/drivers/scsi/aic7xxx_old.c

http://github.com/mirrors/linux · C · 11149 lines · 7575 code · 746 blank · 2828 comment · 1344 complexity · 2ded740f1a053ab0a938f4dc27975484 MD5 · raw file

Large files are truncated click here to view the full file

  1. /*+M*************************************************************************
  2. * Adaptec AIC7xxx device driver for Linux.
  3. *
  4. * Copyright (c) 1994 John Aycock
  5. * The University of Calgary Department of Computer Science.
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 2, or (at your option)
  10. * any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program; see the file COPYING. If not, write to
  19. * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
  20. *
  21. * Sources include the Adaptec 1740 driver (aha1740.c), the Ultrastor 24F
  22. * driver (ultrastor.c), various Linux kernel source, the Adaptec EISA
  23. * config file (!adp7771.cfg), the Adaptec AHA-2740A Series User's Guide,
  24. * the Linux Kernel Hacker's Guide, Writing a SCSI Device Driver for Linux,
  25. * the Adaptec 1542 driver (aha1542.c), the Adaptec EISA overlay file
  26. * (adp7770.ovl), the Adaptec AHA-2740 Series Technical Reference Manual,
  27. * the Adaptec AIC-7770 Data Book, the ANSI SCSI specification, the
  28. * ANSI SCSI-2 specification (draft 10c), ...
  29. *
  30. * --------------------------------------------------------------------------
  31. *
  32. * Modifications by Daniel M. Eischen (deischen@iworks.InterWorks.org):
  33. *
  34. * Substantially modified to include support for wide and twin bus
  35. * adapters, DMAing of SCBs, tagged queueing, IRQ sharing, bug fixes,
  36. * SCB paging, and other rework of the code.
  37. *
  38. * Parts of this driver were also based on the FreeBSD driver by
  39. * Justin T. Gibbs. His copyright follows:
  40. *
  41. * --------------------------------------------------------------------------
  42. * Copyright (c) 1994-1997 Justin Gibbs.
  43. * All rights reserved.
  44. *
  45. * Redistribution and use in source and binary forms, with or without
  46. * modification, are permitted provided that the following conditions
  47. * are met:
  48. * 1. Redistributions of source code must retain the above copyright
  49. * notice, this list of conditions, and the following disclaimer,
  50. * without modification, immediately at the beginning of the file.
  51. * 2. Redistributions in binary form must reproduce the above copyright
  52. * notice, this list of conditions and the following disclaimer in the
  53. * documentation and/or other materials provided with the distribution.
  54. * 3. The name of the author may not be used to endorse or promote products
  55. * derived from this software without specific prior written permission.
  56. *
  57. * Where this Software is combined with software released under the terms of
  58. * the GNU General Public License ("GPL") and the terms of the GPL would require the
  59. * combined work to also be released under the terms of the GPL, the terms
  60. * and conditions of this License will apply in addition to those of the
  61. * GPL with the exception of any terms or conditions of this License that
  62. * conflict with, or are expressly prohibited by, the GPL.
  63. *
  64. * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
  65. * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  66. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  67. * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
  68. * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  69. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  70. * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  71. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  72. * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  73. * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  74. * SUCH DAMAGE.
  75. *
  76. * $Id: aic7xxx.c,v 1.119 1997/06/27 19:39:18 gibbs Exp $
  77. *---------------------------------------------------------------------------
  78. *
  79. * Thanks also go to (in alphabetical order) the following:
  80. *
  81. * Rory Bolt - Sequencer bug fixes
  82. * Jay Estabrook - Initial DEC Alpha support
  83. * Doug Ledford - Much needed abort/reset bug fixes
  84. * Kai Makisara - DMAing of SCBs
  85. *
  86. * A Boot time option was also added for not resetting the scsi bus.
  87. *
  88. * Form: aic7xxx=extended
  89. * aic7xxx=no_reset
  90. * aic7xxx=ultra
  91. * aic7xxx=irq_trigger:[0,1] # 0 edge, 1 level
  92. * aic7xxx=verbose
  93. *
  94. * Daniel M. Eischen, deischen@iworks.InterWorks.org, 1/23/97
  95. *
  96. * $Id: aic7xxx.c,v 4.1 1997/06/12 08:23:42 deang Exp $
  97. *-M*************************************************************************/
  98. /*+M**************************************************************************
  99. *
  100. * Further driver modifications made by Doug Ledford <dledford@redhat.com>
  101. *
  102. * Copyright (c) 1997-1999 Doug Ledford
  103. *
  104. * These changes are released under the same licensing terms as the FreeBSD
  105. * driver written by Justin Gibbs. Please see his Copyright notice above
  106. * for the exact terms and conditions covering my changes as well as the
  107. * warranty statement.
  108. *
  109. * Modifications made to the aic7xxx.c,v 4.1 driver from Dan Eischen include
  110. * but are not limited to:
  111. *
  112. * 1: Import of the latest FreeBSD sequencer code for this driver
  113. * 2: Modification of kernel code to accommodate different sequencer semantics
  114. * 3: Extensive changes throughout kernel portion of driver to improve
  115. * abort/reset processing and error hanndling
  116. * 4: Other work contributed by various people on the Internet
  117. * 5: Changes to printk information and verbosity selection code
  118. * 6: General reliability related changes, especially in IRQ management
  119. * 7: Modifications to the default probe/attach order for supported cards
  120. * 8: SMP friendliness has been improved
  121. *
  122. * Overall, this driver represents a significant departure from the official
  123. * aic7xxx driver released by Dan Eischen in two ways. First, in the code
  124. * itself. A diff between the two version of the driver is now a several
  125. * thousand line diff. Second, in approach to solving the same problem. The
  126. * problem is importing the FreeBSD aic7xxx driver code to linux can be a
  127. * difficult and time consuming process, that also can be error prone. Dan
  128. * Eischen's official driver uses the approach that the linux and FreeBSD
  129. * drivers should be as identical as possible. To that end, his next version
  130. * of this driver will be using a mid-layer code library that he is developing
  131. * to moderate communications between the linux mid-level SCSI code and the
  132. * low level FreeBSD driver. He intends to be able to essentially drop the
  133. * FreeBSD driver into the linux kernel with only a few minor tweaks to some
  134. * include files and the like and get things working, making for fast easy
  135. * imports of the FreeBSD code into linux.
  136. *
  137. * I disagree with Dan's approach. Not that I don't think his way of doing
  138. * things would be nice, easy to maintain, and create a more uniform driver
  139. * between FreeBSD and Linux. I have no objection to those issues. My
  140. * disagreement is on the needed functionality. There simply are certain
  141. * things that are done differently in FreeBSD than linux that will cause
  142. * problems for this driver regardless of any middle ware Dan implements.
  143. * The biggest example of this at the moment is interrupt semantics. Linux
  144. * doesn't provide the same protection techniques as FreeBSD does, nor can
  145. * they be easily implemented in any middle ware code since they would truly
  146. * belong in the kernel proper and would effect all drivers. For the time
  147. * being, I see issues such as these as major stumbling blocks to the
  148. * reliability of code based upon such middle ware. Therefore, I choose to
  149. * use a different approach to importing the FreeBSD code that doesn't
  150. * involve any middle ware type code. My approach is to import the sequencer
  151. * code from FreeBSD wholesale. Then, to only make changes in the kernel
  152. * portion of the driver as they are needed for the new sequencer semantics.
  153. * In this way, the portion of the driver that speaks to the rest of the
  154. * linux kernel is fairly static and can be changed/modified to solve
  155. * any problems one might encounter without concern for the FreeBSD driver.
  156. *
  157. * Note: If time and experience should prove me wrong that the middle ware
  158. * code Dan writes is reliable in its operation, then I'll retract my above
  159. * statements. But, for those that don't know, I'm from Missouri (in the US)
  160. * and our state motto is "The Show-Me State". Well, before I will put
  161. * faith into it, you'll have to show me that it works :)
  162. *
  163. *_M*************************************************************************/
  164. /*
  165. * The next three defines are user configurable. These should be the only
  166. * defines a user might need to get in here and change. There are other
  167. * defines buried deeper in the code, but those really shouldn't need touched
  168. * under normal conditions.
  169. */
  170. /*
  171. * AIC7XXX_STRICT_PCI_SETUP
  172. * Should we assume the PCI config options on our controllers are set with
  173. * sane and proper values, or should we be anal about our PCI config
  174. * registers and force them to what we want? The main advantage to
  175. * defining this option is on non-Intel hardware where the BIOS may not
  176. * have been run to set things up, or if you have one of the BIOSless
  177. * Adaptec controllers, such as a 2910, that don't get set up by the
  178. * BIOS. However, keep in mind that we really do set the most important
  179. * items in the driver regardless of this setting, this only controls some
  180. * of the more esoteric PCI options on these cards. In that sense, I
  181. * would default to leaving this off. However, if people wish to try
  182. * things both ways, that would also help me to know if there are some
  183. * machines where it works one way but not another.
  184. *
  185. * -- July 7, 17:09
  186. * OK...I need this on my machine for testing, so the default is to
  187. * leave it defined.
  188. *
  189. * -- July 7, 18:49
  190. * I needed it for testing, but it didn't make any difference, so back
  191. * off she goes.
  192. *
  193. * -- July 16, 23:04
  194. * I turned it back on to try and compensate for the 2.1.x PCI code
  195. * which no longer relies solely on the BIOS and now tries to set
  196. * things itself.
  197. */
  198. #define AIC7XXX_STRICT_PCI_SETUP
  199. /*
  200. * AIC7XXX_VERBOSE_DEBUGGING
  201. * This option enables a lot of extra printk();s in the code, surrounded
  202. * by if (aic7xxx_verbose ...) statements. Executing all of those if
  203. * statements and the extra checks can get to where it actually does have
  204. * an impact on CPU usage and such, as well as code size. Disabling this
  205. * define will keep some of those from becoming part of the code.
  206. *
  207. * NOTE: Currently, this option has no real effect, I will be adding the
  208. * various #ifdef's in the code later when I've decided a section is
  209. * complete and no longer needs debugging. OK...a lot of things are now
  210. * surrounded by this define, so turning this off does have an impact.
  211. */
  212. /*
  213. * #define AIC7XXX_VERBOSE_DEBUGGING
  214. */
  215. #include <linux/module.h>
  216. #include <stdarg.h>
  217. #include <asm/io.h>
  218. #include <asm/irq.h>
  219. #include <asm/byteorder.h>
  220. #include <linux/string.h>
  221. #include <linux/errno.h>
  222. #include <linux/kernel.h>
  223. #include <linux/ioport.h>
  224. #include <linux/delay.h>
  225. #include <linux/pci.h>
  226. #include <linux/proc_fs.h>
  227. #include <linux/blkdev.h>
  228. #include <linux/init.h>
  229. #include <linux/spinlock.h>
  230. #include <linux/smp.h>
  231. #include <linux/interrupt.h>
  232. #include "scsi.h"
  233. #include <scsi/scsi_host.h>
  234. #include "aic7xxx_old/aic7xxx.h"
  235. #include "aic7xxx_old/sequencer.h"
  236. #include "aic7xxx_old/scsi_message.h"
  237. #include "aic7xxx_old/aic7xxx_reg.h"
  238. #include <scsi/scsicam.h>
  239. #include <linux/stat.h>
  240. #include <linux/slab.h> /* for kmalloc() */
  241. #define AIC7XXX_C_VERSION "5.2.6"
  242. #define ALL_TARGETS -1
  243. #define ALL_CHANNELS -1
  244. #define ALL_LUNS -1
  245. #define MAX_TARGETS 16
  246. #define MAX_LUNS 8
  247. #ifndef TRUE
  248. # define TRUE 1
  249. #endif
  250. #ifndef FALSE
  251. # define FALSE 0
  252. #endif
  253. #if defined(__powerpc__) || defined(__i386__) || defined(__x86_64__)
  254. # define MMAPIO
  255. #endif
  256. /*
  257. * You can try raising me for better performance or lowering me if you have
  258. * flaky devices that go off the scsi bus when hit with too many tagged
  259. * commands (like some IBM SCSI-3 LVD drives).
  260. */
  261. #define AIC7XXX_CMDS_PER_DEVICE 32
  262. typedef struct
  263. {
  264. unsigned char tag_commands[16]; /* Allow for wide/twin adapters. */
  265. } adapter_tag_info_t;
  266. /*
  267. * Make a define that will tell the driver not to the default tag depth
  268. * everywhere.
  269. */
  270. #define DEFAULT_TAG_COMMANDS {0, 0, 0, 0, 0, 0, 0, 0,\
  271. 0, 0, 0, 0, 0, 0, 0, 0}
  272. /*
  273. * Modify this as you see fit for your system. By setting tag_commands
  274. * to 0, the driver will use it's own algorithm for determining the
  275. * number of commands to use (see above). When 255, the driver will
  276. * not enable tagged queueing for that particular device. When positive
  277. * (> 0) and (< 255) the values in the array are used for the queue_depth.
  278. * Note that the maximum value for an entry is 254, but you're insane if
  279. * you try to use that many commands on one device.
  280. *
  281. * In this example, the first line will disable tagged queueing for all
  282. * the devices on the first probed aic7xxx adapter.
  283. *
  284. * The second line enables tagged queueing with 4 commands/LUN for IDs
  285. * (1, 2-11, 13-15), disables tagged queueing for ID 12, and tells the
  286. * driver to use its own algorithm for ID 1.
  287. *
  288. * The third line is the same as the first line.
  289. *
  290. * The fourth line disables tagged queueing for devices 0 and 3. It
  291. * enables tagged queueing for the other IDs, with 16 commands/LUN
  292. * for IDs 1 and 4, 127 commands/LUN for ID 8, and 4 commands/LUN for
  293. * IDs 2, 5-7, and 9-15.
  294. */
  295. /*
  296. * NOTE: The below structure is for reference only, the actual structure
  297. * to modify in order to change things is found after this fake one.
  298. *
  299. adapter_tag_info_t aic7xxx_tag_info[] =
  300. {
  301. {DEFAULT_TAG_COMMANDS},
  302. {{4, 0, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 255, 4, 4, 4}},
  303. {DEFAULT_TAG_COMMANDS},
  304. {{255, 16, 4, 255, 16, 4, 4, 4, 127, 4, 4, 4, 4, 4, 4, 4}}
  305. };
  306. */
  307. static adapter_tag_info_t aic7xxx_tag_info[] =
  308. {
  309. {DEFAULT_TAG_COMMANDS},
  310. {DEFAULT_TAG_COMMANDS},
  311. {DEFAULT_TAG_COMMANDS},
  312. {DEFAULT_TAG_COMMANDS},
  313. {DEFAULT_TAG_COMMANDS},
  314. {DEFAULT_TAG_COMMANDS},
  315. {DEFAULT_TAG_COMMANDS},
  316. {DEFAULT_TAG_COMMANDS},
  317. {DEFAULT_TAG_COMMANDS},
  318. {DEFAULT_TAG_COMMANDS},
  319. {DEFAULT_TAG_COMMANDS},
  320. {DEFAULT_TAG_COMMANDS},
  321. {DEFAULT_TAG_COMMANDS},
  322. {DEFAULT_TAG_COMMANDS},
  323. {DEFAULT_TAG_COMMANDS},
  324. {DEFAULT_TAG_COMMANDS}
  325. };
  326. /*
  327. * Define an array of board names that can be indexed by aha_type.
  328. * Don't forget to change this when changing the types!
  329. */
  330. static const char *board_names[] = {
  331. "AIC-7xxx Unknown", /* AIC_NONE */
  332. "Adaptec AIC-7810 Hardware RAID Controller", /* AIC_7810 */
  333. "Adaptec AIC-7770 SCSI host adapter", /* AIC_7770 */
  334. "Adaptec AHA-274X SCSI host adapter", /* AIC_7771 */
  335. "Adaptec AHA-284X SCSI host adapter", /* AIC_284x */
  336. "Adaptec AIC-7850 SCSI host adapter", /* AIC_7850 */
  337. "Adaptec AIC-7855 SCSI host adapter", /* AIC_7855 */
  338. "Adaptec AIC-7860 Ultra SCSI host adapter", /* AIC_7860 */
  339. "Adaptec AHA-2940A Ultra SCSI host adapter", /* AIC_7861 */
  340. "Adaptec AIC-7870 SCSI host adapter", /* AIC_7870 */
  341. "Adaptec AHA-294X SCSI host adapter", /* AIC_7871 */
  342. "Adaptec AHA-394X SCSI host adapter", /* AIC_7872 */
  343. "Adaptec AHA-398X SCSI host adapter", /* AIC_7873 */
  344. "Adaptec AHA-2944 SCSI host adapter", /* AIC_7874 */
  345. "Adaptec AIC-7880 Ultra SCSI host adapter", /* AIC_7880 */
  346. "Adaptec AHA-294X Ultra SCSI host adapter", /* AIC_7881 */
  347. "Adaptec AHA-394X Ultra SCSI host adapter", /* AIC_7882 */
  348. "Adaptec AHA-398X Ultra SCSI host adapter", /* AIC_7883 */
  349. "Adaptec AHA-2944 Ultra SCSI host adapter", /* AIC_7884 */
  350. "Adaptec AHA-2940UW Pro Ultra SCSI host adapter", /* AIC_7887 */
  351. "Adaptec AIC-7895 Ultra SCSI host adapter", /* AIC_7895 */
  352. "Adaptec AIC-7890/1 Ultra2 SCSI host adapter", /* AIC_7890 */
  353. "Adaptec AHA-293X Ultra2 SCSI host adapter", /* AIC_7890 */
  354. "Adaptec AHA-294X Ultra2 SCSI host adapter", /* AIC_7890 */
  355. "Adaptec AIC-7896/7 Ultra2 SCSI host adapter", /* AIC_7896 */
  356. "Adaptec AHA-394X Ultra2 SCSI host adapter", /* AIC_7897 */
  357. "Adaptec AHA-395X Ultra2 SCSI host adapter", /* AIC_7897 */
  358. "Adaptec PCMCIA SCSI controller", /* card bus stuff */
  359. "Adaptec AIC-7892 Ultra 160/m SCSI host adapter", /* AIC_7892 */
  360. "Adaptec AIC-7899 Ultra 160/m SCSI host adapter", /* AIC_7899 */
  361. };
  362. /*
  363. * There should be a specific return value for this in scsi.h, but
  364. * it seems that most drivers ignore it.
  365. */
  366. #define DID_UNDERFLOW DID_ERROR
  367. /*
  368. * What we want to do is have the higher level scsi driver requeue
  369. * the command to us. There is no specific driver status for this
  370. * condition, but the higher level scsi driver will requeue the
  371. * command on a DID_BUS_BUSY error.
  372. *
  373. * Upon further inspection and testing, it seems that DID_BUS_BUSY
  374. * will *always* retry the command. We can get into an infinite loop
  375. * if this happens when we really want some sort of counter that
  376. * will automatically abort/reset the command after so many retries.
  377. * Using DID_ERROR will do just that. (Made by a suggestion by
  378. * Doug Ledford 8/1/96)
  379. */
  380. #define DID_RETRY_COMMAND DID_ERROR
  381. #define HSCSIID 0x07
  382. #define SCSI_RESET 0x040
  383. /*
  384. * EISA/VL-bus stuff
  385. */
  386. #define MINSLOT 1
  387. #define MAXSLOT 15
  388. #define SLOTBASE(x) ((x) << 12)
  389. #define BASE_TO_SLOT(x) ((x) >> 12)
  390. /*
  391. * Standard EISA Host ID regs (Offset from slot base)
  392. */
  393. #define AHC_HID0 0x80 /* 0,1: msb of ID2, 2-7: ID1 */
  394. #define AHC_HID1 0x81 /* 0-4: ID3, 5-7: LSB ID2 */
  395. #define AHC_HID2 0x82 /* product */
  396. #define AHC_HID3 0x83 /* firmware revision */
  397. /*
  398. * AIC-7770 I/O range to reserve for a card
  399. */
  400. #define MINREG 0xC00
  401. #define MAXREG 0xCFF
  402. #define INTDEF 0x5C /* Interrupt Definition Register */
  403. /*
  404. * AIC-78X0 PCI registers
  405. */
  406. #define CLASS_PROGIF_REVID 0x08
  407. #define DEVREVID 0x000000FFul
  408. #define PROGINFC 0x0000FF00ul
  409. #define SUBCLASS 0x00FF0000ul
  410. #define BASECLASS 0xFF000000ul
  411. #define CSIZE_LATTIME 0x0C
  412. #define CACHESIZE 0x0000003Ful /* only 5 bits */
  413. #define LATTIME 0x0000FF00ul
  414. #define DEVCONFIG 0x40
  415. #define SCBSIZE32 0x00010000ul /* aic789X only */
  416. #define MPORTMODE 0x00000400ul /* aic7870 only */
  417. #define RAMPSM 0x00000200ul /* aic7870 only */
  418. #define RAMPSM_ULTRA2 0x00000004
  419. #define VOLSENSE 0x00000100ul
  420. #define SCBRAMSEL 0x00000080ul
  421. #define SCBRAMSEL_ULTRA2 0x00000008
  422. #define MRDCEN 0x00000040ul
  423. #define EXTSCBTIME 0x00000020ul /* aic7870 only */
  424. #define EXTSCBPEN 0x00000010ul /* aic7870 only */
  425. #define BERREN 0x00000008ul
  426. #define DACEN 0x00000004ul
  427. #define STPWLEVEL 0x00000002ul
  428. #define DIFACTNEGEN 0x00000001ul /* aic7870 only */
  429. #define SCAMCTL 0x1a /* Ultra2 only */
  430. #define CCSCBBADDR 0xf0 /* aic7895/6/7 */
  431. /*
  432. * Define the different types of SEEPROMs on aic7xxx adapters
  433. * and make it also represent the address size used in accessing
  434. * its registers. The 93C46 chips have 1024 bits organized into
  435. * 64 16-bit words, while the 93C56 chips have 2048 bits organized
  436. * into 128 16-bit words. The C46 chips use 6 bits to address
  437. * each word, while the C56 and C66 (4096 bits) use 8 bits to
  438. * address each word.
  439. */
  440. typedef enum {C46 = 6, C56_66 = 8} seeprom_chip_type;
  441. /*
  442. *
  443. * Define the format of the SEEPROM registers (16 bits).
  444. *
  445. */
  446. struct seeprom_config {
  447. /*
  448. * SCSI ID Configuration Flags
  449. */
  450. #define CFXFER 0x0007 /* synchronous transfer rate */
  451. #define CFSYNCH 0x0008 /* enable synchronous transfer */
  452. #define CFDISC 0x0010 /* enable disconnection */
  453. #define CFWIDEB 0x0020 /* wide bus device (wide card) */
  454. #define CFSYNCHISULTRA 0x0040 /* CFSYNC is an ultra offset */
  455. #define CFNEWULTRAFORMAT 0x0080 /* Use the Ultra2 SEEPROM format */
  456. #define CFSTART 0x0100 /* send start unit SCSI command */
  457. #define CFINCBIOS 0x0200 /* include in BIOS scan */
  458. #define CFRNFOUND 0x0400 /* report even if not found */
  459. #define CFMULTILUN 0x0800 /* probe mult luns in BIOS scan */
  460. #define CFWBCACHEYES 0x4000 /* Enable W-Behind Cache on drive */
  461. #define CFWBCACHENC 0xc000 /* Don't change W-Behind Cache */
  462. /* UNUSED 0x3000 */
  463. unsigned short device_flags[16]; /* words 0-15 */
  464. /*
  465. * BIOS Control Bits
  466. */
  467. #define CFSUPREM 0x0001 /* support all removable drives */
  468. #define CFSUPREMB 0x0002 /* support removable drives for boot only */
  469. #define CFBIOSEN 0x0004 /* BIOS enabled */
  470. /* UNUSED 0x0008 */
  471. #define CFSM2DRV 0x0010 /* support more than two drives */
  472. #define CF284XEXTEND 0x0020 /* extended translation (284x cards) */
  473. /* UNUSED 0x0040 */
  474. #define CFEXTEND 0x0080 /* extended translation enabled */
  475. /* UNUSED 0xFF00 */
  476. unsigned short bios_control; /* word 16 */
  477. /*
  478. * Host Adapter Control Bits
  479. */
  480. #define CFAUTOTERM 0x0001 /* Perform Auto termination */
  481. #define CFULTRAEN 0x0002 /* Ultra SCSI speed enable (Ultra cards) */
  482. #define CF284XSELTO 0x0003 /* Selection timeout (284x cards) */
  483. #define CF284XFIFO 0x000C /* FIFO Threshold (284x cards) */
  484. #define CFSTERM 0x0004 /* SCSI low byte termination */
  485. #define CFWSTERM 0x0008 /* SCSI high byte termination (wide card) */
  486. #define CFSPARITY 0x0010 /* SCSI parity */
  487. #define CF284XSTERM 0x0020 /* SCSI low byte termination (284x cards) */
  488. #define CFRESETB 0x0040 /* reset SCSI bus at boot */
  489. #define CFBPRIMARY 0x0100 /* Channel B primary on 7895 chipsets */
  490. #define CFSEAUTOTERM 0x0400 /* aic7890 Perform SE Auto Term */
  491. #define CFLVDSTERM 0x0800 /* aic7890 LVD Termination */
  492. /* UNUSED 0xF280 */
  493. unsigned short adapter_control; /* word 17 */
  494. /*
  495. * Bus Release, Host Adapter ID
  496. */
  497. #define CFSCSIID 0x000F /* host adapter SCSI ID */
  498. /* UNUSED 0x00F0 */
  499. #define CFBRTIME 0xFF00 /* bus release time */
  500. unsigned short brtime_id; /* word 18 */
  501. /*
  502. * Maximum targets
  503. */
  504. #define CFMAXTARG 0x00FF /* maximum targets */
  505. /* UNUSED 0xFF00 */
  506. unsigned short max_targets; /* word 19 */
  507. unsigned short res_1[11]; /* words 20-30 */
  508. unsigned short checksum; /* word 31 */
  509. };
  510. #define SELBUS_MASK 0x0a
  511. #define SELNARROW 0x00
  512. #define SELBUSB 0x08
  513. #define SINGLE_BUS 0x00
  514. #define SCB_TARGET(scb) \
  515. (((scb)->hscb->target_channel_lun & TID) >> 4)
  516. #define SCB_LUN(scb) \
  517. ((scb)->hscb->target_channel_lun & LID)
  518. #define SCB_IS_SCSIBUS_B(scb) \
  519. (((scb)->hscb->target_channel_lun & SELBUSB) != 0)
  520. /*
  521. * If an error occurs during a data transfer phase, run the command
  522. * to completion - it's easier that way - making a note of the error
  523. * condition in this location. This then will modify a DID_OK status
  524. * into an appropriate error for the higher-level SCSI code.
  525. */
  526. #define aic7xxx_error(cmd) ((cmd)->SCp.Status)
  527. /*
  528. * Keep track of the targets returned status.
  529. */
  530. #define aic7xxx_status(cmd) ((cmd)->SCp.sent_command)
  531. /*
  532. * The position of the SCSI commands scb within the scb array.
  533. */
  534. #define aic7xxx_position(cmd) ((cmd)->SCp.have_data_in)
  535. /*
  536. * The stored DMA mapping for single-buffer data transfers.
  537. */
  538. #define aic7xxx_mapping(cmd) ((cmd)->SCp.phase)
  539. /*
  540. * Get out private data area from a scsi cmd pointer
  541. */
  542. #define AIC_DEV(cmd) ((struct aic_dev_data *)(cmd)->device->hostdata)
  543. /*
  544. * So we can keep track of our host structs
  545. */
  546. static struct aic7xxx_host *first_aic7xxx = NULL;
  547. /*
  548. * As of Linux 2.1, the mid-level SCSI code uses virtual addresses
  549. * in the scatter-gather lists. We need to convert the virtual
  550. * addresses to physical addresses.
  551. */
  552. struct hw_scatterlist {
  553. unsigned int address;
  554. unsigned int length;
  555. };
  556. /*
  557. * Maximum number of SG segments these cards can support.
  558. */
  559. #define AIC7XXX_MAX_SG 128
  560. /*
  561. * The maximum number of SCBs we could have for ANY type
  562. * of card. DON'T FORGET TO CHANGE THE SCB MASK IN THE
  563. * SEQUENCER CODE IF THIS IS MODIFIED!
  564. */
  565. #define AIC7XXX_MAXSCB 255
  566. struct aic7xxx_hwscb {
  567. /* ------------ Begin hardware supported fields ---------------- */
  568. /* 0*/ unsigned char control;
  569. /* 1*/ unsigned char target_channel_lun; /* 4/1/3 bits */
  570. /* 2*/ unsigned char target_status;
  571. /* 3*/ unsigned char SG_segment_count;
  572. /* 4*/ unsigned int SG_list_pointer;
  573. /* 8*/ unsigned char residual_SG_segment_count;
  574. /* 9*/ unsigned char residual_data_count[3];
  575. /*12*/ unsigned int data_pointer;
  576. /*16*/ unsigned int data_count;
  577. /*20*/ unsigned int SCSI_cmd_pointer;
  578. /*24*/ unsigned char SCSI_cmd_length;
  579. /*25*/ unsigned char tag; /* Index into our kernel SCB array.
  580. * Also used as the tag for tagged I/O
  581. */
  582. #define SCB_PIO_TRANSFER_SIZE 26 /* amount we need to upload/download
  583. * via PIO to initialize a transaction.
  584. */
  585. /*26*/ unsigned char next; /* Used to thread SCBs awaiting selection
  586. * or disconnected down in the sequencer.
  587. */
  588. /*27*/ unsigned char prev;
  589. /*28*/ unsigned int pad; /*
  590. * Unused by the kernel, but we require
  591. * the padding so that the array of
  592. * hardware SCBs is aligned on 32 byte
  593. * boundaries so the sequencer can index
  594. */
  595. };
  596. typedef enum {
  597. SCB_FREE = 0x0000,
  598. SCB_DTR_SCB = 0x0001,
  599. SCB_WAITINGQ = 0x0002,
  600. SCB_ACTIVE = 0x0004,
  601. SCB_SENSE = 0x0008,
  602. SCB_ABORT = 0x0010,
  603. SCB_DEVICE_RESET = 0x0020,
  604. SCB_RESET = 0x0040,
  605. SCB_RECOVERY_SCB = 0x0080,
  606. SCB_MSGOUT_PPR = 0x0100,
  607. SCB_MSGOUT_SENT = 0x0200,
  608. SCB_MSGOUT_SDTR = 0x0400,
  609. SCB_MSGOUT_WDTR = 0x0800,
  610. SCB_MSGOUT_BITS = SCB_MSGOUT_PPR |
  611. SCB_MSGOUT_SENT |
  612. SCB_MSGOUT_SDTR |
  613. SCB_MSGOUT_WDTR,
  614. SCB_QUEUED_ABORT = 0x1000,
  615. SCB_QUEUED_FOR_DONE = 0x2000,
  616. SCB_WAS_BUSY = 0x4000,
  617. SCB_QUEUE_FULL = 0x8000
  618. } scb_flag_type;
  619. typedef enum {
  620. AHC_FNONE = 0x00000000,
  621. AHC_PAGESCBS = 0x00000001,
  622. AHC_CHANNEL_B_PRIMARY = 0x00000002,
  623. AHC_USEDEFAULTS = 0x00000004,
  624. AHC_INDIRECT_PAGING = 0x00000008,
  625. AHC_CHNLB = 0x00000020,
  626. AHC_CHNLC = 0x00000040,
  627. AHC_EXTEND_TRANS_A = 0x00000100,
  628. AHC_EXTEND_TRANS_B = 0x00000200,
  629. AHC_TERM_ENB_A = 0x00000400,
  630. AHC_TERM_ENB_SE_LOW = 0x00000400,
  631. AHC_TERM_ENB_B = 0x00000800,
  632. AHC_TERM_ENB_SE_HIGH = 0x00000800,
  633. AHC_HANDLING_REQINITS = 0x00001000,
  634. AHC_TARGETMODE = 0x00002000,
  635. AHC_NEWEEPROM_FMT = 0x00004000,
  636. /*
  637. * Here ends the FreeBSD defined flags and here begins the linux defined
  638. * flags. NOTE: I did not preserve the old flag name during this change
  639. * specifically to force me to evaluate what flags were being used properly
  640. * and what flags weren't. This way, I could clean up the flag usage on
  641. * a use by use basis. Doug Ledford
  642. */
  643. AHC_MOTHERBOARD = 0x00020000,
  644. AHC_NO_STPWEN = 0x00040000,
  645. AHC_RESET_DELAY = 0x00080000,
  646. AHC_A_SCANNED = 0x00100000,
  647. AHC_B_SCANNED = 0x00200000,
  648. AHC_MULTI_CHANNEL = 0x00400000,
  649. AHC_BIOS_ENABLED = 0x00800000,
  650. AHC_SEEPROM_FOUND = 0x01000000,
  651. AHC_TERM_ENB_LVD = 0x02000000,
  652. AHC_ABORT_PENDING = 0x04000000,
  653. AHC_RESET_PENDING = 0x08000000,
  654. #define AHC_IN_ISR_BIT 28
  655. AHC_IN_ISR = 0x10000000,
  656. AHC_IN_ABORT = 0x20000000,
  657. AHC_IN_RESET = 0x40000000,
  658. AHC_EXTERNAL_SRAM = 0x80000000
  659. } ahc_flag_type;
  660. typedef enum {
  661. AHC_NONE = 0x0000,
  662. AHC_CHIPID_MASK = 0x00ff,
  663. AHC_AIC7770 = 0x0001,
  664. AHC_AIC7850 = 0x0002,
  665. AHC_AIC7860 = 0x0003,
  666. AHC_AIC7870 = 0x0004,
  667. AHC_AIC7880 = 0x0005,
  668. AHC_AIC7890 = 0x0006,
  669. AHC_AIC7895 = 0x0007,
  670. AHC_AIC7896 = 0x0008,
  671. AHC_AIC7892 = 0x0009,
  672. AHC_AIC7899 = 0x000a,
  673. AHC_VL = 0x0100,
  674. AHC_EISA = 0x0200,
  675. AHC_PCI = 0x0400,
  676. } ahc_chip;
  677. typedef enum {
  678. AHC_FENONE = 0x0000,
  679. AHC_ULTRA = 0x0001,
  680. AHC_ULTRA2 = 0x0002,
  681. AHC_WIDE = 0x0004,
  682. AHC_TWIN = 0x0008,
  683. AHC_MORE_SRAM = 0x0010,
  684. AHC_CMD_CHAN = 0x0020,
  685. AHC_QUEUE_REGS = 0x0040,
  686. AHC_SG_PRELOAD = 0x0080,
  687. AHC_SPIOCAP = 0x0100,
  688. AHC_ULTRA3 = 0x0200,
  689. AHC_NEW_AUTOTERM = 0x0400,
  690. AHC_AIC7770_FE = AHC_FENONE,
  691. AHC_AIC7850_FE = AHC_SPIOCAP,
  692. AHC_AIC7860_FE = AHC_ULTRA|AHC_SPIOCAP,
  693. AHC_AIC7870_FE = AHC_FENONE,
  694. AHC_AIC7880_FE = AHC_ULTRA,
  695. AHC_AIC7890_FE = AHC_MORE_SRAM|AHC_CMD_CHAN|AHC_ULTRA2|
  696. AHC_QUEUE_REGS|AHC_SG_PRELOAD|AHC_NEW_AUTOTERM,
  697. AHC_AIC7895_FE = AHC_MORE_SRAM|AHC_CMD_CHAN|AHC_ULTRA,
  698. AHC_AIC7896_FE = AHC_AIC7890_FE,
  699. AHC_AIC7892_FE = AHC_AIC7890_FE|AHC_ULTRA3,
  700. AHC_AIC7899_FE = AHC_AIC7890_FE|AHC_ULTRA3,
  701. } ahc_feature;
  702. #define SCB_DMA_ADDR(scb, addr) ((unsigned long)(addr) + (scb)->scb_dma->dma_offset)
  703. struct aic7xxx_scb_dma {
  704. unsigned long dma_offset; /* Correction you have to add
  705. * to virtual address to get
  706. * dma handle in this region */
  707. dma_addr_t dma_address; /* DMA handle of the start,
  708. * for unmap */
  709. unsigned int dma_len; /* DMA length */
  710. };
  711. typedef enum {
  712. AHC_BUG_NONE = 0x0000,
  713. AHC_BUG_TMODE_WIDEODD = 0x0001,
  714. AHC_BUG_AUTOFLUSH = 0x0002,
  715. AHC_BUG_CACHETHEN = 0x0004,
  716. AHC_BUG_CACHETHEN_DIS = 0x0008,
  717. AHC_BUG_PCI_2_1_RETRY = 0x0010,
  718. AHC_BUG_PCI_MWI = 0x0020,
  719. AHC_BUG_SCBCHAN_UPLOAD = 0x0040,
  720. } ahc_bugs;
  721. struct aic7xxx_scb {
  722. struct aic7xxx_hwscb *hscb; /* corresponding hardware scb */
  723. struct scsi_cmnd *cmd; /* scsi_cmnd for this scb */
  724. struct aic7xxx_scb *q_next; /* next scb in queue */
  725. volatile scb_flag_type flags; /* current state of scb */
  726. struct hw_scatterlist *sg_list; /* SG list in adapter format */
  727. unsigned char tag_action;
  728. unsigned char sg_count;
  729. unsigned char *sense_cmd; /*
  730. * Allocate 6 characters for
  731. * sense command.
  732. */
  733. unsigned char *cmnd;
  734. unsigned int sg_length; /*
  735. * We init this during
  736. * buildscb so we don't have
  737. * to calculate anything during
  738. * underflow/overflow/stat code
  739. */
  740. void *kmalloc_ptr;
  741. struct aic7xxx_scb_dma *scb_dma;
  742. };
  743. /*
  744. * Define a linked list of SCBs.
  745. */
  746. typedef struct {
  747. struct aic7xxx_scb *head;
  748. struct aic7xxx_scb *tail;
  749. } scb_queue_type;
  750. static struct {
  751. unsigned char errno;
  752. const char *errmesg;
  753. } hard_error[] = {
  754. { ILLHADDR, "Illegal Host Access" },
  755. { ILLSADDR, "Illegal Sequencer Address referenced" },
  756. { ILLOPCODE, "Illegal Opcode in sequencer program" },
  757. { SQPARERR, "Sequencer Ram Parity Error" },
  758. { DPARERR, "Data-Path Ram Parity Error" },
  759. { MPARERR, "Scratch Ram/SCB Array Ram Parity Error" },
  760. { PCIERRSTAT,"PCI Error detected" },
  761. { CIOPARERR, "CIOBUS Parity Error" }
  762. };
  763. static unsigned char
  764. generic_sense[] = { REQUEST_SENSE, 0, 0, 0, 255, 0 };
  765. typedef struct {
  766. scb_queue_type free_scbs; /*
  767. * SCBs assigned to free slot on
  768. * card (no paging required)
  769. */
  770. struct aic7xxx_scb *scb_array[AIC7XXX_MAXSCB];
  771. struct aic7xxx_hwscb *hscbs;
  772. unsigned char numscbs; /* current number of scbs */
  773. unsigned char maxhscbs; /* hardware scbs */
  774. unsigned char maxscbs; /* max scbs including pageable scbs */
  775. dma_addr_t hscbs_dma; /* DMA handle to hscbs */
  776. unsigned int hscbs_dma_len; /* length of the above DMA area */
  777. void *hscb_kmalloc_ptr;
  778. } scb_data_type;
  779. struct target_cmd {
  780. unsigned char mesg_bytes[4];
  781. unsigned char command[28];
  782. };
  783. #define AHC_TRANS_CUR 0x0001
  784. #define AHC_TRANS_ACTIVE 0x0002
  785. #define AHC_TRANS_GOAL 0x0004
  786. #define AHC_TRANS_USER 0x0008
  787. #define AHC_TRANS_QUITE 0x0010
  788. typedef struct {
  789. unsigned char width;
  790. unsigned char period;
  791. unsigned char offset;
  792. unsigned char options;
  793. } transinfo_type;
  794. struct aic_dev_data {
  795. volatile scb_queue_type delayed_scbs;
  796. volatile unsigned short temp_q_depth;
  797. unsigned short max_q_depth;
  798. volatile unsigned char active_cmds;
  799. /*
  800. * Statistics Kept:
  801. *
  802. * Total Xfers (count for each command that has a data xfer),
  803. * broken down by reads && writes.
  804. *
  805. * Further sorted into a few bins for keeping tabs on how many commands
  806. * we get of various sizes.
  807. *
  808. */
  809. long w_total; /* total writes */
  810. long r_total; /* total reads */
  811. long barrier_total; /* total num of REQ_BARRIER commands */
  812. long ordered_total; /* How many REQ_BARRIER commands we
  813. used ordered tags to satisfy */
  814. long w_bins[6]; /* binned write */
  815. long r_bins[6]; /* binned reads */
  816. transinfo_type cur;
  817. transinfo_type goal;
  818. #define BUS_DEVICE_RESET_PENDING 0x01
  819. #define DEVICE_RESET_DELAY 0x02
  820. #define DEVICE_PRINT_DTR 0x04
  821. #define DEVICE_WAS_BUSY 0x08
  822. #define DEVICE_DTR_SCANNED 0x10
  823. #define DEVICE_SCSI_3 0x20
  824. volatile unsigned char flags;
  825. unsigned needppr:1;
  826. unsigned needppr_copy:1;
  827. unsigned needsdtr:1;
  828. unsigned needsdtr_copy:1;
  829. unsigned needwdtr:1;
  830. unsigned needwdtr_copy:1;
  831. unsigned dtr_pending:1;
  832. struct scsi_device *SDptr;
  833. struct list_head list;
  834. };
  835. /*
  836. * Define a structure used for each host adapter. Note, in order to avoid
  837. * problems with architectures I can't test on (because I don't have one,
  838. * such as the Alpha based systems) which happen to give faults for
  839. * non-aligned memory accesses, care was taken to align this structure
  840. * in a way that guaranteed all accesses larger than 8 bits were aligned
  841. * on the appropriate boundary. It's also organized to try and be more
  842. * cache line efficient. Be careful when changing this lest you might hurt
  843. * overall performance and bring down the wrath of the masses.
  844. */
  845. struct aic7xxx_host {
  846. /*
  847. * This is the first 64 bytes in the host struct
  848. */
  849. /*
  850. * We are grouping things here....first, items that get either read or
  851. * written with nearly every interrupt
  852. */
  853. volatile long flags;
  854. ahc_feature features; /* chip features */
  855. unsigned long base; /* card base address */
  856. volatile unsigned char __iomem *maddr; /* memory mapped address */
  857. unsigned long isr_count; /* Interrupt count */
  858. unsigned long spurious_int;
  859. scb_data_type *scb_data;
  860. struct aic7xxx_cmd_queue {
  861. struct scsi_cmnd *head;
  862. struct scsi_cmnd *tail;
  863. } completeq;
  864. /*
  865. * Things read/written on nearly every entry into aic7xxx_queue()
  866. */
  867. volatile scb_queue_type waiting_scbs;
  868. unsigned char unpause; /* unpause value for HCNTRL */
  869. unsigned char pause; /* pause value for HCNTRL */
  870. volatile unsigned char qoutfifonext;
  871. volatile unsigned char activescbs; /* active scbs */
  872. volatile unsigned char max_activescbs;
  873. volatile unsigned char qinfifonext;
  874. volatile unsigned char *untagged_scbs;
  875. volatile unsigned char *qoutfifo;
  876. volatile unsigned char *qinfifo;
  877. unsigned char dev_last_queue_full[MAX_TARGETS];
  878. unsigned char dev_last_queue_full_count[MAX_TARGETS];
  879. unsigned short ultraenb; /* Gets downloaded to card as a bitmap */
  880. unsigned short discenable; /* Gets downloaded to card as a bitmap */
  881. transinfo_type user[MAX_TARGETS];
  882. unsigned char msg_buf[13]; /* The message for the target */
  883. unsigned char msg_type;
  884. #define MSG_TYPE_NONE 0x00
  885. #define MSG_TYPE_INITIATOR_MSGOUT 0x01
  886. #define MSG_TYPE_INITIATOR_MSGIN 0x02
  887. unsigned char msg_len; /* Length of message */
  888. unsigned char msg_index; /* Index into msg_buf array */
  889. /*
  890. * We put the less frequently used host structure items
  891. * after the more frequently used items to try and ease
  892. * the burden on the cache subsystem.
  893. * These entries are not *commonly* accessed, whereas
  894. * the preceding entries are accessed very often.
  895. */
  896. unsigned int irq; /* IRQ for this adapter */
  897. int instance; /* aic7xxx instance number */
  898. int scsi_id; /* host adapter SCSI ID */
  899. int scsi_id_b; /* channel B for twin adapters */
  900. unsigned int bios_address;
  901. int board_name_index;
  902. unsigned short bios_control; /* bios control - SEEPROM */
  903. unsigned short adapter_control; /* adapter control - SEEPROM */
  904. struct pci_dev *pdev;
  905. unsigned char pci_bus;
  906. unsigned char pci_device_fn;
  907. struct seeprom_config sc;
  908. unsigned short sc_type;
  909. unsigned short sc_size;
  910. struct aic7xxx_host *next; /* allow for multiple IRQs */
  911. struct Scsi_Host *host; /* pointer to scsi host */
  912. struct list_head aic_devs; /* all aic_dev structs on host */
  913. int host_no; /* SCSI host number */
  914. unsigned long mbase; /* I/O memory address */
  915. ahc_chip chip; /* chip type */
  916. ahc_bugs bugs;
  917. dma_addr_t fifo_dma; /* DMA handle for fifo arrays */
  918. };
  919. /*
  920. * Valid SCSIRATE values. (p. 3-17)
  921. * Provides a mapping of transfer periods in ns/4 to the proper value to
  922. * stick in the SCSIRATE reg to use that transfer rate.
  923. */
  924. #define AHC_SYNCRATE_ULTRA3 0
  925. #define AHC_SYNCRATE_ULTRA2 1
  926. #define AHC_SYNCRATE_ULTRA 3
  927. #define AHC_SYNCRATE_FAST 6
  928. #define AHC_SYNCRATE_CRC 0x40
  929. #define AHC_SYNCRATE_SE 0x10
  930. static struct aic7xxx_syncrate {
  931. /* Rates in Ultra mode have bit 8 of sxfr set */
  932. #define ULTRA_SXFR 0x100
  933. int sxfr_ultra2;
  934. int sxfr;
  935. unsigned char period;
  936. const char *rate[2];
  937. } aic7xxx_syncrates[] = {
  938. { 0x42, 0x000, 9, {"80.0", "160.0"} },
  939. { 0x13, 0x000, 10, {"40.0", "80.0"} },
  940. { 0x14, 0x000, 11, {"33.0", "66.6"} },
  941. { 0x15, 0x100, 12, {"20.0", "40.0"} },
  942. { 0x16, 0x110, 15, {"16.0", "32.0"} },
  943. { 0x17, 0x120, 18, {"13.4", "26.8"} },
  944. { 0x18, 0x000, 25, {"10.0", "20.0"} },
  945. { 0x19, 0x010, 31, {"8.0", "16.0"} },
  946. { 0x1a, 0x020, 37, {"6.67", "13.3"} },
  947. { 0x1b, 0x030, 43, {"5.7", "11.4"} },
  948. { 0x10, 0x040, 50, {"5.0", "10.0"} },
  949. { 0x00, 0x050, 56, {"4.4", "8.8" } },
  950. { 0x00, 0x060, 62, {"4.0", "8.0" } },
  951. { 0x00, 0x070, 68, {"3.6", "7.2" } },
  952. { 0x00, 0x000, 0, {NULL, NULL} },
  953. };
  954. #define CTL_OF_SCB(scb) (((scb->hscb)->target_channel_lun >> 3) & 0x1), \
  955. (((scb->hscb)->target_channel_lun >> 4) & 0xf), \
  956. ((scb->hscb)->target_channel_lun & 0x07)
  957. #define CTL_OF_CMD(cmd) ((cmd->device->channel) & 0x01), \
  958. ((cmd->device->id) & 0x0f), \
  959. ((cmd->device->lun) & 0x07)
  960. #define TARGET_INDEX(cmd) ((cmd)->device->id | ((cmd)->device->channel << 3))
  961. /*
  962. * A nice little define to make doing our printks a little easier
  963. */
  964. #define WARN_LEAD KERN_WARNING "(scsi%d:%d:%d:%d) "
  965. #define INFO_LEAD KERN_INFO "(scsi%d:%d:%d:%d) "
  966. /*
  967. * XXX - these options apply unilaterally to _all_ 274x/284x/294x
  968. * cards in the system. This should be fixed. Exceptions to this
  969. * rule are noted in the comments.
  970. */
  971. /*
  972. * Use this as the default queue depth when setting tagged queueing on.
  973. */
  974. static unsigned int aic7xxx_default_queue_depth = AIC7XXX_CMDS_PER_DEVICE;
  975. /*
  976. * Skip the scsi bus reset. Non 0 make us skip the reset at startup. This
  977. * has no effect on any later resets that might occur due to things like
  978. * SCSI bus timeouts.
  979. */
  980. static unsigned int aic7xxx_no_reset = 0;
  981. /*
  982. * Certain PCI motherboards will scan PCI devices from highest to lowest,
  983. * others scan from lowest to highest, and they tend to do all kinds of
  984. * strange things when they come into contact with PCI bridge chips. The
  985. * net result of all this is that the PCI card that is actually used to boot
  986. * the machine is very hard to detect. Most motherboards go from lowest
  987. * PCI slot number to highest, and the first SCSI controller found is the
  988. * one you boot from. The only exceptions to this are when a controller
  989. * has its BIOS disabled. So, we by default sort all of our SCSI controllers
  990. * from lowest PCI slot number to highest PCI slot number. We also force
  991. * all controllers with their BIOS disabled to the end of the list. This
  992. * works on *almost* all computers. Where it doesn't work, we have this
  993. * option. Setting this option to non-0 will reverse the order of the sort
  994. * to highest first, then lowest, but will still leave cards with their BIOS
  995. * disabled at the very end. That should fix everyone up unless there are
  996. * really strange cirumstances.
  997. */
  998. static int aic7xxx_reverse_scan = 0;
  999. /*
  1000. * Should we force EXTENDED translation on a controller.
  1001. * 0 == Use whatever is in the SEEPROM or default to off
  1002. * 1 == Use whatever is in the SEEPROM or default to on
  1003. */
  1004. static unsigned int aic7xxx_extended = 0;
  1005. /*
  1006. * The IRQ trigger method used on EISA controllers. Does not effect PCI cards.
  1007. * -1 = Use detected settings.
  1008. * 0 = Force Edge triggered mode.
  1009. * 1 = Force Level triggered mode.
  1010. */
  1011. static int aic7xxx_irq_trigger = -1;
  1012. /*
  1013. * This variable is used to override the termination settings on a controller.
  1014. * This should not be used under normal conditions. However, in the case
  1015. * that a controller does not have a readable SEEPROM (so that we can't
  1016. * read the SEEPROM settings directly) and that a controller has a buggered
  1017. * version of the cable detection logic, this can be used to force the
  1018. * correct termination. It is preferable to use the manual termination
  1019. * settings in the BIOS if possible, but some motherboard controllers store
  1020. * those settings in a format we can't read. In other cases, auto term
  1021. * should also work, but the chipset was put together with no auto term
  1022. * logic (common on motherboard controllers). In those cases, we have
  1023. * 32 bits here to work with. That's good for 8 controllers/channels. The
  1024. * bits are organized as 4 bits per channel, with scsi0 getting the lowest
  1025. * 4 bits in the int. A 1 in a bit position indicates the termination setting
  1026. * that corresponds to that bit should be enabled, a 0 is disabled.
  1027. * It looks something like this:
  1028. *
  1029. * 0x0f = 1111-Single Ended Low Byte Termination on/off
  1030. * ||\-Single Ended High Byte Termination on/off
  1031. * |\-LVD Low Byte Termination on/off
  1032. * \-LVD High Byte Termination on/off
  1033. *
  1034. * For non-Ultra2 controllers, the upper 2 bits are not important. So, to
  1035. * enable both high byte and low byte termination on scsi0, I would need to
  1036. * make sure that the override_term variable was set to 0x03 (bits 0011).
  1037. * To make sure that all termination is enabled on an Ultra2 controller at
  1038. * scsi2 and only high byte termination on scsi1 and high and low byte
  1039. * termination on scsi0, I would set override_term=0xf23 (bits 1111 0010 0011)
  1040. *
  1041. * For the most part, users should never have to use this, that's why I
  1042. * left it fairly cryptic instead of easy to understand. If you need it,
  1043. * most likely someone will be telling you what your's needs to be set to.
  1044. */
  1045. static int aic7xxx_override_term = -1;
  1046. /*
  1047. * Certain motherboard chipset controllers tend to screw
  1048. * up the polarity of the term enable output pin. Use this variable
  1049. * to force the correct polarity for your system. This is a bitfield variable
  1050. * similar to the previous one, but this one has one bit per channel instead
  1051. * of four.
  1052. * 0 = Force the setting to active low.
  1053. * 1 = Force setting to active high.
  1054. * Most Adaptec cards are active high, several motherboards are active low.
  1055. * To force a 2940 card at SCSI 0 to active high and a motherboard 7895
  1056. * controller at scsi1 and scsi2 to active low, and a 2910 card at scsi3
  1057. * to active high, you would need to set stpwlev=0x9 (bits 1001).
  1058. *
  1059. * People shouldn't need to use this, but if you are experiencing lots of
  1060. * SCSI timeout problems, this may help. There is one sure way to test what
  1061. * this option needs to be. Using a boot floppy to boot the system, configure
  1062. * your system to enable all SCSI termination (in the Adaptec SCSI BIOS) and
  1063. * if needed then also pass a value to override_term to make sure that the
  1064. * driver is enabling SCSI termination, then set this variable to either 0
  1065. * or 1. When the driver boots, make sure there are *NO* SCSI cables
  1066. * connected to your controller. If it finds and inits the controller
  1067. * without problem, then the setting you passed to stpwlev was correct. If
  1068. * the driver goes into a reset loop and hangs the system, then you need the
  1069. * other setting for this variable. If neither setting lets the machine
  1070. * boot then you have definite termination problems that may not be fixable.
  1071. */
  1072. static int aic7xxx_stpwlev = -1;
  1073. /*
  1074. * Set this to non-0 in order to force the driver to panic the kernel
  1075. * and print out debugging info on a SCSI abort or reset cycle.
  1076. */
  1077. static int aic7xxx_panic_on_abort = 0;
  1078. /*
  1079. * PCI bus parity checking of the Adaptec controllers. This is somewhat
  1080. * dubious at best. To my knowledge, this option has never actually
  1081. * solved a PCI parity problem, but on certain machines with broken PCI
  1082. * chipset configurations, it can generate tons of false error messages.
  1083. * It's included in the driver for completeness.
  1084. * 0 = Shut off PCI parity check
  1085. * -1 = Normal polarity pci parity checking
  1086. * 1 = reverse polarity pci parity checking
  1087. *
  1088. * NOTE: you can't actually pass -1 on the lilo prompt. So, to set this
  1089. * variable to -1 you would actually want to simply pass the variable
  1090. * name without a number. That will invert the 0 which will result in
  1091. * -1.
  1092. */
  1093. static int aic7xxx_pci_parity = 0;
  1094. /*
  1095. * Set this to any non-0 value to cause us to dump the contents of all
  1096. * the card's registers in a hex dump format tailored to each model of
  1097. * controller.
  1098. *
  1099. * NOTE: THE CONTROLLER IS LEFT IN AN UNUSABLE STATE BY THIS OPTION.
  1100. * YOU CANNOT BOOT UP WITH THIS OPTION, IT IS FOR DEBUGGING PURPOSES
  1101. * ONLY
  1102. */
  1103. static int aic7xxx_dump_card = 0;
  1104. /*
  1105. * Set this to a non-0 value to make us dump out the 32 bit instruction
  1106. * registers on the card after completing the sequencer download. This
  1107. * allows the actual sequencer download to be verified. It is possible
  1108. * to use this option and still boot up and run your system. This is
  1109. * only intended for debugging purposes.
  1110. */
  1111. static int aic7xxx_dump_sequencer = 0;
  1112. /*
  1113. * Certain newer motherboards have put new PCI based devices into the
  1114. * IO spaces that used to typically be occupied by VLB or EISA cards.
  1115. * This overlap can cause these newer motherboards to lock up when scanned
  1116. * for older EISA and VLB devices. Setting this option to non-0 will
  1117. * cause the driver to skip scanning for any VLB or EISA controllers and
  1118. * only support the PCI controllers. NOTE: this means that if the kernel
  1119. * os compiled with PCI support disabled, then setting this to non-0
  1120. * would result in never finding any devices :)
  1121. */
  1122. static int aic7xxx_no_probe = 0;
  1123. /*
  1124. * On some machines, enabling the external SCB RAM isn't reliable yet. I
  1125. * haven't had time to make test patches for things like changing the
  1126. * timing mode on that external RAM either. Some of those changes may
  1127. * fix the problem. Until then though, we default to external SCB RAM
  1128. * off and give a command line option to enable it.
  1129. */
  1130. static int aic7xxx