1481
1482 /* give it to the FC transport */
1483 if (fc_fca_attach(dip, tran) != DDI_SUCCESS) {
1484 cmn_err(CE_WARN, "%s(%d): FCA attach failed", QL_NAME,
1485 instance);
1486 goto attach_failed;
1487 }
1488 progress |= QL_FCA_ATTACH_DONE;
1489
1490 /* Stash the structure so it can be freed at detach */
1491 ha->tran = tran;
1492
1493 /* Acquire global state lock. */
1494 GLOBAL_STATE_LOCK();
1495
1496 /* Add adapter structure to link list. */
1497 ql_add_link_b(&ql_hba, &ha->hba);
1498
1499 /* Start one second driver timer. */
1500 if (ql_timer_timeout_id == NULL) {
1501 ql_timer_ticks = drv_usectohz(1000000);
1502 ql_timer_timeout_id = timeout(ql_timer, (void *)0,
1503 ql_timer_ticks);
1504 }
1505
1506 /* Release global state lock. */
1507 GLOBAL_STATE_UNLOCK();
1508
1509 /* Determine and populate HBA fru info */
1510 ql_setup_fruinfo(ha);
1511
1512 /* Setup task_daemon thread. */
1513 (void) thread_create(NULL, 0, (void (*)())ql_task_daemon, ha,
1514 0, &p0, TS_RUN, minclsyspri);
1515
1516 progress |= QL_TASK_DAEMON_STARTED;
1517
1518 ddi_report_dev(dip);
1519
1520 /* Disable link reset in panic path */
1521 ha->lip_on_panic = 1;
1956
1957 if (ha->devpath != NULL) {
1958 kmem_free(ha->devpath, strlen(ha->devpath) + 1);
1959 }
1960
1961 kmem_free(ha->dev, sizeof (*ha->dev) * DEVICE_HEAD_LIST_SIZE);
1962
1963 EL(ha, "detached\n");
1964
1965 ddi_soft_state_free(ql_state, (int)ha->instance);
1966
1967 break;
1968
1969 case DDI_SUSPEND:
1970 ADAPTER_STATE_LOCK(ha);
1971
1972 delay_cnt = 0;
1973 ha->flags |= ADAPTER_SUSPENDED;
1974 while (ha->flags & ADAPTER_TIMER_BUSY && delay_cnt++ < 10) {
1975 ADAPTER_STATE_UNLOCK(ha);
1976 delay(drv_usectohz(1000000));
1977 ADAPTER_STATE_LOCK(ha);
1978 }
1979 if (ha->busy || ha->flags & ADAPTER_TIMER_BUSY) {
1980 ha->flags &= ~ADAPTER_SUSPENDED;
1981 ADAPTER_STATE_UNLOCK(ha);
1982 rval = DDI_FAILURE;
1983 cmn_err(CE_WARN, "!%s(%d): Fail suspend"
1984 " busy %xh flags %xh", QL_NAME, ha->instance,
1985 ha->busy, ha->flags);
1986 break;
1987 }
1988
1989 ADAPTER_STATE_UNLOCK(ha);
1990
1991 if (ha->flags & IP_INITIALIZED) {
1992 (void) ql_shutdown_ip(ha);
1993 }
1994
1995 if ((suspend = ql_suspend_adapter(ha)) != QL_SUCCESS) {
1996 ADAPTER_STATE_LOCK(ha);
11852
11853 ha->ql_dump_state &= ~(QL_DUMP_VALID | QL_DUMP_UPLOADED);
11854 ha->ql_dump_state |= QL_DUMPING;
11855
11856 QL_DUMP_UNLOCK(ha);
11857
11858 if (CFG_IST(ha, CFG_ENABLE_FWEXTTRACE)) {
11859
11860 /* Insert Time Stamp */
11861 rval = ql_fw_etrace(ha, &ha->fwexttracebuf,
11862 FTO_INSERT_TIME_STAMP);
11863 if (rval != QL_SUCCESS) {
11864 EL(ha, "f/w extended trace insert"
11865 "time stamp failed: %xh\n", rval);
11866 }
11867 }
11868
11869 if (lock_needed == TRUE) {
11870 /* Acquire mailbox register lock. */
11871 MBX_REGISTER_LOCK(ha);
11872 timer = (ha->mcp->timeout + 2) * drv_usectohz(1000000);
11873
11874 /* Check for mailbox available, if not wait for signal. */
11875 while (ha->mailbox_flags & MBX_BUSY_FLG) {
11876 ha->mailbox_flags = (uint8_t)
11877 (ha->mailbox_flags | MBX_WANT_FLG);
11878
11879 /* 30 seconds from now */
11880 if (cv_reltimedwait(&ha->cv_mbx_wait, &ha->mbx_mutex,
11881 timer, TR_CLOCK_TICK) == -1) {
11882 /*
11883 * The timeout time 'timer' was
11884 * reached without the condition
11885 * being signaled.
11886 */
11887
11888 /* Release mailbox register lock. */
11889 MBX_REGISTER_UNLOCK(ha);
11890
11891 EL(ha, "failed, rval = %xh\n",
11892 QL_FUNCTION_TIMEOUT);
15887 /* ARGSUSED */
15888 static void
15889 ql_unbind_dma_buffer(ql_adapter_state_t *ha, dma_mem_t *mem)
15890 {
15891 QL_PRINT_3(CE_CONT, "(%d): started\n", ha->instance);
15892
15893 (void) ddi_dma_unbind_handle(mem->dma_handle);
15894 if (mem->cookie_count > 1) {
15895 kmem_free(mem->cookies, sizeof (ddi_dma_cookie_t) *
15896 mem->cookie_count);
15897 mem->cookies = NULL;
15898 }
15899 mem->cookie_count = 0;
15900
15901 QL_PRINT_3(CE_CONT, "(%d): done\n", ha->instance);
15902 }
15903
15904 static int
15905 ql_suspend_adapter(ql_adapter_state_t *ha)
15906 {
15907 clock_t timer = 32 * drv_usectohz(1000000);
15908
15909 QL_PRINT_3(CE_CONT, "(%d): started\n", ha->instance);
15910
15911 /*
15912 * First we will claim mbox ownership so that no
15913 * thread using mbox hangs when we disable the
15914 * interrupt in the middle of it.
15915 */
15916 MBX_REGISTER_LOCK(ha);
15917
15918 /* Check for mailbox available, if not wait for signal. */
15919 while (ha->mailbox_flags & MBX_BUSY_FLG) {
15920 ha->mailbox_flags = (uint8_t)
15921 (ha->mailbox_flags | MBX_WANT_FLG);
15922
15923 /* 30 seconds from now */
15924 if (cv_reltimedwait(&ha->cv_mbx_wait, &ha->mbx_mutex,
15925 timer, TR_CLOCK_TICK) == -1) {
15926
15927 /* Release mailbox register lock. */
|
1481
1482 /* give it to the FC transport */
1483 if (fc_fca_attach(dip, tran) != DDI_SUCCESS) {
1484 cmn_err(CE_WARN, "%s(%d): FCA attach failed", QL_NAME,
1485 instance);
1486 goto attach_failed;
1487 }
1488 progress |= QL_FCA_ATTACH_DONE;
1489
1490 /* Stash the structure so it can be freed at detach */
1491 ha->tran = tran;
1492
1493 /* Acquire global state lock. */
1494 GLOBAL_STATE_LOCK();
1495
1496 /* Add adapter structure to link list. */
1497 ql_add_link_b(&ql_hba, &ha->hba);
1498
1499 /* Start one second driver timer. */
1500 if (ql_timer_timeout_id == NULL) {
1501 ql_timer_ticks = drv_sectohz(1);
1502 ql_timer_timeout_id = timeout(ql_timer, (void *)0,
1503 ql_timer_ticks);
1504 }
1505
1506 /* Release global state lock. */
1507 GLOBAL_STATE_UNLOCK();
1508
1509 /* Determine and populate HBA fru info */
1510 ql_setup_fruinfo(ha);
1511
1512 /* Setup task_daemon thread. */
1513 (void) thread_create(NULL, 0, (void (*)())ql_task_daemon, ha,
1514 0, &p0, TS_RUN, minclsyspri);
1515
1516 progress |= QL_TASK_DAEMON_STARTED;
1517
1518 ddi_report_dev(dip);
1519
1520 /* Disable link reset in panic path */
1521 ha->lip_on_panic = 1;
1956
1957 if (ha->devpath != NULL) {
1958 kmem_free(ha->devpath, strlen(ha->devpath) + 1);
1959 }
1960
1961 kmem_free(ha->dev, sizeof (*ha->dev) * DEVICE_HEAD_LIST_SIZE);
1962
1963 EL(ha, "detached\n");
1964
1965 ddi_soft_state_free(ql_state, (int)ha->instance);
1966
1967 break;
1968
1969 case DDI_SUSPEND:
1970 ADAPTER_STATE_LOCK(ha);
1971
1972 delay_cnt = 0;
1973 ha->flags |= ADAPTER_SUSPENDED;
1974 while (ha->flags & ADAPTER_TIMER_BUSY && delay_cnt++ < 10) {
1975 ADAPTER_STATE_UNLOCK(ha);
1976 delay(drv_sectohz(1));
1977 ADAPTER_STATE_LOCK(ha);
1978 }
1979 if (ha->busy || ha->flags & ADAPTER_TIMER_BUSY) {
1980 ha->flags &= ~ADAPTER_SUSPENDED;
1981 ADAPTER_STATE_UNLOCK(ha);
1982 rval = DDI_FAILURE;
1983 cmn_err(CE_WARN, "!%s(%d): Fail suspend"
1984 " busy %xh flags %xh", QL_NAME, ha->instance,
1985 ha->busy, ha->flags);
1986 break;
1987 }
1988
1989 ADAPTER_STATE_UNLOCK(ha);
1990
1991 if (ha->flags & IP_INITIALIZED) {
1992 (void) ql_shutdown_ip(ha);
1993 }
1994
1995 if ((suspend = ql_suspend_adapter(ha)) != QL_SUCCESS) {
1996 ADAPTER_STATE_LOCK(ha);
11852
11853 ha->ql_dump_state &= ~(QL_DUMP_VALID | QL_DUMP_UPLOADED);
11854 ha->ql_dump_state |= QL_DUMPING;
11855
11856 QL_DUMP_UNLOCK(ha);
11857
11858 if (CFG_IST(ha, CFG_ENABLE_FWEXTTRACE)) {
11859
11860 /* Insert Time Stamp */
11861 rval = ql_fw_etrace(ha, &ha->fwexttracebuf,
11862 FTO_INSERT_TIME_STAMP);
11863 if (rval != QL_SUCCESS) {
11864 EL(ha, "f/w extended trace insert"
11865 "time stamp failed: %xh\n", rval);
11866 }
11867 }
11868
11869 if (lock_needed == TRUE) {
11870 /* Acquire mailbox register lock. */
11871 MBX_REGISTER_LOCK(ha);
11872 timer = drv_sectohz(ha->mcp->timeout + 2);
11873
11874 /* Check for mailbox available, if not wait for signal. */
11875 while (ha->mailbox_flags & MBX_BUSY_FLG) {
11876 ha->mailbox_flags = (uint8_t)
11877 (ha->mailbox_flags | MBX_WANT_FLG);
11878
11879 /* 30 seconds from now */
11880 if (cv_reltimedwait(&ha->cv_mbx_wait, &ha->mbx_mutex,
11881 timer, TR_CLOCK_TICK) == -1) {
11882 /*
11883 * The timeout time 'timer' was
11884 * reached without the condition
11885 * being signaled.
11886 */
11887
11888 /* Release mailbox register lock. */
11889 MBX_REGISTER_UNLOCK(ha);
11890
11891 EL(ha, "failed, rval = %xh\n",
11892 QL_FUNCTION_TIMEOUT);
15887 /* ARGSUSED */
15888 static void
15889 ql_unbind_dma_buffer(ql_adapter_state_t *ha, dma_mem_t *mem)
15890 {
15891 QL_PRINT_3(CE_CONT, "(%d): started\n", ha->instance);
15892
15893 (void) ddi_dma_unbind_handle(mem->dma_handle);
15894 if (mem->cookie_count > 1) {
15895 kmem_free(mem->cookies, sizeof (ddi_dma_cookie_t) *
15896 mem->cookie_count);
15897 mem->cookies = NULL;
15898 }
15899 mem->cookie_count = 0;
15900
15901 QL_PRINT_3(CE_CONT, "(%d): done\n", ha->instance);
15902 }
15903
15904 static int
15905 ql_suspend_adapter(ql_adapter_state_t *ha)
15906 {
15907 clock_t timer = drv_sectohz(32);
15908
15909 QL_PRINT_3(CE_CONT, "(%d): started\n", ha->instance);
15910
15911 /*
15912 * First we will claim mbox ownership so that no
15913 * thread using mbox hangs when we disable the
15914 * interrupt in the middle of it.
15915 */
15916 MBX_REGISTER_LOCK(ha);
15917
15918 /* Check for mailbox available, if not wait for signal. */
15919 while (ha->mailbox_flags & MBX_BUSY_FLG) {
15920 ha->mailbox_flags = (uint8_t)
15921 (ha->mailbox_flags | MBX_WANT_FLG);
15922
15923 /* 30 seconds from now */
15924 if (cv_reltimedwait(&ha->cv_mbx_wait, &ha->mbx_mutex,
15925 timer, TR_CLOCK_TICK) == -1) {
15926
15927 /* Release mailbox register lock. */
|