svn commit: r268197 - stable/10/sys/dev/mps

Scott Long scottl at FreeBSD.org
Wed Jul 2 23:32:06 UTC 2014


Author: scottl
Date: Wed Jul  2 23:32:05 2014
New Revision: 268197
URL: http://svnweb.freebsd.org/changeset/base/268197

Log:
  Merge r268071, 268072, 268088
  
   Refactor some code in mps.c to reduce header pollution.
   Add accessor functions for manipulating the CAM CCB status field.
   Don't overload the CCB status field within the driver.
  
  Reviewed by:    gibbs, slm
  Obtained from:  Netflix, Inc.

Modified:
  stable/10/sys/dev/mps/mps.c
  stable/10/sys/dev/mps/mps_sas.c
  stable/10/sys/dev/mps/mps_sas.h
  stable/10/sys/dev/mps/mps_user.c
  stable/10/sys/dev/mps/mpsvar.h
Directory Properties:
  stable/10/   (props changed)

Modified: stable/10/sys/dev/mps/mps.c
==============================================================================
--- stable/10/sys/dev/mps/mps.c	Wed Jul  2 23:28:21 2014	(r268196)
+++ stable/10/sys/dev/mps/mps.c	Wed Jul  2 23:32:05 2014	(r268197)
@@ -75,7 +75,6 @@ __FBSDID("$FreeBSD$");
 #include <dev/mps/mps_ioctl.h>
 #include <dev/mps/mpsvar.h>
 #include <dev/mps/mps_table.h>
-#include <dev/mps/mps_sas.h>
 
 static int mps_diag_reset(struct mps_softc *sc, int sleep_flag);
 static int mps_init_queues(struct mps_softc *sc);
@@ -328,11 +327,9 @@ mps_transition_operational(struct mps_so
 static int
 mps_iocfacts_allocate(struct mps_softc *sc, uint8_t attaching)
 {
-	int error, i;
+	int error;
 	Mpi2IOCFactsReply_t saved_facts;
 	uint8_t saved_mode, reallocating;
-	struct mpssas_lun *lun, *lun_tmp;
-	struct mpssas_target *targ;
 
 	mps_dprint(sc, MPS_TRACE, "%s\n", __func__);
 
@@ -489,27 +486,7 @@ mps_iocfacts_allocate(struct mps_softc *
 	 */
 	if (reallocating) {
 		mps_iocfacts_free(sc);
-
-		/*
-		 * The number of targets is based on IOC Facts, so free all of
-		 * the allocated LUNs for each target and then the target buffer
-		 * itself.
-		 */
-		for (i=0; i< saved_facts.MaxTargets; i++) {
-			targ = &sc->sassc->targets[i];
-			SLIST_FOREACH_SAFE(lun, &targ->luns, lun_link,
-			    lun_tmp) {
-				free(lun, M_MPT2);
-			}
-		}
-		free(sc->sassc->targets, M_MPT2);
-
-		sc->sassc->targets = malloc(sizeof(struct mpssas_target) *
-		    sc->facts->MaxTargets, M_MPT2, M_WAITOK|M_ZERO);
-		if (!sc->sassc->targets) {
-			panic("%s failed to alloc targets with error %d\n",
-			    __func__, ENOMEM);
-		}
+		mpssas_realloc_targets(sc, saved_facts.MaxTargets);
 	}
 
 	/*

Modified: stable/10/sys/dev/mps/mps_sas.c
==============================================================================
--- stable/10/sys/dev/mps/mps_sas.c	Wed Jul  2 23:28:21 2014	(r268196)
+++ stable/10/sys/dev/mps/mps_sas.c	Wed Jul  2 23:32:05 2014	(r268197)
@@ -597,7 +597,7 @@ mpssas_remove_device(struct mps_softc *s
 
 		mps_dprint(sc, MPS_XINFO, "Completing missed command %p\n", tm);
 		ccb = tm->cm_complete_data;
-		ccb->ccb_h.status = CAM_DEV_NOT_THERE;
+		mpssas_set_ccbstatus(ccb, CAM_DEV_NOT_THERE);
 		mpssas_scsiio_complete(sc, tm);
 	}
 }
@@ -986,7 +986,7 @@ mpssas_action(struct cam_sim *sim, union
 		 */
 		cpi->maxio = 256 * 1024;
 #endif
-		cpi->ccb_h.status = CAM_REQ_CMP;
+		mpssas_set_ccbstatus(ccb, CAM_REQ_CMP);
 		break;
 	}
 	case XPT_GET_TRAN_SETTINGS:
@@ -1005,7 +1005,7 @@ mpssas_action(struct cam_sim *sim, union
 		    cts->ccb_h.target_id));
 		targ = &sassc->targets[cts->ccb_h.target_id];
 		if (targ->handle == 0x0) {
-			cts->ccb_h.status = CAM_SEL_TIMEOUT;
+			mpssas_set_ccbstatus(ccb, CAM_SEL_TIMEOUT);
 			break;
 		}
 
@@ -1032,12 +1032,12 @@ mpssas_action(struct cam_sim *sim, union
 		scsi->valid = CTS_SCSI_VALID_TQ;
 		scsi->flags = CTS_SCSI_FLAGS_TAG_ENB;
 
-		cts->ccb_h.status = CAM_REQ_CMP;
+		mpssas_set_ccbstatus(ccb, CAM_REQ_CMP);
 		break;
 	}
 	case XPT_CALC_GEOMETRY:
 		cam_calc_geometry(&ccb->ccg, /*extended*/1);
-		ccb->ccb_h.status = CAM_REQ_CMP;
+		mpssas_set_ccbstatus(ccb, CAM_REQ_CMP);
 		break;
 	case XPT_RESET_DEV:
 		mps_dprint(sassc->sc, MPS_XINFO, "mpssas_action XPT_RESET_DEV\n");
@@ -1048,7 +1048,7 @@ mpssas_action(struct cam_sim *sim, union
 	case XPT_TERM_IO:
 		mps_dprint(sassc->sc, MPS_XINFO,
 		    "mpssas_action faking success for abort or reset\n");
-		ccb->ccb_h.status = CAM_REQ_CMP;
+		mpssas_set_ccbstatus(ccb, CAM_REQ_CMP);
 		break;
 	case XPT_SCSI_IO:
 		mpssas_action_scsiio(sassc, ccb);
@@ -1059,7 +1059,7 @@ mpssas_action(struct cam_sim *sim, union
 		return;
 #endif
 	default:
-		ccb->ccb_h.status = CAM_FUNC_NOTAVAIL;
+		mpssas_set_ccbstatus(ccb, CAM_FUNC_NOTAVAIL);
 		break;
 	}
 	xpt_done(ccb);
@@ -1588,8 +1588,7 @@ mpssas_scsiio_timeout(void *data)
 	/* XXX first, check the firmware state, to see if it's still
 	 * operational.  if not, do a diag reset.
 	 */
-
-	cm->cm_ccb->ccb_h.status = CAM_CMD_TIMEOUT;
+	mpssas_set_ccbstatus(cm->cm_ccb, CAM_CMD_TIMEOUT);
 	cm->cm_state = MPS_CM_STATE_TIMEDOUT;
 	TAILQ_INSERT_TAIL(&targ->timedout_commands, cm, cm_recovery);
 
@@ -1650,14 +1649,14 @@ mpssas_action_scsiio(struct mpssas_softc
 	if (targ->handle == 0x0) {
 		mps_dprint(sc, MPS_ERROR, "%s NULL handle for target %u\n", 
 		    __func__, csio->ccb_h.target_id);
-		csio->ccb_h.status = CAM_SEL_TIMEOUT;
+		mpssas_set_ccbstatus(ccb, CAM_SEL_TIMEOUT);
 		xpt_done(ccb);
 		return;
 	}
 	if (targ->flags & MPS_TARGET_FLAGS_RAID_COMPONENT) {
 		mps_dprint(sc, MPS_ERROR, "%s Raid component no SCSI IO "
 		    "supported %u\n", __func__, csio->ccb_h.target_id);
-		csio->ccb_h.status = CAM_TID_INVALID;
+		mpssas_set_ccbstatus(ccb, CAM_TID_INVALID);
 		xpt_done(ccb);
 		return;
 	}
@@ -1666,7 +1665,7 @@ mpssas_action_scsiio(struct mpssas_softc
 	 * Progress" and was actually aborted by the upper layer.  Check for
 	 * this here and complete the command without error.
 	 */
-	if (ccb->ccb_h.status != CAM_REQ_INPROG) {
+	if (mpssas_get_ccbstatus(ccb) != CAM_REQ_INPROG) {
 		mps_dprint(sc, MPS_TRACE, "%s Command is not in progress for "
 		    "target %u\n", __func__, csio->ccb_h.target_id);
 		xpt_done(ccb);
@@ -1679,16 +1678,16 @@ mpssas_action_scsiio(struct mpssas_softc
 	 */
 	if (targ->flags & MPSSAS_TARGET_INREMOVAL) {
 		if (targ->devinfo == 0)
-			csio->ccb_h.status = CAM_REQ_CMP;
+			mpssas_set_ccbstatus(ccb, CAM_REQ_CMP);
 		else
-			csio->ccb_h.status = CAM_SEL_TIMEOUT;
+			mpssas_set_ccbstatus(ccb, CAM_SEL_TIMEOUT);
 		xpt_done(ccb);
 		return;
 	}
 
 	if ((sc->mps_flags & MPS_FLAGS_SHUTDOWN) != 0) {
 		mps_dprint(sc, MPS_INFO, "%s shutting down\n", __func__);
-		csio->ccb_h.status = CAM_TID_INVALID;
+		mpssas_set_ccbstatus(ccb, CAM_TID_INVALID);
 		xpt_done(ccb);
 		return;
 	}
@@ -1767,7 +1766,7 @@ mpssas_action_scsiio(struct mpssas_softc
 	req->Control = htole32(mpi_control);
 	if (MPS_SET_LUN(req->LUN, csio->ccb_h.target_lun) != 0) {
 		mps_free_command(sc, cm);
-		ccb->ccb_h.status = CAM_LUN_INVALID;
+		mpssas_set_ccbstatus(ccb, CAM_LUN_INVALID);
 		xpt_done(ccb);
 		return;
 	}
@@ -1855,10 +1854,10 @@ mpssas_action_scsiio(struct mpssas_softc
 	 * the I/O to the IR volume itself.
 	 */
 	if (sc->WD_valid_config) {
-		if (ccb->ccb_h.status != MPS_WD_RETRY) {
+		if (ccb->ccb_h.sim_priv.entries[0].field == MPS_WD_RETRY) {
 			mpssas_direct_drive_io(sassc, cm, ccb);
 		} else {
-			ccb->ccb_h.status = CAM_REQ_INPROG;
+			mpssas_set_ccbstatus(ccb, CAM_REQ_INPROG);
 		}
 	}
 
@@ -2152,7 +2151,7 @@ mpssas_scsiio_complete(struct mps_softc 
 		 * because there can be no reply when we haven't actually
 		 * gone out to the hardware.
 		 */
-		ccb->ccb_h.status = CAM_REQUEUE_REQ;
+		mpssas_set_ccbstatus(ccb, CAM_REQUEUE_REQ);
 
 		/*
 		 * Currently the only error included in the mask is
@@ -2175,11 +2174,11 @@ mpssas_scsiio_complete(struct mps_softc 
 
 	/* Take the fast path to completion */
 	if (cm->cm_reply == NULL) {
-		if ((ccb->ccb_h.status & CAM_STATUS_MASK) == CAM_REQ_INPROG) {
+		if (mpssas_get_ccbstatus(ccb) == CAM_REQ_INPROG) {
 			if ((sc->mps_flags & MPS_FLAGS_DIAGRESET) != 0)
-				ccb->ccb_h.status = CAM_SCSI_BUS_RESET;
+				mpssas_set_ccbstatus(ccb, CAM_SCSI_BUS_RESET);
 			else {
-				ccb->ccb_h.status = CAM_REQ_CMP;
+				mpssas_set_ccbstatus(ccb, CAM_REQ_CMP);
 				ccb->csio.scsi_status = SCSI_STATUS_OK;
 			}
 			if (sassc->flags & MPSSAS_QUEUE_FROZEN) {
@@ -2195,10 +2194,10 @@ mpssas_scsiio_complete(struct mps_softc 
 		 * CAM_REQ_CMP.  The first is if MPS_CM_FLAGS_ERROR_MASK is
 		 * set, the second is in the MPS_FLAGS_DIAGRESET above.
 		 */
-		if ((ccb->ccb_h.status & CAM_STATUS_MASK) != CAM_REQ_CMP) {
+		if (mpssas_get_ccbstatus(ccb) != CAM_REQ_CMP) {
 			/*
 			 * Freeze the dev queue so that commands are
-			 * executed in the correct order with after error
+			 * executed in the correct order after error
 			 * recovery.
 			 */
 			ccb->ccb_h.status |= CAM_DEV_QFRZN;
@@ -2222,10 +2221,11 @@ mpssas_scsiio_complete(struct mps_softc 
 	 */
 	if (cm->cm_flags & MPS_CM_FLAGS_DD_IO) {
 		mps_free_command(sc, cm);
-		ccb->ccb_h.status = MPS_WD_RETRY;
+		ccb->ccb_h.sim_priv.entries[0].field = MPS_WD_RETRY;
 		mpssas_action_scsiio(sassc, ccb);
 		return;
-	}
+	} else
+		ccb->ccb_h.sim_priv.entries[0].field = 0;
 
 	switch (le16toh(rep->IOCStatus) & MPI2_IOCSTATUS_MASK) {
 	case MPI2_IOCSTATUS_SCSI_DATA_UNDERRUN:
@@ -2241,7 +2241,7 @@ mpssas_scsiio_complete(struct mps_softc 
 		/* Completion failed at the transport level. */
 		if (rep->SCSIState & (MPI2_SCSI_STATE_NO_SCSI_STATUS |
 		    MPI2_SCSI_STATE_TERMINATED)) {
-			ccb->ccb_h.status = CAM_REQ_CMP_ERR;
+			mpssas_set_ccbstatus(ccb, CAM_REQ_CMP_ERR);
 			break;
 		}
 
@@ -2250,7 +2250,7 @@ mpssas_scsiio_complete(struct mps_softc 
 		 * recover the command.
 		 */
 		if (rep->SCSIState & MPI2_SCSI_STATE_AUTOSENSE_FAILED) {
-			ccb->ccb_h.status = CAM_AUTOSENSE_FAIL;
+			mpssas_set_ccbstatus(ccb, CAM_AUTOSENSE_FAIL);
 			break;
 		}
 
@@ -2274,16 +2274,16 @@ mpssas_scsiio_complete(struct mps_softc 
 		 */
 		if ((rep->SCSIStatus == MPI2_SCSI_STATUS_COMMAND_TERMINATED) ||
 		    (rep->SCSIStatus == MPI2_SCSI_STATUS_TASK_ABORTED)) {
-			ccb->ccb_h.status = CAM_REQ_ABORTED;
+			mpssas_set_ccbstatus(ccb, CAM_REQ_ABORTED);
 			break;
 		}
 
 		/* Handle normal status and sense */
 		csio->scsi_status = rep->SCSIStatus;
 		if (rep->SCSIStatus == MPI2_SCSI_STATUS_GOOD)
-			ccb->ccb_h.status = CAM_REQ_CMP;
+			mpssas_set_ccbstatus(ccb, CAM_REQ_CMP);
 		else
-			ccb->ccb_h.status = CAM_SCSI_STATUS_ERROR;
+			mpssas_set_ccbstatus(ccb, CAM_SCSI_STATUS_ERROR);
 
 		if (rep->SCSIState & MPI2_SCSI_STATE_AUTOSENSE_VALID) {
 			int sense_len, returned_sense_len;
@@ -2347,13 +2347,13 @@ mpssas_scsiio_complete(struct mps_softc 
 		 * failed.
 		 */
 		if (cm->cm_targ->devinfo == 0)
-			ccb->ccb_h.status = CAM_REQ_CMP;
+			mpssas_set_ccbstatus(ccb, CAM_REQ_CMP);
 		else
-			ccb->ccb_h.status = CAM_DEV_NOT_THERE;
+			mpssas_set_ccbstatus(ccb, CAM_DEV_NOT_THERE);
 		break;
 	case MPI2_IOCSTATUS_INVALID_SGL:
 		mps_print_scsiio_cmd(sc, cm);
-		ccb->ccb_h.status = CAM_UNREC_HBA_ERROR;
+		mpssas_set_ccbstatus(ccb, CAM_UNREC_HBA_ERROR);
 		break;
 	case MPI2_IOCSTATUS_SCSI_TASK_TERMINATED:
 		/*
@@ -2366,14 +2366,14 @@ mpssas_scsiio_complete(struct mps_softc 
 		 * on the console.
 		 */
 		if (cm->cm_state == MPS_CM_STATE_TIMEDOUT)
-			ccb->ccb_h.status = CAM_CMD_TIMEOUT;
+			mpssas_set_ccbstatus(ccb, CAM_CMD_TIMEOUT);
 		else
-			ccb->ccb_h.status = CAM_REQ_ABORTED;
+			mpssas_set_ccbstatus(ccb, CAM_REQ_ABORTED);
 		break;
 	case MPI2_IOCSTATUS_SCSI_DATA_OVERRUN:
 		/* resid is ignored for this condition */
 		csio->resid = 0;
-		ccb->ccb_h.status = CAM_DATA_RUN_ERR;
+		mpssas_set_ccbstatus(ccb, CAM_DATA_RUN_ERR);
 		break;
 	case MPI2_IOCSTATUS_SCSI_IOC_TERMINATED:
 	case MPI2_IOCSTATUS_SCSI_EXT_TERMINATED:
@@ -2382,7 +2382,7 @@ mpssas_scsiio_complete(struct mps_softc 
 		 * transient transport-related) errors, retry these without
 		 * decrementing the retry count.
 		 */
-		ccb->ccb_h.status = CAM_REQUEUE_REQ;
+		mpssas_set_ccbstatus(ccb, CAM_REQUEUE_REQ);
 		mpssas_log_command(cm, MPS_INFO,
 		    "terminated ioc %x scsi %x state %x xfer %u\n",
 		    le16toh(rep->IOCStatus), rep->SCSIStatus, rep->SCSIState,
@@ -2404,7 +2404,7 @@ mpssas_scsiio_complete(struct mps_softc 
 		    le16toh(rep->IOCStatus), rep->SCSIStatus, rep->SCSIState,
 		    le32toh(rep->TransferCount));
 		csio->resid = cm->cm_length;
-		ccb->ccb_h.status = CAM_REQ_CMP_ERR;
+		mpssas_set_ccbstatus(ccb, CAM_REQ_CMP_ERR);
 		break;
 	}
 	
@@ -2417,7 +2417,7 @@ mpssas_scsiio_complete(struct mps_softc 
 		    "unfreezing SIM queue\n");
 	}
 
-	if ((ccb->ccb_h.status & CAM_STATUS_MASK) != CAM_REQ_CMP) {
+	if (mpssas_get_ccbstatus(ccb) != CAM_REQ_CMP) {
 		ccb->ccb_h.status |= CAM_DEV_QFRZN;
 		xpt_freeze_devq(ccb->ccb_h.path, /*count*/ 1);
 	}
@@ -2715,14 +2715,14 @@ mpssas_smpio_complete(struct mps_softc *
 	if ((cm->cm_flags & MPS_CM_FLAGS_ERROR_MASK) != 0) {
 		mps_dprint(sc, MPS_ERROR,"%s: cm_flags = %#x on SMP request!\n",
 			   __func__, cm->cm_flags);
-		ccb->ccb_h.status = CAM_REQ_CMP_ERR;
+		mpssas_set_ccbstatus(ccb, CAM_REQ_CMP_ERR);
 		goto bailout;
         }
 
 	rpl = (MPI2_SMP_PASSTHROUGH_REPLY *)cm->cm_reply;
 	if (rpl == NULL) {
 		mps_dprint(sc, MPS_ERROR, "%s: NULL cm_reply!\n", __func__);
-		ccb->ccb_h.status = CAM_REQ_CMP_ERR;
+		mpssas_set_ccbstatus(ccb, CAM_REQ_CMP_ERR);
 		goto bailout;
 	}
 
@@ -2735,7 +2735,7 @@ mpssas_smpio_complete(struct mps_softc *
 	    rpl->SASStatus != MPI2_SASSTATUS_SUCCESS) {
 		mps_dprint(sc, MPS_XINFO, "%s: IOCStatus %04x SASStatus %02x\n",
 		    __func__, le16toh(rpl->IOCStatus), rpl->SASStatus);
-		ccb->ccb_h.status = CAM_REQ_CMP_ERR;
+		mpssas_set_ccbstatus(ccb, CAM_REQ_CMP_ERR);
 		goto bailout;
 	}
 
@@ -2744,9 +2744,9 @@ mpssas_smpio_complete(struct mps_softc *
 		   (uintmax_t)sasaddr);
 
 	if (ccb->smpio.smp_response[2] == SMP_FR_ACCEPTED)
-		ccb->ccb_h.status = CAM_REQ_CMP;
+		mpssas_set_ccbstatus(ccb, CAM_REQ_CMP);
 	else
-		ccb->ccb_h.status = CAM_SMP_STATUS_ERROR;
+		mpssas_set_ccbstatus(ccb, CAM_SMP_STATUS_ERROR);
 
 bailout:
 	/*
@@ -2782,7 +2782,7 @@ mpssas_send_smpcmd(struct mpssas_softc *
 	case CAM_DATA_SG_PADDR:
 		mps_dprint(sc, MPS_ERROR,
 			   "%s: physical addresses not supported\n", __func__);
-		ccb->ccb_h.status = CAM_REQ_INVALID;
+		mpssas_set_ccbstatus(ccb, CAM_REQ_INVALID);
 		xpt_done(ccb);
 		return;
 	case CAM_DATA_SG:
@@ -2796,7 +2796,7 @@ mpssas_send_smpcmd(struct mpssas_softc *
 				   "%s: multiple request or response "
 				   "buffer segments not supported for SMP\n",
 				   __func__);
-			ccb->ccb_h.status = CAM_REQ_INVALID;
+			mpssas_set_ccbstatus(ccb, CAM_REQ_INVALID);
 			xpt_done(ccb);
 			return;
 		}
@@ -2830,7 +2830,7 @@ mpssas_send_smpcmd(struct mpssas_softc *
 		response = ccb->smpio.smp_response;
 		break;
 	default:
-		ccb->ccb_h.status = CAM_REQ_INVALID;
+		mpssas_set_ccbstatus(ccb, CAM_REQ_INVALID);
 		xpt_done(ccb);
 		return;
 	}
@@ -2839,7 +2839,7 @@ mpssas_send_smpcmd(struct mpssas_softc *
 	if (cm == NULL) {
 		mps_dprint(sc, MPS_ERROR,
 		    "%s: cannot allocate command\n", __func__);
-		ccb->ccb_h.status = CAM_RESRC_UNAVAIL;
+		mpssas_set_ccbstatus(ccb, CAM_RESRC_UNAVAIL);
 		xpt_done(ccb);
 		return;
 	}
@@ -2927,7 +2927,7 @@ mpssas_send_smpcmd(struct mpssas_softc *
 
 bailout_error:
 	mps_free_command(sc, cm);
-	ccb->ccb_h.status = CAM_RESRC_UNAVAIL;
+	mpssas_set_ccbstatus(ccb, CAM_RESRC_UNAVAIL);
 	xpt_done(ccb);
 	return;
 
@@ -2952,7 +2952,7 @@ mpssas_action_smpio(struct mpssas_softc 
 		mps_dprint(sc, MPS_ERROR,
 			   "%s: target %d does not exist!\n", __func__,
 			   ccb->ccb_h.target_id);
-		ccb->ccb_h.status = CAM_SEL_TIMEOUT;
+		mpssas_set_ccbstatus(ccb, CAM_SEL_TIMEOUT);
 		xpt_done(ccb);
 		return;
 	}
@@ -3001,7 +3001,7 @@ mpssas_action_smpio(struct mpssas_softc 
 			mps_dprint(sc, MPS_ERROR,
 				   "%s: handle %d does not have a valid "
 				   "parent handle!\n", __func__, targ->handle);
-			ccb->ccb_h.status = CAM_REQ_INVALID;
+			mpssas_set_ccbstatus(ccb, CAM_REQ_INVALID);
 			goto bailout;
 		}
 #ifdef OLD_MPS_PROBE
@@ -3012,7 +3012,7 @@ mpssas_action_smpio(struct mpssas_softc 
 			mps_dprint(sc, MPS_ERROR,
 				   "%s: handle %d does not have a valid "
 				   "parent target!\n", __func__, targ->handle);
-			ccb->ccb_h.status = CAM_REQ_INVALID;
+			mpssas_set_ccbstatus(ccb, CAM_REQ_INVALID);
 			goto bailout;
 		}
 
@@ -3022,7 +3022,7 @@ mpssas_action_smpio(struct mpssas_softc 
 				   "%s: handle %d parent %d does not "
 				   "have an SMP target!\n", __func__,
 				   targ->handle, parent_target->handle);
-			ccb->ccb_h.status = CAM_REQ_INVALID;
+			mpssas_set_ccbstatus(ccb, CAM_REQ_INVALID);
 			goto bailout;
 
 		}
@@ -3035,7 +3035,7 @@ mpssas_action_smpio(struct mpssas_softc 
 				   "%s: handle %d parent %d does not "
 				   "have an SMP target!\n", __func__,
 				   targ->handle, targ->parent_handle);
-			ccb->ccb_h.status = CAM_REQ_INVALID;
+			mpssas_set_ccbstatus(ccb, CAM_REQ_INVALID);
 			goto bailout;
 
 		}
@@ -3044,7 +3044,7 @@ mpssas_action_smpio(struct mpssas_softc 
 				   "%s: handle %d parent handle %d does "
 				   "not have a valid SAS address!\n",
 				   __func__, targ->handle, targ->parent_handle);
-			ccb->ccb_h.status = CAM_REQ_INVALID;
+			mpssas_set_ccbstatus(ccb, CAM_REQ_INVALID);
 			goto bailout;
 		}
 
@@ -3057,7 +3057,7 @@ mpssas_action_smpio(struct mpssas_softc 
 		mps_dprint(sc, MPS_INFO,
 			   "%s: unable to find SAS address for handle %d\n",
 			   __func__, targ->handle);
-		ccb->ccb_h.status = CAM_REQ_INVALID;
+		mpssas_set_ccbstatus(ccb, CAM_REQ_INVALID);
 		goto bailout;
 	}
 	mpssas_send_smpcmd(sassc, ccb, sasaddr);
@@ -3089,7 +3089,7 @@ mpssas_action_resetdev(struct mpssas_sof
 	if (tm == NULL) {
 		mps_dprint(sc, MPS_ERROR,
 		    "command alloc failure in mpssas_action_resetdev\n");
-		ccb->ccb_h.status = CAM_RESRC_UNAVAIL;
+		mpssas_set_ccbstatus(ccb, CAM_RESRC_UNAVAIL);
 		xpt_done(ccb);
 		return;
 	}
@@ -3137,7 +3137,7 @@ mpssas_resetdev_complete(struct mps_soft
 			   "%s: cm_flags = %#x for reset of handle %#04x! "
 			   "This should not happen!\n", __func__, tm->cm_flags,
 			   req->DevHandle);
-		ccb->ccb_h.status = CAM_REQ_CMP_ERR;
+		mpssas_set_ccbstatus(ccb, CAM_REQ_CMP_ERR);
 		goto bailout;
 	}
 
@@ -3146,12 +3146,12 @@ mpssas_resetdev_complete(struct mps_soft
 	    le16toh(resp->IOCStatus), le32toh(resp->ResponseCode));
 
 	if (le32toh(resp->ResponseCode) == MPI2_SCSITASKMGMT_RSP_TM_COMPLETE) {
-		ccb->ccb_h.status = CAM_REQ_CMP;
+		mpssas_set_ccbstatus(ccb, CAM_REQ_CMP);
 		mpssas_announce_reset(sc, AC_SENT_BDR, tm->cm_targ->tid,
 		    CAM_LUN_WILDCARD);
 	}
 	else
-		ccb->ccb_h.status = CAM_REQ_CMP_ERR;
+		mpssas_set_ccbstatus(ccb, CAM_REQ_CMP_ERR);
 
 bailout:
 
@@ -3253,7 +3253,7 @@ mpssas_async(void *callback_arg, uint32_
 			cam_release_devq(cdai.ccb_h.path,
 					 0, 0, 0, FALSE);
 
-		if (((cdai.ccb_h.status & CAM_STATUS_MASK) == CAM_REQ_CMP)
+		if ((mpssas_get_ccbstatus((union ccb *)&cdai) == CAM_REQ_CMP)
 		 && (rcap_buf.prot & SRC16_PROT_EN)) {
 			lun->eedp_formatted = TRUE;
 			lun->eedp_block_size = scsi_4btoul(rcap_buf.length);
@@ -3455,7 +3455,7 @@ mpssas_read_cap_done(struct cam_periph *
 		 * the lun as not supporting EEDP and set the block size
 		 * to 0.
 		 */
-		if (((done_ccb->ccb_h.status & CAM_STATUS_MASK) != CAM_REQ_CMP)
+		if ((mpssas_get_ccbstatus(done_ccb) != CAM_REQ_CMP)
 		 || (done_ccb->csio.scsi_status != SCSI_STATUS_OK)) {
 			lun->eedp_formatted = FALSE;
 			lun->eedp_block_size = 0;
@@ -3593,3 +3593,33 @@ mpssas_check_id(struct mpssas_softc *sas
 
 	return (0);
 }
+
+void
+mpssas_realloc_targets(struct mps_softc *sc, int maxtargets)
+{
+	struct mpssas_softc *sassc;
+	struct mpssas_lun *lun, *lun_tmp;
+	struct mpssas_target *targ;
+	int i;
+
+	sassc = sc->sassc;
+	/*
+	 * The number of targets is based on IOC Facts, so free all of
+	 * the allocated LUNs for each target and then the target buffer
+	 * itself.
+	 */
+	for (i=0; i< maxtargets; i++) {
+		targ = &sassc->targets[i];
+		SLIST_FOREACH_SAFE(lun, &targ->luns, lun_link, lun_tmp) {
+			free(lun, M_MPT2);
+		}
+	}
+	free(sassc->targets, M_MPT2);
+
+	sassc->targets = malloc(sizeof(struct mpssas_target) * maxtargets,
+	    M_MPT2, M_WAITOK|M_ZERO);
+	if (!sassc->targets) {
+		panic("%s failed to alloc targets with error %d\n",
+		    __func__, ENOMEM);
+	}
+}

Modified: stable/10/sys/dev/mps/mps_sas.h
==============================================================================
--- stable/10/sys/dev/mps/mps_sas.h	Wed Jul  2 23:28:21 2014	(r268196)
+++ stable/10/sys/dev/mps/mps_sas.h	Wed Jul  2 23:32:05 2014	(r268197)
@@ -145,6 +145,19 @@ mpssas_set_lun(uint8_t *lun, u_int ccblu
 	return (0);
 }
 
+static __inline void
+mpssas_set_ccbstatus(union ccb *ccb, int status)
+{
+	ccb->ccb_h.status &= ~CAM_STATUS_MASK;
+	ccb->ccb_h.status |= status;
+}
+
+static __inline int
+mpssas_get_ccbstatus(union ccb *ccb)
+{
+	return (ccb->ccb_h.status & CAM_STATUS_MASK);
+}
+
 #define MPS_SET_SINGLE_LUN(req, lun)	\
 do {					\
 	bzero((req)->LUN, 8);		\
@@ -156,7 +169,5 @@ void mpssas_discovery_end(struct mpssas_
 void mpssas_startup_increment(struct mpssas_softc *sassc);
 void mpssas_startup_decrement(struct mpssas_softc *sassc);
 
-struct mps_command * mpssas_alloc_tm(struct mps_softc *sc);
-void mpssas_free_tm(struct mps_softc *sc, struct mps_command *tm);
 void mpssas_firmware_event_work(void *arg, int pending);
 int mpssas_check_id(struct mpssas_softc *sassc, int id);

Modified: stable/10/sys/dev/mps/mps_user.c
==============================================================================
--- stable/10/sys/dev/mps/mps_user.c	Wed Jul  2 23:28:21 2014	(r268196)
+++ stable/10/sys/dev/mps/mps_user.c	Wed Jul  2 23:32:05 2014	(r268197)
@@ -101,7 +101,6 @@ __FBSDID("$FreeBSD$");
 #include <dev/mps/mps_ioctl.h>
 #include <dev/mps/mpsvar.h>
 #include <dev/mps/mps_table.h>
-#include <dev/mps/mps_sas.h>
 #include <dev/pci/pcivar.h>
 #include <dev/pci/pcireg.h>
 

Modified: stable/10/sys/dev/mps/mpsvar.h
==============================================================================
--- stable/10/sys/dev/mps/mpsvar.h	Wed Jul  2 23:28:21 2014	(r268196)
+++ stable/10/sys/dev/mps/mpsvar.h	Wed Jul  2 23:32:05 2014	(r268197)
@@ -756,6 +756,9 @@ void mpssas_prepare_remove(struct mpssas
 void mpssas_prepare_volume_remove(struct mpssas_softc *sassc, uint16_t handle);
 int mpssas_startup(struct mps_softc *sc);
 struct mpssas_target * mpssas_find_target_by_handle(struct mpssas_softc *, int, uint16_t);
+void mpssas_realloc_targets(struct mps_softc *sc, int maxtargets);
+struct mps_command * mpssas_alloc_tm(struct mps_softc *sc);
+void mpssas_free_tm(struct mps_softc *sc, struct mps_command *tm);
 
 SYSCTL_DECL(_hw_mps);
 


More information about the svn-src-all mailing list