Lines Matching refs:sc

66 static int mrsas_setup_msix(struct mrsas_softc *sc);
67 static int mrsas_allocate_msix(struct mrsas_softc *sc);
68 static void mrsas_shutdown_ctlr(struct mrsas_softc *sc, u_int32_t opcode);
69 static void mrsas_flush_cache(struct mrsas_softc *sc);
70 static void mrsas_reset_reply_desc(struct mrsas_softc *sc);
72 static int mrsas_get_map_info(struct mrsas_softc *sc);
73 static int mrsas_get_ld_map_info(struct mrsas_softc *sc);
74 static int mrsas_sync_map_info(struct mrsas_softc *sc);
75 static int mrsas_get_pd_list(struct mrsas_softc *sc);
76 static int mrsas_get_ld_list(struct mrsas_softc *sc);
77 static int mrsas_setup_irq(struct mrsas_softc *sc);
78 static int mrsas_alloc_mem(struct mrsas_softc *sc);
79 static int mrsas_init_fw(struct mrsas_softc *sc);
80 static int mrsas_setup_raidmap(struct mrsas_softc *sc);
81 static void megasas_setup_jbod_map(struct mrsas_softc *sc);
82 static int megasas_sync_pd_seq_num(struct mrsas_softc *sc, boolean_t pend);
83 static int mrsas_clear_intr(struct mrsas_softc *sc);
84 static int mrsas_get_ctrl_info(struct mrsas_softc *sc);
85 static void mrsas_update_ext_vd_details(struct mrsas_softc *sc);
87 mrsas_issue_blocked_abort_cmd(struct mrsas_softc *sc,
90 mrsas_get_pd_info(struct mrsas_softc *sc, u_int16_t device_id);
95 mrsas_read_reg_with_retries(struct mrsas_softc *sc, int offset);
96 u_int32_t mrsas_read_reg(struct mrsas_softc *sc, int offset);
98 mrsas_build_mptmfi_passthru(struct mrsas_softc *sc,
100 void mrsas_complete_outstanding_ioctls(struct mrsas_softc *sc);
101 int mrsas_transition_to_ready(struct mrsas_softc *sc, int ocr);
102 int mrsas_init_adapter(struct mrsas_softc *sc);
103 int mrsas_alloc_mpt_cmds(struct mrsas_softc *sc);
104 int mrsas_alloc_ioc_cmd(struct mrsas_softc *sc);
105 int mrsas_alloc_ctlr_info_cmd(struct mrsas_softc *sc);
106 int mrsas_ioc_init(struct mrsas_softc *sc);
107 int mrsas_bus_scan(struct mrsas_softc *sc);
108 int mrsas_issue_dcmd(struct mrsas_softc *sc, struct mrsas_mfi_cmd *cmd);
109 int mrsas_issue_polled(struct mrsas_softc *sc, struct mrsas_mfi_cmd *cmd);
110 int mrsas_reset_ctrl(struct mrsas_softc *sc, u_int8_t reset_reason);
111 int mrsas_wait_for_outstanding(struct mrsas_softc *sc, u_int8_t check_reason);
112 int mrsas_complete_cmd(struct mrsas_softc *sc, u_int32_t MSIxIndex);
113 int mrsas_reset_targets(struct mrsas_softc *sc);
115 mrsas_issue_blocked_cmd(struct mrsas_softc *sc,
118 mrsas_alloc_tmp_dcmd(struct mrsas_softc *sc, struct mrsas_tmp_dcmd *tcmd,
121 void mrsas_wakeup(struct mrsas_softc *sc, struct mrsas_mfi_cmd *cmd);
122 void mrsas_complete_aen(struct mrsas_softc *sc, struct mrsas_mfi_cmd *cmd);
123 void mrsas_complete_abort(struct mrsas_softc *sc, struct mrsas_mfi_cmd *cmd);
124 void mrsas_disable_intr(struct mrsas_softc *sc);
125 void mrsas_enable_intr(struct mrsas_softc *sc);
126 void mrsas_free_ioc_cmd(struct mrsas_softc *sc);
127 void mrsas_free_mem(struct mrsas_softc *sc);
130 void mrsas_teardown_intr(struct mrsas_softc *sc);
132 void mrsas_kill_hba(struct mrsas_softc *sc);
133 void mrsas_aen_handler(struct mrsas_softc *sc);
135 mrsas_write_reg(struct mrsas_softc *sc, int offset,
138 mrsas_fire_cmd(struct mrsas_softc *sc, u_int32_t req_desc_lo,
140 void mrsas_free_ctlr_info_cmd(struct mrsas_softc *sc);
142 mrsas_complete_mptmfi_passthru(struct mrsas_softc *sc,
144 struct mrsas_mfi_cmd *mrsas_get_mfi_cmd(struct mrsas_softc *sc);
147 (struct mrsas_softc *sc, struct mrsas_mfi_cmd *cmd);
149 extern int mrsas_cam_attach(struct mrsas_softc *sc);
150 extern void mrsas_cam_detach(struct mrsas_softc *sc);
151 extern void mrsas_cmd_done(struct mrsas_softc *sc, struct mrsas_mpt_cmd *cmd);
152 extern void mrsas_free_frame(struct mrsas_softc *sc, struct mrsas_mfi_cmd *cmd);
153 extern int mrsas_alloc_mfi_cmds(struct mrsas_softc *sc);
154 extern struct mrsas_mpt_cmd *mrsas_get_mpt_cmd(struct mrsas_softc *sc);
155 extern int mrsas_passthru(struct mrsas_softc *sc, void *arg, u_long ioctlCmd);
156 extern uint8_t MR_ValidateMapInfo(struct mrsas_softc *sc);
159 extern void mrsas_xpt_freeze(struct mrsas_softc *sc);
160 extern void mrsas_xpt_release(struct mrsas_softc *sc);
162 mrsas_get_request_desc(struct mrsas_softc *sc,
164 extern int mrsas_bus_scan_sim(struct mrsas_softc *sc, struct cam_sim *sim);
165 static int mrsas_alloc_evt_log_info_cmd(struct mrsas_softc *sc);
166 static void mrsas_free_evt_log_info_cmd(struct mrsas_softc *sc);
173 mrsas_write_64bit_req_desc(struct mrsas_softc *sc, u_int32_t req_desc_lo,
246 mrsas_read_reg_with_retries(struct mrsas_softc *sc, int offset) in mrsas_read_reg_with_retries() argument
250 if (sc->is_aero) { in mrsas_read_reg_with_retries()
252 ret_val = mrsas_read_reg(sc, offset); in mrsas_read_reg_with_retries()
256 ret_val = mrsas_read_reg(sc, offset); in mrsas_read_reg_with_retries()
266 mrsas_write_reg(struct mrsas_softc *sc, int offset, in mrsas_write_reg() argument
269 bus_space_tag_t bus_tag = sc->bus_tag; in mrsas_write_reg()
270 bus_space_handle_t bus_handle = sc->bus_handle; in mrsas_write_reg()
276 mrsas_read_reg(struct mrsas_softc *sc, int offset) in mrsas_read_reg() argument
278 bus_space_tag_t bus_tag = sc->bus_tag; in mrsas_read_reg()
279 bus_space_handle_t bus_handle = sc->bus_handle; in mrsas_read_reg()
289 mrsas_disable_intr(struct mrsas_softc *sc) in mrsas_disable_intr() argument
293 sc->mask_interrupts = 1; in mrsas_disable_intr()
294 mrsas_write_reg(sc, offsetof(mrsas_reg_set, outbound_intr_mask), mask); in mrsas_disable_intr()
296 (void)mrsas_read_reg(sc, offsetof(mrsas_reg_set, outbound_intr_mask)); in mrsas_disable_intr()
300 mrsas_enable_intr(struct mrsas_softc *sc) in mrsas_enable_intr() argument
304 sc->mask_interrupts = 0; in mrsas_enable_intr()
305 mrsas_write_reg(sc, offsetof(mrsas_reg_set, outbound_intr_status), ~0); in mrsas_enable_intr()
306 (void)mrsas_read_reg(sc, offsetof(mrsas_reg_set, outbound_intr_status)); in mrsas_enable_intr()
308 mrsas_write_reg(sc, offsetof(mrsas_reg_set, outbound_intr_mask), ~mask); in mrsas_enable_intr()
309 (void)mrsas_read_reg(sc, offsetof(mrsas_reg_set, outbound_intr_mask)); in mrsas_enable_intr()
313 mrsas_clear_intr(struct mrsas_softc *sc) in mrsas_clear_intr() argument
318 status = mrsas_read_reg_with_retries(sc, offsetof(mrsas_reg_set, outbound_intr_status)); in mrsas_clear_intr()
375 mrsas_setup_sysctl(struct mrsas_softc *sc) in mrsas_setup_sysctl() argument
386 device_get_unit(sc->mrsas_dev)); in mrsas_setup_sysctl()
387 snprintf(tmpstr2, sizeof(tmpstr2), "%d", device_get_unit(sc->mrsas_dev)); in mrsas_setup_sysctl()
389 sysctl_ctx = device_get_sysctl_ctx(sc->mrsas_dev); in mrsas_setup_sysctl()
391 sysctl_tree = device_get_sysctl_tree(sc->mrsas_dev); in mrsas_setup_sysctl()
394 sysctl_ctx_init(&sc->sysctl_ctx); in mrsas_setup_sysctl()
395 sc->sysctl_tree = SYSCTL_ADD_NODE(&sc->sysctl_ctx, in mrsas_setup_sysctl()
398 if (sc->sysctl_tree == NULL) in mrsas_setup_sysctl()
400 sysctl_ctx = &sc->sysctl_ctx; in mrsas_setup_sysctl()
401 sysctl_tree = sc->sysctl_tree; in mrsas_setup_sysctl()
404 OID_AUTO, "disable_ocr", CTLFLAG_RW, &sc->disableOnlineCtrlReset, 0, in mrsas_setup_sysctl()
413 &sc->reset_count, 0, "number of ocr from start of the day"); in mrsas_setup_sysctl()
417 &sc->fw_outstanding.val_rdonly, 0, "FW outstanding commands"); in mrsas_setup_sysctl()
421 &sc->io_cmds_highwater, 0, "Max FW outstanding commands"); in mrsas_setup_sysctl()
424 OID_AUTO, "mrsas_debug", CTLFLAG_RW, &sc->mrsas_debug, 0, in mrsas_setup_sysctl()
428 OID_AUTO, "mrsas_io_timeout", CTLFLAG_RW, &sc->mrsas_io_timeout, in mrsas_setup_sysctl()
433 &sc->mrsas_fw_fault_check_delay, in mrsas_setup_sysctl()
438 &sc->reset_in_progress, 0, "ocr in progress status"); in mrsas_setup_sysctl()
442 &sc->block_sync_cache, 0, in mrsas_setup_sysctl()
446 &sc->drv_stream_detection, 0, in mrsas_setup_sysctl()
450 &sc->prp_count.val_rdonly, 0, "Number of IOs for which PRPs are built"); in mrsas_setup_sysctl()
453 &sc->sge_holes.val_rdonly, 0, "Number of IOs with holes in SGEs"); in mrsas_setup_sysctl()
463 mrsas_get_tunables(struct mrsas_softc *sc) in mrsas_get_tunables() argument
468 sc->mrsas_debug = in mrsas_get_tunables()
470 sc->mrsas_io_timeout = MRSAS_IO_TIMEOUT; in mrsas_get_tunables()
471 sc->mrsas_fw_fault_check_delay = 1; in mrsas_get_tunables()
472 sc->reset_count = 0; in mrsas_get_tunables()
473 sc->reset_in_progress = 0; in mrsas_get_tunables()
474 sc->block_sync_cache = 0; in mrsas_get_tunables()
475 sc->drv_stream_detection = 1; in mrsas_get_tunables()
480 TUNABLE_INT_FETCH("hw.mrsas.debug_level", &sc->mrsas_debug); in mrsas_get_tunables()
485 TUNABLE_INT_FETCH("hw.mrsas.lb_pending_cmds", &sc->lb_pending_cmds); in mrsas_get_tunables()
489 device_get_unit(sc->mrsas_dev)); in mrsas_get_tunables()
490 TUNABLE_INT_FETCH(tmpstr, &sc->mrsas_debug); in mrsas_get_tunables()
501 mrsas_alloc_evt_log_info_cmd(struct mrsas_softc *sc) in mrsas_alloc_evt_log_info_cmd() argument
507 if (bus_dma_tag_create(sc->mrsas_parent_tag, in mrsas_alloc_evt_log_info_cmd()
517 &sc->el_info_tag)) { in mrsas_alloc_evt_log_info_cmd()
518 device_printf(sc->mrsas_dev, "Cannot allocate event log info tag\n"); in mrsas_alloc_evt_log_info_cmd()
521 if (bus_dmamem_alloc(sc->el_info_tag, (void **)&sc->el_info_mem, in mrsas_alloc_evt_log_info_cmd()
522 BUS_DMA_NOWAIT, &sc->el_info_dmamap)) { in mrsas_alloc_evt_log_info_cmd()
523 device_printf(sc->mrsas_dev, "Cannot allocate event log info cmd mem\n"); in mrsas_alloc_evt_log_info_cmd()
526 if (bus_dmamap_load(sc->el_info_tag, sc->el_info_dmamap, in mrsas_alloc_evt_log_info_cmd()
527 sc->el_info_mem, el_info_size, mrsas_addr_cb, in mrsas_alloc_evt_log_info_cmd()
528 &sc->el_info_phys_addr, BUS_DMA_NOWAIT)) { in mrsas_alloc_evt_log_info_cmd()
529 device_printf(sc->mrsas_dev, "Cannot load event log info cmd mem\n"); in mrsas_alloc_evt_log_info_cmd()
532 memset(sc->el_info_mem, 0, el_info_size); in mrsas_alloc_evt_log_info_cmd()
543 mrsas_free_evt_log_info_cmd(struct mrsas_softc *sc) in mrsas_free_evt_log_info_cmd() argument
545 if (sc->el_info_phys_addr) in mrsas_free_evt_log_info_cmd()
546 bus_dmamap_unload(sc->el_info_tag, sc->el_info_dmamap); in mrsas_free_evt_log_info_cmd()
547 if (sc->el_info_mem != NULL) in mrsas_free_evt_log_info_cmd()
548 bus_dmamem_free(sc->el_info_tag, sc->el_info_mem, sc->el_info_dmamap); in mrsas_free_evt_log_info_cmd()
549 if (sc->el_info_tag != NULL) in mrsas_free_evt_log_info_cmd()
550 bus_dma_tag_destroy(sc->el_info_tag); in mrsas_free_evt_log_info_cmd()
564 mrsas_get_seq_num(struct mrsas_softc *sc, in mrsas_get_seq_num() argument
571 cmd = mrsas_get_mfi_cmd(sc); in mrsas_get_seq_num()
574 device_printf(sc->mrsas_dev, "Failed to get a free cmd\n"); in mrsas_get_seq_num()
579 if (mrsas_alloc_evt_log_info_cmd(sc) != SUCCESS) { in mrsas_get_seq_num()
580 device_printf(sc->mrsas_dev, "Cannot allocate evt log info cmd\n"); in mrsas_get_seq_num()
594 dcmd->sgl.sge32[0].phys_addr = htole32(sc->el_info_phys_addr & 0xFFFFFFFF); in mrsas_get_seq_num()
597 retcode = mrsas_issue_blocked_cmd(sc, cmd); in mrsas_get_seq_num()
605 memcpy(eli, sc->el_info_mem, sizeof(struct mrsas_evt_log_info)); in mrsas_get_seq_num()
606 mrsas_free_evt_log_info_cmd(sc); in mrsas_get_seq_num()
610 sc->do_timedout_reset = MFI_DCMD_TIMEOUT_OCR; in mrsas_get_seq_num()
628 mrsas_register_aen(struct mrsas_softc *sc, u_int32_t seq_num, in mrsas_register_aen() argument
650 if (sc->aen_cmd) { in mrsas_register_aen()
651 prev_aen.word = le32toh(sc->aen_cmd->frame->dcmd.mbox.w[1]); in mrsas_register_aen()
675 sc->aen_cmd->abort_aen = 1; in mrsas_register_aen()
676 ret_val = mrsas_issue_blocked_abort_cmd(sc, in mrsas_register_aen()
677 sc->aen_cmd); in mrsas_register_aen()
683 sc->aen_cmd = NULL; in mrsas_register_aen()
686 cmd = mrsas_get_mfi_cmd(sc); in mrsas_register_aen()
692 memset(sc->evt_detail_mem, 0, sizeof(struct mrsas_evt_detail)); in mrsas_register_aen()
708 sc->last_seq_num = seq_num; in mrsas_register_aen()
710 dcmd->sgl.sge32[0].phys_addr = htole32((u_int32_t)sc->evt_detail_phys_addr & 0xFFFFFFFF); in mrsas_register_aen()
713 if (sc->aen_cmd != NULL) { in mrsas_register_aen()
722 sc->aen_cmd = cmd; in mrsas_register_aen()
727 if (mrsas_issue_dcmd(sc, cmd)) { in mrsas_register_aen()
728 device_printf(sc->mrsas_dev, "Cannot issue AEN DCMD command.\n"); in mrsas_register_aen()
739 mrsas_start_aen(struct mrsas_softc *sc) in mrsas_start_aen() argument
748 if (mrsas_get_seq_num(sc, &eli)) in mrsas_start_aen()
756 return mrsas_register_aen(sc, eli.newest_seq_num + 1, in mrsas_start_aen()
766 mrsas_setup_msix(struct mrsas_softc *sc) in mrsas_setup_msix() argument
770 for (i = 0; i < sc->msix_vectors; i++) { in mrsas_setup_msix()
771 sc->irq_context[i].sc = sc; in mrsas_setup_msix()
772 sc->irq_context[i].MSIxIndex = i; in mrsas_setup_msix()
773 sc->irq_id[i] = i + 1; in mrsas_setup_msix()
774 sc->mrsas_irq[i] = bus_alloc_resource_any in mrsas_setup_msix()
775 (sc->mrsas_dev, SYS_RES_IRQ, &sc->irq_id[i] in mrsas_setup_msix()
777 if (sc->mrsas_irq[i] == NULL) { in mrsas_setup_msix()
778 device_printf(sc->mrsas_dev, "Can't allocate MSI-x\n"); in mrsas_setup_msix()
781 if (bus_setup_intr(sc->mrsas_dev, in mrsas_setup_msix()
782 sc->mrsas_irq[i], in mrsas_setup_msix()
784 NULL, mrsas_isr, &sc->irq_context[i], in mrsas_setup_msix()
785 &sc->intr_handle[i])) { in mrsas_setup_msix()
786 device_printf(sc->mrsas_dev, in mrsas_setup_msix()
794 mrsas_teardown_intr(sc); in mrsas_setup_msix()
803 mrsas_allocate_msix(struct mrsas_softc *sc) in mrsas_allocate_msix() argument
805 if (pci_alloc_msix(sc->mrsas_dev, &sc->msix_vectors) == 0) { in mrsas_allocate_msix()
806 device_printf(sc->mrsas_dev, "Using MSI-X with %d number" in mrsas_allocate_msix()
807 " of vectors\n", sc->msix_vectors); in mrsas_allocate_msix()
809 device_printf(sc->mrsas_dev, "MSI-x setup failed\n"); in mrsas_allocate_msix()
815 mrsas_teardown_intr(sc); in mrsas_allocate_msix()
830 struct mrsas_softc *sc = device_get_softc(dev); in mrsas_attach() local
833 memset(sc, 0, sizeof(struct mrsas_softc)); in mrsas_attach()
836 sc->mrsas_dev = dev; in mrsas_attach()
837 sc->device_id = pci_get_device(dev); in mrsas_attach()
839 switch (sc->device_id) { in mrsas_attach()
846 sc->mrsas_gen3_ctrl = 1; in mrsas_attach()
854 sc->is_ventura = true; in mrsas_attach()
861 sc->is_aero = true; in mrsas_attach()
871 mrsas_get_tunables(sc); in mrsas_attach()
882 if (sc->is_ventura || sc->is_aero) in mrsas_attach()
883 sc->reg_res_id = PCIR_BAR(0); /* BAR0 offset */ in mrsas_attach()
885 sc->reg_res_id = PCIR_BAR(1); /* BAR1 offset */ in mrsas_attach()
887 if ((sc->reg_res = bus_alloc_resource_any(dev, SYS_RES_MEMORY, in mrsas_attach()
888 &(sc->reg_res_id), RF_ACTIVE)) in mrsas_attach()
893 sc->bus_tag = rman_get_bustag(sc->reg_res); in mrsas_attach()
894 sc->bus_handle = rman_get_bushandle(sc->reg_res); in mrsas_attach()
897 mtx_init(&sc->sim_lock, "mrsas_sim_lock", NULL, MTX_DEF); in mrsas_attach()
898 mtx_init(&sc->pci_lock, "mrsas_pci_lock", NULL, MTX_DEF); in mrsas_attach()
899 mtx_init(&sc->io_lock, "mrsas_io_lock", NULL, MTX_DEF); in mrsas_attach()
900 mtx_init(&sc->aen_lock, "mrsas_aen_lock", NULL, MTX_DEF); in mrsas_attach()
901 mtx_init(&sc->ioctl_lock, "mrsas_ioctl_lock", NULL, MTX_SPIN); in mrsas_attach()
902 mtx_init(&sc->mpt_cmd_pool_lock, "mrsas_mpt_cmd_pool_lock", NULL, MTX_DEF); in mrsas_attach()
903 mtx_init(&sc->mfi_cmd_pool_lock, "mrsas_mfi_cmd_pool_lock", NULL, MTX_DEF); in mrsas_attach()
904 mtx_init(&sc->raidmap_lock, "mrsas_raidmap_lock", NULL, MTX_DEF); in mrsas_attach()
905 mtx_init(&sc->stream_lock, "mrsas_stream_lock", NULL, MTX_DEF); in mrsas_attach()
908 TAILQ_INIT(&sc->mrsas_mpt_cmd_list_head); in mrsas_attach()
909 TAILQ_INIT(&sc->mrsas_mfi_cmd_list_head); in mrsas_attach()
911 mrsas_atomic_set(&sc->fw_outstanding, 0); in mrsas_attach()
912 mrsas_atomic_set(&sc->target_reset_outstanding, 0); in mrsas_attach()
913 mrsas_atomic_set(&sc->prp_count, 0); in mrsas_attach()
914 mrsas_atomic_set(&sc->sge_holes, 0); in mrsas_attach()
916 sc->io_cmds_highwater = 0; in mrsas_attach()
918 sc->adprecovery = MRSAS_HBA_OPERATIONAL; in mrsas_attach()
919 sc->UnevenSpanSupport = 0; in mrsas_attach()
921 sc->msix_enable = 0; in mrsas_attach()
924 if (mrsas_init_fw(sc) != SUCCESS) { in mrsas_attach()
928 if ((mrsas_cam_attach(sc) != SUCCESS)) { in mrsas_attach()
932 if (mrsas_setup_irq(sc) != SUCCESS) { in mrsas_attach()
935 error = mrsas_kproc_create(mrsas_ocr_thread, sc, in mrsas_attach()
936 &sc->ocr_thread, 0, 0, "mrsas_ocr%d", in mrsas_attach()
937 device_get_unit(sc->mrsas_dev)); in mrsas_attach()
939 device_printf(sc->mrsas_dev, "Error %d starting OCR thread\n", error); in mrsas_attach()
946 sc->mrsas_ich.ich_func = mrsas_ich_startup; in mrsas_attach()
947 sc->mrsas_ich.ich_arg = sc; in mrsas_attach()
948 if (config_intrhook_establish(&sc->mrsas_ich) != 0) { in mrsas_attach()
949 device_printf(sc->mrsas_dev, "Config hook is already established\n"); in mrsas_attach()
951 mrsas_setup_sysctl(sc); in mrsas_attach()
955 if (sc->ocr_thread_active) in mrsas_attach()
956 wakeup(&sc->ocr_chan); in mrsas_attach()
958 mrsas_teardown_intr(sc); in mrsas_attach()
960 mrsas_cam_detach(sc); in mrsas_attach()
963 if (sc->msix_enable == 1) in mrsas_attach()
964 pci_release_msi(sc->mrsas_dev); in mrsas_attach()
965 mrsas_free_mem(sc); in mrsas_attach()
966 mtx_destroy(&sc->sim_lock); in mrsas_attach()
967 mtx_destroy(&sc->aen_lock); in mrsas_attach()
968 mtx_destroy(&sc->pci_lock); in mrsas_attach()
969 mtx_destroy(&sc->io_lock); in mrsas_attach()
970 mtx_destroy(&sc->ioctl_lock); in mrsas_attach()
971 mtx_destroy(&sc->mpt_cmd_pool_lock); in mrsas_attach()
972 mtx_destroy(&sc->mfi_cmd_pool_lock); in mrsas_attach()
973 mtx_destroy(&sc->raidmap_lock); in mrsas_attach()
974 mtx_destroy(&sc->stream_lock); in mrsas_attach()
976 if (sc->reg_res) { in mrsas_attach()
977 bus_release_resource(sc->mrsas_dev, SYS_RES_MEMORY, in mrsas_attach()
978 sc->reg_res_id, sc->reg_res); in mrsas_attach()
990 struct mrsas_softc *sc = (struct mrsas_softc *)arg; in mrsas_ich_startup() local
995 sema_init(&sc->ioctl_count_sema, MRSAS_MAX_IOCTL_CMDS, in mrsas_ich_startup()
999 sc->mrsas_cdev = make_dev(&mrsas_cdevsw, device_get_unit(sc->mrsas_dev), UID_ROOT, in mrsas_ich_startup()
1001 device_get_unit(sc->mrsas_dev)); in mrsas_ich_startup()
1003 if (device_get_unit(sc->mrsas_dev) == 0) { in mrsas_ich_startup()
1005 &sc->mrsas_linux_emulator_cdev, sc->mrsas_cdev, in mrsas_ich_startup()
1008 if (sc->mrsas_cdev) in mrsas_ich_startup()
1009 sc->mrsas_cdev->si_drv1 = sc; in mrsas_ich_startup()
1015 if (device_get_unit(sc->mrsas_dev) == 0) in mrsas_ich_startup()
1019 mrsas_mgmt_info.sc_ptr[mrsas_mgmt_info.max_index] = sc; in mrsas_ich_startup()
1023 mrsas_enable_intr(sc); in mrsas_ich_startup()
1027 if ((sc->target_list[i].target_id != 0xffff) && in mrsas_ich_startup()
1028 sc->pd_info_mem) in mrsas_ich_startup()
1029 mrsas_get_pd_info(sc, sc->target_list[i].target_id); in mrsas_ich_startup()
1033 if (mrsas_start_aen(sc)) { in mrsas_ich_startup()
1034 device_printf(sc->mrsas_dev, "Error: AEN registration FAILED !!! " in mrsas_ich_startup()
1040 if (sc->mrsas_ich.ich_arg != NULL) { in mrsas_ich_startup()
1041 device_printf(sc->mrsas_dev, "Disestablish mrsas intr hook\n"); in mrsas_ich_startup()
1042 config_intrhook_disestablish(&sc->mrsas_ich); in mrsas_ich_startup()
1043 sc->mrsas_ich.ich_arg = NULL; in mrsas_ich_startup()
1058 struct mrsas_softc *sc; in mrsas_detach() local
1061 sc = device_get_softc(dev); in mrsas_detach()
1062 sc->remove_in_progress = 1; in mrsas_detach()
1065 if ((device_get_unit(dev) == 0) && sc->mrsas_linux_emulator_cdev) in mrsas_detach()
1066 destroy_dev(sc->mrsas_linux_emulator_cdev); in mrsas_detach()
1067 destroy_dev(sc->mrsas_cdev); in mrsas_detach()
1074 if (mrsas_mgmt_info.sc_ptr[i] == sc) { in mrsas_detach()
1081 if (sc->ocr_thread_active) in mrsas_detach()
1082 wakeup(&sc->ocr_chan); in mrsas_detach()
1083 while (sc->reset_in_progress) { in mrsas_detach()
1086 mrsas_dprint(sc, MRSAS_INFO, in mrsas_detach()
1092 while (sc->ocr_thread_active) { in mrsas_detach()
1095 mrsas_dprint(sc, MRSAS_INFO, in mrsas_detach()
1098 sc->ocr_thread_active); in mrsas_detach()
1102 mrsas_flush_cache(sc); in mrsas_detach()
1103 mrsas_shutdown_ctlr(sc, MR_DCMD_CTRL_SHUTDOWN); in mrsas_detach()
1104 mrsas_disable_intr(sc); in mrsas_detach()
1106 if ((sc->is_ventura || sc->is_aero) && sc->streamDetectByLD) { in mrsas_detach()
1108 free(sc->streamDetectByLD[i], M_MRSAS); in mrsas_detach()
1109 free(sc->streamDetectByLD, M_MRSAS); in mrsas_detach()
1110 sc->streamDetectByLD = NULL; in mrsas_detach()
1113 mrsas_cam_detach(sc); in mrsas_detach()
1114 mrsas_teardown_intr(sc); in mrsas_detach()
1115 mrsas_free_mem(sc); in mrsas_detach()
1116 mtx_destroy(&sc->sim_lock); in mrsas_detach()
1117 mtx_destroy(&sc->aen_lock); in mrsas_detach()
1118 mtx_destroy(&sc->pci_lock); in mrsas_detach()
1119 mtx_destroy(&sc->io_lock); in mrsas_detach()
1120 mtx_destroy(&sc->ioctl_lock); in mrsas_detach()
1121 mtx_destroy(&sc->mpt_cmd_pool_lock); in mrsas_detach()
1122 mtx_destroy(&sc->mfi_cmd_pool_lock); in mrsas_detach()
1123 mtx_destroy(&sc->raidmap_lock); in mrsas_detach()
1124 mtx_destroy(&sc->stream_lock); in mrsas_detach()
1127 while (sema_value(&sc->ioctl_count_sema) != MRSAS_MAX_IOCTL_CMDS) in mrsas_detach()
1131 sema_destroy(&sc->ioctl_count_sema); in mrsas_detach()
1133 if (sc->reg_res) { in mrsas_detach()
1134 bus_release_resource(sc->mrsas_dev, in mrsas_detach()
1135 SYS_RES_MEMORY, sc->reg_res_id, sc->reg_res); in mrsas_detach()
1137 if (sc->sysctl_tree != NULL) in mrsas_detach()
1138 sysctl_ctx_free(&sc->sysctl_ctx); in mrsas_detach()
1146 struct mrsas_softc *sc; in mrsas_shutdown() local
1149 sc = device_get_softc(dev); in mrsas_shutdown()
1150 sc->remove_in_progress = 1; in mrsas_shutdown()
1152 if (sc->ocr_thread_active) in mrsas_shutdown()
1153 wakeup(&sc->ocr_chan); in mrsas_shutdown()
1155 while (sc->reset_in_progress && i < 15) { in mrsas_shutdown()
1158 mrsas_dprint(sc, MRSAS_INFO, in mrsas_shutdown()
1164 if (sc->reset_in_progress) { in mrsas_shutdown()
1165 mrsas_dprint(sc, MRSAS_INFO, in mrsas_shutdown()
1171 mrsas_flush_cache(sc); in mrsas_shutdown()
1172 mrsas_shutdown_ctlr(sc, MR_DCMD_CTRL_SHUTDOWN); in mrsas_shutdown()
1173 mrsas_disable_intr(sc); in mrsas_shutdown()
1185 mrsas_free_mem(struct mrsas_softc *sc) in mrsas_free_mem() argument
1196 if (sc->raidmap_phys_addr[i]) in mrsas_free_mem()
1197 bus_dmamap_unload(sc->raidmap_tag[i], sc->raidmap_dmamap[i]); in mrsas_free_mem()
1198 if (sc->raidmap_mem[i] != NULL) in mrsas_free_mem()
1199 bus_dmamem_free(sc->raidmap_tag[i], sc->raidmap_mem[i], sc->raidmap_dmamap[i]); in mrsas_free_mem()
1200 if (sc->raidmap_tag[i] != NULL) in mrsas_free_mem()
1201 bus_dma_tag_destroy(sc->raidmap_tag[i]); in mrsas_free_mem()
1203 if (sc->ld_drv_map[i] != NULL) in mrsas_free_mem()
1204 free(sc->ld_drv_map[i], M_MRSAS); in mrsas_free_mem()
1207 if (sc->jbodmap_phys_addr[i]) in mrsas_free_mem()
1208 bus_dmamap_unload(sc->jbodmap_tag[i], sc->jbodmap_dmamap[i]); in mrsas_free_mem()
1209 if (sc->jbodmap_mem[i] != NULL) in mrsas_free_mem()
1210 bus_dmamem_free(sc->jbodmap_tag[i], sc->jbodmap_mem[i], sc->jbodmap_dmamap[i]); in mrsas_free_mem()
1211 if (sc->jbodmap_tag[i] != NULL) in mrsas_free_mem()
1212 bus_dma_tag_destroy(sc->jbodmap_tag[i]); in mrsas_free_mem()
1217 if (sc->verbuf_phys_addr) in mrsas_free_mem()
1218 bus_dmamap_unload(sc->verbuf_tag, sc->verbuf_dmamap); in mrsas_free_mem()
1219 if (sc->verbuf_mem != NULL) in mrsas_free_mem()
1220 bus_dmamem_free(sc->verbuf_tag, sc->verbuf_mem, sc->verbuf_dmamap); in mrsas_free_mem()
1221 if (sc->verbuf_tag != NULL) in mrsas_free_mem()
1222 bus_dma_tag_destroy(sc->verbuf_tag); in mrsas_free_mem()
1227 if (sc->sense_phys_addr) in mrsas_free_mem()
1228 bus_dmamap_unload(sc->sense_tag, sc->sense_dmamap); in mrsas_free_mem()
1229 if (sc->sense_mem != NULL) in mrsas_free_mem()
1230 bus_dmamem_free(sc->sense_tag, sc->sense_mem, sc->sense_dmamap); in mrsas_free_mem()
1231 if (sc->sense_tag != NULL) in mrsas_free_mem()
1232 bus_dma_tag_destroy(sc->sense_tag); in mrsas_free_mem()
1237 if (sc->chain_frame_phys_addr) in mrsas_free_mem()
1238 bus_dmamap_unload(sc->chain_frame_tag, sc->chain_frame_dmamap); in mrsas_free_mem()
1239 if (sc->chain_frame_mem != NULL) in mrsas_free_mem()
1240 bus_dmamem_free(sc->chain_frame_tag, sc->chain_frame_mem, sc->chain_frame_dmamap); in mrsas_free_mem()
1241 if (sc->chain_frame_tag != NULL) in mrsas_free_mem()
1242 bus_dma_tag_destroy(sc->chain_frame_tag); in mrsas_free_mem()
1247 if (sc->io_request_phys_addr) in mrsas_free_mem()
1248 bus_dmamap_unload(sc->io_request_tag, sc->io_request_dmamap); in mrsas_free_mem()
1249 if (sc->io_request_mem != NULL) in mrsas_free_mem()
1250 bus_dmamem_free(sc->io_request_tag, sc->io_request_mem, sc->io_request_dmamap); in mrsas_free_mem()
1251 if (sc->io_request_tag != NULL) in mrsas_free_mem()
1252 bus_dma_tag_destroy(sc->io_request_tag); in mrsas_free_mem()
1257 if (sc->reply_desc_phys_addr) in mrsas_free_mem()
1258 bus_dmamap_unload(sc->reply_desc_tag, sc->reply_desc_dmamap); in mrsas_free_mem()
1259 if (sc->reply_desc_mem != NULL) in mrsas_free_mem()
1260 bus_dmamem_free(sc->reply_desc_tag, sc->reply_desc_mem, sc->reply_desc_dmamap); in mrsas_free_mem()
1261 if (sc->reply_desc_tag != NULL) in mrsas_free_mem()
1262 bus_dma_tag_destroy(sc->reply_desc_tag); in mrsas_free_mem()
1267 if (sc->evt_detail_phys_addr) in mrsas_free_mem()
1268 bus_dmamap_unload(sc->evt_detail_tag, sc->evt_detail_dmamap); in mrsas_free_mem()
1269 if (sc->evt_detail_mem != NULL) in mrsas_free_mem()
1270 bus_dmamem_free(sc->evt_detail_tag, sc->evt_detail_mem, sc->evt_detail_dmamap); in mrsas_free_mem()
1271 if (sc->evt_detail_tag != NULL) in mrsas_free_mem()
1272 bus_dma_tag_destroy(sc->evt_detail_tag); in mrsas_free_mem()
1277 if (sc->pd_info_phys_addr) in mrsas_free_mem()
1278 bus_dmamap_unload(sc->pd_info_tag, sc->pd_info_dmamap); in mrsas_free_mem()
1279 if (sc->pd_info_mem != NULL) in mrsas_free_mem()
1280 bus_dmamem_free(sc->pd_info_tag, sc->pd_info_mem, sc->pd_info_dmamap); in mrsas_free_mem()
1281 if (sc->pd_info_tag != NULL) in mrsas_free_mem()
1282 bus_dma_tag_destroy(sc->pd_info_tag); in mrsas_free_mem()
1287 if (sc->mfi_cmd_list) { in mrsas_free_mem()
1289 mfi_cmd = sc->mfi_cmd_list[i]; in mrsas_free_mem()
1290 mrsas_free_frame(sc, mfi_cmd); in mrsas_free_mem()
1293 if (sc->mficmd_frame_tag != NULL) in mrsas_free_mem()
1294 bus_dma_tag_destroy(sc->mficmd_frame_tag); in mrsas_free_mem()
1299 max_fw_cmds = sc->max_fw_cmds; in mrsas_free_mem()
1300 if (sc->mpt_cmd_list) { in mrsas_free_mem()
1302 mpt_cmd = sc->mpt_cmd_list[i]; in mrsas_free_mem()
1303 bus_dmamap_destroy(sc->data_tag, mpt_cmd->data_dmamap); in mrsas_free_mem()
1304 free(sc->mpt_cmd_list[i], M_MRSAS); in mrsas_free_mem()
1306 free(sc->mpt_cmd_list, M_MRSAS); in mrsas_free_mem()
1307 sc->mpt_cmd_list = NULL; in mrsas_free_mem()
1313 if (sc->mfi_cmd_list) { in mrsas_free_mem()
1315 free(sc->mfi_cmd_list[i], M_MRSAS); in mrsas_free_mem()
1317 free(sc->mfi_cmd_list, M_MRSAS); in mrsas_free_mem()
1318 sc->mfi_cmd_list = NULL; in mrsas_free_mem()
1323 free(sc->req_desc, M_MRSAS); in mrsas_free_mem()
1324 sc->req_desc = NULL; in mrsas_free_mem()
1329 if (sc->mrsas_parent_tag != NULL) in mrsas_free_mem()
1330 bus_dma_tag_destroy(sc->mrsas_parent_tag); in mrsas_free_mem()
1335 if (sc->ctrl_info != NULL) in mrsas_free_mem()
1336 free(sc->ctrl_info, M_MRSAS); in mrsas_free_mem()
1347 mrsas_teardown_intr(struct mrsas_softc *sc) in mrsas_teardown_intr() argument
1351 if (!sc->msix_enable) { in mrsas_teardown_intr()
1352 if (sc->intr_handle[0]) in mrsas_teardown_intr()
1353 bus_teardown_intr(sc->mrsas_dev, sc->mrsas_irq[0], sc->intr_handle[0]); in mrsas_teardown_intr()
1354 if (sc->mrsas_irq[0] != NULL) in mrsas_teardown_intr()
1355 bus_release_resource(sc->mrsas_dev, SYS_RES_IRQ, in mrsas_teardown_intr()
1356 sc->irq_id[0], sc->mrsas_irq[0]); in mrsas_teardown_intr()
1357 sc->intr_handle[0] = NULL; in mrsas_teardown_intr()
1359 for (i = 0; i < sc->msix_vectors; i++) { in mrsas_teardown_intr()
1360 if (sc->intr_handle[i]) in mrsas_teardown_intr()
1361 bus_teardown_intr(sc->mrsas_dev, sc->mrsas_irq[i], in mrsas_teardown_intr()
1362 sc->intr_handle[i]); in mrsas_teardown_intr()
1364 if (sc->mrsas_irq[i] != NULL) in mrsas_teardown_intr()
1365 bus_release_resource(sc->mrsas_dev, SYS_RES_IRQ, in mrsas_teardown_intr()
1366 sc->irq_id[i], sc->mrsas_irq[i]); in mrsas_teardown_intr()
1368 sc->intr_handle[i] = NULL; in mrsas_teardown_intr()
1370 pci_release_msi(sc->mrsas_dev); in mrsas_teardown_intr()
1414 struct mrsas_softc *sc = NULL; in mrsas_get_softc_instance() local
1418 sc = dev->si_drv1; in mrsas_get_softc_instance()
1424 sc = mrsas_mgmt_info.sc_ptr[user_ioc->host_no]; in mrsas_get_softc_instance()
1425 if (sc == NULL) in mrsas_get_softc_instance()
1429 mrsas_dprint(sc, MRSAS_FAULT, in mrsas_get_softc_instance()
1433 return sc; in mrsas_get_softc_instance()
1446 struct mrsas_softc *sc; in mrsas_ioctl() local
1452 sc = (struct mrsas_softc *)(dev->si_drv1); in mrsas_ioctl()
1455 sc = mrsas_get_softc_instance(dev, cmd, arg); in mrsas_ioctl()
1458 if (!sc) in mrsas_ioctl()
1461 if (sc->remove_in_progress || in mrsas_ioctl()
1462 (sc->adprecovery == MRSAS_HW_CRITICAL_ERROR)) { in mrsas_ioctl()
1463 mrsas_dprint(sc, MRSAS_INFO, in mrsas_ioctl()
1468 mtx_lock_spin(&sc->ioctl_lock); in mrsas_ioctl()
1469 if (!sc->reset_in_progress) { in mrsas_ioctl()
1470 mtx_unlock_spin(&sc->ioctl_lock); in mrsas_ioctl()
1473 mtx_unlock_spin(&sc->ioctl_lock); in mrsas_ioctl()
1474 while (sc->reset_in_progress) { in mrsas_ioctl()
1477 mrsas_dprint(sc, MRSAS_INFO, in mrsas_ioctl()
1493 sema_wait(&sc->ioctl_count_sema); in mrsas_ioctl()
1495 ret = mrsas_passthru(sc, (void *)arg, cmd); in mrsas_ioctl()
1498 sema_post(&sc->ioctl_count_sema); in mrsas_ioctl()
1502 ret = mrsas_bus_scan(sc); in mrsas_ioctl()
1508 pciDrvInfo->busNumber = pci_get_bus(sc->mrsas_dev); in mrsas_ioctl()
1509 pciDrvInfo->deviceNumber = pci_get_slot(sc->mrsas_dev); in mrsas_ioctl()
1510 pciDrvInfo->functionNumber = pci_get_function(sc->mrsas_dev); in mrsas_ioctl()
1511 pciDrvInfo->domainID = pci_get_domain(sc->mrsas_dev); in mrsas_ioctl()
1512 mrsas_dprint(sc, MRSAS_INFO, "pci bus no: %d," in mrsas_ioctl()
1521 ret = mrsas_user_command(sc, (struct mfi_ioc_passthru *)arg); in mrsas_ioctl()
1525 mrsas_dprint(sc, MRSAS_TRACE, "IOCTL command 0x%lx is not handled\n", cmd); in mrsas_ioctl()
1541 struct mrsas_softc *sc; in mrsas_poll() local
1544 sc = dev->si_drv1; in mrsas_poll()
1547 if (sc->mrsas_aen_triggered) { in mrsas_poll()
1553 mtx_lock(&sc->aen_lock); in mrsas_poll()
1554 sc->mrsas_poll_waiting = 1; in mrsas_poll()
1555 selrecord(td, &sc->mrsas_select); in mrsas_poll()
1556 mtx_unlock(&sc->aen_lock); in mrsas_poll()
1571 mrsas_setup_irq(struct mrsas_softc *sc) in mrsas_setup_irq() argument
1573 if (sc->msix_enable && (mrsas_setup_msix(sc) == SUCCESS)) in mrsas_setup_irq()
1574 device_printf(sc->mrsas_dev, "MSI-x interrupts setup success\n"); in mrsas_setup_irq()
1577 device_printf(sc->mrsas_dev, "Fall back to legacy interrupt\n"); in mrsas_setup_irq()
1578 sc->irq_context[0].sc = sc; in mrsas_setup_irq()
1579 sc->irq_context[0].MSIxIndex = 0; in mrsas_setup_irq()
1580 sc->irq_id[0] = 0; in mrsas_setup_irq()
1581 sc->mrsas_irq[0] = bus_alloc_resource_any(sc->mrsas_dev, in mrsas_setup_irq()
1582 SYS_RES_IRQ, &sc->irq_id[0], RF_SHAREABLE | RF_ACTIVE); in mrsas_setup_irq()
1583 if (sc->mrsas_irq[0] == NULL) { in mrsas_setup_irq()
1584 device_printf(sc->mrsas_dev, "Cannot allocate legcay" in mrsas_setup_irq()
1588 if (bus_setup_intr(sc->mrsas_dev, sc->mrsas_irq[0], in mrsas_setup_irq()
1590 &sc->irq_context[0], &sc->intr_handle[0])) { in mrsas_setup_irq()
1591 device_printf(sc->mrsas_dev, "Cannot set up legacy" in mrsas_setup_irq()
1611 struct mrsas_softc *sc = irq_context->sc; in mrsas_isr() local
1614 if (sc->mask_interrupts) in mrsas_isr()
1617 if (!sc->msix_vectors) { in mrsas_isr()
1618 status = mrsas_clear_intr(sc); in mrsas_isr()
1623 if (mrsas_test_bit(MRSAS_FUSION_IN_RESET, &sc->reset_flags)) { in mrsas_isr()
1625 mrsas_clear_intr(sc); in mrsas_isr()
1629 if (mrsas_complete_cmd(sc, irq_context->MSIxIndex) != SUCCESS) in mrsas_isr()
1630 mrsas_clear_intr(sc); in mrsas_isr()
1647 mrsas_complete_cmd(struct mrsas_softc *sc, u_int32_t MSIxIndex) in mrsas_complete_cmd() argument
1667 if (sc->adprecovery == MRSAS_HW_CRITICAL_ERROR) in mrsas_complete_cmd()
1670 desc = sc->reply_desc_mem; in mrsas_complete_cmd()
1671 desc += ((MSIxIndex * sc->reply_alloc_sz) / sizeof(MPI2_REPLY_DESCRIPTORS_UNION)) in mrsas_complete_cmd()
1672 + sc->last_reply_idx[MSIxIndex]; in mrsas_complete_cmd()
1684 cmd_mpt = sc->mpt_cmd_list[smid - 1]; in mrsas_complete_cmd()
1698 device_printf(sc->mrsas_dev, "TM completion type 0x%X, " in mrsas_complete_cmd()
1701 wakeup_one((void *)&sc->ocr_chan); in mrsas_complete_cmd()
1705 lbinfo = &sc->load_balance_info[device_id]; in mrsas_complete_cmd()
1716 mrsas_cmd_done(sc, cmd_mpt); in mrsas_complete_cmd()
1717 mrsas_atomic_dec(&sc->fw_outstanding); in mrsas_complete_cmd()
1735 mtx_lock(&sc->sim_lock); in mrsas_complete_cmd()
1741 mtx_unlock(&sc->sim_lock); in mrsas_complete_cmd()
1743 mrsas_atomic_dec(&sc->fw_outstanding); in mrsas_complete_cmd()
1746 mrsas_cmd_done(sc, cmd_mpt); in mrsas_complete_cmd()
1747 mrsas_atomic_dec(&sc->fw_outstanding); in mrsas_complete_cmd()
1752 cmd_mfi = sc->mfi_cmd_list[cmd_mpt->sync_cmd_idx]; in mrsas_complete_cmd()
1762 mrsas_complete_mptmfi_passthru(sc, cmd_mfi, status); in mrsas_complete_cmd()
1766 sc->last_reply_idx[MSIxIndex]++; in mrsas_complete_cmd()
1767 if (sc->last_reply_idx[MSIxIndex] >= sc->reply_q_depth) in mrsas_complete_cmd()
1768 sc->last_reply_idx[MSIxIndex] = 0; in mrsas_complete_cmd()
1776 if (!sc->last_reply_idx[MSIxIndex]) { in mrsas_complete_cmd()
1777 desc = sc->reply_desc_mem; in mrsas_complete_cmd()
1778 desc += ((MSIxIndex * sc->reply_alloc_sz) / sizeof(MPI2_REPLY_DESCRIPTORS_UNION)); in mrsas_complete_cmd()
1796 if (sc->msix_enable) { in mrsas_complete_cmd()
1797 if (sc->msix_combined) in mrsas_complete_cmd()
1798 mrsas_write_reg(sc, sc->msix_reg_offset[MSIxIndex / 8], in mrsas_complete_cmd()
1800 sc->last_reply_idx[MSIxIndex]); in mrsas_complete_cmd()
1802 mrsas_write_reg(sc, sc->msix_reg_offset[0], (MSIxIndex << 24) | in mrsas_complete_cmd()
1803 sc->last_reply_idx[MSIxIndex]); in mrsas_complete_cmd()
1805 mrsas_write_reg(sc, offsetof(mrsas_reg_set, in mrsas_complete_cmd()
1806 reply_post_host_index), sc->last_reply_idx[0]); in mrsas_complete_cmd()
1817 if (sc->msix_enable) { in mrsas_complete_cmd()
1818 if (sc->msix_combined) { in mrsas_complete_cmd()
1819 mrsas_write_reg(sc, sc->msix_reg_offset[MSIxIndex / 8], in mrsas_complete_cmd()
1821 sc->last_reply_idx[MSIxIndex]); in mrsas_complete_cmd()
1823 mrsas_write_reg(sc, sc->msix_reg_offset[0], (MSIxIndex << 24) | in mrsas_complete_cmd()
1824 sc->last_reply_idx[MSIxIndex]); in mrsas_complete_cmd()
1826 mrsas_write_reg(sc, offsetof(mrsas_reg_set, in mrsas_complete_cmd()
1827 reply_post_host_index), sc->last_reply_idx[0]); in mrsas_complete_cmd()
1844 struct mrsas_softc *sc = cmd->sc; in mrsas_map_mpt_cmd_status() local
1873 device_printf(sc->mrsas_dev, "FW cmd complete status %x\n", status); in mrsas_map_mpt_cmd_status()
1889 mrsas_alloc_mem(struct mrsas_softc *sc) in mrsas_alloc_mem() argument
1898 bus_get_dma_tag(sc->mrsas_dev), /* parent */ in mrsas_alloc_mem()
1909 &sc->mrsas_parent_tag /* tag */ in mrsas_alloc_mem()
1911 device_printf(sc->mrsas_dev, "Cannot allocate parent DMA tag\n"); in mrsas_alloc_mem()
1918 if (bus_dma_tag_create(sc->mrsas_parent_tag, in mrsas_alloc_mem()
1928 &sc->verbuf_tag)) { in mrsas_alloc_mem()
1929 device_printf(sc->mrsas_dev, "Cannot allocate verbuf DMA tag\n"); in mrsas_alloc_mem()
1932 if (bus_dmamem_alloc(sc->verbuf_tag, (void **)&sc->verbuf_mem, in mrsas_alloc_mem()
1933 BUS_DMA_NOWAIT, &sc->verbuf_dmamap)) { in mrsas_alloc_mem()
1934 device_printf(sc->mrsas_dev, "Cannot allocate verbuf memory\n"); in mrsas_alloc_mem()
1937 bzero(sc->verbuf_mem, verbuf_size); in mrsas_alloc_mem()
1938 if (bus_dmamap_load(sc->verbuf_tag, sc->verbuf_dmamap, sc->verbuf_mem, in mrsas_alloc_mem()
1939 verbuf_size, mrsas_addr_cb, &sc->verbuf_phys_addr, in mrsas_alloc_mem()
1941 device_printf(sc->mrsas_dev, "Cannot load verbuf DMA map\n"); in mrsas_alloc_mem()
1947 io_req_size = sc->io_frames_alloc_sz; in mrsas_alloc_mem()
1948 if (bus_dma_tag_create(sc->mrsas_parent_tag, in mrsas_alloc_mem()
1958 &sc->io_request_tag)) { in mrsas_alloc_mem()
1959 device_printf(sc->mrsas_dev, "Cannot create IO request tag\n"); in mrsas_alloc_mem()
1962 if (bus_dmamem_alloc(sc->io_request_tag, (void **)&sc->io_request_mem, in mrsas_alloc_mem()
1963 BUS_DMA_NOWAIT, &sc->io_request_dmamap)) { in mrsas_alloc_mem()
1964 device_printf(sc->mrsas_dev, "Cannot alloc IO request memory\n"); in mrsas_alloc_mem()
1967 bzero(sc->io_request_mem, io_req_size); in mrsas_alloc_mem()
1968 if (bus_dmamap_load(sc->io_request_tag, sc->io_request_dmamap, in mrsas_alloc_mem()
1969 sc->io_request_mem, io_req_size, mrsas_addr_cb, in mrsas_alloc_mem()
1970 &sc->io_request_phys_addr, BUS_DMA_NOWAIT)) { in mrsas_alloc_mem()
1971 device_printf(sc->mrsas_dev, "Cannot load IO request memory\n"); in mrsas_alloc_mem()
1977 chain_frame_size = sc->chain_frames_alloc_sz; in mrsas_alloc_mem()
1978 if (bus_dma_tag_create(sc->mrsas_parent_tag, in mrsas_alloc_mem()
1988 &sc->chain_frame_tag)) { in mrsas_alloc_mem()
1989 device_printf(sc->mrsas_dev, "Cannot create chain frame tag\n"); in mrsas_alloc_mem()
1992 if (bus_dmamem_alloc(sc->chain_frame_tag, (void **)&sc->chain_frame_mem, in mrsas_alloc_mem()
1993 BUS_DMA_NOWAIT, &sc->chain_frame_dmamap)) { in mrsas_alloc_mem()
1994 device_printf(sc->mrsas_dev, "Cannot alloc chain frame memory\n"); in mrsas_alloc_mem()
1997 bzero(sc->chain_frame_mem, chain_frame_size); in mrsas_alloc_mem()
1998 if (bus_dmamap_load(sc->chain_frame_tag, sc->chain_frame_dmamap, in mrsas_alloc_mem()
1999 sc->chain_frame_mem, chain_frame_size, mrsas_addr_cb, in mrsas_alloc_mem()
2000 &sc->chain_frame_phys_addr, BUS_DMA_NOWAIT)) { in mrsas_alloc_mem()
2001 device_printf(sc->mrsas_dev, "Cannot load chain frame memory\n"); in mrsas_alloc_mem()
2004 count = sc->msix_vectors > 0 ? sc->msix_vectors : 1; in mrsas_alloc_mem()
2008 reply_desc_size = sc->reply_alloc_sz * count; in mrsas_alloc_mem()
2009 if (bus_dma_tag_create(sc->mrsas_parent_tag, in mrsas_alloc_mem()
2019 &sc->reply_desc_tag)) { in mrsas_alloc_mem()
2020 device_printf(sc->mrsas_dev, "Cannot create reply descriptor tag\n"); in mrsas_alloc_mem()
2023 if (bus_dmamem_alloc(sc->reply_desc_tag, (void **)&sc->reply_desc_mem, in mrsas_alloc_mem()
2024 BUS_DMA_NOWAIT, &sc->reply_desc_dmamap)) { in mrsas_alloc_mem()
2025 device_printf(sc->mrsas_dev, "Cannot alloc reply descriptor memory\n"); in mrsas_alloc_mem()
2028 if (bus_dmamap_load(sc->reply_desc_tag, sc->reply_desc_dmamap, in mrsas_alloc_mem()
2029 sc->reply_desc_mem, reply_desc_size, mrsas_addr_cb, in mrsas_alloc_mem()
2030 &sc->reply_desc_phys_addr, BUS_DMA_NOWAIT)) { in mrsas_alloc_mem()
2031 device_printf(sc->mrsas_dev, "Cannot load reply descriptor memory\n"); in mrsas_alloc_mem()
2037 sense_size = sc->max_fw_cmds * MRSAS_SENSE_LEN; in mrsas_alloc_mem()
2038 if (bus_dma_tag_create(sc->mrsas_parent_tag, in mrsas_alloc_mem()
2048 &sc->sense_tag)) { in mrsas_alloc_mem()
2049 device_printf(sc->mrsas_dev, "Cannot allocate sense buf tag\n"); in mrsas_alloc_mem()
2052 if (bus_dmamem_alloc(sc->sense_tag, (void **)&sc->sense_mem, in mrsas_alloc_mem()
2053 BUS_DMA_NOWAIT, &sc->sense_dmamap)) { in mrsas_alloc_mem()
2054 device_printf(sc->mrsas_dev, "Cannot allocate sense buf memory\n"); in mrsas_alloc_mem()
2057 if (bus_dmamap_load(sc->sense_tag, sc->sense_dmamap, in mrsas_alloc_mem()
2058 sc->sense_mem, sense_size, mrsas_addr_cb, &sc->sense_phys_addr, in mrsas_alloc_mem()
2060 device_printf(sc->mrsas_dev, "Cannot load sense buf memory\n"); in mrsas_alloc_mem()
2068 if (bus_dma_tag_create(sc->mrsas_parent_tag, in mrsas_alloc_mem()
2078 &sc->evt_detail_tag)) { in mrsas_alloc_mem()
2079 device_printf(sc->mrsas_dev, "Cannot create Event detail tag\n"); in mrsas_alloc_mem()
2082 if (bus_dmamem_alloc(sc->evt_detail_tag, (void **)&sc->evt_detail_mem, in mrsas_alloc_mem()
2083 BUS_DMA_NOWAIT, &sc->evt_detail_dmamap)) { in mrsas_alloc_mem()
2084 device_printf(sc->mrsas_dev, "Cannot alloc Event detail buffer memory\n"); in mrsas_alloc_mem()
2087 bzero(sc->evt_detail_mem, evt_detail_size); in mrsas_alloc_mem()
2088 if (bus_dmamap_load(sc->evt_detail_tag, sc->evt_detail_dmamap, in mrsas_alloc_mem()
2089 sc->evt_detail_mem, evt_detail_size, mrsas_addr_cb, in mrsas_alloc_mem()
2090 &sc->evt_detail_phys_addr, BUS_DMA_NOWAIT)) { in mrsas_alloc_mem()
2091 device_printf(sc->mrsas_dev, "Cannot load Event detail buffer memory\n"); in mrsas_alloc_mem()
2099 if (bus_dma_tag_create(sc->mrsas_parent_tag, in mrsas_alloc_mem()
2109 &sc->pd_info_tag)) { in mrsas_alloc_mem()
2110 device_printf(sc->mrsas_dev, "Cannot create PD INFO tag\n"); in mrsas_alloc_mem()
2113 if (bus_dmamem_alloc(sc->pd_info_tag, (void **)&sc->pd_info_mem, in mrsas_alloc_mem()
2114 BUS_DMA_NOWAIT, &sc->pd_info_dmamap)) { in mrsas_alloc_mem()
2115 device_printf(sc->mrsas_dev, "Cannot alloc PD INFO buffer memory\n"); in mrsas_alloc_mem()
2118 bzero(sc->pd_info_mem, pd_info_size); in mrsas_alloc_mem()
2119 if (bus_dmamap_load(sc->pd_info_tag, sc->pd_info_dmamap, in mrsas_alloc_mem()
2120 sc->pd_info_mem, pd_info_size, mrsas_addr_cb, in mrsas_alloc_mem()
2121 &sc->pd_info_phys_addr, BUS_DMA_NOWAIT)) { in mrsas_alloc_mem()
2122 device_printf(sc->mrsas_dev, "Cannot load PD INFO buffer memory\n"); in mrsas_alloc_mem()
2130 if (bus_dma_tag_create(sc->mrsas_parent_tag, in mrsas_alloc_mem()
2137 sc->max_num_sge, /* nsegments */ in mrsas_alloc_mem()
2141 &sc->io_lock, in mrsas_alloc_mem()
2142 &sc->data_tag)) { in mrsas_alloc_mem()
2143 device_printf(sc->mrsas_dev, "Cannot create data dma tag\n"); in mrsas_alloc_mem()
2174 mrsas_setup_raidmap(struct mrsas_softc *sc) in mrsas_setup_raidmap() argument
2179 sc->ld_drv_map[i] = in mrsas_setup_raidmap()
2180 (void *)malloc(sc->drv_map_sz, M_MRSAS, M_NOWAIT); in mrsas_setup_raidmap()
2182 if (!sc->ld_drv_map[i]) { in mrsas_setup_raidmap()
2183 device_printf(sc->mrsas_dev, "Could not allocate memory for local map"); in mrsas_setup_raidmap()
2186 free(sc->ld_drv_map[0], M_MRSAS); in mrsas_setup_raidmap()
2193 if (bus_dma_tag_create(sc->mrsas_parent_tag, in mrsas_setup_raidmap()
2198 sc->max_map_sz, in mrsas_setup_raidmap()
2200 sc->max_map_sz, in mrsas_setup_raidmap()
2203 &sc->raidmap_tag[i])) { in mrsas_setup_raidmap()
2204 device_printf(sc->mrsas_dev, in mrsas_setup_raidmap()
2208 if (bus_dmamem_alloc(sc->raidmap_tag[i], in mrsas_setup_raidmap()
2209 (void **)&sc->raidmap_mem[i], in mrsas_setup_raidmap()
2210 BUS_DMA_NOWAIT, &sc->raidmap_dmamap[i])) { in mrsas_setup_raidmap()
2211 device_printf(sc->mrsas_dev, in mrsas_setup_raidmap()
2215 bzero(sc->raidmap_mem[i], sc->max_map_sz); in mrsas_setup_raidmap()
2217 if (bus_dmamap_load(sc->raidmap_tag[i], sc->raidmap_dmamap[i], in mrsas_setup_raidmap()
2218 sc->raidmap_mem[i], sc->max_map_sz, in mrsas_setup_raidmap()
2219 mrsas_addr_cb, &sc->raidmap_phys_addr[i], in mrsas_setup_raidmap()
2221 device_printf(sc->mrsas_dev, "Cannot load raidmap memory.\n"); in mrsas_setup_raidmap()
2224 if (!sc->raidmap_mem[i]) { in mrsas_setup_raidmap()
2225 device_printf(sc->mrsas_dev, in mrsas_setup_raidmap()
2231 if (!mrsas_get_map_info(sc)) in mrsas_setup_raidmap()
2232 mrsas_sync_map_info(sc); in mrsas_setup_raidmap()
2247 megasas_setup_jbod_map(struct mrsas_softc *sc) in megasas_setup_jbod_map() argument
2255 if (!sc->ctrl_info->adapterOperations3.useSeqNumJbodFP) { in megasas_setup_jbod_map()
2256 sc->use_seqnum_jbod_fp = 0; in megasas_setup_jbod_map()
2259 if (sc->jbodmap_mem[0]) in megasas_setup_jbod_map()
2263 if (bus_dma_tag_create(sc->mrsas_parent_tag, in megasas_setup_jbod_map()
2273 &sc->jbodmap_tag[i])) { in megasas_setup_jbod_map()
2274 device_printf(sc->mrsas_dev, in megasas_setup_jbod_map()
2278 if (bus_dmamem_alloc(sc->jbodmap_tag[i], in megasas_setup_jbod_map()
2279 (void **)&sc->jbodmap_mem[i], in megasas_setup_jbod_map()
2280 BUS_DMA_NOWAIT, &sc->jbodmap_dmamap[i])) { in megasas_setup_jbod_map()
2281 device_printf(sc->mrsas_dev, in megasas_setup_jbod_map()
2285 bzero(sc->jbodmap_mem[i], pd_seq_map_sz); in megasas_setup_jbod_map()
2287 if (bus_dmamap_load(sc->jbodmap_tag[i], sc->jbodmap_dmamap[i], in megasas_setup_jbod_map()
2288 sc->jbodmap_mem[i], pd_seq_map_sz, in megasas_setup_jbod_map()
2289 mrsas_addr_cb, &sc->jbodmap_phys_addr[i], in megasas_setup_jbod_map()
2291 device_printf(sc->mrsas_dev, "Cannot load jbod map memory.\n"); in megasas_setup_jbod_map()
2294 if (!sc->jbodmap_mem[i]) { in megasas_setup_jbod_map()
2295 device_printf(sc->mrsas_dev, in megasas_setup_jbod_map()
2297 sc->use_seqnum_jbod_fp = 0; in megasas_setup_jbod_map()
2303 if (!megasas_sync_pd_seq_num(sc, false) && in megasas_setup_jbod_map()
2304 !megasas_sync_pd_seq_num(sc, true)) in megasas_setup_jbod_map()
2305 sc->use_seqnum_jbod_fp = 1; in megasas_setup_jbod_map()
2307 sc->use_seqnum_jbod_fp = 0; in megasas_setup_jbod_map()
2309 device_printf(sc->mrsas_dev, "Jbod map is supported\n"); in megasas_setup_jbod_map()
2324 mrsas_init_fw(struct mrsas_softc *sc) in mrsas_init_fw() argument
2337 ret = mrsas_transition_to_ready(sc, ocr); in mrsas_init_fw()
2341 if (sc->is_ventura || sc->is_aero) { in mrsas_init_fw()
2342 scratch_pad_3 = mrsas_read_reg_with_retries(sc, offsetof(mrsas_reg_set, outbound_scratch_pad_3)); in mrsas_init_fw()
2344 device_printf(sc->mrsas_dev, "scratch_pad_3 0x%x\n", scratch_pad_3); in mrsas_init_fw()
2346 sc->maxRaidMapSize = ((scratch_pad_3 >> in mrsas_init_fw()
2351 sc->msix_reg_offset[0] = MPI2_REPLY_POST_HOST_INDEX_OFFSET; in mrsas_init_fw()
2353 …msix_enable = (mrsas_read_reg_with_retries(sc, offsetof(mrsas_reg_set, outbound_scratch_pad)) & 0x… in mrsas_init_fw()
2356 scratch_pad_2 = mrsas_read_reg_with_retries(sc, offsetof(mrsas_reg_set, in mrsas_init_fw()
2360 if (sc->device_id == MRSAS_TBOLT) { in mrsas_init_fw()
2361 sc->msix_vectors = (scratch_pad_2 in mrsas_init_fw()
2363 fw_msix_count = sc->msix_vectors; in mrsas_init_fw()
2366 sc->msix_vectors = ((scratch_pad_2 in mrsas_init_fw()
2369 fw_msix_count = sc->msix_vectors; in mrsas_init_fw()
2371 if ((sc->mrsas_gen3_ctrl && (sc->msix_vectors > 8)) || in mrsas_init_fw()
2372 ((sc->is_ventura || sc->is_aero) && (sc->msix_vectors > 16))) in mrsas_init_fw()
2373 sc->msix_combined = true; in mrsas_init_fw()
2382 sc->msix_reg_offset[loop] = in mrsas_init_fw()
2389 sc->msix_vectors = min(sc->msix_vectors, in mrsas_init_fw()
2393 if (mrsas_allocate_msix(sc) == SUCCESS) in mrsas_init_fw()
2394 sc->msix_enable = 1; in mrsas_init_fw()
2396 sc->msix_enable = 0; in mrsas_init_fw()
2398 device_printf(sc->mrsas_dev, "FW supports <%d> MSIX vector," in mrsas_init_fw()
2400 fw_msix_count, mp_ncpus, sc->msix_vectors); in mrsas_init_fw()
2406 if (sc->msix_combined) { in mrsas_init_fw()
2407 sc->msix_reg_offset[0] = in mrsas_init_fw()
2410 if (mrsas_init_adapter(sc) != SUCCESS) { in mrsas_init_fw()
2411 device_printf(sc->mrsas_dev, "Adapter initialize Fail.\n"); in mrsas_init_fw()
2415 if (sc->is_ventura || sc->is_aero) { in mrsas_init_fw()
2416 scratch_pad_4 = mrsas_read_reg_with_retries(sc, offsetof(mrsas_reg_set, in mrsas_init_fw()
2419 sc->nvme_page_size = 1 << (scratch_pad_4 & MR_NVME_PAGE_SIZE_MASK); in mrsas_init_fw()
2421 device_printf(sc->mrsas_dev, "NVME page size\t: (%d)\n", sc->nvme_page_size); in mrsas_init_fw()
2425 if (mrsas_alloc_mfi_cmds(sc) != SUCCESS) { in mrsas_init_fw()
2426 device_printf(sc->mrsas_dev, "Allocate MFI cmd failed.\n"); in mrsas_init_fw()
2429 sc->ctrl_info = malloc(sizeof(struct mrsas_ctrl_info), M_MRSAS, M_NOWAIT); in mrsas_init_fw()
2430 if (!sc->ctrl_info) { in mrsas_init_fw()
2431 device_printf(sc->mrsas_dev, "Malloc for ctrl_info failed.\n"); in mrsas_init_fw()
2438 if (mrsas_get_ctrl_info(sc)) { in mrsas_init_fw()
2439 device_printf(sc->mrsas_dev, "Unable to get FW ctrl_info.\n"); in mrsas_init_fw()
2442 sc->secure_jbod_support = in mrsas_init_fw()
2443 (u_int8_t)sc->ctrl_info->adapterOperations3.supportSecurityonJBOD; in mrsas_init_fw()
2445 if (sc->secure_jbod_support) in mrsas_init_fw()
2446 device_printf(sc->mrsas_dev, "FW supports SED \n"); in mrsas_init_fw()
2448 if (sc->use_seqnum_jbod_fp) in mrsas_init_fw()
2449 device_printf(sc->mrsas_dev, "FW supports JBOD Map \n"); in mrsas_init_fw()
2451 if (sc->support_morethan256jbod) in mrsas_init_fw()
2452 device_printf(sc->mrsas_dev, "FW supports JBOD Map Ext \n"); in mrsas_init_fw()
2454 if (mrsas_setup_raidmap(sc) != SUCCESS) { in mrsas_init_fw()
2455 device_printf(sc->mrsas_dev, "Error: RAID map setup FAILED !!! " in mrsas_init_fw()
2459 megasas_setup_jbod_map(sc); in mrsas_init_fw()
2461 memset(sc->target_list, 0, in mrsas_init_fw()
2464 sc->target_list[i].target_id = 0xffff; in mrsas_init_fw()
2467 memset(sc->pd_list, 0, in mrsas_init_fw()
2469 if (mrsas_get_pd_list(sc) != SUCCESS) { in mrsas_init_fw()
2470 device_printf(sc->mrsas_dev, "Get PD list failed.\n"); in mrsas_init_fw()
2473 memset(sc->ld_ids, 0xff, MRSAS_MAX_LD_IDS); in mrsas_init_fw()
2474 if (mrsas_get_ld_list(sc) != SUCCESS) { in mrsas_init_fw()
2475 device_printf(sc->mrsas_dev, "Get LD lsit failed.\n"); in mrsas_init_fw()
2479 if ((sc->is_ventura || sc->is_aero) && sc->drv_stream_detection) { in mrsas_init_fw()
2480 sc->streamDetectByLD = malloc(sizeof(PTR_LD_STREAM_DETECT) * in mrsas_init_fw()
2482 if (!sc->streamDetectByLD) { in mrsas_init_fw()
2483 device_printf(sc->mrsas_dev, in mrsas_init_fw()
2488 sc->streamDetectByLD[i] = malloc(sizeof(LD_STREAM_DETECT), M_MRSAS, M_NOWAIT); in mrsas_init_fw()
2489 if (!sc->streamDetectByLD[i]) { in mrsas_init_fw()
2490 device_printf(sc->mrsas_dev, "unable to allocate stream detect by LD\n"); in mrsas_init_fw()
2492 free(sc->streamDetectByLD[j], M_MRSAS); in mrsas_init_fw()
2493 free(sc->streamDetectByLD, M_MRSAS); in mrsas_init_fw()
2494 sc->streamDetectByLD = NULL; in mrsas_init_fw()
2497 memset(sc->streamDetectByLD[i], 0, sizeof(LD_STREAM_DETECT)); in mrsas_init_fw()
2498 sc->streamDetectByLD[i]->mruBitMap = MR_STREAM_BITMAP; in mrsas_init_fw()
2513 max_sectors_1 = (1 << sc->ctrl_info->stripe_sz_ops.min) * in mrsas_init_fw()
2514 sc->ctrl_info->max_strips_per_io; in mrsas_init_fw()
2515 max_sectors_2 = sc->ctrl_info->max_request_size; in mrsas_init_fw()
2517 sc->max_sectors_per_req = (sc->max_num_sge - 1) * MRSAS_PAGE_SIZE / 512; in mrsas_init_fw()
2519 if (tmp_sectors && (sc->max_sectors_per_req > tmp_sectors)) in mrsas_init_fw()
2520 sc->max_sectors_per_req = tmp_sectors; in mrsas_init_fw()
2522 sc->disableOnlineCtrlReset = in mrsas_init_fw()
2523 sc->ctrl_info->properties.OnOffProperties.disableOnlineCtrlReset; in mrsas_init_fw()
2524 sc->UnevenSpanSupport = in mrsas_init_fw()
2525 sc->ctrl_info->adapterOperations2.supportUnevenSpans; in mrsas_init_fw()
2526 if (sc->UnevenSpanSupport) { in mrsas_init_fw()
2527 device_printf(sc->mrsas_dev, "FW supports: UnevenSpanSupport=%x\n\n", in mrsas_init_fw()
2528 sc->UnevenSpanSupport); in mrsas_init_fw()
2530 if (MR_ValidateMapInfo(sc)) in mrsas_init_fw()
2531 sc->fast_path_io = 1; in mrsas_init_fw()
2533 sc->fast_path_io = 0; in mrsas_init_fw()
2536 device_printf(sc->mrsas_dev, "max_fw_cmds: %u max_scsi_cmds: %u\n", in mrsas_init_fw()
2537 sc->max_fw_cmds, sc->max_scsi_cmds); in mrsas_init_fw()
2551 mrsas_init_adapter(struct mrsas_softc *sc) in mrsas_init_adapter() argument
2559 status = mrsas_read_reg_with_retries(sc, offsetof(mrsas_reg_set, outbound_scratch_pad)); in mrsas_init_adapter()
2561 sc->max_fw_cmds = status & MRSAS_FWSTATE_MAXCMD_MASK; in mrsas_init_adapter()
2564 sc->max_fw_cmds = sc->max_fw_cmds - 1; in mrsas_init_adapter()
2565 sc->max_scsi_cmds = sc->max_fw_cmds - MRSAS_MAX_MFI_CMDS; in mrsas_init_adapter()
2568 sc->reply_q_depth = ((sc->max_fw_cmds + 1 + 15) / 16 * 16) * 2; in mrsas_init_adapter()
2569 sc->request_alloc_sz = sizeof(MRSAS_REQUEST_DESCRIPTOR_UNION) * sc->max_fw_cmds; in mrsas_init_adapter()
2570 sc->reply_alloc_sz = sizeof(MPI2_REPLY_DESCRIPTORS_UNION) * (sc->reply_q_depth); in mrsas_init_adapter()
2571 sc->io_frames_alloc_sz = MRSAS_MPI2_RAID_DEFAULT_IO_FRAME_SIZE + in mrsas_init_adapter()
2572 (MRSAS_MPI2_RAID_DEFAULT_IO_FRAME_SIZE * (sc->max_fw_cmds + 1)); in mrsas_init_adapter()
2573 scratch_pad_2 = mrsas_read_reg_with_retries(sc, offsetof(mrsas_reg_set, in mrsas_init_adapter()
2576 mrsas_dprint(sc, MRSAS_TRACE, "%s: sc->reply_q_depth 0x%x," in mrsas_init_adapter()
2579 sc->reply_q_depth, sc->request_alloc_sz, in mrsas_init_adapter()
2580 sc->reply_alloc_sz, sc->io_frames_alloc_sz); in mrsas_init_adapter()
2589 sc->max_chain_frame_sz = in mrsas_init_adapter()
2593 sc->max_chain_frame_sz = in mrsas_init_adapter()
2597 sc->chain_frames_alloc_sz = sc->max_chain_frame_sz * sc->max_fw_cmds; in mrsas_init_adapter()
2598 sc->max_sge_in_main_msg = (MRSAS_MPI2_RAID_DEFAULT_IO_FRAME_SIZE - in mrsas_init_adapter()
2601 sc->max_sge_in_chain = sc->max_chain_frame_sz / sizeof(MPI2_SGE_IO_UNION); in mrsas_init_adapter()
2602 sc->max_num_sge = sc->max_sge_in_main_msg + sc->max_sge_in_chain - 2; in mrsas_init_adapter()
2604 mrsas_dprint(sc, MRSAS_INFO, in mrsas_init_adapter()
2607 sc->max_num_sge, in mrsas_init_adapter()
2608 sc->max_chain_frame_sz, sc->max_fw_cmds, in mrsas_init_adapter()
2609 sc->chain_frames_alloc_sz); in mrsas_init_adapter()
2612 sc->chain_offset_mfi_pthru = offsetof(MRSAS_RAID_SCSI_IO_REQUEST, SGL) / 16; in mrsas_init_adapter()
2614 sc->chain_offset_io_request = (MRSAS_MPI2_RAID_DEFAULT_IO_FRAME_SIZE - in mrsas_init_adapter()
2617 int count = sc->msix_vectors > 0 ? sc->msix_vectors : 1; in mrsas_init_adapter()
2620 sc->last_reply_idx[i] = 0; in mrsas_init_adapter()
2622 ret = mrsas_alloc_mem(sc); in mrsas_init_adapter()
2626 ret = mrsas_alloc_mpt_cmds(sc); in mrsas_init_adapter()
2630 ret = mrsas_ioc_init(sc); in mrsas_init_adapter()
2644 mrsas_alloc_ioc_cmd(struct mrsas_softc *sc) in mrsas_alloc_ioc_cmd() argument
2650 if (bus_dma_tag_create(sc->mrsas_parent_tag, in mrsas_alloc_ioc_cmd()
2660 &sc->ioc_init_tag)) { in mrsas_alloc_ioc_cmd()
2661 device_printf(sc->mrsas_dev, "Cannot allocate ioc init tag\n"); in mrsas_alloc_ioc_cmd()
2664 if (bus_dmamem_alloc(sc->ioc_init_tag, (void **)&sc->ioc_init_mem, in mrsas_alloc_ioc_cmd()
2665 BUS_DMA_NOWAIT, &sc->ioc_init_dmamap)) { in mrsas_alloc_ioc_cmd()
2666 device_printf(sc->mrsas_dev, "Cannot allocate ioc init cmd mem\n"); in mrsas_alloc_ioc_cmd()
2669 bzero(sc->ioc_init_mem, ioc_init_size); in mrsas_alloc_ioc_cmd()
2670 if (bus_dmamap_load(sc->ioc_init_tag, sc->ioc_init_dmamap, in mrsas_alloc_ioc_cmd()
2671 sc->ioc_init_mem, ioc_init_size, mrsas_addr_cb, in mrsas_alloc_ioc_cmd()
2672 &sc->ioc_init_phys_mem, BUS_DMA_NOWAIT)) { in mrsas_alloc_ioc_cmd()
2673 device_printf(sc->mrsas_dev, "Cannot load ioc init cmd mem\n"); in mrsas_alloc_ioc_cmd()
2686 mrsas_free_ioc_cmd(struct mrsas_softc *sc) in mrsas_free_ioc_cmd() argument
2688 if (sc->ioc_init_phys_mem) in mrsas_free_ioc_cmd()
2689 bus_dmamap_unload(sc->ioc_init_tag, sc->ioc_init_dmamap); in mrsas_free_ioc_cmd()
2690 if (sc->ioc_init_mem != NULL) in mrsas_free_ioc_cmd()
2691 bus_dmamem_free(sc->ioc_init_tag, sc->ioc_init_mem, sc->ioc_init_dmamap); in mrsas_free_ioc_cmd()
2692 if (sc->ioc_init_tag != NULL) in mrsas_free_ioc_cmd()
2693 bus_dma_tag_destroy(sc->ioc_init_tag); in mrsas_free_ioc_cmd()
2703 mrsas_ioc_init(struct mrsas_softc *sc) in mrsas_ioc_init() argument
2714 if (mrsas_alloc_ioc_cmd(sc)) { in mrsas_ioc_init()
2715 device_printf(sc->mrsas_dev, "Cannot allocate IOC command.\n"); in mrsas_ioc_init()
2719 if (!sc->block_sync_cache) { in mrsas_ioc_init()
2720 scratch_pad_2 = mrsas_read_reg_with_retries(sc, offsetof(mrsas_reg_set, in mrsas_ioc_init()
2722 sc->fw_sync_cache_support = (scratch_pad_2 & in mrsas_ioc_init()
2726 IOCInitMsg = (pMpi2IOCInitRequest_t)(((char *)sc->ioc_init_mem) + 1024); in mrsas_ioc_init()
2732 IOCInitMsg->ReplyDescriptorPostQueueDepth = htole16(sc->reply_q_depth); in mrsas_ioc_init()
2733 IOCInitMsg->ReplyDescriptorPostQueueAddress = htole64(sc->reply_desc_phys_addr); in mrsas_ioc_init()
2734 IOCInitMsg->SystemRequestFrameBaseAddress = htole64(sc->io_request_phys_addr); in mrsas_ioc_init()
2735 IOCInitMsg->HostMSIxVectors = (sc->msix_vectors > 0 ? sc->msix_vectors : 0); in mrsas_ioc_init()
2738 init_frame = (struct mrsas_init_frame *)sc->ioc_init_mem; in mrsas_ioc_init()
2744 if (sc->mrsas_gen3_ctrl || sc->is_ventura || sc->is_aero) { in mrsas_ioc_init()
2748 if (sc->verbuf_mem) { in mrsas_ioc_init()
2749 snprintf((char *)sc->verbuf_mem, strlen(MRSAS_VERSION) + 2, "%s\n", in mrsas_ioc_init()
2751 init_frame->driver_ver_lo = (bus_addr_t)sc->verbuf_phys_addr; in mrsas_ioc_init()
2757 if (sc->max_chain_frame_sz > MEGASAS_CHAIN_FRAME_SZ_MIN) in mrsas_ioc_init()
2762 phys_addr = (bus_addr_t)sc->ioc_init_phys_mem + 1024; in mrsas_ioc_init()
2766 req_desc.addr.Words = htole64((bus_addr_t)sc->ioc_init_phys_mem); in mrsas_ioc_init()
2770 mrsas_disable_intr(sc); in mrsas_ioc_init()
2771 mrsas_dprint(sc, MRSAS_OCR, "Issuing IOC INIT command to FW.\n"); in mrsas_ioc_init()
2772 mrsas_write_64bit_req_desc(sc, req_desc.addr.u.low, req_desc.addr.u.high); in mrsas_ioc_init()
2788 mrsas_dprint(sc, MRSAS_OCR, in mrsas_ioc_init()
2792 device_printf(sc->mrsas_dev, "IOC Init timed out after %d seconds.\n", max_wait); in mrsas_ioc_init()
2794 device_printf(sc->mrsas_dev, "IOC Init failed, status = 0x%x\n", init_frame->cmd_status); in mrsas_ioc_init()
2798 if (sc->is_aero) { in mrsas_ioc_init()
2799 scratch_pad_2 = mrsas_read_reg_with_retries(sc, offsetof(mrsas_reg_set, in mrsas_ioc_init()
2801 sc->atomic_desc_support = (scratch_pad_2 & in mrsas_ioc_init()
2803 device_printf(sc->mrsas_dev, "FW supports atomic descriptor: %s\n", in mrsas_ioc_init()
2804 sc->atomic_desc_support ? "Yes" : "No"); in mrsas_ioc_init()
2807 mrsas_free_ioc_cmd(sc); in mrsas_ioc_init()
2822 mrsas_alloc_mpt_cmds(struct mrsas_softc *sc) in mrsas_alloc_mpt_cmds() argument
2832 max_fw_cmds = sc->max_fw_cmds; in mrsas_alloc_mpt_cmds()
2834 sc->req_desc = malloc(sc->request_alloc_sz, M_MRSAS, M_NOWAIT); in mrsas_alloc_mpt_cmds()
2835 if (!sc->req_desc) { in mrsas_alloc_mpt_cmds()
2836 device_printf(sc->mrsas_dev, "Out of memory, cannot alloc req desc\n"); in mrsas_alloc_mpt_cmds()
2839 memset(sc->req_desc, 0, sc->request_alloc_sz); in mrsas_alloc_mpt_cmds()
2846 sc->mpt_cmd_list = malloc(sizeof(struct mrsas_mpt_cmd *) * max_fw_cmds, in mrsas_alloc_mpt_cmds()
2848 if (!sc->mpt_cmd_list) { in mrsas_alloc_mpt_cmds()
2849 device_printf(sc->mrsas_dev, "Cannot alloc memory for mpt_cmd_list.\n"); in mrsas_alloc_mpt_cmds()
2852 memset(sc->mpt_cmd_list, 0, sizeof(struct mrsas_mpt_cmd *) * max_fw_cmds); in mrsas_alloc_mpt_cmds()
2854 sc->mpt_cmd_list[i] = malloc(sizeof(struct mrsas_mpt_cmd), in mrsas_alloc_mpt_cmds()
2856 if (!sc->mpt_cmd_list[i]) { in mrsas_alloc_mpt_cmds()
2858 free(sc->mpt_cmd_list[j], M_MRSAS); in mrsas_alloc_mpt_cmds()
2859 free(sc->mpt_cmd_list, M_MRSAS); in mrsas_alloc_mpt_cmds()
2860 sc->mpt_cmd_list = NULL; in mrsas_alloc_mpt_cmds()
2865 io_req_base = (u_int8_t *)sc->io_request_mem + MRSAS_MPI2_RAID_DEFAULT_IO_FRAME_SIZE; in mrsas_alloc_mpt_cmds()
2866 io_req_base_phys = (bus_addr_t)sc->io_request_phys_addr + MRSAS_MPI2_RAID_DEFAULT_IO_FRAME_SIZE; in mrsas_alloc_mpt_cmds()
2867 chain_frame_base = (u_int8_t *)sc->chain_frame_mem; in mrsas_alloc_mpt_cmds()
2868 chain_frame_base_phys = (bus_addr_t)sc->chain_frame_phys_addr; in mrsas_alloc_mpt_cmds()
2869 sense_base = (u_int8_t *)sc->sense_mem; in mrsas_alloc_mpt_cmds()
2870 sense_base_phys = (bus_addr_t)sc->sense_phys_addr; in mrsas_alloc_mpt_cmds()
2872 cmd = sc->mpt_cmd_list[i]; in mrsas_alloc_mpt_cmds()
2874 chain_offset = sc->max_chain_frame_sz * i; in mrsas_alloc_mpt_cmds()
2880 callout_init_mtx(&cmd->cm_callout, &sc->sim_lock, 0); in mrsas_alloc_mpt_cmds()
2882 cmd->sc = sc; in mrsas_alloc_mpt_cmds()
2890 if (bus_dmamap_create(sc->data_tag, 0, &cmd->data_dmamap)) { in mrsas_alloc_mpt_cmds()
2893 TAILQ_INSERT_TAIL(&(sc->mrsas_mpt_cmd_list_head), cmd, next); in mrsas_alloc_mpt_cmds()
2897 reply_desc = sc->reply_desc_mem; in mrsas_alloc_mpt_cmds()
2898 count = sc->msix_vectors > 0 ? sc->msix_vectors : 1; in mrsas_alloc_mpt_cmds()
2899 for (i = 0; i < sc->reply_q_depth * count; i++, reply_desc++) { in mrsas_alloc_mpt_cmds()
2912 mrsas_write_64bit_req_desc(struct mrsas_softc *sc, u_int32_t req_desc_lo, in mrsas_write_64bit_req_desc() argument
2915 mtx_lock(&sc->pci_lock); in mrsas_write_64bit_req_desc()
2916 mrsas_write_reg(sc, offsetof(mrsas_reg_set, inbound_low_queue_port), in mrsas_write_64bit_req_desc()
2918 mrsas_write_reg(sc, offsetof(mrsas_reg_set, inbound_high_queue_port), in mrsas_write_64bit_req_desc()
2920 mtx_unlock(&sc->pci_lock); in mrsas_write_64bit_req_desc()
2933 mrsas_fire_cmd(struct mrsas_softc *sc, u_int32_t req_desc_lo, in mrsas_fire_cmd() argument
2936 if (sc->atomic_desc_support) in mrsas_fire_cmd()
2937 mrsas_write_reg(sc, offsetof(mrsas_reg_set, inbound_single_queue_port), in mrsas_fire_cmd()
2940 mrsas_write_64bit_req_desc(sc, req_desc_lo, req_desc_hi); in mrsas_fire_cmd()
2953 mrsas_transition_to_ready(struct mrsas_softc *sc, int ocr) in mrsas_transition_to_ready() argument
2961 val = mrsas_read_reg_with_retries(sc, offsetof(mrsas_reg_set, outbound_scratch_pad)); in mrsas_transition_to_ready()
2966 device_printf(sc->mrsas_dev, "Waiting for FW to come to ready state\n"); in mrsas_transition_to_ready()
2969 abs_state = mrsas_read_reg_with_retries(sc, offsetof(mrsas_reg_set, outbound_scratch_pad)); in mrsas_transition_to_ready()
2972 device_printf(sc->mrsas_dev, "FW is in FAULT state!!\n"); in mrsas_transition_to_ready()
2980 mrsas_write_reg(sc, offsetof(mrsas_reg_set, doorbell), in mrsas_transition_to_ready()
2985 mrsas_write_reg(sc, offsetof(mrsas_reg_set, doorbell), in mrsas_transition_to_ready()
2994 mrsas_disable_intr(sc); in mrsas_transition_to_ready()
2995 mrsas_write_reg(sc, offsetof(mrsas_reg_set, doorbell), MFI_RESET_FLAGS); in mrsas_transition_to_ready()
2997 if (mrsas_read_reg_with_retries(sc, offsetof(mrsas_reg_set, doorbell)) & 1) in mrsas_transition_to_ready()
3027 device_printf(sc->mrsas_dev, "Unknown state 0x%x\n", fw_state); in mrsas_transition_to_ready()
3035 fw_state = (mrsas_read_reg_with_retries(sc, offsetof(mrsas_reg_set, in mrsas_transition_to_ready()
3037 curr_abs_state = mrsas_read_reg_with_retries(sc, offsetof(mrsas_reg_set, in mrsas_transition_to_ready()
3049 device_printf(sc->mrsas_dev, "FW state [%d] hasn't changed " in mrsas_transition_to_ready()
3054 mrsas_dprint(sc, MRSAS_OCR, "FW now in Ready state\n"); in mrsas_transition_to_ready()
3065 mrsas_get_mfi_cmd(struct mrsas_softc *sc) in mrsas_get_mfi_cmd() argument
3069 mtx_lock(&sc->mfi_cmd_pool_lock); in mrsas_get_mfi_cmd()
3070 if (!TAILQ_EMPTY(&sc->mrsas_mfi_cmd_list_head)) { in mrsas_get_mfi_cmd()
3071 cmd = TAILQ_FIRST(&sc->mrsas_mfi_cmd_list_head); in mrsas_get_mfi_cmd()
3072 TAILQ_REMOVE(&sc->mrsas_mfi_cmd_list_head, cmd, next); in mrsas_get_mfi_cmd()
3074 mtx_unlock(&sc->mfi_cmd_pool_lock); in mrsas_get_mfi_cmd()
3090 struct mrsas_softc *sc; in mrsas_ocr_thread() local
3094 sc = (struct mrsas_softc *)arg; in mrsas_ocr_thread()
3096 mrsas_dprint(sc, MRSAS_TRACE, "%s\n", __func__); in mrsas_ocr_thread()
3097 sc->ocr_thread_active = 1; in mrsas_ocr_thread()
3098 mtx_lock(&sc->sim_lock); in mrsas_ocr_thread()
3101 msleep(&sc->ocr_chan, &sc->sim_lock, PRIBIO, in mrsas_ocr_thread()
3102 "mrsas_ocr", sc->mrsas_fw_fault_check_delay * hz); in mrsas_ocr_thread()
3103 if (sc->remove_in_progress || in mrsas_ocr_thread()
3104 sc->adprecovery == MRSAS_HW_CRITICAL_ERROR) { in mrsas_ocr_thread()
3105 mrsas_dprint(sc, MRSAS_OCR, in mrsas_ocr_thread()
3107 sc->remove_in_progress ? "Shutdown" : in mrsas_ocr_thread()
3111 fw_status = mrsas_read_reg_with_retries(sc, in mrsas_ocr_thread()
3114 if (fw_state == MFI_STATE_FAULT || sc->do_timedout_reset || in mrsas_ocr_thread()
3115 mrsas_atomic_read(&sc->target_reset_outstanding)) { in mrsas_ocr_thread()
3117 mrsas_xpt_freeze(sc); in mrsas_ocr_thread()
3120 if (mrsas_atomic_read(&sc->target_reset_outstanding)) { in mrsas_ocr_thread()
3121 device_printf(sc->mrsas_dev, "Initiating Target RESET " in mrsas_ocr_thread()
3125 msleep(&sc->ocr_chan, &sc->sim_lock, PRIBIO, in mrsas_ocr_thread()
3129 if (mrsas_reset_targets(sc) == FAIL) in mrsas_ocr_thread()
3137 (sc->do_timedout_reset == MFI_DCMD_TIMEOUT_OCR)) { in mrsas_ocr_thread()
3139 device_printf(sc->mrsas_dev, "Initiaiting OCR because of " in mrsas_ocr_thread()
3142 device_printf(sc->mrsas_dev, "Initiaiting OCR " in mrsas_ocr_thread()
3143 "because of %s!\n", sc->do_timedout_reset ? in mrsas_ocr_thread()
3146 mtx_lock_spin(&sc->ioctl_lock); in mrsas_ocr_thread()
3147 sc->reset_in_progress = 1; in mrsas_ocr_thread()
3148 mtx_unlock_spin(&sc->ioctl_lock); in mrsas_ocr_thread()
3149 sc->reset_count++; in mrsas_ocr_thread()
3154 mtx_unlock(&sc->sim_lock); in mrsas_ocr_thread()
3155 taskqueue_drain(sc->ev_tq, &sc->ev_task); in mrsas_ocr_thread()
3156 mtx_lock(&sc->sim_lock); in mrsas_ocr_thread()
3158 taskqueue_block(sc->ev_tq); in mrsas_ocr_thread()
3160 mrsas_reset_ctrl(sc, sc->do_timedout_reset); in mrsas_ocr_thread()
3162 sc->do_timedout_reset = 0; in mrsas_ocr_thread()
3163 sc->reset_in_progress = 0; in mrsas_ocr_thread()
3165 mrsas_atomic_set(&sc->target_reset_outstanding, 0); in mrsas_ocr_thread()
3166 memset(sc->target_reset_pool, 0, in mrsas_ocr_thread()
3167 sizeof(sc->target_reset_pool)); in mrsas_ocr_thread()
3168 taskqueue_unblock(sc->ev_tq); in mrsas_ocr_thread()
3172 mrsas_xpt_release(sc); in mrsas_ocr_thread()
3175 mtx_unlock(&sc->sim_lock); in mrsas_ocr_thread()
3176 sc->ocr_thread_active = 0; in mrsas_ocr_thread()
3188 mrsas_reset_reply_desc(struct mrsas_softc *sc) in mrsas_reset_reply_desc() argument
3193 count = sc->msix_vectors > 0 ? sc->msix_vectors : 1; in mrsas_reset_reply_desc()
3195 sc->last_reply_idx[i] = 0; in mrsas_reset_reply_desc()
3197 reply_desc = sc->reply_desc_mem; in mrsas_reset_reply_desc()
3198 for (i = 0; i < sc->reply_q_depth; i++, reply_desc++) { in mrsas_reset_reply_desc()
3216 mrsas_reset_ctrl(struct mrsas_softc *sc, u_int8_t reset_reason) in mrsas_reset_ctrl() argument
3226 if (sc->adprecovery == MRSAS_HW_CRITICAL_ERROR) { in mrsas_reset_ctrl()
3227 device_printf(sc->mrsas_dev, in mrsas_reset_ctrl()
3231 mrsas_set_bit(MRSAS_FUSION_IN_RESET, &sc->reset_flags); in mrsas_reset_ctrl()
3232 sc->adprecovery = MRSAS_ADPRESET_SM_INFAULT; in mrsas_reset_ctrl()
3233 mrsas_disable_intr(sc); in mrsas_reset_ctrl()
3234 msleep(&sc->ocr_chan, &sc->sim_lock, PRIBIO, "mrsas_ocr", in mrsas_reset_ctrl()
3235 sc->mrsas_fw_fault_check_delay * hz); in mrsas_reset_ctrl()
3238 if (mrsas_wait_for_outstanding(sc, reset_reason)) { in mrsas_reset_ctrl()
3239 mrsas_dprint(sc, MRSAS_OCR, in mrsas_reset_ctrl()
3243 mtx_unlock(&sc->sim_lock); in mrsas_reset_ctrl()
3244 for (i = 0; i < sc->max_fw_cmds; i++) { in mrsas_reset_ctrl()
3245 mpt_cmd = sc->mpt_cmd_list[i]; in mrsas_reset_ctrl()
3248 mrsas_dprint(sc, MRSAS_OCR, in mrsas_reset_ctrl()
3257 mrsas_cmd_done(sc, mpt_cmd); in mrsas_reset_ctrl()
3265 mrsas_atomic_set(&sc->fw_outstanding, 0); in mrsas_reset_ctrl()
3267 mtx_lock(&sc->sim_lock); in mrsas_reset_ctrl()
3269 status_reg = mrsas_read_reg_with_retries(sc, offsetof(mrsas_reg_set, in mrsas_reset_ctrl()
3273 if (sc->disableOnlineCtrlReset || in mrsas_reset_ctrl()
3276 mrsas_dprint(sc, MRSAS_OCR, "Reset not supported, killing adapter.\n"); in mrsas_reset_ctrl()
3277 mrsas_kill_hba(sc); in mrsas_reset_ctrl()
3283 mrsas_write_reg(sc, offsetof(mrsas_reg_set, fusion_seq_offset), in mrsas_reset_ctrl()
3285 mrsas_write_reg(sc, offsetof(mrsas_reg_set, fusion_seq_offset), in mrsas_reset_ctrl()
3287 mrsas_write_reg(sc, offsetof(mrsas_reg_set, fusion_seq_offset), in mrsas_reset_ctrl()
3289 mrsas_write_reg(sc, offsetof(mrsas_reg_set, fusion_seq_offset), in mrsas_reset_ctrl()
3291 mrsas_write_reg(sc, offsetof(mrsas_reg_set, fusion_seq_offset), in mrsas_reset_ctrl()
3293 mrsas_write_reg(sc, offsetof(mrsas_reg_set, fusion_seq_offset), in mrsas_reset_ctrl()
3295 mrsas_write_reg(sc, offsetof(mrsas_reg_set, fusion_seq_offset), in mrsas_reset_ctrl()
3299 host_diag = mrsas_read_reg_with_retries(sc, offsetof(mrsas_reg_set, in mrsas_reset_ctrl()
3304 host_diag = mrsas_read_reg_with_retries(sc, offsetof(mrsas_reg_set, in mrsas_reset_ctrl()
3307 mrsas_dprint(sc, MRSAS_OCR, in mrsas_reset_ctrl()
3316 mrsas_write_reg(sc, offsetof(mrsas_reg_set, fusion_host_diag), in mrsas_reset_ctrl()
3321 host_diag = mrsas_read_reg_with_retries(sc, offsetof(mrsas_reg_set, in mrsas_reset_ctrl()
3326 host_diag = mrsas_read_reg_with_retries(sc, offsetof(mrsas_reg_set, in mrsas_reset_ctrl()
3329 mrsas_dprint(sc, MRSAS_OCR, in mrsas_reset_ctrl()
3337 abs_state = mrsas_read_reg_with_retries(sc, offsetof(mrsas_reg_set, in mrsas_reset_ctrl()
3343 abs_state = mrsas_read_reg_with_retries(sc, offsetof(mrsas_reg_set, in mrsas_reset_ctrl()
3347 mrsas_dprint(sc, MRSAS_OCR, "firmware state < MFI_STATE_FW_INIT," in mrsas_reset_ctrl()
3352 if (mrsas_transition_to_ready(sc, 1)) { in mrsas_reset_ctrl()
3353 mrsas_dprint(sc, MRSAS_OCR, in mrsas_reset_ctrl()
3357 mrsas_reset_reply_desc(sc); in mrsas_reset_ctrl()
3358 if (mrsas_ioc_init(sc)) { in mrsas_reset_ctrl()
3359 mrsas_dprint(sc, MRSAS_OCR, "mrsas_ioc_init() failed!\n"); in mrsas_reset_ctrl()
3362 for (j = 0; j < sc->max_fw_cmds; j++) { in mrsas_reset_ctrl()
3363 mpt_cmd = sc->mpt_cmd_list[j]; in mrsas_reset_ctrl()
3365 mfi_cmd = sc->mfi_cmd_list[mpt_cmd->sync_cmd_idx]; in mrsas_reset_ctrl()
3370 req_desc = mrsas_get_request_desc(sc, in mrsas_reset_ctrl()
3372 mrsas_dprint(sc, MRSAS_OCR, in mrsas_reset_ctrl()
3376 device_printf(sc->mrsas_dev, in mrsas_reset_ctrl()
3379 mrsas_fire_cmd(sc, req_desc->addr.u.low, in mrsas_reset_ctrl()
3386 memset(sc->load_balance_info, 0, in mrsas_reset_ctrl()
3389 if (mrsas_get_ctrl_info(sc)) { in mrsas_reset_ctrl()
3390 mrsas_kill_hba(sc); in mrsas_reset_ctrl()
3394 if (!mrsas_get_map_info(sc)) in mrsas_reset_ctrl()
3395 mrsas_sync_map_info(sc); in mrsas_reset_ctrl()
3397 megasas_setup_jbod_map(sc); in mrsas_reset_ctrl()
3399 if ((sc->is_ventura || sc->is_aero) && sc->streamDetectByLD) { in mrsas_reset_ctrl()
3401 memset(sc->streamDetectByLD[i], 0, sizeof(LD_STREAM_DETECT)); in mrsas_reset_ctrl()
3402 sc->streamDetectByLD[i]->mruBitMap = MR_STREAM_BITMAP; in mrsas_reset_ctrl()
3406 mrsas_clear_bit(MRSAS_FUSION_IN_RESET, &sc->reset_flags); in mrsas_reset_ctrl()
3407 mrsas_enable_intr(sc); in mrsas_reset_ctrl()
3408 sc->adprecovery = MRSAS_HBA_OPERATIONAL; in mrsas_reset_ctrl()
3415 mtx_unlock(&sc->sim_lock); in mrsas_reset_ctrl()
3416 if (mrsas_register_aen(sc, sc->last_seq_num, in mrsas_reset_ctrl()
3418 device_printf(sc->mrsas_dev, in mrsas_reset_ctrl()
3425 mtx_lock(&sc->sim_lock); in mrsas_reset_ctrl()
3428 device_printf(sc->mrsas_dev, "Reset successful\n"); in mrsas_reset_ctrl()
3433 device_printf(sc->mrsas_dev, "Reset failed, killing adapter.\n"); in mrsas_reset_ctrl()
3434 mrsas_kill_hba(sc); in mrsas_reset_ctrl()
3437 mrsas_clear_bit(MRSAS_FUSION_IN_RESET, &sc->reset_flags); in mrsas_reset_ctrl()
3438 mrsas_enable_intr(sc); in mrsas_reset_ctrl()
3439 sc->adprecovery = MRSAS_HBA_OPERATIONAL; in mrsas_reset_ctrl()
3442 mrsas_clear_bit(MRSAS_FUSION_IN_RESET, &sc->reset_flags); in mrsas_reset_ctrl()
3443 mrsas_dprint(sc, MRSAS_OCR, in mrsas_reset_ctrl()
3455 mrsas_kill_hba(struct mrsas_softc *sc) in mrsas_kill_hba() argument
3457 sc->adprecovery = MRSAS_HW_CRITICAL_ERROR; in mrsas_kill_hba()
3459 mrsas_dprint(sc, MRSAS_OCR, "%s\n", __func__); in mrsas_kill_hba()
3460 mrsas_write_reg(sc, offsetof(mrsas_reg_set, doorbell), in mrsas_kill_hba()
3463 mrsas_read_reg(sc, offsetof(mrsas_reg_set, doorbell)); in mrsas_kill_hba()
3464 mrsas_complete_outstanding_ioctls(sc); in mrsas_kill_hba()
3474 mrsas_complete_outstanding_ioctls(struct mrsas_softc *sc) in mrsas_complete_outstanding_ioctls() argument
3481 count = sc->msix_vectors > 0 ? sc->msix_vectors : 1; in mrsas_complete_outstanding_ioctls()
3482 for (i = 0; i < sc->max_fw_cmds; i++) { in mrsas_complete_outstanding_ioctls()
3483 cmd_mpt = sc->mpt_cmd_list[i]; in mrsas_complete_outstanding_ioctls()
3486 cmd_mfi = sc->mfi_cmd_list[cmd_mpt->sync_cmd_idx]; in mrsas_complete_outstanding_ioctls()
3489 mrsas_complete_mptmfi_passthru(sc, cmd_mfi, in mrsas_complete_outstanding_ioctls()
3504 mrsas_wait_for_outstanding(struct mrsas_softc *sc, u_int8_t check_reason) in mrsas_wait_for_outstanding() argument
3510 if (sc->remove_in_progress) { in mrsas_wait_for_outstanding()
3511 mrsas_dprint(sc, MRSAS_OCR, in mrsas_wait_for_outstanding()
3517 fw_state = mrsas_read_reg_with_retries(sc, offsetof(mrsas_reg_set, in mrsas_wait_for_outstanding()
3520 mrsas_dprint(sc, MRSAS_OCR, in mrsas_wait_for_outstanding()
3522 count = sc->msix_vectors > 0 ? sc->msix_vectors : 1; in mrsas_wait_for_outstanding()
3523 mtx_unlock(&sc->sim_lock); in mrsas_wait_for_outstanding()
3525 mrsas_complete_cmd(sc, MSIxIndex); in mrsas_wait_for_outstanding()
3526 mtx_lock(&sc->sim_lock); in mrsas_wait_for_outstanding()
3531 mrsas_dprint(sc, MRSAS_OCR, in mrsas_wait_for_outstanding()
3536 outstanding = mrsas_atomic_read(&sc->fw_outstanding); in mrsas_wait_for_outstanding()
3541 mrsas_dprint(sc, MRSAS_OCR, "[%2d]waiting for %d " in mrsas_wait_for_outstanding()
3543 count = sc->msix_vectors > 0 ? sc->msix_vectors : 1; in mrsas_wait_for_outstanding()
3544 mtx_unlock(&sc->sim_lock); in mrsas_wait_for_outstanding()
3546 mrsas_complete_cmd(sc, MSIxIndex); in mrsas_wait_for_outstanding()
3547 mtx_lock(&sc->sim_lock); in mrsas_wait_for_outstanding()
3552 if (mrsas_atomic_read(&sc->fw_outstanding)) { in mrsas_wait_for_outstanding()
3553 mrsas_dprint(sc, MRSAS_OCR, in mrsas_wait_for_outstanding()
3571 struct mrsas_softc *sc = cmd_mfi->sc; in mrsas_release_mfi_cmd() local
3574 mtx_lock(&sc->mfi_cmd_pool_lock); in mrsas_release_mfi_cmd()
3580 mtx_lock(&sc->mpt_cmd_pool_lock); in mrsas_release_mfi_cmd()
3582 cmd_mpt = sc->mpt_cmd_list[cmd_mfi->cmd_id.context.smid-1]; in mrsas_release_mfi_cmd()
3585 TAILQ_INSERT_HEAD(&(sc->mrsas_mpt_cmd_list_head), cmd_mpt, next); in mrsas_release_mfi_cmd()
3586 mtx_unlock(&sc->mpt_cmd_pool_lock); in mrsas_release_mfi_cmd()
3591 TAILQ_INSERT_HEAD(&(sc->mrsas_mfi_cmd_list_head), cmd_mfi, next); in mrsas_release_mfi_cmd()
3592 mtx_unlock(&sc->mfi_cmd_pool_lock); in mrsas_release_mfi_cmd()
3607 mrsas_get_ctrl_info(struct mrsas_softc *sc) in mrsas_get_ctrl_info() argument
3614 cmd = mrsas_get_mfi_cmd(sc); in mrsas_get_ctrl_info()
3617 device_printf(sc->mrsas_dev, "Failed to get a free cmd\n"); in mrsas_get_ctrl_info()
3622 if (mrsas_alloc_ctlr_info_cmd(sc) != SUCCESS) { in mrsas_get_ctrl_info()
3623 device_printf(sc->mrsas_dev, "Cannot allocate get ctlr info cmd\n"); in mrsas_get_ctrl_info()
3637 dcmd->sgl.sge32[0].phys_addr = htole32(sc->ctlr_info_phys_addr & 0xFFFFFFFF); in mrsas_get_ctrl_info()
3640 if (!sc->mask_interrupts) in mrsas_get_ctrl_info()
3641 retcode = mrsas_issue_blocked_cmd(sc, cmd); in mrsas_get_ctrl_info()
3643 retcode = mrsas_issue_polled(sc, cmd); in mrsas_get_ctrl_info()
3648 memcpy(sc->ctrl_info, sc->ctlr_info_mem, sizeof(struct mrsas_ctrl_info)); in mrsas_get_ctrl_info()
3649 le32_to_cpus(&sc->ctrl_info->properties.OnOffProperties); in mrsas_get_ctrl_info()
3650 le32_to_cpus(&sc->ctrl_info->adapterOperations2); in mrsas_get_ctrl_info()
3651 le32_to_cpus(&sc->ctrl_info->adapterOperations3); in mrsas_get_ctrl_info()
3652 le16_to_cpus(&sc->ctrl_info->adapterOperations4); in mrsas_get_ctrl_info()
3656 mrsas_update_ext_vd_details(sc); in mrsas_get_ctrl_info()
3658 sc->use_seqnum_jbod_fp = in mrsas_get_ctrl_info()
3659 sc->ctrl_info->adapterOperations3.useSeqNumJbodFP; in mrsas_get_ctrl_info()
3660 sc->support_morethan256jbod = in mrsas_get_ctrl_info()
3661 sc->ctrl_info->adapterOperations4.supportPdMapTargetId; in mrsas_get_ctrl_info()
3663 sc->disableOnlineCtrlReset = in mrsas_get_ctrl_info()
3664 sc->ctrl_info->properties.OnOffProperties.disableOnlineCtrlReset; in mrsas_get_ctrl_info()
3667 mrsas_free_ctlr_info_cmd(sc); in mrsas_get_ctrl_info()
3670 sc->do_timedout_reset = MFI_DCMD_TIMEOUT_OCR; in mrsas_get_ctrl_info()
3672 if (!sc->mask_interrupts) in mrsas_get_ctrl_info()
3684 mrsas_update_ext_vd_details(struct mrsas_softc *sc) in mrsas_update_ext_vd_details() argument
3687 sc->max256vdSupport = in mrsas_update_ext_vd_details()
3688 sc->ctrl_info->adapterOperations3.supportMaxExtLDs; in mrsas_update_ext_vd_details()
3691 if (sc->ctrl_info->max_lds > 64) in mrsas_update_ext_vd_details()
3692 sc->max256vdSupport = 1; in mrsas_update_ext_vd_details()
3694 sc->drv_supported_vd_count = MRSAS_MAX_LD_CHANNELS in mrsas_update_ext_vd_details()
3696 sc->drv_supported_pd_count = MRSAS_MAX_PD_CHANNELS in mrsas_update_ext_vd_details()
3698 if (sc->max256vdSupport) { in mrsas_update_ext_vd_details()
3699 sc->fw_supported_vd_count = MAX_LOGICAL_DRIVES_EXT; in mrsas_update_ext_vd_details()
3700 sc->fw_supported_pd_count = MAX_PHYSICAL_DEVICES; in mrsas_update_ext_vd_details()
3702 sc->fw_supported_vd_count = MAX_LOGICAL_DRIVES; in mrsas_update_ext_vd_details()
3703 sc->fw_supported_pd_count = MAX_PHYSICAL_DEVICES; in mrsas_update_ext_vd_details()
3706 if (sc->maxRaidMapSize) { in mrsas_update_ext_vd_details()
3707 ventura_map_sz = sc->maxRaidMapSize * in mrsas_update_ext_vd_details()
3709 sc->current_map_sz = ventura_map_sz; in mrsas_update_ext_vd_details()
3710 sc->max_map_sz = ventura_map_sz; in mrsas_update_ext_vd_details()
3712 sc->old_map_sz = sizeof(MR_FW_RAID_MAP) + in mrsas_update_ext_vd_details()
3713 (sizeof(MR_LD_SPAN_MAP) * (sc->fw_supported_vd_count - 1)); in mrsas_update_ext_vd_details()
3714 sc->new_map_sz = sizeof(MR_FW_RAID_MAP_EXT); in mrsas_update_ext_vd_details()
3715 sc->max_map_sz = max(sc->old_map_sz, sc->new_map_sz); in mrsas_update_ext_vd_details()
3716 if (sc->max256vdSupport) in mrsas_update_ext_vd_details()
3717 sc->current_map_sz = sc->new_map_sz; in mrsas_update_ext_vd_details()
3719 sc->current_map_sz = sc->old_map_sz; in mrsas_update_ext_vd_details()
3722 sc->drv_map_sz = sizeof(MR_DRV_RAID_MAP_ALL); in mrsas_update_ext_vd_details()
3724 device_printf(sc->mrsas_dev, "sc->maxRaidMapSize 0x%x \n", in mrsas_update_ext_vd_details()
3725 sc->maxRaidMapSize); in mrsas_update_ext_vd_details()
3726 device_printf(sc->mrsas_dev, in mrsas_update_ext_vd_details()
3730 sc->new_map_sz, sc->old_map_sz, ventura_map_sz, in mrsas_update_ext_vd_details()
3731 sc->current_map_sz, sc->drv_map_sz, sizeof(MR_DRV_RAID_MAP_ALL)); in mrsas_update_ext_vd_details()
3742 mrsas_alloc_ctlr_info_cmd(struct mrsas_softc *sc) in mrsas_alloc_ctlr_info_cmd() argument
3748 if (bus_dma_tag_create(sc->mrsas_parent_tag, in mrsas_alloc_ctlr_info_cmd()
3758 &sc->ctlr_info_tag)) { in mrsas_alloc_ctlr_info_cmd()
3759 device_printf(sc->mrsas_dev, "Cannot allocate ctlr info tag\n"); in mrsas_alloc_ctlr_info_cmd()
3762 if (bus_dmamem_alloc(sc->ctlr_info_tag, (void **)&sc->ctlr_info_mem, in mrsas_alloc_ctlr_info_cmd()
3763 BUS_DMA_NOWAIT, &sc->ctlr_info_dmamap)) { in mrsas_alloc_ctlr_info_cmd()
3764 device_printf(sc->mrsas_dev, "Cannot allocate ctlr info cmd mem\n"); in mrsas_alloc_ctlr_info_cmd()
3767 if (bus_dmamap_load(sc->ctlr_info_tag, sc->ctlr_info_dmamap, in mrsas_alloc_ctlr_info_cmd()
3768 sc->ctlr_info_mem, ctlr_info_size, mrsas_addr_cb, in mrsas_alloc_ctlr_info_cmd()
3769 &sc->ctlr_info_phys_addr, BUS_DMA_NOWAIT)) { in mrsas_alloc_ctlr_info_cmd()
3770 device_printf(sc->mrsas_dev, "Cannot load ctlr info cmd mem\n"); in mrsas_alloc_ctlr_info_cmd()
3773 memset(sc->ctlr_info_mem, 0, ctlr_info_size); in mrsas_alloc_ctlr_info_cmd()
3784 mrsas_free_ctlr_info_cmd(struct mrsas_softc *sc) in mrsas_free_ctlr_info_cmd() argument
3786 if (sc->ctlr_info_phys_addr) in mrsas_free_ctlr_info_cmd()
3787 bus_dmamap_unload(sc->ctlr_info_tag, sc->ctlr_info_dmamap); in mrsas_free_ctlr_info_cmd()
3788 if (sc->ctlr_info_mem != NULL) in mrsas_free_ctlr_info_cmd()
3789 bus_dmamem_free(sc->ctlr_info_tag, sc->ctlr_info_mem, sc->ctlr_info_dmamap); in mrsas_free_ctlr_info_cmd()
3790 if (sc->ctlr_info_tag != NULL) in mrsas_free_ctlr_info_cmd()
3791 bus_dma_tag_destroy(sc->ctlr_info_tag); in mrsas_free_ctlr_info_cmd()
3804 mrsas_issue_polled(struct mrsas_softc *sc, struct mrsas_mfi_cmd *cmd) in mrsas_issue_polled() argument
3814 if (mrsas_issue_dcmd(sc, cmd)) { in mrsas_issue_polled()
3815 device_printf(sc->mrsas_dev, "Cannot issue DCMD internal command.\n"); in mrsas_issue_polled()
3832 device_printf(sc->mrsas_dev, "DCMD timed out after %d " in mrsas_issue_polled()
3834 device_printf(sc->mrsas_dev, "DCMD opcode 0x%X\n", in mrsas_issue_polled()
3850 mrsas_issue_dcmd(struct mrsas_softc *sc, struct mrsas_mfi_cmd *cmd) in mrsas_issue_dcmd() argument
3854 req_desc = mrsas_build_mpt_cmd(sc, cmd); in mrsas_issue_dcmd()
3856 device_printf(sc->mrsas_dev, "Cannot build MPT cmd.\n"); in mrsas_issue_dcmd()
3859 mrsas_fire_cmd(sc, req_desc->addr.u.low, req_desc->addr.u.high); in mrsas_issue_dcmd()
3872 mrsas_build_mpt_cmd(struct mrsas_softc *sc, struct mrsas_mfi_cmd *cmd) in mrsas_build_mpt_cmd() argument
3877 if (mrsas_build_mptmfi_passthru(sc, cmd)) { in mrsas_build_mpt_cmd()
3878 device_printf(sc->mrsas_dev, "Cannot build MPT-MFI passthru cmd.\n"); in mrsas_build_mpt_cmd()
3883 req_desc = mrsas_get_request_desc(sc, index - 1); in mrsas_build_mpt_cmd()
3903 mrsas_build_mptmfi_passthru(struct mrsas_softc *sc, struct mrsas_mfi_cmd *mfi_cmd) in mrsas_build_mptmfi_passthru() argument
3910 mpt_cmd = mrsas_get_mpt_cmd(sc); in mrsas_build_mptmfi_passthru()
3930 if (sc->mrsas_gen3_ctrl || sc->is_ventura || sc->is_aero) { in mrsas_build_mptmfi_passthru()
3933 sgl_ptr_end += sc->max_sge_in_main_msg - 1; in mrsas_build_mptmfi_passthru()
3940 io_req->ChainOffset = sc->chain_offset_mfi_pthru; in mrsas_build_mptmfi_passthru()
3947 mpi25_ieee_chain->Length = htole32(sc->max_chain_frame_sz); in mrsas_build_mptmfi_passthru()
3961 mrsas_issue_blocked_cmd(struct mrsas_softc *sc, struct mrsas_mfi_cmd *cmd) in mrsas_issue_blocked_cmd() argument
3971 if (mrsas_issue_dcmd(sc, cmd)) { in mrsas_issue_blocked_cmd()
3972 device_printf(sc->mrsas_dev, "Cannot issue DCMD internal command.\n"); in mrsas_issue_blocked_cmd()
3975 sc->chan = (void *)&cmd; in mrsas_issue_blocked_cmd()
3979 tsleep((void *)&sc->chan, 0, "mrsas_sleep", hz); in mrsas_issue_blocked_cmd()
3987 device_printf(sc->mrsas_dev, in mrsas_issue_blocked_cmd()
3994 sc->chan = NULL; in mrsas_issue_blocked_cmd()
3997 device_printf(sc->mrsas_dev, "DCMD timed out after %d " in mrsas_issue_blocked_cmd()
3999 device_printf(sc->mrsas_dev, "DCMD opcode 0x%X\n", in mrsas_issue_blocked_cmd()
4017 mrsas_complete_mptmfi_passthru(struct mrsas_softc *sc, struct mrsas_mfi_cmd *cmd, in mrsas_complete_mptmfi_passthru() argument
4031 device_printf(sc->mrsas_dev, "MFI_CMD_INVALID command.\n"); in mrsas_complete_mptmfi_passthru()
4042 mrsas_wakeup(sc, cmd); in mrsas_complete_mptmfi_passthru()
4051 sc->fast_path_io = 0; in mrsas_complete_mptmfi_passthru()
4052 mtx_lock(&sc->raidmap_lock); in mrsas_complete_mptmfi_passthru()
4053 sc->map_update_cmd = NULL; in mrsas_complete_mptmfi_passthru()
4056 device_printf(sc->mrsas_dev, "map sync failed, status=%x\n", cmd_status); in mrsas_complete_mptmfi_passthru()
4059 mtx_unlock(&sc->raidmap_lock); in mrsas_complete_mptmfi_passthru()
4063 sc->map_id++; in mrsas_complete_mptmfi_passthru()
4065 if (MR_ValidateMapInfo(sc)) in mrsas_complete_mptmfi_passthru()
4066 sc->fast_path_io = 0; in mrsas_complete_mptmfi_passthru()
4068 sc->fast_path_io = 1; in mrsas_complete_mptmfi_passthru()
4069 mrsas_sync_map_info(sc); in mrsas_complete_mptmfi_passthru()
4070 mtx_unlock(&sc->raidmap_lock); in mrsas_complete_mptmfi_passthru()
4075 sc->mrsas_aen_triggered = 0; in mrsas_complete_mptmfi_passthru()
4081 mtx_lock(&sc->raidmap_lock); in mrsas_complete_mptmfi_passthru()
4082 sc->jbod_seq_cmd = NULL; in mrsas_complete_mptmfi_passthru()
4086 sc->pd_seq_map_id++; in mrsas_complete_mptmfi_passthru()
4088 if (megasas_sync_pd_seq_num(sc, true)) in mrsas_complete_mptmfi_passthru()
4089 sc->use_seqnum_jbod_fp = 0; in mrsas_complete_mptmfi_passthru()
4091 sc->use_seqnum_jbod_fp = 0; in mrsas_complete_mptmfi_passthru()
4092 device_printf(sc->mrsas_dev, in mrsas_complete_mptmfi_passthru()
4095 mtx_unlock(&sc->raidmap_lock); in mrsas_complete_mptmfi_passthru()
4100 mrsas_complete_aen(sc, cmd); in mrsas_complete_mptmfi_passthru()
4102 mrsas_wakeup(sc, cmd); in mrsas_complete_mptmfi_passthru()
4106 mrsas_complete_abort(sc, cmd); in mrsas_complete_mptmfi_passthru()
4109 device_printf(sc->mrsas_dev, "Unknown command completed! [0x%X]\n", hdr->cmd); in mrsas_complete_mptmfi_passthru()
4125 mrsas_wakeup(struct mrsas_softc *sc, struct mrsas_mfi_cmd *cmd) in mrsas_wakeup() argument
4132 sc->chan = (void *)&cmd; in mrsas_wakeup()
4133 wakeup_one((void *)&sc->chan); in mrsas_wakeup()
4145 mrsas_shutdown_ctlr(struct mrsas_softc *sc, u_int32_t opcode) in mrsas_shutdown_ctlr() argument
4150 if (sc->adprecovery == MRSAS_HW_CRITICAL_ERROR) in mrsas_shutdown_ctlr()
4153 cmd = mrsas_get_mfi_cmd(sc); in mrsas_shutdown_ctlr()
4155 device_printf(sc->mrsas_dev, "Cannot allocate for shutdown cmd.\n"); in mrsas_shutdown_ctlr()
4158 if (sc->aen_cmd) in mrsas_shutdown_ctlr()
4159 mrsas_issue_blocked_abort_cmd(sc, sc->aen_cmd); in mrsas_shutdown_ctlr()
4160 if (sc->map_update_cmd) in mrsas_shutdown_ctlr()
4161 mrsas_issue_blocked_abort_cmd(sc, sc->map_update_cmd); in mrsas_shutdown_ctlr()
4162 if (sc->jbod_seq_cmd) in mrsas_shutdown_ctlr()
4163 mrsas_issue_blocked_abort_cmd(sc, sc->jbod_seq_cmd); in mrsas_shutdown_ctlr()
4177 device_printf(sc->mrsas_dev, "Preparing to shut down controller.\n"); in mrsas_shutdown_ctlr()
4179 mrsas_issue_blocked_cmd(sc, cmd); in mrsas_shutdown_ctlr()
4193 mrsas_flush_cache(struct mrsas_softc *sc) in mrsas_flush_cache() argument
4198 if (sc->adprecovery == MRSAS_HW_CRITICAL_ERROR) in mrsas_flush_cache()
4201 cmd = mrsas_get_mfi_cmd(sc); in mrsas_flush_cache()
4203 device_printf(sc->mrsas_dev, "Cannot allocate for flush cache cmd.\n"); in mrsas_flush_cache()
4219 mrsas_issue_blocked_cmd(sc, cmd); in mrsas_flush_cache()
4226 megasas_sync_pd_seq_num(struct mrsas_softc *sc, boolean_t pend) in megasas_sync_pd_seq_num() argument
4240 cmd = mrsas_get_mfi_cmd(sc); in megasas_sync_pd_seq_num()
4242 device_printf(sc->mrsas_dev, in megasas_sync_pd_seq_num()
4248 pd_sync = (void *)sc->jbodmap_mem[(sc->pd_seq_map_id & 1)]; in megasas_sync_pd_seq_num()
4249 pd_seq_h = sc->jbodmap_phys_addr[(sc->pd_seq_map_id & 1)]; in megasas_sync_pd_seq_num()
4251 device_printf(sc->mrsas_dev, in megasas_sync_pd_seq_num()
4271 sc->jbod_seq_cmd = cmd; in megasas_sync_pd_seq_num()
4272 if (mrsas_issue_dcmd(sc, cmd)) { in megasas_sync_pd_seq_num()
4273 device_printf(sc->mrsas_dev, in megasas_sync_pd_seq_num()
4281 retcode = mrsas_issue_polled(sc, cmd); in megasas_sync_pd_seq_num()
4286 device_printf(sc->mrsas_dev, in megasas_sync_pd_seq_num()
4292 sc->pd_seq_map_id++; in megasas_sync_pd_seq_num()
4297 sc->do_timedout_reset = MFI_DCMD_TIMEOUT_OCR; in megasas_sync_pd_seq_num()
4310 mrsas_get_map_info(struct mrsas_softc *sc) in mrsas_get_map_info() argument
4314 sc->fast_path_io = 0; in mrsas_get_map_info()
4315 if (!mrsas_get_ld_map_info(sc)) { in mrsas_get_map_info()
4316 retcode = MR_ValidateMapInfo(sc); in mrsas_get_map_info()
4318 sc->fast_path_io = 1; in mrsas_get_map_info()
4333 mrsas_get_ld_map_info(struct mrsas_softc *sc) in mrsas_get_ld_map_info() argument
4341 cmd = mrsas_get_mfi_cmd(sc); in mrsas_get_ld_map_info()
4343 device_printf(sc->mrsas_dev, in mrsas_get_ld_map_info()
4349 map = (void *)sc->raidmap_mem[(sc->map_id & 1)]; in mrsas_get_ld_map_info()
4350 map_phys_addr = sc->raidmap_phys_addr[(sc->map_id & 1)]; in mrsas_get_ld_map_info()
4352 device_printf(sc->mrsas_dev, in mrsas_get_ld_map_info()
4357 memset(map, 0, sizeof(sc->max_map_sz)); in mrsas_get_ld_map_info()
4366 dcmd->data_xfer_len = htole32(sc->current_map_sz); in mrsas_get_ld_map_info()
4369 dcmd->sgl.sge32[0].length = htole32(sc->current_map_sz); in mrsas_get_ld_map_info()
4371 retcode = mrsas_issue_polled(sc, cmd); in mrsas_get_ld_map_info()
4373 sc->do_timedout_reset = MFI_DCMD_TIMEOUT_OCR; in mrsas_get_ld_map_info()
4386 mrsas_sync_map_info(struct mrsas_softc *sc) in mrsas_sync_map_info() argument
4398 cmd = mrsas_get_mfi_cmd(sc); in mrsas_sync_map_info()
4400 device_printf(sc->mrsas_dev, "Cannot alloc for sync map info cmd\n"); in mrsas_sync_map_info()
4403 map = sc->ld_drv_map[sc->map_id & 1]; in mrsas_sync_map_info()
4409 target_map = (MR_LD_TARGET_SYNC *) sc->raidmap_mem[(sc->map_id - 1) & 1]; in mrsas_sync_map_info()
4410 memset(target_map, 0, sc->max_map_sz); in mrsas_sync_map_info()
4412 map_phys_addr = sc->raidmap_phys_addr[(sc->map_id - 1) & 1]; in mrsas_sync_map_info()
4428 dcmd->data_xfer_len = htole32(sc->current_map_sz); in mrsas_sync_map_info()
4433 dcmd->sgl.sge32[0].length = htole32(sc->current_map_sz); in mrsas_sync_map_info()
4435 sc->map_update_cmd = cmd; in mrsas_sync_map_info()
4436 if (mrsas_issue_dcmd(sc, cmd)) { in mrsas_sync_map_info()
4437 device_printf(sc->mrsas_dev, in mrsas_sync_map_info()
4451 mrsas_get_pd_info(struct mrsas_softc *sc, u_int16_t device_id) in mrsas_get_pd_info() argument
4458 cmd = mrsas_get_mfi_cmd(sc); in mrsas_get_pd_info()
4461 device_printf(sc->mrsas_dev, in mrsas_get_pd_info()
4467 memset(sc->pd_info_mem, 0, sizeof(struct mrsas_pd_info)); in mrsas_get_pd_info()
4479 dcmd->sgl.sge32[0].phys_addr = htole32((u_int32_t)sc->pd_info_phys_addr & 0xFFFFFFFF); in mrsas_get_pd_info()
4482 if (!sc->mask_interrupts) in mrsas_get_pd_info()
4483 retcode = mrsas_issue_blocked_cmd(sc, cmd); in mrsas_get_pd_info()
4485 retcode = mrsas_issue_polled(sc, cmd); in mrsas_get_pd_info()
4490 sc->target_list[device_id].interface_type = in mrsas_get_pd_info()
4491 le16toh(sc->pd_info_mem->state.ddf.pdType.intf); in mrsas_get_pd_info()
4498 sc->do_timedout_reset = MFI_DCMD_TIMEOUT_OCR; in mrsas_get_pd_info()
4500 if (!sc->mask_interrupts) in mrsas_get_pd_info()
4513 static void mrsas_add_target(struct mrsas_softc *sc, in mrsas_add_target() argument
4516 sc->target_list[target_id].target_id = target_id; in mrsas_add_target()
4518 device_printf(sc->mrsas_dev, in mrsas_add_target()
4526 if (!sc->mask_interrupts && sc->pd_info_mem && in mrsas_add_target()
4528 mrsas_get_pd_info(sc, target_id); in mrsas_add_target()
4541 static void mrsas_remove_target(struct mrsas_softc *sc, in mrsas_remove_target() argument
4544 sc->target_list[target_id].target_id = 0xffff; in mrsas_remove_target()
4545 device_printf(sc->mrsas_dev, in mrsas_remove_target()
4560 mrsas_get_pd_list(struct mrsas_softc *sc) in mrsas_get_pd_list() argument
4572 cmd = mrsas_get_mfi_cmd(sc); in mrsas_get_pd_list()
4574 device_printf(sc->mrsas_dev, in mrsas_get_pd_list()
4582 if (mrsas_alloc_tmp_dcmd(sc, tcmd, pd_list_size) != SUCCESS) { in mrsas_get_pd_list()
4583 device_printf(sc->mrsas_dev, in mrsas_get_pd_list()
4608 if (!sc->mask_interrupts) in mrsas_get_pd_list()
4609 retcode = mrsas_issue_blocked_cmd(sc, cmd); in mrsas_get_pd_list()
4611 retcode = mrsas_issue_polled(sc, cmd); in mrsas_get_pd_list()
4620 memset(sc->local_pd_list, 0, in mrsas_get_pd_list()
4624 sc->local_pd_list[dev_id].tid = dev_id; in mrsas_get_pd_list()
4625 sc->local_pd_list[dev_id].driveType = in mrsas_get_pd_list()
4627 sc->local_pd_list[dev_id].driveState = in mrsas_get_pd_list()
4629 if (sc->target_list[dev_id].target_id == 0xffff) in mrsas_get_pd_list()
4630 mrsas_add_target(sc, dev_id); in mrsas_get_pd_list()
4634 if ((sc->local_pd_list[pd_index].driveState != in mrsas_get_pd_list()
4636 (sc->target_list[pd_index].target_id != in mrsas_get_pd_list()
4638 mrsas_remove_target(sc, pd_index); in mrsas_get_pd_list()
4645 memcpy(sc->pd_list, sc->local_pd_list, sizeof(sc->local_pd_list)); in mrsas_get_pd_list()
4653 sc->do_timedout_reset = MFI_DCMD_TIMEOUT_OCR; in mrsas_get_pd_list()
4655 if (!sc->mask_interrupts) in mrsas_get_pd_list()
4670 mrsas_get_ld_list(struct mrsas_softc *sc) in mrsas_get_ld_list() argument
4680 cmd = mrsas_get_mfi_cmd(sc); in mrsas_get_ld_list()
4682 device_printf(sc->mrsas_dev, in mrsas_get_ld_list()
4690 if (mrsas_alloc_tmp_dcmd(sc, tcmd, ld_list_size) != SUCCESS) { in mrsas_get_ld_list()
4691 device_printf(sc->mrsas_dev, in mrsas_get_ld_list()
4703 if (sc->max256vdSupport) in mrsas_get_ld_list()
4717 if (!sc->mask_interrupts) in mrsas_get_ld_list()
4718 retcode = mrsas_issue_blocked_cmd(sc, cmd); in mrsas_get_ld_list()
4720 retcode = mrsas_issue_polled(sc, cmd); in mrsas_get_ld_list()
4730 if (le32toh(ld_list_mem->ldCount) <= sc->fw_supported_vd_count) { in mrsas_get_ld_list()
4731 sc->CurLdCount = le32toh(ld_list_mem->ldCount); in mrsas_get_ld_list()
4732 memset(sc->ld_ids, 0xff, MAX_LOGICAL_DRIVES_EXT); in mrsas_get_ld_list()
4737 sc->ld_ids[ids] = ld_list_mem->ldList[ld_index].ref.ld_context.targetId; in mrsas_get_ld_list()
4738 if (sc->target_list[drv_tgt_id].target_id == in mrsas_get_ld_list()
4740 mrsas_add_target(sc, drv_tgt_id); in mrsas_get_ld_list()
4742 if (sc->target_list[drv_tgt_id].target_id != in mrsas_get_ld_list()
4744 mrsas_remove_target(sc, in mrsas_get_ld_list()
4756 sc->do_timedout_reset = MFI_DCMD_TIMEOUT_OCR; in mrsas_get_ld_list()
4757 if (!sc->mask_interrupts) in mrsas_get_ld_list()
4772 mrsas_alloc_tmp_dcmd(struct mrsas_softc *sc, in mrsas_alloc_tmp_dcmd() argument
4775 if (bus_dma_tag_create(sc->mrsas_parent_tag, in mrsas_alloc_tmp_dcmd()
4786 device_printf(sc->mrsas_dev, "Cannot allocate tmp dcmd tag\n"); in mrsas_alloc_tmp_dcmd()
4791 device_printf(sc->mrsas_dev, "Cannot allocate tmp dcmd mem\n"); in mrsas_alloc_tmp_dcmd()
4797 device_printf(sc->mrsas_dev, "Cannot load tmp dcmd mem\n"); in mrsas_alloc_tmp_dcmd()
4832 mrsas_issue_blocked_abort_cmd(struct mrsas_softc *sc, in mrsas_issue_blocked_abort_cmd() argument
4841 cmd = mrsas_get_mfi_cmd(sc); in mrsas_issue_blocked_abort_cmd()
4843 device_printf(sc->mrsas_dev, "Cannot alloc for abort cmd\n"); in mrsas_issue_blocked_abort_cmd()
4859 if (mrsas_issue_dcmd(sc, cmd)) { in mrsas_issue_blocked_abort_cmd()
4860 device_printf(sc->mrsas_dev, "Fail to send abort command.\n"); in mrsas_issue_blocked_abort_cmd()
4864 sc->chan = (void *)&cmd; in mrsas_issue_blocked_abort_cmd()
4867 tsleep((void *)&sc->chan, 0, "mrsas_sleep", hz); in mrsas_issue_blocked_abort_cmd()
4872 device_printf(sc->mrsas_dev, "Abort cmd timed out after %d sec.\n", max_wait); in mrsas_issue_blocked_abort_cmd()
4892 mrsas_complete_abort(struct mrsas_softc *sc, struct mrsas_mfi_cmd *cmd) in mrsas_complete_abort() argument
4897 sc->chan = (void *)&cmd; in mrsas_complete_abort()
4898 wakeup_one((void *)&sc->chan); in mrsas_complete_abort()
4910 mrsas_aen_handler(struct mrsas_softc *sc) in mrsas_aen_handler() argument
4917 if (sc == NULL) { in mrsas_aen_handler()
4921 if (sc->remove_in_progress || sc->reset_in_progress) { in mrsas_aen_handler()
4922 device_printf(sc->mrsas_dev, "Returning from %s, line no %d\n", in mrsas_aen_handler()
4926 if (sc->evt_detail_mem) { in mrsas_aen_handler()
4927 switch (sc->evt_detail_mem->code) { in mrsas_aen_handler()
4929 fail_aen = mrsas_get_pd_list(sc); in mrsas_aen_handler()
4931 mrsas_bus_scan_sim(sc, sc->sim_1); in mrsas_aen_handler()
4936 fail_aen = mrsas_get_pd_list(sc); in mrsas_aen_handler()
4938 mrsas_bus_scan_sim(sc, sc->sim_1); in mrsas_aen_handler()
4945 mrsas_bus_scan_sim(sc, sc->sim_0); in mrsas_aen_handler()
4948 fail_aen = mrsas_get_ld_list(sc); in mrsas_aen_handler()
4950 mrsas_bus_scan_sim(sc, sc->sim_0); in mrsas_aen_handler()
4960 fail_aen = mrsas_get_ctrl_info(sc); in mrsas_aen_handler()
4968 device_printf(sc->mrsas_dev, "invalid evt_detail\n"); in mrsas_aen_handler()
4972 fail_aen = mrsas_get_pd_list(sc); in mrsas_aen_handler()
4974 mrsas_dprint(sc, MRSAS_AEN, "scanning ...sim 1\n"); in mrsas_aen_handler()
4975 mrsas_bus_scan_sim(sc, sc->sim_1); in mrsas_aen_handler()
4979 fail_aen = mrsas_get_ld_list(sc); in mrsas_aen_handler()
4981 mrsas_dprint(sc, MRSAS_AEN, "scanning ...sim 0\n"); in mrsas_aen_handler()
4982 mrsas_bus_scan_sim(sc, sc->sim_0); in mrsas_aen_handler()
4986 seq_num = sc->evt_detail_mem->seq_num + 1; in mrsas_aen_handler()
4993 if (sc->aen_cmd != NULL) in mrsas_aen_handler()
4996 mtx_lock(&sc->aen_lock); in mrsas_aen_handler()
4997 error = mrsas_register_aen(sc, seq_num, in mrsas_aen_handler()
4999 mtx_unlock(&sc->aen_lock); in mrsas_aen_handler()
5002 device_printf(sc->mrsas_dev, "register aen failed error %x\n", error); in mrsas_aen_handler()
5019 mrsas_complete_aen(struct mrsas_softc *sc, struct mrsas_mfi_cmd *cmd) in mrsas_complete_aen() argument
5025 if ((!cmd->abort_aen) && (sc->remove_in_progress == 0)) { in mrsas_complete_aen()
5026 sc->mrsas_aen_triggered = 1; in mrsas_complete_aen()
5027 mtx_lock(&sc->aen_lock); in mrsas_complete_aen()
5028 if (sc->mrsas_poll_waiting) { in mrsas_complete_aen()
5029 sc->mrsas_poll_waiting = 0; in mrsas_complete_aen()
5030 selwakeup(&sc->mrsas_select); in mrsas_complete_aen()
5032 mtx_unlock(&sc->aen_lock); in mrsas_complete_aen()
5036 sc->aen_cmd = NULL; in mrsas_complete_aen()
5039 taskqueue_enqueue(sc->ev_tq, &sc->ev_task); in mrsas_complete_aen()