Lines Matching +full:cts +full:- +full:override
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
146 for (i = start; i < sassc->maxtargets; i++) { in mprsas_find_target_by_handle()
147 target = &sassc->targets[i]; in mprsas_find_target_by_handle()
148 if (target->handle == handle) in mprsas_find_target_by_handle()
165 MPR_FUNCTRACE(sassc->sc); in mprsas_startup_increment()
167 if ((sassc->flags & MPRSAS_IN_STARTUP) != 0) { in mprsas_startup_increment()
168 if (sassc->startup_refcount++ == 0) { in mprsas_startup_increment()
170 mpr_dprint(sassc->sc, MPR_INIT, in mprsas_startup_increment()
173 xpt_freeze_simq(sassc->sim, 1); in mprsas_startup_increment()
175 mpr_dprint(sassc->sc, MPR_INIT, "%s refcount %u\n", __func__, in mprsas_startup_increment()
176 sassc->startup_refcount); in mprsas_startup_increment()
183 if (sassc->flags & MPRSAS_QUEUE_FROZEN) { in mprsas_release_simq_reinit()
184 sassc->flags &= ~MPRSAS_QUEUE_FROZEN; in mprsas_release_simq_reinit()
185 xpt_release_simq(sassc->sim, 1); in mprsas_release_simq_reinit()
186 mpr_dprint(sassc->sc, MPR_INFO, "Unfreezing SIM queue\n"); in mprsas_release_simq_reinit()
193 MPR_FUNCTRACE(sassc->sc); in mprsas_startup_decrement()
195 if ((sassc->flags & MPRSAS_IN_STARTUP) != 0) { in mprsas_startup_decrement()
196 if (--sassc->startup_refcount == 0) { in mprsas_startup_decrement()
197 /* finished all discovery-related actions, release in mprsas_startup_decrement()
200 mpr_dprint(sassc->sc, MPR_INIT, in mprsas_startup_decrement()
202 sassc->flags &= ~MPRSAS_IN_STARTUP; in mprsas_startup_decrement()
203 xpt_release_simq(sassc->sim, 1); in mprsas_startup_decrement()
206 mpr_dprint(sassc->sc, MPR_INIT, "%s refcount %u\n", __func__, in mprsas_startup_decrement()
207 sassc->startup_refcount); in mprsas_startup_decrement()
229 req = (MPI2_SCSI_TASK_MANAGE_REQUEST *)tm->cm_req; in mprsas_alloc_tm()
230 req->Function = MPI2_FUNCTION_SCSI_TASK_MGMT; in mprsas_alloc_tm()
247 if (tm->cm_ccb) { in mprsas_free_tm()
250 tm->cm_targ->tid); in mprsas_free_tm()
251 tm->cm_targ->flags &= ~MPRSAS_TARGET_INRESET; in mprsas_free_tm()
252 xpt_release_devq(tm->cm_ccb->ccb_h.path, 1, TRUE); in mprsas_free_tm()
253 xpt_free_path(tm->cm_ccb->ccb_h.path); in mprsas_free_tm()
254 xpt_free_ccb(tm->cm_ccb); in mprsas_free_tm()
263 struct mprsas_softc *sassc = sc->sassc; in mprsas_rescan_target()
269 pathid = cam_sim_path(sassc->sim); in mprsas_rescan_target()
273 targetid = targ - sassc->targets; in mprsas_rescan_target()
284 if (xpt_create_path(&ccb->ccb_h.path, NULL, pathid, targetid, in mprsas_rescan_target()
292 ccb->ccb_h.func_code = XPT_SCAN_BUS; in mprsas_rescan_target()
294 ccb->ccb_h.func_code = XPT_SCAN_TGT; in mprsas_rescan_target()
311 if ((cm->cm_sc->mpr_debug & level) == 0) in mprsas_log_command()
318 if (cm->cm_ccb != NULL) { in mprsas_log_command()
319 xpt_path_sbuf(cm->cm_ccb->csio.ccb_h.path, &sb); in mprsas_log_command()
320 if (cm->cm_ccb->ccb_h.func_code == XPT_SCSI_IO) { in mprsas_log_command()
321 scsi_command_string(&cm->cm_ccb->csio, &sb); in mprsas_log_command()
323 cm->cm_ccb->csio.dxfer_len); in mprsas_log_command()
327 cam_sim_name(cm->cm_sc->sassc->sim), in mprsas_log_command()
328 cam_sim_unit(cm->cm_sc->sassc->sim), in mprsas_log_command()
329 cam_sim_bus(cm->cm_sc->sassc->sim), in mprsas_log_command()
330 cm->cm_targ ? cm->cm_targ->tid : 0xFFFFFFFF, in mprsas_log_command()
331 cm->cm_lun); in mprsas_log_command()
334 sbuf_printf(&sb, "SMID %u ", cm->cm_desc.Default.SMID); in mprsas_log_command()
337 mpr_print_field(cm->cm_sc, "%s", sbuf_data(&sb)); in mprsas_log_command()
351 reply = (MPI2_SCSI_TASK_MANAGE_REPLY *)tm->cm_reply; in mprsas_remove_volume()
352 handle = (uint16_t)(uintptr_t)tm->cm_complete_data; in mprsas_remove_volume()
353 targ = tm->cm_targ; in mprsas_remove_volume()
363 if ((le16toh(reply->IOCStatus) & MPI2_IOCSTATUS_MASK) != in mprsas_remove_volume()
366 "device 0x%x\n", le16toh(reply->IOCStatus), handle); in mprsas_remove_volume()
370 le32toh(reply->TerminationCount)); in mprsas_remove_volume()
371 mpr_free_reply(sc, tm->cm_reply_data); in mprsas_remove_volume()
372 tm->cm_reply = NULL; /* Ensures the reply won't get re-freed */ in mprsas_remove_volume()
375 targ->tid, handle); in mprsas_remove_volume()
383 if ((le16toh(reply->IOCStatus) & MPI2_IOCSTATUS_MASK) == in mprsas_remove_volume()
385 targ = tm->cm_targ; in mprsas_remove_volume()
386 targ->handle = 0x0; in mprsas_remove_volume()
387 targ->encl_handle = 0x0; in mprsas_remove_volume()
388 targ->encl_level_valid = 0x0; in mprsas_remove_volume()
389 targ->encl_level = 0x0; in mprsas_remove_volume()
390 targ->connector_name[0] = ' '; in mprsas_remove_volume()
391 targ->connector_name[1] = ' '; in mprsas_remove_volume()
392 targ->connector_name[2] = ' '; in mprsas_remove_volume()
393 targ->connector_name[3] = ' '; in mprsas_remove_volume()
394 targ->encl_slot = 0x0; in mprsas_remove_volume()
395 targ->exp_dev_handle = 0x0; in mprsas_remove_volume()
396 targ->phy_num = 0x0; in mprsas_remove_volume()
397 targ->linkrate = 0x0; in mprsas_remove_volume()
398 targ->devinfo = 0x0; in mprsas_remove_volume()
399 targ->flags = 0x0; in mprsas_remove_volume()
400 targ->scsi_req_desc_type = 0; in mprsas_remove_volume()
416 if ((sassc->flags & MPRSAS_TOREMOVE) == 0) in mprsas_prepare_remove_retry()
419 for (i = 0; i < sassc->maxtargets; i++) { in mprsas_prepare_remove_retry()
420 target = &sassc->targets[i]; in mprsas_prepare_remove_retry()
421 if ((target->flags & MPRSAS_TARGET_TOREMOVE) == 0) in mprsas_prepare_remove_retry()
423 if (TAILQ_EMPTY(&sassc->sc->high_priority_req_list)) in mprsas_prepare_remove_retry()
425 target->flags &= ~MPRSAS_TARGET_TOREMOVE; in mprsas_prepare_remove_retry()
426 if (target->flags & MPR_TARGET_FLAGS_VOLUME) in mprsas_prepare_remove_retry()
427 mprsas_prepare_volume_remove(sassc, target->handle); in mprsas_prepare_remove_retry()
429 mprsas_prepare_remove(sassc, target->handle); in mprsas_prepare_remove_retry()
431 sassc->flags &= ~MPRSAS_TOREMOVE; in mprsas_prepare_remove_retry()
446 MPR_FUNCTRACE(sassc->sc); in mprsas_prepare_volume_remove()
447 sc = sassc->sc; in mprsas_prepare_volume_remove()
458 targ->flags |= MPRSAS_TARGET_INREMOVAL; in mprsas_prepare_volume_remove()
462 targ->flags |= MPRSAS_TARGET_TOREMOVE; in mprsas_prepare_volume_remove()
463 sassc->flags |= MPRSAS_TOREMOVE; in mprsas_prepare_volume_remove()
469 req = (MPI2_SCSI_TASK_MANAGE_REQUEST *)cm->cm_req; in mprsas_prepare_volume_remove()
470 req->DevHandle = targ->handle; in mprsas_prepare_volume_remove()
471 req->TaskType = MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET; in mprsas_prepare_volume_remove()
473 if (!targ->is_nvme || sc->custom_nvme_tm_handling) { in mprsas_prepare_volume_remove()
475 req->MsgFlags = MPI2_SCSITASKMGMT_MSGFLAGS_LINK_RESET; in mprsas_prepare_volume_remove()
478 req->MsgFlags = in mprsas_prepare_volume_remove()
482 cm->cm_targ = targ; in mprsas_prepare_volume_remove()
483 cm->cm_data = NULL; in mprsas_prepare_volume_remove()
484 cm->cm_complete = mprsas_remove_volume; in mprsas_prepare_volume_remove()
485 cm->cm_complete_data = (void *)(uintptr_t)handle; in mprsas_prepare_volume_remove()
488 __func__, targ->tid); in mprsas_prepare_volume_remove()
498 * and then an op remove. The reset has the side-effect of aborting any
499 * outstanding requests for the device, which is required for the op-remove to
511 MPR_FUNCTRACE(sassc->sc); in mprsas_prepare_remove()
513 sc = sassc->sc; in mprsas_prepare_remove()
524 targ->flags |= MPRSAS_TARGET_INREMOVAL; in mprsas_prepare_remove()
528 targ->flags |= MPRSAS_TARGET_TOREMOVE; in mprsas_prepare_remove()
529 sassc->flags |= MPRSAS_TOREMOVE; in mprsas_prepare_remove()
535 req = (MPI2_SCSI_TASK_MANAGE_REQUEST *)tm->cm_req; in mprsas_prepare_remove()
536 req->DevHandle = htole16(targ->handle); in mprsas_prepare_remove()
537 req->TaskType = MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET; in mprsas_prepare_remove()
540 req->MsgFlags = MPI2_SCSITASKMGMT_MSGFLAGS_LINK_RESET; in mprsas_prepare_remove()
542 tm->cm_targ = targ; in mprsas_prepare_remove()
543 tm->cm_data = NULL; in mprsas_prepare_remove()
544 tm->cm_complete = mprsas_remove_device; in mprsas_prepare_remove()
545 tm->cm_complete_data = (void *)(uintptr_t)handle; in mprsas_prepare_remove()
548 __func__, targ->tid); in mprsas_prepare_remove()
564 reply = (MPI2_SCSI_TASK_MANAGE_REPLY *)tm->cm_reply; in mprsas_remove_device()
565 handle = (uint16_t)(uintptr_t)tm->cm_complete_data; in mprsas_remove_device()
566 targ = tm->cm_targ; in mprsas_remove_device()
573 if ((tm->cm_flags & MPR_CM_FLAGS_ERROR_MASK) != 0) { in mprsas_remove_device()
576 tm->cm_flags, handle); in mprsas_remove_device()
587 if ((le16toh(reply->IOCStatus) & MPI2_IOCSTATUS_MASK) != in mprsas_remove_device()
590 "device 0x%x\n", le16toh(reply->IOCStatus), handle); in mprsas_remove_device()
594 le32toh(reply->TerminationCount)); in mprsas_remove_device()
595 mpr_free_reply(sc, tm->cm_reply_data); in mprsas_remove_device()
596 tm->cm_reply = NULL; /* Ensures the reply won't get re-freed */ in mprsas_remove_device()
599 req = (MPI2_SAS_IOUNIT_CONTROL_REQUEST *)tm->cm_req; in mprsas_remove_device()
601 req->Function = MPI2_FUNCTION_SAS_IO_UNIT_CONTROL; in mprsas_remove_device()
602 req->Operation = MPI2_SAS_OP_REMOVE_DEVICE; in mprsas_remove_device()
603 req->DevHandle = htole16(handle); in mprsas_remove_device()
604 tm->cm_data = NULL; in mprsas_remove_device()
605 tm->cm_desc.Default.RequestFlags = MPI2_REQ_DESCRIPT_FLAGS_DEFAULT_TYPE; in mprsas_remove_device()
606 tm->cm_complete = mprsas_remove_complete; in mprsas_remove_device()
607 tm->cm_complete_data = (void *)(uintptr_t)handle; in mprsas_remove_device()
614 if (TAILQ_FIRST(&targ->commands) == NULL) { in mprsas_remove_device()
617 targ->tid, handle); in mprsas_remove_device()
619 targ->pending_remove_tm = NULL; in mprsas_remove_device()
621 targ->pending_remove_tm = tm; in mprsas_remove_device()
625 targ->tid, handle); in mprsas_remove_device()
626 if (targ->encl_level_valid) { in mprsas_remove_device()
628 "connector name (%4s)\n", targ->encl_level, targ->encl_slot, in mprsas_remove_device()
629 targ->connector_name); in mprsas_remove_device()
643 reply = (MPI2_SAS_IOUNIT_CONTROL_REPLY *)tm->cm_reply; in mprsas_remove_complete()
644 handle = (uint16_t)(uintptr_t)tm->cm_complete_data; in mprsas_remove_complete()
646 targ = tm->cm_targ; in mprsas_remove_complete()
652 KASSERT(TAILQ_FIRST(&targ->commands) == NULL, in mprsas_remove_complete()
660 if ((tm->cm_flags & MPR_CM_FLAGS_ERROR_MASK) != 0) { in mprsas_remove_complete()
663 tm->cm_flags, handle); in mprsas_remove_complete()
677 __func__, handle, le16toh(reply->IOCStatus)); in mprsas_remove_complete()
685 if ((le16toh(reply->IOCStatus) & MPI2_IOCSTATUS_MASK) == in mprsas_remove_complete()
687 targ->handle = 0x0; in mprsas_remove_complete()
688 targ->encl_handle = 0x0; in mprsas_remove_complete()
689 targ->encl_level_valid = 0x0; in mprsas_remove_complete()
690 targ->encl_level = 0x0; in mprsas_remove_complete()
691 targ->connector_name[0] = ' '; in mprsas_remove_complete()
692 targ->connector_name[1] = ' '; in mprsas_remove_complete()
693 targ->connector_name[2] = ' '; in mprsas_remove_complete()
694 targ->connector_name[3] = ' '; in mprsas_remove_complete()
695 targ->encl_slot = 0x0; in mprsas_remove_complete()
696 targ->exp_dev_handle = 0x0; in mprsas_remove_complete()
697 targ->phy_num = 0x0; in mprsas_remove_complete()
698 targ->linkrate = 0x0; in mprsas_remove_complete()
699 targ->devinfo = 0x0; in mprsas_remove_complete()
700 targ->flags = 0x0; in mprsas_remove_complete()
701 targ->scsi_req_desc_type = 0; in mprsas_remove_complete()
703 while (!SLIST_EMPTY(&targ->luns)) { in mprsas_remove_complete()
704 lun = SLIST_FIRST(&targ->luns); in mprsas_remove_complete()
705 SLIST_REMOVE_HEAD(&targ->luns, lun_link); in mprsas_remove_complete()
732 if (sc->facts->MsgVersion >= MPI2_VERSION_02_06) { in mprsas_register_events()
734 if (sc->mpr_flags & MPR_FLAGS_GEN35_IOC) { in mprsas_register_events()
742 &sc->sassc->mprsas_eh); in mprsas_register_events()
765 sassc->maxtargets = sc->facts->MaxTargets + sc->facts->MaxVolumes; in mpr_attach_sas()
766 sassc->targets = malloc(sizeof(struct mprsas_target) * in mpr_attach_sas()
767 sassc->maxtargets, M_MPR, M_WAITOK|M_ZERO); in mpr_attach_sas()
768 sc->sassc = sassc; in mpr_attach_sas()
769 sassc->sc = sc; in mpr_attach_sas()
771 reqs = sc->num_reqs - sc->num_prireqs - 1; in mpr_attach_sas()
772 if ((sassc->devq = cam_simq_alloc(reqs)) == NULL) { in mpr_attach_sas()
778 unit = device_get_unit(sc->mpr_dev); in mpr_attach_sas()
779 sassc->sim = cam_sim_alloc(mprsas_action, mprsas_poll, "mpr", sassc, in mpr_attach_sas()
780 unit, &sc->mpr_mtx, reqs, reqs, sassc->devq); in mpr_attach_sas()
781 if (sassc->sim == NULL) { in mpr_attach_sas()
787 TAILQ_INIT(&sassc->ev_queue); in mpr_attach_sas()
790 TASK_INIT(&sassc->ev_task, 0, mprsas_firmware_event_work, sc); in mpr_attach_sas()
791 sassc->ev_tq = taskqueue_create("mpr_taskq", M_NOWAIT | M_ZERO, in mpr_attach_sas()
792 taskqueue_thread_enqueue, &sassc->ev_tq); in mpr_attach_sas()
793 taskqueue_start_threads(&sassc->ev_tq, 1, PRIBIO, "%s taskq", in mpr_attach_sas()
794 device_get_nameunit(sc->mpr_dev)); in mpr_attach_sas()
803 if ((error = xpt_bus_register(sassc->sim, sc->mpr_dev, 0)) != 0) { in mpr_attach_sas()
815 sassc->flags |= MPRSAS_IN_STARTUP | MPRSAS_IN_DISCOVERY; in mpr_attach_sas()
816 sc->sassc->startup_refcount = 0; in mpr_attach_sas()
825 status = xpt_create_path(&sassc->path, /*periph*/NULL, in mpr_attach_sas()
826 cam_sim_path(sc->sassc->sim), CAM_TARGET_WILDCARD, in mpr_attach_sas()
831 sassc->path = NULL; in mpr_attach_sas()
837 sassc->path); in mpr_attach_sas()
843 xpt_free_path(sassc->path); in mpr_attach_sas()
844 sassc->path = NULL; in mpr_attach_sas()
874 if (sc->sassc == NULL) in mpr_detach_sas()
877 sassc = sc->sassc; in mpr_detach_sas()
878 mpr_deregister_events(sc, sassc->mprsas_eh); in mpr_detach_sas()
885 if (sassc->ev_tq != NULL) in mpr_detach_sas()
886 taskqueue_free(sassc->ev_tq); in mpr_detach_sas()
889 if (sassc->path != NULL) { in mpr_detach_sas()
890 xpt_register_async(0, mprsas_async, sc, sassc->path); in mpr_detach_sas()
891 xpt_free_path(sassc->path); in mpr_detach_sas()
892 sassc->path = NULL; in mpr_detach_sas()
898 while (sassc->startup_refcount != 0) in mpr_detach_sas()
901 if (sassc->flags & MPRSAS_IN_STARTUP) in mpr_detach_sas()
902 xpt_release_simq(sassc->sim, 1); in mpr_detach_sas()
904 if (sassc->sim != NULL) { in mpr_detach_sas()
905 xpt_bus_deregister(cam_sim_path(sassc->sim)); in mpr_detach_sas()
906 cam_sim_free(sassc->sim, FALSE); in mpr_detach_sas()
911 if (sassc->devq != NULL) in mpr_detach_sas()
912 cam_simq_free(sassc->devq); in mpr_detach_sas()
914 for (i = 0; i < sassc->maxtargets; i++) { in mpr_detach_sas()
915 targ = &sassc->targets[i]; in mpr_detach_sas()
916 SLIST_FOREACH_SAFE(lun, &targ->luns, lun_link, lun_tmp) { in mpr_detach_sas()
920 free(sassc->targets, M_MPR); in mpr_detach_sas()
922 sc->sassc = NULL; in mpr_detach_sas()
930 struct mpr_softc *sc = sassc->sc; in mprsas_discovery_end()
945 if (sc->track_mapping_events) { in mprsas_discovery_end()
949 callout_reset(&sc->device_check_callout, in mprsas_discovery_end()
962 MPR_FUNCTRACE(sassc->sc); in mprsas_action()
963 mpr_dprint(sassc->sc, MPR_TRACE, "ccb func_code 0x%x\n", in mprsas_action()
964 ccb->ccb_h.func_code); in mprsas_action()
965 mtx_assert(&sassc->sc->mpr_mtx, MA_OWNED); in mprsas_action()
967 switch (ccb->ccb_h.func_code) { in mprsas_action()
970 struct ccb_pathinq *cpi = &ccb->cpi; in mprsas_action()
971 struct mpr_softc *sc = sassc->sc; in mprsas_action()
973 cpi->version_num = 1; in mprsas_action()
974 cpi->hba_inquiry = PI_SDTR_ABLE|PI_TAG_ABLE|PI_WIDE_16; in mprsas_action()
975 cpi->target_sprt = 0; in mprsas_action()
976 cpi->hba_misc = PIM_NOBUSRESET | PIM_UNMAPPED | PIM_NOSCAN; in mprsas_action()
977 cpi->hba_eng_cnt = 0; in mprsas_action()
978 cpi->max_target = sassc->maxtargets - 1; in mprsas_action()
979 cpi->max_lun = 255; in mprsas_action()
985 cpi->initiator_id = sassc->maxtargets; in mprsas_action()
986 strlcpy(cpi->sim_vid, "FreeBSD", SIM_IDLEN); in mprsas_action()
987 strlcpy(cpi->hba_vid, "Avago Tech", HBA_IDLEN); in mprsas_action()
988 strlcpy(cpi->dev_name, cam_sim_name(sim), DEV_IDLEN); in mprsas_action()
989 cpi->unit_number = cam_sim_unit(sim); in mprsas_action()
990 cpi->bus_id = cam_sim_bus(sim); in mprsas_action()
992 * XXXSLM-I think this needs to change based on config page or in mprsas_action()
995 cpi->base_transfer_speed = 150000; in mprsas_action()
996 cpi->transport = XPORT_SAS; in mprsas_action()
997 cpi->transport_version = 0; in mprsas_action()
998 cpi->protocol = PROTO_SCSI; in mprsas_action()
999 cpi->protocol_version = SCSI_REV_SPC; in mprsas_action()
1000 cpi->maxio = sc->maxio; in mprsas_action()
1006 struct ccb_trans_settings *cts; in mprsas_action() local
1011 cts = &ccb->cts; in mprsas_action()
1012 sas = &cts->xport_specific.sas; in mprsas_action()
1013 scsi = &cts->proto_specific.scsi; in mprsas_action()
1015 KASSERT(cts->ccb_h.target_id < sassc->maxtargets, in mprsas_action()
1017 cts->ccb_h.target_id)); in mprsas_action()
1018 targ = &sassc->targets[cts->ccb_h.target_id]; in mprsas_action()
1019 if (targ->handle == 0x0) { in mprsas_action()
1024 cts->protocol_version = SCSI_REV_SPC2; in mprsas_action()
1025 cts->transport = XPORT_SAS; in mprsas_action()
1026 cts->transport_version = 0; in mprsas_action()
1028 sas->valid = CTS_SAS_VALID_SPEED; in mprsas_action()
1029 switch (targ->linkrate) { in mprsas_action()
1031 sas->bitrate = 150000; in mprsas_action()
1034 sas->bitrate = 300000; in mprsas_action()
1037 sas->bitrate = 600000; in mprsas_action()
1040 sas->bitrate = 1200000; in mprsas_action()
1043 sas->valid = 0; in mprsas_action()
1046 cts->protocol = PROTO_SCSI; in mprsas_action()
1047 scsi->valid = CTS_SCSI_VALID_TQ; in mprsas_action()
1048 scsi->flags = CTS_SCSI_FLAGS_TAG_ENB; in mprsas_action()
1054 cam_calc_geometry(&ccb->ccg, /*extended*/1); in mprsas_action()
1058 mpr_dprint(sassc->sc, MPR_XINFO, "mprsas_action " in mprsas_action()
1065 mpr_dprint(sassc->sc, MPR_XINFO, "mprsas_action faking success " in mprsas_action()
1087 path_id_t path_id = cam_sim_path(sc->sassc->sim); in mprsas_announce_reset()
1112 mtx_assert(&sc->mpr_mtx, MA_OWNED); in mprsas_complete_all_commands()
1115 for (i = 1; i < sc->num_reqs; i++) { in mprsas_complete_all_commands()
1116 cm = &sc->commands[i]; in mprsas_complete_all_commands()
1117 if (cm->cm_state == MPR_CM_STATE_FREE) in mprsas_complete_all_commands()
1120 cm->cm_state = MPR_CM_STATE_BUSY; in mprsas_complete_all_commands()
1121 cm->cm_reply = NULL; in mprsas_complete_all_commands()
1124 if (cm->cm_flags & MPR_CM_FLAGS_SATA_ID_TIMEOUT) { in mprsas_complete_all_commands()
1125 MPASS(cm->cm_data); in mprsas_complete_all_commands()
1126 free(cm->cm_data, M_MPR); in mprsas_complete_all_commands()
1127 cm->cm_data = NULL; in mprsas_complete_all_commands()
1130 if (cm->cm_flags & MPR_CM_FLAGS_POLLED) in mprsas_complete_all_commands()
1131 cm->cm_flags |= MPR_CM_FLAGS_COMPLETE; in mprsas_complete_all_commands()
1133 if (cm->cm_complete != NULL) { in mprsas_complete_all_commands()
1136 cm, cm->cm_state, cm->cm_ccb); in mprsas_complete_all_commands()
1137 cm->cm_complete(sc, cm); in mprsas_complete_all_commands()
1139 } else if (cm->cm_flags & MPR_CM_FLAGS_WAKEUP) { in mprsas_complete_all_commands()
1142 cm, cm->cm_state, cm->cm_ccb); in mprsas_complete_all_commands()
1147 if ((completed == 0) && (cm->cm_state != MPR_CM_STATE_FREE)) { in mprsas_complete_all_commands()
1151 "reset\n", cm, cm->cm_state, cm->cm_flags, in mprsas_complete_all_commands()
1152 cm->cm_ccb); in mprsas_complete_all_commands()
1156 sc->io_cmds_active = 0; in mprsas_complete_all_commands()
1169 * discovery-related activities have finished, the simq will be in mprsas_handle_reinit()
1173 sc->sassc->flags |= MPRSAS_IN_STARTUP; in mprsas_handle_reinit()
1174 sc->sassc->flags |= MPRSAS_IN_DISCOVERY; in mprsas_handle_reinit()
1175 mprsas_startup_increment(sc->sassc); in mprsas_handle_reinit()
1185 __func__, sc->sassc->startup_refcount); in mprsas_handle_reinit()
1191 for (i = 0; i < sc->sassc->maxtargets; i++) { in mprsas_handle_reinit()
1192 if (sc->sassc->targets[i].outstanding != 0) in mprsas_handle_reinit()
1194 i, sc->sassc->targets[i].outstanding); in mprsas_handle_reinit()
1195 sc->sassc->targets[i].handle = 0x0; in mprsas_handle_reinit()
1196 sc->sassc->targets[i].exp_dev_handle = 0x0; in mprsas_handle_reinit()
1197 sc->sassc->targets[i].outstanding = 0; in mprsas_handle_reinit()
1198 sc->sassc->targets[i].flags = MPRSAS_TARGET_INDIAGRESET; in mprsas_handle_reinit()
1205 struct mpr_softc *sc = tm->cm_sc; in mprsas_tm_timeout()
1207 mtx_assert(&sc->mpr_mtx, MA_OWNED); in mprsas_tm_timeout()
1212 KASSERT(tm->cm_state == MPR_CM_STATE_INQUEUE, in mprsas_tm_timeout()
1213 ("command not inqueue, state = %u\n", tm->cm_state)); in mprsas_tm_timeout()
1215 tm->cm_state = MPR_CM_STATE_BUSY; in mprsas_tm_timeout()
1227 callout_stop(&tm->cm_callout); in mprsas_logical_unit_reset_complete()
1229 reply = (MPI2_SCSI_TASK_MANAGE_REPLY *)tm->cm_reply; in mprsas_logical_unit_reset_complete()
1230 targ = tm->cm_targ; in mprsas_logical_unit_reset_complete()
1237 if ((tm->cm_flags & MPR_CM_FLAGS_ERROR_MASK) != 0) { in mprsas_logical_unit_reset_complete()
1240 "This should not happen!\n", __func__, tm->cm_flags); in mprsas_logical_unit_reset_complete()
1248 if ((sc->mpr_flags & MPR_FLAGS_DIAGRESET) != 0) { in mprsas_logical_unit_reset_complete()
1252 targ->tm = NULL; in mprsas_logical_unit_reset_complete()
1266 le16toh(reply->IOCStatus), le32toh(reply->ResponseCode), in mprsas_logical_unit_reset_complete()
1267 le32toh(reply->TerminationCount)); in mprsas_logical_unit_reset_complete()
1271 * This could be made more efficient by using a per-LU data in mprsas_logical_unit_reset_complete()
1274 TAILQ_FOREACH(cm, &targ->commands, cm_link) { in mprsas_logical_unit_reset_complete()
1275 if (cm->cm_lun == tm->cm_lun) in mprsas_logical_unit_reset_complete()
1282 targ->tid); in mprsas_logical_unit_reset_complete()
1284 mprsas_announce_reset(sc, AC_SENT_BDR, targ->tid, in mprsas_logical_unit_reset_complete()
1285 tm->cm_lun); in mprsas_logical_unit_reset_complete()
1292 cm = TAILQ_FIRST(&targ->timedout_commands); in mprsas_logical_unit_reset_complete()
1295 "More commands to abort for target %u\n", targ->tid); in mprsas_logical_unit_reset_complete()
1298 targ->tm = NULL; in mprsas_logical_unit_reset_complete()
1308 "have %u command(s), sending target reset\n", targ->tid, in mprsas_logical_unit_reset_complete()
1310 if (!targ->is_nvme || sc->custom_nvme_tm_handling) in mprsas_logical_unit_reset_complete()
1325 callout_stop(&tm->cm_callout); in mprsas_target_reset_complete()
1327 req = (MPI2_SCSI_TASK_MANAGE_REQUEST *)tm->cm_req; in mprsas_target_reset_complete()
1328 reply = (MPI2_SCSI_TASK_MANAGE_REPLY *)tm->cm_reply; in mprsas_target_reset_complete()
1329 targ = tm->cm_targ; in mprsas_target_reset_complete()
1336 if ((tm->cm_flags & MPR_CM_FLAGS_ERROR_MASK) != 0) { in mprsas_target_reset_complete()
1338 "reset! This should not happen!\n", __func__, tm->cm_flags); in mprsas_target_reset_complete()
1346 tm, le16toh(req->TaskMID)); in mprsas_target_reset_complete()
1347 if ((sc->mpr_flags & MPR_FLAGS_DIAGRESET) != 0) { in mprsas_target_reset_complete()
1351 targ->tm = NULL; in mprsas_target_reset_complete()
1365 le16toh(reply->IOCStatus), le32toh(reply->ResponseCode), in mprsas_target_reset_complete()
1366 le32toh(reply->TerminationCount)); in mprsas_target_reset_complete()
1368 if (targ->outstanding == 0) { in mprsas_target_reset_complete()
1374 "Finished reset recovery for target %u\n", targ->tid); in mprsas_target_reset_complete()
1376 mprsas_announce_reset(sc, AC_SENT_BDR, tm->cm_targ->tid, in mprsas_target_reset_complete()
1379 targ->tm = NULL; in mprsas_target_reset_complete()
1389 "command(s), resetting controller\n", targ->tid, in mprsas_target_reset_complete()
1390 targ->outstanding); in mprsas_target_reset_complete()
1404 target = tm->cm_targ; in mprsas_send_reset()
1405 if (target->handle == 0) { in mprsas_send_reset()
1407 "%d\n", __func__, target->tid); in mprsas_send_reset()
1408 return -1; in mprsas_send_reset()
1411 req = (MPI2_SCSI_TASK_MANAGE_REQUEST *)tm->cm_req; in mprsas_send_reset()
1412 req->DevHandle = htole16(target->handle); in mprsas_send_reset()
1413 req->TaskType = type; in mprsas_send_reset()
1415 if (!target->is_nvme || sc->custom_nvme_tm_handling) { in mprsas_send_reset()
1421 req->MsgFlags = MPI2_SCSITASKMGMT_MSGFLAGS_LINK_RESET; in mprsas_send_reset()
1423 timeout = (target->controller_reset_timeout) ? ( in mprsas_send_reset()
1424 target->controller_reset_timeout) : (MPR_RESET_TIMEOUT); in mprsas_send_reset()
1426 req->MsgFlags = in mprsas_send_reset()
1432 MPR_SET_LUN(req->LUN, tm->cm_lun); in mprsas_send_reset()
1433 tm->cm_targ->logical_unit_resets++; in mprsas_send_reset()
1436 target->tid, tm->cm_lun); in mprsas_send_reset()
1437 tm->cm_complete = mprsas_logical_unit_reset_complete; in mprsas_send_reset()
1438 mprsas_prepare_for_tm(sc, tm, target, tm->cm_lun); in mprsas_send_reset()
1440 tm->cm_targ->target_resets++; in mprsas_send_reset()
1442 "Sending target reset to target %u\n", target->tid); in mprsas_send_reset()
1443 tm->cm_complete = mprsas_target_reset_complete; in mprsas_send_reset()
1448 return -1; in mprsas_send_reset()
1451 if (target->encl_level_valid) { in mprsas_send_reset()
1454 target->encl_level, target->encl_slot, in mprsas_send_reset()
1455 target->connector_name); in mprsas_send_reset()
1458 tm->cm_data = NULL; in mprsas_send_reset()
1459 tm->cm_complete_data = (void *)tm; in mprsas_send_reset()
1461 callout_reset(&tm->cm_callout, timeout * hz, in mprsas_send_reset()
1480 callout_stop(&tm->cm_callout); in mprsas_abort_complete()
1482 req = (MPI2_SCSI_TASK_MANAGE_REQUEST *)tm->cm_req; in mprsas_abort_complete()
1483 reply = (MPI2_SCSI_TASK_MANAGE_REPLY *)tm->cm_reply; in mprsas_abort_complete()
1484 targ = tm->cm_targ; in mprsas_abort_complete()
1491 if ((tm->cm_flags & MPR_CM_FLAGS_ERROR_MASK) != 0) { in mprsas_abort_complete()
1494 tm->cm_flags, tm, le16toh(req->TaskMID)); in mprsas_abort_complete()
1502 tm, le16toh(req->TaskMID)); in mprsas_abort_complete()
1503 if ((sc->mpr_flags & MPR_FLAGS_DIAGRESET) != 0) { in mprsas_abort_complete()
1507 targ->tm = NULL; in mprsas_abort_complete()
1520 le16toh(req->TaskMID), in mprsas_abort_complete()
1521 le16toh(reply->IOCStatus), le32toh(reply->ResponseCode), in mprsas_abort_complete()
1522 le32toh(reply->TerminationCount)); in mprsas_abort_complete()
1524 cm = TAILQ_FIRST(&tm->cm_targ->timedout_commands); in mprsas_abort_complete()
1531 "Finished abort recovery for target %u\n", targ->tid); in mprsas_abort_complete()
1532 targ->tm = NULL; in mprsas_abort_complete()
1534 } else if (le16toh(req->TaskMID) != cm->cm_desc.Default.SMID) { in mprsas_abort_complete()
1537 "Continuing abort recovery for target %u\n", targ->tid); in mprsas_abort_complete()
1546 targ->tid); in mprsas_abort_complete()
1563 targ = cm->cm_targ; in mprsas_send_abort()
1564 if (targ->handle == 0) { in mprsas_send_abort()
1567 __func__, cm->cm_ccb->ccb_h.target_id); in mprsas_send_abort()
1568 return -1; in mprsas_send_abort()
1574 req = (MPI2_SCSI_TASK_MANAGE_REQUEST *)tm->cm_req; in mprsas_send_abort()
1575 req->DevHandle = htole16(targ->handle); in mprsas_send_abort()
1576 req->TaskType = MPI2_SCSITASKMGMT_TASKTYPE_ABORT_TASK; in mprsas_send_abort()
1579 MPR_SET_LUN(req->LUN, cm->cm_ccb->ccb_h.target_lun); in mprsas_send_abort()
1581 req->TaskMID = htole16(cm->cm_desc.Default.SMID); in mprsas_send_abort()
1583 tm->cm_data = NULL; in mprsas_send_abort()
1584 tm->cm_complete = mprsas_abort_complete; in mprsas_send_abort()
1585 tm->cm_complete_data = (void *)tm; in mprsas_send_abort()
1586 tm->cm_targ = cm->cm_targ; in mprsas_send_abort()
1587 tm->cm_lun = cm->cm_lun; in mprsas_send_abort()
1589 if (!targ->is_nvme || sc->custom_nvme_tm_handling) in mprsas_send_abort()
1592 timeout = sc->nvme_abort_timeout; in mprsas_send_abort()
1594 callout_reset(&tm->cm_callout, timeout * hz, in mprsas_send_abort()
1597 targ->aborts++; in mprsas_send_abort()
1599 mprsas_prepare_for_tm(sc, tm, targ, tm->cm_lun); in mprsas_send_abort()
1605 err, cm, req->TaskMID); in mprsas_send_abort()
1619 sc = cm->cm_sc; in mprsas_scsiio_timeout()
1620 ccb = cm->cm_ccb; in mprsas_scsiio_timeout()
1624 mtx_assert(&sc->mpr_mtx, MA_OWNED); in mprsas_scsiio_timeout()
1631 * and been re-used, though this is unlikely. in mprsas_scsiio_timeout()
1634 if (cm->cm_flags & MPR_CM_FLAGS_ON_RECOVERY) { in mprsas_scsiio_timeout()
1640 if (cm->cm_ccb == NULL) { in mprsas_scsiio_timeout()
1645 targ = cm->cm_targ; in mprsas_scsiio_timeout()
1646 targ->timeouts++; in mprsas_scsiio_timeout()
1648 elapsed = now - ccb->ccb_h.qos.sim_data; in mprsas_scsiio_timeout()
1651 targ->tid, targ->handle, ccb->ccb_h.timeout, in mprsas_scsiio_timeout()
1653 if (targ->encl_level_valid) { in mprsas_scsiio_timeout()
1656 targ->encl_level, targ->encl_slot, targ->connector_name); in mprsas_scsiio_timeout()
1662 mprsas_set_ccbstatus(cm->cm_ccb, CAM_CMD_TIMEOUT); in mprsas_scsiio_timeout()
1663 cm->cm_flags |= MPR_CM_FLAGS_ON_RECOVERY | MPR_CM_FLAGS_TIMEDOUT; in mprsas_scsiio_timeout()
1664 TAILQ_INSERT_TAIL(&targ->timedout_commands, cm, cm_recovery); in mprsas_scsiio_timeout()
1666 if (targ->tm != NULL) { in mprsas_scsiio_timeout()
1672 cm, targ->tm); in mprsas_scsiio_timeout()
1673 } else if ((targ->tm = mprsas_alloc_tm(sc)) != NULL) { in mprsas_scsiio_timeout()
1675 "Sending abort to target %u for SMID %d\n", targ->tid, in mprsas_scsiio_timeout()
1676 cm->cm_desc.Default.SMID); in mprsas_scsiio_timeout()
1678 cm, targ->tm); in mprsas_scsiio_timeout()
1681 mprsas_send_abort(sc, targ->tm, cm); in mprsas_scsiio_timeout()
1698 * mprsas_build_nvme_unmap - Build Native NVMe DSM command equivalent
1700 * Return 0 - for success,
1701 * 1 - to immediately return back the command with success status to CAM
1702 * negative value - to fallback to firmware path i.e. issue scsi unmap
1719 csio = &ccb->csio; in mprsas_build_nvme_unmap()
1723 return -EINVAL; in mprsas_build_nvme_unmap()
1726 plist = malloc(csio->dxfer_len, M_MPR, M_ZERO|M_NOWAIT); in mprsas_build_nvme_unmap()
1730 return -ENOMEM; in mprsas_build_nvme_unmap()
1734 bcopy(csio->data_ptr, plist, csio->dxfer_len); in mprsas_build_nvme_unmap()
1739 ndesc = be16toh(plist->unmap_blk_desc_data_len) >> 4; in mprsas_build_nvme_unmap()
1748 if (data_length > targ->MDTS) { in mprsas_build_nvme_unmap()
1750 "Device's MDTS: %d\n", data_length, targ->MDTS); in mprsas_build_nvme_unmap()
1751 res = -EINVAL; in mprsas_build_nvme_unmap()
1763 TAILQ_INSERT_TAIL(&cm->cm_prp_page_list, prp_page_info, prp_page_link); in mprsas_build_nvme_unmap()
1765 nvme_dsm_ranges = (struct nvme_dsm_range *)prp_page_info->prp_page; in mprsas_build_nvme_unmap()
1766 nvme_dsm_ranges_dma_handle = prp_page_info->prp_page_busaddr; in mprsas_build_nvme_unmap()
1775 htole32(be32toh(plist->desc[i].nlb)); in mprsas_build_nvme_unmap()
1777 htole64(be64toh(plist->desc[i].slba)); in mprsas_build_nvme_unmap()
1782 req = (Mpi26NVMeEncapsulatedRequest_t *)cm->cm_req; in mprsas_build_nvme_unmap()
1784 req->DevHandle = htole16(targ->handle); in mprsas_build_nvme_unmap()
1785 req->Function = MPI2_FUNCTION_NVME_ENCAPSULATED; in mprsas_build_nvme_unmap()
1786 req->Flags = MPI26_NVME_FLAGS_WRITE; in mprsas_build_nvme_unmap()
1787 req->ErrorResponseBaseAddress.High = in mprsas_build_nvme_unmap()
1788 htole32((uint32_t)((uint64_t)cm->cm_sense_busaddr >> 32)); in mprsas_build_nvme_unmap()
1789 req->ErrorResponseBaseAddress.Low = in mprsas_build_nvme_unmap()
1790 htole32(cm->cm_sense_busaddr); in mprsas_build_nvme_unmap()
1791 req->ErrorResponseAllocationLength = in mprsas_build_nvme_unmap()
1793 req->EncapsulatedCommandLength = in mprsas_build_nvme_unmap()
1795 req->DataLength = htole32(data_length); in mprsas_build_nvme_unmap()
1798 c = (struct nvme_command *) req->NVMe_Command; in mprsas_build_nvme_unmap()
1799 c->opc = NVME_OPC_DATASET_MANAGEMENT; in mprsas_build_nvme_unmap()
1800 c->nsid = htole32(csio->ccb_h.target_lun + 1); in mprsas_build_nvme_unmap()
1801 c->cdw10 = htole32(ndesc - 1); in mprsas_build_nvme_unmap()
1802 c->cdw11 = htole32(NVME_DSM_ATTR_DEALLOCATE); in mprsas_build_nvme_unmap()
1804 cm->cm_length = data_length; in mprsas_build_nvme_unmap()
1805 cm->cm_data = NULL; in mprsas_build_nvme_unmap()
1807 cm->cm_complete = mprsas_scsiio_complete; in mprsas_build_nvme_unmap()
1808 cm->cm_complete_data = ccb; in mprsas_build_nvme_unmap()
1809 cm->cm_targ = targ; in mprsas_build_nvme_unmap()
1810 cm->cm_lun = csio->ccb_h.target_lun; in mprsas_build_nvme_unmap()
1811 cm->cm_ccb = ccb; in mprsas_build_nvme_unmap()
1813 cm->cm_desc.Default.RequestFlags = in mprsas_build_nvme_unmap()
1816 csio->ccb_h.qos.sim_data = sbinuptime(); in mprsas_build_nvme_unmap()
1817 callout_reset_sbt(&cm->cm_callout, SBT_1MS * ccb->ccb_h.timeout, 0, in mprsas_build_nvme_unmap()
1820 targ->issued++; in mprsas_build_nvme_unmap()
1821 targ->outstanding++; in mprsas_build_nvme_unmap()
1822 TAILQ_INSERT_TAIL(&targ->commands, cm, cm_link); in mprsas_build_nvme_unmap()
1823 ccb->ccb_h.status |= CAM_SIM_QUEUED; in mprsas_build_nvme_unmap()
1826 __func__, cm, ccb, targ->outstanding); in mprsas_build_nvme_unmap()
1852 sc = sassc->sc; in mprsas_action_scsiio()
1854 mtx_assert(&sc->mpr_mtx, MA_OWNED); in mprsas_action_scsiio()
1856 csio = &ccb->csio; in mprsas_action_scsiio()
1857 KASSERT(csio->ccb_h.target_id < sassc->maxtargets, in mprsas_action_scsiio()
1859 csio->ccb_h.target_id)); in mprsas_action_scsiio()
1860 targ = &sassc->targets[csio->ccb_h.target_id]; in mprsas_action_scsiio()
1861 mpr_dprint(sc, MPR_TRACE, "ccb %p target flag %x\n", ccb, targ->flags); in mprsas_action_scsiio()
1862 if (targ->handle == 0x0) { in mprsas_action_scsiio()
1863 if (targ->flags & MPRSAS_TARGET_INDIAGRESET) { in mprsas_action_scsiio()
1866 __func__, csio->ccb_h.target_id); in mprsas_action_scsiio()
1867 ccb->ccb_h.status = CAM_REQUEUE_REQ | CAM_DEV_QFRZN; in mprsas_action_scsiio()
1868 xpt_freeze_devq(ccb->ccb_h.path, 1); in mprsas_action_scsiio()
1873 __func__, csio->ccb_h.target_id); in mprsas_action_scsiio()
1878 if (targ->flags & MPR_TARGET_FLAGS_RAID_COMPONENT) { in mprsas_action_scsiio()
1880 "supported %u\n", __func__, csio->ccb_h.target_id); in mprsas_action_scsiio()
1892 "target %u\n", __func__, csio->ccb_h.target_id); in mprsas_action_scsiio()
1905 if (targ->flags & MPRSAS_TARGET_INREMOVAL) { in mprsas_action_scsiio()
1906 if (targ->devinfo == 0) in mprsas_action_scsiio()
1914 if ((sc->mpr_flags & MPR_FLAGS_SHUTDOWN) != 0) { in mprsas_action_scsiio()
1925 if (targ->flags & MPRSAS_TARGET_INRESET) { in mprsas_action_scsiio()
1926 ccb->ccb_h.status = CAM_REQUEUE_REQ | CAM_DEV_QFRZN; in mprsas_action_scsiio()
1929 __func__, targ->tid); in mprsas_action_scsiio()
1930 xpt_freeze_devq(ccb->ccb_h.path, 1); in mprsas_action_scsiio()
1936 if (cm == NULL || (sc->mpr_flags & MPR_FLAGS_DIAGRESET)) { in mprsas_action_scsiio()
1940 if ((sassc->flags & MPRSAS_QUEUE_FROZEN) == 0) { in mprsas_action_scsiio()
1941 xpt_freeze_simq(sassc->sim, 1); in mprsas_action_scsiio()
1942 sassc->flags |= MPRSAS_QUEUE_FROZEN; in mprsas_action_scsiio()
1944 ccb->ccb_h.status &= ~CAM_SIM_QUEUED; in mprsas_action_scsiio()
1945 ccb->ccb_h.status |= CAM_REQUEUE_REQ; in mprsas_action_scsiio()
1955 targ->is_nvme && in mprsas_action_scsiio()
1956 (csio->ccb_h.flags & CAM_DATA_MASK) == CAM_DATA_VADDR) { in mprsas_action_scsiio()
1967 req = (MPI2_SCSI_IO_REQUEST *)cm->cm_req; in mprsas_action_scsiio()
1969 req->DevHandle = htole16(targ->handle); in mprsas_action_scsiio()
1970 req->Function = MPI2_FUNCTION_SCSI_IO_REQUEST; in mprsas_action_scsiio()
1971 req->MsgFlags = 0; in mprsas_action_scsiio()
1972 req->SenseBufferLowAddress = htole32(cm->cm_sense_busaddr); in mprsas_action_scsiio()
1973 req->SenseBufferLength = MPR_SENSE_LEN; in mprsas_action_scsiio()
1974 req->SGLFlags = 0; in mprsas_action_scsiio()
1975 req->ChainOffset = 0; in mprsas_action_scsiio()
1976 req->SGLOffset0 = 24; /* 32bit word offset to the SGL */ in mprsas_action_scsiio()
1977 req->SGLOffset1= 0; in mprsas_action_scsiio()
1978 req->SGLOffset2= 0; in mprsas_action_scsiio()
1979 req->SGLOffset3= 0; in mprsas_action_scsiio()
1980 req->SkipCount = 0; in mprsas_action_scsiio()
1981 req->DataLength = htole32(csio->dxfer_len); in mprsas_action_scsiio()
1982 req->BidirectionalDataLength = 0; in mprsas_action_scsiio()
1983 req->IoFlags = htole16(csio->cdb_len); in mprsas_action_scsiio()
1984 req->EEDPFlags = 0; in mprsas_action_scsiio()
1987 switch (csio->ccb_h.flags & CAM_DIR_MASK) { in mprsas_action_scsiio()
1990 cm->cm_flags |= MPR_CM_FLAGS_DATAIN; in mprsas_action_scsiio()
1994 cm->cm_flags |= MPR_CM_FLAGS_DATAOUT; in mprsas_action_scsiio()
2002 if (csio->cdb_len == 32) in mprsas_action_scsiio()
2009 switch (csio->tag_action) { in mprsas_action_scsiio()
2025 mpi_control |= (csio->priority << MPI2_SCSIIO_CONTROL_CMDPRI_SHIFT) & in mprsas_action_scsiio()
2027 mpi_control |= sc->mapping_table[csio->ccb_h.target_id].TLR_bits; in mprsas_action_scsiio()
2028 req->Control = htole32(mpi_control); in mprsas_action_scsiio()
2030 if (MPR_SET_LUN(req->LUN, csio->ccb_h.target_lun) != 0) { in mprsas_action_scsiio()
2037 if (csio->ccb_h.flags & CAM_CDB_POINTER) in mprsas_action_scsiio()
2038 bcopy(csio->cdb_io.cdb_ptr, &req->CDB.CDB32[0], csio->cdb_len); in mprsas_action_scsiio()
2040 KASSERT(csio->cdb_len <= IOCDBLEN, in mprsas_action_scsiio()
2042 "is not set", csio->cdb_len)); in mprsas_action_scsiio()
2043 bcopy(csio->cdb_io.cdb_bytes, &req->CDB.CDB32[0],csio->cdb_len); in mprsas_action_scsiio()
2045 req->IoFlags = htole16(csio->cdb_len); in mprsas_action_scsiio()
2053 eedp_flags = op_code_prot[req->CDB.CDB32[0]]; in mprsas_action_scsiio()
2054 if (sc->eedp_enabled && eedp_flags) { in mprsas_action_scsiio()
2055 SLIST_FOREACH(lun, &targ->luns, lun_link) { in mprsas_action_scsiio()
2056 if (lun->lun_id == csio->ccb_h.target_lun) { in mprsas_action_scsiio()
2061 if ((lun != NULL) && (lun->eedp_formatted)) { in mprsas_action_scsiio()
2062 req->EEDPBlockSize = htole32(lun->eedp_block_size); in mprsas_action_scsiio()
2066 if (sc->mpr_flags & MPR_FLAGS_GEN35_IOC) { in mprsas_action_scsiio()
2070 req->EEDPFlags = htole16(eedp_flags); in mprsas_action_scsiio()
2080 if (csio->cdb_len != 32) { in mprsas_action_scsiio()
2081 lba_byte = (csio->cdb_len == 16) ? 6 : 2; in mprsas_action_scsiio()
2082 ref_tag_addr = (uint8_t *)&req->CDB.EEDP32. in mprsas_action_scsiio()
2086 req->CDB.CDB32[lba_byte + i]; in mprsas_action_scsiio()
2089 req->CDB.EEDP32.PrimaryReferenceTag = in mprsas_action_scsiio()
2090 htole32(req-> in mprsas_action_scsiio()
2092 req->CDB.EEDP32.PrimaryApplicationTagMask = in mprsas_action_scsiio()
2094 req->CDB.CDB32[1] = in mprsas_action_scsiio()
2095 (req->CDB.CDB32[1] & 0x1F) | 0x20; in mprsas_action_scsiio()
2099 req->EEDPFlags = htole16(eedp_flags); in mprsas_action_scsiio()
2100 req->CDB.CDB32[10] = (req->CDB.CDB32[10] & in mprsas_action_scsiio()
2106 cm->cm_length = csio->dxfer_len; in mprsas_action_scsiio()
2107 if (cm->cm_length != 0) { in mprsas_action_scsiio()
2108 cm->cm_data = ccb; in mprsas_action_scsiio()
2109 cm->cm_flags |= MPR_CM_FLAGS_USE_CCB; in mprsas_action_scsiio()
2111 cm->cm_data = NULL; in mprsas_action_scsiio()
2113 cm->cm_sge = &req->SGL; in mprsas_action_scsiio()
2114 cm->cm_sglsize = (32 - 24) * 4; in mprsas_action_scsiio()
2115 cm->cm_complete = mprsas_scsiio_complete; in mprsas_action_scsiio()
2116 cm->cm_complete_data = ccb; in mprsas_action_scsiio()
2117 cm->cm_targ = targ; in mprsas_action_scsiio()
2118 cm->cm_lun = csio->ccb_h.target_lun; in mprsas_action_scsiio()
2119 cm->cm_ccb = ccb; in mprsas_action_scsiio()
2124 if (targ->scsi_req_desc_type == in mprsas_action_scsiio()
2126 req->IoFlags |= MPI25_SCSIIO_IOFLAGS_FAST_PATH; in mprsas_action_scsiio()
2127 cm->cm_desc.FastPathSCSIIO.RequestFlags = in mprsas_action_scsiio()
2129 if (!sc->atomic_desc_capable) { in mprsas_action_scsiio()
2130 cm->cm_desc.FastPathSCSIIO.DevHandle = in mprsas_action_scsiio()
2131 htole16(targ->handle); in mprsas_action_scsiio()
2134 cm->cm_desc.SCSIIO.RequestFlags = in mprsas_action_scsiio()
2136 if (!sc->atomic_desc_capable) in mprsas_action_scsiio()
2137 cm->cm_desc.SCSIIO.DevHandle = htole16(targ->handle); in mprsas_action_scsiio()
2140 csio->ccb_h.qos.sim_data = sbinuptime(); in mprsas_action_scsiio()
2141 callout_reset_sbt(&cm->cm_callout, SBT_1MS * ccb->ccb_h.timeout, 0, in mprsas_action_scsiio()
2144 targ->issued++; in mprsas_action_scsiio()
2145 targ->outstanding++; in mprsas_action_scsiio()
2146 TAILQ_INSERT_TAIL(&targ->commands, cm, cm_link); in mprsas_action_scsiio()
2147 ccb->ccb_h.status |= CAM_SIM_QUEUED; in mprsas_action_scsiio()
2150 __func__, cm, ccb, targ->outstanding); in mprsas_action_scsiio()
2157 * mpr_sc_failed_io_info - translated non-succesfull SCSI_IO request
2165 u16 ioc_status = le16toh(mpi_reply->IOCStatus) & in mpr_sc_failed_io_info()
2167 u8 scsi_state = mpi_reply->SCSIState; in mpr_sc_failed_io_info()
2168 u8 scsi_status = mpi_reply->SCSIStatus; in mpr_sc_failed_io_info()
2171 u32 log_info = le32toh(mpi_reply->IOCLogInfo); in mpr_sc_failed_io_info()
2182 le16toh(mpi_reply->DevHandle), desc_ioc_state, ioc_status); in mpr_sc_failed_io_info()
2183 if (targ->encl_level_valid) { in mpr_sc_failed_io_info()
2185 "connector name (%4s)\n", targ->encl_level, targ->encl_slot, in mpr_sc_failed_io_info()
2186 targ->connector_name); in mpr_sc_failed_io_info()
2191 * TO-DO in mpr_sc_failed_io_info()
2198 if (sc->mpr_debug & MPR_XINFO && in mpr_sc_failed_io_info()
2200 mpr_dprint(sc, MPR_XINFO, "-> Sense Buffer Data : Start :\n"); in mpr_sc_failed_io_info()
2202 mpr_dprint(sc, MPR_XINFO, "-> Sense Buffer Data : End :\n"); in mpr_sc_failed_io_info()
2206 response_info = le32toh(mpi_reply->ResponseInfo); in mpr_sc_failed_io_info()
2228 union ccb *ccb = cm->cm_complete_data; in mprsas_nvme_trans_status_code()
2379 if (returned_sense_len < ccb->csio.sense_len) in mprsas_nvme_trans_status_code()
2380 ccb->csio.sense_resid = ccb->csio.sense_len - in mprsas_nvme_trans_status_code()
2383 ccb->csio.sense_resid = 0; in mprsas_nvme_trans_status_code()
2385 scsi_set_sense_data(&ccb->csio.sense_data, SSD_TYPE_FIXED, in mprsas_nvme_trans_status_code()
2387 ccb->ccb_h.status |= CAM_AUTOSNS_VALID; in mprsas_nvme_trans_status_code()
2404 mpi_reply =(Mpi26NVMeEncapsulatedErrorReply_t *)cm->cm_reply; in mprsas_complete_nvme_unmap()
2405 if (le16toh(mpi_reply->ErrorResponseCount)){ in mprsas_complete_nvme_unmap()
2406 nvme_completion = (struct nvme_completion *)cm->cm_sense; in mprsas_complete_nvme_unmap()
2408 nvme_completion->status, cm); in mprsas_complete_nvme_unmap()
2429 callout_stop(&cm->cm_callout); in mprsas_scsiio_complete()
2430 mtx_assert(&sc->mpr_mtx, MA_OWNED); in mprsas_scsiio_complete()
2432 sassc = sc->sassc; in mprsas_scsiio_complete()
2433 ccb = cm->cm_complete_data; in mprsas_scsiio_complete()
2434 csio = &ccb->csio; in mprsas_scsiio_complete()
2435 target_id = csio->ccb_h.target_id; in mprsas_scsiio_complete()
2436 rep = (MPI2_SCSI_IO_REPLY *)cm->cm_reply; in mprsas_scsiio_complete()
2438 "cm %p SMID %u ccb %p reply %p outstanding %u csio->scsi_status 0x%x," in mprsas_scsiio_complete()
2439 "csio->dxfer_len 0x%x, csio->msg_le 0x%xn\n", cm, in mprsas_scsiio_complete()
2440 cm->cm_desc.Default.SMID, cm->cm_ccb, cm->cm_reply, in mprsas_scsiio_complete()
2441 cm->cm_targ->outstanding, csio->scsi_status, in mprsas_scsiio_complete()
2442 csio->dxfer_len, csio->msg_len); in mprsas_scsiio_complete()
2448 if (cm->cm_data != NULL) { in mprsas_scsiio_complete()
2449 if (cm->cm_flags & MPR_CM_FLAGS_DATAIN) in mprsas_scsiio_complete()
2451 else if (cm->cm_flags & MPR_CM_FLAGS_DATAOUT) in mprsas_scsiio_complete()
2453 bus_dmamap_sync(sc->buffer_dmat, cm->cm_dmamap, dir); in mprsas_scsiio_complete()
2454 bus_dmamap_unload(sc->buffer_dmat, cm->cm_dmamap); in mprsas_scsiio_complete()
2457 cm->cm_targ->completed++; in mprsas_scsiio_complete()
2458 cm->cm_targ->outstanding--; in mprsas_scsiio_complete()
2459 TAILQ_REMOVE(&cm->cm_targ->commands, cm, cm_link); in mprsas_scsiio_complete()
2460 ccb->ccb_h.status &= ~(CAM_STATUS_MASK | CAM_SIM_QUEUED); in mprsas_scsiio_complete()
2462 if (cm->cm_flags & MPR_CM_FLAGS_ON_RECOVERY) { in mprsas_scsiio_complete()
2463 TAILQ_REMOVE(&cm->cm_targ->timedout_commands, cm, cm_recovery); in mprsas_scsiio_complete()
2464 KASSERT(cm->cm_state == MPR_CM_STATE_BUSY, in mprsas_scsiio_complete()
2465 ("Not busy for CM_FLAGS_TIMEDOUT: %u\n", cm->cm_state)); in mprsas_scsiio_complete()
2466 cm->cm_flags &= ~MPR_CM_FLAGS_ON_RECOVERY; in mprsas_scsiio_complete()
2467 if (cm->cm_reply != NULL) in mprsas_scsiio_complete()
2470 "ioc %x scsi %x state %x xfer %u\n", cm, cm->cm_ccb, in mprsas_scsiio_complete()
2471 le16toh(rep->IOCStatus), rep->SCSIStatus, in mprsas_scsiio_complete()
2472 rep->SCSIState, le32toh(rep->TransferCount)); in mprsas_scsiio_complete()
2476 cm, cm->cm_ccb); in mprsas_scsiio_complete()
2477 } else if (cm->cm_targ->tm != NULL) { in mprsas_scsiio_complete()
2478 if (cm->cm_reply != NULL) in mprsas_scsiio_complete()
2482 cm, cm->cm_ccb, le16toh(rep->IOCStatus), in mprsas_scsiio_complete()
2483 rep->SCSIStatus, rep->SCSIState, in mprsas_scsiio_complete()
2484 le32toh(rep->TransferCount)); in mprsas_scsiio_complete()
2488 cm, cm->cm_ccb); in mprsas_scsiio_complete()
2489 } else if ((sc->mpr_flags & MPR_FLAGS_DIAGRESET) != 0) { in mprsas_scsiio_complete()
2491 "reset completed cm %p ccb %p\n", cm, cm->cm_ccb); in mprsas_scsiio_complete()
2494 if ((cm->cm_flags & MPR_CM_FLAGS_ERROR_MASK) != 0) { in mprsas_scsiio_complete()
2516 if ((sassc->flags & MPRSAS_QUEUE_FROZEN) == 0) { in mprsas_scsiio_complete()
2517 xpt_freeze_simq(sassc->sim, 1); in mprsas_scsiio_complete()
2518 sassc->flags |= MPRSAS_QUEUE_FROZEN; in mprsas_scsiio_complete()
2538 if (sc->SSU_started && (scsi_cdb[0] == START_STOP_UNIT)) { in mprsas_scsiio_complete()
2540 sc->SSU_refcount--; in mprsas_scsiio_complete()
2544 if (cm->cm_reply == NULL) { in mprsas_scsiio_complete()
2546 if ((sc->mpr_flags & MPR_FLAGS_DIAGRESET) != 0) in mprsas_scsiio_complete()
2550 csio->scsi_status = SCSI_STATUS_OK; in mprsas_scsiio_complete()
2552 if (sassc->flags & MPRSAS_QUEUE_FROZEN) { in mprsas_scsiio_complete()
2553 ccb->ccb_h.status |= CAM_RELEASE_SIMQ; in mprsas_scsiio_complete()
2554 sassc->flags &= ~MPRSAS_QUEUE_FROZEN; in mprsas_scsiio_complete()
2571 ccb->ccb_h.status |= CAM_DEV_QFRZN; in mprsas_scsiio_complete()
2572 xpt_freeze_devq(ccb->ccb_h.path, /*count*/ 1); in mprsas_scsiio_complete()
2579 target = &sassc->targets[target_id]; in mprsas_scsiio_complete()
2581 target->is_nvme && in mprsas_scsiio_complete()
2582 (csio->ccb_h.flags & CAM_DATA_MASK) == CAM_DATA_VADDR) { in mprsas_scsiio_complete()
2583 rep->SCSIStatus = mprsas_complete_nvme_unmap(sc, cm); in mprsas_scsiio_complete()
2584 csio->scsi_status = rep->SCSIStatus; in mprsas_scsiio_complete()
2589 le16toh(rep->IOCStatus), rep->SCSIStatus, rep->SCSIState, in mprsas_scsiio_complete()
2590 le32toh(rep->TransferCount)); in mprsas_scsiio_complete()
2592 switch (le16toh(rep->IOCStatus) & MPI2_IOCSTATUS_MASK) { in mprsas_scsiio_complete()
2594 csio->resid = cm->cm_length - le32toh(rep->TransferCount); in mprsas_scsiio_complete()
2598 if ((le16toh(rep->IOCStatus) & MPI2_IOCSTATUS_MASK) == in mprsas_scsiio_complete()
2603 if (rep->SCSIState & (MPI2_SCSI_STATE_NO_SCSI_STATUS | in mprsas_scsiio_complete()
2613 if (rep->SCSIState & MPI2_SCSI_STATE_AUTOSENSE_FAILED) { in mprsas_scsiio_complete()
2623 if ((rep->SCSIState & MPI2_SCSI_STATE_RESPONSE_INFO_VALID) && in mprsas_scsiio_complete()
2624 ((le32toh(rep->ResponseInfo) & MPI2_SCSI_RI_MASK_REASONCODE) in mprsas_scsiio_complete()
2626 sc->mapping_table[target_id].TLR_bits = in mprsas_scsiio_complete()
2631 * Intentionally override the normal SCSI status reporting in mprsas_scsiio_complete()
2633 * multi-initiator environment, and we want to make sure that in mprsas_scsiio_complete()
2636 if ((rep->SCSIStatus == MPI2_SCSI_STATUS_COMMAND_TERMINATED) || in mprsas_scsiio_complete()
2637 (rep->SCSIStatus == MPI2_SCSI_STATUS_TASK_ABORTED)) { in mprsas_scsiio_complete()
2643 csio->scsi_status = rep->SCSIStatus; in mprsas_scsiio_complete()
2644 if (rep->SCSIStatus == MPI2_SCSI_STATUS_GOOD) in mprsas_scsiio_complete()
2649 if (rep->SCSIState & MPI2_SCSI_STATE_AUTOSENSE_VALID) { in mprsas_scsiio_complete()
2652 returned_sense_len = min(le32toh(rep->SenseCount), in mprsas_scsiio_complete()
2654 if (returned_sense_len < csio->sense_len) in mprsas_scsiio_complete()
2655 csio->sense_resid = csio->sense_len - in mprsas_scsiio_complete()
2658 csio->sense_resid = 0; in mprsas_scsiio_complete()
2661 csio->sense_len - csio->sense_resid); in mprsas_scsiio_complete()
2662 bzero(&csio->sense_data, sizeof(csio->sense_data)); in mprsas_scsiio_complete()
2663 bcopy(cm->cm_sense, &csio->sense_data, sense_len); in mprsas_scsiio_complete()
2664 ccb->ccb_h.status |= CAM_AUTOSNS_VALID; in mprsas_scsiio_complete()
2678 ((csio->ccb_h.flags & CAM_DATA_MASK) == CAM_DATA_VADDR) && in mprsas_scsiio_complete()
2679 (csio->data_ptr != NULL) && in mprsas_scsiio_complete()
2680 ((csio->data_ptr[0] & 0x1f) == T_SEQUENTIAL) && in mprsas_scsiio_complete()
2681 (sc->control_TLR) && in mprsas_scsiio_complete()
2682 (sc->mapping_table[target_id].device_info & in mprsas_scsiio_complete()
2685 csio->data_ptr; in mprsas_scsiio_complete()
2686 TLR_bits = &sc->mapping_table[target_id].TLR_bits; in mprsas_scsiio_complete()
2690 alloc_len -= csio->resid; in mprsas_scsiio_complete()
2691 for (i = 0; i < MIN(vpd_list->length, alloc_len); i++) { in mprsas_scsiio_complete()
2692 if (vpd_list->list[i] == 0x90) { in mprsas_scsiio_complete()
2700 * If this is a SATA direct-access end device, mark it so that in mprsas_scsiio_complete()
2705 (csio->data_ptr != NULL) && in mprsas_scsiio_complete()
2706 ((csio->data_ptr[0] & 0x1f) == T_DIRECT) && in mprsas_scsiio_complete()
2707 (sc->mapping_table[target_id].device_info & in mprsas_scsiio_complete()
2709 ((sc->mapping_table[target_id].device_info & in mprsas_scsiio_complete()
2712 target = &sassc->targets[target_id]; in mprsas_scsiio_complete()
2713 target->supports_SSU = TRUE; in mprsas_scsiio_complete()
2726 if (cm->cm_targ->devinfo == 0) in mprsas_scsiio_complete()
2745 if (cm->cm_flags & MPR_CM_FLAGS_TIMEDOUT) in mprsas_scsiio_complete()
2752 csio->resid = 0; in mprsas_scsiio_complete()
2758 * These can sometimes be transient transport-related in mprsas_scsiio_complete()
2759 * errors, and sometimes persistent drive-related errors. in mprsas_scsiio_complete()
2767 * of a topology-related error (e.g. a SAS expander problem in mprsas_scsiio_complete()
2774 if (cm->cm_targ->flags & MPRSAS_TARGET_INREMOVAL) in mprsas_scsiio_complete()
2781 le16toh(rep->IOCStatus) & MPI2_IOCSTATUS_MASK), in mprsas_scsiio_complete()
2782 target_id, cm->cm_desc.Default.SMID, in mprsas_scsiio_complete()
2783 le32toh(rep->IOCLogInfo), in mprsas_scsiio_complete()
2784 (cm->cm_targ->flags & MPRSAS_TARGET_INREMOVAL) ? " departing" : ""); in mprsas_scsiio_complete()
2787 rep->SCSIStatus, rep->SCSIState, in mprsas_scsiio_complete()
2788 le32toh(rep->TransferCount)); in mprsas_scsiio_complete()
2803 le16toh(rep->IOCStatus), le32toh(rep->IOCLogInfo), in mprsas_scsiio_complete()
2804 rep->SCSIStatus, rep->SCSIState, in mprsas_scsiio_complete()
2805 le32toh(rep->TransferCount)); in mprsas_scsiio_complete()
2806 csio->resid = cm->cm_length; in mprsas_scsiio_complete()
2809 target->is_nvme && in mprsas_scsiio_complete()
2810 (csio->ccb_h.flags & CAM_DATA_MASK) == CAM_DATA_VADDR) in mprsas_scsiio_complete()
2818 mpr_sc_failed_io_info(sc, csio, rep, cm->cm_targ); in mprsas_scsiio_complete()
2820 if (sassc->flags & MPRSAS_QUEUE_FROZEN) { in mprsas_scsiio_complete()
2821 ccb->ccb_h.status |= CAM_RELEASE_SIMQ; in mprsas_scsiio_complete()
2822 sassc->flags &= ~MPRSAS_QUEUE_FROZEN; in mprsas_scsiio_complete()
2828 ccb->ccb_h.status |= CAM_DEV_QFRZN; in mprsas_scsiio_complete()
2829 xpt_freeze_devq(ccb->ccb_h.path, /*count*/ 1); in mprsas_scsiio_complete()
2838 if (cm->cm_targ->flags & MPRSAS_TARGET_INREMOVAL) { in mprsas_scsiio_complete()
2839 if (TAILQ_FIRST(&cm->cm_targ->commands) == NULL && in mprsas_scsiio_complete()
2840 cm->cm_targ->pending_remove_tm != NULL) { in mprsas_scsiio_complete()
2843 cm->cm_targ->tid, cm->cm_targ->handle); in mprsas_scsiio_complete()
2844 mpr_map_command(sc, cm->cm_targ->pending_remove_tm); in mprsas_scsiio_complete()
2845 cm->cm_targ->pending_remove_tm = NULL; in mprsas_scsiio_complete()
2861 ccb = cm->cm_complete_data; in mprsas_smpio_complete()
2869 if ((cm->cm_flags & MPR_CM_FLAGS_ERROR_MASK) != 0) { in mprsas_smpio_complete()
2871 "request!\n", __func__, cm->cm_flags); in mprsas_smpio_complete()
2876 rpl = (MPI2_SMP_PASSTHROUGH_REPLY *)cm->cm_reply; in mprsas_smpio_complete()
2883 req = (MPI2_SMP_PASSTHROUGH_REQUEST *)cm->cm_req; in mprsas_smpio_complete()
2884 sasaddr = le32toh(req->SASAddress.Low); in mprsas_smpio_complete()
2885 sasaddr |= ((uint64_t)(le32toh(req->SASAddress.High))) << 32; in mprsas_smpio_complete()
2887 if ((le16toh(rpl->IOCStatus) & MPI2_IOCSTATUS_MASK) != in mprsas_smpio_complete()
2889 rpl->SASStatus != MPI2_SASSTATUS_SUCCESS) { in mprsas_smpio_complete()
2891 __func__, le16toh(rpl->IOCStatus), rpl->SASStatus); in mprsas_smpio_complete()
2899 if (ccb->smpio.smp_response[2] == SMP_FR_ACCEPTED) in mprsas_smpio_complete()
2909 bus_dmamap_sync(sc->buffer_dmat, cm->cm_dmamap, in mprsas_smpio_complete()
2911 bus_dmamap_unload(sc->buffer_dmat, cm->cm_dmamap); in mprsas_smpio_complete()
2925 sc = sassc->sc; in mprsas_send_smpcmd()
2928 switch (ccb->ccb_h.flags & CAM_DATA_MASK) { in mprsas_send_smpcmd()
2944 if ((ccb->smpio.smp_request_sglist_cnt > 1) in mprsas_send_smpcmd()
2945 || (ccb->smpio.smp_response_sglist_cnt > 1)) { in mprsas_send_smpcmd()
2962 if (ccb->smpio.smp_request_sglist_cnt != 0) { in mprsas_send_smpcmd()
2965 req_sg = (bus_dma_segment_t *)ccb->smpio.smp_request; in mprsas_send_smpcmd()
2968 request = ccb->smpio.smp_request; in mprsas_send_smpcmd()
2970 if (ccb->smpio.smp_response_sglist_cnt != 0) { in mprsas_send_smpcmd()
2973 rsp_sg = (bus_dma_segment_t *)ccb->smpio.smp_response; in mprsas_send_smpcmd()
2976 response = ccb->smpio.smp_response; in mprsas_send_smpcmd()
2979 request = ccb->smpio.smp_request; in mprsas_send_smpcmd()
2980 response = ccb->smpio.smp_response; in mprsas_send_smpcmd()
2997 req = (MPI2_SMP_PASSTHROUGH_REQUEST *)cm->cm_req; in mprsas_send_smpcmd()
2999 req->Function = MPI2_FUNCTION_SMP_PASSTHROUGH; in mprsas_send_smpcmd()
3002 req->PhysicalPort = 0xff; in mprsas_send_smpcmd()
3004 req->RequestDataLength = htole16(ccb->smpio.smp_request_len); in mprsas_send_smpcmd()
3005 req->SGLFlags = in mprsas_send_smpcmd()
3011 mpr_init_sge(cm, req, &req->SGL); in mprsas_send_smpcmd()
3017 cm->cm_uio.uio_iov = cm->cm_iovec; in mprsas_send_smpcmd()
3018 cm->cm_uio.uio_iovcnt = 2; in mprsas_send_smpcmd()
3019 cm->cm_uio.uio_segflg = UIO_SYSSPACE; in mprsas_send_smpcmd()
3026 cm->cm_uio.uio_rw = UIO_WRITE; in mprsas_send_smpcmd()
3028 cm->cm_iovec[0].iov_base = request; in mprsas_send_smpcmd()
3029 cm->cm_iovec[0].iov_len = le16toh(req->RequestDataLength); in mprsas_send_smpcmd()
3030 cm->cm_iovec[1].iov_base = response; in mprsas_send_smpcmd()
3031 cm->cm_iovec[1].iov_len = ccb->smpio.smp_response_len; in mprsas_send_smpcmd()
3033 cm->cm_uio.uio_resid = cm->cm_iovec[0].iov_len + in mprsas_send_smpcmd()
3034 cm->cm_iovec[1].iov_len; in mprsas_send_smpcmd()
3041 cm->cm_max_segs = 2; in mprsas_send_smpcmd()
3043 cm->cm_desc.Default.RequestFlags = MPI2_REQ_DESCRIPT_FLAGS_DEFAULT_TYPE; in mprsas_send_smpcmd()
3044 cm->cm_complete = mprsas_smpio_complete; in mprsas_send_smpcmd()
3045 cm->cm_complete_data = ccb; in mprsas_send_smpcmd()
3049 * an SMP passthrough request. There is a little special-case in mprsas_send_smpcmd()
3053 cm->cm_flags |= MPR_CM_FLAGS_USE_UIO | MPR_CM_FLAGS_SMP_PASS | in mprsas_send_smpcmd()
3057 req->SASAddress.High = htole32(sasaddr >> 32); in mprsas_send_smpcmd()
3058 req->SASAddress.Low = htole32(sasaddr); in mprsas_send_smpcmd()
3091 sc = sassc->sc; in mprsas_action_smpio()
3096 KASSERT(ccb->ccb_h.target_id < sassc->maxtargets, in mprsas_action_smpio()
3097 ("Target %d out of bounds in XPT_SMP_IO\n", ccb->ccb_h.target_id)); in mprsas_action_smpio()
3098 targ = &sassc->targets[ccb->ccb_h.target_id]; in mprsas_action_smpio()
3099 if (targ->handle == 0x0) { in mprsas_action_smpio()
3101 __func__, ccb->ccb_h.target_id); in mprsas_action_smpio()
3112 if ((targ->devinfo & MPI2_SAS_DEVICE_INFO_SMP_TARGET) != 0) in mprsas_action_smpio()
3113 sasaddr = targ->sasaddr; in mprsas_action_smpio()
3119 * expander SAS address as the port-associated SAS address in in mprsas_action_smpio()
3135 sasaddr = xpt_path_sas_addr(ccb->ccb_h.path); in mprsas_action_smpio()
3147 if (targ->parent_handle == 0x0) { in mprsas_action_smpio()
3149 "a valid parent handle!\n", __func__, targ->handle); in mprsas_action_smpio()
3155 targ->parent_handle); in mprsas_action_smpio()
3159 "a valid parent target!\n", __func__, targ->handle); in mprsas_action_smpio()
3164 if ((parent_target->devinfo & in mprsas_action_smpio()
3168 targ->handle, parent_target->handle); in mprsas_action_smpio()
3173 sasaddr = parent_target->sasaddr; in mprsas_action_smpio()
3175 if ((targ->parent_devinfo & in mprsas_action_smpio()
3179 targ->handle, targ->parent_handle); in mprsas_action_smpio()
3183 if (targ->parent_sasaddr == 0x0) { in mprsas_action_smpio()
3186 targ->handle, targ->parent_handle); in mprsas_action_smpio()
3191 sasaddr = targ->parent_sasaddr; in mprsas_action_smpio()
3197 "handle %d\n", __func__, targ->handle); in mprsas_action_smpio()
3218 MPR_FUNCTRACE(sassc->sc); in mprsas_action_resetdev()
3219 mtx_assert(&sassc->sc->mpr_mtx, MA_OWNED); in mprsas_action_resetdev()
3221 KASSERT(ccb->ccb_h.target_id < sassc->maxtargets, ("Target %d out of " in mprsas_action_resetdev()
3222 "bounds in XPT_RESET_DEV\n", ccb->ccb_h.target_id)); in mprsas_action_resetdev()
3223 sc = sassc->sc; in mprsas_action_resetdev()
3233 targ = &sassc->targets[ccb->ccb_h.target_id]; in mprsas_action_resetdev()
3234 req = (MPI2_SCSI_TASK_MANAGE_REQUEST *)tm->cm_req; in mprsas_action_resetdev()
3235 req->DevHandle = htole16(targ->handle); in mprsas_action_resetdev()
3236 req->TaskType = MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET; in mprsas_action_resetdev()
3238 if (!targ->is_nvme || sc->custom_nvme_tm_handling) { in mprsas_action_resetdev()
3240 req->MsgFlags = MPI2_SCSITASKMGMT_MSGFLAGS_LINK_RESET; in mprsas_action_resetdev()
3243 req->MsgFlags = in mprsas_action_resetdev()
3247 tm->cm_data = NULL; in mprsas_action_resetdev()
3248 tm->cm_complete = mprsas_resetdev_complete; in mprsas_action_resetdev()
3249 tm->cm_complete_data = ccb; in mprsas_action_resetdev()
3252 __func__, targ->tid); in mprsas_action_resetdev()
3253 tm->cm_targ = targ; in mprsas_action_resetdev()
3266 mtx_assert(&sc->mpr_mtx, MA_OWNED); in mprsas_resetdev_complete()
3268 resp = (MPI2_SCSI_TASK_MANAGE_REPLY *)tm->cm_reply; in mprsas_resetdev_complete()
3269 ccb = tm->cm_complete_data; in mprsas_resetdev_complete()
3276 if ((tm->cm_flags & MPR_CM_FLAGS_ERROR_MASK) != 0) { in mprsas_resetdev_complete()
3279 req = (MPI2_SCSI_TASK_MANAGE_REQUEST *)tm->cm_req; in mprsas_resetdev_complete()
3283 tm->cm_flags, req->DevHandle); in mprsas_resetdev_complete()
3289 __func__, le16toh(resp->IOCStatus), le32toh(resp->ResponseCode)); in mprsas_resetdev_complete()
3291 if (le32toh(resp->ResponseCode) == MPI2_SCSITASKMGMT_RSP_TM_COMPLETE) { in mprsas_resetdev_complete()
3293 mprsas_announce_reset(sc, AC_SENT_BDR, tm->cm_targ->tid, in mprsas_resetdev_complete()
3312 if (sassc->sc->mpr_debug & MPR_TRACE) { in mprsas_poll()
3316 mpr_dprint(sassc->sc, MPR_XINFO, "%s clearing MPR_TRACE\n", in mprsas_poll()
3318 sassc->sc->mpr_debug &= ~MPR_TRACE; in mprsas_poll()
3321 mpr_intr_locked(sassc->sc); in mprsas_poll()
3347 sassc = sc->sassc; in mprsas_async()
3358 KASSERT(xpt_path_target_id(path) < sassc->maxtargets, in mprsas_async()
3361 target = &sassc->targets[xpt_path_target_id(path)]; in mprsas_async()
3362 if (target->handle == 0) in mprsas_async()
3367 SLIST_FOREACH(lun, &target->luns, lun_link) { in mprsas_async()
3368 if (lun->lun_id == lunid) { in mprsas_async()
3382 lun->lun_id = lunid; in mprsas_async()
3383 SLIST_INSERT_HEAD(&target->luns, lun, lun_link); in mprsas_async()
3404 lun->eedp_formatted = TRUE; in mprsas_async()
3405 lun->eedp_block_size = in mprsas_async()
3410 lun->eedp_formatted = FALSE; in mprsas_async()
3411 lun->eedp_block_size = 0; in mprsas_async()
3415 lun->eedp_formatted = FALSE; in mprsas_async()
3416 lun->eedp_block_size = 0; in mprsas_async()
3446 path_id = cam_sim_path(sc->sassc->sim); in mprsas_prepare_for_tm()
3447 if (xpt_create_path(&ccb->ccb_h.path, xpt_periph, path_id, in mprsas_prepare_for_tm()
3448 target->tid, lun_id) != CAM_REQ_CMP) { in mprsas_prepare_for_tm()
3451 tm->cm_ccb = ccb; in mprsas_prepare_for_tm()
3452 tm->cm_targ = target; in mprsas_prepare_for_tm()
3453 if ((target->flags & MPRSAS_TARGET_INRESET) == 0) { in mprsas_prepare_for_tm()
3456 __func__, target->tid); in mprsas_prepare_for_tm()
3457 xpt_freeze_devq(ccb->ccb_h.path, 1); in mprsas_prepare_for_tm()
3458 target->flags |= MPRSAS_TARGET_INRESET; in mprsas_prepare_for_tm()
3472 sc->wait_for_port_enable = 1; in mprsas_startup()
3487 request = (MPI2_PORT_ENABLE_REQUEST *)cm->cm_req; in mprsas_send_portenable()
3488 request->Function = MPI2_FUNCTION_PORT_ENABLE; in mprsas_send_portenable()
3489 request->MsgFlags = 0; in mprsas_send_portenable()
3490 request->VP_ID = 0; in mprsas_send_portenable()
3491 cm->cm_desc.Default.RequestFlags = MPI2_REQ_DESCRIPT_FLAGS_DEFAULT_TYPE; in mprsas_send_portenable()
3492 cm->cm_complete = mprsas_portenable_complete; in mprsas_send_portenable()
3493 cm->cm_data = NULL; in mprsas_send_portenable()
3494 cm->cm_sge = NULL; in mprsas_send_portenable()
3499 cm, cm->cm_req, cm->cm_complete); in mprsas_send_portenable()
3510 sassc = sc->sassc; in mprsas_portenable_complete()
3517 if ((cm->cm_flags & MPR_CM_FLAGS_ERROR_MASK) != 0) { in mprsas_portenable_complete()
3519 "This should not happen!\n", __func__, cm->cm_flags); in mprsas_portenable_complete()
3522 reply = (MPI2_PORT_ENABLE_REPLY *)cm->cm_reply; in mprsas_portenable_complete()
3525 else if ((le16toh(reply->IOCStatus) & MPI2_IOCSTATUS_MASK) != in mprsas_portenable_complete()
3535 sc->wait_for_port_enable = 0; in mprsas_portenable_complete()
3536 sc->port_enable_complete = 1; in mprsas_portenable_complete()
3537 wakeup(&sc->port_enable_complete); in mprsas_portenable_complete()
3544 struct mpr_softc *sc = sassc->sc; in mprsas_check_id()
3548 ids = &sc->exclude_ids[0]; in mprsas_check_id()
3567 sassc = sc->sassc; in mprsas_realloc_targets()
3574 targ = &sassc->targets[i]; in mprsas_realloc_targets()
3575 SLIST_FOREACH_SAFE(lun, &targ->luns, lun_link, lun_tmp) { in mprsas_realloc_targets()
3579 free(sassc->targets, M_MPR); in mprsas_realloc_targets()
3581 sassc->targets = malloc(sizeof(struct mprsas_target) * maxtargets, in mprsas_realloc_targets()