/drivers/scsi/aic7xxx/aic79xx_osm.c

http://github.com/mirrors/linux · C · 2877 lines · 2076 code · 328 blank · 473 comment · 404 complexity · c54d73ed5603ab3e4e9a16716720a790 MD5 · raw file

Large files are truncated click here to view the full file

  1. /*
  2. * Adaptec AIC79xx device driver for Linux.
  3. *
  4. * $Id: //depot/aic7xxx/linux/drivers/scsi/aic7xxx/aic79xx_osm.c#171 $
  5. *
  6. * --------------------------------------------------------------------------
  7. * Copyright (c) 1994-2000 Justin T. Gibbs.
  8. * Copyright (c) 1997-1999 Doug Ledford
  9. * Copyright (c) 2000-2003 Adaptec Inc.
  10. * All rights reserved.
  11. *
  12. * Redistribution and use in source and binary forms, with or without
  13. * modification, are permitted provided that the following conditions
  14. * are met:
  15. * 1. Redistributions of source code must retain the above copyright
  16. * notice, this list of conditions, and the following disclaimer,
  17. * without modification.
  18. * 2. Redistributions in binary form must reproduce at minimum a disclaimer
  19. * substantially similar to the "NO WARRANTY" disclaimer below
  20. * ("Disclaimer") and any redistribution must be conditioned upon
  21. * including a substantially similar Disclaimer requirement for further
  22. * binary redistribution.
  23. * 3. Neither the names of the above-listed copyright holders nor the names
  24. * of any contributors may be used to endorse or promote products derived
  25. * from this software without specific prior written permission.
  26. *
  27. * Alternatively, this software may be distributed under the terms of the
  28. * GNU General Public License ("GPL") version 2 as published by the Free
  29. * Software Foundation.
  30. *
  31. * NO WARRANTY
  32. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  33. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  34. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
  35. * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  36. * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  37. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  38. * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  39. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
  40. * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
  41. * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  42. * POSSIBILITY OF SUCH DAMAGES.
  43. */
  44. #include "aic79xx_osm.h"
  45. #include "aic79xx_inline.h"
  46. #include <scsi/scsicam.h>
  47. static struct scsi_transport_template *ahd_linux_transport_template = NULL;
  48. #include <linux/init.h> /* __setup */
  49. #include <linux/mm.h> /* For fetching system memory size */
  50. #include <linux/blkdev.h> /* For block_size() */
  51. #include <linux/delay.h> /* For ssleep/msleep */
  52. #include <linux/device.h>
  53. #include <linux/slab.h>
  54. /*
  55. * Bucket size for counting good commands in between bad ones.
  56. */
  57. #define AHD_LINUX_ERR_THRESH 1000
  58. /*
  59. * Set this to the delay in seconds after SCSI bus reset.
  60. * Note, we honor this only for the initial bus reset.
  61. * The scsi error recovery code performs its own bus settle
  62. * delay handling for error recovery actions.
  63. */
  64. #ifdef CONFIG_AIC79XX_RESET_DELAY_MS
  65. #define AIC79XX_RESET_DELAY CONFIG_AIC79XX_RESET_DELAY_MS
  66. #else
  67. #define AIC79XX_RESET_DELAY 5000
  68. #endif
  69. /*
  70. * To change the default number of tagged transactions allowed per-device,
  71. * add a line to the lilo.conf file like:
  72. * append="aic79xx=verbose,tag_info:{{32,32,32,32},{32,32,32,32}}"
  73. * which will result in the first four devices on the first two
  74. * controllers being set to a tagged queue depth of 32.
  75. *
  76. * The tag_commands is an array of 16 to allow for wide and twin adapters.
  77. * Twin adapters will use indexes 0-7 for channel 0, and indexes 8-15
  78. * for channel 1.
  79. */
  80. typedef struct {
  81. uint16_t tag_commands[16]; /* Allow for wide/twin adapters. */
  82. } adapter_tag_info_t;
  83. /*
  84. * Modify this as you see fit for your system.
  85. *
  86. * 0 tagged queuing disabled
  87. * 1 <= n <= 253 n == max tags ever dispatched.
  88. *
  89. * The driver will throttle the number of commands dispatched to a
  90. * device if it returns queue full. For devices with a fixed maximum
  91. * queue depth, the driver will eventually determine this depth and
  92. * lock it in (a console message is printed to indicate that a lock
  93. * has occurred). On some devices, queue full is returned for a temporary
  94. * resource shortage. These devices will return queue full at varying
  95. * depths. The driver will throttle back when the queue fulls occur and
  96. * attempt to slowly increase the depth over time as the device recovers
  97. * from the resource shortage.
  98. *
  99. * In this example, the first line will disable tagged queueing for all
  100. * the devices on the first probed aic79xx adapter.
  101. *
  102. * The second line enables tagged queueing with 4 commands/LUN for IDs
  103. * (0, 2-11, 13-15), disables tagged queueing for ID 12, and tells the
  104. * driver to attempt to use up to 64 tags for ID 1.
  105. *
  106. * The third line is the same as the first line.
  107. *
  108. * The fourth line disables tagged queueing for devices 0 and 3. It
  109. * enables tagged queueing for the other IDs, with 16 commands/LUN
  110. * for IDs 1 and 4, 127 commands/LUN for ID 8, and 4 commands/LUN for
  111. * IDs 2, 5-7, and 9-15.
  112. */
  113. /*
  114. * NOTE: The below structure is for reference only, the actual structure
  115. * to modify in order to change things is just below this comment block.
  116. adapter_tag_info_t aic79xx_tag_info[] =
  117. {
  118. {{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}},
  119. {{4, 64, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 0, 4, 4, 4}},
  120. {{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}},
  121. {{0, 16, 4, 0, 16, 4, 4, 4, 127, 4, 4, 4, 4, 4, 4, 4}}
  122. };
  123. */
  124. #ifdef CONFIG_AIC79XX_CMDS_PER_DEVICE
  125. #define AIC79XX_CMDS_PER_DEVICE CONFIG_AIC79XX_CMDS_PER_DEVICE
  126. #else
  127. #define AIC79XX_CMDS_PER_DEVICE AHD_MAX_QUEUE
  128. #endif
  129. #define AIC79XX_CONFIGED_TAG_COMMANDS { \
  130. AIC79XX_CMDS_PER_DEVICE, AIC79XX_CMDS_PER_DEVICE, \
  131. AIC79XX_CMDS_PER_DEVICE, AIC79XX_CMDS_PER_DEVICE, \
  132. AIC79XX_CMDS_PER_DEVICE, AIC79XX_CMDS_PER_DEVICE, \
  133. AIC79XX_CMDS_PER_DEVICE, AIC79XX_CMDS_PER_DEVICE, \
  134. AIC79XX_CMDS_PER_DEVICE, AIC79XX_CMDS_PER_DEVICE, \
  135. AIC79XX_CMDS_PER_DEVICE, AIC79XX_CMDS_PER_DEVICE, \
  136. AIC79XX_CMDS_PER_DEVICE, AIC79XX_CMDS_PER_DEVICE, \
  137. AIC79XX_CMDS_PER_DEVICE, AIC79XX_CMDS_PER_DEVICE \
  138. }
  139. /*
  140. * By default, use the number of commands specified by
  141. * the users kernel configuration.
  142. */
  143. static adapter_tag_info_t aic79xx_tag_info[] =
  144. {
  145. {AIC79XX_CONFIGED_TAG_COMMANDS},
  146. {AIC79XX_CONFIGED_TAG_COMMANDS},
  147. {AIC79XX_CONFIGED_TAG_COMMANDS},
  148. {AIC79XX_CONFIGED_TAG_COMMANDS},
  149. {AIC79XX_CONFIGED_TAG_COMMANDS},
  150. {AIC79XX_CONFIGED_TAG_COMMANDS},
  151. {AIC79XX_CONFIGED_TAG_COMMANDS},
  152. {AIC79XX_CONFIGED_TAG_COMMANDS},
  153. {AIC79XX_CONFIGED_TAG_COMMANDS},
  154. {AIC79XX_CONFIGED_TAG_COMMANDS},
  155. {AIC79XX_CONFIGED_TAG_COMMANDS},
  156. {AIC79XX_CONFIGED_TAG_COMMANDS},
  157. {AIC79XX_CONFIGED_TAG_COMMANDS},
  158. {AIC79XX_CONFIGED_TAG_COMMANDS},
  159. {AIC79XX_CONFIGED_TAG_COMMANDS},
  160. {AIC79XX_CONFIGED_TAG_COMMANDS}
  161. };
  162. /*
  163. * The I/O cell on the chip is very configurable in respect to its analog
  164. * characteristics. Set the defaults here; they can be overriden with
  165. * the proper insmod parameters.
  166. */
  167. struct ahd_linux_iocell_opts
  168. {
  169. uint8_t precomp;
  170. uint8_t slewrate;
  171. uint8_t amplitude;
  172. };
  173. #define AIC79XX_DEFAULT_PRECOMP 0xFF
  174. #define AIC79XX_DEFAULT_SLEWRATE 0xFF
  175. #define AIC79XX_DEFAULT_AMPLITUDE 0xFF
  176. #define AIC79XX_DEFAULT_IOOPTS \
  177. { \
  178. AIC79XX_DEFAULT_PRECOMP, \
  179. AIC79XX_DEFAULT_SLEWRATE, \
  180. AIC79XX_DEFAULT_AMPLITUDE \
  181. }
  182. #define AIC79XX_PRECOMP_INDEX 0
  183. #define AIC79XX_SLEWRATE_INDEX 1
  184. #define AIC79XX_AMPLITUDE_INDEX 2
  185. static const struct ahd_linux_iocell_opts aic79xx_iocell_info[] =
  186. {
  187. AIC79XX_DEFAULT_IOOPTS,
  188. AIC79XX_DEFAULT_IOOPTS,
  189. AIC79XX_DEFAULT_IOOPTS,
  190. AIC79XX_DEFAULT_IOOPTS,
  191. AIC79XX_DEFAULT_IOOPTS,
  192. AIC79XX_DEFAULT_IOOPTS,
  193. AIC79XX_DEFAULT_IOOPTS,
  194. AIC79XX_DEFAULT_IOOPTS,
  195. AIC79XX_DEFAULT_IOOPTS,
  196. AIC79XX_DEFAULT_IOOPTS,
  197. AIC79XX_DEFAULT_IOOPTS,
  198. AIC79XX_DEFAULT_IOOPTS,
  199. AIC79XX_DEFAULT_IOOPTS,
  200. AIC79XX_DEFAULT_IOOPTS,
  201. AIC79XX_DEFAULT_IOOPTS,
  202. AIC79XX_DEFAULT_IOOPTS
  203. };
  204. /*
  205. * There should be a specific return value for this in scsi.h, but
  206. * it seems that most drivers ignore it.
  207. */
  208. #define DID_UNDERFLOW DID_ERROR
  209. void
  210. ahd_print_path(struct ahd_softc *ahd, struct scb *scb)
  211. {
  212. printk("(scsi%d:%c:%d:%d): ",
  213. ahd->platform_data->host->host_no,
  214. scb != NULL ? SCB_GET_CHANNEL(ahd, scb) : 'X',
  215. scb != NULL ? SCB_GET_TARGET(ahd, scb) : -1,
  216. scb != NULL ? SCB_GET_LUN(scb) : -1);
  217. }
  218. /*
  219. * XXX - these options apply unilaterally to _all_ adapters
  220. * cards in the system. This should be fixed. Exceptions to this
  221. * rule are noted in the comments.
  222. */
  223. /*
  224. * Skip the scsi bus reset. Non 0 make us skip the reset at startup. This
  225. * has no effect on any later resets that might occur due to things like
  226. * SCSI bus timeouts.
  227. */
  228. static uint32_t aic79xx_no_reset;
  229. /*
  230. * Should we force EXTENDED translation on a controller.
  231. * 0 == Use whatever is in the SEEPROM or default to off
  232. * 1 == Use whatever is in the SEEPROM or default to on
  233. */
  234. static uint32_t aic79xx_extended;
  235. /*
  236. * PCI bus parity checking of the Adaptec controllers. This is somewhat
  237. * dubious at best. To my knowledge, this option has never actually
  238. * solved a PCI parity problem, but on certain machines with broken PCI
  239. * chipset configurations, it can generate tons of false error messages.
  240. * It's included in the driver for completeness.
  241. * 0 = Shut off PCI parity check
  242. * non-0 = Enable PCI parity check
  243. *
  244. * NOTE: you can't actually pass -1 on the lilo prompt. So, to set this
  245. * variable to -1 you would actually want to simply pass the variable
  246. * name without a number. That will invert the 0 which will result in
  247. * -1.
  248. */
  249. static uint32_t aic79xx_pci_parity = ~0;
  250. /*
  251. * There are lots of broken chipsets in the world. Some of them will
  252. * violate the PCI spec when we issue byte sized memory writes to our
  253. * controller. I/O mapped register access, if allowed by the given
  254. * platform, will work in almost all cases.
  255. */
  256. uint32_t aic79xx_allow_memio = ~0;
  257. /*
  258. * So that we can set how long each device is given as a selection timeout.
  259. * The table of values goes like this:
  260. * 0 - 256ms
  261. * 1 - 128ms
  262. * 2 - 64ms
  263. * 3 - 32ms
  264. * We default to 256ms because some older devices need a longer time
  265. * to respond to initial selection.
  266. */
  267. static uint32_t aic79xx_seltime;
  268. /*
  269. * Certain devices do not perform any aging on commands. Should the
  270. * device be saturated by commands in one portion of the disk, it is
  271. * possible for transactions on far away sectors to never be serviced.
  272. * To handle these devices, we can periodically send an ordered tag to
  273. * force all outstanding transactions to be serviced prior to a new
  274. * transaction.
  275. */
  276. static uint32_t aic79xx_periodic_otag;
  277. /* Some storage boxes are using an LSI chip which has a bug making it
  278. * impossible to use aic79xx Rev B chip in 320 speeds. The following
  279. * storage boxes have been reported to be buggy:
  280. * EonStor 3U 16-Bay: U16U-G3A3
  281. * EonStor 2U 12-Bay: U12U-G3A3
  282. * SentinelRAID: 2500F R5 / R6
  283. * SentinelRAID: 2500F R1
  284. * SentinelRAID: 2500F/1500F
  285. * SentinelRAID: 150F
  286. *
  287. * To get around this LSI bug, you can set your board to 160 mode
  288. * or you can enable the SLOWCRC bit.
  289. */
  290. uint32_t aic79xx_slowcrc;
  291. /*
  292. * Module information and settable options.
  293. */
  294. static char *aic79xx = NULL;
  295. MODULE_AUTHOR("Maintainer: Hannes Reinecke <hare@suse.de>");
  296. MODULE_DESCRIPTION("Adaptec AIC790X U320 SCSI Host Bus Adapter driver");
  297. MODULE_LICENSE("Dual BSD/GPL");
  298. MODULE_VERSION(AIC79XX_DRIVER_VERSION);
  299. module_param(aic79xx, charp, 0444);
  300. MODULE_PARM_DESC(aic79xx,
  301. "period-delimited options string:\n"
  302. " verbose Enable verbose/diagnostic logging\n"
  303. " allow_memio Allow device registers to be memory mapped\n"
  304. " debug Bitmask of debug values to enable\n"
  305. " no_reset Suppress initial bus resets\n"
  306. " extended Enable extended geometry on all controllers\n"
  307. " periodic_otag Send an ordered tagged transaction\n"
  308. " periodically to prevent tag starvation.\n"
  309. " This may be required by some older disk\n"
  310. " or drives/RAID arrays.\n"
  311. " tag_info:<tag_str> Set per-target tag depth\n"
  312. " global_tag_depth:<int> Global tag depth for all targets on all buses\n"
  313. " slewrate:<slewrate_list>Set the signal slew rate (0-15).\n"
  314. " precomp:<pcomp_list> Set the signal precompensation (0-7).\n"
  315. " amplitude:<int> Set the signal amplitude (0-7).\n"
  316. " seltime:<int> Selection Timeout:\n"
  317. " (0/256ms,1/128ms,2/64ms,3/32ms)\n"
  318. " slowcrc Turn on the SLOWCRC bit (Rev B only)\n"
  319. "\n"
  320. " Sample modprobe configuration file:\n"
  321. " # Enable verbose logging\n"
  322. " # Set tag depth on Controller 2/Target 2 to 10 tags\n"
  323. " # Shorten the selection timeout to 128ms\n"
  324. "\n"
  325. " options aic79xx 'aic79xx=verbose.tag_info:{{}.{}.{..10}}.seltime:1'\n"
  326. );
  327. static void ahd_linux_handle_scsi_status(struct ahd_softc *,
  328. struct scsi_device *,
  329. struct scb *);
  330. static void ahd_linux_queue_cmd_complete(struct ahd_softc *ahd,
  331. struct scsi_cmnd *cmd);
  332. static int ahd_linux_queue_abort_cmd(struct scsi_cmnd *cmd);
  333. static void ahd_linux_initialize_scsi_bus(struct ahd_softc *ahd);
  334. static u_int ahd_linux_user_tagdepth(struct ahd_softc *ahd,
  335. struct ahd_devinfo *devinfo);
  336. static void ahd_linux_device_queue_depth(struct scsi_device *);
  337. static int ahd_linux_run_command(struct ahd_softc*,
  338. struct ahd_linux_device *,
  339. struct scsi_cmnd *);
  340. static void ahd_linux_setup_tag_info_global(char *p);
  341. static int aic79xx_setup(char *c);
  342. static void ahd_freeze_simq(struct ahd_softc *ahd);
  343. static void ahd_release_simq(struct ahd_softc *ahd);
  344. static int ahd_linux_unit;
  345. /************************** OS Utility Wrappers *******************************/
  346. void ahd_delay(long);
  347. void
  348. ahd_delay(long usec)
  349. {
  350. /*
  351. * udelay on Linux can have problems for
  352. * multi-millisecond waits. Wait at most
  353. * 1024us per call.
  354. */
  355. while (usec > 0) {
  356. udelay(usec % 1024);
  357. usec -= 1024;
  358. }
  359. }
  360. /***************************** Low Level I/O **********************************/
  361. uint8_t ahd_inb(struct ahd_softc * ahd, long port);
  362. void ahd_outb(struct ahd_softc * ahd, long port, uint8_t val);
  363. void ahd_outw_atomic(struct ahd_softc * ahd,
  364. long port, uint16_t val);
  365. void ahd_outsb(struct ahd_softc * ahd, long port,
  366. uint8_t *, int count);
  367. void ahd_insb(struct ahd_softc * ahd, long port,
  368. uint8_t *, int count);
  369. uint8_t
  370. ahd_inb(struct ahd_softc * ahd, long port)
  371. {
  372. uint8_t x;
  373. if (ahd->tags[0] == BUS_SPACE_MEMIO) {
  374. x = readb(ahd->bshs[0].maddr + port);
  375. } else {
  376. x = inb(ahd->bshs[(port) >> 8].ioport + ((port) & 0xFF));
  377. }
  378. mb();
  379. return (x);
  380. }
  381. #if 0 /* unused */
  382. static uint16_t
  383. ahd_inw_atomic(struct ahd_softc * ahd, long port)
  384. {
  385. uint8_t x;
  386. if (ahd->tags[0] == BUS_SPACE_MEMIO) {
  387. x = readw(ahd->bshs[0].maddr + port);
  388. } else {
  389. x = inw(ahd->bshs[(port) >> 8].ioport + ((port) & 0xFF));
  390. }
  391. mb();
  392. return (x);
  393. }
  394. #endif
  395. void
  396. ahd_outb(struct ahd_softc * ahd, long port, uint8_t val)
  397. {
  398. if (ahd->tags[0] == BUS_SPACE_MEMIO) {
  399. writeb(val, ahd->bshs[0].maddr + port);
  400. } else {
  401. outb(val, ahd->bshs[(port) >> 8].ioport + (port & 0xFF));
  402. }
  403. mb();
  404. }
  405. void
  406. ahd_outw_atomic(struct ahd_softc * ahd, long port, uint16_t val)
  407. {
  408. if (ahd->tags[0] == BUS_SPACE_MEMIO) {
  409. writew(val, ahd->bshs[0].maddr + port);
  410. } else {
  411. outw(val, ahd->bshs[(port) >> 8].ioport + (port & 0xFF));
  412. }
  413. mb();
  414. }
  415. void
  416. ahd_outsb(struct ahd_softc * ahd, long port, uint8_t *array, int count)
  417. {
  418. int i;
  419. /*
  420. * There is probably a more efficient way to do this on Linux
  421. * but we don't use this for anything speed critical and this
  422. * should work.
  423. */
  424. for (i = 0; i < count; i++)
  425. ahd_outb(ahd, port, *array++);
  426. }
  427. void
  428. ahd_insb(struct ahd_softc * ahd, long port, uint8_t *array, int count)
  429. {
  430. int i;
  431. /*
  432. * There is probably a more efficient way to do this on Linux
  433. * but we don't use this for anything speed critical and this
  434. * should work.
  435. */
  436. for (i = 0; i < count; i++)
  437. *array++ = ahd_inb(ahd, port);
  438. }
  439. /******************************* PCI Routines *********************************/
  440. uint32_t
  441. ahd_pci_read_config(ahd_dev_softc_t pci, int reg, int width)
  442. {
  443. switch (width) {
  444. case 1:
  445. {
  446. uint8_t retval;
  447. pci_read_config_byte(pci, reg, &retval);
  448. return (retval);
  449. }
  450. case 2:
  451. {
  452. uint16_t retval;
  453. pci_read_config_word(pci, reg, &retval);
  454. return (retval);
  455. }
  456. case 4:
  457. {
  458. uint32_t retval;
  459. pci_read_config_dword(pci, reg, &retval);
  460. return (retval);
  461. }
  462. default:
  463. panic("ahd_pci_read_config: Read size too big");
  464. /* NOTREACHED */
  465. return (0);
  466. }
  467. }
  468. void
  469. ahd_pci_write_config(ahd_dev_softc_t pci, int reg, uint32_t value, int width)
  470. {
  471. switch (width) {
  472. case 1:
  473. pci_write_config_byte(pci, reg, value);
  474. break;
  475. case 2:
  476. pci_write_config_word(pci, reg, value);
  477. break;
  478. case 4:
  479. pci_write_config_dword(pci, reg, value);
  480. break;
  481. default:
  482. panic("ahd_pci_write_config: Write size too big");
  483. /* NOTREACHED */
  484. }
  485. }
  486. /****************************** Inlines ***************************************/
  487. static void ahd_linux_unmap_scb(struct ahd_softc*, struct scb*);
  488. static void
  489. ahd_linux_unmap_scb(struct ahd_softc *ahd, struct scb *scb)
  490. {
  491. struct scsi_cmnd *cmd;
  492. cmd = scb->io_ctx;
  493. ahd_sync_sglist(ahd, scb, BUS_DMASYNC_POSTWRITE);
  494. scsi_dma_unmap(cmd);
  495. }
  496. /******************************** Macros **************************************/
  497. #define BUILD_SCSIID(ahd, cmd) \
  498. (((scmd_id(cmd) << TID_SHIFT) & TID) | (ahd)->our_id)
  499. /*
  500. * Return a string describing the driver.
  501. */
  502. static const char *
  503. ahd_linux_info(struct Scsi_Host *host)
  504. {
  505. static char buffer[512];
  506. char ahd_info[256];
  507. char *bp;
  508. struct ahd_softc *ahd;
  509. bp = &buffer[0];
  510. ahd = *(struct ahd_softc **)host->hostdata;
  511. memset(bp, 0, sizeof(buffer));
  512. strcpy(bp, "Adaptec AIC79XX PCI-X SCSI HBA DRIVER, Rev " AIC79XX_DRIVER_VERSION "\n"
  513. " <");
  514. strcat(bp, ahd->description);
  515. strcat(bp, ">\n"
  516. " ");
  517. ahd_controller_info(ahd, ahd_info);
  518. strcat(bp, ahd_info);
  519. return (bp);
  520. }
  521. /*
  522. * Queue an SCB to the controller.
  523. */
  524. static int
  525. ahd_linux_queue_lck(struct scsi_cmnd * cmd, void (*scsi_done) (struct scsi_cmnd *))
  526. {
  527. struct ahd_softc *ahd;
  528. struct ahd_linux_device *dev = scsi_transport_device_data(cmd->device);
  529. int rtn = SCSI_MLQUEUE_HOST_BUSY;
  530. ahd = *(struct ahd_softc **)cmd->device->host->hostdata;
  531. cmd->scsi_done = scsi_done;
  532. cmd->result = CAM_REQ_INPROG << 16;
  533. rtn = ahd_linux_run_command(ahd, dev, cmd);
  534. return rtn;
  535. }
  536. static DEF_SCSI_QCMD(ahd_linux_queue)
  537. static struct scsi_target **
  538. ahd_linux_target_in_softc(struct scsi_target *starget)
  539. {
  540. struct ahd_softc *ahd =
  541. *((struct ahd_softc **)dev_to_shost(&starget->dev)->hostdata);
  542. unsigned int target_offset;
  543. target_offset = starget->id;
  544. if (starget->channel != 0)
  545. target_offset += 8;
  546. return &ahd->platform_data->starget[target_offset];
  547. }
  548. static int
  549. ahd_linux_target_alloc(struct scsi_target *starget)
  550. {
  551. struct ahd_softc *ahd =
  552. *((struct ahd_softc **)dev_to_shost(&starget->dev)->hostdata);
  553. struct seeprom_config *sc = ahd->seep_config;
  554. unsigned long flags;
  555. struct scsi_target **ahd_targp = ahd_linux_target_in_softc(starget);
  556. struct ahd_devinfo devinfo;
  557. struct ahd_initiator_tinfo *tinfo;
  558. struct ahd_tmode_tstate *tstate;
  559. char channel = starget->channel + 'A';
  560. ahd_lock(ahd, &flags);
  561. BUG_ON(*ahd_targp != NULL);
  562. *ahd_targp = starget;
  563. if (sc) {
  564. int flags = sc->device_flags[starget->id];
  565. tinfo = ahd_fetch_transinfo(ahd, 'A', ahd->our_id,
  566. starget->id, &tstate);
  567. if ((flags & CFPACKETIZED) == 0) {
  568. /* don't negotiate packetized (IU) transfers */
  569. spi_max_iu(starget) = 0;
  570. } else {
  571. if ((ahd->features & AHD_RTI) == 0)
  572. spi_rti(starget) = 0;
  573. }
  574. if ((flags & CFQAS) == 0)
  575. spi_max_qas(starget) = 0;
  576. /* Transinfo values have been set to BIOS settings */
  577. spi_max_width(starget) = (flags & CFWIDEB) ? 1 : 0;
  578. spi_min_period(starget) = tinfo->user.period;
  579. spi_max_offset(starget) = tinfo->user.offset;
  580. }
  581. tinfo = ahd_fetch_transinfo(ahd, channel, ahd->our_id,
  582. starget->id, &tstate);
  583. ahd_compile_devinfo(&devinfo, ahd->our_id, starget->id,
  584. CAM_LUN_WILDCARD, channel,
  585. ROLE_INITIATOR);
  586. ahd_set_syncrate(ahd, &devinfo, 0, 0, 0,
  587. AHD_TRANS_GOAL, /*paused*/FALSE);
  588. ahd_set_width(ahd, &devinfo, MSG_EXT_WDTR_BUS_8_BIT,
  589. AHD_TRANS_GOAL, /*paused*/FALSE);
  590. ahd_unlock(ahd, &flags);
  591. return 0;
  592. }
  593. static void
  594. ahd_linux_target_destroy(struct scsi_target *starget)
  595. {
  596. struct scsi_target **ahd_targp = ahd_linux_target_in_softc(starget);
  597. *ahd_targp = NULL;
  598. }
  599. static int
  600. ahd_linux_slave_alloc(struct scsi_device *sdev)
  601. {
  602. struct ahd_softc *ahd =
  603. *((struct ahd_softc **)sdev->host->hostdata);
  604. struct ahd_linux_device *dev;
  605. if (bootverbose)
  606. printk("%s: Slave Alloc %d\n", ahd_name(ahd), sdev->id);
  607. dev = scsi_transport_device_data(sdev);
  608. memset(dev, 0, sizeof(*dev));
  609. /*
  610. * We start out life using untagged
  611. * transactions of which we allow one.
  612. */
  613. dev->openings = 1;
  614. /*
  615. * Set maxtags to 0. This will be changed if we
  616. * later determine that we are dealing with
  617. * a tagged queuing capable device.
  618. */
  619. dev->maxtags = 0;
  620. return (0);
  621. }
  622. static int
  623. ahd_linux_slave_configure(struct scsi_device *sdev)
  624. {
  625. struct ahd_softc *ahd;
  626. ahd = *((struct ahd_softc **)sdev->host->hostdata);
  627. if (bootverbose)
  628. sdev_printk(KERN_INFO, sdev, "Slave Configure\n");
  629. ahd_linux_device_queue_depth(sdev);
  630. /* Initial Domain Validation */
  631. if (!spi_initial_dv(sdev->sdev_target))
  632. spi_dv_device(sdev);
  633. return 0;
  634. }
  635. #if defined(__i386__)
  636. /*
  637. * Return the disk geometry for the given SCSI device.
  638. */
  639. static int
  640. ahd_linux_biosparam(struct scsi_device *sdev, struct block_device *bdev,
  641. sector_t capacity, int geom[])
  642. {
  643. int heads;
  644. int sectors;
  645. int cylinders;
  646. int extended;
  647. struct ahd_softc *ahd;
  648. ahd = *((struct ahd_softc **)sdev->host->hostdata);
  649. if (scsi_partsize(bdev, capacity, geom))
  650. return 0;
  651. heads = 64;
  652. sectors = 32;
  653. cylinders = aic_sector_div(capacity, heads, sectors);
  654. if (aic79xx_extended != 0)
  655. extended = 1;
  656. else
  657. extended = (ahd->flags & AHD_EXTENDED_TRANS_A) != 0;
  658. if (extended && cylinders >= 1024) {
  659. heads = 255;
  660. sectors = 63;
  661. cylinders = aic_sector_div(capacity, heads, sectors);
  662. }
  663. geom[0] = heads;
  664. geom[1] = sectors;
  665. geom[2] = cylinders;
  666. return (0);
  667. }
  668. #endif
  669. /*
  670. * Abort the current SCSI command(s).
  671. */
  672. static int
  673. ahd_linux_abort(struct scsi_cmnd *cmd)
  674. {
  675. int error;
  676. error = ahd_linux_queue_abort_cmd(cmd);
  677. return error;
  678. }
  679. /*
  680. * Attempt to send a target reset message to the device that timed out.
  681. */
  682. static int
  683. ahd_linux_dev_reset(struct scsi_cmnd *cmd)
  684. {
  685. struct ahd_softc *ahd;
  686. struct ahd_linux_device *dev;
  687. struct scb *reset_scb;
  688. u_int cdb_byte;
  689. int retval = SUCCESS;
  690. int paused;
  691. int wait;
  692. struct ahd_initiator_tinfo *tinfo;
  693. struct ahd_tmode_tstate *tstate;
  694. unsigned long flags;
  695. DECLARE_COMPLETION_ONSTACK(done);
  696. reset_scb = NULL;
  697. paused = FALSE;
  698. wait = FALSE;
  699. ahd = *(struct ahd_softc **)cmd->device->host->hostdata;
  700. scmd_printk(KERN_INFO, cmd,
  701. "Attempting to queue a TARGET RESET message:");
  702. printk("CDB:");
  703. for (cdb_byte = 0; cdb_byte < cmd->cmd_len; cdb_byte++)
  704. printk(" 0x%x", cmd->cmnd[cdb_byte]);
  705. printk("\n");
  706. /*
  707. * Determine if we currently own this command.
  708. */
  709. dev = scsi_transport_device_data(cmd->device);
  710. if (dev == NULL) {
  711. /*
  712. * No target device for this command exists,
  713. * so we must not still own the command.
  714. */
  715. scmd_printk(KERN_INFO, cmd, "Is not an active device\n");
  716. return SUCCESS;
  717. }
  718. /*
  719. * Generate us a new SCB
  720. */
  721. reset_scb = ahd_get_scb(ahd, AHD_NEVER_COL_IDX);
  722. if (!reset_scb) {
  723. scmd_printk(KERN_INFO, cmd, "No SCB available\n");
  724. return FAILED;
  725. }
  726. tinfo = ahd_fetch_transinfo(ahd, 'A', ahd->our_id,
  727. cmd->device->id, &tstate);
  728. reset_scb->io_ctx = cmd;
  729. reset_scb->platform_data->dev = dev;
  730. reset_scb->sg_count = 0;
  731. ahd_set_residual(reset_scb, 0);
  732. ahd_set_sense_residual(reset_scb, 0);
  733. reset_scb->platform_data->xfer_len = 0;
  734. reset_scb->hscb->control = 0;
  735. reset_scb->hscb->scsiid = BUILD_SCSIID(ahd,cmd);
  736. reset_scb->hscb->lun = cmd->device->lun;
  737. reset_scb->hscb->cdb_len = 0;
  738. reset_scb->hscb->task_management = SIU_TASKMGMT_LUN_RESET;
  739. reset_scb->flags |= SCB_DEVICE_RESET|SCB_RECOVERY_SCB|SCB_ACTIVE;
  740. if ((tinfo->curr.ppr_options & MSG_EXT_PPR_IU_REQ) != 0) {
  741. reset_scb->flags |= SCB_PACKETIZED;
  742. } else {
  743. reset_scb->hscb->control |= MK_MESSAGE;
  744. }
  745. dev->openings--;
  746. dev->active++;
  747. dev->commands_issued++;
  748. ahd_lock(ahd, &flags);
  749. LIST_INSERT_HEAD(&ahd->pending_scbs, reset_scb, pending_links);
  750. ahd_queue_scb(ahd, reset_scb);
  751. ahd->platform_data->eh_done = &done;
  752. ahd_unlock(ahd, &flags);
  753. printk("%s: Device reset code sleeping\n", ahd_name(ahd));
  754. if (!wait_for_completion_timeout(&done, 5 * HZ)) {
  755. ahd_lock(ahd, &flags);
  756. ahd->platform_data->eh_done = NULL;
  757. ahd_unlock(ahd, &flags);
  758. printk("%s: Device reset timer expired (active %d)\n",
  759. ahd_name(ahd), dev->active);
  760. retval = FAILED;
  761. }
  762. printk("%s: Device reset returning 0x%x\n", ahd_name(ahd), retval);
  763. return (retval);
  764. }
  765. /*
  766. * Reset the SCSI bus.
  767. */
  768. static int
  769. ahd_linux_bus_reset(struct scsi_cmnd *cmd)
  770. {
  771. struct ahd_softc *ahd;
  772. int found;
  773. unsigned long flags;
  774. ahd = *(struct ahd_softc **)cmd->device->host->hostdata;
  775. #ifdef AHD_DEBUG
  776. if ((ahd_debug & AHD_SHOW_RECOVERY) != 0)
  777. printk("%s: Bus reset called for cmd %p\n",
  778. ahd_name(ahd), cmd);
  779. #endif
  780. ahd_lock(ahd, &flags);
  781. found = ahd_reset_channel(ahd, scmd_channel(cmd) + 'A',
  782. /*initiate reset*/TRUE);
  783. ahd_unlock(ahd, &flags);
  784. if (bootverbose)
  785. printk("%s: SCSI bus reset delivered. "
  786. "%d SCBs aborted.\n", ahd_name(ahd), found);
  787. return (SUCCESS);
  788. }
  789. struct scsi_host_template aic79xx_driver_template = {
  790. .module = THIS_MODULE,
  791. .name = "aic79xx",
  792. .proc_name = "aic79xx",
  793. .show_info = ahd_linux_show_info,
  794. .write_info = ahd_proc_write_seeprom,
  795. .info = ahd_linux_info,
  796. .queuecommand = ahd_linux_queue,
  797. .eh_abort_handler = ahd_linux_abort,
  798. .eh_device_reset_handler = ahd_linux_dev_reset,
  799. .eh_bus_reset_handler = ahd_linux_bus_reset,
  800. #if defined(__i386__)
  801. .bios_param = ahd_linux_biosparam,
  802. #endif
  803. .can_queue = AHD_MAX_QUEUE,
  804. .this_id = -1,
  805. .max_sectors = 8192,
  806. .cmd_per_lun = 2,
  807. .slave_alloc = ahd_linux_slave_alloc,
  808. .slave_configure = ahd_linux_slave_configure,
  809. .target_alloc = ahd_linux_target_alloc,
  810. .target_destroy = ahd_linux_target_destroy,
  811. };
  812. /******************************** Bus DMA *************************************/
  813. int
  814. ahd_dma_tag_create(struct ahd_softc *ahd, bus_dma_tag_t parent,
  815. bus_size_t alignment, bus_size_t boundary,
  816. dma_addr_t lowaddr, dma_addr_t highaddr,
  817. bus_dma_filter_t *filter, void *filterarg,
  818. bus_size_t maxsize, int nsegments,
  819. bus_size_t maxsegsz, int flags, bus_dma_tag_t *ret_tag)
  820. {
  821. bus_dma_tag_t dmat;
  822. dmat = kmalloc(sizeof(*dmat), GFP_ATOMIC);
  823. if (dmat == NULL)
  824. return (ENOMEM);
  825. /*
  826. * Linux is very simplistic about DMA memory. For now don't
  827. * maintain all specification information. Once Linux supplies
  828. * better facilities for doing these operations, or the
  829. * needs of this particular driver change, we might need to do
  830. * more here.
  831. */
  832. dmat->alignment = alignment;
  833. dmat->boundary = boundary;
  834. dmat->maxsize = maxsize;
  835. *ret_tag = dmat;
  836. return (0);
  837. }
  838. void
  839. ahd_dma_tag_destroy(struct ahd_softc *ahd, bus_dma_tag_t dmat)
  840. {
  841. kfree(dmat);
  842. }
  843. int
  844. ahd_dmamem_alloc(struct ahd_softc *ahd, bus_dma_tag_t dmat, void** vaddr,
  845. int flags, bus_dmamap_t *mapp)
  846. {
  847. *vaddr = pci_alloc_consistent(ahd->dev_softc,
  848. dmat->maxsize, mapp);
  849. if (*vaddr == NULL)
  850. return (ENOMEM);
  851. return(0);
  852. }
  853. void
  854. ahd_dmamem_free(struct ahd_softc *ahd, bus_dma_tag_t dmat,
  855. void* vaddr, bus_dmamap_t map)
  856. {
  857. pci_free_consistent(ahd->dev_softc, dmat->maxsize,
  858. vaddr, map);
  859. }
  860. int
  861. ahd_dmamap_load(struct ahd_softc *ahd, bus_dma_tag_t dmat, bus_dmamap_t map,
  862. void *buf, bus_size_t buflen, bus_dmamap_callback_t *cb,
  863. void *cb_arg, int flags)
  864. {
  865. /*
  866. * Assume for now that this will only be used during
  867. * initialization and not for per-transaction buffer mapping.
  868. */
  869. bus_dma_segment_t stack_sg;
  870. stack_sg.ds_addr = map;
  871. stack_sg.ds_len = dmat->maxsize;
  872. cb(cb_arg, &stack_sg, /*nseg*/1, /*error*/0);
  873. return (0);
  874. }
  875. void
  876. ahd_dmamap_destroy(struct ahd_softc *ahd, bus_dma_tag_t dmat, bus_dmamap_t map)
  877. {
  878. }
  879. int
  880. ahd_dmamap_unload(struct ahd_softc *ahd, bus_dma_tag_t dmat, bus_dmamap_t map)
  881. {
  882. /* Nothing to do */
  883. return (0);
  884. }
  885. /********************* Platform Dependent Functions ***************************/
  886. static void
  887. ahd_linux_setup_iocell_info(u_long index, int instance, int targ, int32_t value)
  888. {
  889. if ((instance >= 0)
  890. && (instance < ARRAY_SIZE(aic79xx_iocell_info))) {
  891. uint8_t *iocell_info;
  892. iocell_info = (uint8_t*)&aic79xx_iocell_info[instance];
  893. iocell_info[index] = value & 0xFFFF;
  894. if (bootverbose)
  895. printk("iocell[%d:%ld] = %d\n", instance, index, value);
  896. }
  897. }
  898. static void
  899. ahd_linux_setup_tag_info_global(char *p)
  900. {
  901. int tags, i, j;
  902. tags = simple_strtoul(p + 1, NULL, 0) & 0xff;
  903. printk("Setting Global Tags= %d\n", tags);
  904. for (i = 0; i < ARRAY_SIZE(aic79xx_tag_info); i++) {
  905. for (j = 0; j < AHD_NUM_TARGETS; j++) {
  906. aic79xx_tag_info[i].tag_commands[j] = tags;
  907. }
  908. }
  909. }
  910. static void
  911. ahd_linux_setup_tag_info(u_long arg, int instance, int targ, int32_t value)
  912. {
  913. if ((instance >= 0) && (targ >= 0)
  914. && (instance < ARRAY_SIZE(aic79xx_tag_info))
  915. && (targ < AHD_NUM_TARGETS)) {
  916. aic79xx_tag_info[instance].tag_commands[targ] = value & 0x1FF;
  917. if (bootverbose)
  918. printk("tag_info[%d:%d] = %d\n", instance, targ, value);
  919. }
  920. }
  921. static char *
  922. ahd_parse_brace_option(char *opt_name, char *opt_arg, char *end, int depth,
  923. void (*callback)(u_long, int, int, int32_t),
  924. u_long callback_arg)
  925. {
  926. char *tok_end;
  927. char *tok_end2;
  928. int i;
  929. int instance;
  930. int targ;
  931. int done;
  932. char tok_list[] = {'.', ',', '{', '}', '\0'};
  933. /* All options use a ':' name/arg separator */
  934. if (*opt_arg != ':')
  935. return (opt_arg);
  936. opt_arg++;
  937. instance = -1;
  938. targ = -1;
  939. done = FALSE;
  940. /*
  941. * Restore separator that may be in
  942. * the middle of our option argument.
  943. */
  944. tok_end = strchr(opt_arg, '\0');
  945. if (tok_end < end)
  946. *tok_end = ',';
  947. while (!done) {
  948. switch (*opt_arg) {
  949. case '{':
  950. if (instance == -1) {
  951. instance = 0;
  952. } else {
  953. if (depth > 1) {
  954. if (targ == -1)
  955. targ = 0;
  956. } else {
  957. printk("Malformed Option %s\n",
  958. opt_name);
  959. done = TRUE;
  960. }
  961. }
  962. opt_arg++;
  963. break;
  964. case '}':
  965. if (targ != -1)
  966. targ = -1;
  967. else if (instance != -1)
  968. instance = -1;
  969. opt_arg++;
  970. break;
  971. case ',':
  972. case '.':
  973. if (instance == -1)
  974. done = TRUE;
  975. else if (targ >= 0)
  976. targ++;
  977. else if (instance >= 0)
  978. instance++;
  979. opt_arg++;
  980. break;
  981. case '\0':
  982. done = TRUE;
  983. break;
  984. default:
  985. tok_end = end;
  986. for (i = 0; tok_list[i]; i++) {
  987. tok_end2 = strchr(opt_arg, tok_list[i]);
  988. if ((tok_end2) && (tok_end2 < tok_end))
  989. tok_end = tok_end2;
  990. }
  991. callback(callback_arg, instance, targ,
  992. simple_strtol(opt_arg, NULL, 0));
  993. opt_arg = tok_end;
  994. break;
  995. }
  996. }
  997. return (opt_arg);
  998. }
  999. /*
  1000. * Handle Linux boot parameters. This routine allows for assigning a value
  1001. * to a parameter with a ':' between the parameter and the value.
  1002. * ie. aic79xx=stpwlev:1,extended
  1003. */
  1004. static int
  1005. aic79xx_setup(char *s)
  1006. {
  1007. int i, n;
  1008. char *p;
  1009. char *end;
  1010. static const struct {
  1011. const char *name;
  1012. uint32_t *flag;
  1013. } options[] = {
  1014. { "extended", &aic79xx_extended },
  1015. { "no_reset", &aic79xx_no_reset },
  1016. { "verbose", &aic79xx_verbose },
  1017. { "allow_memio", &aic79xx_allow_memio},
  1018. #ifdef AHD_DEBUG
  1019. { "debug", &ahd_debug },
  1020. #endif
  1021. { "periodic_otag", &aic79xx_periodic_otag },
  1022. { "pci_parity", &aic79xx_pci_parity },
  1023. { "seltime", &aic79xx_seltime },
  1024. { "tag_info", NULL },
  1025. { "global_tag_depth", NULL},
  1026. { "slewrate", NULL },
  1027. { "precomp", NULL },
  1028. { "amplitude", NULL },
  1029. { "slowcrc", &aic79xx_slowcrc },
  1030. };
  1031. end = strchr(s, '\0');
  1032. /*
  1033. * XXX ia64 gcc isn't smart enough to know that ARRAY_SIZE
  1034. * will never be 0 in this case.
  1035. */
  1036. n = 0;
  1037. while ((p = strsep(&s, ",.")) != NULL) {
  1038. if (*p == '\0')
  1039. continue;
  1040. for (i = 0; i < ARRAY_SIZE(options); i++) {
  1041. n = strlen(options[i].name);
  1042. if (strncmp(options[i].name, p, n) == 0)
  1043. break;
  1044. }
  1045. if (i == ARRAY_SIZE(options))
  1046. continue;
  1047. if (strncmp(p, "global_tag_depth", n) == 0) {
  1048. ahd_linux_setup_tag_info_global(p + n);
  1049. } else if (strncmp(p, "tag_info", n) == 0) {
  1050. s = ahd_parse_brace_option("tag_info", p + n, end,
  1051. 2, ahd_linux_setup_tag_info, 0);
  1052. } else if (strncmp(p, "slewrate", n) == 0) {
  1053. s = ahd_parse_brace_option("slewrate",
  1054. p + n, end, 1, ahd_linux_setup_iocell_info,
  1055. AIC79XX_SLEWRATE_INDEX);
  1056. } else if (strncmp(p, "precomp", n) == 0) {
  1057. s = ahd_parse_brace_option("precomp",
  1058. p + n, end, 1, ahd_linux_setup_iocell_info,
  1059. AIC79XX_PRECOMP_INDEX);
  1060. } else if (strncmp(p, "amplitude", n) == 0) {
  1061. s = ahd_parse_brace_option("amplitude",
  1062. p + n, end, 1, ahd_linux_setup_iocell_info,
  1063. AIC79XX_AMPLITUDE_INDEX);
  1064. } else if (p[n] == ':') {
  1065. *(options[i].flag) = simple_strtoul(p + n + 1, NULL, 0);
  1066. } else if (!strncmp(p, "verbose", n)) {
  1067. *(options[i].flag) = 1;
  1068. } else {
  1069. *(options[i].flag) ^= 0xFFFFFFFF;
  1070. }
  1071. }
  1072. return 1;
  1073. }
  1074. __setup("aic79xx=", aic79xx_setup);
  1075. uint32_t aic79xx_verbose;
  1076. int
  1077. ahd_linux_register_host(struct ahd_softc *ahd, struct scsi_host_template *template)
  1078. {
  1079. char buf[80];
  1080. struct Scsi_Host *host;
  1081. char *new_name;
  1082. u_long s;
  1083. int retval;
  1084. template->name = ahd->description;
  1085. host = scsi_host_alloc(template, sizeof(struct ahd_softc *));
  1086. if (host == NULL)
  1087. return (ENOMEM);
  1088. *((struct ahd_softc **)host->hostdata) = ahd;
  1089. ahd->platform_data->host = host;
  1090. host->can_queue = AHD_MAX_QUEUE;
  1091. host->cmd_per_lun = 2;
  1092. host->sg_tablesize = AHD_NSEG;
  1093. host->this_id = ahd->our_id;
  1094. host->irq = ahd->platform_data->irq;
  1095. host->max_id = (ahd->features & AHD_WIDE) ? 16 : 8;
  1096. host->max_lun = AHD_NUM_LUNS;
  1097. host->max_channel = 0;
  1098. host->sg_tablesize = AHD_NSEG;
  1099. ahd_lock(ahd, &s);
  1100. ahd_set_unit(ahd, ahd_linux_unit++);
  1101. ahd_unlock(ahd, &s);
  1102. sprintf(buf, "scsi%d", host->host_no);
  1103. new_name = kmalloc(strlen(buf) + 1, GFP_ATOMIC);
  1104. if (new_name != NULL) {
  1105. strcpy(new_name, buf);
  1106. ahd_set_name(ahd, new_name);
  1107. }
  1108. host->unique_id = ahd->unit;
  1109. ahd_linux_initialize_scsi_bus(ahd);
  1110. ahd_intr_enable(ahd, TRUE);
  1111. host->transportt = ahd_linux_transport_template;
  1112. retval = scsi_add_host(host, &ahd->dev_softc->dev);
  1113. if (retval) {
  1114. printk(KERN_WARNING "aic79xx: scsi_add_host failed\n");
  1115. scsi_host_put(host);
  1116. return retval;
  1117. }
  1118. scsi_scan_host(host);
  1119. return 0;
  1120. }
  1121. /*
  1122. * Place the SCSI bus into a known state by either resetting it,
  1123. * or forcing transfer negotiations on the next command to any
  1124. * target.
  1125. */
  1126. static void
  1127. ahd_linux_initialize_scsi_bus(struct ahd_softc *ahd)
  1128. {
  1129. u_int target_id;
  1130. u_int numtarg;
  1131. unsigned long s;
  1132. target_id = 0;
  1133. numtarg = 0;
  1134. if (aic79xx_no_reset != 0)
  1135. ahd->flags &= ~AHD_RESET_BUS_A;
  1136. if ((ahd->flags & AHD_RESET_BUS_A) != 0)
  1137. ahd_reset_channel(ahd, 'A', /*initiate_reset*/TRUE);
  1138. else
  1139. numtarg = (ahd->features & AHD_WIDE) ? 16 : 8;
  1140. ahd_lock(ahd, &s);
  1141. /*
  1142. * Force negotiation to async for all targets that
  1143. * will not see an initial bus reset.
  1144. */
  1145. for (; target_id < numtarg; target_id++) {
  1146. struct ahd_devinfo devinfo;
  1147. struct ahd_initiator_tinfo *tinfo;
  1148. struct ahd_tmode_tstate *tstate;
  1149. tinfo = ahd_fetch_transinfo(ahd, 'A', ahd->our_id,
  1150. target_id, &tstate);
  1151. ahd_compile_devinfo(&devinfo, ahd->our_id, target_id,
  1152. CAM_LUN_WILDCARD, 'A', ROLE_INITIATOR);
  1153. ahd_update_neg_request(ahd, &devinfo, tstate,
  1154. tinfo, AHD_NEG_ALWAYS);
  1155. }
  1156. ahd_unlock(ahd, &s);
  1157. /* Give the bus some time to recover */
  1158. if ((ahd->flags & AHD_RESET_BUS_A) != 0) {
  1159. ahd_freeze_simq(ahd);
  1160. msleep(AIC79XX_RESET_DELAY);
  1161. ahd_release_simq(ahd);
  1162. }
  1163. }
  1164. int
  1165. ahd_platform_alloc(struct ahd_softc *ahd, void *platform_arg)
  1166. {
  1167. ahd->platform_data =
  1168. kzalloc(sizeof(struct ahd_platform_data), GFP_ATOMIC);
  1169. if (ahd->platform_data == NULL)
  1170. return (ENOMEM);
  1171. ahd->platform_data->irq = AHD_LINUX_NOIRQ;
  1172. ahd_lockinit(ahd);
  1173. ahd->seltime = (aic79xx_seltime & 0x3) << 4;
  1174. return (0);
  1175. }
  1176. void
  1177. ahd_platform_free(struct ahd_softc *ahd)
  1178. {
  1179. struct scsi_target *starget;
  1180. int i;
  1181. if (ahd->platform_data != NULL) {
  1182. /* destroy all of the device and target objects */
  1183. for (i = 0; i < AHD_NUM_TARGETS; i++) {
  1184. starget = ahd->platform_data->starget[i];
  1185. if (starget != NULL) {
  1186. ahd->platform_data->starget[i] = NULL;
  1187. }
  1188. }
  1189. if (ahd->platform_data->irq != AHD_LINUX_NOIRQ)
  1190. free_irq(ahd->platform_data->irq, ahd);
  1191. if (ahd->tags[0] == BUS_SPACE_PIO
  1192. && ahd->bshs[0].ioport != 0)
  1193. release_region(ahd->bshs[0].ioport, 256);
  1194. if (ahd->tags[1] == BUS_SPACE_PIO
  1195. && ahd->bshs[1].ioport != 0)
  1196. release_region(ahd->bshs[1].ioport, 256);
  1197. if (ahd->tags[0] == BUS_SPACE_MEMIO
  1198. && ahd->bshs[0].maddr != NULL) {
  1199. iounmap(ahd->bshs[0].maddr);
  1200. release_mem_region(ahd->platform_data->mem_busaddr,
  1201. 0x1000);
  1202. }
  1203. if (ahd->platform_data->host)
  1204. scsi_host_put(ahd->platform_data->host);
  1205. kfree(ahd->platform_data);
  1206. }
  1207. }
  1208. void
  1209. ahd_platform_init(struct ahd_softc *ahd)
  1210. {
  1211. /*
  1212. * Lookup and commit any modified IO Cell options.
  1213. */
  1214. if (ahd->unit < ARRAY_SIZE(aic79xx_iocell_info)) {
  1215. const struct ahd_linux_iocell_opts *iocell_opts;
  1216. iocell_opts = &aic79xx_iocell_info[ahd->unit];
  1217. if (iocell_opts->precomp != AIC79XX_DEFAULT_PRECOMP)
  1218. AHD_SET_PRECOMP(ahd, iocell_opts->precomp);
  1219. if (iocell_opts->slewrate != AIC79XX_DEFAULT_SLEWRATE)
  1220. AHD_SET_SLEWRATE(ahd, iocell_opts->slewrate);
  1221. if (iocell_opts->amplitude != AIC79XX_DEFAULT_AMPLITUDE)
  1222. AHD_SET_AMPLITUDE(ahd, iocell_opts->amplitude);
  1223. }
  1224. }
  1225. void
  1226. ahd_platform_freeze_devq(struct ahd_softc *ahd, struct scb *scb)
  1227. {
  1228. ahd_platform_abort_scbs(ahd, SCB_GET_TARGET(ahd, scb),
  1229. SCB_GET_CHANNEL(ahd, scb),
  1230. SCB_GET_LUN(scb), SCB_LIST_NULL,
  1231. ROLE_UNKNOWN, CAM_REQUEUE_REQ);
  1232. }
  1233. void
  1234. ahd_platform_set_tags(struct ahd_softc *ahd, struct scsi_device *sdev,
  1235. struct ahd_devinfo *devinfo, ahd_queue_alg alg)
  1236. {
  1237. struct ahd_linux_device *dev;
  1238. int was_queuing;
  1239. int now_queuing;
  1240. if (sdev == NULL)
  1241. return;
  1242. dev = scsi_transport_device_data(sdev);
  1243. if (dev == NULL)
  1244. return;
  1245. was_queuing = dev->flags & (AHD_DEV_Q_BASIC|AHD_DEV_Q_TAGGED);
  1246. switch (alg) {
  1247. default:
  1248. case AHD_QUEUE_NONE:
  1249. now_queuing = 0;
  1250. break;
  1251. case AHD_QUEUE_BASIC:
  1252. now_queuing = AHD_DEV_Q_BASIC;
  1253. break;
  1254. case AHD_QUEUE_TAGGED:
  1255. now_queuing = AHD_DEV_Q_TAGGED;
  1256. break;
  1257. }
  1258. if ((dev->flags & AHD_DEV_FREEZE_TIL_EMPTY) == 0
  1259. && (was_queuing != now_queuing)
  1260. && (dev->active != 0)) {
  1261. dev->flags |= AHD_DEV_FREEZE_TIL_EMPTY;
  1262. dev->qfrozen++;
  1263. }
  1264. dev->flags &= ~(AHD_DEV_Q_BASIC|AHD_DEV_Q_TAGGED|AHD_DEV_PERIODIC_OTAG);
  1265. if (now_queuing) {
  1266. u_int usertags;
  1267. usertags = ahd_linux_user_tagdepth(ahd, devinfo);
  1268. if (!was_queuing) {
  1269. /*
  1270. * Start out aggressively and allow our
  1271. * dynamic queue depth algorithm to take
  1272. * care of the rest.
  1273. */
  1274. dev->maxtags = usertags;
  1275. dev->openings = dev->maxtags - dev->active;
  1276. }
  1277. if (dev->maxtags == 0) {
  1278. /*
  1279. * Queueing is disabled by the user.
  1280. */
  1281. dev->openings = 1;
  1282. } else if (alg == AHD_QUEUE_TAGGED) {
  1283. dev->flags |= AHD_DEV_Q_TAGGED;
  1284. if (aic79xx_periodic_otag != 0)
  1285. dev->flags |= AHD_DEV_PERIODIC_OTAG;
  1286. } else
  1287. dev->flags |= AHD_DEV_Q_BASIC;
  1288. } else {
  1289. /* We can only have one opening. */
  1290. dev->maxtags = 0;
  1291. dev->openings = 1 - dev->active;
  1292. }
  1293. switch ((dev->flags & (AHD_DEV_Q_BASIC|AHD_DEV_Q_TAGGED))) {
  1294. case AHD_DEV_Q_BASIC:
  1295. case AHD_DEV_Q_TAGGED:
  1296. scsi_change_queue_depth(sdev,
  1297. dev->openings + dev->active);
  1298. break;
  1299. default:
  1300. /*
  1301. * We allow the OS to queue 2 untagged transactions to
  1302. * us at any time even though we can only execute them
  1303. * serially on the controller/device. This should
  1304. * remove some latency.
  1305. */
  1306. scsi_change_queue_depth(sdev, 1);
  1307. break;
  1308. }
  1309. }
  1310. int
  1311. ahd_platform_abort_scbs(struct ahd_softc *ahd, int target, char channel,
  1312. int lun, u_int tag, role_t role, uint32_t status)
  1313. {
  1314. return 0;
  1315. }
  1316. static u_int
  1317. ahd_linux_user_tagdepth(struct ahd_softc *ahd, struct ahd_devinfo *devinfo)
  1318. {
  1319. static int warned_user;
  1320. u_int tags;
  1321. tags = 0;
  1322. if ((ahd->user_discenable & devinfo->target_mask) != 0) {
  1323. if (ahd->unit >= ARRAY_SIZE(aic79xx_tag_info)) {
  1324. if (warned_user == 0) {
  1325. printk(KERN_WARNING
  1326. "aic79xx: WARNING: Insufficient tag_info instances\n"
  1327. "aic79xx: for installed controllers. Using defaults\n"
  1328. "aic79xx: Please update the aic79xx_tag_info array in\n"
  1329. "aic79xx: the aic79xx_osm.c source file.\n");
  1330. warned_user++;
  1331. }
  1332. tags = AHD_MAX_QUEUE;
  1333. } else {
  1334. adapter_tag_info_t *tag_info;
  1335. tag_info = &aic79xx_tag_info[ahd->unit];
  1336. tags = tag_info->tag_commands[devinfo->target_offset];
  1337. if (tags > AHD_MAX_QUEUE)
  1338. tags = AHD_MAX_QUEUE;
  1339. }
  1340. }
  1341. return (tags);
  1342. }
  1343. /*
  1344. * Determines the queue depth for a given device.
  1345. */
  1346. static void
  1347. ahd_linux_device_queue_depth(struct scsi_device *sdev)
  1348. {
  1349. struct ahd_devinfo devinfo;
  1350. u_int tags;
  1351. struct ahd_softc *ahd = *((struct ahd_softc **)sdev->host->hostdata);
  1352. ahd_compile_devinfo(&devinfo,
  1353. ahd->our_id,
  1354. sdev->sdev_target->id, sdev->lun,
  1355. sdev->sdev_target->channel == 0 ? 'A' : 'B',
  1356. ROLE_INITIATOR);
  1357. tags = ahd_linux_user_tagdepth(ahd, &devinfo);
  1358. if (tags != 0 && sdev->tagged_supported != 0) {
  1359. ahd_platform_set_tags(ahd, sdev, &devinfo, AHD_QUEUE_TAGGED);
  1360. ahd_send_async(ahd, devinfo.channel, devinfo.target,
  1361. devinfo.lun, AC_TRANSFER_NEG);
  1362. ahd_print_devinfo(ahd, &devinfo);
  1363. printk("Tagged Queuing enabled. Depth %d\n", tags);
  1364. } else {
  1365. ahd_platform_set_tags(ahd, sdev, &devinfo, AHD_QUEUE_NONE);
  1366. ahd_send_async(ahd, devinfo.channel, devinfo.target,
  1367. devinfo.lun, AC_TRANSFER_NEG);
  1368. }
  1369. }
  1370. static int
  1371. ahd_linux_run_command(struct ahd_softc *ahd, struct ahd_linux_device *dev,
  1372. struct scsi_cmnd *cmd)
  1373. {
  1374. struct scb *scb;
  1375. struct hardware_scb *hscb;
  1376. struct ahd_initiator_tinfo *tinfo;
  1377. struct ahd_tmode_tstate *tstate;
  1378. u_int col_idx;
  1379. uint16_t mask;
  1380. unsigned long flags;
  1381. int nseg;
  1382. nseg = scsi_dma_map(cmd);
  1383. if (nseg < 0)
  1384. return SCSI_MLQUEUE_HOST_BUSY;
  1385. ahd_lock(ahd, &flags);
  1386. /*
  1387. * Get an scb to use.
  1388. */
  1389. tinfo = ahd_fetch_transinfo(ahd, 'A', ahd->our_id,
  1390. cmd->device->id, &tstate);
  1391. if ((dev->flags & (AHD_DEV_Q_TAGGED|AHD_DEV_Q_BASIC)) == 0
  1392. || (tinfo->curr.ppr_options & MSG_EXT_PPR_IU_REQ) != 0) {
  1393. col_idx = AHD_NEVER_COL_IDX;
  1394. } else {
  1395. col_idx = AHD_BUILD_COL_IDX(cmd->device->id,
  1396. cmd->device->lun);
  1397. }
  1398. if ((scb = ahd_get_scb(ahd, col_idx)) == NULL) {
  1399. ahd->flags |= AHD_RESOURCE_SHORTAGE;
  1400. ahd_unlock(ahd, &flags);
  1401. scsi_dma_unmap(cmd);
  1402. return SCSI_MLQUEUE_HOST_BUSY;
  1403. }
  1404. scb->io_ctx = cmd;
  1405. scb->platform_data->dev = dev;
  1406. hscb = scb->hscb;
  1407. cmd->host_scribble = (char *)scb;
  1408. /*
  1409. * Fill out basics of the HSCB.
  1410. */
  1411. hscb->control = 0;
  1412. hscb->scsiid = BUILD_SCSIID(ahd, cmd);
  1413. hscb->lun = cmd->device->lun;
  1414. scb->hscb->task_management = 0;
  1415. mask = SCB_GET_TARGET_MASK(ahd, scb);
  1416. if ((ahd->user_discenable & mask) != 0)
  1417. hscb->control |= DISCENB;
  1418. if ((tinfo->curr.ppr_options & MSG_EXT_PPR_IU_REQ) != 0)
  1419. scb->flags |= SCB_PACKETIZED;
  1420. if ((tstate->auto_negotiate & mask) != 0) {
  1421. scb->flags |= SCB_AUTO_NEGOTIATE;
  1422. scb->hscb->control |= MK_MESSAGE;
  1423. }
  1424. if ((dev->flags & (AHD_DEV_Q_TAGGED|AHD_DEV_Q_BASIC)) != 0) {
  1425. if (dev->commands_since_idle_or_otag == AHD_OTAG_THRESH
  1426. && (dev->flags & AHD_DEV_Q_TAGGED) != 0) {
  1427. hscb->control |= MSG_ORDERED_TASK;
  1428. dev->commands_since_idle_or_otag = 0;
  1429. } else {
  1430. hscb->control |= MSG_SIMPLE_TASK;
  1431. }
  1432. }
  1433. hscb->cdb_len = cmd->cmd_len;
  1434. memcpy(hscb->shared_data.idata.cdb, cmd->cmnd, hscb->cdb_len);
  1435. scb->platform_data->xfer_len = 0;
  1436. ahd_set_residual(scb, 0);
  1437. ahd_set_sense_residual(scb, 0);
  1438. scb->sg_count = 0;
  1439. if (nseg > 0) {
  1440. void *sg = scb->sg_list;
  1441. struct scatterlist *cur_seg;
  1442. int i;
  1443. scb->platform_data->xfer_len = 0;
  1444. scsi_for_each_sg(cmd, cur_seg, nseg, i) {
  1445. dma_addr_t addr;
  1446. bus_size_t len;
  1447. addr = sg_dma_address(cur_seg);
  1448. len = sg_dma_len(cur_seg);
  1449. scb->platform_data->xfer_len += len;
  1450. sg = ahd_sg_setup(ahd, scb, sg, addr, len,
  1451. i == (nseg - 1));
  1452. }
  1453. }
  1454. LIST_INSERT_HEAD(&ahd->pending_scbs, scb, pending_links);
  1455. dev->openings--;
  1456. dev->active++;
  1457. dev->commands_issued++;
  1458. if ((dev->flags & AHD_DEV_PERIODIC_OTAG) != 0)
  1459. dev->commands_since_idle_or_otag++;
  1460. scb->flags |= SCB_ACTIVE;
  1461. ahd_queue_scb(ahd, scb);
  1462. ahd_unlock(ahd, &flags);
  1463. return 0;
  1464. }
  1465. /*
  1466. * SCSI controller interrupt handler.
  1467. */
  1468. irqreturn_t
  1469. ahd_linux_isr(int irq, void *dev_id)
  1470. {
  1471. struct ahd_softc *ahd;
  1472. u_long flags;
  1473. int ours;
  1474. ahd = (struct ahd_softc *) dev_id;
  1475. ahd_lock(ahd, &flags);
  1476. ours = ahd_intr(ahd);
  1477. ahd_unlock(ahd, &flags);
  1478. return IRQ_RETVAL(ours);
  1479. }
  1480. void
  1481. ahd_send_async(struct ahd_softc *ahd, char channel,
  1482. u_int target, u_int lun, ac_code code)
  1483. {
  1484. switch (code) {
  1485. case AC_TRANSFER_NEG:
  1486. {
  1487. struct scsi_target *starget;
  1488. struct ahd_initiator_tinfo *tinfo;
  1489. struct ahd_tmode_tstate *tstate;
  1490. unsigned int target_ppr_options;
  1491. BUG_ON(target == CAM_TARGET_WILDCARD);
  1492. tinfo = ahd_fetch_transinfo(ahd, channel, ahd->our_id,
  1493. target, &tstate);
  1494. /*
  1495. * Don't bother reporting results while
  1496. * negotiations are still pending.
  1497. */
  1498. if (tinfo->curr.period != tinfo->goal.period
  1499. || tinfo->curr.width != tinfo->goal.width
  1500. || tinfo->curr.offset != tinfo->goal.offset
  1501. || tinfo->curr.ppr_options != tinfo->goal.ppr_options)
  1502. if (bootverbose == 0)
  1503. break;
  1504. /*
  1505. * Don't bother reporting results that
  1506. * are identical to those last reported.
  1507. */
  1508. starget = ahd->platform_data->starget[target];
  1509. if (starget == NULL)
  1510. break;
  1511. target_ppr_options =
  1512. (spi_dt(starget) ? MSG_EXT_PPR_DT_REQ : 0)
  1513. + (spi_qas(starget) ? MSG_EXT_PPR_QAS_REQ : 0)
  1514. + (spi_iu(starget) ? MSG_EXT_PPR_IU_REQ : 0)
  1515. + (spi_rd_strm(starget) ? MSG_EXT_PPR_RD_STRM : 0)
  1516. + (spi_pcomp_en(starget) ? MSG_EXT_PPR_PCOMP_EN : 0)
  1517. + (spi_rti(starget) ? MSG_EXT_PPR_RTI : 0)
  1518. + (spi_wr_flow(starget) ? MSG_EXT_PPR_WR_FLOW : 0)
  1519. + (spi_hold_mcs(starget) ? MSG_EXT_PPR_HOLD_MCS : 0);
  1520. if (tinfo->curr.period == spi_period(starget)
  1521. && tinfo->curr.width == spi_width(starget)
  1522. && tinfo->curr.offset == spi_offset(starget)
  1523. && tinfo->curr.ppr_options == target_ppr_options)
  1524. if (bootverbose == 0)
  1525. break;
  1526. spi_period(starget) = tinfo->curr.period;
  1527. spi_width(starget) = tinfo->curr.width;
  1528. spi_offset(starget) = tinfo->curr.offset;
  1529. spi_dt(starget) = tinfo->curr.ppr_options & MSG_EXT_PPR_DT_REQ ? 1 : 0;
  1530. spi_qas(starget) = tinfo->curr.ppr_options & MSG_EXT_PPR_QAS_REQ ? 1 : 0;
  1531. spi_iu(starget) = tinfo->curr.ppr_options & MSG_EXT_PPR_IU_REQ ? 1 : 0;
  1532. spi_rd_strm(starget) = tinfo->curr.ppr_options & MSG_EXT_PPR_RD_STRM ? 1 : 0;
  1533. spi_pcomp_en(starget) = tinfo->curr.ppr_options & MSG_EXT_PPR_PCOMP_EN ? 1 : 0;
  1534. spi_rti(starget) = tinfo->curr.ppr_options & MSG_EXT_PPR_RTI ? 1 : 0;
  1535. spi_wr_flow(starget) = tinfo->curr.ppr_options & MSG_EXT_PPR_WR_FLOW ? 1 : 0;
  1536. spi_hold_mcs(starget) = tinfo->curr.ppr_options & MSG_EXT_PPR_HOLD_MCS ? 1 : 0;
  1537. spi_display_xfer_agreement(starget);
  1538. break;
  1539. }
  1540. case AC_SENT_BDR:
  1541. {
  1542. WARN_ON(lun != CAM_LUN_WILDCARD);
  1543. scsi_report_device_reset(ahd->platform_data->host,
  1544. channel - 'A', target);
  1545. break;
  1546. }
  1547. case AC_BUS_RESET:
  1548. if (ahd->platform_data->host != NULL) {
  1549. scsi_report_bus_reset(ahd->platform_data->host,
  1550. channel - 'A');
  1551. }
  1552. break;
  1553. default:
  1554. panic("ahd_send_async: Unexpected async event");
  1555. }
  1556. }
  1557. /*
  1558. * Calls the higher level scsi done function and frees the scb.
  1559. */
  1560. void
  1561. ahd_done(struct ahd_softc *ahd, struct scb *scb)
  1562. {
  1563. struct scsi_cmnd *cmd;
  1564. struct ahd_linux_device *dev;
  1565. if ((scb->flags & SCB_ACTIVE) == 0) {
  1566. printk("SCB %d done'd twice\n", SCB_GET_TAG(scb));
  1567. ahd_dump_card_state(ahd);
  1568. panic("Stopping for safety");
  1569. }
  1570. LIST_REMOVE(scb, pending_links);
  1571. cmd = scb->io_ctx;
  1572. dev = scb->platform_data->dev;
  1573. dev->active--;
  1574. dev->openings++;
  1575. if ((cmd->result & (CAM_DEV_QFRZN << 16)) != 0) {
  1576. cmd->result &= ~(CAM_DEV_QFRZN << 16);
  1577. dev->qfrozen--;
  1578. }
  1579. ahd_linux_unmap_scb(ahd, scb);
  1580. /*
  1581. * Guard against stale sense data.
  1582. * The Linux mid-layer assumes that sense
  1583. * was retrieved anytime the first byte of
  1584. * the sense buffer looks "sane".
  1585. */
  1586. cmd->sense_buffer[0] = 0;
  1587. if (ahd_get_transaction_status(scb) == CAM_REQ_INPROG) {
  1588. uint32_t amount_xferred;
  1589. amount_xferred =
  1590. ahd_get_transfer_length(scb) - ahd_get_residual(scb);
  1591. if ((scb->flags & SCB_TRANSMISSION_ERROR) != 0) {
  1592. #ifdef AHD_DEBUG
  1593. if ((ahd_debug & AHD_SHOW_MISC) != 0) {
  1594. ahd_print_path(ahd, scb);
  1595. printk("Set CAM_UNCOR_PARITY\n");
  1596. }
  1597. #endif
  1598. ahd_set_transaction_status(scb, CAM_UNCOR_PARITY);
  1599. #ifdef AHD_REPORT_UNDERFLOWS
  1600. /*
  1601. * This code is disabled by default as some
  1602. * clients of the SCSI system do not properly
  1603. * initialize the underflow parameter. This
  1604. * results in spurious termination of commands
  1605. * that complete as expected (e.g. underflow is
  1606. * allowed as command can return variable amounts
  1607. * of data.
  1608. */
  1609. } else if (amount_xferred < scb->io_ctx->underflow) {
  1610. u_int i;
  1611. ahd_print_path(ahd, scb);
  1612. printk("CDB:");
  1613. for (i = 0; i < scb->io_ctx->cmd_len; i++)
  1614. printk(" 0x%x", scb->io_ctx->cmnd[i]);
  1615. printk("\n");
  1616. ahd_print_path(ahd, scb);
  1617. printk("Saw underflow (%ld of %ld bytes). "
  1618. "Treated as error\n",
  1619. ahd_get_residual(scb),
  1620. ahd_get_transfer_length(scb));
  1621. ahd_set_transaction_status(scb, CAM_DATA_RUN_ERR);
  1622. #endif
  1623. } else {
  1624. ahd_set_transaction_status(scb, CAM_REQ_CMP);
  1625. }
  1626. } else if (ahd_get_transaction_status(scb) == CAM_SCSI_STATUS_ERROR) {
  1627. ahd_linux_handle_scsi_status(ahd, cmd->device, scb);
  1628. }
  1629. if (dev->openings == 1
  1630. && ahd_get_transaction_status(scb) == CAM_REQ_CMP
  1631. && ahd_get_scsi_status(scb) != SCSI_STATUS_QUEUE_FULL)
  1632. dev->tag_success_count++;
  1633. /*
  1634. * Some devices deal with…