Lines Matching +full:eee +full:- +full:broken +full:- +full:1000 +full:t

1 /*-
2 * SPDX-License-Identifier: BSD-2-Clause
7 * Copyright (c) 2001-2010 Adaptec, Inc.
8 * Copyright (c) 2010-2012 PMC-Sierra, Inc.
246 sc->hint_flags = device_get_flags(sc->aac_dev); in aacraid_attach()
248 * Initialize per-controller queues. in aacraid_attach()
255 sc->aac_state |= AAC_STATE_SUSPEND; in aacraid_attach()
260 sc->msi_enabled = sc->msi_tupelo = FALSE; in aacraid_attach()
267 mtx_init(&sc->aac_io_lock, "AACRAID I/O lock", NULL, MTX_DEF); in aacraid_attach()
268 TAILQ_INIT(&sc->aac_container_tqh); in aacraid_attach()
269 TAILQ_INIT(&sc->aac_ev_cmfree); in aacraid_attach()
272 callout_init_mtx(&sc->aac_daemontime, &sc->aac_io_lock, 0); in aacraid_attach()
280 if (!(sc->flags & AAC_FLAGS_SYNC_MODE)) { in aacraid_attach()
299 unit = device_get_unit(sc->aac_dev); in aacraid_attach()
300 sc->aac_dev_t = make_dev(&aacraid_cdevsw, unit, UID_ROOT, GID_OPERATOR, in aacraid_attach()
302 sc->aac_dev_t->si_drv1 = sc; in aacraid_attach()
306 &sc->aifthread, 0, 0, "aacraid%daif", unit)) in aacraid_attach()
309 /* Register the shutdown method to only be called post-dump */ in aacraid_attach()
310 if ((sc->eh = EVENTHANDLER_REGISTER(shutdown_final, aacraid_shutdown, in aacraid_attach()
311 sc->aac_dev, SHUTDOWN_PRI_DEFAULT)) == NULL) in aacraid_attach()
312 device_printf(sc->aac_dev, in aacraid_attach()
316 mtx_lock(&sc->aac_io_lock); in aacraid_attach()
328 mtx_unlock(&sc->aac_io_lock); in aacraid_attach()
331 TAILQ_INIT(&sc->aac_sim_tqh); in aacraid_attach()
333 /* Register with CAM for the non-DASD devices */ in aacraid_attach()
334 if ((sc->flags & AAC_FLAGS_ENABLE_CAM) != 0) in aacraid_attach()
338 bus_attach_children(sc->aac_dev); in aacraid_attach()
341 sc->aac_state &= ~AAC_STATE_SUSPEND; in aacraid_attach()
346 mtx_lock(&sc->aac_io_lock); in aacraid_attach()
347 callout_reset(&sc->aac_daemontime, 60 * hz, aac_daemon, sc); in aacraid_attach()
348 mtx_unlock(&sc->aac_io_lock); in aacraid_attach()
364 mtx_assert(&sc->aac_io_lock, MA_OWNED); in aac_daemon()
365 if (callout_pending(&sc->aac_daemontime) || in aac_daemon()
366 callout_active(&sc->aac_daemontime) == 0) in aac_daemon()
371 fib = cm->cm_fib; in aac_daemon()
372 cm->cm_timestamp = time_uptime; in aac_daemon()
373 cm->cm_datalen = 0; in aac_daemon()
374 cm->cm_flags |= AAC_CMD_WAIT; in aac_daemon()
376 fib->Header.Size = in aac_daemon()
378 fib->Header.XferState = in aac_daemon()
387 fib->Header.Command = SendHostTime; in aac_daemon()
388 *(uint32_t *)fib->data = htole32(tv.tv_sec); in aac_daemon()
394 callout_schedule(&sc->aac_daemontime, 30 * 60 * hz); in aac_daemon()
401 switch (event->ev_type & AAC_EVENT_MASK) { in aacraid_add_event()
403 TAILQ_INSERT_TAIL(&sc->aac_ev_cmfree, event, ev_links); in aacraid_add_event()
406 device_printf(sc->aac_dev, "aac_add event: unknown event %d\n", in aacraid_add_event()
407 event->ev_type); in aacraid_add_event()
429 device_printf(sc->aac_dev, in aac_get_container_info()
431 return (-1); in aac_get_container_info()
433 fib = cm->cm_fib; in aac_get_container_info()
438 mi = (struct aac_mntinfo *)&fib->data[0]; in aac_get_container_info()
439 /* 4KB support?, 64-bit LBA? */ in aac_get_container_info()
440 if (sc->aac_support_opt2 & AAC_SUPPORTED_VARIABLE_BLOCK_SIZE) in aac_get_container_info()
441 mi->Command = VM_NameServeAllBlk; in aac_get_container_info()
442 else if (sc->flags & AAC_FLAGS_LBA_64BIT) in aac_get_container_info()
443 mi->Command = VM_NameServe64; in aac_get_container_info()
445 mi->Command = VM_NameServe; in aac_get_container_info()
446 mi->MntType = FT_FILESYS; in aac_get_container_info()
447 mi->MntCount = cid; in aac_get_container_info()
453 device_printf(sc->aac_dev, "Error probing container %d\n", cid); in aac_get_container_info()
454 return (-1); in aac_get_container_info()
457 cm->cm_timestamp = time_uptime; in aac_get_container_info()
458 cm->cm_datalen = 0; in aac_get_container_info()
460 fib->Header.Size = in aac_get_container_info()
462 fib->Header.XferState = in aac_get_container_info()
471 fib->Header.Command = ContainerCommand; in aac_get_container_info()
473 device_printf(sc->aac_dev, "Error probing container %d\n", cid); in aac_get_container_info()
475 return (-1); in aac_get_container_info()
478 bcopy(&fib->data[0], mir, sizeof(struct aac_mntinforesp)); in aac_get_container_info()
483 if (mir->MntTable[0].VolType != CT_NONE && in aac_get_container_info()
484 !(mir->MntTable[0].ContentState & AAC_FSCS_HIDDEN)) { in aac_get_container_info()
485 if (!(sc->aac_support_opt2 & AAC_SUPPORTED_VARIABLE_BLOCK_SIZE)) { in aac_get_container_info()
486 mir->MntTable[0].ObjExtension.BlockDevice.BlockSize = 0x200; in aac_get_container_info()
487 mir->MntTable[0].ObjExtension.BlockDevice.bdLgclPhysMap = 0; in aac_get_container_info()
489 ccfg = (struct aac_cnt_config *)&fib->data[0]; in aac_get_container_info()
490 bzero(ccfg, sizeof (*ccfg) - CT_PACKET_SIZE); in aac_get_container_info()
491 ccfg->Command = VM_ContainerConfig; in aac_get_container_info()
492 ccfg->CTCommand.command = CT_CID_TO_32BITS_UID; in aac_get_container_info()
493 ccfg->CTCommand.param[0] = cid; in aac_get_container_info()
500 if (rval == 0 && ccfg->Command == ST_OK && in aac_get_container_info()
501 ccfg->CTCommand.param[0] == CT_OK && in aac_get_container_info()
502 mir->MntTable[0].VolType != CT_PASSTHRU) in aac_get_container_info()
503 *uid = ccfg->CTCommand.param[1]; in aac_get_container_info()
505 fib->Header.Size = in aac_get_container_info()
507 fib->Header.XferState = in aac_get_container_info()
516 fib->Header.Command = ContainerCommand; in aac_get_container_info()
519 if (rval == 0 && ccfg->Command == ST_OK && in aac_get_container_info()
520 ccfg->CTCommand.param[0] == CT_OK && in aac_get_container_info()
521 mir->MntTable[0].VolType != CT_PASSTHRU) in aac_get_container_info()
522 *uid = ccfg->CTCommand.param[1]; in aac_get_container_info()
545 if ((mir->Status == ST_OK) && (mir->MntTable[0].VolType != CT_NONE)) { in aac_add_container()
552 co->co_found = f; in aac_add_container()
553 bcopy(&mir->MntTable[0], &co->co_mntobj, in aac_add_container()
555 co->co_uid = uid; in aac_add_container()
556 TAILQ_INSERT_TAIL(&sc->aac_container_tqh, co, co_link); in aac_add_container()
571 * Create DMA tag for mapping buffers into controller-addressable space. in aac_alloc()
573 if (bus_dma_tag_create(sc->aac_parent_dmat, /* parent */ in aac_alloc()
575 (sc->flags & AAC_FLAGS_SG_64BIT) ? in aac_alloc()
581 sc->aac_sg_tablesize, /* nsegments */ in aac_alloc()
585 &sc->aac_io_lock, /* lockfuncarg */ in aac_alloc()
586 &sc->aac_buffer_dmat)) { in aac_alloc()
587 device_printf(sc->aac_dev, "can't allocate buffer DMA tag\n"); in aac_alloc()
592 * Create DMA tag for mapping FIBs into controller-addressable space.. in aac_alloc()
594 if (sc->flags & AAC_FLAGS_NEW_COMM_TYPE1) in aac_alloc()
595 maxsize = sc->aac_max_fibs_alloc * (sc->aac_max_fib_size + in aac_alloc()
598 maxsize = sc->aac_max_fibs_alloc * (sc->aac_max_fib_size + 31); in aac_alloc()
599 if (bus_dma_tag_create(sc->aac_parent_dmat, /* parent */ in aac_alloc()
601 (sc->flags & AAC_FLAGS_4GB_WINDOW) ? in aac_alloc()
611 &sc->aac_fib_dmat)) { in aac_alloc()
612 device_printf(sc->aac_dev, "can't allocate FIB DMA tag\n"); in aac_alloc()
620 maxsize += sc->aac_max_fibs * sizeof(u_int32_t); in aac_alloc()
621 if (bus_dma_tag_create(sc->aac_parent_dmat, /* parent */ in aac_alloc()
623 (sc->flags & AAC_FLAGS_4GB_WINDOW) ? in aac_alloc()
633 &sc->aac_common_dmat)) { in aac_alloc()
634 device_printf(sc->aac_dev, in aac_alloc()
635 "can't allocate common structure DMA tag\n"); in aac_alloc()
638 if (bus_dmamem_alloc(sc->aac_common_dmat, (void **)&sc->aac_common, in aac_alloc()
639 BUS_DMA_NOWAIT, &sc->aac_common_dmamap)) { in aac_alloc()
640 device_printf(sc->aac_dev, "can't allocate common structure\n"); in aac_alloc()
644 (void)bus_dmamap_load(sc->aac_common_dmat, sc->aac_common_dmamap, in aac_alloc()
645 sc->aac_common, maxsize, in aac_alloc()
647 bzero(sc->aac_common, maxsize); in aac_alloc()
650 TAILQ_INIT(&sc->aac_fibmap_tqh); in aac_alloc()
651 sc->aac_commands = malloc(sc->aac_max_fibs * sizeof(struct aac_command), in aac_alloc()
653 mtx_lock(&sc->aac_io_lock); in aac_alloc()
654 while (sc->total_fibs < sc->aac_max_fibs) { in aac_alloc()
658 mtx_unlock(&sc->aac_io_lock); in aac_alloc()
659 if (sc->total_fibs == 0) in aac_alloc()
678 if (sc->aac_dev_t != NULL) in aacraid_free()
679 destroy_dev(sc->aac_dev_t); in aacraid_free()
683 if (sc->aac_fib_dmat) in aacraid_free()
684 bus_dma_tag_destroy(sc->aac_fib_dmat); in aacraid_free()
686 free(sc->aac_commands, M_AACRAIDBUF); in aacraid_free()
689 if (sc->aac_common) { in aacraid_free()
690 bus_dmamap_unload(sc->aac_common_dmat, sc->aac_common_dmamap); in aacraid_free()
691 bus_dmamem_free(sc->aac_common_dmat, sc->aac_common, in aacraid_free()
692 sc->aac_common_dmamap); in aacraid_free()
694 if (sc->aac_common_dmat) in aacraid_free()
695 bus_dma_tag_destroy(sc->aac_common_dmat); in aacraid_free()
699 if (sc->aac_intr[i]) in aacraid_free()
700 bus_teardown_intr(sc->aac_dev, in aacraid_free()
701 sc->aac_irq[i], sc->aac_intr[i]); in aacraid_free()
702 if (sc->aac_irq[i]) in aacraid_free()
703 bus_release_resource(sc->aac_dev, SYS_RES_IRQ, in aacraid_free()
704 sc->aac_irq_rid[i], sc->aac_irq[i]); in aacraid_free()
708 if (sc->msi_enabled || sc->msi_tupelo) in aacraid_free()
709 pci_release_msi(sc->aac_dev); in aacraid_free()
711 /* destroy data-transfer DMA tag */ in aacraid_free()
712 if (sc->aac_buffer_dmat) in aacraid_free()
713 bus_dma_tag_destroy(sc->aac_buffer_dmat); in aacraid_free()
716 if (sc->aac_parent_dmat) in aacraid_free()
717 bus_dma_tag_destroy(sc->aac_parent_dmat); in aacraid_free()
720 if (sc->aac_regs_res0 != NULL) in aacraid_free()
721 bus_release_resource(sc->aac_dev, SYS_RES_MEMORY, in aacraid_free()
722 sc->aac_regs_rid0, sc->aac_regs_res0); in aacraid_free()
723 if (sc->aac_regs_res1 != NULL) in aacraid_free()
724 bus_release_resource(sc->aac_dev, SYS_RES_MEMORY, in aacraid_free()
725 sc->aac_regs_rid1, sc->aac_regs_res1); in aacraid_free()
746 callout_drain(&sc->aac_daemontime); in aacraid_detach()
748 while ((co = TAILQ_FIRST(&sc->aac_container_tqh)) != NULL) { in aacraid_detach()
749 TAILQ_REMOVE(&sc->aac_container_tqh, co, co_link); in aacraid_detach()
754 while ((sim = TAILQ_FIRST(&sc->aac_sim_tqh)) != NULL) { in aacraid_detach()
755 TAILQ_REMOVE(&sc->aac_sim_tqh, sim, sim_link); in aacraid_detach()
759 if (sc->aifflags & AAC_AIFFLAGS_RUNNING) { in aacraid_detach()
760 sc->aifflags |= AAC_AIFFLAGS_EXIT; in aacraid_detach()
761 wakeup(sc->aifthread); in aacraid_detach()
762 tsleep(sc->aac_dev, PUSER | PCATCH, "aac_dch", 30 * hz); in aacraid_detach()
765 if (sc->aifflags & AAC_AIFFLAGS_RUNNING) in aacraid_detach()
771 EVENTHANDLER_DEREGISTER(shutdown_final, sc->eh); in aacraid_detach()
775 mtx_destroy(&sc->aac_io_lock); in aacraid_detach()
785 * Note that we can assume that the bioq on the controller is empty, as we won't
798 sc->aac_state |= AAC_STATE_SUSPEND; in aacraid_shutdown()
802 * controller to convince it that we don't want to talk to it anymore. in aacraid_shutdown()
805 device_printf(sc->aac_dev, "shutting down controller..."); in aacraid_shutdown()
807 mtx_lock(&sc->aac_io_lock); in aacraid_shutdown()
809 cc = (struct aac_close_command *)&fib->data[0]; in aacraid_shutdown()
812 cc->Command = htole32(VM_CloseAll); in aacraid_shutdown()
813 cc->ContainerId = htole32(0xfffffffe); in aacraid_shutdown()
822 mtx_unlock(&sc->aac_io_lock); in aacraid_shutdown()
838 sc->aac_state |= AAC_STATE_SUSPEND; in aacraid_suspend()
855 sc->aac_state &= ~AAC_STATE_SUSPEND; in aacraid_resume()
875 sc = ctx->sc; in aacraid_new_intr_type1()
876 vector_no = ctx->vector_no; in aacraid_new_intr_type1()
879 mtx_lock(&sc->aac_io_lock); in aacraid_new_intr_type1()
881 if (sc->msi_enabled) { in aacraid_new_intr_type1()
909 if (sc->aac_sync_cm) { in aacraid_new_intr_type1()
910 cm = sc->aac_sync_cm; in aacraid_new_intr_type1()
912 cm->cm_flags |= AAC_CMD_COMPLETED; in aacraid_new_intr_type1()
913 aac_fib_header_toh(&cm->cm_fib->Header); in aacraid_new_intr_type1()
916 if (cm->cm_complete != NULL) { in aacraid_new_intr_type1()
917 cm->cm_complete(cm); in aacraid_new_intr_type1()
922 sc->flags &= ~AAC_QUEUE_FRZN; in aacraid_new_intr_type1()
923 sc->aac_sync_cm = NULL; in aacraid_new_intr_type1()
938 if (sc->flags & AAC_FLAGS_SYNC_MODE) in aacraid_new_intr_type1()
943 index = sc->aac_host_rrq_idx[vector_no]; in aacraid_new_intr_type1()
947 handle = (le32toh(sc->aac_common->ac_host_rrq[index]) & in aacraid_new_intr_type1()
959 cm = sc->aac_commands + (handle - 1); in aacraid_new_intr_type1()
960 fib = cm->cm_fib; in aacraid_new_intr_type1()
961 aac_fib_header_toh(&fib->Header); in aacraid_new_intr_type1()
962 sc->aac_rrq_outstanding[vector_no]--; in aacraid_new_intr_type1()
964 noMoreAif = (fib->Header.XferState & AAC_FIBSTATE_NOMOREAIF) ? 1:0; in aacraid_new_intr_type1()
971 fib->Header.XferState |= AAC_FIBSTATE_DONEADAP; in aacraid_new_intr_type1()
972 *((u_int32_t *)(fib->data)) = htole32(ST_OK); in aacraid_new_intr_type1()
973 cm->cm_flags |= AAC_CMD_FASTRESP; in aacraid_new_intr_type1()
977 cm->cm_flags |= AAC_CMD_COMPLETED; in aacraid_new_intr_type1()
980 if (cm->cm_complete != NULL) { in aacraid_new_intr_type1()
981 cm->cm_complete(cm); in aacraid_new_intr_type1()
986 sc->flags &= ~AAC_QUEUE_FRZN; in aacraid_new_intr_type1()
989 sc->aac_common->ac_host_rrq[index++] = 0; in aacraid_new_intr_type1()
990 if (index == (vector_no + 1) * sc->aac_vector_cap) in aacraid_new_intr_type1()
991 index = vector_no * sc->aac_vector_cap; in aacraid_new_intr_type1()
992 sc->aac_host_rrq_idx[vector_no] = index; in aacraid_new_intr_type1()
994 if ((isAif && !noMoreAif) || sc->aif_pending) in aacraid_new_intr_type1()
1006 if ((sc->flags & AAC_QUEUE_FRZN) == 0) in aacraid_new_intr_type1()
1008 mtx_unlock(&sc->aac_io_lock); in aacraid_new_intr_type1()
1021 mtx_lock(&sc->aac_io_lock); in aac_command_thread()
1022 sc->aifflags = AAC_AIFFLAGS_RUNNING; in aac_command_thread()
1024 while ((sc->aifflags & AAC_AIFFLAGS_EXIT) == 0) { in aac_command_thread()
1026 if ((sc->aifflags & AAC_AIFFLAGS_PENDING) == 0) in aac_command_thread()
1027 retval = msleep(sc->aifthread, &sc->aac_io_lock, PRIBIO, in aac_command_thread()
1033 if ((sc->aifflags & AAC_AIFFLAGS_ALLOCFIBS) != 0) { in aac_command_thread()
1035 sc->aifflags &= ~AAC_AIFFLAGS_ALLOCFIBS; in aac_command_thread()
1041 * This is pretty low-priority, so it's ok if it doesn't in aac_command_thread()
1048 if (sc->aac_common->ac_printf[0] != 0) in aac_command_thread()
1051 sc->aifflags &= ~AAC_AIFFLAGS_RUNNING; in aac_command_thread()
1052 mtx_unlock(&sc->aac_io_lock); in aac_command_thread()
1053 wakeup(sc->aac_dev); in aac_command_thread()
1064 * to cancel a command that is in progress, we can't protect against the
1074 sc = cm->cm_sc; in aacraid_wait_command()
1076 mtx_assert(&sc->aac_io_lock, MA_OWNED); in aacraid_wait_command()
1081 error = msleep(cm, &sc->aac_io_lock, PRIBIO, "aacraid_wait", 0); in aacraid_wait_command()
1100 if (sc->total_fibs < sc->aac_max_fibs) { in aacraid_alloc_command()
1101 sc->aifflags |= AAC_AIFFLAGS_ALLOCFIBS; in aacraid_alloc_command()
1102 wakeup(sc->aifthread); in aacraid_alloc_command()
1120 sc = cm->cm_sc; in aacraid_release_command()
1122 mtx_assert(&sc->aac_io_lock, MA_OWNED); in aacraid_release_command()
1125 cm->cm_sgtable = NULL; in aacraid_release_command()
1126 cm->cm_flags = 0; in aacraid_release_command()
1127 cm->cm_complete = NULL; in aacraid_release_command()
1128 cm->cm_ccb = NULL; in aacraid_release_command()
1129 cm->cm_passthr_dmat = 0; in aacraid_release_command()
1130 cm->cm_fib->Header.XferState = AAC_FIBSTATE_EMPTY; in aacraid_release_command()
1131 cm->cm_fib->Header.StructType = AAC_FIBTYPE_TFIB; in aacraid_release_command()
1132 cm->cm_fib->Header.Unused = 0; in aacraid_release_command()
1133 cm->cm_fib->Header.SenderSize = cm->cm_sc->aac_max_fib_size; in aacraid_release_command()
1140 cm->cm_fib->Header.u.ReceiverFibAddress = (u_int32_t)cm->cm_fibphys; in aacraid_release_command()
1141 cm->cm_fib->Header.Handle = 0; in aacraid_release_command()
1149 while ((event = TAILQ_FIRST(&sc->aac_ev_cmfree)) != NULL) { in aacraid_release_command()
1150 TAILQ_REMOVE(&sc->aac_ev_cmfree, event, ev_links); in aacraid_release_command()
1151 event->ev_callback(sc, event, event->ev_arg); in aacraid_release_command()
1181 mtx_assert(&sc->aac_io_lock, MA_OWNED); in aac_alloc_commands()
1183 if (sc->total_fibs + sc->aac_max_fibs_alloc > sc->aac_max_fibs) in aac_alloc_commands()
1190 mtx_unlock(&sc->aac_io_lock); in aac_alloc_commands()
1192 if (bus_dmamem_alloc(sc->aac_fib_dmat, (void **)&fm->aac_fibs, in aac_alloc_commands()
1193 BUS_DMA_NOWAIT, &fm->aac_fibmap)) { in aac_alloc_commands()
1194 device_printf(sc->aac_dev, in aac_alloc_commands()
1197 mtx_lock(&sc->aac_io_lock); in aac_alloc_commands()
1201 maxsize = sc->aac_max_fib_size + 31; in aac_alloc_commands()
1202 if (sc->flags & AAC_FLAGS_NEW_COMM_TYPE1) in aac_alloc_commands()
1204 /* Ignore errors since this doesn't bounce */ in aac_alloc_commands()
1205 (void)bus_dmamap_load(sc->aac_fib_dmat, fm->aac_fibmap, fm->aac_fibs, in aac_alloc_commands()
1206 sc->aac_max_fibs_alloc * maxsize, in aac_alloc_commands()
1208 mtx_lock(&sc->aac_io_lock); in aac_alloc_commands()
1211 bzero(fm->aac_fibs, sc->aac_max_fibs_alloc * maxsize); in aac_alloc_commands()
1212 for (i = 0; i < sc->aac_max_fibs_alloc; i++) { in aac_alloc_commands()
1213 cm = sc->aac_commands + sc->total_fibs; in aac_alloc_commands()
1214 fm->aac_commands = cm; in aac_alloc_commands()
1215 cm->cm_sc = sc; in aac_alloc_commands()
1216 cm->cm_fib = (struct aac_fib *) in aac_alloc_commands()
1217 ((u_int8_t *)fm->aac_fibs + i * maxsize); in aac_alloc_commands()
1218 cm->cm_fibphys = fibphys + i * maxsize; in aac_alloc_commands()
1219 if (sc->flags & AAC_FLAGS_NEW_COMM_TYPE1) { in aac_alloc_commands()
1222 (cm->cm_fibphys + sizeof(struct aac_fib_xporthdr) + 31) & ~31; in aac_alloc_commands()
1223 cm->cm_fib = (struct aac_fib *) in aac_alloc_commands()
1224 ((u_int8_t *)cm->cm_fib + (fibphys_aligned - cm->cm_fibphys)); in aac_alloc_commands()
1225 cm->cm_fibphys = fibphys_aligned; in aac_alloc_commands()
1228 fibphys_aligned = (cm->cm_fibphys + 31) & ~31; in aac_alloc_commands()
1229 cm->cm_fib = (struct aac_fib *) in aac_alloc_commands()
1230 ((u_int8_t *)cm->cm_fib + (fibphys_aligned - cm->cm_fibphys)); in aac_alloc_commands()
1231 cm->cm_fibphys = fibphys_aligned; in aac_alloc_commands()
1233 cm->cm_index = sc->total_fibs; in aac_alloc_commands()
1235 if ((error = bus_dmamap_create(sc->aac_buffer_dmat, 0, in aac_alloc_commands()
1236 &cm->cm_datamap)) != 0) in aac_alloc_commands()
1238 if (sc->aac_max_fibs <= 1 || sc->aac_max_fibs - sc->total_fibs > 1) in aac_alloc_commands()
1240 sc->total_fibs++; in aac_alloc_commands()
1244 TAILQ_INSERT_TAIL(&sc->aac_fibmap_tqh, fm, fm_link); in aac_alloc_commands()
1245 fwprintf(sc, HBA_FLAGS_DBG_COMM_B, "total_fibs= %d\n", sc->total_fibs); in aac_alloc_commands()
1249 bus_dmamap_unload(sc->aac_fib_dmat, fm->aac_fibmap); in aac_alloc_commands()
1250 bus_dmamem_free(sc->aac_fib_dmat, fm->aac_fibs, fm->aac_fibmap); in aac_alloc_commands()
1267 while ((fm = TAILQ_FIRST(&sc->aac_fibmap_tqh)) != NULL) { in aac_free_commands()
1268 TAILQ_REMOVE(&sc->aac_fibmap_tqh, fm, fm_link); in aac_free_commands()
1273 for (i = 0; i < sc->aac_max_fibs_alloc && sc->total_fibs--; i++) { in aac_free_commands()
1274 cm = fm->aac_commands + i; in aac_free_commands()
1275 bus_dmamap_destroy(sc->aac_buffer_dmat, cm->cm_datamap); in aac_free_commands()
1277 bus_dmamap_unload(sc->aac_fib_dmat, fm->aac_fibmap); in aac_free_commands()
1278 bus_dmamem_free(sc->aac_fib_dmat, fm->aac_fibs, fm->aac_fibmap); in aac_free_commands()
1284 * Command-mapping helper function - populate this command's s/g table.
1295 sc = cm->cm_sc; in aacraid_map_command_sg()
1296 fib = cm->cm_fib; in aacraid_map_command_sg()
1298 mtx_assert(&sc->aac_io_lock, MA_OWNED); in aacraid_map_command_sg()
1300 if ((sc->flags & AAC_FLAGS_SYNC_MODE) && sc->aac_sync_cm) in aacraid_map_command_sg()
1304 if (cm->cm_sgtable != NULL) { in aacraid_map_command_sg()
1305 if (fib->Header.Command == RawIo2) { in aacraid_map_command_sg()
1311 raw = (struct aac_raw_io2 *)&fib->data[0]; in aacraid_map_command_sg()
1312 sg = (struct aac_sge_ieee1212 *)cm->cm_sgtable; in aacraid_map_command_sg()
1313 raw->sgeCnt = nseg; in aacraid_map_command_sg()
1322 raw->sgeFirstSize = cur_size; in aacraid_map_command_sg()
1324 raw->sgeNominalSize = cur_size; in aacraid_map_command_sg()
1327 cur_size != raw->sgeNominalSize) { in aacraid_map_command_sg()
1337 for (i = min_size / PAGE_SIZE; i >= 1; --i) { in aacraid_map_command_sg()
1340 for (j = 1; j < nseg - 1; ++j) { in aacraid_map_command_sg()
1350 if (i>0 && nseg_new<=sc->aac_sg_tablesize && in aacraid_map_command_sg()
1351 !(sc->hint_flags & 4)) in aacraid_map_command_sg()
1355 raw->flags |= RIO2_SGL_CONFORMANT; in aacraid_map_command_sg()
1363 fib->Header.Size += nseg * in aacraid_map_command_sg()
1366 } else if (fib->Header.Command == RawIo) { in aacraid_map_command_sg()
1368 sg = (struct aac_sg_tableraw *)cm->cm_sgtable; in aacraid_map_command_sg()
1369 sg->SgCount = htole32(nseg); in aacraid_map_command_sg()
1371 sg->SgEntryRaw[i].SgAddress = segs[i].ds_addr; in aacraid_map_command_sg()
1372 sg->SgEntryRaw[i].SgByteCount = segs[i].ds_len; in aacraid_map_command_sg()
1373 sg->SgEntryRaw[i].Next = 0; in aacraid_map_command_sg()
1374 sg->SgEntryRaw[i].Prev = 0; in aacraid_map_command_sg()
1375 sg->SgEntryRaw[i].Flags = 0; in aacraid_map_command_sg()
1376 aac_sg_entryraw_tole(&sg->SgEntryRaw[i]); in aacraid_map_command_sg()
1378 aac_raw_io_tole((struct aac_raw_io *)&fib->data[0]); in aacraid_map_command_sg()
1380 fib->Header.Size += nseg*sizeof(struct aac_sg_entryraw); in aacraid_map_command_sg()
1381 } else if ((cm->cm_sc->flags & AAC_FLAGS_SG_64BIT) == 0) { in aacraid_map_command_sg()
1383 sg = cm->cm_sgtable; in aacraid_map_command_sg()
1384 sg->SgCount = htole32(nseg); in aacraid_map_command_sg()
1386 sg->SgEntry[i].SgAddress = segs[i].ds_addr; in aacraid_map_command_sg()
1387 sg->SgEntry[i].SgByteCount = segs[i].ds_len; in aacraid_map_command_sg()
1388 aac_sg_entry_tole(&sg->SgEntry[i]); in aacraid_map_command_sg()
1391 fib->Header.Size += nseg*sizeof(struct aac_sg_entry); in aacraid_map_command_sg()
1394 sg = (struct aac_sg_table64 *)cm->cm_sgtable; in aacraid_map_command_sg()
1395 sg->SgCount = htole32(nseg); in aacraid_map_command_sg()
1397 sg->SgEntry64[i].SgAddress = segs[i].ds_addr; in aacraid_map_command_sg()
1398 sg->SgEntry64[i].SgByteCount = segs[i].ds_len; in aacraid_map_command_sg()
1399 aac_sg_entry64_tole(&sg->SgEntry64[i]); in aacraid_map_command_sg()
1402 fib->Header.Size += nseg*sizeof(struct aac_sg_entry64); in aacraid_map_command_sg()
1411 cm->cm_fib->Header.SenderFibAddress = (cm->cm_index << 2); in aacraid_map_command_sg()
1412 cm->cm_fib->Header.u.ReceiverFibAddress = (u_int32_t)cm->cm_fibphys; in aacraid_map_command_sg()
1414 /* save a pointer to the command for speedy reverse-lookup */ in aacraid_map_command_sg()
1415 cm->cm_fib->Header.Handle += cm->cm_index + 1; in aacraid_map_command_sg()
1417 if (cm->cm_passthr_dmat == 0) { in aacraid_map_command_sg()
1418 if (cm->cm_flags & AAC_CMD_DATAIN) in aacraid_map_command_sg()
1419 bus_dmamap_sync(sc->aac_buffer_dmat, cm->cm_datamap, in aacraid_map_command_sg()
1421 if (cm->cm_flags & AAC_CMD_DATAOUT) in aacraid_map_command_sg()
1422 bus_dmamap_sync(sc->aac_buffer_dmat, cm->cm_datamap, in aacraid_map_command_sg()
1426 cm->cm_flags |= AAC_CMD_MAPPED; in aacraid_map_command_sg()
1428 if (cm->cm_flags & AAC_CMD_WAIT) { in aacraid_map_command_sg()
1429 aac_fib_header_tole(&fib->Header); in aacraid_map_command_sg()
1431 cm->cm_fibphys, 0, 0, 0, NULL, NULL); in aacraid_map_command_sg()
1432 } else if (sc->flags & AAC_FLAGS_SYNC_MODE) { in aacraid_map_command_sg()
1434 sc->aac_sync_cm = cm; in aacraid_map_command_sg()
1435 aac_fib_header_tole(&fib->Header); in aacraid_map_command_sg()
1437 cm->cm_fibphys, 0, 0, 0, &wait, NULL); in aacraid_map_command_sg()
1441 if (--count == 0) { in aacraid_map_command_sg()
1443 sc->flags |= AAC_QUEUE_FRZN; in aacraid_map_command_sg()
1464 for (i = 1, pos = 1; i < nseg - 1; ++i) { in aac_convert_sgraw2()
1465 for (j = 0; j < raw->sge[i].length / (pages*PAGE_SIZE); ++j) { in aac_convert_sgraw2()
1466 addr_low = raw->sge[i].addrLow + j * pages * PAGE_SIZE; in aac_convert_sgraw2()
1468 sge[pos].addrHigh = raw->sge[i].addrHigh; in aac_convert_sgraw2()
1469 if (addr_low < raw->sge[i].addrLow) in aac_convert_sgraw2()
1476 sge[pos] = raw->sge[nseg-1]; in aac_convert_sgraw2()
1478 raw->sge[i] = sge[i]; in aac_convert_sgraw2()
1481 raw->sgeCnt = nseg_new; in aac_convert_sgraw2()
1482 raw->flags |= RIO2_SGL_CONFORMANT; in aac_convert_sgraw2()
1483 raw->sgeNominalSize = pages * PAGE_SIZE; in aac_convert_sgraw2()
1488 * Unmap a command from controller-visible space.
1495 sc = cm->cm_sc; in aac_unmap_command()
1498 if (!(cm->cm_flags & AAC_CMD_MAPPED)) in aac_unmap_command()
1501 if (cm->cm_datalen != 0 && cm->cm_passthr_dmat == 0) { in aac_unmap_command()
1502 if (cm->cm_flags & AAC_CMD_DATAIN) in aac_unmap_command()
1503 bus_dmamap_sync(sc->aac_buffer_dmat, cm->cm_datamap, in aac_unmap_command()
1505 if (cm->cm_flags & AAC_CMD_DATAOUT) in aac_unmap_command()
1506 bus_dmamap_sync(sc->aac_buffer_dmat, cm->cm_datamap, in aac_unmap_command()
1509 bus_dmamap_unload(sc->aac_buffer_dmat, cm->cm_datamap); in aac_unmap_command()
1511 cm->cm_flags &= ~AAC_CMD_MAPPED; in aac_unmap_command()
1529 sc->aac_common_busaddr = segs[0].ds_addr; in aac_common_map()
1547 device_printf(sc->aac_dev, in aac_check_firmware()
1560 waitCount--; in aac_check_firmware()
1571 device_printf(sc->aac_dev, in aac_check_firmware()
1582 if (sc->flags & AAC_FLAGS_PERC2QC) { in aac_check_firmware()
1585 device_printf(sc->aac_dev, in aac_check_firmware()
1591 major = (AAC_GET_MAILBOX(sc, 1) & 0xff) - 0x30; in aac_check_firmware()
1592 minor = (AAC_GET_MAILBOX(sc, 2) & 0xff) - 0x30; in aac_check_firmware()
1594 device_printf(sc->aac_dev, in aac_check_firmware()
1602 * work-arounds to enable. Some firmware revs don't support this in aac_check_firmware()
1607 device_printf(sc->aac_dev, in aac_check_firmware()
1614 sc->supported_options = options; in aac_check_firmware()
1615 sc->doorbell_mask = AAC_GET_MAILBOX(sc, 3); in aac_check_firmware()
1618 (sc->flags & AAC_FLAGS_NO4GB) == 0) in aac_check_firmware()
1619 sc->flags |= AAC_FLAGS_4GB_WINDOW; in aac_check_firmware()
1621 sc->flags |= AAC_FLAGS_ENABLE_CAM; in aac_check_firmware()
1624 && (sc->hint_flags & 0x1)) { in aac_check_firmware()
1625 device_printf(sc->aac_dev, in aac_check_firmware()
1626 "Enabling 64-bit address support\n"); in aac_check_firmware()
1627 sc->flags |= AAC_FLAGS_SG_64BIT; in aac_check_firmware()
1629 if (sc->aac_if.aif_send_command) { in aac_check_firmware()
1631 sc->flags |= AAC_FLAGS_NEW_COMM | AAC_FLAGS_NEW_COMM_TYPE2; in aac_check_firmware()
1633 sc->flags |= AAC_FLAGS_NEW_COMM | AAC_FLAGS_NEW_COMM_TYPE1; in aac_check_firmware()
1636 sc->flags |= AAC_FLAGS_NEW_COMM | AAC_FLAGS_NEW_COMM_TYPE34; in aac_check_firmware()
1639 sc->flags |= AAC_FLAGS_ARRAY_64BIT; in aac_check_firmware()
1642 if (!(sc->flags & AAC_FLAGS_NEW_COMM)) { in aac_check_firmware()
1643 device_printf(sc->aac_dev, "Communication interface not supported!\n"); in aac_check_firmware()
1647 if (sc->hint_flags & 2) { in aac_check_firmware()
1648 device_printf(sc->aac_dev, in aac_check_firmware()
1650 sc->flags |= AAC_FLAGS_SYNC_MODE; in aac_check_firmware()
1651 } else if (sc->flags & AAC_FLAGS_NEW_COMM_TYPE34) { in aac_check_firmware()
1652 device_printf(sc->aac_dev, in aac_check_firmware()
1654 sc->flags |= AAC_FLAGS_SYNC_MODE; in aac_check_firmware()
1657 /* Check for broken hardware that does a lower number of commands */ in aac_check_firmware()
1658 sc->aac_max_fibs = (sc->flags & AAC_FLAGS_256FIBS ? 256:512); in aac_check_firmware()
1661 if (atu_size > rman_get_size(sc->aac_regs_res0)) { in aac_check_firmware()
1663 sc->aac_dev, SYS_RES_MEMORY, in aac_check_firmware()
1664 sc->aac_regs_rid0, sc->aac_regs_res0); in aac_check_firmware()
1665 sc->aac_regs_res0 = bus_alloc_resource_anywhere( in aac_check_firmware()
1666 sc->aac_dev, SYS_RES_MEMORY, &sc->aac_regs_rid0, in aac_check_firmware()
1668 if (sc->aac_regs_res0 == NULL) { in aac_check_firmware()
1669 sc->aac_regs_res0 = bus_alloc_resource_any( in aac_check_firmware()
1670 sc->aac_dev, SYS_RES_MEMORY, in aac_check_firmware()
1671 &sc->aac_regs_rid0, RF_ACTIVE); in aac_check_firmware()
1672 if (sc->aac_regs_res0 == NULL) { in aac_check_firmware()
1673 device_printf(sc->aac_dev, in aac_check_firmware()
1674 "couldn't allocate register window\n"); in aac_check_firmware()
1678 sc->aac_btag0 = rman_get_bustag(sc->aac_regs_res0); in aac_check_firmware()
1679 sc->aac_bhandle0 = rman_get_bushandle(sc->aac_regs_res0); in aac_check_firmware()
1683 sc->aac_max_fib_size = sizeof(struct aac_fib); in aac_check_firmware()
1684 sc->aac_max_sectors = 128; /* 64KB */ in aac_check_firmware()
1685 sc->aac_max_aif = 1; in aac_check_firmware()
1686 if (sc->flags & AAC_FLAGS_SG_64BIT) in aac_check_firmware()
1687 sc->aac_sg_tablesize = (AAC_FIB_DATASIZE in aac_check_firmware()
1688 - sizeof(struct aac_blockwrite64)) in aac_check_firmware()
1691 sc->aac_sg_tablesize = (AAC_FIB_DATASIZE in aac_check_firmware()
1692 - sizeof(struct aac_blockwrite)) in aac_check_firmware()
1697 sc->aac_max_fib_size = (options & 0xFFFF); in aac_check_firmware()
1698 sc->aac_max_sectors = (options >> 16) << 1; in aac_check_firmware()
1700 sc->aac_sg_tablesize = (options >> 16); in aac_check_firmware()
1702 sc->aac_max_fibs = ((options >> 16) & 0xFFFF); in aac_check_firmware()
1703 if (sc->aac_max_fibs == 0 || sc->aac_hwif != AAC_HWIF_SRCV) in aac_check_firmware()
1704 sc->aac_max_fibs = (options & 0xFFFF); in aac_check_firmware()
1706 sc->aac_max_aif = (options & 0xFFFF); in aac_check_firmware()
1708 sc->aac_max_msix =(sc->flags & AAC_FLAGS_NEW_COMM_TYPE2) ? options : 0; in aac_check_firmware()
1711 maxsize = sc->aac_max_fib_size + 31; in aac_check_firmware()
1712 if (sc->flags & AAC_FLAGS_NEW_COMM_TYPE1) in aac_check_firmware()
1715 sc->aac_max_fib_size -= (maxsize - PAGE_SIZE); in aac_check_firmware()
1718 sc->aac_max_fibs_alloc = PAGE_SIZE / maxsize; in aac_check_firmware()
1720 if (sc->aac_max_fib_size > sizeof(struct aac_fib)) { in aac_check_firmware()
1721 sc->flags |= AAC_FLAGS_RAW_IO; in aac_check_firmware()
1722 device_printf(sc->aac_dev, "Enable Raw I/O\n"); in aac_check_firmware()
1724 if ((sc->flags & AAC_FLAGS_RAW_IO) && in aac_check_firmware()
1725 (sc->flags & AAC_FLAGS_ARRAY_64BIT)) { in aac_check_firmware()
1726 sc->flags |= AAC_FLAGS_LBA_64BIT; in aac_check_firmware()
1727 device_printf(sc->aac_dev, "Enable 64-bit array\n"); in aac_check_firmware()
1745 sc->aac_fibs_pushed_no = 0; in aac_init()
1746 for (i = 0; i < sc->aac_max_msix; i++) in aac_init()
1747 sc->aac_host_rrq_idx[i] = i * sc->aac_vector_cap; in aac_init()
1753 ip = &sc->aac_common->ac_init; in aac_init()
1754 ip->InitStructRevision = AAC_INIT_STRUCT_REVISION; in aac_init()
1755 if (sc->aac_max_fib_size > sizeof(struct aac_fib)) { in aac_init()
1756 ip->InitStructRevision = AAC_INIT_STRUCT_REVISION_4; in aac_init()
1757 sc->flags |= AAC_FLAGS_RAW_IO; in aac_init()
1759 ip->NoOfMSIXVectors = sc->aac_max_msix; in aac_init()
1761 ip->AdapterFibsPhysicalAddress = sc->aac_common_busaddr + in aac_init()
1763 ip->AdapterFibsVirtualAddress = 0; in aac_init()
1764 ip->AdapterFibsSize = AAC_ADAPTER_FIBS * sizeof(struct aac_fib); in aac_init()
1765 ip->AdapterFibAlign = sizeof(struct aac_fib); in aac_init()
1767 ip->PrintfBufferAddress = sc->aac_common_busaddr + in aac_init()
1769 ip->PrintfBufferSize = AAC_PRINTF_BUFSIZE; in aac_init()
1773 * broken firmware versions that do the page->byte conversion twice, in aac_init()
1777 ip->HostPhysMemPages = ctob(physmem) / AAC_PAGE_SIZE; in aac_init()
1778 if (sc->flags & AAC_FLAGS_BROKEN_MEMMAP) { in aac_init()
1779 ip->HostPhysMemPages = in aac_init()
1780 (ip->HostPhysMemPages + AAC_PAGE_SIZE) / AAC_PAGE_SIZE; in aac_init()
1782 ip->HostElapsedSeconds = time_uptime; /* reset later if invalid */ in aac_init()
1784 ip->InitFlags = AAC_INITFLAGS_NEW_COMM_SUPPORTED; in aac_init()
1785 if (sc->flags & AAC_FLAGS_NEW_COMM_TYPE1) { in aac_init()
1786 ip->InitStructRevision = AAC_INIT_STRUCT_REVISION_6; in aac_init()
1787 ip->InitFlags |= (AAC_INITFLAGS_NEW_COMM_TYPE1_SUPPORTED | in aac_init()
1789 device_printf(sc->aac_dev, "New comm. interface type1 enabled\n"); in aac_init()
1790 } else if (sc->flags & AAC_FLAGS_NEW_COMM_TYPE2) { in aac_init()
1791 ip->InitStructRevision = AAC_INIT_STRUCT_REVISION_7; in aac_init()
1792 ip->InitFlags |= (AAC_INITFLAGS_NEW_COMM_TYPE2_SUPPORTED | in aac_init()
1794 device_printf(sc->aac_dev, "New comm. interface type2 enabled\n"); in aac_init()
1796 ip->MaxNumAif = sc->aac_max_aif; in aac_init()
1797 ip->HostRRQ_AddrLow = in aac_init()
1798 sc->aac_common_busaddr + offsetof(struct aac_common, ac_host_rrq); in aac_init()
1799 /* always 32-bit address */ in aac_init()
1800 ip->HostRRQ_AddrHigh = 0; in aac_init()
1802 if (sc->aac_support_opt2 & AAC_SUPPORTED_POWER_MANAGEMENT) { in aac_init()
1803 ip->InitFlags |= AAC_INITFLAGS_DRIVER_SUPPORTS_PM; in aac_init()
1804 ip->InitFlags |= AAC_INITFLAGS_DRIVER_USES_UTC_TIME; in aac_init()
1805 device_printf(sc->aac_dev, "Power Management enabled\n"); in aac_init()
1808 ip->MaxIoCommands = sc->aac_max_fibs; in aac_init()
1809 ip->MaxIoSize = AAC_MAXIO_SIZE(sc); in aac_init()
1810 ip->MaxFibSize = sc->aac_max_fib_size; in aac_init()
1815 * Do controller-type-specific initialisation in aac_init()
1823 sc->aac_common_busaddr + in aac_init()
1826 device_printf(sc->aac_dev, in aac_init()
1850 dev = sc->aac_dev; in aac_define_int_mode()
1852 if (sc->flags & AAC_FLAGS_SYNC_MODE) { in aac_define_int_mode()
1854 sc->aac_max_msix = 1; in aac_define_int_mode()
1855 sc->aac_vector_cap = sc->aac_max_fibs; in aac_define_int_mode()
1860 if (sc->aac_max_msix == 0) { in aac_define_int_mode()
1861 if (sc->aac_hwif == AAC_HWIF_SRC) { in aac_define_int_mode()
1864 device_printf(dev, "alloc msi failed - err=%d; " in aac_define_int_mode()
1868 sc->msi_tupelo = TRUE; in aac_define_int_mode()
1871 if (sc->msi_tupelo) in aac_define_int_mode()
1876 sc->aac_max_msix = 1; in aac_define_int_mode()
1877 sc->aac_vector_cap = sc->aac_max_fibs; in aac_define_int_mode()
1885 if (msi_count > sc->aac_max_msix) in aac_define_int_mode()
1886 msi_count = sc->aac_max_msix; in aac_define_int_mode()
1888 device_printf(dev, "alloc msix failed - msi_count=%d, err=%d; " in aac_define_int_mode()
1892 sc->msi_enabled = TRUE; in aac_define_int_mode()
1893 device_printf(dev, "using MSI-X interrupts (%u vectors)\n", in aac_define_int_mode()
1897 if (!sc->msi_enabled) { in aac_define_int_mode()
1900 device_printf(dev, "alloc msi failed - err=%d; " in aac_define_int_mode()
1904 sc->msi_enabled = TRUE; in aac_define_int_mode()
1909 if (sc->msi_enabled) { in aac_define_int_mode()
1915 sc->msi_enabled = FALSE; in aac_define_int_mode()
1919 if (!sc->msi_enabled) { in aac_define_int_mode()
1921 sc->aac_max_msix = 1; in aac_define_int_mode()
1924 if (sc->aac_max_msix > msi_count) in aac_define_int_mode()
1925 sc->aac_max_msix = msi_count; in aac_define_int_mode()
1927 sc->aac_vector_cap = sc->aac_max_fibs / sc->aac_max_msix; in aac_define_int_mode()
1930 sc->msi_enabled,sc->aac_vector_cap, sc->aac_max_fibs, sc->aac_max_msix); in aac_define_int_mode()
1940 dev = sc->aac_dev; in aac_find_pci_capability()
1980 msi_count = sc->aac_max_msix; in aac_setup_intr()
1981 rid = ((sc->msi_enabled || sc->msi_tupelo)? 1:0); in aac_setup_intr()
1984 if ((res = bus_alloc_resource_any(sc->aac_dev,SYS_RES_IRQ, &rid, in aac_setup_intr()
1986 device_printf(sc->aac_dev,"can't allocate interrupt\n"); in aac_setup_intr()
1989 sc->aac_irq_rid[i] = rid; in aac_setup_intr()
1990 sc->aac_irq[i] = res; in aac_setup_intr()
1991 if (aac_bus_setup_intr(sc->aac_dev, res, in aac_setup_intr()
1993 aacraid_new_intr_type1, &sc->aac_msix[i], &tag)) { in aac_setup_intr()
1994 device_printf(sc->aac_dev, "can't set up interrupt\n"); in aac_setup_intr()
1997 sc->aac_msix[i].vector_no = i; in aac_setup_intr()
1998 sc->aac_msix[i].sc = sc; in aac_setup_intr()
1999 sc->aac_intr[i] = tag; in aac_setup_intr()
2013 mtx_lock(&sc->aac_io_lock); in aac_check_config()
2016 ccfg = (struct aac_cnt_config *)&fib->data[0]; in aac_check_config()
2017 bzero(ccfg, sizeof (*ccfg) - CT_PACKET_SIZE); in aac_check_config()
2018 ccfg->Command = VM_ContainerConfig; in aac_check_config()
2019 ccfg->CTCommand.command = CT_GET_CONFIG_STATUS; in aac_check_config()
2020 ccfg->CTCommand.param[CNT_SIZE] = sizeof(struct aac_cf_status_hdr); in aac_check_config()
2027 cf_shdr = (struct aac_cf_status_hdr *)ccfg->CTCommand.data; in aac_check_config()
2028 if (rval == 0 && ccfg->Command == ST_OK && in aac_check_config()
2029 ccfg->CTCommand.param[0] == CT_OK) { in aac_check_config()
2030 if (le32toh(cf_shdr->action) <= CFACT_PAUSE) { in aac_check_config()
2031 bzero(ccfg, sizeof (*ccfg) - CT_PACKET_SIZE); in aac_check_config()
2032 ccfg->Command = VM_ContainerConfig; in aac_check_config()
2033 ccfg->CTCommand.command = CT_COMMIT_CONFIG; in aac_check_config()
2040 if (rval == 0 && ccfg->Command == ST_OK && in aac_check_config()
2041 ccfg->CTCommand.param[0] == CT_OK) { in aac_check_config()
2046 rval = -2; in aac_check_config()
2051 rval = -3; in aac_check_config()
2055 rval = -1; in aac_check_config()
2059 mtx_unlock(&sc->aac_io_lock); in aac_check_config()
2081 if (!sc->msi_enabled) in aacraid_sync_command()
2110 return (-1); in aacraid_sync_command()
2122 mtx_assert(&sc->aac_io_lock, MA_OWNED); in aac_sync_fib()
2130 fib->Header.XferState = AAC_FIBSTATE_HOSTOWNED | in aac_sync_fib()
2133 fib->Header.XferState |= xferstate; in aac_sync_fib()
2134 fib->Header.Command = command; in aac_sync_fib()
2135 fib->Header.StructType = AAC_FIBTYPE_TFIB; in aac_sync_fib()
2136 fib->Header.Size = sizeof(struct aac_fib_header) + datasize; in aac_sync_fib()
2137 fib->Header.SenderSize = sizeof(struct aac_fib); in aac_sync_fib()
2138 fib->Header.SenderFibAddress = 0; /* Not needed */ in aac_sync_fib()
2139 ReceiverFibAddress = sc->aac_common_busaddr + in aac_sync_fib()
2141 fib->Header.u.ReceiverFibAddress = ReceiverFibAddress; in aac_sync_fib()
2142 aac_fib_header_tole(&fib->Header); in aac_sync_fib()
2150 aac_fib_header_toh(&fib->Header); in aac_sync_fib()
2154 aac_fib_header_toh(&fib->Header); in aac_sync_fib()
2175 deadline = time_uptime - AAC_CMD_TIMEOUT; in aac_timeout()
2176 TAILQ_FOREACH(cm, &sc->aac_busy, cm_link) { in aac_timeout()
2177 if (cm->cm_timestamp < deadline) { in aac_timeout()
2178 device_printf(sc->aac_dev, in aac_timeout()
2180 cm, (int)(time_uptime-cm->cm_timestamp)); in aac_timeout()
2181 AAC_PRINT_FIB(sc, cm->cm_fib); in aac_timeout()
2227 if (sc->msi_enabled) { in aac_src_get_istatus()
2247 if (sc->msi_enabled) { in aac_src_clear_istatus()
2316 (sc->msi_enabled ? AAC_INT_ENABLE_TYPE1_MSIX : in aac_src_access_devreg()
2393 if (sc->msi_enabled && cm->cm_fib->Header.Command != AifRequest && in aac_src_send_command()
2394 sc->aac_max_msix > 1) { in aac_src_send_command()
2397 vector_no = sc->aac_fibs_pushed_no % sc->aac_max_msix; in aac_src_send_command()
2400 if (vector_no == sc->aac_max_msix) in aac_src_send_command()
2402 if (sc->aac_rrq_outstanding[vector_no] < in aac_src_send_command()
2403 sc->aac_vector_cap) in aac_src_send_command()
2412 sc->aac_rrq_outstanding[vector_no]++; in aac_src_send_command()
2413 if (sc->aac_fibs_pushed_no == 0xffffffff) in aac_src_send_command()
2414 sc->aac_fibs_pushed_no = 0; in aac_src_send_command()
2416 sc->aac_fibs_pushed_no++; in aac_src_send_command()
2418 cm->cm_fib->Header.Handle += (vector_no << 16); in aac_src_send_command()
2421 if (sc->flags & AAC_FLAGS_NEW_COMM_TYPE2) { in aac_src_send_command()
2423 fibsize = (cm->cm_fib->Header.Size + 127) / 128 - 1; in aac_src_send_command()
2425 address = cm->cm_fibphys; in aac_src_send_command()
2428 cm->cm_fib->Header.StructType = AAC_FIBTYPE_TFIB2; in aac_src_send_command()
2429 cm->cm_fib->Header.u.TimeStamp = 0L; in aac_src_send_command()
2431 cm->cm_fib->Header.StructType = AAC_FIBTYPE_TFIB2_64; in aac_src_send_command()
2432 cm->cm_fib->Header.u.SenderFibAddressHigh = high_addr; in aac_src_send_command()
2434 cm->cm_fib->Header.SenderFibAddress = (u_int32_t)address; in aac_src_send_command()
2438 cm->cm_fib->Header.Size + 127) / 128 - 1; in aac_src_send_command()
2441 ((unsigned char *)cm->cm_fib - sizeof(struct aac_fib_xporthdr)); in aac_src_send_command()
2442 pFibX->Handle = cm->cm_fib->Header.Handle; in aac_src_send_command()
2443 pFibX->HostAddress = cm->cm_fibphys; in aac_src_send_command()
2444 pFibX->Size = cm->cm_fib->Header.Size; in aac_src_send_command()
2446 address = cm->cm_fibphys - sizeof(struct aac_fib_xporthdr); in aac_src_send_command()
2450 aac_fib_header_tole(&cm->cm_fib->Header); in aac_src_send_command()
2472 return(-1); in aac_src_get_outb_queue()
2497 mtx_lock(&sc->aac_io_lock); in aac_describe_controller()
2500 if (sc->supported_options & AAC_SUPPORTED_SUPPLEMENT_ADAPTER_INFO) { in aac_describe_controller()
2501 fib->data[0] = 0; in aac_describe_controller()
2503 device_printf(sc->aac_dev, "RequestSupplementAdapterInfo failed\n"); in aac_describe_controller()
2507 supp_info = ((struct aac_supplement_adapter_info *)&fib->data[0]); in aac_describe_controller()
2508 adapter_type = (char *)supp_info->AdapterTypeText; in aac_describe_controller()
2509 sc->aac_feature_bits = le32toh(supp_info->FeatureBits); in aac_describe_controller()
2510 sc->aac_support_opt2 = le32toh(supp_info->SupportedOptions2); in aac_describe_controller()
2513 device_printf(sc->aac_dev, "%s, aacraid driver %d.%d.%d-%d\n", in aac_describe_controller()
2518 fib->data[0] = 0; in aac_describe_controller()
2520 device_printf(sc->aac_dev, "RequestAdapterInfo failed\n"); in aac_describe_controller()
2522 mtx_unlock(&sc->aac_io_lock); in aac_describe_controller()
2527 info = (struct aac_adapter_info *)&fib->data[0]; in aac_describe_controller()
2529 sc->aac_revision = info->KernelRevision; in aac_describe_controller()
2532 device_printf(sc->aac_dev, "%s %dMHz, %dMB memory " in aac_describe_controller()
2534 aac_describe_code(aac_cpu_variant, info->CpuVariant), in aac_describe_controller()
2535 info->ClockSpeed, info->TotalMem / (1024 * 1024), in aac_describe_controller()
2536 info->BufferMem / (1024 * 1024), in aac_describe_controller()
2537 info->ExecutionMem / (1024 * 1024), in aac_describe_controller()
2539 info->batteryPlatform)); in aac_describe_controller()
2541 device_printf(sc->aac_dev, in aac_describe_controller()
2542 "Kernel %d.%d-%d, Build %d, S/N %6X\n", in aac_describe_controller()
2543 info->KernelRevision.external.comp.major, in aac_describe_controller()
2544 info->KernelRevision.external.comp.minor, in aac_describe_controller()
2545 info->KernelRevision.external.comp.dash, in aac_describe_controller()
2546 info->KernelRevision.buildNumber, in aac_describe_controller()
2547 (u_int32_t)(info->SerialNumber & 0xffffff)); in aac_describe_controller()
2549 device_printf(sc->aac_dev, "Supported Options=%b\n", in aac_describe_controller()
2550 sc->supported_options, in aac_describe_controller()
2574 mtx_unlock(&sc->aac_io_lock); in aac_describe_controller()
2601 sc = dev->si_drv1; in aac_open()
2603 device_busy(sc->aac_dev); in aac_open()
2616 sc = dev->si_drv1; in aac_ioctl()
2621 switch (as->as_item) { in aac_ioctl()
2625 bcopy(&sc->aac_qstat[as->as_item], &as->as_qstat, in aac_ioctl()
2686 * We don't trust the underland to tell us when to delete a in aac_ioctl()
2719 sc = dev->si_drv1; in aac_poll()
2722 mtx_lock(&sc->aac_io_lock); in aac_poll()
2724 for (ctx = sc->fibctx; ctx; ctx = ctx->next) { in aac_poll()
2725 if (ctx->ctx_idx != sc->aifq_idx || ctx->ctx_wrap) { in aac_poll()
2731 mtx_unlock(&sc->aac_io_lock); in aac_poll()
2735 selrecord(td, &sc->rcv_select); in aac_poll()
2745 switch (event->ev_type) { in aac_ioctl_event()
2747 mtx_assert(&sc->aac_io_lock, MA_OWNED); in aac_ioctl_event()
2766 * - At least the FIB data part from userspace should already be in LE,
2769 * - SG tables are converted to BE by aacraid_map_command_sg(). This
2771 * - aacraid_wait_command() calls functions that convert the FIB header
2788 mtx_lock(&sc->aac_io_lock); in aac_ioctl_sendfib()
2796 mtx_unlock(&sc->aac_io_lock); in aac_ioctl_sendfib()
2799 event->ev_type = AAC_EVENT_CMFREE; in aac_ioctl_sendfib()
2800 event->ev_callback = aac_ioctl_event; in aac_ioctl_sendfib()
2801 event->ev_arg = &cm; in aac_ioctl_sendfib()
2803 msleep(cm, &sc->aac_io_lock, 0, "aacraid_ctlsfib", 0); in aac_ioctl_sendfib()
2805 mtx_unlock(&sc->aac_io_lock); in aac_ioctl_sendfib()
2808 * Fetch the FIB header, then re-copy to get data as well. in aac_ioctl_sendfib()
2810 if ((error = copyin(ufib, cm->cm_fib, in aac_ioctl_sendfib()
2813 size = cm->cm_fib->Header.Size + sizeof(struct aac_fib_header); in aac_ioctl_sendfib()
2814 if (size > sc->aac_max_fib_size) { in aac_ioctl_sendfib()
2815 device_printf(sc->aac_dev, "incoming FIB oversized (%d > %d)\n", in aac_ioctl_sendfib()
2816 size, sc->aac_max_fib_size); in aac_ioctl_sendfib()
2817 size = sc->aac_max_fib_size; in aac_ioctl_sendfib()
2819 if ((error = copyin(ufib, cm->cm_fib, size)) != 0) in aac_ioctl_sendfib()
2821 cm->cm_fib->Header.Size = size; in aac_ioctl_sendfib()
2822 cm->cm_timestamp = time_uptime; in aac_ioctl_sendfib()
2823 cm->cm_datalen = 0; in aac_ioctl_sendfib()
2828 mtx_lock(&sc->aac_io_lock); in aac_ioctl_sendfib()
2830 mtx_unlock(&sc->aac_io_lock); in aac_ioctl_sendfib()
2832 device_printf(sc->aac_dev, in aac_ioctl_sendfib()
2840 size = cm->cm_fib->Header.Size; in aac_ioctl_sendfib()
2841 if (size > sc->aac_max_fib_size) { in aac_ioctl_sendfib()
2842 device_printf(sc->aac_dev, "outbound FIB oversized (%d > %d)\n", in aac_ioctl_sendfib()
2843 size, sc->aac_max_fib_size); in aac_ioctl_sendfib()
2844 size = sc->aac_max_fib_size; in aac_ioctl_sendfib()
2846 error = copyout(cm->cm_fib, ufib, size); in aac_ioctl_sendfib()
2850 mtx_lock(&sc->aac_io_lock); in aac_ioctl_sendfib()
2852 mtx_unlock(&sc->aac_io_lock); in aac_ioctl_sendfib()
2878 mtx_lock(&sc->aac_io_lock); in aac_ioctl_send_raw_srb()
2886 mtx_unlock(&sc->aac_io_lock); in aac_ioctl_send_raw_srb()
2889 event->ev_type = AAC_EVENT_CMFREE; in aac_ioctl_send_raw_srb()
2890 event->ev_callback = aac_ioctl_event; in aac_ioctl_send_raw_srb()
2891 event->ev_arg = &cm; in aac_ioctl_send_raw_srb()
2893 msleep(cm, &sc->aac_io_lock, 0, "aacraid_ctlsraw", 0); in aac_ioctl_send_raw_srb()
2895 mtx_unlock(&sc->aac_io_lock); in aac_ioctl_send_raw_srb()
2897 cm->cm_data = NULL; in aac_ioctl_send_raw_srb()
2899 orig_map = cm->cm_datamap; in aac_ioctl_send_raw_srb()
2901 fib = cm->cm_fib; in aac_ioctl_send_raw_srb()
2902 srbcmd = (struct aac_srb *)fib->data; in aac_ioctl_send_raw_srb()
2903 if ((error = copyin((void *)&user_srb->data_len, &fibsize, in aac_ioctl_send_raw_srb()
2906 if (fibsize > (sc->aac_max_fib_size-sizeof(struct aac_fib_header))) { in aac_ioctl_send_raw_srb()
2913 srbcmd->function = 0; /* SRBF_ExecuteScsi */ in aac_ioctl_send_raw_srb()
2914 srbcmd->retry_limit = 0; /* obsolete */ in aac_ioctl_send_raw_srb()
2917 if (srbcmd->sg_map.SgCount > 1) { in aac_ioctl_send_raw_srb()
2923 srbcmd->sg_map.SgCount * sizeof(struct aac_sg_entry))) { in aac_ioctl_send_raw_srb()
2924 struct aac_sg_entry *sgp = srbcmd->sg_map.SgEntry; in aac_ioctl_send_raw_srb()
2933 srbcmd->sg_map.SgCount * sizeof(struct aac_sg_entry64))) { in aac_ioctl_send_raw_srb()
2936 (struct aac_sg_entry64 *)srbcmd->sg_map.SgEntry; in aac_ioctl_send_raw_srb()
2953 srbcmd->data_len = srb_sg_bytecount; in aac_ioctl_send_raw_srb()
2954 if (srbcmd->sg_map.SgCount == 1) in aac_ioctl_send_raw_srb()
2961 if (bus_dma_tag_create(sc->aac_parent_dmat, /* parent */ in aac_ioctl_send_raw_srb()
2963 (sc->flags & AAC_FLAGS_SG_64BIT) ? in aac_ioctl_send_raw_srb()
2969 sc->aac_sg_tablesize, /* nsegments */ in aac_ioctl_send_raw_srb()
2973 &cm->cm_passthr_dmat)) { in aac_ioctl_send_raw_srb()
2977 if (bus_dmamem_alloc(cm->cm_passthr_dmat, (void **)&cm->cm_data, in aac_ioctl_send_raw_srb()
2978 BUS_DMA_NOWAIT, &cm->cm_datamap)) { in aac_ioctl_send_raw_srb()
2983 cm->cm_datalen = srb_sg_bytecount; in aac_ioctl_send_raw_srb()
2984 if (srbcmd->flags & AAC_SRB_FLAGS_DATA_IN) in aac_ioctl_send_raw_srb()
2985 cm->cm_flags |= AAC_CMD_DATAIN; in aac_ioctl_send_raw_srb()
2986 if (srbcmd->flags & AAC_SRB_FLAGS_DATA_OUT) in aac_ioctl_send_raw_srb()
2987 cm->cm_flags |= AAC_CMD_DATAOUT; in aac_ioctl_send_raw_srb()
2989 if (srbcmd->flags & AAC_SRB_FLAGS_DATA_OUT) { in aac_ioctl_send_raw_srb()
2991 cm->cm_data, cm->cm_datalen)) != 0) in aac_ioctl_send_raw_srb()
2994 bus_dmamap_sync(cm->cm_passthr_dmat, cm->cm_datamap, in aac_ioctl_send_raw_srb()
3000 fib->Header.Size = sizeof(struct aac_fib_header) + in aac_ioctl_send_raw_srb()
3002 fib->Header.XferState = in aac_ioctl_send_raw_srb()
3011 fib->Header.Command = (sc->flags & AAC_FLAGS_SG_64BIT) ? in aac_ioctl_send_raw_srb()
3013 cm->cm_sgtable = (struct aac_sg_table *)&srbcmd->sg_map; in aac_ioctl_send_raw_srb()
3019 bus_dmamap_load(cm->cm_passthr_dmat, in aac_ioctl_send_raw_srb()
3020 cm->cm_datamap, cm->cm_data, in aac_ioctl_send_raw_srb()
3021 cm->cm_datalen, in aac_ioctl_send_raw_srb()
3028 mtx_lock(&sc->aac_io_lock); in aac_ioctl_send_raw_srb()
3029 while (!(cm->cm_flags & AAC_CMD_COMPLETED)) in aac_ioctl_send_raw_srb()
3030 msleep(cm, &sc->aac_io_lock, 0, "aacraid_ctlsrw2", 0); in aac_ioctl_send_raw_srb()
3031 mtx_unlock(&sc->aac_io_lock); in aac_ioctl_send_raw_srb()
3034 if (transfer_data && (le32toh(srbcmd->flags) & AAC_SRB_FLAGS_DATA_IN)) { in aac_ioctl_send_raw_srb()
3035 if ((error = copyout(cm->cm_data, in aac_ioctl_send_raw_srb()
3037 cm->cm_datalen)) != 0) in aac_ioctl_send_raw_srb()
3040 bus_dmamap_sync(cm->cm_passthr_dmat, cm->cm_datamap, in aac_ioctl_send_raw_srb()
3045 aac_srb_response_toh((struct aac_srb_response *)fib->data); in aac_ioctl_send_raw_srb()
3046 error = copyout(fib->data, user_reply, sizeof(struct aac_srb_response)); in aac_ioctl_send_raw_srb()
3049 if (cm && cm->cm_data) { in aac_ioctl_send_raw_srb()
3051 bus_dmamap_unload(cm->cm_passthr_dmat, cm->cm_datamap); in aac_ioctl_send_raw_srb()
3052 bus_dmamem_free(cm->cm_passthr_dmat, cm->cm_data, cm->cm_datamap); in aac_ioctl_send_raw_srb()
3053 cm->cm_datamap = orig_map; in aac_ioctl_send_raw_srb()
3055 if (cm && cm->cm_passthr_dmat) in aac_ioctl_send_raw_srb()
3056 bus_dma_tag_destroy(cm->cm_passthr_dmat); in aac_ioctl_send_raw_srb()
3058 mtx_lock(&sc->aac_io_lock); in aac_ioctl_send_raw_srb()
3060 mtx_unlock(&sc->aac_io_lock); in aac_ioctl_send_raw_srb()
3077 sc->aif_pending = 1; in aac_request_aif()
3080 sc->aif_pending = 0; in aac_request_aif()
3083 fib = cm->cm_fib; in aac_request_aif()
3084 fib->Header.Size = sizeof(struct aac_fib); in aac_request_aif()
3085 fib->Header.XferState = in aac_request_aif()
3094 fib->Header.Handle = 0x00800000; in aac_request_aif()
3095 fib->Header.Command = AifRequest; in aac_request_aif()
3096 ((struct aac_aif_command *)fib->data)->command = htole32(AifReqEvent); in aac_request_aif()
3111 device_unbusy(sc->aac_dev); in aac_cdevpriv_dtor()
3132 aif = (struct aac_aif_command*)&fib->data[0]; in aac_handle_aif()
3136 switch (le32toh(aif->command)) { in aac_handle_aif()
3138 switch (le32toh(aif->data.EN.type)) { in aac_handle_aif()
3143 * doesn't tell us anything else! Re-enumerate the in aac_handle_aif()
3162 * co->co_found was already set to 0 in a in aac_handle_aif()
3169 &sc->aac_container_tqh, in aac_handle_aif()
3171 if (co->co_mntobj.ObjectId == in aac_handle_aif()
3173 co->co_found = 1; in aac_handle_aif()
3200 * were not marked 'found'. Since the controller didn't in aac_handle_aif()
3203 * the co->co_found field. in aac_handle_aif()
3205 co = TAILQ_FIRST(&sc->aac_container_tqh); in aac_handle_aif()
3207 if (co->co_found == 0) { in aac_handle_aif()
3209 TAILQ_REMOVE(&sc->aac_container_tqh, co, in aac_handle_aif()
3215 co->co_found = 0; in aac_handle_aif()
3222 if (sc->cam_rescan_cb != NULL) in aac_handle_aif()
3223 sc->cam_rescan_cb(sc, 0, in aac_handle_aif()
3230 switch (le32toh(aif->data.EN.data.EEE.eventType)) { in aac_handle_aif()
3233 channel = le32toh(aif->data.EN.data.EEE.unitID); in aac_handle_aif()
3234 if (sc->cam_rescan_cb != NULL) in aac_handle_aif()
3235 sc->cam_rescan_cb(sc, in aac_handle_aif()
3245 channel = le32toh(aif->data.EN.data.ECE.container); in aac_handle_aif()
3246 if (sc->cam_rescan_cb != NULL) in aac_handle_aif()
3247 sc->cam_rescan_cb(sc, ((channel>>24) & 0xF) + 1, in aac_handle_aif()
3260 current = sc->aifq_idx; in aac_handle_aif()
3263 sc->aifq_filled = 1; in aac_handle_aif()
3264 bcopy(fib, &sc->aac_aifq[current], sizeof(struct aac_fib)); in aac_handle_aif()
3266 aac_fib_header_tole(&sc->aac_aifq[current].Header); in aac_handle_aif()
3268 if (sc->aifq_filled) { in aac_handle_aif()
3269 for (ctx = sc->fibctx; ctx; ctx = ctx->next) { in aac_handle_aif()
3270 if (next == ctx->ctx_idx) in aac_handle_aif()
3271 ctx->ctx_wrap = 1; in aac_handle_aif()
3272 else if (current == ctx->ctx_idx && ctx->ctx_wrap) in aac_handle_aif()
3273 ctx->ctx_idx = next; in aac_handle_aif()
3276 sc->aifq_idx = next; in aac_handle_aif()
3278 if (sc->aac_state & AAC_STATE_AIF_SLEEPER) in aac_handle_aif()
3279 wakeup(sc->aac_aifq); in aac_handle_aif()
3281 selwakeuppri(&sc->rcv_select, PRIBIO); in aac_handle_aif()
3289 * our driver doesn't follow Adaptec's versioning system. Cheat by just
3346 mtx_lock(&sc->aac_io_lock); in aac_open_aif()
3348 if (sc->fibctx == NULL) in aac_open_aif()
3349 sc->fibctx = fibctx; in aac_open_aif()
3351 for (ctx = sc->fibctx; ctx->next; ctx = ctx->next) in aac_open_aif()
3353 ctx->next = fibctx; in aac_open_aif()
3354 fibctx->prev = ctx; in aac_open_aif()
3358 fibctx->unique = (*(u_int32_t *)&fibctx & 0xffffffff); in aac_open_aif()
3359 ctx = sc->fibctx; in aac_open_aif()
3361 if (ctx->unique == fibctx->unique) { in aac_open_aif()
3362 fibctx->unique++; in aac_open_aif()
3363 ctx = sc->fibctx; in aac_open_aif()
3365 ctx = ctx->next; in aac_open_aif()
3369 error = copyout(&fibctx->unique, (void *)arg, sizeof(u_int32_t)); in aac_open_aif()
3370 mtx_unlock(&sc->aac_io_lock); in aac_open_aif()
3386 mtx_lock(&sc->aac_io_lock); in aac_close_aif()
3387 for (ctx = sc->fibctx; ctx; ctx = ctx->next) { in aac_close_aif()
3388 if (ctx->unique == *(uint32_t *)&arg) { in aac_close_aif()
3389 if (ctx == sc->fibctx) in aac_close_aif()
3390 sc->fibctx = NULL; in aac_close_aif()
3392 ctx->prev->next = ctx->next; in aac_close_aif()
3393 if (ctx->next) in aac_close_aif()
3394 ctx->next->prev = ctx->prev; in aac_close_aif()
3402 mtx_unlock(&sc->aac_io_lock); in aac_close_aif()
3418 mtx_lock(&sc->aac_io_lock); in aac_getnext_aif()
3432 for (ctx = sc->fibctx; ctx; ctx = ctx->next) { in aac_getnext_aif()
3433 if (agf.AdapterFibContext == ctx->unique) in aac_getnext_aif()
3437 mtx_unlock(&sc->aac_io_lock); in aac_getnext_aif()
3444 sc->aac_state |= AAC_STATE_AIF_SLEEPER; in aac_getnext_aif()
3446 mtx_unlock(&sc->aac_io_lock); in aac_getnext_aif()
3447 error = tsleep(sc->aac_aifq, PRIBIO | in aac_getnext_aif()
3449 mtx_lock(&sc->aac_io_lock); in aac_getnext_aif()
3453 sc->aac_state &= ~AAC_STATE_AIF_SLEEPER; in aac_getnext_aif()
3456 mtx_unlock(&sc->aac_io_lock); in aac_getnext_aif()
3470 current = ctx->ctx_idx; in aac_return_aif()
3471 if (current == sc->aifq_idx && !ctx->ctx_wrap) { in aac_return_aif()
3476 copyout(&sc->aac_aifq[current], (void *)uptr, sizeof(struct aac_fib)); in aac_return_aif()
3478 device_printf(sc->aac_dev, in aac_return_aif()
3481 ctx->ctx_wrap = 0; in aac_return_aif()
3482 ctx->ctx_idx = (current + 1) % AAC_AIFQ_LENGTH; in aac_return_aif()
3498 pciinf.bus = pci_get_bus(sc->aac_dev); in aac_get_pci_info()
3499 pciinf.slot = pci_get_slot(sc->aac_dev); in aac_get_pci_info()
3531 (sc->flags & AAC_FLAGS_LBA_64BIT) ? 1 : 0; in aac_supported_features()
3537 (sc->flags & AAC_FLAGS_LBA_64BIT) ? 1 : 0; in aac_supported_features()
3548 * the containers to have b:t:l numbers. Fake it.
3559 mtx_lock(&sc->aac_io_lock); in aac_query_disk()
3563 mtx_unlock(&sc->aac_io_lock); in aac_query_disk()
3568 if (id == -1) { in aac_query_disk()
3569 mtx_unlock(&sc->aac_io_lock); in aac_query_disk()
3573 TAILQ_FOREACH(co, &sc->aac_container_tqh, co_link) { in aac_query_disk()
3574 if (co->co_mntobj.ObjectId == id) in aac_query_disk()
3586 query_disk.Bus = device_get_unit(sc->aac_dev); in aac_query_disk()
3595 mtx_unlock(&sc->aac_io_lock); in aac_query_disk()
3608 device_printf(sc->aac_dev, in aac_container_bus()
3612 child = device_add_child(sc->aac_dev, "aacraidp", DEVICE_UNIT_ANY); in aac_container_bus()
3614 device_printf(sc->aac_dev, in aac_container_bus()
3620 sim->TargetsPerBus = AAC_MAX_CONTAINERS; in aac_container_bus()
3621 sim->BusNumber = 0; in aac_container_bus()
3622 sim->BusType = CONTAINER_BUS; in aac_container_bus()
3623 sim->InitiatorBusId = -1; in aac_container_bus()
3624 sim->aac_sc = sc; in aac_container_bus()
3625 sim->sim_dev = child; in aac_container_bus()
3626 sim->aac_cam = NULL; in aac_container_bus()
3630 TAILQ_INSERT_TAIL(&sc->aac_sim_tqh, sim, sim_link); in aac_container_bus()
3633 mir->MntTable[0].VolType)); in aac_container_bus()
3635 bus_attach_children(sc->aac_dev); in aac_container_bus()
3651 mtx_lock(&sc->aac_io_lock); in aac_get_bus_info()
3653 c_cmd = (struct aac_ctcfg *)&fib->data[0]; in aac_get_bus_info()
3656 c_cmd->Command = VM_ContainerConfig; in aac_get_bus_info()
3657 c_cmd->cmd = CT_GET_SCSI_METHOD; in aac_get_bus_info()
3658 c_cmd->param = 0; in aac_get_bus_info()
3664 device_printf(sc->aac_dev, "Error %d sending " in aac_get_bus_info()
3667 mtx_unlock(&sc->aac_io_lock); in aac_get_bus_info()
3671 c_resp = (struct aac_ctcfg_resp *)&fib->data[0]; in aac_get_bus_info()
3673 if (c_resp->Status != ST_OK) { in aac_get_bus_info()
3674 device_printf(sc->aac_dev, "VM_ContainerConfig returned 0x%x\n", in aac_get_bus_info()
3675 c_resp->Status); in aac_get_bus_info()
3677 mtx_unlock(&sc->aac_io_lock); in aac_get_bus_info()
3681 sc->scsi_method_id = c_resp->param; in aac_get_bus_info()
3683 vmi = (struct aac_vmioctl *)&fib->data[0]; in aac_get_bus_info()
3686 vmi->Command = VM_Ioctl; in aac_get_bus_info()
3687 vmi->ObjType = FT_DRIVE; in aac_get_bus_info()
3688 vmi->MethId = sc->scsi_method_id; in aac_get_bus_info()
3689 vmi->ObjId = 0; in aac_get_bus_info()
3690 vmi->IoctlCmd = GetBusInfo; in aac_get_bus_info()
3696 device_printf(sc->aac_dev, "Error %d sending VMIoctl command\n", in aac_get_bus_info()
3699 mtx_unlock(&sc->aac_io_lock); in aac_get_bus_info()
3703 vmi_resp = (struct aac_vmi_businf_resp *)&fib->data[0]; in aac_get_bus_info()
3705 if (vmi_resp->Status != ST_OK) { in aac_get_bus_info()
3706 device_printf(sc->aac_dev, "VM_Ioctl returned %d\n", in aac_get_bus_info()
3707 vmi_resp->Status); in aac_get_bus_info()
3709 mtx_unlock(&sc->aac_io_lock); in aac_get_bus_info()
3713 bcopy(&vmi_resp->BusInf, &businfo, sizeof(struct aac_getbusinf)); in aac_get_bus_info()
3715 mtx_unlock(&sc->aac_io_lock); in aac_get_bus_info()
3724 device_printf(sc->aac_dev, in aac_get_bus_info()
3729 child = device_add_child(sc->aac_dev, "aacraidp", DEVICE_UNIT_ANY); in aac_get_bus_info()
3731 device_printf(sc->aac_dev, in aac_get_bus_info()
3738 caminf->TargetsPerBus = businfo.TargetsPerBus; in aac_get_bus_info()
3739 caminf->BusNumber = i+1; in aac_get_bus_info()
3740 caminf->BusType = PASSTHROUGH_BUS; in aac_get_bus_info()
3741 caminf->InitiatorBusId = -1; in aac_get_bus_info()
3742 caminf->aac_sc = sc; in aac_get_bus_info()
3743 caminf->sim_dev = child; in aac_get_bus_info()
3744 caminf->aac_cam = NULL; in aac_get_bus_info()
3748 TAILQ_INSERT_TAIL(&sc->aac_sim_tqh, caminf, sim_link); in aac_get_bus_info()
3772 * Once do an IOP reset, basically have to re-initialize the card as
3788 mtx_assert(&sc->aac_io_lock, MA_OWNED); in aac_reset_adapter()
3790 if (sc->aac_state & AAC_STATE_RESET) { in aac_reset_adapter()
3791 device_printf(sc->aac_dev, "aac_reset_adapter() already in progress\n"); in aac_reset_adapter()
3794 sc->aac_state |= AAC_STATE_RESET; in aac_reset_adapter()
3804 cm->cm_flags |= AAC_CMD_RESET; in aac_reset_adapter()
3807 if (cm->cm_complete != NULL) { in aac_reset_adapter()
3808 cm->cm_complete(cm); in aac_reset_adapter()
3819 cm->cm_flags |= AAC_CMD_RESET; in aac_reset_adapter()
3822 if (cm->cm_complete != NULL) { in aac_reset_adapter()
3823 cm->cm_complete(cm); in aac_reset_adapter()
3834 mtx_unlock(&sc->aac_io_lock); in aac_reset_adapter()
3835 (void) aacraid_shutdown(sc->aac_dev); in aac_reset_adapter()
3836 mtx_lock(&sc->aac_io_lock); in aac_reset_adapter()
3840 if (sc->aac_support_opt2 & AAC_SUPPORTED_MU_RESET) { in aac_reset_adapter()
3844 * 10000 * 100us = 1000,000us = 1000ms = 1s in aac_reset_adapter()
3849 waitCount--; in aac_reset_adapter()
3854 if (ret && !sc->doorbell_mask) { in aac_reset_adapter()
3859 device_printf(sc->aac_dev, in aac_reset_adapter()
3863 device_printf(sc->aac_dev, in aac_reset_adapter()
3869 pc = (struct aac_pause_command *)&fib->data[0]; in aac_reset_adapter()
3870 pc->Command = VM_ContainerConfig; in aac_reset_adapter()
3871 pc->Type = CT_PAUSE_IO; in aac_reset_adapter()
3872 pc->Timeout = 1; in aac_reset_adapter()
3873 pc->Min = 1; in aac_reset_adapter()
3874 pc->NoRescan = 1; in aac_reset_adapter()
3883 } else if (sc->doorbell_mask) { in aac_reset_adapter()
3885 reset_mask = sc->doorbell_mask; in aac_reset_adapter()
3888 (sc->aac_support_opt2 & AAC_SUPPORTED_DOORBELL_RESET)) { in aac_reset_adapter()
3893 * 10000 * 100us = 1000,000us = 1000ms = 1s in aac_reset_adapter()
3898 waitCount--; in aac_reset_adapter()
3906 max_msix_orig = sc->aac_max_msix; in aac_reset_adapter()
3907 msi_enabled_orig = sc->msi_enabled; in aac_reset_adapter()
3908 sc->msi_enabled = FALSE; in aac_reset_adapter()
3911 if (!(sc->flags & AAC_FLAGS_SYNC_MODE)) { in aac_reset_adapter()
3912 sc->aac_max_msix = max_msix_orig; in aac_reset_adapter()
3914 sc->msi_enabled = msi_enabled_orig; in aac_reset_adapter()
3917 mtx_unlock(&sc->aac_io_lock); in aac_reset_adapter()
3919 mtx_lock(&sc->aac_io_lock); in aac_reset_adapter()
3923 sc->aac_state &= ~AAC_STATE_RESET; in aac_reset_adapter()