Merge with Linux 2.5.48.
[linux-2.6/linux-mips.git] / drivers / scsi / aic7xxx_old.c
blob36d4198e6b1ee1eaf99a7f7ee845c5e44027d458
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 accomodate 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 "scsi.h"
242 #include "hosts.h"
243 #include "aic7xxx_old/aic7xxx.h"
245 #include "aic7xxx_old/sequencer.h"
246 #include "aic7xxx_old/scsi_message.h"
247 #include "aic7xxx_old/aic7xxx_reg.h"
248 #include <scsi/scsicam.h>
250 #include <linux/stat.h>
251 #include <linux/slab.h> /* for kmalloc() */
253 #include <linux/config.h> /* for CONFIG_PCI */
255 #define AIC7XXX_C_VERSION "5.2.6"
257 #define NUMBER(arr) (sizeof(arr) / sizeof(arr[0]))
258 #define MIN(a,b) (((a) < (b)) ? (a) : (b))
259 #define MAX(a,b) (((a) > (b)) ? (a) : (b))
260 #define ALL_TARGETS -1
261 #define ALL_CHANNELS -1
262 #define ALL_LUNS -1
263 #define MAX_TARGETS 16
264 #define MAX_LUNS 8
265 #ifndef TRUE
266 # define TRUE 1
267 #endif
268 #ifndef FALSE
269 # define FALSE 0
270 #endif
272 #if defined(__powerpc__) || defined(__i386__) || defined(__x86_64__)
273 # define MMAPIO
274 #endif
277 * You can try raising me for better performance or lowering me if you have
278 * flaky devices that go off the scsi bus when hit with too many tagged
279 * commands (like some IBM SCSI-3 LVD drives).
281 #define AIC7XXX_CMDS_PER_DEVICE 32
283 typedef struct
285 unsigned char tag_commands[16]; /* Allow for wide/twin adapters. */
286 } adapter_tag_info_t;
289 * Make a define that will tell the driver not to the default tag depth
290 * everywhere.
292 #define DEFAULT_TAG_COMMANDS {0, 0, 0, 0, 0, 0, 0, 0,\
293 0, 0, 0, 0, 0, 0, 0, 0}
296 * Modify this as you see fit for your system. By setting tag_commands
297 * to 0, the driver will use it's own algorithm for determining the
298 * number of commands to use (see above). When 255, the driver will
299 * not enable tagged queueing for that particular device. When positive
300 * (> 0) and (< 255) the values in the array are used for the queue_depth.
301 * Note that the maximum value for an entry is 254, but you're insane if
302 * you try to use that many commands on one device.
304 * In this example, the first line will disable tagged queueing for all
305 * the devices on the first probed aic7xxx adapter.
307 * The second line enables tagged queueing with 4 commands/LUN for IDs
308 * (1, 2-11, 13-15), disables tagged queueing for ID 12, and tells the
309 * driver to use its own algorithm for ID 1.
311 * The third line is the same as the first line.
313 * The fourth line disables tagged queueing for devices 0 and 3. It
314 * enables tagged queueing for the other IDs, with 16 commands/LUN
315 * for IDs 1 and 4, 127 commands/LUN for ID 8, and 4 commands/LUN for
316 * IDs 2, 5-7, and 9-15.
320 * NOTE: The below structure is for reference only, the actual structure
321 * to modify in order to change things is found after this fake one.
323 adapter_tag_info_t aic7xxx_tag_info[] =
325 {DEFAULT_TAG_COMMANDS},
326 {{4, 0, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 255, 4, 4, 4}},
327 {DEFAULT_TAG_COMMANDS},
328 {{255, 16, 4, 255, 16, 4, 4, 4, 127, 4, 4, 4, 4, 4, 4, 4}}
332 static adapter_tag_info_t aic7xxx_tag_info[] =
334 {DEFAULT_TAG_COMMANDS},
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}
354 * Define an array of board names that can be indexed by aha_type.
355 * Don't forget to change this when changing the types!
357 static const char *board_names[] = {
358 "AIC-7xxx Unknown", /* AIC_NONE */
359 "Adaptec AIC-7810 Hardware RAID Controller", /* AIC_7810 */
360 "Adaptec AIC-7770 SCSI host adapter", /* AIC_7770 */
361 "Adaptec AHA-274X SCSI host adapter", /* AIC_7771 */
362 "Adaptec AHA-284X SCSI host adapter", /* AIC_284x */
363 "Adaptec AIC-7850 SCSI host adapter", /* AIC_7850 */
364 "Adaptec AIC-7855 SCSI host adapter", /* AIC_7855 */
365 "Adaptec AIC-7860 Ultra SCSI host adapter", /* AIC_7860 */
366 "Adaptec AHA-2940A Ultra SCSI host adapter", /* AIC_7861 */
367 "Adaptec AIC-7870 SCSI host adapter", /* AIC_7870 */
368 "Adaptec AHA-294X SCSI host adapter", /* AIC_7871 */
369 "Adaptec AHA-394X SCSI host adapter", /* AIC_7872 */
370 "Adaptec AHA-398X SCSI host adapter", /* AIC_7873 */
371 "Adaptec AHA-2944 SCSI host adapter", /* AIC_7874 */
372 "Adaptec AIC-7880 Ultra SCSI host adapter", /* AIC_7880 */
373 "Adaptec AHA-294X Ultra SCSI host adapter", /* AIC_7881 */
374 "Adaptec AHA-394X Ultra SCSI host adapter", /* AIC_7882 */
375 "Adaptec AHA-398X Ultra SCSI host adapter", /* AIC_7883 */
376 "Adaptec AHA-2944 Ultra SCSI host adapter", /* AIC_7884 */
377 "Adaptec AHA-2940UW Pro Ultra SCSI host adapter", /* AIC_7887 */
378 "Adaptec AIC-7895 Ultra SCSI host adapter", /* AIC_7895 */
379 "Adaptec AIC-7890/1 Ultra2 SCSI host adapter", /* AIC_7890 */
380 "Adaptec AHA-293X Ultra2 SCSI host adapter", /* AIC_7890 */
381 "Adaptec AHA-294X Ultra2 SCSI host adapter", /* AIC_7890 */
382 "Adaptec AIC-7896/7 Ultra2 SCSI host adapter", /* AIC_7896 */
383 "Adaptec AHA-394X Ultra2 SCSI host adapter", /* AIC_7897 */
384 "Adaptec AHA-395X Ultra2 SCSI host adapter", /* AIC_7897 */
385 "Adaptec PCMCIA SCSI controller", /* card bus stuff */
386 "Adaptec AIC-7892 Ultra 160/m SCSI host adapter", /* AIC_7892 */
387 "Adaptec AIC-7899 Ultra 160/m SCSI host adapter", /* AIC_7899 */
391 * There should be a specific return value for this in scsi.h, but
392 * it seems that most drivers ignore it.
394 #define DID_UNDERFLOW DID_ERROR
397 * What we want to do is have the higher level scsi driver requeue
398 * the command to us. There is no specific driver status for this
399 * condition, but the higher level scsi driver will requeue the
400 * command on a DID_BUS_BUSY error.
402 * Upon further inspection and testing, it seems that DID_BUS_BUSY
403 * will *always* retry the command. We can get into an infinite loop
404 * if this happens when we really want some sort of counter that
405 * will automatically abort/reset the command after so many retries.
406 * Using DID_ERROR will do just that. (Made by a suggestion by
407 * Doug Ledford 8/1/96)
409 #define DID_RETRY_COMMAND DID_ERROR
411 #define HSCSIID 0x07
412 #define SCSI_RESET 0x040
415 * EISA/VL-bus stuff
417 #define MINSLOT 1
418 #define MAXSLOT 15
419 #define SLOTBASE(x) ((x) << 12)
420 #define BASE_TO_SLOT(x) ((x) >> 12)
423 * Standard EISA Host ID regs (Offset from slot base)
425 #define AHC_HID0 0x80 /* 0,1: msb of ID2, 2-7: ID1 */
426 #define AHC_HID1 0x81 /* 0-4: ID3, 5-7: LSB ID2 */
427 #define AHC_HID2 0x82 /* product */
428 #define AHC_HID3 0x83 /* firmware revision */
431 * AIC-7770 I/O range to reserve for a card
433 #define MINREG 0xC00
434 #define MAXREG 0xCFF
436 #define INTDEF 0x5C /* Interrupt Definition Register */
439 * AIC-78X0 PCI registers
441 #define CLASS_PROGIF_REVID 0x08
442 #define DEVREVID 0x000000FFul
443 #define PROGINFC 0x0000FF00ul
444 #define SUBCLASS 0x00FF0000ul
445 #define BASECLASS 0xFF000000ul
447 #define CSIZE_LATTIME 0x0C
448 #define CACHESIZE 0x0000003Ful /* only 5 bits */
449 #define LATTIME 0x0000FF00ul
451 #define DEVCONFIG 0x40
452 #define SCBSIZE32 0x00010000ul /* aic789X only */
453 #define MPORTMODE 0x00000400ul /* aic7870 only */
454 #define RAMPSM 0x00000200ul /* aic7870 only */
455 #define RAMPSM_ULTRA2 0x00000004
456 #define VOLSENSE 0x00000100ul
457 #define SCBRAMSEL 0x00000080ul
458 #define SCBRAMSEL_ULTRA2 0x00000008
459 #define MRDCEN 0x00000040ul
460 #define EXTSCBTIME 0x00000020ul /* aic7870 only */
461 #define EXTSCBPEN 0x00000010ul /* aic7870 only */
462 #define BERREN 0x00000008ul
463 #define DACEN 0x00000004ul
464 #define STPWLEVEL 0x00000002ul
465 #define DIFACTNEGEN 0x00000001ul /* aic7870 only */
467 #define SCAMCTL 0x1a /* Ultra2 only */
468 #define CCSCBBADDR 0xf0 /* aic7895/6/7 */
471 * Define the different types of SEEPROMs on aic7xxx adapters
472 * and make it also represent the address size used in accessing
473 * its registers. The 93C46 chips have 1024 bits organized into
474 * 64 16-bit words, while the 93C56 chips have 2048 bits organized
475 * into 128 16-bit words. The C46 chips use 6 bits to address
476 * each word, while the C56 and C66 (4096 bits) use 8 bits to
477 * address each word.
479 typedef enum {C46 = 6, C56_66 = 8} seeprom_chip_type;
483 * Define the format of the SEEPROM registers (16 bits).
486 struct seeprom_config {
489 * SCSI ID Configuration Flags
491 #define CFXFER 0x0007 /* synchronous transfer rate */
492 #define CFSYNCH 0x0008 /* enable synchronous transfer */
493 #define CFDISC 0x0010 /* enable disconnection */
494 #define CFWIDEB 0x0020 /* wide bus device (wide card) */
495 #define CFSYNCHISULTRA 0x0040 /* CFSYNC is an ultra offset */
496 #define CFNEWULTRAFORMAT 0x0080 /* Use the Ultra2 SEEPROM format */
497 #define CFSTART 0x0100 /* send start unit SCSI command */
498 #define CFINCBIOS 0x0200 /* include in BIOS scan */
499 #define CFRNFOUND 0x0400 /* report even if not found */
500 #define CFMULTILUN 0x0800 /* probe mult luns in BIOS scan */
501 #define CFWBCACHEYES 0x4000 /* Enable W-Behind Cache on drive */
502 #define CFWBCACHENC 0xc000 /* Don't change W-Behind Cache */
503 /* UNUSED 0x3000 */
504 unsigned short device_flags[16]; /* words 0-15 */
507 * BIOS Control Bits
509 #define CFSUPREM 0x0001 /* support all removable drives */
510 #define CFSUPREMB 0x0002 /* support removable drives for boot only */
511 #define CFBIOSEN 0x0004 /* BIOS enabled */
512 /* UNUSED 0x0008 */
513 #define CFSM2DRV 0x0010 /* support more than two drives */
514 #define CF284XEXTEND 0x0020 /* extended translation (284x cards) */
515 /* UNUSED 0x0040 */
516 #define CFEXTEND 0x0080 /* extended translation enabled */
517 /* UNUSED 0xFF00 */
518 unsigned short bios_control; /* word 16 */
521 * Host Adapter Control Bits
523 #define CFAUTOTERM 0x0001 /* Perform Auto termination */
524 #define CFULTRAEN 0x0002 /* Ultra SCSI speed enable (Ultra cards) */
525 #define CF284XSELTO 0x0003 /* Selection timeout (284x cards) */
526 #define CF284XFIFO 0x000C /* FIFO Threshold (284x cards) */
527 #define CFSTERM 0x0004 /* SCSI low byte termination */
528 #define CFWSTERM 0x0008 /* SCSI high byte termination (wide card) */
529 #define CFSPARITY 0x0010 /* SCSI parity */
530 #define CF284XSTERM 0x0020 /* SCSI low byte termination (284x cards) */
531 #define CFRESETB 0x0040 /* reset SCSI bus at boot */
532 #define CFBPRIMARY 0x0100 /* Channel B primary on 7895 chipsets */
533 #define CFSEAUTOTERM 0x0400 /* aic7890 Perform SE Auto Term */
534 #define CFLVDSTERM 0x0800 /* aic7890 LVD Termination */
535 /* UNUSED 0xF280 */
536 unsigned short adapter_control; /* word 17 */
539 * Bus Release, Host Adapter ID
541 #define CFSCSIID 0x000F /* host adapter SCSI ID */
542 /* UNUSED 0x00F0 */
543 #define CFBRTIME 0xFF00 /* bus release time */
544 unsigned short brtime_id; /* word 18 */
547 * Maximum targets
549 #define CFMAXTARG 0x00FF /* maximum targets */
550 /* UNUSED 0xFF00 */
551 unsigned short max_targets; /* word 19 */
553 unsigned short res_1[11]; /* words 20-30 */
554 unsigned short checksum; /* word 31 */
557 #define SELBUS_MASK 0x0a
558 #define SELNARROW 0x00
559 #define SELBUSB 0x08
560 #define SINGLE_BUS 0x00
562 #define SCB_TARGET(scb) \
563 (((scb)->hscb->target_channel_lun & TID) >> 4)
564 #define SCB_LUN(scb) \
565 ((scb)->hscb->target_channel_lun & LID)
566 #define SCB_IS_SCSIBUS_B(scb) \
567 (((scb)->hscb->target_channel_lun & SELBUSB) != 0)
570 * If an error occurs during a data transfer phase, run the command
571 * to completion - it's easier that way - making a note of the error
572 * condition in this location. This then will modify a DID_OK status
573 * into an appropriate error for the higher-level SCSI code.
575 #define aic7xxx_error(cmd) ((cmd)->SCp.Status)
578 * Keep track of the targets returned status.
580 #define aic7xxx_status(cmd) ((cmd)->SCp.sent_command)
583 * The position of the SCSI commands scb within the scb array.
585 #define aic7xxx_position(cmd) ((cmd)->SCp.have_data_in)
588 * The stored DMA mapping for single-buffer data transfers.
590 #define aic7xxx_mapping(cmd) ((cmd)->SCp.phase)
593 * Get out private data area from a scsi cmd pointer
595 #define AIC_DEV(cmd) ((struct aic_dev_data *)(cmd)->device->hostdata)
598 * So we can keep track of our host structs
600 static struct aic7xxx_host *first_aic7xxx = NULL;
603 * As of Linux 2.1, the mid-level SCSI code uses virtual addresses
604 * in the scatter-gather lists. We need to convert the virtual
605 * addresses to physical addresses.
607 struct hw_scatterlist {
608 unsigned int address;
609 unsigned int length;
613 * Maximum number of SG segments these cards can support.
615 #define AIC7XXX_MAX_SG 128
618 * The maximum number of SCBs we could have for ANY type
619 * of card. DON'T FORGET TO CHANGE THE SCB MASK IN THE
620 * SEQUENCER CODE IF THIS IS MODIFIED!
622 #define AIC7XXX_MAXSCB 255
625 struct aic7xxx_hwscb {
626 /* ------------ Begin hardware supported fields ---------------- */
627 /* 0*/ unsigned char control;
628 /* 1*/ unsigned char target_channel_lun; /* 4/1/3 bits */
629 /* 2*/ unsigned char target_status;
630 /* 3*/ unsigned char SG_segment_count;
631 /* 4*/ unsigned int SG_list_pointer;
632 /* 8*/ unsigned char residual_SG_segment_count;
633 /* 9*/ unsigned char residual_data_count[3];
634 /*12*/ unsigned int data_pointer;
635 /*16*/ unsigned int data_count;
636 /*20*/ unsigned int SCSI_cmd_pointer;
637 /*24*/ unsigned char SCSI_cmd_length;
638 /*25*/ unsigned char tag; /* Index into our kernel SCB array.
639 * Also used as the tag for tagged I/O
641 #define SCB_PIO_TRANSFER_SIZE 26 /* amount we need to upload/download
642 * via PIO to initialize a transaction.
644 /*26*/ unsigned char next; /* Used to thread SCBs awaiting selection
645 * or disconnected down in the sequencer.
647 /*27*/ unsigned char prev;
648 /*28*/ unsigned int pad; /*
649 * Unused by the kernel, but we require
650 * the padding so that the array of
651 * hardware SCBs is aligned on 32 byte
652 * boundaries so the sequencer can index
656 typedef enum {
657 SCB_FREE = 0x0000,
658 SCB_DTR_SCB = 0x0001,
659 SCB_WAITINGQ = 0x0002,
660 SCB_ACTIVE = 0x0004,
661 SCB_SENSE = 0x0008,
662 SCB_ABORT = 0x0010,
663 SCB_DEVICE_RESET = 0x0020,
664 SCB_RESET = 0x0040,
665 SCB_RECOVERY_SCB = 0x0080,
666 SCB_MSGOUT_PPR = 0x0100,
667 SCB_MSGOUT_SENT = 0x0200,
668 SCB_MSGOUT_SDTR = 0x0400,
669 SCB_MSGOUT_WDTR = 0x0800,
670 SCB_MSGOUT_BITS = SCB_MSGOUT_PPR |
671 SCB_MSGOUT_SENT |
672 SCB_MSGOUT_SDTR |
673 SCB_MSGOUT_WDTR,
674 SCB_QUEUED_ABORT = 0x1000,
675 SCB_QUEUED_FOR_DONE = 0x2000,
676 SCB_WAS_BUSY = 0x4000,
677 SCB_QUEUE_FULL = 0x8000
678 } scb_flag_type;
680 typedef enum {
681 AHC_FNONE = 0x00000000,
682 AHC_PAGESCBS = 0x00000001,
683 AHC_CHANNEL_B_PRIMARY = 0x00000002,
684 AHC_USEDEFAULTS = 0x00000004,
685 AHC_INDIRECT_PAGING = 0x00000008,
686 AHC_CHNLB = 0x00000020,
687 AHC_CHNLC = 0x00000040,
688 AHC_EXTEND_TRANS_A = 0x00000100,
689 AHC_EXTEND_TRANS_B = 0x00000200,
690 AHC_TERM_ENB_A = 0x00000400,
691 AHC_TERM_ENB_SE_LOW = 0x00000400,
692 AHC_TERM_ENB_B = 0x00000800,
693 AHC_TERM_ENB_SE_HIGH = 0x00000800,
694 AHC_HANDLING_REQINITS = 0x00001000,
695 AHC_TARGETMODE = 0x00002000,
696 AHC_NEWEEPROM_FMT = 0x00004000,
698 * Here ends the FreeBSD defined flags and here begins the linux defined
699 * flags. NOTE: I did not preserve the old flag name during this change
700 * specifically to force me to evaluate what flags were being used properly
701 * and what flags weren't. This way, I could clean up the flag usage on
702 * a use by use basis. Doug Ledford
704 AHC_MOTHERBOARD = 0x00020000,
705 AHC_NO_STPWEN = 0x00040000,
706 AHC_RESET_DELAY = 0x00080000,
707 AHC_A_SCANNED = 0x00100000,
708 AHC_B_SCANNED = 0x00200000,
709 AHC_MULTI_CHANNEL = 0x00400000,
710 AHC_BIOS_ENABLED = 0x00800000,
711 AHC_SEEPROM_FOUND = 0x01000000,
712 AHC_TERM_ENB_LVD = 0x02000000,
713 AHC_ABORT_PENDING = 0x04000000,
714 AHC_RESET_PENDING = 0x08000000,
715 #define AHC_IN_ISR_BIT 28
716 AHC_IN_ISR = 0x10000000,
717 AHC_IN_ABORT = 0x20000000,
718 AHC_IN_RESET = 0x40000000,
719 AHC_EXTERNAL_SRAM = 0x80000000
720 } ahc_flag_type;
722 typedef enum {
723 AHC_NONE = 0x0000,
724 AHC_CHIPID_MASK = 0x00ff,
725 AHC_AIC7770 = 0x0001,
726 AHC_AIC7850 = 0x0002,
727 AHC_AIC7860 = 0x0003,
728 AHC_AIC7870 = 0x0004,
729 AHC_AIC7880 = 0x0005,
730 AHC_AIC7890 = 0x0006,
731 AHC_AIC7895 = 0x0007,
732 AHC_AIC7896 = 0x0008,
733 AHC_AIC7892 = 0x0009,
734 AHC_AIC7899 = 0x000a,
735 AHC_VL = 0x0100,
736 AHC_EISA = 0x0200,
737 AHC_PCI = 0x0400,
738 } ahc_chip;
740 typedef enum {
741 AHC_FENONE = 0x0000,
742 AHC_ULTRA = 0x0001,
743 AHC_ULTRA2 = 0x0002,
744 AHC_WIDE = 0x0004,
745 AHC_TWIN = 0x0008,
746 AHC_MORE_SRAM = 0x0010,
747 AHC_CMD_CHAN = 0x0020,
748 AHC_QUEUE_REGS = 0x0040,
749 AHC_SG_PRELOAD = 0x0080,
750 AHC_SPIOCAP = 0x0100,
751 AHC_ULTRA3 = 0x0200,
752 AHC_NEW_AUTOTERM = 0x0400,
753 AHC_AIC7770_FE = AHC_FENONE,
754 AHC_AIC7850_FE = AHC_SPIOCAP,
755 AHC_AIC7860_FE = AHC_ULTRA|AHC_SPIOCAP,
756 AHC_AIC7870_FE = AHC_FENONE,
757 AHC_AIC7880_FE = AHC_ULTRA,
758 AHC_AIC7890_FE = AHC_MORE_SRAM|AHC_CMD_CHAN|AHC_ULTRA2|
759 AHC_QUEUE_REGS|AHC_SG_PRELOAD|AHC_NEW_AUTOTERM,
760 AHC_AIC7895_FE = AHC_MORE_SRAM|AHC_CMD_CHAN|AHC_ULTRA,
761 AHC_AIC7896_FE = AHC_AIC7890_FE,
762 AHC_AIC7892_FE = AHC_AIC7890_FE|AHC_ULTRA3,
763 AHC_AIC7899_FE = AHC_AIC7890_FE|AHC_ULTRA3,
764 } ahc_feature;
766 #define SCB_DMA_ADDR(scb, addr) ((unsigned long)(addr) + (scb)->scb_dma->dma_offset)
768 struct aic7xxx_scb_dma {
769 unsigned long dma_offset; /* Correction you have to add
770 * to virtual address to get
771 * dma handle in this region */
772 dma_addr_t dma_address; /* DMA handle of the start,
773 * for unmap */
774 unsigned int dma_len; /* DMA length */
777 typedef enum {
778 AHC_BUG_NONE = 0x0000,
779 AHC_BUG_TMODE_WIDEODD = 0x0001,
780 AHC_BUG_AUTOFLUSH = 0x0002,
781 AHC_BUG_CACHETHEN = 0x0004,
782 AHC_BUG_CACHETHEN_DIS = 0x0008,
783 AHC_BUG_PCI_2_1_RETRY = 0x0010,
784 AHC_BUG_PCI_MWI = 0x0020,
785 AHC_BUG_SCBCHAN_UPLOAD = 0x0040,
786 } ahc_bugs;
788 struct aic7xxx_scb {
789 struct aic7xxx_hwscb *hscb; /* corresponding hardware scb */
790 Scsi_Cmnd *cmd; /* Scsi_Cmnd for this scb */
791 struct aic7xxx_scb *q_next; /* next scb in queue */
792 volatile scb_flag_type flags; /* current state of scb */
793 struct hw_scatterlist *sg_list; /* SG list in adapter format */
794 unsigned char tag_action;
795 unsigned char sg_count;
796 unsigned char *sense_cmd; /*
797 * Allocate 6 characters for
798 * sense command.
800 unsigned char *cmnd;
801 unsigned int sg_length; /* We init this during buildscb so we
802 * don't have to calculate anything
803 * during underflow/overflow/stat code
805 void *kmalloc_ptr;
806 struct aic7xxx_scb_dma *scb_dma;
810 * Define a linked list of SCBs.
812 typedef struct {
813 struct aic7xxx_scb *head;
814 struct aic7xxx_scb *tail;
815 } scb_queue_type;
817 static struct {
818 unsigned char errno;
819 const char *errmesg;
820 } hard_error[] = {
821 { ILLHADDR, "Illegal Host Access" },
822 { ILLSADDR, "Illegal Sequencer Address referenced" },
823 { ILLOPCODE, "Illegal Opcode in sequencer program" },
824 { SQPARERR, "Sequencer Ram Parity Error" },
825 { DPARERR, "Data-Path Ram Parity Error" },
826 { MPARERR, "Scratch Ram/SCB Array Ram Parity Error" },
827 { PCIERRSTAT,"PCI Error detected" },
828 { CIOPARERR, "CIOBUS Parity Error" }
831 static unsigned char
832 generic_sense[] = { REQUEST_SENSE, 0, 0, 0, 255, 0 };
834 typedef struct {
835 scb_queue_type free_scbs; /*
836 * SCBs assigned to free slot on
837 * card (no paging required)
839 struct aic7xxx_scb *scb_array[AIC7XXX_MAXSCB];
840 struct aic7xxx_hwscb *hscbs;
841 unsigned char numscbs; /* current number of scbs */
842 unsigned char maxhscbs; /* hardware scbs */
843 unsigned char maxscbs; /* max scbs including pageable scbs */
844 dma_addr_t hscbs_dma; /* DMA handle to hscbs */
845 unsigned int hscbs_dma_len; /* length of the above DMA area */
846 void *hscb_kmalloc_ptr;
847 } scb_data_type;
849 struct target_cmd {
850 unsigned char mesg_bytes[4];
851 unsigned char command[28];
854 #define AHC_TRANS_CUR 0x0001
855 #define AHC_TRANS_ACTIVE 0x0002
856 #define AHC_TRANS_GOAL 0x0004
857 #define AHC_TRANS_USER 0x0008
858 #define AHC_TRANS_QUITE 0x0010
859 typedef struct {
860 unsigned char width;
861 unsigned char period;
862 unsigned char offset;
863 unsigned char options;
864 } transinfo_type;
866 struct aic_dev_data {
867 volatile scb_queue_type delayed_scbs;
868 volatile unsigned short temp_q_depth;
869 unsigned short max_q_depth;
870 volatile unsigned char active_cmds;
872 * Statistics Kept:
874 * Total Xfers (count for each command that has a data xfer),
875 * broken down by reads && writes.
877 * Further sorted into a few bins for keeping tabs on how many commands
878 * we get of various sizes.
881 long w_total; /* total writes */
882 long r_total; /* total reads */
883 long barrier_total; /* total num of REQ_BARRIER commands */
884 long ordered_total; /* How many REQ_BARRIER commands we
885 used ordered tags to satisfy */
886 long w_bins[6]; /* binned write */
887 long r_bins[6]; /* binned reads */
888 transinfo_type cur;
889 transinfo_type goal;
890 #define BUS_DEVICE_RESET_PENDING 0x01
891 #define DEVICE_RESET_DELAY 0x02
892 #define DEVICE_PRINT_DTR 0x04
893 #define DEVICE_WAS_BUSY 0x08
894 #define DEVICE_DTR_SCANNED 0x10
895 #define DEVICE_SCSI_3 0x20
896 volatile unsigned char flags;
897 unsigned needppr:1;
898 unsigned needppr_copy:1;
899 unsigned needsdtr:1;
900 unsigned needsdtr_copy:1;
901 unsigned needwdtr:1;
902 unsigned needwdtr_copy:1;
903 unsigned dtr_pending:1;
904 struct scsi_device *SDptr;
905 struct list_head list;
909 * Define a structure used for each host adapter. Note, in order to avoid
910 * problems with architectures I can't test on (because I don't have one,
911 * such as the Alpha based systems) which happen to give faults for
912 * non-aligned memory accesses, care was taken to align this structure
913 * in a way that gauranteed all accesses larger than 8 bits were aligned
914 * on the appropriate boundary. It's also organized to try and be more
915 * cache line efficient. Be careful when changing this lest you might hurt
916 * overall performance and bring down the wrath of the masses.
918 struct aic7xxx_host {
920 * This is the first 64 bytes in the host struct
924 * We are grouping things here....first, items that get either read or
925 * written with nearly every interrupt
927 volatile long flags;
928 ahc_feature features; /* chip features */
929 unsigned long base; /* card base address */
930 volatile unsigned char *maddr; /* memory mapped address */
931 unsigned long isr_count; /* Interrupt count */
932 unsigned long spurious_int;
933 scb_data_type *scb_data;
934 struct aic7xxx_cmd_queue {
935 Scsi_Cmnd *head;
936 Scsi_Cmnd *tail;
937 } completeq;
940 * Things read/written on nearly every entry into aic7xxx_queue()
942 volatile scb_queue_type waiting_scbs;
943 unsigned char unpause; /* unpause value for HCNTRL */
944 unsigned char pause; /* pause value for HCNTRL */
945 volatile unsigned char qoutfifonext;
946 volatile unsigned char activescbs; /* active scbs */
947 volatile unsigned char max_activescbs;
948 volatile unsigned char qinfifonext;
949 volatile unsigned char *untagged_scbs;
950 volatile unsigned char *qoutfifo;
951 volatile unsigned char *qinfifo;
953 unsigned char dev_last_queue_full[MAX_TARGETS];
954 unsigned char dev_last_queue_full_count[MAX_TARGETS];
955 unsigned short ultraenb; /* Gets downloaded to card as a
956 bitmap */
957 unsigned short discenable; /* Gets downloaded to card as a
958 bitmap */
959 transinfo_type user[MAX_TARGETS];
961 unsigned char msg_buf[13]; /* The message for the target */
962 unsigned char msg_type;
963 #define MSG_TYPE_NONE 0x00
964 #define MSG_TYPE_INITIATOR_MSGOUT 0x01
965 #define MSG_TYPE_INITIATOR_MSGIN 0x02
966 unsigned char msg_len; /* Length of message */
967 unsigned char msg_index; /* Index into msg_buf array */
971 * We put the less frequently used host structure items after the more
972 * frequently used items to try and ease the burden on the cache subsystem.
973 * These entries are not *commonly* accessed, whereas the preceding entries
974 * are accessed very often.
977 unsigned int irq; /* IRQ for this adapter */
978 int instance; /* aic7xxx instance number */
979 int scsi_id; /* host adapter SCSI ID */
980 int scsi_id_b; /* channel B for twin adapters */
981 unsigned int bios_address;
982 int board_name_index;
983 unsigned short bios_control; /* bios control - SEEPROM */
984 unsigned short adapter_control; /* adapter control - SEEPROM */
985 struct pci_dev *pdev;
986 unsigned char pci_bus;
987 unsigned char pci_device_fn;
988 struct seeprom_config sc;
989 unsigned short sc_type;
990 unsigned short sc_size;
991 struct aic7xxx_host *next; /* allow for multiple IRQs */
992 struct Scsi_Host *host; /* pointer to scsi host */
993 struct list_head aic_devs; /* all aic_dev structs on host */
994 int host_no; /* SCSI host number */
995 unsigned long mbase; /* I/O memory address */
996 ahc_chip chip; /* chip type */
997 ahc_bugs bugs;
998 dma_addr_t fifo_dma; /* DMA handle for fifo arrays */
1003 * Valid SCSIRATE values. (p. 3-17)
1004 * Provides a mapping of transfer periods in ns/4 to the proper value to
1005 * stick in the SCSIRATE reg to use that transfer rate.
1007 #define AHC_SYNCRATE_ULTRA3 0
1008 #define AHC_SYNCRATE_ULTRA2 1
1009 #define AHC_SYNCRATE_ULTRA 3
1010 #define AHC_SYNCRATE_FAST 6
1011 #define AHC_SYNCRATE_CRC 0x40
1012 #define AHC_SYNCRATE_SE 0x10
1013 static struct aic7xxx_syncrate {
1014 /* Rates in Ultra mode have bit 8 of sxfr set */
1015 #define ULTRA_SXFR 0x100
1016 int sxfr_ultra2;
1017 int sxfr;
1018 unsigned char period;
1019 const char *rate[2];
1020 } aic7xxx_syncrates[] = {
1021 { 0x42, 0x000, 9, {"80.0", "160.0"} },
1022 { 0x13, 0x000, 10, {"40.0", "80.0"} },
1023 { 0x14, 0x000, 11, {"33.0", "66.6"} },
1024 { 0x15, 0x100, 12, {"20.0", "40.0"} },
1025 { 0x16, 0x110, 15, {"16.0", "32.0"} },
1026 { 0x17, 0x120, 18, {"13.4", "26.8"} },
1027 { 0x18, 0x000, 25, {"10.0", "20.0"} },
1028 { 0x19, 0x010, 31, {"8.0", "16.0"} },
1029 { 0x1a, 0x020, 37, {"6.67", "13.3"} },
1030 { 0x1b, 0x030, 43, {"5.7", "11.4"} },
1031 { 0x10, 0x040, 50, {"5.0", "10.0"} },
1032 { 0x00, 0x050, 56, {"4.4", "8.8" } },
1033 { 0x00, 0x060, 62, {"4.0", "8.0" } },
1034 { 0x00, 0x070, 68, {"3.6", "7.2" } },
1035 { 0x00, 0x000, 0, {NULL, NULL} },
1038 #define CTL_OF_SCB(scb) (((scb->hscb)->target_channel_lun >> 3) & 0x1), \
1039 (((scb->hscb)->target_channel_lun >> 4) & 0xf), \
1040 ((scb->hscb)->target_channel_lun & 0x07)
1042 #define CTL_OF_CMD(cmd) ((cmd->channel) & 0x01), \
1043 ((cmd->target) & 0x0f), \
1044 ((cmd->lun) & 0x07)
1046 #define TARGET_INDEX(cmd) ((cmd)->target | ((cmd)->channel << 3))
1049 * A nice little define to make doing our printks a little easier
1052 #define WARN_LEAD KERN_WARNING "(scsi%d:%d:%d:%d) "
1053 #define INFO_LEAD KERN_INFO "(scsi%d:%d:%d:%d) "
1056 * XXX - these options apply unilaterally to _all_ 274x/284x/294x
1057 * cards in the system. This should be fixed. Exceptions to this
1058 * rule are noted in the comments.
1062 * Use this as the default queue depth when setting tagged queueing on.
1064 static unsigned int aic7xxx_default_queue_depth = AIC7XXX_CMDS_PER_DEVICE;
1067 * Skip the scsi bus reset. Non 0 make us skip the reset at startup. This
1068 * has no effect on any later resets that might occur due to things like
1069 * SCSI bus timeouts.
1071 static unsigned int aic7xxx_no_reset = 0;
1073 * Certain PCI motherboards will scan PCI devices from highest to lowest,
1074 * others scan from lowest to highest, and they tend to do all kinds of
1075 * strange things when they come into contact with PCI bridge chips. The
1076 * net result of all this is that the PCI card that is actually used to boot
1077 * the machine is very hard to detect. Most motherboards go from lowest
1078 * PCI slot number to highest, and the first SCSI controller found is the
1079 * one you boot from. The only exceptions to this are when a controller
1080 * has its BIOS disabled. So, we by default sort all of our SCSI controllers
1081 * from lowest PCI slot number to highest PCI slot number. We also force
1082 * all controllers with their BIOS disabled to the end of the list. This
1083 * works on *almost* all computers. Where it doesn't work, we have this
1084 * option. Setting this option to non-0 will reverse the order of the sort
1085 * to highest first, then lowest, but will still leave cards with their BIOS
1086 * disabled at the very end. That should fix everyone up unless there are
1087 * really strange cirumstances.
1089 static int aic7xxx_reverse_scan = 0;
1091 * Should we force EXTENDED translation on a controller.
1092 * 0 == Use whatever is in the SEEPROM or default to off
1093 * 1 == Use whatever is in the SEEPROM or default to on
1095 static unsigned int aic7xxx_extended = 0;
1097 * The IRQ trigger method used on EISA controllers. Does not effect PCI cards.
1098 * -1 = Use detected settings.
1099 * 0 = Force Edge triggered mode.
1100 * 1 = Force Level triggered mode.
1102 static int aic7xxx_irq_trigger = -1;
1104 * This variable is used to override the termination settings on a controller.
1105 * This should not be used under normal conditions. However, in the case
1106 * that a controller does not have a readable SEEPROM (so that we can't
1107 * read the SEEPROM settings directly) and that a controller has a buggered
1108 * version of the cable detection logic, this can be used to force the
1109 * correct termination. It is preferable to use the manual termination
1110 * settings in the BIOS if possible, but some motherboard controllers store
1111 * those settings in a format we can't read. In other cases, auto term
1112 * should also work, but the chipset was put together with no auto term
1113 * logic (common on motherboard controllers). In those cases, we have
1114 * 32 bits here to work with. That's good for 8 controllers/channels. The
1115 * bits are organized as 4 bits per channel, with scsi0 getting the lowest
1116 * 4 bits in the int. A 1 in a bit position indicates the termination setting
1117 * that corresponds to that bit should be enabled, a 0 is disabled.
1118 * It looks something like this:
1120 * 0x0f = 1111-Single Ended Low Byte Termination on/off
1121 * ||\-Single Ended High Byte Termination on/off
1122 * |\-LVD Low Byte Termination on/off
1123 * \-LVD High Byte Termination on/off
1125 * For non-Ultra2 controllers, the upper 2 bits are not important. So, to
1126 * enable both high byte and low byte termination on scsi0, I would need to
1127 * make sure that the override_term variable was set to 0x03 (bits 0011).
1128 * To make sure that all termination is enabled on an Ultra2 controller at
1129 * scsi2 and only high byte termination on scsi1 and high and low byte
1130 * termination on scsi0, I would set override_term=0xf23 (bits 1111 0010 0011)
1132 * For the most part, users should never have to use this, that's why I
1133 * left it fairly cryptic instead of easy to understand. If you need it,
1134 * most likely someone will be telling you what your's needs to be set to.
1136 static int aic7xxx_override_term = -1;
1138 * Certain motherboard chipset controllers tend to screw
1139 * up the polarity of the term enable output pin. Use this variable
1140 * to force the correct polarity for your system. This is a bitfield variable
1141 * similar to the previous one, but this one has one bit per channel instead
1142 * of four.
1143 * 0 = Force the setting to active low.
1144 * 1 = Force setting to active high.
1145 * Most Adaptec cards are active high, several motherboards are active low.
1146 * To force a 2940 card at SCSI 0 to active high and a motherboard 7895
1147 * controller at scsi1 and scsi2 to active low, and a 2910 card at scsi3
1148 * to active high, you would need to set stpwlev=0x9 (bits 1001).
1150 * People shouldn't need to use this, but if you are experiencing lots of
1151 * SCSI timeout problems, this may help. There is one sure way to test what
1152 * this option needs to be. Using a boot floppy to boot the system, configure
1153 * your system to enable all SCSI termination (in the Adaptec SCSI BIOS) and
1154 * if needed then also pass a value to override_term to make sure that the
1155 * driver is enabling SCSI termination, then set this variable to either 0
1156 * or 1. When the driver boots, make sure there are *NO* SCSI cables
1157 * connected to your controller. If it finds and inits the controller
1158 * without problem, then the setting you passed to stpwlev was correct. If
1159 * the driver goes into a reset loop and hangs the system, then you need the
1160 * other setting for this variable. If neither setting lets the machine
1161 * boot then you have definite termination problems that may not be fixable.
1163 static int aic7xxx_stpwlev = -1;
1165 * Set this to non-0 in order to force the driver to panic the kernel
1166 * and print out debugging info on a SCSI abort or reset cycle.
1168 static int aic7xxx_panic_on_abort = 0;
1170 * PCI bus parity checking of the Adaptec controllers. This is somewhat
1171 * dubious at best. To my knowledge, this option has never actually
1172 * solved a PCI parity problem, but on certain machines with broken PCI
1173 * chipset configurations, it can generate tons of false error messages.
1174 * It's included in the driver for completeness.
1175 * 0 = Shut off PCI parity check
1176 * -1 = Normal polarity pci parity checking
1177 * 1 = reverse polarity pci parity checking
1179 * NOTE: you can't actually pass -1 on the lilo prompt. So, to set this
1180 * variable to -1 you would actually want to simply pass the variable
1181 * name without a number. That will invert the 0 which will result in
1182 * -1.
1184 static int aic7xxx_pci_parity = 0;
1186 * Set this to any non-0 value to cause us to dump the contents of all
1187 * the card's registers in a hex dump format tailored to each model of
1188 * controller.
1190 * NOTE: THE CONTROLLER IS LEFT IN AN UNUSEABLE STATE BY THIS OPTION.
1191 * YOU CANNOT BOOT UP WITH THIS OPTION, IT IS FOR DEBUGGING PURPOSES
1192 * ONLY
1194 static int aic7xxx_dump_card = 0;
1196 * Set this to a non-0 value to make us dump out the 32 bit instruction
1197 * registers on the card after completing the sequencer download. This
1198 * allows the actual sequencer download to be verified. It is possible
1199 * to use this option and still boot up and run your system. This is
1200 * only intended for debugging purposes.
1202 static int aic7xxx_dump_sequencer = 0;
1204 * Certain newer motherboards have put new PCI based devices into the
1205 * IO spaces that used to typically be occupied by VLB or EISA cards.
1206 * This overlap can cause these newer motherboards to lock up when scanned
1207 * for older EISA and VLB devices. Setting this option to non-0 will
1208 * cause the driver to skip scanning for any VLB or EISA controllers and
1209 * only support the PCI controllers. NOTE: this means that if the kernel
1210 * os compiled with PCI support disabled, then setting this to non-0
1211 * would result in never finding any devices :)
1213 static int aic7xxx_no_probe = 0;
1215 * On some machines, enabling the external SCB RAM isn't reliable yet. I
1216 * haven't had time to make test patches for things like changing the
1217 * timing mode on that external RAM either. Some of those changes may
1218 * fix the problem. Until then though, we default to external SCB RAM
1219 * off and give a command line option to enable it.
1221 static int aic7xxx_scbram = 0;
1223 * So that we can set how long each device is given as a selection timeout.
1224 * The table of values goes like this:
1225 * 0 - 256ms
1226 * 1 - 128ms
1227 * 2 - 64ms
1228 * 3 - 32ms
1229 * We default to 64ms because it's fast. Some old SCSI-I devices need a
1230 * longer time. The final value has to be left shifted by 3, hence 0x10
1231 * is the final value.
1233 static int aic7xxx_seltime = 0x10;
1235 * So that insmod can find the variable and make it point to something
1237 #ifdef MODULE
1238 static char * aic7xxx = NULL;
1239 MODULE_PARM(aic7xxx, "s");
1240 #endif
1242 #define VERBOSE_NORMAL 0x0000
1243 #define VERBOSE_NEGOTIATION 0x0001
1244 #define VERBOSE_SEQINT 0x0002
1245 #define VERBOSE_SCSIINT 0x0004
1246 #define VERBOSE_PROBE 0x0008
1247 #define VERBOSE_PROBE2 0x0010
1248 #define VERBOSE_NEGOTIATION2 0x0020
1249 #define VERBOSE_MINOR_ERROR 0x0040
1250 #define VERBOSE_TRACING 0x0080
1251 #define VERBOSE_ABORT 0x0f00
1252 #define VERBOSE_ABORT_MID 0x0100
1253 #define VERBOSE_ABORT_FIND 0x0200
1254 #define VERBOSE_ABORT_PROCESS 0x0400
1255 #define VERBOSE_ABORT_RETURN 0x0800
1256 #define VERBOSE_RESET 0xf000
1257 #define VERBOSE_RESET_MID 0x1000
1258 #define VERBOSE_RESET_FIND 0x2000
1259 #define VERBOSE_RESET_PROCESS 0x4000
1260 #define VERBOSE_RESET_RETURN 0x8000
1261 static int aic7xxx_verbose = VERBOSE_NORMAL | VERBOSE_NEGOTIATION |
1262 VERBOSE_PROBE; /* verbose messages */
1265 /****************************************************************************
1267 * We're going to start putting in function declarations so that order of
1268 * functions is no longer important. As needed, they are added here.
1270 ***************************************************************************/
1272 static void aic7xxx_set_syncrate(struct aic7xxx_host *p,
1273 struct aic7xxx_syncrate *syncrate, int target, int channel,
1274 unsigned int period, unsigned int offset, unsigned char options,
1275 unsigned int type, struct aic_dev_data *aic_dev);
1276 static void aic7xxx_set_width(struct aic7xxx_host *p, int target, int channel,
1277 int lun, unsigned int width, unsigned int type,
1278 struct aic_dev_data *aic_dev);
1279 static void aic7xxx_panic_abort(struct aic7xxx_host *p, Scsi_Cmnd *cmd);
1280 static void aic7xxx_print_card(struct aic7xxx_host *p);
1281 static void aic7xxx_print_scratch_ram(struct aic7xxx_host *p);
1282 static void aic7xxx_print_sequencer(struct aic7xxx_host *p, int downloaded);
1283 #ifdef AIC7XXX_VERBOSE_DEBUGGING
1284 static void aic7xxx_check_scbs(struct aic7xxx_host *p, char *buffer);
1285 #endif
1287 /****************************************************************************
1289 * These functions are now used. They happen to be wrapped in useless
1290 * inb/outb port read/writes around the real reads and writes because it
1291 * seems that certain very fast CPUs have a problem dealing with us when
1292 * going at full speed.
1294 ***************************************************************************/
1296 static inline unsigned char
1297 aic_inb(struct aic7xxx_host *p, long port)
1299 #ifdef MMAPIO
1300 unsigned char x;
1301 if(p->maddr)
1303 x = readb(p->maddr + port);
1305 else
1307 x = inb(p->base + port);
1309 return(x);
1310 #else
1311 return(inb(p->base + port));
1312 #endif
1315 static inline void
1316 aic_outb(struct aic7xxx_host *p, unsigned char val, long port)
1318 #ifdef MMAPIO
1319 if(p->maddr)
1321 writeb(val, p->maddr + port);
1322 mb(); /* locked operation in order to force CPU ordering */
1323 readb(p->maddr + HCNTRL); /* dummy read to flush the PCI write */
1325 else
1327 outb(val, p->base + port);
1328 mb(); /* locked operation in order to force CPU ordering */
1330 #else
1331 outb(val, p->base + port);
1332 mb(); /* locked operation in order to force CPU ordering */
1333 #endif
1336 /*+F*************************************************************************
1337 * Function:
1338 * aic7xxx_setup
1340 * Description:
1341 * Handle Linux boot parameters. This routine allows for assigning a value
1342 * to a parameter with a ':' between the parameter and the value.
1343 * ie. aic7xxx=unpause:0x0A,extended
1344 *-F*************************************************************************/
1345 static int
1346 aic7xxx_setup(char *s)
1348 int i, n;
1349 char *p;
1350 char *end;
1352 static struct {
1353 const char *name;
1354 unsigned int *flag;
1355 } options[] = {
1356 { "extended", &aic7xxx_extended },
1357 { "no_reset", &aic7xxx_no_reset },
1358 { "irq_trigger", &aic7xxx_irq_trigger },
1359 { "verbose", &aic7xxx_verbose },
1360 { "reverse_scan",&aic7xxx_reverse_scan },
1361 { "override_term", &aic7xxx_override_term },
1362 { "stpwlev", &aic7xxx_stpwlev },
1363 { "no_probe", &aic7xxx_no_probe },
1364 { "panic_on_abort", &aic7xxx_panic_on_abort },
1365 { "pci_parity", &aic7xxx_pci_parity },
1366 { "dump_card", &aic7xxx_dump_card },
1367 { "dump_sequencer", &aic7xxx_dump_sequencer },
1368 { "default_queue_depth", &aic7xxx_default_queue_depth },
1369 { "scbram", &aic7xxx_scbram },
1370 { "seltime", &aic7xxx_seltime },
1371 { "tag_info", NULL }
1374 end = strchr(s, '\0');
1376 while ((p = strsep(&s, ",.")) != NULL)
1378 for (i = 0; i < NUMBER(options); i++)
1380 n = strlen(options[i].name);
1381 if (!strncmp(options[i].name, p, n))
1383 if (!strncmp(p, "tag_info", n))
1385 if (p[n] == ':')
1387 char *base;
1388 char *tok, *tok_end, *tok_end2;
1389 char tok_list[] = { '.', ',', '{', '}', '\0' };
1390 int i, instance = -1, device = -1;
1391 unsigned char done = FALSE;
1393 base = p;
1394 tok = base + n + 1; /* Forward us just past the ':' */
1395 tok_end = strchr(tok, '\0');
1396 if (tok_end < end)
1397 *tok_end = ',';
1398 while(!done)
1400 switch(*tok)
1402 case '{':
1403 if (instance == -1)
1404 instance = 0;
1405 else if (device == -1)
1406 device = 0;
1407 tok++;
1408 break;
1409 case '}':
1410 if (device != -1)
1411 device = -1;
1412 else if (instance != -1)
1413 instance = -1;
1414 tok++;
1415 break;
1416 case ',':
1417 case '.':
1418 if (instance == -1)
1419 done = TRUE;
1420 else if (device >= 0)
1421 device++;
1422 else if (instance >= 0)
1423 instance++;
1424 if ( (device >= MAX_TARGETS) ||
1425 (instance >= NUMBER(aic7xxx_tag_info)) )
1426 done = TRUE;
1427 tok++;
1428 if (!done)
1430 base = tok;
1432 break;
1433 case '\0':
1434 done = TRUE;
1435 break;
1436 default:
1437 done = TRUE;
1438 tok_end = strchr(tok, '\0');
1439 for(i=0; tok_list[i]; i++)
1441 tok_end2 = strchr(tok, tok_list[i]);
1442 if ( (tok_end2) && (tok_end2 < tok_end) )
1444 tok_end = tok_end2;
1445 done = FALSE;
1448 if ( (instance >= 0) && (device >= 0) &&
1449 (instance < NUMBER(aic7xxx_tag_info)) &&
1450 (device < MAX_TARGETS) )
1451 aic7xxx_tag_info[instance].tag_commands[device] =
1452 simple_strtoul(tok, NULL, 0) & 0xff;
1453 tok = tok_end;
1454 break;
1457 while((p != base) && (p != NULL))
1458 p = strsep(&s, ",.");
1461 else if (p[n] == ':')
1463 *(options[i].flag) = simple_strtoul(p + n + 1, NULL, 0);
1464 if(!strncmp(p, "seltime", n))
1466 *(options[i].flag) = (*(options[i].flag) % 4) << 3;
1469 else if (!strncmp(p, "verbose", n))
1471 *(options[i].flag) = 0xff29;
1473 else
1475 *(options[i].flag) = ~(*(options[i].flag));
1476 if(!strncmp(p, "seltime", n))
1478 *(options[i].flag) = (*(options[i].flag) % 4) << 3;
1484 return 1;
1487 __setup("aic7xxx=", aic7xxx_setup);
1489 /*+F*************************************************************************
1490 * Function:
1491 * pause_sequencer
1493 * Description:
1494 * Pause the sequencer and wait for it to actually stop - this
1495 * is important since the sequencer can disable pausing for critical
1496 * sections.
1497 *-F*************************************************************************/
1498 static void
1499 pause_sequencer(struct aic7xxx_host *p)
1501 aic_outb(p, p->pause, HCNTRL);
1502 while ((aic_inb(p, HCNTRL) & PAUSE) == 0)
1506 if(p->features & AHC_ULTRA2)
1508 aic_inb(p, CCSCBCTL);
1512 /*+F*************************************************************************
1513 * Function:
1514 * unpause_sequencer
1516 * Description:
1517 * Unpause the sequencer. Unremarkable, yet done often enough to
1518 * warrant an easy way to do it.
1519 *-F*************************************************************************/
1520 static void
1521 unpause_sequencer(struct aic7xxx_host *p, int unpause_always)
1523 if (unpause_always ||
1524 ( !(aic_inb(p, INTSTAT) & (SCSIINT | SEQINT | BRKADRINT)) &&
1525 !(p->flags & AHC_HANDLING_REQINITS) ) )
1527 aic_outb(p, p->unpause, HCNTRL);
1531 /*+F*************************************************************************
1532 * Function:
1533 * restart_sequencer
1535 * Description:
1536 * Restart the sequencer program from address zero. This assumes
1537 * that the sequencer is already paused.
1538 *-F*************************************************************************/
1539 static void
1540 restart_sequencer(struct aic7xxx_host *p)
1542 aic_outb(p, 0, SEQADDR0);
1543 aic_outb(p, 0, SEQADDR1);
1544 aic_outb(p, FASTMODE, SEQCTL);
1548 * We include the aic7xxx_seq.c file here so that the other defines have
1549 * already been made, and so that it comes before the code that actually
1550 * downloads the instructions (since we don't typically use function
1551 * prototype, our code has to be ordered that way, it's a left-over from
1552 * the original driver days.....I should fix it some time DL).
1554 #include "aic7xxx_old/aic7xxx_seq.c"
1556 /*+F*************************************************************************
1557 * Function:
1558 * aic7xxx_check_patch
1560 * Description:
1561 * See if the next patch to download should be downloaded.
1562 *-F*************************************************************************/
1563 static int
1564 aic7xxx_check_patch(struct aic7xxx_host *p,
1565 struct sequencer_patch **start_patch, int start_instr, int *skip_addr)
1567 struct sequencer_patch *cur_patch;
1568 struct sequencer_patch *last_patch;
1569 int num_patches;
1571 num_patches = sizeof(sequencer_patches)/sizeof(struct sequencer_patch);
1572 last_patch = &sequencer_patches[num_patches];
1573 cur_patch = *start_patch;
1575 while ((cur_patch < last_patch) && (start_instr == cur_patch->begin))
1577 if (cur_patch->patch_func(p) == 0)
1580 * Start rejecting code.
1582 *skip_addr = start_instr + cur_patch->skip_instr;
1583 cur_patch += cur_patch->skip_patch;
1585 else
1588 * Found an OK patch. Advance the patch pointer to the next patch
1589 * and wait for our instruction pointer to get here.
1591 cur_patch++;
1595 *start_patch = cur_patch;
1596 if (start_instr < *skip_addr)
1598 * Still skipping
1600 return (0);
1601 return(1);
1605 /*+F*************************************************************************
1606 * Function:
1607 * aic7xxx_download_instr
1609 * Description:
1610 * Find the next patch to download.
1611 *-F*************************************************************************/
1612 static void
1613 aic7xxx_download_instr(struct aic7xxx_host *p, int instrptr,
1614 unsigned char *dconsts)
1616 union ins_formats instr;
1617 struct ins_format1 *fmt1_ins;
1618 struct ins_format3 *fmt3_ins;
1619 unsigned char opcode;
1621 instr = *(union ins_formats*) &seqprog[instrptr * 4];
1623 instr.integer = le32_to_cpu(instr.integer);
1625 fmt1_ins = &instr.format1;
1626 fmt3_ins = NULL;
1628 /* Pull the opcode */
1629 opcode = instr.format1.opcode;
1630 switch (opcode)
1632 case AIC_OP_JMP:
1633 case AIC_OP_JC:
1634 case AIC_OP_JNC:
1635 case AIC_OP_CALL:
1636 case AIC_OP_JNE:
1637 case AIC_OP_JNZ:
1638 case AIC_OP_JE:
1639 case AIC_OP_JZ:
1641 struct sequencer_patch *cur_patch;
1642 int address_offset;
1643 unsigned int address;
1644 int skip_addr;
1645 int i;
1647 fmt3_ins = &instr.format3;
1648 address_offset = 0;
1649 address = fmt3_ins->address;
1650 cur_patch = sequencer_patches;
1651 skip_addr = 0;
1653 for (i = 0; i < address;)
1655 aic7xxx_check_patch(p, &cur_patch, i, &skip_addr);
1656 if (skip_addr > i)
1658 int end_addr;
1660 end_addr = MIN(address, skip_addr);
1661 address_offset += end_addr - i;
1662 i = skip_addr;
1664 else
1666 i++;
1669 address -= address_offset;
1670 fmt3_ins->address = address;
1671 /* Fall Through to the next code section */
1673 case AIC_OP_OR:
1674 case AIC_OP_AND:
1675 case AIC_OP_XOR:
1676 case AIC_OP_ADD:
1677 case AIC_OP_ADC:
1678 case AIC_OP_BMOV:
1679 if (fmt1_ins->parity != 0)
1681 fmt1_ins->immediate = dconsts[fmt1_ins->immediate];
1683 fmt1_ins->parity = 0;
1684 /* Fall Through to the next code section */
1685 case AIC_OP_ROL:
1686 if ((p->features & AHC_ULTRA2) != 0)
1688 int i, count;
1690 /* Calculate odd parity for the instruction */
1691 for ( i=0, count=0; i < 31; i++)
1693 unsigned int mask;
1695 mask = 0x01 << i;
1696 if ((instr.integer & mask) != 0)
1697 count++;
1699 if (!(count & 0x01))
1700 instr.format1.parity = 1;
1702 else
1704 if (fmt3_ins != NULL)
1706 instr.integer = fmt3_ins->immediate |
1707 (fmt3_ins->source << 8) |
1708 (fmt3_ins->address << 16) |
1709 (fmt3_ins->opcode << 25);
1711 else
1713 instr.integer = fmt1_ins->immediate |
1714 (fmt1_ins->source << 8) |
1715 (fmt1_ins->destination << 16) |
1716 (fmt1_ins->ret << 24) |
1717 (fmt1_ins->opcode << 25);
1720 aic_outb(p, (instr.integer & 0xff), SEQRAM);
1721 aic_outb(p, ((instr.integer >> 8) & 0xff), SEQRAM);
1722 aic_outb(p, ((instr.integer >> 16) & 0xff), SEQRAM);
1723 aic_outb(p, ((instr.integer >> 24) & 0xff), SEQRAM);
1724 udelay(10);
1725 break;
1727 default:
1728 panic("aic7xxx: Unknown opcode encountered in sequencer program.");
1729 break;
1734 /*+F*************************************************************************
1735 * Function:
1736 * aic7xxx_loadseq
1738 * Description:
1739 * Load the sequencer code into the controller memory.
1740 *-F*************************************************************************/
1741 static void
1742 aic7xxx_loadseq(struct aic7xxx_host *p)
1744 struct sequencer_patch *cur_patch;
1745 int i;
1746 int downloaded;
1747 int skip_addr;
1748 unsigned char download_consts[4] = {0, 0, 0, 0};
1750 if (aic7xxx_verbose & VERBOSE_PROBE)
1752 printk(KERN_INFO "(scsi%d) Downloading sequencer code...", p->host_no);
1754 #if 0
1755 download_consts[TMODE_NUMCMDS] = p->num_targetcmds;
1756 #endif
1757 download_consts[TMODE_NUMCMDS] = 0;
1758 cur_patch = &sequencer_patches[0];
1759 downloaded = 0;
1760 skip_addr = 0;
1762 aic_outb(p, PERRORDIS|LOADRAM|FAILDIS|FASTMODE, SEQCTL);
1763 aic_outb(p, 0, SEQADDR0);
1764 aic_outb(p, 0, SEQADDR1);
1766 for (i = 0; i < sizeof(seqprog) / 4; i++)
1768 if (aic7xxx_check_patch(p, &cur_patch, i, &skip_addr) == 0)
1770 /* Skip this instruction for this configuration. */
1771 continue;
1773 aic7xxx_download_instr(p, i, &download_consts[0]);
1774 downloaded++;
1777 aic_outb(p, 0, SEQADDR0);
1778 aic_outb(p, 0, SEQADDR1);
1779 aic_outb(p, FASTMODE | FAILDIS, SEQCTL);
1780 unpause_sequencer(p, TRUE);
1781 mdelay(1);
1782 pause_sequencer(p);
1783 aic_outb(p, FASTMODE, SEQCTL);
1784 if (aic7xxx_verbose & VERBOSE_PROBE)
1786 printk(" %d instructions downloaded\n", downloaded);
1788 if (aic7xxx_dump_sequencer)
1789 aic7xxx_print_sequencer(p, downloaded);
1792 /*+F*************************************************************************
1793 * Function:
1794 * aic7xxx_print_sequencer
1796 * Description:
1797 * Print the contents of the sequencer memory to the screen.
1798 *-F*************************************************************************/
1799 static void
1800 aic7xxx_print_sequencer(struct aic7xxx_host *p, int downloaded)
1802 int i, k, temp;
1804 aic_outb(p, PERRORDIS|LOADRAM|FAILDIS|FASTMODE, SEQCTL);
1805 aic_outb(p, 0, SEQADDR0);
1806 aic_outb(p, 0, SEQADDR1);
1808 k = 0;
1809 for (i=0; i < downloaded; i++)
1811 if ( k == 0 )
1812 printk("%03x: ", i);
1813 temp = aic_inb(p, SEQRAM);
1814 temp |= (aic_inb(p, SEQRAM) << 8);
1815 temp |= (aic_inb(p, SEQRAM) << 16);
1816 temp |= (aic_inb(p, SEQRAM) << 24);
1817 printk("%08x", temp);
1818 if ( ++k == 8 )
1820 printk("\n");
1821 k = 0;
1823 else
1824 printk(" ");
1826 aic_outb(p, 0, SEQADDR0);
1827 aic_outb(p, 0, SEQADDR1);
1828 aic_outb(p, FASTMODE | FAILDIS, SEQCTL);
1829 unpause_sequencer(p, TRUE);
1830 mdelay(1);
1831 pause_sequencer(p);
1832 aic_outb(p, FASTMODE, SEQCTL);
1833 printk("\n");
1836 /*+F*************************************************************************
1837 * Function:
1838 * aic7xxx_info
1840 * Description:
1841 * Return a string describing the driver.
1842 *-F*************************************************************************/
1843 const char *
1844 aic7xxx_info(struct Scsi_Host *dooh)
1846 static char buffer[256];
1847 char *bp;
1848 struct aic7xxx_host *p;
1850 bp = &buffer[0];
1851 p = (struct aic7xxx_host *)dooh->hostdata;
1852 memset(bp, 0, sizeof(buffer));
1853 strcpy(bp, "Adaptec AHA274x/284x/294x (EISA/VLB/PCI-Fast SCSI) ");
1854 strcat(bp, AIC7XXX_C_VERSION);
1855 strcat(bp, "/");
1856 strcat(bp, AIC7XXX_H_VERSION);
1857 strcat(bp, "\n");
1858 strcat(bp, " <");
1859 strcat(bp, board_names[p->board_name_index]);
1860 strcat(bp, ">");
1862 return(bp);
1865 /*+F*************************************************************************
1866 * Function:
1867 * aic7xxx_find_syncrate
1869 * Description:
1870 * Look up the valid period to SCSIRATE conversion in our table
1871 *-F*************************************************************************/
1872 static struct aic7xxx_syncrate *
1873 aic7xxx_find_syncrate(struct aic7xxx_host *p, unsigned int *period,
1874 unsigned int maxsync, unsigned char *options)
1876 struct aic7xxx_syncrate *syncrate;
1877 int done = FALSE;
1879 switch(*options)
1881 case MSG_EXT_PPR_OPTION_DT_CRC:
1882 case MSG_EXT_PPR_OPTION_DT_UNITS:
1883 if(!(p->features & AHC_ULTRA3))
1885 *options = 0;
1886 maxsync = MAX(maxsync, AHC_SYNCRATE_ULTRA2);
1888 break;
1889 case MSG_EXT_PPR_OPTION_DT_CRC_QUICK:
1890 case MSG_EXT_PPR_OPTION_DT_UNITS_QUICK:
1891 if(!(p->features & AHC_ULTRA3))
1893 *options = 0;
1894 maxsync = MAX(maxsync, AHC_SYNCRATE_ULTRA2);
1896 else
1899 * we don't support the Quick Arbitration variants of dual edge
1900 * clocking. As it turns out, we want to send back the
1901 * same basic option, but without the QA attribute.
1902 * We know that we are responding because we would never set
1903 * these options ourself, we would only respond to them.
1905 switch(*options)
1907 case MSG_EXT_PPR_OPTION_DT_CRC_QUICK:
1908 *options = MSG_EXT_PPR_OPTION_DT_CRC;
1909 break;
1910 case MSG_EXT_PPR_OPTION_DT_UNITS_QUICK:
1911 *options = MSG_EXT_PPR_OPTION_DT_UNITS;
1912 break;
1915 break;
1916 default:
1917 *options = 0;
1918 maxsync = MAX(maxsync, AHC_SYNCRATE_ULTRA2);
1919 break;
1921 syncrate = &aic7xxx_syncrates[maxsync];
1922 while ( (syncrate->rate[0] != NULL) &&
1923 (!(p->features & AHC_ULTRA2) || syncrate->sxfr_ultra2) )
1925 if (*period <= syncrate->period)
1927 switch(*options)
1929 case MSG_EXT_PPR_OPTION_DT_CRC:
1930 case MSG_EXT_PPR_OPTION_DT_UNITS:
1931 if(!(syncrate->sxfr_ultra2 & AHC_SYNCRATE_CRC))
1933 done = TRUE;
1935 * oops, we went too low for the CRC/DualEdge signalling, so
1936 * clear the options byte
1938 *options = 0;
1940 * We'll be sending a reply to this packet to set the options
1941 * properly, so unilaterally set the period as well.
1943 *period = syncrate->period;
1945 else
1947 done = TRUE;
1948 if(syncrate == &aic7xxx_syncrates[maxsync])
1950 *period = syncrate->period;
1953 break;
1954 default:
1955 if(!(syncrate->sxfr_ultra2 & AHC_SYNCRATE_CRC))
1957 done = TRUE;
1958 if(syncrate == &aic7xxx_syncrates[maxsync])
1960 *period = syncrate->period;
1963 break;
1965 if(done)
1967 break;
1970 syncrate++;
1972 if ( (*period == 0) || (syncrate->rate[0] == NULL) ||
1973 ((p->features & AHC_ULTRA2) && (syncrate->sxfr_ultra2 == 0)) )
1976 * Use async transfers for this target
1978 *options = 0;
1979 *period = 255;
1980 syncrate = NULL;
1982 return (syncrate);
1986 /*+F*************************************************************************
1987 * Function:
1988 * aic7xxx_find_period
1990 * Description:
1991 * Look up the valid SCSIRATE to period conversion in our table
1992 *-F*************************************************************************/
1993 static unsigned int
1994 aic7xxx_find_period(struct aic7xxx_host *p, unsigned int scsirate,
1995 unsigned int maxsync)
1997 struct aic7xxx_syncrate *syncrate;
1999 if (p->features & AHC_ULTRA2)
2001 scsirate &= SXFR_ULTRA2;
2003 else
2005 scsirate &= SXFR;
2008 syncrate = &aic7xxx_syncrates[maxsync];
2009 while (syncrate->rate[0] != NULL)
2011 if (p->features & AHC_ULTRA2)
2013 if (syncrate->sxfr_ultra2 == 0)
2014 break;
2015 else if (scsirate == syncrate->sxfr_ultra2)
2016 return (syncrate->period);
2017 else if (scsirate == (syncrate->sxfr_ultra2 & ~AHC_SYNCRATE_CRC))
2018 return (syncrate->period);
2020 else if (scsirate == (syncrate->sxfr & ~ULTRA_SXFR))
2022 return (syncrate->period);
2024 syncrate++;
2026 return (0); /* async */
2029 /*+F*************************************************************************
2030 * Function:
2031 * aic7xxx_validate_offset
2033 * Description:
2034 * Set a valid offset value for a particular card in use and transfer
2035 * settings in use.
2036 *-F*************************************************************************/
2037 static void
2038 aic7xxx_validate_offset(struct aic7xxx_host *p,
2039 struct aic7xxx_syncrate *syncrate, unsigned int *offset, int wide)
2041 unsigned int maxoffset;
2043 /* Limit offset to what the card (and device) can do */
2044 if (syncrate == NULL)
2046 maxoffset = 0;
2048 else if (p->features & AHC_ULTRA2)
2050 maxoffset = MAX_OFFSET_ULTRA2;
2052 else
2054 if (wide)
2055 maxoffset = MAX_OFFSET_16BIT;
2056 else
2057 maxoffset = MAX_OFFSET_8BIT;
2059 *offset = MIN(*offset, maxoffset);
2062 /*+F*************************************************************************
2063 * Function:
2064 * aic7xxx_set_syncrate
2066 * Description:
2067 * Set the actual syncrate down in the card and in our host structs
2068 *-F*************************************************************************/
2069 static void
2070 aic7xxx_set_syncrate(struct aic7xxx_host *p, struct aic7xxx_syncrate *syncrate,
2071 int target, int channel, unsigned int period, unsigned int offset,
2072 unsigned char options, unsigned int type, struct aic_dev_data *aic_dev)
2074 unsigned char tindex;
2075 unsigned short target_mask;
2076 unsigned char lun, old_options;
2077 unsigned int old_period, old_offset;
2079 tindex = target | (channel << 3);
2080 target_mask = 0x01 << tindex;
2081 lun = aic_inb(p, SCB_TCL) & 0x07;
2083 if (syncrate == NULL)
2085 period = 0;
2086 offset = 0;
2089 old_period = aic_dev->cur.period;
2090 old_offset = aic_dev->cur.offset;
2091 old_options = aic_dev->cur.options;
2094 if (type & AHC_TRANS_CUR)
2096 unsigned int scsirate;
2098 scsirate = aic_inb(p, TARG_SCSIRATE + tindex);
2099 if (p->features & AHC_ULTRA2)
2101 scsirate &= ~SXFR_ULTRA2;
2102 if (syncrate != NULL)
2104 switch(options)
2106 case MSG_EXT_PPR_OPTION_DT_UNITS:
2108 * mask off the CRC bit in the xfer settings
2110 scsirate |= (syncrate->sxfr_ultra2 & ~AHC_SYNCRATE_CRC);
2111 break;
2112 default:
2113 scsirate |= syncrate->sxfr_ultra2;
2114 break;
2117 if (type & AHC_TRANS_ACTIVE)
2119 aic_outb(p, offset, SCSIOFFSET);
2121 aic_outb(p, offset, TARG_OFFSET + tindex);
2123 else /* Not an Ultra2 controller */
2125 scsirate &= ~(SXFR|SOFS);
2126 p->ultraenb &= ~target_mask;
2127 if (syncrate != NULL)
2129 if (syncrate->sxfr & ULTRA_SXFR)
2131 p->ultraenb |= target_mask;
2133 scsirate |= (syncrate->sxfr & SXFR);
2134 scsirate |= (offset & SOFS);
2136 if (type & AHC_TRANS_ACTIVE)
2138 unsigned char sxfrctl0;
2140 sxfrctl0 = aic_inb(p, SXFRCTL0);
2141 sxfrctl0 &= ~FAST20;
2142 if (p->ultraenb & target_mask)
2143 sxfrctl0 |= FAST20;
2144 aic_outb(p, sxfrctl0, SXFRCTL0);
2146 aic_outb(p, p->ultraenb & 0xff, ULTRA_ENB);
2147 aic_outb(p, (p->ultraenb >> 8) & 0xff, ULTRA_ENB + 1 );
2149 if (type & AHC_TRANS_ACTIVE)
2151 aic_outb(p, scsirate, SCSIRATE);
2153 aic_outb(p, scsirate, TARG_SCSIRATE + tindex);
2154 aic_dev->cur.period = period;
2155 aic_dev->cur.offset = offset;
2156 aic_dev->cur.options = options;
2157 if ( !(type & AHC_TRANS_QUITE) &&
2158 (aic7xxx_verbose & VERBOSE_NEGOTIATION) &&
2159 (aic_dev->flags & DEVICE_PRINT_DTR) )
2161 if (offset)
2163 int rate_mod = (scsirate & WIDEXFER) ? 1 : 0;
2165 printk(INFO_LEAD "Synchronous at %s Mbyte/sec, "
2166 "offset %d.\n", p->host_no, channel, target, lun,
2167 syncrate->rate[rate_mod], offset);
2169 else
2171 printk(INFO_LEAD "Using asynchronous transfers.\n",
2172 p->host_no, channel, target, lun);
2174 aic_dev->flags &= ~DEVICE_PRINT_DTR;
2178 if (type & AHC_TRANS_GOAL)
2180 aic_dev->goal.period = period;
2181 aic_dev->goal.offset = offset;
2182 aic_dev->goal.options = options;
2185 if (type & AHC_TRANS_USER)
2187 p->user[tindex].period = period;
2188 p->user[tindex].offset = offset;
2189 p->user[tindex].options = options;
2193 /*+F*************************************************************************
2194 * Function:
2195 * aic7xxx_set_width
2197 * Description:
2198 * Set the actual width down in the card and in our host structs
2199 *-F*************************************************************************/
2200 static void
2201 aic7xxx_set_width(struct aic7xxx_host *p, int target, int channel, int lun,
2202 unsigned int width, unsigned int type, struct aic_dev_data *aic_dev)
2204 unsigned char tindex;
2205 unsigned short target_mask;
2206 unsigned int old_width;
2208 tindex = target | (channel << 3);
2209 target_mask = 1 << tindex;
2211 old_width = aic_dev->cur.width;
2213 if (type & AHC_TRANS_CUR)
2215 unsigned char scsirate;
2217 scsirate = aic_inb(p, TARG_SCSIRATE + tindex);
2219 scsirate &= ~WIDEXFER;
2220 if (width == MSG_EXT_WDTR_BUS_16_BIT)
2221 scsirate |= WIDEXFER;
2223 aic_outb(p, scsirate, TARG_SCSIRATE + tindex);
2225 if (type & AHC_TRANS_ACTIVE)
2226 aic_outb(p, scsirate, SCSIRATE);
2228 aic_dev->cur.width = width;
2230 if ( !(type & AHC_TRANS_QUITE) &&
2231 (aic7xxx_verbose & VERBOSE_NEGOTIATION2) &&
2232 (aic_dev->flags & DEVICE_PRINT_DTR) )
2234 printk(INFO_LEAD "Using %s transfers\n", p->host_no, channel, target,
2235 lun, (scsirate & WIDEXFER) ? "Wide(16bit)" : "Narrow(8bit)" );
2239 if (type & AHC_TRANS_GOAL)
2240 aic_dev->goal.width = width;
2241 if (type & AHC_TRANS_USER)
2242 p->user[tindex].width = width;
2244 if (aic_dev->goal.offset)
2246 if (p->features & AHC_ULTRA2)
2248 aic_dev->goal.offset = MAX_OFFSET_ULTRA2;
2250 else if (width == MSG_EXT_WDTR_BUS_16_BIT)
2252 aic_dev->goal.offset = MAX_OFFSET_16BIT;
2254 else
2256 aic_dev->goal.offset = MAX_OFFSET_8BIT;
2261 /*+F*************************************************************************
2262 * Function:
2263 * scbq_init
2265 * Description:
2266 * SCB queue initialization.
2268 *-F*************************************************************************/
2269 static void
2270 scbq_init(volatile scb_queue_type *queue)
2272 queue->head = NULL;
2273 queue->tail = NULL;
2276 /*+F*************************************************************************
2277 * Function:
2278 * scbq_insert_head
2280 * Description:
2281 * Add an SCB to the head of the list.
2283 *-F*************************************************************************/
2284 static inline void
2285 scbq_insert_head(volatile scb_queue_type *queue, struct aic7xxx_scb *scb)
2287 scb->q_next = queue->head;
2288 queue->head = scb;
2289 if (queue->tail == NULL) /* If list was empty, update tail. */
2290 queue->tail = queue->head;
2293 /*+F*************************************************************************
2294 * Function:
2295 * scbq_remove_head
2297 * Description:
2298 * Remove an SCB from the head of the list.
2300 *-F*************************************************************************/
2301 static inline struct aic7xxx_scb *
2302 scbq_remove_head(volatile scb_queue_type *queue)
2304 struct aic7xxx_scb * scbp;
2306 scbp = queue->head;
2307 if (queue->head != NULL)
2308 queue->head = queue->head->q_next;
2309 if (queue->head == NULL) /* If list is now empty, update tail. */
2310 queue->tail = NULL;
2311 return(scbp);
2314 /*+F*************************************************************************
2315 * Function:
2316 * scbq_remove
2318 * Description:
2319 * Removes an SCB from the list.
2321 *-F*************************************************************************/
2322 static inline void
2323 scbq_remove(volatile scb_queue_type *queue, struct aic7xxx_scb *scb)
2325 if (queue->head == scb)
2327 /* At beginning of queue, remove from head. */
2328 scbq_remove_head(queue);
2330 else
2332 struct aic7xxx_scb *curscb = queue->head;
2335 * Search until the next scb is the one we're looking for, or
2336 * we run out of queue.
2338 while ((curscb != NULL) && (curscb->q_next != scb))
2340 curscb = curscb->q_next;
2342 if (curscb != NULL)
2344 /* Found it. */
2345 curscb->q_next = scb->q_next;
2346 if (scb->q_next == NULL)
2348 /* Update the tail when removing the tail. */
2349 queue->tail = curscb;
2355 /*+F*************************************************************************
2356 * Function:
2357 * scbq_insert_tail
2359 * Description:
2360 * Add an SCB at the tail of the list.
2362 *-F*************************************************************************/
2363 static inline void
2364 scbq_insert_tail(volatile scb_queue_type *queue, struct aic7xxx_scb *scb)
2366 scb->q_next = NULL;
2367 if (queue->tail != NULL) /* Add the scb at the end of the list. */
2368 queue->tail->q_next = scb;
2369 queue->tail = scb; /* Update the tail. */
2370 if (queue->head == NULL) /* If list was empty, update head. */
2371 queue->head = queue->tail;
2374 /*+F*************************************************************************
2375 * Function:
2376 * aic7xxx_match_scb
2378 * Description:
2379 * Checks to see if an scb matches the target/channel as specified.
2380 * If target is ALL_TARGETS (-1), then we're looking for any device
2381 * on the specified channel; this happens when a channel is going
2382 * to be reset and all devices on that channel must be aborted.
2383 *-F*************************************************************************/
2384 static int
2385 aic7xxx_match_scb(struct aic7xxx_host *p, struct aic7xxx_scb *scb,
2386 int target, int channel, int lun, unsigned char tag)
2388 int targ = (scb->hscb->target_channel_lun >> 4) & 0x0F;
2389 int chan = (scb->hscb->target_channel_lun >> 3) & 0x01;
2390 int slun = scb->hscb->target_channel_lun & 0x07;
2391 int match;
2393 match = ((chan == channel) || (channel == ALL_CHANNELS));
2394 if (match != 0)
2395 match = ((targ == target) || (target == ALL_TARGETS));
2396 if (match != 0)
2397 match = ((lun == slun) || (lun == ALL_LUNS));
2398 if (match != 0)
2399 match = ((tag == scb->hscb->tag) || (tag == SCB_LIST_NULL));
2401 return (match);
2404 /*+F*************************************************************************
2405 * Function:
2406 * aic7xxx_add_curscb_to_free_list
2408 * Description:
2409 * Adds the current scb (in SCBPTR) to the list of free SCBs.
2410 *-F*************************************************************************/
2411 static void
2412 aic7xxx_add_curscb_to_free_list(struct aic7xxx_host *p)
2415 * Invalidate the tag so that aic7xxx_find_scb doesn't think
2416 * it's active
2418 aic_outb(p, SCB_LIST_NULL, SCB_TAG);
2419 aic_outb(p, 0, SCB_CONTROL);
2421 aic_outb(p, aic_inb(p, FREE_SCBH), SCB_NEXT);
2422 aic_outb(p, aic_inb(p, SCBPTR), FREE_SCBH);
2425 /*+F*************************************************************************
2426 * Function:
2427 * aic7xxx_rem_scb_from_disc_list
2429 * Description:
2430 * Removes the current SCB from the disconnected list and adds it
2431 * to the free list.
2432 *-F*************************************************************************/
2433 static unsigned char
2434 aic7xxx_rem_scb_from_disc_list(struct aic7xxx_host *p, unsigned char scbptr,
2435 unsigned char prev)
2437 unsigned char next;
2439 aic_outb(p, scbptr, SCBPTR);
2440 next = aic_inb(p, SCB_NEXT);
2441 aic7xxx_add_curscb_to_free_list(p);
2443 if (prev != SCB_LIST_NULL)
2445 aic_outb(p, prev, SCBPTR);
2446 aic_outb(p, next, SCB_NEXT);
2448 else
2450 aic_outb(p, next, DISCONNECTED_SCBH);
2453 return next;
2456 /*+F*************************************************************************
2457 * Function:
2458 * aic7xxx_busy_target
2460 * Description:
2461 * Set the specified target busy.
2462 *-F*************************************************************************/
2463 static inline void
2464 aic7xxx_busy_target(struct aic7xxx_host *p, struct aic7xxx_scb *scb)
2466 p->untagged_scbs[scb->hscb->target_channel_lun] = scb->hscb->tag;
2469 /*+F*************************************************************************
2470 * Function:
2471 * aic7xxx_index_busy_target
2473 * Description:
2474 * Returns the index of the busy target, and optionally sets the
2475 * target inactive.
2476 *-F*************************************************************************/
2477 static inline unsigned char
2478 aic7xxx_index_busy_target(struct aic7xxx_host *p, unsigned char tcl,
2479 int unbusy)
2481 unsigned char busy_scbid;
2483 busy_scbid = p->untagged_scbs[tcl];
2484 if (unbusy)
2486 p->untagged_scbs[tcl] = SCB_LIST_NULL;
2488 return (busy_scbid);
2491 /*+F*************************************************************************
2492 * Function:
2493 * aic7xxx_find_scb
2495 * Description:
2496 * Look through the SCB array of the card and attempt to find the
2497 * hardware SCB that corresponds to the passed in SCB. Return
2498 * SCB_LIST_NULL if unsuccessful. This routine assumes that the
2499 * card is already paused.
2500 *-F*************************************************************************/
2501 static unsigned char
2502 aic7xxx_find_scb(struct aic7xxx_host *p, struct aic7xxx_scb *scb)
2504 unsigned char saved_scbptr;
2505 unsigned char curindex;
2507 saved_scbptr = aic_inb(p, SCBPTR);
2508 curindex = 0;
2509 for (curindex = 0; curindex < p->scb_data->maxhscbs; curindex++)
2511 aic_outb(p, curindex, SCBPTR);
2512 if (aic_inb(p, SCB_TAG) == scb->hscb->tag)
2514 break;
2517 aic_outb(p, saved_scbptr, SCBPTR);
2518 if (curindex >= p->scb_data->maxhscbs)
2520 curindex = SCB_LIST_NULL;
2523 return (curindex);
2526 /*+F*************************************************************************
2527 * Function:
2528 * aic7xxx_allocate_scb
2530 * Description:
2531 * Get an SCB from the free list or by allocating a new one.
2532 *-F*************************************************************************/
2533 static int
2534 aic7xxx_allocate_scb(struct aic7xxx_host *p)
2536 struct aic7xxx_scb *scbp = NULL;
2537 int scb_size = (sizeof (struct hw_scatterlist) * AIC7XXX_MAX_SG) + 12 + 6;
2538 int i;
2539 int step = PAGE_SIZE / 1024;
2540 unsigned long scb_count = 0;
2541 struct hw_scatterlist *hsgp;
2542 struct aic7xxx_scb *scb_ap;
2543 struct aic7xxx_scb_dma *scb_dma;
2544 unsigned char *bufs;
2546 if (p->scb_data->numscbs < p->scb_data->maxscbs)
2549 * Calculate the optimal number of SCBs to allocate.
2551 * NOTE: This formula works because the sizeof(sg_array) is always
2552 * 1024. Therefore, scb_size * i would always be > PAGE_SIZE *
2553 * (i/step). The (i-1) allows the left hand side of the equation
2554 * to grow into the right hand side to a point of near perfect
2555 * efficiency since scb_size * (i -1) is growing slightly faster
2556 * than the right hand side. If the number of SG array elements
2557 * is changed, this function may not be near so efficient any more.
2559 * Since the DMA'able buffers are now allocated in a seperate
2560 * chunk this algorithm has been modified to match. The '12'
2561 * and '6' factors in scb_size are for the DMA'able command byte
2562 * and sensebuffers respectively. -DaveM
2564 for ( i=step;; i *= 2 )
2566 if ( (scb_size * (i-1)) >= ( (PAGE_SIZE * (i/step)) - 64 ) )
2568 i /= 2;
2569 break;
2572 scb_count = MIN( (i-1), p->scb_data->maxscbs - p->scb_data->numscbs);
2573 scb_ap = (struct aic7xxx_scb *)kmalloc(sizeof (struct aic7xxx_scb) * scb_count
2574 + sizeof(struct aic7xxx_scb_dma), GFP_ATOMIC);
2575 if (scb_ap == NULL)
2576 return(0);
2577 scb_dma = (struct aic7xxx_scb_dma *)&scb_ap[scb_count];
2578 hsgp = (struct hw_scatterlist *)
2579 pci_alloc_consistent(p->pdev, scb_size * scb_count,
2580 &scb_dma->dma_address);
2581 if (hsgp == NULL)
2583 kfree(scb_ap);
2584 return(0);
2586 bufs = (unsigned char *)&hsgp[scb_count * AIC7XXX_MAX_SG];
2587 #ifdef AIC7XXX_VERBOSE_DEBUGGING
2588 if (aic7xxx_verbose > 0xffff)
2590 if (p->scb_data->numscbs == 0)
2591 printk(INFO_LEAD "Allocating initial %ld SCB structures.\n",
2592 p->host_no, -1, -1, -1, scb_count);
2593 else
2594 printk(INFO_LEAD "Allocating %ld additional SCB structures.\n",
2595 p->host_no, -1, -1, -1, scb_count);
2597 #endif
2598 memset(scb_ap, 0, sizeof (struct aic7xxx_scb) * scb_count);
2599 scb_dma->dma_offset = (unsigned long)scb_dma->dma_address
2600 - (unsigned long)hsgp;
2601 scb_dma->dma_len = scb_size * scb_count;
2602 for (i=0; i < scb_count; i++)
2604 scbp = &scb_ap[i];
2605 scbp->hscb = &p->scb_data->hscbs[p->scb_data->numscbs];
2606 scbp->sg_list = &hsgp[i * AIC7XXX_MAX_SG];
2607 scbp->sense_cmd = bufs;
2608 scbp->cmnd = bufs + 6;
2609 bufs += 12 + 6;
2610 scbp->scb_dma = scb_dma;
2611 memset(scbp->hscb, 0, sizeof(struct aic7xxx_hwscb));
2612 scbp->hscb->tag = p->scb_data->numscbs;
2614 * Place in the scb array; never is removed
2616 p->scb_data->scb_array[p->scb_data->numscbs++] = scbp;
2617 scbq_insert_tail(&p->scb_data->free_scbs, scbp);
2619 scbp->kmalloc_ptr = scb_ap;
2621 return(scb_count);
2624 /*+F*************************************************************************
2625 * Function:
2626 * aic7xxx_queue_cmd_complete
2628 * Description:
2629 * Due to race conditions present in the SCSI subsystem, it is easier
2630 * to queue completed commands, then call scsi_done() on them when
2631 * we're finished. This function queues the completed commands.
2632 *-F*************************************************************************/
2633 static void
2634 aic7xxx_queue_cmd_complete(struct aic7xxx_host *p, Scsi_Cmnd *cmd)
2636 aic7xxx_position(cmd) = SCB_LIST_NULL;
2637 cmd->host_scribble = (char *)p->completeq.head;
2638 p->completeq.head = cmd;
2641 /*+F*************************************************************************
2642 * Function:
2643 * aic7xxx_done_cmds_complete
2645 * Description:
2646 * Process the completed command queue.
2647 *-F*************************************************************************/
2648 static void
2649 aic7xxx_done_cmds_complete(struct aic7xxx_host *p)
2651 Scsi_Cmnd *cmd;
2653 while (p->completeq.head != NULL)
2655 cmd = p->completeq.head;
2656 p->completeq.head = (Scsi_Cmnd *)cmd->host_scribble;
2657 cmd->host_scribble = NULL;
2658 cmd->scsi_done(cmd);
2662 /*+F*************************************************************************
2663 * Function:
2664 * aic7xxx_free_scb
2666 * Description:
2667 * Free the scb and insert into the free scb list.
2668 *-F*************************************************************************/
2669 static void
2670 aic7xxx_free_scb(struct aic7xxx_host *p, struct aic7xxx_scb *scb)
2673 scb->flags = SCB_FREE;
2674 scb->cmd = NULL;
2675 scb->sg_count = 0;
2676 scb->sg_length = 0;
2677 scb->tag_action = 0;
2678 scb->hscb->control = 0;
2679 scb->hscb->target_status = 0;
2680 scb->hscb->target_channel_lun = SCB_LIST_NULL;
2682 scbq_insert_head(&p->scb_data->free_scbs, scb);
2685 /*+F*************************************************************************
2686 * Function:
2687 * aic7xxx_done
2689 * Description:
2690 * Calls the higher level scsi done function and frees the scb.
2691 *-F*************************************************************************/
2692 static void
2693 aic7xxx_done(struct aic7xxx_host *p, struct aic7xxx_scb *scb)
2695 Scsi_Cmnd *cmd = scb->cmd;
2696 struct aic_dev_data *aic_dev = cmd->device->hostdata;
2697 int tindex = TARGET_INDEX(cmd);
2698 struct aic7xxx_scb *scbp;
2699 unsigned char queue_depth;
2701 if (cmd->use_sg > 1)
2703 struct scatterlist *sg;
2705 sg = (struct scatterlist *)cmd->request_buffer;
2706 pci_unmap_sg(p->pdev, sg, cmd->use_sg, scsi_to_pci_dma_dir(cmd->sc_data_direction));
2708 else if (cmd->request_bufflen)
2709 pci_unmap_single(p->pdev, aic7xxx_mapping(cmd),
2710 cmd->request_bufflen,
2711 scsi_to_pci_dma_dir(cmd->sc_data_direction));
2712 if (scb->flags & SCB_SENSE)
2714 pci_unmap_single(p->pdev,
2715 le32_to_cpu(scb->sg_list[0].address),
2716 sizeof(cmd->sense_buffer),
2717 PCI_DMA_FROMDEVICE);
2719 if (scb->flags & SCB_RECOVERY_SCB)
2721 p->flags &= ~AHC_ABORT_PENDING;
2723 if (scb->flags & (SCB_RESET|SCB_ABORT))
2725 cmd->result |= (DID_RESET << 16);
2728 if ((scb->flags & SCB_MSGOUT_BITS) != 0)
2730 unsigned short mask;
2731 int message_error = FALSE;
2733 mask = 0x01 << tindex;
2736 * Check to see if we get an invalid message or a message error
2737 * after failing to negotiate a wide or sync transfer message.
2739 if ((scb->flags & SCB_SENSE) &&
2740 ((scb->cmd->sense_buffer[12] == 0x43) || /* INVALID_MESSAGE */
2741 (scb->cmd->sense_buffer[12] == 0x49))) /* MESSAGE_ERROR */
2743 message_error = TRUE;
2746 if (scb->flags & SCB_MSGOUT_WDTR)
2748 if (message_error)
2750 if ( (aic7xxx_verbose & VERBOSE_NEGOTIATION2) &&
2751 (aic_dev->flags & DEVICE_PRINT_DTR) )
2753 printk(INFO_LEAD "Device failed to complete Wide Negotiation "
2754 "processing and\n", p->host_no, CTL_OF_SCB(scb));
2755 printk(INFO_LEAD "returned a sense error code for invalid message, "
2756 "disabling future\n", p->host_no, CTL_OF_SCB(scb));
2757 printk(INFO_LEAD "Wide negotiation to this device.\n", p->host_no,
2758 CTL_OF_SCB(scb));
2760 aic_dev->needwdtr = aic_dev->needwdtr_copy = 0;
2763 if (scb->flags & SCB_MSGOUT_SDTR)
2765 if (message_error)
2767 if ( (aic7xxx_verbose & VERBOSE_NEGOTIATION2) &&
2768 (aic_dev->flags & DEVICE_PRINT_DTR) )
2770 printk(INFO_LEAD "Device failed to complete Sync Negotiation "
2771 "processing and\n", p->host_no, CTL_OF_SCB(scb));
2772 printk(INFO_LEAD "returned a sense error code for invalid message, "
2773 "disabling future\n", p->host_no, CTL_OF_SCB(scb));
2774 printk(INFO_LEAD "Sync negotiation to this device.\n", p->host_no,
2775 CTL_OF_SCB(scb));
2776 aic_dev->flags &= ~DEVICE_PRINT_DTR;
2778 aic_dev->needsdtr = aic_dev->needsdtr_copy = 0;
2781 if (scb->flags & SCB_MSGOUT_PPR)
2783 if(message_error)
2785 if ( (aic7xxx_verbose & VERBOSE_NEGOTIATION2) &&
2786 (aic_dev->flags & DEVICE_PRINT_DTR) )
2788 printk(INFO_LEAD "Device failed to complete Parallel Protocol "
2789 "Request processing and\n", p->host_no, CTL_OF_SCB(scb));
2790 printk(INFO_LEAD "returned a sense error code for invalid message, "
2791 "disabling future\n", p->host_no, CTL_OF_SCB(scb));
2792 printk(INFO_LEAD "Parallel Protocol Request negotiation to this "
2793 "device.\n", p->host_no, CTL_OF_SCB(scb));
2796 * Disable PPR negotiation and revert back to WDTR and SDTR setup
2798 aic_dev->needppr = aic_dev->needppr_copy = 0;
2799 aic_dev->needsdtr = aic_dev->needsdtr_copy = 1;
2800 aic_dev->needwdtr = aic_dev->needwdtr_copy = 1;
2805 queue_depth = aic_dev->temp_q_depth;
2806 if (queue_depth >= aic_dev->active_cmds)
2808 scbp = scbq_remove_head(&aic_dev->delayed_scbs);
2809 if (scbp)
2811 if (queue_depth == 1)
2814 * Give extra preference to untagged devices, such as CD-R devices
2815 * This makes it more likely that a drive *won't* stuff up while
2816 * waiting on data at a critical time, such as CD-R writing and
2817 * audio CD ripping operations. Should also benefit tape drives.
2819 scbq_insert_head(&p->waiting_scbs, scbp);
2821 else
2823 scbq_insert_tail(&p->waiting_scbs, scbp);
2825 #ifdef AIC7XXX_VERBOSE_DEBUGGING
2826 if (aic7xxx_verbose > 0xffff)
2827 printk(INFO_LEAD "Moving SCB from delayed to waiting queue.\n",
2828 p->host_no, CTL_OF_SCB(scbp));
2829 #endif
2830 if (queue_depth > aic_dev->active_cmds)
2832 scbp = scbq_remove_head(&aic_dev->delayed_scbs);
2833 if (scbp)
2834 scbq_insert_tail(&p->waiting_scbs, scbp);
2838 if (!(scb->tag_action))
2840 aic7xxx_index_busy_target(p, scb->hscb->target_channel_lun,
2841 /* unbusy */ TRUE);
2842 if (cmd->device->simple_tags)
2844 aic_dev->temp_q_depth = aic_dev->max_q_depth;
2847 if(scb->flags & SCB_DTR_SCB)
2849 aic_dev->dtr_pending = 0;
2851 aic_dev->active_cmds--;
2852 p->activescbs--;
2854 if ((scb->sg_length >= 512) && (((cmd->result >> 16) & 0xf) == DID_OK))
2856 long *ptr;
2857 int x, i;
2860 if (rq_data_dir(cmd->request) == WRITE)
2862 aic_dev->w_total++;
2863 ptr = aic_dev->w_bins;
2865 else
2867 aic_dev->r_total++;
2868 ptr = aic_dev->r_bins;
2870 if(cmd->device->simple_tags && cmd->request->flags & REQ_HARDBARRIER)
2872 aic_dev->barrier_total++;
2873 if(scb->tag_action == MSG_ORDERED_Q_TAG)
2874 aic_dev->ordered_total++;
2876 x = scb->sg_length;
2877 x >>= 10;
2878 for(i=0; i<6; i++)
2880 x >>= 2;
2881 if(!x) {
2882 ptr[i]++;
2883 break;
2886 if(i == 6 && x)
2887 ptr[5]++;
2889 aic7xxx_free_scb(p, scb);
2890 aic7xxx_queue_cmd_complete(p, cmd);
2894 /*+F*************************************************************************
2895 * Function:
2896 * aic7xxx_run_done_queue
2898 * Description:
2899 * Calls the aic7xxx_done() for the Scsi_Cmnd of each scb in the
2900 * aborted list, and adds each scb to the free list. If complete
2901 * is TRUE, we also process the commands complete list.
2902 *-F*************************************************************************/
2903 static void
2904 aic7xxx_run_done_queue(struct aic7xxx_host *p, /*complete*/ int complete)
2906 struct aic7xxx_scb *scb;
2907 int i, found = 0;
2909 for (i = 0; i < p->scb_data->numscbs; i++)
2911 scb = p->scb_data->scb_array[i];
2912 if (scb->flags & SCB_QUEUED_FOR_DONE)
2914 if (scb->flags & SCB_QUEUE_FULL)
2916 scb->cmd->result = QUEUE_FULL << 1;
2918 else
2920 if (aic7xxx_verbose & (VERBOSE_ABORT_PROCESS | VERBOSE_RESET_PROCESS))
2921 printk(INFO_LEAD "Aborting scb %d\n",
2922 p->host_no, CTL_OF_SCB(scb), scb->hscb->tag);
2924 * Clear any residual information since the normal aic7xxx_done() path
2925 * doesn't touch the residuals.
2927 scb->hscb->residual_SG_segment_count = 0;
2928 scb->hscb->residual_data_count[0] = 0;
2929 scb->hscb->residual_data_count[1] = 0;
2930 scb->hscb->residual_data_count[2] = 0;
2932 found++;
2933 aic7xxx_done(p, scb);
2936 if (aic7xxx_verbose & (VERBOSE_ABORT_RETURN | VERBOSE_RESET_RETURN))
2938 printk(INFO_LEAD "%d commands found and queued for "
2939 "completion.\n", p->host_no, -1, -1, -1, found);
2941 if (complete)
2943 aic7xxx_done_cmds_complete(p);
2947 /*+F*************************************************************************
2948 * Function:
2949 * aic7xxx_abort_waiting_scb
2951 * Description:
2952 * Manipulate the waiting for selection list and return the
2953 * scb that follows the one that we remove.
2954 *-F*************************************************************************/
2955 static unsigned char
2956 aic7xxx_abort_waiting_scb(struct aic7xxx_host *p, struct aic7xxx_scb *scb,
2957 unsigned char scbpos, unsigned char prev)
2959 unsigned char curscb, next;
2962 * Select the SCB we want to abort and pull the next pointer out of it.
2964 curscb = aic_inb(p, SCBPTR);
2965 aic_outb(p, scbpos, SCBPTR);
2966 next = aic_inb(p, SCB_NEXT);
2968 aic7xxx_add_curscb_to_free_list(p);
2971 * Update the waiting list
2973 if (prev == SCB_LIST_NULL)
2976 * First in the list
2978 aic_outb(p, next, WAITING_SCBH);
2980 else
2983 * Select the scb that pointed to us and update its next pointer.
2985 aic_outb(p, prev, SCBPTR);
2986 aic_outb(p, next, SCB_NEXT);
2989 * Point us back at the original scb position and inform the SCSI
2990 * system that the command has been aborted.
2992 aic_outb(p, curscb, SCBPTR);
2993 return (next);
2996 /*+F*************************************************************************
2997 * Function:
2998 * aic7xxx_search_qinfifo
3000 * Description:
3001 * Search the queue-in FIFO for matching SCBs and conditionally
3002 * requeue. Returns the number of matching SCBs.
3003 *-F*************************************************************************/
3004 static int
3005 aic7xxx_search_qinfifo(struct aic7xxx_host *p, int target, int channel,
3006 int lun, unsigned char tag, int flags, int requeue,
3007 volatile scb_queue_type *queue)
3009 int found;
3010 unsigned char qinpos, qintail;
3011 struct aic7xxx_scb *scbp;
3013 found = 0;
3014 qinpos = aic_inb(p, QINPOS);
3015 qintail = p->qinfifonext;
3017 p->qinfifonext = qinpos;
3019 while (qinpos != qintail)
3021 scbp = p->scb_data->scb_array[p->qinfifo[qinpos++]];
3022 if (aic7xxx_match_scb(p, scbp, target, channel, lun, tag))
3025 * We found an scb that needs to be removed.
3027 if (requeue && (queue != NULL))
3029 if (scbp->flags & SCB_WAITINGQ)
3031 scbq_remove(queue, scbp);
3032 scbq_remove(&p->waiting_scbs, scbp);
3033 scbq_remove(&AIC_DEV(scbp->cmd)->delayed_scbs, scbp);
3034 AIC_DEV(scbp->cmd)->active_cmds++;
3035 p->activescbs++;
3037 scbq_insert_tail(queue, scbp);
3038 AIC_DEV(scbp->cmd)->active_cmds--;
3039 p->activescbs--;
3040 scbp->flags |= SCB_WAITINGQ;
3041 if ( !(scbp->tag_action & TAG_ENB) )
3043 aic7xxx_index_busy_target(p, scbp->hscb->target_channel_lun,
3044 TRUE);
3047 else if (requeue)
3049 p->qinfifo[p->qinfifonext++] = scbp->hscb->tag;
3051 else
3054 * Preserve any SCB_RECOVERY_SCB flags on this scb then set the
3055 * flags we were called with, presumeably so aic7xxx_run_done_queue
3056 * can find this scb
3058 scbp->flags = flags | (scbp->flags & SCB_RECOVERY_SCB);
3059 if (aic7xxx_index_busy_target(p, scbp->hscb->target_channel_lun,
3060 FALSE) == scbp->hscb->tag)
3062 aic7xxx_index_busy_target(p, scbp->hscb->target_channel_lun,
3063 TRUE);
3066 found++;
3068 else
3070 p->qinfifo[p->qinfifonext++] = scbp->hscb->tag;
3074 * Now that we've done the work, clear out any left over commands in the
3075 * qinfifo and update the KERNEL_QINPOS down on the card.
3077 * NOTE: This routine expect the sequencer to already be paused when
3078 * it is run....make sure it's that way!
3080 qinpos = p->qinfifonext;
3081 while(qinpos != qintail)
3083 p->qinfifo[qinpos++] = SCB_LIST_NULL;
3085 if (p->features & AHC_QUEUE_REGS)
3086 aic_outb(p, p->qinfifonext, HNSCB_QOFF);
3087 else
3088 aic_outb(p, p->qinfifonext, KERNEL_QINPOS);
3090 return (found);
3093 /*+F*************************************************************************
3094 * Function:
3095 * aic7xxx_scb_on_qoutfifo
3097 * Description:
3098 * Is the scb that was passed to us currently on the qoutfifo?
3099 *-F*************************************************************************/
3100 static int
3101 aic7xxx_scb_on_qoutfifo(struct aic7xxx_host *p, struct aic7xxx_scb *scb)
3103 int i=0;
3105 while(p->qoutfifo[(p->qoutfifonext + i) & 0xff ] != SCB_LIST_NULL)
3107 if(p->qoutfifo[(p->qoutfifonext + i) & 0xff ] == scb->hscb->tag)
3108 return TRUE;
3109 else
3110 i++;
3112 return FALSE;
3116 /*+F*************************************************************************
3117 * Function:
3118 * aic7xxx_reset_device
3120 * Description:
3121 * The device at the given target/channel has been reset. Abort
3122 * all active and queued scbs for that target/channel. This function
3123 * need not worry about linked next pointers because if was a MSG_ABORT_TAG
3124 * then we had a tagged command (no linked next), if it was MSG_ABORT or
3125 * MSG_BUS_DEV_RESET then the device won't know about any commands any more
3126 * and no busy commands will exist, and if it was a bus reset, then nothing
3127 * knows about any linked next commands any more. In all cases, we don't
3128 * need to worry about the linked next or busy scb, we just need to clear
3129 * them.
3130 *-F*************************************************************************/
3131 static void
3132 aic7xxx_reset_device(struct aic7xxx_host *p, int target, int channel,
3133 int lun, unsigned char tag)
3135 struct aic7xxx_scb *scbp, *prev_scbp;
3136 struct scsi_device *sd;
3137 unsigned char active_scb, tcl, scb_tag;
3138 int i = 0, init_lists = FALSE;
3139 struct aic_dev_data *aic_dev, *remove_aic_dev = NULL;
3142 * Restore this when we're done
3144 active_scb = aic_inb(p, SCBPTR);
3146 * If we are still scanning devices, this device may not be linked into
3147 * our host controller yet. So, we grab the temporary aic_dev that we
3148 * allocate during the device scan (by getting device->hostdata for the
3149 * active device) and if the list struct in the aic_dev is empty, we
3150 * add it to p->aic_devs. Then at the end of the function, if we added
3151 * the aic_dev to our host struct so our loop would work, then we just
3152 * remove it.
3154 scb_tag = aic_inb(p, SCB_TAG);
3155 if(scb_tag < p->scb_data->numscbs)
3157 scbp = p->scb_data->scb_array[scb_tag];
3158 remove_aic_dev = (struct aic_dev_data *)scbp->cmd->device->hostdata;
3159 if(list_empty(&remove_aic_dev->list))
3160 list_add_tail(&remove_aic_dev->list, &p->aic_devs);
3161 else
3162 remove_aic_dev = NULL;
3165 if (aic7xxx_verbose & (VERBOSE_RESET_PROCESS | VERBOSE_ABORT_PROCESS))
3167 printk(INFO_LEAD "Reset device, hardware_scb %d, aic_dev %p,\n",
3168 p->host_no, channel, target, lun, active_scb, remove_aic_dev);
3169 printk(INFO_LEAD "Current scb %d, SEQADDR 0x%x, LASTPHASE "
3170 "0x%x\n",
3171 p->host_no, channel, target, lun, scb_tag,
3172 aic_inb(p, SEQADDR0) | (aic_inb(p, SEQADDR1) << 8),
3173 aic_inb(p, LASTPHASE));
3174 printk(INFO_LEAD "SG_CACHEPTR 0x%x, SG_COUNT %d, SCSISIGI 0x%x\n",
3175 p->host_no, channel, target, lun,
3176 (p->features & AHC_ULTRA2) ? aic_inb(p, SG_CACHEPTR) : 0,
3177 aic_inb(p, SG_COUNT), aic_inb(p, SCSISIGI));
3178 printk(INFO_LEAD "SSTAT0 0x%x, SSTAT1 0x%x, SSTAT2 0x%x\n",
3179 p->host_no, channel, target, lun, aic_inb(p, SSTAT0),
3180 aic_inb(p, SSTAT1), aic_inb(p, SSTAT2));
3184 * Deal with the busy target and linked next issues.
3186 list_for_each_entry(aic_dev, &p->aic_devs, list)
3188 if (aic7xxx_verbose & (VERBOSE_RESET_PROCESS | VERBOSE_ABORT_PROCESS))
3189 printk(INFO_LEAD "processing aic_dev %p\n", p->host_no, channel, target,
3190 lun, aic_dev);
3191 sd = aic_dev->SDptr;
3193 if((target != ALL_TARGETS && target != sd->id) ||
3194 (channel != ALL_CHANNELS && channel != sd->channel))
3195 continue;
3196 if (aic7xxx_verbose & (VERBOSE_ABORT_PROCESS | VERBOSE_RESET_PROCESS))
3197 printk(INFO_LEAD "Cleaning up status information "
3198 "and delayed_scbs.\n", p->host_no, sd->channel, sd->id, sd->lun);
3199 aic_dev->flags &= ~BUS_DEVICE_RESET_PENDING;
3200 if ( tag == SCB_LIST_NULL )
3202 aic_dev->dtr_pending = 0;
3203 aic_dev->needppr = aic_dev->needppr_copy;
3204 aic_dev->needsdtr = aic_dev->needsdtr_copy;
3205 aic_dev->needwdtr = aic_dev->needwdtr_copy;
3206 aic_dev->flags = DEVICE_PRINT_DTR;
3207 aic_dev->temp_q_depth = aic_dev->max_q_depth;
3209 tcl = (sd->id << 4) | (sd->channel << 3) | sd->lun;
3210 if ( (aic7xxx_index_busy_target(p, tcl, FALSE) == tag) ||
3211 (tag == SCB_LIST_NULL) )
3212 aic7xxx_index_busy_target(p, tcl, /* unbusy */ TRUE);
3213 prev_scbp = NULL;
3214 scbp = aic_dev->delayed_scbs.head;
3215 while (scbp != NULL)
3217 prev_scbp = scbp;
3218 scbp = scbp->q_next;
3219 if (aic7xxx_match_scb(p, prev_scbp, target, channel, lun, tag))
3221 scbq_remove(&aic_dev->delayed_scbs, prev_scbp);
3222 if (prev_scbp->flags & SCB_WAITINGQ)
3224 aic_dev->active_cmds++;
3225 p->activescbs++;
3227 prev_scbp->flags &= ~(SCB_ACTIVE | SCB_WAITINGQ);
3228 prev_scbp->flags |= SCB_RESET | SCB_QUEUED_FOR_DONE;
3232 if (remove_aic_dev)
3233 list_del(&remove_aic_dev->list);
3235 if (aic7xxx_verbose & (VERBOSE_ABORT_PROCESS | VERBOSE_RESET_PROCESS))
3236 printk(INFO_LEAD "Cleaning QINFIFO.\n", p->host_no, channel, target, lun );
3237 aic7xxx_search_qinfifo(p, target, channel, lun, tag,
3238 SCB_RESET | SCB_QUEUED_FOR_DONE, /* requeue */ FALSE, NULL);
3241 * Search the waiting_scbs queue for matches, this catches any SCB_QUEUED
3242 * ABORT/RESET commands.
3244 if (aic7xxx_verbose & (VERBOSE_ABORT_PROCESS | VERBOSE_RESET_PROCESS))
3245 printk(INFO_LEAD "Cleaning waiting_scbs.\n", p->host_no, channel,
3246 target, lun );
3248 struct aic7xxx_scb *scbp, *prev_scbp;
3250 prev_scbp = NULL;
3251 scbp = p->waiting_scbs.head;
3252 while (scbp != NULL)
3254 prev_scbp = scbp;
3255 scbp = scbp->q_next;
3256 if (aic7xxx_match_scb(p, prev_scbp, target, channel, lun, tag))
3258 scbq_remove(&p->waiting_scbs, prev_scbp);
3259 if (prev_scbp->flags & SCB_WAITINGQ)
3261 AIC_DEV(prev_scbp->cmd)->active_cmds++;
3262 p->activescbs++;
3264 prev_scbp->flags &= ~(SCB_ACTIVE | SCB_WAITINGQ);
3265 prev_scbp->flags |= SCB_RESET | SCB_QUEUED_FOR_DONE;
3272 * Search waiting for selection list.
3274 if (aic7xxx_verbose & (VERBOSE_ABORT_PROCESS | VERBOSE_RESET_PROCESS))
3275 printk(INFO_LEAD "Cleaning waiting for selection "
3276 "list.\n", p->host_no, channel, target, lun);
3278 unsigned char next, prev, scb_index;
3280 next = aic_inb(p, WAITING_SCBH); /* Start at head of list. */
3281 prev = SCB_LIST_NULL;
3282 while (next != SCB_LIST_NULL)
3284 aic_outb(p, next, SCBPTR);
3285 scb_index = aic_inb(p, SCB_TAG);
3286 if (scb_index >= p->scb_data->numscbs)
3289 * No aic7xxx_verbose check here.....we want to see this since it
3290 * means either the kernel driver or the sequencer screwed things up
3292 printk(WARN_LEAD "Waiting List inconsistency; SCB index=%d, "
3293 "numscbs=%d\n", p->host_no, channel, target, lun, scb_index,
3294 p->scb_data->numscbs);
3295 next = aic_inb(p, SCB_NEXT);
3296 aic7xxx_add_curscb_to_free_list(p);
3298 else
3300 scbp = p->scb_data->scb_array[scb_index];
3301 if (aic7xxx_match_scb(p, scbp, target, channel, lun, tag))
3303 next = aic7xxx_abort_waiting_scb(p, scbp, next, prev);
3304 if (scbp->flags & SCB_WAITINGQ)
3306 AIC_DEV(scbp->cmd)->active_cmds++;
3307 p->activescbs++;
3309 scbp->flags &= ~(SCB_ACTIVE | SCB_WAITINGQ);
3310 scbp->flags |= SCB_RESET | SCB_QUEUED_FOR_DONE;
3311 if (prev == SCB_LIST_NULL)
3314 * This is either the first scb on the waiting list, or we
3315 * have already yanked the first and haven't left any behind.
3316 * Either way, we need to turn off the selection hardware if
3317 * it isn't already off.
3319 aic_outb(p, aic_inb(p, SCSISEQ) & ~ENSELO, SCSISEQ);
3320 aic_outb(p, CLRSELTIMEO, CLRSINT1);
3323 else
3325 prev = next;
3326 next = aic_inb(p, SCB_NEXT);
3333 * Go through disconnected list and remove any entries we have queued
3334 * for completion, zeroing their control byte too.
3336 if (aic7xxx_verbose & (VERBOSE_ABORT_PROCESS | VERBOSE_RESET_PROCESS))
3337 printk(INFO_LEAD "Cleaning disconnected scbs "
3338 "list.\n", p->host_no, channel, target, lun);
3339 if (p->flags & AHC_PAGESCBS)
3341 unsigned char next, prev, scb_index;
3343 next = aic_inb(p, DISCONNECTED_SCBH);
3344 prev = SCB_LIST_NULL;
3345 while (next != SCB_LIST_NULL)
3347 aic_outb(p, next, SCBPTR);
3348 scb_index = aic_inb(p, SCB_TAG);
3349 if (scb_index > p->scb_data->numscbs)
3351 printk(WARN_LEAD "Disconnected List inconsistency; SCB index=%d, "
3352 "numscbs=%d\n", p->host_no, channel, target, lun, scb_index,
3353 p->scb_data->numscbs);
3354 next = aic7xxx_rem_scb_from_disc_list(p, next, prev);
3356 else
3358 scbp = p->scb_data->scb_array[scb_index];
3359 if (aic7xxx_match_scb(p, scbp, target, channel, lun, tag))
3361 next = aic7xxx_rem_scb_from_disc_list(p, next, prev);
3362 if (scbp->flags & SCB_WAITINGQ)
3364 AIC_DEV(scbp->cmd)->active_cmds++;
3365 p->activescbs++;
3367 scbp->flags &= ~(SCB_ACTIVE | SCB_WAITINGQ);
3368 scbp->flags |= SCB_RESET | SCB_QUEUED_FOR_DONE;
3369 scbp->hscb->control = 0;
3371 else
3373 prev = next;
3374 next = aic_inb(p, SCB_NEXT);
3381 * Walk the free list making sure no entries on the free list have
3382 * a valid SCB_TAG value or SCB_CONTROL byte.
3384 if (p->flags & AHC_PAGESCBS)
3386 unsigned char next;
3388 next = aic_inb(p, FREE_SCBH);
3389 while (next != SCB_LIST_NULL)
3391 aic_outb(p, next, SCBPTR);
3392 if (aic_inb(p, SCB_TAG) < p->scb_data->numscbs)
3394 printk(WARN_LEAD "Free list inconsistency!.\n", p->host_no, channel,
3395 target, lun);
3396 init_lists = TRUE;
3397 next = SCB_LIST_NULL;
3399 else
3401 aic_outb(p, SCB_LIST_NULL, SCB_TAG);
3402 aic_outb(p, 0, SCB_CONTROL);
3403 next = aic_inb(p, SCB_NEXT);
3409 * Go through the hardware SCB array looking for commands that
3410 * were active but not on any list.
3412 if (init_lists)
3414 aic_outb(p, SCB_LIST_NULL, FREE_SCBH);
3415 aic_outb(p, SCB_LIST_NULL, WAITING_SCBH);
3416 aic_outb(p, SCB_LIST_NULL, DISCONNECTED_SCBH);
3418 for (i = p->scb_data->maxhscbs - 1; i >= 0; i--)
3420 unsigned char scbid;
3422 aic_outb(p, i, SCBPTR);
3423 if (init_lists)
3425 aic_outb(p, SCB_LIST_NULL, SCB_TAG);
3426 aic_outb(p, SCB_LIST_NULL, SCB_NEXT);
3427 aic_outb(p, 0, SCB_CONTROL);
3428 aic7xxx_add_curscb_to_free_list(p);
3430 else
3432 scbid = aic_inb(p, SCB_TAG);
3433 if (scbid < p->scb_data->numscbs)
3435 scbp = p->scb_data->scb_array[scbid];
3436 if (aic7xxx_match_scb(p, scbp, target, channel, lun, tag))
3438 aic_outb(p, 0, SCB_CONTROL);
3439 aic_outb(p, SCB_LIST_NULL, SCB_TAG);
3440 aic7xxx_add_curscb_to_free_list(p);
3447 * Go through the entire SCB array now and look for commands for
3448 * for this target that are stillactive. These are other (most likely
3449 * tagged) commands that were disconnected when the reset occurred.
3450 * Any commands we find here we know this about, it wasn't on any queue,
3451 * it wasn't in the qinfifo, it wasn't in the disconnected or waiting
3452 * lists, so it really must have been a paged out SCB. In that case,
3453 * we shouldn't need to bother with updating any counters, just mark
3454 * the correct flags and go on.
3456 for (i = 0; i < p->scb_data->numscbs; i++)
3458 scbp = p->scb_data->scb_array[i];
3459 if ((scbp->flags & SCB_ACTIVE) &&
3460 aic7xxx_match_scb(p, scbp, target, channel, lun, tag) &&
3461 !aic7xxx_scb_on_qoutfifo(p, scbp))
3463 if (scbp->flags & SCB_WAITINGQ)
3465 scbq_remove(&p->waiting_scbs, scbp);
3466 scbq_remove(&AIC_DEV(scbp->cmd)->delayed_scbs, scbp);
3467 AIC_DEV(scbp->cmd)->active_cmds++;
3468 p->activescbs++;
3470 scbp->flags |= SCB_RESET | SCB_QUEUED_FOR_DONE;
3471 scbp->flags &= ~(SCB_ACTIVE | SCB_WAITINGQ);
3475 aic_outb(p, active_scb, SCBPTR);
3479 /*+F*************************************************************************
3480 * Function:
3481 * aic7xxx_clear_intstat
3483 * Description:
3484 * Clears the interrupt status.
3485 *-F*************************************************************************/
3486 static void
3487 aic7xxx_clear_intstat(struct aic7xxx_host *p)
3489 /* Clear any interrupt conditions this may have caused. */
3490 aic_outb(p, CLRSELDO | CLRSELDI | CLRSELINGO, CLRSINT0);
3491 aic_outb(p, CLRSELTIMEO | CLRATNO | CLRSCSIRSTI | CLRBUSFREE | CLRSCSIPERR |
3492 CLRPHASECHG | CLRREQINIT, CLRSINT1);
3493 aic_outb(p, CLRSCSIINT | CLRSEQINT | CLRBRKADRINT | CLRPARERR, CLRINT);
3496 /*+F*************************************************************************
3497 * Function:
3498 * aic7xxx_reset_current_bus
3500 * Description:
3501 * Reset the current SCSI bus.
3502 *-F*************************************************************************/
3503 static void
3504 aic7xxx_reset_current_bus(struct aic7xxx_host *p)
3507 /* Disable reset interrupts. */
3508 aic_outb(p, aic_inb(p, SIMODE1) & ~ENSCSIRST, SIMODE1);
3510 /* Turn off the bus' current operations, after all, we shouldn't have any
3511 * valid commands left to cause a RSELI and SELO once we've tossed the
3512 * bus away with this reset, so we might as well shut down the sequencer
3513 * until the bus is restarted as oppossed to saving the current settings
3514 * and restoring them (which makes no sense to me). */
3516 /* Turn on the bus reset. */
3517 aic_outb(p, aic_inb(p, SCSISEQ) | SCSIRSTO, SCSISEQ);
3518 while ( (aic_inb(p, SCSISEQ) & SCSIRSTO) == 0)
3519 mdelay(5);
3522 * Some of the new Ultra2 chipsets need a longer delay after a chip
3523 * reset than just the init setup creates, so we have to delay here
3524 * before we go into a reset in order to make the chips happy.
3526 if (p->features & AHC_ULTRA2)
3527 mdelay(250);
3528 else
3529 mdelay(50);
3531 /* Turn off the bus reset. */
3532 aic_outb(p, 0, SCSISEQ);
3533 mdelay(10);
3535 aic7xxx_clear_intstat(p);
3536 /* Re-enable reset interrupts. */
3537 aic_outb(p, aic_inb(p, SIMODE1) | ENSCSIRST, SIMODE1);
3541 /*+F*************************************************************************
3542 * Function:
3543 * aic7xxx_reset_channel
3545 * Description:
3546 * Reset the channel.
3547 *-F*************************************************************************/
3548 static void
3549 aic7xxx_reset_channel(struct aic7xxx_host *p, int channel, int initiate_reset)
3551 unsigned long offset_min, offset_max;
3552 unsigned char sblkctl;
3553 int cur_channel;
3555 if (aic7xxx_verbose & VERBOSE_RESET_PROCESS)
3556 printk(INFO_LEAD "Reset channel called, %s initiate reset.\n",
3557 p->host_no, channel, -1, -1, (initiate_reset==TRUE) ? "will" : "won't" );
3560 if (channel == 1)
3562 offset_min = 8;
3563 offset_max = 16;
3565 else
3567 if (p->features & AHC_TWIN)
3569 /* Channel A */
3570 offset_min = 0;
3571 offset_max = 8;
3573 else
3575 offset_min = 0;
3576 if (p->features & AHC_WIDE)
3578 offset_max = 16;
3580 else
3582 offset_max = 8;
3587 while (offset_min < offset_max)
3590 * Revert to async/narrow transfers until we renegotiate.
3592 aic_outb(p, 0, TARG_SCSIRATE + offset_min);
3593 if (p->features & AHC_ULTRA2)
3595 aic_outb(p, 0, TARG_OFFSET + offset_min);
3597 offset_min++;
3601 * Reset the bus and unpause/restart the controller
3603 sblkctl = aic_inb(p, SBLKCTL);
3604 if ( (p->chip & AHC_CHIPID_MASK) == AHC_AIC7770 )
3605 cur_channel = (sblkctl & SELBUSB) >> 3;
3606 else
3607 cur_channel = 0;
3608 if ( (cur_channel != channel) && (p->features & AHC_TWIN) )
3611 * Case 1: Command for another bus is active
3613 if (aic7xxx_verbose & VERBOSE_RESET_PROCESS)
3614 printk(INFO_LEAD "Stealthily resetting idle channel.\n", p->host_no,
3615 channel, -1, -1);
3617 * Stealthily reset the other bus without upsetting the current bus.
3619 aic_outb(p, sblkctl ^ SELBUSB, SBLKCTL);
3620 aic_outb(p, aic_inb(p, SIMODE1) & ~ENBUSFREE, SIMODE1);
3621 if (initiate_reset)
3623 aic7xxx_reset_current_bus(p);
3625 aic_outb(p, aic_inb(p, SCSISEQ) & (ENSELI|ENRSELI|ENAUTOATNP), SCSISEQ);
3626 aic7xxx_clear_intstat(p);
3627 aic_outb(p, sblkctl, SBLKCTL);
3629 else
3632 * Case 2: A command from this bus is active or we're idle.
3634 if (aic7xxx_verbose & VERBOSE_RESET_PROCESS)
3635 printk(INFO_LEAD "Resetting currently active channel.\n", p->host_no,
3636 channel, -1, -1);
3637 aic_outb(p, aic_inb(p, SIMODE1) & ~(ENBUSFREE|ENREQINIT),
3638 SIMODE1);
3639 p->flags &= ~AHC_HANDLING_REQINITS;
3640 p->msg_type = MSG_TYPE_NONE;
3641 p->msg_len = 0;
3642 if (initiate_reset)
3644 aic7xxx_reset_current_bus(p);
3646 aic_outb(p, aic_inb(p, SCSISEQ) & (ENSELI|ENRSELI|ENAUTOATNP), SCSISEQ);
3647 aic7xxx_clear_intstat(p);
3649 if (aic7xxx_verbose & VERBOSE_RESET_RETURN)
3650 printk(INFO_LEAD "Channel reset\n", p->host_no, channel, -1, -1);
3652 * Clean up all the state information for the pending transactions
3653 * on this bus.
3655 aic7xxx_reset_device(p, ALL_TARGETS, channel, ALL_LUNS, SCB_LIST_NULL);
3657 if ( !(p->features & AHC_TWIN) )
3659 restart_sequencer(p);
3662 return;
3665 /*+F*************************************************************************
3666 * Function:
3667 * aic7xxx_run_waiting_queues
3669 * Description:
3670 * Scan the awaiting_scbs queue downloading and starting as many
3671 * scbs as we can.
3672 *-F*************************************************************************/
3673 static void
3674 aic7xxx_run_waiting_queues(struct aic7xxx_host *p)
3676 struct aic7xxx_scb *scb;
3677 struct aic_dev_data *aic_dev;
3678 int sent;
3681 if (p->waiting_scbs.head == NULL)
3682 return;
3684 sent = 0;
3687 * First handle SCBs that are waiting but have been assigned a slot.
3689 while ((scb = scbq_remove_head(&p->waiting_scbs)) != NULL)
3691 aic_dev = scb->cmd->device->hostdata;
3692 if ( !scb->tag_action )
3694 aic_dev->temp_q_depth = 1;
3696 if ( aic_dev->active_cmds >= aic_dev->temp_q_depth)
3698 scbq_insert_tail(&aic_dev->delayed_scbs, scb);
3700 else
3702 scb->flags &= ~SCB_WAITINGQ;
3703 aic_dev->active_cmds++;
3704 p->activescbs++;
3705 if ( !(scb->tag_action) )
3707 aic7xxx_busy_target(p, scb);
3709 p->qinfifo[p->qinfifonext++] = scb->hscb->tag;
3710 sent++;
3713 if (sent)
3715 if (p->features & AHC_QUEUE_REGS)
3716 aic_outb(p, p->qinfifonext, HNSCB_QOFF);
3717 else
3719 pause_sequencer(p);
3720 aic_outb(p, p->qinfifonext, KERNEL_QINPOS);
3721 unpause_sequencer(p, FALSE);
3723 if (p->activescbs > p->max_activescbs)
3724 p->max_activescbs = p->activescbs;
3728 #ifdef CONFIG_PCI
3730 #define DPE 0x80
3731 #define SSE 0x40
3732 #define RMA 0x20
3733 #define RTA 0x10
3734 #define STA 0x08
3735 #define DPR 0x01
3737 /*+F*************************************************************************
3738 * Function:
3739 * aic7xxx_pci_intr
3741 * Description:
3742 * Check the scsi card for PCI errors and clear the interrupt
3744 * NOTE: If you don't have this function and a 2940 card encounters
3745 * a PCI error condition, the machine will end up locked as the
3746 * interrupt handler gets slammed with non-stop PCI error interrupts
3747 *-F*************************************************************************/
3748 static void
3749 aic7xxx_pci_intr(struct aic7xxx_host *p)
3751 unsigned char status1;
3753 pci_read_config_byte(p->pdev, PCI_STATUS + 1, &status1);
3755 if ( (status1 & DPE) && (aic7xxx_verbose & VERBOSE_MINOR_ERROR) )
3756 printk(WARN_LEAD "Data Parity Error during PCI address or PCI write"
3757 "phase.\n", p->host_no, -1, -1, -1);
3758 if ( (status1 & SSE) && (aic7xxx_verbose & VERBOSE_MINOR_ERROR) )
3759 printk(WARN_LEAD "Signal System Error Detected\n", p->host_no,
3760 -1, -1, -1);
3761 if ( (status1 & RMA) && (aic7xxx_verbose & VERBOSE_MINOR_ERROR) )
3762 printk(WARN_LEAD "Received a PCI Master Abort\n", p->host_no,
3763 -1, -1, -1);
3764 if ( (status1 & RTA) && (aic7xxx_verbose & VERBOSE_MINOR_ERROR) )
3765 printk(WARN_LEAD "Received a PCI Target Abort\n", p->host_no,
3766 -1, -1, -1);
3767 if ( (status1 & STA) && (aic7xxx_verbose & VERBOSE_MINOR_ERROR) )
3768 printk(WARN_LEAD "Signaled a PCI Target Abort\n", p->host_no,
3769 -1, -1, -1);
3770 if ( (status1 & DPR) && (aic7xxx_verbose & VERBOSE_MINOR_ERROR) )
3771 printk(WARN_LEAD "Data Parity Error has been reported via PCI pin "
3772 "PERR#\n", p->host_no, -1, -1, -1);
3774 pci_write_config_byte(p->pdev, PCI_STATUS + 1, status1);
3775 if (status1 & (DPR|RMA|RTA))
3776 aic_outb(p, CLRPARERR, CLRINT);
3778 if ( (aic7xxx_panic_on_abort) && (p->spurious_int > 500) )
3779 aic7xxx_panic_abort(p, NULL);
3782 #endif /* CONFIG_PCI */
3784 /*+F*************************************************************************
3785 * Function:
3786 * aic7xxx_construct_ppr
3788 * Description:
3789 * Build up a Parallel Protocol Request message for use with SCSI-3
3790 * devices.
3791 *-F*************************************************************************/
3792 static void
3793 aic7xxx_construct_ppr(struct aic7xxx_host *p, struct aic7xxx_scb *scb)
3795 p->msg_buf[p->msg_index++] = MSG_EXTENDED;
3796 p->msg_buf[p->msg_index++] = MSG_EXT_PPR_LEN;
3797 p->msg_buf[p->msg_index++] = MSG_EXT_PPR;
3798 p->msg_buf[p->msg_index++] = AIC_DEV(scb->cmd)->goal.period;
3799 p->msg_buf[p->msg_index++] = 0;
3800 p->msg_buf[p->msg_index++] = AIC_DEV(scb->cmd)->goal.offset;
3801 p->msg_buf[p->msg_index++] = AIC_DEV(scb->cmd)->goal.width;
3802 p->msg_buf[p->msg_index++] = AIC_DEV(scb->cmd)->goal.options;
3803 p->msg_len += 8;
3806 /*+F*************************************************************************
3807 * Function:
3808 * aic7xxx_construct_sdtr
3810 * Description:
3811 * Constucts a synchronous data transfer message in the message
3812 * buffer on the sequencer.
3813 *-F*************************************************************************/
3814 static void
3815 aic7xxx_construct_sdtr(struct aic7xxx_host *p, unsigned char period,
3816 unsigned char offset)
3818 p->msg_buf[p->msg_index++] = MSG_EXTENDED;
3819 p->msg_buf[p->msg_index++] = MSG_EXT_SDTR_LEN;
3820 p->msg_buf[p->msg_index++] = MSG_EXT_SDTR;
3821 p->msg_buf[p->msg_index++] = period;
3822 p->msg_buf[p->msg_index++] = offset;
3823 p->msg_len += 5;
3826 /*+F*************************************************************************
3827 * Function:
3828 * aic7xxx_construct_wdtr
3830 * Description:
3831 * Constucts a wide data transfer message in the message buffer
3832 * on the sequencer.
3833 *-F*************************************************************************/
3834 static void
3835 aic7xxx_construct_wdtr(struct aic7xxx_host *p, unsigned char bus_width)
3837 p->msg_buf[p->msg_index++] = MSG_EXTENDED;
3838 p->msg_buf[p->msg_index++] = MSG_EXT_WDTR_LEN;
3839 p->msg_buf[p->msg_index++] = MSG_EXT_WDTR;
3840 p->msg_buf[p->msg_index++] = bus_width;
3841 p->msg_len += 4;
3844 /*+F*************************************************************************
3845 * Function:
3846 * aic7xxx_calc_residual
3848 * Description:
3849 * Calculate the residual data not yet transferred.
3850 *-F*************************************************************************/
3851 static void
3852 aic7xxx_calculate_residual (struct aic7xxx_host *p, struct aic7xxx_scb *scb)
3854 struct aic7xxx_hwscb *hscb;
3855 Scsi_Cmnd *cmd;
3856 int actual, i;
3858 cmd = scb->cmd;
3859 hscb = scb->hscb;
3862 * Don't destroy valid residual information with
3863 * residual coming from a check sense operation.
3865 if (((scb->hscb->control & DISCONNECTED) == 0) &&
3866 (scb->flags & SCB_SENSE) == 0)
3869 * We had an underflow. At this time, there's only
3870 * one other driver that bothers to check for this,
3871 * and cmd->underflow seems to be set rather half-
3872 * heartedly in the higher-level SCSI code.
3874 actual = scb->sg_length;
3875 for (i=1; i < hscb->residual_SG_segment_count; i++)
3877 actual -= scb->sg_list[scb->sg_count - i].length;
3879 actual -= (hscb->residual_data_count[2] << 16) |
3880 (hscb->residual_data_count[1] << 8) |
3881 hscb->residual_data_count[0];
3883 if (actual < cmd->underflow)
3885 if (aic7xxx_verbose & VERBOSE_MINOR_ERROR)
3887 printk(INFO_LEAD "Underflow - Wanted %u, %s %u, residual SG "
3888 "count %d.\n", p->host_no, CTL_OF_SCB(scb), cmd->underflow,
3889 (rq_data_dir(cmd->request) == WRITE) ? "wrote" : "read", actual,
3890 hscb->residual_SG_segment_count);
3891 printk(INFO_LEAD "status 0x%x.\n", p->host_no, CTL_OF_SCB(scb),
3892 hscb->target_status);
3895 * In 2.4, only send back the residual information, don't flag this
3896 * as an error. Before 2.4 we had to flag this as an error because
3897 * the mid layer didn't check residual data counts to see if the
3898 * command needs retried.
3900 cmd->resid = scb->sg_length - actual;
3901 aic7xxx_status(cmd) = hscb->target_status;
3906 * Clean out the residual information in the SCB for the
3907 * next consumer.
3909 hscb->residual_data_count[2] = 0;
3910 hscb->residual_data_count[1] = 0;
3911 hscb->residual_data_count[0] = 0;
3912 hscb->residual_SG_segment_count = 0;
3915 /*+F*************************************************************************
3916 * Function:
3917 * aic7xxx_handle_device_reset
3919 * Description:
3920 * Interrupt handler for sequencer interrupts (SEQINT).
3921 *-F*************************************************************************/
3922 static void
3923 aic7xxx_handle_device_reset(struct aic7xxx_host *p, int target, int channel)
3925 unsigned char tindex = target;
3927 tindex |= ((channel & 0x01) << 3);
3930 * Go back to async/narrow transfers and renegotiate.
3932 aic_outb(p, 0, TARG_SCSIRATE + tindex);
3933 if (p->features & AHC_ULTRA2)
3934 aic_outb(p, 0, TARG_OFFSET + tindex);
3935 aic7xxx_reset_device(p, target, channel, ALL_LUNS, SCB_LIST_NULL);
3936 if (aic7xxx_verbose & VERBOSE_RESET_PROCESS)
3937 printk(INFO_LEAD "Bus Device Reset delivered.\n", p->host_no, channel,
3938 target, -1);
3939 aic7xxx_run_done_queue(p, /*complete*/ TRUE);
3942 /*+F*************************************************************************
3943 * Function:
3944 * aic7xxx_handle_seqint
3946 * Description:
3947 * Interrupt handler for sequencer interrupts (SEQINT).
3948 *-F*************************************************************************/
3949 static void
3950 aic7xxx_handle_seqint(struct aic7xxx_host *p, unsigned char intstat)
3952 struct aic7xxx_scb *scb;
3953 struct aic_dev_data *aic_dev;
3954 unsigned short target_mask;
3955 unsigned char target, lun, tindex;
3956 unsigned char queue_flag = FALSE;
3957 char channel;
3959 target = ((aic_inb(p, SAVED_TCL) >> 4) & 0x0f);
3960 if ( (p->chip & AHC_CHIPID_MASK) == AHC_AIC7770 )
3961 channel = (aic_inb(p, SBLKCTL) & SELBUSB) >> 3;
3962 else
3963 channel = 0;
3964 tindex = target + (channel << 3);
3965 lun = aic_inb(p, SAVED_TCL) & 0x07;
3966 target_mask = (0x01 << tindex);
3969 * Go ahead and clear the SEQINT now, that avoids any interrupt race
3970 * conditions later on in case we enable some other interrupt.
3972 aic_outb(p, CLRSEQINT, CLRINT);
3973 switch (intstat & SEQINT_MASK)
3975 case NO_MATCH:
3977 aic_outb(p, aic_inb(p, SCSISEQ) & (ENSELI|ENRSELI|ENAUTOATNP),
3978 SCSISEQ);
3979 printk(WARN_LEAD "No active SCB for reconnecting target - Issuing "
3980 "BUS DEVICE RESET.\n", p->host_no, channel, target, lun);
3981 printk(WARN_LEAD " SAVED_TCL=0x%x, ARG_1=0x%x, SEQADDR=0x%x\n",
3982 p->host_no, channel, target, lun,
3983 aic_inb(p, SAVED_TCL), aic_inb(p, ARG_1),
3984 (aic_inb(p, SEQADDR1) << 8) | aic_inb(p, SEQADDR0));
3985 if (aic7xxx_panic_on_abort)
3986 aic7xxx_panic_abort(p, NULL);
3988 break;
3990 case SEND_REJECT:
3992 if (aic7xxx_verbose & VERBOSE_MINOR_ERROR)
3993 printk(INFO_LEAD "Rejecting unknown message (0x%x) received from "
3994 "target, SEQ_FLAGS=0x%x\n", p->host_no, channel, target, lun,
3995 aic_inb(p, ACCUM), aic_inb(p, SEQ_FLAGS));
3997 break;
3999 case NO_IDENT:
4002 * The reconnecting target either did not send an identify
4003 * message, or did, but we didn't find an SCB to match and
4004 * before it could respond to our ATN/abort, it hit a dataphase.
4005 * The only safe thing to do is to blow it away with a bus
4006 * reset.
4008 if (aic7xxx_verbose & (VERBOSE_SEQINT | VERBOSE_RESET_MID))
4009 printk(INFO_LEAD "Target did not send an IDENTIFY message; "
4010 "LASTPHASE 0x%x, SAVED_TCL 0x%x\n", p->host_no, channel, target,
4011 lun, aic_inb(p, LASTPHASE), aic_inb(p, SAVED_TCL));
4013 aic7xxx_reset_channel(p, channel, /*initiate reset*/ TRUE);
4014 aic7xxx_run_done_queue(p, TRUE);
4017 break;
4019 case BAD_PHASE:
4020 if (aic_inb(p, LASTPHASE) == P_BUSFREE)
4022 if (aic7xxx_verbose & VERBOSE_SEQINT)
4023 printk(INFO_LEAD "Missed busfree.\n", p->host_no, channel,
4024 target, lun);
4025 restart_sequencer(p);
4027 else
4029 if (aic7xxx_verbose & VERBOSE_SEQINT)
4030 printk(INFO_LEAD "Unknown scsi bus phase, continuing\n", p->host_no,
4031 channel, target, lun);
4033 break;
4035 case EXTENDED_MSG:
4037 p->msg_type = MSG_TYPE_INITIATOR_MSGIN;
4038 p->msg_len = 0;
4039 p->msg_index = 0;
4041 #ifdef AIC7XXX_VERBOSE_DEBUGGING
4042 if (aic7xxx_verbose > 0xffff)
4043 printk(INFO_LEAD "Enabling REQINITs for MSG_IN\n", p->host_no,
4044 channel, target, lun);
4045 #endif
4048 * To actually receive the message, simply turn on
4049 * REQINIT interrupts and let our interrupt handler
4050 * do the rest (REQINIT should already be true).
4052 p->flags |= AHC_HANDLING_REQINITS;
4053 aic_outb(p, aic_inb(p, SIMODE1) | ENREQINIT, SIMODE1);
4056 * We don't want the sequencer unpaused yet so we return early
4058 return;
4061 case REJECT_MSG:
4064 * What we care about here is if we had an outstanding SDTR
4065 * or WDTR message for this target. If we did, this is a
4066 * signal that the target is refusing negotiation.
4068 unsigned char scb_index;
4069 unsigned char last_msg;
4071 scb_index = aic_inb(p, SCB_TAG);
4072 scb = p->scb_data->scb_array[scb_index];
4073 aic_dev = AIC_DEV(scb->cmd);
4074 last_msg = aic_inb(p, LAST_MSG);
4076 if ( (last_msg == MSG_IDENTIFYFLAG) &&
4077 (scb->tag_action) &&
4078 !(scb->flags & SCB_MSGOUT_BITS) )
4080 if (scb->tag_action == MSG_ORDERED_Q_TAG)
4083 * OK...the device seems able to accept tagged commands, but
4084 * not ordered tag commands, only simple tag commands. So, we
4085 * disable ordered tag commands and go on with life just like
4086 * normal.
4088 scsi_adjust_queue_depth(scb->cmd->device, MSG_SIMPLE_TAG,
4089 scb->cmd->device->new_queue_depth);
4090 scb->tag_action = MSG_SIMPLE_Q_TAG;
4091 scb->hscb->control &= ~SCB_TAG_TYPE;
4092 scb->hscb->control |= MSG_SIMPLE_Q_TAG;
4093 aic_outb(p, scb->hscb->control, SCB_CONTROL);
4095 * OK..we set the tag type to simple tag command, now we re-assert
4096 * ATNO and hope this will take us into the identify phase again
4097 * so we can resend the tag type and info to the device.
4099 aic_outb(p, MSG_IDENTIFYFLAG, MSG_OUT);
4100 aic_outb(p, aic_inb(p, SCSISIGI) | ATNO, SCSISIGO);
4102 else if (scb->tag_action == MSG_SIMPLE_Q_TAG)
4104 unsigned char i;
4105 struct aic7xxx_scb *scbp;
4106 int old_verbose;
4108 * Hmmmm....the device is flaking out on tagged commands.
4110 scsi_adjust_queue_depth(scb->cmd->device, 0 /* untagged */,
4111 p->host->cmd_per_lun);
4112 aic_dev->max_q_depth = aic_dev->temp_q_depth = 1;
4114 * We set this command up as a bus device reset. However, we have
4115 * to clear the tag type as it's causing us problems. We shouldnt
4116 * have to worry about any other commands being active, since if
4117 * the device is refusing tagged commands, this should be the
4118 * first tagged command sent to the device, however, we do have
4119 * to worry about any other tagged commands that may already be
4120 * in the qinfifo. The easiest way to do this, is to issue a BDR,
4121 * send all the commands back to the mid level code, then let them
4122 * come back and get rebuilt as untagged commands.
4124 scb->tag_action = 0;
4125 scb->hscb->control &= ~(TAG_ENB | SCB_TAG_TYPE);
4126 aic_outb(p, scb->hscb->control, SCB_CONTROL);
4128 old_verbose = aic7xxx_verbose;
4129 aic7xxx_verbose &= ~(VERBOSE_RESET|VERBOSE_ABORT);
4130 for (i=0; i < p->scb_data->numscbs; i++)
4132 scbp = p->scb_data->scb_array[i];
4133 if ((scbp->flags & SCB_ACTIVE) && (scbp != scb))
4135 if (aic7xxx_match_scb(p, scbp, target, channel, lun, i))
4137 aic7xxx_reset_device(p, target, channel, lun, i);
4141 aic7xxx_run_done_queue(p, TRUE);
4142 aic7xxx_verbose = old_verbose;
4144 * Wait until after the for loop to set the busy index since
4145 * aic7xxx_reset_device will clear the busy index during its
4146 * operation.
4148 aic7xxx_busy_target(p, scb);
4149 printk(INFO_LEAD "Device is refusing tagged commands, using "
4150 "untagged I/O.\n", p->host_no, channel, target, lun);
4151 aic_outb(p, MSG_IDENTIFYFLAG, MSG_OUT);
4152 aic_outb(p, aic_inb(p, SCSISIGI) | ATNO, SCSISIGO);
4155 else if (scb->flags & SCB_MSGOUT_PPR)
4158 * As per the draft specs, any device capable of supporting any of
4159 * the option values other than 0 are not allowed to reject the
4160 * PPR message. Instead, they must negotiate out what they do
4161 * support instead of rejecting our offering or else they cause
4162 * a parity error during msg_out phase to signal that they don't
4163 * like our settings.
4165 aic_dev->needppr = aic_dev->needppr_copy = 0;
4166 aic7xxx_set_width(p, target, channel, lun, MSG_EXT_WDTR_BUS_8_BIT,
4167 (AHC_TRANS_ACTIVE|AHC_TRANS_CUR|AHC_TRANS_QUITE), aic_dev);
4168 aic7xxx_set_syncrate(p, NULL, target, channel, 0, 0, 0,
4169 AHC_TRANS_ACTIVE|AHC_TRANS_CUR|AHC_TRANS_QUITE,
4170 aic_dev);
4171 aic_dev->goal.options = aic_dev->dtr_pending = 0;
4172 scb->flags &= ~SCB_MSGOUT_BITS;
4173 if(aic7xxx_verbose & VERBOSE_NEGOTIATION2)
4175 printk(INFO_LEAD "Device is rejecting PPR messages, falling "
4176 "back.\n", p->host_no, channel, target, lun);
4178 if ( aic_dev->goal.width )
4180 aic_dev->needwdtr = aic_dev->needwdtr_copy = 1;
4181 aic_dev->dtr_pending = 1;
4182 scb->flags |= SCB_MSGOUT_WDTR;
4184 if ( aic_dev->goal.offset )
4186 aic_dev->needsdtr = aic_dev->needsdtr_copy = 1;
4187 if( !aic_dev->dtr_pending )
4189 aic_dev->dtr_pending = 1;
4190 scb->flags |= SCB_MSGOUT_SDTR;
4193 if ( aic_dev->dtr_pending )
4195 aic_outb(p, HOST_MSG, MSG_OUT);
4196 aic_outb(p, aic_inb(p, SCSISIGI) | ATNO, SCSISIGO);
4199 else if (scb->flags & SCB_MSGOUT_WDTR)
4202 * note 8bit xfers and clear flag
4204 aic_dev->needwdtr = aic_dev->needwdtr_copy = 0;
4205 scb->flags &= ~SCB_MSGOUT_BITS;
4206 aic7xxx_set_width(p, target, channel, lun, MSG_EXT_WDTR_BUS_8_BIT,
4207 (AHC_TRANS_ACTIVE|AHC_TRANS_GOAL|AHC_TRANS_CUR), aic_dev);
4208 aic7xxx_set_syncrate(p, NULL, target, channel, 0, 0, 0,
4209 AHC_TRANS_ACTIVE|AHC_TRANS_CUR|AHC_TRANS_QUITE,
4210 aic_dev);
4211 if(aic7xxx_verbose & VERBOSE_NEGOTIATION2)
4213 printk(INFO_LEAD "Device is rejecting WDTR messages, using "
4214 "narrow transfers.\n", p->host_no, channel, target, lun);
4216 aic_dev->needsdtr = aic_dev->needsdtr_copy;
4218 else if (scb->flags & SCB_MSGOUT_SDTR)
4221 * note asynch xfers and clear flag
4223 aic_dev->needsdtr = aic_dev->needsdtr_copy = 0;
4224 scb->flags &= ~SCB_MSGOUT_BITS;
4225 aic7xxx_set_syncrate(p, NULL, target, channel, 0, 0, 0,
4226 (AHC_TRANS_CUR|AHC_TRANS_ACTIVE|AHC_TRANS_GOAL), aic_dev);
4227 if(aic7xxx_verbose & VERBOSE_NEGOTIATION2)
4229 printk(INFO_LEAD "Device is rejecting SDTR messages, using "
4230 "async transfers.\n", p->host_no, channel, target, lun);
4233 else if (aic7xxx_verbose & VERBOSE_SEQINT)
4236 * Otherwise, we ignore it.
4238 printk(INFO_LEAD "Received MESSAGE_REJECT for unknown cause. "
4239 "Ignoring.\n", p->host_no, channel, target, lun);
4242 break;
4244 case BAD_STATUS:
4246 unsigned char scb_index;
4247 struct aic7xxx_hwscb *hscb;
4248 Scsi_Cmnd *cmd;
4250 /* The sequencer will notify us when a command has an error that
4251 * would be of interest to the kernel. This allows us to leave
4252 * the sequencer running in the common case of command completes
4253 * without error. The sequencer will have DMA'd the SCB back
4254 * up to us, so we can reference the drivers SCB array.
4256 * Set the default return value to 0 indicating not to send
4257 * sense. The sense code will change this if needed and this
4258 * reduces code duplication.
4260 aic_outb(p, 0, RETURN_1);
4261 scb_index = aic_inb(p, SCB_TAG);
4262 if (scb_index > p->scb_data->numscbs)
4264 printk(WARN_LEAD "Invalid SCB during SEQINT 0x%02x, SCB_TAG %d.\n",
4265 p->host_no, channel, target, lun, intstat, scb_index);
4266 break;
4268 scb = p->scb_data->scb_array[scb_index];
4269 hscb = scb->hscb;
4271 if (!(scb->flags & SCB_ACTIVE) || (scb->cmd == NULL))
4273 printk(WARN_LEAD "Invalid SCB during SEQINT 0x%x, scb %d, flags 0x%x,"
4274 " cmd 0x%lx.\n", p->host_no, channel, target, lun, intstat,
4275 scb_index, scb->flags, (unsigned long) scb->cmd);
4277 else
4279 cmd = scb->cmd;
4280 aic_dev = AIC_DEV(scb->cmd);
4281 hscb->target_status = aic_inb(p, SCB_TARGET_STATUS);
4282 aic7xxx_status(cmd) = hscb->target_status;
4284 cmd->result = hscb->target_status;
4286 switch (status_byte(hscb->target_status))
4288 case GOOD:
4289 if (aic7xxx_verbose & VERBOSE_SEQINT)
4290 printk(INFO_LEAD "Interrupted for status of GOOD???\n",
4291 p->host_no, CTL_OF_SCB(scb));
4292 break;
4294 case COMMAND_TERMINATED:
4295 case CHECK_CONDITION:
4296 if ( !(scb->flags & SCB_SENSE) )
4299 * Send a sense command to the requesting target.
4300 * XXX - revisit this and get rid of the memcopys.
4302 memcpy(scb->sense_cmd, &generic_sense[0],
4303 sizeof(generic_sense));
4305 scb->sense_cmd[1] = (cmd->lun << 5);
4306 scb->sense_cmd[4] = sizeof(cmd->sense_buffer);
4308 scb->sg_list[0].length =
4309 cpu_to_le32(sizeof(cmd->sense_buffer));
4310 scb->sg_list[0].address =
4311 cpu_to_le32(pci_map_single(p->pdev, cmd->sense_buffer,
4312 sizeof(cmd->sense_buffer),
4313 PCI_DMA_FROMDEVICE));
4316 * XXX - We should allow disconnection, but can't as it
4317 * might allow overlapped tagged commands.
4319 /* hscb->control &= DISCENB; */
4320 hscb->control = 0;
4321 hscb->target_status = 0;
4322 hscb->SG_list_pointer =
4323 cpu_to_le32(SCB_DMA_ADDR(scb, scb->sg_list));
4324 hscb->SCSI_cmd_pointer =
4325 cpu_to_le32(SCB_DMA_ADDR(scb, scb->sense_cmd));
4326 hscb->data_count = scb->sg_list[0].length;
4327 hscb->data_pointer = scb->sg_list[0].address;
4328 hscb->SCSI_cmd_length = COMMAND_SIZE(scb->sense_cmd[0]);
4329 hscb->residual_SG_segment_count = 0;
4330 hscb->residual_data_count[0] = 0;
4331 hscb->residual_data_count[1] = 0;
4332 hscb->residual_data_count[2] = 0;
4334 scb->sg_count = hscb->SG_segment_count = 1;
4335 scb->sg_length = sizeof(cmd->sense_buffer);
4336 scb->tag_action = 0;
4337 scb->flags |= SCB_SENSE;
4339 * Ensure the target is busy since this will be an
4340 * an untagged request.
4342 #ifdef AIC7XXX_VERBOSE_DEBUGGING
4343 if (aic7xxx_verbose & VERBOSE_NEGOTIATION2)
4345 if (scb->flags & SCB_MSGOUT_BITS)
4346 printk(INFO_LEAD "Requesting SENSE with %s\n", p->host_no,
4347 CTL_OF_SCB(scb), (scb->flags & SCB_MSGOUT_SDTR) ?
4348 "SDTR" : "WDTR");
4349 else
4350 printk(INFO_LEAD "Requesting SENSE, no MSG\n", p->host_no,
4351 CTL_OF_SCB(scb));
4353 #endif
4354 aic7xxx_busy_target(p, scb);
4355 aic_outb(p, SEND_SENSE, RETURN_1);
4356 aic7xxx_error(cmd) = DID_OK;
4357 break;
4358 } /* first time sense, no errors */
4359 printk(INFO_LEAD "CHECK_CONDITION on REQUEST_SENSE, returning "
4360 "an error.\n", p->host_no, CTL_OF_SCB(scb));
4361 aic7xxx_error(cmd) = DID_ERROR;
4362 scb->flags &= ~SCB_SENSE;
4363 break;
4365 case QUEUE_FULL:
4366 queue_flag = TRUE; /* Mark that this is a QUEUE_FULL and */
4367 case BUSY: /* drop through to here */
4369 struct aic7xxx_scb *next_scbp, *prev_scbp;
4370 unsigned char active_hscb, next_hscb, prev_hscb, scb_index;
4372 * We have to look three places for queued commands:
4373 * 1: p->waiting_scbs queue
4374 * 2: QINFIFO
4375 * 3: WAITING_SCBS list on card (for commands that are started
4376 * but haven't yet made it to the device)
4378 * Of special note here is that commands on 2 or 3 above will
4379 * have already been marked as active, while commands on 1 will
4380 * not. The aic7xxx_done() function will want to unmark them
4381 * from active, so any commands we pull off of 1 need to
4382 * up the active count.
4384 next_scbp = p->waiting_scbs.head;
4385 while ( next_scbp != NULL )
4387 prev_scbp = next_scbp;
4388 next_scbp = next_scbp->q_next;
4389 if ( aic7xxx_match_scb(p, prev_scbp, target, channel, lun,
4390 SCB_LIST_NULL) )
4392 scbq_remove(&p->waiting_scbs, prev_scbp);
4393 scb->flags = SCB_QUEUED_FOR_DONE | SCB_QUEUE_FULL;
4394 p->activescbs++;
4395 aic_dev->active_cmds++;
4398 aic7xxx_search_qinfifo(p, target, channel, lun,
4399 SCB_LIST_NULL, SCB_QUEUED_FOR_DONE | SCB_QUEUE_FULL,
4400 FALSE, NULL);
4401 next_scbp = NULL;
4402 active_hscb = aic_inb(p, SCBPTR);
4403 prev_hscb = next_hscb = scb_index = SCB_LIST_NULL;
4404 next_hscb = aic_inb(p, WAITING_SCBH);
4405 while (next_hscb != SCB_LIST_NULL)
4407 aic_outb(p, next_hscb, SCBPTR);
4408 scb_index = aic_inb(p, SCB_TAG);
4409 if (scb_index < p->scb_data->numscbs)
4411 next_scbp = p->scb_data->scb_array[scb_index];
4412 if (aic7xxx_match_scb(p, next_scbp, target, channel, lun,
4413 SCB_LIST_NULL) )
4415 next_scbp->flags = SCB_QUEUED_FOR_DONE | SCB_QUEUE_FULL;
4416 next_hscb = aic_inb(p, SCB_NEXT);
4417 aic_outb(p, 0, SCB_CONTROL);
4418 aic_outb(p, SCB_LIST_NULL, SCB_TAG);
4419 aic7xxx_add_curscb_to_free_list(p);
4420 if (prev_hscb == SCB_LIST_NULL)
4422 /* We were first on the list,
4423 * so we kill the selection
4424 * hardware. Let the sequencer
4425 * re-init the hardware itself
4427 aic_outb(p, aic_inb(p, SCSISEQ) & ~ENSELO, SCSISEQ);
4428 aic_outb(p, CLRSELTIMEO, CLRSINT1);
4429 aic_outb(p, next_hscb, WAITING_SCBH);
4431 else
4433 aic_outb(p, prev_hscb, SCBPTR);
4434 aic_outb(p, next_hscb, SCB_NEXT);
4437 else
4439 prev_hscb = next_hscb;
4440 next_hscb = aic_inb(p, SCB_NEXT);
4442 } /* scb_index >= p->scb_data->numscbs */
4444 aic_outb(p, active_hscb, SCBPTR);
4445 aic7xxx_run_done_queue(p, FALSE);
4447 #ifdef AIC7XXX_VERBOSE_DEBUGGING
4448 if( (aic7xxx_verbose & VERBOSE_MINOR_ERROR) ||
4449 (aic7xxx_verbose > 0xffff) )
4451 if (queue_flag)
4452 printk(INFO_LEAD "Queue full received; queue depth %d, "
4453 "active %d\n", p->host_no, CTL_OF_SCB(scb),
4454 aic_dev->max_q_depth, aic_dev->active_cmds);
4455 else
4456 printk(INFO_LEAD "Target busy\n", p->host_no, CTL_OF_SCB(scb));
4458 #endif
4459 #if 0
4460 if (queue_flag)
4462 if ( p->dev_last_queue_full[tindex] !=
4463 p->dev_active_cmds[tindex] )
4465 p->dev_last_queue_full[tindex] =
4466 p->dev_active_cmds[tindex];
4467 p->dev_last_queue_full_count[tindex] = 0;
4469 else
4471 p->dev_last_queue_full_count[tindex]++;
4473 if ( (p->dev_last_queue_full_count[tindex] > 14) &&
4474 (p->dev_active_cmds[tindex] > 4) )
4476 int diff, lun;
4477 if (p->dev_active_cmds[tindex] > p->dev_lun_queue_depth[tindex])
4478 /* We don't know what to do here, so bail. */
4479 break;
4480 if (aic7xxx_verbose & VERBOSE_NEGOTIATION2)
4481 printk(INFO_LEAD "Queue depth reduced to %d\n", p->host_no,
4482 CTL_OF_SCB(scb), p->dev_active_cmds[tindex]);
4483 diff = p->dev_lun_queue_depth[tindex] -
4484 p->dev_active_cmds[tindex];
4485 p->dev_lun_queue_depth[tindex] -= diff;
4486 for(lun = 0; lun < p->host->max_lun; lun++)
4488 if(p->Scsi_Dev[tindex][lun] != NULL)
4490 p->dev_max_queue_depth[tindex] -= diff;
4491 scsi_adjust_queue_depth(p->Scsi_Dev[tindex][lun], 1,
4492 p->dev_lun_queue_depth[tindex]);
4493 if(p->dev_temp_queue_depth[tindex] > p->dev_max_queue_depth[tindex])
4494 p->dev_temp_queue_depth[tindex] = p->dev_max_queue_depth[tindex];
4497 p->dev_last_queue_full[tindex] = 0;
4498 p->dev_last_queue_full_count[tindex] = 0;
4500 else if (p->dev_active_cmds[tindex] == 0)
4502 if (aic7xxx_verbose & VERBOSE_NEGOTIATION)
4504 printk(INFO_LEAD "QUEUE_FULL status received with 0 "
4505 "commands active.\n", p->host_no, CTL_OF_SCB(scb));
4506 printk(INFO_LEAD "Tagged Command Queueing disabled\n",
4507 p->host_no, CTL_OF_SCB(scb));
4509 p->dev_max_queue_depth[tindex] = 1;
4510 p->dev_temp_queue_depth[tindex] = 1;
4511 scb->tag_action = 0;
4512 scb->hscb->control &= ~(MSG_ORDERED_Q_TAG|MSG_SIMPLE_Q_TAG);
4514 else
4516 aic_dev->flags[tindex] |= DEVICE_WAS_BUSY;
4517 p->dev_temp_queue_depth[tindex] =
4518 p->dev_active_cmds[tindex];
4521 #endif
4522 break;
4525 default:
4526 if (aic7xxx_verbose & VERBOSE_SEQINT)
4527 printk(INFO_LEAD "Unexpected target status 0x%x.\n", p->host_no,
4528 CTL_OF_SCB(scb), scb->hscb->target_status);
4529 if (!aic7xxx_error(cmd))
4531 aic7xxx_error(cmd) = DID_RETRY_COMMAND;
4533 break;
4534 } /* end switch */
4535 } /* end else of */
4537 break;
4539 case AWAITING_MSG:
4541 unsigned char scb_index, msg_out;
4543 scb_index = aic_inb(p, SCB_TAG);
4544 msg_out = aic_inb(p, MSG_OUT);
4545 scb = p->scb_data->scb_array[scb_index];
4546 aic_dev = AIC_DEV(scb->cmd);
4547 p->msg_index = p->msg_len = 0;
4549 * This SCB had a MK_MESSAGE set in its control byte informing
4550 * the sequencer that we wanted to send a special message to
4551 * this target.
4554 if ( !(scb->flags & SCB_DEVICE_RESET) &&
4555 (msg_out == MSG_IDENTIFYFLAG) &&
4556 (scb->hscb->control & TAG_ENB) )
4558 p->msg_buf[p->msg_index++] = scb->tag_action;
4559 p->msg_buf[p->msg_index++] = scb->hscb->tag;
4560 p->msg_len += 2;
4563 if (scb->flags & SCB_DEVICE_RESET)
4565 p->msg_buf[p->msg_index++] = MSG_BUS_DEV_RESET;
4566 p->msg_len++;
4567 if (aic7xxx_verbose & VERBOSE_RESET_PROCESS)
4568 printk(INFO_LEAD "Bus device reset mailed.\n",
4569 p->host_no, CTL_OF_SCB(scb));
4571 else if (scb->flags & SCB_ABORT)
4573 if (scb->tag_action)
4575 p->msg_buf[p->msg_index++] = MSG_ABORT_TAG;
4577 else
4579 p->msg_buf[p->msg_index++] = MSG_ABORT;
4581 p->msg_len++;
4582 if (aic7xxx_verbose & VERBOSE_ABORT_PROCESS)
4583 printk(INFO_LEAD "Abort message mailed.\n", p->host_no,
4584 CTL_OF_SCB(scb));
4586 else if (scb->flags & SCB_MSGOUT_PPR)
4588 if (aic7xxx_verbose & VERBOSE_NEGOTIATION2)
4590 printk(INFO_LEAD "Sending PPR (%d/%d/%d/%d) message.\n",
4591 p->host_no, CTL_OF_SCB(scb),
4592 aic_dev->goal.period,
4593 aic_dev->goal.offset,
4594 aic_dev->goal.width,
4595 aic_dev->goal.options);
4597 aic7xxx_construct_ppr(p, scb);
4599 else if (scb->flags & SCB_MSGOUT_WDTR)
4601 if (aic7xxx_verbose & VERBOSE_NEGOTIATION2)
4603 printk(INFO_LEAD "Sending WDTR message.\n", p->host_no,
4604 CTL_OF_SCB(scb));
4606 aic7xxx_construct_wdtr(p, aic_dev->goal.width);
4608 else if (scb->flags & SCB_MSGOUT_SDTR)
4610 unsigned int max_sync, period;
4611 unsigned char options = 0;
4613 * Now that the device is selected, use the bits in SBLKCTL and
4614 * SSTAT2 to determine the max sync rate for this device.
4616 if (p->features & AHC_ULTRA2)
4618 if ( (aic_inb(p, SBLKCTL) & ENAB40) &&
4619 !(aic_inb(p, SSTAT2) & EXP_ACTIVE) )
4621 max_sync = AHC_SYNCRATE_ULTRA2;
4623 else
4625 max_sync = AHC_SYNCRATE_ULTRA;
4628 else if (p->features & AHC_ULTRA)
4630 max_sync = AHC_SYNCRATE_ULTRA;
4632 else
4634 max_sync = AHC_SYNCRATE_FAST;
4636 period = aic_dev->goal.period;
4637 aic7xxx_find_syncrate(p, &period, max_sync, &options);
4638 if (aic7xxx_verbose & VERBOSE_NEGOTIATION2)
4640 printk(INFO_LEAD "Sending SDTR %d/%d message.\n", p->host_no,
4641 CTL_OF_SCB(scb), period,
4642 aic_dev->goal.offset);
4644 aic7xxx_construct_sdtr(p, period, aic_dev->goal.offset);
4646 else
4648 panic("aic7xxx: AWAITING_MSG for an SCB that does "
4649 "not have a waiting message.\n");
4652 * We've set everything up to send our message, now to actually do
4653 * so we need to enable reqinit interrupts and let the interrupt
4654 * handler do the rest. We don't want to unpause the sequencer yet
4655 * though so we'll return early. We also have to make sure that
4656 * we clear the SEQINT *BEFORE* we set the REQINIT handler active
4657 * or else it's possible on VLB cards to loose the first REQINIT
4658 * interrupt. Edge triggered EISA cards could also loose this
4659 * interrupt, although PCI and level triggered cards should not
4660 * have this problem since they continually interrupt the kernel
4661 * until we take care of the situation.
4663 scb->flags |= SCB_MSGOUT_SENT;
4664 p->msg_index = 0;
4665 p->msg_type = MSG_TYPE_INITIATOR_MSGOUT;
4666 p->flags |= AHC_HANDLING_REQINITS;
4667 aic_outb(p, aic_inb(p, SIMODE1) | ENREQINIT, SIMODE1);
4668 return;
4670 break;
4672 case DATA_OVERRUN:
4674 unsigned char scb_index = aic_inb(p, SCB_TAG);
4675 unsigned char lastphase = aic_inb(p, LASTPHASE);
4676 unsigned int i;
4678 scb = (p->scb_data->scb_array[scb_index]);
4680 * XXX - What do we really want to do on an overrun? The
4681 * mid-level SCSI code should handle this, but for now,
4682 * we'll just indicate that the command should retried.
4683 * If we retrieved sense info on this target, then the
4684 * base SENSE info should have been saved prior to the
4685 * overrun error. In that case, we return DID_OK and let
4686 * the mid level code pick up on the sense info. Otherwise
4687 * we return DID_ERROR so the command will get retried.
4689 if ( !(scb->flags & SCB_SENSE) )
4691 printk(WARN_LEAD "Data overrun detected in %s phase, tag %d;\n",
4692 p->host_no, CTL_OF_SCB(scb),
4693 (lastphase == P_DATAIN) ? "Data-In" : "Data-Out", scb->hscb->tag);
4694 printk(KERN_WARNING " %s seen Data Phase. Length=%d, NumSGs=%d.\n",
4695 (aic_inb(p, SEQ_FLAGS) & DPHASE) ? "Have" : "Haven't",
4696 scb->sg_length, scb->sg_count);
4697 printk(KERN_WARNING " Raw SCSI Command: 0x");
4698 for (i = 0; i < scb->hscb->SCSI_cmd_length; i++)
4700 printk("%02x ", scb->cmd->cmnd[i]);
4702 printk("\n");
4703 if(aic7xxx_verbose > 0xffff)
4705 for (i = 0; i < scb->sg_count; i++)
4707 printk(KERN_WARNING " sg[%d] - Addr 0x%x : Length %d\n",
4709 le32_to_cpu(scb->sg_list[i].address),
4710 le32_to_cpu(scb->sg_list[i].length) );
4713 aic7xxx_error(scb->cmd) = DID_ERROR;
4715 else
4716 printk(INFO_LEAD "Data Overrun during SEND_SENSE operation.\n",
4717 p->host_no, CTL_OF_SCB(scb));
4719 break;
4721 case WIDE_RESIDUE:
4723 unsigned char resid_sgcnt, index;
4724 unsigned char scb_index = aic_inb(p, SCB_TAG);
4725 unsigned int cur_addr, resid_dcnt;
4726 unsigned int native_addr, native_length, sg_addr;
4727 int i;
4729 if(scb_index > p->scb_data->numscbs)
4731 printk(WARN_LEAD "invalid scb_index during WIDE_RESIDUE.\n",
4732 p->host_no, -1, -1, -1);
4734 * XXX: Add error handling here
4736 break;
4738 scb = p->scb_data->scb_array[scb_index];
4739 if(!(scb->flags & SCB_ACTIVE) || (scb->cmd == NULL))
4741 printk(WARN_LEAD "invalid scb during WIDE_RESIDUE flags:0x%x "
4742 "scb->cmd:0x%lx\n", p->host_no, CTL_OF_SCB(scb),
4743 scb->flags, (unsigned long)scb->cmd);
4744 break;
4746 if(aic7xxx_verbose & VERBOSE_MINOR_ERROR)
4747 printk(INFO_LEAD "Got WIDE_RESIDUE message, patching up data "
4748 "pointer.\n", p->host_no, CTL_OF_SCB(scb));
4751 * We have a valid scb to use on this WIDE_RESIDUE message, so
4752 * we need to walk the sg list looking for this particular sg
4753 * segment, then see if we happen to be at the very beginning of
4754 * the segment. If we are, then we have to back things up to
4755 * the previous segment. If not, then we simply need to remove
4756 * one byte from this segments address and add one to the byte
4757 * count.
4759 cur_addr = aic_inb(p, SHADDR) | (aic_inb(p, SHADDR + 1) << 8) |
4760 (aic_inb(p, SHADDR + 2) << 16) | (aic_inb(p, SHADDR + 3) << 24);
4761 sg_addr = aic_inb(p, SG_COUNT + 1) | (aic_inb(p, SG_COUNT + 2) << 8) |
4762 (aic_inb(p, SG_COUNT + 3) << 16) | (aic_inb(p, SG_COUNT + 4) << 24);
4763 resid_sgcnt = aic_inb(p, SCB_RESID_SGCNT);
4764 resid_dcnt = aic_inb(p, SCB_RESID_DCNT) |
4765 (aic_inb(p, SCB_RESID_DCNT + 1) << 8) |
4766 (aic_inb(p, SCB_RESID_DCNT + 2) << 16);
4767 index = scb->sg_count - ((resid_sgcnt) ? resid_sgcnt : 1);
4768 native_addr = le32_to_cpu(scb->sg_list[index].address);
4769 native_length = le32_to_cpu(scb->sg_list[index].length);
4771 * If resid_dcnt == native_length, then we just loaded this SG
4772 * segment and we need to back it up one...
4774 if(resid_dcnt == native_length)
4776 if(index == 0)
4779 * Oops, this isn't right, we can't back up to before the
4780 * beginning. This must be a bogus message, ignore it.
4782 break;
4784 resid_dcnt = 1;
4785 resid_sgcnt += 1;
4786 native_addr = le32_to_cpu(scb->sg_list[index - 1].address);
4787 native_length = le32_to_cpu(scb->sg_list[index - 1].length);
4788 cur_addr = native_addr + (native_length - 1);
4789 sg_addr -= sizeof(struct hw_scatterlist);
4791 else
4794 * resid_dcnt != native_length, so we are in the middle of a SG
4795 * element. Back it up one byte and leave the rest alone.
4797 resid_dcnt += 1;
4798 cur_addr -= 1;
4802 * Output the new addresses and counts to the right places on the
4803 * card.
4805 aic_outb(p, resid_sgcnt, SG_COUNT);
4806 aic_outb(p, resid_sgcnt, SCB_RESID_SGCNT);
4807 aic_outb(p, sg_addr & 0xff, SG_COUNT + 1);
4808 aic_outb(p, (sg_addr >> 8) & 0xff, SG_COUNT + 2);
4809 aic_outb(p, (sg_addr >> 16) & 0xff, SG_COUNT + 3);
4810 aic_outb(p, (sg_addr >> 24) & 0xff, SG_COUNT + 4);
4811 aic_outb(p, resid_dcnt & 0xff, SCB_RESID_DCNT);
4812 aic_outb(p, (resid_dcnt >> 8) & 0xff, SCB_RESID_DCNT + 1);
4813 aic_outb(p, (resid_dcnt >> 16) & 0xff, SCB_RESID_DCNT + 2);
4816 * The sequencer actually wants to find the new address
4817 * in the SHADDR register set. On the Ultra2 and later controllers
4818 * this register set is readonly. In order to get the right number
4819 * into the register, you actually have to enter it in HADDR and then
4820 * use the PRELOADEN bit of DFCNTRL to drop it through from the
4821 * HADDR register to the SHADDR register. On non-Ultra2 controllers,
4822 * we simply write it direct.
4824 if(p->features & AHC_ULTRA2)
4827 * We might as well be accurate and drop both the resid_dcnt and
4828 * cur_addr into HCNT and HADDR and have both of them drop
4829 * through to the shadow layer together.
4831 aic_outb(p, resid_dcnt & 0xff, HCNT);
4832 aic_outb(p, (resid_dcnt >> 8) & 0xff, HCNT + 1);
4833 aic_outb(p, (resid_dcnt >> 16) & 0xff, HCNT + 2);
4834 aic_outb(p, cur_addr & 0xff, HADDR);
4835 aic_outb(p, (cur_addr >> 8) & 0xff, HADDR + 1);
4836 aic_outb(p, (cur_addr >> 16) & 0xff, HADDR + 2);
4837 aic_outb(p, (cur_addr >> 24) & 0xff, HADDR + 3);
4838 aic_outb(p, aic_inb(p, DMAPARAMS) | PRELOADEN, DFCNTRL);
4839 udelay(1);
4840 aic_outb(p, aic_inb(p, DMAPARAMS) & ~(SCSIEN|HDMAEN), DFCNTRL);
4841 i=0;
4842 while(((aic_inb(p, DFCNTRL) & (SCSIEN|HDMAEN)) != 0) && (i++ < 1000))
4844 udelay(1);
4847 else
4849 aic_outb(p, cur_addr & 0xff, SHADDR);
4850 aic_outb(p, (cur_addr >> 8) & 0xff, SHADDR + 1);
4851 aic_outb(p, (cur_addr >> 16) & 0xff, SHADDR + 2);
4852 aic_outb(p, (cur_addr >> 24) & 0xff, SHADDR + 3);
4855 break;
4857 case SEQ_SG_FIXUP:
4859 unsigned char scb_index, tmp;
4860 int sg_addr, sg_length;
4862 scb_index = aic_inb(p, SCB_TAG);
4864 if(scb_index > p->scb_data->numscbs)
4866 printk(WARN_LEAD "invalid scb_index during SEQ_SG_FIXUP.\n",
4867 p->host_no, -1, -1, -1);
4868 printk(INFO_LEAD "SCSISIGI 0x%x, SEQADDR 0x%x, SSTAT0 0x%x, SSTAT1 "
4869 "0x%x\n", p->host_no, -1, -1, -1,
4870 aic_inb(p, SCSISIGI),
4871 aic_inb(p, SEQADDR0) | (aic_inb(p, SEQADDR1) << 8),
4872 aic_inb(p, SSTAT0), aic_inb(p, SSTAT1));
4873 printk(INFO_LEAD "SG_CACHEPTR 0x%x, SSTAT2 0x%x, STCNT 0x%x\n",
4874 p->host_no, -1, -1, -1, aic_inb(p, SG_CACHEPTR),
4875 aic_inb(p, SSTAT2), aic_inb(p, STCNT + 2) << 16 |
4876 aic_inb(p, STCNT + 1) << 8 | aic_inb(p, STCNT));
4878 * XXX: Add error handling here
4880 break;
4882 scb = p->scb_data->scb_array[scb_index];
4883 if(!(scb->flags & SCB_ACTIVE) || (scb->cmd == NULL))
4885 printk(WARN_LEAD "invalid scb during SEQ_SG_FIXUP flags:0x%x "
4886 "scb->cmd:0x%p\n", p->host_no, CTL_OF_SCB(scb),
4887 scb->flags, scb->cmd);
4888 printk(INFO_LEAD "SCSISIGI 0x%x, SEQADDR 0x%x, SSTAT0 0x%x, SSTAT1 "
4889 "0x%x\n", p->host_no, CTL_OF_SCB(scb),
4890 aic_inb(p, SCSISIGI),
4891 aic_inb(p, SEQADDR0) | (aic_inb(p, SEQADDR1) << 8),
4892 aic_inb(p, SSTAT0), aic_inb(p, SSTAT1));
4893 printk(INFO_LEAD "SG_CACHEPTR 0x%x, SSTAT2 0x%x, STCNT 0x%x\n",
4894 p->host_no, CTL_OF_SCB(scb), aic_inb(p, SG_CACHEPTR),
4895 aic_inb(p, SSTAT2), aic_inb(p, STCNT + 2) << 16 |
4896 aic_inb(p, STCNT + 1) << 8 | aic_inb(p, STCNT));
4897 break;
4899 if(aic7xxx_verbose & VERBOSE_MINOR_ERROR)
4900 printk(INFO_LEAD "Fixing up SG address for sequencer.\n", p->host_no,
4901 CTL_OF_SCB(scb));
4903 * Advance the SG pointer to the next element in the list
4905 tmp = aic_inb(p, SG_NEXT);
4906 tmp += SG_SIZEOF;
4907 aic_outb(p, tmp, SG_NEXT);
4908 if( tmp < SG_SIZEOF )
4909 aic_outb(p, aic_inb(p, SG_NEXT + 1) + 1, SG_NEXT + 1);
4910 tmp = aic_inb(p, SG_COUNT) - 1;
4911 aic_outb(p, tmp, SG_COUNT);
4912 sg_addr = le32_to_cpu(scb->sg_list[scb->sg_count - tmp].address);
4913 sg_length = le32_to_cpu(scb->sg_list[scb->sg_count - tmp].length);
4915 * Now stuff the element we just advanced past down onto the
4916 * card so it can be stored in the residual area.
4918 aic_outb(p, sg_addr & 0xff, HADDR);
4919 aic_outb(p, (sg_addr >> 8) & 0xff, HADDR + 1);
4920 aic_outb(p, (sg_addr >> 16) & 0xff, HADDR + 2);
4921 aic_outb(p, (sg_addr >> 24) & 0xff, HADDR + 3);
4922 aic_outb(p, sg_length & 0xff, HCNT);
4923 aic_outb(p, (sg_length >> 8) & 0xff, HCNT + 1);
4924 aic_outb(p, (sg_length >> 16) & 0xff, HCNT + 2);
4925 aic_outb(p, (tmp << 2) | ((tmp == 1) ? LAST_SEG : 0), SG_CACHEPTR);
4926 aic_outb(p, aic_inb(p, DMAPARAMS), DFCNTRL);
4927 while(aic_inb(p, SSTAT0) & SDONE) udelay(1);
4928 while(aic_inb(p, DFCNTRL) & (HDMAEN|SCSIEN)) aic_outb(p, 0, DFCNTRL);
4930 break;
4932 #if AIC7XXX_NOT_YET
4933 case TRACEPOINT2:
4935 printk(INFO_LEAD "Tracepoint #2 reached.\n", p->host_no,
4936 channel, target, lun);
4938 break;
4940 /* XXX Fill these in later */
4941 case MSG_BUFFER_BUSY:
4942 printk("aic7xxx: Message buffer busy.\n");
4943 break;
4944 case MSGIN_PHASEMIS:
4945 printk("aic7xxx: Message-in phasemis.\n");
4946 break;
4947 #endif
4949 default: /* unknown */
4950 printk(WARN_LEAD "Unknown SEQINT, INTSTAT 0x%x, SCSISIGI 0x%x.\n",
4951 p->host_no, channel, target, lun, intstat,
4952 aic_inb(p, SCSISIGI));
4953 break;
4957 * Clear the sequencer interrupt and unpause the sequencer.
4959 unpause_sequencer(p, /* unpause always */ TRUE);
4962 /*+F*************************************************************************
4963 * Function:
4964 * aic7xxx_parse_msg
4966 * Description:
4967 * Parses incoming messages into actions on behalf of
4968 * aic7xxx_handle_reqinit
4969 *_F*************************************************************************/
4970 static int
4971 aic7xxx_parse_msg(struct aic7xxx_host *p, struct aic7xxx_scb *scb)
4973 int reject, reply, done;
4974 unsigned char target_scsirate, tindex;
4975 unsigned short target_mask;
4976 unsigned char target, channel, lun;
4977 unsigned char bus_width, new_bus_width;
4978 unsigned char trans_options, new_trans_options;
4979 unsigned int period, new_period, offset, new_offset, maxsync;
4980 struct aic7xxx_syncrate *syncrate;
4981 struct aic_dev_data *aic_dev;
4983 target = scb->cmd->target;
4984 channel = scb->cmd->channel;
4985 lun = scb->cmd->lun;
4986 reply = reject = done = FALSE;
4987 tindex = TARGET_INDEX(scb->cmd);
4988 aic_dev = AIC_DEV(scb->cmd);
4989 target_scsirate = aic_inb(p, TARG_SCSIRATE + tindex);
4990 target_mask = (0x01 << tindex);
4993 * Parse as much of the message as is availible,
4994 * rejecting it if we don't support it. When
4995 * the entire message is availible and has been
4996 * handled, return TRUE indicating that we have
4997 * parsed an entire message.
5000 if (p->msg_buf[0] != MSG_EXTENDED)
5002 reject = TRUE;
5006 * Even if we are an Ultra3 card, don't allow Ultra3 sync rates when
5007 * using the SDTR messages. We need the PPR messages to enable the
5008 * higher speeds that include things like Dual Edge clocking.
5010 if (p->features & AHC_ULTRA2)
5012 if ( (aic_inb(p, SBLKCTL) & ENAB40) &&
5013 !(aic_inb(p, SSTAT2) & EXP_ACTIVE) )
5015 if (p->features & AHC_ULTRA3)
5016 maxsync = AHC_SYNCRATE_ULTRA3;
5017 else
5018 maxsync = AHC_SYNCRATE_ULTRA2;
5020 else
5022 maxsync = AHC_SYNCRATE_ULTRA;
5025 else if (p->features & AHC_ULTRA)
5027 maxsync = AHC_SYNCRATE_ULTRA;
5029 else
5031 maxsync = AHC_SYNCRATE_FAST;
5035 * Just accept the length byte outright and perform
5036 * more checking once we know the message type.
5039 if ( !reject && (p->msg_len > 2) )
5041 switch(p->msg_buf[2])
5043 case MSG_EXT_SDTR:
5046 if (p->msg_buf[1] != MSG_EXT_SDTR_LEN)
5048 reject = TRUE;
5049 break;
5052 if (p->msg_len < (MSG_EXT_SDTR_LEN + 2))
5054 break;
5057 period = new_period = p->msg_buf[3];
5058 offset = new_offset = p->msg_buf[4];
5059 trans_options = new_trans_options = 0;
5060 bus_width = new_bus_width = target_scsirate & WIDEXFER;
5063 * If our current max syncrate is in the Ultra3 range, bump it back
5064 * down to Ultra2 since we can't negotiate DT transfers using SDTR
5066 if(maxsync == AHC_SYNCRATE_ULTRA3)
5067 maxsync = AHC_SYNCRATE_ULTRA2;
5070 * We might have a device that is starting negotiation with us
5071 * before we can start up negotiation with it....be prepared to
5072 * have a device ask for a higher speed then we want to give it
5073 * in that case
5075 if ( (scb->flags & (SCB_MSGOUT_SENT|SCB_MSGOUT_SDTR)) !=
5076 (SCB_MSGOUT_SENT|SCB_MSGOUT_SDTR) )
5078 if (!(aic_dev->flags & DEVICE_DTR_SCANNED))
5081 * We shouldn't get here unless this is a narrow drive, wide
5082 * devices should trigger this same section of code in the WDTR
5083 * handler first instead.
5085 aic_dev->goal.width = MSG_EXT_WDTR_BUS_8_BIT;
5086 aic_dev->goal.options = 0;
5087 if(p->user[tindex].offset)
5089 aic_dev->needsdtr_copy = 1;
5090 aic_dev->goal.period = MAX(10,p->user[tindex].period);
5091 if(p->features & AHC_ULTRA2)
5093 aic_dev->goal.offset = MAX_OFFSET_ULTRA2;
5095 else
5097 aic_dev->goal.offset = MAX_OFFSET_8BIT;
5100 else
5102 aic_dev->needsdtr_copy = 0;
5103 aic_dev->goal.period = 255;
5104 aic_dev->goal.offset = 0;
5106 aic_dev->flags |= DEVICE_DTR_SCANNED | DEVICE_PRINT_DTR;
5108 else if (aic_dev->needsdtr_copy == 0)
5111 * This is a preemptive message from the target, we've already
5112 * scanned this target and set our options for it, and we
5113 * don't need a SDTR with this target (for whatever reason),
5114 * so reject this incoming SDTR
5116 reject = TRUE;
5117 break;
5120 /* The device is sending this message first and we have to reply */
5121 reply = TRUE;
5123 if (aic7xxx_verbose & VERBOSE_NEGOTIATION2)
5125 printk(INFO_LEAD "Received pre-emptive SDTR message from "
5126 "target.\n", p->host_no, CTL_OF_SCB(scb));
5129 * Validate the values the device passed to us against our SEEPROM
5130 * settings. We don't have to do this if we aren't replying since
5131 * the device isn't allowed to send values greater than the ones
5132 * we first sent to it.
5134 new_period = MAX(period, aic_dev->goal.period);
5135 new_offset = MIN(offset, aic_dev->goal.offset);
5139 * Use our new_period, new_offset, bus_width, and card options
5140 * to determine the actual syncrate settings
5142 syncrate = aic7xxx_find_syncrate(p, &new_period, maxsync,
5143 &trans_options);
5144 aic7xxx_validate_offset(p, syncrate, &new_offset, bus_width);
5147 * Did we drop to async? If so, send a reply regardless of whether
5148 * or not we initiated this negotiation.
5150 if ((new_offset == 0) && (new_offset != offset))
5152 aic_dev->needsdtr_copy = 0;
5153 reply = TRUE;
5157 * Did we start this, if not, or if we went too low and had to
5158 * go async, then send an SDTR back to the target
5160 if(reply)
5162 /* when sending a reply, make sure that the goal settings are
5163 * updated along with current and active since the code that
5164 * will actually build the message for the sequencer uses the
5165 * goal settings as its guidelines.
5167 aic7xxx_set_syncrate(p, syncrate, target, channel, new_period,
5168 new_offset, trans_options,
5169 AHC_TRANS_GOAL|AHC_TRANS_ACTIVE|AHC_TRANS_CUR,
5170 aic_dev);
5171 scb->flags &= ~SCB_MSGOUT_BITS;
5172 scb->flags |= SCB_MSGOUT_SDTR;
5173 aic_outb(p, HOST_MSG, MSG_OUT);
5174 aic_outb(p, aic_inb(p, SCSISIGO) | ATNO, SCSISIGO);
5176 else
5178 aic7xxx_set_syncrate(p, syncrate, target, channel, new_period,
5179 new_offset, trans_options,
5180 AHC_TRANS_ACTIVE|AHC_TRANS_CUR, aic_dev);
5181 aic_dev->needsdtr = 0;
5183 done = TRUE;
5184 break;
5186 case MSG_EXT_WDTR:
5189 if (p->msg_buf[1] != MSG_EXT_WDTR_LEN)
5191 reject = TRUE;
5192 break;
5195 if (p->msg_len < (MSG_EXT_WDTR_LEN + 2))
5197 break;
5200 bus_width = new_bus_width = p->msg_buf[3];
5202 if ( (scb->flags & (SCB_MSGOUT_SENT|SCB_MSGOUT_WDTR)) ==
5203 (SCB_MSGOUT_SENT|SCB_MSGOUT_WDTR) )
5205 switch(bus_width)
5207 default:
5209 reject = TRUE;
5210 if ( (aic7xxx_verbose & VERBOSE_NEGOTIATION2) &&
5211 ((aic_dev->flags & DEVICE_PRINT_DTR) ||
5212 (aic7xxx_verbose > 0xffff)) )
5214 printk(INFO_LEAD "Requesting %d bit transfers, rejecting.\n",
5215 p->host_no, CTL_OF_SCB(scb), 8 * (0x01 << bus_width));
5217 } /* We fall through on purpose */
5218 case MSG_EXT_WDTR_BUS_8_BIT:
5220 aic_dev->goal.width = MSG_EXT_WDTR_BUS_8_BIT;
5221 aic_dev->needwdtr_copy &= ~target_mask;
5222 break;
5224 case MSG_EXT_WDTR_BUS_16_BIT:
5226 break;
5229 aic_dev->needwdtr = 0;
5230 aic7xxx_set_width(p, target, channel, lun, new_bus_width,
5231 AHC_TRANS_ACTIVE|AHC_TRANS_CUR, aic_dev);
5233 else
5235 if ( !(aic_dev->flags & DEVICE_DTR_SCANNED) )
5238 * Well, we now know the WDTR and SYNC caps of this device since
5239 * it contacted us first, mark it as such and copy the user stuff
5240 * over to the goal stuff.
5242 if( (p->features & AHC_WIDE) && p->user[tindex].width )
5244 aic_dev->goal.width = MSG_EXT_WDTR_BUS_16_BIT;
5245 aic_dev->needwdtr_copy = 1;
5249 * Devices that support DT transfers don't start WDTR requests
5251 aic_dev->goal.options = 0;
5253 if(p->user[tindex].offset)
5255 aic_dev->needsdtr_copy = 1;
5256 aic_dev->goal.period = MAX(10,p->user[tindex].period);
5257 if(p->features & AHC_ULTRA2)
5259 aic_dev->goal.offset = MAX_OFFSET_ULTRA2;
5261 else if( aic_dev->goal.width )
5263 aic_dev->goal.offset = MAX_OFFSET_16BIT;
5265 else
5267 aic_dev->goal.offset = MAX_OFFSET_8BIT;
5269 } else {
5270 aic_dev->needsdtr_copy = 0;
5271 aic_dev->goal.period = 255;
5272 aic_dev->goal.offset = 0;
5275 aic_dev->flags |= DEVICE_DTR_SCANNED | DEVICE_PRINT_DTR;
5277 else if (aic_dev->needwdtr_copy == 0)
5280 * This is a preemptive message from the target, we've already
5281 * scanned this target and set our options for it, and we
5282 * don't need a WDTR with this target (for whatever reason),
5283 * so reject this incoming WDTR
5285 reject = TRUE;
5286 break;
5289 /* The device is sending this message first and we have to reply */
5290 reply = TRUE;
5292 if (aic7xxx_verbose & VERBOSE_NEGOTIATION2)
5294 printk(INFO_LEAD "Received pre-emptive WDTR message from "
5295 "target.\n", p->host_no, CTL_OF_SCB(scb));
5297 switch(bus_width)
5299 case MSG_EXT_WDTR_BUS_16_BIT:
5301 if ( (p->features & AHC_WIDE) &&
5302 (aic_dev->goal.width == MSG_EXT_WDTR_BUS_16_BIT) )
5304 new_bus_width = MSG_EXT_WDTR_BUS_16_BIT;
5305 break;
5307 } /* Fall through if we aren't a wide card */
5308 default:
5309 case MSG_EXT_WDTR_BUS_8_BIT:
5311 aic_dev->needwdtr_copy = 0;
5312 new_bus_width = MSG_EXT_WDTR_BUS_8_BIT;
5313 break;
5316 scb->flags &= ~SCB_MSGOUT_BITS;
5317 scb->flags |= SCB_MSGOUT_WDTR;
5318 aic_dev->needwdtr = 0;
5319 if(aic_dev->dtr_pending == 0)
5321 /* there is no other command with SCB_DTR_SCB already set that will
5322 * trigger the release of the dtr_pending bit. Both set the bit
5323 * and set scb->flags |= SCB_DTR_SCB
5325 aic_dev->dtr_pending = 1;
5326 scb->flags |= SCB_DTR_SCB;
5328 aic_outb(p, HOST_MSG, MSG_OUT);
5329 aic_outb(p, aic_inb(p, SCSISIGO) | ATNO, SCSISIGO);
5330 /* when sending a reply, make sure that the goal settings are
5331 * updated along with current and active since the code that
5332 * will actually build the message for the sequencer uses the
5333 * goal settings as its guidelines.
5335 aic7xxx_set_width(p, target, channel, lun, new_bus_width,
5336 AHC_TRANS_GOAL|AHC_TRANS_ACTIVE|AHC_TRANS_CUR,
5337 aic_dev);
5341 * By virtue of the SCSI spec, a WDTR message negates any existing
5342 * SDTR negotiations. So, even if needsdtr isn't marked for this
5343 * device, we still have to do a new SDTR message if the device
5344 * supports SDTR at all. Therefore, we check needsdtr_copy instead
5345 * of needstr.
5347 aic7xxx_set_syncrate(p, NULL, target, channel, 0, 0, 0,
5348 AHC_TRANS_ACTIVE|AHC_TRANS_CUR|AHC_TRANS_QUITE,
5349 aic_dev);
5350 aic_dev->needsdtr = aic_dev->needsdtr_copy;
5351 done = TRUE;
5352 break;
5354 case MSG_EXT_PPR:
5357 if (p->msg_buf[1] != MSG_EXT_PPR_LEN)
5359 reject = TRUE;
5360 break;
5363 if (p->msg_len < (MSG_EXT_PPR_LEN + 2))
5365 break;
5368 period = new_period = p->msg_buf[3];
5369 offset = new_offset = p->msg_buf[5];
5370 bus_width = new_bus_width = p->msg_buf[6];
5371 trans_options = new_trans_options = p->msg_buf[7] & 0xf;
5373 if(aic7xxx_verbose & VERBOSE_NEGOTIATION2)
5375 printk(INFO_LEAD "Parsing PPR message (%d/%d/%d/%d)\n",
5376 p->host_no, CTL_OF_SCB(scb), period, offset, bus_width,
5377 trans_options);
5381 * We might have a device that is starting negotiation with us
5382 * before we can start up negotiation with it....be prepared to
5383 * have a device ask for a higher speed then we want to give it
5384 * in that case
5386 if ( (scb->flags & (SCB_MSGOUT_SENT|SCB_MSGOUT_PPR)) !=
5387 (SCB_MSGOUT_SENT|SCB_MSGOUT_PPR) )
5389 /* Have we scanned the device yet? */
5390 if (!(aic_dev->flags & DEVICE_DTR_SCANNED))
5392 /* The device is electing to use PPR messages, so we will too until
5393 * we know better */
5394 aic_dev->needppr = aic_dev->needppr_copy = 1;
5395 aic_dev->needsdtr = aic_dev->needsdtr_copy = 0;
5396 aic_dev->needwdtr = aic_dev->needwdtr_copy = 0;
5398 /* We know the device is SCSI-3 compliant due to PPR */
5399 aic_dev->flags |= DEVICE_SCSI_3;
5402 * Not only is the device starting this up, but it also hasn't
5403 * been scanned yet, so this would likely be our TUR or our
5404 * INQUIRY command at scan time, so we need to use the
5405 * settings from the SEEPROM if they existed. Of course, even
5406 * if we didn't find a SEEPROM, we stuffed default values into
5407 * the user settings anyway, so use those in all cases.
5409 aic_dev->goal.width = p->user[tindex].width;
5410 if(p->user[tindex].offset)
5412 aic_dev->goal.period = p->user[tindex].period;
5413 aic_dev->goal.options = p->user[tindex].options;
5414 if(p->features & AHC_ULTRA2)
5416 aic_dev->goal.offset = MAX_OFFSET_ULTRA2;
5418 else if( aic_dev->goal.width &&
5419 (bus_width == MSG_EXT_WDTR_BUS_16_BIT) &&
5420 p->features & AHC_WIDE )
5422 aic_dev->goal.offset = MAX_OFFSET_16BIT;
5424 else
5426 aic_dev->goal.offset = MAX_OFFSET_8BIT;
5429 else
5431 aic_dev->goal.period = 255;
5432 aic_dev->goal.offset = 0;
5433 aic_dev->goal.options = 0;
5435 aic_dev->flags |= DEVICE_DTR_SCANNED | DEVICE_PRINT_DTR;
5437 else if (aic_dev->needppr_copy == 0)
5440 * This is a preemptive message from the target, we've already
5441 * scanned this target and set our options for it, and we
5442 * don't need a PPR with this target (for whatever reason),
5443 * so reject this incoming PPR
5445 reject = TRUE;
5446 break;
5449 /* The device is sending this message first and we have to reply */
5450 reply = TRUE;
5452 if (aic7xxx_verbose & VERBOSE_NEGOTIATION2)
5454 printk(INFO_LEAD "Received pre-emptive PPR message from "
5455 "target.\n", p->host_no, CTL_OF_SCB(scb));
5460 switch(bus_width)
5462 case MSG_EXT_WDTR_BUS_16_BIT:
5464 if ( (aic_dev->goal.width == MSG_EXT_WDTR_BUS_16_BIT) &&
5465 p->features & AHC_WIDE)
5467 break;
5470 default:
5472 if ( (aic7xxx_verbose & VERBOSE_NEGOTIATION2) &&
5473 ((aic_dev->flags & DEVICE_PRINT_DTR) ||
5474 (aic7xxx_verbose > 0xffff)) )
5476 reply = TRUE;
5477 printk(INFO_LEAD "Requesting %d bit transfers, rejecting.\n",
5478 p->host_no, CTL_OF_SCB(scb), 8 * (0x01 << bus_width));
5480 } /* We fall through on purpose */
5481 case MSG_EXT_WDTR_BUS_8_BIT:
5484 * According to the spec, if we aren't wide, we also can't be
5485 * Dual Edge so clear the options byte
5487 new_trans_options = 0;
5488 new_bus_width = MSG_EXT_WDTR_BUS_8_BIT;
5489 break;
5493 if(reply)
5495 /* when sending a reply, make sure that the goal settings are
5496 * updated along with current and active since the code that
5497 * will actually build the message for the sequencer uses the
5498 * goal settings as its guidelines.
5500 aic7xxx_set_width(p, target, channel, lun, new_bus_width,
5501 AHC_TRANS_GOAL|AHC_TRANS_ACTIVE|AHC_TRANS_CUR,
5502 aic_dev);
5503 syncrate = aic7xxx_find_syncrate(p, &new_period, maxsync,
5504 &new_trans_options);
5505 aic7xxx_validate_offset(p, syncrate, &new_offset, new_bus_width);
5506 aic7xxx_set_syncrate(p, syncrate, target, channel, new_period,
5507 new_offset, new_trans_options,
5508 AHC_TRANS_GOAL|AHC_TRANS_ACTIVE|AHC_TRANS_CUR,
5509 aic_dev);
5511 else
5513 aic7xxx_set_width(p, target, channel, lun, new_bus_width,
5514 AHC_TRANS_ACTIVE|AHC_TRANS_CUR, aic_dev);
5515 syncrate = aic7xxx_find_syncrate(p, &new_period, maxsync,
5516 &new_trans_options);
5517 aic7xxx_validate_offset(p, syncrate, &new_offset, new_bus_width);
5518 aic7xxx_set_syncrate(p, syncrate, target, channel, new_period,
5519 new_offset, new_trans_options,
5520 AHC_TRANS_ACTIVE|AHC_TRANS_CUR, aic_dev);
5524 * As it turns out, if we don't *have* to have PPR messages, then
5525 * configure ourselves not to use them since that makes some
5526 * external drive chassis work (those chassis can't parse PPR
5527 * messages and they mangle the SCSI bus until you send a WDTR
5528 * and SDTR that they can understand).
5530 if(new_trans_options == 0)
5532 aic_dev->needppr = aic_dev->needppr_copy = 0;
5533 if(new_offset)
5535 aic_dev->needsdtr = aic_dev->needsdtr_copy = 1;
5537 if (new_bus_width)
5539 aic_dev->needwdtr = aic_dev->needwdtr_copy = 1;
5543 if((new_offset == 0) && (offset != 0))
5546 * Oops, the syncrate went to low for this card and we fell off
5547 * to async (should never happen with a device that uses PPR
5548 * messages, but have to be complete)
5550 reply = TRUE;
5553 if(reply)
5555 scb->flags &= ~SCB_MSGOUT_BITS;
5556 scb->flags |= SCB_MSGOUT_PPR;
5557 aic_outb(p, HOST_MSG, MSG_OUT);
5558 aic_outb(p, aic_inb(p, SCSISIGO) | ATNO, SCSISIGO);
5560 else
5562 aic_dev->needppr = 0;
5564 done = TRUE;
5565 break;
5567 default:
5569 reject = TRUE;
5570 break;
5572 } /* end of switch(p->msg_type) */
5573 } /* end of if (!reject && (p->msg_len > 2)) */
5575 if (!reply && reject)
5577 aic_outb(p, MSG_MESSAGE_REJECT, MSG_OUT);
5578 aic_outb(p, aic_inb(p, SCSISIGO) | ATNO, SCSISIGO);
5579 done = TRUE;
5581 return(done);
5585 /*+F*************************************************************************
5586 * Function:
5587 * aic7xxx_handle_reqinit
5589 * Description:
5590 * Interrupt handler for REQINIT interrupts (used to transfer messages to
5591 * and from devices).
5592 *_F*************************************************************************/
5593 static void
5594 aic7xxx_handle_reqinit(struct aic7xxx_host *p, struct aic7xxx_scb *scb)
5596 unsigned char lastbyte;
5597 unsigned char phasemis;
5598 int done = FALSE;
5600 switch(p->msg_type)
5602 case MSG_TYPE_INITIATOR_MSGOUT:
5604 if (p->msg_len == 0)
5605 panic("aic7xxx: REQINIT with no active message!\n");
5607 lastbyte = (p->msg_index == (p->msg_len - 1));
5608 phasemis = ( aic_inb(p, SCSISIGI) & PHASE_MASK) != P_MESGOUT;
5610 if (lastbyte || phasemis)
5612 /* Time to end the message */
5613 p->msg_len = 0;
5614 p->msg_type = MSG_TYPE_NONE;
5616 * NOTE-TO-MYSELF: If you clear the REQINIT after you
5617 * disable REQINITs, then cases of REJECT_MSG stop working
5618 * and hang the bus
5620 aic_outb(p, aic_inb(p, SIMODE1) & ~ENREQINIT, SIMODE1);
5621 aic_outb(p, CLRSCSIINT, CLRINT);
5622 p->flags &= ~AHC_HANDLING_REQINITS;
5624 if (phasemis == 0)
5626 aic_outb(p, p->msg_buf[p->msg_index], SINDEX);
5627 aic_outb(p, 0, RETURN_1);
5628 #ifdef AIC7XXX_VERBOSE_DEBUGGING
5629 if (aic7xxx_verbose > 0xffff)
5630 printk(INFO_LEAD "Completed sending of REQINIT message.\n",
5631 p->host_no, CTL_OF_SCB(scb));
5632 #endif
5634 else
5636 aic_outb(p, MSGOUT_PHASEMIS, RETURN_1);
5637 #ifdef AIC7XXX_VERBOSE_DEBUGGING
5638 if (aic7xxx_verbose > 0xffff)
5639 printk(INFO_LEAD "PHASEMIS while sending REQINIT message.\n",
5640 p->host_no, CTL_OF_SCB(scb));
5641 #endif
5643 unpause_sequencer(p, TRUE);
5645 else
5648 * Present the byte on the bus (clearing REQINIT) but don't
5649 * unpause the sequencer.
5651 aic_outb(p, CLRREQINIT, CLRSINT1);
5652 aic_outb(p, CLRSCSIINT, CLRINT);
5653 aic_outb(p, p->msg_buf[p->msg_index++], SCSIDATL);
5655 break;
5657 case MSG_TYPE_INITIATOR_MSGIN:
5659 phasemis = ( aic_inb(p, SCSISIGI) & PHASE_MASK ) != P_MESGIN;
5661 if (phasemis == 0)
5663 p->msg_len++;
5664 /* Pull the byte in without acking it */
5665 p->msg_buf[p->msg_index] = aic_inb(p, SCSIBUSL);
5666 done = aic7xxx_parse_msg(p, scb);
5667 /* Ack the byte */
5668 aic_outb(p, CLRREQINIT, CLRSINT1);
5669 aic_outb(p, CLRSCSIINT, CLRINT);
5670 aic_inb(p, SCSIDATL);
5671 p->msg_index++;
5673 if (phasemis || done)
5675 #ifdef AIC7XXX_VERBOSE_DEBUGGING
5676 if (aic7xxx_verbose > 0xffff)
5678 if (phasemis)
5679 printk(INFO_LEAD "PHASEMIS while receiving REQINIT message.\n",
5680 p->host_no, CTL_OF_SCB(scb));
5681 else
5682 printk(INFO_LEAD "Completed receipt of REQINIT message.\n",
5683 p->host_no, CTL_OF_SCB(scb));
5685 #endif
5686 /* Time to end our message session */
5687 p->msg_len = 0;
5688 p->msg_type = MSG_TYPE_NONE;
5689 aic_outb(p, aic_inb(p, SIMODE1) & ~ENREQINIT, SIMODE1);
5690 aic_outb(p, CLRSCSIINT, CLRINT);
5691 p->flags &= ~AHC_HANDLING_REQINITS;
5692 unpause_sequencer(p, TRUE);
5694 break;
5696 default:
5698 panic("aic7xxx: Unknown REQINIT message type.\n");
5699 break;
5701 } /* End of switch(p->msg_type) */
5704 /*+F*************************************************************************
5705 * Function:
5706 * aic7xxx_handle_scsiint
5708 * Description:
5709 * Interrupt handler for SCSI interrupts (SCSIINT).
5710 *-F*************************************************************************/
5711 static void
5712 aic7xxx_handle_scsiint(struct aic7xxx_host *p, unsigned char intstat)
5714 unsigned char scb_index;
5715 unsigned char status;
5716 struct aic7xxx_scb *scb;
5717 struct aic_dev_data *aic_dev;
5719 scb_index = aic_inb(p, SCB_TAG);
5720 status = aic_inb(p, SSTAT1);
5722 if (scb_index < p->scb_data->numscbs)
5724 scb = p->scb_data->scb_array[scb_index];
5725 if ((scb->flags & SCB_ACTIVE) == 0)
5727 scb = NULL;
5730 else
5732 scb = NULL;
5736 if ((status & SCSIRSTI) != 0)
5738 int channel;
5740 if ( (p->chip & AHC_CHIPID_MASK) == AHC_AIC7770 )
5741 channel = (aic_inb(p, SBLKCTL) & SELBUSB) >> 3;
5742 else
5743 channel = 0;
5745 if (aic7xxx_verbose & VERBOSE_RESET)
5746 printk(WARN_LEAD "Someone else reset the channel!!\n",
5747 p->host_no, channel, -1, -1);
5748 if (aic7xxx_panic_on_abort)
5749 aic7xxx_panic_abort(p, NULL);
5751 * Go through and abort all commands for the channel, but do not
5752 * reset the channel again.
5754 aic7xxx_reset_channel(p, channel, /* Initiate Reset */ FALSE);
5755 aic7xxx_run_done_queue(p, TRUE);
5756 scb = NULL;
5758 else if ( ((status & BUSFREE) != 0) && ((status & SELTO) == 0) )
5761 * First look at what phase we were last in. If it's message-out,
5762 * chances are pretty good that the bus free was in response to
5763 * one of our abort requests.
5765 unsigned char lastphase = aic_inb(p, LASTPHASE);
5766 unsigned char saved_tcl = aic_inb(p, SAVED_TCL);
5767 unsigned char target = (saved_tcl >> 4) & 0x0F;
5768 int channel;
5769 int printerror = TRUE;
5771 if ( (p->chip & AHC_CHIPID_MASK) == AHC_AIC7770 )
5772 channel = (aic_inb(p, SBLKCTL) & SELBUSB) >> 3;
5773 else
5774 channel = 0;
5776 aic_outb(p, aic_inb(p, SCSISEQ) & (ENSELI|ENRSELI|ENAUTOATNP),
5777 SCSISEQ);
5778 if (lastphase == P_MESGOUT)
5780 unsigned char message;
5782 message = aic_inb(p, SINDEX);
5784 if ((message == MSG_ABORT) || (message == MSG_ABORT_TAG))
5786 if (aic7xxx_verbose & VERBOSE_ABORT_PROCESS)
5787 printk(INFO_LEAD "SCB %d abort delivered.\n", p->host_no,
5788 CTL_OF_SCB(scb), scb->hscb->tag);
5789 aic7xxx_reset_device(p, target, channel, ALL_LUNS,
5790 (message == MSG_ABORT) ? SCB_LIST_NULL : scb->hscb->tag );
5791 aic7xxx_run_done_queue(p, TRUE);
5792 scb = NULL;
5793 printerror = 0;
5795 else if (message == MSG_BUS_DEV_RESET)
5797 aic7xxx_handle_device_reset(p, target, channel);
5798 scb = NULL;
5799 printerror = 0;
5802 if ( (scb != NULL) && (scb->flags & SCB_DTR_SCB) )
5805 * Hmmm...error during a negotiation command. Either we have a
5806 * borken bus, or the device doesn't like our negotiation message.
5807 * Since we check the INQUIRY data of a device before sending it
5808 * negotiation messages, assume the bus is borken for whatever
5809 * reason. Complete the command.
5811 printerror = 0;
5812 aic7xxx_reset_device(p, target, channel, ALL_LUNS, scb->hscb->tag);
5813 aic7xxx_run_done_queue(p, TRUE);
5814 scb = NULL;
5816 if (printerror != 0)
5818 if (scb != NULL)
5820 unsigned char tag;
5822 if ((scb->hscb->control & TAG_ENB) != 0)
5824 tag = scb->hscb->tag;
5826 else
5828 tag = SCB_LIST_NULL;
5830 aic7xxx_reset_device(p, target, channel, ALL_LUNS, tag);
5831 aic7xxx_run_done_queue(p, TRUE);
5833 else
5835 aic7xxx_reset_device(p, target, channel, ALL_LUNS, SCB_LIST_NULL);
5836 aic7xxx_run_done_queue(p, TRUE);
5838 printk(INFO_LEAD "Unexpected busfree, LASTPHASE = 0x%x, "
5839 "SEQADDR = 0x%x\n", p->host_no, channel, target, -1, lastphase,
5840 (aic_inb(p, SEQADDR1) << 8) | aic_inb(p, SEQADDR0));
5841 scb = NULL;
5843 aic_outb(p, MSG_NOOP, MSG_OUT);
5844 aic_outb(p, aic_inb(p, SIMODE1) & ~(ENBUSFREE|ENREQINIT),
5845 SIMODE1);
5846 p->flags &= ~AHC_HANDLING_REQINITS;
5847 aic_outb(p, CLRBUSFREE, CLRSINT1);
5848 aic_outb(p, CLRSCSIINT, CLRINT);
5849 restart_sequencer(p);
5850 unpause_sequencer(p, TRUE);
5852 else if ((status & SELTO) != 0)
5854 unsigned char scbptr;
5855 unsigned char nextscb;
5856 Scsi_Cmnd *cmd;
5858 scbptr = aic_inb(p, WAITING_SCBH);
5859 if (scbptr > p->scb_data->maxhscbs)
5862 * I'm still trying to track down exactly how this happens, but until
5863 * I find it, this code will make sure we aren't passing bogus values
5864 * into the SCBPTR register, even if that register will just wrap
5865 * things around, we still don't like having out of range variables.
5867 * NOTE: Don't check the aic7xxx_verbose variable, I want this message
5868 * to always be displayed.
5870 printk(INFO_LEAD "Invalid WAITING_SCBH value %d, improvising.\n",
5871 p->host_no, -1, -1, -1, scbptr);
5872 if (p->scb_data->maxhscbs > 4)
5873 scbptr &= (p->scb_data->maxhscbs - 1);
5874 else
5875 scbptr &= 0x03;
5877 aic_outb(p, scbptr, SCBPTR);
5878 scb_index = aic_inb(p, SCB_TAG);
5880 scb = NULL;
5881 if (scb_index < p->scb_data->numscbs)
5883 scb = p->scb_data->scb_array[scb_index];
5884 if ((scb->flags & SCB_ACTIVE) == 0)
5886 scb = NULL;
5889 if (scb == NULL)
5891 printk(WARN_LEAD "Referenced SCB %d not valid during SELTO.\n",
5892 p->host_no, -1, -1, -1, scb_index);
5893 printk(KERN_WARNING " SCSISEQ = 0x%x SEQADDR = 0x%x SSTAT0 = 0x%x "
5894 "SSTAT1 = 0x%x\n", aic_inb(p, SCSISEQ),
5895 aic_inb(p, SEQADDR0) | (aic_inb(p, SEQADDR1) << 8),
5896 aic_inb(p, SSTAT0), aic_inb(p, SSTAT1));
5897 if (aic7xxx_panic_on_abort)
5898 aic7xxx_panic_abort(p, NULL);
5900 else
5902 cmd = scb->cmd;
5903 cmd->result = (DID_TIME_OUT << 16);
5906 * Clear out this hardware SCB
5908 aic_outb(p, 0, SCB_CONTROL);
5911 * Clear out a few values in the card that are in an undetermined
5912 * state.
5914 aic_outb(p, MSG_NOOP, MSG_OUT);
5917 * Shift the waiting for selection queue forward
5919 nextscb = aic_inb(p, SCB_NEXT);
5920 aic_outb(p, nextscb, WAITING_SCBH);
5923 * Put this SCB back on the free list.
5925 aic7xxx_add_curscb_to_free_list(p);
5926 #ifdef AIC7XXX_VERBOSE_DEBUGGING
5927 if (aic7xxx_verbose > 0xffff)
5928 printk(INFO_LEAD "Selection Timeout.\n", p->host_no, CTL_OF_SCB(scb));
5929 #endif
5930 if (scb->flags & SCB_QUEUED_ABORT)
5933 * We know that this particular SCB had to be the queued abort since
5934 * the disconnected SCB would have gotten a reconnect instead.
5935 * What we need to do then is to let the command timeout again so
5936 * we get a reset since this abort just failed.
5938 cmd->result = 0;
5939 scb = NULL;
5943 * Keep the sequencer from trying to restart any selections
5945 aic_outb(p, aic_inb(p, SCSISEQ) & ~ENSELO, SCSISEQ);
5947 * Make sure the data bits on the bus are released
5948 * Don't do this on 7770 chipsets, it makes them give us
5949 * a BRKADDRINT and kills the card.
5951 if( (p->chip & ~AHC_CHIPID_MASK) == AHC_PCI )
5952 aic_outb(p, 0, SCSIBUSL);
5955 * Delay for the selection timeout delay period then stop the selection
5957 udelay(301);
5958 aic_outb(p, CLRSELINGO, CLRSINT0);
5960 * Clear out all the interrupt status bits
5962 aic_outb(p, aic_inb(p, SIMODE1) & ~(ENREQINIT|ENBUSFREE), SIMODE1);
5963 p->flags &= ~AHC_HANDLING_REQINITS;
5964 aic_outb(p, CLRSELTIMEO | CLRBUSFREE, CLRSINT1);
5965 aic_outb(p, CLRSCSIINT, CLRINT);
5967 * Restarting the sequencer will stop the selection and make sure devices
5968 * are allowed to reselect in.
5970 restart_sequencer(p);
5971 unpause_sequencer(p, TRUE);
5973 else if (scb == NULL)
5975 printk(WARN_LEAD "aic7xxx_isr - referenced scb not valid "
5976 "during scsiint 0x%x scb(%d)\n"
5977 " SIMODE0 0x%x, SIMODE1 0x%x, SSTAT0 0x%x, SEQADDR 0x%x\n",
5978 p->host_no, -1, -1, -1, status, scb_index, aic_inb(p, SIMODE0),
5979 aic_inb(p, SIMODE1), aic_inb(p, SSTAT0),
5980 (aic_inb(p, SEQADDR1) << 8) | aic_inb(p, SEQADDR0));
5982 * Turn off the interrupt and set status to zero, so that it
5983 * falls through the rest of the SCSIINT code.
5985 aic_outb(p, status, CLRSINT1);
5986 aic_outb(p, CLRSCSIINT, CLRINT);
5987 unpause_sequencer(p, /* unpause always */ TRUE);
5988 scb = NULL;
5990 else if (status & SCSIPERR)
5993 * Determine the bus phase and queue an appropriate message.
5995 char *phase;
5996 Scsi_Cmnd *cmd;
5997 unsigned char mesg_out = MSG_NOOP;
5998 unsigned char lastphase = aic_inb(p, LASTPHASE);
5999 unsigned char sstat2 = aic_inb(p, SSTAT2);
6001 cmd = scb->cmd;
6002 switch (lastphase)
6004 case P_DATAOUT:
6005 phase = "Data-Out";
6006 break;
6007 case P_DATAIN:
6008 phase = "Data-In";
6009 mesg_out = MSG_INITIATOR_DET_ERR;
6010 break;
6011 case P_COMMAND:
6012 phase = "Command";
6013 break;
6014 case P_MESGOUT:
6015 phase = "Message-Out";
6016 break;
6017 case P_STATUS:
6018 phase = "Status";
6019 mesg_out = MSG_INITIATOR_DET_ERR;
6020 break;
6021 case P_MESGIN:
6022 phase = "Message-In";
6023 mesg_out = MSG_PARITY_ERROR;
6024 break;
6025 default:
6026 phase = "unknown";
6027 break;
6031 * A parity error has occurred during a data
6032 * transfer phase. Flag it and continue.
6034 if( (p->features & AHC_ULTRA3) &&
6035 (aic_inb(p, SCSIRATE) & AHC_SYNCRATE_CRC) &&
6036 (lastphase == P_DATAIN) )
6038 printk(WARN_LEAD "CRC error during %s phase.\n",
6039 p->host_no, CTL_OF_SCB(scb), phase);
6040 if(sstat2 & CRCVALERR)
6042 printk(WARN_LEAD " CRC error in intermediate CRC packet.\n",
6043 p->host_no, CTL_OF_SCB(scb));
6045 if(sstat2 & CRCENDERR)
6047 printk(WARN_LEAD " CRC error in ending CRC packet.\n",
6048 p->host_no, CTL_OF_SCB(scb));
6050 if(sstat2 & CRCREQERR)
6052 printk(WARN_LEAD " Target incorrectly requested a CRC packet.\n",
6053 p->host_no, CTL_OF_SCB(scb));
6055 if(sstat2 & DUAL_EDGE_ERROR)
6057 printk(WARN_LEAD " Dual Edge transmission error.\n",
6058 p->host_no, CTL_OF_SCB(scb));
6061 else if( (lastphase == P_MESGOUT) &&
6062 (scb->flags & SCB_MSGOUT_PPR) )
6065 * As per the draft specs, any device capable of supporting any of
6066 * the option values other than 0 are not allowed to reject the
6067 * PPR message. Instead, they must negotiate out what they do
6068 * support instead of rejecting our offering or else they cause
6069 * a parity error during msg_out phase to signal that they don't
6070 * like our settings.
6072 aic_dev = AIC_DEV(scb->cmd);
6073 aic_dev->needppr = aic_dev->needppr_copy = 0;
6074 aic7xxx_set_width(p, scb->cmd->target, scb->cmd->channel, scb->cmd->lun,
6075 MSG_EXT_WDTR_BUS_8_BIT,
6076 (AHC_TRANS_ACTIVE|AHC_TRANS_CUR|AHC_TRANS_QUITE),
6077 aic_dev);
6078 aic7xxx_set_syncrate(p, NULL, scb->cmd->target, scb->cmd->channel, 0, 0,
6079 0, AHC_TRANS_ACTIVE|AHC_TRANS_CUR|AHC_TRANS_QUITE,
6080 aic_dev);
6081 aic_dev->goal.options = 0;
6082 scb->flags &= ~SCB_MSGOUT_BITS;
6083 if(aic7xxx_verbose & VERBOSE_NEGOTIATION2)
6085 printk(INFO_LEAD "parity error during PPR message, reverting "
6086 "to WDTR/SDTR\n", p->host_no, CTL_OF_SCB(scb));
6088 if ( aic_dev->goal.width )
6090 aic_dev->needwdtr = aic_dev->needwdtr_copy = 1;
6092 if ( aic_dev->goal.offset )
6094 if( aic_dev->goal.period <= 9 )
6096 aic_dev->goal.period = 10;
6098 aic_dev->needsdtr = aic_dev->needsdtr_copy = 1;
6100 scb = NULL;
6104 * We've set the hardware to assert ATN if we get a parity
6105 * error on "in" phases, so all we need to do is stuff the
6106 * message buffer with the appropriate message. "In" phases
6107 * have set mesg_out to something other than MSG_NOP.
6109 if (mesg_out != MSG_NOOP)
6111 aic_outb(p, mesg_out, MSG_OUT);
6112 aic_outb(p, aic_inb(p, SCSISIGI) | ATNO, SCSISIGO);
6113 scb = NULL;
6115 aic_outb(p, CLRSCSIPERR, CLRSINT1);
6116 aic_outb(p, CLRSCSIINT, CLRINT);
6117 unpause_sequencer(p, /* unpause_always */ TRUE);
6119 else if ( (status & REQINIT) &&
6120 (p->flags & AHC_HANDLING_REQINITS) )
6122 #ifdef AIC7XXX_VERBOSE_DEBUGGING
6123 if (aic7xxx_verbose > 0xffff)
6124 printk(INFO_LEAD "Handling REQINIT, SSTAT1=0x%x.\n", p->host_no,
6125 CTL_OF_SCB(scb), aic_inb(p, SSTAT1));
6126 #endif
6127 aic7xxx_handle_reqinit(p, scb);
6128 return;
6130 else
6133 * We don't know what's going on. Turn off the
6134 * interrupt source and try to continue.
6136 if (aic7xxx_verbose & VERBOSE_SCSIINT)
6137 printk(INFO_LEAD "Unknown SCSIINT status, SSTAT1(0x%x).\n",
6138 p->host_no, -1, -1, -1, status);
6139 aic_outb(p, status, CLRSINT1);
6140 aic_outb(p, CLRSCSIINT, CLRINT);
6141 unpause_sequencer(p, /* unpause always */ TRUE);
6142 scb = NULL;
6144 if (scb != NULL)
6146 aic7xxx_done(p, scb);
6150 #ifdef AIC7XXX_VERBOSE_DEBUGGING
6151 static void
6152 aic7xxx_check_scbs(struct aic7xxx_host *p, char *buffer)
6154 unsigned char saved_scbptr, free_scbh, dis_scbh, wait_scbh, temp;
6155 int i, bogus, lost;
6156 static unsigned char scb_status[AIC7XXX_MAXSCB];
6158 #define SCB_NO_LIST 0
6159 #define SCB_FREE_LIST 1
6160 #define SCB_WAITING_LIST 2
6161 #define SCB_DISCONNECTED_LIST 4
6162 #define SCB_CURRENTLY_ACTIVE 8
6165 * Note, these checks will fail on a regular basis once the machine moves
6166 * beyond the bus scan phase. The problem is race conditions concerning
6167 * the scbs and where they are linked in. When you have 30 or so commands
6168 * outstanding on the bus, and run this twice with every interrupt, the
6169 * chances get pretty good that you'll catch the sequencer with an SCB
6170 * only partially linked in. Therefore, once we pass the scan phase
6171 * of the bus, we really should disable this function.
6173 bogus = FALSE;
6174 memset(&scb_status[0], 0, sizeof(scb_status));
6175 pause_sequencer(p);
6176 saved_scbptr = aic_inb(p, SCBPTR);
6177 if (saved_scbptr >= p->scb_data->maxhscbs)
6179 printk("Bogus SCBPTR %d\n", saved_scbptr);
6180 bogus = TRUE;
6182 scb_status[saved_scbptr] = SCB_CURRENTLY_ACTIVE;
6183 free_scbh = aic_inb(p, FREE_SCBH);
6184 if ( (free_scbh != SCB_LIST_NULL) &&
6185 (free_scbh >= p->scb_data->maxhscbs) )
6187 printk("Bogus FREE_SCBH %d\n", free_scbh);
6188 bogus = TRUE;
6190 else
6192 temp = free_scbh;
6193 while( (temp != SCB_LIST_NULL) && (temp < p->scb_data->maxhscbs) )
6195 if(scb_status[temp] & 0x07)
6197 printk("HSCB %d on multiple lists, status 0x%02x", temp,
6198 scb_status[temp] | SCB_FREE_LIST);
6199 bogus = TRUE;
6201 scb_status[temp] |= SCB_FREE_LIST;
6202 aic_outb(p, temp, SCBPTR);
6203 temp = aic_inb(p, SCB_NEXT);
6207 dis_scbh = aic_inb(p, DISCONNECTED_SCBH);
6208 if ( (dis_scbh != SCB_LIST_NULL) &&
6209 (dis_scbh >= p->scb_data->maxhscbs) )
6211 printk("Bogus DISCONNECTED_SCBH %d\n", dis_scbh);
6212 bogus = TRUE;
6214 else
6216 temp = dis_scbh;
6217 while( (temp != SCB_LIST_NULL) && (temp < p->scb_data->maxhscbs) )
6219 if(scb_status[temp] & 0x07)
6221 printk("HSCB %d on multiple lists, status 0x%02x", temp,
6222 scb_status[temp] | SCB_DISCONNECTED_LIST);
6223 bogus = TRUE;
6225 scb_status[temp] |= SCB_DISCONNECTED_LIST;
6226 aic_outb(p, temp, SCBPTR);
6227 temp = aic_inb(p, SCB_NEXT);
6231 wait_scbh = aic_inb(p, WAITING_SCBH);
6232 if ( (wait_scbh != SCB_LIST_NULL) &&
6233 (wait_scbh >= p->scb_data->maxhscbs) )
6235 printk("Bogus WAITING_SCBH %d\n", wait_scbh);
6236 bogus = TRUE;
6238 else
6240 temp = wait_scbh;
6241 while( (temp != SCB_LIST_NULL) && (temp < p->scb_data->maxhscbs) )
6243 if(scb_status[temp] & 0x07)
6245 printk("HSCB %d on multiple lists, status 0x%02x", temp,
6246 scb_status[temp] | SCB_WAITING_LIST);
6247 bogus = TRUE;
6249 scb_status[temp] |= SCB_WAITING_LIST;
6250 aic_outb(p, temp, SCBPTR);
6251 temp = aic_inb(p, SCB_NEXT);
6255 lost=0;
6256 for(i=0; i < p->scb_data->maxhscbs; i++)
6258 aic_outb(p, i, SCBPTR);
6259 temp = aic_inb(p, SCB_NEXT);
6260 if ( ((temp != SCB_LIST_NULL) &&
6261 (temp >= p->scb_data->maxhscbs)) )
6263 printk("HSCB %d bad, SCB_NEXT invalid(%d).\n", i, temp);
6264 bogus = TRUE;
6266 if ( temp == i )
6268 printk("HSCB %d bad, SCB_NEXT points to self.\n", i);
6269 bogus = TRUE;
6271 if (scb_status[i] == 0)
6272 lost++;
6273 if (lost > 1)
6275 printk("Too many lost scbs.\n");
6276 bogus=TRUE;
6279 aic_outb(p, saved_scbptr, SCBPTR);
6280 unpause_sequencer(p, FALSE);
6281 if (bogus)
6283 printk("Bogus parameters found in card SCB array structures.\n");
6284 printk("%s\n", buffer);
6285 aic7xxx_panic_abort(p, NULL);
6287 return;
6289 #endif
6292 /*+F*************************************************************************
6293 * Function:
6294 * aic7xxx_handle_command_completion_intr
6296 * Description:
6297 * SCSI command completion interrupt handler.
6298 *-F*************************************************************************/
6299 static void
6300 aic7xxx_handle_command_completion_intr(struct aic7xxx_host *p)
6302 struct aic7xxx_scb *scb = NULL;
6303 struct aic_dev_data *aic_dev;
6304 Scsi_Cmnd *cmd;
6305 unsigned char scb_index, tindex;
6307 #ifdef AIC7XXX_VERBOSE_DEBUGGING
6308 if( (p->isr_count < 16) && (aic7xxx_verbose > 0xffff) )
6309 printk(INFO_LEAD "Command Complete Int.\n", p->host_no, -1, -1, -1);
6310 #endif
6313 * Read the INTSTAT location after clearing the CMDINT bit. This forces
6314 * any posted PCI writes to flush to memory. Gerard Roudier suggested
6315 * this fix to the possible race of clearing the CMDINT bit but not
6316 * having all command bytes flushed onto the qoutfifo.
6318 aic_outb(p, CLRCMDINT, CLRINT);
6319 aic_inb(p, INTSTAT);
6321 * The sequencer will continue running when it
6322 * issues this interrupt. There may be >1 commands
6323 * finished, so loop until we've processed them all.
6326 while (p->qoutfifo[p->qoutfifonext] != SCB_LIST_NULL)
6328 scb_index = p->qoutfifo[p->qoutfifonext];
6329 p->qoutfifo[p->qoutfifonext++] = SCB_LIST_NULL;
6330 if ( scb_index >= p->scb_data->numscbs )
6332 printk(WARN_LEAD "CMDCMPLT with invalid SCB index %d\n", p->host_no,
6333 -1, -1, -1, scb_index);
6334 continue;
6336 scb = p->scb_data->scb_array[scb_index];
6337 if (!(scb->flags & SCB_ACTIVE) || (scb->cmd == NULL))
6339 printk(WARN_LEAD "CMDCMPLT without command for SCB %d, SCB flags "
6340 "0x%x, cmd 0x%lx\n", p->host_no, -1, -1, -1, scb_index, scb->flags,
6341 (unsigned long) scb->cmd);
6342 continue;
6344 tindex = TARGET_INDEX(scb->cmd);
6345 aic_dev = AIC_DEV(scb->cmd);
6346 if (scb->flags & SCB_QUEUED_ABORT)
6348 pause_sequencer(p);
6349 if ( ((aic_inb(p, LASTPHASE) & PHASE_MASK) != P_BUSFREE) &&
6350 (aic_inb(p, SCB_TAG) == scb->hscb->tag) )
6352 unpause_sequencer(p, FALSE);
6353 continue;
6355 aic7xxx_reset_device(p, scb->cmd->target, scb->cmd->channel,
6356 scb->cmd->lun, scb->hscb->tag);
6357 scb->flags &= ~(SCB_QUEUED_FOR_DONE | SCB_RESET | SCB_ABORT |
6358 SCB_QUEUED_ABORT);
6359 unpause_sequencer(p, FALSE);
6361 else if (scb->flags & SCB_ABORT)
6364 * We started to abort this, but it completed on us, let it
6365 * through as successful
6367 scb->flags &= ~(SCB_ABORT|SCB_RESET);
6369 else if (scb->flags & SCB_SENSE)
6371 char *buffer = &scb->cmd->sense_buffer[0];
6373 if (buffer[12] == 0x47 || buffer[12] == 0x54)
6376 * Signal that we need to re-negotiate things.
6378 aic_dev->needppr = aic_dev->needppr_copy;
6379 aic_dev->needsdtr = aic_dev->needsdtr_copy;
6380 aic_dev->needwdtr = aic_dev->needwdtr_copy;
6383 cmd = scb->cmd;
6384 if (scb->hscb->residual_SG_segment_count != 0)
6386 aic7xxx_calculate_residual(p, scb);
6388 cmd->result |= (aic7xxx_error(cmd) << 16);
6389 aic7xxx_done(p, scb);
6393 /*+F*************************************************************************
6394 * Function:
6395 * aic7xxx_isr
6397 * Description:
6398 * SCSI controller interrupt handler.
6399 *-F*************************************************************************/
6400 static void
6401 aic7xxx_isr(int irq, void *dev_id, struct pt_regs *regs)
6403 struct aic7xxx_host *p;
6404 unsigned char intstat;
6406 p = (struct aic7xxx_host *)dev_id;
6409 * Just a few sanity checks. Make sure that we have an int pending.
6410 * Also, if PCI, then we are going to check for a PCI bus error status
6411 * should we get too many spurious interrupts.
6413 if (!((intstat = aic_inb(p, INTSTAT)) & INT_PEND))
6415 #ifdef CONFIG_PCI
6416 if ( (p->chip & AHC_PCI) && (p->spurious_int > 500) &&
6417 !(p->flags & AHC_HANDLING_REQINITS) )
6419 if ( aic_inb(p, ERROR) & PCIERRSTAT )
6421 aic7xxx_pci_intr(p);
6423 p->spurious_int = 0;
6425 else if ( !(p->flags & AHC_HANDLING_REQINITS) )
6427 p->spurious_int++;
6429 #endif
6430 return;
6433 p->spurious_int = 0;
6436 * Keep track of interrupts for /proc/scsi
6438 p->isr_count++;
6440 #ifdef AIC7XXX_VERBOSE_DEBUGGING
6441 if ( (p->isr_count < 16) && (aic7xxx_verbose > 0xffff) &&
6442 (aic7xxx_panic_on_abort) && (p->flags & AHC_PAGESCBS) )
6443 aic7xxx_check_scbs(p, "Bogus settings at start of interrupt.");
6444 #endif
6447 * Handle all the interrupt sources - especially for SCSI
6448 * interrupts, we won't get a second chance at them.
6450 if (intstat & CMDCMPLT)
6452 aic7xxx_handle_command_completion_intr(p);
6455 if (intstat & BRKADRINT)
6457 int i;
6458 unsigned char errno = aic_inb(p, ERROR);
6460 printk(KERN_ERR "(scsi%d) BRKADRINT error(0x%x):\n", p->host_no, errno);
6461 for (i = 0; i < NUMBER(hard_error); i++)
6463 if (errno & hard_error[i].errno)
6465 printk(KERN_ERR " %s\n", hard_error[i].errmesg);
6468 printk(KERN_ERR "(scsi%d) SEQADDR=0x%x\n", p->host_no,
6469 (((aic_inb(p, SEQADDR1) << 8) & 0x100) | aic_inb(p, SEQADDR0)));
6470 if (aic7xxx_panic_on_abort)
6471 aic7xxx_panic_abort(p, NULL);
6472 #ifdef CONFIG_PCI
6473 if (errno & PCIERRSTAT)
6474 aic7xxx_pci_intr(p);
6475 #endif
6476 if (errno & (SQPARERR | ILLOPCODE | ILLSADDR))
6478 panic("aic7xxx: unrecoverable BRKADRINT.\n");
6480 if (errno & ILLHADDR)
6482 printk(KERN_ERR "(scsi%d) BUG! Driver accessed chip without first "
6483 "pausing controller!\n", p->host_no);
6485 #ifdef AIC7XXX_VERBOSE_DEBUGGING
6486 if (errno & DPARERR)
6488 if (aic_inb(p, DMAPARAMS) & DIRECTION)
6489 printk("(scsi%d) while DMAing SCB from host to card.\n", p->host_no);
6490 else
6491 printk("(scsi%d) while DMAing SCB from card to host.\n", p->host_no);
6493 #endif
6494 aic_outb(p, CLRPARERR | CLRBRKADRINT, CLRINT);
6495 unpause_sequencer(p, FALSE);
6498 if (intstat & SEQINT)
6501 * Read the CCSCBCTL register to work around a bug in the Ultra2 cards
6503 if(p->features & AHC_ULTRA2)
6505 aic_inb(p, CCSCBCTL);
6507 aic7xxx_handle_seqint(p, intstat);
6510 if (intstat & SCSIINT)
6512 aic7xxx_handle_scsiint(p, intstat);
6515 #ifdef AIC7XXX_VERBOSE_DEBUGGING
6516 if ( (p->isr_count < 16) && (aic7xxx_verbose > 0xffff) &&
6517 (aic7xxx_panic_on_abort) && (p->flags & AHC_PAGESCBS) )
6518 aic7xxx_check_scbs(p, "Bogus settings at end of interrupt.");
6519 #endif
6523 /*+F*************************************************************************
6524 * Function:
6525 * do_aic7xxx_isr
6527 * Description:
6528 * This is a gross hack to solve a problem in linux kernels 2.1.85 and
6529 * above. Please, children, do not try this at home, and if you ever see
6530 * anything like it, please inform the Gross Hack Police immediately
6531 *-F*************************************************************************/
6532 static void
6533 do_aic7xxx_isr(int irq, void *dev_id, struct pt_regs *regs)
6535 unsigned long cpu_flags;
6536 struct aic7xxx_host *p;
6538 p = (struct aic7xxx_host *)dev_id;
6539 if(!p)
6540 return;
6541 spin_lock_irqsave(p->host->host_lock, cpu_flags);
6542 p->flags |= AHC_IN_ISR;
6545 aic7xxx_isr(irq, dev_id, regs);
6546 } while ( (aic_inb(p, INTSTAT) & INT_PEND) );
6547 aic7xxx_done_cmds_complete(p);
6548 aic7xxx_run_waiting_queues(p);
6549 p->flags &= ~AHC_IN_ISR;
6550 spin_unlock_irqrestore(p->host->host_lock, cpu_flags);
6553 /*+F*************************************************************************
6554 * Function:
6555 * aic7xxx_init_transinfo
6557 * Description:
6558 * Set up the initial aic_dev values from the BIOS settings and from
6559 * INQUIRY results
6560 *-F*************************************************************************/
6561 static void
6562 aic7xxx_init_transinfo(struct aic7xxx_host *p, struct aic_dev_data *aic_dev)
6564 Scsi_Device *sdpnt = aic_dev->SDptr;
6565 unsigned char tindex;
6567 tindex = sdpnt->id | (sdpnt->channel << 3);
6568 if (!(aic_dev->flags & DEVICE_DTR_SCANNED))
6570 aic_dev->flags |= DEVICE_DTR_SCANNED;
6572 if ( sdpnt->wdtr && (p->features & AHC_WIDE) )
6574 aic_dev->needwdtr = aic_dev->needwdtr_copy = 1;
6575 aic_dev->goal.width = p->user[tindex].width;
6577 else
6579 aic_dev->needwdtr = aic_dev->needwdtr_copy = 0;
6580 pause_sequencer(p);
6581 aic7xxx_set_width(p, sdpnt->id, sdpnt->channel, sdpnt->lun,
6582 MSG_EXT_WDTR_BUS_8_BIT, (AHC_TRANS_ACTIVE |
6583 AHC_TRANS_GOAL |
6584 AHC_TRANS_CUR), aic_dev );
6585 unpause_sequencer(p, FALSE);
6587 if ( sdpnt->sdtr && p->user[tindex].offset )
6589 aic_dev->goal.period = p->user[tindex].period;
6590 aic_dev->goal.options = p->user[tindex].options;
6591 if (p->features & AHC_ULTRA2)
6592 aic_dev->goal.offset = MAX_OFFSET_ULTRA2;
6593 else if (aic_dev->goal.width == MSG_EXT_WDTR_BUS_16_BIT)
6594 aic_dev->goal.offset = MAX_OFFSET_16BIT;
6595 else
6596 aic_dev->goal.offset = MAX_OFFSET_8BIT;
6597 if ( sdpnt->ppr && p->user[tindex].period <= 9 &&
6598 p->user[tindex].options )
6600 aic_dev->needppr = aic_dev->needppr_copy = 1;
6601 aic_dev->needsdtr = aic_dev->needsdtr_copy = 0;
6602 aic_dev->needwdtr = aic_dev->needwdtr_copy = 0;
6603 aic_dev->flags |= DEVICE_SCSI_3;
6605 else
6607 aic_dev->needsdtr = aic_dev->needsdtr_copy = 1;
6608 aic_dev->goal.period = MAX(10, aic_dev->goal.period);
6609 aic_dev->goal.options = 0;
6612 else
6614 aic_dev->needsdtr = aic_dev->needsdtr_copy = 0;
6615 aic_dev->goal.period = 255;
6616 aic_dev->goal.offset = 0;
6617 aic_dev->goal.options = 0;
6619 aic_dev->flags |= DEVICE_PRINT_DTR;
6623 /*+F*************************************************************************
6624 * Function:
6625 * aic7xxx_alloc_aic_dev
6627 * Description:
6628 * Set up the initial aic_dev struct pointers
6629 *-F*************************************************************************/
6630 static struct aic_dev_data *
6631 aic7xxx_alloc_aic_dev(struct aic7xxx_host *p, Scsi_Device *SDptr)
6633 struct aic_dev_data *aic_dev;
6635 aic_dev = kmalloc(sizeof(struct aic_dev_data), GFP_ATOMIC | GFP_KERNEL);
6636 if(!aic_dev)
6637 return aic_dev;
6638 memset(aic_dev, 0, sizeof(struct aic_dev_data));
6639 SDptr->hostdata = aic_dev;
6640 aic_dev->SDptr = SDptr;
6641 aic_dev->max_q_depth = 1;
6642 aic_dev->temp_q_depth = 1;
6643 scbq_init(&aic_dev->delayed_scbs);
6644 INIT_LIST_HEAD(&aic_dev->list);
6645 return aic_dev;
6648 /*+F*************************************************************************
6649 * Function:
6650 * aic7xxx_device_queue_depth
6652 * Description:
6653 * Determines the queue depth for a given device. There are two ways
6654 * a queue depth can be obtained for a tagged queueing device. One
6655 * way is the default queue depth which is determined by whether
6656 * aic7xxx_default_queue_depth. The other is by the aic7xxx_tag_info
6657 * array.
6659 * If tagged queueing isn't supported on the device, then we set the
6660 * depth to p->host->hostt->cmd_per_lun for internal driver queueing.
6661 * as the default queue depth. Otherwise, we use either 4 or 8 as the
6662 * default queue depth (dependent on the number of hardware SCBs).
6663 * The other way we determine queue depth is through the use of the
6664 * aic7xxx_tag_info array which is enabled by defining
6665 * AIC7XXX_TAGGED_QUEUEING_BY_DEVICE. This array can be initialized
6666 * with queue depths for individual devices. It also allows tagged
6667 * queueing to be [en|dis]abled for a specific adapter.
6668 *-F*************************************************************************/
6669 static void
6670 aic7xxx_device_queue_depth(struct aic7xxx_host *p, Scsi_Device *device)
6672 int tag_enabled = FALSE;
6673 struct aic_dev_data *aic_dev = device->hostdata;
6674 unsigned char tindex;
6676 tindex = device->id | (device->channel << 3);
6678 if (device->simple_tags)
6679 return; // We've already enabled this device
6681 if (device->tagged_supported)
6683 tag_enabled = TRUE;
6685 if (!(p->discenable & (1 << tindex)))
6687 if (aic7xxx_verbose & VERBOSE_NEGOTIATION2)
6688 printk(INFO_LEAD "Disconnection disabled, unable to "
6689 "enable tagged queueing.\n",
6690 p->host_no, device->channel, device->id, device->lun);
6691 tag_enabled = FALSE;
6693 else
6695 if (p->instance >= NUMBER(aic7xxx_tag_info))
6697 static int print_warning = TRUE;
6698 if(print_warning)
6700 printk(KERN_INFO "aic7xxx: WARNING, insufficient tag_info instances for"
6701 " installed controllers.\n");
6702 printk(KERN_INFO "aic7xxx: Please update the aic7xxx_tag_info array in"
6703 " the aic7xxx.c source file.\n");
6704 print_warning = FALSE;
6706 aic_dev->max_q_depth = aic_dev->temp_q_depth =
6707 aic7xxx_default_queue_depth;
6709 else
6712 if (aic7xxx_tag_info[p->instance].tag_commands[tindex] == 255)
6714 tag_enabled = FALSE;
6716 else if (aic7xxx_tag_info[p->instance].tag_commands[tindex] == 0)
6718 aic_dev->max_q_depth = aic_dev->temp_q_depth =
6719 aic7xxx_default_queue_depth;
6721 else
6723 aic_dev->max_q_depth = aic_dev->temp_q_depth =
6724 aic7xxx_tag_info[p->instance].tag_commands[tindex];
6729 if (tag_enabled)
6731 if (aic7xxx_verbose & VERBOSE_NEGOTIATION2)
6733 printk(INFO_LEAD "Tagged queuing enabled, queue depth %d.\n",
6734 p->host_no, device->channel, device->id,
6735 device->lun, aic_dev->max_q_depth);
6737 scsi_adjust_queue_depth(device, MSG_ORDERED_TAG, aic_dev->max_q_depth);
6739 else
6741 if (aic7xxx_verbose & VERBOSE_NEGOTIATION2)
6743 printk(INFO_LEAD "Tagged queuing disabled, queue depth %d.\n",
6744 p->host_no, device->channel, device->id,
6745 device->lun, device->host->cmd_per_lun);
6747 scsi_adjust_queue_depth(device, 0, device->host->cmd_per_lun);
6749 return;
6752 /*+F*************************************************************************
6753 * Function:
6754 * aic7xxx_slave_detach
6756 * Description:
6757 * prepare for this device to go away
6758 *-F*************************************************************************/
6759 void
6760 aic7xxx_slave_detach(Scsi_Device *sdpnt)
6762 struct aic_dev_data *aic_dev = sdpnt->hostdata;
6764 list_del(&aic_dev->list);
6765 sdpnt->hostdata = NULL;
6766 kfree(aic_dev);
6767 return;
6770 /*+F*************************************************************************
6771 * Function:
6772 * aic7xxx_slave_attach
6774 * Description:
6775 * Configure the device we are attaching to the controller. This is
6776 * where we get to do things like scan the INQUIRY data, set queue
6777 * depths, allocate command structs, etc.
6778 *-F*************************************************************************/
6780 aic7xxx_slave_attach(Scsi_Device *sdpnt)
6782 struct aic7xxx_host *p = (struct aic7xxx_host *) sdpnt->host->hostdata;
6783 struct aic_dev_data *aic_dev;
6784 int scbnum;
6786 aic_dev = (struct aic_dev_data *)sdpnt->hostdata;
6788 if(!aic_dev) {
6789 aic_dev = aic7xxx_alloc_aic_dev(p, sdpnt);
6791 if(!aic_dev)
6792 return 1;
6794 aic7xxx_init_transinfo(p, aic_dev);
6795 aic7xxx_device_queue_depth(p, sdpnt);
6796 if(list_empty(&aic_dev->list))
6797 list_add_tail(&aic_dev->list, &p->aic_devs);
6799 scbnum = 0;
6800 list_for_each_entry(aic_dev, &p->aic_devs, list) {
6801 scbnum += aic_dev->max_q_depth;
6803 while (scbnum > p->scb_data->numscbs)
6806 * Pre-allocate the needed SCBs to get around the possibility of having
6807 * to allocate some when memory is more or less exhausted and we need
6808 * the SCB in order to perform a swap operation (possible deadlock)
6810 if ( aic7xxx_allocate_scb(p) == 0 )
6811 break;
6815 return(0);
6818 /*+F*************************************************************************
6819 * Function:
6820 * aic7xxx_probe
6822 * Description:
6823 * Probing for EISA boards: it looks like the first two bytes
6824 * are a manufacturer code - three characters, five bits each:
6826 * BYTE 0 BYTE 1 BYTE 2 BYTE 3
6827 * ?1111122 22233333 PPPPPPPP RRRRRRRR
6829 * The characters are baselined off ASCII '@', so add that value
6830 * to each to get the real ASCII code for it. The next two bytes
6831 * appear to be a product and revision number, probably vendor-
6832 * specific. This is what is being searched for at each port,
6833 * and what should probably correspond to the ID= field in the
6834 * ECU's .cfg file for the card - if your card is not detected,
6835 * make sure your signature is listed in the array.
6837 * The fourth byte's lowest bit seems to be an enabled/disabled
6838 * flag (rest of the bits are reserved?).
6840 * NOTE: This function is only needed on Intel and Alpha platforms,
6841 * the other platforms we support don't have EISA/VLB busses. So,
6842 * we #ifdef this entire function to avoid compiler warnings about
6843 * an unused function.
6844 *-F*************************************************************************/
6845 #if defined(__i386__) || defined(__alpha__)
6846 static int
6847 aic7xxx_probe(int slot, int base, ahc_flag_type *flags)
6849 int i;
6850 unsigned char buf[4];
6852 static struct {
6853 int n;
6854 unsigned char signature[sizeof(buf)];
6855 ahc_chip type;
6856 int bios_disabled;
6857 } AIC7xxx[] = {
6858 { 4, { 0x04, 0x90, 0x77, 0x70 },
6859 AHC_AIC7770|AHC_EISA, FALSE }, /* mb 7770 */
6860 { 4, { 0x04, 0x90, 0x77, 0x71 },
6861 AHC_AIC7770|AHC_EISA, FALSE }, /* host adapter 274x */
6862 { 4, { 0x04, 0x90, 0x77, 0x56 },
6863 AHC_AIC7770|AHC_VL, FALSE }, /* 284x BIOS enabled */
6864 { 4, { 0x04, 0x90, 0x77, 0x57 },
6865 AHC_AIC7770|AHC_VL, TRUE } /* 284x BIOS disabled */
6869 * The VL-bus cards need to be primed by
6870 * writing before a signature check.
6872 for (i = 0; i < sizeof(buf); i++)
6874 outb(0x80 + i, base);
6875 buf[i] = inb(base + i);
6878 for (i = 0; i < NUMBER(AIC7xxx); i++)
6881 * Signature match on enabled card?
6883 if (!memcmp(buf, AIC7xxx[i].signature, AIC7xxx[i].n))
6885 if (inb(base + 4) & 1)
6887 if (AIC7xxx[i].bios_disabled)
6889 *flags |= AHC_USEDEFAULTS;
6891 else
6893 *flags |= AHC_BIOS_ENABLED;
6895 return (i);
6898 printk("aic7xxx: <Adaptec 7770 SCSI Host Adapter> "
6899 "disabled at slot %d, ignored.\n", slot);
6903 return (-1);
6905 #endif /* (__i386__) || (__alpha__) */
6908 /*+F*************************************************************************
6909 * Function:
6910 * read_2840_seeprom
6912 * Description:
6913 * Reads the 2840 serial EEPROM and returns 1 if successful and 0 if
6914 * not successful.
6916 * See read_seeprom (for the 2940) for the instruction set of the 93C46
6917 * chip.
6919 * The 2840 interface to the 93C46 serial EEPROM is through the
6920 * STATUS_2840 and SEECTL_2840 registers. The CS_2840, CK_2840, and
6921 * DO_2840 bits of the SEECTL_2840 register are connected to the chip
6922 * select, clock, and data out lines respectively of the serial EEPROM.
6923 * The DI_2840 bit of the STATUS_2840 is connected to the data in line
6924 * of the serial EEPROM. The EEPROM_TF bit of STATUS_2840 register is
6925 * useful in that it gives us an 800 nsec timer. After a read from the
6926 * SEECTL_2840 register the timing flag is cleared and goes high 800 nsec
6927 * later.
6928 *-F*************************************************************************/
6929 static int
6930 read_284x_seeprom(struct aic7xxx_host *p, struct seeprom_config *sc)
6932 int i = 0, k = 0;
6933 unsigned char temp;
6934 unsigned short checksum = 0;
6935 unsigned short *seeprom = (unsigned short *) sc;
6936 struct seeprom_cmd {
6937 unsigned char len;
6938 unsigned char bits[3];
6940 struct seeprom_cmd seeprom_read = {3, {1, 1, 0}};
6942 #define CLOCK_PULSE(p) \
6943 while ((aic_inb(p, STATUS_2840) & EEPROM_TF) == 0) \
6945 ; /* Do nothing */ \
6947 (void) aic_inb(p, SEECTL_2840);
6950 * Read the first 32 registers of the seeprom. For the 2840,
6951 * the 93C46 SEEPROM is a 1024-bit device with 64 16-bit registers
6952 * but only the first 32 are used by Adaptec BIOS. The loop
6953 * will range from 0 to 31.
6955 for (k = 0; k < (sizeof(*sc) / 2); k++)
6958 * Send chip select for one clock cycle.
6960 aic_outb(p, CK_2840 | CS_2840, SEECTL_2840);
6961 CLOCK_PULSE(p);
6964 * Now we're ready to send the read command followed by the
6965 * address of the 16-bit register we want to read.
6967 for (i = 0; i < seeprom_read.len; i++)
6969 temp = CS_2840 | seeprom_read.bits[i];
6970 aic_outb(p, temp, SEECTL_2840);
6971 CLOCK_PULSE(p);
6972 temp = temp ^ CK_2840;
6973 aic_outb(p, temp, SEECTL_2840);
6974 CLOCK_PULSE(p);
6977 * Send the 6 bit address (MSB first, LSB last).
6979 for (i = 5; i >= 0; i--)
6981 temp = k;
6982 temp = (temp >> i) & 1; /* Mask out all but lower bit. */
6983 temp = CS_2840 | temp;
6984 aic_outb(p, temp, SEECTL_2840);
6985 CLOCK_PULSE(p);
6986 temp = temp ^ CK_2840;
6987 aic_outb(p, temp, SEECTL_2840);
6988 CLOCK_PULSE(p);
6992 * Now read the 16 bit register. An initial 0 precedes the
6993 * register contents which begins with bit 15 (MSB) and ends
6994 * with bit 0 (LSB). The initial 0 will be shifted off the
6995 * top of our word as we let the loop run from 0 to 16.
6997 for (i = 0; i <= 16; i++)
6999 temp = CS_2840;
7000 aic_outb(p, temp, SEECTL_2840);
7001 CLOCK_PULSE(p);
7002 temp = temp ^ CK_2840;
7003 seeprom[k] = (seeprom[k] << 1) | (aic_inb(p, STATUS_2840) & DI_2840);
7004 aic_outb(p, temp, SEECTL_2840);
7005 CLOCK_PULSE(p);
7008 * The serial EEPROM has a checksum in the last word. Keep a
7009 * running checksum for all words read except for the last
7010 * word. We'll verify the checksum after all words have been
7011 * read.
7013 if (k < (sizeof(*sc) / 2) - 1)
7015 checksum = checksum + seeprom[k];
7019 * Reset the chip select for the next command cycle.
7021 aic_outb(p, 0, SEECTL_2840);
7022 CLOCK_PULSE(p);
7023 aic_outb(p, CK_2840, SEECTL_2840);
7024 CLOCK_PULSE(p);
7025 aic_outb(p, 0, SEECTL_2840);
7026 CLOCK_PULSE(p);
7029 #if 0
7030 printk("Computed checksum 0x%x, checksum read 0x%x\n", checksum, sc->checksum);
7031 printk("Serial EEPROM:");
7032 for (k = 0; k < (sizeof(*sc) / 2); k++)
7034 if (((k % 8) == 0) && (k != 0))
7036 printk("\n ");
7038 printk(" 0x%x", seeprom[k]);
7040 printk("\n");
7041 #endif
7043 if (checksum != sc->checksum)
7045 printk("aic7xxx: SEEPROM checksum error, ignoring SEEPROM settings.\n");
7046 return (0);
7049 return (1);
7050 #undef CLOCK_PULSE
7053 #define CLOCK_PULSE(p) \
7054 do { \
7055 int limit = 0; \
7056 do { \
7057 mb(); \
7058 pause_sequencer(p); /* This is just to generate some PCI */ \
7059 /* traffic so the PCI read is flushed */ \
7060 /* it shouldn't be needed, but some */ \
7061 /* chipsets do indeed appear to need */ \
7062 /* something to force PCI reads to get */ \
7063 /* flushed */ \
7064 udelay(1); /* Do nothing */ \
7065 } while (((aic_inb(p, SEECTL) & SEERDY) == 0) && (++limit < 1000)); \
7066 } while(0)
7068 /*+F*************************************************************************
7069 * Function:
7070 * acquire_seeprom
7072 * Description:
7073 * Acquires access to the memory port on PCI controllers.
7074 *-F*************************************************************************/
7075 static int
7076 acquire_seeprom(struct aic7xxx_host *p)
7080 * Request access of the memory port. When access is
7081 * granted, SEERDY will go high. We use a 1 second
7082 * timeout which should be near 1 second more than
7083 * is needed. Reason: after the 7870 chip reset, there
7084 * should be no contention.
7086 aic_outb(p, SEEMS, SEECTL);
7087 CLOCK_PULSE(p);
7088 if ((aic_inb(p, SEECTL) & SEERDY) == 0)
7090 aic_outb(p, 0, SEECTL);
7091 return (0);
7093 return (1);
7096 /*+F*************************************************************************
7097 * Function:
7098 * release_seeprom
7100 * Description:
7101 * Releases access to the memory port on PCI controllers.
7102 *-F*************************************************************************/
7103 static void
7104 release_seeprom(struct aic7xxx_host *p)
7107 * Make sure the SEEPROM is ready before we release it.
7109 CLOCK_PULSE(p);
7110 aic_outb(p, 0, SEECTL);
7113 /*+F*************************************************************************
7114 * Function:
7115 * read_seeprom
7117 * Description:
7118 * Reads the serial EEPROM and returns 1 if successful and 0 if
7119 * not successful.
7121 * The instruction set of the 93C46/56/66 chips is as follows:
7123 * Start OP
7124 * Function Bit Code Address Data Description
7125 * -------------------------------------------------------------------
7126 * READ 1 10 A5 - A0 Reads data stored in memory,
7127 * starting at specified address
7128 * EWEN 1 00 11XXXX Write enable must precede
7129 * all programming modes
7130 * ERASE 1 11 A5 - A0 Erase register A5A4A3A2A1A0
7131 * WRITE 1 01 A5 - A0 D15 - D0 Writes register
7132 * ERAL 1 00 10XXXX Erase all registers
7133 * WRAL 1 00 01XXXX D15 - D0 Writes to all registers
7134 * EWDS 1 00 00XXXX Disables all programming
7135 * instructions
7136 * *Note: A value of X for address is a don't care condition.
7137 * *Note: The 93C56 and 93C66 have 8 address bits.
7140 * The 93C46 has a four wire interface: clock, chip select, data in, and
7141 * data out. In order to perform one of the above functions, you need
7142 * to enable the chip select for a clock period (typically a minimum of
7143 * 1 usec, with the clock high and low a minimum of 750 and 250 nsec
7144 * respectively. While the chip select remains high, you can clock in
7145 * the instructions (above) starting with the start bit, followed by the
7146 * OP code, Address, and Data (if needed). For the READ instruction, the
7147 * requested 16-bit register contents is read from the data out line but
7148 * is preceded by an initial zero (leading 0, followed by 16-bits, MSB
7149 * first). The clock cycling from low to high initiates the next data
7150 * bit to be sent from the chip.
7152 * The 78xx interface to the 93C46 serial EEPROM is through the SEECTL
7153 * register. After successful arbitration for the memory port, the
7154 * SEECS bit of the SEECTL register is connected to the chip select.
7155 * The SEECK, SEEDO, and SEEDI are connected to the clock, data out,
7156 * and data in lines respectively. The SEERDY bit of SEECTL is useful
7157 * in that it gives us an 800 nsec timer. After a write to the SEECTL
7158 * register, the SEERDY goes high 800 nsec later. The one exception
7159 * to this is when we first request access to the memory port. The
7160 * SEERDY goes high to signify that access has been granted and, for
7161 * this case, has no implied timing.
7162 *-F*************************************************************************/
7163 static int
7164 read_seeprom(struct aic7xxx_host *p, int offset,
7165 unsigned short *scarray, unsigned int len, seeprom_chip_type chip)
7167 int i = 0, k;
7168 unsigned char temp;
7169 unsigned short checksum = 0;
7170 struct seeprom_cmd {
7171 unsigned char len;
7172 unsigned char bits[3];
7174 struct seeprom_cmd seeprom_read = {3, {1, 1, 0}};
7177 * Request access of the memory port.
7179 if (acquire_seeprom(p) == 0)
7181 return (0);
7185 * Read 'len' registers of the seeprom. For the 7870, the 93C46
7186 * SEEPROM is a 1024-bit device with 64 16-bit registers but only
7187 * the first 32 are used by Adaptec BIOS. Some adapters use the
7188 * 93C56 SEEPROM which is a 2048-bit device. The loop will range
7189 * from 0 to 'len' - 1.
7191 for (k = 0; k < len; k++)
7194 * Send chip select for one clock cycle.
7196 aic_outb(p, SEEMS | SEECK | SEECS, SEECTL);
7197 CLOCK_PULSE(p);
7200 * Now we're ready to send the read command followed by the
7201 * address of the 16-bit register we want to read.
7203 for (i = 0; i < seeprom_read.len; i++)
7205 temp = SEEMS | SEECS | (seeprom_read.bits[i] << 1);
7206 aic_outb(p, temp, SEECTL);
7207 CLOCK_PULSE(p);
7208 temp = temp ^ SEECK;
7209 aic_outb(p, temp, SEECTL);
7210 CLOCK_PULSE(p);
7213 * Send the 6 or 8 bit address (MSB first, LSB last).
7215 for (i = ((int) chip - 1); i >= 0; i--)
7217 temp = k + offset;
7218 temp = (temp >> i) & 1; /* Mask out all but lower bit. */
7219 temp = SEEMS | SEECS | (temp << 1);
7220 aic_outb(p, temp, SEECTL);
7221 CLOCK_PULSE(p);
7222 temp = temp ^ SEECK;
7223 aic_outb(p, temp, SEECTL);
7224 CLOCK_PULSE(p);
7228 * Now read the 16 bit register. An initial 0 precedes the
7229 * register contents which begins with bit 15 (MSB) and ends
7230 * with bit 0 (LSB). The initial 0 will be shifted off the
7231 * top of our word as we let the loop run from 0 to 16.
7233 for (i = 0; i <= 16; i++)
7235 temp = SEEMS | SEECS;
7236 aic_outb(p, temp, SEECTL);
7237 CLOCK_PULSE(p);
7238 temp = temp ^ SEECK;
7239 scarray[k] = (scarray[k] << 1) | (aic_inb(p, SEECTL) & SEEDI);
7240 aic_outb(p, temp, SEECTL);
7241 CLOCK_PULSE(p);
7245 * The serial EEPROM should have a checksum in the last word.
7246 * Keep a running checksum for all words read except for the
7247 * last word. We'll verify the checksum after all words have
7248 * been read.
7250 if (k < (len - 1))
7252 checksum = checksum + scarray[k];
7256 * Reset the chip select for the next command cycle.
7258 aic_outb(p, SEEMS, SEECTL);
7259 CLOCK_PULSE(p);
7260 aic_outb(p, SEEMS | SEECK, SEECTL);
7261 CLOCK_PULSE(p);
7262 aic_outb(p, SEEMS, SEECTL);
7263 CLOCK_PULSE(p);
7267 * Release access to the memory port and the serial EEPROM.
7269 release_seeprom(p);
7271 #if 0
7272 printk("Computed checksum 0x%x, checksum read 0x%x\n",
7273 checksum, scarray[len - 1]);
7274 printk("Serial EEPROM:");
7275 for (k = 0; k < len; k++)
7277 if (((k % 8) == 0) && (k != 0))
7279 printk("\n ");
7281 printk(" 0x%x", scarray[k]);
7283 printk("\n");
7284 #endif
7285 if ( (checksum != scarray[len - 1]) || (checksum == 0) )
7287 return (0);
7290 return (1);
7293 /*+F*************************************************************************
7294 * Function:
7295 * read_brdctl
7297 * Description:
7298 * Reads the BRDCTL register.
7299 *-F*************************************************************************/
7300 static unsigned char
7301 read_brdctl(struct aic7xxx_host *p)
7303 unsigned char brdctl, value;
7306 * Make sure the SEEPROM is ready before we access it
7308 CLOCK_PULSE(p);
7309 if (p->features & AHC_ULTRA2)
7311 brdctl = BRDRW_ULTRA2;
7312 aic_outb(p, brdctl, BRDCTL);
7313 CLOCK_PULSE(p);
7314 value = aic_inb(p, BRDCTL);
7315 CLOCK_PULSE(p);
7316 return(value);
7318 brdctl = BRDRW;
7319 if ( !((p->chip & AHC_CHIPID_MASK) == AHC_AIC7895) ||
7320 (p->flags & AHC_CHNLB) )
7322 brdctl |= BRDCS;
7324 aic_outb(p, brdctl, BRDCTL);
7325 CLOCK_PULSE(p);
7326 value = aic_inb(p, BRDCTL);
7327 CLOCK_PULSE(p);
7328 aic_outb(p, 0, BRDCTL);
7329 CLOCK_PULSE(p);
7330 return (value);
7333 /*+F*************************************************************************
7334 * Function:
7335 * write_brdctl
7337 * Description:
7338 * Writes a value to the BRDCTL register.
7339 *-F*************************************************************************/
7340 static void
7341 write_brdctl(struct aic7xxx_host *p, unsigned char value)
7343 unsigned char brdctl;
7346 * Make sure the SEEPROM is ready before we access it
7348 CLOCK_PULSE(p);
7349 if (p->features & AHC_ULTRA2)
7351 brdctl = value;
7352 aic_outb(p, brdctl, BRDCTL);
7353 CLOCK_PULSE(p);
7354 brdctl |= BRDSTB_ULTRA2;
7355 aic_outb(p, brdctl, BRDCTL);
7356 CLOCK_PULSE(p);
7357 brdctl &= ~BRDSTB_ULTRA2;
7358 aic_outb(p, brdctl, BRDCTL);
7359 CLOCK_PULSE(p);
7360 read_brdctl(p);
7361 CLOCK_PULSE(p);
7363 else
7365 brdctl = BRDSTB;
7366 if ( !((p->chip & AHC_CHIPID_MASK) == AHC_AIC7895) ||
7367 (p->flags & AHC_CHNLB) )
7369 brdctl |= BRDCS;
7371 brdctl = BRDSTB | BRDCS;
7372 aic_outb(p, brdctl, BRDCTL);
7373 CLOCK_PULSE(p);
7374 brdctl |= value;
7375 aic_outb(p, brdctl, BRDCTL);
7376 CLOCK_PULSE(p);
7377 brdctl &= ~BRDSTB;
7378 aic_outb(p, brdctl, BRDCTL);
7379 CLOCK_PULSE(p);
7380 brdctl &= ~BRDCS;
7381 aic_outb(p, brdctl, BRDCTL);
7382 CLOCK_PULSE(p);
7386 /*+F*************************************************************************
7387 * Function:
7388 * aic785x_cable_detect
7390 * Description:
7391 * Detect the cables that are present on aic785x class controller chips
7392 *-F*************************************************************************/
7393 static void
7394 aic785x_cable_detect(struct aic7xxx_host *p, int *int_50,
7395 int *ext_present, int *eeprom)
7397 unsigned char brdctl;
7399 aic_outb(p, BRDRW | BRDCS, BRDCTL);
7400 CLOCK_PULSE(p);
7401 aic_outb(p, 0, BRDCTL);
7402 CLOCK_PULSE(p);
7403 brdctl = aic_inb(p, BRDCTL);
7404 CLOCK_PULSE(p);
7405 *int_50 = !(brdctl & BRDDAT5);
7406 *ext_present = !(brdctl & BRDDAT6);
7407 *eeprom = (aic_inb(p, SPIOCAP) & EEPROM);
7410 #undef CLOCK_PULSE
7412 /*+F*************************************************************************
7413 * Function:
7414 * aic2940_uwpro_cable_detect
7416 * Description:
7417 * Detect the cables that are present on the 2940-UWPro cards
7419 * NOTE: This function assumes the SEEPROM will have already been acquired
7420 * prior to invocation of this function.
7421 *-F*************************************************************************/
7422 static void
7423 aic2940_uwpro_wide_cable_detect(struct aic7xxx_host *p, int *int_68,
7424 int *ext_68, int *eeprom)
7426 unsigned char brdctl;
7429 * First read the status of our cables. Set the rom bank to
7430 * 0 since the bank setting serves as a multiplexor for the
7431 * cable detection logic. BRDDAT5 controls the bank switch.
7433 write_brdctl(p, 0);
7436 * Now we read the state of the internal 68 connector. BRDDAT6
7437 * is don't care, BRDDAT7 is internal 68. The cable is
7438 * present if the bit is 0
7440 brdctl = read_brdctl(p);
7441 *int_68 = !(brdctl & BRDDAT7);
7444 * Set the bank bit in brdctl and then read the external cable state
7445 * and the EEPROM status
7447 write_brdctl(p, BRDDAT5);
7448 brdctl = read_brdctl(p);
7450 *ext_68 = !(brdctl & BRDDAT6);
7451 *eeprom = !(brdctl & BRDDAT7);
7454 * We're done, the calling function will release the SEEPROM for us
7458 /*+F*************************************************************************
7459 * Function:
7460 * aic787x_cable_detect
7462 * Description:
7463 * Detect the cables that are present on aic787x class controller chips
7465 * NOTE: This function assumes the SEEPROM will have already been acquired
7466 * prior to invocation of this function.
7467 *-F*************************************************************************/
7468 static void
7469 aic787x_cable_detect(struct aic7xxx_host *p, int *int_50, int *int_68,
7470 int *ext_present, int *eeprom)
7472 unsigned char brdctl;
7475 * First read the status of our cables. Set the rom bank to
7476 * 0 since the bank setting serves as a multiplexor for the
7477 * cable detection logic. BRDDAT5 controls the bank switch.
7479 write_brdctl(p, 0);
7482 * Now we read the state of the two internal connectors. BRDDAT6
7483 * is internal 50, BRDDAT7 is internal 68. For each, the cable is
7484 * present if the bit is 0
7486 brdctl = read_brdctl(p);
7487 *int_50 = !(brdctl & BRDDAT6);
7488 *int_68 = !(brdctl & BRDDAT7);
7491 * Set the bank bit in brdctl and then read the external cable state
7492 * and the EEPROM status
7494 write_brdctl(p, BRDDAT5);
7495 brdctl = read_brdctl(p);
7497 *ext_present = !(brdctl & BRDDAT6);
7498 *eeprom = !(brdctl & BRDDAT7);
7501 * We're done, the calling function will release the SEEPROM for us
7505 /*+F*************************************************************************
7506 * Function:
7507 * aic787x_ultra2_term_detect
7509 * Description:
7510 * Detect the termination settings present on ultra2 class controllers
7512 * NOTE: This function assumes the SEEPROM will have already been acquired
7513 * prior to invocation of this function.
7514 *-F*************************************************************************/
7515 static void
7516 aic7xxx_ultra2_term_detect(struct aic7xxx_host *p, int *enableSE_low,
7517 int *enableSE_high, int *enableLVD_low,
7518 int *enableLVD_high, int *eprom_present)
7520 unsigned char brdctl;
7522 brdctl = read_brdctl(p);
7524 *eprom_present = (brdctl & BRDDAT7);
7525 *enableSE_high = (brdctl & BRDDAT6);
7526 *enableSE_low = (brdctl & BRDDAT5);
7527 *enableLVD_high = (brdctl & BRDDAT4);
7528 *enableLVD_low = (brdctl & BRDDAT3);
7531 /*+F*************************************************************************
7532 * Function:
7533 * configure_termination
7535 * Description:
7536 * Configures the termination settings on PCI adapters that have
7537 * SEEPROMs available.
7538 *-F*************************************************************************/
7539 static void
7540 configure_termination(struct aic7xxx_host *p)
7542 int internal50_present = 0;
7543 int internal68_present = 0;
7544 int external_present = 0;
7545 int eprom_present = 0;
7546 int enableSE_low = 0;
7547 int enableSE_high = 0;
7548 int enableLVD_low = 0;
7549 int enableLVD_high = 0;
7550 unsigned char brddat = 0;
7551 unsigned char max_target = 0;
7552 unsigned char sxfrctl1 = aic_inb(p, SXFRCTL1);
7554 if (acquire_seeprom(p))
7556 if (p->features & (AHC_WIDE|AHC_TWIN))
7557 max_target = 16;
7558 else
7559 max_target = 8;
7560 aic_outb(p, SEEMS | SEECS, SEECTL);
7561 sxfrctl1 &= ~STPWEN;
7563 * The termination/cable detection logic is split into three distinct
7564 * groups. Ultra2 and later controllers, 2940UW-Pro controllers, and
7565 * older 7850, 7860, 7870, 7880, and 7895 controllers. Each has its
7566 * own unique way of detecting their cables and writing the results
7567 * back to the card.
7569 if (p->features & AHC_ULTRA2)
7572 * As long as user hasn't overridden term settings, always check the
7573 * cable detection logic
7575 if (aic7xxx_override_term == -1)
7577 aic7xxx_ultra2_term_detect(p, &enableSE_low, &enableSE_high,
7578 &enableLVD_low, &enableLVD_high,
7579 &eprom_present);
7583 * If the user is overriding settings, then they have been preserved
7584 * to here as fake adapter_control entries. Parse them and allow
7585 * them to override the detected settings (if we even did detection).
7587 if (!(p->adapter_control & CFSEAUTOTERM))
7589 enableSE_low = (p->adapter_control & CFSTERM);
7590 enableSE_high = (p->adapter_control & CFWSTERM);
7592 if (!(p->adapter_control & CFAUTOTERM))
7594 enableLVD_low = enableLVD_high = (p->adapter_control & CFLVDSTERM);
7598 * Now take those settings that we have and translate them into the
7599 * values that must be written into the registers.
7601 * Flash Enable = BRDDAT7
7602 * Secondary High Term Enable = BRDDAT6
7603 * Secondary Low Term Enable = BRDDAT5
7604 * LVD/Primary High Term Enable = BRDDAT4
7605 * LVD/Primary Low Term Enable = STPWEN bit in SXFRCTL1
7607 if (enableLVD_low != 0)
7609 sxfrctl1 |= STPWEN;
7610 p->flags |= AHC_TERM_ENB_LVD;
7611 if (aic7xxx_verbose & VERBOSE_PROBE2)
7612 printk(KERN_INFO "(scsi%d) LVD/Primary Low byte termination "
7613 "Enabled\n", p->host_no);
7616 if (enableLVD_high != 0)
7618 brddat |= BRDDAT4;
7619 if (aic7xxx_verbose & VERBOSE_PROBE2)
7620 printk(KERN_INFO "(scsi%d) LVD/Primary High byte termination "
7621 "Enabled\n", p->host_no);
7624 if (enableSE_low != 0)
7626 brddat |= BRDDAT5;
7627 if (aic7xxx_verbose & VERBOSE_PROBE2)
7628 printk(KERN_INFO "(scsi%d) Secondary Low byte termination "
7629 "Enabled\n", p->host_no);
7632 if (enableSE_high != 0)
7634 brddat |= BRDDAT6;
7635 if (aic7xxx_verbose & VERBOSE_PROBE2)
7636 printk(KERN_INFO "(scsi%d) Secondary High byte termination "
7637 "Enabled\n", p->host_no);
7640 else if (p->features & AHC_NEW_AUTOTERM)
7643 * The 50 pin connector termination is controlled by STPWEN in the
7644 * SXFRCTL1 register. Since the Adaptec docs typically say the
7645 * controller is not allowed to be in the middle of a cable and
7646 * this is the only connection on that stub of the bus, there is
7647 * no need to even check for narrow termination, it's simply
7648 * always on.
7650 sxfrctl1 |= STPWEN;
7651 if (aic7xxx_verbose & VERBOSE_PROBE2)
7652 printk(KERN_INFO "(scsi%d) Narrow channel termination Enabled\n",
7653 p->host_no);
7655 if (p->adapter_control & CFAUTOTERM)
7657 aic2940_uwpro_wide_cable_detect(p, &internal68_present,
7658 &external_present,
7659 &eprom_present);
7660 printk(KERN_INFO "(scsi%d) Cables present (Int-50 %s, Int-68 %s, "
7661 "Ext-68 %s)\n", p->host_no,
7662 "Don't Care",
7663 internal68_present ? "YES" : "NO",
7664 external_present ? "YES" : "NO");
7665 if (aic7xxx_verbose & VERBOSE_PROBE2)
7666 printk(KERN_INFO "(scsi%d) EEPROM %s present.\n", p->host_no,
7667 eprom_present ? "is" : "is not");
7668 if (internal68_present && external_present)
7670 brddat = 0;
7671 p->flags &= ~AHC_TERM_ENB_SE_HIGH;
7672 if (aic7xxx_verbose & VERBOSE_PROBE2)
7673 printk(KERN_INFO "(scsi%d) Wide channel termination Disabled\n",
7674 p->host_no);
7676 else
7678 brddat = BRDDAT6;
7679 p->flags |= AHC_TERM_ENB_SE_HIGH;
7680 if (aic7xxx_verbose & VERBOSE_PROBE2)
7681 printk(KERN_INFO "(scsi%d) Wide channel termination Enabled\n",
7682 p->host_no);
7685 else
7688 * The termination of the Wide channel is done more like normal
7689 * though, and the setting of this termination is done by writing
7690 * either a 0 or 1 to BRDDAT6 of the BRDDAT register
7692 if (p->adapter_control & CFWSTERM)
7694 brddat = BRDDAT6;
7695 p->flags |= AHC_TERM_ENB_SE_HIGH;
7696 if (aic7xxx_verbose & VERBOSE_PROBE2)
7697 printk(KERN_INFO "(scsi%d) Wide channel termination Enabled\n",
7698 p->host_no);
7700 else
7702 brddat = 0;
7706 else
7708 if (p->adapter_control & CFAUTOTERM)
7710 if (p->flags & AHC_MOTHERBOARD)
7712 printk(KERN_INFO "(scsi%d) Warning - detected auto-termination\n",
7713 p->host_no);
7714 printk(KERN_INFO "(scsi%d) Please verify driver detected settings "
7715 "are correct.\n", p->host_no);
7716 printk(KERN_INFO "(scsi%d) If not, then please properly set the "
7717 "device termination\n", p->host_no);
7718 printk(KERN_INFO "(scsi%d) in the Adaptec SCSI BIOS by hitting "
7719 "CTRL-A when prompted\n", p->host_no);
7720 printk(KERN_INFO "(scsi%d) during machine bootup.\n", p->host_no);
7722 /* Configure auto termination. */
7724 if ( (p->chip & AHC_CHIPID_MASK) >= AHC_AIC7870 )
7726 aic787x_cable_detect(p, &internal50_present, &internal68_present,
7727 &external_present, &eprom_present);
7729 else
7731 aic785x_cable_detect(p, &internal50_present, &external_present,
7732 &eprom_present);
7735 if (max_target <= 8)
7736 internal68_present = 0;
7738 if (max_target > 8)
7740 printk(KERN_INFO "(scsi%d) Cables present (Int-50 %s, Int-68 %s, "
7741 "Ext-68 %s)\n", p->host_no,
7742 internal50_present ? "YES" : "NO",
7743 internal68_present ? "YES" : "NO",
7744 external_present ? "YES" : "NO");
7746 else
7748 printk(KERN_INFO "(scsi%d) Cables present (Int-50 %s, Ext-50 %s)\n",
7749 p->host_no,
7750 internal50_present ? "YES" : "NO",
7751 external_present ? "YES" : "NO");
7753 if (aic7xxx_verbose & VERBOSE_PROBE2)
7754 printk(KERN_INFO "(scsi%d) EEPROM %s present.\n", p->host_no,
7755 eprom_present ? "is" : "is not");
7758 * Now set the termination based on what we found. BRDDAT6
7759 * controls wide termination enable.
7760 * Flash Enable = BRDDAT7
7761 * SE High Term Enable = BRDDAT6
7763 if (internal50_present && internal68_present && external_present)
7765 printk(KERN_INFO "(scsi%d) Illegal cable configuration!! Only two\n",
7766 p->host_no);
7767 printk(KERN_INFO "(scsi%d) connectors on the SCSI controller may be "
7768 "in use at a time!\n", p->host_no);
7770 * Force termination (low and high byte) on. This is safer than
7771 * leaving it completely off, especially since this message comes
7772 * most often from motherboard controllers that don't even have 3
7773 * connectors, but instead are failing the cable detection.
7775 internal50_present = external_present = 0;
7776 enableSE_high = enableSE_low = 1;
7779 if ((max_target > 8) &&
7780 ((external_present == 0) || (internal68_present == 0)) )
7782 brddat |= BRDDAT6;
7783 p->flags |= AHC_TERM_ENB_SE_HIGH;
7784 if (aic7xxx_verbose & VERBOSE_PROBE2)
7785 printk(KERN_INFO "(scsi%d) SE High byte termination Enabled\n",
7786 p->host_no);
7789 if ( ((internal50_present ? 1 : 0) +
7790 (internal68_present ? 1 : 0) +
7791 (external_present ? 1 : 0)) <= 1 )
7793 sxfrctl1 |= STPWEN;
7794 p->flags |= AHC_TERM_ENB_SE_LOW;
7795 if (aic7xxx_verbose & VERBOSE_PROBE2)
7796 printk(KERN_INFO "(scsi%d) SE Low byte termination Enabled\n",
7797 p->host_no);
7800 else /* p->adapter_control & CFAUTOTERM */
7802 if (p->adapter_control & CFSTERM)
7804 sxfrctl1 |= STPWEN;
7805 if (aic7xxx_verbose & VERBOSE_PROBE2)
7806 printk(KERN_INFO "(scsi%d) SE Low byte termination Enabled\n",
7807 p->host_no);
7810 if (p->adapter_control & CFWSTERM)
7812 brddat |= BRDDAT6;
7813 if (aic7xxx_verbose & VERBOSE_PROBE2)
7814 printk(KERN_INFO "(scsi%d) SE High byte termination Enabled\n",
7815 p->host_no);
7820 aic_outb(p, sxfrctl1, SXFRCTL1);
7821 write_brdctl(p, brddat);
7822 release_seeprom(p);
7826 /*+F*************************************************************************
7827 * Function:
7828 * detect_maxscb
7830 * Description:
7831 * Detects the maximum number of SCBs for the controller and returns
7832 * the count and a mask in p (p->maxscbs, p->qcntmask).
7833 *-F*************************************************************************/
7834 static void
7835 detect_maxscb(struct aic7xxx_host *p)
7837 int i;
7840 * It's possible that we've already done this for multichannel
7841 * adapters.
7843 if (p->scb_data->maxhscbs == 0)
7846 * We haven't initialized the SCB settings yet. Walk the SCBs to
7847 * determince how many there are.
7849 aic_outb(p, 0, FREE_SCBH);
7851 for (i = 0; i < AIC7XXX_MAXSCB; i++)
7853 aic_outb(p, i, SCBPTR);
7854 aic_outb(p, i, SCB_CONTROL);
7855 if (aic_inb(p, SCB_CONTROL) != i)
7856 break;
7857 aic_outb(p, 0, SCBPTR);
7858 if (aic_inb(p, SCB_CONTROL) != 0)
7859 break;
7861 aic_outb(p, i, SCBPTR);
7862 aic_outb(p, 0, SCB_CONTROL); /* Clear the control byte. */
7863 aic_outb(p, i + 1, SCB_NEXT); /* Set the next pointer. */
7864 aic_outb(p, SCB_LIST_NULL, SCB_TAG); /* Make the tag invalid. */
7865 aic_outb(p, SCB_LIST_NULL, SCB_BUSYTARGETS); /* no busy untagged */
7866 aic_outb(p, SCB_LIST_NULL, SCB_BUSYTARGETS+1);/* targets active yet */
7867 aic_outb(p, SCB_LIST_NULL, SCB_BUSYTARGETS+2);
7868 aic_outb(p, SCB_LIST_NULL, SCB_BUSYTARGETS+3);
7871 /* Make sure the last SCB terminates the free list. */
7872 aic_outb(p, i - 1, SCBPTR);
7873 aic_outb(p, SCB_LIST_NULL, SCB_NEXT);
7875 /* Ensure we clear the first (0) SCBs control byte. */
7876 aic_outb(p, 0, SCBPTR);
7877 aic_outb(p, 0, SCB_CONTROL);
7879 p->scb_data->maxhscbs = i;
7881 * Use direct indexing instead for speed
7883 if ( i == AIC7XXX_MAXSCB )
7884 p->flags &= ~AHC_PAGESCBS;
7889 /*+F*************************************************************************
7890 * Function:
7891 * aic7xxx_register
7893 * Description:
7894 * Register a Adaptec aic7xxx chip SCSI controller with the kernel.
7895 *-F*************************************************************************/
7896 static int
7897 aic7xxx_register(Scsi_Host_Template *template, struct aic7xxx_host *p,
7898 int reset_delay)
7900 int i, result;
7901 int max_targets;
7902 int found = 1;
7903 unsigned char term, scsi_conf;
7904 struct Scsi_Host *host;
7906 host = p->host;
7908 p->scb_data->maxscbs = AIC7XXX_MAXSCB;
7909 host->can_queue = AIC7XXX_MAXSCB;
7910 host->cmd_per_lun = 3;
7911 host->sg_tablesize = AIC7XXX_MAX_SG;
7912 host->this_id = p->scsi_id;
7913 host->io_port = p->base;
7914 host->n_io_port = 0xFF;
7915 host->base = p->mbase;
7916 host->irq = p->irq;
7917 if (p->features & AHC_WIDE)
7919 host->max_id = 16;
7921 if (p->features & AHC_TWIN)
7923 host->max_channel = 1;
7926 p->host = host;
7927 p->host_no = host->host_no;
7928 host->unique_id = p->instance;
7929 p->isr_count = 0;
7930 p->next = NULL;
7931 p->completeq.head = NULL;
7932 p->completeq.tail = NULL;
7933 scbq_init(&p->scb_data->free_scbs);
7934 scbq_init(&p->waiting_scbs);
7935 INIT_LIST_HEAD(&p->aic_devs);
7938 * We currently have no commands of any type
7940 p->qinfifonext = 0;
7941 p->qoutfifonext = 0;
7943 printk(KERN_INFO "(scsi%d) <%s> found at ", p->host_no,
7944 board_names[p->board_name_index]);
7945 switch(p->chip)
7947 case (AHC_AIC7770|AHC_EISA):
7948 printk("EISA slot %d\n", p->pci_device_fn);
7949 break;
7950 case (AHC_AIC7770|AHC_VL):
7951 printk("VLB slot %d\n", p->pci_device_fn);
7952 break;
7953 default:
7954 printk("PCI %d/%d/%d\n", p->pci_bus, PCI_SLOT(p->pci_device_fn),
7955 PCI_FUNC(p->pci_device_fn));
7956 break;
7958 if (p->features & AHC_TWIN)
7960 printk(KERN_INFO "(scsi%d) Twin Channel, A SCSI ID %d, B SCSI ID %d, ",
7961 p->host_no, p->scsi_id, p->scsi_id_b);
7963 else
7965 char *channel;
7967 channel = "";
7969 if ((p->flags & AHC_MULTI_CHANNEL) != 0)
7971 channel = " A";
7973 if ( (p->flags & (AHC_CHNLB|AHC_CHNLC)) != 0 )
7975 channel = (p->flags & AHC_CHNLB) ? " B" : " C";
7978 if (p->features & AHC_WIDE)
7980 printk(KERN_INFO "(scsi%d) Wide ", p->host_no);
7982 else
7984 printk(KERN_INFO "(scsi%d) Narrow ", p->host_no);
7986 printk("Channel%s, SCSI ID=%d, ", channel, p->scsi_id);
7988 aic_outb(p, 0, SEQ_FLAGS);
7990 detect_maxscb(p);
7992 printk("%d/%d SCBs\n", p->scb_data->maxhscbs, p->scb_data->maxscbs);
7993 if (aic7xxx_verbose & VERBOSE_PROBE2)
7995 printk(KERN_INFO "(scsi%d) BIOS %sabled, IO Port 0x%lx, IRQ %d\n",
7996 p->host_no, (p->flags & AHC_BIOS_ENABLED) ? "en" : "dis",
7997 p->base, p->irq);
7998 printk(KERN_INFO "(scsi%d) IO Memory at 0x%lx, MMAP Memory at 0x%lx\n",
7999 p->host_no, p->mbase, (unsigned long)p->maddr);
8002 #ifdef CONFIG_PCI
8004 * Now that we know our instance number, we can set the flags we need to
8005 * force termination if need be.
8007 if (aic7xxx_stpwlev != -1)
8010 * This option only applies to PCI controllers.
8012 if ( (p->chip & ~AHC_CHIPID_MASK) == AHC_PCI)
8014 unsigned char devconfig;
8016 pci_read_config_byte(p->pdev, DEVCONFIG, &devconfig);
8017 if ( (aic7xxx_stpwlev >> p->instance) & 0x01 )
8019 devconfig |= STPWLEVEL;
8020 if (aic7xxx_verbose & VERBOSE_PROBE2)
8021 printk("(scsi%d) Force setting STPWLEVEL bit\n", p->host_no);
8023 else
8025 devconfig &= ~STPWLEVEL;
8026 if (aic7xxx_verbose & VERBOSE_PROBE2)
8027 printk("(scsi%d) Force clearing STPWLEVEL bit\n", p->host_no);
8029 pci_write_config_byte(p->pdev, DEVCONFIG, devconfig);
8032 #endif
8035 * That took care of devconfig and stpwlev, now for the actual termination
8036 * settings.
8038 if (aic7xxx_override_term != -1)
8041 * Again, this only applies to PCI controllers. We don't have problems
8042 * with the termination on 274x controllers to the best of my knowledge.
8044 if ( (p->chip & ~AHC_CHIPID_MASK) == AHC_PCI)
8046 unsigned char term_override;
8048 term_override = ( (aic7xxx_override_term >> (p->instance * 4)) & 0x0f);
8049 p->adapter_control &=
8050 ~(CFSTERM|CFWSTERM|CFLVDSTERM|CFAUTOTERM|CFSEAUTOTERM);
8051 if ( (p->features & AHC_ULTRA2) && (term_override & 0x0c) )
8053 p->adapter_control |= CFLVDSTERM;
8055 if (term_override & 0x02)
8057 p->adapter_control |= CFWSTERM;
8059 if (term_override & 0x01)
8061 p->adapter_control |= CFSTERM;
8066 if ( (p->flags & AHC_SEEPROM_FOUND) || (aic7xxx_override_term != -1) )
8068 if (p->features & AHC_SPIOCAP)
8070 if ( aic_inb(p, SPIOCAP) & SSPIOCPS )
8072 * Update the settings in sxfrctl1 to match the termination
8073 * settings.
8075 configure_termination(p);
8077 else if ((p->chip & AHC_CHIPID_MASK) >= AHC_AIC7870)
8079 configure_termination(p);
8084 * Set the SCSI Id, SXFRCTL0, SXFRCTL1, and SIMODE1, for both channels
8086 if (p->features & AHC_TWIN)
8088 /* Select channel B */
8089 aic_outb(p, aic_inb(p, SBLKCTL) | SELBUSB, SBLKCTL);
8091 if ((p->flags & AHC_SEEPROM_FOUND) || (aic7xxx_override_term != -1))
8092 term = (aic_inb(p, SXFRCTL1) & STPWEN);
8093 else
8094 term = ((p->flags & AHC_TERM_ENB_B) ? STPWEN : 0);
8096 aic_outb(p, p->scsi_id_b, SCSIID);
8097 scsi_conf = aic_inb(p, SCSICONF + 1);
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);
8102 aic_outb(p, ENSELTIMO | ENSCSIRST | ENSCSIPERR, SIMODE1);
8103 aic_outb(p, 0, SCSIRATE);
8105 /* Select channel A */
8106 aic_outb(p, aic_inb(p, SBLKCTL) & ~SELBUSB, SBLKCTL);
8109 if (p->features & AHC_ULTRA2)
8111 aic_outb(p, p->scsi_id, SCSIID_ULTRA2);
8113 else
8115 aic_outb(p, p->scsi_id, SCSIID);
8117 if ((p->flags & AHC_SEEPROM_FOUND) || (aic7xxx_override_term != -1))
8118 term = (aic_inb(p, SXFRCTL1) & STPWEN);
8119 else
8120 term = ((p->flags & (AHC_TERM_ENB_A|AHC_TERM_ENB_LVD)) ? STPWEN : 0);
8121 scsi_conf = aic_inb(p, SCSICONF);
8122 aic_outb(p, DFON | SPIOEN, SXFRCTL0);
8123 aic_outb(p, (scsi_conf & ENSPCHK) | aic7xxx_seltime | term |
8124 ENSTIMER | ACTNEGEN, SXFRCTL1);
8125 aic_outb(p, 0, SIMODE0);
8127 * If we are a cardbus adapter then don't enable SCSI reset detection.
8128 * We shouldn't likely be sharing SCSI busses with someone else, and
8129 * if we don't have a cable currently plugged into the controller then
8130 * we won't have a power source for the SCSI termination, which means
8131 * we'll see infinite incoming bus resets.
8133 if(p->flags & AHC_NO_STPWEN)
8134 aic_outb(p, ENSELTIMO | ENSCSIPERR, SIMODE1);
8135 else
8136 aic_outb(p, ENSELTIMO | ENSCSIRST | ENSCSIPERR, SIMODE1);
8137 aic_outb(p, 0, SCSIRATE);
8138 if ( p->features & AHC_ULTRA2)
8139 aic_outb(p, 0, SCSIOFFSET);
8142 * Look at the information that board initialization or the board
8143 * BIOS has left us. In the lower four bits of each target's
8144 * scratch space any value other than 0 indicates that we should
8145 * initiate synchronous transfers. If it's zero, the user or the
8146 * BIOS has decided to disable synchronous negotiation to that
8147 * target so we don't activate the needsdtr flag.
8149 if ((p->features & (AHC_TWIN|AHC_WIDE)) == 0)
8151 max_targets = 8;
8153 else
8155 max_targets = 16;
8158 if (!(aic7xxx_no_reset))
8161 * If we reset the bus, then clear the transfer settings, else leave
8162 * them be.
8164 aic_outb(p, 0, ULTRA_ENB);
8165 aic_outb(p, 0, ULTRA_ENB + 1);
8166 p->ultraenb = 0;
8170 * Allocate enough hardware scbs to handle the maximum number of
8171 * concurrent transactions we can have. We have to make sure that
8172 * the allocated memory is contiguous memory. The Linux kmalloc
8173 * routine should only allocate contiguous memory, but note that
8174 * this could be a problem if kmalloc() is changed.
8177 size_t array_size;
8178 unsigned int hscb_physaddr;
8180 array_size = p->scb_data->maxscbs * sizeof(struct aic7xxx_hwscb);
8181 if (p->scb_data->hscbs == NULL)
8183 /* pci_alloc_consistent enforces the alignment already and
8184 * clears the area as well.
8186 p->scb_data->hscbs = pci_alloc_consistent(p->pdev, array_size,
8187 &p->scb_data->hscbs_dma);
8188 /* We have to use pci_free_consistent, not kfree */
8189 p->scb_data->hscb_kmalloc_ptr = NULL;
8190 p->scb_data->hscbs_dma_len = array_size;
8192 if (p->scb_data->hscbs == NULL)
8194 printk("(scsi%d) Unable to allocate hardware SCB array; "
8195 "failing detection.\n", p->host_no);
8196 aic_outb(p, 0, SIMODE1);
8197 p->irq = 0;
8198 return(0);
8201 hscb_physaddr = p->scb_data->hscbs_dma;
8202 aic_outb(p, hscb_physaddr & 0xFF, HSCB_ADDR);
8203 aic_outb(p, (hscb_physaddr >> 8) & 0xFF, HSCB_ADDR + 1);
8204 aic_outb(p, (hscb_physaddr >> 16) & 0xFF, HSCB_ADDR + 2);
8205 aic_outb(p, (hscb_physaddr >> 24) & 0xFF, HSCB_ADDR + 3);
8207 /* Set up the fifo areas at the same time */
8208 p->untagged_scbs = pci_alloc_consistent(p->pdev, 3*256, &p->fifo_dma);
8209 if (p->untagged_scbs == NULL)
8211 printk("(scsi%d) Unable to allocate hardware FIFO arrays; "
8212 "failing detection.\n", p->host_no);
8213 p->irq = 0;
8214 return(0);
8217 p->qoutfifo = p->untagged_scbs + 256;
8218 p->qinfifo = p->qoutfifo + 256;
8219 for (i = 0; i < 256; i++)
8221 p->untagged_scbs[i] = SCB_LIST_NULL;
8222 p->qinfifo[i] = SCB_LIST_NULL;
8223 p->qoutfifo[i] = SCB_LIST_NULL;
8226 hscb_physaddr = p->fifo_dma;
8227 aic_outb(p, hscb_physaddr & 0xFF, SCBID_ADDR);
8228 aic_outb(p, (hscb_physaddr >> 8) & 0xFF, SCBID_ADDR + 1);
8229 aic_outb(p, (hscb_physaddr >> 16) & 0xFF, SCBID_ADDR + 2);
8230 aic_outb(p, (hscb_physaddr >> 24) & 0xFF, SCBID_ADDR + 3);
8233 /* The Q-FIFOs we just set up are all empty */
8234 aic_outb(p, 0, QINPOS);
8235 aic_outb(p, 0, KERNEL_QINPOS);
8236 aic_outb(p, 0, QOUTPOS);
8238 if(p->features & AHC_QUEUE_REGS)
8240 aic_outb(p, SCB_QSIZE_256, QOFF_CTLSTA);
8241 aic_outb(p, 0, SDSCB_QOFF);
8242 aic_outb(p, 0, SNSCB_QOFF);
8243 aic_outb(p, 0, HNSCB_QOFF);
8247 * We don't have any waiting selections or disconnected SCBs.
8249 aic_outb(p, SCB_LIST_NULL, WAITING_SCBH);
8250 aic_outb(p, SCB_LIST_NULL, DISCONNECTED_SCBH);
8253 * Message out buffer starts empty
8255 aic_outb(p, MSG_NOOP, MSG_OUT);
8256 aic_outb(p, MSG_NOOP, LAST_MSG);
8259 * Set all the other asundry items that haven't been set yet.
8260 * This includes just dumping init values to a lot of registers simply
8261 * to make sure they've been touched and are ready for use parity wise
8262 * speaking.
8264 aic_outb(p, 0, TMODE_CMDADDR);
8265 aic_outb(p, 0, TMODE_CMDADDR + 1);
8266 aic_outb(p, 0, TMODE_CMDADDR + 2);
8267 aic_outb(p, 0, TMODE_CMDADDR + 3);
8268 aic_outb(p, 0, TMODE_CMDADDR_NEXT);
8271 * Link us into the list of valid hosts
8273 p->next = first_aic7xxx;
8274 first_aic7xxx = p;
8277 * Allocate the first set of scbs for this controller. This is to stream-
8278 * line code elsewhere in the driver. If we have to check for the existence
8279 * of scbs in certain code sections, it slows things down. However, as
8280 * soon as we register the IRQ for this card, we could get an interrupt that
8281 * includes possibly the SCSI_RSTI interrupt. If we catch that interrupt
8282 * then we are likely to segfault if we don't have at least one chunk of
8283 * SCBs allocated or add checks all through the reset code to make sure
8284 * that the SCBs have been allocated which is an invalid running condition
8285 * and therefore I think it's preferable to simply pre-allocate the first
8286 * chunk of SCBs.
8288 aic7xxx_allocate_scb(p);
8291 * Load the sequencer program, then re-enable the board -
8292 * resetting the AIC-7770 disables it, leaving the lights
8293 * on with nobody home.
8295 aic7xxx_loadseq(p);
8298 * Make sure the AUTOFLUSHDIS bit is *not* set in the SBLKCTL register
8300 aic_outb(p, aic_inb(p, SBLKCTL) & ~AUTOFLUSHDIS, SBLKCTL);
8302 if ( (p->chip & AHC_CHIPID_MASK) == AHC_AIC7770 )
8304 aic_outb(p, ENABLE, BCTL); /* Enable the boards BUS drivers. */
8307 if ( !(aic7xxx_no_reset) )
8309 if (p->features & AHC_TWIN)
8311 if (aic7xxx_verbose & VERBOSE_PROBE2)
8312 printk(KERN_INFO "(scsi%d) Resetting channel B\n", p->host_no);
8313 aic_outb(p, aic_inb(p, SBLKCTL) | SELBUSB, SBLKCTL);
8314 aic7xxx_reset_current_bus(p);
8315 aic_outb(p, aic_inb(p, SBLKCTL) & ~SELBUSB, SBLKCTL);
8317 /* Reset SCSI bus A. */
8318 if (aic7xxx_verbose & VERBOSE_PROBE2)
8319 { /* In case we are a 3940, 3985, or 7895, print the right channel */
8320 char *channel = "";
8321 if (p->flags & AHC_MULTI_CHANNEL)
8323 channel = " A";
8324 if (p->flags & (AHC_CHNLB|AHC_CHNLC))
8325 channel = (p->flags & AHC_CHNLB) ? " B" : " C";
8327 printk(KERN_INFO "(scsi%d) Resetting channel%s\n", p->host_no, channel);
8330 aic7xxx_reset_current_bus(p);
8333 else
8335 if (!reset_delay)
8337 printk(KERN_INFO "(scsi%d) Not resetting SCSI bus. Note: Don't use "
8338 "the no_reset\n", p->host_no);
8339 printk(KERN_INFO "(scsi%d) option unless you have a verifiable need "
8340 "for it.\n", p->host_no);
8345 * Register IRQ with the kernel. Only allow sharing IRQs with
8346 * PCI devices.
8348 if (!(p->chip & AHC_PCI))
8350 result = (request_irq(p->irq, do_aic7xxx_isr, 0, "aic7xxx", p));
8352 else
8354 result = (request_irq(p->irq, do_aic7xxx_isr, SA_SHIRQ,
8355 "aic7xxx", p));
8356 if (result < 0)
8358 result = (request_irq(p->irq, do_aic7xxx_isr, SA_INTERRUPT | SA_SHIRQ,
8359 "aic7xxx", p));
8362 if (result < 0)
8364 printk(KERN_WARNING "(scsi%d) Couldn't register IRQ %d, ignoring "
8365 "controller.\n", p->host_no, p->irq);
8366 aic_outb(p, 0, SIMODE1);
8367 p->irq = 0;
8368 return (0);
8371 if(aic_inb(p, INTSTAT) & INT_PEND)
8372 printk(INFO_LEAD "spurious interrupt during configuration, cleared.\n",
8373 p->host_no, -1, -1 , -1);
8374 aic7xxx_clear_intstat(p);
8376 unpause_sequencer(p, /* unpause_always */ TRUE);
8378 return (found);
8381 /*+F*************************************************************************
8382 * Function:
8383 * aic7xxx_chip_reset
8385 * Description:
8386 * Perform a chip reset on the aic7xxx SCSI controller. The controller
8387 * is paused upon return.
8388 *-F*************************************************************************/
8390 aic7xxx_chip_reset(struct aic7xxx_host *p)
8392 unsigned char sblkctl;
8393 int wait;
8396 * For some 274x boards, we must clear the CHIPRST bit and pause
8397 * the sequencer. For some reason, this makes the driver work.
8399 aic_outb(p, PAUSE | CHIPRST, HCNTRL);
8402 * In the future, we may call this function as a last resort for
8403 * error handling. Let's be nice and not do any unnecessary delays.
8405 wait = 1000; /* 1 msec (1000 * 1 msec) */
8406 while (--wait && !(aic_inb(p, HCNTRL) & CHIPRSTACK))
8408 udelay(1); /* 1 usec */
8411 pause_sequencer(p);
8413 sblkctl = aic_inb(p, SBLKCTL) & (SELBUSB|SELWIDE);
8414 if (p->chip & AHC_PCI)
8415 sblkctl &= ~SELBUSB;
8416 switch( sblkctl )
8418 case 0: /* normal narrow card */
8419 break;
8420 case 2: /* Wide card */
8421 p->features |= AHC_WIDE;
8422 break;
8423 case 8: /* Twin card */
8424 p->features |= AHC_TWIN;
8425 p->flags |= AHC_MULTI_CHANNEL;
8426 break;
8427 default: /* hmmm...we don't know what this is */
8428 printk(KERN_WARNING "aic7xxx: Unsupported adapter type %d, ignoring.\n",
8429 aic_inb(p, SBLKCTL) & 0x0a);
8430 return(-1);
8432 return(0);
8435 /*+F*************************************************************************
8436 * Function:
8437 * aic7xxx_alloc
8439 * Description:
8440 * Allocate and initialize a host structure. Returns NULL upon error
8441 * and a pointer to a aic7xxx_host struct upon success.
8442 *-F*************************************************************************/
8443 static struct aic7xxx_host *
8444 aic7xxx_alloc(Scsi_Host_Template *sht, struct aic7xxx_host *temp)
8446 struct aic7xxx_host *p = NULL;
8447 struct Scsi_Host *host;
8450 * Allocate a storage area by registering us with the mid-level
8451 * SCSI layer.
8453 host = scsi_register(sht, sizeof(struct aic7xxx_host));
8455 if (host != NULL)
8457 p = (struct aic7xxx_host *) host->hostdata;
8458 memset(p, 0, sizeof(struct aic7xxx_host));
8459 *p = *temp;
8460 p->host = host;
8462 p->scb_data = kmalloc(sizeof(scb_data_type), GFP_ATOMIC);
8463 if (p->scb_data != NULL)
8465 memset(p->scb_data, 0, sizeof(scb_data_type));
8466 scbq_init (&p->scb_data->free_scbs);
8468 else
8471 * For some reason we don't have enough memory. Free the
8472 * allocated memory for the aic7xxx_host struct, and return NULL.
8474 release_region(p->base, MAXREG - MINREG);
8475 scsi_unregister(host);
8476 return(NULL);
8478 p->host_no = host->host_no;
8480 scsi_set_pci_device(host, p->pdev);
8481 return (p);
8484 /*+F*************************************************************************
8485 * Function:
8486 * aic7xxx_free
8488 * Description:
8489 * Frees and releases all resources associated with an instance of
8490 * the driver (struct aic7xxx_host *).
8491 *-F*************************************************************************/
8492 static void
8493 aic7xxx_free(struct aic7xxx_host *p)
8495 int i;
8498 * Free the allocated hardware SCB space.
8500 if (p->scb_data != NULL)
8502 struct aic7xxx_scb_dma *scb_dma = NULL;
8503 if (p->scb_data->hscbs != NULL)
8505 pci_free_consistent(p->pdev, p->scb_data->hscbs_dma_len,
8506 p->scb_data->hscbs, p->scb_data->hscbs_dma);
8507 p->scb_data->hscbs = p->scb_data->hscb_kmalloc_ptr = NULL;
8510 * Free the driver SCBs. These were allocated on an as-need
8511 * basis. We allocated these in groups depending on how many
8512 * we could fit into a given amount of RAM. The tail SCB for
8513 * these allocations has a pointer to the alloced area.
8515 for (i = 0; i < p->scb_data->numscbs; i++)
8517 if (p->scb_data->scb_array[i]->scb_dma != scb_dma)
8519 scb_dma = p->scb_data->scb_array[i]->scb_dma;
8520 pci_free_consistent(p->pdev, scb_dma->dma_len,
8521 (void *)((unsigned long)scb_dma->dma_address
8522 - scb_dma->dma_offset),
8523 scb_dma->dma_address);
8525 if (p->scb_data->scb_array[i]->kmalloc_ptr != NULL)
8526 kfree(p->scb_data->scb_array[i]->kmalloc_ptr);
8527 p->scb_data->scb_array[i] = NULL;
8531 * Free the SCB data area.
8533 kfree(p->scb_data);
8536 pci_free_consistent(p->pdev, 3*256, (void *)p->untagged_scbs, p->fifo_dma);
8539 /*+F*************************************************************************
8540 * Function:
8541 * aic7xxx_load_seeprom
8543 * Description:
8544 * Load the seeprom and configure adapter and target settings.
8545 * Returns 1 if the load was successful and 0 otherwise.
8546 *-F*************************************************************************/
8547 static void
8548 aic7xxx_load_seeprom(struct aic7xxx_host *p, unsigned char *sxfrctl1)
8550 int have_seeprom = 0;
8551 int i, max_targets, mask;
8552 unsigned char scsirate, scsi_conf;
8553 unsigned short scarray[128];
8554 struct seeprom_config *sc = (struct seeprom_config *) scarray;
8556 if (aic7xxx_verbose & VERBOSE_PROBE2)
8558 printk(KERN_INFO "aic7xxx: Loading serial EEPROM...");
8560 switch (p->chip)
8562 case (AHC_AIC7770|AHC_EISA): /* None of these adapters have seeproms. */
8563 if (aic_inb(p, SCSICONF) & TERM_ENB)
8564 p->flags |= AHC_TERM_ENB_A;
8565 if ( (p->features & AHC_TWIN) && (aic_inb(p, SCSICONF + 1) & TERM_ENB) )
8566 p->flags |= AHC_TERM_ENB_B;
8567 break;
8569 case (AHC_AIC7770|AHC_VL):
8570 have_seeprom = read_284x_seeprom(p, (struct seeprom_config *) scarray);
8571 break;
8573 default:
8574 have_seeprom = read_seeprom(p, (p->flags & (AHC_CHNLB|AHC_CHNLC)),
8575 scarray, p->sc_size, p->sc_type);
8576 if (!have_seeprom)
8578 if(p->sc_type == C46)
8579 have_seeprom = read_seeprom(p, (p->flags & (AHC_CHNLB|AHC_CHNLC)),
8580 scarray, p->sc_size, C56_66);
8581 else
8582 have_seeprom = read_seeprom(p, (p->flags & (AHC_CHNLB|AHC_CHNLC)),
8583 scarray, p->sc_size, C46);
8585 if (!have_seeprom)
8587 p->sc_size = 128;
8588 have_seeprom = read_seeprom(p, 4*(p->flags & (AHC_CHNLB|AHC_CHNLC)),
8589 scarray, p->sc_size, p->sc_type);
8590 if (!have_seeprom)
8592 if(p->sc_type == C46)
8593 have_seeprom = read_seeprom(p, 4*(p->flags & (AHC_CHNLB|AHC_CHNLC)),
8594 scarray, p->sc_size, C56_66);
8595 else
8596 have_seeprom = read_seeprom(p, 4*(p->flags & (AHC_CHNLB|AHC_CHNLC)),
8597 scarray, p->sc_size, C46);
8600 break;
8603 if (!have_seeprom)
8605 if (aic7xxx_verbose & VERBOSE_PROBE2)
8607 printk("\naic7xxx: No SEEPROM available.\n");
8609 p->flags |= AHC_NEWEEPROM_FMT;
8610 if (aic_inb(p, SCSISEQ) == 0)
8612 p->flags |= AHC_USEDEFAULTS;
8613 p->flags &= ~AHC_BIOS_ENABLED;
8614 p->scsi_id = p->scsi_id_b = 7;
8615 *sxfrctl1 |= STPWEN;
8616 if (aic7xxx_verbose & VERBOSE_PROBE2)
8618 printk("aic7xxx: Using default values.\n");
8621 else if (aic7xxx_verbose & VERBOSE_PROBE2)
8623 printk("aic7xxx: Using leftover BIOS values.\n");
8625 if ( ((p->chip & ~AHC_CHIPID_MASK) == AHC_PCI) && (*sxfrctl1 & STPWEN) )
8627 p->flags |= AHC_TERM_ENB_SE_LOW | AHC_TERM_ENB_SE_HIGH;
8628 sc->adapter_control &= ~CFAUTOTERM;
8629 sc->adapter_control |= CFSTERM | CFWSTERM | CFLVDSTERM;
8631 if (aic7xxx_extended)
8632 p->flags |= (AHC_EXTEND_TRANS_A | AHC_EXTEND_TRANS_B);
8633 else
8634 p->flags &= ~(AHC_EXTEND_TRANS_A | AHC_EXTEND_TRANS_B);
8636 else
8638 if (aic7xxx_verbose & VERBOSE_PROBE2)
8640 printk("done\n");
8644 * Note things in our flags
8646 p->flags |= AHC_SEEPROM_FOUND;
8649 * Update the settings in sxfrctl1 to match the termination settings.
8651 *sxfrctl1 = 0;
8654 * Get our SCSI ID from the SEEPROM setting...
8656 p->scsi_id = (sc->brtime_id & CFSCSIID);
8659 * First process the settings that are different between the VLB
8660 * and PCI adapter seeproms.
8662 if ((p->chip & AHC_CHIPID_MASK) == AHC_AIC7770)
8664 /* VLB adapter seeproms */
8665 if (sc->bios_control & CF284XEXTEND)
8666 p->flags |= AHC_EXTEND_TRANS_A;
8668 if (sc->adapter_control & CF284XSTERM)
8670 *sxfrctl1 |= STPWEN;
8671 p->flags |= AHC_TERM_ENB_SE_LOW | AHC_TERM_ENB_SE_HIGH;
8674 else
8676 /* PCI adapter seeproms */
8677 if (sc->bios_control & CFEXTEND)
8678 p->flags |= AHC_EXTEND_TRANS_A;
8679 if (sc->bios_control & CFBIOSEN)
8680 p->flags |= AHC_BIOS_ENABLED;
8681 else
8682 p->flags &= ~AHC_BIOS_ENABLED;
8684 if (sc->adapter_control & CFSTERM)
8686 *sxfrctl1 |= STPWEN;
8687 p->flags |= AHC_TERM_ENB_SE_LOW | AHC_TERM_ENB_SE_HIGH;
8690 memcpy(&p->sc, sc, sizeof(struct seeprom_config));
8693 p->discenable = 0;
8696 * Limit to 16 targets just in case. The 2842 for one is known to
8697 * blow the max_targets setting, future cards might also.
8699 max_targets = ((p->features & (AHC_TWIN | AHC_WIDE)) ? 16 : 8);
8701 if (have_seeprom)
8703 for (i = 0; i < max_targets; i++)
8705 if( ((p->features & AHC_ULTRA) &&
8706 !(sc->adapter_control & CFULTRAEN) &&
8707 (sc->device_flags[i] & CFSYNCHISULTRA)) ||
8708 (sc->device_flags[i] & CFNEWULTRAFORMAT) )
8710 p->flags |= AHC_NEWEEPROM_FMT;
8711 break;
8716 for (i = 0; i < max_targets; i++)
8718 mask = (0x01 << i);
8719 if (!have_seeprom)
8721 if (aic_inb(p, SCSISEQ) != 0)
8724 * OK...the BIOS set things up and left behind the settings we need.
8725 * Just make our sc->device_flags[i] entry match what the card has
8726 * set for this device.
8728 p->discenable =
8729 ~(aic_inb(p, DISC_DSB) | (aic_inb(p, DISC_DSB + 1) << 8) );
8730 p->ultraenb =
8731 (aic_inb(p, ULTRA_ENB) | (aic_inb(p, ULTRA_ENB + 1) << 8) );
8732 sc->device_flags[i] = (p->discenable & mask) ? CFDISC : 0;
8733 if (aic_inb(p, TARG_SCSIRATE + i) & WIDEXFER)
8734 sc->device_flags[i] |= CFWIDEB;
8735 if (p->features & AHC_ULTRA2)
8737 if (aic_inb(p, TARG_OFFSET + i))
8739 sc->device_flags[i] |= CFSYNCH;
8740 sc->device_flags[i] |= (aic_inb(p, TARG_SCSIRATE + i) & 0x07);
8741 if ( (aic_inb(p, TARG_SCSIRATE + i) & 0x18) == 0x18 )
8742 sc->device_flags[i] |= CFSYNCHISULTRA;
8745 else
8747 if (aic_inb(p, TARG_SCSIRATE + i) & ~WIDEXFER)
8749 sc->device_flags[i] |= CFSYNCH;
8750 if (p->features & AHC_ULTRA)
8751 sc->device_flags[i] |= ((p->ultraenb & mask) ?
8752 CFSYNCHISULTRA : 0);
8756 else
8759 * Assume the BIOS has NOT been run on this card and nothing between
8760 * the card and the devices is configured yet.
8762 sc->device_flags[i] = CFDISC;
8763 if (p->features & AHC_WIDE)
8764 sc->device_flags[i] |= CFWIDEB;
8765 if (p->features & AHC_ULTRA3)
8766 sc->device_flags[i] |= 2;
8767 else if (p->features & AHC_ULTRA2)
8768 sc->device_flags[i] |= 3;
8769 else if (p->features & AHC_ULTRA)
8770 sc->device_flags[i] |= CFSYNCHISULTRA;
8771 sc->device_flags[i] |= CFSYNCH;
8772 aic_outb(p, 0, TARG_SCSIRATE + i);
8773 if (p->features & AHC_ULTRA2)
8774 aic_outb(p, 0, TARG_OFFSET + i);
8777 if (sc->device_flags[i] & CFDISC)
8779 p->discenable |= mask;
8781 if (p->flags & AHC_NEWEEPROM_FMT)
8783 if ( !(p->features & AHC_ULTRA2) )
8786 * I know of two different Ultra BIOSes that do this differently.
8787 * One on the Gigabyte 6BXU mb that wants flags[i] & CFXFER to
8788 * be == to 0x03 and SYNCHISULTRA to be true to mean 40MByte/s
8789 * while on the IBM Netfinity 5000 they want the same thing
8790 * to be something else, while flags[i] & CFXFER == 0x03 and
8791 * SYNCHISULTRA false should be 40MByte/s. So, we set both to
8792 * 40MByte/s and the lower speeds be damned. People will have
8793 * to select around the conversely mapped lower speeds in order
8794 * to select lower speeds on these boards.
8796 if ( (sc->device_flags[i] & CFNEWULTRAFORMAT) &&
8797 ((sc->device_flags[i] & CFXFER) == 0x03) )
8799 sc->device_flags[i] &= ~CFXFER;
8800 sc->device_flags[i] |= CFSYNCHISULTRA;
8802 if (sc->device_flags[i] & CFSYNCHISULTRA)
8804 p->ultraenb |= mask;
8807 else if ( !(sc->device_flags[i] & CFNEWULTRAFORMAT) &&
8808 (p->features & AHC_ULTRA2) &&
8809 (sc->device_flags[i] & CFSYNCHISULTRA) )
8811 p->ultraenb |= mask;
8814 else if (sc->adapter_control & CFULTRAEN)
8816 p->ultraenb |= mask;
8818 if ( (sc->device_flags[i] & CFSYNCH) == 0)
8820 sc->device_flags[i] &= ~CFXFER;
8821 p->ultraenb &= ~mask;
8822 p->user[i].offset = 0;
8823 p->user[i].period = 0;
8824 p->user[i].options = 0;
8826 else
8828 if (p->features & AHC_ULTRA3)
8830 p->user[i].offset = MAX_OFFSET_ULTRA2;
8831 if( (sc->device_flags[i] & CFXFER) < 0x03 )
8833 scsirate = (sc->device_flags[i] & CFXFER);
8834 p->user[i].options = MSG_EXT_PPR_OPTION_DT_CRC;
8836 else
8838 scsirate = (sc->device_flags[i] & CFXFER) |
8839 ((p->ultraenb & mask) ? 0x18 : 0x10);
8840 p->user[i].options = 0;
8842 p->user[i].period = aic7xxx_find_period(p, scsirate,
8843 AHC_SYNCRATE_ULTRA3);
8845 else if (p->features & AHC_ULTRA2)
8847 p->user[i].offset = MAX_OFFSET_ULTRA2;
8848 scsirate = (sc->device_flags[i] & CFXFER) |
8849 ((p->ultraenb & mask) ? 0x18 : 0x10);
8850 p->user[i].options = 0;
8851 p->user[i].period = aic7xxx_find_period(p, scsirate,
8852 AHC_SYNCRATE_ULTRA2);
8854 else
8856 scsirate = (sc->device_flags[i] & CFXFER) << 4;
8857 p->user[i].options = 0;
8858 p->user[i].offset = MAX_OFFSET_8BIT;
8859 if (p->features & AHC_ULTRA)
8861 short ultraenb;
8862 ultraenb = aic_inb(p, ULTRA_ENB) |
8863 (aic_inb(p, ULTRA_ENB + 1) << 8);
8864 p->user[i].period = aic7xxx_find_period(p, scsirate,
8865 (p->ultraenb & mask) ?
8866 AHC_SYNCRATE_ULTRA :
8867 AHC_SYNCRATE_FAST);
8869 else
8870 p->user[i].period = aic7xxx_find_period(p, scsirate,
8871 AHC_SYNCRATE_FAST);
8874 if ( (sc->device_flags[i] & CFWIDEB) && (p->features & AHC_WIDE) )
8876 p->user[i].width = MSG_EXT_WDTR_BUS_16_BIT;
8878 else
8880 p->user[i].width = MSG_EXT_WDTR_BUS_8_BIT;
8883 aic_outb(p, ~(p->discenable & 0xFF), DISC_DSB);
8884 aic_outb(p, ~((p->discenable >> 8) & 0xFF), DISC_DSB + 1);
8887 * We set the p->ultraenb from the SEEPROM to begin with, but now we make
8888 * it match what is already down in the card. If we are doing a reset
8889 * on the card then this will get put back to a default state anyway.
8890 * This allows us to not have to pre-emptively negotiate when using the
8891 * no_reset option.
8893 if (p->features & AHC_ULTRA)
8894 p->ultraenb = aic_inb(p, ULTRA_ENB) | (aic_inb(p, ULTRA_ENB + 1) << 8);
8897 scsi_conf = (p->scsi_id & HSCSIID);
8899 if(have_seeprom)
8901 p->adapter_control = sc->adapter_control;
8902 p->bios_control = sc->bios_control;
8904 switch (p->chip & AHC_CHIPID_MASK)
8906 case AHC_AIC7895:
8907 case AHC_AIC7896:
8908 case AHC_AIC7899:
8909 if (p->adapter_control & CFBPRIMARY)
8910 p->flags |= AHC_CHANNEL_B_PRIMARY;
8911 default:
8912 break;
8915 if (sc->adapter_control & CFSPARITY)
8916 scsi_conf |= ENSPCHK;
8918 else
8920 scsi_conf |= ENSPCHK | RESET_SCSI;
8924 * Only set the SCSICONF and SCSICONF + 1 registers if we are a PCI card.
8925 * The 2842 and 2742 cards already have these registers set and we don't
8926 * want to muck with them since we don't set all the bits they do.
8928 if ( (p->chip & ~AHC_CHIPID_MASK) == AHC_PCI )
8930 /* Set the host ID */
8931 aic_outb(p, scsi_conf, SCSICONF);
8932 /* In case we are a wide card */
8933 aic_outb(p, p->scsi_id, SCSICONF + 1);
8937 /*+F*************************************************************************
8938 * Function:
8939 * aic7xxx_configure_bugs
8941 * Description:
8942 * Take the card passed in and set the appropriate bug flags based upon
8943 * the card model. Also make any changes needed to device registers or
8944 * PCI registers while we are here.
8945 *-F*************************************************************************/
8946 static void
8947 aic7xxx_configure_bugs(struct aic7xxx_host *p)
8949 unsigned short tmp_word;
8951 switch(p->chip & AHC_CHIPID_MASK)
8953 case AHC_AIC7860:
8954 p->bugs |= AHC_BUG_PCI_2_1_RETRY;
8955 /* fall through */
8956 case AHC_AIC7850:
8957 case AHC_AIC7870:
8958 p->bugs |= AHC_BUG_TMODE_WIDEODD | AHC_BUG_CACHETHEN | AHC_BUG_PCI_MWI;
8959 break;
8960 case AHC_AIC7880:
8961 p->bugs |= AHC_BUG_TMODE_WIDEODD | AHC_BUG_PCI_2_1_RETRY |
8962 AHC_BUG_CACHETHEN | AHC_BUG_PCI_MWI;
8963 break;
8964 case AHC_AIC7890:
8965 p->bugs |= AHC_BUG_AUTOFLUSH | AHC_BUG_CACHETHEN;
8966 break;
8967 case AHC_AIC7892:
8968 p->bugs |= AHC_BUG_SCBCHAN_UPLOAD;
8969 break;
8970 case AHC_AIC7895:
8971 p->bugs |= AHC_BUG_TMODE_WIDEODD | AHC_BUG_PCI_2_1_RETRY |
8972 AHC_BUG_CACHETHEN | AHC_BUG_PCI_MWI;
8973 break;
8974 case AHC_AIC7896:
8975 p->bugs |= AHC_BUG_CACHETHEN_DIS;
8976 break;
8977 case AHC_AIC7899:
8978 p->bugs |= AHC_BUG_SCBCHAN_UPLOAD;
8979 break;
8980 default:
8981 /* Nothing to do */
8982 break;
8986 * Now handle the bugs that require PCI register or card register tweaks
8988 pci_read_config_word(p->pdev, PCI_COMMAND, &tmp_word);
8989 if(p->bugs & AHC_BUG_PCI_MWI)
8991 tmp_word &= ~PCI_COMMAND_INVALIDATE;
8993 else
8995 tmp_word |= PCI_COMMAND_INVALIDATE;
8997 pci_write_config_word(p->pdev, PCI_COMMAND, tmp_word);
8999 if(p->bugs & AHC_BUG_CACHETHEN)
9001 aic_outb(p, aic_inb(p, DSCOMMAND0) & ~CACHETHEN, DSCOMMAND0);
9003 else if (p->bugs & AHC_BUG_CACHETHEN_DIS)
9005 aic_outb(p, aic_inb(p, DSCOMMAND0) | CACHETHEN, DSCOMMAND0);
9008 return;
9012 /*+F*************************************************************************
9013 * Function:
9014 * aic7xxx_detect
9016 * Description:
9017 * Try to detect and register an Adaptec 7770 or 7870 SCSI controller.
9019 * XXX - This should really be called aic7xxx_probe(). A sequence of
9020 * probe(), attach()/detach(), and init() makes more sense than
9021 * one do-it-all function. This may be useful when (and if) the
9022 * mid-level SCSI code is overhauled.
9023 *-F*************************************************************************/
9025 aic7xxx_detect(Scsi_Host_Template *template)
9027 struct aic7xxx_host *temp_p = NULL;
9028 struct aic7xxx_host *current_p = NULL;
9029 struct aic7xxx_host *list_p = NULL;
9030 int found = 0;
9031 #if defined(__i386__) || defined(__alpha__)
9032 ahc_flag_type flags = 0;
9033 int type;
9034 #endif
9035 unsigned char sxfrctl1;
9036 #if defined(__i386__) || defined(__alpha__)
9037 unsigned char hcntrl, hostconf;
9038 unsigned int slot, base;
9039 #endif
9041 #ifdef MODULE
9043 * If we are called as a module, the aic7xxx pointer may not be null
9044 * and it would point to our bootup string, just like on the lilo
9045 * command line. IF not NULL, then process this config string with
9046 * aic7xxx_setup
9048 if(aic7xxx)
9049 aic7xxx_setup(aic7xxx);
9050 #endif
9052 template->proc_name = "aic7xxx";
9053 template->sg_tablesize = AIC7XXX_MAX_SG;
9054 template->max_sectors = 2048;
9057 #ifdef CONFIG_PCI
9059 * PCI-bus probe.
9061 if (pci_present())
9063 struct
9065 unsigned short vendor_id;
9066 unsigned short device_id;
9067 ahc_chip chip;
9068 ahc_flag_type flags;
9069 ahc_feature features;
9070 int board_name_index;
9071 unsigned short seeprom_size;
9072 unsigned short seeprom_type;
9073 } const aic_pdevs[] = {
9074 {PCI_VENDOR_ID_ADAPTEC, PCI_DEVICE_ID_ADAPTEC_7810, AHC_NONE,
9075 AHC_FNONE, AHC_FENONE, 1,
9076 32, C46 },
9077 {PCI_VENDOR_ID_ADAPTEC, PCI_DEVICE_ID_ADAPTEC_7850, AHC_AIC7850,
9078 AHC_PAGESCBS, AHC_AIC7850_FE, 5,
9079 32, C46 },
9080 {PCI_VENDOR_ID_ADAPTEC, PCI_DEVICE_ID_ADAPTEC_7855, AHC_AIC7850,
9081 AHC_PAGESCBS, AHC_AIC7850_FE, 6,
9082 32, C46 },
9083 {PCI_VENDOR_ID_ADAPTEC, PCI_DEVICE_ID_ADAPTEC_7821, AHC_AIC7860,
9084 AHC_PAGESCBS | AHC_NEWEEPROM_FMT | AHC_BIOS_ENABLED,
9085 AHC_AIC7860_FE, 7,
9086 32, C46 },
9087 {PCI_VENDOR_ID_ADAPTEC, PCI_DEVICE_ID_ADAPTEC_3860, AHC_AIC7860,
9088 AHC_PAGESCBS | AHC_NEWEEPROM_FMT | AHC_BIOS_ENABLED,
9089 AHC_AIC7860_FE, 7,
9090 32, C46 },
9091 {PCI_VENDOR_ID_ADAPTEC, PCI_DEVICE_ID_ADAPTEC_38602, AHC_AIC7860,
9092 AHC_PAGESCBS | AHC_NEWEEPROM_FMT | AHC_BIOS_ENABLED,
9093 AHC_AIC7860_FE, 7,
9094 32, C46 },
9095 {PCI_VENDOR_ID_ADAPTEC, PCI_DEVICE_ID_ADAPTEC_38602, AHC_AIC7860,
9096 AHC_PAGESCBS | AHC_NEWEEPROM_FMT | AHC_BIOS_ENABLED,
9097 AHC_AIC7860_FE, 7,
9098 32, C46 },
9099 {PCI_VENDOR_ID_ADAPTEC, PCI_DEVICE_ID_ADAPTEC_7860, AHC_AIC7860,
9100 AHC_PAGESCBS | AHC_NEWEEPROM_FMT | AHC_BIOS_ENABLED | AHC_MOTHERBOARD,
9101 AHC_AIC7860_FE, 7,
9102 32, C46 },
9103 {PCI_VENDOR_ID_ADAPTEC, PCI_DEVICE_ID_ADAPTEC_7861, AHC_AIC7860,
9104 AHC_PAGESCBS | AHC_NEWEEPROM_FMT | AHC_BIOS_ENABLED,
9105 AHC_AIC7860_FE, 8,
9106 32, C46 },
9107 {PCI_VENDOR_ID_ADAPTEC, PCI_DEVICE_ID_ADAPTEC_7870, AHC_AIC7870,
9108 AHC_PAGESCBS | AHC_BIOS_ENABLED | AHC_MOTHERBOARD,
9109 AHC_AIC7870_FE, 9,
9110 32, C46 },
9111 {PCI_VENDOR_ID_ADAPTEC, PCI_DEVICE_ID_ADAPTEC_7871, AHC_AIC7870,
9112 AHC_PAGESCBS | AHC_BIOS_ENABLED, AHC_AIC7870_FE, 10,
9113 32, C46 },
9114 {PCI_VENDOR_ID_ADAPTEC, PCI_DEVICE_ID_ADAPTEC_7872, AHC_AIC7870,
9115 AHC_PAGESCBS | AHC_BIOS_ENABLED | AHC_MULTI_CHANNEL,
9116 AHC_AIC7870_FE, 11,
9117 32, C56_66 },
9118 {PCI_VENDOR_ID_ADAPTEC, PCI_DEVICE_ID_ADAPTEC_7873, AHC_AIC7870,
9119 AHC_PAGESCBS | AHC_BIOS_ENABLED | AHC_MULTI_CHANNEL,
9120 AHC_AIC7870_FE, 12,
9121 32, C56_66 },
9122 {PCI_VENDOR_ID_ADAPTEC, PCI_DEVICE_ID_ADAPTEC_7874, AHC_AIC7870,
9123 AHC_PAGESCBS | AHC_BIOS_ENABLED, AHC_AIC7870_FE, 13,
9124 32, C46 },
9125 {PCI_VENDOR_ID_ADAPTEC, PCI_DEVICE_ID_ADAPTEC_7880, AHC_AIC7880,
9126 AHC_PAGESCBS | AHC_BIOS_ENABLED | AHC_MOTHERBOARD,
9127 AHC_AIC7880_FE, 14,
9128 32, C46 },
9129 {PCI_VENDOR_ID_ADAPTEC, PCI_DEVICE_ID_ADAPTEC_7881, AHC_AIC7880,
9130 AHC_PAGESCBS | AHC_BIOS_ENABLED, AHC_AIC7880_FE, 15,
9131 32, C46 },
9132 {PCI_VENDOR_ID_ADAPTEC, PCI_DEVICE_ID_ADAPTEC_7882, AHC_AIC7880,
9133 AHC_PAGESCBS | AHC_BIOS_ENABLED | AHC_MULTI_CHANNEL,
9134 AHC_AIC7880_FE, 16,
9135 32, C56_66 },
9136 {PCI_VENDOR_ID_ADAPTEC, PCI_DEVICE_ID_ADAPTEC_7883, AHC_AIC7880,
9137 AHC_PAGESCBS | AHC_BIOS_ENABLED | AHC_MULTI_CHANNEL,
9138 AHC_AIC7880_FE, 17,
9139 32, C56_66 },
9140 {PCI_VENDOR_ID_ADAPTEC, PCI_DEVICE_ID_ADAPTEC_7884, AHC_AIC7880,
9141 AHC_PAGESCBS | AHC_BIOS_ENABLED, AHC_AIC7880_FE, 18,
9142 32, C46 },
9143 {PCI_VENDOR_ID_ADAPTEC, PCI_DEVICE_ID_ADAPTEC_7885, AHC_AIC7880,
9144 AHC_PAGESCBS | AHC_BIOS_ENABLED, AHC_AIC7880_FE, 18,
9145 32, C46 },
9146 {PCI_VENDOR_ID_ADAPTEC, PCI_DEVICE_ID_ADAPTEC_7886, AHC_AIC7880,
9147 AHC_PAGESCBS | AHC_BIOS_ENABLED, AHC_AIC7880_FE, 18,
9148 32, C46 },
9149 {PCI_VENDOR_ID_ADAPTEC, PCI_DEVICE_ID_ADAPTEC_7887, AHC_AIC7880,
9150 AHC_PAGESCBS | AHC_BIOS_ENABLED, AHC_AIC7880_FE | AHC_NEW_AUTOTERM, 19,
9151 32, C46 },
9152 {PCI_VENDOR_ID_ADAPTEC, PCI_DEVICE_ID_ADAPTEC_7888, AHC_AIC7880,
9153 AHC_PAGESCBS | AHC_BIOS_ENABLED, AHC_AIC7880_FE, 18,
9154 32, C46 },
9155 {PCI_VENDOR_ID_ADAPTEC, PCI_DEVICE_ID_ADAPTEC_7895, AHC_AIC7895,
9156 AHC_PAGESCBS | AHC_NEWEEPROM_FMT | AHC_BIOS_ENABLED | AHC_MULTI_CHANNEL,
9157 AHC_AIC7895_FE, 20,
9158 32, C56_66 },
9159 {PCI_VENDOR_ID_ADAPTEC2, PCI_DEVICE_ID_ADAPTEC2_7890, AHC_AIC7890,
9160 AHC_PAGESCBS | AHC_NEWEEPROM_FMT | AHC_BIOS_ENABLED,
9161 AHC_AIC7890_FE, 21,
9162 32, C46 },
9163 {PCI_VENDOR_ID_ADAPTEC2, PCI_DEVICE_ID_ADAPTEC2_7890B, AHC_AIC7890,
9164 AHC_PAGESCBS | AHC_NEWEEPROM_FMT | AHC_BIOS_ENABLED,
9165 AHC_AIC7890_FE, 21,
9166 32, C46 },
9167 {PCI_VENDOR_ID_ADAPTEC2, PCI_DEVICE_ID_ADAPTEC2_2930U2, AHC_AIC7890,
9168 AHC_PAGESCBS | AHC_NEWEEPROM_FMT | AHC_BIOS_ENABLED,
9169 AHC_AIC7890_FE, 22,
9170 32, C46 },
9171 {PCI_VENDOR_ID_ADAPTEC2, PCI_DEVICE_ID_ADAPTEC2_2940U2, AHC_AIC7890,
9172 AHC_PAGESCBS | AHC_NEWEEPROM_FMT | AHC_BIOS_ENABLED,
9173 AHC_AIC7890_FE, 23,
9174 32, C46 },
9175 {PCI_VENDOR_ID_ADAPTEC2, PCI_DEVICE_ID_ADAPTEC2_7896, AHC_AIC7896,
9176 AHC_PAGESCBS | AHC_NEWEEPROM_FMT | AHC_BIOS_ENABLED | AHC_MULTI_CHANNEL,
9177 AHC_AIC7896_FE, 24,
9178 32, C56_66 },
9179 {PCI_VENDOR_ID_ADAPTEC2, PCI_DEVICE_ID_ADAPTEC2_3940U2, AHC_AIC7896,
9180 AHC_PAGESCBS | AHC_NEWEEPROM_FMT | AHC_BIOS_ENABLED | AHC_MULTI_CHANNEL,
9181 AHC_AIC7896_FE, 25,
9182 32, C56_66 },
9183 {PCI_VENDOR_ID_ADAPTEC2, PCI_DEVICE_ID_ADAPTEC2_3950U2D, AHC_AIC7896,
9184 AHC_PAGESCBS | AHC_NEWEEPROM_FMT | AHC_BIOS_ENABLED | AHC_MULTI_CHANNEL,
9185 AHC_AIC7896_FE, 26,
9186 32, C56_66 },
9187 {PCI_VENDOR_ID_ADAPTEC, PCI_DEVICE_ID_ADAPTEC_1480A, AHC_AIC7860,
9188 AHC_PAGESCBS | AHC_NEWEEPROM_FMT | AHC_BIOS_ENABLED | AHC_NO_STPWEN,
9189 AHC_AIC7860_FE, 27,
9190 32, C46 },
9191 {PCI_VENDOR_ID_ADAPTEC2, PCI_DEVICE_ID_ADAPTEC2_7892A, AHC_AIC7892,
9192 AHC_PAGESCBS | AHC_NEWEEPROM_FMT | AHC_BIOS_ENABLED,
9193 AHC_AIC7892_FE, 28,
9194 32, C46 },
9195 {PCI_VENDOR_ID_ADAPTEC2, PCI_DEVICE_ID_ADAPTEC2_7892B, AHC_AIC7892,
9196 AHC_PAGESCBS | AHC_NEWEEPROM_FMT | AHC_BIOS_ENABLED,
9197 AHC_AIC7892_FE, 28,
9198 32, C46 },
9199 {PCI_VENDOR_ID_ADAPTEC2, PCI_DEVICE_ID_ADAPTEC2_7892D, AHC_AIC7892,
9200 AHC_PAGESCBS | AHC_NEWEEPROM_FMT | AHC_BIOS_ENABLED,
9201 AHC_AIC7892_FE, 28,
9202 32, C46 },
9203 {PCI_VENDOR_ID_ADAPTEC2, PCI_DEVICE_ID_ADAPTEC2_7892P, AHC_AIC7892,
9204 AHC_PAGESCBS | AHC_NEWEEPROM_FMT | AHC_BIOS_ENABLED,
9205 AHC_AIC7892_FE, 28,
9206 32, C46 },
9207 {PCI_VENDOR_ID_ADAPTEC2, PCI_DEVICE_ID_ADAPTEC2_7899A, AHC_AIC7899,
9208 AHC_PAGESCBS | AHC_NEWEEPROM_FMT | AHC_BIOS_ENABLED | AHC_MULTI_CHANNEL,
9209 AHC_AIC7899_FE, 29,
9210 32, C56_66 },
9211 {PCI_VENDOR_ID_ADAPTEC2, PCI_DEVICE_ID_ADAPTEC2_7899B, AHC_AIC7899,
9212 AHC_PAGESCBS | AHC_NEWEEPROM_FMT | AHC_BIOS_ENABLED | AHC_MULTI_CHANNEL,
9213 AHC_AIC7899_FE, 29,
9214 32, C56_66 },
9215 {PCI_VENDOR_ID_ADAPTEC2, PCI_DEVICE_ID_ADAPTEC2_7899D, AHC_AIC7899,
9216 AHC_PAGESCBS | AHC_NEWEEPROM_FMT | AHC_BIOS_ENABLED | AHC_MULTI_CHANNEL,
9217 AHC_AIC7899_FE, 29,
9218 32, C56_66 },
9219 {PCI_VENDOR_ID_ADAPTEC2, PCI_DEVICE_ID_ADAPTEC2_7899P, AHC_AIC7899,
9220 AHC_PAGESCBS | AHC_NEWEEPROM_FMT | AHC_BIOS_ENABLED | AHC_MULTI_CHANNEL,
9221 AHC_AIC7899_FE, 29,
9222 32, C56_66 },
9225 unsigned short command;
9226 unsigned int devconfig, i, oldverbose;
9227 struct pci_dev *pdev = NULL;
9229 for (i = 0; i < NUMBER(aic_pdevs); i++)
9231 pdev = NULL;
9232 while ((pdev = pci_find_device(aic_pdevs[i].vendor_id,
9233 aic_pdevs[i].device_id,
9234 pdev))) {
9235 if (pci_enable_device(pdev))
9236 continue;
9237 if ( i == 0 ) /* We found one, but it's the 7810 RAID cont. */
9239 if (aic7xxx_verbose & (VERBOSE_PROBE|VERBOSE_PROBE2))
9241 printk(KERN_INFO "aic7xxx: The 7810 RAID controller is not "
9242 "supported by\n");
9243 printk(KERN_INFO " this driver, we are ignoring it.\n");
9246 else if ( (temp_p = kmalloc(sizeof(struct aic7xxx_host),
9247 GFP_ATOMIC)) != NULL )
9249 memset(temp_p, 0, sizeof(struct aic7xxx_host));
9250 temp_p->chip = aic_pdevs[i].chip | AHC_PCI;
9251 temp_p->flags = aic_pdevs[i].flags;
9252 temp_p->features = aic_pdevs[i].features;
9253 temp_p->board_name_index = aic_pdevs[i].board_name_index;
9254 temp_p->sc_size = aic_pdevs[i].seeprom_size;
9255 temp_p->sc_type = aic_pdevs[i].seeprom_type;
9258 * Read sundry information from PCI BIOS.
9260 temp_p->irq = pdev->irq;
9261 temp_p->pdev = pdev;
9262 temp_p->pci_bus = pdev->bus->number;
9263 temp_p->pci_device_fn = pdev->devfn;
9264 temp_p->base = pci_resource_start(pdev, 0);
9265 temp_p->mbase = pci_resource_start(pdev, 1);
9266 current_p = list_p;
9267 while(current_p && temp_p)
9269 if ( ((current_p->pci_bus == temp_p->pci_bus) &&
9270 (current_p->pci_device_fn == temp_p->pci_device_fn)) ||
9271 (temp_p->base && (current_p->base == temp_p->base)) ||
9272 (temp_p->mbase && (current_p->mbase == temp_p->mbase)) )
9274 /* duplicate PCI entry, skip it */
9275 kfree(temp_p);
9276 temp_p = NULL;
9278 current_p = current_p->next;
9280 if ( temp_p == NULL )
9281 continue;
9282 if (aic7xxx_verbose & VERBOSE_PROBE2)
9283 printk("aic7xxx: <%s> at PCI %d/%d\n",
9284 board_names[aic_pdevs[i].board_name_index],
9285 PCI_SLOT(pdev->devfn),
9286 PCI_FUNC(pdev->devfn));
9287 pci_read_config_word(pdev, PCI_COMMAND, &command);
9288 if (aic7xxx_verbose & VERBOSE_PROBE2)
9290 printk("aic7xxx: Initial PCI_COMMAND value was 0x%x\n",
9291 (int)command);
9293 #ifdef AIC7XXX_STRICT_PCI_SETUP
9294 command |= PCI_COMMAND_SERR | PCI_COMMAND_PARITY |
9295 PCI_COMMAND_MASTER | PCI_COMMAND_MEMORY | PCI_COMMAND_IO;
9296 #else
9297 command |= PCI_COMMAND_MASTER | PCI_COMMAND_MEMORY | PCI_COMMAND_IO;
9298 #endif
9299 command &= ~PCI_COMMAND_INVALIDATE;
9300 if (aic7xxx_pci_parity == 0)
9301 command &= ~(PCI_COMMAND_SERR | PCI_COMMAND_PARITY);
9302 pci_write_config_word(pdev, PCI_COMMAND, command);
9303 #ifdef AIC7XXX_STRICT_PCI_SETUP
9304 pci_read_config_dword(pdev, DEVCONFIG, &devconfig);
9305 if (aic7xxx_verbose & VERBOSE_PROBE2)
9307 printk("aic7xxx: Initial DEVCONFIG value was 0x%x\n", devconfig);
9309 devconfig |= 0x80000040;
9310 pci_write_config_dword(pdev, DEVCONFIG, devconfig);
9311 #endif /* AIC7XXX_STRICT_PCI_SETUP */
9313 if(temp_p->base && !request_region(temp_p->base, MAXREG - MINREG,
9314 "aic7xxx"))
9316 printk("aic7xxx: <%s> at PCI %d/%d/%d\n",
9317 board_names[aic_pdevs[i].board_name_index],
9318 temp_p->pci_bus,
9319 PCI_SLOT(temp_p->pci_device_fn),
9320 PCI_FUNC(temp_p->pci_device_fn));
9321 printk("aic7xxx: I/O ports already in use, ignoring.\n");
9322 kfree(temp_p);
9323 temp_p = NULL;
9324 continue;
9327 temp_p->unpause = INTEN;
9328 temp_p->pause = temp_p->unpause | PAUSE;
9329 if ( ((temp_p->base == 0) &&
9330 (temp_p->mbase == 0)) ||
9331 (temp_p->irq == 0) )
9333 printk("aic7xxx: <%s> at PCI %d/%d/%d\n",
9334 board_names[aic_pdevs[i].board_name_index],
9335 temp_p->pci_bus,
9336 PCI_SLOT(temp_p->pci_device_fn),
9337 PCI_FUNC(temp_p->pci_device_fn));
9338 printk("aic7xxx: Controller disabled by BIOS, ignoring.\n");
9339 kfree(temp_p);
9340 temp_p = NULL;
9341 continue;
9344 #ifdef MMAPIO
9345 if ( !(temp_p->base) || !(temp_p->flags & AHC_MULTI_CHANNEL) ||
9346 ((temp_p->chip != (AHC_AIC7870 | AHC_PCI)) &&
9347 (temp_p->chip != (AHC_AIC7880 | AHC_PCI))) )
9349 unsigned long page_offset, base;
9351 base = temp_p->mbase & PAGE_MASK;
9352 page_offset = temp_p->mbase - base;
9353 temp_p->maddr = ioremap_nocache(base, page_offset + 256);
9354 if(temp_p->maddr)
9356 temp_p->maddr += page_offset;
9358 * We need to check the I/O with the MMAPed address. Some machines
9359 * simply fail to work with MMAPed I/O and certain controllers.
9361 if(aic_inb(temp_p, HCNTRL) == 0xff)
9364 * OK.....we failed our test....go back to programmed I/O
9366 printk(KERN_INFO "aic7xxx: <%s> at PCI %d/%d/%d\n",
9367 board_names[aic_pdevs[i].board_name_index],
9368 temp_p->pci_bus,
9369 PCI_SLOT(temp_p->pci_device_fn),
9370 PCI_FUNC(temp_p->pci_device_fn));
9371 printk(KERN_INFO "aic7xxx: MMAPed I/O failed, reverting to "
9372 "Programmed I/O.\n");
9373 iounmap((void *) (((unsigned long) temp_p->maddr) & PAGE_MASK));
9374 temp_p->maddr = 0;
9375 if(temp_p->base == 0)
9377 printk("aic7xxx: <%s> at PCI %d/%d/%d\n",
9378 board_names[aic_pdevs[i].board_name_index],
9379 temp_p->pci_bus,
9380 PCI_SLOT(temp_p->pci_device_fn),
9381 PCI_FUNC(temp_p->pci_device_fn));
9382 printk("aic7xxx: Controller disabled by BIOS, ignoring.\n");
9383 kfree(temp_p);
9384 temp_p = NULL;
9385 continue;
9390 #endif
9393 * We HAVE to make sure the first pause_sequencer() and all other
9394 * subsequent I/O that isn't PCI config space I/O takes place
9395 * after the MMAPed I/O region is configured and tested. The
9396 * problem is the PowerPC architecture that doesn't support
9397 * programmed I/O at all, so we have to have the MMAP I/O set up
9398 * for this pause to even work on those machines.
9400 pause_sequencer(temp_p);
9403 * Clear out any pending PCI error status messages. Also set
9404 * verbose to 0 so that we don't emit strange PCI error messages
9405 * while cleaning out the current status bits.
9407 oldverbose = aic7xxx_verbose;
9408 aic7xxx_verbose = 0;
9409 aic7xxx_pci_intr(temp_p);
9410 aic7xxx_verbose = oldverbose;
9412 temp_p->bios_address = 0;
9415 * Remember how the card was setup in case there is no seeprom.
9417 if (temp_p->features & AHC_ULTRA2)
9418 temp_p->scsi_id = aic_inb(temp_p, SCSIID_ULTRA2) & OID;
9419 else
9420 temp_p->scsi_id = aic_inb(temp_p, SCSIID) & OID;
9422 * Get current termination setting
9424 sxfrctl1 = aic_inb(temp_p, SXFRCTL1);
9426 if (aic7xxx_chip_reset(temp_p) == -1)
9428 release_region(temp_p->base, MAXREG - MINREG);
9429 kfree(temp_p);
9430 temp_p = NULL;
9431 continue;
9434 * Very quickly put the term setting back into the register since
9435 * the chip reset may cause odd things to happen. This is to keep
9436 * LVD busses with lots of drives from draining the power out of
9437 * the diffsense line before we get around to running the
9438 * configure_termination() function. Also restore the STPWLEVEL
9439 * bit of DEVCONFIG
9441 aic_outb(temp_p, sxfrctl1, SXFRCTL1);
9442 pci_write_config_dword(temp_p->pdev, DEVCONFIG, devconfig);
9443 sxfrctl1 &= STPWEN;
9446 * We need to set the CHNL? assignments before loading the SEEPROM
9447 * The 3940 and 3985 cards (original stuff, not any of the later
9448 * stuff) are 7870 and 7880 class chips. The Ultra2 stuff falls
9449 * under 7896 and 7897. The 7895 is in a class by itself :)
9451 switch (temp_p->chip & AHC_CHIPID_MASK)
9453 case AHC_AIC7870: /* 3840 / 3985 */
9454 case AHC_AIC7880: /* 3840 UW / 3985 UW */
9455 if(temp_p->flags & AHC_MULTI_CHANNEL)
9457 switch(PCI_SLOT(temp_p->pci_device_fn))
9459 case 5:
9460 temp_p->flags |= AHC_CHNLB;
9461 break;
9462 case 8:
9463 temp_p->flags |= AHC_CHNLB;
9464 break;
9465 case 12:
9466 temp_p->flags |= AHC_CHNLC;
9467 break;
9468 default:
9469 break;
9472 break;
9474 case AHC_AIC7895: /* 7895 */
9475 case AHC_AIC7896: /* 7896/7 */
9476 case AHC_AIC7899: /* 7899 */
9477 if (PCI_FUNC(pdev->devfn) != 0)
9479 temp_p->flags |= AHC_CHNLB;
9482 * The 7895 is the only chipset that sets the SCBSIZE32 param
9483 * in the DEVCONFIG register. The Ultra2 chipsets use
9484 * the DSCOMMAND0 register instead.
9486 if ((temp_p->chip & AHC_CHIPID_MASK) == AHC_AIC7895)
9488 pci_read_config_dword(pdev, DEVCONFIG, &devconfig);
9489 devconfig |= SCBSIZE32;
9490 pci_write_config_dword(pdev, DEVCONFIG, devconfig);
9492 break;
9493 default:
9494 break;
9498 * Loading of the SEEPROM needs to come after we've set the flags
9499 * to indicate possible CHNLB and CHNLC assigments. Otherwise,
9500 * on 394x and 398x cards we'll end up reading the wrong settings
9501 * for channels B and C
9503 switch (temp_p->chip & AHC_CHIPID_MASK)
9505 case AHC_AIC7892:
9506 case AHC_AIC7899:
9507 aic_outb(temp_p, 0, SCAMCTL);
9509 * Switch to the alt mode of the chip...
9511 aic_outb(temp_p, aic_inb(temp_p, SFUNCT) | ALT_MODE, SFUNCT);
9513 * Set our options...the last two items set our CRC after x byte
9514 * count in target mode...
9516 aic_outb(temp_p, AUTO_MSGOUT_DE | DIS_MSGIN_DUALEDGE, OPTIONMODE);
9517 aic_outb(temp_p, 0x00, 0x0b);
9518 aic_outb(temp_p, 0x10, 0x0a);
9520 * switch back to normal mode...
9522 aic_outb(temp_p, aic_inb(temp_p, SFUNCT) & ~ALT_MODE, SFUNCT);
9523 aic_outb(temp_p, CRCVALCHKEN | CRCENDCHKEN | CRCREQCHKEN |
9524 TARGCRCENDEN | TARGCRCCNTEN,
9525 CRCCONTROL1);
9526 aic_outb(temp_p, ((aic_inb(temp_p, DSCOMMAND0) | USCBSIZE32 |
9527 MPARCKEN | CIOPARCKEN | CACHETHEN) &
9528 ~DPARCKEN), DSCOMMAND0);
9529 aic7xxx_load_seeprom(temp_p, &sxfrctl1);
9530 break;
9531 case AHC_AIC7890:
9532 case AHC_AIC7896:
9533 aic_outb(temp_p, 0, SCAMCTL);
9534 aic_outb(temp_p, (aic_inb(temp_p, DSCOMMAND0) |
9535 CACHETHEN | MPARCKEN | USCBSIZE32 |
9536 CIOPARCKEN) & ~DPARCKEN, DSCOMMAND0);
9537 aic7xxx_load_seeprom(temp_p, &sxfrctl1);
9538 break;
9539 case AHC_AIC7850:
9540 case AHC_AIC7860:
9542 * Set the DSCOMMAND0 register on these cards different from
9543 * on the 789x cards. Also, read the SEEPROM as well.
9545 aic_outb(temp_p, (aic_inb(temp_p, DSCOMMAND0) |
9546 CACHETHEN | MPARCKEN) & ~DPARCKEN,
9547 DSCOMMAND0);
9548 /* FALLTHROUGH */
9549 default:
9550 aic7xxx_load_seeprom(temp_p, &sxfrctl1);
9551 break;
9552 case AHC_AIC7880:
9554 * Check the rev of the chipset before we change DSCOMMAND0
9556 pci_read_config_dword(pdev, DEVCONFIG, &devconfig);
9557 if ((devconfig & 0xff) >= 1)
9559 aic_outb(temp_p, (aic_inb(temp_p, DSCOMMAND0) |
9560 CACHETHEN | MPARCKEN) & ~DPARCKEN,
9561 DSCOMMAND0);
9563 aic7xxx_load_seeprom(temp_p, &sxfrctl1);
9564 break;
9569 * and then we need another switch based on the type in order to
9570 * make sure the channel B primary flag is set properly on 7895
9571 * controllers....Arrrgggghhh!!! We also have to catch the fact
9572 * that when you disable the BIOS on the 7895 on the Intel DK440LX
9573 * motherboard, and possibly others, it only sets the BIOS disabled
9574 * bit on the A channel...I think I'm starting to lean towards
9575 * going postal....
9577 switch(temp_p->chip & AHC_CHIPID_MASK)
9579 case AHC_AIC7895:
9580 case AHC_AIC7896:
9581 case AHC_AIC7899:
9582 current_p = list_p;
9583 while(current_p != NULL)
9585 if ( (current_p->pci_bus == temp_p->pci_bus) &&
9586 (PCI_SLOT(current_p->pci_device_fn) ==
9587 PCI_SLOT(temp_p->pci_device_fn)) )
9589 if ( PCI_FUNC(current_p->pci_device_fn) == 0 )
9591 temp_p->flags |=
9592 (current_p->flags & AHC_CHANNEL_B_PRIMARY);
9593 temp_p->flags &= ~(AHC_BIOS_ENABLED|AHC_USEDEFAULTS);
9594 temp_p->flags |=
9595 (current_p->flags & (AHC_BIOS_ENABLED|AHC_USEDEFAULTS));
9597 else
9599 current_p->flags |=
9600 (temp_p->flags & AHC_CHANNEL_B_PRIMARY);
9601 current_p->flags &= ~(AHC_BIOS_ENABLED|AHC_USEDEFAULTS);
9602 current_p->flags |=
9603 (temp_p->flags & (AHC_BIOS_ENABLED|AHC_USEDEFAULTS));
9606 current_p = current_p->next;
9608 break;
9609 default:
9610 break;
9614 * We only support external SCB RAM on the 7895/6/7 chipsets.
9615 * We could support it on the 7890/1 easy enough, but I don't
9616 * know of any 7890/1 based cards that have it. I do know
9617 * of 7895/6/7 cards that have it and they work properly.
9619 switch(temp_p->chip & AHC_CHIPID_MASK)
9621 default:
9622 break;
9623 case AHC_AIC7895:
9624 case AHC_AIC7896:
9625 case AHC_AIC7899:
9626 pci_read_config_dword(pdev, DEVCONFIG, &devconfig);
9627 if (temp_p->features & AHC_ULTRA2)
9629 if ( (aic_inb(temp_p, DSCOMMAND0) & RAMPSM_ULTRA2) &&
9630 (aic7xxx_scbram) )
9632 aic_outb(temp_p,
9633 aic_inb(temp_p, DSCOMMAND0) & ~SCBRAMSEL_ULTRA2,
9634 DSCOMMAND0);
9635 temp_p->flags |= AHC_EXTERNAL_SRAM;
9636 devconfig |= EXTSCBPEN;
9638 else if (aic_inb(temp_p, DSCOMMAND0) & RAMPSM_ULTRA2)
9640 printk(KERN_INFO "aic7xxx: <%s> at PCI %d/%d/%d\n",
9641 board_names[aic_pdevs[i].board_name_index],
9642 temp_p->pci_bus,
9643 PCI_SLOT(temp_p->pci_device_fn),
9644 PCI_FUNC(temp_p->pci_device_fn));
9645 printk("aic7xxx: external SCB RAM detected, "
9646 "but not enabled\n");
9649 else
9651 if ((devconfig & RAMPSM) && (aic7xxx_scbram))
9653 devconfig &= ~SCBRAMSEL;
9654 devconfig |= EXTSCBPEN;
9655 temp_p->flags |= AHC_EXTERNAL_SRAM;
9657 else if (devconfig & RAMPSM)
9659 printk(KERN_INFO "aic7xxx: <%s> at PCI %d/%d/%d\n",
9660 board_names[aic_pdevs[i].board_name_index],
9661 temp_p->pci_bus,
9662 PCI_SLOT(temp_p->pci_device_fn),
9663 PCI_FUNC(temp_p->pci_device_fn));
9664 printk("aic7xxx: external SCB RAM detected, "
9665 "but not enabled\n");
9668 pci_write_config_dword(pdev, DEVCONFIG, devconfig);
9669 if ( (temp_p->flags & AHC_EXTERNAL_SRAM) &&
9670 (temp_p->flags & AHC_CHNLB) )
9671 aic_outb(temp_p, 1, CCSCBBADDR);
9672 break;
9676 * Take the LED out of diagnostic mode
9678 aic_outb(temp_p,
9679 (aic_inb(temp_p, SBLKCTL) & ~(DIAGLEDEN | DIAGLEDON)),
9680 SBLKCTL);
9683 * We don't know where this is set in the SEEPROM or by the
9684 * BIOS, so we default to 100%. On Ultra2 controllers, use 75%
9685 * instead.
9687 if (temp_p->features & AHC_ULTRA2)
9689 aic_outb(temp_p, RD_DFTHRSH_MAX | WR_DFTHRSH_MAX, DFF_THRSH);
9691 else
9693 aic_outb(temp_p, DFTHRSH_100, DSPCISTATUS);
9697 * Call our function to fixup any bugs that exist on this chipset.
9698 * This may muck with PCI settings and other device settings, so
9699 * make sure it's after all the other PCI and device register
9700 * tweaks so it can back out bad settings on specific broken cards.
9702 aic7xxx_configure_bugs(temp_p);
9704 if ( list_p == NULL )
9706 list_p = current_p = temp_p;
9708 else
9710 current_p = list_p;
9711 while(current_p->next != NULL)
9712 current_p = current_p->next;
9713 current_p->next = temp_p;
9715 temp_p->next = NULL;
9716 found++;
9717 } /* Found an Adaptec PCI device. */
9718 else /* Well, we found one, but we couldn't get any memory */
9720 printk("aic7xxx: Found <%s>\n",
9721 board_names[aic_pdevs[i].board_name_index]);
9722 printk(KERN_INFO "aic7xxx: Unable to allocate device memory, "
9723 "skipping.\n");
9725 } /* while(pdev=....) */
9726 } /* for PCI_DEVICES */
9727 } /* PCI BIOS present */
9728 #endif /* CONFIG_PCI */
9730 #if defined(__i386__) || defined(__alpha__)
9732 * EISA/VL-bus card signature probe.
9734 slot = MINSLOT;
9735 while ( (slot <= MAXSLOT) &&
9736 !(aic7xxx_no_probe) )
9738 base = SLOTBASE(slot) + MINREG;
9740 if (!request_region(base, MAXREG - MINREG, "aic7xxx"))
9743 * Some other driver has staked a
9744 * claim to this i/o region already.
9746 slot++;
9747 continue; /* back to the beginning of the for loop */
9749 flags = 0;
9750 type = aic7xxx_probe(slot, base + AHC_HID0, &flags);
9751 if (type == -1)
9753 release_region(base, MAXREG - MINREG);
9754 slot++;
9755 continue;
9757 temp_p = kmalloc(sizeof(struct aic7xxx_host), GFP_ATOMIC);
9758 if (temp_p == NULL)
9760 printk(KERN_WARNING "aic7xxx: Unable to allocate device space.\n");
9761 release_region(base, MAXREG - MINREG);
9762 slot++;
9763 continue; /* back to the beginning of the while loop */
9767 * Pause the card preserving the IRQ type. Allow the operator
9768 * to override the IRQ trigger.
9770 if (aic7xxx_irq_trigger == 1)
9771 hcntrl = IRQMS; /* Level */
9772 else if (aic7xxx_irq_trigger == 0)
9773 hcntrl = 0; /* Edge */
9774 else
9775 hcntrl = inb(base + HCNTRL) & IRQMS; /* Default */
9776 memset(temp_p, 0, sizeof(struct aic7xxx_host));
9777 temp_p->unpause = hcntrl | INTEN;
9778 temp_p->pause = hcntrl | PAUSE | INTEN;
9779 temp_p->base = base;
9780 temp_p->mbase = 0;
9781 temp_p->maddr = 0;
9782 temp_p->pci_bus = 0;
9783 temp_p->pci_device_fn = slot;
9784 aic_outb(temp_p, hcntrl | PAUSE, HCNTRL);
9785 while( (aic_inb(temp_p, HCNTRL) & PAUSE) == 0 ) ;
9786 if (aic7xxx_chip_reset(temp_p) == -1)
9787 temp_p->irq = 0;
9788 else
9789 temp_p->irq = aic_inb(temp_p, INTDEF) & 0x0F;
9790 temp_p->flags |= AHC_PAGESCBS;
9792 switch (temp_p->irq)
9794 case 9:
9795 case 10:
9796 case 11:
9797 case 12:
9798 case 14:
9799 case 15:
9800 break;
9802 default:
9803 printk(KERN_WARNING "aic7xxx: Host adapter uses unsupported IRQ "
9804 "level %d, ignoring.\n", temp_p->irq);
9805 kfree(temp_p);
9806 release_region(base, MAXREG - MINREG);
9807 slot++;
9808 continue; /* back to the beginning of the while loop */
9812 * We are commited now, everything has been checked and this card
9813 * has been found, now we just set it up
9817 * Insert our new struct into the list at the end
9819 if (list_p == NULL)
9821 list_p = current_p = temp_p;
9823 else
9825 current_p = list_p;
9826 while (current_p->next != NULL)
9827 current_p = current_p->next;
9828 current_p->next = temp_p;
9831 switch (type)
9833 case 0:
9834 temp_p->board_name_index = 2;
9835 if (aic7xxx_verbose & VERBOSE_PROBE2)
9836 printk("aic7xxx: <%s> at EISA %d\n",
9837 board_names[2], slot);
9838 /* FALLTHROUGH */
9839 case 1:
9841 temp_p->chip = AHC_AIC7770 | AHC_EISA;
9842 temp_p->features |= AHC_AIC7770_FE;
9843 temp_p->bios_control = aic_inb(temp_p, HA_274_BIOSCTRL);
9846 * Get the primary channel information. Right now we don't
9847 * do anything with this, but someday we will be able to inform
9848 * the mid-level SCSI code which channel is primary.
9850 if (temp_p->board_name_index == 0)
9852 temp_p->board_name_index = 3;
9853 if (aic7xxx_verbose & VERBOSE_PROBE2)
9854 printk("aic7xxx: <%s> at EISA %d\n",
9855 board_names[3], slot);
9857 if (temp_p->bios_control & CHANNEL_B_PRIMARY)
9859 temp_p->flags |= AHC_CHANNEL_B_PRIMARY;
9862 if ((temp_p->bios_control & BIOSMODE) == BIOSDISABLED)
9864 temp_p->flags &= ~AHC_BIOS_ENABLED;
9866 else
9868 temp_p->flags &= ~AHC_USEDEFAULTS;
9869 temp_p->flags |= AHC_BIOS_ENABLED;
9870 if ( (temp_p->bios_control & 0x20) == 0 )
9872 temp_p->bios_address = 0xcc000;
9873 temp_p->bios_address += (0x4000 * (temp_p->bios_control & 0x07));
9875 else
9877 temp_p->bios_address = 0xd0000;
9878 temp_p->bios_address += (0x8000 * (temp_p->bios_control & 0x06));
9881 temp_p->adapter_control = aic_inb(temp_p, SCSICONF) << 8;
9882 temp_p->adapter_control |= aic_inb(temp_p, SCSICONF + 1);
9883 if (temp_p->features & AHC_WIDE)
9885 temp_p->scsi_id = temp_p->adapter_control & HWSCSIID;
9886 temp_p->scsi_id_b = temp_p->scsi_id;
9888 else
9890 temp_p->scsi_id = (temp_p->adapter_control >> 8) & HSCSIID;
9891 temp_p->scsi_id_b = temp_p->adapter_control & HSCSIID;
9893 aic7xxx_load_seeprom(temp_p, &sxfrctl1);
9894 break;
9897 case 2:
9898 case 3:
9899 temp_p->chip = AHC_AIC7770 | AHC_VL;
9900 temp_p->features |= AHC_AIC7770_FE;
9901 if (type == 2)
9902 temp_p->flags |= AHC_BIOS_ENABLED;
9903 else
9904 temp_p->flags &= ~AHC_BIOS_ENABLED;
9905 if (aic_inb(temp_p, SCSICONF) & TERM_ENB)
9906 sxfrctl1 = STPWEN;
9907 aic7xxx_load_seeprom(temp_p, &sxfrctl1);
9908 temp_p->board_name_index = 4;
9909 if (aic7xxx_verbose & VERBOSE_PROBE2)
9910 printk("aic7xxx: <%s> at VLB %d\n",
9911 board_names[2], slot);
9912 switch( aic_inb(temp_p, STATUS_2840) & BIOS_SEL )
9914 case 0x00:
9915 temp_p->bios_address = 0xe0000;
9916 break;
9917 case 0x20:
9918 temp_p->bios_address = 0xc8000;
9919 break;
9920 case 0x40:
9921 temp_p->bios_address = 0xd0000;
9922 break;
9923 case 0x60:
9924 temp_p->bios_address = 0xd8000;
9925 break;
9926 default:
9927 break; /* can't get here */
9929 break;
9931 default: /* Won't get here. */
9932 break;
9934 if (aic7xxx_verbose & VERBOSE_PROBE2)
9936 printk(KERN_INFO "aic7xxx: BIOS %sabled, IO Port 0x%lx, IRQ %d (%s)\n",
9937 (temp_p->flags & AHC_USEDEFAULTS) ? "dis" : "en", temp_p->base,
9938 temp_p->irq,
9939 (temp_p->pause & IRQMS) ? "level sensitive" : "edge triggered");
9940 printk(KERN_INFO "aic7xxx: Extended translation %sabled.\n",
9941 (temp_p->flags & AHC_EXTEND_TRANS_A) ? "en" : "dis");
9945 * All the 7770 based chipsets have this bug
9947 temp_p->bugs |= AHC_BUG_TMODE_WIDEODD;
9950 * Set the FIFO threshold and the bus off time.
9952 hostconf = aic_inb(temp_p, HOSTCONF);
9953 aic_outb(temp_p, hostconf & DFTHRSH, BUSSPD);
9954 aic_outb(temp_p, (hostconf << 2) & BOFF, BUSTIME);
9955 slot++;
9956 found++;
9959 #endif /* defined(__i386__) || defined(__alpha__) */
9962 * Now, we re-order the probed devices by BIOS address and BUS class.
9963 * In general, we follow this algorithm to make the adapters show up
9964 * in the same order under linux that the computer finds them.
9965 * 1: All VLB/EISA cards with BIOS_ENABLED first, according to BIOS
9966 * address, going from lowest to highest.
9967 * 2: All PCI controllers with BIOS_ENABLED next, according to BIOS
9968 * address, going from lowest to highest.
9969 * 3: Remaining VLB/EISA controllers going in slot order.
9970 * 4: Remaining PCI controllers, going in PCI device order (reversable)
9974 struct aic7xxx_host *sort_list[4] = { NULL, NULL, NULL, NULL };
9975 struct aic7xxx_host *vlb, *pci;
9976 struct aic7xxx_host *prev_p;
9977 struct aic7xxx_host *p;
9978 unsigned char left;
9980 prev_p = vlb = pci = NULL;
9982 temp_p = list_p;
9983 while (temp_p != NULL)
9985 switch(temp_p->chip & ~AHC_CHIPID_MASK)
9987 case AHC_EISA:
9988 case AHC_VL:
9990 p = temp_p;
9991 if (p->flags & AHC_BIOS_ENABLED)
9992 vlb = sort_list[0];
9993 else
9994 vlb = sort_list[2];
9996 if (vlb == NULL)
9998 vlb = temp_p;
9999 temp_p = temp_p->next;
10000 vlb->next = NULL;
10002 else
10004 current_p = vlb;
10005 prev_p = NULL;
10006 while ( (current_p != NULL) &&
10007 (current_p->bios_address < temp_p->bios_address))
10009 prev_p = current_p;
10010 current_p = current_p->next;
10012 if (prev_p != NULL)
10014 prev_p->next = temp_p;
10015 temp_p = temp_p->next;
10016 prev_p->next->next = current_p;
10018 else
10020 vlb = temp_p;
10021 temp_p = temp_p->next;
10022 vlb->next = current_p;
10026 if (p->flags & AHC_BIOS_ENABLED)
10027 sort_list[0] = vlb;
10028 else
10029 sort_list[2] = vlb;
10031 break;
10033 default: /* All PCI controllers fall through to default */
10036 p = temp_p;
10037 if (p->flags & AHC_BIOS_ENABLED)
10038 pci = sort_list[1];
10039 else
10040 pci = sort_list[3];
10042 if (pci == NULL)
10044 pci = temp_p;
10045 temp_p = temp_p->next;
10046 pci->next = NULL;
10048 else
10050 current_p = pci;
10051 prev_p = NULL;
10052 if (!aic7xxx_reverse_scan)
10054 while ( (current_p != NULL) &&
10055 ( (PCI_SLOT(current_p->pci_device_fn) |
10056 (current_p->pci_bus << 8)) <
10057 (PCI_SLOT(temp_p->pci_device_fn) |
10058 (temp_p->pci_bus << 8)) ) )
10060 prev_p = current_p;
10061 current_p = current_p->next;
10064 else
10066 while ( (current_p != NULL) &&
10067 ( (PCI_SLOT(current_p->pci_device_fn) |
10068 (current_p->pci_bus << 8)) >
10069 (PCI_SLOT(temp_p->pci_device_fn) |
10070 (temp_p->pci_bus << 8)) ) )
10072 prev_p = current_p;
10073 current_p = current_p->next;
10077 * Are we dealing with a 7895/6/7/9 where we need to sort the
10078 * channels as well, if so, the bios_address values should
10079 * be the same
10081 if ( (current_p) && (temp_p->flags & AHC_MULTI_CHANNEL) &&
10082 (temp_p->pci_bus == current_p->pci_bus) &&
10083 (PCI_SLOT(temp_p->pci_device_fn) ==
10084 PCI_SLOT(current_p->pci_device_fn)) )
10086 if (temp_p->flags & AHC_CHNLB)
10088 if ( !(temp_p->flags & AHC_CHANNEL_B_PRIMARY) )
10090 prev_p = current_p;
10091 current_p = current_p->next;
10094 else
10096 if (temp_p->flags & AHC_CHANNEL_B_PRIMARY)
10098 prev_p = current_p;
10099 current_p = current_p->next;
10103 if (prev_p != NULL)
10105 prev_p->next = temp_p;
10106 temp_p = temp_p->next;
10107 prev_p->next->next = current_p;
10109 else
10111 pci = temp_p;
10112 temp_p = temp_p->next;
10113 pci->next = current_p;
10117 if (p->flags & AHC_BIOS_ENABLED)
10118 sort_list[1] = pci;
10119 else
10120 sort_list[3] = pci;
10122 break;
10124 } /* End of switch(temp_p->type) */
10125 } /* End of while (temp_p != NULL) */
10127 * At this point, the cards have been broken into 4 sorted lists, now
10128 * we run through the lists in order and register each controller
10131 int i;
10133 left = found;
10134 for (i=0; i<NUMBER(sort_list); i++)
10136 temp_p = sort_list[i];
10137 while(temp_p != NULL)
10139 template->name = board_names[temp_p->board_name_index];
10140 p = aic7xxx_alloc(template, temp_p);
10141 if (p != NULL)
10143 p->instance = found - left;
10144 if (aic7xxx_register(template, p, (--left)) == 0)
10146 found--;
10147 aic7xxx_release(p->host);
10148 scsi_unregister(p->host);
10150 else if (aic7xxx_dump_card)
10152 pause_sequencer(p);
10153 aic7xxx_print_card(p);
10154 aic7xxx_print_scratch_ram(p);
10155 unpause_sequencer(p, TRUE);
10158 current_p = temp_p;
10159 temp_p = (struct aic7xxx_host *)temp_p->next;
10160 kfree(current_p);
10165 return (found);
10168 /*+F*************************************************************************
10169 * Function:
10170 * aic7xxx_buildscb
10172 * Description:
10173 * Build a SCB.
10174 *-F*************************************************************************/
10175 static void
10176 aic7xxx_buildscb(struct aic7xxx_host *p, Scsi_Cmnd *cmd,
10177 struct aic7xxx_scb *scb)
10179 unsigned short mask;
10180 struct aic7xxx_hwscb *hscb;
10181 struct aic_dev_data *aic_dev = cmd->device->hostdata;
10182 struct scsi_device *sdptr = cmd->device;
10183 unsigned char tindex = TARGET_INDEX(cmd);
10184 struct request *req = cmd->request;
10186 mask = (0x01 << tindex);
10187 hscb = scb->hscb;
10190 * Setup the control byte if we need negotiation and have not
10191 * already requested it.
10193 hscb->control = 0;
10194 scb->tag_action = 0;
10196 if (p->discenable & mask)
10198 hscb->control |= DISCENB;
10199 /* We always force TEST_UNIT_READY to untagged */
10200 if (cmd->cmnd[0] != TEST_UNIT_READY && sdptr->simple_tags)
10202 if (req->flags & REQ_HARDBARRIER)
10204 if(sdptr->ordered_tags)
10206 hscb->control |= MSG_ORDERED_Q_TAG;
10207 scb->tag_action = MSG_ORDERED_Q_TAG;
10210 else
10212 hscb->control |= MSG_SIMPLE_Q_TAG;
10213 scb->tag_action = MSG_SIMPLE_Q_TAG;
10217 if ( !(aic_dev->dtr_pending) &&
10218 (aic_dev->needppr || aic_dev->needwdtr || aic_dev->needsdtr) &&
10219 (aic_dev->flags & DEVICE_DTR_SCANNED) )
10221 aic_dev->dtr_pending = 1;
10222 scb->tag_action = 0;
10223 hscb->control &= DISCENB;
10224 hscb->control |= MK_MESSAGE;
10225 if(aic_dev->needppr)
10227 scb->flags |= SCB_MSGOUT_PPR;
10229 else if(aic_dev->needwdtr)
10231 scb->flags |= SCB_MSGOUT_WDTR;
10233 else if(aic_dev->needsdtr)
10235 scb->flags |= SCB_MSGOUT_SDTR;
10237 scb->flags |= SCB_DTR_SCB;
10239 hscb->target_channel_lun = ((cmd->target << 4) & 0xF0) |
10240 ((cmd->channel & 0x01) << 3) | (cmd->lun & 0x07);
10243 * The interpretation of request_buffer and request_bufflen
10244 * changes depending on whether or not use_sg is zero; a
10245 * non-zero use_sg indicates the number of elements in the
10246 * scatter-gather array.
10250 * XXX - this relies on the host data being stored in a
10251 * little-endian format.
10253 hscb->SCSI_cmd_length = cmd->cmd_len;
10254 memcpy(scb->cmnd, cmd->cmnd, cmd->cmd_len);
10255 hscb->SCSI_cmd_pointer = cpu_to_le32(SCB_DMA_ADDR(scb, scb->cmnd));
10257 if (cmd->use_sg)
10259 struct scatterlist *sg; /* Must be mid-level SCSI code scatterlist */
10262 * We must build an SG list in adapter format, as the kernel's SG list
10263 * cannot be used directly because of data field size (__alpha__)
10264 * differences and the kernel SG list uses virtual addresses where
10265 * we need physical addresses.
10267 int i, use_sg;
10269 sg = (struct scatterlist *)cmd->request_buffer;
10270 scb->sg_length = 0;
10271 use_sg = pci_map_sg(p->pdev, sg, cmd->use_sg, scsi_to_pci_dma_dir(cmd->sc_data_direction));
10273 * Copy the segments into the SG array. NOTE!!! - We used to
10274 * have the first entry both in the data_pointer area and the first
10275 * SG element. That has changed somewhat. We still have the first
10276 * entry in both places, but now we download the address of
10277 * scb->sg_list[1] instead of 0 to the sg pointer in the hscb.
10279 for (i = 0; i < use_sg; i++)
10281 unsigned int len = sg_dma_len(sg+i);
10282 scb->sg_list[i].address = cpu_to_le32(sg_dma_address(sg+i));
10283 scb->sg_list[i].length = cpu_to_le32(len);
10284 scb->sg_length += len;
10286 /* Copy the first SG into the data pointer area. */
10287 hscb->data_pointer = scb->sg_list[0].address;
10288 hscb->data_count = scb->sg_list[0].length;
10289 scb->sg_count = i;
10290 hscb->SG_segment_count = i;
10291 hscb->SG_list_pointer = cpu_to_le32(SCB_DMA_ADDR(scb, &scb->sg_list[1]));
10293 else
10295 if (cmd->request_bufflen)
10297 unsigned int address = pci_map_single(p->pdev, cmd->request_buffer,
10298 cmd->request_bufflen,
10299 scsi_to_pci_dma_dir(cmd->sc_data_direction));
10300 aic7xxx_mapping(cmd) = address;
10301 scb->sg_list[0].address = cpu_to_le32(address);
10302 scb->sg_list[0].length = cpu_to_le32(cmd->request_bufflen);
10303 scb->sg_count = 1;
10304 scb->sg_length = cmd->request_bufflen;
10305 hscb->SG_segment_count = 1;
10306 hscb->SG_list_pointer = cpu_to_le32(SCB_DMA_ADDR(scb, &scb->sg_list[0]));
10307 hscb->data_count = scb->sg_list[0].length;
10308 hscb->data_pointer = scb->sg_list[0].address;
10310 else
10312 scb->sg_count = 0;
10313 scb->sg_length = 0;
10314 hscb->SG_segment_count = 0;
10315 hscb->SG_list_pointer = 0;
10316 hscb->data_count = 0;
10317 hscb->data_pointer = 0;
10322 /*+F*************************************************************************
10323 * Function:
10324 * aic7xxx_queue
10326 * Description:
10327 * Queue a SCB to the controller.
10328 *-F*************************************************************************/
10330 aic7xxx_queue(Scsi_Cmnd *cmd, void (*fn)(Scsi_Cmnd *))
10332 struct aic7xxx_host *p;
10333 struct aic7xxx_scb *scb;
10334 struct aic_dev_data *aic_dev;
10336 p = (struct aic7xxx_host *) cmd->host->hostdata;
10338 aic_dev = cmd->device->hostdata;
10339 if(!aic_dev) {
10340 aic_dev = aic7xxx_alloc_aic_dev(p, cmd->device);
10341 if(!aic_dev)
10342 return 1;
10344 else
10346 aic_dev = AIC_DEV(cmd);
10349 #ifdef AIC7XXX_VERBOSE_DEBUGGING
10351 * Check to see if channel was scanned.
10354 if (!(p->flags & AHC_A_SCANNED) && (cmd->channel == 0))
10356 if (aic7xxx_verbose & VERBOSE_PROBE2)
10357 printk(INFO_LEAD "Scanning channel for devices.\n",
10358 p->host_no, 0, -1, -1);
10359 p->flags |= AHC_A_SCANNED;
10361 else
10363 if (!(p->flags & AHC_B_SCANNED) && (cmd->channel == 1))
10365 if (aic7xxx_verbose & VERBOSE_PROBE2)
10366 printk(INFO_LEAD "Scanning channel for devices.\n",
10367 p->host_no, 1, -1, -1);
10368 p->flags |= AHC_B_SCANNED;
10372 if (aic_dev->active_cmds > aic_dev->max_q_depth)
10374 printk(WARN_LEAD "Commands queued exceeds queue "
10375 "depth, active=%d\n",
10376 p->host_no, CTL_OF_CMD(cmd),
10377 aic_dev->active_cmds);
10379 #endif
10381 scb = scbq_remove_head(&p->scb_data->free_scbs);
10382 if (scb == NULL)
10384 aic7xxx_allocate_scb(p);
10385 scb = scbq_remove_head(&p->scb_data->free_scbs);
10386 if(scb == NULL)
10388 printk(WARN_LEAD "Couldn't get a free SCB.\n", p->host_no,
10389 CTL_OF_CMD(cmd));
10390 return 1;
10393 scb->cmd = cmd;
10396 * Make sure the Scsi_Cmnd pointer is saved, the struct it points to
10397 * is set up properly, and the parity error flag is reset, then send
10398 * the SCB to the sequencer and watch the fun begin.
10400 aic7xxx_position(cmd) = scb->hscb->tag;
10401 cmd->scsi_done = fn;
10402 cmd->result = DID_OK;
10403 memset(cmd->sense_buffer, 0, sizeof(cmd->sense_buffer));
10404 aic7xxx_error(cmd) = DID_OK;
10405 aic7xxx_status(cmd) = 0;
10406 cmd->host_scribble = NULL;
10409 * Construct the SCB beforehand, so the sequencer is
10410 * paused a minimal amount of time.
10412 aic7xxx_buildscb(p, cmd, scb);
10414 scb->flags |= SCB_ACTIVE | SCB_WAITINGQ;
10416 scbq_insert_tail(&p->waiting_scbs, scb);
10417 aic7xxx_run_waiting_queues(p);
10418 return (0);
10421 /*+F*************************************************************************
10422 * Function:
10423 * aic7xxx_bus_device_reset
10425 * Description:
10426 * Abort or reset the current SCSI command(s). If the scb has not
10427 * previously been aborted, then we attempt to send a BUS_DEVICE_RESET
10428 * message to the target. If the scb has previously been unsuccessfully
10429 * aborted, then we will reset the channel and have all devices renegotiate.
10430 * Returns an enumerated type that indicates the status of the operation.
10431 *-F*************************************************************************/
10433 aic7xxx_bus_device_reset(Scsi_Cmnd *cmd)
10435 struct aic7xxx_host *p;
10436 struct aic7xxx_scb *scb;
10437 struct aic7xxx_hwscb *hscb;
10438 int channel;
10439 unsigned char saved_scbptr, lastphase;
10440 unsigned char hscb_index;
10441 int disconnected;
10442 struct aic_dev_data *aic_dev;
10444 if(cmd == NULL)
10446 printk(KERN_ERR "aic7xxx_bus_device_reset: called with NULL cmd!\n");
10447 return FAILED;
10449 p = (struct aic7xxx_host *)cmd->host->hostdata;
10450 aic_dev = AIC_DEV(cmd);
10451 if(aic7xxx_position(cmd) < p->scb_data->numscbs)
10452 scb = (p->scb_data->scb_array[aic7xxx_position(cmd)]);
10453 else
10454 return FAILED;
10456 hscb = scb->hscb;
10458 aic7xxx_isr(p->irq, (void *)p, NULL);
10459 aic7xxx_done_cmds_complete(p);
10460 /* If the command was already complete or just completed, then we didn't
10461 * do a reset, return FAILED */
10462 if(!scb->flags & SCB_ACTIVE)
10463 return FAILED;
10465 pause_sequencer(p);
10466 lastphase = aic_inb(p, LASTPHASE);
10467 if (aic7xxx_verbose & VERBOSE_RESET_PROCESS)
10469 printk(INFO_LEAD "Bus Device reset, scb flags 0x%x, ",
10470 p->host_no, CTL_OF_SCB(scb), scb->flags);
10471 switch (lastphase)
10473 case P_DATAOUT:
10474 printk("Data-Out phase\n");
10475 break;
10476 case P_DATAIN:
10477 printk("Data-In phase\n");
10478 break;
10479 case P_COMMAND:
10480 printk("Command phase\n");
10481 break;
10482 case P_MESGOUT:
10483 printk("Message-Out phase\n");
10484 break;
10485 case P_STATUS:
10486 printk("Status phase\n");
10487 break;
10488 case P_MESGIN:
10489 printk("Message-In phase\n");
10490 break;
10491 default:
10493 * We're not in a valid phase, so assume we're idle.
10495 printk("while idle, LASTPHASE = 0x%x\n", lastphase);
10496 break;
10498 printk(INFO_LEAD "SCSISIGI 0x%x, SEQADDR 0x%x, SSTAT0 0x%x, SSTAT1 "
10499 "0x%x\n", p->host_no, CTL_OF_SCB(scb),
10500 aic_inb(p, SCSISIGI),
10501 aic_inb(p, SEQADDR0) | (aic_inb(p, SEQADDR1) << 8),
10502 aic_inb(p, SSTAT0), aic_inb(p, SSTAT1));
10503 printk(INFO_LEAD "SG_CACHEPTR 0x%x, SSTAT2 0x%x, STCNT 0x%x\n", p->host_no,
10504 CTL_OF_SCB(scb),
10505 (p->features & AHC_ULTRA2) ? aic_inb(p, SG_CACHEPTR) : 0,
10506 aic_inb(p, SSTAT2),
10507 aic_inb(p, STCNT + 2) << 16 | aic_inb(p, STCNT + 1) << 8 |
10508 aic_inb(p, STCNT));
10511 channel = cmd->channel;
10514 * Send a Device Reset Message:
10515 * The target that is holding up the bus may not be the same as
10516 * the one that triggered this timeout (different commands have
10517 * different timeout lengths). Our strategy here is to queue an
10518 * abort message to the timed out target if it is disconnected.
10519 * Otherwise, if we have an active target we stuff the message buffer
10520 * with an abort message and assert ATN in the hopes that the target
10521 * will let go of the bus and go to the mesgout phase. If this
10522 * fails, we'll get another timeout a few seconds later which will
10523 * attempt a bus reset.
10525 saved_scbptr = aic_inb(p, SCBPTR);
10526 disconnected = FALSE;
10528 if (lastphase != P_BUSFREE)
10530 if (aic_inb(p, SCB_TAG) >= p->scb_data->numscbs)
10532 printk(WARN_LEAD "Invalid SCB ID %d is active, "
10533 "SCB flags = 0x%x.\n", p->host_no,
10534 CTL_OF_CMD(cmd), scb->hscb->tag, scb->flags);
10535 unpause_sequencer(p, FALSE);
10536 return FAILED;
10538 if (scb->hscb->tag == aic_inb(p, SCB_TAG))
10540 if ( (lastphase == P_MESGOUT) || (lastphase == P_MESGIN) )
10542 printk(WARN_LEAD "Device reset, Message buffer "
10543 "in use\n", p->host_no, CTL_OF_SCB(scb));
10544 unpause_sequencer(p, FALSE);
10545 return FAILED;
10548 if (aic7xxx_verbose & VERBOSE_RESET_PROCESS)
10549 printk(INFO_LEAD "Device reset message in "
10550 "message buffer\n", p->host_no, CTL_OF_SCB(scb));
10551 scb->flags |= SCB_RESET | SCB_DEVICE_RESET;
10552 aic7xxx_error(cmd) = DID_RESET;
10553 aic_dev->flags |= BUS_DEVICE_RESET_PENDING;
10554 /* Send the abort message to the active SCB. */
10555 aic_outb(p, HOST_MSG, MSG_OUT);
10556 aic_outb(p, lastphase | ATNO, SCSISIGO);
10557 unpause_sequencer(p, FALSE);
10558 spin_unlock_irq(p->host->host_lock);
10559 scsi_sleep(HZ);
10560 spin_lock_irq(p->host->host_lock);
10561 if(aic_dev->flags & BUS_DEVICE_RESET_PENDING)
10562 return FAILED;
10563 else
10564 return SUCCESS;
10566 } /* if (last_phase != P_BUSFREE).....indicates we are idle and can work */
10568 * Simply set the MK_MESSAGE flag and the SEQINT handler will do
10569 * the rest on a reconnect/connect.
10571 scb->hscb->control |= MK_MESSAGE;
10572 scb->flags |= SCB_RESET | SCB_DEVICE_RESET;
10573 aic_dev->flags |= BUS_DEVICE_RESET_PENDING;
10575 * Check to see if the command is on the qinfifo. If it is, then we will
10576 * not need to queue the command again since the card should start it soon
10578 if (aic7xxx_search_qinfifo(p, cmd->channel, cmd->target, cmd->lun, hscb->tag,
10579 0, TRUE, NULL) == 0)
10581 disconnected = TRUE;
10582 if ((hscb_index = aic7xxx_find_scb(p, scb)) != SCB_LIST_NULL)
10584 unsigned char scb_control;
10586 aic_outb(p, hscb_index, SCBPTR);
10587 scb_control = aic_inb(p, SCB_CONTROL);
10589 * If the DISCONNECTED bit is not set in SCB_CONTROL, then we are
10590 * actually on the waiting list, not disconnected, and we don't
10591 * need to requeue the command.
10593 disconnected = (scb_control & DISCONNECTED);
10594 aic_outb(p, scb_control | MK_MESSAGE, SCB_CONTROL);
10596 if (disconnected)
10599 * Actually requeue this SCB in case we can select the
10600 * device before it reconnects. This can result in the command
10601 * being on the qinfifo twice, but we don't care because it will
10602 * all get cleaned up if/when the reset takes place.
10604 if (aic7xxx_verbose & VERBOSE_RESET_PROCESS)
10605 printk(INFO_LEAD "Queueing device reset command.\n", p->host_no,
10606 CTL_OF_SCB(scb));
10607 p->qinfifo[p->qinfifonext++] = scb->hscb->tag;
10608 if (p->features & AHC_QUEUE_REGS)
10609 aic_outb(p, p->qinfifonext, HNSCB_QOFF);
10610 else
10611 aic_outb(p, p->qinfifonext, KERNEL_QINPOS);
10612 scb->flags |= SCB_QUEUED_ABORT;
10615 aic_outb(p, saved_scbptr, SCBPTR);
10616 unpause_sequencer(p, FALSE);
10617 spin_unlock_irq(p->host->host_lock);
10618 scsi_sleep(HZ/4);
10619 spin_lock_irq(p->host->host_lock);
10620 if(aic_dev->flags & BUS_DEVICE_RESET_PENDING)
10621 return FAILED;
10622 else
10623 return SUCCESS;
10627 /*+F*************************************************************************
10628 * Function:
10629 * aic7xxx_panic_abort
10631 * Description:
10632 * Abort the current SCSI command(s).
10633 *-F*************************************************************************/
10634 void
10635 aic7xxx_panic_abort(struct aic7xxx_host *p, Scsi_Cmnd *cmd)
10638 printk("aic7xxx driver version %s/%s\n", AIC7XXX_C_VERSION,
10639 UTS_RELEASE);
10640 printk("Controller type:\n %s\n", board_names[p->board_name_index]);
10641 printk("p->flags=0x%lx, p->chip=0x%x, p->features=0x%x, "
10642 "sequencer %s paused\n",
10643 p->flags, p->chip, p->features,
10644 (aic_inb(p, HCNTRL) & PAUSE) ? "is" : "isn't" );
10645 pause_sequencer(p);
10646 disable_irq(p->irq);
10647 aic7xxx_print_card(p);
10648 aic7xxx_print_scratch_ram(p);
10649 spin_unlock_irq(p->host->host_lock);
10650 for(;;) barrier();
10653 /*+F*************************************************************************
10654 * Function:
10655 * aic7xxx_abort
10657 * Description:
10658 * Abort the current SCSI command(s).
10659 *-F*************************************************************************/
10661 aic7xxx_abort(Scsi_Cmnd *cmd)
10663 struct aic7xxx_scb *scb = NULL;
10664 struct aic7xxx_host *p;
10665 int found=0, disconnected;
10666 unsigned char saved_hscbptr, hscbptr, scb_control;
10667 struct aic_dev_data *aic_dev;
10669 if(cmd == NULL)
10671 printk(KERN_ERR "aic7xxx_abort: called with NULL cmd!\n");
10672 return FAILED;
10674 p = (struct aic7xxx_host *)cmd->host->hostdata;
10675 aic_dev = AIC_DEV(cmd);
10676 if(aic7xxx_position(cmd) < p->scb_data->numscbs)
10677 scb = (p->scb_data->scb_array[aic7xxx_position(cmd)]);
10678 else
10679 return FAILED;
10681 aic7xxx_isr(p->irq, (void *)p, NULL);
10682 aic7xxx_done_cmds_complete(p);
10683 /* If the command was already complete or just completed, then we didn't
10684 * do a reset, return FAILED */
10685 if(!scb->flags & SCB_ACTIVE)
10686 return FAILED;
10688 pause_sequencer(p);
10691 * I added a new config option to the driver: "panic_on_abort" that will
10692 * cause the driver to panic and the machine to stop on the first abort
10693 * or reset call into the driver. At that point, it prints out a lot of
10694 * useful information for me which I can then use to try and debug the
10695 * problem. Simply enable the boot time prompt in order to activate this
10696 * code.
10698 if (aic7xxx_panic_on_abort)
10699 aic7xxx_panic_abort(p, cmd);
10701 if (aic7xxx_verbose & VERBOSE_ABORT)
10703 printk(INFO_LEAD "Aborting scb %d, flags 0x%x, SEQADDR 0x%x, LASTPHASE "
10704 "0x%x\n",
10705 p->host_no, CTL_OF_SCB(scb), scb->hscb->tag, scb->flags,
10706 aic_inb(p, SEQADDR0) | (aic_inb(p, SEQADDR1) << 8),
10707 aic_inb(p, LASTPHASE));
10708 printk(INFO_LEAD "SG_CACHEPTR 0x%x, SG_COUNT %d, SCSISIGI 0x%x\n",
10709 p->host_no, CTL_OF_SCB(scb), (p->features & AHC_ULTRA2) ?
10710 aic_inb(p, SG_CACHEPTR) : 0, aic_inb(p, SG_COUNT),
10711 aic_inb(p, SCSISIGI));
10712 printk(INFO_LEAD "SSTAT0 0x%x, SSTAT1 0x%x, SSTAT2 0x%x\n",
10713 p->host_no, CTL_OF_SCB(scb), aic_inb(p, SSTAT0),
10714 aic_inb(p, SSTAT1), aic_inb(p, SSTAT2));
10717 if (scb->flags & SCB_WAITINGQ)
10719 if (aic7xxx_verbose & VERBOSE_ABORT_PROCESS)
10720 printk(INFO_LEAD "SCB found on waiting list and "
10721 "aborted.\n", p->host_no, CTL_OF_SCB(scb));
10722 scbq_remove(&p->waiting_scbs, scb);
10723 scbq_remove(&aic_dev->delayed_scbs, scb);
10724 aic_dev->active_cmds++;
10725 p->activescbs++;
10726 scb->flags &= ~(SCB_WAITINGQ | SCB_ACTIVE);
10727 scb->flags |= SCB_ABORT | SCB_QUEUED_FOR_DONE;
10728 goto success;
10732 * We just checked the waiting_q, now for the QINFIFO
10734 if ( ((found = aic7xxx_search_qinfifo(p, cmd->target, cmd->channel,
10735 cmd->lun, scb->hscb->tag, SCB_ABORT | SCB_QUEUED_FOR_DONE,
10736 FALSE, NULL)) != 0) &&
10737 (aic7xxx_verbose & VERBOSE_ABORT_PROCESS))
10739 printk(INFO_LEAD "SCB found in QINFIFO and aborted.\n", p->host_no,
10740 CTL_OF_SCB(scb));
10741 goto success;
10745 * QINFIFO, waitingq, completeq done. Next, check WAITING_SCB list in card
10748 saved_hscbptr = aic_inb(p, SCBPTR);
10749 if ((hscbptr = aic7xxx_find_scb(p, scb)) != SCB_LIST_NULL)
10751 aic_outb(p, hscbptr, SCBPTR);
10752 scb_control = aic_inb(p, SCB_CONTROL);
10753 disconnected = scb_control & DISCONNECTED;
10755 * If the DISCONNECTED bit is not set in SCB_CONTROL, then we are
10756 * either currently active or on the waiting list.
10758 if(!disconnected && aic_inb(p, LASTPHASE) == P_BUSFREE) {
10759 if (aic7xxx_verbose & VERBOSE_ABORT_PROCESS)
10760 printk(INFO_LEAD "SCB found on hardware waiting"
10761 " list and aborted.\n", p->host_no, CTL_OF_SCB(scb));
10762 /* If we are the only waiting command, stop the selection engine */
10763 if (aic_inb(p, WAITING_SCBH) == hscbptr && aic_inb(p, SCB_NEXT) ==
10764 SCB_LIST_NULL)
10766 aic_outb(p, aic_inb(p, SCSISEQ) & ~ENSELO, SCSISEQ);
10767 aic_outb(p, CLRSELTIMEO, CLRSINT1);
10768 aic_outb(p, SCB_LIST_NULL, WAITING_SCBH);
10770 else
10772 unsigned char prev, next;
10773 prev = SCB_LIST_NULL;
10774 next = aic_inb(p, WAITING_SCBH);
10775 while(next != SCB_LIST_NULL)
10777 aic_outb(p, next, SCBPTR);
10778 if (next == hscbptr)
10780 next = aic_inb(p, SCB_NEXT);
10781 if (prev != SCB_LIST_NULL)
10783 aic_outb(p, prev, SCBPTR);
10784 aic_outb(p, next, SCB_NEXT);
10786 else
10787 aic_outb(p, next, WAITING_SCBH);
10788 aic_outb(p, hscbptr, SCBPTR);
10789 next = SCB_LIST_NULL;
10791 else
10793 prev = next;
10794 next = aic_inb(p, SCB_NEXT);
10798 aic_outb(p, SCB_LIST_NULL, SCB_TAG);
10799 aic_outb(p, 0, SCB_CONTROL);
10800 aic7xxx_add_curscb_to_free_list(p);
10801 scb->flags = SCB_ABORT | SCB_QUEUED_FOR_DONE;
10802 goto success;
10804 else if (!disconnected)
10807 * We are the currently active command
10809 if((aic_inb(p, LASTPHASE) == P_MESGIN) ||
10810 (aic_inb(p, LASTPHASE) == P_MESGOUT))
10813 * Message buffer busy, unable to abort
10815 printk(INFO_LEAD "message buffer busy, unable to abort.\n",
10816 p->host_no, CTL_OF_SCB(scb));
10817 unpause_sequencer(p, FALSE);
10818 return FAILED;
10820 /* Fallthrough to below, set ATNO after we set SCB_CONTROL */
10822 aic_outb(p, scb_control | MK_MESSAGE, SCB_CONTROL);
10823 if(!disconnected)
10825 aic_outb(p, HOST_MSG, MSG_OUT);
10826 aic_outb(p, aic_inb(p, SCSISIGI) | ATNO, SCSISIGO);
10828 aic_outb(p, saved_hscbptr, SCBPTR);
10830 else
10833 * The scb isn't in the card at all and it is active and it isn't in
10834 * any of the queues, so it must be disconnected and paged out. Fall
10835 * through to the code below.
10837 disconnected = 1;
10840 p->flags |= AHC_ABORT_PENDING;
10841 scb->flags |= SCB_QUEUED_ABORT | SCB_ABORT | SCB_RECOVERY_SCB;
10842 scb->hscb->control |= MK_MESSAGE;
10843 if(disconnected)
10845 if (aic7xxx_verbose & VERBOSE_ABORT_PROCESS)
10846 printk(INFO_LEAD "SCB disconnected. Queueing Abort"
10847 " SCB.\n", p->host_no, CTL_OF_SCB(scb));
10848 p->qinfifo[p->qinfifonext++] = scb->hscb->tag;
10849 if (p->features & AHC_QUEUE_REGS)
10850 aic_outb(p, p->qinfifonext, HNSCB_QOFF);
10851 else
10852 aic_outb(p, p->qinfifonext, KERNEL_QINPOS);
10854 unpause_sequencer(p, FALSE);
10855 spin_unlock_irq(p->host->host_lock);
10856 scsi_sleep(HZ/4);
10857 spin_lock_irq(p->host->host_lock);
10858 if (p->flags & AHC_ABORT_PENDING)
10860 if (aic7xxx_verbose & VERBOSE_ABORT_RETURN)
10861 printk(INFO_LEAD "Abort never delivered, returning FAILED\n", p->host_no,
10862 CTL_OF_CMD(cmd));
10863 p->flags &= ~AHC_ABORT_PENDING;
10864 return FAILED;
10866 if (aic7xxx_verbose & VERBOSE_ABORT_RETURN)
10867 printk(INFO_LEAD "Abort successful.\n", p->host_no, CTL_OF_CMD(cmd));
10868 return SUCCESS;
10870 success:
10871 if (aic7xxx_verbose & VERBOSE_ABORT_RETURN)
10872 printk(INFO_LEAD "Abort successful.\n", p->host_no, CTL_OF_CMD(cmd));
10873 aic7xxx_run_done_queue(p, TRUE);
10874 unpause_sequencer(p, FALSE);
10875 return SUCCESS;
10878 /*+F*************************************************************************
10879 * Function:
10880 * aic7xxx_reset
10882 * Description:
10883 * Resetting the bus always succeeds - is has to, otherwise the
10884 * kernel will panic! Try a surgical technique - sending a BUS
10885 * DEVICE RESET message - on the offending target before pulling
10886 * the SCSI bus reset line.
10887 *-F*************************************************************************/
10889 aic7xxx_reset(Scsi_Cmnd *cmd)
10891 struct aic7xxx_scb *scb;
10892 struct aic7xxx_host *p;
10893 struct aic_dev_data *aic_dev;
10895 p = (struct aic7xxx_host *) cmd->host->hostdata;
10896 aic_dev = AIC_DEV(cmd);
10897 if(aic7xxx_position(cmd) < p->scb_data->numscbs)
10899 scb = (p->scb_data->scb_array[aic7xxx_position(cmd)]);
10900 if (scb->cmd != cmd)
10901 scb = NULL;
10903 else
10905 scb = NULL;
10909 * I added a new config option to the driver: "panic_on_abort" that will
10910 * cause the driver to panic and the machine to stop on the first abort
10911 * or reset call into the driver. At that point, it prints out a lot of
10912 * useful information for me which I can then use to try and debug the
10913 * problem. Simply enable the boot time prompt in order to activate this
10914 * code.
10916 if (aic7xxx_panic_on_abort)
10917 aic7xxx_panic_abort(p, cmd);
10919 pause_sequencer(p);
10921 while((aic_inb(p, INTSTAT) & INT_PEND) && !(p->flags & AHC_IN_ISR))
10923 aic7xxx_isr(p->irq, p, (void *)NULL );
10924 pause_sequencer(p);
10926 aic7xxx_done_cmds_complete(p);
10928 if(scb && (scb->cmd == NULL))
10931 * We just completed the command when we ran the isr stuff, so we no
10932 * longer have it.
10934 unpause_sequencer(p, FALSE);
10935 return SUCCESS;
10939 * By this point, we want to already know what we are going to do and
10940 * only have the following code implement our course of action.
10942 aic7xxx_reset_channel(p, cmd->channel, TRUE);
10943 if (p->features & AHC_TWIN)
10945 aic7xxx_reset_channel(p, cmd->channel ^ 0x01, TRUE);
10946 restart_sequencer(p);
10948 aic_outb(p, aic_inb(p, SIMODE1) & ~(ENREQINIT|ENBUSFREE), SIMODE1);
10949 aic7xxx_clear_intstat(p);
10950 p->flags &= ~AHC_HANDLING_REQINITS;
10951 p->msg_type = MSG_TYPE_NONE;
10952 p->msg_index = 0;
10953 p->msg_len = 0;
10954 aic7xxx_run_done_queue(p, TRUE);
10955 unpause_sequencer(p, FALSE);
10956 spin_unlock_irq(p->host->host_lock);
10957 scsi_sleep(2 * HZ);
10958 spin_lock_irq(p->host->host_lock);
10959 return SUCCESS;
10962 /*+F*************************************************************************
10963 * Function:
10964 * aic7xxx_biosparam
10966 * Description:
10967 * Return the disk geometry for the given SCSI device.
10969 * Note:
10970 * This function is broken for today's really large drives and needs
10971 * fixed.
10972 *-F*************************************************************************/
10974 aic7xxx_biosparam(struct scsi_device *sdev, struct block_device *bdev,
10975 sector_t capacity, int geom[])
10977 int heads, sectors, cylinders, ret;
10978 struct aic7xxx_host *p;
10979 unsigned char *buf;
10981 p = (struct aic7xxx_host *) sdev->host->hostdata;
10982 buf = scsi_bios_ptable(bdev);
10984 if ( buf )
10986 ret = scsi_partsize(buf, capacity, &geom[2], &geom[0], &geom[1]);
10987 kfree(buf);
10988 if ( ret != -1 )
10989 return(ret);
10992 heads = 64;
10993 sectors = 32;
10994 cylinders = (unsigned long)capacity / (heads * sectors);
10996 if ((p->flags & AHC_EXTEND_TRANS_A) && (cylinders > 1024))
10998 heads = 255;
10999 sectors = 63;
11000 cylinders = (unsigned long)capacity / (heads * sectors);
11003 geom[0] = heads;
11004 geom[1] = sectors;
11005 geom[2] = cylinders;
11007 return (0);
11010 /*+F*************************************************************************
11011 * Function:
11012 * aic7xxx_release
11014 * Description:
11015 * Free the passed in Scsi_Host memory structures prior to unloading the
11016 * module.
11017 *-F*************************************************************************/
11019 aic7xxx_release(struct Scsi_Host *host)
11021 struct aic7xxx_host *p = (struct aic7xxx_host *) host->hostdata;
11022 struct aic7xxx_host *next, *prev;
11024 if(p->irq)
11025 free_irq(p->irq, p);
11026 if(p->base)
11027 release_region(p->base, MAXREG - MINREG);
11028 #ifdef MMAPIO
11029 if(p->maddr)
11031 iounmap((void *) (((unsigned long) p->maddr) & PAGE_MASK));
11033 #endif /* MMAPIO */
11034 prev = NULL;
11035 next = first_aic7xxx;
11036 while(next != NULL)
11038 if(next == p)
11040 if(prev == NULL)
11041 first_aic7xxx = next->next;
11042 else
11043 prev->next = next->next;
11045 else
11047 prev = next;
11049 next = next->next;
11051 aic7xxx_free(p);
11052 return(0);
11055 /*+F*************************************************************************
11056 * Function:
11057 * aic7xxx_print_card
11059 * Description:
11060 * Print out all of the control registers on the card
11062 * NOTE: This function is not yet safe for use on the VLB and EISA
11063 * controllers, so it isn't used on those controllers at all.
11064 *-F*************************************************************************/
11065 static void
11066 aic7xxx_print_card(struct aic7xxx_host *p)
11068 int i, j, k, chip;
11069 static struct register_ranges {
11070 int num_ranges;
11071 int range_val[32];
11072 } cards_ds[] = {
11073 { 0, {0,} }, /* none */
11074 {10, {0x00, 0x05, 0x08, 0x11, 0x18, 0x19, 0x1f, 0x1f, 0x60, 0x60, /*7771*/
11075 0x62, 0x66, 0x80, 0x8e, 0x90, 0x95, 0x97, 0x97, 0x9b, 0x9f} },
11076 { 9, {0x00, 0x05, 0x08, 0x11, 0x18, 0x1f, 0x60, 0x60, 0x62, 0x66, /*7850*/
11077 0x80, 0x8e, 0x90, 0x95, 0x97, 0x97, 0x9a, 0x9f} },
11078 { 9, {0x00, 0x05, 0x08, 0x11, 0x18, 0x1f, 0x60, 0x60, 0x62, 0x66, /*7860*/
11079 0x80, 0x8e, 0x90, 0x95, 0x97, 0x97, 0x9a, 0x9f} },
11080 {10, {0x00, 0x05, 0x08, 0x11, 0x18, 0x19, 0x1c, 0x1f, 0x60, 0x60, /*7870*/
11081 0x62, 0x66, 0x80, 0x8e, 0x90, 0x95, 0x97, 0x97, 0x9a, 0x9f} },
11082 {10, {0x00, 0x05, 0x08, 0x11, 0x18, 0x1a, 0x1c, 0x1f, 0x60, 0x60, /*7880*/
11083 0x62, 0x66, 0x80, 0x8e, 0x90, 0x95, 0x97, 0x97, 0x9a, 0x9f} },
11084 {16, {0x00, 0x05, 0x08, 0x11, 0x18, 0x1f, 0x60, 0x60, 0x62, 0x66, /*7890*/
11085 0x84, 0x8e, 0x90, 0x95, 0x97, 0x97, 0x9a, 0x9a, 0x9f, 0x9f,
11086 0xe0, 0xf1, 0xf4, 0xf4, 0xf6, 0xf6, 0xf8, 0xf8, 0xfa, 0xfc,
11087 0xfe, 0xff} },
11088 {12, {0x00, 0x05, 0x08, 0x11, 0x18, 0x19, 0x1b, 0x1f, 0x60, 0x60, /*7895*/
11089 0x62, 0x66, 0x80, 0x8e, 0x90, 0x95, 0x97, 0x97, 0x9a, 0x9a,
11090 0x9f, 0x9f, 0xe0, 0xf1} },
11091 {16, {0x00, 0x05, 0x08, 0x11, 0x18, 0x1f, 0x60, 0x60, 0x62, 0x66, /*7896*/
11092 0x84, 0x8e, 0x90, 0x95, 0x97, 0x97, 0x9a, 0x9a, 0x9f, 0x9f,
11093 0xe0, 0xf1, 0xf4, 0xf4, 0xf6, 0xf6, 0xf8, 0xf8, 0xfa, 0xfc,
11094 0xfe, 0xff} },
11095 {12, {0x00, 0x05, 0x08, 0x11, 0x18, 0x1f, 0x60, 0x60, 0x62, 0x66, /*7892*/
11096 0x84, 0x8e, 0x90, 0x95, 0x97, 0x97, 0x9a, 0x9a, 0x9c, 0x9f,
11097 0xe0, 0xf1, 0xf4, 0xfc} },
11098 {12, {0x00, 0x05, 0x08, 0x11, 0x18, 0x1f, 0x60, 0x60, 0x62, 0x66, /*7899*/
11099 0x84, 0x8e, 0x90, 0x95, 0x97, 0x97, 0x9a, 0x9a, 0x9c, 0x9f,
11100 0xe0, 0xf1, 0xf4, 0xfc} },
11102 chip = p->chip & AHC_CHIPID_MASK;
11103 printk("%s at ",
11104 board_names[p->board_name_index]);
11105 switch(p->chip & ~AHC_CHIPID_MASK)
11107 case AHC_VL:
11108 printk("VLB Slot %d.\n", p->pci_device_fn);
11109 break;
11110 case AHC_EISA:
11111 printk("EISA Slot %d.\n", p->pci_device_fn);
11112 break;
11113 case AHC_PCI:
11114 default:
11115 printk("PCI %d/%d/%d.\n", p->pci_bus, PCI_SLOT(p->pci_device_fn),
11116 PCI_FUNC(p->pci_device_fn));
11117 break;
11121 * the registers on the card....
11123 printk("Card Dump:\n");
11124 k = 0;
11125 for(i=0; i<cards_ds[chip].num_ranges; i++)
11127 for(j = cards_ds[chip].range_val[ i * 2 ];
11128 j <= cards_ds[chip].range_val[ i * 2 + 1 ] ;
11129 j++)
11131 printk("%02x:%02x ", j, aic_inb(p, j));
11132 if(++k == 13)
11134 printk("\n");
11135 k=0;
11139 if(k != 0)
11140 printk("\n");
11143 * If this was an Ultra2 controller, then we just hosed the card in terms
11144 * of the QUEUE REGS. This function is only called at init time or by
11145 * the panic_abort function, so it's safe to assume a generic init time
11146 * setting here
11149 if(p->features & AHC_QUEUE_REGS)
11151 aic_outb(p, 0, SDSCB_QOFF);
11152 aic_outb(p, 0, SNSCB_QOFF);
11153 aic_outb(p, 0, HNSCB_QOFF);
11158 /*+F*************************************************************************
11159 * Function:
11160 * aic7xxx_print_scratch_ram
11162 * Description:
11163 * Print out the scratch RAM values on the card.
11164 *-F*************************************************************************/
11165 static void
11166 aic7xxx_print_scratch_ram(struct aic7xxx_host *p)
11168 int i, k;
11170 k = 0;
11171 printk("Scratch RAM:\n");
11172 for(i = SRAM_BASE; i < SEQCTL; i++)
11174 printk("%02x:%02x ", i, aic_inb(p, i));
11175 if(++k == 13)
11177 printk("\n");
11178 k=0;
11181 if (p->features & AHC_MORE_SRAM)
11183 for(i = TARG_OFFSET; i < 0x80; i++)
11185 printk("%02x:%02x ", i, aic_inb(p, i));
11186 if(++k == 13)
11188 printk("\n");
11189 k=0;
11193 printk("\n");
11197 #include "aic7xxx_old/aic7xxx_proc.c"
11199 MODULE_LICENSE("Dual BSD/GPL");
11202 /* Eventually this will go into an include file, but this will be later */
11203 static Scsi_Host_Template driver_template = AIC7XXX;
11205 #include "scsi_module.c"
11208 * Overrides for Emacs so that we almost follow Linus's tabbing style.
11209 * Emacs will notice this stuff at the end of the file and automatically
11210 * adjust the settings for this buffer only. This must remain at the end
11211 * of the file.
11212 * ---------------------------------------------------------------------------
11213 * Local variables:
11214 * c-indent-level: 2
11215 * c-brace-imaginary-offset: 0
11216 * c-brace-offset: -2
11217 * c-argdecl-indent: 2
11218 * c-label-offset: -2
11219 * c-continued-statement-offset: 2
11220 * c-continued-brace-offset: 0
11221 * indent-tabs-mode: nil
11222 * tab-width: 8
11223 * End: