Lines Matching +full:timer +full:- +full:cannot +full:- +full:wake +full:- +full:cpu
205 {0x1000, MRSAS_AERO_10E0, 0xffff, 0xffff, "BROADCOM AERO-10E0 SAS Controller"},
206 {0x1000, MRSAS_AERO_10E1, 0xffff, 0xffff, "BROADCOM AERO-10E1 SAS Controller"},
207 {0x1000, MRSAS_AERO_10E2, 0xffff, 0xffff, "BROADCOM AERO-10E2 SAS Controller"},
208 {0x1000, MRSAS_AERO_10E3, 0xffff, 0xffff, "BROADCOM AERO-10E3 SAS Controller"},
209 {0x1000, MRSAS_AERO_10E4, 0xffff, 0xffff, "BROADCOM AERO-10E4 SAS Controller"},
210 {0x1000, MRSAS_AERO_10E5, 0xffff, 0xffff, "BROADCOM AERO-10E5 SAS Controller"},
211 {0x1000, MRSAS_AERO_10E6, 0xffff, 0xffff, "BROADCOM AERO-10E6 SAS Controller"},
212 {0x1000, MRSAS_AERO_10E7, 0xffff, 0xffff, "BROADCOM AERO-10E7 SAS Controller"},
250 if (sc->is_aero) { in mrsas_read_reg_with_retries()
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()
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()
293 sc->mask_interrupts = 1; in mrsas_disable_intr()
304 sc->mask_interrupts = 0; in mrsas_enable_intr()
337 for (pci_device = device_table; pci_device->vendor != 0; pci_device++) { in mrsas_find_ident()
338 if ((pci_device->vendor == pci_get_vendor(dev)) && in mrsas_find_ident()
339 (pci_device->device == pci_get_device(dev)) && in mrsas_find_ident()
340 ((pci_device->subvendor == pci_get_subvendor(dev)) || in mrsas_find_ident()
341 (pci_device->subvendor == 0xffff)) && in mrsas_find_ident()
342 ((pci_device->subdevice == pci_get_subdevice(dev)) || in mrsas_find_ident()
343 (pci_device->subdevice == 0xffff))) in mrsas_find_ident()
361 device_set_desc(dev, id->desc); in mrsas_probe()
363 return (-30); in mrsas_probe()
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()
429 0, "Driver IO timeout value in mili-second."); 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()
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()
487 /* Grab the unit-instance variables */ 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()
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()
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()
558 * Firmware maintains a log of all events in a non-volatile area.
574 device_printf(sc->mrsas_dev, "Failed to get a free cmd\n"); in mrsas_get_seq_num()
575 return -ENOMEM; in mrsas_get_seq_num()
577 dcmd = &cmd->frame->dcmd; in mrsas_get_seq_num()
580 device_printf(sc->mrsas_dev, "Cannot allocate evt log info cmd\n"); in mrsas_get_seq_num()
582 return -ENOMEM; in mrsas_get_seq_num()
584 memset(dcmd->mbox.b, 0, MFI_MBOX_SIZE); in mrsas_get_seq_num()
586 dcmd->cmd = MFI_CMD_DCMD; in mrsas_get_seq_num()
587 dcmd->cmd_status = 0x0; in mrsas_get_seq_num()
588 dcmd->sge_count = 1; in mrsas_get_seq_num()
589 dcmd->flags = htole16(MFI_FRAME_DIR_READ); in mrsas_get_seq_num()
590 dcmd->timeout = 0; in mrsas_get_seq_num()
591 dcmd->pad_0 = 0; in mrsas_get_seq_num()
592 dcmd->data_xfer_len = htole32(sizeof(struct mrsas_evt_log_info)); in mrsas_get_seq_num()
593 dcmd->opcode = htole32(MR_DCMD_CTRL_EVENT_GET_INFO); in mrsas_get_seq_num()
594 dcmd->sgl.sge32[0].phys_addr = htole32(sc->el_info_phys_addr & 0xFFFFFFFF); in mrsas_get_seq_num()
595 dcmd->sgl.sge32[0].length = htole32(sizeof(struct mrsas_evt_log_info)); in mrsas_get_seq_num()
605 memcpy(eli, sc->el_info_mem, sizeof(struct mrsas_evt_log_info)); in mrsas_get_seq_num()
610 sc->do_timedout_reset = MFI_DCMD_TIMEOUT_OCR; in mrsas_get_seq_num()
644 * class_locale that is superset of both old and current and re-issue in mrsas_register_aen()
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()
655 * higher values. If a PROGRESS (= -1) was previously in mrsas_register_aen()
675 sc->aen_cmd->abort_aen = 1; in mrsas_register_aen()
677 sc->aen_cmd); in mrsas_register_aen()
683 sc->aen_cmd = NULL; in mrsas_register_aen()
690 dcmd = &cmd->frame->dcmd; in mrsas_register_aen()
692 memset(sc->evt_detail_mem, 0, sizeof(struct mrsas_evt_detail)); in mrsas_register_aen()
697 memset(dcmd->mbox.b, 0, MFI_MBOX_SIZE); in mrsas_register_aen()
699 dcmd->cmd = MFI_CMD_DCMD; in mrsas_register_aen()
700 dcmd->cmd_status = 0x0; in mrsas_register_aen()
701 dcmd->sge_count = 1; in mrsas_register_aen()
702 dcmd->flags = htole16(MFI_FRAME_DIR_READ); in mrsas_register_aen()
703 dcmd->timeout = 0; in mrsas_register_aen()
704 dcmd->pad_0 = 0; in mrsas_register_aen()
705 dcmd->data_xfer_len = htole32(sizeof(struct mrsas_evt_detail)); in mrsas_register_aen()
706 dcmd->opcode = htole32(MR_DCMD_CTRL_EVENT_WAIT); in mrsas_register_aen()
707 dcmd->mbox.w[0] = htole32(seq_num); in mrsas_register_aen()
708 sc->last_seq_num = seq_num; in mrsas_register_aen()
709 dcmd->mbox.w[1] = htole32(curr_aen.word); 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()
711 dcmd->sgl.sge32[0].length = htole32(sizeof(struct mrsas_evt_detail)); in mrsas_register_aen()
713 if (sc->aen_cmd != NULL) { in mrsas_register_aen()
720 * cmd and re-register with a new EVENT LOCALE supplied by that app in mrsas_register_aen()
722 sc->aen_cmd = cmd; in mrsas_register_aen()
728 device_printf(sc->mrsas_dev, "Cannot issue AEN DCMD command.\n"); in mrsas_register_aen()
749 return -1; in mrsas_start_aen()
762 * mrsas_setup_msix: Allocate MSI-x vectors
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()
787 "Cannot set up MSI-x interrupt handler\n"); in mrsas_setup_msix()
799 * mrsas_allocate_msix: Setup MSI-x vectors
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()
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()
867 device_printf(dev, "Adapter is in non-secure mode\n"); 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()
890 device_printf(dev, "Cannot allocate PCI registers\n"); 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()
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()
955 if (sc->ocr_thread_active) in mrsas_attach()
956 wakeup(&sc->ocr_chan); in mrsas_attach()
963 if (sc->msix_enable == 1) in mrsas_attach()
964 pci_release_msi(sc->mrsas_dev); 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()
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()
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()
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()
1048 * mrsas_detach: De-allocates and teardown resources
1052 * It performs memory de-allocations, shutdown of the controller and various
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()
1075 mrsas_mgmt_info.count--; 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()
1092 while (sc->ocr_thread_active) { in mrsas_detach()
1098 sc->ocr_thread_active); 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()
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()
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()
1164 if (sc->reset_in_progress) { in mrsas_shutdown()
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()
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()
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()
1406 * do not provide host_no. Use cdev->si_drv1 to get softc instance for those
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()
1427 user_ioc->host_no); in mrsas_get_softc_instance()
1428 else if (user_ioc->host_no >= mrsas_mgmt_info.max_index) in mrsas_get_softc_instance()
1430 "Invalid Controller number %d\n", user_ioc->host_no); in mrsas_get_softc_instance()
1452 sc = (struct mrsas_softc *)(dev->si_drv1); in mrsas_ioctl()
1461 if (sc->remove_in_progress || in mrsas_ioctl()
1462 (sc->adprecovery == MRSAS_HW_CRITICAL_ERROR)) { 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()
1493 sema_wait(&sc->ioctl_count_sema); in mrsas_ioctl()
1498 sema_post(&sc->ioctl_count_sema); 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()
1515 pciDrvInfo->busNumber, pciDrvInfo->deviceNumber, in mrsas_ioctl()
1516 pciDrvInfo->functionNumber, pciDrvInfo->domainID); in mrsas_ioctl()
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()
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()
1614 if (sc->mask_interrupts) in mrsas_isr()
1617 if (!sc->msix_vectors) { in mrsas_isr()
1623 if (mrsas_test_bit(MRSAS_FUSION_IN_RESET, &sc->reset_flags)) { in mrsas_isr()
1629 if (mrsas_complete_cmd(sc, irq_context->MSIxIndex) != SUCCESS) in mrsas_isr()
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()
1676 desc_val.word = desc->Words; in mrsas_complete_cmd()
1679 reply_descript_type = reply_desc->ReplyFlags & MPI2_RPY_DESCRIPT_FLAGS_TYPE_MASK; in mrsas_complete_cmd()
1683 smid = le16toh(reply_desc->SMID); in mrsas_complete_cmd()
1684 cmd_mpt = sc->mpt_cmd_list[smid - 1]; in mrsas_complete_cmd()
1685 scsi_io_req = (MRSAS_RAID_SCSI_IO_REQUEST *) cmd_mpt->io_request; in mrsas_complete_cmd()
1687 status = scsi_io_req->RaidContext.raid_context.status; in mrsas_complete_cmd()
1688 extStatus = scsi_io_req->RaidContext.raid_context.exStatus; in mrsas_complete_cmd()
1689 sense = cmd_mpt->sense; in mrsas_complete_cmd()
1690 data_length = scsi_io_req->DataLength; in mrsas_complete_cmd()
1692 switch (scsi_io_req->Function) { in mrsas_complete_cmd()
1695 mr_tm_req = (MR_TASK_MANAGE_REQUEST *) cmd_mpt->io_request; in mrsas_complete_cmd()
1697 &mr_tm_req->TmRequest; in mrsas_complete_cmd()
1698 device_printf(sc->mrsas_dev, "TM completion type 0x%X, " in mrsas_complete_cmd()
1699 "TaskMID: 0x%X", mpi_tm_req->TaskType, mpi_tm_req->TaskMID); in mrsas_complete_cmd()
1701 wakeup_one((void *)&sc->ocr_chan); in mrsas_complete_cmd()
1704 device_id = cmd_mpt->ccb_ptr->ccb_h.target_id; in mrsas_complete_cmd()
1705 lbinfo = &sc->load_balance_info[device_id]; in mrsas_complete_cmd()
1707 if (cmd_mpt->load_balance == MRSAS_LOAD_BALANCE_FLAG) { in mrsas_complete_cmd()
1708 mrsas_atomic_dec(&lbinfo->scsi_pending_cmds[cmd_mpt->pd_r1_lb]); in mrsas_complete_cmd()
1709 cmd_mpt->load_balance &= ~MRSAS_LOAD_BALANCE_FLAG; in mrsas_complete_cmd()
1713 if (cmd_mpt->r1_alt_dev_handle == MR_DEVHANDLE_INVALID) { in mrsas_complete_cmd()
1714 mrsas_map_mpt_cmd_status(cmd_mpt, cmd_mpt->ccb_ptr, status, in mrsas_complete_cmd()
1717 mrsas_atomic_dec(&sc->fw_outstanding); in mrsas_complete_cmd()
1726 cmd_mpt->cmd_completed = 1; in mrsas_complete_cmd()
1727 r1_cmd = cmd_mpt->peer_cmd; in mrsas_complete_cmd()
1728 if (r1_cmd->cmd_completed) { in mrsas_complete_cmd()
1729 if (r1_cmd->io_request->RaidContext.raid_context.status != MFI_STAT_OK) { in mrsas_complete_cmd()
1730 status = r1_cmd->io_request->RaidContext.raid_context.status; in mrsas_complete_cmd()
1731 extStatus = r1_cmd->io_request->RaidContext.raid_context.exStatus; in mrsas_complete_cmd()
1732 data_length = r1_cmd->io_request->DataLength; in mrsas_complete_cmd()
1733 sense = r1_cmd->sense; in mrsas_complete_cmd()
1735 mtx_lock(&sc->sim_lock); in mrsas_complete_cmd()
1736 r1_cmd->ccb_ptr = NULL; in mrsas_complete_cmd()
1737 if (r1_cmd->callout_owner) { in mrsas_complete_cmd()
1738 callout_stop(&r1_cmd->cm_callout); in mrsas_complete_cmd()
1739 r1_cmd->callout_owner = false; 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()
1744 mrsas_map_mpt_cmd_status(cmd_mpt, cmd_mpt->ccb_ptr, status, 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()
1759 if (cmd_mfi->frame->hdr.flags & htole16(MFI_FRAME_DONT_POST_IN_REPLY_QUEUE)) 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()
1770 desc->Words = ~((uint64_t)0x00); /* set it back to all 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()
1783 desc_val.word = desc->Words; in mrsas_complete_cmd()
1785 reply_descript_type = reply_desc->ReplyFlags & MPI2_RPY_DESCRIPT_FLAGS_TYPE_MASK; 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()
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()
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()
1849 ccb_ptr->ccb_h.status = CAM_REQ_CMP; in mrsas_map_mpt_cmd_status()
1853 ccb_ptr->ccb_h.status = CAM_SCSI_STATUS_ERROR; in mrsas_map_mpt_cmd_status()
1854 sense_data = (u_int8_t *)&ccb_ptr->csio.sense_data; in mrsas_map_mpt_cmd_status()
1858 ccb_ptr->csio.sense_len = 18; in mrsas_map_mpt_cmd_status()
1859 ccb_ptr->ccb_h.status |= CAM_AUTOSNS_VALID; in mrsas_map_mpt_cmd_status()
1864 if (ccb_ptr->ccb_h.target_lun) in mrsas_map_mpt_cmd_status()
1865 ccb_ptr->ccb_h.status |= CAM_LUN_INVALID; in mrsas_map_mpt_cmd_status()
1867 ccb_ptr->ccb_h.status |= CAM_DEV_NOT_THERE; in mrsas_map_mpt_cmd_status()
1870 ccb_ptr->ccb_h.status |= CAM_REQUEUE_REQ; in mrsas_map_mpt_cmd_status()
1873 device_printf(sc->mrsas_dev, "FW cmd complete status %x\n", status); in mrsas_map_mpt_cmd_status()
1874 ccb_ptr->ccb_h.status = CAM_REQ_CMP_ERR; in mrsas_map_mpt_cmd_status()
1875 ccb_ptr->csio.scsi_status = status; in mrsas_map_mpt_cmd_status()
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()
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()
2205 "Cannot allocate raid map tag.\n"); 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()
2212 "Cannot allocate raidmap memory.\n"); 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()
2226 "Cannot allocate memory for raid map.\n"); in mrsas_setup_raidmap()
2241 * megasas_setup_jbod_map - setup jbod map for FP seq_number.
2253 (sizeof(struct MR_PD_CFG_SEQ) * (MAX_PHYSICAL_DEVICES - 1)); in megasas_setup_jbod_map()
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()
2275 "Cannot allocate jbod map tag.\n"); 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()
2282 "Cannot allocate jbod map memory.\n"); 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()
2296 "Cannot allocate memory for jbod map.\n"); in megasas_setup_jbod_map()
2297 sc->use_seqnum_jbod_fp = 0; 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()
2341 if (sc->is_ventura || sc->is_aero) { 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()
2350 /* MSI-x index 0- reply post host index register */ in mrsas_init_fw()
2351 sc->msix_reg_offset[0] = MPI2_REPLY_POST_HOST_INDEX_OFFSET; in mrsas_init_fw()
2352 /* Check if MSI-X is supported while in ready state */ in mrsas_init_fw()
2359 /* Check max MSI-X vectors */ 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()
2365 /* Invader/Fury supports 96 MSI-X 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()
2375 * Save 1-15 reply post index in mrsas_init_fw()
2382 sc->msix_reg_offset[loop] = in mrsas_init_fw()
2388 /* Don't bother allocating more MSI-X vectors than cpus */ in mrsas_init_fw()
2389 sc->msix_vectors = min(sc->msix_vectors, in mrsas_init_fw()
2392 /* Allocate MSI-x vectors */ 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()
2399 "Online CPU %d Current MSIX <%d>\n", in mrsas_init_fw()
2400 fw_msix_count, mp_ncpus, sc->msix_vectors); in mrsas_init_fw()
2403 * MSI-X host index 0 is common for all adapter. in mrsas_init_fw()
2406 if (sc->msix_combined) { in mrsas_init_fw()
2407 sc->msix_reg_offset[0] = 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()
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()
2424 /* Allocate internal commands for pass-thru */ 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()
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()
2455 device_printf(sc->mrsas_dev, "Error: RAID map setup FAILED !!! " 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()
2466 /* For pass-thru, get PD/LD list and controller info */ in mrsas_init_fw()
2467 memset(sc->pd_list, 0, 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()
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()
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()
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()
2576 mrsas_dprint(sc, MRSAS_TRACE, "%s: sc->reply_q_depth 0x%x," in mrsas_init_adapter()
2577 "sc->request_alloc_sz 0x%x, sc->reply_alloc_sz 0x%x," in mrsas_init_adapter()
2578 "sc->io_frames_alloc_sz 0x%x\n", __func__, 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()
2585 * than legacy Firmware. Legacy Firmware - Frame size is (8 * 128) = in mrsas_init_adapter()
2586 * 1K 1M IO Firmware - Frame size is (8 * 128 * 4) = 4K 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()
2606 "max fw cmd: 0x%x sc->chain_frames_alloc_sz: 0x%x\n", 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()
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()
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()
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()
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()
2727 IOCInitMsg->Function = MPI2_FUNCTION_IOC_INIT; in mrsas_ioc_init()
2728 IOCInitMsg->WhoInit = MPI2_WHOINIT_HOST_DRIVER; in mrsas_ioc_init()
2729 IOCInitMsg->MsgVersion = htole16(MPI2_VERSION); in mrsas_ioc_init()
2730 IOCInitMsg->HeaderVersion = htole16(MPI2_HEADER_VERSION); in mrsas_ioc_init()
2731 IOCInitMsg->SystemRequestFrameSize = htole16(MRSAS_MPI2_RAID_DEFAULT_IO_FRAME_SIZE / 4); 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()
2736 IOCInitMsg->HostPageSize = MR_DEFAULT_NVME_PAGE_SHIFT; in mrsas_ioc_init()
2738 init_frame = (struct mrsas_init_frame *)sc->ioc_init_mem; in mrsas_ioc_init()
2739 init_frame->cmd = MFI_CMD_INIT; in mrsas_ioc_init()
2740 init_frame->cmd_status = 0xFF; in mrsas_ioc_init()
2741 init_frame->flags |= htole16(MFI_FRAME_DONT_POST_IN_REPLY_QUEUE); in mrsas_ioc_init()
2744 if (sc->mrsas_gen3_ctrl || sc->is_ventura || sc->is_aero) { in mrsas_ioc_init()
2745 init_frame->driver_operations. 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()
2752 init_frame->driver_ver_hi = 0; in mrsas_ioc_init()
2754 init_frame->driver_operations.mfi_capabilities.support_ndrive_r1_lb = 1; in mrsas_ioc_init()
2755 init_frame->driver_operations.mfi_capabilities.support_max_255lds = 1; in mrsas_ioc_init()
2756 init_frame->driver_operations.mfi_capabilities.security_protocol_cmds_fw = 1; in mrsas_ioc_init()
2757 if (sc->max_chain_frame_sz > MEGASAS_CHAIN_FRAME_SZ_MIN) in mrsas_ioc_init()
2758 init_frame->driver_operations.mfi_capabilities.support_ext_io_size = 1; in mrsas_ioc_init()
2760 init_frame->driver_operations.reg = htole32(init_frame->driver_operations.reg); in mrsas_ioc_init()
2762 phys_addr = (bus_addr_t)sc->ioc_init_phys_mem + 1024; in mrsas_ioc_init()
2763 init_frame->queue_info_new_phys_addr_lo = htole32(phys_addr); in mrsas_ioc_init()
2764 init_frame->data_xfer_len = htole32(sizeof(Mpi2IOCInitRequest_t)); in mrsas_ioc_init()
2766 req_desc.addr.Words = htole64((bus_addr_t)sc->ioc_init_phys_mem); in mrsas_ioc_init()
2775 * Poll response timer to wait for Firmware response. While this in mrsas_ioc_init()
2776 * timer with the DELAY call could block CPU, the time interval for in mrsas_ioc_init()
2779 if (init_frame->cmd_status == 0xFF) { in mrsas_ioc_init()
2781 if (init_frame->cmd_status == 0xFF) in mrsas_ioc_init()
2787 if (init_frame->cmd_status == 0) in mrsas_ioc_init()
2791 if (init_frame->cmd_status == 0xFF) 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()
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()
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()
2842 * sc->mpt_cmd_list is an array of struct mrsas_mpt_cmd pointers. 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()
2877 cmd->index = i + 1; in mrsas_alloc_mpt_cmds()
2878 cmd->ccb_ptr = NULL; in mrsas_alloc_mpt_cmds()
2879 cmd->r1_alt_dev_handle = MR_DEVHANDLE_INVALID; in mrsas_alloc_mpt_cmds()
2880 callout_init_mtx(&cmd->cm_callout, &sc->sim_lock, 0); in mrsas_alloc_mpt_cmds()
2881 cmd->sync_cmd_idx = (u_int32_t)MRSAS_ULONG_MAX; in mrsas_alloc_mpt_cmds()
2882 cmd->sc = sc; in mrsas_alloc_mpt_cmds()
2883 cmd->io_request = (MRSAS_RAID_SCSI_IO_REQUEST *) (io_req_base + offset); in mrsas_alloc_mpt_cmds()
2884 memset(cmd->io_request, 0, sizeof(MRSAS_RAID_SCSI_IO_REQUEST)); in mrsas_alloc_mpt_cmds()
2885 cmd->io_request_phys_addr = io_req_base_phys + offset; in mrsas_alloc_mpt_cmds()
2886 cmd->chain_frame = (MPI2_SGE_IO_UNION *) (chain_frame_base + chain_offset); in mrsas_alloc_mpt_cmds()
2887 cmd->chain_frame_phys_addr = chain_frame_base_phys + chain_offset; in mrsas_alloc_mpt_cmds()
2888 cmd->sense = sense_base + sense_offset; in mrsas_alloc_mpt_cmds()
2889 cmd->sense_phys_addr = sense_base_phys + sense_offset; 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()
2900 reply_desc->Words = MRSAS_ULONG_MAX; in mrsas_alloc_mpt_cmds()
2915 mtx_lock(&sc->pci_lock); in mrsas_write_64bit_req_desc()
2920 mtx_unlock(&sc->pci_lock); in mrsas_write_64bit_req_desc()
2936 if (sc->atomic_desc_support) in mrsas_fire_cmd()
2948 * possible states. If the FW in operational, waiting-for-handshake states,
2966 device_printf(sc->mrsas_dev, "Waiting for FW to come to ready state\n"); in mrsas_transition_to_ready()
2972 device_printf(sc->mrsas_dev, "FW is in FAULT state!!\n"); in mrsas_transition_to_ready()
2977 return -ENODEV; in mrsas_transition_to_ready()
3027 device_printf(sc->mrsas_dev, "Unknown state 0x%x\n", fw_state); in mrsas_transition_to_ready()
3028 return -ENODEV; in mrsas_transition_to_ready()
3049 device_printf(sc->mrsas_dev, "FW state [%d] hasn't changed " in mrsas_transition_to_ready()
3051 return -ENODEV; in mrsas_transition_to_ready()
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()
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()
3107 sc->remove_in_progress ? "Shutdown" : 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()
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()
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()
3175 mtx_unlock(&sc->sim_lock); in mrsas_ocr_thread()
3176 sc->ocr_thread_active = 0; in mrsas_ocr_thread()
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()
3199 reply_desc->Words = MRSAS_ULONG_MAX; in mrsas_reset_reply_desc()
3213 * OCR, Re-fire Management command and move Controller to Operation state.
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()
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()
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()
3247 if (mpt_cmd->peer_cmd) { in mrsas_reset_ctrl()
3249 "R1 FP command [%d] - (mpt_cmd) %p, (peer_cmd) %p\n", in mrsas_reset_ctrl()
3250 i, mpt_cmd, mpt_cmd->peer_cmd); in mrsas_reset_ctrl()
3253 if (mpt_cmd->ccb_ptr) { in mrsas_reset_ctrl()
3254 if (mpt_cmd->callout_owner) { in mrsas_reset_ctrl()
3255 ccb = (union ccb *)(mpt_cmd->ccb_ptr); in mrsas_reset_ctrl()
3256 ccb->ccb_h.status = CAM_SCSI_BUS_RESET; in mrsas_reset_ctrl()
3259 mpt_cmd->ccb_ptr = NULL; 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()
3273 if (sc->disableOnlineCtrlReset || 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()
3364 if (mpt_cmd->sync_cmd_idx != (u_int32_t)MRSAS_ULONG_MAX) { in mrsas_reset_ctrl()
3365 mfi_cmd = sc->mfi_cmd_list[mpt_cmd->sync_cmd_idx]; in mrsas_reset_ctrl()
3366 /* If not an IOCTL then release the command else re-fire */ in mrsas_reset_ctrl()
3367 if (!mfi_cmd->sync_cmd) { in mrsas_reset_ctrl()
3371 mfi_cmd->cmd_id.context.smid - 1); in mrsas_reset_ctrl()
3373 "Re-fire command DCMD opcode 0x%x index %d\n ", in mrsas_reset_ctrl()
3374 mfi_cmd->frame->dcmd.opcode, j); in mrsas_reset_ctrl()
3376 device_printf(sc->mrsas_dev, in mrsas_reset_ctrl()
3377 "Cannot build MPT cmd.\n"); in mrsas_reset_ctrl()
3379 mrsas_fire_cmd(sc, req_desc->addr.u.low, in mrsas_reset_ctrl()
3380 req_desc->addr.u.high); in mrsas_reset_ctrl()
3386 memset(sc->load_balance_info, 0, 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()
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()
3420 "Further events from the controller cannot be notified." 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()
3437 mrsas_clear_bit(MRSAS_FUSION_IN_RESET, &sc->reset_flags); 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()
3457 sc->adprecovery = MRSAS_HW_CRITICAL_ERROR; in mrsas_kill_hba()
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()
3485 if (cmd_mpt->sync_cmd_idx != (u_int32_t)MRSAS_ULONG_MAX) { in mrsas_complete_outstanding_ioctls()
3486 cmd_mfi = sc->mfi_cmd_list[cmd_mpt->sync_cmd_idx]; in mrsas_complete_outstanding_ioctls()
3487 if (cmd_mfi->sync_cmd && cmd_mfi->frame->hdr.cmd != MFI_CMD_ABORT) { in mrsas_complete_outstanding_ioctls()
3490 cmd_mpt->io_request->RaidContext.raid_context.status); in mrsas_complete_outstanding_ioctls()
3510 if (sc->remove_in_progress) { 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()
3526 mtx_lock(&sc->sim_lock); in mrsas_wait_for_outstanding()
3536 outstanding = mrsas_atomic_read(&sc->fw_outstanding); 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()
3547 mtx_lock(&sc->sim_lock); in mrsas_wait_for_outstanding()
3552 if (mrsas_atomic_read(&sc->fw_outstanding)) { in mrsas_wait_for_outstanding()
3571 struct mrsas_softc *sc = cmd_mfi->sc; in mrsas_release_mfi_cmd()
3574 mtx_lock(&sc->mfi_cmd_pool_lock); in mrsas_release_mfi_cmd()
3579 if (cmd_mfi->cmd_id.context.smid) { 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()
3583 cmd_mpt->flags = 0; in mrsas_release_mfi_cmd()
3584 cmd_mpt->sync_cmd_idx = (u_int32_t)MRSAS_ULONG_MAX; 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()
3589 cmd_mfi->ccb_ptr = NULL; in mrsas_release_mfi_cmd()
3590 cmd_mfi->cmd_id.frame_count = 0; 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()
3617 device_printf(sc->mrsas_dev, "Failed to get a free cmd\n"); in mrsas_get_ctrl_info()
3618 return -ENOMEM; in mrsas_get_ctrl_info()
3620 dcmd = &cmd->frame->dcmd; in mrsas_get_ctrl_info()
3623 device_printf(sc->mrsas_dev, "Cannot allocate get ctlr info cmd\n"); in mrsas_get_ctrl_info()
3625 return -ENOMEM; in mrsas_get_ctrl_info()
3627 memset(dcmd->mbox.b, 0, MFI_MBOX_SIZE); in mrsas_get_ctrl_info()
3629 dcmd->cmd = MFI_CMD_DCMD; in mrsas_get_ctrl_info()
3630 dcmd->cmd_status = 0xFF; in mrsas_get_ctrl_info()
3631 dcmd->sge_count = 1; in mrsas_get_ctrl_info()
3632 dcmd->flags = MFI_FRAME_DIR_READ; in mrsas_get_ctrl_info()
3633 dcmd->timeout = 0; in mrsas_get_ctrl_info()
3634 dcmd->pad_0 = 0; in mrsas_get_ctrl_info()
3635 dcmd->data_xfer_len = htole32(sizeof(struct mrsas_ctrl_info)); in mrsas_get_ctrl_info()
3636 dcmd->opcode = htole32(MR_DCMD_CTRL_GET_INFO); in mrsas_get_ctrl_info()
3637 dcmd->sgl.sge32[0].phys_addr = htole32(sc->ctlr_info_phys_addr & 0xFFFFFFFF); in mrsas_get_ctrl_info()
3638 dcmd->sgl.sge32[0].length = htole32(sizeof(struct mrsas_ctrl_info)); in mrsas_get_ctrl_info()
3640 if (!sc->mask_interrupts) 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()
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()
3670 sc->do_timedout_reset = MFI_DCMD_TIMEOUT_OCR; in mrsas_get_ctrl_info()
3672 if (!sc->mask_interrupts) in mrsas_get_ctrl_info()
3681 * sc - Controller's softc
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()
3729 "fusion->drv_map_sz =0x%x, size of driver raid map 0x%lx \n", 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()
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()
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()
3801 * the poll response timer is 180 seconds.
3806 struct mrsas_header *frame_hdr = &cmd->frame->hdr; in mrsas_issue_polled()
3810 frame_hdr->cmd_status = 0xFF; in mrsas_issue_polled()
3811 frame_hdr->flags |= htole16(MFI_FRAME_DONT_POST_IN_REPLY_QUEUE); in mrsas_issue_polled()
3815 device_printf(sc->mrsas_dev, "Cannot issue DCMD internal command.\n"); in mrsas_issue_polled()
3819 * Poll response timer to wait for Firmware response. While this in mrsas_issue_polled()
3820 * timer with the DELAY call could block CPU, the time interval for in mrsas_issue_polled()
3823 if (frame_hdr->cmd_status == 0xFF) { in mrsas_issue_polled()
3825 if (frame_hdr->cmd_status == 0xFF) in mrsas_issue_polled()
3831 if (frame_hdr->cmd_status == 0xFF) { 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()
3835 cmd->frame->dcmd.opcode); in mrsas_issue_polled()
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()
3868 * This function is called by mrsas_issue_cmd() to build the MPT-MFI passthru
3878 device_printf(sc->mrsas_dev, "Cannot build MPT-MFI passthru cmd.\n"); in mrsas_build_mpt_cmd()
3881 index = cmd->cmd_id.context.smid; in mrsas_build_mpt_cmd()
3883 req_desc = mrsas_get_request_desc(sc, index - 1); in mrsas_build_mpt_cmd()
3887 req_desc->addr.Words = 0; in mrsas_build_mpt_cmd()
3888 …req_desc->SCSIIO.RequestFlags = (MPI2_REQ_DESCRIPT_FLAGS_SCSI_IO << MRSAS_REQ_DESCRIPT_FLAGS_TYPE_… in mrsas_build_mpt_cmd()
3890 req_desc->SCSIIO.SMID = htole16(index); in mrsas_build_mpt_cmd()
3908 struct mrsas_header *frame_hdr = &mfi_cmd->frame->hdr; in mrsas_build_mptmfi_passthru()
3915 mfi_cmd->cmd_id.context.smid = mpt_cmd->index; in mrsas_build_mptmfi_passthru()
3917 mpt_cmd->sync_cmd_idx = mfi_cmd->index; in mrsas_build_mptmfi_passthru()
3925 if (frame_hdr->flags & htole16(MFI_FRAME_DONT_POST_IN_REPLY_QUEUE)) in mrsas_build_mptmfi_passthru()
3926 mpt_cmd->flags = MFI_FRAME_DONT_POST_IN_REPLY_QUEUE; in mrsas_build_mptmfi_passthru()
3928 io_req = mpt_cmd->io_request; in mrsas_build_mptmfi_passthru()
3930 if (sc->mrsas_gen3_ctrl || sc->is_ventura || sc->is_aero) { in mrsas_build_mptmfi_passthru()
3931 pMpi25IeeeSgeChain64_t sgl_ptr_end = (pMpi25IeeeSgeChain64_t)&io_req->SGL; in mrsas_build_mptmfi_passthru()
3933 sgl_ptr_end += sc->max_sge_in_main_msg - 1; in mrsas_build_mptmfi_passthru()
3934 sgl_ptr_end->Flags = 0; in mrsas_build_mptmfi_passthru()
3936 mpi25_ieee_chain = (MPI25_IEEE_SGE_CHAIN64 *) & io_req->SGL.IeeeChain; in mrsas_build_mptmfi_passthru()
3938 io_req->Function = MRSAS_MPI2_FUNCTION_PASSTHRU_IO_REQUEST; in mrsas_build_mptmfi_passthru()
3939 io_req->SGLOffset0 = offsetof(MRSAS_RAID_SCSI_IO_REQUEST, SGL) / 4; in mrsas_build_mptmfi_passthru()
3940 io_req->ChainOffset = sc->chain_offset_mfi_pthru; in mrsas_build_mptmfi_passthru()
3942 mpi25_ieee_chain->Address = htole64(mfi_cmd->frame_phys_addr); in mrsas_build_mptmfi_passthru()
3944 mpi25_ieee_chain->Flags = IEEE_SGE_FLAGS_CHAIN_ELEMENT | in mrsas_build_mptmfi_passthru()
3947 mpi25_ieee_chain->Length = htole32(sc->max_chain_frame_sz); in mrsas_build_mptmfi_passthru()
3968 cmd->cmd_status = 0xFF; in mrsas_issue_blocked_cmd()
3970 /* Build MPT-MFI command for issue to FW */ 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()
3978 if (cmd->cmd_status == 0xFF) { in mrsas_issue_blocked_cmd()
3979 tsleep((void *)&sc->chan, 0, "mrsas_sleep", hz); in mrsas_issue_blocked_cmd()
3983 if (!cmd->sync_cmd) { /* cmd->sync will be set for an IOCTL 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()
3996 if (cmd->cmd_status == 0xFF) { 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()
4000 cmd->frame->dcmd.opcode); in mrsas_issue_blocked_cmd()
4013 * received from Firmware, and io_request->Function is
4020 struct mrsas_header *hdr = &cmd->frame->hdr; in mrsas_complete_mptmfi_passthru()
4021 u_int8_t cmd_status = cmd->frame->hdr.cmd_status; in mrsas_complete_mptmfi_passthru()
4023 /* Reset the retry counter for future re-tries */ in mrsas_complete_mptmfi_passthru()
4024 cmd->retry_for_fw_reset = 0; in mrsas_complete_mptmfi_passthru()
4026 if (cmd->ccb_ptr) in mrsas_complete_mptmfi_passthru()
4027 cmd->ccb_ptr = NULL; in mrsas_complete_mptmfi_passthru()
4029 switch (hdr->cmd) { in mrsas_complete_mptmfi_passthru()
4031 device_printf(sc->mrsas_dev, "MFI_CMD_INVALID command.\n"); in mrsas_complete_mptmfi_passthru()
4040 if (cmd->sync_cmd) { in mrsas_complete_mptmfi_passthru()
4041 cmd->sync_cmd = 0; in mrsas_complete_mptmfi_passthru()
4049 if ((cmd->frame->dcmd.opcode == MR_DCMD_LD_MAP_GET_INFO) && in mrsas_complete_mptmfi_passthru()
4050 (cmd->frame->dcmd.mbox.b[1] == 1)) { 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()
4066 sc->fast_path_io = 0; in mrsas_complete_mptmfi_passthru()
4068 sc->fast_path_io = 1; in mrsas_complete_mptmfi_passthru()
4070 mtx_unlock(&sc->raidmap_lock); in mrsas_complete_mptmfi_passthru()
4073 if (cmd->frame->dcmd.opcode == MR_DCMD_CTRL_EVENT_GET_INFO || in mrsas_complete_mptmfi_passthru()
4074 cmd->frame->dcmd.opcode == MR_DCMD_CTRL_EVENT_GET) { in mrsas_complete_mptmfi_passthru()
4075 sc->mrsas_aen_triggered = 0; in mrsas_complete_mptmfi_passthru()
4078 if ((cmd->frame->dcmd.opcode == in mrsas_complete_mptmfi_passthru()
4080 (cmd->frame->dcmd.mbox.b[0] == 1)) { 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()
4087 /* Re-register a pd sync seq num cmd */ 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()
4099 if (le32toh(cmd->frame->dcmd.opcode) == MR_DCMD_CTRL_EVENT_WAIT) in mrsas_complete_mptmfi_passthru()
4109 device_printf(sc->mrsas_dev, "Unknown command completed! [0x%X]\n", hdr->cmd); in mrsas_complete_mptmfi_passthru()
4120 * timer is started. This function is called from
4121 * mrsas_complete_mptmfi_passthru() as it completes the command, to wake up
4127 cmd->cmd_status = cmd->frame->io.cmd_status; in mrsas_wakeup()
4129 if (cmd->cmd_status == 0xFF) in mrsas_wakeup()
4130 cmd->cmd_status = 0; in mrsas_wakeup()
4132 sc->chan = (void *)&cmd; in mrsas_wakeup()
4133 wakeup_one((void *)&sc->chan); in mrsas_wakeup()
4150 if (sc->adprecovery == MRSAS_HW_CRITICAL_ERROR) 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()
4165 dcmd = &cmd->frame->dcmd; in mrsas_shutdown_ctlr()
4166 memset(dcmd->mbox.b, 0, MFI_MBOX_SIZE); in mrsas_shutdown_ctlr()
4168 dcmd->cmd = MFI_CMD_DCMD; in mrsas_shutdown_ctlr()
4169 dcmd->cmd_status = 0x0; in mrsas_shutdown_ctlr()
4170 dcmd->sge_count = 0; in mrsas_shutdown_ctlr()
4171 dcmd->flags = MFI_FRAME_DIR_NONE; in mrsas_shutdown_ctlr()
4172 dcmd->timeout = 0; in mrsas_shutdown_ctlr()
4173 dcmd->pad_0 = 0; in mrsas_shutdown_ctlr()
4174 dcmd->data_xfer_len = 0; in mrsas_shutdown_ctlr()
4175 dcmd->opcode = opcode; in mrsas_shutdown_ctlr()
4177 device_printf(sc->mrsas_dev, "Preparing to shut down controller.\n"); in mrsas_shutdown_ctlr()
4198 if (sc->adprecovery == MRSAS_HW_CRITICAL_ERROR) in mrsas_flush_cache()
4203 device_printf(sc->mrsas_dev, "Cannot allocate for flush cache cmd.\n"); in mrsas_flush_cache()
4206 dcmd = &cmd->frame->dcmd; in mrsas_flush_cache()
4207 memset(dcmd->mbox.b, 0, MFI_MBOX_SIZE); in mrsas_flush_cache()
4209 dcmd->cmd = MFI_CMD_DCMD; in mrsas_flush_cache()
4210 dcmd->cmd_status = 0x0; in mrsas_flush_cache()
4211 dcmd->sge_count = 0; in mrsas_flush_cache()
4212 dcmd->flags = MFI_FRAME_DIR_NONE; in mrsas_flush_cache()
4213 dcmd->timeout = 0; in mrsas_flush_cache()
4214 dcmd->pad_0 = 0; in mrsas_flush_cache()
4215 dcmd->data_xfer_len = 0; in mrsas_flush_cache()
4216 dcmd->opcode = MR_DCMD_CTRL_CACHE_FLUSH; in mrsas_flush_cache()
4217 dcmd->mbox.b[0] = MR_FLUSH_CTRL_CACHE | MR_FLUSH_DISK_CACHE; in mrsas_flush_cache()
4238 (MAX_PHYSICAL_DEVICES - 1)); in megasas_sync_pd_seq_num()
4242 device_printf(sc->mrsas_dev, in megasas_sync_pd_seq_num()
4243 "Cannot alloc for ld map info cmd.\n"); in megasas_sync_pd_seq_num()
4246 dcmd = &cmd->frame->dcmd; 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()
4257 memset(dcmd->mbox.b, 0, MFI_MBOX_SIZE); in megasas_sync_pd_seq_num()
4258 dcmd->cmd = MFI_CMD_DCMD; in megasas_sync_pd_seq_num()
4259 dcmd->cmd_status = 0xFF; in megasas_sync_pd_seq_num()
4260 dcmd->sge_count = 1; in megasas_sync_pd_seq_num()
4261 dcmd->timeout = 0; in megasas_sync_pd_seq_num()
4262 dcmd->pad_0 = 0; in megasas_sync_pd_seq_num()
4263 dcmd->data_xfer_len = htole32(pd_seq_map_sz); in megasas_sync_pd_seq_num()
4264 dcmd->opcode = htole32(MR_DCMD_SYSTEM_PD_MAP_GET_INFO); in megasas_sync_pd_seq_num()
4265 dcmd->sgl.sge32[0].phys_addr = htole32(pd_seq_h & 0xFFFFFFFF); in megasas_sync_pd_seq_num()
4266 dcmd->sgl.sge32[0].length = htole32(pd_seq_map_sz); in megasas_sync_pd_seq_num()
4269 dcmd->mbox.b[0] = MRSAS_DCMD_MBOX_PEND_FLAG; in megasas_sync_pd_seq_num()
4270 dcmd->flags = htole16(MFI_FRAME_DIR_WRITE); in megasas_sync_pd_seq_num()
4271 sc->jbod_seq_cmd = cmd; in megasas_sync_pd_seq_num()
4273 device_printf(sc->mrsas_dev, in megasas_sync_pd_seq_num()
4279 dcmd->flags = htole16(MFI_FRAME_DIR_READ); in megasas_sync_pd_seq_num()
4285 if (le32toh(pd_sync->count) > MAX_PHYSICAL_DEVICES) { in megasas_sync_pd_seq_num()
4286 device_printf(sc->mrsas_dev, in megasas_sync_pd_seq_num()
4288 MAX_PHYSICAL_DEVICES, pd_sync->count); in megasas_sync_pd_seq_num()
4289 retcode = -EINVAL; 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()
4307 * and validate RAID map. It returns 0 if successful, 1 other- wise.
4314 sc->fast_path_io = 0; in mrsas_get_map_info()
4318 sc->fast_path_io = 1; in mrsas_get_map_info()
4343 device_printf(sc->mrsas_dev, in mrsas_get_ld_map_info()
4344 "Cannot alloc for ld map info cmd.\n"); in mrsas_get_ld_map_info()
4347 dcmd = &cmd->frame->dcmd; 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()
4358 memset(dcmd->mbox.b, 0, MFI_MBOX_SIZE); in mrsas_get_ld_map_info()
4360 dcmd->cmd = MFI_CMD_DCMD; in mrsas_get_ld_map_info()
4361 dcmd->cmd_status = 0xFF; in mrsas_get_ld_map_info()
4362 dcmd->sge_count = 1; in mrsas_get_ld_map_info()
4363 dcmd->flags = htole16(MFI_FRAME_DIR_READ); in mrsas_get_ld_map_info()
4364 dcmd->timeout = 0; in mrsas_get_ld_map_info()
4365 dcmd->pad_0 = 0; in mrsas_get_ld_map_info()
4366 dcmd->data_xfer_len = htole32(sc->current_map_sz); in mrsas_get_ld_map_info()
4367 dcmd->opcode = htole32(MR_DCMD_LD_MAP_GET_INFO); in mrsas_get_ld_map_info()
4368 dcmd->sgl.sge32[0].phys_addr = htole32(map_phys_addr & 0xFFFFFFFF); in mrsas_get_ld_map_info()
4369 dcmd->sgl.sge32[0].length = htole32(sc->current_map_sz); in mrsas_get_ld_map_info()
4373 sc->do_timedout_reset = MFI_DCMD_TIMEOUT_OCR; in mrsas_get_ld_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()
4404 num_lds = map->raidMap.ldCount; in mrsas_sync_map_info()
4406 dcmd = &cmd->frame->dcmd; in mrsas_sync_map_info()
4407 memset(dcmd->mbox.b, 0, MFI_MBOX_SIZE); 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()
4418 ld_sync->targetId = MR_GetLDTgtId(i, map); in mrsas_sync_map_info()
4419 ld_sync->seqNum = raid->seqNum; in mrsas_sync_map_info()
4422 dcmd->cmd = MFI_CMD_DCMD; in mrsas_sync_map_info()
4423 dcmd->cmd_status = 0xFF; in mrsas_sync_map_info()
4424 dcmd->sge_count = 1; in mrsas_sync_map_info()
4425 dcmd->flags = htole16(MFI_FRAME_DIR_WRITE); in mrsas_sync_map_info()
4426 dcmd->timeout = 0; in mrsas_sync_map_info()
4427 dcmd->pad_0 = 0; in mrsas_sync_map_info()
4428 dcmd->data_xfer_len = htole32(sc->current_map_sz); in mrsas_sync_map_info()
4429 dcmd->mbox.b[0] = num_lds; in mrsas_sync_map_info()
4430 dcmd->mbox.b[1] = MRSAS_DCMD_MBOX_PEND_FLAG; in mrsas_sync_map_info()
4431 dcmd->opcode = htole32(MR_DCMD_LD_MAP_GET_INFO); in mrsas_sync_map_info()
4432 dcmd->sgl.sge32[0].phys_addr = htole32(map_phys_addr & 0xFFFFFFFF); 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()
4437 device_printf(sc->mrsas_dev, in mrsas_sync_map_info()
4444 /* Input: dcmd.opcode - MR_DCMD_PD_GET_INFO
4445 * dcmd.mbox.s[0] - deviceId for this physical drive
4446 * dcmd.sge IN - ptr to returned MR_PD_INFO structure
4461 device_printf(sc->mrsas_dev, in mrsas_get_pd_info()
4462 "Cannot alloc for get PD info cmd\n"); in mrsas_get_pd_info()
4465 dcmd = &cmd->frame->dcmd; in mrsas_get_pd_info()
4467 memset(sc->pd_info_mem, 0, sizeof(struct mrsas_pd_info)); in mrsas_get_pd_info()
4468 memset(dcmd->mbox.b, 0, MFI_MBOX_SIZE); in mrsas_get_pd_info()
4470 dcmd->mbox.s[0] = htole16(device_id); in mrsas_get_pd_info()
4471 dcmd->cmd = MFI_CMD_DCMD; in mrsas_get_pd_info()
4472 dcmd->cmd_status = 0xFF; in mrsas_get_pd_info()
4473 dcmd->sge_count = 1; in mrsas_get_pd_info()
4474 dcmd->flags = MFI_FRAME_DIR_READ; in mrsas_get_pd_info()
4475 dcmd->timeout = 0; in mrsas_get_pd_info()
4476 dcmd->pad_0 = 0; in mrsas_get_pd_info()
4477 dcmd->data_xfer_len = htole32(sizeof(struct mrsas_pd_info)); in mrsas_get_pd_info()
4478 dcmd->opcode = htole32(MR_DCMD_PD_GET_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()
4480 dcmd->sgl.sge32[0].length = htole32(sizeof(struct mrsas_pd_info)); in mrsas_get_pd_info()
4482 if (!sc->mask_interrupts) 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()
4508 * for system PDs- target ID ranges from 0 to (MRSAS_MAX_PD - 1)
4509 * for VDs- target ID ranges from MRSAS_MAX_PD to MRSAS_MAX_TM_TARGETS
4516 sc->target_list[target_id].target_id = target_id; in mrsas_add_target()
4518 device_printf(sc->mrsas_dev, in mrsas_add_target()
4521 (target_id < MRSAS_MAX_PD ? target_id : (target_id - MRSAS_MAX_PD))); in mrsas_add_target()
4526 if (!sc->mask_interrupts && sc->pd_info_mem && in mrsas_add_target()
4536 * for system PDs- target ID ranges from 0 to (MRSAS_MAX_PD - 1)
4537 * for VDs- target ID ranges from MRSAS_MAX_PD to MRSAS_MAX_TM_TARGETS
4544 sc->target_list[target_id].target_id = 0xffff; in mrsas_remove_target()
4545 device_printf(sc->mrsas_dev, in mrsas_remove_target()
4548 (target_id < MRSAS_MAX_PD ? target_id : (target_id - MRSAS_MAX_PD))); in mrsas_remove_target()
4574 device_printf(sc->mrsas_dev, in mrsas_get_pd_list()
4575 "Cannot alloc for get PD list cmd\n"); in mrsas_get_pd_list()
4578 dcmd = &cmd->frame->dcmd; in mrsas_get_pd_list()
4583 device_printf(sc->mrsas_dev, in mrsas_get_pd_list()
4584 "Cannot alloc dmamap for get PD list cmd\n"); in mrsas_get_pd_list()
4590 pd_list_mem = tcmd->tmp_dcmd_mem; in mrsas_get_pd_list()
4591 pd_list_phys_addr = tcmd->tmp_dcmd_phys_addr; in mrsas_get_pd_list()
4593 memset(dcmd->mbox.b, 0, MFI_MBOX_SIZE); in mrsas_get_pd_list()
4595 dcmd->mbox.b[0] = MR_PD_QUERY_TYPE_EXPOSED_TO_HOST; in mrsas_get_pd_list()
4596 dcmd->mbox.b[1] = 0; in mrsas_get_pd_list()
4597 dcmd->cmd = MFI_CMD_DCMD; in mrsas_get_pd_list()
4598 dcmd->cmd_status = 0xFF; in mrsas_get_pd_list()
4599 dcmd->sge_count = 1; in mrsas_get_pd_list()
4600 dcmd->flags = htole16(MFI_FRAME_DIR_READ); in mrsas_get_pd_list()
4601 dcmd->timeout = 0; in mrsas_get_pd_list()
4602 dcmd->pad_0 = 0; in mrsas_get_pd_list()
4603 dcmd->data_xfer_len = htole32(MRSAS_MAX_PD * sizeof(struct MR_PD_LIST)); in mrsas_get_pd_list()
4604 dcmd->opcode = htole32(MR_DCMD_PD_LIST_QUERY); in mrsas_get_pd_list()
4605 dcmd->sgl.sge32[0].phys_addr = htole32(pd_list_phys_addr & 0xFFFFFFFF); in mrsas_get_pd_list()
4606 dcmd->sgl.sge32[0].length = htole32(MRSAS_MAX_PD * sizeof(struct MR_PD_LIST)); in mrsas_get_pd_list()
4608 if (!sc->mask_interrupts) in mrsas_get_pd_list()
4618 pd_addr = pd_list_mem->addr; in mrsas_get_pd_list()
4619 if (le32toh(pd_list_mem->count) < pd_count) { in mrsas_get_pd_list()
4620 memset(sc->local_pd_list, 0, in mrsas_get_pd_list()
4622 for (pd_index = 0; pd_index < le32toh(pd_list_mem->count); pd_index++) { in mrsas_get_pd_list()
4623 dev_id = le16toh(pd_addr->deviceId); 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()
4626 le16toh(pd_addr->scsiDevType); 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()
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()
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()
4682 device_printf(sc->mrsas_dev, in mrsas_get_ld_list()
4683 "Cannot alloc for get LD list cmd\n"); in mrsas_get_ld_list()
4686 dcmd = &cmd->frame->dcmd; in mrsas_get_ld_list()
4691 device_printf(sc->mrsas_dev, in mrsas_get_ld_list()
4692 "Cannot alloc dmamap for get LD list cmd\n"); in mrsas_get_ld_list()
4698 ld_list_mem = tcmd->tmp_dcmd_mem; in mrsas_get_ld_list()
4699 ld_list_phys_addr = tcmd->tmp_dcmd_phys_addr; in mrsas_get_ld_list()
4701 memset(dcmd->mbox.b, 0, MFI_MBOX_SIZE); in mrsas_get_ld_list()
4703 if (sc->max256vdSupport) in mrsas_get_ld_list()
4704 dcmd->mbox.b[0] = 1; in mrsas_get_ld_list()
4706 dcmd->cmd = MFI_CMD_DCMD; in mrsas_get_ld_list()
4707 dcmd->cmd_status = 0xFF; in mrsas_get_ld_list()
4708 dcmd->sge_count = 1; in mrsas_get_ld_list()
4709 dcmd->flags = MFI_FRAME_DIR_READ; in mrsas_get_ld_list()
4710 dcmd->timeout = 0; in mrsas_get_ld_list()
4711 dcmd->data_xfer_len = htole32(sizeof(struct MR_LD_LIST)); in mrsas_get_ld_list()
4712 dcmd->opcode = htole32(MR_DCMD_LD_GET_LIST); in mrsas_get_ld_list()
4713 dcmd->sgl.sge32[0].phys_addr = htole32(ld_list_phys_addr); in mrsas_get_ld_list()
4714 dcmd->sgl.sge32[0].length = htole32(sizeof(struct MR_LD_LIST)); in mrsas_get_ld_list()
4715 dcmd->pad_0 = 0; in mrsas_get_ld_list()
4717 if (!sc->mask_interrupts) in mrsas_get_ld_list()
4726 printf("Number of LDs %d\n", ld_list_mem->ldCount); 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()
4733 for (ld_index = 0; ld_index < le32toh(ld_list_mem->ldCount); ld_index++) { in mrsas_get_ld_list()
4734 ids = ld_list_mem->ldList[ld_index].ref.ld_context.targetId; in mrsas_get_ld_list()
4736 if (ld_list_mem->ldList[ld_index].state != 0) { 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()
4742 if (sc->target_list[drv_tgt_id].target_id != 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()
4775 if (bus_dma_tag_create(sc->mrsas_parent_tag, in mrsas_alloc_tmp_dcmd()
4785 &tcmd->tmp_dcmd_tag)) { in mrsas_alloc_tmp_dcmd()
4786 device_printf(sc->mrsas_dev, "Cannot allocate tmp dcmd tag\n"); in mrsas_alloc_tmp_dcmd()
4789 if (bus_dmamem_alloc(tcmd->tmp_dcmd_tag, (void **)&tcmd->tmp_dcmd_mem, in mrsas_alloc_tmp_dcmd()
4790 BUS_DMA_NOWAIT, &tcmd->tmp_dcmd_dmamap)) { in mrsas_alloc_tmp_dcmd()
4791 device_printf(sc->mrsas_dev, "Cannot allocate tmp dcmd mem\n"); in mrsas_alloc_tmp_dcmd()
4794 if (bus_dmamap_load(tcmd->tmp_dcmd_tag, tcmd->tmp_dcmd_dmamap, in mrsas_alloc_tmp_dcmd()
4795 tcmd->tmp_dcmd_mem, size, mrsas_addr_cb, in mrsas_alloc_tmp_dcmd()
4796 &tcmd->tmp_dcmd_phys_addr, BUS_DMA_NOWAIT)) { in mrsas_alloc_tmp_dcmd()
4797 device_printf(sc->mrsas_dev, "Cannot load tmp dcmd mem\n"); in mrsas_alloc_tmp_dcmd()
4800 memset(tcmd->tmp_dcmd_mem, 0, size); in mrsas_alloc_tmp_dcmd()
4814 if (tmp->tmp_dcmd_phys_addr) in mrsas_free_tmp_dcmd()
4815 bus_dmamap_unload(tmp->tmp_dcmd_tag, tmp->tmp_dcmd_dmamap); in mrsas_free_tmp_dcmd()
4816 if (tmp->tmp_dcmd_mem != NULL) in mrsas_free_tmp_dcmd()
4817 bus_dmamem_free(tmp->tmp_dcmd_tag, tmp->tmp_dcmd_mem, tmp->tmp_dcmd_dmamap); in mrsas_free_tmp_dcmd()
4818 if (tmp->tmp_dcmd_tag != NULL) in mrsas_free_tmp_dcmd()
4819 bus_dma_tag_destroy(tmp->tmp_dcmd_tag); in mrsas_free_tmp_dcmd()
4843 device_printf(sc->mrsas_dev, "Cannot alloc for abort cmd\n"); in mrsas_issue_blocked_abort_cmd()
4846 abort_fr = &cmd->frame->abort; in mrsas_issue_blocked_abort_cmd()
4849 abort_fr->cmd = MFI_CMD_ABORT; in mrsas_issue_blocked_abort_cmd()
4850 abort_fr->cmd_status = 0xFF; in mrsas_issue_blocked_abort_cmd()
4851 abort_fr->flags = 0; in mrsas_issue_blocked_abort_cmd()
4852 abort_fr->abort_context = cmd_to_abort->index; in mrsas_issue_blocked_abort_cmd()
4853 abort_fr->abort_mfi_phys_addr_lo = cmd_to_abort->frame_phys_addr; in mrsas_issue_blocked_abort_cmd()
4854 abort_fr->abort_mfi_phys_addr_hi = 0; in mrsas_issue_blocked_abort_cmd()
4856 cmd->sync_cmd = 1; in mrsas_issue_blocked_abort_cmd()
4857 cmd->cmd_status = 0xFF; 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()
4866 if (cmd->cmd_status == 0xFF) { 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()
4878 cmd->sync_cmd = 0; in mrsas_issue_blocked_abort_cmd()
4889 * mrsas_complete_mptmfi_passthru() to wake up the sleep thread associated.
4894 if (cmd->sync_cmd) { in mrsas_complete_abort()
4895 cmd->sync_cmd = 0; in mrsas_complete_abort()
4896 cmd->cmd_status = 0; in mrsas_complete_abort()
4897 sc->chan = (void *)&cmd; in mrsas_complete_abort()
4898 wakeup_one((void *)&sc->chan); in mrsas_complete_abort()
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()
4931 mrsas_bus_scan_sim(sc, sc->sim_1); 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()
4950 mrsas_bus_scan_sim(sc, sc->sim_0); in mrsas_aen_handler()
4968 device_printf(sc->mrsas_dev, "invalid evt_detail\n"); in mrsas_aen_handler()
4975 mrsas_bus_scan_sim(sc, sc->sim_1); 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()
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()
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()
5034 cmd->abort_aen = 0; 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()