More meth updates.
[linux-2.6/linux-mips.git] / drivers / scsi / aic7xxx_old.c
blobefaa1d9c733a05d50b437bb74a35513e996d9452
1 /*+M*************************************************************************
2 * Adaptec AIC7xxx device driver for Linux.
4 * Copyright (c) 1994 John Aycock
5 * The University of Calgary Department of Computer Science.
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.
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.
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.
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), ...
30 * --------------------------------------------------------------------------
32 * Modifications by Daniel M. Eischen (deischen@iworks.InterWorks.org):
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.
38 * Parts of this driver were also based on the FreeBSD driver by
39 * Justin T. Gibbs. His copyright follows:
41 * --------------------------------------------------------------------------
42 * Copyright (c) 1994-1997 Justin Gibbs.
43 * All rights reserved.
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.
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.
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.
76 * $Id: aic7xxx.c,v 1.119 1997/06/27 19:39:18 gibbs Exp $
77 *---------------------------------------------------------------------------
79 * Thanks also go to (in alphabetical order) the following:
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
86 * A Boot time option was also added for not resetting the scsi bus.
88 * Form: aic7xxx=extended
89 * aic7xxx=no_reset
90 * aic7xxx=ultra
91 * aic7xxx=irq_trigger:[0,1] # 0 edge, 1 level
92 * aic7xxx=verbose
94 * Daniel M. Eischen, deischen@iworks.InterWorks.org, 1/23/97
96 * $Id: aic7xxx.c,v 4.1 1997/06/12 08:23:42 deang Exp $
97 *-M*************************************************************************/
99 /*+M**************************************************************************
101 * Further driver modifications made by Doug Ledford <dledford@redhat.com>
103 * Copyright (c) 1997-1999 Doug Ledford
105 * These changes are released under the same licensing terms as the FreeBSD
106 * driver written by Justin Gibbs. Please see his Copyright notice above
107 * for the exact terms and conditions covering my changes as well as the
108 * warranty statement.
110 * Modifications made to the aic7xxx.c,v 4.1 driver from Dan Eischen include
111 * but are not limited to:
113 * 1: Import of the latest FreeBSD sequencer code for this driver
114 * 2: Modification of kernel code to accommodate different sequencer semantics
115 * 3: Extensive changes throughout kernel portion of driver to improve
116 * abort/reset processing and error hanndling
117 * 4: Other work contributed by various people on the Internet
118 * 5: Changes to printk information and verbosity selection code
119 * 6: General reliability related changes, especially in IRQ management
120 * 7: Modifications to the default probe/attach order for supported cards
121 * 8: SMP friendliness has been improved
123 * Overall, this driver represents a significant departure from the official
124 * aic7xxx driver released by Dan Eischen in two ways. First, in the code
125 * itself. A diff between the two version of the driver is now a several
126 * thousand line diff. Second, in approach to solving the same problem. The
127 * problem is importing the FreeBSD aic7xxx driver code to linux can be a
128 * difficult and time consuming process, that also can be error prone. Dan
129 * Eischen's official driver uses the approach that the linux and FreeBSD
130 * drivers should be as identical as possible. To that end, his next version
131 * of this driver will be using a mid-layer code library that he is developing
132 * to moderate communications between the linux mid-level SCSI code and the
133 * low level FreeBSD driver. He intends to be able to essentially drop the
134 * FreeBSD driver into the linux kernel with only a few minor tweaks to some
135 * include files and the like and get things working, making for fast easy
136 * imports of the FreeBSD code into linux.
138 * I disagree with Dan's approach. Not that I don't think his way of doing
139 * things would be nice, easy to maintain, and create a more uniform driver
140 * between FreeBSD and Linux. I have no objection to those issues. My
141 * disagreement is on the needed functionality. There simply are certain
142 * things that are done differently in FreeBSD than linux that will cause
143 * problems for this driver regardless of any middle ware Dan implements.
144 * The biggest example of this at the moment is interrupt semantics. Linux
145 * doesn't provide the same protection techniques as FreeBSD does, nor can
146 * they be easily implemented in any middle ware code since they would truly
147 * belong in the kernel proper and would effect all drivers. For the time
148 * being, I see issues such as these as major stumbling blocks to the
149 * reliability of code based upon such middle ware. Therefore, I choose to
150 * use a different approach to importing the FreeBSD code that doesn't
151 * involve any middle ware type code. My approach is to import the sequencer
152 * code from FreeBSD wholesale. Then, to only make changes in the kernel
153 * portion of the driver as they are needed for the new sequencer semantics.
154 * In this way, the portion of the driver that speaks to the rest of the
155 * linux kernel is fairly static and can be changed/modified to solve
156 * any problems one might encounter without concern for the FreeBSD driver.
158 * Note: If time and experience should prove me wrong that the middle ware
159 * code Dan writes is reliable in its operation, then I'll retract my above
160 * statements. But, for those that don't know, I'm from Missouri (in the US)
161 * and our state motto is "The Show-Me State". Well, before I will put
162 * faith into it, you'll have to show me that it works :)
164 *_M*************************************************************************/
167 * The next three defines are user configurable. These should be the only
168 * defines a user might need to get in here and change. There are other
169 * defines buried deeper in the code, but those really shouldn't need touched
170 * under normal conditions.
174 * AIC7XXX_STRICT_PCI_SETUP
175 * Should we assume the PCI config options on our controllers are set with
176 * sane and proper values, or should we be anal about our PCI config
177 * registers and force them to what we want? The main advantage to
178 * defining this option is on non-Intel hardware where the BIOS may not
179 * have been run to set things up, or if you have one of the BIOSless
180 * Adaptec controllers, such as a 2910, that don't get set up by the
181 * BIOS. However, keep in mind that we really do set the most important
182 * items in the driver regardless of this setting, this only controls some
183 * of the more esoteric PCI options on these cards. In that sense, I
184 * would default to leaving this off. However, if people wish to try
185 * things both ways, that would also help me to know if there are some
186 * machines where it works one way but not another.
188 * -- July 7, 17:09
189 * OK...I need this on my machine for testing, so the default is to
190 * leave it defined.
192 * -- July 7, 18:49
193 * I needed it for testing, but it didn't make any difference, so back
194 * off she goes.
196 * -- July 16, 23:04
197 * I turned it back on to try and compensate for the 2.1.x PCI code
198 * which no longer relies solely on the BIOS and now tries to set
199 * things itself.
202 #define AIC7XXX_STRICT_PCI_SETUP
205 * AIC7XXX_VERBOSE_DEBUGGING
206 * This option enables a lot of extra printk();s in the code, surrounded
207 * by if (aic7xxx_verbose ...) statements. Executing all of those if
208 * statements and the extra checks can get to where it actually does have
209 * an impact on CPU usage and such, as well as code size. Disabling this
210 * define will keep some of those from becoming part of the code.
212 * NOTE: Currently, this option has no real effect, I will be adding the
213 * various #ifdef's in the code later when I've decided a section is
214 * complete and no longer needs debugging. OK...a lot of things are now
215 * surrounded by this define, so turning this off does have an impact.
219 * #define AIC7XXX_VERBOSE_DEBUGGING
222 #include <linux/module.h>
223 #include <stdarg.h>
224 #include <asm/io.h>
225 #include <asm/irq.h>
226 #include <asm/byteorder.h>
227 #include <linux/version.h>
228 #include <linux/string.h>
229 #include <linux/errno.h>
230 #include <linux/kernel.h>
231 #include <linux/ioport.h>
232 #include <linux/delay.h>
233 #include <linux/sched.h>
234 #include <linux/pci.h>
235 #include <linux/proc_fs.h>
236 #include <linux/blk.h>
237 #include <linux/init.h>
238 #include <linux/spinlock.h>
239 #include <linux/smp.h>
240 #include <linux/blk.h>
241 #include <linux/interrupt.h>
242 #include "scsi.h"
243 #include "hosts.h"
244 #include "aic7xxx_old/aic7xxx.h"
246 #include "aic7xxx_old/sequencer.h"
247 #include "aic7xxx_old/scsi_message.h"
248 #include "aic7xxx_old/aic7xxx_reg.h"
249 #include <scsi/scsicam.h>
251 #include <linux/stat.h>
252 #include <linux/slab.h> /* for kmalloc() */
254 #include <linux/config.h> /* for CONFIG_PCI */
256 #define AIC7XXX_C_VERSION "5.2.6"
258 #define NUMBER(arr) (sizeof(arr) / sizeof(arr[0]))
259 #define MIN(a,b) (((a) < (b)) ? (a) : (b))
260 #define MAX(a,b) (((a) > (b)) ? (a) : (b))
261 #define ALL_TARGETS -1
262 #define ALL_CHANNELS -1
263 #define ALL_LUNS -1
264 #define MAX_TARGETS 16
265 #define MAX_LUNS 8
266 #ifndef TRUE
267 # define TRUE 1
268 #endif
269 #ifndef FALSE
270 # define FALSE 0
271 #endif
273 #if defined(__powerpc__) || defined(__i386__) || defined(__x86_64__)
274 # define MMAPIO
275 #endif
278 * You can try raising me for better performance or lowering me if you have
279 * flaky devices that go off the scsi bus when hit with too many tagged
280 * commands (like some IBM SCSI-3 LVD drives).
282 #define AIC7XXX_CMDS_PER_DEVICE 32
284 typedef struct
286 unsigned char tag_commands[16]; /* Allow for wide/twin adapters. */
287 } adapter_tag_info_t;
290 * Make a define that will tell the driver not to the default tag depth
291 * everywhere.
293 #define DEFAULT_TAG_COMMANDS {0, 0, 0, 0, 0, 0, 0, 0,\
294 0, 0, 0, 0, 0, 0, 0, 0}
297 * Modify this as you see fit for your system. By setting tag_commands
298 * to 0, the driver will use it's own algorithm for determining the
299 * number of commands to use (see above). When 255, the driver will
300 * not enable tagged queueing for that particular device. When positive
301 * (> 0) and (< 255) the values in the array are used for the queue_depth.
302 * Note that the maximum value for an entry is 254, but you're insane if
303 * you try to use that many commands on one device.
305 * In this example, the first line will disable tagged queueing for all
306 * the devices on the first probed aic7xxx adapter.
308 * The second line enables tagged queueing with 4 commands/LUN for IDs
309 * (1, 2-11, 13-15), disables tagged queueing for ID 12, and tells the
310 * driver to use its own algorithm for ID 1.
312 * The third line is the same as the first line.
314 * The fourth line disables tagged queueing for devices 0 and 3. It
315 * enables tagged queueing for the other IDs, with 16 commands/LUN
316 * for IDs 1 and 4, 127 commands/LUN for ID 8, and 4 commands/LUN for
317 * IDs 2, 5-7, and 9-15.
321 * NOTE: The below structure is for reference only, the actual structure
322 * to modify in order to change things is found after this fake one.
324 adapter_tag_info_t aic7xxx_tag_info[] =
326 {DEFAULT_TAG_COMMANDS},
327 {{4, 0, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 255, 4, 4, 4}},
328 {DEFAULT_TAG_COMMANDS},
329 {{255, 16, 4, 255, 16, 4, 4, 4, 127, 4, 4, 4, 4, 4, 4, 4}}
333 static adapter_tag_info_t aic7xxx_tag_info[] =
335 {DEFAULT_TAG_COMMANDS},
336 {DEFAULT_TAG_COMMANDS},
337 {DEFAULT_TAG_COMMANDS},
338 {DEFAULT_TAG_COMMANDS},
339 {DEFAULT_TAG_COMMANDS},
340 {DEFAULT_TAG_COMMANDS},
341 {DEFAULT_TAG_COMMANDS},
342 {DEFAULT_TAG_COMMANDS},
343 {DEFAULT_TAG_COMMANDS},
344 {DEFAULT_TAG_COMMANDS},
345 {DEFAULT_TAG_COMMANDS},
346 {DEFAULT_TAG_COMMANDS},
347 {DEFAULT_TAG_COMMANDS},
348 {DEFAULT_TAG_COMMANDS},
349 {DEFAULT_TAG_COMMANDS},
350 {DEFAULT_TAG_COMMANDS}
355 * Define an array of board names that can be indexed by aha_type.
356 * Don't forget to change this when changing the types!
358 static const char *board_names[] = {
359 "AIC-7xxx Unknown", /* AIC_NONE */
360 "Adaptec AIC-7810 Hardware RAID Controller", /* AIC_7810 */
361 "Adaptec AIC-7770 SCSI host adapter", /* AIC_7770 */
362 "Adaptec AHA-274X SCSI host adapter", /* AIC_7771 */
363 "Adaptec AHA-284X SCSI host adapter", /* AIC_284x */
364 "Adaptec AIC-7850 SCSI host adapter", /* AIC_7850 */
365 "Adaptec AIC-7855 SCSI host adapter", /* AIC_7855 */
366 "Adaptec AIC-7860 Ultra SCSI host adapter", /* AIC_7860 */
367 "Adaptec AHA-2940A Ultra SCSI host adapter", /* AIC_7861 */
368 "Adaptec AIC-7870 SCSI host adapter", /* AIC_7870 */
369 "Adaptec AHA-294X SCSI host adapter", /* AIC_7871 */
370 "Adaptec AHA-394X SCSI host adapter", /* AIC_7872 */
371 "Adaptec AHA-398X SCSI host adapter", /* AIC_7873 */
372 "Adaptec AHA-2944 SCSI host adapter", /* AIC_7874 */
373 "Adaptec AIC-7880 Ultra SCSI host adapter", /* AIC_7880 */
374 "Adaptec AHA-294X Ultra SCSI host adapter", /* AIC_7881 */
375 "Adaptec AHA-394X Ultra SCSI host adapter", /* AIC_7882 */
376 "Adaptec AHA-398X Ultra SCSI host adapter", /* AIC_7883 */
377 "Adaptec AHA-2944 Ultra SCSI host adapter", /* AIC_7884 */
378 "Adaptec AHA-2940UW Pro Ultra SCSI host adapter", /* AIC_7887 */
379 "Adaptec AIC-7895 Ultra SCSI host adapter", /* AIC_7895 */
380 "Adaptec AIC-7890/1 Ultra2 SCSI host adapter", /* AIC_7890 */
381 "Adaptec AHA-293X Ultra2 SCSI host adapter", /* AIC_7890 */
382 "Adaptec AHA-294X Ultra2 SCSI host adapter", /* AIC_7890 */
383 "Adaptec AIC-7896/7 Ultra2 SCSI host adapter", /* AIC_7896 */
384 "Adaptec AHA-394X Ultra2 SCSI host adapter", /* AIC_7897 */
385 "Adaptec AHA-395X Ultra2 SCSI host adapter", /* AIC_7897 */
386 "Adaptec PCMCIA SCSI controller", /* card bus stuff */
387 "Adaptec AIC-7892 Ultra 160/m SCSI host adapter", /* AIC_7892 */
388 "Adaptec AIC-7899 Ultra 160/m SCSI host adapter", /* AIC_7899 */
392 * There should be a specific return value for this in scsi.h, but
393 * it seems that most drivers ignore it.
395 #define DID_UNDERFLOW DID_ERROR
398 * What we want to do is have the higher level scsi driver requeue
399 * the command to us. There is no specific driver status for this
400 * condition, but the higher level scsi driver will requeue the
401 * command on a DID_BUS_BUSY error.
403 * Upon further inspection and testing, it seems that DID_BUS_BUSY
404 * will *always* retry the command. We can get into an infinite loop
405 * if this happens when we really want some sort of counter that
406 * will automatically abort/reset the command after so many retries.
407 * Using DID_ERROR will do just that. (Made by a suggestion by
408 * Doug Ledford 8/1/96)
410 #define DID_RETRY_COMMAND DID_ERROR
412 #define HSCSIID 0x07
413 #define SCSI_RESET 0x040
416 * EISA/VL-bus stuff
418 #define MINSLOT 1
419 #define MAXSLOT 15
420 #define SLOTBASE(x) ((x) << 12)
421 #define BASE_TO_SLOT(x) ((x) >> 12)
424 * Standard EISA Host ID regs (Offset from slot base)
426 #define AHC_HID0 0x80 /* 0,1: msb of ID2, 2-7: ID1 */
427 #define AHC_HID1 0x81 /* 0-4: ID3, 5-7: LSB ID2 */
428 #define AHC_HID2 0x82 /* product */
429 #define AHC_HID3 0x83 /* firmware revision */
432 * AIC-7770 I/O range to reserve for a card
434 #define MINREG 0xC00
435 #define MAXREG 0xCFF
437 #define INTDEF 0x5C /* Interrupt Definition Register */
440 * AIC-78X0 PCI registers
442 #define CLASS_PROGIF_REVID 0x08
443 #define DEVREVID 0x000000FFul
444 #define PROGINFC 0x0000FF00ul
445 #define SUBCLASS 0x00FF0000ul
446 #define BASECLASS 0xFF000000ul
448 #define CSIZE_LATTIME 0x0C
449 #define CACHESIZE 0x0000003Ful /* only 5 bits */
450 #define LATTIME 0x0000FF00ul
452 #define DEVCONFIG 0x40
453 #define SCBSIZE32 0x00010000ul /* aic789X only */
454 #define MPORTMODE 0x00000400ul /* aic7870 only */
455 #define RAMPSM 0x00000200ul /* aic7870 only */
456 #define RAMPSM_ULTRA2 0x00000004
457 #define VOLSENSE 0x00000100ul
458 #define SCBRAMSEL 0x00000080ul
459 #define SCBRAMSEL_ULTRA2 0x00000008
460 #define MRDCEN 0x00000040ul
461 #define EXTSCBTIME 0x00000020ul /* aic7870 only */
462 #define EXTSCBPEN 0x00000010ul /* aic7870 only */
463 #define BERREN 0x00000008ul
464 #define DACEN 0x00000004ul
465 #define STPWLEVEL 0x00000002ul
466 #define DIFACTNEGEN 0x00000001ul /* aic7870 only */
468 #define SCAMCTL 0x1a /* Ultra2 only */
469 #define CCSCBBADDR 0xf0 /* aic7895/6/7 */
472 * Define the different types of SEEPROMs on aic7xxx adapters
473 * and make it also represent the address size used in accessing
474 * its registers. The 93C46 chips have 1024 bits organized into
475 * 64 16-bit words, while the 93C56 chips have 2048 bits organized
476 * into 128 16-bit words. The C46 chips use 6 bits to address
477 * each word, while the C56 and C66 (4096 bits) use 8 bits to
478 * address each word.
480 typedef enum {C46 = 6, C56_66 = 8} seeprom_chip_type;
484 * Define the format of the SEEPROM registers (16 bits).
487 struct seeprom_config {
490 * SCSI ID Configuration Flags
492 #define CFXFER 0x0007 /* synchronous transfer rate */
493 #define CFSYNCH 0x0008 /* enable synchronous transfer */
494 #define CFDISC 0x0010 /* enable disconnection */
495 #define CFWIDEB 0x0020 /* wide bus device (wide card) */
496 #define CFSYNCHISULTRA 0x0040 /* CFSYNC is an ultra offset */
497 #define CFNEWULTRAFORMAT 0x0080 /* Use the Ultra2 SEEPROM format */
498 #define CFSTART 0x0100 /* send start unit SCSI command */
499 #define CFINCBIOS 0x0200 /* include in BIOS scan */
500 #define CFRNFOUND 0x0400 /* report even if not found */
501 #define CFMULTILUN 0x0800 /* probe mult luns in BIOS scan */
502 #define CFWBCACHEYES 0x4000 /* Enable W-Behind Cache on drive */
503 #define CFWBCACHENC 0xc000 /* Don't change W-Behind Cache */
504 /* UNUSED 0x3000 */
505 unsigned short device_flags[16]; /* words 0-15 */
508 * BIOS Control Bits
510 #define CFSUPREM 0x0001 /* support all removable drives */
511 #define CFSUPREMB 0x0002 /* support removable drives for boot only */
512 #define CFBIOSEN 0x0004 /* BIOS enabled */
513 /* UNUSED 0x0008 */
514 #define CFSM2DRV 0x0010 /* support more than two drives */
515 #define CF284XEXTEND 0x0020 /* extended translation (284x cards) */
516 /* UNUSED 0x0040 */
517 #define CFEXTEND 0x0080 /* extended translation enabled */
518 /* UNUSED 0xFF00 */
519 unsigned short bios_control; /* word 16 */
522 * Host Adapter Control Bits
524 #define CFAUTOTERM 0x0001 /* Perform Auto termination */
525 #define CFULTRAEN 0x0002 /* Ultra SCSI speed enable (Ultra cards) */
526 #define CF284XSELTO 0x0003 /* Selection timeout (284x cards) */
527 #define CF284XFIFO 0x000C /* FIFO Threshold (284x cards) */
528 #define CFSTERM 0x0004 /* SCSI low byte termination */
529 #define CFWSTERM 0x0008 /* SCSI high byte termination (wide card) */
530 #define CFSPARITY 0x0010 /* SCSI parity */
531 #define CF284XSTERM 0x0020 /* SCSI low byte termination (284x cards) */
532 #define CFRESETB 0x0040 /* reset SCSI bus at boot */
533 #define CFBPRIMARY 0x0100 /* Channel B primary on 7895 chipsets */
534 #define CFSEAUTOTERM 0x0400 /* aic7890 Perform SE Auto Term */
535 #define CFLVDSTERM 0x0800 /* aic7890 LVD Termination */
536 /* UNUSED 0xF280 */
537 unsigned short adapter_control; /* word 17 */
540 * Bus Release, Host Adapter ID
542 #define CFSCSIID 0x000F /* host adapter SCSI ID */
543 /* UNUSED 0x00F0 */
544 #define CFBRTIME 0xFF00 /* bus release time */
545 unsigned short brtime_id; /* word 18 */
548 * Maximum targets
550 #define CFMAXTARG 0x00FF /* maximum targets */
551 /* UNUSED 0xFF00 */
552 unsigned short max_targets; /* word 19 */
554 unsigned short res_1[11]; /* words 20-30 */
555 unsigned short checksum; /* word 31 */
558 #define SELBUS_MASK 0x0a
559 #define SELNARROW 0x00
560 #define SELBUSB 0x08
561 #define SINGLE_BUS 0x00
563 #define SCB_TARGET(scb) \
564 (((scb)->hscb->target_channel_lun & TID) >> 4)
565 #define SCB_LUN(scb) \
566 ((scb)->hscb->target_channel_lun & LID)
567 #define SCB_IS_SCSIBUS_B(scb) \
568 (((scb)->hscb->target_channel_lun & SELBUSB) != 0)
571 * If an error occurs during a data transfer phase, run the command
572 * to completion - it's easier that way - making a note of the error
573 * condition in this location. This then will modify a DID_OK status
574 * into an appropriate error for the higher-level SCSI code.
576 #define aic7xxx_error(cmd) ((cmd)->SCp.Status)
579 * Keep track of the targets returned status.
581 #define aic7xxx_status(cmd) ((cmd)->SCp.sent_command)
584 * The position of the SCSI commands scb within the scb array.
586 #define aic7xxx_position(cmd) ((cmd)->SCp.have_data_in)
589 * The stored DMA mapping for single-buffer data transfers.
591 #define aic7xxx_mapping(cmd) ((cmd)->SCp.phase)
594 * Get out private data area from a scsi cmd pointer
596 #define AIC_DEV(cmd) ((struct aic_dev_data *)(cmd)->device->hostdata)
599 * So we can keep track of our host structs
601 static struct aic7xxx_host *first_aic7xxx = NULL;
604 * As of Linux 2.1, the mid-level SCSI code uses virtual addresses
605 * in the scatter-gather lists. We need to convert the virtual
606 * addresses to physical addresses.
608 struct hw_scatterlist {
609 unsigned int address;
610 unsigned int length;
614 * Maximum number of SG segments these cards can support.
616 #define AIC7XXX_MAX_SG 128
619 * The maximum number of SCBs we could have for ANY type
620 * of card. DON'T FORGET TO CHANGE THE SCB MASK IN THE
621 * SEQUENCER CODE IF THIS IS MODIFIED!
623 #define AIC7XXX_MAXSCB 255
626 struct aic7xxx_hwscb {
627 /* ------------ Begin hardware supported fields ---------------- */
628 /* 0*/ unsigned char control;
629 /* 1*/ unsigned char target_channel_lun; /* 4/1/3 bits */
630 /* 2*/ unsigned char target_status;
631 /* 3*/ unsigned char SG_segment_count;
632 /* 4*/ unsigned int SG_list_pointer;
633 /* 8*/ unsigned char residual_SG_segment_count;
634 /* 9*/ unsigned char residual_data_count[3];
635 /*12*/ unsigned int data_pointer;
636 /*16*/ unsigned int data_count;
637 /*20*/ unsigned int SCSI_cmd_pointer;
638 /*24*/ unsigned char SCSI_cmd_length;
639 /*25*/ unsigned char tag; /* Index into our kernel SCB array.
640 * Also used as the tag for tagged I/O
642 #define SCB_PIO_TRANSFER_SIZE 26 /* amount we need to upload/download
643 * via PIO to initialize a transaction.
645 /*26*/ unsigned char next; /* Used to thread SCBs awaiting selection
646 * or disconnected down in the sequencer.
648 /*27*/ unsigned char prev;
649 /*28*/ unsigned int pad; /*
650 * Unused by the kernel, but we require
651 * the padding so that the array of
652 * hardware SCBs is aligned on 32 byte
653 * boundaries so the sequencer can index
657 typedef enum {
658 SCB_FREE = 0x0000,
659 SCB_DTR_SCB = 0x0001,
660 SCB_WAITINGQ = 0x0002,
661 SCB_ACTIVE = 0x0004,
662 SCB_SENSE = 0x0008,
663 SCB_ABORT = 0x0010,
664 SCB_DEVICE_RESET = 0x0020,
665 SCB_RESET = 0x0040,
666 SCB_RECOVERY_SCB = 0x0080,
667 SCB_MSGOUT_PPR = 0x0100,
668 SCB_MSGOUT_SENT = 0x0200,
669 SCB_MSGOUT_SDTR = 0x0400,
670 SCB_MSGOUT_WDTR = 0x0800,
671 SCB_MSGOUT_BITS = SCB_MSGOUT_PPR |
672 SCB_MSGOUT_SENT |
673 SCB_MSGOUT_SDTR |
674 SCB_MSGOUT_WDTR,
675 SCB_QUEUED_ABORT = 0x1000,
676 SCB_QUEUED_FOR_DONE = 0x2000,
677 SCB_WAS_BUSY = 0x4000,
678 SCB_QUEUE_FULL = 0x8000
679 } scb_flag_type;
681 typedef enum {
682 AHC_FNONE = 0x00000000,
683 AHC_PAGESCBS = 0x00000001,
684 AHC_CHANNEL_B_PRIMARY = 0x00000002,
685 AHC_USEDEFAULTS = 0x00000004,
686 AHC_INDIRECT_PAGING = 0x00000008,
687 AHC_CHNLB = 0x00000020,
688 AHC_CHNLC = 0x00000040,
689 AHC_EXTEND_TRANS_A = 0x00000100,
690 AHC_EXTEND_TRANS_B = 0x00000200,
691 AHC_TERM_ENB_A = 0x00000400,
692 AHC_TERM_ENB_SE_LOW = 0x00000400,
693 AHC_TERM_ENB_B = 0x00000800,
694 AHC_TERM_ENB_SE_HIGH = 0x00000800,
695 AHC_HANDLING_REQINITS = 0x00001000,
696 AHC_TARGETMODE = 0x00002000,
697 AHC_NEWEEPROM_FMT = 0x00004000,
699 * Here ends the FreeBSD defined flags and here begins the linux defined
700 * flags. NOTE: I did not preserve the old flag name during this change
701 * specifically to force me to evaluate what flags were being used properly
702 * and what flags weren't. This way, I could clean up the flag usage on
703 * a use by use basis. Doug Ledford
705 AHC_MOTHERBOARD = 0x00020000,
706 AHC_NO_STPWEN = 0x00040000,
707 AHC_RESET_DELAY = 0x00080000,
708 AHC_A_SCANNED = 0x00100000,
709 AHC_B_SCANNED = 0x00200000,
710 AHC_MULTI_CHANNEL = 0x00400000,
711 AHC_BIOS_ENABLED = 0x00800000,
712 AHC_SEEPROM_FOUND = 0x01000000,
713 AHC_TERM_ENB_LVD = 0x02000000,
714 AHC_ABORT_PENDING = 0x04000000,
715 AHC_RESET_PENDING = 0x08000000,
716 #define AHC_IN_ISR_BIT 28
717 AHC_IN_ISR = 0x10000000,
718 AHC_IN_ABORT = 0x20000000,
719 AHC_IN_RESET = 0x40000000,
720 AHC_EXTERNAL_SRAM = 0x80000000
721 } ahc_flag_type;
723 typedef enum {
724 AHC_NONE = 0x0000,
725 AHC_CHIPID_MASK = 0x00ff,
726 AHC_AIC7770 = 0x0001,
727 AHC_AIC7850 = 0x0002,
728 AHC_AIC7860 = 0x0003,
729 AHC_AIC7870 = 0x0004,
730 AHC_AIC7880 = 0x0005,
731 AHC_AIC7890 = 0x0006,
732 AHC_AIC7895 = 0x0007,
733 AHC_AIC7896 = 0x0008,
734 AHC_AIC7892 = 0x0009,
735 AHC_AIC7899 = 0x000a,
736 AHC_VL = 0x0100,
737 AHC_EISA = 0x0200,
738 AHC_PCI = 0x0400,
739 } ahc_chip;
741 typedef enum {
742 AHC_FENONE = 0x0000,
743 AHC_ULTRA = 0x0001,
744 AHC_ULTRA2 = 0x0002,
745 AHC_WIDE = 0x0004,
746 AHC_TWIN = 0x0008,
747 AHC_MORE_SRAM = 0x0010,
748 AHC_CMD_CHAN = 0x0020,
749 AHC_QUEUE_REGS = 0x0040,
750 AHC_SG_PRELOAD = 0x0080,
751 AHC_SPIOCAP = 0x0100,
752 AHC_ULTRA3 = 0x0200,
753 AHC_NEW_AUTOTERM = 0x0400,
754 AHC_AIC7770_FE = AHC_FENONE,
755 AHC_AIC7850_FE = AHC_SPIOCAP,
756 AHC_AIC7860_FE = AHC_ULTRA|AHC_SPIOCAP,
757 AHC_AIC7870_FE = AHC_FENONE,
758 AHC_AIC7880_FE = AHC_ULTRA,
759 AHC_AIC7890_FE = AHC_MORE_SRAM|AHC_CMD_CHAN|AHC_ULTRA2|
760 AHC_QUEUE_REGS|AHC_SG_PRELOAD|AHC_NEW_AUTOTERM,
761 AHC_AIC7895_FE = AHC_MORE_SRAM|AHC_CMD_CHAN|AHC_ULTRA,
762 AHC_AIC7896_FE = AHC_AIC7890_FE,
763 AHC_AIC7892_FE = AHC_AIC7890_FE|AHC_ULTRA3,
764 AHC_AIC7899_FE = AHC_AIC7890_FE|AHC_ULTRA3,
765 } ahc_feature;
767 #define SCB_DMA_ADDR(scb, addr) ((unsigned long)(addr) + (scb)->scb_dma->dma_offset)
769 struct aic7xxx_scb_dma {
770 unsigned long dma_offset; /* Correction you have to add
771 * to virtual address to get
772 * dma handle in this region */
773 dma_addr_t dma_address; /* DMA handle of the start,
774 * for unmap */
775 unsigned int dma_len; /* DMA length */
778 typedef enum {
779 AHC_BUG_NONE = 0x0000,
780 AHC_BUG_TMODE_WIDEODD = 0x0001,
781 AHC_BUG_AUTOFLUSH = 0x0002,
782 AHC_BUG_CACHETHEN = 0x0004,
783 AHC_BUG_CACHETHEN_DIS = 0x0008,
784 AHC_BUG_PCI_2_1_RETRY = 0x0010,
785 AHC_BUG_PCI_MWI = 0x0020,
786 AHC_BUG_SCBCHAN_UPLOAD = 0x0040,
787 } ahc_bugs;
789 struct aic7xxx_scb {
790 struct aic7xxx_hwscb *hscb; /* corresponding hardware scb */
791 Scsi_Cmnd *cmd; /* Scsi_Cmnd for this scb */
792 struct aic7xxx_scb *q_next; /* next scb in queue */
793 volatile scb_flag_type flags; /* current state of scb */
794 struct hw_scatterlist *sg_list; /* SG list in adapter format */
795 unsigned char tag_action;
796 unsigned char sg_count;
797 unsigned char *sense_cmd; /*
798 * Allocate 6 characters for
799 * sense command.
801 unsigned char *cmnd;
802 unsigned int sg_length; /* We init this during buildscb so we
803 * don't have to calculate anything
804 * during underflow/overflow/stat code
806 void *kmalloc_ptr;
807 struct aic7xxx_scb_dma *scb_dma;
811 * Define a linked list of SCBs.
813 typedef struct {
814 struct aic7xxx_scb *head;
815 struct aic7xxx_scb *tail;
816 } scb_queue_type;
818 static struct {
819 unsigned char errno;
820 const char *errmesg;
821 } hard_error[] = {
822 { ILLHADDR, "Illegal Host Access" },
823 { ILLSADDR, "Illegal Sequencer Address referenced" },
824 { ILLOPCODE, "Illegal Opcode in sequencer program" },
825 { SQPARERR, "Sequencer Ram Parity Error" },
826 { DPARERR, "Data-Path Ram Parity Error" },
827 { MPARERR, "Scratch Ram/SCB Array Ram Parity Error" },
828 { PCIERRSTAT,"PCI Error detected" },
829 { CIOPARERR, "CIOBUS Parity Error" }
832 static unsigned char
833 generic_sense[] = { REQUEST_SENSE, 0, 0, 0, 255, 0 };
835 typedef struct {
836 scb_queue_type free_scbs; /*
837 * SCBs assigned to free slot on
838 * card (no paging required)
840 struct aic7xxx_scb *scb_array[AIC7XXX_MAXSCB];
841 struct aic7xxx_hwscb *hscbs;
842 unsigned char numscbs; /* current number of scbs */
843 unsigned char maxhscbs; /* hardware scbs */
844 unsigned char maxscbs; /* max scbs including pageable scbs */
845 dma_addr_t hscbs_dma; /* DMA handle to hscbs */
846 unsigned int hscbs_dma_len; /* length of the above DMA area */
847 void *hscb_kmalloc_ptr;
848 } scb_data_type;
850 struct target_cmd {
851 unsigned char mesg_bytes[4];
852 unsigned char command[28];
855 #define AHC_TRANS_CUR 0x0001
856 #define AHC_TRANS_ACTIVE 0x0002
857 #define AHC_TRANS_GOAL 0x0004
858 #define AHC_TRANS_USER 0x0008
859 #define AHC_TRANS_QUITE 0x0010
860 typedef struct {
861 unsigned char width;
862 unsigned char period;
863 unsigned char offset;
864 unsigned char options;
865 } transinfo_type;
867 struct aic_dev_data {
868 volatile scb_queue_type delayed_scbs;
869 volatile unsigned short temp_q_depth;
870 unsigned short max_q_depth;
871 volatile unsigned char active_cmds;
873 * Statistics Kept:
875 * Total Xfers (count for each command that has a data xfer),
876 * broken down by reads && writes.
878 * Further sorted into a few bins for keeping tabs on how many commands
879 * we get of various sizes.
882 long w_total; /* total writes */
883 long r_total; /* total reads */
884 long barrier_total; /* total num of REQ_BARRIER commands */
885 long ordered_total; /* How many REQ_BARRIER commands we
886 used ordered tags to satisfy */
887 long w_bins[6]; /* binned write */
888 long r_bins[6]; /* binned reads */
889 transinfo_type cur;
890 transinfo_type goal;
891 #define BUS_DEVICE_RESET_PENDING 0x01
892 #define DEVICE_RESET_DELAY 0x02
893 #define DEVICE_PRINT_DTR 0x04
894 #define DEVICE_WAS_BUSY 0x08
895 #define DEVICE_DTR_SCANNED 0x10
896 #define DEVICE_SCSI_3 0x20
897 volatile unsigned char flags;
898 unsigned needppr:1;
899 unsigned needppr_copy:1;
900 unsigned needsdtr:1;
901 unsigned needsdtr_copy:1;
902 unsigned needwdtr:1;
903 unsigned needwdtr_copy:1;
904 unsigned dtr_pending:1;
905 struct scsi_device *SDptr;
906 struct list_head list;
910 * Define a structure used for each host adapter. Note, in order to avoid
911 * problems with architectures I can't test on (because I don't have one,
912 * such as the Alpha based systems) which happen to give faults for
913 * non-aligned memory accesses, care was taken to align this structure
914 * in a way that gauranteed all accesses larger than 8 bits were aligned
915 * on the appropriate boundary. It's also organized to try and be more
916 * cache line efficient. Be careful when changing this lest you might hurt
917 * overall performance and bring down the wrath of the masses.
919 struct aic7xxx_host {
921 * This is the first 64 bytes in the host struct
925 * We are grouping things here....first, items that get either read or
926 * written with nearly every interrupt
928 volatile long flags;
929 ahc_feature features; /* chip features */
930 unsigned long base; /* card base address */
931 volatile unsigned char *maddr; /* memory mapped address */
932 unsigned long isr_count; /* Interrupt count */
933 unsigned long spurious_int;
934 scb_data_type *scb_data;
935 struct aic7xxx_cmd_queue {
936 Scsi_Cmnd *head;
937 Scsi_Cmnd *tail;
938 } completeq;
941 * Things read/written on nearly every entry into aic7xxx_queue()
943 volatile scb_queue_type waiting_scbs;
944 unsigned char unpause; /* unpause value for HCNTRL */
945 unsigned char pause; /* pause value for HCNTRL */
946 volatile unsigned char qoutfifonext;
947 volatile unsigned char activescbs; /* active scbs */
948 volatile unsigned char max_activescbs;
949 volatile unsigned char qinfifonext;
950 volatile unsigned char *untagged_scbs;
951 volatile unsigned char *qoutfifo;
952 volatile unsigned char *qinfifo;
954 unsigned char dev_last_queue_full[MAX_TARGETS];
955 unsigned char dev_last_queue_full_count[MAX_TARGETS];
956 unsigned short ultraenb; /* Gets downloaded to card as a
957 bitmap */
958 unsigned short discenable; /* Gets downloaded to card as a
959 bitmap */
960 transinfo_type user[MAX_TARGETS];
962 unsigned char msg_buf[13]; /* The message for the target */
963 unsigned char msg_type;
964 #define MSG_TYPE_NONE 0x00
965 #define MSG_TYPE_INITIATOR_MSGOUT 0x01
966 #define MSG_TYPE_INITIATOR_MSGIN 0x02
967 unsigned char msg_len; /* Length of message */
968 unsigned char msg_index; /* Index into msg_buf array */
972 * We put the less frequently used host structure items after the more
973 * frequently used items to try and ease the burden on the cache subsystem.
974 * These entries are not *commonly* accessed, whereas the preceding entries
975 * are accessed very often.
978 unsigned int irq; /* IRQ for this adapter */
979 int instance; /* aic7xxx instance number */
980 int scsi_id; /* host adapter SCSI ID */
981 int scsi_id_b; /* channel B for twin adapters */
982 unsigned int bios_address;
983 int board_name_index;
984 unsigned short bios_control; /* bios control - SEEPROM */
985 unsigned short adapter_control; /* adapter control - SEEPROM */
986 struct pci_dev *pdev;
987 unsigned char pci_bus;
988 unsigned char pci_device_fn;
989 struct seeprom_config sc;
990 unsigned short sc_type;
991 unsigned short sc_size;
992 struct aic7xxx_host *next; /* allow for multiple IRQs */
993 struct Scsi_Host *host; /* pointer to scsi host */
994 struct list_head aic_devs; /* all aic_dev structs on host */
995 int host_no; /* SCSI host number */
996 unsigned long mbase; /* I/O memory address */
997 ahc_chip chip; /* chip type */
998 ahc_bugs bugs;
999 dma_addr_t fifo_dma; /* DMA handle for fifo arrays */
1004 * Valid SCSIRATE values. (p. 3-17)
1005 * Provides a mapping of transfer periods in ns/4 to the proper value to
1006 * stick in the SCSIRATE reg to use that transfer rate.
1008 #define AHC_SYNCRATE_ULTRA3 0
1009 #define AHC_SYNCRATE_ULTRA2 1
1010 #define AHC_SYNCRATE_ULTRA 3
1011 #define AHC_SYNCRATE_FAST 6
1012 #define AHC_SYNCRATE_CRC 0x40
1013 #define AHC_SYNCRATE_SE 0x10
1014 static struct aic7xxx_syncrate {
1015 /* Rates in Ultra mode have bit 8 of sxfr set */
1016 #define ULTRA_SXFR 0x100
1017 int sxfr_ultra2;
1018 int sxfr;
1019 unsigned char period;
1020 const char *rate[2];
1021 } aic7xxx_syncrates[] = {
1022 { 0x42, 0x000, 9, {"80.0", "160.0"} },
1023 { 0x13, 0x000, 10, {"40.0", "80.0"} },
1024 { 0x14, 0x000, 11, {"33.0", "66.6"} },
1025 { 0x15, 0x100, 12, {"20.0", "40.0"} },
1026 { 0x16, 0x110, 15, {"16.0", "32.0"} },
1027 { 0x17, 0x120, 18, {"13.4", "26.8"} },
1028 { 0x18, 0x000, 25, {"10.0", "20.0"} },
1029 { 0x19, 0x010, 31, {"8.0", "16.0"} },
1030 { 0x1a, 0x020, 37, {"6.67", "13.3"} },
1031 { 0x1b, 0x030, 43, {"5.7", "11.4"} },
1032 { 0x10, 0x040, 50, {"5.0", "10.0"} },
1033 { 0x00, 0x050, 56, {"4.4", "8.8" } },
1034 { 0x00, 0x060, 62, {"4.0", "8.0" } },
1035 { 0x00, 0x070, 68, {"3.6", "7.2" } },
1036 { 0x00, 0x000, 0, {NULL, NULL} },
1039 #define CTL_OF_SCB(scb) (((scb->hscb)->target_channel_lun >> 3) & 0x1), \
1040 (((scb->hscb)->target_channel_lun >> 4) & 0xf), \
1041 ((scb->hscb)->target_channel_lun & 0x07)
1043 #define CTL_OF_CMD(cmd) ((cmd->device->channel) & 0x01), \
1044 ((cmd->device->id) & 0x0f), \
1045 ((cmd->device->lun) & 0x07)
1047 #define TARGET_INDEX(cmd) ((cmd)->device->id | ((cmd)->device->channel << 3))
1050 * A nice little define to make doing our printks a little easier
1053 #define WARN_LEAD KERN_WARNING "(scsi%d:%d:%d:%d) "
1054 #define INFO_LEAD KERN_INFO "(scsi%d:%d:%d:%d) "
1057 * XXX - these options apply unilaterally to _all_ 274x/284x/294x
1058 * cards in the system. This should be fixed. Exceptions to this
1059 * rule are noted in the comments.
1063 * Use this as the default queue depth when setting tagged queueing on.
1065 static unsigned int aic7xxx_default_queue_depth = AIC7XXX_CMDS_PER_DEVICE;
1068 * Skip the scsi bus reset. Non 0 make us skip the reset at startup. This
1069 * has no effect on any later resets that might occur due to things like
1070 * SCSI bus timeouts.
1072 static unsigned int aic7xxx_no_reset = 0;
1074 * Certain PCI motherboards will scan PCI devices from highest to lowest,
1075 * others scan from lowest to highest, and they tend to do all kinds of
1076 * strange things when they come into contact with PCI bridge chips. The
1077 * net result of all this is that the PCI card that is actually used to boot
1078 * the machine is very hard to detect. Most motherboards go from lowest
1079 * PCI slot number to highest, and the first SCSI controller found is the
1080 * one you boot from. The only exceptions to this are when a controller
1081 * has its BIOS disabled. So, we by default sort all of our SCSI controllers
1082 * from lowest PCI slot number to highest PCI slot number. We also force
1083 * all controllers with their BIOS disabled to the end of the list. This
1084 * works on *almost* all computers. Where it doesn't work, we have this
1085 * option. Setting this option to non-0 will reverse the order of the sort
1086 * to highest first, then lowest, but will still leave cards with their BIOS
1087 * disabled at the very end. That should fix everyone up unless there are
1088 * really strange cirumstances.
1090 static int aic7xxx_reverse_scan = 0;
1092 * Should we force EXTENDED translation on a controller.
1093 * 0 == Use whatever is in the SEEPROM or default to off
1094 * 1 == Use whatever is in the SEEPROM or default to on
1096 static unsigned int aic7xxx_extended = 0;
1098 * The IRQ trigger method used on EISA controllers. Does not effect PCI cards.
1099 * -1 = Use detected settings.
1100 * 0 = Force Edge triggered mode.
1101 * 1 = Force Level triggered mode.
1103 static int aic7xxx_irq_trigger = -1;
1105 * This variable is used to override the termination settings on a controller.
1106 * This should not be used under normal conditions. However, in the case
1107 * that a controller does not have a readable SEEPROM (so that we can't
1108 * read the SEEPROM settings directly) and that a controller has a buggered
1109 * version of the cable detection logic, this can be used to force the
1110 * correct termination. It is preferable to use the manual termination
1111 * settings in the BIOS if possible, but some motherboard controllers store
1112 * those settings in a format we can't read. In other cases, auto term
1113 * should also work, but the chipset was put together with no auto term
1114 * logic (common on motherboard controllers). In those cases, we have
1115 * 32 bits here to work with. That's good for 8 controllers/channels. The
1116 * bits are organized as 4 bits per channel, with scsi0 getting the lowest
1117 * 4 bits in the int. A 1 in a bit position indicates the termination setting
1118 * that corresponds to that bit should be enabled, a 0 is disabled.
1119 * It looks something like this:
1121 * 0x0f = 1111-Single Ended Low Byte Termination on/off
1122 * ||\-Single Ended High Byte Termination on/off
1123 * |\-LVD Low Byte Termination on/off
1124 * \-LVD High Byte Termination on/off
1126 * For non-Ultra2 controllers, the upper 2 bits are not important. So, to
1127 * enable both high byte and low byte termination on scsi0, I would need to
1128 * make sure that the override_term variable was set to 0x03 (bits 0011).
1129 * To make sure that all termination is enabled on an Ultra2 controller at
1130 * scsi2 and only high byte termination on scsi1 and high and low byte
1131 * termination on scsi0, I would set override_term=0xf23 (bits 1111 0010 0011)
1133 * For the most part, users should never have to use this, that's why I
1134 * left it fairly cryptic instead of easy to understand. If you need it,
1135 * most likely someone will be telling you what your's needs to be set to.
1137 static int aic7xxx_override_term = -1;
1139 * Certain motherboard chipset controllers tend to screw
1140 * up the polarity of the term enable output pin. Use this variable
1141 * to force the correct polarity for your system. This is a bitfield variable
1142 * similar to the previous one, but this one has one bit per channel instead
1143 * of four.
1144 * 0 = Force the setting to active low.
1145 * 1 = Force setting to active high.
1146 * Most Adaptec cards are active high, several motherboards are active low.
1147 * To force a 2940 card at SCSI 0 to active high and a motherboard 7895
1148 * controller at scsi1 and scsi2 to active low, and a 2910 card at scsi3
1149 * to active high, you would need to set stpwlev=0x9 (bits 1001).
1151 * People shouldn't need to use this, but if you are experiencing lots of
1152 * SCSI timeout problems, this may help. There is one sure way to test what
1153 * this option needs to be. Using a boot floppy to boot the system, configure
1154 * your system to enable all SCSI termination (in the Adaptec SCSI BIOS) and
1155 * if needed then also pass a value to override_term to make sure that the
1156 * driver is enabling SCSI termination, then set this variable to either 0
1157 * or 1. When the driver boots, make sure there are *NO* SCSI cables
1158 * connected to your controller. If it finds and inits the controller
1159 * without problem, then the setting you passed to stpwlev was correct. If
1160 * the driver goes into a reset loop and hangs the system, then you need the
1161 * other setting for this variable. If neither setting lets the machine
1162 * boot then you have definite termination problems that may not be fixable.
1164 static int aic7xxx_stpwlev = -1;
1166 * Set this to non-0 in order to force the driver to panic the kernel
1167 * and print out debugging info on a SCSI abort or reset cycle.
1169 static int aic7xxx_panic_on_abort = 0;
1171 * PCI bus parity checking of the Adaptec controllers. This is somewhat
1172 * dubious at best. To my knowledge, this option has never actually
1173 * solved a PCI parity problem, but on certain machines with broken PCI
1174 * chipset configurations, it can generate tons of false error messages.
1175 * It's included in the driver for completeness.
1176 * 0 = Shut off PCI parity check
1177 * -1 = Normal polarity pci parity checking
1178 * 1 = reverse polarity pci parity checking
1180 * NOTE: you can't actually pass -1 on the lilo prompt. So, to set this
1181 * variable to -1 you would actually want to simply pass the variable
1182 * name without a number. That will invert the 0 which will result in
1183 * -1.
1185 static int aic7xxx_pci_parity = 0;
1187 * Set this to any non-0 value to cause us to dump the contents of all
1188 * the card's registers in a hex dump format tailored to each model of
1189 * controller.
1191 * NOTE: THE CONTROLLER IS LEFT IN AN UNUSEABLE STATE BY THIS OPTION.
1192 * YOU CANNOT BOOT UP WITH THIS OPTION, IT IS FOR DEBUGGING PURPOSES
1193 * ONLY
1195 static int aic7xxx_dump_card = 0;
1197 * Set this to a non-0 value to make us dump out the 32 bit instruction
1198 * registers on the card after completing the sequencer download. This
1199 * allows the actual sequencer download to be verified. It is possible
1200 * to use this option and still boot up and run your system. This is
1201 * only intended for debugging purposes.
1203 static int aic7xxx_dump_sequencer = 0;
1205 * Certain newer motherboards have put new PCI based devices into the
1206 * IO spaces that used to typically be occupied by VLB or EISA cards.
1207 * This overlap can cause these newer motherboards to lock up when scanned
1208 * for older EISA and VLB devices. Setting this option to non-0 will
1209 * cause the driver to skip scanning for any VLB or EISA controllers and
1210 * only support the PCI controllers. NOTE: this means that if the kernel
1211 * os compiled with PCI support disabled, then setting this to non-0
1212 * would result in never finding any devices :)
1214 static int aic7xxx_no_probe = 0;
1216 * On some machines, enabling the external SCB RAM isn't reliable yet. I
1217 * haven't had time to make test patches for things like changing the
1218 * timing mode on that external RAM either. Some of those changes may
1219 * fix the problem. Until then though, we default to external SCB RAM
1220 * off and give a command line option to enable it.
1222 static int aic7xxx_scbram = 0;
1224 * So that we can set how long each device is given as a selection timeout.
1225 * The table of values goes like this:
1226 * 0 - 256ms
1227 * 1 - 128ms
1228 * 2 - 64ms
1229 * 3 - 32ms
1230 * We default to 64ms because it's fast. Some old SCSI-I devices need a
1231 * longer time. The final value has to be left shifted by 3, hence 0x10
1232 * is the final value.
1234 static int aic7xxx_seltime = 0x10;
1236 * So that insmod can find the variable and make it point to something
1238 #ifdef MODULE
1239 static char * aic7xxx = NULL;
1240 MODULE_PARM(aic7xxx, "s");
1241 #endif
1243 #define VERBOSE_NORMAL 0x0000
1244 #define VERBOSE_NEGOTIATION 0x0001
1245 #define VERBOSE_SEQINT 0x0002
1246 #define VERBOSE_SCSIINT 0x0004
1247 #define VERBOSE_PROBE 0x0008
1248 #define VERBOSE_PROBE2 0x0010
1249 #define VERBOSE_NEGOTIATION2 0x0020
1250 #define VERBOSE_MINOR_ERROR 0x0040
1251 #define VERBOSE_TRACING 0x0080
1252 #define VERBOSE_ABORT 0x0f00
1253 #define VERBOSE_ABORT_MID 0x0100
1254 #define VERBOSE_ABORT_FIND 0x0200
1255 #define VERBOSE_ABORT_PROCESS 0x0400
1256 #define VERBOSE_ABORT_RETURN 0x0800
1257 #define VERBOSE_RESET 0xf000
1258 #define VERBOSE_RESET_MID 0x1000
1259 #define VERBOSE_RESET_FIND 0x2000
1260 #define VERBOSE_RESET_PROCESS 0x4000
1261 #define VERBOSE_RESET_RETURN 0x8000
1262 static int aic7xxx_verbose = VERBOSE_NORMAL | VERBOSE_NEGOTIATION |
1263 VERBOSE_PROBE; /* verbose messages */
1266 /****************************************************************************
1268 * We're going to start putting in function declarations so that order of
1269 * functions is no longer important. As needed, they are added here.
1271 ***************************************************************************/
1273 static int aic7xxx_release(struct Scsi_Host *host);
1274 static void aic7xxx_set_syncrate(struct aic7xxx_host *p,
1275 struct aic7xxx_syncrate *syncrate, int target, int channel,
1276 unsigned int period, unsigned int offset, unsigned char options,
1277 unsigned int type, struct aic_dev_data *aic_dev);
1278 static void aic7xxx_set_width(struct aic7xxx_host *p, int target, int channel,
1279 int lun, unsigned int width, unsigned int type,
1280 struct aic_dev_data *aic_dev);
1281 static void aic7xxx_panic_abort(struct aic7xxx_host *p, Scsi_Cmnd *cmd);
1282 static void aic7xxx_print_card(struct aic7xxx_host *p);
1283 static void aic7xxx_print_scratch_ram(struct aic7xxx_host *p);
1284 static void aic7xxx_print_sequencer(struct aic7xxx_host *p, int downloaded);
1285 #ifdef AIC7XXX_VERBOSE_DEBUGGING
1286 static void aic7xxx_check_scbs(struct aic7xxx_host *p, char *buffer);
1287 #endif
1289 /****************************************************************************
1291 * These functions are now used. They happen to be wrapped in useless
1292 * inb/outb port read/writes around the real reads and writes because it
1293 * seems that certain very fast CPUs have a problem dealing with us when
1294 * going at full speed.
1296 ***************************************************************************/
1298 static inline unsigned char
1299 aic_inb(struct aic7xxx_host *p, long port)
1301 #ifdef MMAPIO
1302 unsigned char x;
1303 if(p->maddr)
1305 x = readb(p->maddr + port);
1307 else
1309 x = inb(p->base + port);
1311 return(x);
1312 #else
1313 return(inb(p->base + port));
1314 #endif
1317 static inline void
1318 aic_outb(struct aic7xxx_host *p, unsigned char val, long port)
1320 #ifdef MMAPIO
1321 if(p->maddr)
1323 writeb(val, p->maddr + port);
1324 mb(); /* locked operation in order to force CPU ordering */
1325 readb(p->maddr + HCNTRL); /* dummy read to flush the PCI write */
1327 else
1329 outb(val, p->base + port);
1330 mb(); /* locked operation in order to force CPU ordering */
1332 #else
1333 outb(val, p->base + port);
1334 mb(); /* locked operation in order to force CPU ordering */
1335 #endif
1338 /*+F*************************************************************************
1339 * Function:
1340 * aic7xxx_setup
1342 * Description:
1343 * Handle Linux boot parameters. This routine allows for assigning a value
1344 * to a parameter with a ':' between the parameter and the value.
1345 * ie. aic7xxx=unpause:0x0A,extended
1346 *-F*************************************************************************/
1347 static int
1348 aic7xxx_setup(char *s)
1350 int i, n;
1351 char *p;
1352 char *end;
1354 static struct {
1355 const char *name;
1356 unsigned int *flag;
1357 } options[] = {
1358 { "extended", &aic7xxx_extended },
1359 { "no_reset", &aic7xxx_no_reset },
1360 { "irq_trigger", &aic7xxx_irq_trigger },
1361 { "verbose", &aic7xxx_verbose },
1362 { "reverse_scan",&aic7xxx_reverse_scan },
1363 { "override_term", &aic7xxx_override_term },
1364 { "stpwlev", &aic7xxx_stpwlev },
1365 { "no_probe", &aic7xxx_no_probe },
1366 { "panic_on_abort", &aic7xxx_panic_on_abort },
1367 { "pci_parity", &aic7xxx_pci_parity },
1368 { "dump_card", &aic7xxx_dump_card },
1369 { "dump_sequencer", &aic7xxx_dump_sequencer },
1370 { "default_queue_depth", &aic7xxx_default_queue_depth },
1371 { "scbram", &aic7xxx_scbram },
1372 { "seltime", &aic7xxx_seltime },
1373 { "tag_info", NULL }
1376 end = strchr(s, '\0');
1378 while ((p = strsep(&s, ",.")) != NULL)
1380 for (i = 0; i < NUMBER(options); i++)
1382 n = strlen(options[i].name);
1383 if (!strncmp(options[i].name, p, n))
1385 if (!strncmp(p, "tag_info", n))
1387 if (p[n] == ':')
1389 char *base;
1390 char *tok, *tok_end, *tok_end2;
1391 char tok_list[] = { '.', ',', '{', '}', '\0' };
1392 int i, instance = -1, device = -1;
1393 unsigned char done = FALSE;
1395 base = p;
1396 tok = base + n + 1; /* Forward us just past the ':' */
1397 tok_end = strchr(tok, '\0');
1398 if (tok_end < end)
1399 *tok_end = ',';
1400 while(!done)
1402 switch(*tok)
1404 case '{':
1405 if (instance == -1)
1406 instance = 0;
1407 else if (device == -1)
1408 device = 0;
1409 tok++;
1410 break;
1411 case '}':
1412 if (device != -1)
1413 device = -1;
1414 else if (instance != -1)
1415 instance = -1;
1416 tok++;
1417 break;
1418 case ',':
1419 case '.':
1420 if (instance == -1)
1421 done = TRUE;
1422 else if (device >= 0)
1423 device++;
1424 else if (instance >= 0)
1425 instance++;
1426 if ( (device >= MAX_TARGETS) ||
1427 (instance >= NUMBER(aic7xxx_tag_info)) )
1428 done = TRUE;
1429 tok++;
1430 if (!done)
1432 base = tok;
1434 break;
1435 case '\0':
1436 done = TRUE;
1437 break;
1438 default:
1439 done = TRUE;
1440 tok_end = strchr(tok, '\0');
1441 for(i=0; tok_list[i]; i++)
1443 tok_end2 = strchr(tok, tok_list[i]);
1444 if ( (tok_end2) && (tok_end2 < tok_end) )
1446 tok_end = tok_end2;
1447 done = FALSE;
1450 if ( (instance >= 0) && (device >= 0) &&
1451 (instance < NUMBER(aic7xxx_tag_info)) &&
1452 (device < MAX_TARGETS) )
1453 aic7xxx_tag_info[instance].tag_commands[device] =
1454 simple_strtoul(tok, NULL, 0) & 0xff;
1455 tok = tok_end;
1456 break;
1459 while((p != base) && (p != NULL))
1460 p = strsep(&s, ",.");
1463 else if (p[n] == ':')
1465 *(options[i].flag) = simple_strtoul(p + n + 1, NULL, 0);
1466 if(!strncmp(p, "seltime", n))
1468 *(options[i].flag) = (*(options[i].flag) % 4) << 3;
1471 else if (!strncmp(p, "verbose", n))
1473 *(options[i].flag) = 0xff29;
1475 else
1477 *(options[i].flag) = ~(*(options[i].flag));
1478 if(!strncmp(p, "seltime", n))
1480 *(options[i].flag) = (*(options[i].flag) % 4) << 3;
1486 return 1;
1489 __setup("aic7xxx=", aic7xxx_setup);
1491 /*+F*************************************************************************
1492 * Function:
1493 * pause_sequencer
1495 * Description:
1496 * Pause the sequencer and wait for it to actually stop - this
1497 * is important since the sequencer can disable pausing for critical
1498 * sections.
1499 *-F*************************************************************************/
1500 static void
1501 pause_sequencer(struct aic7xxx_host *p)
1503 aic_outb(p, p->pause, HCNTRL);
1504 while ((aic_inb(p, HCNTRL) & PAUSE) == 0)
1508 if(p->features & AHC_ULTRA2)
1510 aic_inb(p, CCSCBCTL);
1514 /*+F*************************************************************************
1515 * Function:
1516 * unpause_sequencer
1518 * Description:
1519 * Unpause the sequencer. Unremarkable, yet done often enough to
1520 * warrant an easy way to do it.
1521 *-F*************************************************************************/
1522 static void
1523 unpause_sequencer(struct aic7xxx_host *p, int unpause_always)
1525 if (unpause_always ||
1526 ( !(aic_inb(p, INTSTAT) & (SCSIINT | SEQINT | BRKADRINT)) &&
1527 !(p->flags & AHC_HANDLING_REQINITS) ) )
1529 aic_outb(p, p->unpause, HCNTRL);
1533 /*+F*************************************************************************
1534 * Function:
1535 * restart_sequencer
1537 * Description:
1538 * Restart the sequencer program from address zero. This assumes
1539 * that the sequencer is already paused.
1540 *-F*************************************************************************/
1541 static void
1542 restart_sequencer(struct aic7xxx_host *p)
1544 aic_outb(p, 0, SEQADDR0);
1545 aic_outb(p, 0, SEQADDR1);
1546 aic_outb(p, FASTMODE, SEQCTL);
1550 * We include the aic7xxx_seq.c file here so that the other defines have
1551 * already been made, and so that it comes before the code that actually
1552 * downloads the instructions (since we don't typically use function
1553 * prototype, our code has to be ordered that way, it's a left-over from
1554 * the original driver days.....I should fix it some time DL).
1556 #include "aic7xxx_old/aic7xxx_seq.c"
1558 /*+F*************************************************************************
1559 * Function:
1560 * aic7xxx_check_patch
1562 * Description:
1563 * See if the next patch to download should be downloaded.
1564 *-F*************************************************************************/
1565 static int
1566 aic7xxx_check_patch(struct aic7xxx_host *p,
1567 struct sequencer_patch **start_patch, int start_instr, int *skip_addr)
1569 struct sequencer_patch *cur_patch;
1570 struct sequencer_patch *last_patch;
1571 int num_patches;
1573 num_patches = sizeof(sequencer_patches)/sizeof(struct sequencer_patch);
1574 last_patch = &sequencer_patches[num_patches];
1575 cur_patch = *start_patch;
1577 while ((cur_patch < last_patch) && (start_instr == cur_patch->begin))
1579 if (cur_patch->patch_func(p) == 0)
1582 * Start rejecting code.
1584 *skip_addr = start_instr + cur_patch->skip_instr;
1585 cur_patch += cur_patch->skip_patch;
1587 else
1590 * Found an OK patch. Advance the patch pointer to the next patch
1591 * and wait for our instruction pointer to get here.
1593 cur_patch++;
1597 *start_patch = cur_patch;
1598 if (start_instr < *skip_addr)
1600 * Still skipping
1602 return (0);
1603 return(1);
1607 /*+F*************************************************************************
1608 * Function:
1609 * aic7xxx_download_instr
1611 * Description:
1612 * Find the next patch to download.
1613 *-F*************************************************************************/
1614 static void
1615 aic7xxx_download_instr(struct aic7xxx_host *p, int instrptr,
1616 unsigned char *dconsts)
1618 union ins_formats instr;
1619 struct ins_format1 *fmt1_ins;
1620 struct ins_format3 *fmt3_ins;
1621 unsigned char opcode;
1623 instr = *(union ins_formats*) &seqprog[instrptr * 4];
1625 instr.integer = le32_to_cpu(instr.integer);
1627 fmt1_ins = &instr.format1;
1628 fmt3_ins = NULL;
1630 /* Pull the opcode */
1631 opcode = instr.format1.opcode;
1632 switch (opcode)
1634 case AIC_OP_JMP:
1635 case AIC_OP_JC:
1636 case AIC_OP_JNC:
1637 case AIC_OP_CALL:
1638 case AIC_OP_JNE:
1639 case AIC_OP_JNZ:
1640 case AIC_OP_JE:
1641 case AIC_OP_JZ:
1643 struct sequencer_patch *cur_patch;
1644 int address_offset;
1645 unsigned int address;
1646 int skip_addr;
1647 int i;
1649 fmt3_ins = &instr.format3;
1650 address_offset = 0;
1651 address = fmt3_ins->address;
1652 cur_patch = sequencer_patches;
1653 skip_addr = 0;
1655 for (i = 0; i < address;)
1657 aic7xxx_check_patch(p, &cur_patch, i, &skip_addr);
1658 if (skip_addr > i)
1660 int end_addr;
1662 end_addr = MIN(address, skip_addr);
1663 address_offset += end_addr - i;
1664 i = skip_addr;
1666 else
1668 i++;
1671 address -= address_offset;
1672 fmt3_ins->address = address;
1673 /* Fall Through to the next code section */
1675 case AIC_OP_OR:
1676 case AIC_OP_AND:
1677 case AIC_OP_XOR:
1678 case AIC_OP_ADD:
1679 case AIC_OP_ADC:
1680 case AIC_OP_BMOV:
1681 if (fmt1_ins->parity != 0)
1683 fmt1_ins->immediate = dconsts[fmt1_ins->immediate];
1685 fmt1_ins->parity = 0;
1686 /* Fall Through to the next code section */
1687 case AIC_OP_ROL:
1688 if ((p->features & AHC_ULTRA2) != 0)
1690 int i, count;
1692 /* Calculate odd parity for the instruction */
1693 for ( i=0, count=0; i < 31; i++)
1695 unsigned int mask;
1697 mask = 0x01 << i;
1698 if ((instr.integer & mask) != 0)
1699 count++;
1701 if (!(count & 0x01))
1702 instr.format1.parity = 1;
1704 else
1706 if (fmt3_ins != NULL)
1708 instr.integer = fmt3_ins->immediate |
1709 (fmt3_ins->source << 8) |
1710 (fmt3_ins->address << 16) |
1711 (fmt3_ins->opcode << 25);
1713 else
1715 instr.integer = fmt1_ins->immediate |
1716 (fmt1_ins->source << 8) |
1717 (fmt1_ins->destination << 16) |
1718 (fmt1_ins->ret << 24) |
1719 (fmt1_ins->opcode << 25);
1722 aic_outb(p, (instr.integer & 0xff), SEQRAM);
1723 aic_outb(p, ((instr.integer >> 8) & 0xff), SEQRAM);
1724 aic_outb(p, ((instr.integer >> 16) & 0xff), SEQRAM);
1725 aic_outb(p, ((instr.integer >> 24) & 0xff), SEQRAM);
1726 udelay(10);
1727 break;
1729 default:
1730 panic("aic7xxx: Unknown opcode encountered in sequencer program.");
1731 break;
1736 /*+F*************************************************************************
1737 * Function:
1738 * aic7xxx_loadseq
1740 * Description:
1741 * Load the sequencer code into the controller memory.
1742 *-F*************************************************************************/
1743 static void
1744 aic7xxx_loadseq(struct aic7xxx_host *p)
1746 struct sequencer_patch *cur_patch;
1747 int i;
1748 int downloaded;
1749 int skip_addr;
1750 unsigned char download_consts[4] = {0, 0, 0, 0};
1752 if (aic7xxx_verbose & VERBOSE_PROBE)
1754 printk(KERN_INFO "(scsi%d) Downloading sequencer code...", p->host_no);
1756 #if 0
1757 download_consts[TMODE_NUMCMDS] = p->num_targetcmds;
1758 #endif
1759 download_consts[TMODE_NUMCMDS] = 0;
1760 cur_patch = &sequencer_patches[0];
1761 downloaded = 0;
1762 skip_addr = 0;
1764 aic_outb(p, PERRORDIS|LOADRAM|FAILDIS|FASTMODE, SEQCTL);
1765 aic_outb(p, 0, SEQADDR0);
1766 aic_outb(p, 0, SEQADDR1);
1768 for (i = 0; i < sizeof(seqprog) / 4; i++)
1770 if (aic7xxx_check_patch(p, &cur_patch, i, &skip_addr) == 0)
1772 /* Skip this instruction for this configuration. */
1773 continue;
1775 aic7xxx_download_instr(p, i, &download_consts[0]);
1776 downloaded++;
1779 aic_outb(p, 0, SEQADDR0);
1780 aic_outb(p, 0, SEQADDR1);
1781 aic_outb(p, FASTMODE | FAILDIS, SEQCTL);
1782 unpause_sequencer(p, TRUE);
1783 mdelay(1);
1784 pause_sequencer(p);
1785 aic_outb(p, FASTMODE, SEQCTL);
1786 if (aic7xxx_verbose & VERBOSE_PROBE)
1788 printk(" %d instructions downloaded\n", downloaded);
1790 if (aic7xxx_dump_sequencer)
1791 aic7xxx_print_sequencer(p, downloaded);
1794 /*+F*************************************************************************
1795 * Function:
1796 * aic7xxx_print_sequencer
1798 * Description:
1799 * Print the contents of the sequencer memory to the screen.
1800 *-F*************************************************************************/
1801 static void
1802 aic7xxx_print_sequencer(struct aic7xxx_host *p, int downloaded)
1804 int i, k, temp;
1806 aic_outb(p, PERRORDIS|LOADRAM|FAILDIS|FASTMODE, SEQCTL);
1807 aic_outb(p, 0, SEQADDR0);
1808 aic_outb(p, 0, SEQADDR1);
1810 k = 0;
1811 for (i=0; i < downloaded; i++)
1813 if ( k == 0 )
1814 printk("%03x: ", i);
1815 temp = aic_inb(p, SEQRAM);
1816 temp |= (aic_inb(p, SEQRAM) << 8);
1817 temp |= (aic_inb(p, SEQRAM) << 16);
1818 temp |= (aic_inb(p, SEQRAM) << 24);
1819 printk("%08x", temp);
1820 if ( ++k == 8 )
1822 printk("\n");
1823 k = 0;
1825 else
1826 printk(" ");
1828 aic_outb(p, 0, SEQADDR0);
1829 aic_outb(p, 0, SEQADDR1);
1830 aic_outb(p, FASTMODE | FAILDIS, SEQCTL);
1831 unpause_sequencer(p, TRUE);
1832 mdelay(1);
1833 pause_sequencer(p);
1834 aic_outb(p, FASTMODE, SEQCTL);
1835 printk("\n");
1838 /*+F*************************************************************************
1839 * Function:
1840 * aic7xxx_info
1842 * Description:
1843 * Return a string describing the driver.
1844 *-F*************************************************************************/
1845 const char *
1846 aic7xxx_info(struct Scsi_Host *dooh)
1848 static char buffer[256];
1849 char *bp;
1850 struct aic7xxx_host *p;
1852 bp = &buffer[0];
1853 p = (struct aic7xxx_host *)dooh->hostdata;
1854 memset(bp, 0, sizeof(buffer));
1855 strcpy(bp, "Adaptec AHA274x/284x/294x (EISA/VLB/PCI-Fast SCSI) ");
1856 strcat(bp, AIC7XXX_C_VERSION);
1857 strcat(bp, "/");
1858 strcat(bp, AIC7XXX_H_VERSION);
1859 strcat(bp, "\n");
1860 strcat(bp, " <");
1861 strcat(bp, board_names[p->board_name_index]);
1862 strcat(bp, ">");
1864 return(bp);
1867 /*+F*************************************************************************
1868 * Function:
1869 * aic7xxx_find_syncrate
1871 * Description:
1872 * Look up the valid period to SCSIRATE conversion in our table
1873 *-F*************************************************************************/
1874 static struct aic7xxx_syncrate *
1875 aic7xxx_find_syncrate(struct aic7xxx_host *p, unsigned int *period,
1876 unsigned int maxsync, unsigned char *options)
1878 struct aic7xxx_syncrate *syncrate;
1879 int done = FALSE;
1881 switch(*options)
1883 case MSG_EXT_PPR_OPTION_DT_CRC:
1884 case MSG_EXT_PPR_OPTION_DT_UNITS:
1885 if(!(p->features & AHC_ULTRA3))
1887 *options = 0;
1888 maxsync = MAX(maxsync, AHC_SYNCRATE_ULTRA2);
1890 break;
1891 case MSG_EXT_PPR_OPTION_DT_CRC_QUICK:
1892 case MSG_EXT_PPR_OPTION_DT_UNITS_QUICK:
1893 if(!(p->features & AHC_ULTRA3))
1895 *options = 0;
1896 maxsync = MAX(maxsync, AHC_SYNCRATE_ULTRA2);
1898 else
1901 * we don't support the Quick Arbitration variants of dual edge
1902 * clocking. As it turns out, we want to send back the
1903 * same basic option, but without the QA attribute.
1904 * We know that we are responding because we would never set
1905 * these options ourself, we would only respond to them.
1907 switch(*options)
1909 case MSG_EXT_PPR_OPTION_DT_CRC_QUICK:
1910 *options = MSG_EXT_PPR_OPTION_DT_CRC;
1911 break;
1912 case MSG_EXT_PPR_OPTION_DT_UNITS_QUICK:
1913 *options = MSG_EXT_PPR_OPTION_DT_UNITS;
1914 break;
1917 break;
1918 default:
1919 *options = 0;
1920 maxsync = MAX(maxsync, AHC_SYNCRATE_ULTRA2);
1921 break;
1923 syncrate = &aic7xxx_syncrates[maxsync];
1924 while ( (syncrate->rate[0] != NULL) &&
1925 (!(p->features & AHC_ULTRA2) || syncrate->sxfr_ultra2) )
1927 if (*period <= syncrate->period)
1929 switch(*options)
1931 case MSG_EXT_PPR_OPTION_DT_CRC:
1932 case MSG_EXT_PPR_OPTION_DT_UNITS:
1933 if(!(syncrate->sxfr_ultra2 & AHC_SYNCRATE_CRC))
1935 done = TRUE;
1937 * oops, we went too low for the CRC/DualEdge signalling, so
1938 * clear the options byte
1940 *options = 0;
1942 * We'll be sending a reply to this packet to set the options
1943 * properly, so unilaterally set the period as well.
1945 *period = syncrate->period;
1947 else
1949 done = TRUE;
1950 if(syncrate == &aic7xxx_syncrates[maxsync])
1952 *period = syncrate->period;
1955 break;
1956 default:
1957 if(!(syncrate->sxfr_ultra2 & AHC_SYNCRATE_CRC))
1959 done = TRUE;
1960 if(syncrate == &aic7xxx_syncrates[maxsync])
1962 *period = syncrate->period;
1965 break;
1967 if(done)
1969 break;
1972 syncrate++;
1974 if ( (*period == 0) || (syncrate->rate[0] == NULL) ||
1975 ((p->features & AHC_ULTRA2) && (syncrate->sxfr_ultra2 == 0)) )
1978 * Use async transfers for this target
1980 *options = 0;
1981 *period = 255;
1982 syncrate = NULL;
1984 return (syncrate);
1988 /*+F*************************************************************************
1989 * Function:
1990 * aic7xxx_find_period
1992 * Description:
1993 * Look up the valid SCSIRATE to period conversion in our table
1994 *-F*************************************************************************/
1995 static unsigned int
1996 aic7xxx_find_period(struct aic7xxx_host *p, unsigned int scsirate,
1997 unsigned int maxsync)
1999 struct aic7xxx_syncrate *syncrate;
2001 if (p->features & AHC_ULTRA2)
2003 scsirate &= SXFR_ULTRA2;
2005 else
2007 scsirate &= SXFR;
2010 syncrate = &aic7xxx_syncrates[maxsync];
2011 while (syncrate->rate[0] != NULL)
2013 if (p->features & AHC_ULTRA2)
2015 if (syncrate->sxfr_ultra2 == 0)
2016 break;
2017 else if (scsirate == syncrate->sxfr_ultra2)
2018 return (syncrate->period);
2019 else if (scsirate == (syncrate->sxfr_ultra2 & ~AHC_SYNCRATE_CRC))
2020 return (syncrate->period);
2022 else if (scsirate == (syncrate->sxfr & ~ULTRA_SXFR))
2024 return (syncrate->period);
2026 syncrate++;
2028 return (0); /* async */
2031 /*+F*************************************************************************
2032 * Function:
2033 * aic7xxx_validate_offset
2035 * Description:
2036 * Set a valid offset value for a particular card in use and transfer
2037 * settings in use.
2038 *-F*************************************************************************/
2039 static void
2040 aic7xxx_validate_offset(struct aic7xxx_host *p,
2041 struct aic7xxx_syncrate *syncrate, unsigned int *offset, int wide)
2043 unsigned int maxoffset;
2045 /* Limit offset to what the card (and device) can do */
2046 if (syncrate == NULL)
2048 maxoffset = 0;
2050 else if (p->features & AHC_ULTRA2)
2052 maxoffset = MAX_OFFSET_ULTRA2;
2054 else
2056 if (wide)
2057 maxoffset = MAX_OFFSET_16BIT;
2058 else
2059 maxoffset = MAX_OFFSET_8BIT;
2061 *offset = MIN(*offset, maxoffset);
2064 /*+F*************************************************************************
2065 * Function:
2066 * aic7xxx_set_syncrate
2068 * Description:
2069 * Set the actual syncrate down in the card and in our host structs
2070 *-F*************************************************************************/
2071 static void
2072 aic7xxx_set_syncrate(struct aic7xxx_host *p, struct aic7xxx_syncrate *syncrate,
2073 int target, int channel, unsigned int period, unsigned int offset,
2074 unsigned char options, unsigned int type, struct aic_dev_data *aic_dev)
2076 unsigned char tindex;
2077 unsigned short target_mask;
2078 unsigned char lun, old_options;
2079 unsigned int old_period, old_offset;
2081 tindex = target | (channel << 3);
2082 target_mask = 0x01 << tindex;
2083 lun = aic_inb(p, SCB_TCL) & 0x07;
2085 if (syncrate == NULL)
2087 period = 0;
2088 offset = 0;
2091 old_period = aic_dev->cur.period;
2092 old_offset = aic_dev->cur.offset;
2093 old_options = aic_dev->cur.options;
2096 if (type & AHC_TRANS_CUR)
2098 unsigned int scsirate;
2100 scsirate = aic_inb(p, TARG_SCSIRATE + tindex);
2101 if (p->features & AHC_ULTRA2)
2103 scsirate &= ~SXFR_ULTRA2;
2104 if (syncrate != NULL)
2106 switch(options)
2108 case MSG_EXT_PPR_OPTION_DT_UNITS:
2110 * mask off the CRC bit in the xfer settings
2112 scsirate |= (syncrate->sxfr_ultra2 & ~AHC_SYNCRATE_CRC);
2113 break;
2114 default:
2115 scsirate |= syncrate->sxfr_ultra2;
2116 break;
2119 if (type & AHC_TRANS_ACTIVE)
2121 aic_outb(p, offset, SCSIOFFSET);
2123 aic_outb(p, offset, TARG_OFFSET + tindex);
2125 else /* Not an Ultra2 controller */
2127 scsirate &= ~(SXFR|SOFS);
2128 p->ultraenb &= ~target_mask;
2129 if (syncrate != NULL)
2131 if (syncrate->sxfr & ULTRA_SXFR)
2133 p->ultraenb |= target_mask;
2135 scsirate |= (syncrate->sxfr & SXFR);
2136 scsirate |= (offset & SOFS);
2138 if (type & AHC_TRANS_ACTIVE)
2140 unsigned char sxfrctl0;
2142 sxfrctl0 = aic_inb(p, SXFRCTL0);
2143 sxfrctl0 &= ~FAST20;
2144 if (p->ultraenb & target_mask)
2145 sxfrctl0 |= FAST20;
2146 aic_outb(p, sxfrctl0, SXFRCTL0);
2148 aic_outb(p, p->ultraenb & 0xff, ULTRA_ENB);
2149 aic_outb(p, (p->ultraenb >> 8) & 0xff, ULTRA_ENB + 1 );
2151 if (type & AHC_TRANS_ACTIVE)
2153 aic_outb(p, scsirate, SCSIRATE);
2155 aic_outb(p, scsirate, TARG_SCSIRATE + tindex);
2156 aic_dev->cur.period = period;
2157 aic_dev->cur.offset = offset;
2158 aic_dev->cur.options = options;
2159 if ( !(type & AHC_TRANS_QUITE) &&
2160 (aic7xxx_verbose & VERBOSE_NEGOTIATION) &&
2161 (aic_dev->flags & DEVICE_PRINT_DTR) )
2163 if (offset)
2165 int rate_mod = (scsirate & WIDEXFER) ? 1 : 0;
2167 printk(INFO_LEAD "Synchronous at %s Mbyte/sec, "
2168 "offset %d.\n", p->host_no, channel, target, lun,
2169 syncrate->rate[rate_mod], offset);
2171 else
2173 printk(INFO_LEAD "Using asynchronous transfers.\n",
2174 p->host_no, channel, target, lun);
2176 aic_dev->flags &= ~DEVICE_PRINT_DTR;
2180 if (type & AHC_TRANS_GOAL)
2182 aic_dev->goal.period = period;
2183 aic_dev->goal.offset = offset;
2184 aic_dev->goal.options = options;
2187 if (type & AHC_TRANS_USER)
2189 p->user[tindex].period = period;
2190 p->user[tindex].offset = offset;
2191 p->user[tindex].options = options;
2195 /*+F*************************************************************************
2196 * Function:
2197 * aic7xxx_set_width
2199 * Description:
2200 * Set the actual width down in the card and in our host structs
2201 *-F*************************************************************************/
2202 static void
2203 aic7xxx_set_width(struct aic7xxx_host *p, int target, int channel, int lun,
2204 unsigned int width, unsigned int type, struct aic_dev_data *aic_dev)
2206 unsigned char tindex;
2207 unsigned short target_mask;
2208 unsigned int old_width;
2210 tindex = target | (channel << 3);
2211 target_mask = 1 << tindex;
2213 old_width = aic_dev->cur.width;
2215 if (type & AHC_TRANS_CUR)
2217 unsigned char scsirate;
2219 scsirate = aic_inb(p, TARG_SCSIRATE + tindex);
2221 scsirate &= ~WIDEXFER;
2222 if (width == MSG_EXT_WDTR_BUS_16_BIT)
2223 scsirate |= WIDEXFER;
2225 aic_outb(p, scsirate, TARG_SCSIRATE + tindex);
2227 if (type & AHC_TRANS_ACTIVE)
2228 aic_outb(p, scsirate, SCSIRATE);
2230 aic_dev->cur.width = width;
2232 if ( !(type & AHC_TRANS_QUITE) &&
2233 (aic7xxx_verbose & VERBOSE_NEGOTIATION2) &&
2234 (aic_dev->flags & DEVICE_PRINT_DTR) )
2236 printk(INFO_LEAD "Using %s transfers\n", p->host_no, channel, target,
2237 lun, (scsirate & WIDEXFER) ? "Wide(16bit)" : "Narrow(8bit)" );
2241 if (type & AHC_TRANS_GOAL)
2242 aic_dev->goal.width = width;
2243 if (type & AHC_TRANS_USER)
2244 p->user[tindex].width = width;
2246 if (aic_dev->goal.offset)
2248 if (p->features & AHC_ULTRA2)
2250 aic_dev->goal.offset = MAX_OFFSET_ULTRA2;
2252 else if (width == MSG_EXT_WDTR_BUS_16_BIT)
2254 aic_dev->goal.offset = MAX_OFFSET_16BIT;
2256 else
2258 aic_dev->goal.offset = MAX_OFFSET_8BIT;
2263 /*+F*************************************************************************
2264 * Function:
2265 * scbq_init
2267 * Description:
2268 * SCB queue initialization.
2270 *-F*************************************************************************/
2271 static void
2272 scbq_init(volatile scb_queue_type *queue)
2274 queue->head = NULL;
2275 queue->tail = NULL;
2278 /*+F*************************************************************************
2279 * Function:
2280 * scbq_insert_head
2282 * Description:
2283 * Add an SCB to the head of the list.
2285 *-F*************************************************************************/
2286 static inline void
2287 scbq_insert_head(volatile scb_queue_type *queue, struct aic7xxx_scb *scb)
2289 scb->q_next = queue->head;
2290 queue->head = scb;
2291 if (queue->tail == NULL) /* If list was empty, update tail. */
2292 queue->tail = queue->head;
2295 /*+F*************************************************************************
2296 * Function:
2297 * scbq_remove_head
2299 * Description:
2300 * Remove an SCB from the head of the list.
2302 *-F*************************************************************************/
2303 static inline struct aic7xxx_scb *
2304 scbq_remove_head(volatile scb_queue_type *queue)
2306 struct aic7xxx_scb * scbp;
2308 scbp = queue->head;
2309 if (queue->head != NULL)
2310 queue->head = queue->head->q_next;
2311 if (queue->head == NULL) /* If list is now empty, update tail. */
2312 queue->tail = NULL;
2313 return(scbp);
2316 /*+F*************************************************************************
2317 * Function:
2318 * scbq_remove
2320 * Description:
2321 * Removes an SCB from the list.
2323 *-F*************************************************************************/
2324 static inline void
2325 scbq_remove(volatile scb_queue_type *queue, struct aic7xxx_scb *scb)
2327 if (queue->head == scb)
2329 /* At beginning of queue, remove from head. */
2330 scbq_remove_head(queue);
2332 else
2334 struct aic7xxx_scb *curscb = queue->head;
2337 * Search until the next scb is the one we're looking for, or
2338 * we run out of queue.
2340 while ((curscb != NULL) && (curscb->q_next != scb))
2342 curscb = curscb->q_next;
2344 if (curscb != NULL)
2346 /* Found it. */
2347 curscb->q_next = scb->q_next;
2348 if (scb->q_next == NULL)
2350 /* Update the tail when removing the tail. */
2351 queue->tail = curscb;
2357 /*+F*************************************************************************
2358 * Function:
2359 * scbq_insert_tail
2361 * Description:
2362 * Add an SCB at the tail of the list.
2364 *-F*************************************************************************/
2365 static inline void
2366 scbq_insert_tail(volatile scb_queue_type *queue, struct aic7xxx_scb *scb)
2368 scb->q_next = NULL;
2369 if (queue->tail != NULL) /* Add the scb at the end of the list. */
2370 queue->tail->q_next = scb;
2371 queue->tail = scb; /* Update the tail. */
2372 if (queue->head == NULL) /* If list was empty, update head. */
2373 queue->head = queue->tail;
2376 /*+F*************************************************************************
2377 * Function:
2378 * aic7xxx_match_scb
2380 * Description:
2381 * Checks to see if an scb matches the target/channel as specified.
2382 * If target is ALL_TARGETS (-1), then we're looking for any device
2383 * on the specified channel; this happens when a channel is going
2384 * to be reset and all devices on that channel must be aborted.
2385 *-F*************************************************************************/
2386 static int
2387 aic7xxx_match_scb(struct aic7xxx_host *p, struct aic7xxx_scb *scb,
2388 int target, int channel, int lun, unsigned char tag)
2390 int targ = (scb->hscb->target_channel_lun >> 4) & 0x0F;
2391 int chan = (scb->hscb->target_channel_lun >> 3) & 0x01;
2392 int slun = scb->hscb->target_channel_lun & 0x07;
2393 int match;
2395 match = ((chan == channel) || (channel == ALL_CHANNELS));
2396 if (match != 0)
2397 match = ((targ == target) || (target == ALL_TARGETS));
2398 if (match != 0)
2399 match = ((lun == slun) || (lun == ALL_LUNS));
2400 if (match != 0)
2401 match = ((tag == scb->hscb->tag) || (tag == SCB_LIST_NULL));
2403 return (match);
2406 /*+F*************************************************************************
2407 * Function:
2408 * aic7xxx_add_curscb_to_free_list
2410 * Description:
2411 * Adds the current scb (in SCBPTR) to the list of free SCBs.
2412 *-F*************************************************************************/
2413 static void
2414 aic7xxx_add_curscb_to_free_list(struct aic7xxx_host *p)
2417 * Invalidate the tag so that aic7xxx_find_scb doesn't think
2418 * it's active
2420 aic_outb(p, SCB_LIST_NULL, SCB_TAG);
2421 aic_outb(p, 0, SCB_CONTROL);
2423 aic_outb(p, aic_inb(p, FREE_SCBH), SCB_NEXT);
2424 aic_outb(p, aic_inb(p, SCBPTR), FREE_SCBH);
2427 /*+F*************************************************************************
2428 * Function:
2429 * aic7xxx_rem_scb_from_disc_list
2431 * Description:
2432 * Removes the current SCB from the disconnected list and adds it
2433 * to the free list.
2434 *-F*************************************************************************/
2435 static unsigned char
2436 aic7xxx_rem_scb_from_disc_list(struct aic7xxx_host *p, unsigned char scbptr,
2437 unsigned char prev)
2439 unsigned char next;
2441 aic_outb(p, scbptr, SCBPTR);
2442 next = aic_inb(p, SCB_NEXT);
2443 aic7xxx_add_curscb_to_free_list(p);
2445 if (prev != SCB_LIST_NULL)
2447 aic_outb(p, prev, SCBPTR);
2448 aic_outb(p, next, SCB_NEXT);
2450 else
2452 aic_outb(p, next, DISCONNECTED_SCBH);
2455 return next;
2458 /*+F*************************************************************************
2459 * Function:
2460 * aic7xxx_busy_target
2462 * Description:
2463 * Set the specified target busy.
2464 *-F*************************************************************************/
2465 static inline void
2466 aic7xxx_busy_target(struct aic7xxx_host *p, struct aic7xxx_scb *scb)
2468 p->untagged_scbs[scb->hscb->target_channel_lun] = scb->hscb->tag;
2471 /*+F*************************************************************************
2472 * Function:
2473 * aic7xxx_index_busy_target
2475 * Description:
2476 * Returns the index of the busy target, and optionally sets the
2477 * target inactive.
2478 *-F*************************************************************************/
2479 static inline unsigned char
2480 aic7xxx_index_busy_target(struct aic7xxx_host *p, unsigned char tcl,
2481 int unbusy)
2483 unsigned char busy_scbid;
2485 busy_scbid = p->untagged_scbs[tcl];
2486 if (unbusy)
2488 p->untagged_scbs[tcl] = SCB_LIST_NULL;
2490 return (busy_scbid);
2493 /*+F*************************************************************************
2494 * Function:
2495 * aic7xxx_find_scb
2497 * Description:
2498 * Look through the SCB array of the card and attempt to find the
2499 * hardware SCB that corresponds to the passed in SCB. Return
2500 * SCB_LIST_NULL if unsuccessful. This routine assumes that the
2501 * card is already paused.
2502 *-F*************************************************************************/
2503 static unsigned char
2504 aic7xxx_find_scb(struct aic7xxx_host *p, struct aic7xxx_scb *scb)
2506 unsigned char saved_scbptr;
2507 unsigned char curindex;
2509 saved_scbptr = aic_inb(p, SCBPTR);
2510 curindex = 0;
2511 for (curindex = 0; curindex < p->scb_data->maxhscbs; curindex++)
2513 aic_outb(p, curindex, SCBPTR);
2514 if (aic_inb(p, SCB_TAG) == scb->hscb->tag)
2516 break;
2519 aic_outb(p, saved_scbptr, SCBPTR);
2520 if (curindex >= p->scb_data->maxhscbs)
2522 curindex = SCB_LIST_NULL;
2525 return (curindex);
2528 /*+F*************************************************************************
2529 * Function:
2530 * aic7xxx_allocate_scb
2532 * Description:
2533 * Get an SCB from the free list or by allocating a new one.
2534 *-F*************************************************************************/
2535 static int
2536 aic7xxx_allocate_scb(struct aic7xxx_host *p)
2538 struct aic7xxx_scb *scbp = NULL;
2539 int scb_size = (sizeof (struct hw_scatterlist) * AIC7XXX_MAX_SG) + 12 + 6;
2540 int i;
2541 int step = PAGE_SIZE / 1024;
2542 unsigned long scb_count = 0;
2543 struct hw_scatterlist *hsgp;
2544 struct aic7xxx_scb *scb_ap;
2545 struct aic7xxx_scb_dma *scb_dma;
2546 unsigned char *bufs;
2548 if (p->scb_data->numscbs < p->scb_data->maxscbs)
2551 * Calculate the optimal number of SCBs to allocate.
2553 * NOTE: This formula works because the sizeof(sg_array) is always
2554 * 1024. Therefore, scb_size * i would always be > PAGE_SIZE *
2555 * (i/step). The (i-1) allows the left hand side of the equation
2556 * to grow into the right hand side to a point of near perfect
2557 * efficiency since scb_size * (i -1) is growing slightly faster
2558 * than the right hand side. If the number of SG array elements
2559 * is changed, this function may not be near so efficient any more.
2561 * Since the DMA'able buffers are now allocated in a separate
2562 * chunk this algorithm has been modified to match. The '12'
2563 * and '6' factors in scb_size are for the DMA'able command byte
2564 * and sensebuffers respectively. -DaveM
2566 for ( i=step;; i *= 2 )
2568 if ( (scb_size * (i-1)) >= ( (PAGE_SIZE * (i/step)) - 64 ) )
2570 i /= 2;
2571 break;
2574 scb_count = MIN( (i-1), p->scb_data->maxscbs - p->scb_data->numscbs);
2575 scb_ap = (struct aic7xxx_scb *)kmalloc(sizeof (struct aic7xxx_scb) * scb_count
2576 + sizeof(struct aic7xxx_scb_dma), GFP_ATOMIC);
2577 if (scb_ap == NULL)
2578 return(0);
2579 scb_dma = (struct aic7xxx_scb_dma *)&scb_ap[scb_count];
2580 hsgp = (struct hw_scatterlist *)
2581 pci_alloc_consistent(p->pdev, scb_size * scb_count,
2582 &scb_dma->dma_address);
2583 if (hsgp == NULL)
2585 kfree(scb_ap);
2586 return(0);
2588 bufs = (unsigned char *)&hsgp[scb_count * AIC7XXX_MAX_SG];
2589 #ifdef AIC7XXX_VERBOSE_DEBUGGING
2590 if (aic7xxx_verbose > 0xffff)
2592 if (p->scb_data->numscbs == 0)
2593 printk(INFO_LEAD "Allocating initial %ld SCB structures.\n",
2594 p->host_no, -1, -1, -1, scb_count);
2595 else
2596 printk(INFO_LEAD "Allocating %ld additional SCB structures.\n",
2597 p->host_no, -1, -1, -1, scb_count);
2599 #endif
2600 memset(scb_ap, 0, sizeof (struct aic7xxx_scb) * scb_count);
2601 scb_dma->dma_offset = (unsigned long)scb_dma->dma_address
2602 - (unsigned long)hsgp;
2603 scb_dma->dma_len = scb_size * scb_count;
2604 for (i=0; i < scb_count; i++)
2606 scbp = &scb_ap[i];
2607 scbp->hscb = &p->scb_data->hscbs[p->scb_data->numscbs];
2608 scbp->sg_list = &hsgp[i * AIC7XXX_MAX_SG];
2609 scbp->sense_cmd = bufs;
2610 scbp->cmnd = bufs + 6;
2611 bufs += 12 + 6;
2612 scbp->scb_dma = scb_dma;
2613 memset(scbp->hscb, 0, sizeof(struct aic7xxx_hwscb));
2614 scbp->hscb->tag = p->scb_data->numscbs;
2616 * Place in the scb array; never is removed
2618 p->scb_data->scb_array[p->scb_data->numscbs++] = scbp;
2619 scbq_insert_tail(&p->scb_data->free_scbs, scbp);
2621 scbp->kmalloc_ptr = scb_ap;
2623 return(scb_count);
2626 /*+F*************************************************************************
2627 * Function:
2628 * aic7xxx_queue_cmd_complete
2630 * Description:
2631 * Due to race conditions present in the SCSI subsystem, it is easier
2632 * to queue completed commands, then call scsi_done() on them when
2633 * we're finished. This function queues the completed commands.
2634 *-F*************************************************************************/
2635 static void
2636 aic7xxx_queue_cmd_complete(struct aic7xxx_host *p, Scsi_Cmnd *cmd)
2638 aic7xxx_position(cmd) = SCB_LIST_NULL;
2639 cmd->host_scribble = (char *)p->completeq.head;
2640 p->completeq.head = cmd;
2643 /*+F*************************************************************************
2644 * Function:
2645 * aic7xxx_done_cmds_complete
2647 * Description:
2648 * Process the completed command queue.
2649 *-F*************************************************************************/
2650 static void
2651 aic7xxx_done_cmds_complete(struct aic7xxx_host *p)
2653 Scsi_Cmnd *cmd;
2655 while (p->completeq.head != NULL)
2657 cmd = p->completeq.head;
2658 p->completeq.head = (Scsi_Cmnd *)cmd->host_scribble;
2659 cmd->host_scribble = NULL;
2660 cmd->scsi_done(cmd);
2664 /*+F*************************************************************************
2665 * Function:
2666 * aic7xxx_free_scb
2668 * Description:
2669 * Free the scb and insert into the free scb list.
2670 *-F*************************************************************************/
2671 static void
2672 aic7xxx_free_scb(struct aic7xxx_host *p, struct aic7xxx_scb *scb)
2675 scb->flags = SCB_FREE;
2676 scb->cmd = NULL;
2677 scb->sg_count = 0;
2678 scb->sg_length = 0;
2679 scb->tag_action = 0;
2680 scb->hscb->control = 0;
2681 scb->hscb->target_status = 0;
2682 scb->hscb->target_channel_lun = SCB_LIST_NULL;
2684 scbq_insert_head(&p->scb_data->free_scbs, scb);
2687 /*+F*************************************************************************
2688 * Function:
2689 * aic7xxx_done
2691 * Description:
2692 * Calls the higher level scsi done function and frees the scb.
2693 *-F*************************************************************************/
2694 static void
2695 aic7xxx_done(struct aic7xxx_host *p, struct aic7xxx_scb *scb)
2697 Scsi_Cmnd *cmd = scb->cmd;
2698 struct aic_dev_data *aic_dev = cmd->device->hostdata;
2699 int tindex = TARGET_INDEX(cmd);
2700 struct aic7xxx_scb *scbp;
2701 unsigned char queue_depth;
2703 if (cmd->use_sg > 1)
2705 struct scatterlist *sg;
2707 sg = (struct scatterlist *)cmd->request_buffer;
2708 pci_unmap_sg(p->pdev, sg, cmd->use_sg, scsi_to_pci_dma_dir(cmd->sc_data_direction));
2710 else if (cmd->request_bufflen)
2711 pci_unmap_single(p->pdev, aic7xxx_mapping(cmd),
2712 cmd->request_bufflen,
2713 scsi_to_pci_dma_dir(cmd->sc_data_direction));
2714 if (scb->flags & SCB_SENSE)
2716 pci_unmap_single(p->pdev,
2717 le32_to_cpu(scb->sg_list[0].address),
2718 sizeof(cmd->sense_buffer),
2719 PCI_DMA_FROMDEVICE);
2721 if (scb->flags & SCB_RECOVERY_SCB)
2723 p->flags &= ~AHC_ABORT_PENDING;
2725 if (scb->flags & (SCB_RESET|SCB_ABORT))
2727 cmd->result |= (DID_RESET << 16);
2730 if ((scb->flags & SCB_MSGOUT_BITS) != 0)
2732 unsigned short mask;
2733 int message_error = FALSE;
2735 mask = 0x01 << tindex;
2738 * Check to see if we get an invalid message or a message error
2739 * after failing to negotiate a wide or sync transfer message.
2741 if ((scb->flags & SCB_SENSE) &&
2742 ((scb->cmd->sense_buffer[12] == 0x43) || /* INVALID_MESSAGE */
2743 (scb->cmd->sense_buffer[12] == 0x49))) /* MESSAGE_ERROR */
2745 message_error = TRUE;
2748 if (scb->flags & SCB_MSGOUT_WDTR)
2750 if (message_error)
2752 if ( (aic7xxx_verbose & VERBOSE_NEGOTIATION2) &&
2753 (aic_dev->flags & DEVICE_PRINT_DTR) )
2755 printk(INFO_LEAD "Device failed to complete Wide Negotiation "
2756 "processing and\n", p->host_no, CTL_OF_SCB(scb));
2757 printk(INFO_LEAD "returned a sense error code for invalid message, "
2758 "disabling future\n", p->host_no, CTL_OF_SCB(scb));
2759 printk(INFO_LEAD "Wide negotiation to this device.\n", p->host_no,
2760 CTL_OF_SCB(scb));
2762 aic_dev->needwdtr = aic_dev->needwdtr_copy = 0;
2765 if (scb->flags & SCB_MSGOUT_SDTR)
2767 if (message_error)
2769 if ( (aic7xxx_verbose & VERBOSE_NEGOTIATION2) &&
2770 (aic_dev->flags & DEVICE_PRINT_DTR) )
2772 printk(INFO_LEAD "Device failed to complete Sync Negotiation "
2773 "processing and\n", p->host_no, CTL_OF_SCB(scb));
2774 printk(INFO_LEAD "returned a sense error code for invalid message, "
2775 "disabling future\n", p->host_no, CTL_OF_SCB(scb));
2776 printk(INFO_LEAD "Sync negotiation to this device.\n", p->host_no,
2777 CTL_OF_SCB(scb));
2778 aic_dev->flags &= ~DEVICE_PRINT_DTR;
2780 aic_dev->needsdtr = aic_dev->needsdtr_copy = 0;
2783 if (scb->flags & SCB_MSGOUT_PPR)
2785 if(message_error)
2787 if ( (aic7xxx_verbose & VERBOSE_NEGOTIATION2) &&
2788 (aic_dev->flags & DEVICE_PRINT_DTR) )
2790 printk(INFO_LEAD "Device failed to complete Parallel Protocol "
2791 "Request processing and\n", p->host_no, CTL_OF_SCB(scb));
2792 printk(INFO_LEAD "returned a sense error code for invalid message, "
2793 "disabling future\n", p->host_no, CTL_OF_SCB(scb));
2794 printk(INFO_LEAD "Parallel Protocol Request negotiation to this "
2795 "device.\n", p->host_no, CTL_OF_SCB(scb));
2798 * Disable PPR negotiation and revert back to WDTR and SDTR setup
2800 aic_dev->needppr = aic_dev->needppr_copy = 0;
2801 aic_dev->needsdtr = aic_dev->needsdtr_copy = 1;
2802 aic_dev->needwdtr = aic_dev->needwdtr_copy = 1;
2807 queue_depth = aic_dev->temp_q_depth;
2808 if (queue_depth >= aic_dev->active_cmds)
2810 scbp = scbq_remove_head(&aic_dev->delayed_scbs);
2811 if (scbp)
2813 if (queue_depth == 1)
2816 * Give extra preference to untagged devices, such as CD-R devices
2817 * This makes it more likely that a drive *won't* stuff up while
2818 * waiting on data at a critical time, such as CD-R writing and
2819 * audio CD ripping operations. Should also benefit tape drives.
2821 scbq_insert_head(&p->waiting_scbs, scbp);
2823 else
2825 scbq_insert_tail(&p->waiting_scbs, scbp);
2827 #ifdef AIC7XXX_VERBOSE_DEBUGGING
2828 if (aic7xxx_verbose > 0xffff)
2829 printk(INFO_LEAD "Moving SCB from delayed to waiting queue.\n",
2830 p->host_no, CTL_OF_SCB(scbp));
2831 #endif
2832 if (queue_depth > aic_dev->active_cmds)
2834 scbp = scbq_remove_head(&aic_dev->delayed_scbs);
2835 if (scbp)
2836 scbq_insert_tail(&p->waiting_scbs, scbp);
2840 if (!(scb->tag_action))
2842 aic7xxx_index_busy_target(p, scb->hscb->target_channel_lun,
2843 /* unbusy */ TRUE);
2844 if (cmd->device->simple_tags)
2846 aic_dev->temp_q_depth = aic_dev->max_q_depth;
2849 if(scb->flags & SCB_DTR_SCB)
2851 aic_dev->dtr_pending = 0;
2853 aic_dev->active_cmds--;
2854 p->activescbs--;
2856 if ((scb->sg_length >= 512) && (((cmd->result >> 16) & 0xf) == DID_OK))
2858 long *ptr;
2859 int x, i;
2862 if (rq_data_dir(cmd->request) == WRITE)
2864 aic_dev->w_total++;
2865 ptr = aic_dev->w_bins;
2867 else
2869 aic_dev->r_total++;
2870 ptr = aic_dev->r_bins;
2872 if(cmd->device->simple_tags && cmd->request->flags & REQ_HARDBARRIER)
2874 aic_dev->barrier_total++;
2875 if(scb->tag_action == MSG_ORDERED_Q_TAG)
2876 aic_dev->ordered_total++;
2878 x = scb->sg_length;
2879 x >>= 10;
2880 for(i=0; i<6; i++)
2882 x >>= 2;
2883 if(!x) {
2884 ptr[i]++;
2885 break;
2888 if(i == 6 && x)
2889 ptr[5]++;
2891 aic7xxx_free_scb(p, scb);
2892 aic7xxx_queue_cmd_complete(p, cmd);
2896 /*+F*************************************************************************
2897 * Function:
2898 * aic7xxx_run_done_queue
2900 * Description:
2901 * Calls the aic7xxx_done() for the Scsi_Cmnd of each scb in the
2902 * aborted list, and adds each scb to the free list. If complete
2903 * is TRUE, we also process the commands complete list.
2904 *-F*************************************************************************/
2905 static void
2906 aic7xxx_run_done_queue(struct aic7xxx_host *p, /*complete*/ int complete)
2908 struct aic7xxx_scb *scb;
2909 int i, found = 0;
2911 for (i = 0; i < p->scb_data->numscbs; i++)
2913 scb = p->scb_data->scb_array[i];
2914 if (scb->flags & SCB_QUEUED_FOR_DONE)
2916 if (scb->flags & SCB_QUEUE_FULL)
2918 scb->cmd->result = QUEUE_FULL << 1;
2920 else
2922 if (aic7xxx_verbose & (VERBOSE_ABORT_PROCESS | VERBOSE_RESET_PROCESS))
2923 printk(INFO_LEAD "Aborting scb %d\n",
2924 p->host_no, CTL_OF_SCB(scb), scb->hscb->tag);
2926 * Clear any residual information since the normal aic7xxx_done() path
2927 * doesn't touch the residuals.
2929 scb->hscb->residual_SG_segment_count = 0;
2930 scb->hscb->residual_data_count[0] = 0;
2931 scb->hscb->residual_data_count[1] = 0;
2932 scb->hscb->residual_data_count[2] = 0;
2934 found++;
2935 aic7xxx_done(p, scb);
2938 if (aic7xxx_verbose & (VERBOSE_ABORT_RETURN | VERBOSE_RESET_RETURN))
2940 printk(INFO_LEAD "%d commands found and queued for "
2941 "completion.\n", p->host_no, -1, -1, -1, found);
2943 if (complete)
2945 aic7xxx_done_cmds_complete(p);
2949 /*+F*************************************************************************
2950 * Function:
2951 * aic7xxx_abort_waiting_scb
2953 * Description:
2954 * Manipulate the waiting for selection list and return the
2955 * scb that follows the one that we remove.
2956 *-F*************************************************************************/
2957 static unsigned char
2958 aic7xxx_abort_waiting_scb(struct aic7xxx_host *p, struct aic7xxx_scb *scb,
2959 unsigned char scbpos, unsigned char prev)
2961 unsigned char curscb, next;
2964 * Select the SCB we want to abort and pull the next pointer out of it.
2966 curscb = aic_inb(p, SCBPTR);
2967 aic_outb(p, scbpos, SCBPTR);
2968 next = aic_inb(p, SCB_NEXT);
2970 aic7xxx_add_curscb_to_free_list(p);
2973 * Update the waiting list
2975 if (prev == SCB_LIST_NULL)
2978 * First in the list
2980 aic_outb(p, next, WAITING_SCBH);
2982 else
2985 * Select the scb that pointed to us and update its next pointer.
2987 aic_outb(p, prev, SCBPTR);
2988 aic_outb(p, next, SCB_NEXT);
2991 * Point us back at the original scb position and inform the SCSI
2992 * system that the command has been aborted.
2994 aic_outb(p, curscb, SCBPTR);
2995 return (next);
2998 /*+F*************************************************************************
2999 * Function:
3000 * aic7xxx_search_qinfifo
3002 * Description:
3003 * Search the queue-in FIFO for matching SCBs and conditionally
3004 * requeue. Returns the number of matching SCBs.
3005 *-F*************************************************************************/
3006 static int
3007 aic7xxx_search_qinfifo(struct aic7xxx_host *p, int target, int channel,
3008 int lun, unsigned char tag, int flags, int requeue,
3009 volatile scb_queue_type *queue)
3011 int found;
3012 unsigned char qinpos, qintail;
3013 struct aic7xxx_scb *scbp;
3015 found = 0;
3016 qinpos = aic_inb(p, QINPOS);
3017 qintail = p->qinfifonext;
3019 p->qinfifonext = qinpos;
3021 while (qinpos != qintail)
3023 scbp = p->scb_data->scb_array[p->qinfifo[qinpos++]];
3024 if (aic7xxx_match_scb(p, scbp, target, channel, lun, tag))
3027 * We found an scb that needs to be removed.
3029 if (requeue && (queue != NULL))
3031 if (scbp->flags & SCB_WAITINGQ)
3033 scbq_remove(queue, scbp);
3034 scbq_remove(&p->waiting_scbs, scbp);
3035 scbq_remove(&AIC_DEV(scbp->cmd)->delayed_scbs, scbp);
3036 AIC_DEV(scbp->cmd)->active_cmds++;
3037 p->activescbs++;
3039 scbq_insert_tail(queue, scbp);
3040 AIC_DEV(scbp->cmd)->active_cmds--;
3041 p->activescbs--;
3042 scbp->flags |= SCB_WAITINGQ;
3043 if ( !(scbp->tag_action & TAG_ENB) )
3045 aic7xxx_index_busy_target(p, scbp->hscb->target_channel_lun,
3046 TRUE);
3049 else if (requeue)
3051 p->qinfifo[p->qinfifonext++] = scbp->hscb->tag;
3053 else
3056 * Preserve any SCB_RECOVERY_SCB flags on this scb then set the
3057 * flags we were called with, presumeably so aic7xxx_run_done_queue
3058 * can find this scb
3060 scbp->flags = flags | (scbp->flags & SCB_RECOVERY_SCB);
3061 if (aic7xxx_index_busy_target(p, scbp->hscb->target_channel_lun,
3062 FALSE) == scbp->hscb->tag)
3064 aic7xxx_index_busy_target(p, scbp->hscb->target_channel_lun,
3065 TRUE);
3068 found++;
3070 else
3072 p->qinfifo[p->qinfifonext++] = scbp->hscb->tag;
3076 * Now that we've done the work, clear out any left over commands in the
3077 * qinfifo and update the KERNEL_QINPOS down on the card.
3079 * NOTE: This routine expect the sequencer to already be paused when
3080 * it is run....make sure it's that way!
3082 qinpos = p->qinfifonext;
3083 while(qinpos != qintail)
3085 p->qinfifo[qinpos++] = SCB_LIST_NULL;
3087 if (p->features & AHC_QUEUE_REGS)
3088 aic_outb(p, p->qinfifonext, HNSCB_QOFF);
3089 else
3090 aic_outb(p, p->qinfifonext, KERNEL_QINPOS);
3092 return (found);
3095 /*+F*************************************************************************
3096 * Function:
3097 * aic7xxx_scb_on_qoutfifo
3099 * Description:
3100 * Is the scb that was passed to us currently on the qoutfifo?
3101 *-F*************************************************************************/
3102 static int
3103 aic7xxx_scb_on_qoutfifo(struct aic7xxx_host *p, struct aic7xxx_scb *scb)
3105 int i=0;
3107 while(p->qoutfifo[(p->qoutfifonext + i) & 0xff ] != SCB_LIST_NULL)
3109 if(p->qoutfifo[(p->qoutfifonext + i) & 0xff ] == scb->hscb->tag)
3110 return TRUE;
3111 else
3112 i++;
3114 return FALSE;
3118 /*+F*************************************************************************
3119 * Function:
3120 * aic7xxx_reset_device
3122 * Description:
3123 * The device at the given target/channel has been reset. Abort
3124 * all active and queued scbs for that target/channel. This function
3125 * need not worry about linked next pointers because if was a MSG_ABORT_TAG
3126 * then we had a tagged command (no linked next), if it was MSG_ABORT or
3127 * MSG_BUS_DEV_RESET then the device won't know about any commands any more
3128 * and no busy commands will exist, and if it was a bus reset, then nothing
3129 * knows about any linked next commands any more. In all cases, we don't
3130 * need to worry about the linked next or busy scb, we just need to clear
3131 * them.
3132 *-F*************************************************************************/
3133 static void
3134 aic7xxx_reset_device(struct aic7xxx_host *p, int target, int channel,
3135 int lun, unsigned char tag)
3137 struct aic7xxx_scb *scbp, *prev_scbp;
3138 struct scsi_device *sd;
3139 unsigned char active_scb, tcl, scb_tag;
3140 int i = 0, init_lists = FALSE;
3141 struct aic_dev_data *aic_dev;
3144 * Restore this when we're done
3146 active_scb = aic_inb(p, SCBPTR);
3147 scb_tag = aic_inb(p, SCB_TAG);
3149 if (aic7xxx_verbose & (VERBOSE_RESET_PROCESS | VERBOSE_ABORT_PROCESS))
3151 printk(INFO_LEAD "Reset device, hardware_scb %d,\n",
3152 p->host_no, channel, target, lun, active_scb);
3153 printk(INFO_LEAD "Current scb %d, SEQADDR 0x%x, LASTPHASE "
3154 "0x%x\n",
3155 p->host_no, channel, target, lun, scb_tag,
3156 aic_inb(p, SEQADDR0) | (aic_inb(p, SEQADDR1) << 8),
3157 aic_inb(p, LASTPHASE));
3158 printk(INFO_LEAD "SG_CACHEPTR 0x%x, SG_COUNT %d, SCSISIGI 0x%x\n",
3159 p->host_no, channel, target, lun,
3160 (p->features & AHC_ULTRA2) ? aic_inb(p, SG_CACHEPTR) : 0,
3161 aic_inb(p, SG_COUNT), aic_inb(p, SCSISIGI));
3162 printk(INFO_LEAD "SSTAT0 0x%x, SSTAT1 0x%x, SSTAT2 0x%x\n",
3163 p->host_no, channel, target, lun, aic_inb(p, SSTAT0),
3164 aic_inb(p, SSTAT1), aic_inb(p, SSTAT2));
3168 * Deal with the busy target and linked next issues.
3170 list_for_each_entry(aic_dev, &p->aic_devs, list)
3172 if (aic7xxx_verbose & (VERBOSE_RESET_PROCESS | VERBOSE_ABORT_PROCESS))
3173 printk(INFO_LEAD "processing aic_dev %p\n", p->host_no, channel, target,
3174 lun, aic_dev);
3175 sd = aic_dev->SDptr;
3177 if((target != ALL_TARGETS && target != sd->id) ||
3178 (channel != ALL_CHANNELS && channel != sd->channel))
3179 continue;
3180 if (aic7xxx_verbose & (VERBOSE_ABORT_PROCESS | VERBOSE_RESET_PROCESS))
3181 printk(INFO_LEAD "Cleaning up status information "
3182 "and delayed_scbs.\n", p->host_no, sd->channel, sd->id, sd->lun);
3183 aic_dev->flags &= ~BUS_DEVICE_RESET_PENDING;
3184 if ( tag == SCB_LIST_NULL )
3186 aic_dev->dtr_pending = 0;
3187 aic_dev->needppr = aic_dev->needppr_copy;
3188 aic_dev->needsdtr = aic_dev->needsdtr_copy;
3189 aic_dev->needwdtr = aic_dev->needwdtr_copy;
3190 aic_dev->flags = DEVICE_PRINT_DTR;
3191 aic_dev->temp_q_depth = aic_dev->max_q_depth;
3193 tcl = (sd->id << 4) | (sd->channel << 3) | sd->lun;
3194 if ( (aic7xxx_index_busy_target(p, tcl, FALSE) == tag) ||
3195 (tag == SCB_LIST_NULL) )
3196 aic7xxx_index_busy_target(p, tcl, /* unbusy */ TRUE);
3197 prev_scbp = NULL;
3198 scbp = aic_dev->delayed_scbs.head;
3199 while (scbp != NULL)
3201 prev_scbp = scbp;
3202 scbp = scbp->q_next;
3203 if (aic7xxx_match_scb(p, prev_scbp, target, channel, lun, tag))
3205 scbq_remove(&aic_dev->delayed_scbs, prev_scbp);
3206 if (prev_scbp->flags & SCB_WAITINGQ)
3208 aic_dev->active_cmds++;
3209 p->activescbs++;
3211 prev_scbp->flags &= ~(SCB_ACTIVE | SCB_WAITINGQ);
3212 prev_scbp->flags |= SCB_RESET | SCB_QUEUED_FOR_DONE;
3217 if (aic7xxx_verbose & (VERBOSE_ABORT_PROCESS | VERBOSE_RESET_PROCESS))
3218 printk(INFO_LEAD "Cleaning QINFIFO.\n", p->host_no, channel, target, lun );
3219 aic7xxx_search_qinfifo(p, target, channel, lun, tag,
3220 SCB_RESET | SCB_QUEUED_FOR_DONE, /* requeue */ FALSE, NULL);
3223 * Search the waiting_scbs queue for matches, this catches any SCB_QUEUED
3224 * ABORT/RESET commands.
3226 if (aic7xxx_verbose & (VERBOSE_ABORT_PROCESS | VERBOSE_RESET_PROCESS))
3227 printk(INFO_LEAD "Cleaning waiting_scbs.\n", p->host_no, channel,
3228 target, lun );
3230 struct aic7xxx_scb *scbp, *prev_scbp;
3232 prev_scbp = NULL;
3233 scbp = p->waiting_scbs.head;
3234 while (scbp != NULL)
3236 prev_scbp = scbp;
3237 scbp = scbp->q_next;
3238 if (aic7xxx_match_scb(p, prev_scbp, target, channel, lun, tag))
3240 scbq_remove(&p->waiting_scbs, prev_scbp);
3241 if (prev_scbp->flags & SCB_WAITINGQ)
3243 AIC_DEV(prev_scbp->cmd)->active_cmds++;
3244 p->activescbs++;
3246 prev_scbp->flags &= ~(SCB_ACTIVE | SCB_WAITINGQ);
3247 prev_scbp->flags |= SCB_RESET | SCB_QUEUED_FOR_DONE;
3254 * Search waiting for selection list.
3256 if (aic7xxx_verbose & (VERBOSE_ABORT_PROCESS | VERBOSE_RESET_PROCESS))
3257 printk(INFO_LEAD "Cleaning waiting for selection "
3258 "list.\n", p->host_no, channel, target, lun);
3260 unsigned char next, prev, scb_index;
3262 next = aic_inb(p, WAITING_SCBH); /* Start at head of list. */
3263 prev = SCB_LIST_NULL;
3264 while (next != SCB_LIST_NULL)
3266 aic_outb(p, next, SCBPTR);
3267 scb_index = aic_inb(p, SCB_TAG);
3268 if (scb_index >= p->scb_data->numscbs)
3271 * No aic7xxx_verbose check here.....we want to see this since it
3272 * means either the kernel driver or the sequencer screwed things up
3274 printk(WARN_LEAD "Waiting List inconsistency; SCB index=%d, "
3275 "numscbs=%d\n", p->host_no, channel, target, lun, scb_index,
3276 p->scb_data->numscbs);
3277 next = aic_inb(p, SCB_NEXT);
3278 aic7xxx_add_curscb_to_free_list(p);
3280 else
3282 scbp = p->scb_data->scb_array[scb_index];
3283 if (aic7xxx_match_scb(p, scbp, target, channel, lun, tag))
3285 next = aic7xxx_abort_waiting_scb(p, scbp, next, prev);
3286 if (scbp->flags & SCB_WAITINGQ)
3288 AIC_DEV(scbp->cmd)->active_cmds++;
3289 p->activescbs++;
3291 scbp->flags &= ~(SCB_ACTIVE | SCB_WAITINGQ);
3292 scbp->flags |= SCB_RESET | SCB_QUEUED_FOR_DONE;
3293 if (prev == SCB_LIST_NULL)
3296 * This is either the first scb on the waiting list, or we
3297 * have already yanked the first and haven't left any behind.
3298 * Either way, we need to turn off the selection hardware if
3299 * it isn't already off.
3301 aic_outb(p, aic_inb(p, SCSISEQ) & ~ENSELO, SCSISEQ);
3302 aic_outb(p, CLRSELTIMEO, CLRSINT1);
3305 else
3307 prev = next;
3308 next = aic_inb(p, SCB_NEXT);
3315 * Go through disconnected list and remove any entries we have queued
3316 * for completion, zeroing their control byte too.
3318 if (aic7xxx_verbose & (VERBOSE_ABORT_PROCESS | VERBOSE_RESET_PROCESS))
3319 printk(INFO_LEAD "Cleaning disconnected scbs "
3320 "list.\n", p->host_no, channel, target, lun);
3321 if (p->flags & AHC_PAGESCBS)
3323 unsigned char next, prev, scb_index;
3325 next = aic_inb(p, DISCONNECTED_SCBH);
3326 prev = SCB_LIST_NULL;
3327 while (next != SCB_LIST_NULL)
3329 aic_outb(p, next, SCBPTR);
3330 scb_index = aic_inb(p, SCB_TAG);
3331 if (scb_index > p->scb_data->numscbs)
3333 printk(WARN_LEAD "Disconnected List inconsistency; SCB index=%d, "
3334 "numscbs=%d\n", p->host_no, channel, target, lun, scb_index,
3335 p->scb_data->numscbs);
3336 next = aic7xxx_rem_scb_from_disc_list(p, next, prev);
3338 else
3340 scbp = p->scb_data->scb_array[scb_index];
3341 if (aic7xxx_match_scb(p, scbp, target, channel, lun, tag))
3343 next = aic7xxx_rem_scb_from_disc_list(p, next, prev);
3344 if (scbp->flags & SCB_WAITINGQ)
3346 AIC_DEV(scbp->cmd)->active_cmds++;
3347 p->activescbs++;
3349 scbp->flags &= ~(SCB_ACTIVE | SCB_WAITINGQ);
3350 scbp->flags |= SCB_RESET | SCB_QUEUED_FOR_DONE;
3351 scbp->hscb->control = 0;
3353 else
3355 prev = next;
3356 next = aic_inb(p, SCB_NEXT);
3363 * Walk the free list making sure no entries on the free list have
3364 * a valid SCB_TAG value or SCB_CONTROL byte.
3366 if (p->flags & AHC_PAGESCBS)
3368 unsigned char next;
3370 next = aic_inb(p, FREE_SCBH);
3371 while (next != SCB_LIST_NULL)
3373 aic_outb(p, next, SCBPTR);
3374 if (aic_inb(p, SCB_TAG) < p->scb_data->numscbs)
3376 printk(WARN_LEAD "Free list inconsistency!.\n", p->host_no, channel,
3377 target, lun);
3378 init_lists = TRUE;
3379 next = SCB_LIST_NULL;
3381 else
3383 aic_outb(p, SCB_LIST_NULL, SCB_TAG);
3384 aic_outb(p, 0, SCB_CONTROL);
3385 next = aic_inb(p, SCB_NEXT);
3391 * Go through the hardware SCB array looking for commands that
3392 * were active but not on any list.
3394 if (init_lists)
3396 aic_outb(p, SCB_LIST_NULL, FREE_SCBH);
3397 aic_outb(p, SCB_LIST_NULL, WAITING_SCBH);
3398 aic_outb(p, SCB_LIST_NULL, DISCONNECTED_SCBH);
3400 for (i = p->scb_data->maxhscbs - 1; i >= 0; i--)
3402 unsigned char scbid;
3404 aic_outb(p, i, SCBPTR);
3405 if (init_lists)
3407 aic_outb(p, SCB_LIST_NULL, SCB_TAG);
3408 aic_outb(p, SCB_LIST_NULL, SCB_NEXT);
3409 aic_outb(p, 0, SCB_CONTROL);
3410 aic7xxx_add_curscb_to_free_list(p);
3412 else
3414 scbid = aic_inb(p, SCB_TAG);
3415 if (scbid < p->scb_data->numscbs)
3417 scbp = p->scb_data->scb_array[scbid];
3418 if (aic7xxx_match_scb(p, scbp, target, channel, lun, tag))
3420 aic_outb(p, 0, SCB_CONTROL);
3421 aic_outb(p, SCB_LIST_NULL, SCB_TAG);
3422 aic7xxx_add_curscb_to_free_list(p);
3429 * Go through the entire SCB array now and look for commands for
3430 * for this target that are stillactive. These are other (most likely
3431 * tagged) commands that were disconnected when the reset occurred.
3432 * Any commands we find here we know this about, it wasn't on any queue,
3433 * it wasn't in the qinfifo, it wasn't in the disconnected or waiting
3434 * lists, so it really must have been a paged out SCB. In that case,
3435 * we shouldn't need to bother with updating any counters, just mark
3436 * the correct flags and go on.
3438 for (i = 0; i < p->scb_data->numscbs; i++)
3440 scbp = p->scb_data->scb_array[i];
3441 if ((scbp->flags & SCB_ACTIVE) &&
3442 aic7xxx_match_scb(p, scbp, target, channel, lun, tag) &&
3443 !aic7xxx_scb_on_qoutfifo(p, scbp))
3445 if (scbp->flags & SCB_WAITINGQ)
3447 scbq_remove(&p->waiting_scbs, scbp);
3448 scbq_remove(&AIC_DEV(scbp->cmd)->delayed_scbs, scbp);
3449 AIC_DEV(scbp->cmd)->active_cmds++;
3450 p->activescbs++;
3452 scbp->flags |= SCB_RESET | SCB_QUEUED_FOR_DONE;
3453 scbp->flags &= ~(SCB_ACTIVE | SCB_WAITINGQ);
3457 aic_outb(p, active_scb, SCBPTR);
3461 /*+F*************************************************************************
3462 * Function:
3463 * aic7xxx_clear_intstat
3465 * Description:
3466 * Clears the interrupt status.
3467 *-F*************************************************************************/
3468 static void
3469 aic7xxx_clear_intstat(struct aic7xxx_host *p)
3471 /* Clear any interrupt conditions this may have caused. */
3472 aic_outb(p, CLRSELDO | CLRSELDI | CLRSELINGO, CLRSINT0);
3473 aic_outb(p, CLRSELTIMEO | CLRATNO | CLRSCSIRSTI | CLRBUSFREE | CLRSCSIPERR |
3474 CLRPHASECHG | CLRREQINIT, CLRSINT1);
3475 aic_outb(p, CLRSCSIINT | CLRSEQINT | CLRBRKADRINT | CLRPARERR, CLRINT);
3478 /*+F*************************************************************************
3479 * Function:
3480 * aic7xxx_reset_current_bus
3482 * Description:
3483 * Reset the current SCSI bus.
3484 *-F*************************************************************************/
3485 static void
3486 aic7xxx_reset_current_bus(struct aic7xxx_host *p)
3489 /* Disable reset interrupts. */
3490 aic_outb(p, aic_inb(p, SIMODE1) & ~ENSCSIRST, SIMODE1);
3492 /* Turn off the bus' current operations, after all, we shouldn't have any
3493 * valid commands left to cause a RSELI and SELO once we've tossed the
3494 * bus away with this reset, so we might as well shut down the sequencer
3495 * until the bus is restarted as oppossed to saving the current settings
3496 * and restoring them (which makes no sense to me). */
3498 /* Turn on the bus reset. */
3499 aic_outb(p, aic_inb(p, SCSISEQ) | SCSIRSTO, SCSISEQ);
3500 while ( (aic_inb(p, SCSISEQ) & SCSIRSTO) == 0)
3501 mdelay(5);
3504 * Some of the new Ultra2 chipsets need a longer delay after a chip
3505 * reset than just the init setup creates, so we have to delay here
3506 * before we go into a reset in order to make the chips happy.
3508 if (p->features & AHC_ULTRA2)
3509 mdelay(250);
3510 else
3511 mdelay(50);
3513 /* Turn off the bus reset. */
3514 aic_outb(p, 0, SCSISEQ);
3515 mdelay(10);
3517 aic7xxx_clear_intstat(p);
3518 /* Re-enable reset interrupts. */
3519 aic_outb(p, aic_inb(p, SIMODE1) | ENSCSIRST, SIMODE1);
3523 /*+F*************************************************************************
3524 * Function:
3525 * aic7xxx_reset_channel
3527 * Description:
3528 * Reset the channel.
3529 *-F*************************************************************************/
3530 static void
3531 aic7xxx_reset_channel(struct aic7xxx_host *p, int channel, int initiate_reset)
3533 unsigned long offset_min, offset_max;
3534 unsigned char sblkctl;
3535 int cur_channel;
3537 if (aic7xxx_verbose & VERBOSE_RESET_PROCESS)
3538 printk(INFO_LEAD "Reset channel called, %s initiate reset.\n",
3539 p->host_no, channel, -1, -1, (initiate_reset==TRUE) ? "will" : "won't" );
3542 if (channel == 1)
3544 offset_min = 8;
3545 offset_max = 16;
3547 else
3549 if (p->features & AHC_TWIN)
3551 /* Channel A */
3552 offset_min = 0;
3553 offset_max = 8;
3555 else
3557 offset_min = 0;
3558 if (p->features & AHC_WIDE)
3560 offset_max = 16;
3562 else
3564 offset_max = 8;
3569 while (offset_min < offset_max)
3572 * Revert to async/narrow transfers until we renegotiate.
3574 aic_outb(p, 0, TARG_SCSIRATE + offset_min);
3575 if (p->features & AHC_ULTRA2)
3577 aic_outb(p, 0, TARG_OFFSET + offset_min);
3579 offset_min++;
3583 * Reset the bus and unpause/restart the controller
3585 sblkctl = aic_inb(p, SBLKCTL);
3586 if ( (p->chip & AHC_CHIPID_MASK) == AHC_AIC7770 )
3587 cur_channel = (sblkctl & SELBUSB) >> 3;
3588 else
3589 cur_channel = 0;
3590 if ( (cur_channel != channel) && (p->features & AHC_TWIN) )
3593 * Case 1: Command for another bus is active
3595 if (aic7xxx_verbose & VERBOSE_RESET_PROCESS)
3596 printk(INFO_LEAD "Stealthily resetting idle channel.\n", p->host_no,
3597 channel, -1, -1);
3599 * Stealthily reset the other bus without upsetting the current bus.
3601 aic_outb(p, sblkctl ^ SELBUSB, SBLKCTL);
3602 aic_outb(p, aic_inb(p, SIMODE1) & ~ENBUSFREE, SIMODE1);
3603 if (initiate_reset)
3605 aic7xxx_reset_current_bus(p);
3607 aic_outb(p, aic_inb(p, SCSISEQ) & (ENSELI|ENRSELI|ENAUTOATNP), SCSISEQ);
3608 aic7xxx_clear_intstat(p);
3609 aic_outb(p, sblkctl, SBLKCTL);
3611 else
3614 * Case 2: A command from this bus is active or we're idle.
3616 if (aic7xxx_verbose & VERBOSE_RESET_PROCESS)
3617 printk(INFO_LEAD "Resetting currently active channel.\n", p->host_no,
3618 channel, -1, -1);
3619 aic_outb(p, aic_inb(p, SIMODE1) & ~(ENBUSFREE|ENREQINIT),
3620 SIMODE1);
3621 p->flags &= ~AHC_HANDLING_REQINITS;
3622 p->msg_type = MSG_TYPE_NONE;
3623 p->msg_len = 0;
3624 if (initiate_reset)
3626 aic7xxx_reset_current_bus(p);
3628 aic_outb(p, aic_inb(p, SCSISEQ) & (ENSELI|ENRSELI|ENAUTOATNP), SCSISEQ);
3629 aic7xxx_clear_intstat(p);
3631 if (aic7xxx_verbose & VERBOSE_RESET_RETURN)
3632 printk(INFO_LEAD "Channel reset\n", p->host_no, channel, -1, -1);
3634 * Clean up all the state information for the pending transactions
3635 * on this bus.
3637 aic7xxx_reset_device(p, ALL_TARGETS, channel, ALL_LUNS, SCB_LIST_NULL);
3639 if ( !(p->features & AHC_TWIN) )
3641 restart_sequencer(p);
3644 return;
3647 /*+F*************************************************************************
3648 * Function:
3649 * aic7xxx_run_waiting_queues
3651 * Description:
3652 * Scan the awaiting_scbs queue downloading and starting as many
3653 * scbs as we can.
3654 *-F*************************************************************************/
3655 static void
3656 aic7xxx_run_waiting_queues(struct aic7xxx_host *p)
3658 struct aic7xxx_scb *scb;
3659 struct aic_dev_data *aic_dev;
3660 int sent;
3663 if (p->waiting_scbs.head == NULL)
3664 return;
3666 sent = 0;
3669 * First handle SCBs that are waiting but have been assigned a slot.
3671 while ((scb = scbq_remove_head(&p->waiting_scbs)) != NULL)
3673 aic_dev = scb->cmd->device->hostdata;
3674 if ( !scb->tag_action )
3676 aic_dev->temp_q_depth = 1;
3678 if ( aic_dev->active_cmds >= aic_dev->temp_q_depth)
3680 scbq_insert_tail(&aic_dev->delayed_scbs, scb);
3682 else
3684 scb->flags &= ~SCB_WAITINGQ;
3685 aic_dev->active_cmds++;
3686 p->activescbs++;
3687 if ( !(scb->tag_action) )
3689 aic7xxx_busy_target(p, scb);
3691 p->qinfifo[p->qinfifonext++] = scb->hscb->tag;
3692 sent++;
3695 if (sent)
3697 if (p->features & AHC_QUEUE_REGS)
3698 aic_outb(p, p->qinfifonext, HNSCB_QOFF);
3699 else
3701 pause_sequencer(p);
3702 aic_outb(p, p->qinfifonext, KERNEL_QINPOS);
3703 unpause_sequencer(p, FALSE);
3705 if (p->activescbs > p->max_activescbs)
3706 p->max_activescbs = p->activescbs;
3710 #ifdef CONFIG_PCI
3712 #define DPE 0x80
3713 #define SSE 0x40
3714 #define RMA 0x20
3715 #define RTA 0x10
3716 #define STA 0x08
3717 #define DPR 0x01
3719 /*+F*************************************************************************
3720 * Function:
3721 * aic7xxx_pci_intr
3723 * Description:
3724 * Check the scsi card for PCI errors and clear the interrupt
3726 * NOTE: If you don't have this function and a 2940 card encounters
3727 * a PCI error condition, the machine will end up locked as the
3728 * interrupt handler gets slammed with non-stop PCI error interrupts
3729 *-F*************************************************************************/
3730 static void
3731 aic7xxx_pci_intr(struct aic7xxx_host *p)
3733 unsigned char status1;
3735 pci_read_config_byte(p->pdev, PCI_STATUS + 1, &status1);
3737 if ( (status1 & DPE) && (aic7xxx_verbose & VERBOSE_MINOR_ERROR) )
3738 printk(WARN_LEAD "Data Parity Error during PCI address or PCI write"
3739 "phase.\n", p->host_no, -1, -1, -1);
3740 if ( (status1 & SSE) && (aic7xxx_verbose & VERBOSE_MINOR_ERROR) )
3741 printk(WARN_LEAD "Signal System Error Detected\n", p->host_no,
3742 -1, -1, -1);
3743 if ( (status1 & RMA) && (aic7xxx_verbose & VERBOSE_MINOR_ERROR) )
3744 printk(WARN_LEAD "Received a PCI Master Abort\n", p->host_no,
3745 -1, -1, -1);
3746 if ( (status1 & RTA) && (aic7xxx_verbose & VERBOSE_MINOR_ERROR) )
3747 printk(WARN_LEAD "Received a PCI Target Abort\n", p->host_no,
3748 -1, -1, -1);
3749 if ( (status1 & STA) && (aic7xxx_verbose & VERBOSE_MINOR_ERROR) )
3750 printk(WARN_LEAD "Signaled a PCI Target Abort\n", p->host_no,
3751 -1, -1, -1);
3752 if ( (status1 & DPR) && (aic7xxx_verbose & VERBOSE_MINOR_ERROR) )
3753 printk(WARN_LEAD "Data Parity Error has been reported via PCI pin "
3754 "PERR#\n", p->host_no, -1, -1, -1);
3756 pci_write_config_byte(p->pdev, PCI_STATUS + 1, status1);
3757 if (status1 & (DPR|RMA|RTA))
3758 aic_outb(p, CLRPARERR, CLRINT);
3760 if ( (aic7xxx_panic_on_abort) && (p->spurious_int > 500) )
3761 aic7xxx_panic_abort(p, NULL);
3764 #endif /* CONFIG_PCI */
3766 /*+F*************************************************************************
3767 * Function:
3768 * aic7xxx_construct_ppr
3770 * Description:
3771 * Build up a Parallel Protocol Request message for use with SCSI-3
3772 * devices.
3773 *-F*************************************************************************/
3774 static void
3775 aic7xxx_construct_ppr(struct aic7xxx_host *p, struct aic7xxx_scb *scb)
3777 p->msg_buf[p->msg_index++] = MSG_EXTENDED;
3778 p->msg_buf[p->msg_index++] = MSG_EXT_PPR_LEN;
3779 p->msg_buf[p->msg_index++] = MSG_EXT_PPR;
3780 p->msg_buf[p->msg_index++] = AIC_DEV(scb->cmd)->goal.period;
3781 p->msg_buf[p->msg_index++] = 0;
3782 p->msg_buf[p->msg_index++] = AIC_DEV(scb->cmd)->goal.offset;
3783 p->msg_buf[p->msg_index++] = AIC_DEV(scb->cmd)->goal.width;
3784 p->msg_buf[p->msg_index++] = AIC_DEV(scb->cmd)->goal.options;
3785 p->msg_len += 8;
3788 /*+F*************************************************************************
3789 * Function:
3790 * aic7xxx_construct_sdtr
3792 * Description:
3793 * Constucts a synchronous data transfer message in the message
3794 * buffer on the sequencer.
3795 *-F*************************************************************************/
3796 static void
3797 aic7xxx_construct_sdtr(struct aic7xxx_host *p, unsigned char period,
3798 unsigned char offset)
3800 p->msg_buf[p->msg_index++] = MSG_EXTENDED;
3801 p->msg_buf[p->msg_index++] = MSG_EXT_SDTR_LEN;
3802 p->msg_buf[p->msg_index++] = MSG_EXT_SDTR;
3803 p->msg_buf[p->msg_index++] = period;
3804 p->msg_buf[p->msg_index++] = offset;
3805 p->msg_len += 5;
3808 /*+F*************************************************************************
3809 * Function:
3810 * aic7xxx_construct_wdtr
3812 * Description:
3813 * Constucts a wide data transfer message in the message buffer
3814 * on the sequencer.
3815 *-F*************************************************************************/
3816 static void
3817 aic7xxx_construct_wdtr(struct aic7xxx_host *p, unsigned char bus_width)
3819 p->msg_buf[p->msg_index++] = MSG_EXTENDED;
3820 p->msg_buf[p->msg_index++] = MSG_EXT_WDTR_LEN;
3821 p->msg_buf[p->msg_index++] = MSG_EXT_WDTR;
3822 p->msg_buf[p->msg_index++] = bus_width;
3823 p->msg_len += 4;
3826 /*+F*************************************************************************
3827 * Function:
3828 * aic7xxx_calc_residual
3830 * Description:
3831 * Calculate the residual data not yet transferred.
3832 *-F*************************************************************************/
3833 static void
3834 aic7xxx_calculate_residual (struct aic7xxx_host *p, struct aic7xxx_scb *scb)
3836 struct aic7xxx_hwscb *hscb;
3837 Scsi_Cmnd *cmd;
3838 int actual, i;
3840 cmd = scb->cmd;
3841 hscb = scb->hscb;
3844 * Don't destroy valid residual information with
3845 * residual coming from a check sense operation.
3847 if (((scb->hscb->control & DISCONNECTED) == 0) &&
3848 (scb->flags & SCB_SENSE) == 0)
3851 * We had an underflow. At this time, there's only
3852 * one other driver that bothers to check for this,
3853 * and cmd->underflow seems to be set rather half-
3854 * heartedly in the higher-level SCSI code.
3856 actual = scb->sg_length;
3857 for (i=1; i < hscb->residual_SG_segment_count; i++)
3859 actual -= scb->sg_list[scb->sg_count - i].length;
3861 actual -= (hscb->residual_data_count[2] << 16) |
3862 (hscb->residual_data_count[1] << 8) |
3863 hscb->residual_data_count[0];
3865 if (actual < cmd->underflow)
3867 if (aic7xxx_verbose & VERBOSE_MINOR_ERROR)
3869 printk(INFO_LEAD "Underflow - Wanted %u, %s %u, residual SG "
3870 "count %d.\n", p->host_no, CTL_OF_SCB(scb), cmd->underflow,
3871 (rq_data_dir(cmd->request) == WRITE) ? "wrote" : "read", actual,
3872 hscb->residual_SG_segment_count);
3873 printk(INFO_LEAD "status 0x%x.\n", p->host_no, CTL_OF_SCB(scb),
3874 hscb->target_status);
3877 * In 2.4, only send back the residual information, don't flag this
3878 * as an error. Before 2.4 we had to flag this as an error because
3879 * the mid layer didn't check residual data counts to see if the
3880 * command needs retried.
3882 cmd->resid = scb->sg_length - actual;
3883 aic7xxx_status(cmd) = hscb->target_status;
3888 * Clean out the residual information in the SCB for the
3889 * next consumer.
3891 hscb->residual_data_count[2] = 0;
3892 hscb->residual_data_count[1] = 0;
3893 hscb->residual_data_count[0] = 0;
3894 hscb->residual_SG_segment_count = 0;
3897 /*+F*************************************************************************
3898 * Function:
3899 * aic7xxx_handle_device_reset
3901 * Description:
3902 * Interrupt handler for sequencer interrupts (SEQINT).
3903 *-F*************************************************************************/
3904 static void
3905 aic7xxx_handle_device_reset(struct aic7xxx_host *p, int target, int channel)
3907 unsigned char tindex = target;
3909 tindex |= ((channel & 0x01) << 3);
3912 * Go back to async/narrow transfers and renegotiate.
3914 aic_outb(p, 0, TARG_SCSIRATE + tindex);
3915 if (p->features & AHC_ULTRA2)
3916 aic_outb(p, 0, TARG_OFFSET + tindex);
3917 aic7xxx_reset_device(p, target, channel, ALL_LUNS, SCB_LIST_NULL);
3918 if (aic7xxx_verbose & VERBOSE_RESET_PROCESS)
3919 printk(INFO_LEAD "Bus Device Reset delivered.\n", p->host_no, channel,
3920 target, -1);
3921 aic7xxx_run_done_queue(p, /*complete*/ TRUE);
3924 /*+F*************************************************************************
3925 * Function:
3926 * aic7xxx_handle_seqint
3928 * Description:
3929 * Interrupt handler for sequencer interrupts (SEQINT).
3930 *-F*************************************************************************/
3931 static void
3932 aic7xxx_handle_seqint(struct aic7xxx_host *p, unsigned char intstat)
3934 struct aic7xxx_scb *scb;
3935 struct aic_dev_data *aic_dev;
3936 unsigned short target_mask;
3937 unsigned char target, lun, tindex;
3938 unsigned char queue_flag = FALSE;
3939 char channel;
3940 int result;
3942 target = ((aic_inb(p, SAVED_TCL) >> 4) & 0x0f);
3943 if ( (p->chip & AHC_CHIPID_MASK) == AHC_AIC7770 )
3944 channel = (aic_inb(p, SBLKCTL) & SELBUSB) >> 3;
3945 else
3946 channel = 0;
3947 tindex = target + (channel << 3);
3948 lun = aic_inb(p, SAVED_TCL) & 0x07;
3949 target_mask = (0x01 << tindex);
3952 * Go ahead and clear the SEQINT now, that avoids any interrupt race
3953 * conditions later on in case we enable some other interrupt.
3955 aic_outb(p, CLRSEQINT, CLRINT);
3956 switch (intstat & SEQINT_MASK)
3958 case NO_MATCH:
3960 aic_outb(p, aic_inb(p, SCSISEQ) & (ENSELI|ENRSELI|ENAUTOATNP),
3961 SCSISEQ);
3962 printk(WARN_LEAD "No active SCB for reconnecting target - Issuing "
3963 "BUS DEVICE RESET.\n", p->host_no, channel, target, lun);
3964 printk(WARN_LEAD " SAVED_TCL=0x%x, ARG_1=0x%x, SEQADDR=0x%x\n",
3965 p->host_no, channel, target, lun,
3966 aic_inb(p, SAVED_TCL), aic_inb(p, ARG_1),
3967 (aic_inb(p, SEQADDR1) << 8) | aic_inb(p, SEQADDR0));
3968 if (aic7xxx_panic_on_abort)
3969 aic7xxx_panic_abort(p, NULL);
3971 break;
3973 case SEND_REJECT:
3975 if (aic7xxx_verbose & VERBOSE_MINOR_ERROR)
3976 printk(INFO_LEAD "Rejecting unknown message (0x%x) received from "
3977 "target, SEQ_FLAGS=0x%x\n", p->host_no, channel, target, lun,
3978 aic_inb(p, ACCUM), aic_inb(p, SEQ_FLAGS));
3980 break;
3982 case NO_IDENT:
3985 * The reconnecting target either did not send an identify
3986 * message, or did, but we didn't find an SCB to match and
3987 * before it could respond to our ATN/abort, it hit a dataphase.
3988 * The only safe thing to do is to blow it away with a bus
3989 * reset.
3991 if (aic7xxx_verbose & (VERBOSE_SEQINT | VERBOSE_RESET_MID))
3992 printk(INFO_LEAD "Target did not send an IDENTIFY message; "
3993 "LASTPHASE 0x%x, SAVED_TCL 0x%x\n", p->host_no, channel, target,
3994 lun, aic_inb(p, LASTPHASE), aic_inb(p, SAVED_TCL));
3996 aic7xxx_reset_channel(p, channel, /*initiate reset*/ TRUE);
3997 aic7xxx_run_done_queue(p, TRUE);
4000 break;
4002 case BAD_PHASE:
4003 if (aic_inb(p, LASTPHASE) == P_BUSFREE)
4005 if (aic7xxx_verbose & VERBOSE_SEQINT)
4006 printk(INFO_LEAD "Missed busfree.\n", p->host_no, channel,
4007 target, lun);
4008 restart_sequencer(p);
4010 else
4012 if (aic7xxx_verbose & VERBOSE_SEQINT)
4013 printk(INFO_LEAD "Unknown scsi bus phase, continuing\n", p->host_no,
4014 channel, target, lun);
4016 break;
4018 case EXTENDED_MSG:
4020 p->msg_type = MSG_TYPE_INITIATOR_MSGIN;
4021 p->msg_len = 0;
4022 p->msg_index = 0;
4024 #ifdef AIC7XXX_VERBOSE_DEBUGGING
4025 if (aic7xxx_verbose > 0xffff)
4026 printk(INFO_LEAD "Enabling REQINITs for MSG_IN\n", p->host_no,
4027 channel, target, lun);
4028 #endif
4031 * To actually receive the message, simply turn on
4032 * REQINIT interrupts and let our interrupt handler
4033 * do the rest (REQINIT should already be true).
4035 p->flags |= AHC_HANDLING_REQINITS;
4036 aic_outb(p, aic_inb(p, SIMODE1) | ENREQINIT, SIMODE1);
4039 * We don't want the sequencer unpaused yet so we return early
4041 return;
4044 case REJECT_MSG:
4047 * What we care about here is if we had an outstanding SDTR
4048 * or WDTR message for this target. If we did, this is a
4049 * signal that the target is refusing negotiation.
4051 unsigned char scb_index;
4052 unsigned char last_msg;
4054 scb_index = aic_inb(p, SCB_TAG);
4055 scb = p->scb_data->scb_array[scb_index];
4056 aic_dev = AIC_DEV(scb->cmd);
4057 last_msg = aic_inb(p, LAST_MSG);
4059 if ( (last_msg == MSG_IDENTIFYFLAG) &&
4060 (scb->tag_action) &&
4061 !(scb->flags & SCB_MSGOUT_BITS) )
4063 if (scb->tag_action == MSG_ORDERED_Q_TAG)
4066 * OK...the device seems able to accept tagged commands, but
4067 * not ordered tag commands, only simple tag commands. So, we
4068 * disable ordered tag commands and go on with life just like
4069 * normal.
4071 scsi_adjust_queue_depth(scb->cmd->device, MSG_SIMPLE_TAG,
4072 scb->cmd->device->queue_depth);
4073 scb->tag_action = MSG_SIMPLE_Q_TAG;
4074 scb->hscb->control &= ~SCB_TAG_TYPE;
4075 scb->hscb->control |= MSG_SIMPLE_Q_TAG;
4076 aic_outb(p, scb->hscb->control, SCB_CONTROL);
4078 * OK..we set the tag type to simple tag command, now we re-assert
4079 * ATNO and hope this will take us into the identify phase again
4080 * so we can resend the tag type and info to the device.
4082 aic_outb(p, MSG_IDENTIFYFLAG, MSG_OUT);
4083 aic_outb(p, aic_inb(p, SCSISIGI) | ATNO, SCSISIGO);
4085 else if (scb->tag_action == MSG_SIMPLE_Q_TAG)
4087 unsigned char i;
4088 struct aic7xxx_scb *scbp;
4089 int old_verbose;
4091 * Hmmmm....the device is flaking out on tagged commands.
4093 scsi_adjust_queue_depth(scb->cmd->device, 0 /* untagged */,
4094 p->host->cmd_per_lun);
4095 aic_dev->max_q_depth = aic_dev->temp_q_depth = 1;
4097 * We set this command up as a bus device reset. However, we have
4098 * to clear the tag type as it's causing us problems. We shouldnt
4099 * have to worry about any other commands being active, since if
4100 * the device is refusing tagged commands, this should be the
4101 * first tagged command sent to the device, however, we do have
4102 * to worry about any other tagged commands that may already be
4103 * in the qinfifo. The easiest way to do this, is to issue a BDR,
4104 * send all the commands back to the mid level code, then let them
4105 * come back and get rebuilt as untagged commands.
4107 scb->tag_action = 0;
4108 scb->hscb->control &= ~(TAG_ENB | SCB_TAG_TYPE);
4109 aic_outb(p, scb->hscb->control, SCB_CONTROL);
4111 old_verbose = aic7xxx_verbose;
4112 aic7xxx_verbose &= ~(VERBOSE_RESET|VERBOSE_ABORT);
4113 for (i=0; i < p->scb_data->numscbs; i++)
4115 scbp = p->scb_data->scb_array[i];
4116 if ((scbp->flags & SCB_ACTIVE) && (scbp != scb))
4118 if (aic7xxx_match_scb(p, scbp, target, channel, lun, i))
4120 aic7xxx_reset_device(p, target, channel, lun, i);
4124 aic7xxx_run_done_queue(p, TRUE);
4125 aic7xxx_verbose = old_verbose;
4127 * Wait until after the for loop to set the busy index since
4128 * aic7xxx_reset_device will clear the busy index during its
4129 * operation.
4131 aic7xxx_busy_target(p, scb);
4132 printk(INFO_LEAD "Device is refusing tagged commands, using "
4133 "untagged I/O.\n", p->host_no, channel, target, lun);
4134 aic_outb(p, MSG_IDENTIFYFLAG, MSG_OUT);
4135 aic_outb(p, aic_inb(p, SCSISIGI) | ATNO, SCSISIGO);
4138 else if (scb->flags & SCB_MSGOUT_PPR)
4141 * As per the draft specs, any device capable of supporting any of
4142 * the option values other than 0 are not allowed to reject the
4143 * PPR message. Instead, they must negotiate out what they do
4144 * support instead of rejecting our offering or else they cause
4145 * a parity error during msg_out phase to signal that they don't
4146 * like our settings.
4148 aic_dev->needppr = aic_dev->needppr_copy = 0;
4149 aic7xxx_set_width(p, target, channel, lun, MSG_EXT_WDTR_BUS_8_BIT,
4150 (AHC_TRANS_ACTIVE|AHC_TRANS_CUR|AHC_TRANS_QUITE), aic_dev);
4151 aic7xxx_set_syncrate(p, NULL, target, channel, 0, 0, 0,
4152 AHC_TRANS_ACTIVE|AHC_TRANS_CUR|AHC_TRANS_QUITE,
4153 aic_dev);
4154 aic_dev->goal.options = aic_dev->dtr_pending = 0;
4155 scb->flags &= ~SCB_MSGOUT_BITS;
4156 if(aic7xxx_verbose & VERBOSE_NEGOTIATION2)
4158 printk(INFO_LEAD "Device is rejecting PPR messages, falling "
4159 "back.\n", p->host_no, channel, target, lun);
4161 if ( aic_dev->goal.width )
4163 aic_dev->needwdtr = aic_dev->needwdtr_copy = 1;
4164 aic_dev->dtr_pending = 1;
4165 scb->flags |= SCB_MSGOUT_WDTR;
4167 if ( aic_dev->goal.offset )
4169 aic_dev->needsdtr = aic_dev->needsdtr_copy = 1;
4170 if( !aic_dev->dtr_pending )
4172 aic_dev->dtr_pending = 1;
4173 scb->flags |= SCB_MSGOUT_SDTR;
4176 if ( aic_dev->dtr_pending )
4178 aic_outb(p, HOST_MSG, MSG_OUT);
4179 aic_outb(p, aic_inb(p, SCSISIGI) | ATNO, SCSISIGO);
4182 else if (scb->flags & SCB_MSGOUT_WDTR)
4185 * note 8bit xfers and clear flag
4187 aic_dev->needwdtr = aic_dev->needwdtr_copy = 0;
4188 scb->flags &= ~SCB_MSGOUT_BITS;
4189 aic7xxx_set_width(p, target, channel, lun, MSG_EXT_WDTR_BUS_8_BIT,
4190 (AHC_TRANS_ACTIVE|AHC_TRANS_GOAL|AHC_TRANS_CUR), aic_dev);
4191 aic7xxx_set_syncrate(p, NULL, target, channel, 0, 0, 0,
4192 AHC_TRANS_ACTIVE|AHC_TRANS_CUR|AHC_TRANS_QUITE,
4193 aic_dev);
4194 if(aic7xxx_verbose & VERBOSE_NEGOTIATION2)
4196 printk(INFO_LEAD "Device is rejecting WDTR messages, using "
4197 "narrow transfers.\n", p->host_no, channel, target, lun);
4199 aic_dev->needsdtr = aic_dev->needsdtr_copy;
4201 else if (scb->flags & SCB_MSGOUT_SDTR)
4204 * note asynch xfers and clear flag
4206 aic_dev->needsdtr = aic_dev->needsdtr_copy = 0;
4207 scb->flags &= ~SCB_MSGOUT_BITS;
4208 aic7xxx_set_syncrate(p, NULL, target, channel, 0, 0, 0,
4209 (AHC_TRANS_CUR|AHC_TRANS_ACTIVE|AHC_TRANS_GOAL), aic_dev);
4210 if(aic7xxx_verbose & VERBOSE_NEGOTIATION2)
4212 printk(INFO_LEAD "Device is rejecting SDTR messages, using "
4213 "async transfers.\n", p->host_no, channel, target, lun);
4216 else if (aic7xxx_verbose & VERBOSE_SEQINT)
4219 * Otherwise, we ignore it.
4221 printk(INFO_LEAD "Received MESSAGE_REJECT for unknown cause. "
4222 "Ignoring.\n", p->host_no, channel, target, lun);
4225 break;
4227 case BAD_STATUS:
4229 unsigned char scb_index;
4230 struct aic7xxx_hwscb *hscb;
4231 Scsi_Cmnd *cmd;
4233 /* The sequencer will notify us when a command has an error that
4234 * would be of interest to the kernel. This allows us to leave
4235 * the sequencer running in the common case of command completes
4236 * without error. The sequencer will have DMA'd the SCB back
4237 * up to us, so we can reference the drivers SCB array.
4239 * Set the default return value to 0 indicating not to send
4240 * sense. The sense code will change this if needed and this
4241 * reduces code duplication.
4243 aic_outb(p, 0, RETURN_1);
4244 scb_index = aic_inb(p, SCB_TAG);
4245 if (scb_index > p->scb_data->numscbs)
4247 printk(WARN_LEAD "Invalid SCB during SEQINT 0x%02x, SCB_TAG %d.\n",
4248 p->host_no, channel, target, lun, intstat, scb_index);
4249 break;
4251 scb = p->scb_data->scb_array[scb_index];
4252 hscb = scb->hscb;
4254 if (!(scb->flags & SCB_ACTIVE) || (scb->cmd == NULL))
4256 printk(WARN_LEAD "Invalid SCB during SEQINT 0x%x, scb %d, flags 0x%x,"
4257 " cmd 0x%lx.\n", p->host_no, channel, target, lun, intstat,
4258 scb_index, scb->flags, (unsigned long) scb->cmd);
4260 else
4262 cmd = scb->cmd;
4263 aic_dev = AIC_DEV(scb->cmd);
4264 hscb->target_status = aic_inb(p, SCB_TARGET_STATUS);
4265 aic7xxx_status(cmd) = hscb->target_status;
4267 cmd->result = hscb->target_status;
4269 switch (status_byte(hscb->target_status))
4271 case GOOD:
4272 if (aic7xxx_verbose & VERBOSE_SEQINT)
4273 printk(INFO_LEAD "Interrupted for status of GOOD???\n",
4274 p->host_no, CTL_OF_SCB(scb));
4275 break;
4277 case COMMAND_TERMINATED:
4278 case CHECK_CONDITION:
4279 if ( !(scb->flags & SCB_SENSE) )
4282 * Send a sense command to the requesting target.
4283 * XXX - revisit this and get rid of the memcopys.
4285 memcpy(scb->sense_cmd, &generic_sense[0],
4286 sizeof(generic_sense));
4288 scb->sense_cmd[1] = (cmd->device->lun << 5);
4289 scb->sense_cmd[4] = sizeof(cmd->sense_buffer);
4291 scb->sg_list[0].length =
4292 cpu_to_le32(sizeof(cmd->sense_buffer));
4293 scb->sg_list[0].address =
4294 cpu_to_le32(pci_map_single(p->pdev, cmd->sense_buffer,
4295 sizeof(cmd->sense_buffer),
4296 PCI_DMA_FROMDEVICE));
4299 * XXX - We should allow disconnection, but can't as it
4300 * might allow overlapped tagged commands.
4302 /* hscb->control &= DISCENB; */
4303 hscb->control = 0;
4304 hscb->target_status = 0;
4305 hscb->SG_list_pointer =
4306 cpu_to_le32(SCB_DMA_ADDR(scb, scb->sg_list));
4307 hscb->SCSI_cmd_pointer =
4308 cpu_to_le32(SCB_DMA_ADDR(scb, scb->sense_cmd));
4309 hscb->data_count = scb->sg_list[0].length;
4310 hscb->data_pointer = scb->sg_list[0].address;
4311 hscb->SCSI_cmd_length = COMMAND_SIZE(scb->sense_cmd[0]);
4312 hscb->residual_SG_segment_count = 0;
4313 hscb->residual_data_count[0] = 0;
4314 hscb->residual_data_count[1] = 0;
4315 hscb->residual_data_count[2] = 0;
4317 scb->sg_count = hscb->SG_segment_count = 1;
4318 scb->sg_length = sizeof(cmd->sense_buffer);
4319 scb->tag_action = 0;
4320 scb->flags |= SCB_SENSE;
4322 * Ensure the target is busy since this will be an
4323 * an untagged request.
4325 #ifdef AIC7XXX_VERBOSE_DEBUGGING
4326 if (aic7xxx_verbose & VERBOSE_NEGOTIATION2)
4328 if (scb->flags & SCB_MSGOUT_BITS)
4329 printk(INFO_LEAD "Requesting SENSE with %s\n", p->host_no,
4330 CTL_OF_SCB(scb), (scb->flags & SCB_MSGOUT_SDTR) ?
4331 "SDTR" : "WDTR");
4332 else
4333 printk(INFO_LEAD "Requesting SENSE, no MSG\n", p->host_no,
4334 CTL_OF_SCB(scb));
4336 #endif
4337 aic7xxx_busy_target(p, scb);
4338 aic_outb(p, SEND_SENSE, RETURN_1);
4339 aic7xxx_error(cmd) = DID_OK;
4340 break;
4341 } /* first time sense, no errors */
4342 printk(INFO_LEAD "CHECK_CONDITION on REQUEST_SENSE, returning "
4343 "an error.\n", p->host_no, CTL_OF_SCB(scb));
4344 aic7xxx_error(cmd) = DID_ERROR;
4345 scb->flags &= ~SCB_SENSE;
4346 break;
4348 case QUEUE_FULL:
4349 queue_flag = TRUE; /* Mark that this is a QUEUE_FULL and */
4350 case BUSY: /* drop through to here */
4352 struct aic7xxx_scb *next_scbp, *prev_scbp;
4353 unsigned char active_hscb, next_hscb, prev_hscb, scb_index;
4355 * We have to look three places for queued commands:
4356 * 1: p->waiting_scbs queue
4357 * 2: QINFIFO
4358 * 3: WAITING_SCBS list on card (for commands that are started
4359 * but haven't yet made it to the device)
4361 * Of special note here is that commands on 2 or 3 above will
4362 * have already been marked as active, while commands on 1 will
4363 * not. The aic7xxx_done() function will want to unmark them
4364 * from active, so any commands we pull off of 1 need to
4365 * up the active count.
4367 next_scbp = p->waiting_scbs.head;
4368 while ( next_scbp != NULL )
4370 prev_scbp = next_scbp;
4371 next_scbp = next_scbp->q_next;
4372 if ( aic7xxx_match_scb(p, prev_scbp, target, channel, lun,
4373 SCB_LIST_NULL) )
4375 scbq_remove(&p->waiting_scbs, prev_scbp);
4376 scb->flags = SCB_QUEUED_FOR_DONE | SCB_QUEUE_FULL;
4377 p->activescbs++;
4378 aic_dev->active_cmds++;
4381 aic7xxx_search_qinfifo(p, target, channel, lun,
4382 SCB_LIST_NULL, SCB_QUEUED_FOR_DONE | SCB_QUEUE_FULL,
4383 FALSE, NULL);
4384 next_scbp = NULL;
4385 active_hscb = aic_inb(p, SCBPTR);
4386 prev_hscb = next_hscb = scb_index = SCB_LIST_NULL;
4387 next_hscb = aic_inb(p, WAITING_SCBH);
4388 while (next_hscb != SCB_LIST_NULL)
4390 aic_outb(p, next_hscb, SCBPTR);
4391 scb_index = aic_inb(p, SCB_TAG);
4392 if (scb_index < p->scb_data->numscbs)
4394 next_scbp = p->scb_data->scb_array[scb_index];
4395 if (aic7xxx_match_scb(p, next_scbp, target, channel, lun,
4396 SCB_LIST_NULL) )
4398 next_scbp->flags = SCB_QUEUED_FOR_DONE | SCB_QUEUE_FULL;
4399 next_hscb = aic_inb(p, SCB_NEXT);
4400 aic_outb(p, 0, SCB_CONTROL);
4401 aic_outb(p, SCB_LIST_NULL, SCB_TAG);
4402 aic7xxx_add_curscb_to_free_list(p);
4403 if (prev_hscb == SCB_LIST_NULL)
4405 /* We were first on the list,
4406 * so we kill the selection
4407 * hardware. Let the sequencer
4408 * re-init the hardware itself
4410 aic_outb(p, aic_inb(p, SCSISEQ) & ~ENSELO, SCSISEQ);
4411 aic_outb(p, CLRSELTIMEO, CLRSINT1);
4412 aic_outb(p, next_hscb, WAITING_SCBH);
4414 else
4416 aic_outb(p, prev_hscb, SCBPTR);
4417 aic_outb(p, next_hscb, SCB_NEXT);
4420 else
4422 prev_hscb = next_hscb;
4423 next_hscb = aic_inb(p, SCB_NEXT);
4425 } /* scb_index >= p->scb_data->numscbs */
4427 aic_outb(p, active_hscb, SCBPTR);
4428 aic7xxx_run_done_queue(p, FALSE);
4430 #ifdef AIC7XXX_VERBOSE_DEBUGGING
4431 if( (aic7xxx_verbose & VERBOSE_MINOR_ERROR) ||
4432 (aic7xxx_verbose > 0xffff) )
4434 if (queue_flag)
4435 printk(INFO_LEAD "Queue full received; queue depth %d, "
4436 "active %d\n", p->host_no, CTL_OF_SCB(scb),
4437 aic_dev->max_q_depth, aic_dev->active_cmds);
4438 else
4439 printk(INFO_LEAD "Target busy\n", p->host_no, CTL_OF_SCB(scb));
4441 #endif
4442 if (queue_flag)
4444 int diff;
4445 result = scsi_track_queue_full(cmd->device,
4446 aic_dev->active_cmds);
4447 if ( result < 0 )
4449 if (aic7xxx_verbose & VERBOSE_NEGOTIATION2)
4450 printk(INFO_LEAD "Tagged Command Queueing disabled.\n",
4451 p->host_no, CTL_OF_SCB(scb));
4452 diff = aic_dev->max_q_depth - p->host->cmd_per_lun;
4453 aic_dev->temp_q_depth = 1;
4454 aic_dev->max_q_depth = 1;
4456 else if ( result > 0 )
4458 if (aic7xxx_verbose & VERBOSE_NEGOTIATION2)
4459 printk(INFO_LEAD "Queue depth reduced to %d\n", p->host_no,
4460 CTL_OF_SCB(scb), result);
4461 diff = aic_dev->max_q_depth - result;
4462 aic_dev->max_q_depth = result;
4463 /* temp_q_depth could have been dropped to 1 for an untagged
4464 * command that might be coming up */
4465 if(aic_dev->temp_q_depth > result)
4466 aic_dev->temp_q_depth = result;
4468 /* We should free up the no unused SCB entries. But, that's
4469 * a difficult thing to do because we use a direct indexed
4470 * array, so we can't just take any entries and free them,
4471 * we *have* to free the ones at the end of the array, and
4472 * they very well could be in use right now, which means
4473 * in order to do this right, we have to add a delayed
4474 * freeing mechanism tied into the scb_free() code area.
4475 * We'll add that later.
4478 break;
4481 default:
4482 if (aic7xxx_verbose & VERBOSE_SEQINT)
4483 printk(INFO_LEAD "Unexpected target status 0x%x.\n", p->host_no,
4484 CTL_OF_SCB(scb), scb->hscb->target_status);
4485 if (!aic7xxx_error(cmd))
4487 aic7xxx_error(cmd) = DID_RETRY_COMMAND;
4489 break;
4490 } /* end switch */
4491 } /* end else of */
4493 break;
4495 case AWAITING_MSG:
4497 unsigned char scb_index, msg_out;
4499 scb_index = aic_inb(p, SCB_TAG);
4500 msg_out = aic_inb(p, MSG_OUT);
4501 scb = p->scb_data->scb_array[scb_index];
4502 aic_dev = AIC_DEV(scb->cmd);
4503 p->msg_index = p->msg_len = 0;
4505 * This SCB had a MK_MESSAGE set in its control byte informing
4506 * the sequencer that we wanted to send a special message to
4507 * this target.
4510 if ( !(scb->flags & SCB_DEVICE_RESET) &&
4511 (msg_out == MSG_IDENTIFYFLAG) &&
4512 (scb->hscb->control & TAG_ENB) )
4514 p->msg_buf[p->msg_index++] = scb->tag_action;
4515 p->msg_buf[p->msg_index++] = scb->hscb->tag;
4516 p->msg_len += 2;
4519 if (scb->flags & SCB_DEVICE_RESET)
4521 p->msg_buf[p->msg_index++] = MSG_BUS_DEV_RESET;
4522 p->msg_len++;
4523 if (aic7xxx_verbose & VERBOSE_RESET_PROCESS)
4524 printk(INFO_LEAD "Bus device reset mailed.\n",
4525 p->host_no, CTL_OF_SCB(scb));
4527 else if (scb->flags & SCB_ABORT)
4529 if (scb->tag_action)
4531 p->msg_buf[p->msg_index++] = MSG_ABORT_TAG;
4533 else
4535 p->msg_buf[p->msg_index++] = MSG_ABORT;
4537 p->msg_len++;
4538 if (aic7xxx_verbose & VERBOSE_ABORT_PROCESS)
4539 printk(INFO_LEAD "Abort message mailed.\n", p->host_no,
4540 CTL_OF_SCB(scb));
4542 else if (scb->flags & SCB_MSGOUT_PPR)
4544 if (aic7xxx_verbose & VERBOSE_NEGOTIATION2)
4546 printk(INFO_LEAD "Sending PPR (%d/%d/%d/%d) message.\n",
4547 p->host_no, CTL_OF_SCB(scb),
4548 aic_dev->goal.period,
4549 aic_dev->goal.offset,
4550 aic_dev->goal.width,
4551 aic_dev->goal.options);
4553 aic7xxx_construct_ppr(p, scb);
4555 else if (scb->flags & SCB_MSGOUT_WDTR)
4557 if (aic7xxx_verbose & VERBOSE_NEGOTIATION2)
4559 printk(INFO_LEAD "Sending WDTR message.\n", p->host_no,
4560 CTL_OF_SCB(scb));
4562 aic7xxx_construct_wdtr(p, aic_dev->goal.width);
4564 else if (scb->flags & SCB_MSGOUT_SDTR)
4566 unsigned int max_sync, period;
4567 unsigned char options = 0;
4569 * Now that the device is selected, use the bits in SBLKCTL and
4570 * SSTAT2 to determine the max sync rate for this device.
4572 if (p->features & AHC_ULTRA2)
4574 if ( (aic_inb(p, SBLKCTL) & ENAB40) &&
4575 !(aic_inb(p, SSTAT2) & EXP_ACTIVE) )
4577 max_sync = AHC_SYNCRATE_ULTRA2;
4579 else
4581 max_sync = AHC_SYNCRATE_ULTRA;
4584 else if (p->features & AHC_ULTRA)
4586 max_sync = AHC_SYNCRATE_ULTRA;
4588 else
4590 max_sync = AHC_SYNCRATE_FAST;
4592 period = aic_dev->goal.period;
4593 aic7xxx_find_syncrate(p, &period, max_sync, &options);
4594 if (aic7xxx_verbose & VERBOSE_NEGOTIATION2)
4596 printk(INFO_LEAD "Sending SDTR %d/%d message.\n", p->host_no,
4597 CTL_OF_SCB(scb), period,
4598 aic_dev->goal.offset);
4600 aic7xxx_construct_sdtr(p, period, aic_dev->goal.offset);
4602 else
4604 panic("aic7xxx: AWAITING_MSG for an SCB that does "
4605 "not have a waiting message.\n");
4608 * We've set everything up to send our message, now to actually do
4609 * so we need to enable reqinit interrupts and let the interrupt
4610 * handler do the rest. We don't want to unpause the sequencer yet
4611 * though so we'll return early. We also have to make sure that
4612 * we clear the SEQINT *BEFORE* we set the REQINIT handler active
4613 * or else it's possible on VLB cards to lose the first REQINIT
4614 * interrupt. Edge triggered EISA cards could also lose this
4615 * interrupt, although PCI and level triggered cards should not
4616 * have this problem since they continually interrupt the kernel
4617 * until we take care of the situation.
4619 scb->flags |= SCB_MSGOUT_SENT;
4620 p->msg_index = 0;
4621 p->msg_type = MSG_TYPE_INITIATOR_MSGOUT;
4622 p->flags |= AHC_HANDLING_REQINITS;
4623 aic_outb(p, aic_inb(p, SIMODE1) | ENREQINIT, SIMODE1);
4624 return;
4626 break;
4628 case DATA_OVERRUN:
4630 unsigned char scb_index = aic_inb(p, SCB_TAG);
4631 unsigned char lastphase = aic_inb(p, LASTPHASE);
4632 unsigned int i;
4634 scb = (p->scb_data->scb_array[scb_index]);
4636 * XXX - What do we really want to do on an overrun? The
4637 * mid-level SCSI code should handle this, but for now,
4638 * we'll just indicate that the command should retried.
4639 * If we retrieved sense info on this target, then the
4640 * base SENSE info should have been saved prior to the
4641 * overrun error. In that case, we return DID_OK and let
4642 * the mid level code pick up on the sense info. Otherwise
4643 * we return DID_ERROR so the command will get retried.
4645 if ( !(scb->flags & SCB_SENSE) )
4647 printk(WARN_LEAD "Data overrun detected in %s phase, tag %d;\n",
4648 p->host_no, CTL_OF_SCB(scb),
4649 (lastphase == P_DATAIN) ? "Data-In" : "Data-Out", scb->hscb->tag);
4650 printk(KERN_WARNING " %s seen Data Phase. Length=%d, NumSGs=%d.\n",
4651 (aic_inb(p, SEQ_FLAGS) & DPHASE) ? "Have" : "Haven't",
4652 scb->sg_length, scb->sg_count);
4653 printk(KERN_WARNING " Raw SCSI Command: 0x");
4654 for (i = 0; i < scb->hscb->SCSI_cmd_length; i++)
4656 printk("%02x ", scb->cmd->cmnd[i]);
4658 printk("\n");
4659 if(aic7xxx_verbose > 0xffff)
4661 for (i = 0; i < scb->sg_count; i++)
4663 printk(KERN_WARNING " sg[%d] - Addr 0x%x : Length %d\n",
4665 le32_to_cpu(scb->sg_list[i].address),
4666 le32_to_cpu(scb->sg_list[i].length) );
4669 aic7xxx_error(scb->cmd) = DID_ERROR;
4671 else
4672 printk(INFO_LEAD "Data Overrun during SEND_SENSE operation.\n",
4673 p->host_no, CTL_OF_SCB(scb));
4675 break;
4677 case WIDE_RESIDUE:
4679 unsigned char resid_sgcnt, index;
4680 unsigned char scb_index = aic_inb(p, SCB_TAG);
4681 unsigned int cur_addr, resid_dcnt;
4682 unsigned int native_addr, native_length, sg_addr;
4683 int i;
4685 if(scb_index > p->scb_data->numscbs)
4687 printk(WARN_LEAD "invalid scb_index during WIDE_RESIDUE.\n",
4688 p->host_no, -1, -1, -1);
4690 * XXX: Add error handling here
4692 break;
4694 scb = p->scb_data->scb_array[scb_index];
4695 if(!(scb->flags & SCB_ACTIVE) || (scb->cmd == NULL))
4697 printk(WARN_LEAD "invalid scb during WIDE_RESIDUE flags:0x%x "
4698 "scb->cmd:0x%lx\n", p->host_no, CTL_OF_SCB(scb),
4699 scb->flags, (unsigned long)scb->cmd);
4700 break;
4702 if(aic7xxx_verbose & VERBOSE_MINOR_ERROR)
4703 printk(INFO_LEAD "Got WIDE_RESIDUE message, patching up data "
4704 "pointer.\n", p->host_no, CTL_OF_SCB(scb));
4707 * We have a valid scb to use on this WIDE_RESIDUE message, so
4708 * we need to walk the sg list looking for this particular sg
4709 * segment, then see if we happen to be at the very beginning of
4710 * the segment. If we are, then we have to back things up to
4711 * the previous segment. If not, then we simply need to remove
4712 * one byte from this segments address and add one to the byte
4713 * count.
4715 cur_addr = aic_inb(p, SHADDR) | (aic_inb(p, SHADDR + 1) << 8) |
4716 (aic_inb(p, SHADDR + 2) << 16) | (aic_inb(p, SHADDR + 3) << 24);
4717 sg_addr = aic_inb(p, SG_COUNT + 1) | (aic_inb(p, SG_COUNT + 2) << 8) |
4718 (aic_inb(p, SG_COUNT + 3) << 16) | (aic_inb(p, SG_COUNT + 4) << 24);
4719 resid_sgcnt = aic_inb(p, SCB_RESID_SGCNT);
4720 resid_dcnt = aic_inb(p, SCB_RESID_DCNT) |
4721 (aic_inb(p, SCB_RESID_DCNT + 1) << 8) |
4722 (aic_inb(p, SCB_RESID_DCNT + 2) << 16);
4723 index = scb->sg_count - ((resid_sgcnt) ? resid_sgcnt : 1);
4724 native_addr = le32_to_cpu(scb->sg_list[index].address);
4725 native_length = le32_to_cpu(scb->sg_list[index].length);
4727 * If resid_dcnt == native_length, then we just loaded this SG
4728 * segment and we need to back it up one...
4730 if(resid_dcnt == native_length)
4732 if(index == 0)
4735 * Oops, this isn't right, we can't back up to before the
4736 * beginning. This must be a bogus message, ignore it.
4738 break;
4740 resid_dcnt = 1;
4741 resid_sgcnt += 1;
4742 native_addr = le32_to_cpu(scb->sg_list[index - 1].address);
4743 native_length = le32_to_cpu(scb->sg_list[index - 1].length);
4744 cur_addr = native_addr + (native_length - 1);
4745 sg_addr -= sizeof(struct hw_scatterlist);
4747 else
4750 * resid_dcnt != native_length, so we are in the middle of a SG
4751 * element. Back it up one byte and leave the rest alone.
4753 resid_dcnt += 1;
4754 cur_addr -= 1;
4758 * Output the new addresses and counts to the right places on the
4759 * card.
4761 aic_outb(p, resid_sgcnt, SG_COUNT);
4762 aic_outb(p, resid_sgcnt, SCB_RESID_SGCNT);
4763 aic_outb(p, sg_addr & 0xff, SG_COUNT + 1);
4764 aic_outb(p, (sg_addr >> 8) & 0xff, SG_COUNT + 2);
4765 aic_outb(p, (sg_addr >> 16) & 0xff, SG_COUNT + 3);
4766 aic_outb(p, (sg_addr >> 24) & 0xff, SG_COUNT + 4);
4767 aic_outb(p, resid_dcnt & 0xff, SCB_RESID_DCNT);
4768 aic_outb(p, (resid_dcnt >> 8) & 0xff, SCB_RESID_DCNT + 1);
4769 aic_outb(p, (resid_dcnt >> 16) & 0xff, SCB_RESID_DCNT + 2);
4772 * The sequencer actually wants to find the new address
4773 * in the SHADDR register set. On the Ultra2 and later controllers
4774 * this register set is readonly. In order to get the right number
4775 * into the register, you actually have to enter it in HADDR and then
4776 * use the PRELOADEN bit of DFCNTRL to drop it through from the
4777 * HADDR register to the SHADDR register. On non-Ultra2 controllers,
4778 * we simply write it direct.
4780 if(p->features & AHC_ULTRA2)
4783 * We might as well be accurate and drop both the resid_dcnt and
4784 * cur_addr into HCNT and HADDR and have both of them drop
4785 * through to the shadow layer together.
4787 aic_outb(p, resid_dcnt & 0xff, HCNT);
4788 aic_outb(p, (resid_dcnt >> 8) & 0xff, HCNT + 1);
4789 aic_outb(p, (resid_dcnt >> 16) & 0xff, HCNT + 2);
4790 aic_outb(p, cur_addr & 0xff, HADDR);
4791 aic_outb(p, (cur_addr >> 8) & 0xff, HADDR + 1);
4792 aic_outb(p, (cur_addr >> 16) & 0xff, HADDR + 2);
4793 aic_outb(p, (cur_addr >> 24) & 0xff, HADDR + 3);
4794 aic_outb(p, aic_inb(p, DMAPARAMS) | PRELOADEN, DFCNTRL);
4795 udelay(1);
4796 aic_outb(p, aic_inb(p, DMAPARAMS) & ~(SCSIEN|HDMAEN), DFCNTRL);
4797 i=0;
4798 while(((aic_inb(p, DFCNTRL) & (SCSIEN|HDMAEN)) != 0) && (i++ < 1000))
4800 udelay(1);
4803 else
4805 aic_outb(p, cur_addr & 0xff, SHADDR);
4806 aic_outb(p, (cur_addr >> 8) & 0xff, SHADDR + 1);
4807 aic_outb(p, (cur_addr >> 16) & 0xff, SHADDR + 2);
4808 aic_outb(p, (cur_addr >> 24) & 0xff, SHADDR + 3);
4811 break;
4813 case SEQ_SG_FIXUP:
4815 unsigned char scb_index, tmp;
4816 int sg_addr, sg_length;
4818 scb_index = aic_inb(p, SCB_TAG);
4820 if(scb_index > p->scb_data->numscbs)
4822 printk(WARN_LEAD "invalid scb_index during SEQ_SG_FIXUP.\n",
4823 p->host_no, -1, -1, -1);
4824 printk(INFO_LEAD "SCSISIGI 0x%x, SEQADDR 0x%x, SSTAT0 0x%x, SSTAT1 "
4825 "0x%x\n", p->host_no, -1, -1, -1,
4826 aic_inb(p, SCSISIGI),
4827 aic_inb(p, SEQADDR0) | (aic_inb(p, SEQADDR1) << 8),
4828 aic_inb(p, SSTAT0), aic_inb(p, SSTAT1));
4829 printk(INFO_LEAD "SG_CACHEPTR 0x%x, SSTAT2 0x%x, STCNT 0x%x\n",
4830 p->host_no, -1, -1, -1, aic_inb(p, SG_CACHEPTR),
4831 aic_inb(p, SSTAT2), aic_inb(p, STCNT + 2) << 16 |
4832 aic_inb(p, STCNT + 1) << 8 | aic_inb(p, STCNT));
4834 * XXX: Add error handling here
4836 break;
4838 scb = p->scb_data->scb_array[scb_index];
4839 if(!(scb->flags & SCB_ACTIVE) || (scb->cmd == NULL))
4841 printk(WARN_LEAD "invalid scb during SEQ_SG_FIXUP flags:0x%x "
4842 "scb->cmd:0x%p\n", p->host_no, CTL_OF_SCB(scb),
4843 scb->flags, scb->cmd);
4844 printk(INFO_LEAD "SCSISIGI 0x%x, SEQADDR 0x%x, SSTAT0 0x%x, SSTAT1 "
4845 "0x%x\n", p->host_no, CTL_OF_SCB(scb),
4846 aic_inb(p, SCSISIGI),
4847 aic_inb(p, SEQADDR0) | (aic_inb(p, SEQADDR1) << 8),
4848 aic_inb(p, SSTAT0), aic_inb(p, SSTAT1));
4849 printk(INFO_LEAD "SG_CACHEPTR 0x%x, SSTAT2 0x%x, STCNT 0x%x\n",
4850 p->host_no, CTL_OF_SCB(scb), aic_inb(p, SG_CACHEPTR),
4851 aic_inb(p, SSTAT2), aic_inb(p, STCNT + 2) << 16 |
4852 aic_inb(p, STCNT + 1) << 8 | aic_inb(p, STCNT));
4853 break;
4855 if(aic7xxx_verbose & VERBOSE_MINOR_ERROR)
4856 printk(INFO_LEAD "Fixing up SG address for sequencer.\n", p->host_no,
4857 CTL_OF_SCB(scb));
4859 * Advance the SG pointer to the next element in the list
4861 tmp = aic_inb(p, SG_NEXT);
4862 tmp += SG_SIZEOF;
4863 aic_outb(p, tmp, SG_NEXT);
4864 if( tmp < SG_SIZEOF )
4865 aic_outb(p, aic_inb(p, SG_NEXT + 1) + 1, SG_NEXT + 1);
4866 tmp = aic_inb(p, SG_COUNT) - 1;
4867 aic_outb(p, tmp, SG_COUNT);
4868 sg_addr = le32_to_cpu(scb->sg_list[scb->sg_count - tmp].address);
4869 sg_length = le32_to_cpu(scb->sg_list[scb->sg_count - tmp].length);
4871 * Now stuff the element we just advanced past down onto the
4872 * card so it can be stored in the residual area.
4874 aic_outb(p, sg_addr & 0xff, HADDR);
4875 aic_outb(p, (sg_addr >> 8) & 0xff, HADDR + 1);
4876 aic_outb(p, (sg_addr >> 16) & 0xff, HADDR + 2);
4877 aic_outb(p, (sg_addr >> 24) & 0xff, HADDR + 3);
4878 aic_outb(p, sg_length & 0xff, HCNT);
4879 aic_outb(p, (sg_length >> 8) & 0xff, HCNT + 1);
4880 aic_outb(p, (sg_length >> 16) & 0xff, HCNT + 2);
4881 aic_outb(p, (tmp << 2) | ((tmp == 1) ? LAST_SEG : 0), SG_CACHEPTR);
4882 aic_outb(p, aic_inb(p, DMAPARAMS), DFCNTRL);
4883 while(aic_inb(p, SSTAT0) & SDONE) udelay(1);
4884 while(aic_inb(p, DFCNTRL) & (HDMAEN|SCSIEN)) aic_outb(p, 0, DFCNTRL);
4886 break;
4888 #if AIC7XXX_NOT_YET
4889 case TRACEPOINT2:
4891 printk(INFO_LEAD "Tracepoint #2 reached.\n", p->host_no,
4892 channel, target, lun);
4894 break;
4896 /* XXX Fill these in later */
4897 case MSG_BUFFER_BUSY:
4898 printk("aic7xxx: Message buffer busy.\n");
4899 break;
4900 case MSGIN_PHASEMIS:
4901 printk("aic7xxx: Message-in phasemis.\n");
4902 break;
4903 #endif
4905 default: /* unknown */
4906 printk(WARN_LEAD "Unknown SEQINT, INTSTAT 0x%x, SCSISIGI 0x%x.\n",
4907 p->host_no, channel, target, lun, intstat,
4908 aic_inb(p, SCSISIGI));
4909 break;
4913 * Clear the sequencer interrupt and unpause the sequencer.
4915 unpause_sequencer(p, /* unpause always */ TRUE);
4918 /*+F*************************************************************************
4919 * Function:
4920 * aic7xxx_parse_msg
4922 * Description:
4923 * Parses incoming messages into actions on behalf of
4924 * aic7xxx_handle_reqinit
4925 *_F*************************************************************************/
4926 static int
4927 aic7xxx_parse_msg(struct aic7xxx_host *p, struct aic7xxx_scb *scb)
4929 int reject, reply, done;
4930 unsigned char target_scsirate, tindex;
4931 unsigned short target_mask;
4932 unsigned char target, channel, lun;
4933 unsigned char bus_width, new_bus_width;
4934 unsigned char trans_options, new_trans_options;
4935 unsigned int period, new_period, offset, new_offset, maxsync;
4936 struct aic7xxx_syncrate *syncrate;
4937 struct aic_dev_data *aic_dev;
4939 target = scb->cmd->device->id;
4940 channel = scb->cmd->device->channel;
4941 lun = scb->cmd->device->lun;
4942 reply = reject = done = FALSE;
4943 tindex = TARGET_INDEX(scb->cmd);
4944 aic_dev = AIC_DEV(scb->cmd);
4945 target_scsirate = aic_inb(p, TARG_SCSIRATE + tindex);
4946 target_mask = (0x01 << tindex);
4949 * Parse as much of the message as is available,
4950 * rejecting it if we don't support it. When
4951 * the entire message is available and has been
4952 * handled, return TRUE indicating that we have
4953 * parsed an entire message.
4956 if (p->msg_buf[0] != MSG_EXTENDED)
4958 reject = TRUE;
4962 * Even if we are an Ultra3 card, don't allow Ultra3 sync rates when
4963 * using the SDTR messages. We need the PPR messages to enable the
4964 * higher speeds that include things like Dual Edge clocking.
4966 if (p->features & AHC_ULTRA2)
4968 if ( (aic_inb(p, SBLKCTL) & ENAB40) &&
4969 !(aic_inb(p, SSTAT2) & EXP_ACTIVE) )
4971 if (p->features & AHC_ULTRA3)
4972 maxsync = AHC_SYNCRATE_ULTRA3;
4973 else
4974 maxsync = AHC_SYNCRATE_ULTRA2;
4976 else
4978 maxsync = AHC_SYNCRATE_ULTRA;
4981 else if (p->features & AHC_ULTRA)
4983 maxsync = AHC_SYNCRATE_ULTRA;
4985 else
4987 maxsync = AHC_SYNCRATE_FAST;
4991 * Just accept the length byte outright and perform
4992 * more checking once we know the message type.
4995 if ( !reject && (p->msg_len > 2) )
4997 switch(p->msg_buf[2])
4999 case MSG_EXT_SDTR:
5002 if (p->msg_buf[1] != MSG_EXT_SDTR_LEN)
5004 reject = TRUE;
5005 break;
5008 if (p->msg_len < (MSG_EXT_SDTR_LEN + 2))
5010 break;
5013 period = new_period = p->msg_buf[3];
5014 offset = new_offset = p->msg_buf[4];
5015 trans_options = new_trans_options = 0;
5016 bus_width = new_bus_width = target_scsirate & WIDEXFER;
5019 * If our current max syncrate is in the Ultra3 range, bump it back
5020 * down to Ultra2 since we can't negotiate DT transfers using SDTR
5022 if(maxsync == AHC_SYNCRATE_ULTRA3)
5023 maxsync = AHC_SYNCRATE_ULTRA2;
5026 * We might have a device that is starting negotiation with us
5027 * before we can start up negotiation with it....be prepared to
5028 * have a device ask for a higher speed then we want to give it
5029 * in that case
5031 if ( (scb->flags & (SCB_MSGOUT_SENT|SCB_MSGOUT_SDTR)) !=
5032 (SCB_MSGOUT_SENT|SCB_MSGOUT_SDTR) )
5034 if (!(aic_dev->flags & DEVICE_DTR_SCANNED))
5037 * We shouldn't get here unless this is a narrow drive, wide
5038 * devices should trigger this same section of code in the WDTR
5039 * handler first instead.
5041 aic_dev->goal.width = MSG_EXT_WDTR_BUS_8_BIT;
5042 aic_dev->goal.options = 0;
5043 if(p->user[tindex].offset)
5045 aic_dev->needsdtr_copy = 1;
5046 aic_dev->goal.period = MAX(10,p->user[tindex].period);
5047 if(p->features & AHC_ULTRA2)
5049 aic_dev->goal.offset = MAX_OFFSET_ULTRA2;
5051 else
5053 aic_dev->goal.offset = MAX_OFFSET_8BIT;
5056 else
5058 aic_dev->needsdtr_copy = 0;
5059 aic_dev->goal.period = 255;
5060 aic_dev->goal.offset = 0;
5062 aic_dev->flags |= DEVICE_DTR_SCANNED | DEVICE_PRINT_DTR;
5064 else if (aic_dev->needsdtr_copy == 0)
5067 * This is a preemptive message from the target, we've already
5068 * scanned this target and set our options for it, and we
5069 * don't need a SDTR with this target (for whatever reason),
5070 * so reject this incoming SDTR
5072 reject = TRUE;
5073 break;
5076 /* The device is sending this message first and we have to reply */
5077 reply = TRUE;
5079 if (aic7xxx_verbose & VERBOSE_NEGOTIATION2)
5081 printk(INFO_LEAD "Received pre-emptive SDTR message from "
5082 "target.\n", p->host_no, CTL_OF_SCB(scb));
5085 * Validate the values the device passed to us against our SEEPROM
5086 * settings. We don't have to do this if we aren't replying since
5087 * the device isn't allowed to send values greater than the ones
5088 * we first sent to it.
5090 new_period = MAX(period, aic_dev->goal.period);
5091 new_offset = MIN(offset, aic_dev->goal.offset);
5095 * Use our new_period, new_offset, bus_width, and card options
5096 * to determine the actual syncrate settings
5098 syncrate = aic7xxx_find_syncrate(p, &new_period, maxsync,
5099 &trans_options);
5100 aic7xxx_validate_offset(p, syncrate, &new_offset, bus_width);
5103 * Did we drop to async? If so, send a reply regardless of whether
5104 * or not we initiated this negotiation.
5106 if ((new_offset == 0) && (new_offset != offset))
5108 aic_dev->needsdtr_copy = 0;
5109 reply = TRUE;
5113 * Did we start this, if not, or if we went too low and had to
5114 * go async, then send an SDTR back to the target
5116 if(reply)
5118 /* when sending a reply, make sure that the goal settings are
5119 * updated along with current and active since the code that
5120 * will actually build the message for the sequencer uses the
5121 * goal settings as its guidelines.
5123 aic7xxx_set_syncrate(p, syncrate, target, channel, new_period,
5124 new_offset, trans_options,
5125 AHC_TRANS_GOAL|AHC_TRANS_ACTIVE|AHC_TRANS_CUR,
5126 aic_dev);
5127 scb->flags &= ~SCB_MSGOUT_BITS;
5128 scb->flags |= SCB_MSGOUT_SDTR;
5129 aic_outb(p, HOST_MSG, MSG_OUT);
5130 aic_outb(p, aic_inb(p, SCSISIGO) | ATNO, SCSISIGO);
5132 else
5134 aic7xxx_set_syncrate(p, syncrate, target, channel, new_period,
5135 new_offset, trans_options,
5136 AHC_TRANS_ACTIVE|AHC_TRANS_CUR, aic_dev);
5137 aic_dev->needsdtr = 0;
5139 done = TRUE;
5140 break;
5142 case MSG_EXT_WDTR:
5145 if (p->msg_buf[1] != MSG_EXT_WDTR_LEN)
5147 reject = TRUE;
5148 break;
5151 if (p->msg_len < (MSG_EXT_WDTR_LEN + 2))
5153 break;
5156 bus_width = new_bus_width = p->msg_buf[3];
5158 if ( (scb->flags & (SCB_MSGOUT_SENT|SCB_MSGOUT_WDTR)) ==
5159 (SCB_MSGOUT_SENT|SCB_MSGOUT_WDTR) )
5161 switch(bus_width)
5163 default:
5165 reject = TRUE;
5166 if ( (aic7xxx_verbose & VERBOSE_NEGOTIATION2) &&
5167 ((aic_dev->flags & DEVICE_PRINT_DTR) ||
5168 (aic7xxx_verbose > 0xffff)) )
5170 printk(INFO_LEAD "Requesting %d bit transfers, rejecting.\n",
5171 p->host_no, CTL_OF_SCB(scb), 8 * (0x01 << bus_width));
5173 } /* We fall through on purpose */
5174 case MSG_EXT_WDTR_BUS_8_BIT:
5176 aic_dev->goal.width = MSG_EXT_WDTR_BUS_8_BIT;
5177 aic_dev->needwdtr_copy &= ~target_mask;
5178 break;
5180 case MSG_EXT_WDTR_BUS_16_BIT:
5182 break;
5185 aic_dev->needwdtr = 0;
5186 aic7xxx_set_width(p, target, channel, lun, new_bus_width,
5187 AHC_TRANS_ACTIVE|AHC_TRANS_CUR, aic_dev);
5189 else
5191 if ( !(aic_dev->flags & DEVICE_DTR_SCANNED) )
5194 * Well, we now know the WDTR and SYNC caps of this device since
5195 * it contacted us first, mark it as such and copy the user stuff
5196 * over to the goal stuff.
5198 if( (p->features & AHC_WIDE) && p->user[tindex].width )
5200 aic_dev->goal.width = MSG_EXT_WDTR_BUS_16_BIT;
5201 aic_dev->needwdtr_copy = 1;
5205 * Devices that support DT transfers don't start WDTR requests
5207 aic_dev->goal.options = 0;
5209 if(p->user[tindex].offset)
5211 aic_dev->needsdtr_copy = 1;
5212 aic_dev->goal.period = MAX(10,p->user[tindex].period);
5213 if(p->features & AHC_ULTRA2)
5215 aic_dev->goal.offset = MAX_OFFSET_ULTRA2;
5217 else if( aic_dev->goal.width )
5219 aic_dev->goal.offset = MAX_OFFSET_16BIT;
5221 else
5223 aic_dev->goal.offset = MAX_OFFSET_8BIT;
5225 } else {
5226 aic_dev->needsdtr_copy = 0;
5227 aic_dev->goal.period = 255;
5228 aic_dev->goal.offset = 0;
5231 aic_dev->flags |= DEVICE_DTR_SCANNED | DEVICE_PRINT_DTR;
5233 else if (aic_dev->needwdtr_copy == 0)
5236 * This is a preemptive message from the target, we've already
5237 * scanned this target and set our options for it, and we
5238 * don't need a WDTR with this target (for whatever reason),
5239 * so reject this incoming WDTR
5241 reject = TRUE;
5242 break;
5245 /* The device is sending this message first and we have to reply */
5246 reply = TRUE;
5248 if (aic7xxx_verbose & VERBOSE_NEGOTIATION2)
5250 printk(INFO_LEAD "Received pre-emptive WDTR message from "
5251 "target.\n", p->host_no, CTL_OF_SCB(scb));
5253 switch(bus_width)
5255 case MSG_EXT_WDTR_BUS_16_BIT:
5257 if ( (p->features & AHC_WIDE) &&
5258 (aic_dev->goal.width == MSG_EXT_WDTR_BUS_16_BIT) )
5260 new_bus_width = MSG_EXT_WDTR_BUS_16_BIT;
5261 break;
5263 } /* Fall through if we aren't a wide card */
5264 default:
5265 case MSG_EXT_WDTR_BUS_8_BIT:
5267 aic_dev->needwdtr_copy = 0;
5268 new_bus_width = MSG_EXT_WDTR_BUS_8_BIT;
5269 break;
5272 scb->flags &= ~SCB_MSGOUT_BITS;
5273 scb->flags |= SCB_MSGOUT_WDTR;
5274 aic_dev->needwdtr = 0;
5275 if(aic_dev->dtr_pending == 0)
5277 /* there is no other command with SCB_DTR_SCB already set that will
5278 * trigger the release of the dtr_pending bit. Both set the bit
5279 * and set scb->flags |= SCB_DTR_SCB
5281 aic_dev->dtr_pending = 1;
5282 scb->flags |= SCB_DTR_SCB;
5284 aic_outb(p, HOST_MSG, MSG_OUT);
5285 aic_outb(p, aic_inb(p, SCSISIGO) | ATNO, SCSISIGO);
5286 /* when sending a reply, make sure that the goal settings are
5287 * updated along with current and active since the code that
5288 * will actually build the message for the sequencer uses the
5289 * goal settings as its guidelines.
5291 aic7xxx_set_width(p, target, channel, lun, new_bus_width,
5292 AHC_TRANS_GOAL|AHC_TRANS_ACTIVE|AHC_TRANS_CUR,
5293 aic_dev);
5297 * By virtue of the SCSI spec, a WDTR message negates any existing
5298 * SDTR negotiations. So, even if needsdtr isn't marked for this
5299 * device, we still have to do a new SDTR message if the device
5300 * supports SDTR at all. Therefore, we check needsdtr_copy instead
5301 * of needstr.
5303 aic7xxx_set_syncrate(p, NULL, target, channel, 0, 0, 0,
5304 AHC_TRANS_ACTIVE|AHC_TRANS_CUR|AHC_TRANS_QUITE,
5305 aic_dev);
5306 aic_dev->needsdtr = aic_dev->needsdtr_copy;
5307 done = TRUE;
5308 break;
5310 case MSG_EXT_PPR:
5313 if (p->msg_buf[1] != MSG_EXT_PPR_LEN)
5315 reject = TRUE;
5316 break;
5319 if (p->msg_len < (MSG_EXT_PPR_LEN + 2))
5321 break;
5324 period = new_period = p->msg_buf[3];
5325 offset = new_offset = p->msg_buf[5];
5326 bus_width = new_bus_width = p->msg_buf[6];
5327 trans_options = new_trans_options = p->msg_buf[7] & 0xf;
5329 if(aic7xxx_verbose & VERBOSE_NEGOTIATION2)
5331 printk(INFO_LEAD "Parsing PPR message (%d/%d/%d/%d)\n",
5332 p->host_no, CTL_OF_SCB(scb), period, offset, bus_width,
5333 trans_options);
5337 * We might have a device that is starting negotiation with us
5338 * before we can start up negotiation with it....be prepared to
5339 * have a device ask for a higher speed then we want to give it
5340 * in that case
5342 if ( (scb->flags & (SCB_MSGOUT_SENT|SCB_MSGOUT_PPR)) !=
5343 (SCB_MSGOUT_SENT|SCB_MSGOUT_PPR) )
5345 /* Have we scanned the device yet? */
5346 if (!(aic_dev->flags & DEVICE_DTR_SCANNED))
5348 /* The device is electing to use PPR messages, so we will too until
5349 * we know better */
5350 aic_dev->needppr = aic_dev->needppr_copy = 1;
5351 aic_dev->needsdtr = aic_dev->needsdtr_copy = 0;
5352 aic_dev->needwdtr = aic_dev->needwdtr_copy = 0;
5354 /* We know the device is SCSI-3 compliant due to PPR */
5355 aic_dev->flags |= DEVICE_SCSI_3;
5358 * Not only is the device starting this up, but it also hasn't
5359 * been scanned yet, so this would likely be our TUR or our
5360 * INQUIRY command at scan time, so we need to use the
5361 * settings from the SEEPROM if they existed. Of course, even
5362 * if we didn't find a SEEPROM, we stuffed default values into
5363 * the user settings anyway, so use those in all cases.
5365 aic_dev->goal.width = p->user[tindex].width;
5366 if(p->user[tindex].offset)
5368 aic_dev->goal.period = p->user[tindex].period;
5369 aic_dev->goal.options = p->user[tindex].options;
5370 if(p->features & AHC_ULTRA2)
5372 aic_dev->goal.offset = MAX_OFFSET_ULTRA2;
5374 else if( aic_dev->goal.width &&
5375 (bus_width == MSG_EXT_WDTR_BUS_16_BIT) &&
5376 p->features & AHC_WIDE )
5378 aic_dev->goal.offset = MAX_OFFSET_16BIT;
5380 else
5382 aic_dev->goal.offset = MAX_OFFSET_8BIT;
5385 else
5387 aic_dev->goal.period = 255;
5388 aic_dev->goal.offset = 0;
5389 aic_dev->goal.options = 0;
5391 aic_dev->flags |= DEVICE_DTR_SCANNED | DEVICE_PRINT_DTR;
5393 else if (aic_dev->needppr_copy == 0)
5396 * This is a preemptive message from the target, we've already
5397 * scanned this target and set our options for it, and we
5398 * don't need a PPR with this target (for whatever reason),
5399 * so reject this incoming PPR
5401 reject = TRUE;
5402 break;
5405 /* The device is sending this message first and we have to reply */
5406 reply = TRUE;
5408 if (aic7xxx_verbose & VERBOSE_NEGOTIATION2)
5410 printk(INFO_LEAD "Received pre-emptive PPR message from "
5411 "target.\n", p->host_no, CTL_OF_SCB(scb));
5416 switch(bus_width)
5418 case MSG_EXT_WDTR_BUS_16_BIT:
5420 if ( (aic_dev->goal.width == MSG_EXT_WDTR_BUS_16_BIT) &&
5421 p->features & AHC_WIDE)
5423 break;
5426 default:
5428 if ( (aic7xxx_verbose & VERBOSE_NEGOTIATION2) &&
5429 ((aic_dev->flags & DEVICE_PRINT_DTR) ||
5430 (aic7xxx_verbose > 0xffff)) )
5432 reply = TRUE;
5433 printk(INFO_LEAD "Requesting %d bit transfers, rejecting.\n",
5434 p->host_no, CTL_OF_SCB(scb), 8 * (0x01 << bus_width));
5436 } /* We fall through on purpose */
5437 case MSG_EXT_WDTR_BUS_8_BIT:
5440 * According to the spec, if we aren't wide, we also can't be
5441 * Dual Edge so clear the options byte
5443 new_trans_options = 0;
5444 new_bus_width = MSG_EXT_WDTR_BUS_8_BIT;
5445 break;
5449 if(reply)
5451 /* when sending a reply, make sure that the goal settings are
5452 * updated along with current and active since the code that
5453 * will actually build the message for the sequencer uses the
5454 * goal settings as its guidelines.
5456 aic7xxx_set_width(p, target, channel, lun, new_bus_width,
5457 AHC_TRANS_GOAL|AHC_TRANS_ACTIVE|AHC_TRANS_CUR,
5458 aic_dev);
5459 syncrate = aic7xxx_find_syncrate(p, &new_period, maxsync,
5460 &new_trans_options);
5461 aic7xxx_validate_offset(p, syncrate, &new_offset, new_bus_width);
5462 aic7xxx_set_syncrate(p, syncrate, target, channel, new_period,
5463 new_offset, new_trans_options,
5464 AHC_TRANS_GOAL|AHC_TRANS_ACTIVE|AHC_TRANS_CUR,
5465 aic_dev);
5467 else
5469 aic7xxx_set_width(p, target, channel, lun, new_bus_width,
5470 AHC_TRANS_ACTIVE|AHC_TRANS_CUR, aic_dev);
5471 syncrate = aic7xxx_find_syncrate(p, &new_period, maxsync,
5472 &new_trans_options);
5473 aic7xxx_validate_offset(p, syncrate, &new_offset, new_bus_width);
5474 aic7xxx_set_syncrate(p, syncrate, target, channel, new_period,
5475 new_offset, new_trans_options,
5476 AHC_TRANS_ACTIVE|AHC_TRANS_CUR, aic_dev);
5480 * As it turns out, if we don't *have* to have PPR messages, then
5481 * configure ourselves not to use them since that makes some
5482 * external drive chassis work (those chassis can't parse PPR
5483 * messages and they mangle the SCSI bus until you send a WDTR
5484 * and SDTR that they can understand).
5486 if(new_trans_options == 0)
5488 aic_dev->needppr = aic_dev->needppr_copy = 0;
5489 if(new_offset)
5491 aic_dev->needsdtr = aic_dev->needsdtr_copy = 1;
5493 if (new_bus_width)
5495 aic_dev->needwdtr = aic_dev->needwdtr_copy = 1;
5499 if((new_offset == 0) && (offset != 0))
5502 * Oops, the syncrate went to low for this card and we fell off
5503 * to async (should never happen with a device that uses PPR
5504 * messages, but have to be complete)
5506 reply = TRUE;
5509 if(reply)
5511 scb->flags &= ~SCB_MSGOUT_BITS;
5512 scb->flags |= SCB_MSGOUT_PPR;
5513 aic_outb(p, HOST_MSG, MSG_OUT);
5514 aic_outb(p, aic_inb(p, SCSISIGO) | ATNO, SCSISIGO);
5516 else
5518 aic_dev->needppr = 0;
5520 done = TRUE;
5521 break;
5523 default:
5525 reject = TRUE;
5526 break;
5528 } /* end of switch(p->msg_type) */
5529 } /* end of if (!reject && (p->msg_len > 2)) */
5531 if (!reply && reject)
5533 aic_outb(p, MSG_MESSAGE_REJECT, MSG_OUT);
5534 aic_outb(p, aic_inb(p, SCSISIGO) | ATNO, SCSISIGO);
5535 done = TRUE;
5537 return(done);
5541 /*+F*************************************************************************
5542 * Function:
5543 * aic7xxx_handle_reqinit
5545 * Description:
5546 * Interrupt handler for REQINIT interrupts (used to transfer messages to
5547 * and from devices).
5548 *_F*************************************************************************/
5549 static void
5550 aic7xxx_handle_reqinit(struct aic7xxx_host *p, struct aic7xxx_scb *scb)
5552 unsigned char lastbyte;
5553 unsigned char phasemis;
5554 int done = FALSE;
5556 switch(p->msg_type)
5558 case MSG_TYPE_INITIATOR_MSGOUT:
5560 if (p->msg_len == 0)
5561 panic("aic7xxx: REQINIT with no active message!\n");
5563 lastbyte = (p->msg_index == (p->msg_len - 1));
5564 phasemis = ( aic_inb(p, SCSISIGI) & PHASE_MASK) != P_MESGOUT;
5566 if (lastbyte || phasemis)
5568 /* Time to end the message */
5569 p->msg_len = 0;
5570 p->msg_type = MSG_TYPE_NONE;
5572 * NOTE-TO-MYSELF: If you clear the REQINIT after you
5573 * disable REQINITs, then cases of REJECT_MSG stop working
5574 * and hang the bus
5576 aic_outb(p, aic_inb(p, SIMODE1) & ~ENREQINIT, SIMODE1);
5577 aic_outb(p, CLRSCSIINT, CLRINT);
5578 p->flags &= ~AHC_HANDLING_REQINITS;
5580 if (phasemis == 0)
5582 aic_outb(p, p->msg_buf[p->msg_index], SINDEX);
5583 aic_outb(p, 0, RETURN_1);
5584 #ifdef AIC7XXX_VERBOSE_DEBUGGING
5585 if (aic7xxx_verbose > 0xffff)
5586 printk(INFO_LEAD "Completed sending of REQINIT message.\n",
5587 p->host_no, CTL_OF_SCB(scb));
5588 #endif
5590 else
5592 aic_outb(p, MSGOUT_PHASEMIS, RETURN_1);
5593 #ifdef AIC7XXX_VERBOSE_DEBUGGING
5594 if (aic7xxx_verbose > 0xffff)
5595 printk(INFO_LEAD "PHASEMIS while sending REQINIT message.\n",
5596 p->host_no, CTL_OF_SCB(scb));
5597 #endif
5599 unpause_sequencer(p, TRUE);
5601 else
5604 * Present the byte on the bus (clearing REQINIT) but don't
5605 * unpause the sequencer.
5607 aic_outb(p, CLRREQINIT, CLRSINT1);
5608 aic_outb(p, CLRSCSIINT, CLRINT);
5609 aic_outb(p, p->msg_buf[p->msg_index++], SCSIDATL);
5611 break;
5613 case MSG_TYPE_INITIATOR_MSGIN:
5615 phasemis = ( aic_inb(p, SCSISIGI) & PHASE_MASK ) != P_MESGIN;
5617 if (phasemis == 0)
5619 p->msg_len++;
5620 /* Pull the byte in without acking it */
5621 p->msg_buf[p->msg_index] = aic_inb(p, SCSIBUSL);
5622 done = aic7xxx_parse_msg(p, scb);
5623 /* Ack the byte */
5624 aic_outb(p, CLRREQINIT, CLRSINT1);
5625 aic_outb(p, CLRSCSIINT, CLRINT);
5626 aic_inb(p, SCSIDATL);
5627 p->msg_index++;
5629 if (phasemis || done)
5631 #ifdef AIC7XXX_VERBOSE_DEBUGGING
5632 if (aic7xxx_verbose > 0xffff)
5634 if (phasemis)
5635 printk(INFO_LEAD "PHASEMIS while receiving REQINIT message.\n",
5636 p->host_no, CTL_OF_SCB(scb));
5637 else
5638 printk(INFO_LEAD "Completed receipt of REQINIT message.\n",
5639 p->host_no, CTL_OF_SCB(scb));
5641 #endif
5642 /* Time to end our message session */
5643 p->msg_len = 0;
5644 p->msg_type = MSG_TYPE_NONE;
5645 aic_outb(p, aic_inb(p, SIMODE1) & ~ENREQINIT, SIMODE1);
5646 aic_outb(p, CLRSCSIINT, CLRINT);
5647 p->flags &= ~AHC_HANDLING_REQINITS;
5648 unpause_sequencer(p, TRUE);
5650 break;
5652 default:
5654 panic("aic7xxx: Unknown REQINIT message type.\n");
5655 break;
5657 } /* End of switch(p->msg_type) */
5660 /*+F*************************************************************************
5661 * Function:
5662 * aic7xxx_handle_scsiint
5664 * Description:
5665 * Interrupt handler for SCSI interrupts (SCSIINT).
5666 *-F*************************************************************************/
5667 static void
5668 aic7xxx_handle_scsiint(struct aic7xxx_host *p, unsigned char intstat)
5670 unsigned char scb_index;
5671 unsigned char status;
5672 struct aic7xxx_scb *scb;
5673 struct aic_dev_data *aic_dev;
5675 scb_index = aic_inb(p, SCB_TAG);
5676 status = aic_inb(p, SSTAT1);
5678 if (scb_index < p->scb_data->numscbs)
5680 scb = p->scb_data->scb_array[scb_index];
5681 if ((scb->flags & SCB_ACTIVE) == 0)
5683 scb = NULL;
5686 else
5688 scb = NULL;
5692 if ((status & SCSIRSTI) != 0)
5694 int channel;
5696 if ( (p->chip & AHC_CHIPID_MASK) == AHC_AIC7770 )
5697 channel = (aic_inb(p, SBLKCTL) & SELBUSB) >> 3;
5698 else
5699 channel = 0;
5701 if (aic7xxx_verbose & VERBOSE_RESET)
5702 printk(WARN_LEAD "Someone else reset the channel!!\n",
5703 p->host_no, channel, -1, -1);
5704 if (aic7xxx_panic_on_abort)
5705 aic7xxx_panic_abort(p, NULL);
5707 * Go through and abort all commands for the channel, but do not
5708 * reset the channel again.
5710 aic7xxx_reset_channel(p, channel, /* Initiate Reset */ FALSE);
5711 aic7xxx_run_done_queue(p, TRUE);
5712 scb = NULL;
5714 else if ( ((status & BUSFREE) != 0) && ((status & SELTO) == 0) )
5717 * First look at what phase we were last in. If it's message-out,
5718 * chances are pretty good that the bus free was in response to
5719 * one of our abort requests.
5721 unsigned char lastphase = aic_inb(p, LASTPHASE);
5722 unsigned char saved_tcl = aic_inb(p, SAVED_TCL);
5723 unsigned char target = (saved_tcl >> 4) & 0x0F;
5724 int channel;
5725 int printerror = TRUE;
5727 if ( (p->chip & AHC_CHIPID_MASK) == AHC_AIC7770 )
5728 channel = (aic_inb(p, SBLKCTL) & SELBUSB) >> 3;
5729 else
5730 channel = 0;
5732 aic_outb(p, aic_inb(p, SCSISEQ) & (ENSELI|ENRSELI|ENAUTOATNP),
5733 SCSISEQ);
5734 if (lastphase == P_MESGOUT)
5736 unsigned char message;
5738 message = aic_inb(p, SINDEX);
5740 if ((message == MSG_ABORT) || (message == MSG_ABORT_TAG))
5742 if (aic7xxx_verbose & VERBOSE_ABORT_PROCESS)
5743 printk(INFO_LEAD "SCB %d abort delivered.\n", p->host_no,
5744 CTL_OF_SCB(scb), scb->hscb->tag);
5745 aic7xxx_reset_device(p, target, channel, ALL_LUNS,
5746 (message == MSG_ABORT) ? SCB_LIST_NULL : scb->hscb->tag );
5747 aic7xxx_run_done_queue(p, TRUE);
5748 scb = NULL;
5749 printerror = 0;
5751 else if (message == MSG_BUS_DEV_RESET)
5753 aic7xxx_handle_device_reset(p, target, channel);
5754 scb = NULL;
5755 printerror = 0;
5758 if ( (scb != NULL) && (scb->flags & SCB_DTR_SCB) )
5761 * Hmmm...error during a negotiation command. Either we have a
5762 * borken bus, or the device doesn't like our negotiation message.
5763 * Since we check the INQUIRY data of a device before sending it
5764 * negotiation messages, assume the bus is borken for whatever
5765 * reason. Complete the command.
5767 printerror = 0;
5768 aic7xxx_reset_device(p, target, channel, ALL_LUNS, scb->hscb->tag);
5769 aic7xxx_run_done_queue(p, TRUE);
5770 scb = NULL;
5772 if (printerror != 0)
5774 if (scb != NULL)
5776 unsigned char tag;
5778 if ((scb->hscb->control & TAG_ENB) != 0)
5780 tag = scb->hscb->tag;
5782 else
5784 tag = SCB_LIST_NULL;
5786 aic7xxx_reset_device(p, target, channel, ALL_LUNS, tag);
5787 aic7xxx_run_done_queue(p, TRUE);
5789 else
5791 aic7xxx_reset_device(p, target, channel, ALL_LUNS, SCB_LIST_NULL);
5792 aic7xxx_run_done_queue(p, TRUE);
5794 printk(INFO_LEAD "Unexpected busfree, LASTPHASE = 0x%x, "
5795 "SEQADDR = 0x%x\n", p->host_no, channel, target, -1, lastphase,
5796 (aic_inb(p, SEQADDR1) << 8) | aic_inb(p, SEQADDR0));
5797 scb = NULL;
5799 aic_outb(p, MSG_NOOP, MSG_OUT);
5800 aic_outb(p, aic_inb(p, SIMODE1) & ~(ENBUSFREE|ENREQINIT),
5801 SIMODE1);
5802 p->flags &= ~AHC_HANDLING_REQINITS;
5803 aic_outb(p, CLRBUSFREE, CLRSINT1);
5804 aic_outb(p, CLRSCSIINT, CLRINT);
5805 restart_sequencer(p);
5806 unpause_sequencer(p, TRUE);
5808 else if ((status & SELTO) != 0)
5810 unsigned char scbptr;
5811 unsigned char nextscb;
5812 Scsi_Cmnd *cmd;
5814 scbptr = aic_inb(p, WAITING_SCBH);
5815 if (scbptr > p->scb_data->maxhscbs)
5818 * I'm still trying to track down exactly how this happens, but until
5819 * I find it, this code will make sure we aren't passing bogus values
5820 * into the SCBPTR register, even if that register will just wrap
5821 * things around, we still don't like having out of range variables.
5823 * NOTE: Don't check the aic7xxx_verbose variable, I want this message
5824 * to always be displayed.
5826 printk(INFO_LEAD "Invalid WAITING_SCBH value %d, improvising.\n",
5827 p->host_no, -1, -1, -1, scbptr);
5828 if (p->scb_data->maxhscbs > 4)
5829 scbptr &= (p->scb_data->maxhscbs - 1);
5830 else
5831 scbptr &= 0x03;
5833 aic_outb(p, scbptr, SCBPTR);
5834 scb_index = aic_inb(p, SCB_TAG);
5836 scb = NULL;
5837 if (scb_index < p->scb_data->numscbs)
5839 scb = p->scb_data->scb_array[scb_index];
5840 if ((scb->flags & SCB_ACTIVE) == 0)
5842 scb = NULL;
5845 if (scb == NULL)
5847 printk(WARN_LEAD "Referenced SCB %d not valid during SELTO.\n",
5848 p->host_no, -1, -1, -1, scb_index);
5849 printk(KERN_WARNING " SCSISEQ = 0x%x SEQADDR = 0x%x SSTAT0 = 0x%x "
5850 "SSTAT1 = 0x%x\n", aic_inb(p, SCSISEQ),
5851 aic_inb(p, SEQADDR0) | (aic_inb(p, SEQADDR1) << 8),
5852 aic_inb(p, SSTAT0), aic_inb(p, SSTAT1));
5853 if (aic7xxx_panic_on_abort)
5854 aic7xxx_panic_abort(p, NULL);
5856 else
5858 cmd = scb->cmd;
5859 cmd->result = (DID_TIME_OUT << 16);
5862 * Clear out this hardware SCB
5864 aic_outb(p, 0, SCB_CONTROL);
5867 * Clear out a few values in the card that are in an undetermined
5868 * state.
5870 aic_outb(p, MSG_NOOP, MSG_OUT);
5873 * Shift the waiting for selection queue forward
5875 nextscb = aic_inb(p, SCB_NEXT);
5876 aic_outb(p, nextscb, WAITING_SCBH);
5879 * Put this SCB back on the free list.
5881 aic7xxx_add_curscb_to_free_list(p);
5882 #ifdef AIC7XXX_VERBOSE_DEBUGGING
5883 if (aic7xxx_verbose > 0xffff)
5884 printk(INFO_LEAD "Selection Timeout.\n", p->host_no, CTL_OF_SCB(scb));
5885 #endif
5886 if (scb->flags & SCB_QUEUED_ABORT)
5889 * We know that this particular SCB had to be the queued abort since
5890 * the disconnected SCB would have gotten a reconnect instead.
5891 * What we need to do then is to let the command timeout again so
5892 * we get a reset since this abort just failed.
5894 cmd->result = 0;
5895 scb = NULL;
5899 * Keep the sequencer from trying to restart any selections
5901 aic_outb(p, aic_inb(p, SCSISEQ) & ~ENSELO, SCSISEQ);
5903 * Make sure the data bits on the bus are released
5904 * Don't do this on 7770 chipsets, it makes them give us
5905 * a BRKADDRINT and kills the card.
5907 if( (p->chip & ~AHC_CHIPID_MASK) == AHC_PCI )
5908 aic_outb(p, 0, SCSIBUSL);
5911 * Delay for the selection timeout delay period then stop the selection
5913 udelay(301);
5914 aic_outb(p, CLRSELINGO, CLRSINT0);
5916 * Clear out all the interrupt status bits
5918 aic_outb(p, aic_inb(p, SIMODE1) & ~(ENREQINIT|ENBUSFREE), SIMODE1);
5919 p->flags &= ~AHC_HANDLING_REQINITS;
5920 aic_outb(p, CLRSELTIMEO | CLRBUSFREE, CLRSINT1);
5921 aic_outb(p, CLRSCSIINT, CLRINT);
5923 * Restarting the sequencer will stop the selection and make sure devices
5924 * are allowed to reselect in.
5926 restart_sequencer(p);
5927 unpause_sequencer(p, TRUE);
5929 else if (scb == NULL)
5931 printk(WARN_LEAD "aic7xxx_isr - referenced scb not valid "
5932 "during scsiint 0x%x scb(%d)\n"
5933 " SIMODE0 0x%x, SIMODE1 0x%x, SSTAT0 0x%x, SEQADDR 0x%x\n",
5934 p->host_no, -1, -1, -1, status, scb_index, aic_inb(p, SIMODE0),
5935 aic_inb(p, SIMODE1), aic_inb(p, SSTAT0),
5936 (aic_inb(p, SEQADDR1) << 8) | aic_inb(p, SEQADDR0));
5938 * Turn off the interrupt and set status to zero, so that it
5939 * falls through the rest of the SCSIINT code.
5941 aic_outb(p, status, CLRSINT1);
5942 aic_outb(p, CLRSCSIINT, CLRINT);
5943 unpause_sequencer(p, /* unpause always */ TRUE);
5944 scb = NULL;
5946 else if (status & SCSIPERR)
5949 * Determine the bus phase and queue an appropriate message.
5951 char *phase;
5952 Scsi_Cmnd *cmd;
5953 unsigned char mesg_out = MSG_NOOP;
5954 unsigned char lastphase = aic_inb(p, LASTPHASE);
5955 unsigned char sstat2 = aic_inb(p, SSTAT2);
5957 cmd = scb->cmd;
5958 switch (lastphase)
5960 case P_DATAOUT:
5961 phase = "Data-Out";
5962 break;
5963 case P_DATAIN:
5964 phase = "Data-In";
5965 mesg_out = MSG_INITIATOR_DET_ERR;
5966 break;
5967 case P_COMMAND:
5968 phase = "Command";
5969 break;
5970 case P_MESGOUT:
5971 phase = "Message-Out";
5972 break;
5973 case P_STATUS:
5974 phase = "Status";
5975 mesg_out = MSG_INITIATOR_DET_ERR;
5976 break;
5977 case P_MESGIN:
5978 phase = "Message-In";
5979 mesg_out = MSG_PARITY_ERROR;
5980 break;
5981 default:
5982 phase = "unknown";
5983 break;
5987 * A parity error has occurred during a data
5988 * transfer phase. Flag it and continue.
5990 if( (p->features & AHC_ULTRA3) &&
5991 (aic_inb(p, SCSIRATE) & AHC_SYNCRATE_CRC) &&
5992 (lastphase == P_DATAIN) )
5994 printk(WARN_LEAD "CRC error during %s phase.\n",
5995 p->host_no, CTL_OF_SCB(scb), phase);
5996 if(sstat2 & CRCVALERR)
5998 printk(WARN_LEAD " CRC error in intermediate CRC packet.\n",
5999 p->host_no, CTL_OF_SCB(scb));
6001 if(sstat2 & CRCENDERR)
6003 printk(WARN_LEAD " CRC error in ending CRC packet.\n",
6004 p->host_no, CTL_OF_SCB(scb));
6006 if(sstat2 & CRCREQERR)
6008 printk(WARN_LEAD " Target incorrectly requested a CRC packet.\n",
6009 p->host_no, CTL_OF_SCB(scb));
6011 if(sstat2 & DUAL_EDGE_ERROR)
6013 printk(WARN_LEAD " Dual Edge transmission error.\n",
6014 p->host_no, CTL_OF_SCB(scb));
6017 else if( (lastphase == P_MESGOUT) &&
6018 (scb->flags & SCB_MSGOUT_PPR) )
6021 * As per the draft specs, any device capable of supporting any of
6022 * the option values other than 0 are not allowed to reject the
6023 * PPR message. Instead, they must negotiate out what they do
6024 * support instead of rejecting our offering or else they cause
6025 * a parity error during msg_out phase to signal that they don't
6026 * like our settings.
6028 aic_dev = AIC_DEV(scb->cmd);
6029 aic_dev->needppr = aic_dev->needppr_copy = 0;
6030 aic7xxx_set_width(p, scb->cmd->device->id, scb->cmd->device->channel, scb->cmd->device->lun,
6031 MSG_EXT_WDTR_BUS_8_BIT,
6032 (AHC_TRANS_ACTIVE|AHC_TRANS_CUR|AHC_TRANS_QUITE),
6033 aic_dev);
6034 aic7xxx_set_syncrate(p, NULL, scb->cmd->device->id, scb->cmd->device->channel, 0, 0,
6035 0, AHC_TRANS_ACTIVE|AHC_TRANS_CUR|AHC_TRANS_QUITE,
6036 aic_dev);
6037 aic_dev->goal.options = 0;
6038 scb->flags &= ~SCB_MSGOUT_BITS;
6039 if(aic7xxx_verbose & VERBOSE_NEGOTIATION2)
6041 printk(INFO_LEAD "parity error during PPR message, reverting "
6042 "to WDTR/SDTR\n", p->host_no, CTL_OF_SCB(scb));
6044 if ( aic_dev->goal.width )
6046 aic_dev->needwdtr = aic_dev->needwdtr_copy = 1;
6048 if ( aic_dev->goal.offset )
6050 if( aic_dev->goal.period <= 9 )
6052 aic_dev->goal.period = 10;
6054 aic_dev->needsdtr = aic_dev->needsdtr_copy = 1;
6056 scb = NULL;
6060 * We've set the hardware to assert ATN if we get a parity
6061 * error on "in" phases, so all we need to do is stuff the
6062 * message buffer with the appropriate message. "In" phases
6063 * have set mesg_out to something other than MSG_NOP.
6065 if (mesg_out != MSG_NOOP)
6067 aic_outb(p, mesg_out, MSG_OUT);
6068 aic_outb(p, aic_inb(p, SCSISIGI) | ATNO, SCSISIGO);
6069 scb = NULL;
6071 aic_outb(p, CLRSCSIPERR, CLRSINT1);
6072 aic_outb(p, CLRSCSIINT, CLRINT);
6073 unpause_sequencer(p, /* unpause_always */ TRUE);
6075 else if ( (status & REQINIT) &&
6076 (p->flags & AHC_HANDLING_REQINITS) )
6078 #ifdef AIC7XXX_VERBOSE_DEBUGGING
6079 if (aic7xxx_verbose > 0xffff)
6080 printk(INFO_LEAD "Handling REQINIT, SSTAT1=0x%x.\n", p->host_no,
6081 CTL_OF_SCB(scb), aic_inb(p, SSTAT1));
6082 #endif
6083 aic7xxx_handle_reqinit(p, scb);
6084 return;
6086 else
6089 * We don't know what's going on. Turn off the
6090 * interrupt source and try to continue.
6092 if (aic7xxx_verbose & VERBOSE_SCSIINT)
6093 printk(INFO_LEAD "Unknown SCSIINT status, SSTAT1(0x%x).\n",
6094 p->host_no, -1, -1, -1, status);
6095 aic_outb(p, status, CLRSINT1);
6096 aic_outb(p, CLRSCSIINT, CLRINT);
6097 unpause_sequencer(p, /* unpause always */ TRUE);
6098 scb = NULL;
6100 if (scb != NULL)
6102 aic7xxx_done(p, scb);
6106 #ifdef AIC7XXX_VERBOSE_DEBUGGING
6107 static void
6108 aic7xxx_check_scbs(struct aic7xxx_host *p, char *buffer)
6110 unsigned char saved_scbptr, free_scbh, dis_scbh, wait_scbh, temp;
6111 int i, bogus, lost;
6112 static unsigned char scb_status[AIC7XXX_MAXSCB];
6114 #define SCB_NO_LIST 0
6115 #define SCB_FREE_LIST 1
6116 #define SCB_WAITING_LIST 2
6117 #define SCB_DISCONNECTED_LIST 4
6118 #define SCB_CURRENTLY_ACTIVE 8
6121 * Note, these checks will fail on a regular basis once the machine moves
6122 * beyond the bus scan phase. The problem is race conditions concerning
6123 * the scbs and where they are linked in. When you have 30 or so commands
6124 * outstanding on the bus, and run this twice with every interrupt, the
6125 * chances get pretty good that you'll catch the sequencer with an SCB
6126 * only partially linked in. Therefore, once we pass the scan phase
6127 * of the bus, we really should disable this function.
6129 bogus = FALSE;
6130 memset(&scb_status[0], 0, sizeof(scb_status));
6131 pause_sequencer(p);
6132 saved_scbptr = aic_inb(p, SCBPTR);
6133 if (saved_scbptr >= p->scb_data->maxhscbs)
6135 printk("Bogus SCBPTR %d\n", saved_scbptr);
6136 bogus = TRUE;
6138 scb_status[saved_scbptr] = SCB_CURRENTLY_ACTIVE;
6139 free_scbh = aic_inb(p, FREE_SCBH);
6140 if ( (free_scbh != SCB_LIST_NULL) &&
6141 (free_scbh >= p->scb_data->maxhscbs) )
6143 printk("Bogus FREE_SCBH %d\n", free_scbh);
6144 bogus = TRUE;
6146 else
6148 temp = free_scbh;
6149 while( (temp != SCB_LIST_NULL) && (temp < p->scb_data->maxhscbs) )
6151 if(scb_status[temp] & 0x07)
6153 printk("HSCB %d on multiple lists, status 0x%02x", temp,
6154 scb_status[temp] | SCB_FREE_LIST);
6155 bogus = TRUE;
6157 scb_status[temp] |= SCB_FREE_LIST;
6158 aic_outb(p, temp, SCBPTR);
6159 temp = aic_inb(p, SCB_NEXT);
6163 dis_scbh = aic_inb(p, DISCONNECTED_SCBH);
6164 if ( (dis_scbh != SCB_LIST_NULL) &&
6165 (dis_scbh >= p->scb_data->maxhscbs) )
6167 printk("Bogus DISCONNECTED_SCBH %d\n", dis_scbh);
6168 bogus = TRUE;
6170 else
6172 temp = dis_scbh;
6173 while( (temp != SCB_LIST_NULL) && (temp < p->scb_data->maxhscbs) )
6175 if(scb_status[temp] & 0x07)
6177 printk("HSCB %d on multiple lists, status 0x%02x", temp,
6178 scb_status[temp] | SCB_DISCONNECTED_LIST);
6179 bogus = TRUE;
6181 scb_status[temp] |= SCB_DISCONNECTED_LIST;
6182 aic_outb(p, temp, SCBPTR);
6183 temp = aic_inb(p, SCB_NEXT);
6187 wait_scbh = aic_inb(p, WAITING_SCBH);
6188 if ( (wait_scbh != SCB_LIST_NULL) &&
6189 (wait_scbh >= p->scb_data->maxhscbs) )
6191 printk("Bogus WAITING_SCBH %d\n", wait_scbh);
6192 bogus = TRUE;
6194 else
6196 temp = wait_scbh;
6197 while( (temp != SCB_LIST_NULL) && (temp < p->scb_data->maxhscbs) )
6199 if(scb_status[temp] & 0x07)
6201 printk("HSCB %d on multiple lists, status 0x%02x", temp,
6202 scb_status[temp] | SCB_WAITING_LIST);
6203 bogus = TRUE;
6205 scb_status[temp] |= SCB_WAITING_LIST;
6206 aic_outb(p, temp, SCBPTR);
6207 temp = aic_inb(p, SCB_NEXT);
6211 lost=0;
6212 for(i=0; i < p->scb_data->maxhscbs; i++)
6214 aic_outb(p, i, SCBPTR);
6215 temp = aic_inb(p, SCB_NEXT);
6216 if ( ((temp != SCB_LIST_NULL) &&
6217 (temp >= p->scb_data->maxhscbs)) )
6219 printk("HSCB %d bad, SCB_NEXT invalid(%d).\n", i, temp);
6220 bogus = TRUE;
6222 if ( temp == i )
6224 printk("HSCB %d bad, SCB_NEXT points to self.\n", i);
6225 bogus = TRUE;
6227 if (scb_status[i] == 0)
6228 lost++;
6229 if (lost > 1)
6231 printk("Too many lost scbs.\n");
6232 bogus=TRUE;
6235 aic_outb(p, saved_scbptr, SCBPTR);
6236 unpause_sequencer(p, FALSE);
6237 if (bogus)
6239 printk("Bogus parameters found in card SCB array structures.\n");
6240 printk("%s\n", buffer);
6241 aic7xxx_panic_abort(p, NULL);
6243 return;
6245 #endif
6248 /*+F*************************************************************************
6249 * Function:
6250 * aic7xxx_handle_command_completion_intr
6252 * Description:
6253 * SCSI command completion interrupt handler.
6254 *-F*************************************************************************/
6255 static void
6256 aic7xxx_handle_command_completion_intr(struct aic7xxx_host *p)
6258 struct aic7xxx_scb *scb = NULL;
6259 struct aic_dev_data *aic_dev;
6260 Scsi_Cmnd *cmd;
6261 unsigned char scb_index, tindex;
6263 #ifdef AIC7XXX_VERBOSE_DEBUGGING
6264 if( (p->isr_count < 16) && (aic7xxx_verbose > 0xffff) )
6265 printk(INFO_LEAD "Command Complete Int.\n", p->host_no, -1, -1, -1);
6266 #endif
6269 * Read the INTSTAT location after clearing the CMDINT bit. This forces
6270 * any posted PCI writes to flush to memory. Gerard Roudier suggested
6271 * this fix to the possible race of clearing the CMDINT bit but not
6272 * having all command bytes flushed onto the qoutfifo.
6274 aic_outb(p, CLRCMDINT, CLRINT);
6275 aic_inb(p, INTSTAT);
6277 * The sequencer will continue running when it
6278 * issues this interrupt. There may be >1 commands
6279 * finished, so loop until we've processed them all.
6282 while (p->qoutfifo[p->qoutfifonext] != SCB_LIST_NULL)
6284 scb_index = p->qoutfifo[p->qoutfifonext];
6285 p->qoutfifo[p->qoutfifonext++] = SCB_LIST_NULL;
6286 if ( scb_index >= p->scb_data->numscbs )
6288 printk(WARN_LEAD "CMDCMPLT with invalid SCB index %d\n", p->host_no,
6289 -1, -1, -1, scb_index);
6290 continue;
6292 scb = p->scb_data->scb_array[scb_index];
6293 if (!(scb->flags & SCB_ACTIVE) || (scb->cmd == NULL))
6295 printk(WARN_LEAD "CMDCMPLT without command for SCB %d, SCB flags "
6296 "0x%x, cmd 0x%lx\n", p->host_no, -1, -1, -1, scb_index, scb->flags,
6297 (unsigned long) scb->cmd);
6298 continue;
6300 tindex = TARGET_INDEX(scb->cmd);
6301 aic_dev = AIC_DEV(scb->cmd);
6302 if (scb->flags & SCB_QUEUED_ABORT)
6304 pause_sequencer(p);
6305 if ( ((aic_inb(p, LASTPHASE) & PHASE_MASK) != P_BUSFREE) &&
6306 (aic_inb(p, SCB_TAG) == scb->hscb->tag) )
6308 unpause_sequencer(p, FALSE);
6309 continue;
6311 aic7xxx_reset_device(p, scb->cmd->device->id, scb->cmd->device->channel,
6312 scb->cmd->device->lun, scb->hscb->tag);
6313 scb->flags &= ~(SCB_QUEUED_FOR_DONE | SCB_RESET | SCB_ABORT |
6314 SCB_QUEUED_ABORT);
6315 unpause_sequencer(p, FALSE);
6317 else if (scb->flags & SCB_ABORT)
6320 * We started to abort this, but it completed on us, let it
6321 * through as successful
6323 scb->flags &= ~(SCB_ABORT|SCB_RESET);
6325 else if (scb->flags & SCB_SENSE)
6327 char *buffer = &scb->cmd->sense_buffer[0];
6329 if (buffer[12] == 0x47 || buffer[12] == 0x54)
6332 * Signal that we need to re-negotiate things.
6334 aic_dev->needppr = aic_dev->needppr_copy;
6335 aic_dev->needsdtr = aic_dev->needsdtr_copy;
6336 aic_dev->needwdtr = aic_dev->needwdtr_copy;
6339 cmd = scb->cmd;
6340 if (scb->hscb->residual_SG_segment_count != 0)
6342 aic7xxx_calculate_residual(p, scb);
6344 cmd->result |= (aic7xxx_error(cmd) << 16);
6345 aic7xxx_done(p, scb);
6349 /*+F*************************************************************************
6350 * Function:
6351 * aic7xxx_isr
6353 * Description:
6354 * SCSI controller interrupt handler.
6355 *-F*************************************************************************/
6356 static void
6357 aic7xxx_isr(int irq, void *dev_id, struct pt_regs *regs)
6359 struct aic7xxx_host *p;
6360 unsigned char intstat;
6362 p = (struct aic7xxx_host *)dev_id;
6365 * Just a few sanity checks. Make sure that we have an int pending.
6366 * Also, if PCI, then we are going to check for a PCI bus error status
6367 * should we get too many spurious interrupts.
6369 if (!((intstat = aic_inb(p, INTSTAT)) & INT_PEND))
6371 #ifdef CONFIG_PCI
6372 if ( (p->chip & AHC_PCI) && (p->spurious_int > 500) &&
6373 !(p->flags & AHC_HANDLING_REQINITS) )
6375 if ( aic_inb(p, ERROR) & PCIERRSTAT )
6377 aic7xxx_pci_intr(p);
6379 p->spurious_int = 0;
6381 else if ( !(p->flags & AHC_HANDLING_REQINITS) )
6383 p->spurious_int++;
6385 #endif
6386 return;
6389 p->spurious_int = 0;
6392 * Keep track of interrupts for /proc/scsi
6394 p->isr_count++;
6396 #ifdef AIC7XXX_VERBOSE_DEBUGGING
6397 if ( (p->isr_count < 16) && (aic7xxx_verbose > 0xffff) &&
6398 (aic7xxx_panic_on_abort) && (p->flags & AHC_PAGESCBS) )
6399 aic7xxx_check_scbs(p, "Bogus settings at start of interrupt.");
6400 #endif
6403 * Handle all the interrupt sources - especially for SCSI
6404 * interrupts, we won't get a second chance at them.
6406 if (intstat & CMDCMPLT)
6408 aic7xxx_handle_command_completion_intr(p);
6411 if (intstat & BRKADRINT)
6413 int i;
6414 unsigned char errno = aic_inb(p, ERROR);
6416 printk(KERN_ERR "(scsi%d) BRKADRINT error(0x%x):\n", p->host_no, errno);
6417 for (i = 0; i < NUMBER(hard_error); i++)
6419 if (errno & hard_error[i].errno)
6421 printk(KERN_ERR " %s\n", hard_error[i].errmesg);
6424 printk(KERN_ERR "(scsi%d) SEQADDR=0x%x\n", p->host_no,
6425 (((aic_inb(p, SEQADDR1) << 8) & 0x100) | aic_inb(p, SEQADDR0)));
6426 if (aic7xxx_panic_on_abort)
6427 aic7xxx_panic_abort(p, NULL);
6428 #ifdef CONFIG_PCI
6429 if (errno & PCIERRSTAT)
6430 aic7xxx_pci_intr(p);
6431 #endif
6432 if (errno & (SQPARERR | ILLOPCODE | ILLSADDR))
6434 panic("aic7xxx: unrecoverable BRKADRINT.\n");
6436 if (errno & ILLHADDR)
6438 printk(KERN_ERR "(scsi%d) BUG! Driver accessed chip without first "
6439 "pausing controller!\n", p->host_no);
6441 #ifdef AIC7XXX_VERBOSE_DEBUGGING
6442 if (errno & DPARERR)
6444 if (aic_inb(p, DMAPARAMS) & DIRECTION)
6445 printk("(scsi%d) while DMAing SCB from host to card.\n", p->host_no);
6446 else
6447 printk("(scsi%d) while DMAing SCB from card to host.\n", p->host_no);
6449 #endif
6450 aic_outb(p, CLRPARERR | CLRBRKADRINT, CLRINT);
6451 unpause_sequencer(p, FALSE);
6454 if (intstat & SEQINT)
6457 * Read the CCSCBCTL register to work around a bug in the Ultra2 cards
6459 if(p->features & AHC_ULTRA2)
6461 aic_inb(p, CCSCBCTL);
6463 aic7xxx_handle_seqint(p, intstat);
6466 if (intstat & SCSIINT)
6468 aic7xxx_handle_scsiint(p, intstat);
6471 #ifdef AIC7XXX_VERBOSE_DEBUGGING
6472 if ( (p->isr_count < 16) && (aic7xxx_verbose > 0xffff) &&
6473 (aic7xxx_panic_on_abort) && (p->flags & AHC_PAGESCBS) )
6474 aic7xxx_check_scbs(p, "Bogus settings at end of interrupt.");
6475 #endif
6479 /*+F*************************************************************************
6480 * Function:
6481 * do_aic7xxx_isr
6483 * Description:
6484 * This is a gross hack to solve a problem in linux kernels 2.1.85 and
6485 * above. Please, children, do not try this at home, and if you ever see
6486 * anything like it, please inform the Gross Hack Police immediately
6487 *-F*************************************************************************/
6488 static irqreturn_t
6489 do_aic7xxx_isr(int irq, void *dev_id, struct pt_regs *regs)
6491 unsigned long cpu_flags;
6492 struct aic7xxx_host *p;
6494 p = (struct aic7xxx_host *)dev_id;
6495 if(!p)
6496 return IRQ_NONE;
6497 spin_lock_irqsave(p->host->host_lock, cpu_flags);
6498 p->flags |= AHC_IN_ISR;
6501 aic7xxx_isr(irq, dev_id, regs);
6502 } while ( (aic_inb(p, INTSTAT) & INT_PEND) );
6503 aic7xxx_done_cmds_complete(p);
6504 aic7xxx_run_waiting_queues(p);
6505 p->flags &= ~AHC_IN_ISR;
6506 spin_unlock_irqrestore(p->host->host_lock, cpu_flags);
6508 return IRQ_HANDLED;
6511 /*+F*************************************************************************
6512 * Function:
6513 * aic7xxx_init_transinfo
6515 * Description:
6516 * Set up the initial aic_dev values from the BIOS settings and from
6517 * INQUIRY results
6518 *-F*************************************************************************/
6519 static void
6520 aic7xxx_init_transinfo(struct aic7xxx_host *p, struct aic_dev_data *aic_dev)
6522 Scsi_Device *sdpnt = aic_dev->SDptr;
6523 unsigned char tindex;
6525 tindex = sdpnt->id | (sdpnt->channel << 3);
6526 if (!(aic_dev->flags & DEVICE_DTR_SCANNED))
6528 aic_dev->flags |= DEVICE_DTR_SCANNED;
6530 if ( sdpnt->wdtr && (p->features & AHC_WIDE) )
6532 aic_dev->needwdtr = aic_dev->needwdtr_copy = 1;
6533 aic_dev->goal.width = p->user[tindex].width;
6535 else
6537 aic_dev->needwdtr = aic_dev->needwdtr_copy = 0;
6538 pause_sequencer(p);
6539 aic7xxx_set_width(p, sdpnt->id, sdpnt->channel, sdpnt->lun,
6540 MSG_EXT_WDTR_BUS_8_BIT, (AHC_TRANS_ACTIVE |
6541 AHC_TRANS_GOAL |
6542 AHC_TRANS_CUR), aic_dev );
6543 unpause_sequencer(p, FALSE);
6545 if ( sdpnt->sdtr && p->user[tindex].offset )
6547 aic_dev->goal.period = p->user[tindex].period;
6548 aic_dev->goal.options = p->user[tindex].options;
6549 if (p->features & AHC_ULTRA2)
6550 aic_dev->goal.offset = MAX_OFFSET_ULTRA2;
6551 else if (aic_dev->goal.width == MSG_EXT_WDTR_BUS_16_BIT)
6552 aic_dev->goal.offset = MAX_OFFSET_16BIT;
6553 else
6554 aic_dev->goal.offset = MAX_OFFSET_8BIT;
6555 if ( sdpnt->ppr && p->user[tindex].period <= 9 &&
6556 p->user[tindex].options )
6558 aic_dev->needppr = aic_dev->needppr_copy = 1;
6559 aic_dev->needsdtr = aic_dev->needsdtr_copy = 0;
6560 aic_dev->needwdtr = aic_dev->needwdtr_copy = 0;
6561 aic_dev->flags |= DEVICE_SCSI_3;
6563 else
6565 aic_dev->needsdtr = aic_dev->needsdtr_copy = 1;
6566 aic_dev->goal.period = MAX(10, aic_dev->goal.period);
6567 aic_dev->goal.options = 0;
6570 else
6572 aic_dev->needsdtr = aic_dev->needsdtr_copy = 0;
6573 aic_dev->goal.period = 255;
6574 aic_dev->goal.offset = 0;
6575 aic_dev->goal.options = 0;
6577 aic_dev->flags |= DEVICE_PRINT_DTR;
6581 /*+F*************************************************************************
6582 * Function:
6583 * aic7xxx_slave_alloc
6585 * Description:
6586 * Set up the initial aic_dev struct pointers
6587 *-F*************************************************************************/
6588 static int
6589 aic7xxx_slave_alloc(Scsi_Device *SDptr)
6591 struct aic7xxx_host *p = (struct aic7xxx_host *)SDptr->host->hostdata;
6592 struct aic_dev_data *aic_dev;
6594 aic_dev = kmalloc(sizeof(struct aic_dev_data), GFP_ATOMIC | GFP_KERNEL);
6595 if(!aic_dev)
6596 return 1;
6598 * Check to see if channel was scanned.
6601 if (!(p->flags & AHC_A_SCANNED) && (SDptr->channel == 0))
6603 if (aic7xxx_verbose & VERBOSE_PROBE2)
6604 printk(INFO_LEAD "Scanning channel for devices.\n",
6605 p->host_no, 0, -1, -1);
6606 p->flags |= AHC_A_SCANNED;
6608 else
6610 if (!(p->flags & AHC_B_SCANNED) && (SDptr->channel == 1))
6612 if (aic7xxx_verbose & VERBOSE_PROBE2)
6613 printk(INFO_LEAD "Scanning channel for devices.\n",
6614 p->host_no, 1, -1, -1);
6615 p->flags |= AHC_B_SCANNED;
6619 memset(aic_dev, 0, sizeof(struct aic_dev_data));
6620 SDptr->hostdata = aic_dev;
6621 aic_dev->SDptr = SDptr;
6622 aic_dev->max_q_depth = 1;
6623 aic_dev->temp_q_depth = 1;
6624 scbq_init(&aic_dev->delayed_scbs);
6625 INIT_LIST_HEAD(&aic_dev->list);
6626 list_add_tail(&aic_dev->list, &p->aic_devs);
6627 return 0;
6630 /*+F*************************************************************************
6631 * Function:
6632 * aic7xxx_device_queue_depth
6634 * Description:
6635 * Determines the queue depth for a given device. There are two ways
6636 * a queue depth can be obtained for a tagged queueing device. One
6637 * way is the default queue depth which is determined by whether
6638 * aic7xxx_default_queue_depth. The other is by the aic7xxx_tag_info
6639 * array.
6641 * If tagged queueing isn't supported on the device, then we set the
6642 * depth to p->host->hostt->cmd_per_lun for internal driver queueing.
6643 * as the default queue depth. Otherwise, we use either 4 or 8 as the
6644 * default queue depth (dependent on the number of hardware SCBs).
6645 * The other way we determine queue depth is through the use of the
6646 * aic7xxx_tag_info array which is enabled by defining
6647 * AIC7XXX_TAGGED_QUEUEING_BY_DEVICE. This array can be initialized
6648 * with queue depths for individual devices. It also allows tagged
6649 * queueing to be [en|dis]abled for a specific adapter.
6650 *-F*************************************************************************/
6651 static void
6652 aic7xxx_device_queue_depth(struct aic7xxx_host *p, Scsi_Device *device)
6654 int tag_enabled = FALSE;
6655 struct aic_dev_data *aic_dev = device->hostdata;
6656 unsigned char tindex;
6658 tindex = device->id | (device->channel << 3);
6660 if (device->simple_tags)
6661 return; // We've already enabled this device
6663 if (device->tagged_supported)
6665 tag_enabled = TRUE;
6667 if (!(p->discenable & (1 << tindex)))
6669 if (aic7xxx_verbose & VERBOSE_NEGOTIATION2)
6670 printk(INFO_LEAD "Disconnection disabled, unable to "
6671 "enable tagged queueing.\n",
6672 p->host_no, device->channel, device->id, device->lun);
6673 tag_enabled = FALSE;
6675 else
6677 if (p->instance >= NUMBER(aic7xxx_tag_info))
6679 static int print_warning = TRUE;
6680 if(print_warning)
6682 printk(KERN_INFO "aic7xxx: WARNING, insufficient tag_info instances for"
6683 " installed controllers.\n");
6684 printk(KERN_INFO "aic7xxx: Please update the aic7xxx_tag_info array in"
6685 " the aic7xxx.c source file.\n");
6686 print_warning = FALSE;
6688 aic_dev->max_q_depth = aic_dev->temp_q_depth =
6689 aic7xxx_default_queue_depth;
6691 else
6694 if (aic7xxx_tag_info[p->instance].tag_commands[tindex] == 255)
6696 tag_enabled = FALSE;
6698 else if (aic7xxx_tag_info[p->instance].tag_commands[tindex] == 0)
6700 aic_dev->max_q_depth = aic_dev->temp_q_depth =
6701 aic7xxx_default_queue_depth;
6703 else
6705 aic_dev->max_q_depth = aic_dev->temp_q_depth =
6706 aic7xxx_tag_info[p->instance].tag_commands[tindex];
6711 if (tag_enabled)
6713 if (aic7xxx_verbose & VERBOSE_NEGOTIATION2)
6715 printk(INFO_LEAD "Tagged queuing enabled, queue depth %d.\n",
6716 p->host_no, device->channel, device->id,
6717 device->lun, aic_dev->max_q_depth);
6719 scsi_adjust_queue_depth(device, MSG_ORDERED_TAG, aic_dev->max_q_depth);
6721 else
6723 if (aic7xxx_verbose & VERBOSE_NEGOTIATION2)
6725 printk(INFO_LEAD "Tagged queuing disabled, queue depth %d.\n",
6726 p->host_no, device->channel, device->id,
6727 device->lun, device->host->cmd_per_lun);
6729 scsi_adjust_queue_depth(device, 0, device->host->cmd_per_lun);
6731 return;
6734 /*+F*************************************************************************
6735 * Function:
6736 * aic7xxx_slave_destroy
6738 * Description:
6739 * prepare for this device to go away
6740 *-F*************************************************************************/
6741 static void
6742 aic7xxx_slave_destroy(Scsi_Device *SDptr)
6744 struct aic_dev_data *aic_dev = SDptr->hostdata;
6746 list_del(&aic_dev->list);
6747 SDptr->hostdata = NULL;
6748 kfree(aic_dev);
6749 return;
6752 /*+F*************************************************************************
6753 * Function:
6754 * aic7xxx_slave_configure
6756 * Description:
6757 * Configure the device we are attaching to the controller. This is
6758 * where we get to do things like scan the INQUIRY data, set queue
6759 * depths, allocate command structs, etc.
6760 *-F*************************************************************************/
6761 static int
6762 aic7xxx_slave_configure(Scsi_Device *SDptr)
6764 struct aic7xxx_host *p = (struct aic7xxx_host *) SDptr->host->hostdata;
6765 struct aic_dev_data *aic_dev;
6766 int scbnum;
6768 aic_dev = (struct aic_dev_data *)SDptr->hostdata;
6770 aic7xxx_init_transinfo(p, aic_dev);
6771 aic7xxx_device_queue_depth(p, SDptr);
6772 if(list_empty(&aic_dev->list))
6773 list_add_tail(&aic_dev->list, &p->aic_devs);
6775 scbnum = 0;
6776 list_for_each_entry(aic_dev, &p->aic_devs, list) {
6777 scbnum += aic_dev->max_q_depth;
6779 while (scbnum > p->scb_data->numscbs)
6782 * Pre-allocate the needed SCBs to get around the possibility of having
6783 * to allocate some when memory is more or less exhausted and we need
6784 * the SCB in order to perform a swap operation (possible deadlock)
6786 if ( aic7xxx_allocate_scb(p) == 0 )
6787 break;
6791 return(0);
6794 /*+F*************************************************************************
6795 * Function:
6796 * aic7xxx_probe
6798 * Description:
6799 * Probing for EISA boards: it looks like the first two bytes
6800 * are a manufacturer code - three characters, five bits each:
6802 * BYTE 0 BYTE 1 BYTE 2 BYTE 3
6803 * ?1111122 22233333 PPPPPPPP RRRRRRRR
6805 * The characters are baselined off ASCII '@', so add that value
6806 * to each to get the real ASCII code for it. The next two bytes
6807 * appear to be a product and revision number, probably vendor-
6808 * specific. This is what is being searched for at each port,
6809 * and what should probably correspond to the ID= field in the
6810 * ECU's .cfg file for the card - if your card is not detected,
6811 * make sure your signature is listed in the array.
6813 * The fourth byte's lowest bit seems to be an enabled/disabled
6814 * flag (rest of the bits are reserved?).
6816 * NOTE: This function is only needed on Intel and Alpha platforms,
6817 * the other platforms we support don't have EISA/VLB busses. So,
6818 * we #ifdef this entire function to avoid compiler warnings about
6819 * an unused function.
6820 *-F*************************************************************************/
6821 #if defined(__i386__) || defined(__alpha__)
6822 static int
6823 aic7xxx_probe(int slot, int base, ahc_flag_type *flags)
6825 int i;
6826 unsigned char buf[4];
6828 static struct {
6829 int n;
6830 unsigned char signature[sizeof(buf)];
6831 ahc_chip type;
6832 int bios_disabled;
6833 } AIC7xxx[] = {
6834 { 4, { 0x04, 0x90, 0x77, 0x70 },
6835 AHC_AIC7770|AHC_EISA, FALSE }, /* mb 7770 */
6836 { 4, { 0x04, 0x90, 0x77, 0x71 },
6837 AHC_AIC7770|AHC_EISA, FALSE }, /* host adapter 274x */
6838 { 4, { 0x04, 0x90, 0x77, 0x56 },
6839 AHC_AIC7770|AHC_VL, FALSE }, /* 284x BIOS enabled */
6840 { 4, { 0x04, 0x90, 0x77, 0x57 },
6841 AHC_AIC7770|AHC_VL, TRUE } /* 284x BIOS disabled */
6845 * The VL-bus cards need to be primed by
6846 * writing before a signature check.
6848 for (i = 0; i < sizeof(buf); i++)
6850 outb(0x80 + i, base);
6851 buf[i] = inb(base + i);
6854 for (i = 0; i < NUMBER(AIC7xxx); i++)
6857 * Signature match on enabled card?
6859 if (!memcmp(buf, AIC7xxx[i].signature, AIC7xxx[i].n))
6861 if (inb(base + 4) & 1)
6863 if (AIC7xxx[i].bios_disabled)
6865 *flags |= AHC_USEDEFAULTS;
6867 else
6869 *flags |= AHC_BIOS_ENABLED;
6871 return (i);
6874 printk("aic7xxx: <Adaptec 7770 SCSI Host Adapter> "
6875 "disabled at slot %d, ignored.\n", slot);
6879 return (-1);
6881 #endif /* (__i386__) || (__alpha__) */
6884 /*+F*************************************************************************
6885 * Function:
6886 * read_2840_seeprom
6888 * Description:
6889 * Reads the 2840 serial EEPROM and returns 1 if successful and 0 if
6890 * not successful.
6892 * See read_seeprom (for the 2940) for the instruction set of the 93C46
6893 * chip.
6895 * The 2840 interface to the 93C46 serial EEPROM is through the
6896 * STATUS_2840 and SEECTL_2840 registers. The CS_2840, CK_2840, and
6897 * DO_2840 bits of the SEECTL_2840 register are connected to the chip
6898 * select, clock, and data out lines respectively of the serial EEPROM.
6899 * The DI_2840 bit of the STATUS_2840 is connected to the data in line
6900 * of the serial EEPROM. The EEPROM_TF bit of STATUS_2840 register is
6901 * useful in that it gives us an 800 nsec timer. After a read from the
6902 * SEECTL_2840 register the timing flag is cleared and goes high 800 nsec
6903 * later.
6904 *-F*************************************************************************/
6905 static int
6906 read_284x_seeprom(struct aic7xxx_host *p, struct seeprom_config *sc)
6908 int i = 0, k = 0;
6909 unsigned char temp;
6910 unsigned short checksum = 0;
6911 unsigned short *seeprom = (unsigned short *) sc;
6912 struct seeprom_cmd {
6913 unsigned char len;
6914 unsigned char bits[3];
6916 struct seeprom_cmd seeprom_read = {3, {1, 1, 0}};
6918 #define CLOCK_PULSE(p) \
6919 while ((aic_inb(p, STATUS_2840) & EEPROM_TF) == 0) \
6921 ; /* Do nothing */ \
6923 (void) aic_inb(p, SEECTL_2840);
6926 * Read the first 32 registers of the seeprom. For the 2840,
6927 * the 93C46 SEEPROM is a 1024-bit device with 64 16-bit registers
6928 * but only the first 32 are used by Adaptec BIOS. The loop
6929 * will range from 0 to 31.
6931 for (k = 0; k < (sizeof(*sc) / 2); k++)
6934 * Send chip select for one clock cycle.
6936 aic_outb(p, CK_2840 | CS_2840, SEECTL_2840);
6937 CLOCK_PULSE(p);
6940 * Now we're ready to send the read command followed by the
6941 * address of the 16-bit register we want to read.
6943 for (i = 0; i < seeprom_read.len; i++)
6945 temp = CS_2840 | seeprom_read.bits[i];
6946 aic_outb(p, temp, SEECTL_2840);
6947 CLOCK_PULSE(p);
6948 temp = temp ^ CK_2840;
6949 aic_outb(p, temp, SEECTL_2840);
6950 CLOCK_PULSE(p);
6953 * Send the 6 bit address (MSB first, LSB last).
6955 for (i = 5; i >= 0; i--)
6957 temp = k;
6958 temp = (temp >> i) & 1; /* Mask out all but lower bit. */
6959 temp = CS_2840 | temp;
6960 aic_outb(p, temp, SEECTL_2840);
6961 CLOCK_PULSE(p);
6962 temp = temp ^ CK_2840;
6963 aic_outb(p, temp, SEECTL_2840);
6964 CLOCK_PULSE(p);
6968 * Now read the 16 bit register. An initial 0 precedes the
6969 * register contents which begins with bit 15 (MSB) and ends
6970 * with bit 0 (LSB). The initial 0 will be shifted off the
6971 * top of our word as we let the loop run from 0 to 16.
6973 for (i = 0; i <= 16; i++)
6975 temp = CS_2840;
6976 aic_outb(p, temp, SEECTL_2840);
6977 CLOCK_PULSE(p);
6978 temp = temp ^ CK_2840;
6979 seeprom[k] = (seeprom[k] << 1) | (aic_inb(p, STATUS_2840) & DI_2840);
6980 aic_outb(p, temp, SEECTL_2840);
6981 CLOCK_PULSE(p);
6984 * The serial EEPROM has a checksum in the last word. Keep a
6985 * running checksum for all words read except for the last
6986 * word. We'll verify the checksum after all words have been
6987 * read.
6989 if (k < (sizeof(*sc) / 2) - 1)
6991 checksum = checksum + seeprom[k];
6995 * Reset the chip select for the next command cycle.
6997 aic_outb(p, 0, SEECTL_2840);
6998 CLOCK_PULSE(p);
6999 aic_outb(p, CK_2840, SEECTL_2840);
7000 CLOCK_PULSE(p);
7001 aic_outb(p, 0, SEECTL_2840);
7002 CLOCK_PULSE(p);
7005 #if 0
7006 printk("Computed checksum 0x%x, checksum read 0x%x\n", checksum, sc->checksum);
7007 printk("Serial EEPROM:");
7008 for (k = 0; k < (sizeof(*sc) / 2); k++)
7010 if (((k % 8) == 0) && (k != 0))
7012 printk("\n ");
7014 printk(" 0x%x", seeprom[k]);
7016 printk("\n");
7017 #endif
7019 if (checksum != sc->checksum)
7021 printk("aic7xxx: SEEPROM checksum error, ignoring SEEPROM settings.\n");
7022 return (0);
7025 return (1);
7026 #undef CLOCK_PULSE
7029 #define CLOCK_PULSE(p) \
7030 do { \
7031 int limit = 0; \
7032 do { \
7033 mb(); \
7034 pause_sequencer(p); /* This is just to generate some PCI */ \
7035 /* traffic so the PCI read is flushed */ \
7036 /* it shouldn't be needed, but some */ \
7037 /* chipsets do indeed appear to need */ \
7038 /* something to force PCI reads to get */ \
7039 /* flushed */ \
7040 udelay(1); /* Do nothing */ \
7041 } while (((aic_inb(p, SEECTL) & SEERDY) == 0) && (++limit < 1000)); \
7042 } while(0)
7044 /*+F*************************************************************************
7045 * Function:
7046 * acquire_seeprom
7048 * Description:
7049 * Acquires access to the memory port on PCI controllers.
7050 *-F*************************************************************************/
7051 static int
7052 acquire_seeprom(struct aic7xxx_host *p)
7056 * Request access of the memory port. When access is
7057 * granted, SEERDY will go high. We use a 1 second
7058 * timeout which should be near 1 second more than
7059 * is needed. Reason: after the 7870 chip reset, there
7060 * should be no contention.
7062 aic_outb(p, SEEMS, SEECTL);
7063 CLOCK_PULSE(p);
7064 if ((aic_inb(p, SEECTL) & SEERDY) == 0)
7066 aic_outb(p, 0, SEECTL);
7067 return (0);
7069 return (1);
7072 /*+F*************************************************************************
7073 * Function:
7074 * release_seeprom
7076 * Description:
7077 * Releases access to the memory port on PCI controllers.
7078 *-F*************************************************************************/
7079 static void
7080 release_seeprom(struct aic7xxx_host *p)
7083 * Make sure the SEEPROM is ready before we release it.
7085 CLOCK_PULSE(p);
7086 aic_outb(p, 0, SEECTL);
7089 /*+F*************************************************************************
7090 * Function:
7091 * read_seeprom
7093 * Description:
7094 * Reads the serial EEPROM and returns 1 if successful and 0 if
7095 * not successful.
7097 * The instruction set of the 93C46/56/66 chips is as follows:
7099 * Start OP
7100 * Function Bit Code Address Data Description
7101 * -------------------------------------------------------------------
7102 * READ 1 10 A5 - A0 Reads data stored in memory,
7103 * starting at specified address
7104 * EWEN 1 00 11XXXX Write enable must precede
7105 * all programming modes
7106 * ERASE 1 11 A5 - A0 Erase register A5A4A3A2A1A0
7107 * WRITE 1 01 A5 - A0 D15 - D0 Writes register
7108 * ERAL 1 00 10XXXX Erase all registers
7109 * WRAL 1 00 01XXXX D15 - D0 Writes to all registers
7110 * EWDS 1 00 00XXXX Disables all programming
7111 * instructions
7112 * *Note: A value of X for address is a don't care condition.
7113 * *Note: The 93C56 and 93C66 have 8 address bits.
7116 * The 93C46 has a four wire interface: clock, chip select, data in, and
7117 * data out. In order to perform one of the above functions, you need
7118 * to enable the chip select for a clock period (typically a minimum of
7119 * 1 usec, with the clock high and low a minimum of 750 and 250 nsec
7120 * respectively. While the chip select remains high, you can clock in
7121 * the instructions (above) starting with the start bit, followed by the
7122 * OP code, Address, and Data (if needed). For the READ instruction, the
7123 * requested 16-bit register contents is read from the data out line but
7124 * is preceded by an initial zero (leading 0, followed by 16-bits, MSB
7125 * first). The clock cycling from low to high initiates the next data
7126 * bit to be sent from the chip.
7128 * The 78xx interface to the 93C46 serial EEPROM is through the SEECTL
7129 * register. After successful arbitration for the memory port, the
7130 * SEECS bit of the SEECTL register is connected to the chip select.
7131 * The SEECK, SEEDO, and SEEDI are connected to the clock, data out,
7132 * and data in lines respectively. The SEERDY bit of SEECTL is useful
7133 * in that it gives us an 800 nsec timer. After a write to the SEECTL
7134 * register, the SEERDY goes high 800 nsec later. The one exception
7135 * to this is when we first request access to the memory port. The
7136 * SEERDY goes high to signify that access has been granted and, for
7137 * this case, has no implied timing.
7138 *-F*************************************************************************/
7139 static int
7140 read_seeprom(struct aic7xxx_host *p, int offset,
7141 unsigned short *scarray, unsigned int len, seeprom_chip_type chip)
7143 int i = 0, k;
7144 unsigned char temp;
7145 unsigned short checksum = 0;
7146 struct seeprom_cmd {
7147 unsigned char len;
7148 unsigned char bits[3];
7150 struct seeprom_cmd seeprom_read = {3, {1, 1, 0}};
7153 * Request access of the memory port.
7155 if (acquire_seeprom(p) == 0)
7157 return (0);
7161 * Read 'len' registers of the seeprom. For the 7870, the 93C46
7162 * SEEPROM is a 1024-bit device with 64 16-bit registers but only
7163 * the first 32 are used by Adaptec BIOS. Some adapters use the
7164 * 93C56 SEEPROM which is a 2048-bit device. The loop will range
7165 * from 0 to 'len' - 1.
7167 for (k = 0; k < len; k++)
7170 * Send chip select for one clock cycle.
7172 aic_outb(p, SEEMS | SEECK | SEECS, SEECTL);
7173 CLOCK_PULSE(p);
7176 * Now we're ready to send the read command followed by the
7177 * address of the 16-bit register we want to read.
7179 for (i = 0; i < seeprom_read.len; i++)
7181 temp = SEEMS | SEECS | (seeprom_read.bits[i] << 1);
7182 aic_outb(p, temp, SEECTL);
7183 CLOCK_PULSE(p);
7184 temp = temp ^ SEECK;
7185 aic_outb(p, temp, SEECTL);
7186 CLOCK_PULSE(p);
7189 * Send the 6 or 8 bit address (MSB first, LSB last).
7191 for (i = ((int) chip - 1); i >= 0; i--)
7193 temp = k + offset;
7194 temp = (temp >> i) & 1; /* Mask out all but lower bit. */
7195 temp = SEEMS | SEECS | (temp << 1);
7196 aic_outb(p, temp, SEECTL);
7197 CLOCK_PULSE(p);
7198 temp = temp ^ SEECK;
7199 aic_outb(p, temp, SEECTL);
7200 CLOCK_PULSE(p);
7204 * Now read the 16 bit register. An initial 0 precedes the
7205 * register contents which begins with bit 15 (MSB) and ends
7206 * with bit 0 (LSB). The initial 0 will be shifted off the
7207 * top of our word as we let the loop run from 0 to 16.
7209 for (i = 0; i <= 16; i++)
7211 temp = SEEMS | SEECS;
7212 aic_outb(p, temp, SEECTL);
7213 CLOCK_PULSE(p);
7214 temp = temp ^ SEECK;
7215 scarray[k] = (scarray[k] << 1) | (aic_inb(p, SEECTL) & SEEDI);
7216 aic_outb(p, temp, SEECTL);
7217 CLOCK_PULSE(p);
7221 * The serial EEPROM should have a checksum in the last word.
7222 * Keep a running checksum for all words read except for the
7223 * last word. We'll verify the checksum after all words have
7224 * been read.
7226 if (k < (len - 1))
7228 checksum = checksum + scarray[k];
7232 * Reset the chip select for the next command cycle.
7234 aic_outb(p, SEEMS, SEECTL);
7235 CLOCK_PULSE(p);
7236 aic_outb(p, SEEMS | SEECK, SEECTL);
7237 CLOCK_PULSE(p);
7238 aic_outb(p, SEEMS, SEECTL);
7239 CLOCK_PULSE(p);
7243 * Release access to the memory port and the serial EEPROM.
7245 release_seeprom(p);
7247 #if 0
7248 printk("Computed checksum 0x%x, checksum read 0x%x\n",
7249 checksum, scarray[len - 1]);
7250 printk("Serial EEPROM:");
7251 for (k = 0; k < len; k++)
7253 if (((k % 8) == 0) && (k != 0))
7255 printk("\n ");
7257 printk(" 0x%x", scarray[k]);
7259 printk("\n");
7260 #endif
7261 if ( (checksum != scarray[len - 1]) || (checksum == 0) )
7263 return (0);
7266 return (1);
7269 /*+F*************************************************************************
7270 * Function:
7271 * read_brdctl
7273 * Description:
7274 * Reads the BRDCTL register.
7275 *-F*************************************************************************/
7276 static unsigned char
7277 read_brdctl(struct aic7xxx_host *p)
7279 unsigned char brdctl, value;
7282 * Make sure the SEEPROM is ready before we access it
7284 CLOCK_PULSE(p);
7285 if (p->features & AHC_ULTRA2)
7287 brdctl = BRDRW_ULTRA2;
7288 aic_outb(p, brdctl, BRDCTL);
7289 CLOCK_PULSE(p);
7290 value = aic_inb(p, BRDCTL);
7291 CLOCK_PULSE(p);
7292 return(value);
7294 brdctl = BRDRW;
7295 if ( !((p->chip & AHC_CHIPID_MASK) == AHC_AIC7895) ||
7296 (p->flags & AHC_CHNLB) )
7298 brdctl |= BRDCS;
7300 aic_outb(p, brdctl, BRDCTL);
7301 CLOCK_PULSE(p);
7302 value = aic_inb(p, BRDCTL);
7303 CLOCK_PULSE(p);
7304 aic_outb(p, 0, BRDCTL);
7305 CLOCK_PULSE(p);
7306 return (value);
7309 /*+F*************************************************************************
7310 * Function:
7311 * write_brdctl
7313 * Description:
7314 * Writes a value to the BRDCTL register.
7315 *-F*************************************************************************/
7316 static void
7317 write_brdctl(struct aic7xxx_host *p, unsigned char value)
7319 unsigned char brdctl;
7322 * Make sure the SEEPROM is ready before we access it
7324 CLOCK_PULSE(p);
7325 if (p->features & AHC_ULTRA2)
7327 brdctl = value;
7328 aic_outb(p, brdctl, BRDCTL);
7329 CLOCK_PULSE(p);
7330 brdctl |= BRDSTB_ULTRA2;
7331 aic_outb(p, brdctl, BRDCTL);
7332 CLOCK_PULSE(p);
7333 brdctl &= ~BRDSTB_ULTRA2;
7334 aic_outb(p, brdctl, BRDCTL);
7335 CLOCK_PULSE(p);
7336 read_brdctl(p);
7337 CLOCK_PULSE(p);
7339 else
7341 brdctl = BRDSTB;
7342 if ( !((p->chip & AHC_CHIPID_MASK) == AHC_AIC7895) ||
7343 (p->flags & AHC_CHNLB) )
7345 brdctl |= BRDCS;
7347 brdctl = BRDSTB | BRDCS;
7348 aic_outb(p, brdctl, BRDCTL);
7349 CLOCK_PULSE(p);
7350 brdctl |= value;
7351 aic_outb(p, brdctl, BRDCTL);
7352 CLOCK_PULSE(p);
7353 brdctl &= ~BRDSTB;
7354 aic_outb(p, brdctl, BRDCTL);
7355 CLOCK_PULSE(p);
7356 brdctl &= ~BRDCS;
7357 aic_outb(p, brdctl, BRDCTL);
7358 CLOCK_PULSE(p);
7362 /*+F*************************************************************************
7363 * Function:
7364 * aic785x_cable_detect
7366 * Description:
7367 * Detect the cables that are present on aic785x class controller chips
7368 *-F*************************************************************************/
7369 static void
7370 aic785x_cable_detect(struct aic7xxx_host *p, int *int_50,
7371 int *ext_present, int *eeprom)
7373 unsigned char brdctl;
7375 aic_outb(p, BRDRW | BRDCS, BRDCTL);
7376 CLOCK_PULSE(p);
7377 aic_outb(p, 0, BRDCTL);
7378 CLOCK_PULSE(p);
7379 brdctl = aic_inb(p, BRDCTL);
7380 CLOCK_PULSE(p);
7381 *int_50 = !(brdctl & BRDDAT5);
7382 *ext_present = !(brdctl & BRDDAT6);
7383 *eeprom = (aic_inb(p, SPIOCAP) & EEPROM);
7386 #undef CLOCK_PULSE
7388 /*+F*************************************************************************
7389 * Function:
7390 * aic2940_uwpro_cable_detect
7392 * Description:
7393 * Detect the cables that are present on the 2940-UWPro cards
7395 * NOTE: This function assumes the SEEPROM will have already been acquired
7396 * prior to invocation of this function.
7397 *-F*************************************************************************/
7398 static void
7399 aic2940_uwpro_wide_cable_detect(struct aic7xxx_host *p, int *int_68,
7400 int *ext_68, int *eeprom)
7402 unsigned char brdctl;
7405 * First read the status of our cables. Set the rom bank to
7406 * 0 since the bank setting serves as a multiplexor for the
7407 * cable detection logic. BRDDAT5 controls the bank switch.
7409 write_brdctl(p, 0);
7412 * Now we read the state of the internal 68 connector. BRDDAT6
7413 * is don't care, BRDDAT7 is internal 68. The cable is
7414 * present if the bit is 0
7416 brdctl = read_brdctl(p);
7417 *int_68 = !(brdctl & BRDDAT7);
7420 * Set the bank bit in brdctl and then read the external cable state
7421 * and the EEPROM status
7423 write_brdctl(p, BRDDAT5);
7424 brdctl = read_brdctl(p);
7426 *ext_68 = !(brdctl & BRDDAT6);
7427 *eeprom = !(brdctl & BRDDAT7);
7430 * We're done, the calling function will release the SEEPROM for us
7434 /*+F*************************************************************************
7435 * Function:
7436 * aic787x_cable_detect
7438 * Description:
7439 * Detect the cables that are present on aic787x class controller chips
7441 * NOTE: This function assumes the SEEPROM will have already been acquired
7442 * prior to invocation of this function.
7443 *-F*************************************************************************/
7444 static void
7445 aic787x_cable_detect(struct aic7xxx_host *p, int *int_50, int *int_68,
7446 int *ext_present, int *eeprom)
7448 unsigned char brdctl;
7451 * First read the status of our cables. Set the rom bank to
7452 * 0 since the bank setting serves as a multiplexor for the
7453 * cable detection logic. BRDDAT5 controls the bank switch.
7455 write_brdctl(p, 0);
7458 * Now we read the state of the two internal connectors. BRDDAT6
7459 * is internal 50, BRDDAT7 is internal 68. For each, the cable is
7460 * present if the bit is 0
7462 brdctl = read_brdctl(p);
7463 *int_50 = !(brdctl & BRDDAT6);
7464 *int_68 = !(brdctl & BRDDAT7);
7467 * Set the bank bit in brdctl and then read the external cable state
7468 * and the EEPROM status
7470 write_brdctl(p, BRDDAT5);
7471 brdctl = read_brdctl(p);
7473 *ext_present = !(brdctl & BRDDAT6);
7474 *eeprom = !(brdctl & BRDDAT7);
7477 * We're done, the calling function will release the SEEPROM for us
7481 /*+F*************************************************************************
7482 * Function:
7483 * aic787x_ultra2_term_detect
7485 * Description:
7486 * Detect the termination settings present on ultra2 class controllers
7488 * NOTE: This function assumes the SEEPROM will have already been acquired
7489 * prior to invocation of this function.
7490 *-F*************************************************************************/
7491 static void
7492 aic7xxx_ultra2_term_detect(struct aic7xxx_host *p, int *enableSE_low,
7493 int *enableSE_high, int *enableLVD_low,
7494 int *enableLVD_high, int *eprom_present)
7496 unsigned char brdctl;
7498 brdctl = read_brdctl(p);
7500 *eprom_present = (brdctl & BRDDAT7);
7501 *enableSE_high = (brdctl & BRDDAT6);
7502 *enableSE_low = (brdctl & BRDDAT5);
7503 *enableLVD_high = (brdctl & BRDDAT4);
7504 *enableLVD_low = (brdctl & BRDDAT3);
7507 /*+F*************************************************************************
7508 * Function:
7509 * configure_termination
7511 * Description:
7512 * Configures the termination settings on PCI adapters that have
7513 * SEEPROMs available.
7514 *-F*************************************************************************/
7515 static void
7516 configure_termination(struct aic7xxx_host *p)
7518 int internal50_present = 0;
7519 int internal68_present = 0;
7520 int external_present = 0;
7521 int eprom_present = 0;
7522 int enableSE_low = 0;
7523 int enableSE_high = 0;
7524 int enableLVD_low = 0;
7525 int enableLVD_high = 0;
7526 unsigned char brddat = 0;
7527 unsigned char max_target = 0;
7528 unsigned char sxfrctl1 = aic_inb(p, SXFRCTL1);
7530 if (acquire_seeprom(p))
7532 if (p->features & (AHC_WIDE|AHC_TWIN))
7533 max_target = 16;
7534 else
7535 max_target = 8;
7536 aic_outb(p, SEEMS | SEECS, SEECTL);
7537 sxfrctl1 &= ~STPWEN;
7539 * The termination/cable detection logic is split into three distinct
7540 * groups. Ultra2 and later controllers, 2940UW-Pro controllers, and
7541 * older 7850, 7860, 7870, 7880, and 7895 controllers. Each has its
7542 * own unique way of detecting their cables and writing the results
7543 * back to the card.
7545 if (p->features & AHC_ULTRA2)
7548 * As long as user hasn't overridden term settings, always check the
7549 * cable detection logic
7551 if (aic7xxx_override_term == -1)
7553 aic7xxx_ultra2_term_detect(p, &enableSE_low, &enableSE_high,
7554 &enableLVD_low, &enableLVD_high,
7555 &eprom_present);
7559 * If the user is overriding settings, then they have been preserved
7560 * to here as fake adapter_control entries. Parse them and allow
7561 * them to override the detected settings (if we even did detection).
7563 if (!(p->adapter_control & CFSEAUTOTERM))
7565 enableSE_low = (p->adapter_control & CFSTERM);
7566 enableSE_high = (p->adapter_control & CFWSTERM);
7568 if (!(p->adapter_control & CFAUTOTERM))
7570 enableLVD_low = enableLVD_high = (p->adapter_control & CFLVDSTERM);
7574 * Now take those settings that we have and translate them into the
7575 * values that must be written into the registers.
7577 * Flash Enable = BRDDAT7
7578 * Secondary High Term Enable = BRDDAT6
7579 * Secondary Low Term Enable = BRDDAT5
7580 * LVD/Primary High Term Enable = BRDDAT4
7581 * LVD/Primary Low Term Enable = STPWEN bit in SXFRCTL1
7583 if (enableLVD_low != 0)
7585 sxfrctl1 |= STPWEN;
7586 p->flags |= AHC_TERM_ENB_LVD;
7587 if (aic7xxx_verbose & VERBOSE_PROBE2)
7588 printk(KERN_INFO "(scsi%d) LVD/Primary Low byte termination "
7589 "Enabled\n", p->host_no);
7592 if (enableLVD_high != 0)
7594 brddat |= BRDDAT4;
7595 if (aic7xxx_verbose & VERBOSE_PROBE2)
7596 printk(KERN_INFO "(scsi%d) LVD/Primary High byte termination "
7597 "Enabled\n", p->host_no);
7600 if (enableSE_low != 0)
7602 brddat |= BRDDAT5;
7603 if (aic7xxx_verbose & VERBOSE_PROBE2)
7604 printk(KERN_INFO "(scsi%d) Secondary Low byte termination "
7605 "Enabled\n", p->host_no);
7608 if (enableSE_high != 0)
7610 brddat |= BRDDAT6;
7611 if (aic7xxx_verbose & VERBOSE_PROBE2)
7612 printk(KERN_INFO "(scsi%d) Secondary High byte termination "
7613 "Enabled\n", p->host_no);
7616 else if (p->features & AHC_NEW_AUTOTERM)
7619 * The 50 pin connector termination is controlled by STPWEN in the
7620 * SXFRCTL1 register. Since the Adaptec docs typically say the
7621 * controller is not allowed to be in the middle of a cable and
7622 * this is the only connection on that stub of the bus, there is
7623 * no need to even check for narrow termination, it's simply
7624 * always on.
7626 sxfrctl1 |= STPWEN;
7627 if (aic7xxx_verbose & VERBOSE_PROBE2)
7628 printk(KERN_INFO "(scsi%d) Narrow channel termination Enabled\n",
7629 p->host_no);
7631 if (p->adapter_control & CFAUTOTERM)
7633 aic2940_uwpro_wide_cable_detect(p, &internal68_present,
7634 &external_present,
7635 &eprom_present);
7636 printk(KERN_INFO "(scsi%d) Cables present (Int-50 %s, Int-68 %s, "
7637 "Ext-68 %s)\n", p->host_no,
7638 "Don't Care",
7639 internal68_present ? "YES" : "NO",
7640 external_present ? "YES" : "NO");
7641 if (aic7xxx_verbose & VERBOSE_PROBE2)
7642 printk(KERN_INFO "(scsi%d) EEPROM %s present.\n", p->host_no,
7643 eprom_present ? "is" : "is not");
7644 if (internal68_present && external_present)
7646 brddat = 0;
7647 p->flags &= ~AHC_TERM_ENB_SE_HIGH;
7648 if (aic7xxx_verbose & VERBOSE_PROBE2)
7649 printk(KERN_INFO "(scsi%d) Wide channel termination Disabled\n",
7650 p->host_no);
7652 else
7654 brddat = BRDDAT6;
7655 p->flags |= AHC_TERM_ENB_SE_HIGH;
7656 if (aic7xxx_verbose & VERBOSE_PROBE2)
7657 printk(KERN_INFO "(scsi%d) Wide channel termination Enabled\n",
7658 p->host_no);
7661 else
7664 * The termination of the Wide channel is done more like normal
7665 * though, and the setting of this termination is done by writing
7666 * either a 0 or 1 to BRDDAT6 of the BRDDAT register
7668 if (p->adapter_control & CFWSTERM)
7670 brddat = BRDDAT6;
7671 p->flags |= AHC_TERM_ENB_SE_HIGH;
7672 if (aic7xxx_verbose & VERBOSE_PROBE2)
7673 printk(KERN_INFO "(scsi%d) Wide channel termination Enabled\n",
7674 p->host_no);
7676 else
7678 brddat = 0;
7682 else
7684 if (p->adapter_control & CFAUTOTERM)
7686 if (p->flags & AHC_MOTHERBOARD)
7688 printk(KERN_INFO "(scsi%d) Warning - detected auto-termination\n",
7689 p->host_no);
7690 printk(KERN_INFO "(scsi%d) Please verify driver detected settings "
7691 "are correct.\n", p->host_no);
7692 printk(KERN_INFO "(scsi%d) If not, then please properly set the "
7693 "device termination\n", p->host_no);
7694 printk(KERN_INFO "(scsi%d) in the Adaptec SCSI BIOS by hitting "
7695 "CTRL-A when prompted\n", p->host_no);
7696 printk(KERN_INFO "(scsi%d) during machine bootup.\n", p->host_no);
7698 /* Configure auto termination. */
7700 if ( (p->chip & AHC_CHIPID_MASK) >= AHC_AIC7870 )
7702 aic787x_cable_detect(p, &internal50_present, &internal68_present,
7703 &external_present, &eprom_present);
7705 else
7707 aic785x_cable_detect(p, &internal50_present, &external_present,
7708 &eprom_present);
7711 if (max_target <= 8)
7712 internal68_present = 0;
7714 if (max_target > 8)
7716 printk(KERN_INFO "(scsi%d) Cables present (Int-50 %s, Int-68 %s, "
7717 "Ext-68 %s)\n", p->host_no,
7718 internal50_present ? "YES" : "NO",
7719 internal68_present ? "YES" : "NO",
7720 external_present ? "YES" : "NO");
7722 else
7724 printk(KERN_INFO "(scsi%d) Cables present (Int-50 %s, Ext-50 %s)\n",
7725 p->host_no,
7726 internal50_present ? "YES" : "NO",
7727 external_present ? "YES" : "NO");
7729 if (aic7xxx_verbose & VERBOSE_PROBE2)
7730 printk(KERN_INFO "(scsi%d) EEPROM %s present.\n", p->host_no,
7731 eprom_present ? "is" : "is not");
7734 * Now set the termination based on what we found. BRDDAT6
7735 * controls wide termination enable.
7736 * Flash Enable = BRDDAT7
7737 * SE High Term Enable = BRDDAT6
7739 if (internal50_present && internal68_present && external_present)
7741 printk(KERN_INFO "(scsi%d) Illegal cable configuration!! Only two\n",
7742 p->host_no);
7743 printk(KERN_INFO "(scsi%d) connectors on the SCSI controller may be "
7744 "in use at a time!\n", p->host_no);
7746 * Force termination (low and high byte) on. This is safer than
7747 * leaving it completely off, especially since this message comes
7748 * most often from motherboard controllers that don't even have 3
7749 * connectors, but instead are failing the cable detection.
7751 internal50_present = external_present = 0;
7752 enableSE_high = enableSE_low = 1;
7755 if ((max_target > 8) &&
7756 ((external_present == 0) || (internal68_present == 0)) )
7758 brddat |= BRDDAT6;
7759 p->flags |= AHC_TERM_ENB_SE_HIGH;
7760 if (aic7xxx_verbose & VERBOSE_PROBE2)
7761 printk(KERN_INFO "(scsi%d) SE High byte termination Enabled\n",
7762 p->host_no);
7765 if ( ((internal50_present ? 1 : 0) +
7766 (internal68_present ? 1 : 0) +
7767 (external_present ? 1 : 0)) <= 1 )
7769 sxfrctl1 |= STPWEN;
7770 p->flags |= AHC_TERM_ENB_SE_LOW;
7771 if (aic7xxx_verbose & VERBOSE_PROBE2)
7772 printk(KERN_INFO "(scsi%d) SE Low byte termination Enabled\n",
7773 p->host_no);
7776 else /* p->adapter_control & CFAUTOTERM */
7778 if (p->adapter_control & CFSTERM)
7780 sxfrctl1 |= STPWEN;
7781 if (aic7xxx_verbose & VERBOSE_PROBE2)
7782 printk(KERN_INFO "(scsi%d) SE Low byte termination Enabled\n",
7783 p->host_no);
7786 if (p->adapter_control & CFWSTERM)
7788 brddat |= BRDDAT6;
7789 if (aic7xxx_verbose & VERBOSE_PROBE2)
7790 printk(KERN_INFO "(scsi%d) SE High byte termination Enabled\n",
7791 p->host_no);
7796 aic_outb(p, sxfrctl1, SXFRCTL1);
7797 write_brdctl(p, brddat);
7798 release_seeprom(p);
7802 /*+F*************************************************************************
7803 * Function:
7804 * detect_maxscb
7806 * Description:
7807 * Detects the maximum number of SCBs for the controller and returns
7808 * the count and a mask in p (p->maxscbs, p->qcntmask).
7809 *-F*************************************************************************/
7810 static void
7811 detect_maxscb(struct aic7xxx_host *p)
7813 int i;
7816 * It's possible that we've already done this for multichannel
7817 * adapters.
7819 if (p->scb_data->maxhscbs == 0)
7822 * We haven't initialized the SCB settings yet. Walk the SCBs to
7823 * determince how many there are.
7825 aic_outb(p, 0, FREE_SCBH);
7827 for (i = 0; i < AIC7XXX_MAXSCB; i++)
7829 aic_outb(p, i, SCBPTR);
7830 aic_outb(p, i, SCB_CONTROL);
7831 if (aic_inb(p, SCB_CONTROL) != i)
7832 break;
7833 aic_outb(p, 0, SCBPTR);
7834 if (aic_inb(p, SCB_CONTROL) != 0)
7835 break;
7837 aic_outb(p, i, SCBPTR);
7838 aic_outb(p, 0, SCB_CONTROL); /* Clear the control byte. */
7839 aic_outb(p, i + 1, SCB_NEXT); /* Set the next pointer. */
7840 aic_outb(p, SCB_LIST_NULL, SCB_TAG); /* Make the tag invalid. */
7841 aic_outb(p, SCB_LIST_NULL, SCB_BUSYTARGETS); /* no busy untagged */
7842 aic_outb(p, SCB_LIST_NULL, SCB_BUSYTARGETS+1);/* targets active yet */
7843 aic_outb(p, SCB_LIST_NULL, SCB_BUSYTARGETS+2);
7844 aic_outb(p, SCB_LIST_NULL, SCB_BUSYTARGETS+3);
7847 /* Make sure the last SCB terminates the free list. */
7848 aic_outb(p, i - 1, SCBPTR);
7849 aic_outb(p, SCB_LIST_NULL, SCB_NEXT);
7851 /* Ensure we clear the first (0) SCBs control byte. */
7852 aic_outb(p, 0, SCBPTR);
7853 aic_outb(p, 0, SCB_CONTROL);
7855 p->scb_data->maxhscbs = i;
7857 * Use direct indexing instead for speed
7859 if ( i == AIC7XXX_MAXSCB )
7860 p->flags &= ~AHC_PAGESCBS;
7865 /*+F*************************************************************************
7866 * Function:
7867 * aic7xxx_register
7869 * Description:
7870 * Register a Adaptec aic7xxx chip SCSI controller with the kernel.
7871 *-F*************************************************************************/
7872 static int
7873 aic7xxx_register(Scsi_Host_Template *template, struct aic7xxx_host *p,
7874 int reset_delay)
7876 int i, result;
7877 int max_targets;
7878 int found = 1;
7879 unsigned char term, scsi_conf;
7880 struct Scsi_Host *host;
7882 host = p->host;
7884 p->scb_data->maxscbs = AIC7XXX_MAXSCB;
7885 host->can_queue = AIC7XXX_MAXSCB;
7886 host->cmd_per_lun = 3;
7887 host->sg_tablesize = AIC7XXX_MAX_SG;
7888 host->this_id = p->scsi_id;
7889 host->io_port = p->base;
7890 host->n_io_port = 0xFF;
7891 host->base = p->mbase;
7892 host->irq = p->irq;
7893 if (p->features & AHC_WIDE)
7895 host->max_id = 16;
7897 if (p->features & AHC_TWIN)
7899 host->max_channel = 1;
7902 p->host = host;
7903 p->host_no = host->host_no;
7904 host->unique_id = p->instance;
7905 p->isr_count = 0;
7906 p->next = NULL;
7907 p->completeq.head = NULL;
7908 p->completeq.tail = NULL;
7909 scbq_init(&p->scb_data->free_scbs);
7910 scbq_init(&p->waiting_scbs);
7911 INIT_LIST_HEAD(&p->aic_devs);
7914 * We currently have no commands of any type
7916 p->qinfifonext = 0;
7917 p->qoutfifonext = 0;
7919 printk(KERN_INFO "(scsi%d) <%s> found at ", p->host_no,
7920 board_names[p->board_name_index]);
7921 switch(p->chip)
7923 case (AHC_AIC7770|AHC_EISA):
7924 printk("EISA slot %d\n", p->pci_device_fn);
7925 break;
7926 case (AHC_AIC7770|AHC_VL):
7927 printk("VLB slot %d\n", p->pci_device_fn);
7928 break;
7929 default:
7930 printk("PCI %d/%d/%d\n", p->pci_bus, PCI_SLOT(p->pci_device_fn),
7931 PCI_FUNC(p->pci_device_fn));
7932 break;
7934 if (p->features & AHC_TWIN)
7936 printk(KERN_INFO "(scsi%d) Twin Channel, A SCSI ID %d, B SCSI ID %d, ",
7937 p->host_no, p->scsi_id, p->scsi_id_b);
7939 else
7941 char *channel;
7943 channel = "";
7945 if ((p->flags & AHC_MULTI_CHANNEL) != 0)
7947 channel = " A";
7949 if ( (p->flags & (AHC_CHNLB|AHC_CHNLC)) != 0 )
7951 channel = (p->flags & AHC_CHNLB) ? " B" : " C";
7954 if (p->features & AHC_WIDE)
7956 printk(KERN_INFO "(scsi%d) Wide ", p->host_no);
7958 else
7960 printk(KERN_INFO "(scsi%d) Narrow ", p->host_no);
7962 printk("Channel%s, SCSI ID=%d, ", channel, p->scsi_id);
7964 aic_outb(p, 0, SEQ_FLAGS);
7966 detect_maxscb(p);
7968 printk("%d/%d SCBs\n", p->scb_data->maxhscbs, p->scb_data->maxscbs);
7969 if (aic7xxx_verbose & VERBOSE_PROBE2)
7971 printk(KERN_INFO "(scsi%d) BIOS %sabled, IO Port 0x%lx, IRQ %d\n",
7972 p->host_no, (p->flags & AHC_BIOS_ENABLED) ? "en" : "dis",
7973 p->base, p->irq);
7974 printk(KERN_INFO "(scsi%d) IO Memory at 0x%lx, MMAP Memory at 0x%lx\n",
7975 p->host_no, p->mbase, (unsigned long)p->maddr);
7978 #ifdef CONFIG_PCI
7980 * Now that we know our instance number, we can set the flags we need to
7981 * force termination if need be.
7983 if (aic7xxx_stpwlev != -1)
7986 * This option only applies to PCI controllers.
7988 if ( (p->chip & ~AHC_CHIPID_MASK) == AHC_PCI)
7990 unsigned char devconfig;
7992 pci_read_config_byte(p->pdev, DEVCONFIG, &devconfig);
7993 if ( (aic7xxx_stpwlev >> p->instance) & 0x01 )
7995 devconfig |= STPWLEVEL;
7996 if (aic7xxx_verbose & VERBOSE_PROBE2)
7997 printk("(scsi%d) Force setting STPWLEVEL bit\n", p->host_no);
7999 else
8001 devconfig &= ~STPWLEVEL;
8002 if (aic7xxx_verbose & VERBOSE_PROBE2)
8003 printk("(scsi%d) Force clearing STPWLEVEL bit\n", p->host_no);
8005 pci_write_config_byte(p->pdev, DEVCONFIG, devconfig);
8008 #endif
8011 * That took care of devconfig and stpwlev, now for the actual termination
8012 * settings.
8014 if (aic7xxx_override_term != -1)
8017 * Again, this only applies to PCI controllers. We don't have problems
8018 * with the termination on 274x controllers to the best of my knowledge.
8020 if ( (p->chip & ~AHC_CHIPID_MASK) == AHC_PCI)
8022 unsigned char term_override;
8024 term_override = ( (aic7xxx_override_term >> (p->instance * 4)) & 0x0f);
8025 p->adapter_control &=
8026 ~(CFSTERM|CFWSTERM|CFLVDSTERM|CFAUTOTERM|CFSEAUTOTERM);
8027 if ( (p->features & AHC_ULTRA2) && (term_override & 0x0c) )
8029 p->adapter_control |= CFLVDSTERM;
8031 if (term_override & 0x02)
8033 p->adapter_control |= CFWSTERM;
8035 if (term_override & 0x01)
8037 p->adapter_control |= CFSTERM;
8042 if ( (p->flags & AHC_SEEPROM_FOUND) || (aic7xxx_override_term != -1) )
8044 if (p->features & AHC_SPIOCAP)
8046 if ( aic_inb(p, SPIOCAP) & SSPIOCPS )
8048 * Update the settings in sxfrctl1 to match the termination
8049 * settings.
8051 configure_termination(p);
8053 else if ((p->chip & AHC_CHIPID_MASK) >= AHC_AIC7870)
8055 configure_termination(p);
8060 * Set the SCSI Id, SXFRCTL0, SXFRCTL1, and SIMODE1, for both channels
8062 if (p->features & AHC_TWIN)
8064 /* Select channel B */
8065 aic_outb(p, aic_inb(p, SBLKCTL) | SELBUSB, SBLKCTL);
8067 if ((p->flags & AHC_SEEPROM_FOUND) || (aic7xxx_override_term != -1))
8068 term = (aic_inb(p, SXFRCTL1) & STPWEN);
8069 else
8070 term = ((p->flags & AHC_TERM_ENB_B) ? STPWEN : 0);
8072 aic_outb(p, p->scsi_id_b, SCSIID);
8073 scsi_conf = aic_inb(p, SCSICONF + 1);
8074 aic_outb(p, DFON | SPIOEN, SXFRCTL0);
8075 aic_outb(p, (scsi_conf & ENSPCHK) | aic7xxx_seltime | term |
8076 ENSTIMER | ACTNEGEN, SXFRCTL1);
8077 aic_outb(p, 0, SIMODE0);
8078 aic_outb(p, ENSELTIMO | ENSCSIRST | ENSCSIPERR, SIMODE1);
8079 aic_outb(p, 0, SCSIRATE);
8081 /* Select channel A */
8082 aic_outb(p, aic_inb(p, SBLKCTL) & ~SELBUSB, SBLKCTL);
8085 if (p->features & AHC_ULTRA2)
8087 aic_outb(p, p->scsi_id, SCSIID_ULTRA2);
8089 else
8091 aic_outb(p, p->scsi_id, SCSIID);
8093 if ((p->flags & AHC_SEEPROM_FOUND) || (aic7xxx_override_term != -1))
8094 term = (aic_inb(p, SXFRCTL1) & STPWEN);
8095 else
8096 term = ((p->flags & (AHC_TERM_ENB_A|AHC_TERM_ENB_LVD)) ? STPWEN : 0);
8097 scsi_conf = aic_inb(p, SCSICONF);
8098 aic_outb(p, DFON | SPIOEN, SXFRCTL0);
8099 aic_outb(p, (scsi_conf & ENSPCHK) | aic7xxx_seltime | term |
8100 ENSTIMER | ACTNEGEN, SXFRCTL1);
8101 aic_outb(p, 0, SIMODE0);
8103 * If we are a cardbus adapter then don't enable SCSI reset detection.
8104 * We shouldn't likely be sharing SCSI busses with someone else, and
8105 * if we don't have a cable currently plugged into the controller then
8106 * we won't have a power source for the SCSI termination, which means
8107 * we'll see infinite incoming bus resets.
8109 if(p->flags & AHC_NO_STPWEN)
8110 aic_outb(p, ENSELTIMO | ENSCSIPERR, SIMODE1);
8111 else
8112 aic_outb(p, ENSELTIMO | ENSCSIRST | ENSCSIPERR, SIMODE1);
8113 aic_outb(p, 0, SCSIRATE);
8114 if ( p->features & AHC_ULTRA2)
8115 aic_outb(p, 0, SCSIOFFSET);
8118 * Look at the information that board initialization or the board
8119 * BIOS has left us. In the lower four bits of each target's
8120 * scratch space any value other than 0 indicates that we should
8121 * initiate synchronous transfers. If it's zero, the user or the
8122 * BIOS has decided to disable synchronous negotiation to that
8123 * target so we don't activate the needsdtr flag.
8125 if ((p->features & (AHC_TWIN|AHC_WIDE)) == 0)
8127 max_targets = 8;
8129 else
8131 max_targets = 16;
8134 if (!(aic7xxx_no_reset))
8137 * If we reset the bus, then clear the transfer settings, else leave
8138 * them be.
8140 aic_outb(p, 0, ULTRA_ENB);
8141 aic_outb(p, 0, ULTRA_ENB + 1);
8142 p->ultraenb = 0;
8146 * Allocate enough hardware scbs to handle the maximum number of
8147 * concurrent transactions we can have. We have to make sure that
8148 * the allocated memory is contiguous memory. The Linux kmalloc
8149 * routine should only allocate contiguous memory, but note that
8150 * this could be a problem if kmalloc() is changed.
8153 size_t array_size;
8154 unsigned int hscb_physaddr;
8156 array_size = p->scb_data->maxscbs * sizeof(struct aic7xxx_hwscb);
8157 if (p->scb_data->hscbs == NULL)
8159 /* pci_alloc_consistent enforces the alignment already and
8160 * clears the area as well.
8162 p->scb_data->hscbs = pci_alloc_consistent(p->pdev, array_size,
8163 &p->scb_data->hscbs_dma);
8164 /* We have to use pci_free_consistent, not kfree */
8165 p->scb_data->hscb_kmalloc_ptr = NULL;
8166 p->scb_data->hscbs_dma_len = array_size;
8168 if (p->scb_data->hscbs == NULL)
8170 printk("(scsi%d) Unable to allocate hardware SCB array; "
8171 "failing detection.\n", p->host_no);
8172 aic_outb(p, 0, SIMODE1);
8173 p->irq = 0;
8174 return(0);
8177 hscb_physaddr = p->scb_data->hscbs_dma;
8178 aic_outb(p, hscb_physaddr & 0xFF, HSCB_ADDR);
8179 aic_outb(p, (hscb_physaddr >> 8) & 0xFF, HSCB_ADDR + 1);
8180 aic_outb(p, (hscb_physaddr >> 16) & 0xFF, HSCB_ADDR + 2);
8181 aic_outb(p, (hscb_physaddr >> 24) & 0xFF, HSCB_ADDR + 3);
8183 /* Set up the fifo areas at the same time */
8184 p->untagged_scbs = pci_alloc_consistent(p->pdev, 3*256, &p->fifo_dma);
8185 if (p->untagged_scbs == NULL)
8187 printk("(scsi%d) Unable to allocate hardware FIFO arrays; "
8188 "failing detection.\n", p->host_no);
8189 p->irq = 0;
8190 return(0);
8193 p->qoutfifo = p->untagged_scbs + 256;
8194 p->qinfifo = p->qoutfifo + 256;
8195 for (i = 0; i < 256; i++)
8197 p->untagged_scbs[i] = SCB_LIST_NULL;
8198 p->qinfifo[i] = SCB_LIST_NULL;
8199 p->qoutfifo[i] = SCB_LIST_NULL;
8202 hscb_physaddr = p->fifo_dma;
8203 aic_outb(p, hscb_physaddr & 0xFF, SCBID_ADDR);
8204 aic_outb(p, (hscb_physaddr >> 8) & 0xFF, SCBID_ADDR + 1);
8205 aic_outb(p, (hscb_physaddr >> 16) & 0xFF, SCBID_ADDR + 2);
8206 aic_outb(p, (hscb_physaddr >> 24) & 0xFF, SCBID_ADDR + 3);
8209 /* The Q-FIFOs we just set up are all empty */
8210 aic_outb(p, 0, QINPOS);
8211 aic_outb(p, 0, KERNEL_QINPOS);
8212 aic_outb(p, 0, QOUTPOS);
8214 if(p->features & AHC_QUEUE_REGS)
8216 aic_outb(p, SCB_QSIZE_256, QOFF_CTLSTA);
8217 aic_outb(p, 0, SDSCB_QOFF);
8218 aic_outb(p, 0, SNSCB_QOFF);
8219 aic_outb(p, 0, HNSCB_QOFF);
8223 * We don't have any waiting selections or disconnected SCBs.
8225 aic_outb(p, SCB_LIST_NULL, WAITING_SCBH);
8226 aic_outb(p, SCB_LIST_NULL, DISCONNECTED_SCBH);
8229 * Message out buffer starts empty
8231 aic_outb(p, MSG_NOOP, MSG_OUT);
8232 aic_outb(p, MSG_NOOP, LAST_MSG);
8235 * Set all the other asundry items that haven't been set yet.
8236 * This includes just dumping init values to a lot of registers simply
8237 * to make sure they've been touched and are ready for use parity wise
8238 * speaking.
8240 aic_outb(p, 0, TMODE_CMDADDR);
8241 aic_outb(p, 0, TMODE_CMDADDR + 1);
8242 aic_outb(p, 0, TMODE_CMDADDR + 2);
8243 aic_outb(p, 0, TMODE_CMDADDR + 3);
8244 aic_outb(p, 0, TMODE_CMDADDR_NEXT);
8247 * Link us into the list of valid hosts
8249 p->next = first_aic7xxx;
8250 first_aic7xxx = p;
8253 * Allocate the first set of scbs for this controller. This is to stream-
8254 * line code elsewhere in the driver. If we have to check for the existence
8255 * of scbs in certain code sections, it slows things down. However, as
8256 * soon as we register the IRQ for this card, we could get an interrupt that
8257 * includes possibly the SCSI_RSTI interrupt. If we catch that interrupt
8258 * then we are likely to segfault if we don't have at least one chunk of
8259 * SCBs allocated or add checks all through the reset code to make sure
8260 * that the SCBs have been allocated which is an invalid running condition
8261 * and therefore I think it's preferable to simply pre-allocate the first
8262 * chunk of SCBs.
8264 aic7xxx_allocate_scb(p);
8267 * Load the sequencer program, then re-enable the board -
8268 * resetting the AIC-7770 disables it, leaving the lights
8269 * on with nobody home.
8271 aic7xxx_loadseq(p);
8274 * Make sure the AUTOFLUSHDIS bit is *not* set in the SBLKCTL register
8276 aic_outb(p, aic_inb(p, SBLKCTL) & ~AUTOFLUSHDIS, SBLKCTL);
8278 if ( (p->chip & AHC_CHIPID_MASK) == AHC_AIC7770 )
8280 aic_outb(p, ENABLE, BCTL); /* Enable the boards BUS drivers. */
8283 if ( !(aic7xxx_no_reset) )
8285 if (p->features & AHC_TWIN)
8287 if (aic7xxx_verbose & VERBOSE_PROBE2)
8288 printk(KERN_INFO "(scsi%d) Resetting channel B\n", p->host_no);
8289 aic_outb(p, aic_inb(p, SBLKCTL) | SELBUSB, SBLKCTL);
8290 aic7xxx_reset_current_bus(p);
8291 aic_outb(p, aic_inb(p, SBLKCTL) & ~SELBUSB, SBLKCTL);
8293 /* Reset SCSI bus A. */
8294 if (aic7xxx_verbose & VERBOSE_PROBE2)
8295 { /* In case we are a 3940, 3985, or 7895, print the right channel */
8296 char *channel = "";
8297 if (p->flags & AHC_MULTI_CHANNEL)
8299 channel = " A";
8300 if (p->flags & (AHC_CHNLB|AHC_CHNLC))
8301 channel = (p->flags & AHC_CHNLB) ? " B" : " C";
8303 printk(KERN_INFO "(scsi%d) Resetting channel%s\n", p->host_no, channel);
8306 aic7xxx_reset_current_bus(p);
8309 else
8311 if (!reset_delay)
8313 printk(KERN_INFO "(scsi%d) Not resetting SCSI bus. Note: Don't use "
8314 "the no_reset\n", p->host_no);
8315 printk(KERN_INFO "(scsi%d) option unless you have a verifiable need "
8316 "for it.\n", p->host_no);
8321 * Register IRQ with the kernel. Only allow sharing IRQs with
8322 * PCI devices.
8324 if (!(p->chip & AHC_PCI))
8326 result = (request_irq(p->irq, do_aic7xxx_isr, 0, "aic7xxx", p));
8328 else
8330 result = (request_irq(p->irq, do_aic7xxx_isr, SA_SHIRQ,
8331 "aic7xxx", p));
8332 if (result < 0)
8334 result = (request_irq(p->irq, do_aic7xxx_isr, SA_INTERRUPT | SA_SHIRQ,
8335 "aic7xxx", p));
8338 if (result < 0)
8340 printk(KERN_WARNING "(scsi%d) Couldn't register IRQ %d, ignoring "
8341 "controller.\n", p->host_no, p->irq);
8342 aic_outb(p, 0, SIMODE1);
8343 p->irq = 0;
8344 return (0);
8347 if(aic_inb(p, INTSTAT) & INT_PEND)
8348 printk(INFO_LEAD "spurious interrupt during configuration, cleared.\n",
8349 p->host_no, -1, -1 , -1);
8350 aic7xxx_clear_intstat(p);
8352 unpause_sequencer(p, /* unpause_always */ TRUE);
8354 return (found);
8357 /*+F*************************************************************************
8358 * Function:
8359 * aic7xxx_chip_reset
8361 * Description:
8362 * Perform a chip reset on the aic7xxx SCSI controller. The controller
8363 * is paused upon return.
8364 *-F*************************************************************************/
8365 static int
8366 aic7xxx_chip_reset(struct aic7xxx_host *p)
8368 unsigned char sblkctl;
8369 int wait;
8372 * For some 274x boards, we must clear the CHIPRST bit and pause
8373 * the sequencer. For some reason, this makes the driver work.
8375 aic_outb(p, PAUSE | CHIPRST, HCNTRL);
8378 * In the future, we may call this function as a last resort for
8379 * error handling. Let's be nice and not do any unnecessary delays.
8381 wait = 1000; /* 1 msec (1000 * 1 msec) */
8382 while (--wait && !(aic_inb(p, HCNTRL) & CHIPRSTACK))
8384 udelay(1); /* 1 usec */
8387 pause_sequencer(p);
8389 sblkctl = aic_inb(p, SBLKCTL) & (SELBUSB|SELWIDE);
8390 if (p->chip & AHC_PCI)
8391 sblkctl &= ~SELBUSB;
8392 switch( sblkctl )
8394 case 0: /* normal narrow card */
8395 break;
8396 case 2: /* Wide card */
8397 p->features |= AHC_WIDE;
8398 break;
8399 case 8: /* Twin card */
8400 p->features |= AHC_TWIN;
8401 p->flags |= AHC_MULTI_CHANNEL;
8402 break;
8403 default: /* hmmm...we don't know what this is */
8404 printk(KERN_WARNING "aic7xxx: Unsupported adapter type %d, ignoring.\n",
8405 aic_inb(p, SBLKCTL) & 0x0a);
8406 return(-1);
8408 return(0);
8411 /*+F*************************************************************************
8412 * Function:
8413 * aic7xxx_alloc
8415 * Description:
8416 * Allocate and initialize a host structure. Returns NULL upon error
8417 * and a pointer to a aic7xxx_host struct upon success.
8418 *-F*************************************************************************/
8419 static struct aic7xxx_host *
8420 aic7xxx_alloc(Scsi_Host_Template *sht, struct aic7xxx_host *temp)
8422 struct aic7xxx_host *p = NULL;
8423 struct Scsi_Host *host;
8426 * Allocate a storage area by registering us with the mid-level
8427 * SCSI layer.
8429 host = scsi_register(sht, sizeof(struct aic7xxx_host));
8431 if (host != NULL)
8433 p = (struct aic7xxx_host *) host->hostdata;
8434 memset(p, 0, sizeof(struct aic7xxx_host));
8435 *p = *temp;
8436 p->host = host;
8438 p->scb_data = kmalloc(sizeof(scb_data_type), GFP_ATOMIC);
8439 if (p->scb_data != NULL)
8441 memset(p->scb_data, 0, sizeof(scb_data_type));
8442 scbq_init (&p->scb_data->free_scbs);
8444 else
8447 * For some reason we don't have enough memory. Free the
8448 * allocated memory for the aic7xxx_host struct, and return NULL.
8450 release_region(p->base, MAXREG - MINREG);
8451 scsi_unregister(host);
8452 return(NULL);
8454 p->host_no = host->host_no;
8456 scsi_set_device(host, &p->pdev->dev);
8457 return (p);
8460 /*+F*************************************************************************
8461 * Function:
8462 * aic7xxx_free
8464 * Description:
8465 * Frees and releases all resources associated with an instance of
8466 * the driver (struct aic7xxx_host *).
8467 *-F*************************************************************************/
8468 static void
8469 aic7xxx_free(struct aic7xxx_host *p)
8471 int i;
8474 * Free the allocated hardware SCB space.
8476 if (p->scb_data != NULL)
8478 struct aic7xxx_scb_dma *scb_dma = NULL;
8479 if (p->scb_data->hscbs != NULL)
8481 pci_free_consistent(p->pdev, p->scb_data->hscbs_dma_len,
8482 p->scb_data->hscbs, p->scb_data->hscbs_dma);
8483 p->scb_data->hscbs = p->scb_data->hscb_kmalloc_ptr = NULL;
8486 * Free the driver SCBs. These were allocated on an as-need
8487 * basis. We allocated these in groups depending on how many
8488 * we could fit into a given amount of RAM. The tail SCB for
8489 * these allocations has a pointer to the alloced area.
8491 for (i = 0; i < p->scb_data->numscbs; i++)
8493 if (p->scb_data->scb_array[i]->scb_dma != scb_dma)
8495 scb_dma = p->scb_data->scb_array[i]->scb_dma;
8496 pci_free_consistent(p->pdev, scb_dma->dma_len,
8497 (void *)((unsigned long)scb_dma->dma_address
8498 - scb_dma->dma_offset),
8499 scb_dma->dma_address);
8501 if (p->scb_data->scb_array[i]->kmalloc_ptr != NULL)
8502 kfree(p->scb_data->scb_array[i]->kmalloc_ptr);
8503 p->scb_data->scb_array[i] = NULL;
8507 * Free the SCB data area.
8509 kfree(p->scb_data);
8512 pci_free_consistent(p->pdev, 3*256, (void *)p->untagged_scbs, p->fifo_dma);
8515 /*+F*************************************************************************
8516 * Function:
8517 * aic7xxx_load_seeprom
8519 * Description:
8520 * Load the seeprom and configure adapter and target settings.
8521 * Returns 1 if the load was successful and 0 otherwise.
8522 *-F*************************************************************************/
8523 static void
8524 aic7xxx_load_seeprom(struct aic7xxx_host *p, unsigned char *sxfrctl1)
8526 int have_seeprom = 0;
8527 int i, max_targets, mask;
8528 unsigned char scsirate, scsi_conf;
8529 unsigned short scarray[128];
8530 struct seeprom_config *sc = (struct seeprom_config *) scarray;
8532 if (aic7xxx_verbose & VERBOSE_PROBE2)
8534 printk(KERN_INFO "aic7xxx: Loading serial EEPROM...");
8536 switch (p->chip)
8538 case (AHC_AIC7770|AHC_EISA): /* None of these adapters have seeproms. */
8539 if (aic_inb(p, SCSICONF) & TERM_ENB)
8540 p->flags |= AHC_TERM_ENB_A;
8541 if ( (p->features & AHC_TWIN) && (aic_inb(p, SCSICONF + 1) & TERM_ENB) )
8542 p->flags |= AHC_TERM_ENB_B;
8543 break;
8545 case (AHC_AIC7770|AHC_VL):
8546 have_seeprom = read_284x_seeprom(p, (struct seeprom_config *) scarray);
8547 break;
8549 default:
8550 have_seeprom = read_seeprom(p, (p->flags & (AHC_CHNLB|AHC_CHNLC)),
8551 scarray, p->sc_size, p->sc_type);
8552 if (!have_seeprom)
8554 if(p->sc_type == C46)
8555 have_seeprom = read_seeprom(p, (p->flags & (AHC_CHNLB|AHC_CHNLC)),
8556 scarray, p->sc_size, C56_66);
8557 else
8558 have_seeprom = read_seeprom(p, (p->flags & (AHC_CHNLB|AHC_CHNLC)),
8559 scarray, p->sc_size, C46);
8561 if (!have_seeprom)
8563 p->sc_size = 128;
8564 have_seeprom = read_seeprom(p, 4*(p->flags & (AHC_CHNLB|AHC_CHNLC)),
8565 scarray, p->sc_size, p->sc_type);
8566 if (!have_seeprom)
8568 if(p->sc_type == C46)
8569 have_seeprom = read_seeprom(p, 4*(p->flags & (AHC_CHNLB|AHC_CHNLC)),
8570 scarray, p->sc_size, C56_66);
8571 else
8572 have_seeprom = read_seeprom(p, 4*(p->flags & (AHC_CHNLB|AHC_CHNLC)),
8573 scarray, p->sc_size, C46);
8576 break;
8579 if (!have_seeprom)
8581 if (aic7xxx_verbose & VERBOSE_PROBE2)
8583 printk("\naic7xxx: No SEEPROM available.\n");
8585 p->flags |= AHC_NEWEEPROM_FMT;
8586 if (aic_inb(p, SCSISEQ) == 0)
8588 p->flags |= AHC_USEDEFAULTS;
8589 p->flags &= ~AHC_BIOS_ENABLED;
8590 p->scsi_id = p->scsi_id_b = 7;
8591 *sxfrctl1 |= STPWEN;
8592 if (aic7xxx_verbose & VERBOSE_PROBE2)
8594 printk("aic7xxx: Using default values.\n");
8597 else if (aic7xxx_verbose & VERBOSE_PROBE2)
8599 printk("aic7xxx: Using leftover BIOS values.\n");
8601 if ( ((p->chip & ~AHC_CHIPID_MASK) == AHC_PCI) && (*sxfrctl1 & STPWEN) )
8603 p->flags |= AHC_TERM_ENB_SE_LOW | AHC_TERM_ENB_SE_HIGH;
8604 sc->adapter_control &= ~CFAUTOTERM;
8605 sc->adapter_control |= CFSTERM | CFWSTERM | CFLVDSTERM;
8607 if (aic7xxx_extended)
8608 p->flags |= (AHC_EXTEND_TRANS_A | AHC_EXTEND_TRANS_B);
8609 else
8610 p->flags &= ~(AHC_EXTEND_TRANS_A | AHC_EXTEND_TRANS_B);
8612 else
8614 if (aic7xxx_verbose & VERBOSE_PROBE2)
8616 printk("done\n");
8620 * Note things in our flags
8622 p->flags |= AHC_SEEPROM_FOUND;
8625 * Update the settings in sxfrctl1 to match the termination settings.
8627 *sxfrctl1 = 0;
8630 * Get our SCSI ID from the SEEPROM setting...
8632 p->scsi_id = (sc->brtime_id & CFSCSIID);
8635 * First process the settings that are different between the VLB
8636 * and PCI adapter seeproms.
8638 if ((p->chip & AHC_CHIPID_MASK) == AHC_AIC7770)
8640 /* VLB adapter seeproms */
8641 if (sc->bios_control & CF284XEXTEND)
8642 p->flags |= AHC_EXTEND_TRANS_A;
8644 if (sc->adapter_control & CF284XSTERM)
8646 *sxfrctl1 |= STPWEN;
8647 p->flags |= AHC_TERM_ENB_SE_LOW | AHC_TERM_ENB_SE_HIGH;
8650 else
8652 /* PCI adapter seeproms */
8653 if (sc->bios_control & CFEXTEND)
8654 p->flags |= AHC_EXTEND_TRANS_A;
8655 if (sc->bios_control & CFBIOSEN)
8656 p->flags |= AHC_BIOS_ENABLED;
8657 else
8658 p->flags &= ~AHC_BIOS_ENABLED;
8660 if (sc->adapter_control & CFSTERM)
8662 *sxfrctl1 |= STPWEN;
8663 p->flags |= AHC_TERM_ENB_SE_LOW | AHC_TERM_ENB_SE_HIGH;
8666 memcpy(&p->sc, sc, sizeof(struct seeprom_config));
8669 p->discenable = 0;
8672 * Limit to 16 targets just in case. The 2842 for one is known to
8673 * blow the max_targets setting, future cards might also.
8675 max_targets = ((p->features & (AHC_TWIN | AHC_WIDE)) ? 16 : 8);
8677 if (have_seeprom)
8679 for (i = 0; i < max_targets; i++)
8681 if( ((p->features & AHC_ULTRA) &&
8682 !(sc->adapter_control & CFULTRAEN) &&
8683 (sc->device_flags[i] & CFSYNCHISULTRA)) ||
8684 (sc->device_flags[i] & CFNEWULTRAFORMAT) )
8686 p->flags |= AHC_NEWEEPROM_FMT;
8687 break;
8692 for (i = 0; i < max_targets; i++)
8694 mask = (0x01 << i);
8695 if (!have_seeprom)
8697 if (aic_inb(p, SCSISEQ) != 0)
8700 * OK...the BIOS set things up and left behind the settings we need.
8701 * Just make our sc->device_flags[i] entry match what the card has
8702 * set for this device.
8704 p->discenable =
8705 ~(aic_inb(p, DISC_DSB) | (aic_inb(p, DISC_DSB + 1) << 8) );
8706 p->ultraenb =
8707 (aic_inb(p, ULTRA_ENB) | (aic_inb(p, ULTRA_ENB + 1) << 8) );
8708 sc->device_flags[i] = (p->discenable & mask) ? CFDISC : 0;
8709 if (aic_inb(p, TARG_SCSIRATE + i) & WIDEXFER)
8710 sc->device_flags[i] |= CFWIDEB;
8711 if (p->features & AHC_ULTRA2)
8713 if (aic_inb(p, TARG_OFFSET + i))
8715 sc->device_flags[i] |= CFSYNCH;
8716 sc->device_flags[i] |= (aic_inb(p, TARG_SCSIRATE + i) & 0x07);
8717 if ( (aic_inb(p, TARG_SCSIRATE + i) & 0x18) == 0x18 )
8718 sc->device_flags[i] |= CFSYNCHISULTRA;
8721 else
8723 if (aic_inb(p, TARG_SCSIRATE + i) & ~WIDEXFER)
8725 sc->device_flags[i] |= CFSYNCH;
8726 if (p->features & AHC_ULTRA)
8727 sc->device_flags[i] |= ((p->ultraenb & mask) ?
8728 CFSYNCHISULTRA : 0);
8732 else
8735 * Assume the BIOS has NOT been run on this card and nothing between
8736 * the card and the devices is configured yet.
8738 sc->device_flags[i] = CFDISC;
8739 if (p->features & AHC_WIDE)
8740 sc->device_flags[i] |= CFWIDEB;
8741 if (p->features & AHC_ULTRA3)
8742 sc->device_flags[i] |= 2;
8743 else if (p->features & AHC_ULTRA2)
8744 sc->device_flags[i] |= 3;
8745 else if (p->features & AHC_ULTRA)
8746 sc->device_flags[i] |= CFSYNCHISULTRA;
8747 sc->device_flags[i] |= CFSYNCH;
8748 aic_outb(p, 0, TARG_SCSIRATE + i);
8749 if (p->features & AHC_ULTRA2)
8750 aic_outb(p, 0, TARG_OFFSET + i);
8753 if (sc->device_flags[i] & CFDISC)
8755 p->discenable |= mask;
8757 if (p->flags & AHC_NEWEEPROM_FMT)
8759 if ( !(p->features & AHC_ULTRA2) )
8762 * I know of two different Ultra BIOSes that do this differently.
8763 * One on the Gigabyte 6BXU mb that wants flags[i] & CFXFER to
8764 * be == to 0x03 and SYNCHISULTRA to be true to mean 40MByte/s
8765 * while on the IBM Netfinity 5000 they want the same thing
8766 * to be something else, while flags[i] & CFXFER == 0x03 and
8767 * SYNCHISULTRA false should be 40MByte/s. So, we set both to
8768 * 40MByte/s and the lower speeds be damned. People will have
8769 * to select around the conversely mapped lower speeds in order
8770 * to select lower speeds on these boards.
8772 if ( (sc->device_flags[i] & CFNEWULTRAFORMAT) &&
8773 ((sc->device_flags[i] & CFXFER) == 0x03) )
8775 sc->device_flags[i] &= ~CFXFER;
8776 sc->device_flags[i] |= CFSYNCHISULTRA;
8778 if (sc->device_flags[i] & CFSYNCHISULTRA)
8780 p->ultraenb |= mask;
8783 else if ( !(sc->device_flags[i] & CFNEWULTRAFORMAT) &&
8784 (p->features & AHC_ULTRA2) &&
8785 (sc->device_flags[i] & CFSYNCHISULTRA) )
8787 p->ultraenb |= mask;
8790 else if (sc->adapter_control & CFULTRAEN)
8792 p->ultraenb |= mask;
8794 if ( (sc->device_flags[i] & CFSYNCH) == 0)
8796 sc->device_flags[i] &= ~CFXFER;
8797 p->ultraenb &= ~mask;
8798 p->user[i].offset = 0;
8799 p->user[i].period = 0;
8800 p->user[i].options = 0;
8802 else
8804 if (p->features & AHC_ULTRA3)
8806 p->user[i].offset = MAX_OFFSET_ULTRA2;
8807 if( (sc->device_flags[i] & CFXFER) < 0x03 )
8809 scsirate = (sc->device_flags[i] & CFXFER);
8810 p->user[i].options = MSG_EXT_PPR_OPTION_DT_CRC;
8812 else
8814 scsirate = (sc->device_flags[i] & CFXFER) |
8815 ((p->ultraenb & mask) ? 0x18 : 0x10);
8816 p->user[i].options = 0;
8818 p->user[i].period = aic7xxx_find_period(p, scsirate,
8819 AHC_SYNCRATE_ULTRA3);
8821 else if (p->features & AHC_ULTRA2)
8823 p->user[i].offset = MAX_OFFSET_ULTRA2;
8824 scsirate = (sc->device_flags[i] & CFXFER) |
8825 ((p->ultraenb & mask) ? 0x18 : 0x10);
8826 p->user[i].options = 0;
8827 p->user[i].period = aic7xxx_find_period(p, scsirate,
8828 AHC_SYNCRATE_ULTRA2);
8830 else
8832 scsirate = (sc->device_flags[i] & CFXFER) << 4;
8833 p->user[i].options = 0;
8834 p->user[i].offset = MAX_OFFSET_8BIT;
8835 if (p->features & AHC_ULTRA)
8837 short ultraenb;
8838 ultraenb = aic_inb(p, ULTRA_ENB) |
8839 (aic_inb(p, ULTRA_ENB + 1) << 8);
8840 p->user[i].period = aic7xxx_find_period(p, scsirate,
8841 (p->ultraenb & mask) ?
8842 AHC_SYNCRATE_ULTRA :
8843 AHC_SYNCRATE_FAST);
8845 else
8846 p->user[i].period = aic7xxx_find_period(p, scsirate,
8847 AHC_SYNCRATE_FAST);
8850 if ( (sc->device_flags[i] & CFWIDEB) && (p->features & AHC_WIDE) )
8852 p->user[i].width = MSG_EXT_WDTR_BUS_16_BIT;
8854 else
8856 p->user[i].width = MSG_EXT_WDTR_BUS_8_BIT;
8859 aic_outb(p, ~(p->discenable & 0xFF), DISC_DSB);
8860 aic_outb(p, ~((p->discenable >> 8) & 0xFF), DISC_DSB + 1);
8863 * We set the p->ultraenb from the SEEPROM to begin with, but now we make
8864 * it match what is already down in the card. If we are doing a reset
8865 * on the card then this will get put back to a default state anyway.
8866 * This allows us to not have to pre-emptively negotiate when using the
8867 * no_reset option.
8869 if (p->features & AHC_ULTRA)
8870 p->ultraenb = aic_inb(p, ULTRA_ENB) | (aic_inb(p, ULTRA_ENB + 1) << 8);
8873 scsi_conf = (p->scsi_id & HSCSIID);
8875 if(have_seeprom)
8877 p->adapter_control = sc->adapter_control;
8878 p->bios_control = sc->bios_control;
8880 switch (p->chip & AHC_CHIPID_MASK)
8882 case AHC_AIC7895:
8883 case AHC_AIC7896:
8884 case AHC_AIC7899:
8885 if (p->adapter_control & CFBPRIMARY)
8886 p->flags |= AHC_CHANNEL_B_PRIMARY;
8887 default:
8888 break;
8891 if (sc->adapter_control & CFSPARITY)
8892 scsi_conf |= ENSPCHK;
8894 else
8896 scsi_conf |= ENSPCHK | RESET_SCSI;
8900 * Only set the SCSICONF and SCSICONF + 1 registers if we are a PCI card.
8901 * The 2842 and 2742 cards already have these registers set and we don't
8902 * want to muck with them since we don't set all the bits they do.
8904 if ( (p->chip & ~AHC_CHIPID_MASK) == AHC_PCI )
8906 /* Set the host ID */
8907 aic_outb(p, scsi_conf, SCSICONF);
8908 /* In case we are a wide card */
8909 aic_outb(p, p->scsi_id, SCSICONF + 1);
8913 /*+F*************************************************************************
8914 * Function:
8915 * aic7xxx_configure_bugs
8917 * Description:
8918 * Take the card passed in and set the appropriate bug flags based upon
8919 * the card model. Also make any changes needed to device registers or
8920 * PCI registers while we are here.
8921 *-F*************************************************************************/
8922 static void
8923 aic7xxx_configure_bugs(struct aic7xxx_host *p)
8925 unsigned short tmp_word;
8927 switch(p->chip & AHC_CHIPID_MASK)
8929 case AHC_AIC7860:
8930 p->bugs |= AHC_BUG_PCI_2_1_RETRY;
8931 /* fall through */
8932 case AHC_AIC7850:
8933 case AHC_AIC7870:
8934 p->bugs |= AHC_BUG_TMODE_WIDEODD | AHC_BUG_CACHETHEN | AHC_BUG_PCI_MWI;
8935 break;
8936 case AHC_AIC7880:
8937 p->bugs |= AHC_BUG_TMODE_WIDEODD | AHC_BUG_PCI_2_1_RETRY |
8938 AHC_BUG_CACHETHEN | AHC_BUG_PCI_MWI;
8939 break;
8940 case AHC_AIC7890:
8941 p->bugs |= AHC_BUG_AUTOFLUSH | AHC_BUG_CACHETHEN;
8942 break;
8943 case AHC_AIC7892:
8944 p->bugs |= AHC_BUG_SCBCHAN_UPLOAD;
8945 break;
8946 case AHC_AIC7895:
8947 p->bugs |= AHC_BUG_TMODE_WIDEODD | AHC_BUG_PCI_2_1_RETRY |
8948 AHC_BUG_CACHETHEN | AHC_BUG_PCI_MWI;
8949 break;
8950 case AHC_AIC7896:
8951 p->bugs |= AHC_BUG_CACHETHEN_DIS;
8952 break;
8953 case AHC_AIC7899:
8954 p->bugs |= AHC_BUG_SCBCHAN_UPLOAD;
8955 break;
8956 default:
8957 /* Nothing to do */
8958 break;
8962 * Now handle the bugs that require PCI register or card register tweaks
8964 pci_read_config_word(p->pdev, PCI_COMMAND, &tmp_word);
8965 if(p->bugs & AHC_BUG_PCI_MWI)
8967 tmp_word &= ~PCI_COMMAND_INVALIDATE;
8969 else
8971 tmp_word |= PCI_COMMAND_INVALIDATE;
8973 pci_write_config_word(p->pdev, PCI_COMMAND, tmp_word);
8975 if(p->bugs & AHC_BUG_CACHETHEN)
8977 aic_outb(p, aic_inb(p, DSCOMMAND0) & ~CACHETHEN, DSCOMMAND0);
8979 else if (p->bugs & AHC_BUG_CACHETHEN_DIS)
8981 aic_outb(p, aic_inb(p, DSCOMMAND0) | CACHETHEN, DSCOMMAND0);
8984 return;
8988 /*+F*************************************************************************
8989 * Function:
8990 * aic7xxx_detect
8992 * Description:
8993 * Try to detect and register an Adaptec 7770 or 7870 SCSI controller.
8995 * XXX - This should really be called aic7xxx_probe(). A sequence of
8996 * probe(), attach()/detach(), and init() makes more sense than
8997 * one do-it-all function. This may be useful when (and if) the
8998 * mid-level SCSI code is overhauled.
8999 *-F*************************************************************************/
9000 static int
9001 aic7xxx_detect(Scsi_Host_Template *template)
9003 struct aic7xxx_host *temp_p = NULL;
9004 struct aic7xxx_host *current_p = NULL;
9005 struct aic7xxx_host *list_p = NULL;
9006 int found = 0;
9007 #if defined(__i386__) || defined(__alpha__)
9008 ahc_flag_type flags = 0;
9009 int type;
9010 #endif
9011 unsigned char sxfrctl1;
9012 #if defined(__i386__) || defined(__alpha__)
9013 unsigned char hcntrl, hostconf;
9014 unsigned int slot, base;
9015 #endif
9017 #ifdef MODULE
9019 * If we are called as a module, the aic7xxx pointer may not be null
9020 * and it would point to our bootup string, just like on the lilo
9021 * command line. IF not NULL, then process this config string with
9022 * aic7xxx_setup
9024 if(aic7xxx)
9025 aic7xxx_setup(aic7xxx);
9026 #endif
9028 template->proc_name = "aic7xxx";
9029 template->sg_tablesize = AIC7XXX_MAX_SG;
9032 #ifdef CONFIG_PCI
9034 * PCI-bus probe.
9037 struct
9039 unsigned short vendor_id;
9040 unsigned short device_id;
9041 ahc_chip chip;
9042 ahc_flag_type flags;
9043 ahc_feature features;
9044 int board_name_index;
9045 unsigned short seeprom_size;
9046 unsigned short seeprom_type;
9047 } const aic_pdevs[] = {
9048 {PCI_VENDOR_ID_ADAPTEC, PCI_DEVICE_ID_ADAPTEC_7810, AHC_NONE,
9049 AHC_FNONE, AHC_FENONE, 1,
9050 32, C46 },
9051 {PCI_VENDOR_ID_ADAPTEC, PCI_DEVICE_ID_ADAPTEC_7850, AHC_AIC7850,
9052 AHC_PAGESCBS, AHC_AIC7850_FE, 5,
9053 32, C46 },
9054 {PCI_VENDOR_ID_ADAPTEC, PCI_DEVICE_ID_ADAPTEC_7855, AHC_AIC7850,
9055 AHC_PAGESCBS, AHC_AIC7850_FE, 6,
9056 32, C46 },
9057 {PCI_VENDOR_ID_ADAPTEC, PCI_DEVICE_ID_ADAPTEC_7821, AHC_AIC7860,
9058 AHC_PAGESCBS | AHC_NEWEEPROM_FMT | AHC_BIOS_ENABLED,
9059 AHC_AIC7860_FE, 7,
9060 32, C46 },
9061 {PCI_VENDOR_ID_ADAPTEC, PCI_DEVICE_ID_ADAPTEC_3860, AHC_AIC7860,
9062 AHC_PAGESCBS | AHC_NEWEEPROM_FMT | AHC_BIOS_ENABLED,
9063 AHC_AIC7860_FE, 7,
9064 32, C46 },
9065 {PCI_VENDOR_ID_ADAPTEC, PCI_DEVICE_ID_ADAPTEC_38602, AHC_AIC7860,
9066 AHC_PAGESCBS | AHC_NEWEEPROM_FMT | AHC_BIOS_ENABLED,
9067 AHC_AIC7860_FE, 7,
9068 32, C46 },
9069 {PCI_VENDOR_ID_ADAPTEC, PCI_DEVICE_ID_ADAPTEC_38602, AHC_AIC7860,
9070 AHC_PAGESCBS | AHC_NEWEEPROM_FMT | AHC_BIOS_ENABLED,
9071 AHC_AIC7860_FE, 7,
9072 32, C46 },
9073 {PCI_VENDOR_ID_ADAPTEC, PCI_DEVICE_ID_ADAPTEC_7860, AHC_AIC7860,
9074 AHC_PAGESCBS | AHC_NEWEEPROM_FMT | AHC_BIOS_ENABLED | AHC_MOTHERBOARD,
9075 AHC_AIC7860_FE, 7,
9076 32, C46 },
9077 {PCI_VENDOR_ID_ADAPTEC, PCI_DEVICE_ID_ADAPTEC_7861, AHC_AIC7860,
9078 AHC_PAGESCBS | AHC_NEWEEPROM_FMT | AHC_BIOS_ENABLED,
9079 AHC_AIC7860_FE, 8,
9080 32, C46 },
9081 {PCI_VENDOR_ID_ADAPTEC, PCI_DEVICE_ID_ADAPTEC_7870, AHC_AIC7870,
9082 AHC_PAGESCBS | AHC_BIOS_ENABLED | AHC_MOTHERBOARD,
9083 AHC_AIC7870_FE, 9,
9084 32, C46 },
9085 {PCI_VENDOR_ID_ADAPTEC, PCI_DEVICE_ID_ADAPTEC_7871, AHC_AIC7870,
9086 AHC_PAGESCBS | AHC_BIOS_ENABLED, AHC_AIC7870_FE, 10,
9087 32, C46 },
9088 {PCI_VENDOR_ID_ADAPTEC, PCI_DEVICE_ID_ADAPTEC_7872, AHC_AIC7870,
9089 AHC_PAGESCBS | AHC_BIOS_ENABLED | AHC_MULTI_CHANNEL,
9090 AHC_AIC7870_FE, 11,
9091 32, C56_66 },
9092 {PCI_VENDOR_ID_ADAPTEC, PCI_DEVICE_ID_ADAPTEC_7873, AHC_AIC7870,
9093 AHC_PAGESCBS | AHC_BIOS_ENABLED | AHC_MULTI_CHANNEL,
9094 AHC_AIC7870_FE, 12,
9095 32, C56_66 },
9096 {PCI_VENDOR_ID_ADAPTEC, PCI_DEVICE_ID_ADAPTEC_7874, AHC_AIC7870,
9097 AHC_PAGESCBS | AHC_BIOS_ENABLED, AHC_AIC7870_FE, 13,
9098 32, C46 },
9099 {PCI_VENDOR_ID_ADAPTEC, PCI_DEVICE_ID_ADAPTEC_7880, AHC_AIC7880,
9100 AHC_PAGESCBS | AHC_BIOS_ENABLED | AHC_MOTHERBOARD,
9101 AHC_AIC7880_FE, 14,
9102 32, C46 },
9103 {PCI_VENDOR_ID_ADAPTEC, PCI_DEVICE_ID_ADAPTEC_7881, AHC_AIC7880,
9104 AHC_PAGESCBS | AHC_BIOS_ENABLED, AHC_AIC7880_FE, 15,
9105 32, C46 },
9106 {PCI_VENDOR_ID_ADAPTEC, PCI_DEVICE_ID_ADAPTEC_7882, AHC_AIC7880,
9107 AHC_PAGESCBS | AHC_BIOS_ENABLED | AHC_MULTI_CHANNEL,
9108 AHC_AIC7880_FE, 16,
9109 32, C56_66 },
9110 {PCI_VENDOR_ID_ADAPTEC, PCI_DEVICE_ID_ADAPTEC_7883, AHC_AIC7880,
9111 AHC_PAGESCBS | AHC_BIOS_ENABLED | AHC_MULTI_CHANNEL,
9112 AHC_AIC7880_FE, 17,
9113 32, C56_66 },
9114 {PCI_VENDOR_ID_ADAPTEC, PCI_DEVICE_ID_ADAPTEC_7884, AHC_AIC7880,
9115 AHC_PAGESCBS | AHC_BIOS_ENABLED, AHC_AIC7880_FE, 18,
9116 32, C46 },
9117 {PCI_VENDOR_ID_ADAPTEC, PCI_DEVICE_ID_ADAPTEC_7885, AHC_AIC7880,
9118 AHC_PAGESCBS | AHC_BIOS_ENABLED, AHC_AIC7880_FE, 18,
9119 32, C46 },
9120 {PCI_VENDOR_ID_ADAPTEC, PCI_DEVICE_ID_ADAPTEC_7886, AHC_AIC7880,
9121 AHC_PAGESCBS | AHC_BIOS_ENABLED, AHC_AIC7880_FE, 18,
9122 32, C46 },
9123 {PCI_VENDOR_ID_ADAPTEC, PCI_DEVICE_ID_ADAPTEC_7887, AHC_AIC7880,
9124 AHC_PAGESCBS | AHC_BIOS_ENABLED, AHC_AIC7880_FE | AHC_NEW_AUTOTERM, 19,
9125 32, C46 },
9126 {PCI_VENDOR_ID_ADAPTEC, PCI_DEVICE_ID_ADAPTEC_7888, AHC_AIC7880,
9127 AHC_PAGESCBS | AHC_BIOS_ENABLED, AHC_AIC7880_FE, 18,
9128 32, C46 },
9129 {PCI_VENDOR_ID_ADAPTEC, PCI_DEVICE_ID_ADAPTEC_7895, AHC_AIC7895,
9130 AHC_PAGESCBS | AHC_NEWEEPROM_FMT | AHC_BIOS_ENABLED | AHC_MULTI_CHANNEL,
9131 AHC_AIC7895_FE, 20,
9132 32, C56_66 },
9133 {PCI_VENDOR_ID_ADAPTEC2, PCI_DEVICE_ID_ADAPTEC2_7890, AHC_AIC7890,
9134 AHC_PAGESCBS | AHC_NEWEEPROM_FMT | AHC_BIOS_ENABLED,
9135 AHC_AIC7890_FE, 21,
9136 32, C46 },
9137 {PCI_VENDOR_ID_ADAPTEC2, PCI_DEVICE_ID_ADAPTEC2_7890B, AHC_AIC7890,
9138 AHC_PAGESCBS | AHC_NEWEEPROM_FMT | AHC_BIOS_ENABLED,
9139 AHC_AIC7890_FE, 21,
9140 32, C46 },
9141 {PCI_VENDOR_ID_ADAPTEC2, PCI_DEVICE_ID_ADAPTEC2_2930U2, AHC_AIC7890,
9142 AHC_PAGESCBS | AHC_NEWEEPROM_FMT | AHC_BIOS_ENABLED,
9143 AHC_AIC7890_FE, 22,
9144 32, C46 },
9145 {PCI_VENDOR_ID_ADAPTEC2, PCI_DEVICE_ID_ADAPTEC2_2940U2, AHC_AIC7890,
9146 AHC_PAGESCBS | AHC_NEWEEPROM_FMT | AHC_BIOS_ENABLED,
9147 AHC_AIC7890_FE, 23,
9148 32, C46 },
9149 {PCI_VENDOR_ID_ADAPTEC2, PCI_DEVICE_ID_ADAPTEC2_7896, AHC_AIC7896,
9150 AHC_PAGESCBS | AHC_NEWEEPROM_FMT | AHC_BIOS_ENABLED | AHC_MULTI_CHANNEL,
9151 AHC_AIC7896_FE, 24,
9152 32, C56_66 },
9153 {PCI_VENDOR_ID_ADAPTEC2, PCI_DEVICE_ID_ADAPTEC2_3940U2, AHC_AIC7896,
9154 AHC_PAGESCBS | AHC_NEWEEPROM_FMT | AHC_BIOS_ENABLED | AHC_MULTI_CHANNEL,
9155 AHC_AIC7896_FE, 25,
9156 32, C56_66 },
9157 {PCI_VENDOR_ID_ADAPTEC2, PCI_DEVICE_ID_ADAPTEC2_3950U2D, AHC_AIC7896,
9158 AHC_PAGESCBS | AHC_NEWEEPROM_FMT | AHC_BIOS_ENABLED | AHC_MULTI_CHANNEL,
9159 AHC_AIC7896_FE, 26,
9160 32, C56_66 },
9161 {PCI_VENDOR_ID_ADAPTEC, PCI_DEVICE_ID_ADAPTEC_1480A, AHC_AIC7860,
9162 AHC_PAGESCBS | AHC_NEWEEPROM_FMT | AHC_BIOS_ENABLED | AHC_NO_STPWEN,
9163 AHC_AIC7860_FE, 27,
9164 32, C46 },
9165 {PCI_VENDOR_ID_ADAPTEC2, PCI_DEVICE_ID_ADAPTEC2_7892A, AHC_AIC7892,
9166 AHC_PAGESCBS | AHC_NEWEEPROM_FMT | AHC_BIOS_ENABLED,
9167 AHC_AIC7892_FE, 28,
9168 32, C46 },
9169 {PCI_VENDOR_ID_ADAPTEC2, PCI_DEVICE_ID_ADAPTEC2_7892B, AHC_AIC7892,
9170 AHC_PAGESCBS | AHC_NEWEEPROM_FMT | AHC_BIOS_ENABLED,
9171 AHC_AIC7892_FE, 28,
9172 32, C46 },
9173 {PCI_VENDOR_ID_ADAPTEC2, PCI_DEVICE_ID_ADAPTEC2_7892D, AHC_AIC7892,
9174 AHC_PAGESCBS | AHC_NEWEEPROM_FMT | AHC_BIOS_ENABLED,
9175 AHC_AIC7892_FE, 28,
9176 32, C46 },
9177 {PCI_VENDOR_ID_ADAPTEC2, PCI_DEVICE_ID_ADAPTEC2_7892P, AHC_AIC7892,
9178 AHC_PAGESCBS | AHC_NEWEEPROM_FMT | AHC_BIOS_ENABLED,
9179 AHC_AIC7892_FE, 28,
9180 32, C46 },
9181 {PCI_VENDOR_ID_ADAPTEC2, PCI_DEVICE_ID_ADAPTEC2_7899A, AHC_AIC7899,
9182 AHC_PAGESCBS | AHC_NEWEEPROM_FMT | AHC_BIOS_ENABLED | AHC_MULTI_CHANNEL,
9183 AHC_AIC7899_FE, 29,
9184 32, C56_66 },
9185 {PCI_VENDOR_ID_ADAPTEC2, PCI_DEVICE_ID_ADAPTEC2_7899B, AHC_AIC7899,
9186 AHC_PAGESCBS | AHC_NEWEEPROM_FMT | AHC_BIOS_ENABLED | AHC_MULTI_CHANNEL,
9187 AHC_AIC7899_FE, 29,
9188 32, C56_66 },
9189 {PCI_VENDOR_ID_ADAPTEC2, PCI_DEVICE_ID_ADAPTEC2_7899D, AHC_AIC7899,
9190 AHC_PAGESCBS | AHC_NEWEEPROM_FMT | AHC_BIOS_ENABLED | AHC_MULTI_CHANNEL,
9191 AHC_AIC7899_FE, 29,
9192 32, C56_66 },
9193 {PCI_VENDOR_ID_ADAPTEC2, PCI_DEVICE_ID_ADAPTEC2_7899P, AHC_AIC7899,
9194 AHC_PAGESCBS | AHC_NEWEEPROM_FMT | AHC_BIOS_ENABLED | AHC_MULTI_CHANNEL,
9195 AHC_AIC7899_FE, 29,
9196 32, C56_66 },
9199 unsigned short command;
9200 unsigned int devconfig, i, oldverbose;
9201 struct pci_dev *pdev = NULL;
9203 for (i = 0; i < NUMBER(aic_pdevs); i++)
9205 pdev = NULL;
9206 while ((pdev = pci_find_device(aic_pdevs[i].vendor_id,
9207 aic_pdevs[i].device_id,
9208 pdev))) {
9209 if (pci_enable_device(pdev))
9210 continue;
9211 if ( i == 0 ) /* We found one, but it's the 7810 RAID cont. */
9213 if (aic7xxx_verbose & (VERBOSE_PROBE|VERBOSE_PROBE2))
9215 printk(KERN_INFO "aic7xxx: The 7810 RAID controller is not "
9216 "supported by\n");
9217 printk(KERN_INFO " this driver, we are ignoring it.\n");
9220 else if ( (temp_p = kmalloc(sizeof(struct aic7xxx_host),
9221 GFP_ATOMIC)) != NULL )
9223 memset(temp_p, 0, sizeof(struct aic7xxx_host));
9224 temp_p->chip = aic_pdevs[i].chip | AHC_PCI;
9225 temp_p->flags = aic_pdevs[i].flags;
9226 temp_p->features = aic_pdevs[i].features;
9227 temp_p->board_name_index = aic_pdevs[i].board_name_index;
9228 temp_p->sc_size = aic_pdevs[i].seeprom_size;
9229 temp_p->sc_type = aic_pdevs[i].seeprom_type;
9232 * Read sundry information from PCI BIOS.
9234 temp_p->irq = pdev->irq;
9235 temp_p->pdev = pdev;
9236 temp_p->pci_bus = pdev->bus->number;
9237 temp_p->pci_device_fn = pdev->devfn;
9238 temp_p->base = pci_resource_start(pdev, 0);
9239 temp_p->mbase = pci_resource_start(pdev, 1);
9240 current_p = list_p;
9241 while(current_p && temp_p)
9243 if ( ((current_p->pci_bus == temp_p->pci_bus) &&
9244 (current_p->pci_device_fn == temp_p->pci_device_fn)) ||
9245 (temp_p->base && (current_p->base == temp_p->base)) ||
9246 (temp_p->mbase && (current_p->mbase == temp_p->mbase)) )
9248 /* duplicate PCI entry, skip it */
9249 kfree(temp_p);
9250 continue;
9252 current_p = current_p->next;
9254 if(pci_request_regions(temp_p->pdev, "aic7xxx"))
9256 printk("aic7xxx: <%s> at PCI %d/%d/%d\n",
9257 board_names[aic_pdevs[i].board_name_index],
9258 temp_p->pci_bus,
9259 PCI_SLOT(temp_p->pci_device_fn),
9260 PCI_FUNC(temp_p->pci_device_fn));
9261 printk("aic7xxx: I/O ports already in use, ignoring.\n");
9262 kfree(temp_p);
9263 continue;
9266 if (aic7xxx_verbose & VERBOSE_PROBE2)
9267 printk("aic7xxx: <%s> at PCI %d/%d\n",
9268 board_names[aic_pdevs[i].board_name_index],
9269 PCI_SLOT(pdev->devfn),
9270 PCI_FUNC(pdev->devfn));
9271 pci_read_config_word(pdev, PCI_COMMAND, &command);
9272 if (aic7xxx_verbose & VERBOSE_PROBE2)
9274 printk("aic7xxx: Initial PCI_COMMAND value was 0x%x\n",
9275 (int)command);
9277 #ifdef AIC7XXX_STRICT_PCI_SETUP
9278 command |= PCI_COMMAND_SERR | PCI_COMMAND_PARITY |
9279 PCI_COMMAND_MASTER | PCI_COMMAND_MEMORY | PCI_COMMAND_IO;
9280 #else
9281 command |= PCI_COMMAND_MASTER | PCI_COMMAND_MEMORY | PCI_COMMAND_IO;
9282 #endif
9283 command &= ~PCI_COMMAND_INVALIDATE;
9284 if (aic7xxx_pci_parity == 0)
9285 command &= ~(PCI_COMMAND_SERR | PCI_COMMAND_PARITY);
9286 pci_write_config_word(pdev, PCI_COMMAND, command);
9287 #ifdef AIC7XXX_STRICT_PCI_SETUP
9288 pci_read_config_dword(pdev, DEVCONFIG, &devconfig);
9289 if (aic7xxx_verbose & VERBOSE_PROBE2)
9291 printk("aic7xxx: Initial DEVCONFIG value was 0x%x\n", devconfig);
9293 devconfig |= 0x80000040;
9294 pci_write_config_dword(pdev, DEVCONFIG, devconfig);
9295 #endif /* AIC7XXX_STRICT_PCI_SETUP */
9297 temp_p->unpause = INTEN;
9298 temp_p->pause = temp_p->unpause | PAUSE;
9299 if ( ((temp_p->base == 0) &&
9300 (temp_p->mbase == 0)) ||
9301 (temp_p->irq == 0) )
9303 printk("aic7xxx: <%s> at PCI %d/%d/%d\n",
9304 board_names[aic_pdevs[i].board_name_index],
9305 temp_p->pci_bus,
9306 PCI_SLOT(temp_p->pci_device_fn),
9307 PCI_FUNC(temp_p->pci_device_fn));
9308 printk("aic7xxx: Controller disabled by BIOS, ignoring.\n");
9309 goto skip_pci_controller;
9312 #ifdef MMAPIO
9313 if ( !(temp_p->base) || !(temp_p->flags & AHC_MULTI_CHANNEL) ||
9314 ((temp_p->chip != (AHC_AIC7870 | AHC_PCI)) &&
9315 (temp_p->chip != (AHC_AIC7880 | AHC_PCI))) )
9317 unsigned long page_offset, base;
9319 base = temp_p->mbase & PAGE_MASK;
9320 page_offset = temp_p->mbase - base;
9321 temp_p->maddr = ioremap_nocache(base, page_offset + 256);
9322 if(temp_p->maddr)
9324 temp_p->maddr += page_offset;
9326 * We need to check the I/O with the MMAPed address. Some machines
9327 * simply fail to work with MMAPed I/O and certain controllers.
9329 if(aic_inb(temp_p, HCNTRL) == 0xff)
9332 * OK.....we failed our test....go back to programmed I/O
9334 printk(KERN_INFO "aic7xxx: <%s> at PCI %d/%d/%d\n",
9335 board_names[aic_pdevs[i].board_name_index],
9336 temp_p->pci_bus,
9337 PCI_SLOT(temp_p->pci_device_fn),
9338 PCI_FUNC(temp_p->pci_device_fn));
9339 printk(KERN_INFO "aic7xxx: MMAPed I/O failed, reverting to "
9340 "Programmed I/O.\n");
9341 iounmap((void *) (((unsigned long) temp_p->maddr) & PAGE_MASK));
9342 temp_p->maddr = 0;
9343 if(temp_p->base == 0)
9345 printk("aic7xxx: <%s> at PCI %d/%d/%d\n",
9346 board_names[aic_pdevs[i].board_name_index],
9347 temp_p->pci_bus,
9348 PCI_SLOT(temp_p->pci_device_fn),
9349 PCI_FUNC(temp_p->pci_device_fn));
9350 printk("aic7xxx: Controller disabled by BIOS, ignoring.\n");
9351 goto skip_pci_controller;
9356 #endif
9359 * We HAVE to make sure the first pause_sequencer() and all other
9360 * subsequent I/O that isn't PCI config space I/O takes place
9361 * after the MMAPed I/O region is configured and tested. The
9362 * problem is the PowerPC architecture that doesn't support
9363 * programmed I/O at all, so we have to have the MMAP I/O set up
9364 * for this pause to even work on those machines.
9366 pause_sequencer(temp_p);
9369 * Clear out any pending PCI error status messages. Also set
9370 * verbose to 0 so that we don't emit strange PCI error messages
9371 * while cleaning out the current status bits.
9373 oldverbose = aic7xxx_verbose;
9374 aic7xxx_verbose = 0;
9375 aic7xxx_pci_intr(temp_p);
9376 aic7xxx_verbose = oldverbose;
9378 temp_p->bios_address = 0;
9381 * Remember how the card was setup in case there is no seeprom.
9383 if (temp_p->features & AHC_ULTRA2)
9384 temp_p->scsi_id = aic_inb(temp_p, SCSIID_ULTRA2) & OID;
9385 else
9386 temp_p->scsi_id = aic_inb(temp_p, SCSIID) & OID;
9388 * Get current termination setting
9390 sxfrctl1 = aic_inb(temp_p, SXFRCTL1);
9392 if (aic7xxx_chip_reset(temp_p) == -1)
9394 goto skip_pci_controller;
9397 * Very quickly put the term setting back into the register since
9398 * the chip reset may cause odd things to happen. This is to keep
9399 * LVD busses with lots of drives from draining the power out of
9400 * the diffsense line before we get around to running the
9401 * configure_termination() function. Also restore the STPWLEVEL
9402 * bit of DEVCONFIG
9404 aic_outb(temp_p, sxfrctl1, SXFRCTL1);
9405 pci_write_config_dword(temp_p->pdev, DEVCONFIG, devconfig);
9406 sxfrctl1 &= STPWEN;
9409 * We need to set the CHNL? assignments before loading the SEEPROM
9410 * The 3940 and 3985 cards (original stuff, not any of the later
9411 * stuff) are 7870 and 7880 class chips. The Ultra2 stuff falls
9412 * under 7896 and 7897. The 7895 is in a class by itself :)
9414 switch (temp_p->chip & AHC_CHIPID_MASK)
9416 case AHC_AIC7870: /* 3840 / 3985 */
9417 case AHC_AIC7880: /* 3840 UW / 3985 UW */
9418 if(temp_p->flags & AHC_MULTI_CHANNEL)
9420 switch(PCI_SLOT(temp_p->pci_device_fn))
9422 case 5:
9423 temp_p->flags |= AHC_CHNLB;
9424 break;
9425 case 8:
9426 temp_p->flags |= AHC_CHNLB;
9427 break;
9428 case 12:
9429 temp_p->flags |= AHC_CHNLC;
9430 break;
9431 default:
9432 break;
9435 break;
9437 case AHC_AIC7895: /* 7895 */
9438 case AHC_AIC7896: /* 7896/7 */
9439 case AHC_AIC7899: /* 7899 */
9440 if (PCI_FUNC(pdev->devfn) != 0)
9442 temp_p->flags |= AHC_CHNLB;
9445 * The 7895 is the only chipset that sets the SCBSIZE32 param
9446 * in the DEVCONFIG register. The Ultra2 chipsets use
9447 * the DSCOMMAND0 register instead.
9449 if ((temp_p->chip & AHC_CHIPID_MASK) == AHC_AIC7895)
9451 pci_read_config_dword(pdev, DEVCONFIG, &devconfig);
9452 devconfig |= SCBSIZE32;
9453 pci_write_config_dword(pdev, DEVCONFIG, devconfig);
9455 break;
9456 default:
9457 break;
9461 * Loading of the SEEPROM needs to come after we've set the flags
9462 * to indicate possible CHNLB and CHNLC assigments. Otherwise,
9463 * on 394x and 398x cards we'll end up reading the wrong settings
9464 * for channels B and C
9466 switch (temp_p->chip & AHC_CHIPID_MASK)
9468 case AHC_AIC7892:
9469 case AHC_AIC7899:
9470 aic_outb(temp_p, 0, SCAMCTL);
9472 * Switch to the alt mode of the chip...
9474 aic_outb(temp_p, aic_inb(temp_p, SFUNCT) | ALT_MODE, SFUNCT);
9476 * Set our options...the last two items set our CRC after x byte
9477 * count in target mode...
9479 aic_outb(temp_p, AUTO_MSGOUT_DE | DIS_MSGIN_DUALEDGE, OPTIONMODE);
9480 aic_outb(temp_p, 0x00, 0x0b);
9481 aic_outb(temp_p, 0x10, 0x0a);
9483 * switch back to normal mode...
9485 aic_outb(temp_p, aic_inb(temp_p, SFUNCT) & ~ALT_MODE, SFUNCT);
9486 aic_outb(temp_p, CRCVALCHKEN | CRCENDCHKEN | CRCREQCHKEN |
9487 TARGCRCENDEN | TARGCRCCNTEN,
9488 CRCCONTROL1);
9489 aic_outb(temp_p, ((aic_inb(temp_p, DSCOMMAND0) | USCBSIZE32 |
9490 MPARCKEN | CIOPARCKEN | CACHETHEN) &
9491 ~DPARCKEN), DSCOMMAND0);
9492 aic7xxx_load_seeprom(temp_p, &sxfrctl1);
9493 break;
9494 case AHC_AIC7890:
9495 case AHC_AIC7896:
9496 aic_outb(temp_p, 0, SCAMCTL);
9497 aic_outb(temp_p, (aic_inb(temp_p, DSCOMMAND0) |
9498 CACHETHEN | MPARCKEN | USCBSIZE32 |
9499 CIOPARCKEN) & ~DPARCKEN, DSCOMMAND0);
9500 aic7xxx_load_seeprom(temp_p, &sxfrctl1);
9501 break;
9502 case AHC_AIC7850:
9503 case AHC_AIC7860:
9505 * Set the DSCOMMAND0 register on these cards different from
9506 * on the 789x cards. Also, read the SEEPROM as well.
9508 aic_outb(temp_p, (aic_inb(temp_p, DSCOMMAND0) |
9509 CACHETHEN | MPARCKEN) & ~DPARCKEN,
9510 DSCOMMAND0);
9511 /* FALLTHROUGH */
9512 default:
9513 aic7xxx_load_seeprom(temp_p, &sxfrctl1);
9514 break;
9515 case AHC_AIC7880:
9517 * Check the rev of the chipset before we change DSCOMMAND0
9519 pci_read_config_dword(pdev, DEVCONFIG, &devconfig);
9520 if ((devconfig & 0xff) >= 1)
9522 aic_outb(temp_p, (aic_inb(temp_p, DSCOMMAND0) |
9523 CACHETHEN | MPARCKEN) & ~DPARCKEN,
9524 DSCOMMAND0);
9526 aic7xxx_load_seeprom(temp_p, &sxfrctl1);
9527 break;
9532 * and then we need another switch based on the type in order to
9533 * make sure the channel B primary flag is set properly on 7895
9534 * controllers....Arrrgggghhh!!! We also have to catch the fact
9535 * that when you disable the BIOS on the 7895 on the Intel DK440LX
9536 * motherboard, and possibly others, it only sets the BIOS disabled
9537 * bit on the A channel...I think I'm starting to lean towards
9538 * going postal....
9540 switch(temp_p->chip & AHC_CHIPID_MASK)
9542 case AHC_AIC7895:
9543 case AHC_AIC7896:
9544 case AHC_AIC7899:
9545 current_p = list_p;
9546 while(current_p != NULL)
9548 if ( (current_p->pci_bus == temp_p->pci_bus) &&
9549 (PCI_SLOT(current_p->pci_device_fn) ==
9550 PCI_SLOT(temp_p->pci_device_fn)) )
9552 if ( PCI_FUNC(current_p->pci_device_fn) == 0 )
9554 temp_p->flags |=
9555 (current_p->flags & AHC_CHANNEL_B_PRIMARY);
9556 temp_p->flags &= ~(AHC_BIOS_ENABLED|AHC_USEDEFAULTS);
9557 temp_p->flags |=
9558 (current_p->flags & (AHC_BIOS_ENABLED|AHC_USEDEFAULTS));
9560 else
9562 current_p->flags |=
9563 (temp_p->flags & AHC_CHANNEL_B_PRIMARY);
9564 current_p->flags &= ~(AHC_BIOS_ENABLED|AHC_USEDEFAULTS);
9565 current_p->flags |=
9566 (temp_p->flags & (AHC_BIOS_ENABLED|AHC_USEDEFAULTS));
9569 current_p = current_p->next;
9571 break;
9572 default:
9573 break;
9577 * We only support external SCB RAM on the 7895/6/7 chipsets.
9578 * We could support it on the 7890/1 easy enough, but I don't
9579 * know of any 7890/1 based cards that have it. I do know
9580 * of 7895/6/7 cards that have it and they work properly.
9582 switch(temp_p->chip & AHC_CHIPID_MASK)
9584 default:
9585 break;
9586 case AHC_AIC7895:
9587 case AHC_AIC7896:
9588 case AHC_AIC7899:
9589 pci_read_config_dword(pdev, DEVCONFIG, &devconfig);
9590 if (temp_p->features & AHC_ULTRA2)
9592 if ( (aic_inb(temp_p, DSCOMMAND0) & RAMPSM_ULTRA2) &&
9593 (aic7xxx_scbram) )
9595 aic_outb(temp_p,
9596 aic_inb(temp_p, DSCOMMAND0) & ~SCBRAMSEL_ULTRA2,
9597 DSCOMMAND0);
9598 temp_p->flags |= AHC_EXTERNAL_SRAM;
9599 devconfig |= EXTSCBPEN;
9601 else if (aic_inb(temp_p, DSCOMMAND0) & RAMPSM_ULTRA2)
9603 printk(KERN_INFO "aic7xxx: <%s> at PCI %d/%d/%d\n",
9604 board_names[aic_pdevs[i].board_name_index],
9605 temp_p->pci_bus,
9606 PCI_SLOT(temp_p->pci_device_fn),
9607 PCI_FUNC(temp_p->pci_device_fn));
9608 printk("aic7xxx: external SCB RAM detected, "
9609 "but not enabled\n");
9612 else
9614 if ((devconfig & RAMPSM) && (aic7xxx_scbram))
9616 devconfig &= ~SCBRAMSEL;
9617 devconfig |= EXTSCBPEN;
9618 temp_p->flags |= AHC_EXTERNAL_SRAM;
9620 else if (devconfig & RAMPSM)
9622 printk(KERN_INFO "aic7xxx: <%s> at PCI %d/%d/%d\n",
9623 board_names[aic_pdevs[i].board_name_index],
9624 temp_p->pci_bus,
9625 PCI_SLOT(temp_p->pci_device_fn),
9626 PCI_FUNC(temp_p->pci_device_fn));
9627 printk("aic7xxx: external SCB RAM detected, "
9628 "but not enabled\n");
9631 pci_write_config_dword(pdev, DEVCONFIG, devconfig);
9632 if ( (temp_p->flags & AHC_EXTERNAL_SRAM) &&
9633 (temp_p->flags & AHC_CHNLB) )
9634 aic_outb(temp_p, 1, CCSCBBADDR);
9635 break;
9639 * Take the LED out of diagnostic mode
9641 aic_outb(temp_p,
9642 (aic_inb(temp_p, SBLKCTL) & ~(DIAGLEDEN | DIAGLEDON)),
9643 SBLKCTL);
9646 * We don't know where this is set in the SEEPROM or by the
9647 * BIOS, so we default to 100%. On Ultra2 controllers, use 75%
9648 * instead.
9650 if (temp_p->features & AHC_ULTRA2)
9652 aic_outb(temp_p, RD_DFTHRSH_MAX | WR_DFTHRSH_MAX, DFF_THRSH);
9654 else
9656 aic_outb(temp_p, DFTHRSH_100, DSPCISTATUS);
9660 * Call our function to fixup any bugs that exist on this chipset.
9661 * This may muck with PCI settings and other device settings, so
9662 * make sure it's after all the other PCI and device register
9663 * tweaks so it can back out bad settings on specific broken cards.
9665 aic7xxx_configure_bugs(temp_p);
9667 if ( list_p == NULL )
9669 list_p = current_p = temp_p;
9671 else
9673 current_p = list_p;
9674 while(current_p->next != NULL)
9675 current_p = current_p->next;
9676 current_p->next = temp_p;
9678 temp_p->next = NULL;
9679 found++;
9680 continue;
9681 skip_pci_controller:
9682 pci_release_regions(temp_p->pdev);
9683 kfree(temp_p);
9684 } /* Found an Adaptec PCI device. */
9685 else /* Well, we found one, but we couldn't get any memory */
9687 printk("aic7xxx: Found <%s>\n",
9688 board_names[aic_pdevs[i].board_name_index]);
9689 printk(KERN_INFO "aic7xxx: Unable to allocate device memory, "
9690 "skipping.\n");
9692 } /* while(pdev=....) */
9693 } /* for PCI_DEVICES */
9695 #endif /* CONFIG_PCI */
9697 #if defined(__i386__) || defined(__alpha__)
9699 * EISA/VL-bus card signature probe.
9701 slot = MINSLOT;
9702 while ( (slot <= MAXSLOT) &&
9703 !(aic7xxx_no_probe) )
9705 base = SLOTBASE(slot) + MINREG;
9707 if (!request_region(base, MAXREG - MINREG, "aic7xxx"))
9710 * Some other driver has staked a
9711 * claim to this i/o region already.
9713 slot++;
9714 continue; /* back to the beginning of the for loop */
9716 flags = 0;
9717 type = aic7xxx_probe(slot, base + AHC_HID0, &flags);
9718 if (type == -1)
9720 release_region(base, MAXREG - MINREG);
9721 slot++;
9722 continue;
9724 temp_p = kmalloc(sizeof(struct aic7xxx_host), GFP_ATOMIC);
9725 if (temp_p == NULL)
9727 printk(KERN_WARNING "aic7xxx: Unable to allocate device space.\n");
9728 release_region(base, MAXREG - MINREG);
9729 slot++;
9730 continue; /* back to the beginning of the while loop */
9734 * Pause the card preserving the IRQ type. Allow the operator
9735 * to override the IRQ trigger.
9737 if (aic7xxx_irq_trigger == 1)
9738 hcntrl = IRQMS; /* Level */
9739 else if (aic7xxx_irq_trigger == 0)
9740 hcntrl = 0; /* Edge */
9741 else
9742 hcntrl = inb(base + HCNTRL) & IRQMS; /* Default */
9743 memset(temp_p, 0, sizeof(struct aic7xxx_host));
9744 temp_p->unpause = hcntrl | INTEN;
9745 temp_p->pause = hcntrl | PAUSE | INTEN;
9746 temp_p->base = base;
9747 temp_p->mbase = 0;
9748 temp_p->maddr = 0;
9749 temp_p->pci_bus = 0;
9750 temp_p->pci_device_fn = slot;
9751 aic_outb(temp_p, hcntrl | PAUSE, HCNTRL);
9752 while( (aic_inb(temp_p, HCNTRL) & PAUSE) == 0 ) ;
9753 if (aic7xxx_chip_reset(temp_p) == -1)
9754 temp_p->irq = 0;
9755 else
9756 temp_p->irq = aic_inb(temp_p, INTDEF) & 0x0F;
9757 temp_p->flags |= AHC_PAGESCBS;
9759 switch (temp_p->irq)
9761 case 9:
9762 case 10:
9763 case 11:
9764 case 12:
9765 case 14:
9766 case 15:
9767 break;
9769 default:
9770 printk(KERN_WARNING "aic7xxx: Host adapter uses unsupported IRQ "
9771 "level %d, ignoring.\n", temp_p->irq);
9772 kfree(temp_p);
9773 release_region(base, MAXREG - MINREG);
9774 slot++;
9775 continue; /* back to the beginning of the while loop */
9779 * We are commited now, everything has been checked and this card
9780 * has been found, now we just set it up
9784 * Insert our new struct into the list at the end
9786 if (list_p == NULL)
9788 list_p = current_p = temp_p;
9790 else
9792 current_p = list_p;
9793 while (current_p->next != NULL)
9794 current_p = current_p->next;
9795 current_p->next = temp_p;
9798 switch (type)
9800 case 0:
9801 temp_p->board_name_index = 2;
9802 if (aic7xxx_verbose & VERBOSE_PROBE2)
9803 printk("aic7xxx: <%s> at EISA %d\n",
9804 board_names[2], slot);
9805 /* FALLTHROUGH */
9806 case 1:
9808 temp_p->chip = AHC_AIC7770 | AHC_EISA;
9809 temp_p->features |= AHC_AIC7770_FE;
9810 temp_p->bios_control = aic_inb(temp_p, HA_274_BIOSCTRL);
9813 * Get the primary channel information. Right now we don't
9814 * do anything with this, but someday we will be able to inform
9815 * the mid-level SCSI code which channel is primary.
9817 if (temp_p->board_name_index == 0)
9819 temp_p->board_name_index = 3;
9820 if (aic7xxx_verbose & VERBOSE_PROBE2)
9821 printk("aic7xxx: <%s> at EISA %d\n",
9822 board_names[3], slot);
9824 if (temp_p->bios_control & CHANNEL_B_PRIMARY)
9826 temp_p->flags |= AHC_CHANNEL_B_PRIMARY;
9829 if ((temp_p->bios_control & BIOSMODE) == BIOSDISABLED)
9831 temp_p->flags &= ~AHC_BIOS_ENABLED;
9833 else
9835 temp_p->flags &= ~AHC_USEDEFAULTS;
9836 temp_p->flags |= AHC_BIOS_ENABLED;
9837 if ( (temp_p->bios_control & 0x20) == 0 )
9839 temp_p->bios_address = 0xcc000;
9840 temp_p->bios_address += (0x4000 * (temp_p->bios_control & 0x07));
9842 else
9844 temp_p->bios_address = 0xd0000;
9845 temp_p->bios_address += (0x8000 * (temp_p->bios_control & 0x06));
9848 temp_p->adapter_control = aic_inb(temp_p, SCSICONF) << 8;
9849 temp_p->adapter_control |= aic_inb(temp_p, SCSICONF + 1);
9850 if (temp_p->features & AHC_WIDE)
9852 temp_p->scsi_id = temp_p->adapter_control & HWSCSIID;
9853 temp_p->scsi_id_b = temp_p->scsi_id;
9855 else
9857 temp_p->scsi_id = (temp_p->adapter_control >> 8) & HSCSIID;
9858 temp_p->scsi_id_b = temp_p->adapter_control & HSCSIID;
9860 aic7xxx_load_seeprom(temp_p, &sxfrctl1);
9861 break;
9864 case 2:
9865 case 3:
9866 temp_p->chip = AHC_AIC7770 | AHC_VL;
9867 temp_p->features |= AHC_AIC7770_FE;
9868 if (type == 2)
9869 temp_p->flags |= AHC_BIOS_ENABLED;
9870 else
9871 temp_p->flags &= ~AHC_BIOS_ENABLED;
9872 if (aic_inb(temp_p, SCSICONF) & TERM_ENB)
9873 sxfrctl1 = STPWEN;
9874 aic7xxx_load_seeprom(temp_p, &sxfrctl1);
9875 temp_p->board_name_index = 4;
9876 if (aic7xxx_verbose & VERBOSE_PROBE2)
9877 printk("aic7xxx: <%s> at VLB %d\n",
9878 board_names[2], slot);
9879 switch( aic_inb(temp_p, STATUS_2840) & BIOS_SEL )
9881 case 0x00:
9882 temp_p->bios_address = 0xe0000;
9883 break;
9884 case 0x20:
9885 temp_p->bios_address = 0xc8000;
9886 break;
9887 case 0x40:
9888 temp_p->bios_address = 0xd0000;
9889 break;
9890 case 0x60:
9891 temp_p->bios_address = 0xd8000;
9892 break;
9893 default:
9894 break; /* can't get here */
9896 break;
9898 default: /* Won't get here. */
9899 break;
9901 if (aic7xxx_verbose & VERBOSE_PROBE2)
9903 printk(KERN_INFO "aic7xxx: BIOS %sabled, IO Port 0x%lx, IRQ %d (%s)\n",
9904 (temp_p->flags & AHC_USEDEFAULTS) ? "dis" : "en", temp_p->base,
9905 temp_p->irq,
9906 (temp_p->pause & IRQMS) ? "level sensitive" : "edge triggered");
9907 printk(KERN_INFO "aic7xxx: Extended translation %sabled.\n",
9908 (temp_p->flags & AHC_EXTEND_TRANS_A) ? "en" : "dis");
9912 * All the 7770 based chipsets have this bug
9914 temp_p->bugs |= AHC_BUG_TMODE_WIDEODD;
9917 * Set the FIFO threshold and the bus off time.
9919 hostconf = aic_inb(temp_p, HOSTCONF);
9920 aic_outb(temp_p, hostconf & DFTHRSH, BUSSPD);
9921 aic_outb(temp_p, (hostconf << 2) & BOFF, BUSTIME);
9922 slot++;
9923 found++;
9926 #endif /* defined(__i386__) || defined(__alpha__) */
9929 * Now, we re-order the probed devices by BIOS address and BUS class.
9930 * In general, we follow this algorithm to make the adapters show up
9931 * in the same order under linux that the computer finds them.
9932 * 1: All VLB/EISA cards with BIOS_ENABLED first, according to BIOS
9933 * address, going from lowest to highest.
9934 * 2: All PCI controllers with BIOS_ENABLED next, according to BIOS
9935 * address, going from lowest to highest.
9936 * 3: Remaining VLB/EISA controllers going in slot order.
9937 * 4: Remaining PCI controllers, going in PCI device order (reversable)
9941 struct aic7xxx_host *sort_list[4] = { NULL, NULL, NULL, NULL };
9942 struct aic7xxx_host *vlb, *pci;
9943 struct aic7xxx_host *prev_p;
9944 struct aic7xxx_host *p;
9945 unsigned char left;
9947 prev_p = vlb = pci = NULL;
9949 temp_p = list_p;
9950 while (temp_p != NULL)
9952 switch(temp_p->chip & ~AHC_CHIPID_MASK)
9954 case AHC_EISA:
9955 case AHC_VL:
9957 p = temp_p;
9958 if (p->flags & AHC_BIOS_ENABLED)
9959 vlb = sort_list[0];
9960 else
9961 vlb = sort_list[2];
9963 if (vlb == NULL)
9965 vlb = temp_p;
9966 temp_p = temp_p->next;
9967 vlb->next = NULL;
9969 else
9971 current_p = vlb;
9972 prev_p = NULL;
9973 while ( (current_p != NULL) &&
9974 (current_p->bios_address < temp_p->bios_address))
9976 prev_p = current_p;
9977 current_p = current_p->next;
9979 if (prev_p != NULL)
9981 prev_p->next = temp_p;
9982 temp_p = temp_p->next;
9983 prev_p->next->next = current_p;
9985 else
9987 vlb = temp_p;
9988 temp_p = temp_p->next;
9989 vlb->next = current_p;
9993 if (p->flags & AHC_BIOS_ENABLED)
9994 sort_list[0] = vlb;
9995 else
9996 sort_list[2] = vlb;
9998 break;
10000 default: /* All PCI controllers fall through to default */
10003 p = temp_p;
10004 if (p->flags & AHC_BIOS_ENABLED)
10005 pci = sort_list[1];
10006 else
10007 pci = sort_list[3];
10009 if (pci == NULL)
10011 pci = temp_p;
10012 temp_p = temp_p->next;
10013 pci->next = NULL;
10015 else
10017 current_p = pci;
10018 prev_p = NULL;
10019 if (!aic7xxx_reverse_scan)
10021 while ( (current_p != NULL) &&
10022 ( (PCI_SLOT(current_p->pci_device_fn) |
10023 (current_p->pci_bus << 8)) <
10024 (PCI_SLOT(temp_p->pci_device_fn) |
10025 (temp_p->pci_bus << 8)) ) )
10027 prev_p = current_p;
10028 current_p = current_p->next;
10031 else
10033 while ( (current_p != NULL) &&
10034 ( (PCI_SLOT(current_p->pci_device_fn) |
10035 (current_p->pci_bus << 8)) >
10036 (PCI_SLOT(temp_p->pci_device_fn) |
10037 (temp_p->pci_bus << 8)) ) )
10039 prev_p = current_p;
10040 current_p = current_p->next;
10044 * Are we dealing with a 7895/6/7/9 where we need to sort the
10045 * channels as well, if so, the bios_address values should
10046 * be the same
10048 if ( (current_p) && (temp_p->flags & AHC_MULTI_CHANNEL) &&
10049 (temp_p->pci_bus == current_p->pci_bus) &&
10050 (PCI_SLOT(temp_p->pci_device_fn) ==
10051 PCI_SLOT(current_p->pci_device_fn)) )
10053 if (temp_p->flags & AHC_CHNLB)
10055 if ( !(temp_p->flags & AHC_CHANNEL_B_PRIMARY) )
10057 prev_p = current_p;
10058 current_p = current_p->next;
10061 else
10063 if (temp_p->flags & AHC_CHANNEL_B_PRIMARY)
10065 prev_p = current_p;
10066 current_p = current_p->next;
10070 if (prev_p != NULL)
10072 prev_p->next = temp_p;
10073 temp_p = temp_p->next;
10074 prev_p->next->next = current_p;
10076 else
10078 pci = temp_p;
10079 temp_p = temp_p->next;
10080 pci->next = current_p;
10084 if (p->flags & AHC_BIOS_ENABLED)
10085 sort_list[1] = pci;
10086 else
10087 sort_list[3] = pci;
10089 break;
10091 } /* End of switch(temp_p->type) */
10092 } /* End of while (temp_p != NULL) */
10094 * At this point, the cards have been broken into 4 sorted lists, now
10095 * we run through the lists in order and register each controller
10098 int i;
10100 left = found;
10101 for (i=0; i<NUMBER(sort_list); i++)
10103 temp_p = sort_list[i];
10104 while(temp_p != NULL)
10106 template->name = board_names[temp_p->board_name_index];
10107 p = aic7xxx_alloc(template, temp_p);
10108 if (p != NULL)
10110 p->instance = found - left;
10111 if (aic7xxx_register(template, p, (--left)) == 0)
10113 found--;
10114 aic7xxx_release(p->host);
10115 scsi_unregister(p->host);
10117 else if (aic7xxx_dump_card)
10119 pause_sequencer(p);
10120 aic7xxx_print_card(p);
10121 aic7xxx_print_scratch_ram(p);
10122 unpause_sequencer(p, TRUE);
10125 current_p = temp_p;
10126 temp_p = (struct aic7xxx_host *)temp_p->next;
10127 kfree(current_p);
10132 return (found);
10135 /*+F*************************************************************************
10136 * Function:
10137 * aic7xxx_buildscb
10139 * Description:
10140 * Build a SCB.
10141 *-F*************************************************************************/
10142 static void
10143 aic7xxx_buildscb(struct aic7xxx_host *p, Scsi_Cmnd *cmd,
10144 struct aic7xxx_scb *scb)
10146 unsigned short mask;
10147 struct aic7xxx_hwscb *hscb;
10148 struct aic_dev_data *aic_dev = cmd->device->hostdata;
10149 struct scsi_device *sdptr = cmd->device;
10150 unsigned char tindex = TARGET_INDEX(cmd);
10151 struct request *req = cmd->request;
10153 mask = (0x01 << tindex);
10154 hscb = scb->hscb;
10157 * Setup the control byte if we need negotiation and have not
10158 * already requested it.
10160 hscb->control = 0;
10161 scb->tag_action = 0;
10163 if (p->discenable & mask)
10165 hscb->control |= DISCENB;
10166 /* We always force TEST_UNIT_READY to untagged */
10167 if (cmd->cmnd[0] != TEST_UNIT_READY && sdptr->simple_tags)
10169 if (req->flags & REQ_HARDBARRIER)
10171 if(sdptr->ordered_tags)
10173 hscb->control |= MSG_ORDERED_Q_TAG;
10174 scb->tag_action = MSG_ORDERED_Q_TAG;
10177 else
10179 hscb->control |= MSG_SIMPLE_Q_TAG;
10180 scb->tag_action = MSG_SIMPLE_Q_TAG;
10184 if ( !(aic_dev->dtr_pending) &&
10185 (aic_dev->needppr || aic_dev->needwdtr || aic_dev->needsdtr) &&
10186 (aic_dev->flags & DEVICE_DTR_SCANNED) )
10188 aic_dev->dtr_pending = 1;
10189 scb->tag_action = 0;
10190 hscb->control &= DISCENB;
10191 hscb->control |= MK_MESSAGE;
10192 if(aic_dev->needppr)
10194 scb->flags |= SCB_MSGOUT_PPR;
10196 else if(aic_dev->needwdtr)
10198 scb->flags |= SCB_MSGOUT_WDTR;
10200 else if(aic_dev->needsdtr)
10202 scb->flags |= SCB_MSGOUT_SDTR;
10204 scb->flags |= SCB_DTR_SCB;
10206 hscb->target_channel_lun = ((cmd->device->id << 4) & 0xF0) |
10207 ((cmd->device->channel & 0x01) << 3) | (cmd->device->lun & 0x07);
10210 * The interpretation of request_buffer and request_bufflen
10211 * changes depending on whether or not use_sg is zero; a
10212 * non-zero use_sg indicates the number of elements in the
10213 * scatter-gather array.
10217 * XXX - this relies on the host data being stored in a
10218 * little-endian format.
10220 hscb->SCSI_cmd_length = cmd->cmd_len;
10221 memcpy(scb->cmnd, cmd->cmnd, cmd->cmd_len);
10222 hscb->SCSI_cmd_pointer = cpu_to_le32(SCB_DMA_ADDR(scb, scb->cmnd));
10224 if (cmd->use_sg)
10226 struct scatterlist *sg; /* Must be mid-level SCSI code scatterlist */
10229 * We must build an SG list in adapter format, as the kernel's SG list
10230 * cannot be used directly because of data field size (__alpha__)
10231 * differences and the kernel SG list uses virtual addresses where
10232 * we need physical addresses.
10234 int i, use_sg;
10236 sg = (struct scatterlist *)cmd->request_buffer;
10237 scb->sg_length = 0;
10238 use_sg = pci_map_sg(p->pdev, sg, cmd->use_sg, scsi_to_pci_dma_dir(cmd->sc_data_direction));
10240 * Copy the segments into the SG array. NOTE!!! - We used to
10241 * have the first entry both in the data_pointer area and the first
10242 * SG element. That has changed somewhat. We still have the first
10243 * entry in both places, but now we download the address of
10244 * scb->sg_list[1] instead of 0 to the sg pointer in the hscb.
10246 for (i = 0; i < use_sg; i++)
10248 unsigned int len = sg_dma_len(sg+i);
10249 scb->sg_list[i].address = cpu_to_le32(sg_dma_address(sg+i));
10250 scb->sg_list[i].length = cpu_to_le32(len);
10251 scb->sg_length += len;
10253 /* Copy the first SG into the data pointer area. */
10254 hscb->data_pointer = scb->sg_list[0].address;
10255 hscb->data_count = scb->sg_list[0].length;
10256 scb->sg_count = i;
10257 hscb->SG_segment_count = i;
10258 hscb->SG_list_pointer = cpu_to_le32(SCB_DMA_ADDR(scb, &scb->sg_list[1]));
10260 else
10262 if (cmd->request_bufflen)
10264 unsigned int address = pci_map_single(p->pdev, cmd->request_buffer,
10265 cmd->request_bufflen,
10266 scsi_to_pci_dma_dir(cmd->sc_data_direction));
10267 aic7xxx_mapping(cmd) = address;
10268 scb->sg_list[0].address = cpu_to_le32(address);
10269 scb->sg_list[0].length = cpu_to_le32(cmd->request_bufflen);
10270 scb->sg_count = 1;
10271 scb->sg_length = cmd->request_bufflen;
10272 hscb->SG_segment_count = 1;
10273 hscb->SG_list_pointer = cpu_to_le32(SCB_DMA_ADDR(scb, &scb->sg_list[0]));
10274 hscb->data_count = scb->sg_list[0].length;
10275 hscb->data_pointer = scb->sg_list[0].address;
10277 else
10279 scb->sg_count = 0;
10280 scb->sg_length = 0;
10281 hscb->SG_segment_count = 0;
10282 hscb->SG_list_pointer = 0;
10283 hscb->data_count = 0;
10284 hscb->data_pointer = 0;
10289 /*+F*************************************************************************
10290 * Function:
10291 * aic7xxx_queue
10293 * Description:
10294 * Queue a SCB to the controller.
10295 *-F*************************************************************************/
10296 static int
10297 aic7xxx_queue(Scsi_Cmnd *cmd, void (*fn)(Scsi_Cmnd *))
10299 struct aic7xxx_host *p;
10300 struct aic7xxx_scb *scb;
10301 struct aic_dev_data *aic_dev;
10303 p = (struct aic7xxx_host *) cmd->device->host->hostdata;
10305 aic_dev = cmd->device->hostdata;
10306 #ifdef AIC7XXX_VERBOSE_DEBUGGING
10307 if (aic_dev->active_cmds > aic_dev->max_q_depth)
10309 printk(WARN_LEAD "Commands queued exceeds queue "
10310 "depth, active=%d\n",
10311 p->host_no, CTL_OF_CMD(cmd),
10312 aic_dev->active_cmds);
10314 #endif
10316 scb = scbq_remove_head(&p->scb_data->free_scbs);
10317 if (scb == NULL)
10319 aic7xxx_allocate_scb(p);
10320 scb = scbq_remove_head(&p->scb_data->free_scbs);
10321 if(scb == NULL)
10323 printk(WARN_LEAD "Couldn't get a free SCB.\n", p->host_no,
10324 CTL_OF_CMD(cmd));
10325 return 1;
10328 scb->cmd = cmd;
10331 * Make sure the Scsi_Cmnd pointer is saved, the struct it points to
10332 * is set up properly, and the parity error flag is reset, then send
10333 * the SCB to the sequencer and watch the fun begin.
10335 aic7xxx_position(cmd) = scb->hscb->tag;
10336 cmd->scsi_done = fn;
10337 cmd->result = DID_OK;
10338 memset(cmd->sense_buffer, 0, sizeof(cmd->sense_buffer));
10339 aic7xxx_error(cmd) = DID_OK;
10340 aic7xxx_status(cmd) = 0;
10341 cmd->host_scribble = NULL;
10344 * Construct the SCB beforehand, so the sequencer is
10345 * paused a minimal amount of time.
10347 aic7xxx_buildscb(p, cmd, scb);
10349 scb->flags |= SCB_ACTIVE | SCB_WAITINGQ;
10351 scbq_insert_tail(&p->waiting_scbs, scb);
10352 aic7xxx_run_waiting_queues(p);
10353 return (0);
10356 /*+F*************************************************************************
10357 * Function:
10358 * aic7xxx_bus_device_reset
10360 * Description:
10361 * Abort or reset the current SCSI command(s). If the scb has not
10362 * previously been aborted, then we attempt to send a BUS_DEVICE_RESET
10363 * message to the target. If the scb has previously been unsuccessfully
10364 * aborted, then we will reset the channel and have all devices renegotiate.
10365 * Returns an enumerated type that indicates the status of the operation.
10366 *-F*************************************************************************/
10367 static int
10368 aic7xxx_bus_device_reset(Scsi_Cmnd *cmd)
10370 struct aic7xxx_host *p;
10371 struct aic7xxx_scb *scb;
10372 struct aic7xxx_hwscb *hscb;
10373 int channel;
10374 unsigned char saved_scbptr, lastphase;
10375 unsigned char hscb_index;
10376 int disconnected;
10377 struct aic_dev_data *aic_dev;
10379 if(cmd == NULL)
10381 printk(KERN_ERR "aic7xxx_bus_device_reset: called with NULL cmd!\n");
10382 return FAILED;
10384 p = (struct aic7xxx_host *)cmd->device->host->hostdata;
10385 aic_dev = AIC_DEV(cmd);
10386 if(aic7xxx_position(cmd) < p->scb_data->numscbs)
10387 scb = (p->scb_data->scb_array[aic7xxx_position(cmd)]);
10388 else
10389 return FAILED;
10391 hscb = scb->hscb;
10393 aic7xxx_isr(p->irq, (void *)p, NULL);
10394 aic7xxx_done_cmds_complete(p);
10395 /* If the command was already complete or just completed, then we didn't
10396 * do a reset, return FAILED */
10397 if(!(scb->flags & SCB_ACTIVE))
10398 return FAILED;
10400 pause_sequencer(p);
10401 lastphase = aic_inb(p, LASTPHASE);
10402 if (aic7xxx_verbose & VERBOSE_RESET_PROCESS)
10404 printk(INFO_LEAD "Bus Device reset, scb flags 0x%x, ",
10405 p->host_no, CTL_OF_SCB(scb), scb->flags);
10406 switch (lastphase)
10408 case P_DATAOUT:
10409 printk("Data-Out phase\n");
10410 break;
10411 case P_DATAIN:
10412 printk("Data-In phase\n");
10413 break;
10414 case P_COMMAND:
10415 printk("Command phase\n");
10416 break;
10417 case P_MESGOUT:
10418 printk("Message-Out phase\n");
10419 break;
10420 case P_STATUS:
10421 printk("Status phase\n");
10422 break;
10423 case P_MESGIN:
10424 printk("Message-In phase\n");
10425 break;
10426 default:
10428 * We're not in a valid phase, so assume we're idle.
10430 printk("while idle, LASTPHASE = 0x%x\n", lastphase);
10431 break;
10433 printk(INFO_LEAD "SCSISIGI 0x%x, SEQADDR 0x%x, SSTAT0 0x%x, SSTAT1 "
10434 "0x%x\n", p->host_no, CTL_OF_SCB(scb),
10435 aic_inb(p, SCSISIGI),
10436 aic_inb(p, SEQADDR0) | (aic_inb(p, SEQADDR1) << 8),
10437 aic_inb(p, SSTAT0), aic_inb(p, SSTAT1));
10438 printk(INFO_LEAD "SG_CACHEPTR 0x%x, SSTAT2 0x%x, STCNT 0x%x\n", p->host_no,
10439 CTL_OF_SCB(scb),
10440 (p->features & AHC_ULTRA2) ? aic_inb(p, SG_CACHEPTR) : 0,
10441 aic_inb(p, SSTAT2),
10442 aic_inb(p, STCNT + 2) << 16 | aic_inb(p, STCNT + 1) << 8 |
10443 aic_inb(p, STCNT));
10446 channel = cmd->device->channel;
10449 * Send a Device Reset Message:
10450 * The target that is holding up the bus may not be the same as
10451 * the one that triggered this timeout (different commands have
10452 * different timeout lengths). Our strategy here is to queue an
10453 * abort message to the timed out target if it is disconnected.
10454 * Otherwise, if we have an active target we stuff the message buffer
10455 * with an abort message and assert ATN in the hopes that the target
10456 * will let go of the bus and go to the mesgout phase. If this
10457 * fails, we'll get another timeout a few seconds later which will
10458 * attempt a bus reset.
10460 saved_scbptr = aic_inb(p, SCBPTR);
10461 disconnected = FALSE;
10463 if (lastphase != P_BUSFREE)
10465 if (aic_inb(p, SCB_TAG) >= p->scb_data->numscbs)
10467 printk(WARN_LEAD "Invalid SCB ID %d is active, "
10468 "SCB flags = 0x%x.\n", p->host_no,
10469 CTL_OF_CMD(cmd), scb->hscb->tag, scb->flags);
10470 unpause_sequencer(p, FALSE);
10471 return FAILED;
10473 if (scb->hscb->tag == aic_inb(p, SCB_TAG))
10475 if ( (lastphase == P_MESGOUT) || (lastphase == P_MESGIN) )
10477 printk(WARN_LEAD "Device reset, Message buffer "
10478 "in use\n", p->host_no, CTL_OF_SCB(scb));
10479 unpause_sequencer(p, FALSE);
10480 return FAILED;
10483 if (aic7xxx_verbose & VERBOSE_RESET_PROCESS)
10484 printk(INFO_LEAD "Device reset message in "
10485 "message buffer\n", p->host_no, CTL_OF_SCB(scb));
10486 scb->flags |= SCB_RESET | SCB_DEVICE_RESET;
10487 aic7xxx_error(cmd) = DID_RESET;
10488 aic_dev->flags |= BUS_DEVICE_RESET_PENDING;
10489 /* Send the abort message to the active SCB. */
10490 aic_outb(p, HOST_MSG, MSG_OUT);
10491 aic_outb(p, lastphase | ATNO, SCSISIGO);
10492 unpause_sequencer(p, FALSE);
10493 spin_unlock_irq(p->host->host_lock);
10494 scsi_sleep(HZ);
10495 spin_lock_irq(p->host->host_lock);
10496 if(aic_dev->flags & BUS_DEVICE_RESET_PENDING)
10497 return FAILED;
10498 else
10499 return SUCCESS;
10501 } /* if (last_phase != P_BUSFREE).....indicates we are idle and can work */
10503 * Simply set the MK_MESSAGE flag and the SEQINT handler will do
10504 * the rest on a reconnect/connect.
10506 scb->hscb->control |= MK_MESSAGE;
10507 scb->flags |= SCB_RESET | SCB_DEVICE_RESET;
10508 aic_dev->flags |= BUS_DEVICE_RESET_PENDING;
10510 * Check to see if the command is on the qinfifo. If it is, then we will
10511 * not need to queue the command again since the card should start it soon
10513 if (aic7xxx_search_qinfifo(p, cmd->device->channel, cmd->device->id, cmd->device->lun, hscb->tag,
10514 0, TRUE, NULL) == 0)
10516 disconnected = TRUE;
10517 if ((hscb_index = aic7xxx_find_scb(p, scb)) != SCB_LIST_NULL)
10519 unsigned char scb_control;
10521 aic_outb(p, hscb_index, SCBPTR);
10522 scb_control = aic_inb(p, SCB_CONTROL);
10524 * If the DISCONNECTED bit is not set in SCB_CONTROL, then we are
10525 * actually on the waiting list, not disconnected, and we don't
10526 * need to requeue the command.
10528 disconnected = (scb_control & DISCONNECTED);
10529 aic_outb(p, scb_control | MK_MESSAGE, SCB_CONTROL);
10531 if (disconnected)
10534 * Actually requeue this SCB in case we can select the
10535 * device before it reconnects. This can result in the command
10536 * being on the qinfifo twice, but we don't care because it will
10537 * all get cleaned up if/when the reset takes place.
10539 if (aic7xxx_verbose & VERBOSE_RESET_PROCESS)
10540 printk(INFO_LEAD "Queueing device reset command.\n", p->host_no,
10541 CTL_OF_SCB(scb));
10542 p->qinfifo[p->qinfifonext++] = scb->hscb->tag;
10543 if (p->features & AHC_QUEUE_REGS)
10544 aic_outb(p, p->qinfifonext, HNSCB_QOFF);
10545 else
10546 aic_outb(p, p->qinfifonext, KERNEL_QINPOS);
10547 scb->flags |= SCB_QUEUED_ABORT;
10550 aic_outb(p, saved_scbptr, SCBPTR);
10551 unpause_sequencer(p, FALSE);
10552 spin_unlock_irq(p->host->host_lock);
10553 scsi_sleep(HZ/4);
10554 spin_lock_irq(p->host->host_lock);
10555 if(aic_dev->flags & BUS_DEVICE_RESET_PENDING)
10556 return FAILED;
10557 else
10558 return SUCCESS;
10562 /*+F*************************************************************************
10563 * Function:
10564 * aic7xxx_panic_abort
10566 * Description:
10567 * Abort the current SCSI command(s).
10568 *-F*************************************************************************/
10569 static void
10570 aic7xxx_panic_abort(struct aic7xxx_host *p, Scsi_Cmnd *cmd)
10573 printk("aic7xxx driver version %s/%s\n", AIC7XXX_C_VERSION,
10574 UTS_RELEASE);
10575 printk("Controller type:\n %s\n", board_names[p->board_name_index]);
10576 printk("p->flags=0x%lx, p->chip=0x%x, p->features=0x%x, "
10577 "sequencer %s paused\n",
10578 p->flags, p->chip, p->features,
10579 (aic_inb(p, HCNTRL) & PAUSE) ? "is" : "isn't" );
10580 pause_sequencer(p);
10581 disable_irq(p->irq);
10582 aic7xxx_print_card(p);
10583 aic7xxx_print_scratch_ram(p);
10584 spin_unlock_irq(p->host->host_lock);
10585 for(;;) barrier();
10588 /*+F*************************************************************************
10589 * Function:
10590 * aic7xxx_abort
10592 * Description:
10593 * Abort the current SCSI command(s).
10594 *-F*************************************************************************/
10595 static int
10596 aic7xxx_abort(Scsi_Cmnd *cmd)
10598 struct aic7xxx_scb *scb = NULL;
10599 struct aic7xxx_host *p;
10600 int found=0, disconnected;
10601 unsigned char saved_hscbptr, hscbptr, scb_control;
10602 struct aic_dev_data *aic_dev;
10604 if(cmd == NULL)
10606 printk(KERN_ERR "aic7xxx_abort: called with NULL cmd!\n");
10607 return FAILED;
10609 p = (struct aic7xxx_host *)cmd->device->host->hostdata;
10610 aic_dev = AIC_DEV(cmd);
10611 if(aic7xxx_position(cmd) < p->scb_data->numscbs)
10612 scb = (p->scb_data->scb_array[aic7xxx_position(cmd)]);
10613 else
10614 return FAILED;
10616 aic7xxx_isr(p->irq, (void *)p, NULL);
10617 aic7xxx_done_cmds_complete(p);
10618 /* If the command was already complete or just completed, then we didn't
10619 * do a reset, return FAILED */
10620 if(!(scb->flags & SCB_ACTIVE))
10621 return FAILED;
10623 pause_sequencer(p);
10626 * I added a new config option to the driver: "panic_on_abort" that will
10627 * cause the driver to panic and the machine to stop on the first abort
10628 * or reset call into the driver. At that point, it prints out a lot of
10629 * useful information for me which I can then use to try and debug the
10630 * problem. Simply enable the boot time prompt in order to activate this
10631 * code.
10633 if (aic7xxx_panic_on_abort)
10634 aic7xxx_panic_abort(p, cmd);
10636 if (aic7xxx_verbose & VERBOSE_ABORT)
10638 printk(INFO_LEAD "Aborting scb %d, flags 0x%x, SEQADDR 0x%x, LASTPHASE "
10639 "0x%x\n",
10640 p->host_no, CTL_OF_SCB(scb), scb->hscb->tag, scb->flags,
10641 aic_inb(p, SEQADDR0) | (aic_inb(p, SEQADDR1) << 8),
10642 aic_inb(p, LASTPHASE));
10643 printk(INFO_LEAD "SG_CACHEPTR 0x%x, SG_COUNT %d, SCSISIGI 0x%x\n",
10644 p->host_no, CTL_OF_SCB(scb), (p->features & AHC_ULTRA2) ?
10645 aic_inb(p, SG_CACHEPTR) : 0, aic_inb(p, SG_COUNT),
10646 aic_inb(p, SCSISIGI));
10647 printk(INFO_LEAD "SSTAT0 0x%x, SSTAT1 0x%x, SSTAT2 0x%x\n",
10648 p->host_no, CTL_OF_SCB(scb), aic_inb(p, SSTAT0),
10649 aic_inb(p, SSTAT1), aic_inb(p, SSTAT2));
10652 if (scb->flags & SCB_WAITINGQ)
10654 if (aic7xxx_verbose & VERBOSE_ABORT_PROCESS)
10655 printk(INFO_LEAD "SCB found on waiting list and "
10656 "aborted.\n", p->host_no, CTL_OF_SCB(scb));
10657 scbq_remove(&p->waiting_scbs, scb);
10658 scbq_remove(&aic_dev->delayed_scbs, scb);
10659 aic_dev->active_cmds++;
10660 p->activescbs++;
10661 scb->flags &= ~(SCB_WAITINGQ | SCB_ACTIVE);
10662 scb->flags |= SCB_ABORT | SCB_QUEUED_FOR_DONE;
10663 goto success;
10667 * We just checked the waiting_q, now for the QINFIFO
10669 if ( ((found = aic7xxx_search_qinfifo(p, cmd->device->id, cmd->device->channel,
10670 cmd->device->lun, scb->hscb->tag, SCB_ABORT | SCB_QUEUED_FOR_DONE,
10671 FALSE, NULL)) != 0) &&
10672 (aic7xxx_verbose & VERBOSE_ABORT_PROCESS))
10674 printk(INFO_LEAD "SCB found in QINFIFO and aborted.\n", p->host_no,
10675 CTL_OF_SCB(scb));
10676 goto success;
10680 * QINFIFO, waitingq, completeq done. Next, check WAITING_SCB list in card
10683 saved_hscbptr = aic_inb(p, SCBPTR);
10684 if ((hscbptr = aic7xxx_find_scb(p, scb)) != SCB_LIST_NULL)
10686 aic_outb(p, hscbptr, SCBPTR);
10687 scb_control = aic_inb(p, SCB_CONTROL);
10688 disconnected = scb_control & DISCONNECTED;
10690 * If the DISCONNECTED bit is not set in SCB_CONTROL, then we are
10691 * either currently active or on the waiting list.
10693 if(!disconnected && aic_inb(p, LASTPHASE) == P_BUSFREE) {
10694 if (aic7xxx_verbose & VERBOSE_ABORT_PROCESS)
10695 printk(INFO_LEAD "SCB found on hardware waiting"
10696 " list and aborted.\n", p->host_no, CTL_OF_SCB(scb));
10697 /* If we are the only waiting command, stop the selection engine */
10698 if (aic_inb(p, WAITING_SCBH) == hscbptr && aic_inb(p, SCB_NEXT) ==
10699 SCB_LIST_NULL)
10701 aic_outb(p, aic_inb(p, SCSISEQ) & ~ENSELO, SCSISEQ);
10702 aic_outb(p, CLRSELTIMEO, CLRSINT1);
10703 aic_outb(p, SCB_LIST_NULL, WAITING_SCBH);
10705 else
10707 unsigned char prev, next;
10708 prev = SCB_LIST_NULL;
10709 next = aic_inb(p, WAITING_SCBH);
10710 while(next != SCB_LIST_NULL)
10712 aic_outb(p, next, SCBPTR);
10713 if (next == hscbptr)
10715 next = aic_inb(p, SCB_NEXT);
10716 if (prev != SCB_LIST_NULL)
10718 aic_outb(p, prev, SCBPTR);
10719 aic_outb(p, next, SCB_NEXT);
10721 else
10722 aic_outb(p, next, WAITING_SCBH);
10723 aic_outb(p, hscbptr, SCBPTR);
10724 next = SCB_LIST_NULL;
10726 else
10728 prev = next;
10729 next = aic_inb(p, SCB_NEXT);
10733 aic_outb(p, SCB_LIST_NULL, SCB_TAG);
10734 aic_outb(p, 0, SCB_CONTROL);
10735 aic7xxx_add_curscb_to_free_list(p);
10736 scb->flags = SCB_ABORT | SCB_QUEUED_FOR_DONE;
10737 goto success;
10739 else if (!disconnected)
10742 * We are the currently active command
10744 if((aic_inb(p, LASTPHASE) == P_MESGIN) ||
10745 (aic_inb(p, LASTPHASE) == P_MESGOUT))
10748 * Message buffer busy, unable to abort
10750 printk(INFO_LEAD "message buffer busy, unable to abort.\n",
10751 p->host_no, CTL_OF_SCB(scb));
10752 unpause_sequencer(p, FALSE);
10753 return FAILED;
10755 /* Fallthrough to below, set ATNO after we set SCB_CONTROL */
10757 aic_outb(p, scb_control | MK_MESSAGE, SCB_CONTROL);
10758 if(!disconnected)
10760 aic_outb(p, HOST_MSG, MSG_OUT);
10761 aic_outb(p, aic_inb(p, SCSISIGI) | ATNO, SCSISIGO);
10763 aic_outb(p, saved_hscbptr, SCBPTR);
10765 else
10768 * The scb isn't in the card at all and it is active and it isn't in
10769 * any of the queues, so it must be disconnected and paged out. Fall
10770 * through to the code below.
10772 disconnected = 1;
10775 p->flags |= AHC_ABORT_PENDING;
10776 scb->flags |= SCB_QUEUED_ABORT | SCB_ABORT | SCB_RECOVERY_SCB;
10777 scb->hscb->control |= MK_MESSAGE;
10778 if(disconnected)
10780 if (aic7xxx_verbose & VERBOSE_ABORT_PROCESS)
10781 printk(INFO_LEAD "SCB disconnected. Queueing Abort"
10782 " SCB.\n", p->host_no, CTL_OF_SCB(scb));
10783 p->qinfifo[p->qinfifonext++] = scb->hscb->tag;
10784 if (p->features & AHC_QUEUE_REGS)
10785 aic_outb(p, p->qinfifonext, HNSCB_QOFF);
10786 else
10787 aic_outb(p, p->qinfifonext, KERNEL_QINPOS);
10789 unpause_sequencer(p, FALSE);
10790 spin_unlock_irq(p->host->host_lock);
10791 scsi_sleep(HZ/4);
10792 spin_lock_irq(p->host->host_lock);
10793 if (p->flags & AHC_ABORT_PENDING)
10795 if (aic7xxx_verbose & VERBOSE_ABORT_RETURN)
10796 printk(INFO_LEAD "Abort never delivered, returning FAILED\n", p->host_no,
10797 CTL_OF_CMD(cmd));
10798 p->flags &= ~AHC_ABORT_PENDING;
10799 return FAILED;
10801 if (aic7xxx_verbose & VERBOSE_ABORT_RETURN)
10802 printk(INFO_LEAD "Abort successful.\n", p->host_no, CTL_OF_CMD(cmd));
10803 return SUCCESS;
10805 success:
10806 if (aic7xxx_verbose & VERBOSE_ABORT_RETURN)
10807 printk(INFO_LEAD "Abort successful.\n", p->host_no, CTL_OF_CMD(cmd));
10808 aic7xxx_run_done_queue(p, TRUE);
10809 unpause_sequencer(p, FALSE);
10810 return SUCCESS;
10813 /*+F*************************************************************************
10814 * Function:
10815 * aic7xxx_reset
10817 * Description:
10818 * Resetting the bus always succeeds - is has to, otherwise the
10819 * kernel will panic! Try a surgical technique - sending a BUS
10820 * DEVICE RESET message - on the offending target before pulling
10821 * the SCSI bus reset line.
10822 *-F*************************************************************************/
10823 static int
10824 aic7xxx_reset(Scsi_Cmnd *cmd)
10826 struct aic7xxx_scb *scb;
10827 struct aic7xxx_host *p;
10828 struct aic_dev_data *aic_dev;
10830 p = (struct aic7xxx_host *) cmd->device->host->hostdata;
10831 aic_dev = AIC_DEV(cmd);
10832 if(aic7xxx_position(cmd) < p->scb_data->numscbs)
10834 scb = (p->scb_data->scb_array[aic7xxx_position(cmd)]);
10835 if (scb->cmd != cmd)
10836 scb = NULL;
10838 else
10840 scb = NULL;
10844 * I added a new config option to the driver: "panic_on_abort" that will
10845 * cause the driver to panic and the machine to stop on the first abort
10846 * or reset call into the driver. At that point, it prints out a lot of
10847 * useful information for me which I can then use to try and debug the
10848 * problem. Simply enable the boot time prompt in order to activate this
10849 * code.
10851 if (aic7xxx_panic_on_abort)
10852 aic7xxx_panic_abort(p, cmd);
10854 pause_sequencer(p);
10856 while((aic_inb(p, INTSTAT) & INT_PEND) && !(p->flags & AHC_IN_ISR))
10858 aic7xxx_isr(p->irq, p, (void *)NULL );
10859 pause_sequencer(p);
10861 aic7xxx_done_cmds_complete(p);
10863 if(scb && (scb->cmd == NULL))
10866 * We just completed the command when we ran the isr stuff, so we no
10867 * longer have it.
10869 unpause_sequencer(p, FALSE);
10870 return SUCCESS;
10874 * By this point, we want to already know what we are going to do and
10875 * only have the following code implement our course of action.
10877 aic7xxx_reset_channel(p, cmd->device->channel, TRUE);
10878 if (p->features & AHC_TWIN)
10880 aic7xxx_reset_channel(p, cmd->device->channel ^ 0x01, TRUE);
10881 restart_sequencer(p);
10883 aic_outb(p, aic_inb(p, SIMODE1) & ~(ENREQINIT|ENBUSFREE), SIMODE1);
10884 aic7xxx_clear_intstat(p);
10885 p->flags &= ~AHC_HANDLING_REQINITS;
10886 p->msg_type = MSG_TYPE_NONE;
10887 p->msg_index = 0;
10888 p->msg_len = 0;
10889 aic7xxx_run_done_queue(p, TRUE);
10890 unpause_sequencer(p, FALSE);
10891 spin_unlock_irq(p->host->host_lock);
10892 scsi_sleep(2 * HZ);
10893 spin_lock_irq(p->host->host_lock);
10894 return SUCCESS;
10897 /*+F*************************************************************************
10898 * Function:
10899 * aic7xxx_biosparam
10901 * Description:
10902 * Return the disk geometry for the given SCSI device.
10904 * Note:
10905 * This function is broken for today's really large drives and needs
10906 * fixed.
10907 *-F*************************************************************************/
10908 static int
10909 aic7xxx_biosparam(struct scsi_device *sdev, struct block_device *bdev,
10910 sector_t capacity, int geom[])
10912 sector_t heads, sectors, cylinders;
10913 int ret;
10914 struct aic7xxx_host *p;
10915 unsigned char *buf;
10917 p = (struct aic7xxx_host *) sdev->host->hostdata;
10918 buf = scsi_bios_ptable(bdev);
10920 if ( buf )
10922 ret = scsi_partsize(buf, capacity, &geom[2], &geom[0], &geom[1]);
10923 kfree(buf);
10924 if ( ret != -1 )
10925 return(ret);
10928 heads = 64;
10929 sectors = 32;
10930 cylinders = capacity >> 11;
10932 if ((p->flags & AHC_EXTEND_TRANS_A) && (cylinders > 1024))
10934 heads = 255;
10935 sectors = 63;
10936 cylinders = capacity >> 14;
10937 if(capacity > (65535 * heads * sectors))
10938 cylinders = 65535;
10939 else
10940 cylinders = ((unsigned int)capacity) / (unsigned int)(heads * sectors);
10943 geom[0] = (int)heads;
10944 geom[1] = (int)sectors;
10945 geom[2] = (int)cylinders;
10947 return (0);
10950 /*+F*************************************************************************
10951 * Function:
10952 * aic7xxx_release
10954 * Description:
10955 * Free the passed in Scsi_Host memory structures prior to unloading the
10956 * module.
10957 *-F*************************************************************************/
10958 static int
10959 aic7xxx_release(struct Scsi_Host *host)
10961 struct aic7xxx_host *p = (struct aic7xxx_host *) host->hostdata;
10962 struct aic7xxx_host *next, *prev;
10964 if(p->irq)
10965 free_irq(p->irq, p);
10966 #ifdef MMAPIO
10967 if(p->maddr)
10969 iounmap((void *) (((unsigned long) p->maddr) & PAGE_MASK));
10971 #endif /* MMAPIO */
10972 if(!p->pdev)
10973 release_region(p->base, MAXREG - MINREG);
10974 else
10975 pci_release_regions(p->pdev);
10976 prev = NULL;
10977 next = first_aic7xxx;
10978 while(next != NULL)
10980 if(next == p)
10982 if(prev == NULL)
10983 first_aic7xxx = next->next;
10984 else
10985 prev->next = next->next;
10987 else
10989 prev = next;
10991 next = next->next;
10993 aic7xxx_free(p);
10994 return(0);
10997 /*+F*************************************************************************
10998 * Function:
10999 * aic7xxx_print_card
11001 * Description:
11002 * Print out all of the control registers on the card
11004 * NOTE: This function is not yet safe for use on the VLB and EISA
11005 * controllers, so it isn't used on those controllers at all.
11006 *-F*************************************************************************/
11007 static void
11008 aic7xxx_print_card(struct aic7xxx_host *p)
11010 int i, j, k, chip;
11011 static struct register_ranges {
11012 int num_ranges;
11013 int range_val[32];
11014 } cards_ds[] = {
11015 { 0, {0,} }, /* none */
11016 {10, {0x00, 0x05, 0x08, 0x11, 0x18, 0x19, 0x1f, 0x1f, 0x60, 0x60, /*7771*/
11017 0x62, 0x66, 0x80, 0x8e, 0x90, 0x95, 0x97, 0x97, 0x9b, 0x9f} },
11018 { 9, {0x00, 0x05, 0x08, 0x11, 0x18, 0x1f, 0x60, 0x60, 0x62, 0x66, /*7850*/
11019 0x80, 0x8e, 0x90, 0x95, 0x97, 0x97, 0x9a, 0x9f} },
11020 { 9, {0x00, 0x05, 0x08, 0x11, 0x18, 0x1f, 0x60, 0x60, 0x62, 0x66, /*7860*/
11021 0x80, 0x8e, 0x90, 0x95, 0x97, 0x97, 0x9a, 0x9f} },
11022 {10, {0x00, 0x05, 0x08, 0x11, 0x18, 0x19, 0x1c, 0x1f, 0x60, 0x60, /*7870*/
11023 0x62, 0x66, 0x80, 0x8e, 0x90, 0x95, 0x97, 0x97, 0x9a, 0x9f} },
11024 {10, {0x00, 0x05, 0x08, 0x11, 0x18, 0x1a, 0x1c, 0x1f, 0x60, 0x60, /*7880*/
11025 0x62, 0x66, 0x80, 0x8e, 0x90, 0x95, 0x97, 0x97, 0x9a, 0x9f} },
11026 {16, {0x00, 0x05, 0x08, 0x11, 0x18, 0x1f, 0x60, 0x60, 0x62, 0x66, /*7890*/
11027 0x84, 0x8e, 0x90, 0x95, 0x97, 0x97, 0x9a, 0x9a, 0x9f, 0x9f,
11028 0xe0, 0xf1, 0xf4, 0xf4, 0xf6, 0xf6, 0xf8, 0xf8, 0xfa, 0xfc,
11029 0xfe, 0xff} },
11030 {12, {0x00, 0x05, 0x08, 0x11, 0x18, 0x19, 0x1b, 0x1f, 0x60, 0x60, /*7895*/
11031 0x62, 0x66, 0x80, 0x8e, 0x90, 0x95, 0x97, 0x97, 0x9a, 0x9a,
11032 0x9f, 0x9f, 0xe0, 0xf1} },
11033 {16, {0x00, 0x05, 0x08, 0x11, 0x18, 0x1f, 0x60, 0x60, 0x62, 0x66, /*7896*/
11034 0x84, 0x8e, 0x90, 0x95, 0x97, 0x97, 0x9a, 0x9a, 0x9f, 0x9f,
11035 0xe0, 0xf1, 0xf4, 0xf4, 0xf6, 0xf6, 0xf8, 0xf8, 0xfa, 0xfc,
11036 0xfe, 0xff} },
11037 {12, {0x00, 0x05, 0x08, 0x11, 0x18, 0x1f, 0x60, 0x60, 0x62, 0x66, /*7892*/
11038 0x84, 0x8e, 0x90, 0x95, 0x97, 0x97, 0x9a, 0x9a, 0x9c, 0x9f,
11039 0xe0, 0xf1, 0xf4, 0xfc} },
11040 {12, {0x00, 0x05, 0x08, 0x11, 0x18, 0x1f, 0x60, 0x60, 0x62, 0x66, /*7899*/
11041 0x84, 0x8e, 0x90, 0x95, 0x97, 0x97, 0x9a, 0x9a, 0x9c, 0x9f,
11042 0xe0, 0xf1, 0xf4, 0xfc} },
11044 chip = p->chip & AHC_CHIPID_MASK;
11045 printk("%s at ",
11046 board_names[p->board_name_index]);
11047 switch(p->chip & ~AHC_CHIPID_MASK)
11049 case AHC_VL:
11050 printk("VLB Slot %d.\n", p->pci_device_fn);
11051 break;
11052 case AHC_EISA:
11053 printk("EISA Slot %d.\n", p->pci_device_fn);
11054 break;
11055 case AHC_PCI:
11056 default:
11057 printk("PCI %d/%d/%d.\n", p->pci_bus, PCI_SLOT(p->pci_device_fn),
11058 PCI_FUNC(p->pci_device_fn));
11059 break;
11063 * the registers on the card....
11065 printk("Card Dump:\n");
11066 k = 0;
11067 for(i=0; i<cards_ds[chip].num_ranges; i++)
11069 for(j = cards_ds[chip].range_val[ i * 2 ];
11070 j <= cards_ds[chip].range_val[ i * 2 + 1 ] ;
11071 j++)
11073 printk("%02x:%02x ", j, aic_inb(p, j));
11074 if(++k == 13)
11076 printk("\n");
11077 k=0;
11081 if(k != 0)
11082 printk("\n");
11085 * If this was an Ultra2 controller, then we just hosed the card in terms
11086 * of the QUEUE REGS. This function is only called at init time or by
11087 * the panic_abort function, so it's safe to assume a generic init time
11088 * setting here
11091 if(p->features & AHC_QUEUE_REGS)
11093 aic_outb(p, 0, SDSCB_QOFF);
11094 aic_outb(p, 0, SNSCB_QOFF);
11095 aic_outb(p, 0, HNSCB_QOFF);
11100 /*+F*************************************************************************
11101 * Function:
11102 * aic7xxx_print_scratch_ram
11104 * Description:
11105 * Print out the scratch RAM values on the card.
11106 *-F*************************************************************************/
11107 static void
11108 aic7xxx_print_scratch_ram(struct aic7xxx_host *p)
11110 int i, k;
11112 k = 0;
11113 printk("Scratch RAM:\n");
11114 for(i = SRAM_BASE; i < SEQCTL; i++)
11116 printk("%02x:%02x ", i, aic_inb(p, i));
11117 if(++k == 13)
11119 printk("\n");
11120 k=0;
11123 if (p->features & AHC_MORE_SRAM)
11125 for(i = TARG_OFFSET; i < 0x80; i++)
11127 printk("%02x:%02x ", i, aic_inb(p, i));
11128 if(++k == 13)
11130 printk("\n");
11131 k=0;
11135 printk("\n");
11139 #include "aic7xxx_old/aic7xxx_proc.c"
11141 MODULE_LICENSE("Dual BSD/GPL");
11144 static Scsi_Host_Template driver_template = {
11145 .proc_info = aic7xxx_proc_info,
11146 .detect = aic7xxx_detect,
11147 .release = aic7xxx_release,
11148 .info = aic7xxx_info,
11149 .queuecommand = aic7xxx_queue,
11150 .slave_alloc = aic7xxx_slave_alloc,
11151 .slave_configure = aic7xxx_slave_configure,
11152 .slave_destroy = aic7xxx_slave_destroy,
11153 .bios_param = aic7xxx_biosparam,
11154 .eh_abort_handler = aic7xxx_abort,
11155 .eh_device_reset_handler = aic7xxx_bus_device_reset,
11156 .eh_host_reset_handler = aic7xxx_reset,
11157 .can_queue = 255,
11158 .this_id = -1,
11159 .max_sectors = 2048,
11160 .cmd_per_lun = 3,
11161 .use_clustering = ENABLE_CLUSTERING,
11164 #include "scsi_module.c"
11167 * Overrides for Emacs so that we almost follow Linus's tabbing style.
11168 * Emacs will notice this stuff at the end of the file and automatically
11169 * adjust the settings for this buffer only. This must remain at the end
11170 * of the file.
11171 * ---------------------------------------------------------------------------
11172 * Local variables:
11173 * c-indent-level: 2
11174 * c-brace-imaginary-offset: 0
11175 * c-brace-offset: -2
11176 * c-argdecl-indent: 2
11177 * c-label-offset: -2
11178 * c-continued-statement-offset: 2
11179 * c-continued-brace-offset: 0
11180 * indent-tabs-mode: nil
11181 * tab-width: 8
11182 * End: