PageRenderTime 105ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 1ms

/drivers/scsi/aic7xxx_old.c

http://github.com/mirrors/linux
C | 11149 lines | 7575 code | 746 blank | 2828 comment | 1306 complexity | 2ded740f1a053ab0a938f4dc27975484 MD5 | raw file
Possible License(s): AGPL-1.0, GPL-2.0, LGPL-2.0
  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_scbram = 0;
  1131. /*
  1132. * So that we can set how long each device is given as a selection timeout.
  1133. * The table of values goes like this:
  1134. * 0 - 256ms
  1135. * 1 - 128ms
  1136. * 2 - 64ms
  1137. * 3 - 32ms
  1138. * We default to 64ms because it's fast. Some old SCSI-I devices need a
  1139. * longer time. The final value has to be left shifted by 3, hence 0x10
  1140. * is the final value.
  1141. */
  1142. static int aic7xxx_seltime = 0x10;
  1143. /*
  1144. * So that insmod can find the variable and make it point to something
  1145. */
  1146. #ifdef MODULE
  1147. static char * aic7xxx = NULL;
  1148. module_param(aic7xxx, charp, 0);
  1149. #endif
  1150. #define VERBOSE_NORMAL 0x0000
  1151. #define VERBOSE_NEGOTIATION 0x0001
  1152. #define VERBOSE_SEQINT 0x0002
  1153. #define VERBOSE_SCSIINT 0x0004
  1154. #define VERBOSE_PROBE 0x0008
  1155. #define VERBOSE_PROBE2 0x0010
  1156. #define VERBOSE_NEGOTIATION2 0x0020
  1157. #define VERBOSE_MINOR_ERROR 0x0040
  1158. #define VERBOSE_TRACING 0x0080
  1159. #define VERBOSE_ABORT 0x0f00
  1160. #define VERBOSE_ABORT_MID 0x0100
  1161. #define VERBOSE_ABORT_FIND 0x0200
  1162. #define VERBOSE_ABORT_PROCESS 0x0400
  1163. #define VERBOSE_ABORT_RETURN 0x0800
  1164. #define VERBOSE_RESET 0xf000
  1165. #define VERBOSE_RESET_MID 0x1000
  1166. #define VERBOSE_RESET_FIND 0x2000
  1167. #define VERBOSE_RESET_PROCESS 0x4000
  1168. #define VERBOSE_RESET_RETURN 0x8000
  1169. static int aic7xxx_verbose = VERBOSE_NORMAL | VERBOSE_NEGOTIATION |
  1170. VERBOSE_PROBE; /* verbose messages */
  1171. /****************************************************************************
  1172. *
  1173. * We're going to start putting in function declarations so that order of
  1174. * functions is no longer important. As needed, they are added here.
  1175. *
  1176. ***************************************************************************/
  1177. static int aic7xxx_release(struct Scsi_Host *host);
  1178. static void aic7xxx_set_syncrate(struct aic7xxx_host *p,
  1179. struct aic7xxx_syncrate *syncrate, int target, int channel,
  1180. unsigned int period, unsigned int offset, unsigned char options,
  1181. unsigned int type, struct aic_dev_data *aic_dev);
  1182. static void aic7xxx_set_width(struct aic7xxx_host *p, int target, int channel,
  1183. int lun, unsigned int width, unsigned int type,
  1184. struct aic_dev_data *aic_dev);
  1185. static void aic7xxx_panic_abort(struct aic7xxx_host *p, struct scsi_cmnd *cmd);
  1186. static void aic7xxx_print_card(struct aic7xxx_host *p);
  1187. static void aic7xxx_print_scratch_ram(struct aic7xxx_host *p);
  1188. static void aic7xxx_print_sequencer(struct aic7xxx_host *p, int downloaded);
  1189. #ifdef AIC7XXX_VERBOSE_DEBUGGING
  1190. static void aic7xxx_check_scbs(struct aic7xxx_host *p, char *buffer);
  1191. #endif
  1192. /****************************************************************************
  1193. *
  1194. * These functions are now used. They happen to be wrapped in useless
  1195. * inb/outb port read/writes around the real reads and writes because it
  1196. * seems that certain very fast CPUs have a problem dealing with us when
  1197. * going at full speed.
  1198. *
  1199. ***************************************************************************/
  1200. static unsigned char
  1201. aic_inb(struct aic7xxx_host *p, long port)
  1202. {
  1203. #ifdef MMAPIO
  1204. unsigned char x;
  1205. if(p->maddr)
  1206. {
  1207. x = readb(p->maddr + port);
  1208. }
  1209. else
  1210. {
  1211. x = inb(p->base + port);
  1212. }
  1213. return(x);
  1214. #else
  1215. return(inb(p->base + port));
  1216. #endif
  1217. }
  1218. static void
  1219. aic_outb(struct aic7xxx_host *p, unsigned char val, long port)
  1220. {
  1221. #ifdef MMAPIO
  1222. if(p->maddr)
  1223. {
  1224. writeb(val, p->maddr + port);
  1225. mb(); /* locked operation in order to force CPU ordering */
  1226. readb(p->maddr + HCNTRL); /* dummy read to flush the PCI write */
  1227. }
  1228. else
  1229. {
  1230. outb(val, p->base + port);
  1231. mb(); /* locked operation in order to force CPU ordering */
  1232. }
  1233. #else
  1234. outb(val, p->base + port);
  1235. mb(); /* locked operation in order to force CPU ordering */
  1236. #endif
  1237. }
  1238. /*+F*************************************************************************
  1239. * Function:
  1240. * aic7xxx_setup
  1241. *
  1242. * Description:
  1243. * Handle Linux boot parameters. This routine allows for assigning a value
  1244. * to a parameter with a ':' between the parameter and the value.
  1245. * ie. aic7xxx=unpause:0x0A,extended
  1246. *-F*************************************************************************/
  1247. static int
  1248. aic7xxx_setup(char *s)
  1249. {
  1250. int i, n;
  1251. char *p;
  1252. char *end;
  1253. static struct {
  1254. const char *name;
  1255. unsigned int *flag;
  1256. } options[] = {
  1257. { "extended", &aic7xxx_extended },
  1258. { "no_reset", &aic7xxx_no_reset },
  1259. { "irq_trigger", &aic7xxx_irq_trigger },
  1260. { "verbose", &aic7xxx_verbose },
  1261. { "reverse_scan",&aic7xxx_reverse_scan },
  1262. { "override_term", &aic7xxx_override_term },
  1263. { "stpwlev", &aic7xxx_stpwlev },
  1264. { "no_probe", &aic7xxx_no_probe },
  1265. { "panic_on_abort", &aic7xxx_panic_on_abort },
  1266. { "pci_parity", &aic7xxx_pci_parity },
  1267. { "dump_card", &aic7xxx_dump_card },
  1268. { "dump_sequencer", &aic7xxx_dump_sequencer },
  1269. { "default_queue_depth", &aic7xxx_default_queue_depth },
  1270. { "scbram", &aic7xxx_scbram },
  1271. { "seltime", &aic7xxx_seltime },
  1272. { "tag_info", NULL }
  1273. };
  1274. end = strchr(s, '\0');
  1275. while ((p = strsep(&s, ",.")) != NULL)
  1276. {
  1277. for (i = 0; i < ARRAY_SIZE(options); i++)
  1278. {
  1279. n = strlen(options[i].name);
  1280. if (!strncmp(options[i].name, p, n))
  1281. {
  1282. if (!strncmp(p, "tag_info", n))
  1283. {
  1284. if (p[n] == ':')
  1285. {
  1286. char *base;
  1287. char *tok, *tok_end, *tok_end2;
  1288. char tok_list[] = { '.', ',', '{', '}', '\0' };
  1289. int i, instance = -1, device = -1;
  1290. unsigned char done = FALSE;
  1291. base = p;
  1292. tok = base + n + 1; /* Forward us just past the ':' */
  1293. tok_end = strchr(tok, '\0');
  1294. if (tok_end < end)
  1295. *tok_end = ',';
  1296. while(!done)
  1297. {
  1298. switch(*tok)
  1299. {
  1300. case '{':
  1301. if (instance == -1)
  1302. instance = 0;
  1303. else if (device == -1)
  1304. device = 0;
  1305. tok++;
  1306. break;
  1307. case '}':
  1308. if (device != -1)
  1309. device = -1;
  1310. else if (instance != -1)
  1311. instance = -1;
  1312. tok++;
  1313. break;
  1314. case ',':
  1315. case '.':
  1316. if (instance == -1)
  1317. done = TRUE;
  1318. else if (device >= 0)
  1319. device++;
  1320. else if (instance >= 0)
  1321. instance++;
  1322. if ( (device >= MAX_TARGETS) ||
  1323. (instance >= ARRAY_SIZE(aic7xxx_tag_info)) )
  1324. done = TRUE;
  1325. tok++;
  1326. if (!done)
  1327. {
  1328. base = tok;
  1329. }
  1330. break;
  1331. case '\0':
  1332. done = TRUE;
  1333. break;
  1334. default:
  1335. done = TRUE;
  1336. tok_end = strchr(tok, '\0');
  1337. for(i=0; tok_list[i]; i++)
  1338. {
  1339. tok_end2 = strchr(tok, tok_list[i]);
  1340. if ( (tok_end2) && (tok_end2 < tok_end) )
  1341. {
  1342. tok_end = tok_end2;
  1343. done = FALSE;
  1344. }
  1345. }
  1346. if ( (instance >= 0) && (device >= 0) &&
  1347. (instance < ARRAY_SIZE(aic7xxx_tag_info)) &&
  1348. (device < MAX_TARGETS) )
  1349. aic7xxx_tag_info[instance].tag_commands[device] =
  1350. simple_strtoul(tok, NULL, 0) & 0xff;
  1351. tok = tok_end;
  1352. break;
  1353. }
  1354. }
  1355. while((p != base) && (p != NULL))
  1356. p = strsep(&s, ",.");
  1357. }
  1358. }
  1359. else if (p[n] == ':')
  1360. {
  1361. *(options[i].flag) = simple_strtoul(p + n + 1, NULL, 0);
  1362. if(!strncmp(p, "seltime", n))
  1363. {
  1364. *(options[i].flag) = (*(options[i].flag) % 4) << 3;
  1365. }
  1366. }
  1367. else if (!strncmp(p, "verbose", n))
  1368. {
  1369. *(options[i].flag) = 0xff29;
  1370. }
  1371. else
  1372. {
  1373. *(options[i].flag) = ~(*(options[i].flag));
  1374. if(!strncmp(p, "seltime", n))
  1375. {
  1376. *(options[i].flag) = (*(options[i].flag) % 4) << 3;
  1377. }
  1378. }
  1379. }
  1380. }
  1381. }
  1382. return 1;
  1383. }
  1384. __setup("aic7xxx=", aic7xxx_setup);
  1385. /*+F*************************************************************************
  1386. * Function:
  1387. * pause_sequencer
  1388. *
  1389. * Description:
  1390. * Pause the sequencer and wait for it to actually stop - this
  1391. * is important since the sequencer can disable pausing for critical
  1392. * sections.
  1393. *-F*************************************************************************/
  1394. static void
  1395. pause_sequencer(struct aic7xxx_host *p)
  1396. {
  1397. aic_outb(p, p->pause, HCNTRL);
  1398. while ((aic_inb(p, HCNTRL) & PAUSE) == 0)
  1399. {
  1400. ;
  1401. }
  1402. if(p->features & AHC_ULTRA2)
  1403. {
  1404. aic_inb(p, CCSCBCTL);
  1405. }
  1406. }
  1407. /*+F*************************************************************************
  1408. * Function:
  1409. * unpause_sequencer
  1410. *
  1411. * Description:
  1412. * Unpause the sequencer. Unremarkable, yet done often enough to
  1413. * warrant an easy way to do it.
  1414. *-F*************************************************************************/
  1415. static void
  1416. unpause_sequencer(struct aic7xxx_host *p, int unpause_always)
  1417. {
  1418. if (unpause_always ||
  1419. ( !(aic_inb(p, INTSTAT) & (SCSIINT | SEQINT | BRKADRINT)) &&
  1420. !(p->flags & AHC_HANDLING_REQINITS) ) )
  1421. {
  1422. aic_outb(p, p->unpause, HCNTRL);
  1423. }
  1424. }
  1425. /*+F*************************************************************************
  1426. * Function:
  1427. * restart_sequencer
  1428. *
  1429. * Description:
  1430. * Restart the sequencer program from address zero. This assumes
  1431. * that the sequencer is already paused.
  1432. *-F*************************************************************************/
  1433. static void
  1434. restart_sequencer(struct aic7xxx_host *p)
  1435. {
  1436. aic_outb(p, 0, SEQADDR0);
  1437. aic_outb(p, 0, SEQADDR1);
  1438. aic_outb(p, FASTMODE, SEQCTL);
  1439. }
  1440. /*
  1441. * We include the aic7xxx_seq.c file here so that the other defines have
  1442. * already been made, and so that it comes before the code that actually
  1443. * downloads the instructions (since we don't typically use function
  1444. * prototype, our code has to be ordered that way, it's a left-over from
  1445. * the original driver days.....I should fix it some time DL).
  1446. */
  1447. #include "aic7xxx_old/aic7xxx_seq.c"
  1448. /*+F*************************************************************************
  1449. * Function:
  1450. * aic7xxx_check_patch
  1451. *
  1452. * Description:
  1453. * See if the next patch to download should be downloaded.
  1454. *-F*************************************************************************/
  1455. static int
  1456. aic7xxx_check_patch(struct aic7xxx_host *p,
  1457. struct sequencer_patch **start_patch, int start_instr, int *skip_addr)
  1458. {
  1459. struct sequencer_patch *cur_patch;
  1460. struct sequencer_patch *last_patch;
  1461. int num_patches;
  1462. num_patches = ARRAY_SIZE(sequencer_patches);
  1463. last_patch = &sequencer_patches[num_patches];
  1464. cur_patch = *start_patch;
  1465. while ((cur_patch < last_patch) && (start_instr == cur_patch->begin))
  1466. {
  1467. if (cur_patch->patch_func(p) == 0)
  1468. {
  1469. /*
  1470. * Start rejecting code.
  1471. */
  1472. *skip_addr = start_instr + cur_patch->skip_instr;
  1473. cur_patch += cur_patch->skip_patch;
  1474. }
  1475. else
  1476. {
  1477. /*
  1478. * Found an OK patch. Advance the patch pointer to the next patch
  1479. * and wait for our instruction pointer to get here.
  1480. */
  1481. cur_patch++;
  1482. }
  1483. }
  1484. *start_patch = cur_patch;
  1485. if (start_instr < *skip_addr)
  1486. /*
  1487. * Still skipping
  1488. */
  1489. return (0);
  1490. return(1);
  1491. }
  1492. /*+F*************************************************************************
  1493. * Function:
  1494. * aic7xxx_download_instr
  1495. *
  1496. * Description:
  1497. * Find the next patch to download.
  1498. *-F*************************************************************************/
  1499. static void
  1500. aic7xxx_download_instr(struct aic7xxx_host *p, int instrptr,
  1501. unsigned char *dconsts)
  1502. {
  1503. union ins_formats instr;
  1504. struct ins_format1 *fmt1_ins;
  1505. struct ins_format3 *fmt3_ins;
  1506. unsigned char opcode;
  1507. instr = *(union ins_formats*) &seqprog[instrptr * 4];
  1508. instr.integer = le32_to_cpu(instr.integer);
  1509. fmt1_ins = &instr.format1;
  1510. fmt3_ins = NULL;
  1511. /* Pull the opcode */
  1512. opcode = instr.format1.opcode;
  1513. switch (opcode)
  1514. {
  1515. case AIC_OP_JMP:
  1516. case AIC_OP_JC:
  1517. case AIC_OP_JNC:
  1518. case AIC_OP_CALL:
  1519. case AIC_OP_JNE:
  1520. case AIC_OP_JNZ:
  1521. case AIC_OP_JE:
  1522. case AIC_OP_JZ:
  1523. {
  1524. struct sequencer_patch *cur_patch;
  1525. int address_offset;
  1526. unsigned int address;
  1527. int skip_addr;
  1528. int i;
  1529. fmt3_ins = &instr.format3;
  1530. address_offset = 0;
  1531. address = fmt3_ins->address;
  1532. cur_patch = sequencer_patches;
  1533. skip_addr = 0;
  1534. for (i = 0; i < address;)
  1535. {
  1536. aic7xxx_check_patch(p, &cur_patch, i, &skip_addr);
  1537. if (skip_addr > i)
  1538. {
  1539. int end_addr;
  1540. end_addr = min_t(int, address, skip_addr);
  1541. address_offset += end_addr - i;
  1542. i = skip_addr;
  1543. }
  1544. else
  1545. {
  1546. i++;
  1547. }
  1548. }
  1549. address -= address_offset;
  1550. fmt3_ins->address = address;
  1551. /* Fall Through to the next code section */
  1552. }
  1553. case AIC_OP_OR:
  1554. case AIC_OP_AND:
  1555. case AIC_OP_XOR:
  1556. case AIC_OP_ADD:
  1557. case AIC_OP_ADC:
  1558. case AIC_OP_BMOV:
  1559. if (fmt1_ins->parity != 0)
  1560. {
  1561. fmt1_ins->immediate = dconsts[fmt1_ins->immediate];
  1562. }
  1563. fmt1_ins->parity = 0;
  1564. /* Fall Through to the next code section */
  1565. case AIC_OP_ROL:
  1566. if ((p->features & AHC_ULTRA2) != 0)
  1567. {
  1568. int i, count;
  1569. /* Calculate odd parity for the instruction */
  1570. for ( i=0, count=0; i < 31; i++)
  1571. {
  1572. unsigned int mask;
  1573. mask = 0x01 << i;
  1574. if ((instr.integer & mask) != 0)
  1575. count++;
  1576. }
  1577. if (!(count & 0x01))
  1578. instr.format1.parity = 1;
  1579. }
  1580. else
  1581. {
  1582. if (fmt3_ins != NULL)
  1583. {
  1584. instr.integer = fmt3_ins->immediate |
  1585. (fmt3_ins->source << 8) |
  1586. (fmt3_ins->address << 16) |
  1587. (fmt3_ins->opcode << 25);
  1588. }
  1589. else
  1590. {
  1591. instr.integer = fmt1_ins->immediate |
  1592. (fmt1_ins->source << 8) |
  1593. (fmt1_ins->destination << 16) |
  1594. (fmt1_ins->ret << 24) |
  1595. (fmt1_ins->opcode << 25);
  1596. }
  1597. }
  1598. aic_outb(p, (instr.integer & 0xff), SEQRAM);
  1599. aic_outb(p, ((instr.integer >> 8) & 0xff), SEQRAM);
  1600. aic_outb(p, ((instr.integer >> 16) & 0xff), SEQRAM);
  1601. aic_outb(p, ((instr.integer >> 24) & 0xff), SEQRAM);
  1602. udelay(10);
  1603. break;
  1604. default:
  1605. panic("aic7xxx: Unknown opcode encountered in sequencer program.");
  1606. break;
  1607. }
  1608. }
  1609. /*+F*************************************************************************
  1610. * Function:
  1611. * aic7xxx_loadseq
  1612. *
  1613. * Description:
  1614. * Load the sequencer code into the controller memory.
  1615. *-F*************************************************************************/
  1616. static void
  1617. aic7xxx_loadseq(struct aic7xxx_host *p)
  1618. {
  1619. struct sequencer_patch *cur_patch;
  1620. int i;
  1621. int downloaded;
  1622. int skip_addr;
  1623. unsigned char download_consts[4] = {0, 0, 0, 0};
  1624. if (aic7xxx_verbose & VERBOSE_PROBE)
  1625. {
  1626. printk(KERN_INFO "(scsi%d) Downloading sequencer code...", p->host_no);
  1627. }
  1628. #if 0
  1629. download_consts[TMODE_NUMCMDS] = p->num_targetcmds;
  1630. #endif
  1631. download_consts[TMODE_NUMCMDS] = 0;
  1632. cur_patch = &sequencer_patches[0];
  1633. downloaded = 0;
  1634. skip_addr = 0;
  1635. aic_outb(p, PERRORDIS|LOADRAM|FAILDIS|FASTMODE, SEQCTL);
  1636. aic_outb(p, 0, SEQADDR0);
  1637. aic_outb(p, 0, SEQADDR1);
  1638. for (i = 0; i < sizeof(seqprog) / 4; i++)
  1639. {
  1640. if (aic7xxx_check_patch(p, &cur_patch, i, &skip_addr) == 0)
  1641. {
  1642. /* Skip this instruction for this configuration. */
  1643. continue;
  1644. }
  1645. aic7xxx_download_instr(p, i, &download_consts[0]);
  1646. downloaded++;
  1647. }
  1648. aic_outb(p, 0, SEQADDR0);
  1649. aic_outb(p, 0, SEQADDR1);
  1650. aic_outb(p, FASTMODE | FAILDIS, SEQCTL);
  1651. unpause_sequencer(p, TRUE);
  1652. mdelay(1);
  1653. pause_sequencer(p);
  1654. aic_outb(p, FASTMODE, SEQCTL);
  1655. if (aic7xxx_verbose & VERBOSE_PROBE)
  1656. {
  1657. printk(" %d instructions downloaded\n", downloaded);
  1658. }
  1659. if (aic7xxx_dump_sequencer)
  1660. aic7xxx_print_sequencer(p, downloaded);
  1661. }
  1662. /*+F*************************************************************************
  1663. * Function:
  1664. * aic7xxx_print_sequencer
  1665. *
  1666. * Description:
  1667. * Print the contents of the sequencer memory to the screen.
  1668. *-F*************************************************************************/
  1669. static void
  1670. aic7xxx_print_sequencer(struct aic7xxx_host *p, int downloaded)
  1671. {
  1672. int i, k, temp;
  1673. aic_outb(p, PERRORDIS|LOADRAM|FAILDIS|FASTMODE, SEQCTL);
  1674. aic_outb(p, 0, SEQADDR0);
  1675. aic_outb(p, 0, SEQADDR1);
  1676. k = 0;
  1677. for (i=0; i < downloaded; i++)
  1678. {
  1679. if ( k == 0 )
  1680. printk("%03x: ", i);
  1681. temp = aic_inb(p, SEQRAM);
  1682. temp |= (aic_inb(p, SEQRAM) << 8);
  1683. temp |= (aic_inb(p, SEQRAM) << 16);
  1684. temp |= (aic_inb(p, SEQRAM) << 24);
  1685. printk("%08x", temp);
  1686. if ( ++k == 8 )
  1687. {
  1688. printk("\n");
  1689. k = 0;
  1690. }
  1691. else
  1692. printk(" ");
  1693. }
  1694. aic_outb(p, 0, SEQADDR0);
  1695. aic_outb(p, 0, SEQADDR1);
  1696. aic_outb(p, FASTMODE | FAILDIS, SEQCTL);
  1697. unpause_sequencer(p, TRUE);
  1698. mdelay(1);
  1699. pause_sequencer(p);
  1700. aic_outb(p, FASTMODE, SEQCTL);
  1701. printk("\n");
  1702. }
  1703. /*+F*************************************************************************
  1704. * Function:
  1705. * aic7xxx_info
  1706. *
  1707. * Description:
  1708. * Return a string describing the driver.
  1709. *-F*************************************************************************/
  1710. static const char *
  1711. aic7xxx_info(struct Scsi_Host *dooh)
  1712. {
  1713. static char buffer[256];
  1714. char *bp;
  1715. struct aic7xxx_host *p;
  1716. bp = &buffer[0];
  1717. p = (struct aic7xxx_host *)dooh->hostdata;
  1718. memset(bp, 0, sizeof(buffer));
  1719. strcpy(bp, "Adaptec AHA274x/284x/294x (EISA/VLB/PCI-Fast SCSI) ");
  1720. strcat(bp, AIC7XXX_C_VERSION);
  1721. strcat(bp, "/");
  1722. strcat(bp, AIC7XXX_H_VERSION);
  1723. strcat(bp, "\n");
  1724. strcat(bp, " <");
  1725. strcat(bp, board_names[p->board_name_index]);
  1726. strcat(bp, ">");
  1727. return(bp);
  1728. }
  1729. /*+F*************************************************************************
  1730. * Function:
  1731. * aic7xxx_find_syncrate
  1732. *
  1733. * Description:
  1734. * Look up the valid period to SCSIRATE conversion in our table
  1735. *-F*************************************************************************/
  1736. static struct aic7xxx_syncrate *
  1737. aic7xxx_find_syncrate(struct aic7xxx_host *p, unsigned int *period,
  1738. unsigned int maxsync, unsigned char *options)
  1739. {
  1740. struct aic7xxx_syncrate *syncrate;
  1741. int done = FALSE;
  1742. switch(*options)
  1743. {
  1744. case MSG_EXT_PPR_OPTION_DT_CRC:
  1745. case MSG_EXT_PPR_OPTION_DT_UNITS:
  1746. if(!(p->features & AHC_ULTRA3))
  1747. {
  1748. *options = 0;
  1749. maxsync = max_t(unsigned int, maxsync, AHC_SYNCRATE_ULTRA2);
  1750. }
  1751. break;
  1752. case MSG_EXT_PPR_OPTION_DT_CRC_QUICK:
  1753. case MSG_EXT_PPR_OPTION_DT_UNITS_QUICK:
  1754. if(!(p->features & AHC_ULTRA3))
  1755. {
  1756. *options = 0;
  1757. maxsync = max_t(unsigned int, maxsync, AHC_SYNCRATE_ULTRA2);
  1758. }
  1759. else
  1760. {
  1761. /*
  1762. * we don't support the Quick Arbitration variants of dual edge
  1763. * clocking. As it turns out, we want to send back the
  1764. * same basic option, but without the QA attribute.
  1765. * We know that we are responding because we would never set
  1766. * these options ourself, we would only respond to them.
  1767. */
  1768. switch(*options)
  1769. {
  1770. case MSG_EXT_PPR_OPTION_DT_CRC_QUICK:
  1771. *options = MSG_EXT_PPR_OPTION_DT_CRC;
  1772. break;
  1773. case MSG_EXT_PPR_OPTION_DT_UNITS_QUICK:
  1774. *options = MSG_EXT_PPR_OPTION_DT_UNITS;
  1775. break;
  1776. }
  1777. }
  1778. break;
  1779. default:
  1780. *options = 0;
  1781. maxsync = max_t(unsigned int, maxsync, AHC_SYNCRATE_ULTRA2);
  1782. break;
  1783. }
  1784. syncrate = &aic7xxx_syncrates[maxsync];
  1785. while ( (syncrate->rate[0] != NULL) &&
  1786. (!(p->features & AHC_ULTRA2) || syncrate->sxfr_ultra2) )
  1787. {
  1788. if (*period <= syncrate->period)
  1789. {
  1790. switch(*options)
  1791. {
  1792. case MSG_EXT_PPR_OPTION_DT_CRC:
  1793. case MSG_EXT_PPR_OPTION_DT_UNITS:
  1794. if(!(syncrate->sxfr_ultra2 & AHC_SYNCRATE_CRC))
  1795. {
  1796. done = TRUE;
  1797. /*
  1798. * oops, we went too low for the CRC/DualEdge signalling, so
  1799. * clear the options byte
  1800. */
  1801. *options = 0;
  1802. /*
  1803. * We'll be sending a reply to this packet to set the options
  1804. * properly, so unilaterally set the period as well.
  1805. */
  1806. *period = syncrate->period;
  1807. }
  1808. else
  1809. {
  1810. done = TRUE;
  1811. if(syncrate == &aic7xxx_syncrates[maxsync])
  1812. {
  1813. *period = syncrate->period;
  1814. }
  1815. }
  1816. break;
  1817. default:
  1818. if(!(syncrate->sxfr_ultra2 & AHC_SYNCRATE_CRC))
  1819. {
  1820. done = TRUE;
  1821. if(syncrate == &aic7xxx_syncrates[maxsync])
  1822. {
  1823. *period = syncrate->period;
  1824. }
  1825. }
  1826. break;
  1827. }
  1828. if(done)
  1829. {
  1830. break;
  1831. }
  1832. }
  1833. syncrate++;
  1834. }
  1835. if ( (*period == 0) || (syncrate->rate[0] == NULL) ||
  1836. ((p->features & AHC_ULTRA2) && (syncrate->sxfr_ultra2 == 0)) )
  1837. {
  1838. /*
  1839. * Use async transfers for this target
  1840. */
  1841. *options = 0;
  1842. *period = 255;
  1843. syncrate = NULL;
  1844. }
  1845. return (syncrate);
  1846. }
  1847. /*+F*************************************************************************
  1848. * Function:
  1849. * aic7xxx_find_period
  1850. *
  1851. * Description:
  1852. * Look up the valid SCSIRATE to period conversion in our table
  1853. *-F*************************************************************************/
  1854. static unsigned int
  1855. aic7xxx_find_period(struct aic7xxx_host *p, unsigned int scsirate,
  1856. unsigned int maxsync)
  1857. {
  1858. struct aic7xxx_syncrate *syncrate;
  1859. if (p->features & AHC_ULTRA2)
  1860. {
  1861. scsirate &= SXFR_ULTRA2;
  1862. }
  1863. else
  1864. {
  1865. scsirate &= SXFR;
  1866. }
  1867. syncrate = &aic7xxx_syncrates[maxsync];
  1868. while (syncrate->rate[0] != NULL)
  1869. {
  1870. if (p->features & AHC_ULTRA2)
  1871. {
  1872. if (syncrate->sxfr_ultra2 == 0)
  1873. break;
  1874. else if (scsirate == syncrate->sxfr_ultra2)
  1875. return (syncrate->period);
  1876. else if (scsirate == (syncrate->sxfr_ultra2 & ~AHC_SYNCRATE_CRC))
  1877. return (syncrate->period);
  1878. }
  1879. else if (scsirate == (syncrate->sxfr & ~ULTRA_SXFR))
  1880. {
  1881. return (syncrate->period);
  1882. }
  1883. syncrate++;
  1884. }
  1885. return (0); /* async */
  1886. }
  1887. /*+F*************************************************************************
  1888. * Function:
  1889. * aic7xxx_validate_offset
  1890. *
  1891. * Description:
  1892. * Set a valid offset value for a particular card in use and transfer
  1893. * settings in use.
  1894. *-F*************************************************************************/
  1895. static void
  1896. aic7xxx_validate_offset(struct aic7xxx_host *p,
  1897. struct aic7xxx_syncrate *syncrate, unsigned int *offset, int wide)
  1898. {
  1899. unsigned int maxoffset;
  1900. /* Limit offset to what the card (and device) can do */
  1901. if (syncrate == NULL)
  1902. {
  1903. maxoffset = 0;
  1904. }
  1905. else if (p->features & AHC_ULTRA2)
  1906. {
  1907. maxoffset = MAX_OFFSET_ULTRA2;
  1908. }
  1909. else
  1910. {
  1911. if (wide)
  1912. maxoffset = MAX_OFFSET_16BIT;
  1913. else
  1914. maxoffset = MAX_OFFSET_8BIT;
  1915. }
  1916. *offset = min(*offset, maxoffset);
  1917. }
  1918. /*+F*************************************************************************
  1919. * Function:
  1920. * aic7xxx_set_syncrate
  1921. *
  1922. * Description:
  1923. * Set the actual syncrate down in the card and in our host structs
  1924. *-F*************************************************************************/
  1925. static void
  1926. aic7xxx_set_syncrate(struct aic7xxx_host *p, struct aic7xxx_syncrate *syncrate,
  1927. int target, int channel, unsigned int period, unsigned int offset,
  1928. unsigned char options, unsigned int type, struct aic_dev_data *aic_dev)
  1929. {
  1930. unsigned char tindex;
  1931. unsigned short target_mask;
  1932. unsigned char lun, old_options;
  1933. unsigned int old_period, old_offset;
  1934. tindex = target | (channel << 3);
  1935. target_mask = 0x01 << tindex;
  1936. lun = aic_inb(p, SCB_TCL) & 0x07;
  1937. if (syncrate == NULL)
  1938. {
  1939. period = 0;
  1940. offset = 0;
  1941. }
  1942. old_period = aic_dev->cur.period;
  1943. old_offset = aic_dev->cur.offset;
  1944. old_options = aic_dev->cur.options;
  1945. if (type & AHC_TRANS_CUR)
  1946. {
  1947. unsigned int scsirate;
  1948. scsirate = aic_inb(p, TARG_SCSIRATE + tindex);
  1949. if (p->features & AHC_ULTRA2)
  1950. {
  1951. scsirate &= ~SXFR_ULTRA2;
  1952. if (syncrate != NULL)
  1953. {
  1954. switch(options)
  1955. {
  1956. case MSG_EXT_PPR_OPTION_DT_UNITS:
  1957. /*
  1958. * mask off the CRC bit in the xfer settings
  1959. */
  1960. scsirate |= (syncrate->sxfr_ultra2 & ~AHC_SYNCRATE_CRC);
  1961. break;
  1962. default:
  1963. scsirate |= syncrate->sxfr_ultra2;
  1964. break;
  1965. }
  1966. }
  1967. if (type & AHC_TRANS_ACTIVE)
  1968. {
  1969. aic_outb(p, offset, SCSIOFFSET);
  1970. }
  1971. aic_outb(p, offset, TARG_OFFSET + tindex);
  1972. }
  1973. else /* Not an Ultra2 controller */
  1974. {
  1975. scsirate &= ~(SXFR|SOFS);
  1976. p->ultraenb &= ~target_mask;
  1977. if (syncrate != NULL)
  1978. {
  1979. if (syncrate->sxfr & ULTRA_SXFR)
  1980. {
  1981. p->ultraenb |= target_mask;
  1982. }
  1983. scsirate |= (syncrate->sxfr & SXFR);
  1984. scsirate |= (offset & SOFS);
  1985. }
  1986. if (type & AHC_TRANS_ACTIVE)
  1987. {
  1988. unsigned char sxfrctl0;
  1989. sxfrctl0 = aic_inb(p, SXFRCTL0);
  1990. sxfrctl0 &= ~FAST20;
  1991. if (p->ultraenb & target_mask)
  1992. sxfrctl0 |= FAST20;
  1993. aic_outb(p, sxfrctl0, SXFRCTL0);
  1994. }
  1995. aic_outb(p, p->ultraenb & 0xff, ULTRA_ENB);
  1996. aic_outb(p, (p->ultraenb >> 8) & 0xff, ULTRA_ENB + 1 );
  1997. }
  1998. if (type & AHC_TRANS_ACTIVE)
  1999. {
  2000. aic_outb(p, scsirate, SCSIRATE);
  2001. }
  2002. aic_outb(p, scsirate, TARG_SCSIRATE + tindex);
  2003. aic_dev->cur.period = period;
  2004. aic_dev->cur.offset = offset;
  2005. aic_dev->cur.options = options;
  2006. if ( !(type & AHC_TRANS_QUITE) &&
  2007. (aic7xxx_verbose & VERBOSE_NEGOTIATION) &&
  2008. (aic_dev->flags & DEVICE_PRINT_DTR) )
  2009. {
  2010. if (offset)
  2011. {
  2012. int rate_mod = (scsirate & WIDEXFER) ? 1 : 0;
  2013. printk(INFO_LEAD "Synchronous at %s Mbyte/sec, "
  2014. "offset %d.\n", p->host_no, channel, target, lun,
  2015. syncrate->rate[rate_mod], offset);
  2016. }
  2017. else
  2018. {
  2019. printk(INFO_LEAD "Using asynchronous transfers.\n",
  2020. p->host_no, channel, target, lun);
  2021. }
  2022. aic_dev->flags &= ~DEVICE_PRINT_DTR;
  2023. }
  2024. }
  2025. if (type & AHC_TRANS_GOAL)
  2026. {
  2027. aic_dev->goal.period = period;
  2028. aic_dev->goal.offset = offset;
  2029. aic_dev->goal.options = options;
  2030. }
  2031. if (type & AHC_TRANS_USER)
  2032. {
  2033. p->user[tindex].period = period;
  2034. p->user[tindex].offset = offset;
  2035. p->user[tindex].options = options;
  2036. }
  2037. }
  2038. /*+F*************************************************************************
  2039. * Function:
  2040. * aic7xxx_set_width
  2041. *
  2042. * Description:
  2043. * Set the actual width down in the card and in our host structs
  2044. *-F*************************************************************************/
  2045. static void
  2046. aic7xxx_set_width(struct aic7xxx_host *p, int target, int channel, int lun,
  2047. unsigned int width, unsigned int type, struct aic_dev_data *aic_dev)
  2048. {
  2049. unsigned char tindex;
  2050. unsigned short target_mask;
  2051. unsigned int old_width;
  2052. tindex = target | (channel << 3);
  2053. target_mask = 1 << tindex;
  2054. old_width = aic_dev->cur.width;
  2055. if (type & AHC_TRANS_CUR)
  2056. {
  2057. unsigned char scsirate;
  2058. scsirate = aic_inb(p, TARG_SCSIRATE + tindex);
  2059. scsirate &= ~WIDEXFER;
  2060. if (width == MSG_EXT_WDTR_BUS_16_BIT)
  2061. scsirate |= WIDEXFER;
  2062. aic_outb(p, scsirate, TARG_SCSIRATE + tindex);
  2063. if (type & AHC_TRANS_ACTIVE)
  2064. aic_outb(p, scsirate, SCSIRATE);
  2065. aic_dev->cur.width = width;
  2066. if ( !(type & AHC_TRANS_QUITE) &&
  2067. (aic7xxx_verbose & VERBOSE_NEGOTIATION2) &&
  2068. (aic_dev->flags & DEVICE_PRINT_DTR) )
  2069. {
  2070. printk(INFO_LEAD "Using %s transfers\n", p->host_no, channel, target,
  2071. lun, (scsirate & WIDEXFER) ? "Wide(16bit)" : "Narrow(8bit)" );
  2072. }
  2073. }
  2074. if (type & AHC_TRANS_GOAL)
  2075. aic_dev->goal.width = width;
  2076. if (type & AHC_TRANS_USER)
  2077. p->user[tindex].width = width;
  2078. if (aic_dev->goal.offset)
  2079. {
  2080. if (p->features & AHC_ULTRA2)
  2081. {
  2082. aic_dev->goal.offset = MAX_OFFSET_ULTRA2;
  2083. }
  2084. else if (width == MSG_EXT_WDTR_BUS_16_BIT)
  2085. {
  2086. aic_dev->goal.offset = MAX_OFFSET_16BIT;
  2087. }
  2088. else
  2089. {
  2090. aic_dev->goal.offset = MAX_OFFSET_8BIT;
  2091. }
  2092. }
  2093. }
  2094. /*+F*************************************************************************
  2095. * Function:
  2096. * scbq_init
  2097. *
  2098. * Description:
  2099. * SCB queue initialization.
  2100. *
  2101. *-F*************************************************************************/
  2102. static void
  2103. scbq_init(volatile scb_queue_type *queue)
  2104. {
  2105. queue->head = NULL;
  2106. queue->tail = NULL;
  2107. }
  2108. /*+F*************************************************************************
  2109. * Function:
  2110. * scbq_insert_head
  2111. *
  2112. * Description:
  2113. * Add an SCB to the head of the list.
  2114. *
  2115. *-F*************************************************************************/
  2116. static inline void
  2117. scbq_insert_head(volatile scb_queue_type *queue, struct aic7xxx_scb *scb)
  2118. {
  2119. scb->q_next = queue->head;
  2120. queue->head = scb;
  2121. if (queue->tail == NULL) /* If list was empty, update tail. */
  2122. queue->tail = queue->head;
  2123. }
  2124. /*+F*************************************************************************
  2125. * Function:
  2126. * scbq_remove_head
  2127. *
  2128. * Description:
  2129. * Remove an SCB from the head of the list.
  2130. *
  2131. *-F*************************************************************************/
  2132. static inline struct aic7xxx_scb *
  2133. scbq_remove_head(volatile scb_queue_type *queue)
  2134. {
  2135. struct aic7xxx_scb * scbp;
  2136. scbp = queue->head;
  2137. if (queue->head != NULL)
  2138. queue->head = queue->head->q_next;
  2139. if (queue->head == NULL) /* If list is now empty, update tail. */
  2140. queue->tail = NULL;
  2141. return(scbp);
  2142. }
  2143. /*+F*************************************************************************
  2144. * Function:
  2145. * scbq_remove
  2146. *
  2147. * Description:
  2148. * Removes an SCB from the list.
  2149. *
  2150. *-F*************************************************************************/
  2151. static inline void
  2152. scbq_remove(volatile scb_queue_type *queue, struct aic7xxx_scb *scb)
  2153. {
  2154. if (queue->head == scb)
  2155. {
  2156. /* At beginning of queue, remove from head. */
  2157. scbq_remove_head(queue);
  2158. }
  2159. else
  2160. {
  2161. struct aic7xxx_scb *curscb = queue->head;
  2162. /*
  2163. * Search until the next scb is the one we're looking for, or
  2164. * we run out of queue.
  2165. */
  2166. while ((curscb != NULL) && (curscb->q_next != scb))
  2167. {
  2168. curscb = curscb->q_next;
  2169. }
  2170. if (curscb != NULL)
  2171. {
  2172. /* Found it. */
  2173. curscb->q_next = scb->q_next;
  2174. if (scb->q_next == NULL)
  2175. {
  2176. /* Update the tail when removing the tail. */
  2177. queue->tail = curscb;
  2178. }
  2179. }
  2180. }
  2181. }
  2182. /*+F*************************************************************************
  2183. * Function:
  2184. * scbq_insert_tail
  2185. *
  2186. * Description:
  2187. * Add an SCB at the tail of the list.
  2188. *
  2189. *-F*************************************************************************/
  2190. static inline void
  2191. scbq_insert_tail(volatile scb_queue_type *queue, struct aic7xxx_scb *scb)
  2192. {
  2193. scb->q_next = NULL;
  2194. if (queue->tail != NULL) /* Add the scb at the end of the list. */
  2195. queue->tail->q_next = scb;
  2196. queue->tail = scb; /* Update the tail. */
  2197. if (queue->head == NULL) /* If list was empty, update head. */
  2198. queue->head = queue->tail;
  2199. }
  2200. /*+F*************************************************************************
  2201. * Function:
  2202. * aic7xxx_match_scb
  2203. *
  2204. * Description:
  2205. * Checks to see if an scb matches the target/channel as specified.
  2206. * If target is ALL_TARGETS (-1), then we're looking for any device
  2207. * on the specified channel; this happens when a channel is going
  2208. * to be reset and all devices on that channel must be aborted.
  2209. *-F*************************************************************************/
  2210. static int
  2211. aic7xxx_match_scb(struct aic7xxx_host *p, struct aic7xxx_scb *scb,
  2212. int target, int channel, int lun, unsigned char tag)
  2213. {
  2214. int targ = (scb->hscb->target_channel_lun >> 4) & 0x0F;
  2215. int chan = (scb->hscb->target_channel_lun >> 3) & 0x01;
  2216. int slun = scb->hscb->target_channel_lun & 0x07;
  2217. int match;
  2218. match = ((chan == channel) || (channel == ALL_CHANNELS));
  2219. if (match != 0)
  2220. match = ((targ == target) || (target == ALL_TARGETS));
  2221. if (match != 0)
  2222. match = ((lun == slun) || (lun == ALL_LUNS));
  2223. if (match != 0)
  2224. match = ((tag == scb->hscb->tag) || (tag == SCB_LIST_NULL));
  2225. return (match);
  2226. }
  2227. /*+F*************************************************************************
  2228. * Function:
  2229. * aic7xxx_add_curscb_to_free_list
  2230. *
  2231. * Description:
  2232. * Adds the current scb (in SCBPTR) to the list of free SCBs.
  2233. *-F*************************************************************************/
  2234. static void
  2235. aic7xxx_add_curscb_to_free_list(struct aic7xxx_host *p)
  2236. {
  2237. /*
  2238. * Invalidate the tag so that aic7xxx_find_scb doesn't think
  2239. * it's active
  2240. */
  2241. aic_outb(p, SCB_LIST_NULL, SCB_TAG);
  2242. aic_outb(p, 0, SCB_CONTROL);
  2243. aic_outb(p, aic_inb(p, FREE_SCBH), SCB_NEXT);
  2244. aic_outb(p, aic_inb(p, SCBPTR), FREE_SCBH);
  2245. }
  2246. /*+F*************************************************************************
  2247. * Function:
  2248. * aic7xxx_rem_scb_from_disc_list
  2249. *
  2250. * Description:
  2251. * Removes the current SCB from the disconnected list and adds it
  2252. * to the free list.
  2253. *-F*************************************************************************/
  2254. static unsigned char
  2255. aic7xxx_rem_scb_from_disc_list(struct aic7xxx_host *p, unsigned char scbptr,
  2256. unsigned char prev)
  2257. {
  2258. unsigned char next;
  2259. aic_outb(p, scbptr, SCBPTR);
  2260. next = aic_inb(p, SCB_NEXT);
  2261. aic7xxx_add_curscb_to_free_list(p);
  2262. if (prev != SCB_LIST_NULL)
  2263. {
  2264. aic_outb(p, prev, SCBPTR);
  2265. aic_outb(p, next, SCB_NEXT);
  2266. }
  2267. else
  2268. {
  2269. aic_outb(p, next, DISCONNECTED_SCBH);
  2270. }
  2271. return next;
  2272. }
  2273. /*+F*************************************************************************
  2274. * Function:
  2275. * aic7xxx_busy_target
  2276. *
  2277. * Description:
  2278. * Set the specified target busy.
  2279. *-F*************************************************************************/
  2280. static inline void
  2281. aic7xxx_busy_target(struct aic7xxx_host *p, struct aic7xxx_scb *scb)
  2282. {
  2283. p->untagged_scbs[scb->hscb->target_channel_lun] = scb->hscb->tag;
  2284. }
  2285. /*+F*************************************************************************
  2286. * Function:
  2287. * aic7xxx_index_busy_target
  2288. *
  2289. * Description:
  2290. * Returns the index of the busy target, and optionally sets the
  2291. * target inactive.
  2292. *-F*************************************************************************/
  2293. static inline unsigned char
  2294. aic7xxx_index_busy_target(struct aic7xxx_host *p, unsigned char tcl,
  2295. int unbusy)
  2296. {
  2297. unsigned char busy_scbid;
  2298. busy_scbid = p->untagged_scbs[tcl];
  2299. if (unbusy)
  2300. {
  2301. p->untagged_scbs[tcl] = SCB_LIST_NULL;
  2302. }
  2303. return (busy_scbid);
  2304. }
  2305. /*+F*************************************************************************
  2306. * Function:
  2307. * aic7xxx_find_scb
  2308. *
  2309. * Description:
  2310. * Look through the SCB array of the card and attempt to find the
  2311. * hardware SCB that corresponds to the passed in SCB. Return
  2312. * SCB_LIST_NULL if unsuccessful. This routine assumes that the
  2313. * card is already paused.
  2314. *-F*************************************************************************/
  2315. static unsigned char
  2316. aic7xxx_find_scb(struct aic7xxx_host *p, struct aic7xxx_scb *scb)
  2317. {
  2318. unsigned char saved_scbptr;
  2319. unsigned char curindex;
  2320. saved_scbptr = aic_inb(p, SCBPTR);
  2321. curindex = 0;
  2322. for (curindex = 0; curindex < p->scb_data->maxhscbs; curindex++)
  2323. {
  2324. aic_outb(p, curindex, SCBPTR);
  2325. if (aic_inb(p, SCB_TAG) == scb->hscb->tag)
  2326. {
  2327. break;
  2328. }
  2329. }
  2330. aic_outb(p, saved_scbptr, SCBPTR);
  2331. if (curindex >= p->scb_data->maxhscbs)
  2332. {
  2333. curindex = SCB_LIST_NULL;
  2334. }
  2335. return (curindex);
  2336. }
  2337. /*+F*************************************************************************
  2338. * Function:
  2339. * aic7xxx_allocate_scb
  2340. *
  2341. * Description:
  2342. * Get an SCB from the free list or by allocating a new one.
  2343. *-F*************************************************************************/
  2344. static int
  2345. aic7xxx_allocate_scb(struct aic7xxx_host *p)
  2346. {
  2347. struct aic7xxx_scb *scbp = NULL;
  2348. int scb_size = (sizeof (struct hw_scatterlist) * AIC7XXX_MAX_SG) + 12 + 6;
  2349. int i;
  2350. int step = PAGE_SIZE / 1024;
  2351. unsigned long scb_count = 0;
  2352. struct hw_scatterlist *hsgp;
  2353. struct aic7xxx_scb *scb_ap;
  2354. struct aic7xxx_scb_dma *scb_dma;
  2355. unsigned char *bufs;
  2356. if (p->scb_data->numscbs < p->scb_data->maxscbs)
  2357. {
  2358. /*
  2359. * Calculate the optimal number of SCBs to allocate.
  2360. *
  2361. * NOTE: This formula works because the sizeof(sg_array) is always
  2362. * 1024. Therefore, scb_size * i would always be > PAGE_SIZE *
  2363. * (i/step). The (i-1) allows the left hand side of the equation
  2364. * to grow into the right hand side to a point of near perfect
  2365. * efficiency since scb_size * (i -1) is growing slightly faster
  2366. * than the right hand side. If the number of SG array elements
  2367. * is changed, this function may not be near so efficient any more.
  2368. *
  2369. * Since the DMA'able buffers are now allocated in a separate
  2370. * chunk this algorithm has been modified to match. The '12'
  2371. * and '6' factors in scb_size are for the DMA'able command byte
  2372. * and sensebuffers respectively. -DaveM
  2373. */
  2374. for ( i=step;; i *= 2 )
  2375. {
  2376. if ( (scb_size * (i-1)) >= ( (PAGE_SIZE * (i/step)) - 64 ) )
  2377. {
  2378. i /= 2;
  2379. break;
  2380. }
  2381. }
  2382. scb_count = min( (i-1), p->scb_data->maxscbs - p->scb_data->numscbs);
  2383. scb_ap = kmalloc(sizeof (struct aic7xxx_scb) * scb_count
  2384. + sizeof(struct aic7xxx_scb_dma), GFP_ATOMIC);
  2385. if (scb_ap == NULL)
  2386. return(0);
  2387. scb_dma = (struct aic7xxx_scb_dma *)&scb_ap[scb_count];
  2388. hsgp = (struct hw_scatterlist *)
  2389. pci_alloc_consistent(p->pdev, scb_size * scb_count,
  2390. &scb_dma->dma_address);
  2391. if (hsgp == NULL)
  2392. {
  2393. kfree(scb_ap);
  2394. return(0);
  2395. }
  2396. bufs = (unsigned char *)&hsgp[scb_count * AIC7XXX_MAX_SG];
  2397. #ifdef AIC7XXX_VERBOSE_DEBUGGING
  2398. if (aic7xxx_verbose > 0xffff)
  2399. {
  2400. if (p->scb_data->numscbs == 0)
  2401. printk(INFO_LEAD "Allocating initial %ld SCB structures.\n",
  2402. p->host_no, -1, -1, -1, scb_count);
  2403. else
  2404. printk(INFO_LEAD "Allocating %ld additional SCB structures.\n",
  2405. p->host_no, -1, -1, -1, scb_count);
  2406. }
  2407. #endif
  2408. memset(scb_ap, 0, sizeof (struct aic7xxx_scb) * scb_count);
  2409. scb_dma->dma_offset = (unsigned long)scb_dma->dma_address
  2410. - (unsigned long)hsgp;
  2411. scb_dma->dma_len = scb_size * scb_count;
  2412. for (i=0; i < scb_count; i++)
  2413. {
  2414. scbp = &scb_ap[i];
  2415. scbp->hscb = &p->scb_data->hscbs[p->scb_data->numscbs];
  2416. scbp->sg_list = &hsgp[i * AIC7XXX_MAX_SG];
  2417. scbp->sense_cmd = bufs;
  2418. scbp->cmnd = bufs + 6;
  2419. bufs += 12 + 6;
  2420. scbp->scb_dma = scb_dma;
  2421. memset(scbp->hscb, 0, sizeof(struct aic7xxx_hwscb));
  2422. scbp->hscb->tag = p->scb_data->numscbs;
  2423. /*
  2424. * Place in the scb array; never is removed
  2425. */
  2426. p->scb_data->scb_array[p->scb_data->numscbs++] = scbp;
  2427. scbq_insert_tail(&p->scb_data->free_scbs, scbp);
  2428. }
  2429. scbp->kmalloc_ptr = scb_ap;
  2430. }
  2431. return(scb_count);
  2432. }
  2433. /*+F*************************************************************************
  2434. * Function:
  2435. * aic7xxx_queue_cmd_complete
  2436. *
  2437. * Description:
  2438. * Due to race conditions present in the SCSI subsystem, it is easier
  2439. * to queue completed commands, then call scsi_done() on them when
  2440. * we're finished. This function queues the completed commands.
  2441. *-F*************************************************************************/
  2442. static void
  2443. aic7xxx_queue_cmd_complete(struct aic7xxx_host *p, struct scsi_cmnd *cmd)
  2444. {
  2445. aic7xxx_position(cmd) = SCB_LIST_NULL;
  2446. cmd->host_scribble = (char *)p->completeq.head;
  2447. p->completeq.head = cmd;
  2448. }
  2449. /*+F*************************************************************************
  2450. * Function:
  2451. * aic7xxx_done_cmds_complete
  2452. *
  2453. * Description:
  2454. * Process the completed command queue.
  2455. *-F*************************************************************************/
  2456. static void aic7xxx_done_cmds_complete(struct aic7xxx_host *p)
  2457. {
  2458. struct scsi_cmnd *cmd;
  2459. while (p->completeq.head != NULL) {
  2460. cmd = p->completeq.head;
  2461. p->completeq.head = (struct scsi_cmnd *) cmd->host_scribble;
  2462. cmd->host_scribble = NULL;
  2463. cmd->scsi_done(cmd);
  2464. }
  2465. }
  2466. /*+F*************************************************************************
  2467. * Function:
  2468. * aic7xxx_free_scb
  2469. *
  2470. * Description:
  2471. * Free the scb and insert into the free scb list.
  2472. *-F*************************************************************************/
  2473. static void
  2474. aic7xxx_free_scb(struct aic7xxx_host *p, struct aic7xxx_scb *scb)
  2475. {
  2476. scb->flags = SCB_FREE;
  2477. scb->cmd = NULL;
  2478. scb->sg_count = 0;
  2479. scb->sg_length = 0;
  2480. scb->tag_action = 0;
  2481. scb->hscb->control = 0;
  2482. scb->hscb->target_status = 0;
  2483. scb->hscb->target_channel_lun = SCB_LIST_NULL;
  2484. scbq_insert_head(&p->scb_data->free_scbs, scb);
  2485. }
  2486. /*+F*************************************************************************
  2487. * Function:
  2488. * aic7xxx_done
  2489. *
  2490. * Description:
  2491. * Calls the higher level scsi done function and frees the scb.
  2492. *-F*************************************************************************/
  2493. static void
  2494. aic7xxx_done(struct aic7xxx_host *p, struct aic7xxx_scb *scb)
  2495. {
  2496. struct scsi_cmnd *cmd = scb->cmd;
  2497. struct aic_dev_data *aic_dev = cmd->device->hostdata;
  2498. int tindex = TARGET_INDEX(cmd);
  2499. struct aic7xxx_scb *scbp;
  2500. unsigned char queue_depth;
  2501. scsi_dma_unmap(cmd);
  2502. if (scb->flags & SCB_SENSE)
  2503. {
  2504. pci_unmap_single(p->pdev,
  2505. le32_to_cpu(scb->sg_list[0].address),
  2506. SCSI_SENSE_BUFFERSIZE,
  2507. PCI_DMA_FROMDEVICE);
  2508. }
  2509. if (scb->flags & SCB_RECOVERY_SCB)
  2510. {
  2511. p->flags &= ~AHC_ABORT_PENDING;
  2512. }
  2513. if (scb->flags & (SCB_RESET|SCB_ABORT))
  2514. {
  2515. cmd->result |= (DID_RESET << 16);
  2516. }
  2517. if ((scb->flags & SCB_MSGOUT_BITS) != 0)
  2518. {
  2519. unsigned short mask;
  2520. int message_error = FALSE;
  2521. mask = 0x01 << tindex;
  2522. /*
  2523. * Check to see if we get an invalid message or a message error
  2524. * after failing to negotiate a wide or sync transfer message.
  2525. */
  2526. if ((scb->flags & SCB_SENSE) &&
  2527. ((scb->cmd->sense_buffer[12] == 0x43) || /* INVALID_MESSAGE */
  2528. (scb->cmd->sense_buffer[12] == 0x49))) /* MESSAGE_ERROR */
  2529. {
  2530. message_error = TRUE;
  2531. }
  2532. if (scb->flags & SCB_MSGOUT_WDTR)
  2533. {
  2534. if (message_error)
  2535. {
  2536. if ( (aic7xxx_verbose & VERBOSE_NEGOTIATION2) &&
  2537. (aic_dev->flags & DEVICE_PRINT_DTR) )
  2538. {
  2539. printk(INFO_LEAD "Device failed to complete Wide Negotiation "
  2540. "processing and\n", p->host_no, CTL_OF_SCB(scb));
  2541. printk(INFO_LEAD "returned a sense error code for invalid message, "
  2542. "disabling future\n", p->host_no, CTL_OF_SCB(scb));
  2543. printk(INFO_LEAD "Wide negotiation to this device.\n", p->host_no,
  2544. CTL_OF_SCB(scb));
  2545. }
  2546. aic_dev->needwdtr = aic_dev->needwdtr_copy = 0;
  2547. }
  2548. }
  2549. if (scb->flags & SCB_MSGOUT_SDTR)
  2550. {
  2551. if (message_error)
  2552. {
  2553. if ( (aic7xxx_verbose & VERBOSE_NEGOTIATION2) &&
  2554. (aic_dev->flags & DEVICE_PRINT_DTR) )
  2555. {
  2556. printk(INFO_LEAD "Device failed to complete Sync Negotiation "
  2557. "processing and\n", p->host_no, CTL_OF_SCB(scb));
  2558. printk(INFO_LEAD "returned a sense error code for invalid message, "
  2559. "disabling future\n", p->host_no, CTL_OF_SCB(scb));
  2560. printk(INFO_LEAD "Sync negotiation to this device.\n", p->host_no,
  2561. CTL_OF_SCB(scb));
  2562. aic_dev->flags &= ~DEVICE_PRINT_DTR;
  2563. }
  2564. aic_dev->needsdtr = aic_dev->needsdtr_copy = 0;
  2565. }
  2566. }
  2567. if (scb->flags & SCB_MSGOUT_PPR)
  2568. {
  2569. if(message_error)
  2570. {
  2571. if ( (aic7xxx_verbose & VERBOSE_NEGOTIATION2) &&
  2572. (aic_dev->flags & DEVICE_PRINT_DTR) )
  2573. {
  2574. printk(INFO_LEAD "Device failed to complete Parallel Protocol "
  2575. "Request processing and\n", p->host_no, CTL_OF_SCB(scb));
  2576. printk(INFO_LEAD "returned a sense error code for invalid message, "
  2577. "disabling future\n", p->host_no, CTL_OF_SCB(scb));
  2578. printk(INFO_LEAD "Parallel Protocol Request negotiation to this "
  2579. "device.\n", p->host_no, CTL_OF_SCB(scb));
  2580. }
  2581. /*
  2582. * Disable PPR negotiation and revert back to WDTR and SDTR setup
  2583. */
  2584. aic_dev->needppr = aic_dev->needppr_copy = 0;
  2585. aic_dev->needsdtr = aic_dev->needsdtr_copy = 1;
  2586. aic_dev->needwdtr = aic_dev->needwdtr_copy = 1;
  2587. }
  2588. }
  2589. }
  2590. queue_depth = aic_dev->temp_q_depth;
  2591. if (queue_depth >= aic_dev->active_cmds)
  2592. {
  2593. scbp = scbq_remove_head(&aic_dev->delayed_scbs);
  2594. if (scbp)
  2595. {
  2596. if (queue_depth == 1)
  2597. {
  2598. /*
  2599. * Give extra preference to untagged devices, such as CD-R devices
  2600. * This makes it more likely that a drive *won't* stuff up while
  2601. * waiting on data at a critical time, such as CD-R writing and
  2602. * audio CD ripping operations. Should also benefit tape drives.
  2603. */
  2604. scbq_insert_head(&p->waiting_scbs, scbp);
  2605. }
  2606. else
  2607. {
  2608. scbq_insert_tail(&p->waiting_scbs, scbp);
  2609. }
  2610. #ifdef AIC7XXX_VERBOSE_DEBUGGING
  2611. if (aic7xxx_verbose > 0xffff)
  2612. printk(INFO_LEAD "Moving SCB from delayed to waiting queue.\n",
  2613. p->host_no, CTL_OF_SCB(scbp));
  2614. #endif
  2615. if (queue_depth > aic_dev->active_cmds)
  2616. {
  2617. scbp = scbq_remove_head(&aic_dev->delayed_scbs);
  2618. if (scbp)
  2619. scbq_insert_tail(&p->waiting_scbs, scbp);
  2620. }
  2621. }
  2622. }
  2623. if (!(scb->tag_action))
  2624. {
  2625. aic7xxx_index_busy_target(p, scb->hscb->target_channel_lun,
  2626. /* unbusy */ TRUE);
  2627. if (cmd->device->simple_tags)
  2628. {
  2629. aic_dev->temp_q_depth = aic_dev->max_q_depth;
  2630. }
  2631. }
  2632. if(scb->flags & SCB_DTR_SCB)
  2633. {
  2634. aic_dev->dtr_pending = 0;
  2635. }
  2636. aic_dev->active_cmds--;
  2637. p->activescbs--;
  2638. if ((scb->sg_length >= 512) && (((cmd->result >> 16) & 0xf) == DID_OK))
  2639. {
  2640. long *ptr;
  2641. int x, i;
  2642. if (rq_data_dir(cmd->request) == WRITE)
  2643. {
  2644. aic_dev->w_total++;
  2645. ptr = aic_dev->w_bins;
  2646. }
  2647. else
  2648. {
  2649. aic_dev->r_total++;
  2650. ptr = aic_dev->r_bins;
  2651. }
  2652. x = scb->sg_length;
  2653. x >>= 10;
  2654. for(i=0; i<6; i++)
  2655. {
  2656. x >>= 2;
  2657. if(!x) {
  2658. ptr[i]++;
  2659. break;
  2660. }
  2661. }
  2662. if(i == 6 && x)
  2663. ptr[5]++;
  2664. }
  2665. aic7xxx_free_scb(p, scb);
  2666. aic7xxx_queue_cmd_complete(p, cmd);
  2667. }
  2668. /*+F*************************************************************************
  2669. * Function:
  2670. * aic7xxx_run_done_queue
  2671. *
  2672. * Description:
  2673. * Calls the aic7xxx_done() for the scsi_cmnd of each scb in the
  2674. * aborted list, and adds each scb to the free list. If complete
  2675. * is TRUE, we also process the commands complete list.
  2676. *-F*************************************************************************/
  2677. static void
  2678. aic7xxx_run_done_queue(struct aic7xxx_host *p, /*complete*/ int complete)
  2679. {
  2680. struct aic7xxx_scb *scb;
  2681. int i, found = 0;
  2682. for (i = 0; i < p->scb_data->numscbs; i++)
  2683. {
  2684. scb = p->scb_data->scb_array[i];
  2685. if (scb->flags & SCB_QUEUED_FOR_DONE)
  2686. {
  2687. if (scb->flags & SCB_QUEUE_FULL)
  2688. {
  2689. scb->cmd->result = QUEUE_FULL << 1;
  2690. }
  2691. else
  2692. {
  2693. if (aic7xxx_verbose & (VERBOSE_ABORT_PROCESS | VERBOSE_RESET_PROCESS))
  2694. printk(INFO_LEAD "Aborting scb %d\n",
  2695. p->host_no, CTL_OF_SCB(scb), scb->hscb->tag);
  2696. /*
  2697. * Clear any residual information since the normal aic7xxx_done() path
  2698. * doesn't touch the residuals.
  2699. */
  2700. scb->hscb->residual_SG_segment_count = 0;
  2701. scb->hscb->residual_data_count[0] = 0;
  2702. scb->hscb->residual_data_count[1] = 0;
  2703. scb->hscb->residual_data_count[2] = 0;
  2704. }
  2705. found++;
  2706. aic7xxx_done(p, scb);
  2707. }
  2708. }
  2709. if (aic7xxx_verbose & (VERBOSE_ABORT_RETURN | VERBOSE_RESET_RETURN))
  2710. {
  2711. printk(INFO_LEAD "%d commands found and queued for "
  2712. "completion.\n", p->host_no, -1, -1, -1, found);
  2713. }
  2714. if (complete)
  2715. {
  2716. aic7xxx_done_cmds_complete(p);
  2717. }
  2718. }
  2719. /*+F*************************************************************************
  2720. * Function:
  2721. * aic7xxx_abort_waiting_scb
  2722. *
  2723. * Description:
  2724. * Manipulate the waiting for selection list and return the
  2725. * scb that follows the one that we remove.
  2726. *-F*************************************************************************/
  2727. static unsigned char
  2728. aic7xxx_abort_waiting_scb(struct aic7xxx_host *p, struct aic7xxx_scb *scb,
  2729. unsigned char scbpos, unsigned char prev)
  2730. {
  2731. unsigned char curscb, next;
  2732. /*
  2733. * Select the SCB we want to abort and pull the next pointer out of it.
  2734. */
  2735. curscb = aic_inb(p, SCBPTR);
  2736. aic_outb(p, scbpos, SCBPTR);
  2737. next = aic_inb(p, SCB_NEXT);
  2738. aic7xxx_add_curscb_to_free_list(p);
  2739. /*
  2740. * Update the waiting list
  2741. */
  2742. if (prev == SCB_LIST_NULL)
  2743. {
  2744. /*
  2745. * First in the list
  2746. */
  2747. aic_outb(p, next, WAITING_SCBH);
  2748. }
  2749. else
  2750. {
  2751. /*
  2752. * Select the scb that pointed to us and update its next pointer.
  2753. */
  2754. aic_outb(p, prev, SCBPTR);
  2755. aic_outb(p, next, SCB_NEXT);
  2756. }
  2757. /*
  2758. * Point us back at the original scb position and inform the SCSI
  2759. * system that the command has been aborted.
  2760. */
  2761. aic_outb(p, curscb, SCBPTR);
  2762. return (next);
  2763. }
  2764. /*+F*************************************************************************
  2765. * Function:
  2766. * aic7xxx_search_qinfifo
  2767. *
  2768. * Description:
  2769. * Search the queue-in FIFO for matching SCBs and conditionally
  2770. * requeue. Returns the number of matching SCBs.
  2771. *-F*************************************************************************/
  2772. static int
  2773. aic7xxx_search_qinfifo(struct aic7xxx_host *p, int target, int channel,
  2774. int lun, unsigned char tag, int flags, int requeue,
  2775. volatile scb_queue_type *queue)
  2776. {
  2777. int found;
  2778. unsigned char qinpos, qintail;
  2779. struct aic7xxx_scb *scbp;
  2780. found = 0;
  2781. qinpos = aic_inb(p, QINPOS);
  2782. qintail = p->qinfifonext;
  2783. p->qinfifonext = qinpos;
  2784. while (qinpos != qintail)
  2785. {
  2786. scbp = p->scb_data->scb_array[p->qinfifo[qinpos++]];
  2787. if (aic7xxx_match_scb(p, scbp, target, channel, lun, tag))
  2788. {
  2789. /*
  2790. * We found an scb that needs to be removed.
  2791. */
  2792. if (requeue && (queue != NULL))
  2793. {
  2794. if (scbp->flags & SCB_WAITINGQ)
  2795. {
  2796. scbq_remove(queue, scbp);
  2797. scbq_remove(&p->waiting_scbs, scbp);
  2798. scbq_remove(&AIC_DEV(scbp->cmd)->delayed_scbs, scbp);
  2799. AIC_DEV(scbp->cmd)->active_cmds++;
  2800. p->activescbs++;
  2801. }
  2802. scbq_insert_tail(queue, scbp);
  2803. AIC_DEV(scbp->cmd)->active_cmds--;
  2804. p->activescbs--;
  2805. scbp->flags |= SCB_WAITINGQ;
  2806. if ( !(scbp->tag_action & TAG_ENB) )
  2807. {
  2808. aic7xxx_index_busy_target(p, scbp->hscb->target_channel_lun,
  2809. TRUE);
  2810. }
  2811. }
  2812. else if (requeue)
  2813. {
  2814. p->qinfifo[p->qinfifonext++] = scbp->hscb->tag;
  2815. }
  2816. else
  2817. {
  2818. /*
  2819. * Preserve any SCB_RECOVERY_SCB flags on this scb then set the
  2820. * flags we were called with, presumeably so aic7xxx_run_done_queue
  2821. * can find this scb
  2822. */
  2823. scbp->flags = flags | (scbp->flags & SCB_RECOVERY_SCB);
  2824. if (aic7xxx_index_busy_target(p, scbp->hscb->target_channel_lun,
  2825. FALSE) == scbp->hscb->tag)
  2826. {
  2827. aic7xxx_index_busy_target(p, scbp->hscb->target_channel_lun,
  2828. TRUE);
  2829. }
  2830. }
  2831. found++;
  2832. }
  2833. else
  2834. {
  2835. p->qinfifo[p->qinfifonext++] = scbp->hscb->tag;
  2836. }
  2837. }
  2838. /*
  2839. * Now that we've done the work, clear out any left over commands in the
  2840. * qinfifo and update the KERNEL_QINPOS down on the card.
  2841. *
  2842. * NOTE: This routine expect the sequencer to already be paused when
  2843. * it is run....make sure it's that way!
  2844. */
  2845. qinpos = p->qinfifonext;
  2846. while(qinpos != qintail)
  2847. {
  2848. p->qinfifo[qinpos++] = SCB_LIST_NULL;
  2849. }
  2850. if (p->features & AHC_QUEUE_REGS)
  2851. aic_outb(p, p->qinfifonext, HNSCB_QOFF);
  2852. else
  2853. aic_outb(p, p->qinfifonext, KERNEL_QINPOS);
  2854. return (found);
  2855. }
  2856. /*+F*************************************************************************
  2857. * Function:
  2858. * aic7xxx_scb_on_qoutfifo
  2859. *
  2860. * Description:
  2861. * Is the scb that was passed to us currently on the qoutfifo?
  2862. *-F*************************************************************************/
  2863. static int
  2864. aic7xxx_scb_on_qoutfifo(struct aic7xxx_host *p, struct aic7xxx_scb *scb)
  2865. {
  2866. int i=0;
  2867. while(p->qoutfifo[(p->qoutfifonext + i) & 0xff ] != SCB_LIST_NULL)
  2868. {
  2869. if(p->qoutfifo[(p->qoutfifonext + i) & 0xff ] == scb->hscb->tag)
  2870. return TRUE;
  2871. else
  2872. i++;
  2873. }
  2874. return FALSE;
  2875. }
  2876. /*+F*************************************************************************
  2877. * Function:
  2878. * aic7xxx_reset_device
  2879. *
  2880. * Description:
  2881. * The device at the given target/channel has been reset. Abort
  2882. * all active and queued scbs for that target/channel. This function
  2883. * need not worry about linked next pointers because if was a MSG_ABORT_TAG
  2884. * then we had a tagged command (no linked next), if it was MSG_ABORT or
  2885. * MSG_BUS_DEV_RESET then the device won't know about any commands any more
  2886. * and no busy commands will exist, and if it was a bus reset, then nothing
  2887. * knows about any linked next commands any more. In all cases, we don't
  2888. * need to worry about the linked next or busy scb, we just need to clear
  2889. * them.
  2890. *-F*************************************************************************/
  2891. static void
  2892. aic7xxx_reset_device(struct aic7xxx_host *p, int target, int channel,
  2893. int lun, unsigned char tag)
  2894. {
  2895. struct aic7xxx_scb *scbp, *prev_scbp;
  2896. struct scsi_device *sd;
  2897. unsigned char active_scb, tcl, scb_tag;
  2898. int i = 0, init_lists = FALSE;
  2899. struct aic_dev_data *aic_dev;
  2900. /*
  2901. * Restore this when we're done
  2902. */
  2903. active_scb = aic_inb(p, SCBPTR);
  2904. scb_tag = aic_inb(p, SCB_TAG);
  2905. if (aic7xxx_verbose & (VERBOSE_RESET_PROCESS | VERBOSE_ABORT_PROCESS))
  2906. {
  2907. printk(INFO_LEAD "Reset device, hardware_scb %d,\n",
  2908. p->host_no, channel, target, lun, active_scb);
  2909. printk(INFO_LEAD "Current scb %d, SEQADDR 0x%x, LASTPHASE "
  2910. "0x%x\n",
  2911. p->host_no, channel, target, lun, scb_tag,
  2912. aic_inb(p, SEQADDR0) | (aic_inb(p, SEQADDR1) << 8),
  2913. aic_inb(p, LASTPHASE));
  2914. printk(INFO_LEAD "SG_CACHEPTR 0x%x, SG_COUNT %d, SCSISIGI 0x%x\n",
  2915. p->host_no, channel, target, lun,
  2916. (p->features & AHC_ULTRA2) ? aic_inb(p, SG_CACHEPTR) : 0,
  2917. aic_inb(p, SG_COUNT), aic_inb(p, SCSISIGI));
  2918. printk(INFO_LEAD "SSTAT0 0x%x, SSTAT1 0x%x, SSTAT2 0x%x\n",
  2919. p->host_no, channel, target, lun, aic_inb(p, SSTAT0),
  2920. aic_inb(p, SSTAT1), aic_inb(p, SSTAT2));
  2921. }
  2922. /*
  2923. * Deal with the busy target and linked next issues.
  2924. */
  2925. list_for_each_entry(aic_dev, &p->aic_devs, list)
  2926. {
  2927. if (aic7xxx_verbose & (VERBOSE_RESET_PROCESS | VERBOSE_ABORT_PROCESS))
  2928. printk(INFO_LEAD "processing aic_dev %p\n", p->host_no, channel, target,
  2929. lun, aic_dev);
  2930. sd = aic_dev->SDptr;
  2931. if((target != ALL_TARGETS && target != sd->id) ||
  2932. (channel != ALL_CHANNELS && channel != sd->channel))
  2933. continue;
  2934. if (aic7xxx_verbose & (VERBOSE_ABORT_PROCESS | VERBOSE_RESET_PROCESS))
  2935. printk(INFO_LEAD "Cleaning up status information "
  2936. "and delayed_scbs.\n", p->host_no, sd->channel, sd->id, sd->lun);
  2937. aic_dev->flags &= ~BUS_DEVICE_RESET_PENDING;
  2938. if ( tag == SCB_LIST_NULL )
  2939. {
  2940. aic_dev->dtr_pending = 0;
  2941. aic_dev->needppr = aic_dev->needppr_copy;
  2942. aic_dev->needsdtr = aic_dev->needsdtr_copy;
  2943. aic_dev->needwdtr = aic_dev->needwdtr_copy;
  2944. aic_dev->flags = DEVICE_PRINT_DTR;
  2945. aic_dev->temp_q_depth = aic_dev->max_q_depth;
  2946. }
  2947. tcl = (sd->id << 4) | (sd->channel << 3) | sd->lun;
  2948. if ( (aic7xxx_index_busy_target(p, tcl, FALSE) == tag) ||
  2949. (tag == SCB_LIST_NULL) )
  2950. aic7xxx_index_busy_target(p, tcl, /* unbusy */ TRUE);
  2951. prev_scbp = NULL;
  2952. scbp = aic_dev->delayed_scbs.head;
  2953. while (scbp != NULL)
  2954. {
  2955. prev_scbp = scbp;
  2956. scbp = scbp->q_next;
  2957. if (aic7xxx_match_scb(p, prev_scbp, target, channel, lun, tag))
  2958. {
  2959. scbq_remove(&aic_dev->delayed_scbs, prev_scbp);
  2960. if (prev_scbp->flags & SCB_WAITINGQ)
  2961. {
  2962. aic_dev->active_cmds++;
  2963. p->activescbs++;
  2964. }
  2965. prev_scbp->flags &= ~(SCB_ACTIVE | SCB_WAITINGQ);
  2966. prev_scbp->flags |= SCB_RESET | SCB_QUEUED_FOR_DONE;
  2967. }
  2968. }
  2969. }
  2970. if (aic7xxx_verbose & (VERBOSE_ABORT_PROCESS | VERBOSE_RESET_PROCESS))
  2971. printk(INFO_LEAD "Cleaning QINFIFO.\n", p->host_no, channel, target, lun );
  2972. aic7xxx_search_qinfifo(p, target, channel, lun, tag,
  2973. SCB_RESET | SCB_QUEUED_FOR_DONE, /* requeue */ FALSE, NULL);
  2974. /*
  2975. * Search the waiting_scbs queue for matches, this catches any SCB_QUEUED
  2976. * ABORT/RESET commands.
  2977. */
  2978. if (aic7xxx_verbose & (VERBOSE_ABORT_PROCESS | VERBOSE_RESET_PROCESS))
  2979. printk(INFO_LEAD "Cleaning waiting_scbs.\n", p->host_no, channel,
  2980. target, lun );
  2981. {
  2982. struct aic7xxx_scb *scbp, *prev_scbp;
  2983. prev_scbp = NULL;
  2984. scbp = p->waiting_scbs.head;
  2985. while (scbp != NULL)
  2986. {
  2987. prev_scbp = scbp;
  2988. scbp = scbp->q_next;
  2989. if (aic7xxx_match_scb(p, prev_scbp, target, channel, lun, tag))
  2990. {
  2991. scbq_remove(&p->waiting_scbs, prev_scbp);
  2992. if (prev_scbp->flags & SCB_WAITINGQ)
  2993. {
  2994. AIC_DEV(prev_scbp->cmd)->active_cmds++;
  2995. p->activescbs++;
  2996. }
  2997. prev_scbp->flags &= ~(SCB_ACTIVE | SCB_WAITINGQ);
  2998. prev_scbp->flags |= SCB_RESET | SCB_QUEUED_FOR_DONE;
  2999. }
  3000. }
  3001. }
  3002. /*
  3003. * Search waiting for selection list.
  3004. */
  3005. if (aic7xxx_verbose & (VERBOSE_ABORT_PROCESS | VERBOSE_RESET_PROCESS))
  3006. printk(INFO_LEAD "Cleaning waiting for selection "
  3007. "list.\n", p->host_no, channel, target, lun);
  3008. {
  3009. unsigned char next, prev, scb_index;
  3010. next = aic_inb(p, WAITING_SCBH); /* Start at head of list. */
  3011. prev = SCB_LIST_NULL;
  3012. while (next != SCB_LIST_NULL)
  3013. {
  3014. aic_outb(p, next, SCBPTR);
  3015. scb_index = aic_inb(p, SCB_TAG);
  3016. if (scb_index >= p->scb_data->numscbs)
  3017. {
  3018. /*
  3019. * No aic7xxx_verbose check here.....we want to see this since it
  3020. * means either the kernel driver or the sequencer screwed things up
  3021. */
  3022. printk(WARN_LEAD "Waiting List inconsistency; SCB index=%d, "
  3023. "numscbs=%d\n", p->host_no, channel, target, lun, scb_index,
  3024. p->scb_data->numscbs);
  3025. next = aic_inb(p, SCB_NEXT);
  3026. aic7xxx_add_curscb_to_free_list(p);
  3027. }
  3028. else
  3029. {
  3030. scbp = p->scb_data->scb_array[scb_index];
  3031. if (aic7xxx_match_scb(p, scbp, target, channel, lun, tag))
  3032. {
  3033. next = aic7xxx_abort_waiting_scb(p, scbp, next, prev);
  3034. if (scbp->flags & SCB_WAITINGQ)
  3035. {
  3036. AIC_DEV(scbp->cmd)->active_cmds++;
  3037. p->activescbs++;
  3038. }
  3039. scbp->flags &= ~(SCB_ACTIVE | SCB_WAITINGQ);
  3040. scbp->flags |= SCB_RESET | SCB_QUEUED_FOR_DONE;
  3041. if (prev == SCB_LIST_NULL)
  3042. {
  3043. /*
  3044. * This is either the first scb on the waiting list, or we
  3045. * have already yanked the first and haven't left any behind.
  3046. * Either way, we need to turn off the selection hardware if
  3047. * it isn't already off.
  3048. */
  3049. aic_outb(p, aic_inb(p, SCSISEQ) & ~ENSELO, SCSISEQ);
  3050. aic_outb(p, CLRSELTIMEO, CLRSINT1);
  3051. }
  3052. }
  3053. else
  3054. {
  3055. prev = next;
  3056. next = aic_inb(p, SCB_NEXT);
  3057. }
  3058. }
  3059. }
  3060. }
  3061. /*
  3062. * Go through disconnected list and remove any entries we have queued
  3063. * for completion, zeroing their control byte too.
  3064. */
  3065. if (aic7xxx_verbose & (VERBOSE_ABORT_PROCESS | VERBOSE_RESET_PROCESS))
  3066. printk(INFO_LEAD "Cleaning disconnected scbs "
  3067. "list.\n", p->host_no, channel, target, lun);
  3068. if (p->flags & AHC_PAGESCBS)
  3069. {
  3070. unsigned char next, prev, scb_index;
  3071. next = aic_inb(p, DISCONNECTED_SCBH);
  3072. prev = SCB_LIST_NULL;
  3073. while (next != SCB_LIST_NULL)
  3074. {
  3075. aic_outb(p, next, SCBPTR);
  3076. scb_index = aic_inb(p, SCB_TAG);
  3077. if (scb_index > p->scb_data->numscbs)
  3078. {
  3079. printk(WARN_LEAD "Disconnected List inconsistency; SCB index=%d, "
  3080. "numscbs=%d\n", p->host_no, channel, target, lun, scb_index,
  3081. p->scb_data->numscbs);
  3082. next = aic7xxx_rem_scb_from_disc_list(p, next, prev);
  3083. }
  3084. else
  3085. {
  3086. scbp = p->scb_data->scb_array[scb_index];
  3087. if (aic7xxx_match_scb(p, scbp, target, channel, lun, tag))
  3088. {
  3089. next = aic7xxx_rem_scb_from_disc_list(p, next, prev);
  3090. if (scbp->flags & SCB_WAITINGQ)
  3091. {
  3092. AIC_DEV(scbp->cmd)->active_cmds++;
  3093. p->activescbs++;
  3094. }
  3095. scbp->flags &= ~(SCB_ACTIVE | SCB_WAITINGQ);
  3096. scbp->flags |= SCB_RESET | SCB_QUEUED_FOR_DONE;
  3097. scbp->hscb->control = 0;
  3098. }
  3099. else
  3100. {
  3101. prev = next;
  3102. next = aic_inb(p, SCB_NEXT);
  3103. }
  3104. }
  3105. }
  3106. }
  3107. /*
  3108. * Walk the free list making sure no entries on the free list have
  3109. * a valid SCB_TAG value or SCB_CONTROL byte.
  3110. */
  3111. if (p->flags & AHC_PAGESCBS)
  3112. {
  3113. unsigned char next;
  3114. next = aic_inb(p, FREE_SCBH);
  3115. while (next != SCB_LIST_NULL)
  3116. {
  3117. aic_outb(p, next, SCBPTR);
  3118. if (aic_inb(p, SCB_TAG) < p->scb_data->numscbs)
  3119. {
  3120. printk(WARN_LEAD "Free list inconsistency!.\n", p->host_no, channel,
  3121. target, lun);
  3122. init_lists = TRUE;
  3123. next = SCB_LIST_NULL;
  3124. }
  3125. else
  3126. {
  3127. aic_outb(p, SCB_LIST_NULL, SCB_TAG);
  3128. aic_outb(p, 0, SCB_CONTROL);
  3129. next = aic_inb(p, SCB_NEXT);
  3130. }
  3131. }
  3132. }
  3133. /*
  3134. * Go through the hardware SCB array looking for commands that
  3135. * were active but not on any list.
  3136. */
  3137. if (init_lists)
  3138. {
  3139. aic_outb(p, SCB_LIST_NULL, FREE_SCBH);
  3140. aic_outb(p, SCB_LIST_NULL, WAITING_SCBH);
  3141. aic_outb(p, SCB_LIST_NULL, DISCONNECTED_SCBH);
  3142. }
  3143. for (i = p->scb_data->maxhscbs - 1; i >= 0; i--)
  3144. {
  3145. unsigned char scbid;
  3146. aic_outb(p, i, SCBPTR);
  3147. if (init_lists)
  3148. {
  3149. aic_outb(p, SCB_LIST_NULL, SCB_TAG);
  3150. aic_outb(p, SCB_LIST_NULL, SCB_NEXT);
  3151. aic_outb(p, 0, SCB_CONTROL);
  3152. aic7xxx_add_curscb_to_free_list(p);
  3153. }
  3154. else
  3155. {
  3156. scbid = aic_inb(p, SCB_TAG);
  3157. if (scbid < p->scb_data->numscbs)
  3158. {
  3159. scbp = p->scb_data->scb_array[scbid];
  3160. if (aic7xxx_match_scb(p, scbp, target, channel, lun, tag))
  3161. {
  3162. aic_outb(p, 0, SCB_CONTROL);
  3163. aic_outb(p, SCB_LIST_NULL, SCB_TAG);
  3164. aic7xxx_add_curscb_to_free_list(p);
  3165. }
  3166. }
  3167. }
  3168. }
  3169. /*
  3170. * Go through the entire SCB array now and look for commands for
  3171. * for this target that are stillactive. These are other (most likely
  3172. * tagged) commands that were disconnected when the reset occurred.
  3173. * Any commands we find here we know this about, it wasn't on any queue,
  3174. * it wasn't in the qinfifo, it wasn't in the disconnected or waiting
  3175. * lists, so it really must have been a paged out SCB. In that case,
  3176. * we shouldn't need to bother with updating any counters, just mark
  3177. * the correct flags and go on.
  3178. */
  3179. for (i = 0; i < p->scb_data->numscbs; i++)
  3180. {
  3181. scbp = p->scb_data->scb_array[i];
  3182. if ((scbp->flags & SCB_ACTIVE) &&
  3183. aic7xxx_match_scb(p, scbp, target, channel, lun, tag) &&
  3184. !aic7xxx_scb_on_qoutfifo(p, scbp))
  3185. {
  3186. if (scbp->flags & SCB_WAITINGQ)
  3187. {
  3188. scbq_remove(&p->waiting_scbs, scbp);
  3189. scbq_remove(&AIC_DEV(scbp->cmd)->delayed_scbs, scbp);
  3190. AIC_DEV(scbp->cmd)->active_cmds++;
  3191. p->activescbs++;
  3192. }
  3193. scbp->flags |= SCB_RESET | SCB_QUEUED_FOR_DONE;
  3194. scbp->flags &= ~(SCB_ACTIVE | SCB_WAITINGQ);
  3195. }
  3196. }
  3197. aic_outb(p, active_scb, SCBPTR);
  3198. }
  3199. /*+F*************************************************************************
  3200. * Function:
  3201. * aic7xxx_clear_intstat
  3202. *
  3203. * Description:
  3204. * Clears the interrupt status.
  3205. *-F*************************************************************************/
  3206. static void
  3207. aic7xxx_clear_intstat(struct aic7xxx_host *p)
  3208. {
  3209. /* Clear any interrupt conditions this may have caused. */
  3210. aic_outb(p, CLRSELDO | CLRSELDI | CLRSELINGO, CLRSINT0);
  3211. aic_outb(p, CLRSELTIMEO | CLRATNO | CLRSCSIRSTI | CLRBUSFREE | CLRSCSIPERR |
  3212. CLRPHASECHG | CLRREQINIT, CLRSINT1);
  3213. aic_outb(p, CLRSCSIINT | CLRSEQINT | CLRBRKADRINT | CLRPARERR, CLRINT);
  3214. }
  3215. /*+F*************************************************************************
  3216. * Function:
  3217. * aic7xxx_reset_current_bus
  3218. *
  3219. * Description:
  3220. * Reset the current SCSI bus.
  3221. *-F*************************************************************************/
  3222. static void
  3223. aic7xxx_reset_current_bus(struct aic7xxx_host *p)
  3224. {
  3225. /* Disable reset interrupts. */
  3226. aic_outb(p, aic_inb(p, SIMODE1) & ~ENSCSIRST, SIMODE1);
  3227. /* Turn off the bus' current operations, after all, we shouldn't have any
  3228. * valid commands left to cause a RSELI and SELO once we've tossed the
  3229. * bus away with this reset, so we might as well shut down the sequencer
  3230. * until the bus is restarted as opposed to saving the current settings
  3231. * and restoring them (which makes no sense to me). */
  3232. /* Turn on the bus reset. */
  3233. aic_outb(p, aic_inb(p, SCSISEQ) | SCSIRSTO, SCSISEQ);
  3234. while ( (aic_inb(p, SCSISEQ) & SCSIRSTO) == 0)
  3235. mdelay(5);
  3236. /*
  3237. * Some of the new Ultra2 chipsets need a longer delay after a chip
  3238. * reset than just the init setup creates, so we have to delay here
  3239. * before we go into a reset in order to make the chips happy.
  3240. */
  3241. if (p->features & AHC_ULTRA2)
  3242. mdelay(250);
  3243. else
  3244. mdelay(50);
  3245. /* Turn off the bus reset. */
  3246. aic_outb(p, 0, SCSISEQ);
  3247. mdelay(10);
  3248. aic7xxx_clear_intstat(p);
  3249. /* Re-enable reset interrupts. */
  3250. aic_outb(p, aic_inb(p, SIMODE1) | ENSCSIRST, SIMODE1);
  3251. }
  3252. /*+F*************************************************************************
  3253. * Function:
  3254. * aic7xxx_reset_channel
  3255. *
  3256. * Description:
  3257. * Reset the channel.
  3258. *-F*************************************************************************/
  3259. static void
  3260. aic7xxx_reset_channel(struct aic7xxx_host *p, int channel, int initiate_reset)
  3261. {
  3262. unsigned long offset_min, offset_max;
  3263. unsigned char sblkctl;
  3264. int cur_channel;
  3265. if (aic7xxx_verbose & VERBOSE_RESET_PROCESS)
  3266. printk(INFO_LEAD "Reset channel called, %s initiate reset.\n",
  3267. p->host_no, channel, -1, -1, (initiate_reset==TRUE) ? "will" : "won't" );
  3268. if (channel == 1)
  3269. {
  3270. offset_min = 8;
  3271. offset_max = 16;
  3272. }
  3273. else
  3274. {
  3275. if (p->features & AHC_TWIN)
  3276. {
  3277. /* Channel A */
  3278. offset_min = 0;
  3279. offset_max = 8;
  3280. }
  3281. else
  3282. {
  3283. offset_min = 0;
  3284. if (p->features & AHC_WIDE)
  3285. {
  3286. offset_max = 16;
  3287. }
  3288. else
  3289. {
  3290. offset_max = 8;
  3291. }
  3292. }
  3293. }
  3294. while (offset_min < offset_max)
  3295. {
  3296. /*
  3297. * Revert to async/narrow transfers until we renegotiate.
  3298. */
  3299. aic_outb(p, 0, TARG_SCSIRATE + offset_min);
  3300. if (p->features & AHC_ULTRA2)
  3301. {
  3302. aic_outb(p, 0, TARG_OFFSET + offset_min);
  3303. }
  3304. offset_min++;
  3305. }
  3306. /*
  3307. * Reset the bus and unpause/restart the controller
  3308. */
  3309. sblkctl = aic_inb(p, SBLKCTL);
  3310. if ( (p->chip & AHC_CHIPID_MASK) == AHC_AIC7770 )
  3311. cur_channel = (sblkctl & SELBUSB) >> 3;
  3312. else
  3313. cur_channel = 0;
  3314. if ( (cur_channel != channel) && (p->features & AHC_TWIN) )
  3315. {
  3316. /*
  3317. * Case 1: Command for another bus is active
  3318. */
  3319. if (aic7xxx_verbose & VERBOSE_RESET_PROCESS)
  3320. printk(INFO_LEAD "Stealthily resetting idle channel.\n", p->host_no,
  3321. channel, -1, -1);
  3322. /*
  3323. * Stealthily reset the other bus without upsetting the current bus.
  3324. */
  3325. aic_outb(p, sblkctl ^ SELBUSB, SBLKCTL);
  3326. aic_outb(p, aic_inb(p, SIMODE1) & ~ENBUSFREE, SIMODE1);
  3327. if (initiate_reset)
  3328. {
  3329. aic7xxx_reset_current_bus(p);
  3330. }
  3331. aic_outb(p, aic_inb(p, SCSISEQ) & (ENSELI|ENRSELI|ENAUTOATNP), SCSISEQ);
  3332. aic7xxx_clear_intstat(p);
  3333. aic_outb(p, sblkctl, SBLKCTL);
  3334. }
  3335. else
  3336. {
  3337. /*
  3338. * Case 2: A command from this bus is active or we're idle.
  3339. */
  3340. if (aic7xxx_verbose & VERBOSE_RESET_PROCESS)
  3341. printk(INFO_LEAD "Resetting currently active channel.\n", p->host_no,
  3342. channel, -1, -1);
  3343. aic_outb(p, aic_inb(p, SIMODE1) & ~(ENBUSFREE|ENREQINIT),
  3344. SIMODE1);
  3345. p->flags &= ~AHC_HANDLING_REQINITS;
  3346. p->msg_type = MSG_TYPE_NONE;
  3347. p->msg_len = 0;
  3348. if (initiate_reset)
  3349. {
  3350. aic7xxx_reset_current_bus(p);
  3351. }
  3352. aic_outb(p, aic_inb(p, SCSISEQ) & (ENSELI|ENRSELI|ENAUTOATNP), SCSISEQ);
  3353. aic7xxx_clear_intstat(p);
  3354. }
  3355. if (aic7xxx_verbose & VERBOSE_RESET_RETURN)
  3356. printk(INFO_LEAD "Channel reset\n", p->host_no, channel, -1, -1);
  3357. /*
  3358. * Clean up all the state information for the pending transactions
  3359. * on this bus.
  3360. */
  3361. aic7xxx_reset_device(p, ALL_TARGETS, channel, ALL_LUNS, SCB_LIST_NULL);
  3362. if ( !(p->features & AHC_TWIN) )
  3363. {
  3364. restart_sequencer(p);
  3365. }
  3366. return;
  3367. }
  3368. /*+F*************************************************************************
  3369. * Function:
  3370. * aic7xxx_run_waiting_queues
  3371. *
  3372. * Description:
  3373. * Scan the awaiting_scbs queue downloading and starting as many
  3374. * scbs as we can.
  3375. *-F*************************************************************************/
  3376. static void
  3377. aic7xxx_run_waiting_queues(struct aic7xxx_host *p)
  3378. {
  3379. struct aic7xxx_scb *scb;
  3380. struct aic_dev_data *aic_dev;
  3381. int sent;
  3382. if (p->waiting_scbs.head == NULL)
  3383. return;
  3384. sent = 0;
  3385. /*
  3386. * First handle SCBs that are waiting but have been assigned a slot.
  3387. */
  3388. while ((scb = scbq_remove_head(&p->waiting_scbs)) != NULL)
  3389. {
  3390. aic_dev = scb->cmd->device->hostdata;
  3391. if ( !scb->tag_action )
  3392. {
  3393. aic_dev->temp_q_depth = 1;
  3394. }
  3395. if ( aic_dev->active_cmds >= aic_dev->temp_q_depth)
  3396. {
  3397. scbq_insert_tail(&aic_dev->delayed_scbs, scb);
  3398. }
  3399. else
  3400. {
  3401. scb->flags &= ~SCB_WAITINGQ;
  3402. aic_dev->active_cmds++;
  3403. p->activescbs++;
  3404. if ( !(scb->tag_action) )
  3405. {
  3406. aic7xxx_busy_target(p, scb);
  3407. }
  3408. p->qinfifo[p->qinfifonext++] = scb->hscb->tag;
  3409. sent++;
  3410. }
  3411. }
  3412. if (sent)
  3413. {
  3414. if (p->features & AHC_QUEUE_REGS)
  3415. aic_outb(p, p->qinfifonext, HNSCB_QOFF);
  3416. else
  3417. {
  3418. pause_sequencer(p);
  3419. aic_outb(p, p->qinfifonext, KERNEL_QINPOS);
  3420. unpause_sequencer(p, FALSE);
  3421. }
  3422. if (p->activescbs > p->max_activescbs)
  3423. p->max_activescbs = p->activescbs;
  3424. }
  3425. }
  3426. #ifdef CONFIG_PCI
  3427. #define DPE 0x80
  3428. #define SSE 0x40
  3429. #define RMA 0x20
  3430. #define RTA 0x10
  3431. #define STA 0x08
  3432. #define DPR 0x01
  3433. /*+F*************************************************************************
  3434. * Function:
  3435. * aic7xxx_pci_intr
  3436. *
  3437. * Description:
  3438. * Check the scsi card for PCI errors and clear the interrupt
  3439. *
  3440. * NOTE: If you don't have this function and a 2940 card encounters
  3441. * a PCI error condition, the machine will end up locked as the
  3442. * interrupt handler gets slammed with non-stop PCI error interrupts
  3443. *-F*************************************************************************/
  3444. static void
  3445. aic7xxx_pci_intr(struct aic7xxx_host *p)
  3446. {
  3447. unsigned char status1;
  3448. pci_read_config_byte(p->pdev, PCI_STATUS + 1, &status1);
  3449. if ( (status1 & DPE) && (aic7xxx_verbose & VERBOSE_MINOR_ERROR) )
  3450. printk(WARN_LEAD "Data Parity Error during PCI address or PCI write"
  3451. "phase.\n", p->host_no, -1, -1, -1);
  3452. if ( (status1 & SSE) && (aic7xxx_verbose & VERBOSE_MINOR_ERROR) )
  3453. printk(WARN_LEAD "Signal System Error Detected\n", p->host_no,
  3454. -1, -1, -1);
  3455. if ( (status1 & RMA) && (aic7xxx_verbose & VERBOSE_MINOR_ERROR) )
  3456. printk(WARN_LEAD "Received a PCI Master Abort\n", p->host_no,
  3457. -1, -1, -1);
  3458. if ( (status1 & RTA) && (aic7xxx_verbose & VERBOSE_MINOR_ERROR) )
  3459. printk(WARN_LEAD "Received a PCI Target Abort\n", p->host_no,
  3460. -1, -1, -1);
  3461. if ( (status1 & STA) && (aic7xxx_verbose & VERBOSE_MINOR_ERROR) )
  3462. printk(WARN_LEAD "Signaled a PCI Target Abort\n", p->host_no,
  3463. -1, -1, -1);
  3464. if ( (status1 & DPR) && (aic7xxx_verbose & VERBOSE_MINOR_ERROR) )
  3465. printk(WARN_LEAD "Data Parity Error has been reported via PCI pin "
  3466. "PERR#\n", p->host_no, -1, -1, -1);
  3467. pci_write_config_byte(p->pdev, PCI_STATUS + 1, status1);
  3468. if (status1 & (DPR|RMA|RTA))
  3469. aic_outb(p, CLRPARERR, CLRINT);
  3470. if ( (aic7xxx_panic_on_abort) && (p->spurious_int > 500) )
  3471. aic7xxx_panic_abort(p, NULL);
  3472. }
  3473. #endif /* CONFIG_PCI */
  3474. /*+F*************************************************************************
  3475. * Function:
  3476. * aic7xxx_construct_ppr
  3477. *
  3478. * Description:
  3479. * Build up a Parallel Protocol Request message for use with SCSI-3
  3480. * devices.
  3481. *-F*************************************************************************/
  3482. static void
  3483. aic7xxx_construct_ppr(struct aic7xxx_host *p, struct aic7xxx_scb *scb)
  3484. {
  3485. p->msg_buf[p->msg_index++] = MSG_EXTENDED;
  3486. p->msg_buf[p->msg_index++] = MSG_EXT_PPR_LEN;
  3487. p->msg_buf[p->msg_index++] = MSG_EXT_PPR;
  3488. p->msg_buf[p->msg_index++] = AIC_DEV(scb->cmd)->goal.period;
  3489. p->msg_buf[p->msg_index++] = 0;
  3490. p->msg_buf[p->msg_index++] = AIC_DEV(scb->cmd)->goal.offset;
  3491. p->msg_buf[p->msg_index++] = AIC_DEV(scb->cmd)->goal.width;
  3492. p->msg_buf[p->msg_index++] = AIC_DEV(scb->cmd)->goal.options;
  3493. p->msg_len += 8;
  3494. }
  3495. /*+F*************************************************************************
  3496. * Function:
  3497. * aic7xxx_construct_sdtr
  3498. *
  3499. * Description:
  3500. * Constucts a synchronous data transfer message in the message
  3501. * buffer on the sequencer.
  3502. *-F*************************************************************************/
  3503. static void
  3504. aic7xxx_construct_sdtr(struct aic7xxx_host *p, unsigned char period,
  3505. unsigned char offset)
  3506. {
  3507. p->msg_buf[p->msg_index++] = MSG_EXTENDED;
  3508. p->msg_buf[p->msg_index++] = MSG_EXT_SDTR_LEN;
  3509. p->msg_buf[p->msg_index++] = MSG_EXT_SDTR;
  3510. p->msg_buf[p->msg_index++] = period;
  3511. p->msg_buf[p->msg_index++] = offset;
  3512. p->msg_len += 5;
  3513. }
  3514. /*+F*************************************************************************
  3515. * Function:
  3516. * aic7xxx_construct_wdtr
  3517. *
  3518. * Description:
  3519. * Constucts a wide data transfer message in the message buffer
  3520. * on the sequencer.
  3521. *-F*************************************************************************/
  3522. static void
  3523. aic7xxx_construct_wdtr(struct aic7xxx_host *p, unsigned char bus_width)
  3524. {
  3525. p->msg_buf[p->msg_index++] = MSG_EXTENDED;
  3526. p->msg_buf[p->msg_index++] = MSG_EXT_WDTR_LEN;
  3527. p->msg_buf[p->msg_index++] = MSG_EXT_WDTR;
  3528. p->msg_buf[p->msg_index++] = bus_width;
  3529. p->msg_len += 4;
  3530. }
  3531. /*+F*************************************************************************
  3532. * Function:
  3533. * aic7xxx_calc_residual
  3534. *
  3535. * Description:
  3536. * Calculate the residual data not yet transferred.
  3537. *-F*************************************************************************/
  3538. static void
  3539. aic7xxx_calculate_residual (struct aic7xxx_host *p, struct aic7xxx_scb *scb)
  3540. {
  3541. struct aic7xxx_hwscb *hscb;
  3542. struct scsi_cmnd *cmd;
  3543. int actual, i;
  3544. cmd = scb->cmd;
  3545. hscb = scb->hscb;
  3546. /*
  3547. * Don't destroy valid residual information with
  3548. * residual coming from a check sense operation.
  3549. */
  3550. if (((scb->hscb->control & DISCONNECTED) == 0) &&
  3551. (scb->flags & SCB_SENSE) == 0)
  3552. {
  3553. /*
  3554. * We had an underflow. At this time, there's only
  3555. * one other driver that bothers to check for this,
  3556. * and cmd->underflow seems to be set rather half-
  3557. * heartedly in the higher-level SCSI code.
  3558. */
  3559. actual = scb->sg_length;
  3560. for (i=1; i < hscb->residual_SG_segment_count; i++)
  3561. {
  3562. actual -= scb->sg_list[scb->sg_count - i].length;
  3563. }
  3564. actual -= (hscb->residual_data_count[2] << 16) |
  3565. (hscb->residual_data_count[1] << 8) |
  3566. hscb->residual_data_count[0];
  3567. if (actual < cmd->underflow)
  3568. {
  3569. if (aic7xxx_verbose & VERBOSE_MINOR_ERROR)
  3570. {
  3571. printk(INFO_LEAD "Underflow - Wanted %u, %s %u, residual SG "
  3572. "count %d.\n", p->host_no, CTL_OF_SCB(scb), cmd->underflow,
  3573. (rq_data_dir(cmd->request) == WRITE) ? "wrote" : "read", actual,
  3574. hscb->residual_SG_segment_count);
  3575. printk(INFO_LEAD "status 0x%x.\n", p->host_no, CTL_OF_SCB(scb),
  3576. hscb->target_status);
  3577. }
  3578. /*
  3579. * In 2.4, only send back the residual information, don't flag this
  3580. * as an error. Before 2.4 we had to flag this as an error because
  3581. * the mid layer didn't check residual data counts to see if the
  3582. * command needs retried.
  3583. */
  3584. scsi_set_resid(cmd, scb->sg_length - actual);
  3585. aic7xxx_status(cmd) = hscb->target_status;
  3586. }
  3587. }
  3588. /*
  3589. * Clean out the residual information in the SCB for the
  3590. * next consumer.
  3591. */
  3592. hscb->residual_data_count[2] = 0;
  3593. hscb->residual_data_count[1] = 0;
  3594. hscb->residual_data_count[0] = 0;
  3595. hscb->residual_SG_segment_count = 0;
  3596. }
  3597. /*+F*************************************************************************
  3598. * Function:
  3599. * aic7xxx_handle_device_reset
  3600. *
  3601. * Description:
  3602. * Interrupt handler for sequencer interrupts (SEQINT).
  3603. *-F*************************************************************************/
  3604. static void
  3605. aic7xxx_handle_device_reset(struct aic7xxx_host *p, int target, int channel)
  3606. {
  3607. unsigned char tindex = target;
  3608. tindex |= ((channel & 0x01) << 3);
  3609. /*
  3610. * Go back to async/narrow transfers and renegotiate.
  3611. */
  3612. aic_outb(p, 0, TARG_SCSIRATE + tindex);
  3613. if (p->features & AHC_ULTRA2)
  3614. aic_outb(p, 0, TARG_OFFSET + tindex);
  3615. aic7xxx_reset_device(p, target, channel, ALL_LUNS, SCB_LIST_NULL);
  3616. if (aic7xxx_verbose & VERBOSE_RESET_PROCESS)
  3617. printk(INFO_LEAD "Bus Device Reset delivered.\n", p->host_no, channel,
  3618. target, -1);
  3619. aic7xxx_run_done_queue(p, /*complete*/ TRUE);
  3620. }
  3621. /*+F*************************************************************************
  3622. * Function:
  3623. * aic7xxx_handle_seqint
  3624. *
  3625. * Description:
  3626. * Interrupt handler for sequencer interrupts (SEQINT).
  3627. *-F*************************************************************************/
  3628. static void
  3629. aic7xxx_handle_seqint(struct aic7xxx_host *p, unsigned char intstat)
  3630. {
  3631. struct aic7xxx_scb *scb;
  3632. struct aic_dev_data *aic_dev;
  3633. unsigned short target_mask;
  3634. unsigned char target, lun, tindex;
  3635. unsigned char queue_flag = FALSE;
  3636. char channel;
  3637. int result;
  3638. target = ((aic_inb(p, SAVED_TCL) >> 4) & 0x0f);
  3639. if ( (p->chip & AHC_CHIPID_MASK) == AHC_AIC7770 )
  3640. channel = (aic_inb(p, SBLKCTL) & SELBUSB) >> 3;
  3641. else
  3642. channel = 0;
  3643. tindex = target + (channel << 3);
  3644. lun = aic_inb(p, SAVED_TCL) & 0x07;
  3645. target_mask = (0x01 << tindex);
  3646. /*
  3647. * Go ahead and clear the SEQINT now, that avoids any interrupt race
  3648. * conditions later on in case we enable some other interrupt.
  3649. */
  3650. aic_outb(p, CLRSEQINT, CLRINT);
  3651. switch (intstat & SEQINT_MASK)
  3652. {
  3653. case NO_MATCH:
  3654. {
  3655. aic_outb(p, aic_inb(p, SCSISEQ) & (ENSELI|ENRSELI|ENAUTOATNP),
  3656. SCSISEQ);
  3657. printk(WARN_LEAD "No active SCB for reconnecting target - Issuing "
  3658. "BUS DEVICE RESET.\n", p->host_no, channel, target, lun);
  3659. printk(WARN_LEAD " SAVED_TCL=0x%x, ARG_1=0x%x, SEQADDR=0x%x\n",
  3660. p->host_no, channel, target, lun,
  3661. aic_inb(p, SAVED_TCL), aic_inb(p, ARG_1),
  3662. (aic_inb(p, SEQADDR1) << 8) | aic_inb(p, SEQADDR0));
  3663. if (aic7xxx_panic_on_abort)
  3664. aic7xxx_panic_abort(p, NULL);
  3665. }
  3666. break;
  3667. case SEND_REJECT:
  3668. {
  3669. if (aic7xxx_verbose & VERBOSE_MINOR_ERROR)
  3670. printk(INFO_LEAD "Rejecting unknown message (0x%x) received from "
  3671. "target, SEQ_FLAGS=0x%x\n", p->host_no, channel, target, lun,
  3672. aic_inb(p, ACCUM), aic_inb(p, SEQ_FLAGS));
  3673. }
  3674. break;
  3675. case NO_IDENT:
  3676. {
  3677. /*
  3678. * The reconnecting target either did not send an identify
  3679. * message, or did, but we didn't find an SCB to match and
  3680. * before it could respond to our ATN/abort, it hit a dataphase.
  3681. * The only safe thing to do is to blow it away with a bus
  3682. * reset.
  3683. */
  3684. if (aic7xxx_verbose & (VERBOSE_SEQINT | VERBOSE_RESET_MID))
  3685. printk(INFO_LEAD "Target did not send an IDENTIFY message; "
  3686. "LASTPHASE 0x%x, SAVED_TCL 0x%x\n", p->host_no, channel, target,
  3687. lun, aic_inb(p, LASTPHASE), aic_inb(p, SAVED_TCL));
  3688. aic7xxx_reset_channel(p, channel, /*initiate reset*/ TRUE);
  3689. aic7xxx_run_done_queue(p, TRUE);
  3690. }
  3691. break;
  3692. case BAD_PHASE:
  3693. if (aic_inb(p, LASTPHASE) == P_BUSFREE)
  3694. {
  3695. if (aic7xxx_verbose & VERBOSE_SEQINT)
  3696. printk(INFO_LEAD "Missed busfree.\n", p->host_no, channel,
  3697. target, lun);
  3698. restart_sequencer(p);
  3699. }
  3700. else
  3701. {
  3702. if (aic7xxx_verbose & VERBOSE_SEQINT)
  3703. printk(INFO_LEAD "Unknown scsi bus phase, continuing\n", p->host_no,
  3704. channel, target, lun);
  3705. }
  3706. break;
  3707. case EXTENDED_MSG:
  3708. {
  3709. p->msg_type = MSG_TYPE_INITIATOR_MSGIN;
  3710. p->msg_len = 0;
  3711. p->msg_index = 0;
  3712. #ifdef AIC7XXX_VERBOSE_DEBUGGING
  3713. if (aic7xxx_verbose > 0xffff)
  3714. printk(INFO_LEAD "Enabling REQINITs for MSG_IN\n", p->host_no,
  3715. channel, target, lun);
  3716. #endif
  3717. /*
  3718. * To actually receive the message, simply turn on
  3719. * REQINIT interrupts and let our interrupt handler
  3720. * do the rest (REQINIT should already be true).
  3721. */
  3722. p->flags |= AHC_HANDLING_REQINITS;
  3723. aic_outb(p, aic_inb(p, SIMODE1) | ENREQINIT, SIMODE1);
  3724. /*
  3725. * We don't want the sequencer unpaused yet so we return early
  3726. */
  3727. return;
  3728. }
  3729. case REJECT_MSG:
  3730. {
  3731. /*
  3732. * What we care about here is if we had an outstanding SDTR
  3733. * or WDTR message for this target. If we did, this is a
  3734. * signal that the target is refusing negotiation.
  3735. */
  3736. unsigned char scb_index;
  3737. unsigned char last_msg;
  3738. scb_index = aic_inb(p, SCB_TAG);
  3739. scb = p->scb_data->scb_array[scb_index];
  3740. aic_dev = AIC_DEV(scb->cmd);
  3741. last_msg = aic_inb(p, LAST_MSG);
  3742. if ( (last_msg == MSG_IDENTIFYFLAG) &&
  3743. (scb->tag_action) &&
  3744. !(scb->flags & SCB_MSGOUT_BITS) )
  3745. {
  3746. if (scb->tag_action == MSG_ORDERED_Q_TAG)
  3747. {
  3748. /*
  3749. * OK...the device seems able to accept tagged commands, but
  3750. * not ordered tag commands, only simple tag commands. So, we
  3751. * disable ordered tag commands and go on with life just like
  3752. * normal.
  3753. */
  3754. scsi_adjust_queue_depth(scb->cmd->device, MSG_SIMPLE_TAG,
  3755. scb->cmd->device->queue_depth);
  3756. scb->tag_action = MSG_SIMPLE_Q_TAG;
  3757. scb->hscb->control &= ~SCB_TAG_TYPE;
  3758. scb->hscb->control |= MSG_SIMPLE_Q_TAG;
  3759. aic_outb(p, scb->hscb->control, SCB_CONTROL);
  3760. /*
  3761. * OK..we set the tag type to simple tag command, now we re-assert
  3762. * ATNO and hope this will take us into the identify phase again
  3763. * so we can resend the tag type and info to the device.
  3764. */
  3765. aic_outb(p, MSG_IDENTIFYFLAG, MSG_OUT);
  3766. aic_outb(p, aic_inb(p, SCSISIGI) | ATNO, SCSISIGO);
  3767. }
  3768. else if (scb->tag_action == MSG_SIMPLE_Q_TAG)
  3769. {
  3770. unsigned char i;
  3771. struct aic7xxx_scb *scbp;
  3772. int old_verbose;
  3773. /*
  3774. * Hmmmm....the device is flaking out on tagged commands.
  3775. */
  3776. scsi_adjust_queue_depth(scb->cmd->device, 0 /* untagged */,
  3777. p->host->cmd_per_lun);
  3778. aic_dev->max_q_depth = aic_dev->temp_q_depth = 1;
  3779. /*
  3780. * We set this command up as a bus device reset. However, we have
  3781. * to clear the tag type as it's causing us problems. We shouldn't
  3782. * have to worry about any other commands being active, since if
  3783. * the device is refusing tagged commands, this should be the
  3784. * first tagged command sent to the device, however, we do have
  3785. * to worry about any other tagged commands that may already be
  3786. * in the qinfifo. The easiest way to do this, is to issue a BDR,
  3787. * send all the commands back to the mid level code, then let them
  3788. * come back and get rebuilt as untagged commands.
  3789. */
  3790. scb->tag_action = 0;
  3791. scb->hscb->control &= ~(TAG_ENB | SCB_TAG_TYPE);
  3792. aic_outb(p, scb->hscb->control, SCB_CONTROL);
  3793. old_verbose = aic7xxx_verbose;
  3794. aic7xxx_verbose &= ~(VERBOSE_RESET|VERBOSE_ABORT);
  3795. for (i=0; i < p->scb_data->numscbs; i++)
  3796. {
  3797. scbp = p->scb_data->scb_array[i];
  3798. if ((scbp->flags & SCB_ACTIVE) && (scbp != scb))
  3799. {
  3800. if (aic7xxx_match_scb(p, scbp, target, channel, lun, i))
  3801. {
  3802. aic7xxx_reset_device(p, target, channel, lun, i);
  3803. }
  3804. }
  3805. }
  3806. aic7xxx_run_done_queue(p, TRUE);
  3807. aic7xxx_verbose = old_verbose;
  3808. /*
  3809. * Wait until after the for loop to set the busy index since
  3810. * aic7xxx_reset_device will clear the busy index during its
  3811. * operation.
  3812. */
  3813. aic7xxx_busy_target(p, scb);
  3814. printk(INFO_LEAD "Device is refusing tagged commands, using "
  3815. "untagged I/O.\n", p->host_no, channel, target, lun);
  3816. aic_outb(p, MSG_IDENTIFYFLAG, MSG_OUT);
  3817. aic_outb(p, aic_inb(p, SCSISIGI) | ATNO, SCSISIGO);
  3818. }
  3819. }
  3820. else if (scb->flags & SCB_MSGOUT_PPR)
  3821. {
  3822. /*
  3823. * As per the draft specs, any device capable of supporting any of
  3824. * the option values other than 0 are not allowed to reject the
  3825. * PPR message. Instead, they must negotiate out what they do
  3826. * support instead of rejecting our offering or else they cause
  3827. * a parity error during msg_out phase to signal that they don't
  3828. * like our settings.
  3829. */
  3830. aic_dev->needppr = aic_dev->needppr_copy = 0;
  3831. aic7xxx_set_width(p, target, channel, lun, MSG_EXT_WDTR_BUS_8_BIT,
  3832. (AHC_TRANS_ACTIVE|AHC_TRANS_CUR|AHC_TRANS_QUITE), aic_dev);
  3833. aic7xxx_set_syncrate(p, NULL, target, channel, 0, 0, 0,
  3834. AHC_TRANS_ACTIVE|AHC_TRANS_CUR|AHC_TRANS_QUITE,
  3835. aic_dev);
  3836. aic_dev->goal.options = aic_dev->dtr_pending = 0;
  3837. scb->flags &= ~SCB_MSGOUT_BITS;
  3838. if(aic7xxx_verbose & VERBOSE_NEGOTIATION2)
  3839. {
  3840. printk(INFO_LEAD "Device is rejecting PPR messages, falling "
  3841. "back.\n", p->host_no, channel, target, lun);
  3842. }
  3843. if ( aic_dev->goal.width )
  3844. {
  3845. aic_dev->needwdtr = aic_dev->needwdtr_copy = 1;
  3846. aic_dev->dtr_pending = 1;
  3847. scb->flags |= SCB_MSGOUT_WDTR;
  3848. }
  3849. if ( aic_dev->goal.offset )
  3850. {
  3851. aic_dev->needsdtr = aic_dev->needsdtr_copy = 1;
  3852. if( !aic_dev->dtr_pending )
  3853. {
  3854. aic_dev->dtr_pending = 1;
  3855. scb->flags |= SCB_MSGOUT_SDTR;
  3856. }
  3857. }
  3858. if ( aic_dev->dtr_pending )
  3859. {
  3860. aic_outb(p, HOST_MSG, MSG_OUT);
  3861. aic_outb(p, aic_inb(p, SCSISIGI) | ATNO, SCSISIGO);
  3862. }
  3863. }
  3864. else if (scb->flags & SCB_MSGOUT_WDTR)
  3865. {
  3866. /*
  3867. * note 8bit xfers and clear flag
  3868. */
  3869. aic_dev->needwdtr = aic_dev->needwdtr_copy = 0;
  3870. scb->flags &= ~SCB_MSGOUT_BITS;
  3871. aic7xxx_set_width(p, target, channel, lun, MSG_EXT_WDTR_BUS_8_BIT,
  3872. (AHC_TRANS_ACTIVE|AHC_TRANS_GOAL|AHC_TRANS_CUR), aic_dev);
  3873. aic7xxx_set_syncrate(p, NULL, target, channel, 0, 0, 0,
  3874. AHC_TRANS_ACTIVE|AHC_TRANS_CUR|AHC_TRANS_QUITE,
  3875. aic_dev);
  3876. if(aic7xxx_verbose & VERBOSE_NEGOTIATION2)
  3877. {
  3878. printk(INFO_LEAD "Device is rejecting WDTR messages, using "
  3879. "narrow transfers.\n", p->host_no, channel, target, lun);
  3880. }
  3881. aic_dev->needsdtr = aic_dev->needsdtr_copy;
  3882. }
  3883. else if (scb->flags & SCB_MSGOUT_SDTR)
  3884. {
  3885. /*
  3886. * note asynch xfers and clear flag
  3887. */
  3888. aic_dev->needsdtr = aic_dev->needsdtr_copy = 0;
  3889. scb->flags &= ~SCB_MSGOUT_BITS;
  3890. aic7xxx_set_syncrate(p, NULL, target, channel, 0, 0, 0,
  3891. (AHC_TRANS_CUR|AHC_TRANS_ACTIVE|AHC_TRANS_GOAL), aic_dev);
  3892. if(aic7xxx_verbose & VERBOSE_NEGOTIATION2)
  3893. {
  3894. printk(INFO_LEAD "Device is rejecting SDTR messages, using "
  3895. "async transfers.\n", p->host_no, channel, target, lun);
  3896. }
  3897. }
  3898. else if (aic7xxx_verbose & VERBOSE_SEQINT)
  3899. {
  3900. /*
  3901. * Otherwise, we ignore it.
  3902. */
  3903. printk(INFO_LEAD "Received MESSAGE_REJECT for unknown cause. "
  3904. "Ignoring.\n", p->host_no, channel, target, lun);
  3905. }
  3906. }
  3907. break;
  3908. case BAD_STATUS:
  3909. {
  3910. unsigned char scb_index;
  3911. struct aic7xxx_hwscb *hscb;
  3912. struct scsi_cmnd *cmd;
  3913. /* The sequencer will notify us when a command has an error that
  3914. * would be of interest to the kernel. This allows us to leave
  3915. * the sequencer running in the common case of command completes
  3916. * without error. The sequencer will have DMA'd the SCB back
  3917. * up to us, so we can reference the drivers SCB array.
  3918. *
  3919. * Set the default return value to 0 indicating not to send
  3920. * sense. The sense code will change this if needed and this
  3921. * reduces code duplication.
  3922. */
  3923. aic_outb(p, 0, RETURN_1);
  3924. scb_index = aic_inb(p, SCB_TAG);
  3925. if (scb_index > p->scb_data->numscbs)
  3926. {
  3927. printk(WARN_LEAD "Invalid SCB during SEQINT 0x%02x, SCB_TAG %d.\n",
  3928. p->host_no, channel, target, lun, intstat, scb_index);
  3929. break;
  3930. }
  3931. scb = p->scb_data->scb_array[scb_index];
  3932. hscb = scb->hscb;
  3933. if (!(scb->flags & SCB_ACTIVE) || (scb->cmd == NULL))
  3934. {
  3935. printk(WARN_LEAD "Invalid SCB during SEQINT 0x%x, scb %d, flags 0x%x,"
  3936. " cmd 0x%lx.\n", p->host_no, channel, target, lun, intstat,
  3937. scb_index, scb->flags, (unsigned long) scb->cmd);
  3938. }
  3939. else
  3940. {
  3941. cmd = scb->cmd;
  3942. aic_dev = AIC_DEV(scb->cmd);
  3943. hscb->target_status = aic_inb(p, SCB_TARGET_STATUS);
  3944. aic7xxx_status(cmd) = hscb->target_status;
  3945. cmd->result = hscb->target_status;
  3946. switch (status_byte(hscb->target_status))
  3947. {
  3948. case GOOD:
  3949. if (aic7xxx_verbose & VERBOSE_SEQINT)
  3950. printk(INFO_LEAD "Interrupted for status of GOOD???\n",
  3951. p->host_no, CTL_OF_SCB(scb));
  3952. break;
  3953. case COMMAND_TERMINATED:
  3954. case CHECK_CONDITION:
  3955. if ( !(scb->flags & SCB_SENSE) )
  3956. {
  3957. /*
  3958. * Send a sense command to the requesting target.
  3959. * XXX - revisit this and get rid of the memcopys.
  3960. */
  3961. memcpy(scb->sense_cmd, &generic_sense[0],
  3962. sizeof(generic_sense));
  3963. scb->sense_cmd[1] = (cmd->device->lun << 5);
  3964. scb->sense_cmd[4] = SCSI_SENSE_BUFFERSIZE;
  3965. scb->sg_list[0].length =
  3966. cpu_to_le32(SCSI_SENSE_BUFFERSIZE);
  3967. scb->sg_list[0].address =
  3968. cpu_to_le32(pci_map_single(p->pdev, cmd->sense_buffer,
  3969. SCSI_SENSE_BUFFERSIZE,
  3970. PCI_DMA_FROMDEVICE));
  3971. /*
  3972. * XXX - We should allow disconnection, but can't as it
  3973. * might allow overlapped tagged commands.
  3974. */
  3975. /* hscb->control &= DISCENB; */
  3976. hscb->control = 0;
  3977. hscb->target_status = 0;
  3978. hscb->SG_list_pointer =
  3979. cpu_to_le32(SCB_DMA_ADDR(scb, scb->sg_list));
  3980. hscb->SCSI_cmd_pointer =
  3981. cpu_to_le32(SCB_DMA_ADDR(scb, scb->sense_cmd));
  3982. hscb->data_count = scb->sg_list[0].length;
  3983. hscb->data_pointer = scb->sg_list[0].address;
  3984. hscb->SCSI_cmd_length = COMMAND_SIZE(scb->sense_cmd[0]);
  3985. hscb->residual_SG_segment_count = 0;
  3986. hscb->residual_data_count[0] = 0;
  3987. hscb->residual_data_count[1] = 0;
  3988. hscb->residual_data_count[2] = 0;
  3989. scb->sg_count = hscb->SG_segment_count = 1;
  3990. scb->sg_length = SCSI_SENSE_BUFFERSIZE;
  3991. scb->tag_action = 0;
  3992. scb->flags |= SCB_SENSE;
  3993. /*
  3994. * Ensure the target is busy since this will be an
  3995. * an untagged request.
  3996. */
  3997. #ifdef AIC7XXX_VERBOSE_DEBUGGING
  3998. if (aic7xxx_verbose & VERBOSE_NEGOTIATION2)
  3999. {
  4000. if (scb->flags & SCB_MSGOUT_BITS)
  4001. printk(INFO_LEAD "Requesting SENSE with %s\n", p->host_no,
  4002. CTL_OF_SCB(scb), (scb->flags & SCB_MSGOUT_SDTR) ?
  4003. "SDTR" : "WDTR");
  4004. else
  4005. printk(INFO_LEAD "Requesting SENSE, no MSG\n", p->host_no,
  4006. CTL_OF_SCB(scb));
  4007. }
  4008. #endif
  4009. aic7xxx_busy_target(p, scb);
  4010. aic_outb(p, SEND_SENSE, RETURN_1);
  4011. aic7xxx_error(cmd) = DID_OK;
  4012. break;
  4013. } /* first time sense, no errors */
  4014. printk(INFO_LEAD "CHECK_CONDITION on REQUEST_SENSE, returning "
  4015. "an error.\n", p->host_no, CTL_OF_SCB(scb));
  4016. aic7xxx_error(cmd) = DID_ERROR;
  4017. scb->flags &= ~SCB_SENSE;
  4018. break;
  4019. case QUEUE_FULL:
  4020. queue_flag = TRUE; /* Mark that this is a QUEUE_FULL and */
  4021. case BUSY: /* drop through to here */
  4022. {
  4023. struct aic7xxx_scb *next_scbp, *prev_scbp;
  4024. unsigned char active_hscb, next_hscb, prev_hscb, scb_index;
  4025. /*
  4026. * We have to look three places for queued commands:
  4027. * 1: p->waiting_scbs queue
  4028. * 2: QINFIFO
  4029. * 3: WAITING_SCBS list on card (for commands that are started
  4030. * but haven't yet made it to the device)
  4031. *
  4032. * Of special note here is that commands on 2 or 3 above will
  4033. * have already been marked as active, while commands on 1 will
  4034. * not. The aic7xxx_done() function will want to unmark them
  4035. * from active, so any commands we pull off of 1 need to
  4036. * up the active count.
  4037. */
  4038. next_scbp = p->waiting_scbs.head;
  4039. while ( next_scbp != NULL )
  4040. {
  4041. prev_scbp = next_scbp;
  4042. next_scbp = next_scbp->q_next;
  4043. if ( aic7xxx_match_scb(p, prev_scbp, target, channel, lun,
  4044. SCB_LIST_NULL) )
  4045. {
  4046. scbq_remove(&p->waiting_scbs, prev_scbp);
  4047. scb->flags = SCB_QUEUED_FOR_DONE | SCB_QUEUE_FULL;
  4048. p->activescbs++;
  4049. aic_dev->active_cmds++;
  4050. }
  4051. }
  4052. aic7xxx_search_qinfifo(p, target, channel, lun,
  4053. SCB_LIST_NULL, SCB_QUEUED_FOR_DONE | SCB_QUEUE_FULL,
  4054. FALSE, NULL);
  4055. next_scbp = NULL;
  4056. active_hscb = aic_inb(p, SCBPTR);
  4057. prev_hscb = next_hscb = scb_index = SCB_LIST_NULL;
  4058. next_hscb = aic_inb(p, WAITING_SCBH);
  4059. while (next_hscb != SCB_LIST_NULL)
  4060. {
  4061. aic_outb(p, next_hscb, SCBPTR);
  4062. scb_index = aic_inb(p, SCB_TAG);
  4063. if (scb_index < p->scb_data->numscbs)
  4064. {
  4065. next_scbp = p->scb_data->scb_array[scb_index];
  4066. if (aic7xxx_match_scb(p, next_scbp, target, channel, lun,
  4067. SCB_LIST_NULL) )
  4068. {
  4069. next_scbp->flags = SCB_QUEUED_FOR_DONE | SCB_QUEUE_FULL;
  4070. next_hscb = aic_inb(p, SCB_NEXT);
  4071. aic_outb(p, 0, SCB_CONTROL);
  4072. aic_outb(p, SCB_LIST_NULL, SCB_TAG);
  4073. aic7xxx_add_curscb_to_free_list(p);
  4074. if (prev_hscb == SCB_LIST_NULL)
  4075. {
  4076. /* We were first on the list,
  4077. * so we kill the selection
  4078. * hardware. Let the sequencer
  4079. * re-init the hardware itself
  4080. */
  4081. aic_outb(p, aic_inb(p, SCSISEQ) & ~ENSELO, SCSISEQ);
  4082. aic_outb(p, CLRSELTIMEO, CLRSINT1);
  4083. aic_outb(p, next_hscb, WAITING_SCBH);
  4084. }
  4085. else
  4086. {
  4087. aic_outb(p, prev_hscb, SCBPTR);
  4088. aic_outb(p, next_hscb, SCB_NEXT);
  4089. }
  4090. }
  4091. else
  4092. {
  4093. prev_hscb = next_hscb;
  4094. next_hscb = aic_inb(p, SCB_NEXT);
  4095. }
  4096. } /* scb_index >= p->scb_data->numscbs */
  4097. }
  4098. aic_outb(p, active_hscb, SCBPTR);
  4099. aic7xxx_run_done_queue(p, FALSE);
  4100. #ifdef AIC7XXX_VERBOSE_DEBUGGING
  4101. if( (aic7xxx_verbose & VERBOSE_MINOR_ERROR) ||
  4102. (aic7xxx_verbose > 0xffff) )
  4103. {
  4104. if (queue_flag)
  4105. printk(INFO_LEAD "Queue full received; queue depth %d, "
  4106. "active %d\n", p->host_no, CTL_OF_SCB(scb),
  4107. aic_dev->max_q_depth, aic_dev->active_cmds);
  4108. else
  4109. printk(INFO_LEAD "Target busy\n", p->host_no, CTL_OF_SCB(scb));
  4110. }
  4111. #endif
  4112. if (queue_flag)
  4113. {
  4114. int diff;
  4115. result = scsi_track_queue_full(cmd->device,
  4116. aic_dev->active_cmds);
  4117. if ( result < 0 )
  4118. {
  4119. if (aic7xxx_verbose & VERBOSE_NEGOTIATION2)
  4120. printk(INFO_LEAD "Tagged Command Queueing disabled.\n",
  4121. p->host_no, CTL_OF_SCB(scb));
  4122. diff = aic_dev->max_q_depth - p->host->cmd_per_lun;
  4123. aic_dev->temp_q_depth = 1;
  4124. aic_dev->max_q_depth = 1;
  4125. }
  4126. else if ( result > 0 )
  4127. {
  4128. if (aic7xxx_verbose & VERBOSE_NEGOTIATION2)
  4129. printk(INFO_LEAD "Queue depth reduced to %d\n", p->host_no,
  4130. CTL_OF_SCB(scb), result);
  4131. diff = aic_dev->max_q_depth - result;
  4132. aic_dev->max_q_depth = result;
  4133. /* temp_q_depth could have been dropped to 1 for an untagged
  4134. * command that might be coming up */
  4135. if(aic_dev->temp_q_depth > result)
  4136. aic_dev->temp_q_depth = result;
  4137. }
  4138. /* We should free up the no unused SCB entries. But, that's
  4139. * a difficult thing to do because we use a direct indexed
  4140. * array, so we can't just take any entries and free them,
  4141. * we *have* to free the ones at the end of the array, and
  4142. * they very well could be in use right now, which means
  4143. * in order to do this right, we have to add a delayed
  4144. * freeing mechanism tied into the scb_free() code area.
  4145. * We'll add that later.
  4146. */
  4147. }
  4148. break;
  4149. }
  4150. default:
  4151. if (aic7xxx_verbose & VERBOSE_SEQINT)
  4152. printk(INFO_LEAD "Unexpected target status 0x%x.\n", p->host_no,
  4153. CTL_OF_SCB(scb), scb->hscb->target_status);
  4154. if (!aic7xxx_error(cmd))
  4155. {
  4156. aic7xxx_error(cmd) = DID_RETRY_COMMAND;
  4157. }
  4158. break;
  4159. } /* end switch */
  4160. } /* end else of */
  4161. }
  4162. break;
  4163. case AWAITING_MSG:
  4164. {
  4165. unsigned char scb_index, msg_out;
  4166. scb_index = aic_inb(p, SCB_TAG);
  4167. msg_out = aic_inb(p, MSG_OUT);
  4168. scb = p->scb_data->scb_array[scb_index];
  4169. aic_dev = AIC_DEV(scb->cmd);
  4170. p->msg_index = p->msg_len = 0;
  4171. /*
  4172. * This SCB had a MK_MESSAGE set in its control byte informing
  4173. * the sequencer that we wanted to send a special message to
  4174. * this target.
  4175. */
  4176. if ( !(scb->flags & SCB_DEVICE_RESET) &&
  4177. (msg_out == MSG_IDENTIFYFLAG) &&
  4178. (scb->hscb->control & TAG_ENB) )
  4179. {
  4180. p->msg_buf[p->msg_index++] = scb->tag_action;
  4181. p->msg_buf[p->msg_index++] = scb->hscb->tag;
  4182. p->msg_len += 2;
  4183. }
  4184. if (scb->flags & SCB_DEVICE_RESET)
  4185. {
  4186. p->msg_buf[p->msg_index++] = MSG_BUS_DEV_RESET;
  4187. p->msg_len++;
  4188. if (aic7xxx_verbose & VERBOSE_RESET_PROCESS)
  4189. printk(INFO_LEAD "Bus device reset mailed.\n",
  4190. p->host_no, CTL_OF_SCB(scb));
  4191. }
  4192. else if (scb->flags & SCB_ABORT)
  4193. {
  4194. if (scb->tag_action)
  4195. {
  4196. p->msg_buf[p->msg_index++] = MSG_ABORT_TAG;
  4197. }
  4198. else
  4199. {
  4200. p->msg_buf[p->msg_index++] = MSG_ABORT;
  4201. }
  4202. p->msg_len++;
  4203. if (aic7xxx_verbose & VERBOSE_ABORT_PROCESS)
  4204. printk(INFO_LEAD "Abort message mailed.\n", p->host_no,
  4205. CTL_OF_SCB(scb));
  4206. }
  4207. else if (scb->flags & SCB_MSGOUT_PPR)
  4208. {
  4209. if (aic7xxx_verbose & VERBOSE_NEGOTIATION2)
  4210. {
  4211. printk(INFO_LEAD "Sending PPR (%d/%d/%d/%d) message.\n",
  4212. p->host_no, CTL_OF_SCB(scb),
  4213. aic_dev->goal.period,
  4214. aic_dev->goal.offset,
  4215. aic_dev->goal.width,
  4216. aic_dev->goal.options);
  4217. }
  4218. aic7xxx_construct_ppr(p, scb);
  4219. }
  4220. else if (scb->flags & SCB_MSGOUT_WDTR)
  4221. {
  4222. if (aic7xxx_verbose & VERBOSE_NEGOTIATION2)
  4223. {
  4224. printk(INFO_LEAD "Sending WDTR message.\n", p->host_no,
  4225. CTL_OF_SCB(scb));
  4226. }
  4227. aic7xxx_construct_wdtr(p, aic_dev->goal.width);
  4228. }
  4229. else if (scb->flags & SCB_MSGOUT_SDTR)
  4230. {
  4231. unsigned int max_sync, period;
  4232. unsigned char options = 0;
  4233. /*
  4234. * Now that the device is selected, use the bits in SBLKCTL and
  4235. * SSTAT2 to determine the max sync rate for this device.
  4236. */
  4237. if (p->features & AHC_ULTRA2)
  4238. {
  4239. if ( (aic_inb(p, SBLKCTL) & ENAB40) &&
  4240. !(aic_inb(p, SSTAT2) & EXP_ACTIVE) )
  4241. {
  4242. max_sync = AHC_SYNCRATE_ULTRA2;
  4243. }
  4244. else
  4245. {
  4246. max_sync = AHC_SYNCRATE_ULTRA;
  4247. }
  4248. }
  4249. else if (p->features & AHC_ULTRA)
  4250. {
  4251. max_sync = AHC_SYNCRATE_ULTRA;
  4252. }
  4253. else
  4254. {
  4255. max_sync = AHC_SYNCRATE_FAST;
  4256. }
  4257. period = aic_dev->goal.period;
  4258. aic7xxx_find_syncrate(p, &period, max_sync, &options);
  4259. if (aic7xxx_verbose & VERBOSE_NEGOTIATION2)
  4260. {
  4261. printk(INFO_LEAD "Sending SDTR %d/%d message.\n", p->host_no,
  4262. CTL_OF_SCB(scb), period,
  4263. aic_dev->goal.offset);
  4264. }
  4265. aic7xxx_construct_sdtr(p, period, aic_dev->goal.offset);
  4266. }
  4267. else
  4268. {
  4269. panic("aic7xxx: AWAITING_MSG for an SCB that does "
  4270. "not have a waiting message.\n");
  4271. }
  4272. /*
  4273. * We've set everything up to send our message, now to actually do
  4274. * so we need to enable reqinit interrupts and let the interrupt
  4275. * handler do the rest. We don't want to unpause the sequencer yet
  4276. * though so we'll return early. We also have to make sure that
  4277. * we clear the SEQINT *BEFORE* we set the REQINIT handler active
  4278. * or else it's possible on VLB cards to lose the first REQINIT
  4279. * interrupt. Edge triggered EISA cards could also lose this
  4280. * interrupt, although PCI and level triggered cards should not
  4281. * have this problem since they continually interrupt the kernel
  4282. * until we take care of the situation.
  4283. */
  4284. scb->flags |= SCB_MSGOUT_SENT;
  4285. p->msg_index = 0;
  4286. p->msg_type = MSG_TYPE_INITIATOR_MSGOUT;
  4287. p->flags |= AHC_HANDLING_REQINITS;
  4288. aic_outb(p, aic_inb(p, SIMODE1) | ENREQINIT, SIMODE1);
  4289. return;
  4290. }
  4291. break;
  4292. case DATA_OVERRUN:
  4293. {
  4294. unsigned char scb_index = aic_inb(p, SCB_TAG);
  4295. unsigned char lastphase = aic_inb(p, LASTPHASE);
  4296. unsigned int i;
  4297. scb = (p->scb_data->scb_array[scb_index]);
  4298. /*
  4299. * XXX - What do we really want to do on an overrun? The
  4300. * mid-level SCSI code should handle this, but for now,
  4301. * we'll just indicate that the command should retried.
  4302. * If we retrieved sense info on this target, then the
  4303. * base SENSE info should have been saved prior to the
  4304. * overrun error. In that case, we return DID_OK and let
  4305. * the mid level code pick up on the sense info. Otherwise
  4306. * we return DID_ERROR so the command will get retried.
  4307. */
  4308. if ( !(scb->flags & SCB_SENSE) )
  4309. {
  4310. printk(WARN_LEAD "Data overrun detected in %s phase, tag %d;\n",
  4311. p->host_no, CTL_OF_SCB(scb),
  4312. (lastphase == P_DATAIN) ? "Data-In" : "Data-Out", scb->hscb->tag);
  4313. printk(KERN_WARNING " %s seen Data Phase. Length=%d, NumSGs=%d.\n",
  4314. (aic_inb(p, SEQ_FLAGS) & DPHASE) ? "Have" : "Haven't",
  4315. scb->sg_length, scb->sg_count);
  4316. printk(KERN_WARNING " Raw SCSI Command: 0x");
  4317. for (i = 0; i < scb->hscb->SCSI_cmd_length; i++)
  4318. {
  4319. printk("%02x ", scb->cmd->cmnd[i]);
  4320. }
  4321. printk("\n");
  4322. if(aic7xxx_verbose > 0xffff)
  4323. {
  4324. for (i = 0; i < scb->sg_count; i++)
  4325. {
  4326. printk(KERN_WARNING " sg[%d] - Addr 0x%x : Length %d\n",
  4327. i,
  4328. le32_to_cpu(scb->sg_list[i].address),
  4329. le32_to_cpu(scb->sg_list[i].length) );
  4330. }
  4331. }
  4332. aic7xxx_error(scb->cmd) = DID_ERROR;
  4333. }
  4334. else
  4335. printk(INFO_LEAD "Data Overrun during SEND_SENSE operation.\n",
  4336. p->host_no, CTL_OF_SCB(scb));
  4337. }
  4338. break;
  4339. case WIDE_RESIDUE:
  4340. {
  4341. unsigned char resid_sgcnt, index;
  4342. unsigned char scb_index = aic_inb(p, SCB_TAG);
  4343. unsigned int cur_addr, resid_dcnt;
  4344. unsigned int native_addr, native_length, sg_addr;
  4345. int i;
  4346. if(scb_index > p->scb_data->numscbs)
  4347. {
  4348. printk(WARN_LEAD "invalid scb_index during WIDE_RESIDUE.\n",
  4349. p->host_no, -1, -1, -1);
  4350. /*
  4351. * XXX: Add error handling here
  4352. */
  4353. break;
  4354. }
  4355. scb = p->scb_data->scb_array[scb_index];
  4356. if(!(scb->flags & SCB_ACTIVE) || (scb->cmd == NULL))
  4357. {
  4358. printk(WARN_LEAD "invalid scb during WIDE_RESIDUE flags:0x%x "
  4359. "scb->cmd:0x%lx\n", p->host_no, CTL_OF_SCB(scb),
  4360. scb->flags, (unsigned long)scb->cmd);
  4361. break;
  4362. }
  4363. if(aic7xxx_verbose & VERBOSE_MINOR_ERROR)
  4364. printk(INFO_LEAD "Got WIDE_RESIDUE message, patching up data "
  4365. "pointer.\n", p->host_no, CTL_OF_SCB(scb));
  4366. /*
  4367. * We have a valid scb to use on this WIDE_RESIDUE message, so
  4368. * we need to walk the sg list looking for this particular sg
  4369. * segment, then see if we happen to be at the very beginning of
  4370. * the segment. If we are, then we have to back things up to
  4371. * the previous segment. If not, then we simply need to remove
  4372. * one byte from this segments address and add one to the byte
  4373. * count.
  4374. */
  4375. cur_addr = aic_inb(p, SHADDR) | (aic_inb(p, SHADDR + 1) << 8) |
  4376. (aic_inb(p, SHADDR + 2) << 16) | (aic_inb(p, SHADDR + 3) << 24);
  4377. sg_addr = aic_inb(p, SG_COUNT + 1) | (aic_inb(p, SG_COUNT + 2) << 8) |
  4378. (aic_inb(p, SG_COUNT + 3) << 16) | (aic_inb(p, SG_COUNT + 4) << 24);
  4379. resid_sgcnt = aic_inb(p, SCB_RESID_SGCNT);
  4380. resid_dcnt = aic_inb(p, SCB_RESID_DCNT) |
  4381. (aic_inb(p, SCB_RESID_DCNT + 1) << 8) |
  4382. (aic_inb(p, SCB_RESID_DCNT + 2) << 16);
  4383. index = scb->sg_count - ((resid_sgcnt) ? resid_sgcnt : 1);
  4384. native_addr = le32_to_cpu(scb->sg_list[index].address);
  4385. native_length = le32_to_cpu(scb->sg_list[index].length);
  4386. /*
  4387. * If resid_dcnt == native_length, then we just loaded this SG
  4388. * segment and we need to back it up one...
  4389. */
  4390. if(resid_dcnt == native_length)
  4391. {
  4392. if(index == 0)
  4393. {
  4394. /*
  4395. * Oops, this isn't right, we can't back up to before the
  4396. * beginning. This must be a bogus message, ignore it.
  4397. */
  4398. break;
  4399. }
  4400. resid_dcnt = 1;
  4401. resid_sgcnt += 1;
  4402. native_addr = le32_to_cpu(scb->sg_list[index - 1].address);
  4403. native_length = le32_to_cpu(scb->sg_list[index - 1].length);
  4404. cur_addr = native_addr + (native_length - 1);
  4405. sg_addr -= sizeof(struct hw_scatterlist);
  4406. }
  4407. else
  4408. {
  4409. /*
  4410. * resid_dcnt != native_length, so we are in the middle of a SG
  4411. * element. Back it up one byte and leave the rest alone.
  4412. */
  4413. resid_dcnt += 1;
  4414. cur_addr -= 1;
  4415. }
  4416. /*
  4417. * Output the new addresses and counts to the right places on the
  4418. * card.
  4419. */
  4420. aic_outb(p, resid_sgcnt, SG_COUNT);
  4421. aic_outb(p, resid_sgcnt, SCB_RESID_SGCNT);
  4422. aic_outb(p, sg_addr & 0xff, SG_COUNT + 1);
  4423. aic_outb(p, (sg_addr >> 8) & 0xff, SG_COUNT + 2);
  4424. aic_outb(p, (sg_addr >> 16) & 0xff, SG_COUNT + 3);
  4425. aic_outb(p, (sg_addr >> 24) & 0xff, SG_COUNT + 4);
  4426. aic_outb(p, resid_dcnt & 0xff, SCB_RESID_DCNT);
  4427. aic_outb(p, (resid_dcnt >> 8) & 0xff, SCB_RESID_DCNT + 1);
  4428. aic_outb(p, (resid_dcnt >> 16) & 0xff, SCB_RESID_DCNT + 2);
  4429. /*
  4430. * The sequencer actually wants to find the new address
  4431. * in the SHADDR register set. On the Ultra2 and later controllers
  4432. * this register set is readonly. In order to get the right number
  4433. * into the register, you actually have to enter it in HADDR and then
  4434. * use the PRELOADEN bit of DFCNTRL to drop it through from the
  4435. * HADDR register to the SHADDR register. On non-Ultra2 controllers,
  4436. * we simply write it direct.
  4437. */
  4438. if(p->features & AHC_ULTRA2)
  4439. {
  4440. /*
  4441. * We might as well be accurate and drop both the resid_dcnt and
  4442. * cur_addr into HCNT and HADDR and have both of them drop
  4443. * through to the shadow layer together.
  4444. */
  4445. aic_outb(p, resid_dcnt & 0xff, HCNT);
  4446. aic_outb(p, (resid_dcnt >> 8) & 0xff, HCNT + 1);
  4447. aic_outb(p, (resid_dcnt >> 16) & 0xff, HCNT + 2);
  4448. aic_outb(p, cur_addr & 0xff, HADDR);
  4449. aic_outb(p, (cur_addr >> 8) & 0xff, HADDR + 1);
  4450. aic_outb(p, (cur_addr >> 16) & 0xff, HADDR + 2);
  4451. aic_outb(p, (cur_addr >> 24) & 0xff, HADDR + 3);
  4452. aic_outb(p, aic_inb(p, DMAPARAMS) | PRELOADEN, DFCNTRL);
  4453. udelay(1);
  4454. aic_outb(p, aic_inb(p, DMAPARAMS) & ~(SCSIEN|HDMAEN), DFCNTRL);
  4455. i=0;
  4456. while(((aic_inb(p, DFCNTRL) & (SCSIEN|HDMAEN)) != 0) && (i++ < 1000))
  4457. {
  4458. udelay(1);
  4459. }
  4460. }
  4461. else
  4462. {
  4463. aic_outb(p, cur_addr & 0xff, SHADDR);
  4464. aic_outb(p, (cur_addr >> 8) & 0xff, SHADDR + 1);
  4465. aic_outb(p, (cur_addr >> 16) & 0xff, SHADDR + 2);
  4466. aic_outb(p, (cur_addr >> 24) & 0xff, SHADDR + 3);
  4467. }
  4468. }
  4469. break;
  4470. case SEQ_SG_FIXUP:
  4471. {
  4472. unsigned char scb_index, tmp;
  4473. int sg_addr, sg_length;
  4474. scb_index = aic_inb(p, SCB_TAG);
  4475. if(scb_index > p->scb_data->numscbs)
  4476. {
  4477. printk(WARN_LEAD "invalid scb_index during SEQ_SG_FIXUP.\n",
  4478. p->host_no, -1, -1, -1);
  4479. printk(INFO_LEAD "SCSISIGI 0x%x, SEQADDR 0x%x, SSTAT0 0x%x, SSTAT1 "
  4480. "0x%x\n", p->host_no, -1, -1, -1,
  4481. aic_inb(p, SCSISIGI),
  4482. aic_inb(p, SEQADDR0) | (aic_inb(p, SEQADDR1) << 8),
  4483. aic_inb(p, SSTAT0), aic_inb(p, SSTAT1));
  4484. printk(INFO_LEAD "SG_CACHEPTR 0x%x, SSTAT2 0x%x, STCNT 0x%x\n",
  4485. p->host_no, -1, -1, -1, aic_inb(p, SG_CACHEPTR),
  4486. aic_inb(p, SSTAT2), aic_inb(p, STCNT + 2) << 16 |
  4487. aic_inb(p, STCNT + 1) << 8 | aic_inb(p, STCNT));
  4488. /*
  4489. * XXX: Add error handling here
  4490. */
  4491. break;
  4492. }
  4493. scb = p->scb_data->scb_array[scb_index];
  4494. if(!(scb->flags & SCB_ACTIVE) || (scb->cmd == NULL))
  4495. {
  4496. printk(WARN_LEAD "invalid scb during SEQ_SG_FIXUP flags:0x%x "
  4497. "scb->cmd:0x%p\n", p->host_no, CTL_OF_SCB(scb),
  4498. scb->flags, scb->cmd);
  4499. printk(INFO_LEAD "SCSISIGI 0x%x, SEQADDR 0x%x, SSTAT0 0x%x, SSTAT1 "
  4500. "0x%x\n", p->host_no, CTL_OF_SCB(scb),
  4501. aic_inb(p, SCSISIGI),
  4502. aic_inb(p, SEQADDR0) | (aic_inb(p, SEQADDR1) << 8),
  4503. aic_inb(p, SSTAT0), aic_inb(p, SSTAT1));
  4504. printk(INFO_LEAD "SG_CACHEPTR 0x%x, SSTAT2 0x%x, STCNT 0x%x\n",
  4505. p->host_no, CTL_OF_SCB(scb), aic_inb(p, SG_CACHEPTR),
  4506. aic_inb(p, SSTAT2), aic_inb(p, STCNT + 2) << 16 |
  4507. aic_inb(p, STCNT + 1) << 8 | aic_inb(p, STCNT));
  4508. break;
  4509. }
  4510. if(aic7xxx_verbose & VERBOSE_MINOR_ERROR)
  4511. printk(INFO_LEAD "Fixing up SG address for sequencer.\n", p->host_no,
  4512. CTL_OF_SCB(scb));
  4513. /*
  4514. * Advance the SG pointer to the next element in the list
  4515. */
  4516. tmp = aic_inb(p, SG_NEXT);
  4517. tmp += SG_SIZEOF;
  4518. aic_outb(p, tmp, SG_NEXT);
  4519. if( tmp < SG_SIZEOF )
  4520. aic_outb(p, aic_inb(p, SG_NEXT + 1) + 1, SG_NEXT + 1);
  4521. tmp = aic_inb(p, SG_COUNT) - 1;
  4522. aic_outb(p, tmp, SG_COUNT);
  4523. sg_addr = le32_to_cpu(scb->sg_list[scb->sg_count - tmp].address);
  4524. sg_length = le32_to_cpu(scb->sg_list[scb->sg_count - tmp].length);
  4525. /*
  4526. * Now stuff the element we just advanced past down onto the
  4527. * card so it can be stored in the residual area.
  4528. */
  4529. aic_outb(p, sg_addr & 0xff, HADDR);
  4530. aic_outb(p, (sg_addr >> 8) & 0xff, HADDR + 1);
  4531. aic_outb(p, (sg_addr >> 16) & 0xff, HADDR + 2);
  4532. aic_outb(p, (sg_addr >> 24) & 0xff, HADDR + 3);
  4533. aic_outb(p, sg_length & 0xff, HCNT);
  4534. aic_outb(p, (sg_length >> 8) & 0xff, HCNT + 1);
  4535. aic_outb(p, (sg_length >> 16) & 0xff, HCNT + 2);
  4536. aic_outb(p, (tmp << 2) | ((tmp == 1) ? LAST_SEG : 0), SG_CACHEPTR);
  4537. aic_outb(p, aic_inb(p, DMAPARAMS), DFCNTRL);
  4538. while(aic_inb(p, SSTAT0) & SDONE) udelay(1);
  4539. while(aic_inb(p, DFCNTRL) & (HDMAEN|SCSIEN)) aic_outb(p, 0, DFCNTRL);
  4540. }
  4541. break;
  4542. #ifdef AIC7XXX_NOT_YET
  4543. case TRACEPOINT2:
  4544. {
  4545. printk(INFO_LEAD "Tracepoint #2 reached.\n", p->host_no,
  4546. channel, target, lun);
  4547. }
  4548. break;
  4549. /* XXX Fill these in later */
  4550. case MSG_BUFFER_BUSY:
  4551. printk("aic7xxx: Message buffer busy.\n");
  4552. break;
  4553. case MSGIN_PHASEMIS:
  4554. printk("aic7xxx: Message-in phasemis.\n");
  4555. break;
  4556. #endif
  4557. default: /* unknown */
  4558. printk(WARN_LEAD "Unknown SEQINT, INTSTAT 0x%x, SCSISIGI 0x%x.\n",
  4559. p->host_no, channel, target, lun, intstat,
  4560. aic_inb(p, SCSISIGI));
  4561. break;
  4562. }
  4563. /*
  4564. * Clear the sequencer interrupt and unpause the sequencer.
  4565. */
  4566. unpause_sequencer(p, /* unpause always */ TRUE);
  4567. }
  4568. /*+F*************************************************************************
  4569. * Function:
  4570. * aic7xxx_parse_msg
  4571. *
  4572. * Description:
  4573. * Parses incoming messages into actions on behalf of
  4574. * aic7xxx_handle_reqinit
  4575. *_F*************************************************************************/
  4576. static int
  4577. aic7xxx_parse_msg(struct aic7xxx_host *p, struct aic7xxx_scb *scb)
  4578. {
  4579. int reject, reply, done;
  4580. unsigned char target_scsirate, tindex;
  4581. unsigned short target_mask;
  4582. unsigned char target, channel, lun;
  4583. unsigned char bus_width, new_bus_width;
  4584. unsigned char trans_options, new_trans_options;
  4585. unsigned int period, new_period, offset, new_offset, maxsync;
  4586. struct aic7xxx_syncrate *syncrate;
  4587. struct aic_dev_data *aic_dev;
  4588. target = scb->cmd->device->id;
  4589. channel = scb->cmd->device->channel;
  4590. lun = scb->cmd->device->lun;
  4591. reply = reject = done = FALSE;
  4592. tindex = TARGET_INDEX(scb->cmd);
  4593. aic_dev = AIC_DEV(scb->cmd);
  4594. target_scsirate = aic_inb(p, TARG_SCSIRATE + tindex);
  4595. target_mask = (0x01 << tindex);
  4596. /*
  4597. * Parse as much of the message as is available,
  4598. * rejecting it if we don't support it. When
  4599. * the entire message is available and has been
  4600. * handled, return TRUE indicating that we have
  4601. * parsed an entire message.
  4602. */
  4603. if (p->msg_buf[0] != MSG_EXTENDED)
  4604. {
  4605. reject = TRUE;
  4606. }
  4607. /*
  4608. * Even if we are an Ultra3 card, don't allow Ultra3 sync rates when
  4609. * using the SDTR messages. We need the PPR messages to enable the
  4610. * higher speeds that include things like Dual Edge clocking.
  4611. */
  4612. if (p->features & AHC_ULTRA2)
  4613. {
  4614. if ( (aic_inb(p, SBLKCTL) & ENAB40) &&
  4615. !(aic_inb(p, SSTAT2) & EXP_ACTIVE) )
  4616. {
  4617. if (p->features & AHC_ULTRA3)
  4618. maxsync = AHC_SYNCRATE_ULTRA3;
  4619. else
  4620. maxsync = AHC_SYNCRATE_ULTRA2;
  4621. }
  4622. else
  4623. {
  4624. maxsync = AHC_SYNCRATE_ULTRA;
  4625. }
  4626. }
  4627. else if (p->features & AHC_ULTRA)
  4628. {
  4629. maxsync = AHC_SYNCRATE_ULTRA;
  4630. }
  4631. else
  4632. {
  4633. maxsync = AHC_SYNCRATE_FAST;
  4634. }
  4635. /*
  4636. * Just accept the length byte outright and perform
  4637. * more checking once we know the message type.
  4638. */
  4639. if ( !reject && (p->msg_len > 2) )
  4640. {
  4641. switch(p->msg_buf[2])
  4642. {
  4643. case MSG_EXT_SDTR:
  4644. {
  4645. if (p->msg_buf[1] != MSG_EXT_SDTR_LEN)
  4646. {
  4647. reject = TRUE;
  4648. break;
  4649. }
  4650. if (p->msg_len < (MSG_EXT_SDTR_LEN + 2))
  4651. {
  4652. break;
  4653. }
  4654. period = new_period = p->msg_buf[3];
  4655. offset = new_offset = p->msg_buf[4];
  4656. trans_options = new_trans_options = 0;
  4657. bus_width = new_bus_width = target_scsirate & WIDEXFER;
  4658. /*
  4659. * If our current max syncrate is in the Ultra3 range, bump it back
  4660. * down to Ultra2 since we can't negotiate DT transfers using SDTR
  4661. */
  4662. if(maxsync == AHC_SYNCRATE_ULTRA3)
  4663. maxsync = AHC_SYNCRATE_ULTRA2;
  4664. /*
  4665. * We might have a device that is starting negotiation with us
  4666. * before we can start up negotiation with it....be prepared to
  4667. * have a device ask for a higher speed then we want to give it
  4668. * in that case
  4669. */
  4670. if ( (scb->flags & (SCB_MSGOUT_SENT|SCB_MSGOUT_SDTR)) !=
  4671. (SCB_MSGOUT_SENT|SCB_MSGOUT_SDTR) )
  4672. {
  4673. if (!(aic_dev->flags & DEVICE_DTR_SCANNED))
  4674. {
  4675. /*
  4676. * We shouldn't get here unless this is a narrow drive, wide
  4677. * devices should trigger this same section of code in the WDTR
  4678. * handler first instead.
  4679. */
  4680. aic_dev->goal.width = MSG_EXT_WDTR_BUS_8_BIT;
  4681. aic_dev->goal.options = 0;
  4682. if(p->user[tindex].offset)
  4683. {
  4684. aic_dev->needsdtr_copy = 1;
  4685. aic_dev->goal.period = max_t(unsigned char, 10,p->user[tindex].period);
  4686. if(p->features & AHC_ULTRA2)
  4687. {
  4688. aic_dev->goal.offset = MAX_OFFSET_ULTRA2;
  4689. }
  4690. else
  4691. {
  4692. aic_dev->goal.offset = MAX_OFFSET_8BIT;
  4693. }
  4694. }
  4695. else
  4696. {
  4697. aic_dev->needsdtr_copy = 0;
  4698. aic_dev->goal.period = 255;
  4699. aic_dev->goal.offset = 0;
  4700. }
  4701. aic_dev->flags |= DEVICE_DTR_SCANNED | DEVICE_PRINT_DTR;
  4702. }
  4703. else if (aic_dev->needsdtr_copy == 0)
  4704. {
  4705. /*
  4706. * This is a preemptive message from the target, we've already
  4707. * scanned this target and set our options for it, and we
  4708. * don't need a SDTR with this target (for whatever reason),
  4709. * so reject this incoming SDTR
  4710. */
  4711. reject = TRUE;
  4712. break;
  4713. }
  4714. /* The device is sending this message first and we have to reply */
  4715. reply = TRUE;
  4716. if (aic7xxx_verbose & VERBOSE_NEGOTIATION2)
  4717. {
  4718. printk(INFO_LEAD "Received pre-emptive SDTR message from "
  4719. "target.\n", p->host_no, CTL_OF_SCB(scb));
  4720. }
  4721. /*
  4722. * Validate the values the device passed to us against our SEEPROM
  4723. * settings. We don't have to do this if we aren't replying since
  4724. * the device isn't allowed to send values greater than the ones
  4725. * we first sent to it.
  4726. */
  4727. new_period = max_t(unsigned int, period, aic_dev->goal.period);
  4728. new_offset = min_t(unsigned int, offset, aic_dev->goal.offset);
  4729. }
  4730. /*
  4731. * Use our new_period, new_offset, bus_width, and card options
  4732. * to determine the actual syncrate settings
  4733. */
  4734. syncrate = aic7xxx_find_syncrate(p, &new_period, maxsync,
  4735. &trans_options);
  4736. aic7xxx_validate_offset(p, syncrate, &new_offset, bus_width);
  4737. /*
  4738. * Did we drop to async? If so, send a reply regardless of whether
  4739. * or not we initiated this negotiation.
  4740. */
  4741. if ((new_offset == 0) && (new_offset != offset))
  4742. {
  4743. aic_dev->needsdtr_copy = 0;
  4744. reply = TRUE;
  4745. }
  4746. /*
  4747. * Did we start this, if not, or if we went too low and had to
  4748. * go async, then send an SDTR back to the target
  4749. */
  4750. if(reply)
  4751. {
  4752. /* when sending a reply, make sure that the goal settings are
  4753. * updated along with current and active since the code that
  4754. * will actually build the message for the sequencer uses the
  4755. * goal settings as its guidelines.
  4756. */
  4757. aic7xxx_set_syncrate(p, syncrate, target, channel, new_period,
  4758. new_offset, trans_options,
  4759. AHC_TRANS_GOAL|AHC_TRANS_ACTIVE|AHC_TRANS_CUR,
  4760. aic_dev);
  4761. scb->flags &= ~SCB_MSGOUT_BITS;
  4762. scb->flags |= SCB_MSGOUT_SDTR;
  4763. aic_outb(p, HOST_MSG, MSG_OUT);
  4764. aic_outb(p, aic_inb(p, SCSISIGO) | ATNO, SCSISIGO);
  4765. }
  4766. else
  4767. {
  4768. aic7xxx_set_syncrate(p, syncrate, target, channel, new_period,
  4769. new_offset, trans_options,
  4770. AHC_TRANS_ACTIVE|AHC_TRANS_CUR, aic_dev);
  4771. aic_dev->needsdtr = 0;
  4772. }
  4773. done = TRUE;
  4774. break;
  4775. }
  4776. case MSG_EXT_WDTR:
  4777. {
  4778. if (p->msg_buf[1] != MSG_EXT_WDTR_LEN)
  4779. {
  4780. reject = TRUE;
  4781. break;
  4782. }
  4783. if (p->msg_len < (MSG_EXT_WDTR_LEN + 2))
  4784. {
  4785. break;
  4786. }
  4787. bus_width = new_bus_width = p->msg_buf[3];
  4788. if ( (scb->flags & (SCB_MSGOUT_SENT|SCB_MSGOUT_WDTR)) ==
  4789. (SCB_MSGOUT_SENT|SCB_MSGOUT_WDTR) )
  4790. {
  4791. switch(bus_width)
  4792. {
  4793. default:
  4794. {
  4795. reject = TRUE;
  4796. if ( (aic7xxx_verbose & VERBOSE_NEGOTIATION2) &&
  4797. ((aic_dev->flags & DEVICE_PRINT_DTR) ||
  4798. (aic7xxx_verbose > 0xffff)) )
  4799. {
  4800. printk(INFO_LEAD "Requesting %d bit transfers, rejecting.\n",
  4801. p->host_no, CTL_OF_SCB(scb), 8 * (0x01 << bus_width));
  4802. }
  4803. } /* We fall through on purpose */
  4804. case MSG_EXT_WDTR_BUS_8_BIT:
  4805. {
  4806. aic_dev->goal.width = MSG_EXT_WDTR_BUS_8_BIT;
  4807. aic_dev->needwdtr_copy &= ~target_mask;
  4808. break;
  4809. }
  4810. case MSG_EXT_WDTR_BUS_16_BIT:
  4811. {
  4812. break;
  4813. }
  4814. }
  4815. aic_dev->needwdtr = 0;
  4816. aic7xxx_set_width(p, target, channel, lun, new_bus_width,
  4817. AHC_TRANS_ACTIVE|AHC_TRANS_CUR, aic_dev);
  4818. }
  4819. else
  4820. {
  4821. if ( !(aic_dev->flags & DEVICE_DTR_SCANNED) )
  4822. {
  4823. /*
  4824. * Well, we now know the WDTR and SYNC caps of this device since
  4825. * it contacted us first, mark it as such and copy the user stuff
  4826. * over to the goal stuff.
  4827. */
  4828. if( (p->features & AHC_WIDE) && p->user[tindex].width )
  4829. {
  4830. aic_dev->goal.width = MSG_EXT_WDTR_BUS_16_BIT;
  4831. aic_dev->needwdtr_copy = 1;
  4832. }
  4833. /*
  4834. * Devices that support DT transfers don't start WDTR requests
  4835. */
  4836. aic_dev->goal.options = 0;
  4837. if(p->user[tindex].offset)
  4838. {
  4839. aic_dev->needsdtr_copy = 1;
  4840. aic_dev->goal.period = max_t(unsigned char, 10, p->user[tindex].period);
  4841. if(p->features & AHC_ULTRA2)
  4842. {
  4843. aic_dev->goal.offset = MAX_OFFSET_ULTRA2;
  4844. }
  4845. else if( aic_dev->goal.width )
  4846. {
  4847. aic_dev->goal.offset = MAX_OFFSET_16BIT;
  4848. }
  4849. else
  4850. {
  4851. aic_dev->goal.offset = MAX_OFFSET_8BIT;
  4852. }
  4853. } else {
  4854. aic_dev->needsdtr_copy = 0;
  4855. aic_dev->goal.period = 255;
  4856. aic_dev->goal.offset = 0;
  4857. }
  4858. aic_dev->flags |= DEVICE_DTR_SCANNED | DEVICE_PRINT_DTR;
  4859. }
  4860. else if (aic_dev->needwdtr_copy == 0)
  4861. {
  4862. /*
  4863. * This is a preemptive message from the target, we've already
  4864. * scanned this target and set our options for it, and we
  4865. * don't need a WDTR with this target (for whatever reason),
  4866. * so reject this incoming WDTR
  4867. */
  4868. reject = TRUE;
  4869. break;
  4870. }
  4871. /* The device is sending this message first and we have to reply */
  4872. reply = TRUE;
  4873. if (aic7xxx_verbose & VERBOSE_NEGOTIATION2)
  4874. {
  4875. printk(INFO_LEAD "Received pre-emptive WDTR message from "
  4876. "target.\n", p->host_no, CTL_OF_SCB(scb));
  4877. }
  4878. switch(bus_width)
  4879. {
  4880. case MSG_EXT_WDTR_BUS_16_BIT:
  4881. {
  4882. if ( (p->features & AHC_WIDE) &&
  4883. (aic_dev->goal.width == MSG_EXT_WDTR_BUS_16_BIT) )
  4884. {
  4885. new_bus_width = MSG_EXT_WDTR_BUS_16_BIT;
  4886. break;
  4887. }
  4888. } /* Fall through if we aren't a wide card */
  4889. default:
  4890. case MSG_EXT_WDTR_BUS_8_BIT:
  4891. {
  4892. aic_dev->needwdtr_copy = 0;
  4893. new_bus_width = MSG_EXT_WDTR_BUS_8_BIT;
  4894. break;
  4895. }
  4896. }
  4897. scb->flags &= ~SCB_MSGOUT_BITS;
  4898. scb->flags |= SCB_MSGOUT_WDTR;
  4899. aic_dev->needwdtr = 0;
  4900. if(aic_dev->dtr_pending == 0)
  4901. {
  4902. /* there is no other command with SCB_DTR_SCB already set that will
  4903. * trigger the release of the dtr_pending bit. Both set the bit
  4904. * and set scb->flags |= SCB_DTR_SCB
  4905. */
  4906. aic_dev->dtr_pending = 1;
  4907. scb->flags |= SCB_DTR_SCB;
  4908. }
  4909. aic_outb(p, HOST_MSG, MSG_OUT);
  4910. aic_outb(p, aic_inb(p, SCSISIGO) | ATNO, SCSISIGO);
  4911. /* when sending a reply, make sure that the goal settings are
  4912. * updated along with current and active since the code that
  4913. * will actually build the message for the sequencer uses the
  4914. * goal settings as its guidelines.
  4915. */
  4916. aic7xxx_set_width(p, target, channel, lun, new_bus_width,
  4917. AHC_TRANS_GOAL|AHC_TRANS_ACTIVE|AHC_TRANS_CUR,
  4918. aic_dev);
  4919. }
  4920. /*
  4921. * By virtue of the SCSI spec, a WDTR message negates any existing
  4922. * SDTR negotiations. So, even if needsdtr isn't marked for this
  4923. * device, we still have to do a new SDTR message if the device
  4924. * supports SDTR at all. Therefore, we check needsdtr_copy instead
  4925. * of needstr.
  4926. */
  4927. aic7xxx_set_syncrate(p, NULL, target, channel, 0, 0, 0,
  4928. AHC_TRANS_ACTIVE|AHC_TRANS_CUR|AHC_TRANS_QUITE,
  4929. aic_dev);
  4930. aic_dev->needsdtr = aic_dev->needsdtr_copy;
  4931. done = TRUE;
  4932. break;
  4933. }
  4934. case MSG_EXT_PPR:
  4935. {
  4936. if (p->msg_buf[1] != MSG_EXT_PPR_LEN)
  4937. {
  4938. reject = TRUE;
  4939. break;
  4940. }
  4941. if (p->msg_len < (MSG_EXT_PPR_LEN + 2))
  4942. {
  4943. break;
  4944. }
  4945. period = new_period = p->msg_buf[3];
  4946. offset = new_offset = p->msg_buf[5];
  4947. bus_width = new_bus_width = p->msg_buf[6];
  4948. trans_options = new_trans_options = p->msg_buf[7] & 0xf;
  4949. if(aic7xxx_verbose & VERBOSE_NEGOTIATION2)
  4950. {
  4951. printk(INFO_LEAD "Parsing PPR message (%d/%d/%d/%d)\n",
  4952. p->host_no, CTL_OF_SCB(scb), period, offset, bus_width,
  4953. trans_options);
  4954. }
  4955. /*
  4956. * We might have a device that is starting negotiation with us
  4957. * before we can start up negotiation with it....be prepared to
  4958. * have a device ask for a higher speed then we want to give it
  4959. * in that case
  4960. */
  4961. if ( (scb->flags & (SCB_MSGOUT_SENT|SCB_MSGOUT_PPR)) !=
  4962. (SCB_MSGOUT_SENT|SCB_MSGOUT_PPR) )
  4963. {
  4964. /* Have we scanned the device yet? */
  4965. if (!(aic_dev->flags & DEVICE_DTR_SCANNED))
  4966. {
  4967. /* The device is electing to use PPR messages, so we will too until
  4968. * we know better */
  4969. aic_dev->needppr = aic_dev->needppr_copy = 1;
  4970. aic_dev->needsdtr = aic_dev->needsdtr_copy = 0;
  4971. aic_dev->needwdtr = aic_dev->needwdtr_copy = 0;
  4972. /* We know the device is SCSI-3 compliant due to PPR */
  4973. aic_dev->flags |= DEVICE_SCSI_3;
  4974. /*
  4975. * Not only is the device starting this up, but it also hasn't
  4976. * been scanned yet, so this would likely be our TUR or our
  4977. * INQUIRY command at scan time, so we need to use the
  4978. * settings from the SEEPROM if they existed. Of course, even
  4979. * if we didn't find a SEEPROM, we stuffed default values into
  4980. * the user settings anyway, so use those in all cases.
  4981. */
  4982. aic_dev->goal.width = p->user[tindex].width;
  4983. if(p->user[tindex].offset)
  4984. {
  4985. aic_dev->goal.period = p->user[tindex].period;
  4986. aic_dev->goal.options = p->user[tindex].options;
  4987. if(p->features & AHC_ULTRA2)
  4988. {
  4989. aic_dev->goal.offset = MAX_OFFSET_ULTRA2;
  4990. }
  4991. else if( aic_dev->goal.width &&
  4992. (bus_width == MSG_EXT_WDTR_BUS_16_BIT) &&
  4993. p->features & AHC_WIDE )
  4994. {
  4995. aic_dev->goal.offset = MAX_OFFSET_16BIT;
  4996. }
  4997. else
  4998. {
  4999. aic_dev->goal.offset = MAX_OFFSET_8BIT;
  5000. }
  5001. }
  5002. else
  5003. {
  5004. aic_dev->goal.period = 255;
  5005. aic_dev->goal.offset = 0;
  5006. aic_dev->goal.options = 0;
  5007. }
  5008. aic_dev->flags |= DEVICE_DTR_SCANNED | DEVICE_PRINT_DTR;
  5009. }
  5010. else if (aic_dev->needppr_copy == 0)
  5011. {
  5012. /*
  5013. * This is a preemptive message from the target, we've already
  5014. * scanned this target and set our options for it, and we
  5015. * don't need a PPR with this target (for whatever reason),
  5016. * so reject this incoming PPR
  5017. */
  5018. reject = TRUE;
  5019. break;
  5020. }
  5021. /* The device is sending this message first and we have to reply */
  5022. reply = TRUE;
  5023. if (aic7xxx_verbose & VERBOSE_NEGOTIATION2)
  5024. {
  5025. printk(INFO_LEAD "Received pre-emptive PPR message from "
  5026. "target.\n", p->host_no, CTL_OF_SCB(scb));
  5027. }
  5028. }
  5029. switch(bus_width)
  5030. {
  5031. case MSG_EXT_WDTR_BUS_16_BIT:
  5032. {
  5033. if ( (aic_dev->goal.width == MSG_EXT_WDTR_BUS_16_BIT) &&
  5034. p->features & AHC_WIDE)
  5035. {
  5036. break;
  5037. }
  5038. }
  5039. default:
  5040. {
  5041. if ( (aic7xxx_verbose & VERBOSE_NEGOTIATION2) &&
  5042. ((aic_dev->flags & DEVICE_PRINT_DTR) ||
  5043. (aic7xxx_verbose > 0xffff)) )
  5044. {
  5045. reply = TRUE;
  5046. printk(INFO_LEAD "Requesting %d bit transfers, rejecting.\n",
  5047. p->host_no, CTL_OF_SCB(scb), 8 * (0x01 << bus_width));
  5048. }
  5049. } /* We fall through on purpose */
  5050. case MSG_EXT_WDTR_BUS_8_BIT:
  5051. {
  5052. /*
  5053. * According to the spec, if we aren't wide, we also can't be
  5054. * Dual Edge so clear the options byte
  5055. */
  5056. new_trans_options = 0;
  5057. new_bus_width = MSG_EXT_WDTR_BUS_8_BIT;
  5058. break;
  5059. }
  5060. }
  5061. if(reply)
  5062. {
  5063. /* when sending a reply, make sure that the goal settings are
  5064. * updated along with current and active since the code that
  5065. * will actually build the message for the sequencer uses the
  5066. * goal settings as its guidelines.
  5067. */
  5068. aic7xxx_set_width(p, target, channel, lun, new_bus_width,
  5069. AHC_TRANS_GOAL|AHC_TRANS_ACTIVE|AHC_TRANS_CUR,
  5070. aic_dev);
  5071. syncrate = aic7xxx_find_syncrate(p, &new_period, maxsync,
  5072. &new_trans_options);
  5073. aic7xxx_validate_offset(p, syncrate, &new_offset, new_bus_width);
  5074. aic7xxx_set_syncrate(p, syncrate, target, channel, new_period,
  5075. new_offset, new_trans_options,
  5076. AHC_TRANS_GOAL|AHC_TRANS_ACTIVE|AHC_TRANS_CUR,
  5077. aic_dev);
  5078. }
  5079. else
  5080. {
  5081. aic7xxx_set_width(p, target, channel, lun, new_bus_width,
  5082. AHC_TRANS_ACTIVE|AHC_TRANS_CUR, aic_dev);
  5083. syncrate = aic7xxx_find_syncrate(p, &new_period, maxsync,
  5084. &new_trans_options);
  5085. aic7xxx_validate_offset(p, syncrate, &new_offset, new_bus_width);
  5086. aic7xxx_set_syncrate(p, syncrate, target, channel, new_period,
  5087. new_offset, new_trans_options,
  5088. AHC_TRANS_ACTIVE|AHC_TRANS_CUR, aic_dev);
  5089. }
  5090. /*
  5091. * As it turns out, if we don't *have* to have PPR messages, then
  5092. * configure ourselves not to use them since that makes some
  5093. * external drive chassis work (those chassis can't parse PPR
  5094. * messages and they mangle the SCSI bus until you send a WDTR
  5095. * and SDTR that they can understand).
  5096. */
  5097. if(new_trans_options == 0)
  5098. {
  5099. aic_dev->needppr = aic_dev->needppr_copy = 0;
  5100. if(new_offset)
  5101. {
  5102. aic_dev->needsdtr = aic_dev->needsdtr_copy = 1;
  5103. }
  5104. if (new_bus_width)
  5105. {
  5106. aic_dev->needwdtr = aic_dev->needwdtr_copy = 1;
  5107. }
  5108. }
  5109. if((new_offset == 0) && (offset != 0))
  5110. {
  5111. /*
  5112. * Oops, the syncrate went to low for this card and we fell off
  5113. * to async (should never happen with a device that uses PPR
  5114. * messages, but have to be complete)
  5115. */
  5116. reply = TRUE;
  5117. }
  5118. if(reply)
  5119. {
  5120. scb->flags &= ~SCB_MSGOUT_BITS;
  5121. scb->flags |= SCB_MSGOUT_PPR;
  5122. aic_outb(p, HOST_MSG, MSG_OUT);
  5123. aic_outb(p, aic_inb(p, SCSISIGO) | ATNO, SCSISIGO);
  5124. }
  5125. else
  5126. {
  5127. aic_dev->needppr = 0;
  5128. }
  5129. done = TRUE;
  5130. break;
  5131. }
  5132. default:
  5133. {
  5134. reject = TRUE;
  5135. break;
  5136. }
  5137. } /* end of switch(p->msg_type) */
  5138. } /* end of if (!reject && (p->msg_len > 2)) */
  5139. if (!reply && reject)
  5140. {
  5141. aic_outb(p, MSG_MESSAGE_REJECT, MSG_OUT);
  5142. aic_outb(p, aic_inb(p, SCSISIGO) | ATNO, SCSISIGO);
  5143. done = TRUE;
  5144. }
  5145. return(done);
  5146. }
  5147. /*+F*************************************************************************
  5148. * Function:
  5149. * aic7xxx_handle_reqinit
  5150. *
  5151. * Description:
  5152. * Interrupt handler for REQINIT interrupts (used to transfer messages to
  5153. * and from devices).
  5154. *_F*************************************************************************/
  5155. static void
  5156. aic7xxx_handle_reqinit(struct aic7xxx_host *p, struct aic7xxx_scb *scb)
  5157. {
  5158. unsigned char lastbyte;
  5159. unsigned char phasemis;
  5160. int done = FALSE;
  5161. switch(p->msg_type)
  5162. {
  5163. case MSG_TYPE_INITIATOR_MSGOUT:
  5164. {
  5165. if (p->msg_len == 0)
  5166. panic("aic7xxx: REQINIT with no active message!\n");
  5167. lastbyte = (p->msg_index == (p->msg_len - 1));
  5168. phasemis = ( aic_inb(p, SCSISIGI) & PHASE_MASK) != P_MESGOUT;
  5169. if (lastbyte || phasemis)
  5170. {
  5171. /* Time to end the message */
  5172. p->msg_len = 0;
  5173. p->msg_type = MSG_TYPE_NONE;
  5174. /*
  5175. * NOTE-TO-MYSELF: If you clear the REQINIT after you
  5176. * disable REQINITs, then cases of REJECT_MSG stop working
  5177. * and hang the bus
  5178. */
  5179. aic_outb(p, aic_inb(p, SIMODE1) & ~ENREQINIT, SIMODE1);
  5180. aic_outb(p, CLRSCSIINT, CLRINT);
  5181. p->flags &= ~AHC_HANDLING_REQINITS;
  5182. if (phasemis == 0)
  5183. {
  5184. aic_outb(p, p->msg_buf[p->msg_index], SINDEX);
  5185. aic_outb(p, 0, RETURN_1);
  5186. #ifdef AIC7XXX_VERBOSE_DEBUGGING
  5187. if (aic7xxx_verbose > 0xffff)
  5188. printk(INFO_LEAD "Completed sending of REQINIT message.\n",
  5189. p->host_no, CTL_OF_SCB(scb));
  5190. #endif
  5191. }
  5192. else
  5193. {
  5194. aic_outb(p, MSGOUT_PHASEMIS, RETURN_1);
  5195. #ifdef AIC7XXX_VERBOSE_DEBUGGING
  5196. if (aic7xxx_verbose > 0xffff)
  5197. printk(INFO_LEAD "PHASEMIS while sending REQINIT message.\n",
  5198. p->host_no, CTL_OF_SCB(scb));
  5199. #endif
  5200. }
  5201. unpause_sequencer(p, TRUE);
  5202. }
  5203. else
  5204. {
  5205. /*
  5206. * Present the byte on the bus (clearing REQINIT) but don't
  5207. * unpause the sequencer.
  5208. */
  5209. aic_outb(p, CLRREQINIT, CLRSINT1);
  5210. aic_outb(p, CLRSCSIINT, CLRINT);
  5211. aic_outb(p, p->msg_buf[p->msg_index++], SCSIDATL);
  5212. }
  5213. break;
  5214. }
  5215. case MSG_TYPE_INITIATOR_MSGIN:
  5216. {
  5217. phasemis = ( aic_inb(p, SCSISIGI) & PHASE_MASK ) != P_MESGIN;
  5218. if (phasemis == 0)
  5219. {
  5220. p->msg_len++;
  5221. /* Pull the byte in without acking it */
  5222. p->msg_buf[p->msg_index] = aic_inb(p, SCSIBUSL);
  5223. done = aic7xxx_parse_msg(p, scb);
  5224. /* Ack the byte */
  5225. aic_outb(p, CLRREQINIT, CLRSINT1);
  5226. aic_outb(p, CLRSCSIINT, CLRINT);
  5227. aic_inb(p, SCSIDATL);
  5228. p->msg_index++;
  5229. }
  5230. if (phasemis || done)
  5231. {
  5232. #ifdef AIC7XXX_VERBOSE_DEBUGGING
  5233. if (aic7xxx_verbose > 0xffff)
  5234. {
  5235. if (phasemis)
  5236. printk(INFO_LEAD "PHASEMIS while receiving REQINIT message.\n",
  5237. p->host_no, CTL_OF_SCB(scb));
  5238. else
  5239. printk(INFO_LEAD "Completed receipt of REQINIT message.\n",
  5240. p->host_no, CTL_OF_SCB(scb));
  5241. }
  5242. #endif
  5243. /* Time to end our message session */
  5244. p->msg_len = 0;
  5245. p->msg_type = MSG_TYPE_NONE;
  5246. aic_outb(p, aic_inb(p, SIMODE1) & ~ENREQINIT, SIMODE1);
  5247. aic_outb(p, CLRSCSIINT, CLRINT);
  5248. p->flags &= ~AHC_HANDLING_REQINITS;
  5249. unpause_sequencer(p, TRUE);
  5250. }
  5251. break;
  5252. }
  5253. default:
  5254. {
  5255. panic("aic7xxx: Unknown REQINIT message type.\n");
  5256. break;
  5257. }
  5258. } /* End of switch(p->msg_type) */
  5259. }
  5260. /*+F*************************************************************************
  5261. * Function:
  5262. * aic7xxx_handle_scsiint
  5263. *
  5264. * Description:
  5265. * Interrupt handler for SCSI interrupts (SCSIINT).
  5266. *-F*************************************************************************/
  5267. static void
  5268. aic7xxx_handle_scsiint(struct aic7xxx_host *p, unsigned char intstat)
  5269. {
  5270. unsigned char scb_index;
  5271. unsigned char status;
  5272. struct aic7xxx_scb *scb;
  5273. struct aic_dev_data *aic_dev;
  5274. scb_index = aic_inb(p, SCB_TAG);
  5275. status = aic_inb(p, SSTAT1);
  5276. if (scb_index < p->scb_data->numscbs)
  5277. {
  5278. scb = p->scb_data->scb_array[scb_index];
  5279. if ((scb->flags & SCB_ACTIVE) == 0)
  5280. {
  5281. scb = NULL;
  5282. }
  5283. }
  5284. else
  5285. {
  5286. scb = NULL;
  5287. }
  5288. if ((status & SCSIRSTI) != 0)
  5289. {
  5290. int channel;
  5291. if ( (p->chip & AHC_CHIPID_MASK) == AHC_AIC7770 )
  5292. channel = (aic_inb(p, SBLKCTL) & SELBUSB) >> 3;
  5293. else
  5294. channel = 0;
  5295. if (aic7xxx_verbose & VERBOSE_RESET)
  5296. printk(WARN_LEAD "Someone else reset the channel!!\n",
  5297. p->host_no, channel, -1, -1);
  5298. if (aic7xxx_panic_on_abort)
  5299. aic7xxx_panic_abort(p, NULL);
  5300. /*
  5301. * Go through and abort all commands for the channel, but do not
  5302. * reset the channel again.
  5303. */
  5304. aic7xxx_reset_channel(p, channel, /* Initiate Reset */ FALSE);
  5305. aic7xxx_run_done_queue(p, TRUE);
  5306. scb = NULL;
  5307. }
  5308. else if ( ((status & BUSFREE) != 0) && ((status & SELTO) == 0) )
  5309. {
  5310. /*
  5311. * First look at what phase we were last in. If it's message-out,
  5312. * chances are pretty good that the bus free was in response to
  5313. * one of our abort requests.
  5314. */
  5315. unsigned char lastphase = aic_inb(p, LASTPHASE);
  5316. unsigned char saved_tcl = aic_inb(p, SAVED_TCL);
  5317. unsigned char target = (saved_tcl >> 4) & 0x0F;
  5318. int channel;
  5319. int printerror = TRUE;
  5320. if ( (p->chip & AHC_CHIPID_MASK) == AHC_AIC7770 )
  5321. channel = (aic_inb(p, SBLKCTL) & SELBUSB) >> 3;
  5322. else
  5323. channel = 0;
  5324. aic_outb(p, aic_inb(p, SCSISEQ) & (ENSELI|ENRSELI|ENAUTOATNP),
  5325. SCSISEQ);
  5326. if (lastphase == P_MESGOUT)
  5327. {
  5328. unsigned char message;
  5329. message = aic_inb(p, SINDEX);
  5330. if ((message == MSG_ABORT) || (message == MSG_ABORT_TAG))
  5331. {
  5332. if (aic7xxx_verbose & VERBOSE_ABORT_PROCESS)
  5333. printk(INFO_LEAD "SCB %d abort delivered.\n", p->host_no,
  5334. CTL_OF_SCB(scb), scb->hscb->tag);
  5335. aic7xxx_reset_device(p, target, channel, ALL_LUNS,
  5336. (message == MSG_ABORT) ? SCB_LIST_NULL : scb->hscb->tag );
  5337. aic7xxx_run_done_queue(p, TRUE);
  5338. scb = NULL;
  5339. printerror = 0;
  5340. }
  5341. else if (message == MSG_BUS_DEV_RESET)
  5342. {
  5343. aic7xxx_handle_device_reset(p, target, channel);
  5344. scb = NULL;
  5345. printerror = 0;
  5346. }
  5347. }
  5348. if ( (scb != NULL) && (scb->flags & SCB_DTR_SCB) )
  5349. {
  5350. /*
  5351. * Hmmm...error during a negotiation command. Either we have a
  5352. * borken bus, or the device doesn't like our negotiation message.
  5353. * Since we check the INQUIRY data of a device before sending it
  5354. * negotiation messages, assume the bus is borken for whatever
  5355. * reason. Complete the command.
  5356. */
  5357. printerror = 0;
  5358. aic7xxx_reset_device(p, target, channel, ALL_LUNS, scb->hscb->tag);
  5359. aic7xxx_run_done_queue(p, TRUE);
  5360. scb = NULL;
  5361. }
  5362. if (printerror != 0)
  5363. {
  5364. if (scb != NULL)
  5365. {
  5366. unsigned char tag;
  5367. if ((scb->hscb->control & TAG_ENB) != 0)
  5368. {
  5369. tag = scb->hscb->tag;
  5370. }
  5371. else
  5372. {
  5373. tag = SCB_LIST_NULL;
  5374. }
  5375. aic7xxx_reset_device(p, target, channel, ALL_LUNS, tag);
  5376. aic7xxx_run_done_queue(p, TRUE);
  5377. }
  5378. else
  5379. {
  5380. aic7xxx_reset_device(p, target, channel, ALL_LUNS, SCB_LIST_NULL);
  5381. aic7xxx_run_done_queue(p, TRUE);
  5382. }
  5383. printk(INFO_LEAD "Unexpected busfree, LASTPHASE = 0x%x, "
  5384. "SEQADDR = 0x%x\n", p->host_no, channel, target, -1, lastphase,
  5385. (aic_inb(p, SEQADDR1) << 8) | aic_inb(p, SEQADDR0));
  5386. scb = NULL;
  5387. }
  5388. aic_outb(p, MSG_NOOP, MSG_OUT);
  5389. aic_outb(p, aic_inb(p, SIMODE1) & ~(ENBUSFREE|ENREQINIT),
  5390. SIMODE1);
  5391. p->flags &= ~AHC_HANDLING_REQINITS;
  5392. aic_outb(p, CLRBUSFREE, CLRSINT1);
  5393. aic_outb(p, CLRSCSIINT, CLRINT);
  5394. restart_sequencer(p);
  5395. unpause_sequencer(p, TRUE);
  5396. }
  5397. else if ((status & SELTO) != 0)
  5398. {
  5399. unsigned char scbptr;
  5400. unsigned char nextscb;
  5401. struct scsi_cmnd *cmd;
  5402. scbptr = aic_inb(p, WAITING_SCBH);
  5403. if (scbptr > p->scb_data->maxhscbs)
  5404. {
  5405. /*
  5406. * I'm still trying to track down exactly how this happens, but until
  5407. * I find it, this code will make sure we aren't passing bogus values
  5408. * into the SCBPTR register, even if that register will just wrap
  5409. * things around, we still don't like having out of range variables.
  5410. *
  5411. * NOTE: Don't check the aic7xxx_verbose variable, I want this message
  5412. * to always be displayed.
  5413. */
  5414. printk(INFO_LEAD "Invalid WAITING_SCBH value %d, improvising.\n",
  5415. p->host_no, -1, -1, -1, scbptr);
  5416. if (p->scb_data->maxhscbs > 4)
  5417. scbptr &= (p->scb_data->maxhscbs - 1);
  5418. else
  5419. scbptr &= 0x03;
  5420. }
  5421. aic_outb(p, scbptr, SCBPTR);
  5422. scb_index = aic_inb(p, SCB_TAG);
  5423. scb = NULL;
  5424. if (scb_index < p->scb_data->numscbs)
  5425. {
  5426. scb = p->scb_data->scb_array[scb_index];
  5427. if ((scb->flags & SCB_ACTIVE) == 0)
  5428. {
  5429. scb = NULL;
  5430. }
  5431. }
  5432. if (scb == NULL)
  5433. {
  5434. printk(WARN_LEAD "Referenced SCB %d not valid during SELTO.\n",
  5435. p->host_no, -1, -1, -1, scb_index);
  5436. printk(KERN_WARNING " SCSISEQ = 0x%x SEQADDR = 0x%x SSTAT0 = 0x%x "
  5437. "SSTAT1 = 0x%x\n", aic_inb(p, SCSISEQ),
  5438. aic_inb(p, SEQADDR0) | (aic_inb(p, SEQADDR1) << 8),
  5439. aic_inb(p, SSTAT0), aic_inb(p, SSTAT1));
  5440. if (aic7xxx_panic_on_abort)
  5441. aic7xxx_panic_abort(p, NULL);
  5442. }
  5443. else
  5444. {
  5445. cmd = scb->cmd;
  5446. cmd->result = (DID_TIME_OUT << 16);
  5447. /*
  5448. * Clear out this hardware SCB
  5449. */
  5450. aic_outb(p, 0, SCB_CONTROL);
  5451. /*
  5452. * Clear out a few values in the card that are in an undetermined
  5453. * state.
  5454. */
  5455. aic_outb(p, MSG_NOOP, MSG_OUT);
  5456. /*
  5457. * Shift the waiting for selection queue forward
  5458. */
  5459. nextscb = aic_inb(p, SCB_NEXT);
  5460. aic_outb(p, nextscb, WAITING_SCBH);
  5461. /*
  5462. * Put this SCB back on the free list.
  5463. */
  5464. aic7xxx_add_curscb_to_free_list(p);
  5465. #ifdef AIC7XXX_VERBOSE_DEBUGGING
  5466. if (aic7xxx_verbose > 0xffff)
  5467. printk(INFO_LEAD "Selection Timeout.\n", p->host_no, CTL_OF_SCB(scb));
  5468. #endif
  5469. if (scb->flags & SCB_QUEUED_ABORT)
  5470. {
  5471. /*
  5472. * We know that this particular SCB had to be the queued abort since
  5473. * the disconnected SCB would have gotten a reconnect instead.
  5474. * What we need to do then is to let the command timeout again so
  5475. * we get a reset since this abort just failed.
  5476. */
  5477. cmd->result = 0;
  5478. scb = NULL;
  5479. }
  5480. }
  5481. /*
  5482. * Keep the sequencer from trying to restart any selections
  5483. */
  5484. aic_outb(p, aic_inb(p, SCSISEQ) & ~ENSELO, SCSISEQ);
  5485. /*
  5486. * Make sure the data bits on the bus are released
  5487. * Don't do this on 7770 chipsets, it makes them give us
  5488. * a BRKADDRINT and kills the card.
  5489. */
  5490. if( (p->chip & ~AHC_CHIPID_MASK) == AHC_PCI )
  5491. aic_outb(p, 0, SCSIBUSL);
  5492. /*
  5493. * Delay for the selection timeout delay period then stop the selection
  5494. */
  5495. udelay(301);
  5496. aic_outb(p, CLRSELINGO, CLRSINT0);
  5497. /*
  5498. * Clear out all the interrupt status bits
  5499. */
  5500. aic_outb(p, aic_inb(p, SIMODE1) & ~(ENREQINIT|ENBUSFREE), SIMODE1);
  5501. p->flags &= ~AHC_HANDLING_REQINITS;
  5502. aic_outb(p, CLRSELTIMEO | CLRBUSFREE, CLRSINT1);
  5503. aic_outb(p, CLRSCSIINT, CLRINT);
  5504. /*
  5505. * Restarting the sequencer will stop the selection and make sure devices
  5506. * are allowed to reselect in.
  5507. */
  5508. restart_sequencer(p);
  5509. unpause_sequencer(p, TRUE);
  5510. }
  5511. else if (scb == NULL)
  5512. {
  5513. printk(WARN_LEAD "aic7xxx_isr - referenced scb not valid "
  5514. "during scsiint 0x%x scb(%d)\n"
  5515. " SIMODE0 0x%x, SIMODE1 0x%x, SSTAT0 0x%x, SEQADDR 0x%x\n",
  5516. p->host_no, -1, -1, -1, status, scb_index, aic_inb(p, SIMODE0),
  5517. aic_inb(p, SIMODE1), aic_inb(p, SSTAT0),
  5518. (aic_inb(p, SEQADDR1) << 8) | aic_inb(p, SEQADDR0));
  5519. /*
  5520. * Turn off the interrupt and set status to zero, so that it
  5521. * falls through the rest of the SCSIINT code.
  5522. */
  5523. aic_outb(p, status, CLRSINT1);
  5524. aic_outb(p, CLRSCSIINT, CLRINT);
  5525. unpause_sequencer(p, /* unpause always */ TRUE);
  5526. scb = NULL;
  5527. }
  5528. else if (status & SCSIPERR)
  5529. {
  5530. /*
  5531. * Determine the bus phase and queue an appropriate message.
  5532. */
  5533. char *phase;
  5534. struct scsi_cmnd *cmd;
  5535. unsigned char mesg_out = MSG_NOOP;
  5536. unsigned char lastphase = aic_inb(p, LASTPHASE);
  5537. unsigned char sstat2 = aic_inb(p, SSTAT2);
  5538. cmd = scb->cmd;
  5539. switch (lastphase)
  5540. {
  5541. case P_DATAOUT:
  5542. phase = "Data-Out";
  5543. break;
  5544. case P_DATAIN:
  5545. phase = "Data-In";
  5546. mesg_out = MSG_INITIATOR_DET_ERR;
  5547. break;
  5548. case P_COMMAND:
  5549. phase = "Command";
  5550. break;
  5551. case P_MESGOUT:
  5552. phase = "Message-Out";
  5553. break;
  5554. case P_STATUS:
  5555. phase = "Status";
  5556. mesg_out = MSG_INITIATOR_DET_ERR;
  5557. break;
  5558. case P_MESGIN:
  5559. phase = "Message-In";
  5560. mesg_out = MSG_PARITY_ERROR;
  5561. break;
  5562. default:
  5563. phase = "unknown";
  5564. break;
  5565. }
  5566. /*
  5567. * A parity error has occurred during a data
  5568. * transfer phase. Flag it and continue.
  5569. */
  5570. if( (p->features & AHC_ULTRA3) &&
  5571. (aic_inb(p, SCSIRATE) & AHC_SYNCRATE_CRC) &&
  5572. (lastphase == P_DATAIN) )
  5573. {
  5574. printk(WARN_LEAD "CRC error during %s phase.\n",
  5575. p->host_no, CTL_OF_SCB(scb), phase);
  5576. if(sstat2 & CRCVALERR)
  5577. {
  5578. printk(WARN_LEAD " CRC error in intermediate CRC packet.\n",
  5579. p->host_no, CTL_OF_SCB(scb));
  5580. }
  5581. if(sstat2 & CRCENDERR)
  5582. {
  5583. printk(WARN_LEAD " CRC error in ending CRC packet.\n",
  5584. p->host_no, CTL_OF_SCB(scb));
  5585. }
  5586. if(sstat2 & CRCREQERR)
  5587. {
  5588. printk(WARN_LEAD " Target incorrectly requested a CRC packet.\n",
  5589. p->host_no, CTL_OF_SCB(scb));
  5590. }
  5591. if(sstat2 & DUAL_EDGE_ERROR)
  5592. {
  5593. printk(WARN_LEAD " Dual Edge transmission error.\n",
  5594. p->host_no, CTL_OF_SCB(scb));
  5595. }
  5596. }
  5597. else if( (lastphase == P_MESGOUT) &&
  5598. (scb->flags & SCB_MSGOUT_PPR) )
  5599. {
  5600. /*
  5601. * As per the draft specs, any device capable of supporting any of
  5602. * the option values other than 0 are not allowed to reject the
  5603. * PPR message. Instead, they must negotiate out what they do
  5604. * support instead of rejecting our offering or else they cause
  5605. * a parity error during msg_out phase to signal that they don't
  5606. * like our settings.
  5607. */
  5608. aic_dev = AIC_DEV(scb->cmd);
  5609. aic_dev->needppr = aic_dev->needppr_copy = 0;
  5610. aic7xxx_set_width(p, scb->cmd->device->id, scb->cmd->device->channel, scb->cmd->device->lun,
  5611. MSG_EXT_WDTR_BUS_8_BIT,
  5612. (AHC_TRANS_ACTIVE|AHC_TRANS_CUR|AHC_TRANS_QUITE),
  5613. aic_dev);
  5614. aic7xxx_set_syncrate(p, NULL, scb->cmd->device->id, scb->cmd->device->channel, 0, 0,
  5615. 0, AHC_TRANS_ACTIVE|AHC_TRANS_CUR|AHC_TRANS_QUITE,
  5616. aic_dev);
  5617. aic_dev->goal.options = 0;
  5618. scb->flags &= ~SCB_MSGOUT_BITS;
  5619. if(aic7xxx_verbose & VERBOSE_NEGOTIATION2)
  5620. {
  5621. printk(INFO_LEAD "parity error during PPR message, reverting "
  5622. "to WDTR/SDTR\n", p->host_no, CTL_OF_SCB(scb));
  5623. }
  5624. if ( aic_dev->goal.width )
  5625. {
  5626. aic_dev->needwdtr = aic_dev->needwdtr_copy = 1;
  5627. }
  5628. if ( aic_dev->goal.offset )
  5629. {
  5630. if( aic_dev->goal.period <= 9 )
  5631. {
  5632. aic_dev->goal.period = 10;
  5633. }
  5634. aic_dev->needsdtr = aic_dev->needsdtr_copy = 1;
  5635. }
  5636. scb = NULL;
  5637. }
  5638. /*
  5639. * We've set the hardware to assert ATN if we get a parity
  5640. * error on "in" phases, so all we need to do is stuff the
  5641. * message buffer with the appropriate message. "In" phases
  5642. * have set mesg_out to something other than MSG_NOP.
  5643. */
  5644. if (mesg_out != MSG_NOOP)
  5645. {
  5646. aic_outb(p, mesg_out, MSG_OUT);
  5647. aic_outb(p, aic_inb(p, SCSISIGI) | ATNO, SCSISIGO);
  5648. scb = NULL;
  5649. }
  5650. aic_outb(p, CLRSCSIPERR, CLRSINT1);
  5651. aic_outb(p, CLRSCSIINT, CLRINT);
  5652. unpause_sequencer(p, /* unpause_always */ TRUE);
  5653. }
  5654. else if ( (status & REQINIT) &&
  5655. (p->flags & AHC_HANDLING_REQINITS) )
  5656. {
  5657. #ifdef AIC7XXX_VERBOSE_DEBUGGING
  5658. if (aic7xxx_verbose > 0xffff)
  5659. printk(INFO_LEAD "Handling REQINIT, SSTAT1=0x%x.\n", p->host_no,
  5660. CTL_OF_SCB(scb), aic_inb(p, SSTAT1));
  5661. #endif
  5662. aic7xxx_handle_reqinit(p, scb);
  5663. return;
  5664. }
  5665. else
  5666. {
  5667. /*
  5668. * We don't know what's going on. Turn off the
  5669. * interrupt source and try to continue.
  5670. */
  5671. if (aic7xxx_verbose & VERBOSE_SCSIINT)
  5672. printk(INFO_LEAD "Unknown SCSIINT status, SSTAT1(0x%x).\n",
  5673. p->host_no, -1, -1, -1, status);
  5674. aic_outb(p, status, CLRSINT1);
  5675. aic_outb(p, CLRSCSIINT, CLRINT);
  5676. unpause_sequencer(p, /* unpause always */ TRUE);
  5677. scb = NULL;
  5678. }
  5679. if (scb != NULL)
  5680. {
  5681. aic7xxx_done(p, scb);
  5682. }
  5683. }
  5684. #ifdef AIC7XXX_VERBOSE_DEBUGGING
  5685. static void
  5686. aic7xxx_check_scbs(struct aic7xxx_host *p, char *buffer)
  5687. {
  5688. unsigned char saved_scbptr, free_scbh, dis_scbh, wait_scbh, temp;
  5689. int i, bogus, lost;
  5690. static unsigned char scb_status[AIC7XXX_MAXSCB];
  5691. #define SCB_NO_LIST 0
  5692. #define SCB_FREE_LIST 1
  5693. #define SCB_WAITING_LIST 2
  5694. #define SCB_DISCONNECTED_LIST 4
  5695. #define SCB_CURRENTLY_ACTIVE 8
  5696. /*
  5697. * Note, these checks will fail on a regular basis once the machine moves
  5698. * beyond the bus scan phase. The problem is race conditions concerning
  5699. * the scbs and where they are linked in. When you have 30 or so commands
  5700. * outstanding on the bus, and run this twice with every interrupt, the
  5701. * chances get pretty good that you'll catch the sequencer with an SCB
  5702. * only partially linked in. Therefore, once we pass the scan phase
  5703. * of the bus, we really should disable this function.
  5704. */
  5705. bogus = FALSE;
  5706. memset(&scb_status[0], 0, sizeof(scb_status));
  5707. pause_sequencer(p);
  5708. saved_scbptr = aic_inb(p, SCBPTR);
  5709. if (saved_scbptr >= p->scb_data->maxhscbs)
  5710. {
  5711. printk("Bogus SCBPTR %d\n", saved_scbptr);
  5712. bogus = TRUE;
  5713. }
  5714. scb_status[saved_scbptr] = SCB_CURRENTLY_ACTIVE;
  5715. free_scbh = aic_inb(p, FREE_SCBH);
  5716. if ( (free_scbh != SCB_LIST_NULL) &&
  5717. (free_scbh >= p->scb_data->maxhscbs) )
  5718. {
  5719. printk("Bogus FREE_SCBH %d\n", free_scbh);
  5720. bogus = TRUE;
  5721. }
  5722. else
  5723. {
  5724. temp = free_scbh;
  5725. while( (temp != SCB_LIST_NULL) && (temp < p->scb_data->maxhscbs) )
  5726. {
  5727. if(scb_status[temp] & 0x07)
  5728. {
  5729. printk("HSCB %d on multiple lists, status 0x%02x", temp,
  5730. scb_status[temp] | SCB_FREE_LIST);
  5731. bogus = TRUE;
  5732. }
  5733. scb_status[temp] |= SCB_FREE_LIST;
  5734. aic_outb(p, temp, SCBPTR);
  5735. temp = aic_inb(p, SCB_NEXT);
  5736. }
  5737. }
  5738. dis_scbh = aic_inb(p, DISCONNECTED_SCBH);
  5739. if ( (dis_scbh != SCB_LIST_NULL) &&
  5740. (dis_scbh >= p->scb_data->maxhscbs) )
  5741. {
  5742. printk("Bogus DISCONNECTED_SCBH %d\n", dis_scbh);
  5743. bogus = TRUE;
  5744. }
  5745. else
  5746. {
  5747. temp = dis_scbh;
  5748. while( (temp != SCB_LIST_NULL) && (temp < p->scb_data->maxhscbs) )
  5749. {
  5750. if(scb_status[temp] & 0x07)
  5751. {
  5752. printk("HSCB %d on multiple lists, status 0x%02x", temp,
  5753. scb_status[temp] | SCB_DISCONNECTED_LIST);
  5754. bogus = TRUE;
  5755. }
  5756. scb_status[temp] |= SCB_DISCONNECTED_LIST;
  5757. aic_outb(p, temp, SCBPTR);
  5758. temp = aic_inb(p, SCB_NEXT);
  5759. }
  5760. }
  5761. wait_scbh = aic_inb(p, WAITING_SCBH);
  5762. if ( (wait_scbh != SCB_LIST_NULL) &&
  5763. (wait_scbh >= p->scb_data->maxhscbs) )
  5764. {
  5765. printk("Bogus WAITING_SCBH %d\n", wait_scbh);
  5766. bogus = TRUE;
  5767. }
  5768. else
  5769. {
  5770. temp = wait_scbh;
  5771. while( (temp != SCB_LIST_NULL) && (temp < p->scb_data->maxhscbs) )
  5772. {
  5773. if(scb_status[temp] & 0x07)
  5774. {
  5775. printk("HSCB %d on multiple lists, status 0x%02x", temp,
  5776. scb_status[temp] | SCB_WAITING_LIST);
  5777. bogus = TRUE;
  5778. }
  5779. scb_status[temp] |= SCB_WAITING_LIST;
  5780. aic_outb(p, temp, SCBPTR);
  5781. temp = aic_inb(p, SCB_NEXT);
  5782. }
  5783. }
  5784. lost=0;
  5785. for(i=0; i < p->scb_data->maxhscbs; i++)
  5786. {
  5787. aic_outb(p, i, SCBPTR);
  5788. temp = aic_inb(p, SCB_NEXT);
  5789. if ( ((temp != SCB_LIST_NULL) &&
  5790. (temp >= p->scb_data->maxhscbs)) )
  5791. {
  5792. printk("HSCB %d bad, SCB_NEXT invalid(%d).\n", i, temp);
  5793. bogus = TRUE;
  5794. }
  5795. if ( temp == i )
  5796. {
  5797. printk("HSCB %d bad, SCB_NEXT points to self.\n", i);
  5798. bogus = TRUE;
  5799. }
  5800. if (scb_status[i] == 0)
  5801. lost++;
  5802. if (lost > 1)
  5803. {
  5804. printk("Too many lost scbs.\n");
  5805. bogus=TRUE;
  5806. }
  5807. }
  5808. aic_outb(p, saved_scbptr, SCBPTR);
  5809. unpause_sequencer(p, FALSE);
  5810. if (bogus)
  5811. {
  5812. printk("Bogus parameters found in card SCB array structures.\n");
  5813. printk("%s\n", buffer);
  5814. aic7xxx_panic_abort(p, NULL);
  5815. }
  5816. return;
  5817. }
  5818. #endif
  5819. /*+F*************************************************************************
  5820. * Function:
  5821. * aic7xxx_handle_command_completion_intr
  5822. *
  5823. * Description:
  5824. * SCSI command completion interrupt handler.
  5825. *-F*************************************************************************/
  5826. static void
  5827. aic7xxx_handle_command_completion_intr(struct aic7xxx_host *p)
  5828. {
  5829. struct aic7xxx_scb *scb = NULL;
  5830. struct aic_dev_data *aic_dev;
  5831. struct scsi_cmnd *cmd;
  5832. unsigned char scb_index, tindex;
  5833. #ifdef AIC7XXX_VERBOSE_DEBUGGING
  5834. if( (p->isr_count < 16) && (aic7xxx_verbose > 0xffff) )
  5835. printk(INFO_LEAD "Command Complete Int.\n", p->host_no, -1, -1, -1);
  5836. #endif
  5837. /*
  5838. * Read the INTSTAT location after clearing the CMDINT bit. This forces
  5839. * any posted PCI writes to flush to memory. Gerard Roudier suggested
  5840. * this fix to the possible race of clearing the CMDINT bit but not
  5841. * having all command bytes flushed onto the qoutfifo.
  5842. */
  5843. aic_outb(p, CLRCMDINT, CLRINT);
  5844. aic_inb(p, INTSTAT);
  5845. /*
  5846. * The sequencer will continue running when it
  5847. * issues this interrupt. There may be >1 commands
  5848. * finished, so loop until we've processed them all.
  5849. */
  5850. while (p->qoutfifo[p->qoutfifonext] != SCB_LIST_NULL)
  5851. {
  5852. scb_index = p->qoutfifo[p->qoutfifonext];
  5853. p->qoutfifo[p->qoutfifonext++] = SCB_LIST_NULL;
  5854. if ( scb_index >= p->scb_data->numscbs )
  5855. {
  5856. printk(WARN_LEAD "CMDCMPLT with invalid SCB index %d\n", p->host_no,
  5857. -1, -1, -1, scb_index);
  5858. continue;
  5859. }
  5860. scb = p->scb_data->scb_array[scb_index];
  5861. if (!(scb->flags & SCB_ACTIVE) || (scb->cmd == NULL))
  5862. {
  5863. printk(WARN_LEAD "CMDCMPLT without command for SCB %d, SCB flags "
  5864. "0x%x, cmd 0x%lx\n", p->host_no, -1, -1, -1, scb_index, scb->flags,
  5865. (unsigned long) scb->cmd);
  5866. continue;
  5867. }
  5868. tindex = TARGET_INDEX(scb->cmd);
  5869. aic_dev = AIC_DEV(scb->cmd);
  5870. if (scb->flags & SCB_QUEUED_ABORT)
  5871. {
  5872. pause_sequencer(p);
  5873. if ( ((aic_inb(p, LASTPHASE) & PHASE_MASK) != P_BUSFREE) &&
  5874. (aic_inb(p, SCB_TAG) == scb->hscb->tag) )
  5875. {
  5876. unpause_sequencer(p, FALSE);
  5877. continue;
  5878. }
  5879. aic7xxx_reset_device(p, scb->cmd->device->id, scb->cmd->device->channel,
  5880. scb->cmd->device->lun, scb->hscb->tag);
  5881. scb->flags &= ~(SCB_QUEUED_FOR_DONE | SCB_RESET | SCB_ABORT |
  5882. SCB_QUEUED_ABORT);
  5883. unpause_sequencer(p, FALSE);
  5884. }
  5885. else if (scb->flags & SCB_ABORT)
  5886. {
  5887. /*
  5888. * We started to abort this, but it completed on us, let it
  5889. * through as successful
  5890. */
  5891. scb->flags &= ~(SCB_ABORT|SCB_RESET);
  5892. }
  5893. else if (scb->flags & SCB_SENSE)
  5894. {
  5895. char *buffer = &scb->cmd->sense_buffer[0];
  5896. if (buffer[12] == 0x47 || buffer[12] == 0x54)
  5897. {
  5898. /*
  5899. * Signal that we need to re-negotiate things.
  5900. */
  5901. aic_dev->needppr = aic_dev->needppr_copy;
  5902. aic_dev->needsdtr = aic_dev->needsdtr_copy;
  5903. aic_dev->needwdtr = aic_dev->needwdtr_copy;
  5904. }
  5905. }
  5906. cmd = scb->cmd;
  5907. if (scb->hscb->residual_SG_segment_count != 0)
  5908. {
  5909. aic7xxx_calculate_residual(p, scb);
  5910. }
  5911. cmd->result |= (aic7xxx_error(cmd) << 16);
  5912. aic7xxx_done(p, scb);
  5913. }
  5914. }
  5915. /*+F*************************************************************************
  5916. * Function:
  5917. * aic7xxx_isr
  5918. *
  5919. * Description:
  5920. * SCSI controller interrupt handler.
  5921. *-F*************************************************************************/
  5922. static void
  5923. aic7xxx_isr(void *dev_id)
  5924. {
  5925. struct aic7xxx_host *p;
  5926. unsigned char intstat;
  5927. p = dev_id;
  5928. /*
  5929. * Just a few sanity checks. Make sure that we have an int pending.
  5930. * Also, if PCI, then we are going to check for a PCI bus error status
  5931. * should we get too many spurious interrupts.
  5932. */
  5933. if (!((intstat = aic_inb(p, INTSTAT)) & INT_PEND))
  5934. {
  5935. #ifdef CONFIG_PCI
  5936. if ( (p->chip & AHC_PCI) && (p->spurious_int > 500) &&
  5937. !(p->flags & AHC_HANDLING_REQINITS) )
  5938. {
  5939. if ( aic_inb(p, ERROR) & PCIERRSTAT )
  5940. {
  5941. aic7xxx_pci_intr(p);
  5942. }
  5943. p->spurious_int = 0;
  5944. }
  5945. else if ( !(p->flags & AHC_HANDLING_REQINITS) )
  5946. {
  5947. p->spurious_int++;
  5948. }
  5949. #endif
  5950. return;
  5951. }
  5952. p->spurious_int = 0;
  5953. /*
  5954. * Keep track of interrupts for /proc/scsi
  5955. */
  5956. p->isr_count++;
  5957. #ifdef AIC7XXX_VERBOSE_DEBUGGING
  5958. if ( (p->isr_count < 16) && (aic7xxx_verbose > 0xffff) &&
  5959. (aic7xxx_panic_on_abort) && (p->flags & AHC_PAGESCBS) )
  5960. aic7xxx_check_scbs(p, "Bogus settings at start of interrupt.");
  5961. #endif
  5962. /*
  5963. * Handle all the interrupt sources - especially for SCSI
  5964. * interrupts, we won't get a second chance at them.
  5965. */
  5966. if (intstat & CMDCMPLT)
  5967. {
  5968. aic7xxx_handle_command_completion_intr(p);
  5969. }
  5970. if (intstat & BRKADRINT)
  5971. {
  5972. int i;
  5973. unsigned char errno = aic_inb(p, ERROR);
  5974. printk(KERN_ERR "(scsi%d) BRKADRINT error(0x%x):\n", p->host_no, errno);
  5975. for (i = 0; i < ARRAY_SIZE(hard_error); i++)
  5976. {
  5977. if (errno & hard_error[i].errno)
  5978. {
  5979. printk(KERN_ERR " %s\n", hard_error[i].errmesg);
  5980. }
  5981. }
  5982. printk(KERN_ERR "(scsi%d) SEQADDR=0x%x\n", p->host_no,
  5983. (((aic_inb(p, SEQADDR1) << 8) & 0x100) | aic_inb(p, SEQADDR0)));
  5984. if (aic7xxx_panic_on_abort)
  5985. aic7xxx_panic_abort(p, NULL);
  5986. #ifdef CONFIG_PCI
  5987. if (errno & PCIERRSTAT)
  5988. aic7xxx_pci_intr(p);
  5989. #endif
  5990. if (errno & (SQPARERR | ILLOPCODE | ILLSADDR))
  5991. {
  5992. panic("aic7xxx: unrecoverable BRKADRINT.\n");
  5993. }
  5994. if (errno & ILLHADDR)
  5995. {
  5996. printk(KERN_ERR "(scsi%d) BUG! Driver accessed chip without first "
  5997. "pausing controller!\n", p->host_no);
  5998. }
  5999. #ifdef AIC7XXX_VERBOSE_DEBUGGING
  6000. if (errno & DPARERR)
  6001. {
  6002. if (aic_inb(p, DMAPARAMS) & DIRECTION)
  6003. printk("(scsi%d) while DMAing SCB from host to card.\n", p->host_no);
  6004. else
  6005. printk("(scsi%d) while DMAing SCB from card to host.\n", p->host_no);
  6006. }
  6007. #endif
  6008. aic_outb(p, CLRPARERR | CLRBRKADRINT, CLRINT);
  6009. unpause_sequencer(p, FALSE);
  6010. }
  6011. if (intstat & SEQINT)
  6012. {
  6013. /*
  6014. * Read the CCSCBCTL register to work around a bug in the Ultra2 cards
  6015. */
  6016. if(p->features & AHC_ULTRA2)
  6017. {
  6018. aic_inb(p, CCSCBCTL);
  6019. }
  6020. aic7xxx_handle_seqint(p, intstat);
  6021. }
  6022. if (intstat & SCSIINT)
  6023. {
  6024. aic7xxx_handle_scsiint(p, intstat);
  6025. }
  6026. #ifdef AIC7XXX_VERBOSE_DEBUGGING
  6027. if ( (p->isr_count < 16) && (aic7xxx_verbose > 0xffff) &&
  6028. (aic7xxx_panic_on_abort) && (p->flags & AHC_PAGESCBS) )
  6029. aic7xxx_check_scbs(p, "Bogus settings at end of interrupt.");
  6030. #endif
  6031. }
  6032. /*+F*************************************************************************
  6033. * Function:
  6034. * do_aic7xxx_isr
  6035. *
  6036. * Description:
  6037. * This is a gross hack to solve a problem in linux kernels 2.1.85 and
  6038. * above. Please, children, do not try this at home, and if you ever see
  6039. * anything like it, please inform the Gross Hack Police immediately
  6040. *-F*************************************************************************/
  6041. static irqreturn_t
  6042. do_aic7xxx_isr(int irq, void *dev_id)
  6043. {
  6044. unsigned long cpu_flags;
  6045. struct aic7xxx_host *p;
  6046. p = dev_id;
  6047. if(!p)
  6048. return IRQ_NONE;
  6049. spin_lock_irqsave(p->host->host_lock, cpu_flags);
  6050. p->flags |= AHC_IN_ISR;
  6051. do
  6052. {
  6053. aic7xxx_isr(dev_id);
  6054. } while ( (aic_inb(p, INTSTAT) & INT_PEND) );
  6055. aic7xxx_done_cmds_complete(p);
  6056. aic7xxx_run_waiting_queues(p);
  6057. p->flags &= ~AHC_IN_ISR;
  6058. spin_unlock_irqrestore(p->host->host_lock, cpu_flags);
  6059. return IRQ_HANDLED;
  6060. }
  6061. /*+F*************************************************************************
  6062. * Function:
  6063. * aic7xxx_init_transinfo
  6064. *
  6065. * Description:
  6066. * Set up the initial aic_dev values from the BIOS settings and from
  6067. * INQUIRY results
  6068. *-F*************************************************************************/
  6069. static void
  6070. aic7xxx_init_transinfo(struct aic7xxx_host *p, struct aic_dev_data *aic_dev)
  6071. {
  6072. struct scsi_device *sdpnt = aic_dev->SDptr;
  6073. unsigned char tindex;
  6074. tindex = sdpnt->id | (sdpnt->channel << 3);
  6075. if (!(aic_dev->flags & DEVICE_DTR_SCANNED))
  6076. {
  6077. aic_dev->flags |= DEVICE_DTR_SCANNED;
  6078. if ( sdpnt->wdtr && (p->features & AHC_WIDE) )
  6079. {
  6080. aic_dev->needwdtr = aic_dev->needwdtr_copy = 1;
  6081. aic_dev->goal.width = p->user[tindex].width;
  6082. }
  6083. else
  6084. {
  6085. aic_dev->needwdtr = aic_dev->needwdtr_copy = 0;
  6086. pause_sequencer(p);
  6087. aic7xxx_set_width(p, sdpnt->id, sdpnt->channel, sdpnt->lun,
  6088. MSG_EXT_WDTR_BUS_8_BIT, (AHC_TRANS_ACTIVE |
  6089. AHC_TRANS_GOAL |
  6090. AHC_TRANS_CUR), aic_dev );
  6091. unpause_sequencer(p, FALSE);
  6092. }
  6093. if ( sdpnt->sdtr && p->user[tindex].offset )
  6094. {
  6095. aic_dev->goal.period = p->user[tindex].period;
  6096. aic_dev->goal.options = p->user[tindex].options;
  6097. if (p->features & AHC_ULTRA2)
  6098. aic_dev->goal.offset = MAX_OFFSET_ULTRA2;
  6099. else if (aic_dev->goal.width == MSG_EXT_WDTR_BUS_16_BIT)
  6100. aic_dev->goal.offset = MAX_OFFSET_16BIT;
  6101. else
  6102. aic_dev->goal.offset = MAX_OFFSET_8BIT;
  6103. if ( sdpnt->ppr && p->user[tindex].period <= 9 &&
  6104. p->user[tindex].options )
  6105. {
  6106. aic_dev->needppr = aic_dev->needppr_copy = 1;
  6107. aic_dev->needsdtr = aic_dev->needsdtr_copy = 0;
  6108. aic_dev->needwdtr = aic_dev->needwdtr_copy = 0;
  6109. aic_dev->flags |= DEVICE_SCSI_3;
  6110. }
  6111. else
  6112. {
  6113. aic_dev->needsdtr = aic_dev->needsdtr_copy = 1;
  6114. aic_dev->goal.period = max_t(unsigned char, 10, aic_dev->goal.period);
  6115. aic_dev->goal.options = 0;
  6116. }
  6117. }
  6118. else
  6119. {
  6120. aic_dev->needsdtr = aic_dev->needsdtr_copy = 0;
  6121. aic_dev->goal.period = 255;
  6122. aic_dev->goal.offset = 0;
  6123. aic_dev->goal.options = 0;
  6124. }
  6125. aic_dev->flags |= DEVICE_PRINT_DTR;
  6126. }
  6127. }
  6128. /*+F*************************************************************************
  6129. * Function:
  6130. * aic7xxx_slave_alloc
  6131. *
  6132. * Description:
  6133. * Set up the initial aic_dev struct pointers
  6134. *-F*************************************************************************/
  6135. static int
  6136. aic7xxx_slave_alloc(struct scsi_device *SDptr)
  6137. {
  6138. struct aic7xxx_host *p = (struct aic7xxx_host *)SDptr->host->hostdata;
  6139. struct aic_dev_data *aic_dev;
  6140. aic_dev = kmalloc(sizeof(struct aic_dev_data), GFP_KERNEL);
  6141. if(!aic_dev)
  6142. return 1;
  6143. /*
  6144. * Check to see if channel was scanned.
  6145. */
  6146. if (!(p->flags & AHC_A_SCANNED) && (SDptr->channel == 0))
  6147. {
  6148. if (aic7xxx_verbose & VERBOSE_PROBE2)
  6149. printk(INFO_LEAD "Scanning channel for devices.\n",
  6150. p->host_no, 0, -1, -1);
  6151. p->flags |= AHC_A_SCANNED;
  6152. }
  6153. else
  6154. {
  6155. if (!(p->flags & AHC_B_SCANNED) && (SDptr->channel == 1))
  6156. {
  6157. if (aic7xxx_verbose & VERBOSE_PROBE2)
  6158. printk(INFO_LEAD "Scanning channel for devices.\n",
  6159. p->host_no, 1, -1, -1);
  6160. p->flags |= AHC_B_SCANNED;
  6161. }
  6162. }
  6163. memset(aic_dev, 0, sizeof(struct aic_dev_data));
  6164. SDptr->hostdata = aic_dev;
  6165. aic_dev->SDptr = SDptr;
  6166. aic_dev->max_q_depth = 1;
  6167. aic_dev->temp_q_depth = 1;
  6168. scbq_init(&aic_dev->delayed_scbs);
  6169. INIT_LIST_HEAD(&aic_dev->list);
  6170. list_add_tail(&aic_dev->list, &p->aic_devs);
  6171. return 0;
  6172. }
  6173. /*+F*************************************************************************
  6174. * Function:
  6175. * aic7xxx_device_queue_depth
  6176. *
  6177. * Description:
  6178. * Determines the queue depth for a given device. There are two ways
  6179. * a queue depth can be obtained for a tagged queueing device. One
  6180. * way is the default queue depth which is determined by whether
  6181. * aic7xxx_default_queue_depth. The other is by the aic7xxx_tag_info
  6182. * array.
  6183. *
  6184. * If tagged queueing isn't supported on the device, then we set the
  6185. * depth to p->host->hostt->cmd_per_lun for internal driver queueing.
  6186. * as the default queue depth. Otherwise, we use either 4 or 8 as the
  6187. * default queue depth (dependent on the number of hardware SCBs).
  6188. * The other way we determine queue depth is through the use of the
  6189. * aic7xxx_tag_info array which is enabled by defining
  6190. * AIC7XXX_TAGGED_QUEUEING_BY_DEVICE. This array can be initialized
  6191. * with queue depths for individual devices. It also allows tagged
  6192. * queueing to be [en|dis]abled for a specific adapter.
  6193. *-F*************************************************************************/
  6194. static void
  6195. aic7xxx_device_queue_depth(struct aic7xxx_host *p, struct scsi_device *device)
  6196. {
  6197. int tag_enabled = FALSE;
  6198. struct aic_dev_data *aic_dev = device->hostdata;
  6199. unsigned char tindex;
  6200. tindex = device->id | (device->channel << 3);
  6201. if (device->simple_tags)
  6202. return; // We've already enabled this device
  6203. if (device->tagged_supported)
  6204. {
  6205. tag_enabled = TRUE;
  6206. if (!(p->discenable & (1 << tindex)))
  6207. {
  6208. if (aic7xxx_verbose & VERBOSE_NEGOTIATION2)
  6209. printk(INFO_LEAD "Disconnection disabled, unable to "
  6210. "enable tagged queueing.\n",
  6211. p->host_no, device->channel, device->id, device->lun);
  6212. tag_enabled = FALSE;
  6213. }
  6214. else
  6215. {
  6216. if (p->instance >= ARRAY_SIZE(aic7xxx_tag_info))
  6217. {
  6218. static int print_warning = TRUE;
  6219. if(print_warning)
  6220. {
  6221. printk(KERN_INFO "aic7xxx: WARNING, insufficient tag_info instances for"
  6222. " installed controllers.\n");
  6223. printk(KERN_INFO "aic7xxx: Please update the aic7xxx_tag_info array in"
  6224. " the aic7xxx.c source file.\n");
  6225. print_warning = FALSE;
  6226. }
  6227. aic_dev->max_q_depth = aic_dev->temp_q_depth =
  6228. aic7xxx_default_queue_depth;
  6229. }
  6230. else
  6231. {
  6232. if (aic7xxx_tag_info[p->instance].tag_commands[tindex] == 255)
  6233. {
  6234. tag_enabled = FALSE;
  6235. }
  6236. else if (aic7xxx_tag_info[p->instance].tag_commands[tindex] == 0)
  6237. {
  6238. aic_dev->max_q_depth = aic_dev->temp_q_depth =
  6239. aic7xxx_default_queue_depth;
  6240. }
  6241. else
  6242. {
  6243. aic_dev->max_q_depth = aic_dev->temp_q_depth =
  6244. aic7xxx_tag_info[p->instance].tag_commands[tindex];
  6245. }
  6246. }
  6247. }
  6248. }
  6249. if (tag_enabled)
  6250. {
  6251. if (aic7xxx_verbose & VERBOSE_NEGOTIATION2)
  6252. {
  6253. printk(INFO_LEAD "Tagged queuing enabled, queue depth %d.\n",
  6254. p->host_no, device->channel, device->id,
  6255. device->lun, aic_dev->max_q_depth);
  6256. }
  6257. scsi_adjust_queue_depth(device, MSG_ORDERED_TAG, aic_dev->max_q_depth);
  6258. }
  6259. else
  6260. {
  6261. if (aic7xxx_verbose & VERBOSE_NEGOTIATION2)
  6262. {
  6263. printk(INFO_LEAD "Tagged queuing disabled, queue depth %d.\n",
  6264. p->host_no, device->channel, device->id,
  6265. device->lun, device->host->cmd_per_lun);
  6266. }
  6267. scsi_adjust_queue_depth(device, 0, device->host->cmd_per_lun);
  6268. }
  6269. return;
  6270. }
  6271. /*+F*************************************************************************
  6272. * Function:
  6273. * aic7xxx_slave_destroy
  6274. *
  6275. * Description:
  6276. * prepare for this device to go away
  6277. *-F*************************************************************************/
  6278. static void
  6279. aic7xxx_slave_destroy(struct scsi_device *SDptr)
  6280. {
  6281. struct aic_dev_data *aic_dev = SDptr->hostdata;
  6282. list_del(&aic_dev->list);
  6283. SDptr->hostdata = NULL;
  6284. kfree(aic_dev);
  6285. return;
  6286. }
  6287. /*+F*************************************************************************
  6288. * Function:
  6289. * aic7xxx_slave_configure
  6290. *
  6291. * Description:
  6292. * Configure the device we are attaching to the controller. This is
  6293. * where we get to do things like scan the INQUIRY data, set queue
  6294. * depths, allocate command structs, etc.
  6295. *-F*************************************************************************/
  6296. static int
  6297. aic7xxx_slave_configure(struct scsi_device *SDptr)
  6298. {
  6299. struct aic7xxx_host *p = (struct aic7xxx_host *) SDptr->host->hostdata;
  6300. struct aic_dev_data *aic_dev;
  6301. int scbnum;
  6302. aic_dev = (struct aic_dev_data *)SDptr->hostdata;
  6303. aic7xxx_init_transinfo(p, aic_dev);
  6304. aic7xxx_device_queue_depth(p, SDptr);
  6305. if(list_empty(&aic_dev->list))
  6306. list_add_tail(&aic_dev->list, &p->aic_devs);
  6307. scbnum = 0;
  6308. list_for_each_entry(aic_dev, &p->aic_devs, list) {
  6309. scbnum += aic_dev->max_q_depth;
  6310. }
  6311. while (scbnum > p->scb_data->numscbs)
  6312. {
  6313. /*
  6314. * Pre-allocate the needed SCBs to get around the possibility of having
  6315. * to allocate some when memory is more or less exhausted and we need
  6316. * the SCB in order to perform a swap operation (possible deadlock)
  6317. */
  6318. if ( aic7xxx_allocate_scb(p) == 0 )
  6319. break;
  6320. }
  6321. return(0);
  6322. }
  6323. /*+F*************************************************************************
  6324. * Function:
  6325. * aic7xxx_probe
  6326. *
  6327. * Description:
  6328. * Probing for EISA boards: it looks like the first two bytes
  6329. * are a manufacturer code - three characters, five bits each:
  6330. *
  6331. * BYTE 0 BYTE 1 BYTE 2 BYTE 3
  6332. * ?1111122 22233333 PPPPPPPP RRRRRRRR
  6333. *
  6334. * The characters are baselined off ASCII '@', so add that value
  6335. * to each to get the real ASCII code for it. The next two bytes
  6336. * appear to be a product and revision number, probably vendor-
  6337. * specific. This is what is being searched for at each port,
  6338. * and what should probably correspond to the ID= field in the
  6339. * ECU's .cfg file for the card - if your card is not detected,
  6340. * make sure your signature is listed in the array.
  6341. *
  6342. * The fourth byte's lowest bit seems to be an enabled/disabled
  6343. * flag (rest of the bits are reserved?).
  6344. *
  6345. * NOTE: This function is only needed on Intel and Alpha platforms,
  6346. * the other platforms we support don't have EISA/VLB busses. So,
  6347. * we #ifdef this entire function to avoid compiler warnings about
  6348. * an unused function.
  6349. *-F*************************************************************************/
  6350. #if defined(__i386__) || defined(__alpha__)
  6351. static int
  6352. aic7xxx_probe(int slot, int base, ahc_flag_type *flags)
  6353. {
  6354. int i;
  6355. unsigned char buf[4];
  6356. static struct {
  6357. int n;
  6358. unsigned char signature[sizeof(buf)];
  6359. ahc_chip type;
  6360. int bios_disabled;
  6361. } AIC7xxx[] = {
  6362. { 4, { 0x04, 0x90, 0x77, 0x70 },
  6363. AHC_AIC7770|AHC_EISA, FALSE }, /* mb 7770 */
  6364. { 4, { 0x04, 0x90, 0x77, 0x71 },
  6365. AHC_AIC7770|AHC_EISA, FALSE }, /* host adapter 274x */
  6366. { 4, { 0x04, 0x90, 0x77, 0x56 },
  6367. AHC_AIC7770|AHC_VL, FALSE }, /* 284x BIOS enabled */
  6368. { 4, { 0x04, 0x90, 0x77, 0x57 },
  6369. AHC_AIC7770|AHC_VL, TRUE } /* 284x BIOS disabled */
  6370. };
  6371. /*
  6372. * The VL-bus cards need to be primed by
  6373. * writing before a signature check.
  6374. */
  6375. for (i = 0; i < sizeof(buf); i++)
  6376. {
  6377. outb(0x80 + i, base);
  6378. buf[i] = inb(base + i);
  6379. }
  6380. for (i = 0; i < ARRAY_SIZE(AIC7xxx); i++)
  6381. {
  6382. /*
  6383. * Signature match on enabled card?
  6384. */
  6385. if (!memcmp(buf, AIC7xxx[i].signature, AIC7xxx[i].n))
  6386. {
  6387. if (inb(base + 4) & 1)
  6388. {
  6389. if (AIC7xxx[i].bios_disabled)
  6390. {
  6391. *flags |= AHC_USEDEFAULTS;
  6392. }
  6393. else
  6394. {
  6395. *flags |= AHC_BIOS_ENABLED;
  6396. }
  6397. return (i);
  6398. }
  6399. printk("aic7xxx: <Adaptec 7770 SCSI Host Adapter> "
  6400. "disabled at slot %d, ignored.\n", slot);
  6401. }
  6402. }
  6403. return (-1);
  6404. }
  6405. #endif /* (__i386__) || (__alpha__) */
  6406. /*+F*************************************************************************
  6407. * Function:
  6408. * read_2840_seeprom
  6409. *
  6410. * Description:
  6411. * Reads the 2840 serial EEPROM and returns 1 if successful and 0 if
  6412. * not successful.
  6413. *
  6414. * See read_seeprom (for the 2940) for the instruction set of the 93C46
  6415. * chip.
  6416. *
  6417. * The 2840 interface to the 93C46 serial EEPROM is through the
  6418. * STATUS_2840 and SEECTL_2840 registers. The CS_2840, CK_2840, and
  6419. * DO_2840 bits of the SEECTL_2840 register are connected to the chip
  6420. * select, clock, and data out lines respectively of the serial EEPROM.
  6421. * The DI_2840 bit of the STATUS_2840 is connected to the data in line
  6422. * of the serial EEPROM. The EEPROM_TF bit of STATUS_2840 register is
  6423. * useful in that it gives us an 800 nsec timer. After a read from the
  6424. * SEECTL_2840 register the timing flag is cleared and goes high 800 nsec
  6425. * later.
  6426. *-F*************************************************************************/
  6427. static int
  6428. read_284x_seeprom(struct aic7xxx_host *p, struct seeprom_config *sc)
  6429. {
  6430. int i = 0, k = 0;
  6431. unsigned char temp;
  6432. unsigned short checksum = 0;
  6433. unsigned short *seeprom = (unsigned short *) sc;
  6434. struct seeprom_cmd {
  6435. unsigned char len;
  6436. unsigned char bits[3];
  6437. };
  6438. struct seeprom_cmd seeprom_read = {3, {1, 1, 0}};
  6439. #define CLOCK_PULSE(p) \
  6440. while ((aic_inb(p, STATUS_2840) & EEPROM_TF) == 0) \
  6441. { \
  6442. ; /* Do nothing */ \
  6443. } \
  6444. (void) aic_inb(p, SEECTL_2840);
  6445. /*
  6446. * Read the first 32 registers of the seeprom. For the 2840,
  6447. * the 93C46 SEEPROM is a 1024-bit device with 64 16-bit registers
  6448. * but only the first 32 are used by Adaptec BIOS. The loop
  6449. * will range from 0 to 31.
  6450. */
  6451. for (k = 0; k < (sizeof(*sc) / 2); k++)
  6452. {
  6453. /*
  6454. * Send chip select for one clock cycle.
  6455. */
  6456. aic_outb(p, CK_2840 | CS_2840, SEECTL_2840);
  6457. CLOCK_PULSE(p);
  6458. /*
  6459. * Now we're ready to send the read command followed by the
  6460. * address of the 16-bit register we want to read.
  6461. */
  6462. for (i = 0; i < seeprom_read.len; i++)
  6463. {
  6464. temp = CS_2840 | seeprom_read.bits[i];
  6465. aic_outb(p, temp, SEECTL_2840);
  6466. CLOCK_PULSE(p);
  6467. temp = temp ^ CK_2840;
  6468. aic_outb(p, temp, SEECTL_2840);
  6469. CLOCK_PULSE(p);
  6470. }
  6471. /*
  6472. * Send the 6 bit address (MSB first, LSB last).
  6473. */
  6474. for (i = 5; i >= 0; i--)
  6475. {
  6476. temp = k;
  6477. temp = (temp >> i) & 1; /* Mask out all but lower bit. */
  6478. temp = CS_2840 | temp;
  6479. aic_outb(p, temp, SEECTL_2840);
  6480. CLOCK_PULSE(p);
  6481. temp = temp ^ CK_2840;
  6482. aic_outb(p, temp, SEECTL_2840);
  6483. CLOCK_PULSE(p);
  6484. }
  6485. /*
  6486. * Now read the 16 bit register. An initial 0 precedes the
  6487. * register contents which begins with bit 15 (MSB) and ends
  6488. * with bit 0 (LSB). The initial 0 will be shifted off the
  6489. * top of our word as we let the loop run from 0 to 16.
  6490. */
  6491. for (i = 0; i <= 16; i++)
  6492. {
  6493. temp = CS_2840;
  6494. aic_outb(p, temp, SEECTL_2840);
  6495. CLOCK_PULSE(p);
  6496. temp = temp ^ CK_2840;
  6497. seeprom[k] = (seeprom[k] << 1) | (aic_inb(p, STATUS_2840) & DI_2840);
  6498. aic_outb(p, temp, SEECTL_2840);
  6499. CLOCK_PULSE(p);
  6500. }
  6501. /*
  6502. * The serial EEPROM has a checksum in the last word. Keep a
  6503. * running checksum for all words read except for the last
  6504. * word. We'll verify the checksum after all words have been
  6505. * read.
  6506. */
  6507. if (k < (sizeof(*sc) / 2) - 1)
  6508. {
  6509. checksum = checksum + seeprom[k];
  6510. }
  6511. /*
  6512. * Reset the chip select for the next command cycle.
  6513. */
  6514. aic_outb(p, 0, SEECTL_2840);
  6515. CLOCK_PULSE(p);
  6516. aic_outb(p, CK_2840, SEECTL_2840);
  6517. CLOCK_PULSE(p);
  6518. aic_outb(p, 0, SEECTL_2840);
  6519. CLOCK_PULSE(p);
  6520. }
  6521. #if 0
  6522. printk("Computed checksum 0x%x, checksum read 0x%x\n", checksum, sc->checksum);
  6523. printk("Serial EEPROM:");
  6524. for (k = 0; k < (sizeof(*sc) / 2); k++)
  6525. {
  6526. if (((k % 8) == 0) && (k != 0))
  6527. {
  6528. printk("\n ");
  6529. }
  6530. printk(" 0x%x", seeprom[k]);
  6531. }
  6532. printk("\n");
  6533. #endif
  6534. if (checksum != sc->checksum)
  6535. {
  6536. printk("aic7xxx: SEEPROM checksum error, ignoring SEEPROM settings.\n");
  6537. return (0);
  6538. }
  6539. return (1);
  6540. #undef CLOCK_PULSE
  6541. }
  6542. #define CLOCK_PULSE(p) \
  6543. do { \
  6544. int limit = 0; \
  6545. do { \
  6546. mb(); \
  6547. pause_sequencer(p); /* This is just to generate some PCI */ \
  6548. /* traffic so the PCI read is flushed */ \
  6549. /* it shouldn't be needed, but some */ \
  6550. /* chipsets do indeed appear to need */ \
  6551. /* something to force PCI reads to get */ \
  6552. /* flushed */ \
  6553. udelay(1); /* Do nothing */ \
  6554. } while (((aic_inb(p, SEECTL) & SEERDY) == 0) && (++limit < 1000)); \
  6555. } while(0)
  6556. /*+F*************************************************************************
  6557. * Function:
  6558. * acquire_seeprom
  6559. *
  6560. * Description:
  6561. * Acquires access to the memory port on PCI controllers.
  6562. *-F*************************************************************************/
  6563. static int
  6564. acquire_seeprom(struct aic7xxx_host *p)
  6565. {
  6566. /*
  6567. * Request access of the memory port. When access is
  6568. * granted, SEERDY will go high. We use a 1 second
  6569. * timeout which should be near 1 second more than
  6570. * is needed. Reason: after the 7870 chip reset, there
  6571. * should be no contention.
  6572. */
  6573. aic_outb(p, SEEMS, SEECTL);
  6574. CLOCK_PULSE(p);
  6575. if ((aic_inb(p, SEECTL) & SEERDY) == 0)
  6576. {
  6577. aic_outb(p, 0, SEECTL);
  6578. return (0);
  6579. }
  6580. return (1);
  6581. }
  6582. /*+F*************************************************************************
  6583. * Function:
  6584. * release_seeprom
  6585. *
  6586. * Description:
  6587. * Releases access to the memory port on PCI controllers.
  6588. *-F*************************************************************************/
  6589. static void
  6590. release_seeprom(struct aic7xxx_host *p)
  6591. {
  6592. /*
  6593. * Make sure the SEEPROM is ready before we release it.
  6594. */
  6595. CLOCK_PULSE(p);
  6596. aic_outb(p, 0, SEECTL);
  6597. }
  6598. /*+F*************************************************************************
  6599. * Function:
  6600. * read_seeprom
  6601. *
  6602. * Description:
  6603. * Reads the serial EEPROM and returns 1 if successful and 0 if
  6604. * not successful.
  6605. *
  6606. * The instruction set of the 93C46/56/66 chips is as follows:
  6607. *
  6608. * Start OP
  6609. * Function Bit Code Address Data Description
  6610. * -------------------------------------------------------------------
  6611. * READ 1 10 A5 - A0 Reads data stored in memory,
  6612. * starting at specified address
  6613. * EWEN 1 00 11XXXX Write enable must precede
  6614. * all programming modes
  6615. * ERASE 1 11 A5 - A0 Erase register A5A4A3A2A1A0
  6616. * WRITE 1 01 A5 - A0 D15 - D0 Writes register
  6617. * ERAL 1 00 10XXXX Erase all registers
  6618. * WRAL 1 00 01XXXX D15 - D0 Writes to all registers
  6619. * EWDS 1 00 00XXXX Disables all programming
  6620. * instructions
  6621. * *Note: A value of X for address is a don't care condition.
  6622. * *Note: The 93C56 and 93C66 have 8 address bits.
  6623. *
  6624. *
  6625. * The 93C46 has a four wire interface: clock, chip select, data in, and
  6626. * data out. In order to perform one of the above functions, you need
  6627. * to enable the chip select for a clock period (typically a minimum of
  6628. * 1 usec, with the clock high and low a minimum of 750 and 250 nsec
  6629. * respectively. While the chip select remains high, you can clock in
  6630. * the instructions (above) starting with the start bit, followed by the
  6631. * OP code, Address, and Data (if needed). For the READ instruction, the
  6632. * requested 16-bit register contents is read from the data out line but
  6633. * is preceded by an initial zero (leading 0, followed by 16-bits, MSB
  6634. * first). The clock cycling from low to high initiates the next data
  6635. * bit to be sent from the chip.
  6636. *
  6637. * The 78xx interface to the 93C46 serial EEPROM is through the SEECTL
  6638. * register. After successful arbitration for the memory port, the
  6639. * SEECS bit of the SEECTL register is connected to the chip select.
  6640. * The SEECK, SEEDO, and SEEDI are connected to the clock, data out,
  6641. * and data in lines respectively. The SEERDY bit of SEECTL is useful
  6642. * in that it gives us an 800 nsec timer. After a write to the SEECTL
  6643. * register, the SEERDY goes high 800 nsec later. The one exception
  6644. * to this is when we first request access to the memory port. The
  6645. * SEERDY goes high to signify that access has been granted and, for
  6646. * this case, has no implied timing.
  6647. *-F*************************************************************************/
  6648. static int
  6649. read_seeprom(struct aic7xxx_host *p, int offset,
  6650. unsigned short *scarray, unsigned int len, seeprom_chip_type chip)
  6651. {
  6652. int i = 0, k;
  6653. unsigned char temp;
  6654. unsigned short checksum = 0;
  6655. struct seeprom_cmd {
  6656. unsigned char len;
  6657. unsigned char bits[3];
  6658. };
  6659. struct seeprom_cmd seeprom_read = {3, {1, 1, 0}};
  6660. /*
  6661. * Request access of the memory port.
  6662. */
  6663. if (acquire_seeprom(p) == 0)
  6664. {
  6665. return (0);
  6666. }
  6667. /*
  6668. * Read 'len' registers of the seeprom. For the 7870, the 93C46
  6669. * SEEPROM is a 1024-bit device with 64 16-bit registers but only
  6670. * the first 32 are used by Adaptec BIOS. Some adapters use the
  6671. * 93C56 SEEPROM which is a 2048-bit device. The loop will range
  6672. * from 0 to 'len' - 1.
  6673. */
  6674. for (k = 0; k < len; k++)
  6675. {
  6676. /*
  6677. * Send chip select for one clock cycle.
  6678. */
  6679. aic_outb(p, SEEMS | SEECK | SEECS, SEECTL);
  6680. CLOCK_PULSE(p);
  6681. /*
  6682. * Now we're ready to send the read command followed by the
  6683. * address of the 16-bit register we want to read.
  6684. */
  6685. for (i = 0; i < seeprom_read.len; i++)
  6686. {
  6687. temp = SEEMS | SEECS | (seeprom_read.bits[i] << 1);
  6688. aic_outb(p, temp, SEECTL);
  6689. CLOCK_PULSE(p);
  6690. temp = temp ^ SEECK;
  6691. aic_outb(p, temp, SEECTL);
  6692. CLOCK_PULSE(p);
  6693. }
  6694. /*
  6695. * Send the 6 or 8 bit address (MSB first, LSB last).
  6696. */
  6697. for (i = ((int) chip - 1); i >= 0; i--)
  6698. {
  6699. temp = k + offset;
  6700. temp = (temp >> i) & 1; /* Mask out all but lower bit. */
  6701. temp = SEEMS | SEECS | (temp << 1);
  6702. aic_outb(p, temp, SEECTL);
  6703. CLOCK_PULSE(p);
  6704. temp = temp ^ SEECK;
  6705. aic_outb(p, temp, SEECTL);
  6706. CLOCK_PULSE(p);
  6707. }
  6708. /*
  6709. * Now read the 16 bit register. An initial 0 precedes the
  6710. * register contents which begins with bit 15 (MSB) and ends
  6711. * with bit 0 (LSB). The initial 0 will be shifted off the
  6712. * top of our word as we let the loop run from 0 to 16.
  6713. */
  6714. for (i = 0; i <= 16; i++)
  6715. {
  6716. temp = SEEMS | SEECS;
  6717. aic_outb(p, temp, SEECTL);
  6718. CLOCK_PULSE(p);
  6719. temp = temp ^ SEECK;
  6720. scarray[k] = (scarray[k] << 1) | (aic_inb(p, SEECTL) & SEEDI);
  6721. aic_outb(p, temp, SEECTL);
  6722. CLOCK_PULSE(p);
  6723. }
  6724. /*
  6725. * The serial EEPROM should have a checksum in the last word.
  6726. * Keep a running checksum for all words read except for the
  6727. * last word. We'll verify the checksum after all words have
  6728. * been read.
  6729. */
  6730. if (k < (len - 1))
  6731. {
  6732. checksum = checksum + scarray[k];
  6733. }
  6734. /*
  6735. * Reset the chip select for the next command cycle.
  6736. */
  6737. aic_outb(p, SEEMS, SEECTL);
  6738. CLOCK_PULSE(p);
  6739. aic_outb(p, SEEMS | SEECK, SEECTL);
  6740. CLOCK_PULSE(p);
  6741. aic_outb(p, SEEMS, SEECTL);
  6742. CLOCK_PULSE(p);
  6743. }
  6744. /*
  6745. * Release access to the memory port and the serial EEPROM.
  6746. */
  6747. release_seeprom(p);
  6748. #if 0
  6749. printk("Computed checksum 0x%x, checksum read 0x%x\n",
  6750. checksum, scarray[len - 1]);
  6751. printk("Serial EEPROM:");
  6752. for (k = 0; k < len; k++)
  6753. {
  6754. if (((k % 8) == 0) && (k != 0))
  6755. {
  6756. printk("\n ");
  6757. }
  6758. printk(" 0x%x", scarray[k]);
  6759. }
  6760. printk("\n");
  6761. #endif
  6762. if ( (checksum != scarray[len - 1]) || (checksum == 0) )
  6763. {
  6764. return (0);
  6765. }
  6766. return (1);
  6767. }
  6768. /*+F*************************************************************************
  6769. * Function:
  6770. * read_brdctl
  6771. *
  6772. * Description:
  6773. * Reads the BRDCTL register.
  6774. *-F*************************************************************************/
  6775. static unsigned char
  6776. read_brdctl(struct aic7xxx_host *p)
  6777. {
  6778. unsigned char brdctl, value;
  6779. /*
  6780. * Make sure the SEEPROM is ready before we access it
  6781. */
  6782. CLOCK_PULSE(p);
  6783. if (p->features & AHC_ULTRA2)
  6784. {
  6785. brdctl = BRDRW_ULTRA2;
  6786. aic_outb(p, brdctl, BRDCTL);
  6787. CLOCK_PULSE(p);
  6788. value = aic_inb(p, BRDCTL);
  6789. CLOCK_PULSE(p);
  6790. return(value);
  6791. }
  6792. brdctl = BRDRW;
  6793. if ( !((p->chip & AHC_CHIPID_MASK) == AHC_AIC7895) ||
  6794. (p->flags & AHC_CHNLB) )
  6795. {
  6796. brdctl |= BRDCS;
  6797. }
  6798. aic_outb(p, brdctl, BRDCTL);
  6799. CLOCK_PULSE(p);
  6800. value = aic_inb(p, BRDCTL);
  6801. CLOCK_PULSE(p);
  6802. aic_outb(p, 0, BRDCTL);
  6803. CLOCK_PULSE(p);
  6804. return (value);
  6805. }
  6806. /*+F*************************************************************************
  6807. * Function:
  6808. * write_brdctl
  6809. *
  6810. * Description:
  6811. * Writes a value to the BRDCTL register.
  6812. *-F*************************************************************************/
  6813. static void
  6814. write_brdctl(struct aic7xxx_host *p, unsigned char value)
  6815. {
  6816. unsigned char brdctl;
  6817. /*
  6818. * Make sure the SEEPROM is ready before we access it
  6819. */
  6820. CLOCK_PULSE(p);
  6821. if (p->features & AHC_ULTRA2)
  6822. {
  6823. brdctl = value;
  6824. aic_outb(p, brdctl, BRDCTL);
  6825. CLOCK_PULSE(p);
  6826. brdctl |= BRDSTB_ULTRA2;
  6827. aic_outb(p, brdctl, BRDCTL);
  6828. CLOCK_PULSE(p);
  6829. brdctl &= ~BRDSTB_ULTRA2;
  6830. aic_outb(p, brdctl, BRDCTL);
  6831. CLOCK_PULSE(p);
  6832. read_brdctl(p);
  6833. CLOCK_PULSE(p);
  6834. }
  6835. else
  6836. {
  6837. brdctl = BRDSTB;
  6838. if ( !((p->chip & AHC_CHIPID_MASK) == AHC_AIC7895) ||
  6839. (p->flags & AHC_CHNLB) )
  6840. {
  6841. brdctl |= BRDCS;
  6842. }
  6843. brdctl = BRDSTB | BRDCS;
  6844. aic_outb(p, brdctl, BRDCTL);
  6845. CLOCK_PULSE(p);
  6846. brdctl |= value;
  6847. aic_outb(p, brdctl, BRDCTL);
  6848. CLOCK_PULSE(p);
  6849. brdctl &= ~BRDSTB;
  6850. aic_outb(p, brdctl, BRDCTL);
  6851. CLOCK_PULSE(p);
  6852. brdctl &= ~BRDCS;
  6853. aic_outb(p, brdctl, BRDCTL);
  6854. CLOCK_PULSE(p);
  6855. }
  6856. }
  6857. /*+F*************************************************************************
  6858. * Function:
  6859. * aic785x_cable_detect
  6860. *
  6861. * Description:
  6862. * Detect the cables that are present on aic785x class controller chips
  6863. *-F*************************************************************************/
  6864. static void
  6865. aic785x_cable_detect(struct aic7xxx_host *p, int *int_50,
  6866. int *ext_present, int *eeprom)
  6867. {
  6868. unsigned char brdctl;
  6869. aic_outb(p, BRDRW | BRDCS, BRDCTL);
  6870. CLOCK_PULSE(p);
  6871. aic_outb(p, 0, BRDCTL);
  6872. CLOCK_PULSE(p);
  6873. brdctl = aic_inb(p, BRDCTL);
  6874. CLOCK_PULSE(p);
  6875. *int_50 = !(brdctl & BRDDAT5);
  6876. *ext_present = !(brdctl & BRDDAT6);
  6877. *eeprom = (aic_inb(p, SPIOCAP) & EEPROM);
  6878. }
  6879. #undef CLOCK_PULSE
  6880. /*+F*************************************************************************
  6881. * Function:
  6882. * aic2940_uwpro_cable_detect
  6883. *
  6884. * Description:
  6885. * Detect the cables that are present on the 2940-UWPro cards
  6886. *
  6887. * NOTE: This function assumes the SEEPROM will have already been acquired
  6888. * prior to invocation of this function.
  6889. *-F*************************************************************************/
  6890. static void
  6891. aic2940_uwpro_wide_cable_detect(struct aic7xxx_host *p, int *int_68,
  6892. int *ext_68, int *eeprom)
  6893. {
  6894. unsigned char brdctl;
  6895. /*
  6896. * First read the status of our cables. Set the rom bank to
  6897. * 0 since the bank setting serves as a multiplexor for the
  6898. * cable detection logic. BRDDAT5 controls the bank switch.
  6899. */
  6900. write_brdctl(p, 0);
  6901. /*
  6902. * Now we read the state of the internal 68 connector. BRDDAT6
  6903. * is don't care, BRDDAT7 is internal 68. The cable is
  6904. * present if the bit is 0
  6905. */
  6906. brdctl = read_brdctl(p);
  6907. *int_68 = !(brdctl & BRDDAT7);
  6908. /*
  6909. * Set the bank bit in brdctl and then read the external cable state
  6910. * and the EEPROM status
  6911. */
  6912. write_brdctl(p, BRDDAT5);
  6913. brdctl = read_brdctl(p);
  6914. *ext_68 = !(brdctl & BRDDAT6);
  6915. *eeprom = !(brdctl & BRDDAT7);
  6916. /*
  6917. * We're done, the calling function will release the SEEPROM for us
  6918. */
  6919. }
  6920. /*+F*************************************************************************
  6921. * Function:
  6922. * aic787x_cable_detect
  6923. *
  6924. * Description:
  6925. * Detect the cables that are present on aic787x class controller chips
  6926. *
  6927. * NOTE: This function assumes the SEEPROM will have already been acquired
  6928. * prior to invocation of this function.
  6929. *-F*************************************************************************/
  6930. static void
  6931. aic787x_cable_detect(struct aic7xxx_host *p, int *int_50, int *int_68,
  6932. int *ext_present, int *eeprom)
  6933. {
  6934. unsigned char brdctl;
  6935. /*
  6936. * First read the status of our cables. Set the rom bank to
  6937. * 0 since the bank setting serves as a multiplexor for the
  6938. * cable detection logic. BRDDAT5 controls the bank switch.
  6939. */
  6940. write_brdctl(p, 0);
  6941. /*
  6942. * Now we read the state of the two internal connectors. BRDDAT6
  6943. * is internal 50, BRDDAT7 is internal 68. For each, the cable is
  6944. * present if the bit is 0
  6945. */
  6946. brdctl = read_brdctl(p);
  6947. *int_50 = !(brdctl & BRDDAT6);
  6948. *int_68 = !(brdctl & BRDDAT7);
  6949. /*
  6950. * Set the bank bit in brdctl and then read the external cable state
  6951. * and the EEPROM status
  6952. */
  6953. write_brdctl(p, BRDDAT5);
  6954. brdctl = read_brdctl(p);
  6955. *ext_present = !(brdctl & BRDDAT6);
  6956. *eeprom = !(brdctl & BRDDAT7);
  6957. /*
  6958. * We're done, the calling function will release the SEEPROM for us
  6959. */
  6960. }
  6961. /*+F*************************************************************************
  6962. * Function:
  6963. * aic787x_ultra2_term_detect
  6964. *
  6965. * Description:
  6966. * Detect the termination settings present on ultra2 class controllers
  6967. *
  6968. * NOTE: This function assumes the SEEPROM will have already been acquired
  6969. * prior to invocation of this function.
  6970. *-F*************************************************************************/
  6971. static void
  6972. aic7xxx_ultra2_term_detect(struct aic7xxx_host *p, int *enableSE_low,
  6973. int *enableSE_high, int *enableLVD_low,
  6974. int *enableLVD_high, int *eprom_present)
  6975. {
  6976. unsigned char brdctl;
  6977. brdctl = read_brdctl(p);
  6978. *eprom_present = (brdctl & BRDDAT7);
  6979. *enableSE_high = (brdctl & BRDDAT6);
  6980. *enableSE_low = (brdctl & BRDDAT5);
  6981. *enableLVD_high = (brdctl & BRDDAT4);
  6982. *enableLVD_low = (brdctl & BRDDAT3);
  6983. }
  6984. /*+F*************************************************************************
  6985. * Function:
  6986. * configure_termination
  6987. *
  6988. * Description:
  6989. * Configures the termination settings on PCI adapters that have
  6990. * SEEPROMs available.
  6991. *-F*************************************************************************/
  6992. static void
  6993. configure_termination(struct aic7xxx_host *p)
  6994. {
  6995. int internal50_present = 0;
  6996. int internal68_present = 0;
  6997. int external_present = 0;
  6998. int eprom_present = 0;
  6999. int enableSE_low = 0;
  7000. int enableSE_high = 0;
  7001. int enableLVD_low = 0;
  7002. int enableLVD_high = 0;
  7003. unsigned char brddat = 0;
  7004. unsigned char max_target = 0;
  7005. unsigned char sxfrctl1 = aic_inb(p, SXFRCTL1);
  7006. if (acquire_seeprom(p))
  7007. {
  7008. if (p->features & (AHC_WIDE|AHC_TWIN))
  7009. max_target = 16;
  7010. else
  7011. max_target = 8;
  7012. aic_outb(p, SEEMS | SEECS, SEECTL);
  7013. sxfrctl1 &= ~STPWEN;
  7014. /*
  7015. * The termination/cable detection logic is split into three distinct
  7016. * groups. Ultra2 and later controllers, 2940UW-Pro controllers, and
  7017. * older 7850, 7860, 7870, 7880, and 7895 controllers. Each has its
  7018. * own unique way of detecting their cables and writing the results
  7019. * back to the card.
  7020. */
  7021. if (p->features & AHC_ULTRA2)
  7022. {
  7023. /*
  7024. * As long as user hasn't overridden term settings, always check the
  7025. * cable detection logic
  7026. */
  7027. if (aic7xxx_override_term == -1)
  7028. {
  7029. aic7xxx_ultra2_term_detect(p, &enableSE_low, &enableSE_high,
  7030. &enableLVD_low, &enableLVD_high,
  7031. &eprom_present);
  7032. }
  7033. /*
  7034. * If the user is overriding settings, then they have been preserved
  7035. * to here as fake adapter_control entries. Parse them and allow
  7036. * them to override the detected settings (if we even did detection).
  7037. */
  7038. if (!(p->adapter_control & CFSEAUTOTERM))
  7039. {
  7040. enableSE_low = (p->adapter_control & CFSTERM);
  7041. enableSE_high = (p->adapter_control & CFWSTERM);
  7042. }
  7043. if (!(p->adapter_control & CFAUTOTERM))
  7044. {
  7045. enableLVD_low = enableLVD_high = (p->adapter_control & CFLVDSTERM);
  7046. }
  7047. /*
  7048. * Now take those settings that we have and translate them into the
  7049. * values that must be written into the registers.
  7050. *
  7051. * Flash Enable = BRDDAT7
  7052. * Secondary High Term Enable = BRDDAT6
  7053. * Secondary Low Term Enable = BRDDAT5
  7054. * LVD/Primary High Term Enable = BRDDAT4
  7055. * LVD/Primary Low Term Enable = STPWEN bit in SXFRCTL1
  7056. */
  7057. if (enableLVD_low != 0)
  7058. {
  7059. sxfrctl1 |= STPWEN;
  7060. p->flags |= AHC_TERM_ENB_LVD;
  7061. if (aic7xxx_verbose & VERBOSE_PROBE2)
  7062. printk(KERN_INFO "(scsi%d) LVD/Primary Low byte termination "
  7063. "Enabled\n", p->host_no);
  7064. }
  7065. if (enableLVD_high != 0)
  7066. {
  7067. brddat |= BRDDAT4;
  7068. if (aic7xxx_verbose & VERBOSE_PROBE2)
  7069. printk(KERN_INFO "(scsi%d) LVD/Primary High byte termination "
  7070. "Enabled\n", p->host_no);
  7071. }
  7072. if (enableSE_low != 0)
  7073. {
  7074. brddat |= BRDDAT5;
  7075. if (aic7xxx_verbose & VERBOSE_PROBE2)
  7076. printk(KERN_INFO "(scsi%d) Secondary Low byte termination "
  7077. "Enabled\n", p->host_no);
  7078. }
  7079. if (enableSE_high != 0)
  7080. {
  7081. brddat |= BRDDAT6;
  7082. if (aic7xxx_verbose & VERBOSE_PROBE2)
  7083. printk(KERN_INFO "(scsi%d) Secondary High byte termination "
  7084. "Enabled\n", p->host_no);
  7085. }
  7086. }
  7087. else if (p->features & AHC_NEW_AUTOTERM)
  7088. {
  7089. /*
  7090. * The 50 pin connector termination is controlled by STPWEN in the
  7091. * SXFRCTL1 register. Since the Adaptec docs typically say the
  7092. * controller is not allowed to be in the middle of a cable and
  7093. * this is the only connection on that stub of the bus, there is
  7094. * no need to even check for narrow termination, it's simply
  7095. * always on.
  7096. */
  7097. sxfrctl1 |= STPWEN;
  7098. if (aic7xxx_verbose & VERBOSE_PROBE2)
  7099. printk(KERN_INFO "(scsi%d) Narrow channel termination Enabled\n",
  7100. p->host_no);
  7101. if (p->adapter_control & CFAUTOTERM)
  7102. {
  7103. aic2940_uwpro_wide_cable_detect(p, &internal68_present,
  7104. &external_present,
  7105. &eprom_present);
  7106. printk(KERN_INFO "(scsi%d) Cables present (Int-50 %s, Int-68 %s, "
  7107. "Ext-68 %s)\n", p->host_no,
  7108. "Don't Care",
  7109. internal68_present ? "YES" : "NO",
  7110. external_present ? "YES" : "NO");
  7111. if (aic7xxx_verbose & VERBOSE_PROBE2)
  7112. printk(KERN_INFO "(scsi%d) EEPROM %s present.\n", p->host_no,
  7113. eprom_present ? "is" : "is not");
  7114. if (internal68_present && external_present)
  7115. {
  7116. brddat = 0;
  7117. p->flags &= ~AHC_TERM_ENB_SE_HIGH;
  7118. if (aic7xxx_verbose & VERBOSE_PROBE2)
  7119. printk(KERN_INFO "(scsi%d) Wide channel termination Disabled\n",
  7120. p->host_no);
  7121. }
  7122. else
  7123. {
  7124. brddat = BRDDAT6;
  7125. p->flags |= AHC_TERM_ENB_SE_HIGH;
  7126. if (aic7xxx_verbose & VERBOSE_PROBE2)
  7127. printk(KERN_INFO "(scsi%d) Wide channel termination Enabled\n",
  7128. p->host_no);
  7129. }
  7130. }
  7131. else
  7132. {
  7133. /*
  7134. * The termination of the Wide channel is done more like normal
  7135. * though, and the setting of this termination is done by writing
  7136. * either a 0 or 1 to BRDDAT6 of the BRDDAT register
  7137. */
  7138. if (p->adapter_control & CFWSTERM)
  7139. {
  7140. brddat = BRDDAT6;
  7141. p->flags |= AHC_TERM_ENB_SE_HIGH;
  7142. if (aic7xxx_verbose & VERBOSE_PROBE2)
  7143. printk(KERN_INFO "(scsi%d) Wide channel termination Enabled\n",
  7144. p->host_no);
  7145. }
  7146. else
  7147. {
  7148. brddat = 0;
  7149. }
  7150. }
  7151. }
  7152. else
  7153. {
  7154. if (p->adapter_control & CFAUTOTERM)
  7155. {
  7156. if (p->flags & AHC_MOTHERBOARD)
  7157. {
  7158. printk(KERN_INFO "(scsi%d) Warning - detected auto-termination\n",
  7159. p->host_no);
  7160. printk(KERN_INFO "(scsi%d) Please verify driver detected settings "
  7161. "are correct.\n", p->host_no);
  7162. printk(KERN_INFO "(scsi%d) If not, then please properly set the "
  7163. "device termination\n", p->host_no);
  7164. printk(KERN_INFO "(scsi%d) in the Adaptec SCSI BIOS by hitting "
  7165. "CTRL-A when prompted\n", p->host_no);
  7166. printk(KERN_INFO "(scsi%d) during machine bootup.\n", p->host_no);
  7167. }
  7168. /* Configure auto termination. */
  7169. if ( (p->chip & AHC_CHIPID_MASK) >= AHC_AIC7870 )
  7170. {
  7171. aic787x_cable_detect(p, &internal50_present, &internal68_present,
  7172. &external_present, &eprom_present);
  7173. }
  7174. else
  7175. {
  7176. aic785x_cable_detect(p, &internal50_present, &external_present,
  7177. &eprom_present);
  7178. }
  7179. if (max_target <= 8)
  7180. internal68_present = 0;
  7181. if (max_target > 8)
  7182. {
  7183. printk(KERN_INFO "(scsi%d) Cables present (Int-50 %s, Int-68 %s, "
  7184. "Ext-68 %s)\n", p->host_no,
  7185. internal50_present ? "YES" : "NO",
  7186. internal68_present ? "YES" : "NO",
  7187. external_present ? "YES" : "NO");
  7188. }
  7189. else
  7190. {
  7191. printk(KERN_INFO "(scsi%d) Cables present (Int-50 %s, Ext-50 %s)\n",
  7192. p->host_no,
  7193. internal50_present ? "YES" : "NO",
  7194. external_present ? "YES" : "NO");
  7195. }
  7196. if (aic7xxx_verbose & VERBOSE_PROBE2)
  7197. printk(KERN_INFO "(scsi%d) EEPROM %s present.\n", p->host_no,
  7198. eprom_present ? "is" : "is not");
  7199. /*
  7200. * Now set the termination based on what we found. BRDDAT6
  7201. * controls wide termination enable.
  7202. * Flash Enable = BRDDAT7
  7203. * SE High Term Enable = BRDDAT6
  7204. */
  7205. if (internal50_present && internal68_present && external_present)
  7206. {
  7207. printk(KERN_INFO "(scsi%d) Illegal cable configuration!! Only two\n",
  7208. p->host_no);
  7209. printk(KERN_INFO "(scsi%d) connectors on the SCSI controller may be "
  7210. "in use at a time!\n", p->host_no);
  7211. /*
  7212. * Force termination (low and high byte) on. This is safer than
  7213. * leaving it completely off, especially since this message comes
  7214. * most often from motherboard controllers that don't even have 3
  7215. * connectors, but instead are failing the cable detection.
  7216. */
  7217. internal50_present = external_present = 0;
  7218. enableSE_high = enableSE_low = 1;
  7219. }
  7220. if ((max_target > 8) &&
  7221. ((external_present == 0) || (internal68_present == 0)) )
  7222. {
  7223. brddat |= BRDDAT6;
  7224. p->flags |= AHC_TERM_ENB_SE_HIGH;
  7225. if (aic7xxx_verbose & VERBOSE_PROBE2)
  7226. printk(KERN_INFO "(scsi%d) SE High byte termination Enabled\n",
  7227. p->host_no);
  7228. }
  7229. if ( ((internal50_present ? 1 : 0) +
  7230. (internal68_present ? 1 : 0) +
  7231. (external_present ? 1 : 0)) <= 1 )
  7232. {
  7233. sxfrctl1 |= STPWEN;
  7234. p->flags |= AHC_TERM_ENB_SE_LOW;
  7235. if (aic7xxx_verbose & VERBOSE_PROBE2)
  7236. printk(KERN_INFO "(scsi%d) SE Low byte termination Enabled\n",
  7237. p->host_no);
  7238. }
  7239. }
  7240. else /* p->adapter_control & CFAUTOTERM */
  7241. {
  7242. if (p->adapter_control & CFSTERM)
  7243. {
  7244. sxfrctl1 |= STPWEN;
  7245. if (aic7xxx_verbose & VERBOSE_PROBE2)
  7246. printk(KERN_INFO "(scsi%d) SE Low byte termination Enabled\n",
  7247. p->host_no);
  7248. }
  7249. if (p->adapter_control & CFWSTERM)
  7250. {
  7251. brddat |= BRDDAT6;
  7252. if (aic7xxx_verbose & VERBOSE_PROBE2)
  7253. printk(KERN_INFO "(scsi%d) SE High byte termination Enabled\n",
  7254. p->host_no);
  7255. }
  7256. }
  7257. }
  7258. aic_outb(p, sxfrctl1, SXFRCTL1);
  7259. write_brdctl(p, brddat);
  7260. release_seeprom(p);
  7261. }
  7262. }
  7263. /*+F*************************************************************************
  7264. * Function:
  7265. * detect_maxscb
  7266. *
  7267. * Description:
  7268. * Detects the maximum number of SCBs for the controller and returns
  7269. * the count and a mask in p (p->maxscbs, p->qcntmask).
  7270. *-F*************************************************************************/
  7271. static void
  7272. detect_maxscb(struct aic7xxx_host *p)
  7273. {
  7274. int i;
  7275. /*
  7276. * It's possible that we've already done this for multichannel
  7277. * adapters.
  7278. */
  7279. if (p->scb_data->maxhscbs == 0)
  7280. {
  7281. /*
  7282. * We haven't initialized the SCB settings yet. Walk the SCBs to
  7283. * determince how many there are.
  7284. */
  7285. aic_outb(p, 0, FREE_SCBH);
  7286. for (i = 0; i < AIC7XXX_MAXSCB; i++)
  7287. {
  7288. aic_outb(p, i, SCBPTR);
  7289. aic_outb(p, i, SCB_CONTROL);
  7290. if (aic_inb(p, SCB_CONTROL) != i)
  7291. break;
  7292. aic_outb(p, 0, SCBPTR);
  7293. if (aic_inb(p, SCB_CONTROL) != 0)
  7294. break;
  7295. aic_outb(p, i, SCBPTR);
  7296. aic_outb(p, 0, SCB_CONTROL); /* Clear the control byte. */
  7297. aic_outb(p, i + 1, SCB_NEXT); /* Set the next pointer. */
  7298. aic_outb(p, SCB_LIST_NULL, SCB_TAG); /* Make the tag invalid. */
  7299. aic_outb(p, SCB_LIST_NULL, SCB_BUSYTARGETS); /* no busy untagged */
  7300. aic_outb(p, SCB_LIST_NULL, SCB_BUSYTARGETS+1);/* targets active yet */
  7301. aic_outb(p, SCB_LIST_NULL, SCB_BUSYTARGETS+2);
  7302. aic_outb(p, SCB_LIST_NULL, SCB_BUSYTARGETS+3);
  7303. }
  7304. /* Make sure the last SCB terminates the free list. */
  7305. aic_outb(p, i - 1, SCBPTR);
  7306. aic_outb(p, SCB_LIST_NULL, SCB_NEXT);
  7307. /* Ensure we clear the first (0) SCBs control byte. */
  7308. aic_outb(p, 0, SCBPTR);
  7309. aic_outb(p, 0, SCB_CONTROL);
  7310. p->scb_data->maxhscbs = i;
  7311. /*
  7312. * Use direct indexing instead for speed
  7313. */
  7314. if ( i == AIC7XXX_MAXSCB )
  7315. p->flags &= ~AHC_PAGESCBS;
  7316. }
  7317. }
  7318. /*+F*************************************************************************
  7319. * Function:
  7320. * aic7xxx_register
  7321. *
  7322. * Description:
  7323. * Register a Adaptec aic7xxx chip SCSI controller with the kernel.
  7324. *-F*************************************************************************/
  7325. static int
  7326. aic7xxx_register(struct scsi_host_template *template, struct aic7xxx_host *p,
  7327. int reset_delay)
  7328. {
  7329. int i, result;
  7330. int max_targets;
  7331. int found = 1;
  7332. unsigned char term, scsi_conf;
  7333. struct Scsi_Host *host;
  7334. host = p->host;
  7335. p->scb_data->maxscbs = AIC7XXX_MAXSCB;
  7336. host->can_queue = AIC7XXX_MAXSCB;
  7337. host->cmd_per_lun = 3;
  7338. host->sg_tablesize = AIC7XXX_MAX_SG;
  7339. host->this_id = p->scsi_id;
  7340. host->io_port = p->base;
  7341. host->n_io_port = 0xFF;
  7342. host->base = p->mbase;
  7343. host->irq = p->irq;
  7344. if (p->features & AHC_WIDE)
  7345. {
  7346. host->max_id = 16;
  7347. }
  7348. if (p->features & AHC_TWIN)
  7349. {
  7350. host->max_channel = 1;
  7351. }
  7352. p->host = host;
  7353. p->host_no = host->host_no;
  7354. host->unique_id = p->instance;
  7355. p->isr_count = 0;
  7356. p->next = NULL;
  7357. p->completeq.head = NULL;
  7358. p->completeq.tail = NULL;
  7359. scbq_init(&p->scb_data->free_scbs);
  7360. scbq_init(&p->waiting_scbs);
  7361. INIT_LIST_HEAD(&p->aic_devs);
  7362. /*
  7363. * We currently have no commands of any type
  7364. */
  7365. p->qinfifonext = 0;
  7366. p->qoutfifonext = 0;
  7367. printk(KERN_INFO "(scsi%d) <%s> found at ", p->host_no,
  7368. board_names[p->board_name_index]);
  7369. switch(p->chip)
  7370. {
  7371. case (AHC_AIC7770|AHC_EISA):
  7372. printk("EISA slot %d\n", p->pci_device_fn);
  7373. break;
  7374. case (AHC_AIC7770|AHC_VL):
  7375. printk("VLB slot %d\n", p->pci_device_fn);
  7376. break;
  7377. default:
  7378. printk("PCI %d/%d/%d\n", p->pci_bus, PCI_SLOT(p->pci_device_fn),
  7379. PCI_FUNC(p->pci_device_fn));
  7380. break;
  7381. }
  7382. if (p->features & AHC_TWIN)
  7383. {
  7384. printk(KERN_INFO "(scsi%d) Twin Channel, A SCSI ID %d, B SCSI ID %d, ",
  7385. p->host_no, p->scsi_id, p->scsi_id_b);
  7386. }
  7387. else
  7388. {
  7389. char *channel;
  7390. channel = "";
  7391. if ((p->flags & AHC_MULTI_CHANNEL) != 0)
  7392. {
  7393. channel = " A";
  7394. if ( (p->flags & (AHC_CHNLB|AHC_CHNLC)) != 0 )
  7395. {
  7396. channel = (p->flags & AHC_CHNLB) ? " B" : " C";
  7397. }
  7398. }
  7399. if (p->features & AHC_WIDE)
  7400. {
  7401. printk(KERN_INFO "(scsi%d) Wide ", p->host_no);
  7402. }
  7403. else
  7404. {
  7405. printk(KERN_INFO "(scsi%d) Narrow ", p->host_no);
  7406. }
  7407. printk("Channel%s, SCSI ID=%d, ", channel, p->scsi_id);
  7408. }
  7409. aic_outb(p, 0, SEQ_FLAGS);
  7410. detect_maxscb(p);
  7411. printk("%d/%d SCBs\n", p->scb_data->maxhscbs, p->scb_data->maxscbs);
  7412. if (aic7xxx_verbose & VERBOSE_PROBE2)
  7413. {
  7414. printk(KERN_INFO "(scsi%d) BIOS %sabled, IO Port 0x%lx, IRQ %d\n",
  7415. p->host_no, (p->flags & AHC_BIOS_ENABLED) ? "en" : "dis",
  7416. p->base, p->irq);
  7417. printk(KERN_INFO "(scsi%d) IO Memory at 0x%lx, MMAP Memory at %p\n",
  7418. p->host_no, p->mbase, p->maddr);
  7419. }
  7420. #ifdef CONFIG_PCI
  7421. /*
  7422. * Now that we know our instance number, we can set the flags we need to
  7423. * force termination if need be.
  7424. */
  7425. if (aic7xxx_stpwlev != -1)
  7426. {
  7427. /*
  7428. * This option only applies to PCI controllers.
  7429. */
  7430. if ( (p->chip & ~AHC_CHIPID_MASK) == AHC_PCI)
  7431. {
  7432. unsigned char devconfig;
  7433. pci_read_config_byte(p->pdev, DEVCONFIG, &devconfig);
  7434. if ( (aic7xxx_stpwlev >> p->instance) & 0x01 )
  7435. {
  7436. devconfig |= STPWLEVEL;
  7437. if (aic7xxx_verbose & VERBOSE_PROBE2)
  7438. printk("(scsi%d) Force setting STPWLEVEL bit\n", p->host_no);
  7439. }
  7440. else
  7441. {
  7442. devconfig &= ~STPWLEVEL;
  7443. if (aic7xxx_verbose & VERBOSE_PROBE2)
  7444. printk("(scsi%d) Force clearing STPWLEVEL bit\n", p->host_no);
  7445. }
  7446. pci_write_config_byte(p->pdev, DEVCONFIG, devconfig);
  7447. }
  7448. }
  7449. #endif
  7450. /*
  7451. * That took care of devconfig and stpwlev, now for the actual termination
  7452. * settings.
  7453. */
  7454. if (aic7xxx_override_term != -1)
  7455. {
  7456. /*
  7457. * Again, this only applies to PCI controllers. We don't have problems
  7458. * with the termination on 274x controllers to the best of my knowledge.
  7459. */
  7460. if ( (p->chip & ~AHC_CHIPID_MASK) == AHC_PCI)
  7461. {
  7462. unsigned char term_override;
  7463. term_override = ( (aic7xxx_override_term >> (p->instance * 4)) & 0x0f);
  7464. p->adapter_control &=
  7465. ~(CFSTERM|CFWSTERM|CFLVDSTERM|CFAUTOTERM|CFSEAUTOTERM);
  7466. if ( (p->features & AHC_ULTRA2) && (term_override & 0x0c) )
  7467. {
  7468. p->adapter_control |= CFLVDSTERM;
  7469. }
  7470. if (term_override & 0x02)
  7471. {
  7472. p->adapter_control |= CFWSTERM;
  7473. }
  7474. if (term_override & 0x01)
  7475. {
  7476. p->adapter_control |= CFSTERM;
  7477. }
  7478. }
  7479. }
  7480. if ( (p->flags & AHC_SEEPROM_FOUND) || (aic7xxx_override_term != -1) )
  7481. {
  7482. if (p->features & AHC_SPIOCAP)
  7483. {
  7484. if ( aic_inb(p, SPIOCAP) & SSPIOCPS )
  7485. /*
  7486. * Update the settings in sxfrctl1 to match the termination
  7487. * settings.
  7488. */
  7489. configure_termination(p);
  7490. }
  7491. else if ((p->chip & AHC_CHIPID_MASK) >= AHC_AIC7870)
  7492. {
  7493. configure_termination(p);
  7494. }
  7495. }
  7496. /*
  7497. * Set the SCSI Id, SXFRCTL0, SXFRCTL1, and SIMODE1, for both channels
  7498. */
  7499. if (p->features & AHC_TWIN)
  7500. {
  7501. /* Select channel B */
  7502. aic_outb(p, aic_inb(p, SBLKCTL) | SELBUSB, SBLKCTL);
  7503. if ((p->flags & AHC_SEEPROM_FOUND) || (aic7xxx_override_term != -1))
  7504. term = (aic_inb(p, SXFRCTL1) & STPWEN);
  7505. else
  7506. term = ((p->flags & AHC_TERM_ENB_B) ? STPWEN : 0);
  7507. aic_outb(p, p->scsi_id_b, SCSIID);
  7508. scsi_conf = aic_inb(p, SCSICONF + 1);
  7509. aic_outb(p, DFON | SPIOEN, SXFRCTL0);
  7510. aic_outb(p, (scsi_conf & ENSPCHK) | aic7xxx_seltime | term |
  7511. ENSTIMER | ACTNEGEN, SXFRCTL1);
  7512. aic_outb(p, 0, SIMODE0);
  7513. aic_outb(p, ENSELTIMO | ENSCSIRST | ENSCSIPERR, SIMODE1);
  7514. aic_outb(p, 0, SCSIRATE);
  7515. /* Select channel A */
  7516. aic_outb(p, aic_inb(p, SBLKCTL) & ~SELBUSB, SBLKCTL);
  7517. }
  7518. if (p->features & AHC_ULTRA2)
  7519. {
  7520. aic_outb(p, p->scsi_id, SCSIID_ULTRA2);
  7521. }
  7522. else
  7523. {
  7524. aic_outb(p, p->scsi_id, SCSIID);
  7525. }
  7526. if ((p->flags & AHC_SEEPROM_FOUND) || (aic7xxx_override_term != -1))
  7527. term = (aic_inb(p, SXFRCTL1) & STPWEN);
  7528. else
  7529. term = ((p->flags & (AHC_TERM_ENB_A|AHC_TERM_ENB_LVD)) ? STPWEN : 0);
  7530. scsi_conf = aic_inb(p, SCSICONF);
  7531. aic_outb(p, DFON | SPIOEN, SXFRCTL0);
  7532. aic_outb(p, (scsi_conf & ENSPCHK) | aic7xxx_seltime | term |
  7533. ENSTIMER | ACTNEGEN, SXFRCTL1);
  7534. aic_outb(p, 0, SIMODE0);
  7535. /*
  7536. * If we are a cardbus adapter then don't enable SCSI reset detection.
  7537. * We shouldn't likely be sharing SCSI busses with someone else, and
  7538. * if we don't have a cable currently plugged into the controller then
  7539. * we won't have a power source for the SCSI termination, which means
  7540. * we'll see infinite incoming bus resets.
  7541. */
  7542. if(p->flags & AHC_NO_STPWEN)
  7543. aic_outb(p, ENSELTIMO | ENSCSIPERR, SIMODE1);
  7544. else
  7545. aic_outb(p, ENSELTIMO | ENSCSIRST | ENSCSIPERR, SIMODE1);
  7546. aic_outb(p, 0, SCSIRATE);
  7547. if ( p->features & AHC_ULTRA2)
  7548. aic_outb(p, 0, SCSIOFFSET);
  7549. /*
  7550. * Look at the information that board initialization or the board
  7551. * BIOS has left us. In the lower four bits of each target's
  7552. * scratch space any value other than 0 indicates that we should
  7553. * initiate synchronous transfers. If it's zero, the user or the
  7554. * BIOS has decided to disable synchronous negotiation to that
  7555. * target so we don't activate the needsdtr flag.
  7556. */
  7557. if ((p->features & (AHC_TWIN|AHC_WIDE)) == 0)
  7558. {
  7559. max_targets = 8;
  7560. }
  7561. else
  7562. {
  7563. max_targets = 16;
  7564. }
  7565. if (!(aic7xxx_no_reset))
  7566. {
  7567. /*
  7568. * If we reset the bus, then clear the transfer settings, else leave
  7569. * them be.
  7570. */
  7571. aic_outb(p, 0, ULTRA_ENB);
  7572. aic_outb(p, 0, ULTRA_ENB + 1);
  7573. p->ultraenb = 0;
  7574. }
  7575. /*
  7576. * Allocate enough hardware scbs to handle the maximum number of
  7577. * concurrent transactions we can have. We have to make sure that
  7578. * the allocated memory is contiguous memory. The Linux kmalloc
  7579. * routine should only allocate contiguous memory, but note that
  7580. * this could be a problem if kmalloc() is changed.
  7581. */
  7582. {
  7583. size_t array_size;
  7584. unsigned int hscb_physaddr;
  7585. array_size = p->scb_data->maxscbs * sizeof(struct aic7xxx_hwscb);
  7586. if (p->scb_data->hscbs == NULL)
  7587. {
  7588. /* pci_alloc_consistent enforces the alignment already and
  7589. * clears the area as well.
  7590. */
  7591. p->scb_data->hscbs = pci_alloc_consistent(p->pdev, array_size,
  7592. &p->scb_data->hscbs_dma);
  7593. /* We have to use pci_free_consistent, not kfree */
  7594. p->scb_data->hscb_kmalloc_ptr = NULL;
  7595. p->scb_data->hscbs_dma_len = array_size;
  7596. }
  7597. if (p->scb_data->hscbs == NULL)
  7598. {
  7599. printk("(scsi%d) Unable to allocate hardware SCB array; "
  7600. "failing detection.\n", p->host_no);
  7601. aic_outb(p, 0, SIMODE1);
  7602. p->irq = 0;
  7603. return(0);
  7604. }
  7605. hscb_physaddr = p->scb_data->hscbs_dma;
  7606. aic_outb(p, hscb_physaddr & 0xFF, HSCB_ADDR);
  7607. aic_outb(p, (hscb_physaddr >> 8) & 0xFF, HSCB_ADDR + 1);
  7608. aic_outb(p, (hscb_physaddr >> 16) & 0xFF, HSCB_ADDR + 2);
  7609. aic_outb(p, (hscb_physaddr >> 24) & 0xFF, HSCB_ADDR + 3);
  7610. /* Set up the fifo areas at the same time */
  7611. p->untagged_scbs = pci_alloc_consistent(p->pdev, 3*256, &p->fifo_dma);
  7612. if (p->untagged_scbs == NULL)
  7613. {
  7614. printk("(scsi%d) Unable to allocate hardware FIFO arrays; "
  7615. "failing detection.\n", p->host_no);
  7616. p->irq = 0;
  7617. return(0);
  7618. }
  7619. p->qoutfifo = p->untagged_scbs + 256;
  7620. p->qinfifo = p->qoutfifo + 256;
  7621. for (i = 0; i < 256; i++)
  7622. {
  7623. p->untagged_scbs[i] = SCB_LIST_NULL;
  7624. p->qinfifo[i] = SCB_LIST_NULL;
  7625. p->qoutfifo[i] = SCB_LIST_NULL;
  7626. }
  7627. hscb_physaddr = p->fifo_dma;
  7628. aic_outb(p, hscb_physaddr & 0xFF, SCBID_ADDR);
  7629. aic_outb(p, (hscb_physaddr >> 8) & 0xFF, SCBID_ADDR + 1);
  7630. aic_outb(p, (hscb_physaddr >> 16) & 0xFF, SCBID_ADDR + 2);
  7631. aic_outb(p, (hscb_physaddr >> 24) & 0xFF, SCBID_ADDR + 3);
  7632. }
  7633. /* The Q-FIFOs we just set up are all empty */
  7634. aic_outb(p, 0, QINPOS);
  7635. aic_outb(p, 0, KERNEL_QINPOS);
  7636. aic_outb(p, 0, QOUTPOS);
  7637. if(p->features & AHC_QUEUE_REGS)
  7638. {
  7639. aic_outb(p, SCB_QSIZE_256, QOFF_CTLSTA);
  7640. aic_outb(p, 0, SDSCB_QOFF);
  7641. aic_outb(p, 0, SNSCB_QOFF);
  7642. aic_outb(p, 0, HNSCB_QOFF);
  7643. }
  7644. /*
  7645. * We don't have any waiting selections or disconnected SCBs.
  7646. */
  7647. aic_outb(p, SCB_LIST_NULL, WAITING_SCBH);
  7648. aic_outb(p, SCB_LIST_NULL, DISCONNECTED_SCBH);
  7649. /*
  7650. * Message out buffer starts empty
  7651. */
  7652. aic_outb(p, MSG_NOOP, MSG_OUT);
  7653. aic_outb(p, MSG_NOOP, LAST_MSG);
  7654. /*
  7655. * Set all the other asundry items that haven't been set yet.
  7656. * This includes just dumping init values to a lot of registers simply
  7657. * to make sure they've been touched and are ready for use parity wise
  7658. * speaking.
  7659. */
  7660. aic_outb(p, 0, TMODE_CMDADDR);
  7661. aic_outb(p, 0, TMODE_CMDADDR + 1);
  7662. aic_outb(p, 0, TMODE_CMDADDR + 2);
  7663. aic_outb(p, 0, TMODE_CMDADDR + 3);
  7664. aic_outb(p, 0, TMODE_CMDADDR_NEXT);
  7665. /*
  7666. * Link us into the list of valid hosts
  7667. */
  7668. p->next = first_aic7xxx;
  7669. first_aic7xxx = p;
  7670. /*
  7671. * Allocate the first set of scbs for this controller. This is to stream-
  7672. * line code elsewhere in the driver. If we have to check for the existence
  7673. * of scbs in certain code sections, it slows things down. However, as
  7674. * soon as we register the IRQ for this card, we could get an interrupt that
  7675. * includes possibly the SCSI_RSTI interrupt. If we catch that interrupt
  7676. * then we are likely to segfault if we don't have at least one chunk of
  7677. * SCBs allocated or add checks all through the reset code to make sure
  7678. * that the SCBs have been allocated which is an invalid running condition
  7679. * and therefore I think it's preferable to simply pre-allocate the first
  7680. * chunk of SCBs.
  7681. */
  7682. aic7xxx_allocate_scb(p);
  7683. /*
  7684. * Load the sequencer program, then re-enable the board -
  7685. * resetting the AIC-7770 disables it, leaving the lights
  7686. * on with nobody home.
  7687. */
  7688. aic7xxx_loadseq(p);
  7689. /*
  7690. * Make sure the AUTOFLUSHDIS bit is *not* set in the SBLKCTL register
  7691. */
  7692. aic_outb(p, aic_inb(p, SBLKCTL) & ~AUTOFLUSHDIS, SBLKCTL);
  7693. if ( (p->chip & AHC_CHIPID_MASK) == AHC_AIC7770 )
  7694. {
  7695. aic_outb(p, ENABLE, BCTL); /* Enable the boards BUS drivers. */
  7696. }
  7697. if ( !(aic7xxx_no_reset) )
  7698. {
  7699. if (p->features & AHC_TWIN)
  7700. {
  7701. if (aic7xxx_verbose & VERBOSE_PROBE2)
  7702. printk(KERN_INFO "(scsi%d) Resetting channel B\n", p->host_no);
  7703. aic_outb(p, aic_inb(p, SBLKCTL) | SELBUSB, SBLKCTL);
  7704. aic7xxx_reset_current_bus(p);
  7705. aic_outb(p, aic_inb(p, SBLKCTL) & ~SELBUSB, SBLKCTL);
  7706. }
  7707. /* Reset SCSI bus A. */
  7708. if (aic7xxx_verbose & VERBOSE_PROBE2)
  7709. { /* In case we are a 3940, 3985, or 7895, print the right channel */
  7710. char *channel = "";
  7711. if (p->flags & AHC_MULTI_CHANNEL)
  7712. {
  7713. channel = " A";
  7714. if (p->flags & (AHC_CHNLB|AHC_CHNLC))
  7715. channel = (p->flags & AHC_CHNLB) ? " B" : " C";
  7716. }
  7717. printk(KERN_INFO "(scsi%d) Resetting channel%s\n", p->host_no, channel);
  7718. }
  7719. aic7xxx_reset_current_bus(p);
  7720. }
  7721. else
  7722. {
  7723. if (!reset_delay)
  7724. {
  7725. printk(KERN_INFO "(scsi%d) Not resetting SCSI bus. Note: Don't use "
  7726. "the no_reset\n", p->host_no);
  7727. printk(KERN_INFO "(scsi%d) option unless you have a verifiable need "
  7728. "for it.\n", p->host_no);
  7729. }
  7730. }
  7731. /*
  7732. * Register IRQ with the kernel. Only allow sharing IRQs with
  7733. * PCI devices.
  7734. */
  7735. if (!(p->chip & AHC_PCI))
  7736. {
  7737. result = (request_irq(p->irq, do_aic7xxx_isr, 0, "aic7xxx", p));
  7738. }
  7739. else
  7740. {
  7741. result = (request_irq(p->irq, do_aic7xxx_isr, IRQF_SHARED,
  7742. "aic7xxx", p));
  7743. if (result < 0)
  7744. {
  7745. result = (request_irq(p->irq, do_aic7xxx_isr, IRQF_DISABLED | IRQF_SHARED,
  7746. "aic7xxx", p));
  7747. }
  7748. }
  7749. if (result < 0)
  7750. {
  7751. printk(KERN_WARNING "(scsi%d) Couldn't register IRQ %d, ignoring "
  7752. "controller.\n", p->host_no, p->irq);
  7753. aic_outb(p, 0, SIMODE1);
  7754. p->irq = 0;
  7755. return (0);
  7756. }
  7757. if(aic_inb(p, INTSTAT) & INT_PEND)
  7758. printk(INFO_LEAD "spurious interrupt during configuration, cleared.\n",
  7759. p->host_no, -1, -1 , -1);
  7760. aic7xxx_clear_intstat(p);
  7761. unpause_sequencer(p, /* unpause_always */ TRUE);
  7762. return (found);
  7763. }
  7764. /*+F*************************************************************************
  7765. * Function:
  7766. * aic7xxx_chip_reset
  7767. *
  7768. * Description:
  7769. * Perform a chip reset on the aic7xxx SCSI controller. The controller
  7770. * is paused upon return.
  7771. *-F*************************************************************************/
  7772. static int
  7773. aic7xxx_chip_reset(struct aic7xxx_host *p)
  7774. {
  7775. unsigned char sblkctl;
  7776. int wait;
  7777. /*
  7778. * For some 274x boards, we must clear the CHIPRST bit and pause
  7779. * the sequencer. For some reason, this makes the driver work.
  7780. */
  7781. aic_outb(p, PAUSE | CHIPRST, HCNTRL);
  7782. /*
  7783. * In the future, we may call this function as a last resort for
  7784. * error handling. Let's be nice and not do any unnecessary delays.
  7785. */
  7786. wait = 1000; /* 1 msec (1000 * 1 msec) */
  7787. while (--wait && !(aic_inb(p, HCNTRL) & CHIPRSTACK))
  7788. {
  7789. udelay(1); /* 1 usec */
  7790. }
  7791. pause_sequencer(p);
  7792. sblkctl = aic_inb(p, SBLKCTL) & (SELBUSB|SELWIDE);
  7793. if (p->chip & AHC_PCI)
  7794. sblkctl &= ~SELBUSB;
  7795. switch( sblkctl )
  7796. {
  7797. case 0: /* normal narrow card */
  7798. break;
  7799. case 2: /* Wide card */
  7800. p->features |= AHC_WIDE;
  7801. break;
  7802. case 8: /* Twin card */
  7803. p->features |= AHC_TWIN;
  7804. p->flags |= AHC_MULTI_CHANNEL;
  7805. break;
  7806. default: /* hmmm...we don't know what this is */
  7807. printk(KERN_WARNING "aic7xxx: Unsupported adapter type %d, ignoring.\n",
  7808. aic_inb(p, SBLKCTL) & 0x0a);
  7809. return(-1);
  7810. }
  7811. return(0);
  7812. }
  7813. /*+F*************************************************************************
  7814. * Function:
  7815. * aic7xxx_alloc
  7816. *
  7817. * Description:
  7818. * Allocate and initialize a host structure. Returns NULL upon error
  7819. * and a pointer to a aic7xxx_host struct upon success.
  7820. *-F*************************************************************************/
  7821. static struct aic7xxx_host *
  7822. aic7xxx_alloc(struct scsi_host_template *sht, struct aic7xxx_host *temp)
  7823. {
  7824. struct aic7xxx_host *p = NULL;
  7825. struct Scsi_Host *host;
  7826. /*
  7827. * Allocate a storage area by registering us with the mid-level
  7828. * SCSI layer.
  7829. */
  7830. host = scsi_register(sht, sizeof(struct aic7xxx_host));
  7831. if (host != NULL)
  7832. {
  7833. p = (struct aic7xxx_host *) host->hostdata;
  7834. memset(p, 0, sizeof(struct aic7xxx_host));
  7835. *p = *temp;
  7836. p->host = host;
  7837. p->scb_data = kzalloc(sizeof(scb_data_type), GFP_ATOMIC);
  7838. if (p->scb_data)
  7839. {
  7840. scbq_init (&p->scb_data->free_scbs);
  7841. }
  7842. else
  7843. {
  7844. /*
  7845. * For some reason we don't have enough memory. Free the
  7846. * allocated memory for the aic7xxx_host struct, and return NULL.
  7847. */
  7848. release_region(p->base, MAXREG - MINREG);
  7849. scsi_unregister(host);
  7850. return(NULL);
  7851. }
  7852. p->host_no = host->host_no;
  7853. }
  7854. return (p);
  7855. }
  7856. /*+F*************************************************************************
  7857. * Function:
  7858. * aic7xxx_free
  7859. *
  7860. * Description:
  7861. * Frees and releases all resources associated with an instance of
  7862. * the driver (struct aic7xxx_host *).
  7863. *-F*************************************************************************/
  7864. static void
  7865. aic7xxx_free(struct aic7xxx_host *p)
  7866. {
  7867. int i;
  7868. /*
  7869. * Free the allocated hardware SCB space.
  7870. */
  7871. if (p->scb_data != NULL)
  7872. {
  7873. struct aic7xxx_scb_dma *scb_dma = NULL;
  7874. if (p->scb_data->hscbs != NULL)
  7875. {
  7876. pci_free_consistent(p->pdev, p->scb_data->hscbs_dma_len,
  7877. p->scb_data->hscbs, p->scb_data->hscbs_dma);
  7878. p->scb_data->hscbs = p->scb_data->hscb_kmalloc_ptr = NULL;
  7879. }
  7880. /*
  7881. * Free the driver SCBs. These were allocated on an as-need
  7882. * basis. We allocated these in groups depending on how many
  7883. * we could fit into a given amount of RAM. The tail SCB for
  7884. * these allocations has a pointer to the alloced area.
  7885. */
  7886. for (i = 0; i < p->scb_data->numscbs; i++)
  7887. {
  7888. if (p->scb_data->scb_array[i]->scb_dma != scb_dma)
  7889. {
  7890. scb_dma = p->scb_data->scb_array[i]->scb_dma;
  7891. pci_free_consistent(p->pdev, scb_dma->dma_len,
  7892. (void *)((unsigned long)scb_dma->dma_address
  7893. - scb_dma->dma_offset),
  7894. scb_dma->dma_address);
  7895. }
  7896. kfree(p->scb_data->scb_array[i]->kmalloc_ptr);
  7897. p->scb_data->scb_array[i] = NULL;
  7898. }
  7899. /*
  7900. * Free the SCB data area.
  7901. */
  7902. kfree(p->scb_data);
  7903. }
  7904. pci_free_consistent(p->pdev, 3*256, (void *)p->untagged_scbs, p->fifo_dma);
  7905. }
  7906. /*+F*************************************************************************
  7907. * Function:
  7908. * aic7xxx_load_seeprom
  7909. *
  7910. * Description:
  7911. * Load the seeprom and configure adapter and target settings.
  7912. * Returns 1 if the load was successful and 0 otherwise.
  7913. *-F*************************************************************************/
  7914. static void
  7915. aic7xxx_load_seeprom(struct aic7xxx_host *p, unsigned char *sxfrctl1)
  7916. {
  7917. int have_seeprom = 0;
  7918. int i, max_targets, mask;
  7919. unsigned char scsirate, scsi_conf;
  7920. unsigned short scarray[128];
  7921. struct seeprom_config *sc = (struct seeprom_config *) scarray;
  7922. if (aic7xxx_verbose & VERBOSE_PROBE2)
  7923. {
  7924. printk(KERN_INFO "aic7xxx: Loading serial EEPROM...");
  7925. }
  7926. switch (p->chip)
  7927. {
  7928. case (AHC_AIC7770|AHC_EISA): /* None of these adapters have seeproms. */
  7929. if (aic_inb(p, SCSICONF) & TERM_ENB)
  7930. p->flags |= AHC_TERM_ENB_A;
  7931. if ( (p->features & AHC_TWIN) && (aic_inb(p, SCSICONF + 1) & TERM_ENB) )
  7932. p->flags |= AHC_TERM_ENB_B;
  7933. break;
  7934. case (AHC_AIC7770|AHC_VL):
  7935. have_seeprom = read_284x_seeprom(p, (struct seeprom_config *) scarray);
  7936. break;
  7937. default:
  7938. have_seeprom = read_seeprom(p, (p->flags & (AHC_CHNLB|AHC_CHNLC)),
  7939. scarray, p->sc_size, p->sc_type);
  7940. if (!have_seeprom)
  7941. {
  7942. if(p->sc_type == C46)
  7943. have_seeprom = read_seeprom(p, (p->flags & (AHC_CHNLB|AHC_CHNLC)),
  7944. scarray, p->sc_size, C56_66);
  7945. else
  7946. have_seeprom = read_seeprom(p, (p->flags & (AHC_CHNLB|AHC_CHNLC)),
  7947. scarray, p->sc_size, C46);
  7948. }
  7949. if (!have_seeprom)
  7950. {
  7951. p->sc_size = 128;
  7952. have_seeprom = read_seeprom(p, 4*(p->flags & (AHC_CHNLB|AHC_CHNLC)),
  7953. scarray, p->sc_size, p->sc_type);
  7954. if (!have_seeprom)
  7955. {
  7956. if(p->sc_type == C46)
  7957. have_seeprom = read_seeprom(p, 4*(p->flags & (AHC_CHNLB|AHC_CHNLC)),
  7958. scarray, p->sc_size, C56_66);
  7959. else
  7960. have_seeprom = read_seeprom(p, 4*(p->flags & (AHC_CHNLB|AHC_CHNLC)),
  7961. scarray, p->sc_size, C46);
  7962. }
  7963. }
  7964. break;
  7965. }
  7966. if (!have_seeprom)
  7967. {
  7968. if (aic7xxx_verbose & VERBOSE_PROBE2)
  7969. {
  7970. printk("\naic7xxx: No SEEPROM available.\n");
  7971. }
  7972. p->flags |= AHC_NEWEEPROM_FMT;
  7973. if (aic_inb(p, SCSISEQ) == 0)
  7974. {
  7975. p->flags |= AHC_USEDEFAULTS;
  7976. p->flags &= ~AHC_BIOS_ENABLED;
  7977. p->scsi_id = p->scsi_id_b = 7;
  7978. *sxfrctl1 |= STPWEN;
  7979. if (aic7xxx_verbose & VERBOSE_PROBE2)
  7980. {
  7981. printk("aic7xxx: Using default values.\n");
  7982. }
  7983. }
  7984. else if (aic7xxx_verbose & VERBOSE_PROBE2)
  7985. {
  7986. printk("aic7xxx: Using leftover BIOS values.\n");
  7987. }
  7988. if ( ((p->chip & ~AHC_CHIPID_MASK) == AHC_PCI) && (*sxfrctl1 & STPWEN) )
  7989. {
  7990. p->flags |= AHC_TERM_ENB_SE_LOW | AHC_TERM_ENB_SE_HIGH;
  7991. sc->adapter_control &= ~CFAUTOTERM;
  7992. sc->adapter_control |= CFSTERM | CFWSTERM | CFLVDSTERM;
  7993. }
  7994. if (aic7xxx_extended)
  7995. p->flags |= (AHC_EXTEND_TRANS_A | AHC_EXTEND_TRANS_B);
  7996. else
  7997. p->flags &= ~(AHC_EXTEND_TRANS_A | AHC_EXTEND_TRANS_B);
  7998. }
  7999. else
  8000. {
  8001. if (aic7xxx_verbose & VERBOSE_PROBE2)
  8002. {
  8003. printk("done\n");
  8004. }
  8005. /*
  8006. * Note things in our flags
  8007. */
  8008. p->flags |= AHC_SEEPROM_FOUND;
  8009. /*
  8010. * Update the settings in sxfrctl1 to match the termination settings.
  8011. */
  8012. *sxfrctl1 = 0;
  8013. /*
  8014. * Get our SCSI ID from the SEEPROM setting...
  8015. */
  8016. p->scsi_id = (sc->brtime_id & CFSCSIID);
  8017. /*
  8018. * First process the settings that are different between the VLB
  8019. * and PCI adapter seeproms.
  8020. */
  8021. if ((p->chip & AHC_CHIPID_MASK) == AHC_AIC7770)
  8022. {
  8023. /* VLB adapter seeproms */
  8024. if (sc->bios_control & CF284XEXTEND)
  8025. p->flags |= AHC_EXTEND_TRANS_A;
  8026. if (sc->adapter_control & CF284XSTERM)
  8027. {
  8028. *sxfrctl1 |= STPWEN;
  8029. p->flags |= AHC_TERM_ENB_SE_LOW | AHC_TERM_ENB_SE_HIGH;
  8030. }
  8031. }
  8032. else
  8033. {
  8034. /* PCI adapter seeproms */
  8035. if (sc->bios_control & CFEXTEND)
  8036. p->flags |= AHC_EXTEND_TRANS_A;
  8037. if (sc->bios_control & CFBIOSEN)
  8038. p->flags |= AHC_BIOS_ENABLED;
  8039. else
  8040. p->flags &= ~AHC_BIOS_ENABLED;
  8041. if (sc->adapter_control & CFSTERM)
  8042. {
  8043. *sxfrctl1 |= STPWEN;
  8044. p->flags |= AHC_TERM_ENB_SE_LOW | AHC_TERM_ENB_SE_HIGH;
  8045. }
  8046. }
  8047. memcpy(&p->sc, sc, sizeof(struct seeprom_config));
  8048. }
  8049. p->discenable = 0;
  8050. /*
  8051. * Limit to 16 targets just in case. The 2842 for one is known to
  8052. * blow the max_targets setting, future cards might also.
  8053. */
  8054. max_targets = ((p->features & (AHC_TWIN | AHC_WIDE)) ? 16 : 8);
  8055. if (have_seeprom)
  8056. {
  8057. for (i = 0; i < max_targets; i++)
  8058. {
  8059. if( ((p->features & AHC_ULTRA) &&
  8060. !(sc->adapter_control & CFULTRAEN) &&
  8061. (sc->device_flags[i] & CFSYNCHISULTRA)) ||
  8062. (sc->device_flags[i] & CFNEWULTRAFORMAT) )
  8063. {
  8064. p->flags |= AHC_NEWEEPROM_FMT;
  8065. break;
  8066. }
  8067. }
  8068. }
  8069. for (i = 0; i < max_targets; i++)
  8070. {
  8071. mask = (0x01 << i);
  8072. if (!have_seeprom)
  8073. {
  8074. if (aic_inb(p, SCSISEQ) != 0)
  8075. {
  8076. /*
  8077. * OK...the BIOS set things up and left behind the settings we need.
  8078. * Just make our sc->device_flags[i] entry match what the card has
  8079. * set for this device.
  8080. */
  8081. p->discenable =
  8082. ~(aic_inb(p, DISC_DSB) | (aic_inb(p, DISC_DSB + 1) << 8) );
  8083. p->ultraenb =
  8084. (aic_inb(p, ULTRA_ENB) | (aic_inb(p, ULTRA_ENB + 1) << 8) );
  8085. sc->device_flags[i] = (p->discenable & mask) ? CFDISC : 0;
  8086. if (aic_inb(p, TARG_SCSIRATE + i) & WIDEXFER)
  8087. sc->device_flags[i] |= CFWIDEB;
  8088. if (p->features & AHC_ULTRA2)
  8089. {
  8090. if (aic_inb(p, TARG_OFFSET + i))
  8091. {
  8092. sc->device_flags[i] |= CFSYNCH;
  8093. sc->device_flags[i] |= (aic_inb(p, TARG_SCSIRATE + i) & 0x07);
  8094. if ( (aic_inb(p, TARG_SCSIRATE + i) & 0x18) == 0x18 )
  8095. sc->device_flags[i] |= CFSYNCHISULTRA;
  8096. }
  8097. }
  8098. else
  8099. {
  8100. if (aic_inb(p, TARG_SCSIRATE + i) & ~WIDEXFER)
  8101. {
  8102. sc->device_flags[i] |= CFSYNCH;
  8103. if (p->features & AHC_ULTRA)
  8104. sc->device_flags[i] |= ((p->ultraenb & mask) ?
  8105. CFSYNCHISULTRA : 0);
  8106. }
  8107. }
  8108. }
  8109. else
  8110. {
  8111. /*
  8112. * Assume the BIOS has NOT been run on this card and nothing between
  8113. * the card and the devices is configured yet.
  8114. */
  8115. sc->device_flags[i] = CFDISC;
  8116. if (p->features & AHC_WIDE)
  8117. sc->device_flags[i] |= CFWIDEB;
  8118. if (p->features & AHC_ULTRA3)
  8119. sc->device_flags[i] |= 2;
  8120. else if (p->features & AHC_ULTRA2)
  8121. sc->device_flags[i] |= 3;
  8122. else if (p->features & AHC_ULTRA)
  8123. sc->device_flags[i] |= CFSYNCHISULTRA;
  8124. sc->device_flags[i] |= CFSYNCH;
  8125. aic_outb(p, 0, TARG_SCSIRATE + i);
  8126. if (p->features & AHC_ULTRA2)
  8127. aic_outb(p, 0, TARG_OFFSET + i);
  8128. }
  8129. }
  8130. if (sc->device_flags[i] & CFDISC)
  8131. {
  8132. p->discenable |= mask;
  8133. }
  8134. if (p->flags & AHC_NEWEEPROM_FMT)
  8135. {
  8136. if ( !(p->features & AHC_ULTRA2) )
  8137. {
  8138. /*
  8139. * I know of two different Ultra BIOSes that do this differently.
  8140. * One on the Gigabyte 6BXU mb that wants flags[i] & CFXFER to
  8141. * be == to 0x03 and SYNCHISULTRA to be true to mean 40MByte/s
  8142. * while on the IBM Netfinity 5000 they want the same thing
  8143. * to be something else, while flags[i] & CFXFER == 0x03 and
  8144. * SYNCHISULTRA false should be 40MByte/s. So, we set both to
  8145. * 40MByte/s and the lower speeds be damned. People will have
  8146. * to select around the conversely mapped lower speeds in order
  8147. * to select lower speeds on these boards.
  8148. */
  8149. if ( (sc->device_flags[i] & CFNEWULTRAFORMAT) &&
  8150. ((sc->device_flags[i] & CFXFER) == 0x03) )
  8151. {
  8152. sc->device_flags[i] &= ~CFXFER;
  8153. sc->device_flags[i] |= CFSYNCHISULTRA;
  8154. }
  8155. if (sc->device_flags[i] & CFSYNCHISULTRA)
  8156. {
  8157. p->ultraenb |= mask;
  8158. }
  8159. }
  8160. else if ( !(sc->device_flags[i] & CFNEWULTRAFORMAT) &&
  8161. (p->features & AHC_ULTRA2) &&
  8162. (sc->device_flags[i] & CFSYNCHISULTRA) )
  8163. {
  8164. p->ultraenb |= mask;
  8165. }
  8166. }
  8167. else if (sc->adapter_control & CFULTRAEN)
  8168. {
  8169. p->ultraenb |= mask;
  8170. }
  8171. if ( (sc->device_flags[i] & CFSYNCH) == 0)
  8172. {
  8173. sc->device_flags[i] &= ~CFXFER;
  8174. p->ultraenb &= ~mask;
  8175. p->user[i].offset = 0;
  8176. p->user[i].period = 0;
  8177. p->user[i].options = 0;
  8178. }
  8179. else
  8180. {
  8181. if (p->features & AHC_ULTRA3)
  8182. {
  8183. p->user[i].offset = MAX_OFFSET_ULTRA2;
  8184. if( (sc->device_flags[i] & CFXFER) < 0x03 )
  8185. {
  8186. scsirate = (sc->device_flags[i] & CFXFER);
  8187. p->user[i].options = MSG_EXT_PPR_OPTION_DT_CRC;
  8188. }
  8189. else
  8190. {
  8191. scsirate = (sc->device_flags[i] & CFXFER) |
  8192. ((p->ultraenb & mask) ? 0x18 : 0x10);
  8193. p->user[i].options = 0;
  8194. }
  8195. p->user[i].period = aic7xxx_find_period(p, scsirate,
  8196. AHC_SYNCRATE_ULTRA3);
  8197. }
  8198. else if (p->features & AHC_ULTRA2)
  8199. {
  8200. p->user[i].offset = MAX_OFFSET_ULTRA2;
  8201. scsirate = (sc->device_flags[i] & CFXFER) |
  8202. ((p->ultraenb & mask) ? 0x18 : 0x10);
  8203. p->user[i].options = 0;
  8204. p->user[i].period = aic7xxx_find_period(p, scsirate,
  8205. AHC_SYNCRATE_ULTRA2);
  8206. }
  8207. else
  8208. {
  8209. scsirate = (sc->device_flags[i] & CFXFER) << 4;
  8210. p->user[i].options = 0;
  8211. p->user[i].offset = MAX_OFFSET_8BIT;
  8212. if (p->features & AHC_ULTRA)
  8213. {
  8214. short ultraenb;
  8215. ultraenb = aic_inb(p, ULTRA_ENB) |
  8216. (aic_inb(p, ULTRA_ENB + 1) << 8);
  8217. p->user[i].period = aic7xxx_find_period(p, scsirate,
  8218. (p->ultraenb & mask) ?
  8219. AHC_SYNCRATE_ULTRA :
  8220. AHC_SYNCRATE_FAST);
  8221. }
  8222. else
  8223. p->user[i].period = aic7xxx_find_period(p, scsirate,
  8224. AHC_SYNCRATE_FAST);
  8225. }
  8226. }
  8227. if ( (sc->device_flags[i] & CFWIDEB) && (p->features & AHC_WIDE) )
  8228. {
  8229. p->user[i].width = MSG_EXT_WDTR_BUS_16_BIT;
  8230. }
  8231. else
  8232. {
  8233. p->user[i].width = MSG_EXT_WDTR_BUS_8_BIT;
  8234. }
  8235. }
  8236. aic_outb(p, ~(p->discenable & 0xFF), DISC_DSB);
  8237. aic_outb(p, ~((p->discenable >> 8) & 0xFF), DISC_DSB + 1);
  8238. /*
  8239. * We set the p->ultraenb from the SEEPROM to begin with, but now we make
  8240. * it match what is already down in the card. If we are doing a reset
  8241. * on the card then this will get put back to a default state anyway.
  8242. * This allows us to not have to pre-emptively negotiate when using the
  8243. * no_reset option.
  8244. */
  8245. if (p->features & AHC_ULTRA)
  8246. p->ultraenb = aic_inb(p, ULTRA_ENB) | (aic_inb(p, ULTRA_ENB + 1) << 8);
  8247. scsi_conf = (p->scsi_id & HSCSIID);
  8248. if(have_seeprom)
  8249. {
  8250. p->adapter_control = sc->adapter_control;
  8251. p->bios_control = sc->bios_control;
  8252. switch (p->chip & AHC_CHIPID_MASK)
  8253. {
  8254. case AHC_AIC7895:
  8255. case AHC_AIC7896:
  8256. case AHC_AIC7899:
  8257. if (p->adapter_control & CFBPRIMARY)
  8258. p->flags |= AHC_CHANNEL_B_PRIMARY;
  8259. default:
  8260. break;
  8261. }
  8262. if (sc->adapter_control & CFSPARITY)
  8263. scsi_conf |= ENSPCHK;
  8264. }
  8265. else
  8266. {
  8267. scsi_conf |= ENSPCHK | RESET_SCSI;
  8268. }
  8269. /*
  8270. * Only set the SCSICONF and SCSICONF + 1 registers if we are a PCI card.
  8271. * The 2842 and 2742 cards already have these registers set and we don't
  8272. * want to muck with them since we don't set all the bits they do.
  8273. */
  8274. if ( (p->chip & ~AHC_CHIPID_MASK) == AHC_PCI )
  8275. {
  8276. /* Set the host ID */
  8277. aic_outb(p, scsi_conf, SCSICONF);
  8278. /* In case we are a wide card */
  8279. aic_outb(p, p->scsi_id, SCSICONF + 1);
  8280. }
  8281. }
  8282. /*+F*************************************************************************
  8283. * Function:
  8284. * aic7xxx_configure_bugs
  8285. *
  8286. * Description:
  8287. * Take the card passed in and set the appropriate bug flags based upon
  8288. * the card model. Also make any changes needed to device registers or
  8289. * PCI registers while we are here.
  8290. *-F*************************************************************************/
  8291. static void
  8292. aic7xxx_configure_bugs(struct aic7xxx_host *p)
  8293. {
  8294. unsigned short tmp_word;
  8295. switch(p->chip & AHC_CHIPID_MASK)
  8296. {
  8297. case AHC_AIC7860:
  8298. p->bugs |= AHC_BUG_PCI_2_1_RETRY;
  8299. /* fall through */
  8300. case AHC_AIC7850:
  8301. case AHC_AIC7870:
  8302. p->bugs |= AHC_BUG_TMODE_WIDEODD | AHC_BUG_CACHETHEN | AHC_BUG_PCI_MWI;
  8303. break;
  8304. case AHC_AIC7880:
  8305. p->bugs |= AHC_BUG_TMODE_WIDEODD | AHC_BUG_PCI_2_1_RETRY |
  8306. AHC_BUG_CACHETHEN | AHC_BUG_PCI_MWI;
  8307. break;
  8308. case AHC_AIC7890:
  8309. p->bugs |= AHC_BUG_AUTOFLUSH | AHC_BUG_CACHETHEN;
  8310. break;
  8311. case AHC_AIC7892:
  8312. p->bugs |= AHC_BUG_SCBCHAN_UPLOAD;
  8313. break;
  8314. case AHC_AIC7895:
  8315. p->bugs |= AHC_BUG_TMODE_WIDEODD | AHC_BUG_PCI_2_1_RETRY |
  8316. AHC_BUG_CACHETHEN | AHC_BUG_PCI_MWI;
  8317. break;
  8318. case AHC_AIC7896:
  8319. p->bugs |= AHC_BUG_CACHETHEN_DIS;
  8320. break;
  8321. case AHC_AIC7899:
  8322. p->bugs |= AHC_BUG_SCBCHAN_UPLOAD;
  8323. break;
  8324. default:
  8325. /* Nothing to do */
  8326. break;
  8327. }
  8328. /*
  8329. * Now handle the bugs that require PCI register or card register tweaks
  8330. */
  8331. pci_read_config_word(p->pdev, PCI_COMMAND, &tmp_word);
  8332. if(p->bugs & AHC_BUG_PCI_MWI)
  8333. {
  8334. tmp_word &= ~PCI_COMMAND_INVALIDATE;
  8335. }
  8336. else
  8337. {
  8338. tmp_word |= PCI_COMMAND_INVALIDATE;
  8339. }
  8340. pci_write_config_word(p->pdev, PCI_COMMAND, tmp_word);
  8341. if(p->bugs & AHC_BUG_CACHETHEN)
  8342. {
  8343. aic_outb(p, aic_inb(p, DSCOMMAND0) & ~CACHETHEN, DSCOMMAND0);
  8344. }
  8345. else if (p->bugs & AHC_BUG_CACHETHEN_DIS)
  8346. {
  8347. aic_outb(p, aic_inb(p, DSCOMMAND0) | CACHETHEN, DSCOMMAND0);
  8348. }
  8349. return;
  8350. }
  8351. /*+F*************************************************************************
  8352. * Function:
  8353. * aic7xxx_detect
  8354. *
  8355. * Description:
  8356. * Try to detect and register an Adaptec 7770 or 7870 SCSI controller.
  8357. *
  8358. * XXX - This should really be called aic7xxx_probe(). A sequence of
  8359. * probe(), attach()/detach(), and init() makes more sense than
  8360. * one do-it-all function. This may be useful when (and if) the
  8361. * mid-level SCSI code is overhauled.
  8362. *-F*************************************************************************/
  8363. static int
  8364. aic7xxx_detect(struct scsi_host_template *template)
  8365. {
  8366. struct aic7xxx_host *temp_p = NULL;
  8367. struct aic7xxx_host *current_p = NULL;
  8368. struct aic7xxx_host *list_p = NULL;
  8369. int found = 0;
  8370. #if defined(__i386__) || defined(__alpha__)
  8371. ahc_flag_type flags = 0;
  8372. int type;
  8373. #endif
  8374. unsigned char sxfrctl1;
  8375. #if defined(__i386__) || defined(__alpha__)
  8376. unsigned char hcntrl, hostconf;
  8377. unsigned int slot, base;
  8378. #endif
  8379. #ifdef MODULE
  8380. /*
  8381. * If we are called as a module, the aic7xxx pointer may not be null
  8382. * and it would point to our bootup string, just like on the lilo
  8383. * command line. IF not NULL, then process this config string with
  8384. * aic7xxx_setup
  8385. */
  8386. if(aic7xxx)
  8387. aic7xxx_setup(aic7xxx);
  8388. #endif
  8389. template->proc_name = "aic7xxx";
  8390. template->sg_tablesize = AIC7XXX_MAX_SG;
  8391. #ifdef CONFIG_PCI
  8392. /*
  8393. * PCI-bus probe.
  8394. */
  8395. {
  8396. static struct
  8397. {
  8398. unsigned short vendor_id;
  8399. unsigned short device_id;
  8400. ahc_chip chip;
  8401. ahc_flag_type flags;
  8402. ahc_feature features;
  8403. int board_name_index;
  8404. unsigned short seeprom_size;
  8405. unsigned short seeprom_type;
  8406. } const aic_pdevs[] = {
  8407. {PCI_VENDOR_ID_ADAPTEC, PCI_DEVICE_ID_ADAPTEC_7810, AHC_NONE,
  8408. AHC_FNONE, AHC_FENONE, 1,
  8409. 32, C46 },
  8410. {PCI_VENDOR_ID_ADAPTEC, PCI_DEVICE_ID_ADAPTEC_7850, AHC_AIC7850,
  8411. AHC_PAGESCBS, AHC_AIC7850_FE, 5,
  8412. 32, C46 },
  8413. {PCI_VENDOR_ID_ADAPTEC, PCI_DEVICE_ID_ADAPTEC_7855, AHC_AIC7850,
  8414. AHC_PAGESCBS, AHC_AIC7850_FE, 6,
  8415. 32, C46 },
  8416. {PCI_VENDOR_ID_ADAPTEC, PCI_DEVICE_ID_ADAPTEC_7821, AHC_AIC7860,
  8417. AHC_PAGESCBS | AHC_NEWEEPROM_FMT | AHC_BIOS_ENABLED,
  8418. AHC_AIC7860_FE, 7,
  8419. 32, C46 },
  8420. {PCI_VENDOR_ID_ADAPTEC, PCI_DEVICE_ID_ADAPTEC_3860, AHC_AIC7860,
  8421. AHC_PAGESCBS | AHC_NEWEEPROM_FMT | AHC_BIOS_ENABLED,
  8422. AHC_AIC7860_FE, 7,
  8423. 32, C46 },
  8424. {PCI_VENDOR_ID_ADAPTEC, PCI_DEVICE_ID_ADAPTEC_38602, AHC_AIC7860,
  8425. AHC_PAGESCBS | AHC_NEWEEPROM_FMT | AHC_BIOS_ENABLED,
  8426. AHC_AIC7860_FE, 7,
  8427. 32, C46 },
  8428. {PCI_VENDOR_ID_ADAPTEC, PCI_DEVICE_ID_ADAPTEC_38602, AHC_AIC7860,
  8429. AHC_PAGESCBS | AHC_NEWEEPROM_FMT | AHC_BIOS_ENABLED,
  8430. AHC_AIC7860_FE, 7,
  8431. 32, C46 },
  8432. {PCI_VENDOR_ID_ADAPTEC, PCI_DEVICE_ID_ADAPTEC_7860, AHC_AIC7860,
  8433. AHC_PAGESCBS | AHC_NEWEEPROM_FMT | AHC_BIOS_ENABLED | AHC_MOTHERBOARD,
  8434. AHC_AIC7860_FE, 7,
  8435. 32, C46 },
  8436. {PCI_VENDOR_ID_ADAPTEC, PCI_DEVICE_ID_ADAPTEC_7861, AHC_AIC7860,
  8437. AHC_PAGESCBS | AHC_NEWEEPROM_FMT | AHC_BIOS_ENABLED,
  8438. AHC_AIC7860_FE, 8,
  8439. 32, C46 },
  8440. {PCI_VENDOR_ID_ADAPTEC, PCI_DEVICE_ID_ADAPTEC_7870, AHC_AIC7870,
  8441. AHC_PAGESCBS | AHC_BIOS_ENABLED | AHC_MOTHERBOARD,
  8442. AHC_AIC7870_FE, 9,
  8443. 32, C46 },
  8444. {PCI_VENDOR_ID_ADAPTEC, PCI_DEVICE_ID_ADAPTEC_7871, AHC_AIC7870,
  8445. AHC_PAGESCBS | AHC_BIOS_ENABLED, AHC_AIC7870_FE, 10,
  8446. 32, C46 },
  8447. {PCI_VENDOR_ID_ADAPTEC, PCI_DEVICE_ID_ADAPTEC_7872, AHC_AIC7870,
  8448. AHC_PAGESCBS | AHC_BIOS_ENABLED | AHC_MULTI_CHANNEL,
  8449. AHC_AIC7870_FE, 11,
  8450. 32, C56_66 },
  8451. {PCI_VENDOR_ID_ADAPTEC, PCI_DEVICE_ID_ADAPTEC_7873, AHC_AIC7870,
  8452. AHC_PAGESCBS | AHC_BIOS_ENABLED | AHC_MULTI_CHANNEL,
  8453. AHC_AIC7870_FE, 12,
  8454. 32, C56_66 },
  8455. {PCI_VENDOR_ID_ADAPTEC, PCI_DEVICE_ID_ADAPTEC_7874, AHC_AIC7870,
  8456. AHC_PAGESCBS | AHC_BIOS_ENABLED, AHC_AIC7870_FE, 13,
  8457. 32, C46 },
  8458. {PCI_VENDOR_ID_ADAPTEC, PCI_DEVICE_ID_ADAPTEC_7880, AHC_AIC7880,
  8459. AHC_PAGESCBS | AHC_BIOS_ENABLED | AHC_MOTHERBOARD,
  8460. AHC_AIC7880_FE, 14,
  8461. 32, C46 },
  8462. {PCI_VENDOR_ID_ADAPTEC, PCI_DEVICE_ID_ADAPTEC_7881, AHC_AIC7880,
  8463. AHC_PAGESCBS | AHC_BIOS_ENABLED, AHC_AIC7880_FE, 15,
  8464. 32, C46 },
  8465. {PCI_VENDOR_ID_ADAPTEC, PCI_DEVICE_ID_ADAPTEC_7882, AHC_AIC7880,
  8466. AHC_PAGESCBS | AHC_BIOS_ENABLED | AHC_MULTI_CHANNEL,
  8467. AHC_AIC7880_FE, 16,
  8468. 32, C56_66 },
  8469. {PCI_VENDOR_ID_ADAPTEC, PCI_DEVICE_ID_ADAPTEC_7883, AHC_AIC7880,
  8470. AHC_PAGESCBS | AHC_BIOS_ENABLED | AHC_MULTI_CHANNEL,
  8471. AHC_AIC7880_FE, 17,
  8472. 32, C56_66 },
  8473. {PCI_VENDOR_ID_ADAPTEC, PCI_DEVICE_ID_ADAPTEC_7884, AHC_AIC7880,
  8474. AHC_PAGESCBS | AHC_BIOS_ENABLED, AHC_AIC7880_FE, 18,
  8475. 32, C46 },
  8476. {PCI_VENDOR_ID_ADAPTEC, PCI_DEVICE_ID_ADAPTEC_7885, AHC_AIC7880,
  8477. AHC_PAGESCBS | AHC_BIOS_ENABLED, AHC_AIC7880_FE, 18,
  8478. 32, C46 },
  8479. {PCI_VENDOR_ID_ADAPTEC, PCI_DEVICE_ID_ADAPTEC_7886, AHC_AIC7880,
  8480. AHC_PAGESCBS | AHC_BIOS_ENABLED, AHC_AIC7880_FE, 18,
  8481. 32, C46 },
  8482. {PCI_VENDOR_ID_ADAPTEC, PCI_DEVICE_ID_ADAPTEC_7887, AHC_AIC7880,
  8483. AHC_PAGESCBS | AHC_BIOS_ENABLED, AHC_AIC7880_FE | AHC_NEW_AUTOTERM, 19,
  8484. 32, C46 },
  8485. {PCI_VENDOR_ID_ADAPTEC, PCI_DEVICE_ID_ADAPTEC_7888, AHC_AIC7880,
  8486. AHC_PAGESCBS | AHC_BIOS_ENABLED, AHC_AIC7880_FE, 18,
  8487. 32, C46 },
  8488. {PCI_VENDOR_ID_ADAPTEC, PCI_DEVICE_ID_ADAPTEC_7895, AHC_AIC7895,
  8489. AHC_PAGESCBS | AHC_NEWEEPROM_FMT | AHC_BIOS_ENABLED | AHC_MULTI_CHANNEL,
  8490. AHC_AIC7895_FE, 20,
  8491. 32, C56_66 },
  8492. {PCI_VENDOR_ID_ADAPTEC2, PCI_DEVICE_ID_ADAPTEC2_7890, AHC_AIC7890,
  8493. AHC_PAGESCBS | AHC_NEWEEPROM_FMT | AHC_BIOS_ENABLED,
  8494. AHC_AIC7890_FE, 21,
  8495. 32, C46 },
  8496. {PCI_VENDOR_ID_ADAPTEC2, PCI_DEVICE_ID_ADAPTEC2_7890B, AHC_AIC7890,
  8497. AHC_PAGESCBS | AHC_NEWEEPROM_FMT | AHC_BIOS_ENABLED,
  8498. AHC_AIC7890_FE, 21,
  8499. 32, C46 },
  8500. {PCI_VENDOR_ID_ADAPTEC2, PCI_DEVICE_ID_ADAPTEC2_2930U2, AHC_AIC7890,
  8501. AHC_PAGESCBS | AHC_NEWEEPROM_FMT | AHC_BIOS_ENABLED,
  8502. AHC_AIC7890_FE, 22,
  8503. 32, C46 },
  8504. {PCI_VENDOR_ID_ADAPTEC2, PCI_DEVICE_ID_ADAPTEC2_2940U2, AHC_AIC7890,
  8505. AHC_PAGESCBS | AHC_NEWEEPROM_FMT | AHC_BIOS_ENABLED,
  8506. AHC_AIC7890_FE, 23,
  8507. 32, C46 },
  8508. {PCI_VENDOR_ID_ADAPTEC2, PCI_DEVICE_ID_ADAPTEC2_7896, AHC_AIC7896,
  8509. AHC_PAGESCBS | AHC_NEWEEPROM_FMT | AHC_BIOS_ENABLED | AHC_MULTI_CHANNEL,
  8510. AHC_AIC7896_FE, 24,
  8511. 32, C56_66 },
  8512. {PCI_VENDOR_ID_ADAPTEC2, PCI_DEVICE_ID_ADAPTEC2_3940U2, AHC_AIC7896,
  8513. AHC_PAGESCBS | AHC_NEWEEPROM_FMT | AHC_BIOS_ENABLED | AHC_MULTI_CHANNEL,
  8514. AHC_AIC7896_FE, 25,
  8515. 32, C56_66 },
  8516. {PCI_VENDOR_ID_ADAPTEC2, PCI_DEVICE_ID_ADAPTEC2_3950U2D, AHC_AIC7896,
  8517. AHC_PAGESCBS | AHC_NEWEEPROM_FMT | AHC_BIOS_ENABLED | AHC_MULTI_CHANNEL,
  8518. AHC_AIC7896_FE, 26,
  8519. 32, C56_66 },
  8520. {PCI_VENDOR_ID_ADAPTEC, PCI_DEVICE_ID_ADAPTEC_1480A, AHC_AIC7860,
  8521. AHC_PAGESCBS | AHC_NEWEEPROM_FMT | AHC_BIOS_ENABLED | AHC_NO_STPWEN,
  8522. AHC_AIC7860_FE, 27,
  8523. 32, C46 },
  8524. {PCI_VENDOR_ID_ADAPTEC2, PCI_DEVICE_ID_ADAPTEC2_7892A, AHC_AIC7892,
  8525. AHC_PAGESCBS | AHC_NEWEEPROM_FMT | AHC_BIOS_ENABLED,
  8526. AHC_AIC7892_FE, 28,
  8527. 32, C46 },
  8528. {PCI_VENDOR_ID_ADAPTEC2, PCI_DEVICE_ID_ADAPTEC2_7892B, AHC_AIC7892,
  8529. AHC_PAGESCBS | AHC_NEWEEPROM_FMT | AHC_BIOS_ENABLED,
  8530. AHC_AIC7892_FE, 28,
  8531. 32, C46 },
  8532. {PCI_VENDOR_ID_ADAPTEC2, PCI_DEVICE_ID_ADAPTEC2_7892D, AHC_AIC7892,
  8533. AHC_PAGESCBS | AHC_NEWEEPROM_FMT | AHC_BIOS_ENABLED,
  8534. AHC_AIC7892_FE, 28,
  8535. 32, C46 },
  8536. {PCI_VENDOR_ID_ADAPTEC2, PCI_DEVICE_ID_ADAPTEC2_7892P, AHC_AIC7892,
  8537. AHC_PAGESCBS | AHC_NEWEEPROM_FMT | AHC_BIOS_ENABLED,
  8538. AHC_AIC7892_FE, 28,
  8539. 32, C46 },
  8540. {PCI_VENDOR_ID_ADAPTEC2, PCI_DEVICE_ID_ADAPTEC2_7899A, AHC_AIC7899,
  8541. AHC_PAGESCBS | AHC_NEWEEPROM_FMT | AHC_BIOS_ENABLED | AHC_MULTI_CHANNEL,
  8542. AHC_AIC7899_FE, 29,
  8543. 32, C56_66 },
  8544. {PCI_VENDOR_ID_ADAPTEC2, PCI_DEVICE_ID_ADAPTEC2_7899B, AHC_AIC7899,
  8545. AHC_PAGESCBS | AHC_NEWEEPROM_FMT | AHC_BIOS_ENABLED | AHC_MULTI_CHANNEL,
  8546. AHC_AIC7899_FE, 29,
  8547. 32, C56_66 },
  8548. {PCI_VENDOR_ID_ADAPTEC2, PCI_DEVICE_ID_ADAPTEC2_7899D, AHC_AIC7899,
  8549. AHC_PAGESCBS | AHC_NEWEEPROM_FMT | AHC_BIOS_ENABLED | AHC_MULTI_CHANNEL,
  8550. AHC_AIC7899_FE, 29,
  8551. 32, C56_66 },
  8552. {PCI_VENDOR_ID_ADAPTEC2, PCI_DEVICE_ID_ADAPTEC2_7899P, AHC_AIC7899,
  8553. AHC_PAGESCBS | AHC_NEWEEPROM_FMT | AHC_BIOS_ENABLED | AHC_MULTI_CHANNEL,
  8554. AHC_AIC7899_FE, 29,
  8555. 32, C56_66 },
  8556. };
  8557. unsigned short command;
  8558. unsigned int devconfig, i, oldverbose;
  8559. struct pci_dev *pdev = NULL;
  8560. for (i = 0; i < ARRAY_SIZE(aic_pdevs); i++)
  8561. {
  8562. pdev = NULL;
  8563. while ((pdev = pci_get_device(aic_pdevs[i].vendor_id,
  8564. aic_pdevs[i].device_id,
  8565. pdev))) {
  8566. if (pci_enable_device(pdev))
  8567. continue;
  8568. if ( i == 0 ) /* We found one, but it's the 7810 RAID cont. */
  8569. {
  8570. if (aic7xxx_verbose & (VERBOSE_PROBE|VERBOSE_PROBE2))
  8571. {
  8572. printk(KERN_INFO "aic7xxx: The 7810 RAID controller is not "
  8573. "supported by\n");
  8574. printk(KERN_INFO " this driver, we are ignoring it.\n");
  8575. }
  8576. }
  8577. else if ( (temp_p = kzalloc(sizeof(struct aic7xxx_host),
  8578. GFP_ATOMIC)) != NULL )
  8579. {
  8580. temp_p->chip = aic_pdevs[i].chip | AHC_PCI;
  8581. temp_p->flags = aic_pdevs[i].flags;
  8582. temp_p->features = aic_pdevs[i].features;
  8583. temp_p->board_name_index = aic_pdevs[i].board_name_index;
  8584. temp_p->sc_size = aic_pdevs[i].seeprom_size;
  8585. temp_p->sc_type = aic_pdevs[i].seeprom_type;
  8586. /*
  8587. * Read sundry information from PCI BIOS.
  8588. */
  8589. temp_p->irq = pdev->irq;
  8590. temp_p->pdev = pdev;
  8591. temp_p->pci_bus = pdev->bus->number;
  8592. temp_p->pci_device_fn = pdev->devfn;
  8593. temp_p->base = pci_resource_start(pdev, 0);
  8594. temp_p->mbase = pci_resource_start(pdev, 1);
  8595. current_p = list_p;
  8596. while(current_p && temp_p)
  8597. {
  8598. if ( ((current_p->pci_bus == temp_p->pci_bus) &&
  8599. (current_p->pci_device_fn == temp_p->pci_device_fn)) ||
  8600. (temp_p->base && (current_p->base == temp_p->base)) ||
  8601. (temp_p->mbase && (current_p->mbase == temp_p->mbase)) )
  8602. {
  8603. /* duplicate PCI entry, skip it */
  8604. kfree(temp_p);
  8605. temp_p = NULL;
  8606. continue;
  8607. }
  8608. current_p = current_p->next;
  8609. }
  8610. if(pci_request_regions(temp_p->pdev, "aic7xxx"))
  8611. {
  8612. printk("aic7xxx: <%s> at PCI %d/%d/%d\n",
  8613. board_names[aic_pdevs[i].board_name_index],
  8614. temp_p->pci_bus,
  8615. PCI_SLOT(temp_p->pci_device_fn),
  8616. PCI_FUNC(temp_p->pci_device_fn));
  8617. printk("aic7xxx: I/O ports already in use, ignoring.\n");
  8618. kfree(temp_p);
  8619. continue;
  8620. }
  8621. if (aic7xxx_verbose & VERBOSE_PROBE2)
  8622. printk("aic7xxx: <%s> at PCI %d/%d\n",
  8623. board_names[aic_pdevs[i].board_name_index],
  8624. PCI_SLOT(pdev->devfn),
  8625. PCI_FUNC(pdev->devfn));
  8626. pci_read_config_word(pdev, PCI_COMMAND, &command);
  8627. if (aic7xxx_verbose & VERBOSE_PROBE2)
  8628. {
  8629. printk("aic7xxx: Initial PCI_COMMAND value was 0x%x\n",
  8630. (int)command);
  8631. }
  8632. #ifdef AIC7XXX_STRICT_PCI_SETUP
  8633. command |= PCI_COMMAND_SERR | PCI_COMMAND_PARITY |
  8634. PCI_COMMAND_MASTER | PCI_COMMAND_MEMORY | PCI_COMMAND_IO;
  8635. #else
  8636. command |= PCI_COMMAND_MASTER | PCI_COMMAND_MEMORY | PCI_COMMAND_IO;
  8637. #endif
  8638. command &= ~PCI_COMMAND_INVALIDATE;
  8639. if (aic7xxx_pci_parity == 0)
  8640. command &= ~(PCI_COMMAND_SERR | PCI_COMMAND_PARITY);
  8641. pci_write_config_word(pdev, PCI_COMMAND, command);
  8642. #ifdef AIC7XXX_STRICT_PCI_SETUP
  8643. pci_read_config_dword(pdev, DEVCONFIG, &devconfig);
  8644. if (aic7xxx_verbose & VERBOSE_PROBE2)
  8645. {
  8646. printk("aic7xxx: Initial DEVCONFIG value was 0x%x\n", devconfig);
  8647. }
  8648. devconfig |= 0x80000040;
  8649. pci_write_config_dword(pdev, DEVCONFIG, devconfig);
  8650. #endif /* AIC7XXX_STRICT_PCI_SETUP */
  8651. temp_p->unpause = INTEN;
  8652. temp_p->pause = temp_p->unpause | PAUSE;
  8653. if ( ((temp_p->base == 0) &&
  8654. (temp_p->mbase == 0)) ||
  8655. (temp_p->irq == 0) )
  8656. {
  8657. printk("aic7xxx: <%s> at PCI %d/%d/%d\n",
  8658. board_names[aic_pdevs[i].board_name_index],
  8659. temp_p->pci_bus,
  8660. PCI_SLOT(temp_p->pci_device_fn),
  8661. PCI_FUNC(temp_p->pci_device_fn));
  8662. printk("aic7xxx: Controller disabled by BIOS, ignoring.\n");
  8663. goto skip_pci_controller;
  8664. }
  8665. #ifdef MMAPIO
  8666. if ( !(temp_p->base) || !(temp_p->flags & AHC_MULTI_CHANNEL) ||
  8667. ((temp_p->chip != (AHC_AIC7870 | AHC_PCI)) &&
  8668. (temp_p->chip != (AHC_AIC7880 | AHC_PCI))) )
  8669. {
  8670. temp_p->maddr = ioremap_nocache(temp_p->mbase, 256);
  8671. if(temp_p->maddr)
  8672. {
  8673. /*
  8674. * We need to check the I/O with the MMAPed address. Some machines
  8675. * simply fail to work with MMAPed I/O and certain controllers.
  8676. */
  8677. if(aic_inb(temp_p, HCNTRL) == 0xff)
  8678. {
  8679. /*
  8680. * OK.....we failed our test....go back to programmed I/O
  8681. */
  8682. printk(KERN_INFO "aic7xxx: <%s> at PCI %d/%d/%d\n",
  8683. board_names[aic_pdevs[i].board_name_index],
  8684. temp_p->pci_bus,
  8685. PCI_SLOT(temp_p->pci_device_fn),
  8686. PCI_FUNC(temp_p->pci_device_fn));
  8687. printk(KERN_INFO "aic7xxx: MMAPed I/O failed, reverting to "
  8688. "Programmed I/O.\n");
  8689. iounmap(temp_p->maddr);
  8690. temp_p->maddr = NULL;
  8691. if(temp_p->base == 0)
  8692. {
  8693. printk("aic7xxx: <%s> at PCI %d/%d/%d\n",
  8694. board_names[aic_pdevs[i].board_name_index],
  8695. temp_p->pci_bus,
  8696. PCI_SLOT(temp_p->pci_device_fn),
  8697. PCI_FUNC(temp_p->pci_device_fn));
  8698. printk("aic7xxx: Controller disabled by BIOS, ignoring.\n");
  8699. goto skip_pci_controller;
  8700. }
  8701. }
  8702. }
  8703. }
  8704. #endif
  8705. /*
  8706. * We HAVE to make sure the first pause_sequencer() and all other
  8707. * subsequent I/O that isn't PCI config space I/O takes place
  8708. * after the MMAPed I/O region is configured and tested. The
  8709. * problem is the PowerPC architecture that doesn't support
  8710. * programmed I/O at all, so we have to have the MMAP I/O set up
  8711. * for this pause to even work on those machines.
  8712. */
  8713. pause_sequencer(temp_p);
  8714. /*
  8715. * Clear out any pending PCI error status messages. Also set
  8716. * verbose to 0 so that we don't emit strange PCI error messages
  8717. * while cleaning out the current status bits.
  8718. */
  8719. oldverbose = aic7xxx_verbose;
  8720. aic7xxx_verbose = 0;
  8721. aic7xxx_pci_intr(temp_p);
  8722. aic7xxx_verbose = oldverbose;
  8723. temp_p->bios_address = 0;
  8724. /*
  8725. * Remember how the card was setup in case there is no seeprom.
  8726. */
  8727. if (temp_p->features & AHC_ULTRA2)
  8728. temp_p->scsi_id = aic_inb(temp_p, SCSIID_ULTRA2) & OID;
  8729. else
  8730. temp_p->scsi_id = aic_inb(temp_p, SCSIID) & OID;
  8731. /*
  8732. * Get current termination setting
  8733. */
  8734. sxfrctl1 = aic_inb(temp_p, SXFRCTL1);
  8735. if (aic7xxx_chip_reset(temp_p) == -1)
  8736. {
  8737. goto skip_pci_controller;
  8738. }
  8739. /*
  8740. * Very quickly put the term setting back into the register since
  8741. * the chip reset may cause odd things to happen. This is to keep
  8742. * LVD busses with lots of drives from draining the power out of
  8743. * the diffsense line before we get around to running the
  8744. * configure_termination() function. Also restore the STPWLEVEL
  8745. * bit of DEVCONFIG
  8746. */
  8747. aic_outb(temp_p, sxfrctl1, SXFRCTL1);
  8748. pci_write_config_dword(temp_p->pdev, DEVCONFIG, devconfig);
  8749. sxfrctl1 &= STPWEN;
  8750. /*
  8751. * We need to set the CHNL? assignments before loading the SEEPROM
  8752. * The 3940 and 3985 cards (original stuff, not any of the later
  8753. * stuff) are 7870 and 7880 class chips. The Ultra2 stuff falls
  8754. * under 7896 and 7897. The 7895 is in a class by itself :)
  8755. */
  8756. switch (temp_p->chip & AHC_CHIPID_MASK)
  8757. {
  8758. case AHC_AIC7870: /* 3840 / 3985 */
  8759. case AHC_AIC7880: /* 3840 UW / 3985 UW */
  8760. if(temp_p->flags & AHC_MULTI_CHANNEL)
  8761. {
  8762. switch(PCI_SLOT(temp_p->pci_device_fn))
  8763. {
  8764. case 5:
  8765. temp_p->flags |= AHC_CHNLB;
  8766. break;
  8767. case 8:
  8768. temp_p->flags |= AHC_CHNLB;
  8769. break;
  8770. case 12:
  8771. temp_p->flags |= AHC_CHNLC;
  8772. break;
  8773. default:
  8774. break;
  8775. }
  8776. }
  8777. break;
  8778. case AHC_AIC7895: /* 7895 */
  8779. case AHC_AIC7896: /* 7896/7 */
  8780. case AHC_AIC7899: /* 7899 */
  8781. if (PCI_FUNC(pdev->devfn) != 0)
  8782. {
  8783. temp_p->flags |= AHC_CHNLB;
  8784. }
  8785. /*
  8786. * The 7895 is the only chipset that sets the SCBSIZE32 param
  8787. * in the DEVCONFIG register. The Ultra2 chipsets use
  8788. * the DSCOMMAND0 register instead.
  8789. */
  8790. if ((temp_p->chip & AHC_CHIPID_MASK) == AHC_AIC7895)
  8791. {
  8792. pci_read_config_dword(pdev, DEVCONFIG, &devconfig);
  8793. devconfig |= SCBSIZE32;
  8794. pci_write_config_dword(pdev, DEVCONFIG, devconfig);
  8795. }
  8796. break;
  8797. default:
  8798. break;
  8799. }
  8800. /*
  8801. * Loading of the SEEPROM needs to come after we've set the flags
  8802. * to indicate possible CHNLB and CHNLC assigments. Otherwise,
  8803. * on 394x and 398x cards we'll end up reading the wrong settings
  8804. * for channels B and C
  8805. */
  8806. switch (temp_p->chip & AHC_CHIPID_MASK)
  8807. {
  8808. case AHC_AIC7892:
  8809. case AHC_AIC7899:
  8810. aic_outb(temp_p, 0, SCAMCTL);
  8811. /*
  8812. * Switch to the alt mode of the chip...
  8813. */
  8814. aic_outb(temp_p, aic_inb(temp_p, SFUNCT) | ALT_MODE, SFUNCT);
  8815. /*
  8816. * Set our options...the last two items set our CRC after x byte
  8817. * count in target mode...
  8818. */
  8819. aic_outb(temp_p, AUTO_MSGOUT_DE | DIS_MSGIN_DUALEDGE, OPTIONMODE);
  8820. aic_outb(temp_p, 0x00, 0x0b);
  8821. aic_outb(temp_p, 0x10, 0x0a);
  8822. /*
  8823. * switch back to normal mode...
  8824. */
  8825. aic_outb(temp_p, aic_inb(temp_p, SFUNCT) & ~ALT_MODE, SFUNCT);
  8826. aic_outb(temp_p, CRCVALCHKEN | CRCENDCHKEN | CRCREQCHKEN |
  8827. TARGCRCENDEN | TARGCRCCNTEN,
  8828. CRCCONTROL1);
  8829. aic_outb(temp_p, ((aic_inb(temp_p, DSCOMMAND0) | USCBSIZE32 |
  8830. MPARCKEN | CIOPARCKEN | CACHETHEN) &
  8831. ~DPARCKEN), DSCOMMAND0);
  8832. aic7xxx_load_seeprom(temp_p, &sxfrctl1);
  8833. break;
  8834. case AHC_AIC7890:
  8835. case AHC_AIC7896:
  8836. aic_outb(temp_p, 0, SCAMCTL);
  8837. aic_outb(temp_p, (aic_inb(temp_p, DSCOMMAND0) |
  8838. CACHETHEN | MPARCKEN | USCBSIZE32 |
  8839. CIOPARCKEN) & ~DPARCKEN, DSCOMMAND0);
  8840. aic7xxx_load_seeprom(temp_p, &sxfrctl1);
  8841. break;
  8842. case AHC_AIC7850:
  8843. case AHC_AIC7860:
  8844. /*
  8845. * Set the DSCOMMAND0 register on these cards different from
  8846. * on the 789x cards. Also, read the SEEPROM as well.
  8847. */
  8848. aic_outb(temp_p, (aic_inb(temp_p, DSCOMMAND0) |
  8849. CACHETHEN | MPARCKEN) & ~DPARCKEN,
  8850. DSCOMMAND0);
  8851. /* FALLTHROUGH */
  8852. default:
  8853. aic7xxx_load_seeprom(temp_p, &sxfrctl1);
  8854. break;
  8855. case AHC_AIC7880:
  8856. /*
  8857. * Check the rev of the chipset before we change DSCOMMAND0
  8858. */
  8859. pci_read_config_dword(pdev, DEVCONFIG, &devconfig);
  8860. if ((devconfig & 0xff) >= 1)
  8861. {
  8862. aic_outb(temp_p, (aic_inb(temp_p, DSCOMMAND0) |
  8863. CACHETHEN | MPARCKEN) & ~DPARCKEN,
  8864. DSCOMMAND0);
  8865. }
  8866. aic7xxx_load_seeprom(temp_p, &sxfrctl1);
  8867. break;
  8868. }
  8869. /*
  8870. * and then we need another switch based on the type in order to
  8871. * make sure the channel B primary flag is set properly on 7895
  8872. * controllers....Arrrgggghhh!!! We also have to catch the fact
  8873. * that when you disable the BIOS on the 7895 on the Intel DK440LX
  8874. * motherboard, and possibly others, it only sets the BIOS disabled
  8875. * bit on the A channel...I think I'm starting to lean towards
  8876. * going postal....
  8877. */
  8878. switch(temp_p->chip & AHC_CHIPID_MASK)
  8879. {
  8880. case AHC_AIC7895:
  8881. case AHC_AIC7896:
  8882. case AHC_AIC7899:
  8883. current_p = list_p;
  8884. while(current_p != NULL)
  8885. {
  8886. if ( (current_p->pci_bus == temp_p->pci_bus) &&
  8887. (PCI_SLOT(current_p->pci_device_fn) ==
  8888. PCI_SLOT(temp_p->pci_device_fn)) )
  8889. {
  8890. if ( PCI_FUNC(current_p->pci_device_fn) == 0 )
  8891. {
  8892. temp_p->flags |=
  8893. (current_p->flags & AHC_CHANNEL_B_PRIMARY);
  8894. temp_p->flags &= ~(AHC_BIOS_ENABLED|AHC_USEDEFAULTS);
  8895. temp_p->flags |=
  8896. (current_p->flags & (AHC_BIOS_ENABLED|AHC_USEDEFAULTS));
  8897. }
  8898. else
  8899. {
  8900. current_p->flags |=
  8901. (temp_p->flags & AHC_CHANNEL_B_PRIMARY);
  8902. current_p->flags &= ~(AHC_BIOS_ENABLED|AHC_USEDEFAULTS);
  8903. current_p->flags |=
  8904. (temp_p->flags & (AHC_BIOS_ENABLED|AHC_USEDEFAULTS));
  8905. }
  8906. }
  8907. current_p = current_p->next;
  8908. }
  8909. break;
  8910. default:
  8911. break;
  8912. }
  8913. /*
  8914. * We only support external SCB RAM on the 7895/6/7 chipsets.
  8915. * We could support it on the 7890/1 easy enough, but I don't
  8916. * know of any 7890/1 based cards that have it. I do know
  8917. * of 7895/6/7 cards that have it and they work properly.
  8918. */
  8919. switch(temp_p->chip & AHC_CHIPID_MASK)
  8920. {
  8921. default:
  8922. break;
  8923. case AHC_AIC7895:
  8924. case AHC_AIC7896:
  8925. case AHC_AIC7899:
  8926. pci_read_config_dword(pdev, DEVCONFIG, &devconfig);
  8927. if (temp_p->features & AHC_ULTRA2)
  8928. {
  8929. if ( (aic_inb(temp_p, DSCOMMAND0) & RAMPSM_ULTRA2) &&
  8930. (aic7xxx_scbram) )
  8931. {
  8932. aic_outb(temp_p,
  8933. aic_inb(temp_p, DSCOMMAND0) & ~SCBRAMSEL_ULTRA2,
  8934. DSCOMMAND0);
  8935. temp_p->flags |= AHC_EXTERNAL_SRAM;
  8936. devconfig |= EXTSCBPEN;
  8937. }
  8938. else if (aic_inb(temp_p, DSCOMMAND0) & RAMPSM_ULTRA2)
  8939. {
  8940. printk(KERN_INFO "aic7xxx: <%s> at PCI %d/%d/%d\n",
  8941. board_names[aic_pdevs[i].board_name_index],
  8942. temp_p->pci_bus,
  8943. PCI_SLOT(temp_p->pci_device_fn),
  8944. PCI_FUNC(temp_p->pci_device_fn));
  8945. printk("aic7xxx: external SCB RAM detected, "
  8946. "but not enabled\n");
  8947. }
  8948. }
  8949. else
  8950. {
  8951. if ((devconfig & RAMPSM) && (aic7xxx_scbram))
  8952. {
  8953. devconfig &= ~SCBRAMSEL;
  8954. devconfig |= EXTSCBPEN;
  8955. temp_p->flags |= AHC_EXTERNAL_SRAM;
  8956. }
  8957. else if (devconfig & RAMPSM)
  8958. {
  8959. printk(KERN_INFO "aic7xxx: <%s> at PCI %d/%d/%d\n",
  8960. board_names[aic_pdevs[i].board_name_index],
  8961. temp_p->pci_bus,
  8962. PCI_SLOT(temp_p->pci_device_fn),
  8963. PCI_FUNC(temp_p->pci_device_fn));
  8964. printk("aic7xxx: external SCB RAM detected, "
  8965. "but not enabled\n");
  8966. }
  8967. }
  8968. pci_write_config_dword(pdev, DEVCONFIG, devconfig);
  8969. if ( (temp_p->flags & AHC_EXTERNAL_SRAM) &&
  8970. (temp_p->flags & AHC_CHNLB) )
  8971. aic_outb(temp_p, 1, CCSCBBADDR);
  8972. break;
  8973. }
  8974. /*
  8975. * Take the LED out of diagnostic mode
  8976. */
  8977. aic_outb(temp_p,
  8978. (aic_inb(temp_p, SBLKCTL) & ~(DIAGLEDEN | DIAGLEDON)),
  8979. SBLKCTL);
  8980. /*
  8981. * We don't know where this is set in the SEEPROM or by the
  8982. * BIOS, so we default to 100%. On Ultra2 controllers, use 75%
  8983. * instead.
  8984. */
  8985. if (temp_p->features & AHC_ULTRA2)
  8986. {
  8987. aic_outb(temp_p, RD_DFTHRSH_MAX | WR_DFTHRSH_MAX, DFF_THRSH);
  8988. }
  8989. else
  8990. {
  8991. aic_outb(temp_p, DFTHRSH_100, DSPCISTATUS);
  8992. }
  8993. /*
  8994. * Call our function to fixup any bugs that exist on this chipset.
  8995. * This may muck with PCI settings and other device settings, so
  8996. * make sure it's after all the other PCI and device register
  8997. * tweaks so it can back out bad settings on specific broken cards.
  8998. */
  8999. aic7xxx_configure_bugs(temp_p);
  9000. /* Hold a pci device reference */
  9001. pci_dev_get(temp_p->pdev);
  9002. if ( list_p == NULL )
  9003. {
  9004. list_p = current_p = temp_p;
  9005. }
  9006. else
  9007. {
  9008. current_p = list_p;
  9009. while(current_p->next != NULL)
  9010. current_p = current_p->next;
  9011. current_p->next = temp_p;
  9012. }
  9013. temp_p->next = NULL;
  9014. found++;
  9015. continue;
  9016. skip_pci_controller:
  9017. #ifdef CONFIG_PCI
  9018. pci_release_regions(temp_p->pdev);
  9019. #endif
  9020. kfree(temp_p);
  9021. } /* Found an Adaptec PCI device. */
  9022. else /* Well, we found one, but we couldn't get any memory */
  9023. {
  9024. printk("aic7xxx: Found <%s>\n",
  9025. board_names[aic_pdevs[i].board_name_index]);
  9026. printk(KERN_INFO "aic7xxx: Unable to allocate device memory, "
  9027. "skipping.\n");
  9028. }
  9029. } /* while(pdev=....) */
  9030. } /* for PCI_DEVICES */
  9031. }
  9032. #endif /* CONFIG_PCI */
  9033. #if defined(__i386__) || defined(__alpha__)
  9034. /*
  9035. * EISA/VL-bus card signature probe.
  9036. */
  9037. slot = MINSLOT;
  9038. while ( (slot <= MAXSLOT) &&
  9039. !(aic7xxx_no_probe) )
  9040. {
  9041. base = SLOTBASE(slot) + MINREG;
  9042. if (!request_region(base, MAXREG - MINREG, "aic7xxx"))
  9043. {
  9044. /*
  9045. * Some other driver has staked a
  9046. * claim to this i/o region already.
  9047. */
  9048. slot++;
  9049. continue; /* back to the beginning of the for loop */
  9050. }
  9051. flags = 0;
  9052. type = aic7xxx_probe(slot, base + AHC_HID0, &flags);
  9053. if (type == -1)
  9054. {
  9055. release_region(base, MAXREG - MINREG);
  9056. slot++;
  9057. continue;
  9058. }
  9059. temp_p = kmalloc(sizeof(struct aic7xxx_host), GFP_ATOMIC);
  9060. if (temp_p == NULL)
  9061. {
  9062. printk(KERN_WARNING "aic7xxx: Unable to allocate device space.\n");
  9063. release_region(base, MAXREG - MINREG);
  9064. slot++;
  9065. continue; /* back to the beginning of the while loop */
  9066. }
  9067. /*
  9068. * Pause the card preserving the IRQ type. Allow the operator
  9069. * to override the IRQ trigger.
  9070. */
  9071. if (aic7xxx_irq_trigger == 1)
  9072. hcntrl = IRQMS; /* Level */
  9073. else if (aic7xxx_irq_trigger == 0)
  9074. hcntrl = 0; /* Edge */
  9075. else
  9076. hcntrl = inb(base + HCNTRL) & IRQMS; /* Default */
  9077. memset(temp_p, 0, sizeof(struct aic7xxx_host));
  9078. temp_p->unpause = hcntrl | INTEN;
  9079. temp_p->pause = hcntrl | PAUSE | INTEN;
  9080. temp_p->base = base;
  9081. temp_p->mbase = 0;
  9082. temp_p->maddr = NULL;
  9083. temp_p->pci_bus = 0;
  9084. temp_p->pci_device_fn = slot;
  9085. aic_outb(temp_p, hcntrl | PAUSE, HCNTRL);
  9086. while( (aic_inb(temp_p, HCNTRL) & PAUSE) == 0 ) ;
  9087. if (aic7xxx_chip_reset(temp_p) == -1)
  9088. temp_p->irq = 0;
  9089. else
  9090. temp_p->irq = aic_inb(temp_p, INTDEF) & 0x0F;
  9091. temp_p->flags |= AHC_PAGESCBS;
  9092. switch (temp_p->irq)
  9093. {
  9094. case 9:
  9095. case 10:
  9096. case 11:
  9097. case 12:
  9098. case 14:
  9099. case 15:
  9100. break;
  9101. default:
  9102. printk(KERN_WARNING "aic7xxx: Host adapter uses unsupported IRQ "
  9103. "level %d, ignoring.\n", temp_p->irq);
  9104. kfree(temp_p);
  9105. release_region(base, MAXREG - MINREG);
  9106. slot++;
  9107. continue; /* back to the beginning of the while loop */
  9108. }
  9109. /*
  9110. * We are committed now, everything has been checked and this card
  9111. * has been found, now we just set it up
  9112. */
  9113. /*
  9114. * Insert our new struct into the list at the end
  9115. */
  9116. if (list_p == NULL)
  9117. {
  9118. list_p = current_p = temp_p;
  9119. }
  9120. else
  9121. {
  9122. current_p = list_p;
  9123. while (current_p->next != NULL)
  9124. current_p = current_p->next;
  9125. current_p->next = temp_p;
  9126. }
  9127. switch (type)
  9128. {
  9129. case 0:
  9130. temp_p->board_name_index = 2;
  9131. if (aic7xxx_verbose & VERBOSE_PROBE2)
  9132. printk("aic7xxx: <%s> at EISA %d\n",
  9133. board_names[2], slot);
  9134. /* FALLTHROUGH */
  9135. case 1:
  9136. {
  9137. temp_p->chip = AHC_AIC7770 | AHC_EISA;
  9138. temp_p->features |= AHC_AIC7770_FE;
  9139. temp_p->bios_control = aic_inb(temp_p, HA_274_BIOSCTRL);
  9140. /*
  9141. * Get the primary channel information. Right now we don't
  9142. * do anything with this, but someday we will be able to inform
  9143. * the mid-level SCSI code which channel is primary.
  9144. */
  9145. if (temp_p->board_name_index == 0)
  9146. {
  9147. temp_p->board_name_index = 3;
  9148. if (aic7xxx_verbose & VERBOSE_PROBE2)
  9149. printk("aic7xxx: <%s> at EISA %d\n",
  9150. board_names[3], slot);
  9151. }
  9152. if (temp_p->bios_control & CHANNEL_B_PRIMARY)
  9153. {
  9154. temp_p->flags |= AHC_CHANNEL_B_PRIMARY;
  9155. }
  9156. if ((temp_p->bios_control & BIOSMODE) == BIOSDISABLED)
  9157. {
  9158. temp_p->flags &= ~AHC_BIOS_ENABLED;
  9159. }
  9160. else
  9161. {
  9162. temp_p->flags &= ~AHC_USEDEFAULTS;
  9163. temp_p->flags |= AHC_BIOS_ENABLED;
  9164. if ( (temp_p->bios_control & 0x20) == 0 )
  9165. {
  9166. temp_p->bios_address = 0xcc000;
  9167. temp_p->bios_address += (0x4000 * (temp_p->bios_control & 0x07));
  9168. }
  9169. else
  9170. {
  9171. temp_p->bios_address = 0xd0000;
  9172. temp_p->bios_address += (0x8000 * (temp_p->bios_control & 0x06));
  9173. }
  9174. }
  9175. temp_p->adapter_control = aic_inb(temp_p, SCSICONF) << 8;
  9176. temp_p->adapter_control |= aic_inb(temp_p, SCSICONF + 1);
  9177. if (temp_p->features & AHC_WIDE)
  9178. {
  9179. temp_p->scsi_id = temp_p->adapter_control & HWSCSIID;
  9180. temp_p->scsi_id_b = temp_p->scsi_id;
  9181. }
  9182. else
  9183. {
  9184. temp_p->scsi_id = (temp_p->adapter_control >> 8) & HSCSIID;
  9185. temp_p->scsi_id_b = temp_p->adapter_control & HSCSIID;
  9186. }
  9187. aic7xxx_load_seeprom(temp_p, &sxfrctl1);
  9188. break;
  9189. }
  9190. case 2:
  9191. case 3:
  9192. temp_p->chip = AHC_AIC7770 | AHC_VL;
  9193. temp_p->features |= AHC_AIC7770_FE;
  9194. if (type == 2)
  9195. temp_p->flags |= AHC_BIOS_ENABLED;
  9196. else
  9197. temp_p->flags &= ~AHC_BIOS_ENABLED;
  9198. if (aic_inb(temp_p, SCSICONF) & TERM_ENB)
  9199. sxfrctl1 = STPWEN;
  9200. aic7xxx_load_seeprom(temp_p, &sxfrctl1);
  9201. temp_p->board_name_index = 4;
  9202. if (aic7xxx_verbose & VERBOSE_PROBE2)
  9203. printk("aic7xxx: <%s> at VLB %d\n",
  9204. board_names[2], slot);
  9205. switch( aic_inb(temp_p, STATUS_2840) & BIOS_SEL )
  9206. {
  9207. case 0x00:
  9208. temp_p->bios_address = 0xe0000;
  9209. break;
  9210. case 0x20:
  9211. temp_p->bios_address = 0xc8000;
  9212. break;
  9213. case 0x40:
  9214. temp_p->bios_address = 0xd0000;
  9215. break;
  9216. case 0x60:
  9217. temp_p->bios_address = 0xd8000;
  9218. break;
  9219. default:
  9220. break; /* can't get here */
  9221. }
  9222. break;
  9223. default: /* Won't get here. */
  9224. break;
  9225. }
  9226. if (aic7xxx_verbose & VERBOSE_PROBE2)
  9227. {
  9228. printk(KERN_INFO "aic7xxx: BIOS %sabled, IO Port 0x%lx, IRQ %d (%s)\n",
  9229. (temp_p->flags & AHC_USEDEFAULTS) ? "dis" : "en", temp_p->base,
  9230. temp_p->irq,
  9231. (temp_p->pause & IRQMS) ? "level sensitive" : "edge triggered");
  9232. printk(KERN_INFO "aic7xxx: Extended translation %sabled.\n",
  9233. (temp_p->flags & AHC_EXTEND_TRANS_A) ? "en" : "dis");
  9234. }
  9235. /*
  9236. * All the 7770 based chipsets have this bug
  9237. */
  9238. temp_p->bugs |= AHC_BUG_TMODE_WIDEODD;
  9239. /*
  9240. * Set the FIFO threshold and the bus off time.
  9241. */
  9242. hostconf = aic_inb(temp_p, HOSTCONF);
  9243. aic_outb(temp_p, hostconf & DFTHRSH, BUSSPD);
  9244. aic_outb(temp_p, (hostconf << 2) & BOFF, BUSTIME);
  9245. slot++;
  9246. found++;
  9247. }
  9248. #endif /* defined(__i386__) || defined(__alpha__) */
  9249. /*
  9250. * Now, we re-order the probed devices by BIOS address and BUS class.
  9251. * In general, we follow this algorithm to make the adapters show up
  9252. * in the same order under linux that the computer finds them.
  9253. * 1: All VLB/EISA cards with BIOS_ENABLED first, according to BIOS
  9254. * address, going from lowest to highest.
  9255. * 2: All PCI controllers with BIOS_ENABLED next, according to BIOS
  9256. * address, going from lowest to highest.
  9257. * 3: Remaining VLB/EISA controllers going in slot order.
  9258. * 4: Remaining PCI controllers, going in PCI device order (reversible)
  9259. */
  9260. {
  9261. struct aic7xxx_host *sort_list[4] = { NULL, NULL, NULL, NULL };
  9262. struct aic7xxx_host *vlb, *pci;
  9263. struct aic7xxx_host *prev_p;
  9264. struct aic7xxx_host *p;
  9265. unsigned char left;
  9266. prev_p = vlb = pci = NULL;
  9267. temp_p = list_p;
  9268. while (temp_p != NULL)
  9269. {
  9270. switch(temp_p->chip & ~AHC_CHIPID_MASK)
  9271. {
  9272. case AHC_EISA:
  9273. case AHC_VL:
  9274. {
  9275. p = temp_p;
  9276. if (p->flags & AHC_BIOS_ENABLED)
  9277. vlb = sort_list[0];
  9278. else
  9279. vlb = sort_list[2];
  9280. if (vlb == NULL)
  9281. {
  9282. vlb = temp_p;
  9283. temp_p = temp_p->next;
  9284. vlb->next = NULL;
  9285. }
  9286. else
  9287. {
  9288. current_p = vlb;
  9289. prev_p = NULL;
  9290. while ( (current_p != NULL) &&
  9291. (current_p->bios_address < temp_p->bios_address))
  9292. {
  9293. prev_p = current_p;
  9294. current_p = current_p->next;
  9295. }
  9296. if (prev_p != NULL)
  9297. {
  9298. prev_p->next = temp_p;
  9299. temp_p = temp_p->next;
  9300. prev_p->next->next = current_p;
  9301. }
  9302. else
  9303. {
  9304. vlb = temp_p;
  9305. temp_p = temp_p->next;
  9306. vlb->next = current_p;
  9307. }
  9308. }
  9309. if (p->flags & AHC_BIOS_ENABLED)
  9310. sort_list[0] = vlb;
  9311. else
  9312. sort_list[2] = vlb;
  9313. break;
  9314. }
  9315. default: /* All PCI controllers fall through to default */
  9316. {
  9317. p = temp_p;
  9318. if (p->flags & AHC_BIOS_ENABLED)
  9319. pci = sort_list[1];
  9320. else
  9321. pci = sort_list[3];
  9322. if (pci == NULL)
  9323. {
  9324. pci = temp_p;
  9325. temp_p = temp_p->next;
  9326. pci->next = NULL;
  9327. }
  9328. else
  9329. {
  9330. current_p = pci;
  9331. prev_p = NULL;
  9332. if (!aic7xxx_reverse_scan)
  9333. {
  9334. while ( (current_p != NULL) &&
  9335. ( (PCI_SLOT(current_p->pci_device_fn) |
  9336. (current_p->pci_bus << 8)) <
  9337. (PCI_SLOT(temp_p->pci_device_fn) |
  9338. (temp_p->pci_bus << 8)) ) )
  9339. {
  9340. prev_p = current_p;
  9341. current_p = current_p->next;
  9342. }
  9343. }
  9344. else
  9345. {
  9346. while ( (current_p != NULL) &&
  9347. ( (PCI_SLOT(current_p->pci_device_fn) |
  9348. (current_p->pci_bus << 8)) >
  9349. (PCI_SLOT(temp_p->pci_device_fn) |
  9350. (temp_p->pci_bus << 8)) ) )
  9351. {
  9352. prev_p = current_p;
  9353. current_p = current_p->next;
  9354. }
  9355. }
  9356. /*
  9357. * Are we dealing with a 7895/6/7/9 where we need to sort the
  9358. * channels as well, if so, the bios_address values should
  9359. * be the same
  9360. */
  9361. if ( (current_p) && (temp_p->flags & AHC_MULTI_CHANNEL) &&
  9362. (temp_p->pci_bus == current_p->pci_bus) &&
  9363. (PCI_SLOT(temp_p->pci_device_fn) ==
  9364. PCI_SLOT(current_p->pci_device_fn)) )
  9365. {
  9366. if (temp_p->flags & AHC_CHNLB)
  9367. {
  9368. if ( !(temp_p->flags & AHC_CHANNEL_B_PRIMARY) )
  9369. {
  9370. prev_p = current_p;
  9371. current_p = current_p->next;
  9372. }
  9373. }
  9374. else
  9375. {
  9376. if (temp_p->flags & AHC_CHANNEL_B_PRIMARY)
  9377. {
  9378. prev_p = current_p;
  9379. current_p = current_p->next;
  9380. }
  9381. }
  9382. }
  9383. if (prev_p != NULL)
  9384. {
  9385. prev_p->next = temp_p;
  9386. temp_p = temp_p->next;
  9387. prev_p->next->next = current_p;
  9388. }
  9389. else
  9390. {
  9391. pci = temp_p;
  9392. temp_p = temp_p->next;
  9393. pci->next = current_p;
  9394. }
  9395. }
  9396. if (p->flags & AHC_BIOS_ENABLED)
  9397. sort_list[1] = pci;
  9398. else
  9399. sort_list[3] = pci;
  9400. break;
  9401. }
  9402. } /* End of switch(temp_p->type) */
  9403. } /* End of while (temp_p != NULL) */
  9404. /*
  9405. * At this point, the cards have been broken into 4 sorted lists, now
  9406. * we run through the lists in order and register each controller
  9407. */
  9408. {
  9409. int i;
  9410. left = found;
  9411. for (i=0; i<ARRAY_SIZE(sort_list); i++)
  9412. {
  9413. temp_p = sort_list[i];
  9414. while(temp_p != NULL)
  9415. {
  9416. template->name = board_names[temp_p->board_name_index];
  9417. p = aic7xxx_alloc(template, temp_p);
  9418. if (p != NULL)
  9419. {
  9420. p->instance = found - left;
  9421. if (aic7xxx_register(template, p, (--left)) == 0)
  9422. {
  9423. found--;
  9424. aic7xxx_release(p->host);
  9425. scsi_unregister(p->host);
  9426. }
  9427. else if (aic7xxx_dump_card)
  9428. {
  9429. pause_sequencer(p);
  9430. aic7xxx_print_card(p);
  9431. aic7xxx_print_scratch_ram(p);
  9432. unpause_sequencer(p, TRUE);
  9433. }
  9434. }
  9435. current_p = temp_p;
  9436. temp_p = (struct aic7xxx_host *)temp_p->next;
  9437. kfree(current_p);
  9438. }
  9439. }
  9440. }
  9441. }
  9442. return (found);
  9443. }
  9444. /*+F*************************************************************************
  9445. * Function:
  9446. * aic7xxx_buildscb
  9447. *
  9448. * Description:
  9449. * Build a SCB.
  9450. *-F*************************************************************************/
  9451. static void aic7xxx_buildscb(struct aic7xxx_host *p, struct scsi_cmnd *cmd,
  9452. struct aic7xxx_scb *scb)
  9453. {
  9454. unsigned short mask;
  9455. struct aic7xxx_hwscb *hscb;
  9456. struct aic_dev_data *aic_dev = cmd->device->hostdata;
  9457. struct scsi_device *sdptr = cmd->device;
  9458. unsigned char tindex = TARGET_INDEX(cmd);
  9459. int use_sg;
  9460. mask = (0x01 << tindex);
  9461. hscb = scb->hscb;
  9462. /*
  9463. * Setup the control byte if we need negotiation and have not
  9464. * already requested it.
  9465. */
  9466. hscb->control = 0;
  9467. scb->tag_action = 0;
  9468. if (p->discenable & mask)
  9469. {
  9470. hscb->control |= DISCENB;
  9471. /* We always force TEST_UNIT_READY to untagged */
  9472. if (cmd->cmnd[0] != TEST_UNIT_READY && sdptr->simple_tags)
  9473. {
  9474. hscb->control |= MSG_SIMPLE_Q_TAG;
  9475. scb->tag_action = MSG_SIMPLE_Q_TAG;
  9476. }
  9477. }
  9478. if ( !(aic_dev->dtr_pending) &&
  9479. (aic_dev->needppr || aic_dev->needwdtr || aic_dev->needsdtr) &&
  9480. (aic_dev->flags & DEVICE_DTR_SCANNED) )
  9481. {
  9482. aic_dev->dtr_pending = 1;
  9483. scb->tag_action = 0;
  9484. hscb->control &= DISCENB;
  9485. hscb->control |= MK_MESSAGE;
  9486. if(aic_dev->needppr)
  9487. {
  9488. scb->flags |= SCB_MSGOUT_PPR;
  9489. }
  9490. else if(aic_dev->needwdtr)
  9491. {
  9492. scb->flags |= SCB_MSGOUT_WDTR;
  9493. }
  9494. else if(aic_dev->needsdtr)
  9495. {
  9496. scb->flags |= SCB_MSGOUT_SDTR;
  9497. }
  9498. scb->flags |= SCB_DTR_SCB;
  9499. }
  9500. hscb->target_channel_lun = ((cmd->device->id << 4) & 0xF0) |
  9501. ((cmd->device->channel & 0x01) << 3) | (cmd->device->lun & 0x07);
  9502. /*
  9503. * The interpretation of request_buffer and request_bufflen
  9504. * changes depending on whether or not use_sg is zero; a
  9505. * non-zero use_sg indicates the number of elements in the
  9506. * scatter-gather array.
  9507. */
  9508. /*
  9509. * XXX - this relies on the host data being stored in a
  9510. * little-endian format.
  9511. */
  9512. hscb->SCSI_cmd_length = cmd->cmd_len;
  9513. memcpy(scb->cmnd, cmd->cmnd, cmd->cmd_len);
  9514. hscb->SCSI_cmd_pointer = cpu_to_le32(SCB_DMA_ADDR(scb, scb->cmnd));
  9515. use_sg = scsi_dma_map(cmd);
  9516. BUG_ON(use_sg < 0);
  9517. if (use_sg) {
  9518. struct scatterlist *sg; /* Must be mid-level SCSI code scatterlist */
  9519. /*
  9520. * We must build an SG list in adapter format, as the kernel's SG list
  9521. * cannot be used directly because of data field size (__alpha__)
  9522. * differences and the kernel SG list uses virtual addresses where
  9523. * we need physical addresses.
  9524. */
  9525. int i;
  9526. scb->sg_length = 0;
  9527. /*
  9528. * Copy the segments into the SG array. NOTE!!! - We used to
  9529. * have the first entry both in the data_pointer area and the first
  9530. * SG element. That has changed somewhat. We still have the first
  9531. * entry in both places, but now we download the address of
  9532. * scb->sg_list[1] instead of 0 to the sg pointer in the hscb.
  9533. */
  9534. scsi_for_each_sg(cmd, sg, use_sg, i) {
  9535. unsigned int len = sg_dma_len(sg);
  9536. scb->sg_list[i].address = cpu_to_le32(sg_dma_address(sg));
  9537. scb->sg_list[i].length = cpu_to_le32(len);
  9538. scb->sg_length += len;
  9539. }
  9540. /* Copy the first SG into the data pointer area. */
  9541. hscb->data_pointer = scb->sg_list[0].address;
  9542. hscb->data_count = scb->sg_list[0].length;
  9543. scb->sg_count = i;
  9544. hscb->SG_segment_count = i;
  9545. hscb->SG_list_pointer = cpu_to_le32(SCB_DMA_ADDR(scb, &scb->sg_list[1]));
  9546. } else {
  9547. scb->sg_count = 0;
  9548. scb->sg_length = 0;
  9549. hscb->SG_segment_count = 0;
  9550. hscb->SG_list_pointer = 0;
  9551. hscb->data_count = 0;
  9552. hscb->data_pointer = 0;
  9553. }
  9554. }
  9555. /*+F*************************************************************************
  9556. * Function:
  9557. * aic7xxx_queue
  9558. *
  9559. * Description:
  9560. * Queue a SCB to the controller.
  9561. *-F*************************************************************************/
  9562. static int aic7xxx_queue_lck(struct scsi_cmnd *cmd, void (*fn)(struct scsi_cmnd *))
  9563. {
  9564. struct aic7xxx_host *p;
  9565. struct aic7xxx_scb *scb;
  9566. struct aic_dev_data *aic_dev;
  9567. p = (struct aic7xxx_host *) cmd->device->host->hostdata;
  9568. aic_dev = cmd->device->hostdata;
  9569. #ifdef AIC7XXX_VERBOSE_DEBUGGING
  9570. if (aic_dev->active_cmds > aic_dev->max_q_depth)
  9571. {
  9572. printk(WARN_LEAD "Commands queued exceeds queue "
  9573. "depth, active=%d\n",
  9574. p->host_no, CTL_OF_CMD(cmd),
  9575. aic_dev->active_cmds);
  9576. }
  9577. #endif
  9578. scb = scbq_remove_head(&p->scb_data->free_scbs);
  9579. if (scb == NULL)
  9580. {
  9581. aic7xxx_allocate_scb(p);
  9582. scb = scbq_remove_head(&p->scb_data->free_scbs);
  9583. if(scb == NULL)
  9584. {
  9585. printk(WARN_LEAD "Couldn't get a free SCB.\n", p->host_no,
  9586. CTL_OF_CMD(cmd));
  9587. return 1;
  9588. }
  9589. }
  9590. scb->cmd = cmd;
  9591. /*
  9592. * Make sure the scsi_cmnd pointer is saved, the struct it points to
  9593. * is set up properly, and the parity error flag is reset, then send
  9594. * the SCB to the sequencer and watch the fun begin.
  9595. */
  9596. aic7xxx_position(cmd) = scb->hscb->tag;
  9597. cmd->scsi_done = fn;
  9598. cmd->result = DID_OK;
  9599. aic7xxx_error(cmd) = DID_OK;
  9600. aic7xxx_status(cmd) = 0;
  9601. cmd->host_scribble = NULL;
  9602. /*
  9603. * Construct the SCB beforehand, so the sequencer is
  9604. * paused a minimal amount of time.
  9605. */
  9606. aic7xxx_buildscb(p, cmd, scb);
  9607. scb->flags |= SCB_ACTIVE | SCB_WAITINGQ;
  9608. scbq_insert_tail(&p->waiting_scbs, scb);
  9609. aic7xxx_run_waiting_queues(p);
  9610. return (0);
  9611. }
  9612. static DEF_SCSI_QCMD(aic7xxx_queue)
  9613. /*+F*************************************************************************
  9614. * Function:
  9615. * aic7xxx_bus_device_reset
  9616. *
  9617. * Description:
  9618. * Abort or reset the current SCSI command(s). If the scb has not
  9619. * previously been aborted, then we attempt to send a BUS_DEVICE_RESET
  9620. * message to the target. If the scb has previously been unsuccessfully
  9621. * aborted, then we will reset the channel and have all devices renegotiate.
  9622. * Returns an enumerated type that indicates the status of the operation.
  9623. *-F*************************************************************************/
  9624. static int __aic7xxx_bus_device_reset(struct scsi_cmnd *cmd)
  9625. {
  9626. struct aic7xxx_host *p;
  9627. struct aic7xxx_scb *scb;
  9628. struct aic7xxx_hwscb *hscb;
  9629. int channel;
  9630. unsigned char saved_scbptr, lastphase;
  9631. unsigned char hscb_index;
  9632. int disconnected;
  9633. struct aic_dev_data *aic_dev;
  9634. if(cmd == NULL)
  9635. {
  9636. printk(KERN_ERR "aic7xxx_bus_device_reset: called with NULL cmd!\n");
  9637. return FAILED;
  9638. }
  9639. p = (struct aic7xxx_host *)cmd->device->host->hostdata;
  9640. aic_dev = AIC_DEV(cmd);
  9641. if(aic7xxx_position(cmd) < p->scb_data->numscbs)
  9642. scb = (p->scb_data->scb_array[aic7xxx_position(cmd)]);
  9643. else
  9644. return FAILED;
  9645. hscb = scb->hscb;
  9646. aic7xxx_isr(p);
  9647. aic7xxx_done_cmds_complete(p);
  9648. /* If the command was already complete or just completed, then we didn't
  9649. * do a reset, return FAILED */
  9650. if(!(scb->flags & SCB_ACTIVE))
  9651. return FAILED;
  9652. pause_sequencer(p);
  9653. lastphase = aic_inb(p, LASTPHASE);
  9654. if (aic7xxx_verbose & VERBOSE_RESET_PROCESS)
  9655. {
  9656. printk(INFO_LEAD "Bus Device reset, scb flags 0x%x, ",
  9657. p->host_no, CTL_OF_SCB(scb), scb->flags);
  9658. switch (lastphase)
  9659. {
  9660. case P_DATAOUT:
  9661. printk("Data-Out phase\n");
  9662. break;
  9663. case P_DATAIN:
  9664. printk("Data-In phase\n");
  9665. break;
  9666. case P_COMMAND:
  9667. printk("Command phase\n");
  9668. break;
  9669. case P_MESGOUT:
  9670. printk("Message-Out phase\n");
  9671. break;
  9672. case P_STATUS:
  9673. printk("Status phase\n");
  9674. break;
  9675. case P_MESGIN:
  9676. printk("Message-In phase\n");
  9677. break;
  9678. default:
  9679. /*
  9680. * We're not in a valid phase, so assume we're idle.
  9681. */
  9682. printk("while idle, LASTPHASE = 0x%x\n", lastphase);
  9683. break;
  9684. }
  9685. printk(INFO_LEAD "SCSISIGI 0x%x, SEQADDR 0x%x, SSTAT0 0x%x, SSTAT1 "
  9686. "0x%x\n", p->host_no, CTL_OF_SCB(scb),
  9687. aic_inb(p, SCSISIGI),
  9688. aic_inb(p, SEQADDR0) | (aic_inb(p, SEQADDR1) << 8),
  9689. aic_inb(p, SSTAT0), aic_inb(p, SSTAT1));
  9690. printk(INFO_LEAD "SG_CACHEPTR 0x%x, SSTAT2 0x%x, STCNT 0x%x\n", p->host_no,
  9691. CTL_OF_SCB(scb),
  9692. (p->features & AHC_ULTRA2) ? aic_inb(p, SG_CACHEPTR) : 0,
  9693. aic_inb(p, SSTAT2),
  9694. aic_inb(p, STCNT + 2) << 16 | aic_inb(p, STCNT + 1) << 8 |
  9695. aic_inb(p, STCNT));
  9696. }
  9697. channel = cmd->device->channel;
  9698. /*
  9699. * Send a Device Reset Message:
  9700. * The target that is holding up the bus may not be the same as
  9701. * the one that triggered this timeout (different commands have
  9702. * different timeout lengths). Our strategy here is to queue an
  9703. * abort message to the timed out target if it is disconnected.
  9704. * Otherwise, if we have an active target we stuff the message buffer
  9705. * with an abort message and assert ATN in the hopes that the target
  9706. * will let go of the bus and go to the mesgout phase. If this
  9707. * fails, we'll get another timeout a few seconds later which will
  9708. * attempt a bus reset.
  9709. */
  9710. saved_scbptr = aic_inb(p, SCBPTR);
  9711. disconnected = FALSE;
  9712. if (lastphase != P_BUSFREE)
  9713. {
  9714. if (aic_inb(p, SCB_TAG) >= p->scb_data->numscbs)
  9715. {
  9716. printk(WARN_LEAD "Invalid SCB ID %d is active, "
  9717. "SCB flags = 0x%x.\n", p->host_no,
  9718. CTL_OF_CMD(cmd), scb->hscb->tag, scb->flags);
  9719. unpause_sequencer(p, FALSE);
  9720. return FAILED;
  9721. }
  9722. if (scb->hscb->tag == aic_inb(p, SCB_TAG))
  9723. {
  9724. if ( (lastphase == P_MESGOUT) || (lastphase == P_MESGIN) )
  9725. {
  9726. printk(WARN_LEAD "Device reset, Message buffer "
  9727. "in use\n", p->host_no, CTL_OF_SCB(scb));
  9728. unpause_sequencer(p, FALSE);
  9729. return FAILED;
  9730. }
  9731. if (aic7xxx_verbose & VERBOSE_RESET_PROCESS)
  9732. printk(INFO_LEAD "Device reset message in "
  9733. "message buffer\n", p->host_no, CTL_OF_SCB(scb));
  9734. scb->flags |= SCB_RESET | SCB_DEVICE_RESET;
  9735. aic7xxx_error(cmd) = DID_RESET;
  9736. aic_dev->flags |= BUS_DEVICE_RESET_PENDING;
  9737. /* Send the abort message to the active SCB. */
  9738. aic_outb(p, HOST_MSG, MSG_OUT);
  9739. aic_outb(p, lastphase | ATNO, SCSISIGO);
  9740. unpause_sequencer(p, FALSE);
  9741. spin_unlock_irq(p->host->host_lock);
  9742. ssleep(1);
  9743. spin_lock_irq(p->host->host_lock);
  9744. if(aic_dev->flags & BUS_DEVICE_RESET_PENDING)
  9745. return FAILED;
  9746. else
  9747. return SUCCESS;
  9748. }
  9749. } /* if (last_phase != P_BUSFREE).....indicates we are idle and can work */
  9750. /*
  9751. * Simply set the MK_MESSAGE flag and the SEQINT handler will do
  9752. * the rest on a reconnect/connect.
  9753. */
  9754. scb->hscb->control |= MK_MESSAGE;
  9755. scb->flags |= SCB_RESET | SCB_DEVICE_RESET;
  9756. aic_dev->flags |= BUS_DEVICE_RESET_PENDING;
  9757. /*
  9758. * Check to see if the command is on the qinfifo. If it is, then we will
  9759. * not need to queue the command again since the card should start it soon
  9760. */
  9761. if (aic7xxx_search_qinfifo(p, cmd->device->channel, cmd->device->id, cmd->device->lun, hscb->tag,
  9762. 0, TRUE, NULL) == 0)
  9763. {
  9764. disconnected = TRUE;
  9765. if ((hscb_index = aic7xxx_find_scb(p, scb)) != SCB_LIST_NULL)
  9766. {
  9767. unsigned char scb_control;
  9768. aic_outb(p, hscb_index, SCBPTR);
  9769. scb_control = aic_inb(p, SCB_CONTROL);
  9770. /*
  9771. * If the DISCONNECTED bit is not set in SCB_CONTROL, then we are
  9772. * actually on the waiting list, not disconnected, and we don't
  9773. * need to requeue the command.
  9774. */
  9775. disconnected = (scb_control & DISCONNECTED);
  9776. aic_outb(p, scb_control | MK_MESSAGE, SCB_CONTROL);
  9777. }
  9778. if (disconnected)
  9779. {
  9780. /*
  9781. * Actually requeue this SCB in case we can select the
  9782. * device before it reconnects. This can result in the command
  9783. * being on the qinfifo twice, but we don't care because it will
  9784. * all get cleaned up if/when the reset takes place.
  9785. */
  9786. if (aic7xxx_verbose & VERBOSE_RESET_PROCESS)
  9787. printk(INFO_LEAD "Queueing device reset command.\n", p->host_no,
  9788. CTL_OF_SCB(scb));
  9789. p->qinfifo[p->qinfifonext++] = scb->hscb->tag;
  9790. if (p->features & AHC_QUEUE_REGS)
  9791. aic_outb(p, p->qinfifonext, HNSCB_QOFF);
  9792. else
  9793. aic_outb(p, p->qinfifonext, KERNEL_QINPOS);
  9794. scb->flags |= SCB_QUEUED_ABORT;
  9795. }
  9796. }
  9797. aic_outb(p, saved_scbptr, SCBPTR);
  9798. unpause_sequencer(p, FALSE);
  9799. spin_unlock_irq(p->host->host_lock);
  9800. msleep(1000/4);
  9801. spin_lock_irq(p->host->host_lock);
  9802. if(aic_dev->flags & BUS_DEVICE_RESET_PENDING)
  9803. return FAILED;
  9804. else
  9805. return SUCCESS;
  9806. }
  9807. static int aic7xxx_bus_device_reset(struct scsi_cmnd *cmd)
  9808. {
  9809. int rc;
  9810. spin_lock_irq(cmd->device->host->host_lock);
  9811. rc = __aic7xxx_bus_device_reset(cmd);
  9812. spin_unlock_irq(cmd->device->host->host_lock);
  9813. return rc;
  9814. }
  9815. /*+F*************************************************************************
  9816. * Function:
  9817. * aic7xxx_panic_abort
  9818. *
  9819. * Description:
  9820. * Abort the current SCSI command(s).
  9821. *-F*************************************************************************/
  9822. static void aic7xxx_panic_abort(struct aic7xxx_host *p, struct scsi_cmnd *cmd)
  9823. {
  9824. printk("aic7xxx driver version %s\n", AIC7XXX_C_VERSION);
  9825. printk("Controller type:\n %s\n", board_names[p->board_name_index]);
  9826. printk("p->flags=0x%lx, p->chip=0x%x, p->features=0x%x, "
  9827. "sequencer %s paused\n",
  9828. p->flags, p->chip, p->features,
  9829. (aic_inb(p, HCNTRL) & PAUSE) ? "is" : "isn't" );
  9830. pause_sequencer(p);
  9831. disable_irq(p->irq);
  9832. aic7xxx_print_card(p);
  9833. aic7xxx_print_scratch_ram(p);
  9834. spin_unlock_irq(p->host->host_lock);
  9835. for(;;) barrier();
  9836. }
  9837. /*+F*************************************************************************
  9838. * Function:
  9839. * aic7xxx_abort
  9840. *
  9841. * Description:
  9842. * Abort the current SCSI command(s).
  9843. *-F*************************************************************************/
  9844. static int __aic7xxx_abort(struct scsi_cmnd *cmd)
  9845. {
  9846. struct aic7xxx_scb *scb = NULL;
  9847. struct aic7xxx_host *p;
  9848. int found=0, disconnected;
  9849. unsigned char saved_hscbptr, hscbptr, scb_control;
  9850. struct aic_dev_data *aic_dev;
  9851. if(cmd == NULL)
  9852. {
  9853. printk(KERN_ERR "aic7xxx_abort: called with NULL cmd!\n");
  9854. return FAILED;
  9855. }
  9856. p = (struct aic7xxx_host *)cmd->device->host->hostdata;
  9857. aic_dev = AIC_DEV(cmd);
  9858. if(aic7xxx_position(cmd) < p->scb_data->numscbs)
  9859. scb = (p->scb_data->scb_array[aic7xxx_position(cmd)]);
  9860. else
  9861. return FAILED;
  9862. aic7xxx_isr(p);
  9863. aic7xxx_done_cmds_complete(p);
  9864. /* If the command was already complete or just completed, then we didn't
  9865. * do a reset, return FAILED */
  9866. if(!(scb->flags & SCB_ACTIVE))
  9867. return FAILED;
  9868. pause_sequencer(p);
  9869. /*
  9870. * I added a new config option to the driver: "panic_on_abort" that will
  9871. * cause the driver to panic and the machine to stop on the first abort
  9872. * or reset call into the driver. At that point, it prints out a lot of
  9873. * useful information for me which I can then use to try and debug the
  9874. * problem. Simply enable the boot time prompt in order to activate this
  9875. * code.
  9876. */
  9877. if (aic7xxx_panic_on_abort)
  9878. aic7xxx_panic_abort(p, cmd);
  9879. if (aic7xxx_verbose & VERBOSE_ABORT)
  9880. {
  9881. printk(INFO_LEAD "Aborting scb %d, flags 0x%x, SEQADDR 0x%x, LASTPHASE "
  9882. "0x%x\n",
  9883. p->host_no, CTL_OF_SCB(scb), scb->hscb->tag, scb->flags,
  9884. aic_inb(p, SEQADDR0) | (aic_inb(p, SEQADDR1) << 8),
  9885. aic_inb(p, LASTPHASE));
  9886. printk(INFO_LEAD "SG_CACHEPTR 0x%x, SG_COUNT %d, SCSISIGI 0x%x\n",
  9887. p->host_no, CTL_OF_SCB(scb), (p->features & AHC_ULTRA2) ?
  9888. aic_inb(p, SG_CACHEPTR) : 0, aic_inb(p, SG_COUNT),
  9889. aic_inb(p, SCSISIGI));
  9890. printk(INFO_LEAD "SSTAT0 0x%x, SSTAT1 0x%x, SSTAT2 0x%x\n",
  9891. p->host_no, CTL_OF_SCB(scb), aic_inb(p, SSTAT0),
  9892. aic_inb(p, SSTAT1), aic_inb(p, SSTAT2));
  9893. }
  9894. if (scb->flags & SCB_WAITINGQ)
  9895. {
  9896. if (aic7xxx_verbose & VERBOSE_ABORT_PROCESS)
  9897. printk(INFO_LEAD "SCB found on waiting list and "
  9898. "aborted.\n", p->host_no, CTL_OF_SCB(scb));
  9899. scbq_remove(&p->waiting_scbs, scb);
  9900. scbq_remove(&aic_dev->delayed_scbs, scb);
  9901. aic_dev->active_cmds++;
  9902. p->activescbs++;
  9903. scb->flags &= ~(SCB_WAITINGQ | SCB_ACTIVE);
  9904. scb->flags |= SCB_ABORT | SCB_QUEUED_FOR_DONE;
  9905. goto success;
  9906. }
  9907. /*
  9908. * We just checked the waiting_q, now for the QINFIFO
  9909. */
  9910. if ( ((found = aic7xxx_search_qinfifo(p, cmd->device->id, cmd->device->channel,
  9911. cmd->device->lun, scb->hscb->tag, SCB_ABORT | SCB_QUEUED_FOR_DONE,
  9912. FALSE, NULL)) != 0) &&
  9913. (aic7xxx_verbose & VERBOSE_ABORT_PROCESS))
  9914. {
  9915. printk(INFO_LEAD "SCB found in QINFIFO and aborted.\n", p->host_no,
  9916. CTL_OF_SCB(scb));
  9917. goto success;
  9918. }
  9919. /*
  9920. * QINFIFO, waitingq, completeq done. Next, check WAITING_SCB list in card
  9921. */
  9922. saved_hscbptr = aic_inb(p, SCBPTR);
  9923. if ((hscbptr = aic7xxx_find_scb(p, scb)) != SCB_LIST_NULL)
  9924. {
  9925. aic_outb(p, hscbptr, SCBPTR);
  9926. scb_control = aic_inb(p, SCB_CONTROL);
  9927. disconnected = scb_control & DISCONNECTED;
  9928. /*
  9929. * If the DISCONNECTED bit is not set in SCB_CONTROL, then we are
  9930. * either currently active or on the waiting list.
  9931. */
  9932. if(!disconnected && aic_inb(p, LASTPHASE) == P_BUSFREE) {
  9933. if (aic7xxx_verbose & VERBOSE_ABORT_PROCESS)
  9934. printk(INFO_LEAD "SCB found on hardware waiting"
  9935. " list and aborted.\n", p->host_no, CTL_OF_SCB(scb));
  9936. /* If we are the only waiting command, stop the selection engine */
  9937. if (aic_inb(p, WAITING_SCBH) == hscbptr && aic_inb(p, SCB_NEXT) ==
  9938. SCB_LIST_NULL)
  9939. {
  9940. aic_outb(p, aic_inb(p, SCSISEQ) & ~ENSELO, SCSISEQ);
  9941. aic_outb(p, CLRSELTIMEO, CLRSINT1);
  9942. aic_outb(p, SCB_LIST_NULL, WAITING_SCBH);
  9943. }
  9944. else
  9945. {
  9946. unsigned char prev, next;
  9947. prev = SCB_LIST_NULL;
  9948. next = aic_inb(p, WAITING_SCBH);
  9949. while(next != SCB_LIST_NULL)
  9950. {
  9951. aic_outb(p, next, SCBPTR);
  9952. if (next == hscbptr)
  9953. {
  9954. next = aic_inb(p, SCB_NEXT);
  9955. if (prev != SCB_LIST_NULL)
  9956. {
  9957. aic_outb(p, prev, SCBPTR);
  9958. aic_outb(p, next, SCB_NEXT);
  9959. }
  9960. else
  9961. aic_outb(p, next, WAITING_SCBH);
  9962. aic_outb(p, hscbptr, SCBPTR);
  9963. next = SCB_LIST_NULL;
  9964. }
  9965. else
  9966. {
  9967. prev = next;
  9968. next = aic_inb(p, SCB_NEXT);
  9969. }
  9970. }
  9971. }
  9972. aic_outb(p, SCB_LIST_NULL, SCB_TAG);
  9973. aic_outb(p, 0, SCB_CONTROL);
  9974. aic7xxx_add_curscb_to_free_list(p);
  9975. scb->flags = SCB_ABORT | SCB_QUEUED_FOR_DONE;
  9976. goto success;
  9977. }
  9978. else if (!disconnected)
  9979. {
  9980. /*
  9981. * We are the currently active command
  9982. */
  9983. if((aic_inb(p, LASTPHASE) == P_MESGIN) ||
  9984. (aic_inb(p, LASTPHASE) == P_MESGOUT))
  9985. {
  9986. /*
  9987. * Message buffer busy, unable to abort
  9988. */
  9989. printk(INFO_LEAD "message buffer busy, unable to abort.\n",
  9990. p->host_no, CTL_OF_SCB(scb));
  9991. unpause_sequencer(p, FALSE);
  9992. return FAILED;
  9993. }
  9994. /* Fallthrough to below, set ATNO after we set SCB_CONTROL */
  9995. }
  9996. aic_outb(p, scb_control | MK_MESSAGE, SCB_CONTROL);
  9997. if(!disconnected)
  9998. {
  9999. aic_outb(p, HOST_MSG, MSG_OUT);
  10000. aic_outb(p, aic_inb(p, SCSISIGI) | ATNO, SCSISIGO);
  10001. }
  10002. aic_outb(p, saved_hscbptr, SCBPTR);
  10003. }
  10004. else
  10005. {
  10006. /*
  10007. * The scb isn't in the card at all and it is active and it isn't in
  10008. * any of the queues, so it must be disconnected and paged out. Fall
  10009. * through to the code below.
  10010. */
  10011. disconnected = 1;
  10012. }
  10013. p->flags |= AHC_ABORT_PENDING;
  10014. scb->flags |= SCB_QUEUED_ABORT | SCB_ABORT | SCB_RECOVERY_SCB;
  10015. scb->hscb->control |= MK_MESSAGE;
  10016. if(disconnected)
  10017. {
  10018. if (aic7xxx_verbose & VERBOSE_ABORT_PROCESS)
  10019. printk(INFO_LEAD "SCB disconnected. Queueing Abort"
  10020. " SCB.\n", p->host_no, CTL_OF_SCB(scb));
  10021. p->qinfifo[p->qinfifonext++] = scb->hscb->tag;
  10022. if (p->features & AHC_QUEUE_REGS)
  10023. aic_outb(p, p->qinfifonext, HNSCB_QOFF);
  10024. else
  10025. aic_outb(p, p->qinfifonext, KERNEL_QINPOS);
  10026. }
  10027. unpause_sequencer(p, FALSE);
  10028. spin_unlock_irq(p->host->host_lock);
  10029. msleep(1000/4);
  10030. spin_lock_irq(p->host->host_lock);
  10031. if (p->flags & AHC_ABORT_PENDING)
  10032. {
  10033. if (aic7xxx_verbose & VERBOSE_ABORT_RETURN)
  10034. printk(INFO_LEAD "Abort never delivered, returning FAILED\n", p->host_no,
  10035. CTL_OF_CMD(cmd));
  10036. p->flags &= ~AHC_ABORT_PENDING;
  10037. return FAILED;
  10038. }
  10039. if (aic7xxx_verbose & VERBOSE_ABORT_RETURN)
  10040. printk(INFO_LEAD "Abort successful.\n", p->host_no, CTL_OF_CMD(cmd));
  10041. return SUCCESS;
  10042. success:
  10043. if (aic7xxx_verbose & VERBOSE_ABORT_RETURN)
  10044. printk(INFO_LEAD "Abort successful.\n", p->host_no, CTL_OF_CMD(cmd));
  10045. aic7xxx_run_done_queue(p, TRUE);
  10046. unpause_sequencer(p, FALSE);
  10047. return SUCCESS;
  10048. }
  10049. static int aic7xxx_abort(struct scsi_cmnd *cmd)
  10050. {
  10051. int rc;
  10052. spin_lock_irq(cmd->device->host->host_lock);
  10053. rc = __aic7xxx_abort(cmd);
  10054. spin_unlock_irq(cmd->device->host->host_lock);
  10055. return rc;
  10056. }
  10057. /*+F*************************************************************************
  10058. * Function:
  10059. * aic7xxx_reset
  10060. *
  10061. * Description:
  10062. * Resetting the bus always succeeds - is has to, otherwise the
  10063. * kernel will panic! Try a surgical technique - sending a BUS
  10064. * DEVICE RESET message - on the offending target before pulling
  10065. * the SCSI bus reset line.
  10066. *-F*************************************************************************/
  10067. static int aic7xxx_reset(struct scsi_cmnd *cmd)
  10068. {
  10069. struct aic7xxx_scb *scb;
  10070. struct aic7xxx_host *p;
  10071. struct aic_dev_data *aic_dev;
  10072. p = (struct aic7xxx_host *) cmd->device->host->hostdata;
  10073. spin_lock_irq(p->host->host_lock);
  10074. aic_dev = AIC_DEV(cmd);
  10075. if(aic7xxx_position(cmd) < p->scb_data->numscbs)
  10076. {
  10077. scb = (p->scb_data->scb_array[aic7xxx_position(cmd)]);
  10078. if (scb->cmd != cmd)
  10079. scb = NULL;
  10080. }
  10081. else
  10082. {
  10083. scb = NULL;
  10084. }
  10085. /*
  10086. * I added a new config option to the driver: "panic_on_abort" that will
  10087. * cause the driver to panic and the machine to stop on the first abort
  10088. * or reset call into the driver. At that point, it prints out a lot of
  10089. * useful information for me which I can then use to try and debug the
  10090. * problem. Simply enable the boot time prompt in order to activate this
  10091. * code.
  10092. */
  10093. if (aic7xxx_panic_on_abort)
  10094. aic7xxx_panic_abort(p, cmd);
  10095. pause_sequencer(p);
  10096. while((aic_inb(p, INTSTAT) & INT_PEND) && !(p->flags & AHC_IN_ISR))
  10097. {
  10098. aic7xxx_isr(p);
  10099. pause_sequencer(p);
  10100. }
  10101. aic7xxx_done_cmds_complete(p);
  10102. if(scb && (scb->cmd == NULL))
  10103. {
  10104. /*
  10105. * We just completed the command when we ran the isr stuff, so we no
  10106. * longer have it.
  10107. */
  10108. unpause_sequencer(p, FALSE);
  10109. spin_unlock_irq(p->host->host_lock);
  10110. return SUCCESS;
  10111. }
  10112. /*
  10113. * By this point, we want to already know what we are going to do and
  10114. * only have the following code implement our course of action.
  10115. */
  10116. aic7xxx_reset_channel(p, cmd->device->channel, TRUE);
  10117. if (p->features & AHC_TWIN)
  10118. {
  10119. aic7xxx_reset_channel(p, cmd->device->channel ^ 0x01, TRUE);
  10120. restart_sequencer(p);
  10121. }
  10122. aic_outb(p, aic_inb(p, SIMODE1) & ~(ENREQINIT|ENBUSFREE), SIMODE1);
  10123. aic7xxx_clear_intstat(p);
  10124. p->flags &= ~AHC_HANDLING_REQINITS;
  10125. p->msg_type = MSG_TYPE_NONE;
  10126. p->msg_index = 0;
  10127. p->msg_len = 0;
  10128. aic7xxx_run_done_queue(p, TRUE);
  10129. unpause_sequencer(p, FALSE);
  10130. spin_unlock_irq(p->host->host_lock);
  10131. ssleep(2);
  10132. return SUCCESS;
  10133. }
  10134. /*+F*************************************************************************
  10135. * Function:
  10136. * aic7xxx_biosparam
  10137. *
  10138. * Description:
  10139. * Return the disk geometry for the given SCSI device.
  10140. *
  10141. * Note:
  10142. * This function is broken for today's really large drives and needs
  10143. * fixed.
  10144. *-F*************************************************************************/
  10145. static int
  10146. aic7xxx_biosparam(struct scsi_device *sdev, struct block_device *bdev,
  10147. sector_t capacity, int geom[])
  10148. {
  10149. sector_t heads, sectors, cylinders;
  10150. int ret;
  10151. struct aic7xxx_host *p;
  10152. unsigned char *buf;
  10153. p = (struct aic7xxx_host *) sdev->host->hostdata;
  10154. buf = scsi_bios_ptable(bdev);
  10155. if ( buf )
  10156. {
  10157. ret = scsi_partsize(buf, capacity, &geom[2], &geom[0], &geom[1]);
  10158. kfree(buf);
  10159. if ( ret != -1 )
  10160. return(ret);
  10161. }
  10162. heads = 64;
  10163. sectors = 32;
  10164. cylinders = capacity >> 11;
  10165. if ((p->flags & AHC_EXTEND_TRANS_A) && (cylinders > 1024))
  10166. {
  10167. heads = 255;
  10168. sectors = 63;
  10169. cylinders = capacity >> 14;
  10170. if(capacity > (65535 * heads * sectors))
  10171. cylinders = 65535;
  10172. else
  10173. cylinders = ((unsigned int)capacity) / (unsigned int)(heads * sectors);
  10174. }
  10175. geom[0] = (int)heads;
  10176. geom[1] = (int)sectors;
  10177. geom[2] = (int)cylinders;
  10178. return (0);
  10179. }
  10180. /*+F*************************************************************************
  10181. * Function:
  10182. * aic7xxx_release
  10183. *
  10184. * Description:
  10185. * Free the passed in Scsi_Host memory structures prior to unloading the
  10186. * module.
  10187. *-F*************************************************************************/
  10188. static int
  10189. aic7xxx_release(struct Scsi_Host *host)
  10190. {
  10191. struct aic7xxx_host *p = (struct aic7xxx_host *) host->hostdata;
  10192. struct aic7xxx_host *next, *prev;
  10193. if(p->irq)
  10194. free_irq(p->irq, p);
  10195. #ifdef MMAPIO
  10196. if(p->maddr)
  10197. {
  10198. iounmap(p->maddr);
  10199. }
  10200. #endif /* MMAPIO */
  10201. if(!p->pdev)
  10202. release_region(p->base, MAXREG - MINREG);
  10203. #ifdef CONFIG_PCI
  10204. else {
  10205. pci_release_regions(p->pdev);
  10206. pci_dev_put(p->pdev);
  10207. }
  10208. #endif
  10209. prev = NULL;
  10210. next = first_aic7xxx;
  10211. while(next != NULL)
  10212. {
  10213. if(next == p)
  10214. {
  10215. if(prev == NULL)
  10216. first_aic7xxx = next->next;
  10217. else
  10218. prev->next = next->next;
  10219. }
  10220. else
  10221. {
  10222. prev = next;
  10223. }
  10224. next = next->next;
  10225. }
  10226. aic7xxx_free(p);
  10227. return(0);
  10228. }
  10229. /*+F*************************************************************************
  10230. * Function:
  10231. * aic7xxx_print_card
  10232. *
  10233. * Description:
  10234. * Print out all of the control registers on the card
  10235. *
  10236. * NOTE: This function is not yet safe for use on the VLB and EISA
  10237. * controllers, so it isn't used on those controllers at all.
  10238. *-F*************************************************************************/
  10239. static void
  10240. aic7xxx_print_card(struct aic7xxx_host *p)
  10241. {
  10242. int i, j, k, chip;
  10243. static struct register_ranges {
  10244. int num_ranges;
  10245. int range_val[32];
  10246. } cards_ds[] = {
  10247. { 0, {0,} }, /* none */
  10248. {10, {0x00, 0x05, 0x08, 0x11, 0x18, 0x19, 0x1f, 0x1f, 0x60, 0x60, /*7771*/
  10249. 0x62, 0x66, 0x80, 0x8e, 0x90, 0x95, 0x97, 0x97, 0x9b, 0x9f} },
  10250. { 9, {0x00, 0x05, 0x08, 0x11, 0x18, 0x1f, 0x60, 0x60, 0x62, 0x66, /*7850*/
  10251. 0x80, 0x8e, 0x90, 0x95, 0x97, 0x97, 0x9a, 0x9f} },
  10252. { 9, {0x00, 0x05, 0x08, 0x11, 0x18, 0x1f, 0x60, 0x60, 0x62, 0x66, /*7860*/
  10253. 0x80, 0x8e, 0x90, 0x95, 0x97, 0x97, 0x9a, 0x9f} },
  10254. {10, {0x00, 0x05, 0x08, 0x11, 0x18, 0x19, 0x1c, 0x1f, 0x60, 0x60, /*7870*/
  10255. 0x62, 0x66, 0x80, 0x8e, 0x90, 0x95, 0x97, 0x97, 0x9a, 0x9f} },
  10256. {10, {0x00, 0x05, 0x08, 0x11, 0x18, 0x1a, 0x1c, 0x1f, 0x60, 0x60, /*7880*/
  10257. 0x62, 0x66, 0x80, 0x8e, 0x90, 0x95, 0x97, 0x97, 0x9a, 0x9f} },
  10258. {16, {0x00, 0x05, 0x08, 0x11, 0x18, 0x1f, 0x60, 0x60, 0x62, 0x66, /*7890*/
  10259. 0x84, 0x8e, 0x90, 0x95, 0x97, 0x97, 0x9a, 0x9a, 0x9f, 0x9f,
  10260. 0xe0, 0xf1, 0xf4, 0xf4, 0xf6, 0xf6, 0xf8, 0xf8, 0xfa, 0xfc,
  10261. 0xfe, 0xff} },
  10262. {12, {0x00, 0x05, 0x08, 0x11, 0x18, 0x19, 0x1b, 0x1f, 0x60, 0x60, /*7895*/
  10263. 0x62, 0x66, 0x80, 0x8e, 0x90, 0x95, 0x97, 0x97, 0x9a, 0x9a,
  10264. 0x9f, 0x9f, 0xe0, 0xf1} },
  10265. {16, {0x00, 0x05, 0x08, 0x11, 0x18, 0x1f, 0x60, 0x60, 0x62, 0x66, /*7896*/
  10266. 0x84, 0x8e, 0x90, 0x95, 0x97, 0x97, 0x9a, 0x9a, 0x9f, 0x9f,
  10267. 0xe0, 0xf1, 0xf4, 0xf4, 0xf6, 0xf6, 0xf8, 0xf8, 0xfa, 0xfc,
  10268. 0xfe, 0xff} },
  10269. {12, {0x00, 0x05, 0x08, 0x11, 0x18, 0x1f, 0x60, 0x60, 0x62, 0x66, /*7892*/
  10270. 0x84, 0x8e, 0x90, 0x95, 0x97, 0x97, 0x9a, 0x9a, 0x9c, 0x9f,
  10271. 0xe0, 0xf1, 0xf4, 0xfc} },
  10272. {12, {0x00, 0x05, 0x08, 0x11, 0x18, 0x1f, 0x60, 0x60, 0x62, 0x66, /*7899*/
  10273. 0x84, 0x8e, 0x90, 0x95, 0x97, 0x97, 0x9a, 0x9a, 0x9c, 0x9f,
  10274. 0xe0, 0xf1, 0xf4, 0xfc} },
  10275. };
  10276. chip = p->chip & AHC_CHIPID_MASK;
  10277. printk("%s at ",
  10278. board_names[p->board_name_index]);
  10279. switch(p->chip & ~AHC_CHIPID_MASK)
  10280. {
  10281. case AHC_VL:
  10282. printk("VLB Slot %d.\n", p->pci_device_fn);
  10283. break;
  10284. case AHC_EISA:
  10285. printk("EISA Slot %d.\n", p->pci_device_fn);
  10286. break;
  10287. case AHC_PCI:
  10288. default:
  10289. printk("PCI %d/%d/%d.\n", p->pci_bus, PCI_SLOT(p->pci_device_fn),
  10290. PCI_FUNC(p->pci_device_fn));
  10291. break;
  10292. }
  10293. /*
  10294. * the registers on the card....
  10295. */
  10296. printk("Card Dump:\n");
  10297. k = 0;
  10298. for(i=0; i<cards_ds[chip].num_ranges; i++)
  10299. {
  10300. for(j = cards_ds[chip].range_val[ i * 2 ];
  10301. j <= cards_ds[chip].range_val[ i * 2 + 1 ] ;
  10302. j++)
  10303. {
  10304. printk("%02x:%02x ", j, aic_inb(p, j));
  10305. if(++k == 13)
  10306. {
  10307. printk("\n");
  10308. k=0;
  10309. }
  10310. }
  10311. }
  10312. if(k != 0)
  10313. printk("\n");
  10314. /*
  10315. * If this was an Ultra2 controller, then we just hosed the card in terms
  10316. * of the QUEUE REGS. This function is only called at init time or by
  10317. * the panic_abort function, so it's safe to assume a generic init time
  10318. * setting here
  10319. */
  10320. if(p->features & AHC_QUEUE_REGS)
  10321. {
  10322. aic_outb(p, 0, SDSCB_QOFF);
  10323. aic_outb(p, 0, SNSCB_QOFF);
  10324. aic_outb(p, 0, HNSCB_QOFF);
  10325. }
  10326. }
  10327. /*+F*************************************************************************
  10328. * Function:
  10329. * aic7xxx_print_scratch_ram
  10330. *
  10331. * Description:
  10332. * Print out the scratch RAM values on the card.
  10333. *-F*************************************************************************/
  10334. static void
  10335. aic7xxx_print_scratch_ram(struct aic7xxx_host *p)
  10336. {
  10337. int i, k;
  10338. k = 0;
  10339. printk("Scratch RAM:\n");
  10340. for(i = SRAM_BASE; i < SEQCTL; i++)
  10341. {
  10342. printk("%02x:%02x ", i, aic_inb(p, i));
  10343. if(++k == 13)
  10344. {
  10345. printk("\n");
  10346. k=0;
  10347. }
  10348. }
  10349. if (p->features & AHC_MORE_SRAM)
  10350. {
  10351. for(i = TARG_OFFSET; i < 0x80; i++)
  10352. {
  10353. printk("%02x:%02x ", i, aic_inb(p, i));
  10354. if(++k == 13)
  10355. {
  10356. printk("\n");
  10357. k=0;
  10358. }
  10359. }
  10360. }
  10361. printk("\n");
  10362. }
  10363. #include "aic7xxx_old/aic7xxx_proc.c"
  10364. MODULE_LICENSE("Dual BSD/GPL");
  10365. MODULE_VERSION(AIC7XXX_H_VERSION);
  10366. static struct scsi_host_template driver_template = {
  10367. .show_info = aic7xxx_show_info,
  10368. .detect = aic7xxx_detect,
  10369. .release = aic7xxx_release,
  10370. .info = aic7xxx_info,
  10371. .queuecommand = aic7xxx_queue,
  10372. .slave_alloc = aic7xxx_slave_alloc,
  10373. .slave_configure = aic7xxx_slave_configure,
  10374. .slave_destroy = aic7xxx_slave_destroy,
  10375. .bios_param = aic7xxx_biosparam,
  10376. .eh_abort_handler = aic7xxx_abort,
  10377. .eh_device_reset_handler = aic7xxx_bus_device_reset,
  10378. .eh_host_reset_handler = aic7xxx_reset,
  10379. .can_queue = 255,
  10380. .this_id = -1,
  10381. .max_sectors = 2048,
  10382. .cmd_per_lun = 3,
  10383. .use_clustering = ENABLE_CLUSTERING,
  10384. };
  10385. #include "scsi_module.c"
  10386. /*
  10387. * Overrides for Emacs so that we almost follow Linus's tabbing style.
  10388. * Emacs will notice this stuff at the end of the file and automatically
  10389. * adjust the settings for this buffer only. This must remain at the end
  10390. * of the file.
  10391. * ---------------------------------------------------------------------------
  10392. * Local variables:
  10393. * c-indent-level: 2
  10394. * c-brace-imaginary-offset: 0
  10395. * c-brace-offset: -2
  10396. * c-argdecl-indent: 2
  10397. * c-label-offset: -2
  10398. * c-continued-statement-offset: 2
  10399. * c-continued-brace-offset: 0
  10400. * indent-tabs-mode: nil
  10401. * tab-width: 8
  10402. * End:
  10403. */