Lines Matching +full:debounce +full:- +full:rep

1 /*-
3 * Copyright (c) 2011-2015 LSI Corp.
4 * Copyright (c) 2013-2016 Avago Technologies
5 * Copyright 2000-2020 Broadcom Inc.
29 * Broadcom Inc. (LSI) MPT-Fusion Host Adapter FreeBSD
147 for (i = start; i < sassc->maxtargets; i++) { in mprsas_find_target_by_handle()
148 target = &sassc->targets[i]; in mprsas_find_target_by_handle()
149 if (target->handle == handle) in mprsas_find_target_by_handle()
166 MPR_FUNCTRACE(sassc->sc); in mprsas_startup_increment()
168 if ((sassc->flags & MPRSAS_IN_STARTUP) != 0) { in mprsas_startup_increment()
169 if (sassc->startup_refcount++ == 0) { in mprsas_startup_increment()
171 mpr_dprint(sassc->sc, MPR_INIT, in mprsas_startup_increment()
174 xpt_freeze_simq(sassc->sim, 1); in mprsas_startup_increment()
176 mpr_dprint(sassc->sc, MPR_INIT, "%s refcount %u\n", __func__, in mprsas_startup_increment()
177 sassc->startup_refcount); in mprsas_startup_increment()
184 if (sassc->flags & MPRSAS_QUEUE_FROZEN) { in mprsas_release_simq_reinit()
185 sassc->flags &= ~MPRSAS_QUEUE_FROZEN; in mprsas_release_simq_reinit()
186 xpt_release_simq(sassc->sim, 1); in mprsas_release_simq_reinit()
187 mpr_dprint(sassc->sc, MPR_INFO, "Unfreezing SIM queue\n"); in mprsas_release_simq_reinit()
194 MPR_FUNCTRACE(sassc->sc); in mprsas_startup_decrement()
196 if ((sassc->flags & MPRSAS_IN_STARTUP) != 0) { in mprsas_startup_decrement()
197 if (--sassc->startup_refcount == 0) { in mprsas_startup_decrement()
198 /* finished all discovery-related actions, release in mprsas_startup_decrement()
201 mpr_dprint(sassc->sc, MPR_INIT, in mprsas_startup_decrement()
203 sassc->flags &= ~MPRSAS_IN_STARTUP; in mprsas_startup_decrement()
204 xpt_release_simq(sassc->sim, 1); in mprsas_startup_decrement()
207 mpr_dprint(sassc->sc, MPR_INIT, "%s refcount %u\n", __func__, in mprsas_startup_decrement()
208 sassc->startup_refcount); in mprsas_startup_decrement()
230 req = (MPI2_SCSI_TASK_MANAGE_REQUEST *)tm->cm_req; in mprsas_alloc_tm()
231 req->Function = MPI2_FUNCTION_SCSI_TASK_MGMT; in mprsas_alloc_tm()
248 if (tm->cm_ccb) { in mprsas_free_tm()
251 tm->cm_targ->tid); in mprsas_free_tm()
252 tm->cm_targ->flags &= ~MPRSAS_TARGET_INRESET; in mprsas_free_tm()
253 xpt_release_devq(tm->cm_ccb->ccb_h.path, 1, TRUE); in mprsas_free_tm()
254 xpt_free_path(tm->cm_ccb->ccb_h.path); in mprsas_free_tm()
255 xpt_free_ccb(tm->cm_ccb); in mprsas_free_tm()
264 struct mprsas_softc *sassc = sc->sassc; in mprsas_rescan_target()
270 pathid = cam_sim_path(sassc->sim); in mprsas_rescan_target()
274 targetid = targ - sassc->targets; in mprsas_rescan_target()
285 if (xpt_create_path(&ccb->ccb_h.path, NULL, pathid, targetid, in mprsas_rescan_target()
293 ccb->ccb_h.func_code = XPT_SCAN_BUS; in mprsas_rescan_target()
295 ccb->ccb_h.func_code = XPT_SCAN_TGT; in mprsas_rescan_target()
312 if ((cm->cm_sc->mpr_debug & level) == 0) in mprsas_log_command()
319 if (cm->cm_ccb != NULL) { in mprsas_log_command()
320 xpt_path_sbuf(cm->cm_ccb->csio.ccb_h.path, &sb); in mprsas_log_command()
321 if (cm->cm_ccb->ccb_h.func_code == XPT_SCSI_IO) { in mprsas_log_command()
322 scsi_command_string(&cm->cm_ccb->csio, &sb); in mprsas_log_command()
324 cm->cm_ccb->csio.dxfer_len); in mprsas_log_command()
328 cam_sim_name(cm->cm_sc->sassc->sim), in mprsas_log_command()
329 cam_sim_unit(cm->cm_sc->sassc->sim), in mprsas_log_command()
330 cam_sim_bus(cm->cm_sc->sassc->sim), in mprsas_log_command()
331 cm->cm_targ ? cm->cm_targ->tid : 0xFFFFFFFF, in mprsas_log_command()
332 cm->cm_lun); in mprsas_log_command()
335 sbuf_printf(&sb, "SMID %u ", cm->cm_desc.Default.SMID); in mprsas_log_command()
338 mpr_print_field(cm->cm_sc, "%s", sbuf_data(&sb)); in mprsas_log_command()
352 reply = (MPI2_SCSI_TASK_MANAGE_REPLY *)tm->cm_reply; in mprsas_remove_volume()
353 handle = (uint16_t)(uintptr_t)tm->cm_complete_data; in mprsas_remove_volume()
354 targ = tm->cm_targ; in mprsas_remove_volume()
364 if ((le16toh(reply->IOCStatus) & MPI2_IOCSTATUS_MASK) != in mprsas_remove_volume()
367 "device 0x%x\n", le16toh(reply->IOCStatus), handle); in mprsas_remove_volume()
371 le32toh(reply->TerminationCount)); in mprsas_remove_volume()
372 mpr_free_reply(sc, tm->cm_reply_data); in mprsas_remove_volume()
373 tm->cm_reply = NULL; /* Ensures the reply won't get re-freed */ in mprsas_remove_volume()
376 targ->tid, handle); in mprsas_remove_volume()
384 if ((le16toh(reply->IOCStatus) & MPI2_IOCSTATUS_MASK) == in mprsas_remove_volume()
386 targ = tm->cm_targ; in mprsas_remove_volume()
387 targ->handle = 0x0; in mprsas_remove_volume()
388 targ->encl_handle = 0x0; in mprsas_remove_volume()
389 targ->encl_level_valid = 0x0; in mprsas_remove_volume()
390 targ->encl_level = 0x0; in mprsas_remove_volume()
391 targ->connector_name[0] = ' '; in mprsas_remove_volume()
392 targ->connector_name[1] = ' '; in mprsas_remove_volume()
393 targ->connector_name[2] = ' '; in mprsas_remove_volume()
394 targ->connector_name[3] = ' '; in mprsas_remove_volume()
395 targ->encl_slot = 0x0; in mprsas_remove_volume()
396 targ->exp_dev_handle = 0x0; in mprsas_remove_volume()
397 targ->phy_num = 0x0; in mprsas_remove_volume()
398 targ->linkrate = 0x0; in mprsas_remove_volume()
399 targ->devinfo = 0x0; in mprsas_remove_volume()
400 targ->flags = 0x0; in mprsas_remove_volume()
401 targ->scsi_req_desc_type = 0; in mprsas_remove_volume()
417 if ((sassc->flags & MPRSAS_TOREMOVE) == 0) in mprsas_prepare_remove_retry()
420 for (i = 0; i < sassc->maxtargets; i++) { in mprsas_prepare_remove_retry()
421 target = &sassc->targets[i]; in mprsas_prepare_remove_retry()
422 if ((target->flags & MPRSAS_TARGET_TOREMOVE) == 0) in mprsas_prepare_remove_retry()
424 if (TAILQ_EMPTY(&sassc->sc->high_priority_req_list)) in mprsas_prepare_remove_retry()
426 target->flags &= ~MPRSAS_TARGET_TOREMOVE; in mprsas_prepare_remove_retry()
427 if (target->flags & MPR_TARGET_FLAGS_VOLUME) in mprsas_prepare_remove_retry()
428 mprsas_prepare_volume_remove(sassc, target->handle); in mprsas_prepare_remove_retry()
430 mprsas_prepare_remove(sassc, target->handle); in mprsas_prepare_remove_retry()
432 sassc->flags &= ~MPRSAS_TOREMOVE; in mprsas_prepare_remove_retry()
447 MPR_FUNCTRACE(sassc->sc); in mprsas_prepare_volume_remove()
448 sc = sassc->sc; in mprsas_prepare_volume_remove()
459 targ->flags |= MPRSAS_TARGET_INREMOVAL; in mprsas_prepare_volume_remove()
463 targ->flags |= MPRSAS_TARGET_TOREMOVE; in mprsas_prepare_volume_remove()
464 sassc->flags |= MPRSAS_TOREMOVE; in mprsas_prepare_volume_remove()
470 req = (MPI2_SCSI_TASK_MANAGE_REQUEST *)cm->cm_req; in mprsas_prepare_volume_remove()
471 req->DevHandle = targ->handle; in mprsas_prepare_volume_remove()
472 req->TaskType = MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET; in mprsas_prepare_volume_remove()
474 if (!targ->is_nvme || sc->custom_nvme_tm_handling) { in mprsas_prepare_volume_remove()
476 req->MsgFlags = MPI2_SCSITASKMGMT_MSGFLAGS_LINK_RESET; in mprsas_prepare_volume_remove()
479 req->MsgFlags = in mprsas_prepare_volume_remove()
483 cm->cm_targ = targ; in mprsas_prepare_volume_remove()
484 cm->cm_data = NULL; in mprsas_prepare_volume_remove()
485 cm->cm_complete = mprsas_remove_volume; in mprsas_prepare_volume_remove()
486 cm->cm_complete_data = (void *)(uintptr_t)handle; in mprsas_prepare_volume_remove()
489 __func__, targ->tid); in mprsas_prepare_volume_remove()
496 * The firmware performs debounce on the link to avoid transient link errors
499 * and then an op remove. The reset has the side-effect of aborting any
500 * outstanding requests for the device, which is required for the op-remove to
512 MPR_FUNCTRACE(sassc->sc); in mprsas_prepare_remove()
514 sc = sassc->sc; in mprsas_prepare_remove()
525 targ->flags |= MPRSAS_TARGET_INREMOVAL; in mprsas_prepare_remove()
529 targ->flags |= MPRSAS_TARGET_TOREMOVE; in mprsas_prepare_remove()
530 sassc->flags |= MPRSAS_TOREMOVE; in mprsas_prepare_remove()
536 req = (MPI2_SCSI_TASK_MANAGE_REQUEST *)tm->cm_req; in mprsas_prepare_remove()
537 req->DevHandle = htole16(targ->handle); in mprsas_prepare_remove()
538 req->TaskType = MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET; in mprsas_prepare_remove()
541 req->MsgFlags = MPI2_SCSITASKMGMT_MSGFLAGS_LINK_RESET; in mprsas_prepare_remove()
543 tm->cm_targ = targ; in mprsas_prepare_remove()
544 tm->cm_data = NULL; in mprsas_prepare_remove()
545 tm->cm_complete = mprsas_remove_device; in mprsas_prepare_remove()
546 tm->cm_complete_data = (void *)(uintptr_t)handle; in mprsas_prepare_remove()
549 __func__, targ->tid); in mprsas_prepare_remove()
565 reply = (MPI2_SCSI_TASK_MANAGE_REPLY *)tm->cm_reply; in mprsas_remove_device()
566 handle = (uint16_t)(uintptr_t)tm->cm_complete_data; in mprsas_remove_device()
567 targ = tm->cm_targ; in mprsas_remove_device()
574 if ((tm->cm_flags & MPR_CM_FLAGS_ERROR_MASK) != 0) { in mprsas_remove_device()
577 tm->cm_flags, handle); in mprsas_remove_device()
588 if ((le16toh(reply->IOCStatus) & MPI2_IOCSTATUS_MASK) != in mprsas_remove_device()
591 "device 0x%x\n", le16toh(reply->IOCStatus), handle); in mprsas_remove_device()
595 le32toh(reply->TerminationCount)); in mprsas_remove_device()
596 mpr_free_reply(sc, tm->cm_reply_data); in mprsas_remove_device()
597 tm->cm_reply = NULL; /* Ensures the reply won't get re-freed */ in mprsas_remove_device()
600 req = (MPI2_SAS_IOUNIT_CONTROL_REQUEST *)tm->cm_req; in mprsas_remove_device()
602 req->Function = MPI2_FUNCTION_SAS_IO_UNIT_CONTROL; in mprsas_remove_device()
603 req->Operation = MPI2_SAS_OP_REMOVE_DEVICE; in mprsas_remove_device()
604 req->DevHandle = htole16(handle); in mprsas_remove_device()
605 tm->cm_data = NULL; in mprsas_remove_device()
606 tm->cm_desc.Default.RequestFlags = MPI2_REQ_DESCRIPT_FLAGS_DEFAULT_TYPE; in mprsas_remove_device()
607 tm->cm_complete = mprsas_remove_complete; in mprsas_remove_device()
608 tm->cm_complete_data = (void *)(uintptr_t)handle; in mprsas_remove_device()
615 if (TAILQ_FIRST(&targ->commands) == NULL) { in mprsas_remove_device()
618 targ->tid, handle); in mprsas_remove_device()
620 targ->pending_remove_tm = NULL; in mprsas_remove_device()
622 targ->pending_remove_tm = tm; in mprsas_remove_device()
626 targ->tid, handle); in mprsas_remove_device()
627 if (targ->encl_level_valid) { in mprsas_remove_device()
629 "connector name (%4s)\n", targ->encl_level, targ->encl_slot, in mprsas_remove_device()
630 targ->connector_name); in mprsas_remove_device()
644 reply = (MPI2_SAS_IOUNIT_CONTROL_REPLY *)tm->cm_reply; in mprsas_remove_complete()
645 handle = (uint16_t)(uintptr_t)tm->cm_complete_data; in mprsas_remove_complete()
647 targ = tm->cm_targ; in mprsas_remove_complete()
653 KASSERT(TAILQ_FIRST(&targ->commands) == NULL, in mprsas_remove_complete()
661 if ((tm->cm_flags & MPR_CM_FLAGS_ERROR_MASK) != 0) { in mprsas_remove_complete()
664 tm->cm_flags, handle); in mprsas_remove_complete()
678 __func__, handle, le16toh(reply->IOCStatus)); in mprsas_remove_complete()
686 if ((le16toh(reply->IOCStatus) & MPI2_IOCSTATUS_MASK) == in mprsas_remove_complete()
688 targ->handle = 0x0; in mprsas_remove_complete()
689 targ->encl_handle = 0x0; in mprsas_remove_complete()
690 targ->encl_level_valid = 0x0; in mprsas_remove_complete()
691 targ->encl_level = 0x0; in mprsas_remove_complete()
692 targ->connector_name[0] = ' '; in mprsas_remove_complete()
693 targ->connector_name[1] = ' '; in mprsas_remove_complete()
694 targ->connector_name[2] = ' '; in mprsas_remove_complete()
695 targ->connector_name[3] = ' '; in mprsas_remove_complete()
696 targ->encl_slot = 0x0; in mprsas_remove_complete()
697 targ->exp_dev_handle = 0x0; in mprsas_remove_complete()
698 targ->phy_num = 0x0; in mprsas_remove_complete()
699 targ->linkrate = 0x0; in mprsas_remove_complete()
700 targ->devinfo = 0x0; in mprsas_remove_complete()
701 targ->flags = 0x0; in mprsas_remove_complete()
702 targ->scsi_req_desc_type = 0; in mprsas_remove_complete()
704 while (!SLIST_EMPTY(&targ->luns)) { in mprsas_remove_complete()
705 lun = SLIST_FIRST(&targ->luns); in mprsas_remove_complete()
706 SLIST_REMOVE_HEAD(&targ->luns, lun_link); in mprsas_remove_complete()
733 if (sc->facts->MsgVersion >= MPI2_VERSION_02_06) { in mprsas_register_events()
735 if (sc->mpr_flags & MPR_FLAGS_GEN35_IOC) { in mprsas_register_events()
743 &sc->sassc->mprsas_eh); in mprsas_register_events()
766 sassc->maxtargets = sc->facts->MaxTargets + sc->facts->MaxVolumes; in mpr_attach_sas()
767 sassc->targets = malloc(sizeof(struct mprsas_target) * in mpr_attach_sas()
768 sassc->maxtargets, M_MPR, M_WAITOK|M_ZERO); in mpr_attach_sas()
769 sc->sassc = sassc; in mpr_attach_sas()
770 sassc->sc = sc; in mpr_attach_sas()
772 reqs = sc->num_reqs - sc->num_prireqs - 1; in mpr_attach_sas()
773 if ((sassc->devq = cam_simq_alloc(reqs)) == NULL) { in mpr_attach_sas()
779 unit = device_get_unit(sc->mpr_dev); in mpr_attach_sas()
780 sassc->sim = cam_sim_alloc(mprsas_action, mprsas_poll, "mpr", sassc, in mpr_attach_sas()
781 unit, &sc->mpr_mtx, reqs, reqs, sassc->devq); in mpr_attach_sas()
782 if (sassc->sim == NULL) { in mpr_attach_sas()
788 TAILQ_INIT(&sassc->ev_queue); in mpr_attach_sas()
791 TASK_INIT(&sassc->ev_task, 0, mprsas_firmware_event_work, sc); in mpr_attach_sas()
792 sassc->ev_tq = taskqueue_create("mpr_taskq", M_NOWAIT | M_ZERO, in mpr_attach_sas()
793 taskqueue_thread_enqueue, &sassc->ev_tq); in mpr_attach_sas()
794 taskqueue_start_threads(&sassc->ev_tq, 1, PRIBIO, "%s taskq", in mpr_attach_sas()
795 device_get_nameunit(sc->mpr_dev)); in mpr_attach_sas()
804 if ((error = xpt_bus_register(sassc->sim, sc->mpr_dev, 0)) != 0) { in mpr_attach_sas()
816 sassc->flags |= MPRSAS_IN_STARTUP | MPRSAS_IN_DISCOVERY; in mpr_attach_sas()
817 sc->sassc->startup_refcount = 0; in mpr_attach_sas()
826 status = xpt_create_path(&sassc->path, /*periph*/NULL, in mpr_attach_sas()
827 cam_sim_path(sc->sassc->sim), CAM_TARGET_WILDCARD, in mpr_attach_sas()
832 sassc->path = NULL; in mpr_attach_sas()
838 sassc->path); in mpr_attach_sas()
844 xpt_free_path(sassc->path); in mpr_attach_sas()
845 sassc->path = NULL; in mpr_attach_sas()
875 if (sc->sassc == NULL) in mpr_detach_sas()
878 sassc = sc->sassc; in mpr_detach_sas()
879 mpr_deregister_events(sc, sassc->mprsas_eh); in mpr_detach_sas()
886 if (sassc->ev_tq != NULL) in mpr_detach_sas()
887 taskqueue_free(sassc->ev_tq); in mpr_detach_sas()
890 if (sassc->path != NULL) { in mpr_detach_sas()
891 xpt_register_async(0, mprsas_async, sc, sassc->path); in mpr_detach_sas()
892 xpt_free_path(sassc->path); in mpr_detach_sas()
893 sassc->path = NULL; in mpr_detach_sas()
899 while (sassc->startup_refcount != 0) in mpr_detach_sas()
902 if (sassc->flags & MPRSAS_IN_STARTUP) in mpr_detach_sas()
903 xpt_release_simq(sassc->sim, 1); in mpr_detach_sas()
905 if (sassc->sim != NULL) { in mpr_detach_sas()
906 xpt_bus_deregister(cam_sim_path(sassc->sim)); in mpr_detach_sas()
907 cam_sim_free(sassc->sim, FALSE); in mpr_detach_sas()
912 if (sassc->devq != NULL) in mpr_detach_sas()
913 cam_simq_free(sassc->devq); in mpr_detach_sas()
915 for (i = 0; i < sassc->maxtargets; i++) { in mpr_detach_sas()
916 targ = &sassc->targets[i]; in mpr_detach_sas()
917 SLIST_FOREACH_SAFE(lun, &targ->luns, lun_link, lun_tmp) { in mpr_detach_sas()
921 free(sassc->targets, M_MPR); in mpr_detach_sas()
923 sc->sassc = NULL; in mpr_detach_sas()
931 struct mpr_softc *sc = sassc->sc; in mprsas_discovery_end()
946 if (sc->track_mapping_events) { in mprsas_discovery_end()
950 callout_reset(&sc->device_check_callout, in mprsas_discovery_end()
963 MPR_FUNCTRACE(sassc->sc); in mprsas_action()
964 mpr_dprint(sassc->sc, MPR_TRACE, "ccb func_code 0x%x\n", in mprsas_action()
965 ccb->ccb_h.func_code); in mprsas_action()
966 mtx_assert(&sassc->sc->mpr_mtx, MA_OWNED); in mprsas_action()
968 switch (ccb->ccb_h.func_code) { in mprsas_action()
971 struct ccb_pathinq *cpi = &ccb->cpi; in mprsas_action()
972 struct mpr_softc *sc = sassc->sc; in mprsas_action()
974 cpi->version_num = 1; in mprsas_action()
975 cpi->hba_inquiry = PI_SDTR_ABLE|PI_TAG_ABLE|PI_WIDE_16; in mprsas_action()
976 cpi->target_sprt = 0; in mprsas_action()
977 cpi->hba_misc = PIM_NOBUSRESET | PIM_UNMAPPED | PIM_NOSCAN; in mprsas_action()
978 cpi->hba_eng_cnt = 0; in mprsas_action()
979 cpi->max_target = sassc->maxtargets - 1; in mprsas_action()
980 cpi->max_lun = 255; in mprsas_action()
986 cpi->initiator_id = sassc->maxtargets; in mprsas_action()
987 strlcpy(cpi->sim_vid, "FreeBSD", SIM_IDLEN); in mprsas_action()
988 strlcpy(cpi->hba_vid, "Avago Tech", HBA_IDLEN); in mprsas_action()
989 strlcpy(cpi->dev_name, cam_sim_name(sim), DEV_IDLEN); in mprsas_action()
990 cpi->unit_number = cam_sim_unit(sim); in mprsas_action()
991 cpi->bus_id = cam_sim_bus(sim); in mprsas_action()
993 * XXXSLM-I think this needs to change based on config page or in mprsas_action()
996 cpi->base_transfer_speed = 150000; in mprsas_action()
997 cpi->transport = XPORT_SAS; in mprsas_action()
998 cpi->transport_version = 0; in mprsas_action()
999 cpi->protocol = PROTO_SCSI; in mprsas_action()
1000 cpi->protocol_version = SCSI_REV_SPC; in mprsas_action()
1001 cpi->maxio = sc->maxio; in mprsas_action()
1012 cts = &ccb->cts; in mprsas_action()
1013 sas = &cts->xport_specific.sas; in mprsas_action()
1014 scsi = &cts->proto_specific.scsi; in mprsas_action()
1016 KASSERT(cts->ccb_h.target_id < sassc->maxtargets, in mprsas_action()
1018 cts->ccb_h.target_id)); in mprsas_action()
1019 targ = &sassc->targets[cts->ccb_h.target_id]; in mprsas_action()
1020 if (targ->handle == 0x0) { in mprsas_action()
1025 cts->protocol_version = SCSI_REV_SPC2; in mprsas_action()
1026 cts->transport = XPORT_SAS; in mprsas_action()
1027 cts->transport_version = 0; in mprsas_action()
1029 sas->valid = CTS_SAS_VALID_SPEED; in mprsas_action()
1030 switch (targ->linkrate) { in mprsas_action()
1032 sas->bitrate = 150000; in mprsas_action()
1035 sas->bitrate = 300000; in mprsas_action()
1038 sas->bitrate = 600000; in mprsas_action()
1041 sas->bitrate = 1200000; in mprsas_action()
1044 sas->valid = 0; in mprsas_action()
1047 cts->protocol = PROTO_SCSI; in mprsas_action()
1048 scsi->valid = CTS_SCSI_VALID_TQ; in mprsas_action()
1049 scsi->flags = CTS_SCSI_FLAGS_TAG_ENB; in mprsas_action()
1055 cam_calc_geometry(&ccb->ccg, /*extended*/1); in mprsas_action()
1059 mpr_dprint(sassc->sc, MPR_XINFO, "mprsas_action " in mprsas_action()
1066 mpr_dprint(sassc->sc, MPR_XINFO, "mprsas_action faking success " in mprsas_action()
1088 path_id_t path_id = cam_sim_path(sc->sassc->sim); in mprsas_announce_reset()
1113 mtx_assert(&sc->mpr_mtx, MA_OWNED); in mprsas_complete_all_commands()
1116 for (i = 1; i < sc->num_reqs; i++) { in mprsas_complete_all_commands()
1117 cm = &sc->commands[i]; in mprsas_complete_all_commands()
1118 if (cm->cm_state == MPR_CM_STATE_FREE) in mprsas_complete_all_commands()
1121 cm->cm_state = MPR_CM_STATE_BUSY; in mprsas_complete_all_commands()
1122 cm->cm_reply = NULL; in mprsas_complete_all_commands()
1125 if (cm->cm_flags & MPR_CM_FLAGS_SATA_ID_TIMEOUT) { in mprsas_complete_all_commands()
1126 MPASS(cm->cm_data); in mprsas_complete_all_commands()
1127 free(cm->cm_data, M_MPR); in mprsas_complete_all_commands()
1128 cm->cm_data = NULL; in mprsas_complete_all_commands()
1131 if (cm->cm_flags & MPR_CM_FLAGS_POLLED) in mprsas_complete_all_commands()
1132 cm->cm_flags |= MPR_CM_FLAGS_COMPLETE; in mprsas_complete_all_commands()
1134 if (cm->cm_complete != NULL) { in mprsas_complete_all_commands()
1137 cm, cm->cm_state, cm->cm_ccb); in mprsas_complete_all_commands()
1138 cm->cm_complete(sc, cm); in mprsas_complete_all_commands()
1140 } else if (cm->cm_flags & MPR_CM_FLAGS_WAKEUP) { in mprsas_complete_all_commands()
1143 cm, cm->cm_state, cm->cm_ccb); in mprsas_complete_all_commands()
1148 if ((completed == 0) && (cm->cm_state != MPR_CM_STATE_FREE)) { in mprsas_complete_all_commands()
1152 "reset\n", cm, cm->cm_state, cm->cm_flags, in mprsas_complete_all_commands()
1153 cm->cm_ccb); in mprsas_complete_all_commands()
1157 sc->io_cmds_active = 0; in mprsas_complete_all_commands()
1170 * discovery-related activities have finished, the simq will be in mprsas_handle_reinit()
1174 sc->sassc->flags |= MPRSAS_IN_STARTUP; in mprsas_handle_reinit()
1175 sc->sassc->flags |= MPRSAS_IN_DISCOVERY; in mprsas_handle_reinit()
1176 mprsas_startup_increment(sc->sassc); in mprsas_handle_reinit()
1186 __func__, sc->sassc->startup_refcount); in mprsas_handle_reinit()
1192 for (i = 0; i < sc->sassc->maxtargets; i++) { in mprsas_handle_reinit()
1193 if (sc->sassc->targets[i].outstanding != 0) in mprsas_handle_reinit()
1195 i, sc->sassc->targets[i].outstanding); in mprsas_handle_reinit()
1196 sc->sassc->targets[i].handle = 0x0; in mprsas_handle_reinit()
1197 sc->sassc->targets[i].exp_dev_handle = 0x0; in mprsas_handle_reinit()
1198 sc->sassc->targets[i].outstanding = 0; in mprsas_handle_reinit()
1199 sc->sassc->targets[i].flags = MPRSAS_TARGET_INDIAGRESET; in mprsas_handle_reinit()
1206 struct mpr_softc *sc = tm->cm_sc; in mprsas_tm_timeout()
1208 mtx_assert(&sc->mpr_mtx, MA_OWNED); in mprsas_tm_timeout()
1213 KASSERT(tm->cm_state == MPR_CM_STATE_INQUEUE, in mprsas_tm_timeout()
1214 ("command not inqueue, state = %u\n", tm->cm_state)); in mprsas_tm_timeout()
1216 tm->cm_state = MPR_CM_STATE_BUSY; in mprsas_tm_timeout()
1228 callout_stop(&tm->cm_callout); in mprsas_logical_unit_reset_complete()
1230 reply = (MPI2_SCSI_TASK_MANAGE_REPLY *)tm->cm_reply; in mprsas_logical_unit_reset_complete()
1231 targ = tm->cm_targ; in mprsas_logical_unit_reset_complete()
1238 if ((tm->cm_flags & MPR_CM_FLAGS_ERROR_MASK) != 0) { in mprsas_logical_unit_reset_complete()
1241 "This should not happen!\n", __func__, tm->cm_flags); in mprsas_logical_unit_reset_complete()
1249 if ((sc->mpr_flags & MPR_FLAGS_DIAGRESET) != 0) { in mprsas_logical_unit_reset_complete()
1253 targ->tm = NULL; in mprsas_logical_unit_reset_complete()
1267 le16toh(reply->IOCStatus), le32toh(reply->ResponseCode), in mprsas_logical_unit_reset_complete()
1268 le32toh(reply->TerminationCount)); in mprsas_logical_unit_reset_complete()
1272 * This could be made more efficient by using a per-LU data in mprsas_logical_unit_reset_complete()
1275 TAILQ_FOREACH(cm, &targ->commands, cm_link) { in mprsas_logical_unit_reset_complete()
1276 if (cm->cm_lun == tm->cm_lun) in mprsas_logical_unit_reset_complete()
1283 targ->tid); in mprsas_logical_unit_reset_complete()
1285 mprsas_announce_reset(sc, AC_SENT_BDR, targ->tid, in mprsas_logical_unit_reset_complete()
1286 tm->cm_lun); in mprsas_logical_unit_reset_complete()
1293 cm = TAILQ_FIRST(&targ->timedout_commands); in mprsas_logical_unit_reset_complete()
1296 "More commands to abort for target %u\n", targ->tid); in mprsas_logical_unit_reset_complete()
1299 targ->tm = NULL; in mprsas_logical_unit_reset_complete()
1309 "have %u command(s), sending target reset\n", targ->tid, in mprsas_logical_unit_reset_complete()
1311 if (!targ->is_nvme || sc->custom_nvme_tm_handling) in mprsas_logical_unit_reset_complete()
1326 callout_stop(&tm->cm_callout); in mprsas_target_reset_complete()
1328 req = (MPI2_SCSI_TASK_MANAGE_REQUEST *)tm->cm_req; in mprsas_target_reset_complete()
1329 reply = (MPI2_SCSI_TASK_MANAGE_REPLY *)tm->cm_reply; in mprsas_target_reset_complete()
1330 targ = tm->cm_targ; in mprsas_target_reset_complete()
1337 if ((tm->cm_flags & MPR_CM_FLAGS_ERROR_MASK) != 0) { in mprsas_target_reset_complete()
1339 "reset! This should not happen!\n", __func__, tm->cm_flags); in mprsas_target_reset_complete()
1347 tm, le16toh(req->TaskMID)); in mprsas_target_reset_complete()
1348 if ((sc->mpr_flags & MPR_FLAGS_DIAGRESET) != 0) { in mprsas_target_reset_complete()
1352 targ->tm = NULL; in mprsas_target_reset_complete()
1366 le16toh(reply->IOCStatus), le32toh(reply->ResponseCode), in mprsas_target_reset_complete()
1367 le32toh(reply->TerminationCount)); in mprsas_target_reset_complete()
1369 if (targ->outstanding == 0) { in mprsas_target_reset_complete()
1375 "Finished reset recovery for target %u\n", targ->tid); in mprsas_target_reset_complete()
1377 mprsas_announce_reset(sc, AC_SENT_BDR, tm->cm_targ->tid, in mprsas_target_reset_complete()
1380 targ->tm = NULL; in mprsas_target_reset_complete()
1390 "command(s), resetting controller\n", targ->tid, in mprsas_target_reset_complete()
1391 targ->outstanding); in mprsas_target_reset_complete()
1405 target = tm->cm_targ; in mprsas_send_reset()
1406 if (target->handle == 0) { in mprsas_send_reset()
1408 "%d\n", __func__, target->tid); in mprsas_send_reset()
1409 return -1; in mprsas_send_reset()
1412 req = (MPI2_SCSI_TASK_MANAGE_REQUEST *)tm->cm_req; in mprsas_send_reset()
1413 req->DevHandle = htole16(target->handle); in mprsas_send_reset()
1414 req->TaskType = type; in mprsas_send_reset()
1416 if (!target->is_nvme || sc->custom_nvme_tm_handling) { in mprsas_send_reset()
1422 req->MsgFlags = MPI2_SCSITASKMGMT_MSGFLAGS_LINK_RESET; in mprsas_send_reset()
1424 timeout = (target->controller_reset_timeout) ? ( in mprsas_send_reset()
1425 target->controller_reset_timeout) : (MPR_RESET_TIMEOUT); in mprsas_send_reset()
1427 req->MsgFlags = in mprsas_send_reset()
1433 MPR_SET_LUN(req->LUN, tm->cm_lun); in mprsas_send_reset()
1434 tm->cm_targ->logical_unit_resets++; in mprsas_send_reset()
1437 target->tid, tm->cm_lun); in mprsas_send_reset()
1438 tm->cm_complete = mprsas_logical_unit_reset_complete; in mprsas_send_reset()
1439 mprsas_prepare_for_tm(sc, tm, target, tm->cm_lun); in mprsas_send_reset()
1441 tm->cm_targ->target_resets++; in mprsas_send_reset()
1443 "Sending target reset to target %u\n", target->tid); in mprsas_send_reset()
1444 tm->cm_complete = mprsas_target_reset_complete; in mprsas_send_reset()
1449 return -1; in mprsas_send_reset()
1452 if (target->encl_level_valid) { in mprsas_send_reset()
1455 target->encl_level, target->encl_slot, in mprsas_send_reset()
1456 target->connector_name); in mprsas_send_reset()
1459 tm->cm_data = NULL; in mprsas_send_reset()
1460 tm->cm_complete_data = (void *)tm; in mprsas_send_reset()
1462 callout_reset(&tm->cm_callout, timeout * hz, in mprsas_send_reset()
1481 callout_stop(&tm->cm_callout); in mprsas_abort_complete()
1483 req = (MPI2_SCSI_TASK_MANAGE_REQUEST *)tm->cm_req; in mprsas_abort_complete()
1484 reply = (MPI2_SCSI_TASK_MANAGE_REPLY *)tm->cm_reply; in mprsas_abort_complete()
1485 targ = tm->cm_targ; in mprsas_abort_complete()
1492 if ((tm->cm_flags & MPR_CM_FLAGS_ERROR_MASK) != 0) { in mprsas_abort_complete()
1495 tm->cm_flags, tm, le16toh(req->TaskMID)); in mprsas_abort_complete()
1503 tm, le16toh(req->TaskMID)); in mprsas_abort_complete()
1504 if ((sc->mpr_flags & MPR_FLAGS_DIAGRESET) != 0) { in mprsas_abort_complete()
1508 targ->tm = NULL; in mprsas_abort_complete()
1521 le16toh(req->TaskMID), in mprsas_abort_complete()
1522 le16toh(reply->IOCStatus), le32toh(reply->ResponseCode), in mprsas_abort_complete()
1523 le32toh(reply->TerminationCount)); in mprsas_abort_complete()
1525 cm = TAILQ_FIRST(&tm->cm_targ->timedout_commands); in mprsas_abort_complete()
1532 "Finished abort recovery for target %u\n", targ->tid); in mprsas_abort_complete()
1533 targ->tm = NULL; in mprsas_abort_complete()
1535 } else if (le16toh(req->TaskMID) != cm->cm_desc.Default.SMID) { in mprsas_abort_complete()
1538 "Continuing abort recovery for target %u\n", targ->tid); in mprsas_abort_complete()
1547 targ->tid); in mprsas_abort_complete()
1564 targ = cm->cm_targ; in mprsas_send_abort()
1565 if (targ->handle == 0) { in mprsas_send_abort()
1568 __func__, cm->cm_ccb->ccb_h.target_id); in mprsas_send_abort()
1569 return -1; in mprsas_send_abort()
1575 req = (MPI2_SCSI_TASK_MANAGE_REQUEST *)tm->cm_req; in mprsas_send_abort()
1576 req->DevHandle = htole16(targ->handle); in mprsas_send_abort()
1577 req->TaskType = MPI2_SCSITASKMGMT_TASKTYPE_ABORT_TASK; in mprsas_send_abort()
1580 MPR_SET_LUN(req->LUN, cm->cm_ccb->ccb_h.target_lun); in mprsas_send_abort()
1582 req->TaskMID = htole16(cm->cm_desc.Default.SMID); in mprsas_send_abort()
1584 tm->cm_data = NULL; in mprsas_send_abort()
1585 tm->cm_complete = mprsas_abort_complete; in mprsas_send_abort()
1586 tm->cm_complete_data = (void *)tm; in mprsas_send_abort()
1587 tm->cm_targ = cm->cm_targ; in mprsas_send_abort()
1588 tm->cm_lun = cm->cm_lun; in mprsas_send_abort()
1590 if (!targ->is_nvme || sc->custom_nvme_tm_handling) in mprsas_send_abort()
1593 timeout = sc->nvme_abort_timeout; in mprsas_send_abort()
1595 callout_reset(&tm->cm_callout, timeout * hz, in mprsas_send_abort()
1598 targ->aborts++; in mprsas_send_abort()
1600 mprsas_prepare_for_tm(sc, tm, targ, tm->cm_lun); in mprsas_send_abort()
1606 err, cm, req->TaskMID); in mprsas_send_abort()
1620 sc = cm->cm_sc; in mprsas_scsiio_timeout()
1621 ccb = cm->cm_ccb; in mprsas_scsiio_timeout()
1625 mtx_assert(&sc->mpr_mtx, MA_OWNED); in mprsas_scsiio_timeout()
1632 * and been re-used, though this is unlikely. in mprsas_scsiio_timeout()
1635 if (cm->cm_flags & MPR_CM_FLAGS_ON_RECOVERY) { in mprsas_scsiio_timeout()
1641 if (cm->cm_ccb == NULL) { in mprsas_scsiio_timeout()
1646 targ = cm->cm_targ; in mprsas_scsiio_timeout()
1647 targ->timeouts++; in mprsas_scsiio_timeout()
1649 elapsed = now - ccb->ccb_h.qos.sim_data; in mprsas_scsiio_timeout()
1652 targ->tid, targ->handle, ccb->ccb_h.timeout, in mprsas_scsiio_timeout()
1654 if (targ->encl_level_valid) { in mprsas_scsiio_timeout()
1657 targ->encl_level, targ->encl_slot, targ->connector_name); in mprsas_scsiio_timeout()
1663 mprsas_set_ccbstatus(cm->cm_ccb, CAM_CMD_TIMEOUT); in mprsas_scsiio_timeout()
1664 cm->cm_flags |= MPR_CM_FLAGS_ON_RECOVERY | MPR_CM_FLAGS_TIMEDOUT; in mprsas_scsiio_timeout()
1665 TAILQ_INSERT_TAIL(&targ->timedout_commands, cm, cm_recovery); in mprsas_scsiio_timeout()
1667 if (targ->tm != NULL) { in mprsas_scsiio_timeout()
1673 cm, targ->tm); in mprsas_scsiio_timeout()
1674 } else if ((targ->tm = mprsas_alloc_tm(sc)) != NULL) { in mprsas_scsiio_timeout()
1676 "Sending abort to target %u for SMID %d\n", targ->tid, in mprsas_scsiio_timeout()
1677 cm->cm_desc.Default.SMID); in mprsas_scsiio_timeout()
1679 cm, targ->tm); in mprsas_scsiio_timeout()
1682 mprsas_send_abort(sc, targ->tm, cm); in mprsas_scsiio_timeout()
1699 * mprsas_build_nvme_unmap - Build Native NVMe DSM command equivalent
1701 * Return 0 - for success,
1702 * 1 - to immediately return back the command with success status to CAM
1703 * negative value - to fallback to firmware path i.e. issue scsi unmap
1720 csio = &ccb->csio; in mprsas_build_nvme_unmap()
1724 return -EINVAL; in mprsas_build_nvme_unmap()
1727 plist = malloc(csio->dxfer_len, M_MPR, M_ZERO|M_NOWAIT); in mprsas_build_nvme_unmap()
1731 return -ENOMEM; in mprsas_build_nvme_unmap()
1735 bcopy(csio->data_ptr, plist, csio->dxfer_len); in mprsas_build_nvme_unmap()
1740 ndesc = be16toh(plist->unmap_blk_desc_data_len) >> 4; in mprsas_build_nvme_unmap()
1749 if (data_length > targ->MDTS) { in mprsas_build_nvme_unmap()
1751 "Device's MDTS: %d\n", data_length, targ->MDTS); in mprsas_build_nvme_unmap()
1752 res = -EINVAL; in mprsas_build_nvme_unmap()
1764 TAILQ_INSERT_TAIL(&cm->cm_prp_page_list, prp_page_info, prp_page_link); in mprsas_build_nvme_unmap()
1766 nvme_dsm_ranges = (struct nvme_dsm_range *)prp_page_info->prp_page; in mprsas_build_nvme_unmap()
1767 nvme_dsm_ranges_dma_handle = prp_page_info->prp_page_busaddr; in mprsas_build_nvme_unmap()
1776 htole32(be32toh(plist->desc[i].nlb)); in mprsas_build_nvme_unmap()
1778 htole64(be64toh(plist->desc[i].slba)); in mprsas_build_nvme_unmap()
1783 req = (Mpi26NVMeEncapsulatedRequest_t *)cm->cm_req; in mprsas_build_nvme_unmap()
1785 req->DevHandle = htole16(targ->handle); in mprsas_build_nvme_unmap()
1786 req->Function = MPI2_FUNCTION_NVME_ENCAPSULATED; in mprsas_build_nvme_unmap()
1787 req->Flags = MPI26_NVME_FLAGS_WRITE; in mprsas_build_nvme_unmap()
1788 req->ErrorResponseBaseAddress.High = in mprsas_build_nvme_unmap()
1789 htole32((uint32_t)((uint64_t)cm->cm_sense_busaddr >> 32)); in mprsas_build_nvme_unmap()
1790 req->ErrorResponseBaseAddress.Low = in mprsas_build_nvme_unmap()
1791 htole32(cm->cm_sense_busaddr); in mprsas_build_nvme_unmap()
1792 req->ErrorResponseAllocationLength = in mprsas_build_nvme_unmap()
1794 req->EncapsulatedCommandLength = in mprsas_build_nvme_unmap()
1796 req->DataLength = htole32(data_length); in mprsas_build_nvme_unmap()
1799 c = (struct nvme_command *) req->NVMe_Command; in mprsas_build_nvme_unmap()
1800 c->opc = NVME_OPC_DATASET_MANAGEMENT; in mprsas_build_nvme_unmap()
1801 c->nsid = htole32(csio->ccb_h.target_lun + 1); in mprsas_build_nvme_unmap()
1802 c->cdw10 = htole32(ndesc - 1); in mprsas_build_nvme_unmap()
1803 c->cdw11 = htole32(NVME_DSM_ATTR_DEALLOCATE); in mprsas_build_nvme_unmap()
1805 cm->cm_length = data_length; in mprsas_build_nvme_unmap()
1806 cm->cm_data = NULL; in mprsas_build_nvme_unmap()
1808 cm->cm_complete = mprsas_scsiio_complete; in mprsas_build_nvme_unmap()
1809 cm->cm_complete_data = ccb; in mprsas_build_nvme_unmap()
1810 cm->cm_targ = targ; in mprsas_build_nvme_unmap()
1811 cm->cm_lun = csio->ccb_h.target_lun; in mprsas_build_nvme_unmap()
1812 cm->cm_ccb = ccb; in mprsas_build_nvme_unmap()
1814 cm->cm_desc.Default.RequestFlags = in mprsas_build_nvme_unmap()
1817 csio->ccb_h.qos.sim_data = sbinuptime(); in mprsas_build_nvme_unmap()
1818 callout_reset_sbt(&cm->cm_callout, SBT_1MS * ccb->ccb_h.timeout, 0, in mprsas_build_nvme_unmap()
1821 targ->issued++; in mprsas_build_nvme_unmap()
1822 targ->outstanding++; in mprsas_build_nvme_unmap()
1823 TAILQ_INSERT_TAIL(&targ->commands, cm, cm_link); in mprsas_build_nvme_unmap()
1824 ccb->ccb_h.status |= CAM_SIM_QUEUED; in mprsas_build_nvme_unmap()
1827 __func__, cm, ccb, targ->outstanding); in mprsas_build_nvme_unmap()
1853 sc = sassc->sc; in mprsas_action_scsiio()
1855 mtx_assert(&sc->mpr_mtx, MA_OWNED); in mprsas_action_scsiio()
1857 csio = &ccb->csio; in mprsas_action_scsiio()
1858 KASSERT(csio->ccb_h.target_id < sassc->maxtargets, in mprsas_action_scsiio()
1860 csio->ccb_h.target_id)); in mprsas_action_scsiio()
1861 targ = &sassc->targets[csio->ccb_h.target_id]; in mprsas_action_scsiio()
1862 mpr_dprint(sc, MPR_TRACE, "ccb %p target flag %x\n", ccb, targ->flags); in mprsas_action_scsiio()
1863 if (targ->handle == 0x0) { in mprsas_action_scsiio()
1864 if (targ->flags & MPRSAS_TARGET_INDIAGRESET) { in mprsas_action_scsiio()
1867 __func__, csio->ccb_h.target_id); in mprsas_action_scsiio()
1868 ccb->ccb_h.status = CAM_REQUEUE_REQ | CAM_DEV_QFRZN; in mprsas_action_scsiio()
1869 xpt_freeze_devq(ccb->ccb_h.path, 1); in mprsas_action_scsiio()
1874 __func__, csio->ccb_h.target_id); in mprsas_action_scsiio()
1879 if (targ->flags & MPR_TARGET_FLAGS_RAID_COMPONENT) { in mprsas_action_scsiio()
1881 "supported %u\n", __func__, csio->ccb_h.target_id); in mprsas_action_scsiio()
1893 "target %u\n", __func__, csio->ccb_h.target_id); in mprsas_action_scsiio()
1906 if (targ->flags & MPRSAS_TARGET_INREMOVAL) { in mprsas_action_scsiio()
1907 if (targ->devinfo == 0) in mprsas_action_scsiio()
1915 if ((sc->mpr_flags & MPR_FLAGS_SHUTDOWN) != 0) { in mprsas_action_scsiio()
1926 if (targ->flags & MPRSAS_TARGET_INRESET) { in mprsas_action_scsiio()
1927 ccb->ccb_h.status = CAM_REQUEUE_REQ | CAM_DEV_QFRZN; in mprsas_action_scsiio()
1930 __func__, targ->tid); in mprsas_action_scsiio()
1931 xpt_freeze_devq(ccb->ccb_h.path, 1); in mprsas_action_scsiio()
1937 if (cm == NULL || (sc->mpr_flags & MPR_FLAGS_DIAGRESET)) { in mprsas_action_scsiio()
1941 if ((sassc->flags & MPRSAS_QUEUE_FROZEN) == 0) { in mprsas_action_scsiio()
1942 xpt_freeze_simq(sassc->sim, 1); in mprsas_action_scsiio()
1943 sassc->flags |= MPRSAS_QUEUE_FROZEN; in mprsas_action_scsiio()
1945 ccb->ccb_h.status &= ~CAM_SIM_QUEUED; in mprsas_action_scsiio()
1946 ccb->ccb_h.status |= CAM_REQUEUE_REQ; in mprsas_action_scsiio()
1956 targ->is_nvme && in mprsas_action_scsiio()
1957 (csio->ccb_h.flags & CAM_DATA_MASK) == CAM_DATA_VADDR) { in mprsas_action_scsiio()
1968 req = (MPI2_SCSI_IO_REQUEST *)cm->cm_req; in mprsas_action_scsiio()
1970 req->DevHandle = htole16(targ->handle); in mprsas_action_scsiio()
1971 req->Function = MPI2_FUNCTION_SCSI_IO_REQUEST; in mprsas_action_scsiio()
1972 req->MsgFlags = 0; in mprsas_action_scsiio()
1973 req->SenseBufferLowAddress = htole32(cm->cm_sense_busaddr); in mprsas_action_scsiio()
1974 req->SenseBufferLength = MPR_SENSE_LEN; in mprsas_action_scsiio()
1975 req->SGLFlags = 0; in mprsas_action_scsiio()
1976 req->ChainOffset = 0; in mprsas_action_scsiio()
1977 req->SGLOffset0 = 24; /* 32bit word offset to the SGL */ in mprsas_action_scsiio()
1978 req->SGLOffset1= 0; in mprsas_action_scsiio()
1979 req->SGLOffset2= 0; in mprsas_action_scsiio()
1980 req->SGLOffset3= 0; in mprsas_action_scsiio()
1981 req->SkipCount = 0; in mprsas_action_scsiio()
1982 req->DataLength = htole32(csio->dxfer_len); in mprsas_action_scsiio()
1983 req->BidirectionalDataLength = 0; in mprsas_action_scsiio()
1984 req->IoFlags = htole16(csio->cdb_len); in mprsas_action_scsiio()
1985 req->EEDPFlags = 0; in mprsas_action_scsiio()
1988 switch (csio->ccb_h.flags & CAM_DIR_MASK) { in mprsas_action_scsiio()
1991 cm->cm_flags |= MPR_CM_FLAGS_DATAIN; in mprsas_action_scsiio()
1995 cm->cm_flags |= MPR_CM_FLAGS_DATAOUT; in mprsas_action_scsiio()
2003 if (csio->cdb_len == 32) in mprsas_action_scsiio()
2010 switch (csio->tag_action) { in mprsas_action_scsiio()
2026 mpi_control |= (csio->priority << MPI2_SCSIIO_CONTROL_CMDPRI_SHIFT) & in mprsas_action_scsiio()
2028 mpi_control |= sc->mapping_table[csio->ccb_h.target_id].TLR_bits; in mprsas_action_scsiio()
2029 req->Control = htole32(mpi_control); in mprsas_action_scsiio()
2031 if (MPR_SET_LUN(req->LUN, csio->ccb_h.target_lun) != 0) { in mprsas_action_scsiio()
2038 if (csio->ccb_h.flags & CAM_CDB_POINTER) in mprsas_action_scsiio()
2039 bcopy(csio->cdb_io.cdb_ptr, &req->CDB.CDB32[0], csio->cdb_len); in mprsas_action_scsiio()
2041 KASSERT(csio->cdb_len <= IOCDBLEN, in mprsas_action_scsiio()
2043 "is not set", csio->cdb_len)); in mprsas_action_scsiio()
2044 bcopy(csio->cdb_io.cdb_bytes, &req->CDB.CDB32[0],csio->cdb_len); in mprsas_action_scsiio()
2046 req->IoFlags = htole16(csio->cdb_len); in mprsas_action_scsiio()
2054 eedp_flags = op_code_prot[req->CDB.CDB32[0]]; in mprsas_action_scsiio()
2055 if (sc->eedp_enabled && eedp_flags) { in mprsas_action_scsiio()
2056 SLIST_FOREACH(lun, &targ->luns, lun_link) { in mprsas_action_scsiio()
2057 if (lun->lun_id == csio->ccb_h.target_lun) { in mprsas_action_scsiio()
2062 if ((lun != NULL) && (lun->eedp_formatted)) { in mprsas_action_scsiio()
2063 req->EEDPBlockSize = htole32(lun->eedp_block_size); in mprsas_action_scsiio()
2067 if (sc->mpr_flags & MPR_FLAGS_GEN35_IOC) { in mprsas_action_scsiio()
2071 req->EEDPFlags = htole16(eedp_flags); in mprsas_action_scsiio()
2081 if (csio->cdb_len != 32) { in mprsas_action_scsiio()
2082 lba_byte = (csio->cdb_len == 16) ? 6 : 2; in mprsas_action_scsiio()
2083 ref_tag_addr = (uint8_t *)&req->CDB.EEDP32. in mprsas_action_scsiio()
2087 req->CDB.CDB32[lba_byte + i]; in mprsas_action_scsiio()
2090 req->CDB.EEDP32.PrimaryReferenceTag = in mprsas_action_scsiio()
2091 htole32(req-> in mprsas_action_scsiio()
2093 req->CDB.EEDP32.PrimaryApplicationTagMask = in mprsas_action_scsiio()
2095 req->CDB.CDB32[1] = in mprsas_action_scsiio()
2096 (req->CDB.CDB32[1] & 0x1F) | 0x20; in mprsas_action_scsiio()
2100 req->EEDPFlags = htole16(eedp_flags); in mprsas_action_scsiio()
2101 req->CDB.CDB32[10] = (req->CDB.CDB32[10] & in mprsas_action_scsiio()
2107 cm->cm_length = csio->dxfer_len; in mprsas_action_scsiio()
2108 if (cm->cm_length != 0) { in mprsas_action_scsiio()
2109 cm->cm_data = ccb; in mprsas_action_scsiio()
2110 cm->cm_flags |= MPR_CM_FLAGS_USE_CCB; in mprsas_action_scsiio()
2112 cm->cm_data = NULL; in mprsas_action_scsiio()
2114 cm->cm_sge = &req->SGL; in mprsas_action_scsiio()
2115 cm->cm_sglsize = (32 - 24) * 4; in mprsas_action_scsiio()
2116 cm->cm_complete = mprsas_scsiio_complete; in mprsas_action_scsiio()
2117 cm->cm_complete_data = ccb; in mprsas_action_scsiio()
2118 cm->cm_targ = targ; in mprsas_action_scsiio()
2119 cm->cm_lun = csio->ccb_h.target_lun; in mprsas_action_scsiio()
2120 cm->cm_ccb = ccb; in mprsas_action_scsiio()
2125 if (targ->scsi_req_desc_type == in mprsas_action_scsiio()
2127 req->IoFlags |= MPI25_SCSIIO_IOFLAGS_FAST_PATH; in mprsas_action_scsiio()
2128 cm->cm_desc.FastPathSCSIIO.RequestFlags = in mprsas_action_scsiio()
2130 if (!sc->atomic_desc_capable) { in mprsas_action_scsiio()
2131 cm->cm_desc.FastPathSCSIIO.DevHandle = in mprsas_action_scsiio()
2132 htole16(targ->handle); in mprsas_action_scsiio()
2135 cm->cm_desc.SCSIIO.RequestFlags = in mprsas_action_scsiio()
2137 if (!sc->atomic_desc_capable) in mprsas_action_scsiio()
2138 cm->cm_desc.SCSIIO.DevHandle = htole16(targ->handle); in mprsas_action_scsiio()
2141 csio->ccb_h.qos.sim_data = sbinuptime(); in mprsas_action_scsiio()
2142 callout_reset_sbt(&cm->cm_callout, SBT_1MS * ccb->ccb_h.timeout, 0, in mprsas_action_scsiio()
2145 targ->issued++; in mprsas_action_scsiio()
2146 targ->outstanding++; in mprsas_action_scsiio()
2147 TAILQ_INSERT_TAIL(&targ->commands, cm, cm_link); in mprsas_action_scsiio()
2148 ccb->ccb_h.status |= CAM_SIM_QUEUED; in mprsas_action_scsiio()
2151 __func__, cm, ccb, targ->outstanding); in mprsas_action_scsiio()
2158 * mpr_sc_failed_io_info - translated non-succesfull SCSI_IO request
2166 u16 ioc_status = le16toh(mpi_reply->IOCStatus) & in mpr_sc_failed_io_info()
2168 u8 scsi_state = mpi_reply->SCSIState; in mpr_sc_failed_io_info()
2169 u8 scsi_status = mpi_reply->SCSIStatus; in mpr_sc_failed_io_info()
2172 u32 log_info = le32toh(mpi_reply->IOCLogInfo); in mpr_sc_failed_io_info()
2183 le16toh(mpi_reply->DevHandle), desc_ioc_state, ioc_status); in mpr_sc_failed_io_info()
2184 if (targ->encl_level_valid) { in mpr_sc_failed_io_info()
2186 "connector name (%4s)\n", targ->encl_level, targ->encl_slot, in mpr_sc_failed_io_info()
2187 targ->connector_name); in mpr_sc_failed_io_info()
2192 * TO-DO in mpr_sc_failed_io_info()
2199 if (sc->mpr_debug & MPR_XINFO && in mpr_sc_failed_io_info()
2201 mpr_dprint(sc, MPR_XINFO, "-> Sense Buffer Data : Start :\n"); in mpr_sc_failed_io_info()
2203 mpr_dprint(sc, MPR_XINFO, "-> Sense Buffer Data : End :\n"); in mpr_sc_failed_io_info()
2207 response_info = le32toh(mpi_reply->ResponseInfo); in mpr_sc_failed_io_info()
2229 union ccb *ccb = cm->cm_complete_data; in mprsas_nvme_trans_status_code()
2380 if (returned_sense_len < ccb->csio.sense_len) in mprsas_nvme_trans_status_code()
2381 ccb->csio.sense_resid = ccb->csio.sense_len - in mprsas_nvme_trans_status_code()
2384 ccb->csio.sense_resid = 0; in mprsas_nvme_trans_status_code()
2386 scsi_set_sense_data(&ccb->csio.sense_data, SSD_TYPE_FIXED, in mprsas_nvme_trans_status_code()
2388 ccb->ccb_h.status |= CAM_AUTOSNS_VALID; in mprsas_nvme_trans_status_code()
2405 mpi_reply =(Mpi26NVMeEncapsulatedErrorReply_t *)cm->cm_reply; in mprsas_complete_nvme_unmap()
2406 if (le16toh(mpi_reply->ErrorResponseCount)){ in mprsas_complete_nvme_unmap()
2407 nvme_completion = (struct nvme_completion *)cm->cm_sense; in mprsas_complete_nvme_unmap()
2409 nvme_completion->status, cm); in mprsas_complete_nvme_unmap()
2417 MPI2_SCSI_IO_REPLY *rep; in mprsas_scsiio_complete() local
2430 callout_stop(&cm->cm_callout); in mprsas_scsiio_complete()
2431 mtx_assert(&sc->mpr_mtx, MA_OWNED); in mprsas_scsiio_complete()
2433 sassc = sc->sassc; in mprsas_scsiio_complete()
2434 ccb = cm->cm_complete_data; in mprsas_scsiio_complete()
2435 csio = &ccb->csio; in mprsas_scsiio_complete()
2436 target_id = csio->ccb_h.target_id; in mprsas_scsiio_complete()
2437 rep = (MPI2_SCSI_IO_REPLY *)cm->cm_reply; in mprsas_scsiio_complete()
2439 "cm %p SMID %u ccb %p reply %p outstanding %u csio->scsi_status 0x%x," in mprsas_scsiio_complete()
2440 "csio->dxfer_len 0x%x, csio->msg_le 0x%xn\n", cm, in mprsas_scsiio_complete()
2441 cm->cm_desc.Default.SMID, cm->cm_ccb, cm->cm_reply, in mprsas_scsiio_complete()
2442 cm->cm_targ->outstanding, csio->scsi_status, in mprsas_scsiio_complete()
2443 csio->dxfer_len, csio->msg_len); in mprsas_scsiio_complete()
2449 if (cm->cm_data != NULL) { in mprsas_scsiio_complete()
2450 if (cm->cm_flags & MPR_CM_FLAGS_DATAIN) in mprsas_scsiio_complete()
2452 else if (cm->cm_flags & MPR_CM_FLAGS_DATAOUT) in mprsas_scsiio_complete()
2454 bus_dmamap_sync(sc->buffer_dmat, cm->cm_dmamap, dir); in mprsas_scsiio_complete()
2455 bus_dmamap_unload(sc->buffer_dmat, cm->cm_dmamap); in mprsas_scsiio_complete()
2458 cm->cm_targ->completed++; in mprsas_scsiio_complete()
2459 cm->cm_targ->outstanding--; in mprsas_scsiio_complete()
2460 TAILQ_REMOVE(&cm->cm_targ->commands, cm, cm_link); in mprsas_scsiio_complete()
2461 ccb->ccb_h.status &= ~(CAM_STATUS_MASK | CAM_SIM_QUEUED); in mprsas_scsiio_complete()
2463 if (cm->cm_flags & MPR_CM_FLAGS_ON_RECOVERY) { in mprsas_scsiio_complete()
2464 TAILQ_REMOVE(&cm->cm_targ->timedout_commands, cm, cm_recovery); in mprsas_scsiio_complete()
2465 KASSERT(cm->cm_state == MPR_CM_STATE_BUSY, in mprsas_scsiio_complete()
2466 ("Not busy for CM_FLAGS_TIMEDOUT: %u\n", cm->cm_state)); in mprsas_scsiio_complete()
2467 cm->cm_flags &= ~MPR_CM_FLAGS_ON_RECOVERY; in mprsas_scsiio_complete()
2468 if (cm->cm_reply != NULL) in mprsas_scsiio_complete()
2471 "ioc %x scsi %x state %x xfer %u\n", cm, cm->cm_ccb, in mprsas_scsiio_complete()
2472 le16toh(rep->IOCStatus), rep->SCSIStatus, in mprsas_scsiio_complete()
2473 rep->SCSIState, le32toh(rep->TransferCount)); in mprsas_scsiio_complete()
2477 cm, cm->cm_ccb); in mprsas_scsiio_complete()
2478 } else if (cm->cm_targ->tm != NULL) { in mprsas_scsiio_complete()
2479 if (cm->cm_reply != NULL) in mprsas_scsiio_complete()
2483 cm, cm->cm_ccb, le16toh(rep->IOCStatus), in mprsas_scsiio_complete()
2484 rep->SCSIStatus, rep->SCSIState, in mprsas_scsiio_complete()
2485 le32toh(rep->TransferCount)); in mprsas_scsiio_complete()
2489 cm, cm->cm_ccb); in mprsas_scsiio_complete()
2490 } else if ((sc->mpr_flags & MPR_FLAGS_DIAGRESET) != 0) { in mprsas_scsiio_complete()
2492 "reset completed cm %p ccb %p\n", cm, cm->cm_ccb); in mprsas_scsiio_complete()
2495 if ((cm->cm_flags & MPR_CM_FLAGS_ERROR_MASK) != 0) { in mprsas_scsiio_complete()
2517 if ((sassc->flags & MPRSAS_QUEUE_FROZEN) == 0) { in mprsas_scsiio_complete()
2518 xpt_freeze_simq(sassc->sim, 1); in mprsas_scsiio_complete()
2519 sassc->flags |= MPRSAS_QUEUE_FROZEN; in mprsas_scsiio_complete()
2539 if (sc->SSU_started && (scsi_cdb[0] == START_STOP_UNIT)) { in mprsas_scsiio_complete()
2541 sc->SSU_refcount--; in mprsas_scsiio_complete()
2545 if (cm->cm_reply == NULL) { in mprsas_scsiio_complete()
2547 if ((sc->mpr_flags & MPR_FLAGS_DIAGRESET) != 0) in mprsas_scsiio_complete()
2551 csio->scsi_status = SCSI_STATUS_OK; in mprsas_scsiio_complete()
2553 if (sassc->flags & MPRSAS_QUEUE_FROZEN) { in mprsas_scsiio_complete()
2554 ccb->ccb_h.status |= CAM_RELEASE_SIMQ; in mprsas_scsiio_complete()
2555 sassc->flags &= ~MPRSAS_QUEUE_FROZEN; in mprsas_scsiio_complete()
2572 ccb->ccb_h.status |= CAM_DEV_QFRZN; in mprsas_scsiio_complete()
2573 xpt_freeze_devq(ccb->ccb_h.path, /*count*/ 1); in mprsas_scsiio_complete()
2580 target = &sassc->targets[target_id]; in mprsas_scsiio_complete()
2582 target->is_nvme && in mprsas_scsiio_complete()
2583 (csio->ccb_h.flags & CAM_DATA_MASK) == CAM_DATA_VADDR) { in mprsas_scsiio_complete()
2584 rep->SCSIStatus = mprsas_complete_nvme_unmap(sc, cm); in mprsas_scsiio_complete()
2585 csio->scsi_status = rep->SCSIStatus; in mprsas_scsiio_complete()
2590 le16toh(rep->IOCStatus), rep->SCSIStatus, rep->SCSIState, in mprsas_scsiio_complete()
2591 le32toh(rep->TransferCount)); in mprsas_scsiio_complete()
2593 switch (le16toh(rep->IOCStatus) & MPI2_IOCSTATUS_MASK) { in mprsas_scsiio_complete()
2595 csio->resid = cm->cm_length - le32toh(rep->TransferCount); in mprsas_scsiio_complete()
2599 if ((le16toh(rep->IOCStatus) & MPI2_IOCSTATUS_MASK) == in mprsas_scsiio_complete()
2604 if (rep->SCSIState & (MPI2_SCSI_STATE_NO_SCSI_STATUS | in mprsas_scsiio_complete()
2614 if (rep->SCSIState & MPI2_SCSI_STATE_AUTOSENSE_FAILED) { in mprsas_scsiio_complete()
2624 if ((rep->SCSIState & MPI2_SCSI_STATE_RESPONSE_INFO_VALID) && in mprsas_scsiio_complete()
2625 ((le32toh(rep->ResponseInfo) & MPI2_SCSI_RI_MASK_REASONCODE) in mprsas_scsiio_complete()
2627 sc->mapping_table[target_id].TLR_bits = in mprsas_scsiio_complete()
2634 * multi-initiator environment, and we want to make sure that in mprsas_scsiio_complete()
2637 if ((rep->SCSIStatus == MPI2_SCSI_STATUS_COMMAND_TERMINATED) || in mprsas_scsiio_complete()
2638 (rep->SCSIStatus == MPI2_SCSI_STATUS_TASK_ABORTED)) { in mprsas_scsiio_complete()
2644 csio->scsi_status = rep->SCSIStatus; in mprsas_scsiio_complete()
2645 if (rep->SCSIStatus == MPI2_SCSI_STATUS_GOOD) in mprsas_scsiio_complete()
2650 if (rep->SCSIState & MPI2_SCSI_STATE_AUTOSENSE_VALID) { in mprsas_scsiio_complete()
2653 returned_sense_len = min(le32toh(rep->SenseCount), in mprsas_scsiio_complete()
2655 if (returned_sense_len < csio->sense_len) in mprsas_scsiio_complete()
2656 csio->sense_resid = csio->sense_len - in mprsas_scsiio_complete()
2659 csio->sense_resid = 0; in mprsas_scsiio_complete()
2662 csio->sense_len - csio->sense_resid); in mprsas_scsiio_complete()
2663 bzero(&csio->sense_data, sizeof(csio->sense_data)); in mprsas_scsiio_complete()
2664 bcopy(cm->cm_sense, &csio->sense_data, sense_len); in mprsas_scsiio_complete()
2665 ccb->ccb_h.status |= CAM_AUTOSNS_VALID; in mprsas_scsiio_complete()
2679 ((csio->ccb_h.flags & CAM_DATA_MASK) == CAM_DATA_VADDR) && in mprsas_scsiio_complete()
2680 (csio->data_ptr != NULL) && in mprsas_scsiio_complete()
2681 ((csio->data_ptr[0] & 0x1f) == T_SEQUENTIAL) && in mprsas_scsiio_complete()
2682 (sc->control_TLR) && in mprsas_scsiio_complete()
2683 (sc->mapping_table[target_id].device_info & in mprsas_scsiio_complete()
2686 csio->data_ptr; in mprsas_scsiio_complete()
2687 TLR_bits = &sc->mapping_table[target_id].TLR_bits; in mprsas_scsiio_complete()
2691 alloc_len -= csio->resid; in mprsas_scsiio_complete()
2692 for (i = 0; i < MIN(vpd_list->length, alloc_len); i++) { in mprsas_scsiio_complete()
2693 if (vpd_list->list[i] == 0x90) { in mprsas_scsiio_complete()
2701 * If this is a SATA direct-access end device, mark it so that in mprsas_scsiio_complete()
2706 (csio->data_ptr != NULL) && in mprsas_scsiio_complete()
2707 ((csio->data_ptr[0] & 0x1f) == T_DIRECT) && in mprsas_scsiio_complete()
2708 (sc->mapping_table[target_id].device_info & in mprsas_scsiio_complete()
2710 ((sc->mapping_table[target_id].device_info & in mprsas_scsiio_complete()
2713 target = &sassc->targets[target_id]; in mprsas_scsiio_complete()
2714 target->supports_SSU = TRUE; in mprsas_scsiio_complete()
2727 if (cm->cm_targ->devinfo == 0) in mprsas_scsiio_complete()
2746 if (cm->cm_flags & MPR_CM_FLAGS_TIMEDOUT) in mprsas_scsiio_complete()
2753 csio->resid = 0; in mprsas_scsiio_complete()
2759 * These can sometimes be transient transport-related in mprsas_scsiio_complete()
2760 * errors, and sometimes persistent drive-related errors. in mprsas_scsiio_complete()
2768 * of a topology-related error (e.g. a SAS expander problem in mprsas_scsiio_complete()
2775 if (cm->cm_targ->flags & MPRSAS_TARGET_INREMOVAL) in mprsas_scsiio_complete()
2782 le16toh(rep->IOCStatus) & MPI2_IOCSTATUS_MASK), in mprsas_scsiio_complete()
2783 target_id, cm->cm_desc.Default.SMID, in mprsas_scsiio_complete()
2784 le32toh(rep->IOCLogInfo), in mprsas_scsiio_complete()
2785 (cm->cm_targ->flags & MPRSAS_TARGET_INREMOVAL) ? " departing" : ""); in mprsas_scsiio_complete()
2788 rep->SCSIStatus, rep->SCSIState, in mprsas_scsiio_complete()
2789 le32toh(rep->TransferCount)); in mprsas_scsiio_complete()
2804 le16toh(rep->IOCStatus), le32toh(rep->IOCLogInfo), in mprsas_scsiio_complete()
2805 rep->SCSIStatus, rep->SCSIState, in mprsas_scsiio_complete()
2806 le32toh(rep->TransferCount)); in mprsas_scsiio_complete()
2807 csio->resid = cm->cm_length; in mprsas_scsiio_complete()
2810 target->is_nvme && in mprsas_scsiio_complete()
2811 (csio->ccb_h.flags & CAM_DATA_MASK) == CAM_DATA_VADDR) in mprsas_scsiio_complete()
2819 mpr_sc_failed_io_info(sc, csio, rep, cm->cm_targ); in mprsas_scsiio_complete()
2821 if (sassc->flags & MPRSAS_QUEUE_FROZEN) { in mprsas_scsiio_complete()
2822 ccb->ccb_h.status |= CAM_RELEASE_SIMQ; in mprsas_scsiio_complete()
2823 sassc->flags &= ~MPRSAS_QUEUE_FROZEN; in mprsas_scsiio_complete()
2829 ccb->ccb_h.status |= CAM_DEV_QFRZN; in mprsas_scsiio_complete()
2830 xpt_freeze_devq(ccb->ccb_h.path, /*count*/ 1); in mprsas_scsiio_complete()
2839 if (cm->cm_targ->flags & MPRSAS_TARGET_INREMOVAL) { in mprsas_scsiio_complete()
2840 if (TAILQ_FIRST(&cm->cm_targ->commands) == NULL && in mprsas_scsiio_complete()
2841 cm->cm_targ->pending_remove_tm != NULL) { in mprsas_scsiio_complete()
2844 cm->cm_targ->tid, cm->cm_targ->handle); in mprsas_scsiio_complete()
2845 mpr_map_command(sc, cm->cm_targ->pending_remove_tm); in mprsas_scsiio_complete()
2846 cm->cm_targ->pending_remove_tm = NULL; in mprsas_scsiio_complete()
2862 ccb = cm->cm_complete_data; in mprsas_smpio_complete()
2870 if ((cm->cm_flags & MPR_CM_FLAGS_ERROR_MASK) != 0) { in mprsas_smpio_complete()
2872 "request!\n", __func__, cm->cm_flags); in mprsas_smpio_complete()
2877 rpl = (MPI2_SMP_PASSTHROUGH_REPLY *)cm->cm_reply; in mprsas_smpio_complete()
2884 req = (MPI2_SMP_PASSTHROUGH_REQUEST *)cm->cm_req; in mprsas_smpio_complete()
2885 sasaddr = le32toh(req->SASAddress.Low); in mprsas_smpio_complete()
2886 sasaddr |= ((uint64_t)(le32toh(req->SASAddress.High))) << 32; in mprsas_smpio_complete()
2888 if ((le16toh(rpl->IOCStatus) & MPI2_IOCSTATUS_MASK) != in mprsas_smpio_complete()
2890 rpl->SASStatus != MPI2_SASSTATUS_SUCCESS) { in mprsas_smpio_complete()
2892 __func__, le16toh(rpl->IOCStatus), rpl->SASStatus); in mprsas_smpio_complete()
2900 if (ccb->smpio.smp_response[2] == SMP_FR_ACCEPTED) in mprsas_smpio_complete()
2910 bus_dmamap_sync(sc->buffer_dmat, cm->cm_dmamap, in mprsas_smpio_complete()
2912 bus_dmamap_unload(sc->buffer_dmat, cm->cm_dmamap); in mprsas_smpio_complete()
2926 sc = sassc->sc; in mprsas_send_smpcmd()
2929 switch (ccb->ccb_h.flags & CAM_DATA_MASK) { in mprsas_send_smpcmd()
2945 if ((ccb->smpio.smp_request_sglist_cnt > 1) in mprsas_send_smpcmd()
2946 || (ccb->smpio.smp_response_sglist_cnt > 1)) { in mprsas_send_smpcmd()
2963 if (ccb->smpio.smp_request_sglist_cnt != 0) { in mprsas_send_smpcmd()
2966 req_sg = (bus_dma_segment_t *)ccb->smpio.smp_request; in mprsas_send_smpcmd()
2969 request = ccb->smpio.smp_request; in mprsas_send_smpcmd()
2971 if (ccb->smpio.smp_response_sglist_cnt != 0) { in mprsas_send_smpcmd()
2974 rsp_sg = (bus_dma_segment_t *)ccb->smpio.smp_response; in mprsas_send_smpcmd()
2977 response = ccb->smpio.smp_response; in mprsas_send_smpcmd()
2980 request = ccb->smpio.smp_request; in mprsas_send_smpcmd()
2981 response = ccb->smpio.smp_response; in mprsas_send_smpcmd()
2998 req = (MPI2_SMP_PASSTHROUGH_REQUEST *)cm->cm_req; in mprsas_send_smpcmd()
3000 req->Function = MPI2_FUNCTION_SMP_PASSTHROUGH; in mprsas_send_smpcmd()
3003 req->PhysicalPort = 0xff; in mprsas_send_smpcmd()
3005 req->RequestDataLength = htole16(ccb->smpio.smp_request_len); in mprsas_send_smpcmd()
3006 req->SGLFlags = in mprsas_send_smpcmd()
3012 mpr_init_sge(cm, req, &req->SGL); in mprsas_send_smpcmd()
3018 cm->cm_uio.uio_iov = cm->cm_iovec; in mprsas_send_smpcmd()
3019 cm->cm_uio.uio_iovcnt = 2; in mprsas_send_smpcmd()
3020 cm->cm_uio.uio_segflg = UIO_SYSSPACE; in mprsas_send_smpcmd()
3027 cm->cm_uio.uio_rw = UIO_WRITE; in mprsas_send_smpcmd()
3029 cm->cm_iovec[0].iov_base = request; in mprsas_send_smpcmd()
3030 cm->cm_iovec[0].iov_len = le16toh(req->RequestDataLength); in mprsas_send_smpcmd()
3031 cm->cm_iovec[1].iov_base = response; in mprsas_send_smpcmd()
3032 cm->cm_iovec[1].iov_len = ccb->smpio.smp_response_len; in mprsas_send_smpcmd()
3034 cm->cm_uio.uio_resid = cm->cm_iovec[0].iov_len + in mprsas_send_smpcmd()
3035 cm->cm_iovec[1].iov_len; in mprsas_send_smpcmd()
3042 cm->cm_max_segs = 2; in mprsas_send_smpcmd()
3044 cm->cm_desc.Default.RequestFlags = MPI2_REQ_DESCRIPT_FLAGS_DEFAULT_TYPE; in mprsas_send_smpcmd()
3045 cm->cm_complete = mprsas_smpio_complete; in mprsas_send_smpcmd()
3046 cm->cm_complete_data = ccb; in mprsas_send_smpcmd()
3050 * an SMP passthrough request. There is a little special-case in mprsas_send_smpcmd()
3054 cm->cm_flags |= MPR_CM_FLAGS_USE_UIO | MPR_CM_FLAGS_SMP_PASS | in mprsas_send_smpcmd()
3058 req->SASAddress.High = htole32(sasaddr >> 32); in mprsas_send_smpcmd()
3059 req->SASAddress.Low = htole32(sasaddr); in mprsas_send_smpcmd()
3092 sc = sassc->sc; in mprsas_action_smpio()
3097 KASSERT(ccb->ccb_h.target_id < sassc->maxtargets, in mprsas_action_smpio()
3098 ("Target %d out of bounds in XPT_SMP_IO\n", ccb->ccb_h.target_id)); in mprsas_action_smpio()
3099 targ = &sassc->targets[ccb->ccb_h.target_id]; in mprsas_action_smpio()
3100 if (targ->handle == 0x0) { in mprsas_action_smpio()
3102 __func__, ccb->ccb_h.target_id); in mprsas_action_smpio()
3113 if ((targ->devinfo & MPI2_SAS_DEVICE_INFO_SMP_TARGET) != 0) in mprsas_action_smpio()
3114 sasaddr = targ->sasaddr; in mprsas_action_smpio()
3120 * expander SAS address as the port-associated SAS address in in mprsas_action_smpio()
3136 sasaddr = xpt_path_sas_addr(ccb->ccb_h.path); in mprsas_action_smpio()
3148 if (targ->parent_handle == 0x0) { in mprsas_action_smpio()
3150 "a valid parent handle!\n", __func__, targ->handle); in mprsas_action_smpio()
3156 targ->parent_handle); in mprsas_action_smpio()
3160 "a valid parent target!\n", __func__, targ->handle); in mprsas_action_smpio()
3165 if ((parent_target->devinfo & in mprsas_action_smpio()
3169 targ->handle, parent_target->handle); in mprsas_action_smpio()
3174 sasaddr = parent_target->sasaddr; in mprsas_action_smpio()
3176 if ((targ->parent_devinfo & in mprsas_action_smpio()
3180 targ->handle, targ->parent_handle); in mprsas_action_smpio()
3184 if (targ->parent_sasaddr == 0x0) { in mprsas_action_smpio()
3187 targ->handle, targ->parent_handle); in mprsas_action_smpio()
3192 sasaddr = targ->parent_sasaddr; in mprsas_action_smpio()
3198 "handle %d\n", __func__, targ->handle); in mprsas_action_smpio()
3219 MPR_FUNCTRACE(sassc->sc); in mprsas_action_resetdev()
3220 mtx_assert(&sassc->sc->mpr_mtx, MA_OWNED); in mprsas_action_resetdev()
3222 KASSERT(ccb->ccb_h.target_id < sassc->maxtargets, ("Target %d out of " in mprsas_action_resetdev()
3223 "bounds in XPT_RESET_DEV\n", ccb->ccb_h.target_id)); in mprsas_action_resetdev()
3224 sc = sassc->sc; in mprsas_action_resetdev()
3234 targ = &sassc->targets[ccb->ccb_h.target_id]; in mprsas_action_resetdev()
3235 req = (MPI2_SCSI_TASK_MANAGE_REQUEST *)tm->cm_req; in mprsas_action_resetdev()
3236 req->DevHandle = htole16(targ->handle); in mprsas_action_resetdev()
3237 req->TaskType = MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET; in mprsas_action_resetdev()
3239 if (!targ->is_nvme || sc->custom_nvme_tm_handling) { in mprsas_action_resetdev()
3241 req->MsgFlags = MPI2_SCSITASKMGMT_MSGFLAGS_LINK_RESET; in mprsas_action_resetdev()
3244 req->MsgFlags = in mprsas_action_resetdev()
3248 tm->cm_data = NULL; in mprsas_action_resetdev()
3249 tm->cm_complete = mprsas_resetdev_complete; in mprsas_action_resetdev()
3250 tm->cm_complete_data = ccb; in mprsas_action_resetdev()
3253 __func__, targ->tid); in mprsas_action_resetdev()
3254 tm->cm_targ = targ; in mprsas_action_resetdev()
3267 mtx_assert(&sc->mpr_mtx, MA_OWNED); in mprsas_resetdev_complete()
3269 resp = (MPI2_SCSI_TASK_MANAGE_REPLY *)tm->cm_reply; in mprsas_resetdev_complete()
3270 ccb = tm->cm_complete_data; in mprsas_resetdev_complete()
3277 if ((tm->cm_flags & MPR_CM_FLAGS_ERROR_MASK) != 0) { in mprsas_resetdev_complete()
3280 req = (MPI2_SCSI_TASK_MANAGE_REQUEST *)tm->cm_req; in mprsas_resetdev_complete()
3284 tm->cm_flags, req->DevHandle); in mprsas_resetdev_complete()
3290 __func__, le16toh(resp->IOCStatus), le32toh(resp->ResponseCode)); in mprsas_resetdev_complete()
3292 if (le32toh(resp->ResponseCode) == MPI2_SCSITASKMGMT_RSP_TM_COMPLETE) { in mprsas_resetdev_complete()
3294 mprsas_announce_reset(sc, AC_SENT_BDR, tm->cm_targ->tid, in mprsas_resetdev_complete()
3313 if (sassc->sc->mpr_debug & MPR_TRACE) { in mprsas_poll()
3317 mpr_dprint(sassc->sc, MPR_XINFO, "%s clearing MPR_TRACE\n", in mprsas_poll()
3319 sassc->sc->mpr_debug &= ~MPR_TRACE; in mprsas_poll()
3322 mpr_intr_locked(sassc->sc); in mprsas_poll()
3348 sassc = sc->sassc; in mprsas_async()
3359 KASSERT(xpt_path_target_id(path) < sassc->maxtargets, in mprsas_async()
3362 target = &sassc->targets[xpt_path_target_id(path)]; in mprsas_async()
3363 if (target->handle == 0) in mprsas_async()
3368 SLIST_FOREACH(lun, &target->luns, lun_link) { in mprsas_async()
3369 if (lun->lun_id == lunid) { in mprsas_async()
3383 lun->lun_id = lunid; in mprsas_async()
3384 SLIST_INSERT_HEAD(&target->luns, lun, lun_link); in mprsas_async()
3405 lun->eedp_formatted = TRUE; in mprsas_async()
3406 lun->eedp_block_size = in mprsas_async()
3411 lun->eedp_formatted = FALSE; in mprsas_async()
3412 lun->eedp_block_size = 0; in mprsas_async()
3416 lun->eedp_formatted = FALSE; in mprsas_async()
3417 lun->eedp_block_size = 0; in mprsas_async()
3447 path_id = cam_sim_path(sc->sassc->sim); in mprsas_prepare_for_tm()
3448 if (xpt_create_path(&ccb->ccb_h.path, xpt_periph, path_id, in mprsas_prepare_for_tm()
3449 target->tid, lun_id) != CAM_REQ_CMP) { in mprsas_prepare_for_tm()
3452 tm->cm_ccb = ccb; in mprsas_prepare_for_tm()
3453 tm->cm_targ = target; in mprsas_prepare_for_tm()
3454 if ((target->flags & MPRSAS_TARGET_INRESET) == 0) { in mprsas_prepare_for_tm()
3457 __func__, target->tid); in mprsas_prepare_for_tm()
3458 xpt_freeze_devq(ccb->ccb_h.path, 1); in mprsas_prepare_for_tm()
3459 target->flags |= MPRSAS_TARGET_INRESET; in mprsas_prepare_for_tm()
3473 sc->wait_for_port_enable = 1; in mprsas_startup()
3488 request = (MPI2_PORT_ENABLE_REQUEST *)cm->cm_req; in mprsas_send_portenable()
3489 request->Function = MPI2_FUNCTION_PORT_ENABLE; in mprsas_send_portenable()
3490 request->MsgFlags = 0; in mprsas_send_portenable()
3491 request->VP_ID = 0; in mprsas_send_portenable()
3492 cm->cm_desc.Default.RequestFlags = MPI2_REQ_DESCRIPT_FLAGS_DEFAULT_TYPE; in mprsas_send_portenable()
3493 cm->cm_complete = mprsas_portenable_complete; in mprsas_send_portenable()
3494 cm->cm_data = NULL; in mprsas_send_portenable()
3495 cm->cm_sge = NULL; in mprsas_send_portenable()
3500 cm, cm->cm_req, cm->cm_complete); in mprsas_send_portenable()
3511 sassc = sc->sassc; in mprsas_portenable_complete()
3518 if ((cm->cm_flags & MPR_CM_FLAGS_ERROR_MASK) != 0) { in mprsas_portenable_complete()
3520 "This should not happen!\n", __func__, cm->cm_flags); in mprsas_portenable_complete()
3523 reply = (MPI2_PORT_ENABLE_REPLY *)cm->cm_reply; in mprsas_portenable_complete()
3526 else if ((le16toh(reply->IOCStatus) & MPI2_IOCSTATUS_MASK) != in mprsas_portenable_complete()
3536 sc->wait_for_port_enable = 0; in mprsas_portenable_complete()
3537 sc->port_enable_complete = 1; in mprsas_portenable_complete()
3538 wakeup(&sc->port_enable_complete); in mprsas_portenable_complete()
3545 struct mpr_softc *sc = sassc->sc; in mprsas_check_id()
3549 ids = &sc->exclude_ids[0]; in mprsas_check_id()
3568 sassc = sc->sassc; in mprsas_realloc_targets()
3575 targ = &sassc->targets[i]; in mprsas_realloc_targets()
3576 SLIST_FOREACH_SAFE(lun, &targ->luns, lun_link, lun_tmp) { in mprsas_realloc_targets()
3580 free(sassc->targets, M_MPR); in mprsas_realloc_targets()
3582 sassc->targets = malloc(sizeof(struct mprsas_target) * maxtargets, in mprsas_realloc_targets()