aic7xxx: convert to SPI transport class Domain Validation

Now that we export all the parameters, this is easy to do.
It also means that we can dump about 2000 lines of code that
were dedicated to doing this internally.

Additionally, this removes all the aic7xxx driver abuse
of SCSI timers which were embedded in the DV routines.

Signed-off-by: James Bottomley <James.Bottomley@SteelEye.com>

authored by and committed by James Bottomley cb624029 92d161c3

+10 -1711
+10 -1671
drivers/scsi/aic7xxx/aic7xxx_osm.c
··· 275 275 }; 276 276 277 277 /* 278 - * DV option: 279 - * 280 - * positive value = DV Enabled 281 - * zero = DV Disabled 282 - * negative value = DV Default for adapter type/seeprom 283 - */ 284 - #ifdef CONFIG_AIC7XXX_DV_SETTING 285 - #define AIC7XXX_CONFIGED_DV CONFIG_AIC7XXX_DV_SETTING 286 - #else 287 - #define AIC7XXX_CONFIGED_DV -1 288 - #endif 289 - 290 - static int8_t aic7xxx_dv_settings[] = 291 - { 292 - AIC7XXX_CONFIGED_DV, 293 - AIC7XXX_CONFIGED_DV, 294 - AIC7XXX_CONFIGED_DV, 295 - AIC7XXX_CONFIGED_DV, 296 - AIC7XXX_CONFIGED_DV, 297 - AIC7XXX_CONFIGED_DV, 298 - AIC7XXX_CONFIGED_DV, 299 - AIC7XXX_CONFIGED_DV, 300 - AIC7XXX_CONFIGED_DV, 301 - AIC7XXX_CONFIGED_DV, 302 - AIC7XXX_CONFIGED_DV, 303 - AIC7XXX_CONFIGED_DV, 304 - AIC7XXX_CONFIGED_DV, 305 - AIC7XXX_CONFIGED_DV, 306 - AIC7XXX_CONFIGED_DV, 307 - AIC7XXX_CONFIGED_DV 308 - }; 309 - 310 - /* 311 278 * There should be a specific return value for this in scsi.h, but 312 279 * it seems that most drivers ignore it. 313 280 */ ··· 421 454 " tag_info:<tag_str> Set per-target tag depth\n" 422 455 " global_tag_depth:<int> Global tag depth for every target\n" 423 456 " on every bus\n" 424 - " dv:<dv_settings> Set per-controller Domain Validation Setting.\n" 425 457 " seltime:<int> Selection Timeout\n" 426 458 " (0/256ms,1/128ms,2/64ms,3/32ms)\n" 427 459 "\n" ··· 437 471 struct scb *); 438 472 static void ahc_linux_queue_cmd_complete(struct ahc_softc *ahc, 439 473 Scsi_Cmnd *cmd); 440 - static void ahc_linux_filter_inquiry(struct ahc_softc*, struct ahc_devinfo*); 441 474 static void ahc_linux_sem_timeout(u_long arg); 442 475 static void ahc_linux_freeze_simq(struct ahc_softc *ahc); 443 476 static void ahc_linux_release_simq(u_long arg); ··· 445 480 static void ahc_linux_initialize_scsi_bus(struct ahc_softc *ahc); 446 481 static void ahc_linux_size_nseg(void); 447 482 static void ahc_linux_thread_run_complete_queue(struct ahc_softc *ahc); 448 - static void ahc_linux_start_dv(struct ahc_softc *ahc); 449 - static void ahc_linux_dv_timeout(struct scsi_cmnd *cmd); 450 - static int ahc_linux_dv_thread(void *data); 451 - static void ahc_linux_kill_dv_thread(struct ahc_softc *ahc); 452 - static void ahc_linux_dv_target(struct ahc_softc *ahc, u_int target); 453 - static void ahc_linux_dv_transition(struct ahc_softc *ahc, 454 - struct scsi_cmnd *cmd, 455 - struct ahc_devinfo *devinfo, 456 - struct ahc_linux_target *targ); 457 - static void ahc_linux_dv_fill_cmd(struct ahc_softc *ahc, 458 - struct scsi_cmnd *cmd, 459 - struct ahc_devinfo *devinfo); 460 - static void ahc_linux_dv_inq(struct ahc_softc *ahc, 461 - struct scsi_cmnd *cmd, 462 - struct ahc_devinfo *devinfo, 463 - struct ahc_linux_target *targ, 464 - u_int request_length); 465 - static void ahc_linux_dv_tur(struct ahc_softc *ahc, 466 - struct scsi_cmnd *cmd, 467 - struct ahc_devinfo *devinfo); 468 - static void ahc_linux_dv_rebd(struct ahc_softc *ahc, 469 - struct scsi_cmnd *cmd, 470 - struct ahc_devinfo *devinfo, 471 - struct ahc_linux_target *targ); 472 - static void ahc_linux_dv_web(struct ahc_softc *ahc, 473 - struct scsi_cmnd *cmd, 474 - struct ahc_devinfo *devinfo, 475 - struct ahc_linux_target *targ); 476 - static void ahc_linux_dv_reb(struct ahc_softc *ahc, 477 - struct scsi_cmnd *cmd, 478 - struct ahc_devinfo *devinfo, 479 - struct ahc_linux_target *targ); 480 - static void ahc_linux_dv_su(struct ahc_softc *ahc, 481 - struct scsi_cmnd *cmd, 482 - struct ahc_devinfo *devinfo, 483 - struct ahc_linux_target *targ); 484 - static int ahc_linux_fallback(struct ahc_softc *ahc, 485 - struct ahc_devinfo *devinfo); 486 - static void ahc_linux_dv_complete(Scsi_Cmnd *cmd); 487 - static void ahc_linux_generate_dv_pattern(struct ahc_linux_target *targ); 488 483 static u_int ahc_linux_user_tagdepth(struct ahc_softc *ahc, 489 484 struct ahc_devinfo *devinfo); 490 - static u_int ahc_linux_user_dv_setting(struct ahc_softc *ahc); 491 485 static void ahc_linux_device_queue_depth(struct ahc_softc *ahc, 492 486 struct ahc_linux_device *dev); 493 487 static struct ahc_linux_target* ahc_linux_alloc_target(struct ahc_softc*, ··· 462 538 struct ahc_linux_device*); 463 539 static void ahc_linux_setup_tag_info_global(char *p); 464 540 static aic_option_callback_t ahc_linux_setup_tag_info; 465 - static aic_option_callback_t ahc_linux_setup_dv; 466 541 static int aic7xxx_setup(char *s); 467 542 static int ahc_linux_next_unit(void); 468 543 static void ahc_runq_tasklet(unsigned long data); ··· 590 667 { 591 668 592 669 if ((ahc->flags & AHC_RESOURCE_SHORTAGE) != 0 593 - || (ahc->platform_data->qfrozen != 0 594 - && AHC_DV_SIMQ_FROZEN(ahc) == 0)) 670 + || (ahc->platform_data->qfrozen != 0)) 595 671 return (NULL); 596 672 return (TAILQ_FIRST(&ahc->platform_data->device_runq)); 597 673 } ··· 888 966 * DV commands through so long as we are only frozen to 889 967 * perform DV. 890 968 */ 891 - if (ahc->platform_data->qfrozen != 0 892 - && AHC_DV_CMD(cmd) == 0) { 969 + if (ahc->platform_data->qfrozen != 0) { 893 970 894 971 ahc_cmd_set_transaction_status(cmd, CAM_REQUEUE_REQ); 895 972 ahc_linux_queue_cmd_complete(ahc, cmd); ··· 955 1034 ahc_linux_device_queue_depth(ahc, dev); 956 1035 } 957 1036 ahc_midlayer_entrypoint_unlock(ahc, &flags); 1037 + 1038 + /* Initial Domain Validation */ 1039 + if (!spi_initial_dv(device->sdev_target)) 1040 + spi_dv_device(device); 1041 + 958 1042 return (0); 959 1043 } 960 1044 ··· 1475 1549 } 1476 1550 } 1477 1551 1478 - static void 1479 - ahc_linux_setup_dv(u_long arg, int instance, int targ, int32_t value) 1480 - { 1481 - 1482 - if ((instance >= 0) 1483 - && (instance < NUM_ELEMENTS(aic7xxx_dv_settings))) { 1484 - aic7xxx_dv_settings[instance] = value; 1485 - if (bootverbose) 1486 - printf("dv[%d] = %d\n", instance, value); 1487 - } 1488 - } 1489 - 1490 1552 /* 1491 1553 * Handle Linux boot parameters. This routine allows for assigning a value 1492 1554 * to a parameter with a ':' between the parameter and the value. ··· 1534 1620 } else if (strncmp(p, "tag_info", n) == 0) { 1535 1621 s = aic_parse_brace_option("tag_info", p + n, end, 1536 1622 2, ahc_linux_setup_tag_info, 0); 1537 - } else if (strncmp(p, "dv", n) == 0) { 1538 - s = aic_parse_brace_option("dv", p + n, end, 1, 1539 - ahc_linux_setup_dv, 0); 1540 1623 } else if (p[n] == ':') { 1541 1624 *(options[i].flag) = simple_strtoul(p + n + 1, NULL, 0); 1542 1625 } else if (strncmp(p, "verbose", n) == 0) { ··· 1556 1645 struct Scsi_Host *host; 1557 1646 char *new_name; 1558 1647 u_long s; 1559 - u_int targ_offset; 1560 1648 1561 1649 template->name = ahc->description; 1562 1650 host = scsi_host_alloc(template, sizeof(struct ahc_softc *)); ··· 1591 1681 scsi_set_pci_device(host, ahc->dev_softc); 1592 1682 #endif 1593 1683 ahc_linux_initialize_scsi_bus(ahc); 1594 - ahc_unlock(ahc, &s); 1595 - ahc->platform_data->dv_pid = kernel_thread(ahc_linux_dv_thread, ahc, 0); 1596 - ahc_lock(ahc, &s); 1597 - if (ahc->platform_data->dv_pid < 0) { 1598 - printf("%s: Failed to create DV thread, error= %d\n", 1599 - ahc_name(ahc), ahc->platform_data->dv_pid); 1600 - return (-ahc->platform_data->dv_pid); 1601 - } 1602 - /* 1603 - * Initially allocate *all* of our linux target objects 1604 - * so that the DV thread will scan them all in parallel 1605 - * just after driver initialization. Any device that 1606 - * does not exist will have its target object destroyed 1607 - * by the selection timeout handler. In the case of a 1608 - * device that appears after the initial DV scan, async 1609 - * negotiation will occur for the first command, and DV 1610 - * will comence should that first command be successful. 1611 - */ 1612 - for (targ_offset = 0; 1613 - targ_offset < host->max_id * (host->max_channel + 1); 1614 - targ_offset++) { 1615 - u_int channel; 1616 - u_int target; 1617 - 1618 - channel = 0; 1619 - target = targ_offset; 1620 - if (target > 7 1621 - && (ahc->features & AHC_TWIN) != 0) { 1622 - channel = 1; 1623 - target &= 0x7; 1624 - } 1625 - /* 1626 - * Skip our own ID. Some Compaq/HP storage devices 1627 - * have enclosure management devices that respond to 1628 - * single bit selection (i.e. selecting ourselves). 1629 - * It is expected that either an external application 1630 - * or a modified kernel will be used to probe this 1631 - * ID if it is appropriate. To accommodate these 1632 - * installations, ahc_linux_alloc_target() will allocate 1633 - * for our ID if asked to do so. 1634 - */ 1635 - if ((channel == 0 && target == ahc->our_id) 1636 - || (channel == 1 && target == ahc->our_id_b)) 1637 - continue; 1638 - 1639 - ahc_linux_alloc_target(ahc, channel, target); 1640 - } 1641 1684 ahc_intr_enable(ahc, TRUE); 1642 - ahc_linux_start_dv(ahc); 1643 1685 ahc_unlock(ahc, &s); 1644 1686 1645 1687 host->transportt = ahc_linux_transport_template; ··· 1728 1866 ahc->platform_data->completeq_timer.function = 1729 1867 (ahc_linux_callback_t *)ahc_linux_thread_run_complete_queue; 1730 1868 init_MUTEX_LOCKED(&ahc->platform_data->eh_sem); 1731 - init_MUTEX_LOCKED(&ahc->platform_data->dv_sem); 1732 - init_MUTEX_LOCKED(&ahc->platform_data->dv_cmd_sem); 1733 1869 tasklet_init(&ahc->platform_data->runq_tasklet, ahc_runq_tasklet, 1734 1870 (unsigned long)ahc); 1735 1871 ahc->seltime = (aic7xxx_seltime & 0x3) << 4; ··· 1747 1887 1748 1888 if (ahc->platform_data != NULL) { 1749 1889 del_timer_sync(&ahc->platform_data->completeq_timer); 1750 - ahc_linux_kill_dv_thread(ahc); 1751 1890 tasklet_kill(&ahc->platform_data->runq_tasklet); 1752 1891 if (ahc->platform_data->host != NULL) { 1753 1892 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0) ··· 1985 2126 ahc_unlock(ahc, &flags); 1986 2127 } 1987 2128 1988 - static void 1989 - ahc_linux_start_dv(struct ahc_softc *ahc) 1990 - { 1991 - 1992 - /* 1993 - * Freeze the simq and signal ahc_linux_queue to not let any 1994 - * more commands through. 1995 - */ 1996 - if ((ahc->platform_data->flags & AHC_DV_ACTIVE) == 0) { 1997 - #ifdef AHC_DEBUG 1998 - if (ahc_debug & AHC_SHOW_DV) 1999 - printf("%s: Waking DV thread\n", ahc_name(ahc)); 2000 - #endif 2001 - 2002 - ahc->platform_data->flags |= AHC_DV_ACTIVE; 2003 - ahc_linux_freeze_simq(ahc); 2004 - 2005 - /* Wake up the DV kthread */ 2006 - up(&ahc->platform_data->dv_sem); 2007 - } 2008 - } 2009 - 2010 - static void 2011 - ahc_linux_kill_dv_thread(struct ahc_softc *ahc) 2012 - { 2013 - u_long s; 2014 - 2015 - ahc_lock(ahc, &s); 2016 - if (ahc->platform_data->dv_pid != 0) { 2017 - ahc->platform_data->flags |= AHC_DV_SHUTDOWN; 2018 - ahc_unlock(ahc, &s); 2019 - up(&ahc->platform_data->dv_sem); 2020 - 2021 - /* 2022 - * Use the eh_sem as an indicator that the 2023 - * dv thread is exiting. Note that the dv 2024 - * thread must still return after performing 2025 - * the up on our semaphore before it has 2026 - * completely exited this module. Unfortunately, 2027 - * there seems to be no easy way to wait for the 2028 - * exit of a thread for which you are not the 2029 - * parent (dv threads are parented by init). 2030 - * Cross your fingers... 2031 - */ 2032 - down(&ahc->platform_data->eh_sem); 2033 - 2034 - /* 2035 - * Mark the dv thread as already dead. This 2036 - * avoids attempting to kill it a second time. 2037 - * This is necessary because we must kill the 2038 - * DV thread before calling ahc_free() in the 2039 - * module shutdown case to avoid bogus locking 2040 - * in the SCSI mid-layer, but we ahc_free() is 2041 - * called without killing the DV thread in the 2042 - * instance detach case, so ahc_platform_free() 2043 - * calls us again to verify that the DV thread 2044 - * is dead. 2045 - */ 2046 - ahc->platform_data->dv_pid = 0; 2047 - } else { 2048 - ahc_unlock(ahc, &s); 2049 - } 2050 - } 2051 - 2052 - static int 2053 - ahc_linux_dv_thread(void *data) 2054 - { 2055 - struct ahc_softc *ahc; 2056 - int target; 2057 - u_long s; 2058 - 2059 - ahc = (struct ahc_softc *)data; 2060 - 2061 - #ifdef AHC_DEBUG 2062 - if (ahc_debug & AHC_SHOW_DV) 2063 - printf("Launching DV Thread\n"); 2064 - #endif 2065 - 2066 - /* 2067 - * Complete thread creation. 2068 - */ 2069 - lock_kernel(); 2070 - #if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0) 2071 - /* 2072 - * Don't care about any signals. 2073 - */ 2074 - siginitsetinv(&current->blocked, 0); 2075 - 2076 - daemonize(); 2077 - sprintf(current->comm, "ahc_dv_%d", ahc->unit); 2078 - #else 2079 - daemonize("ahc_dv_%d", ahc->unit); 2080 - current->flags |= PF_FREEZE; 2081 - #endif 2082 - unlock_kernel(); 2083 - 2084 - while (1) { 2085 - /* 2086 - * Use down_interruptible() rather than down() to 2087 - * avoid inclusion in the load average. 2088 - */ 2089 - down_interruptible(&ahc->platform_data->dv_sem); 2090 - 2091 - /* Check to see if we've been signaled to exit */ 2092 - ahc_lock(ahc, &s); 2093 - if ((ahc->platform_data->flags & AHC_DV_SHUTDOWN) != 0) { 2094 - ahc_unlock(ahc, &s); 2095 - break; 2096 - } 2097 - ahc_unlock(ahc, &s); 2098 - 2099 - #ifdef AHC_DEBUG 2100 - if (ahc_debug & AHC_SHOW_DV) 2101 - printf("%s: Beginning Domain Validation\n", 2102 - ahc_name(ahc)); 2103 - #endif 2104 - 2105 - /* 2106 - * Wait for any pending commands to drain before proceeding. 2107 - */ 2108 - ahc_lock(ahc, &s); 2109 - while (LIST_FIRST(&ahc->pending_scbs) != NULL) { 2110 - ahc->platform_data->flags |= AHC_DV_WAIT_SIMQ_EMPTY; 2111 - ahc_unlock(ahc, &s); 2112 - down_interruptible(&ahc->platform_data->dv_sem); 2113 - ahc_lock(ahc, &s); 2114 - } 2115 - 2116 - /* 2117 - * Wait for the SIMQ to be released so that DV is the 2118 - * only reason the queue is frozen. 2119 - */ 2120 - while (AHC_DV_SIMQ_FROZEN(ahc) == 0) { 2121 - ahc->platform_data->flags |= AHC_DV_WAIT_SIMQ_RELEASE; 2122 - ahc_unlock(ahc, &s); 2123 - down_interruptible(&ahc->platform_data->dv_sem); 2124 - ahc_lock(ahc, &s); 2125 - } 2126 - ahc_unlock(ahc, &s); 2127 - 2128 - for (target = 0; target < AHC_NUM_TARGETS; target++) 2129 - ahc_linux_dv_target(ahc, target); 2130 - 2131 - ahc_lock(ahc, &s); 2132 - ahc->platform_data->flags &= ~AHC_DV_ACTIVE; 2133 - ahc_unlock(ahc, &s); 2134 - 2135 - /* 2136 - * Release the SIMQ so that normal commands are 2137 - * allowed to continue on the bus. 2138 - */ 2139 - ahc_linux_release_simq((u_long)ahc); 2140 - } 2141 - up(&ahc->platform_data->eh_sem); 2142 - return (0); 2143 - } 2144 - 2145 - #define AHC_LINUX_DV_INQ_SHORT_LEN 36 2146 - #define AHC_LINUX_DV_INQ_LEN 256 2147 - #define AHC_LINUX_DV_TIMEOUT (HZ / 4) 2148 - 2149 - #define AHC_SET_DV_STATE(ahc, targ, newstate) \ 2150 - ahc_set_dv_state(ahc, targ, newstate, __LINE__) 2151 - 2152 - static __inline void 2153 - ahc_set_dv_state(struct ahc_softc *ahc, struct ahc_linux_target *targ, 2154 - ahc_dv_state newstate, u_int line) 2155 - { 2156 - ahc_dv_state oldstate; 2157 - 2158 - oldstate = targ->dv_state; 2159 - #ifdef AHC_DEBUG 2160 - if (ahc_debug & AHC_SHOW_DV) 2161 - printf("%s:%d: Going from state %d to state %d\n", 2162 - ahc_name(ahc), line, oldstate, newstate); 2163 - #endif 2164 - 2165 - if (oldstate == newstate) 2166 - targ->dv_state_retry++; 2167 - else 2168 - targ->dv_state_retry = 0; 2169 - targ->dv_state = newstate; 2170 - } 2171 - 2172 - static void 2173 - ahc_linux_dv_target(struct ahc_softc *ahc, u_int target_offset) 2174 - { 2175 - struct ahc_devinfo devinfo; 2176 - struct ahc_linux_target *targ; 2177 - struct scsi_cmnd *cmd; 2178 - struct scsi_device *scsi_dev; 2179 - struct scsi_sense_data *sense; 2180 - uint8_t *buffer; 2181 - u_long s; 2182 - u_int timeout; 2183 - int echo_size; 2184 - 2185 - sense = NULL; 2186 - buffer = NULL; 2187 - echo_size = 0; 2188 - ahc_lock(ahc, &s); 2189 - targ = ahc->platform_data->targets[target_offset]; 2190 - if (targ == NULL || (targ->flags & AHC_DV_REQUIRED) == 0) { 2191 - ahc_unlock(ahc, &s); 2192 - return; 2193 - } 2194 - ahc_compile_devinfo(&devinfo, 2195 - targ->channel == 0 ? ahc->our_id : ahc->our_id_b, 2196 - targ->target, /*lun*/0, targ->channel + 'A', 2197 - ROLE_INITIATOR); 2198 - #ifdef AHC_DEBUG 2199 - if (ahc_debug & AHC_SHOW_DV) { 2200 - ahc_print_devinfo(ahc, &devinfo); 2201 - printf("Performing DV\n"); 2202 - } 2203 - #endif 2204 - 2205 - ahc_unlock(ahc, &s); 2206 - 2207 - cmd = malloc(sizeof(struct scsi_cmnd), M_DEVBUF, M_WAITOK); 2208 - scsi_dev = malloc(sizeof(struct scsi_device), M_DEVBUF, M_WAITOK); 2209 - scsi_dev->host = ahc->platform_data->host; 2210 - scsi_dev->id = devinfo.target; 2211 - scsi_dev->lun = devinfo.lun; 2212 - scsi_dev->channel = devinfo.channel - 'A'; 2213 - ahc->platform_data->dv_scsi_dev = scsi_dev; 2214 - 2215 - AHC_SET_DV_STATE(ahc, targ, AHC_DV_STATE_INQ_SHORT_ASYNC); 2216 - 2217 - while (targ->dv_state != AHC_DV_STATE_EXIT) { 2218 - timeout = AHC_LINUX_DV_TIMEOUT; 2219 - switch (targ->dv_state) { 2220 - case AHC_DV_STATE_INQ_SHORT_ASYNC: 2221 - case AHC_DV_STATE_INQ_ASYNC: 2222 - case AHC_DV_STATE_INQ_ASYNC_VERIFY: 2223 - /* 2224 - * Set things to async narrow to reduce the 2225 - * chance that the INQ will fail. 2226 - */ 2227 - ahc_lock(ahc, &s); 2228 - ahc_set_syncrate(ahc, &devinfo, NULL, 0, 0, 0, 2229 - AHC_TRANS_GOAL, /*paused*/FALSE); 2230 - ahc_set_width(ahc, &devinfo, MSG_EXT_WDTR_BUS_8_BIT, 2231 - AHC_TRANS_GOAL, /*paused*/FALSE); 2232 - ahc_unlock(ahc, &s); 2233 - timeout = 10 * HZ; 2234 - targ->flags &= ~AHC_INQ_VALID; 2235 - /* FALLTHROUGH */ 2236 - case AHC_DV_STATE_INQ_VERIFY: 2237 - { 2238 - u_int inq_len; 2239 - 2240 - if (targ->dv_state == AHC_DV_STATE_INQ_SHORT_ASYNC) 2241 - inq_len = AHC_LINUX_DV_INQ_SHORT_LEN; 2242 - else 2243 - inq_len = targ->inq_data->additional_length + 5; 2244 - ahc_linux_dv_inq(ahc, cmd, &devinfo, targ, inq_len); 2245 - break; 2246 - } 2247 - case AHC_DV_STATE_TUR: 2248 - case AHC_DV_STATE_BUSY: 2249 - timeout = 5 * HZ; 2250 - ahc_linux_dv_tur(ahc, cmd, &devinfo); 2251 - break; 2252 - case AHC_DV_STATE_REBD: 2253 - ahc_linux_dv_rebd(ahc, cmd, &devinfo, targ); 2254 - break; 2255 - case AHC_DV_STATE_WEB: 2256 - ahc_linux_dv_web(ahc, cmd, &devinfo, targ); 2257 - break; 2258 - 2259 - case AHC_DV_STATE_REB: 2260 - ahc_linux_dv_reb(ahc, cmd, &devinfo, targ); 2261 - break; 2262 - 2263 - case AHC_DV_STATE_SU: 2264 - ahc_linux_dv_su(ahc, cmd, &devinfo, targ); 2265 - timeout = 50 * HZ; 2266 - break; 2267 - 2268 - default: 2269 - ahc_print_devinfo(ahc, &devinfo); 2270 - printf("Unknown DV state %d\n", targ->dv_state); 2271 - goto out; 2272 - } 2273 - 2274 - /* Queue the command and wait for it to complete */ 2275 - /* Abuse eh_timeout in the scsi_cmnd struct for our purposes */ 2276 - init_timer(&cmd->eh_timeout); 2277 - #ifdef AHC_DEBUG 2278 - if ((ahc_debug & AHC_SHOW_MESSAGES) != 0) 2279 - /* 2280 - * All of the printfs during negotiation 2281 - * really slow down the negotiation. 2282 - * Add a bit of time just to be safe. 2283 - */ 2284 - timeout += HZ; 2285 - #endif 2286 - scsi_add_timer(cmd, timeout, ahc_linux_dv_timeout); 2287 - /* 2288 - * In 2.5.X, it is assumed that all calls from the 2289 - * "midlayer" (which we are emulating) will have the 2290 - * ahc host lock held. For other kernels, the 2291 - * io_request_lock must be held. 2292 - */ 2293 - #if AHC_SCSI_HAS_HOST_LOCK != 0 2294 - ahc_lock(ahc, &s); 2295 - #else 2296 - spin_lock_irqsave(&io_request_lock, s); 2297 - #endif 2298 - ahc_linux_queue(cmd, ahc_linux_dv_complete); 2299 - #if AHC_SCSI_HAS_HOST_LOCK != 0 2300 - ahc_unlock(ahc, &s); 2301 - #else 2302 - spin_unlock_irqrestore(&io_request_lock, s); 2303 - #endif 2304 - down_interruptible(&ahc->platform_data->dv_cmd_sem); 2305 - /* 2306 - * Wait for the SIMQ to be released so that DV is the 2307 - * only reason the queue is frozen. 2308 - */ 2309 - ahc_lock(ahc, &s); 2310 - while (AHC_DV_SIMQ_FROZEN(ahc) == 0) { 2311 - ahc->platform_data->flags |= AHC_DV_WAIT_SIMQ_RELEASE; 2312 - ahc_unlock(ahc, &s); 2313 - down_interruptible(&ahc->platform_data->dv_sem); 2314 - ahc_lock(ahc, &s); 2315 - } 2316 - ahc_unlock(ahc, &s); 2317 - 2318 - ahc_linux_dv_transition(ahc, cmd, &devinfo, targ); 2319 - } 2320 - 2321 - out: 2322 - if ((targ->flags & AHC_INQ_VALID) != 0 2323 - && ahc_linux_get_device(ahc, devinfo.channel - 'A', 2324 - devinfo.target, devinfo.lun, 2325 - /*alloc*/FALSE) == NULL) { 2326 - /* 2327 - * The DV state machine failed to configure this device. 2328 - * This is normal if DV is disabled. Since we have inquiry 2329 - * data, filter it and use the "optimistic" negotiation 2330 - * parameters found in the inquiry string. 2331 - */ 2332 - ahc_linux_filter_inquiry(ahc, &devinfo); 2333 - if ((targ->flags & (AHC_BASIC_DV|AHC_ENHANCED_DV)) != 0) { 2334 - ahc_print_devinfo(ahc, &devinfo); 2335 - printf("DV failed to configure device. " 2336 - "Please file a bug report against " 2337 - "this driver.\n"); 2338 - } 2339 - } 2340 - 2341 - if (cmd != NULL) 2342 - free(cmd, M_DEVBUF); 2343 - 2344 - if (ahc->platform_data->dv_scsi_dev != NULL) { 2345 - free(ahc->platform_data->dv_scsi_dev, M_DEVBUF); 2346 - ahc->platform_data->dv_scsi_dev = NULL; 2347 - } 2348 - 2349 - ahc_lock(ahc, &s); 2350 - if (targ->dv_buffer != NULL) { 2351 - free(targ->dv_buffer, M_DEVBUF); 2352 - targ->dv_buffer = NULL; 2353 - } 2354 - if (targ->dv_buffer1 != NULL) { 2355 - free(targ->dv_buffer1, M_DEVBUF); 2356 - targ->dv_buffer1 = NULL; 2357 - } 2358 - targ->flags &= ~AHC_DV_REQUIRED; 2359 - if (targ->refcount == 0) 2360 - ahc_linux_free_target(ahc, targ); 2361 - ahc_unlock(ahc, &s); 2362 - } 2363 - 2364 - static void 2365 - ahc_linux_dv_transition(struct ahc_softc *ahc, struct scsi_cmnd *cmd, 2366 - struct ahc_devinfo *devinfo, 2367 - struct ahc_linux_target *targ) 2368 - { 2369 - u_int32_t status; 2370 - 2371 - status = aic_error_action(cmd, targ->inq_data, 2372 - ahc_cmd_get_transaction_status(cmd), 2373 - ahc_cmd_get_scsi_status(cmd)); 2374 - 2375 - #ifdef AHC_DEBUG 2376 - if (ahc_debug & AHC_SHOW_DV) { 2377 - ahc_print_devinfo(ahc, devinfo); 2378 - printf("Entering ahc_linux_dv_transition, state= %d, " 2379 - "status= 0x%x, cmd->result= 0x%x\n", targ->dv_state, 2380 - status, cmd->result); 2381 - } 2382 - #endif 2383 - 2384 - switch (targ->dv_state) { 2385 - case AHC_DV_STATE_INQ_SHORT_ASYNC: 2386 - case AHC_DV_STATE_INQ_ASYNC: 2387 - switch (status & SS_MASK) { 2388 - case SS_NOP: 2389 - { 2390 - AHC_SET_DV_STATE(ahc, targ, targ->dv_state+1); 2391 - break; 2392 - } 2393 - case SS_INQ_REFRESH: 2394 - AHC_SET_DV_STATE(ahc, targ, 2395 - AHC_DV_STATE_INQ_SHORT_ASYNC); 2396 - break; 2397 - case SS_TUR: 2398 - case SS_RETRY: 2399 - AHC_SET_DV_STATE(ahc, targ, targ->dv_state); 2400 - if (ahc_cmd_get_transaction_status(cmd) 2401 - == CAM_REQUEUE_REQ) 2402 - targ->dv_state_retry--; 2403 - if ((status & SS_ERRMASK) == EBUSY) 2404 - AHC_SET_DV_STATE(ahc, targ, AHC_DV_STATE_BUSY); 2405 - if (targ->dv_state_retry < 10) 2406 - break; 2407 - /* FALLTHROUGH */ 2408 - default: 2409 - AHC_SET_DV_STATE(ahc, targ, AHC_DV_STATE_EXIT); 2410 - #ifdef AHC_DEBUG 2411 - if (ahc_debug & AHC_SHOW_DV) { 2412 - ahc_print_devinfo(ahc, devinfo); 2413 - printf("Failed DV inquiry, skipping\n"); 2414 - } 2415 - #endif 2416 - break; 2417 - } 2418 - break; 2419 - case AHC_DV_STATE_INQ_ASYNC_VERIFY: 2420 - switch (status & SS_MASK) { 2421 - case SS_NOP: 2422 - { 2423 - u_int xportflags; 2424 - u_int spi3data; 2425 - 2426 - if (memcmp(targ->inq_data, targ->dv_buffer, 2427 - AHC_LINUX_DV_INQ_LEN) != 0) { 2428 - /* 2429 - * Inquiry data must have changed. 2430 - * Try from the top again. 2431 - */ 2432 - AHC_SET_DV_STATE(ahc, targ, 2433 - AHC_DV_STATE_INQ_SHORT_ASYNC); 2434 - break; 2435 - } 2436 - 2437 - AHC_SET_DV_STATE(ahc, targ, targ->dv_state+1); 2438 - targ->flags |= AHC_INQ_VALID; 2439 - if (ahc_linux_user_dv_setting(ahc) == 0) 2440 - break; 2441 - 2442 - xportflags = targ->inq_data->flags; 2443 - if ((xportflags & (SID_Sync|SID_WBus16)) == 0) 2444 - break; 2445 - 2446 - spi3data = targ->inq_data->spi3data; 2447 - switch (spi3data & SID_SPI_CLOCK_DT_ST) { 2448 - default: 2449 - case SID_SPI_CLOCK_ST: 2450 - /* Assume only basic DV is supported. */ 2451 - targ->flags |= AHC_BASIC_DV; 2452 - break; 2453 - case SID_SPI_CLOCK_DT: 2454 - case SID_SPI_CLOCK_DT_ST: 2455 - targ->flags |= AHC_ENHANCED_DV; 2456 - break; 2457 - } 2458 - break; 2459 - } 2460 - case SS_INQ_REFRESH: 2461 - AHC_SET_DV_STATE(ahc, targ, 2462 - AHC_DV_STATE_INQ_SHORT_ASYNC); 2463 - break; 2464 - case SS_TUR: 2465 - case SS_RETRY: 2466 - AHC_SET_DV_STATE(ahc, targ, targ->dv_state); 2467 - if (ahc_cmd_get_transaction_status(cmd) 2468 - == CAM_REQUEUE_REQ) 2469 - targ->dv_state_retry--; 2470 - 2471 - if ((status & SS_ERRMASK) == EBUSY) 2472 - AHC_SET_DV_STATE(ahc, targ, AHC_DV_STATE_BUSY); 2473 - if (targ->dv_state_retry < 10) 2474 - break; 2475 - /* FALLTHROUGH */ 2476 - default: 2477 - AHC_SET_DV_STATE(ahc, targ, AHC_DV_STATE_EXIT); 2478 - #ifdef AHC_DEBUG 2479 - if (ahc_debug & AHC_SHOW_DV) { 2480 - ahc_print_devinfo(ahc, devinfo); 2481 - printf("Failed DV inquiry, skipping\n"); 2482 - } 2483 - #endif 2484 - break; 2485 - } 2486 - break; 2487 - case AHC_DV_STATE_INQ_VERIFY: 2488 - switch (status & SS_MASK) { 2489 - case SS_NOP: 2490 - { 2491 - 2492 - if (memcmp(targ->inq_data, targ->dv_buffer, 2493 - AHC_LINUX_DV_INQ_LEN) == 0) { 2494 - AHC_SET_DV_STATE(ahc, targ, AHC_DV_STATE_EXIT); 2495 - break; 2496 - } 2497 - #ifdef AHC_DEBUG 2498 - if (ahc_debug & AHC_SHOW_DV) { 2499 - int i; 2500 - 2501 - ahc_print_devinfo(ahc, devinfo); 2502 - printf("Inquiry buffer mismatch:"); 2503 - for (i = 0; i < AHC_LINUX_DV_INQ_LEN; i++) { 2504 - if ((i & 0xF) == 0) 2505 - printf("\n "); 2506 - printf("0x%x:0x0%x ", 2507 - ((uint8_t *)targ->inq_data)[i], 2508 - targ->dv_buffer[i]); 2509 - } 2510 - printf("\n"); 2511 - } 2512 - #endif 2513 - 2514 - if (ahc_linux_fallback(ahc, devinfo) != 0) { 2515 - AHC_SET_DV_STATE(ahc, targ, AHC_DV_STATE_EXIT); 2516 - break; 2517 - } 2518 - /* 2519 - * Do not count "falling back" 2520 - * against our retries. 2521 - */ 2522 - targ->dv_state_retry = 0; 2523 - AHC_SET_DV_STATE(ahc, targ, targ->dv_state); 2524 - break; 2525 - } 2526 - case SS_INQ_REFRESH: 2527 - AHC_SET_DV_STATE(ahc, targ, 2528 - AHC_DV_STATE_INQ_SHORT_ASYNC); 2529 - break; 2530 - case SS_TUR: 2531 - case SS_RETRY: 2532 - AHC_SET_DV_STATE(ahc, targ, targ->dv_state); 2533 - if (ahc_cmd_get_transaction_status(cmd) 2534 - == CAM_REQUEUE_REQ) { 2535 - targ->dv_state_retry--; 2536 - } else if ((status & SSQ_FALLBACK) != 0) { 2537 - if (ahc_linux_fallback(ahc, devinfo) != 0) { 2538 - AHC_SET_DV_STATE(ahc, targ, 2539 - AHC_DV_STATE_EXIT); 2540 - break; 2541 - } 2542 - /* 2543 - * Do not count "falling back" 2544 - * against our retries. 2545 - */ 2546 - targ->dv_state_retry = 0; 2547 - } else if ((status & SS_ERRMASK) == EBUSY) 2548 - AHC_SET_DV_STATE(ahc, targ, AHC_DV_STATE_BUSY); 2549 - if (targ->dv_state_retry < 10) 2550 - break; 2551 - /* FALLTHROUGH */ 2552 - default: 2553 - AHC_SET_DV_STATE(ahc, targ, AHC_DV_STATE_EXIT); 2554 - #ifdef AHC_DEBUG 2555 - if (ahc_debug & AHC_SHOW_DV) { 2556 - ahc_print_devinfo(ahc, devinfo); 2557 - printf("Failed DV inquiry, skipping\n"); 2558 - } 2559 - #endif 2560 - break; 2561 - } 2562 - break; 2563 - 2564 - case AHC_DV_STATE_TUR: 2565 - switch (status & SS_MASK) { 2566 - case SS_NOP: 2567 - if ((targ->flags & AHC_BASIC_DV) != 0) { 2568 - ahc_linux_filter_inquiry(ahc, devinfo); 2569 - AHC_SET_DV_STATE(ahc, targ, 2570 - AHC_DV_STATE_INQ_VERIFY); 2571 - } else if ((targ->flags & AHC_ENHANCED_DV) != 0) { 2572 - AHC_SET_DV_STATE(ahc, targ, AHC_DV_STATE_REBD); 2573 - } else { 2574 - AHC_SET_DV_STATE(ahc, targ, AHC_DV_STATE_EXIT); 2575 - } 2576 - break; 2577 - case SS_RETRY: 2578 - case SS_TUR: 2579 - if ((status & SS_ERRMASK) == EBUSY) { 2580 - AHC_SET_DV_STATE(ahc, targ, AHC_DV_STATE_BUSY); 2581 - break; 2582 - } 2583 - AHC_SET_DV_STATE(ahc, targ, targ->dv_state); 2584 - if (ahc_cmd_get_transaction_status(cmd) 2585 - == CAM_REQUEUE_REQ) { 2586 - targ->dv_state_retry--; 2587 - } else if ((status & SSQ_FALLBACK) != 0) { 2588 - if (ahc_linux_fallback(ahc, devinfo) != 0) { 2589 - AHC_SET_DV_STATE(ahc, targ, 2590 - AHC_DV_STATE_EXIT); 2591 - break; 2592 - } 2593 - /* 2594 - * Do not count "falling back" 2595 - * against our retries. 2596 - */ 2597 - targ->dv_state_retry = 0; 2598 - } 2599 - if (targ->dv_state_retry >= 10) { 2600 - #ifdef AHC_DEBUG 2601 - if (ahc_debug & AHC_SHOW_DV) { 2602 - ahc_print_devinfo(ahc, devinfo); 2603 - printf("DV TUR reties exhausted\n"); 2604 - } 2605 - #endif 2606 - AHC_SET_DV_STATE(ahc, targ, AHC_DV_STATE_EXIT); 2607 - break; 2608 - } 2609 - if (status & SSQ_DELAY) 2610 - ssleep(1); 2611 - 2612 - break; 2613 - case SS_START: 2614 - AHC_SET_DV_STATE(ahc, targ, AHC_DV_STATE_SU); 2615 - break; 2616 - case SS_INQ_REFRESH: 2617 - AHC_SET_DV_STATE(ahc, targ, 2618 - AHC_DV_STATE_INQ_SHORT_ASYNC); 2619 - break; 2620 - default: 2621 - AHC_SET_DV_STATE(ahc, targ, AHC_DV_STATE_EXIT); 2622 - break; 2623 - } 2624 - break; 2625 - 2626 - case AHC_DV_STATE_REBD: 2627 - switch (status & SS_MASK) { 2628 - case SS_NOP: 2629 - { 2630 - uint32_t echo_size; 2631 - 2632 - AHC_SET_DV_STATE(ahc, targ, AHC_DV_STATE_WEB); 2633 - echo_size = scsi_3btoul(&targ->dv_buffer[1]); 2634 - echo_size &= 0x1FFF; 2635 - #ifdef AHC_DEBUG 2636 - if (ahc_debug & AHC_SHOW_DV) { 2637 - ahc_print_devinfo(ahc, devinfo); 2638 - printf("Echo buffer size= %d\n", echo_size); 2639 - } 2640 - #endif 2641 - if (echo_size == 0) { 2642 - AHC_SET_DV_STATE(ahc, targ, AHC_DV_STATE_EXIT); 2643 - break; 2644 - } 2645 - 2646 - /* Generate the buffer pattern */ 2647 - targ->dv_echo_size = echo_size; 2648 - ahc_linux_generate_dv_pattern(targ); 2649 - /* 2650 - * Setup initial negotiation values. 2651 - */ 2652 - ahc_linux_filter_inquiry(ahc, devinfo); 2653 - break; 2654 - } 2655 - case SS_INQ_REFRESH: 2656 - AHC_SET_DV_STATE(ahc, targ, 2657 - AHC_DV_STATE_INQ_SHORT_ASYNC); 2658 - break; 2659 - case SS_RETRY: 2660 - AHC_SET_DV_STATE(ahc, targ, targ->dv_state); 2661 - if (ahc_cmd_get_transaction_status(cmd) 2662 - == CAM_REQUEUE_REQ) 2663 - targ->dv_state_retry--; 2664 - if (targ->dv_state_retry <= 10) 2665 - break; 2666 - #ifdef AHC_DEBUG 2667 - if (ahc_debug & AHC_SHOW_DV) { 2668 - ahc_print_devinfo(ahc, devinfo); 2669 - printf("DV REBD reties exhausted\n"); 2670 - } 2671 - #endif 2672 - /* FALLTHROUGH */ 2673 - case SS_FATAL: 2674 - default: 2675 - /* 2676 - * Setup initial negotiation values 2677 - * and try level 1 DV. 2678 - */ 2679 - ahc_linux_filter_inquiry(ahc, devinfo); 2680 - AHC_SET_DV_STATE(ahc, targ, AHC_DV_STATE_INQ_VERIFY); 2681 - targ->dv_echo_size = 0; 2682 - break; 2683 - } 2684 - break; 2685 - 2686 - case AHC_DV_STATE_WEB: 2687 - switch (status & SS_MASK) { 2688 - case SS_NOP: 2689 - AHC_SET_DV_STATE(ahc, targ, AHC_DV_STATE_REB); 2690 - break; 2691 - case SS_INQ_REFRESH: 2692 - AHC_SET_DV_STATE(ahc, targ, 2693 - AHC_DV_STATE_INQ_SHORT_ASYNC); 2694 - break; 2695 - case SS_RETRY: 2696 - AHC_SET_DV_STATE(ahc, targ, targ->dv_state); 2697 - if (ahc_cmd_get_transaction_status(cmd) 2698 - == CAM_REQUEUE_REQ) { 2699 - targ->dv_state_retry--; 2700 - } else if ((status & SSQ_FALLBACK) != 0) { 2701 - if (ahc_linux_fallback(ahc, devinfo) != 0) { 2702 - AHC_SET_DV_STATE(ahc, targ, 2703 - AHC_DV_STATE_EXIT); 2704 - break; 2705 - } 2706 - /* 2707 - * Do not count "falling back" 2708 - * against our retries. 2709 - */ 2710 - targ->dv_state_retry = 0; 2711 - } 2712 - if (targ->dv_state_retry <= 10) 2713 - break; 2714 - /* FALLTHROUGH */ 2715 - #ifdef AHC_DEBUG 2716 - if (ahc_debug & AHC_SHOW_DV) { 2717 - ahc_print_devinfo(ahc, devinfo); 2718 - printf("DV WEB reties exhausted\n"); 2719 - } 2720 - #endif 2721 - default: 2722 - AHC_SET_DV_STATE(ahc, targ, AHC_DV_STATE_EXIT); 2723 - break; 2724 - } 2725 - break; 2726 - 2727 - case AHC_DV_STATE_REB: 2728 - switch (status & SS_MASK) { 2729 - case SS_NOP: 2730 - if (memcmp(targ->dv_buffer, targ->dv_buffer1, 2731 - targ->dv_echo_size) != 0) { 2732 - if (ahc_linux_fallback(ahc, devinfo) != 0) 2733 - AHC_SET_DV_STATE(ahc, targ, 2734 - AHC_DV_STATE_EXIT); 2735 - else 2736 - AHC_SET_DV_STATE(ahc, targ, 2737 - AHC_DV_STATE_WEB); 2738 - break; 2739 - } 2740 - 2741 - if (targ->dv_buffer != NULL) { 2742 - free(targ->dv_buffer, M_DEVBUF); 2743 - targ->dv_buffer = NULL; 2744 - } 2745 - if (targ->dv_buffer1 != NULL) { 2746 - free(targ->dv_buffer1, M_DEVBUF); 2747 - targ->dv_buffer1 = NULL; 2748 - } 2749 - AHC_SET_DV_STATE(ahc, targ, AHC_DV_STATE_EXIT); 2750 - break; 2751 - case SS_INQ_REFRESH: 2752 - AHC_SET_DV_STATE(ahc, targ, 2753 - AHC_DV_STATE_INQ_SHORT_ASYNC); 2754 - break; 2755 - case SS_RETRY: 2756 - AHC_SET_DV_STATE(ahc, targ, targ->dv_state); 2757 - if (ahc_cmd_get_transaction_status(cmd) 2758 - == CAM_REQUEUE_REQ) { 2759 - targ->dv_state_retry--; 2760 - } else if ((status & SSQ_FALLBACK) != 0) { 2761 - if (ahc_linux_fallback(ahc, devinfo) != 0) { 2762 - AHC_SET_DV_STATE(ahc, targ, 2763 - AHC_DV_STATE_EXIT); 2764 - break; 2765 - } 2766 - AHC_SET_DV_STATE(ahc, targ, AHC_DV_STATE_WEB); 2767 - } 2768 - if (targ->dv_state_retry <= 10) { 2769 - if ((status & (SSQ_DELAY_RANDOM|SSQ_DELAY))!= 0) 2770 - msleep(ahc->our_id*1000/10); 2771 - break; 2772 - } 2773 - #ifdef AHC_DEBUG 2774 - if (ahc_debug & AHC_SHOW_DV) { 2775 - ahc_print_devinfo(ahc, devinfo); 2776 - printf("DV REB reties exhausted\n"); 2777 - } 2778 - #endif 2779 - /* FALLTHROUGH */ 2780 - default: 2781 - AHC_SET_DV_STATE(ahc, targ, AHC_DV_STATE_EXIT); 2782 - break; 2783 - } 2784 - break; 2785 - 2786 - case AHC_DV_STATE_SU: 2787 - switch (status & SS_MASK) { 2788 - case SS_NOP: 2789 - case SS_INQ_REFRESH: 2790 - AHC_SET_DV_STATE(ahc, targ, 2791 - AHC_DV_STATE_INQ_SHORT_ASYNC); 2792 - break; 2793 - default: 2794 - AHC_SET_DV_STATE(ahc, targ, AHC_DV_STATE_EXIT); 2795 - break; 2796 - } 2797 - break; 2798 - 2799 - case AHC_DV_STATE_BUSY: 2800 - switch (status & SS_MASK) { 2801 - case SS_NOP: 2802 - case SS_INQ_REFRESH: 2803 - AHC_SET_DV_STATE(ahc, targ, 2804 - AHC_DV_STATE_INQ_SHORT_ASYNC); 2805 - break; 2806 - case SS_TUR: 2807 - case SS_RETRY: 2808 - AHC_SET_DV_STATE(ahc, targ, targ->dv_state); 2809 - if (ahc_cmd_get_transaction_status(cmd) 2810 - == CAM_REQUEUE_REQ) { 2811 - targ->dv_state_retry--; 2812 - } else if (targ->dv_state_retry < 60) { 2813 - if ((status & SSQ_DELAY) != 0) 2814 - ssleep(1); 2815 - } else { 2816 - #ifdef AHC_DEBUG 2817 - if (ahc_debug & AHC_SHOW_DV) { 2818 - ahc_print_devinfo(ahc, devinfo); 2819 - printf("DV BUSY reties exhausted\n"); 2820 - } 2821 - #endif 2822 - AHC_SET_DV_STATE(ahc, targ, AHC_DV_STATE_EXIT); 2823 - } 2824 - break; 2825 - default: 2826 - AHC_SET_DV_STATE(ahc, targ, AHC_DV_STATE_EXIT); 2827 - break; 2828 - } 2829 - break; 2830 - 2831 - default: 2832 - printf("%s: Invalid DV completion state %d\n", ahc_name(ahc), 2833 - targ->dv_state); 2834 - AHC_SET_DV_STATE(ahc, targ, AHC_DV_STATE_EXIT); 2835 - break; 2836 - } 2837 - } 2838 - 2839 - static void 2840 - ahc_linux_dv_fill_cmd(struct ahc_softc *ahc, struct scsi_cmnd *cmd, 2841 - struct ahc_devinfo *devinfo) 2842 - { 2843 - memset(cmd, 0, sizeof(struct scsi_cmnd)); 2844 - cmd->device = ahc->platform_data->dv_scsi_dev; 2845 - cmd->scsi_done = ahc_linux_dv_complete; 2846 - } 2847 - 2848 - /* 2849 - * Synthesize an inquiry command. On the return trip, it'll be 2850 - * sniffed and the device transfer settings set for us. 2851 - */ 2852 - static void 2853 - ahc_linux_dv_inq(struct ahc_softc *ahc, struct scsi_cmnd *cmd, 2854 - struct ahc_devinfo *devinfo, struct ahc_linux_target *targ, 2855 - u_int request_length) 2856 - { 2857 - 2858 - #ifdef AHC_DEBUG 2859 - if (ahc_debug & AHC_SHOW_DV) { 2860 - ahc_print_devinfo(ahc, devinfo); 2861 - printf("Sending INQ\n"); 2862 - } 2863 - #endif 2864 - if (targ->inq_data == NULL) 2865 - targ->inq_data = malloc(AHC_LINUX_DV_INQ_LEN, 2866 - M_DEVBUF, M_WAITOK); 2867 - if (targ->dv_state > AHC_DV_STATE_INQ_ASYNC) { 2868 - if (targ->dv_buffer != NULL) 2869 - free(targ->dv_buffer, M_DEVBUF); 2870 - targ->dv_buffer = malloc(AHC_LINUX_DV_INQ_LEN, 2871 - M_DEVBUF, M_WAITOK); 2872 - } 2873 - 2874 - ahc_linux_dv_fill_cmd(ahc, cmd, devinfo); 2875 - cmd->sc_data_direction = DMA_FROM_DEVICE; 2876 - cmd->cmd_len = 6; 2877 - cmd->cmnd[0] = INQUIRY; 2878 - cmd->cmnd[4] = request_length; 2879 - cmd->request_bufflen = request_length; 2880 - if (targ->dv_state > AHC_DV_STATE_INQ_ASYNC) 2881 - cmd->request_buffer = targ->dv_buffer; 2882 - else 2883 - cmd->request_buffer = targ->inq_data; 2884 - memset(cmd->request_buffer, 0, AHC_LINUX_DV_INQ_LEN); 2885 - } 2886 - 2887 - static void 2888 - ahc_linux_dv_tur(struct ahc_softc *ahc, struct scsi_cmnd *cmd, 2889 - struct ahc_devinfo *devinfo) 2890 - { 2891 - 2892 - #ifdef AHC_DEBUG 2893 - if (ahc_debug & AHC_SHOW_DV) { 2894 - ahc_print_devinfo(ahc, devinfo); 2895 - printf("Sending TUR\n"); 2896 - } 2897 - #endif 2898 - /* Do a TUR to clear out any non-fatal transitional state */ 2899 - ahc_linux_dv_fill_cmd(ahc, cmd, devinfo); 2900 - cmd->sc_data_direction = DMA_NONE; 2901 - cmd->cmd_len = 6; 2902 - cmd->cmnd[0] = TEST_UNIT_READY; 2903 - } 2904 - 2905 - #define AHC_REBD_LEN 4 2906 - 2907 - static void 2908 - ahc_linux_dv_rebd(struct ahc_softc *ahc, struct scsi_cmnd *cmd, 2909 - struct ahc_devinfo *devinfo, struct ahc_linux_target *targ) 2910 - { 2911 - 2912 - #ifdef AHC_DEBUG 2913 - if (ahc_debug & AHC_SHOW_DV) { 2914 - ahc_print_devinfo(ahc, devinfo); 2915 - printf("Sending REBD\n"); 2916 - } 2917 - #endif 2918 - if (targ->dv_buffer != NULL) 2919 - free(targ->dv_buffer, M_DEVBUF); 2920 - targ->dv_buffer = malloc(AHC_REBD_LEN, M_DEVBUF, M_WAITOK); 2921 - ahc_linux_dv_fill_cmd(ahc, cmd, devinfo); 2922 - cmd->sc_data_direction = DMA_FROM_DEVICE; 2923 - cmd->cmd_len = 10; 2924 - cmd->cmnd[0] = READ_BUFFER; 2925 - cmd->cmnd[1] = 0x0b; 2926 - scsi_ulto3b(AHC_REBD_LEN, &cmd->cmnd[6]); 2927 - cmd->request_bufflen = AHC_REBD_LEN; 2928 - cmd->underflow = cmd->request_bufflen; 2929 - cmd->request_buffer = targ->dv_buffer; 2930 - } 2931 - 2932 - static void 2933 - ahc_linux_dv_web(struct ahc_softc *ahc, struct scsi_cmnd *cmd, 2934 - struct ahc_devinfo *devinfo, struct ahc_linux_target *targ) 2935 - { 2936 - 2937 - #ifdef AHC_DEBUG 2938 - if (ahc_debug & AHC_SHOW_DV) { 2939 - ahc_print_devinfo(ahc, devinfo); 2940 - printf("Sending WEB\n"); 2941 - } 2942 - #endif 2943 - ahc_linux_dv_fill_cmd(ahc, cmd, devinfo); 2944 - cmd->sc_data_direction = DMA_TO_DEVICE; 2945 - cmd->cmd_len = 10; 2946 - cmd->cmnd[0] = WRITE_BUFFER; 2947 - cmd->cmnd[1] = 0x0a; 2948 - scsi_ulto3b(targ->dv_echo_size, &cmd->cmnd[6]); 2949 - cmd->request_bufflen = targ->dv_echo_size; 2950 - cmd->underflow = cmd->request_bufflen; 2951 - cmd->request_buffer = targ->dv_buffer; 2952 - } 2953 - 2954 - static void 2955 - ahc_linux_dv_reb(struct ahc_softc *ahc, struct scsi_cmnd *cmd, 2956 - struct ahc_devinfo *devinfo, struct ahc_linux_target *targ) 2957 - { 2958 - 2959 - #ifdef AHC_DEBUG 2960 - if (ahc_debug & AHC_SHOW_DV) { 2961 - ahc_print_devinfo(ahc, devinfo); 2962 - printf("Sending REB\n"); 2963 - } 2964 - #endif 2965 - ahc_linux_dv_fill_cmd(ahc, cmd, devinfo); 2966 - cmd->sc_data_direction = DMA_FROM_DEVICE; 2967 - cmd->cmd_len = 10; 2968 - cmd->cmnd[0] = READ_BUFFER; 2969 - cmd->cmnd[1] = 0x0a; 2970 - scsi_ulto3b(targ->dv_echo_size, &cmd->cmnd[6]); 2971 - cmd->request_bufflen = targ->dv_echo_size; 2972 - cmd->underflow = cmd->request_bufflen; 2973 - cmd->request_buffer = targ->dv_buffer1; 2974 - } 2975 - 2976 - static void 2977 - ahc_linux_dv_su(struct ahc_softc *ahc, struct scsi_cmnd *cmd, 2978 - struct ahc_devinfo *devinfo, 2979 - struct ahc_linux_target *targ) 2980 - { 2981 - u_int le; 2982 - 2983 - le = SID_IS_REMOVABLE(targ->inq_data) ? SSS_LOEJ : 0; 2984 - 2985 - #ifdef AHC_DEBUG 2986 - if (ahc_debug & AHC_SHOW_DV) { 2987 - ahc_print_devinfo(ahc, devinfo); 2988 - printf("Sending SU\n"); 2989 - } 2990 - #endif 2991 - ahc_linux_dv_fill_cmd(ahc, cmd, devinfo); 2992 - cmd->sc_data_direction = DMA_NONE; 2993 - cmd->cmd_len = 6; 2994 - cmd->cmnd[0] = START_STOP_UNIT; 2995 - cmd->cmnd[4] = le | SSS_START; 2996 - } 2997 - 2998 - static int 2999 - ahc_linux_fallback(struct ahc_softc *ahc, struct ahc_devinfo *devinfo) 3000 - { 3001 - struct ahc_linux_target *targ; 3002 - struct ahc_initiator_tinfo *tinfo; 3003 - struct ahc_transinfo *goal; 3004 - struct ahc_tmode_tstate *tstate; 3005 - struct ahc_syncrate *syncrate; 3006 - u_long s; 3007 - u_int width; 3008 - u_int period; 3009 - u_int offset; 3010 - u_int ppr_options; 3011 - u_int cur_speed; 3012 - u_int wide_speed; 3013 - u_int narrow_speed; 3014 - u_int fallback_speed; 3015 - 3016 - #ifdef AHC_DEBUG 3017 - if (ahc_debug & AHC_SHOW_DV) { 3018 - ahc_print_devinfo(ahc, devinfo); 3019 - printf("Trying to fallback\n"); 3020 - } 3021 - #endif 3022 - ahc_lock(ahc, &s); 3023 - targ = ahc->platform_data->targets[devinfo->target_offset]; 3024 - tinfo = ahc_fetch_transinfo(ahc, devinfo->channel, 3025 - devinfo->our_scsiid, 3026 - devinfo->target, &tstate); 3027 - goal = &tinfo->goal; 3028 - width = goal->width; 3029 - period = goal->period; 3030 - offset = goal->offset; 3031 - ppr_options = goal->ppr_options; 3032 - if (offset == 0) 3033 - period = AHC_ASYNC_XFER_PERIOD; 3034 - if (targ->dv_next_narrow_period == 0) 3035 - targ->dv_next_narrow_period = MAX(period, AHC_SYNCRATE_ULTRA2); 3036 - if (targ->dv_next_wide_period == 0) 3037 - targ->dv_next_wide_period = period; 3038 - if (targ->dv_max_width == 0) 3039 - targ->dv_max_width = width; 3040 - if (targ->dv_max_ppr_options == 0) 3041 - targ->dv_max_ppr_options = ppr_options; 3042 - if (targ->dv_last_ppr_options == 0) 3043 - targ->dv_last_ppr_options = ppr_options; 3044 - 3045 - cur_speed = aic_calc_speed(width, period, offset, AHC_SYNCRATE_MIN); 3046 - wide_speed = aic_calc_speed(MSG_EXT_WDTR_BUS_16_BIT, 3047 - targ->dv_next_wide_period, 3048 - MAX_OFFSET, 3049 - AHC_SYNCRATE_MIN); 3050 - narrow_speed = aic_calc_speed(MSG_EXT_WDTR_BUS_8_BIT, 3051 - targ->dv_next_narrow_period, 3052 - MAX_OFFSET, 3053 - AHC_SYNCRATE_MIN); 3054 - fallback_speed = aic_calc_speed(width, period+1, offset, 3055 - AHC_SYNCRATE_MIN); 3056 - #ifdef AHC_DEBUG 3057 - if (ahc_debug & AHC_SHOW_DV) { 3058 - printf("cur_speed= %d, wide_speed= %d, narrow_speed= %d, " 3059 - "fallback_speed= %d\n", cur_speed, wide_speed, 3060 - narrow_speed, fallback_speed); 3061 - } 3062 - #endif 3063 - 3064 - if (cur_speed > 160000) { 3065 - /* 3066 - * Paced/DT/IU_REQ only transfer speeds. All we 3067 - * can do is fallback in terms of syncrate. 3068 - */ 3069 - period++; 3070 - } else if (cur_speed > 80000) { 3071 - if ((ppr_options & MSG_EXT_PPR_IU_REQ) != 0) { 3072 - /* 3073 - * Try without IU_REQ as it may be confusing 3074 - * an expander. 3075 - */ 3076 - ppr_options &= ~MSG_EXT_PPR_IU_REQ; 3077 - } else { 3078 - /* 3079 - * Paced/DT only transfer speeds. All we 3080 - * can do is fallback in terms of syncrate. 3081 - */ 3082 - period++; 3083 - ppr_options = targ->dv_max_ppr_options; 3084 - } 3085 - } else if (cur_speed > 3300) { 3086 - 3087 - /* 3088 - * In this range we the following 3089 - * options ordered from highest to 3090 - * lowest desireability: 3091 - * 3092 - * o Wide/DT 3093 - * o Wide/non-DT 3094 - * o Narrow at a potentally higher sync rate. 3095 - * 3096 - * All modes are tested with and without IU_REQ 3097 - * set since using IUs may confuse an expander. 3098 - */ 3099 - if ((ppr_options & MSG_EXT_PPR_IU_REQ) != 0) { 3100 - 3101 - ppr_options &= ~MSG_EXT_PPR_IU_REQ; 3102 - } else if ((ppr_options & MSG_EXT_PPR_DT_REQ) != 0) { 3103 - /* 3104 - * Try going non-DT. 3105 - */ 3106 - ppr_options = targ->dv_max_ppr_options; 3107 - ppr_options &= ~MSG_EXT_PPR_DT_REQ; 3108 - } else if (targ->dv_last_ppr_options != 0) { 3109 - /* 3110 - * Try without QAS or any other PPR options. 3111 - * We may need a non-PPR message to work with 3112 - * an expander. We look at the "last PPR options" 3113 - * so we will perform this fallback even if the 3114 - * target responded to our PPR negotiation with 3115 - * no option bits set. 3116 - */ 3117 - ppr_options = 0; 3118 - } else if (width == MSG_EXT_WDTR_BUS_16_BIT) { 3119 - /* 3120 - * If the next narrow speed is greater than 3121 - * the next wide speed, fallback to narrow. 3122 - * Otherwise fallback to the next DT/Wide setting. 3123 - * The narrow async speed will always be smaller 3124 - * than the wide async speed, so handle this case 3125 - * specifically. 3126 - */ 3127 - ppr_options = targ->dv_max_ppr_options; 3128 - if (narrow_speed > fallback_speed 3129 - || period >= AHC_ASYNC_XFER_PERIOD) { 3130 - targ->dv_next_wide_period = period+1; 3131 - width = MSG_EXT_WDTR_BUS_8_BIT; 3132 - period = targ->dv_next_narrow_period; 3133 - } else { 3134 - period++; 3135 - } 3136 - } else if ((ahc->features & AHC_WIDE) != 0 3137 - && targ->dv_max_width != 0 3138 - && wide_speed >= fallback_speed 3139 - && (targ->dv_next_wide_period <= AHC_ASYNC_XFER_PERIOD 3140 - || period >= AHC_ASYNC_XFER_PERIOD)) { 3141 - 3142 - /* 3143 - * We are narrow. Try falling back 3144 - * to the next wide speed with 3145 - * all supported ppr options set. 3146 - */ 3147 - targ->dv_next_narrow_period = period+1; 3148 - width = MSG_EXT_WDTR_BUS_16_BIT; 3149 - period = targ->dv_next_wide_period; 3150 - ppr_options = targ->dv_max_ppr_options; 3151 - } else { 3152 - /* Only narrow fallback is allowed. */ 3153 - period++; 3154 - ppr_options = targ->dv_max_ppr_options; 3155 - } 3156 - } else { 3157 - ahc_unlock(ahc, &s); 3158 - return (-1); 3159 - } 3160 - offset = MAX_OFFSET; 3161 - syncrate = ahc_find_syncrate(ahc, &period, &ppr_options, 3162 - AHC_SYNCRATE_DT); 3163 - ahc_set_width(ahc, devinfo, width, AHC_TRANS_GOAL, FALSE); 3164 - if (period == 0) { 3165 - period = 0; 3166 - offset = 0; 3167 - ppr_options = 0; 3168 - if (width == MSG_EXT_WDTR_BUS_8_BIT) 3169 - targ->dv_next_narrow_period = AHC_ASYNC_XFER_PERIOD; 3170 - else 3171 - targ->dv_next_wide_period = AHC_ASYNC_XFER_PERIOD; 3172 - } 3173 - ahc_set_syncrate(ahc, devinfo, syncrate, period, offset, 3174 - ppr_options, AHC_TRANS_GOAL, FALSE); 3175 - targ->dv_last_ppr_options = ppr_options; 3176 - ahc_unlock(ahc, &s); 3177 - return (0); 3178 - } 3179 - 3180 - static void 3181 - ahc_linux_dv_timeout(struct scsi_cmnd *cmd) 3182 - { 3183 - struct ahc_softc *ahc; 3184 - struct scb *scb; 3185 - u_long flags; 3186 - 3187 - ahc = *((struct ahc_softc **)cmd->device->host->hostdata); 3188 - ahc_lock(ahc, &flags); 3189 - 3190 - #ifdef AHC_DEBUG 3191 - if (ahc_debug & AHC_SHOW_DV) { 3192 - printf("%s: Timeout while doing DV command %x.\n", 3193 - ahc_name(ahc), cmd->cmnd[0]); 3194 - ahc_dump_card_state(ahc); 3195 - } 3196 - #endif 3197 - 3198 - /* 3199 - * Guard against "done race". No action is 3200 - * required if we just completed. 3201 - */ 3202 - if ((scb = (struct scb *)cmd->host_scribble) == NULL) { 3203 - ahc_unlock(ahc, &flags); 3204 - return; 3205 - } 3206 - 3207 - /* 3208 - * Command has not completed. Mark this 3209 - * SCB as having failing status prior to 3210 - * resetting the bus, so we get the correct 3211 - * error code. 3212 - */ 3213 - if ((scb->flags & SCB_SENSE) != 0) 3214 - ahc_set_transaction_status(scb, CAM_AUTOSENSE_FAIL); 3215 - else 3216 - ahc_set_transaction_status(scb, CAM_CMD_TIMEOUT); 3217 - ahc_reset_channel(ahc, cmd->device->channel + 'A', /*initiate*/TRUE); 3218 - 3219 - /* 3220 - * Add a minimal bus settle delay for devices that are slow to 3221 - * respond after bus resets. 3222 - */ 3223 - ahc_linux_freeze_simq(ahc); 3224 - init_timer(&ahc->platform_data->reset_timer); 3225 - ahc->platform_data->reset_timer.data = (u_long)ahc; 3226 - ahc->platform_data->reset_timer.expires = jiffies + HZ / 2; 3227 - ahc->platform_data->reset_timer.function = 3228 - (ahc_linux_callback_t *)ahc_linux_release_simq; 3229 - add_timer(&ahc->platform_data->reset_timer); 3230 - if (ahc_linux_next_device_to_run(ahc) != NULL) 3231 - ahc_schedule_runq(ahc); 3232 - ahc_linux_run_complete_queue(ahc); 3233 - ahc_unlock(ahc, &flags); 3234 - } 3235 - 3236 - static void 3237 - ahc_linux_dv_complete(struct scsi_cmnd *cmd) 3238 - { 3239 - struct ahc_softc *ahc; 3240 - 3241 - ahc = *((struct ahc_softc **)cmd->device->host->hostdata); 3242 - 3243 - /* Delete the DV timer before it goes off! */ 3244 - scsi_delete_timer(cmd); 3245 - 3246 - #ifdef AHC_DEBUG 3247 - if (ahc_debug & AHC_SHOW_DV) 3248 - printf("%s:%d:%d: Command completed, status= 0x%x\n", 3249 - ahc_name(ahc), cmd->device->channel, 3250 - cmd->device->id, cmd->result); 3251 - #endif 3252 - 3253 - /* Wake up the state machine */ 3254 - up(&ahc->platform_data->dv_cmd_sem); 3255 - } 3256 - 3257 - static void 3258 - ahc_linux_generate_dv_pattern(struct ahc_linux_target *targ) 3259 - { 3260 - uint16_t b; 3261 - u_int i; 3262 - u_int j; 3263 - 3264 - if (targ->dv_buffer != NULL) 3265 - free(targ->dv_buffer, M_DEVBUF); 3266 - targ->dv_buffer = malloc(targ->dv_echo_size, M_DEVBUF, M_WAITOK); 3267 - if (targ->dv_buffer1 != NULL) 3268 - free(targ->dv_buffer1, M_DEVBUF); 3269 - targ->dv_buffer1 = malloc(targ->dv_echo_size, M_DEVBUF, M_WAITOK); 3270 - 3271 - i = 0; 3272 - b = 0x0001; 3273 - for (j = 0 ; i < targ->dv_echo_size; j++) { 3274 - if (j < 32) { 3275 - /* 3276 - * 32bytes of sequential numbers. 3277 - */ 3278 - targ->dv_buffer[i++] = j & 0xff; 3279 - } else if (j < 48) { 3280 - /* 3281 - * 32bytes of repeating 0x0000, 0xffff. 3282 - */ 3283 - targ->dv_buffer[i++] = (j & 0x02) ? 0xff : 0x00; 3284 - } else if (j < 64) { 3285 - /* 3286 - * 32bytes of repeating 0x5555, 0xaaaa. 3287 - */ 3288 - targ->dv_buffer[i++] = (j & 0x02) ? 0xaa : 0x55; 3289 - } else { 3290 - /* 3291 - * Remaining buffer is filled with a repeating 3292 - * patter of: 3293 - * 3294 - * 0xffff 3295 - * ~0x0001 << shifted once in each loop. 3296 - */ 3297 - if (j & 0x02) { 3298 - if (j & 0x01) { 3299 - targ->dv_buffer[i++] = ~(b >> 8) & 0xff; 3300 - b <<= 1; 3301 - if (b == 0x0000) 3302 - b = 0x0001; 3303 - } else { 3304 - targ->dv_buffer[i++] = (~b & 0xff); 3305 - } 3306 - } else { 3307 - targ->dv_buffer[i++] = 0xff; 3308 - } 3309 - } 3310 - } 3311 - } 3312 - 3313 2129 static u_int 3314 2130 ahc_linux_user_tagdepth(struct ahc_softc *ahc, struct ahc_devinfo *devinfo) 3315 2131 { ··· 2014 3480 } 2015 3481 } 2016 3482 return (tags); 2017 - } 2018 - 2019 - static u_int 2020 - ahc_linux_user_dv_setting(struct ahc_softc *ahc) 2021 - { 2022 - static int warned_user; 2023 - int dv; 2024 - 2025 - if (ahc->unit >= NUM_ELEMENTS(aic7xxx_dv_settings)) { 2026 - if (warned_user == 0) { 2027 - 2028 - printf(KERN_WARNING 2029 - "aic7xxx: WARNING: Insufficient dv settings instances\n" 2030 - "aic7xxx: for installed controllers. Using defaults\n" 2031 - "aic7xxx: Please update the aic7xxx_dv_settings array\n" 2032 - "aic7xxx: in the aic7xxx_osm.c source file.\n"); 2033 - warned_user++; 2034 - } 2035 - dv = -1; 2036 - } else { 2037 - 2038 - dv = aic7xxx_dv_settings[ahc->unit]; 2039 - } 2040 - 2041 - if (dv < 0) { 2042 - u_long s; 2043 - 2044 - /* 2045 - * Apply the default. 2046 - */ 2047 - /* 2048 - * XXX - Enable DV on non-U160 controllers once it 2049 - * has been tested there. 2050 - */ 2051 - ahc_lock(ahc, &s); 2052 - dv = (ahc->features & AHC_DT); 2053 - if (ahc->seep_config != 0 2054 - && ahc->seep_config->signature >= CFSIGNATURE2) 2055 - dv = (ahc->seep_config->adapter_control & CFENABLEDV); 2056 - ahc_unlock(ahc, &s); 2057 - } 2058 - return (dv); 2059 3483 } 2060 3484 2061 3485 /* ··· 2066 3574 * Schedule us to run later. The only reason we are not 2067 3575 * running is because the whole controller Q is frozen. 2068 3576 */ 2069 - if (ahc->platform_data->qfrozen != 0 2070 - && AHC_DV_SIMQ_FROZEN(ahc) == 0) { 3577 + if (ahc->platform_data->qfrozen != 0) { 2071 3578 TAILQ_INSERT_TAIL(&ahc->platform_data->device_runq, 2072 3579 dev, links); 2073 3580 dev->flags |= AHC_DEV_ON_RUN_LIST; ··· 2106 3615 2107 3616 if ((ahc->user_discenable & mask) != 0) 2108 3617 hscb->control |= DISCENB; 2109 - 2110 - if (AHC_DV_CMD(cmd) != 0) 2111 - scb->flags |= SCB_SILENT; 2112 3618 2113 3619 if ((tstate->auto_negotiate & mask) != 0) { 2114 3620 scb->flags |= SCB_AUTO_NEGOTIATE; ··· 2299 3811 targ->channel = channel; 2300 3812 targ->target = target; 2301 3813 targ->ahc = ahc; 2302 - targ->flags = AHC_DV_REQUIRED; 2303 3814 ahc->platform_data->targets[target_offset] = targ; 2304 3815 return (targ); 2305 3816 } ··· 2337 3850 ahc->platform_data->targets[target_offset] = NULL; 2338 3851 if (targ->inq_data != NULL) 2339 3852 free(targ->inq_data, M_DEVBUF); 2340 - if (targ->dv_buffer != NULL) 2341 - free(targ->dv_buffer, M_DEVBUF); 2342 - if (targ->dv_buffer1 != NULL) 2343 - free(targ->dv_buffer1, M_DEVBUF); 2344 3853 free(targ, M_DEVBUF); 2345 3854 } 2346 3855 ··· 2383 3900 targ->devices[dev->lun] = NULL; 2384 3901 free(dev, M_DEVBUF); 2385 3902 targ->refcount--; 2386 - if (targ->refcount == 0 2387 - && (targ->flags & AHC_DV_REQUIRED) == 0) 3903 + if (targ->refcount == 0) 2388 3904 ahc_linux_free_target(ahc, targ); 2389 3905 } 2390 3906 ··· 2587 4105 ahc_linux_handle_scsi_status(ahc, dev, scb); 2588 4106 } else if (ahc_get_transaction_status(scb) == CAM_SEL_TIMEOUT) { 2589 4107 dev->flags |= AHC_DEV_UNCONFIGURED; 2590 - if (AHC_DV_CMD(cmd) == FALSE) 2591 - dev->target->flags &= ~AHC_DV_REQUIRED; 2592 4108 } 2593 - /* 2594 - * Start DV for devices that require it assuming the first command 2595 - * sent does not result in a selection timeout. 2596 - */ 2597 - if (ahc_get_transaction_status(scb) != CAM_SEL_TIMEOUT 2598 - && (dev->target->flags & AHC_DV_REQUIRED) != 0) 2599 - ahc_linux_start_dv(ahc); 2600 4109 2601 4110 if (dev->openings == 1 2602 4111 && ahc_get_transaction_status(scb) == CAM_REQ_CMP ··· 2631 4158 2632 4159 ahc_free_scb(ahc, scb); 2633 4160 ahc_linux_queue_cmd_complete(ahc, cmd); 2634 - 2635 - if ((ahc->platform_data->flags & AHC_DV_WAIT_SIMQ_EMPTY) != 0 2636 - && LIST_FIRST(&ahc->pending_scbs) == NULL) { 2637 - ahc->platform_data->flags &= ~AHC_DV_WAIT_SIMQ_EMPTY; 2638 - up(&ahc->platform_data->dv_sem); 2639 - } 2640 - 2641 4161 } 2642 4162 2643 4163 static void ··· 2807 4341 * full error information available when making 2808 4342 * state change decisions. 2809 4343 */ 2810 - if (AHC_DV_CMD(cmd) == FALSE) { 4344 + { 2811 4345 u_int new_status; 2812 4346 2813 4347 switch (ahc_cmd_get_transaction_status(cmd)) { ··· 2898 4432 } 2899 4433 2900 4434 static void 2901 - ahc_linux_filter_inquiry(struct ahc_softc *ahc, struct ahc_devinfo *devinfo) 2902 - { 2903 - struct scsi_inquiry_data *sid; 2904 - struct ahc_initiator_tinfo *tinfo; 2905 - struct ahc_transinfo *user; 2906 - struct ahc_transinfo *goal; 2907 - struct ahc_transinfo *curr; 2908 - struct ahc_tmode_tstate *tstate; 2909 - struct ahc_syncrate *syncrate; 2910 - struct ahc_linux_device *dev; 2911 - u_int maxsync; 2912 - u_int width; 2913 - u_int period; 2914 - u_int offset; 2915 - u_int ppr_options; 2916 - u_int trans_version; 2917 - u_int prot_version; 2918 - 2919 - /* 2920 - * Determine if this lun actually exists. If so, 2921 - * hold on to its corresponding device structure. 2922 - * If not, make sure we release the device and 2923 - * don't bother processing the rest of this inquiry 2924 - * command. 2925 - */ 2926 - dev = ahc_linux_get_device(ahc, devinfo->channel - 'A', 2927 - devinfo->target, devinfo->lun, 2928 - /*alloc*/TRUE); 2929 - 2930 - sid = (struct scsi_inquiry_data *)dev->target->inq_data; 2931 - if (SID_QUAL(sid) == SID_QUAL_LU_CONNECTED) { 2932 - 2933 - dev->flags &= ~AHC_DEV_UNCONFIGURED; 2934 - } else { 2935 - dev->flags |= AHC_DEV_UNCONFIGURED; 2936 - return; 2937 - } 2938 - 2939 - /* 2940 - * Update our notion of this device's transfer 2941 - * negotiation capabilities. 2942 - */ 2943 - tinfo = ahc_fetch_transinfo(ahc, devinfo->channel, 2944 - devinfo->our_scsiid, 2945 - devinfo->target, &tstate); 2946 - user = &tinfo->user; 2947 - goal = &tinfo->goal; 2948 - curr = &tinfo->curr; 2949 - width = user->width; 2950 - period = user->period; 2951 - offset = user->offset; 2952 - ppr_options = user->ppr_options; 2953 - trans_version = user->transport_version; 2954 - prot_version = MIN(user->protocol_version, SID_ANSI_REV(sid)); 2955 - 2956 - /* 2957 - * Only attempt SPI3/4 once we've verified that 2958 - * the device claims to support SPI3/4 features. 2959 - */ 2960 - if (prot_version < SCSI_REV_2) 2961 - trans_version = SID_ANSI_REV(sid); 2962 - else 2963 - trans_version = SCSI_REV_2; 2964 - 2965 - if ((sid->flags & SID_WBus16) == 0) 2966 - width = MSG_EXT_WDTR_BUS_8_BIT; 2967 - if ((sid->flags & SID_Sync) == 0) { 2968 - period = 0; 2969 - offset = 0; 2970 - ppr_options = 0; 2971 - } 2972 - if ((sid->spi3data & SID_SPI_QAS) == 0) 2973 - ppr_options &= ~MSG_EXT_PPR_QAS_REQ; 2974 - if ((sid->spi3data & SID_SPI_CLOCK_DT) == 0) 2975 - ppr_options &= MSG_EXT_PPR_QAS_REQ; 2976 - if ((sid->spi3data & SID_SPI_IUS) == 0) 2977 - ppr_options &= (MSG_EXT_PPR_DT_REQ 2978 - | MSG_EXT_PPR_QAS_REQ); 2979 - 2980 - if (prot_version > SCSI_REV_2 2981 - && ppr_options != 0) 2982 - trans_version = user->transport_version; 2983 - 2984 - ahc_validate_width(ahc, /*tinfo limit*/NULL, &width, ROLE_UNKNOWN); 2985 - if ((ahc->features & AHC_ULTRA2) != 0) 2986 - maxsync = AHC_SYNCRATE_DT; 2987 - else if ((ahc->features & AHC_ULTRA) != 0) 2988 - maxsync = AHC_SYNCRATE_ULTRA; 2989 - else 2990 - maxsync = AHC_SYNCRATE_FAST; 2991 - 2992 - syncrate = ahc_find_syncrate(ahc, &period, &ppr_options, maxsync); 2993 - ahc_validate_offset(ahc, /*tinfo limit*/NULL, syncrate, 2994 - &offset, width, ROLE_UNKNOWN); 2995 - if (offset == 0 || period == 0) { 2996 - period = 0; 2997 - offset = 0; 2998 - ppr_options = 0; 2999 - } 3000 - /* Apply our filtered user settings. */ 3001 - curr->transport_version = trans_version; 3002 - curr->protocol_version = prot_version; 3003 - ahc_set_width(ahc, devinfo, width, AHC_TRANS_GOAL, /*paused*/FALSE); 3004 - ahc_set_syncrate(ahc, devinfo, syncrate, period, 3005 - offset, ppr_options, AHC_TRANS_GOAL, 3006 - /*paused*/FALSE); 3007 - } 3008 - 3009 - static void 3010 4435 ahc_linux_sem_timeout(u_long arg) 3011 4436 { 3012 4437 struct ahc_softc *ahc; ··· 2942 4585 ahc->platform_data->qfrozen--; 2943 4586 if (ahc->platform_data->qfrozen == 0) 2944 4587 unblock_reqs = 1; 2945 - if (AHC_DV_SIMQ_FROZEN(ahc) 2946 - && ((ahc->platform_data->flags & AHC_DV_WAIT_SIMQ_RELEASE) != 0)) { 2947 - ahc->platform_data->flags &= ~AHC_DV_WAIT_SIMQ_RELEASE; 2948 - up(&ahc->platform_data->dv_sem); 2949 - } 2950 4588 ahc_schedule_runq(ahc); 2951 4589 ahc_unlock(ahc, &s); 2952 4590 /* ··· 3626 5274 static void 3627 5275 ahc_linux_exit(void) 3628 5276 { 3629 - struct ahc_softc *ahc; 3630 - 3631 - /* 3632 - * Shutdown DV threads before going into the SCSI mid-layer. 3633 - * This avoids situations where the mid-layer locks the entire 3634 - * kernel so that waiting for our DV threads to exit leads 3635 - * to deadlock. 3636 - */ 3637 - TAILQ_FOREACH(ahc, &ahc_tailq, links) { 3638 - 3639 - ahc_linux_kill_dv_thread(ahc); 3640 - } 3641 - 3642 5277 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0) 3643 5278 /* 3644 5279 * In 2.4 we have to unregister from the PCI core _after_
-40
drivers/scsi/aic7xxx/aic7xxx_osm.h
··· 424 424 }; 425 425 426 426 typedef enum { 427 - AHC_DV_REQUIRED = 0x01, 428 427 AHC_INQ_VALID = 0x02, 429 - AHC_BASIC_DV = 0x04, 430 - AHC_ENHANCED_DV = 0x08 431 428 } ahc_linux_targ_flags; 432 - 433 - /* DV States */ 434 - typedef enum { 435 - AHC_DV_STATE_EXIT = 0, 436 - AHC_DV_STATE_INQ_SHORT_ASYNC, 437 - AHC_DV_STATE_INQ_ASYNC, 438 - AHC_DV_STATE_INQ_ASYNC_VERIFY, 439 - AHC_DV_STATE_TUR, 440 - AHC_DV_STATE_REBD, 441 - AHC_DV_STATE_INQ_VERIFY, 442 - AHC_DV_STATE_WEB, 443 - AHC_DV_STATE_REB, 444 - AHC_DV_STATE_SU, 445 - AHC_DV_STATE_BUSY 446 - } ahc_dv_state; 447 429 448 430 struct ahc_linux_target { 449 431 struct ahc_linux_device *devices[AHC_NUM_LUNS]; ··· 436 454 struct ahc_softc *ahc; 437 455 ahc_linux_targ_flags flags; 438 456 struct scsi_inquiry_data *inq_data; 439 - /* 440 - * The next "fallback" period to use for narrow/wide transfers. 441 - */ 442 - uint8_t dv_next_narrow_period; 443 - uint8_t dv_next_wide_period; 444 - uint8_t dv_max_width; 445 - uint8_t dv_max_ppr_options; 446 - uint8_t dv_last_ppr_options; 447 - u_int dv_echo_size; 448 - ahc_dv_state dv_state; 449 - u_int dv_state_retry; 450 - char *dv_buffer; 451 - char *dv_buffer1; 452 457 }; 453 458 454 459 /********************* Definitions Required by the Core ***********************/ ··· 480 511 * this driver. 481 512 */ 482 513 typedef enum { 483 - AHC_DV_WAIT_SIMQ_EMPTY = 0x01, 484 - AHC_DV_WAIT_SIMQ_RELEASE = 0x02, 485 - AHC_DV_ACTIVE = 0x04, 486 - AHC_DV_SHUTDOWN = 0x08, 487 514 AHC_RUN_CMPLT_Q_TIMER = 0x10 488 515 } ahc_linux_softc_flags; 489 516 ··· 902 937 #endif 903 938 904 939 /*************************** Domain Validation ********************************/ 905 - #define AHC_DV_CMD(cmd) ((cmd)->scsi_done == ahc_linux_dv_complete) 906 - #define AHC_DV_SIMQ_FROZEN(ahc) \ 907 - ((((ahc)->platform_data->flags & AHC_DV_ACTIVE) != 0) \ 908 - && (ahc)->platform_data->qfrozen == 1) 909 - 910 940 /*********************** Transaction Access Wrappers *************************/ 911 941 static __inline void ahc_cmd_set_transaction_status(Scsi_Cmnd *, uint32_t); 912 942 static __inline void ahc_set_transaction_status(struct scb *, uint32_t);