Lines Matching +full:spi +full:- +full:crc
1 /*-
2 * SPDX-License-Identifier: BSD-2-Clause
31 * Common Interface for SCSI-3 Support driver.
37 * Interface for SCSI-3 Support Open Specification", Version 1.04,
40 * arbitrarlily cut-down version of a larger (and probably even more
45 * offloading most of the queueing and being-a-disk chores onto CAM.
407 nitems(ciss_vendor_data) - 1);
424 return(-1); in ciss_lookup()
436 if (i != -1) { in ciss_probe()
495 sc->ciss_dev = dev; in ciss_attach()
496 mtx_init(&sc->ciss_mtx, "cissmtx", NULL, MTX_DEF); in ciss_attach()
497 callout_init_mtx(&sc->ciss_periodic, &sc->ciss_mtx, 0); in ciss_attach()
500 * Do PCI-specific init. in ciss_attach()
559 sc->ciss_dev_t = make_dev(&ciss_cdevsw, device_get_unit(sc->ciss_dev), in ciss_attach()
561 "ciss%d", device_get_unit(sc->ciss_dev)); in ciss_attach()
562 sc->ciss_dev_t->si_drv1 = sc; in ciss_attach()
568 sc->ciss_flags |= CISS_FLAG_RUNNING; in ciss_attach()
576 mtx_lock(&sc->ciss_mtx); in ciss_attach()
592 mtx_lock(&sc->ciss_mtx); in ciss_detach()
593 if (sc->ciss_flags & CISS_FLAG_CONTROL_OPEN) { in ciss_detach()
594 mtx_unlock(&sc->ciss_mtx); in ciss_detach()
617 mtx_lock(&sc->ciss_mtx); in ciss_shutdown()
621 if (sc->ciss_soft_reset) in ciss_shutdown()
623 mtx_unlock(&sc->ciss_mtx); in ciss_shutdown()
632 SYSCTL_ADD_INT(device_get_sysctl_ctx(sc->ciss_dev), in ciss_init_sysctl()
633 SYSCTL_CHILDREN(device_get_sysctl_tree(sc->ciss_dev)), in ciss_init_sysctl()
634 OID_AUTO, "soft_reset", CTLFLAG_RW, &sc->ciss_soft_reset, 0, ""); in ciss_init_sysctl()
638 * Perform PCI-specific attachment actions.
653 i = ciss_lookup(sc->ciss_dev); in ciss_init_pci()
677 sc->ciss_regs_rid = CISS_TL_SIMPLE_BAR_REGS; in ciss_init_pci()
678 if ((sc->ciss_regs_resource = in ciss_init_pci()
679 bus_alloc_resource_any(sc->ciss_dev, SYS_RES_MEMORY, in ciss_init_pci()
680 &sc->ciss_regs_rid, RF_ACTIVE)) == NULL) { in ciss_init_pci()
684 sc->ciss_regs_bhandle = rman_get_bushandle(sc->ciss_regs_resource); in ciss_init_pci()
685 sc->ciss_regs_btag = rman_get_bustag(sc->ciss_regs_resource); in ciss_init_pci()
691 sc->ciss_cfg_rid = CISS_TL_SIMPLE_READ(sc, CISS_TL_SIMPLE_CFG_BAR) & 0xffff; in ciss_init_pci()
692 if (sc->ciss_cfg_rid != sc->ciss_regs_rid) { in ciss_init_pci()
693 if ((sc->ciss_cfg_resource = in ciss_init_pci()
694 bus_alloc_resource_any(sc->ciss_dev, SYS_RES_MEMORY, in ciss_init_pci()
695 &sc->ciss_cfg_rid, RF_ACTIVE)) == NULL) { in ciss_init_pci()
699 cbase = (uintptr_t)rman_get_virtual(sc->ciss_cfg_resource); in ciss_init_pci()
700 csize = rman_get_end(sc->ciss_cfg_resource) - in ciss_init_pci()
701 rman_get_start(sc->ciss_cfg_resource) + 1; in ciss_init_pci()
703 cbase = (uintptr_t)rman_get_virtual(sc->ciss_regs_resource); in ciss_init_pci()
704 csize = rman_get_end(sc->ciss_regs_resource) - in ciss_init_pci()
705 rman_get_start(sc->ciss_regs_resource) + 1; in ciss_init_pci()
711 * sanity-check the config structure. If it's OK, point to it. in ciss_init_pci()
717 sc->ciss_cfg = (struct ciss_config_table *)(cbase + cofs); in ciss_init_pci()
718 debug(1, "config struct at %p", sc->ciss_cfg); in ciss_init_pci()
724 sc->ciss_max_requests = min(CISS_MAX_REQUESTS, sc->ciss_cfg->max_outstanding_commands); in ciss_init_pci()
730 if (strncmp(sc->ciss_cfg->signature, "CISS", 4)) { in ciss_init_pci()
732 sc->ciss_cfg->signature[0], sc->ciss_cfg->signature[1], in ciss_init_pci()
733 sc->ciss_cfg->signature[2], sc->ciss_cfg->signature[3]); in ciss_init_pci()
740 if (!(sc->ciss_cfg->supported_methods & in ciss_init_pci()
743 sc->ciss_cfg->supported_methods); in ciss_init_pci()
761 supported_methods = sc->ciss_cfg->supported_methods; in ciss_init_pci()
768 sc->ciss_perf = (struct ciss_perf_config *)(cbase + cofs + in ciss_init_pci()
769 sc->ciss_cfg->transport_offset); in ciss_init_pci()
778 sc->ciss_cfg->supported_methods); in ciss_init_pci()
786 sc->ciss_cfg->requested_method = method; in ciss_init_pci()
787 sc->ciss_cfg->command_physlimit = 0; in ciss_init_pci()
788 sc->ciss_cfg->interrupt_coalesce_delay = CISS_INTERRUPT_COALESCE_DELAY; in ciss_init_pci()
789 sc->ciss_cfg->interrupt_coalesce_count = CISS_INTERRUPT_COALESCE_COUNT; in ciss_init_pci()
792 sc->ciss_cfg->host_driver |= CISS_DRIVER_SCSI_PREFETCH; in ciss_init_pci()
800 if ((sc->ciss_cfg->active_method & method) == 0) { in ciss_init_pci()
805 sc->ciss_cfg->active_method); in ciss_init_pci()
820 sc->ciss_irq_rid[0] = 0; in ciss_init_pci()
833 sc->ciss_interrupt_mask = CISS_TL_PERF_INTR_OPQ | CISS_TL_PERF_INTR_MSI; in ciss_init_pci()
841 sc->ciss_perf = NULL; in ciss_init_pci()
843 sc->ciss_interrupt_mask = sqmask; in ciss_init_pci()
854 if ((sc->ciss_irq_resource = in ciss_init_pci()
855 bus_alloc_resource_any(sc->ciss_dev, SYS_RES_IRQ, &sc->ciss_irq_rid[0], in ciss_init_pci()
861 if (bus_setup_intr(sc->ciss_dev, sc->ciss_irq_resource, in ciss_init_pci()
863 &sc->ciss_intr)) { in ciss_init_pci()
872 * Note that "simple" adapters can only address within a 32-bit in ciss_init_pci()
875 if (bus_dma_tag_create(bus_get_dma_tag(sc->ciss_dev),/* PCI parent */ in ciss_init_pci()
885 &sc->ciss_parent_dmat)) { in ciss_init_pci()
891 * Create DMA tag for mapping buffers into adapter-addressable in ciss_init_pci()
894 if (bus_dma_tag_create(sc->ciss_parent_dmat, /* parent */ in ciss_init_pci()
899 (CISS_MAX_SG_ELEMENTS - 1) * PAGE_SIZE, /* maxsize */ in ciss_init_pci()
903 busdma_lock_mutex, &sc->ciss_mtx, /* lockfunc, lockarg */ in ciss_init_pci()
904 &sc->ciss_buffer_dmat)) { in ciss_init_pci()
913 * Four interrupts are available, but we only use 1 right now. If MSI-X
922 i = ciss_lookup(sc->ciss_dev); in ciss_setup_msix()
930 val = pci_msix_count(sc->ciss_dev); in ciss_setup_msix()
932 val = pci_msi_count(sc->ciss_dev); in ciss_setup_msix()
933 device_printf(sc->ciss_dev, "got %d MSI messages]\n", val); in ciss_setup_msix()
938 if (pci_alloc_msix(sc->ciss_dev, &val) != 0) { in ciss_setup_msix()
939 if (pci_alloc_msi(sc->ciss_dev, &val) != 0) in ciss_setup_msix()
943 sc->ciss_msi = val; in ciss_setup_msix()
949 sc->ciss_irq_rid[i] = i + 1; in ciss_setup_msix()
961 struct ciss_perf_config *pc = sc->ciss_perf; in ciss_init_perf()
967 reply_size = sizeof(uint64_t) * sc->ciss_max_requests; in ciss_init_perf()
968 if (bus_dma_tag_create(sc->ciss_parent_dmat, /* parent */ in ciss_init_perf()
977 &sc->ciss_reply_dmat)) { in ciss_init_perf()
984 if (bus_dmamem_alloc(sc->ciss_reply_dmat, (void **)&sc->ciss_reply, in ciss_init_perf()
985 BUS_DMA_NOWAIT, &sc->ciss_reply_map)) { in ciss_init_perf()
989 bus_dmamap_load(sc->ciss_reply_dmat, sc->ciss_reply_map, sc->ciss_reply, in ciss_init_perf()
990 reply_size, ciss_command_map_helper, &sc->ciss_reply_phys, 0); in ciss_init_perf()
991 bzero(sc->ciss_reply, reply_size); in ciss_init_perf()
993 sc->ciss_cycle = 0x1; in ciss_init_perf()
994 sc->ciss_rqidx = 0; in ciss_init_perf()
1000 * for page-aligned i/o's, but since most i/o comes from the various pagers, in ciss_init_perf()
1003 pc->fetch_count[CISS_SG_FETCH_NONE] = (sizeof(struct ciss_command) + 15) / 16; in ciss_init_perf()
1004 pc->fetch_count[CISS_SG_FETCH_1] = in ciss_init_perf()
1006 pc->fetch_count[CISS_SG_FETCH_2] = in ciss_init_perf()
1008 pc->fetch_count[CISS_SG_FETCH_4] = in ciss_init_perf()
1010 pc->fetch_count[CISS_SG_FETCH_8] = in ciss_init_perf()
1012 pc->fetch_count[CISS_SG_FETCH_16] = in ciss_init_perf()
1014 pc->fetch_count[CISS_SG_FETCH_32] = in ciss_init_perf()
1016 pc->fetch_count[CISS_SG_FETCH_MAX] = (CISS_COMMAND_ALLOC_SIZE + 15) / 16; in ciss_init_perf()
1018 pc->rq_size = sc->ciss_max_requests; /* XXX less than the card supports? */ in ciss_init_perf()
1019 pc->rq_count = 1; /* XXX Hardcode for a single queue */ in ciss_init_perf()
1020 pc->rq_bank_hi = 0; in ciss_init_perf()
1021 pc->rq_bank_lo = 0; in ciss_init_perf()
1022 pc->rq[0].rq_addr_hi = 0x0; in ciss_init_perf()
1023 pc->rq[0].rq_addr_lo = sc->ciss_reply_phys; in ciss_init_perf()
1041 if (!(sc->ciss_cfg->active_method & CISS_TRANSPORT_METHOD_READY)) { in ciss_wait_adapter()
1043 for (i = 0; !(sc->ciss_cfg->active_method & CISS_TRANSPORT_METHOD_READY); i++) { in ciss_wait_adapter()
1119 for (i = 0; i < sc->ciss_max_logical_bus; i++) { in ciss_soft_reset()
1121 if (sc->ciss_controllers[i].physical.bus == 0) in ciss_soft_reset()
1131 cc = cr->cr_cc; in ciss_soft_reset()
1132 cc->header.address = sc->ciss_controllers[i]; in ciss_soft_reset()
1164 sc->ciss_max_requests, sc->ciss_cfg->max_outstanding_commands); in ciss_init_requests()
1169 if (bus_dma_tag_create(sc->ciss_parent_dmat, /* parent */ in ciss_init_requests()
1175 sc->ciss_max_requests, 1, /* maxsize, nsegments */ in ciss_init_requests()
1179 &sc->ciss_command_dmat)) { in ciss_init_requests()
1186 if (bus_dmamem_alloc(sc->ciss_command_dmat, (void **)&sc->ciss_command, in ciss_init_requests()
1187 BUS_DMA_NOWAIT, &sc->ciss_command_map)) { in ciss_init_requests()
1191 bus_dmamap_load(sc->ciss_command_dmat, sc->ciss_command_map,sc->ciss_command, in ciss_init_requests()
1192 CISS_COMMAND_ALLOC_SIZE * sc->ciss_max_requests, in ciss_init_requests()
1193 ciss_command_map_helper, &sc->ciss_command_phys, 0); in ciss_init_requests()
1194 bzero(sc->ciss_command, CISS_COMMAND_ALLOC_SIZE * sc->ciss_max_requests); in ciss_init_requests()
1200 for (i = 1; i < sc->ciss_max_requests; i++) { in ciss_init_requests()
1201 cr = &sc->ciss_request[i]; in ciss_init_requests()
1202 cr->cr_sc = sc; in ciss_init_requests()
1203 cr->cr_tag = i; in ciss_init_requests()
1204 cr->cr_cc = (struct ciss_command *)((uintptr_t)sc->ciss_command + in ciss_init_requests()
1206 cr->cr_ccphys = sc->ciss_command_phys + CISS_COMMAND_ALLOC_SIZE * i; in ciss_init_requests()
1207 bus_dmamap_create(sc->ciss_buffer_dmat, 0, &cr->cr_datamap); in ciss_init_requests()
1239 (void **)&sc->ciss_id, in ciss_identify_adapter()
1240 sizeof(*sc->ciss_id))) != 0) in ciss_identify_adapter()
1268 /* sanity-check reply */ in ciss_identify_adapter()
1269 if (!(sc->ciss_id->controller_flags & CONTROLLER_FLAGS_BIG_MAP_SUPPORT)) { in ciss_identify_adapter()
1277 sc->ciss_flags |= CISS_FLAG_FAKE_SYNCH; in ciss_identify_adapter()
1281 sc->ciss_flags |= CISS_FLAG_BMIC_ABORT; in ciss_identify_adapter()
1289 if (sc->ciss_cfg->max_logical_supported == 0) in ciss_identify_adapter()
1290 sc->ciss_cfg->max_logical_supported = CISS_MAX_LOGICAL; in ciss_identify_adapter()
1291 if (sc->ciss_cfg->max_physical_supported == 0) in ciss_identify_adapter()
1292 sc->ciss_cfg->max_physical_supported = CISS_MAX_PHYSICAL; in ciss_identify_adapter()
1296 sc->ciss_id->configured_logical_drives, in ciss_identify_adapter()
1297 (sc->ciss_id->configured_logical_drives == 1) ? "" : "s"); in ciss_identify_adapter()
1298 ciss_printf(sc, " firmware %4.4s\n", sc->ciss_id->running_firmware_revision); in ciss_identify_adapter()
1299 ciss_printf(sc, " %d SCSI channels\n", sc->ciss_id->scsi_chip_count); in ciss_identify_adapter()
1302 ciss_printf(sc, " %d FC channels\n", sc->ciss_id->fibre_chip_count); in ciss_identify_adapter()
1303 ciss_printf(sc, " %d enclosures\n", sc->ciss_id->bEnclosureCount); in ciss_identify_adapter()
1304 ciss_printf(sc, " %d expanders\n", sc->ciss_id->bExpanderCount); in ciss_identify_adapter()
1305 ciss_printf(sc, " maximum blocks: %d\n", sc->ciss_id->maximum_blocks); in ciss_identify_adapter()
1306 ciss_printf(sc, " controller clock: %d\n", sc->ciss_id->controller_clock); in ciss_identify_adapter()
1307 ciss_printf(sc, " %d MB controller memory\n", sc->ciss_id->total_controller_mem_mb); in ciss_identify_adapter()
1310 ciss_printf(sc, " signature '%.4s'\n", sc->ciss_cfg->signature); in ciss_identify_adapter()
1311 ciss_printf(sc, " valence %d\n", sc->ciss_cfg->valence); in ciss_identify_adapter()
1313 sc->ciss_cfg->supported_methods, in ciss_identify_adapter()
1316 sc->ciss_cfg->active_method, "\20\2simple\3performant\4MEMQ\n"); in ciss_identify_adapter()
1318 sc->ciss_cfg->command_physlimit); in ciss_identify_adapter()
1320 sc->ciss_cfg->interrupt_coalesce_delay); in ciss_identify_adapter()
1322 sc->ciss_cfg->interrupt_coalesce_count); in ciss_identify_adapter()
1324 sc->ciss_cfg->max_outstanding_commands); in ciss_identify_adapter()
1325 ciss_printf(sc, " bus types 0x%b\n", sc->ciss_cfg->bus_types, in ciss_identify_adapter()
1327 ciss_printf(sc, " server name '%.16s'\n", sc->ciss_cfg->server_name); in ciss_identify_adapter()
1328 ciss_printf(sc, " heartbeat 0x%x\n", sc->ciss_cfg->heartbeat); in ciss_identify_adapter()
1329 ciss_printf(sc, " max logical volumes: %d\n", sc->ciss_cfg->max_logical_supported); in ciss_identify_adapter()
1330 ciss_printf(sc, " max physical disks supported: %d\n", sc->ciss_cfg->max_physical_supported); in ciss_identify_adapter()
1331 …ciss_printf(sc, " max physical disks per logical volume: %d\n", sc->ciss_cfg->max_physical_per_lo… in ciss_identify_adapter()
1332 …ciss_printf(sc, " JBOD Support is %s\n", (sc->ciss_id->uiYetMoreControllerFlags & YMORE_CONTROLLE… in ciss_identify_adapter()
1334 …ciss_printf(sc, " JBOD Mode is %s\n", (sc->ciss_id->PowerUPNvramFlags & PWR_UP_FLAG_JBOD_ENABLED)… in ciss_identify_adapter()
1340 if (sc->ciss_id != NULL) { in ciss_identify_adapter()
1341 free(sc->ciss_id, CISS_MALLOC_CLASS); in ciss_identify_adapter()
1342 sc->ciss_id = NULL; in ciss_identify_adapter()
1358 struct ciss_report_cdb *crc; in ciss_report_luns() local
1384 cc = cr->cr_cc; in ciss_report_luns()
1385 cr->cr_data = cll; in ciss_report_luns()
1386 cr->cr_length = report_size; in ciss_report_luns()
1387 cr->cr_flags = CISS_REQ_DATAIN; in ciss_report_luns()
1389 cc->header.address.physical.mode = CISS_HDR_ADDRESS_MODE_PERIPHERAL; in ciss_report_luns()
1390 cc->header.address.physical.bus = 0; in ciss_report_luns()
1391 cc->header.address.physical.target = 0; in ciss_report_luns()
1392 cc->cdb.cdb_length = sizeof(*crc); in ciss_report_luns()
1393 cc->cdb.type = CISS_CDB_TYPE_COMMAND; in ciss_report_luns()
1394 cc->cdb.attribute = CISS_CDB_ATTRIBUTE_SIMPLE; in ciss_report_luns()
1395 cc->cdb.direction = CISS_CDB_DIRECTION_READ; in ciss_report_luns()
1396 cc->cdb.timeout = 30; /* XXX better suggestions? */ in ciss_report_luns()
1398 crc = (struct ciss_report_cdb *)&(cc->cdb.cdb[0]); in ciss_report_luns()
1399 bzero(crc, sizeof(*crc)); in ciss_report_luns()
1400 crc->opcode = opcode; in ciss_report_luns()
1401 crc->length = htonl(report_size); /* big-endian field */ in ciss_report_luns()
1402 cll->list_size = htonl(report_size - sizeof(*cll)); /* big-endian field */ in ciss_report_luns()
1423 sc->ciss_cfg->max_logical_supported); in ciss_report_luns()
1457 sc->ciss_cfg->max_logical_supported); in ciss_init_logical()
1463 /* sanity-check reply */ in ciss_init_logical()
1464 ndrives = (ntohl(cll->list_size) / sizeof(union ciss_device_address)); in ciss_init_logical()
1465 if ((ndrives < 0) || (ndrives > sc->ciss_cfg->max_logical_supported)) { in ciss_init_logical()
1467 ndrives, sc->ciss_cfg->max_logical_supported); in ciss_init_logical()
1480 sc->ciss_logical = in ciss_init_logical()
1481 malloc(sc->ciss_max_logical_bus * sizeof(struct ciss_ldrive *), in ciss_init_logical()
1483 if (sc->ciss_logical == NULL) { in ciss_init_logical()
1488 for (i = 0; i < sc->ciss_max_logical_bus; i++) { in ciss_init_logical()
1489 sc->ciss_logical[i] = in ciss_init_logical()
1490 malloc(sc->ciss_cfg->max_logical_supported * in ciss_init_logical()
1493 if (sc->ciss_logical[i] == NULL) { in ciss_init_logical()
1498 for (j = 0; j < sc->ciss_cfg->max_logical_supported; j++) in ciss_init_logical()
1499 sc->ciss_logical[i][j].cl_status = CISS_LD_NONEXISTENT; in ciss_init_logical()
1502 for (i = 0; i < sc->ciss_cfg->max_logical_supported; i++) { in ciss_init_logical()
1507 bus = CISS_LUN_TO_BUS(cll->lun[i].logical.lun); in ciss_init_logical()
1508 target = CISS_LUN_TO_TARGET(cll->lun[i].logical.lun); in ciss_init_logical()
1509 ld = &sc->ciss_logical[bus][target]; in ciss_init_logical()
1511 ld->cl_address = cll->lun[i]; in ciss_init_logical()
1512 ld->cl_controller = &sc->ciss_controllers[bus]; in ciss_init_logical()
1518 if (ld->cl_lstatus->media_exchanged) in ciss_init_logical()
1542 sc->ciss_cfg->max_physical_supported); in ciss_init_physical()
1548 nphys = (ntohl(cll->list_size) / sizeof(union ciss_device_address)); in ciss_init_physical()
1555 /* Per-controller highest target number seen */ in ciss_init_physical()
1556 sc->ciss_max_physical_target = 0; in ciss_init_physical()
1568 * ciss_controllers[] - indexed by logical bus in ciss_init_physical()
1569 * ciss_cam_sim[] - indexed by both logical and physical, with physical in ciss_init_physical()
1571 * ciss_logical[][] - indexed by logical bus in ciss_init_physical()
1572 * ciss_physical[][] - indexed by physical bus in ciss_init_physical()
1591 sc->ciss_max_logical_bus = 1; in ciss_init_physical()
1593 if (cll->lun[i].physical.extra_address == 0) { in ciss_init_physical()
1594 bus = cll->lun[i].physical.bus; in ciss_init_physical()
1595 sc->ciss_max_logical_bus = max(sc->ciss_max_logical_bus, bus) + 1; in ciss_init_physical()
1597 bus = CISS_EXTRA_BUS2(cll->lun[i].physical.extra_address); in ciss_init_physical()
1598 sc->ciss_max_physical_bus = max(sc->ciss_max_physical_bus, bus); in ciss_init_physical()
1602 sc->ciss_controllers = in ciss_init_physical()
1603 malloc(sc->ciss_max_logical_bus * sizeof (union ciss_device_address), in ciss_init_physical()
1606 if (sc->ciss_controllers == NULL) { in ciss_init_physical()
1614 if (cll->lun[i].physical.extra_address == 0) { in ciss_init_physical()
1615 sc->ciss_controllers[cll->lun[i].physical.bus] = cll->lun[i]; in ciss_init_physical()
1619 sc->ciss_physical = in ciss_init_physical()
1620 malloc(sc->ciss_max_physical_bus * sizeof(struct ciss_pdrive *), in ciss_init_physical()
1622 if (sc->ciss_physical == NULL) { in ciss_init_physical()
1628 for (i = 0; i < sc->ciss_max_physical_bus; i++) { in ciss_init_physical()
1629 sc->ciss_physical[i] = in ciss_init_physical()
1632 if (sc->ciss_physical[i] == NULL) { in ciss_init_physical()
1641 ciss_printf(sc, "max physical target id: %d\n", sc->ciss_max_physical_target); in ciss_init_physical()
1657 nphys = (ntohl(cll->list_size) / sizeof(union ciss_device_address)); in ciss_filter_physical()
1659 if (cll->lun[i].physical.extra_address == 0) in ciss_filter_physical()
1674 ea = cll->lun[i].physical.extra_address; in ciss_filter_physical()
1679 (cll->lun[i].physical.mode == CISS_HDR_ADDRESS_MODE_MASK_PERIPHERAL)) in ciss_filter_physical()
1687 bus = CISS_EXTRA_BUS2(ea) - 1; in ciss_filter_physical()
1689 sc->ciss_physical[bus][target].cp_address = cll->lun[i]; in ciss_filter_physical()
1690 sc->ciss_physical[bus][target].cp_online = 1; in ciss_filter_physical()
1692 if ((target > sc->ciss_max_physical_target) && in ciss_filter_physical()
1693 (cll->lun[i].physical.mode != CISS_HDR_ADDRESS_MODE_MASK_PERIPHERAL)) in ciss_filter_physical()
1694 sc->ciss_max_physical_target = target; in ciss_filter_physical()
1711 bzero(&ld->cl_geometry, sizeof(ld->cl_geometry)); in ciss_inquiry_logical()
1716 cc = cr->cr_cc; in ciss_inquiry_logical()
1717 cr->cr_data = &ld->cl_geometry; in ciss_inquiry_logical()
1718 cr->cr_length = sizeof(ld->cl_geometry); in ciss_inquiry_logical()
1719 cr->cr_flags = CISS_REQ_DATAIN; in ciss_inquiry_logical()
1721 cc->header.address = ld->cl_address; in ciss_inquiry_logical()
1722 cc->cdb.cdb_length = 6; in ciss_inquiry_logical()
1723 cc->cdb.type = CISS_CDB_TYPE_COMMAND; in ciss_inquiry_logical()
1724 cc->cdb.attribute = CISS_CDB_ATTRIBUTE_SIMPLE; in ciss_inquiry_logical()
1725 cc->cdb.direction = CISS_CDB_DIRECTION_READ; in ciss_inquiry_logical()
1726 cc->cdb.timeout = 30; in ciss_inquiry_logical()
1728 inq = (struct scsi_inquiry *)&(cc->cdb.cdb[0]); in ciss_inquiry_logical()
1729 inq->opcode = INQUIRY; in ciss_inquiry_logical()
1730 inq->byte2 = SI_EVPD; in ciss_inquiry_logical()
1731 inq->page_code = CISS_VPD_LOGICAL_DRIVE_GEOMETRY; in ciss_inquiry_logical()
1732 scsi_ulto2b(sizeof(ld->cl_geometry), inq->length); in ciss_inquiry_logical()
1777 (void **)&ld->cl_ldrive, in ciss_identify_logical()
1778 sizeof(*ld->cl_ldrive))) != 0) in ciss_identify_logical()
1780 cc = cr->cr_cc; in ciss_identify_logical()
1781 cc->header.address = *ld->cl_controller; /* target controller */ in ciss_identify_logical()
1782 cbc = (struct ciss_bmic_cdb *)&(cc->cdb.cdb[0]); in ciss_identify_logical()
1783 cbc->log_drive = CISS_LUN_TO_TARGET(ld->cl_address.logical.lun); in ciss_identify_logical()
1829 CISS_LUN_TO_BUS(ld->cl_address.logical.lun), in ciss_identify_logical()
1830 CISS_LUN_TO_TARGET(ld->cl_address.logical.lun), in ciss_identify_logical()
1831 ciss_name_ldrive_org(ld->cl_ldrive->fault_tolerance), in ciss_identify_logical()
1832 ((ld->cl_ldrive->blocks_available / (1024 * 1024)) * in ciss_identify_logical()
1833 ld->cl_ldrive->block_size)); in ciss_identify_logical()
1839 /* make the drive not-exist */ in ciss_identify_logical()
1840 ld->cl_status = CISS_LD_NONEXISTENT; in ciss_identify_logical()
1841 if (ld->cl_ldrive != NULL) { in ciss_identify_logical()
1842 free(ld->cl_ldrive, CISS_MALLOC_CLASS); in ciss_identify_logical()
1843 ld->cl_ldrive = NULL; in ciss_identify_logical()
1845 if (ld->cl_lstatus != NULL) { in ciss_identify_logical()
1846 free(ld->cl_lstatus, CISS_MALLOC_CLASS); in ciss_identify_logical()
1847 ld->cl_lstatus = NULL; in ciss_identify_logical()
1873 (void **)&ld->cl_lstatus, in ciss_get_ldrive_status()
1874 sizeof(*ld->cl_lstatus))) != 0) in ciss_get_ldrive_status()
1876 cc = cr->cr_cc; in ciss_get_ldrive_status()
1877 cc->header.address = *ld->cl_controller; /* target controller */ in ciss_get_ldrive_status()
1878 cbc = (struct ciss_bmic_cdb *)&(cc->cdb.cdb[0]); in ciss_get_ldrive_status()
1879 cbc->log_drive = CISS_LUN_TO_TARGET(ld->cl_address.logical.lun); in ciss_get_ldrive_status()
1912 ld->cl_status = ciss_decode_ldrive_status(ld->cl_lstatus->status); in ciss_get_ldrive_status()
1956 ldrive = CISS_LUN_TO_TARGET(ld->cl_address.logical.lun); in ciss_accept_media()
1966 cc = cr->cr_cc; in ciss_accept_media()
1967 cc->header.address = *ld->cl_controller; /* target controller */ in ciss_accept_media()
1968 cbc = (struct ciss_bmic_cdb *)&(cc->cdb.cdb[0]); in ciss_accept_media()
1969 cbc->log_drive = ldrive; in ciss_accept_media()
1988 ciss_printf(cr->cr_sc, "error accepting media into failed logical drive (%s)\n", in ciss_accept_media()
2011 sc->ciss_flags |= CISS_FLAG_ABORTING; in ciss_free()
2014 callout_stop(&sc->ciss_periodic); in ciss_free()
2022 if (sc->ciss_cam_sim) { in ciss_free()
2023 for (i = 0; i < sc->ciss_max_logical_bus; i++) { in ciss_free()
2024 if (sc->ciss_cam_sim[i]) { in ciss_free()
2025 xpt_bus_deregister(cam_sim_path(sc->ciss_cam_sim[i])); in ciss_free()
2026 cam_sim_free(sc->ciss_cam_sim[i], 0); in ciss_free()
2029 for (i = CISS_PHYSICAL_BASE; i < sc->ciss_max_physical_bus + in ciss_free()
2031 if (sc->ciss_cam_sim[i]) { in ciss_free()
2032 xpt_bus_deregister(cam_sim_path(sc->ciss_cam_sim[i])); in ciss_free()
2033 cam_sim_free(sc->ciss_cam_sim[i], 0); in ciss_free()
2036 free(sc->ciss_cam_sim, CISS_MALLOC_CLASS); in ciss_free()
2038 if (sc->ciss_cam_devq) in ciss_free()
2039 cam_simq_free(sc->ciss_cam_devq); in ciss_free()
2042 mtx_unlock(&sc->ciss_mtx); in ciss_free()
2043 if (sc->ciss_dev_t != NULL) in ciss_free()
2044 destroy_dev(sc->ciss_dev_t); in ciss_free()
2047 callout_drain(&sc->ciss_periodic); in ciss_free()
2048 mtx_destroy(&sc->ciss_mtx); in ciss_free()
2051 if (sc->ciss_id != NULL) in ciss_free()
2052 free(sc->ciss_id, CISS_MALLOC_CLASS); in ciss_free()
2055 if (sc->ciss_regs_resource != NULL) in ciss_free()
2056 bus_release_resource(sc->ciss_dev, SYS_RES_MEMORY, in ciss_free()
2057 sc->ciss_regs_rid, sc->ciss_regs_resource); in ciss_free()
2058 if (sc->ciss_cfg_resource != NULL) in ciss_free()
2059 bus_release_resource(sc->ciss_dev, SYS_RES_MEMORY, in ciss_free()
2060 sc->ciss_cfg_rid, sc->ciss_cfg_resource); in ciss_free()
2061 if (sc->ciss_intr != NULL) in ciss_free()
2062 bus_teardown_intr(sc->ciss_dev, sc->ciss_irq_resource, sc->ciss_intr); in ciss_free()
2063 if (sc->ciss_irq_resource != NULL) in ciss_free()
2064 bus_release_resource(sc->ciss_dev, SYS_RES_IRQ, in ciss_free()
2065 sc->ciss_irq_rid[0], sc->ciss_irq_resource); in ciss_free()
2066 if (sc->ciss_msi) in ciss_free()
2067 pci_release_msi(sc->ciss_dev); in ciss_free()
2070 bus_dmamap_destroy(sc->ciss_buffer_dmat, cr->cr_datamap); in ciss_free()
2071 if (sc->ciss_buffer_dmat) in ciss_free()
2072 bus_dma_tag_destroy(sc->ciss_buffer_dmat); in ciss_free()
2075 if (sc->ciss_command != NULL) { in ciss_free()
2076 bus_dmamap_unload(sc->ciss_command_dmat, sc->ciss_command_map); in ciss_free()
2077 bus_dmamem_free(sc->ciss_command_dmat, sc->ciss_command, sc->ciss_command_map); in ciss_free()
2079 if (sc->ciss_command_dmat) in ciss_free()
2080 bus_dma_tag_destroy(sc->ciss_command_dmat); in ciss_free()
2082 if (sc->ciss_reply) { in ciss_free()
2083 bus_dmamap_unload(sc->ciss_reply_dmat, sc->ciss_reply_map); in ciss_free()
2084 bus_dmamem_free(sc->ciss_reply_dmat, sc->ciss_reply, sc->ciss_reply_map); in ciss_free()
2086 if (sc->ciss_reply_dmat) in ciss_free()
2087 bus_dma_tag_destroy(sc->ciss_reply_dmat); in ciss_free()
2090 if (sc->ciss_parent_dmat) in ciss_free()
2091 bus_dma_tag_destroy(sc->ciss_parent_dmat); in ciss_free()
2092 if (sc->ciss_logical) { in ciss_free()
2093 for (i = 0; i < sc->ciss_max_logical_bus; i++) { in ciss_free()
2094 for (j = 0; j < sc->ciss_cfg->max_logical_supported; j++) { in ciss_free()
2095 if (sc->ciss_logical[i][j].cl_ldrive) in ciss_free()
2096 free(sc->ciss_logical[i][j].cl_ldrive, CISS_MALLOC_CLASS); in ciss_free()
2097 if (sc->ciss_logical[i][j].cl_lstatus) in ciss_free()
2098 free(sc->ciss_logical[i][j].cl_lstatus, CISS_MALLOC_CLASS); in ciss_free()
2100 free(sc->ciss_logical[i], CISS_MALLOC_CLASS); in ciss_free()
2102 free(sc->ciss_logical, CISS_MALLOC_CLASS); in ciss_free()
2105 if (sc->ciss_physical) { in ciss_free()
2106 for (i = 0; i < sc->ciss_max_physical_bus; i++) in ciss_free()
2107 free(sc->ciss_physical[i], CISS_MALLOC_CLASS); in ciss_free()
2108 free(sc->ciss_physical, CISS_MALLOC_CLASS); in ciss_free()
2111 if (sc->ciss_controllers) in ciss_free()
2112 free(sc->ciss_controllers, CISS_MALLOC_CLASS); in ciss_free()
2133 debug(2, "post command %d tag %d ", cr->cr_tag, cr->cr_cc->header.host_tag); in ciss_start()
2182 if (index >= sc->ciss_max_requests) { in ciss_done()
2186 cr = &(sc->ciss_request[index]); in ciss_done()
2187 cc = cr->cr_cc; in ciss_done()
2188 cc->header.host_tag = tag; /* not updated by adapter */ in ciss_done()
2208 tag = sc->ciss_reply[sc->ciss_rqidx]; in ciss_perf_done()
2209 if ((tag & CISS_CYCLE_MASK) != sc->ciss_cycle) in ciss_perf_done()
2214 if (index < sc->ciss_max_requests) { in ciss_perf_done()
2215 cr = &(sc->ciss_request[index]); in ciss_perf_done()
2216 cc = cr->cr_cc; in ciss_perf_done()
2217 cc->header.host_tag = tag; /* not updated by adapter */ in ciss_perf_done()
2222 if (++sc->ciss_rqidx == sc->ciss_max_requests) { in ciss_perf_done()
2223 sc->ciss_rqidx = 0; in ciss_perf_done()
2224 sc->ciss_cycle ^= 1; in ciss_perf_done()
2245 mtx_lock(&sc->ciss_mtx); in ciss_intr()
2247 mtx_unlock(&sc->ciss_mtx); in ciss_intr()
2272 mtx_lock(&sc->ciss_mtx); in ciss_perf_msi_intr()
2274 mtx_unlock(&sc->ciss_mtx); in ciss_perf_msi_intr()
2282 * - by invoking a callback function (cr_complete is non-null)
2283 * - by waking up a sleeper (cr_flags has CISS_REQ_SLEEP set)
2284 * - by clearing the CISS_REQ_POLL flag in interrupt/timeout context
2302 if ((cr->cr_flags & CISS_REQ_BUSY) == 0) in ciss_complete()
2303 ciss_printf(sc, "WARNING: completing non-busy request\n"); in ciss_complete()
2304 cr->cr_flags &= ~CISS_REQ_BUSY; in ciss_complete()
2309 if (cr->cr_complete != NULL) { in ciss_complete()
2310 cr->cr_complete(cr); in ciss_complete()
2317 if (cr->cr_flags & CISS_REQ_SLEEP) { in ciss_complete()
2318 cr->cr_flags &= ~CISS_REQ_SLEEP; in ciss_complete()
2326 if (cr->cr_flags & CISS_REQ_POLL) { in ciss_complete()
2327 cr->cr_flags &= ~CISS_REQ_POLL; in ciss_complete()
2352 cc = cr->cr_cc; in _ciss_report_request()
2353 ce = (struct ciss_error_info *)&(cc->sg[0]); in _ciss_report_request()
2359 if ((cc->header.host_tag & CISS_HDR_HOST_TAG_ERROR) && in _ciss_report_request()
2360 ((ce->command_status == CISS_CMD_STATUS_DATA_OVERRUN) || in _ciss_report_request()
2361 (ce->command_status == CISS_CMD_STATUS_DATA_UNDERRUN)) && in _ciss_report_request()
2362 ((cc->cdb.cdb[0] == CISS_OPCODE_REPORT_LOGICAL_LUNS) || in _ciss_report_request()
2363 (cc->cdb.cdb[0] == CISS_OPCODE_REPORT_PHYSICAL_LUNS) || in _ciss_report_request()
2364 (cc->cdb.cdb[0] == RECEIVE_DIAGNOSTIC) || in _ciss_report_request()
2365 (cc->cdb.cdb[0] == INQUIRY))) { in _ciss_report_request()
2366 cc->header.host_tag &= ~CISS_HDR_HOST_TAG_ERROR; in _ciss_report_request()
2374 if (!(cc->header.host_tag & CISS_HDR_HOST_TAG_ERROR)) { in _ciss_report_request()
2382 *command_status = ce->command_status; in _ciss_report_request()
2384 if (ce->command_status == CISS_CMD_STATUS_DATA_UNDERRUN) { in _ciss_report_request()
2386 } else if (ce->command_status == CISS_CMD_STATUS_TARGET_STATUS) { in _ciss_report_request()
2387 *scsi_status = ce->scsi_status; in _ciss_report_request()
2389 *scsi_status = -1; in _ciss_report_request()
2392 if ((bootverbose || ciss_verbose > 3 || (ciss_verbose > 2 && ce->scsi_status != 0)) && in _ciss_report_request()
2393 (ce->command_status != CISS_CMD_STATUS_DATA_UNDERRUN)) { in _ciss_report_request()
2394 ciss_printf(cr->cr_sc, "command status 0x%x (%s) scsi status 0x%x (opcode 0x%02x)\n", in _ciss_report_request()
2395 ce->command_status, ciss_name_command_status(ce->command_status), in _ciss_report_request()
2396 ce->scsi_status, in _ciss_report_request()
2397 cc->cdb.cdb[0]); in _ciss_report_request()
2399 if (ce->command_status == CISS_CMD_STATUS_INVALID_COMMAND) { in _ciss_report_request()
2400 ciss_printf(cr->cr_sc, "invalid command, offense size %d at %d, value 0x%x, function %s\n", in _ciss_report_request()
2401 ce->additional_error_info.invalid_command.offense_size, in _ciss_report_request()
2402 ce->additional_error_info.invalid_command.offense_offset, in _ciss_report_request()
2403 ce->additional_error_info.invalid_command.offense_value, in _ciss_report_request()
2422 if (cr->cr_sc->ciss_flags & CISS_FLAG_RUNNING) { in ciss_synch_request()
2444 sc = cr->cr_sc; in ciss_poll_request()
2445 cr->cr_flags |= CISS_REQ_POLL; in ciss_poll_request()
2450 if (sc->ciss_perf) in ciss_poll_request()
2455 if (!(cr->cr_flags & CISS_REQ_POLL)) in ciss_poll_request()
2458 } while (timeout-- >= 0); in ciss_poll_request()
2475 cr->cr_flags |= CISS_REQ_SLEEP; in ciss_wait_request()
2479 while ((cr->cr_flags & CISS_REQ_SLEEP) && (error != EWOULDBLOCK)) { in ciss_wait_request()
2480 error = msleep_sbt(cr, &cr->cr_sc->ciss_mtx, PRIBIO, "cissREQ", in ciss_wait_request()
2502 if ((error = ciss_get_request(ar->cr_sc, &cr)) != 0)
2506 cc = cr->cr_cc;
2507 cc->header.address.mode.mode = CISS_HDR_ADDRESS_MODE_PERIPHERAL; /* addressing? */
2508 cc->header.address.physical.target = 0;
2509 cc->header.address.physical.bus = 0;
2510 cc->cdb.cdb_length = sizeof(*cmc);
2511 cc->cdb.type = CISS_CDB_TYPE_MESSAGE;
2512 cc->cdb.attribute = CISS_CDB_ATTRIBUTE_SIMPLE;
2513 cc->cdb.direction = CISS_CDB_DIRECTION_NONE;
2514 cc->cdb.timeout = 30;
2516 cmc = (struct ciss_message_cdb *)&(cc->cdb.cdb[0]);
2517 cmc->opcode = CISS_OPCODE_MESSAGE_ABORT;
2518 cmc->type = CISS_MESSAGE_ABORT_TASK;
2519 cmc->abort_tag = ar->cr_tag; /* endianness?? */
2551 cr->cr_data = NULL; in ciss_get_request()
2552 cr->cr_flags = 0; in ciss_get_request()
2553 cr->cr_complete = NULL; in ciss_get_request()
2554 cr->cr_private = NULL; in ciss_get_request()
2555 cr->cr_sg_tag = CISS_SG_MAX; /* Backstop to prevent accidents */ in ciss_get_request()
2574 cc = cr->cr_cc; in ciss_preen_command()
2575 cc->header.sg_in_list = 0; /* kinda inefficient this way */ in ciss_preen_command()
2576 cc->header.sg_total = 0; in ciss_preen_command()
2577 cc->header.host_tag = cr->cr_tag << 2; in ciss_preen_command()
2578 cc->header.host_tag_zeroes = 0; in ciss_preen_command()
2579 bzero(&(cc->sg[0]), CISS_COMMAND_ALLOC_SIZE - sizeof(struct ciss_command)); in ciss_preen_command()
2580 cmdphys = cr->cr_ccphys; in ciss_preen_command()
2581 cc->error_info.error_info_address = cmdphys + sizeof(struct ciss_command); in ciss_preen_command()
2582 cc->error_info.error_info_length = CISS_COMMAND_ALLOC_SIZE - sizeof(struct ciss_command); in ciss_preen_command()
2643 cr->cr_data = buf; in ciss_get_bmic_request()
2644 cr->cr_length = bufsize; in ciss_get_bmic_request()
2646 cr->cr_flags = CISS_REQ_DATAIN; in ciss_get_bmic_request()
2648 cc = cr->cr_cc; in ciss_get_bmic_request()
2649 cc->header.address.physical.mode = CISS_HDR_ADDRESS_MODE_PERIPHERAL; in ciss_get_bmic_request()
2650 cc->header.address.physical.bus = 0; in ciss_get_bmic_request()
2651 cc->header.address.physical.target = 0; in ciss_get_bmic_request()
2652 cc->cdb.cdb_length = sizeof(*cbc); in ciss_get_bmic_request()
2653 cc->cdb.type = CISS_CDB_TYPE_COMMAND; in ciss_get_bmic_request()
2654 cc->cdb.attribute = CISS_CDB_ATTRIBUTE_SIMPLE; in ciss_get_bmic_request()
2655 cc->cdb.direction = dataout ? CISS_CDB_DIRECTION_WRITE : CISS_CDB_DIRECTION_READ; in ciss_get_bmic_request()
2656 cc->cdb.timeout = 0; in ciss_get_bmic_request()
2658 cbc = (struct ciss_bmic_cdb *)&(cc->cdb.cdb[0]); in ciss_get_bmic_request()
2660 cbc->opcode = dataout ? CISS_ARRAY_CONTROLLER_WRITE : CISS_ARRAY_CONTROLLER_READ; in ciss_get_bmic_request()
2661 cbc->bmic_opcode = opcode; in ciss_get_bmic_request()
2662 cbc->size = htons((u_int16_t)bufsize); in ciss_get_bmic_request()
2695 msleep(sc, &sc->ciss_mtx, PPAUSE, "cissREQ", hz); in ciss_user_command()
2696 cc = cr->cr_cc; in ciss_user_command()
2699 * Allocate an in-kernel databuffer if required, copy in user data. in ciss_user_command()
2701 mtx_unlock(&sc->ciss_mtx); in ciss_user_command()
2702 cr->cr_length = ioc->buf_size; in ciss_user_command()
2703 if (ioc->buf_size > 0) { in ciss_user_command()
2704 if ((cr->cr_data = malloc(ioc->buf_size, CISS_MALLOC_CLASS, M_NOWAIT)) == NULL) { in ciss_user_command()
2708 if ((error = copyin(ioc->buf, cr->cr_data, ioc->buf_size))) { in ciss_user_command()
2709 debug(0, "copyin: bad data buffer %p/%d", ioc->buf, ioc->buf_size); in ciss_user_command()
2717 bcopy(&ioc->LUN_info, &cc->header.address, sizeof(cc->header.address)); in ciss_user_command()
2718 bcopy(&ioc->Request, &cc->cdb, sizeof(cc->cdb)); in ciss_user_command()
2721 mtx_lock(&sc->ciss_mtx); in ciss_user_command()
2727 debug(0, "request failed - %d", error); in ciss_user_command()
2734 ce = (struct ciss_error_info *)&(cc->sg[0]); in ciss_user_command()
2735 if ((cc->header.host_tag & CISS_HDR_HOST_TAG_ERROR) == 0) in ciss_user_command()
2741 bcopy(ce, &ioc->error_info, sizeof(*ce)); in ciss_user_command()
2742 mtx_unlock(&sc->ciss_mtx); in ciss_user_command()
2743 if ((ioc->buf_size > 0) && in ciss_user_command()
2744 (error = copyout(cr->cr_data, ioc->buf, ioc->buf_size))) { in ciss_user_command()
2745 debug(0, "copyout: bad data buffer %p/%d", ioc->buf, ioc->buf_size); in ciss_user_command()
2753 mtx_lock(&sc->ciss_mtx); in ciss_user_command()
2756 if ((cr != NULL) && (cr->cr_data != NULL)) in ciss_user_command()
2757 free(cr->cr_data, CISS_MALLOC_CLASS); in ciss_user_command()
2764 * Map a request into bus-visible space, initialise the scatter/gather
2775 sc = cr->cr_sc; in ciss_map_request()
2778 if (cr->cr_flags & CISS_REQ_MAPPED) in ciss_map_request()
2781 cr->cr_flags |= CISS_REQ_MAPPED; in ciss_map_request()
2783 bus_dmamap_sync(sc->ciss_command_dmat, sc->ciss_command_map, in ciss_map_request()
2786 if (cr->cr_data != NULL) { in ciss_map_request()
2787 if (cr->cr_flags & CISS_REQ_CCB) in ciss_map_request()
2788 error = bus_dmamap_load_ccb(sc->ciss_buffer_dmat, in ciss_map_request()
2789 cr->cr_datamap, cr->cr_data, in ciss_map_request()
2792 error = bus_dmamap_load(sc->ciss_buffer_dmat, cr->cr_datamap, in ciss_map_request()
2793 cr->cr_data, cr->cr_length, in ciss_map_request()
2801 cr->cr_sg_tag = CISS_SG_NONE; in ciss_map_request()
2802 cr->cr_flags |= CISS_REQ_BUSY; in ciss_map_request()
2803 if (sc->ciss_perf) in ciss_map_request()
2806 CISS_TL_SIMPLE_POST_CMD(sc, cr->cr_ccphys); in ciss_map_request()
2823 sc = cr->cr_sc; in ciss_request_map_helper()
2824 cc = cr->cr_cc; in ciss_request_map_helper()
2827 cc->sg[i].address = segs[i].ds_addr; in ciss_request_map_helper()
2828 cc->sg[i].length = segs[i].ds_len; in ciss_request_map_helper()
2829 cc->sg[i].extension = 0; in ciss_request_map_helper()
2832 cc->header.sg_in_list = nseg; in ciss_request_map_helper()
2833 cc->header.sg_total = nseg; in ciss_request_map_helper()
2835 if (cr->cr_flags & CISS_REQ_DATAIN) in ciss_request_map_helper()
2836 bus_dmamap_sync(sc->ciss_buffer_dmat, cr->cr_datamap, BUS_DMASYNC_PREREAD); in ciss_request_map_helper()
2837 if (cr->cr_flags & CISS_REQ_DATAOUT) in ciss_request_map_helper()
2838 bus_dmamap_sync(sc->ciss_buffer_dmat, cr->cr_datamap, BUS_DMASYNC_PREWRITE); in ciss_request_map_helper()
2841 cr->cr_sg_tag = CISS_SG_NONE; in ciss_request_map_helper()
2843 cr->cr_sg_tag = CISS_SG_1; in ciss_request_map_helper()
2845 cr->cr_sg_tag = CISS_SG_2; in ciss_request_map_helper()
2847 cr->cr_sg_tag = CISS_SG_4; in ciss_request_map_helper()
2849 cr->cr_sg_tag = CISS_SG_8; in ciss_request_map_helper()
2851 cr->cr_sg_tag = CISS_SG_16; in ciss_request_map_helper()
2853 cr->cr_sg_tag = CISS_SG_32; in ciss_request_map_helper()
2855 cr->cr_sg_tag = CISS_SG_MAX; in ciss_request_map_helper()
2860 cr->cr_flags |= CISS_REQ_BUSY; in ciss_request_map_helper()
2861 if (sc->ciss_perf) in ciss_request_map_helper()
2864 CISS_TL_SIMPLE_POST_CMD(sc, cr->cr_ccphys); in ciss_request_map_helper()
2868 * Unmap a request from bus-visible space.
2877 sc = cr->cr_sc; in ciss_unmap_request()
2880 if ((cr->cr_flags & CISS_REQ_MAPPED) == 0) in ciss_unmap_request()
2883 bus_dmamap_sync(sc->ciss_command_dmat, sc->ciss_command_map, in ciss_unmap_request()
2886 if (cr->cr_data == NULL) in ciss_unmap_request()
2889 if (cr->cr_flags & CISS_REQ_DATAIN) in ciss_unmap_request()
2890 bus_dmamap_sync(sc->ciss_buffer_dmat, cr->cr_datamap, BUS_DMASYNC_POSTREAD); in ciss_unmap_request()
2891 if (cr->cr_flags & CISS_REQ_DATAOUT) in ciss_unmap_request()
2892 bus_dmamap_sync(sc->ciss_buffer_dmat, cr->cr_datamap, BUS_DMASYNC_POSTWRITE); in ciss_unmap_request()
2894 bus_dmamap_unload(sc->ciss_buffer_dmat, cr->cr_datamap); in ciss_unmap_request()
2896 cr->cr_flags &= ~CISS_REQ_MAPPED; in ciss_unmap_request()
2915 if ((sc->ciss_cam_devq = cam_simq_alloc(sc->ciss_max_requests - 2)) == NULL) { in ciss_cam_init()
2929 maxbus = max(sc->ciss_max_logical_bus, sc->ciss_max_physical_bus + in ciss_cam_init()
2931 sc->ciss_cam_sim = malloc(maxbus * sizeof(struct cam_sim*), in ciss_cam_init()
2933 if (sc->ciss_cam_sim == NULL) { in ciss_cam_init()
2938 for (i = 0; i < sc->ciss_max_logical_bus; i++) { in ciss_cam_init()
2939 if ((sc->ciss_cam_sim[i] = cam_sim_alloc(ciss_cam_action, ciss_cam_poll, in ciss_cam_init()
2941 device_get_unit(sc->ciss_dev), in ciss_cam_init()
2942 &sc->ciss_mtx, in ciss_cam_init()
2944 sc->ciss_max_requests - 2, in ciss_cam_init()
2945 sc->ciss_cam_devq)) == NULL) { in ciss_cam_init()
2953 mtx_lock(&sc->ciss_mtx); in ciss_cam_init()
2954 if (i == 0 || sc->ciss_controllers[i].physical.bus != 0) { in ciss_cam_init()
2955 if (xpt_bus_register(sc->ciss_cam_sim[i], sc->ciss_dev, i) != 0) { in ciss_cam_init()
2957 mtx_unlock(&sc->ciss_mtx); in ciss_cam_init()
2961 mtx_unlock(&sc->ciss_mtx); in ciss_cam_init()
2964 for (i = CISS_PHYSICAL_BASE; i < sc->ciss_max_physical_bus + in ciss_cam_init()
2966 if ((sc->ciss_cam_sim[i] = cam_sim_alloc(ciss_cam_action, ciss_cam_poll, in ciss_cam_init()
2968 device_get_unit(sc->ciss_dev), in ciss_cam_init()
2969 &sc->ciss_mtx, 1, in ciss_cam_init()
2970 sc->ciss_max_requests - 2, in ciss_cam_init()
2971 sc->ciss_cam_devq)) == NULL) { in ciss_cam_init()
2976 mtx_lock(&sc->ciss_mtx); in ciss_cam_init()
2977 if (xpt_bus_register(sc->ciss_cam_sim[i], sc->ciss_dev, i) != 0) { in ciss_cam_init()
2979 mtx_unlock(&sc->ciss_mtx); in ciss_cam_init()
2982 mtx_unlock(&sc->ciss_mtx); in ciss_cam_init()
3003 if (xpt_create_path(&ccb->ccb_h.path, NULL, in ciss_cam_rescan_target()
3004 cam_sim_path(sc->ciss_cam_sim[bus]), in ciss_cam_rescan_target()
3027 csio = (struct ccb_scsiio *)&ccb->csio; in ciss_cam_action()
3028 target = csio->ccb_h.target_id; in ciss_cam_action()
3031 switch (ccb->ccb_h.func_code) { in ciss_cam_action()
3041 struct ccb_calc_geometry *ccg = &ccb->ccg; in ciss_cam_action()
3044 …debug(1, "XPT_CALC_GEOMETRY %d:%d:%d", cam_sim_bus(sim), ccb->ccb_h.target_id, ccb->ccb_h.target_l… in ciss_cam_action()
3048 ld = &sc->ciss_logical[bus][target]; in ciss_cam_action()
3054 if (physical || ld->cl_geometry.fault_tolerance == 0xFF) { in ciss_cam_action()
3057 ccg->heads = 255; in ciss_cam_action()
3058 ccg->secs_per_track = 32; in ciss_cam_action()
3059 secs_per_cylinder = ccg->heads * ccg->secs_per_track; in ciss_cam_action()
3060 ccg->cylinders = ccg->volume_size / secs_per_cylinder; in ciss_cam_action()
3062 ccg->heads = ld->cl_geometry.heads; in ciss_cam_action()
3063 ccg->secs_per_track = ld->cl_geometry.sectors; in ciss_cam_action()
3064 ccg->cylinders = ntohs(ld->cl_geometry.cylinders); in ciss_cam_action()
3066 ccb->ccb_h.status = CAM_REQ_CMP; in ciss_cam_action()
3073 struct ccb_pathinq *cpi = &ccb->cpi; in ciss_cam_action()
3076 debug(1, "XPT_PATH_INQ %d:%d:%d", cam_sim_bus(sim), ccb->ccb_h.target_id, ccb->ccb_h.target_lun); in ciss_cam_action()
3078 cpi->version_num = 1; in ciss_cam_action()
3079 cpi->hba_inquiry = PI_TAG_ABLE; /* XXX is this correct? */ in ciss_cam_action()
3080 cpi->target_sprt = 0; in ciss_cam_action()
3081 cpi->hba_misc = 0; in ciss_cam_action()
3082 cpi->max_target = MAX(sc->ciss_max_physical_target, sc->ciss_cfg->max_logical_supported); in ciss_cam_action()
3083 cpi->max_lun = 0; /* 'logical drive' channel only */ in ciss_cam_action()
3085 cpi->initiator_id = ciss_initiator_id; in ciss_cam_action()
3087 cpi->initiator_id = sc->ciss_cfg->max_logical_supported; in ciss_cam_action()
3088 strlcpy(cpi->sim_vid, "FreeBSD", SIM_IDLEN); in ciss_cam_action()
3089 strlcpy(cpi->hba_vid, "CISS", HBA_IDLEN); in ciss_cam_action()
3090 strlcpy(cpi->dev_name, cam_sim_name(sim), DEV_IDLEN); in ciss_cam_action()
3091 cpi->unit_number = cam_sim_unit(sim); in ciss_cam_action()
3092 cpi->bus_id = cam_sim_bus(sim); in ciss_cam_action()
3093 cpi->base_transfer_speed = ciss_base_transfer_speed; in ciss_cam_action()
3094 cpi->transport = XPORT_SPI; in ciss_cam_action()
3095 cpi->transport_version = 2; in ciss_cam_action()
3096 cpi->protocol = PROTO_SCSI; in ciss_cam_action()
3097 cpi->protocol_version = SCSI_REV_2; in ciss_cam_action()
3098 if (sc->ciss_cfg->max_sg_length == 0) { in ciss_cam_action()
3110 sg_length = sc->ciss_cfg->max_sg_length - 1; in ciss_cam_action()
3111 sg_length = (1 << (fls(sg_length) - 1)) + 1; in ciss_cam_action()
3113 cpi->maxio = (min(CISS_MAX_SG_ELEMENTS, sg_length) - 1) * PAGE_SIZE; in ciss_cam_action()
3114 ccb->ccb_h.status = CAM_REQ_CMP; in ciss_cam_action()
3120 struct ccb_trans_settings *cts = &ccb->cts; in ciss_cam_action()
3121 struct ccb_trans_settings_spi *spi = &cts->xport_specific.spi; in ciss_cam_action() local
3122 struct ccb_trans_settings_scsi *scsi = &cts->proto_specific.scsi; in ciss_cam_action()
3125 ctl->ccb_h.target_id); in ciss_cam_action()
3127 cts->protocol = PROTO_SCSI; in ciss_cam_action()
3128 cts->protocol_version = SCSI_REV_2; in ciss_cam_action()
3129 cts->transport = XPORT_SPI; in ciss_cam_action()
3130 cts->transport_version = 2; in ciss_cam_action()
3132 spi->valid = CTS_SPI_VALID_DISC; in ciss_cam_action()
3133 spi->flags = CTS_SPI_FLAGS_DISC_ENB; in ciss_cam_action()
3135 scsi->valid = CTS_SCSI_VALID_TQ; in ciss_cam_action()
3136 scsi->flags = CTS_SCSI_FLAGS_TAG_ENB; in ciss_cam_action()
3138 cts->ccb_h.status = CAM_REQ_CMP; in ciss_cam_action()
3143 debug(1, "unspported func_code = 0x%x", ccb->ccb_h.func_code); in ciss_cam_action()
3144 ccb->ccb_h.status = CAM_REQ_INVALID; in ciss_cam_action()
3165 target = csio->ccb_h.target_id; in ciss_cam_action_io()
3167 debug(2, "XPT_SCSI_IO %d:%d:%d", bus, target, csio->ccb_h.target_lun); in ciss_cam_action_io()
3170 if ((csio->ccb_h.flags & CAM_CDB_POINTER) && (csio->ccb_h.flags & CAM_CDB_PHYS)) { in ciss_cam_action_io()
3172 csio->ccb_h.status = CAM_REQ_CMP_ERR; in ciss_cam_action_io()
3176 if ((csio->ccb_h.status & CAM_STATUS_MASK) != CAM_REQ_INPROG) { in ciss_cam_action_io()
3192 sc->ciss_flags |= CISS_FLAG_BUSY; in ciss_cam_action_io()
3193 csio->ccb_h.status |= CAM_REQUEUE_REQ; in ciss_cam_action_io()
3200 cc = cr->cr_cc; in ciss_cam_action_io()
3201 cr->cr_data = csio; in ciss_cam_action_io()
3202 cr->cr_length = csio->dxfer_len; in ciss_cam_action_io()
3203 cr->cr_complete = ciss_cam_complete; in ciss_cam_action_io()
3204 cr->cr_private = csio; in ciss_cam_action_io()
3210 cc->header.address = in ciss_cam_action_io()
3211 sc->ciss_physical[CISS_CAM_TO_PBUS(bus)][target].cp_address; in ciss_cam_action_io()
3213 cc->header.address = in ciss_cam_action_io()
3214 sc->ciss_logical[bus][target].cl_address; in ciss_cam_action_io()
3215 cc->cdb.cdb_length = csio->cdb_len; in ciss_cam_action_io()
3216 cc->cdb.type = CISS_CDB_TYPE_COMMAND; in ciss_cam_action_io()
3217 cc->cdb.attribute = CISS_CDB_ATTRIBUTE_SIMPLE; /* XXX ordered tags? */ in ciss_cam_action_io()
3218 if ((csio->ccb_h.flags & CAM_DIR_MASK) == CAM_DIR_OUT) { in ciss_cam_action_io()
3219 cr->cr_flags = CISS_REQ_DATAOUT | CISS_REQ_CCB; in ciss_cam_action_io()
3220 cc->cdb.direction = CISS_CDB_DIRECTION_WRITE; in ciss_cam_action_io()
3221 } else if ((csio->ccb_h.flags & CAM_DIR_MASK) == CAM_DIR_IN) { in ciss_cam_action_io()
3222 cr->cr_flags = CISS_REQ_DATAIN | CISS_REQ_CCB; in ciss_cam_action_io()
3223 cc->cdb.direction = CISS_CDB_DIRECTION_READ; in ciss_cam_action_io()
3225 cr->cr_data = NULL; in ciss_cam_action_io()
3226 cr->cr_flags = 0; in ciss_cam_action_io()
3227 cc->cdb.direction = CISS_CDB_DIRECTION_NONE; in ciss_cam_action_io()
3229 cc->cdb.timeout = (csio->ccb_h.timeout / 1000) + 1; in ciss_cam_action_io()
3230 if (csio->ccb_h.flags & CAM_CDB_POINTER) { in ciss_cam_action_io()
3231 bcopy(csio->cdb_io.cdb_ptr, &cc->cdb.cdb[0], csio->cdb_len); in ciss_cam_action_io()
3233 bcopy(csio->cdb_io.cdb_bytes, &cc->cdb.cdb[0], csio->cdb_len); in ciss_cam_action_io()
3245 csio->ccb_h.status |= CAM_RELEASE_SIMQ; in ciss_cam_action_io()
3249 csio->ccb_h.status |= CAM_REQUEUE_REQ; in ciss_cam_action_io()
3267 target = csio->ccb_h.target_id; in ciss_cam_emulate()
3268 bus = cam_sim_bus(xpt_path_sim(csio->ccb_h.path)); in ciss_cam_emulate()
3269 opcode = (csio->ccb_h.flags & CAM_CDB_POINTER) ? in ciss_cam_emulate()
3270 *(u_int8_t *)csio->cdb_io.cdb_ptr : csio->cdb_io.cdb_bytes[0]; in ciss_cam_emulate()
3273 if (sc->ciss_physical[CISS_CAM_TO_PBUS(bus)][target].cp_online != 1) { in ciss_cam_emulate()
3274 csio->ccb_h.status |= CAM_SEL_TIMEOUT; in ciss_cam_emulate()
3286 if (sc->ciss_logical[bus][target].cl_status != CISS_LD_ONLINE) { in ciss_cam_emulate()
3287 csio->ccb_h.status |= CAM_SEL_TIMEOUT; in ciss_cam_emulate()
3293 if (sc->ciss_flags & CISS_FLAG_FAKE_SYNCH) { in ciss_cam_emulate()
3298 if (((csio->ccb_h.flags & CAM_CDB_POINTER) ? in ciss_cam_emulate()
3299 *(u_int8_t *)csio->cdb_io.cdb_ptr : csio->cdb_io.cdb_bytes[0]) == SYNCHRONIZE_CACHE) { in ciss_cam_emulate()
3301 csio->ccb_h.status |= CAM_REQ_CMP; in ciss_cam_emulate()
3313 if (opcode == REPORT_LUNS && csio->dxfer_len > 0) { in ciss_cam_emulate()
3314 csio->data_ptr[3] = 8; in ciss_cam_emulate()
3315 csio->ccb_h.status |= CAM_REQ_CMP; in ciss_cam_emulate()
3324 * Check for possibly-completed commands.
3335 if (sc->ciss_perf) in ciss_cam_poll()
3343 * Handle completion of a command - pass results back through the CCB
3357 sc = cr->cr_sc; in ciss_cam_complete()
3358 cc = cr->cr_cc; in ciss_cam_complete()
3359 ce = (struct ciss_error_info *)&(cc->sg[0]); in ciss_cam_complete()
3360 csio = (struct ccb_scsiio *)cr->cr_private; in ciss_cam_complete()
3368 csio->resid = ce->residual_count; in ciss_cam_complete()
3371 csio->scsi_status = scsi_status; in ciss_cam_complete()
3373 csio->ccb_h.status |= CAM_REQ_CMP; in ciss_cam_complete()
3376 csio->scsi_status = scsi_status; in ciss_cam_complete()
3377 bzero(&csio->sense_data, SSD_FULL_SIZE); in ciss_cam_complete()
3378 bcopy(&ce->sense_info[0], &csio->sense_data, ce->sense_length); in ciss_cam_complete()
3379 if (csio->sense_len > ce->sense_length) in ciss_cam_complete()
3380 csio->sense_resid = csio->sense_len - ce->sense_length; in ciss_cam_complete()
3382 csio->sense_resid = 0; in ciss_cam_complete()
3383 csio->resid = ce->residual_count; in ciss_cam_complete()
3384 csio->ccb_h.status |= CAM_SCSI_STATUS_ERROR | CAM_AUTOSNS_VALID; in ciss_cam_complete()
3387 csio->ccb_h.status |= CAM_DATA_RUN_ERR; in ciss_cam_complete()
3390 csio->ccb_h.status |= CAM_REQ_CMP_ERR; in ciss_cam_complete()
3394 /* handle post-command fixup */ in ciss_cam_complete()
3398 if (sc->ciss_flags & CISS_FLAG_BUSY) { in ciss_cam_complete()
3399 sc->ciss_flags &= ~CISS_FLAG_BUSY; in ciss_cam_complete()
3400 if (csio->ccb_h.status & CAM_RELEASE_SIMQ) in ciss_cam_complete()
3401 xpt_release_simq(xpt_path_sim(csio->ccb_h.path), 0); in ciss_cam_complete()
3403 csio->ccb_h.status |= CAM_RELEASE_SIMQ; in ciss_cam_complete()
3419 cdb = (csio->ccb_h.flags & CAM_CDB_POINTER) ? in ciss_cam_complete_fixup()
3420 (uint8_t *)csio->cdb_io.cdb_ptr : csio->cdb_io.cdb_bytes; in ciss_cam_complete_fixup()
3423 (csio->ccb_h.flags & CAM_DIR_MASK) == CAM_DIR_IN && in ciss_cam_complete_fixup()
3424 csio->dxfer_len >= SHORT_INQUIRY_LENGTH) { in ciss_cam_complete_fixup()
3425 inq = (struct scsi_inquiry_data *)csio->data_ptr; in ciss_cam_complete_fixup()
3426 target = csio->ccb_h.target_id; in ciss_cam_complete_fixup()
3427 bus = cam_sim_bus(xpt_path_sim(csio->ccb_h.path)); in ciss_cam_complete_fixup()
3435 if( !(sc->ciss_id->PowerUPNvramFlags & PWR_UP_FLAG_JBOD_ENABLED)){ in ciss_cam_complete_fixup()
3438 inq->device = (inq->device & 0xe0) | T_NODEVICE; in ciss_cam_complete_fixup()
3441 cl = &sc->ciss_logical[bus][target]; in ciss_cam_complete_fixup()
3443 padstr(inq->vendor, "HP", in ciss_cam_complete_fixup()
3445 padstr(inq->product, in ciss_cam_complete_fixup()
3446 ciss_name_ldrive_org(cl->cl_ldrive->fault_tolerance), in ciss_cam_complete_fixup()
3448 padstr(inq->revision, in ciss_cam_complete_fixup()
3449 ciss_name_ldrive_status(cl->cl_lstatus->status), in ciss_cam_complete_fixup()
3470 status = xpt_create_path(&path, NULL, cam_sim_path(sc->ciss_cam_sim[bus]), in ciss_name_device()
3479 sprintf(sc->ciss_logical[bus][target].cl_name, "%s%d", in ciss_name_device()
3480 periph->periph_name, periph->unit_number); in ciss_name_device()
3484 sc->ciss_logical[bus][target].cl_name[0] = 0; in ciss_name_device()
3506 if (sc->ciss_cfg->heartbeat == sc->ciss_heartbeat) { in ciss_periodic()
3507 sc->ciss_heart_attack++; in ciss_periodic()
3509 sc->ciss_heartbeat, sc->ciss_heart_attack); in ciss_periodic()
3510 if (sc->ciss_heart_attack == 3) { in ciss_periodic()
3516 sc->ciss_heartbeat = sc->ciss_cfg->heartbeat; in ciss_periodic()
3517 sc->ciss_heart_attack = 0; in ciss_periodic()
3518 debug(3, "new heartbeat 0x%x", sc->ciss_heartbeat); in ciss_periodic()
3525 cc = cr->cr_cc; in ciss_periodic()
3526 cr->cr_complete = ciss_nop_complete; in ciss_periodic()
3527 cc->cdb.cdb_length = 1; in ciss_periodic()
3528 cc->cdb.type = CISS_CDB_TYPE_MESSAGE; in ciss_periodic()
3529 cc->cdb.attribute = CISS_CDB_ATTRIBUTE_SIMPLE; in ciss_periodic()
3530 cc->cdb.direction = CISS_CDB_DIRECTION_WRITE; in ciss_periodic()
3531 cc->cdb.timeout = 0; in ciss_periodic()
3532 cc->cdb.cdb[0] = CISS_OPCODE_MESSAGE_NOP; in ciss_periodic()
3543 if (!(sc->ciss_flags & CISS_FLAG_NOTIFY_OK)) { in ciss_periodic()
3551 callout_reset(&sc->ciss_periodic, CISS_HEARTBEAT_RATE * hz, ciss_periodic, sc); in ciss_periodic()
3560 sc = cr->cr_sc; in ciss_nop_complete()
3587 pci_disable_busmaster(sc->ciss_dev); in ciss_disable_adapter()
3588 sc->ciss_flags &= ~CISS_FLAG_RUNNING; in ciss_disable_adapter()
3591 for (i = 1; i < sc->ciss_max_requests; i++) { in ciss_disable_adapter()
3592 cr = &sc->ciss_request[i]; in ciss_disable_adapter()
3593 if ((cr->cr_flags & CISS_REQ_BUSY) == 0) in ciss_disable_adapter()
3596 cc = cr->cr_cc; in ciss_disable_adapter()
3597 ce = (struct ciss_error_info *)&(cc->sg[0]); in ciss_disable_adapter()
3598 ce->command_status = CISS_CMD_STATUS_HARDWARE_ERROR; in ciss_disable_adapter()
3609 if (cr->cr_complete != NULL) { in ciss_disable_adapter()
3610 cr->cr_complete(cr); in ciss_disable_adapter()
3617 if (cr->cr_flags & CISS_REQ_SLEEP) { in ciss_disable_adapter()
3618 cr->cr_flags &= ~CISS_REQ_SLEEP; in ciss_disable_adapter()
3642 cr = sc->ciss_periodic_notify; in ciss_notify_event()
3650 sc->ciss_periodic_notify = cr; in ciss_notify_event()
3651 cr->cr_complete = ciss_notify_complete; in ciss_notify_event()
3652 debug(1, "acquired request %d", cr->cr_tag); in ciss_notify_event()
3660 if (cr->cr_data == NULL) { in ciss_notify_event()
3661 if ((cr->cr_data = malloc(CISS_NOTIFY_DATA_SIZE, CISS_MALLOC_CLASS, M_NOWAIT)) == NULL) { in ciss_notify_event()
3666 cr->cr_length = CISS_NOTIFY_DATA_SIZE; in ciss_notify_event()
3669 /* re-setup the request's command (since we never release it) XXX overkill*/ in ciss_notify_event()
3673 cc = cr->cr_cc; in ciss_notify_event()
3674 cc->header.address.physical.mode = CISS_HDR_ADDRESS_MODE_PERIPHERAL; in ciss_notify_event()
3675 cc->header.address.physical.bus = 0; in ciss_notify_event()
3676 cc->header.address.physical.target = 0; in ciss_notify_event()
3678 cc->cdb.cdb_length = sizeof(*cnc); in ciss_notify_event()
3679 cc->cdb.type = CISS_CDB_TYPE_COMMAND; in ciss_notify_event()
3680 cc->cdb.attribute = CISS_CDB_ATTRIBUTE_SIMPLE; in ciss_notify_event()
3681 cc->cdb.direction = CISS_CDB_DIRECTION_READ; in ciss_notify_event()
3682 cc->cdb.timeout = 0; /* no timeout, we hope */ in ciss_notify_event()
3684 cnc = (struct ciss_notify_cdb *)&(cc->cdb.cdb[0]); in ciss_notify_event()
3685 bzero(cr->cr_data, CISS_NOTIFY_DATA_SIZE); in ciss_notify_event()
3686 cnc->opcode = CISS_OPCODE_READ; in ciss_notify_event()
3687 cnc->command = CISS_COMMAND_NOTIFY_ON_EVENT; in ciss_notify_event()
3688 cnc->timeout = 0; /* no timeout, we hope */ in ciss_notify_event()
3689 cnc->synchronous = 0; in ciss_notify_event()
3690 cnc->ordered = 0; in ciss_notify_event()
3691 cnc->seek_to_oldest = 0; in ciss_notify_event()
3692 if ((sc->ciss_flags & CISS_FLAG_RUNNING) == 0) in ciss_notify_event()
3693 cnc->new_only = 1; in ciss_notify_event()
3695 cnc->new_only = 0; in ciss_notify_event()
3696 cnc->length = htonl(CISS_NOTIFY_DATA_SIZE); in ciss_notify_event()
3704 if (cr->cr_data != NULL) in ciss_notify_event()
3705 free(cr->cr_data, CISS_MALLOC_CLASS); in ciss_notify_event()
3708 sc->ciss_periodic_notify = NULL; in ciss_notify_event()
3710 sc->ciss_flags &= ~CISS_FLAG_NOTIFY_OK; in ciss_notify_event()
3713 sc->ciss_flags |= CISS_FLAG_NOTIFY_OK; in ciss_notify_event()
3726 cn = (struct ciss_notify *)cr->cr_data; in ciss_notify_complete()
3727 sc = cr->cr_sc; in ciss_notify_complete()
3745 sc->ciss_flags &= ~CISS_FLAG_NOTIFY_OK; in ciss_notify_complete()
3752 if (cn->message[0] != 0) in ciss_notify_complete()
3753 ciss_printf(sc, "*** %.80s\n", cn->message); in ciss_notify_complete()
3756 cn->class, cn->subclass, cn->detail); in ciss_notify_complete()
3762 if ((cn->class == CISS_NOTIFY_NOTIFIER) && in ciss_notify_complete()
3763 (cn->subclass == CISS_NOTIFY_NOTIFIER_STATUS) && in ciss_notify_complete()
3764 (cn->detail == 1)) { in ciss_notify_complete()
3766 sc->ciss_flags &= ~CISS_FLAG_NOTIFY_OK; in ciss_notify_complete()
3768 sc->ciss_periodic_notify = NULL; in ciss_notify_complete()
3769 wakeup(&sc->ciss_periodic_notify); in ciss_notify_complete()
3773 sc->ciss_periodic_notify = NULL; in ciss_notify_complete()
3774 wakeup(&sc->ciss_periodic_notify); in ciss_notify_complete()
3775 wakeup(&sc->ciss_notify); in ciss_notify_complete()
3780 if (!(sc->ciss_flags & CISS_FLAG_ABORTING)) { in ciss_notify_complete()
3809 if (!(sc->ciss_flags & CISS_FLAG_NOTIFY_OK)) in ciss_notify_abort()
3817 if ((cr->cr_data = malloc(CISS_NOTIFY_DATA_SIZE, CISS_MALLOC_CLASS, M_NOWAIT)) == NULL) { in ciss_notify_abort()
3822 cr->cr_length = CISS_NOTIFY_DATA_SIZE; in ciss_notify_abort()
3825 cc = cr->cr_cc; in ciss_notify_abort()
3826 cc->header.address.physical.mode = CISS_HDR_ADDRESS_MODE_PERIPHERAL; in ciss_notify_abort()
3827 cc->header.address.physical.bus = 0; in ciss_notify_abort()
3828 cc->header.address.physical.target = 0; in ciss_notify_abort()
3829 cc->cdb.cdb_length = sizeof(*cnc); in ciss_notify_abort()
3830 cc->cdb.type = CISS_CDB_TYPE_COMMAND; in ciss_notify_abort()
3831 cc->cdb.attribute = CISS_CDB_ATTRIBUTE_SIMPLE; in ciss_notify_abort()
3832 cc->cdb.direction = CISS_CDB_DIRECTION_READ; in ciss_notify_abort()
3833 cc->cdb.timeout = 0; /* no timeout, we hope */ in ciss_notify_abort()
3835 cnc = (struct ciss_notify_cdb *)&(cc->cdb.cdb[0]); in ciss_notify_abort()
3837 cnc->opcode = CISS_OPCODE_WRITE; in ciss_notify_abort()
3838 cnc->command = CISS_COMMAND_ABORT_NOTIFY; in ciss_notify_abort()
3839 cnc->length = htonl(CISS_NOTIFY_DATA_SIZE); in ciss_notify_abort()
3875 if (sc->ciss_periodic_notify != NULL) in ciss_notify_abort()
3876 ciss_release_request(sc->ciss_periodic_notify); in ciss_notify_abort()
3896 while (sc->ciss_periodic_notify != NULL) { in ciss_notify_abort()
3897 error = msleep(&sc->ciss_periodic_notify, &sc->ciss_mtx, PRIBIO, "cissNEA", hz * 5); in ciss_notify_abort()
3907 if (cr->cr_data != NULL) in ciss_notify_abort()
3908 free(cr->cr_data, CISS_MALLOC_CLASS); in ciss_notify_abort()
3912 sc->ciss_flags &= ~CISS_FLAG_NOTIFY_OK; in ciss_notify_abort()
3931 if (!(sc->ciss_flags & CISS_FLAG_NOTIFY_OK)) in ciss_notify_abort_bmic()
3987 sc->ciss_cfg->max_logical_supported); in ciss_notify_rescan_logical()
3991 ndrives = (ntohl(cll->list_size) / sizeof(union ciss_device_address)); in ciss_notify_rescan_logical()
3997 for (i = 0; i < sc->ciss_max_logical_bus; i++) { in ciss_notify_rescan_logical()
3998 for (j = 0; j < sc->ciss_cfg->max_logical_supported; j++) { in ciss_notify_rescan_logical()
3999 ld = &sc->ciss_logical[i][j]; in ciss_notify_rescan_logical()
4001 if (ld->cl_update == 0) in ciss_notify_rescan_logical()
4004 if (ld->cl_status != CISS_LD_ONLINE) { in ciss_notify_rescan_logical()
4006 ld->cl_update = 0; in ciss_notify_rescan_logical()
4007 if (ld->cl_ldrive) in ciss_notify_rescan_logical()
4008 free(ld->cl_ldrive, CISS_MALLOC_CLASS); in ciss_notify_rescan_logical()
4009 if (ld->cl_lstatus) in ciss_notify_rescan_logical()
4010 free(ld->cl_lstatus, CISS_MALLOC_CLASS); in ciss_notify_rescan_logical()
4012 ld->cl_ldrive = NULL; in ciss_notify_rescan_logical()
4013 ld->cl_lstatus = NULL; in ciss_notify_rescan_logical()
4024 bus = CISS_LUN_TO_BUS(cll->lun[i].logical.lun); in ciss_notify_rescan_logical()
4025 target = CISS_LUN_TO_TARGET(cll->lun[i].logical.lun); in ciss_notify_rescan_logical()
4026 ld = &sc->ciss_logical[bus][target]; in ciss_notify_rescan_logical()
4028 if (ld->cl_update == 0) in ciss_notify_rescan_logical()
4031 ld->cl_update = 0; in ciss_notify_rescan_logical()
4032 ld->cl_address = cll->lun[i]; in ciss_notify_rescan_logical()
4033 ld->cl_controller = &sc->ciss_controllers[bus]; in ciss_notify_rescan_logical()
4056 bus = cn->device.physical.bus; in ciss_notify_logical()
4057 target = cn->data.logical_status.logical_drive; in ciss_notify_logical()
4058 ld = &sc->ciss_logical[bus][target]; in ciss_notify_logical()
4060 switch (cn->subclass) { in ciss_notify_logical()
4062 switch (cn->detail) { in ciss_notify_logical()
4065 ciss_printf(sc, "logical drive %d (%s) changed status %s->%s, spare status 0x%b\n", in ciss_notify_logical()
4066 cn->data.logical_status.logical_drive, ld->cl_name, in ciss_notify_logical()
4067 ciss_name_ldrive_status(cn->data.logical_status.previous_state), in ciss_notify_logical()
4068 ciss_name_ldrive_status(cn->data.logical_status.new_state), in ciss_notify_logical()
4069 cn->data.logical_status.spare_state, in ciss_notify_logical()
4075 ostatus = ciss_decode_ldrive_status(cn->data.logical_status.previous_state); in ciss_notify_logical()
4076 ld->cl_status = ciss_decode_ldrive_status(cn->data.logical_status.new_state); in ciss_notify_logical()
4077 if (ld->cl_lstatus != NULL) in ciss_notify_logical()
4078 ld->cl_lstatus->status = cn->data.logical_status.new_state; in ciss_notify_logical()
4083 if (ostatus != ld->cl_status) { in ciss_notify_logical()
4084 ld->cl_update = 1; in ciss_notify_logical()
4093 cn->data.logical_status.logical_drive, ld->cl_name); in ciss_notify_logical()
4096 ld->cl_update = 1; in ciss_notify_logical()
4097 ld->cl_status = ciss_decode_ldrive_status(cn->data.logical_status.new_state); in ciss_notify_logical()
4104 cn->data.rebuild_aborted.logical_drive, in ciss_notify_logical()
4105 ld->cl_name, in ciss_notify_logical()
4106 (cn->detail == 2) ? "read" : "write"); in ciss_notify_logical()
4112 if (cn->detail == 0) { in ciss_notify_logical()
4114 cn->data.io_error.logical_drive, in ciss_notify_logical()
4115 ld->cl_name, in ciss_notify_logical()
4116 cn->data.io_error.failure_bus, in ciss_notify_logical()
4117 cn->data.io_error.failure_drive); in ciss_notify_logical()
4123 if (cn->detail == 0) in ciss_notify_logical()
4125 cn->data.consistency_completed.logical_drive, in ciss_notify_logical()
4126 ld->cl_name); in ciss_notify_logical()
4148 switch (cn->subclass) { in ciss_notify_hotplug()
4151 bus = CISS_BIG_MAP_BUS(sc, cn->data.drive.big_physical_drive_number); in ciss_notify_hotplug()
4153 CISS_BIG_MAP_TARGET(sc, cn->data.drive.big_physical_drive_number); in ciss_notify_hotplug()
4155 if (cn->detail == 0) { in ciss_notify_hotplug()
4161 sc->ciss_physical[bus][target].cp_online = 0; in ciss_notify_hotplug()
4167 sc->ciss_cfg->max_physical_supported); in ciss_notify_hotplug()
4177 ciss_printf(sc, "Unknown hotplug event %d\n", cn->subclass); in ciss_notify_hotplug()
4197 mtx_lock(&sc->ciss_mtx); in ciss_notify_thread()
4200 if (STAILQ_EMPTY(&sc->ciss_notify) != 0 && in ciss_notify_thread()
4201 (sc->ciss_flags & CISS_FLAG_THREAD_SHUT) == 0) { in ciss_notify_thread()
4202 msleep(&sc->ciss_notify, &sc->ciss_mtx, PUSER, "idle", 0); in ciss_notify_thread()
4205 if (sc->ciss_flags & CISS_FLAG_THREAD_SHUT) in ciss_notify_thread()
4224 cn = (struct ciss_notify *)cr->cr_data; in ciss_notify_thread()
4226 switch (cn->class) { in ciss_notify_thread()
4240 sc->ciss_notify_thread = NULL; in ciss_notify_thread()
4241 wakeup(&sc->ciss_notify_thread); in ciss_notify_thread()
4243 mtx_unlock(&sc->ciss_mtx); in ciss_notify_thread()
4255 &sc->ciss_notify_thread, 0, 0, "ciss_notify%d", in ciss_spawn_notify_thread()
4256 device_get_unit(sc->ciss_dev))) in ciss_spawn_notify_thread()
4267 if (sc->ciss_notify_thread == NULL) in ciss_kill_notify_thread()
4270 sc->ciss_flags |= CISS_FLAG_THREAD_SHUT; in ciss_kill_notify_thread()
4271 wakeup(&sc->ciss_notify); in ciss_kill_notify_thread()
4272 msleep(&sc->ciss_notify_thread, &sc->ciss_mtx, PUSER, "thtrm", 0); in ciss_kill_notify_thread()
4286 sc = cr->cr_sc; in ciss_print_request()
4287 cc = cr->cr_cc; in ciss_print_request()
4291 cr->cr_data, cr->cr_length, cr->cr_tag, cr->cr_flags, in ciss_print_request()
4294 cc->header.sg_in_list, cc->header.sg_total, cc->header.host_tag); in ciss_print_request()
4295 switch(cc->header.address.mode.mode) { in ciss_print_request()
4299 cc->header.address.physical.bus, cc->header.address.physical.target); in ciss_print_request()
4302 ciss_printf(sc, " logical unit %d\n", cc->header.address.logical.lun); in ciss_print_request()
4306 (cc->cdb.direction == CISS_CDB_DIRECTION_NONE) ? "no-I/O" : in ciss_print_request()
4307 (cc->cdb.direction == CISS_CDB_DIRECTION_READ) ? "READ" : in ciss_print_request()
4308 (cc->cdb.direction == CISS_CDB_DIRECTION_WRITE) ? "WRITE" : "??", in ciss_print_request()
4309 cc->cdb.cdb_length, in ciss_print_request()
4310 (cc->cdb.type == CISS_CDB_TYPE_COMMAND) ? "command" : in ciss_print_request()
4311 (cc->cdb.type == CISS_CDB_TYPE_MESSAGE) ? "message" : "??", in ciss_print_request()
4312 (cc->cdb.attribute == CISS_CDB_ATTRIBUTE_UNTAGGED) ? "untagged" : in ciss_print_request()
4313 (cc->cdb.attribute == CISS_CDB_ATTRIBUTE_SIMPLE) ? "simple" : in ciss_print_request()
4314 (cc->cdb.attribute == CISS_CDB_ATTRIBUTE_HEAD_OF_QUEUE) ? "head-of-queue" : in ciss_print_request()
4315 (cc->cdb.attribute == CISS_CDB_ATTRIBUTE_ORDERED) ? "ordered" : in ciss_print_request()
4316 (cc->cdb.attribute == CISS_CDB_ATTRIBUTE_AUTO_CONTINGENT) ? "auto-contingent" : "??"); in ciss_print_request()
4317 ciss_printf(sc, " %*D\n", cc->cdb.cdb_length, &cc->cdb.cdb[0], " "); in ciss_print_request()
4319 if (cc->header.host_tag & CISS_HDR_HOST_TAG_ERROR) { in ciss_print_request()
4323 for (i = 0; i < cc->header.sg_in_list; i++) { in ciss_print_request()
4326 printf("0x%08x/%d ", (u_int32_t)cc->sg[i].address, cc->sg[i].length); in ciss_print_request()
4327 if ((((i + 1) % 4) == 0) || (i == (cc->header.sg_in_list - 1))) in ciss_print_request()
4342 if (ld->cl_lstatus == NULL) { in ciss_print_ldrive()
4348 switch(ld->cl_lstatus->status) { in ciss_print_ldrive()
4359 bus = CISS_BIG_MAP_BUS(sc, ld->cl_lstatus->drive_rebuilding); in ciss_print_ldrive()
4360 target = CISS_BIG_MAP_BUS(sc, ld->cl_lstatus->drive_rebuilding); in ciss_print_ldrive()
4362 bus, target, ld->cl_lstatus->blocks_to_recover); in ciss_print_ldrive()
4366 ld->cl_lstatus->blocks_to_recover); in ciss_print_ldrive()
4387 bus = CISS_BIG_MAP_BUS(sc, ld->cl_lstatus->drive_failure_map[i]); in ciss_print_ldrive()
4388 target = CISS_BIG_MAP_TARGET(sc, ld->cl_lstatus->drive_failure_map[i]); in ciss_print_ldrive()
4389 if (bus == -1) in ciss_print_ldrive()
4392 ld->cl_lstatus->drive_failure_map[i]); in ciss_print_ldrive()
4411 sc->ciss_qstat[i].q_length, in ciss_print_adapter()
4412 sc->ciss_qstat[i].q_max); in ciss_print_adapter()
4414 ciss_printf(sc, "max_requests %d\n", sc->ciss_max_requests); in ciss_print_adapter()
4415 ciss_printf(sc, "flags %b\n", sc->ciss_flags, in ciss_print_adapter()
4418 for (i = 0; i < sc->ciss_max_logical_bus; i++) { in ciss_print_adapter()
4419 for (j = 0; j < sc->ciss_cfg->max_logical_supported; j++) { in ciss_print_adapter()
4421 ciss_print_ldrive(sc, &sc->ciss_logical[i][j]); in ciss_print_adapter()
4427 for (i = 1; i < sc->ciss_max_requests; i++) in ciss_print_adapter()
4428 ciss_print_request(sc->ciss_request + i); in ciss_print_adapter()
4582 sc = (struct ciss_softc *)dev->si_drv1; in ciss_open()
4586 mtx_lock(&sc->ciss_mtx); in ciss_open()
4587 sc->ciss_flags |= CISS_FLAG_CONTROL_OPEN; in ciss_open()
4588 mtx_unlock(&sc->ciss_mtx); in ciss_open()
4602 sc = (struct ciss_softc *)dev->si_drv1; in ciss_close()
4604 mtx_lock(&sc->ciss_mtx); in ciss_close()
4605 sc->ciss_flags &= ~CISS_FLAG_CONTROL_OPEN; in ciss_close()
4606 mtx_unlock(&sc->ciss_mtx); in ciss_close()
4611 * Handle adapter-specific control operations.
4629 sc = (struct ciss_softc *)dev->si_drv1; in ciss_ioctl()
4631 mtx_lock(&sc->ciss_mtx); in ciss_ioctl()
4638 switch (cr->cs_item) { in ciss_ioctl()
4641 bcopy(&sc->ciss_qstat[cr->cs_item], &cr->cs_qstat, in ciss_ioctl()
4656 pis->bus = pci_get_bus(sc->ciss_dev); in ciss_ioctl()
4657 pis->dev_fn = pci_get_slot(sc->ciss_dev); in ciss_ioctl()
4658 pis->board_id = (pci_get_subvendor(sc->ciss_dev) << 16) | in ciss_ioctl()
4659 pci_get_subdevice(sc->ciss_dev); in ciss_ioctl()
4668 cis->delay = sc->ciss_cfg->interrupt_coalesce_delay; in ciss_ioctl()
4669 cis->count = sc->ciss_cfg->interrupt_coalesce_count; in ciss_ioctl()
4678 if ((cis->delay == 0) && (cis->count == 0)) { in ciss_ioctl()
4687 sc->ciss_cfg->interrupt_coalesce_delay = cis->delay; in ciss_ioctl()
4688 sc->ciss_cfg->interrupt_coalesce_count = cis->count; in ciss_ioctl()
4698 bcopy(sc->ciss_cfg->server_name, (NodeName_type *)addr, in ciss_ioctl()
4703 bcopy((NodeName_type *)addr, sc->ciss_cfg->server_name, in ciss_ioctl()
4710 *(Heartbeat_type *)addr = sc->ciss_cfg->heartbeat; in ciss_ioctl()
4714 *(BusTypes_type *)addr = sc->ciss_cfg->bus_types; in ciss_ioctl()
4718 bcopy(sc->ciss_id->running_firmware_revision, (FirmwareVer_type *)addr, in ciss_ioctl()
4738 ioc_swab.LUN_info = ioc32->LUN_info; in ciss_ioctl()
4739 ioc_swab.Request = ioc32->Request; in ciss_ioctl()
4740 ioc_swab.error_info = ioc32->error_info; in ciss_ioctl()
4741 ioc_swab.buf_size = ioc32->buf_size; in ciss_ioctl()
4742 ioc_swab.buf = (u_int8_t *)(uintptr_t)ioc32->buf; in ciss_ioctl()
4770 mtx_unlock(&sc->ciss_mtx); in ciss_ioctl()