Import 2.3.99pre7-1
[davej-history.git] / drivers / scsi / aic7xxx.c
blob8d041639b000dfce379fa701d7249d2554114314
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 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 #if defined(MODULE) || defined(PCMCIA)
223 #include <linux/module.h>
224 #endif
226 #if defined(PCMCIA)
227 # undef MODULE
228 #endif
230 #include <stdarg.h>
231 #include <asm/io.h>
232 #include <asm/irq.h>
233 #include <asm/byteorder.h>
234 #include <linux/version.h>
235 #include <linux/string.h>
236 #include <linux/errno.h>
237 #include <linux/kernel.h>
238 #include <linux/ioport.h>
239 #include <linux/delay.h>
240 #include <linux/sched.h>
241 #include <linux/pci.h>
242 #include <linux/proc_fs.h>
243 #include <linux/blk.h>
244 #include <linux/tqueue.h>
245 #include <linux/init.h>
246 #include "sd.h"
247 #include "scsi.h"
248 #include "hosts.h"
249 #include "aic7xxx.h"
251 #include "aic7xxx/sequencer.h"
252 #include "aic7xxx/scsi_message.h"
253 #include "aic7xxx_reg.h"
254 #include <scsi/scsicam.h>
256 #include <linux/stat.h>
257 #include <linux/malloc.h> /* for kmalloc() */
259 #include <linux/config.h> /* for CONFIG_PCI */
262 * To generate the correct addresses for the controller to issue
263 * on the bus. Originally added for DEC Alpha support.
265 #define VIRT_TO_BUS(a) (unsigned int)virt_to_bus((void *)(a))
267 #define AIC7XXX_C_VERSION "5.2.0"
269 #define NUMBER(arr) (sizeof(arr) / sizeof(arr[0]))
270 #define MIN(a,b) (((a) < (b)) ? (a) : (b))
271 #define MAX(a,b) (((a) > (b)) ? (a) : (b))
272 #define ALL_TARGETS -1
273 #define ALL_CHANNELS -1
274 #define ALL_LUNS -1
275 #define MAX_TARGETS 16
276 #define MAX_LUNS 8
277 #ifndef TRUE
278 # define TRUE 1
279 #endif
280 #ifndef FALSE
281 # define FALSE 0
282 #endif
285 * We need the bios32.h file if we are kernel version 2.1.92 or less. The
286 * full set of pci_* changes wasn't in place until 2.1.93
289 #if LINUX_VERSION_CODE <= KERNEL_VERSION(2,1,92)
290 # if defined(__sparc_v9__) || defined(__powerpc__)
291 # error "PPC and Sparc platforms are only support under 2.1.92 and above"
292 # endif
293 # include <linux/bios32.h>
294 #endif
296 #if defined(__powerpc__)
297 # define MMAPIO
298 # ifdef mb
299 # undef mb
300 # endif
301 # define mb() \
302 __asm__ __volatile__("eieio" ::: "memory")
303 #elif defined(__i386__)
304 # define MMAPIO
305 # ifdef mb
306 # undef mb
307 # endif
308 # define mb() \
309 __asm__ __volatile__("lock ; addl $0,0(%%esp)": : :"memory")
310 #elif defined(__alpha__)
311 # ifdef mb
312 # undef mb
313 # endif
314 # define mb() \
315 __asm__ __volatile__("mb": : :"memory")
316 #endif
318 #if LINUX_VERSION_CODE > KERNEL_VERSION(2,1,0)
319 # include <linux/spinlock.h>
320 # include <linux/smp.h>
321 # define cpuid smp_processor_id()
322 # if LINUX_VERSION_CODE < KERNEL_VERSION(2,1,95)
323 # define DRIVER_LOCK_INIT \
324 spin_lock_init(&p->spin_lock);
325 # define DRIVER_LOCK \
326 if(!p->cpu_lock_count[cpuid]) { \
327 spin_lock_irqsave(&p->spin_lock, cpu_flags); \
328 p->cpu_lock_count[cpuid]++; \
329 } else { \
330 p->cpu_lock_count[cpuid]++; \
332 # define DRIVER_UNLOCK \
333 if(--p->cpu_lock_count[cpuid] == 0) \
334 spin_unlock_irqrestore(&p->spin_lock, cpu_flags);
335 # else
336 # define DRIVER_LOCK_INIT
337 # define DRIVER_LOCK
338 # define DRIVER_UNLOCK
339 # endif
340 #else
341 # define cpuid 0
342 # define DRIVER_LOCK_INIT
343 # define DRIVER_LOCK \
344 save_flags(cpu_flags); \
345 cli();
346 # define DRIVER_UNLOCK \
347 restore_flags(cpu_flags);
348 # define le32_to_cpu(x) (x)
349 # define cpu_to_le32(x) (x)
350 #endif
353 * You can try raising me if tagged queueing is enabled, or lowering
354 * me if you only have 4 SCBs.
356 #ifdef CONFIG_AIC7XXX_CMDS_PER_DEVICE
357 #define AIC7XXX_CMDS_PER_DEVICE CONFIG_AIC7XXX_CMDS_PER_DEVICE
358 #else
359 #define AIC7XXX_CMDS_PER_DEVICE 8
360 #endif
362 /* Set this to the delay in seconds after SCSI bus reset. */
363 #ifdef CONFIG_AIC7XXX_RESET_DELAY
364 #define AIC7XXX_RESET_DELAY CONFIG_AIC7XXX_RESET_DELAY
365 #else
366 #define AIC7XXX_RESET_DELAY 5
367 #endif
370 * Control collection of SCSI transfer statistics for the /proc filesystem.
372 * NOTE: Do NOT enable this when running on kernels version 1.2.x and below.
373 * NOTE: This does affect performance since it has to maintain statistics.
375 #ifdef CONFIG_AIC7XXX_PROC_STATS
376 #define AIC7XXX_PROC_STATS
377 #endif
380 * NOTE: Uncommenting the define below no longer has any effect, the
381 * tagged queue value array is always active now. I've added
382 * a setup option to set this particular array and I'm hoping
383 * insmod will be smart enough to set it properly as well. It's
384 * by use of this array that a person can enable tagged queueing.
385 * The DEFAULT_TAG_COMMANDS define has been changed to disable
386 * tagged queueing by default, so if your devices can handle tagged
387 * queueing you will need to add a line to their lilo.conf file like:
388 * append="aic7xxx=verbose,tag_info:{{32,32,32,32},{32,32,32,32}}"
389 * which will result in the first four devices on the first two
390 * controllers being set to a tagged queue depth of 32.
392 * Set this for defining the number of tagged commands on a device
393 * by device, and controller by controller basis. The first set
394 * of tagged commands will be used for the first detected aic7xxx
395 * controller, the second set will be used for the second detected
396 * aic7xxx controller, and so on. These values will *only* be used
397 * for targets that are tagged queueing capable; these values will
398 * be ignored in all other cases. The tag_commands is an array of
399 * 16 to allow for wide and twin adapters. Twin adapters will use
400 * indexes 0-7 for channel 0, and indexes 8-15 for channel 1.
402 * *** Determining commands per LUN ***
404 * When AIC7XXX_CMDS_PER_DEVICE is not defined, the driver will use its
405 * own algorithm to determine the commands/LUN. If SCB paging is
406 * enabled, which is always now, the default is 8 commands per lun
407 * that indicates it supports tagged queueing. All non-tagged devices
408 * use an internal queue depth of 3, with no more than one of those
409 * three commands active at one time.
411 /* #define AIC7XXX_TAGGED_QUEUEING_BY_DEVICE */
413 typedef struct
415 unsigned char tag_commands[16]; /* Allow for wide/twin adapters. */
416 } adapter_tag_info_t;
419 * Make a define that will tell the driver not to use tagged queueing
420 * by default.
422 #ifdef CONFIG_AIC7XXX_TCQ_ON_BY_DEFAULT
423 #define DEFAULT_TAG_COMMANDS {0, 0, 0, 0, 0, 0, 0, 0,\
424 0, 0, 0, 0, 0, 0, 0, 0}
425 #else
426 #define DEFAULT_TAG_COMMANDS {255, 255, 255, 255, 255, 255, 255, 255,\
427 255, 255, 255, 255, 255, 255, 255, 255}
428 #endif
431 * Modify this as you see fit for your system. By setting tag_commands
432 * to 0, the driver will use it's own algorithm for determining the
433 * number of commands to use (see above). When 255, the driver will
434 * not enable tagged queueing for that particular device. When positive
435 * (> 0) and (< 255) the values in the array are used for the queue_depth.
436 * Note that the maximum value for an entry is 254, but you're insane if
437 * you try to use that many commands on one device.
439 * In this example, the first line will disable tagged queueing for all
440 * the devices on the first probed aic7xxx adapter.
442 * The second line enables tagged queueing with 4 commands/LUN for IDs
443 * (1, 2-11, 13-15), disables tagged queueing for ID 12, and tells the
444 * driver to use its own algorithm for ID 1.
446 * The third line is the same as the first line.
448 * The fourth line disables tagged queueing for devices 0 and 3. It
449 * enables tagged queueing for the other IDs, with 16 commands/LUN
450 * for IDs 1 and 4, 127 commands/LUN for ID 8, and 4 commands/LUN for
451 * IDs 2, 5-7, and 9-15.
455 * NOTE: The below structure is for reference only, the actual structure
456 * to modify in order to change things is located around line
457 * number 1305
458 adapter_tag_info_t aic7xxx_tag_info[] =
460 {DEFAULT_TAG_COMMANDS},
461 {{4, 0, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 255, 4, 4, 4}},
462 {DEFAULT_TAG_COMMANDS},
463 {{255, 16, 4, 255, 16, 4, 4, 4, 127, 4, 4, 4, 4, 4, 4, 4}}
467 static adapter_tag_info_t aic7xxx_tag_info[] =
469 {DEFAULT_TAG_COMMANDS},
470 {DEFAULT_TAG_COMMANDS},
471 {DEFAULT_TAG_COMMANDS},
472 {DEFAULT_TAG_COMMANDS},
473 {DEFAULT_TAG_COMMANDS},
474 {DEFAULT_TAG_COMMANDS},
475 {DEFAULT_TAG_COMMANDS},
476 {DEFAULT_TAG_COMMANDS},
477 {DEFAULT_TAG_COMMANDS},
478 {DEFAULT_TAG_COMMANDS},
479 {DEFAULT_TAG_COMMANDS},
480 {DEFAULT_TAG_COMMANDS},
481 {DEFAULT_TAG_COMMANDS},
482 {DEFAULT_TAG_COMMANDS},
483 {DEFAULT_TAG_COMMANDS},
484 {DEFAULT_TAG_COMMANDS}
489 * Define an array of board names that can be indexed by aha_type.
490 * Don't forget to change this when changing the types!
492 static const char *board_names[] = {
493 "AIC-7xxx Unknown", /* AIC_NONE */
494 "Adaptec AIC-7810 Hardware RAID Controller", /* AIC_7810 */
495 "Adaptec AIC-7770 SCSI host adapter", /* AIC_7770 */
496 "Adaptec AHA-274X SCSI host adapter", /* AIC_7771 */
497 "Adaptec AHA-284X SCSI host adapter", /* AIC_284x */
498 "Adaptec AIC-7850 SCSI host adapter", /* AIC_7850 */
499 "Adaptec AIC-7855 SCSI host adapter", /* AIC_7855 */
500 "Adaptec AIC-7860 Ultra SCSI host adapter", /* AIC_7860 */
501 "Adaptec AHA-2940A Ultra SCSI host adapter", /* AIC_7861 */
502 "Adaptec AIC-7870 SCSI host adapter", /* AIC_7870 */
503 "Adaptec AHA-294X SCSI host adapter", /* AIC_7871 */
504 "Adaptec AHA-394X SCSI host adapter", /* AIC_7872 */
505 "Adaptec AHA-398X SCSI host adapter", /* AIC_7873 */
506 "Adaptec AHA-2944 SCSI host adapter", /* AIC_7874 */
507 "Adaptec AIC-7880 Ultra SCSI host adapter", /* AIC_7880 */
508 "Adaptec AHA-294X Ultra SCSI host adapter", /* AIC_7881 */
509 "Adaptec AHA-394X Ultra SCSI host adapter", /* AIC_7882 */
510 "Adaptec AHA-398X Ultra SCSI host adapter", /* AIC_7883 */
511 "Adaptec AHA-2944 Ultra SCSI host adapter", /* AIC_7884 */
512 "Adaptec AIC-7895 Ultra SCSI host adapter", /* AIC_7895 */
513 "Adaptec AIC-7890/1 Ultra2 SCSI host adapter", /* AIC_7890 */
514 "Adaptec AHA-293X Ultra2 SCSI host adapter", /* AIC_7890 */
515 "Adaptec AHA-294X Ultra2 SCSI host adapter", /* AIC_7890 */
516 "Adaptec AIC-7896/7 Ultra2 SCSI host adapter", /* AIC_7896 */
517 "Adaptec AHA-394X Ultra2 SCSI host adapter", /* AIC_7897 */
518 "Adaptec AHA-395X Ultra2 SCSI host adapter", /* AIC_7897 */
519 "Adaptec PCMCIA SCSI controller", /* card bus stuff */
520 "Adaptec AIC-7892 Ultra 160/m SCSI host adapter", /* AIC_7892 */
521 "Adaptec AIC-7899 Ultra 160/m SCSI host adapter", /* AIC_7899 */
525 * There should be a specific return value for this in scsi.h, but
526 * it seems that most drivers ignore it.
528 #define DID_UNDERFLOW DID_ERROR
531 * What we want to do is have the higher level scsi driver requeue
532 * the command to us. There is no specific driver status for this
533 * condition, but the higher level scsi driver will requeue the
534 * command on a DID_BUS_BUSY error.
536 * Upon further inspection and testing, it seems that DID_BUS_BUSY
537 * will *always* retry the command. We can get into an infinite loop
538 * if this happens when we really want some sort of counter that
539 * will automatically abort/reset the command after so many retries.
540 * Using DID_ERROR will do just that. (Made by a suggestion by
541 * Doug Ledford 8/1/96)
543 #define DID_RETRY_COMMAND DID_ERROR
545 #define HSCSIID 0x07
546 #define SCSI_RESET 0x040
549 * EISA/VL-bus stuff
551 #define MINSLOT 1
552 #define MAXSLOT 15
553 #define SLOTBASE(x) ((x) << 12)
554 #define BASE_TO_SLOT(x) ((x) >> 12)
557 * Standard EISA Host ID regs (Offset from slot base)
559 #define AHC_HID0 0x80 /* 0,1: msb of ID2, 2-7: ID1 */
560 #define AHC_HID1 0x81 /* 0-4: ID3, 5-7: LSB ID2 */
561 #define AHC_HID2 0x82 /* product */
562 #define AHC_HID3 0x83 /* firmware revision */
565 * AIC-7770 I/O range to reserve for a card
567 #define MINREG 0xC00
568 #define MAXREG 0xCBF
570 #define INTDEF 0x5C /* Interrupt Definition Register */
573 * AIC-78X0 PCI registers
575 #define CLASS_PROGIF_REVID 0x08
576 #define DEVREVID 0x000000FFul
577 #define PROGINFC 0x0000FF00ul
578 #define SUBCLASS 0x00FF0000ul
579 #define BASECLASS 0xFF000000ul
581 #define CSIZE_LATTIME 0x0C
582 #define CACHESIZE 0x0000003Ful /* only 5 bits */
583 #define LATTIME 0x0000FF00ul
585 #define DEVCONFIG 0x40
586 #define SCBSIZE32 0x00010000ul /* aic789X only */
587 #define MPORTMODE 0x00000400ul /* aic7870 only */
588 #define RAMPSM 0x00000200ul /* aic7870 only */
589 #define RAMPSM_ULTRA2 0x00000004
590 #define VOLSENSE 0x00000100ul
591 #define SCBRAMSEL 0x00000080ul
592 #define SCBRAMSEL_ULTRA2 0x00000008
593 #define MRDCEN 0x00000040ul
594 #define EXTSCBTIME 0x00000020ul /* aic7870 only */
595 #define EXTSCBPEN 0x00000010ul /* aic7870 only */
596 #define BERREN 0x00000008ul
597 #define DACEN 0x00000004ul
598 #define STPWLEVEL 0x00000002ul
599 #define DIFACTNEGEN 0x00000001ul /* aic7870 only */
601 #define SCAMCTL 0x1a /* Ultra2 only */
602 #define CCSCBBADDR 0xf0 /* aic7895/6/7 */
605 * Define the different types of SEEPROMs on aic7xxx adapters
606 * and make it also represent the address size used in accessing
607 * its registers. The 93C46 chips have 1024 bits organized into
608 * 64 16-bit words, while the 93C56 chips have 2048 bits organized
609 * into 128 16-bit words. The C46 chips use 6 bits to address
610 * each word, while the C56 and C66 (4096 bits) use 8 bits to
611 * address each word.
613 typedef enum {C46 = 6, C56_66 = 8} seeprom_chip_type;
617 * Define the format of the SEEPROM registers (16 bits).
620 struct seeprom_config {
623 * SCSI ID Configuration Flags
625 #define CFXFER 0x0007 /* synchronous transfer rate */
626 #define CFSYNCH 0x0008 /* enable synchronous transfer */
627 #define CFDISC 0x0010 /* enable disconnection */
628 #define CFWIDEB 0x0020 /* wide bus device (wide card) */
629 #define CFSYNCHISULTRA 0x0040 /* CFSYNC is an ultra offset */
630 #define CFNEWULTRAFORMAT 0x0080 /* Use the Ultra2 SEEPROM format */
631 #define CFSTART 0x0100 /* send start unit SCSI command */
632 #define CFINCBIOS 0x0200 /* include in BIOS scan */
633 #define CFRNFOUND 0x0400 /* report even if not found */
634 #define CFMULTILUN 0x0800 /* probe mult luns in BIOS scan */
635 #define CFWBCACHEYES 0x4000 /* Enable W-Behind Cache on drive */
636 #define CFWBCACHENC 0xc000 /* Don't change W-Behind Cache */
637 /* UNUSED 0x3000 */
638 unsigned short device_flags[16]; /* words 0-15 */
641 * BIOS Control Bits
643 #define CFSUPREM 0x0001 /* support all removable drives */
644 #define CFSUPREMB 0x0002 /* support removable drives for boot only */
645 #define CFBIOSEN 0x0004 /* BIOS enabled */
646 /* UNUSED 0x0008 */
647 #define CFSM2DRV 0x0010 /* support more than two drives */
648 #define CF284XEXTEND 0x0020 /* extended translation (284x cards) */
649 /* UNUSED 0x0040 */
650 #define CFEXTEND 0x0080 /* extended translation enabled */
651 /* UNUSED 0xFF00 */
652 unsigned short bios_control; /* word 16 */
655 * Host Adapter Control Bits
657 #define CFAUTOTERM 0x0001 /* Perform Auto termination */
658 #define CFULTRAEN 0x0002 /* Ultra SCSI speed enable (Ultra cards) */
659 #define CF284XSELTO 0x0003 /* Selection timeout (284x cards) */
660 #define CF284XFIFO 0x000C /* FIFO Threshold (284x cards) */
661 #define CFSTERM 0x0004 /* SCSI low byte termination */
662 #define CFWSTERM 0x0008 /* SCSI high byte termination (wide card) */
663 #define CFSPARITY 0x0010 /* SCSI parity */
664 #define CF284XSTERM 0x0020 /* SCSI low byte termination (284x cards) */
665 #define CFRESETB 0x0040 /* reset SCSI bus at boot */
666 #define CFBPRIMARY 0x0100 /* Channel B primary on 7895 chipsets */
667 #define CFSEAUTOTERM 0x0400 /* aic7890 Perform SE Auto Term */
668 #define CFLVDSTERM 0x0800 /* aic7890 LVD Termination */
669 /* UNUSED 0xF280 */
670 unsigned short adapter_control; /* word 17 */
673 * Bus Release, Host Adapter ID
675 #define CFSCSIID 0x000F /* host adapter SCSI ID */
676 /* UNUSED 0x00F0 */
677 #define CFBRTIME 0xFF00 /* bus release time */
678 unsigned short brtime_id; /* word 18 */
681 * Maximum targets
683 #define CFMAXTARG 0x00FF /* maximum targets */
684 /* UNUSED 0xFF00 */
685 unsigned short max_targets; /* word 19 */
687 unsigned short res_1[11]; /* words 20-30 */
688 unsigned short checksum; /* word 31 */
691 #define SELBUS_MASK 0x0a
692 #define SELNARROW 0x00
693 #define SELBUSB 0x08
694 #define SINGLE_BUS 0x00
696 #define SCB_TARGET(scb) \
697 (((scb)->hscb->target_channel_lun & TID) >> 4)
698 #define SCB_LUN(scb) \
699 ((scb)->hscb->target_channel_lun & LID)
700 #define SCB_IS_SCSIBUS_B(scb) \
701 (((scb)->hscb->target_channel_lun & SELBUSB) != 0)
704 * If an error occurs during a data transfer phase, run the command
705 * to completion - it's easier that way - making a note of the error
706 * condition in this location. This then will modify a DID_OK status
707 * into an appropriate error for the higher-level SCSI code.
709 #define aic7xxx_error(cmd) ((cmd)->SCp.Status)
712 * Keep track of the targets returned status.
714 #define aic7xxx_status(cmd) ((cmd)->SCp.sent_command)
717 * The position of the SCSI commands scb within the scb array.
719 #define aic7xxx_position(cmd) ((cmd)->SCp.have_data_in)
722 * The stored DMA mapping for single-buffer data transfers.
724 #define aic7xxx_mapping(cmd) ((cmd)->SCp.phase)
727 * So we can keep track of our host structs
729 static struct aic7xxx_host *first_aic7xxx = NULL;
732 * As of Linux 2.1, the mid-level SCSI code uses virtual addresses
733 * in the scatter-gather lists. We need to convert the virtual
734 * addresses to physical addresses.
736 struct hw_scatterlist {
737 unsigned int address;
738 unsigned int length;
742 * Maximum number of SG segments these cards can support.
744 #define AIC7XXX_MAX_SG 128
747 * The maximum number of SCBs we could have for ANY type
748 * of card. DON'T FORGET TO CHANGE THE SCB MASK IN THE
749 * SEQUENCER CODE IF THIS IS MODIFIED!
751 #define AIC7XXX_MAXSCB 255
754 struct aic7xxx_hwscb {
755 /* ------------ Begin hardware supported fields ---------------- */
756 /* 0*/ unsigned char control;
757 /* 1*/ unsigned char target_channel_lun; /* 4/1/3 bits */
758 /* 2*/ unsigned char target_status;
759 /* 3*/ unsigned char SG_segment_count;
760 /* 4*/ unsigned int SG_list_pointer;
761 /* 8*/ unsigned char residual_SG_segment_count;
762 /* 9*/ unsigned char residual_data_count[3];
763 /*12*/ unsigned int data_pointer;
764 /*16*/ unsigned int data_count;
765 /*20*/ unsigned int SCSI_cmd_pointer;
766 /*24*/ unsigned char SCSI_cmd_length;
767 /*25*/ unsigned char tag; /* Index into our kernel SCB array.
768 * Also used as the tag for tagged I/O
770 #define SCB_PIO_TRANSFER_SIZE 26 /* amount we need to upload/download
771 * via PIO to initialize a transaction.
773 /*26*/ unsigned char next; /* Used to thread SCBs awaiting selection
774 * or disconnected down in the sequencer.
776 /*27*/ unsigned char prev;
777 /*28*/ unsigned int pad; /*
778 * Unused by the kernel, but we require
779 * the padding so that the array of
780 * hardware SCBs is alligned on 32 byte
781 * boundaries so the sequencer can index
785 typedef enum {
786 SCB_FREE = 0x0000,
787 SCB_WAITINGQ = 0x0002,
788 SCB_ACTIVE = 0x0004,
789 SCB_SENSE = 0x0008,
790 SCB_ABORT = 0x0010,
791 SCB_DEVICE_RESET = 0x0020,
792 SCB_RESET = 0x0040,
793 SCB_RECOVERY_SCB = 0x0080,
794 SCB_MSGOUT_PPR = 0x0100,
795 SCB_MSGOUT_SENT = 0x0200,
796 SCB_MSGOUT_SDTR = 0x0400,
797 SCB_MSGOUT_WDTR = 0x0800,
798 SCB_MSGOUT_BITS = SCB_MSGOUT_PPR |
799 SCB_MSGOUT_SENT |
800 SCB_MSGOUT_SDTR |
801 SCB_MSGOUT_WDTR,
802 SCB_QUEUED_ABORT = 0x1000,
803 SCB_QUEUED_FOR_DONE = 0x2000,
804 SCB_WAS_BUSY = 0x4000
805 } scb_flag_type;
807 typedef enum {
808 AHC_FNONE = 0x00000000,
809 AHC_PAGESCBS = 0x00000001,
810 AHC_CHANNEL_B_PRIMARY = 0x00000002,
811 AHC_USEDEFAULTS = 0x00000004,
812 AHC_INDIRECT_PAGING = 0x00000008,
813 AHC_CHNLB = 0x00000020,
814 AHC_CHNLC = 0x00000040,
815 AHC_EXTEND_TRANS_A = 0x00000100,
816 AHC_EXTEND_TRANS_B = 0x00000200,
817 AHC_TERM_ENB_A = 0x00000400,
818 AHC_TERM_ENB_SE_LOW = 0x00000400,
819 AHC_TERM_ENB_B = 0x00000800,
820 AHC_TERM_ENB_SE_HIGH = 0x00000800,
821 AHC_HANDLING_REQINITS = 0x00001000,
822 AHC_TARGETMODE = 0x00002000,
823 AHC_NEWEEPROM_FMT = 0x00004000,
825 * Here ends the FreeBSD defined flags and here begins the linux defined
826 * flags. NOTE: I did not preserve the old flag name during this change
827 * specifically to force me to evaluate what flags were being used properly
828 * and what flags weren't. This way, I could clean up the flag usage on
829 * a use by use basis. Doug Ledford
831 AHC_NO_STPWR = 0x00040000,
832 AHC_RESET_DELAY = 0x00080000,
833 AHC_A_SCANNED = 0x00100000,
834 AHC_B_SCANNED = 0x00200000,
835 AHC_MULTI_CHANNEL = 0x00400000,
836 AHC_BIOS_ENABLED = 0x00800000,
837 AHC_SEEPROM_FOUND = 0x01000000,
838 AHC_TERM_ENB_LVD = 0x02000000,
839 AHC_ABORT_PENDING = 0x04000000,
840 AHC_RESET_PENDING = 0x08000000,
841 #define AHC_IN_ISR_BIT 28
842 AHC_IN_ISR = 0x10000000,
843 AHC_IN_ABORT = 0x20000000,
844 AHC_IN_RESET = 0x40000000,
845 AHC_EXTERNAL_SRAM = 0x80000000
846 } ahc_flag_type;
848 typedef enum {
849 AHC_NONE = 0x0000,
850 AHC_CHIPID_MASK = 0x00ff,
851 AHC_AIC7770 = 0x0001,
852 AHC_AIC7850 = 0x0002,
853 AHC_AIC7860 = 0x0003,
854 AHC_AIC7870 = 0x0004,
855 AHC_AIC7880 = 0x0005,
856 AHC_AIC7890 = 0x0006,
857 AHC_AIC7895 = 0x0007,
858 AHC_AIC7896 = 0x0008,
859 AHC_AIC7892 = 0x0009,
860 AHC_AIC7899 = 0x000a,
861 AHC_VL = 0x0100,
862 AHC_EISA = 0x0200,
863 AHC_PCI = 0x0400,
864 } ahc_chip;
866 typedef enum {
867 AHC_FENONE = 0x0000,
868 AHC_ULTRA = 0x0001,
869 AHC_ULTRA2 = 0x0002,
870 AHC_WIDE = 0x0004,
871 AHC_TWIN = 0x0008,
872 AHC_MORE_SRAM = 0x0010,
873 AHC_CMD_CHAN = 0x0020,
874 AHC_QUEUE_REGS = 0x0040,
875 AHC_SG_PRELOAD = 0x0080,
876 AHC_SPIOCAP = 0x0100,
877 AHC_ULTRA3 = 0x0200,
878 AHC_NEW_AUTOTERM = 0x0400,
879 AHC_AIC7770_FE = AHC_FENONE,
880 AHC_AIC7850_FE = AHC_SPIOCAP,
881 AHC_AIC7860_FE = AHC_ULTRA|AHC_SPIOCAP,
882 AHC_AIC7870_FE = AHC_FENONE,
883 AHC_AIC7880_FE = AHC_ULTRA,
884 AHC_AIC7890_FE = AHC_MORE_SRAM|AHC_CMD_CHAN|AHC_ULTRA2|
885 AHC_QUEUE_REGS|AHC_SG_PRELOAD|AHC_NEW_AUTOTERM,
886 AHC_AIC7895_FE = AHC_MORE_SRAM|AHC_CMD_CHAN|AHC_ULTRA,
887 AHC_AIC7896_FE = AHC_AIC7890_FE,
888 AHC_AIC7892_FE = AHC_AIC7890_FE|AHC_ULTRA3,
889 AHC_AIC7899_FE = AHC_AIC7890_FE|AHC_ULTRA3,
890 } ahc_feature;
892 #define SCB_DMA_ADDR(scb, addr) ((unsigned long)(addr) + (scb)->scb_dma->dma_offset)
894 struct aic7xxx_scb_dma {
895 unsigned long dma_offset; /* Correction you have to add
896 * to virtual address to get
897 * dma handle in this region */
898 dma_addr_t dma_address; /* DMA handle of the start,
899 * for unmap */
900 unsigned int dma_len; /* DMA length */
903 struct aic7xxx_scb {
904 struct aic7xxx_hwscb *hscb; /* corresponding hardware scb */
905 Scsi_Cmnd *cmd; /* Scsi_Cmnd for this scb */
906 struct aic7xxx_scb *q_next; /* next scb in queue */
907 volatile scb_flag_type flags; /* current state of scb */
908 struct hw_scatterlist *sg_list; /* SG list in adapter format */
909 unsigned char tag_action;
910 unsigned char sg_count;
911 unsigned char *sense_cmd; /*
912 * Allocate 6 characters for
913 * sense command.
915 unsigned char *cmnd;
916 unsigned int sg_length; /* We init this during buildscb so we
917 * don't have to calculate anything
918 * during underflow/overflow/stat code
920 void *kmalloc_ptr;
921 struct aic7xxx_scb_dma *scb_dma;
925 * Define a linked list of SCBs.
927 typedef struct {
928 struct aic7xxx_scb *head;
929 struct aic7xxx_scb *tail;
930 } scb_queue_type;
932 static struct {
933 unsigned char errno;
934 const char *errmesg;
935 } hard_error[] = {
936 { ILLHADDR, "Illegal Host Access" },
937 { ILLSADDR, "Illegal Sequencer Address referenced" },
938 { ILLOPCODE, "Illegal Opcode in sequencer program" },
939 { SQPARERR, "Sequencer Ram Parity Error" },
940 { DPARERR, "Data-Path Ram Parity Error" },
941 { MPARERR, "Scratch Ram/SCB Array Ram Parity Error" },
942 { PCIERRSTAT,"PCI Error detected" },
943 { CIOPARERR, "CIOBUS Parity Error" }
946 static unsigned char
947 generic_sense[] = { REQUEST_SENSE, 0, 0, 0, 255, 0 };
949 typedef struct {
950 scb_queue_type free_scbs; /*
951 * SCBs assigned to free slot on
952 * card (no paging required)
954 struct aic7xxx_scb *scb_array[AIC7XXX_MAXSCB];
955 struct aic7xxx_hwscb *hscbs;
956 unsigned char numscbs; /* current number of scbs */
957 unsigned char maxhscbs; /* hardware scbs */
958 unsigned char maxscbs; /* max scbs including pageable scbs */
959 dma_addr_t hscbs_dma; /* DMA handle to hscbs */
960 unsigned int hscbs_dma_len; /* length of the above DMA area */
961 void *hscb_kmalloc_ptr;
962 } scb_data_type;
964 struct target_cmd {
965 unsigned char mesg_bytes[4];
966 unsigned char command[28];
969 #define AHC_TRANS_CUR 0x0001
970 #define AHC_TRANS_ACTIVE 0x0002
971 #define AHC_TRANS_GOAL 0x0004
972 #define AHC_TRANS_USER 0x0008
973 #define AHC_TRANS_QUITE 0x0010
974 typedef struct {
975 unsigned char cur_width;
976 unsigned char goal_width;
977 unsigned char cur_period;
978 unsigned char goal_period;
979 unsigned char cur_offset;
980 unsigned char goal_offset;
981 unsigned char cur_options;
982 unsigned char goal_options;
983 unsigned char user_width;
984 unsigned char user_period;
985 unsigned char user_offset;
986 unsigned char user_options;
987 } transinfo_type;
990 * Define a structure used for each host adapter. Note, in order to avoid
991 * problems with architectures I can't test on (because I don't have one,
992 * such as the Alpha based systems) which happen to give faults for
993 * non-aligned memory accesses, care was taken to align this structure
994 * in a way that gauranteed all accesses larger than 8 bits were aligned
995 * on the appropriate boundary. It's also organized to try and be more
996 * cache line efficient. Be careful when changing this lest you might hurt
997 * overall performance and bring down the wrath of the masses.
999 struct aic7xxx_host {
1001 * This is the first 64 bytes in the host struct
1005 * We are grouping things here....first, items that get either read or
1006 * written with nearly every interrupt
1008 volatile ahc_flag_type flags;
1009 ahc_feature features; /* chip features */
1010 unsigned long base; /* card base address */
1011 volatile unsigned char *maddr; /* memory mapped address */
1012 unsigned long isr_count; /* Interrupt count */
1013 unsigned long spurious_int;
1014 scb_data_type *scb_data;
1015 volatile unsigned short needdv;
1016 volatile unsigned short needppr;
1017 volatile unsigned short needsdtr;
1018 volatile unsigned short needwdtr;
1019 volatile unsigned short dtr_pending;
1020 struct aic7xxx_cmd_queue {
1021 Scsi_Cmnd *head;
1022 Scsi_Cmnd *tail;
1023 } completeq;
1026 * Things read/written on nearly every entry into aic7xxx_queue()
1028 volatile scb_queue_type waiting_scbs;
1029 unsigned short discenable; /* Targets allowed to disconnect */
1030 unsigned short tagenable; /* Targets using tagged I/O */
1031 unsigned short orderedtag; /* Ordered Q tags allowed */
1032 unsigned char unpause; /* unpause value for HCNTRL */
1033 unsigned char pause; /* pause value for HCNTRL */
1034 volatile unsigned char qoutfifonext;
1035 volatile unsigned char activescbs; /* active scbs */
1036 volatile unsigned char max_activescbs;
1037 volatile unsigned char qinfifonext;
1038 volatile unsigned char *untagged_scbs;
1039 volatile unsigned char *qoutfifo;
1040 volatile unsigned char *qinfifo;
1042 #define DEVICE_PRESENT 0x01
1043 #define BUS_DEVICE_RESET_PENDING 0x02
1044 #define DEVICE_RESET_DELAY 0x04
1045 #define DEVICE_PRINT_DTR 0x08
1046 #define DEVICE_PARITY_ERROR 0x10
1047 #define DEVICE_WAS_BUSY 0x20
1048 #define DEVICE_SCSI_3 0x40
1049 #define DEVICE_SCANNED 0x80
1050 volatile unsigned char dev_flags[MAX_TARGETS];
1051 volatile unsigned char dev_active_cmds[MAX_TARGETS];
1052 volatile unsigned char dev_temp_queue_depth[MAX_TARGETS];
1053 unsigned char dev_commands_sent[MAX_TARGETS];
1055 unsigned int dev_timer_active; /* Which devs have a timer set */
1056 struct timer_list dev_timer;
1057 unsigned long dev_expires[MAX_TARGETS];
1059 #if LINUX_VERSION_CODE > KERNEL_VERSION(2,1,0)
1060 spinlock_t spin_lock;
1061 volatile unsigned char cpu_lock_count[NR_CPUS];
1062 #endif
1065 Scsi_Cmnd *dev_dtr_cmnd[MAX_TARGETS];
1067 unsigned int dev_checksum[MAX_TARGETS];
1069 unsigned char dev_last_queue_full[MAX_TARGETS];
1070 unsigned char dev_last_queue_full_count[MAX_TARGETS];
1071 unsigned char dev_max_queue_depth[MAX_TARGETS];
1073 volatile scb_queue_type delayed_scbs[MAX_TARGETS];
1076 unsigned char msg_buf[13]; /* The message for the target */
1077 unsigned char msg_type;
1078 #define MSG_TYPE_NONE 0x00
1079 #define MSG_TYPE_INITIATOR_MSGOUT 0x01
1080 #define MSG_TYPE_INITIATOR_MSGIN 0x02
1081 unsigned char msg_len; /* Length of message */
1082 unsigned char msg_index; /* Index into msg_buf array */
1083 transinfo_type transinfo[MAX_TARGETS];
1087 * We put the less frequently used host structure items after the more
1088 * frequently used items to try and ease the burden on the cache subsystem.
1089 * These entries are not *commonly* accessed, whereas the preceding entries
1090 * are accessed very often.
1093 unsigned int irq; /* IRQ for this adapter */
1094 int instance; /* aic7xxx instance number */
1095 int scsi_id; /* host adapter SCSI ID */
1096 int scsi_id_b; /* channel B for twin adapters */
1097 unsigned int bios_address;
1098 int board_name_index;
1099 unsigned short needppr_copy; /* default config */
1100 unsigned short needsdtr_copy; /* default config */
1101 unsigned short needwdtr_copy; /* default config */
1102 unsigned short ultraenb; /* Ultra mode target list */
1103 unsigned short bios_control; /* bios control - SEEPROM */
1104 unsigned short adapter_control; /* adapter control - SEEPROM */
1105 struct pci_dev *pdev;
1106 unsigned char pci_bus;
1107 unsigned char pci_device_fn;
1108 struct seeprom_config sc;
1109 unsigned short sc_type;
1110 unsigned short sc_size;
1111 struct aic7xxx_host *next; /* allow for multiple IRQs */
1112 struct Scsi_Host *host; /* pointer to scsi host */
1113 int host_no; /* SCSI host number */
1114 unsigned long mbase; /* I/O memory address */
1115 ahc_chip chip; /* chip type */
1116 dma_addr_t fifo_dma; /* DMA handle for fifo arrays */
1119 * Statistics Kept:
1121 * Total Xfers (count for each command that has a data xfer),
1122 * broken down further by reads && writes.
1124 * Binned sizes, writes && reads:
1125 * < 512, 512, 1-2K, 2-4K, 4-8K, 8-16K, 16-32K, 32-64K, 64K-128K, > 128K
1127 * Total amounts read/written above 512 bytes (amts under ignored)
1129 * NOTE: Enabling this feature is likely to cause a noticeable performance
1130 * decrease as the accesses into the stats structures blows apart multiple
1131 * cache lines and is CPU time consuming.
1133 * NOTE: Since it doesn't really buy us much, but consumes *tons* of RAM
1134 * and blows apart all sorts of cache lines, I modified this so that we
1135 * no longer look at the LUN. All LUNs now go into the same bin on each
1136 * device for stats purposes.
1138 struct aic7xxx_xferstats {
1139 long w_total; /* total writes */
1140 long r_total; /* total reads */
1141 #ifdef AIC7XXX_PROC_STATS
1142 long w_bins[8]; /* binned write */
1143 long r_bins[8]; /* binned reads */
1144 #endif /* AIC7XXX_PROC_STATS */
1145 } stats[MAX_TARGETS]; /* [(channel << 3)|target] */
1147 #if 0
1148 struct target_cmd *targetcmds;
1149 unsigned int num_targetcmds;
1150 #endif
1155 * Valid SCSIRATE values. (p. 3-17)
1156 * Provides a mapping of transfer periods in ns/4 to the proper value to
1157 * stick in the SCSIRATE reg to use that transfer rate.
1159 #define AHC_SYNCRATE_ULTRA3 0
1160 #define AHC_SYNCRATE_ULTRA2 1
1161 #define AHC_SYNCRATE_ULTRA 3
1162 #define AHC_SYNCRATE_FAST 6
1163 #define AHC_SYNCRATE_CRC 0x40
1164 #define AHC_SYNCRATE_SE 0x10
1165 static struct aic7xxx_syncrate {
1166 /* Rates in Ultra mode have bit 8 of sxfr set */
1167 #define ULTRA_SXFR 0x100
1168 int sxfr_ultra2;
1169 int sxfr;
1170 unsigned char period;
1171 const char *rate[2];
1172 } aic7xxx_syncrates[] = {
1173 { 0x42, 0x000, 9, {"80.0", "160.0"} },
1174 { 0x13, 0x000, 10, {"40.0", "80.0"} },
1175 { 0x14, 0x000, 11, {"33.0", "66.6"} },
1176 { 0x15, 0x100, 12, {"20.0", "40.0"} },
1177 { 0x16, 0x110, 15, {"16.0", "32.0"} },
1178 { 0x17, 0x120, 18, {"13.4", "26.8"} },
1179 { 0x18, 0x000, 25, {"10.0", "20.0"} },
1180 { 0x19, 0x010, 31, {"8.0", "16.0"} },
1181 { 0x1a, 0x020, 37, {"6.67", "13.3"} },
1182 { 0x1b, 0x030, 43, {"5.7", "11.4"} },
1183 { 0x10, 0x040, 50, {"5.0", "10.0"} },
1184 { 0x00, 0x050, 56, {"4.4", "8.8" } },
1185 { 0x00, 0x060, 62, {"4.0", "8.0" } },
1186 { 0x00, 0x070, 68, {"3.6", "7.2" } },
1187 { 0x00, 0x000, 0, {NULL, NULL} },
1190 #define CTL_OF_SCB(scb) (((scb->hscb)->target_channel_lun >> 3) & 0x1), \
1191 (((scb->hscb)->target_channel_lun >> 4) & 0xf), \
1192 ((scb->hscb)->target_channel_lun & 0x07)
1194 #define CTL_OF_CMD(cmd) ((cmd->channel) & 0x01), \
1195 ((cmd->target) & 0x0f), \
1196 ((cmd->lun) & 0x07)
1198 #define TARGET_INDEX(cmd) ((cmd)->target | ((cmd)->channel << 3))
1201 * A nice little define to make doing our printks a little easier
1204 #define WARN_LEAD KERN_WARNING "(scsi%d:%d:%d:%d) "
1205 #define INFO_LEAD KERN_INFO "(scsi%d:%d:%d:%d) "
1208 * XXX - these options apply unilaterally to _all_ 274x/284x/294x
1209 * cards in the system. This should be fixed. Exceptions to this
1210 * rule are noted in the comments.
1215 * Skip the scsi bus reset. Non 0 make us skip the reset at startup. This
1216 * has no effect on any later resets that might occur due to things like
1217 * SCSI bus timeouts.
1219 static unsigned int aic7xxx_no_reset = 0;
1221 * Certain PCI motherboards will scan PCI devices from highest to lowest,
1222 * others scan from lowest to highest, and they tend to do all kinds of
1223 * strange things when they come into contact with PCI bridge chips. The
1224 * net result of all this is that the PCI card that is actually used to boot
1225 * the machine is very hard to detect. Most motherboards go from lowest
1226 * PCI slot number to highest, and the first SCSI controller found is the
1227 * one you boot from. The only exceptions to this are when a controller
1228 * has its BIOS disabled. So, we by default sort all of our SCSI controllers
1229 * from lowest PCI slot number to highest PCI slot number. We also force
1230 * all controllers with their BIOS disabled to the end of the list. This
1231 * works on *almost* all computers. Where it doesn't work, we have this
1232 * option. Setting this option to non-0 will reverse the order of the sort
1233 * to highest first, then lowest, but will still leave cards with their BIOS
1234 * disabled at the very end. That should fix everyone up unless there are
1235 * really strange cirumstances.
1237 static int aic7xxx_reverse_scan = 0;
1239 * Should we force EXTENDED translation on a controller.
1240 * 0 == Use whatever is in the SEEPROM or default to off
1241 * 1 == Use whatever is in the SEEPROM or default to on
1243 static unsigned int aic7xxx_extended = 0;
1245 * The IRQ trigger method used on EISA controllers. Does not effect PCI cards.
1246 * -1 = Use detected settings.
1247 * 0 = Force Edge triggered mode.
1248 * 1 = Force Level triggered mode.
1250 static int aic7xxx_irq_trigger = -1;
1252 * This variable is used to override the termination settings on a controller.
1253 * This should not be used under normal conditions. However, in the case
1254 * that a controller does not have a readable SEEPROM (so that we can't
1255 * read the SEEPROM settings directly) and that a controller has a buggered
1256 * version of the cable detection logic, this can be used to force the
1257 * correct termination. It is preferable to use the manual termination
1258 * settings in the BIOS if possible, but some motherboard controllers store
1259 * those settings in a format we can't read. In other cases, auto term
1260 * should also work, but the chipset was put together with no auto term
1261 * logic (common on motherboard controllers). In those cases, we have
1262 * 32 bits here to work with. That's good for 8 controllers/channels. The
1263 * bits are organized as 4 bits per channel, with scsi0 getting the lowest
1264 * 4 bits in the int. A 1 in a bit position indicates the termination setting
1265 * that corresponds to that bit should be enabled, a 0 is disabled.
1266 * It looks something like this:
1268 * 0x0f = 1111-Single Ended Low Byte Termination on/off
1269 * ||\-Single Ended High Byte Termination on/off
1270 * |\-LVD Low Byte Termination on/off
1271 * \-LVD High Byte Termination on/off
1273 * For non-Ultra2 controllers, the upper 2 bits are not important. So, to
1274 * enable both high byte and low byte termination on scsi0, I would need to
1275 * make sure that the override_term variable was set to 0x03 (bits 0011).
1276 * To make sure that all termination is enabled on an Ultra2 controller at
1277 * scsi2 and only high byte termination on scsi1 and high and low byte
1278 * termination on scsi0, I would set override_term=0xf23 (bits 1111 0010 0011)
1280 * For the most part, users should never have to use this, that's why I
1281 * left it fairly cryptic instead of easy to understand. If you need it,
1282 * most likely someone will be telling you what your's needs to be set to.
1284 static int aic7xxx_override_term = -1;
1286 * Certain motherboard chipset controllers tend to screw
1287 * up the polarity of the term enable output pin. Use this variable
1288 * to force the correct polarity for your system. This is a bitfield variable
1289 * similar to the previous one, but this one has one bit per channel instead
1290 * of four.
1291 * 0 = Force the setting to active low.
1292 * 1 = Force setting to active high.
1293 * Most Adaptec cards are active high, several motherboards are active low.
1294 * To force a 2940 card at SCSI 0 to active high and a motherboard 7895
1295 * controller at scsi1 and scsi2 to active low, and a 2910 card at scsi3
1296 * to active high, you would need to set stpwlev=0x9 (bits 1001).
1298 * People shouldn't need to use this, but if you are experiencing lots of
1299 * SCSI timeout problems, this may help. There is one sure way to test what
1300 * this option needs to be. Using a boot floppy to boot the system, configure
1301 * your system to enable all SCSI termination (in the Adaptec SCSI BIOS) and
1302 * if needed then also pass a value to override_term to make sure that the
1303 * driver is enabling SCSI termination, then set this variable to either 0
1304 * or 1. When the driver boots, make sure there are *NO* SCSI cables
1305 * connected to your controller. If it finds and inits the controller
1306 * without problem, then the setting you passed to stpwlev was correct. If
1307 * the driver goes into a reset loop and hangs the system, then you need the
1308 * other setting for this variable. If neither setting lets the machine
1309 * boot then you have definite termination problems that may not be fixable.
1311 static int aic7xxx_stpwlev = -1;
1313 * Set this to non-0 in order to force the driver to panic the kernel
1314 * and print out debugging info on a SCSI abort or reset cycle.
1316 static int aic7xxx_panic_on_abort = 0;
1318 * PCI bus parity checking of the Adaptec controllers. This is somewhat
1319 * dubious at best. To my knowledge, this option has never actually
1320 * solved a PCI parity problem, but on certain machines with broken PCI
1321 * chipset configurations, it can generate tons of false error messages.
1322 * It's included in the driver for completeness.
1323 * 0 = Shut off PCI parity check
1324 * -1 = Normal polarity pci parity checking
1325 * 1 = reverse polarity pci parity checking
1327 * NOTE: you can't actually pass -1 on the lilo prompt. So, to set this
1328 * variable to -1 you would actually want to simply pass the variable
1329 * name without a number. That will invert the 0 which will result in
1330 * -1.
1332 static int aic7xxx_pci_parity = 0;
1334 * Set this to any non-0 value to cause us to dump the contents of all
1335 * the card's registers in a hex dump format tailored to each model of
1336 * controller.
1338 * NOTE: THE CONTROLLER IS LEFT IN AN UNUSEABLE STATE BY THIS OPTION.
1339 * YOU CANNOT BOOT UP WITH THIS OPTION, IT IS FOR DEBUGGING PURPOSES
1340 * ONLY
1342 static int aic7xxx_dump_card = 0;
1344 * Set this to a non-0 value to make us dump out the 32 bit instruction
1345 * registers on the card after completing the sequencer download. This
1346 * allows the actual sequencer download to be verified. It is possible
1347 * to use this option and still boot up and run your system. This is
1348 * only intended for debugging purposes.
1350 static int aic7xxx_dump_sequencer = 0;
1352 * Certain newer motherboards have put new PCI based devices into the
1353 * IO spaces that used to typically be occupied by VLB or EISA cards.
1354 * This overlap can cause these newer motherboards to lock up when scanned
1355 * for older EISA and VLB devices. Setting this option to non-0 will
1356 * cause the driver to skip scanning for any VLB or EISA controllers and
1357 * only support the PCI controllers. NOTE: this means that if the kernel
1358 * os compiled with PCI support disabled, then setting this to non-0
1359 * would result in never finding any devices :)
1361 static int aic7xxx_no_probe = 0;
1363 * On some machines, enabling the external SCB RAM isn't reliable yet. I
1364 * haven't had time to make test patches for things like changing the
1365 * timing mode on that external RAM either. Some of those changes may
1366 * fix the problem. Until then though, we default to external SCB RAM
1367 * off and give a command line option to enable it.
1369 static int aic7xxx_scbram = 0;
1371 * So that we can set how long each device is given as a selection timeout.
1372 * The table of values goes like this:
1373 * 0 - 256ms
1374 * 1 - 128ms
1375 * 2 - 64ms
1376 * 3 - 32ms
1377 * We default to 64ms because it's fast. Some old SCSI-I devices need a
1378 * longer time. The final value has to be left shifted by 3, hence 0x10
1379 * is the final value.
1381 static int aic7xxx_seltime = 0x10;
1383 * So that insmod can find the variable and make it point to something
1385 #ifdef MODULE
1386 static char * aic7xxx = NULL;
1387 #if LINUX_VERSION_CODE > KERNEL_VERSION(2,1,18)
1388 MODULE_PARM(aic7xxx, "s");
1389 #endif
1392 * Just in case someone uses commas to separate items on the insmod
1393 * command line, we define a dummy buffer here to avoid having insmod
1394 * write wild stuff into our code segment
1396 static char dummy_buffer[60] = "Please don't trounce on me insmod!!\n";
1398 #endif
1400 #define VERBOSE_NORMAL 0x0000
1401 #define VERBOSE_NEGOTIATION 0x0001
1402 #define VERBOSE_SEQINT 0x0002
1403 #define VERBOSE_SCSIINT 0x0004
1404 #define VERBOSE_PROBE 0x0008
1405 #define VERBOSE_PROBE2 0x0010
1406 #define VERBOSE_NEGOTIATION2 0x0020
1407 #define VERBOSE_MINOR_ERROR 0x0040
1408 #define VERBOSE_TRACING 0x0080
1409 #define VERBOSE_ABORT 0x0f00
1410 #define VERBOSE_ABORT_MID 0x0100
1411 #define VERBOSE_ABORT_FIND 0x0200
1412 #define VERBOSE_ABORT_PROCESS 0x0400
1413 #define VERBOSE_ABORT_RETURN 0x0800
1414 #define VERBOSE_RESET 0xf000
1415 #define VERBOSE_RESET_MID 0x1000
1416 #define VERBOSE_RESET_FIND 0x2000
1417 #define VERBOSE_RESET_PROCESS 0x4000
1418 #define VERBOSE_RESET_RETURN 0x8000
1419 static int aic7xxx_verbose = VERBOSE_NORMAL | VERBOSE_NEGOTIATION |
1420 VERBOSE_PROBE; /* verbose messages */
1423 /****************************************************************************
1425 * We're going to start putting in function declarations so that order of
1426 * functions is no longer important. As needed, they are added here.
1428 ***************************************************************************/
1430 static void aic7xxx_panic_abort(struct aic7xxx_host *p, Scsi_Cmnd *cmd);
1431 static void aic7xxx_print_card(struct aic7xxx_host *p);
1432 static void aic7xxx_print_scratch_ram(struct aic7xxx_host *p);
1433 static void aic7xxx_print_sequencer(struct aic7xxx_host *p, int downloaded);
1434 #ifdef AIC7XXX_VERBOSE_DEBUGGING
1435 static void aic7xxx_check_scbs(struct aic7xxx_host *p, char *buffer);
1436 #endif
1438 /****************************************************************************
1440 * These functions are now used. They happen to be wrapped in useless
1441 * inb/outb port read/writes around the real reads and writes because it
1442 * seems that certain very fast CPUs have a problem dealing with us when
1443 * going at full speed.
1445 ***************************************************************************/
1447 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,1,0)
1448 static inline void
1449 mdelay(int milliseconds)
1451 int i;
1453 for(i=0; i<milliseconds; i++)
1454 udelay(1000);
1457 static inline int
1458 time_after_eq(unsigned long a, unsigned long b)
1460 return((long)((a) - (b)) >= 0L);
1463 static inline int
1464 timer_pending(struct timer_list *timer)
1466 return( timer->prev != NULL );
1469 #define PCI_DEVICE_ID_ADAPTEC_1480A 0x6075
1471 #endif
1473 static inline unsigned char
1474 aic_inb(struct aic7xxx_host *p, long port)
1476 #ifdef MMAPIO
1477 unsigned char x;
1478 if(p->maddr)
1480 x = readb(p->maddr + port);
1482 else
1484 x = inb(p->base + port);
1486 mb();
1487 return(x);
1488 #else
1489 return(inb(p->base + port));
1490 #endif
1493 static inline void
1494 aic_outb(struct aic7xxx_host *p, unsigned char val, long port)
1496 #ifdef MMAPIO
1497 if(p->maddr)
1499 writeb(val, p->maddr + port);
1501 else
1503 outb(val, p->base + port);
1505 mb();
1506 #else
1507 outb(val, p->base + port);
1508 #endif
1511 /*+F*************************************************************************
1512 * Function:
1513 * aic7xxx_setup
1515 * Description:
1516 * Handle Linux boot parameters. This routine allows for assigning a value
1517 * to a parameter with a ':' between the parameter and the value.
1518 * ie. aic7xxx=unpause:0x0A,extended
1519 *-F*************************************************************************/
1520 static int
1521 aic7xxx_setup(char *s)
1523 int i, n;
1524 char *p;
1525 char *end;
1527 static struct {
1528 const char *name;
1529 unsigned int *flag;
1530 } options[] = {
1531 { "extended", &aic7xxx_extended },
1532 { "no_reset", &aic7xxx_no_reset },
1533 { "irq_trigger", &aic7xxx_irq_trigger },
1534 { "verbose", &aic7xxx_verbose },
1535 { "reverse_scan",&aic7xxx_reverse_scan },
1536 { "override_term", &aic7xxx_override_term },
1537 { "stpwlev", &aic7xxx_stpwlev },
1538 { "no_probe", &aic7xxx_no_probe },
1539 { "panic_on_abort", &aic7xxx_panic_on_abort },
1540 { "pci_parity", &aic7xxx_pci_parity },
1541 { "dump_card", &aic7xxx_dump_card },
1542 { "dump_sequencer", &aic7xxx_dump_sequencer },
1543 { "scbram", &aic7xxx_scbram },
1544 { "seltime", &aic7xxx_seltime },
1545 { "tag_info", NULL }
1548 end = strchr(s, '\0');
1550 for (p = strtok(s, ",."); p; p = strtok(NULL, ",."))
1552 for (i = 0; i < NUMBER(options); i++)
1554 n = strlen(options[i].name);
1555 if (!strncmp(options[i].name, p, n))
1557 if (!strncmp(p, "tag_info", n))
1559 if (p[n] == ':')
1561 char *base;
1562 char *tok, *tok_end, *tok_end2;
1563 char tok_list[] = { '.', ',', '{', '}', '\0' };
1564 int i, instance = -1, device = -1;
1565 unsigned char done = FALSE;
1567 base = p;
1568 tok = base + n + 1; /* Forward us just past the ':' */
1569 tok_end = strchr(tok, '\0');
1570 if (tok_end < end)
1571 *tok_end = ',';
1572 while(!done)
1574 switch(*tok)
1576 case '{':
1577 if (instance == -1)
1578 instance = 0;
1579 else if (device == -1)
1580 device = 0;
1581 tok++;
1582 break;
1583 case '}':
1584 if (device != -1)
1585 device = -1;
1586 else if (instance != -1)
1587 instance = -1;
1588 tok++;
1589 break;
1590 case ',':
1591 case '.':
1592 if (instance == -1)
1593 done = TRUE;
1594 else if (device >= 0)
1595 device++;
1596 else if (instance >= 0)
1597 instance++;
1598 if ( (device >= MAX_TARGETS) ||
1599 (instance >= NUMBER(aic7xxx_tag_info)) )
1600 done = TRUE;
1601 tok++;
1602 if (!done)
1604 base = tok;
1606 break;
1607 case '\0':
1608 done = TRUE;
1609 break;
1610 default:
1611 done = TRUE;
1612 tok_end = strchr(tok, '\0');
1613 for(i=0; tok_list[i]; i++)
1615 tok_end2 = strchr(tok, tok_list[i]);
1616 if ( (tok_end2) && (tok_end2 < tok_end) )
1618 tok_end = tok_end2;
1619 done = FALSE;
1622 if ( (instance >= 0) && (device >= 0) &&
1623 (instance < NUMBER(aic7xxx_tag_info)) &&
1624 (device < MAX_TARGETS) )
1625 aic7xxx_tag_info[instance].tag_commands[device] =
1626 simple_strtoul(tok, NULL, 0) & 0xff;
1627 tok = tok_end;
1628 break;
1631 while((p != base) && (p != NULL))
1632 p = strtok(NULL, ",.");
1635 else if (p[n] == ':')
1637 *(options[i].flag) = simple_strtoul(p + n + 1, NULL, 0);
1638 if(!strncmp(p, "seltime", n))
1640 *(options[i].flag) = (*(options[i].flag) % 4) << 3;
1643 else if (!strncmp(p, "verbose", n))
1645 *(options[i].flag) = 0xff09;
1647 else
1649 *(options[i].flag) = ~(*(options[i].flag));
1650 if(!strncmp(p, "seltime", n))
1652 *(options[i].flag) = (*(options[i].flag) % 4) << 3;
1658 return 1;
1661 __setup("aic7xxx=", aic7xxx_setup);
1663 /*+F*************************************************************************
1664 * Function:
1665 * pause_sequencer
1667 * Description:
1668 * Pause the sequencer and wait for it to actually stop - this
1669 * is important since the sequencer can disable pausing for critical
1670 * sections.
1671 *-F*************************************************************************/
1672 static inline void
1673 pause_sequencer(struct aic7xxx_host *p)
1675 aic_outb(p, p->pause, HCNTRL);
1676 while ((aic_inb(p, HCNTRL) & PAUSE) == 0)
1682 /*+F*************************************************************************
1683 * Function:
1684 * unpause_sequencer
1686 * Description:
1687 * Unpause the sequencer. Unremarkable, yet done often enough to
1688 * warrant an easy way to do it.
1689 *-F*************************************************************************/
1690 static inline void
1691 unpause_sequencer(struct aic7xxx_host *p, int unpause_always)
1693 if (unpause_always ||
1694 ( !(aic_inb(p, INTSTAT) & (SCSIINT | SEQINT | BRKADRINT)) &&
1695 !(p->flags & AHC_HANDLING_REQINITS) ) )
1697 aic_outb(p, p->unpause, HCNTRL);
1701 /*+F*************************************************************************
1702 * Function:
1703 * restart_sequencer
1705 * Description:
1706 * Restart the sequencer program from address zero. This assumes
1707 * that the sequencer is already paused.
1708 *-F*************************************************************************/
1709 static inline void
1710 restart_sequencer(struct aic7xxx_host *p)
1712 aic_outb(p, 0, SEQADDR0);
1713 aic_outb(p, 0, SEQADDR1);
1714 aic_outb(p, FASTMODE, SEQCTL);
1718 * We include the aic7xxx_seq.c file here so that the other defines have
1719 * already been made, and so that it comes before the code that actually
1720 * downloads the instructions (since we don't typically use function
1721 * prototype, our code has to be ordered that way, it's a left-over from
1722 * the original driver days.....I should fix it some time DL).
1724 #include "aic7xxx_seq.c"
1726 /*+F*************************************************************************
1727 * Function:
1728 * aic7xxx_check_patch
1730 * Description:
1731 * See if the next patch to download should be downloaded.
1732 *-F*************************************************************************/
1733 static int
1734 aic7xxx_check_patch(struct aic7xxx_host *p,
1735 struct sequencer_patch **start_patch, int start_instr, int *skip_addr)
1737 struct sequencer_patch *cur_patch;
1738 struct sequencer_patch *last_patch;
1739 int num_patches;
1741 num_patches = sizeof(sequencer_patches)/sizeof(struct sequencer_patch);
1742 last_patch = &sequencer_patches[num_patches];
1743 cur_patch = *start_patch;
1745 while ((cur_patch < last_patch) && (start_instr == cur_patch->begin))
1747 if (cur_patch->patch_func(p) == 0)
1750 * Start rejecting code.
1752 *skip_addr = start_instr + cur_patch->skip_instr;
1753 cur_patch += cur_patch->skip_patch;
1755 else
1758 * Found an OK patch. Advance the patch pointer to the next patch
1759 * and wait for our instruction pointer to get here.
1761 cur_patch++;
1765 *start_patch = cur_patch;
1766 if (start_instr < *skip_addr)
1768 * Still skipping
1770 return (0);
1771 return(1);
1775 /*+F*************************************************************************
1776 * Function:
1777 * aic7xxx_download_instr
1779 * Description:
1780 * Find the next patch to download.
1781 *-F*************************************************************************/
1782 static void
1783 aic7xxx_download_instr(struct aic7xxx_host *p, int instrptr,
1784 unsigned char *dconsts)
1786 union ins_formats instr;
1787 struct ins_format1 *fmt1_ins;
1788 struct ins_format3 *fmt3_ins;
1789 unsigned char opcode;
1790 volatile unsigned char hcntrl;
1792 instr = *(union ins_formats*) &seqprog[instrptr * 4];
1794 instr.integer = le32_to_cpu(instr.integer);
1796 fmt1_ins = &instr.format1;
1797 fmt3_ins = NULL;
1799 /* Pull the opcode */
1800 opcode = instr.format1.opcode;
1801 switch (opcode)
1803 case AIC_OP_JMP:
1804 case AIC_OP_JC:
1805 case AIC_OP_JNC:
1806 case AIC_OP_CALL:
1807 case AIC_OP_JNE:
1808 case AIC_OP_JNZ:
1809 case AIC_OP_JE:
1810 case AIC_OP_JZ:
1812 struct sequencer_patch *cur_patch;
1813 int address_offset;
1814 unsigned int address;
1815 int skip_addr;
1816 int i;
1818 fmt3_ins = &instr.format3;
1819 address_offset = 0;
1820 address = fmt3_ins->address;
1821 cur_patch = sequencer_patches;
1822 skip_addr = 0;
1824 for (i = 0; i < address;)
1826 aic7xxx_check_patch(p, &cur_patch, i, &skip_addr);
1827 if (skip_addr > i)
1829 int end_addr;
1831 end_addr = MIN(address, skip_addr);
1832 address_offset += end_addr - i;
1833 i = skip_addr;
1835 else
1837 i++;
1840 address -= address_offset;
1841 fmt3_ins->address = address;
1842 /* Fall Through to the next code section */
1844 case AIC_OP_OR:
1845 case AIC_OP_AND:
1846 case AIC_OP_XOR:
1847 case AIC_OP_ADD:
1848 case AIC_OP_ADC:
1849 case AIC_OP_BMOV:
1850 if (fmt1_ins->parity != 0)
1852 fmt1_ins->immediate = dconsts[fmt1_ins->immediate];
1854 fmt1_ins->parity = 0;
1855 /* Fall Through to the next code section */
1856 case AIC_OP_ROL:
1857 if ((p->features & AHC_ULTRA2) != 0)
1859 int i, count;
1861 /* Calculate odd parity for the instruction */
1862 for ( i=0, count=0; i < 31; i++)
1864 unsigned int mask;
1866 mask = 0x01 << i;
1867 if ((instr.integer & mask) != 0)
1868 count++;
1870 if (!(count & 0x01))
1871 instr.format1.parity = 1;
1873 else
1875 if (fmt3_ins != NULL)
1877 instr.integer = fmt3_ins->immediate |
1878 (fmt3_ins->source << 8) |
1879 (fmt3_ins->address << 16) |
1880 (fmt3_ins->opcode << 25);
1882 else
1884 instr.integer = fmt1_ins->immediate |
1885 (fmt1_ins->source << 8) |
1886 (fmt1_ins->destination << 16) |
1887 (fmt1_ins->ret << 24) |
1888 (fmt1_ins->opcode << 25);
1891 aic_outb(p, (instr.integer & 0xff), SEQRAM);
1892 hcntrl = aic_inb(p, HCNTRL);
1893 aic_outb(p, ((instr.integer >> 8) & 0xff), SEQRAM);
1894 hcntrl = aic_inb(p, HCNTRL);
1895 aic_outb(p, ((instr.integer >> 16) & 0xff), SEQRAM);
1896 hcntrl = aic_inb(p, HCNTRL);
1897 aic_outb(p, ((instr.integer >> 24) & 0xff), SEQRAM);
1898 hcntrl = aic_inb(p, HCNTRL);
1899 udelay(50);
1900 break;
1902 default:
1903 panic("aic7xxx: Unknown opcode encountered in sequencer program.");
1904 break;
1909 /*+F*************************************************************************
1910 * Function:
1911 * aic7xxx_loadseq
1913 * Description:
1914 * Load the sequencer code into the controller memory.
1915 *-F*************************************************************************/
1916 static void
1917 aic7xxx_loadseq(struct aic7xxx_host *p)
1919 struct sequencer_patch *cur_patch;
1920 int i;
1921 int downloaded;
1922 int skip_addr;
1923 unsigned char download_consts[4] = {0, 0, 0, 0};
1925 if (aic7xxx_verbose & VERBOSE_PROBE)
1927 printk(KERN_INFO "(scsi%d) Downloading sequencer code...", p->host_no);
1929 #if 0
1930 download_consts[TMODE_NUMCMDS] = p->num_targetcmds;
1931 #endif
1932 download_consts[TMODE_NUMCMDS] = 0;
1933 cur_patch = &sequencer_patches[0];
1934 downloaded = 0;
1935 skip_addr = 0;
1937 aic_outb(p, PERRORDIS|LOADRAM|FAILDIS|FASTMODE, SEQCTL);
1938 aic_outb(p, 0, SEQADDR0);
1939 aic_outb(p, 0, SEQADDR1);
1941 for (i = 0; i < sizeof(seqprog) / 4; i++)
1943 if (aic7xxx_check_patch(p, &cur_patch, i, &skip_addr) == 0)
1945 /* Skip this instruction for this configuration. */
1946 continue;
1948 aic7xxx_download_instr(p, i, &download_consts[0]);
1949 downloaded++;
1952 aic_outb(p, 0, SEQADDR0);
1953 aic_outb(p, 0, SEQADDR1);
1954 aic_outb(p, FASTMODE | FAILDIS, SEQCTL);
1955 unpause_sequencer(p, TRUE);
1956 mdelay(1);
1957 pause_sequencer(p);
1958 aic_outb(p, FASTMODE, SEQCTL);
1959 if (aic7xxx_verbose & VERBOSE_PROBE)
1961 printk(" %d instructions downloaded\n", downloaded);
1963 if (aic7xxx_dump_sequencer)
1964 aic7xxx_print_sequencer(p, downloaded);
1967 /*+F*************************************************************************
1968 * Function:
1969 * aic7xxx_print_sequencer
1971 * Description:
1972 * Print the contents of the sequencer memory to the screen.
1973 *-F*************************************************************************/
1974 static void
1975 aic7xxx_print_sequencer(struct aic7xxx_host *p, int downloaded)
1977 int i, k, temp;
1979 aic_outb(p, PERRORDIS|LOADRAM|FAILDIS|FASTMODE, SEQCTL);
1980 aic_outb(p, 0, SEQADDR0);
1981 aic_outb(p, 0, SEQADDR1);
1983 k = 0;
1984 for (i=0; i < downloaded; i++)
1986 if ( k == 0 )
1987 printk("%03x: ", i);
1988 temp = aic_inb(p, SEQRAM);
1989 temp |= (aic_inb(p, SEQRAM) << 8);
1990 temp |= (aic_inb(p, SEQRAM) << 16);
1991 temp |= (aic_inb(p, SEQRAM) << 24);
1992 printk("%08x", temp);
1993 if ( ++k == 8 )
1995 printk("\n");
1996 k = 0;
1998 else
1999 printk(" ");
2001 aic_outb(p, 0, SEQADDR0);
2002 aic_outb(p, 0, SEQADDR1);
2003 aic_outb(p, FASTMODE | FAILDIS, SEQCTL);
2004 unpause_sequencer(p, TRUE);
2005 mdelay(1);
2006 pause_sequencer(p);
2007 aic_outb(p, FASTMODE, SEQCTL);
2008 printk("\n");
2011 /*+F*************************************************************************
2012 * Function:
2013 * aic7xxx_info
2015 * Description:
2016 * Return a string describing the driver.
2017 *-F*************************************************************************/
2018 const char *
2019 aic7xxx_info(struct Scsi_Host *dooh)
2021 static char buffer[256];
2022 char *bp;
2023 struct aic7xxx_host *p;
2025 bp = &buffer[0];
2026 p = (struct aic7xxx_host *)dooh->hostdata;
2027 memset(bp, 0, sizeof(buffer));
2028 strcpy(bp, "Adaptec AHA274x/284x/294x (EISA/VLB/PCI-Fast SCSI) ");
2029 strcat(bp, AIC7XXX_C_VERSION);
2030 strcat(bp, "/");
2031 strcat(bp, AIC7XXX_H_VERSION);
2032 strcat(bp, "\n");
2033 strcat(bp, " <");
2034 strcat(bp, board_names[p->board_name_index]);
2035 strcat(bp, ">");
2037 return(bp);
2040 /*+F*************************************************************************
2041 * Function:
2042 * aic7xxx_find_syncrate
2044 * Description:
2045 * Look up the valid period to SCSIRATE conversion in our table
2046 *-F*************************************************************************/
2047 static struct aic7xxx_syncrate *
2048 aic7xxx_find_syncrate(struct aic7xxx_host *p, unsigned int *period,
2049 unsigned int maxsync, unsigned char *options)
2051 struct aic7xxx_syncrate *syncrate;
2052 int done = FALSE;
2054 switch(*options)
2056 case MSG_EXT_PPR_OPTION_DT_CRC:
2057 case MSG_EXT_PPR_OPTION_DT_UNITS:
2058 if(!(p->features & AHC_ULTRA3))
2060 *options = 0;
2061 maxsync = MAX(maxsync, AHC_SYNCRATE_ULTRA2);
2063 break;
2064 case MSG_EXT_PPR_OPTION_DT_CRC_QUICK:
2065 case MSG_EXT_PPR_OPTION_DT_UNITS_QUICK:
2066 if(!(p->features & AHC_ULTRA3))
2068 *options = 0;
2069 maxsync = MAX(maxsync, AHC_SYNCRATE_ULTRA2);
2071 else
2074 * we don't support the Quick Arbitration variants of dual edge
2075 * clocking. As it turns out, we want to send back the
2076 * same basic option, but without the QA attribute.
2077 * We know that we are responding because we would never set
2078 * these options ourself, we would only respond to them.
2080 switch(*options)
2082 case MSG_EXT_PPR_OPTION_DT_CRC_QUICK:
2083 *options = MSG_EXT_PPR_OPTION_DT_CRC;
2084 break;
2085 case MSG_EXT_PPR_OPTION_DT_UNITS_QUICK:
2086 *options = MSG_EXT_PPR_OPTION_DT_UNITS;
2087 break;
2090 break;
2091 default:
2092 *options = 0;
2093 maxsync = MAX(maxsync, AHC_SYNCRATE_ULTRA2);
2094 break;
2096 syncrate = &aic7xxx_syncrates[maxsync];
2097 while ( (syncrate->rate[0] != NULL) &&
2098 (!(p->features & AHC_ULTRA2) || syncrate->sxfr_ultra2) )
2100 if (*period <= syncrate->period)
2102 switch(*options)
2104 case MSG_EXT_PPR_OPTION_DT_CRC:
2105 case MSG_EXT_PPR_OPTION_DT_UNITS:
2106 if(!(syncrate->sxfr_ultra2 & AHC_SYNCRATE_CRC))
2108 done = TRUE;
2110 * oops, we went too low for the CRC/DualEdge signalling, so
2111 * clear the options byte
2113 *options = 0;
2115 * We'll be sending a reply to this packet to set the options
2116 * properly, so unilaterally set the period as well.
2118 *period = syncrate->period;
2120 else
2122 done = TRUE;
2123 if(syncrate == &aic7xxx_syncrates[maxsync])
2125 *period = syncrate->period;
2128 break;
2129 default:
2130 if(!(syncrate->sxfr_ultra2 & AHC_SYNCRATE_CRC))
2132 done = TRUE;
2133 if(syncrate == &aic7xxx_syncrates[maxsync])
2135 *period = syncrate->period;
2138 break;
2140 if(done)
2142 break;
2145 syncrate++;
2147 if ( (*period == 0) || (syncrate->rate[0] == NULL) ||
2148 ((p->features & AHC_ULTRA2) && (syncrate->sxfr_ultra2 == 0)) )
2151 * Use async transfers for this target
2153 *options = 0;
2154 *period = 0;
2155 syncrate = NULL;
2157 return (syncrate);
2161 /*+F*************************************************************************
2162 * Function:
2163 * aic7xxx_find_period
2165 * Description:
2166 * Look up the valid SCSIRATE to period conversion in our table
2167 *-F*************************************************************************/
2168 static unsigned int
2169 aic7xxx_find_period(struct aic7xxx_host *p, unsigned int scsirate,
2170 unsigned int maxsync)
2172 struct aic7xxx_syncrate *syncrate;
2174 if (p->features & AHC_ULTRA2)
2176 scsirate &= SXFR_ULTRA2;
2178 else
2180 scsirate &= SXFR;
2183 syncrate = &aic7xxx_syncrates[maxsync];
2184 while (syncrate->rate[0] != NULL)
2186 if (p->features & AHC_ULTRA2)
2188 if (syncrate->sxfr_ultra2 == 0)
2189 break;
2190 else if (scsirate == syncrate->sxfr_ultra2)
2191 return (syncrate->period);
2192 else if (scsirate == (syncrate->sxfr_ultra2 & ~AHC_SYNCRATE_CRC))
2193 return (syncrate->period);
2195 else if (scsirate == (syncrate->sxfr & ~ULTRA_SXFR))
2197 return (syncrate->period);
2199 syncrate++;
2201 return (0); /* async */
2204 /*+F*************************************************************************
2205 * Function:
2206 * aic7xxx_validate_offset
2208 * Description:
2209 * Set a valid offset value for a particular card in use and transfer
2210 * settings in use.
2211 *-F*************************************************************************/
2212 static void
2213 aic7xxx_validate_offset(struct aic7xxx_host *p,
2214 struct aic7xxx_syncrate *syncrate, unsigned int *offset, int wide)
2216 unsigned int maxoffset;
2218 /* Limit offset to what the card (and device) can do */
2219 if (syncrate == NULL)
2221 maxoffset = 0;
2223 else if (p->features & AHC_ULTRA2)
2225 maxoffset = MAX_OFFSET_ULTRA2;
2227 else
2229 if (wide)
2230 maxoffset = MAX_OFFSET_16BIT;
2231 else
2232 maxoffset = MAX_OFFSET_8BIT;
2234 *offset = MIN(*offset, maxoffset);
2237 /*+F*************************************************************************
2238 * Function:
2239 * aic7xxx_set_syncrate
2241 * Description:
2242 * Set the actual syncrate down in the card and in our host structs
2243 *-F*************************************************************************/
2244 static void
2245 aic7xxx_set_syncrate(struct aic7xxx_host *p, struct aic7xxx_syncrate *syncrate,
2246 int target, int channel, unsigned int period, unsigned int offset,
2247 unsigned char options, unsigned int type)
2249 unsigned char tindex;
2250 unsigned short target_mask;
2251 unsigned char lun, old_options;
2252 unsigned int old_period, old_offset;
2254 tindex = target | (channel << 3);
2255 target_mask = 0x01 << tindex;
2256 lun = aic_inb(p, SCB_TCL) & 0x07;
2258 if (syncrate == NULL)
2260 period = 0;
2261 offset = 0;
2264 old_period = p->transinfo[tindex].cur_period;
2265 old_offset = p->transinfo[tindex].cur_offset;
2266 old_options = p->transinfo[tindex].cur_options;
2269 if (type & AHC_TRANS_CUR)
2271 unsigned int scsirate;
2273 scsirate = aic_inb(p, TARG_SCSIRATE + tindex);
2274 if (p->features & AHC_ULTRA2)
2276 scsirate &= ~SXFR_ULTRA2;
2277 if (syncrate != NULL)
2279 switch(options)
2281 case MSG_EXT_PPR_OPTION_DT_UNITS:
2283 * mask off the CRC bit in the xfer settings
2285 scsirate |= (syncrate->sxfr_ultra2 & ~AHC_SYNCRATE_CRC);
2286 break;
2287 default:
2288 scsirate |= syncrate->sxfr_ultra2;
2289 break;
2292 if (type & AHC_TRANS_ACTIVE)
2294 aic_outb(p, offset, SCSIOFFSET);
2296 aic_outb(p, offset, TARG_OFFSET + tindex);
2298 else /* Not an Ultra2 controller */
2300 scsirate &= ~(SXFR|SOFS);
2301 p->ultraenb &= ~target_mask;
2302 if (syncrate != NULL)
2304 if (syncrate->sxfr & ULTRA_SXFR)
2306 p->ultraenb |= target_mask;
2308 scsirate |= (syncrate->sxfr & SXFR);
2309 scsirate |= (offset & SOFS);
2311 if (type & AHC_TRANS_ACTIVE)
2313 unsigned char sxfrctl0;
2315 sxfrctl0 = aic_inb(p, SXFRCTL0);
2316 sxfrctl0 &= ~FAST20;
2317 if (p->ultraenb & target_mask)
2318 sxfrctl0 |= FAST20;
2319 aic_outb(p, sxfrctl0, SXFRCTL0);
2321 aic_outb(p, p->ultraenb & 0xff, ULTRA_ENB);
2322 aic_outb(p, (p->ultraenb >> 8) & 0xff, ULTRA_ENB + 1 );
2324 if (type & AHC_TRANS_ACTIVE)
2326 aic_outb(p, scsirate, SCSIRATE);
2328 aic_outb(p, scsirate, TARG_SCSIRATE + tindex);
2329 p->transinfo[tindex].cur_period = period;
2330 p->transinfo[tindex].cur_offset = offset;
2331 p->transinfo[tindex].cur_options = options;
2332 if ( !(type & AHC_TRANS_QUITE) &&
2333 (aic7xxx_verbose & VERBOSE_NEGOTIATION) &&
2334 (p->dev_flags[tindex] & DEVICE_PRINT_DTR) )
2336 if (offset)
2338 int rate_mod = (scsirate & WIDEXFER) ? 1 : 0;
2340 printk(INFO_LEAD "Synchronous at %s Mbyte/sec, "
2341 "offset %d.\n", p->host_no, channel, target, lun,
2342 syncrate->rate[rate_mod], offset);
2344 else
2346 printk(INFO_LEAD "Using asynchronous transfers.\n",
2347 p->host_no, channel, target, lun);
2349 p->dev_flags[tindex] &= ~DEVICE_PRINT_DTR;
2353 if (type & AHC_TRANS_GOAL)
2355 p->transinfo[tindex].goal_period = period;
2356 p->transinfo[tindex].goal_offset = offset;
2357 p->transinfo[tindex].goal_options = options;
2360 if (type & AHC_TRANS_USER)
2362 p->transinfo[tindex].user_period = period;
2363 p->transinfo[tindex].user_offset = offset;
2364 p->transinfo[tindex].user_options = options;
2368 /*+F*************************************************************************
2369 * Function:
2370 * aic7xxx_set_width
2372 * Description:
2373 * Set the actual width down in the card and in our host structs
2374 *-F*************************************************************************/
2375 static void
2376 aic7xxx_set_width(struct aic7xxx_host *p, int target, int channel, int lun,
2377 unsigned int width, unsigned int type)
2379 unsigned char tindex;
2380 unsigned short target_mask;
2381 unsigned int old_width;
2383 tindex = target | (channel << 3);
2384 target_mask = 1 << tindex;
2386 old_width = p->transinfo[tindex].cur_width;
2388 if (type & AHC_TRANS_CUR)
2390 unsigned char scsirate;
2392 scsirate = aic_inb(p, TARG_SCSIRATE + tindex);
2394 scsirate &= ~WIDEXFER;
2395 if (width == MSG_EXT_WDTR_BUS_16_BIT)
2396 scsirate |= WIDEXFER;
2398 aic_outb(p, scsirate, TARG_SCSIRATE + tindex);
2400 if (type & AHC_TRANS_ACTIVE)
2401 aic_outb(p, scsirate, SCSIRATE);
2403 p->transinfo[tindex].cur_width = width;
2405 if ( !(type & AHC_TRANS_QUITE) &&
2406 (aic7xxx_verbose & VERBOSE_NEGOTIATION2) &&
2407 (p->dev_flags[tindex] & DEVICE_PRINT_DTR) )
2409 printk(INFO_LEAD "Using %s transfers\n", p->host_no, channel, target,
2410 lun, (scsirate & WIDEXFER) ? "Wide(16bit)" : "Narrow(8bit)" );
2414 if (type & AHC_TRANS_GOAL)
2415 p->transinfo[tindex].goal_width = width;
2416 if (type & AHC_TRANS_USER)
2417 p->transinfo[tindex].user_width = width;
2419 if (p->transinfo[tindex].goal_offset)
2421 if (p->features & AHC_ULTRA2)
2423 p->transinfo[tindex].goal_offset = MAX_OFFSET_ULTRA2;
2425 else if (width == MSG_EXT_WDTR_BUS_16_BIT)
2427 p->transinfo[tindex].goal_offset = MAX_OFFSET_16BIT;
2429 else
2431 p->transinfo[tindex].goal_offset = MAX_OFFSET_8BIT;
2436 /*+F*************************************************************************
2437 * Function:
2438 * scbq_init
2440 * Description:
2441 * SCB queue initialization.
2443 *-F*************************************************************************/
2444 static void
2445 scbq_init(volatile scb_queue_type *queue)
2447 queue->head = NULL;
2448 queue->tail = NULL;
2451 /*+F*************************************************************************
2452 * Function:
2453 * scbq_insert_head
2455 * Description:
2456 * Add an SCB to the head of the list.
2458 *-F*************************************************************************/
2459 static inline void
2460 scbq_insert_head(volatile scb_queue_type *queue, struct aic7xxx_scb *scb)
2462 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,1,95)
2463 unsigned long cpu_flags;
2464 #endif
2466 DRIVER_LOCK
2467 scb->q_next = queue->head;
2468 queue->head = scb;
2469 if (queue->tail == NULL) /* If list was empty, update tail. */
2470 queue->tail = queue->head;
2471 DRIVER_UNLOCK
2474 /*+F*************************************************************************
2475 * Function:
2476 * scbq_remove_head
2478 * Description:
2479 * Remove an SCB from the head of the list.
2481 *-F*************************************************************************/
2482 static inline struct aic7xxx_scb *
2483 scbq_remove_head(volatile scb_queue_type *queue)
2485 struct aic7xxx_scb * scbp;
2486 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,1,95)
2487 unsigned long cpu_flags;
2488 #endif
2490 DRIVER_LOCK
2491 scbp = queue->head;
2492 if (queue->head != NULL)
2493 queue->head = queue->head->q_next;
2494 if (queue->head == NULL) /* If list is now empty, update tail. */
2495 queue->tail = NULL;
2496 DRIVER_UNLOCK
2497 return(scbp);
2500 /*+F*************************************************************************
2501 * Function:
2502 * scbq_remove
2504 * Description:
2505 * Removes an SCB from the list.
2507 *-F*************************************************************************/
2508 static inline void
2509 scbq_remove(volatile scb_queue_type *queue, struct aic7xxx_scb *scb)
2511 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,1,95)
2512 unsigned long cpu_flags;
2513 #endif
2515 DRIVER_LOCK
2516 if (queue->head == scb)
2518 /* At beginning of queue, remove from head. */
2519 scbq_remove_head(queue);
2521 else
2523 struct aic7xxx_scb *curscb = queue->head;
2526 * Search until the next scb is the one we're looking for, or
2527 * we run out of queue.
2529 while ((curscb != NULL) && (curscb->q_next != scb))
2531 curscb = curscb->q_next;
2533 if (curscb != NULL)
2535 /* Found it. */
2536 curscb->q_next = scb->q_next;
2537 if (scb->q_next == NULL)
2539 /* Update the tail when removing the tail. */
2540 queue->tail = curscb;
2544 DRIVER_UNLOCK
2547 /*+F*************************************************************************
2548 * Function:
2549 * scbq_insert_tail
2551 * Description:
2552 * Add an SCB at the tail of the list.
2554 *-F*************************************************************************/
2555 static inline void
2556 scbq_insert_tail(volatile scb_queue_type *queue, struct aic7xxx_scb *scb)
2558 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,1,95)
2559 unsigned long cpu_flags;
2560 #endif
2562 DRIVER_LOCK
2563 scb->q_next = NULL;
2564 if (queue->tail != NULL) /* Add the scb at the end of the list. */
2565 queue->tail->q_next = scb;
2566 queue->tail = scb; /* Update the tail. */
2567 if (queue->head == NULL) /* If list was empty, update head. */
2568 queue->head = queue->tail;
2569 DRIVER_UNLOCK
2572 /*+F*************************************************************************
2573 * Function:
2574 * aic7xxx_match_scb
2576 * Description:
2577 * Checks to see if an scb matches the target/channel as specified.
2578 * If target is ALL_TARGETS (-1), then we're looking for any device
2579 * on the specified channel; this happens when a channel is going
2580 * to be reset and all devices on that channel must be aborted.
2581 *-F*************************************************************************/
2582 static int
2583 aic7xxx_match_scb(struct aic7xxx_host *p, struct aic7xxx_scb *scb,
2584 int target, int channel, int lun, unsigned char tag)
2586 int targ = (scb->hscb->target_channel_lun >> 4) & 0x0F;
2587 int chan = (scb->hscb->target_channel_lun >> 3) & 0x01;
2588 int slun = scb->hscb->target_channel_lun & 0x07;
2589 int match;
2591 match = ((chan == channel) || (channel == ALL_CHANNELS));
2592 if (match != 0)
2593 match = ((targ == target) || (target == ALL_TARGETS));
2594 if (match != 0)
2595 match = ((lun == slun) || (lun == ALL_LUNS));
2596 if (match != 0)
2597 match = ((tag == scb->hscb->tag) || (tag == SCB_LIST_NULL));
2599 return (match);
2602 /*+F*************************************************************************
2603 * Function:
2604 * aic7xxx_add_curscb_to_free_list
2606 * Description:
2607 * Adds the current scb (in SCBPTR) to the list of free SCBs.
2608 *-F*************************************************************************/
2609 static void
2610 aic7xxx_add_curscb_to_free_list(struct aic7xxx_host *p)
2613 * Invalidate the tag so that aic7xxx_find_scb doesn't think
2614 * it's active
2616 aic_outb(p, SCB_LIST_NULL, SCB_TAG);
2617 aic_outb(p, 0, SCB_CONTROL);
2619 aic_outb(p, aic_inb(p, FREE_SCBH), SCB_NEXT);
2620 aic_outb(p, aic_inb(p, SCBPTR), FREE_SCBH);
2623 /*+F*************************************************************************
2624 * Function:
2625 * aic7xxx_rem_scb_from_disc_list
2627 * Description:
2628 * Removes the current SCB from the disconnected list and adds it
2629 * to the free list.
2630 *-F*************************************************************************/
2631 static unsigned char
2632 aic7xxx_rem_scb_from_disc_list(struct aic7xxx_host *p, unsigned char scbptr,
2633 unsigned char prev)
2635 unsigned char next;
2637 aic_outb(p, scbptr, SCBPTR);
2638 next = aic_inb(p, SCB_NEXT);
2639 aic7xxx_add_curscb_to_free_list(p);
2641 if (prev != SCB_LIST_NULL)
2643 aic_outb(p, prev, SCBPTR);
2644 aic_outb(p, next, SCB_NEXT);
2646 else
2648 aic_outb(p, next, DISCONNECTED_SCBH);
2651 return next;
2654 /*+F*************************************************************************
2655 * Function:
2656 * aic7xxx_busy_target
2658 * Description:
2659 * Set the specified target busy.
2660 *-F*************************************************************************/
2661 static inline void
2662 aic7xxx_busy_target(struct aic7xxx_host *p, struct aic7xxx_scb *scb)
2664 p->untagged_scbs[scb->hscb->target_channel_lun] = scb->hscb->tag;
2667 /*+F*************************************************************************
2668 * Function:
2669 * aic7xxx_index_busy_target
2671 * Description:
2672 * Returns the index of the busy target, and optionally sets the
2673 * target inactive.
2674 *-F*************************************************************************/
2675 static inline unsigned char
2676 aic7xxx_index_busy_target(struct aic7xxx_host *p, unsigned char tcl,
2677 int unbusy)
2679 unsigned char busy_scbid;
2681 busy_scbid = p->untagged_scbs[tcl];
2682 if (unbusy)
2684 p->untagged_scbs[tcl] = SCB_LIST_NULL;
2686 return (busy_scbid);
2689 /*+F*************************************************************************
2690 * Function:
2691 * aic7xxx_find_scb
2693 * Description:
2694 * Look through the SCB array of the card and attempt to find the
2695 * hardware SCB that corresponds to the passed in SCB. Return
2696 * SCB_LIST_NULL if unsuccessful. This routine assumes that the
2697 * card is already paused.
2698 *-F*************************************************************************/
2699 static unsigned char
2700 aic7xxx_find_scb(struct aic7xxx_host *p, struct aic7xxx_scb *scb)
2702 unsigned char saved_scbptr;
2703 unsigned char curindex;
2705 saved_scbptr = aic_inb(p, SCBPTR);
2706 curindex = 0;
2707 for (curindex = 0; curindex < p->scb_data->maxhscbs; curindex++)
2709 aic_outb(p, curindex, SCBPTR);
2710 if (aic_inb(p, SCB_TAG) == scb->hscb->tag)
2712 break;
2715 aic_outb(p, saved_scbptr, SCBPTR);
2716 if (curindex >= p->scb_data->maxhscbs)
2718 curindex = SCB_LIST_NULL;
2721 return (curindex);
2724 /*+F*************************************************************************
2725 * Function:
2726 * aic7xxx_allocate_scb
2728 * Description:
2729 * Get an SCB from the free list or by allocating a new one.
2730 *-F*************************************************************************/
2731 static int
2732 aic7xxx_allocate_scb(struct aic7xxx_host *p)
2734 struct aic7xxx_scb *scbp = NULL;
2735 int scb_size = (sizeof (struct hw_scatterlist) * AIC7XXX_MAX_SG) + 12 + 6;
2736 int i;
2737 int step = PAGE_SIZE / 1024;
2738 unsigned long scb_count = 0;
2739 struct hw_scatterlist *hsgp;
2740 struct aic7xxx_scb *scb_ap;
2741 struct aic7xxx_scb_dma *scb_dma;
2742 unsigned char *bufs;
2744 if (p->scb_data->numscbs < p->scb_data->maxscbs)
2747 * Calculate the optimal number of SCBs to allocate.
2749 * NOTE: This formula works because the sizeof(sg_array) is always
2750 * 1024. Therefore, scb_size * i would always be > PAGE_SIZE *
2751 * (i/step). The (i-1) allows the left hand side of the equation
2752 * to grow into the right hand side to a point of near perfect
2753 * efficiency since scb_size * (i -1) is growing slightly faster
2754 * than the right hand side. If the number of SG array elements
2755 * is changed, this function may not be near so efficient any more.
2757 * Since the DMA'able buffers are now allocated in a seperate
2758 * chunk this algorithm has been modified to match. The '12'
2759 * and '6' factors in scb_size are for the DMA'able command byte
2760 * and sensebuffers respectively. -DaveM
2762 for ( i=step;; i *= 2 )
2764 if ( (scb_size * (i-1)) >= ( (PAGE_SIZE * (i/step)) - 64 ) )
2766 i /= 2;
2767 break;
2770 scb_count = MIN( (i-1), p->scb_data->maxscbs - p->scb_data->numscbs);
2771 scb_ap = (struct aic7xxx_scb *)kmalloc(sizeof (struct aic7xxx_scb) * scb_count
2772 + sizeof(struct aic7xxx_scb_dma), GFP_ATOMIC);
2773 if (scb_ap == NULL)
2774 return(0);
2775 scb_dma = (struct aic7xxx_scb_dma *)&scb_ap[scb_count];
2776 hsgp = (struct hw_scatterlist *)
2777 pci_alloc_consistent(p->pdev, scb_size * scb_count,
2778 &scb_dma->dma_address);
2779 if (hsgp == NULL)
2781 kfree(scb_ap);
2782 return(0);
2784 bufs = (unsigned char *)&hsgp[scb_count * AIC7XXX_MAX_SG];
2785 #ifdef AIC7XXX_VERBOSE_DEBUGGING
2786 if (aic7xxx_verbose > 0xffff)
2788 if (p->scb_data->numscbs == 0)
2789 printk(INFO_LEAD "Allocating initial %ld SCB structures.\n",
2790 p->host_no, -1, -1, -1, scb_count);
2791 else
2792 printk(INFO_LEAD "Allocating %ld additional SCB structures.\n",
2793 p->host_no, -1, -1, -1, scb_count);
2795 #endif
2796 memset(scb_ap, 0, sizeof (struct aic7xxx_scb) * scb_count);
2797 scb_dma->dma_offset = (unsigned long)scb_dma->dma_address
2798 - (unsigned long)hsgp;
2799 scb_dma->dma_len = scb_size * scb_count;
2800 for (i=0; i < scb_count; i++)
2802 scbp = &scb_ap[i];
2803 scbp->hscb = &p->scb_data->hscbs[p->scb_data->numscbs];
2804 scbp->sg_list = &hsgp[i * AIC7XXX_MAX_SG];
2805 scbp->sense_cmd = bufs;
2806 scbp->cmnd = bufs + 6;
2807 bufs += 12 + 6;
2808 scbp->scb_dma = scb_dma;
2809 memset(scbp->hscb, 0, sizeof(struct aic7xxx_hwscb));
2810 scbp->hscb->tag = p->scb_data->numscbs;
2812 * Place in the scb array; never is removed
2814 p->scb_data->scb_array[p->scb_data->numscbs++] = scbp;
2815 scbq_insert_tail(&p->scb_data->free_scbs, scbp);
2817 scbp->kmalloc_ptr = scb_ap;
2819 return(scb_count);
2822 /*+F*************************************************************************
2823 * Function:
2824 * aic7xxx_queue_cmd_complete
2826 * Description:
2827 * Due to race conditions present in the SCSI subsystem, it is easier
2828 * to queue completed commands, then call scsi_done() on them when
2829 * we're finished. This function queues the completed commands.
2830 *-F*************************************************************************/
2831 static void
2832 aic7xxx_queue_cmd_complete(struct aic7xxx_host *p, Scsi_Cmnd *cmd)
2834 cmd->host_scribble = (char *)p->completeq.head;
2835 p->completeq.head = cmd;
2838 /*+F*************************************************************************
2839 * Function:
2840 * aic7xxx_done_cmds_complete
2842 * Description:
2843 * Process the completed command queue.
2844 *-F*************************************************************************/
2845 static void
2846 aic7xxx_done_cmds_complete(struct aic7xxx_host *p)
2848 Scsi_Cmnd *cmd;
2849 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,1,95)
2850 unsigned int cpu_flags = 0;
2851 #endif
2853 DRIVER_LOCK
2854 while (p->completeq.head != NULL)
2856 cmd = p->completeq.head;
2857 p->completeq.head = (Scsi_Cmnd *)cmd->host_scribble;
2858 cmd->host_scribble = NULL;
2859 cmd->scsi_done(cmd);
2861 DRIVER_UNLOCK
2864 /*+F*************************************************************************
2865 * Function:
2866 * aic7xxx_free_scb
2868 * Description:
2869 * Free the scb and insert into the free scb list.
2870 *-F*************************************************************************/
2871 static void
2872 aic7xxx_free_scb(struct aic7xxx_host *p, struct aic7xxx_scb *scb)
2875 scb->flags = SCB_FREE;
2876 scb->cmd = NULL;
2877 scb->sg_count = 0;
2878 scb->sg_length = 0;
2879 scb->tag_action = 0;
2880 scb->hscb->control = 0;
2881 scb->hscb->target_status = 0;
2882 scb->hscb->target_channel_lun = SCB_LIST_NULL;
2884 scbq_insert_head(&p->scb_data->free_scbs, scb);
2887 /*+F*************************************************************************
2888 * Function:
2889 * aic7xxx_done
2891 * Description:
2892 * Calls the higher level scsi done function and frees the scb.
2893 *-F*************************************************************************/
2894 static void
2895 aic7xxx_done(struct aic7xxx_host *p, struct aic7xxx_scb *scb)
2897 Scsi_Cmnd *cmd = scb->cmd;
2898 int tindex = TARGET_INDEX(cmd);
2899 struct aic7xxx_scb *scbp;
2900 unsigned char queue_depth;
2902 if (cmd->use_sg > 1)
2904 struct scatterlist *sg;
2906 sg = (struct scatterlist *)cmd->request_buffer;
2907 pci_unmap_sg(p->pdev, sg, cmd->use_sg, scsi_to_pci_dma_dir(cmd->sc_data_direction));
2909 else if (cmd->request_bufflen)
2910 pci_unmap_single(p->pdev, aic7xxx_mapping(cmd),
2911 cmd->request_bufflen,
2912 scsi_to_pci_dma_dir(cmd->sc_data_direction));
2913 if (scb->flags & SCB_SENSE)
2915 pci_unmap_single(p->pdev,
2916 le32_to_cpu(scb->sg_list[0].address),
2917 sizeof(cmd->sense_buffer),
2918 PCI_DMA_FROMDEVICE);
2920 if (scb->flags & SCB_RECOVERY_SCB)
2922 p->flags &= ~AHC_ABORT_PENDING;
2924 if (scb->flags & SCB_RESET)
2926 cmd->result = (DID_RESET << 16) | (cmd->result & 0xffff);
2928 else if (scb->flags & SCB_ABORT)
2930 cmd->result = (DID_RESET << 16) | (cmd->result & 0xffff);
2932 else if (!(p->dev_flags[tindex] & DEVICE_SCANNED))
2934 if ( (cmd->cmnd[0] == INQUIRY) && (cmd->result == DID_OK) )
2936 char *buffer;
2938 p->dev_flags[tindex] |= DEVICE_PRESENT;
2939 if(cmd->use_sg)
2941 struct scatterlist *sg;
2943 sg = (struct scatterlist *)cmd->request_buffer;
2944 buffer = (char *)sg[0].address;
2946 else
2948 buffer = (char *)cmd->request_buffer;
2950 #define WIDE_INQUIRY_BITS 0x60
2951 #define SYNC_INQUIRY_BITS 0x10
2952 #define SCSI_VERSION_BITS 0x07
2953 if ( (buffer[7] & WIDE_INQUIRY_BITS) &&
2954 (p->features & AHC_WIDE) )
2956 p->needwdtr |= (1<<tindex);
2957 p->needwdtr_copy |= (1<<tindex);
2958 p->transinfo[tindex].goal_width = p->transinfo[tindex].user_width;
2960 else
2962 p->needwdtr &= ~(1<<tindex);
2963 p->needwdtr_copy &= ~(1<<tindex);
2964 pause_sequencer(p);
2965 aic7xxx_set_width(p, cmd->target, cmd->channel, cmd->lun,
2966 MSG_EXT_WDTR_BUS_8_BIT, (AHC_TRANS_ACTIVE |
2967 AHC_TRANS_GOAL |
2968 AHC_TRANS_CUR) );
2969 unpause_sequencer(p, FALSE);
2971 if (buffer[7] & SYNC_INQUIRY_BITS)
2973 p->needsdtr |= (1<<tindex);
2974 p->needsdtr_copy |= (1<<tindex);
2976 p->transinfo[tindex].goal_period = p->transinfo[tindex].user_period;
2977 p->transinfo[tindex].goal_options = p->transinfo[tindex].user_options;
2978 if (p->transinfo[tindex].user_offset)
2980 if (p->features & AHC_ULTRA2)
2981 p->transinfo[tindex].goal_offset = MAX_OFFSET_ULTRA2;
2982 else if (p->transinfo[tindex].goal_width == MSG_EXT_WDTR_BUS_16_BIT)
2983 p->transinfo[tindex].goal_offset = MAX_OFFSET_16BIT;
2984 else
2985 p->transinfo[tindex].goal_offset = MAX_OFFSET_8BIT;
2988 else
2990 p->needsdtr &= ~(1<<tindex);
2991 p->needsdtr_copy &= ~(1<<tindex);
2992 p->transinfo[tindex].goal_period = 0;
2993 p->transinfo[tindex].goal_offset = 0;
2994 p->transinfo[tindex].goal_options = 0;
2996 if ( (buffer[2] & SCSI_VERSION_BITS) == 3 )
2998 p->dev_flags[tindex] |= DEVICE_SCSI_3;
3000 * OK, we are a SCSI 3 device and we are in need of negotiation.
3001 * Use PPR messages instead of WDTR and SDTR messages.
3003 if ( (p->needsdtr & (1<<tindex)) ||
3004 (p->needwdtr & (1<<tindex)) )
3006 p->needppr |= (1<<tindex);
3007 p->needppr_copy |= (1<<tindex);
3009 p->needwdtr &= ~(1<<tindex);
3010 p->needwdtr_copy &= ~(1<<tindex);
3011 p->needsdtr &= ~(1<<tindex);
3012 p->needsdtr_copy &= ~(1<<tindex);
3015 * Get the INQUIRY checksum. We use this on Ultra 160/m
3016 * and older devices both. It allows us to drop speed on any bus type
3017 * while at the same time giving us the needed domain validation for
3018 * Ultra 160/m
3020 * Note: We only get the checksum and set the SCANNED bit if this is
3021 * one of our dtr commands. If we don't do this, then we end up
3022 * getting bad checksum results on the mid-level SCSI code's INQUIRY
3023 * commands.
3025 if(p->dev_dtr_cmnd[tindex] == cmd) {
3026 unsigned int checksum = 0;
3027 int *ibuffer;
3028 int i=0;
3030 ibuffer = (int *)buffer;
3031 for( i = 0; i < (cmd->request_bufflen >> 2); i++)
3033 checksum += ibuffer[i];
3035 p->dev_checksum[tindex] = checksum;
3036 p->dev_flags[tindex] |= DEVICE_SCANNED;
3037 p->dev_flags[tindex] |= DEVICE_PRINT_DTR;
3039 #undef WIDE_INQUIRY_BITS
3040 #undef SYNC_INQUIRY_BITS
3041 #undef SCSI_VERSION_BITS
3044 else if ((scb->flags & SCB_MSGOUT_BITS) != 0)
3046 unsigned short mask;
3047 int message_error = FALSE;
3049 mask = 0x01 << tindex;
3052 * Check to see if we get an invalid message or a message error
3053 * after failing to negotiate a wide or sync transfer message.
3055 if ((scb->flags & SCB_SENSE) &&
3056 ((scb->cmd->sense_buffer[12] == 0x43) || /* INVALID_MESSAGE */
3057 (scb->cmd->sense_buffer[12] == 0x49))) /* MESSAGE_ERROR */
3059 message_error = TRUE;
3062 if (scb->flags & SCB_MSGOUT_WDTR)
3064 p->dtr_pending &= ~mask;
3065 if (message_error)
3067 if ( (aic7xxx_verbose & VERBOSE_NEGOTIATION2) &&
3068 (p->dev_flags[tindex] & DEVICE_PRINT_DTR) )
3070 printk(INFO_LEAD "Device failed to complete Wide Negotiation "
3071 "processing and\n", p->host_no, CTL_OF_SCB(scb));
3072 printk(INFO_LEAD "returned a sense error code for invalid message, "
3073 "disabling future\n", p->host_no, CTL_OF_SCB(scb));
3074 printk(INFO_LEAD "Wide negotiation to this device.\n", p->host_no,
3075 CTL_OF_SCB(scb));
3077 p->needwdtr &= ~mask;
3078 p->needwdtr_copy &= ~mask;
3081 if (scb->flags & SCB_MSGOUT_SDTR)
3083 p->dtr_pending &= ~mask;
3084 if (message_error)
3086 if ( (aic7xxx_verbose & VERBOSE_NEGOTIATION2) &&
3087 (p->dev_flags[tindex] & DEVICE_PRINT_DTR) )
3089 printk(INFO_LEAD "Device failed to complete Sync Negotiation "
3090 "processing and\n", p->host_no, CTL_OF_SCB(scb));
3091 printk(INFO_LEAD "returned a sense error code for invalid message, "
3092 "disabling future\n", p->host_no, CTL_OF_SCB(scb));
3093 printk(INFO_LEAD "Sync negotiation to this device.\n", p->host_no,
3094 CTL_OF_SCB(scb));
3095 p->dev_flags[tindex] &= ~DEVICE_PRINT_DTR;
3097 p->needsdtr &= ~mask;
3098 p->needsdtr_copy &= ~mask;
3101 if (scb->flags & SCB_MSGOUT_PPR)
3103 p->dtr_pending &= ~mask;
3104 if(message_error)
3106 if ( (aic7xxx_verbose & VERBOSE_NEGOTIATION2) &&
3107 (p->dev_flags[tindex] & DEVICE_PRINT_DTR) )
3109 printk(INFO_LEAD "Device failed to complete Parallel Protocol "
3110 "Request processing and\n", p->host_no, CTL_OF_SCB(scb));
3111 printk(INFO_LEAD "returned a sense error code for invalid message, "
3112 "disabling future\n", p->host_no, CTL_OF_SCB(scb));
3113 printk(INFO_LEAD "Parallel Protocol Request negotiation to this "
3114 "device.\n", p->host_no, CTL_OF_SCB(scb));
3117 * Disable PPR negotiation and revert back to WDTR and SDTR setup
3119 p->needppr &= ~mask;
3120 p->needppr_copy &= ~mask;
3121 p->needsdtr |= mask;
3122 p->needsdtr_copy |= mask;
3123 p->needwdtr |= mask;
3124 p->needwdtr_copy |= mask;
3128 queue_depth = p->dev_temp_queue_depth[tindex];
3129 if (queue_depth >= p->dev_active_cmds[tindex])
3131 scbp = scbq_remove_head(&p->delayed_scbs[tindex]);
3132 if (scbp)
3134 if (queue_depth == 1)
3137 * Give extra preference to untagged devices, such as CD-R devices
3138 * This makes it more likely that a drive *won't* stuff up while
3139 * waiting on data at a critical time, such as CD-R writing and
3140 * audio CD ripping operations. Should also benefit tape drives.
3142 scbq_insert_head(&p->waiting_scbs, scbp);
3144 else
3146 scbq_insert_tail(&p->waiting_scbs, scbp);
3148 #ifdef AIC7XXX_VERBOSE_DEBUGGING
3149 if (aic7xxx_verbose > 0xffff)
3150 printk(INFO_LEAD "Moving SCB from delayed to waiting queue.\n",
3151 p->host_no, CTL_OF_SCB(scbp));
3152 #endif
3153 if (queue_depth > p->dev_active_cmds[tindex])
3155 scbp = scbq_remove_head(&p->delayed_scbs[tindex]);
3156 if (scbp)
3157 scbq_insert_tail(&p->waiting_scbs, scbp);
3161 if ( !(scb->tag_action) && (p->tagenable & (1<<tindex)) )
3163 p->dev_temp_queue_depth[tindex] = p->dev_max_queue_depth[tindex];
3165 p->dev_active_cmds[tindex]--;
3166 p->activescbs--;
3169 int actual;
3172 * XXX: we should actually know how much actually transferred
3173 * XXX: for each command, but apparently that's too difficult.
3175 * We set a lower limit of 512 bytes on the transfer length. We
3176 * ignore anything less than this because we don't have a real
3177 * reason to count it. Read/Writes to tapes are usually about 20K
3178 * and disks are a minimum of 512 bytes unless you want to count
3179 * non-read/write commands (such as TEST_UNIT_READY) which we don't
3181 actual = scb->sg_length;
3182 if ((actual >= 512) && (((cmd->result >> 16) & 0xf) == DID_OK))
3184 struct aic7xxx_xferstats *sp;
3185 #ifdef AIC7XXX_PROC_STATS
3186 long *ptr;
3187 int x;
3188 #endif /* AIC7XXX_PROC_STATS */
3190 sp = &p->stats[TARGET_INDEX(cmd)];
3193 * For block devices, cmd->request.cmd is always == either READ or
3194 * WRITE. For character devices, this isn't always set properly, so
3195 * we check data_cmnd[0]. This catches the conditions for st.c, but
3196 * I'm still not sure if request.cmd is valid for sg devices.
3198 if ( (cmd->request.cmd == WRITE) || (cmd->data_cmnd[0] == WRITE_6) ||
3199 (cmd->data_cmnd[0] == WRITE_FILEMARKS) )
3201 sp->w_total++;
3202 #ifdef AIC7XXX_VERBOSE_DEBUGGING
3203 if ( (sp->w_total > 16) && (aic7xxx_verbose > 0xffff) )
3204 aic7xxx_verbose &= 0xffff;
3205 #endif
3206 #ifdef AIC7XXX_PROC_STATS
3207 ptr = sp->w_bins;
3208 #endif /* AIC7XXX_PROC_STATS */
3210 else
3212 sp->r_total++;
3213 #ifdef AIC7XXX_VERBOSE_DEBUGGING
3214 if ( (sp->r_total > 16) && (aic7xxx_verbose > 0xffff) )
3215 aic7xxx_verbose &= 0xffff;
3216 #endif
3217 #ifdef AIC7XXX_PROC_STATS
3218 ptr = sp->r_bins;
3219 #endif /* AIC7XXX_PROC_STATS */
3221 #ifdef AIC7XXX_PROC_STATS
3222 x = -11;
3223 while(actual)
3225 actual >>= 1;
3226 x++;
3228 if (x < 0)
3230 ptr[0]++;
3232 else if (x > 7)
3234 ptr[7]++;
3236 else
3238 ptr[x]++;
3240 #endif /* AIC7XXX_PROC_STATS */
3243 aic7xxx_free_scb(p, scb);
3244 aic7xxx_queue_cmd_complete(p, cmd);
3248 /*+F*************************************************************************
3249 * Function:
3250 * aic7xxx_run_done_queue
3252 * Description:
3253 * Calls the aic7xxx_done() for the Scsi_Cmnd of each scb in the
3254 * aborted list, and adds each scb to the free list. If complete
3255 * is TRUE, we also process the commands complete list.
3256 *-F*************************************************************************/
3257 static void
3258 aic7xxx_run_done_queue(struct aic7xxx_host *p, /*complete*/ int complete)
3260 struct aic7xxx_scb *scb;
3261 int i, found = 0;
3263 for (i = 0; i < p->scb_data->numscbs; i++)
3265 scb = p->scb_data->scb_array[i];
3266 if (scb->flags & SCB_QUEUED_FOR_DONE)
3268 if (aic7xxx_verbose & (VERBOSE_ABORT_PROCESS | VERBOSE_RESET_PROCESS))
3269 printk(INFO_LEAD "Aborting scb %d\n",
3270 p->host_no, CTL_OF_SCB(scb), scb->hscb->tag);
3271 found++;
3272 aic7xxx_done(p, scb);
3275 if (aic7xxx_verbose & (VERBOSE_ABORT_RETURN | VERBOSE_RESET_RETURN))
3277 printk(INFO_LEAD "%d commands found and queued for "
3278 "completion.\n", p->host_no, -1, -1, -1, found);
3280 if (complete)
3282 aic7xxx_done_cmds_complete(p);
3286 /*+F*************************************************************************
3287 * Function:
3288 * aic7xxx_abort_waiting_scb
3290 * Description:
3291 * Manipulate the waiting for selection list and return the
3292 * scb that follows the one that we remove.
3293 *-F*************************************************************************/
3294 static unsigned char
3295 aic7xxx_abort_waiting_scb(struct aic7xxx_host *p, struct aic7xxx_scb *scb,
3296 unsigned char scbpos, unsigned char prev)
3298 unsigned char curscb, next;
3301 * Select the SCB we want to abort and pull the next pointer out of it.
3303 curscb = aic_inb(p, SCBPTR);
3304 aic_outb(p, scbpos, SCBPTR);
3305 next = aic_inb(p, SCB_NEXT);
3307 aic7xxx_add_curscb_to_free_list(p);
3310 * Update the waiting list
3312 if (prev == SCB_LIST_NULL)
3315 * First in the list
3317 aic_outb(p, next, WAITING_SCBH);
3319 else
3322 * Select the scb that pointed to us and update its next pointer.
3324 aic_outb(p, prev, SCBPTR);
3325 aic_outb(p, next, SCB_NEXT);
3328 * Point us back at the original scb position and inform the SCSI
3329 * system that the command has been aborted.
3331 aic_outb(p, curscb, SCBPTR);
3332 return (next);
3335 /*+F*************************************************************************
3336 * Function:
3337 * aic7xxx_search_qinfifo
3339 * Description:
3340 * Search the queue-in FIFO for matching SCBs and conditionally
3341 * requeue. Returns the number of matching SCBs.
3342 *-F*************************************************************************/
3343 static int
3344 aic7xxx_search_qinfifo(struct aic7xxx_host *p, int target, int channel,
3345 int lun, unsigned char tag, int flags, int requeue,
3346 volatile scb_queue_type *queue)
3348 int found;
3349 unsigned char qinpos, qintail;
3350 struct aic7xxx_scb *scbp;
3352 found = 0;
3353 qinpos = aic_inb(p, QINPOS);
3354 qintail = p->qinfifonext;
3356 p->qinfifonext = qinpos;
3358 while (qinpos != qintail)
3360 scbp = p->scb_data->scb_array[p->qinfifo[qinpos++]];
3361 if (aic7xxx_match_scb(p, scbp, target, channel, lun, tag))
3364 * We found an scb that needs to be removed.
3366 if (requeue && (queue != NULL))
3368 if (scbp->flags & SCB_WAITINGQ)
3370 scbq_remove(queue, scbp);
3371 scbq_remove(&p->waiting_scbs, scbp);
3372 scbq_remove(&p->delayed_scbs[TARGET_INDEX(scbp->cmd)], scbp);
3373 p->dev_active_cmds[TARGET_INDEX(scbp->cmd)]++;
3374 p->activescbs++;
3376 scbq_insert_tail(queue, scbp);
3377 p->dev_active_cmds[TARGET_INDEX(scbp->cmd)]--;
3378 p->activescbs--;
3379 scbp->flags |= SCB_WAITINGQ;
3380 if ( !(scbp->tag_action & TAG_ENB) )
3382 aic7xxx_index_busy_target(p, scbp->hscb->target_channel_lun,
3383 TRUE);
3386 else if (requeue)
3388 p->qinfifo[p->qinfifonext++] = scbp->hscb->tag;
3390 else
3393 * Preserve any SCB_RECOVERY_SCB flags on this scb then set the
3394 * flags we were called with, presumeably so aic7xxx_run_done_queue
3395 * can find this scb
3397 scbp->flags = flags | (scbp->flags & SCB_RECOVERY_SCB);
3398 if (aic7xxx_index_busy_target(p, scbp->hscb->target_channel_lun,
3399 FALSE) == scbp->hscb->tag)
3401 aic7xxx_index_busy_target(p, scbp->hscb->target_channel_lun,
3402 TRUE);
3405 found++;
3407 else
3409 p->qinfifo[p->qinfifonext++] = scbp->hscb->tag;
3413 * Now that we've done the work, clear out any left over commands in the
3414 * qinfifo and update the KERNEL_QINPOS down on the card.
3416 * NOTE: This routine expect the sequencer to already be paused when
3417 * it is run....make sure it's that way!
3419 qinpos = p->qinfifonext;
3420 while(qinpos != qintail)
3422 p->qinfifo[qinpos++] = SCB_LIST_NULL;
3424 if (p->features & AHC_QUEUE_REGS)
3425 aic_outb(p, p->qinfifonext, HNSCB_QOFF);
3426 else
3427 aic_outb(p, p->qinfifonext, KERNEL_QINPOS);
3429 return (found);
3432 /*+F*************************************************************************
3433 * Function:
3434 * aic7xxx_scb_on_qoutfifo
3436 * Description:
3437 * Is the scb that was passed to us currently on the qoutfifo?
3438 *-F*************************************************************************/
3439 static int
3440 aic7xxx_scb_on_qoutfifo(struct aic7xxx_host *p, struct aic7xxx_scb *scb)
3442 int i=0;
3444 while(p->qoutfifo[(p->qoutfifonext + i) & 0xff ] != SCB_LIST_NULL)
3446 if(p->qoutfifo[(p->qoutfifonext + i) & 0xff ] == scb->hscb->tag)
3447 return TRUE;
3448 else
3449 i++;
3451 return FALSE;
3455 /*+F*************************************************************************
3456 * Function:
3457 * aic7xxx_reset_device
3459 * Description:
3460 * The device at the given target/channel has been reset. Abort
3461 * all active and queued scbs for that target/channel. This function
3462 * need not worry about linked next pointers because if was a MSG_ABORT_TAG
3463 * then we had a tagged command (no linked next), if it was MSG_ABORT or
3464 * MSG_BUS_DEV_RESET then the device won't know about any commands any more
3465 * and no busy commands will exist, and if it was a bus reset, then nothing
3466 * knows about any linked next commands any more. In all cases, we don't
3467 * need to worry about the linked next or busy scb, we just need to clear
3468 * them.
3469 *-F*************************************************************************/
3470 static void
3471 aic7xxx_reset_device(struct aic7xxx_host *p, int target, int channel,
3472 int lun, unsigned char tag)
3474 struct aic7xxx_scb *scbp;
3475 unsigned char active_scb, tcl;
3476 int i = 0, j, init_lists = FALSE;
3479 * Restore this when we're done
3481 active_scb = aic_inb(p, SCBPTR);
3483 if (aic7xxx_verbose & (VERBOSE_RESET_PROCESS | VERBOSE_ABORT_PROCESS))
3484 printk(INFO_LEAD "Reset device, active_scb %d\n",
3485 p->host_no, channel, target, lun, active_scb);
3487 * Deal with the busy target and linked next issues.
3490 int min_target, max_target;
3491 struct aic7xxx_scb *scbp, *prev_scbp;
3493 /* Make all targets 'relative' to bus A. */
3494 if (target == ALL_TARGETS)
3496 switch (channel)
3498 case 0:
3499 min_target = 0;
3500 max_target = (p->features & AHC_WIDE) ? 15 : 7;
3501 break;
3502 case 1:
3503 min_target = 8;
3504 max_target = 15;
3505 break;
3506 case ALL_CHANNELS:
3507 default:
3508 min_target = 0;
3509 max_target = (p->features & (AHC_TWIN|AHC_WIDE)) ? 15 : 7;
3510 break;
3513 else
3515 min_target = target | (channel << 3);
3516 max_target = min_target;
3520 for (i = min_target; i <= max_target; i++)
3522 if ( i == p->scsi_id )
3524 continue;
3526 if (aic7xxx_verbose & (VERBOSE_ABORT_PROCESS | VERBOSE_RESET_PROCESS))
3527 printk(INFO_LEAD "Cleaning up status information "
3528 "and delayed_scbs.\n", p->host_no, channel, i, lun);
3529 p->dev_flags[i] &= ~(BUS_DEVICE_RESET_PENDING | DEVICE_PARITY_ERROR);
3530 if ( tag == SCB_LIST_NULL )
3532 p->dev_flags[i] |= DEVICE_PRINT_DTR | DEVICE_RESET_DELAY;
3533 p->dev_expires[i] = jiffies + (4 * HZ);
3534 p->dev_timer_active |= (0x01 << i);
3535 p->dev_last_queue_full_count[i] = 0;
3536 p->dev_last_queue_full[i] = 0;
3537 p->dev_temp_queue_depth[i] =
3538 p->dev_max_queue_depth[i];
3540 for(j=0; j<MAX_LUNS; j++)
3542 if (channel == 1)
3543 tcl = ((i << 4) & 0x70) | (channel << 3) | j;
3544 else
3545 tcl = (i << 4) | (channel << 3) | j;
3546 if ( (aic7xxx_index_busy_target(p, tcl, FALSE) == tag) ||
3547 (tag == SCB_LIST_NULL) )
3548 aic7xxx_index_busy_target(p, tcl, /* unbusy */ TRUE);
3550 j = 0;
3551 prev_scbp = NULL;
3552 scbp = p->delayed_scbs[i].head;
3553 while ( (scbp != NULL) && (j++ <= (p->scb_data->numscbs + 1)) )
3555 prev_scbp = scbp;
3556 scbp = scbp->q_next;
3557 if ( prev_scbp == scbp )
3559 if (aic7xxx_verbose & (VERBOSE_ABORT | VERBOSE_RESET))
3560 printk(WARN_LEAD "Yikes!! scb->q_next == scb "
3561 "in the delayed_scbs queue!\n", p->host_no, channel, i, lun);
3562 scbp = NULL;
3563 prev_scbp->q_next = NULL;
3564 p->delayed_scbs[i].tail = prev_scbp;
3566 if (aic7xxx_match_scb(p, prev_scbp, target, channel, lun, tag))
3568 scbq_remove(&p->delayed_scbs[i], prev_scbp);
3569 if (prev_scbp->flags & SCB_WAITINGQ)
3571 p->dev_active_cmds[i]++;
3572 p->activescbs++;
3574 prev_scbp->flags &= ~(SCB_ACTIVE | SCB_WAITINGQ);
3575 prev_scbp->flags |= SCB_RESET | SCB_QUEUED_FOR_DONE;
3578 if ( j > (p->scb_data->maxscbs + 1) )
3580 if (aic7xxx_verbose & (VERBOSE_ABORT | VERBOSE_RESET))
3581 printk(WARN_LEAD "Yikes!! There's a loop in the "
3582 "delayed_scbs queue!\n", p->host_no, channel, i, lun);
3583 scbq_init(&p->delayed_scbs[i]);
3585 if ( !(p->dev_timer_active & (0x01 << MAX_TARGETS)) ||
3586 time_after_eq(p->dev_timer.expires, p->dev_expires[i]) )
3588 mod_timer(&p->dev_timer, p->dev_expires[i]);
3589 p->dev_timer_active |= (0x01 << MAX_TARGETS);
3594 if (aic7xxx_verbose & (VERBOSE_ABORT_PROCESS | VERBOSE_RESET_PROCESS))
3595 printk(INFO_LEAD "Cleaning QINFIFO.\n", p->host_no, channel, target, lun );
3596 aic7xxx_search_qinfifo(p, target, channel, lun, tag,
3597 SCB_RESET | SCB_QUEUED_FOR_DONE, /* requeue */ FALSE, NULL);
3600 * Search the waiting_scbs queue for matches, this catches any SCB_QUEUED
3601 * ABORT/RESET commands.
3603 if (aic7xxx_verbose & (VERBOSE_ABORT_PROCESS | VERBOSE_RESET_PROCESS))
3604 printk(INFO_LEAD "Cleaning waiting_scbs.\n", p->host_no, channel,
3605 target, lun );
3607 struct aic7xxx_scb *scbp, *prev_scbp;
3609 j = 0;
3610 prev_scbp = NULL;
3611 scbp = p->waiting_scbs.head;
3612 while ( (scbp != NULL) && (j++ <= (p->scb_data->numscbs + 1)) )
3614 prev_scbp = scbp;
3615 scbp = scbp->q_next;
3616 if ( prev_scbp == scbp )
3618 if (aic7xxx_verbose & (VERBOSE_ABORT | VERBOSE_RESET))
3619 printk(WARN_LEAD "Yikes!! scb->q_next == scb "
3620 "in the waiting_scbs queue!\n", p->host_no, CTL_OF_SCB(scbp));
3621 scbp = NULL;
3622 prev_scbp->q_next = NULL;
3623 p->waiting_scbs.tail = prev_scbp;
3625 if (aic7xxx_match_scb(p, prev_scbp, target, channel, lun, tag))
3627 scbq_remove(&p->waiting_scbs, prev_scbp);
3628 if (prev_scbp->flags & SCB_WAITINGQ)
3630 p->dev_active_cmds[TARGET_INDEX(prev_scbp->cmd)]++;
3631 p->activescbs++;
3633 prev_scbp->flags &= ~(SCB_ACTIVE | SCB_WAITINGQ);
3634 prev_scbp->flags |= SCB_RESET | SCB_QUEUED_FOR_DONE;
3637 if ( j > (p->scb_data->maxscbs + 1) )
3639 if (aic7xxx_verbose & (VERBOSE_ABORT | VERBOSE_RESET))
3640 printk(WARN_LEAD "Yikes!! There's a loop in the "
3641 "waiting_scbs queue!\n", p->host_no, channel, target, lun);
3642 scbq_init(&p->waiting_scbs);
3648 * Search waiting for selection list.
3650 if (aic7xxx_verbose & (VERBOSE_ABORT_PROCESS | VERBOSE_RESET_PROCESS))
3651 printk(INFO_LEAD "Cleaning waiting for selection "
3652 "list.\n", p->host_no, channel, target, lun);
3654 unsigned char next, prev, scb_index;
3656 next = aic_inb(p, WAITING_SCBH); /* Start at head of list. */
3657 prev = SCB_LIST_NULL;
3658 j = 0;
3659 while ( (next != SCB_LIST_NULL) && (j++ <= (p->scb_data->maxscbs + 1)) )
3661 aic_outb(p, next, SCBPTR);
3662 scb_index = aic_inb(p, SCB_TAG);
3663 if (scb_index >= p->scb_data->numscbs)
3666 * No aic7xxx_verbose check here.....we want to see this since it
3667 * means either the kernel driver or the sequencer screwed things up
3669 printk(WARN_LEAD "Waiting List inconsistency; SCB index=%d, "
3670 "numscbs=%d\n", p->host_no, channel, target, lun, scb_index,
3671 p->scb_data->numscbs);
3672 next = aic_inb(p, SCB_NEXT);
3673 aic7xxx_add_curscb_to_free_list(p);
3675 else
3677 scbp = p->scb_data->scb_array[scb_index];
3678 if (aic7xxx_match_scb(p, scbp, target, channel, lun, tag))
3680 next = aic7xxx_abort_waiting_scb(p, scbp, next, prev);
3681 if (scbp->flags & SCB_WAITINGQ)
3683 p->dev_active_cmds[TARGET_INDEX(scbp->cmd)]++;
3684 p->activescbs++;
3686 scbp->flags &= ~(SCB_ACTIVE | SCB_WAITINGQ);
3687 scbp->flags |= SCB_RESET | SCB_QUEUED_FOR_DONE;
3688 if (prev == SCB_LIST_NULL)
3691 * This is either the first scb on the waiting list, or we
3692 * have already yanked the first and haven't left any behind.
3693 * Either way, we need to turn off the selection hardware if
3694 * it isn't already off.
3696 aic_outb(p, aic_inb(p, SCSISEQ) & ~ENSELO, SCSISEQ);
3697 aic_outb(p, CLRSELTIMEO, CLRSINT1);
3700 else
3702 prev = next;
3703 next = aic_inb(p, SCB_NEXT);
3707 if ( j > (p->scb_data->maxscbs + 1) )
3709 printk(WARN_LEAD "Yikes!! There is a loop in the waiting for "
3710 "selection list!\n", p->host_no, channel, target, lun);
3711 init_lists = TRUE;
3716 * Go through disconnected list and remove any entries we have queued
3717 * for completion, zeroing their control byte too.
3719 if (aic7xxx_verbose & (VERBOSE_ABORT_PROCESS | VERBOSE_RESET_PROCESS))
3720 printk(INFO_LEAD "Cleaning disconnected scbs "
3721 "list.\n", p->host_no, channel, target, lun);
3722 if (p->flags & AHC_PAGESCBS)
3724 unsigned char next, prev, scb_index;
3726 next = aic_inb(p, DISCONNECTED_SCBH);
3727 prev = SCB_LIST_NULL;
3728 j = 0;
3729 while ( (next != SCB_LIST_NULL) && (j++ <= (p->scb_data->maxscbs + 1)) )
3731 aic_outb(p, next, SCBPTR);
3732 scb_index = aic_inb(p, SCB_TAG);
3733 if (scb_index > p->scb_data->numscbs)
3735 printk(WARN_LEAD "Disconnected List inconsistency; SCB index=%d, "
3736 "numscbs=%d\n", p->host_no, channel, target, lun, scb_index,
3737 p->scb_data->numscbs);
3738 next = aic7xxx_rem_scb_from_disc_list(p, next, prev);
3740 else
3742 scbp = p->scb_data->scb_array[scb_index];
3743 if (aic7xxx_match_scb(p, scbp, target, channel, lun, tag))
3745 next = aic7xxx_rem_scb_from_disc_list(p, next, prev);
3746 if (scbp->flags & SCB_WAITINGQ)
3748 p->dev_active_cmds[TARGET_INDEX(scbp->cmd)]++;
3749 p->activescbs++;
3751 scbp->flags &= ~(SCB_ACTIVE | SCB_WAITINGQ);
3752 scbp->flags |= SCB_RESET | SCB_QUEUED_FOR_DONE;
3753 scbp->hscb->control = 0;
3755 else
3757 prev = next;
3758 next = aic_inb(p, SCB_NEXT);
3762 if ( j > (p->scb_data->maxscbs + 1) )
3764 printk(WARN_LEAD "Yikes!! There is a loop in the disconnected list!\n",
3765 p->host_no, channel, target, lun);
3766 init_lists = TRUE;
3771 * Walk the free list making sure no entries on the free list have
3772 * a valid SCB_TAG value or SCB_CONTROL byte.
3774 if (p->flags & AHC_PAGESCBS)
3776 unsigned char next;
3778 j = 0;
3779 next = aic_inb(p, FREE_SCBH);
3780 if ( (next >= p->scb_data->maxhscbs) && (next != SCB_LIST_NULL) )
3782 printk(WARN_LEAD "Bogus FREE_SCBH!.\n", p->host_no, channel,
3783 target, lun);
3784 init_lists = TRUE;
3785 next = SCB_LIST_NULL;
3787 while ( (next != SCB_LIST_NULL) && (j++ <= (p->scb_data->maxscbs + 1)) )
3789 aic_outb(p, next, SCBPTR);
3790 if (aic_inb(p, SCB_TAG) < p->scb_data->numscbs)
3792 printk(WARN_LEAD "Free list inconsistency!.\n", p->host_no, channel,
3793 target, lun);
3794 init_lists = TRUE;
3795 next = SCB_LIST_NULL;
3797 else
3799 aic_outb(p, SCB_LIST_NULL, SCB_TAG);
3800 aic_outb(p, 0, SCB_CONTROL);
3801 next = aic_inb(p, SCB_NEXT);
3804 if ( j > (p->scb_data->maxscbs + 1) )
3806 printk(WARN_LEAD "Yikes!! There is a loop in the free list!\n",
3807 p->host_no, channel, target, lun);
3808 init_lists = TRUE;
3813 * Go through the hardware SCB array looking for commands that
3814 * were active but not on any list.
3816 if (init_lists)
3818 aic_outb(p, SCB_LIST_NULL, FREE_SCBH);
3819 aic_outb(p, SCB_LIST_NULL, WAITING_SCBH);
3820 aic_outb(p, SCB_LIST_NULL, DISCONNECTED_SCBH);
3822 for (i = p->scb_data->maxhscbs - 1; i >= 0; i--)
3824 unsigned char scbid;
3826 aic_outb(p, i, SCBPTR);
3827 if (init_lists)
3829 aic_outb(p, SCB_LIST_NULL, SCB_TAG);
3830 aic_outb(p, SCB_LIST_NULL, SCB_NEXT);
3831 aic_outb(p, 0, SCB_CONTROL);
3832 aic7xxx_add_curscb_to_free_list(p);
3834 else
3836 scbid = aic_inb(p, SCB_TAG);
3837 if (scbid < p->scb_data->numscbs)
3839 scbp = p->scb_data->scb_array[scbid];
3840 if (aic7xxx_match_scb(p, scbp, target, channel, lun, tag))
3842 aic_outb(p, 0, SCB_CONTROL);
3843 aic_outb(p, SCB_LIST_NULL, SCB_TAG);
3844 aic7xxx_add_curscb_to_free_list(p);
3851 * Go through the entire SCB array now and look for commands for
3852 * for this target that are stillactive. These are other (most likely
3853 * tagged) commands that were disconnected when the reset occurred.
3854 * Any commands we find here we know this about, it wasn't on any queue,
3855 * it wasn't in the qinfifo, it wasn't in the disconnected or waiting
3856 * lists, so it really must have been a paged out SCB. In that case,
3857 * we shouldn't need to bother with updating any counters, just mark
3858 * the correct flags and go on.
3860 for (i = 0; i < p->scb_data->numscbs; i++)
3862 scbp = p->scb_data->scb_array[i];
3863 if ((scbp->flags & SCB_ACTIVE) &&
3864 aic7xxx_match_scb(p, scbp, target, channel, lun, tag) &&
3865 !aic7xxx_scb_on_qoutfifo(p, scbp))
3867 if (scbp->flags & SCB_WAITINGQ)
3869 scbq_remove(&p->waiting_scbs, scbp);
3870 scbq_remove(&p->delayed_scbs[TARGET_INDEX(scbp->cmd)], scbp);
3871 p->dev_active_cmds[TARGET_INDEX(scbp->cmd)]++;
3872 p->activescbs++;
3874 scbp->flags |= SCB_RESET | SCB_QUEUED_FOR_DONE;
3875 scbp->flags &= ~(SCB_ACTIVE | SCB_WAITINGQ);
3879 aic_outb(p, active_scb, SCBPTR);
3883 /*+F*************************************************************************
3884 * Function:
3885 * aic7xxx_clear_intstat
3887 * Description:
3888 * Clears the interrupt status.
3889 *-F*************************************************************************/
3890 static void
3891 aic7xxx_clear_intstat(struct aic7xxx_host *p)
3893 /* Clear any interrupt conditions this may have caused. */
3894 aic_outb(p, CLRSELDO | CLRSELDI | CLRSELINGO, CLRSINT0);
3895 aic_outb(p, CLRSELTIMEO | CLRATNO | CLRSCSIRSTI | CLRBUSFREE | CLRSCSIPERR |
3896 CLRPHASECHG | CLRREQINIT, CLRSINT1);
3897 aic_outb(p, CLRSCSIINT | CLRSEQINT | CLRBRKADRINT | CLRPARERR, CLRINT);
3900 /*+F*************************************************************************
3901 * Function:
3902 * aic7xxx_reset_current_bus
3904 * Description:
3905 * Reset the current SCSI bus.
3906 *-F*************************************************************************/
3907 static void
3908 aic7xxx_reset_current_bus(struct aic7xxx_host *p)
3911 /* Disable reset interrupts. */
3912 aic_outb(p, aic_inb(p, SIMODE1) & ~ENSCSIRST, SIMODE1);
3914 /* Turn off the bus' current operations, after all, we shouldn't have any
3915 * valid commands left to cause a RSELI and SELO once we've tossed the
3916 * bus away with this reset, so we might as well shut down the sequencer
3917 * until the bus is restarted as oppossed to saving the current settings
3918 * and restoring them (which makes no sense to me). */
3920 /* Turn on the bus reset. */
3921 aic_outb(p, aic_inb(p, SCSISEQ) | SCSIRSTO, SCSISEQ);
3922 while ( (aic_inb(p, SCSISEQ) & SCSIRSTO) == 0)
3923 mdelay(5);
3926 * Some of the new Ultra2 chipsets need a longer delay after a chip
3927 * reset than just the init setup creates, so we have to delay here
3928 * before we go into a reset in order to make the chips happy.
3930 if (p->features & AHC_ULTRA2)
3931 mdelay(250);
3932 else
3933 mdelay(50);
3935 /* Turn off the bus reset. */
3936 aic_outb(p, 0, SCSISEQ);
3937 mdelay(10);
3939 aic7xxx_clear_intstat(p);
3940 /* Re-enable reset interrupts. */
3941 aic_outb(p, aic_inb(p, SIMODE1) | ENSCSIRST, SIMODE1);
3945 /*+F*************************************************************************
3946 * Function:
3947 * aic7xxx_reset_channel
3949 * Description:
3950 * Reset the channel.
3951 *-F*************************************************************************/
3952 static void
3953 aic7xxx_reset_channel(struct aic7xxx_host *p, int channel, int initiate_reset)
3955 unsigned long offset_min, offset_max;
3956 unsigned char sblkctl;
3957 int cur_channel;
3959 if (aic7xxx_verbose & VERBOSE_RESET_PROCESS)
3960 printk(INFO_LEAD "Reset channel called, %s initiate reset.\n",
3961 p->host_no, channel, -1, -1, (initiate_reset==TRUE) ? "will" : "won't" );
3964 if (channel == 1)
3966 p->needsdtr |= (p->needsdtr_copy & 0xFF00);
3967 p->dtr_pending &= 0x00FF;
3968 offset_min = 8;
3969 offset_max = 16;
3971 else
3973 if (p->features & AHC_TWIN)
3975 /* Channel A */
3976 p->needsdtr |= (p->needsdtr_copy & 0x00FF);
3977 p->dtr_pending &= 0xFF00;
3978 offset_min = 0;
3979 offset_max = 8;
3981 else
3983 p->needppr = p->needppr_copy;
3984 p->needsdtr = p->needsdtr_copy;
3985 p->needwdtr = p->needwdtr_copy;
3986 p->dtr_pending = 0x0;
3987 offset_min = 0;
3988 if (p->features & AHC_WIDE)
3990 offset_max = 16;
3992 else
3994 offset_max = 8;
3999 while (offset_min < offset_max)
4002 * Revert to async/narrow transfers until we renegotiate.
4004 aic_outb(p, 0, TARG_SCSIRATE + offset_min);
4005 if (p->features & AHC_ULTRA2)
4007 aic_outb(p, 0, TARG_OFFSET + offset_min);
4009 offset_min++;
4013 * Reset the bus and unpause/restart the controller
4015 sblkctl = aic_inb(p, SBLKCTL);
4016 if ( (p->chip & AHC_CHIPID_MASK) == AHC_AIC7770 )
4017 cur_channel = (sblkctl & SELBUSB) >> 3;
4018 else
4019 cur_channel = 0;
4020 if ( (cur_channel != channel) && (p->features & AHC_TWIN) )
4023 * Case 1: Command for another bus is active
4025 if (aic7xxx_verbose & VERBOSE_RESET_PROCESS)
4026 printk(INFO_LEAD "Stealthily resetting idle channel.\n", p->host_no,
4027 channel, -1, -1);
4029 * Stealthily reset the other bus without upsetting the current bus.
4031 aic_outb(p, sblkctl ^ SELBUSB, SBLKCTL);
4032 aic_outb(p, aic_inb(p, SIMODE1) & ~ENBUSFREE, SIMODE1);
4033 if (initiate_reset)
4035 aic7xxx_reset_current_bus(p);
4037 aic_outb(p, aic_inb(p, SCSISEQ) & (ENSELI|ENRSELI|ENAUTOATNP), SCSISEQ);
4038 aic7xxx_clear_intstat(p);
4039 aic_outb(p, sblkctl, SBLKCTL);
4041 else
4044 * Case 2: A command from this bus is active or we're idle.
4046 if (aic7xxx_verbose & VERBOSE_RESET_PROCESS)
4047 printk(INFO_LEAD "Resetting currently active channel.\n", p->host_no,
4048 channel, -1, -1);
4049 aic_outb(p, aic_inb(p, SIMODE1) & ~(ENBUSFREE|ENREQINIT),
4050 SIMODE1);
4051 p->flags &= ~AHC_HANDLING_REQINITS;
4052 p->msg_type = MSG_TYPE_NONE;
4053 p->msg_len = 0;
4054 if (initiate_reset)
4056 aic7xxx_reset_current_bus(p);
4058 aic_outb(p, aic_inb(p, SCSISEQ) & (ENSELI|ENRSELI|ENAUTOATNP), SCSISEQ);
4059 aic7xxx_clear_intstat(p);
4061 if (aic7xxx_verbose & VERBOSE_RESET_RETURN)
4062 printk(INFO_LEAD "Channel reset\n", p->host_no, channel, -1, -1);
4064 * Clean up all the state information for the pending transactions
4065 * on this bus.
4067 aic7xxx_reset_device(p, ALL_TARGETS, channel, ALL_LUNS, SCB_LIST_NULL);
4069 if ( !(p->features & AHC_TWIN) )
4071 restart_sequencer(p);
4074 return;
4077 /*+F*************************************************************************
4078 * Function:
4079 * aic7xxx_run_waiting_queues
4081 * Description:
4082 * Scan the awaiting_scbs queue downloading and starting as many
4083 * scbs as we can.
4084 *-F*************************************************************************/
4085 static void
4086 aic7xxx_run_waiting_queues(struct aic7xxx_host *p)
4088 struct aic7xxx_scb *scb;
4089 int tindex;
4090 int sent;
4091 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,1,95)
4092 unsigned long cpu_flags = 0;
4093 #endif
4096 if (p->waiting_scbs.head == NULL)
4097 return;
4099 sent = 0;
4102 * First handle SCBs that are waiting but have been assigned a slot.
4104 DRIVER_LOCK
4105 while ((scb = scbq_remove_head(&p->waiting_scbs)) != NULL)
4107 tindex = TARGET_INDEX(scb->cmd);
4108 if ( !scb->tag_action && (p->tagenable & (1<<tindex)) )
4110 p->dev_temp_queue_depth[tindex] = 1;
4112 if ( (p->dev_active_cmds[tindex] >=
4113 p->dev_temp_queue_depth[tindex]) ||
4114 (p->dev_flags[tindex] & (DEVICE_RESET_DELAY|DEVICE_WAS_BUSY)) ||
4115 (p->flags & AHC_RESET_DELAY) )
4117 scbq_insert_tail(&p->delayed_scbs[tindex], scb);
4119 else
4121 scb->flags &= ~SCB_WAITINGQ;
4122 p->dev_active_cmds[tindex]++;
4123 p->activescbs++;
4124 if ( !(scb->tag_action) )
4126 aic7xxx_busy_target(p, scb);
4128 p->qinfifo[p->qinfifonext++] = scb->hscb->tag;
4129 sent++;
4132 if (sent)
4134 if (p->features & AHC_QUEUE_REGS)
4135 aic_outb(p, p->qinfifonext, HNSCB_QOFF);
4136 else
4138 pause_sequencer(p);
4139 aic_outb(p, p->qinfifonext, KERNEL_QINPOS);
4140 unpause_sequencer(p, FALSE);
4142 if (p->activescbs > p->max_activescbs)
4143 p->max_activescbs = p->activescbs;
4145 DRIVER_UNLOCK
4148 #ifdef CONFIG_PCI
4150 #define DPE 0x80
4151 #define SSE 0x40
4152 #define RMA 0x20
4153 #define RTA 0x10
4154 #define STA 0x08
4155 #define DPR 0x01
4157 /*+F*************************************************************************
4158 * Function:
4159 * aic7xxx_pci_intr
4161 * Description:
4162 * Check the scsi card for PCI errors and clear the interrupt
4164 * NOTE: If you don't have this function and a 2940 card encounters
4165 * a PCI error condition, the machine will end up locked as the
4166 * interrupt handler gets slammed with non-stop PCI error interrupts
4167 *-F*************************************************************************/
4168 static void
4169 aic7xxx_pci_intr(struct aic7xxx_host *p)
4171 unsigned char status1;
4173 #if LINUX_VERSION_CODE > KERNEL_VERSION(2,1,92)
4174 pci_read_config_byte(p->pdev, PCI_STATUS + 1, &status1);
4175 #else
4176 pcibios_read_config_byte(p->pci_bus, p->pci_device_fn,
4177 PCI_STATUS + 1, &status1);
4178 #endif
4180 if ( (status1 & DPE) && (aic7xxx_verbose & VERBOSE_MINOR_ERROR) )
4181 printk(WARN_LEAD "Data Parity Error during PCI address or PCI write"
4182 "phase.\n", p->host_no, -1, -1, -1);
4183 if ( (status1 & SSE) && (aic7xxx_verbose & VERBOSE_MINOR_ERROR) )
4184 printk(WARN_LEAD "Signal System Error Detected\n", p->host_no,
4185 -1, -1, -1);
4186 if ( (status1 & RMA) && (aic7xxx_verbose & VERBOSE_MINOR_ERROR) )
4187 printk(WARN_LEAD "Received a PCI Master Abort\n", p->host_no,
4188 -1, -1, -1);
4189 if ( (status1 & RTA) && (aic7xxx_verbose & VERBOSE_MINOR_ERROR) )
4190 printk(WARN_LEAD "Received a PCI Target Abort\n", p->host_no,
4191 -1, -1, -1);
4192 if ( (status1 & STA) && (aic7xxx_verbose & VERBOSE_MINOR_ERROR) )
4193 printk(WARN_LEAD "Signaled a PCI Target Abort\n", p->host_no,
4194 -1, -1, -1);
4195 if ( (status1 & DPR) && (aic7xxx_verbose & VERBOSE_MINOR_ERROR) )
4196 printk(WARN_LEAD "Data Parity Error has been reported via PCI pin "
4197 "PERR#\n", p->host_no, -1, -1, -1);
4199 #if LINUX_VERSION_CODE > KERNEL_VERSION(2,1,92)
4200 pci_write_config_byte(p->pdev, PCI_STATUS + 1, status1);
4201 #else
4202 pcibios_write_config_byte(p->pci_bus, p->pci_device_fn,
4203 PCI_STATUS + 1, status1);
4204 #endif
4205 if (status1 & (DPR|RMA|RTA))
4206 aic_outb(p, CLRPARERR, CLRINT);
4208 if ( (aic7xxx_panic_on_abort) && (p->spurious_int > 500) )
4209 aic7xxx_panic_abort(p, NULL);
4212 #endif /* CONFIG_PCI */
4214 /*+F*************************************************************************
4215 * Function:
4216 * aic7xxx_timer
4218 * Description:
4219 * Take expired extries off of delayed queues and place on waiting queue
4220 * then run waiting queue to start commands.
4221 ***************************************************************************/
4222 static void
4223 aic7xxx_timer(struct aic7xxx_host *p)
4225 int i, j;
4226 unsigned long cpu_flags = 0;
4227 struct aic7xxx_scb *scb;
4229 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,1,95)
4230 DRIVER_LOCK
4231 #else
4232 spin_lock_irqsave(&io_request_lock, cpu_flags);
4233 #endif
4234 p->dev_timer_active &= ~(0x01 << MAX_TARGETS);
4235 if ( (p->dev_timer_active & (0x01 << p->scsi_id)) &&
4236 time_after_eq(jiffies, p->dev_expires[p->scsi_id]) )
4238 p->flags &= ~AHC_RESET_DELAY;
4239 p->dev_timer_active &= ~(0x01 << p->scsi_id);
4241 for(i=0; i<MAX_TARGETS; i++)
4243 if ( (i != p->scsi_id) &&
4244 (p->dev_timer_active & (0x01 << i)) &&
4245 time_after_eq(jiffies, p->dev_expires[i]) )
4247 p->dev_timer_active &= ~(0x01 << i);
4248 p->dev_flags[i] &= ~(DEVICE_RESET_DELAY|DEVICE_WAS_BUSY);
4249 p->dev_temp_queue_depth[i] = p->dev_max_queue_depth[i];
4250 j = 0;
4251 while ( ((scb = scbq_remove_head(&p->delayed_scbs[i])) != NULL) &&
4252 (j++ < p->scb_data->numscbs) )
4254 scbq_insert_tail(&p->waiting_scbs, scb);
4256 if (j == p->scb_data->numscbs)
4258 printk(INFO_LEAD "timer: Yikes, loop in delayed_scbs list.\n",
4259 p->host_no, 0, i, -1);
4260 scbq_init(&p->delayed_scbs[i]);
4261 scbq_init(&p->waiting_scbs);
4263 * Well, things are screwed now, wait for a reset to clean the junk
4264 * out.
4268 else if ( p->dev_timer_active & (0x01 << i) )
4270 if ( p->dev_timer_active & (0x01 << MAX_TARGETS) )
4272 if ( time_after_eq(p->dev_timer.expires, p->dev_expires[i]) )
4274 p->dev_timer.expires = p->dev_expires[i];
4277 else
4279 p->dev_timer.expires = p->dev_expires[i];
4280 p->dev_timer_active |= (0x01 << MAX_TARGETS);
4284 if ( p->dev_timer_active & (0x01 << MAX_TARGETS) )
4286 add_timer(&p->dev_timer);
4289 aic7xxx_run_waiting_queues(p);
4290 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,1,95)
4291 DRIVER_UNLOCK
4292 #else
4293 spin_unlock_irqrestore(&io_request_lock, cpu_flags);
4294 #endif
4297 /*+F*************************************************************************
4298 * Function:
4299 * aic7xxx_construct_ppr
4301 * Description:
4302 * Build up a Parallel Protocol Request message for use with SCSI-3
4303 * devices.
4304 *-F*************************************************************************/
4305 static void
4306 aic7xxx_construct_ppr(struct aic7xxx_host *p, struct aic7xxx_scb *scb)
4308 int tindex = TARGET_INDEX(scb->cmd);
4310 p->msg_buf[p->msg_index++] = MSG_EXTENDED;
4311 p->msg_buf[p->msg_index++] = MSG_EXT_PPR_LEN;
4312 p->msg_buf[p->msg_index++] = MSG_EXT_PPR;
4313 p->msg_buf[p->msg_index++] = p->transinfo[tindex].goal_period;
4314 p->msg_buf[p->msg_index++] = 0;
4315 p->msg_buf[p->msg_index++] = p->transinfo[tindex].goal_offset;
4316 p->msg_buf[p->msg_index++] = p->transinfo[tindex].goal_width;
4317 p->msg_buf[p->msg_index++] = p->transinfo[tindex].goal_options;
4318 p->msg_len += 8;
4321 /*+F*************************************************************************
4322 * Function:
4323 * aic7xxx_construct_sdtr
4325 * Description:
4326 * Constucts a synchronous data transfer message in the message
4327 * buffer on the sequencer.
4328 *-F*************************************************************************/
4329 static void
4330 aic7xxx_construct_sdtr(struct aic7xxx_host *p, unsigned char period,
4331 unsigned char offset)
4333 p->msg_buf[p->msg_index++] = MSG_EXTENDED;
4334 p->msg_buf[p->msg_index++] = MSG_EXT_SDTR_LEN;
4335 p->msg_buf[p->msg_index++] = MSG_EXT_SDTR;
4336 p->msg_buf[p->msg_index++] = period;
4337 p->msg_buf[p->msg_index++] = offset;
4338 p->msg_len += 5;
4341 /*+F*************************************************************************
4342 * Function:
4343 * aic7xxx_construct_wdtr
4345 * Description:
4346 * Constucts a wide data transfer message in the message buffer
4347 * on the sequencer.
4348 *-F*************************************************************************/
4349 static void
4350 aic7xxx_construct_wdtr(struct aic7xxx_host *p, unsigned char bus_width)
4352 p->msg_buf[p->msg_index++] = MSG_EXTENDED;
4353 p->msg_buf[p->msg_index++] = MSG_EXT_WDTR_LEN;
4354 p->msg_buf[p->msg_index++] = MSG_EXT_WDTR;
4355 p->msg_buf[p->msg_index++] = bus_width;
4356 p->msg_len += 4;
4359 /*+F*************************************************************************
4360 * Function:
4361 * aic7xxx_calc_residual
4363 * Description:
4364 * Calculate the residual data not yet transferred.
4365 *-F*************************************************************************/
4366 static void
4367 aic7xxx_calculate_residual (struct aic7xxx_host *p, struct aic7xxx_scb *scb)
4369 struct aic7xxx_hwscb *hscb;
4370 Scsi_Cmnd *cmd;
4371 int actual, i;
4373 cmd = scb->cmd;
4374 hscb = scb->hscb;
4377 * Don't destroy valid residual information with
4378 * residual coming from a check sense operation.
4380 if (((scb->hscb->control & DISCONNECTED) == 0) &&
4381 (scb->flags & SCB_SENSE) == 0)
4384 * We had an underflow. At this time, there's only
4385 * one other driver that bothers to check for this,
4386 * and cmd->underflow seems to be set rather half-
4387 * heartedly in the higher-level SCSI code.
4389 actual = scb->sg_length;
4390 for (i=1; i < hscb->residual_SG_segment_count; i++)
4392 actual -= scb->sg_list[scb->sg_count - i].length;
4394 actual -= (hscb->residual_data_count[2] << 16) |
4395 (hscb->residual_data_count[1] << 8) |
4396 hscb->residual_data_count[0];
4398 if (actual < cmd->underflow)
4400 if (aic7xxx_verbose & VERBOSE_MINOR_ERROR)
4401 printk(INFO_LEAD "Underflow - Wanted %u, %s %u, residual SG "
4402 "count %d.\n", p->host_no, CTL_OF_SCB(scb), cmd->underflow,
4403 (cmd->request.cmd == WRITE) ? "wrote" : "read", actual,
4404 hscb->residual_SG_segment_count);
4405 aic7xxx_error(cmd) = DID_RETRY_COMMAND;
4406 aic7xxx_status(cmd) = hscb->target_status;
4411 * Clean out the residual information in the SCB for the
4412 * next consumer.
4414 hscb->residual_data_count[2] = 0;
4415 hscb->residual_data_count[1] = 0;
4416 hscb->residual_data_count[0] = 0;
4417 hscb->residual_SG_segment_count = 0;
4420 /*+F*************************************************************************
4421 * Function:
4422 * aic7xxx_handle_device_reset
4424 * Description:
4425 * Interrupt handler for sequencer interrupts (SEQINT).
4426 *-F*************************************************************************/
4427 static void
4428 aic7xxx_handle_device_reset(struct aic7xxx_host *p, int target, int channel)
4430 unsigned short targ_mask;
4431 unsigned char tindex = target;
4433 tindex |= ((channel & 0x01) << 3);
4435 targ_mask = (0x01 << tindex);
4437 * Go back to async/narrow transfers and renegotiate.
4439 p->needppr |= (p->needppr_copy & targ_mask);
4440 p->needsdtr |= (p->needsdtr_copy & targ_mask);
4441 p->needwdtr |= (p->needwdtr_copy & targ_mask);
4442 p->dtr_pending &= ~targ_mask;
4443 aic_outb(p, 0, TARG_SCSIRATE + tindex);
4444 if (p->features & AHC_ULTRA2)
4445 aic_outb(p, 0, TARG_OFFSET + tindex);
4446 aic7xxx_reset_device(p, target, channel, ALL_LUNS, SCB_LIST_NULL);
4447 if (aic7xxx_verbose & VERBOSE_RESET_PROCESS)
4448 printk(INFO_LEAD "Bus Device Reset delivered.\n", p->host_no, channel,
4449 target, -1);
4450 aic7xxx_run_done_queue(p, /*complete*/ TRUE);
4453 /*+F*************************************************************************
4454 * Function:
4455 * aic7xxx_handle_seqint
4457 * Description:
4458 * Interrupt handler for sequencer interrupts (SEQINT).
4459 *-F*************************************************************************/
4460 static void
4461 aic7xxx_handle_seqint(struct aic7xxx_host *p, unsigned char intstat)
4463 struct aic7xxx_scb *scb;
4464 unsigned short target_mask;
4465 unsigned char target, lun, tindex;
4466 unsigned char queue_flag = FALSE;
4467 char channel;
4469 target = ((aic_inb(p, SAVED_TCL) >> 4) & 0x0f);
4470 if ( (p->chip & AHC_CHIPID_MASK) == AHC_AIC7770 )
4471 channel = (aic_inb(p, SBLKCTL) & SELBUSB) >> 3;
4472 else
4473 channel = 0;
4474 tindex = target + (channel << 3);
4475 lun = aic_inb(p, SAVED_TCL) & 0x07;
4476 target_mask = (0x01 << tindex);
4479 * Go ahead and clear the SEQINT now, that avoids any interrupt race
4480 * conditions later on in case we enable some other interrupt.
4482 aic_outb(p, CLRSEQINT, CLRINT);
4483 switch (intstat & SEQINT_MASK)
4485 case NO_MATCH:
4487 aic_outb(p, aic_inb(p, SCSISEQ) & (ENSELI|ENRSELI|ENAUTOATNP),
4488 SCSISEQ);
4489 printk(WARN_LEAD "No active SCB for reconnecting target - Issuing "
4490 "BUS DEVICE RESET.\n", p->host_no, channel, target, lun);
4491 printk(WARN_LEAD " SAVED_TCL=0x%x, ARG_1=0x%x, SEQADDR=0x%x\n",
4492 p->host_no, channel, target, lun,
4493 aic_inb(p, SAVED_TCL), aic_inb(p, ARG_1),
4494 (aic_inb(p, SEQADDR1) << 8) | aic_inb(p, SEQADDR0));
4495 if (aic7xxx_panic_on_abort)
4496 aic7xxx_panic_abort(p, NULL);
4498 break;
4500 case SEND_REJECT:
4502 if (aic7xxx_verbose & VERBOSE_MINOR_ERROR)
4503 printk(INFO_LEAD "Rejecting unknown message (0x%x) received from "
4504 "target, SEQ_FLAGS=0x%x\n", p->host_no, channel, target, lun,
4505 aic_inb(p, ACCUM), aic_inb(p, SEQ_FLAGS));
4507 break;
4509 case NO_IDENT:
4512 * The reconnecting target either did not send an identify
4513 * message, or did, but we didn't find an SCB to match and
4514 * before it could respond to our ATN/abort, it hit a dataphase.
4515 * The only safe thing to do is to blow it away with a bus
4516 * reset.
4518 if (aic7xxx_verbose & (VERBOSE_SEQINT | VERBOSE_RESET_MID))
4519 printk(INFO_LEAD "Target did not send an IDENTIFY message; "
4520 "LASTPHASE 0x%x, SAVED_TCL 0x%x\n", p->host_no, channel, target,
4521 lun, aic_inb(p, LASTPHASE), aic_inb(p, SAVED_TCL));
4523 aic7xxx_reset_channel(p, channel, /*initiate reset*/ TRUE);
4524 aic7xxx_run_done_queue(p, TRUE);
4527 break;
4529 case BAD_PHASE:
4530 if (aic_inb(p, LASTPHASE) == P_BUSFREE)
4532 if (aic7xxx_verbose & VERBOSE_SEQINT)
4533 printk(INFO_LEAD "Missed busfree.\n", p->host_no, channel,
4534 target, lun);
4535 restart_sequencer(p);
4537 else
4539 if (aic7xxx_verbose & VERBOSE_SEQINT)
4540 printk(INFO_LEAD "Unknown scsi bus phase, continuing\n", p->host_no,
4541 channel, target, lun);
4543 break;
4545 case EXTENDED_MSG:
4547 p->msg_type = MSG_TYPE_INITIATOR_MSGIN;
4548 p->msg_len = 0;
4549 p->msg_index = 0;
4551 #ifdef AIC7XXX_VERBOSE_DEBUGGING
4552 if (aic7xxx_verbose > 0xffff)
4553 printk(INFO_LEAD "Enabling REQINITs for MSG_IN\n", p->host_no,
4554 channel, target, lun);
4555 #endif
4558 * To actually receive the message, simply turn on
4559 * REQINIT interrupts and let our interrupt handler
4560 * do the rest (REQINIT should already be true).
4562 p->flags |= AHC_HANDLING_REQINITS;
4563 aic_outb(p, aic_inb(p, SIMODE1) | ENREQINIT, SIMODE1);
4566 * We don't want the sequencer unpaused yet so we return early
4568 return;
4571 case REJECT_MSG:
4574 * What we care about here is if we had an outstanding SDTR
4575 * or WDTR message for this target. If we did, this is a
4576 * signal that the target is refusing negotiation.
4578 unsigned char scb_index;
4579 unsigned char last_msg;
4581 scb_index = aic_inb(p, SCB_TAG);
4582 scb = p->scb_data->scb_array[scb_index];
4583 last_msg = aic_inb(p, LAST_MSG);
4585 if ( (last_msg == MSG_IDENTIFYFLAG) &&
4586 (scb->tag_action) &&
4587 !(scb->flags & SCB_MSGOUT_BITS) )
4589 if (scb->tag_action == MSG_ORDERED_Q_TAG)
4592 * OK...the device seems able to accept tagged commands, but
4593 * not ordered tag commands, only simple tag commands. So, we
4594 * disable ordered tag commands and go on with life just like
4595 * normal.
4597 p->orderedtag &= ~target_mask;
4598 scb->tag_action = MSG_SIMPLE_Q_TAG;
4599 scb->hscb->control &= ~SCB_TAG_TYPE;
4600 scb->hscb->control |= MSG_SIMPLE_Q_TAG;
4601 aic_outb(p, scb->hscb->control, SCB_CONTROL);
4603 * OK..we set the tag type to simple tag command, now we re-assert
4604 * ATNO and hope this will take us into the identify phase again
4605 * so we can resend the tag type and info to the device.
4607 aic_outb(p, MSG_IDENTIFYFLAG, MSG_OUT);
4608 aic_outb(p, aic_inb(p, SCSISIGI) | ATNO, SCSISIGO);
4610 else if (scb->tag_action == MSG_SIMPLE_Q_TAG)
4612 unsigned char i, reset = 0;
4613 struct aic7xxx_scb *scbp;
4614 int old_verbose;
4616 * Hmmmm....the device is flaking out on tagged commands. The
4617 * bad thing is that we already have tagged commands enabled in
4618 * the device struct in the mid level code. We also have a queue
4619 * set according to the tagged queue depth. Gonna have to live
4620 * with it by controlling our queue depth internally and making
4621 * sure we don't set the tagged command flag any more.
4623 p->tagenable &= ~target_mask;
4624 p->orderedtag &= ~target_mask;
4625 p->dev_max_queue_depth[tindex] =
4626 p->dev_temp_queue_depth[tindex] = 1;
4628 * We set this command up as a bus device reset. However, we have
4629 * to clear the tag type as it's causing us problems. We shouldnt
4630 * have to worry about any other commands being active, since if
4631 * the device is refusing tagged commands, this should be the
4632 * first tagged command sent to the device, however, we do have
4633 * to worry about any other tagged commands that may already be
4634 * in the qinfifo. The easiest way to do this, is to issue a BDR,
4635 * send all the commands back to the mid level code, then let them
4636 * come back and get rebuilt as untagged commands.
4638 scb->tag_action = 0;
4639 scb->hscb->control &= ~(TAG_ENB | SCB_TAG_TYPE);
4640 aic_outb(p, scb->hscb->control, SCB_CONTROL);
4642 old_verbose = aic7xxx_verbose;
4643 aic7xxx_verbose &= ~(VERBOSE_RESET|VERBOSE_ABORT);
4644 for (i=0; i!=p->scb_data->numscbs; i++)
4646 scbp = p->scb_data->scb_array[i];
4647 if ((scbp->flags & SCB_ACTIVE) && (scbp != scb))
4649 if (aic7xxx_match_scb(p, scbp, target, channel, lun, i))
4651 aic7xxx_reset_device(p, target, channel, lun, i);
4652 reset++;
4654 aic7xxx_run_done_queue(p, TRUE);
4657 aic7xxx_verbose = old_verbose;
4659 * Wait until after the for loop to set the busy index since
4660 * aic7xxx_reset_device will clear the busy index during its
4661 * operation.
4663 aic7xxx_busy_target(p, scb);
4664 printk(INFO_LEAD "Device is refusing tagged commands, using "
4665 "untagged I/O.\n", p->host_no, channel, target, lun);
4666 aic_outb(p, MSG_IDENTIFYFLAG, MSG_OUT);
4667 aic_outb(p, aic_inb(p, SCSISIGI) | ATNO, SCSISIGO);
4670 else if (scb->flags & SCB_MSGOUT_PPR)
4673 * As per the draft specs, any device capable of supporting any of
4674 * the option values other than 0 are not allowed to reject the
4675 * PPR message. Instead, they must negotiate out what they do
4676 * support instead of rejecting our offering.
4678 p->needppr &= ~target_mask;
4679 p->needppr_copy &= ~target_mask;
4680 aic7xxx_set_width(p, target, channel, lun, MSG_EXT_WDTR_BUS_8_BIT,
4681 (AHC_TRANS_ACTIVE|AHC_TRANS_CUR|AHC_TRANS_QUITE));
4682 aic7xxx_set_syncrate(p, NULL, target, channel, 0, 0, 0,
4683 AHC_TRANS_ACTIVE|AHC_TRANS_CUR|AHC_TRANS_QUITE);
4684 p->transinfo[tindex].goal_options = 0;
4685 p->dtr_pending &= ~target_mask;
4686 scb->flags &= ~SCB_MSGOUT_BITS;
4687 if(aic7xxx_verbose & VERBOSE_NEGOTIATION2)
4689 printk(INFO_LEAD "Device is rejecting PPR messages, falling "
4690 "back.\n", p->host_no, channel, target, lun);
4692 if ( p->transinfo[tindex].goal_width )
4694 p->needwdtr |= target_mask;
4695 p->needwdtr_copy |= target_mask;
4696 p->dtr_pending |= target_mask;
4697 scb->flags |= SCB_MSGOUT_WDTR;
4699 if ( p->transinfo[tindex].goal_offset )
4701 p->needsdtr |= target_mask;
4702 p->needsdtr_copy |= target_mask;
4703 if( !(p->dtr_pending & target_mask) )
4705 p->dtr_pending |= target_mask;
4706 scb->flags |= SCB_MSGOUT_SDTR;
4709 if ( p->dtr_pending & target_mask )
4711 aic_outb(p, HOST_MSG, MSG_OUT);
4712 aic_outb(p, aic_inb(p, SCSISIGI) | ATNO, SCSISIGO);
4715 else if (scb->flags & SCB_MSGOUT_WDTR)
4718 * note 8bit xfers and clear flag
4720 p->needwdtr &= ~target_mask;
4721 p->needwdtr_copy &= ~target_mask;
4722 p->dtr_pending &= ~target_mask;
4723 scb->flags &= ~SCB_MSGOUT_BITS;
4724 aic7xxx_set_width(p, target, channel, lun, MSG_EXT_WDTR_BUS_8_BIT,
4725 (AHC_TRANS_ACTIVE|AHC_TRANS_GOAL|AHC_TRANS_CUR));
4726 aic7xxx_set_syncrate(p, NULL, target, channel, 0, 0, 0,
4727 AHC_TRANS_ACTIVE|AHC_TRANS_CUR|AHC_TRANS_QUITE);
4728 if(aic7xxx_verbose & VERBOSE_NEGOTIATION2)
4730 printk(INFO_LEAD "Device is rejecting WDTR messages, using "
4731 "narrow transfers.\n", p->host_no, channel, target, lun);
4733 p->needsdtr |= (p->needsdtr_copy & target_mask);
4735 else if (scb->flags & SCB_MSGOUT_SDTR)
4738 * note asynch xfers and clear flag
4740 p->needsdtr &= ~target_mask;
4741 p->needsdtr_copy &= ~target_mask;
4742 p->dtr_pending &= ~target_mask;
4743 scb->flags &= ~SCB_MSGOUT_SDTR;
4744 aic7xxx_set_syncrate(p, NULL, target, channel, 0, 0, 0,
4745 (AHC_TRANS_CUR|AHC_TRANS_ACTIVE|AHC_TRANS_GOAL));
4746 if(aic7xxx_verbose & VERBOSE_NEGOTIATION2)
4748 printk(INFO_LEAD "Device is rejecting SDTR messages, using "
4749 "async transfers.\n", p->host_no, channel, target, lun);
4752 else if (aic7xxx_verbose & VERBOSE_SEQINT)
4755 * Otherwise, we ignore it.
4757 printk(INFO_LEAD "Received MESSAGE_REJECT for unknown cause. "
4758 "Ignoring.\n", p->host_no, channel, target, lun);
4761 break;
4763 case BAD_STATUS:
4765 unsigned char scb_index;
4766 struct aic7xxx_hwscb *hscb;
4767 Scsi_Cmnd *cmd;
4769 /* The sequencer will notify us when a command has an error that
4770 * would be of interest to the kernel. This allows us to leave
4771 * the sequencer running in the common case of command completes
4772 * without error. The sequencer will have DMA'd the SCB back
4773 * up to us, so we can reference the drivers SCB array.
4775 * Set the default return value to 0 indicating not to send
4776 * sense. The sense code will change this if needed and this
4777 * reduces code duplication.
4779 aic_outb(p, 0, RETURN_1);
4780 scb_index = aic_inb(p, SCB_TAG);
4781 if (scb_index > p->scb_data->numscbs)
4783 printk(WARN_LEAD "Invalid SCB during SEQINT 0x%02x, SCB_TAG %d.\n",
4784 p->host_no, channel, target, lun, intstat, scb_index);
4785 break;
4787 scb = p->scb_data->scb_array[scb_index];
4788 hscb = scb->hscb;
4790 if (!(scb->flags & SCB_ACTIVE) || (scb->cmd == NULL))
4792 printk(WARN_LEAD "Invalid SCB during SEQINT 0x%x, scb %d, flags 0x%x,"
4793 " cmd 0x%lx.\n", p->host_no, channel, target, lun, intstat,
4794 scb_index, scb->flags, (unsigned long) scb->cmd);
4796 else
4798 cmd = scb->cmd;
4799 hscb->target_status = aic_inb(p, SCB_TARGET_STATUS);
4800 aic7xxx_status(cmd) = hscb->target_status;
4802 cmd->result = hscb->target_status;
4804 switch (status_byte(hscb->target_status))
4806 case GOOD:
4807 if (aic7xxx_verbose & VERBOSE_SEQINT)
4808 printk(INFO_LEAD "Interrupted for status of GOOD???\n",
4809 p->host_no, CTL_OF_SCB(scb));
4810 break;
4812 case COMMAND_TERMINATED:
4813 case CHECK_CONDITION:
4814 if ( !(scb->flags & SCB_SENSE) )
4816 unsigned char *sense_buffer;
4818 * XXX - How do we save the residual (if there is one).
4820 if ( hscb->residual_SG_segment_count != 0 )
4821 aic7xxx_calculate_residual(p, scb);
4824 * Send a sense command to the requesting target.
4825 * XXX - revisit this and get rid of the memcopys.
4827 memcpy(scb->sense_cmd, &generic_sense[0],
4828 sizeof(generic_sense));
4830 scb->sense_cmd[1] = (cmd->lun << 5);
4831 scb->sense_cmd[4] = sizeof(cmd->sense_buffer);
4833 sense_buffer = cmd->sense_buffer;
4834 scb->sg_list[0].length =
4835 cpu_to_le32(sizeof(cmd->sense_buffer));
4838 * XXX - We should allow disconnection, but can't as it
4839 * might allow overlapped tagged commands.
4841 /* hscb->control &= DISCENB; */
4842 hscb->control = 0;
4843 hscb->target_status = 0;
4844 hscb->SG_list_pointer =
4845 cpu_to_le32(SCB_DMA_ADDR(scb, scb->sg_list));
4846 hscb->data_count = scb->sg_list[0].length;
4847 hscb->SCSI_cmd_pointer =
4848 cpu_to_le32(SCB_DMA_ADDR(scb, scb->sense_cmd));
4849 hscb->SCSI_cmd_length = COMMAND_SIZE(scb->sense_cmd[0]);
4850 hscb->residual_SG_segment_count = 0;
4851 hscb->residual_data_count[0] = 0;
4852 hscb->residual_data_count[1] = 0;
4853 hscb->residual_data_count[2] = 0;
4855 scb->sg_count = hscb->SG_segment_count = 1;
4856 scb->sg_length = sizeof(cmd->sense_buffer);
4857 scb->tag_action = 0;
4859 * This problem could be caused if the target has lost power
4860 * or found some other way to loose the negotiation settings,
4861 * so if needed, we'll re-negotiate while doing the sense cmd.
4862 * However, if this SCB already was attempting to negotiate,
4863 * then we assume this isn't the problem and skip this part.
4865 if ( (scb->cmd->cmnd[0] != TEST_UNIT_READY) &&
4866 (p->dev_flags[tindex] & DEVICE_SCANNED) &&
4867 !(p->dtr_pending & target_mask) )
4869 p->needppr |= (p->needppr_copy & target_mask);
4870 p->needwdtr |= (p->needwdtr_copy & target_mask);
4871 p->needsdtr |= (p->needsdtr_copy & target_mask);
4873 else if ( scb->cmd == p->dev_dtr_cmnd[tindex] )
4876 * This is already a negotiation command, so we must have
4877 * already done PPR, WDTR or SDTR. Since our negotiation
4878 * could have gotten rejected, we don't really know the
4879 * full state of things. Don't do anything here, and allow
4880 * the negotiation_complete() handler to do the right
4881 * thing.
4885 * This is the important part though. We are getting sense
4886 * info back from this device. It's going into a fake
4887 * command. We need to put that into the real command
4888 * instead so that the mid level SCSI code can act upon it.
4889 * So, when we set up these fake commands, the next pointer
4890 * is used to point to the real command. Use that to change
4891 * the address of our sense_buffer[] to the real command.
4892 * However, don't do this if the real command is also a
4893 * TEST_UNIT_READY as it will most likely pull down its own
4894 * SENSE information anyway.
4896 if (cmd->next->cmnd[0] != TEST_UNIT_READY)
4897 sense_buffer = cmd->next->sense_buffer;
4899 scb->sg_list[0].address =
4900 cpu_to_le32(pci_map_single(p->pdev, sense_buffer,
4901 sizeof(cmd->sense_buffer),
4902 PCI_DMA_FROMDEVICE));
4903 hscb->data_pointer = scb->sg_list[0].address;
4905 scb->flags |= SCB_SENSE;
4907 * Ensure the target is busy since this will be an
4908 * an untagged request.
4910 #ifdef AIC7XXX_VERBOSE_DEBUGGING
4911 if (aic7xxx_verbose & VERBOSE_NEGOTIATION2)
4913 if (scb->flags & SCB_MSGOUT_BITS)
4914 printk(INFO_LEAD "Requesting SENSE with %s\n", p->host_no,
4915 CTL_OF_SCB(scb), (scb->flags & SCB_MSGOUT_SDTR) ?
4916 "SDTR" : "WDTR");
4917 else
4918 printk(INFO_LEAD "Requesting SENSE, no MSG\n", p->host_no,
4919 CTL_OF_SCB(scb));
4921 #endif
4922 aic7xxx_busy_target(p, scb);
4923 aic_outb(p, SEND_SENSE, RETURN_1);
4924 aic7xxx_error(cmd) = DID_OK;
4925 break;
4926 } /* first time sense, no errors */
4927 aic7xxx_error(cmd) = DID_OK;
4928 scb->flags &= ~SCB_SENSE;
4929 break;
4931 case QUEUE_FULL:
4932 queue_flag = TRUE; /* Mark that this is a QUEUE_FULL and */
4933 case BUSY: /* drop through to here */
4935 struct aic7xxx_scb *next_scbp, *prev_scbp;
4936 unsigned char active_hscb, next_hscb, prev_hscb, scb_index;
4938 * We have to look three places for queued commands:
4939 * 1: QINFIFO
4940 * 2: p->waiting_scbs queue
4941 * 3: WAITING_SCBS list on card (for commands that are started
4942 * but haven't yet made it to the device)
4944 aic7xxx_search_qinfifo(p, target, channel, lun,
4945 SCB_LIST_NULL, 0, TRUE,
4946 &p->delayed_scbs[tindex]);
4947 next_scbp = p->waiting_scbs.head;
4948 while ( next_scbp != NULL )
4950 prev_scbp = next_scbp;
4951 next_scbp = next_scbp->q_next;
4952 if ( aic7xxx_match_scb(p, prev_scbp, target, channel, lun,
4953 SCB_LIST_NULL) )
4955 scbq_remove(&p->waiting_scbs, prev_scbp);
4956 scbq_insert_tail(&p->delayed_scbs[tindex],
4957 prev_scbp);
4960 next_scbp = NULL;
4961 active_hscb = aic_inb(p, SCBPTR);
4962 prev_hscb = next_hscb = scb_index = SCB_LIST_NULL;
4963 next_hscb = aic_inb(p, WAITING_SCBH);
4964 while (next_hscb != SCB_LIST_NULL)
4966 aic_outb(p, next_hscb, SCBPTR);
4967 scb_index = aic_inb(p, SCB_TAG);
4968 if (scb_index < p->scb_data->numscbs)
4970 next_scbp = p->scb_data->scb_array[scb_index];
4971 if (aic7xxx_match_scb(p, next_scbp, target, channel, lun,
4972 SCB_LIST_NULL) )
4974 if (next_scbp->flags & SCB_WAITINGQ)
4976 p->dev_active_cmds[tindex]++;
4977 p->activescbs--;
4978 scbq_remove(&p->delayed_scbs[tindex], next_scbp);
4979 scbq_remove(&p->waiting_scbs, next_scbp);
4981 scbq_insert_head(&p->delayed_scbs[tindex],
4982 next_scbp);
4983 next_scbp->flags |= SCB_WAITINGQ;
4984 p->dev_active_cmds[tindex]--;
4985 p->activescbs--;
4986 next_hscb = aic_inb(p, SCB_NEXT);
4987 aic_outb(p, 0, SCB_CONTROL);
4988 aic_outb(p, SCB_LIST_NULL, SCB_TAG);
4989 aic7xxx_add_curscb_to_free_list(p);
4990 if (prev_hscb == SCB_LIST_NULL)
4992 /* We were first on the list,
4993 * so we kill the selection
4994 * hardware. Let the sequencer
4995 * re-init the hardware itself
4997 aic_outb(p, aic_inb(p, SCSISEQ) & ~ENSELO, SCSISEQ);
4998 aic_outb(p, CLRSELTIMEO, CLRSINT1);
4999 aic_outb(p, next_hscb, WAITING_SCBH);
5001 else
5003 aic_outb(p, prev_hscb, SCBPTR);
5004 aic_outb(p, next_hscb, SCB_NEXT);
5007 else
5009 prev_hscb = next_hscb;
5010 next_hscb = aic_inb(p, SCB_NEXT);
5012 } /* scb_index >= p->scb_data->numscbs */
5014 aic_outb(p, active_hscb, SCBPTR);
5015 if (scb->flags & SCB_WAITINGQ)
5017 scbq_remove(&p->delayed_scbs[tindex], scb);
5018 scbq_remove(&p->waiting_scbs, scb);
5019 p->dev_active_cmds[tindex]++;
5020 p->activescbs++;
5022 scbq_insert_head(&p->delayed_scbs[tindex], scb);
5023 p->dev_active_cmds[tindex]--;
5024 p->activescbs--;
5025 scb->flags |= SCB_WAITINGQ | SCB_WAS_BUSY;
5027 if ( !(p->dev_timer_active & (0x01 << tindex)) )
5029 p->dev_timer_active |= (0x01 << tindex);
5030 if ( p->dev_active_cmds[tindex] )
5032 p->dev_expires[tindex] = jiffies + HZ;
5034 else
5036 p->dev_expires[tindex] = jiffies + (HZ / 10);
5038 if ( !(p->dev_timer_active & (0x01 << MAX_TARGETS)) )
5040 p->dev_timer.expires = p->dev_expires[tindex];
5041 p->dev_timer_active |= (0x01 << MAX_TARGETS);
5042 add_timer(&p->dev_timer);
5044 else if ( time_after_eq(p->dev_timer.expires,
5045 p->dev_expires[tindex]) )
5046 mod_timer(&p->dev_timer, p->dev_expires[tindex]);
5048 #ifdef AIC7XXX_VERBOSE_DEBUGGING
5049 if( (aic7xxx_verbose & VERBOSE_MINOR_ERROR) ||
5050 (aic7xxx_verbose > 0xffff) )
5052 if (queue_flag)
5053 printk(INFO_LEAD "Queue full received; queue depth %d, "
5054 "active %d\n", p->host_no, CTL_OF_SCB(scb),
5055 p->dev_max_queue_depth[tindex],
5056 p->dev_active_cmds[tindex]);
5057 else
5058 printk(INFO_LEAD "Target busy\n", p->host_no, CTL_OF_SCB(scb));
5061 #endif
5062 if (queue_flag)
5064 if ( p->dev_last_queue_full[tindex] !=
5065 p->dev_active_cmds[tindex] )
5067 p->dev_last_queue_full[tindex] =
5068 p->dev_active_cmds[tindex];
5069 p->dev_last_queue_full_count[tindex] = 0;
5071 else
5073 p->dev_last_queue_full_count[tindex]++;
5075 if ( (p->dev_last_queue_full_count[tindex] > 14) &&
5076 (p->dev_active_cmds[tindex] > 4) )
5078 if (aic7xxx_verbose & VERBOSE_NEGOTIATION2)
5079 printk(INFO_LEAD "Queue depth reduced to %d\n", p->host_no,
5080 CTL_OF_SCB(scb), p->dev_active_cmds[tindex]);
5081 p->dev_max_queue_depth[tindex] =
5082 p->dev_active_cmds[tindex];
5083 p->dev_last_queue_full[tindex] = 0;
5084 p->dev_last_queue_full_count[tindex] = 0;
5085 p->dev_temp_queue_depth[tindex] =
5086 p->dev_active_cmds[tindex];
5088 else if (p->dev_active_cmds[tindex] == 0)
5090 if (aic7xxx_verbose & VERBOSE_NEGOTIATION)
5092 printk(INFO_LEAD "QUEUE_FULL status received with 0 "
5093 "commands active.\n", p->host_no, CTL_OF_SCB(scb));
5094 printk(INFO_LEAD "Tagged Command Queueing disabled\n",
5095 p->host_no, CTL_OF_SCB(scb));
5097 p->dev_max_queue_depth[tindex] = 1;
5098 p->dev_temp_queue_depth[tindex] = 1;
5099 scb->tag_action = 0;
5100 scb->hscb->control &= ~(MSG_ORDERED_Q_TAG|MSG_SIMPLE_Q_TAG);
5102 else
5104 p->dev_flags[tindex] |= DEVICE_WAS_BUSY;
5105 p->dev_temp_queue_depth[tindex] =
5106 p->dev_active_cmds[tindex];
5109 break;
5112 default:
5113 if (aic7xxx_verbose & VERBOSE_SEQINT)
5114 printk(INFO_LEAD "Unexpected target status 0x%x.\n", p->host_no,
5115 CTL_OF_SCB(scb), scb->hscb->target_status);
5116 if (!aic7xxx_error(cmd))
5118 aic7xxx_error(cmd) = DID_RETRY_COMMAND;
5120 break;
5121 } /* end switch */
5122 } /* end else of */
5124 break;
5126 case AWAITING_MSG:
5128 unsigned char scb_index, msg_out;
5130 scb_index = aic_inb(p, SCB_TAG);
5131 msg_out = aic_inb(p, MSG_OUT);
5132 scb = p->scb_data->scb_array[scb_index];
5133 p->msg_index = p->msg_len = 0;
5135 * This SCB had a MK_MESSAGE set in its control byte informing
5136 * the sequencer that we wanted to send a special message to
5137 * this target.
5140 if ( !(scb->flags & SCB_DEVICE_RESET) &&
5141 (msg_out == MSG_IDENTIFYFLAG) &&
5142 (scb->hscb->control & TAG_ENB) )
5144 p->msg_buf[p->msg_index++] = scb->tag_action;
5145 p->msg_buf[p->msg_index++] = scb->hscb->tag;
5146 p->msg_len += 2;
5149 if (scb->flags & SCB_DEVICE_RESET)
5151 p->msg_buf[p->msg_index++] = MSG_BUS_DEV_RESET;
5152 p->msg_len++;
5153 if (aic7xxx_verbose & VERBOSE_RESET_PROCESS)
5154 printk(INFO_LEAD "Bus device reset mailed.\n",
5155 p->host_no, CTL_OF_SCB(scb));
5157 else if (scb->flags & SCB_ABORT)
5159 if (scb->tag_action)
5161 p->msg_buf[p->msg_index++] = MSG_ABORT_TAG;
5163 else
5165 p->msg_buf[p->msg_index++] = MSG_ABORT;
5167 p->msg_len++;
5168 if (aic7xxx_verbose & VERBOSE_ABORT_PROCESS)
5169 printk(INFO_LEAD "Abort message mailed.\n", p->host_no,
5170 CTL_OF_SCB(scb));
5172 else if (scb->flags & SCB_MSGOUT_PPR)
5174 unsigned int max_sync, period;
5175 unsigned char options = 0;
5177 if (p->features & AHC_ULTRA2)
5179 if ( (aic_inb(p, SBLKCTL) & ENAB40) &&
5180 !(aic_inb(p, SSTAT2) & EXP_ACTIVE) )
5182 if( (p->features & AHC_ULTRA3) &&
5183 (p->dev_flags[tindex] & DEVICE_SCSI_3) &&
5184 (p->transinfo[tindex].goal_width ==
5185 MSG_EXT_WDTR_BUS_16_BIT) &&
5186 (p->transinfo[tindex].goal_options != 0) )
5188 max_sync = AHC_SYNCRATE_ULTRA3;
5189 options = p->transinfo[tindex].goal_options;
5191 else
5193 max_sync = AHC_SYNCRATE_ULTRA2;
5196 else
5198 max_sync = AHC_SYNCRATE_ULTRA;
5201 else if (p->features & AHC_ULTRA)
5203 max_sync = AHC_SYNCRATE_ULTRA;
5205 else
5207 max_sync = AHC_SYNCRATE_FAST;
5209 period = p->transinfo[tindex].goal_period;
5210 aic7xxx_find_syncrate(p, &period, max_sync, &options);
5211 p->transinfo[tindex].goal_period = period;
5212 p->transinfo[tindex].goal_options = options;
5213 if (aic7xxx_verbose & VERBOSE_NEGOTIATION2)
5215 printk(INFO_LEAD "Sending PPR (%d/%d/%d/%d) message.\n",
5216 p->host_no, CTL_OF_SCB(scb), period,
5217 p->transinfo[tindex].goal_offset,
5218 p->transinfo[tindex].goal_width, options);
5220 aic7xxx_construct_ppr(p, scb);
5222 else if (scb->flags & SCB_MSGOUT_WDTR)
5224 if (aic7xxx_verbose & VERBOSE_NEGOTIATION2)
5226 printk(INFO_LEAD "Sending WDTR message.\n", p->host_no,
5227 CTL_OF_SCB(scb));
5229 aic7xxx_construct_wdtr(p, p->transinfo[tindex].goal_width);
5231 else if (scb->flags & SCB_MSGOUT_SDTR)
5233 unsigned int max_sync, period;
5234 unsigned char options = 0;
5236 * Now that the device is selected, use the bits in SBLKCTL and
5237 * SSTAT2 to determine the max sync rate for this device.
5239 if (p->features & AHC_ULTRA2)
5241 if ( (aic_inb(p, SBLKCTL) & ENAB40) &&
5242 !(aic_inb(p, SSTAT2) & EXP_ACTIVE) )
5244 max_sync = AHC_SYNCRATE_ULTRA2;
5246 else
5248 max_sync = AHC_SYNCRATE_ULTRA;
5251 else if (p->features & AHC_ULTRA)
5253 max_sync = AHC_SYNCRATE_ULTRA;
5255 else
5257 max_sync = AHC_SYNCRATE_FAST;
5259 period = p->transinfo[tindex].goal_period;
5260 aic7xxx_find_syncrate(p, &period, max_sync, &options);
5261 if (aic7xxx_verbose & VERBOSE_NEGOTIATION2)
5263 printk(INFO_LEAD "Sending SDTR %d/%d message.\n", p->host_no,
5264 CTL_OF_SCB(scb),
5265 p->transinfo[tindex].goal_period,
5266 p->transinfo[tindex].goal_offset);
5268 aic7xxx_construct_sdtr(p, period,
5269 p->transinfo[tindex].goal_offset);
5271 else
5273 sti();
5274 panic("aic7xxx: AWAITING_MSG for an SCB that does "
5275 "not have a waiting message.\n");
5278 * We've set everything up to send our message, now to actually do
5279 * so we need to enable reqinit interrupts and let the interrupt
5280 * handler do the rest. We don't want to unpause the sequencer yet
5281 * though so we'll return early. We also have to make sure that
5282 * we clear the SEQINT *BEFORE* we set the REQINIT handler active
5283 * or else it's possible on VLB cards to loose the first REQINIT
5284 * interrupt. Edge triggered EISA cards could also loose this
5285 * interrupt, although PCI and level triggered cards should not
5286 * have this problem since they continually interrupt the kernel
5287 * until we take care of the situation.
5289 scb->flags |= SCB_MSGOUT_SENT;
5290 p->msg_index = 0;
5291 p->msg_type = MSG_TYPE_INITIATOR_MSGOUT;
5292 p->flags |= AHC_HANDLING_REQINITS;
5293 aic_outb(p, aic_inb(p, SIMODE1) | ENREQINIT, SIMODE1);
5294 return;
5296 break;
5298 case DATA_OVERRUN:
5300 unsigned char scb_index = aic_inb(p, SCB_TAG);
5301 unsigned char lastphase = aic_inb(p, LASTPHASE);
5302 unsigned int i;
5304 scb = (p->scb_data->scb_array[scb_index]);
5306 * XXX - What do we really want to do on an overrun? The
5307 * mid-level SCSI code should handle this, but for now,
5308 * we'll just indicate that the command should retried.
5309 * If we retrieved sense info on this target, then the
5310 * base SENSE info should have been saved prior to the
5311 * overrun error. In that case, we return DID_OK and let
5312 * the mid level code pick up on the sense info. Otherwise
5313 * we return DID_ERROR so the command will get retried.
5315 if ( !(scb->flags & SCB_SENSE) )
5317 printk(WARN_LEAD "Data overrun detected in %s phase, tag %d;\n",
5318 p->host_no, CTL_OF_SCB(scb),
5319 (lastphase == P_DATAIN) ? "Data-In" : "Data-Out", scb->hscb->tag);
5320 printk(KERN_WARNING " %s seen Data Phase. Length=%d, NumSGs=%d.\n",
5321 (aic_inb(p, SEQ_FLAGS) & DPHASE) ? "Have" : "Haven't",
5322 scb->sg_length, scb->sg_count);
5323 for (i = 0; i < scb->sg_count; i++)
5325 printk(KERN_WARNING " sg[%d] - Addr 0x%x : Length %d\n",
5327 le32_to_cpu(scb->sg_list[i].address),
5328 le32_to_cpu(scb->sg_list[i].length) );
5330 aic7xxx_error(scb->cmd) = DID_ERROR;
5332 else
5333 printk(INFO_LEAD "Data Overrun during SEND_SENSE operation.\n",
5334 p->host_no, CTL_OF_SCB(scb));
5336 break;
5338 case WIDE_RESIDUE:
5340 unsigned char resid_sgcnt, index;
5341 unsigned char scb_index = aic_inb(p, SCB_TAG);
5342 unsigned int cur_addr, resid_dcnt;
5343 unsigned int native_addr, native_length;
5344 int i;
5346 if(scb_index > p->scb_data->numscbs)
5348 printk(WARN_LEAD "invalid scb_index during WIDE_RESIDUE.\n",
5349 p->host_no, -1, -1, -1);
5351 * XXX: Add error handling here
5353 break;
5355 scb = p->scb_data->scb_array[scb_index];
5356 if(!(scb->flags & SCB_ACTIVE) || (scb->cmd == NULL))
5358 printk(WARN_LEAD "invalid scb during WIDE_RESIDUE flags:0x%x "
5359 "scb->cmd:0x%lx\n", p->host_no, CTL_OF_SCB(scb),
5360 scb->flags, (unsigned long)scb->cmd);
5361 break;
5365 * We have a valid scb to use on this WIDE_RESIDUE message, so
5366 * we need to walk the sg list looking for this particular sg
5367 * segment, then see if we happen to be at the very beginning of
5368 * the segment. If we are, then we have to back things up to
5369 * the previous segment. If not, then we simply need to remove
5370 * one byte from this segments address and add one to the byte
5371 * count.
5373 cur_addr = aic_inb(p, SHADDR) | (aic_inb(p, SHADDR + 1) << 8) |
5374 (aic_inb(p, SHADDR + 2) << 16) | (aic_inb(p, SHADDR + 3) << 24);
5375 resid_sgcnt = aic_inb(p, SCB_RESID_SGCNT);
5376 resid_dcnt = aic_inb(p, SCB_RESID_DCNT) |
5377 (aic_inb(p, SCB_RESID_DCNT + 1) << 8) |
5378 (aic_inb(p, SCB_RESID_DCNT + 2) << 24);
5379 index = scb->sg_count - resid_sgcnt;
5380 native_addr = le32_to_cpu(scb->sg_list[index].address);
5381 native_length = le32_to_cpu(scb->sg_list[index].length);
5383 * Make sure this is a valid sg_seg for the given pointer
5385 if(cur_addr < native_addr ||
5386 cur_addr > (native_addr + native_length))
5388 printk(WARN_LEAD "invalid cur_addr:0x%x during WIDE_RESIDUE\n",
5389 p->host_no, CTL_OF_SCB(scb), cur_addr);
5390 if(index > 0)
5391 printk(WARN_LEAD " sg_address[-1]:0x%x sg_length[-1]:%d\n",
5392 p->host_no, CTL_OF_SCB(scb),
5393 le32_to_cpu(scb->sg_list[index - 1].address),
5394 le32_to_cpu(scb->sg_list[index - 1].length));
5395 printk(WARN_LEAD " sg_address:0x%x sg_length:%d\n",
5396 p->host_no, CTL_OF_SCB(scb),
5397 native_addr, native_length);
5398 if(resid_sgcnt > 1)
5399 printk(WARN_LEAD " sg_address[1]:0x%x sg_length[1]:%d\n",
5400 p->host_no, CTL_OF_SCB(scb),
5401 le32_to_cpu(scb->sg_list[index + 1].address),
5402 le32_to_cpu(scb->sg_list[index + 1].length));
5403 break;
5407 * If our current address matches the sg_seg->address then we
5408 * have to back up the sg array to the previous segment and set
5409 * it up to have only one byte of transfer left to go.
5411 if(cur_addr == native_addr)
5413 if(index == 0)
5415 printk(WARN_LEAD "bogus WIDE_RESIDUE message, no data has been "
5416 "transferred.\n", p->host_no, CTL_OF_SCB(scb));
5417 break;
5419 resid_sgcnt++;
5420 index--;
5421 cur_addr = le32_to_cpu(scb->sg_list[index].address) +
5422 le32_to_cpu(scb->sg_list[index].length) - 1;
5423 native_addr = aic_inb(p, SG_NEXT) | (aic_inb(p, SG_NEXT + 1) << 8)
5424 | (aic_inb(p, SG_NEXT + 2) << 16) | (aic_inb(p, SG_NEXT + 3) << 24);
5425 native_addr -= SG_SIZEOF;
5426 aic_outb(p, resid_sgcnt, SG_COUNT);
5427 aic_outb(p, resid_sgcnt, SCB_RESID_SGCNT);
5428 aic_outb(p, native_addr & 0xff, SG_NEXT);
5429 aic_outb(p, (native_addr >> 8) & 0xff, SG_NEXT + 1);
5430 aic_outb(p, (native_addr >> 16) & 0xff, SG_NEXT + 2);
5431 aic_outb(p, (native_addr >> 24) & 0xff, SG_NEXT + 3);
5432 aic_outb(p, 1, SCB_RESID_DCNT);
5433 aic_outb(p, 0, SCB_RESID_DCNT + 1);
5434 aic_outb(p, 0, SCB_RESID_DCNT + 2);
5435 aic_outb(p, 1, HCNT);
5436 aic_outb(p, 0, HCNT + 1);
5437 aic_outb(p, 0, HCNT + 2);
5438 aic_outb(p, cur_addr & 0xff, HADDR);
5439 aic_outb(p, (cur_addr >> 8) & 0xff, HADDR + 1);
5440 aic_outb(p, (cur_addr >> 16) & 0xff, HADDR + 2);
5441 aic_outb(p, (cur_addr >> 24) & 0xff, HADDR + 3);
5443 * The sequencer actually wants to find the new address and byte
5444 * count in the SHCNT and SHADDR register sets. These registers
5445 * are a shadow of the regular HCNT and HADDR registers. On the
5446 * Ultra2 controllers, these registers are read only and the way
5447 * we have to set their values is to put the values we want into
5448 * the HCNT and HADDR registers and then output PRELOADEN into
5449 * the DFCNTRL register which causes the card to latch the current
5450 * values in the HADDR and HCNT registers and drop it through to
5451 * the shadow registers. On older cards we copy them directly
5452 * across by hand.
5454 if(p->features & AHC_ULTRA2)
5456 aic_outb(p, aic_inb(p, DMAPARAMS), DFCNTRL);
5457 i=0;
5458 udelay(1);
5459 while(((aic_inb(p, SSTAT0) & SDONE) != 0) && (i++ < 1000))
5461 aic_outb(p, aic_inb(p, DMAPARAMS), DFCNTRL);
5462 udelay(1);
5465 else
5467 aic_outb(p, 1, STCNT);
5468 aic_outb(p, 0, STCNT + 1);
5469 aic_outb(p, 0, STCNT + 2);
5470 aic_outb(p, cur_addr & 0xff, SHADDR);
5471 aic_outb(p, (cur_addr >> 8) & 0xff, SHADDR + 1);
5472 aic_outb(p, (cur_addr >> 16) & 0xff, SHADDR + 2);
5473 aic_outb(p, (cur_addr >> 24) & 0xff, SHADDR + 3);
5476 else
5479 * Back the data pointer up by one and add one to the remaining
5480 * byte count. Then store that in the HCNT and HADDR registers.
5482 cur_addr--;
5483 resid_dcnt++;
5484 aic_outb(p, resid_dcnt & 0xff, SCB_RESID_DCNT);
5485 aic_outb(p, (resid_dcnt >> 8) & 0xff, SCB_RESID_DCNT + 1);
5486 aic_outb(p, (resid_dcnt >> 16) & 0xff, SCB_RESID_DCNT + 2);
5487 aic_outb(p, resid_dcnt & 0xff, HCNT);
5488 aic_outb(p, (resid_dcnt >> 8) & 0xff, HCNT + 1);
5489 aic_outb(p, (resid_dcnt >> 16) & 0xff, HCNT + 2);
5490 aic_outb(p, cur_addr & 0xff, HADDR);
5491 aic_outb(p, (cur_addr >> 8) & 0xff, HADDR + 1);
5492 aic_outb(p, (cur_addr >> 16) & 0xff, HADDR + 2);
5493 aic_outb(p, (cur_addr >> 24) & 0xff, HADDR + 3);
5494 if(p->features & AHC_ULTRA2)
5496 aic_outb(p, aic_inb(p, DMAPARAMS), DFCNTRL);
5497 i=0;
5498 udelay(1);
5499 while(((aic_inb(p, SSTAT0) & SDONE) != 0) && (i++ < 1000))
5501 aic_outb(p, aic_inb(p, DMAPARAMS), DFCNTRL);
5502 udelay(1);
5505 else
5507 aic_outb(p, resid_dcnt & 0xff, STCNT);
5508 aic_outb(p, (resid_dcnt >> 8) & 0xff, STCNT + 1);
5509 aic_outb(p, (resid_dcnt >> 16) & 0xff, STCNT + 2);
5510 aic_outb(p, cur_addr & 0xff, SHADDR);
5511 aic_outb(p, (cur_addr >> 8) & 0xff, SHADDR + 1);
5512 aic_outb(p, (cur_addr >> 16) & 0xff, SHADDR + 2);
5513 aic_outb(p, (cur_addr >> 24) & 0xff, SHADDR + 3);
5517 break;
5520 #if AIC7XXX_NOT_YET
5521 case TRACEPOINT:
5523 printk(INFO_LEAD "Tracepoint #1 reached.\n", p->host_no,
5524 channel, target, lun);
5526 break;
5528 case TRACEPOINT2:
5530 printk(INFO_LEAD "Tracepoint #2 reached.\n", p->host_no,
5531 channel, target, lun);
5533 break;
5535 /* XXX Fill these in later */
5536 case MSG_BUFFER_BUSY:
5537 printk("aic7xxx: Message buffer busy.\n");
5538 break;
5539 case MSGIN_PHASEMIS:
5540 printk("aic7xxx: Message-in phasemis.\n");
5541 break;
5542 #endif
5544 default: /* unknown */
5545 printk(WARN_LEAD "Unknown SEQINT, INTSTAT 0x%x, SCSISIGI 0x%x.\n",
5546 p->host_no, channel, target, lun, intstat,
5547 aic_inb(p, SCSISIGI));
5548 break;
5552 * Clear the sequencer interrupt and unpause the sequencer.
5554 unpause_sequencer(p, /* unpause always */ TRUE);
5557 /*+F*************************************************************************
5558 * Function:
5559 * aic7xxx_parse_msg
5561 * Description:
5562 * Parses incoming messages into actions on behalf of
5563 * aic7xxx_handle_reqinit
5564 *_F*************************************************************************/
5565 static int
5566 aic7xxx_parse_msg(struct aic7xxx_host *p, struct aic7xxx_scb *scb)
5568 int reject, reply, done;
5569 unsigned char target_scsirate, tindex;
5570 unsigned short target_mask;
5571 unsigned char target, channel, lun;
5573 target = scb->cmd->target;
5574 channel = scb->cmd->channel;
5575 lun = scb->cmd->lun;
5576 reply = reject = done = FALSE;
5577 tindex = TARGET_INDEX(scb->cmd);
5578 target_scsirate = aic_inb(p, TARG_SCSIRATE + tindex);
5579 target_mask = (0x01 << tindex);
5582 * Parse as much of the message as is availible,
5583 * rejecting it if we don't support it. When
5584 * the entire message is availible and has been
5585 * handled, return TRUE indicating that we have
5586 * parsed an entire message.
5589 if (p->msg_buf[0] != MSG_EXTENDED)
5591 reject = TRUE;
5595 * Just accept the length byte outright and perform
5596 * more checking once we know the message type.
5599 if ( !reject && (p->msg_len > 2) )
5601 switch(p->msg_buf[2])
5603 case MSG_EXT_SDTR:
5605 unsigned int period, offset;
5606 unsigned char maxsync, saved_offset, options;
5607 struct aic7xxx_syncrate *syncrate;
5609 if (p->msg_buf[1] != MSG_EXT_SDTR_LEN)
5611 reject = TRUE;
5612 break;
5615 if (p->msg_len < (MSG_EXT_SDTR_LEN + 2))
5617 break;
5620 period = p->msg_buf[3];
5621 saved_offset = offset = p->msg_buf[4];
5622 options = 0;
5625 * Even if we are an Ultra3 card, don't allow Ultra3 sync rates when
5626 * using the SDTR messages. We need the PPR messages to enable the
5627 * higher speeds that include things like Dual Edge clocking.
5629 if (p->features & AHC_ULTRA2)
5631 if ( (aic_inb(p, SBLKCTL) & ENAB40) &&
5632 !(aic_inb(p, SSTAT2) & EXP_ACTIVE) )
5634 maxsync = AHC_SYNCRATE_ULTRA2;
5636 else
5638 maxsync = AHC_SYNCRATE_ULTRA;
5641 else if (p->features & AHC_ULTRA)
5643 maxsync = AHC_SYNCRATE_ULTRA;
5645 else
5647 maxsync = AHC_SYNCRATE_FAST;
5650 * We might have a device that is starting negotiation with us
5651 * before we can start up negotiation with it....be prepared to
5652 * have a device ask for a higher speed then we want to give it
5653 * in that case
5655 if ( (scb->flags & (SCB_MSGOUT_SENT|SCB_MSGOUT_SDTR)) !=
5656 (SCB_MSGOUT_SENT|SCB_MSGOUT_SDTR) )
5658 if (!(p->dev_flags[tindex] & DEVICE_SCANNED) &&
5659 !(p->needsdtr_copy & target_mask) &&
5660 (p->transinfo[tindex].user_offset) )
5663 * Not only is the device starting this up, but it also hasn't
5664 * been scanned yet, so this would likely be our TUR or our
5665 * INQUIRY command at scan time, so we need to use the
5666 * settings from the SEEPROM if they existed. Of course, even
5667 * if we didn't find a SEEPROM, we stuffed default values into
5668 * the user settings anyway, so use those in all cases.
5670 p->transinfo[tindex].goal_period =
5671 p->transinfo[tindex].user_period;
5672 if(p->features & AHC_ULTRA2)
5674 p->transinfo[tindex].goal_offset = MAX_OFFSET_ULTRA2;
5676 else if (p->transinfo[tindex].cur_width)
5678 p->transinfo[tindex].goal_offset = MAX_OFFSET_16BIT;
5680 else
5682 p->transinfo[tindex].goal_offset = MAX_OFFSET_8BIT;
5684 p->needsdtr_copy |= target_mask;
5686 if (aic7xxx_verbose & VERBOSE_NEGOTIATION2)
5688 printk(INFO_LEAD "Received pre-emptive SDTR message from "
5689 "target.\n", p->host_no, CTL_OF_SCB(scb));
5691 if ( !p->transinfo[tindex].goal_offset )
5692 period = 255;
5693 if ( p->transinfo[tindex].goal_period > period )
5694 period = p->transinfo[tindex].goal_period;
5697 syncrate = aic7xxx_find_syncrate(p, &period, maxsync, &options);
5698 aic7xxx_validate_offset(p, syncrate, &offset,
5699 target_scsirate & WIDEXFER);
5700 aic7xxx_set_syncrate(p, syncrate, target, channel, period,
5701 offset, options, AHC_TRANS_ACTIVE|AHC_TRANS_CUR);
5704 * Did we drop to async? Or are we sending a reply? If we are,
5705 * then we have to make sure that the reply value reflects the proper
5706 * settings so we need to set the goal values according to what
5707 * we need to send.
5709 if ( (offset != saved_offset) ||
5710 ((scb->flags & (SCB_MSGOUT_SENT|SCB_MSGOUT_SDTR)) !=
5711 (SCB_MSGOUT_SENT|SCB_MSGOUT_SDTR) ) )
5713 aic7xxx_set_syncrate(p, syncrate, target, channel, period, offset,
5714 options, AHC_TRANS_GOAL|AHC_TRANS_QUITE);
5718 * Did we start this, if not, or if we went to low and had to
5719 * go async, then send an SDTR back to the target
5721 p->needsdtr &= ~target_mask;
5722 p->dtr_pending &= ~target_mask;
5723 if ( ((scb->flags & (SCB_MSGOUT_SENT|SCB_MSGOUT_SDTR)) !=
5724 (SCB_MSGOUT_SENT|SCB_MSGOUT_SDTR)) ||
5725 (offset != saved_offset) )
5727 reply = TRUE;
5728 p->dtr_pending |= target_mask;
5729 scb->flags &= ~SCB_MSGOUT_BITS;
5730 scb->flags |= SCB_MSGOUT_SDTR;
5731 aic_outb(p, HOST_MSG, MSG_OUT);
5732 aic_outb(p, aic_inb(p, SCSISIGO) | ATNO, SCSISIGO);
5734 done = TRUE;
5735 break;
5737 case MSG_EXT_WDTR:
5739 unsigned char bus_width;
5741 if (p->msg_buf[1] != MSG_EXT_WDTR_LEN)
5743 reject = TRUE;
5744 break;
5747 if (p->msg_len < (MSG_EXT_WDTR_LEN + 2))
5749 break;
5752 bus_width = p->msg_buf[3];
5753 if ( (scb->flags & (SCB_MSGOUT_SENT|SCB_MSGOUT_WDTR)) ==
5754 (SCB_MSGOUT_SENT|SCB_MSGOUT_WDTR) )
5756 switch(bus_width)
5758 default:
5760 reject = TRUE;
5761 if ( (aic7xxx_verbose & VERBOSE_NEGOTIATION2) &&
5762 ((p->dev_flags[tindex] & DEVICE_PRINT_DTR) ||
5763 (aic7xxx_verbose > 0xffff)) )
5765 printk(INFO_LEAD "Requesting %d bit transfers, rejecting.\n",
5766 p->host_no, CTL_OF_SCB(scb), 8 * (0x01 << bus_width));
5768 } /* We fall through on purpose */
5769 case MSG_EXT_WDTR_BUS_8_BIT:
5771 bus_width = MSG_EXT_WDTR_BUS_8_BIT;
5772 p->needwdtr_copy &= ~target_mask;
5773 break;
5775 case MSG_EXT_WDTR_BUS_16_BIT:
5777 break;
5780 p->dtr_pending &= ~target_mask;
5781 p->needwdtr &= ~target_mask;
5783 else
5785 if ( !(p->dev_flags[tindex] & DEVICE_SCANNED) )
5788 * Well, we now know the WDTR and SYNC caps of this device since
5789 * it contacted us first, mark it as such and copy the user stuff
5790 * over to the goal stuff.
5792 p->transinfo[tindex].goal_period =
5793 p->transinfo[tindex].user_period;
5794 if(p->transinfo[tindex].user_offset)
5796 if(p->features & AHC_ULTRA2)
5798 p->transinfo[tindex].goal_offset = MAX_OFFSET_ULTRA2;
5800 else if( p->transinfo[tindex].user_width &&
5801 (bus_width == MSG_EXT_WDTR_BUS_16_BIT) &&
5802 p->features & AHC_WIDE )
5804 p->transinfo[tindex].goal_offset = MAX_OFFSET_16BIT;
5806 else
5808 p->transinfo[tindex].goal_offset = MAX_OFFSET_8BIT;
5811 p->transinfo[tindex].goal_width =
5812 p->transinfo[tindex].user_width;
5813 p->needwdtr_copy |= target_mask;
5814 p->needsdtr_copy |= target_mask;
5816 if (aic7xxx_verbose & VERBOSE_NEGOTIATION2)
5818 printk(INFO_LEAD "Received pre-emptive WDTR message from "
5819 "target.\n", p->host_no, CTL_OF_SCB(scb));
5821 switch(bus_width)
5823 default:
5825 if ( (p->features & AHC_WIDE) &&
5826 (p->transinfo[tindex].goal_width ==
5827 MSG_EXT_WDTR_BUS_16_BIT) )
5829 bus_width = MSG_EXT_WDTR_BUS_16_BIT;
5830 break;
5832 } /* Fall through if we aren't a wide card */
5833 case MSG_EXT_WDTR_BUS_8_BIT:
5835 p->needwdtr_copy &= ~target_mask;
5836 bus_width = MSG_EXT_WDTR_BUS_8_BIT;
5837 aic7xxx_set_width(p, target, channel, lun, bus_width,
5838 AHC_TRANS_GOAL|AHC_TRANS_QUITE);
5839 break;
5842 reply = TRUE;
5843 scb->flags &= ~SCB_MSGOUT_BITS;
5844 scb->flags |= SCB_MSGOUT_WDTR;
5845 p->needwdtr &= ~target_mask;
5846 p->dtr_pending |= target_mask;
5847 aic_outb(p, HOST_MSG, MSG_OUT);
5848 aic_outb(p, aic_inb(p, SCSISIGO) | ATNO, SCSISIGO);
5850 aic7xxx_set_width(p, target, channel, lun, bus_width,
5851 AHC_TRANS_ACTIVE|AHC_TRANS_CUR);
5854 * By virtue of the SCSI spec, a WDTR message negates any existing
5855 * SDTR negotiations. So, even if needsdtr isn't marked for this
5856 * device, we still have to do a new SDTR message if the device
5857 * supports SDTR at all. Therefore, we check needsdtr_copy instead
5858 * of needstr.
5860 aic7xxx_set_syncrate(p, NULL, target, channel, 0, 0, 0,
5861 AHC_TRANS_ACTIVE|AHC_TRANS_CUR|AHC_TRANS_QUITE);
5862 p->needsdtr |= (p->needsdtr_copy & target_mask);
5863 done = TRUE;
5864 break;
5866 case MSG_EXT_PPR:
5868 unsigned char bus_width, trans_options, new_trans_options;
5869 unsigned int period, offset;
5870 unsigned char maxsync, saved_offset;
5871 struct aic7xxx_syncrate *syncrate;
5873 if (p->msg_buf[1] != MSG_EXT_PPR_LEN)
5875 reject = TRUE;
5876 break;
5879 if (p->msg_len < (MSG_EXT_PPR_LEN + 2))
5881 break;
5884 period = p->msg_buf[3];
5885 offset = saved_offset = p->msg_buf[5];
5886 bus_width = p->msg_buf[6];
5887 trans_options = new_trans_options = p->msg_buf[7] & 0xf;
5889 if(aic7xxx_verbose & VERBOSE_NEGOTIATION2)
5891 printk(INFO_LEAD "Parsing PPR message (%d/%d/%d/%d)\n",
5892 p->host_no, CTL_OF_SCB(scb), period, offset, bus_width,
5893 trans_options);
5896 if ( (aic_inb(p, SBLKCTL) & ENAB40) &&
5897 !(aic_inb(p, SSTAT2) & EXP_ACTIVE) )
5899 if(p->features & AHC_ULTRA3)
5901 maxsync = AHC_SYNCRATE_ULTRA3;
5903 else
5905 maxsync = AHC_SYNCRATE_ULTRA2;
5908 else
5910 maxsync = AHC_SYNCRATE_ULTRA;
5913 * We might have a device that is starting negotiation with us
5914 * before we can start up negotiation with it....be prepared to
5915 * have a device ask for a higher speed then we want to give it
5916 * in that case
5918 if ( (scb->flags & (SCB_MSGOUT_SENT|SCB_MSGOUT_PPR)) !=
5919 (SCB_MSGOUT_SENT|SCB_MSGOUT_PPR) )
5921 reply = TRUE;
5922 scb->flags &= ~SCB_MSGOUT_BITS;
5923 scb->flags |= SCB_MSGOUT_PPR;
5924 if (!(p->dev_flags[tindex] & DEVICE_SCANNED))
5927 * Not only is the device starting this up, but it also hasn't
5928 * been scanned yet, so this would likely be our TUR or our
5929 * INQUIRY command at scan time, so we need to use the
5930 * settings from the SEEPROM if they existed. Of course, even
5931 * if we didn't find a SEEPROM, we stuffed default values into
5932 * the user settings anyway, so use those in all cases.
5934 p->transinfo[tindex].goal_period =
5935 p->transinfo[tindex].user_period;
5936 if(p->transinfo[tindex].user_offset)
5938 if(p->features & AHC_ULTRA2)
5940 p->transinfo[tindex].goal_offset = MAX_OFFSET_ULTRA2;
5942 else if( p->transinfo[tindex].user_width &&
5943 (bus_width == MSG_EXT_WDTR_BUS_16_BIT) &&
5944 p->features & AHC_WIDE )
5946 p->transinfo[tindex].goal_offset = MAX_OFFSET_16BIT;
5948 else
5950 p->transinfo[tindex].goal_offset = MAX_OFFSET_8BIT;
5953 p->transinfo[tindex].goal_width =
5954 p->transinfo[tindex].user_width;
5955 p->transinfo[tindex].goal_options =
5956 p->transinfo[tindex].user_options;
5957 p->needppr_copy |= target_mask;
5959 if (aic7xxx_verbose & VERBOSE_NEGOTIATION2)
5961 printk(INFO_LEAD "Received pre-emptive PPR message from "
5962 "target.\n", p->host_no, CTL_OF_SCB(scb));
5964 if ( !p->transinfo[tindex].goal_offset )
5965 period = 255;
5966 if ( p->transinfo[tindex].goal_period > period )
5967 period = p->transinfo[tindex].goal_period;
5968 if ( p->transinfo[tindex].goal_options == 0 )
5969 new_trans_options = 0;
5970 switch(bus_width)
5972 default:
5974 if ( (p->features & AHC_WIDE) &&
5975 (p->transinfo[tindex].goal_width ==
5976 MSG_EXT_WDTR_BUS_16_BIT) )
5978 bus_width = MSG_EXT_WDTR_BUS_16_BIT;
5979 break;
5981 } /* Fall through if we aren't a wide card */
5982 case MSG_EXT_WDTR_BUS_8_BIT:
5984 p->needwdtr_copy &= ~target_mask;
5985 bus_width = MSG_EXT_WDTR_BUS_8_BIT;
5986 aic7xxx_set_width(p, target, channel, lun, bus_width,
5987 AHC_TRANS_GOAL|AHC_TRANS_QUITE);
5988 break;
5992 else
5994 switch(bus_width)
5996 default:
5998 reply = TRUE;
5999 if ( (aic7xxx_verbose & VERBOSE_NEGOTIATION2) &&
6000 ((p->dev_flags[tindex] & DEVICE_PRINT_DTR) ||
6001 (aic7xxx_verbose > 0xffff)) )
6003 printk(INFO_LEAD "Requesting %d bit transfers, rejecting.\n",
6004 p->host_no, CTL_OF_SCB(scb), 8 * (0x01 << bus_width));
6006 } /* We fall through on purpose */
6007 case MSG_EXT_WDTR_BUS_8_BIT:
6010 * According to the spec, if we aren't wide, we also can't be
6011 * Dual Edge so clear the options byte
6013 new_trans_options = 0;
6014 bus_width = MSG_EXT_WDTR_BUS_8_BIT;
6015 break;
6017 case MSG_EXT_WDTR_BUS_16_BIT:
6019 break;
6024 aic7xxx_set_width(p, target, channel, lun, bus_width,
6025 AHC_TRANS_ACTIVE|AHC_TRANS_CUR);
6026 syncrate = aic7xxx_find_syncrate(p, &period, maxsync,
6027 &new_trans_options);
6028 aic7xxx_validate_offset(p, syncrate, &offset, bus_width);
6029 aic7xxx_set_syncrate(p, syncrate, target, channel, period,
6030 offset, new_trans_options,
6031 AHC_TRANS_ACTIVE|AHC_TRANS_CUR);
6033 if( (offset != saved_offset) ||
6034 (trans_options != new_trans_options) ||
6035 ((scb->flags & (SCB_MSGOUT_SENT|SCB_MSGOUT_PPR)) !=
6036 (SCB_MSGOUT_SENT|SCB_MSGOUT_PPR)) )
6038 aic7xxx_set_width(p, target, channel, lun, bus_width,
6039 AHC_TRANS_GOAL|AHC_TRANS_QUITE);
6040 aic7xxx_set_syncrate(p, syncrate, target, channel, period,
6041 offset, new_trans_options,
6042 AHC_TRANS_GOAL|AHC_TRANS_QUITE);
6043 reply = TRUE;
6045 p->dtr_pending &= ~target_mask;
6046 p->needppr &= ~target_mask;
6047 if(reply)
6049 p->dtr_pending |= target_mask;
6050 scb->flags &= ~SCB_MSGOUT_BITS;
6051 scb->flags |= SCB_MSGOUT_PPR;
6052 aic_outb(p, HOST_MSG, MSG_OUT);
6053 aic_outb(p, aic_inb(p, SCSISIGO) | ATNO, SCSISIGO);
6055 done = TRUE;
6056 break;
6058 default:
6060 reject = TRUE;
6061 break;
6063 } /* end of switch(p->msg_type) */
6064 } /* end of if (!reject && (p->msg_len > 2)) */
6066 if (!reply && reject)
6068 aic_outb(p, MSG_MESSAGE_REJECT, MSG_OUT);
6069 aic_outb(p, aic_inb(p, SCSISIGO) | ATNO, SCSISIGO);
6070 done = TRUE;
6072 return(done);
6076 /*+F*************************************************************************
6077 * Function:
6078 * aic7xxx_handle_reqinit
6080 * Description:
6081 * Interrupt handler for REQINIT interrupts (used to transfer messages to
6082 * and from devices).
6083 *_F*************************************************************************/
6084 static void
6085 aic7xxx_handle_reqinit(struct aic7xxx_host *p, struct aic7xxx_scb *scb)
6087 unsigned char lastbyte;
6088 unsigned char phasemis;
6089 int done = FALSE;
6091 switch(p->msg_type)
6093 case MSG_TYPE_INITIATOR_MSGOUT:
6095 if (p->msg_len == 0)
6096 panic("aic7xxx: REQINIT with no active message!\n");
6098 lastbyte = (p->msg_index == (p->msg_len - 1));
6099 phasemis = ( aic_inb(p, SCSISIGI) & PHASE_MASK) != P_MESGOUT;
6101 if (lastbyte || phasemis)
6103 /* Time to end the message */
6104 p->msg_len = 0;
6105 p->msg_type = MSG_TYPE_NONE;
6107 * NOTE-TO-MYSELF: If you clear the REQINIT after you
6108 * disable REQINITs, then cases of REJECT_MSG stop working
6109 * and hang the bus
6111 aic_outb(p, aic_inb(p, SIMODE1) & ~ENREQINIT, SIMODE1);
6112 aic_outb(p, CLRSCSIINT, CLRINT);
6113 p->flags &= ~AHC_HANDLING_REQINITS;
6115 if (phasemis == 0)
6117 aic_outb(p, p->msg_buf[p->msg_index], SINDEX);
6118 aic_outb(p, 0, RETURN_1);
6119 #ifdef AIC7XXX_VERBOSE_DEBUGGING
6120 if (aic7xxx_verbose > 0xffff)
6121 printk(INFO_LEAD "Completed sending of REQINIT message.\n",
6122 p->host_no, CTL_OF_SCB(scb));
6123 #endif
6125 else
6127 aic_outb(p, MSGOUT_PHASEMIS, RETURN_1);
6128 #ifdef AIC7XXX_VERBOSE_DEBUGGING
6129 if (aic7xxx_verbose > 0xffff)
6130 printk(INFO_LEAD "PHASEMIS while sending REQINIT message.\n",
6131 p->host_no, CTL_OF_SCB(scb));
6132 #endif
6134 unpause_sequencer(p, TRUE);
6136 else
6139 * Present the byte on the bus (clearing REQINIT) but don't
6140 * unpause the sequencer.
6142 aic_outb(p, CLRREQINIT, CLRSINT1);
6143 aic_outb(p, CLRSCSIINT, CLRINT);
6144 aic_outb(p, p->msg_buf[p->msg_index++], SCSIDATL);
6146 break;
6148 case MSG_TYPE_INITIATOR_MSGIN:
6150 phasemis = ( aic_inb(p, SCSISIGI) & PHASE_MASK ) != P_MESGIN;
6152 if (phasemis == 0)
6154 p->msg_len++;
6155 /* Pull the byte in without acking it */
6156 p->msg_buf[p->msg_index] = aic_inb(p, SCSIBUSL);
6157 done = aic7xxx_parse_msg(p, scb);
6158 /* Ack the byte */
6159 aic_outb(p, CLRREQINIT, CLRSINT1);
6160 aic_outb(p, CLRSCSIINT, CLRINT);
6161 aic_inb(p, SCSIDATL);
6162 p->msg_index++;
6164 if (phasemis || done)
6166 #ifdef AIC7XXX_VERBOSE_DEBUGGING
6167 if (aic7xxx_verbose > 0xffff)
6169 if (phasemis)
6170 printk(INFO_LEAD "PHASEMIS while receiving REQINIT message.\n",
6171 p->host_no, CTL_OF_SCB(scb));
6172 else
6173 printk(INFO_LEAD "Completed receipt of REQINIT message.\n",
6174 p->host_no, CTL_OF_SCB(scb));
6176 #endif
6177 /* Time to end our message session */
6178 p->msg_len = 0;
6179 p->msg_type = MSG_TYPE_NONE;
6180 aic_outb(p, aic_inb(p, SIMODE1) & ~ENREQINIT, SIMODE1);
6181 aic_outb(p, CLRSCSIINT, CLRINT);
6182 p->flags &= ~AHC_HANDLING_REQINITS;
6183 unpause_sequencer(p, TRUE);
6185 break;
6187 default:
6189 panic("aic7xxx: Unknown REQINIT message type.\n");
6190 break;
6192 } /* End of switch(p->msg_type) */
6195 /*+F*************************************************************************
6196 * Function:
6197 * aic7xxx_handle_scsiint
6199 * Description:
6200 * Interrupt handler for SCSI interrupts (SCSIINT).
6201 *-F*************************************************************************/
6202 static void
6203 aic7xxx_handle_scsiint(struct aic7xxx_host *p, unsigned char intstat)
6205 unsigned char scb_index;
6206 unsigned char status;
6207 struct aic7xxx_scb *scb;
6209 scb_index = aic_inb(p, SCB_TAG);
6210 status = aic_inb(p, SSTAT1);
6212 if (scb_index < p->scb_data->numscbs)
6214 scb = p->scb_data->scb_array[scb_index];
6215 if ((scb->flags & SCB_ACTIVE) == 0)
6217 scb = NULL;
6220 else
6222 scb = NULL;
6226 if ((status & SCSIRSTI) != 0)
6228 int channel;
6230 if ( (p->chip & AHC_CHIPID_MASK) == AHC_AIC7770 )
6231 channel = (aic_inb(p, SBLKCTL) & SELBUSB) >> 3;
6232 else
6233 channel = 0;
6235 if (aic7xxx_verbose & VERBOSE_RESET)
6236 printk(WARN_LEAD "Someone else reset the channel!!\n",
6237 p->host_no, channel, -1, -1);
6238 if (aic7xxx_panic_on_abort)
6239 aic7xxx_panic_abort(p, NULL);
6241 * Go through and abort all commands for the channel, but do not
6242 * reset the channel again.
6244 aic7xxx_reset_channel(p, channel, /* Initiate Reset */ FALSE);
6245 aic7xxx_run_done_queue(p, TRUE);
6246 scb = NULL;
6248 else if ( ((status & BUSFREE) != 0) && ((status & SELTO) == 0) )
6251 * First look at what phase we were last in. If it's message-out,
6252 * chances are pretty good that the bus free was in response to
6253 * one of our abort requests.
6255 unsigned char lastphase = aic_inb(p, LASTPHASE);
6256 unsigned char saved_tcl = aic_inb(p, SAVED_TCL);
6257 unsigned char target = (saved_tcl >> 4) & 0x0F;
6258 int channel;
6259 int printerror = TRUE;
6261 if ( (p->chip & AHC_CHIPID_MASK) == AHC_AIC7770 )
6262 channel = (aic_inb(p, SBLKCTL) & SELBUSB) >> 3;
6263 else
6264 channel = 0;
6266 aic_outb(p, aic_inb(p, SCSISEQ) & (ENSELI|ENRSELI|ENAUTOATNP),
6267 SCSISEQ);
6268 if (lastphase == P_MESGOUT)
6270 unsigned char message;
6272 message = aic_inb(p, SINDEX);
6274 if ((message == MSG_ABORT) || (message == MSG_ABORT_TAG))
6276 if (aic7xxx_verbose & VERBOSE_ABORT_PROCESS)
6277 printk(INFO_LEAD "SCB %d abort delivered.\n", p->host_no,
6278 CTL_OF_SCB(scb), scb->hscb->tag);
6279 aic7xxx_reset_device(p, target, channel, ALL_LUNS,
6280 (message == MSG_ABORT) ? SCB_LIST_NULL : scb->hscb->tag );
6281 aic7xxx_run_done_queue(p, TRUE);
6282 scb = NULL;
6283 printerror = 0;
6285 else if (message == MSG_BUS_DEV_RESET)
6287 aic7xxx_handle_device_reset(p, target, channel);
6288 scb = NULL;
6289 printerror = 0;
6292 if ( (scb != NULL) &&
6293 (scb->cmd == p->dev_dtr_cmnd[TARGET_INDEX(scb->cmd)]) )
6296 * This might be a SCSI-3 device that is dropping the bus due to
6297 * errors and signalling that we should reduce the transfer speed.
6298 * All we have to do is complete this command (since it's a negotiation
6299 * command already) and the checksum routine should flag an error and
6300 * reduce the speed setting and renegotiate. We call the reset routing
6301 * just to clean out the hardware from this scb.
6303 printerror = 0;
6304 aic7xxx_reset_device(p, target, channel, ALL_LUNS, scb->hscb->tag);
6305 aic7xxx_run_done_queue(p, TRUE);
6306 scb = NULL;
6308 if (printerror != 0)
6310 if (scb != NULL)
6312 unsigned char tag;
6314 if ((scb->hscb->control & TAG_ENB) != 0)
6316 tag = scb->hscb->tag;
6318 else
6320 tag = SCB_LIST_NULL;
6322 aic7xxx_reset_device(p, target, channel, ALL_LUNS, tag);
6323 aic7xxx_run_done_queue(p, TRUE);
6325 else
6327 aic7xxx_reset_device(p, target, channel, ALL_LUNS, SCB_LIST_NULL);
6328 aic7xxx_run_done_queue(p, TRUE);
6330 printk(INFO_LEAD "Unexpected busfree, LASTPHASE = 0x%x, "
6331 "SEQADDR = 0x%x\n", p->host_no, channel, target, -1, lastphase,
6332 (aic_inb(p, SEQADDR1) << 8) | aic_inb(p, SEQADDR0));
6333 scb = NULL;
6335 aic_outb(p, MSG_NOOP, MSG_OUT);
6336 aic_outb(p, aic_inb(p, SIMODE1) & ~(ENBUSFREE|ENREQINIT),
6337 SIMODE1);
6338 p->flags &= ~AHC_HANDLING_REQINITS;
6339 aic_outb(p, CLRBUSFREE, CLRSINT1);
6340 aic_outb(p, CLRSCSIINT, CLRINT);
6341 restart_sequencer(p);
6342 unpause_sequencer(p, TRUE);
6344 else if ((status & SELTO) != 0)
6346 unsigned char scbptr;
6347 unsigned char nextscb;
6348 Scsi_Cmnd *cmd;
6350 scbptr = aic_inb(p, WAITING_SCBH);
6351 if (scbptr > p->scb_data->maxhscbs)
6354 * I'm still trying to track down exactly how this happens, but until
6355 * I find it, this code will make sure we aren't passing bogus values
6356 * into the SCBPTR register, even if that register will just wrap
6357 * things around, we still don't like having out of range variables.
6359 * NOTE: Don't check the aic7xxx_verbose variable, I want this message
6360 * to always be displayed.
6362 printk(INFO_LEAD "Invalid WAITING_SCBH value %d, improvising.\n",
6363 p->host_no, -1, -1, -1, scbptr);
6364 if (p->scb_data->maxhscbs > 4)
6365 scbptr &= (p->scb_data->maxhscbs - 1);
6366 else
6367 scbptr &= 0x03;
6369 aic_outb(p, scbptr, SCBPTR);
6370 scb_index = aic_inb(p, SCB_TAG);
6372 scb = NULL;
6373 if (scb_index < p->scb_data->numscbs)
6375 scb = p->scb_data->scb_array[scb_index];
6376 if ((scb->flags & SCB_ACTIVE) == 0)
6378 scb = NULL;
6381 if (scb == NULL)
6383 printk(WARN_LEAD "Referenced SCB %d not valid during SELTO.\n",
6384 p->host_no, -1, -1, -1, scb_index);
6385 printk(KERN_WARNING " SCSISEQ = 0x%x SEQADDR = 0x%x SSTAT0 = 0x%x "
6386 "SSTAT1 = 0x%x\n", aic_inb(p, SCSISEQ),
6387 aic_inb(p, SEQADDR0) | (aic_inb(p, SEQADDR1) << 8),
6388 aic_inb(p, SSTAT0), aic_inb(p, SSTAT1));
6389 if (aic7xxx_panic_on_abort)
6390 aic7xxx_panic_abort(p, NULL);
6392 else
6394 cmd = scb->cmd;
6395 cmd->result = (DID_TIME_OUT << 16);
6398 * Clear out this hardware SCB
6400 aic_outb(p, 0, SCB_CONTROL);
6403 * Clear out a few values in the card that are in an undetermined
6404 * state.
6406 aic_outb(p, MSG_NOOP, MSG_OUT);
6409 * Shift the waiting for selection queue forward
6411 nextscb = aic_inb(p, SCB_NEXT);
6412 aic_outb(p, nextscb, WAITING_SCBH);
6415 * Put this SCB back on the free list.
6417 aic7xxx_add_curscb_to_free_list(p);
6418 #ifdef AIC7XXX_VERBOSE_DEBUGGING
6419 if (aic7xxx_verbose > 0xffff)
6420 printk(INFO_LEAD "Selection Timeout.\n", p->host_no, CTL_OF_SCB(scb));
6421 #endif
6422 if (scb->flags & SCB_QUEUED_ABORT)
6425 * We know that this particular SCB had to be the queued abort since
6426 * the disconnected SCB would have gotten a reconnect instead.
6427 * What we need to do then is to let the command timeout again so
6428 * we get a reset since this abort just failed.
6430 cmd->result = 0;
6431 scb = NULL;
6433 else if (scb->cmd == p->dev_dtr_cmnd[TARGET_INDEX(scb->cmd)])
6436 * Turn off the needsdtr, needwdtr, and needppr bits since this device
6437 * doesn't seem to exist.
6439 p->needppr &= ~(0x01 << TARGET_INDEX(scb->cmd));
6440 p->needppr_copy &= ~(0x01 << TARGET_INDEX(scb->cmd));
6441 p->needsdtr &= ~(0x01 << TARGET_INDEX(scb->cmd));
6442 p->needsdtr_copy &= ~(0x01 << TARGET_INDEX(scb->cmd));
6443 p->needwdtr &= ~(0x01 << TARGET_INDEX(scb->cmd));
6444 p->needwdtr_copy &= ~(0x01 << TARGET_INDEX(scb->cmd));
6448 * Restarting the sequencer will stop the selection and make sure devices
6449 * are allowed to reselect in.
6451 aic_outb(p, 0, SCSISEQ);
6452 aic_outb(p, CLRSELINGO, CLRSINT0);
6453 aic_outb(p, aic_inb(p, SIMODE1) & ~(ENREQINIT|ENBUSFREE), SIMODE1);
6454 p->flags &= ~AHC_HANDLING_REQINITS;
6455 aic_outb(p, CLRSELTIMEO | CLRBUSFREE, CLRSINT1);
6456 aic_outb(p, CLRSCSIINT, CLRINT);
6457 restart_sequencer(p);
6458 unpause_sequencer(p, TRUE);
6460 else if (scb == NULL)
6462 printk(WARN_LEAD "aic7xxx_isr - referenced scb not valid "
6463 "during scsiint 0x%x scb(%d)\n"
6464 " SIMODE0 0x%x, SIMODE1 0x%x, SSTAT0 0x%x, SEQADDR 0x%x\n",
6465 p->host_no, -1, -1, -1, status, scb_index, aic_inb(p, SIMODE0),
6466 aic_inb(p, SIMODE1), aic_inb(p, SSTAT0),
6467 (aic_inb(p, SEQADDR1) << 8) | aic_inb(p, SEQADDR0));
6469 * Turn off the interrupt and set status to zero, so that it
6470 * falls through the rest of the SCSIINT code.
6472 aic_outb(p, status, CLRSINT1);
6473 aic_outb(p, CLRSCSIINT, CLRINT);
6474 unpause_sequencer(p, /* unpause always */ TRUE);
6475 scb = NULL;
6477 else if (status & SCSIPERR)
6480 * Determine the bus phase and queue an appropriate message.
6482 char *phase;
6483 Scsi_Cmnd *cmd;
6484 unsigned char mesg_out = MSG_NOOP;
6485 unsigned char lastphase = aic_inb(p, LASTPHASE);
6486 unsigned char sstat2 = aic_inb(p, SSTAT2);
6487 unsigned char tindex = TARGET_INDEX(scb->cmd);
6489 cmd = scb->cmd;
6490 switch (lastphase)
6492 case P_DATAOUT:
6493 phase = "Data-Out";
6494 break;
6495 case P_DATAIN:
6496 phase = "Data-In";
6497 mesg_out = MSG_INITIATOR_DET_ERR;
6498 break;
6499 case P_COMMAND:
6500 phase = "Command";
6501 break;
6502 case P_MESGOUT:
6503 phase = "Message-Out";
6504 break;
6505 case P_STATUS:
6506 phase = "Status";
6507 mesg_out = MSG_INITIATOR_DET_ERR;
6508 break;
6509 case P_MESGIN:
6510 phase = "Message-In";
6511 mesg_out = MSG_PARITY_ERROR;
6512 break;
6513 default:
6514 phase = "unknown";
6515 break;
6519 * A parity error has occurred during a data
6520 * transfer phase. Flag it and continue.
6522 if( (aic_inb(p, SCSIRATE) & AHC_SYNCRATE_CRC) && (lastphase == P_DATAIN) )
6524 printk(WARN_LEAD "CRC error during %s phase.\n",
6525 p->host_no, CTL_OF_SCB(scb), phase);
6526 if(sstat2 & CRCVALERR)
6528 printk(WARN_LEAD " CRC error in intermediate CRC packet.\n",
6529 p->host_no, CTL_OF_SCB(scb));
6531 if(sstat2 & CRCENDERR)
6533 printk(WARN_LEAD " CRC error in ending CRC packet.\n",
6534 p->host_no, CTL_OF_SCB(scb));
6536 if(sstat2 & CRCREQERR)
6538 printk(WARN_LEAD " Target incorrectly requested a CRC packet.\n",
6539 p->host_no, CTL_OF_SCB(scb));
6541 if(sstat2 & DUAL_EDGE_ERROR)
6543 printk(WARN_LEAD " Dual Edge transmission error.\n",
6544 p->host_no, CTL_OF_SCB(scb));
6547 else
6549 printk(WARN_LEAD "Parity error during %s phase.\n",
6550 p->host_no, CTL_OF_SCB(scb), phase);
6553 if(p->dev_flags[tindex] & DEVICE_PARITY_ERROR)
6555 struct aic7xxx_syncrate *syncrate;
6556 unsigned int period = p->transinfo[tindex].cur_period;
6557 unsigned char options = p->transinfo[tindex].cur_options;
6559 * oops, we had a failure, lower the transfer rate and try again. It's
6560 * worth noting here that it might be wise to also check for typical
6561 * wide setting on narrow cable type problems and try disabling wide
6562 * instead of slowing down if those exist. That's hard to do with simple
6563 * checksums though.
6565 if((syncrate = aic7xxx_find_syncrate(p, &period, 0, &options)) != NULL)
6567 syncrate++;
6568 if( (syncrate->rate[0] != NULL) &&
6569 (!(p->features & AHC_ULTRA2) || (syncrate->sxfr_ultra2 == 0)) )
6571 p->transinfo[tindex].goal_period = syncrate->period;
6572 if( !(syncrate->sxfr_ultra2 & 0x40) )
6574 p->transinfo[tindex].goal_options = 0;
6577 else
6579 p->transinfo[tindex].goal_offset = 0;
6580 p->transinfo[tindex].goal_period = 0;
6581 p->transinfo[tindex].goal_options = 0;
6583 p->needppr |= (p->needppr_copy & (1<<tindex));
6584 p->needsdtr |= (p->needsdtr_copy & (1<<tindex));
6585 p->needwdtr |= (p->needwdtr_copy & (1<<tindex));
6587 p->dev_flags[tindex] &= ~DEVICE_PARITY_ERROR;
6589 else
6591 p->dev_flags[tindex] |= DEVICE_PARITY_ERROR;
6595 * We've set the hardware to assert ATN if we get a parity
6596 * error on "in" phases, so all we need to do is stuff the
6597 * message buffer with the appropriate message. "In" phases
6598 * have set mesg_out to something other than MSG_NOP.
6600 if (mesg_out != MSG_NOOP)
6602 aic_outb(p, mesg_out, MSG_OUT);
6603 scb = NULL;
6605 aic_outb(p, CLRSCSIPERR, CLRSINT1);
6606 aic_outb(p, CLRSCSIINT, CLRINT);
6607 unpause_sequencer(p, /* unpause_always */ TRUE);
6609 else if ( (status & REQINIT) &&
6610 (p->flags & AHC_HANDLING_REQINITS) )
6612 #ifdef AIC7XXX_VERBOSE_DEBUGGING
6613 if (aic7xxx_verbose > 0xffff)
6614 printk(INFO_LEAD "Handling REQINIT, SSTAT1=0x%x.\n", p->host_no,
6615 CTL_OF_SCB(scb), aic_inb(p, SSTAT1));
6616 #endif
6617 aic7xxx_handle_reqinit(p, scb);
6618 return;
6620 else
6623 * We don't know what's going on. Turn off the
6624 * interrupt source and try to continue.
6626 if (aic7xxx_verbose & VERBOSE_SCSIINT)
6627 printk(INFO_LEAD "Unknown SCSIINT status, SSTAT1(0x%x).\n",
6628 p->host_no, -1, -1, -1, status);
6629 aic_outb(p, status, CLRSINT1);
6630 aic_outb(p, CLRSCSIINT, CLRINT);
6631 unpause_sequencer(p, /* unpause always */ TRUE);
6632 scb = NULL;
6634 if (scb != NULL)
6636 aic7xxx_done(p, scb);
6640 #ifdef AIC7XXX_VERBOSE_DEBUGGING
6641 static void
6642 aic7xxx_check_scbs(struct aic7xxx_host *p, char *buffer)
6644 unsigned char saved_scbptr, free_scbh, dis_scbh, wait_scbh, temp;
6645 int i, bogus, lost;
6646 static unsigned char scb_status[AIC7XXX_MAXSCB];
6648 #define SCB_NO_LIST 0
6649 #define SCB_FREE_LIST 1
6650 #define SCB_WAITING_LIST 2
6651 #define SCB_DISCONNECTED_LIST 4
6652 #define SCB_CURRENTLY_ACTIVE 8
6655 * Note, these checks will fail on a regular basis once the machine moves
6656 * beyond the bus scan phase. The problem is race conditions concerning
6657 * the scbs and where they are linked in. When you have 30 or so commands
6658 * outstanding on the bus, and run this twice with every interrupt, the
6659 * chances get pretty good that you'll catch the sequencer with an SCB
6660 * only partially linked in. Therefore, once we pass the scan phase
6661 * of the bus, we really should disable this function.
6663 bogus = FALSE;
6664 memset(&scb_status[0], 0, sizeof(scb_status));
6665 pause_sequencer(p);
6666 saved_scbptr = aic_inb(p, SCBPTR);
6667 if (saved_scbptr >= p->scb_data->maxhscbs)
6669 printk("Bogus SCBPTR %d\n", saved_scbptr);
6670 bogus = TRUE;
6672 scb_status[saved_scbptr] = SCB_CURRENTLY_ACTIVE;
6673 free_scbh = aic_inb(p, FREE_SCBH);
6674 if ( (free_scbh != SCB_LIST_NULL) &&
6675 (free_scbh >= p->scb_data->maxhscbs) )
6677 printk("Bogus FREE_SCBH %d\n", free_scbh);
6678 bogus = TRUE;
6680 else
6682 temp = free_scbh;
6683 while( (temp != SCB_LIST_NULL) && (temp < p->scb_data->maxhscbs) )
6685 if(scb_status[temp] & 0x07)
6687 printk("HSCB %d on multiple lists, status 0x%02x", temp,
6688 scb_status[temp] | SCB_FREE_LIST);
6689 bogus = TRUE;
6691 scb_status[temp] |= SCB_FREE_LIST;
6692 aic_outb(p, temp, SCBPTR);
6693 temp = aic_inb(p, SCB_NEXT);
6697 dis_scbh = aic_inb(p, DISCONNECTED_SCBH);
6698 if ( (dis_scbh != SCB_LIST_NULL) &&
6699 (dis_scbh >= p->scb_data->maxhscbs) )
6701 printk("Bogus DISCONNECTED_SCBH %d\n", dis_scbh);
6702 bogus = TRUE;
6704 else
6706 temp = dis_scbh;
6707 while( (temp != SCB_LIST_NULL) && (temp < p->scb_data->maxhscbs) )
6709 if(scb_status[temp] & 0x07)
6711 printk("HSCB %d on multiple lists, status 0x%02x", temp,
6712 scb_status[temp] | SCB_DISCONNECTED_LIST);
6713 bogus = TRUE;
6715 scb_status[temp] |= SCB_DISCONNECTED_LIST;
6716 aic_outb(p, temp, SCBPTR);
6717 temp = aic_inb(p, SCB_NEXT);
6721 wait_scbh = aic_inb(p, WAITING_SCBH);
6722 if ( (wait_scbh != SCB_LIST_NULL) &&
6723 (wait_scbh >= p->scb_data->maxhscbs) )
6725 printk("Bogus WAITING_SCBH %d\n", wait_scbh);
6726 bogus = TRUE;
6728 else
6730 temp = wait_scbh;
6731 while( (temp != SCB_LIST_NULL) && (temp < p->scb_data->maxhscbs) )
6733 if(scb_status[temp] & 0x07)
6735 printk("HSCB %d on multiple lists, status 0x%02x", temp,
6736 scb_status[temp] | SCB_WAITING_LIST);
6737 bogus = TRUE;
6739 scb_status[temp] |= SCB_WAITING_LIST;
6740 aic_outb(p, temp, SCBPTR);
6741 temp = aic_inb(p, SCB_NEXT);
6745 lost=0;
6746 for(i=0; i < p->scb_data->maxhscbs; i++)
6748 aic_outb(p, i, SCBPTR);
6749 temp = aic_inb(p, SCB_NEXT);
6750 if ( ((temp != SCB_LIST_NULL) &&
6751 (temp >= p->scb_data->maxhscbs)) )
6753 printk("HSCB %d bad, SCB_NEXT invalid(%d).\n", i, temp);
6754 bogus = TRUE;
6756 if ( temp == i )
6758 printk("HSCB %d bad, SCB_NEXT points to self.\n", i);
6759 bogus = TRUE;
6761 if (scb_status[i] == 0)
6762 lost++;
6763 if (lost > 1)
6765 printk("Too many lost scbs.\n");
6766 bogus=TRUE;
6769 aic_outb(p, saved_scbptr, SCBPTR);
6770 unpause_sequencer(p, FALSE);
6771 if (bogus)
6773 printk("Bogus parameters found in card SCB array structures.\n");
6774 printk("%s\n", buffer);
6775 aic7xxx_panic_abort(p, NULL);
6777 return;
6779 #endif
6782 /*+F*************************************************************************
6783 * Function:
6784 * aic7xxx_handle_command_completion_intr
6786 * Description:
6787 * SCSI command completion interrupt handler.
6788 *-F*************************************************************************/
6789 static void
6790 aic7xxx_handle_command_completion_intr(struct aic7xxx_host *p)
6792 struct aic7xxx_scb *scb = NULL;
6793 Scsi_Cmnd *cmd;
6794 unsigned char scb_index;
6796 #ifdef AIC7XXX_VERBOSE_DEBUGGING
6797 if( (p->isr_count < 16) && (aic7xxx_verbose > 0xffff) )
6798 printk(INFO_LEAD "Command Complete Int.\n", p->host_no, -1, -1, -1);
6799 #endif
6802 * Read the INTSTAT location after clearing the CMDINT bit. This forces
6803 * any posted PCI writes to flush to memory. Gerard Roudier suggested
6804 * this fix to the possible race of clearing the CMDINT bit but not
6805 * having all command bytes flushed onto the qoutfifo.
6807 aic_outb(p, CLRCMDINT, CLRINT);
6808 aic_inb(p, INTSTAT);
6810 * The sequencer will continue running when it
6811 * issues this interrupt. There may be >1 commands
6812 * finished, so loop until we've processed them all.
6815 while (p->qoutfifo[p->qoutfifonext] != SCB_LIST_NULL)
6817 scb_index = p->qoutfifo[p->qoutfifonext];
6818 p->qoutfifo[p->qoutfifonext++] = SCB_LIST_NULL;
6819 if ( scb_index >= p->scb_data->numscbs )
6820 scb = NULL;
6821 else
6822 scb = p->scb_data->scb_array[scb_index];
6823 if (scb == NULL)
6825 printk(WARN_LEAD "CMDCMPLT with invalid SCB index %d\n", p->host_no,
6826 -1, -1, -1, scb_index);
6827 continue;
6829 else if (!(scb->flags & SCB_ACTIVE) || (scb->cmd == NULL))
6831 printk(WARN_LEAD "CMDCMPLT without command for SCB %d, SCB flags "
6832 "0x%x, cmd 0x%lx\n", p->host_no, -1, -1, -1, scb_index, scb->flags,
6833 (unsigned long) scb->cmd);
6834 continue;
6836 else if (scb->flags & SCB_QUEUED_ABORT)
6838 pause_sequencer(p);
6839 if ( ((aic_inb(p, LASTPHASE) & PHASE_MASK) != P_BUSFREE) &&
6840 (aic_inb(p, SCB_TAG) == scb->hscb->tag) )
6842 unpause_sequencer(p, FALSE);
6843 continue;
6845 aic7xxx_reset_device(p, scb->cmd->target, scb->cmd->channel,
6846 scb->cmd->lun, scb->hscb->tag);
6847 scb->flags &= ~(SCB_QUEUED_FOR_DONE | SCB_RESET | SCB_ABORT |
6848 SCB_QUEUED_ABORT);
6849 unpause_sequencer(p, FALSE);
6851 else if (scb->flags & SCB_ABORT)
6854 * We started to abort this, but it completed on us, let it
6855 * through as successful
6857 scb->flags &= ~(SCB_ABORT|SCB_RESET);
6859 switch (status_byte(scb->hscb->target_status))
6861 case QUEUE_FULL:
6862 case BUSY:
6863 scb->hscb->target_status = 0;
6864 scb->cmd->result = 0;
6865 aic7xxx_error(scb->cmd) = DID_OK;
6866 break;
6867 default:
6868 cmd = scb->cmd;
6869 if (scb->hscb->residual_SG_segment_count != 0)
6871 aic7xxx_calculate_residual(p, scb);
6873 cmd->result |= (aic7xxx_error(cmd) << 16);
6874 aic7xxx_done(p, scb);
6875 break;
6880 /*+F*************************************************************************
6881 * Function:
6882 * aic7xxx_isr
6884 * Description:
6885 * SCSI controller interrupt handler.
6886 *-F*************************************************************************/
6887 static void
6888 aic7xxx_isr(int irq, void *dev_id, struct pt_regs *regs)
6890 struct aic7xxx_host *p;
6891 unsigned char intstat;
6893 p = (struct aic7xxx_host *)dev_id;
6896 * Just a few sanity checks. Make sure that we have an int pending.
6897 * Also, if PCI, then we are going to check for a PCI bus error status
6898 * should we get too many spurious interrupts.
6900 if (!((intstat = aic_inb(p, INTSTAT)) & INT_PEND))
6902 #ifdef CONFIG_PCI
6903 if ( (p->chip & AHC_PCI) && (p->spurious_int > 500) &&
6904 !(p->flags & AHC_HANDLING_REQINITS) )
6906 if ( aic_inb(p, ERROR) & PCIERRSTAT )
6908 aic7xxx_pci_intr(p);
6910 p->spurious_int = 0;
6912 else if ( !(p->flags & AHC_HANDLING_REQINITS) )
6914 p->spurious_int++;
6916 #endif
6917 return;
6920 p->spurious_int = 0;
6923 * Keep track of interrupts for /proc/scsi
6925 p->isr_count++;
6927 #ifdef AIC7XXX_VERBOSE_DEBUGGING
6928 if ( (p->isr_count < 16) && (aic7xxx_verbose > 0xffff) &&
6929 (aic7xxx_panic_on_abort) && (p->flags & AHC_PAGESCBS) )
6930 aic7xxx_check_scbs(p, "Bogus settings at start of interrupt.");
6931 #endif
6934 * Handle all the interrupt sources - especially for SCSI
6935 * interrupts, we won't get a second chance at them.
6937 if (intstat & CMDCMPLT)
6939 aic7xxx_handle_command_completion_intr(p);
6942 if (intstat & BRKADRINT)
6944 int i;
6945 unsigned char errno = aic_inb(p, ERROR);
6947 printk(KERN_ERR "(scsi%d) BRKADRINT error(0x%x):\n", p->host_no, errno);
6948 for (i = 0; i < NUMBER(hard_error); i++)
6950 if (errno & hard_error[i].errno)
6952 printk(KERN_ERR " %s\n", hard_error[i].errmesg);
6955 printk(KERN_ERR "(scsi%d) SEQADDR=0x%x\n", p->host_no,
6956 (((aic_inb(p, SEQADDR1) << 8) & 0x100) | aic_inb(p, SEQADDR0)));
6957 if (aic7xxx_panic_on_abort)
6958 aic7xxx_panic_abort(p, NULL);
6959 #ifdef CONFIG_PCI
6960 if (errno & PCIERRSTAT)
6961 aic7xxx_pci_intr(p);
6962 #endif
6963 if (errno & (SQPARERR | ILLOPCODE | ILLSADDR))
6965 sti();
6966 panic("aic7xxx: unrecoverable BRKADRINT.\n");
6968 if (errno & ILLHADDR)
6970 printk(KERN_ERR "(scsi%d) BUG! Driver accessed chip without first "
6971 "pausing controller!\n", p->host_no);
6973 #ifdef AIC7XXX_VERBOSE_DEBUGGING
6974 if (errno & DPARERR)
6976 if (aic_inb(p, DMAPARAMS) & DIRECTION)
6977 printk("(scsi%d) while DMAing SCB from host to card.\n", p->host_no);
6978 else
6979 printk("(scsi%d) while DMAing SCB from card to host.\n", p->host_no);
6981 #endif
6982 aic_outb(p, CLRPARERR | CLRBRKADRINT, CLRINT);
6983 unpause_sequencer(p, FALSE);
6986 if (intstat & SEQINT)
6988 aic7xxx_handle_seqint(p, intstat);
6991 if (intstat & SCSIINT)
6993 aic7xxx_handle_scsiint(p, intstat);
6996 #ifdef AIC7XXX_VERBOSE_DEBUGGING
6997 if ( (p->isr_count < 16) && (aic7xxx_verbose > 0xffff) &&
6998 (aic7xxx_panic_on_abort) && (p->flags & AHC_PAGESCBS) )
6999 aic7xxx_check_scbs(p, "Bogus settings at end of interrupt.");
7000 #endif
7004 /*+F*************************************************************************
7005 * Function:
7006 * do_aic7xxx_isr
7008 * Description:
7009 * This is a gross hack to solve a problem in linux kernels 2.1.85 and
7010 * above. Please, children, do not try this at home, and if you ever see
7011 * anything like it, please inform the Gross Hack Police immediately
7012 *-F*************************************************************************/
7013 static void
7014 do_aic7xxx_isr(int irq, void *dev_id, struct pt_regs *regs)
7016 unsigned long cpu_flags;
7017 struct aic7xxx_host *p;
7019 p = (struct aic7xxx_host *)dev_id;
7020 if(!p)
7021 return;
7022 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,1,95)
7023 spin_lock_irqsave(&io_request_lock, cpu_flags);
7024 if(test_and_set_bit(AHC_IN_ISR_BIT, (void *)&p->flags))
7026 return;
7030 aic7xxx_isr(irq, dev_id, regs);
7031 } while ( (aic_inb(p, INTSTAT) & INT_PEND) );
7032 aic7xxx_done_cmds_complete(p);
7033 aic7xxx_run_waiting_queues(p);
7034 clear_bit(AHC_IN_ISR_BIT, (void *)&p->flags);
7035 spin_unlock_irqrestore(&io_request_lock, cpu_flags);
7036 #else
7037 if(set_bit(AHC_IN_ISR_BIT, (int *)&p->flags))
7039 return;
7041 DRIVER_LOCK
7044 aic7xxx_isr(irq, dev_id, regs);
7045 } while ( (aic_inb(p, INTSTAT) & INT_PEND) );
7046 DRIVER_UNLOCK
7047 aic7xxx_done_cmds_complete(p);
7048 aic7xxx_run_waiting_queues(p);
7049 clear_bit(AHC_IN_ISR_BIT, (int *)&p->flags);
7050 #endif
7053 /*+F*************************************************************************
7054 * Function:
7055 * aic7xxx_device_queue_depth
7057 * Description:
7058 * Determines the queue depth for a given device. There are two ways
7059 * a queue depth can be obtained for a tagged queueing device. One
7060 * way is the default queue depth which is determined by whether
7061 * AIC7XXX_CMDS_PER_DEVICE is defined. If it is defined, then it is used
7062 * as the default queue depth. Otherwise, we use either 4 or 8 as the
7063 * default queue depth (dependent on the number of hardware SCBs).
7064 * The other way we determine queue depth is through the use of the
7065 * aic7xxx_tag_info array which is enabled by defining
7066 * AIC7XXX_TAGGED_QUEUEING_BY_DEVICE. This array can be initialized
7067 * with queue depths for individual devices. It also allows tagged
7068 * queueing to be [en|dis]abled for a specific adapter.
7069 *-F*************************************************************************/
7070 static void
7071 aic7xxx_device_queue_depth(struct aic7xxx_host *p, Scsi_Device *device)
7073 int default_depth = 3;
7074 unsigned char tindex;
7075 unsigned short target_mask;
7077 tindex = device->id | (device->channel << 3);
7078 target_mask = (1 << tindex);
7080 device->queue_depth = default_depth;
7081 p->dev_temp_queue_depth[tindex] = 1;
7082 p->dev_max_queue_depth[tindex] = 1;
7083 p->tagenable &= ~target_mask;
7085 if (device->tagged_supported)
7087 int tag_enabled = TRUE;
7089 default_depth = AIC7XXX_CMDS_PER_DEVICE;
7091 if (!(p->discenable & target_mask))
7093 if (aic7xxx_verbose & VERBOSE_NEGOTIATION2)
7094 printk(INFO_LEAD "Disconnection disabled, unable to "
7095 "enable tagged queueing.\n",
7096 p->host_no, device->channel, device->id, device->lun);
7098 else
7100 if (p->instance >= NUMBER(aic7xxx_tag_info))
7102 static int print_warning = TRUE;
7103 if(print_warning)
7105 printk(KERN_INFO "aic7xxx: WARNING, insufficient tag_info instances for"
7106 " installed controllers.\n");
7107 printk(KERN_INFO "aic7xxx: Please update the aic7xxx_tag_info array in"
7108 " the aic7xxx.c source file.\n");
7109 print_warning = FALSE;
7111 device->queue_depth = default_depth;
7113 else
7116 if (aic7xxx_tag_info[p->instance].tag_commands[tindex] == 255)
7118 tag_enabled = FALSE;
7119 device->queue_depth = 3; /* Tagged queueing is disabled. */
7121 else if (aic7xxx_tag_info[p->instance].tag_commands[tindex] == 0)
7123 device->queue_depth = default_depth;
7125 else
7127 device->queue_depth =
7128 aic7xxx_tag_info[p->instance].tag_commands[tindex];
7131 if ((device->tagged_queue == 0) && tag_enabled)
7133 if (aic7xxx_verbose & VERBOSE_NEGOTIATION2)
7135 printk(INFO_LEAD "Enabled tagged queuing, queue depth %d.\n",
7136 p->host_no, device->channel, device->id,
7137 device->lun, device->queue_depth);
7139 p->dev_max_queue_depth[tindex] = device->queue_depth;
7140 p->dev_temp_queue_depth[tindex] = device->queue_depth;
7141 p->tagenable |= target_mask;
7142 p->orderedtag |= target_mask;
7143 device->tagged_queue = 1;
7144 device->current_tag = SCB_LIST_NULL;
7150 /*+F*************************************************************************
7151 * Function:
7152 * aic7xxx_select_queue_depth
7154 * Description:
7155 * Sets the queue depth for each SCSI device hanging off the input
7156 * host adapter. We use a queue depth of 2 for devices that do not
7157 * support tagged queueing. If AIC7XXX_CMDS_PER_LUN is defined, we
7158 * use that for tagged queueing devices; otherwise we use our own
7159 * algorithm for determining the queue depth based on the maximum
7160 * SCBs for the controller.
7161 *-F*************************************************************************/
7162 static void
7163 aic7xxx_select_queue_depth(struct Scsi_Host *host,
7164 Scsi_Device *scsi_devs)
7166 Scsi_Device *device;
7167 struct aic7xxx_host *p = (struct aic7xxx_host *) host->hostdata;
7168 int scbnum;
7170 scbnum = 0;
7171 for (device = scsi_devs; device != NULL; device = device->next)
7173 if (device->host == host)
7175 aic7xxx_device_queue_depth(p, device);
7176 scbnum += device->queue_depth;
7179 while (scbnum > p->scb_data->numscbs)
7182 * Pre-allocate the needed SCBs to get around the possibility of having
7183 * to allocate some when memory is more or less exhausted and we need
7184 * the SCB in order to perform a swap operation (possible deadlock)
7186 if ( aic7xxx_allocate_scb(p) == 0 )
7187 return;
7191 /*+F*************************************************************************
7192 * Function:
7193 * aic7xxx_probe
7195 * Description:
7196 * Probing for EISA boards: it looks like the first two bytes
7197 * are a manufacturer code - three characters, five bits each:
7199 * BYTE 0 BYTE 1 BYTE 2 BYTE 3
7200 * ?1111122 22233333 PPPPPPPP RRRRRRRR
7202 * The characters are baselined off ASCII '@', so add that value
7203 * to each to get the real ASCII code for it. The next two bytes
7204 * appear to be a product and revision number, probably vendor-
7205 * specific. This is what is being searched for at each port,
7206 * and what should probably correspond to the ID= field in the
7207 * ECU's .cfg file for the card - if your card is not detected,
7208 * make sure your signature is listed in the array.
7210 * The fourth byte's lowest bit seems to be an enabled/disabled
7211 * flag (rest of the bits are reserved?).
7213 * NOTE: This function is only needed on Intel and Alpha platforms,
7214 * the other platforms we support don't have EISA/VLB busses. So,
7215 * we #ifdef this entire function to avoid compiler warnings about
7216 * an unused function.
7217 *-F*************************************************************************/
7218 #if defined(__i386__) || defined(__alpha__)
7219 static int
7220 aic7xxx_probe(int slot, int base, ahc_flag_type *flags)
7222 int i;
7223 unsigned char buf[4];
7225 static struct {
7226 int n;
7227 unsigned char signature[sizeof(buf)];
7228 ahc_chip type;
7229 int bios_disabled;
7230 } AIC7xxx[] = {
7231 { 4, { 0x04, 0x90, 0x77, 0x70 },
7232 AHC_AIC7770|AHC_EISA, FALSE }, /* mb 7770 */
7233 { 4, { 0x04, 0x90, 0x77, 0x71 },
7234 AHC_AIC7770|AHC_EISA, FALSE }, /* host adapter 274x */
7235 { 4, { 0x04, 0x90, 0x77, 0x56 },
7236 AHC_AIC7770|AHC_VL, FALSE }, /* 284x BIOS enabled */
7237 { 4, { 0x04, 0x90, 0x77, 0x57 },
7238 AHC_AIC7770|AHC_VL, TRUE } /* 284x BIOS disabled */
7242 * The VL-bus cards need to be primed by
7243 * writing before a signature check.
7245 for (i = 0; i < sizeof(buf); i++)
7247 outb(0x80 + i, base);
7248 buf[i] = inb(base + i);
7251 for (i = 0; i < NUMBER(AIC7xxx); i++)
7254 * Signature match on enabled card?
7256 if (!memcmp(buf, AIC7xxx[i].signature, AIC7xxx[i].n))
7258 if (inb(base + 4) & 1)
7260 if (AIC7xxx[i].bios_disabled)
7262 *flags |= AHC_USEDEFAULTS;
7264 else
7266 *flags |= AHC_BIOS_ENABLED;
7268 return (i);
7271 printk("aic7xxx: <Adaptec 7770 SCSI Host Adapter> "
7272 "disabled at slot %d, ignored.\n", slot);
7276 return (-1);
7278 #endif /* (__i386__) || (__alpha__) */
7281 /*+F*************************************************************************
7282 * Function:
7283 * read_2840_seeprom
7285 * Description:
7286 * Reads the 2840 serial EEPROM and returns 1 if successful and 0 if
7287 * not successful.
7289 * See read_seeprom (for the 2940) for the instruction set of the 93C46
7290 * chip.
7292 * The 2840 interface to the 93C46 serial EEPROM is through the
7293 * STATUS_2840 and SEECTL_2840 registers. The CS_2840, CK_2840, and
7294 * DO_2840 bits of the SEECTL_2840 register are connected to the chip
7295 * select, clock, and data out lines respectively of the serial EEPROM.
7296 * The DI_2840 bit of the STATUS_2840 is connected to the data in line
7297 * of the serial EEPROM. The EEPROM_TF bit of STATUS_2840 register is
7298 * useful in that it gives us an 800 nsec timer. After a read from the
7299 * SEECTL_2840 register the timing flag is cleared and goes high 800 nsec
7300 * later.
7301 *-F*************************************************************************/
7302 static int
7303 read_284x_seeprom(struct aic7xxx_host *p, struct seeprom_config *sc)
7305 int i = 0, k = 0;
7306 unsigned char temp;
7307 unsigned short checksum = 0;
7308 unsigned short *seeprom = (unsigned short *) sc;
7309 struct seeprom_cmd {
7310 unsigned char len;
7311 unsigned char bits[3];
7313 struct seeprom_cmd seeprom_read = {3, {1, 1, 0}};
7315 #define CLOCK_PULSE(p) \
7316 while ((aic_inb(p, STATUS_2840) & EEPROM_TF) == 0) \
7318 ; /* Do nothing */ \
7320 (void) aic_inb(p, SEECTL_2840);
7323 * Read the first 32 registers of the seeprom. For the 2840,
7324 * the 93C46 SEEPROM is a 1024-bit device with 64 16-bit registers
7325 * but only the first 32 are used by Adaptec BIOS. The loop
7326 * will range from 0 to 31.
7328 for (k = 0; k < (sizeof(*sc) / 2); k++)
7331 * Send chip select for one clock cycle.
7333 aic_outb(p, CK_2840 | CS_2840, SEECTL_2840);
7334 CLOCK_PULSE(p);
7337 * Now we're ready to send the read command followed by the
7338 * address of the 16-bit register we want to read.
7340 for (i = 0; i < seeprom_read.len; i++)
7342 temp = CS_2840 | seeprom_read.bits[i];
7343 aic_outb(p, temp, SEECTL_2840);
7344 CLOCK_PULSE(p);
7345 temp = temp ^ CK_2840;
7346 aic_outb(p, temp, SEECTL_2840);
7347 CLOCK_PULSE(p);
7350 * Send the 6 bit address (MSB first, LSB last).
7352 for (i = 5; i >= 0; i--)
7354 temp = k;
7355 temp = (temp >> i) & 1; /* Mask out all but lower bit. */
7356 temp = CS_2840 | temp;
7357 aic_outb(p, temp, SEECTL_2840);
7358 CLOCK_PULSE(p);
7359 temp = temp ^ CK_2840;
7360 aic_outb(p, temp, SEECTL_2840);
7361 CLOCK_PULSE(p);
7365 * Now read the 16 bit register. An initial 0 precedes the
7366 * register contents which begins with bit 15 (MSB) and ends
7367 * with bit 0 (LSB). The initial 0 will be shifted off the
7368 * top of our word as we let the loop run from 0 to 16.
7370 for (i = 0; i <= 16; i++)
7372 temp = CS_2840;
7373 aic_outb(p, temp, SEECTL_2840);
7374 CLOCK_PULSE(p);
7375 temp = temp ^ CK_2840;
7376 seeprom[k] = (seeprom[k] << 1) | (aic_inb(p, STATUS_2840) & DI_2840);
7377 aic_outb(p, temp, SEECTL_2840);
7378 CLOCK_PULSE(p);
7381 * The serial EEPROM has a checksum in the last word. Keep a
7382 * running checksum for all words read except for the last
7383 * word. We'll verify the checksum after all words have been
7384 * read.
7386 if (k < (sizeof(*sc) / 2) - 1)
7388 checksum = checksum + seeprom[k];
7392 * Reset the chip select for the next command cycle.
7394 aic_outb(p, 0, SEECTL_2840);
7395 CLOCK_PULSE(p);
7396 aic_outb(p, CK_2840, SEECTL_2840);
7397 CLOCK_PULSE(p);
7398 aic_outb(p, 0, SEECTL_2840);
7399 CLOCK_PULSE(p);
7402 #if 0
7403 printk("Computed checksum 0x%x, checksum read 0x%x\n", checksum, sc->checksum);
7404 printk("Serial EEPROM:");
7405 for (k = 0; k < (sizeof(*sc) / 2); k++)
7407 if (((k % 8) == 0) && (k != 0))
7409 printk("\n ");
7411 printk(" 0x%x", seeprom[k]);
7413 printk("\n");
7414 #endif
7416 if (checksum != sc->checksum)
7418 printk("aic7xxx: SEEPROM checksum error, ignoring SEEPROM settings.\n");
7419 return (0);
7422 return (1);
7423 #undef CLOCK_PULSE
7426 #define CLOCK_PULSE(p) \
7427 do { \
7428 int limit = 0; \
7429 do { \
7430 mb(); \
7431 pause_sequencer(p); /* This is just to generate some PCI */ \
7432 /* traffic so the PCI read is flushed */ \
7433 /* it shouldn't be needed, but some */ \
7434 /* chipsets do indeed appear to need */ \
7435 /* something to force PCI reads to get */ \
7436 /* flushed */ \
7437 udelay(1); /* Do nothing */ \
7438 } while (((aic_inb(p, SEECTL) & SEERDY) == 0) && (++limit < 1000)); \
7439 } while(0)
7441 /*+F*************************************************************************
7442 * Function:
7443 * acquire_seeprom
7445 * Description:
7446 * Acquires access to the memory port on PCI controllers.
7447 *-F*************************************************************************/
7448 static int
7449 acquire_seeprom(struct aic7xxx_host *p)
7453 * Request access of the memory port. When access is
7454 * granted, SEERDY will go high. We use a 1 second
7455 * timeout which should be near 1 second more than
7456 * is needed. Reason: after the 7870 chip reset, there
7457 * should be no contention.
7459 aic_outb(p, SEEMS, SEECTL);
7460 CLOCK_PULSE(p);
7461 if ((aic_inb(p, SEECTL) & SEERDY) == 0)
7463 aic_outb(p, 0, SEECTL);
7464 return (0);
7466 return (1);
7469 /*+F*************************************************************************
7470 * Function:
7471 * release_seeprom
7473 * Description:
7474 * Releases access to the memory port on PCI controllers.
7475 *-F*************************************************************************/
7476 static void
7477 release_seeprom(struct aic7xxx_host *p)
7480 * Make sure the SEEPROM is ready before we release it.
7482 CLOCK_PULSE(p);
7483 aic_outb(p, 0, SEECTL);
7484 CLOCK_PULSE(p);
7487 /*+F*************************************************************************
7488 * Function:
7489 * read_seeprom
7491 * Description:
7492 * Reads the serial EEPROM and returns 1 if successful and 0 if
7493 * not successful.
7495 * The instruction set of the 93C46/56/66 chips is as follows:
7497 * Start OP
7498 * Function Bit Code Address Data Description
7499 * -------------------------------------------------------------------
7500 * READ 1 10 A5 - A0 Reads data stored in memory,
7501 * starting at specified address
7502 * EWEN 1 00 11XXXX Write enable must precede
7503 * all programming modes
7504 * ERASE 1 11 A5 - A0 Erase register A5A4A3A2A1A0
7505 * WRITE 1 01 A5 - A0 D15 - D0 Writes register
7506 * ERAL 1 00 10XXXX Erase all registers
7507 * WRAL 1 00 01XXXX D15 - D0 Writes to all registers
7508 * EWDS 1 00 00XXXX Disables all programming
7509 * instructions
7510 * *Note: A value of X for address is a don't care condition.
7511 * *Note: The 93C56 and 93C66 have 8 address bits.
7514 * The 93C46 has a four wire interface: clock, chip select, data in, and
7515 * data out. In order to perform one of the above functions, you need
7516 * to enable the chip select for a clock period (typically a minimum of
7517 * 1 usec, with the clock high and low a minimum of 750 and 250 nsec
7518 * respectively. While the chip select remains high, you can clock in
7519 * the instructions (above) starting with the start bit, followed by the
7520 * OP code, Address, and Data (if needed). For the READ instruction, the
7521 * requested 16-bit register contents is read from the data out line but
7522 * is preceded by an initial zero (leading 0, followed by 16-bits, MSB
7523 * first). The clock cycling from low to high initiates the next data
7524 * bit to be sent from the chip.
7526 * The 78xx interface to the 93C46 serial EEPROM is through the SEECTL
7527 * register. After successful arbitration for the memory port, the
7528 * SEECS bit of the SEECTL register is connected to the chip select.
7529 * The SEECK, SEEDO, and SEEDI are connected to the clock, data out,
7530 * and data in lines respectively. The SEERDY bit of SEECTL is useful
7531 * in that it gives us an 800 nsec timer. After a write to the SEECTL
7532 * register, the SEERDY goes high 800 nsec later. The one exception
7533 * to this is when we first request access to the memory port. The
7534 * SEERDY goes high to signify that access has been granted and, for
7535 * this case, has no implied timing.
7536 *-F*************************************************************************/
7537 static int
7538 read_seeprom(struct aic7xxx_host *p, int offset,
7539 unsigned short *scarray, unsigned int len, seeprom_chip_type chip)
7541 int i = 0, k;
7542 unsigned char temp;
7543 unsigned short checksum = 0;
7544 struct seeprom_cmd {
7545 unsigned char len;
7546 unsigned char bits[3];
7548 struct seeprom_cmd seeprom_read = {3, {1, 1, 0}};
7551 * Request access of the memory port.
7553 if (acquire_seeprom(p) == 0)
7555 return (0);
7559 * Read 'len' registers of the seeprom. For the 7870, the 93C46
7560 * SEEPROM is a 1024-bit device with 64 16-bit registers but only
7561 * the first 32 are used by Adaptec BIOS. Some adapters use the
7562 * 93C56 SEEPROM which is a 2048-bit device. The loop will range
7563 * from 0 to 'len' - 1.
7565 for (k = 0; k < len; k++)
7568 * Send chip select for one clock cycle.
7570 aic_outb(p, SEEMS | SEECK | SEECS, SEECTL);
7571 CLOCK_PULSE(p);
7574 * Now we're ready to send the read command followed by the
7575 * address of the 16-bit register we want to read.
7577 for (i = 0; i < seeprom_read.len; i++)
7579 temp = SEEMS | SEECS | (seeprom_read.bits[i] << 1);
7580 aic_outb(p, temp, SEECTL);
7581 CLOCK_PULSE(p);
7582 temp = temp ^ SEECK;
7583 aic_outb(p, temp, SEECTL);
7584 CLOCK_PULSE(p);
7587 * Send the 6 or 8 bit address (MSB first, LSB last).
7589 for (i = ((int) chip - 1); i >= 0; i--)
7591 temp = k + offset;
7592 temp = (temp >> i) & 1; /* Mask out all but lower bit. */
7593 temp = SEEMS | SEECS | (temp << 1);
7594 aic_outb(p, temp, SEECTL);
7595 CLOCK_PULSE(p);
7596 temp = temp ^ SEECK;
7597 aic_outb(p, temp, SEECTL);
7598 CLOCK_PULSE(p);
7602 * Now read the 16 bit register. An initial 0 precedes the
7603 * register contents which begins with bit 15 (MSB) and ends
7604 * with bit 0 (LSB). The initial 0 will be shifted off the
7605 * top of our word as we let the loop run from 0 to 16.
7607 for (i = 0; i <= 16; i++)
7609 temp = SEEMS | SEECS;
7610 aic_outb(p, temp, SEECTL);
7611 CLOCK_PULSE(p);
7612 temp = temp ^ SEECK;
7613 scarray[k] = (scarray[k] << 1) | (aic_inb(p, SEECTL) & SEEDI);
7614 aic_outb(p, temp, SEECTL);
7615 CLOCK_PULSE(p);
7619 * The serial EEPROM should have a checksum in the last word.
7620 * Keep a running checksum for all words read except for the
7621 * last word. We'll verify the checksum after all words have
7622 * been read.
7624 if (k < (len - 1))
7626 checksum = checksum + scarray[k];
7630 * Reset the chip select for the next command cycle.
7632 aic_outb(p, SEEMS, SEECTL);
7633 CLOCK_PULSE(p);
7634 aic_outb(p, SEEMS | SEECK, SEECTL);
7635 CLOCK_PULSE(p);
7636 aic_outb(p, SEEMS, SEECTL);
7637 CLOCK_PULSE(p);
7641 * Release access to the memory port and the serial EEPROM.
7643 release_seeprom(p);
7645 #if 0
7646 printk("Computed checksum 0x%x, checksum read 0x%x\n",
7647 checksum, scarray[len - 1]);
7648 printk("Serial EEPROM:");
7649 for (k = 0; k < len; k++)
7651 if (((k % 8) == 0) && (k != 0))
7653 printk("\n ");
7655 printk(" 0x%x", scarray[k]);
7657 printk("\n");
7658 #endif
7659 if ( (checksum != scarray[len - 1]) || (checksum == 0) )
7661 return (0);
7664 return (1);
7667 /*+F*************************************************************************
7668 * Function:
7669 * read_brdctl
7671 * Description:
7672 * Reads the BRDCTL register.
7673 *-F*************************************************************************/
7674 static unsigned char
7675 read_brdctl(struct aic7xxx_host *p)
7677 unsigned char brdctl, value;
7680 * Make sure the SEEPROM is ready before we access it
7682 CLOCK_PULSE(p);
7683 if (p->features & AHC_ULTRA2)
7685 brdctl = BRDRW_ULTRA2;
7686 aic_outb(p, brdctl, BRDCTL);
7687 CLOCK_PULSE(p);
7688 value = aic_inb(p, BRDCTL);
7689 CLOCK_PULSE(p);
7690 return(value);
7692 brdctl = BRDRW;
7693 if ( !((p->chip & AHC_CHIPID_MASK) == AHC_AIC7895) ||
7694 (p->flags & AHC_CHNLB) )
7696 brdctl |= BRDCS;
7698 aic_outb(p, brdctl, BRDCTL);
7699 CLOCK_PULSE(p);
7700 value = aic_inb(p, BRDCTL);
7701 CLOCK_PULSE(p);
7702 aic_outb(p, 0, BRDCTL);
7703 CLOCK_PULSE(p);
7704 return (value);
7707 /*+F*************************************************************************
7708 * Function:
7709 * write_brdctl
7711 * Description:
7712 * Writes a value to the BRDCTL register.
7713 *-F*************************************************************************/
7714 static void
7715 write_brdctl(struct aic7xxx_host *p, unsigned char value)
7717 unsigned char brdctl;
7720 * Make sure the SEEPROM is ready before we access it
7722 CLOCK_PULSE(p);
7723 if (p->features & AHC_ULTRA2)
7725 brdctl = value;
7726 aic_outb(p, brdctl, BRDCTL);
7727 CLOCK_PULSE(p);
7728 brdctl |= BRDSTB_ULTRA2;
7729 aic_outb(p, brdctl, BRDCTL);
7730 CLOCK_PULSE(p);
7731 brdctl &= ~BRDSTB_ULTRA2;
7732 aic_outb(p, brdctl, BRDCTL);
7733 CLOCK_PULSE(p);
7734 read_brdctl(p);
7735 CLOCK_PULSE(p);
7737 else
7739 brdctl = BRDSTB;
7740 if ( !((p->chip & AHC_CHIPID_MASK) == AHC_AIC7895) ||
7741 (p->flags & AHC_CHNLB) )
7743 brdctl |= BRDCS;
7745 brdctl = BRDSTB | BRDCS;
7746 aic_outb(p, brdctl, BRDCTL);
7747 CLOCK_PULSE(p);
7748 brdctl |= value;
7749 aic_outb(p, brdctl, BRDCTL);
7750 CLOCK_PULSE(p);
7751 brdctl &= ~BRDSTB;
7752 aic_outb(p, brdctl, BRDCTL);
7753 CLOCK_PULSE(p);
7754 brdctl &= ~BRDCS;
7755 aic_outb(p, brdctl, BRDCTL);
7756 CLOCK_PULSE(p);
7760 #undef CLOCK_PULSE
7762 /*+F*************************************************************************
7763 * Function:
7764 * aic785x_cable_detect
7766 * Description:
7767 * Detect the cables that are present on aic785x class controller chips
7768 *-F*************************************************************************/
7769 static void
7770 aic785x_cable_detect(struct aic7xxx_host *p, int *int_50,
7771 int *ext_present, int *eeprom)
7773 unsigned char brdctl;
7775 aic_outb(p, BRDRW | BRDCS, BRDCTL);
7776 udelay(1);
7777 aic_outb(p, 0, BRDCTL);
7778 udelay(1);
7779 brdctl = aic_inb(p, BRDCTL);
7780 udelay(1);
7781 *int_50 = !(brdctl & BRDDAT5);
7782 *ext_present = !(brdctl & BRDDAT6);
7783 *eeprom = (aic_inb(p, SPIOCAP) & EEPROM);
7786 /*+F*************************************************************************
7787 * Function:
7788 * aic787x_cable_detect
7790 * Description:
7791 * Detect the cables that are present on aic787x class controller chips
7793 * NOTE: This functions assumes the SEEPROM will have already been aquired
7794 * prior to invocation of this function.
7795 *-F*************************************************************************/
7796 static void
7797 aic787x_cable_detect(struct aic7xxx_host *p, int *int_50, int *int_68,
7798 int *ext_present, int *eeprom)
7800 unsigned char brdctl;
7803 * First read the status of our cables. Set the rom bank to
7804 * 0 since the bank setting serves as a multiplexor for the
7805 * cable detection logic. BRDDAT5 controls the bank switch.
7807 write_brdctl(p, 0);
7810 * Now we read the state of the two internal connectors. BRDDAT6
7811 * is internal 50, BRDDAT7 is internal 68. For each, the cable is
7812 * present if the bit is 0
7814 brdctl = read_brdctl(p);
7815 *int_50 = !(brdctl & BRDDAT6);
7816 *int_68 = !(brdctl & BRDDAT7);
7819 * Set the bank bit in brdctl and then read the external cable state
7820 * and the EEPROM status
7822 write_brdctl(p, BRDDAT5);
7823 brdctl = read_brdctl(p);
7825 *ext_present = !(brdctl & BRDDAT6);
7826 *eeprom = !(brdctl & BRDDAT7);
7829 * We're done, the calling function will release the SEEPROM for us
7833 /*+F*************************************************************************
7834 * Function:
7835 * aic787x_ultra2_term_detect
7837 * Description:
7838 * Detect the termination settings present on ultra2 class controllers
7840 * NOTE: This functions assumes the SEEPROM will have already been aquired
7841 * prior to invocation of this function.
7842 *-F*************************************************************************/
7843 static void
7844 aic7xxx_ultra2_term_detect(struct aic7xxx_host *p, int *enableSE_low,
7845 int *enableSE_high, int *enableLVD_low,
7846 int *enableLVD_high, int *eprom_present)
7848 unsigned char brdctl;
7850 brdctl = read_brdctl(p);
7852 *eprom_present = (brdctl & BRDDAT7);
7853 *enableSE_high = (brdctl & BRDDAT6);
7854 *enableSE_low = (brdctl & BRDDAT5);
7855 *enableLVD_high = (brdctl & BRDDAT4);
7856 *enableLVD_low = (brdctl & BRDDAT3);
7859 /*+F*************************************************************************
7860 * Function:
7861 * configure_termination
7863 * Description:
7864 * Configures the termination settings on PCI adapters that have
7865 * SEEPROMs available.
7866 *-F*************************************************************************/
7867 static void
7868 configure_termination(struct aic7xxx_host *p)
7870 int internal50_present = 0;
7871 int internal68_present = 0;
7872 int external_present = 0;
7873 int eprom_present = 0;
7874 int enableSE_low = 0;
7875 int enableSE_high = 0;
7876 int enableLVD_low = 0;
7877 int enableLVD_high = 0;
7878 unsigned char brddat = 0;
7879 unsigned char max_target = 0;
7880 unsigned char sxfrctl1 = aic_inb(p, SXFRCTL1);
7882 if (acquire_seeprom(p))
7884 if (p->features & (AHC_WIDE|AHC_TWIN))
7885 max_target = 16;
7886 else
7887 max_target = 8;
7888 aic_outb(p, SEEMS | SEECS, SEECTL);
7889 sxfrctl1 &= ~STPWEN;
7890 if ( (p->adapter_control & CFAUTOTERM) ||
7891 (p->features & AHC_NEW_AUTOTERM) )
7893 if ( (p->adapter_control & CFAUTOTERM) &&
7894 !(p->features & AHC_NEW_AUTOTERM) )
7896 printk(KERN_INFO "(scsi%d) Warning - detected auto-termination\n",
7897 p->host_no);
7898 printk(KERN_INFO "(scsi%d) Please verify driver detected settings are "
7899 "correct.\n", p->host_no);
7900 printk(KERN_INFO "(scsi%d) If not, then please properly set the device "
7901 "termination\n", p->host_no);
7902 printk(KERN_INFO "(scsi%d) in the Adaptec SCSI BIOS by hitting CTRL-A "
7903 "when prompted\n", p->host_no);
7904 printk(KERN_INFO "(scsi%d) during machine bootup.\n", p->host_no);
7906 /* Configure auto termination. */
7908 if (p->features & AHC_NEW_AUTOTERM)
7910 if (aic7xxx_override_term == -1)
7911 aic7xxx_ultra2_term_detect(p, &enableSE_low, &enableSE_high,
7912 &enableLVD_low, &enableLVD_high,
7913 &eprom_present);
7914 if (!(p->adapter_control & CFSEAUTOTERM))
7916 enableSE_low = (p->adapter_control & CFSTERM);
7917 enableSE_high = (p->adapter_control & CFWSTERM);
7919 if (!(p->adapter_control & CFAUTOTERM))
7921 enableLVD_low = enableLVD_high = (p->adapter_control & CFLVDSTERM);
7923 internal50_present = 0;
7924 internal68_present = 1;
7925 external_present = 1;
7927 else if ( (p->chip & AHC_CHIPID_MASK) >= AHC_AIC7870 )
7929 aic787x_cable_detect(p, &internal50_present, &internal68_present,
7930 &external_present, &eprom_present);
7932 else
7934 aic785x_cable_detect(p, &internal50_present, &external_present,
7935 &eprom_present);
7938 if (max_target <= 8)
7939 internal68_present = 0;
7941 if ( !(p->features & AHC_NEW_AUTOTERM) )
7943 if (max_target > 8)
7945 printk(KERN_INFO "(scsi%d) Cables present (Int-50 %s, Int-68 %s, "
7946 "Ext-68 %s)\n", p->host_no,
7947 internal50_present ? "YES" : "NO",
7948 internal68_present ? "YES" : "NO",
7949 external_present ? "YES" : "NO");
7951 else
7953 printk(KERN_INFO "(scsi%d) Cables present (Int-50 %s, Ext-50 %s)\n",
7954 p->host_no,
7955 internal50_present ? "YES" : "NO",
7956 external_present ? "YES" : "NO");
7959 if (aic7xxx_verbose & VERBOSE_PROBE2)
7960 printk(KERN_INFO "(scsi%d) EEPROM %s present.\n", p->host_no,
7961 eprom_present ? "is" : "is not");
7964 * Now set the termination based on what we found. BRDDAT6
7965 * controls wide termination enable.
7966 * Flash Enable = BRDDAT7
7967 * SE High Term Enable = BRDDAT6
7968 * SE Low Term Enable = BRDDAT5 (7890)
7969 * LVD High Term Enable = BRDDAT4 (7890)
7971 if ( !(p->features & AHC_NEW_AUTOTERM) &&
7972 (internal50_present && internal68_present && external_present) )
7974 printk(KERN_INFO "(scsi%d) Illegal cable configuration!! Only two\n",
7975 p->host_no);
7976 printk(KERN_INFO "(scsi%d) connectors on the SCSI controller may be "
7977 "in use at a time!\n", p->host_no);
7979 * Force termination (low and high byte) on. This is safer than
7980 * leaving it completely off, especially since this message comes
7981 * most often from motherboard controllers that don't even have 3
7982 * connectors, but instead are failing the cable detection.
7984 internal50_present = external_present = 0;
7985 enableSE_high = enableSE_low = 1;
7988 if ((max_target > 8) &&
7989 ((external_present == 0) || (internal68_present == 0) ||
7990 (enableSE_high != 0)))
7992 brddat |= BRDDAT6;
7993 p->flags |= AHC_TERM_ENB_SE_HIGH;
7994 if (aic7xxx_verbose & VERBOSE_PROBE2)
7995 printk(KERN_INFO "(scsi%d) SE High byte termination Enabled\n",
7996 p->host_no);
7999 if ( (((internal50_present ? 1 : 0) +
8000 (internal68_present ? 1 : 0) +
8001 (external_present ? 1 : 0)) <= 1) ||
8002 (enableSE_low != 0) )
8004 if (p->features & AHC_NEW_AUTOTERM)
8005 brddat |= BRDDAT5;
8006 else
8007 sxfrctl1 |= STPWEN;
8008 p->flags |= AHC_TERM_ENB_SE_LOW;
8009 if (aic7xxx_verbose & VERBOSE_PROBE2)
8010 printk(KERN_INFO "(scsi%d) SE Low byte termination Enabled\n",
8011 p->host_no);
8014 if (enableLVD_low != 0)
8016 sxfrctl1 |= STPWEN;
8017 p->flags |= AHC_TERM_ENB_LVD;
8018 if (aic7xxx_verbose & VERBOSE_PROBE2)
8019 printk(KERN_INFO "(scsi%d) LVD Low byte termination Enabled\n",
8020 p->host_no);
8023 if (enableLVD_high != 0)
8025 brddat |= BRDDAT4;
8026 if (aic7xxx_verbose & VERBOSE_PROBE2)
8027 printk(KERN_INFO "(scsi%d) LVD High byte termination Enabled\n",
8028 p->host_no);
8031 else
8033 if (p->adapter_control & CFSTERM)
8035 if (p->features & AHC_NEW_AUTOTERM)
8036 brddat |= BRDDAT5;
8037 else
8038 sxfrctl1 |= STPWEN;
8039 if (aic7xxx_verbose & VERBOSE_PROBE2)
8040 printk(KERN_INFO "(scsi%d) SE Low byte termination Enabled\n",
8041 p->host_no);
8044 if (p->adapter_control & CFWSTERM)
8046 brddat |= BRDDAT6;
8047 if (aic7xxx_verbose & VERBOSE_PROBE2)
8048 printk(KERN_INFO "(scsi%d) SE High byte termination Enabled\n",
8049 p->host_no);
8052 aic_outb(p, sxfrctl1, SXFRCTL1);
8053 write_brdctl(p, brddat);
8054 release_seeprom(p);
8058 /*+F*************************************************************************
8059 * Function:
8060 * detect_maxscb
8062 * Description:
8063 * Detects the maximum number of SCBs for the controller and returns
8064 * the count and a mask in p (p->maxscbs, p->qcntmask).
8065 *-F*************************************************************************/
8066 static void
8067 detect_maxscb(struct aic7xxx_host *p)
8069 int i;
8072 * It's possible that we've already done this for multichannel
8073 * adapters.
8075 if (p->scb_data->maxhscbs == 0)
8078 * We haven't initialized the SCB settings yet. Walk the SCBs to
8079 * determince how many there are.
8081 aic_outb(p, 0, FREE_SCBH);
8083 for (i = 0; i < AIC7XXX_MAXSCB; i++)
8085 aic_outb(p, i, SCBPTR);
8086 aic_outb(p, i, SCB_CONTROL);
8087 if (aic_inb(p, SCB_CONTROL) != i)
8088 break;
8089 aic_outb(p, 0, SCBPTR);
8090 if (aic_inb(p, SCB_CONTROL) != 0)
8091 break;
8093 aic_outb(p, i, SCBPTR);
8094 aic_outb(p, 0, SCB_CONTROL); /* Clear the control byte. */
8095 aic_outb(p, i + 1, SCB_NEXT); /* Set the next pointer. */
8096 aic_outb(p, SCB_LIST_NULL, SCB_TAG); /* Make the tag invalid. */
8097 aic_outb(p, SCB_LIST_NULL, SCB_BUSYTARGETS); /* no busy untagged */
8098 aic_outb(p, SCB_LIST_NULL, SCB_BUSYTARGETS+1);/* targets active yet */
8099 aic_outb(p, SCB_LIST_NULL, SCB_BUSYTARGETS+2);
8100 aic_outb(p, SCB_LIST_NULL, SCB_BUSYTARGETS+3);
8103 /* Make sure the last SCB terminates the free list. */
8104 aic_outb(p, i - 1, SCBPTR);
8105 aic_outb(p, SCB_LIST_NULL, SCB_NEXT);
8107 /* Ensure we clear the first (0) SCBs control byte. */
8108 aic_outb(p, 0, SCBPTR);
8109 aic_outb(p, 0, SCB_CONTROL);
8111 p->scb_data->maxhscbs = i;
8113 * Use direct indexing instead for speed
8115 if ( i == AIC7XXX_MAXSCB )
8116 p->flags &= ~AHC_PAGESCBS;
8121 /*+F*************************************************************************
8122 * Function:
8123 * aic7xxx_register
8125 * Description:
8126 * Register a Adaptec aic7xxx chip SCSI controller with the kernel.
8127 *-F*************************************************************************/
8128 static int
8129 aic7xxx_register(Scsi_Host_Template *template, struct aic7xxx_host *p,
8130 int reset_delay)
8132 int i, result;
8133 int max_targets;
8134 int found = 1;
8135 unsigned char term, scsi_conf;
8136 struct Scsi_Host *host;
8138 host = p->host;
8140 p->scb_data->maxscbs = AIC7XXX_MAXSCB;
8141 host->can_queue = AIC7XXX_MAXSCB;
8142 host->cmd_per_lun = 3;
8143 host->sg_tablesize = AIC7XXX_MAX_SG;
8144 host->select_queue_depths = aic7xxx_select_queue_depth;
8145 host->this_id = p->scsi_id;
8146 host->io_port = p->base;
8147 host->n_io_port = 0xFF;
8148 host->base = p->mbase;
8149 host->irq = p->irq;
8150 if (p->features & AHC_WIDE)
8152 host->max_id = 16;
8154 if (p->features & AHC_TWIN)
8156 host->max_channel = 1;
8159 p->host = host;
8160 p->host_no = host->host_no;
8161 host->unique_id = p->instance;
8162 p->isr_count = 0;
8163 p->next = NULL;
8164 p->completeq.head = NULL;
8165 p->completeq.tail = NULL;
8166 scbq_init(&p->scb_data->free_scbs);
8167 scbq_init(&p->waiting_scbs);
8168 init_timer(&p->dev_timer);
8169 p->dev_timer.data = (unsigned long)p;
8170 p->dev_timer.function = (void *)aic7xxx_timer;
8171 p->dev_timer_active = 0;
8174 * We currently have no commands of any type
8176 p->qinfifonext = 0;
8177 p->qoutfifonext = 0;
8179 for (i = 0; i < MAX_TARGETS; i++)
8181 p->dev_commands_sent[i] = 0;
8182 p->dev_flags[i] = 0;
8183 p->dev_active_cmds[i] = 0;
8184 p->dev_last_queue_full[i] = 0;
8185 p->dev_last_queue_full_count[i] = 0;
8186 p->dev_max_queue_depth[i] = 1;
8187 p->dev_temp_queue_depth[i] = 1;
8188 p->dev_expires[i] = 0;
8189 scbq_init(&p->delayed_scbs[i]);
8192 printk(KERN_INFO "(scsi%d) <%s> found at ", p->host_no,
8193 board_names[p->board_name_index]);
8194 switch(p->chip)
8196 case (AHC_AIC7770|AHC_EISA):
8197 printk("EISA slot %d\n", p->pci_device_fn);
8198 break;
8199 case (AHC_AIC7770|AHC_VL):
8200 printk("VLB slot %d\n", p->pci_device_fn);
8201 break;
8202 default:
8203 printk("PCI %d/%d/%d\n", p->pci_bus, PCI_SLOT(p->pci_device_fn),
8204 PCI_FUNC(p->pci_device_fn));
8205 break;
8207 if (p->features & AHC_TWIN)
8209 printk(KERN_INFO "(scsi%d) Twin Channel, A SCSI ID %d, B SCSI ID %d, ",
8210 p->host_no, p->scsi_id, p->scsi_id_b);
8212 else
8214 char *channel;
8216 channel = "";
8218 if ((p->flags & AHC_MULTI_CHANNEL) != 0)
8220 channel = " A";
8222 if ( (p->flags & (AHC_CHNLB|AHC_CHNLC)) != 0 )
8224 channel = (p->flags & AHC_CHNLB) ? " B" : " C";
8227 if (p->features & AHC_WIDE)
8229 printk(KERN_INFO "(scsi%d) Wide ", p->host_no);
8231 else
8233 printk(KERN_INFO "(scsi%d) Narrow ", p->host_no);
8235 printk("Channel%s, SCSI ID=%d, ", channel, p->scsi_id);
8237 aic_outb(p, 0, SEQ_FLAGS);
8240 * We are starting to do real work on the card....it's possible we could
8241 * generate some spurious interrupts at this point, especially in the
8242 * event of a PCI error or some such. If there are other devices already
8243 * registered on the same interrupt as us, this could cause the machine
8244 * to lock up. So, we disable the interrupt this card is on until we
8245 * finish our card setup. We only need to do this for modules, if we are
8246 * compiled into the kernel then interrupts are already off during this
8247 * part of the code.
8249 #ifdef MODULE
8250 disable_irq(p->irq);
8251 #endif
8253 detect_maxscb(p);
8256 printk("%d/%d SCBs\n", p->scb_data->maxhscbs, p->scb_data->maxscbs);
8257 if (aic7xxx_verbose & VERBOSE_PROBE2)
8259 printk(KERN_INFO "(scsi%d) BIOS %sabled, IO Port 0x%lx, IRQ %d\n",
8260 p->host_no, (p->flags & AHC_BIOS_ENABLED) ? "en" : "dis",
8261 p->base, p->irq);
8262 printk(KERN_INFO "(scsi%d) IO Memory at 0x%lx, MMAP Memory at 0x%lx\n",
8263 p->host_no, p->mbase, (unsigned long)p->maddr);
8266 #ifdef CONFIG_PCI
8268 * Now that we know our instance number, we can set the flags we need to
8269 * force termination if need be.
8271 if (aic7xxx_stpwlev != -1)
8274 * This option only applies to PCI controllers.
8276 if ( (p->chip & ~AHC_CHIPID_MASK) == AHC_PCI)
8278 unsigned char devconfig;
8280 #if LINUX_VERSION_CODE > KERNEL_VERSION(2,1,92)
8281 pci_read_config_byte(p->pdev, DEVCONFIG, &devconfig);
8282 #else
8283 pcibios_read_config_byte(p->pci_bus, p->pci_device_fn,
8284 DEVCONFIG, &devconfig);
8285 #endif
8286 if ( (aic7xxx_stpwlev >> p->instance) & 0x01 )
8288 devconfig |= STPWLEVEL;
8289 if (aic7xxx_verbose & VERBOSE_PROBE2)
8290 printk("(scsi%d) Force setting STPWLEVEL bit\n", p->host_no);
8292 else
8294 devconfig &= ~STPWLEVEL;
8295 if (aic7xxx_verbose & VERBOSE_PROBE2)
8296 printk("(scsi%d) Force clearing STPWLEVEL bit\n", p->host_no);
8298 #if LINUX_VERSION_CODE > KERNEL_VERSION(2,1,92)
8299 pci_write_config_byte(p->pdev, DEVCONFIG, devconfig);
8300 #else
8301 pcibios_write_config_byte(p->pci_bus, p->pci_device_fn,
8302 DEVCONFIG, devconfig);
8303 #endif
8306 #endif
8309 * That took care of devconfig and stpwlev, now for the actual termination
8310 * settings.
8312 if (aic7xxx_override_term != -1)
8315 * Again, this only applies to PCI controllers. We don't have problems
8316 * with the termination on 274x controllers to the best of my knowledge.
8318 if ( (p->chip & ~AHC_CHIPID_MASK) == AHC_PCI)
8320 unsigned char term_override;
8322 term_override = ( (aic7xxx_override_term >> (p->instance * 4)) & 0x0f);
8323 p->adapter_control &=
8324 ~(CFSTERM|CFWSTERM|CFLVDSTERM|CFAUTOTERM|CFSEAUTOTERM);
8325 if ( (p->features & AHC_ULTRA2) && (term_override & 0x0c) )
8327 p->adapter_control |= CFLVDSTERM;
8329 if (term_override & 0x02)
8331 p->adapter_control |= CFWSTERM;
8333 if (term_override & 0x01)
8335 p->adapter_control |= CFSTERM;
8340 if ( (p->flags & AHC_SEEPROM_FOUND) || (aic7xxx_override_term != -1) )
8342 if (p->features & AHC_SPIOCAP)
8344 if ( aic_inb(p, SPIOCAP) & SSPIOCPS )
8346 * Update the settings in sxfrctl1 to match the termination
8347 * settings.
8349 configure_termination(p);
8351 else if ((p->chip & AHC_CHIPID_MASK) >= AHC_AIC7870)
8353 configure_termination(p);
8358 * Set the SCSI Id, SXFRCTL0, SXFRCTL1, and SIMODE1, for both channels
8360 if (p->features & AHC_TWIN)
8362 /* Select channel B */
8363 aic_outb(p, aic_inb(p, SBLKCTL) | SELBUSB, SBLKCTL);
8365 if ((p->flags & AHC_SEEPROM_FOUND) || (aic7xxx_override_term != -1))
8366 term = (aic_inb(p, SXFRCTL1) & STPWEN);
8367 else
8368 term = ((p->flags & AHC_TERM_ENB_B) ? STPWEN : 0);
8370 aic_outb(p, p->scsi_id_b, SCSIID);
8371 scsi_conf = aic_inb(p, SCSICONF + 1);
8372 aic_outb(p, DFON | SPIOEN, SXFRCTL0);
8373 aic_outb(p, (scsi_conf & ENSPCHK) | aic7xxx_seltime | term |
8374 ENSTIMER | ACTNEGEN, SXFRCTL1);
8375 aic_outb(p, 0, SIMODE0);
8376 aic_outb(p, ENSELTIMO | ENSCSIRST | ENSCSIPERR, SIMODE1);
8377 aic_outb(p, 0, SCSIRATE);
8379 /* Select channel A */
8380 aic_outb(p, aic_inb(p, SBLKCTL) & ~SELBUSB, SBLKCTL);
8383 if (p->features & AHC_ULTRA2)
8385 aic_outb(p, p->scsi_id, SCSIID_ULTRA2);
8387 else
8389 aic_outb(p, p->scsi_id, SCSIID);
8391 if ((p->flags & AHC_SEEPROM_FOUND) || (aic7xxx_override_term != -1))
8392 term = (aic_inb(p, SXFRCTL1) & STPWEN);
8393 else
8394 term = ((p->flags & (AHC_TERM_ENB_A|AHC_TERM_ENB_LVD)) ? STPWEN : 0);
8395 scsi_conf = aic_inb(p, SCSICONF);
8396 aic_outb(p, DFON | SPIOEN, SXFRCTL0);
8397 aic_outb(p, (scsi_conf & ENSPCHK) | aic7xxx_seltime | term |
8398 ENSTIMER | ACTNEGEN, SXFRCTL1);
8399 aic_outb(p, 0, SIMODE0);
8401 * If we are a cardbus adapter then don't enable SCSI reset detection.
8402 * We shouldn't likely be sharing SCSI busses with someone else, and
8403 * if we don't have a cable currently plugged into the controller then
8404 * we won't have a power source for the SCSI termination, which means
8405 * we'll see infinite incoming bus resets.
8407 if(p->flags & AHC_NO_STPWR)
8408 aic_outb(p, ENSELTIMO | ENSCSIPERR, SIMODE1);
8409 else
8410 aic_outb(p, ENSELTIMO | ENSCSIRST | ENSCSIPERR, SIMODE1);
8411 aic_outb(p, 0, SCSIRATE);
8412 if ( p->features & AHC_ULTRA2)
8413 aic_outb(p, 0, SCSIOFFSET);
8416 * Look at the information that board initialization or the board
8417 * BIOS has left us. In the lower four bits of each target's
8418 * scratch space any value other than 0 indicates that we should
8419 * initiate synchronous transfers. If it's zero, the user or the
8420 * BIOS has decided to disable synchronous negotiation to that
8421 * target so we don't activate the needsdtr flag.
8423 if ((p->features & (AHC_TWIN|AHC_WIDE)) == 0)
8425 max_targets = 8;
8427 else
8429 max_targets = 16;
8432 if (!(aic7xxx_no_reset))
8435 * If we reset the bus, then clear the transfer settings, else leave
8436 * them be
8438 for (i = 0; i < max_targets; i++)
8440 aic_outb(p, 0, TARG_SCSIRATE + i);
8441 if (p->features & AHC_ULTRA2)
8443 aic_outb(p, 0, TARG_OFFSET + i);
8445 p->transinfo[i].cur_offset = 0;
8446 p->transinfo[i].cur_period = 0;
8447 p->transinfo[i].cur_width = MSG_EXT_WDTR_BUS_8_BIT;
8451 * If we reset the bus, then clear the transfer settings, else leave
8452 * them be.
8454 aic_outb(p, 0, ULTRA_ENB);
8455 aic_outb(p, 0, ULTRA_ENB + 1);
8456 p->ultraenb = 0;
8460 * Allocate enough hardware scbs to handle the maximum number of
8461 * concurrent transactions we can have. We have to make sure that
8462 * the allocated memory is contiguous memory. The Linux kmalloc
8463 * routine should only allocate contiguous memory, but note that
8464 * this could be a problem if kmalloc() is changed.
8467 size_t array_size;
8468 unsigned int hscb_physaddr;
8470 array_size = p->scb_data->maxscbs * sizeof(struct aic7xxx_hwscb);
8471 if (p->scb_data->hscbs == NULL)
8473 /* pci_alloc_consistent enforces the alignment already and
8474 * clears the area as well.
8476 p->scb_data->hscbs = pci_alloc_consistent(p->pdev, array_size,
8477 &p->scb_data->hscbs_dma);
8478 /* We have to use pci_free_consistent, not kfree */
8479 p->scb_data->hscb_kmalloc_ptr = NULL;
8480 p->scb_data->hscbs_dma_len = array_size;
8482 if (p->scb_data->hscbs == NULL)
8484 printk("(scsi%d) Unable to allocate hardware SCB array; "
8485 "failing detection.\n", p->host_no);
8486 aic_outb(p, 0, SIMODE1);
8487 #ifdef MODULE
8488 enable_irq(p->irq);
8489 #endif
8490 p->irq = 0;
8491 return(0);
8494 hscb_physaddr = p->scb_data->hscbs_dma;
8495 aic_outb(p, hscb_physaddr & 0xFF, HSCB_ADDR);
8496 aic_outb(p, (hscb_physaddr >> 8) & 0xFF, HSCB_ADDR + 1);
8497 aic_outb(p, (hscb_physaddr >> 16) & 0xFF, HSCB_ADDR + 2);
8498 aic_outb(p, (hscb_physaddr >> 24) & 0xFF, HSCB_ADDR + 3);
8500 /* Set up the fifo areas at the same time */
8501 p->untagged_scbs = pci_alloc_consistent(p->pdev, 3*256, &p->fifo_dma);
8502 if (p->untagged_scbs == NULL)
8504 printk("(scsi%d) Unable to allocate hardware FIFO arrays; "
8505 "failing detection.\n", p->host_no);
8506 p->irq = 0;
8507 return(0);
8510 p->qoutfifo = p->untagged_scbs + 256;
8511 p->qinfifo = p->qoutfifo + 256;
8512 for (i = 0; i < 256; i++)
8514 p->untagged_scbs[i] = SCB_LIST_NULL;
8515 p->qinfifo[i] = SCB_LIST_NULL;
8516 p->qoutfifo[i] = SCB_LIST_NULL;
8519 hscb_physaddr = p->fifo_dma;
8520 aic_outb(p, hscb_physaddr & 0xFF, SCBID_ADDR);
8521 aic_outb(p, (hscb_physaddr >> 8) & 0xFF, SCBID_ADDR + 1);
8522 aic_outb(p, (hscb_physaddr >> 16) & 0xFF, SCBID_ADDR + 2);
8523 aic_outb(p, (hscb_physaddr >> 24) & 0xFF, SCBID_ADDR + 3);
8526 /* The Q-FIFOs we just set up are all empty */
8527 aic_outb(p, 0, QINPOS);
8528 aic_outb(p, 0, KERNEL_QINPOS);
8529 aic_outb(p, 0, QOUTPOS);
8531 if(p->features & AHC_QUEUE_REGS)
8533 aic_outb(p, SCB_QSIZE_256, QOFF_CTLSTA);
8534 aic_outb(p, 0, SDSCB_QOFF);
8535 aic_outb(p, 0, SNSCB_QOFF);
8536 aic_outb(p, 0, HNSCB_QOFF);
8540 * We don't have any waiting selections or disconnected SCBs.
8542 aic_outb(p, SCB_LIST_NULL, WAITING_SCBH);
8543 aic_outb(p, SCB_LIST_NULL, DISCONNECTED_SCBH);
8546 * Message out buffer starts empty
8548 aic_outb(p, MSG_NOOP, MSG_OUT);
8549 aic_outb(p, MSG_NOOP, LAST_MSG);
8552 * Set all the other asundry items that haven't been set yet.
8553 * This includes just dumping init values to a lot of registers simply
8554 * to make sure they've been touched and are ready for use parity wise
8555 * speaking.
8557 aic_outb(p, 0, TMODE_CMDADDR);
8558 aic_outb(p, 0, TMODE_CMDADDR + 1);
8559 aic_outb(p, 0, TMODE_CMDADDR + 2);
8560 aic_outb(p, 0, TMODE_CMDADDR + 3);
8561 aic_outb(p, 0, TMODE_CMDADDR_NEXT);
8564 * Link us into the list of valid hosts
8566 p->next = first_aic7xxx;
8567 first_aic7xxx = p;
8570 * Allocate the first set of scbs for this controller. This is to stream-
8571 * line code elsewhere in the driver. If we have to check for the existence
8572 * of scbs in certain code sections, it slows things down. However, as
8573 * soon as we register the IRQ for this card, we could get an interrupt that
8574 * includes possibly the SCSI_RSTI interrupt. If we catch that interrupt
8575 * then we are likely to segfault if we don't have at least one chunk of
8576 * SCBs allocated or add checks all through the reset code to make sure
8577 * that the SCBs have been allocated which is an invalid running condition
8578 * and therefore I think it's preferable to simply pre-allocate the first
8579 * chunk of SCBs.
8581 aic7xxx_allocate_scb(p);
8584 * Load the sequencer program, then re-enable the board -
8585 * resetting the AIC-7770 disables it, leaving the lights
8586 * on with nobody home.
8588 aic7xxx_loadseq(p);
8591 * Make sure the AUTOFLUSHDIS bit is *not* set in the SBLKCTL register
8593 aic_outb(p, aic_inb(p, SBLKCTL) & ~AUTOFLUSHDIS, SBLKCTL);
8595 if ( (p->chip & AHC_CHIPID_MASK) == AHC_AIC7770 )
8597 aic_outb(p, ENABLE, BCTL); /* Enable the boards BUS drivers. */
8600 if ( !(aic7xxx_no_reset) )
8602 if (p->features & AHC_TWIN)
8604 if (aic7xxx_verbose & VERBOSE_PROBE2)
8605 printk(KERN_INFO "(scsi%d) Resetting channel B\n", p->host_no);
8606 aic_outb(p, aic_inb(p, SBLKCTL) | SELBUSB, SBLKCTL);
8607 aic7xxx_reset_current_bus(p);
8608 aic_outb(p, aic_inb(p, SBLKCTL) & ~SELBUSB, SBLKCTL);
8610 /* Reset SCSI bus A. */
8611 if (aic7xxx_verbose & VERBOSE_PROBE2)
8612 { /* In case we are a 3940, 3985, or 7895, print the right channel */
8613 char *channel = "";
8614 if (p->flags & AHC_MULTI_CHANNEL)
8616 channel = " A";
8617 if (p->flags & (AHC_CHNLB|AHC_CHNLC))
8618 channel = (p->flags & AHC_CHNLB) ? " B" : " C";
8620 printk(KERN_INFO "(scsi%d) Resetting channel%s\n", p->host_no, channel);
8623 aic7xxx_reset_current_bus(p);
8626 * Delay for the reset delay by setting the timer, this will delay
8627 * future commands sent to any devices.
8629 p->flags |= AHC_RESET_DELAY;
8630 for(i=0; i<MAX_TARGETS; i++)
8632 p->dev_expires[i] = jiffies + (4 * HZ);
8633 p->dev_timer_active |= (0x01 << i);
8635 p->dev_timer.expires = p->dev_expires[p->scsi_id];
8636 add_timer(&p->dev_timer);
8637 p->dev_timer_active |= (0x01 << MAX_TARGETS);
8639 else
8641 if (!reset_delay)
8643 printk(KERN_INFO "(scsi%d) Not resetting SCSI bus. Note: Don't use "
8644 "the no_reset\n", p->host_no);
8645 printk(KERN_INFO "(scsi%d) option unless you have a verifiable need "
8646 "for it.\n", p->host_no);
8651 * Register IRQ with the kernel. Only allow sharing IRQs with
8652 * PCI devices.
8654 if (!(p->chip & AHC_PCI))
8656 result = (request_irq(p->irq, do_aic7xxx_isr, 0, "aic7xxx", p));
8658 else
8660 result = (request_irq(p->irq, do_aic7xxx_isr, SA_SHIRQ,
8661 "aic7xxx", p));
8662 if (result < 0)
8664 result = (request_irq(p->irq, do_aic7xxx_isr, SA_INTERRUPT | SA_SHIRQ,
8665 "aic7xxx", p));
8668 if (result < 0)
8670 printk(KERN_WARNING "(scsi%d) Couldn't register IRQ %d, ignoring "
8671 "controller.\n", p->host_no, p->irq);
8672 aic_outb(p, 0, SIMODE1);
8673 #ifdef MODULE
8674 enable_irq(p->irq);
8675 #endif
8676 p->irq = 0;
8677 return (0);
8680 if(aic_inb(p, INTSTAT) & INT_PEND)
8681 printk(INFO_LEAD "spurious interrupt during configuration, cleared.\n",
8682 p->host_no, -1, -1 , -1);
8683 aic7xxx_clear_intstat(p);
8685 #ifdef MODULE
8686 enable_irq(p->irq);
8687 #endif
8689 unpause_sequencer(p, /* unpause_always */ TRUE);
8691 return (found);
8694 /*+F*************************************************************************
8695 * Function:
8696 * aic7xxx_chip_reset
8698 * Description:
8699 * Perform a chip reset on the aic7xxx SCSI controller. The controller
8700 * is paused upon return.
8701 *-F*************************************************************************/
8703 aic7xxx_chip_reset(struct aic7xxx_host *p)
8705 unsigned char sblkctl;
8706 int wait;
8709 * For some 274x boards, we must clear the CHIPRST bit and pause
8710 * the sequencer. For some reason, this makes the driver work.
8712 aic_outb(p, PAUSE | CHIPRST, HCNTRL);
8715 * In the future, we may call this function as a last resort for
8716 * error handling. Let's be nice and not do any unecessary delays.
8718 wait = 1000; /* 1 second (1000 * 1 msec) */
8719 while (--wait && !(aic_inb(p, HCNTRL) & CHIPRSTACK))
8721 udelay(1); /* 1 msec */
8724 pause_sequencer(p);
8726 sblkctl = aic_inb(p, SBLKCTL) & (SELBUSB|SELWIDE);
8727 if (p->chip & AHC_PCI)
8728 sblkctl &= ~SELBUSB;
8729 switch( sblkctl )
8731 case 0: /* normal narrow card */
8732 break;
8733 case 2: /* Wide card */
8734 p->features |= AHC_WIDE;
8735 break;
8736 case 8: /* Twin card */
8737 p->features |= AHC_TWIN;
8738 p->flags |= AHC_MULTI_CHANNEL;
8739 break;
8740 default: /* hmmm...we don't know what this is */
8741 printk(KERN_WARNING "aic7xxx: Unsupported adapter type %d, ignoring.\n",
8742 aic_inb(p, SBLKCTL) & 0x0a);
8743 return(-1);
8745 return(0);
8748 /*+F*************************************************************************
8749 * Function:
8750 * aic7xxx_alloc
8752 * Description:
8753 * Allocate and initialize a host structure. Returns NULL upon error
8754 * and a pointer to a aic7xxx_host struct upon success.
8755 *-F*************************************************************************/
8756 static struct aic7xxx_host *
8757 aic7xxx_alloc(Scsi_Host_Template *sht, struct aic7xxx_host *temp)
8759 struct aic7xxx_host *p = NULL;
8760 struct Scsi_Host *host;
8761 int i;
8764 * Allocate a storage area by registering us with the mid-level
8765 * SCSI layer.
8767 host = scsi_register(sht, sizeof(struct aic7xxx_host));
8769 if (host != NULL)
8771 p = (struct aic7xxx_host *) host->hostdata;
8772 memset(p, 0, sizeof(struct aic7xxx_host));
8773 *p = *temp;
8774 p->host = host;
8776 p->scb_data = kmalloc(sizeof(scb_data_type), GFP_ATOMIC);
8777 if (p->scb_data != NULL)
8779 memset(p->scb_data, 0, sizeof(scb_data_type));
8780 scbq_init (&p->scb_data->free_scbs);
8782 else
8785 * For some reason we don't have enough memory. Free the
8786 * allocated memory for the aic7xxx_host struct, and return NULL.
8788 release_region(p->base, MAXREG - MINREG);
8789 scsi_unregister(host);
8790 return(NULL);
8792 p->host_no = host->host_no;
8793 p->tagenable = 0;
8794 p->orderedtag = 0;
8795 for (i=0; i<MAX_TARGETS; i++)
8797 p->transinfo[i].goal_period = 0;
8798 p->transinfo[i].goal_offset = 0;
8799 p->transinfo[i].goal_options = 0;
8800 p->transinfo[i].goal_width = MSG_EXT_WDTR_BUS_8_BIT;
8802 DRIVER_LOCK_INIT
8804 return (p);
8807 /*+F*************************************************************************
8808 * Function:
8809 * aic7xxx_free
8811 * Description:
8812 * Frees and releases all resources associated with an instance of
8813 * the driver (struct aic7xxx_host *).
8814 *-F*************************************************************************/
8815 static void
8816 aic7xxx_free(struct aic7xxx_host *p)
8818 int i;
8821 * Free the allocated hardware SCB space.
8823 if (p->scb_data != NULL)
8825 struct aic7xxx_scb_dma *scb_dma = NULL;
8826 if (p->scb_data->hscbs != NULL)
8828 pci_free_consistent(p->pdev, p->scb_data->hscbs_dma_len,
8829 p->scb_data->hscbs, p->scb_data->hscbs_dma);
8830 p->scb_data->hscbs = p->scb_data->hscb_kmalloc_ptr = NULL;
8833 * Free the driver SCBs. These were allocated on an as-need
8834 * basis. We allocated these in groups depending on how many
8835 * we could fit into a given amount of RAM. The tail SCB for
8836 * these allocations has a pointer to the alloced area.
8838 for (i = 0; i < p->scb_data->numscbs; i++)
8840 if (p->scb_data->scb_array[i]->scb_dma != scb_dma)
8842 scb_dma = p->scb_data->scb_array[i]->scb_dma;
8843 pci_free_consistent(p->pdev, scb_dma->dma_len,
8844 (void *)((unsigned long)scb_dma->dma_address
8845 - scb_dma->dma_offset),
8846 scb_dma->dma_address);
8848 if (p->scb_data->scb_array[i]->kmalloc_ptr != NULL)
8849 kfree(p->scb_data->scb_array[i]->kmalloc_ptr);
8850 p->scb_data->scb_array[i] = NULL;
8854 * Free the SCB data area.
8856 kfree(p->scb_data);
8860 * Free any alloced Scsi_Cmnd structures that might be around for
8861 * negotiation purposes....
8863 for (i = 0; i < MAX_TARGETS; i++)
8865 if(p->dev_dtr_cmnd[i])
8867 if(p->dev_dtr_cmnd[i]->request_buffer)
8869 kfree(p->dev_dtr_cmnd[i]->request_buffer);
8871 kfree(p->dev_dtr_cmnd[i]);
8875 pci_free_consistent(p->pdev, 3*256, (void *)p->untagged_scbs, p->fifo_dma);
8878 /*+F*************************************************************************
8879 * Function:
8880 * aic7xxx_load_seeprom
8882 * Description:
8883 * Load the seeprom and configure adapter and target settings.
8884 * Returns 1 if the load was successful and 0 otherwise.
8885 *-F*************************************************************************/
8886 static void
8887 aic7xxx_load_seeprom(struct aic7xxx_host *p, unsigned char *sxfrctl1)
8889 int have_seeprom = 0;
8890 int i, max_targets, mask;
8891 unsigned char scsirate, scsi_conf;
8892 unsigned short scarray[128];
8893 struct seeprom_config *sc = (struct seeprom_config *) scarray;
8895 if (aic7xxx_verbose & VERBOSE_PROBE2)
8897 printk(KERN_INFO "aic7xxx: Loading serial EEPROM...");
8899 switch (p->chip)
8901 case (AHC_AIC7770|AHC_EISA): /* None of these adapters have seeproms. */
8902 if (aic_inb(p, SCSICONF) & TERM_ENB)
8903 p->flags |= AHC_TERM_ENB_A;
8904 if ( (p->features & AHC_TWIN) && (aic_inb(p, SCSICONF + 1) & TERM_ENB) )
8905 p->flags |= AHC_TERM_ENB_B;
8906 break;
8908 case (AHC_AIC7770|AHC_VL):
8909 have_seeprom = read_284x_seeprom(p, (struct seeprom_config *) scarray);
8910 break;
8912 default:
8913 have_seeprom = read_seeprom(p, (p->flags & (AHC_CHNLB|AHC_CHNLC)),
8914 scarray, p->sc_size, p->sc_type);
8915 if (!have_seeprom)
8917 if(p->sc_type == C46)
8918 have_seeprom = read_seeprom(p, (p->flags & (AHC_CHNLB|AHC_CHNLC)),
8919 scarray, p->sc_size, C56_66);
8920 else
8921 have_seeprom = read_seeprom(p, (p->flags & (AHC_CHNLB|AHC_CHNLC)),
8922 scarray, p->sc_size, C46);
8924 if (!have_seeprom)
8926 p->sc_size = 128;
8927 have_seeprom = read_seeprom(p, 4*(p->flags & (AHC_CHNLB|AHC_CHNLC)),
8928 scarray, p->sc_size, p->sc_type);
8929 if (!have_seeprom)
8931 if(p->sc_type == C46)
8932 have_seeprom = read_seeprom(p, 4*(p->flags & (AHC_CHNLB|AHC_CHNLC)),
8933 scarray, p->sc_size, C56_66);
8934 else
8935 have_seeprom = read_seeprom(p, 4*(p->flags & (AHC_CHNLB|AHC_CHNLC)),
8936 scarray, p->sc_size, C46);
8939 break;
8942 if (!have_seeprom)
8944 if (aic7xxx_verbose & VERBOSE_PROBE2)
8946 printk("\naic7xxx: No SEEPROM available.\n");
8948 p->flags |= AHC_NEWEEPROM_FMT;
8949 if (aic_inb(p, SCSISEQ) == 0)
8951 p->flags |= AHC_USEDEFAULTS;
8952 p->flags &= ~AHC_BIOS_ENABLED;
8953 p->scsi_id = p->scsi_id_b = 7;
8954 *sxfrctl1 |= STPWEN;
8955 if (aic7xxx_verbose & VERBOSE_PROBE2)
8957 printk("aic7xxx: Using default values.\n");
8960 else if (aic7xxx_verbose & VERBOSE_PROBE2)
8962 printk("aic7xxx: Using leftover BIOS values.\n");
8964 if ( ((p->chip & ~AHC_CHIPID_MASK) == AHC_PCI) && (*sxfrctl1 & STPWEN) )
8966 p->flags |= AHC_TERM_ENB_SE_LOW | AHC_TERM_ENB_SE_HIGH;
8967 sc->adapter_control &= ~CFAUTOTERM;
8968 sc->adapter_control |= CFSTERM | CFWSTERM | CFLVDSTERM;
8970 if (aic7xxx_extended)
8971 p->flags |= (AHC_EXTEND_TRANS_A | AHC_EXTEND_TRANS_B);
8972 else
8973 p->flags &= ~(AHC_EXTEND_TRANS_A | AHC_EXTEND_TRANS_B);
8975 else
8977 if (aic7xxx_verbose & VERBOSE_PROBE2)
8979 printk("done\n");
8983 * Note things in our flags
8985 p->flags |= AHC_SEEPROM_FOUND;
8988 * Update the settings in sxfrctl1 to match the termination settings.
8990 *sxfrctl1 = 0;
8993 * Get our SCSI ID from the SEEPROM setting...
8995 p->scsi_id = (sc->brtime_id & CFSCSIID);
8998 * First process the settings that are different between the VLB
8999 * and PCI adapter seeproms.
9001 if ((p->chip & AHC_CHIPID_MASK) == AHC_AIC7770)
9003 /* VLB adapter seeproms */
9004 if (sc->bios_control & CF284XEXTEND)
9005 p->flags |= AHC_EXTEND_TRANS_A;
9007 if (sc->adapter_control & CF284XSTERM)
9009 *sxfrctl1 |= STPWEN;
9010 p->flags |= AHC_TERM_ENB_SE_LOW | AHC_TERM_ENB_SE_HIGH;
9013 else
9015 /* PCI adapter seeproms */
9016 if (sc->bios_control & CFEXTEND)
9017 p->flags |= AHC_EXTEND_TRANS_A;
9018 if (sc->bios_control & CFBIOSEN)
9019 p->flags |= AHC_BIOS_ENABLED;
9020 else
9021 p->flags &= ~AHC_BIOS_ENABLED;
9023 if (sc->adapter_control & CFSTERM)
9025 *sxfrctl1 |= STPWEN;
9026 p->flags |= AHC_TERM_ENB_SE_LOW | AHC_TERM_ENB_SE_HIGH;
9029 p->sc = *sc;
9032 p->discenable = 0;
9035 * Limit to 16 targets just in case. The 2842 for one is known to
9036 * blow the max_targets setting, future cards might also.
9038 max_targets = ((p->features & (AHC_TWIN | AHC_WIDE)) ? 16 : 8);
9040 if (have_seeprom)
9042 for (i = 0; i < max_targets; i++)
9044 if( ((p->features & AHC_ULTRA) &&
9045 !(sc->adapter_control & CFULTRAEN) &&
9046 (sc->device_flags[i] & CFSYNCHISULTRA)) ||
9047 (sc->device_flags[i] & CFNEWULTRAFORMAT) )
9049 p->flags |= AHC_NEWEEPROM_FMT;
9050 break;
9055 for (i = 0; i < max_targets; i++)
9057 mask = (0x01 << i);
9058 if (!have_seeprom)
9060 if (aic_inb(p, SCSISEQ) != 0)
9063 * OK...the BIOS set things up and left behind the settings we need.
9064 * Just make our sc->device_flags[i] entry match what the card has
9065 * set for this device.
9067 p->discenable =
9068 ~(aic_inb(p, DISC_DSB) | (aic_inb(p, DISC_DSB + 1) << 8) );
9069 p->ultraenb =
9070 (aic_inb(p, ULTRA_ENB) | (aic_inb(p, ULTRA_ENB + 1) << 8) );
9071 sc->device_flags[i] = (p->discenable & mask) ? CFDISC : 0;
9072 if (aic_inb(p, TARG_SCSIRATE + i) & WIDEXFER)
9073 sc->device_flags[i] |= CFWIDEB;
9074 if (p->features & AHC_ULTRA2)
9076 if (aic_inb(p, TARG_OFFSET + i))
9078 sc->device_flags[i] |= CFSYNCH;
9079 sc->device_flags[i] |= (aic_inb(p, TARG_SCSIRATE + i) & 0x07);
9080 if ( (aic_inb(p, TARG_SCSIRATE + i) & 0x18) == 0x18 )
9081 sc->device_flags[i] |= CFSYNCHISULTRA;
9084 else
9086 if (aic_inb(p, TARG_SCSIRATE + i) & ~WIDEXFER)
9088 sc->device_flags[i] |= CFSYNCH;
9089 if (p->features & AHC_ULTRA)
9090 sc->device_flags[i] |= ((p->ultraenb & mask) ?
9091 CFSYNCHISULTRA : 0);
9095 else
9098 * Assume the BIOS has NOT been run on this card and nothing between
9099 * the card and the devices is configured yet.
9101 sc->device_flags[i] = CFDISC;
9102 if (p->features & AHC_WIDE)
9103 sc->device_flags[i] |= CFWIDEB;
9104 if (p->features & AHC_ULTRA3)
9105 sc->device_flags[i] |= 2;
9106 else if (p->features & AHC_ULTRA2)
9107 sc->device_flags[i] |= 3;
9108 else if (p->features & AHC_ULTRA)
9109 sc->device_flags[i] |= CFSYNCHISULTRA;
9110 sc->device_flags[i] |= CFSYNCH;
9111 aic_outb(p, 0, TARG_SCSIRATE + i);
9112 if (p->features & AHC_ULTRA2)
9113 aic_outb(p, 0, TARG_OFFSET + i);
9116 if (sc->device_flags[i] & CFDISC)
9118 p->discenable |= mask;
9120 if (p->flags & AHC_NEWEEPROM_FMT)
9122 if ( !(p->features & AHC_ULTRA2) )
9125 * I know of two different Ultra BIOSes that do this differently.
9126 * One on the Gigabyte 6BXU mb that wants flags[i] & CFXFER to
9127 * be == to 0x03 and SYNCHISULTRA to be true to mean 40MByte/s
9128 * while on the IBM Netfinity 5000 they want the same thing
9129 * to be something else, while flags[i] & CFXFER == 0x03 and
9130 * SYNCHISULTRA false should be 40MByte/s. So, we set both to
9131 * 40MByte/s and the lower speeds be damned. People will have
9132 * to select around the conversely mapped lower speeds in order
9133 * to select lower speeds on these boards.
9135 if ( (sc->device_flags[i] & CFNEWULTRAFORMAT) &&
9136 ((sc->device_flags[i] & CFXFER) == 0x03) )
9138 sc->device_flags[i] &= ~CFXFER;
9139 sc->device_flags[i] |= CFSYNCHISULTRA;
9141 if (sc->device_flags[i] & CFSYNCHISULTRA)
9143 p->ultraenb |= mask;
9146 else if ( !(sc->device_flags[i] & CFNEWULTRAFORMAT) &&
9147 (p->features & AHC_ULTRA2) &&
9148 (sc->device_flags[i] & CFSYNCHISULTRA) )
9150 p->ultraenb |= mask;
9153 else if (sc->adapter_control & CFULTRAEN)
9155 p->ultraenb |= mask;
9157 if ( (sc->device_flags[i] & CFSYNCH) == 0)
9159 sc->device_flags[i] &= ~CFXFER;
9160 p->ultraenb &= ~mask;
9161 p->transinfo[i].user_offset = 0;
9162 p->transinfo[i].user_period = 0;
9163 p->transinfo[i].user_options = 0;
9164 p->transinfo[i].cur_offset = 0;
9165 p->transinfo[i].cur_period = 0;
9166 p->transinfo[i].cur_options = 0;
9167 p->needsdtr_copy &= ~mask;
9169 else
9171 if (p->features & AHC_ULTRA3)
9173 p->transinfo[i].user_offset = MAX_OFFSET_ULTRA2;
9174 p->transinfo[i].cur_offset = aic_inb(p, TARG_OFFSET + i);
9175 if( (sc->device_flags[i] & CFXFER) < 0x03 )
9177 scsirate = (sc->device_flags[i] & CFXFER);
9178 p->transinfo[i].user_options = MSG_EXT_PPR_OPTION_DT_CRC;
9179 if( (aic_inb(p, TARG_SCSIRATE + i) & CFXFER) < 0x03 )
9181 p->transinfo[i].cur_options =
9182 ((aic_inb(p, TARG_SCSIRATE + i) & 0x40) ?
9183 MSG_EXT_PPR_OPTION_DT_CRC : MSG_EXT_PPR_OPTION_DT_UNITS);
9185 else
9187 p->transinfo[i].cur_options = 0;
9190 else
9192 scsirate = (sc->device_flags[i] & CFXFER) |
9193 ((p->ultraenb & mask) ? 0x18 : 0x10);
9194 p->transinfo[i].user_options = 0;
9195 p->transinfo[i].cur_options = 0;
9197 p->transinfo[i].user_period = aic7xxx_find_period(p, scsirate,
9198 AHC_SYNCRATE_ULTRA3);
9199 p->transinfo[i].cur_period = aic7xxx_find_period(p,
9200 aic_inb(p, TARG_SCSIRATE + i),
9201 AHC_SYNCRATE_ULTRA3);
9203 else if (p->features & AHC_ULTRA2)
9205 p->transinfo[i].user_offset = MAX_OFFSET_ULTRA2;
9206 p->transinfo[i].cur_offset = aic_inb(p, TARG_OFFSET + i);
9207 scsirate = (sc->device_flags[i] & CFXFER) |
9208 ((p->ultraenb & mask) ? 0x18 : 0x10);
9209 p->transinfo[i].user_options = 0;
9210 p->transinfo[i].cur_options = 0;
9211 p->transinfo[i].user_period = aic7xxx_find_period(p, scsirate,
9212 AHC_SYNCRATE_ULTRA2);
9213 p->transinfo[i].cur_period = aic7xxx_find_period(p,
9214 aic_inb(p, TARG_SCSIRATE + i),
9215 AHC_SYNCRATE_ULTRA2);
9217 else
9219 scsirate = (sc->device_flags[i] & CFXFER) << 4;
9220 p->transinfo[i].user_options = 0;
9221 p->transinfo[i].cur_options = 0;
9222 p->transinfo[i].user_offset = MAX_OFFSET_8BIT;
9223 if (p->features & AHC_ULTRA)
9225 short ultraenb;
9226 ultraenb = aic_inb(p, ULTRA_ENB) |
9227 (aic_inb(p, ULTRA_ENB + 1) << 8);
9228 p->transinfo[i].user_period = aic7xxx_find_period(p,
9229 scsirate,
9230 (p->ultraenb & mask) ?
9231 AHC_SYNCRATE_ULTRA :
9232 AHC_SYNCRATE_FAST);
9233 p->transinfo[i].cur_period = aic7xxx_find_period(p,
9234 aic_inb(p, TARG_SCSIRATE + i),
9235 (ultraenb & mask) ?
9236 AHC_SYNCRATE_ULTRA :
9237 AHC_SYNCRATE_FAST);
9239 else
9240 p->transinfo[i].user_period = aic7xxx_find_period(p,
9241 scsirate, AHC_SYNCRATE_FAST);
9243 p->needsdtr_copy |= mask;
9245 if ( (sc->device_flags[i] & CFWIDEB) && (p->features & AHC_WIDE) )
9247 p->transinfo[i].user_width = MSG_EXT_WDTR_BUS_16_BIT;
9248 p->needwdtr_copy |= mask;
9250 else
9252 p->transinfo[i].user_width = MSG_EXT_WDTR_BUS_8_BIT;
9253 p->needwdtr_copy &= ~mask;
9255 p->transinfo[i].cur_width =
9256 (aic_inb(p, TARG_SCSIRATE + i) & WIDEXFER) ?
9257 MSG_EXT_WDTR_BUS_16_BIT : MSG_EXT_WDTR_BUS_8_BIT;
9259 aic_outb(p, ~(p->discenable & 0xFF), DISC_DSB);
9260 aic_outb(p, ~((p->discenable >> 8) & 0xFF), DISC_DSB + 1);
9261 p->needppr = p->needppr_copy = p->needdv = 0;
9262 p->needwdtr = p->needwdtr_copy;
9263 p->needsdtr = p->needsdtr_copy;
9264 p->dtr_pending = 0;
9267 * We set the p->ultraenb from the SEEPROM to begin with, but now we make
9268 * it match what is already down in the card. If we are doing a reset
9269 * on the card then this will get put back to a default state anyway.
9270 * This allows us to not have to pre-emptively negotiate when using the
9271 * no_reset option.
9273 if (p->features & AHC_ULTRA)
9274 p->ultraenb = aic_inb(p, ULTRA_ENB) | (aic_inb(p, ULTRA_ENB + 1) << 8);
9277 scsi_conf = (p->scsi_id & HSCSIID);
9279 if(have_seeprom)
9281 p->adapter_control = sc->adapter_control;
9282 p->bios_control = sc->bios_control;
9284 switch (p->chip & AHC_CHIPID_MASK)
9286 case AHC_AIC7895:
9287 case AHC_AIC7896:
9288 case AHC_AIC7899:
9289 if (p->adapter_control & CFBPRIMARY)
9290 p->flags |= AHC_CHANNEL_B_PRIMARY;
9291 default:
9292 break;
9295 if (sc->adapter_control & CFSPARITY)
9296 scsi_conf |= ENSPCHK;
9298 else
9300 scsi_conf |= ENSPCHK | RESET_SCSI;
9304 * Only set the SCSICONF and SCSICONF + 1 registers if we are a PCI card.
9305 * The 2842 and 2742 cards already have these registers set and we don't
9306 * want to muck with them since we don't set all the bits they do.
9308 if ( (p->chip & ~AHC_CHIPID_MASK) == AHC_PCI )
9310 /* Set the host ID */
9311 aic_outb(p, scsi_conf, SCSICONF);
9312 /* In case we are a wide card */
9313 aic_outb(p, p->scsi_id, SCSICONF + 1);
9317 /*+F*************************************************************************
9318 * Function:
9319 * aic7xxx_detect
9321 * Description:
9322 * Try to detect and register an Adaptec 7770 or 7870 SCSI controller.
9324 * XXX - This should really be called aic7xxx_probe(). A sequence of
9325 * probe(), attach()/detach(), and init() makes more sense than
9326 * one do-it-all function. This may be useful when (and if) the
9327 * mid-level SCSI code is overhauled.
9328 *-F*************************************************************************/
9330 aic7xxx_detect(Scsi_Host_Template *template)
9332 struct aic7xxx_host *temp_p = NULL;
9333 struct aic7xxx_host *current_p = NULL;
9334 struct aic7xxx_host *list_p = NULL;
9335 int found = 0;
9336 #if defined(__i386__) || defined(__alpha__)
9337 ahc_flag_type flags = 0;
9338 int type;
9339 #endif
9340 unsigned char sxfrctl1;
9341 #if defined(__i386__) || defined(__alpha__)
9342 unsigned char hcntrl, hostconf;
9343 unsigned int slot, base;
9344 #endif
9346 #ifdef MODULE
9348 * If we are called as a module, the aic7xxx pointer may not be null
9349 * and it would point to our bootup string, just like on the lilo
9350 * command line. IF not NULL, then process this config string with
9351 * aic7xxx_setup
9353 if(aic7xxx)
9354 aic7xxx_setup(aic7xxx);
9355 if(dummy_buffer[0] != 'P')
9356 printk(KERN_WARNING "aic7xxx: Please read the file /usr/src/linux/drivers"
9357 "/scsi/README.aic7xxx\n"
9358 "aic7xxx: to see the proper way to specify options to the aic7xxx "
9359 "module\n"
9360 "aic7xxx: Specifically, don't use any commas when passing arguments to\n"
9361 "aic7xxx: insmod or else it might trash certain memory areas.\n");
9362 #endif
9364 template->proc_name = "aic7xxx";
9365 template->sg_tablesize = AIC7XXX_MAX_SG;
9368 #ifdef CONFIG_PCI
9370 * PCI-bus probe.
9372 #if LINUX_VERSION_CODE > KERNEL_VERSION(2,1,92)
9373 if (pci_present())
9374 #else
9375 if (pcibios_present())
9376 #endif
9378 struct
9380 unsigned short vendor_id;
9381 unsigned short device_id;
9382 ahc_chip chip;
9383 ahc_flag_type flags;
9384 ahc_feature features;
9385 int board_name_index;
9386 unsigned short seeprom_size;
9387 unsigned short seeprom_type;
9388 } const aic_pdevs[] = {
9389 {PCI_VENDOR_ID_ADAPTEC, PCI_DEVICE_ID_ADAPTEC_7810, AHC_NONE,
9390 AHC_FNONE, AHC_FENONE, 1,
9391 32, C46 },
9392 {PCI_VENDOR_ID_ADAPTEC, PCI_DEVICE_ID_ADAPTEC_7850, AHC_AIC7850,
9393 AHC_PAGESCBS, AHC_AIC7850_FE, 5,
9394 32, C46 },
9395 {PCI_VENDOR_ID_ADAPTEC, PCI_DEVICE_ID_ADAPTEC_7855, AHC_AIC7850,
9396 AHC_PAGESCBS, AHC_AIC7850_FE, 6,
9397 32, C46 },
9398 {PCI_VENDOR_ID_ADAPTEC, PCI_DEVICE_ID_ADAPTEC_7821, AHC_AIC7860,
9399 AHC_PAGESCBS | AHC_NEWEEPROM_FMT | AHC_BIOS_ENABLED,
9400 AHC_AIC7860_FE, 7,
9401 32, C46 },
9402 {PCI_VENDOR_ID_ADAPTEC, PCI_DEVICE_ID_ADAPTEC_3860, AHC_AIC7860,
9403 AHC_PAGESCBS | AHC_NEWEEPROM_FMT | AHC_BIOS_ENABLED,
9404 AHC_AIC7860_FE, 7,
9405 32, C46 },
9406 {PCI_VENDOR_ID_ADAPTEC, PCI_DEVICE_ID_ADAPTEC_38602, AHC_AIC7860,
9407 AHC_PAGESCBS | AHC_NEWEEPROM_FMT | AHC_BIOS_ENABLED,
9408 AHC_AIC7860_FE, 7,
9409 32, C46 },
9410 {PCI_VENDOR_ID_ADAPTEC, PCI_DEVICE_ID_ADAPTEC_38602, AHC_AIC7860,
9411 AHC_PAGESCBS | AHC_NEWEEPROM_FMT | AHC_BIOS_ENABLED,
9412 AHC_AIC7860_FE, 7,
9413 32, C46 },
9414 {PCI_VENDOR_ID_ADAPTEC, PCI_DEVICE_ID_ADAPTEC_7860, AHC_AIC7860,
9415 AHC_PAGESCBS | AHC_NEWEEPROM_FMT | AHC_BIOS_ENABLED,
9416 AHC_AIC7860_FE, 7,
9417 32, C46 },
9418 {PCI_VENDOR_ID_ADAPTEC, PCI_DEVICE_ID_ADAPTEC_7861, AHC_AIC7860,
9419 AHC_PAGESCBS | AHC_NEWEEPROM_FMT | AHC_BIOS_ENABLED,
9420 AHC_AIC7860_FE, 8,
9421 32, C46 },
9422 {PCI_VENDOR_ID_ADAPTEC, PCI_DEVICE_ID_ADAPTEC_7870, AHC_AIC7870,
9423 AHC_PAGESCBS | AHC_BIOS_ENABLED, AHC_AIC7870_FE, 9,
9424 32, C46 },
9425 {PCI_VENDOR_ID_ADAPTEC, PCI_DEVICE_ID_ADAPTEC_7871, AHC_AIC7870,
9426 AHC_PAGESCBS | AHC_BIOS_ENABLED, AHC_AIC7870_FE, 10,
9427 32, C46 },
9428 {PCI_VENDOR_ID_ADAPTEC, PCI_DEVICE_ID_ADAPTEC_7872, AHC_AIC7870,
9429 AHC_PAGESCBS | AHC_BIOS_ENABLED | AHC_MULTI_CHANNEL,
9430 AHC_AIC7870_FE, 11,
9431 32, C56_66 },
9432 {PCI_VENDOR_ID_ADAPTEC, PCI_DEVICE_ID_ADAPTEC_7873, AHC_AIC7870,
9433 AHC_PAGESCBS | AHC_BIOS_ENABLED | AHC_MULTI_CHANNEL,
9434 AHC_AIC7870_FE, 12,
9435 32, C56_66 },
9436 {PCI_VENDOR_ID_ADAPTEC, PCI_DEVICE_ID_ADAPTEC_7874, AHC_AIC7870,
9437 AHC_PAGESCBS | AHC_BIOS_ENABLED, AHC_AIC7870_FE, 13,
9438 32, C46 },
9439 {PCI_VENDOR_ID_ADAPTEC, PCI_DEVICE_ID_ADAPTEC_7880, AHC_AIC7880,
9440 AHC_PAGESCBS | AHC_BIOS_ENABLED, AHC_AIC7880_FE, 14,
9441 32, C46 },
9442 {PCI_VENDOR_ID_ADAPTEC, PCI_DEVICE_ID_ADAPTEC_7881, AHC_AIC7880,
9443 AHC_PAGESCBS | AHC_BIOS_ENABLED, AHC_AIC7880_FE, 15,
9444 32, C46 },
9445 {PCI_VENDOR_ID_ADAPTEC, PCI_DEVICE_ID_ADAPTEC_7882, AHC_AIC7880,
9446 AHC_PAGESCBS | AHC_BIOS_ENABLED | AHC_MULTI_CHANNEL,
9447 AHC_AIC7880_FE, 16,
9448 32, C56_66 },
9449 {PCI_VENDOR_ID_ADAPTEC, PCI_DEVICE_ID_ADAPTEC_7883, AHC_AIC7880,
9450 AHC_PAGESCBS | AHC_BIOS_ENABLED | AHC_MULTI_CHANNEL,
9451 AHC_AIC7880_FE, 17,
9452 32, C56_66 },
9453 {PCI_VENDOR_ID_ADAPTEC, PCI_DEVICE_ID_ADAPTEC_7884, AHC_AIC7880,
9454 AHC_PAGESCBS | AHC_BIOS_ENABLED, AHC_AIC7880_FE, 18,
9455 32, C46 },
9456 {PCI_VENDOR_ID_ADAPTEC, PCI_DEVICE_ID_ADAPTEC_7885, AHC_AIC7880,
9457 AHC_PAGESCBS | AHC_BIOS_ENABLED, AHC_AIC7880_FE, 18,
9458 32, C46 },
9459 {PCI_VENDOR_ID_ADAPTEC, PCI_DEVICE_ID_ADAPTEC_7886, AHC_AIC7880,
9460 AHC_PAGESCBS | AHC_BIOS_ENABLED, AHC_AIC7880_FE, 18,
9461 32, C46 },
9462 {PCI_VENDOR_ID_ADAPTEC, PCI_DEVICE_ID_ADAPTEC_7887, AHC_AIC7880,
9463 AHC_PAGESCBS | AHC_BIOS_ENABLED, AHC_AIC7880_FE | AHC_NEW_AUTOTERM, 18,
9464 32, C46 },
9465 {PCI_VENDOR_ID_ADAPTEC, PCI_DEVICE_ID_ADAPTEC_7888, AHC_AIC7880,
9466 AHC_PAGESCBS | AHC_BIOS_ENABLED, AHC_AIC7880_FE, 18,
9467 32, C46 },
9468 {PCI_VENDOR_ID_ADAPTEC, PCI_DEVICE_ID_ADAPTEC_7895, AHC_AIC7895,
9469 AHC_PAGESCBS | AHC_NEWEEPROM_FMT | AHC_BIOS_ENABLED | AHC_MULTI_CHANNEL,
9470 AHC_AIC7895_FE, 19,
9471 32, C56_66 },
9472 {PCI_VENDOR_ID_ADAPTEC2, PCI_DEVICE_ID_ADAPTEC2_7890, AHC_AIC7890,
9473 AHC_PAGESCBS | AHC_NEWEEPROM_FMT | AHC_BIOS_ENABLED,
9474 AHC_AIC7890_FE, 20,
9475 32, C46 },
9476 {PCI_VENDOR_ID_ADAPTEC2, PCI_DEVICE_ID_ADAPTEC2_7890B, AHC_AIC7890,
9477 AHC_PAGESCBS | AHC_NEWEEPROM_FMT | AHC_BIOS_ENABLED,
9478 AHC_AIC7890_FE, 20,
9479 32, C46 },
9480 {PCI_VENDOR_ID_ADAPTEC2, PCI_DEVICE_ID_ADAPTEC2_2930U2, AHC_AIC7890,
9481 AHC_PAGESCBS | AHC_NEWEEPROM_FMT | AHC_BIOS_ENABLED,
9482 AHC_AIC7890_FE, 21,
9483 32, C46 },
9484 {PCI_VENDOR_ID_ADAPTEC2, PCI_DEVICE_ID_ADAPTEC2_2940U2, AHC_AIC7890,
9485 AHC_PAGESCBS | AHC_NEWEEPROM_FMT | AHC_BIOS_ENABLED,
9486 AHC_AIC7890_FE, 22,
9487 32, C46 },
9488 {PCI_VENDOR_ID_ADAPTEC2, PCI_DEVICE_ID_ADAPTEC2_7896, AHC_AIC7896,
9489 AHC_PAGESCBS | AHC_NEWEEPROM_FMT | AHC_BIOS_ENABLED | AHC_MULTI_CHANNEL,
9490 AHC_AIC7896_FE, 23,
9491 32, C56_66 },
9492 {PCI_VENDOR_ID_ADAPTEC2, PCI_DEVICE_ID_ADAPTEC2_3940U2, AHC_AIC7896,
9493 AHC_PAGESCBS | AHC_NEWEEPROM_FMT | AHC_BIOS_ENABLED | AHC_MULTI_CHANNEL,
9494 AHC_AIC7896_FE, 24,
9495 32, C56_66 },
9496 {PCI_VENDOR_ID_ADAPTEC2, PCI_DEVICE_ID_ADAPTEC2_3950U2D, AHC_AIC7896,
9497 AHC_PAGESCBS | AHC_NEWEEPROM_FMT | AHC_BIOS_ENABLED | AHC_MULTI_CHANNEL,
9498 AHC_AIC7896_FE, 25,
9499 32, C56_66 },
9500 {PCI_VENDOR_ID_ADAPTEC, PCI_DEVICE_ID_ADAPTEC_1480A, AHC_AIC7860,
9501 AHC_PAGESCBS | AHC_NEWEEPROM_FMT | AHC_BIOS_ENABLED | AHC_NO_STPWR,
9502 AHC_AIC7860_FE, 26,
9503 32, C46 },
9504 {PCI_VENDOR_ID_ADAPTEC2, PCI_DEVICE_ID_ADAPTEC2_7892A, AHC_AIC7892,
9505 AHC_PAGESCBS | AHC_NEWEEPROM_FMT | AHC_BIOS_ENABLED,
9506 AHC_AIC7892_FE, 27,
9507 32, C46 },
9508 {PCI_VENDOR_ID_ADAPTEC2, PCI_DEVICE_ID_ADAPTEC2_7892B, AHC_AIC7892,
9509 AHC_PAGESCBS | AHC_NEWEEPROM_FMT | AHC_BIOS_ENABLED,
9510 AHC_AIC7892_FE, 27,
9511 32, C46 },
9512 {PCI_VENDOR_ID_ADAPTEC2, PCI_DEVICE_ID_ADAPTEC2_7892D, AHC_AIC7892,
9513 AHC_PAGESCBS | AHC_NEWEEPROM_FMT | AHC_BIOS_ENABLED,
9514 AHC_AIC7892_FE, 27,
9515 32, C46 },
9516 {PCI_VENDOR_ID_ADAPTEC2, PCI_DEVICE_ID_ADAPTEC2_7892P, AHC_AIC7892,
9517 AHC_PAGESCBS | AHC_NEWEEPROM_FMT | AHC_BIOS_ENABLED,
9518 AHC_AIC7892_FE, 27,
9519 32, C46 },
9520 {PCI_VENDOR_ID_ADAPTEC2, PCI_DEVICE_ID_ADAPTEC2_7899A, AHC_AIC7899,
9521 AHC_PAGESCBS | AHC_NEWEEPROM_FMT | AHC_BIOS_ENABLED | AHC_MULTI_CHANNEL,
9522 AHC_AIC7899_FE, 28,
9523 32, C56_66 },
9524 {PCI_VENDOR_ID_ADAPTEC2, PCI_DEVICE_ID_ADAPTEC2_7899B, AHC_AIC7899,
9525 AHC_PAGESCBS | AHC_NEWEEPROM_FMT | AHC_BIOS_ENABLED | AHC_MULTI_CHANNEL,
9526 AHC_AIC7899_FE, 28,
9527 32, C56_66 },
9528 {PCI_VENDOR_ID_ADAPTEC2, PCI_DEVICE_ID_ADAPTEC2_7899D, AHC_AIC7899,
9529 AHC_PAGESCBS | AHC_NEWEEPROM_FMT | AHC_BIOS_ENABLED | AHC_MULTI_CHANNEL,
9530 AHC_AIC7899_FE, 28,
9531 32, C56_66 },
9532 {PCI_VENDOR_ID_ADAPTEC2, PCI_DEVICE_ID_ADAPTEC2_7899P, AHC_AIC7899,
9533 AHC_PAGESCBS | AHC_NEWEEPROM_FMT | AHC_BIOS_ENABLED | AHC_MULTI_CHANNEL,
9534 AHC_AIC7899_FE, 28,
9535 32, C56_66 },
9538 unsigned short command;
9539 unsigned int devconfig, i, oldverbose;
9540 #if LINUX_VERSION_CODE > KERNEL_VERSION(2,1,92)
9541 struct pci_dev *pdev = NULL;
9542 #else
9543 int index;
9544 unsigned int piobase, mmapbase;
9545 unsigned char pci_bus, pci_devfn, pci_irq;
9546 #endif
9548 for (i = 0; i < NUMBER(aic_pdevs); i++)
9550 #if LINUX_VERSION_CODE > KERNEL_VERSION(2,1,92)
9551 pdev = NULL;
9552 while ((pdev = pci_find_device(aic_pdevs[i].vendor_id,
9553 aic_pdevs[i].device_id,
9554 pdev)))
9555 #else
9556 index = 0;
9557 while (!(pcibios_find_device(aic_pdevs[i].vendor_id,
9558 aic_pdevs[i].device_id,
9559 index++, &pci_bus, &pci_devfn)) )
9560 #endif
9562 if ( i == 0 ) /* We found one, but it's the 7810 RAID cont. */
9564 if (aic7xxx_verbose & (VERBOSE_PROBE|VERBOSE_PROBE2))
9566 printk(KERN_INFO "aic7xxx: The 7810 RAID controller is not "
9567 "supported by\n");
9568 printk(KERN_INFO " this driver, we are ignoring it.\n");
9571 else if ( (temp_p = kmalloc(sizeof(struct aic7xxx_host),
9572 GFP_ATOMIC)) != NULL )
9574 memset(temp_p, 0, sizeof(struct aic7xxx_host));
9575 temp_p->chip = aic_pdevs[i].chip | AHC_PCI;
9576 temp_p->flags = aic_pdevs[i].flags;
9577 temp_p->features = aic_pdevs[i].features;
9578 temp_p->board_name_index = aic_pdevs[i].board_name_index;
9579 temp_p->sc_size = aic_pdevs[i].seeprom_size;
9580 temp_p->sc_type = aic_pdevs[i].seeprom_type;
9583 * Read sundry information from PCI BIOS.
9585 #if LINUX_VERSION_CODE > KERNEL_VERSION(2,1,92)
9586 temp_p->irq = pdev->irq;
9587 temp_p->pdev = pdev;
9588 temp_p->pci_bus = pdev->bus->number;
9589 temp_p->pci_device_fn = pdev->devfn;
9590 temp_p->base = pdev->resource[0].start;
9591 temp_p->mbase = pdev->resource[1].start;
9592 current_p = list_p;
9593 while(current_p && temp_p)
9595 if ( ((current_p->pci_bus == temp_p->pci_bus) &&
9596 (current_p->pci_device_fn == temp_p->pci_device_fn)) ||
9597 (current_p->base == temp_p->base) )
9599 /* duplicate PCI entry, skip it */
9600 kfree(temp_p);
9601 temp_p = NULL;
9603 current_p = current_p->next;
9605 if ( temp_p == NULL )
9606 continue;
9607 if (aic7xxx_verbose & VERBOSE_PROBE2)
9608 printk("aic7xxx: <%s> at PCI %d/%d\n",
9609 board_names[aic_pdevs[i].board_name_index],
9610 PCI_SLOT(pdev->devfn),
9611 PCI_FUNC(pdev->devfn));
9612 pci_read_config_word(pdev, PCI_COMMAND, &command);
9613 if (aic7xxx_verbose & VERBOSE_PROBE2)
9615 printk("aic7xxx: Initial PCI_COMMAND value was 0x%x\n",
9616 (int)command);
9618 #ifdef AIC7XXX_STRICT_PCI_SETUP
9619 command |= PCI_COMMAND_SERR | PCI_COMMAND_PARITY |
9620 PCI_COMMAND_MASTER | PCI_COMMAND_MEMORY | PCI_COMMAND_IO;
9621 #else
9622 command |= PCI_COMMAND_MASTER | PCI_COMMAND_MEMORY | PCI_COMMAND_IO;
9623 #endif
9624 command &= ~PCI_COMMAND_INVALIDATE;
9625 if (aic7xxx_pci_parity == 0)
9626 command &= ~(PCI_COMMAND_SERR | PCI_COMMAND_PARITY);
9627 pci_write_config_word(pdev, PCI_COMMAND, command);
9628 #ifdef AIC7XXX_STRICT_PCI_SETUP
9629 pci_read_config_dword(pdev, DEVCONFIG, &devconfig);
9630 if (aic7xxx_verbose & VERBOSE_PROBE2)
9632 printk("aic7xxx: Initial DEVCONFIG value was 0x%x\n", devconfig);
9634 devconfig |= 0x80000040;
9635 pci_write_config_dword(pdev, DEVCONFIG, devconfig);
9636 #endif /* AIC7XXX_STRICT_PCI_SETUP */
9637 #else /* LINUX_VERSION_CODE > KERNEL_VERSION(2,1,92) */
9638 temp_p->pci_bus = pci_bus;
9639 temp_p->pci_device_fn = pci_devfn;
9640 pcibios_read_config_byte(pci_bus, pci_devfn, PCI_INTERRUPT_LINE,
9641 &pci_irq);
9642 temp_p->irq = pci_irq;
9643 pcibios_read_config_dword(pci_bus, pci_devfn, PCI_BASE_ADDRESS_0,
9644 &piobase);
9645 temp_p->base = piobase;
9646 pcibios_read_config_dword(pci_bus, pci_devfn, PCI_BASE_ADDRESS_1,
9647 &mmapbase);
9648 temp_p->mbase = mmapbase;
9649 temp_p->base &= PCI_BASE_ADDRESS_IO_MASK;
9650 temp_p->mbase &= PCI_BASE_ADDRESS_MEM_MASK;
9651 current_p = list_p;
9652 while(current_p)
9654 if ( ((current_p->pci_bus == temp_p->pci_bus) &&
9655 (current_p->pci_device_fn == temp_p->pci_device_fn)) ||
9656 (current_p->base == temp_p->base) )
9658 /* duplicate PCI entry, skip it */
9659 kfree(temp_p);
9660 temp_p = NULL;
9662 current_p = current_p->next;
9664 if ( temp_p == NULL )
9665 continue;
9666 if (aic7xxx_verbose & VERBOSE_PROBE2)
9667 printk("aic7xxx: <%s> at PCI %d/%d/%d\n",
9668 board_names[aic_pdevs[i].board_name_index],
9669 temp_p->pci_bus,
9670 PCI_SLOT(temp_p->pci_device_fn),
9671 PCI_FUNC(temp_p->pci_device_fn));
9672 pcibios_read_config_word(pci_bus, pci_devfn, PCI_COMMAND, &command);
9673 if (aic7xxx_verbose & VERBOSE_PROBE2)
9675 printk("aic7xxx: Initial PCI_COMMAND value was 0x%x\n",
9676 (int)command);
9678 #ifdef AIC7XXX_STRICT_PCI_SETUP
9679 command |= PCI_COMMAND_SERR | PCI_COMMAND_PARITY |
9680 PCI_COMMAND_MASTER | PCI_COMMAND_MEMORY | PCI_COMMAND_IO;
9681 #else
9682 command |= PCI_COMMAND_MASTER | PCI_COMMAND_MEMORY | PCI_COMMAND_IO;
9683 #endif
9684 command &= ~PCI_COMMAND_INVALIDATE;
9685 if (aic7xxx_pci_parity == 0)
9686 command &= ~(PCI_COMMAND_SERR | PCI_COMMAND_PARITY);
9687 pcibios_write_config_word(pci_bus, pci_devfn, PCI_COMMAND, command);
9688 #ifdef AIC7XXX_STRICT_PCI_SETUP
9689 pcibios_read_config_dword(pci_bus, pci_devfn, DEVCONFIG, &devconfig);
9690 if (aic7xxx_verbose & VERBOSE_PROBE2)
9692 printk("aic7xxx: Initial DEVCONFIG value was 0x%x\n", devconfig);
9694 devconfig |= 0x80000040;
9695 pcibios_write_config_dword(pci_bus, pci_devfn, DEVCONFIG, devconfig);
9696 #endif /* AIC7XXX_STRICT_PCI_SETUP */
9697 #endif /* LINUX_VERSION_CODE > KERNEL_VERSION(2,1,92) */
9699 if(check_region(temp_p->base, MAXREG - MINREG))
9701 printk("aic7xxx: <%s> at PCI %d/%d/%d\n",
9702 board_names[aic_pdevs[i].board_name_index],
9703 temp_p->pci_bus,
9704 PCI_SLOT(temp_p->pci_device_fn),
9705 PCI_FUNC(temp_p->pci_device_fn));
9706 printk("aic7xxx: I/O ports already in use, ignoring.\n");
9707 kfree(temp_p);
9708 temp_p = NULL;
9709 continue;
9712 temp_p->unpause = INTEN;
9713 temp_p->pause = temp_p->unpause | PAUSE;
9714 if ( ((temp_p->base == 0) &&
9715 (temp_p->mbase == 0)) ||
9716 (temp_p->irq == 0) )
9718 printk("aic7xxx: <%s> at PCI %d/%d/%d\n",
9719 board_names[aic_pdevs[i].board_name_index],
9720 temp_p->pci_bus,
9721 PCI_SLOT(temp_p->pci_device_fn),
9722 PCI_FUNC(temp_p->pci_device_fn));
9723 printk("aic7xxx: Controller disabled by BIOS, ignoring.\n");
9724 kfree(temp_p);
9725 temp_p = NULL;
9726 continue;
9729 #ifdef MMAPIO
9730 if ( !(temp_p->flags & AHC_MULTI_CHANNEL) ||
9731 ((temp_p->chip != (AHC_AIC7870 | AHC_PCI)) &&
9732 (temp_p->chip != (AHC_AIC7880 | AHC_PCI))) )
9734 unsigned long page_offset, base;
9736 base = temp_p->mbase & PAGE_MASK;
9737 page_offset = temp_p->mbase - base;
9738 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,1,0)
9739 temp_p->maddr = ioremap_nocache(base, page_offset + 256);
9740 #else
9741 temp_p->maddr = vremap(base, page_offset + 256);
9742 #endif
9743 if(temp_p->maddr)
9745 temp_p->maddr += page_offset;
9747 * We need to check the I/O with the MMAPed address. Some machines
9748 * simply fail to work with MMAPed I/O and certain controllers.
9750 if(aic_inb(temp_p, HCNTRL) == 0xff)
9753 * OK.....we failed our test....go back to programmed I/O
9755 printk(KERN_INFO "aic7xxx: <%s> at PCI %d/%d/%d\n",
9756 board_names[aic_pdevs[i].board_name_index],
9757 temp_p->pci_bus,
9758 PCI_SLOT(temp_p->pci_device_fn),
9759 PCI_FUNC(temp_p->pci_device_fn));
9760 printk(KERN_INFO "aic7xxx: MMAPed I/O failed, reverting to "
9761 "Programmed I/O.\n");
9762 #if LINUX_VERSION_CODE > KERNEL_VERSION(2,1,0)
9763 iounmap((void *) (((unsigned long) temp_p->maddr) & PAGE_MASK));
9764 #else
9765 vfree((void *) (((unsigned long) temp_p->maddr) & PAGE_MASK));
9766 #endif
9767 temp_p->maddr = 0;
9771 #endif
9774 * Lock out other contenders for our i/o space.
9776 request_region(temp_p->base, MAXREG - MINREG, "aic7xxx");
9779 * We HAVE to make sure the first pause_sequencer() and all other
9780 * subsequent I/O that isn't PCI config space I/O takes place
9781 * after the MMAPed I/O region is configured and tested. The
9782 * problem is the PowerPC architecture that doesn't support
9783 * programmed I/O at all, so we have to have the MMAP I/O set up
9784 * for this pause to even work on those machines.
9786 pause_sequencer(temp_p);
9789 * Clear out any pending PCI error status messages. Also set
9790 * verbose to 0 so that we don't emit strange PCI error messages
9791 * while cleaning out the current status bits.
9793 oldverbose = aic7xxx_verbose;
9794 aic7xxx_verbose = 0;
9795 aic7xxx_pci_intr(temp_p);
9796 aic7xxx_verbose = oldverbose;
9798 temp_p->bios_address = 0;
9801 * Remember how the card was setup in case there is no seeprom.
9803 if (temp_p->features & AHC_ULTRA2)
9804 temp_p->scsi_id = aic_inb(temp_p, SCSIID_ULTRA2) & OID;
9805 else
9806 temp_p->scsi_id = aic_inb(temp_p, SCSIID) & OID;
9808 * Get current termination setting
9810 sxfrctl1 = aic_inb(temp_p, SXFRCTL1);
9812 if (aic7xxx_chip_reset(temp_p) == -1)
9814 release_region(temp_p->base, MAXREG - MINREG);
9815 kfree(temp_p);
9816 temp_p = NULL;
9817 continue;
9820 * Very quickly put the term setting back into the register since
9821 * the chip reset may cause odd things to happen. This is to keep
9822 * LVD busses with lots of drives from draining the power out of
9823 * the diffsense line before we get around to running the
9824 * configure_termination() function. Also restore the STPWLEVEL
9825 * bit of DEVCONFIG
9827 aic_outb(temp_p, sxfrctl1, SXFRCTL1);
9828 #if LINUX_VERSION_CODE > KERNEL_VERSION(2,1,92)
9829 pcibios_write_config_dword(temp_p->pci_bus, temp_p->pci_device_fn,
9830 DEVCONFIG, devconfig);
9831 #else
9832 pci_write_config_dword(temp_p->pdev, DEVCONFIG, devconfig);
9833 #endif
9834 sxfrctl1 &= STPWEN;
9837 * We need to set the CHNL? assignments before loading the SEEPROM
9838 * The 3940 and 3985 cards (original stuff, not any of the later
9839 * stuff) are 7870 and 7880 class chips. The Ultra2 stuff falls
9840 * under 7896 and 7897. The 7895 is in a class by itself :)
9842 switch (temp_p->chip & AHC_CHIPID_MASK)
9844 case AHC_AIC7870: /* 3840 / 3985 */
9845 case AHC_AIC7880: /* 3840 UW / 3985 UW */
9846 if(temp_p->flags & AHC_MULTI_CHANNEL)
9848 switch(PCI_SLOT(temp_p->pci_device_fn))
9850 case 5:
9851 temp_p->flags |= AHC_CHNLB;
9852 break;
9853 case 8:
9854 temp_p->flags |= AHC_CHNLB;
9855 break;
9856 case 12:
9857 temp_p->flags |= AHC_CHNLC;
9858 break;
9859 default:
9860 break;
9863 break;
9865 case AHC_AIC7895: /* 7895 */
9866 case AHC_AIC7896: /* 7896/7 */
9867 case AHC_AIC7899: /* 7899 */
9868 #if LINUX_VERSION_CODE > KERNEL_VERSION(2,1,92)
9869 if (PCI_FUNC(pdev->devfn) != 0)
9871 temp_p->flags |= AHC_CHNLB;
9874 * The 7895 is the only chipset that sets the SCBSIZE32 param
9875 * in the DEVCONFIG register. The Ultra2 chipsets use
9876 * the DSCOMMAND0 register instead.
9878 if ((temp_p->chip & AHC_CHIPID_MASK) == AHC_AIC7895)
9880 pci_read_config_dword(pdev, DEVCONFIG, &devconfig);
9881 devconfig |= SCBSIZE32;
9882 pci_write_config_dword(pdev, DEVCONFIG, devconfig);
9884 #else
9885 if (PCI_FUNC(temp_p->pci_device_fn) != 0)
9887 temp_p->flags |= AHC_CHNLB;
9890 * The 7895 is the only chipset that sets the SCBSIZE32 param
9891 * in the DEVCONFIG register. The Ultra2 chipsets use
9892 * the DSCOMMAND0 register instead.
9894 if ((temp_p->chip & AHC_CHIPID_MASK) == AHC_AIC7895)
9896 pcibios_read_config_dword(pci_bus, pci_devfn, DEVCONFIG,
9897 &devconfig);
9898 devconfig |= SCBSIZE32;
9899 pcibios_write_config_dword(pci_bus, pci_devfn, DEVCONFIG,
9900 devconfig);
9902 #endif
9903 break;
9904 default:
9905 break;
9909 * Loading of the SEEPROM needs to come after we've set the flags
9910 * to indicate possible CHNLB and CHNLC assigments. Otherwise,
9911 * on 394x and 398x cards we'll end up reading the wrong settings
9912 * for channels B and C
9914 switch (temp_p->chip & AHC_CHIPID_MASK)
9916 case AHC_AIC7892:
9917 case AHC_AIC7899:
9918 aic_outb(temp_p, 0, SCAMCTL);
9920 * Switch to the alt mode of the chip...
9922 aic_outb(temp_p, aic_inb(temp_p, SFUNCT) | ALT_MODE, SFUNCT);
9924 * Set our options...the last two items set our CRC after x byte
9925 * count in target mode...
9927 aic_outb(temp_p, AUTO_MSGOUT_DE | DIS_MSGIN_DUALEDGE, OPTIONMODE);
9928 aic_outb(temp_p, 0x00, 0x0b);
9929 aic_outb(temp_p, 0x10, 0x0a);
9931 * switch back to normal mode...
9933 aic_outb(temp_p, aic_inb(temp_p, SFUNCT) & ~ALT_MODE, SFUNCT);
9934 aic_outb(temp_p, CRCVALCHKEN | CRCENDCHKEN | CRCREQCHKEN |
9935 TARGCRCENDEN | TARGCRCCNTEN,
9936 CRCCONTROL1);
9937 aic_outb(temp_p, ((aic_inb(temp_p, DSCOMMAND0) | USCBSIZE32 |
9938 MPARCKEN | CIOPARCKEN | CACHETHEN) &
9939 ~DPARCKEN), DSCOMMAND0);
9940 aic7xxx_load_seeprom(temp_p, &sxfrctl1);
9941 break;
9942 case AHC_AIC7890:
9943 case AHC_AIC7896:
9944 aic_outb(temp_p, 0, SCAMCTL);
9945 aic_outb(temp_p, (aic_inb(temp_p, DSCOMMAND0) |
9946 CACHETHEN | MPARCKEN | USCBSIZE32 |
9947 CIOPARCKEN) & ~DPARCKEN, DSCOMMAND0);
9948 aic7xxx_load_seeprom(temp_p, &sxfrctl1);
9949 break;
9950 case AHC_AIC7850:
9951 case AHC_AIC7860:
9953 * Set the DSCOMMAND0 register on these cards different from
9954 * on the 789x cards. Also, read the SEEPROM as well.
9956 aic_outb(temp_p, (aic_inb(temp_p, DSCOMMAND0) |
9957 CACHETHEN | MPARCKEN) & ~DPARCKEN,
9958 DSCOMMAND0);
9959 /* FALLTHROUGH */
9960 default:
9961 aic7xxx_load_seeprom(temp_p, &sxfrctl1);
9962 break;
9963 case AHC_AIC7880:
9965 * Check the rev of the chipset before we change DSCOMMAND0
9967 #if LINUX_VERSION_CODE > KERNEL_VERSION(2,1,92)
9968 pci_read_config_dword(pdev, DEVCONFIG, &devconfig);
9969 #else
9970 pcibios_read_config_dword(pci_bus, pci_devfn, DEVCONFIG,
9971 &devconfig);
9972 #endif
9973 if ((devconfig & 0xff) >= 1)
9975 aic_outb(temp_p, (aic_inb(temp_p, DSCOMMAND0) |
9976 CACHETHEN | MPARCKEN) & ~DPARCKEN,
9977 DSCOMMAND0);
9979 aic7xxx_load_seeprom(temp_p, &sxfrctl1);
9980 break;
9985 * and then we need another switch based on the type in order to
9986 * make sure the channel B primary flag is set properly on 7895
9987 * controllers....Arrrgggghhh!!! We also have to catch the fact
9988 * that when you disable the BIOS on the 7895 on the Intel DK440LX
9989 * motherboard, and possibly others, it only sets the BIOS disabled
9990 * bit on the A channel...I think I'm starting to lean towards
9991 * going postal....
9993 switch(temp_p->chip & AHC_CHIPID_MASK)
9995 case AHC_AIC7895:
9996 case AHC_AIC7896:
9997 case AHC_AIC7899:
9998 current_p = list_p;
9999 while(current_p != NULL)
10001 if ( (current_p->pci_bus == temp_p->pci_bus) &&
10002 (PCI_SLOT(current_p->pci_device_fn) ==
10003 PCI_SLOT(temp_p->pci_device_fn)) )
10005 if ( PCI_FUNC(current_p->pci_device_fn) == 0 )
10007 temp_p->flags |=
10008 (current_p->flags & AHC_CHANNEL_B_PRIMARY);
10009 temp_p->flags &= ~(AHC_BIOS_ENABLED|AHC_USEDEFAULTS);
10010 temp_p->flags |=
10011 (current_p->flags & (AHC_BIOS_ENABLED|AHC_USEDEFAULTS));
10013 else
10015 current_p->flags |=
10016 (temp_p->flags & AHC_CHANNEL_B_PRIMARY);
10017 current_p->flags &= ~(AHC_BIOS_ENABLED|AHC_USEDEFAULTS);
10018 current_p->flags |=
10019 (temp_p->flags & (AHC_BIOS_ENABLED|AHC_USEDEFAULTS));
10022 current_p = current_p->next;
10024 break;
10025 default:
10026 break;
10030 * We only support external SCB RAM on the 7895/6/7 chipsets.
10031 * We could support it on the 7890/1 easy enough, but I don't
10032 * know of any 7890/1 based cards that have it. I do know
10033 * of 7895/6/7 cards that have it and they work properly.
10035 switch(temp_p->chip & AHC_CHIPID_MASK)
10037 default:
10038 break;
10039 case AHC_AIC7895:
10040 case AHC_AIC7896:
10041 case AHC_AIC7899:
10042 #if LINUX_VERSION_CODE > KERNEL_VERSION(2,1,92)
10043 pci_read_config_dword(pdev, DEVCONFIG, &devconfig);
10044 #else
10045 pcibios_read_config_dword(pci_bus, pci_devfn, DEVCONFIG,
10046 &devconfig);
10047 #endif
10048 if (temp_p->features & AHC_ULTRA2)
10050 if ( (aic_inb(temp_p, DSCOMMAND0) & RAMPSM_ULTRA2) &&
10051 (aic7xxx_scbram) )
10053 aic_outb(temp_p,
10054 aic_inb(temp_p, DSCOMMAND0) & ~SCBRAMSEL_ULTRA2,
10055 DSCOMMAND0);
10056 temp_p->flags |= AHC_EXTERNAL_SRAM;
10057 devconfig |= EXTSCBPEN;
10059 else if (aic_inb(temp_p, DSCOMMAND0) & RAMPSM_ULTRA2)
10061 printk(KERN_INFO "aic7xxx: <%s> at PCI %d/%d/%d\n",
10062 board_names[aic_pdevs[i].board_name_index],
10063 temp_p->pci_bus,
10064 PCI_SLOT(temp_p->pci_device_fn),
10065 PCI_FUNC(temp_p->pci_device_fn));
10066 printk("aic7xxx: external SCB RAM detected, "
10067 "but not enabled\n");
10070 else
10072 if ((devconfig & RAMPSM) && (aic7xxx_scbram))
10074 devconfig &= ~SCBRAMSEL;
10075 devconfig |= EXTSCBPEN;
10076 temp_p->flags |= AHC_EXTERNAL_SRAM;
10078 else if (devconfig & RAMPSM)
10080 printk(KERN_INFO "aic7xxx: <%s> at PCI %d/%d/%d\n",
10081 board_names[aic_pdevs[i].board_name_index],
10082 temp_p->pci_bus,
10083 PCI_SLOT(temp_p->pci_device_fn),
10084 PCI_FUNC(temp_p->pci_device_fn));
10085 printk("aic7xxx: external SCB RAM detected, "
10086 "but not enabled\n");
10089 #if LINUX_VERSION_CODE > KERNEL_VERSION(2,1,92)
10090 pci_write_config_dword(pdev, DEVCONFIG, devconfig);
10091 #else
10092 pcibios_write_config_dword(pci_bus, pci_devfn, DEVCONFIG,
10093 devconfig);
10094 #endif
10095 if ( (temp_p->flags & AHC_EXTERNAL_SRAM) &&
10096 (temp_p->flags & AHC_CHNLB) )
10097 aic_outb(temp_p, 1, CCSCBBADDR);
10098 break;
10102 * Take the LED out of diagnostic mode
10104 aic_outb(temp_p,
10105 (aic_inb(temp_p, SBLKCTL) & ~(DIAGLEDEN | DIAGLEDON)),
10106 SBLKCTL);
10109 * We don't know where this is set in the SEEPROM or by the
10110 * BIOS, so we default to 100%. On Ultra2 controllers, use 75%
10111 * instead.
10113 if (temp_p->features & AHC_ULTRA2)
10115 aic_outb(temp_p, RD_DFTHRSH_MAX | WR_DFTHRSH_MAX, DFF_THRSH);
10117 else
10119 aic_outb(temp_p, DFTHRSH_100, DSPCISTATUS);
10122 if ( list_p == NULL )
10124 list_p = current_p = temp_p;
10126 else
10128 current_p = list_p;
10129 while(current_p->next != NULL)
10130 current_p = current_p->next;
10131 current_p->next = temp_p;
10133 temp_p->next = NULL;
10134 found++;
10135 } /* Found an Adaptec PCI device. */
10136 else /* Well, we found one, but we couldn't get any memory */
10138 printk("aic7xxx: Found <%s>\n",
10139 board_names[aic_pdevs[i].board_name_index]);
10140 printk(KERN_INFO "aic7xxx: Unable to allocate device memory, "
10141 "skipping.\n");
10143 } /* while(pdev=....) */
10144 } /* for PCI_DEVICES */
10145 } /* PCI BIOS present */
10146 #endif CONFIG_PCI
10148 #if defined(__i386__) || defined(__alpha__)
10150 * EISA/VL-bus card signature probe.
10152 slot = MINSLOT;
10153 while ( (slot <= MAXSLOT) &&
10154 !(aic7xxx_no_probe) )
10156 base = SLOTBASE(slot) + MINREG;
10158 if (check_region(base, MAXREG - MINREG))
10161 * Some other driver has staked a
10162 * claim to this i/o region already.
10164 slot++;
10165 continue; /* back to the beginning of the for loop */
10167 flags = 0;
10168 type = aic7xxx_probe(slot, base + AHC_HID0, &flags);
10169 if (type == -1)
10171 slot++;
10172 continue;
10174 temp_p = kmalloc(sizeof(struct aic7xxx_host), GFP_ATOMIC);
10175 if (temp_p == NULL)
10177 printk(KERN_WARNING "aic7xxx: Unable to allocate device space.\n");
10178 slot++;
10179 continue; /* back to the beginning of the while loop */
10182 * Lock out other contenders for our i/o space.
10184 request_region(base, MAXREG - MINREG, "aic7xxx");
10187 * Pause the card preserving the IRQ type. Allow the operator
10188 * to override the IRQ trigger.
10190 if (aic7xxx_irq_trigger == 1)
10191 hcntrl = IRQMS; /* Level */
10192 else if (aic7xxx_irq_trigger == 0)
10193 hcntrl = 0; /* Edge */
10194 else
10195 hcntrl = inb(base + HCNTRL) & IRQMS; /* Default */
10196 memset(temp_p, 0, sizeof(struct aic7xxx_host));
10197 temp_p->unpause = hcntrl | INTEN;
10198 temp_p->pause = hcntrl | PAUSE | INTEN;
10199 temp_p->base = base;
10200 temp_p->mbase = 0;
10201 temp_p->maddr = 0;
10202 temp_p->pci_bus = 0;
10203 temp_p->pci_device_fn = slot;
10204 aic_outb(temp_p, hcntrl | PAUSE, HCNTRL);
10205 while( (aic_inb(temp_p, HCNTRL) & PAUSE) == 0 ) ;
10206 if (aic7xxx_chip_reset(temp_p) == -1)
10207 temp_p->irq = 0;
10208 else
10209 temp_p->irq = aic_inb(temp_p, INTDEF) & 0x0F;
10210 temp_p->flags |= AHC_PAGESCBS;
10212 switch (temp_p->irq)
10214 case 9:
10215 case 10:
10216 case 11:
10217 case 12:
10218 case 14:
10219 case 15:
10220 break;
10222 default:
10223 printk(KERN_WARNING "aic7xxx: Host adapter uses unsupported IRQ "
10224 "level %d, ignoring.\n", temp_p->irq);
10225 kfree(temp_p);
10226 release_region(base, MAXREG - MINREG);
10227 slot++;
10228 continue; /* back to the beginning of the while loop */
10232 * We are commited now, everything has been checked and this card
10233 * has been found, now we just set it up
10237 * Insert our new struct into the list at the end
10239 if (list_p == NULL)
10241 list_p = current_p = temp_p;
10243 else
10245 current_p = list_p;
10246 while (current_p->next != NULL)
10247 current_p = current_p->next;
10248 current_p->next = temp_p;
10251 switch (type)
10253 case 0:
10254 temp_p->board_name_index = 2;
10255 if (aic7xxx_verbose & VERBOSE_PROBE2)
10256 printk("aic7xxx: <%s> at EISA %d\n",
10257 board_names[2], slot);
10258 /* FALLTHROUGH */
10259 case 1:
10261 temp_p->chip = AHC_AIC7770 | AHC_EISA;
10262 temp_p->features |= AHC_AIC7770_FE;
10263 temp_p->bios_control = aic_inb(temp_p, HA_274_BIOSCTRL);
10266 * Get the primary channel information. Right now we don't
10267 * do anything with this, but someday we will be able to inform
10268 * the mid-level SCSI code which channel is primary.
10270 if (temp_p->board_name_index == 0)
10272 temp_p->board_name_index = 3;
10273 if (aic7xxx_verbose & VERBOSE_PROBE2)
10274 printk("aic7xxx: <%s> at EISA %d\n",
10275 board_names[3], slot);
10277 if (temp_p->bios_control & CHANNEL_B_PRIMARY)
10279 temp_p->flags |= AHC_CHANNEL_B_PRIMARY;
10282 if ((temp_p->bios_control & BIOSMODE) == BIOSDISABLED)
10284 temp_p->flags &= ~AHC_BIOS_ENABLED;
10286 else
10288 temp_p->flags &= ~AHC_USEDEFAULTS;
10289 temp_p->flags |= AHC_BIOS_ENABLED;
10290 if ( (temp_p->bios_control & 0x20) == 0 )
10292 temp_p->bios_address = 0xcc000;
10293 temp_p->bios_address += (0x4000 * (temp_p->bios_control & 0x07));
10295 else
10297 temp_p->bios_address = 0xd0000;
10298 temp_p->bios_address += (0x8000 * (temp_p->bios_control & 0x06));
10301 temp_p->adapter_control = aic_inb(temp_p, SCSICONF) << 8;
10302 temp_p->adapter_control |= aic_inb(temp_p, SCSICONF + 1);
10303 if (temp_p->features & AHC_WIDE)
10305 temp_p->scsi_id = temp_p->adapter_control & HWSCSIID;
10306 temp_p->scsi_id_b = temp_p->scsi_id;
10308 else
10310 temp_p->scsi_id = (temp_p->adapter_control >> 8) & HSCSIID;
10311 temp_p->scsi_id_b = temp_p->adapter_control & HSCSIID;
10313 aic7xxx_load_seeprom(temp_p, &sxfrctl1);
10314 break;
10317 case 2:
10318 case 3:
10319 temp_p->chip = AHC_AIC7770 | AHC_VL;
10320 temp_p->features |= AHC_AIC7770_FE;
10321 if (type == 2)
10322 temp_p->flags |= AHC_BIOS_ENABLED;
10323 else
10324 temp_p->flags &= ~AHC_BIOS_ENABLED;
10325 if (aic_inb(temp_p, SCSICONF) & TERM_ENB)
10326 sxfrctl1 = STPWEN;
10327 aic7xxx_load_seeprom(temp_p, &sxfrctl1);
10328 temp_p->board_name_index = 4;
10329 if (aic7xxx_verbose & VERBOSE_PROBE2)
10330 printk("aic7xxx: <%s> at VLB %d\n",
10331 board_names[2], slot);
10332 switch( aic_inb(temp_p, STATUS_2840) & BIOS_SEL )
10334 case 0x00:
10335 temp_p->bios_address = 0xe0000;
10336 break;
10337 case 0x20:
10338 temp_p->bios_address = 0xc8000;
10339 break;
10340 case 0x40:
10341 temp_p->bios_address = 0xd0000;
10342 break;
10343 case 0x60:
10344 temp_p->bios_address = 0xd8000;
10345 break;
10346 default:
10347 break; /* can't get here */
10349 break;
10351 default: /* Won't get here. */
10352 break;
10354 if (aic7xxx_verbose & VERBOSE_PROBE2)
10356 printk(KERN_INFO "aic7xxx: BIOS %sabled, IO Port 0x%lx, IRQ %d (%s)\n",
10357 (temp_p->flags & AHC_USEDEFAULTS) ? "dis" : "en", temp_p->base,
10358 temp_p->irq,
10359 (temp_p->pause & IRQMS) ? "level sensitive" : "edge triggered");
10360 printk(KERN_INFO "aic7xxx: Extended translation %sabled.\n",
10361 (temp_p->flags & AHC_EXTEND_TRANS_A) ? "en" : "dis");
10365 * Set the FIFO threshold and the bus off time.
10367 hostconf = aic_inb(temp_p, HOSTCONF);
10368 aic_outb(temp_p, hostconf & DFTHRSH, BUSSPD);
10369 aic_outb(temp_p, (hostconf << 2) & BOFF, BUSTIME);
10370 slot++;
10371 found++;
10374 #endif /* defined(__i386__) || defined(__alpha__) */
10377 * Now, we re-order the probed devices by BIOS address and BUS class.
10378 * In general, we follow this algorithm to make the adapters show up
10379 * in the same order under linux that the computer finds them.
10380 * 1: All VLB/EISA cards with BIOS_ENABLED first, according to BIOS
10381 * address, going from lowest to highest.
10382 * 2: All PCI controllers with BIOS_ENABLED next, according to BIOS
10383 * address, going from lowest to highest.
10384 * 3: Remaining VLB/EISA controllers going in slot order.
10385 * 4: Remaining PCI controllers, going in PCI device order (reversable)
10389 struct aic7xxx_host *sort_list[4] = { NULL, NULL, NULL, NULL };
10390 struct aic7xxx_host *vlb, *pci;
10391 struct aic7xxx_host *prev_p;
10392 struct aic7xxx_host *p;
10393 unsigned char left;
10395 prev_p = vlb = pci = NULL;
10397 temp_p = list_p;
10398 while (temp_p != NULL)
10400 switch(temp_p->chip & ~AHC_CHIPID_MASK)
10402 case AHC_EISA:
10403 case AHC_VL:
10405 p = temp_p;
10406 if (p->flags & AHC_BIOS_ENABLED)
10407 vlb = sort_list[0];
10408 else
10409 vlb = sort_list[2];
10411 if (vlb == NULL)
10413 vlb = temp_p;
10414 temp_p = temp_p->next;
10415 vlb->next = NULL;
10417 else
10419 current_p = vlb;
10420 prev_p = NULL;
10421 while ( (current_p != NULL) &&
10422 (current_p->bios_address < temp_p->bios_address))
10424 prev_p = current_p;
10425 current_p = current_p->next;
10427 if (prev_p != NULL)
10429 prev_p->next = temp_p;
10430 temp_p = temp_p->next;
10431 prev_p->next->next = current_p;
10433 else
10435 vlb = temp_p;
10436 temp_p = temp_p->next;
10437 vlb->next = current_p;
10441 if (p->flags & AHC_BIOS_ENABLED)
10442 sort_list[0] = vlb;
10443 else
10444 sort_list[2] = vlb;
10446 break;
10448 default: /* All PCI controllers fall through to default */
10451 p = temp_p;
10452 if (p->flags & AHC_BIOS_ENABLED)
10453 pci = sort_list[1];
10454 else
10455 pci = sort_list[3];
10457 if (pci == NULL)
10459 pci = temp_p;
10460 temp_p = temp_p->next;
10461 pci->next = NULL;
10463 else
10465 current_p = pci;
10466 prev_p = NULL;
10467 if (!aic7xxx_reverse_scan)
10469 while ( (current_p != NULL) &&
10470 ( (PCI_SLOT(current_p->pci_device_fn) |
10471 (current_p->pci_bus << 8)) <
10472 (PCI_SLOT(temp_p->pci_device_fn) |
10473 (temp_p->pci_bus << 8)) ) )
10475 prev_p = current_p;
10476 current_p = current_p->next;
10479 else
10481 while ( (current_p != NULL) &&
10482 ( (PCI_SLOT(current_p->pci_device_fn) |
10483 (current_p->pci_bus << 8)) >
10484 (PCI_SLOT(temp_p->pci_device_fn) |
10485 (temp_p->pci_bus << 8)) ) )
10487 prev_p = current_p;
10488 current_p = current_p->next;
10492 * Are we dealing with a 7895/6/7/9 where we need to sort the
10493 * channels as well, if so, the bios_address values should
10494 * be the same
10496 if ( (current_p) && (temp_p->flags & AHC_MULTI_CHANNEL) &&
10497 (temp_p->pci_bus == current_p->pci_bus) &&
10498 (PCI_SLOT(temp_p->pci_device_fn) ==
10499 PCI_SLOT(current_p->pci_device_fn)) )
10501 if (temp_p->flags & AHC_CHNLB)
10503 if ( !(temp_p->flags & AHC_CHANNEL_B_PRIMARY) )
10505 prev_p = current_p;
10506 current_p = current_p->next;
10509 else
10511 if (temp_p->flags & AHC_CHANNEL_B_PRIMARY)
10513 prev_p = current_p;
10514 current_p = current_p->next;
10518 if (prev_p != NULL)
10520 prev_p->next = temp_p;
10521 temp_p = temp_p->next;
10522 prev_p->next->next = current_p;
10524 else
10526 pci = temp_p;
10527 temp_p = temp_p->next;
10528 pci->next = current_p;
10532 if (p->flags & AHC_BIOS_ENABLED)
10533 sort_list[1] = pci;
10534 else
10535 sort_list[3] = pci;
10537 break;
10539 } /* End of switch(temp_p->type) */
10540 } /* End of while (temp_p != NULL) */
10542 * At this point, the cards have been broken into 4 sorted lists, now
10543 * we run through the lists in order and register each controller
10546 int i;
10548 left = found;
10549 for (i=0; i<NUMBER(sort_list); i++)
10551 temp_p = sort_list[i];
10552 while(temp_p != NULL)
10554 template->name = board_names[temp_p->board_name_index];
10555 p = aic7xxx_alloc(template, temp_p);
10556 if (p != NULL)
10558 p->instance = found - left;
10559 if (aic7xxx_register(template, p, (--left)) == 0)
10561 found--;
10562 aic7xxx_release(p->host);
10563 scsi_unregister(p->host);
10565 else if (aic7xxx_dump_card)
10567 pause_sequencer(p);
10568 aic7xxx_print_card(p);
10569 aic7xxx_print_scratch_ram(p);
10570 unpause_sequencer(p, TRUE);
10573 current_p = temp_p;
10574 temp_p = (struct aic7xxx_host *)temp_p->next;
10575 kfree(current_p);
10580 return (found);
10583 static void aic7xxx_build_negotiation_cmnd(struct aic7xxx_host *p,
10584 Scsi_Cmnd *old_cmd, int tindex);
10586 /*+F*************************************************************************
10587 * Function:
10588 * aic7xxx_allocate_negotiation_command
10590 * Description:
10591 * allocate the actual command struct and fill in the gaps...
10592 *-F*************************************************************************/
10593 static Scsi_Cmnd *
10594 aic7xxx_allocate_negotiation_command(struct aic7xxx_host *p,
10595 Scsi_Cmnd *old_cmd, int tindex)
10597 Scsi_Cmnd *cmd;
10598 char *buffer;
10600 if (!(p->dev_dtr_cmnd[tindex] = kmalloc(sizeof(Scsi_Cmnd), GFP_ATOMIC)) )
10602 return(NULL);
10604 if (!(buffer = kmalloc(256, GFP_ATOMIC)))
10606 kfree(p->dev_dtr_cmnd[tindex]);
10607 p->dev_dtr_cmnd[tindex] = NULL;
10608 return(NULL);
10610 cmd = p->dev_dtr_cmnd[tindex];
10611 memset(cmd, 0, sizeof(Scsi_Cmnd));
10612 memcpy(cmd, old_cmd, sizeof(Scsi_Cmnd));
10613 memset(&cmd->cmnd[0], 0, sizeof(cmd->cmnd));
10614 memset(&cmd->data_cmnd[0], 0, sizeof(cmd->data_cmnd));
10615 cmd->lun = 0;
10616 cmd->request_bufflen = 255;
10617 cmd->request_buffer = buffer;
10618 cmd->sc_data_direction = SCSI_DATA_READ;
10619 cmd->use_sg = cmd->old_use_sg = cmd->sglist_len = 0;
10620 cmd->bufflen = 0;
10621 cmd->buffer = NULL;
10622 cmd->underflow = 0;
10623 cmd->cmd_len = 6;
10624 cmd->cmnd[0] = cmd->data_cmnd[0] = INQUIRY;
10625 cmd->cmnd[1] = cmd->data_cmnd[1] = 0;
10626 cmd->cmnd[2] = cmd->data_cmnd[2] = 0;
10627 cmd->cmnd[3] = cmd->data_cmnd[3] = 0;
10628 cmd->cmnd[4] = cmd->data_cmnd[4] = 255; /* match what scsi.c does here */
10629 cmd->cmnd[5] = cmd->data_cmnd[5] = 0;
10630 return(cmd);
10633 /*+F*************************************************************************
10634 * Function:
10635 * aic7xxx_negotiation_complete
10637 * Description:
10638 * Handle completion events for our Negotiation commands. Clear out the
10639 * struct and get it ready for its next use.
10640 *-F*************************************************************************/
10641 static void
10642 aic7xxx_negotiation_complete(Scsi_Cmnd *cmd)
10644 unsigned int checksum;
10645 int i;
10646 int *ibuffer;
10647 struct aic7xxx_host *p = (struct aic7xxx_host *)cmd->host->hostdata;
10648 int tindex = TARGET_INDEX(cmd);
10649 struct aic7xxx_syncrate *syncrate;
10652 * perform our minimalistic domain validation
10654 if(p->dev_flags[tindex] & DEVICE_SCANNED)
10656 ibuffer = (int *)cmd->request_buffer;
10657 checksum = 0;
10658 for(i = 0; i < (cmd->request_bufflen >> 2); i++)
10660 checksum += ibuffer[i];
10662 if( (checksum != p->dev_checksum[tindex]) &&
10663 (p->transinfo[tindex].cur_offset != 0) )
10665 unsigned int period = p->transinfo[tindex].cur_period;
10666 unsigned char options = p->transinfo[tindex].cur_options;
10668 if (p->needdv & (1<<tindex))
10671 * oops, we had a failure, lower the transfer rate and try again. It's
10672 * worth noting here that it might be wise to also check for typical
10673 * wide setting on narrow cable type problems and try disabling wide
10674 * instead of slowing down if those exist. That's hard to do with simple
10675 * checksums though.
10677 if(aic7xxx_verbose & VERBOSE_NEGOTIATION2)
10679 printk(INFO_LEAD "reducing SCSI transfer speed due to Domain "
10680 "validation failure.\n", p->host_no, CTL_OF_CMD(cmd));
10682 if((syncrate = aic7xxx_find_syncrate(p, &period, 0, &options)) != NULL)
10684 syncrate++;
10685 if( (syncrate->rate[0] != NULL) &&
10686 (!(p->features & AHC_ULTRA2) || (syncrate->sxfr_ultra2 == 0)) )
10688 p->transinfo[tindex].goal_period = syncrate->period;
10689 if( !(syncrate->sxfr_ultra2 & 0x40) )
10691 p->transinfo[tindex].goal_options = 0;
10694 else
10696 p->transinfo[tindex].goal_offset = 0;
10697 p->transinfo[tindex].goal_period = 0;
10698 p->transinfo[tindex].goal_options = 0;
10700 p->needppr |= (p->needppr_copy & (1<<tindex));
10701 p->needsdtr |= (p->needsdtr_copy & (1<<tindex));
10702 p->needwdtr |= (p->needwdtr_copy & (1<<tindex));
10704 p->needdv &= ~(1<<tindex);
10706 else
10708 if(aic7xxx_verbose & VERBOSE_NEGOTIATION2)
10710 printk(INFO_LEAD "Performing Domain validation.\n",
10711 p->host_no, CTL_OF_CMD(cmd));
10714 * Update the checksum in case the INQUIRY data has changed, maybe
10715 * in relation to a change in the mode pages, or whatever.
10717 p->dev_checksum[tindex] = checksum;
10719 * Signal that we are trying out the domain validation
10721 p->needdv |= (1<<tindex);
10723 * Signal that we need to re-negotiate things, this also gets us our
10724 * INQUIRY command to re-checksum off of.
10726 p->needppr |= (p->needppr_copy & (1<<tindex));
10727 p->needsdtr |= (p->needsdtr_copy & (1<<tindex));
10728 p->needwdtr |= (p->needwdtr_copy & (1<<tindex));
10731 else
10733 if( (aic7xxx_verbose & VERBOSE_NEGOTIATION2) &&
10734 (p->needdv & (1<<tindex)) )
10736 printk(INFO_LEAD "Successfully completed Domain validation.\n",
10737 p->host_no, CTL_OF_CMD(cmd));
10740 * We successfully did our checksum, so don't leave the needdv flag set
10741 * in case we might have set it last time through.
10743 p->needdv &= ~(1<<tindex);
10747 p->dtr_pending &= ~(0x01 << tindex);
10749 * This looks recursive in the extreme, but if this was a WDTR negotiation
10750 * and we didn't follow up with SDTR yet, then this will get it started.
10751 * For all other cases, this should work out to be a no-op, unless we are
10752 * doing domain validation and happen to need a new negotiation command.
10754 aic7xxx_build_negotiation_cmnd(p, cmd->next, tindex);
10755 return;
10758 /*+F*************************************************************************
10759 * Function:
10760 * aic7xxx_build_negotiation_command
10762 * Description:
10763 * Build a Scsi_Cmnd structure to perform negotiation with or else send
10764 * a pre-built command specifically for this purpose.
10765 *-F*************************************************************************/
10766 static void
10767 aic7xxx_build_negotiation_cmnd(struct aic7xxx_host *p, Scsi_Cmnd *old_cmd,
10768 int tindex)
10771 if ( !(p->dtr_pending & (1<<tindex)) &&
10772 ( (p->needppr & (1<<tindex)) ||
10773 (p->needwdtr & (1<<tindex)) ||
10774 (p->needsdtr & (1<<tindex)) ) )
10776 if ( (p->dev_dtr_cmnd[tindex] == NULL) &&
10777 (aic7xxx_allocate_negotiation_command(p, old_cmd, tindex) == NULL) )
10779 return;
10782 * Before sending this thing out, we also make the cmd->next pointer
10783 * point to the real command so we can stuff any possible SENSE data
10784 * into the real command instead of this fake command. This has to be
10785 * done each time the command is built, not just the first time, hence
10786 * it's outside of the above if()...
10788 p->dev_dtr_cmnd[tindex]->next = old_cmd;
10790 * Clear the buffer so checksums come out right....
10792 memset(p->dev_dtr_cmnd[tindex]->request_buffer, 0,
10793 p->dev_dtr_cmnd[tindex]->request_bufflen);
10795 * Remove any commands for this particular device that might be on the
10796 * waiting_scbs queue or qinfifo so that this command goes out first.
10797 * This is vital for our implementation of domain validation.
10799 pause_sequencer(p);
10800 aic7xxx_search_qinfifo(p, old_cmd->target, old_cmd->channel, ALL_LUNS,
10801 SCB_LIST_NULL, 0, TRUE, &p->delayed_scbs[tindex]);
10802 unpause_sequencer(p, FALSE);
10804 struct aic7xxx_scb *scb, *next;
10806 scb = p->waiting_scbs.head;
10807 while(scb != NULL)
10809 if( aic7xxx_match_scb(p, scb, old_cmd->target, old_cmd->channel,
10810 ALL_LUNS, SCB_LIST_NULL) )
10812 next = scb->q_next;
10813 scbq_remove(&p->waiting_scbs, scb);
10814 scbq_insert_tail(&p->delayed_scbs[tindex], scb);
10815 scb = next;
10817 else
10819 scb = scb->q_next;
10823 aic7xxx_queue(p->dev_dtr_cmnd[tindex],
10824 aic7xxx_negotiation_complete);
10828 #ifdef AIC7XXX_VERBOSE_DEBUGGING
10829 /*+F*************************************************************************
10830 * Function:
10831 * aic7xxx_print_scb
10833 * Description:
10834 * Dump the byte codes for an about to be sent SCB.
10835 *-F*************************************************************************/
10836 static void
10837 aic7xxx_print_scb(struct aic7xxx_host *p, struct aic7xxx_scb *scb)
10839 int i;
10840 unsigned char *x;
10842 x = (unsigned char *)&scb->hscb->control;
10844 for(i=0; i<32; i++)
10846 printk("%02x ", x[i]);
10848 printk("\n");
10850 #endif
10852 /*+F*************************************************************************
10853 * Function:
10854 * aic7xxx_buildscb
10856 * Description:
10857 * Build a SCB.
10858 *-F*************************************************************************/
10859 static void
10860 aic7xxx_buildscb(struct aic7xxx_host *p, Scsi_Cmnd *cmd,
10861 struct aic7xxx_scb *scb)
10863 unsigned short mask;
10864 struct aic7xxx_hwscb *hscb;
10865 unsigned char tindex = TARGET_INDEX(cmd);
10867 mask = (0x01 << tindex);
10868 hscb = scb->hscb;
10871 * Setup the control byte if we need negotiation and have not
10872 * already requested it.
10874 hscb->control = 0;
10875 scb->tag_action = 0;
10876 if (p->discenable & mask)
10878 hscb->control |= DISCENB;
10879 if ( (p->tagenable & mask) &&
10880 (cmd->cmnd[0] != TEST_UNIT_READY) )
10882 cmd->tag = hscb->tag;
10883 p->dev_commands_sent[tindex]++;
10884 if (p->dev_commands_sent[tindex] < 200)
10886 hscb->control |= MSG_SIMPLE_Q_TAG;
10887 scb->tag_action = MSG_SIMPLE_Q_TAG;
10889 else
10891 if (p->orderedtag & mask)
10893 hscb->control |= MSG_ORDERED_Q_TAG;
10894 scb->tag_action = MSG_ORDERED_Q_TAG;
10896 else
10898 hscb->control |= MSG_SIMPLE_Q_TAG;
10899 scb->tag_action = MSG_SIMPLE_Q_TAG;
10901 p->dev_commands_sent[tindex] = 0;
10905 if ( cmd == p->dev_dtr_cmnd[tindex] )
10907 p->dtr_pending |= mask;
10908 scb->tag_action = 0;
10909 if (p->dev_flags[tindex] & DEVICE_SCANNED)
10911 hscb->control &= DISCENB;
10912 hscb->control |= MK_MESSAGE;
10913 if(p->needppr & mask)
10915 scb->flags |= SCB_MSGOUT_PPR;
10917 else if(p->needwdtr & mask)
10919 scb->flags |= SCB_MSGOUT_WDTR;
10921 else if(p->needsdtr & mask)
10923 scb->flags |= SCB_MSGOUT_SDTR;
10927 if ( !(p->dtr_pending & mask) &&
10928 ( (p->needppr & mask) ||
10929 (p->needwdtr & mask) ||
10930 (p->needsdtr & mask) ) )
10932 aic7xxx_build_negotiation_cmnd(p, cmd, tindex);
10934 hscb->target_channel_lun = ((cmd->target << 4) & 0xF0) |
10935 ((cmd->channel & 0x01) << 3) | (cmd->lun & 0x07);
10938 * The interpretation of request_buffer and request_bufflen
10939 * changes depending on whether or not use_sg is zero; a
10940 * non-zero use_sg indicates the number of elements in the
10941 * scatter-gather array.
10945 * XXX - this relies on the host data being stored in a
10946 * little-endian format.
10948 hscb->SCSI_cmd_length = cmd->cmd_len;
10949 memcpy(scb->cmnd, cmd->cmnd, cmd->cmd_len);
10950 hscb->SCSI_cmd_pointer = cpu_to_le32(SCB_DMA_ADDR(scb, scb->cmnd));
10952 if (cmd->use_sg)
10954 struct scatterlist *sg; /* Must be mid-level SCSI code scatterlist */
10957 * We must build an SG list in adapter format, as the kernel's SG list
10958 * cannot be used directly because of data field size (__alpha__)
10959 * differences and the kernel SG list uses virtual addresses where
10960 * we need physical addresses.
10962 int i, use_sg;
10964 sg = (struct scatterlist *)cmd->request_buffer;
10965 scb->sg_length = 0;
10966 use_sg = pci_map_sg(p->pdev, sg, cmd->use_sg, scsi_to_pci_dma_dir(cmd->sc_data_direction));
10968 * Copy the segments into the SG array. NOTE!!! - We used to
10969 * have the first entry both in the data_pointer area and the first
10970 * SG element. That has changed somewhat. We still have the first
10971 * entry in both places, but now we download the address of
10972 * scb->sg_list[1] instead of 0 to the sg pointer in the hscb.
10974 for (i = 0; i < use_sg; i++)
10976 unsigned int len = sg_dma_len(sg+i);
10977 scb->sg_list[i].address = cpu_to_le32(sg_dma_address(sg+i));
10978 scb->sg_list[i].length = cpu_to_le32(len);
10979 scb->sg_length += len;
10981 /* Copy the first SG into the data pointer area. */
10982 hscb->data_pointer = scb->sg_list[0].address;
10983 hscb->data_count = scb->sg_list[0].length;
10984 scb->sg_count = i;
10985 hscb->SG_segment_count = i;
10986 hscb->SG_list_pointer = cpu_to_le32(SCB_DMA_ADDR(scb, &scb->sg_list[1]));
10988 else
10990 if (cmd->request_bufflen)
10992 unsigned int address = pci_map_single(p->pdev, cmd->request_buffer,
10993 cmd->request_bufflen,
10994 scsi_to_pci_dma_dir(cmd->sc_data_direction));
10995 aic7xxx_mapping(cmd) = address;
10996 scb->sg_list[0].address = cpu_to_le32(address);
10997 scb->sg_list[0].length = cpu_to_le32(cmd->request_bufflen);
10998 scb->sg_count = 1;
10999 scb->sg_length = cmd->request_bufflen;
11000 hscb->SG_segment_count = 1;
11001 hscb->SG_list_pointer = cpu_to_le32(SCB_DMA_ADDR(scb, &scb->sg_list[0]));
11002 hscb->data_count = scb->sg_list[0].length;
11003 hscb->data_pointer = scb->sg_list[0].address;
11005 else
11007 scb->sg_count = 0;
11008 scb->sg_length = 0;
11009 hscb->SG_segment_count = 0;
11010 hscb->SG_list_pointer = 0;
11011 hscb->data_count = 0;
11012 hscb->data_pointer = 0;
11017 /*+F*************************************************************************
11018 * Function:
11019 * aic7xxx_queue
11021 * Description:
11022 * Queue a SCB to the controller.
11023 *-F*************************************************************************/
11025 aic7xxx_queue(Scsi_Cmnd *cmd, void (*fn)(Scsi_Cmnd *))
11027 struct aic7xxx_host *p;
11028 struct aic7xxx_scb *scb;
11029 #ifdef AIC7XXX_VERBOSE_DEBUGGING
11030 int tindex = TARGET_INDEX(cmd);
11031 #endif
11032 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,1,95)
11033 unsigned long cpu_flags = 0;
11034 #endif
11036 p = (struct aic7xxx_host *) cmd->host->hostdata;
11038 * Check to see if channel was scanned.
11041 #ifdef AIC7XXX_VERBOSE_DEBUGGING
11042 if (!(p->flags & AHC_A_SCANNED) && (cmd->channel == 0))
11044 if (aic7xxx_verbose & VERBOSE_PROBE2)
11045 printk(INFO_LEAD "Scanning channel for devices.\n",
11046 p->host_no, 0, -1, -1);
11047 p->flags |= AHC_A_SCANNED;
11049 else
11051 if (!(p->flags & AHC_B_SCANNED) && (cmd->channel == 1))
11053 if (aic7xxx_verbose & VERBOSE_PROBE2)
11054 printk(INFO_LEAD "Scanning channel for devices.\n",
11055 p->host_no, 1, -1, -1);
11056 p->flags |= AHC_B_SCANNED;
11060 if (p->dev_active_cmds[tindex] > (cmd->device->queue_depth + 1))
11062 printk(WARN_LEAD "Commands queued exceeds queue "
11063 "depth, active=%d\n",
11064 p->host_no, CTL_OF_CMD(cmd),
11065 p->dev_active_cmds[tindex]);
11066 if ( p->dev_active_cmds[tindex] > 220 )
11067 p->dev_active_cmds[tindex] = 0;
11069 #endif
11071 scb = scbq_remove_head(&p->scb_data->free_scbs);
11072 if (scb == NULL)
11074 DRIVER_LOCK
11075 aic7xxx_allocate_scb(p);
11076 DRIVER_UNLOCK
11077 scb = scbq_remove_head(&p->scb_data->free_scbs);
11079 if (scb == NULL)
11081 printk(WARN_LEAD "Couldn't get a free SCB.\n", p->host_no,
11082 CTL_OF_CMD(cmd));
11083 cmd->result = (DID_BUS_BUSY << 16);
11084 DRIVER_LOCK
11085 aic7xxx_queue_cmd_complete(p, cmd);
11086 DRIVER_UNLOCK
11087 return 0;
11089 else
11091 scb->cmd = cmd;
11092 aic7xxx_position(cmd) = scb->hscb->tag;
11095 * Construct the SCB beforehand, so the sequencer is
11096 * paused a minimal amount of time.
11098 aic7xxx_buildscb(p, cmd, scb);
11101 * Make sure the Scsi_Cmnd pointer is saved, the struct it points to
11102 * is set up properly, and the parity error flag is reset, then send
11103 * the SCB to the sequencer and watch the fun begin.
11105 cmd->scsi_done = fn;
11106 cmd->result = DID_OK;
11107 memset(cmd->sense_buffer, 0, sizeof(cmd->sense_buffer));
11108 aic7xxx_error(cmd) = DID_OK;
11109 aic7xxx_status(cmd) = 0;
11110 cmd->host_scribble = NULL;
11112 scb->flags |= SCB_ACTIVE | SCB_WAITINGQ;
11114 DRIVER_LOCK
11115 scbq_insert_tail(&p->waiting_scbs, scb);
11116 if ( (p->flags & (AHC_IN_ISR | AHC_IN_ABORT | AHC_IN_RESET)) == 0)
11118 aic7xxx_run_waiting_queues(p);
11120 DRIVER_UNLOCK
11122 return (0);
11125 /*+F*************************************************************************
11126 * Function:
11127 * aic7xxx_bus_device_reset
11129 * Description:
11130 * Abort or reset the current SCSI command(s). If the scb has not
11131 * previously been aborted, then we attempt to send a BUS_DEVICE_RESET
11132 * message to the target. If the scb has previously been unsuccessfully
11133 * aborted, then we will reset the channel and have all devices renegotiate.
11134 * Returns an enumerated type that indicates the status of the operation.
11135 *-F*************************************************************************/
11136 static int
11137 aic7xxx_bus_device_reset(struct aic7xxx_host *p, Scsi_Cmnd *cmd)
11139 struct aic7xxx_scb *scb;
11140 struct aic7xxx_hwscb *hscb;
11141 int result = -1;
11142 int channel;
11143 unsigned char saved_scbptr, lastphase;
11144 unsigned char hscb_index;
11145 int disconnected;
11147 scb = (p->scb_data->scb_array[aic7xxx_position(cmd)]);
11148 hscb = scb->hscb;
11150 lastphase = aic_inb(p, LASTPHASE);
11151 if (aic7xxx_verbose & VERBOSE_RESET_PROCESS)
11153 printk(INFO_LEAD "Bus Device reset, scb flags 0x%x, ",
11154 p->host_no, CTL_OF_SCB(scb), scb->flags);
11155 switch (lastphase)
11157 case P_DATAOUT:
11158 printk("Data-Out phase\n");
11159 break;
11160 case P_DATAIN:
11161 printk("Data-In phase\n");
11162 break;
11163 case P_COMMAND:
11164 printk("Command phase\n");
11165 break;
11166 case P_MESGOUT:
11167 printk("Message-Out phase\n");
11168 break;
11169 case P_STATUS:
11170 printk("Status phase\n");
11171 break;
11172 case P_MESGIN:
11173 printk("Message-In phase\n");
11174 break;
11175 default:
11177 * We're not in a valid phase, so assume we're idle.
11179 printk("while idle, LASTPHASE = 0x%x\n", lastphase);
11180 break;
11182 printk(INFO_LEAD "SCSISIGI 0x%x, SEQADDR 0x%x, SSTAT0 0x%x, SSTAT1 "
11183 "0x%x\n", p->host_no, CTL_OF_SCB(scb),
11184 aic_inb(p, SCSISIGI),
11185 aic_inb(p, SEQADDR0) | (aic_inb(p, SEQADDR1) << 8),
11186 aic_inb(p, SSTAT0), aic_inb(p, SSTAT1));
11189 channel = cmd->channel;
11192 * Send a Device Reset Message:
11193 * The target that is holding up the bus may not be the same as
11194 * the one that triggered this timeout (different commands have
11195 * different timeout lengths). Our strategy here is to queue an
11196 * abort message to the timed out target if it is disconnected.
11197 * Otherwise, if we have an active target we stuff the message buffer
11198 * with an abort message and assert ATN in the hopes that the target
11199 * will let go of the bus and go to the mesgout phase. If this
11200 * fails, we'll get another timeout a few seconds later which will
11201 * attempt a bus reset.
11203 saved_scbptr = aic_inb(p, SCBPTR);
11204 disconnected = FALSE;
11206 if (lastphase != P_BUSFREE)
11208 if (aic_inb(p, SCB_TAG) >= p->scb_data->numscbs)
11210 printk(WARN_LEAD "Invalid SCB ID %d is active, "
11211 "SCB flags = 0x%x.\n", p->host_no,
11212 CTL_OF_CMD(cmd), scb->hscb->tag, scb->flags);
11213 return(SCSI_RESET_ERROR);
11215 if (scb->hscb->tag == aic_inb(p, SCB_TAG))
11217 if ( (lastphase != P_MESGOUT) && (lastphase != P_MESGIN) )
11219 if (aic7xxx_verbose & VERBOSE_RESET_PROCESS)
11220 printk(INFO_LEAD "Device reset message in "
11221 "message buffer\n", p->host_no, CTL_OF_SCB(scb));
11222 scb->flags |= SCB_RESET | SCB_DEVICE_RESET;
11223 aic7xxx_error(scb->cmd) = DID_RESET;
11224 p->dev_flags[TARGET_INDEX(scb->cmd)] |=
11225 BUS_DEVICE_RESET_PENDING;
11226 /* Send the abort message to the active SCB. */
11227 aic_outb(p, HOST_MSG, MSG_OUT);
11228 aic_outb(p, lastphase | ATNO, SCSISIGO);
11229 return(SCSI_RESET_PENDING);
11231 else
11233 /* We want to send out the message, but it could screw an already */
11234 /* in place and being used message. Instead, we return an error */
11235 /* to try and start the bus reset phase since this command is */
11236 /* probably hung (aborts failed, and now reset is failing). We */
11237 /* also make sure to set BUS_DEVICE_RESET_PENDING so we won't try */
11238 /* any more on this device, but instead will escalate to a bus or */
11239 /* host reset (additionally, we won't try to abort any more). */
11240 printk(WARN_LEAD "Device reset, Message buffer "
11241 "in use\n", p->host_no, CTL_OF_SCB(scb));
11242 scb->flags |= SCB_RESET | SCB_DEVICE_RESET;
11243 aic7xxx_error(scb->cmd) = DID_RESET;
11244 p->dev_flags[TARGET_INDEX(scb->cmd)] |=
11245 BUS_DEVICE_RESET_PENDING;
11246 return(SCSI_RESET_ERROR);
11249 } /* if (last_phase != P_BUSFREE).....indicates we are idle and can work */
11250 hscb_index = aic7xxx_find_scb(p, scb);
11251 if (hscb_index == SCB_LIST_NULL)
11253 disconnected = (aic7xxx_scb_on_qoutfifo(p, scb)) ? FALSE : TRUE;
11255 else
11257 aic_outb(p, hscb_index, SCBPTR);
11258 if (aic_inb(p, SCB_CONTROL) & DISCONNECTED)
11260 disconnected = TRUE;
11263 if (disconnected)
11266 * Simply set the MK_MESSAGE flag and the SEQINT handler will do
11267 * the rest on a reconnect.
11269 scb->hscb->control |= MK_MESSAGE;
11270 scb->flags |= SCB_RESET | SCB_DEVICE_RESET;
11271 p->dev_flags[TARGET_INDEX(scb->cmd)] |=
11272 BUS_DEVICE_RESET_PENDING;
11273 if (hscb_index != SCB_LIST_NULL)
11275 unsigned char scb_control;
11277 aic_outb(p, hscb_index, SCBPTR);
11278 scb_control = aic_inb(p, SCB_CONTROL);
11279 aic_outb(p, scb_control | MK_MESSAGE, SCB_CONTROL);
11282 * Actually requeue this SCB in case we can select the
11283 * device before it reconnects. If the transaction we
11284 * want to abort is not tagged, then this will be the only
11285 * outstanding command and we can simply shove it on the
11286 * qoutfifo and be done. If it is tagged, then it goes right
11287 * in with all the others, no problem :) We need to add it
11288 * to the qinfifo and let the sequencer know it is there.
11289 * Now, the only problem left to deal with is, *IF* this
11290 * command completes, in spite of the MK_MESSAGE bit in the
11291 * control byte, then we need to pick that up in the interrupt
11292 * routine and clean things up. This *shouldn't* ever happen.
11294 if (aic7xxx_verbose & VERBOSE_RESET_PROCESS)
11295 printk(INFO_LEAD "Queueing device reset "
11296 "command.\n", p->host_no, CTL_OF_SCB(scb));
11297 p->qinfifo[p->qinfifonext++] = scb->hscb->tag;
11298 if (p->features & AHC_QUEUE_REGS)
11299 aic_outb(p, p->qinfifonext, HNSCB_QOFF);
11300 else
11301 aic_outb(p, p->qinfifonext, KERNEL_QINPOS);
11302 scb->flags |= SCB_QUEUED_ABORT;
11303 result = SCSI_RESET_PENDING;
11305 else if (result == -1)
11307 result = SCSI_RESET_ERROR;
11309 aic_outb(p, saved_scbptr, SCBPTR);
11310 return (result);
11314 /*+F*************************************************************************
11315 * Function:
11316 * aic7xxx_panic_abort
11318 * Description:
11319 * Abort the current SCSI command(s).
11320 *-F*************************************************************************/
11321 void
11322 aic7xxx_panic_abort(struct aic7xxx_host *p, Scsi_Cmnd *cmd)
11324 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,1,0)
11325 int i, mask, found, need_tag;
11326 struct aic7xxx_scb *scb;
11327 unsigned char qinpos, hscbp;
11329 found = FALSE;
11330 #endif
11332 printk("aic7xxx driver version %s/%s\n", AIC7XXX_C_VERSION,
11333 UTS_RELEASE);
11334 printk("Controller type:\n %s\n", board_names[p->board_name_index]);
11335 printk("p->flags=0x%x, p->chip=0x%x, p->features=0x%x, "
11336 "sequencer %s paused\n",
11337 p->flags, p->chip, p->features,
11338 (aic_inb(p, HCNTRL) & PAUSE) ? "is" : "isn't" );
11339 pause_sequencer(p);
11340 disable_irq(p->irq);
11341 aic7xxx_print_card(p);
11342 aic7xxx_print_scratch_ram(p);
11343 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,1,0)
11344 for(i=0; i<MAX_TARGETS; i++)
11346 if(p->dev_flags[i] & DEVICE_PRESENT)
11348 mask = (0x01 << i);
11349 printk(INFO_LEAD "dev_flags=0x%x, Pending:%c, PPR:%c/%c, WDTR:%c/%c, "
11350 "SDTR:%c/%c, q_depth=%d:%d\n",
11351 p->host_no, 0, i, 0, p->dev_flags[i],
11352 (p->dtr_pending & mask) ? 'Y' : 'N',
11353 (p->needppr & mask) ? 'Y' : 'N',
11354 (p->needppr_copy & mask) ? 'Y' : 'N',
11355 (p->needwdtr & mask) ? 'Y' : 'N',
11356 (p->needwdtr_copy & mask) ? 'Y' : 'N',
11357 (p->needsdtr & mask) ? 'Y' : 'N',
11358 (p->needsdtr_copy & mask) ? 'Y' : 'N',
11359 p->dev_active_cmds[i],
11360 p->dev_max_queue_depth[i] );
11361 printk(INFO_LEAD "targ_scsirate=0x%x", p->host_no, 0, i, 0,
11362 aic_inb(p, TARG_SCSIRATE + i));
11363 if (p->features & AHC_ULTRA2)
11364 printk(", targ_offset=%d", aic_inb(p, TARG_OFFSET + i));
11365 printk("\n");
11369 * Search for this command and see if we can't track it down, it's the
11370 * one causing the timeout. Print out this command first, then all other
11371 * active commands afterwords.
11373 need_tag = -1;
11374 if ( cmd )
11376 scb = p->scb_data->scb_array[aic7xxx_position(cmd)];
11377 if ( (scb->flags & SCB_ACTIVE) && (scb->cmd == cmd) )
11379 printk("Timed out command is scb #%d:\n", scb->hscb->tag);
11380 printk("Tag%d: flags=0x%x, control=0x%x, TCL=0x%x, %s\n", scb->hscb->tag,
11381 scb->flags, scb->hscb->control, scb->hscb->target_channel_lun,
11382 (scb->flags & SCB_WAITINGQ) ? "WAITINGQ" : "Sent" );
11383 need_tag = scb->hscb->tag;
11384 if (scb->flags & SCB_WAITINGQ) found=TRUE;
11387 printk("QINFIFO: (TAG) ");
11388 qinpos = aic_inb(p, QINPOS);
11389 while ( qinpos != p->qinfifonext )
11391 if (p->qinfifo[qinpos] == need_tag)
11392 found=TRUE;
11393 printk("%d ", p->qinfifo[qinpos++]);
11395 printk("\n");
11396 printk("Current SCB: (SCBPTR/TAG/CONTROL) %d/%d/0x%x\n", aic_inb(p, SCBPTR),
11397 aic_inb(p, SCB_TAG), aic_inb(p, SCB_CONTROL) );
11398 if (aic_inb(p, SCB_TAG) == need_tag) found=TRUE;
11399 printk("WAITING_SCBS: (SCBPTR/TAG/CONTROL) %d->",
11400 hscbp = aic_inb(p, WAITING_SCBH));
11401 while (hscbp != SCB_LIST_NULL)
11403 aic_outb(p, hscbp, SCBPTR);
11404 printk("%d/%d/0x%x ", hscbp, aic_inb(p, SCB_TAG), aic_inb(p, SCB_CONTROL));
11405 hscbp = aic_inb(p, SCB_NEXT);
11406 if (aic_inb(p, SCB_TAG) == need_tag) found=TRUE;
11408 printk("\n");
11409 printk("DISCONNECTED_SCBS: (SCBPTR/TAG/CONTROL) %d->",
11410 hscbp = aic_inb(p, DISCONNECTED_SCBH));
11411 while (hscbp != SCB_LIST_NULL)
11413 aic_outb(p, hscbp, SCBPTR);
11414 printk("%d/%d/0x%x ", hscbp, aic_inb(p, SCB_TAG), aic_inb(p, SCB_CONTROL));
11415 hscbp = aic_inb(p, SCB_NEXT);
11416 if (aic_inb(p, SCB_TAG) == need_tag) found=TRUE;
11418 printk("\n");
11419 printk("FREE_SCBS: (SCBPTR/TAG/CONTROL) %d->",
11420 hscbp = aic_inb(p, FREE_SCBH));
11421 while (hscbp != SCB_LIST_NULL)
11423 aic_outb(p, hscbp, SCBPTR);
11424 printk("%d/%d/0x%x ", hscbp, aic_inb(p, SCB_TAG), aic_inb(p, SCB_CONTROL));
11425 hscbp = aic_inb(p, SCB_NEXT);
11427 printk("\n");
11429 if (found == FALSE)
11432 * We haven't found the offending SCB yet, and it should be around
11433 * somewhere, so go look for it in the cards SCBs.
11435 printk("SCBPTR CONTROL TAG NEXT\n");
11436 for(i=0; i<p->scb_data->maxhscbs; i++)
11438 aic_outb(p, i, SCBPTR);
11439 printk(" %3d %02x %02x %02x\n", i,
11440 aic_inb(p, SCB_CONTROL), aic_inb(p, SCB_TAG),
11441 aic_inb(p, SCB_NEXT));
11446 for (i=0; i < p->scb_data->numscbs; i++)
11448 scb = p->scb_data->scb_array[i];
11449 if ( (scb->flags & SCB_ACTIVE) && (scb->cmd != cmd) )
11451 printk("Tag%d: flags=0x%x, control=0x%x, TCL=0x%x, %s\n", scb->hscb->tag,
11452 scb->flags, scb->hscb->control, scb->hscb->target_channel_lun,
11453 (scb->flags & SCB_WAITINGQ) ? "WAITINGQ" : "Sent" );
11456 #endif
11457 sti();
11458 for(;;) barrier();
11461 /*+F*************************************************************************
11462 * Function:
11463 * aic7xxx_abort
11465 * Description:
11466 * Abort the current SCSI command(s).
11467 *-F*************************************************************************/
11469 aic7xxx_abort(Scsi_Cmnd *cmd)
11471 struct aic7xxx_scb *scb = NULL;
11472 struct aic7xxx_host *p;
11473 int result, found=0;
11474 unsigned char tmp_char, saved_hscbptr, next_hscbptr, prev_hscbptr;
11475 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,1,95)
11476 unsigned long cpu_flags = 0;
11477 #endif
11478 Scsi_Cmnd *cmd_next, *cmd_prev;
11480 p = (struct aic7xxx_host *) cmd->host->hostdata;
11481 scb = (p->scb_data->scb_array[aic7xxx_position(cmd)]);
11484 * I added a new config option to the driver: "panic_on_abort" that will
11485 * cause the driver to panic and the machine to stop on the first abort
11486 * or reset call into the driver. At that point, it prints out a lot of
11487 * usefull information for me which I can then use to try and debug the
11488 * problem. Simply enable the boot time prompt in order to activate this
11489 * code.
11491 if (aic7xxx_panic_on_abort)
11492 aic7xxx_panic_abort(p, cmd);
11494 DRIVER_LOCK
11497 * Run the isr to grab any command in the QOUTFIFO and any other misc.
11498 * assundry tasks. This should also set up the bh handler if there is
11499 * anything to be done, but it won't run until we are done here since
11500 * we are following a straight code path without entering the scheduler
11501 * code.
11504 pause_sequencer(p);
11505 while ( (aic_inb(p, INTSTAT) & INT_PEND) && !(p->flags & AHC_IN_ISR))
11507 aic7xxx_isr(p->irq, p, (void *)NULL);
11508 pause_sequencer(p);
11509 aic7xxx_done_cmds_complete(p);
11512 if ((scb == NULL) || (cmd->serial_number != cmd->serial_number_at_timeout))
11513 /* Totally bogus cmd since it points beyond our */
11514 { /* valid SCB range or doesn't even match it's own*/
11515 /* timeout serial number. */
11516 if (aic7xxx_verbose & VERBOSE_ABORT_MID)
11517 printk(INFO_LEAD "Abort called with bogus Scsi_Cmnd "
11518 "pointer.\n", p->host_no, CTL_OF_CMD(cmd));
11519 unpause_sequencer(p, FALSE);
11520 DRIVER_UNLOCK
11521 return(SCSI_ABORT_NOT_RUNNING);
11523 if (scb->cmd != cmd) /* Hmmm...either this SCB is currently free with a */
11524 { /* NULL cmd pointer (NULLed out when freed) or it */
11525 /* has already been recycled for another command */
11526 /* Either way, this SCB has nothing to do with this*/
11527 /* command and we need to deal with cmd without */
11528 /* touching the SCB. */
11529 /* The theory here is to return a value that will */
11530 /* make the queued for complete command actually */
11531 /* finish successfully, or to indicate that we */
11532 /* don't have this cmd any more and the mid level */
11533 /* code needs to find it. */
11534 cmd_next = p->completeq.head;
11535 cmd_prev = NULL;
11536 while (cmd_next != NULL)
11538 if (cmd_next == cmd)
11540 if (aic7xxx_verbose & VERBOSE_ABORT_PROCESS)
11541 printk(INFO_LEAD "Abort called for command "
11542 "on completeq, completing.\n", p->host_no, CTL_OF_CMD(cmd));
11543 if ( cmd_prev == NULL )
11544 p->completeq.head = (Scsi_Cmnd *)cmd_next->host_scribble;
11545 else
11546 cmd_prev->host_scribble = cmd_next->host_scribble;
11547 cmd_next->scsi_done(cmd_next);
11548 unpause_sequencer(p, FALSE);
11549 DRIVER_UNLOCK
11550 return(SCSI_ABORT_NOT_RUNNING); /* It's already back as a successful
11551 * completion */
11553 cmd_prev = cmd_next;
11554 cmd_next = (Scsi_Cmnd *)cmd_next->host_scribble;
11556 if (aic7xxx_verbose & VERBOSE_ABORT_MID)
11557 printk(INFO_LEAD "Abort called for already completed"
11558 " command.\n", p->host_no, CTL_OF_CMD(cmd));
11559 unpause_sequencer(p, FALSE);
11560 DRIVER_UNLOCK
11561 return(SCSI_ABORT_NOT_RUNNING);
11564 /* At this point we know the following:
11565 * the SCB pointer is valid
11566 * the command pointer passed in to us and the scb->cmd pointer match
11567 * this then means that the command we need to abort is the same as the
11568 * command held by the scb pointer and is a valid abort request.
11569 * Now, we just have to figure out what to do from here. Current plan is:
11570 * if we have already been here on this command, escalate to a reset
11571 * if scb is on waiting list or QINFIFO, send it back as aborted, but
11572 * we also need to be aware of the possibility that we could be using
11573 * a faked negotiation command that is holding this command up, if
11574 * so we need to take care of that command instead, which means we
11575 * would then treat this one like it was sitting around disconnected
11576 * instead.
11577 * if scb is on WAITING_SCB list in sequencer, free scb and send back
11578 * if scb is disconnected and not completed, abort with abort message
11579 * if scb is currently running, then it may be causing the bus to hang
11580 * so we want a return value that indicates a reset would be appropriate
11581 * if the command does not finish shortly
11582 * if scb is already complete but not on completeq, we're screwed because
11583 * this can't happen (except if the command is in the QOUTFIFO, in which
11584 * case we would like it to complete successfully instead of having to
11585 * to be re-done)
11586 * All other scenarios already dealt with by previous code.
11589 if ( scb->flags & (SCB_ABORT | SCB_RESET | SCB_QUEUED_ABORT) )
11591 if (aic7xxx_verbose & VERBOSE_ABORT_PROCESS)
11592 printk(INFO_LEAD "SCB aborted once already, "
11593 "escalating.\n", p->host_no, CTL_OF_SCB(scb));
11594 unpause_sequencer(p, FALSE);
11595 DRIVER_UNLOCK
11596 return(SCSI_ABORT_SNOOZE);
11598 if ( (p->flags & (AHC_RESET_PENDING | AHC_ABORT_PENDING)) ||
11599 (p->dev_flags[TARGET_INDEX(scb->cmd)] &
11600 BUS_DEVICE_RESET_PENDING) )
11602 if (aic7xxx_verbose & VERBOSE_ABORT_PROCESS)
11603 printk(INFO_LEAD "Reset/Abort pending for this "
11604 "device, not wasting our time.\n", p->host_no, CTL_OF_SCB(scb));
11605 unpause_sequencer(p, FALSE);
11606 DRIVER_UNLOCK
11607 return(SCSI_ABORT_PENDING);
11610 found = 0;
11611 p->flags |= AHC_IN_ABORT;
11612 if (aic7xxx_verbose & VERBOSE_ABORT)
11613 printk(INFO_LEAD "Aborting scb %d, flags 0x%x\n",
11614 p->host_no, CTL_OF_SCB(scb), scb->hscb->tag, scb->flags);
11617 * First, let's check to see if the currently running command is our target
11618 * since if it is, the return is fairly easy and quick since we don't want
11619 * to touch the command in case it might complete, but we do want a timeout
11620 * in case it's actually hung, so we really do nothing, but tell the mid
11621 * level code to reset the timeout.
11624 if ( scb->hscb->tag == aic_inb(p, SCB_TAG) )
11627 * Check to see if the sequencer is just sitting on this command, or
11628 * if it's actively being run.
11630 result = aic_inb(p, LASTPHASE);
11631 switch (result)
11633 case P_DATAOUT: /* For any of these cases, we can assume we are */
11634 case P_DATAIN: /* an active command and act according. For */
11635 case P_COMMAND: /* anything else we are going to fall on through*/
11636 case P_STATUS: /* The SCSI_ABORT_SNOOZE will give us two abort */
11637 case P_MESGOUT: /* chances to finish and then escalate to a */
11638 case P_MESGIN: /* reset call */
11639 if (aic7xxx_verbose & VERBOSE_ABORT_PROCESS)
11640 printk(INFO_LEAD "SCB is currently active. "
11641 "Waiting on completion.\n", p->host_no, CTL_OF_SCB(scb));
11642 unpause_sequencer(p, FALSE);
11643 p->flags &= ~AHC_IN_ABORT;
11644 scb->flags |= SCB_RECOVERY_SCB; /* Note the fact that we've been */
11645 p->flags |= AHC_ABORT_PENDING; /* here so we will know not to */
11646 DRIVER_UNLOCK /* muck with other SCBs if this */
11647 return(SCSI_ABORT_PENDING); /* one doesn't complete and clear */
11648 break; /* out. */
11649 default:
11650 break;
11654 if ((found == 0) && (scb->flags & SCB_WAITINGQ))
11656 int tindex = TARGET_INDEX(cmd);
11657 unsigned short mask;
11659 mask = (1 << tindex);
11661 if (p->dtr_pending & mask)
11663 if (p->dev_dtr_cmnd[tindex]->next != cmd)
11664 found = 1;
11665 else
11666 found = 0;
11668 else
11670 found = 1;
11672 if (found == 0)
11675 * OK..this means the command we are currently getting an abort
11676 * for has an outstanding negotiation command in front of it.
11677 * We don't really have a way to tie back into the negotiation
11678 * commands, so we just send this back as pending, then it
11679 * will get reset in 2 seconds.
11681 unpause_sequencer(p, TRUE);
11682 scb->flags |= SCB_ABORT;
11683 DRIVER_UNLOCK
11684 return(SCSI_ABORT_PENDING);
11686 if (aic7xxx_verbose & VERBOSE_ABORT_PROCESS)
11687 printk(INFO_LEAD "SCB found on waiting list and "
11688 "aborted.\n", p->host_no, CTL_OF_SCB(scb));
11689 scbq_remove(&p->waiting_scbs, scb);
11690 scbq_remove(&p->delayed_scbs[tindex], scb);
11691 p->dev_active_cmds[tindex]++;
11692 p->activescbs++;
11693 scb->flags &= ~(SCB_WAITINGQ | SCB_ACTIVE);
11694 scb->flags |= SCB_ABORT | SCB_QUEUED_FOR_DONE;
11695 found = 1;
11699 * We just checked the waiting_q, now for the QINFIFO
11701 if ( found == 0 )
11703 if ( ((found = aic7xxx_search_qinfifo(p, cmd->target,
11704 cmd->channel,
11705 cmd->lun, scb->hscb->tag, SCB_ABORT | SCB_QUEUED_FOR_DONE,
11706 FALSE, NULL)) != 0) &&
11707 (aic7xxx_verbose & VERBOSE_ABORT_PROCESS))
11708 printk(INFO_LEAD "SCB found in QINFIFO and "
11709 "aborted.\n", p->host_no, CTL_OF_SCB(scb));
11713 * QINFIFO, waitingq, completeq done. Next, check WAITING_SCB list in card
11716 if ( found == 0 )
11718 unsigned char scb_next_ptr;
11719 prev_hscbptr = SCB_LIST_NULL;
11720 saved_hscbptr = aic_inb(p, SCBPTR);
11721 next_hscbptr = aic_inb(p, WAITING_SCBH);
11722 while ( next_hscbptr != SCB_LIST_NULL )
11724 aic_outb(p, next_hscbptr, SCBPTR );
11725 if ( scb->hscb->tag == aic_inb(p, SCB_TAG) )
11727 found = 1;
11728 if (aic7xxx_verbose & VERBOSE_ABORT_PROCESS)
11729 printk(INFO_LEAD "SCB found on hardware waiting"
11730 " list and aborted.\n", p->host_no, CTL_OF_SCB(scb));
11731 if ( prev_hscbptr == SCB_LIST_NULL )
11733 aic_outb(p, aic_inb(p, SCB_NEXT), WAITING_SCBH);
11734 /* stop the selection since we just
11735 * grabbed the scb out from under the
11736 * card
11738 aic_outb(p, aic_inb(p, SCSISEQ) & ~ENSELO, SCSISEQ);
11739 aic_outb(p, CLRSELTIMEO, CLRSINT1);
11741 else
11743 scb_next_ptr = aic_inb(p, SCB_NEXT);
11744 aic_outb(p, prev_hscbptr, SCBPTR);
11745 aic_outb(p, scb_next_ptr, SCB_NEXT);
11746 aic_outb(p, next_hscbptr, SCBPTR);
11748 aic_outb(p, SCB_LIST_NULL, SCB_TAG);
11749 aic_outb(p, 0, SCB_CONTROL);
11750 aic7xxx_add_curscb_to_free_list(p);
11751 scb->flags = SCB_ABORT | SCB_QUEUED_FOR_DONE;
11752 break;
11754 prev_hscbptr = next_hscbptr;
11755 next_hscbptr = aic_inb(p, SCB_NEXT);
11757 aic_outb(p, saved_hscbptr, SCBPTR );
11761 * Hmmm...completeq, QOUTFIFO, QINFIFO, WAITING_SCBH, waitingq all checked.
11762 * OK...the sequencer's paused, interrupts are off, and we haven't found the
11763 * command anyplace where it could be easily aborted. Time for the hard
11764 * work. We also know the command is valid. This essentially means the
11765 * command is disconnected, or connected but not into any phases yet, which
11766 * we know due to the tests we ran earlier on the current active scb phase.
11767 * At this point we can queue the abort tag and go on with life.
11770 if ( found == 0 )
11772 p->flags |= AHC_ABORT_PENDING;
11773 scb->flags |= SCB_QUEUED_ABORT | SCB_ABORT | SCB_RECOVERY_SCB;
11774 scb->hscb->control |= MK_MESSAGE;
11775 result=aic7xxx_find_scb(p, scb);
11776 if ( result != SCB_LIST_NULL )
11778 saved_hscbptr = aic_inb(p, SCBPTR);
11779 aic_outb(p, result, SCBPTR);
11780 tmp_char = aic_inb(p, SCB_CONTROL);
11781 aic_outb(p, tmp_char | MK_MESSAGE, SCB_CONTROL);
11782 aic_outb(p, saved_hscbptr, SCBPTR);
11784 if (aic7xxx_verbose & VERBOSE_ABORT_PROCESS)
11785 printk(INFO_LEAD "SCB disconnected. Queueing Abort"
11786 " SCB.\n", p->host_no, CTL_OF_SCB(scb));
11787 p->qinfifo[p->qinfifonext++] = scb->hscb->tag;
11788 if (p->features & AHC_QUEUE_REGS)
11789 aic_outb(p, p->qinfifonext, HNSCB_QOFF);
11790 else
11791 aic_outb(p, p->qinfifonext, KERNEL_QINPOS);
11793 if (found)
11795 aic7xxx_run_done_queue(p, TRUE);
11796 aic7xxx_run_waiting_queues(p);
11798 p->flags &= ~AHC_IN_ABORT;
11799 unpause_sequencer(p, FALSE);
11800 DRIVER_UNLOCK
11803 * On the return value. If we found the command and aborted it, then we know
11804 * it's already sent back and there is no reason for a further timeout, so
11805 * we use SCSI_ABORT_SUCCESS. On the queued abort side, we aren't so certain
11806 * there hasn't been a bus hang or something that might keep the abort from
11807 * from completing. Therefore, we use SCSI_ABORT_PENDING. The first time this
11808 * is passed back, the timeout on the command gets extended, the second time
11809 * we pass this back, the mid level SCSI code calls our reset function, which
11810 * would shake loose a hung bus.
11812 if ( found != 0 )
11813 return(SCSI_ABORT_SUCCESS);
11814 else
11815 return(SCSI_ABORT_PENDING);
11819 /*+F*************************************************************************
11820 * Function:
11821 * aic7xxx_reset
11823 * Description:
11824 * Resetting the bus always succeeds - is has to, otherwise the
11825 * kernel will panic! Try a surgical technique - sending a BUS
11826 * DEVICE RESET message - on the offending target before pulling
11827 * the SCSI bus reset line.
11828 *-F*************************************************************************/
11830 aic7xxx_reset(Scsi_Cmnd *cmd, unsigned int flags)
11832 struct aic7xxx_scb *scb = NULL;
11833 struct aic7xxx_host *p;
11834 int tindex;
11835 int result = -1;
11836 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,1,95)
11837 unsigned long cpu_flags = 0;
11838 #endif
11839 #define DEVICE_RESET 0x01
11840 #define BUS_RESET 0x02
11841 #define HOST_RESET 0x04
11842 #define FAIL 0x08
11843 #define RESET_DELAY 0x10
11844 int action;
11845 Scsi_Cmnd *cmd_prev, *cmd_next;
11848 if ( cmd == NULL )
11850 printk(KERN_WARNING "(scsi?:?:?:?) Reset called with NULL Scsi_Cmnd "
11851 "pointer, failing.\n");
11852 return(SCSI_RESET_SNOOZE);
11855 p = (struct aic7xxx_host *) cmd->host->hostdata;
11856 scb = (p->scb_data->scb_array[aic7xxx_position(cmd)]);
11857 tindex = TARGET_INDEX(cmd);
11860 * I added a new config option to the driver: "panic_on_abort" that will
11861 * cause the driver to panic and the machine to stop on the first abort
11862 * or reset call into the driver. At that point, it prints out a lot of
11863 * usefull information for me which I can then use to try and debug the
11864 * problem. Simply enable the boot time prompt in order to activate this
11865 * code.
11867 if (aic7xxx_panic_on_abort)
11868 aic7xxx_panic_abort(p, cmd);
11870 DRIVER_LOCK
11872 pause_sequencer(p);
11873 while ( (aic_inb(p, INTSTAT) & INT_PEND) && !(p->flags & AHC_IN_ISR))
11875 aic7xxx_isr(p->irq, p, (void *)NULL );
11876 pause_sequencer(p);
11877 aic7xxx_done_cmds_complete(p);
11880 if (scb == NULL)
11882 if (aic7xxx_verbose & VERBOSE_RESET_MID)
11883 printk(INFO_LEAD "Reset called with bogus Scsi_Cmnd"
11884 "->SCB mapping, improvising.\n", p->host_no, CTL_OF_CMD(cmd));
11885 if ( flags & SCSI_RESET_SUGGEST_HOST_RESET )
11887 action = HOST_RESET;
11889 else
11891 action = BUS_RESET;
11894 else if (scb->cmd != cmd)
11896 if (aic7xxx_verbose & VERBOSE_RESET_MID)
11897 printk(INFO_LEAD "Reset called with recycled SCB "
11898 "for cmd.\n", p->host_no, CTL_OF_CMD(cmd));
11899 cmd_prev = NULL;
11900 cmd_next = p->completeq.head;
11901 while ( cmd_next != NULL )
11903 if (cmd_next == cmd)
11905 if (aic7xxx_verbose & VERBOSE_RESET_RETURN)
11906 printk(INFO_LEAD "Reset, found cmd on completeq"
11907 ", completing.\n", p->host_no, CTL_OF_CMD(cmd));
11908 unpause_sequencer(p, FALSE);
11909 DRIVER_UNLOCK
11910 return(SCSI_RESET_NOT_RUNNING);
11912 cmd_prev = cmd_next;
11913 cmd_next = (Scsi_Cmnd *)cmd_next->host_scribble;
11915 if ( !(flags & SCSI_RESET_SYNCHRONOUS) )
11917 if (aic7xxx_verbose & VERBOSE_RESET_RETURN)
11918 printk(INFO_LEAD "Reset, cmd not found,"
11919 " failing.\n", p->host_no, CTL_OF_CMD(cmd));
11920 unpause_sequencer(p, FALSE);
11921 DRIVER_UNLOCK
11922 return(SCSI_RESET_NOT_RUNNING);
11924 else
11926 if (aic7xxx_verbose & VERBOSE_RESET_MID)
11927 printk(INFO_LEAD "Reset called, no scb, "
11928 "flags 0x%x\n", p->host_no, CTL_OF_CMD(cmd), flags);
11929 scb = NULL;
11930 action = HOST_RESET;
11933 else
11935 if (aic7xxx_verbose & VERBOSE_RESET_MID)
11936 printk(INFO_LEAD "Reset called, scb %d, flags "
11937 "0x%x\n", p->host_no, CTL_OF_SCB(scb), scb->hscb->tag, scb->flags);
11938 if ( aic7xxx_scb_on_qoutfifo(p, scb) )
11940 if(aic7xxx_verbose & VERBOSE_RESET_RETURN)
11941 printk(INFO_LEAD "SCB on qoutfifo, completing.\n", p->host_no,
11942 CTL_OF_SCB(scb));
11943 if ((aic_inb(p,INTSTAT) & CMDCMPLT) == 0)
11944 printk(INFO_LEAD "missed CMDCMPLT interrupt!\n", p->host_no,
11945 CTL_OF_SCB(scb));
11946 aic7xxx_handle_command_completion_intr(p);
11947 aic7xxx_done_cmds_complete(p);
11948 aic7xxx_run_waiting_queues(p);
11949 unpause_sequencer(p, FALSE);
11950 DRIVER_UNLOCK
11951 return(SCSI_RESET_SUCCESS);
11953 if ( flags & SCSI_RESET_SUGGEST_HOST_RESET )
11955 action = HOST_RESET;
11957 else if ( flags & SCSI_RESET_SUGGEST_BUS_RESET )
11959 action = BUS_RESET;
11961 else
11963 action = DEVICE_RESET;
11966 if ( (action & DEVICE_RESET) &&
11967 (p->dev_flags[tindex] & BUS_DEVICE_RESET_PENDING) )
11969 if (aic7xxx_verbose & VERBOSE_RESET_PROCESS)
11970 printk(INFO_LEAD "Bus device reset already sent to "
11971 "device, escalating.\n", p->host_no, CTL_OF_CMD(cmd));
11972 action = BUS_RESET;
11974 if ( (action & DEVICE_RESET) &&
11975 (scb->flags & SCB_QUEUED_ABORT) )
11977 if (aic7xxx_verbose & VERBOSE_RESET_PROCESS)
11979 printk(INFO_LEAD "Have already attempted to reach "
11980 "device with queued\n", p->host_no, CTL_OF_CMD(cmd));
11981 printk(INFO_LEAD "message, will escalate to bus "
11982 "reset.\n", p->host_no, CTL_OF_CMD(cmd));
11984 action = BUS_RESET;
11986 if ( (action & DEVICE_RESET) &&
11987 (p->flags & (AHC_RESET_PENDING | AHC_ABORT_PENDING)) )
11989 if (aic7xxx_verbose & VERBOSE_RESET_PROCESS)
11990 printk(INFO_LEAD "Bus device reset stupid when "
11991 "other action has failed.\n", p->host_no, CTL_OF_CMD(cmd));
11992 action = BUS_RESET;
11994 if ( (action & BUS_RESET) && !(p->features & AHC_TWIN) )
11996 action = HOST_RESET;
11998 if ( (p->dev_flags[tindex] & DEVICE_RESET_DELAY) &&
11999 !(action & (HOST_RESET | BUS_RESET)))
12001 if (aic7xxx_verbose & VERBOSE_RESET_PROCESS)
12003 printk(INFO_LEAD "Reset called too soon after last "
12004 "reset without requesting\n", p->host_no, CTL_OF_CMD(cmd));
12005 printk(INFO_LEAD "bus or host reset, escalating.\n", p->host_no,
12006 CTL_OF_CMD(cmd));
12008 action = BUS_RESET;
12010 if ( (p->flags & AHC_RESET_DELAY) &&
12011 (action & (HOST_RESET | BUS_RESET)) )
12013 if (aic7xxx_verbose & VERBOSE_RESET_PROCESS)
12014 printk(INFO_LEAD "Reset called too soon after "
12015 "last bus reset, delaying.\n", p->host_no, CTL_OF_CMD(cmd));
12016 action = RESET_DELAY;
12019 * By this point, we want to already know what we are going to do and
12020 * only have the following code implement our course of action.
12022 switch (action)
12024 case RESET_DELAY:
12025 unpause_sequencer(p, FALSE);
12026 DRIVER_UNLOCK
12027 return(SCSI_RESET_PENDING);
12028 break;
12029 case FAIL:
12030 unpause_sequencer(p, FALSE);
12031 DRIVER_UNLOCK
12032 return(SCSI_RESET_ERROR);
12033 break;
12034 case DEVICE_RESET:
12035 p->flags |= AHC_IN_RESET;
12036 result = aic7xxx_bus_device_reset(p, cmd);
12037 aic7xxx_run_done_queue(p, TRUE);
12038 /* We can't rely on run_waiting_queues to unpause the sequencer for
12039 * PCI based controllers since we use AAP */
12040 aic7xxx_run_waiting_queues(p);
12041 unpause_sequencer(p, FALSE);
12042 p->flags &= ~AHC_IN_RESET;
12043 DRIVER_UNLOCK
12044 return(result);
12045 break;
12046 case BUS_RESET:
12047 case HOST_RESET:
12048 default:
12049 p->flags |= AHC_IN_RESET | AHC_RESET_DELAY;
12050 p->dev_expires[p->scsi_id] = jiffies + (3 * HZ);
12051 p->dev_timer_active |= (0x01 << p->scsi_id);
12052 if ( !(p->dev_timer_active & (0x01 << MAX_TARGETS)) ||
12053 time_after_eq(p->dev_timer.expires, p->dev_expires[p->scsi_id]) )
12055 mod_timer(&p->dev_timer, p->dev_expires[p->scsi_id]);
12056 p->dev_timer_active |= (0x01 << MAX_TARGETS);
12058 aic7xxx_reset_channel(p, cmd->channel, TRUE);
12059 if ( (p->features & AHC_TWIN) && (action & HOST_RESET) )
12061 aic7xxx_reset_channel(p, cmd->channel ^ 0x01, TRUE);
12062 restart_sequencer(p);
12064 if (action != HOST_RESET)
12065 result = SCSI_RESET_SUCCESS | SCSI_RESET_BUS_RESET;
12066 else
12068 result = SCSI_RESET_SUCCESS | SCSI_RESET_HOST_RESET;
12069 aic_outb(p, aic_inb(p, SIMODE1) & ~(ENREQINIT|ENBUSFREE),
12070 SIMODE1);
12071 aic7xxx_clear_intstat(p);
12072 p->flags &= ~AHC_HANDLING_REQINITS;
12073 p->msg_type = MSG_TYPE_NONE;
12074 p->msg_index = 0;
12075 p->msg_len = 0;
12077 aic7xxx_run_done_queue(p, TRUE);
12079 * If this a SCSI_RESET_SYNCHRONOUS then the command we were given is
12080 * in need of being re-started, so send it on through to aic7xxx_queue
12081 * and let it set until the delay is over. This keeps it from dying
12082 * entirely and avoids getting a bogus dead command back through the
12083 * mid-level code due to too many retries.
12085 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,1,132)
12086 if ( flags & SCSI_RESET_SYNCHRONOUS )
12088 cmd->result = DID_BUS_BUSY << 16;
12089 cmd->done(cmd);
12091 #endif
12092 p->flags &= ~AHC_IN_RESET;
12094 * We can't rely on run_waiting_queues to unpause the sequencer for
12095 * PCI based controllers since we use AAP. NOTE: this also sets
12096 * the timer for the one command we might have queued in the case
12097 * of a synch reset.
12099 aic7xxx_run_waiting_queues(p);
12100 unpause_sequencer(p, FALSE);
12101 DRIVER_UNLOCK
12102 return(result);
12103 break;
12107 /*+F*************************************************************************
12108 * Function:
12109 * aic7xxx_biosparam
12111 * Description:
12112 * Return the disk geometry for the given SCSI device.
12113 *-F*************************************************************************/
12115 aic7xxx_biosparam(Disk *disk, kdev_t dev, int geom[])
12117 int heads, sectors, cylinders, ret;
12118 struct aic7xxx_host *p;
12119 struct buffer_head *bh;
12121 p = (struct aic7xxx_host *) disk->device->host->hostdata;
12122 bh = bread(MKDEV(MAJOR(dev), MINOR(dev)&~0xf), 0, 1024);
12124 if ( bh )
12126 ret = scsi_partsize(bh, disk->capacity, &geom[2], &geom[0], &geom[1]);
12127 brelse(bh);
12128 if ( ret != -1 )
12129 return(ret);
12132 heads = 64;
12133 sectors = 32;
12134 cylinders = disk->capacity / (heads * sectors);
12136 if ((p->flags & AHC_EXTEND_TRANS_A) && (cylinders > 1024))
12138 heads = 255;
12139 sectors = 63;
12140 cylinders = disk->capacity / (heads * sectors);
12143 geom[0] = heads;
12144 geom[1] = sectors;
12145 geom[2] = cylinders;
12147 return (0);
12150 /*+F*************************************************************************
12151 * Function:
12152 * aic7xxx_release
12154 * Description:
12155 * Free the passed in Scsi_Host memory structures prior to unloading the
12156 * module.
12157 *-F*************************************************************************/
12159 aic7xxx_release(struct Scsi_Host *host)
12161 struct aic7xxx_host *p = (struct aic7xxx_host *) host->hostdata;
12162 struct aic7xxx_host *next, *prev;
12164 if(p->irq)
12165 free_irq(p->irq, p);
12166 release_region(p->base, MAXREG - MINREG);
12167 #ifdef MMAPIO
12168 if(p->maddr)
12170 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,1,0)
12171 vfree((void *) (((unsigned long) p->maddr) & PAGE_MASK));
12172 #else
12173 iounmap((void *) (((unsigned long) p->maddr) & PAGE_MASK));
12174 #endif
12176 #endif /* MMAPIO */
12177 prev = NULL;
12178 next = first_aic7xxx;
12179 while(next != NULL)
12181 if(next == p)
12183 if(prev == NULL)
12184 first_aic7xxx = next->next;
12185 else
12186 prev->next = next->next;
12188 else
12190 prev = next;
12192 next = next->next;
12194 aic7xxx_free(p);
12195 return(0);
12198 /*+F*************************************************************************
12199 * Function:
12200 * aic7xxx_print_card
12202 * Description:
12203 * Print out all of the control registers on the card
12205 * NOTE: This function is not yet safe for use on the VLB and EISA
12206 * controllers, so it isn't used on those controllers at all.
12207 *-F*************************************************************************/
12208 static void
12209 aic7xxx_print_card(struct aic7xxx_host *p)
12211 int i, j, k, chip;
12212 static struct register_ranges {
12213 int num_ranges;
12214 int range_val[32];
12215 } cards_ds[] = {
12216 { 0, {0,} }, /* none */
12217 {10, {0x00, 0x05, 0x08, 0x11, 0x18, 0x19, 0x1f, 0x1f, 0x60, 0x60, /*7771*/
12218 0x62, 0x66, 0x80, 0x8e, 0x90, 0x95, 0x97, 0x97, 0x9b, 0x9f} },
12219 { 9, {0x00, 0x05, 0x08, 0x11, 0x18, 0x1f, 0x60, 0x60, 0x62, 0x66, /*7850*/
12220 0x80, 0x8e, 0x90, 0x95, 0x97, 0x97, 0x9a, 0x9f} },
12221 { 9, {0x00, 0x05, 0x08, 0x11, 0x18, 0x1f, 0x60, 0x60, 0x62, 0x66, /*7860*/
12222 0x80, 0x8e, 0x90, 0x95, 0x97, 0x97, 0x9a, 0x9f} },
12223 {10, {0x00, 0x05, 0x08, 0x11, 0x18, 0x19, 0x1c, 0x1f, 0x60, 0x60, /*7870*/
12224 0x62, 0x66, 0x80, 0x8e, 0x90, 0x95, 0x97, 0x97, 0x9a, 0x9f} },
12225 {10, {0x00, 0x05, 0x08, 0x11, 0x18, 0x1a, 0x1c, 0x1f, 0x60, 0x60, /*7880*/
12226 0x62, 0x66, 0x80, 0x8e, 0x90, 0x95, 0x97, 0x97, 0x9a, 0x9f} },
12227 {16, {0x00, 0x05, 0x08, 0x11, 0x18, 0x1f, 0x60, 0x60, 0x62, 0x66, /*7890*/
12228 0x84, 0x8e, 0x90, 0x95, 0x97, 0x97, 0x9a, 0x9a, 0x9f, 0x9f,
12229 0xe0, 0xf1, 0xf4, 0xf4, 0xf6, 0xf6, 0xf8, 0xf8, 0xfa, 0xfc,
12230 0xfe, 0xff} },
12231 {12, {0x00, 0x05, 0x08, 0x11, 0x18, 0x19, 0x1b, 0x1f, 0x60, 0x60, /*7895*/
12232 0x62, 0x66, 0x80, 0x8e, 0x90, 0x95, 0x97, 0x97, 0x9a, 0x9a,
12233 0x9f, 0x9f, 0xe0, 0xf1} },
12234 {16, {0x00, 0x05, 0x08, 0x11, 0x18, 0x1f, 0x60, 0x60, 0x62, 0x66, /*7896*/
12235 0x84, 0x8e, 0x90, 0x95, 0x97, 0x97, 0x9a, 0x9a, 0x9f, 0x9f,
12236 0xe0, 0xf1, 0xf4, 0xf4, 0xf6, 0xf6, 0xf8, 0xf8, 0xfa, 0xfc,
12237 0xfe, 0xff} },
12238 {12, {0x00, 0x05, 0x08, 0x11, 0x18, 0x1f, 0x60, 0x60, 0x62, 0x66, /*7892*/
12239 0x84, 0x8e, 0x90, 0x95, 0x97, 0x97, 0x9a, 0x9a, 0x9c, 0x9f,
12240 0xe0, 0xf1, 0xf4, 0xfc} },
12241 {12, {0x00, 0x05, 0x08, 0x11, 0x18, 0x1f, 0x60, 0x60, 0x62, 0x66, /*7899*/
12242 0x84, 0x8e, 0x90, 0x95, 0x97, 0x97, 0x9a, 0x9a, 0x9c, 0x9f,
12243 0xe0, 0xf1, 0xf4, 0xfc} },
12245 #ifdef CONFIG_PCI
12246 static struct register_ranges cards_ns[] = {
12247 { 0, {0,} }, /* none */
12248 { 0, {0,} }, /* 7771 */
12249 { 7, {0x04, 0x08, 0x0c, 0x0e, 0x10, 0x17, 0x28, 0x2b, 0x30, 0x33,
12250 0x3c, 0x41, 0x43, 0x47} },
12251 { 7, {0x04, 0x08, 0x0c, 0x0e, 0x10, 0x17, 0x28, 0x2b, 0x30, 0x33,
12252 0x3c, 0x41, 0x43, 0x47} },
12253 { 5, {0x04, 0x08, 0x0c, 0x0e, 0x10, 0x17, 0x30, 0x33, 0x3c, 0x41} },
12254 { 5, {0x04, 0x08, 0x0c, 0x0e, 0x10, 0x17, 0x30, 0x34, 0x3c, 0x47} },
12255 { 5, {0x04, 0x08, 0x0c, 0x1b, 0x30, 0x34, 0x3c, 0x43, 0xdc, 0xe3} },
12256 { 6, {0x04, 0x08, 0x0c, 0x0e, 0x10, 0x17, 0x30, 0x34, 0x3c, 0x47,
12257 0xdc, 0xe3} },
12258 { 6, {0x04, 0x08, 0x0c, 0x1b, 0x30, 0x34, 0x3c, 0x43, 0xdc, 0xe3,
12259 0xff, 0xff} },
12260 { 6, {0x04, 0x08, 0x0c, 0x1b, 0x30, 0x34, 0x3c, 0x43, 0xdc, 0xe3,
12261 0xff, 0xff} },
12262 { 6, {0x04, 0x08, 0x0c, 0x1b, 0x30, 0x34, 0x3c, 0x43, 0xdc, 0xe3,
12263 0xff, 0xff} }
12265 #endif
12266 chip = p->chip & AHC_CHIPID_MASK;
12268 * Let's run through the PCI space first....
12270 printk("%s at ",
12271 board_names[p->board_name_index]);
12272 switch(p->chip & ~AHC_CHIPID_MASK)
12274 case AHC_VL:
12275 printk("VLB Slot %d.\n", p->pci_device_fn);
12276 break;
12277 case AHC_EISA:
12278 printk("EISA Slot %d.\n", p->pci_device_fn);
12279 break;
12280 case AHC_PCI:
12281 default:
12282 printk("PCI %d/%d/%d.\n", p->pci_bus, PCI_SLOT(p->pci_device_fn),
12283 PCI_FUNC(p->pci_device_fn));
12284 break;
12287 #ifdef CONFIG_PCI
12289 unsigned char temp;
12291 printk("PCI Dump:\n");
12292 k=0;
12293 for(i=0; i<cards_ns[chip].num_ranges; i++)
12295 for(j = cards_ns[chip].range_val[ i * 2 ];
12296 j <= cards_ns[chip].range_val[ i * 2 + 1 ] ;
12297 j++)
12299 #if LINUX_VERSION_CODE > KERNEL_VERSION(2,1,92)
12300 pci_read_config_byte(p->pdev, j, &temp);
12301 #else
12302 pcibios_read_config_byte(p->pci_bus, p->pci_device_fn, j, &temp);
12303 #endif
12304 printk("%02x:%02x ", j, temp);
12305 if(++k == 13)
12307 printk("\n");
12308 k = 0;
12313 if(k != 0)
12314 printk("\n");
12315 #endif /* CONFIG_PCI */
12318 * Now the registers on the card....
12320 printk("Card Dump:\n");
12321 k = 0;
12322 for(i=0; i<cards_ds[chip].num_ranges; i++)
12324 for(j = cards_ds[chip].range_val[ i * 2 ];
12325 j <= cards_ds[chip].range_val[ i * 2 + 1 ] ;
12326 j++)
12328 printk("%02x:%02x ", j, aic_inb(p, j));
12329 if(++k == 13)
12331 printk("\n");
12332 k=0;
12336 if(k != 0)
12337 printk("\n");
12338 if (p->flags & AHC_SEEPROM_FOUND)
12340 unsigned short *sc1;
12341 sc1 = (unsigned short *)&p->sc;
12343 printk("SEEPROM dump.\n");
12344 for(i=1; i<=32; i++)
12346 printk("0x%04x", sc1[i-1]);
12347 if ( (i % 8) == 0 )
12348 printk("\n");
12349 else
12350 printk(" ");
12355 * If this was an Ultra2 controller, then we just hosed the card in terms
12356 * of the QUEUE REGS. This function is only called at init time or by
12357 * the panic_abort function, so it's safe to assume a generic init time
12358 * setting here
12361 if(p->features & AHC_QUEUE_REGS)
12363 aic_outb(p, 0, SDSCB_QOFF);
12364 aic_outb(p, 0, SNSCB_QOFF);
12365 aic_outb(p, 0, HNSCB_QOFF);
12370 /*+F*************************************************************************
12371 * Function:
12372 * aic7xxx_print_scratch_ram
12374 * Description:
12375 * Print out the scratch RAM values on the card.
12376 *-F*************************************************************************/
12377 static void
12378 aic7xxx_print_scratch_ram(struct aic7xxx_host *p)
12380 int i, k;
12382 k = 0;
12383 printk("Scratch RAM:\n");
12384 for(i = SRAM_BASE; i < SEQCTL; i++)
12386 printk("%02x:%02x ", i, aic_inb(p, i));
12387 if(++k == 13)
12389 printk("\n");
12390 k=0;
12393 if (p->features & AHC_MORE_SRAM)
12395 for(i = TARG_OFFSET; i < 0x80; i++)
12397 printk("%02x:%02x ", i, aic_inb(p, i));
12398 if(++k == 13)
12400 printk("\n");
12401 k=0;
12405 printk("\n");
12409 #include "aic7xxx_proc.c"
12411 #ifdef MODULE
12412 /* Eventually this will go into an include file, but this will be later */
12413 Scsi_Host_Template driver_template = AIC7XXX;
12415 #include "scsi_module.c"
12416 #endif
12419 * Overrides for Emacs so that we almost follow Linus's tabbing style.
12420 * Emacs will notice this stuff at the end of the file and automatically
12421 * adjust the settings for this buffer only. This must remain at the end
12422 * of the file.
12423 * ---------------------------------------------------------------------------
12424 * Local variables:
12425 * c-indent-level: 2
12426 * c-brace-imaginary-offset: 0
12427 * c-brace-offset: -2
12428 * c-argdecl-indent: 2
12429 * c-label-offset: -2
12430 * c-continued-statement-offset: 2
12431 * c-continued-brace-offset: 0
12432 * indent-tabs-mode: nil
12433 * tab-width: 8
12434 * End: