From fa7130a4bc5adf823d5387fd7acb11753e4e7764 Mon Sep 17 00:00:00 2001 From: scottl Date: Wed, 2 Jul 2014 23:32:05 +0000 Subject: [PATCH] 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. git-svn-id: svn://svn.freebsd.org/base/stable/10@268197 ccf9f872-aa2e-dd11-9fc8-001c23d0bc1f --- sys/dev/mps/mps.c | 27 +------ sys/dev/mps/mps_sas.c | 156 ++++++++++++++++++++++++----------------- sys/dev/mps/mps_sas.h | 15 +++- sys/dev/mps/mps_user.c | 1 - sys/dev/mps/mpsvar.h | 3 + 5 files changed, 111 insertions(+), 91 deletions(-) diff --git a/sys/dev/mps/mps.c b/sys/dev/mps/mps.c index a73b39193..c1c1f6c99 100644 --- a/sys/dev/mps/mps.c +++ b/sys/dev/mps/mps.c @@ -75,7 +75,6 @@ __FBSDID("$FreeBSD$"); #include #include #include -#include 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_softc *sc) 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 *sc, uint8_t attaching) */ 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); } /* diff --git a/sys/dev/mps/mps_sas.c b/sys/dev/mps/mps_sas.c index 639730422..0dfc771ae 100644 --- a/sys/dev/mps/mps_sas.c +++ b/sys/dev/mps/mps_sas.c @@ -597,7 +597,7 @@ mpssas_remove_device(struct mps_softc *sc, struct mps_command *tm) 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 ccb *ccb) */ 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 ccb *ccb) 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 ccb *ccb) 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 ccb *ccb) 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 ccb *ccb) 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 *sassc, union ccb *ccb) 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 *sassc, union ccb *ccb) * 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 *sassc, union ccb *ccb) */ 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 *sassc, union ccb *ccb) 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 *sassc, union ccb *ccb) * 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 *sc, struct mps_command *cm) * 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 *sc, struct mps_command *cm) /* 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 *sc, struct mps_command *cm) * 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 *sc, struct mps_command *cm) */ 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 *sc, struct mps_command *cm) /* 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 *sc, struct mps_command *cm) * 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 *sc, struct mps_command *cm) */ 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 *sc, struct mps_command *cm) * 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 *sc, struct mps_command *cm) * 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 *sc, struct mps_command *cm) * 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 *sc, struct mps_command *cm) 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 *sc, struct mps_command *cm) "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 *sc, struct mps_command *cm) 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 *sc, struct mps_command *cm) 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 *sc, struct mps_command *cm) (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 *sassc, union ccb *ccb, uint64_t sasaddr) 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 *sassc, union ccb *ccb, uint64_t sasaddr) "%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 *sassc, union ccb *ccb, uint64_t sasaddr) 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 *sassc, union ccb *ccb, uint64_t sasaddr) 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 *sassc, union ccb *ccb, uint64_t sasaddr) 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 *sassc, union ccb *ccb) 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 *sassc, union ccb *ccb) 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 *sassc, union ccb *ccb) 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 *sassc, union ccb *ccb) "%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 *sassc, union ccb *ccb) "%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 *sassc, union ccb *ccb) "%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 *sassc, union ccb *ccb) 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_softc *sassc, union ccb *ccb) 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_softc *sc, struct mps_command *tm) "%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_softc *sc, struct mps_command *tm) 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_t code, struct cam_path *path, 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 *periph, union ccb *done_ccb) * 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 *sassc, int id) 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); + } +} diff --git a/sys/dev/mps/mps_sas.h b/sys/dev/mps/mps_sas.h index 0c3bb0898..dac49058d 100644 --- a/sys/dev/mps/mps_sas.h +++ b/sys/dev/mps/mps_sas.h @@ -145,6 +145,19 @@ mpssas_set_lun(uint8_t *lun, u_int ccblun) 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_softc *sassc); 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); diff --git a/sys/dev/mps/mps_user.c b/sys/dev/mps/mps_user.c index 9212f77f9..16ec4e4e6 100644 --- a/sys/dev/mps/mps_user.c +++ b/sys/dev/mps/mps_user.c @@ -101,7 +101,6 @@ __FBSDID("$FreeBSD$"); #include #include #include -#include #include #include diff --git a/sys/dev/mps/mpsvar.h b/sys/dev/mps/mpsvar.h index 14015fa0d..50e93f00a 100644 --- a/sys/dev/mps/mpsvar.h +++ b/sys/dev/mps/mpsvar.h @@ -756,6 +756,9 @@ void mpssas_prepare_remove(struct mpssas_softc *sassc, uint16_t handle); 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); -- 2.45.0