Lines Matching refs:sc

77 static void	aac_add_container(struct aac_softc *sc,
80 static void aac_get_bus_info(struct aac_softc *sc);
81 static void aac_container_bus(struct aac_softc *sc);
83 static int aac_convert_sgraw2(struct aac_softc *sc, struct aac_raw_io2 *raw,
87 static void aac_timeout(struct aac_softc *sc);
88 static void aac_command_thread(struct aac_softc *sc);
89 static int aac_sync_fib(struct aac_softc *sc, u_int32_t command,
95 static int aac_alloc_commands(struct aac_softc *sc);
96 static void aac_free_commands(struct aac_softc *sc);
100 static int aac_alloc(struct aac_softc *sc);
103 static int aac_check_firmware(struct aac_softc *sc);
104 static void aac_define_int_mode(struct aac_softc *sc);
105 static int aac_init(struct aac_softc *sc);
106 static int aac_find_pci_capability(struct aac_softc *sc, int cap);
107 static int aac_setup_intr(struct aac_softc *sc);
108 static int aac_check_config(struct aac_softc *sc);
111 static int aac_src_get_fwstatus(struct aac_softc *sc);
112 static void aac_src_qnotify(struct aac_softc *sc, int qbit);
113 static int aac_src_get_istatus(struct aac_softc *sc);
114 static void aac_src_clear_istatus(struct aac_softc *sc, int mask);
115 static void aac_src_set_mailbox(struct aac_softc *sc, u_int32_t command,
118 static int aac_src_get_mailbox(struct aac_softc *sc, int mb);
119 static void aac_src_access_devreg(struct aac_softc *sc, int mode);
120 static int aac_src_send_command(struct aac_softc *sc, struct aac_command *cm);
121 static int aac_src_get_outb_queue(struct aac_softc *sc);
122 static void aac_src_set_outb_queue(struct aac_softc *sc, int index);
138 static void aac_srcv_set_mailbox(struct aac_softc *sc, u_int32_t command,
141 static int aac_srcv_get_mailbox(struct aac_softc *sc, int mb);
183 static void aac_describe_controller(struct aac_softc *sc);
196 static int aac_ioctl_sendfib(struct aac_softc *sc, caddr_t ufib);
197 static int aac_ioctl_send_raw_srb(struct aac_softc *sc, caddr_t arg);
198 static void aac_handle_aif(struct aac_softc *sc, struct aac_fib *fib);
199 static void aac_request_aif(struct aac_softc *sc);
200 static int aac_rev_check(struct aac_softc *sc, caddr_t udata);
201 static int aac_open_aif(struct aac_softc *sc, caddr_t arg);
202 static int aac_close_aif(struct aac_softc *sc, caddr_t arg);
203 static int aac_getnext_aif(struct aac_softc *sc, caddr_t arg);
204 static int aac_return_aif(struct aac_softc *sc,
206 static int aac_query_disk(struct aac_softc *sc, caddr_t uptr);
207 static int aac_get_pci_info(struct aac_softc *sc, caddr_t uptr);
208 static int aac_supported_features(struct aac_softc *sc, caddr_t uptr);
209 static void aac_ioctl_event(struct aac_softc *sc,
211 static int aac_reset_adapter(struct aac_softc *sc);
212 static int aac_get_container_info(struct aac_softc *sc,
217 aac_check_adapter_health(struct aac_softc *sc, u_int8_t *bled);
244 aacraid_attach(struct aac_softc *sc)
252 fwprintf(sc, HBA_FLAGS_DBG_FUNCTION_ENTRY_B, "");
253 sc->hint_flags = device_get_flags(sc->aac_dev);
257 aac_initq_free(sc);
258 aac_initq_ready(sc);
259 aac_initq_busy(sc);
262 sc->aac_state |= AAC_STATE_SUSPEND;
267 sc->msi_enabled = sc->msi_tupelo = FALSE;
268 if ((error = aac_check_firmware(sc)) != 0)
274 mtx_init(&sc->aac_io_lock, "AACRAID I/O lock", NULL, MTX_DEF);
275 TAILQ_INIT(&sc->aac_container_tqh);
276 TAILQ_INIT(&sc->aac_ev_cmfree);
280 callout_init_mtx(&sc->aac_daemontime, &sc->aac_io_lock, 0);
285 if ((error = aac_alloc(sc)) != 0)
287 aac_define_int_mode(sc);
288 if (!(sc->flags & AAC_FLAGS_SYNC_MODE)) {
289 if ((error = aac_init(sc)) != 0)
296 if ((error = aac_setup_intr(sc)) != 0)
302 aac_describe_controller(sc);
307 unit = device_get_unit(sc->aac_dev);
308 sc->aac_dev_t = make_dev(&aacraid_cdevsw, unit, UID_ROOT, GID_OPERATOR,
310 sc->aac_dev_t->si_drv1 = sc;
313 if (aac_kthread_create((void(*)(void *))aac_command_thread, sc,
314 &sc->aifthread, 0, 0, "aacraid%daif", unit))
318 if ((sc->eh = EVENTHANDLER_REGISTER(shutdown_final, aacraid_shutdown,
319 sc->aac_dev, SHUTDOWN_PRI_DEFAULT)) == NULL)
320 device_printf(sc->aac_dev,
324 mtx_lock(&sc->aac_io_lock);
325 aac_alloc_sync_fib(sc, &fib);
328 if ((aac_get_container_info(sc, fib, i, &mir, &uid)) != 0)
332 aac_add_container(sc, &mir, 0, uid);
335 aac_release_sync_fib(sc);
336 mtx_unlock(&sc->aac_io_lock);
339 TAILQ_INIT(&sc->aac_sim_tqh);
340 aac_container_bus(sc);
342 if ((sc->flags & AAC_FLAGS_ENABLE_CAM) != 0)
343 aac_get_bus_info(sc);
346 bus_generic_attach(sc->aac_dev);
349 sc->aac_state &= ~AAC_STATE_SUSPEND;
352 AAC_ACCESS_DEVREG(sc, AAC_ENABLE_INTERRUPT);
355 mtx_lock(&sc->aac_io_lock);
356 callout_reset(&sc->aac_daemontime, 60 * hz, aac_daemon, sc);
357 mtx_unlock(&sc->aac_io_lock);
363 sc->timeout_id = timeout(aac_daemon, (void *)sc, tvtohz(&tv));
373 struct aac_softc *sc;
378 sc = arg;
379 fwprintf(sc, HBA_FLAGS_DBG_FUNCTION_ENTRY_B, "");
382 mtx_assert(&sc->aac_io_lock, MA_OWNED);
383 if (callout_pending(&sc->aac_daemontime) ||
384 callout_active(&sc->aac_daemontime) == 0)
387 mtx_lock(&sc->aac_io_lock);
391 if (!aacraid_alloc_command(sc, &cm)) {
416 callout_schedule(&sc->aac_daemontime, 30 * 60 * hz);
418 mtx_unlock(&sc->aac_io_lock);
421 sc->timeout_id = timeout(aac_daemon, (void *)sc, tvtohz(&tv));
426 aacraid_add_event(struct aac_softc *sc, struct aac_event *event)
431 TAILQ_INSERT_TAIL(&sc->aac_ev_cmfree, event, ev_links);
434 device_printf(sc->aac_dev, "aac_add event: unknown event %d\n",
446 aac_get_container_info(struct aac_softc *sc, struct aac_fib *sync_fib, int cid,
456 if (aacraid_alloc_command(sc, &cm)) {
457 device_printf(sc->aac_dev,
468 if (sc->aac_support_opt2 & AAC_SUPPORTED_VARIABLE_BLOCK_SIZE)
470 else if (sc->flags & AAC_FLAGS_LBA_64BIT)
478 if (aac_sync_fib(sc, ContainerCommand, 0, fib,
480 device_printf(sc->aac_dev, "Error probing container %d\n", cid);
500 device_printf(sc->aac_dev, "Error probing container %d\n", cid);
511 if (!(sc->aac_support_opt2 & AAC_SUPPORTED_VARIABLE_BLOCK_SIZE)) {
522 rval = aac_sync_fib(sc, ContainerCommand, 0, fib,
557 aac_add_container(struct aac_softc *sc, struct aac_mntinforesp *mir, int f,
562 fwprintf(sc, HBA_FLAGS_DBG_FUNCTION_ENTRY_B, "");
579 TAILQ_INSERT_TAIL(&sc->aac_container_tqh, co, co_link);
584 * Allocate resources associated with (sc)
587 aac_alloc(struct aac_softc *sc)
591 fwprintf(sc, HBA_FLAGS_DBG_FUNCTION_ENTRY_B, "");
596 if (bus_dma_tag_create(sc->aac_parent_dmat, /* parent */
598 (sc->flags & AAC_FLAGS_SG_64BIT) ?
603 sc->aac_max_sectors << 9, /* maxsize */
604 sc->aac_sg_tablesize, /* nsegments */
608 &sc->aac_io_lock, /* lockfuncarg */
609 &sc->aac_buffer_dmat)) {
610 device_printf(sc->aac_dev, "can't allocate buffer DMA tag\n");
617 if (sc->flags & AAC_FLAGS_NEW_COMM_TYPE1)
618 maxsize = sc->aac_max_fibs_alloc * (sc->aac_max_fib_size +
621 maxsize = sc->aac_max_fibs_alloc * (sc->aac_max_fib_size + 31);
622 if (bus_dma_tag_create(sc->aac_parent_dmat, /* parent */
624 (sc->flags & AAC_FLAGS_4GB_WINDOW) ?
634 &sc->aac_fib_dmat)) {
635 device_printf(sc->aac_dev, "can't allocate FIB DMA tag\n");
643 maxsize += sc->aac_max_fibs * sizeof(u_int32_t);
644 if (bus_dma_tag_create(sc->aac_parent_dmat, /* parent */
646 (sc->flags & AAC_FLAGS_4GB_WINDOW) ?
656 &sc->aac_common_dmat)) {
657 device_printf(sc->aac_dev,
661 if (bus_dmamem_alloc(sc->aac_common_dmat, (void **)&sc->aac_common,
662 BUS_DMA_NOWAIT, &sc->aac_common_dmamap)) {
663 device_printf(sc->aac_dev, "can't allocate common structure\n");
667 (void)bus_dmamap_load(sc->aac_common_dmat, sc->aac_common_dmamap,
668 sc->aac_common, maxsize,
669 aac_common_map, sc, 0);
670 bzero(sc->aac_common, maxsize);
673 TAILQ_INIT(&sc->aac_fibmap_tqh);
674 sc->aac_commands = malloc(sc->aac_max_fibs * sizeof(struct aac_command),
676 mtx_lock(&sc->aac_io_lock);
677 while (sc->total_fibs < sc->aac_max_fibs) {
678 if (aac_alloc_commands(sc) != 0)
681 mtx_unlock(&sc->aac_io_lock);
682 if (sc->total_fibs == 0)
689 * Free all of the resources associated with (sc)
694 aacraid_free(struct aac_softc *sc)
698 fwprintf(sc, HBA_FLAGS_DBG_FUNCTION_ENTRY_B, "");
701 if (sc->aac_dev_t != NULL)
702 destroy_dev(sc->aac_dev_t);
705 aac_free_commands(sc);
706 if (sc->aac_fib_dmat)
707 bus_dma_tag_destroy(sc->aac_fib_dmat);
709 free(sc->aac_commands, M_AACRAIDBUF);
712 if (sc->aac_common) {
713 bus_dmamap_unload(sc->aac_common_dmat, sc->aac_common_dmamap);
714 bus_dmamem_free(sc->aac_common_dmat, sc->aac_common,
715 sc->aac_common_dmamap);
717 if (sc->aac_common_dmat)
718 bus_dma_tag_destroy(sc->aac_common_dmat);
722 if (sc->aac_intr[i])
723 bus_teardown_intr(sc->aac_dev,
724 sc->aac_irq[i], sc->aac_intr[i]);
725 if (sc->aac_irq[i])
726 bus_release_resource(sc->aac_dev, SYS_RES_IRQ,
727 sc->aac_irq_rid[i], sc->aac_irq[i]);
731 if (sc->msi_enabled || sc->msi_tupelo)
732 pci_release_msi(sc->aac_dev);
735 if (sc->aac_buffer_dmat)
736 bus_dma_tag_destroy(sc->aac_buffer_dmat);
739 if (sc->aac_parent_dmat)
740 bus_dma_tag_destroy(sc->aac_parent_dmat);
743 if (sc->aac_regs_res0 != NULL)
744 bus_release_resource(sc->aac_dev, SYS_RES_MEMORY,
745 sc->aac_regs_rid0, sc->aac_regs_res0);
746 if (sc->aac_regs_res1 != NULL)
747 bus_release_resource(sc->aac_dev, SYS_RES_MEMORY,
748 sc->aac_regs_rid1, sc->aac_regs_res1);
757 struct aac_softc *sc;
762 sc = device_get_softc(dev);
763 fwprintf(sc, HBA_FLAGS_DBG_FUNCTION_ENTRY_B, "");
766 callout_drain(&sc->aac_daemontime);
768 untimeout(aac_daemon, (void *)sc, sc->timeout_id);
771 while ((co = TAILQ_FIRST(&sc->aac_container_tqh)) != NULL) {
772 TAILQ_REMOVE(&sc->aac_container_tqh, co, co_link);
777 while ((sim = TAILQ_FIRST(&sc->aac_sim_tqh)) != NULL) {
778 TAILQ_REMOVE(&sc->aac_sim_tqh, sim, sim_link);
785 if (sc->aifflags & AAC_AIFFLAGS_RUNNING) {
786 sc->aifflags |= AAC_AIFFLAGS_EXIT;
787 wakeup(sc->aifthread);
788 tsleep(sc->aac_dev, PUSER | PCATCH, "aac_dch", 30 * hz);
791 if (sc->aifflags & AAC_AIFFLAGS_RUNNING)
797 EVENTHANDLER_DEREGISTER(shutdown_final, sc->eh);
799 aacraid_free(sc);
801 mtx_destroy(&sc->aac_io_lock);
817 struct aac_softc *sc;
821 sc = device_get_softc(dev);
822 fwprintf(sc, HBA_FLAGS_DBG_FUNCTION_ENTRY_B, "");
824 sc->aac_state |= AAC_STATE_SUSPEND;
831 device_printf(sc->aac_dev, "shutting down controller...");
833 mtx_lock(&sc->aac_io_lock);
834 aac_alloc_sync_fib(sc, &fib);
840 if (aac_sync_fib(sc, ContainerCommand, 0, fib,
846 AAC_ACCESS_DEVREG(sc, AAC_DISABLE_INTERRUPT);
847 aac_release_sync_fib(sc);
848 mtx_unlock(&sc->aac_io_lock);
859 struct aac_softc *sc;
861 sc = device_get_softc(dev);
863 fwprintf(sc, HBA_FLAGS_DBG_FUNCTION_ENTRY_B, "");
864 sc->aac_state |= AAC_STATE_SUSPEND;
866 AAC_ACCESS_DEVREG(sc, AAC_DISABLE_INTERRUPT);
876 struct aac_softc *sc;
878 sc = device_get_softc(dev);
880 fwprintf(sc, HBA_FLAGS_DBG_FUNCTION_ENTRY_B, "");
881 sc->aac_state &= ~AAC_STATE_SUSPEND;
882 AAC_ACCESS_DEVREG(sc, AAC_ENABLE_INTERRUPT);
893 struct aac_softc *sc;
901 sc = ctx->sc;
904 fwprintf(sc, HBA_FLAGS_DBG_FUNCTION_ENTRY_B, "");
905 mtx_lock(&sc->aac_io_lock);
907 if (sc->msi_enabled) {
910 bellbits = AAC_MEM0_GETREG4(sc, AAC_SRC_ODBR_MSI);
918 bellbits = AAC_MEM0_GETREG4(sc, AAC_SRC_ODBR_R);
921 AAC_MEM0_SETREG4(sc, AAC_SRC_ODBR_C, bellbits);
924 AAC_MEM0_SETREG4(sc, AAC_SRC_ODBR_C, bellbits);
931 AAC_MEM0_GETREG4(sc, AAC_SRC_ODBR_R);
935 if (sc->aac_sync_cm) {
936 cm = sc->aac_sync_cm;
945 sc->flags &= ~AAC_QUEUE_FRZN;
946 sc->aac_sync_cm = NULL;
953 aac_request_aif(sc);
960 index = sc->aac_host_rrq_idx[vector_no];
964 handle = (sc->aac_common->ac_host_rrq[index] & 0x7fffffff);
975 cm = sc->aac_commands + (handle - 1);
977 sc->aac_rrq_outstanding[vector_no]--;
981 aac_handle_aif(sc, fib);
1001 sc->flags &= ~AAC_QUEUE_FRZN;
1004 sc->aac_common->ac_host_rrq[index++] = 0;
1005 if (index == (vector_no + 1) * sc->aac_vector_cap)
1006 index = vector_no * sc->aac_vector_cap;
1007 sc->aac_host_rrq_idx[vector_no] = index;
1009 if ((isAif && !noMoreAif) || sc->aif_pending)
1010 aac_request_aif(sc);
1015 aac_request_aif(sc);
1016 AAC_ACCESS_DEVREG(sc, AAC_CLEAR_AIF_BIT);
1021 if ((sc->flags & AAC_QUEUE_FRZN) == 0)
1022 aacraid_startio(sc);
1023 mtx_unlock(&sc->aac_io_lock);
1030 aac_command_thread(struct aac_softc *sc)
1034 fwprintf(sc, HBA_FLAGS_DBG_FUNCTION_ENTRY_B, "");
1036 mtx_lock(&sc->aac_io_lock);
1037 sc->aifflags = AAC_AIFFLAGS_RUNNING;
1039 while ((sc->aifflags & AAC_AIFFLAGS_EXIT) == 0) {
1042 if ((sc->aifflags & AAC_AIFFLAGS_PENDING) == 0)
1043 retval = msleep(sc->aifthread, &sc->aac_io_lock, PRIBIO,
1051 if ((sc->aifflags & AAC_AIFFLAGS_ALLOCFIBS) != 0) {
1052 aac_alloc_commands(sc);
1053 sc->aifflags &= ~AAC_AIFFLAGS_ALLOCFIBS;
1054 aacraid_startio(sc);
1063 aac_timeout(sc);
1066 if (sc->aac_common->ac_printf[0] != 0)
1067 aac_print_printf(sc);
1069 sc->aifflags &= ~AAC_AIFFLAGS_RUNNING;
1070 mtx_unlock(&sc->aac_io_lock);
1071 wakeup(sc->aac_dev);
1089 struct aac_softc *sc;
1092 sc = cm->cm_sc;
1093 fwprintf(sc, HBA_FLAGS_DBG_FUNCTION_ENTRY_B, "");
1094 mtx_assert(&sc->aac_io_lock, MA_OWNED);
1098 aacraid_startio(sc);
1099 error = msleep(cm, &sc->aac_io_lock, PRIBIO, "aacraid_wait", 0);
1111 aacraid_alloc_command(struct aac_softc *sc, struct aac_command **cmp)
1115 fwprintf(sc, HBA_FLAGS_DBG_FUNCTION_ENTRY_B, "");
1117 if ((cm = aac_dequeue_free(sc)) == NULL) {
1118 if (sc->total_fibs < sc->aac_max_fibs) {
1119 sc->aifflags |= AAC_AIFFLAGS_ALLOCFIBS;
1120 wakeup(sc->aifthread);
1136 struct aac_softc *sc;
1138 sc = cm->cm_sc;
1139 fwprintf(sc, HBA_FLAGS_DBG_FUNCTION_ENTRY_B, "");
1140 mtx_assert(&sc->aac_io_lock, MA_OWNED);
1167 while ((event = TAILQ_FIRST(&sc->aac_ev_cmfree)) != NULL) {
1168 TAILQ_REMOVE(&sc->aac_ev_cmfree, event, ev_links);
1169 event->ev_callback(sc, event, event->ev_arg);
1190 aac_alloc_commands(struct aac_softc *sc)
1198 fwprintf(sc, HBA_FLAGS_DBG_FUNCTION_ENTRY_B, "");
1199 mtx_assert(&sc->aac_io_lock, MA_OWNED);
1201 if (sc->total_fibs + sc->aac_max_fibs_alloc > sc->aac_max_fibs)
1208 mtx_unlock(&sc->aac_io_lock);
1210 if (bus_dmamem_alloc(sc->aac_fib_dmat, (void **)&fm->aac_fibs,
1212 device_printf(sc->aac_dev,
1215 mtx_lock(&sc->aac_io_lock);
1219 maxsize = sc->aac_max_fib_size + 31;
1220 if (sc->flags & AAC_FLAGS_NEW_COMM_TYPE1)
1223 (void)bus_dmamap_load(sc->aac_fib_dmat, fm->aac_fibmap, fm->aac_fibs,
1224 sc->aac_max_fibs_alloc * maxsize,
1226 mtx_lock(&sc->aac_io_lock);
1229 bzero(fm->aac_fibs, sc->aac_max_fibs_alloc * maxsize);
1230 for (i = 0; i < sc->aac_max_fibs_alloc; i++) {
1231 cm = sc->aac_commands + sc->total_fibs;
1233 cm->cm_sc = sc;
1237 if (sc->flags & AAC_FLAGS_NEW_COMM_TYPE1) {
1251 cm->cm_index = sc->total_fibs;
1253 if ((error = bus_dmamap_create(sc->aac_buffer_dmat, 0,
1256 if (sc->aac_max_fibs <= 1 || sc->aac_max_fibs - sc->total_fibs > 1)
1258 sc->total_fibs++;
1262 TAILQ_INSERT_TAIL(&sc->aac_fibmap_tqh, fm, fm_link);
1263 fwprintf(sc, HBA_FLAGS_DBG_COMM_B, "total_fibs= %d\n", sc->total_fibs);
1267 bus_dmamap_unload(sc->aac_fib_dmat, fm->aac_fibmap);
1268 bus_dmamem_free(sc->aac_fib_dmat, fm->aac_fibs, fm->aac_fibmap);
1277 aac_free_commands(struct aac_softc *sc)
1283 fwprintf(sc, HBA_FLAGS_DBG_FUNCTION_ENTRY_B, "");
1285 while ((fm = TAILQ_FIRST(&sc->aac_fibmap_tqh)) != NULL) {
1287 TAILQ_REMOVE(&sc->aac_fibmap_tqh, fm, fm_link);
1292 for (i = 0; i < sc->aac_max_fibs_alloc && sc->total_fibs--; i++) {
1294 bus_dmamap_destroy(sc->aac_buffer_dmat, cm->cm_datamap);
1296 bus_dmamap_unload(sc->aac_fib_dmat, fm->aac_fibmap);
1297 bus_dmamem_free(sc->aac_fib_dmat, fm->aac_fibs, fm->aac_fibmap);
1308 struct aac_softc *sc;
1314 sc = cm->cm_sc;
1316 fwprintf(sc, HBA_FLAGS_DBG_FUNCTION_ENTRY_B, "nseg %d", nseg);
1317 mtx_assert(&sc->aac_io_lock, MA_OWNED);
1319 if ((sc->flags & AAC_FLAGS_SYNC_MODE) && sc->aac_sync_cm)
1369 if (i>0 && nseg_new<=sc->aac_sg_tablesize &&
1370 !(sc->hint_flags & 4))
1371 nseg = aac_convert_sgraw2(sc,
1430 bus_dmamap_sync(sc->aac_buffer_dmat, cm->cm_datamap,
1433 bus_dmamap_sync(sc->aac_buffer_dmat, cm->cm_datamap,
1440 aacraid_sync_command(sc, AAC_MONKER_SYNCFIB,
1442 } else if (sc->flags & AAC_FLAGS_SYNC_MODE) {
1444 sc->aac_sync_cm = cm;
1445 aacraid_sync_command(sc, AAC_MONKER_SYNCFIB,
1449 while (AAC_SEND_COMMAND(sc, cm) != 0) {
1452 sc->flags |= AAC_QUEUE_FRZN;
1462 aac_convert_sgraw2(struct aac_softc *sc, struct aac_raw_io2 *raw,
1504 struct aac_softc *sc;
1506 sc = cm->cm_sc;
1507 fwprintf(sc, HBA_FLAGS_DBG_FUNCTION_ENTRY_B, "");
1514 bus_dmamap_sync(sc->aac_buffer_dmat, cm->cm_datamap,
1517 bus_dmamap_sync(sc->aac_buffer_dmat, cm->cm_datamap,
1520 bus_dmamap_unload(sc->aac_buffer_dmat, cm->cm_datamap);
1535 struct aac_softc *sc;
1537 sc = (struct aac_softc *)arg;
1538 fwprintf(sc, HBA_FLAGS_DBG_FUNCTION_ENTRY_B, "");
1540 sc->aac_common_busaddr = segs[0].ds_addr;
1544 aac_check_firmware(struct aac_softc *sc)
1550 fwprintf(sc, HBA_FLAGS_DBG_FUNCTION_ENTRY_B, "");
1553 if (AAC_GET_FWSTATUS(sc) & AAC_FLASH_UPD_PENDING) {
1556 code = AAC_GET_FWSTATUS(sc);
1558 device_printf(sc->aac_dev,
1580 code = AAC_GET_FWSTATUS(sc);
1582 device_printf(sc->aac_dev,
1593 if (sc->flags & AAC_FLAGS_PERC2QC) {
1594 if (aacraid_sync_command(sc, AAC_MONKER_GETKERNVER, 0, 0, 0, 0,
1596 device_printf(sc->aac_dev,
1602 major = (AAC_GET_MAILBOX(sc, 1) & 0xff) - 0x30;
1603 minor = (AAC_GET_MAILBOX(sc, 2) & 0xff) - 0x30;
1605 device_printf(sc->aac_dev,
1616 if (aacraid_sync_command(sc, AAC_MONKER_GETINFO, 0, 0, 0, 0, &status, NULL)) {
1618 device_printf(sc->aac_dev,
1623 options = AAC_GET_MAILBOX(sc, 1);
1624 atu_size = AAC_GET_MAILBOX(sc, 2);
1625 sc->supported_options = options;
1626 sc->doorbell_mask = AAC_GET_MAILBOX(sc, 3);
1629 (sc->flags & AAC_FLAGS_NO4GB) == 0)
1630 sc->flags |= AAC_FLAGS_4GB_WINDOW;
1632 sc->flags |= AAC_FLAGS_ENABLE_CAM;
1635 && (sc->hint_flags & 0x1)) {
1636 device_printf(sc->aac_dev,
1638 sc->flags |= AAC_FLAGS_SG_64BIT;
1640 if (sc->aac_if.aif_send_command) {
1642 sc->flags |= AAC_FLAGS_NEW_COMM | AAC_FLAGS_NEW_COMM_TYPE2;
1644 sc->flags |= AAC_FLAGS_NEW_COMM | AAC_FLAGS_NEW_COMM_TYPE1;
1647 sc->flags |= AAC_FLAGS_NEW_COMM | AAC_FLAGS_NEW_COMM_TYPE34;
1650 sc->flags |= AAC_FLAGS_ARRAY_64BIT;
1653 if (!(sc->flags & AAC_FLAGS_NEW_COMM)) {
1654 device_printf(sc->aac_dev, "Communication interface not supported!\n");
1658 if (sc->hint_flags & 2) {
1659 device_printf(sc->aac_dev,
1661 sc->flags |= AAC_FLAGS_SYNC_MODE;
1662 } else if (sc->flags & AAC_FLAGS_NEW_COMM_TYPE34) {
1663 device_printf(sc->aac_dev,
1665 sc->flags |= AAC_FLAGS_SYNC_MODE;
1669 sc->aac_max_fibs = (sc->flags & AAC_FLAGS_256FIBS ? 256:512);
1672 if (atu_size > rman_get_size(sc->aac_regs_res0)) {
1674 sc->aac_dev, SYS_RES_MEMORY,
1675 sc->aac_regs_rid0, sc->aac_regs_res0);
1676 sc->aac_regs_res0 = bus_alloc_resource_anywhere(
1677 sc->aac_dev, SYS_RES_MEMORY, &sc->aac_regs_rid0,
1679 if (sc->aac_regs_res0 == NULL) {
1680 sc->aac_regs_res0 = bus_alloc_resource_any(
1681 sc->aac_dev, SYS_RES_MEMORY,
1682 &sc->aac_regs_rid0, RF_ACTIVE);
1683 if (sc->aac_regs_res0 == NULL) {
1684 device_printf(sc->aac_dev,
1689 sc->aac_btag0 = rman_get_bustag(sc->aac_regs_res0);
1690 sc->aac_bhandle0 = rman_get_bushandle(sc->aac_regs_res0);
1694 sc->aac_max_fib_size = sizeof(struct aac_fib);
1695 sc->aac_max_sectors = 128; /* 64KB */
1696 sc->aac_max_aif = 1;
1697 if (sc->flags & AAC_FLAGS_SG_64BIT)
1698 sc->aac_sg_tablesize = (AAC_FIB_DATASIZE
1702 sc->aac_sg_tablesize = (AAC_FIB_DATASIZE
1706 if (!aacraid_sync_command(sc, AAC_MONKER_GETCOMMPREF, 0, 0, 0, 0, NULL, NULL)) {
1707 options = AAC_GET_MAILBOX(sc, 1);
1708 sc->aac_max_fib_size = (options & 0xFFFF);
1709 sc->aac_max_sectors = (options >> 16) << 1;
1710 options = AAC_GET_MAILBOX(sc, 2);
1711 sc->aac_sg_tablesize = (options >> 16);
1712 options = AAC_GET_MAILBOX(sc, 3);
1713 sc->aac_max_fibs = ((options >> 16) & 0xFFFF);
1714 if (sc->aac_max_fibs == 0 || sc->aac_hwif != AAC_HWIF_SRCV)
1715 sc->aac_max_fibs = (options & 0xFFFF);
1716 options = AAC_GET_MAILBOX(sc, 4);
1717 sc->aac_max_aif = (options & 0xFFFF);
1718 options = AAC_GET_MAILBOX(sc, 5);
1719 sc->aac_max_msix =(sc->flags & AAC_FLAGS_NEW_COMM_TYPE2) ? options : 0;
1722 maxsize = sc->aac_max_fib_size + 31;
1723 if (sc->flags & AAC_FLAGS_NEW_COMM_TYPE1)
1726 sc->aac_max_fib_size -= (maxsize - PAGE_SIZE);
1729 sc->aac_max_fibs_alloc = PAGE_SIZE / maxsize;
1731 if (sc->aac_max_fib_size > sizeof(struct aac_fib)) {
1732 sc->flags |= AAC_FLAGS_RAW_IO;
1733 device_printf(sc->aac_dev, "Enable Raw I/O\n");
1735 if ((sc->flags & AAC_FLAGS_RAW_IO) &&
1736 (sc->flags & AAC_FLAGS_ARRAY_64BIT)) {
1737 sc->flags |= AAC_FLAGS_LBA_64BIT;
1738 device_printf(sc->aac_dev, "Enable 64-bit array\n");
1742 aacraid_get_fw_debug_buffer(sc);
1748 aac_init(struct aac_softc *sc)
1753 fwprintf(sc, HBA_FLAGS_DBG_FUNCTION_ENTRY_B, "");
1756 sc->aac_fibs_pushed_no = 0;
1757 for (i = 0; i < sc->aac_max_msix; i++)
1758 sc->aac_host_rrq_idx[i] = i * sc->aac_vector_cap;
1764 ip = &sc->aac_common->ac_init;
1766 if (sc->aac_max_fib_size > sizeof(struct aac_fib)) {
1768 sc->flags |= AAC_FLAGS_RAW_IO;
1770 ip->NoOfMSIXVectors = sc->aac_max_msix;
1772 ip->AdapterFibsPhysicalAddress = sc->aac_common_busaddr +
1778 ip->PrintfBufferAddress = sc->aac_common_busaddr +
1789 if (sc->flags & AAC_FLAGS_BROKEN_MEMMAP) {
1796 if (sc->flags & AAC_FLAGS_NEW_COMM_TYPE1) {
1800 device_printf(sc->aac_dev, "New comm. interface type1 enabled\n");
1801 } else if (sc->flags & AAC_FLAGS_NEW_COMM_TYPE2) {
1805 device_printf(sc->aac_dev, "New comm. interface type2 enabled\n");
1807 ip->MaxNumAif = sc->aac_max_aif;
1809 sc->aac_common_busaddr + offsetof(struct aac_common, ac_host_rrq);
1813 if (sc->aac_support_opt2 & AAC_SUPPORTED_POWER_MANAGEMENT) {
1816 device_printf(sc->aac_dev, "Power Management enabled\n");
1819 ip->MaxIoCommands = sc->aac_max_fibs;
1820 ip->MaxIoSize = sc->aac_max_sectors << 9;
1821 ip->MaxFibSize = sc->aac_max_fib_size;
1826 AAC_MEM0_SETREG4(sc, AAC_SRC_ODBR_C, ~0);
1831 if (aacraid_sync_command(sc, AAC_MONKER_INITSTRUCT,
1832 sc->aac_common_busaddr +
1835 device_printf(sc->aac_dev,
1844 if ((error = aac_check_config(sc)) != 0)
1853 aac_define_int_mode(struct aac_softc *sc)
1859 dev = sc->aac_dev;
1861 if (sc->flags & AAC_FLAGS_SYNC_MODE) {
1863 sc->aac_max_msix = 1;
1864 sc->aac_vector_cap = sc->aac_max_fibs;
1869 if (sc->aac_max_msix == 0) {
1870 if (sc->aac_hwif == AAC_HWIF_SRC) {
1877 sc->msi_tupelo = TRUE;
1880 if (sc->msi_tupelo)
1885 sc->aac_max_msix = 1;
1886 sc->aac_vector_cap = sc->aac_max_fibs;
1894 if (msi_count > sc->aac_max_msix)
1895 msi_count = sc->aac_max_msix;
1901 sc->msi_enabled = TRUE;
1906 if (!sc->msi_enabled) {
1913 sc->msi_enabled = TRUE;
1918 if (sc->msi_enabled) {
1920 cap = aac_find_pci_capability(sc, PCIY_MSIX);
1924 sc->msi_enabled = FALSE;
1928 if (!sc->msi_enabled) {
1930 sc->aac_max_msix = 1;
1932 AAC_ACCESS_DEVREG(sc, AAC_ENABLE_MSIX);
1933 if (sc->aac_max_msix > msi_count)
1934 sc->aac_max_msix = msi_count;
1936 sc->aac_vector_cap = sc->aac_max_fibs / sc->aac_max_msix;
1938 fwprintf(sc, HBA_FLAGS_DBG_DEBUG_B, "msi_enabled %d vector_cap %d max_fibs %d max_msix %d",
1939 sc->msi_enabled,sc->aac_vector_cap, sc->aac_max_fibs, sc->aac_max_msix);
1943 aac_find_pci_capability(struct aac_softc *sc, int cap)
1949 dev = sc->aac_dev;
1983 aac_setup_intr(struct aac_softc *sc)
1989 msi_count = sc->aac_max_msix;
1990 rid = ((sc->msi_enabled || sc->msi_tupelo)? 1:0);
1993 if ((res = bus_alloc_resource_any(sc->aac_dev,SYS_RES_IRQ, &rid,
1995 device_printf(sc->aac_dev,"can't allocate interrupt\n");
1998 sc->aac_irq_rid[i] = rid;
1999 sc->aac_irq[i] = res;
2000 if (aac_bus_setup_intr(sc->aac_dev, res,
2002 aacraid_new_intr_type1, &sc->aac_msix[i], &tag)) {
2003 device_printf(sc->aac_dev, "can't set up interrupt\n");
2006 sc->aac_msix[i].vector_no = i;
2007 sc->aac_msix[i].sc = sc;
2008 sc->aac_intr[i] = tag;
2015 aac_check_config(struct aac_softc *sc)
2022 mtx_lock(&sc->aac_io_lock);
2023 aac_alloc_sync_fib(sc, &fib);
2031 rval = aac_sync_fib(sc, ContainerCommand, 0, fib,
2041 rval = aac_sync_fib(sc, ContainerCommand, 0, fib,
2061 aac_release_sync_fib(sc);
2062 mtx_unlock(&sc->aac_io_lock);
2071 aacraid_sync_command(struct aac_softc *sc, u_int32_t command,
2078 fwprintf(sc, HBA_FLAGS_DBG_FUNCTION_ENTRY_B, "");
2081 AAC_SET_MAILBOX(sc, command, arg0, arg1, arg2, arg3);
2084 if (!sc->msi_enabled)
2085 AAC_CLEAR_ISTATUS(sc, AAC_DB_SYNC_COMMAND);
2088 AAC_QNOTIFY(sc, AAC_DB_SYNC_COMMAND);
2095 fwprintf(sc, HBA_FLAGS_DBG_ERROR_B, "timed out");
2098 } while (!(AAC_GET_ISTATUS(sc) & AAC_DB_SYNC_COMMAND));
2101 AAC_CLEAR_ISTATUS(sc, AAC_DB_SYNC_COMMAND);
2104 status = AAC_GET_MAILBOX(sc, 0);
2110 *r1 = AAC_GET_MAILBOX(sc, 1);
2119 aac_sync_fib(struct aac_softc *sc, u_int32_t command, u_int32_t xferstate,
2122 fwprintf(sc, HBA_FLAGS_DBG_FUNCTION_ENTRY_B, "");
2123 mtx_assert(&sc->aac_io_lock, MA_OWNED);
2140 fib->Header.u.ReceiverFibAddress = sc->aac_common_busaddr +
2146 if (aacraid_sync_command(sc, AAC_MONKER_SYNCFIB,
2148 fwprintf(sc, HBA_FLAGS_DBG_ERROR_B, "IO error");
2160 aac_timeout(struct aac_softc *sc)
2166 fwprintf(sc, HBA_FLAGS_DBG_FUNCTION_ENTRY_B, "");
2173 TAILQ_FOREACH(cm, &sc->aac_busy, cm_link) {
2175 device_printf(sc->aac_dev,
2178 AAC_PRINT_FIB(sc, cm->cm_fib);
2184 aac_reset_adapter(sc);
2185 aacraid_print_queues(sc);
2196 aac_src_get_fwstatus(struct aac_softc *sc)
2198 fwprintf(sc, HBA_FLAGS_DBG_FUNCTION_ENTRY_B, "");
2200 return(AAC_MEM0_GETREG4(sc, AAC_SRC_OMR));
2207 aac_src_qnotify(struct aac_softc *sc, int qbit)
2209 fwprintf(sc, HBA_FLAGS_DBG_FUNCTION_ENTRY_B, "");
2211 AAC_MEM0_SETREG4(sc, AAC_SRC_IDBR, qbit << AAC_SRC_IDR_SHIFT);
2218 aac_src_get_istatus(struct aac_softc *sc)
2222 fwprintf(sc, HBA_FLAGS_DBG_FUNCTION_ENTRY_B, "");
2224 if (sc->msi_enabled) {
2225 val = AAC_MEM0_GETREG4(sc, AAC_SRC_ODBR_MSI);
2231 val = AAC_MEM0_GETREG4(sc, AAC_SRC_ODBR_R) >> AAC_SRC_ODR_SHIFT;
2240 aac_src_clear_istatus(struct aac_softc *sc, int mask)
2242 fwprintf(sc, HBA_FLAGS_DBG_FUNCTION_ENTRY_B, "");
2244 if (sc->msi_enabled) {
2246 AAC_ACCESS_DEVREG(sc, AAC_CLEAR_SYNC_BIT);
2248 AAC_MEM0_SETREG4(sc, AAC_SRC_ODBR_C, mask << AAC_SRC_ODR_SHIFT);
2256 aac_src_set_mailbox(struct aac_softc *sc, u_int32_t command, u_int32_t arg0,
2259 fwprintf(sc, HBA_FLAGS_DBG_FUNCTION_ENTRY_B, "");
2261 AAC_MEM0_SETREG4(sc, AAC_SRC_MAILBOX, command);
2262 AAC_MEM0_SETREG4(sc, AAC_SRC_MAILBOX + 4, arg0);
2263 AAC_MEM0_SETREG4(sc, AAC_SRC_MAILBOX + 8, arg1);
2264 AAC_MEM0_SETREG4(sc, AAC_SRC_MAILBOX + 12, arg2);
2265 AAC_MEM0_SETREG4(sc, AAC_SRC_MAILBOX + 16, arg3);
2269 aac_srcv_set_mailbox(struct aac_softc *sc, u_int32_t command, u_int32_t arg0,
2272 fwprintf(sc, HBA_FLAGS_DBG_FUNCTION_ENTRY_B, "");
2274 AAC_MEM0_SETREG4(sc, AAC_SRCV_MAILBOX, command);
2275 AAC_MEM0_SETREG4(sc, AAC_SRCV_MAILBOX + 4, arg0);
2276 AAC_MEM0_SETREG4(sc, AAC_SRCV_MAILBOX + 8, arg1);
2277 AAC_MEM0_SETREG4(sc, AAC_SRCV_MAILBOX + 12, arg2);
2278 AAC_MEM0_SETREG4(sc, AAC_SRCV_MAILBOX + 16, arg3);
2285 aac_src_get_mailbox(struct aac_softc *sc, int mb)
2287 fwprintf(sc, HBA_FLAGS_DBG_FUNCTION_ENTRY_B, "");
2289 return(AAC_MEM0_GETREG4(sc, AAC_SRC_MAILBOX + (mb * 4)));
2293 aac_srcv_get_mailbox(struct aac_softc *sc, int mb)
2295 fwprintf(sc, HBA_FLAGS_DBG_FUNCTION_ENTRY_B, "");
2297 return(AAC_MEM0_GETREG4(sc, AAC_SRCV_MAILBOX + (mb * 4)));
2304 aac_src_access_devreg(struct aac_softc *sc, int mode)
2308 fwprintf(sc, HBA_FLAGS_DBG_FUNCTION_ENTRY_B, "");
2312 AAC_MEM0_SETREG4(sc, AAC_SRC_OIMR,
2313 (sc->msi_enabled ? AAC_INT_ENABLE_TYPE1_MSIX :
2318 AAC_MEM0_SETREG4(sc, AAC_SRC_OIMR, AAC_INT_DISABLE_ALL);
2323 val = AAC_MEM0_GETREG4(sc, AAC_SRC_IDBR);
2325 AAC_MEM0_SETREG4(sc, AAC_SRC_IDBR, val);
2326 AAC_MEM0_GETREG4(sc, AAC_SRC_IDBR);
2329 AAC_MEM0_SETREG4(sc, AAC_SRC_IOAR, val);
2330 val = AAC_MEM0_GETREG4(sc, AAC_SRC_OIMR);
2331 AAC_MEM0_SETREG4(sc, AAC_SRC_OIMR,
2337 val = AAC_MEM0_GETREG4(sc, AAC_SRC_IDBR);
2339 AAC_MEM0_SETREG4(sc, AAC_SRC_IDBR, val);
2340 AAC_MEM0_GETREG4(sc, AAC_SRC_IDBR);
2345 val = AAC_MEM0_GETREG4(sc, AAC_SRC_IDBR);
2347 AAC_MEM0_SETREG4(sc, AAC_SRC_IDBR, val);
2348 AAC_MEM0_GETREG4(sc, AAC_SRC_IDBR);
2353 val = AAC_MEM0_GETREG4(sc, AAC_SRC_IDBR);
2355 AAC_MEM0_SETREG4(sc, AAC_SRC_IDBR, val);
2356 AAC_MEM0_GETREG4(sc, AAC_SRC_IDBR);
2361 val = AAC_MEM0_GETREG4(sc, AAC_SRC_IDBR);
2363 AAC_MEM0_SETREG4(sc, AAC_SRC_IDBR, val);
2364 AAC_MEM0_GETREG4(sc, AAC_SRC_IDBR);
2367 AAC_MEM0_SETREG4(sc, AAC_SRC_IOAR, val);
2368 val = AAC_MEM0_GETREG4(sc, AAC_SRC_OIMR);
2369 AAC_MEM0_SETREG4(sc, AAC_SRC_OIMR,
2382 aac_src_send_command(struct aac_softc *sc, struct aac_command *cm)
2388 fwprintf(sc, HBA_FLAGS_DBG_FUNCTION_ENTRY_B, "send command (new comm. type1)");
2390 if (sc->msi_enabled && cm->cm_fib->Header.Command != AifRequest &&
2391 sc->aac_max_msix > 1) {
2394 vector_no = sc->aac_fibs_pushed_no % sc->aac_max_msix;
2397 if (vector_no == sc->aac_max_msix)
2399 if (sc->aac_rrq_outstanding[vector_no] <
2400 sc->aac_vector_cap)
2409 sc->aac_rrq_outstanding[vector_no]++;
2410 if (sc->aac_fibs_pushed_no == 0xffffffff)
2411 sc->aac_fibs_pushed_no = 0;
2413 sc->aac_fibs_pushed_no++;
2418 if (sc->flags & AAC_FLAGS_NEW_COMM_TYPE2) {
2450 AAC_MEM0_SETREG4(sc, AAC_SRC_IQUE64_H, high_addr);
2451 AAC_MEM0_SETREG4(sc, AAC_SRC_IQUE64_L, (u_int32_t)address + fibsize);
2453 AAC_MEM0_SETREG4(sc, AAC_SRC_IQUE32, (u_int32_t)address + fibsize);
2462 aac_src_get_outb_queue(struct aac_softc *sc)
2464 fwprintf(sc, HBA_FLAGS_DBG_FUNCTION_ENTRY_B, "");
2470 aac_src_set_outb_queue(struct aac_softc *sc, int index)
2472 fwprintf(sc, HBA_FLAGS_DBG_FUNCTION_ENTRY_B, "");
2483 aac_describe_controller(struct aac_softc *sc)
2489 fwprintf(sc, HBA_FLAGS_DBG_FUNCTION_ENTRY_B, "");
2491 mtx_lock(&sc->aac_io_lock);
2492 aac_alloc_sync_fib(sc, &fib);
2494 if (sc->supported_options & AAC_SUPPORTED_SUPPLEMENT_ADAPTER_INFO) {
2496 if (aac_sync_fib(sc, RequestSupplementAdapterInfo, 0, fib, 1))
2497 device_printf(sc->aac_dev, "RequestSupplementAdapterInfo failed\n");
2503 sc->aac_feature_bits = supp_info->FeatureBits;
2504 sc->aac_support_opt2 = supp_info->SupportedOptions2;
2507 device_printf(sc->aac_dev, "%s, aacraid driver %d.%d.%d-%d\n",
2513 if (aac_sync_fib(sc, RequestAdapterInfo, 0, fib, 1)) {
2514 device_printf(sc->aac_dev, "RequestAdapterInfo failed\n");
2515 aac_release_sync_fib(sc);
2516 mtx_unlock(&sc->aac_io_lock);
2522 sc->aac_revision = info->KernelRevision;
2525 device_printf(sc->aac_dev, "%s %dMHz, %dMB memory "
2534 device_printf(sc->aac_dev,
2542 device_printf(sc->aac_dev, "Supported Options=%b\n",
2543 sc->supported_options,
2566 aac_release_sync_fib(sc);
2567 mtx_unlock(&sc->aac_io_lock);
2592 struct aac_softc *sc;
2594 sc = dev->si_drv1;
2595 fwprintf(sc, HBA_FLAGS_DBG_FUNCTION_ENTRY_B, "");
2597 device_busy(sc->aac_dev);
2598 devfs_set_cdevpriv(sc, aac_cdevpriv_dtor);
2607 struct aac_softc *sc;
2611 sc = dev->si_drv1;
2612 fwprintf(sc, HBA_FLAGS_DBG_FUNCTION_ENTRY_B, "");
2620 bcopy(&sc->aac_qstat[as->as_item], &as->as_qstat,
2634 fwprintf(sc, HBA_FLAGS_DBG_IOCTL_COMMANDS_B, "FSACTL_SENDFIB");
2635 error = aac_ioctl_sendfib(sc, arg);
2640 fwprintf(sc, HBA_FLAGS_DBG_IOCTL_COMMANDS_B, "FSACTL_SEND_RAW_SRB");
2641 error = aac_ioctl_send_raw_srb(sc, arg);
2645 fwprintf(sc, HBA_FLAGS_DBG_IOCTL_COMMANDS_B, "FSACTL_AIF_THREAD");
2651 fwprintf(sc, HBA_FLAGS_DBG_IOCTL_COMMANDS_B, "FSACTL_OPEN_GET_ADAPTER_FIB");
2652 error = aac_open_aif(sc, arg);
2657 fwprintf(sc, HBA_FLAGS_DBG_IOCTL_COMMANDS_B, "FSACTL_GET_NEXT_ADAPTER_FIB");
2658 error = aac_getnext_aif(sc, arg);
2663 fwprintf(sc, HBA_FLAGS_DBG_IOCTL_COMMANDS_B, "FSACTL_CLOSE_GET_ADAPTER_FIB");
2664 error = aac_close_aif(sc, arg);
2669 fwprintf(sc, HBA_FLAGS_DBG_IOCTL_COMMANDS_B, "FSACTL_MINIPORT_REV_CHECK");
2670 error = aac_rev_check(sc, arg);
2675 fwprintf(sc, HBA_FLAGS_DBG_IOCTL_COMMANDS_B, "FSACTL_QUERY_DISK");
2676 error = aac_query_disk(sc, arg);
2690 fwprintf(sc, HBA_FLAGS_DBG_IOCTL_COMMANDS_B, "FSACTL_GET_PCI_INFO");
2691 error = aac_get_pci_info(sc, arg);
2696 fwprintf(sc, HBA_FLAGS_DBG_IOCTL_COMMANDS_B, "FSACTL_GET_FEATURES");
2697 error = aac_supported_features(sc, arg);
2700 fwprintf(sc, HBA_FLAGS_DBG_IOCTL_COMMANDS_B, "unsupported cmd 0x%lx\n", cmd);
2710 struct aac_softc *sc;
2714 sc = dev->si_drv1;
2717 mtx_lock(&sc->aac_io_lock);
2719 for (ctx = sc->fibctx; ctx; ctx = ctx->next) {
2720 if (ctx->ctx_idx != sc->aifq_idx || ctx->ctx_wrap) {
2726 mtx_unlock(&sc->aac_io_lock);
2730 selrecord(td, &sc->rcv_select);
2737 aac_ioctl_event(struct aac_softc *sc, struct aac_event *event, void *arg)
2742 mtx_assert(&sc->aac_io_lock, MA_OWNED);
2743 if (aacraid_alloc_command(sc, (struct aac_command **)arg)) {
2744 aacraid_add_event(sc, event);
2759 aac_ioctl_sendfib(struct aac_softc *sc, caddr_t ufib)
2764 fwprintf(sc, HBA_FLAGS_DBG_FUNCTION_ENTRY_B, "");
2771 mtx_lock(&sc->aac_io_lock);
2772 if (aacraid_alloc_command(sc, &cm)) {
2779 mtx_unlock(&sc->aac_io_lock);
2785 aacraid_add_event(sc, event);
2786 msleep(cm, &sc->aac_io_lock, 0, "aacraid_ctlsfib", 0);
2788 mtx_unlock(&sc->aac_io_lock);
2797 if (size > sc->aac_max_fib_size) {
2798 device_printf(sc->aac_dev, "incoming FIB oversized (%d > %d)\n",
2799 size, sc->aac_max_fib_size);
2800 size = sc->aac_max_fib_size;
2811 mtx_lock(&sc->aac_io_lock);
2813 mtx_unlock(&sc->aac_io_lock);
2815 device_printf(sc->aac_dev,
2824 if (size > sc->aac_max_fib_size) {
2825 device_printf(sc->aac_dev, "outbound FIB oversized (%d > %d)\n",
2826 size, sc->aac_max_fib_size);
2827 size = sc->aac_max_fib_size;
2833 mtx_lock(&sc->aac_io_lock);
2835 mtx_unlock(&sc->aac_io_lock);
2844 aac_ioctl_send_raw_srb(struct aac_softc *sc, caddr_t arg)
2857 fwprintf(sc, HBA_FLAGS_DBG_FUNCTION_ENTRY_B, "");
2861 mtx_lock(&sc->aac_io_lock);
2862 if (aacraid_alloc_command(sc, &cm)) {
2869 mtx_unlock(&sc->aac_io_lock);
2875 aacraid_add_event(sc, event);
2876 msleep(cm, &sc->aac_io_lock, 0, "aacraid_ctlsraw", 0);
2878 mtx_unlock(&sc->aac_io_lock);
2889 if (fibsize > (sc->aac_max_fib_size-sizeof(struct aac_fib_header))) {
2944 if (bus_dma_tag_create(sc->aac_parent_dmat, /* parent */
2946 (sc->flags & AAC_FLAGS_SG_64BIT) ?
2952 sc->aac_sg_tablesize, /* nsegments */
2994 fib->Header.Command = (sc->flags & AAC_FLAGS_SG_64BIT) ?
3009 mtx_lock(&sc->aac_io_lock);
3011 msleep(cm, &sc->aac_io_lock, 0, "aacraid_ctlsrw2", 0);
3012 mtx_unlock(&sc->aac_io_lock);
3038 mtx_lock(&sc->aac_io_lock);
3040 mtx_unlock(&sc->aac_io_lock);
3049 aac_request_aif(struct aac_softc *sc)
3054 fwprintf(sc, HBA_FLAGS_DBG_FUNCTION_ENTRY_B, "");
3056 if (aacraid_alloc_command(sc, &cm)) {
3057 sc->aif_pending = 1;
3060 sc->aif_pending = 0;
3089 struct aac_softc *sc;
3091 sc = arg;
3092 fwprintf(sc, HBA_FLAGS_DBG_FUNCTION_ENTRY_B, "");
3094 device_unbusy(sc->aac_dev);
3101 struct aac_softc *sc;
3103 sc = dev->si_drv1;
3104 fwprintf(sc, HBA_FLAGS_DBG_FUNCTION_ENTRY_B, "");
3114 aac_handle_aif(struct aac_softc *sc, struct aac_fib *fib)
3125 fwprintf(sc, HBA_FLAGS_DBG_FUNCTION_ENTRY_B, "");
3128 aacraid_print_aif(sc, aif);
3141 aac_alloc_sync_fib(sc, &sync_fib);
3150 if (aac_get_container_info(sc, sync_fib, i,
3164 &sc->aac_container_tqh,
3186 aac_add_container(sc, &mir, 1, uid);
3191 aac_release_sync_fib(sc);
3200 co = TAILQ_FIRST(&sc->aac_container_tqh);
3204 TAILQ_REMOVE(&sc->aac_container_tqh, co,
3217 if (sc->cam_rescan_cb != NULL)
3218 sc->cam_rescan_cb(sc, 0,
3229 if (sc->cam_rescan_cb != NULL)
3230 sc->cam_rescan_cb(sc,
3241 if (sc->cam_rescan_cb != NULL)
3242 sc->cam_rescan_cb(sc, ((channel>>24) & 0xF) + 1,
3255 current = sc->aifq_idx;
3258 sc->aifq_filled = 1;
3259 bcopy(fib, &sc->aac_aifq[current], sizeof(struct aac_fib));
3261 if (sc->aifq_filled) {
3262 for (ctx = sc->fibctx; ctx; ctx = ctx->next) {
3269 sc->aifq_idx = next;
3271 if (sc->aac_state & AAC_STATE_AIF_SLEEPER)
3272 wakeup(sc->aac_aifq);
3274 selwakeuppri(&sc->rcv_select, PRIBIO);
3286 aac_rev_check(struct aac_softc *sc, caddr_t udata)
3292 fwprintf(sc, HBA_FLAGS_DBG_FUNCTION_ENTRY_B, "");
3302 fwprintf(sc, HBA_FLAGS_DBG_IOCTL_COMMANDS_B, "Userland revision= %d\n",
3328 aac_open_aif(struct aac_softc *sc, caddr_t arg)
3333 fwprintf(sc, HBA_FLAGS_DBG_FUNCTION_ENTRY_B, "");
3339 mtx_lock(&sc->aac_io_lock);
3341 if (sc->fibctx == NULL)
3342 sc->fibctx = fibctx;
3344 for (ctx = sc->fibctx; ctx->next; ctx = ctx->next)
3352 ctx = sc->fibctx;
3356 ctx = sc->fibctx;
3363 mtx_unlock(&sc->aac_io_lock);
3365 aac_close_aif(sc, (caddr_t)ctx);
3373 aac_close_aif(struct aac_softc *sc, caddr_t arg)
3377 fwprintf(sc, HBA_FLAGS_DBG_FUNCTION_ENTRY_B, "");
3379 mtx_lock(&sc->aac_io_lock);
3380 for (ctx = sc->fibctx; ctx; ctx = ctx->next) {
3382 if (ctx == sc->fibctx)
3383 sc->fibctx = NULL;
3395 mtx_unlock(&sc->aac_io_lock);
3403 aac_getnext_aif(struct aac_softc *sc, caddr_t arg)
3409 fwprintf(sc, HBA_FLAGS_DBG_FUNCTION_ENTRY_B, "");
3411 mtx_lock(&sc->aac_io_lock);
3425 for (ctx = sc->fibctx; ctx; ctx = ctx->next) {
3430 mtx_unlock(&sc->aac_io_lock);
3434 error = aac_return_aif(sc, ctx, agf.AifFib);
3436 fwprintf(sc, HBA_FLAGS_DBG_AIF_B, "aac_getnext_aif(): waiting for AIF");
3437 sc->aac_state |= AAC_STATE_AIF_SLEEPER;
3439 mtx_unlock(&sc->aac_io_lock);
3440 error = tsleep(sc->aac_aifq, PRIBIO |
3442 mtx_lock(&sc->aac_io_lock);
3444 error = aac_return_aif(sc, ctx, agf.AifFib);
3446 sc->aac_state &= ~AAC_STATE_AIF_SLEEPER;
3449 mtx_unlock(&sc->aac_io_lock);
3457 aac_return_aif(struct aac_softc *sc, struct aac_fib_context *ctx, caddr_t uptr)
3461 fwprintf(sc, HBA_FLAGS_DBG_FUNCTION_ENTRY_B, "");
3464 if (current == sc->aifq_idx && !ctx->ctx_wrap) {
3469 copyout(&sc->aac_aifq[current], (void *)uptr, sizeof(struct aac_fib));
3471 device_printf(sc->aac_dev,
3481 aac_get_pci_info(struct aac_softc *sc, caddr_t uptr)
3489 fwprintf(sc, HBA_FLAGS_DBG_FUNCTION_ENTRY_B, "");
3491 pciinf.bus = pci_get_bus(sc->aac_dev);
3492 pciinf.slot = pci_get_slot(sc->aac_dev);
3501 aac_supported_features(struct aac_softc *sc, caddr_t uptr)
3506 fwprintf(sc, HBA_FLAGS_DBG_FUNCTION_ENTRY_B, "");
3524 (sc->flags & AAC_FLAGS_LBA_64BIT) ? 1 : 0;
3530 (sc->flags & AAC_FLAGS_LBA_64BIT) ? 1 : 0;
3544 aac_query_disk(struct aac_softc *sc, caddr_t uptr)
3550 fwprintf(sc, HBA_FLAGS_DBG_FUNCTION_ENTRY_B, "");
3552 mtx_lock(&sc->aac_io_lock);
3556 mtx_unlock(&sc->aac_io_lock);
3562 mtx_unlock(&sc->aac_io_lock);
3566 TAILQ_FOREACH(co, &sc->aac_container_tqh, co_link) {
3579 query_disk.Bus = device_get_unit(sc->aac_dev);
3588 mtx_unlock(&sc->aac_io_lock);
3593 aac_container_bus(struct aac_softc *sc)
3601 device_printf(sc->aac_dev,
3605 child = device_add_child(sc->aac_dev, "aacraidp", -1);
3607 device_printf(sc->aac_dev,
3617 sim->aac_sc = sc;
3623 TAILQ_INSERT_TAIL(&sc->aac_sim_tqh, sim, sim_link);
3628 bus_generic_attach(sc->aac_dev);
3632 aac_get_bus_info(struct aac_softc *sc)
3644 mtx_lock(&sc->aac_io_lock);
3645 aac_alloc_sync_fib(sc, &fib);
3653 error = aac_sync_fib(sc, ContainerCommand, 0, fib,
3656 device_printf(sc->aac_dev, "Error %d sending "
3658 aac_release_sync_fib(sc);
3659 mtx_unlock(&sc->aac_io_lock);
3665 device_printf(sc->aac_dev, "VM_ContainerConfig returned 0x%x\n",
3667 aac_release_sync_fib(sc);
3668 mtx_unlock(&sc->aac_io_lock);
3672 sc->scsi_method_id = c_resp->param;
3679 vmi->MethId = sc->scsi_method_id;
3683 error = aac_sync_fib(sc, ContainerCommand, 0, fib,
3686 device_printf(sc->aac_dev, "Error %d sending VMIoctl command\n",
3688 aac_release_sync_fib(sc);
3689 mtx_unlock(&sc->aac_io_lock);
3695 device_printf(sc->aac_dev, "VM_Ioctl returned %d\n",
3697 aac_release_sync_fib(sc);
3698 mtx_unlock(&sc->aac_io_lock);
3703 aac_release_sync_fib(sc);
3704 mtx_unlock(&sc->aac_io_lock);
3713 device_printf(sc->aac_dev,
3718 child = device_add_child(sc->aac_dev, "aacraidp", -1);
3720 device_printf(sc->aac_dev,
3731 caminf->aac_sc = sc;
3737 TAILQ_INSERT_TAIL(&sc->aac_sim_tqh, caminf, sim_link);
3746 aac_check_adapter_health(struct aac_softc *sc, u_int8_t *bled)
3750 ret = AAC_GET_FWSTATUS(sc);
3768 aac_reset_adapter(struct aac_softc *sc)
3776 fwprintf(sc, HBA_FLAGS_DBG_FUNCTION_ENTRY_B, "");
3777 mtx_assert(&sc->aac_io_lock, MA_OWNED);
3779 if (sc->aac_state & AAC_STATE_RESET) {
3780 device_printf(sc->aac_dev, "aac_reset_adapter() already in progress\n");
3783 sc->aac_state |= AAC_STATE_RESET;
3786 AAC_ACCESS_DEVREG(sc, AAC_DISABLE_INTERRUPT);
3792 while ((cm = aac_dequeue_busy(sc)) != NULL) {
3807 while ((cm = aac_dequeue_ready(sc)) != NULL) {
3822 if (aac_check_adapter_health(sc, NULL) == 0) {
3823 mtx_unlock(&sc->aac_io_lock);
3824 (void) aacraid_shutdown(sc->aac_dev);
3825 mtx_lock(&sc->aac_io_lock);
3829 if (sc->aac_support_opt2 & AAC_SUPPORTED_MU_RESET) {
3830 AAC_MEM0_SETREG4(sc, AAC_IRCSR, AAC_IRCSR_CORES_RST);
3841 ret = aacraid_sync_command(sc, AAC_IOP_RESET_ALWAYS,
3843 if (ret && !sc->doorbell_mask) {
3845 if ((aacraid_sync_command(sc, AAC_IOP_RESET, 0,0,0,0,
3848 device_printf(sc->aac_dev,
3852 device_printf(sc->aac_dev,
3857 aac_alloc_sync_fib(sc, &fib);
3865 (void) aac_sync_fib(sc, ContainerCommand, 0,
3867 aac_release_sync_fib(sc);
3871 } else if (sc->doorbell_mask) {
3873 reset_mask = sc->doorbell_mask;
3876 (sc->aac_support_opt2 & AAC_SUPPORTED_DOORBELL_RESET)) {
3877 AAC_MEM0_SETREG4(sc, AAC_SRC_IDBR, reset_mask);
3894 max_msix_orig = sc->aac_max_msix;
3895 msi_enabled_orig = sc->msi_enabled;
3896 sc->msi_enabled = FALSE;
3897 if (aac_check_firmware(sc) != 0)
3899 if (!(sc->flags & AAC_FLAGS_SYNC_MODE)) {
3900 sc->aac_max_msix = max_msix_orig;
3902 sc->msi_enabled = msi_enabled_orig;
3903 AAC_ACCESS_DEVREG(sc, AAC_ENABLE_MSIX);
3905 mtx_unlock(&sc->aac_io_lock);
3906 aac_init(sc);
3907 mtx_lock(&sc->aac_io_lock);
3911 sc->aac_state &= ~AAC_STATE_RESET;
3912 AAC_ACCESS_DEVREG(sc, AAC_ENABLE_INTERRUPT);
3913 aacraid_startio(sc);