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)
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
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
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
91 * aic7xxx=irq_trigger:[0,1] # 0 edge, 1 level
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.
189 * OK...I need this on my machine for testing, so the default is to
193 * I needed it for testing, but it didn't make any difference, so back
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
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>
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>
250 #include "aic7xxx/sequencer.h"
251 #include "aic7xxx/scsi_message.h"
252 #include "aic7xxx_reg.h"
253 #include <scsi/scsicam.h>
255 #include <linux/stat.h>
256 #include <linux/malloc.h> /* for kmalloc() */
258 #include <linux/config.h> /* for CONFIG_PCI */
261 * To generate the correct addresses for the controller to issue
262 * on the bus. Originally added for DEC Alpha support.
264 #define VIRT_TO_BUS(a) (unsigned int)virt_to_bus((void *)(a))
266 struct proc_dir_entry proc_scsi_aic7xxx
= {
267 PROC_SCSI_AIC7XXX
, 7, "aic7xxx",
268 S_IFDIR
| S_IRUGO
| S_IXUGO
, 2,
269 0, 0, 0, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
272 #define AIC7XXX_C_VERSION "5.1.19"
274 #define NUMBER(arr) (sizeof(arr) / sizeof(arr[0]))
275 #define MIN(a,b) (((a) < (b)) ? (a) : (b))
276 #define MAX(a,b) (((a) > (b)) ? (a) : (b))
277 #define ALL_TARGETS -1
278 #define ALL_CHANNELS -1
280 #define MAX_TARGETS 16
289 #ifndef KERNEL_VERSION
290 # define KERNEL_VERSION(x,y,z) (((x)<<16)+((y)<<8)+(z))
294 * We need the bios32.h file if we are kernel version 2.1.92 or less. The
295 * full set of pci_* changes wasn't in place until 2.1.93
298 #if LINUX_VERSION_CODE <= KERNEL_VERSION(2,1,92)
299 # if defined(__sparc_v9__) || defined(__powerpc__)
300 # error "PPC and Sparc platforms are only support under 2.1.92 and above"
302 # include <linux/bios32.h>
305 #if defined(__powerpc__)
311 __asm__ __volatile__("eieio" ::: "memory")
312 #elif defined(__i386__)
318 __asm__ __volatile__("lock ; addl $0,0(%%esp)": : :"memory")
319 #elif defined(__alpha__)
324 __asm__ __volatile__("mb": : :"memory")
327 #if LINUX_VERSION_CODE > KERNEL_VERSION(2,1,0)
328 # include <linux/spinlock.h>
329 # include <linux/smp.h>
330 # define cpuid smp_processor_id()
331 # if LINUX_VERSION_CODE < KERNEL_VERSION(2,1,95)
332 # define DRIVER_LOCK_INIT \
333 spin_lock_init(&p->spin_lock);
334 # define DRIVER_LOCK \
335 if(!p->cpu_lock_count[cpuid]) { \
336 spin_lock_irqsave(&p->spin_lock, cpu_flags); \
337 p->cpu_lock_count[cpuid]++; \
339 p->cpu_lock_count[cpuid]++; \
341 # define DRIVER_UNLOCK \
342 if(--p->cpu_lock_count[cpuid] == 0) \
343 spin_unlock_irqrestore(&p->spin_lock, cpu_flags);
345 # define DRIVER_LOCK_INIT
347 # define DRIVER_UNLOCK
351 # define DRIVER_LOCK_INIT
352 # define DRIVER_LOCK \
353 save_flags(cpu_flags); \
355 # define DRIVER_UNLOCK \
356 restore_flags(cpu_flags);
357 # define le32_to_cpu(x) (x)
358 # define cpu_to_le32(x) (x)
362 * You can try raising me if tagged queueing is enabled, or lowering
363 * me if you only have 4 SCBs.
365 #ifdef CONFIG_AIC7XXX_CMDS_PER_DEVICE
366 #define AIC7XXX_CMDS_PER_DEVICE CONFIG_AIC7XXX_CMDS_PER_DEVICE
368 #define AIC7XXX_CMDS_PER_DEVICE 8
371 /* Set this to the delay in seconds after SCSI bus reset. */
372 #ifdef CONFIG_AIC7XXX_RESET_DELAY
373 #define AIC7XXX_RESET_DELAY CONFIG_AIC7XXX_RESET_DELAY
375 #define AIC7XXX_RESET_DELAY 5
379 * Control collection of SCSI transfer statistics for the /proc filesystem.
381 * NOTE: Do NOT enable this when running on kernels version 1.2.x and below.
382 * NOTE: This does affect performance since it has to maintain statistics.
384 #ifdef CONFIG_AIC7XXX_PROC_STATS
385 #define AIC7XXX_PROC_STATS
389 * NOTE: Uncommenting the define below no longer has any effect, the
390 * tagged queue value array is always active now. I've added
391 * a setup option to set this particular array and I'm hoping
392 * insmod will be smart enough to set it properly as well. It's
393 * by use of this array that a person can enable tagged queueing.
394 * The DEFAULT_TAG_COMMANDS define has been changed to disable
395 * tagged queueing by default, so if your devices can handle tagged
396 * queueing you will need to add a line to their lilo.conf file like:
397 * append="aic7xxx=verbose,tag_info:{{32,32,32,32},{32,32,32,32}}"
398 * which will result in the first four devices on the first two
399 * controllers being set to a tagged queue depth of 32.
401 * Set this for defining the number of tagged commands on a device
402 * by device, and controller by controller basis. The first set
403 * of tagged commands will be used for the first detected aic7xxx
404 * controller, the second set will be used for the second detected
405 * aic7xxx controller, and so on. These values will *only* be used
406 * for targets that are tagged queueing capable; these values will
407 * be ignored in all other cases. The tag_commands is an array of
408 * 16 to allow for wide and twin adapters. Twin adapters will use
409 * indexes 0-7 for channel 0, and indexes 8-15 for channel 1.
411 * *** Determining commands per LUN ***
413 * When AIC7XXX_CMDS_PER_DEVICE is not defined, the driver will use its
414 * own algorithm to determine the commands/LUN. If SCB paging is
415 * enabled, which is always now, the default is 8 commands per lun
416 * that indicates it supports tagged queueing. All non-tagged devices
417 * use an internal queue depth of 3, with no more than one of those
418 * three commands active at one time.
420 /* #define AIC7XXX_TAGGED_QUEUEING_BY_DEVICE */
424 unsigned char tag_commands
[16]; /* Allow for wide/twin adapters. */
425 } adapter_tag_info_t
;
428 * Make a define that will tell the driver not to use tagged queueing
431 #ifdef CONFIG_AIC7XXX_TCQ_ON_BY_DEFAULT
432 #define DEFAULT_TAG_COMMANDS {0, 0, 0, 0, 0, 0, 0, 0,\
433 0, 0, 0, 0, 0, 0, 0, 0}
435 #define DEFAULT_TAG_COMMANDS {255, 255, 255, 255, 255, 255, 255, 255,\
436 255, 255, 255, 255, 255, 255, 255, 255}
440 * Modify this as you see fit for your system. By setting tag_commands
441 * to 0, the driver will use it's own algorithm for determining the
442 * number of commands to use (see above). When 255, the driver will
443 * not enable tagged queueing for that particular device. When positive
444 * (> 0) and (< 255) the values in the array are used for the queue_depth.
445 * Note that the maximum value for an entry is 254, but you're insane if
446 * you try to use that many commands on one device.
448 * In this example, the first line will disable tagged queueing for all
449 * the devices on the first probed aic7xxx adapter.
451 * The second line enables tagged queueing with 4 commands/LUN for IDs
452 * (1, 2-11, 13-15), disables tagged queueing for ID 12, and tells the
453 * driver to use its own algorithm for ID 1.
455 * The third line is the same as the first line.
457 * The fourth line disables tagged queueing for devices 0 and 3. It
458 * enables tagged queueing for the other IDs, with 16 commands/LUN
459 * for IDs 1 and 4, 127 commands/LUN for ID 8, and 4 commands/LUN for
460 * IDs 2, 5-7, and 9-15.
464 * NOTE: The below structure is for reference only, the actual structure
465 * to modify in order to change things is located around line
467 adapter_tag_info_t aic7xxx_tag_info[] =
469 {DEFAULT_TAG_COMMANDS},
470 {{4, 0, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 255, 4, 4, 4}},
471 {DEFAULT_TAG_COMMANDS},
472 {{255, 16, 4, 255, 16, 4, 4, 4, 127, 4, 4, 4, 4, 4, 4, 4}}
476 static adapter_tag_info_t aic7xxx_tag_info
[] =
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
},
485 {DEFAULT_TAG_COMMANDS
},
486 {DEFAULT_TAG_COMMANDS
},
487 {DEFAULT_TAG_COMMANDS
},
488 {DEFAULT_TAG_COMMANDS
},
489 {DEFAULT_TAG_COMMANDS
},
490 {DEFAULT_TAG_COMMANDS
},
491 {DEFAULT_TAG_COMMANDS
},
492 {DEFAULT_TAG_COMMANDS
},
493 {DEFAULT_TAG_COMMANDS
}
498 * Define an array of board names that can be indexed by aha_type.
499 * Don't forget to change this when changing the types!
501 static const char *board_names
[] = {
502 "AIC-7xxx Unknown", /* AIC_NONE */
503 "Adaptec AIC-7810 Hardware RAID Controller", /* AIC_7810 */
504 "Adaptec AIC-7770 SCSI host adapter", /* AIC_7770 */
505 "Adaptec AHA-274X SCSI host adapter", /* AIC_7771 */
506 "Adaptec AHA-284X SCSI host adapter", /* AIC_284x */
507 "Adaptec AIC-7850 SCSI host adapter", /* AIC_7850 */
508 "Adaptec AIC-7855 SCSI host adapter", /* AIC_7855 */
509 "Adaptec AIC-7860 Ultra SCSI host adapter", /* AIC_7860 */
510 "Adaptec AHA-2940A Ultra SCSI host adapter", /* AIC_7861 */
511 "Adaptec AIC-7870 SCSI host adapter", /* AIC_7870 */
512 "Adaptec AHA-294X SCSI host adapter", /* AIC_7871 */
513 "Adaptec AHA-394X SCSI host adapter", /* AIC_7872 */
514 "Adaptec AHA-398X SCSI host adapter", /* AIC_7873 */
515 "Adaptec AHA-2944 SCSI host adapter", /* AIC_7874 */
516 "Adaptec AIC-7880 Ultra SCSI host adapter", /* AIC_7880 */
517 "Adaptec AHA-294X Ultra SCSI host adapter", /* AIC_7881 */
518 "Adaptec AHA-394X Ultra SCSI host adapter", /* AIC_7882 */
519 "Adaptec AHA-398X Ultra SCSI host adapter", /* AIC_7883 */
520 "Adaptec AHA-2944 Ultra SCSI host adapter", /* AIC_7884 */
521 "Adaptec AIC-7895 Ultra SCSI host adapter", /* AIC_7895 */
522 "Adaptec AIC-7890/1 Ultra2 SCSI host adapter", /* AIC_7890 */
523 "Adaptec AHA-293X Ultra2 SCSI host adapter", /* AIC_7890 */
524 "Adaptec AHA-294X Ultra2 SCSI host adapter", /* AIC_7890 */
525 "Adaptec AIC-7896/7 Ultra2 SCSI host adapter", /* AIC_7896 */
526 "Adaptec AHA-394X Ultra2 SCSI host adapter", /* AIC_7897 */
527 "Adaptec AHA-395X Ultra2 SCSI host adapter", /* AIC_7897 */
528 "Adaptec PCMCIA SCSI controller", /* card bus stuff */
529 "Adaptec AIC-7892 Ultra 160/m SCSI host adapter", /* AIC_7892 */
530 "Adaptec AIC-7899 Ultra 160/m SCSI host adapter", /* AIC_7899 */
534 * There should be a specific return value for this in scsi.h, but
535 * it seems that most drivers ignore it.
537 #define DID_UNDERFLOW DID_ERROR
540 * What we want to do is have the higher level scsi driver requeue
541 * the command to us. There is no specific driver status for this
542 * condition, but the higher level scsi driver will requeue the
543 * command on a DID_BUS_BUSY error.
545 * Upon further inspection and testing, it seems that DID_BUS_BUSY
546 * will *always* retry the command. We can get into an infinite loop
547 * if this happens when we really want some sort of counter that
548 * will automatically abort/reset the command after so many retries.
549 * Using DID_ERROR will do just that. (Made by a suggestion by
550 * Doug Ledford 8/1/96)
552 #define DID_RETRY_COMMAND DID_ERROR
555 #define SCSI_RESET 0x040
562 #define SLOTBASE(x) ((x) << 12)
563 #define BASE_TO_SLOT(x) ((x) >> 12)
566 * Standard EISA Host ID regs (Offset from slot base)
568 #define AHC_HID0 0x80 /* 0,1: msb of ID2, 2-7: ID1 */
569 #define AHC_HID1 0x81 /* 0-4: ID3, 5-7: LSB ID2 */
570 #define AHC_HID2 0x82 /* product */
571 #define AHC_HID3 0x83 /* firmware revision */
574 * AIC-7770 I/O range to reserve for a card
579 #define INTDEF 0x5C /* Interrupt Definition Register */
582 * AIC-78X0 PCI registers
584 #define CLASS_PROGIF_REVID 0x08
585 #define DEVREVID 0x000000FFul
586 #define PROGINFC 0x0000FF00ul
587 #define SUBCLASS 0x00FF0000ul
588 #define BASECLASS 0xFF000000ul
590 #define CSIZE_LATTIME 0x0C
591 #define CACHESIZE 0x0000003Ful /* only 5 bits */
592 #define LATTIME 0x0000FF00ul
594 #define DEVCONFIG 0x40
595 #define SCBSIZE32 0x00010000ul /* aic789X only */
596 #define MPORTMODE 0x00000400ul /* aic7870 only */
597 #define RAMPSM 0x00000200ul /* aic7870 only */
598 #define RAMPSM_ULTRA2 0x00000004
599 #define VOLSENSE 0x00000100ul
600 #define SCBRAMSEL 0x00000080ul
601 #define SCBRAMSEL_ULTRA2 0x00000008
602 #define MRDCEN 0x00000040ul
603 #define EXTSCBTIME 0x00000020ul /* aic7870 only */
604 #define EXTSCBPEN 0x00000010ul /* aic7870 only */
605 #define BERREN 0x00000008ul
606 #define DACEN 0x00000004ul
607 #define STPWLEVEL 0x00000002ul
608 #define DIFACTNEGEN 0x00000001ul /* aic7870 only */
610 #define SCAMCTL 0x1a /* Ultra2 only */
611 #define CCSCBBADDR 0xf0 /* aic7895/6/7 */
614 * Define the different types of SEEPROMs on aic7xxx adapters
615 * and make it also represent the address size used in accessing
616 * its registers. The 93C46 chips have 1024 bits organized into
617 * 64 16-bit words, while the 93C56 chips have 2048 bits organized
618 * into 128 16-bit words. The C46 chips use 6 bits to address
619 * each word, while the C56 and C66 (4096 bits) use 8 bits to
622 typedef enum {C46
= 6, C56_66
= 8} seeprom_chip_type
;
626 * Define the format of the SEEPROM registers (16 bits).
629 struct seeprom_config
{
632 * SCSI ID Configuration Flags
634 #define CFXFER 0x0007 /* synchronous transfer rate */
635 #define CFSYNCH 0x0008 /* enable synchronous transfer */
636 #define CFDISC 0x0010 /* enable disconnection */
637 #define CFWIDEB 0x0020 /* wide bus device (wide card) */
638 #define CFSYNCHISULTRA 0x0040 /* CFSYNC is an ultra offset */
639 #define CFNEWULTRAFORMAT 0x0080 /* Use the Ultra2 SEEPROM format */
640 #define CFSTART 0x0100 /* send start unit SCSI command */
641 #define CFINCBIOS 0x0200 /* include in BIOS scan */
642 #define CFRNFOUND 0x0400 /* report even if not found */
643 #define CFMULTILUN 0x0800 /* probe mult luns in BIOS scan */
644 #define CFWBCACHEYES 0x4000 /* Enable W-Behind Cache on drive */
645 #define CFWBCACHENC 0xc000 /* Don't change W-Behind Cache */
647 unsigned short device_flags
[16]; /* words 0-15 */
652 #define CFSUPREM 0x0001 /* support all removable drives */
653 #define CFSUPREMB 0x0002 /* support removable drives for boot only */
654 #define CFBIOSEN 0x0004 /* BIOS enabled */
656 #define CFSM2DRV 0x0010 /* support more than two drives */
657 #define CF284XEXTEND 0x0020 /* extended translation (284x cards) */
659 #define CFEXTEND 0x0080 /* extended translation enabled */
661 unsigned short bios_control
; /* word 16 */
664 * Host Adapter Control Bits
666 #define CFAUTOTERM 0x0001 /* Perform Auto termination */
667 #define CFULTRAEN 0x0002 /* Ultra SCSI speed enable (Ultra cards) */
668 #define CF284XSELTO 0x0003 /* Selection timeout (284x cards) */
669 #define CF284XFIFO 0x000C /* FIFO Threshold (284x cards) */
670 #define CFSTERM 0x0004 /* SCSI low byte termination */
671 #define CFWSTERM 0x0008 /* SCSI high byte termination (wide card) */
672 #define CFSPARITY 0x0010 /* SCSI parity */
673 #define CF284XSTERM 0x0020 /* SCSI low byte termination (284x cards) */
674 #define CFRESETB 0x0040 /* reset SCSI bus at boot */
675 #define CFBPRIMARY 0x0100 /* Channel B primary on 7895 chipsets */
676 #define CFSEAUTOTERM 0x0400 /* aic7890 Perform SE Auto Term */
677 #define CFLVDSTERM 0x0800 /* aic7890 LVD Termination */
679 unsigned short adapter_control
; /* word 17 */
682 * Bus Release, Host Adapter ID
684 #define CFSCSIID 0x000F /* host adapter SCSI ID */
686 #define CFBRTIME 0xFF00 /* bus release time */
687 unsigned short brtime_id
; /* word 18 */
692 #define CFMAXTARG 0x00FF /* maximum targets */
694 unsigned short max_targets
; /* word 19 */
696 unsigned short res_1
[11]; /* words 20-30 */
697 unsigned short checksum
; /* word 31 */
700 #define SELBUS_MASK 0x0a
701 #define SELNARROW 0x00
703 #define SINGLE_BUS 0x00
705 #define SCB_TARGET(scb) \
706 (((scb)->hscb->target_channel_lun & TID) >> 4)
707 #define SCB_LUN(scb) \
708 ((scb)->hscb->target_channel_lun & LID)
709 #define SCB_IS_SCSIBUS_B(scb) \
710 (((scb)->hscb->target_channel_lun & SELBUSB) != 0)
713 * If an error occurs during a data transfer phase, run the command
714 * to completion - it's easier that way - making a note of the error
715 * condition in this location. This then will modify a DID_OK status
716 * into an appropriate error for the higher-level SCSI code.
718 #define aic7xxx_error(cmd) ((cmd)->SCp.Status)
721 * Keep track of the targets returned status.
723 #define aic7xxx_status(cmd) ((cmd)->SCp.sent_command)
726 * The position of the SCSI commands scb within the scb array.
728 #define aic7xxx_position(cmd) ((cmd)->SCp.have_data_in)
731 * So we can keep track of our host structs
733 static struct aic7xxx_host
*first_aic7xxx
= NULL
;
736 * As of Linux 2.1, the mid-level SCSI code uses virtual addresses
737 * in the scatter-gather lists. We need to convert the virtual
738 * addresses to physical addresses.
740 struct hw_scatterlist
{
741 unsigned int address
;
746 * Maximum number of SG segments these cards can support.
748 #define AIC7XXX_MAX_SG 128
751 * The maximum number of SCBs we could have for ANY type
752 * of card. DON'T FORGET TO CHANGE THE SCB MASK IN THE
753 * SEQUENCER CODE IF THIS IS MODIFIED!
755 #define AIC7XXX_MAXSCB 255
758 struct aic7xxx_hwscb
{
759 /* ------------ Begin hardware supported fields ---------------- */
760 /* 0*/ unsigned char control
;
761 /* 1*/ unsigned char target_channel_lun
; /* 4/1/3 bits */
762 /* 2*/ unsigned char target_status
;
763 /* 3*/ unsigned char SG_segment_count
;
764 /* 4*/ unsigned int SG_list_pointer
;
765 /* 8*/ unsigned char residual_SG_segment_count
;
766 /* 9*/ unsigned char residual_data_count
[3];
767 /*12*/ unsigned int data_pointer
;
768 /*16*/ unsigned int data_count
;
769 /*20*/ unsigned int SCSI_cmd_pointer
;
770 /*24*/ unsigned char SCSI_cmd_length
;
771 /*25*/ unsigned char tag
; /* Index into our kernel SCB array.
772 * Also used as the tag for tagged I/O
774 #define SCB_PIO_TRANSFER_SIZE 26 /* amount we need to upload/download
775 * via PIO to initialize a transaction.
777 /*26*/ unsigned char next
; /* Used to thread SCBs awaiting selection
778 * or disconnected down in the sequencer.
780 /*27*/ unsigned char prev
;
781 /*28*/ unsigned int pad
; /*
782 * Unused by the kernel, but we require
783 * the padding so that the array of
784 * hardware SCBs is alligned on 32 byte
785 * boundaries so the sequencer can index
791 SCB_WAITINGQ
= 0x0002,
795 SCB_DEVICE_RESET
= 0x0020,
797 SCB_RECOVERY_SCB
= 0x0080,
798 SCB_MSGOUT_PPR
= 0x0100,
799 SCB_MSGOUT_SENT
= 0x0200,
800 SCB_MSGOUT_SDTR
= 0x0400,
801 SCB_MSGOUT_WDTR
= 0x0800,
802 SCB_MSGOUT_BITS
= SCB_MSGOUT_PPR
|
806 SCB_QUEUED_ABORT
= 0x1000,
807 SCB_QUEUED_FOR_DONE
= 0x2000,
808 SCB_WAS_BUSY
= 0x4000
812 AHC_FNONE
= 0x00000000,
813 AHC_PAGESCBS
= 0x00000001,
814 AHC_CHANNEL_B_PRIMARY
= 0x00000002,
815 AHC_USEDEFAULTS
= 0x00000004,
816 AHC_INDIRECT_PAGING
= 0x00000008,
817 AHC_CHNLB
= 0x00000020,
818 AHC_CHNLC
= 0x00000040,
819 AHC_EXTEND_TRANS_A
= 0x00000100,
820 AHC_EXTEND_TRANS_B
= 0x00000200,
821 AHC_TERM_ENB_A
= 0x00000400,
822 AHC_TERM_ENB_SE_LOW
= 0x00000400,
823 AHC_TERM_ENB_B
= 0x00000800,
824 AHC_TERM_ENB_SE_HIGH
= 0x00000800,
825 AHC_HANDLING_REQINITS
= 0x00001000,
826 AHC_TARGETMODE
= 0x00002000,
827 AHC_NEWEEPROM_FMT
= 0x00004000,
829 * Here ends the FreeBSD defined flags and here begins the linux defined
830 * flags. NOTE: I did not preserve the old flag name during this change
831 * specifically to force me to evaluate what flags were being used properly
832 * and what flags weren't. This way, I could clean up the flag usage on
833 * a use by use basis. Doug Ledford
835 AHC_RESET_DELAY
= 0x00080000,
836 AHC_A_SCANNED
= 0x00100000,
837 AHC_B_SCANNED
= 0x00200000,
838 AHC_MULTI_CHANNEL
= 0x00400000,
839 AHC_BIOS_ENABLED
= 0x00800000,
840 AHC_SEEPROM_FOUND
= 0x01000000,
841 AHC_TERM_ENB_LVD
= 0x02000000,
842 AHC_ABORT_PENDING
= 0x04000000,
843 AHC_RESET_PENDING
= 0x08000000,
844 #define AHC_IN_ISR_BIT 28
845 AHC_IN_ISR
= 0x10000000,
846 AHC_IN_ABORT
= 0x20000000,
847 AHC_IN_RESET
= 0x40000000,
848 AHC_EXTERNAL_SRAM
= 0x80000000
853 AHC_CHIPID_MASK
= 0x00ff,
854 AHC_AIC7770
= 0x0001,
855 AHC_AIC7850
= 0x0002,
856 AHC_AIC7860
= 0x0003,
857 AHC_AIC7870
= 0x0004,
858 AHC_AIC7880
= 0x0005,
859 AHC_AIC7890
= 0x0006,
860 AHC_AIC7895
= 0x0007,
861 AHC_AIC7896
= 0x0008,
862 AHC_AIC7892
= 0x0009,
863 AHC_AIC7899
= 0x000a,
875 AHC_MORE_SRAM
= 0x0010,
876 AHC_CMD_CHAN
= 0x0020,
877 AHC_QUEUE_REGS
= 0x0040,
878 AHC_SG_PRELOAD
= 0x0080,
879 AHC_SPIOCAP
= 0x0100,
881 AHC_AIC7770_FE
= AHC_FENONE
,
882 AHC_AIC7850_FE
= AHC_SPIOCAP
,
883 AHC_AIC7860_FE
= AHC_ULTRA
|AHC_SPIOCAP
,
884 AHC_AIC7870_FE
= AHC_FENONE
,
885 AHC_AIC7880_FE
= AHC_ULTRA
,
886 AHC_AIC7890_FE
= AHC_MORE_SRAM
|AHC_CMD_CHAN
|AHC_ULTRA2
|
887 AHC_QUEUE_REGS
|AHC_SG_PRELOAD
,
888 AHC_AIC7895_FE
= AHC_MORE_SRAM
|AHC_CMD_CHAN
|AHC_ULTRA
,
889 AHC_AIC7896_FE
= AHC_AIC7890_FE
,
890 AHC_AIC7892_FE
= AHC_AIC7890_FE
|AHC_ULTRA3
,
891 AHC_AIC7899_FE
= AHC_AIC7890_FE
|AHC_ULTRA3
,
895 struct aic7xxx_hwscb
*hscb
; /* corresponding hardware scb */
896 Scsi_Cmnd
*cmd
; /* Scsi_Cmnd for this scb */
897 struct aic7xxx_scb
*q_next
; /* next scb in queue */
898 volatile scb_flag_type flags
; /* current state of scb */
899 struct hw_scatterlist
*sg_list
; /* SG list in adapter format */
900 unsigned char tag_action
;
901 unsigned char sg_count
;
902 unsigned char sense_cmd
[6]; /*
903 * Allocate 6 characters for
906 unsigned int sg_length
; /* We init this during buildscb so we
907 * don't have to calculate anything
908 * during underflow/overflow/stat code
914 * Define a linked list of SCBs.
917 struct aic7xxx_scb
*head
;
918 struct aic7xxx_scb
*tail
;
925 { ILLHADDR
, "Illegal Host Access" },
926 { ILLSADDR
, "Illegal Sequencer Address referenced" },
927 { ILLOPCODE
, "Illegal Opcode in sequencer program" },
928 { SQPARERR
, "Sequencer Ram Parity Error" },
929 { DPARERR
, "Data-Path Ram Parity Error" },
930 { MPARERR
, "Scratch Ram/SCB Array Ram Parity Error" },
931 { PCIERRSTAT
,"PCI Error detected" },
932 { CIOPARERR
, "CIOBUS Parity Error" }
936 generic_sense
[] = { REQUEST_SENSE
, 0, 0, 0, 255, 0 };
939 scb_queue_type free_scbs
; /*
940 * SCBs assigned to free slot on
941 * card (no paging required)
943 struct aic7xxx_scb
*scb_array
[AIC7XXX_MAXSCB
];
944 struct aic7xxx_hwscb
*hscbs
;
945 unsigned char numscbs
; /* current number of scbs */
946 unsigned char maxhscbs
; /* hardware scbs */
947 unsigned char maxscbs
; /* max scbs including pageable scbs */
948 void *hscb_kmalloc_ptr
;
952 unsigned char mesg_bytes
[4];
953 unsigned char command
[28];
956 #define AHC_TRANS_CUR 0x0001
957 #define AHC_TRANS_ACTIVE 0x0002
958 #define AHC_TRANS_GOAL 0x0004
959 #define AHC_TRANS_USER 0x0008
960 #define AHC_TRANS_QUITE 0x0010
962 unsigned char cur_width
;
963 unsigned char goal_width
;
964 unsigned char cur_period
;
965 unsigned char goal_period
;
966 unsigned char cur_offset
;
967 unsigned char goal_offset
;
968 unsigned char cur_options
;
969 unsigned char goal_options
;
970 unsigned char user_width
;
971 unsigned char user_period
;
972 unsigned char user_offset
;
973 unsigned char user_options
;
977 * Define a structure used for each host adapter. Note, in order to avoid
978 * problems with architectures I can't test on (because I don't have one,
979 * such as the Alpha based systems) which happen to give faults for
980 * non-aligned memory accesses, care was taken to align this structure
981 * in a way that gauranteed all accesses larger than 8 bits were aligned
982 * on the appropriate boundary. It's also organized to try and be more
983 * cache line efficient. Be careful when changing this lest you might hurt
984 * overall performance and bring down the wrath of the masses.
986 struct aic7xxx_host
{
988 * This is the first 64 bytes in the host struct
992 * We are grouping things here....first, items that get either read or
993 * written with nearly every interrupt
995 volatile ahc_flag_type flags
;
996 ahc_feature features
; /* chip features */
997 unsigned long base
; /* card base address */
998 volatile unsigned char *maddr
; /* memory mapped address */
999 unsigned long isr_count
; /* Interrupt count */
1000 unsigned long spurious_int
;
1001 scb_data_type
*scb_data
;
1002 volatile unsigned short needdv
;
1003 volatile unsigned short needppr
;
1004 volatile unsigned short needsdtr
;
1005 volatile unsigned short needwdtr
;
1006 volatile unsigned short dtr_pending
;
1007 struct aic7xxx_cmd_queue
{
1013 * Things read/written on nearly every entry into aic7xxx_queue()
1015 volatile scb_queue_type waiting_scbs
;
1016 unsigned short discenable
; /* Targets allowed to disconnect */
1017 unsigned short tagenable
; /* Targets using tagged I/O */
1018 unsigned short orderedtag
; /* Ordered Q tags allowed */
1019 unsigned char unpause
; /* unpause value for HCNTRL */
1020 unsigned char pause
; /* pause value for HCNTRL */
1021 volatile unsigned char qoutfifonext
;
1022 volatile unsigned char activescbs
; /* active scbs */
1023 volatile unsigned char max_activescbs
;
1024 volatile unsigned char qinfifonext
;
1026 #define DEVICE_PRESENT 0x01
1027 #define BUS_DEVICE_RESET_PENDING 0x02
1028 #define DEVICE_RESET_DELAY 0x04
1029 #define DEVICE_PRINT_DTR 0x08
1030 #define DEVICE_PARITY_ERROR 0x10
1031 #define DEVICE_WAS_BUSY 0x20
1032 #define DEVICE_SCSI_3 0x40
1033 #define DEVICE_SCANNED 0x80
1034 volatile unsigned char dev_flags
[MAX_TARGETS
];
1035 volatile unsigned char dev_active_cmds
[MAX_TARGETS
];
1036 volatile unsigned char dev_temp_queue_depth
[MAX_TARGETS
];
1037 unsigned char dev_commands_sent
[MAX_TARGETS
];
1039 unsigned int dev_timer_active
; /* Which devs have a timer set */
1040 struct timer_list dev_timer
;
1041 unsigned long dev_expires
[MAX_TARGETS
];
1043 #if LINUX_VERSION_CODE > KERNEL_VERSION(2,1,0)
1044 spinlock_t spin_lock
;
1045 volatile unsigned char cpu_lock_count
[NR_CPUS
];
1049 Scsi_Cmnd
*dev_dtr_cmnd
[MAX_TARGETS
];
1051 unsigned int dev_checksum
[MAX_TARGETS
];
1053 unsigned char dev_last_queue_full
[MAX_TARGETS
];
1054 unsigned char dev_last_queue_full_count
[MAX_TARGETS
];
1055 unsigned char dev_max_queue_depth
[MAX_TARGETS
];
1057 volatile scb_queue_type delayed_scbs
[MAX_TARGETS
];
1060 unsigned char msg_buf
[13]; /* The message for the target */
1061 unsigned char msg_type
;
1062 #define MSG_TYPE_NONE 0x00
1063 #define MSG_TYPE_INITIATOR_MSGOUT 0x01
1064 #define MSG_TYPE_INITIATOR_MSGIN 0x02
1065 unsigned char msg_len
; /* Length of message */
1066 unsigned char msg_index
; /* Index into msg_buf array */
1067 transinfo_type transinfo
[MAX_TARGETS
];
1071 * We put the less frequently used host structure items after the more
1072 * frequently used items to try and ease the burden on the cache subsystem.
1073 * These entries are not *commonly* accessed, whereas the preceding entries
1074 * are accessed very often. The only exceptions are the qinfifo, qoutfifo,
1075 * and untagged_scbs array. But, they are often accessed only once and each
1076 * access into these arrays is likely to blow a cache line, so they are put
1077 * down here so we can minimize the number of cache lines required to hold
1078 * the preceeding entries.
1081 volatile unsigned char untagged_scbs
[256];
1082 volatile unsigned char qoutfifo
[256];
1083 volatile unsigned char qinfifo
[256];
1084 unsigned int irq
; /* IRQ for this adapter */
1085 int instance
; /* aic7xxx instance number */
1086 int scsi_id
; /* host adapter SCSI ID */
1087 int scsi_id_b
; /* channel B for twin adapters */
1088 unsigned int bios_address
;
1089 int board_name_index
;
1090 unsigned short needppr_copy
; /* default config */
1091 unsigned short needsdtr_copy
; /* default config */
1092 unsigned short needwdtr_copy
; /* default config */
1093 unsigned short ultraenb
; /* Ultra mode target list */
1094 unsigned short bios_control
; /* bios control - SEEPROM */
1095 unsigned short adapter_control
; /* adapter control - SEEPROM */
1096 #if LINUX_VERSION_CODE > KERNEL_VERSION(2,1,92)
1097 struct pci_dev
*pdev
;
1099 unsigned char pci_bus
;
1100 unsigned char pci_device_fn
;
1101 struct seeprom_config sc
;
1102 unsigned short sc_type
;
1103 unsigned short sc_size
;
1104 struct aic7xxx_host
*next
; /* allow for multiple IRQs */
1105 struct Scsi_Host
*host
; /* pointer to scsi host */
1106 int host_no
; /* SCSI host number */
1107 unsigned long mbase
; /* I/O memory address */
1108 ahc_chip chip
; /* chip type */
1113 * Total Xfers (count for each command that has a data xfer),
1114 * broken down further by reads && writes.
1116 * Binned sizes, writes && reads:
1117 * < 512, 512, 1-2K, 2-4K, 4-8K, 8-16K, 16-32K, 32-64K, 64K-128K, > 128K
1119 * Total amounts read/written above 512 bytes (amts under ignored)
1121 * NOTE: Enabling this feature is likely to cause a noticeable performance
1122 * decrease as the accesses into the stats structures blows apart multiple
1123 * cache lines and is CPU time consuming.
1125 * NOTE: Since it doesn't really buy us much, but consumes *tons* of RAM
1126 * and blows apart all sorts of cache lines, I modified this so that we
1127 * no longer look at the LUN. All LUNs now go into the same bin on each
1128 * device for stats purposes.
1130 struct aic7xxx_xferstats
{
1131 long w_total
; /* total writes */
1132 long r_total
; /* total reads */
1133 #ifdef AIC7XXX_PROC_STATS
1134 long w_bins
[8]; /* binned write */
1135 long r_bins
[8]; /* binned reads */
1136 #endif /* AIC7XXX_PROC_STATS */
1137 } stats
[MAX_TARGETS
]; /* [(channel << 3)|target] */
1140 struct target_cmd
*targetcmds
;
1141 unsigned int num_targetcmds
;
1147 * Valid SCSIRATE values. (p. 3-17)
1148 * Provides a mapping of transfer periods in ns/4 to the proper value to
1149 * stick in the SCSIRATE reg to use that transfer rate.
1151 #define AHC_SYNCRATE_ULTRA3 0
1152 #define AHC_SYNCRATE_ULTRA2 1
1153 #define AHC_SYNCRATE_ULTRA 3
1154 #define AHC_SYNCRATE_FAST 6
1155 #define AHC_SYNCRATE_CRC 0x40
1156 #define AHC_SYNCRATE_SE 0x10
1157 static struct aic7xxx_syncrate
{
1158 /* Rates in Ultra mode have bit 8 of sxfr set */
1159 #define ULTRA_SXFR 0x100
1162 unsigned char period
;
1163 const char *rate
[2];
1164 } aic7xxx_syncrates
[] = {
1165 { 0x42, 0x000, 9, {"80.0", "160.0"} },
1166 { 0x13, 0x000, 10, {"40.0", "80.0"} },
1167 { 0x14, 0x000, 11, {"33.0", "66.6"} },
1168 { 0x15, 0x100, 12, {"20.0", "40.0"} },
1169 { 0x16, 0x110, 15, {"16.0", "32.0"} },
1170 { 0x17, 0x120, 18, {"13.4", "26.8"} },
1171 { 0x18, 0x000, 25, {"10.0", "20.0"} },
1172 { 0x19, 0x010, 31, {"8.0", "16.0"} },
1173 { 0x1a, 0x020, 37, {"6.67", "13.3"} },
1174 { 0x1b, 0x030, 43, {"5.7", "11.4"} },
1175 { 0x10, 0x040, 50, {"5.0", "10.0"} },
1176 { 0x00, 0x050, 56, {"4.4", "8.8" } },
1177 { 0x00, 0x060, 62, {"4.0", "8.0" } },
1178 { 0x00, 0x070, 68, {"3.6", "7.2" } },
1179 { 0x00, 0x000, 0, {NULL
, NULL
} },
1182 #define CTL_OF_SCB(scb) (((scb->hscb)->target_channel_lun >> 3) & 0x1), \
1183 (((scb->hscb)->target_channel_lun >> 4) & 0xf), \
1184 ((scb->hscb)->target_channel_lun & 0x07)
1186 #define CTL_OF_CMD(cmd) ((cmd->channel) & 0x01), \
1187 ((cmd->target) & 0x0f), \
1190 #define TARGET_INDEX(cmd) ((cmd)->target | ((cmd)->channel << 3))
1193 * A nice little define to make doing our printks a little easier
1196 #define WARN_LEAD KERN_WARNING "(scsi%d:%d:%d:%d) "
1197 #define INFO_LEAD KERN_INFO "(scsi%d:%d:%d:%d) "
1200 * XXX - these options apply unilaterally to _all_ 274x/284x/294x
1201 * cards in the system. This should be fixed. Exceptions to this
1202 * rule are noted in the comments.
1207 * Skip the scsi bus reset. Non 0 make us skip the reset at startup. This
1208 * has no effect on any later resets that might occur due to things like
1209 * SCSI bus timeouts.
1211 static unsigned int aic7xxx_no_reset
= 0;
1213 * Certain PCI motherboards will scan PCI devices from highest to lowest,
1214 * others scan from lowest to highest, and they tend to do all kinds of
1215 * strange things when they come into contact with PCI bridge chips. The
1216 * net result of all this is that the PCI card that is actually used to boot
1217 * the machine is very hard to detect. Most motherboards go from lowest
1218 * PCI slot number to highest, and the first SCSI controller found is the
1219 * one you boot from. The only exceptions to this are when a controller
1220 * has its BIOS disabled. So, we by default sort all of our SCSI controllers
1221 * from lowest PCI slot number to highest PCI slot number. We also force
1222 * all controllers with their BIOS disabled to the end of the list. This
1223 * works on *almost* all computers. Where it doesn't work, we have this
1224 * option. Setting this option to non-0 will reverse the order of the sort
1225 * to highest first, then lowest, but will still leave cards with their BIOS
1226 * disabled at the very end. That should fix everyone up unless there are
1227 * really strange cirumstances.
1229 static int aic7xxx_reverse_scan
= 0;
1231 * Should we force EXTENDED translation on a controller.
1232 * 0 == Use whatever is in the SEEPROM or default to off
1233 * 1 == Use whatever is in the SEEPROM or default to on
1235 static unsigned int aic7xxx_extended
= 0;
1237 * The IRQ trigger method used on EISA controllers. Does not effect PCI cards.
1238 * -1 = Use detected settings.
1239 * 0 = Force Edge triggered mode.
1240 * 1 = Force Level triggered mode.
1242 static int aic7xxx_irq_trigger
= -1;
1244 * This variable is used to override the termination settings on a controller.
1245 * This should not be used under normal conditions. However, in the case
1246 * that a controller does not have a readable SEEPROM (so that we can't
1247 * read the SEEPROM settings directly) and that a controller has a buggered
1248 * version of the cable detection logic, this can be used to force the
1249 * correct termination. It is preferable to use the manual termination
1250 * settings in the BIOS if possible, but some motherboard controllers store
1251 * those settings in a format we can't read. In other cases, auto term
1252 * should also work, but the chipset was put together with no auto term
1253 * logic (common on motherboard controllers). In those cases, we have
1254 * 32 bits here to work with. That's good for 8 controllers/channels. The
1255 * bits are organized as 4 bits per channel, with scsi0 getting the lowest
1256 * 4 bits in the int. A 1 in a bit position indicates the termination setting
1257 * that corresponds to that bit should be enabled, a 0 is disabled.
1258 * It looks something like this:
1260 * 0x0f = 1111-Single Ended Low Byte Termination on/off
1261 * ||\-Single Ended High Byte Termination on/off
1262 * |\-LVD Low Byte Termination on/off
1263 * \-LVD High Byte Termination on/off
1265 * For non-Ultra2 controllers, the upper 2 bits are not important. So, to
1266 * enable both high byte and low byte termination on scsi0, I would need to
1267 * make sure that the override_term variable was set to 0x03 (bits 0011).
1268 * To make sure that all termination is enabled on an Ultra2 controller at
1269 * scsi2 and only high byte termination on scsi1 and high and low byte
1270 * termination on scsi0, I would set override_term=0xf23 (bits 1111 0010 0011)
1272 * For the most part, users should never have to use this, that's why I
1273 * left it fairly cryptic instead of easy to understand. If you need it,
1274 * most likely someone will be telling you what your's needs to be set to.
1276 static int aic7xxx_override_term
= -1;
1278 * Certain motherboard chipset controllers tend to screw
1279 * up the polarity of the term enable output pin. Use this variable
1280 * to force the correct polarity for your system. This is a bitfield variable
1281 * similar to the previous one, but this one has one bit per channel instead
1283 * 0 = Force the setting to active low.
1284 * 1 = Force setting to active high.
1285 * Most Adaptec cards are active high, several motherboards are active low.
1286 * To force a 2940 card at SCSI 0 to active high and a motherboard 7895
1287 * controller at scsi1 and scsi2 to active low, and a 2910 card at scsi3
1288 * to active high, you would need to set stpwlev=0x9 (bits 1001).
1290 * People shouldn't need to use this, but if you are experiencing lots of
1291 * SCSI timeout problems, this may help. There is one sure way to test what
1292 * this option needs to be. Using a boot floppy to boot the system, configure
1293 * your system to enable all SCSI termination (in the Adaptec SCSI BIOS) and
1294 * if needed then also pass a value to override_term to make sure that the
1295 * driver is enabling SCSI termination, then set this variable to either 0
1296 * or 1. When the driver boots, make sure there are *NO* SCSI cables
1297 * connected to your controller. If it finds and inits the controller
1298 * without problem, then the setting you passed to stpwlev was correct. If
1299 * the driver goes into a reset loop and hangs the system, then you need the
1300 * other setting for this variable. If neither setting lets the machine
1301 * boot then you have definite termination problems that may not be fixable.
1303 static int aic7xxx_stpwlev
= -1;
1305 * Set this to non-0 in order to force the driver to panic the kernel
1306 * and print out debugging info on a SCSI abort or reset cycle.
1308 static int aic7xxx_panic_on_abort
= 0;
1310 * PCI bus parity checking of the Adaptec controllers. This is somewhat
1311 * dubious at best. To my knowledge, this option has never actually
1312 * solved a PCI parity problem, but on certain machines with broken PCI
1313 * chipset configurations, it can generate tons of false error messages.
1314 * It's included in the driver for completeness.
1315 * 0 = Shut off PCI parity check
1316 * -1 = Normal polarity pci parity checking
1317 * 1 = reverse polarity pci parity checking
1319 * NOTE: you can't actually pass -1 on the lilo prompt. So, to set this
1320 * variable to -1 you would actually want to simply pass the variable
1321 * name without a number. That will invert the 0 which will result in
1324 static int aic7xxx_pci_parity
= 0;
1326 * Set this to any non-0 value to cause us to dump the contents of all
1327 * the card's registers in a hex dump format tailored to each model of
1330 * NOTE: THE CONTROLLER IS LEFT IN AN UNUSEABLE STATE BY THIS OPTION.
1331 * YOU CANNOT BOOT UP WITH THIS OPTION, IT IS FOR DEBUGGING PURPOSES
1334 static int aic7xxx_dump_card
= 0;
1336 * Set this to a non-0 value to make us dump out the 32 bit instruction
1337 * registers on the card after completing the sequencer download. This
1338 * allows the actual sequencer download to be verified. It is possible
1339 * to use this option and still boot up and run your system. This is
1340 * only intended for debugging purposes.
1342 static int aic7xxx_dump_sequencer
= 0;
1344 * Certain newer motherboards have put new PCI based devices into the
1345 * IO spaces that used to typically be occupied by VLB or EISA cards.
1346 * This overlap can cause these newer motherboards to lock up when scanned
1347 * for older EISA and VLB devices. Setting this option to non-0 will
1348 * cause the driver to skip scanning for any VLB or EISA controllers and
1349 * only support the PCI controllers. NOTE: this means that if the kernel
1350 * os compiled with PCI support disabled, then setting this to non-0
1351 * would result in never finding any devices :)
1353 static int aic7xxx_no_probe
= 0;
1356 * So that insmod can find the variable and make it point to something
1359 static char * aic7xxx
= NULL
;
1360 #if LINUX_VERSION_CODE > KERNEL_VERSION(2,1,18)
1361 MODULE_PARM(aic7xxx
, "s");
1365 * Just in case someone uses commas to separate items on the insmod
1366 * command line, we define a dummy buffer here to avoid having insmod
1367 * write wild stuff into our code segment
1369 static char dummy_buffer
[60] = "Please don't trounce on me insmod!!\n";
1373 #define VERBOSE_NORMAL 0x0000
1374 #define VERBOSE_NEGOTIATION 0x0001
1375 #define VERBOSE_SEQINT 0x0002
1376 #define VERBOSE_SCSIINT 0x0004
1377 #define VERBOSE_PROBE 0x0008
1378 #define VERBOSE_PROBE2 0x0010
1379 #define VERBOSE_NEGOTIATION2 0x0020
1380 #define VERBOSE_MINOR_ERROR 0x0040
1381 #define VERBOSE_TRACING 0x0080
1382 #define VERBOSE_ABORT 0x0f00
1383 #define VERBOSE_ABORT_MID 0x0100
1384 #define VERBOSE_ABORT_FIND 0x0200
1385 #define VERBOSE_ABORT_PROCESS 0x0400
1386 #define VERBOSE_ABORT_RETURN 0x0800
1387 #define VERBOSE_RESET 0xf000
1388 #define VERBOSE_RESET_MID 0x1000
1389 #define VERBOSE_RESET_FIND 0x2000
1390 #define VERBOSE_RESET_PROCESS 0x4000
1391 #define VERBOSE_RESET_RETURN 0x8000
1392 static int aic7xxx_verbose
= VERBOSE_NORMAL
| VERBOSE_NEGOTIATION
|
1393 VERBOSE_PROBE
; /* verbose messages */
1396 /****************************************************************************
1398 * We're going to start putting in function declarations so that order of
1399 * functions is no longer important. As needed, they are added here.
1401 ***************************************************************************/
1403 static void aic7xxx_panic_abort(struct aic7xxx_host
*p
, Scsi_Cmnd
*cmd
);
1404 static void aic7xxx_print_card(struct aic7xxx_host
*p
);
1405 static void aic7xxx_print_scratch_ram(struct aic7xxx_host
*p
);
1406 static void aic7xxx_print_sequencer(struct aic7xxx_host
*p
, int downloaded
);
1407 #ifdef AIC7XXX_VERBOSE_DEBUGGING
1408 static void aic7xxx_check_scbs(struct aic7xxx_host
*p
, char *buffer
);
1411 /****************************************************************************
1413 * These functions are now used. They happen to be wrapped in useless
1414 * inb/outb port read/writes around the real reads and writes because it
1415 * seems that certain very fast CPUs have a problem dealing with us when
1416 * going at full speed.
1418 ***************************************************************************/
1420 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,1,0)
1422 mdelay(int milliseconds
)
1426 for(i
=0; i
<milliseconds
; i
++)
1431 time_after_eq(unsigned long a
, unsigned long b
)
1433 return((long)((a
) - (b
)) >= 0L);
1437 timer_pending(struct timer_list
*timer
)
1439 return( timer
->prev
!= NULL
);
1442 #define PCI_DEVICE_ID_ADAPTEC_1480A 0x6075
1446 static inline unsigned char
1447 aic_inb(struct aic7xxx_host
*p
, long port
)
1457 x
= inb(p
->base
+ port
);
1462 return(inb(p
->base
+ port
));
1467 aic_outb(struct aic7xxx_host
*p
, unsigned char val
, long port
)
1472 p
->maddr
[port
] = val
;
1476 outb(val
, p
->base
+ port
);
1480 outb(val
, p
->base
+ port
);
1484 /*+F*************************************************************************
1489 * Handle Linux boot parameters. This routine allows for assigning a value
1490 * to a parameter with a ':' between the parameter and the value.
1491 * ie. aic7xxx=unpause:0x0A,extended
1492 *-F*************************************************************************/
1494 aic7xxx_setup(char *s
, int *dummy
)
1504 { "extended", &aic7xxx_extended
},
1505 { "no_reset", &aic7xxx_no_reset
},
1506 { "irq_trigger", &aic7xxx_irq_trigger
},
1507 { "verbose", &aic7xxx_verbose
},
1508 { "reverse_scan",&aic7xxx_reverse_scan
},
1509 { "override_term", &aic7xxx_override_term
},
1510 { "stpwlev", &aic7xxx_stpwlev
},
1511 { "no_probe", &aic7xxx_no_probe
},
1512 { "panic_on_abort", &aic7xxx_panic_on_abort
},
1513 { "pci_parity", &aic7xxx_pci_parity
},
1514 { "dump_card", &aic7xxx_dump_card
},
1515 { "dump_sequencer", &aic7xxx_dump_sequencer
},
1516 { "tag_info", NULL
}
1519 end
= strchr(s
, '\0');
1521 for (p
= strtok(s
, ",."); p
; p
= strtok(NULL
, ",."))
1523 for (i
= 0; i
< NUMBER(options
); i
++)
1525 n
= strlen(options
[i
].name
);
1526 if (!strncmp(options
[i
].name
, p
, n
))
1528 if (!strncmp(p
, "tag_info", n
))
1533 char *tok
, *tok_end
, *tok_end2
;
1534 char tok_list
[] = { '.', ',', '{', '}', '\0' };
1535 int i
, instance
= -1, device
= -1;
1536 unsigned char done
= FALSE
;
1539 tok
= base
+ n
+ 1; /* Forward us just past the ':' */
1540 tok_end
= strchr(tok
, '\0');
1550 else if (device
== -1)
1557 else if (instance
!= -1)
1565 else if (device
>= 0)
1567 else if (instance
>= 0)
1569 if ( (device
>= MAX_TARGETS
) ||
1570 (instance
>= NUMBER(aic7xxx_tag_info
)) )
1583 tok_end
= strchr(tok
, '\0');
1584 for(i
=0; tok_list
[i
]; i
++)
1586 tok_end2
= strchr(tok
, tok_list
[i
]);
1587 if ( (tok_end2
) && (tok_end2
< tok_end
) )
1593 if ( (instance
>= 0) && (device
>= 0) &&
1594 (instance
< NUMBER(aic7xxx_tag_info
)) &&
1595 (device
< MAX_TARGETS
) )
1596 aic7xxx_tag_info
[instance
].tag_commands
[device
] =
1597 simple_strtoul(tok
, NULL
, 0) & 0xff;
1602 while((p
!= base
) && (p
!= NULL
))
1603 p
= strtok(NULL
, ",.");
1606 else if (p
[n
] == ':')
1608 *(options
[i
].flag
) = simple_strtoul(p
+ n
+ 1, NULL
, 0);
1610 else if (!strncmp(p
, "verbose", n
))
1612 *(options
[i
].flag
) = 0xff09;
1616 *(options
[i
].flag
) = ~(*(options
[i
].flag
));
1623 /*+F*************************************************************************
1628 * Pause the sequencer and wait for it to actually stop - this
1629 * is important since the sequencer can disable pausing for critical
1631 *-F*************************************************************************/
1633 pause_sequencer(struct aic7xxx_host
*p
)
1635 aic_outb(p
, p
->pause
, HCNTRL
);
1636 while ((aic_inb(p
, HCNTRL
) & PAUSE
) == 0)
1642 /*+F*************************************************************************
1647 * Unpause the sequencer. Unremarkable, yet done often enough to
1648 * warrant an easy way to do it.
1649 *-F*************************************************************************/
1651 unpause_sequencer(struct aic7xxx_host
*p
, int unpause_always
)
1653 if (unpause_always
||
1654 ( !(aic_inb(p
, INTSTAT
) & (SCSIINT
| SEQINT
| BRKADRINT
)) &&
1655 !(p
->flags
& AHC_HANDLING_REQINITS
) ) )
1657 aic_outb(p
, p
->unpause
, HCNTRL
);
1661 /*+F*************************************************************************
1666 * Restart the sequencer program from address zero. This assumes
1667 * that the sequencer is already paused.
1668 *-F*************************************************************************/
1670 restart_sequencer(struct aic7xxx_host
*p
)
1672 aic_outb(p
, 0, SEQADDR0
);
1673 aic_outb(p
, 0, SEQADDR1
);
1674 aic_outb(p
, FASTMODE
, SEQCTL
);
1678 * We include the aic7xxx_seq.c file here so that the other defines have
1679 * already been made, and so that it comes before the code that actually
1680 * downloads the instructions (since we don't typically use function
1681 * prototype, our code has to be ordered that way, it's a left-over from
1682 * the original driver days.....I should fix it some time DL).
1684 #include "aic7xxx_seq.c"
1686 /*+F*************************************************************************
1688 * aic7xxx_check_patch
1691 * See if the next patch to download should be downloaded.
1692 *-F*************************************************************************/
1694 aic7xxx_check_patch(struct aic7xxx_host
*p
,
1695 struct sequencer_patch
**start_patch
, int start_instr
, int *skip_addr
)
1697 struct sequencer_patch
*cur_patch
;
1698 struct sequencer_patch
*last_patch
;
1701 num_patches
= sizeof(sequencer_patches
)/sizeof(struct sequencer_patch
);
1702 last_patch
= &sequencer_patches
[num_patches
];
1703 cur_patch
= *start_patch
;
1705 while ((cur_patch
< last_patch
) && (start_instr
== cur_patch
->begin
))
1707 if (cur_patch
->patch_func(p
) == 0)
1710 * Start rejecting code.
1712 *skip_addr
= start_instr
+ cur_patch
->skip_instr
;
1713 cur_patch
+= cur_patch
->skip_patch
;
1718 * Found an OK patch. Advance the patch pointer to the next patch
1719 * and wait for our instruction pointer to get here.
1725 *start_patch
= cur_patch
;
1726 if (start_instr
< *skip_addr
)
1735 /*+F*************************************************************************
1737 * aic7xxx_download_instr
1740 * Find the next patch to download.
1741 *-F*************************************************************************/
1743 aic7xxx_download_instr(struct aic7xxx_host
*p
, int instrptr
,
1744 unsigned char *dconsts
)
1746 union ins_formats instr
;
1747 struct ins_format1
*fmt1_ins
;
1748 struct ins_format3
*fmt3_ins
;
1749 unsigned char opcode
;
1751 instr
= *(union ins_formats
*) &seqprog
[instrptr
* 4];
1753 instr
.integer
= le32_to_cpu(instr
.integer
);
1755 fmt1_ins
= &instr
.format1
;
1758 /* Pull the opcode */
1759 opcode
= instr
.format1
.opcode
;
1771 struct sequencer_patch
*cur_patch
;
1773 unsigned int address
;
1777 fmt3_ins
= &instr
.format3
;
1779 address
= fmt3_ins
->address
;
1780 cur_patch
= sequencer_patches
;
1783 for (i
= 0; i
< address
;)
1785 aic7xxx_check_patch(p
, &cur_patch
, i
, &skip_addr
);
1790 end_addr
= MIN(address
, skip_addr
);
1791 address_offset
+= end_addr
- i
;
1799 address
-= address_offset
;
1800 fmt3_ins
->address
= address
;
1801 /* Fall Through to the next code section */
1809 if (fmt1_ins
->parity
!= 0)
1811 fmt1_ins
->immediate
= dconsts
[fmt1_ins
->immediate
];
1813 fmt1_ins
->parity
= 0;
1814 /* Fall Through to the next code section */
1816 if ((p
->features
& AHC_ULTRA2
) != 0)
1820 /* Calculate odd parity for the instruction */
1821 for ( i
=0, count
=0; i
< 31; i
++)
1826 if ((instr
.integer
& mask
) != 0)
1829 if (!(count
& 0x01))
1830 instr
.format1
.parity
= 1;
1834 if (fmt3_ins
!= NULL
)
1836 instr
.integer
= fmt3_ins
->immediate
|
1837 (fmt3_ins
->source
<< 8) |
1838 (fmt3_ins
->address
<< 16) |
1839 (fmt3_ins
->opcode
<< 25);
1843 instr
.integer
= fmt1_ins
->immediate
|
1844 (fmt1_ins
->source
<< 8) |
1845 (fmt1_ins
->destination
<< 16) |
1846 (fmt1_ins
->ret
<< 24) |
1847 (fmt1_ins
->opcode
<< 25);
1850 aic_outb(p
, (instr
.integer
& 0xff), SEQRAM
);
1851 aic_outb(p
, ((instr
.integer
>> 8) & 0xff), SEQRAM
);
1852 aic_outb(p
, ((instr
.integer
>> 16) & 0xff), SEQRAM
);
1853 aic_outb(p
, ((instr
.integer
>> 24) & 0xff), SEQRAM
);
1858 panic("aic7xxx: Unknown opcode encountered in sequencer program.");
1864 /*+F*************************************************************************
1869 * Load the sequencer code into the controller memory.
1870 *-F*************************************************************************/
1872 aic7xxx_loadseq(struct aic7xxx_host
*p
)
1874 struct sequencer_patch
*cur_patch
;
1878 unsigned char download_consts
[4] = {0, 0, 0, 0};
1880 if (aic7xxx_verbose
& VERBOSE_PROBE
)
1882 printk(KERN_INFO
"(scsi%d) Downloading sequencer code...", p
->host_no
);
1885 download_consts
[TMODE_NUMCMDS
] = p
->num_targetcmds
;
1887 download_consts
[TMODE_NUMCMDS
] = 0;
1888 cur_patch
= &sequencer_patches
[0];
1892 aic_outb(p
, PERRORDIS
|LOADRAM
|FAILDIS
|FASTMODE
, SEQCTL
);
1893 aic_outb(p
, 0, SEQADDR0
);
1894 aic_outb(p
, 0, SEQADDR1
);
1896 for (i
= 0; i
< sizeof(seqprog
) / 4; i
++)
1898 if (aic7xxx_check_patch(p
, &cur_patch
, i
, &skip_addr
) == 0)
1900 /* Skip this instruction for this configuration. */
1903 aic7xxx_download_instr(p
, i
, &download_consts
[0]);
1907 aic_outb(p
, 0, SEQADDR0
);
1908 aic_outb(p
, 0, SEQADDR1
);
1909 aic_outb(p
, FASTMODE
| FAILDIS
, SEQCTL
);
1910 unpause_sequencer(p
, TRUE
);
1913 aic_outb(p
, FASTMODE
, SEQCTL
);
1914 if (aic7xxx_verbose
& VERBOSE_PROBE
)
1916 printk(" %d instructions downloaded\n", downloaded
);
1918 if (aic7xxx_dump_sequencer
)
1919 aic7xxx_print_sequencer(p
, downloaded
);
1922 /*+F*************************************************************************
1924 * aic7xxx_print_sequencer
1927 * Print the contents of the sequencer memory to the screen.
1928 *-F*************************************************************************/
1930 aic7xxx_print_sequencer(struct aic7xxx_host
*p
, int downloaded
)
1934 aic_outb(p
, PERRORDIS
|LOADRAM
|FAILDIS
|FASTMODE
, SEQCTL
);
1935 aic_outb(p
, 0, SEQADDR0
);
1936 aic_outb(p
, 0, SEQADDR1
);
1939 for (i
=0; i
< downloaded
; i
++)
1942 printk("%03x: ", i
);
1943 temp
= aic_inb(p
, SEQRAM
);
1944 temp
|= (aic_inb(p
, SEQRAM
) << 8);
1945 temp
|= (aic_inb(p
, SEQRAM
) << 16);
1946 temp
|= (aic_inb(p
, SEQRAM
) << 24);
1947 printk("%08x", temp
);
1956 aic_outb(p
, 0, SEQADDR0
);
1957 aic_outb(p
, 0, SEQADDR1
);
1958 aic_outb(p
, FASTMODE
| FAILDIS
, SEQCTL
);
1959 unpause_sequencer(p
, TRUE
);
1962 aic_outb(p
, FASTMODE
, SEQCTL
);
1966 /*+F*************************************************************************
1971 * Delay for specified amount of time. We use mdelay because the timer
1972 * interrupt is not guaranteed to be enabled. This will cause an
1973 * infinite loop since jiffies (clock ticks) is not updated.
1974 *-F*************************************************************************/
1976 aic7xxx_delay(int seconds
)
1978 mdelay(seconds
* 1000);
1981 /*+F*************************************************************************
1986 * Return a string describing the driver.
1987 *-F*************************************************************************/
1989 aic7xxx_info(struct Scsi_Host
*dooh
)
1991 static char buffer
[256];
1993 struct aic7xxx_host
*p
;
1996 p
= (struct aic7xxx_host
*)dooh
->hostdata
;
1997 memset(bp
, 0, sizeof(buffer
));
1998 strcpy(bp
, "Adaptec AHA274x/284x/294x (EISA/VLB/PCI-Fast SCSI) ");
1999 strcat(bp
, AIC7XXX_C_VERSION
);
2001 strcat(bp
, AIC7XXX_H_VERSION
);
2004 strcat(bp
, board_names
[p
->board_name_index
]);
2010 /*+F*************************************************************************
2012 * aic7xxx_find_syncrate
2015 * Look up the valid period to SCSIRATE conversion in our table
2016 *-F*************************************************************************/
2017 static struct aic7xxx_syncrate
*
2018 aic7xxx_find_syncrate(struct aic7xxx_host
*p
, unsigned int *period
,
2019 unsigned int maxsync
, unsigned char *options
)
2021 struct aic7xxx_syncrate
*syncrate
;
2026 case MSG_EXT_PPR_OPTION_DT_CRC
:
2027 case MSG_EXT_PPR_OPTION_DT_UNITS
:
2028 if(!(p
->features
& AHC_ULTRA3
))
2031 maxsync
= MAX(maxsync
, AHC_SYNCRATE_ULTRA2
);
2034 case MSG_EXT_PPR_OPTION_DT_CRC_QUICK
:
2035 case MSG_EXT_PPR_OPTION_DT_UNITS_QUICK
:
2036 if(!(p
->features
& AHC_ULTRA3
))
2039 maxsync
= MAX(maxsync
, AHC_SYNCRATE_ULTRA2
);
2044 * we don't support the Quick Arbitration variants of dual edge
2045 * clocking. As it turns out, we want to send back the
2046 * same basic option, but without the QA attribute.
2047 * We know that we are responding because we would never set
2048 * these options ourself, we would only respond to them.
2052 case MSG_EXT_PPR_OPTION_DT_CRC_QUICK
:
2053 *options
= MSG_EXT_PPR_OPTION_DT_CRC
;
2055 case MSG_EXT_PPR_OPTION_DT_UNITS_QUICK
:
2056 *options
= MSG_EXT_PPR_OPTION_DT_UNITS
;
2063 maxsync
= MAX(maxsync
, AHC_SYNCRATE_ULTRA2
);
2066 syncrate
= &aic7xxx_syncrates
[maxsync
];
2067 while ( (syncrate
->rate
[0] != NULL
) &&
2068 (!(p
->features
& AHC_ULTRA2
) || syncrate
->sxfr_ultra2
) )
2070 if (*period
<= syncrate
->period
)
2074 case MSG_EXT_PPR_OPTION_DT_CRC
:
2075 case MSG_EXT_PPR_OPTION_DT_UNITS
:
2076 if(!(syncrate
->sxfr_ultra2
& AHC_SYNCRATE_CRC
))
2080 * oops, we went too low for the CRC/DualEdge signalling, so
2081 * clear the options byte
2085 * We'll be sending a reply to this packet to set the options
2086 * properly, so unilaterally set the period as well.
2088 *period
= syncrate
->period
;
2093 if(syncrate
== &aic7xxx_syncrates
[maxsync
])
2095 *period
= syncrate
->period
;
2100 if(!(syncrate
->sxfr_ultra2
& AHC_SYNCRATE_CRC
))
2103 if(syncrate
== &aic7xxx_syncrates
[maxsync
])
2105 *period
= syncrate
->period
;
2117 if ( (*period
== 0) || (syncrate
->rate
[0] == NULL
) ||
2118 ((p
->features
& AHC_ULTRA2
) && (syncrate
->sxfr_ultra2
== 0)) )
2121 * Use async transfers for this target
2131 /*+F*************************************************************************
2133 * aic7xxx_find_period
2136 * Look up the valid SCSIRATE to period conversion in our table
2137 *-F*************************************************************************/
2139 aic7xxx_find_period(struct aic7xxx_host
*p
, unsigned int scsirate
,
2140 unsigned int maxsync
)
2142 struct aic7xxx_syncrate
*syncrate
;
2144 if (p
->features
& AHC_ULTRA2
)
2146 scsirate
&= SXFR_ULTRA2
;
2153 syncrate
= &aic7xxx_syncrates
[maxsync
];
2154 while (syncrate
->rate
[0] != NULL
)
2156 if (p
->features
& AHC_ULTRA2
)
2158 if (syncrate
->sxfr_ultra2
== 0)
2160 else if (scsirate
== syncrate
->sxfr_ultra2
)
2161 return (syncrate
->period
);
2162 else if (scsirate
== (syncrate
->sxfr_ultra2
& ~AHC_SYNCRATE_CRC
))
2163 return (syncrate
->period
);
2165 else if (scsirate
== (syncrate
->sxfr
& ~ULTRA_SXFR
))
2167 return (syncrate
->period
);
2171 return (0); /* async */
2174 /*+F*************************************************************************
2176 * aic7xxx_validate_offset
2179 * Set a valid offset value for a particular card in use and transfer
2181 *-F*************************************************************************/
2183 aic7xxx_validate_offset(struct aic7xxx_host
*p
,
2184 struct aic7xxx_syncrate
*syncrate
, unsigned int *offset
, int wide
)
2186 unsigned int maxoffset
;
2188 /* Limit offset to what the card (and device) can do */
2189 if (syncrate
== NULL
)
2193 else if (p
->features
& AHC_ULTRA2
)
2195 maxoffset
= MAX_OFFSET_ULTRA2
;
2200 maxoffset
= MAX_OFFSET_16BIT
;
2202 maxoffset
= MAX_OFFSET_8BIT
;
2204 *offset
= MIN(*offset
, maxoffset
);
2207 /*+F*************************************************************************
2209 * aic7xxx_set_syncrate
2212 * Set the actual syncrate down in the card and in our host structs
2213 *-F*************************************************************************/
2215 aic7xxx_set_syncrate(struct aic7xxx_host
*p
, struct aic7xxx_syncrate
*syncrate
,
2216 int target
, int channel
, unsigned int period
, unsigned int offset
,
2217 unsigned char options
, unsigned int type
)
2219 unsigned char tindex
;
2220 unsigned short target_mask
;
2221 unsigned char lun
, old_options
;
2222 unsigned int old_period
, old_offset
;
2224 tindex
= target
| (channel
<< 3);
2225 target_mask
= 0x01 << tindex
;
2226 lun
= aic_inb(p
, SCB_TCL
) & 0x07;
2228 if (syncrate
== NULL
)
2234 old_period
= p
->transinfo
[tindex
].cur_period
;
2235 old_offset
= p
->transinfo
[tindex
].cur_offset
;
2236 old_options
= p
->transinfo
[tindex
].cur_options
;
2239 if (type
& AHC_TRANS_CUR
)
2241 unsigned int scsirate
;
2243 scsirate
= aic_inb(p
, TARG_SCSIRATE
+ tindex
);
2244 if (p
->features
& AHC_ULTRA2
)
2246 scsirate
&= ~SXFR_ULTRA2
;
2247 if (syncrate
!= NULL
)
2251 case MSG_EXT_PPR_OPTION_DT_UNITS
:
2253 * mask off the CRC bit in the xfer settings
2255 scsirate
|= (syncrate
->sxfr_ultra2
& ~AHC_SYNCRATE_CRC
);
2258 scsirate
|= syncrate
->sxfr_ultra2
;
2262 if (type
& AHC_TRANS_ACTIVE
)
2264 aic_outb(p
, offset
, SCSIOFFSET
);
2266 aic_outb(p
, offset
, TARG_OFFSET
+ tindex
);
2268 else /* Not an Ultra2 controller */
2270 scsirate
&= ~(SXFR
|SOFS
);
2271 p
->ultraenb
&= ~target_mask
;
2272 if (syncrate
!= NULL
)
2274 if (syncrate
->sxfr
& ULTRA_SXFR
)
2276 p
->ultraenb
|= target_mask
;
2278 scsirate
|= (syncrate
->sxfr
& SXFR
);
2279 scsirate
|= (offset
& SOFS
);
2281 if (type
& AHC_TRANS_ACTIVE
)
2283 unsigned char sxfrctl0
;
2285 sxfrctl0
= aic_inb(p
, SXFRCTL0
);
2286 sxfrctl0
&= ~FAST20
;
2287 if (p
->ultraenb
& target_mask
)
2289 aic_outb(p
, sxfrctl0
, SXFRCTL0
);
2291 aic_outb(p
, p
->ultraenb
& 0xff, ULTRA_ENB
);
2292 aic_outb(p
, (p
->ultraenb
>> 8) & 0xff, ULTRA_ENB
+ 1 );
2294 if (type
& AHC_TRANS_ACTIVE
)
2296 aic_outb(p
, scsirate
, SCSIRATE
);
2298 aic_outb(p
, scsirate
, TARG_SCSIRATE
+ tindex
);
2299 p
->transinfo
[tindex
].cur_period
= period
;
2300 p
->transinfo
[tindex
].cur_offset
= offset
;
2301 p
->transinfo
[tindex
].cur_options
= options
;
2302 if ( !(type
& AHC_TRANS_QUITE
) &&
2303 (aic7xxx_verbose
& VERBOSE_NEGOTIATION
) &&
2304 (p
->dev_flags
[tindex
] & DEVICE_PRINT_DTR
) )
2308 int rate_mod
= (scsirate
& WIDEXFER
) ? 1 : 0;
2310 printk(INFO_LEAD
"Synchronous at %s Mbyte/sec, "
2311 "offset %d.\n", p
->host_no
, channel
, target
, lun
,
2312 syncrate
->rate
[rate_mod
], offset
);
2316 printk(INFO_LEAD
"Using asynchronous transfers.\n",
2317 p
->host_no
, channel
, target
, lun
);
2319 p
->dev_flags
[tindex
] &= ~DEVICE_PRINT_DTR
;
2323 if (type
& AHC_TRANS_GOAL
)
2325 p
->transinfo
[tindex
].goal_period
= period
;
2326 p
->transinfo
[tindex
].goal_offset
= offset
;
2327 p
->transinfo
[tindex
].goal_options
= options
;
2330 if (type
& AHC_TRANS_USER
)
2332 p
->transinfo
[tindex
].user_period
= period
;
2333 p
->transinfo
[tindex
].user_offset
= offset
;
2334 p
->transinfo
[tindex
].user_options
= options
;
2338 /*+F*************************************************************************
2343 * Set the actual width down in the card and in our host structs
2344 *-F*************************************************************************/
2346 aic7xxx_set_width(struct aic7xxx_host
*p
, int target
, int channel
, int lun
,
2347 unsigned int width
, unsigned int type
)
2349 unsigned char tindex
;
2350 unsigned short target_mask
;
2351 unsigned int old_width
;
2353 tindex
= target
| (channel
<< 3);
2354 target_mask
= 1 << tindex
;
2356 old_width
= p
->transinfo
[tindex
].cur_width
;
2358 if (type
& AHC_TRANS_CUR
)
2360 unsigned char scsirate
;
2362 scsirate
= aic_inb(p
, TARG_SCSIRATE
+ tindex
);
2364 scsirate
&= ~WIDEXFER
;
2365 if (width
== MSG_EXT_WDTR_BUS_16_BIT
)
2366 scsirate
|= WIDEXFER
;
2368 aic_outb(p
, scsirate
, TARG_SCSIRATE
+ tindex
);
2370 if (type
& AHC_TRANS_ACTIVE
)
2371 aic_outb(p
, scsirate
, SCSIRATE
);
2373 p
->transinfo
[tindex
].cur_width
= width
;
2375 if ( !(type
& AHC_TRANS_QUITE
) &&
2376 (aic7xxx_verbose
& VERBOSE_NEGOTIATION2
) &&
2377 (p
->dev_flags
[tindex
] & DEVICE_PRINT_DTR
) )
2379 printk(INFO_LEAD
"Using %s transfers\n", p
->host_no
, channel
, target
,
2380 lun
, (scsirate
& WIDEXFER
) ? "Wide(16bit)" : "Narrow(8bit)" );
2384 if (type
& AHC_TRANS_GOAL
)
2385 p
->transinfo
[tindex
].goal_width
= width
;
2386 if (type
& AHC_TRANS_USER
)
2387 p
->transinfo
[tindex
].user_width
= width
;
2389 if (p
->transinfo
[tindex
].goal_offset
)
2391 if (p
->features
& AHC_ULTRA2
)
2393 p
->transinfo
[tindex
].goal_offset
= MAX_OFFSET_ULTRA2
;
2395 else if (width
== MSG_EXT_WDTR_BUS_16_BIT
)
2397 p
->transinfo
[tindex
].goal_offset
= MAX_OFFSET_16BIT
;
2401 p
->transinfo
[tindex
].goal_offset
= MAX_OFFSET_8BIT
;
2406 /*+F*************************************************************************
2411 * SCB queue initialization.
2413 *-F*************************************************************************/
2415 scbq_init(volatile scb_queue_type
*queue
)
2421 /*+F*************************************************************************
2426 * Add an SCB to the head of the list.
2428 *-F*************************************************************************/
2430 scbq_insert_head(volatile scb_queue_type
*queue
, struct aic7xxx_scb
*scb
)
2432 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,1,95)
2433 unsigned long cpu_flags
;
2437 scb
->q_next
= queue
->head
;
2439 if (queue
->tail
== NULL
) /* If list was empty, update tail. */
2440 queue
->tail
= queue
->head
;
2444 /*+F*************************************************************************
2449 * Remove an SCB from the head of the list.
2451 *-F*************************************************************************/
2452 static inline struct aic7xxx_scb
*
2453 scbq_remove_head(volatile scb_queue_type
*queue
)
2455 struct aic7xxx_scb
* scbp
;
2456 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,1,95)
2457 unsigned long cpu_flags
;
2462 if (queue
->head
!= NULL
)
2463 queue
->head
= queue
->head
->q_next
;
2464 if (queue
->head
== NULL
) /* If list is now empty, update tail. */
2470 /*+F*************************************************************************
2475 * Removes an SCB from the list.
2477 *-F*************************************************************************/
2479 scbq_remove(volatile scb_queue_type
*queue
, struct aic7xxx_scb
*scb
)
2481 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,1,95)
2482 unsigned long cpu_flags
;
2486 if (queue
->head
== scb
)
2488 /* At beginning of queue, remove from head. */
2489 scbq_remove_head(queue
);
2493 struct aic7xxx_scb
*curscb
= queue
->head
;
2496 * Search until the next scb is the one we're looking for, or
2497 * we run out of queue.
2499 while ((curscb
!= NULL
) && (curscb
->q_next
!= scb
))
2501 curscb
= curscb
->q_next
;
2506 curscb
->q_next
= scb
->q_next
;
2507 if (scb
->q_next
== NULL
)
2509 /* Update the tail when removing the tail. */
2510 queue
->tail
= curscb
;
2517 /*+F*************************************************************************
2522 * Add an SCB at the tail of the list.
2524 *-F*************************************************************************/
2526 scbq_insert_tail(volatile scb_queue_type
*queue
, struct aic7xxx_scb
*scb
)
2528 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,1,95)
2529 unsigned long cpu_flags
;
2534 if (queue
->tail
!= NULL
) /* Add the scb at the end of the list. */
2535 queue
->tail
->q_next
= scb
;
2536 queue
->tail
= scb
; /* Update the tail. */
2537 if (queue
->head
== NULL
) /* If list was empty, update head. */
2538 queue
->head
= queue
->tail
;
2542 /*+F*************************************************************************
2547 * Checks to see if an scb matches the target/channel as specified.
2548 * If target is ALL_TARGETS (-1), then we're looking for any device
2549 * on the specified channel; this happens when a channel is going
2550 * to be reset and all devices on that channel must be aborted.
2551 *-F*************************************************************************/
2553 aic7xxx_match_scb(struct aic7xxx_host
*p
, struct aic7xxx_scb
*scb
,
2554 int target
, int channel
, int lun
, unsigned char tag
)
2556 int targ
= (scb
->hscb
->target_channel_lun
>> 4) & 0x0F;
2557 int chan
= (scb
->hscb
->target_channel_lun
>> 3) & 0x01;
2558 int slun
= scb
->hscb
->target_channel_lun
& 0x07;
2561 match
= ((chan
== channel
) || (channel
== ALL_CHANNELS
));
2563 match
= ((targ
== target
) || (target
== ALL_TARGETS
));
2565 match
= ((lun
== slun
) || (lun
== ALL_LUNS
));
2567 match
= ((tag
== scb
->hscb
->tag
) || (tag
== SCB_LIST_NULL
));
2572 /*+F*************************************************************************
2574 * aic7xxx_add_curscb_to_free_list
2577 * Adds the current scb (in SCBPTR) to the list of free SCBs.
2578 *-F*************************************************************************/
2580 aic7xxx_add_curscb_to_free_list(struct aic7xxx_host
*p
)
2583 * Invalidate the tag so that aic7xxx_find_scb doesn't think
2586 aic_outb(p
, SCB_LIST_NULL
, SCB_TAG
);
2587 aic_outb(p
, 0, SCB_CONTROL
);
2589 aic_outb(p
, aic_inb(p
, FREE_SCBH
), SCB_NEXT
);
2590 aic_outb(p
, aic_inb(p
, SCBPTR
), FREE_SCBH
);
2593 /*+F*************************************************************************
2595 * aic7xxx_rem_scb_from_disc_list
2598 * Removes the current SCB from the disconnected list and adds it
2600 *-F*************************************************************************/
2601 static unsigned char
2602 aic7xxx_rem_scb_from_disc_list(struct aic7xxx_host
*p
, unsigned char scbptr
,
2607 aic_outb(p
, scbptr
, SCBPTR
);
2608 next
= aic_inb(p
, SCB_NEXT
);
2609 aic7xxx_add_curscb_to_free_list(p
);
2611 if (prev
!= SCB_LIST_NULL
)
2613 aic_outb(p
, prev
, SCBPTR
);
2614 aic_outb(p
, next
, SCB_NEXT
);
2618 aic_outb(p
, next
, DISCONNECTED_SCBH
);
2624 /*+F*************************************************************************
2626 * aic7xxx_busy_target
2629 * Set the specified target busy.
2630 *-F*************************************************************************/
2632 aic7xxx_busy_target(struct aic7xxx_host
*p
, struct aic7xxx_scb
*scb
)
2634 p
->untagged_scbs
[scb
->hscb
->target_channel_lun
] = scb
->hscb
->tag
;
2637 /*+F*************************************************************************
2639 * aic7xxx_index_busy_target
2642 * Returns the index of the busy target, and optionally sets the
2644 *-F*************************************************************************/
2645 static inline unsigned char
2646 aic7xxx_index_busy_target(struct aic7xxx_host
*p
, unsigned char tcl
,
2649 unsigned char busy_scbid
;
2651 busy_scbid
= p
->untagged_scbs
[tcl
];
2654 p
->untagged_scbs
[tcl
] = SCB_LIST_NULL
;
2656 return (busy_scbid
);
2659 /*+F*************************************************************************
2664 * Look through the SCB array of the card and attempt to find the
2665 * hardware SCB that corresponds to the passed in SCB. Return
2666 * SCB_LIST_NULL if unsuccessful. This routine assumes that the
2667 * card is already paused.
2668 *-F*************************************************************************/
2669 static unsigned char
2670 aic7xxx_find_scb(struct aic7xxx_host
*p
, struct aic7xxx_scb
*scb
)
2672 unsigned char saved_scbptr
;
2673 unsigned char curindex
;
2675 saved_scbptr
= aic_inb(p
, SCBPTR
);
2677 for (curindex
= 0; curindex
< p
->scb_data
->maxhscbs
; curindex
++)
2679 aic_outb(p
, curindex
, SCBPTR
);
2680 if (aic_inb(p
, SCB_TAG
) == scb
->hscb
->tag
)
2685 aic_outb(p
, saved_scbptr
, SCBPTR
);
2686 if (curindex
>= p
->scb_data
->maxhscbs
)
2688 curindex
= SCB_LIST_NULL
;
2694 /*+F*************************************************************************
2696 * aic7xxx_allocate_scb
2699 * Get an SCB from the free list or by allocating a new one.
2700 *-F*************************************************************************/
2702 aic7xxx_allocate_scb(struct aic7xxx_host
*p
)
2704 struct aic7xxx_scb
*scbp
= NULL
;
2705 int scb_size
= sizeof(struct aic7xxx_scb
) +
2706 sizeof (struct hw_scatterlist
) * AIC7XXX_MAX_SG
;
2708 int step
= PAGE_SIZE
/ 1024;
2709 unsigned long scb_count
= 0;
2710 struct hw_scatterlist
*hsgp
;
2711 struct aic7xxx_scb
*scb_ap
;
2715 if (p
->scb_data
->numscbs
< p
->scb_data
->maxscbs
)
2718 * Calculate the optimal number of SCBs to allocate.
2720 * NOTE: This formula works because the sizeof(sg_array) is always
2721 * 1024. Therefore, scb_size * i would always be > PAGE_SIZE *
2722 * (i/step). The (i-1) allows the left hand side of the equation
2723 * to grow into the right hand side to a point of near perfect
2724 * efficiency since scb_size * (i -1) is growing slightly faster
2725 * than the right hand side. If the number of SG array elements
2726 * is changed, this function may not be near so efficient any more.
2728 for ( i
=step
;; i
*= 2 )
2730 if ( (scb_size
* (i
-1)) >= ( (PAGE_SIZE
* (i
/step
)) - 64 ) )
2736 scb_count
= MIN( (i
-1), p
->scb_data
->maxscbs
- p
->scb_data
->numscbs
);
2737 scb_ap
= (struct aic7xxx_scb
*)kmalloc(scb_size
* scb_count
, GFP_ATOMIC
);
2740 #ifdef AIC7XXX_VERBOSE_DEBUGGING
2741 if (aic7xxx_verbose
> 0xffff)
2743 if (p
->scb_data
->numscbs
== 0)
2744 printk(INFO_LEAD
"Allocating initial %ld SCB structures.\n",
2745 p
->host_no
, -1, -1, -1, scb_count
);
2747 printk(INFO_LEAD
"Allocating %ld additional SCB structures.\n",
2748 p
->host_no
, -1, -1, -1, scb_count
);
2751 memset(scb_ap
, 0, scb_count
* scb_size
);
2752 temp
= (unsigned long) &scb_ap
[scb_count
];
2755 hsgp
= (struct hw_scatterlist
*)temp
;
2756 for (i
=0; i
< scb_count
; i
++)
2759 scbp
->hscb
= &p
->scb_data
->hscbs
[p
->scb_data
->numscbs
];
2760 scbp
->sg_list
= &hsgp
[i
* AIC7XXX_MAX_SG
];
2761 memset(scbp
->hscb
, 0, sizeof(struct aic7xxx_hwscb
));
2762 scbp
->hscb
->tag
= p
->scb_data
->numscbs
;
2764 * Place in the scb array; never is removed
2766 p
->scb_data
->scb_array
[p
->scb_data
->numscbs
++] = scbp
;
2767 scbq_insert_tail(&p
->scb_data
->free_scbs
, scbp
);
2769 scbp
->kmalloc_ptr
= scb_ap
;
2779 /*+F*************************************************************************
2781 * aic7xxx_queue_cmd_complete
2784 * Due to race conditions present in the SCSI subsystem, it is easier
2785 * to queue completed commands, then call scsi_done() on them when
2786 * we're finished. This function queues the completed commands.
2787 *-F*************************************************************************/
2789 aic7xxx_queue_cmd_complete(struct aic7xxx_host
*p
, Scsi_Cmnd
*cmd
)
2791 cmd
->host_scribble
= (char *)p
->completeq
.head
;
2792 p
->completeq
.head
= cmd
;
2795 /*+F*************************************************************************
2797 * aic7xxx_done_cmds_complete
2800 * Process the completed command queue.
2801 *-F*************************************************************************/
2803 aic7xxx_done_cmds_complete(struct aic7xxx_host
*p
)
2806 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,1,95)
2807 unsigned int cpu_flags
= 0;
2811 while (p
->completeq
.head
!= NULL
)
2813 cmd
= p
->completeq
.head
;
2814 p
->completeq
.head
= (Scsi_Cmnd
*)cmd
->host_scribble
;
2815 cmd
->host_scribble
= NULL
;
2816 cmd
->scsi_done(cmd
);
2821 /*+F*************************************************************************
2826 * Free the scb and insert into the free scb list.
2827 *-F*************************************************************************/
2829 aic7xxx_free_scb(struct aic7xxx_host
*p
, struct aic7xxx_scb
*scb
)
2832 scb
->flags
= SCB_FREE
;
2836 scb
->tag_action
= 0;
2837 scb
->hscb
->control
= 0;
2838 scb
->hscb
->target_status
= 0;
2839 scb
->hscb
->target_channel_lun
= SCB_LIST_NULL
;
2841 scbq_insert_head(&p
->scb_data
->free_scbs
, scb
);
2844 /*+F*************************************************************************
2849 * Calls the higher level scsi done function and frees the scb.
2850 *-F*************************************************************************/
2852 aic7xxx_done(struct aic7xxx_host
*p
, struct aic7xxx_scb
*scb
)
2854 Scsi_Cmnd
*cmd
= scb
->cmd
;
2855 int tindex
= TARGET_INDEX(cmd
);
2856 struct aic7xxx_scb
*scbp
;
2857 unsigned char queue_depth
;
2859 if (scb
->flags
& SCB_RECOVERY_SCB
)
2861 p
->flags
&= ~AHC_ABORT_PENDING
;
2863 if (scb
->flags
& SCB_RESET
)
2865 cmd
->result
= (DID_RESET
<< 16) | (cmd
->result
& 0xffff);
2867 else if (scb
->flags
& SCB_ABORT
)
2869 cmd
->result
= (DID_RESET
<< 16) | (cmd
->result
& 0xffff);
2871 else if (!(p
->dev_flags
[tindex
] & DEVICE_SCANNED
))
2873 if ( (cmd
->cmnd
[0] == INQUIRY
) && (cmd
->result
== DID_OK
) )
2877 p
->dev_flags
[tindex
] |= DEVICE_PRESENT
;
2880 struct scatterlist
*sg
;
2882 sg
= (struct scatterlist
*)cmd
->request_buffer
;
2883 buffer
= (char *)sg
[0].address
;
2887 buffer
= (char *)cmd
->request_buffer
;
2889 #define WIDE_INQUIRY_BITS 0x60
2890 #define SYNC_INQUIRY_BITS 0x10
2891 #define SCSI_VERSION_BITS 0x07
2892 if ( (buffer
[7] & WIDE_INQUIRY_BITS
) &&
2893 (p
->features
& AHC_WIDE
) )
2895 p
->needwdtr
|= (1<<tindex
);
2896 p
->needwdtr_copy
|= (1<<tindex
);
2897 p
->transinfo
[tindex
].goal_width
= p
->transinfo
[tindex
].user_width
;
2901 p
->needwdtr
&= ~(1<<tindex
);
2902 p
->needwdtr_copy
&= ~(1<<tindex
);
2904 aic7xxx_set_width(p
, cmd
->target
, cmd
->channel
, cmd
->lun
,
2905 MSG_EXT_WDTR_BUS_8_BIT
, (AHC_TRANS_ACTIVE
|
2908 unpause_sequencer(p
, FALSE
);
2910 if (buffer
[7] & SYNC_INQUIRY_BITS
)
2912 p
->needsdtr
|= (1<<tindex
);
2913 p
->needsdtr_copy
|= (1<<tindex
);
2915 p
->transinfo
[tindex
].goal_period
= p
->transinfo
[tindex
].user_period
;
2916 p
->transinfo
[tindex
].goal_options
= p
->transinfo
[tindex
].user_options
;
2917 if (p
->transinfo
[tindex
].user_offset
)
2919 if (p
->features
& AHC_ULTRA2
)
2920 p
->transinfo
[tindex
].goal_offset
= MAX_OFFSET_ULTRA2
;
2921 else if (p
->transinfo
[tindex
].goal_width
== MSG_EXT_WDTR_BUS_16_BIT
)
2922 p
->transinfo
[tindex
].goal_offset
= MAX_OFFSET_16BIT
;
2924 p
->transinfo
[tindex
].goal_offset
= MAX_OFFSET_8BIT
;
2929 p
->needsdtr
&= ~(1<<tindex
);
2930 p
->needsdtr_copy
&= ~(1<<tindex
);
2931 p
->transinfo
[tindex
].goal_period
= 0;
2932 p
->transinfo
[tindex
].goal_offset
= 0;
2933 p
->transinfo
[tindex
].goal_options
= 0;
2935 if ( (buffer
[2] & SCSI_VERSION_BITS
) == 3 )
2937 p
->dev_flags
[tindex
] |= DEVICE_SCSI_3
;
2939 * OK, we are a SCSI 3 device and we are in need of negotiation.
2940 * Use PPR messages instead of WDTR and SDTR messages.
2942 if ( (p
->needsdtr
& (1<<tindex
)) ||
2943 (p
->needwdtr
& (1<<tindex
)) )
2945 p
->needppr
|= (1<<tindex
);
2946 p
->needppr_copy
|= (1<<tindex
);
2948 p
->needwdtr
&= ~(1<<tindex
);
2949 p
->needwdtr_copy
&= ~(1<<tindex
);
2950 p
->needsdtr
&= ~(1<<tindex
);
2951 p
->needsdtr_copy
&= ~(1<<tindex
);
2954 * Get the INQUIRY checksum. We use this on Ultra 160/m
2955 * and older devices both. It allows us to drop speed on any bus type
2956 * while at the same time giving us the needed domain validation for
2959 * Note: We only get the checksum and set the SCANNED bit if this is
2960 * one of our dtr commands. If we don't do this, then we end up
2961 * getting bad checksum results on the mid-level SCSI code's INQUIRY
2964 if(p
->dev_dtr_cmnd
[tindex
] == cmd
) {
2965 unsigned int checksum
= 0;
2969 ibuffer
= (int *)buffer
;
2970 for( i
= 0; i
< (cmd
->request_bufflen
>> 2); i
++)
2972 checksum
+= ibuffer
[i
];
2974 p
->dev_checksum
[tindex
] = checksum
;
2975 p
->dev_flags
[tindex
] |= DEVICE_SCANNED
;
2976 p
->dev_flags
[tindex
] |= DEVICE_PRINT_DTR
;
2978 #undef WIDE_INQUIRY_BITS
2979 #undef SYNC_INQUIRY_BITS
2980 #undef SCSI_VERSION_BITS
2983 else if ((scb
->flags
& SCB_MSGOUT_BITS
) != 0)
2985 unsigned short mask
;
2986 int message_error
= FALSE
;
2988 mask
= 0x01 << tindex
;
2991 * Check to see if we get an invalid message or a message error
2992 * after failing to negotiate a wide or sync transfer message.
2994 if ((scb
->flags
& SCB_SENSE
) &&
2995 ((scb
->cmd
->sense_buffer
[12] == 0x43) || /* INVALID_MESSAGE */
2996 (scb
->cmd
->sense_buffer
[12] == 0x49))) /* MESSAGE_ERROR */
2998 message_error
= TRUE
;
3001 if (scb
->flags
& SCB_MSGOUT_WDTR
)
3003 p
->dtr_pending
&= ~mask
;
3006 if ( (aic7xxx_verbose
& VERBOSE_NEGOTIATION2
) &&
3007 (p
->dev_flags
[tindex
] & DEVICE_PRINT_DTR
) )
3009 printk(INFO_LEAD
"Device failed to complete Wide Negotiation "
3010 "processing and\n", p
->host_no
, CTL_OF_SCB(scb
));
3011 printk(INFO_LEAD
"returned a sense error code for invalid message, "
3012 "disabling future\n", p
->host_no
, CTL_OF_SCB(scb
));
3013 printk(INFO_LEAD
"Wide negotiation to this device.\n", p
->host_no
,
3016 p
->needwdtr
&= ~mask
;
3017 p
->needwdtr_copy
&= ~mask
;
3020 if (scb
->flags
& SCB_MSGOUT_SDTR
)
3022 p
->dtr_pending
&= ~mask
;
3025 if ( (aic7xxx_verbose
& VERBOSE_NEGOTIATION2
) &&
3026 (p
->dev_flags
[tindex
] & DEVICE_PRINT_DTR
) )
3028 printk(INFO_LEAD
"Device failed to complete Sync Negotiation "
3029 "processing and\n", p
->host_no
, CTL_OF_SCB(scb
));
3030 printk(INFO_LEAD
"returned a sense error code for invalid message, "
3031 "disabling future\n", p
->host_no
, CTL_OF_SCB(scb
));
3032 printk(INFO_LEAD
"Sync negotiation to this device.\n", p
->host_no
,
3034 p
->dev_flags
[tindex
] &= ~DEVICE_PRINT_DTR
;
3036 p
->needsdtr
&= ~mask
;
3037 p
->needsdtr_copy
&= ~mask
;
3040 if (scb
->flags
& SCB_MSGOUT_PPR
)
3042 p
->dtr_pending
&= ~mask
;
3045 if ( (aic7xxx_verbose
& VERBOSE_NEGOTIATION2
) &&
3046 (p
->dev_flags
[tindex
] & DEVICE_PRINT_DTR
) )
3048 printk(INFO_LEAD
"Device failed to complete Parallel Protocol "
3049 "Request processing and\n", p
->host_no
, CTL_OF_SCB(scb
));
3050 printk(INFO_LEAD
"returned a sense error code for invalid message, "
3051 "disabling future\n", p
->host_no
, CTL_OF_SCB(scb
));
3052 printk(INFO_LEAD
"Parallel Protocol Request negotiation to this "
3053 "device.\n", p
->host_no
, CTL_OF_SCB(scb
));
3056 * Disable PPR negotiation and revert back to WDTR and SDTR setup
3058 p
->needppr
&= ~mask
;
3059 p
->needppr_copy
&= ~mask
;
3060 p
->needsdtr
|= mask
;
3061 p
->needsdtr_copy
|= mask
;
3062 p
->needwdtr
|= mask
;
3063 p
->needwdtr_copy
|= mask
;
3067 queue_depth
= p
->dev_temp_queue_depth
[tindex
];
3068 if (queue_depth
>= p
->dev_active_cmds
[tindex
])
3070 scbp
= scbq_remove_head(&p
->delayed_scbs
[tindex
]);
3073 if (queue_depth
== 1)
3076 * Give extra preference to untagged devices, such as CD-R devices
3077 * This makes it more likely that a drive *won't* stuff up while
3078 * waiting on data at a critical time, such as CD-R writing and
3079 * audio CD ripping operations. Should also benefit tape drives.
3081 scbq_insert_head(&p
->waiting_scbs
, scbp
);
3085 scbq_insert_tail(&p
->waiting_scbs
, scbp
);
3087 #ifdef AIC7XXX_VERBOSE_DEBUGGING
3088 if (aic7xxx_verbose
> 0xffff)
3089 printk(INFO_LEAD
"Moving SCB from delayed to waiting queue.\n",
3090 p
->host_no
, CTL_OF_SCB(scbp
));
3092 if (queue_depth
> p
->dev_active_cmds
[tindex
])
3094 scbp
= scbq_remove_head(&p
->delayed_scbs
[tindex
]);
3096 scbq_insert_tail(&p
->waiting_scbs
, scbp
);
3100 if ( !(scb
->tag_action
) && (p
->tagenable
& (1<<tindex
)) )
3102 p
->dev_temp_queue_depth
[tindex
] = p
->dev_max_queue_depth
[tindex
];
3104 p
->dev_active_cmds
[tindex
]--;
3111 * XXX: we should actually know how much actually transferred
3112 * XXX: for each command, but apparently that's too difficult.
3114 * We set a lower limit of 512 bytes on the transfer length. We
3115 * ignore anything less than this because we don't have a real
3116 * reason to count it. Read/Writes to tapes are usually about 20K
3117 * and disks are a minimum of 512 bytes unless you want to count
3118 * non-read/write commands (such as TEST_UNIT_READY) which we don't
3120 actual
= scb
->sg_length
;
3121 if ((actual
>= 512) && (((cmd
->result
>> 16) & 0xf) == DID_OK
))
3123 struct aic7xxx_xferstats
*sp
;
3124 #ifdef AIC7XXX_PROC_STATS
3127 #endif /* AIC7XXX_PROC_STATS */
3129 sp
= &p
->stats
[TARGET_INDEX(cmd
)];
3132 * For block devices, cmd->request.cmd is always == either READ or
3133 * WRITE. For character devices, this isn't always set properly, so
3134 * we check data_cmnd[0]. This catches the conditions for st.c, but
3135 * I'm still not sure if request.cmd is valid for sg devices.
3137 if ( (cmd
->request
.cmd
== WRITE
) || (cmd
->data_cmnd
[0] == WRITE_6
) ||
3138 (cmd
->data_cmnd
[0] == WRITE_FILEMARKS
) )
3141 #ifdef AIC7XXX_VERBOSE_DEBUGGING
3142 if ( (sp
->w_total
> 16) && (aic7xxx_verbose
> 0xffff) )
3143 aic7xxx_verbose
&= 0xffff;
3145 #ifdef AIC7XXX_PROC_STATS
3147 #endif /* AIC7XXX_PROC_STATS */
3152 #ifdef AIC7XXX_VERBOSE_DEBUGGING
3153 if ( (sp
->r_total
> 16) && (aic7xxx_verbose
> 0xffff) )
3154 aic7xxx_verbose
&= 0xffff;
3156 #ifdef AIC7XXX_PROC_STATS
3158 #endif /* AIC7XXX_PROC_STATS */
3160 #ifdef AIC7XXX_PROC_STATS
3179 #endif /* AIC7XXX_PROC_STATS */
3182 aic7xxx_free_scb(p
, scb
);
3183 aic7xxx_queue_cmd_complete(p
, cmd
);
3187 /*+F*************************************************************************
3189 * aic7xxx_run_done_queue
3192 * Calls the aic7xxx_done() for the Scsi_Cmnd of each scb in the
3193 * aborted list, and adds each scb to the free list. If complete
3194 * is TRUE, we also process the commands complete list.
3195 *-F*************************************************************************/
3197 aic7xxx_run_done_queue(struct aic7xxx_host
*p
, /*complete*/ int complete
)
3199 struct aic7xxx_scb
*scb
;
3202 for (i
= 0; i
< p
->scb_data
->numscbs
; i
++)
3204 scb
= p
->scb_data
->scb_array
[i
];
3205 if (scb
->flags
& SCB_QUEUED_FOR_DONE
)
3207 if (aic7xxx_verbose
& (VERBOSE_ABORT_PROCESS
| VERBOSE_RESET_PROCESS
))
3208 printk(INFO_LEAD
"Aborting scb %d\n",
3209 p
->host_no
, CTL_OF_SCB(scb
), scb
->hscb
->tag
);
3211 aic7xxx_done(p
, scb
);
3214 if (aic7xxx_verbose
& (VERBOSE_ABORT_RETURN
| VERBOSE_RESET_RETURN
))
3216 printk(INFO_LEAD
"%d commands found and queued for "
3217 "completion.\n", p
->host_no
, -1, -1, -1, found
);
3221 aic7xxx_done_cmds_complete(p
);
3225 /*+F*************************************************************************
3227 * aic7xxx_abort_waiting_scb
3230 * Manipulate the waiting for selection list and return the
3231 * scb that follows the one that we remove.
3232 *-F*************************************************************************/
3233 static unsigned char
3234 aic7xxx_abort_waiting_scb(struct aic7xxx_host
*p
, struct aic7xxx_scb
*scb
,
3235 unsigned char scbpos
, unsigned char prev
)
3237 unsigned char curscb
, next
;
3240 * Select the SCB we want to abort and pull the next pointer out of it.
3242 curscb
= aic_inb(p
, SCBPTR
);
3243 aic_outb(p
, scbpos
, SCBPTR
);
3244 next
= aic_inb(p
, SCB_NEXT
);
3246 aic7xxx_add_curscb_to_free_list(p
);
3249 * Update the waiting list
3251 if (prev
== SCB_LIST_NULL
)
3256 aic_outb(p
, next
, WAITING_SCBH
);
3261 * Select the scb that pointed to us and update its next pointer.
3263 aic_outb(p
, prev
, SCBPTR
);
3264 aic_outb(p
, next
, SCB_NEXT
);
3267 * Point us back at the original scb position and inform the SCSI
3268 * system that the command has been aborted.
3270 aic_outb(p
, curscb
, SCBPTR
);
3274 /*+F*************************************************************************
3276 * aic7xxx_search_qinfifo
3279 * Search the queue-in FIFO for matching SCBs and conditionally
3280 * requeue. Returns the number of matching SCBs.
3281 *-F*************************************************************************/
3283 aic7xxx_search_qinfifo(struct aic7xxx_host
*p
, int target
, int channel
,
3284 int lun
, unsigned char tag
, int flags
, int requeue
,
3285 volatile scb_queue_type
*queue
)
3288 unsigned char qinpos
, qintail
;
3289 struct aic7xxx_scb
*scbp
;
3292 qinpos
= aic_inb(p
, QINPOS
);
3293 qintail
= p
->qinfifonext
;
3295 p
->qinfifonext
= qinpos
;
3297 while (qinpos
!= qintail
)
3299 scbp
= p
->scb_data
->scb_array
[p
->qinfifo
[qinpos
++]];
3300 if (aic7xxx_match_scb(p
, scbp
, target
, channel
, lun
, tag
))
3303 * We found an scb that needs to be removed.
3305 if (requeue
&& (queue
!= NULL
))
3307 if (scbp
->flags
& SCB_WAITINGQ
)
3309 scbq_remove(queue
, scbp
);
3310 scbq_remove(&p
->waiting_scbs
, scbp
);
3311 scbq_remove(&p
->delayed_scbs
[TARGET_INDEX(scbp
->cmd
)], scbp
);
3312 p
->dev_active_cmds
[TARGET_INDEX(scbp
->cmd
)]++;
3315 scbq_insert_tail(queue
, scbp
);
3316 p
->dev_active_cmds
[TARGET_INDEX(scbp
->cmd
)]--;
3318 scbp
->flags
|= SCB_WAITINGQ
;
3319 if ( !(scbp
->tag_action
& TAG_ENB
) )
3321 aic7xxx_index_busy_target(p
, scbp
->hscb
->target_channel_lun
,
3327 p
->qinfifo
[p
->qinfifonext
++] = scbp
->hscb
->tag
;
3332 * Preserve any SCB_RECOVERY_SCB flags on this scb then set the
3333 * flags we were called with, presumeably so aic7xxx_run_done_queue
3336 scbp
->flags
= flags
| (scbp
->flags
& SCB_RECOVERY_SCB
);
3337 if (aic7xxx_index_busy_target(p
, scbp
->hscb
->target_channel_lun
,
3338 FALSE
) == scbp
->hscb
->tag
)
3340 aic7xxx_index_busy_target(p
, scbp
->hscb
->target_channel_lun
,
3348 p
->qinfifo
[p
->qinfifonext
++] = scbp
->hscb
->tag
;
3352 * Now that we've done the work, clear out any left over commands in the
3353 * qinfifo and update the KERNEL_QINPOS down on the card.
3355 * NOTE: This routine expect the sequencer to already be paused when
3356 * it is run....make sure it's that way!
3358 qinpos
= p
->qinfifonext
;
3359 while(qinpos
!= qintail
)
3361 p
->qinfifo
[qinpos
++] = SCB_LIST_NULL
;
3363 if (p
->features
& AHC_QUEUE_REGS
)
3364 aic_outb(p
, p
->qinfifonext
, HNSCB_QOFF
);
3366 aic_outb(p
, p
->qinfifonext
, KERNEL_QINPOS
);
3371 /*+F*************************************************************************
3373 * aic7xxx_scb_on_qoutfifo
3376 * Is the scb that was passed to us currently on the qoutfifo?
3377 *-F*************************************************************************/
3379 aic7xxx_scb_on_qoutfifo(struct aic7xxx_host
*p
, struct aic7xxx_scb
*scb
)
3383 while(p
->qoutfifo
[(p
->qoutfifonext
+ i
) & 0xff ] != SCB_LIST_NULL
)
3385 if(p
->qoutfifo
[(p
->qoutfifonext
+ i
) & 0xff ] == scb
->hscb
->tag
)
3394 /*+F*************************************************************************
3396 * aic7xxx_reset_device
3399 * The device at the given target/channel has been reset. Abort
3400 * all active and queued scbs for that target/channel. This function
3401 * need not worry about linked next pointers because if was a MSG_ABORT_TAG
3402 * then we had a tagged command (no linked next), if it was MSG_ABORT or
3403 * MSG_BUS_DEV_RESET then the device won't know about any commands any more
3404 * and no busy commands will exist, and if it was a bus reset, then nothing
3405 * knows about any linked next commands any more. In all cases, we don't
3406 * need to worry about the linked next or busy scb, we just need to clear
3408 *-F*************************************************************************/
3410 aic7xxx_reset_device(struct aic7xxx_host
*p
, int target
, int channel
,
3411 int lun
, unsigned char tag
)
3413 struct aic7xxx_scb
*scbp
;
3414 unsigned char active_scb
, tcl
;
3415 int i
= 0, j
, init_lists
= FALSE
;
3418 * Restore this when we're done
3420 active_scb
= aic_inb(p
, SCBPTR
);
3422 if (aic7xxx_verbose
& (VERBOSE_RESET_PROCESS
| VERBOSE_ABORT_PROCESS
))
3423 printk(INFO_LEAD
"Reset device, active_scb %d\n",
3424 p
->host_no
, channel
, target
, lun
, active_scb
);
3426 * Deal with the busy target and linked next issues.
3429 int min_target
, max_target
;
3430 struct aic7xxx_scb
*scbp
, *prev_scbp
;
3432 /* Make all targets 'relative' to bus A. */
3433 if (target
== ALL_TARGETS
)
3439 max_target
= (p
->features
& AHC_WIDE
) ? 15 : 7;
3448 max_target
= (p
->features
& (AHC_TWIN
|AHC_WIDE
)) ? 15 : 7;
3454 min_target
= target
| (channel
<< 3);
3455 max_target
= min_target
;
3459 for (i
= min_target
; i
<= max_target
; i
++)
3461 if ( i
== p
->scsi_id
)
3465 if (aic7xxx_verbose
& (VERBOSE_ABORT_PROCESS
| VERBOSE_RESET_PROCESS
))
3466 printk(INFO_LEAD
"Cleaning up status information "
3467 "and delayed_scbs.\n", p
->host_no
, channel
, i
, lun
);
3468 p
->dev_flags
[i
] &= ~(BUS_DEVICE_RESET_PENDING
| DEVICE_PARITY_ERROR
);
3469 if ( tag
== SCB_LIST_NULL
)
3471 p
->dev_flags
[i
] |= DEVICE_PRINT_DTR
| DEVICE_RESET_DELAY
;
3472 p
->dev_expires
[i
] = jiffies
+ (4 * HZ
);
3473 p
->dev_timer_active
|= (0x01 << i
);
3474 p
->dev_last_queue_full_count
[i
] = 0;
3475 p
->dev_last_queue_full
[i
] = 0;
3476 p
->dev_temp_queue_depth
[i
] =
3477 p
->dev_max_queue_depth
[i
];
3479 for(j
=0; j
<MAX_LUNS
; j
++)
3482 tcl
= ((i
<< 4) & 0x70) | (channel
<< 3) | j
;
3484 tcl
= (i
<< 4) | (channel
<< 3) | j
;
3485 if ( (aic7xxx_index_busy_target(p
, tcl
, FALSE
) == tag
) ||
3486 (tag
== SCB_LIST_NULL
) )
3487 aic7xxx_index_busy_target(p
, tcl
, /* unbusy */ TRUE
);
3491 scbp
= p
->delayed_scbs
[i
].head
;
3492 while ( (scbp
!= NULL
) && (j
++ <= (p
->scb_data
->numscbs
+ 1)) )
3495 scbp
= scbp
->q_next
;
3496 if ( prev_scbp
== scbp
)
3498 if (aic7xxx_verbose
& (VERBOSE_ABORT
| VERBOSE_RESET
))
3499 printk(WARN_LEAD
"Yikes!! scb->q_next == scb "
3500 "in the delayed_scbs queue!\n", p
->host_no
, channel
, i
, lun
);
3502 prev_scbp
->q_next
= NULL
;
3503 p
->delayed_scbs
[i
].tail
= prev_scbp
;
3505 if (aic7xxx_match_scb(p
, prev_scbp
, target
, channel
, lun
, tag
))
3507 scbq_remove(&p
->delayed_scbs
[i
], prev_scbp
);
3508 if (prev_scbp
->flags
& SCB_WAITINGQ
)
3510 p
->dev_active_cmds
[i
]++;
3513 prev_scbp
->flags
&= ~(SCB_ACTIVE
| SCB_WAITINGQ
);
3514 prev_scbp
->flags
|= SCB_RESET
| SCB_QUEUED_FOR_DONE
;
3517 if ( j
> (p
->scb_data
->maxscbs
+ 1) )
3519 if (aic7xxx_verbose
& (VERBOSE_ABORT
| VERBOSE_RESET
))
3520 printk(WARN_LEAD
"Yikes!! There's a loop in the "
3521 "delayed_scbs queue!\n", p
->host_no
, channel
, i
, lun
);
3522 scbq_init(&p
->delayed_scbs
[i
]);
3524 if ( !(p
->dev_timer_active
& (0x01 << MAX_TARGETS
)) ||
3525 time_after_eq(p
->dev_timer
.expires
, p
->dev_expires
[i
]) )
3527 del_timer(&p
->dev_timer
);
3528 p
->dev_timer
.expires
= p
->dev_expires
[i
];
3529 add_timer(&p
->dev_timer
);
3530 p
->dev_timer_active
|= (0x01 << MAX_TARGETS
);
3535 if (aic7xxx_verbose
& (VERBOSE_ABORT_PROCESS
| VERBOSE_RESET_PROCESS
))
3536 printk(INFO_LEAD
"Cleaning QINFIFO.\n", p
->host_no
, channel
, target
, lun
);
3537 aic7xxx_search_qinfifo(p
, target
, channel
, lun
, tag
,
3538 SCB_RESET
| SCB_QUEUED_FOR_DONE
, /* requeue */ FALSE
, NULL
);
3541 * Search the waiting_scbs queue for matches, this catches any SCB_QUEUED
3542 * ABORT/RESET commands.
3544 if (aic7xxx_verbose
& (VERBOSE_ABORT_PROCESS
| VERBOSE_RESET_PROCESS
))
3545 printk(INFO_LEAD
"Cleaning waiting_scbs.\n", p
->host_no
, channel
,
3548 struct aic7xxx_scb
*scbp
, *prev_scbp
;
3552 scbp
= p
->waiting_scbs
.head
;
3553 while ( (scbp
!= NULL
) && (j
++ <= (p
->scb_data
->numscbs
+ 1)) )
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 waiting_scbs queue!\n", p
->host_no
, CTL_OF_SCB(scbp
));
3563 prev_scbp
->q_next
= NULL
;
3564 p
->waiting_scbs
.tail
= prev_scbp
;
3566 if (aic7xxx_match_scb(p
, prev_scbp
, target
, channel
, lun
, tag
))
3568 scbq_remove(&p
->waiting_scbs
, prev_scbp
);
3569 if (prev_scbp
->flags
& SCB_WAITINGQ
)
3571 p
->dev_active_cmds
[TARGET_INDEX(prev_scbp
->cmd
)]++;
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 "waiting_scbs queue!\n", p
->host_no
, channel
, target
, lun
);
3583 scbq_init(&p
->waiting_scbs
);
3589 * Search waiting for selection list.
3591 if (aic7xxx_verbose
& (VERBOSE_ABORT_PROCESS
| VERBOSE_RESET_PROCESS
))
3592 printk(INFO_LEAD
"Cleaning waiting for selection "
3593 "list.\n", p
->host_no
, channel
, target
, lun
);
3595 unsigned char next
, prev
, scb_index
;
3597 next
= aic_inb(p
, WAITING_SCBH
); /* Start at head of list. */
3598 prev
= SCB_LIST_NULL
;
3600 while ( (next
!= SCB_LIST_NULL
) && (j
++ <= (p
->scb_data
->maxscbs
+ 1)) )
3602 aic_outb(p
, next
, SCBPTR
);
3603 scb_index
= aic_inb(p
, SCB_TAG
);
3604 if (scb_index
>= p
->scb_data
->numscbs
)
3607 * No aic7xxx_verbose check here.....we want to see this since it
3608 * means either the kernel driver or the sequencer screwed things up
3610 printk(WARN_LEAD
"Waiting List inconsistency; SCB index=%d, "
3611 "numscbs=%d\n", p
->host_no
, channel
, target
, lun
, scb_index
,
3612 p
->scb_data
->numscbs
);
3613 next
= aic_inb(p
, SCB_NEXT
);
3614 aic7xxx_add_curscb_to_free_list(p
);
3618 scbp
= p
->scb_data
->scb_array
[scb_index
];
3619 if (aic7xxx_match_scb(p
, scbp
, target
, channel
, lun
, tag
))
3621 next
= aic7xxx_abort_waiting_scb(p
, scbp
, next
, prev
);
3622 if (scbp
->flags
& SCB_WAITINGQ
)
3624 p
->dev_active_cmds
[TARGET_INDEX(scbp
->cmd
)]++;
3627 scbp
->flags
&= ~(SCB_ACTIVE
| SCB_WAITINGQ
);
3628 scbp
->flags
|= SCB_RESET
| SCB_QUEUED_FOR_DONE
;
3629 if (prev
== SCB_LIST_NULL
)
3632 * This is either the first scb on the waiting list, or we
3633 * have already yanked the first and haven't left any behind.
3634 * Either way, we need to turn off the selection hardware if
3635 * it isn't already off.
3637 aic_outb(p
, aic_inb(p
, SCSISEQ
) & ~ENSELO
, SCSISEQ
);
3638 aic_outb(p
, CLRSELTIMEO
, CLRSINT1
);
3644 next
= aic_inb(p
, SCB_NEXT
);
3648 if ( j
> (p
->scb_data
->maxscbs
+ 1) )
3650 printk(WARN_LEAD
"Yikes!! There is a loop in the waiting for "
3651 "selection list!\n", p
->host_no
, channel
, target
, lun
);
3657 * Go through disconnected list and remove any entries we have queued
3658 * for completion, zeroing their control byte too.
3660 if (aic7xxx_verbose
& (VERBOSE_ABORT_PROCESS
| VERBOSE_RESET_PROCESS
))
3661 printk(INFO_LEAD
"Cleaning disconnected scbs "
3662 "list.\n", p
->host_no
, channel
, target
, lun
);
3663 if (p
->flags
& AHC_PAGESCBS
)
3665 unsigned char next
, prev
, scb_index
;
3667 next
= aic_inb(p
, DISCONNECTED_SCBH
);
3668 prev
= SCB_LIST_NULL
;
3670 while ( (next
!= SCB_LIST_NULL
) && (j
++ <= (p
->scb_data
->maxscbs
+ 1)) )
3672 aic_outb(p
, next
, SCBPTR
);
3673 scb_index
= aic_inb(p
, SCB_TAG
);
3674 if (scb_index
> p
->scb_data
->numscbs
)
3676 printk(WARN_LEAD
"Disconnected List inconsistency; SCB index=%d, "
3677 "numscbs=%d\n", p
->host_no
, channel
, target
, lun
, scb_index
,
3678 p
->scb_data
->numscbs
);
3679 next
= aic7xxx_rem_scb_from_disc_list(p
, next
, prev
);
3683 scbp
= p
->scb_data
->scb_array
[scb_index
];
3684 if (aic7xxx_match_scb(p
, scbp
, target
, channel
, lun
, tag
))
3686 next
= aic7xxx_rem_scb_from_disc_list(p
, next
, prev
);
3687 if (scbp
->flags
& SCB_WAITINGQ
)
3689 p
->dev_active_cmds
[TARGET_INDEX(scbp
->cmd
)]++;
3692 scbp
->flags
&= ~(SCB_ACTIVE
| SCB_WAITINGQ
);
3693 scbp
->flags
|= SCB_RESET
| SCB_QUEUED_FOR_DONE
;
3694 scbp
->hscb
->control
= 0;
3699 next
= aic_inb(p
, SCB_NEXT
);
3703 if ( j
> (p
->scb_data
->maxscbs
+ 1) )
3705 printk(WARN_LEAD
"Yikes!! There is a loop in the disconnected list!\n",
3706 p
->host_no
, channel
, target
, lun
);
3712 * Walk the free list making sure no entries on the free list have
3713 * a valid SCB_TAG value or SCB_CONTROL byte.
3715 if (p
->flags
& AHC_PAGESCBS
)
3720 next
= aic_inb(p
, FREE_SCBH
);
3721 if ( (next
>= p
->scb_data
->maxhscbs
) && (next
!= SCB_LIST_NULL
) )
3723 printk(WARN_LEAD
"Bogus FREE_SCBH!.\n", p
->host_no
, channel
,
3726 next
= SCB_LIST_NULL
;
3728 while ( (next
!= SCB_LIST_NULL
) && (j
++ <= (p
->scb_data
->maxscbs
+ 1)) )
3730 aic_outb(p
, next
, SCBPTR
);
3731 if (aic_inb(p
, SCB_TAG
) < p
->scb_data
->numscbs
)
3733 printk(WARN_LEAD
"Free list inconsistency!.\n", p
->host_no
, channel
,
3736 next
= SCB_LIST_NULL
;
3740 aic_outb(p
, SCB_LIST_NULL
, SCB_TAG
);
3741 aic_outb(p
, 0, SCB_CONTROL
);
3742 next
= aic_inb(p
, SCB_NEXT
);
3745 if ( j
> (p
->scb_data
->maxscbs
+ 1) )
3747 printk(WARN_LEAD
"Yikes!! There is a loop in the free list!\n",
3748 p
->host_no
, channel
, target
, lun
);
3754 * Go through the hardware SCB array looking for commands that
3755 * were active but not on any list.
3759 aic_outb(p
, SCB_LIST_NULL
, FREE_SCBH
);
3760 aic_outb(p
, SCB_LIST_NULL
, WAITING_SCBH
);
3761 aic_outb(p
, SCB_LIST_NULL
, DISCONNECTED_SCBH
);
3763 for (i
= p
->scb_data
->maxhscbs
- 1; i
>= 0; i
--)
3765 unsigned char scbid
;
3767 aic_outb(p
, i
, SCBPTR
);
3770 aic_outb(p
, SCB_LIST_NULL
, SCB_TAG
);
3771 aic_outb(p
, SCB_LIST_NULL
, SCB_NEXT
);
3772 aic_outb(p
, 0, SCB_CONTROL
);
3773 aic7xxx_add_curscb_to_free_list(p
);
3777 scbid
= aic_inb(p
, SCB_TAG
);
3778 if (scbid
< p
->scb_data
->numscbs
)
3780 scbp
= p
->scb_data
->scb_array
[scbid
];
3781 if (aic7xxx_match_scb(p
, scbp
, target
, channel
, lun
, tag
))
3783 aic_outb(p
, 0, SCB_CONTROL
);
3784 aic_outb(p
, SCB_LIST_NULL
, SCB_TAG
);
3785 aic7xxx_add_curscb_to_free_list(p
);
3792 * Go through the entire SCB array now and look for commands for
3793 * for this target that are stillactive. These are other (most likely
3794 * tagged) commands that were disconnected when the reset occurred.
3795 * Any commands we find here we know this about, it wasn't on any queue,
3796 * it wasn't in the qinfifo, it wasn't in the disconnected or waiting
3797 * lists, so it really must have been a paged out SCB. In that case,
3798 * we shouldn't need to bother with updating any counters, just mark
3799 * the correct flags and go on.
3801 for (i
= 0; i
< p
->scb_data
->numscbs
; i
++)
3803 scbp
= p
->scb_data
->scb_array
[i
];
3804 if ((scbp
->flags
& SCB_ACTIVE
) &&
3805 aic7xxx_match_scb(p
, scbp
, target
, channel
, lun
, tag
) &&
3806 !aic7xxx_scb_on_qoutfifo(p
, scbp
))
3808 if (scbp
->flags
& SCB_WAITINGQ
)
3810 scbq_remove(&p
->waiting_scbs
, scbp
);
3811 scbq_remove(&p
->delayed_scbs
[TARGET_INDEX(scbp
->cmd
)], scbp
);
3812 p
->dev_active_cmds
[TARGET_INDEX(scbp
->cmd
)]++;
3815 scbp
->flags
|= SCB_RESET
| SCB_QUEUED_FOR_DONE
;
3816 scbp
->flags
&= ~(SCB_ACTIVE
| SCB_WAITINGQ
);
3820 aic_outb(p
, active_scb
, SCBPTR
);
3824 /*+F*************************************************************************
3826 * aic7xxx_clear_intstat
3829 * Clears the interrupt status.
3830 *-F*************************************************************************/
3832 aic7xxx_clear_intstat(struct aic7xxx_host
*p
)
3834 /* Clear any interrupt conditions this may have caused. */
3835 aic_outb(p
, CLRSELDO
| CLRSELDI
| CLRSELINGO
, CLRSINT0
);
3836 aic_outb(p
, CLRSELTIMEO
| CLRATNO
| CLRSCSIRSTI
| CLRBUSFREE
| CLRSCSIPERR
|
3837 CLRPHASECHG
| CLRREQINIT
, CLRSINT1
);
3838 aic_outb(p
, CLRSCSIINT
| CLRSEQINT
| CLRBRKADRINT
| CLRPARERR
, CLRINT
);
3841 /*+F*************************************************************************
3843 * aic7xxx_reset_current_bus
3846 * Reset the current SCSI bus.
3847 *-F*************************************************************************/
3849 aic7xxx_reset_current_bus(struct aic7xxx_host
*p
)
3852 /* Disable reset interrupts. */
3853 aic_outb(p
, aic_inb(p
, SIMODE1
) & ~ENSCSIRST
, SIMODE1
);
3855 /* Turn off the bus' current operations, after all, we shouldn't have any
3856 * valid commands left to cause a RSELI and SELO once we've tossed the
3857 * bus away with this reset, so we might as well shut down the sequencer
3858 * until the bus is restarted as oppossed to saving the current settings
3859 * and restoring them (which makes no sense to me). */
3861 /* Turn on the bus reset. */
3862 aic_outb(p
, aic_inb(p
, SCSISEQ
) | SCSIRSTO
, SCSISEQ
);
3863 while ( (aic_inb(p
, SCSISEQ
) & SCSIRSTO
) == 0)
3868 /* Turn off the bus reset. */
3869 aic_outb(p
, 0, SCSISEQ
);
3872 aic7xxx_clear_intstat(p
);
3873 /* Re-enable reset interrupts. */
3874 aic_outb(p
, aic_inb(p
, SIMODE1
) | ENSCSIRST
, SIMODE1
);
3878 /*+F*************************************************************************
3880 * aic7xxx_reset_channel
3883 * Reset the channel.
3884 *-F*************************************************************************/
3886 aic7xxx_reset_channel(struct aic7xxx_host
*p
, int channel
, int initiate_reset
)
3888 unsigned long offset_min
, offset_max
;
3889 unsigned char sblkctl
;
3892 if (aic7xxx_verbose
& VERBOSE_RESET_PROCESS
)
3893 printk(INFO_LEAD
"Reset channel called, %s initiate reset.\n",
3894 p
->host_no
, channel
, -1, -1, (initiate_reset
==TRUE
) ? "will" : "won't" );
3899 p
->needsdtr
|= (p
->needsdtr_copy
& 0xFF00);
3900 p
->dtr_pending
&= 0x00FF;
3906 if (p
->features
& AHC_TWIN
)
3909 p
->needsdtr
|= (p
->needsdtr_copy
& 0x00FF);
3910 p
->dtr_pending
&= 0xFF00;
3916 p
->needppr
= p
->needppr_copy
;
3917 p
->needsdtr
= p
->needsdtr_copy
;
3918 p
->needwdtr
= p
->needwdtr_copy
;
3919 p
->dtr_pending
= 0x0;
3921 if (p
->features
& AHC_WIDE
)
3932 while (offset_min
< offset_max
)
3935 * Revert to async/narrow transfers until we renegotiate.
3937 aic_outb(p
, 0, TARG_SCSIRATE
+ offset_min
);
3938 if (p
->features
& AHC_ULTRA2
)
3940 aic_outb(p
, 0, TARG_OFFSET
+ offset_min
);
3946 * Reset the bus and unpause/restart the controller
3948 sblkctl
= aic_inb(p
, SBLKCTL
);
3949 if ( (p
->chip
& AHC_CHIPID_MASK
) == AHC_AIC7770
)
3950 cur_channel
= (sblkctl
& SELBUSB
) >> 3;
3953 if ( (cur_channel
!= channel
) && (p
->features
& AHC_TWIN
) )
3956 * Case 1: Command for another bus is active
3958 if (aic7xxx_verbose
& VERBOSE_RESET_PROCESS
)
3959 printk(INFO_LEAD
"Stealthily resetting idle channel.\n", p
->host_no
,
3962 * Stealthily reset the other bus without upsetting the current bus.
3964 aic_outb(p
, sblkctl
^ SELBUSB
, SBLKCTL
);
3965 aic_outb(p
, aic_inb(p
, SIMODE1
) & ~ENBUSFREE
, SIMODE1
);
3968 aic7xxx_reset_current_bus(p
);
3970 aic_outb(p
, aic_inb(p
, SCSISEQ
) & (ENSELI
|ENRSELI
|ENAUTOATNP
), SCSISEQ
);
3971 aic7xxx_clear_intstat(p
);
3972 aic_outb(p
, sblkctl
, SBLKCTL
);
3977 * Case 2: A command from this bus is active or we're idle.
3979 if (aic7xxx_verbose
& VERBOSE_RESET_PROCESS
)
3980 printk(INFO_LEAD
"Resetting currently active channel.\n", p
->host_no
,
3982 aic_outb(p
, aic_inb(p
, SIMODE1
) & ~(ENBUSFREE
|ENREQINIT
),
3984 p
->flags
&= ~AHC_HANDLING_REQINITS
;
3985 p
->msg_type
= MSG_TYPE_NONE
;
3989 aic7xxx_reset_current_bus(p
);
3991 aic_outb(p
, aic_inb(p
, SCSISEQ
) & (ENSELI
|ENRSELI
|ENAUTOATNP
), SCSISEQ
);
3992 aic7xxx_clear_intstat(p
);
3994 if (aic7xxx_verbose
& VERBOSE_RESET_RETURN
)
3995 printk(INFO_LEAD
"Channel reset\n", p
->host_no
, channel
, -1, -1);
3997 * Clean up all the state information for the pending transactions
4000 aic7xxx_reset_device(p
, ALL_TARGETS
, channel
, ALL_LUNS
, SCB_LIST_NULL
);
4002 if ( !(p
->features
& AHC_TWIN
) )
4004 restart_sequencer(p
);
4010 /*+F*************************************************************************
4012 * aic7xxx_run_waiting_queues
4015 * Scan the awaiting_scbs queue downloading and starting as many
4017 *-F*************************************************************************/
4019 aic7xxx_run_waiting_queues(struct aic7xxx_host
*p
)
4021 struct aic7xxx_scb
*scb
;
4024 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,1,95)
4025 unsigned long cpu_flags
= 0;
4029 if (p
->waiting_scbs
.head
== NULL
)
4035 * First handle SCBs that are waiting but have been assigned a slot.
4038 while ((scb
= scbq_remove_head(&p
->waiting_scbs
)) != NULL
)
4040 tindex
= TARGET_INDEX(scb
->cmd
);
4041 if ( !scb
->tag_action
&& (p
->tagenable
& (1<<tindex
)) )
4043 p
->dev_temp_queue_depth
[tindex
] = 1;
4045 if ( (p
->dev_active_cmds
[tindex
] >=
4046 p
->dev_temp_queue_depth
[tindex
]) ||
4047 (p
->dev_flags
[tindex
] & (DEVICE_RESET_DELAY
|DEVICE_WAS_BUSY
)) ||
4048 (p
->flags
& AHC_RESET_DELAY
) )
4050 scbq_insert_tail(&p
->delayed_scbs
[tindex
], scb
);
4054 scb
->flags
&= ~SCB_WAITINGQ
;
4055 p
->dev_active_cmds
[tindex
]++;
4057 if ( !(scb
->tag_action
) )
4059 aic7xxx_busy_target(p
, scb
);
4061 p
->qinfifo
[p
->qinfifonext
++] = scb
->hscb
->tag
;
4067 if (p
->features
& AHC_QUEUE_REGS
)
4068 aic_outb(p
, p
->qinfifonext
, HNSCB_QOFF
);
4072 aic_outb(p
, p
->qinfifonext
, KERNEL_QINPOS
);
4073 unpause_sequencer(p
, FALSE
);
4075 if (p
->activescbs
> p
->max_activescbs
)
4076 p
->max_activescbs
= p
->activescbs
;
4090 /*+F*************************************************************************
4095 * Check the scsi card for PCI errors and clear the interrupt
4097 * NOTE: If you don't have this function and a 2940 card encounters
4098 * a PCI error condition, the machine will end up locked as the
4099 * interrupt handler gets slammed with non-stop PCI error interrupts
4100 *-F*************************************************************************/
4102 aic7xxx_pci_intr(struct aic7xxx_host
*p
)
4104 unsigned char status1
;
4106 #if LINUX_VERSION_CODE > KERNEL_VERSION(2,1,92)
4107 pci_read_config_byte(p
->pdev
, PCI_STATUS
+ 1, &status1
);
4109 pcibios_read_config_byte(p
->pci_bus
, p
->pci_device_fn
,
4110 PCI_STATUS
+ 1, &status1
);
4113 if ( (status1
& DPE
) && (aic7xxx_verbose
& VERBOSE_MINOR_ERROR
) )
4114 printk(WARN_LEAD
"Data Parity Error during PCI address or PCI write"
4115 "phase.\n", p
->host_no
, -1, -1, -1);
4116 if ( (status1
& SSE
) && (aic7xxx_verbose
& VERBOSE_MINOR_ERROR
) )
4117 printk(WARN_LEAD
"Signal System Error Detected\n", p
->host_no
,
4119 if ( (status1
& RMA
) && (aic7xxx_verbose
& VERBOSE_MINOR_ERROR
) )
4120 printk(WARN_LEAD
"Received a PCI Master Abort\n", p
->host_no
,
4122 if ( (status1
& RTA
) && (aic7xxx_verbose
& VERBOSE_MINOR_ERROR
) )
4123 printk(WARN_LEAD
"Received a PCI Target Abort\n", p
->host_no
,
4125 if ( (status1
& STA
) && (aic7xxx_verbose
& VERBOSE_MINOR_ERROR
) )
4126 printk(WARN_LEAD
"Signaled a PCI Target Abort\n", p
->host_no
,
4128 if ( (status1
& DPR
) && (aic7xxx_verbose
& VERBOSE_MINOR_ERROR
) )
4129 printk(WARN_LEAD
"Data Parity Error has been reported via PCI pin "
4130 "PERR#\n", p
->host_no
, -1, -1, -1);
4132 #if LINUX_VERSION_CODE > KERNEL_VERSION(2,1,92)
4133 pci_write_config_byte(p
->pdev
, PCI_STATUS
+ 1, status1
);
4135 pcibios_write_config_byte(p
->pci_bus
, p
->pci_device_fn
,
4136 PCI_STATUS
+ 1, status1
);
4138 if (status1
& (DPR
|RMA
|RTA
))
4139 aic_outb(p
, CLRPARERR
, CLRINT
);
4141 if ( (aic7xxx_panic_on_abort
) && (p
->spurious_int
> 500) )
4142 aic7xxx_panic_abort(p
, NULL
);
4145 #endif /* CONFIG_PCI */
4147 /*+F*************************************************************************
4152 * Take expired extries off of delayed queues and place on waiting queue
4153 * then run waiting queue to start commands.
4154 ***************************************************************************/
4156 aic7xxx_timer(struct aic7xxx_host
*p
)
4159 unsigned long cpu_flags
= 0;
4160 struct aic7xxx_scb
*scb
;
4162 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,1,95)
4165 spin_lock_irqsave(&io_request_lock
, cpu_flags
);
4167 p
->dev_timer_active
&= ~(0x01 << MAX_TARGETS
);
4168 if ( (p
->dev_timer_active
& (0x01 << p
->scsi_id
)) &&
4169 time_after_eq(jiffies
, p
->dev_expires
[p
->scsi_id
]) )
4171 p
->flags
&= ~AHC_RESET_DELAY
;
4172 p
->dev_timer_active
&= ~(0x01 << p
->scsi_id
);
4174 for(i
=0; i
<MAX_TARGETS
; i
++)
4176 if ( (i
!= p
->scsi_id
) &&
4177 (p
->dev_timer_active
& (0x01 << i
)) &&
4178 time_after_eq(jiffies
, p
->dev_expires
[i
]) )
4180 p
->dev_timer_active
&= ~(0x01 << i
);
4181 p
->dev_flags
[i
] &= ~(DEVICE_RESET_DELAY
|DEVICE_WAS_BUSY
);
4182 p
->dev_temp_queue_depth
[i
] = p
->dev_max_queue_depth
[i
];
4184 while ( ((scb
= scbq_remove_head(&p
->delayed_scbs
[i
])) != NULL
) &&
4185 (j
++ < p
->scb_data
->numscbs
) )
4187 scbq_insert_tail(&p
->waiting_scbs
, scb
);
4189 if (j
== p
->scb_data
->numscbs
)
4191 printk(INFO_LEAD
"timer: Yikes, loop in delayed_scbs list.\n",
4192 p
->host_no
, 0, i
, -1);
4193 scbq_init(&p
->delayed_scbs
[i
]);
4194 scbq_init(&p
->waiting_scbs
);
4196 * Well, things are screwed now, wait for a reset to clean the junk
4201 else if ( p
->dev_timer_active
& (0x01 << i
) )
4203 if ( p
->dev_timer_active
& (0x01 << MAX_TARGETS
) )
4205 if ( time_after_eq(p
->dev_timer
.expires
, p
->dev_expires
[i
]) )
4207 p
->dev_timer
.expires
= p
->dev_expires
[i
];
4212 p
->dev_timer
.expires
= p
->dev_expires
[i
];
4213 p
->dev_timer_active
|= (0x01 << MAX_TARGETS
);
4217 if ( p
->dev_timer_active
& (0x01 << MAX_TARGETS
) )
4219 add_timer(&p
->dev_timer
);
4222 aic7xxx_run_waiting_queues(p
);
4223 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,1,95)
4226 spin_unlock_irqrestore(&io_request_lock
, cpu_flags
);
4230 /*+F*************************************************************************
4232 * aic7xxx_construct_ppr
4235 * Build up a Parallel Protocol Request message for use with SCSI-3
4237 *-F*************************************************************************/
4239 aic7xxx_construct_ppr(struct aic7xxx_host
*p
, struct aic7xxx_scb
*scb
)
4241 int tindex
= TARGET_INDEX(scb
->cmd
);
4243 p
->msg_buf
[p
->msg_index
++] = MSG_EXTENDED
;
4244 p
->msg_buf
[p
->msg_index
++] = MSG_EXT_PPR_LEN
;
4245 p
->msg_buf
[p
->msg_index
++] = MSG_EXT_PPR
;
4246 p
->msg_buf
[p
->msg_index
++] = p
->transinfo
[tindex
].goal_period
;
4247 p
->msg_buf
[p
->msg_index
++] = 0;
4248 p
->msg_buf
[p
->msg_index
++] = p
->transinfo
[tindex
].goal_offset
;
4249 p
->msg_buf
[p
->msg_index
++] = p
->transinfo
[tindex
].goal_width
;
4250 p
->msg_buf
[p
->msg_index
++] = p
->transinfo
[tindex
].goal_options
;
4254 /*+F*************************************************************************
4256 * aic7xxx_construct_sdtr
4259 * Constucts a synchronous data transfer message in the message
4260 * buffer on the sequencer.
4261 *-F*************************************************************************/
4263 aic7xxx_construct_sdtr(struct aic7xxx_host
*p
, unsigned char period
,
4264 unsigned char offset
)
4266 p
->msg_buf
[p
->msg_index
++] = MSG_EXTENDED
;
4267 p
->msg_buf
[p
->msg_index
++] = MSG_EXT_SDTR_LEN
;
4268 p
->msg_buf
[p
->msg_index
++] = MSG_EXT_SDTR
;
4269 p
->msg_buf
[p
->msg_index
++] = period
;
4270 p
->msg_buf
[p
->msg_index
++] = offset
;
4274 /*+F*************************************************************************
4276 * aic7xxx_construct_wdtr
4279 * Constucts a wide data transfer message in the message buffer
4281 *-F*************************************************************************/
4283 aic7xxx_construct_wdtr(struct aic7xxx_host
*p
, unsigned char bus_width
)
4285 p
->msg_buf
[p
->msg_index
++] = MSG_EXTENDED
;
4286 p
->msg_buf
[p
->msg_index
++] = MSG_EXT_WDTR_LEN
;
4287 p
->msg_buf
[p
->msg_index
++] = MSG_EXT_WDTR
;
4288 p
->msg_buf
[p
->msg_index
++] = bus_width
;
4292 /*+F*************************************************************************
4294 * aic7xxx_calc_residual
4297 * Calculate the residual data not yet transferred.
4298 *-F*************************************************************************/
4300 aic7xxx_calculate_residual (struct aic7xxx_host
*p
, struct aic7xxx_scb
*scb
)
4302 struct aic7xxx_hwscb
*hscb
;
4310 * Don't destroy valid residual information with
4311 * residual coming from a check sense operation.
4313 if (((scb
->hscb
->control
& DISCONNECTED
) == 0) &&
4314 (scb
->flags
& SCB_SENSE
) == 0)
4317 * We had an underflow. At this time, there's only
4318 * one other driver that bothers to check for this,
4319 * and cmd->underflow seems to be set rather half-
4320 * heartedly in the higher-level SCSI code.
4322 actual
= scb
->sg_length
;
4323 for (i
=1; i
< hscb
->residual_SG_segment_count
; i
++)
4325 actual
-= scb
->sg_list
[scb
->sg_count
- i
].length
;
4327 actual
-= (hscb
->residual_data_count
[2] << 16) |
4328 (hscb
->residual_data_count
[1] << 8) |
4329 hscb
->residual_data_count
[0];
4331 if (actual
< cmd
->underflow
)
4333 if (aic7xxx_verbose
& VERBOSE_MINOR_ERROR
)
4334 printk(INFO_LEAD
"Underflow - Wanted %u, %s %u, residual SG "
4335 "count %d.\n", p
->host_no
, CTL_OF_SCB(scb
), cmd
->underflow
,
4336 (cmd
->request
.cmd
== WRITE
) ? "wrote" : "read", actual
,
4337 hscb
->residual_SG_segment_count
);
4338 aic7xxx_error(cmd
) = DID_RETRY_COMMAND
;
4339 aic7xxx_status(cmd
) = hscb
->target_status
;
4344 * Clean out the residual information in the SCB for the
4347 hscb
->residual_data_count
[2] = 0;
4348 hscb
->residual_data_count
[1] = 0;
4349 hscb
->residual_data_count
[0] = 0;
4350 hscb
->residual_SG_segment_count
= 0;
4353 /*+F*************************************************************************
4355 * aic7xxx_handle_device_reset
4358 * Interrupt handler for sequencer interrupts (SEQINT).
4359 *-F*************************************************************************/
4361 aic7xxx_handle_device_reset(struct aic7xxx_host
*p
, int target
, int channel
)
4363 unsigned short targ_mask
;
4364 unsigned char tindex
= target
;
4366 tindex
|= ((channel
& 0x01) << 3);
4368 targ_mask
= (0x01 << tindex
);
4370 * Go back to async/narrow transfers and renegotiate.
4372 p
->needppr
|= (p
->needppr_copy
& targ_mask
);
4373 p
->needsdtr
|= (p
->needsdtr_copy
& targ_mask
);
4374 p
->needwdtr
|= (p
->needwdtr_copy
& targ_mask
);
4375 p
->dtr_pending
&= ~targ_mask
;
4376 aic_outb(p
, 0, TARG_SCSIRATE
+ tindex
);
4377 if (p
->features
& AHC_ULTRA2
)
4378 aic_outb(p
, 0, TARG_OFFSET
+ tindex
);
4379 aic7xxx_reset_device(p
, target
, channel
, ALL_LUNS
, SCB_LIST_NULL
);
4380 if (aic7xxx_verbose
& VERBOSE_RESET_PROCESS
)
4381 printk(INFO_LEAD
"Bus Device Reset delivered.\n", p
->host_no
, channel
,
4383 aic7xxx_run_done_queue(p
, /*complete*/ TRUE
);
4386 /*+F*************************************************************************
4388 * aic7xxx_handle_seqint
4391 * Interrupt handler for sequencer interrupts (SEQINT).
4392 *-F*************************************************************************/
4394 aic7xxx_handle_seqint(struct aic7xxx_host
*p
, unsigned char intstat
)
4396 struct aic7xxx_scb
*scb
;
4397 unsigned short target_mask
;
4398 unsigned char target
, lun
, tindex
;
4399 unsigned char queue_flag
= FALSE
;
4402 target
= ((aic_inb(p
, SAVED_TCL
) >> 4) & 0x0f);
4403 if ( (p
->chip
& AHC_CHIPID_MASK
) == AHC_AIC7770
)
4404 channel
= (aic_inb(p
, SBLKCTL
) & SELBUSB
) >> 3;
4407 tindex
= target
+ (channel
<< 3);
4408 lun
= aic_inb(p
, SAVED_TCL
) & 0x07;
4409 target_mask
= (0x01 << tindex
);
4412 * Go ahead and clear the SEQINT now, that avoids any interrupt race
4413 * conditions later on in case we enable some other interrupt.
4415 aic_outb(p
, CLRSEQINT
, CLRINT
);
4416 switch (intstat
& SEQINT_MASK
)
4420 aic_outb(p
, aic_inb(p
, SCSISEQ
) & (ENSELI
|ENRSELI
|ENAUTOATNP
),
4422 printk(WARN_LEAD
"No active SCB for reconnecting target - Issuing "
4423 "BUS DEVICE RESET.\n", p
->host_no
, channel
, target
, lun
);
4424 printk(WARN_LEAD
" SAVED_TCL=0x%x, ARG_1=0x%x, SEQADDR=0x%x\n",
4425 p
->host_no
, channel
, target
, lun
,
4426 aic_inb(p
, SAVED_TCL
), aic_inb(p
, ARG_1
),
4427 (aic_inb(p
, SEQADDR1
) << 8) | aic_inb(p
, SEQADDR0
));
4428 if (aic7xxx_panic_on_abort
)
4429 aic7xxx_panic_abort(p
, NULL
);
4435 if (aic7xxx_verbose
& VERBOSE_MINOR_ERROR
)
4436 printk(INFO_LEAD
"Rejecting unknown message (0x%x) received from "
4437 "target, SEQ_FLAGS=0x%x\n", p
->host_no
, channel
, target
, lun
,
4438 aic_inb(p
, ACCUM
), aic_inb(p
, SEQ_FLAGS
));
4445 * The reconnecting target either did not send an identify
4446 * message, or did, but we didn't find an SCB to match and
4447 * before it could respond to our ATN/abort, it hit a dataphase.
4448 * The only safe thing to do is to blow it away with a bus
4451 if (aic7xxx_verbose
& (VERBOSE_SEQINT
| VERBOSE_RESET_MID
))
4452 printk(INFO_LEAD
"Target did not send an IDENTIFY message; "
4453 "LASTPHASE 0x%x, SAVED_TCL 0x%x\n", p
->host_no
, channel
, target
,
4454 lun
, aic_inb(p
, LASTPHASE
), aic_inb(p
, SAVED_TCL
));
4456 aic7xxx_reset_channel(p
, channel
, /*initiate reset*/ TRUE
);
4457 aic7xxx_run_done_queue(p
, TRUE
);
4463 if (aic_inb(p
, LASTPHASE
) == P_BUSFREE
)
4465 if (aic7xxx_verbose
& VERBOSE_SEQINT
)
4466 printk(INFO_LEAD
"Missed busfree.\n", p
->host_no
, channel
,
4468 restart_sequencer(p
);
4472 if (aic7xxx_verbose
& VERBOSE_SEQINT
)
4473 printk(INFO_LEAD
"Unknown scsi bus phase, continuing\n", p
->host_no
,
4474 channel
, target
, lun
);
4480 p
->msg_type
= MSG_TYPE_INITIATOR_MSGIN
;
4484 #ifdef AIC7XXX_VERBOSE_DEBUGGING
4485 if (aic7xxx_verbose
> 0xffff)
4486 printk(INFO_LEAD
"Enabling REQINITs for MSG_IN\n", p
->host_no
,
4487 channel
, target
, lun
);
4491 * To actually receive the message, simply turn on
4492 * REQINIT interrupts and let our interrupt handler
4493 * do the rest (REQINIT should already be true).
4495 p
->flags
|= AHC_HANDLING_REQINITS
;
4496 aic_outb(p
, aic_inb(p
, SIMODE1
) | ENREQINIT
, SIMODE1
);
4499 * We don't want the sequencer unpaused yet so we return early
4507 * What we care about here is if we had an outstanding SDTR
4508 * or WDTR message for this target. If we did, this is a
4509 * signal that the target is refusing negotiation.
4511 unsigned char scb_index
;
4512 unsigned char last_msg
;
4514 scb_index
= aic_inb(p
, SCB_TAG
);
4515 scb
= p
->scb_data
->scb_array
[scb_index
];
4516 last_msg
= aic_inb(p
, LAST_MSG
);
4518 if ( (last_msg
== MSG_IDENTIFYFLAG
) &&
4519 (scb
->tag_action
) &&
4520 !(scb
->flags
& SCB_MSGOUT_BITS
) )
4522 if (scb
->tag_action
== MSG_ORDERED_Q_TAG
)
4525 * OK...the device seems able to accept tagged commands, but
4526 * not ordered tag commands, only simple tag commands. So, we
4527 * disable ordered tag commands and go on with life just like
4530 p
->orderedtag
&= ~target_mask
;
4531 scb
->tag_action
= MSG_SIMPLE_Q_TAG
;
4532 scb
->hscb
->control
&= ~SCB_TAG_TYPE
;
4533 scb
->hscb
->control
|= MSG_SIMPLE_Q_TAG
;
4534 aic_outb(p
, scb
->hscb
->control
, SCB_CONTROL
);
4536 * OK..we set the tag type to simple tag command, now we re-assert
4537 * ATNO and hope this will take us into the identify phase again
4538 * so we can resend the tag type and info to the device.
4540 aic_outb(p
, MSG_IDENTIFYFLAG
, MSG_OUT
);
4541 aic_outb(p
, aic_inb(p
, SCSISIGI
) | ATNO
, SCSISIGO
);
4543 else if (scb
->tag_action
== MSG_SIMPLE_Q_TAG
)
4545 unsigned char i
, reset
= 0;
4546 struct aic7xxx_scb
*scbp
;
4549 * Hmmmm....the device is flaking out on tagged commands. The
4550 * bad thing is that we already have tagged commands enabled in
4551 * the device struct in the mid level code. We also have a queue
4552 * set according to the tagged queue depth. Gonna have to live
4553 * with it by controlling our queue depth internally and making
4554 * sure we don't set the tagged command flag any more.
4556 p
->tagenable
&= ~target_mask
;
4557 p
->orderedtag
&= ~target_mask
;
4558 p
->dev_max_queue_depth
[tindex
] =
4559 p
->dev_temp_queue_depth
[tindex
] = 1;
4561 * We set this command up as a bus device reset. However, we have
4562 * to clear the tag type as it's causing us problems. We shouldnt
4563 * have to worry about any other commands being active, since if
4564 * the device is refusing tagged commands, this should be the
4565 * first tagged command sent to the device, however, we do have
4566 * to worry about any other tagged commands that may already be
4567 * in the qinfifo. The easiest way to do this, is to issue a BDR,
4568 * send all the commands back to the mid level code, then let them
4569 * come back and get rebuilt as untagged commands.
4571 scb
->tag_action
= 0;
4572 scb
->hscb
->control
&= ~(TAG_ENB
| SCB_TAG_TYPE
);
4573 aic_outb(p
, scb
->hscb
->control
, SCB_CONTROL
);
4575 old_verbose
= aic7xxx_verbose
;
4576 aic7xxx_verbose
&= ~(VERBOSE_RESET
|VERBOSE_ABORT
);
4577 for (i
=0; i
!=p
->scb_data
->numscbs
; i
++)
4579 scbp
= p
->scb_data
->scb_array
[i
];
4580 if ((scbp
->flags
& SCB_ACTIVE
) && (scbp
!= scb
))
4582 if (aic7xxx_match_scb(p
, scbp
, target
, channel
, lun
, i
))
4584 aic7xxx_reset_device(p
, target
, channel
, lun
, i
);
4587 aic7xxx_run_done_queue(p
, TRUE
);
4590 aic7xxx_verbose
= old_verbose
;
4592 * Wait until after the for loop to set the busy index since
4593 * aic7xxx_reset_device will clear the busy index during its
4596 aic7xxx_busy_target(p
, scb
);
4597 printk(INFO_LEAD
"Device is refusing tagged commands, using "
4598 "untagged I/O.\n", p
->host_no
, channel
, target
, lun
);
4599 aic_outb(p
, MSG_IDENTIFYFLAG
, MSG_OUT
);
4600 aic_outb(p
, aic_inb(p
, SCSISIGI
) | ATNO
, SCSISIGO
);
4603 else if (scb
->flags
& SCB_MSGOUT_PPR
)
4606 * As per the draft specs, any device capable of supporting any of
4607 * the option values other than 0 are not allowed to reject the
4608 * PPR message. Instead, they must negotiate out what they do
4609 * support instead of rejecting our offering.
4611 p
->needppr
&= ~target_mask
;
4612 p
->needppr_copy
&= ~target_mask
;
4613 aic7xxx_set_width(p
, target
, channel
, lun
, MSG_EXT_WDTR_BUS_8_BIT
,
4614 (AHC_TRANS_ACTIVE
|AHC_TRANS_CUR
|AHC_TRANS_QUITE
));
4615 aic7xxx_set_syncrate(p
, NULL
, target
, channel
, 0, 0, 0,
4616 AHC_TRANS_ACTIVE
|AHC_TRANS_CUR
|AHC_TRANS_QUITE
);
4617 p
->transinfo
[tindex
].goal_options
= 0;
4618 p
->dtr_pending
&= ~target_mask
;
4619 scb
->flags
&= ~SCB_MSGOUT_BITS
;
4620 if(aic7xxx_verbose
& VERBOSE_NEGOTIATION2
)
4622 printk(INFO_LEAD
"Device is rejecting PPR messages, falling "
4623 "back.\n", p
->host_no
, channel
, target
, lun
);
4625 if ( p
->transinfo
[tindex
].goal_width
)
4627 p
->needwdtr
|= target_mask
;
4628 p
->needwdtr_copy
|= target_mask
;
4629 p
->dtr_pending
|= target_mask
;
4630 scb
->flags
|= SCB_MSGOUT_WDTR
;
4632 if ( p
->transinfo
[tindex
].goal_offset
)
4634 p
->needsdtr
|= target_mask
;
4635 p
->needsdtr_copy
|= target_mask
;
4636 if( !(p
->dtr_pending
& target_mask
) )
4638 p
->dtr_pending
|= target_mask
;
4639 scb
->flags
|= SCB_MSGOUT_SDTR
;
4642 if ( p
->dtr_pending
& target_mask
)
4644 aic_outb(p
, HOST_MSG
, MSG_OUT
);
4645 aic_outb(p
, aic_inb(p
, SCSISIGI
) | ATNO
, SCSISIGO
);
4648 else if (scb
->flags
& SCB_MSGOUT_WDTR
)
4651 * note 8bit xfers and clear flag
4653 p
->needwdtr
&= ~target_mask
;
4654 p
->needwdtr_copy
&= ~target_mask
;
4655 p
->dtr_pending
&= ~target_mask
;
4656 scb
->flags
&= ~SCB_MSGOUT_BITS
;
4657 aic7xxx_set_width(p
, target
, channel
, lun
, MSG_EXT_WDTR_BUS_8_BIT
,
4658 (AHC_TRANS_ACTIVE
|AHC_TRANS_GOAL
|AHC_TRANS_CUR
));
4659 aic7xxx_set_syncrate(p
, NULL
, target
, channel
, 0, 0, 0,
4660 AHC_TRANS_ACTIVE
|AHC_TRANS_CUR
|AHC_TRANS_QUITE
);
4661 if(aic7xxx_verbose
& VERBOSE_NEGOTIATION2
)
4663 printk(INFO_LEAD
"Device is rejecting WDTR messages, using "
4664 "narrow transfers.\n", p
->host_no
, channel
, target
, lun
);
4666 p
->needsdtr
|= (p
->needsdtr_copy
& target_mask
);
4668 else if (scb
->flags
& SCB_MSGOUT_SDTR
)
4671 * note asynch xfers and clear flag
4673 p
->needsdtr
&= ~target_mask
;
4674 p
->needsdtr_copy
&= ~target_mask
;
4675 p
->dtr_pending
&= ~target_mask
;
4676 scb
->flags
&= ~SCB_MSGOUT_SDTR
;
4677 aic7xxx_set_syncrate(p
, NULL
, target
, channel
, 0, 0, 0,
4678 (AHC_TRANS_CUR
|AHC_TRANS_ACTIVE
|AHC_TRANS_GOAL
));
4679 if(aic7xxx_verbose
& VERBOSE_NEGOTIATION2
)
4681 printk(INFO_LEAD
"Device is rejecting SDTR messages, using "
4682 "async transfers.\n", p
->host_no
, channel
, target
, lun
);
4685 else if (aic7xxx_verbose
& VERBOSE_SEQINT
)
4688 * Otherwise, we ignore it.
4690 printk(INFO_LEAD
"Received MESSAGE_REJECT for unknown cause. "
4691 "Ignoring.\n", p
->host_no
, channel
, target
, lun
);
4698 unsigned char scb_index
;
4699 struct aic7xxx_hwscb
*hscb
;
4702 /* The sequencer will notify us when a command has an error that
4703 * would be of interest to the kernel. This allows us to leave
4704 * the sequencer running in the common case of command completes
4705 * without error. The sequencer will have DMA'd the SCB back
4706 * up to us, so we can reference the drivers SCB array.
4708 * Set the default return value to 0 indicating not to send
4709 * sense. The sense code will change this if needed and this
4710 * reduces code duplication.
4712 aic_outb(p
, 0, RETURN_1
);
4713 scb_index
= aic_inb(p
, SCB_TAG
);
4714 if (scb_index
> p
->scb_data
->numscbs
)
4716 printk(WARN_LEAD
"Invalid SCB during SEQINT 0x%02x, SCB_TAG %d.\n",
4717 p
->host_no
, channel
, target
, lun
, intstat
, scb_index
);
4720 scb
= p
->scb_data
->scb_array
[scb_index
];
4723 if (!(scb
->flags
& SCB_ACTIVE
) || (scb
->cmd
== NULL
))
4725 printk(WARN_LEAD
"Invalid SCB during SEQINT 0x%x, scb %d, flags 0x%x,"
4726 " cmd 0x%lx.\n", p
->host_no
, channel
, target
, lun
, intstat
,
4727 scb_index
, scb
->flags
, (unsigned long) scb
->cmd
);
4732 hscb
->target_status
= aic_inb(p
, SCB_TARGET_STATUS
);
4733 aic7xxx_status(cmd
) = hscb
->target_status
;
4735 cmd
->result
= hscb
->target_status
;
4737 switch (status_byte(hscb
->target_status
))
4740 if (aic7xxx_verbose
& VERBOSE_SEQINT
)
4741 printk(INFO_LEAD
"Interrupted for status of GOOD???\n",
4742 p
->host_no
, CTL_OF_SCB(scb
));
4745 case COMMAND_TERMINATED
:
4746 case CHECK_CONDITION
:
4747 if ( !(scb
->flags
& SCB_SENSE
) )
4750 * XXX - How do we save the residual (if there is one).
4752 if ( hscb
->residual_SG_segment_count
!= 0 )
4753 aic7xxx_calculate_residual(p
, scb
);
4756 * Send a sense command to the requesting target.
4757 * XXX - revisit this and get rid of the memcopys.
4759 memcpy(&scb
->sense_cmd
[0], &generic_sense
[0],
4760 sizeof(generic_sense
));
4762 scb
->sense_cmd
[1] = (cmd
->lun
<< 5);
4763 scb
->sense_cmd
[4] = sizeof(cmd
->sense_buffer
);
4765 scb
->sg_list
[0].address
=
4766 cpu_to_le32(VIRT_TO_BUS(&cmd
->sense_buffer
[0]));
4767 scb
->sg_list
[0].length
=
4768 cpu_to_le32(sizeof(cmd
->sense_buffer
));
4771 * XXX - We should allow disconnection, but can't as it
4772 * might allow overlapped tagged commands.
4774 /* hscb->control &= DISCENB; */
4776 hscb
->target_status
= 0;
4777 hscb
->SG_list_pointer
=
4778 cpu_to_le32(VIRT_TO_BUS(&scb
->sg_list
[0]));
4779 hscb
->data_pointer
= scb
->sg_list
[0].address
;
4780 hscb
->data_count
= scb
->sg_list
[0].length
;
4781 hscb
->SCSI_cmd_pointer
=
4782 cpu_to_le32(VIRT_TO_BUS(&scb
->sense_cmd
[0]));
4783 hscb
->SCSI_cmd_length
= COMMAND_SIZE(scb
->sense_cmd
[0]);
4784 hscb
->residual_SG_segment_count
= 0;
4785 hscb
->residual_data_count
[0] = 0;
4786 hscb
->residual_data_count
[1] = 0;
4787 hscb
->residual_data_count
[2] = 0;
4789 scb
->sg_count
= hscb
->SG_segment_count
= 1;
4790 scb
->sg_length
= sizeof(cmd
->sense_buffer
);
4791 scb
->tag_action
= 0;
4793 * This problem could be caused if the target has lost power
4794 * or found some other way to loose the negotiation settings,
4795 * so if needed, we'll re-negotiate while doing the sense cmd.
4796 * However, if this SCB already was attempting to negotiate,
4797 * then we assume this isn't the problem and skip this part.
4799 if ( (scb
->cmd
->cmnd
[0] != TEST_UNIT_READY
) &&
4800 (p
->dev_flags
[tindex
] & DEVICE_SCANNED
) &&
4801 !(p
->dtr_pending
& target_mask
) )
4803 p
->needppr
|= (p
->needppr_copy
& target_mask
);
4804 p
->needwdtr
|= (p
->needwdtr_copy
& target_mask
);
4805 p
->needsdtr
|= (p
->needsdtr_copy
& target_mask
);
4807 else if ( scb
->cmd
== p
->dev_dtr_cmnd
[tindex
] )
4810 * This is already a negotiation command, so we must have
4811 * already done PPR, WDTR or SDTR. Since our negotiation
4812 * could have gotten rejected, we don't really know the
4813 * full state of things. Don't do anything here, and allow
4814 * the negotiation_complete() handler to do the right
4819 * This is the important part though. We are getting sense
4820 * info back from this device. It's going into a fake
4821 * command. We need to put that into the real command
4822 * instead so that the mid level SCSI code can act upon it.
4823 * So, when we set up these fake commands, the next pointer
4824 * is used to point to the real command. Use that to change
4825 * the address of our sense_buffer[] to the real command.
4826 * However, don't do this if the real command is also a
4827 * TEST_UNIT_READY as it will most likely pull down its own
4828 * SENSE information anyway.
4830 if (cmd
->next
->cmnd
[0] != TEST_UNIT_READY
)
4832 scb
->sg_list
[0].address
=
4833 cpu_to_le32(VIRT_TO_BUS(&cmd
->next
->sense_buffer
[0]));
4834 hscb
->data_pointer
= scb
->sg_list
[0].address
;
4837 scb
->flags
|= SCB_SENSE
;
4839 * Ensure the target is busy since this will be an
4840 * an untagged request.
4842 #ifdef AIC7XXX_VERBOSE_DEBUGGING
4843 if (aic7xxx_verbose
& VERBOSE_NEGOTIATION2
)
4845 if (scb
->flags
& SCB_MSGOUT_BITS
)
4846 printk(INFO_LEAD
"Requesting SENSE with %s\n", p
->host_no
,
4847 CTL_OF_SCB(scb
), (scb
->flags
& SCB_MSGOUT_SDTR
) ?
4850 printk(INFO_LEAD
"Requesting SENSE, no MSG\n", p
->host_no
,
4854 aic7xxx_busy_target(p
, scb
);
4855 aic_outb(p
, SEND_SENSE
, RETURN_1
);
4856 aic7xxx_error(cmd
) = DID_OK
;
4858 } /* first time sense, no errors */
4859 aic7xxx_error(cmd
) = DID_OK
;
4860 scb
->flags
&= ~SCB_SENSE
;
4864 queue_flag
= TRUE
; /* Mark that this is a QUEUE_FULL and */
4865 case BUSY
: /* drop through to here */
4867 struct aic7xxx_scb
*next_scbp
, *prev_scbp
;
4868 unsigned char active_hscb
, next_hscb
, prev_hscb
, scb_index
;
4870 * We have to look three places for queued commands:
4872 * 2: p->waiting_scbs queue
4873 * 3: WAITING_SCBS list on card (for commands that are started
4874 * but haven't yet made it to the device)
4876 aic7xxx_search_qinfifo(p
, target
, channel
, lun
,
4877 SCB_LIST_NULL
, 0, TRUE
,
4878 &p
->delayed_scbs
[tindex
]);
4879 next_scbp
= p
->waiting_scbs
.head
;
4880 while ( next_scbp
!= NULL
)
4882 prev_scbp
= next_scbp
;
4883 next_scbp
= next_scbp
->q_next
;
4884 if ( aic7xxx_match_scb(p
, prev_scbp
, target
, channel
, lun
,
4887 scbq_remove(&p
->waiting_scbs
, prev_scbp
);
4888 scbq_insert_tail(&p
->delayed_scbs
[tindex
],
4893 active_hscb
= aic_inb(p
, SCBPTR
);
4894 prev_hscb
= next_hscb
= scb_index
= SCB_LIST_NULL
;
4895 next_hscb
= aic_inb(p
, WAITING_SCBH
);
4896 while (next_hscb
!= SCB_LIST_NULL
)
4898 aic_outb(p
, next_hscb
, SCBPTR
);
4899 scb_index
= aic_inb(p
, SCB_TAG
);
4900 if (scb_index
< p
->scb_data
->numscbs
)
4902 next_scbp
= p
->scb_data
->scb_array
[scb_index
];
4903 if (aic7xxx_match_scb(p
, next_scbp
, target
, channel
, lun
,
4906 if (next_scbp
->flags
& SCB_WAITINGQ
)
4908 p
->dev_active_cmds
[tindex
]++;
4910 scbq_remove(&p
->delayed_scbs
[tindex
], next_scbp
);
4911 scbq_remove(&p
->waiting_scbs
, next_scbp
);
4913 scbq_insert_head(&p
->delayed_scbs
[tindex
],
4915 next_scbp
->flags
|= SCB_WAITINGQ
;
4916 p
->dev_active_cmds
[tindex
]--;
4918 next_hscb
= aic_inb(p
, SCB_NEXT
);
4919 aic_outb(p
, 0, SCB_CONTROL
);
4920 aic_outb(p
, SCB_LIST_NULL
, SCB_TAG
);
4921 aic7xxx_add_curscb_to_free_list(p
);
4922 if (prev_hscb
== SCB_LIST_NULL
)
4924 /* We were first on the list,
4925 * so we kill the selection
4926 * hardware. Let the sequencer
4927 * re-init the hardware itself
4929 aic_outb(p
, aic_inb(p
, SCSISEQ
) & ~ENSELO
, SCSISEQ
);
4930 aic_outb(p
, CLRSELTIMEO
, CLRSINT1
);
4931 aic_outb(p
, next_hscb
, WAITING_SCBH
);
4935 aic_outb(p
, prev_hscb
, SCBPTR
);
4936 aic_outb(p
, next_hscb
, SCB_NEXT
);
4941 prev_hscb
= next_hscb
;
4942 next_hscb
= aic_inb(p
, SCB_NEXT
);
4944 } /* scb_index >= p->scb_data->numscbs */
4946 aic_outb(p
, active_hscb
, SCBPTR
);
4947 if (scb
->flags
& SCB_WAITINGQ
)
4949 scbq_remove(&p
->delayed_scbs
[tindex
], scb
);
4950 scbq_remove(&p
->waiting_scbs
, scb
);
4951 p
->dev_active_cmds
[tindex
]++;
4954 scbq_insert_head(&p
->delayed_scbs
[tindex
], scb
);
4955 p
->dev_active_cmds
[tindex
]--;
4957 scb
->flags
|= SCB_WAITINGQ
| SCB_WAS_BUSY
;
4959 if ( !(p
->dev_timer_active
& (0x01 << tindex
)) )
4961 p
->dev_timer_active
|= (0x01 << tindex
);
4962 if ( p
->dev_active_cmds
[tindex
] )
4964 p
->dev_expires
[tindex
] = jiffies
+ HZ
;
4968 p
->dev_expires
[tindex
] = jiffies
+ (HZ
/ 10);
4970 if ( !(p
->dev_timer_active
& (0x01 << MAX_TARGETS
)) )
4972 p
->dev_timer
.expires
= p
->dev_expires
[tindex
];
4973 p
->dev_timer_active
|= (0x01 << MAX_TARGETS
);
4974 add_timer(&p
->dev_timer
);
4976 else if ( time_after_eq(p
->dev_timer
.expires
,
4977 p
->dev_expires
[tindex
]) )
4979 del_timer(&p
->dev_timer
);
4980 p
->dev_timer
.expires
= p
->dev_expires
[tindex
];
4981 add_timer(&p
->dev_timer
);
4984 #ifdef AIC7XXX_VERBOSE_DEBUGGING
4985 if( (aic7xxx_verbose
& VERBOSE_MINOR_ERROR
) ||
4986 (aic7xxx_verbose
> 0xffff) )
4989 printk(INFO_LEAD
"Queue full received; queue depth %d, "
4990 "active %d\n", p
->host_no
, CTL_OF_SCB(scb
),
4991 p
->dev_max_queue_depth
[tindex
],
4992 p
->dev_active_cmds
[tindex
]);
4994 printk(INFO_LEAD
"Target busy\n", p
->host_no
, CTL_OF_SCB(scb
));
5000 if ( p
->dev_last_queue_full
[tindex
] !=
5001 p
->dev_active_cmds
[tindex
] )
5003 p
->dev_last_queue_full
[tindex
] =
5004 p
->dev_active_cmds
[tindex
];
5005 p
->dev_last_queue_full_count
[tindex
] = 0;
5009 p
->dev_last_queue_full_count
[tindex
]++;
5011 if ( (p
->dev_last_queue_full_count
[tindex
] > 14) &&
5012 (p
->dev_active_cmds
[tindex
] > 4) )
5014 if (aic7xxx_verbose
& VERBOSE_NEGOTIATION2
)
5015 printk(INFO_LEAD
"Queue depth reduced to %d\n", p
->host_no
,
5016 CTL_OF_SCB(scb
), p
->dev_active_cmds
[tindex
]);
5017 p
->dev_max_queue_depth
[tindex
] =
5018 p
->dev_active_cmds
[tindex
];
5019 p
->dev_last_queue_full
[tindex
] = 0;
5020 p
->dev_last_queue_full_count
[tindex
] = 0;
5021 p
->dev_temp_queue_depth
[tindex
] =
5022 p
->dev_active_cmds
[tindex
];
5024 else if (p
->dev_active_cmds
[tindex
] == 0)
5026 if (aic7xxx_verbose
& VERBOSE_NEGOTIATION
)
5028 printk(INFO_LEAD
"QUEUE_FULL status received with 0 "
5029 "commands active.\n", p
->host_no
, CTL_OF_SCB(scb
));
5030 printk(INFO_LEAD
"Tagged Command Queueing disabled\n",
5031 p
->host_no
, CTL_OF_SCB(scb
));
5033 p
->dev_max_queue_depth
[tindex
] = 1;
5034 p
->dev_temp_queue_depth
[tindex
] = 1;
5035 scb
->tag_action
= 0;
5036 scb
->hscb
->control
&= ~(MSG_ORDERED_Q_TAG
|MSG_SIMPLE_Q_TAG
);
5040 p
->dev_flags
[tindex
] |= DEVICE_WAS_BUSY
;
5041 p
->dev_temp_queue_depth
[tindex
] =
5042 p
->dev_active_cmds
[tindex
];
5049 if (aic7xxx_verbose
& VERBOSE_SEQINT
)
5050 printk(INFO_LEAD
"Unexpected target status 0x%x.\n", p
->host_no
,
5051 CTL_OF_SCB(scb
), scb
->hscb
->target_status
);
5052 if (!aic7xxx_error(cmd
))
5054 aic7xxx_error(cmd
) = DID_RETRY_COMMAND
;
5064 unsigned char scb_index
, msg_out
;
5066 scb_index
= aic_inb(p
, SCB_TAG
);
5067 msg_out
= aic_inb(p
, MSG_OUT
);
5068 scb
= p
->scb_data
->scb_array
[scb_index
];
5069 p
->msg_index
= p
->msg_len
= 0;
5071 * This SCB had a MK_MESSAGE set in its control byte informing
5072 * the sequencer that we wanted to send a special message to
5076 if ( !(scb
->flags
& SCB_DEVICE_RESET
) &&
5077 (msg_out
== MSG_IDENTIFYFLAG
) &&
5078 (scb
->hscb
->control
& TAG_ENB
) )
5080 p
->msg_buf
[p
->msg_index
++] = scb
->tag_action
;
5081 p
->msg_buf
[p
->msg_index
++] = scb
->hscb
->tag
;
5085 if (scb
->flags
& SCB_DEVICE_RESET
)
5087 p
->msg_buf
[p
->msg_index
++] = MSG_BUS_DEV_RESET
;
5089 if (aic7xxx_verbose
& VERBOSE_RESET_PROCESS
)
5090 printk(INFO_LEAD
"Bus device reset mailed.\n",
5091 p
->host_no
, CTL_OF_SCB(scb
));
5093 else if (scb
->flags
& SCB_ABORT
)
5095 if (scb
->tag_action
)
5097 p
->msg_buf
[p
->msg_index
++] = MSG_ABORT_TAG
;
5101 p
->msg_buf
[p
->msg_index
++] = MSG_ABORT
;
5104 if (aic7xxx_verbose
& VERBOSE_ABORT_PROCESS
)
5105 printk(INFO_LEAD
"Abort message mailed.\n", p
->host_no
,
5108 else if (scb
->flags
& SCB_MSGOUT_PPR
)
5110 unsigned int max_sync
, period
;
5111 unsigned char options
= p
->transinfo
[tindex
].goal_options
;
5113 if (p
->features
& AHC_ULTRA2
)
5115 if ( (aic_inb(p
, SBLKCTL
) & ENAB40
) &&
5116 !(aic_inb(p
, SSTAT2
) & EXP_ACTIVE
) )
5118 if( (p
->features
& AHC_ULTRA3
) &&
5119 (p
->dev_flags
[tindex
] & DEVICE_SCSI_3
) &&
5120 (p
->transinfo
[tindex
].goal_width
==
5121 MSG_EXT_WDTR_BUS_16_BIT
) &&
5124 max_sync
= AHC_SYNCRATE_ULTRA3
;
5128 max_sync
= AHC_SYNCRATE_ULTRA2
;
5133 max_sync
= AHC_SYNCRATE_ULTRA
;
5136 else if (p
->features
& AHC_ULTRA
)
5138 max_sync
= AHC_SYNCRATE_ULTRA
;
5142 max_sync
= AHC_SYNCRATE_FAST
;
5144 period
= p
->transinfo
[tindex
].goal_period
;
5145 aic7xxx_find_syncrate(p
, &period
, max_sync
, &options
);
5146 p
->transinfo
[tindex
].goal_period
= period
;
5147 p
->transinfo
[tindex
].goal_options
= options
;
5148 if (aic7xxx_verbose
& VERBOSE_NEGOTIATION2
)
5150 printk(INFO_LEAD
"Sending PPR (%d/%d/%d/%d) message.\n",
5151 p
->host_no
, CTL_OF_SCB(scb
), period
,
5152 p
->transinfo
[tindex
].goal_offset
,
5153 p
->transinfo
[tindex
].goal_width
, options
);
5155 aic7xxx_construct_ppr(p
, scb
);
5157 else if (scb
->flags
& SCB_MSGOUT_WDTR
)
5159 if (aic7xxx_verbose
& VERBOSE_NEGOTIATION2
)
5161 printk(INFO_LEAD
"Sending WDTR message.\n", p
->host_no
,
5164 aic7xxx_construct_wdtr(p
, p
->transinfo
[tindex
].goal_width
);
5166 else if (scb
->flags
& SCB_MSGOUT_SDTR
)
5168 unsigned int max_sync
, period
;
5169 unsigned char options
= 0;
5171 * Now that the device is selected, use the bits in SBLKCTL and
5172 * SSTAT2 to determine the max sync rate for this device.
5174 if (p
->features
& AHC_ULTRA2
)
5176 if ( (aic_inb(p
, SBLKCTL
) & ENAB40
) &&
5177 !(aic_inb(p
, SSTAT2
) & EXP_ACTIVE
) )
5179 max_sync
= AHC_SYNCRATE_ULTRA2
;
5183 max_sync
= AHC_SYNCRATE_ULTRA
;
5186 else if (p
->features
& AHC_ULTRA
)
5188 max_sync
= AHC_SYNCRATE_ULTRA
;
5192 max_sync
= AHC_SYNCRATE_FAST
;
5194 period
= p
->transinfo
[tindex
].goal_period
;
5195 aic7xxx_find_syncrate(p
, &period
, max_sync
, &options
);
5196 if (aic7xxx_verbose
& VERBOSE_NEGOTIATION2
)
5198 printk(INFO_LEAD
"Sending SDTR %d/%d message.\n", p
->host_no
,
5200 p
->transinfo
[tindex
].goal_period
,
5201 p
->transinfo
[tindex
].goal_offset
);
5203 aic7xxx_construct_sdtr(p
, period
,
5204 p
->transinfo
[tindex
].goal_offset
);
5209 panic("aic7xxx: AWAITING_MSG for an SCB that does "
5210 "not have a waiting message.\n");
5213 * We've set everything up to send our message, now to actually do
5214 * so we need to enable reqinit interrupts and let the interrupt
5215 * handler do the rest. We don't want to unpause the sequencer yet
5216 * though so we'll return early. We also have to make sure that
5217 * we clear the SEQINT *BEFORE* we set the REQINIT handler active
5218 * or else it's possible on VLB cards to loose the first REQINIT
5219 * interrupt. Edge triggered EISA cards could also loose this
5220 * interrupt, although PCI and level triggered cards should not
5221 * have this problem since they continually interrupt the kernel
5222 * until we take care of the situation.
5224 scb
->flags
|= SCB_MSGOUT_SENT
;
5226 p
->msg_type
= MSG_TYPE_INITIATOR_MSGOUT
;
5227 p
->flags
|= AHC_HANDLING_REQINITS
;
5228 aic_outb(p
, aic_inb(p
, SIMODE1
) | ENREQINIT
, SIMODE1
);
5235 unsigned char scb_index
= aic_inb(p
, SCB_TAG
);
5236 unsigned char lastphase
= aic_inb(p
, LASTPHASE
);
5239 scb
= (p
->scb_data
->scb_array
[scb_index
]);
5241 * XXX - What do we really want to do on an overrun? The
5242 * mid-level SCSI code should handle this, but for now,
5243 * we'll just indicate that the command should retried.
5244 * If we retrieved sense info on this target, then the
5245 * base SENSE info should have been saved prior to the
5246 * overrun error. In that case, we return DID_OK and let
5247 * the mid level code pick up on the sense info. Otherwise
5248 * we return DID_ERROR so the command will get retried.
5250 if ( !(scb
->flags
& SCB_SENSE
) )
5252 printk(WARN_LEAD
"Data overrun detected in %s phase, tag %d;\n",
5253 p
->host_no
, CTL_OF_SCB(scb
),
5254 (lastphase
== P_DATAIN
) ? "Data-In" : "Data-Out", scb
->hscb
->tag
);
5255 printk(KERN_WARNING
" %s seen Data Phase. Length=%d, NumSGs=%d.\n",
5256 (aic_inb(p
, SEQ_FLAGS
) & DPHASE
) ? "Have" : "Haven't",
5257 scb
->sg_length
, scb
->sg_count
);
5258 for (i
= 0; i
< scb
->sg_count
; i
++)
5260 printk(KERN_WARNING
" sg[%d] - Addr 0x%x : Length %d\n",
5262 le32_to_cpu(scb
->sg_list
[i
].address
),
5263 le32_to_cpu(scb
->sg_list
[i
].length
) );
5265 aic7xxx_error(scb
->cmd
) = DID_ERROR
;
5268 printk(INFO_LEAD
"Data Overrun during SEND_SENSE operation.\n",
5269 p
->host_no
, CTL_OF_SCB(scb
));
5276 printk(INFO_LEAD
"Tracepoint #1 reached.\n", p
->host_no
,
5277 channel
, target
, lun
);
5283 printk(INFO_LEAD
"Tracepoint #2 reached.\n", p
->host_no
,
5284 channel
, target
, lun
);
5288 /* XXX Fill these in later */
5289 case MSG_BUFFER_BUSY
:
5290 printk("aic7xxx: Message buffer busy.\n");
5292 case MSGIN_PHASEMIS
:
5293 printk("aic7xxx: Message-in phasemis.\n");
5297 default: /* unknown */
5298 printk(WARN_LEAD
"Unknown SEQINT, INTSTAT 0x%x, SCSISIGI 0x%x.\n",
5299 p
->host_no
, channel
, target
, lun
, intstat
,
5300 aic_inb(p
, SCSISIGI
));
5305 * Clear the sequencer interrupt and unpause the sequencer.
5307 unpause_sequencer(p
, /* unpause always */ TRUE
);
5310 /*+F*************************************************************************
5315 * Parses incoming messages into actions on behalf of
5316 * aic7xxx_handle_reqinit
5317 *_F*************************************************************************/
5319 aic7xxx_parse_msg(struct aic7xxx_host
*p
, struct aic7xxx_scb
*scb
)
5321 int reject
, reply
, done
;
5322 unsigned char target_scsirate
, tindex
;
5323 unsigned short target_mask
;
5324 unsigned char target
, channel
, lun
;
5326 target
= scb
->cmd
->target
;
5327 channel
= scb
->cmd
->channel
;
5328 lun
= scb
->cmd
->lun
;
5329 reply
= reject
= done
= FALSE
;
5330 tindex
= TARGET_INDEX(scb
->cmd
);
5331 target_scsirate
= aic_inb(p
, TARG_SCSIRATE
+ tindex
);
5332 target_mask
= (0x01 << tindex
);
5335 * Parse as much of the message as is availible,
5336 * rejecting it if we don't support it. When
5337 * the entire message is availible and has been
5338 * handled, return TRUE indicating that we have
5339 * parsed an entire message.
5342 if (p
->msg_buf
[0] != MSG_EXTENDED
)
5348 * Just accept the length byte outright and perform
5349 * more checking once we know the message type.
5352 if ( !reject
&& (p
->msg_len
> 2) )
5354 switch(p
->msg_buf
[2])
5358 unsigned int period
, offset
;
5359 unsigned char maxsync
, saved_offset
, options
;
5360 struct aic7xxx_syncrate
*syncrate
;
5362 if (p
->msg_buf
[1] != MSG_EXT_SDTR_LEN
)
5368 if (p
->msg_len
< (MSG_EXT_SDTR_LEN
+ 2))
5373 period
= p
->msg_buf
[3];
5374 saved_offset
= offset
= p
->msg_buf
[4];
5378 * Even if we are an Ultra3 card, don't allow Ultra3 sync rates when
5379 * using the SDTR messages. We need the PPR messages to enable the
5380 * higher speeds that include things like Dual Edge clocking.
5382 if (p
->features
& AHC_ULTRA2
)
5384 if ( (aic_inb(p
, SBLKCTL
) & ENAB40
) &&
5385 !(aic_inb(p
, SSTAT2
) & EXP_ACTIVE
) )
5387 maxsync
= AHC_SYNCRATE_ULTRA2
;
5391 maxsync
= AHC_SYNCRATE_ULTRA
;
5394 else if (p
->features
& AHC_ULTRA
)
5396 maxsync
= AHC_SYNCRATE_ULTRA
;
5400 maxsync
= AHC_SYNCRATE_FAST
;
5403 * We might have a device that is starting negotiation with us
5404 * before we can start up negotiation with it....be prepared to
5405 * have a device ask for a higher speed then we want to give it
5408 if ( (scb
->flags
& (SCB_MSGOUT_SENT
|SCB_MSGOUT_SDTR
)) !=
5409 (SCB_MSGOUT_SENT
|SCB_MSGOUT_SDTR
) )
5411 if (!(p
->dev_flags
[tindex
] & DEVICE_SCANNED
) &&
5412 !(p
->needsdtr_copy
& target_mask
) &&
5413 (p
->transinfo
[tindex
].user_offset
) )
5416 * Not only is the device starting this up, but it also hasn't
5417 * been scanned yet, so this would likely be our TUR or our
5418 * INQUIRY command at scan time, so we need to use the
5419 * settings from the SEEPROM if they existed. Of course, even
5420 * if we didn't find a SEEPROM, we stuffed default values into
5421 * the user settings anyway, so use those in all cases.
5423 p
->transinfo
[tindex
].goal_period
=
5424 p
->transinfo
[tindex
].user_period
;
5425 if(p
->features
& AHC_ULTRA2
)
5427 p
->transinfo
[tindex
].goal_offset
= MAX_OFFSET_ULTRA2
;
5429 else if (p
->transinfo
[tindex
].cur_width
)
5431 p
->transinfo
[tindex
].goal_offset
= MAX_OFFSET_16BIT
;
5435 p
->transinfo
[tindex
].goal_offset
= MAX_OFFSET_8BIT
;
5437 p
->needsdtr_copy
|= target_mask
;
5439 if (aic7xxx_verbose
& VERBOSE_NEGOTIATION2
)
5441 printk(INFO_LEAD
"Received pre-emptive SDTR message from "
5442 "target.\n", p
->host_no
, CTL_OF_SCB(scb
));
5444 if ( !p
->transinfo
[tindex
].goal_offset
)
5446 if ( p
->transinfo
[tindex
].goal_period
> period
)
5447 period
= p
->transinfo
[tindex
].goal_period
;
5450 syncrate
= aic7xxx_find_syncrate(p
, &period
, maxsync
, &options
);
5451 aic7xxx_validate_offset(p
, syncrate
, &offset
,
5452 target_scsirate
& WIDEXFER
);
5453 aic7xxx_set_syncrate(p
, syncrate
, target
, channel
, period
,
5454 offset
, options
, AHC_TRANS_ACTIVE
|AHC_TRANS_CUR
);
5457 * Did we drop to async? Or are we sending a reply? If we are,
5458 * then we have to make sure that the reply value reflects the proper
5459 * settings so we need to set the goal values according to what
5462 if ( (offset
!= saved_offset
) ||
5463 ((scb
->flags
& (SCB_MSGOUT_SENT
|SCB_MSGOUT_SDTR
)) !=
5464 (SCB_MSGOUT_SENT
|SCB_MSGOUT_SDTR
) ) )
5466 aic7xxx_set_syncrate(p
, syncrate
, target
, channel
, period
, offset
,
5467 options
, AHC_TRANS_GOAL
|AHC_TRANS_QUITE
);
5471 * Did we start this, if not, or if we went to low and had to
5472 * go async, then send an SDTR back to the target
5474 p
->needsdtr
&= ~target_mask
;
5475 p
->dtr_pending
&= ~target_mask
;
5476 if ( ((scb
->flags
& (SCB_MSGOUT_SENT
|SCB_MSGOUT_SDTR
)) !=
5477 (SCB_MSGOUT_SENT
|SCB_MSGOUT_SDTR
)) ||
5478 (offset
!= saved_offset
) )
5481 p
->dtr_pending
|= target_mask
;
5482 scb
->flags
&= ~SCB_MSGOUT_BITS
;
5483 scb
->flags
|= SCB_MSGOUT_SDTR
;
5484 aic_outb(p
, HOST_MSG
, MSG_OUT
);
5485 aic_outb(p
, aic_inb(p
, SCSISIGO
) | ATNO
, SCSISIGO
);
5492 unsigned char bus_width
;
5494 if (p
->msg_buf
[1] != MSG_EXT_WDTR_LEN
)
5500 if (p
->msg_len
< (MSG_EXT_WDTR_LEN
+ 2))
5505 bus_width
= p
->msg_buf
[3];
5506 if ( (scb
->flags
& (SCB_MSGOUT_SENT
|SCB_MSGOUT_WDTR
)) ==
5507 (SCB_MSGOUT_SENT
|SCB_MSGOUT_WDTR
) )
5514 if ( (aic7xxx_verbose
& VERBOSE_NEGOTIATION2
) &&
5515 ((p
->dev_flags
[tindex
] & DEVICE_PRINT_DTR
) ||
5516 (aic7xxx_verbose
> 0xffff)) )
5518 printk(INFO_LEAD
"Requesting %d bit transfers, rejecting.\n",
5519 p
->host_no
, CTL_OF_SCB(scb
), 8 * (0x01 << bus_width
));
5521 } /* We fall through on purpose */
5522 case MSG_EXT_WDTR_BUS_8_BIT
:
5524 bus_width
= MSG_EXT_WDTR_BUS_8_BIT
;
5525 p
->needwdtr_copy
&= ~target_mask
;
5528 case MSG_EXT_WDTR_BUS_16_BIT
:
5533 p
->dtr_pending
&= ~target_mask
;
5534 p
->needwdtr
&= ~target_mask
;
5538 if ( !(p
->dev_flags
[tindex
] & DEVICE_SCANNED
) )
5541 * Well, we now know the WDTR and SYNC caps of this device since
5542 * it contacted us first, mark it as such and copy the user stuff
5543 * over to the goal stuff.
5545 p
->transinfo
[tindex
].goal_period
=
5546 p
->transinfo
[tindex
].user_period
;
5547 if(p
->transinfo
[tindex
].user_offset
)
5549 if(p
->features
& AHC_ULTRA2
)
5551 p
->transinfo
[tindex
].goal_offset
= MAX_OFFSET_ULTRA2
;
5553 else if( p
->transinfo
[tindex
].user_width
&&
5554 (bus_width
== MSG_EXT_WDTR_BUS_16_BIT
) &&
5555 p
->features
& AHC_WIDE
)
5557 p
->transinfo
[tindex
].goal_offset
= MAX_OFFSET_16BIT
;
5561 p
->transinfo
[tindex
].goal_offset
= MAX_OFFSET_8BIT
;
5564 p
->transinfo
[tindex
].goal_width
=
5565 p
->transinfo
[tindex
].user_width
;
5566 p
->needwdtr_copy
|= target_mask
;
5567 p
->needsdtr_copy
|= target_mask
;
5569 if (aic7xxx_verbose
& VERBOSE_NEGOTIATION2
)
5571 printk(INFO_LEAD
"Received pre-emptive WDTR message from "
5572 "target.\n", p
->host_no
, CTL_OF_SCB(scb
));
5578 if ( (p
->features
& AHC_WIDE
) &&
5579 (p
->transinfo
[tindex
].goal_width
==
5580 MSG_EXT_WDTR_BUS_16_BIT
) )
5582 bus_width
= MSG_EXT_WDTR_BUS_16_BIT
;
5585 } /* Fall through if we aren't a wide card */
5586 case MSG_EXT_WDTR_BUS_8_BIT
:
5588 p
->needwdtr_copy
&= ~target_mask
;
5589 bus_width
= MSG_EXT_WDTR_BUS_8_BIT
;
5590 aic7xxx_set_width(p
, target
, channel
, lun
, bus_width
,
5591 AHC_TRANS_GOAL
|AHC_TRANS_QUITE
);
5596 scb
->flags
&= ~SCB_MSGOUT_BITS
;
5597 scb
->flags
|= SCB_MSGOUT_WDTR
;
5598 p
->needwdtr
&= ~target_mask
;
5599 p
->dtr_pending
|= target_mask
;
5600 aic_outb(p
, HOST_MSG
, MSG_OUT
);
5601 aic_outb(p
, aic_inb(p
, SCSISIGO
) | ATNO
, SCSISIGO
);
5603 aic7xxx_set_width(p
, target
, channel
, lun
, bus_width
,
5604 AHC_TRANS_ACTIVE
|AHC_TRANS_CUR
);
5607 * By virtue of the SCSI spec, a WDTR message negates any existing
5608 * SDTR negotiations. So, even if needsdtr isn't marked for this
5609 * device, we still have to do a new SDTR message if the device
5610 * supports SDTR at all. Therefore, we check needsdtr_copy instead
5613 aic7xxx_set_syncrate(p
, NULL
, target
, channel
, 0, 0, 0,
5614 AHC_TRANS_ACTIVE
|AHC_TRANS_CUR
|AHC_TRANS_QUITE
);
5615 p
->needsdtr
|= (p
->needsdtr_copy
& target_mask
);
5621 unsigned char bus_width
, trans_options
, new_trans_options
;
5622 unsigned int period
, offset
;
5623 unsigned char maxsync
, saved_offset
;
5624 struct aic7xxx_syncrate
*syncrate
;
5626 if (p
->msg_buf
[1] != MSG_EXT_PPR_LEN
)
5633 * If we aren't on one of the new Ultra3 cards, then reject any PPR
5634 * message since we can't support any option field other than 0
5636 if( !(p
->features
& AHC_ULTRA3
) )
5642 if (p
->msg_len
< (MSG_EXT_PPR_LEN
+ 2))
5647 period
= p
->msg_buf
[3];
5648 offset
= saved_offset
= p
->msg_buf
[5];
5649 bus_width
= p
->msg_buf
[6];
5650 trans_options
= new_trans_options
= p
->msg_buf
[7] & 0xf;
5652 if(aic7xxx_verbose
& VERBOSE_NEGOTIATION2
)
5654 printk(INFO_LEAD
"Parsing PPR message (%d/%d/%d/%d)\n",
5655 p
->host_no
, CTL_OF_SCB(scb
), period
, offset
, bus_width
,
5659 if ( (aic_inb(p
, SBLKCTL
) & ENAB40
) &&
5660 !(aic_inb(p
, SSTAT2
) & EXP_ACTIVE
) )
5662 if(p
->features
& AHC_ULTRA3
)
5664 maxsync
= AHC_SYNCRATE_ULTRA3
;
5668 maxsync
= AHC_SYNCRATE_ULTRA2
;
5673 maxsync
= AHC_SYNCRATE_ULTRA
;
5676 * We might have a device that is starting negotiation with us
5677 * before we can start up negotiation with it....be prepared to
5678 * have a device ask for a higher speed then we want to give it
5681 if ( (scb
->flags
& (SCB_MSGOUT_SENT
|SCB_MSGOUT_PPR
)) !=
5682 (SCB_MSGOUT_SENT
|SCB_MSGOUT_PPR
) )
5685 scb
->flags
&= ~SCB_MSGOUT_BITS
;
5686 scb
->flags
|= SCB_MSGOUT_PPR
;
5687 if (!(p
->dev_flags
[tindex
] & DEVICE_SCANNED
))
5690 * Not only is the device starting this up, but it also hasn't
5691 * been scanned yet, so this would likely be our TUR or our
5692 * INQUIRY command at scan time, so we need to use the
5693 * settings from the SEEPROM if they existed. Of course, even
5694 * if we didn't find a SEEPROM, we stuffed default values into
5695 * the user settings anyway, so use those in all cases.
5697 p
->transinfo
[tindex
].goal_period
=
5698 p
->transinfo
[tindex
].user_period
;
5699 if(p
->transinfo
[tindex
].user_offset
)
5701 if(p
->features
& AHC_ULTRA2
)
5703 p
->transinfo
[tindex
].goal_offset
= MAX_OFFSET_ULTRA2
;
5705 else if( p
->transinfo
[tindex
].user_width
&&
5706 (bus_width
== MSG_EXT_WDTR_BUS_16_BIT
) &&
5707 p
->features
& AHC_WIDE
)
5709 p
->transinfo
[tindex
].goal_offset
= MAX_OFFSET_16BIT
;
5713 p
->transinfo
[tindex
].goal_offset
= MAX_OFFSET_8BIT
;
5716 p
->transinfo
[tindex
].goal_width
=
5717 p
->transinfo
[tindex
].user_width
;
5718 p
->transinfo
[tindex
].goal_options
=
5719 p
->transinfo
[tindex
].user_options
;
5720 p
->needppr_copy
|= target_mask
;
5722 if (aic7xxx_verbose
& VERBOSE_NEGOTIATION2
)
5724 printk(INFO_LEAD
"Received pre-emptive PPR message from "
5725 "target.\n", p
->host_no
, CTL_OF_SCB(scb
));
5727 if ( !p
->transinfo
[tindex
].goal_offset
)
5729 if ( p
->transinfo
[tindex
].goal_period
> period
)
5730 period
= p
->transinfo
[tindex
].goal_period
;
5731 if ( p
->transinfo
[tindex
].goal_options
== 0 )
5732 new_trans_options
= 0;
5737 if ( (p
->features
& AHC_WIDE
) &&
5738 (p
->transinfo
[tindex
].goal_width
==
5739 MSG_EXT_WDTR_BUS_16_BIT
) )
5741 bus_width
= MSG_EXT_WDTR_BUS_16_BIT
;
5744 } /* Fall through if we aren't a wide card */
5745 case MSG_EXT_WDTR_BUS_8_BIT
:
5747 p
->needwdtr_copy
&= ~target_mask
;
5748 bus_width
= MSG_EXT_WDTR_BUS_8_BIT
;
5749 aic7xxx_set_width(p
, target
, channel
, lun
, bus_width
,
5750 AHC_TRANS_GOAL
|AHC_TRANS_QUITE
);
5762 if ( (aic7xxx_verbose
& VERBOSE_NEGOTIATION2
) &&
5763 ((p
->dev_flags
[tindex
] & DEVICE_PRINT_DTR
) ||
5764 (aic7xxx_verbose
> 0xffff)) )
5766 printk(INFO_LEAD
"Requesting %d bit transfers, rejecting.\n",
5767 p
->host_no
, CTL_OF_SCB(scb
), 8 * (0x01 << bus_width
));
5769 } /* We fall through on purpose */
5770 case MSG_EXT_WDTR_BUS_8_BIT
:
5773 * According to the spec, if we aren't wide, we also can't be
5774 * Dual Edge so clear the options byte
5776 new_trans_options
= 0;
5777 bus_width
= MSG_EXT_WDTR_BUS_8_BIT
;
5780 case MSG_EXT_WDTR_BUS_16_BIT
:
5787 aic7xxx_set_width(p
, target
, channel
, lun
, bus_width
,
5788 AHC_TRANS_ACTIVE
|AHC_TRANS_CUR
);
5789 syncrate
= aic7xxx_find_syncrate(p
, &period
, maxsync
,
5790 &new_trans_options
);
5791 aic7xxx_validate_offset(p
, syncrate
, &offset
, bus_width
);
5792 aic7xxx_set_syncrate(p
, syncrate
, target
, channel
, period
,
5793 offset
, new_trans_options
,
5794 AHC_TRANS_ACTIVE
|AHC_TRANS_CUR
);
5796 if( (offset
!= saved_offset
) ||
5797 (trans_options
!= new_trans_options
) ||
5798 ((scb
->flags
& (SCB_MSGOUT_SENT
|SCB_MSGOUT_PPR
)) !=
5799 (SCB_MSGOUT_SENT
|SCB_MSGOUT_PPR
)) )
5801 aic7xxx_set_width(p
, target
, channel
, lun
, bus_width
,
5802 AHC_TRANS_GOAL
|AHC_TRANS_QUITE
);
5803 aic7xxx_set_syncrate(p
, syncrate
, target
, channel
, period
,
5804 offset
, new_trans_options
,
5805 AHC_TRANS_GOAL
|AHC_TRANS_QUITE
);
5808 p
->dtr_pending
&= ~target_mask
;
5809 p
->needppr
&= ~target_mask
;
5812 p
->dtr_pending
|= target_mask
;
5813 scb
->flags
&= ~SCB_MSGOUT_BITS
;
5814 scb
->flags
|= SCB_MSGOUT_PPR
;
5815 aic_outb(p
, HOST_MSG
, MSG_OUT
);
5816 aic_outb(p
, aic_inb(p
, SCSISIGO
) | ATNO
, SCSISIGO
);
5826 } /* end of switch(p->msg_type) */
5827 } /* end of if (!reject && (p->msg_len > 2)) */
5829 if (!reply
&& reject
)
5831 aic_outb(p
, MSG_MESSAGE_REJECT
, MSG_OUT
);
5832 aic_outb(p
, aic_inb(p
, SCSISIGO
) | ATNO
, SCSISIGO
);
5839 /*+F*************************************************************************
5841 * aic7xxx_handle_reqinit
5844 * Interrupt handler for REQINIT interrupts (used to transfer messages to
5845 * and from devices).
5846 *_F*************************************************************************/
5848 aic7xxx_handle_reqinit(struct aic7xxx_host
*p
, struct aic7xxx_scb
*scb
)
5850 unsigned char lastbyte
;
5851 unsigned char phasemis
;
5856 case MSG_TYPE_INITIATOR_MSGOUT
:
5858 if (p
->msg_len
== 0)
5859 panic("aic7xxx: REQINIT with no active message!\n");
5861 lastbyte
= (p
->msg_index
== (p
->msg_len
- 1));
5862 phasemis
= ( aic_inb(p
, SCSISIGI
) & PHASE_MASK
) != P_MESGOUT
;
5864 if (lastbyte
|| phasemis
)
5866 /* Time to end the message */
5868 p
->msg_type
= MSG_TYPE_NONE
;
5870 * NOTE-TO-MYSELF: If you clear the REQINIT after you
5871 * disable REQINITs, then cases of REJECT_MSG stop working
5874 aic_outb(p
, aic_inb(p
, SIMODE1
) & ~ENREQINIT
, SIMODE1
);
5875 aic_outb(p
, CLRSCSIINT
, CLRINT
);
5876 p
->flags
&= ~AHC_HANDLING_REQINITS
;
5880 aic_outb(p
, p
->msg_buf
[p
->msg_index
], SINDEX
);
5881 aic_outb(p
, 0, RETURN_1
);
5882 #ifdef AIC7XXX_VERBOSE_DEBUGGING
5883 if (aic7xxx_verbose
> 0xffff)
5884 printk(INFO_LEAD
"Completed sending of REQINIT message.\n",
5885 p
->host_no
, CTL_OF_SCB(scb
));
5890 aic_outb(p
, MSGOUT_PHASEMIS
, RETURN_1
);
5891 #ifdef AIC7XXX_VERBOSE_DEBUGGING
5892 if (aic7xxx_verbose
> 0xffff)
5893 printk(INFO_LEAD
"PHASEMIS while sending REQINIT message.\n",
5894 p
->host_no
, CTL_OF_SCB(scb
));
5897 unpause_sequencer(p
, TRUE
);
5902 * Present the byte on the bus (clearing REQINIT) but don't
5903 * unpause the sequencer.
5905 aic_outb(p
, CLRREQINIT
, CLRSINT1
);
5906 aic_outb(p
, CLRSCSIINT
, CLRINT
);
5907 aic_outb(p
, p
->msg_buf
[p
->msg_index
++], SCSIDATL
);
5911 case MSG_TYPE_INITIATOR_MSGIN
:
5913 phasemis
= ( aic_inb(p
, SCSISIGI
) & PHASE_MASK
) != P_MESGIN
;
5918 /* Pull the byte in without acking it */
5919 p
->msg_buf
[p
->msg_index
] = aic_inb(p
, SCSIBUSL
);
5920 done
= aic7xxx_parse_msg(p
, scb
);
5922 aic_outb(p
, CLRREQINIT
, CLRSINT1
);
5923 aic_outb(p
, CLRSCSIINT
, CLRINT
);
5924 aic_inb(p
, SCSIDATL
);
5927 if (phasemis
|| done
)
5929 #ifdef AIC7XXX_VERBOSE_DEBUGGING
5930 if (aic7xxx_verbose
> 0xffff)
5933 printk(INFO_LEAD
"PHASEMIS while receiving REQINIT message.\n",
5934 p
->host_no
, CTL_OF_SCB(scb
));
5936 printk(INFO_LEAD
"Completed receipt of REQINIT message.\n",
5937 p
->host_no
, CTL_OF_SCB(scb
));
5940 /* Time to end our message session */
5942 p
->msg_type
= MSG_TYPE_NONE
;
5943 aic_outb(p
, aic_inb(p
, SIMODE1
) & ~ENREQINIT
, SIMODE1
);
5944 aic_outb(p
, CLRSCSIINT
, CLRINT
);
5945 p
->flags
&= ~AHC_HANDLING_REQINITS
;
5946 unpause_sequencer(p
, TRUE
);
5952 panic("aic7xxx: Unknown REQINIT message type.\n");
5955 } /* End of switch(p->msg_type) */
5958 /*+F*************************************************************************
5960 * aic7xxx_handle_scsiint
5963 * Interrupt handler for SCSI interrupts (SCSIINT).
5964 *-F*************************************************************************/
5966 aic7xxx_handle_scsiint(struct aic7xxx_host
*p
, unsigned char intstat
)
5968 unsigned char scb_index
;
5969 unsigned char status
;
5970 struct aic7xxx_scb
*scb
;
5972 scb_index
= aic_inb(p
, SCB_TAG
);
5973 status
= aic_inb(p
, SSTAT1
);
5975 if (scb_index
< p
->scb_data
->numscbs
)
5977 scb
= p
->scb_data
->scb_array
[scb_index
];
5978 if ((scb
->flags
& SCB_ACTIVE
) == 0)
5989 if ((status
& SCSIRSTI
) != 0)
5993 if ( (p
->chip
& AHC_CHIPID_MASK
) == AHC_AIC7770
)
5994 channel
= (aic_inb(p
, SBLKCTL
) & SELBUSB
) >> 3;
5998 if (aic7xxx_verbose
& VERBOSE_RESET
)
5999 printk(WARN_LEAD
"Someone else reset the channel!!\n",
6000 p
->host_no
, channel
, -1, -1);
6001 if (aic7xxx_panic_on_abort
)
6002 aic7xxx_panic_abort(p
, NULL
);
6004 * Go through and abort all commands for the channel, but do not
6005 * reset the channel again.
6007 aic7xxx_reset_channel(p
, channel
, /* Initiate Reset */ FALSE
);
6008 aic7xxx_run_done_queue(p
, TRUE
);
6011 else if ( ((status
& BUSFREE
) != 0) && ((status
& SELTO
) == 0) )
6014 * First look at what phase we were last in. If it's message-out,
6015 * chances are pretty good that the bus free was in response to
6016 * one of our abort requests.
6018 unsigned char lastphase
= aic_inb(p
, LASTPHASE
);
6019 unsigned char saved_tcl
= aic_inb(p
, SAVED_TCL
);
6020 unsigned char target
= (saved_tcl
>> 4) & 0x0F;
6022 int printerror
= TRUE
;
6024 if ( (p
->chip
& AHC_CHIPID_MASK
) == AHC_AIC7770
)
6025 channel
= (aic_inb(p
, SBLKCTL
) & SELBUSB
) >> 3;
6029 aic_outb(p
, aic_inb(p
, SCSISEQ
) & (ENSELI
|ENRSELI
|ENAUTOATNP
),
6031 if (lastphase
== P_MESGOUT
)
6033 unsigned char message
;
6035 message
= aic_inb(p
, SINDEX
);
6037 if ((message
== MSG_ABORT
) || (message
== MSG_ABORT_TAG
))
6039 if (aic7xxx_verbose
& VERBOSE_ABORT_PROCESS
)
6040 printk(INFO_LEAD
"SCB %d abort delivered.\n", p
->host_no
,
6041 CTL_OF_SCB(scb
), scb
->hscb
->tag
);
6042 aic7xxx_reset_device(p
, target
, channel
, ALL_LUNS
,
6043 (message
== MSG_ABORT
) ? SCB_LIST_NULL
: scb
->hscb
->tag
);
6044 aic7xxx_run_done_queue(p
, TRUE
);
6048 else if (message
== MSG_BUS_DEV_RESET
)
6050 aic7xxx_handle_device_reset(p
, target
, channel
);
6055 if ( (scb
!= NULL
) &&
6056 (scb
->cmd
== p
->dev_dtr_cmnd
[TARGET_INDEX(scb
->cmd
)]) )
6059 * This might be a SCSI-3 device that is dropping the bus due to
6060 * errors and signalling that we should reduce the transfer speed.
6061 * All we have to do is complete this command (since it's a negotiation
6062 * command already) and the checksum routine should flag an error and
6063 * reduce the speed setting and renegotiate. We call the reset routing
6064 * just to clean out the hardware from this scb.
6067 aic7xxx_reset_device(p
, target
, channel
, ALL_LUNS
, scb
->hscb
->tag
);
6068 aic7xxx_run_done_queue(p
, TRUE
);
6071 if (printerror
!= 0)
6077 if ((scb
->hscb
->control
& TAG_ENB
) != 0)
6079 tag
= scb
->hscb
->tag
;
6083 tag
= SCB_LIST_NULL
;
6085 aic7xxx_reset_device(p
, target
, channel
, ALL_LUNS
, tag
);
6086 aic7xxx_run_done_queue(p
, TRUE
);
6090 aic7xxx_reset_device(p
, target
, channel
, ALL_LUNS
, SCB_LIST_NULL
);
6091 aic7xxx_run_done_queue(p
, TRUE
);
6093 printk(INFO_LEAD
"Unexpected busfree, LASTPHASE = 0x%x, "
6094 "SEQADDR = 0x%x\n", p
->host_no
, channel
, target
, -1, lastphase
,
6095 (aic_inb(p
, SEQADDR1
) << 8) | aic_inb(p
, SEQADDR0
));
6098 aic_outb(p
, MSG_NOOP
, MSG_OUT
);
6099 aic_outb(p
, aic_inb(p
, SIMODE1
) & ~(ENBUSFREE
|ENREQINIT
),
6101 p
->flags
&= ~AHC_HANDLING_REQINITS
;
6102 aic_outb(p
, CLRBUSFREE
, CLRSINT1
);
6103 aic_outb(p
, CLRSCSIINT
, CLRINT
);
6104 restart_sequencer(p
);
6105 unpause_sequencer(p
, TRUE
);
6107 else if ((status
& SELTO
) != 0)
6109 unsigned char scbptr
;
6110 unsigned char nextscb
;
6113 scbptr
= aic_inb(p
, WAITING_SCBH
);
6114 if (scbptr
> p
->scb_data
->maxhscbs
)
6117 * I'm still trying to track down exactly how this happens, but until
6118 * I find it, this code will make sure we aren't passing bogus values
6119 * into the SCBPTR register, even if that register will just wrap
6120 * things around, we still don't like having out of range variables.
6122 * NOTE: Don't check the aic7xxx_verbose variable, I want this message
6123 * to always be displayed.
6125 printk(INFO_LEAD
"Invalid WAITING_SCBH value %d, improvising.\n",
6126 p
->host_no
, -1, -1, -1, scbptr
);
6127 if (p
->scb_data
->maxhscbs
> 4)
6128 scbptr
&= (p
->scb_data
->maxhscbs
- 1);
6132 aic_outb(p
, scbptr
, SCBPTR
);
6133 scb_index
= aic_inb(p
, SCB_TAG
);
6136 if (scb_index
< p
->scb_data
->numscbs
)
6138 scb
= p
->scb_data
->scb_array
[scb_index
];
6139 if ((scb
->flags
& SCB_ACTIVE
) == 0)
6146 printk(WARN_LEAD
"Referenced SCB %d not valid during SELTO.\n",
6147 p
->host_no
, -1, -1, -1, scb_index
);
6148 printk(KERN_WARNING
" SCSISEQ = 0x%x SEQADDR = 0x%x SSTAT0 = 0x%x "
6149 "SSTAT1 = 0x%x\n", aic_inb(p
, SCSISEQ
),
6150 aic_inb(p
, SEQADDR0
) | (aic_inb(p
, SEQADDR1
) << 8),
6151 aic_inb(p
, SSTAT0
), aic_inb(p
, SSTAT1
));
6152 if (aic7xxx_panic_on_abort
)
6153 aic7xxx_panic_abort(p
, NULL
);
6158 cmd
->result
= (DID_TIME_OUT
<< 16);
6161 * Clear out this hardware SCB
6163 aic_outb(p
, 0, SCB_CONTROL
);
6166 * Clear out a few values in the card that are in an undetermined
6169 aic_outb(p
, MSG_NOOP
, MSG_OUT
);
6172 * Shift the waiting for selection queue forward
6174 nextscb
= aic_inb(p
, SCB_NEXT
);
6175 aic_outb(p
, nextscb
, WAITING_SCBH
);
6178 * Put this SCB back on the free list.
6180 aic7xxx_add_curscb_to_free_list(p
);
6181 #ifdef AIC7XXX_VERBOSE_DEBUGGING
6182 if (aic7xxx_verbose
> 0xffff)
6183 printk(INFO_LEAD
"Selection Timeout.\n", p
->host_no
, CTL_OF_SCB(scb
));
6185 if (scb
->flags
& SCB_QUEUED_ABORT
)
6188 * We know that this particular SCB had to be the queued abort since
6189 * the disconnected SCB would have gotten a reconnect instead.
6190 * What we need to do then is to let the command timeout again so
6191 * we get a reset since this abort just failed.
6196 if (scb
->cmd
== p
->dev_dtr_cmnd
[TARGET_INDEX(scb
->cmd
)])
6199 * Turn off the needsdtr, needwdtr, and needppr bits since this device
6200 * doesn't seem to exist.
6202 p
->needppr
&= ~(0x01 << TARGET_INDEX(scb
->cmd
));
6203 p
->needppr_copy
&= ~(0x01 << TARGET_INDEX(scb
->cmd
));
6204 p
->needsdtr
&= ~(0x01 << TARGET_INDEX(scb
->cmd
));
6205 p
->needsdtr_copy
&= ~(0x01 << TARGET_INDEX(scb
->cmd
));
6206 p
->needwdtr
&= ~(0x01 << TARGET_INDEX(scb
->cmd
));
6207 p
->needwdtr_copy
&= ~(0x01 << TARGET_INDEX(scb
->cmd
));
6211 * Restarting the sequencer will stop the selection and make sure devices
6212 * are allowed to reselect in.
6214 aic_outb(p
, 0, SCSISEQ
);
6215 aic_outb(p
, CLRSELINGO
, CLRSINT0
);
6216 aic_outb(p
, aic_inb(p
, SIMODE1
) & ~(ENREQINIT
|ENBUSFREE
), SIMODE1
);
6217 p
->flags
&= ~AHC_HANDLING_REQINITS
;
6218 aic_outb(p
, CLRSELTIMEO
| CLRBUSFREE
, CLRSINT1
);
6219 aic_outb(p
, CLRSCSIINT
, CLRINT
);
6220 restart_sequencer(p
);
6221 unpause_sequencer(p
, TRUE
);
6223 else if (scb
== NULL
)
6225 printk(WARN_LEAD
"aic7xxx_isr - referenced scb not valid "
6226 "during scsiint 0x%x scb(%d)\n"
6227 " SIMODE0 0x%x, SIMODE1 0x%x, SSTAT0 0x%x, SEQADDR 0x%x\n",
6228 p
->host_no
, -1, -1, -1, status
, scb_index
, aic_inb(p
, SIMODE0
),
6229 aic_inb(p
, SIMODE1
), aic_inb(p
, SSTAT0
),
6230 (aic_inb(p
, SEQADDR1
) << 8) | aic_inb(p
, SEQADDR0
));
6232 * Turn off the interrupt and set status to zero, so that it
6233 * falls through the rest of the SCSIINT code.
6235 aic_outb(p
, status
, CLRSINT1
);
6236 aic_outb(p
, CLRSCSIINT
, CLRINT
);
6237 unpause_sequencer(p
, /* unpause always */ TRUE
);
6240 else if (status
& SCSIPERR
)
6243 * Determine the bus phase and queue an appropriate message.
6247 unsigned char mesg_out
= MSG_NOOP
;
6248 unsigned char lastphase
= aic_inb(p
, LASTPHASE
);
6249 unsigned char sstat2
= aic_inb(p
, SSTAT2
);
6250 unsigned char tindex
= TARGET_INDEX(scb
->cmd
);
6260 mesg_out
= MSG_INITIATOR_DET_ERR
;
6266 phase
= "Message-Out";
6270 mesg_out
= MSG_INITIATOR_DET_ERR
;
6273 phase
= "Message-In";
6274 mesg_out
= MSG_PARITY_ERROR
;
6282 * A parity error has occurred during a data
6283 * transfer phase. Flag it and continue.
6285 if( (aic_inb(p
, SCSIRATE
) & AHC_SYNCRATE_CRC
) && (lastphase
== P_DATAIN
) )
6287 printk(WARN_LEAD
"CRC error during %s phase.\n",
6288 p
->host_no
, CTL_OF_SCB(scb
), phase
);
6289 if(sstat2
& CRCVALERR
)
6291 printk(WARN_LEAD
" CRC error in intermediate CRC packet.\n",
6292 p
->host_no
, CTL_OF_SCB(scb
));
6294 if(sstat2
& CRCENDERR
)
6296 printk(WARN_LEAD
" CRC error in ending CRC packet.\n",
6297 p
->host_no
, CTL_OF_SCB(scb
));
6299 if(sstat2
& CRCREQERR
)
6301 printk(WARN_LEAD
" Target incorrectly requested a CRC packet.\n",
6302 p
->host_no
, CTL_OF_SCB(scb
));
6304 if(sstat2
& DUAL_EDGE_ERROR
)
6306 printk(WARN_LEAD
" Dual Edge transmission error.\n",
6307 p
->host_no
, CTL_OF_SCB(scb
));
6312 printk(WARN_LEAD
"Parity error during %s phase.\n",
6313 p
->host_no
, CTL_OF_SCB(scb
), phase
);
6316 if(p
->dev_flags
[tindex
] & DEVICE_PARITY_ERROR
)
6318 struct aic7xxx_syncrate
*syncrate
;
6319 unsigned int period
= p
->transinfo
[tindex
].cur_period
;
6320 unsigned char options
= p
->transinfo
[tindex
].cur_options
;
6322 * oops, we had a failure, lower the transfer rate and try again. It's
6323 * worth noting here that it might be wise to also check for typical
6324 * wide setting on narrow cable type problems and try disabling wide
6325 * instead of slowing down if those exist. That's hard to do with simple
6328 if((syncrate
= aic7xxx_find_syncrate(p
, &period
, 0, &options
)) != NULL
)
6331 if( (syncrate
->rate
[0] != NULL
) &&
6332 (!(p
->features
& AHC_ULTRA2
) || (syncrate
->sxfr_ultra2
== 0)) )
6334 p
->transinfo
[tindex
].goal_period
= syncrate
->period
;
6335 if( !(syncrate
->sxfr_ultra2
& 0x40) )
6337 p
->transinfo
[tindex
].goal_options
= 0;
6342 p
->transinfo
[tindex
].goal_offset
= 0;
6343 p
->transinfo
[tindex
].goal_period
= 0;
6344 p
->transinfo
[tindex
].goal_options
= 0;
6346 p
->needppr
|= (p
->needppr_copy
& (1<<tindex
));
6347 p
->needsdtr
|= (p
->needsdtr_copy
& (1<<tindex
));
6348 p
->needwdtr
|= (p
->needwdtr_copy
& (1<<tindex
));
6350 p
->dev_flags
[tindex
] &= ~DEVICE_PARITY_ERROR
;
6354 p
->dev_flags
[tindex
] |= DEVICE_PARITY_ERROR
;
6358 * We've set the hardware to assert ATN if we get a parity
6359 * error on "in" phases, so all we need to do is stuff the
6360 * message buffer with the appropriate message. "In" phases
6361 * have set mesg_out to something other than MSG_NOP.
6363 if (mesg_out
!= MSG_NOOP
)
6365 aic_outb(p
, mesg_out
, MSG_OUT
);
6368 aic_outb(p
, CLRSCSIPERR
, CLRSINT1
);
6369 aic_outb(p
, CLRSCSIINT
, CLRINT
);
6370 unpause_sequencer(p
, /* unpause_always */ TRUE
);
6372 else if ( (status
& REQINIT
) &&
6373 (p
->flags
& AHC_HANDLING_REQINITS
) )
6375 #ifdef AIC7XXX_VERBOSE_DEBUGGING
6376 if (aic7xxx_verbose
> 0xffff)
6377 printk(INFO_LEAD
"Handling REQINIT, SSTAT1=0x%x.\n", p
->host_no
,
6378 CTL_OF_SCB(scb
), aic_inb(p
, SSTAT1
));
6380 aic7xxx_handle_reqinit(p
, scb
);
6386 * We don't know what's going on. Turn off the
6387 * interrupt source and try to continue.
6389 if (aic7xxx_verbose
& VERBOSE_SCSIINT
)
6390 printk(INFO_LEAD
"Unknown SCSIINT status, SSTAT1(0x%x).\n",
6391 p
->host_no
, -1, -1, -1, status
);
6392 aic_outb(p
, status
, CLRSINT1
);
6393 aic_outb(p
, CLRSCSIINT
, CLRINT
);
6394 unpause_sequencer(p
, /* unpause always */ TRUE
);
6399 aic7xxx_done(p
, scb
);
6403 #ifdef AIC7XXX_VERBOSE_DEBUGGING
6405 aic7xxx_check_scbs(struct aic7xxx_host
*p
, char *buffer
)
6407 unsigned char saved_scbptr
, free_scbh
, dis_scbh
, wait_scbh
, temp
;
6409 static unsigned char scb_status
[AIC7XXX_MAXSCB
];
6411 #define SCB_NO_LIST 0
6412 #define SCB_FREE_LIST 1
6413 #define SCB_WAITING_LIST 2
6414 #define SCB_DISCONNECTED_LIST 4
6415 #define SCB_CURRENTLY_ACTIVE 8
6418 * Note, these checks will fail on a regular basis once the machine moves
6419 * beyond the bus scan phase. The problem is race conditions concerning
6420 * the scbs and where they are linked in. When you have 30 or so commands
6421 * outstanding on the bus, and run this twice with every interrupt, the
6422 * chances get pretty good that you'll catch the sequencer with an SCB
6423 * only partially linked in. Therefore, once we pass the scan phase
6424 * of the bus, we really should disable this function.
6427 memset(&scb_status
[0], 0, sizeof(scb_status
));
6429 saved_scbptr
= aic_inb(p
, SCBPTR
);
6430 if (saved_scbptr
>= p
->scb_data
->maxhscbs
)
6432 printk("Bogus SCBPTR %d\n", saved_scbptr
);
6435 scb_status
[saved_scbptr
] = SCB_CURRENTLY_ACTIVE
;
6436 free_scbh
= aic_inb(p
, FREE_SCBH
);
6437 if ( (free_scbh
!= SCB_LIST_NULL
) &&
6438 (free_scbh
>= p
->scb_data
->maxhscbs
) )
6440 printk("Bogus FREE_SCBH %d\n", free_scbh
);
6446 while( (temp
!= SCB_LIST_NULL
) && (temp
< p
->scb_data
->maxhscbs
) )
6448 if(scb_status
[temp
] & 0x07)
6450 printk("HSCB %d on multiple lists, status 0x%02x", temp
,
6451 scb_status
[temp
] | SCB_FREE_LIST
);
6454 scb_status
[temp
] |= SCB_FREE_LIST
;
6455 aic_outb(p
, temp
, SCBPTR
);
6456 temp
= aic_inb(p
, SCB_NEXT
);
6460 dis_scbh
= aic_inb(p
, DISCONNECTED_SCBH
);
6461 if ( (dis_scbh
!= SCB_LIST_NULL
) &&
6462 (dis_scbh
>= p
->scb_data
->maxhscbs
) )
6464 printk("Bogus DISCONNECTED_SCBH %d\n", dis_scbh
);
6470 while( (temp
!= SCB_LIST_NULL
) && (temp
< p
->scb_data
->maxhscbs
) )
6472 if(scb_status
[temp
] & 0x07)
6474 printk("HSCB %d on multiple lists, status 0x%02x", temp
,
6475 scb_status
[temp
] | SCB_DISCONNECTED_LIST
);
6478 scb_status
[temp
] |= SCB_DISCONNECTED_LIST
;
6479 aic_outb(p
, temp
, SCBPTR
);
6480 temp
= aic_inb(p
, SCB_NEXT
);
6484 wait_scbh
= aic_inb(p
, WAITING_SCBH
);
6485 if ( (wait_scbh
!= SCB_LIST_NULL
) &&
6486 (wait_scbh
>= p
->scb_data
->maxhscbs
) )
6488 printk("Bogus WAITING_SCBH %d\n", wait_scbh
);
6494 while( (temp
!= SCB_LIST_NULL
) && (temp
< p
->scb_data
->maxhscbs
) )
6496 if(scb_status
[temp
] & 0x07)
6498 printk("HSCB %d on multiple lists, status 0x%02x", temp
,
6499 scb_status
[temp
] | SCB_WAITING_LIST
);
6502 scb_status
[temp
] |= SCB_WAITING_LIST
;
6503 aic_outb(p
, temp
, SCBPTR
);
6504 temp
= aic_inb(p
, SCB_NEXT
);
6509 for(i
=0; i
< p
->scb_data
->maxhscbs
; i
++)
6511 aic_outb(p
, i
, SCBPTR
);
6512 temp
= aic_inb(p
, SCB_NEXT
);
6513 if ( ((temp
!= SCB_LIST_NULL
) &&
6514 (temp
>= p
->scb_data
->maxhscbs
)) )
6516 printk("HSCB %d bad, SCB_NEXT invalid(%d).\n", i
, temp
);
6521 printk("HSCB %d bad, SCB_NEXT points to self.\n", i
);
6524 if (scb_status
[i
] == 0)
6528 printk("Too many lost scbs.\n");
6532 aic_outb(p
, saved_scbptr
, SCBPTR
);
6533 unpause_sequencer(p
, FALSE
);
6536 printk("Bogus parameters found in card SCB array structures.\n");
6537 printk("%s\n", buffer
);
6538 aic7xxx_panic_abort(p
, NULL
);
6544 /*+F*************************************************************************
6549 * SCSI controller interrupt handler.
6550 *-F*************************************************************************/
6552 aic7xxx_isr(int irq
, void *dev_id
, struct pt_regs
*regs
)
6554 struct aic7xxx_host
*p
;
6555 unsigned char intstat
;
6557 p
= (struct aic7xxx_host
*)dev_id
;
6560 * Just a few sanity checks. Make sure that we have an int pending.
6561 * Also, if PCI, then we are going to check for a PCI bus error status
6562 * should we get too many spurious interrupts.
6564 if (!((intstat
= aic_inb(p
, INTSTAT
)) & INT_PEND
))
6567 if ( (p
->chip
& AHC_PCI
) && (p
->spurious_int
> 500) &&
6568 !(p
->flags
& AHC_HANDLING_REQINITS
) )
6570 if ( aic_inb(p
, ERROR
) & PCIERRSTAT
)
6572 aic7xxx_pci_intr(p
);
6574 p
->spurious_int
= 0;
6576 else if ( !(p
->flags
& AHC_HANDLING_REQINITS
) )
6584 p
->spurious_int
= 0;
6587 * Keep track of interrupts for /proc/scsi
6591 #ifdef AIC7XXX_VERBOSE_DEBUGGING
6592 if ( (p
->isr_count
< 16) && (aic7xxx_verbose
> 0xffff) &&
6593 (aic7xxx_panic_on_abort
) && (p
->flags
& AHC_PAGESCBS
) )
6594 aic7xxx_check_scbs(p
, "Bogus settings at start of interrupt.");
6598 * Handle all the interrupt sources - especially for SCSI
6599 * interrupts, we won't get a second chance at them.
6601 if (intstat
& CMDCMPLT
)
6603 struct aic7xxx_scb
*scb
= NULL
;
6605 unsigned char scb_index
;
6607 #ifdef AIC7XXX_VERBOSE_DEBUGGING
6608 if( (p
->isr_count
< 16) && (aic7xxx_verbose
> 0xffff) )
6609 printk(INFO_LEAD
"Command Complete Int.\n", p
->host_no
, -1, -1, -1);
6613 * Clear interrupt status before running the completion loop.
6614 * This eliminates a race condition whereby a command could
6615 * complete between the last check of qoutfifo and the
6616 * CLRCMDINT statement. This would result in us thinking the
6617 * qoutfifo was empty when it wasn't, and in actuality be a lost
6618 * completion interrupt. With multiple devices or tagged queueing
6619 * this could be very bad if we caught all but the last completion
6620 * and no more are imediately sent.
6622 aic_outb(p
, CLRCMDINT
, CLRINT
);
6624 * The sequencer will continue running when it
6625 * issues this interrupt. There may be >1 commands
6626 * finished, so loop until we've processed them all.
6629 while (p
->qoutfifo
[p
->qoutfifonext
] != SCB_LIST_NULL
)
6631 scb_index
= p
->qoutfifo
[p
->qoutfifonext
];
6632 p
->qoutfifo
[p
->qoutfifonext
++] = SCB_LIST_NULL
;
6633 if ( scb_index
>= p
->scb_data
->numscbs
)
6636 scb
= p
->scb_data
->scb_array
[scb_index
];
6639 printk(WARN_LEAD
"CMDCMPLT with invalid SCB index %d\n", p
->host_no
,
6640 -1, -1, -1, scb_index
);
6643 else if (!(scb
->flags
& SCB_ACTIVE
) || (scb
->cmd
== NULL
))
6645 printk(WARN_LEAD
"CMDCMPLT without command for SCB %d, SCB flags "
6646 "0x%x, cmd 0x%lx\n", p
->host_no
, -1, -1, -1, scb_index
, scb
->flags
,
6647 (unsigned long) scb
->cmd
);
6650 else if (scb
->flags
& SCB_QUEUED_ABORT
)
6653 if ( ((aic_inb(p
, LASTPHASE
) & PHASE_MASK
) != P_BUSFREE
) &&
6654 (aic_inb(p
, SCB_TAG
) == scb
->hscb
->tag
) )
6656 unpause_sequencer(p
, FALSE
);
6659 aic7xxx_reset_device(p
, scb
->cmd
->target
, scb
->cmd
->channel
,
6660 scb
->cmd
->lun
, scb
->hscb
->tag
);
6661 scb
->flags
&= ~(SCB_QUEUED_FOR_DONE
| SCB_RESET
| SCB_ABORT
|
6663 unpause_sequencer(p
, FALSE
);
6665 else if (scb
->flags
& SCB_ABORT
)
6668 * We started to abort this, but it completed on us, let it
6669 * through as successful
6671 scb
->flags
&= ~(SCB_ABORT
|SCB_RESET
);
6673 switch (status_byte(scb
->hscb
->target_status
))
6677 scb
->hscb
->target_status
= 0;
6678 scb
->cmd
->result
= 0;
6679 aic7xxx_error(scb
->cmd
) = DID_OK
;
6683 if (scb
->hscb
->residual_SG_segment_count
!= 0)
6685 aic7xxx_calculate_residual(p
, scb
);
6687 cmd
->result
|= (aic7xxx_error(cmd
) << 16);
6688 aic7xxx_done(p
, scb
);
6694 if (intstat
& BRKADRINT
)
6697 unsigned char errno
= aic_inb(p
, ERROR
);
6699 printk(KERN_ERR
"(scsi%d) BRKADRINT error(0x%x):\n", p
->host_no
, errno
);
6700 for (i
= 0; i
< NUMBER(hard_error
); i
++)
6702 if (errno
& hard_error
[i
].errno
)
6704 printk(KERN_ERR
" %s\n", hard_error
[i
].errmesg
);
6707 printk(KERN_ERR
"(scsi%d) SEQADDR=0x%x\n", p
->host_no
,
6708 (((aic_inb(p
, SEQADDR1
) << 8) & 0x100) | aic_inb(p
, SEQADDR0
)));
6709 if (aic7xxx_panic_on_abort
)
6710 aic7xxx_panic_abort(p
, NULL
);
6712 if (errno
& PCIERRSTAT
)
6713 aic7xxx_pci_intr(p
);
6715 if (errno
& (SQPARERR
| ILLOPCODE
| ILLSADDR
))
6718 panic("aic7xxx: unrecoverable BRKADRINT.\n");
6720 if (errno
& ILLHADDR
)
6722 printk(KERN_ERR
"(scsi%d) BUG! Driver accessed chip without first "
6723 "pausing controller!\n", p
->host_no
);
6725 #ifdef AIC7XXX_VERBOSE_DEBUGGING
6726 if (errno
& DPARERR
)
6728 if (aic_inb(p
, DMAPARAMS
) & DIRECTION
)
6729 printk("(scsi%d) while DMAing SCB from host to card.\n", p
->host_no
);
6731 printk("(scsi%d) while DMAing SCB from card to host.\n", p
->host_no
);
6734 aic_outb(p
, CLRPARERR
| CLRBRKADRINT
, CLRINT
);
6735 unpause_sequencer(p
, FALSE
);
6738 if (intstat
& SEQINT
)
6740 aic7xxx_handle_seqint(p
, intstat
);
6743 if (intstat
& SCSIINT
)
6745 aic7xxx_handle_scsiint(p
, intstat
);
6748 #ifdef AIC7XXX_VERBOSE_DEBUGGING
6749 if ( (p
->isr_count
< 16) && (aic7xxx_verbose
> 0xffff) &&
6750 (aic7xxx_panic_on_abort
) && (p
->flags
& AHC_PAGESCBS
) )
6751 aic7xxx_check_scbs(p
, "Bogus settings at end of interrupt.");
6756 /*+F*************************************************************************
6761 * This is a gross hack to solve a problem in linux kernels 2.1.85 and
6762 * above. Please, children, do not try this at home, and if you ever see
6763 * anything like it, please inform the Gross Hack Police immediately
6764 *-F*************************************************************************/
6766 do_aic7xxx_isr(int irq
, void *dev_id
, struct pt_regs
*regs
)
6768 unsigned long cpu_flags
;
6769 struct aic7xxx_host
*p
;
6771 p
= (struct aic7xxx_host
*)dev_id
;
6774 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,1,95)
6775 spin_lock_irqsave(&io_request_lock
, cpu_flags
);
6776 if(test_and_set_bit(AHC_IN_ISR_BIT
, &p
->flags
))
6782 aic7xxx_isr(irq
, dev_id
, regs
);
6783 } while ( (aic_inb(p
, INTSTAT
) & INT_PEND
) );
6784 aic7xxx_done_cmds_complete(p
);
6785 aic7xxx_run_waiting_queues(p
);
6786 clear_bit(AHC_IN_ISR_BIT
, &p
->flags
);
6787 spin_unlock_irqrestore(&io_request_lock
, cpu_flags
);
6789 if(set_bit(AHC_IN_ISR_BIT
, (int *)&p
->flags
))
6796 aic7xxx_isr(irq
, dev_id
, regs
);
6797 } while ( (aic_inb(p
, INTSTAT
) & INT_PEND
) );
6799 aic7xxx_done_cmds_complete(p
);
6800 aic7xxx_run_waiting_queues(p
);
6801 clear_bit(AHC_IN_ISR_BIT
, (int *)&p
->flags
);
6805 /*+F*************************************************************************
6807 * aic7xxx_device_queue_depth
6810 * Determines the queue depth for a given device. There are two ways
6811 * a queue depth can be obtained for a tagged queueing device. One
6812 * way is the default queue depth which is determined by whether
6813 * AIC7XXX_CMDS_PER_DEVICE is defined. If it is defined, then it is used
6814 * as the default queue depth. Otherwise, we use either 4 or 8 as the
6815 * default queue depth (dependent on the number of hardware SCBs).
6816 * The other way we determine queue depth is through the use of the
6817 * aic7xxx_tag_info array which is enabled by defining
6818 * AIC7XXX_TAGGED_QUEUEING_BY_DEVICE. This array can be initialized
6819 * with queue depths for individual devices. It also allows tagged
6820 * queueing to be [en|dis]abled for a specific adapter.
6821 *-F*************************************************************************/
6823 aic7xxx_device_queue_depth(struct aic7xxx_host
*p
, Scsi_Device
*device
)
6825 int default_depth
= 3;
6826 unsigned char tindex
;
6827 unsigned short target_mask
;
6829 tindex
= device
->id
| (device
->channel
<< 3);
6830 target_mask
= (1 << tindex
);
6832 device
->queue_depth
= default_depth
;
6833 p
->dev_temp_queue_depth
[tindex
] = 1;
6834 p
->dev_max_queue_depth
[tindex
] = 1;
6835 p
->tagenable
&= ~target_mask
;
6837 if (device
->tagged_supported
)
6839 int tag_enabled
= TRUE
;
6841 default_depth
= AIC7XXX_CMDS_PER_DEVICE
;
6843 if (!(p
->discenable
& target_mask
))
6845 if (aic7xxx_verbose
& VERBOSE_NEGOTIATION2
)
6846 printk(INFO_LEAD
"Disconnection disabled, unable to "
6847 "enable tagged queueing.\n",
6848 p
->host_no
, device
->channel
, device
->id
, device
->lun
);
6852 if (p
->instance
>= NUMBER(aic7xxx_tag_info
))
6854 static int print_warning
= TRUE
;
6857 printk(KERN_INFO
"aic7xxx: WARNING, insufficient tag_info instances for"
6858 " installed controllers.\n");
6859 printk(KERN_INFO
"aic7xxx: Please update the aic7xxx_tag_info array in"
6860 " the aic7xxx.c source file.\n");
6861 print_warning
= FALSE
;
6863 device
->queue_depth
= default_depth
;
6868 if (aic7xxx_tag_info
[p
->instance
].tag_commands
[tindex
] == 255)
6870 tag_enabled
= FALSE
;
6871 device
->queue_depth
= 3; /* Tagged queueing is disabled. */
6873 else if (aic7xxx_tag_info
[p
->instance
].tag_commands
[tindex
] == 0)
6875 device
->queue_depth
= default_depth
;
6879 device
->queue_depth
=
6880 aic7xxx_tag_info
[p
->instance
].tag_commands
[tindex
];
6883 if ((device
->tagged_queue
== 0) && tag_enabled
)
6885 if (aic7xxx_verbose
& VERBOSE_NEGOTIATION2
)
6887 printk(INFO_LEAD
"Enabled tagged queuing, queue depth %d.\n",
6888 p
->host_no
, device
->channel
, device
->id
,
6889 device
->lun
, device
->queue_depth
);
6891 p
->dev_max_queue_depth
[tindex
] = device
->queue_depth
;
6892 p
->dev_temp_queue_depth
[tindex
] = device
->queue_depth
;
6893 p
->tagenable
|= target_mask
;
6894 p
->orderedtag
|= target_mask
;
6895 device
->tagged_queue
= 1;
6896 device
->current_tag
= SCB_LIST_NULL
;
6902 /*+F*************************************************************************
6904 * aic7xxx_select_queue_depth
6907 * Sets the queue depth for each SCSI device hanging off the input
6908 * host adapter. We use a queue depth of 2 for devices that do not
6909 * support tagged queueing. If AIC7XXX_CMDS_PER_LUN is defined, we
6910 * use that for tagged queueing devices; otherwise we use our own
6911 * algorithm for determining the queue depth based on the maximum
6912 * SCBs for the controller.
6913 *-F*************************************************************************/
6915 aic7xxx_select_queue_depth(struct Scsi_Host
*host
,
6916 Scsi_Device
*scsi_devs
)
6918 Scsi_Device
*device
;
6919 struct aic7xxx_host
*p
= (struct aic7xxx_host
*) host
->hostdata
;
6923 for (device
= scsi_devs
; device
!= NULL
; device
= device
->next
)
6925 if (device
->host
== host
)
6927 aic7xxx_device_queue_depth(p
, device
);
6928 scbnum
+= device
->queue_depth
;
6931 while (scbnum
> p
->scb_data
->numscbs
)
6934 * Pre-allocate the needed SCBs to get around the possibility of having
6935 * to allocate some when memory is more or less exhausted and we need
6936 * the SCB in order to perform a swap operation (possible deadlock)
6938 if ( aic7xxx_allocate_scb(p
) == 0 )
6943 /*+F*************************************************************************
6948 * Probing for EISA boards: it looks like the first two bytes
6949 * are a manufacturer code - three characters, five bits each:
6951 * BYTE 0 BYTE 1 BYTE 2 BYTE 3
6952 * ?1111122 22233333 PPPPPPPP RRRRRRRR
6954 * The characters are baselined off ASCII '@', so add that value
6955 * to each to get the real ASCII code for it. The next two bytes
6956 * appear to be a product and revision number, probably vendor-
6957 * specific. This is what is being searched for at each port,
6958 * and what should probably correspond to the ID= field in the
6959 * ECU's .cfg file for the card - if your card is not detected,
6960 * make sure your signature is listed in the array.
6962 * The fourth byte's lowest bit seems to be an enabled/disabled
6963 * flag (rest of the bits are reserved?).
6965 * NOTE: This function is only needed on Intel and Alpha platforms,
6966 * the other platforms we support don't have EISA/VLB busses. So,
6967 * we #ifdef this entire function to avoid compiler warnings about
6968 * an unused function.
6969 *-F*************************************************************************/
6970 #if defined(__i386__) || defined(__alpha__)
6972 aic7xxx_probe(int slot
, int base
, ahc_flag_type
*flags
)
6975 unsigned char buf
[4];
6979 unsigned char signature
[sizeof(buf
)];
6983 { 4, { 0x04, 0x90, 0x77, 0x70 },
6984 AHC_AIC7770
|AHC_EISA
, FALSE
}, /* mb 7770 */
6985 { 4, { 0x04, 0x90, 0x77, 0x71 },
6986 AHC_AIC7770
|AHC_EISA
, FALSE
}, /* host adapter 274x */
6987 { 4, { 0x04, 0x90, 0x77, 0x56 },
6988 AHC_AIC7770
|AHC_VL
, FALSE
}, /* 284x BIOS enabled */
6989 { 4, { 0x04, 0x90, 0x77, 0x57 },
6990 AHC_AIC7770
|AHC_VL
, TRUE
} /* 284x BIOS disabled */
6994 * The VL-bus cards need to be primed by
6995 * writing before a signature check.
6997 for (i
= 0; i
< sizeof(buf
); i
++)
6999 outb(0x80 + i
, base
);
7000 buf
[i
] = inb(base
+ i
);
7003 for (i
= 0; i
< NUMBER(AIC7xxx
); i
++)
7006 * Signature match on enabled card?
7008 if (!memcmp(buf
, AIC7xxx
[i
].signature
, AIC7xxx
[i
].n
))
7010 if (inb(base
+ 4) & 1)
7012 if (AIC7xxx
[i
].bios_disabled
)
7014 *flags
|= AHC_USEDEFAULTS
;
7018 *flags
|= AHC_BIOS_ENABLED
;
7023 printk("aic7xxx: <Adaptec 7770 SCSI Host Adapter> "
7024 "disabled at slot %d, ignored.\n", slot
);
7030 #endif /* (__i386__) || (__alpha__) */
7033 /*+F*************************************************************************
7038 * Reads the 2840 serial EEPROM and returns 1 if successful and 0 if
7041 * See read_seeprom (for the 2940) for the instruction set of the 93C46
7044 * The 2840 interface to the 93C46 serial EEPROM is through the
7045 * STATUS_2840 and SEECTL_2840 registers. The CS_2840, CK_2840, and
7046 * DO_2840 bits of the SEECTL_2840 register are connected to the chip
7047 * select, clock, and data out lines respectively of the serial EEPROM.
7048 * The DI_2840 bit of the STATUS_2840 is connected to the data in line
7049 * of the serial EEPROM. The EEPROM_TF bit of STATUS_2840 register is
7050 * useful in that it gives us an 800 nsec timer. After a read from the
7051 * SEECTL_2840 register the timing flag is cleared and goes high 800 nsec
7053 *-F*************************************************************************/
7055 read_284x_seeprom(struct aic7xxx_host
*p
, struct seeprom_config
*sc
)
7059 unsigned short checksum
= 0;
7060 unsigned short *seeprom
= (unsigned short *) sc
;
7061 struct seeprom_cmd
{
7063 unsigned char bits
[3];
7065 struct seeprom_cmd seeprom_read
= {3, {1, 1, 0}};
7067 #define CLOCK_PULSE(p) \
7068 while ((aic_inb(p, STATUS_2840) & EEPROM_TF) == 0) \
7070 ; /* Do nothing */ \
7072 (void) aic_inb(p, SEECTL_2840);
7075 * Read the first 32 registers of the seeprom. For the 2840,
7076 * the 93C46 SEEPROM is a 1024-bit device with 64 16-bit registers
7077 * but only the first 32 are used by Adaptec BIOS. The loop
7078 * will range from 0 to 31.
7080 for (k
= 0; k
< (sizeof(*sc
) / 2); k
++)
7083 * Send chip select for one clock cycle.
7085 aic_outb(p
, CK_2840
| CS_2840
, SEECTL_2840
);
7089 * Now we're ready to send the read command followed by the
7090 * address of the 16-bit register we want to read.
7092 for (i
= 0; i
< seeprom_read
.len
; i
++)
7094 temp
= CS_2840
| seeprom_read
.bits
[i
];
7095 aic_outb(p
, temp
, SEECTL_2840
);
7097 temp
= temp
^ CK_2840
;
7098 aic_outb(p
, temp
, SEECTL_2840
);
7102 * Send the 6 bit address (MSB first, LSB last).
7104 for (i
= 5; i
>= 0; i
--)
7107 temp
= (temp
>> i
) & 1; /* Mask out all but lower bit. */
7108 temp
= CS_2840
| temp
;
7109 aic_outb(p
, temp
, SEECTL_2840
);
7111 temp
= temp
^ CK_2840
;
7112 aic_outb(p
, temp
, SEECTL_2840
);
7117 * Now read the 16 bit register. An initial 0 precedes the
7118 * register contents which begins with bit 15 (MSB) and ends
7119 * with bit 0 (LSB). The initial 0 will be shifted off the
7120 * top of our word as we let the loop run from 0 to 16.
7122 for (i
= 0; i
<= 16; i
++)
7125 aic_outb(p
, temp
, SEECTL_2840
);
7127 temp
= temp
^ CK_2840
;
7128 seeprom
[k
] = (seeprom
[k
] << 1) | (aic_inb(p
, STATUS_2840
) & DI_2840
);
7129 aic_outb(p
, temp
, SEECTL_2840
);
7133 * The serial EEPROM has a checksum in the last word. Keep a
7134 * running checksum for all words read except for the last
7135 * word. We'll verify the checksum after all words have been
7138 if (k
< (sizeof(*sc
) / 2) - 1)
7140 checksum
= checksum
+ seeprom
[k
];
7144 * Reset the chip select for the next command cycle.
7146 aic_outb(p
, 0, SEECTL_2840
);
7148 aic_outb(p
, CK_2840
, SEECTL_2840
);
7150 aic_outb(p
, 0, SEECTL_2840
);
7155 printk("Computed checksum 0x%x, checksum read 0x%x\n", checksum
, sc
->checksum
);
7156 printk("Serial EEPROM:");
7157 for (k
= 0; k
< (sizeof(*sc
) / 2); k
++)
7159 if (((k
% 8) == 0) && (k
!= 0))
7163 printk(" 0x%x", seeprom
[k
]);
7168 if (checksum
!= sc
->checksum
)
7170 printk("aic7xxx: SEEPROM checksum error, ignoring SEEPROM settings.\n");
7178 /*+F*************************************************************************
7183 * Acquires access to the memory port on PCI controllers.
7184 *-F*************************************************************************/
7186 acquire_seeprom(struct aic7xxx_host
*p
)
7191 * Request access of the memory port. When access is
7192 * granted, SEERDY will go high. We use a 1 second
7193 * timeout which should be near 1 second more than
7194 * is needed. Reason: after the 7870 chip reset, there
7195 * should be no contention.
7197 aic_outb(p
, SEEMS
, SEECTL
);
7198 wait
= 1000; /* 1000 msec = 1 second */
7199 while ((wait
> 0) && ((aic_inb(p
, SEECTL
) & SEERDY
) == 0))
7202 mdelay(1); /* 1 msec */
7204 if ((aic_inb(p
, SEECTL
) & SEERDY
) == 0)
7206 aic_outb(p
, 0, SEECTL
);
7212 /*+F*************************************************************************
7217 * Releases access to the memory port on PCI controllers.
7218 *-F*************************************************************************/
7220 release_seeprom(struct aic7xxx_host
*p
)
7222 aic_outb(p
, 0, SEECTL
);
7225 /*+F*************************************************************************
7230 * Reads the serial EEPROM and returns 1 if successful and 0 if
7233 * The instruction set of the 93C46/56/66 chips is as follows:
7236 * Function Bit Code Address Data Description
7237 * -------------------------------------------------------------------
7238 * READ 1 10 A5 - A0 Reads data stored in memory,
7239 * starting at specified address
7240 * EWEN 1 00 11XXXX Write enable must precede
7241 * all programming modes
7242 * ERASE 1 11 A5 - A0 Erase register A5A4A3A2A1A0
7243 * WRITE 1 01 A5 - A0 D15 - D0 Writes register
7244 * ERAL 1 00 10XXXX Erase all registers
7245 * WRAL 1 00 01XXXX D15 - D0 Writes to all registers
7246 * EWDS 1 00 00XXXX Disables all programming
7248 * *Note: A value of X for address is a don't care condition.
7249 * *Note: The 93C56 and 93C66 have 8 address bits.
7252 * The 93C46 has a four wire interface: clock, chip select, data in, and
7253 * data out. In order to perform one of the above functions, you need
7254 * to enable the chip select for a clock period (typically a minimum of
7255 * 1 usec, with the clock high and low a minimum of 750 and 250 nsec
7256 * respectively. While the chip select remains high, you can clock in
7257 * the instructions (above) starting with the start bit, followed by the
7258 * OP code, Address, and Data (if needed). For the READ instruction, the
7259 * requested 16-bit register contents is read from the data out line but
7260 * is preceded by an initial zero (leading 0, followed by 16-bits, MSB
7261 * first). The clock cycling from low to high initiates the next data
7262 * bit to be sent from the chip.
7264 * The 78xx interface to the 93C46 serial EEPROM is through the SEECTL
7265 * register. After successful arbitration for the memory port, the
7266 * SEECS bit of the SEECTL register is connected to the chip select.
7267 * The SEECK, SEEDO, and SEEDI are connected to the clock, data out,
7268 * and data in lines respectively. The SEERDY bit of SEECTL is useful
7269 * in that it gives us an 800 nsec timer. After a write to the SEECTL
7270 * register, the SEERDY goes high 800 nsec later. The one exception
7271 * to this is when we first request access to the memory port. The
7272 * SEERDY goes high to signify that access has been granted and, for
7273 * this case, has no implied timing.
7274 *-F*************************************************************************/
7276 read_seeprom(struct aic7xxx_host
*p
, int offset
,
7277 unsigned short *scarray
, unsigned int len
, seeprom_chip_type chip
)
7281 unsigned short checksum
= 0;
7282 struct seeprom_cmd
{
7284 unsigned char bits
[3];
7286 struct seeprom_cmd seeprom_read
= {3, {1, 1, 0}};
7288 #define CLOCK_PULSE(p) \
7289 while ((aic_inb(p, SEECTL) & SEERDY) == 0) \
7291 ; /* Do nothing */ \
7295 * Request access of the memory port.
7297 if (acquire_seeprom(p
) == 0)
7303 * Read 'len' registers of the seeprom. For the 7870, the 93C46
7304 * SEEPROM is a 1024-bit device with 64 16-bit registers but only
7305 * the first 32 are used by Adaptec BIOS. Some adapters use the
7306 * 93C56 SEEPROM which is a 2048-bit device. The loop will range
7307 * from 0 to 'len' - 1.
7309 for (k
= 0; k
< len
; k
++)
7312 * Send chip select for one clock cycle.
7314 aic_outb(p
, SEEMS
| SEECK
| SEECS
, SEECTL
);
7318 * Now we're ready to send the read command followed by the
7319 * address of the 16-bit register we want to read.
7321 for (i
= 0; i
< seeprom_read
.len
; i
++)
7323 temp
= SEEMS
| SEECS
| (seeprom_read
.bits
[i
] << 1);
7324 aic_outb(p
, temp
, SEECTL
);
7326 temp
= temp
^ SEECK
;
7327 aic_outb(p
, temp
, SEECTL
);
7331 * Send the 6 or 8 bit address (MSB first, LSB last).
7333 for (i
= ((int) chip
- 1); i
>= 0; i
--)
7336 temp
= (temp
>> i
) & 1; /* Mask out all but lower bit. */
7337 temp
= SEEMS
| SEECS
| (temp
<< 1);
7338 aic_outb(p
, temp
, SEECTL
);
7340 temp
= temp
^ SEECK
;
7341 aic_outb(p
, temp
, SEECTL
);
7346 * Now read the 16 bit register. An initial 0 precedes the
7347 * register contents which begins with bit 15 (MSB) and ends
7348 * with bit 0 (LSB). The initial 0 will be shifted off the
7349 * top of our word as we let the loop run from 0 to 16.
7351 for (i
= 0; i
<= 16; i
++)
7353 temp
= SEEMS
| SEECS
;
7354 aic_outb(p
, temp
, SEECTL
);
7356 temp
= temp
^ SEECK
;
7357 scarray
[k
] = (scarray
[k
] << 1) | (aic_inb(p
, SEECTL
) & SEEDI
);
7358 aic_outb(p
, temp
, SEECTL
);
7363 * The serial EEPROM should have a checksum in the last word.
7364 * Keep a running checksum for all words read except for the
7365 * last word. We'll verify the checksum after all words have
7370 checksum
= checksum
+ scarray
[k
];
7374 * Reset the chip select for the next command cycle.
7376 aic_outb(p
, SEEMS
, SEECTL
);
7378 aic_outb(p
, SEEMS
| SEECK
, SEECTL
);
7380 aic_outb(p
, SEEMS
, SEECTL
);
7385 * Release access to the memory port and the serial EEPROM.
7390 printk("Computed checksum 0x%x, checksum read 0x%x\n",
7391 checksum
, scarray
[len
- 1]);
7392 printk("Serial EEPROM:");
7393 for (k
= 0; k
< len
; k
++)
7395 if (((k
% 8) == 0) && (k
!= 0))
7399 printk(" 0x%x", scarray
[k
]);
7403 if ( (checksum
!= scarray
[len
- 1]) || (checksum
== 0) )
7412 /*+F*************************************************************************
7417 * Reads the BRDCTL register.
7418 *-F*************************************************************************/
7419 static unsigned char
7420 read_brdctl(struct aic7xxx_host
*p
)
7422 unsigned char brdctl
, value
;
7424 if (p
->features
& AHC_ULTRA2
)
7426 brdctl
= BRDRW_ULTRA2
;
7427 aic_outb(p
, brdctl
, BRDCTL
);
7429 return(aic_inb(p
, BRDCTL
));
7432 if ( !((p
->chip
& AHC_CHIPID_MASK
) == AHC_AIC7895
) ||
7433 (p
->flags
& AHC_CHNLB
) )
7437 aic_outb(p
, brdctl
, BRDCTL
);
7439 value
= aic_inb(p
, BRDCTL
);
7440 aic_outb(p
, 0, BRDCTL
);
7445 /*+F*************************************************************************
7450 * Writes a value to the BRDCTL register.
7451 *-F*************************************************************************/
7453 write_brdctl(struct aic7xxx_host
*p
, unsigned char value
)
7455 unsigned char brdctl
;
7457 if (p
->features
& AHC_ULTRA2
)
7460 aic_outb(p
, brdctl
, BRDCTL
);
7462 brdctl
|= BRDSTB_ULTRA2
;
7463 aic_outb(p
, brdctl
, BRDCTL
);
7465 brdctl
&= ~BRDSTB_ULTRA2
;
7466 aic_outb(p
, brdctl
, BRDCTL
);
7473 if ( !((p
->chip
& AHC_CHIPID_MASK
) == AHC_AIC7895
) ||
7474 (p
->flags
& AHC_CHNLB
) )
7478 brdctl
= BRDSTB
| BRDCS
;
7479 aic_outb(p
, brdctl
, BRDCTL
);
7482 aic_outb(p
, brdctl
, BRDCTL
);
7485 aic_outb(p
, brdctl
, BRDCTL
);
7488 aic_outb(p
, brdctl
, BRDCTL
);
7493 /*+F*************************************************************************
7495 * aic785x_cable_detect
7498 * Detect the cables that are present on aic785x class controller chips
7499 *-F*************************************************************************/
7501 aic785x_cable_detect(struct aic7xxx_host
*p
, int *int_50
,
7502 int *ext_present
, int *eeprom
)
7504 unsigned char brdctl
;
7506 aic_outb(p
, BRDRW
| BRDCS
, BRDCTL
);
7508 aic_outb(p
, 0, BRDCTL
);
7510 brdctl
= aic_inb(p
, BRDCTL
);
7512 *int_50
= !(brdctl
& BRDDAT5
);
7513 *ext_present
= !(brdctl
& BRDDAT6
);
7514 *eeprom
= (aic_inb(p
, SPIOCAP
) & EEPROM
);
7517 /*+F*************************************************************************
7519 * aic787x_cable_detect
7522 * Detect the cables that are present on aic787x class controller chips
7524 * NOTE: This functions assumes the SEEPROM will have already been aquired
7525 * prior to invocation of this function.
7526 *-F*************************************************************************/
7528 aic787x_cable_detect(struct aic7xxx_host
*p
, int *int_50
, int *int_68
,
7529 int *ext_present
, int *eeprom
)
7531 unsigned char brdctl
;
7534 * First read the status of our cables. Set the rom bank to
7535 * 0 since the bank setting serves as a multiplexor for the
7536 * cable detection logic. BRDDAT5 controls the bank switch.
7541 * Now we read the state of the two internal connectors. BRDDAT6
7542 * is internal 50, BRDDAT7 is internal 68. For each, the cable is
7543 * present if the bit is 0
7545 brdctl
= read_brdctl(p
);
7546 *int_50
= !(brdctl
& BRDDAT6
);
7547 *int_68
= !(brdctl
& BRDDAT7
);
7550 * Set the bank bit in brdctl and then read the external cable state
7551 * and the EEPROM status
7553 write_brdctl(p
, BRDDAT5
);
7554 brdctl
= read_brdctl(p
);
7556 *ext_present
= !(brdctl
& BRDDAT6
);
7557 *eeprom
= !(brdctl
& BRDDAT7
);
7560 * We're done, the calling function will release the SEEPROM for us
7564 /*+F*************************************************************************
7566 * aic787x_ultra2_term_detect
7569 * Detect the termination settings present on ultra2 class controllers
7571 * NOTE: This functions assumes the SEEPROM will have already been aquired
7572 * prior to invocation of this function.
7573 *-F*************************************************************************/
7575 aic7xxx_ultra2_term_detect(struct aic7xxx_host
*p
, int *enableSE_low
,
7576 int *enableSE_high
, int *enableLVD_low
,
7577 int *enableLVD_high
, int *eprom_present
)
7579 unsigned char brdctl
;
7581 brdctl
= read_brdctl(p
);
7583 *eprom_present
= (brdctl
& BRDDAT7
);
7584 *enableSE_high
= (brdctl
& BRDDAT6
);
7585 *enableSE_low
= (brdctl
& BRDDAT5
);
7586 *enableLVD_high
= (brdctl
& BRDDAT4
);
7587 *enableLVD_low
= (brdctl
& BRDDAT3
);
7590 /*+F*************************************************************************
7592 * configure_termination
7595 * Configures the termination settings on PCI adapters that have
7596 * SEEPROMs available.
7597 *-F*************************************************************************/
7599 configure_termination(struct aic7xxx_host
*p
)
7601 int internal50_present
= 0;
7602 int internal68_present
= 0;
7603 int external_present
= 0;
7604 int eprom_present
= 0;
7605 int enableSE_low
= 0;
7606 int enableSE_high
= 0;
7607 int enableLVD_low
= 0;
7608 int enableLVD_high
= 0;
7609 unsigned char brddat
= 0;
7610 unsigned char max_target
= 0;
7611 unsigned char sxfrctl1
= aic_inb(p
, SXFRCTL1
);
7613 if (acquire_seeprom(p
))
7615 if (p
->features
& (AHC_WIDE
|AHC_TWIN
))
7619 aic_outb(p
, SEEMS
| SEECS
, SEECTL
);
7620 sxfrctl1
&= ~STPWEN
;
7621 if ( (p
->adapter_control
& CFAUTOTERM
) ||
7622 (p
->features
& AHC_ULTRA2
) )
7624 if ( (p
->adapter_control
& CFAUTOTERM
) && !(p
->features
& AHC_ULTRA2
) )
7626 printk(KERN_INFO
"(scsi%d) Warning - detected auto-termination\n",
7628 printk(KERN_INFO
"(scsi%d) Please verify driver detected settings are "
7629 "correct.\n", p
->host_no
);
7630 printk(KERN_INFO
"(scsi%d) If not, then please properly set the device "
7631 "termination\n", p
->host_no
);
7632 printk(KERN_INFO
"(scsi%d) in the Adaptec SCSI BIOS by hitting CTRL-A "
7633 "when prompted\n", p
->host_no
);
7634 printk(KERN_INFO
"(scsi%d) during machine bootup.\n", p
->host_no
);
7636 /* Configure auto termination. */
7638 if (p
->features
& AHC_ULTRA2
)
7640 if (aic7xxx_override_term
== -1)
7641 aic7xxx_ultra2_term_detect(p
, &enableSE_low
, &enableSE_high
,
7642 &enableLVD_low
, &enableLVD_high
,
7644 if (!(p
->adapter_control
& CFSEAUTOTERM
))
7646 enableSE_low
= (p
->adapter_control
& CFSTERM
);
7647 enableSE_high
= (p
->adapter_control
& CFWSTERM
);
7649 if (!(p
->adapter_control
& CFAUTOTERM
))
7651 enableLVD_low
= enableLVD_high
= (p
->adapter_control
& CFLVDSTERM
);
7653 internal50_present
= 0;
7654 internal68_present
= 1;
7655 external_present
= 1;
7657 else if ( (p
->chip
& AHC_CHIPID_MASK
) >= AHC_AIC7870
)
7659 aic787x_cable_detect(p
, &internal50_present
, &internal68_present
,
7660 &external_present
, &eprom_present
);
7664 aic785x_cable_detect(p
, &internal50_present
, &external_present
,
7668 if (max_target
<= 8)
7669 internal68_present
= 0;
7671 if ( !(p
->features
& AHC_ULTRA2
) )
7675 printk(KERN_INFO
"(scsi%d) Cables present (Int-50 %s, Int-68 %s, "
7676 "Ext-68 %s)\n", p
->host_no
,
7677 internal50_present
? "YES" : "NO",
7678 internal68_present
? "YES" : "NO",
7679 external_present
? "YES" : "NO");
7683 printk(KERN_INFO
"(scsi%d) Cables present (Int-50 %s, Ext-50 %s)\n",
7685 internal50_present
? "YES" : "NO",
7686 external_present
? "YES" : "NO");
7689 if (aic7xxx_verbose
& VERBOSE_PROBE2
)
7690 printk(KERN_INFO
"(scsi%d) EEPROM %s present.\n", p
->host_no
,
7691 eprom_present
? "is" : "is not");
7694 * Now set the termination based on what we found. BRDDAT6
7695 * controls wide termination enable.
7696 * Flash Enable = BRDDAT7
7697 * SE High Term Enable = BRDDAT6
7698 * SE Low Term Enable = BRDDAT5 (7890)
7699 * LVD High Term Enable = BRDDAT4 (7890)
7701 if ( !(p
->features
& AHC_ULTRA2
) &&
7702 (internal50_present
&& internal68_present
&& external_present
) )
7704 printk(KERN_INFO
"(scsi%d) Illegal cable configuration!! Only two\n",
7706 printk(KERN_INFO
"(scsi%d) connectors on the SCSI controller may be "
7707 "in use at a time!\n", p
->host_no
);
7709 * Force termination (low and high byte) on. This is safer than
7710 * leaving it completely off, especially since this message comes
7711 * most often from motherboard controllers that don't even have 3
7712 * connectors, but instead are failing the cable detection.
7714 internal50_present
= external_present
= 0;
7715 enableSE_high
= enableSE_low
= 1;
7718 if ((max_target
> 8) &&
7719 ((external_present
== 0) || (internal68_present
== 0) ||
7720 (enableSE_high
!= 0)))
7723 p
->flags
|= AHC_TERM_ENB_SE_HIGH
;
7724 if (aic7xxx_verbose
& VERBOSE_PROBE2
)
7725 printk(KERN_INFO
"(scsi%d) SE High byte termination Enabled\n",
7729 if ( (((internal50_present
? 1 : 0) +
7730 (internal68_present
? 1 : 0) +
7731 (external_present
? 1 : 0)) <= 1) ||
7732 (enableSE_low
!= 0) )
7734 if (p
->features
& AHC_ULTRA2
)
7738 p
->flags
|= AHC_TERM_ENB_SE_LOW
;
7739 if (aic7xxx_verbose
& VERBOSE_PROBE2
)
7740 printk(KERN_INFO
"(scsi%d) SE Low byte termination Enabled\n",
7744 if (enableLVD_low
!= 0)
7747 p
->flags
|= AHC_TERM_ENB_LVD
;
7748 if (aic7xxx_verbose
& VERBOSE_PROBE2
)
7749 printk(KERN_INFO
"(scsi%d) LVD Low byte termination Enabled\n",
7753 if (enableLVD_high
!= 0)
7756 if (aic7xxx_verbose
& VERBOSE_PROBE2
)
7757 printk(KERN_INFO
"(scsi%d) LVD High byte termination Enabled\n",
7763 if (p
->adapter_control
& CFSTERM
)
7765 if (p
->features
& AHC_ULTRA2
)
7769 if (aic7xxx_verbose
& VERBOSE_PROBE2
)
7770 printk(KERN_INFO
"(scsi%d) SE Low byte termination Enabled\n",
7774 if (p
->adapter_control
& CFWSTERM
)
7777 if (aic7xxx_verbose
& VERBOSE_PROBE2
)
7778 printk(KERN_INFO
"(scsi%d) SE High byte termination Enabled\n",
7782 aic_outb(p
, sxfrctl1
, SXFRCTL1
);
7783 write_brdctl(p
, brddat
);
7788 /*+F*************************************************************************
7793 * Detects the maximum number of SCBs for the controller and returns
7794 * the count and a mask in p (p->maxscbs, p->qcntmask).
7795 *-F*************************************************************************/
7797 detect_maxscb(struct aic7xxx_host
*p
)
7802 * It's possible that we've already done this for multichannel
7805 if (p
->scb_data
->maxhscbs
== 0)
7808 * We haven't initialized the SCB settings yet. Walk the SCBs to
7809 * determince how many there are.
7811 aic_outb(p
, 0, FREE_SCBH
);
7813 for (i
= 0; i
< AIC7XXX_MAXSCB
; i
++)
7815 aic_outb(p
, i
, SCBPTR
);
7816 aic_outb(p
, i
, SCB_CONTROL
);
7817 if (aic_inb(p
, SCB_CONTROL
) != i
)
7819 aic_outb(p
, 0, SCBPTR
);
7820 if (aic_inb(p
, SCB_CONTROL
) != 0)
7823 aic_outb(p
, i
, SCBPTR
);
7824 aic_outb(p
, 0, SCB_CONTROL
); /* Clear the control byte. */
7825 aic_outb(p
, i
+ 1, SCB_NEXT
); /* Set the next pointer. */
7826 aic_outb(p
, SCB_LIST_NULL
, SCB_TAG
); /* Make the tag invalid. */
7827 aic_outb(p
, SCB_LIST_NULL
, SCB_BUSYTARGETS
); /* no busy untagged */
7828 aic_outb(p
, SCB_LIST_NULL
, SCB_BUSYTARGETS
+1);/* targets active yet */
7829 aic_outb(p
, SCB_LIST_NULL
, SCB_BUSYTARGETS
+2);
7830 aic_outb(p
, SCB_LIST_NULL
, SCB_BUSYTARGETS
+3);
7833 /* Make sure the last SCB terminates the free list. */
7834 aic_outb(p
, i
- 1, SCBPTR
);
7835 aic_outb(p
, SCB_LIST_NULL
, SCB_NEXT
);
7837 /* Ensure we clear the first (0) SCBs control byte. */
7838 aic_outb(p
, 0, SCBPTR
);
7839 aic_outb(p
, 0, SCB_CONTROL
);
7841 p
->scb_data
->maxhscbs
= i
;
7843 * Use direct indexing instead for speed
7845 if ( i
== AIC7XXX_MAXSCB
)
7846 p
->flags
&= ~AHC_PAGESCBS
;
7851 /*+F*************************************************************************
7856 * Register a Adaptec aic7xxx chip SCSI controller with the kernel.
7857 *-F*************************************************************************/
7859 aic7xxx_register(Scsi_Host_Template
*template, struct aic7xxx_host
*p
,
7865 unsigned char term
, scsi_conf
;
7866 struct Scsi_Host
*host
;
7869 * Lock out other contenders for our i/o space.
7871 request_region(p
->base
, MAXREG
- MINREG
, "aic7xxx");
7876 p
->scb_data
->maxscbs
= AIC7XXX_MAXSCB
;
7877 host
->can_queue
= AIC7XXX_MAXSCB
;
7878 host
->cmd_per_lun
= 3;
7879 host
->sg_tablesize
= AIC7XXX_MAX_SG
;
7880 host
->select_queue_depths
= aic7xxx_select_queue_depth
;
7881 host
->this_id
= p
->scsi_id
;
7882 host
->io_port
= p
->base
;
7883 host
->n_io_port
= 0xFF;
7884 host
->base
= (unsigned char *) p
->mbase
;
7886 if (p
->features
& AHC_WIDE
)
7890 if (p
->features
& AHC_TWIN
)
7892 host
->max_channel
= 1;
7896 p
->host_no
= host
->host_no
;
7897 host
->unique_id
= p
->instance
;
7900 p
->completeq
.head
= NULL
;
7901 p
->completeq
.tail
= NULL
;
7902 scbq_init(&p
->scb_data
->free_scbs
);
7903 scbq_init(&p
->waiting_scbs
);
7904 init_timer(&p
->dev_timer
);
7905 p
->dev_timer
.data
= (unsigned long)p
;
7906 p
->dev_timer
.function
= (void *)aic7xxx_timer
;
7907 p
->dev_timer_active
= 0;
7909 for (i
= 0; i
< NUMBER(p
->untagged_scbs
); i
++)
7911 p
->untagged_scbs
[i
] = SCB_LIST_NULL
;
7912 p
->qinfifo
[i
] = SCB_LIST_NULL
;
7913 p
->qoutfifo
[i
] = SCB_LIST_NULL
;
7916 * We currently have no commands of any type
7919 p
->qoutfifonext
= 0;
7921 for (i
= 0; i
< MAX_TARGETS
; i
++)
7923 p
->dev_commands_sent
[i
] = 0;
7924 p
->dev_flags
[i
] = 0;
7925 p
->dev_active_cmds
[i
] = 0;
7926 p
->dev_last_queue_full
[i
] = 0;
7927 p
->dev_last_queue_full_count
[i
] = 0;
7928 p
->dev_max_queue_depth
[i
] = 1;
7929 p
->dev_temp_queue_depth
[i
] = 1;
7930 p
->dev_expires
[i
] = 0;
7931 scbq_init(&p
->delayed_scbs
[i
]);
7934 printk(KERN_INFO
"(scsi%d) <%s> found at ", p
->host_no
,
7935 board_names
[p
->board_name_index
]);
7938 case (AHC_AIC7770
|AHC_EISA
):
7939 printk("EISA slot %d\n", p
->pci_device_fn
);
7941 case (AHC_AIC7770
|AHC_VL
):
7942 printk("VLB slot %d\n", p
->pci_device_fn
);
7945 printk("PCI %d/%d\n", PCI_SLOT(p
->pci_device_fn
),
7946 PCI_FUNC(p
->pci_device_fn
));
7949 if (p
->features
& AHC_TWIN
)
7951 printk(KERN_INFO
"(scsi%d) Twin Channel, A SCSI ID %d, B SCSI ID %d, ",
7952 p
->host_no
, p
->scsi_id
, p
->scsi_id_b
);
7960 if ((p
->flags
& AHC_MULTI_CHANNEL
) != 0)
7964 if ( (p
->flags
& (AHC_CHNLB
|AHC_CHNLC
)) != 0 )
7966 channel
= (p
->flags
& AHC_CHNLB
) ? " B" : " C";
7969 if (p
->features
& AHC_WIDE
)
7971 printk(KERN_INFO
"(scsi%d) Wide ", p
->host_no
);
7975 printk(KERN_INFO
"(scsi%d) Narrow ", p
->host_no
);
7977 printk("Channel%s, SCSI ID=%d, ", channel
, p
->scsi_id
);
7979 aic_outb(p
, 0, SEQ_FLAGS
);
7984 printk("%d/%d SCBs\n", p
->scb_data
->maxhscbs
, p
->scb_data
->maxscbs
);
7985 if (aic7xxx_verbose
& VERBOSE_PROBE2
)
7987 printk(KERN_INFO
"(scsi%d) BIOS %sabled, IO Port 0x%lx, IRQ %d\n",
7988 p
->host_no
, (p
->flags
& AHC_BIOS_ENABLED
) ? "en" : "dis",
7990 printk(KERN_INFO
"(scsi%d) IO Memory at 0x%lx, MMAP Memory at 0x%lx\n",
7991 p
->host_no
, p
->mbase
, (unsigned long)p
->maddr
);
7996 * Now that we know our instance number, we can set the flags we need to
7997 * force termination if need be.
7999 if (aic7xxx_stpwlev
!= -1)
8002 * This option only applies to PCI controllers.
8004 if ( (p
->chip
& ~AHC_CHIPID_MASK
) == AHC_PCI
)
8006 unsigned char devconfig
;
8008 #if LINUX_KERNEL_VERSION > KERNEL_VERSION(2,1,92)
8009 pci_read_config_byte(p
->pdev
, DEVCONFIG
, &devconfig
);
8011 pcibios_read_config_byte(p
->pci_bus
, p
->pci_device_fn
,
8012 DEVCONFIG
, &devconfig
);
8014 if ( (aic7xxx_stpwlev
>> p
->instance
) & 0x01 )
8017 if (aic7xxx_verbose
& VERBOSE_PROBE2
)
8018 printk("(scsi%d) Force setting STPWLEV bit\n", p
->host_no
);
8023 if (aic7xxx_verbose
& VERBOSE_PROBE2
)
8024 printk("(scsi%d) Force clearing STPWLEV bit\n", p
->host_no
);
8026 #if LINUX_KERNEL_VERSION > KERNEL_VERSION(2,1,92)
8027 pci_write_config_byte(p
->pdev
, DEVCONFIG
, devconfig
);
8029 pcibios_write_config_byte(p
->pci_bus
, p
->pci_device_fn
,
8030 DEVCONFIG
, devconfig
);
8037 * That took care of devconfig and stpwlev, now for the actual termination
8040 if (aic7xxx_override_term
!= -1)
8043 * Again, this only applies to PCI controllers. We don't have problems
8044 * with the termination on 274x controllers to the best of my knowledge.
8046 if ( (p
->chip
& ~AHC_CHIPID_MASK
) == AHC_PCI
)
8048 unsigned char term_override
;
8050 term_override
= ( (aic7xxx_override_term
>> (p
->instance
* 4)) & 0x0f);
8051 p
->adapter_control
&=
8052 ~(CFSTERM
|CFWSTERM
|CFLVDSTERM
|CFAUTOTERM
|CFSEAUTOTERM
);
8053 if ( (p
->features
& AHC_ULTRA2
) && (term_override
& 0x0c) )
8055 p
->adapter_control
|= CFLVDSTERM
;
8057 if (term_override
& 0x02)
8059 p
->adapter_control
|= CFWSTERM
;
8061 if (term_override
& 0x01)
8063 p
->adapter_control
|= CFSTERM
;
8068 if ( (p
->flags
& AHC_SEEPROM_FOUND
) || (aic7xxx_override_term
!= -1) )
8070 if (p
->features
& AHC_SPIOCAP
)
8072 if ( aic_inb(p
, SPIOCAP
) & SSPIOCPS
)
8074 * Update the settings in sxfrctl1 to match the termination
8077 configure_termination(p
);
8079 else if ((p
->chip
& AHC_CHIPID_MASK
) >= AHC_AIC7870
)
8081 configure_termination(p
);
8086 * Clear out any possible pending interrupts.
8088 aic7xxx_clear_intstat(p
);
8091 * Set the SCSI Id, SXFRCTL0, SXFRCTL1, and SIMODE1, for both channels
8093 if (p
->features
& AHC_TWIN
)
8095 /* Select channel B */
8096 aic_outb(p
, aic_inb(p
, SBLKCTL
) | SELBUSB
, SBLKCTL
);
8098 if ((p
->flags
& AHC_SEEPROM_FOUND
) || (aic7xxx_override_term
!= -1))
8099 term
= (aic_inb(p
, SXFRCTL1
) & STPWEN
);
8101 term
= ((p
->flags
& AHC_TERM_ENB_B
) ? STPWEN
: 0);
8103 aic_outb(p
, p
->scsi_id_b
, SCSIID
);
8104 scsi_conf
= aic_inb(p
, SCSICONF
+ 1);
8105 aic_outb(p
, DFON
| SPIOEN
, SXFRCTL0
);
8106 aic_outb(p
, (scsi_conf
& ENSPCHK
) | STIMESEL
| term
|
8107 ENSTIMER
| ACTNEGEN
, SXFRCTL1
);
8108 aic_outb(p
, 0, SIMODE0
);
8109 aic_outb(p
, ENSELTIMO
| ENSCSIRST
| ENSCSIPERR
, SIMODE1
);
8110 aic_outb(p
, 0, SCSIRATE
);
8112 /* Select channel A */
8113 aic_outb(p
, aic_inb(p
, SBLKCTL
) & ~SELBUSB
, SBLKCTL
);
8116 if (p
->features
& AHC_ULTRA2
)
8118 aic_outb(p
, p
->scsi_id
, SCSIID_ULTRA2
);
8122 aic_outb(p
, p
->scsi_id
, SCSIID
);
8124 if ((p
->flags
& AHC_SEEPROM_FOUND
) || (aic7xxx_override_term
!= -1))
8125 term
= (aic_inb(p
, SXFRCTL1
) & STPWEN
);
8127 term
= ((p
->flags
& (AHC_TERM_ENB_A
|AHC_TERM_ENB_LVD
)) ? STPWEN
: 0);
8128 scsi_conf
= aic_inb(p
, SCSICONF
);
8129 aic_outb(p
, DFON
| SPIOEN
, SXFRCTL0
);
8130 aic_outb(p
, (scsi_conf
& ENSPCHK
) | STIMESEL
| term
|
8131 ENSTIMER
| ACTNEGEN
, SXFRCTL1
);
8132 aic_outb(p
, 0, SIMODE0
);
8133 aic_outb(p
, ENSELTIMO
| ENSCSIRST
| ENSCSIPERR
, SIMODE1
);
8134 aic_outb(p
, 0, SCSIRATE
);
8135 if ( p
->features
& AHC_ULTRA2
)
8136 aic_outb(p
, 0, SCSIOFFSET
);
8139 * Look at the information that board initialization or the board
8140 * BIOS has left us. In the lower four bits of each target's
8141 * scratch space any value other than 0 indicates that we should
8142 * initiate synchronous transfers. If it's zero, the user or the
8143 * BIOS has decided to disable synchronous negotiation to that
8144 * target so we don't activate the needsdtr flag.
8146 if ((p
->features
& (AHC_TWIN
|AHC_WIDE
)) == 0)
8155 if (!(aic7xxx_no_reset
))
8158 * If we reset the bus, then clear the transfer settings, else leave
8161 for (i
= 0; i
< max_targets
; i
++)
8163 aic_outb(p
, 0, TARG_SCSIRATE
+ i
);
8164 if (p
->features
& AHC_ULTRA2
)
8166 aic_outb(p
, 0, TARG_OFFSET
+ i
);
8168 p
->transinfo
[i
].cur_offset
= 0;
8169 p
->transinfo
[i
].cur_period
= 0;
8170 p
->transinfo
[i
].cur_width
= MSG_EXT_WDTR_BUS_8_BIT
;
8174 * If we reset the bus, then clear the transfer settings, else leave
8177 aic_outb(p
, 0, ULTRA_ENB
);
8178 aic_outb(p
, 0, ULTRA_ENB
+ 1);
8183 * Allocate enough hardware scbs to handle the maximum number of
8184 * concurrent transactions we can have. We have to make sure that
8185 * the allocated memory is contiguous memory. The Linux kmalloc
8186 * routine should only allocate contiguous memory, but note that
8187 * this could be a problem if kmalloc() is changed.
8191 unsigned int hscb_physaddr
;
8194 array_size
= p
->scb_data
->maxscbs
* sizeof(struct aic7xxx_hwscb
);
8195 if (p
->scb_data
->hscbs
== NULL
)
8198 * A little padding so we can align thing the way we want
8200 p
->scb_data
->hscbs
= kmalloc(array_size
+ 0x1f, GFP_ATOMIC
);
8202 if (p
->scb_data
->hscbs
== NULL
)
8204 printk("(scsi%d) Unable to allocate hardware SCB array; "
8205 "failing detection.\n", p
->host_no
);
8210 * Save the actual kmalloc buffer pointer off, then align our
8211 * buffer to a 32 byte boundary
8213 p
->scb_data
->hscb_kmalloc_ptr
= p
->scb_data
->hscbs
;
8214 temp
= (unsigned long)p
->scb_data
->hscbs
;
8217 p
->scb_data
->hscbs
= (struct aic7xxx_hwscb
*)temp
;
8218 /* At least the control byte of each SCB needs to be 0. */
8219 memset(p
->scb_data
->hscbs
, 0, array_size
);
8221 /* Tell the sequencer where it can find the hardware SCB array. */
8222 hscb_physaddr
= VIRT_TO_BUS(p
->scb_data
->hscbs
);
8223 aic_outb(p
, hscb_physaddr
& 0xFF, HSCB_ADDR
);
8224 aic_outb(p
, (hscb_physaddr
>> 8) & 0xFF, HSCB_ADDR
+ 1);
8225 aic_outb(p
, (hscb_physaddr
>> 16) & 0xFF, HSCB_ADDR
+ 2);
8226 aic_outb(p
, (hscb_physaddr
>> 24) & 0xFF, HSCB_ADDR
+ 3);
8228 /* Set up the fifo areas at the same time */
8229 hscb_physaddr
= VIRT_TO_BUS(&p
->untagged_scbs
[0]);
8230 aic_outb(p
, hscb_physaddr
& 0xFF, SCBID_ADDR
);
8231 aic_outb(p
, (hscb_physaddr
>> 8) & 0xFF, SCBID_ADDR
+ 1);
8232 aic_outb(p
, (hscb_physaddr
>> 16) & 0xFF, SCBID_ADDR
+ 2);
8233 aic_outb(p
, (hscb_physaddr
>> 24) & 0xFF, SCBID_ADDR
+ 3);
8236 /* The Q-FIFOs we just set up are all empty */
8237 aic_outb(p
, 0, QINPOS
);
8238 aic_outb(p
, 0, KERNEL_QINPOS
);
8239 aic_outb(p
, 0, QOUTPOS
);
8241 if(p
->features
& AHC_QUEUE_REGS
)
8243 aic_outb(p
, SCB_QSIZE_256
, QOFF_CTLSTA
);
8244 aic_outb(p
, 0, SDSCB_QOFF
);
8245 aic_outb(p
, 0, SNSCB_QOFF
);
8246 aic_outb(p
, 0, HNSCB_QOFF
);
8250 * We don't have any waiting selections or disconnected SCBs.
8252 aic_outb(p
, SCB_LIST_NULL
, WAITING_SCBH
);
8253 aic_outb(p
, SCB_LIST_NULL
, DISCONNECTED_SCBH
);
8256 * Message out buffer starts empty
8258 aic_outb(p
, MSG_NOOP
, MSG_OUT
);
8259 aic_outb(p
, MSG_NOOP
, LAST_MSG
);
8262 * Set all the other asundry items that haven't been set yet.
8263 * This includes just dumping init values to a lot of registers simply
8264 * to make sure they've been touched and are ready for use parity wise
8267 aic_outb(p
, 0, TMODE_CMDADDR
);
8268 aic_outb(p
, 0, TMODE_CMDADDR
+ 1);
8269 aic_outb(p
, 0, TMODE_CMDADDR
+ 2);
8270 aic_outb(p
, 0, TMODE_CMDADDR
+ 3);
8271 aic_outb(p
, 0, TMODE_CMDADDR_NEXT
);
8274 * Link us into the list of valid hosts
8276 p
->next
= first_aic7xxx
;
8280 * Clear out any possible pending interrupts, again.
8282 aic7xxx_clear_intstat(p
);
8285 * Allocate the first set of scbs for this controller. This is to stream-
8286 * line code elsewhere in the driver. If we have to check for the existence
8287 * of scbs in certain code sections, it slows things down. However, as
8288 * soon as we register the IRQ for this card, we could get an interrupt that
8289 * includes possibly the SCSI_RSTI interrupt. If we catch that interrupt
8290 * then we are likely to segfault if we don't have at least one chunk of
8291 * SCBs allocated or add checks all through the reset code to make sure
8292 * that the SCBs have been allocated which is an invalid running condition
8293 * and therefore I think it's preferable to simply pre-allocate the first
8296 aic7xxx_allocate_scb(p
);
8299 * Load the sequencer program, then re-enable the board -
8300 * resetting the AIC-7770 disables it, leaving the lights
8301 * on with nobody home.
8306 * Make sure the AUTOFLUSHDIS bit is *not* set in the SBLKCTL register
8308 aic_outb(p
, aic_inb(p
, SBLKCTL
) & ~AUTOFLUSHDIS
, SBLKCTL
);
8310 if ( (p
->chip
& AHC_CHIPID_MASK
) == AHC_AIC7770
)
8312 aic_outb(p
, ENABLE
, BCTL
); /* Enable the boards BUS drivers. */
8315 if ( !(aic7xxx_no_reset
) )
8317 if (p
->features
& AHC_TWIN
)
8319 if (aic7xxx_verbose
& VERBOSE_PROBE2
)
8320 printk(KERN_INFO
"(scsi%d) Resetting channel B\n", p
->host_no
);
8321 aic_outb(p
, aic_inb(p
, SBLKCTL
) | SELBUSB
, SBLKCTL
);
8322 aic7xxx_reset_current_bus(p
);
8323 aic_outb(p
, aic_inb(p
, SBLKCTL
) & ~SELBUSB
, SBLKCTL
);
8325 /* Reset SCSI bus A. */
8326 if (aic7xxx_verbose
& VERBOSE_PROBE2
)
8327 { /* In case we are a 3940, 3985, or 7895, print the right channel */
8329 if (p
->flags
& AHC_MULTI_CHANNEL
)
8332 if (p
->flags
& (AHC_CHNLB
|AHC_CHNLC
))
8333 channel
= (p
->flags
& AHC_CHNLB
) ? " B" : " C";
8335 printk(KERN_INFO
"(scsi%d) Resetting channel%s\n", p
->host_no
, channel
);
8339 * Some of the new Ultra2 chipsets need a longer delay after a chip
8340 * reset than just the init setup creates, so we have to delay here
8341 * before we go into a reset in order to make the chips happy.
8343 if (p
->features
& AHC_ULTRA2
)
8345 aic7xxx_reset_current_bus(p
);
8348 * Delay for the reset delay.
8351 aic7xxx_delay(AIC7XXX_RESET_DELAY
);
8357 printk(KERN_INFO
"(scsi%d) Not resetting SCSI bus. Note: Don't use "
8358 "the no_reset\n", p
->host_no
);
8359 printk(KERN_INFO
"(scsi%d) option unless you have a verifiable need "
8360 "for it.\n", p
->host_no
);
8361 printk(KERN_INFO
"(scsi%d) The no_reset option is known to break some "
8362 "systems,\n", p
->host_no
);
8363 printk(KERN_INFO
"(scsi%d) and is not supported by the driver author\n",
8365 aic7xxx_delay(AIC7XXX_RESET_DELAY
);
8370 * Register IRQ with the kernel. Only allow sharing IRQs with
8373 if (!(p
->chip
& AHC_PCI
))
8375 result
= (request_irq(p
->irq
, do_aic7xxx_isr
, 0, "aic7xxx", p
));
8379 result
= (request_irq(p
->irq
, do_aic7xxx_isr
, SA_SHIRQ
,
8383 result
= (request_irq(p
->irq
, do_aic7xxx_isr
, SA_INTERRUPT
| SA_SHIRQ
,
8389 printk(KERN_WARNING
"(scsi%d) Couldn't register IRQ %d, ignoring "
8390 "controller.\n", p
->host_no
, p
->irq
);
8395 unpause_sequencer(p
, /* unpause_always */ TRUE
);
8400 /*+F*************************************************************************
8402 * aic7xxx_chip_reset
8405 * Perform a chip reset on the aic7xxx SCSI controller. The controller
8406 * is paused upon return.
8407 *-F*************************************************************************/
8409 aic7xxx_chip_reset(struct aic7xxx_host
*p
)
8411 unsigned char sblkctl
;
8415 * For some 274x boards, we must clear the CHIPRST bit and pause
8416 * the sequencer. For some reason, this makes the driver work.
8418 aic_outb(p
, PAUSE
| CHIPRST
, HCNTRL
);
8421 * In the future, we may call this function as a last resort for
8422 * error handling. Let's be nice and not do any unecessary delays.
8424 wait
= 1000; /* 1 second (1000 * 1 msec) */
8425 while (--wait
&& !(aic_inb(p
, HCNTRL
) & CHIPRSTACK
))
8427 mdelay(1); /* 1 msec */
8432 sblkctl
= aic_inb(p
, SBLKCTL
) & (SELBUSB
|SELWIDE
);
8433 if (p
->chip
& AHC_PCI
)
8434 sblkctl
&= ~SELBUSB
;
8437 case 0: /* normal narrow card */
8439 case 2: /* Wide card */
8440 p
->features
|= AHC_WIDE
;
8442 case 8: /* Twin card */
8443 p
->features
|= AHC_TWIN
;
8444 p
->flags
|= AHC_MULTI_CHANNEL
;
8446 default: /* hmmm...we don't know what this is */
8447 printk(KERN_WARNING
"aic7xxx: Unsupported adapter type %d, ignoring.\n",
8448 aic_inb(p
, SBLKCTL
) & 0x0a);
8454 /*+F*************************************************************************
8459 * Allocate and initialize a host structure. Returns NULL upon error
8460 * and a pointer to a aic7xxx_host struct upon success.
8461 *-F*************************************************************************/
8462 static struct aic7xxx_host
*
8463 aic7xxx_alloc(Scsi_Host_Template
*sht
, struct aic7xxx_host
*temp
)
8465 struct aic7xxx_host
*p
= NULL
;
8466 struct Scsi_Host
*host
;
8470 * Allocate a storage area by registering us with the mid-level
8473 host
= scsi_register(sht
, sizeof(struct aic7xxx_host
));
8477 p
= (struct aic7xxx_host
*) host
->hostdata
;
8478 memset(p
, 0, sizeof(struct aic7xxx_host
));
8482 p
->scb_data
= kmalloc(sizeof(scb_data_type
), GFP_ATOMIC
);
8483 if (p
->scb_data
!= NULL
)
8485 memset(p
->scb_data
, 0, sizeof(scb_data_type
));
8486 scbq_init (&p
->scb_data
->free_scbs
);
8491 * For some reason we don't have enough memory. Free the
8492 * allocated memory for the aic7xxx_host struct, and return NULL.
8494 release_region(p
->base
, MAXREG
- MINREG
);
8495 scsi_unregister(host
);
8498 p
->host_no
= host
->host_no
;
8501 for (i
=0; i
<MAX_TARGETS
; i
++)
8503 p
->transinfo
[i
].goal_period
= 0;
8504 p
->transinfo
[i
].goal_offset
= 0;
8505 p
->transinfo
[i
].goal_options
= 0;
8506 p
->transinfo
[i
].goal_width
= MSG_EXT_WDTR_BUS_8_BIT
;
8513 /*+F*************************************************************************
8518 * Frees and releases all resources associated with an instance of
8519 * the driver (struct aic7xxx_host *).
8520 *-F*************************************************************************/
8522 aic7xxx_free(struct aic7xxx_host
*p
)
8527 * Free the allocated hardware SCB space.
8529 if (p
->scb_data
!= NULL
)
8531 if (p
->scb_data
->hscbs
!= NULL
)
8533 kfree(p
->scb_data
->hscb_kmalloc_ptr
);
8534 p
->scb_data
->hscbs
= p
->scb_data
->hscb_kmalloc_ptr
= NULL
;
8537 * Free the driver SCBs. These were allocated on an as-need
8538 * basis. We allocated these in groups depending on how many
8539 * we could fit into a given amount of RAM. The tail SCB for
8540 * these allocations has a pointer to the alloced area.
8542 for (i
= 0; i
< p
->scb_data
->numscbs
; i
++)
8544 if (p
->scb_data
->scb_array
[i
]->kmalloc_ptr
!= NULL
)
8545 kfree(p
->scb_data
->scb_array
[i
]->kmalloc_ptr
);
8546 p
->scb_data
->scb_array
[i
] = NULL
;
8550 * Free the SCB data area.
8556 * Free any alloced Scsi_Cmnd structures that might be around for
8557 * negotiation purposes....
8559 for (i
= 0; i
< MAX_TARGETS
; i
++)
8561 if(p
->dev_dtr_cmnd
[i
])
8563 if(p
->dev_dtr_cmnd
[i
]->request_buffer
)
8565 kfree(p
->dev_dtr_cmnd
[i
]->request_buffer
);
8567 kfree(p
->dev_dtr_cmnd
[i
]);
8573 /*+F*************************************************************************
8575 * aic7xxx_load_seeprom
8578 * Load the seeprom and configure adapter and target settings.
8579 * Returns 1 if the load was successful and 0 otherwise.
8580 *-F*************************************************************************/
8582 aic7xxx_load_seeprom(struct aic7xxx_host
*p
, unsigned char *sxfrctl1
)
8584 int have_seeprom
= 0;
8585 int i
, max_targets
, mask
;
8586 unsigned char scsirate
, scsi_conf
;
8587 unsigned short scarray
[128];
8588 struct seeprom_config
*sc
= (struct seeprom_config
*) scarray
;
8590 if (aic7xxx_verbose
& VERBOSE_PROBE2
)
8592 printk(KERN_INFO
"aic7xxx: Loading serial EEPROM...");
8596 case (AHC_AIC7770
|AHC_EISA
): /* None of these adapters have seeproms. */
8597 if (aic_inb(p
, SCSICONF
) & TERM_ENB
)
8598 p
->flags
|= AHC_TERM_ENB_A
;
8599 if ( (p
->features
& AHC_TWIN
) && (aic_inb(p
, SCSICONF
+ 1) & TERM_ENB
) )
8600 p
->flags
|= AHC_TERM_ENB_B
;
8603 case (AHC_AIC7770
|AHC_VL
):
8604 have_seeprom
= read_284x_seeprom(p
, (struct seeprom_config
*) scarray
);
8608 have_seeprom
= read_seeprom(p
, (p
->flags
& (AHC_CHNLB
|AHC_CHNLC
)),
8609 scarray
, p
->sc_size
, p
->sc_type
);
8612 if(p
->sc_type
== C46
)
8613 have_seeprom
= read_seeprom(p
, (p
->flags
& (AHC_CHNLB
|AHC_CHNLC
)),
8614 scarray
, p
->sc_size
, C56_66
);
8616 have_seeprom
= read_seeprom(p
, (p
->flags
& (AHC_CHNLB
|AHC_CHNLC
)),
8617 scarray
, p
->sc_size
, C46
);
8622 have_seeprom
= read_seeprom(p
, (p
->flags
& (AHC_CHNLB
|AHC_CHNLC
)),
8623 scarray
, p
->sc_size
, p
->sc_type
);
8626 if(p
->sc_type
== C46
)
8627 have_seeprom
= read_seeprom(p
, (p
->flags
& (AHC_CHNLB
|AHC_CHNLC
)),
8628 scarray
, p
->sc_size
, C56_66
);
8630 have_seeprom
= read_seeprom(p
, (p
->flags
& (AHC_CHNLB
|AHC_CHNLC
)),
8631 scarray
, p
->sc_size
, C46
);
8639 if (aic7xxx_verbose
& VERBOSE_PROBE2
)
8641 printk("\naic7xxx: No SEEPROM available.\n");
8643 p
->flags
|= AHC_NEWEEPROM_FMT
;
8644 if (aic_inb(p
, SCSISEQ
) == 0)
8646 p
->flags
|= AHC_USEDEFAULTS
;
8647 p
->flags
&= ~AHC_BIOS_ENABLED
;
8648 p
->scsi_id
= p
->scsi_id_b
= 7;
8649 *sxfrctl1
|= STPWEN
;
8650 if (aic7xxx_verbose
& VERBOSE_PROBE2
)
8652 printk("aic7xxx: Using default values.\n");
8655 else if (aic7xxx_verbose
& VERBOSE_PROBE2
)
8657 printk("aic7xxx: Using leftover BIOS values.\n");
8659 if ( ((p
->chip
& ~AHC_CHIPID_MASK
) == AHC_PCI
) && (*sxfrctl1
& STPWEN
) )
8661 p
->flags
|= AHC_TERM_ENB_SE_LOW
| AHC_TERM_ENB_SE_HIGH
;
8662 sc
->adapter_control
&= ~CFAUTOTERM
;
8663 sc
->adapter_control
|= CFSTERM
| CFWSTERM
| CFLVDSTERM
;
8665 if (aic7xxx_extended
)
8666 p
->flags
|= (AHC_EXTEND_TRANS_A
| AHC_EXTEND_TRANS_B
);
8668 p
->flags
&= ~(AHC_EXTEND_TRANS_A
| AHC_EXTEND_TRANS_B
);
8672 if (aic7xxx_verbose
& VERBOSE_PROBE2
)
8678 * Note things in our flags
8680 p
->flags
|= AHC_SEEPROM_FOUND
;
8683 * Update the settings in sxfrctl1 to match the termination settings.
8688 * Get our SCSI ID from the SEEPROM setting...
8690 p
->scsi_id
= (sc
->brtime_id
& CFSCSIID
);
8693 * First process the settings that are different between the VLB
8694 * and PCI adapter seeproms.
8696 if ((p
->chip
& AHC_CHIPID_MASK
) == AHC_AIC7770
)
8698 /* VLB adapter seeproms */
8699 if (sc
->bios_control
& CF284XEXTEND
)
8700 p
->flags
|= AHC_EXTEND_TRANS_A
;
8702 if (sc
->adapter_control
& CF284XSTERM
)
8704 *sxfrctl1
|= STPWEN
;
8705 p
->flags
|= AHC_TERM_ENB_SE_LOW
| AHC_TERM_ENB_SE_HIGH
;
8710 /* PCI adapter seeproms */
8711 if (sc
->bios_control
& CFEXTEND
)
8712 p
->flags
|= AHC_EXTEND_TRANS_A
;
8713 if (sc
->bios_control
& CFBIOSEN
)
8714 p
->flags
|= AHC_BIOS_ENABLED
;
8716 p
->flags
&= ~AHC_BIOS_ENABLED
;
8718 if (sc
->adapter_control
& CFSTERM
)
8720 *sxfrctl1
|= STPWEN
;
8721 p
->flags
|= AHC_TERM_ENB_SE_LOW
| AHC_TERM_ENB_SE_HIGH
;
8730 * Limit to 16 targets just in case. The 2842 for one is known to
8731 * blow the max_targets setting, future cards might also.
8733 max_targets
= ((p
->features
& (AHC_TWIN
| AHC_WIDE
)) ? 16 : 8);
8737 for (i
= 0; i
< max_targets
; i
++)
8739 if( ((p
->features
& AHC_ULTRA
) &&
8740 !(sc
->adapter_control
& CFULTRAEN
) &&
8741 (sc
->device_flags
[i
] & CFSYNCHISULTRA
)) ||
8742 (sc
->device_flags
[i
] & CFNEWULTRAFORMAT
) )
8744 p
->flags
|= AHC_NEWEEPROM_FMT
;
8750 for (i
= 0; i
< max_targets
; i
++)
8755 if (aic_inb(p
, SCSISEQ
) != 0)
8758 * OK...the BIOS set things up and left behind the settings we need.
8759 * Just make our sc->device_flags[i] entry match what the card has
8760 * set for this device.
8763 ~(aic_inb(p
, DISC_DSB
) | (aic_inb(p
, DISC_DSB
+ 1) << 8) );
8765 (aic_inb(p
, ULTRA_ENB
) | (aic_inb(p
, ULTRA_ENB
+ 1) << 8) );
8766 sc
->device_flags
[i
] = (p
->discenable
& mask
) ? CFDISC
: 0;
8767 if (aic_inb(p
, TARG_SCSIRATE
+ i
) & WIDEXFER
)
8768 sc
->device_flags
[i
] |= CFWIDEB
;
8769 if (p
->features
& AHC_ULTRA2
)
8771 if (aic_inb(p
, TARG_OFFSET
+ i
))
8773 sc
->device_flags
[i
] |= CFSYNCH
;
8774 sc
->device_flags
[i
] |= (aic_inb(p
, TARG_SCSIRATE
+ i
) & 0x07);
8775 if ( (aic_inb(p
, TARG_SCSIRATE
+ i
) & 0x18) == 0x18 )
8776 sc
->device_flags
[i
] |= CFSYNCHISULTRA
;
8781 if (aic_inb(p
, TARG_SCSIRATE
+ i
) & ~WIDEXFER
)
8783 sc
->device_flags
[i
] |= CFSYNCH
;
8784 if (p
->features
& AHC_ULTRA
)
8785 sc
->device_flags
[i
] |= ((p
->ultraenb
& mask
) ?
8786 CFSYNCHISULTRA
: 0);
8793 * Assume the BIOS has NOT been run on this card and nothing between
8794 * the card and the devices is configured yet.
8796 sc
->device_flags
[i
] = CFDISC
;
8797 if (p
->features
& AHC_WIDE
)
8798 sc
->device_flags
[i
] |= CFWIDEB
;
8799 if (p
->features
& AHC_ULTRA3
)
8800 sc
->device_flags
[i
] |= 2;
8801 else if (p
->features
& AHC_ULTRA2
)
8802 sc
->device_flags
[i
] |= 3;
8803 else if (p
->features
& AHC_ULTRA
)
8804 sc
->device_flags
[i
] |= CFSYNCHISULTRA
;
8805 sc
->device_flags
[i
] |= CFSYNCH
;
8806 aic_outb(p
, 0, TARG_SCSIRATE
+ i
);
8807 if (p
->features
& AHC_ULTRA2
)
8808 aic_outb(p
, 0, TARG_OFFSET
+ i
);
8811 if (sc
->device_flags
[i
] & CFDISC
)
8813 p
->discenable
|= mask
;
8815 if (p
->flags
& AHC_NEWEEPROM_FMT
)
8817 if ( !(p
->features
& AHC_ULTRA2
) )
8820 * I know of two different Ultra BIOSes that do this differently.
8821 * One on the Gigabyte 6BXU mb that wants flags[i] & CFXFER to
8822 * be == to 0x03 and SYNCHISULTRA to be true to mean 40MByte/s
8823 * while on the IBM Netfinity 5000 they want the same thing
8824 * to be something else, while flags[i] & CFXFER == 0x03 and
8825 * SYNCHISULTRA false should be 40MByte/s. So, we set both to
8826 * 40MByte/s and the lower speeds be damned. People will have
8827 * to select around the conversely mapped lower speeds in order
8828 * to select lower speeds on these boards.
8830 if ( (sc
->device_flags
[i
] & CFNEWULTRAFORMAT
) &&
8831 ((sc
->device_flags
[i
] & CFXFER
) == 0x03) )
8833 sc
->device_flags
[i
] &= ~CFXFER
;
8834 sc
->device_flags
[i
] |= CFSYNCHISULTRA
;
8836 if (sc
->device_flags
[i
] & CFSYNCHISULTRA
)
8838 p
->ultraenb
|= mask
;
8841 else if ( !(sc
->device_flags
[i
] & CFNEWULTRAFORMAT
) &&
8842 (p
->features
& AHC_ULTRA2
) &&
8843 (sc
->device_flags
[i
] & CFSYNCHISULTRA
) )
8845 p
->ultraenb
|= mask
;
8848 else if (sc
->adapter_control
& CFULTRAEN
)
8850 p
->ultraenb
|= mask
;
8852 if ( (sc
->device_flags
[i
] & CFSYNCH
) == 0)
8854 sc
->device_flags
[i
] &= ~CFXFER
;
8855 p
->ultraenb
&= ~mask
;
8856 p
->transinfo
[i
].user_offset
= 0;
8857 p
->transinfo
[i
].user_period
= 0;
8858 p
->transinfo
[i
].user_options
= 0;
8859 p
->transinfo
[i
].cur_offset
= 0;
8860 p
->transinfo
[i
].cur_period
= 0;
8861 p
->transinfo
[i
].cur_options
= 0;
8862 p
->needsdtr_copy
&= ~mask
;
8866 if (p
->features
& AHC_ULTRA3
)
8868 p
->transinfo
[i
].user_offset
= MAX_OFFSET_ULTRA2
;
8869 p
->transinfo
[i
].cur_offset
= aic_inb(p
, TARG_OFFSET
+ i
);
8870 if( (sc
->device_flags
[i
] & CFXFER
) < 0x03 )
8872 scsirate
= (sc
->device_flags
[i
] & CFXFER
);
8873 p
->transinfo
[i
].user_options
= MSG_EXT_PPR_OPTION_DT_CRC
;
8874 if( (aic_inb(p
, TARG_SCSIRATE
+ i
) & CFXFER
) < 0x03 )
8876 p
->transinfo
[i
].cur_options
=
8877 ((aic_inb(p
, TARG_SCSIRATE
+ i
) & 0x40) ?
8878 MSG_EXT_PPR_OPTION_DT_CRC
: MSG_EXT_PPR_OPTION_DT_UNITS
);
8882 p
->transinfo
[i
].cur_options
= 0;
8887 scsirate
= (sc
->device_flags
[i
] & CFXFER
) |
8888 ((p
->ultraenb
& mask
) ? 0x18 : 0x10);
8889 p
->transinfo
[i
].user_options
= 0;
8890 p
->transinfo
[i
].cur_options
= 0;
8892 p
->transinfo
[i
].user_period
= aic7xxx_find_period(p
, scsirate
,
8893 AHC_SYNCRATE_ULTRA3
);
8894 p
->transinfo
[i
].cur_period
= aic7xxx_find_period(p
,
8895 aic_inb(p
, TARG_SCSIRATE
+ i
),
8896 AHC_SYNCRATE_ULTRA3
);
8898 else if (p
->features
& AHC_ULTRA2
)
8900 p
->transinfo
[i
].user_offset
= MAX_OFFSET_ULTRA2
;
8901 p
->transinfo
[i
].cur_offset
= aic_inb(p
, TARG_OFFSET
+ i
);
8902 scsirate
= (sc
->device_flags
[i
] & CFXFER
) |
8903 ((p
->ultraenb
& mask
) ? 0x18 : 0x10);
8904 p
->transinfo
[i
].user_options
= 0;
8905 p
->transinfo
[i
].cur_options
= 0;
8906 p
->transinfo
[i
].user_period
= aic7xxx_find_period(p
, scsirate
,
8907 AHC_SYNCRATE_ULTRA2
);
8908 p
->transinfo
[i
].cur_period
= aic7xxx_find_period(p
,
8909 aic_inb(p
, TARG_SCSIRATE
+ i
),
8910 AHC_SYNCRATE_ULTRA2
);
8914 scsirate
= (sc
->device_flags
[i
] & CFXFER
) << 4;
8915 p
->transinfo
[i
].user_options
= 0;
8916 p
->transinfo
[i
].cur_options
= 0;
8917 p
->transinfo
[i
].user_offset
= MAX_OFFSET_8BIT
;
8918 if (p
->features
& AHC_ULTRA
)
8921 ultraenb
= aic_inb(p
, ULTRA_ENB
) |
8922 (aic_inb(p
, ULTRA_ENB
+ 1) << 8);
8923 p
->transinfo
[i
].user_period
= aic7xxx_find_period(p
,
8925 (p
->ultraenb
& mask
) ?
8926 AHC_SYNCRATE_ULTRA
:
8928 p
->transinfo
[i
].cur_period
= aic7xxx_find_period(p
,
8929 aic_inb(p
, TARG_SCSIRATE
+ i
),
8931 AHC_SYNCRATE_ULTRA
:
8935 p
->transinfo
[i
].user_period
= aic7xxx_find_period(p
,
8936 scsirate
, AHC_SYNCRATE_FAST
);
8938 p
->needsdtr_copy
|= mask
;
8940 if ( (sc
->device_flags
[i
] & CFWIDEB
) && (p
->features
& AHC_WIDE
) )
8942 p
->transinfo
[i
].user_width
= MSG_EXT_WDTR_BUS_16_BIT
;
8943 p
->needwdtr_copy
|= mask
;
8947 p
->transinfo
[i
].user_width
= MSG_EXT_WDTR_BUS_8_BIT
;
8948 p
->needwdtr_copy
&= ~mask
;
8950 p
->transinfo
[i
].cur_width
=
8951 (aic_inb(p
, TARG_SCSIRATE
+ i
) & WIDEXFER
) ?
8952 MSG_EXT_WDTR_BUS_16_BIT
: MSG_EXT_WDTR_BUS_8_BIT
;
8954 aic_outb(p
, ~(p
->discenable
& 0xFF), DISC_DSB
);
8955 aic_outb(p
, ~((p
->discenable
>> 8) & 0xFF), DISC_DSB
+ 1);
8956 p
->needppr
= p
->needppr_copy
= p
->needdv
= 0;
8957 p
->needwdtr
= p
->needwdtr_copy
;
8958 p
->needsdtr
= p
->needsdtr_copy
;
8962 * We set the p->ultraenb from the SEEPROM to begin with, but now we make
8963 * it match what is already down in the card. If we are doing a reset
8964 * on the card then this will get put back to a default state anyway.
8965 * This allows us to not have to pre-emptively negotiate when using the
8968 if (p
->features
& AHC_ULTRA
)
8969 p
->ultraenb
= aic_inb(p
, ULTRA_ENB
) | (aic_inb(p
, ULTRA_ENB
+ 1) << 8);
8972 scsi_conf
= (p
->scsi_id
& HSCSIID
);
8976 p
->adapter_control
= sc
->adapter_control
;
8977 p
->bios_control
= sc
->bios_control
;
8979 switch (p
->chip
& AHC_CHIPID_MASK
)
8984 if (p
->adapter_control
& CFBPRIMARY
)
8985 p
->flags
|= AHC_CHANNEL_B_PRIMARY
;
8990 if (sc
->adapter_control
& CFSPARITY
)
8991 scsi_conf
|= ENSPCHK
;
8995 scsi_conf
|= ENSPCHK
| RESET_SCSI
;
8999 * Only set the SCSICONF and SCSICONF + 1 registers if we are a PCI card.
9000 * The 2842 and 2742 cards already have these registers set and we don't
9001 * want to muck with them since we don't set all the bits they do.
9003 if ( (p
->chip
& ~AHC_CHIPID_MASK
) == AHC_PCI
)
9005 /* Set the host ID */
9006 aic_outb(p
, scsi_conf
, SCSICONF
);
9007 /* In case we are a wide card */
9008 aic_outb(p
, p
->scsi_id
, SCSICONF
+ 1);
9012 /*+F*************************************************************************
9017 * Try to detect and register an Adaptec 7770 or 7870 SCSI controller.
9019 * XXX - This should really be called aic7xxx_probe(). A sequence of
9020 * probe(), attach()/detach(), and init() makes more sense than
9021 * one do-it-all function. This may be useful when (and if) the
9022 * mid-level SCSI code is overhauled.
9023 *-F*************************************************************************/
9025 aic7xxx_detect(Scsi_Host_Template
*template)
9027 struct aic7xxx_host
*temp_p
= NULL
;
9028 struct aic7xxx_host
*current_p
= NULL
;
9029 struct aic7xxx_host
*list_p
= NULL
;
9031 #if defined(__i386__) || defined(__alpha__)
9032 ahc_flag_type flags
= 0;
9035 unsigned char sxfrctl1
;
9036 #if defined(__i386__) || defined(__alpha__)
9037 unsigned char hcntrl
, hostconf
;
9038 unsigned int slot
, base
;
9043 * If we are called as a module, the aic7xxx pointer may not be null
9044 * and it would point to our bootup string, just like on the lilo
9045 * command line. IF not NULL, then process this config string with
9049 aic7xxx_setup(aic7xxx
, NULL
);
9050 if(dummy_buffer
[0] != 'P')
9051 printk(KERN_WARNING
"aic7xxx: Please read the file /usr/src/linux/drivers"
9052 "/scsi/README.aic7xxx\n"
9053 "aic7xxx: to see the proper way to specify options to the aic7xxx "
9055 "aic7xxx: Specifically, don't use any commas when passing arguments to\n"
9056 "aic7xxx: insmod or else it might trash certain memory areas.\n");
9059 template->proc_dir
= &proc_scsi_aic7xxx
;
9060 template->sg_tablesize
= AIC7XXX_MAX_SG
;
9063 #if defined(__i386__) || defined(__alpha__)
9066 * PCI-bus chipset probe.
9068 #if LINUX_VERSION_CODE > KERNEL_VERSION(2,1,92)
9071 if (pci_find_device(PCI_VENDOR_ID_INTEL
,
9072 PCI_DEVICE_ID_INTEL_82450GX
,
9074 aic7xxx_no_probe
= 1;
9075 if (pci_find_device(PCI_VENDOR_ID_INTEL
,
9076 PCI_DEVICE_ID_INTEL_82451NX
,
9078 aic7xxx_no_probe
= 1;
9081 #define PCI_DEVICE_ID_INTEL_82451NX 0x84ca
9082 if (pcibios_present())
9084 unsigned char pci_bus
, pci_devfn
;
9085 if (!(pcibios_find_device(PCI_VENDOR_ID_INTEL
,
9086 PCI_DEVICE_ID_INTEL_82450GX
,
9087 0, &pci_bus
, &pci_devfn
)) )
9088 aic7xxx_no_probe
= 1;
9089 if (!(pcibios_find_device(PCI_VENDOR_ID_INTEL
,
9090 PCI_DEVICE_ID_INTEL_82451NX
,
9091 0, &pci_bus
, &pci_devfn
)) )
9092 aic7xxx_no_probe
= 1;
9094 #endif /* LINUX_VERSION_CODE */
9095 #endif /* CONFIG_PCI */
9097 * EISA/VL-bus card signature probe.
9100 while ( (slot
<= MAXSLOT
) &&
9101 !(aic7xxx_no_probe
) )
9103 base
= SLOTBASE(slot
) + MINREG
;
9105 if (check_region(base
, MAXREG
- MINREG
))
9108 * Some other driver has staked a
9109 * claim to this i/o region already.
9112 continue; /* back to the beginning of the for loop */
9115 type
= aic7xxx_probe(slot
, base
+ AHC_HID0
, &flags
);
9121 temp_p
= kmalloc(sizeof(struct aic7xxx_host
), GFP_ATOMIC
);
9124 printk(KERN_WARNING
"aic7xxx: Unable to allocate device space.\n");
9126 continue; /* back to the beginning of the while loop */
9129 * Pause the card preserving the IRQ type. Allow the operator
9130 * to override the IRQ trigger.
9132 if (aic7xxx_irq_trigger
== 1)
9133 hcntrl
= IRQMS
; /* Level */
9134 else if (aic7xxx_irq_trigger
== 0)
9135 hcntrl
= 0; /* Edge */
9137 hcntrl
= inb(base
+ HCNTRL
) & IRQMS
; /* Default */
9138 memset(temp_p
, 0, sizeof(struct aic7xxx_host
));
9139 temp_p
->unpause
= hcntrl
| INTEN
;
9140 temp_p
->pause
= hcntrl
| PAUSE
| INTEN
;
9141 temp_p
->base
= base
;
9144 temp_p
->pci_bus
= 0;
9145 temp_p
->pci_device_fn
= slot
;
9146 aic_outb(temp_p
, hcntrl
| PAUSE
, HCNTRL
);
9147 while( (aic_inb(temp_p
, HCNTRL
) & PAUSE
) == 0 ) ;
9148 if (aic7xxx_chip_reset(temp_p
) == -1)
9151 temp_p
->irq
= aic_inb(temp_p
, INTDEF
) & 0x0F;
9152 temp_p
->flags
|= AHC_PAGESCBS
;
9154 switch (temp_p
->irq
)
9165 printk(KERN_WARNING
"aic7xxx: Host adapter uses unsupported IRQ "
9166 "level %d, ignoring.\n", temp_p
->irq
);
9169 continue; /* back to the beginning of the while loop */
9173 * We are commited now, everything has been checked and this card
9174 * has been found, now we just set it up
9178 * Insert our new struct into the list at the end
9182 list_p
= current_p
= temp_p
;
9187 while (current_p
->next
!= NULL
)
9188 current_p
= current_p
->next
;
9189 current_p
->next
= temp_p
;
9195 temp_p
->board_name_index
= 2;
9196 if (aic7xxx_verbose
& VERBOSE_PROBE2
)
9197 printk("aic7xxx: <%s> at EISA %d\n",
9198 board_names
[2], slot
);
9202 temp_p
->chip
= AHC_AIC7770
| AHC_EISA
;
9203 temp_p
->features
|= AHC_AIC7770_FE
;
9204 temp_p
->bios_control
= aic_inb(temp_p
, HA_274_BIOSCTRL
);
9207 * Get the primary channel information. Right now we don't
9208 * do anything with this, but someday we will be able to inform
9209 * the mid-level SCSI code which channel is primary.
9211 if (temp_p
->board_name_index
== 0)
9213 temp_p
->board_name_index
= 3;
9214 if (aic7xxx_verbose
& VERBOSE_PROBE2
)
9215 printk("aic7xxx: <%s> at EISA %d\n",
9216 board_names
[3], slot
);
9218 if (temp_p
->bios_control
& CHANNEL_B_PRIMARY
)
9220 temp_p
->flags
|= AHC_CHANNEL_B_PRIMARY
;
9223 if ((temp_p
->bios_control
& BIOSMODE
) == BIOSDISABLED
)
9225 temp_p
->flags
&= ~AHC_BIOS_ENABLED
;
9229 temp_p
->flags
&= ~AHC_USEDEFAULTS
;
9230 temp_p
->flags
|= AHC_BIOS_ENABLED
;
9231 if ( (temp_p
->bios_control
& 0x20) == 0 )
9233 temp_p
->bios_address
= 0xcc000;
9234 temp_p
->bios_address
+= (0x4000 * (temp_p
->bios_control
& 0x07));
9238 temp_p
->bios_address
= 0xd0000;
9239 temp_p
->bios_address
+= (0x8000 * (temp_p
->bios_control
& 0x06));
9242 temp_p
->adapter_control
= aic_inb(temp_p
, SCSICONF
) << 8;
9243 temp_p
->adapter_control
|= aic_inb(temp_p
, SCSICONF
+ 1);
9244 if (temp_p
->features
& AHC_WIDE
)
9246 temp_p
->scsi_id
= temp_p
->adapter_control
& HWSCSIID
;
9247 temp_p
->scsi_id_b
= temp_p
->scsi_id
;
9251 temp_p
->scsi_id
= (temp_p
->adapter_control
>> 8) & HSCSIID
;
9252 temp_p
->scsi_id_b
= temp_p
->adapter_control
& HSCSIID
;
9254 aic7xxx_load_seeprom(temp_p
, &sxfrctl1
);
9260 temp_p
->chip
= AHC_AIC7770
| AHC_VL
;
9261 temp_p
->features
|= AHC_AIC7770_FE
;
9263 temp_p
->flags
|= AHC_BIOS_ENABLED
;
9265 temp_p
->flags
&= ~AHC_BIOS_ENABLED
;
9266 if (aic_inb(temp_p
, SCSICONF
) & TERM_ENB
)
9268 aic7xxx_load_seeprom(temp_p
, &sxfrctl1
);
9269 temp_p
->board_name_index
= 4;
9270 if (aic7xxx_verbose
& VERBOSE_PROBE2
)
9271 printk("aic7xxx: <%s> at VLB %d\n",
9272 board_names
[2], slot
);
9273 switch( aic_inb(temp_p
, STATUS_2840
) & BIOS_SEL
)
9276 temp_p
->bios_address
= 0xe0000;
9279 temp_p
->bios_address
= 0xc8000;
9282 temp_p
->bios_address
= 0xd0000;
9285 temp_p
->bios_address
= 0xd8000;
9288 break; /* can't get here */
9292 default: /* Won't get here. */
9295 if (aic7xxx_verbose
& VERBOSE_PROBE2
)
9297 printk(KERN_INFO
"aic7xxx: BIOS %sabled, IO Port 0x%lx, IRQ %d (%s)\n",
9298 (temp_p
->flags
& AHC_USEDEFAULTS
) ? "dis" : "en", temp_p
->base
,
9300 (temp_p
->pause
& IRQMS
) ? "level sensitive" : "edge triggered");
9301 printk(KERN_INFO
"aic7xxx: Extended translation %sabled.\n",
9302 (temp_p
->flags
& AHC_EXTEND_TRANS_A
) ? "en" : "dis");
9306 * Set the FIFO threshold and the bus off time.
9308 hostconf
= aic_inb(temp_p
, HOSTCONF
);
9309 aic_outb(temp_p
, hostconf
& DFTHRSH
, BUSSPD
);
9310 aic_outb(temp_p
, (hostconf
<< 2) & BOFF
, BUSTIME
);
9315 #endif /* defined(__i386__) || defined(__alpha__) */
9321 #if LINUX_VERSION_CODE > KERNEL_VERSION(2,1,92)
9324 if (pcibios_present())
9329 unsigned short vendor_id
;
9330 unsigned short device_id
;
9332 ahc_flag_type flags
;
9333 ahc_feature features
;
9334 int board_name_index
;
9335 unsigned short seeprom_size
;
9336 unsigned short seeprom_type
;
9337 } const aic_pdevs
[] = {
9338 {PCI_VENDOR_ID_ADAPTEC
, PCI_DEVICE_ID_ADAPTEC_7810
, AHC_NONE
,
9339 AHC_FNONE
, AHC_FENONE
, 1,
9341 {PCI_VENDOR_ID_ADAPTEC
, PCI_DEVICE_ID_ADAPTEC_7850
, AHC_AIC7850
,
9342 AHC_PAGESCBS
, AHC_AIC7850_FE
, 5,
9344 {PCI_VENDOR_ID_ADAPTEC
, PCI_DEVICE_ID_ADAPTEC_7855
, AHC_AIC7850
,
9345 AHC_PAGESCBS
, AHC_AIC7850_FE
, 6,
9347 {PCI_VENDOR_ID_ADAPTEC
, PCI_DEVICE_ID_ADAPTEC_7821
, AHC_AIC7860
,
9348 AHC_PAGESCBS
| AHC_NEWEEPROM_FMT
| AHC_BIOS_ENABLED
,
9351 {PCI_VENDOR_ID_ADAPTEC
, PCI_DEVICE_ID_ADAPTEC_3860
, AHC_AIC7860
,
9352 AHC_PAGESCBS
| AHC_NEWEEPROM_FMT
| AHC_BIOS_ENABLED
,
9355 {PCI_VENDOR_ID_ADAPTEC
, PCI_DEVICE_ID_ADAPTEC_38602
, AHC_AIC7860
,
9356 AHC_PAGESCBS
| AHC_NEWEEPROM_FMT
| AHC_BIOS_ENABLED
,
9359 {PCI_VENDOR_ID_ADAPTEC
, PCI_DEVICE_ID_ADAPTEC_38602
, AHC_AIC7860
,
9360 AHC_PAGESCBS
| AHC_NEWEEPROM_FMT
| AHC_BIOS_ENABLED
,
9363 {PCI_VENDOR_ID_ADAPTEC
, PCI_DEVICE_ID_ADAPTEC_7860
, AHC_AIC7860
,
9364 AHC_PAGESCBS
| AHC_NEWEEPROM_FMT
| AHC_BIOS_ENABLED
,
9367 {PCI_VENDOR_ID_ADAPTEC
, PCI_DEVICE_ID_ADAPTEC_7861
, AHC_AIC7860
,
9368 AHC_PAGESCBS
| AHC_NEWEEPROM_FMT
| AHC_BIOS_ENABLED
,
9371 {PCI_VENDOR_ID_ADAPTEC
, PCI_DEVICE_ID_ADAPTEC_7870
, AHC_AIC7870
,
9372 AHC_PAGESCBS
| AHC_BIOS_ENABLED
, AHC_AIC7870_FE
, 9,
9374 {PCI_VENDOR_ID_ADAPTEC
, PCI_DEVICE_ID_ADAPTEC_7871
, AHC_AIC7870
,
9375 AHC_PAGESCBS
| AHC_BIOS_ENABLED
, AHC_AIC7870_FE
, 10,
9377 {PCI_VENDOR_ID_ADAPTEC
, PCI_DEVICE_ID_ADAPTEC_7872
, AHC_AIC7870
,
9378 AHC_PAGESCBS
| AHC_BIOS_ENABLED
| AHC_MULTI_CHANNEL
,
9381 {PCI_VENDOR_ID_ADAPTEC
, PCI_DEVICE_ID_ADAPTEC_7873
, AHC_AIC7870
,
9382 AHC_PAGESCBS
| AHC_BIOS_ENABLED
| AHC_MULTI_CHANNEL
,
9385 {PCI_VENDOR_ID_ADAPTEC
, PCI_DEVICE_ID_ADAPTEC_7874
, AHC_AIC7870
,
9386 AHC_PAGESCBS
| AHC_BIOS_ENABLED
, AHC_AIC7870_FE
, 13,
9388 {PCI_VENDOR_ID_ADAPTEC
, PCI_DEVICE_ID_ADAPTEC_7880
, AHC_AIC7880
,
9389 AHC_PAGESCBS
| AHC_BIOS_ENABLED
, AHC_AIC7880_FE
, 14,
9391 {PCI_VENDOR_ID_ADAPTEC
, PCI_DEVICE_ID_ADAPTEC_7881
, AHC_AIC7880
,
9392 AHC_PAGESCBS
| AHC_BIOS_ENABLED
, AHC_AIC7880_FE
, 15,
9394 {PCI_VENDOR_ID_ADAPTEC
, PCI_DEVICE_ID_ADAPTEC_7882
, AHC_AIC7880
,
9395 AHC_PAGESCBS
| AHC_BIOS_ENABLED
| AHC_MULTI_CHANNEL
,
9398 {PCI_VENDOR_ID_ADAPTEC
, PCI_DEVICE_ID_ADAPTEC_7883
, AHC_AIC7880
,
9399 AHC_PAGESCBS
| AHC_BIOS_ENABLED
| AHC_MULTI_CHANNEL
,
9402 {PCI_VENDOR_ID_ADAPTEC
, PCI_DEVICE_ID_ADAPTEC_7884
, AHC_AIC7880
,
9403 AHC_PAGESCBS
| AHC_BIOS_ENABLED
, AHC_AIC7880_FE
, 18,
9405 {PCI_VENDOR_ID_ADAPTEC
, PCI_DEVICE_ID_ADAPTEC_7885
, AHC_AIC7880
,
9406 AHC_PAGESCBS
| AHC_BIOS_ENABLED
, AHC_AIC7880_FE
, 18,
9408 {PCI_VENDOR_ID_ADAPTEC
, PCI_DEVICE_ID_ADAPTEC_7886
, AHC_AIC7880
,
9409 AHC_PAGESCBS
| AHC_BIOS_ENABLED
, AHC_AIC7880_FE
, 18,
9411 {PCI_VENDOR_ID_ADAPTEC
, PCI_DEVICE_ID_ADAPTEC_7887
, AHC_AIC7880
,
9412 AHC_PAGESCBS
| AHC_BIOS_ENABLED
, AHC_AIC7880_FE
, 18,
9414 {PCI_VENDOR_ID_ADAPTEC
, PCI_DEVICE_ID_ADAPTEC_7888
, AHC_AIC7880
,
9415 AHC_PAGESCBS
| AHC_BIOS_ENABLED
, AHC_AIC7880_FE
, 18,
9417 {PCI_VENDOR_ID_ADAPTEC
, PCI_DEVICE_ID_ADAPTEC_7895
, AHC_AIC7895
,
9418 AHC_PAGESCBS
| AHC_NEWEEPROM_FMT
| AHC_BIOS_ENABLED
| AHC_MULTI_CHANNEL
,
9421 {PCI_VENDOR_ID_ADAPTEC2
, PCI_DEVICE_ID_ADAPTEC2_7890
, AHC_AIC7890
,
9422 AHC_PAGESCBS
| AHC_NEWEEPROM_FMT
| AHC_BIOS_ENABLED
,
9425 {PCI_VENDOR_ID_ADAPTEC2
, PCI_DEVICE_ID_ADAPTEC2_7890B
, AHC_AIC7890
,
9426 AHC_PAGESCBS
| AHC_NEWEEPROM_FMT
| AHC_BIOS_ENABLED
,
9429 {PCI_VENDOR_ID_ADAPTEC2
, PCI_DEVICE_ID_ADAPTEC2_2930U2
, AHC_AIC7890
,
9430 AHC_PAGESCBS
| AHC_NEWEEPROM_FMT
| AHC_BIOS_ENABLED
,
9433 {PCI_VENDOR_ID_ADAPTEC2
, PCI_DEVICE_ID_ADAPTEC2_2940U2
, AHC_AIC7890
,
9434 AHC_PAGESCBS
| AHC_NEWEEPROM_FMT
| AHC_BIOS_ENABLED
,
9437 {PCI_VENDOR_ID_ADAPTEC2
, PCI_DEVICE_ID_ADAPTEC2_7896
, AHC_AIC7896
,
9438 AHC_PAGESCBS
| AHC_NEWEEPROM_FMT
| AHC_BIOS_ENABLED
| AHC_MULTI_CHANNEL
,
9441 {PCI_VENDOR_ID_ADAPTEC2
, PCI_DEVICE_ID_ADAPTEC2_3940U2
, AHC_AIC7896
,
9442 AHC_PAGESCBS
| AHC_NEWEEPROM_FMT
| AHC_BIOS_ENABLED
| AHC_MULTI_CHANNEL
,
9445 {PCI_VENDOR_ID_ADAPTEC2
, PCI_DEVICE_ID_ADAPTEC2_3950U2D
, AHC_AIC7896
,
9446 AHC_PAGESCBS
| AHC_NEWEEPROM_FMT
| AHC_BIOS_ENABLED
| AHC_MULTI_CHANNEL
,
9449 {PCI_VENDOR_ID_ADAPTEC
, PCI_DEVICE_ID_ADAPTEC_1480A
, AHC_AIC7860
,
9450 AHC_PAGESCBS
| AHC_NEWEEPROM_FMT
| AHC_BIOS_ENABLED
,
9453 {PCI_VENDOR_ID_ADAPTEC2
, PCI_DEVICE_ID_ADAPTEC2_7892A
, AHC_AIC7892
,
9454 AHC_PAGESCBS
| AHC_NEWEEPROM_FMT
| AHC_BIOS_ENABLED
,
9457 {PCI_VENDOR_ID_ADAPTEC2
, PCI_DEVICE_ID_ADAPTEC2_7892B
, AHC_AIC7892
,
9458 AHC_PAGESCBS
| AHC_NEWEEPROM_FMT
| AHC_BIOS_ENABLED
,
9461 {PCI_VENDOR_ID_ADAPTEC2
, PCI_DEVICE_ID_ADAPTEC2_7892D
, AHC_AIC7892
,
9462 AHC_PAGESCBS
| AHC_NEWEEPROM_FMT
| AHC_BIOS_ENABLED
,
9465 {PCI_VENDOR_ID_ADAPTEC2
, PCI_DEVICE_ID_ADAPTEC2_7892P
, AHC_AIC7892
,
9466 AHC_PAGESCBS
| AHC_NEWEEPROM_FMT
| AHC_BIOS_ENABLED
,
9469 {PCI_VENDOR_ID_ADAPTEC2
, PCI_DEVICE_ID_ADAPTEC2_7899A
, AHC_AIC7899
,
9470 AHC_PAGESCBS
| AHC_NEWEEPROM_FMT
| AHC_BIOS_ENABLED
| AHC_MULTI_CHANNEL
,
9473 {PCI_VENDOR_ID_ADAPTEC2
, PCI_DEVICE_ID_ADAPTEC2_7899B
, AHC_AIC7899
,
9474 AHC_PAGESCBS
| AHC_NEWEEPROM_FMT
| AHC_BIOS_ENABLED
| AHC_MULTI_CHANNEL
,
9477 {PCI_VENDOR_ID_ADAPTEC2
, PCI_DEVICE_ID_ADAPTEC2_7899D
, AHC_AIC7899
,
9478 AHC_PAGESCBS
| AHC_NEWEEPROM_FMT
| AHC_BIOS_ENABLED
| AHC_MULTI_CHANNEL
,
9481 {PCI_VENDOR_ID_ADAPTEC2
, PCI_DEVICE_ID_ADAPTEC2_7899P
, AHC_AIC7899
,
9482 AHC_PAGESCBS
| AHC_NEWEEPROM_FMT
| AHC_BIOS_ENABLED
| AHC_MULTI_CHANNEL
,
9487 unsigned short command
;
9488 unsigned int devconfig
, i
, oldverbose
;
9489 #if LINUX_VERSION_CODE > KERNEL_VERSION(2,1,92)
9490 struct pci_dev
*pdev
= NULL
;
9493 unsigned int piobase
, mmapbase
;
9494 unsigned char pci_bus
, pci_devfn
, pci_irq
;
9497 for (i
= 0; i
< NUMBER(aic_pdevs
); i
++)
9499 #if LINUX_VERSION_CODE > KERNEL_VERSION(2,1,92)
9501 while ((pdev
= pci_find_device(aic_pdevs
[i
].vendor_id
,
9502 aic_pdevs
[i
].device_id
,
9506 while (!(pcibios_find_device(aic_pdevs
[i
].vendor_id
,
9507 aic_pdevs
[i
].device_id
,
9508 index
++, &pci_bus
, &pci_devfn
)) )
9511 if ( i
== 0 ) /* We found one, but it's the 7810 RAID cont. */
9513 if (aic7xxx_verbose
& (VERBOSE_PROBE
|VERBOSE_PROBE2
))
9515 printk(KERN_INFO
"aic7xxx: The 7810 RAID controller is not "
9517 printk(KERN_INFO
" this driver, we are ignoring it.\n");
9520 else if ( (temp_p
= kmalloc(sizeof(struct aic7xxx_host
),
9521 GFP_ATOMIC
)) != NULL
)
9523 memset(temp_p
, 0, sizeof(struct aic7xxx_host
));
9524 temp_p
->chip
= aic_pdevs
[i
].chip
| AHC_PCI
;
9525 temp_p
->flags
= aic_pdevs
[i
].flags
;
9526 temp_p
->features
= aic_pdevs
[i
].features
;
9527 temp_p
->board_name_index
= aic_pdevs
[i
].board_name_index
;
9528 temp_p
->sc_size
= aic_pdevs
[i
].seeprom_size
;
9529 temp_p
->sc_type
= aic_pdevs
[i
].seeprom_type
;
9532 * Read sundry information from PCI BIOS.
9534 #if LINUX_VERSION_CODE > KERNEL_VERSION(2,1,92)
9535 temp_p
->irq
= pdev
->irq
;
9536 temp_p
->pdev
= pdev
;
9537 temp_p
->pci_bus
= pdev
->bus
->number
;
9538 temp_p
->pci_device_fn
= pdev
->devfn
;
9539 temp_p
->base
= pdev
->resource
[0].start
;
9540 temp_p
->mbase
= pdev
->resource
[1].start
;
9544 if ( ((current_p
->pci_bus
== temp_p
->pci_bus
) &&
9545 (current_p
->pci_device_fn
== temp_p
->pci_device_fn
)) ||
9546 (current_p
->base
== temp_p
->base
) )
9548 /* duplicate PCI entry, skip it */
9552 current_p
= current_p
->next
;
9554 if ( temp_p
== NULL
)
9556 if (aic7xxx_verbose
& VERBOSE_PROBE2
)
9557 printk("aic7xxx: <%s> at PCI %d/%d\n",
9558 board_names
[aic_pdevs
[i
].board_name_index
],
9559 PCI_SLOT(temp_p
->pdev
->devfn
),
9560 PCI_FUNC(temp_p
->pdev
->devfn
));
9561 pci_read_config_word(pdev
, PCI_COMMAND
, &command
);
9562 if (aic7xxx_verbose
& VERBOSE_PROBE2
)
9564 printk("aic7xxx: Initial PCI_COMMAND value was 0x%x\n",
9567 #ifdef AIC7XXX_STRICT_PCI_SETUP
9568 command
|= PCI_COMMAND_SERR
| PCI_COMMAND_PARITY
|
9569 PCI_COMMAND_MASTER
| PCI_COMMAND_MEMORY
| PCI_COMMAND_IO
;
9571 command
|= PCI_COMMAND_MASTER
| PCI_COMMAND_MEMORY
| PCI_COMMAND_IO
;
9573 command
&= ~PCI_COMMAND_INVALIDATE
;
9574 if (aic7xxx_pci_parity
== 0)
9575 command
&= ~(PCI_COMMAND_SERR
| PCI_COMMAND_PARITY
);
9576 pci_write_config_word(pdev
, PCI_COMMAND
, command
);
9577 #ifdef AIC7XXX_STRICT_PCI_SETUP
9578 pci_read_config_dword(pdev
, DEVCONFIG
, &devconfig
);
9579 if (aic7xxx_verbose
& VERBOSE_PROBE2
)
9581 printk("aic7xxx: Initial DEVCONFIG value was 0x%x\n", devconfig
);
9583 devconfig
|= 0x80000040;
9584 pci_write_config_dword(pdev
, DEVCONFIG
, devconfig
);
9585 #endif /* AIC7XXX_STRICT_PCI_SETUP */
9586 #else /* LINUX_VERSION_CODE > KERNEL_VERSION(2,1,92) */
9587 temp_p
->pci_bus
= pci_bus
;
9588 temp_p
->pci_device_fn
= pci_devfn
;
9589 pcibios_read_config_byte(pci_bus
, pci_devfn
, PCI_INTERRUPT_LINE
,
9591 temp_p
->irq
= pci_irq
;
9592 pcibios_read_config_dword(pci_bus
, pci_devfn
, PCI_BASE_ADDRESS_0
,
9594 temp_p
->base
= piobase
;
9595 pcibios_read_config_dword(pci_bus
, pci_devfn
, PCI_BASE_ADDRESS_1
,
9597 temp_p
->mbase
= mmapbase
;
9598 temp_p
->base
&= PCI_BASE_ADDRESS_IO_MASK
;
9599 temp_p
->mbase
&= PCI_BASE_ADDRESS_MEM_MASK
;
9603 if ( ((current_p
->pci_bus
== temp_p
->pci_bus
) &&
9604 (current_p
->pci_device_fn
== temp_p
->pci_device_fn
)) ||
9605 (current_p
->base
== temp_p
->base
) )
9607 /* duplicate PCI entry, skip it */
9611 current_p
= current_p
->next
;
9613 if ( temp_p
== NULL
)
9615 if (aic7xxx_verbose
& VERBOSE_PROBE2
)
9616 printk("aic7xxx: <%s> at PCI %d/%d\n",
9617 board_names
[aic_pdevs
[i
].board_name_index
],
9618 PCI_SLOT(temp_p
->pci_device_fn
),
9619 PCI_FUNC(temp_p
->pci_device_fn
));
9620 pcibios_read_config_word(pci_bus
, pci_devfn
, PCI_COMMAND
, &command
);
9621 if (aic7xxx_verbose
& VERBOSE_PROBE2
)
9623 printk("aic7xxx: Initial PCI_COMMAND value was 0x%x\n",
9626 #ifdef AIC7XXX_STRICT_PCI_SETUP
9627 command
|= PCI_COMMAND_SERR
| PCI_COMMAND_PARITY
|
9628 PCI_COMMAND_MASTER
| PCI_COMMAND_MEMORY
| PCI_COMMAND_IO
;
9630 command
|= PCI_COMMAND_MASTER
| PCI_COMMAND_MEMORY
| PCI_COMMAND_IO
;
9632 command
&= ~PCI_COMMAND_INVALIDATE
;
9633 if (aic7xxx_pci_parity
== 0)
9634 command
&= ~(PCI_COMMAND_SERR
| PCI_COMMAND_PARITY
);
9635 pcibios_write_config_word(pci_bus
, pci_devfn
, PCI_COMMAND
, command
);
9636 #ifdef AIC7XXX_STRICT_PCI_SETUP
9637 pcibios_read_config_dword(pci_bus
, pci_devfn
, DEVCONFIG
, &devconfig
);
9638 if (aic7xxx_verbose
& VERBOSE_PROBE2
)
9640 printk("aic7xxx: Initial DEVCONFIG value was 0x%x\n", devconfig
);
9642 devconfig
|= 0x80000040;
9643 pcibios_write_config_dword(pci_bus
, pci_devfn
, DEVCONFIG
, devconfig
);
9644 #endif /* AIC7XXX_STRICT_PCI_SETUP */
9645 #endif /* LINUIX_VERSION_CODE > KERNEL_VERSION(2,1,92) */
9647 temp_p
->unpause
= INTEN
;
9648 temp_p
->pause
= temp_p
->unpause
| PAUSE
;
9649 if ( ((temp_p
->base
== 0) &&
9650 (temp_p
->mbase
== 0)) ||
9651 (temp_p
->irq
== 0) )
9653 printk("aic7xxx: <%s> at PCI %d/%d\n",
9654 board_names
[aic_pdevs
[i
].board_name_index
],
9655 PCI_SLOT(temp_p
->pci_device_fn
),
9656 PCI_FUNC(temp_p
->pci_device_fn
));
9657 printk("aic7xxx: Controller disabled by BIOS, ignoring.\n");
9664 if ( !(temp_p
->flags
& AHC_MULTI_CHANNEL
) ||
9665 ((temp_p
->chip
!= (AHC_AIC7870
| AHC_PCI
)) &&
9666 (temp_p
->chip
!= (AHC_AIC7880
| AHC_PCI
))) )
9668 unsigned long page_offset
, base
;
9670 base
= temp_p
->mbase
& PAGE_MASK
;
9671 page_offset
= temp_p
->mbase
- base
;
9672 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,1,0)
9673 temp_p
->maddr
= ioremap_nocache(base
, page_offset
+ 256);
9675 temp_p
->maddr
= vremap(base
, page_offset
+ 256);
9679 temp_p
->maddr
+= page_offset
;
9681 * We need to check the I/O with the MMAPed address. Some machines
9682 * simply fail to work with MMAPed I/O and certain controllers.
9684 if(aic_inb(temp_p
, HCNTRL
) == 0xff)
9687 * OK.....we failed our test....go back to programmed I/O
9689 printk(KERN_INFO
"aic7xxx: <%s> at PCI %d/%d\n",
9690 board_names
[aic_pdevs
[i
].board_name_index
],
9691 PCI_SLOT(temp_p
->pci_device_fn
),
9692 PCI_FUNC(temp_p
->pci_device_fn
));
9693 printk(KERN_INFO
"aic7xxx: MMAPed I/O failed, reverting to "
9694 "Programmed I/O.\n");
9695 #if LINUX_VERSION_CODE > KERNEL_VERSION(2,1,0)
9696 iounmap((void *) (((unsigned long) temp_p
->maddr
) & PAGE_MASK
));
9698 vfree((void *) (((unsigned long) temp_p
->maddr
) & PAGE_MASK
));
9707 * We HAVE to make sure the first pause_sequencer() and all other
9708 * subsequent I/O that isn't PCI config space I/O takes place
9709 * after the MMAPed I/O region is configured and tested. The
9710 * problem is the PowerPC architecture that doesn't support
9711 * programmed I/O at all, so we have to have the MMAP I/O set up
9712 * for this pause to even work on those machines.
9714 pause_sequencer(temp_p
);
9717 * Clear out any pending PCI error status messages. Also set
9718 * verbose to 0 so that we don't emit strange PCI error messages
9719 * while cleaning out the current status bits.
9721 oldverbose
= aic7xxx_verbose
;
9722 aic7xxx_verbose
= 0;
9723 aic7xxx_pci_intr(temp_p
);
9724 aic7xxx_verbose
= oldverbose
;
9726 temp_p
->bios_address
= 0;
9729 * Remember how the card was setup in case there is no seeprom.
9731 if (temp_p
->features
& AHC_ULTRA2
)
9732 temp_p
->scsi_id
= aic_inb(temp_p
, SCSIID_ULTRA2
) & OID
;
9734 temp_p
->scsi_id
= aic_inb(temp_p
, SCSIID
) & OID
;
9736 * Get current termination setting
9738 sxfrctl1
= aic_inb(temp_p
, SXFRCTL1
) & STPWEN
;
9740 if (aic7xxx_chip_reset(temp_p
) == -1)
9748 * We need to set the CHNL? assignments before loading the SEEPROM
9749 * The 3940 and 3985 cards (original stuff, not any of the later
9750 * stuff) are 7870 and 7880 class chips. The Ultra2 stuff falls
9751 * under 7896 and 7897. The 7895 is in a class by itself :)
9753 switch (temp_p
->chip
& AHC_CHIPID_MASK
)
9755 case AHC_AIC7870
: /* 3840 / 3985 */
9756 case AHC_AIC7880
: /* 3840 UW / 3985 UW */
9757 if(temp_p
->flags
& AHC_MULTI_CHANNEL
)
9759 switch(PCI_SLOT(temp_p
->pci_device_fn
))
9762 temp_p
->flags
|= AHC_CHNLB
;
9765 temp_p
->flags
|= AHC_CHNLB
;
9768 temp_p
->flags
|= AHC_CHNLC
;
9776 case AHC_AIC7895
: /* 7895 */
9777 case AHC_AIC7896
: /* 7896/7 */
9778 case AHC_AIC7899
: /* 7899 */
9779 #if LINUX_VERSION_CODE > KERNEL_VERSION(2,1,92)
9780 if (PCI_FUNC(temp_p
->pdev
->devfn
) != 0)
9782 temp_p
->flags
|= AHC_CHNLB
;
9785 * The 7895 is the only chipset that sets the SCBSIZE32 param
9786 * in the DEVCONFIG register. The Ultra2 chipsets use
9787 * the DSCOMMAND0 register instead.
9789 if ((temp_p
->chip
& AHC_CHIPID_MASK
) == AHC_AIC7895
)
9791 pci_read_config_dword(pdev
, DEVCONFIG
, &devconfig
);
9792 devconfig
|= SCBSIZE32
;
9793 pci_write_config_dword(pdev
, DEVCONFIG
, devconfig
);
9796 if (PCI_FUNC(temp_p
->pci_device_fn
) != 0)
9798 temp_p
->flags
|= AHC_CHNLB
;
9801 * The 7895 is the only chipset that sets the SCBSIZE32 param
9802 * in the DEVCONFIG register. The Ultra2 chipsets use
9803 * the DSCOMMAND0 register instead.
9805 if ((temp_p
->chip
& AHC_CHIPID_MASK
) == AHC_AIC7895
)
9807 pcibios_read_config_dword(pci_bus
, pci_devfn
, DEVCONFIG
,
9809 devconfig
|= SCBSIZE32
;
9810 pcibios_write_config_dword(pci_bus
, pci_devfn
, DEVCONFIG
,
9820 * Loading of the SEEPROM needs to come after we've set the flags
9821 * to indicate possible CHNLB and CHNLC assigments. Otherwise,
9822 * on 394x and 398x cards we'll end up reading the wrong settings
9823 * for channels B and C
9825 switch (temp_p
->chip
& AHC_CHIPID_MASK
)
9829 aic_outb(temp_p
, 0, SCAMCTL
);
9831 * Switch to the alt mode of the chip...
9833 aic_outb(temp_p
, aic_inb(temp_p
, SFUNCT
) | ALT_MODE
, SFUNCT
);
9835 * Set our options...the last two items set our CRC after x byte
9836 * count in target mode...
9838 aic_outb(temp_p
, AUTO_MSGOUT_DE
| DIS_MSGIN_DUALEDGE
, OPTIONMODE
);
9839 aic_outb(temp_p
, 0x00, 0x0b);
9840 aic_outb(temp_p
, 0x10, 0x0a);
9842 * switch back to normal mode...
9844 aic_outb(temp_p
, aic_inb(temp_p
, SFUNCT
) & ~ALT_MODE
, SFUNCT
);
9845 aic_outb(temp_p
, CRCVALCHKEN
| CRCENDCHKEN
| CRCREQCHKEN
|
9846 TARGCRCENDEN
| TARGCRCCNTEN
,
9848 aic_outb(temp_p
, ((aic_inb(temp_p
, DSCOMMAND0
) | USCBSIZE32
|
9849 MPARCKEN
| CIOPARCKEN
| CACHETHEN
) &
9850 ~DPARCKEN
), DSCOMMAND0
);
9851 aic7xxx_load_seeprom(temp_p
, &sxfrctl1
);
9855 aic_outb(temp_p
, 0, SCAMCTL
);
9856 aic_outb(temp_p
, (aic_inb(temp_p
, DSCOMMAND0
) |
9857 CACHETHEN
| MPARCKEN
| USCBSIZE32
|
9858 CIOPARCKEN
) & ~DPARCKEN
, DSCOMMAND0
);
9859 aic7xxx_load_seeprom(temp_p
, &sxfrctl1
);
9864 * Set the DSCOMMAND0 register on these cards different from
9865 * on the 789x cards. Also, read the SEEPROM as well.
9867 aic_outb(temp_p
, (aic_inb(temp_p
, DSCOMMAND0
) |
9868 CACHETHEN
| MPARCKEN
) & ~DPARCKEN
,
9872 aic7xxx_load_seeprom(temp_p
, &sxfrctl1
);
9876 * Check the rev of the chipset before we change DSCOMMAND0
9878 #if LINUX_VERSION_CODE > KERNEL_VERSION(2,1,92)
9879 pci_read_config_dword(pdev
, DEVCONFIG
, &devconfig
);
9881 pcibios_read_config_dword(pci_bus
, pci_devfn
, DEVCONFIG
,
9884 if ((devconfig
& 0xff) >= 1)
9886 aic_outb(temp_p
, (aic_inb(temp_p
, DSCOMMAND0
) |
9887 CACHETHEN
| MPARCKEN
) & ~DPARCKEN
,
9890 aic7xxx_load_seeprom(temp_p
, &sxfrctl1
);
9896 * and then we need another switch based on the type in order to
9897 * make sure the channel B primary flag is set properly on 7895
9898 * controllers....Arrrgggghhh!!! We also have to catch the fact
9899 * that when you disable the BIOS on the 7895 on the Intel DK440LX
9900 * motherboard, and possibly others, it only sets the BIOS disabled
9901 * bit on the A channel...I think I'm starting to lean towards
9904 switch(temp_p
->chip
& AHC_CHIPID_MASK
)
9910 while(current_p
!= NULL
)
9912 if ( (current_p
->pci_bus
== temp_p
->pci_bus
) &&
9913 (PCI_SLOT(current_p
->pci_device_fn
) ==
9914 PCI_SLOT(temp_p
->pci_device_fn
)) )
9916 if ( PCI_FUNC(current_p
->pci_device_fn
) == 0 )
9919 (current_p
->flags
& AHC_CHANNEL_B_PRIMARY
);
9920 temp_p
->flags
&= ~(AHC_BIOS_ENABLED
|AHC_USEDEFAULTS
);
9922 (current_p
->flags
& (AHC_BIOS_ENABLED
|AHC_USEDEFAULTS
));
9927 (temp_p
->flags
& AHC_CHANNEL_B_PRIMARY
);
9928 current_p
->flags
&= ~(AHC_BIOS_ENABLED
|AHC_USEDEFAULTS
);
9930 (temp_p
->flags
& (AHC_BIOS_ENABLED
|AHC_USEDEFAULTS
));
9933 current_p
= current_p
->next
;
9941 * We only support external SCB RAM on the 7895/6/7 chipsets.
9942 * We could support it on the 7890/1 easy enough, but I don't
9943 * know of any 7890/1 based cards that have it. I do know
9944 * of 7895/6/7 cards that have it and they work properly.
9946 switch(temp_p
->chip
& AHC_CHIPID_MASK
)
9953 #if LINUX_VERSION_CODE > KERNEL_VERSION(2,1,92)
9954 pci_read_config_dword(pdev
, DEVCONFIG
, &devconfig
);
9956 pcibios_read_config_dword(pci_bus
, pci_devfn
, DEVCONFIG
,
9959 if (temp_p
->features
& AHC_ULTRA2
)
9961 if (aic_inb(temp_p
, DSCOMMAND0
) & RAMPSM_ULTRA2
)
9964 aic_inb(temp_p
, DSCOMMAND0
) & ~SCBRAMSEL_ULTRA2
,
9966 temp_p
->flags
|= AHC_EXTERNAL_SRAM
;
9967 devconfig
|= EXTSCBPEN
;
9970 else if (devconfig
& RAMPSM
)
9972 devconfig
&= ~SCBRAMSEL
;
9973 devconfig
|= EXTSCBPEN
;
9974 temp_p
->flags
|= AHC_EXTERNAL_SRAM
;
9976 #if LINUX_VERSION_CODE > KERNEL_VERSION(2,1,92)
9977 pci_write_config_dword(pdev
, DEVCONFIG
, devconfig
);
9979 pcibios_write_config_dword(pci_bus
, pci_devfn
, DEVCONFIG
,
9982 if ( (temp_p
->flags
& AHC_EXTERNAL_SRAM
) &&
9983 (temp_p
->flags
& AHC_CHNLB
) )
9984 aic_outb(temp_p
, 1, CCSCBBADDR
);
9989 * Take the LED out of diagnostic mode
9992 (aic_inb(temp_p
, SBLKCTL
) & ~(DIAGLEDEN
| DIAGLEDON
)),
9996 * We don't know where this is set in the SEEPROM or by the
9997 * BIOS, so we default to 100%. On Ultra2 controllers, use 75%
10000 if (temp_p
->features
& AHC_ULTRA2
)
10002 aic_outb(temp_p
, RD_DFTHRSH_MAX
| WR_DFTHRSH_MAX
, DFF_THRSH
);
10006 aic_outb(temp_p
, DFTHRSH_100
, DSPCISTATUS
);
10009 if ( list_p
== NULL
)
10011 list_p
= current_p
= temp_p
;
10015 current_p
= list_p
;
10016 while(current_p
->next
!= NULL
)
10017 current_p
= current_p
->next
;
10018 current_p
->next
= temp_p
;
10020 temp_p
->next
= NULL
;
10022 } /* Found an Adaptec PCI device. */
10023 else /* Well, we found one, but we couldn't get any memory */
10025 printk("aic7xxx: Found <%s>\n",
10026 board_names
[aic_pdevs
[i
].board_name_index
]);
10027 printk(KERN_INFO
"aic7xxx: Unable to allocate device memory, "
10030 } /* while(pdev=....) */
10031 } /* for PCI_DEVICES */
10032 } /* PCI BIOS present */
10035 * Now, we re-order the probed devices by BIOS address and BUS class.
10036 * In general, we follow this algorithm to make the adapters show up
10037 * in the same order under linux that the computer finds them.
10038 * 1: All VLB/EISA cards with BIOS_ENABLED first, according to BIOS
10039 * address, going from lowest to highest.
10040 * 2: All PCI controllers with BIOS_ENABLED next, according to BIOS
10041 * address, going from lowest to highest.
10042 * 3: Remaining VLB/EISA controllers going in slot order.
10043 * 4: Remaining PCI controllers, going in PCI device order (reversable)
10047 struct aic7xxx_host
*sort_list
[4] = { NULL
, NULL
, NULL
, NULL
};
10048 struct aic7xxx_host
*vlb
, *pci
;
10049 struct aic7xxx_host
*prev_p
;
10050 struct aic7xxx_host
*p
;
10051 unsigned char left
;
10053 prev_p
= vlb
= pci
= NULL
;
10056 while (temp_p
!= NULL
)
10058 switch(temp_p
->chip
& ~AHC_CHIPID_MASK
)
10064 if (p
->flags
& AHC_BIOS_ENABLED
)
10065 vlb
= sort_list
[0];
10067 vlb
= sort_list
[2];
10072 temp_p
= temp_p
->next
;
10079 while ( (current_p
!= NULL
) &&
10080 (current_p
->bios_address
< temp_p
->bios_address
))
10082 prev_p
= current_p
;
10083 current_p
= current_p
->next
;
10085 if (prev_p
!= NULL
)
10087 prev_p
->next
= temp_p
;
10088 temp_p
= temp_p
->next
;
10089 prev_p
->next
->next
= current_p
;
10094 temp_p
= temp_p
->next
;
10095 vlb
->next
= current_p
;
10099 if (p
->flags
& AHC_BIOS_ENABLED
)
10100 sort_list
[0] = vlb
;
10102 sort_list
[2] = vlb
;
10106 default: /* All PCI controllers fall through to default */
10110 if (p
->flags
& AHC_BIOS_ENABLED
)
10111 pci
= sort_list
[1];
10113 pci
= sort_list
[3];
10118 temp_p
= temp_p
->next
;
10125 if (!aic7xxx_reverse_scan
)
10127 while ( (current_p
!= NULL
) &&
10128 ( (PCI_SLOT(current_p
->pci_device_fn
) |
10129 (current_p
->pci_bus
<< 8)) <
10130 (PCI_SLOT(temp_p
->pci_device_fn
) |
10131 (temp_p
->pci_bus
<< 8)) ) )
10133 prev_p
= current_p
;
10134 current_p
= current_p
->next
;
10139 while ( (current_p
!= NULL
) &&
10140 ( (PCI_SLOT(current_p
->pci_device_fn
) |
10141 (current_p
->pci_bus
<< 8)) >
10142 (PCI_SLOT(temp_p
->pci_device_fn
) |
10143 (temp_p
->pci_bus
<< 8)) ) )
10145 prev_p
= current_p
;
10146 current_p
= current_p
->next
;
10150 * Are we dealing with a 7895/6/7/9 where we need to sort the
10151 * channels as well, if so, the bios_address values should
10154 if ( (current_p
) && (temp_p
->flags
& AHC_MULTI_CHANNEL
) &&
10155 (temp_p
->pci_bus
== current_p
->pci_bus
) &&
10156 (PCI_SLOT(temp_p
->pci_device_fn
) ==
10157 PCI_SLOT(current_p
->pci_device_fn
)) )
10159 if (temp_p
->flags
& AHC_CHNLB
)
10161 if ( !(temp_p
->flags
& AHC_CHANNEL_B_PRIMARY
) )
10163 prev_p
= current_p
;
10164 current_p
= current_p
->next
;
10169 if (temp_p
->flags
& AHC_CHANNEL_B_PRIMARY
)
10171 prev_p
= current_p
;
10172 current_p
= current_p
->next
;
10176 if (prev_p
!= NULL
)
10178 prev_p
->next
= temp_p
;
10179 temp_p
= temp_p
->next
;
10180 prev_p
->next
->next
= current_p
;
10185 temp_p
= temp_p
->next
;
10186 pci
->next
= current_p
;
10190 if (p
->flags
& AHC_BIOS_ENABLED
)
10191 sort_list
[1] = pci
;
10193 sort_list
[3] = pci
;
10197 } /* End of switch(temp_p->type) */
10198 } /* End of while (temp_p != NULL) */
10200 * At this point, the cards have been broken into 4 sorted lists, now
10201 * we run through the lists in order and register each controller
10207 for (i
=0; i
<NUMBER(sort_list
); i
++)
10209 temp_p
= sort_list
[i
];
10210 while(temp_p
!= NULL
)
10212 template->name
= board_names
[temp_p
->board_name_index
];
10213 p
= aic7xxx_alloc(template, temp_p
);
10216 p
->instance
= found
- left
;
10217 if (aic7xxx_register(template, p
, (--left
)) == 0)
10220 aic7xxx_release(p
->host
);
10221 scsi_unregister(p
->host
);
10223 else if (aic7xxx_dump_card
)
10225 pause_sequencer(p
);
10226 aic7xxx_print_card(p
);
10227 aic7xxx_print_scratch_ram(p
);
10228 unpause_sequencer(p
, TRUE
);
10231 current_p
= temp_p
;
10232 temp_p
= (struct aic7xxx_host
*)temp_p
->next
;
10241 static void aic7xxx_build_negotiation_cmnd(struct aic7xxx_host
*p
,
10242 Scsi_Cmnd
*old_cmd
, int tindex
);
10244 /*+F*************************************************************************
10246 * aic7xxx_allocate_negotiation_command
10249 * allocate the actual command struct and fill in the gaps...
10250 *-F*************************************************************************/
10252 aic7xxx_allocate_negotiation_command(struct aic7xxx_host
*p
,
10253 Scsi_Cmnd
*old_cmd
, int tindex
)
10258 if (!(p
->dev_dtr_cmnd
[tindex
] = kmalloc(sizeof(Scsi_Cmnd
), GFP_ATOMIC
)) )
10262 if (!(buffer
= kmalloc(256, GFP_ATOMIC
)))
10264 kfree(p
->dev_dtr_cmnd
[tindex
]);
10265 p
->dev_dtr_cmnd
[tindex
] = NULL
;
10268 cmd
= p
->dev_dtr_cmnd
[tindex
];
10269 memset(cmd
, 0, sizeof(Scsi_Cmnd
));
10270 memcpy(cmd
, old_cmd
, sizeof(Scsi_Cmnd
));
10271 memset(&cmd
->cmnd
[0], 0, sizeof(cmd
->cmnd
));
10272 memset(&cmd
->data_cmnd
[0], 0, sizeof(cmd
->data_cmnd
));
10274 cmd
->request_bufflen
= 255;
10275 cmd
->request_buffer
= buffer
;
10276 cmd
->use_sg
= cmd
->old_use_sg
= cmd
->sglist_len
= 0;
10278 cmd
->buffer
= NULL
;
10279 cmd
->underflow
= 0;
10281 cmd
->cmnd
[0] = cmd
->data_cmnd
[0] = INQUIRY
;
10282 cmd
->cmnd
[1] = cmd
->data_cmnd
[1] = 0;
10283 cmd
->cmnd
[2] = cmd
->data_cmnd
[2] = 0;
10284 cmd
->cmnd
[3] = cmd
->data_cmnd
[3] = 0;
10285 cmd
->cmnd
[4] = cmd
->data_cmnd
[4] = 255; /* match what scsi.c does here */
10286 cmd
->cmnd
[5] = cmd
->data_cmnd
[5] = 0;
10290 /*+F*************************************************************************
10292 * aic7xxx_negotiation_complete
10295 * Handle completion events for our Negotiation commands. Clear out the
10296 * struct and get it ready for its next use.
10297 *-F*************************************************************************/
10299 aic7xxx_negotiation_complete(Scsi_Cmnd
*cmd
)
10301 unsigned int checksum
;
10304 struct aic7xxx_host
*p
= (struct aic7xxx_host
*)cmd
->host
->hostdata
;
10305 int tindex
= TARGET_INDEX(cmd
);
10306 struct aic7xxx_syncrate
*syncrate
;
10309 * perform our minimalistic domain validation
10311 if(p
->dev_flags
[tindex
] & DEVICE_SCANNED
)
10313 ibuffer
= (int *)cmd
->request_buffer
;
10315 for(i
= 0; i
< (cmd
->request_bufflen
>> 2); i
++)
10317 checksum
+= ibuffer
[i
];
10319 if( (checksum
!= p
->dev_checksum
[tindex
]) &&
10320 (p
->transinfo
[tindex
].cur_offset
!= 0) )
10322 unsigned int period
= p
->transinfo
[tindex
].cur_period
;
10323 unsigned char options
= p
->transinfo
[tindex
].cur_options
;
10325 if (p
->needdv
& (1<<tindex
))
10328 * oops, we had a failure, lower the transfer rate and try again. It's
10329 * worth noting here that it might be wise to also check for typical
10330 * wide setting on narrow cable type problems and try disabling wide
10331 * instead of slowing down if those exist. That's hard to do with simple
10332 * checksums though.
10334 if(aic7xxx_verbose
& VERBOSE_NEGOTIATION
)
10336 printk(INFO_LEAD
"reducing SCSI transfer speed due to Domain "
10337 "validation failure.\n", p
->host_no
, CTL_OF_CMD(cmd
));
10339 if((syncrate
= aic7xxx_find_syncrate(p
, &period
, 0, &options
)) != NULL
)
10342 if( (syncrate
->rate
[0] != NULL
) &&
10343 (!(p
->features
& AHC_ULTRA2
) || (syncrate
->sxfr_ultra2
== 0)) )
10345 p
->transinfo
[tindex
].goal_period
= syncrate
->period
;
10346 if( !(syncrate
->sxfr_ultra2
& 0x40) )
10348 p
->transinfo
[tindex
].goal_options
= 0;
10353 p
->transinfo
[tindex
].goal_offset
= 0;
10354 p
->transinfo
[tindex
].goal_period
= 0;
10355 p
->transinfo
[tindex
].goal_options
= 0;
10357 p
->needppr
|= (p
->needppr_copy
& (1<<tindex
));
10358 p
->needsdtr
|= (p
->needsdtr_copy
& (1<<tindex
));
10359 p
->needwdtr
|= (p
->needwdtr_copy
& (1<<tindex
));
10361 p
->needdv
&= ~(1<<tindex
);
10365 if(aic7xxx_verbose
& VERBOSE_NEGOTIATION
)
10367 printk(INFO_LEAD
"Performing Domain validation.\n",
10368 p
->host_no
, CTL_OF_CMD(cmd
));
10371 * Update the checksum in case the INQUIRY data has changed, maybe
10372 * in relation to a change in the mode pages, or whatever.
10374 p
->dev_checksum
[tindex
] = checksum
;
10376 * Signal that we are trying out the domain validation
10378 p
->needdv
|= (1<<tindex
);
10380 * Signal that we need to re-negotiate things, this also gets us our
10381 * INQUIRY command to re-checksum off of.
10383 p
->needppr
|= (p
->needppr_copy
& (1<<tindex
));
10384 p
->needsdtr
|= (p
->needsdtr_copy
& (1<<tindex
));
10385 p
->needwdtr
|= (p
->needwdtr_copy
& (1<<tindex
));
10390 if( (aic7xxx_verbose
& VERBOSE_NEGOTIATION
) &&
10391 (p
->needdv
& (1<<tindex
)) )
10393 printk(INFO_LEAD
"Successfully completed Domain validation.\n",
10394 p
->host_no
, CTL_OF_CMD(cmd
));
10397 * We successfully did our checksum, so don't leave the needdv flag set
10398 * in case we might have set it last time through.
10400 p
->needdv
&= ~(1<<tindex
);
10404 p
->dtr_pending
&= ~(0x01 << tindex
);
10406 * This looks recursive in the extreme, but if this was a WDTR negotiation
10407 * and we didn't follow up with SDTR yet, then this will get it started.
10408 * For all other cases, this should work out to be a no-op, unless we are
10409 * doing domain validation and happen to need a new negotiation command.
10411 aic7xxx_build_negotiation_cmnd(p
, cmd
->next
, tindex
);
10415 /*+F*************************************************************************
10417 * aic7xxx_build_negotiation_command
10420 * Build a Scsi_Cmnd structure to perform negotiation with or else send
10421 * a pre-built command specifically for this purpose.
10422 *-F*************************************************************************/
10424 aic7xxx_build_negotiation_cmnd(struct aic7xxx_host
*p
, Scsi_Cmnd
*old_cmd
,
10428 if ( !(p
->dtr_pending
& (1<<tindex
)) &&
10429 ( (p
->needppr
& (1<<tindex
)) ||
10430 (p
->needwdtr
& (1<<tindex
)) ||
10431 (p
->needsdtr
& (1<<tindex
)) ) )
10433 if ( (p
->dev_dtr_cmnd
[tindex
] == NULL
) &&
10434 (aic7xxx_allocate_negotiation_command(p
, old_cmd
, tindex
) == NULL
) )
10439 * Before sending this thing out, we also make the cmd->next pointer
10440 * point to the real command so we can stuff any possible SENSE data
10441 * into the real command instead of this fake command. This has to be
10442 * done each time the command is built, not just the first time, hence
10443 * it's outside of the above if()...
10445 p
->dev_dtr_cmnd
[tindex
]->next
= old_cmd
;
10447 * Clear the buffer so checksums come out right....
10449 memset(p
->dev_dtr_cmnd
[tindex
]->request_buffer
, 0,
10450 p
->dev_dtr_cmnd
[tindex
]->request_bufflen
);
10452 * Remove any commands for this particular device that might be on the
10453 * waiting_scbs queue or qinfifo so that this command goes out first.
10454 * This is vital for our implementation of domain validation.
10456 pause_sequencer(p
);
10457 aic7xxx_search_qinfifo(p
, old_cmd
->target
, old_cmd
->channel
, ALL_LUNS
,
10458 SCB_LIST_NULL
, 0, TRUE
, &p
->delayed_scbs
[tindex
]);
10459 unpause_sequencer(p
, FALSE
);
10461 struct aic7xxx_scb
*scb
, *next
;
10463 scb
= p
->waiting_scbs
.head
;
10466 if( aic7xxx_match_scb(p
, scb
, old_cmd
->target
, old_cmd
->channel
,
10467 ALL_LUNS
, SCB_LIST_NULL
) )
10469 next
= scb
->q_next
;
10470 scbq_remove(&p
->waiting_scbs
, scb
);
10471 scbq_insert_tail(&p
->delayed_scbs
[tindex
], scb
);
10480 aic7xxx_queue(p
->dev_dtr_cmnd
[tindex
],
10481 aic7xxx_negotiation_complete
);
10485 #ifdef AIC7XXX_VERBOSE_DEBUGGING
10486 /*+F*************************************************************************
10488 * aic7xxx_print_scb
10491 * Dump the byte codes for an about to be sent SCB.
10492 *-F*************************************************************************/
10494 aic7xxx_print_scb(struct aic7xxx_host
*p
, struct aic7xxx_scb
*scb
)
10499 x
= (unsigned char *)&scb
->hscb
->control
;
10501 for(i
=0; i
<32; i
++)
10503 printk("%02x ", x
[i
]);
10509 /*+F*************************************************************************
10515 *-F*************************************************************************/
10517 aic7xxx_buildscb(struct aic7xxx_host
*p
, Scsi_Cmnd
*cmd
,
10518 struct aic7xxx_scb
*scb
)
10520 unsigned short mask
;
10521 struct aic7xxx_hwscb
*hscb
;
10522 unsigned char tindex
= TARGET_INDEX(cmd
);
10524 mask
= (0x01 << tindex
);
10528 * Setup the control byte if we need negotiation and have not
10529 * already requested it.
10532 scb
->tag_action
= 0;
10533 if (p
->discenable
& mask
)
10535 hscb
->control
|= DISCENB
;
10536 if ( (p
->tagenable
& mask
) &&
10537 (cmd
->cmnd
[0] != TEST_UNIT_READY
) )
10539 cmd
->tag
= hscb
->tag
;
10540 p
->dev_commands_sent
[tindex
]++;
10541 if (p
->dev_commands_sent
[tindex
] < 200)
10543 hscb
->control
|= MSG_SIMPLE_Q_TAG
;
10544 scb
->tag_action
= MSG_SIMPLE_Q_TAG
;
10548 if (p
->orderedtag
& mask
)
10550 hscb
->control
|= MSG_ORDERED_Q_TAG
;
10551 scb
->tag_action
= MSG_ORDERED_Q_TAG
;
10555 hscb
->control
|= MSG_SIMPLE_Q_TAG
;
10556 scb
->tag_action
= MSG_SIMPLE_Q_TAG
;
10558 p
->dev_commands_sent
[tindex
] = 0;
10562 if ( cmd
== p
->dev_dtr_cmnd
[tindex
] )
10564 p
->dtr_pending
|= mask
;
10565 scb
->tag_action
= 0;
10566 if (p
->dev_flags
[tindex
] & DEVICE_SCANNED
)
10568 hscb
->control
&= DISCENB
;
10569 hscb
->control
|= MK_MESSAGE
;
10570 if(p
->needppr
& mask
)
10572 scb
->flags
|= SCB_MSGOUT_PPR
;
10574 else if(p
->needwdtr
& mask
)
10576 scb
->flags
|= SCB_MSGOUT_WDTR
;
10578 else if(p
->needsdtr
& mask
)
10580 scb
->flags
|= SCB_MSGOUT_SDTR
;
10584 if ( !(p
->dtr_pending
& mask
) &&
10585 ( (p
->needppr
& mask
) ||
10586 (p
->needwdtr
& mask
) ||
10587 (p
->needsdtr
& mask
) ) )
10589 aic7xxx_build_negotiation_cmnd(p
, cmd
, tindex
);
10591 hscb
->target_channel_lun
= ((cmd
->target
<< 4) & 0xF0) |
10592 ((cmd
->channel
& 0x01) << 3) | (cmd
->lun
& 0x07);
10595 * The interpretation of request_buffer and request_bufflen
10596 * changes depending on whether or not use_sg is zero; a
10597 * non-zero use_sg indicates the number of elements in the
10598 * scatter-gather array.
10602 * XXX - this relies on the host data being stored in a
10603 * little-endian format.
10605 hscb
->SCSI_cmd_length
= cmd
->cmd_len
;
10606 hscb
->SCSI_cmd_pointer
= cpu_to_le32(VIRT_TO_BUS(cmd
->cmnd
));
10610 struct scatterlist
*sg
; /* Must be mid-level SCSI code scatterlist */
10613 * We must build an SG list in adapter format, as the kernel's SG list
10614 * cannot be used directly because of data field size (__alpha__)
10615 * differences and the kernel SG list uses virtual addresses where
10616 * we need physical addresses.
10620 sg
= (struct scatterlist
*)cmd
->request_buffer
;
10621 scb
->sg_length
= 0;
10623 * Copy the segments into the SG array. NOTE!!! - We used to
10624 * have the first entry both in the data_pointer area and the first
10625 * SG element. That has changed somewhat. We still have the first
10626 * entry in both places, but now we download the address of
10627 * scb->sg_list[1] instead of 0 to the sg pointer in the hscb.
10629 for (i
= 0; i
< cmd
->use_sg
; i
++)
10631 scb
->sg_list
[i
].address
= cpu_to_le32(VIRT_TO_BUS(sg
[i
].address
));
10632 scb
->sg_list
[i
].length
= cpu_to_le32(sg
[i
].length
);
10633 scb
->sg_length
+= sg
[i
].length
;
10635 /* Copy the first SG into the data pointer area. */
10636 hscb
->data_pointer
= scb
->sg_list
[0].address
;
10637 hscb
->data_count
= scb
->sg_list
[0].length
;
10638 scb
->sg_count
= cmd
->use_sg
;
10639 hscb
->SG_segment_count
= cmd
->use_sg
;
10640 hscb
->SG_list_pointer
= cpu_to_le32(VIRT_TO_BUS(&scb
->sg_list
[1]));
10644 if (cmd
->request_bufflen
)
10647 scb
->sg_list
[0].address
= cpu_to_le32(VIRT_TO_BUS(cmd
->request_buffer
));
10648 scb
->sg_list
[0].length
= cpu_to_le32(cmd
->request_bufflen
);
10649 scb
->sg_length
= cmd
->request_bufflen
;
10650 hscb
->SG_segment_count
= 1;
10651 hscb
->SG_list_pointer
= cpu_to_le32(VIRT_TO_BUS(&scb
->sg_list
[0]));
10652 hscb
->data_count
= scb
->sg_list
[0].length
;
10653 hscb
->data_pointer
= scb
->sg_list
[0].address
;
10658 scb
->sg_length
= 0;
10659 hscb
->SG_segment_count
= 0;
10660 hscb
->SG_list_pointer
= 0;
10661 hscb
->data_count
= 0;
10662 hscb
->data_pointer
= 0;
10667 /*+F*************************************************************************
10672 * Queue a SCB to the controller.
10673 *-F*************************************************************************/
10675 aic7xxx_queue(Scsi_Cmnd
*cmd
, void (*fn
)(Scsi_Cmnd
*))
10677 struct aic7xxx_host
*p
;
10678 struct aic7xxx_scb
*scb
;
10679 #ifdef AIC7XXX_VERBOSE_DEBUGGING
10680 int tindex
= TARGET_INDEX(cmd
);
10682 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,1,95)
10683 unsigned long cpu_flags
= 0;
10686 p
= (struct aic7xxx_host
*) cmd
->host
->hostdata
;
10688 * Check to see if channel was scanned.
10691 #ifdef AIC7XXX_VERBOSE_DEBUGGING
10692 if (!(p
->flags
& AHC_A_SCANNED
) && (cmd
->channel
== 0))
10694 if (aic7xxx_verbose
& VERBOSE_PROBE2
)
10695 printk(INFO_LEAD
"Scanning channel for devices.\n",
10696 p
->host_no
, 0, -1, -1);
10697 p
->flags
|= AHC_A_SCANNED
;
10701 if (!(p
->flags
& AHC_B_SCANNED
) && (cmd
->channel
== 1))
10703 if (aic7xxx_verbose
& VERBOSE_PROBE2
)
10704 printk(INFO_LEAD
"Scanning channel for devices.\n",
10705 p
->host_no
, 1, -1, -1);
10706 p
->flags
|= AHC_B_SCANNED
;
10710 if (p
->dev_active_cmds
[tindex
] > (cmd
->device
->queue_depth
+ 1))
10712 printk(WARN_LEAD
"Commands queued exceeds queue "
10713 "depth, active=%d\n",
10714 p
->host_no
, CTL_OF_CMD(cmd
),
10715 p
->dev_active_cmds
[tindex
]);
10716 if ( p
->dev_active_cmds
[tindex
] > 220 )
10717 p
->dev_active_cmds
[tindex
] = 0;
10721 scb
= scbq_remove_head(&p
->scb_data
->free_scbs
);
10725 aic7xxx_allocate_scb(p
);
10727 scb
= scbq_remove_head(&p
->scb_data
->free_scbs
);
10731 printk(WARN_LEAD
"Couldn't get a free SCB.\n", p
->host_no
,
10733 cmd
->result
= (DID_BUS_BUSY
<< 16);
10735 aic7xxx_queue_cmd_complete(p
, cmd
);
10742 aic7xxx_position(cmd
) = scb
->hscb
->tag
;
10745 * Construct the SCB beforehand, so the sequencer is
10746 * paused a minimal amount of time.
10748 aic7xxx_buildscb(p
, cmd
, scb
);
10751 * Make sure the Scsi_Cmnd pointer is saved, the struct it points to
10752 * is set up properly, and the parity error flag is reset, then send
10753 * the SCB to the sequencer and watch the fun begin.
10755 cmd
->scsi_done
= fn
;
10756 cmd
->result
= DID_OK
;
10757 memset(cmd
->sense_buffer
, 0, sizeof(cmd
->sense_buffer
));
10758 aic7xxx_error(cmd
) = DID_OK
;
10759 aic7xxx_status(cmd
) = 0;
10760 cmd
->host_scribble
= NULL
;
10762 scb
->flags
|= SCB_ACTIVE
| SCB_WAITINGQ
;
10765 scbq_insert_tail(&p
->waiting_scbs
, scb
);
10766 if ( (p
->flags
& (AHC_IN_ISR
| AHC_IN_ABORT
| AHC_IN_RESET
)) == 0)
10768 aic7xxx_run_waiting_queues(p
);
10775 /*+F*************************************************************************
10777 * aic7xxx_bus_device_reset
10780 * Abort or reset the current SCSI command(s). If the scb has not
10781 * previously been aborted, then we attempt to send a BUS_DEVICE_RESET
10782 * message to the target. If the scb has previously been unsuccessfully
10783 * aborted, then we will reset the channel and have all devices renegotiate.
10784 * Returns an enumerated type that indicates the status of the operation.
10785 *-F*************************************************************************/
10787 aic7xxx_bus_device_reset(struct aic7xxx_host
*p
, Scsi_Cmnd
*cmd
)
10789 struct aic7xxx_scb
*scb
;
10790 struct aic7xxx_hwscb
*hscb
;
10793 unsigned char saved_scbptr
, lastphase
;
10794 unsigned char hscb_index
;
10797 scb
= (p
->scb_data
->scb_array
[aic7xxx_position(cmd
)]);
10800 lastphase
= aic_inb(p
, LASTPHASE
);
10801 if (aic7xxx_verbose
& VERBOSE_RESET_PROCESS
)
10803 printk(INFO_LEAD
"Bus Device reset, scb flags 0x%x, ",
10804 p
->host_no
, CTL_OF_SCB(scb
), scb
->flags
);
10808 printk("Data-Out phase\n");
10811 printk("Data-In phase\n");
10814 printk("Command phase\n");
10817 printk("Message-Out phase\n");
10820 printk("Status phase\n");
10823 printk("Message-In phase\n");
10827 * We're not in a valid phase, so assume we're idle.
10829 printk("while idle, LASTPHASE = 0x%x\n", lastphase
);
10832 printk(INFO_LEAD
"SCSISIGI 0x%x, SEQADDR 0x%x, SSTAT0 0x%x, SSTAT1 "
10833 "0x%x\n", p
->host_no
, CTL_OF_SCB(scb
),
10834 aic_inb(p
, SCSISIGI
),
10835 aic_inb(p
, SEQADDR0
) | (aic_inb(p
, SEQADDR1
) << 8),
10836 aic_inb(p
, SSTAT0
), aic_inb(p
, SSTAT1
));
10839 channel
= cmd
->channel
;
10842 * Send a Device Reset Message:
10843 * The target that is holding up the bus may not be the same as
10844 * the one that triggered this timeout (different commands have
10845 * different timeout lengths). Our strategy here is to queue an
10846 * abort message to the timed out target if it is disconnected.
10847 * Otherwise, if we have an active target we stuff the message buffer
10848 * with an abort message and assert ATN in the hopes that the target
10849 * will let go of the bus and go to the mesgout phase. If this
10850 * fails, we'll get another timeout a few seconds later which will
10851 * attempt a bus reset.
10853 saved_scbptr
= aic_inb(p
, SCBPTR
);
10854 disconnected
= FALSE
;
10856 if (lastphase
!= P_BUSFREE
)
10858 if (aic_inb(p
, SCB_TAG
) >= p
->scb_data
->numscbs
)
10860 printk(WARN_LEAD
"Invalid SCB ID %d is active, "
10861 "SCB flags = 0x%x.\n", p
->host_no
,
10862 CTL_OF_CMD(cmd
), scb
->hscb
->tag
, scb
->flags
);
10863 return(SCSI_RESET_ERROR
);
10865 if (scb
->hscb
->tag
== aic_inb(p
, SCB_TAG
))
10867 if ( (lastphase
!= P_MESGOUT
) && (lastphase
!= P_MESGIN
) )
10869 if (aic7xxx_verbose
& VERBOSE_RESET_PROCESS
)
10870 printk(INFO_LEAD
"Device reset message in "
10871 "message buffer\n", p
->host_no
, CTL_OF_SCB(scb
));
10872 scb
->flags
|= SCB_RESET
| SCB_DEVICE_RESET
;
10873 aic7xxx_error(scb
->cmd
) = DID_RESET
;
10874 p
->dev_flags
[TARGET_INDEX(scb
->cmd
)] |=
10875 BUS_DEVICE_RESET_PENDING
;
10876 /* Send the abort message to the active SCB. */
10877 aic_outb(p
, HOST_MSG
, MSG_OUT
);
10878 aic_outb(p
, lastphase
| ATNO
, SCSISIGO
);
10879 return(SCSI_RESET_PENDING
);
10883 /* We want to send out the message, but it could screw an already */
10884 /* in place and being used message. Instead, we return an error */
10885 /* to try and start the bus reset phase since this command is */
10886 /* probably hung (aborts failed, and now reset is failing). We */
10887 /* also make sure to set BUS_DEVICE_RESET_PENDING so we won't try */
10888 /* any more on this device, but instead will escalate to a bus or */
10889 /* host reset (additionally, we won't try to abort any more). */
10890 printk(WARN_LEAD
"Device reset, Message buffer "
10891 "in use\n", p
->host_no
, CTL_OF_SCB(scb
));
10892 scb
->flags
|= SCB_RESET
| SCB_DEVICE_RESET
;
10893 aic7xxx_error(scb
->cmd
) = DID_RESET
;
10894 p
->dev_flags
[TARGET_INDEX(scb
->cmd
)] |=
10895 BUS_DEVICE_RESET_PENDING
;
10896 return(SCSI_RESET_ERROR
);
10899 } /* if (last_phase != P_BUSFREE).....indicates we are idle and can work */
10900 hscb_index
= aic7xxx_find_scb(p
, scb
);
10901 if (hscb_index
== SCB_LIST_NULL
)
10903 disconnected
= (aic7xxx_scb_on_qoutfifo(p
, scb
)) ? FALSE
: TRUE
;
10907 aic_outb(p
, hscb_index
, SCBPTR
);
10908 if (aic_inb(p
, SCB_CONTROL
) & DISCONNECTED
)
10910 disconnected
= TRUE
;
10916 * Simply set the MK_MESSAGE flag and the SEQINT handler will do
10917 * the rest on a reconnect.
10919 scb
->hscb
->control
|= MK_MESSAGE
;
10920 scb
->flags
|= SCB_RESET
| SCB_DEVICE_RESET
;
10921 p
->dev_flags
[TARGET_INDEX(scb
->cmd
)] |=
10922 BUS_DEVICE_RESET_PENDING
;
10923 if (hscb_index
!= SCB_LIST_NULL
)
10925 unsigned char scb_control
;
10927 aic_outb(p
, hscb_index
, SCBPTR
);
10928 scb_control
= aic_inb(p
, SCB_CONTROL
);
10929 aic_outb(p
, scb_control
| MK_MESSAGE
, SCB_CONTROL
);
10932 * Actually requeue this SCB in case we can select the
10933 * device before it reconnects. If the transaction we
10934 * want to abort is not tagged, then this will be the only
10935 * outstanding command and we can simply shove it on the
10936 * qoutfifo and be done. If it is tagged, then it goes right
10937 * in with all the others, no problem :) We need to add it
10938 * to the qinfifo and let the sequencer know it is there.
10939 * Now, the only problem left to deal with is, *IF* this
10940 * command completes, in spite of the MK_MESSAGE bit in the
10941 * control byte, then we need to pick that up in the interrupt
10942 * routine and clean things up. This *shouldn't* ever happen.
10944 if (aic7xxx_verbose
& VERBOSE_RESET_PROCESS
)
10945 printk(INFO_LEAD
"Queueing device reset "
10946 "command.\n", p
->host_no
, CTL_OF_SCB(scb
));
10947 p
->qinfifo
[p
->qinfifonext
++] = scb
->hscb
->tag
;
10948 if (p
->features
& AHC_QUEUE_REGS
)
10949 aic_outb(p
, p
->qinfifonext
, HNSCB_QOFF
);
10951 aic_outb(p
, p
->qinfifonext
, KERNEL_QINPOS
);
10952 scb
->flags
|= SCB_QUEUED_ABORT
;
10953 result
= SCSI_RESET_PENDING
;
10955 else if (result
== -1)
10957 result
= SCSI_RESET_ERROR
;
10959 aic_outb(p
, saved_scbptr
, SCBPTR
);
10964 /*+F*************************************************************************
10966 * aic7xxx_panic_abort
10969 * Abort the current SCSI command(s).
10970 *-F*************************************************************************/
10972 aic7xxx_panic_abort(struct aic7xxx_host
*p
, Scsi_Cmnd
*cmd
)
10974 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,1,0)
10975 int i
, mask
, found
, need_tag
;
10976 struct aic7xxx_scb
*scb
;
10977 unsigned char qinpos
, hscbp
;
10982 printk("aic7xxx driver version %s/%s\n", AIC7XXX_C_VERSION
,
10984 printk("Controller type:\n %s\n", board_names
[p
->board_name_index
]);
10985 printk("p->flags=0x%x, p->chip=0x%x, p->features=0x%x, "
10986 "sequencer %s paused\n",
10987 p
->flags
, p
->chip
, p
->features
,
10988 (aic_inb(p
, HCNTRL
) & PAUSE
) ? "is" : "isn't" );
10989 pause_sequencer(p
);
10990 disable_irq(p
->irq
);
10991 aic7xxx_print_card(p
);
10992 aic7xxx_print_scratch_ram(p
);
10993 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,1,0)
10994 for(i
=0; i
<MAX_TARGETS
; i
++)
10996 if(p
->dev_flags
[i
] & DEVICE_PRESENT
)
10998 mask
= (0x01 << i
);
10999 printk(INFO_LEAD
"dev_flags=0x%x, Pending:%c, PPR:%c/%c, WDTR:%c/%c, "
11000 "SDTR:%c/%c, q_depth=%d:%d\n",
11001 p
->host_no
, 0, i
, 0, p
->dev_flags
[i
],
11002 (p
->dtr_pending
& mask
) ? 'Y' : 'N',
11003 (p
->needppr
& mask
) ? 'Y' : 'N',
11004 (p
->needppr_copy
& mask
) ? 'Y' : 'N',
11005 (p
->needwdtr
& mask
) ? 'Y' : 'N',
11006 (p
->needwdtr_copy
& mask
) ? 'Y' : 'N',
11007 (p
->needsdtr
& mask
) ? 'Y' : 'N',
11008 (p
->needsdtr_copy
& mask
) ? 'Y' : 'N',
11009 p
->dev_active_cmds
[i
],
11010 p
->dev_max_queue_depth
[i
] );
11011 printk(INFO_LEAD
"targ_scsirate=0x%x", p
->host_no
, 0, i
, 0,
11012 aic_inb(p
, TARG_SCSIRATE
+ i
));
11013 if (p
->features
& AHC_ULTRA2
)
11014 printk(", targ_offset=%d", aic_inb(p
, TARG_OFFSET
+ i
));
11019 * Search for this command and see if we can't track it down, it's the
11020 * one causing the timeout. Print out this command first, then all other
11021 * active commands afterwords.
11026 scb
= p
->scb_data
->scb_array
[aic7xxx_position(cmd
)];
11027 if ( (scb
->flags
& SCB_ACTIVE
) && (scb
->cmd
== cmd
) )
11029 printk("Timed out command is scb #%d:\n", scb
->hscb
->tag
);
11030 printk("Tag%d: flags=0x%x, control=0x%x, TCL=0x%x, %s\n", scb
->hscb
->tag
,
11031 scb
->flags
, scb
->hscb
->control
, scb
->hscb
->target_channel_lun
,
11032 (scb
->flags
& SCB_WAITINGQ
) ? "WAITINGQ" : "Sent" );
11033 need_tag
= scb
->hscb
->tag
;
11034 if (scb
->flags
& SCB_WAITINGQ
) found
=TRUE
;
11037 printk("QINFIFO: (TAG) ");
11038 qinpos
= aic_inb(p
, QINPOS
);
11039 while ( qinpos
!= p
->qinfifonext
)
11041 if (p
->qinfifo
[qinpos
] == need_tag
)
11043 printk("%d ", p
->qinfifo
[qinpos
++]);
11046 printk("Current SCB: (SCBPTR/TAG/CONTROL) %d/%d/0x%x\n", aic_inb(p
, SCBPTR
),
11047 aic_inb(p
, SCB_TAG
), aic_inb(p
, SCB_CONTROL
) );
11048 if (aic_inb(p
, SCB_TAG
) == need_tag
) found
=TRUE
;
11049 printk("WAITING_SCBS: (SCBPTR/TAG/CONTROL) %d->",
11050 hscbp
= aic_inb(p
, WAITING_SCBH
));
11051 while (hscbp
!= SCB_LIST_NULL
)
11053 aic_outb(p
, hscbp
, SCBPTR
);
11054 printk("%d/%d/0x%x ", hscbp
, aic_inb(p
, SCB_TAG
), aic_inb(p
, SCB_CONTROL
));
11055 hscbp
= aic_inb(p
, SCB_NEXT
);
11056 if (aic_inb(p
, SCB_TAG
) == need_tag
) found
=TRUE
;
11059 printk("DISCONNECTED_SCBS: (SCBPTR/TAG/CONTROL) %d->",
11060 hscbp
= aic_inb(p
, DISCONNECTED_SCBH
));
11061 while (hscbp
!= SCB_LIST_NULL
)
11063 aic_outb(p
, hscbp
, SCBPTR
);
11064 printk("%d/%d/0x%x ", hscbp
, aic_inb(p
, SCB_TAG
), aic_inb(p
, SCB_CONTROL
));
11065 hscbp
= aic_inb(p
, SCB_NEXT
);
11066 if (aic_inb(p
, SCB_TAG
) == need_tag
) found
=TRUE
;
11069 printk("FREE_SCBS: (SCBPTR/TAG/CONTROL) %d->",
11070 hscbp
= aic_inb(p
, FREE_SCBH
));
11071 while (hscbp
!= SCB_LIST_NULL
)
11073 aic_outb(p
, hscbp
, SCBPTR
);
11074 printk("%d/%d/0x%x ", hscbp
, aic_inb(p
, SCB_TAG
), aic_inb(p
, SCB_CONTROL
));
11075 hscbp
= aic_inb(p
, SCB_NEXT
);
11079 if (found
== FALSE
)
11082 * We haven't found the offending SCB yet, and it should be around
11083 * somewhere, so go look for it in the cards SCBs.
11085 printk("SCBPTR CONTROL TAG NEXT\n");
11086 for(i
=0; i
<p
->scb_data
->maxhscbs
; i
++)
11088 aic_outb(p
, i
, SCBPTR
);
11089 printk(" %3d %02x %02x %02x\n", i
,
11090 aic_inb(p
, SCB_CONTROL
), aic_inb(p
, SCB_TAG
),
11091 aic_inb(p
, SCB_NEXT
));
11096 for (i
=0; i
< p
->scb_data
->numscbs
; i
++)
11098 scb
= p
->scb_data
->scb_array
[i
];
11099 if ( (scb
->flags
& SCB_ACTIVE
) && (scb
->cmd
!= cmd
) )
11101 printk("Tag%d: flags=0x%x, control=0x%x, TCL=0x%x, %s\n", scb
->hscb
->tag
,
11102 scb
->flags
, scb
->hscb
->control
, scb
->hscb
->target_channel_lun
,
11103 (scb
->flags
& SCB_WAITINGQ
) ? "WAITINGQ" : "Sent" );
11111 /*+F*************************************************************************
11116 * Abort the current SCSI command(s).
11117 *-F*************************************************************************/
11119 aic7xxx_abort(Scsi_Cmnd
*cmd
)
11121 struct aic7xxx_scb
*scb
= NULL
;
11122 struct aic7xxx_host
*p
;
11123 int result
, found
=0;
11124 unsigned char tmp_char
, saved_hscbptr
, next_hscbptr
, prev_hscbptr
;
11125 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,1,95)
11126 unsigned long cpu_flags
= 0;
11128 Scsi_Cmnd
*cmd_next
, *cmd_prev
;
11130 p
= (struct aic7xxx_host
*) cmd
->host
->hostdata
;
11131 scb
= (p
->scb_data
->scb_array
[aic7xxx_position(cmd
)]);
11134 * I added a new config option to the driver: "panic_on_abort" that will
11135 * cause the driver to panic and the machine to stop on the first abort
11136 * or reset call into the driver. At that point, it prints out a lot of
11137 * usefull information for me which I can then use to try and debug the
11138 * problem. Simply enable the boot time prompt in order to activate this
11141 if (aic7xxx_panic_on_abort
)
11142 aic7xxx_panic_abort(p
, cmd
);
11147 * Run the isr to grab any command in the QOUTFIFO and any other misc.
11148 * assundry tasks. This should also set up the bh handler if there is
11149 * anything to be done, but it won't run until we are done here since
11150 * we are following a straight code path without entering the scheduler
11154 pause_sequencer(p
);
11155 while ( (aic_inb(p
, INTSTAT
) & INT_PEND
) && !(p
->flags
& AHC_IN_ISR
))
11157 aic7xxx_isr(p
->irq
, p
, (void *)NULL
);
11158 pause_sequencer(p
);
11159 aic7xxx_done_cmds_complete(p
);
11162 if ((scb
== NULL
) || (cmd
->serial_number
!= cmd
->serial_number_at_timeout
))
11163 /* Totally bogus cmd since it points beyond our */
11164 { /* valid SCB range or doesn't even match it's own*/
11165 /* timeout serial number. */
11166 if (aic7xxx_verbose
& VERBOSE_ABORT_MID
)
11167 printk(INFO_LEAD
"Abort called with bogus Scsi_Cmnd "
11168 "pointer.\n", p
->host_no
, CTL_OF_CMD(cmd
));
11169 unpause_sequencer(p
, FALSE
);
11171 return(SCSI_ABORT_NOT_RUNNING
);
11173 if (scb
->cmd
!= cmd
) /* Hmmm...either this SCB is currently free with a */
11174 { /* NULL cmd pointer (NULLed out when freed) or it */
11175 /* has already been recycled for another command */
11176 /* Either way, this SCB has nothing to do with this*/
11177 /* command and we need to deal with cmd without */
11178 /* touching the SCB. */
11179 /* The theory here is to return a value that will */
11180 /* make the queued for complete command actually */
11181 /* finish successfully, or to indicate that we */
11182 /* don't have this cmd any more and the mid level */
11183 /* code needs to find it. */
11184 cmd_next
= p
->completeq
.head
;
11186 while (cmd_next
!= NULL
)
11188 if (cmd_next
== cmd
)
11190 if (aic7xxx_verbose
& VERBOSE_ABORT_PROCESS
)
11191 printk(INFO_LEAD
"Abort called for command "
11192 "on completeq, completing.\n", p
->host_no
, CTL_OF_CMD(cmd
));
11193 if ( cmd_prev
== NULL
)
11194 p
->completeq
.head
= (Scsi_Cmnd
*)cmd_next
->host_scribble
;
11196 cmd_prev
->host_scribble
= cmd_next
->host_scribble
;
11197 cmd_next
->scsi_done(cmd_next
);
11198 unpause_sequencer(p
, FALSE
);
11200 return(SCSI_ABORT_NOT_RUNNING
); /* It's already back as a successful
11203 cmd_prev
= cmd_next
;
11204 cmd_next
= (Scsi_Cmnd
*)cmd_next
->host_scribble
;
11206 if (aic7xxx_verbose
& VERBOSE_ABORT_MID
)
11207 printk(INFO_LEAD
"Abort called for already completed"
11208 " command.\n", p
->host_no
, CTL_OF_CMD(cmd
));
11209 unpause_sequencer(p
, FALSE
);
11211 return(SCSI_ABORT_NOT_RUNNING
);
11214 /* At this point we know the following:
11215 * the SCB pointer is valid
11216 * the command pointer passed in to us and the scb->cmd pointer match
11217 * this then means that the command we need to abort is the same as the
11218 * command held by the scb pointer and is a valid abort request.
11219 * Now, we just have to figure out what to do from here. Current plan is:
11220 * if we have already been here on this command, escalate to a reset
11221 * if scb is on waiting list or QINFIFO, send it back as aborted, but
11222 * we also need to be aware of the possibility that we could be using
11223 * a faked negotiation command that is holding this command up, if
11224 * so we need to take care of that command instead, which means we
11225 * would then treat this one like it was sitting around disconnected
11227 * if scb is on WAITING_SCB list in sequencer, free scb and send back
11228 * if scb is disconnected and not completed, abort with abort message
11229 * if scb is currently running, then it may be causing the bus to hang
11230 * so we want a return value that indicates a reset would be appropriate
11231 * if the command does not finish shortly
11232 * if scb is already complete but not on completeq, we're screwed because
11233 * this can't happen (except if the command is in the QOUTFIFO, in which
11234 * case we would like it to complete successfully instead of having to
11236 * All other scenarios already dealt with by previous code.
11239 if ( scb
->flags
& (SCB_ABORT
| SCB_RESET
| SCB_QUEUED_ABORT
) )
11241 if (aic7xxx_verbose
& VERBOSE_ABORT_PROCESS
)
11242 printk(INFO_LEAD
"SCB aborted once already, "
11243 "escalating.\n", p
->host_no
, CTL_OF_SCB(scb
));
11244 unpause_sequencer(p
, FALSE
);
11246 return(SCSI_ABORT_SNOOZE
);
11248 if ( (p
->flags
& (AHC_RESET_PENDING
| AHC_ABORT_PENDING
)) ||
11249 (p
->dev_flags
[TARGET_INDEX(scb
->cmd
)] &
11250 BUS_DEVICE_RESET_PENDING
) )
11252 if (aic7xxx_verbose
& VERBOSE_ABORT_PROCESS
)
11253 printk(INFO_LEAD
"Reset/Abort pending for this "
11254 "device, not wasting our time.\n", p
->host_no
, CTL_OF_SCB(scb
));
11255 unpause_sequencer(p
, FALSE
);
11257 return(SCSI_ABORT_PENDING
);
11261 p
->flags
|= AHC_IN_ABORT
;
11262 if (aic7xxx_verbose
& VERBOSE_ABORT
)
11263 printk(INFO_LEAD
"Aborting scb %d, flags 0x%x\n",
11264 p
->host_no
, CTL_OF_SCB(scb
), scb
->hscb
->tag
, scb
->flags
);
11267 * First, let's check to see if the currently running command is our target
11268 * since if it is, the return is fairly easy and quick since we don't want
11269 * to touch the command in case it might complete, but we do want a timeout
11270 * in case it's actually hung, so we really do nothing, but tell the mid
11271 * level code to reset the timeout.
11274 if ( scb
->hscb
->tag
== aic_inb(p
, SCB_TAG
) )
11277 * Check to see if the sequencer is just sitting on this command, or
11278 * if it's actively being run.
11280 result
= aic_inb(p
, LASTPHASE
);
11283 case P_DATAOUT
: /* For any of these cases, we can assume we are */
11284 case P_DATAIN
: /* an active command and act according. For */
11285 case P_COMMAND
: /* anything else we are going to fall on through*/
11286 case P_STATUS
: /* The SCSI_ABORT_SNOOZE will give us two abort */
11287 case P_MESGOUT
: /* chances to finish and then escalate to a */
11288 case P_MESGIN
: /* reset call */
11289 if (aic7xxx_verbose
& VERBOSE_ABORT_PROCESS
)
11290 printk(INFO_LEAD
"SCB is currently active. "
11291 "Waiting on completion.\n", p
->host_no
, CTL_OF_SCB(scb
));
11292 unpause_sequencer(p
, FALSE
);
11293 p
->flags
&= ~AHC_IN_ABORT
;
11294 scb
->flags
|= SCB_RECOVERY_SCB
; /* Note the fact that we've been */
11295 p
->flags
|= AHC_ABORT_PENDING
; /* here so we will know not to */
11296 DRIVER_UNLOCK
/* muck with other SCBs if this */
11297 return(SCSI_ABORT_PENDING
); /* one doesn't complete and clear */
11304 if ((found
== 0) && (scb
->flags
& SCB_WAITINGQ
))
11306 int tindex
= TARGET_INDEX(cmd
);
11307 unsigned short mask
;
11309 mask
= (1 << tindex
);
11311 if (p
->dtr_pending
& mask
)
11313 if (p
->dev_dtr_cmnd
[tindex
]->next
!= cmd
)
11325 * OK..this means the command we are currently getting an abort
11326 * for has an outstanding negotiation command in front of it.
11327 * We don't really have a way to tie back into the negotiation
11328 * commands, so we just send this back as pending, then it
11329 * will get reset in 2 seconds.
11331 unpause_sequencer(p
, TRUE
);
11332 scb
->flags
|= SCB_ABORT
;
11334 return(SCSI_ABORT_PENDING
);
11336 if (aic7xxx_verbose
& VERBOSE_ABORT_PROCESS
)
11337 printk(INFO_LEAD
"SCB found on waiting list and "
11338 "aborted.\n", p
->host_no
, CTL_OF_SCB(scb
));
11339 scbq_remove(&p
->waiting_scbs
, scb
);
11340 scbq_remove(&p
->delayed_scbs
[tindex
], scb
);
11341 p
->dev_active_cmds
[tindex
]++;
11343 scb
->flags
&= ~(SCB_WAITINGQ
| SCB_ACTIVE
);
11344 scb
->flags
|= SCB_ABORT
| SCB_QUEUED_FOR_DONE
;
11349 * We just checked the waiting_q, now for the QINFIFO
11353 if ( ((found
= aic7xxx_search_qinfifo(p
, cmd
->target
,
11355 cmd
->lun
, scb
->hscb
->tag
, SCB_ABORT
| SCB_QUEUED_FOR_DONE
,
11356 FALSE
, NULL
)) != 0) &&
11357 (aic7xxx_verbose
& VERBOSE_ABORT_PROCESS
))
11358 printk(INFO_LEAD
"SCB found in QINFIFO and "
11359 "aborted.\n", p
->host_no
, CTL_OF_SCB(scb
));
11363 * QINFIFO, waitingq, completeq done. Next, check WAITING_SCB list in card
11368 unsigned char scb_next_ptr
;
11369 prev_hscbptr
= SCB_LIST_NULL
;
11370 saved_hscbptr
= aic_inb(p
, SCBPTR
);
11371 next_hscbptr
= aic_inb(p
, WAITING_SCBH
);
11372 while ( next_hscbptr
!= SCB_LIST_NULL
)
11374 aic_outb(p
, next_hscbptr
, SCBPTR
);
11375 if ( scb
->hscb
->tag
== aic_inb(p
, SCB_TAG
) )
11378 if (aic7xxx_verbose
& VERBOSE_ABORT_PROCESS
)
11379 printk(INFO_LEAD
"SCB found on hardware waiting"
11380 " list and aborted.\n", p
->host_no
, CTL_OF_SCB(scb
));
11381 if ( prev_hscbptr
== SCB_LIST_NULL
)
11383 aic_outb(p
, aic_inb(p
, SCB_NEXT
), WAITING_SCBH
);
11384 /* stop the selection since we just
11385 * grabbed the scb out from under the
11388 aic_outb(p
, aic_inb(p
, SCSISEQ
) & ~ENSELO
, SCSISEQ
);
11389 aic_outb(p
, CLRSELTIMEO
, CLRSINT1
);
11393 scb_next_ptr
= aic_inb(p
, SCB_NEXT
);
11394 aic_outb(p
, prev_hscbptr
, SCBPTR
);
11395 aic_outb(p
, scb_next_ptr
, SCB_NEXT
);
11396 aic_outb(p
, next_hscbptr
, SCBPTR
);
11398 aic_outb(p
, SCB_LIST_NULL
, SCB_TAG
);
11399 aic_outb(p
, 0, SCB_CONTROL
);
11400 aic7xxx_add_curscb_to_free_list(p
);
11401 scb
->flags
= SCB_ABORT
| SCB_QUEUED_FOR_DONE
;
11404 prev_hscbptr
= next_hscbptr
;
11405 next_hscbptr
= aic_inb(p
, SCB_NEXT
);
11407 aic_outb(p
, saved_hscbptr
, SCBPTR
);
11411 * Hmmm...completeq, QOUTFIFO, QINFIFO, WAITING_SCBH, waitingq all checked.
11412 * OK...the sequencer's paused, interrupts are off, and we haven't found the
11413 * command anyplace where it could be easily aborted. Time for the hard
11414 * work. We also know the command is valid. This essentially means the
11415 * command is disconnected, or connected but not into any phases yet, which
11416 * we know due to the tests we ran earlier on the current active scb phase.
11417 * At this point we can queue the abort tag and go on with life.
11422 p
->flags
|= AHC_ABORT_PENDING
;
11423 scb
->flags
|= SCB_QUEUED_ABORT
| SCB_ABORT
| SCB_RECOVERY_SCB
;
11424 scb
->hscb
->control
|= MK_MESSAGE
;
11425 result
=aic7xxx_find_scb(p
, scb
);
11426 if ( result
!= SCB_LIST_NULL
)
11428 saved_hscbptr
= aic_inb(p
, SCBPTR
);
11429 aic_outb(p
, result
, SCBPTR
);
11430 tmp_char
= aic_inb(p
, SCB_CONTROL
);
11431 aic_outb(p
, tmp_char
| MK_MESSAGE
, SCB_CONTROL
);
11432 aic_outb(p
, saved_hscbptr
, SCBPTR
);
11434 if (aic7xxx_verbose
& VERBOSE_ABORT_PROCESS
)
11435 printk(INFO_LEAD
"SCB disconnected. Queueing Abort"
11436 " SCB.\n", p
->host_no
, CTL_OF_SCB(scb
));
11437 p
->qinfifo
[p
->qinfifonext
++] = scb
->hscb
->tag
;
11438 if (p
->features
& AHC_QUEUE_REGS
)
11439 aic_outb(p
, p
->qinfifonext
, HNSCB_QOFF
);
11441 aic_outb(p
, p
->qinfifonext
, KERNEL_QINPOS
);
11445 aic7xxx_run_done_queue(p
, TRUE
);
11446 aic7xxx_run_waiting_queues(p
);
11448 p
->flags
&= ~AHC_IN_ABORT
;
11449 unpause_sequencer(p
, FALSE
);
11453 * On the return value. If we found the command and aborted it, then we know
11454 * it's already sent back and there is no reason for a further timeout, so
11455 * we use SCSI_ABORT_SUCCESS. On the queued abort side, we aren't so certain
11456 * there hasn't been a bus hang or something that might keep the abort from
11457 * from completing. Therefore, we use SCSI_ABORT_PENDING. The first time this
11458 * is passed back, the timeout on the command gets extended, the second time
11459 * we pass this back, the mid level SCSI code calls our reset function, which
11460 * would shake loose a hung bus.
11463 return(SCSI_ABORT_SUCCESS
);
11465 return(SCSI_ABORT_PENDING
);
11469 /*+F*************************************************************************
11474 * Resetting the bus always succeeds - is has to, otherwise the
11475 * kernel will panic! Try a surgical technique - sending a BUS
11476 * DEVICE RESET message - on the offending target before pulling
11477 * the SCSI bus reset line.
11478 *-F*************************************************************************/
11480 aic7xxx_reset(Scsi_Cmnd
*cmd
, unsigned int flags
)
11482 struct aic7xxx_scb
*scb
= NULL
;
11483 struct aic7xxx_host
*p
;
11486 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,1,95)
11487 unsigned long cpu_flags
= 0;
11489 #define DEVICE_RESET 0x01
11490 #define BUS_RESET 0x02
11491 #define HOST_RESET 0x04
11493 #define RESET_DELAY 0x10
11495 Scsi_Cmnd
*cmd_prev
, *cmd_next
;
11500 printk(KERN_WARNING
"(scsi?:?:?:?) Reset called with NULL Scsi_Cmnd "
11501 "pointer, failing.\n");
11502 return(SCSI_RESET_SNOOZE
);
11505 p
= (struct aic7xxx_host
*) cmd
->host
->hostdata
;
11506 scb
= (p
->scb_data
->scb_array
[aic7xxx_position(cmd
)]);
11507 tindex
= TARGET_INDEX(cmd
);
11510 * I added a new config option to the driver: "panic_on_abort" that will
11511 * cause the driver to panic and the machine to stop on the first abort
11512 * or reset call into the driver. At that point, it prints out a lot of
11513 * usefull information for me which I can then use to try and debug the
11514 * problem. Simply enable the boot time prompt in order to activate this
11517 if (aic7xxx_panic_on_abort
)
11518 aic7xxx_panic_abort(p
, cmd
);
11522 pause_sequencer(p
);
11523 while ( (aic_inb(p
, INTSTAT
) & INT_PEND
) && !(p
->flags
& AHC_IN_ISR
))
11525 aic7xxx_isr(p
->irq
, p
, (void *)NULL
);
11526 pause_sequencer(p
);
11527 aic7xxx_done_cmds_complete(p
);
11532 if (aic7xxx_verbose
& VERBOSE_RESET_MID
)
11533 printk(INFO_LEAD
"Reset called with bogus Scsi_Cmnd"
11534 "->SCB mapping, improvising.\n", p
->host_no
, CTL_OF_CMD(cmd
));
11535 if ( flags
& SCSI_RESET_SUGGEST_HOST_RESET
)
11537 action
= HOST_RESET
;
11541 action
= BUS_RESET
;
11544 else if (scb
->cmd
!= cmd
)
11546 if (aic7xxx_verbose
& VERBOSE_RESET_MID
)
11547 printk(INFO_LEAD
"Reset called with recycled SCB "
11548 "for cmd.\n", p
->host_no
, CTL_OF_CMD(cmd
));
11550 cmd_next
= p
->completeq
.head
;
11551 while ( cmd_next
!= NULL
)
11553 if (cmd_next
== cmd
)
11555 if (aic7xxx_verbose
& VERBOSE_RESET_RETURN
)
11556 printk(INFO_LEAD
"Reset, found cmd on completeq"
11557 ", completing.\n", p
->host_no
, CTL_OF_CMD(cmd
));
11558 unpause_sequencer(p
, FALSE
);
11560 return(SCSI_RESET_NOT_RUNNING
);
11562 cmd_prev
= cmd_next
;
11563 cmd_next
= (Scsi_Cmnd
*)cmd_next
->host_scribble
;
11565 if ( !(flags
& SCSI_RESET_SYNCHRONOUS
) )
11567 if (aic7xxx_verbose
& VERBOSE_RESET_RETURN
)
11568 printk(INFO_LEAD
"Reset, cmd not found,"
11569 " failing.\n", p
->host_no
, CTL_OF_CMD(cmd
));
11570 unpause_sequencer(p
, FALSE
);
11572 return(SCSI_RESET_NOT_RUNNING
);
11576 if (aic7xxx_verbose
& VERBOSE_RESET_MID
)
11577 printk(INFO_LEAD
"Reset called, no scb, "
11578 "flags 0x%x\n", p
->host_no
, CTL_OF_CMD(cmd
), flags
);
11580 action
= HOST_RESET
;
11585 if (aic7xxx_verbose
& VERBOSE_RESET_MID
)
11586 printk(INFO_LEAD
"Reset called, scb %d, flags "
11587 "0x%x\n", p
->host_no
, CTL_OF_SCB(scb
), scb
->hscb
->tag
, scb
->flags
);
11588 if ( aic7xxx_scb_on_qoutfifo(p
, scb
) )
11590 if(aic7xxx_verbose
& VERBOSE_RESET_RETURN
)
11591 printk(INFO_LEAD
"SCB on qoutfifo, returning.\n", p
->host_no
,
11593 aic7xxx_run_done_queue(p
, TRUE
);
11594 aic7xxx_run_waiting_queues(p
);
11595 unpause_sequencer(p
, FALSE
);
11597 return(SCSI_RESET_NOT_RUNNING
);
11599 if ( flags
& SCSI_RESET_SUGGEST_HOST_RESET
)
11601 action
= HOST_RESET
;
11603 else if ( flags
& SCSI_RESET_SUGGEST_BUS_RESET
)
11605 action
= BUS_RESET
;
11609 action
= DEVICE_RESET
;
11612 if ( (action
& DEVICE_RESET
) &&
11613 (p
->dev_flags
[tindex
] & BUS_DEVICE_RESET_PENDING
) )
11615 if (aic7xxx_verbose
& VERBOSE_RESET_PROCESS
)
11616 printk(INFO_LEAD
"Bus device reset already sent to "
11617 "device, escalating.\n", p
->host_no
, CTL_OF_CMD(cmd
));
11618 action
= BUS_RESET
;
11620 if ( (action
& DEVICE_RESET
) &&
11621 (scb
->flags
& SCB_QUEUED_ABORT
) )
11623 if (aic7xxx_verbose
& VERBOSE_RESET_PROCESS
)
11625 printk(INFO_LEAD
"Have already attempted to reach "
11626 "device with queued\n", p
->host_no
, CTL_OF_CMD(cmd
));
11627 printk(INFO_LEAD
"message, will escalate to bus "
11628 "reset.\n", p
->host_no
, CTL_OF_CMD(cmd
));
11630 action
= BUS_RESET
;
11632 if ( (action
& DEVICE_RESET
) &&
11633 (p
->flags
& (AHC_RESET_PENDING
| AHC_ABORT_PENDING
)) )
11635 if (aic7xxx_verbose
& VERBOSE_RESET_PROCESS
)
11636 printk(INFO_LEAD
"Bus device reset stupid when "
11637 "other action has failed.\n", p
->host_no
, CTL_OF_CMD(cmd
));
11638 action
= BUS_RESET
;
11640 if ( (action
& BUS_RESET
) && !(p
->features
& AHC_TWIN
) )
11642 action
= HOST_RESET
;
11644 if ( (p
->dev_flags
[tindex
] & DEVICE_RESET_DELAY
) &&
11645 !(action
& (HOST_RESET
| BUS_RESET
)))
11647 if (aic7xxx_verbose
& VERBOSE_RESET_PROCESS
)
11649 printk(INFO_LEAD
"Reset called too soon after last "
11650 "reset without requesting\n", p
->host_no
, CTL_OF_CMD(cmd
));
11651 printk(INFO_LEAD
"bus or host reset, escalating.\n", p
->host_no
,
11654 action
= BUS_RESET
;
11656 if ( (p
->flags
& AHC_RESET_DELAY
) &&
11657 (action
& (HOST_RESET
| BUS_RESET
)) )
11659 if (aic7xxx_verbose
& VERBOSE_RESET_PROCESS
)
11660 printk(INFO_LEAD
"Reset called too soon after "
11661 "last bus reset, delaying.\n", p
->host_no
, CTL_OF_CMD(cmd
));
11662 action
= RESET_DELAY
;
11665 * By this point, we want to already know what we are going to do and
11666 * only have the following code implement our course of action.
11671 unpause_sequencer(p
, FALSE
);
11673 return(SCSI_RESET_PENDING
);
11676 unpause_sequencer(p
, FALSE
);
11678 return(SCSI_RESET_ERROR
);
11681 p
->flags
|= AHC_IN_RESET
;
11682 result
= aic7xxx_bus_device_reset(p
, cmd
);
11683 aic7xxx_run_done_queue(p
, TRUE
);
11684 /* We can't rely on run_waiting_queues to unpause the sequencer for
11685 * PCI based controllers since we use AAP */
11686 aic7xxx_run_waiting_queues(p
);
11687 unpause_sequencer(p
, FALSE
);
11688 p
->flags
&= ~AHC_IN_RESET
;
11695 p
->flags
|= AHC_IN_RESET
| AHC_RESET_DELAY
;
11696 p
->dev_expires
[p
->scsi_id
] = jiffies
+ (3 * HZ
);
11697 p
->dev_timer_active
|= (0x01 << p
->scsi_id
);
11698 if ( !(p
->dev_timer_active
& (0x01 << MAX_TARGETS
)) ||
11699 time_after_eq(p
->dev_timer
.expires
, p
->dev_expires
[p
->scsi_id
]) )
11701 del_timer(&p
->dev_timer
);
11702 p
->dev_timer
.expires
= p
->dev_expires
[p
->scsi_id
];
11703 add_timer(&p
->dev_timer
);
11704 p
->dev_timer_active
|= (0x01 << MAX_TARGETS
);
11706 aic7xxx_reset_channel(p
, cmd
->channel
, TRUE
);
11707 if ( (p
->features
& AHC_TWIN
) && (action
& HOST_RESET
) )
11709 aic7xxx_reset_channel(p
, cmd
->channel
^ 0x01, TRUE
);
11710 restart_sequencer(p
);
11712 if (action
!= HOST_RESET
)
11713 result
= SCSI_RESET_SUCCESS
| SCSI_RESET_BUS_RESET
;
11716 result
= SCSI_RESET_SUCCESS
| SCSI_RESET_HOST_RESET
;
11717 aic_outb(p
, aic_inb(p
, SIMODE1
) & ~(ENREQINIT
|ENBUSFREE
),
11719 aic7xxx_clear_intstat(p
);
11720 p
->flags
&= ~AHC_HANDLING_REQINITS
;
11721 p
->msg_type
= MSG_TYPE_NONE
;
11725 aic7xxx_run_done_queue(p
, TRUE
);
11727 * If this a SCSI_RESET_SYNCHRONOUS then the command we were given is
11728 * in need of being re-started, so send it on through to aic7xxx_queue
11729 * and let it set until the delay is over. This keeps it from dying
11730 * entirely and avoids getting a bogus dead command back through the
11731 * mid-level code due to too many retries.
11733 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,1,132)
11734 if ( flags
& SCSI_RESET_SYNCHRONOUS
)
11736 cmd
->result
= DID_BUS_BUSY
<< 16;
11740 p
->flags
&= ~AHC_IN_RESET
;
11742 * We can't rely on run_waiting_queues to unpause the sequencer for
11743 * PCI based controllers since we use AAP. NOTE: this also sets
11744 * the timer for the one command we might have queued in the case
11745 * of a synch reset.
11747 aic7xxx_run_waiting_queues(p
);
11748 unpause_sequencer(p
, FALSE
);
11755 /*+F*************************************************************************
11757 * aic7xxx_biosparam
11760 * Return the disk geometry for the given SCSI device.
11761 *-F*************************************************************************/
11763 aic7xxx_biosparam(Disk
*disk
, kdev_t dev
, int geom
[])
11765 int heads
, sectors
, cylinders
, ret
;
11766 struct aic7xxx_host
*p
;
11767 struct buffer_head
*bh
;
11769 p
= (struct aic7xxx_host
*) disk
->device
->host
->hostdata
;
11770 bh
= bread(MKDEV(MAJOR(dev
), MINOR(dev
)&~0xf), 0, 1024);
11774 ret
= scsi_partsize(bh
, disk
->capacity
, &geom
[2], &geom
[0], &geom
[1]);
11782 cylinders
= disk
->capacity
/ (heads
* sectors
);
11784 if ((p
->flags
& AHC_EXTEND_TRANS_A
) && (cylinders
> 1024))
11788 cylinders
= disk
->capacity
/ (heads
* sectors
);
11793 geom
[2] = cylinders
;
11798 /*+F*************************************************************************
11803 * Free the passed in Scsi_Host memory structures prior to unloading the
11805 *-F*************************************************************************/
11807 aic7xxx_release(struct Scsi_Host
*host
)
11809 struct aic7xxx_host
*p
= (struct aic7xxx_host
*) host
->hostdata
;
11810 struct aic7xxx_host
*next
, *prev
;
11813 free_irq(p
->irq
, p
);
11814 release_region(p
->base
, MAXREG
- MINREG
);
11818 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,1,0)
11819 vfree((void *) (((unsigned long) p
->maddr
) & PAGE_MASK
));
11821 iounmap((void *) (((unsigned long) p
->maddr
) & PAGE_MASK
));
11824 #endif /* MMAPIO */
11826 next
= first_aic7xxx
;
11827 while(next
!= NULL
)
11832 first_aic7xxx
= next
->next
;
11834 prev
->next
= next
->next
;
11846 /*+F*************************************************************************
11848 * aic7xxx_print_card
11851 * Print out all of the control registers on the card
11853 * NOTE: This function is not yet safe for use on the VLB and EISA
11854 * controllers, so it isn't used on those controllers at all.
11855 *-F*************************************************************************/
11857 aic7xxx_print_card(struct aic7xxx_host
*p
)
11860 static struct register_ranges
{
11864 { 0, {0,} }, /* none */
11865 {10, {0x00, 0x05, 0x08, 0x11, 0x18, 0x19, 0x1f, 0x1f, 0x60, 0x60, /*7771*/
11866 0x62, 0x66, 0x80, 0x8e, 0x90, 0x95, 0x97, 0x97, 0x9b, 0x9f} },
11867 { 9, {0x00, 0x05, 0x08, 0x11, 0x18, 0x1f, 0x60, 0x60, 0x62, 0x66, /*7850*/
11868 0x80, 0x8e, 0x90, 0x95, 0x97, 0x97, 0x9a, 0x9f} },
11869 { 9, {0x00, 0x05, 0x08, 0x11, 0x18, 0x1f, 0x60, 0x60, 0x62, 0x66, /*7860*/
11870 0x80, 0x8e, 0x90, 0x95, 0x97, 0x97, 0x9a, 0x9f} },
11871 {10, {0x00, 0x05, 0x08, 0x11, 0x18, 0x19, 0x1c, 0x1f, 0x60, 0x60, /*7870*/
11872 0x62, 0x66, 0x80, 0x8e, 0x90, 0x95, 0x97, 0x97, 0x9a, 0x9f} },
11873 {10, {0x00, 0x05, 0x08, 0x11, 0x18, 0x1a, 0x1c, 0x1f, 0x60, 0x60, /*7880*/
11874 0x62, 0x66, 0x80, 0x8e, 0x90, 0x95, 0x97, 0x97, 0x9a, 0x9f} },
11875 {16, {0x00, 0x05, 0x08, 0x11, 0x18, 0x1f, 0x60, 0x60, 0x62, 0x66, /*7890*/
11876 0x84, 0x8e, 0x90, 0x95, 0x97, 0x97, 0x9a, 0x9a, 0x9f, 0x9f,
11877 0xe0, 0xf1, 0xf4, 0xf4, 0xf6, 0xf6, 0xf8, 0xf8, 0xfa, 0xfc,
11879 {12, {0x00, 0x05, 0x08, 0x11, 0x18, 0x19, 0x1b, 0x1f, 0x60, 0x60, /*7895*/
11880 0x62, 0x66, 0x80, 0x8e, 0x90, 0x95, 0x97, 0x97, 0x9a, 0x9a,
11881 0x9f, 0x9f, 0xe0, 0xf1} },
11882 {16, {0x00, 0x05, 0x08, 0x11, 0x18, 0x1f, 0x60, 0x60, 0x62, 0x66, /*7896*/
11883 0x84, 0x8e, 0x90, 0x95, 0x97, 0x97, 0x9a, 0x9a, 0x9f, 0x9f,
11884 0xe0, 0xf1, 0xf4, 0xf4, 0xf6, 0xf6, 0xf8, 0xf8, 0xfa, 0xfc,
11886 {12, {0x00, 0x05, 0x08, 0x11, 0x18, 0x1f, 0x60, 0x60, 0x62, 0x66, /*7892*/
11887 0x84, 0x8e, 0x90, 0x95, 0x97, 0x97, 0x9a, 0x9a, 0x9c, 0x9f,
11888 0xe0, 0xf1, 0xf4, 0xfc} },
11889 {12, {0x00, 0x05, 0x08, 0x11, 0x18, 0x1f, 0x60, 0x60, 0x62, 0x66, /*7899*/
11890 0x84, 0x8e, 0x90, 0x95, 0x97, 0x97, 0x9a, 0x9a, 0x9c, 0x9f,
11891 0xe0, 0xf1, 0xf4, 0xfc} },
11894 static struct register_ranges cards_ns
[] = {
11895 { 0, {0,} }, /* none */
11896 { 0, {0,} }, /* 7771 */
11897 { 7, {0x04, 0x08, 0x0c, 0x0e, 0x10, 0x17, 0x28, 0x2b, 0x30, 0x33,
11898 0x3c, 0x41, 0x43, 0x47} },
11899 { 7, {0x04, 0x08, 0x0c, 0x0e, 0x10, 0x17, 0x28, 0x2b, 0x30, 0x33,
11900 0x3c, 0x41, 0x43, 0x47} },
11901 { 5, {0x04, 0x08, 0x0c, 0x0e, 0x10, 0x17, 0x30, 0x33, 0x3c, 0x41} },
11902 { 5, {0x04, 0x08, 0x0c, 0x0e, 0x10, 0x17, 0x30, 0x34, 0x3c, 0x47} },
11903 { 5, {0x04, 0x08, 0x0c, 0x1b, 0x30, 0x34, 0x3c, 0x43, 0xdc, 0xe3} },
11904 { 6, {0x04, 0x08, 0x0c, 0x0e, 0x10, 0x17, 0x30, 0x34, 0x3c, 0x47,
11906 { 6, {0x04, 0x08, 0x0c, 0x1b, 0x30, 0x34, 0x3c, 0x43, 0xdc, 0xe3,
11908 { 6, {0x04, 0x08, 0x0c, 0x1b, 0x30, 0x34, 0x3c, 0x43, 0xdc, 0xe3,
11910 { 6, {0x04, 0x08, 0x0c, 0x1b, 0x30, 0x34, 0x3c, 0x43, 0xdc, 0xe3,
11914 chip
= p
->chip
& AHC_CHIPID_MASK
;
11916 * Let's run through the PCI space first....
11919 board_names
[p
->board_name_index
]);
11920 switch(p
->chip
& ~AHC_CHIPID_MASK
)
11923 printk("VLB Slot %d.\n", p
->pci_device_fn
);
11926 printk("EISA Slot %d.\n", p
->pci_device_fn
);
11930 printk("PCI %d/%d.\n", PCI_SLOT(p
->pci_device_fn
),
11931 PCI_FUNC(p
->pci_device_fn
));
11937 unsigned char temp
;
11939 printk("PCI Dump:\n");
11941 for(i
=0; i
<cards_ns
[chip
].num_ranges
; i
++)
11943 for(j
= cards_ns
[chip
].range_val
[ i
* 2 ];
11944 j
<= cards_ns
[chip
].range_val
[ i
* 2 + 1 ] ;
11947 #if LINUX_VERSION_CODE > KERNEL_VERSION(2,1,92)
11948 pci_read_config_byte(p
->pdev
, j
, &temp
);
11950 pcibios_read_config_byte(p
->pci_bus
, p
->pci_device_fn
, j
, &temp
);
11952 printk("%02x:%02x ", j
, temp
);
11963 #endif /* CONFIG_PCI */
11966 * Now the registers on the card....
11968 printk("Card Dump:\n");
11970 for(i
=0; i
<cards_ds
[chip
].num_ranges
; i
++)
11972 for(j
= cards_ds
[chip
].range_val
[ i
* 2 ];
11973 j
<= cards_ds
[chip
].range_val
[ i
* 2 + 1 ] ;
11976 printk("%02x:%02x ", j
, aic_inb(p
, j
));
11986 if (p
->flags
& AHC_SEEPROM_FOUND
)
11988 unsigned short *sc1
;
11989 sc1
= (unsigned short *)&p
->sc
;
11991 printk("SEEPROM dump.\n");
11992 for(i
=1; i
<=32; i
++)
11994 printk("0x%04x", sc1
[i
-1]);
11995 if ( (i
% 8) == 0 )
12003 * If this was an Ultra2 controller, then we just hosed the card in terms
12004 * of the QUEUE REGS. This function is only called at init time or by
12005 * the panic_abort function, so it's safe to assume a generic init time
12009 if(p
->features
& AHC_QUEUE_REGS
)
12011 aic_outb(p
, 0, SDSCB_QOFF
);
12012 aic_outb(p
, 0, SNSCB_QOFF
);
12013 aic_outb(p
, 0, HNSCB_QOFF
);
12018 /*+F*************************************************************************
12020 * aic7xxx_print_scratch_ram
12023 * Print out the scratch RAM values on the card.
12024 *-F*************************************************************************/
12026 aic7xxx_print_scratch_ram(struct aic7xxx_host
*p
)
12031 printk("Scratch RAM:\n");
12032 for(i
= SRAM_BASE
; i
< SEQCTL
; i
++)
12034 printk("%02x:%02x ", i
, aic_inb(p
, i
));
12041 if (p
->features
& AHC_MORE_SRAM
)
12043 for(i
= TARG_OFFSET
; i
< 0x80; i
++)
12045 printk("%02x:%02x ", i
, aic_inb(p
, i
));
12057 #include "aic7xxx_proc.c"
12060 /* Eventually this will go into an include file, but this will be later */
12061 Scsi_Host_Template driver_template
= AIC7XXX
;
12063 #include "scsi_module.c"
12067 * Overrides for Emacs so that we almost follow Linus's tabbing style.
12068 * Emacs will notice this stuff at the end of the file and automatically
12069 * adjust the settings for this buffer only. This must remain at the end
12071 * ---------------------------------------------------------------------------
12073 * c-indent-level: 2
12074 * c-brace-imaginary-offset: 0
12075 * c-brace-offset: -2
12076 * c-argdecl-indent: 2
12077 * c-label-offset: -2
12078 * c-continued-statement-offset: 2
12079 * c-continued-brace-offset: 0
12080 * indent-tabs-mode: nil