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>
245 #include <linux/init.h>
246 #include <linux/spinlock.h>
247 #include <linux/smp.h>
253 #include "aic7xxx/sequencer.h"
254 #include "aic7xxx/scsi_message.h"
255 #include "aic7xxx_reg.h"
256 #include <scsi/scsicam.h>
258 #include <linux/stat.h>
259 #include <linux/malloc.h> /* for kmalloc() */
261 #include <linux/config.h> /* for CONFIG_PCI */
264 * To generate the correct addresses for the controller to issue
265 * on the bus. Originally added for DEC Alpha support.
267 #define VIRT_TO_BUS(a) (unsigned int)virt_to_bus((void *)(a))
269 #define AIC7XXX_C_VERSION "5.2.1"
271 #define NUMBER(arr) (sizeof(arr) / sizeof(arr[0]))
272 #define MIN(a,b) (((a) < (b)) ? (a) : (b))
273 #define MAX(a,b) (((a) > (b)) ? (a) : (b))
274 #define ALL_TARGETS -1
275 #define ALL_CHANNELS -1
277 #define MAX_TARGETS 16
286 #if defined(__powerpc__) || defined(__i386__)
290 # if LINUX_VERSION_CODE < KERNEL_VERSION(2,1,95)
291 # define cpuid smp_processor_id()
292 # define DRIVER_LOCK_INIT \
293 spin_lock_init(&p->spin_lock);
294 # define DRIVER_LOCK \
295 if(!p->cpu_lock_count[cpuid]) { \
296 spin_lock_irqsave(&p->spin_lock, cpu_flags); \
297 p->cpu_lock_count[cpuid]++; \
299 p->cpu_lock_count[cpuid]++; \
301 # define DRIVER_UNLOCK \
302 if(--p->cpu_lock_count[cpuid] == 0) \
303 spin_unlock_irqrestore(&p->spin_lock, cpu_flags);
305 # define DRIVER_LOCK_INIT
307 # define DRIVER_UNLOCK
311 * You can try raising me if tagged queueing is enabled, or lowering
312 * me if you only have 4 SCBs.
314 #ifdef CONFIG_AIC7XXX_CMDS_PER_DEVICE
315 #define AIC7XXX_CMDS_PER_DEVICE CONFIG_AIC7XXX_CMDS_PER_DEVICE
317 #define AIC7XXX_CMDS_PER_DEVICE 8
321 * Control collection of SCSI transfer statistics for the /proc filesystem.
323 * NOTE: Do NOT enable this when running on kernels version 1.2.x and below.
324 * NOTE: This does affect performance since it has to maintain statistics.
326 #ifdef CONFIG_AIC7XXX_PROC_STATS
327 #define AIC7XXX_PROC_STATS
331 * *** Determining commands per LUN ***
333 * When AIC7XXX_CMDS_PER_DEVICE is not defined, the driver will use its
334 * own algorithm to determine the commands/LUN. If SCB paging is
335 * enabled, which is always now, the default is 8 commands per lun
336 * that indicates it supports tagged queueing. All non-tagged devices
337 * use an internal queue depth of 3, with no more than one of those
338 * three commands active at one time.
343 unsigned char tag_commands
[16]; /* Allow for wide/twin adapters. */
344 } adapter_tag_info_t
;
347 * Make a define that will tell the driver not to use tagged queueing
350 #ifdef CONFIG_AIC7XXX_TCQ_ON_BY_DEFAULT
351 #define DEFAULT_TAG_COMMANDS {0, 0, 0, 0, 0, 0, 0, 0,\
352 0, 0, 0, 0, 0, 0, 0, 0}
354 #define DEFAULT_TAG_COMMANDS {255, 255, 255, 255, 255, 255, 255, 255,\
355 255, 255, 255, 255, 255, 255, 255, 255}
359 * Modify this as you see fit for your system. By setting tag_commands
360 * to 0, the driver will use it's own algorithm for determining the
361 * number of commands to use (see above). When 255, the driver will
362 * not enable tagged queueing for that particular device. When positive
363 * (> 0) and (< 255) the values in the array are used for the queue_depth.
364 * Note that the maximum value for an entry is 254, but you're insane if
365 * you try to use that many commands on one device.
367 * In this example, the first line will disable tagged queueing for all
368 * the devices on the first probed aic7xxx adapter.
370 * The second line enables tagged queueing with 4 commands/LUN for IDs
371 * (1, 2-11, 13-15), disables tagged queueing for ID 12, and tells the
372 * driver to use its own algorithm for ID 1.
374 * The third line is the same as the first line.
376 * The fourth line disables tagged queueing for devices 0 and 3. It
377 * enables tagged queueing for the other IDs, with 16 commands/LUN
378 * for IDs 1 and 4, 127 commands/LUN for ID 8, and 4 commands/LUN for
379 * IDs 2, 5-7, and 9-15.
383 * NOTE: The below structure is for reference only, the actual structure
384 * to modify in order to change things is found after this fake one.
386 adapter_tag_info_t aic7xxx_tag_info[] =
388 {DEFAULT_TAG_COMMANDS},
389 {{4, 0, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 255, 4, 4, 4}},
390 {DEFAULT_TAG_COMMANDS},
391 {{255, 16, 4, 255, 16, 4, 4, 4, 127, 4, 4, 4, 4, 4, 4, 4}}
395 static adapter_tag_info_t aic7xxx_tag_info
[] =
397 {DEFAULT_TAG_COMMANDS
},
398 {DEFAULT_TAG_COMMANDS
},
399 {DEFAULT_TAG_COMMANDS
},
400 {DEFAULT_TAG_COMMANDS
},
401 {DEFAULT_TAG_COMMANDS
},
402 {DEFAULT_TAG_COMMANDS
},
403 {DEFAULT_TAG_COMMANDS
},
404 {DEFAULT_TAG_COMMANDS
},
405 {DEFAULT_TAG_COMMANDS
},
406 {DEFAULT_TAG_COMMANDS
},
407 {DEFAULT_TAG_COMMANDS
},
408 {DEFAULT_TAG_COMMANDS
},
409 {DEFAULT_TAG_COMMANDS
},
410 {DEFAULT_TAG_COMMANDS
},
411 {DEFAULT_TAG_COMMANDS
},
412 {DEFAULT_TAG_COMMANDS
}
417 * Define an array of board names that can be indexed by aha_type.
418 * Don't forget to change this when changing the types!
420 static const char *board_names
[] = {
421 "AIC-7xxx Unknown", /* AIC_NONE */
422 "Adaptec AIC-7810 Hardware RAID Controller", /* AIC_7810 */
423 "Adaptec AIC-7770 SCSI host adapter", /* AIC_7770 */
424 "Adaptec AHA-274X SCSI host adapter", /* AIC_7771 */
425 "Adaptec AHA-284X SCSI host adapter", /* AIC_284x */
426 "Adaptec AIC-7850 SCSI host adapter", /* AIC_7850 */
427 "Adaptec AIC-7855 SCSI host adapter", /* AIC_7855 */
428 "Adaptec AIC-7860 Ultra SCSI host adapter", /* AIC_7860 */
429 "Adaptec AHA-2940A Ultra SCSI host adapter", /* AIC_7861 */
430 "Adaptec AIC-7870 SCSI host adapter", /* AIC_7870 */
431 "Adaptec AHA-294X SCSI host adapter", /* AIC_7871 */
432 "Adaptec AHA-394X SCSI host adapter", /* AIC_7872 */
433 "Adaptec AHA-398X SCSI host adapter", /* AIC_7873 */
434 "Adaptec AHA-2944 SCSI host adapter", /* AIC_7874 */
435 "Adaptec AIC-7880 Ultra SCSI host adapter", /* AIC_7880 */
436 "Adaptec AHA-294X Ultra SCSI host adapter", /* AIC_7881 */
437 "Adaptec AHA-394X Ultra SCSI host adapter", /* AIC_7882 */
438 "Adaptec AHA-398X Ultra SCSI host adapter", /* AIC_7883 */
439 "Adaptec AHA-2944 Ultra SCSI host adapter", /* AIC_7884 */
440 "Adaptec AHA-2940UW Pro Ultra SCSI host adapter", /* AIC_7887 */
441 "Adaptec AIC-7895 Ultra SCSI host adapter", /* AIC_7895 */
442 "Adaptec AIC-7890/1 Ultra2 SCSI host adapter", /* AIC_7890 */
443 "Adaptec AHA-293X Ultra2 SCSI host adapter", /* AIC_7890 */
444 "Adaptec AHA-294X Ultra2 SCSI host adapter", /* AIC_7890 */
445 "Adaptec AIC-7896/7 Ultra2 SCSI host adapter", /* AIC_7896 */
446 "Adaptec AHA-394X Ultra2 SCSI host adapter", /* AIC_7897 */
447 "Adaptec AHA-395X Ultra2 SCSI host adapter", /* AIC_7897 */
448 "Adaptec PCMCIA SCSI controller", /* card bus stuff */
449 "Adaptec AIC-7892 Ultra 160/m SCSI host adapter", /* AIC_7892 */
450 "Adaptec AIC-7899 Ultra 160/m SCSI host adapter", /* AIC_7899 */
454 * There should be a specific return value for this in scsi.h, but
455 * it seems that most drivers ignore it.
457 #define DID_UNDERFLOW DID_ERROR
460 * What we want to do is have the higher level scsi driver requeue
461 * the command to us. There is no specific driver status for this
462 * condition, but the higher level scsi driver will requeue the
463 * command on a DID_BUS_BUSY error.
465 * Upon further inspection and testing, it seems that DID_BUS_BUSY
466 * will *always* retry the command. We can get into an infinite loop
467 * if this happens when we really want some sort of counter that
468 * will automatically abort/reset the command after so many retries.
469 * Using DID_ERROR will do just that. (Made by a suggestion by
470 * Doug Ledford 8/1/96)
472 #define DID_RETRY_COMMAND DID_ERROR
475 #define SCSI_RESET 0x040
482 #define SLOTBASE(x) ((x) << 12)
483 #define BASE_TO_SLOT(x) ((x) >> 12)
486 * Standard EISA Host ID regs (Offset from slot base)
488 #define AHC_HID0 0x80 /* 0,1: msb of ID2, 2-7: ID1 */
489 #define AHC_HID1 0x81 /* 0-4: ID3, 5-7: LSB ID2 */
490 #define AHC_HID2 0x82 /* product */
491 #define AHC_HID3 0x83 /* firmware revision */
494 * AIC-7770 I/O range to reserve for a card
499 #define INTDEF 0x5C /* Interrupt Definition Register */
502 * AIC-78X0 PCI registers
504 #define CLASS_PROGIF_REVID 0x08
505 #define DEVREVID 0x000000FFul
506 #define PROGINFC 0x0000FF00ul
507 #define SUBCLASS 0x00FF0000ul
508 #define BASECLASS 0xFF000000ul
510 #define CSIZE_LATTIME 0x0C
511 #define CACHESIZE 0x0000003Ful /* only 5 bits */
512 #define LATTIME 0x0000FF00ul
514 #define DEVCONFIG 0x40
515 #define SCBSIZE32 0x00010000ul /* aic789X only */
516 #define MPORTMODE 0x00000400ul /* aic7870 only */
517 #define RAMPSM 0x00000200ul /* aic7870 only */
518 #define RAMPSM_ULTRA2 0x00000004
519 #define VOLSENSE 0x00000100ul
520 #define SCBRAMSEL 0x00000080ul
521 #define SCBRAMSEL_ULTRA2 0x00000008
522 #define MRDCEN 0x00000040ul
523 #define EXTSCBTIME 0x00000020ul /* aic7870 only */
524 #define EXTSCBPEN 0x00000010ul /* aic7870 only */
525 #define BERREN 0x00000008ul
526 #define DACEN 0x00000004ul
527 #define STPWLEVEL 0x00000002ul
528 #define DIFACTNEGEN 0x00000001ul /* aic7870 only */
530 #define SCAMCTL 0x1a /* Ultra2 only */
531 #define CCSCBBADDR 0xf0 /* aic7895/6/7 */
534 * Define the different types of SEEPROMs on aic7xxx adapters
535 * and make it also represent the address size used in accessing
536 * its registers. The 93C46 chips have 1024 bits organized into
537 * 64 16-bit words, while the 93C56 chips have 2048 bits organized
538 * into 128 16-bit words. The C46 chips use 6 bits to address
539 * each word, while the C56 and C66 (4096 bits) use 8 bits to
542 typedef enum {C46
= 6, C56_66
= 8} seeprom_chip_type
;
546 * Define the format of the SEEPROM registers (16 bits).
549 struct seeprom_config
{
552 * SCSI ID Configuration Flags
554 #define CFXFER 0x0007 /* synchronous transfer rate */
555 #define CFSYNCH 0x0008 /* enable synchronous transfer */
556 #define CFDISC 0x0010 /* enable disconnection */
557 #define CFWIDEB 0x0020 /* wide bus device (wide card) */
558 #define CFSYNCHISULTRA 0x0040 /* CFSYNC is an ultra offset */
559 #define CFNEWULTRAFORMAT 0x0080 /* Use the Ultra2 SEEPROM format */
560 #define CFSTART 0x0100 /* send start unit SCSI command */
561 #define CFINCBIOS 0x0200 /* include in BIOS scan */
562 #define CFRNFOUND 0x0400 /* report even if not found */
563 #define CFMULTILUN 0x0800 /* probe mult luns in BIOS scan */
564 #define CFWBCACHEYES 0x4000 /* Enable W-Behind Cache on drive */
565 #define CFWBCACHENC 0xc000 /* Don't change W-Behind Cache */
567 unsigned short device_flags
[16]; /* words 0-15 */
572 #define CFSUPREM 0x0001 /* support all removable drives */
573 #define CFSUPREMB 0x0002 /* support removable drives for boot only */
574 #define CFBIOSEN 0x0004 /* BIOS enabled */
576 #define CFSM2DRV 0x0010 /* support more than two drives */
577 #define CF284XEXTEND 0x0020 /* extended translation (284x cards) */
579 #define CFEXTEND 0x0080 /* extended translation enabled */
581 unsigned short bios_control
; /* word 16 */
584 * Host Adapter Control Bits
586 #define CFAUTOTERM 0x0001 /* Perform Auto termination */
587 #define CFULTRAEN 0x0002 /* Ultra SCSI speed enable (Ultra cards) */
588 #define CF284XSELTO 0x0003 /* Selection timeout (284x cards) */
589 #define CF284XFIFO 0x000C /* FIFO Threshold (284x cards) */
590 #define CFSTERM 0x0004 /* SCSI low byte termination */
591 #define CFWSTERM 0x0008 /* SCSI high byte termination (wide card) */
592 #define CFSPARITY 0x0010 /* SCSI parity */
593 #define CF284XSTERM 0x0020 /* SCSI low byte termination (284x cards) */
594 #define CFRESETB 0x0040 /* reset SCSI bus at boot */
595 #define CFBPRIMARY 0x0100 /* Channel B primary on 7895 chipsets */
596 #define CFSEAUTOTERM 0x0400 /* aic7890 Perform SE Auto Term */
597 #define CFLVDSTERM 0x0800 /* aic7890 LVD Termination */
599 unsigned short adapter_control
; /* word 17 */
602 * Bus Release, Host Adapter ID
604 #define CFSCSIID 0x000F /* host adapter SCSI ID */
606 #define CFBRTIME 0xFF00 /* bus release time */
607 unsigned short brtime_id
; /* word 18 */
612 #define CFMAXTARG 0x00FF /* maximum targets */
614 unsigned short max_targets
; /* word 19 */
616 unsigned short res_1
[11]; /* words 20-30 */
617 unsigned short checksum
; /* word 31 */
620 #define SELBUS_MASK 0x0a
621 #define SELNARROW 0x00
623 #define SINGLE_BUS 0x00
625 #define SCB_TARGET(scb) \
626 (((scb)->hscb->target_channel_lun & TID) >> 4)
627 #define SCB_LUN(scb) \
628 ((scb)->hscb->target_channel_lun & LID)
629 #define SCB_IS_SCSIBUS_B(scb) \
630 (((scb)->hscb->target_channel_lun & SELBUSB) != 0)
633 * If an error occurs during a data transfer phase, run the command
634 * to completion - it's easier that way - making a note of the error
635 * condition in this location. This then will modify a DID_OK status
636 * into an appropriate error for the higher-level SCSI code.
638 #define aic7xxx_error(cmd) ((cmd)->SCp.Status)
641 * Keep track of the targets returned status.
643 #define aic7xxx_status(cmd) ((cmd)->SCp.sent_command)
646 * The position of the SCSI commands scb within the scb array.
648 #define aic7xxx_position(cmd) ((cmd)->SCp.have_data_in)
651 * The stored DMA mapping for single-buffer data transfers.
653 #define aic7xxx_mapping(cmd) ((cmd)->SCp.phase)
656 * So we can keep track of our host structs
658 static struct aic7xxx_host
*first_aic7xxx
= NULL
;
661 * As of Linux 2.1, the mid-level SCSI code uses virtual addresses
662 * in the scatter-gather lists. We need to convert the virtual
663 * addresses to physical addresses.
665 struct hw_scatterlist
{
666 unsigned int address
;
671 * Maximum number of SG segments these cards can support.
673 #define AIC7XXX_MAX_SG 128
676 * The maximum number of SCBs we could have for ANY type
677 * of card. DON'T FORGET TO CHANGE THE SCB MASK IN THE
678 * SEQUENCER CODE IF THIS IS MODIFIED!
680 #define AIC7XXX_MAXSCB 255
683 struct aic7xxx_hwscb
{
684 /* ------------ Begin hardware supported fields ---------------- */
685 /* 0*/ unsigned char control
;
686 /* 1*/ unsigned char target_channel_lun
; /* 4/1/3 bits */
687 /* 2*/ unsigned char target_status
;
688 /* 3*/ unsigned char SG_segment_count
;
689 /* 4*/ unsigned int SG_list_pointer
;
690 /* 8*/ unsigned char residual_SG_segment_count
;
691 /* 9*/ unsigned char residual_data_count
[3];
692 /*12*/ unsigned int data_pointer
;
693 /*16*/ unsigned int data_count
;
694 /*20*/ unsigned int SCSI_cmd_pointer
;
695 /*24*/ unsigned char SCSI_cmd_length
;
696 /*25*/ unsigned char tag
; /* Index into our kernel SCB array.
697 * Also used as the tag for tagged I/O
699 #define SCB_PIO_TRANSFER_SIZE 26 /* amount we need to upload/download
700 * via PIO to initialize a transaction.
702 /*26*/ unsigned char next
; /* Used to thread SCBs awaiting selection
703 * or disconnected down in the sequencer.
705 /*27*/ unsigned char prev
;
706 /*28*/ unsigned int pad
; /*
707 * Unused by the kernel, but we require
708 * the padding so that the array of
709 * hardware SCBs is alligned on 32 byte
710 * boundaries so the sequencer can index
716 SCB_WAITINGQ
= 0x0002,
720 SCB_DEVICE_RESET
= 0x0020,
722 SCB_RECOVERY_SCB
= 0x0080,
723 SCB_MSGOUT_PPR
= 0x0100,
724 SCB_MSGOUT_SENT
= 0x0200,
725 SCB_MSGOUT_SDTR
= 0x0400,
726 SCB_MSGOUT_WDTR
= 0x0800,
727 SCB_MSGOUT_BITS
= SCB_MSGOUT_PPR
|
731 SCB_QUEUED_ABORT
= 0x1000,
732 SCB_QUEUED_FOR_DONE
= 0x2000,
733 SCB_WAS_BUSY
= 0x4000
737 AHC_FNONE
= 0x00000000,
738 AHC_PAGESCBS
= 0x00000001,
739 AHC_CHANNEL_B_PRIMARY
= 0x00000002,
740 AHC_USEDEFAULTS
= 0x00000004,
741 AHC_INDIRECT_PAGING
= 0x00000008,
742 AHC_CHNLB
= 0x00000020,
743 AHC_CHNLC
= 0x00000040,
744 AHC_EXTEND_TRANS_A
= 0x00000100,
745 AHC_EXTEND_TRANS_B
= 0x00000200,
746 AHC_TERM_ENB_A
= 0x00000400,
747 AHC_TERM_ENB_SE_LOW
= 0x00000400,
748 AHC_TERM_ENB_B
= 0x00000800,
749 AHC_TERM_ENB_SE_HIGH
= 0x00000800,
750 AHC_HANDLING_REQINITS
= 0x00001000,
751 AHC_TARGETMODE
= 0x00002000,
752 AHC_NEWEEPROM_FMT
= 0x00004000,
754 * Here ends the FreeBSD defined flags and here begins the linux defined
755 * flags. NOTE: I did not preserve the old flag name during this change
756 * specifically to force me to evaluate what flags were being used properly
757 * and what flags weren't. This way, I could clean up the flag usage on
758 * a use by use basis. Doug Ledford
760 AHC_MOTHERBOARD
= 0x00020000,
761 AHC_NO_STPWEN
= 0x00040000,
762 AHC_RESET_DELAY
= 0x00080000,
763 AHC_A_SCANNED
= 0x00100000,
764 AHC_B_SCANNED
= 0x00200000,
765 AHC_MULTI_CHANNEL
= 0x00400000,
766 AHC_BIOS_ENABLED
= 0x00800000,
767 AHC_SEEPROM_FOUND
= 0x01000000,
768 AHC_TERM_ENB_LVD
= 0x02000000,
769 AHC_ABORT_PENDING
= 0x04000000,
770 AHC_RESET_PENDING
= 0x08000000,
771 #define AHC_IN_ISR_BIT 28
772 AHC_IN_ISR
= 0x10000000,
773 AHC_IN_ABORT
= 0x20000000,
774 AHC_IN_RESET
= 0x40000000,
775 AHC_EXTERNAL_SRAM
= 0x80000000
780 AHC_CHIPID_MASK
= 0x00ff,
781 AHC_AIC7770
= 0x0001,
782 AHC_AIC7850
= 0x0002,
783 AHC_AIC7860
= 0x0003,
784 AHC_AIC7870
= 0x0004,
785 AHC_AIC7880
= 0x0005,
786 AHC_AIC7890
= 0x0006,
787 AHC_AIC7895
= 0x0007,
788 AHC_AIC7896
= 0x0008,
789 AHC_AIC7892
= 0x0009,
790 AHC_AIC7899
= 0x000a,
802 AHC_MORE_SRAM
= 0x0010,
803 AHC_CMD_CHAN
= 0x0020,
804 AHC_QUEUE_REGS
= 0x0040,
805 AHC_SG_PRELOAD
= 0x0080,
806 AHC_SPIOCAP
= 0x0100,
808 AHC_NEW_AUTOTERM
= 0x0400,
809 AHC_AIC7770_FE
= AHC_FENONE
,
810 AHC_AIC7850_FE
= AHC_SPIOCAP
,
811 AHC_AIC7860_FE
= AHC_ULTRA
|AHC_SPIOCAP
,
812 AHC_AIC7870_FE
= AHC_FENONE
,
813 AHC_AIC7880_FE
= AHC_ULTRA
,
814 AHC_AIC7890_FE
= AHC_MORE_SRAM
|AHC_CMD_CHAN
|AHC_ULTRA2
|
815 AHC_QUEUE_REGS
|AHC_SG_PRELOAD
|AHC_NEW_AUTOTERM
,
816 AHC_AIC7895_FE
= AHC_MORE_SRAM
|AHC_CMD_CHAN
|AHC_ULTRA
,
817 AHC_AIC7896_FE
= AHC_AIC7890_FE
,
818 AHC_AIC7892_FE
= AHC_AIC7890_FE
|AHC_ULTRA3
,
819 AHC_AIC7899_FE
= AHC_AIC7890_FE
|AHC_ULTRA3
,
822 #define SCB_DMA_ADDR(scb, addr) ((unsigned long)(addr) + (scb)->scb_dma->dma_offset)
824 struct aic7xxx_scb_dma
{
825 unsigned long dma_offset
; /* Correction you have to add
826 * to virtual address to get
827 * dma handle in this region */
828 dma_addr_t dma_address
; /* DMA handle of the start,
830 unsigned int dma_len
; /* DMA length */
834 struct aic7xxx_hwscb
*hscb
; /* corresponding hardware scb */
835 Scsi_Cmnd
*cmd
; /* Scsi_Cmnd for this scb */
836 struct aic7xxx_scb
*q_next
; /* next scb in queue */
837 volatile scb_flag_type flags
; /* current state of scb */
838 struct hw_scatterlist
*sg_list
; /* SG list in adapter format */
839 unsigned char tag_action
;
840 unsigned char sg_count
;
841 unsigned char *sense_cmd
; /*
842 * Allocate 6 characters for
846 unsigned int sg_length
; /* We init this during buildscb so we
847 * don't have to calculate anything
848 * during underflow/overflow/stat code
851 struct aic7xxx_scb_dma
*scb_dma
;
855 * Define a linked list of SCBs.
858 struct aic7xxx_scb
*head
;
859 struct aic7xxx_scb
*tail
;
866 { ILLHADDR
, "Illegal Host Access" },
867 { ILLSADDR
, "Illegal Sequencer Address referenced" },
868 { ILLOPCODE
, "Illegal Opcode in sequencer program" },
869 { SQPARERR
, "Sequencer Ram Parity Error" },
870 { DPARERR
, "Data-Path Ram Parity Error" },
871 { MPARERR
, "Scratch Ram/SCB Array Ram Parity Error" },
872 { PCIERRSTAT
,"PCI Error detected" },
873 { CIOPARERR
, "CIOBUS Parity Error" }
877 generic_sense
[] = { REQUEST_SENSE
, 0, 0, 0, 255, 0 };
880 scb_queue_type free_scbs
; /*
881 * SCBs assigned to free slot on
882 * card (no paging required)
884 struct aic7xxx_scb
*scb_array
[AIC7XXX_MAXSCB
];
885 struct aic7xxx_hwscb
*hscbs
;
886 unsigned char numscbs
; /* current number of scbs */
887 unsigned char maxhscbs
; /* hardware scbs */
888 unsigned char maxscbs
; /* max scbs including pageable scbs */
889 dma_addr_t hscbs_dma
; /* DMA handle to hscbs */
890 unsigned int hscbs_dma_len
; /* length of the above DMA area */
891 void *hscb_kmalloc_ptr
;
895 unsigned char mesg_bytes
[4];
896 unsigned char command
[28];
899 #define AHC_TRANS_CUR 0x0001
900 #define AHC_TRANS_ACTIVE 0x0002
901 #define AHC_TRANS_GOAL 0x0004
902 #define AHC_TRANS_USER 0x0008
903 #define AHC_TRANS_QUITE 0x0010
905 unsigned char cur_width
;
906 unsigned char goal_width
;
907 unsigned char cur_period
;
908 unsigned char goal_period
;
909 unsigned char cur_offset
;
910 unsigned char goal_offset
;
911 unsigned char cur_options
;
912 unsigned char goal_options
;
913 unsigned char user_width
;
914 unsigned char user_period
;
915 unsigned char user_offset
;
916 unsigned char user_options
;
920 * Define a structure used for each host adapter. Note, in order to avoid
921 * problems with architectures I can't test on (because I don't have one,
922 * such as the Alpha based systems) which happen to give faults for
923 * non-aligned memory accesses, care was taken to align this structure
924 * in a way that gauranteed all accesses larger than 8 bits were aligned
925 * on the appropriate boundary. It's also organized to try and be more
926 * cache line efficient. Be careful when changing this lest you might hurt
927 * overall performance and bring down the wrath of the masses.
929 struct aic7xxx_host
{
931 * This is the first 64 bytes in the host struct
935 * We are grouping things here....first, items that get either read or
936 * written with nearly every interrupt
938 volatile ahc_flag_type flags
;
939 ahc_feature features
; /* chip features */
940 unsigned long base
; /* card base address */
941 volatile unsigned char *maddr
; /* memory mapped address */
942 unsigned long isr_count
; /* Interrupt count */
943 unsigned long spurious_int
;
944 scb_data_type
*scb_data
;
945 volatile unsigned short needdv
;
946 volatile unsigned short needppr
;
947 volatile unsigned short needsdtr
;
948 volatile unsigned short needwdtr
;
949 volatile unsigned short dtr_pending
;
950 struct aic7xxx_cmd_queue
{
956 * Things read/written on nearly every entry into aic7xxx_queue()
958 volatile scb_queue_type waiting_scbs
;
959 unsigned short discenable
; /* Targets allowed to disconnect */
960 unsigned short tagenable
; /* Targets using tagged I/O */
961 unsigned short orderedtag
; /* Ordered Q tags allowed */
962 unsigned char unpause
; /* unpause value for HCNTRL */
963 unsigned char pause
; /* pause value for HCNTRL */
964 volatile unsigned char qoutfifonext
;
965 volatile unsigned char activescbs
; /* active scbs */
966 volatile unsigned char max_activescbs
;
967 volatile unsigned char qinfifonext
;
968 volatile unsigned char *untagged_scbs
;
969 volatile unsigned char *qoutfifo
;
970 volatile unsigned char *qinfifo
;
972 #define DEVICE_PRESENT 0x01
973 #define BUS_DEVICE_RESET_PENDING 0x02
974 #define DEVICE_RESET_DELAY 0x04
975 #define DEVICE_PRINT_DTR 0x08
976 #define DEVICE_PARITY_ERROR 0x10
977 #define DEVICE_WAS_BUSY 0x20
978 #define DEVICE_SCSI_3 0x40
979 #define DEVICE_SCANNED 0x80
980 volatile unsigned char dev_flags
[MAX_TARGETS
];
981 volatile unsigned char dev_active_cmds
[MAX_TARGETS
];
982 volatile unsigned char dev_temp_queue_depth
[MAX_TARGETS
];
983 unsigned char dev_commands_sent
[MAX_TARGETS
];
985 unsigned int dev_timer_active
; /* Which devs have a timer set */
986 struct timer_list dev_timer
;
987 unsigned long dev_expires
[MAX_TARGETS
];
989 spinlock_t spin_lock
;
990 volatile unsigned char cpu_lock_count
[NR_CPUS
];
992 Scsi_Cmnd
*dev_dtr_cmnd
[MAX_TARGETS
];
994 unsigned int dev_checksum
[MAX_TARGETS
];
996 unsigned char dev_last_queue_full
[MAX_TARGETS
];
997 unsigned char dev_last_queue_full_count
[MAX_TARGETS
];
998 unsigned char dev_max_queue_depth
[MAX_TARGETS
];
1000 volatile scb_queue_type delayed_scbs
[MAX_TARGETS
];
1003 unsigned char msg_buf
[13]; /* The message for the target */
1004 unsigned char msg_type
;
1005 #define MSG_TYPE_NONE 0x00
1006 #define MSG_TYPE_INITIATOR_MSGOUT 0x01
1007 #define MSG_TYPE_INITIATOR_MSGIN 0x02
1008 unsigned char msg_len
; /* Length of message */
1009 unsigned char msg_index
; /* Index into msg_buf array */
1010 transinfo_type transinfo
[MAX_TARGETS
];
1014 * We put the less frequently used host structure items after the more
1015 * frequently used items to try and ease the burden on the cache subsystem.
1016 * These entries are not *commonly* accessed, whereas the preceding entries
1017 * are accessed very often.
1020 unsigned int irq
; /* IRQ for this adapter */
1021 int instance
; /* aic7xxx instance number */
1022 int scsi_id
; /* host adapter SCSI ID */
1023 int scsi_id_b
; /* channel B for twin adapters */
1024 unsigned int bios_address
;
1025 int board_name_index
;
1026 unsigned short needppr_copy
; /* default config */
1027 unsigned short needsdtr_copy
; /* default config */
1028 unsigned short needwdtr_copy
; /* default config */
1029 unsigned short ultraenb
; /* Ultra mode target list */
1030 unsigned short bios_control
; /* bios control - SEEPROM */
1031 unsigned short adapter_control
; /* adapter control - SEEPROM */
1032 struct pci_dev
*pdev
;
1033 unsigned char pci_bus
;
1034 unsigned char pci_device_fn
;
1035 struct seeprom_config sc
;
1036 unsigned short sc_type
;
1037 unsigned short sc_size
;
1038 struct aic7xxx_host
*next
; /* allow for multiple IRQs */
1039 struct Scsi_Host
*host
; /* pointer to scsi host */
1040 int host_no
; /* SCSI host number */
1041 unsigned long mbase
; /* I/O memory address */
1042 ahc_chip chip
; /* chip type */
1043 dma_addr_t fifo_dma
; /* DMA handle for fifo arrays */
1048 * Total Xfers (count for each command that has a data xfer),
1049 * broken down further by reads && writes.
1051 * Binned sizes, writes && reads:
1052 * < 512, 512, 1-2K, 2-4K, 4-8K, 8-16K, 16-32K, 32-64K, 64K-128K, > 128K
1054 * Total amounts read/written above 512 bytes (amts under ignored)
1056 * NOTE: Enabling this feature is likely to cause a noticeable performance
1057 * decrease as the accesses into the stats structures blows apart multiple
1058 * cache lines and is CPU time consuming.
1060 * NOTE: Since it doesn't really buy us much, but consumes *tons* of RAM
1061 * and blows apart all sorts of cache lines, I modified this so that we
1062 * no longer look at the LUN. All LUNs now go into the same bin on each
1063 * device for stats purposes.
1065 struct aic7xxx_xferstats
{
1066 long w_total
; /* total writes */
1067 long r_total
; /* total reads */
1068 #ifdef AIC7XXX_PROC_STATS
1069 long w_bins
[8]; /* binned write */
1070 long r_bins
[8]; /* binned reads */
1071 #endif /* AIC7XXX_PROC_STATS */
1072 } stats
[MAX_TARGETS
]; /* [(channel << 3)|target] */
1075 struct target_cmd
*targetcmds
;
1076 unsigned int num_targetcmds
;
1082 * Valid SCSIRATE values. (p. 3-17)
1083 * Provides a mapping of transfer periods in ns/4 to the proper value to
1084 * stick in the SCSIRATE reg to use that transfer rate.
1086 #define AHC_SYNCRATE_ULTRA3 0
1087 #define AHC_SYNCRATE_ULTRA2 1
1088 #define AHC_SYNCRATE_ULTRA 3
1089 #define AHC_SYNCRATE_FAST 6
1090 #define AHC_SYNCRATE_CRC 0x40
1091 #define AHC_SYNCRATE_SE 0x10
1092 static struct aic7xxx_syncrate
{
1093 /* Rates in Ultra mode have bit 8 of sxfr set */
1094 #define ULTRA_SXFR 0x100
1097 unsigned char period
;
1098 const char *rate
[2];
1099 } aic7xxx_syncrates
[] = {
1100 { 0x42, 0x000, 9, {"80.0", "160.0"} },
1101 { 0x13, 0x000, 10, {"40.0", "80.0"} },
1102 { 0x14, 0x000, 11, {"33.0", "66.6"} },
1103 { 0x15, 0x100, 12, {"20.0", "40.0"} },
1104 { 0x16, 0x110, 15, {"16.0", "32.0"} },
1105 { 0x17, 0x120, 18, {"13.4", "26.8"} },
1106 { 0x18, 0x000, 25, {"10.0", "20.0"} },
1107 { 0x19, 0x010, 31, {"8.0", "16.0"} },
1108 { 0x1a, 0x020, 37, {"6.67", "13.3"} },
1109 { 0x1b, 0x030, 43, {"5.7", "11.4"} },
1110 { 0x10, 0x040, 50, {"5.0", "10.0"} },
1111 { 0x00, 0x050, 56, {"4.4", "8.8" } },
1112 { 0x00, 0x060, 62, {"4.0", "8.0" } },
1113 { 0x00, 0x070, 68, {"3.6", "7.2" } },
1114 { 0x00, 0x000, 0, {NULL
, NULL
} },
1117 #define CTL_OF_SCB(scb) (((scb->hscb)->target_channel_lun >> 3) & 0x1), \
1118 (((scb->hscb)->target_channel_lun >> 4) & 0xf), \
1119 ((scb->hscb)->target_channel_lun & 0x07)
1121 #define CTL_OF_CMD(cmd) ((cmd->channel) & 0x01), \
1122 ((cmd->target) & 0x0f), \
1125 #define TARGET_INDEX(cmd) ((cmd)->target | ((cmd)->channel << 3))
1128 * A nice little define to make doing our printks a little easier
1131 #define WARN_LEAD KERN_WARNING "(scsi%d:%d:%d:%d) "
1132 #define INFO_LEAD KERN_INFO "(scsi%d:%d:%d:%d) "
1135 * XXX - these options apply unilaterally to _all_ 274x/284x/294x
1136 * cards in the system. This should be fixed. Exceptions to this
1137 * rule are noted in the comments.
1142 * Skip the scsi bus reset. Non 0 make us skip the reset at startup. This
1143 * has no effect on any later resets that might occur due to things like
1144 * SCSI bus timeouts.
1146 static unsigned int aic7xxx_no_reset
= 0;
1148 * Certain PCI motherboards will scan PCI devices from highest to lowest,
1149 * others scan from lowest to highest, and they tend to do all kinds of
1150 * strange things when they come into contact with PCI bridge chips. The
1151 * net result of all this is that the PCI card that is actually used to boot
1152 * the machine is very hard to detect. Most motherboards go from lowest
1153 * PCI slot number to highest, and the first SCSI controller found is the
1154 * one you boot from. The only exceptions to this are when a controller
1155 * has its BIOS disabled. So, we by default sort all of our SCSI controllers
1156 * from lowest PCI slot number to highest PCI slot number. We also force
1157 * all controllers with their BIOS disabled to the end of the list. This
1158 * works on *almost* all computers. Where it doesn't work, we have this
1159 * option. Setting this option to non-0 will reverse the order of the sort
1160 * to highest first, then lowest, but will still leave cards with their BIOS
1161 * disabled at the very end. That should fix everyone up unless there are
1162 * really strange cirumstances.
1164 static int aic7xxx_reverse_scan
= 0;
1166 * Should we force EXTENDED translation on a controller.
1167 * 0 == Use whatever is in the SEEPROM or default to off
1168 * 1 == Use whatever is in the SEEPROM or default to on
1170 static unsigned int aic7xxx_extended
= 0;
1172 * The IRQ trigger method used on EISA controllers. Does not effect PCI cards.
1173 * -1 = Use detected settings.
1174 * 0 = Force Edge triggered mode.
1175 * 1 = Force Level triggered mode.
1177 static int aic7xxx_irq_trigger
= -1;
1179 * This variable is used to override the termination settings on a controller.
1180 * This should not be used under normal conditions. However, in the case
1181 * that a controller does not have a readable SEEPROM (so that we can't
1182 * read the SEEPROM settings directly) and that a controller has a buggered
1183 * version of the cable detection logic, this can be used to force the
1184 * correct termination. It is preferable to use the manual termination
1185 * settings in the BIOS if possible, but some motherboard controllers store
1186 * those settings in a format we can't read. In other cases, auto term
1187 * should also work, but the chipset was put together with no auto term
1188 * logic (common on motherboard controllers). In those cases, we have
1189 * 32 bits here to work with. That's good for 8 controllers/channels. The
1190 * bits are organized as 4 bits per channel, with scsi0 getting the lowest
1191 * 4 bits in the int. A 1 in a bit position indicates the termination setting
1192 * that corresponds to that bit should be enabled, a 0 is disabled.
1193 * It looks something like this:
1195 * 0x0f = 1111-Single Ended Low Byte Termination on/off
1196 * ||\-Single Ended High Byte Termination on/off
1197 * |\-LVD Low Byte Termination on/off
1198 * \-LVD High Byte Termination on/off
1200 * For non-Ultra2 controllers, the upper 2 bits are not important. So, to
1201 * enable both high byte and low byte termination on scsi0, I would need to
1202 * make sure that the override_term variable was set to 0x03 (bits 0011).
1203 * To make sure that all termination is enabled on an Ultra2 controller at
1204 * scsi2 and only high byte termination on scsi1 and high and low byte
1205 * termination on scsi0, I would set override_term=0xf23 (bits 1111 0010 0011)
1207 * For the most part, users should never have to use this, that's why I
1208 * left it fairly cryptic instead of easy to understand. If you need it,
1209 * most likely someone will be telling you what your's needs to be set to.
1211 static int aic7xxx_override_term
= -1;
1213 * Certain motherboard chipset controllers tend to screw
1214 * up the polarity of the term enable output pin. Use this variable
1215 * to force the correct polarity for your system. This is a bitfield variable
1216 * similar to the previous one, but this one has one bit per channel instead
1218 * 0 = Force the setting to active low.
1219 * 1 = Force setting to active high.
1220 * Most Adaptec cards are active high, several motherboards are active low.
1221 * To force a 2940 card at SCSI 0 to active high and a motherboard 7895
1222 * controller at scsi1 and scsi2 to active low, and a 2910 card at scsi3
1223 * to active high, you would need to set stpwlev=0x9 (bits 1001).
1225 * People shouldn't need to use this, but if you are experiencing lots of
1226 * SCSI timeout problems, this may help. There is one sure way to test what
1227 * this option needs to be. Using a boot floppy to boot the system, configure
1228 * your system to enable all SCSI termination (in the Adaptec SCSI BIOS) and
1229 * if needed then also pass a value to override_term to make sure that the
1230 * driver is enabling SCSI termination, then set this variable to either 0
1231 * or 1. When the driver boots, make sure there are *NO* SCSI cables
1232 * connected to your controller. If it finds and inits the controller
1233 * without problem, then the setting you passed to stpwlev was correct. If
1234 * the driver goes into a reset loop and hangs the system, then you need the
1235 * other setting for this variable. If neither setting lets the machine
1236 * boot then you have definite termination problems that may not be fixable.
1238 static int aic7xxx_stpwlev
= -1;
1240 * Set this to non-0 in order to force the driver to panic the kernel
1241 * and print out debugging info on a SCSI abort or reset cycle.
1243 static int aic7xxx_panic_on_abort
= 0;
1245 * PCI bus parity checking of the Adaptec controllers. This is somewhat
1246 * dubious at best. To my knowledge, this option has never actually
1247 * solved a PCI parity problem, but on certain machines with broken PCI
1248 * chipset configurations, it can generate tons of false error messages.
1249 * It's included in the driver for completeness.
1250 * 0 = Shut off PCI parity check
1251 * -1 = Normal polarity pci parity checking
1252 * 1 = reverse polarity pci parity checking
1254 * NOTE: you can't actually pass -1 on the lilo prompt. So, to set this
1255 * variable to -1 you would actually want to simply pass the variable
1256 * name without a number. That will invert the 0 which will result in
1259 static int aic7xxx_pci_parity
= 0;
1261 * Set this to any non-0 value to cause us to dump the contents of all
1262 * the card's registers in a hex dump format tailored to each model of
1265 * NOTE: THE CONTROLLER IS LEFT IN AN UNUSEABLE STATE BY THIS OPTION.
1266 * YOU CANNOT BOOT UP WITH THIS OPTION, IT IS FOR DEBUGGING PURPOSES
1269 static int aic7xxx_dump_card
= 0;
1271 * Set this to a non-0 value to make us dump out the 32 bit instruction
1272 * registers on the card after completing the sequencer download. This
1273 * allows the actual sequencer download to be verified. It is possible
1274 * to use this option and still boot up and run your system. This is
1275 * only intended for debugging purposes.
1277 static int aic7xxx_dump_sequencer
= 0;
1279 * Certain newer motherboards have put new PCI based devices into the
1280 * IO spaces that used to typically be occupied by VLB or EISA cards.
1281 * This overlap can cause these newer motherboards to lock up when scanned
1282 * for older EISA and VLB devices. Setting this option to non-0 will
1283 * cause the driver to skip scanning for any VLB or EISA controllers and
1284 * only support the PCI controllers. NOTE: this means that if the kernel
1285 * os compiled with PCI support disabled, then setting this to non-0
1286 * would result in never finding any devices :)
1288 static int aic7xxx_no_probe
= 0;
1290 * On some machines, enabling the external SCB RAM isn't reliable yet. I
1291 * haven't had time to make test patches for things like changing the
1292 * timing mode on that external RAM either. Some of those changes may
1293 * fix the problem. Until then though, we default to external SCB RAM
1294 * off and give a command line option to enable it.
1296 static int aic7xxx_scbram
= 0;
1298 * So that we can set how long each device is given as a selection timeout.
1299 * The table of values goes like this:
1304 * We default to 64ms because it's fast. Some old SCSI-I devices need a
1305 * longer time. The final value has to be left shifted by 3, hence 0x10
1306 * is the final value.
1308 static int aic7xxx_seltime
= 0x10;
1310 * So that insmod can find the variable and make it point to something
1313 static char * aic7xxx
= NULL
;
1314 MODULE_PARM(aic7xxx
, "s");
1317 * Just in case someone uses commas to separate items on the insmod
1318 * command line, we define a dummy buffer here to avoid having insmod
1319 * write wild stuff into our code segment
1321 static char dummy_buffer
[60] = "Please don't trounce on me insmod!!\n";
1325 #define VERBOSE_NORMAL 0x0000
1326 #define VERBOSE_NEGOTIATION 0x0001
1327 #define VERBOSE_SEQINT 0x0002
1328 #define VERBOSE_SCSIINT 0x0004
1329 #define VERBOSE_PROBE 0x0008
1330 #define VERBOSE_PROBE2 0x0010
1331 #define VERBOSE_NEGOTIATION2 0x0020
1332 #define VERBOSE_MINOR_ERROR 0x0040
1333 #define VERBOSE_TRACING 0x0080
1334 #define VERBOSE_ABORT 0x0f00
1335 #define VERBOSE_ABORT_MID 0x0100
1336 #define VERBOSE_ABORT_FIND 0x0200
1337 #define VERBOSE_ABORT_PROCESS 0x0400
1338 #define VERBOSE_ABORT_RETURN 0x0800
1339 #define VERBOSE_RESET 0xf000
1340 #define VERBOSE_RESET_MID 0x1000
1341 #define VERBOSE_RESET_FIND 0x2000
1342 #define VERBOSE_RESET_PROCESS 0x4000
1343 #define VERBOSE_RESET_RETURN 0x8000
1344 static int aic7xxx_verbose
= VERBOSE_NORMAL
| VERBOSE_NEGOTIATION
|
1345 VERBOSE_PROBE
; /* verbose messages */
1348 /****************************************************************************
1350 * We're going to start putting in function declarations so that order of
1351 * functions is no longer important. As needed, they are added here.
1353 ***************************************************************************/
1355 static void aic7xxx_panic_abort(struct aic7xxx_host
*p
, Scsi_Cmnd
*cmd
);
1356 static void aic7xxx_print_card(struct aic7xxx_host
*p
);
1357 static void aic7xxx_print_scratch_ram(struct aic7xxx_host
*p
);
1358 static void aic7xxx_print_sequencer(struct aic7xxx_host
*p
, int downloaded
);
1359 #ifdef AIC7XXX_VERBOSE_DEBUGGING
1360 static void aic7xxx_check_scbs(struct aic7xxx_host
*p
, char *buffer
);
1363 /****************************************************************************
1365 * These functions are now used. They happen to be wrapped in useless
1366 * inb/outb port read/writes around the real reads and writes because it
1367 * seems that certain very fast CPUs have a problem dealing with us when
1368 * going at full speed.
1370 ***************************************************************************/
1372 static inline unsigned char
1373 aic_inb(struct aic7xxx_host
*p
, long port
)
1379 x
= readb(p
->maddr
+ port
);
1383 x
= inb(p
->base
+ port
);
1387 return(inb(p
->base
+ port
));
1392 aic_outb(struct aic7xxx_host
*p
, unsigned char val
, long port
)
1397 writeb(val
, p
->maddr
+ port
);
1398 mb(); /* locked operation in order to force CPU ordering */
1399 readb(p
->maddr
+ HCNTRL
); /* dummy read to flush the PCI write */
1403 outb(val
, p
->base
+ port
);
1404 mb(); /* locked operation in order to force CPU ordering */
1407 outb(val
, p
->base
+ port
);
1408 mb(); /* locked operation in order to force CPU ordering */
1412 /*+F*************************************************************************
1417 * Handle Linux boot parameters. This routine allows for assigning a value
1418 * to a parameter with a ':' between the parameter and the value.
1419 * ie. aic7xxx=unpause:0x0A,extended
1420 *-F*************************************************************************/
1422 aic7xxx_setup(char *s
)
1432 { "extended", &aic7xxx_extended
},
1433 { "no_reset", &aic7xxx_no_reset
},
1434 { "irq_trigger", &aic7xxx_irq_trigger
},
1435 { "verbose", &aic7xxx_verbose
},
1436 { "reverse_scan",&aic7xxx_reverse_scan
},
1437 { "override_term", &aic7xxx_override_term
},
1438 { "stpwlev", &aic7xxx_stpwlev
},
1439 { "no_probe", &aic7xxx_no_probe
},
1440 { "panic_on_abort", &aic7xxx_panic_on_abort
},
1441 { "pci_parity", &aic7xxx_pci_parity
},
1442 { "dump_card", &aic7xxx_dump_card
},
1443 { "dump_sequencer", &aic7xxx_dump_sequencer
},
1444 { "scbram", &aic7xxx_scbram
},
1445 { "seltime", &aic7xxx_seltime
},
1446 { "tag_info", NULL
}
1449 end
= strchr(s
, '\0');
1451 for (p
= strtok(s
, ",."); p
; p
= strtok(NULL
, ",."))
1453 for (i
= 0; i
< NUMBER(options
); i
++)
1455 n
= strlen(options
[i
].name
);
1456 if (!strncmp(options
[i
].name
, p
, n
))
1458 if (!strncmp(p
, "tag_info", n
))
1463 char *tok
, *tok_end
, *tok_end2
;
1464 char tok_list
[] = { '.', ',', '{', '}', '\0' };
1465 int i
, instance
= -1, device
= -1;
1466 unsigned char done
= FALSE
;
1469 tok
= base
+ n
+ 1; /* Forward us just past the ':' */
1470 tok_end
= strchr(tok
, '\0');
1480 else if (device
== -1)
1487 else if (instance
!= -1)
1495 else if (device
>= 0)
1497 else if (instance
>= 0)
1499 if ( (device
>= MAX_TARGETS
) ||
1500 (instance
>= NUMBER(aic7xxx_tag_info
)) )
1513 tok_end
= strchr(tok
, '\0');
1514 for(i
=0; tok_list
[i
]; i
++)
1516 tok_end2
= strchr(tok
, tok_list
[i
]);
1517 if ( (tok_end2
) && (tok_end2
< tok_end
) )
1523 if ( (instance
>= 0) && (device
>= 0) &&
1524 (instance
< NUMBER(aic7xxx_tag_info
)) &&
1525 (device
< MAX_TARGETS
) )
1526 aic7xxx_tag_info
[instance
].tag_commands
[device
] =
1527 simple_strtoul(tok
, NULL
, 0) & 0xff;
1532 while((p
!= base
) && (p
!= NULL
))
1533 p
= strtok(NULL
, ",.");
1536 else if (p
[n
] == ':')
1538 *(options
[i
].flag
) = simple_strtoul(p
+ n
+ 1, NULL
, 0);
1539 if(!strncmp(p
, "seltime", n
))
1541 *(options
[i
].flag
) = (*(options
[i
].flag
) % 4) << 3;
1544 else if (!strncmp(p
, "verbose", n
))
1546 *(options
[i
].flag
) = 0xff29;
1550 *(options
[i
].flag
) = ~(*(options
[i
].flag
));
1551 if(!strncmp(p
, "seltime", n
))
1553 *(options
[i
].flag
) = (*(options
[i
].flag
) % 4) << 3;
1562 __setup("aic7xxx=", aic7xxx_setup
);
1564 /*+F*************************************************************************
1569 * Pause the sequencer and wait for it to actually stop - this
1570 * is important since the sequencer can disable pausing for critical
1572 *-F*************************************************************************/
1574 pause_sequencer(struct aic7xxx_host
*p
)
1576 aic_outb(p
, p
->pause
, HCNTRL
);
1577 while ((aic_inb(p
, HCNTRL
) & PAUSE
) == 0)
1581 if(p
->features
& AHC_ULTRA2
)
1583 aic_inb(p
, CCSCBCTL
);
1587 /*+F*************************************************************************
1592 * Unpause the sequencer. Unremarkable, yet done often enough to
1593 * warrant an easy way to do it.
1594 *-F*************************************************************************/
1596 unpause_sequencer(struct aic7xxx_host
*p
, int unpause_always
)
1598 if (unpause_always
||
1599 ( !(aic_inb(p
, INTSTAT
) & (SCSIINT
| SEQINT
| BRKADRINT
)) &&
1600 !(p
->flags
& AHC_HANDLING_REQINITS
) ) )
1602 aic_outb(p
, p
->unpause
, HCNTRL
);
1606 /*+F*************************************************************************
1611 * Restart the sequencer program from address zero. This assumes
1612 * that the sequencer is already paused.
1613 *-F*************************************************************************/
1615 restart_sequencer(struct aic7xxx_host
*p
)
1617 aic_outb(p
, 0, SEQADDR0
);
1618 aic_outb(p
, 0, SEQADDR1
);
1619 aic_outb(p
, FASTMODE
, SEQCTL
);
1623 * We include the aic7xxx_seq.c file here so that the other defines have
1624 * already been made, and so that it comes before the code that actually
1625 * downloads the instructions (since we don't typically use function
1626 * prototype, our code has to be ordered that way, it's a left-over from
1627 * the original driver days.....I should fix it some time DL).
1629 #include "aic7xxx_seq.c"
1631 /*+F*************************************************************************
1633 * aic7xxx_check_patch
1636 * See if the next patch to download should be downloaded.
1637 *-F*************************************************************************/
1639 aic7xxx_check_patch(struct aic7xxx_host
*p
,
1640 struct sequencer_patch
**start_patch
, int start_instr
, int *skip_addr
)
1642 struct sequencer_patch
*cur_patch
;
1643 struct sequencer_patch
*last_patch
;
1646 num_patches
= sizeof(sequencer_patches
)/sizeof(struct sequencer_patch
);
1647 last_patch
= &sequencer_patches
[num_patches
];
1648 cur_patch
= *start_patch
;
1650 while ((cur_patch
< last_patch
) && (start_instr
== cur_patch
->begin
))
1652 if (cur_patch
->patch_func(p
) == 0)
1655 * Start rejecting code.
1657 *skip_addr
= start_instr
+ cur_patch
->skip_instr
;
1658 cur_patch
+= cur_patch
->skip_patch
;
1663 * Found an OK patch. Advance the patch pointer to the next patch
1664 * and wait for our instruction pointer to get here.
1670 *start_patch
= cur_patch
;
1671 if (start_instr
< *skip_addr
)
1680 /*+F*************************************************************************
1682 * aic7xxx_download_instr
1685 * Find the next patch to download.
1686 *-F*************************************************************************/
1688 aic7xxx_download_instr(struct aic7xxx_host
*p
, int instrptr
,
1689 unsigned char *dconsts
)
1691 union ins_formats instr
;
1692 struct ins_format1
*fmt1_ins
;
1693 struct ins_format3
*fmt3_ins
;
1694 unsigned char opcode
;
1696 instr
= *(union ins_formats
*) &seqprog
[instrptr
* 4];
1698 instr
.integer
= le32_to_cpu(instr
.integer
);
1700 fmt1_ins
= &instr
.format1
;
1703 /* Pull the opcode */
1704 opcode
= instr
.format1
.opcode
;
1716 struct sequencer_patch
*cur_patch
;
1718 unsigned int address
;
1722 fmt3_ins
= &instr
.format3
;
1724 address
= fmt3_ins
->address
;
1725 cur_patch
= sequencer_patches
;
1728 for (i
= 0; i
< address
;)
1730 aic7xxx_check_patch(p
, &cur_patch
, i
, &skip_addr
);
1735 end_addr
= MIN(address
, skip_addr
);
1736 address_offset
+= end_addr
- i
;
1744 address
-= address_offset
;
1745 fmt3_ins
->address
= address
;
1746 /* Fall Through to the next code section */
1754 if (fmt1_ins
->parity
!= 0)
1756 fmt1_ins
->immediate
= dconsts
[fmt1_ins
->immediate
];
1758 fmt1_ins
->parity
= 0;
1759 /* Fall Through to the next code section */
1761 if ((p
->features
& AHC_ULTRA2
) != 0)
1765 /* Calculate odd parity for the instruction */
1766 for ( i
=0, count
=0; i
< 31; i
++)
1771 if ((instr
.integer
& mask
) != 0)
1774 if (!(count
& 0x01))
1775 instr
.format1
.parity
= 1;
1779 if (fmt3_ins
!= NULL
)
1781 instr
.integer
= fmt3_ins
->immediate
|
1782 (fmt3_ins
->source
<< 8) |
1783 (fmt3_ins
->address
<< 16) |
1784 (fmt3_ins
->opcode
<< 25);
1788 instr
.integer
= fmt1_ins
->immediate
|
1789 (fmt1_ins
->source
<< 8) |
1790 (fmt1_ins
->destination
<< 16) |
1791 (fmt1_ins
->ret
<< 24) |
1792 (fmt1_ins
->opcode
<< 25);
1795 aic_outb(p
, (instr
.integer
& 0xff), SEQRAM
);
1796 aic_outb(p
, ((instr
.integer
>> 8) & 0xff), SEQRAM
);
1797 aic_outb(p
, ((instr
.integer
>> 16) & 0xff), SEQRAM
);
1798 aic_outb(p
, ((instr
.integer
>> 24) & 0xff), SEQRAM
);
1803 panic("aic7xxx: Unknown opcode encountered in sequencer program.");
1809 /*+F*************************************************************************
1814 * Load the sequencer code into the controller memory.
1815 *-F*************************************************************************/
1817 aic7xxx_loadseq(struct aic7xxx_host
*p
)
1819 struct sequencer_patch
*cur_patch
;
1823 unsigned char download_consts
[4] = {0, 0, 0, 0};
1825 if (aic7xxx_verbose
& VERBOSE_PROBE
)
1827 printk(KERN_INFO
"(scsi%d) Downloading sequencer code...", p
->host_no
);
1830 download_consts
[TMODE_NUMCMDS
] = p
->num_targetcmds
;
1832 download_consts
[TMODE_NUMCMDS
] = 0;
1833 cur_patch
= &sequencer_patches
[0];
1837 aic_outb(p
, PERRORDIS
|LOADRAM
|FAILDIS
|FASTMODE
, SEQCTL
);
1838 aic_outb(p
, 0, SEQADDR0
);
1839 aic_outb(p
, 0, SEQADDR1
);
1841 for (i
= 0; i
< sizeof(seqprog
) / 4; i
++)
1843 if (aic7xxx_check_patch(p
, &cur_patch
, i
, &skip_addr
) == 0)
1845 /* Skip this instruction for this configuration. */
1848 aic7xxx_download_instr(p
, i
, &download_consts
[0]);
1852 aic_outb(p
, 0, SEQADDR0
);
1853 aic_outb(p
, 0, SEQADDR1
);
1854 aic_outb(p
, FASTMODE
| FAILDIS
, SEQCTL
);
1855 unpause_sequencer(p
, TRUE
);
1858 aic_outb(p
, FASTMODE
, SEQCTL
);
1859 if (aic7xxx_verbose
& VERBOSE_PROBE
)
1861 printk(" %d instructions downloaded\n", downloaded
);
1863 if (aic7xxx_dump_sequencer
)
1864 aic7xxx_print_sequencer(p
, downloaded
);
1867 /*+F*************************************************************************
1869 * aic7xxx_print_sequencer
1872 * Print the contents of the sequencer memory to the screen.
1873 *-F*************************************************************************/
1875 aic7xxx_print_sequencer(struct aic7xxx_host
*p
, int downloaded
)
1879 aic_outb(p
, PERRORDIS
|LOADRAM
|FAILDIS
|FASTMODE
, SEQCTL
);
1880 aic_outb(p
, 0, SEQADDR0
);
1881 aic_outb(p
, 0, SEQADDR1
);
1884 for (i
=0; i
< downloaded
; i
++)
1887 printk("%03x: ", i
);
1888 temp
= aic_inb(p
, SEQRAM
);
1889 temp
|= (aic_inb(p
, SEQRAM
) << 8);
1890 temp
|= (aic_inb(p
, SEQRAM
) << 16);
1891 temp
|= (aic_inb(p
, SEQRAM
) << 24);
1892 printk("%08x", temp
);
1901 aic_outb(p
, 0, SEQADDR0
);
1902 aic_outb(p
, 0, SEQADDR1
);
1903 aic_outb(p
, FASTMODE
| FAILDIS
, SEQCTL
);
1904 unpause_sequencer(p
, TRUE
);
1907 aic_outb(p
, FASTMODE
, SEQCTL
);
1911 /*+F*************************************************************************
1916 * Return a string describing the driver.
1917 *-F*************************************************************************/
1919 aic7xxx_info(struct Scsi_Host
*dooh
)
1921 static char buffer
[256];
1923 struct aic7xxx_host
*p
;
1926 p
= (struct aic7xxx_host
*)dooh
->hostdata
;
1927 memset(bp
, 0, sizeof(buffer
));
1928 strcpy(bp
, "Adaptec AHA274x/284x/294x (EISA/VLB/PCI-Fast SCSI) ");
1929 strcat(bp
, AIC7XXX_C_VERSION
);
1931 strcat(bp
, AIC7XXX_H_VERSION
);
1934 strcat(bp
, board_names
[p
->board_name_index
]);
1940 /*+F*************************************************************************
1942 * aic7xxx_find_syncrate
1945 * Look up the valid period to SCSIRATE conversion in our table
1946 *-F*************************************************************************/
1947 static struct aic7xxx_syncrate
*
1948 aic7xxx_find_syncrate(struct aic7xxx_host
*p
, unsigned int *period
,
1949 unsigned int maxsync
, unsigned char *options
)
1951 struct aic7xxx_syncrate
*syncrate
;
1956 case MSG_EXT_PPR_OPTION_DT_CRC
:
1957 case MSG_EXT_PPR_OPTION_DT_UNITS
:
1958 if(!(p
->features
& AHC_ULTRA3
))
1961 maxsync
= MAX(maxsync
, AHC_SYNCRATE_ULTRA2
);
1964 case MSG_EXT_PPR_OPTION_DT_CRC_QUICK
:
1965 case MSG_EXT_PPR_OPTION_DT_UNITS_QUICK
:
1966 if(!(p
->features
& AHC_ULTRA3
))
1969 maxsync
= MAX(maxsync
, AHC_SYNCRATE_ULTRA2
);
1974 * we don't support the Quick Arbitration variants of dual edge
1975 * clocking. As it turns out, we want to send back the
1976 * same basic option, but without the QA attribute.
1977 * We know that we are responding because we would never set
1978 * these options ourself, we would only respond to them.
1982 case MSG_EXT_PPR_OPTION_DT_CRC_QUICK
:
1983 *options
= MSG_EXT_PPR_OPTION_DT_CRC
;
1985 case MSG_EXT_PPR_OPTION_DT_UNITS_QUICK
:
1986 *options
= MSG_EXT_PPR_OPTION_DT_UNITS
;
1993 maxsync
= MAX(maxsync
, AHC_SYNCRATE_ULTRA2
);
1996 syncrate
= &aic7xxx_syncrates
[maxsync
];
1997 while ( (syncrate
->rate
[0] != NULL
) &&
1998 (!(p
->features
& AHC_ULTRA2
) || syncrate
->sxfr_ultra2
) )
2000 if (*period
<= syncrate
->period
)
2004 case MSG_EXT_PPR_OPTION_DT_CRC
:
2005 case MSG_EXT_PPR_OPTION_DT_UNITS
:
2006 if(!(syncrate
->sxfr_ultra2
& AHC_SYNCRATE_CRC
))
2010 * oops, we went too low for the CRC/DualEdge signalling, so
2011 * clear the options byte
2015 * We'll be sending a reply to this packet to set the options
2016 * properly, so unilaterally set the period as well.
2018 *period
= syncrate
->period
;
2023 if(syncrate
== &aic7xxx_syncrates
[maxsync
])
2025 *period
= syncrate
->period
;
2030 if(!(syncrate
->sxfr_ultra2
& AHC_SYNCRATE_CRC
))
2033 if(syncrate
== &aic7xxx_syncrates
[maxsync
])
2035 *period
= syncrate
->period
;
2047 if ( (*period
== 0) || (syncrate
->rate
[0] == NULL
) ||
2048 ((p
->features
& AHC_ULTRA2
) && (syncrate
->sxfr_ultra2
== 0)) )
2051 * Use async transfers for this target
2061 /*+F*************************************************************************
2063 * aic7xxx_find_period
2066 * Look up the valid SCSIRATE to period conversion in our table
2067 *-F*************************************************************************/
2069 aic7xxx_find_period(struct aic7xxx_host
*p
, unsigned int scsirate
,
2070 unsigned int maxsync
)
2072 struct aic7xxx_syncrate
*syncrate
;
2074 if (p
->features
& AHC_ULTRA2
)
2076 scsirate
&= SXFR_ULTRA2
;
2083 syncrate
= &aic7xxx_syncrates
[maxsync
];
2084 while (syncrate
->rate
[0] != NULL
)
2086 if (p
->features
& AHC_ULTRA2
)
2088 if (syncrate
->sxfr_ultra2
== 0)
2090 else if (scsirate
== syncrate
->sxfr_ultra2
)
2091 return (syncrate
->period
);
2092 else if (scsirate
== (syncrate
->sxfr_ultra2
& ~AHC_SYNCRATE_CRC
))
2093 return (syncrate
->period
);
2095 else if (scsirate
== (syncrate
->sxfr
& ~ULTRA_SXFR
))
2097 return (syncrate
->period
);
2101 return (0); /* async */
2104 /*+F*************************************************************************
2106 * aic7xxx_validate_offset
2109 * Set a valid offset value for a particular card in use and transfer
2111 *-F*************************************************************************/
2113 aic7xxx_validate_offset(struct aic7xxx_host
*p
,
2114 struct aic7xxx_syncrate
*syncrate
, unsigned int *offset
, int wide
)
2116 unsigned int maxoffset
;
2118 /* Limit offset to what the card (and device) can do */
2119 if (syncrate
== NULL
)
2123 else if (p
->features
& AHC_ULTRA2
)
2125 maxoffset
= MAX_OFFSET_ULTRA2
;
2130 maxoffset
= MAX_OFFSET_16BIT
;
2132 maxoffset
= MAX_OFFSET_8BIT
;
2134 *offset
= MIN(*offset
, maxoffset
);
2137 /*+F*************************************************************************
2139 * aic7xxx_set_syncrate
2142 * Set the actual syncrate down in the card and in our host structs
2143 *-F*************************************************************************/
2145 aic7xxx_set_syncrate(struct aic7xxx_host
*p
, struct aic7xxx_syncrate
*syncrate
,
2146 int target
, int channel
, unsigned int period
, unsigned int offset
,
2147 unsigned char options
, unsigned int type
)
2149 unsigned char tindex
;
2150 unsigned short target_mask
;
2151 unsigned char lun
, old_options
;
2152 unsigned int old_period
, old_offset
;
2154 tindex
= target
| (channel
<< 3);
2155 target_mask
= 0x01 << tindex
;
2156 lun
= aic_inb(p
, SCB_TCL
) & 0x07;
2158 if (syncrate
== NULL
)
2164 old_period
= p
->transinfo
[tindex
].cur_period
;
2165 old_offset
= p
->transinfo
[tindex
].cur_offset
;
2166 old_options
= p
->transinfo
[tindex
].cur_options
;
2169 if (type
& AHC_TRANS_CUR
)
2171 unsigned int scsirate
;
2173 scsirate
= aic_inb(p
, TARG_SCSIRATE
+ tindex
);
2174 if (p
->features
& AHC_ULTRA2
)
2176 scsirate
&= ~SXFR_ULTRA2
;
2177 if (syncrate
!= NULL
)
2181 case MSG_EXT_PPR_OPTION_DT_UNITS
:
2183 * mask off the CRC bit in the xfer settings
2185 scsirate
|= (syncrate
->sxfr_ultra2
& ~AHC_SYNCRATE_CRC
);
2188 scsirate
|= syncrate
->sxfr_ultra2
;
2192 if (type
& AHC_TRANS_ACTIVE
)
2194 aic_outb(p
, offset
, SCSIOFFSET
);
2196 aic_outb(p
, offset
, TARG_OFFSET
+ tindex
);
2198 else /* Not an Ultra2 controller */
2200 scsirate
&= ~(SXFR
|SOFS
);
2201 p
->ultraenb
&= ~target_mask
;
2202 if (syncrate
!= NULL
)
2204 if (syncrate
->sxfr
& ULTRA_SXFR
)
2206 p
->ultraenb
|= target_mask
;
2208 scsirate
|= (syncrate
->sxfr
& SXFR
);
2209 scsirate
|= (offset
& SOFS
);
2211 if (type
& AHC_TRANS_ACTIVE
)
2213 unsigned char sxfrctl0
;
2215 sxfrctl0
= aic_inb(p
, SXFRCTL0
);
2216 sxfrctl0
&= ~FAST20
;
2217 if (p
->ultraenb
& target_mask
)
2219 aic_outb(p
, sxfrctl0
, SXFRCTL0
);
2221 aic_outb(p
, p
->ultraenb
& 0xff, ULTRA_ENB
);
2222 aic_outb(p
, (p
->ultraenb
>> 8) & 0xff, ULTRA_ENB
+ 1 );
2224 if (type
& AHC_TRANS_ACTIVE
)
2226 aic_outb(p
, scsirate
, SCSIRATE
);
2228 aic_outb(p
, scsirate
, TARG_SCSIRATE
+ tindex
);
2229 p
->transinfo
[tindex
].cur_period
= period
;
2230 p
->transinfo
[tindex
].cur_offset
= offset
;
2231 p
->transinfo
[tindex
].cur_options
= options
;
2232 if ( !(type
& AHC_TRANS_QUITE
) &&
2233 (aic7xxx_verbose
& VERBOSE_NEGOTIATION
) &&
2234 (p
->dev_flags
[tindex
] & DEVICE_PRINT_DTR
) )
2238 int rate_mod
= (scsirate
& WIDEXFER
) ? 1 : 0;
2240 printk(INFO_LEAD
"Synchronous at %s Mbyte/sec, "
2241 "offset %d.\n", p
->host_no
, channel
, target
, lun
,
2242 syncrate
->rate
[rate_mod
], offset
);
2246 printk(INFO_LEAD
"Using asynchronous transfers.\n",
2247 p
->host_no
, channel
, target
, lun
);
2249 p
->dev_flags
[tindex
] &= ~DEVICE_PRINT_DTR
;
2253 if (type
& AHC_TRANS_GOAL
)
2255 p
->transinfo
[tindex
].goal_period
= period
;
2256 p
->transinfo
[tindex
].goal_offset
= offset
;
2257 p
->transinfo
[tindex
].goal_options
= options
;
2260 if (type
& AHC_TRANS_USER
)
2262 p
->transinfo
[tindex
].user_period
= period
;
2263 p
->transinfo
[tindex
].user_offset
= offset
;
2264 p
->transinfo
[tindex
].user_options
= options
;
2268 /*+F*************************************************************************
2273 * Set the actual width down in the card and in our host structs
2274 *-F*************************************************************************/
2276 aic7xxx_set_width(struct aic7xxx_host
*p
, int target
, int channel
, int lun
,
2277 unsigned int width
, unsigned int type
)
2279 unsigned char tindex
;
2280 unsigned short target_mask
;
2281 unsigned int old_width
;
2283 tindex
= target
| (channel
<< 3);
2284 target_mask
= 1 << tindex
;
2286 old_width
= p
->transinfo
[tindex
].cur_width
;
2288 if (type
& AHC_TRANS_CUR
)
2290 unsigned char scsirate
;
2292 scsirate
= aic_inb(p
, TARG_SCSIRATE
+ tindex
);
2294 scsirate
&= ~WIDEXFER
;
2295 if (width
== MSG_EXT_WDTR_BUS_16_BIT
)
2296 scsirate
|= WIDEXFER
;
2298 aic_outb(p
, scsirate
, TARG_SCSIRATE
+ tindex
);
2300 if (type
& AHC_TRANS_ACTIVE
)
2301 aic_outb(p
, scsirate
, SCSIRATE
);
2303 p
->transinfo
[tindex
].cur_width
= width
;
2305 if ( !(type
& AHC_TRANS_QUITE
) &&
2306 (aic7xxx_verbose
& VERBOSE_NEGOTIATION2
) &&
2307 (p
->dev_flags
[tindex
] & DEVICE_PRINT_DTR
) )
2309 printk(INFO_LEAD
"Using %s transfers\n", p
->host_no
, channel
, target
,
2310 lun
, (scsirate
& WIDEXFER
) ? "Wide(16bit)" : "Narrow(8bit)" );
2314 if (type
& AHC_TRANS_GOAL
)
2315 p
->transinfo
[tindex
].goal_width
= width
;
2316 if (type
& AHC_TRANS_USER
)
2317 p
->transinfo
[tindex
].user_width
= width
;
2319 if (p
->transinfo
[tindex
].goal_offset
)
2321 if (p
->features
& AHC_ULTRA2
)
2323 p
->transinfo
[tindex
].goal_offset
= MAX_OFFSET_ULTRA2
;
2325 else if (width
== MSG_EXT_WDTR_BUS_16_BIT
)
2327 p
->transinfo
[tindex
].goal_offset
= MAX_OFFSET_16BIT
;
2331 p
->transinfo
[tindex
].goal_offset
= MAX_OFFSET_8BIT
;
2336 /*+F*************************************************************************
2341 * SCB queue initialization.
2343 *-F*************************************************************************/
2345 scbq_init(volatile scb_queue_type
*queue
)
2351 /*+F*************************************************************************
2356 * Add an SCB to the head of the list.
2358 *-F*************************************************************************/
2360 scbq_insert_head(volatile scb_queue_type
*queue
, struct aic7xxx_scb
*scb
)
2362 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,1,95)
2363 unsigned long cpu_flags
;
2367 scb
->q_next
= queue
->head
;
2369 if (queue
->tail
== NULL
) /* If list was empty, update tail. */
2370 queue
->tail
= queue
->head
;
2374 /*+F*************************************************************************
2379 * Remove an SCB from the head of the list.
2381 *-F*************************************************************************/
2382 static inline struct aic7xxx_scb
*
2383 scbq_remove_head(volatile scb_queue_type
*queue
)
2385 struct aic7xxx_scb
* scbp
;
2386 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,1,95)
2387 unsigned long cpu_flags
;
2392 if (queue
->head
!= NULL
)
2393 queue
->head
= queue
->head
->q_next
;
2394 if (queue
->head
== NULL
) /* If list is now empty, update tail. */
2400 /*+F*************************************************************************
2405 * Removes an SCB from the list.
2407 *-F*************************************************************************/
2409 scbq_remove(volatile scb_queue_type
*queue
, struct aic7xxx_scb
*scb
)
2411 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,1,95)
2412 unsigned long cpu_flags
;
2416 if (queue
->head
== scb
)
2418 /* At beginning of queue, remove from head. */
2419 scbq_remove_head(queue
);
2423 struct aic7xxx_scb
*curscb
= queue
->head
;
2426 * Search until the next scb is the one we're looking for, or
2427 * we run out of queue.
2429 while ((curscb
!= NULL
) && (curscb
->q_next
!= scb
))
2431 curscb
= curscb
->q_next
;
2436 curscb
->q_next
= scb
->q_next
;
2437 if (scb
->q_next
== NULL
)
2439 /* Update the tail when removing the tail. */
2440 queue
->tail
= curscb
;
2447 /*+F*************************************************************************
2452 * Add an SCB at the tail of the list.
2454 *-F*************************************************************************/
2456 scbq_insert_tail(volatile scb_queue_type
*queue
, struct aic7xxx_scb
*scb
)
2458 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,1,95)
2459 unsigned long cpu_flags
;
2464 if (queue
->tail
!= NULL
) /* Add the scb at the end of the list. */
2465 queue
->tail
->q_next
= scb
;
2466 queue
->tail
= scb
; /* Update the tail. */
2467 if (queue
->head
== NULL
) /* If list was empty, update head. */
2468 queue
->head
= queue
->tail
;
2472 /*+F*************************************************************************
2477 * Checks to see if an scb matches the target/channel as specified.
2478 * If target is ALL_TARGETS (-1), then we're looking for any device
2479 * on the specified channel; this happens when a channel is going
2480 * to be reset and all devices on that channel must be aborted.
2481 *-F*************************************************************************/
2483 aic7xxx_match_scb(struct aic7xxx_host
*p
, struct aic7xxx_scb
*scb
,
2484 int target
, int channel
, int lun
, unsigned char tag
)
2486 int targ
= (scb
->hscb
->target_channel_lun
>> 4) & 0x0F;
2487 int chan
= (scb
->hscb
->target_channel_lun
>> 3) & 0x01;
2488 int slun
= scb
->hscb
->target_channel_lun
& 0x07;
2491 match
= ((chan
== channel
) || (channel
== ALL_CHANNELS
));
2493 match
= ((targ
== target
) || (target
== ALL_TARGETS
));
2495 match
= ((lun
== slun
) || (lun
== ALL_LUNS
));
2497 match
= ((tag
== scb
->hscb
->tag
) || (tag
== SCB_LIST_NULL
));
2502 /*+F*************************************************************************
2504 * aic7xxx_add_curscb_to_free_list
2507 * Adds the current scb (in SCBPTR) to the list of free SCBs.
2508 *-F*************************************************************************/
2510 aic7xxx_add_curscb_to_free_list(struct aic7xxx_host
*p
)
2513 * Invalidate the tag so that aic7xxx_find_scb doesn't think
2516 aic_outb(p
, SCB_LIST_NULL
, SCB_TAG
);
2517 aic_outb(p
, 0, SCB_CONTROL
);
2519 aic_outb(p
, aic_inb(p
, FREE_SCBH
), SCB_NEXT
);
2520 aic_outb(p
, aic_inb(p
, SCBPTR
), FREE_SCBH
);
2523 /*+F*************************************************************************
2525 * aic7xxx_rem_scb_from_disc_list
2528 * Removes the current SCB from the disconnected list and adds it
2530 *-F*************************************************************************/
2531 static unsigned char
2532 aic7xxx_rem_scb_from_disc_list(struct aic7xxx_host
*p
, unsigned char scbptr
,
2537 aic_outb(p
, scbptr
, SCBPTR
);
2538 next
= aic_inb(p
, SCB_NEXT
);
2539 aic7xxx_add_curscb_to_free_list(p
);
2541 if (prev
!= SCB_LIST_NULL
)
2543 aic_outb(p
, prev
, SCBPTR
);
2544 aic_outb(p
, next
, SCB_NEXT
);
2548 aic_outb(p
, next
, DISCONNECTED_SCBH
);
2554 /*+F*************************************************************************
2556 * aic7xxx_busy_target
2559 * Set the specified target busy.
2560 *-F*************************************************************************/
2562 aic7xxx_busy_target(struct aic7xxx_host
*p
, struct aic7xxx_scb
*scb
)
2564 p
->untagged_scbs
[scb
->hscb
->target_channel_lun
] = scb
->hscb
->tag
;
2567 /*+F*************************************************************************
2569 * aic7xxx_index_busy_target
2572 * Returns the index of the busy target, and optionally sets the
2574 *-F*************************************************************************/
2575 static inline unsigned char
2576 aic7xxx_index_busy_target(struct aic7xxx_host
*p
, unsigned char tcl
,
2579 unsigned char busy_scbid
;
2581 busy_scbid
= p
->untagged_scbs
[tcl
];
2584 p
->untagged_scbs
[tcl
] = SCB_LIST_NULL
;
2586 return (busy_scbid
);
2589 /*+F*************************************************************************
2594 * Look through the SCB array of the card and attempt to find the
2595 * hardware SCB that corresponds to the passed in SCB. Return
2596 * SCB_LIST_NULL if unsuccessful. This routine assumes that the
2597 * card is already paused.
2598 *-F*************************************************************************/
2599 static unsigned char
2600 aic7xxx_find_scb(struct aic7xxx_host
*p
, struct aic7xxx_scb
*scb
)
2602 unsigned char saved_scbptr
;
2603 unsigned char curindex
;
2605 saved_scbptr
= aic_inb(p
, SCBPTR
);
2607 for (curindex
= 0; curindex
< p
->scb_data
->maxhscbs
; curindex
++)
2609 aic_outb(p
, curindex
, SCBPTR
);
2610 if (aic_inb(p
, SCB_TAG
) == scb
->hscb
->tag
)
2615 aic_outb(p
, saved_scbptr
, SCBPTR
);
2616 if (curindex
>= p
->scb_data
->maxhscbs
)
2618 curindex
= SCB_LIST_NULL
;
2624 /*+F*************************************************************************
2626 * aic7xxx_allocate_scb
2629 * Get an SCB from the free list or by allocating a new one.
2630 *-F*************************************************************************/
2632 aic7xxx_allocate_scb(struct aic7xxx_host
*p
)
2634 struct aic7xxx_scb
*scbp
= NULL
;
2635 int scb_size
= (sizeof (struct hw_scatterlist
) * AIC7XXX_MAX_SG
) + 12 + 6;
2637 int step
= PAGE_SIZE
/ 1024;
2638 unsigned long scb_count
= 0;
2639 struct hw_scatterlist
*hsgp
;
2640 struct aic7xxx_scb
*scb_ap
;
2641 struct aic7xxx_scb_dma
*scb_dma
;
2642 unsigned char *bufs
;
2644 if (p
->scb_data
->numscbs
< p
->scb_data
->maxscbs
)
2647 * Calculate the optimal number of SCBs to allocate.
2649 * NOTE: This formula works because the sizeof(sg_array) is always
2650 * 1024. Therefore, scb_size * i would always be > PAGE_SIZE *
2651 * (i/step). The (i-1) allows the left hand side of the equation
2652 * to grow into the right hand side to a point of near perfect
2653 * efficiency since scb_size * (i -1) is growing slightly faster
2654 * than the right hand side. If the number of SG array elements
2655 * is changed, this function may not be near so efficient any more.
2657 * Since the DMA'able buffers are now allocated in a seperate
2658 * chunk this algorithm has been modified to match. The '12'
2659 * and '6' factors in scb_size are for the DMA'able command byte
2660 * and sensebuffers respectively. -DaveM
2662 for ( i
=step
;; i
*= 2 )
2664 if ( (scb_size
* (i
-1)) >= ( (PAGE_SIZE
* (i
/step
)) - 64 ) )
2670 scb_count
= MIN( (i
-1), p
->scb_data
->maxscbs
- p
->scb_data
->numscbs
);
2671 scb_ap
= (struct aic7xxx_scb
*)kmalloc(sizeof (struct aic7xxx_scb
) * scb_count
2672 + sizeof(struct aic7xxx_scb_dma
), GFP_ATOMIC
);
2675 scb_dma
= (struct aic7xxx_scb_dma
*)&scb_ap
[scb_count
];
2676 hsgp
= (struct hw_scatterlist
*)
2677 pci_alloc_consistent(p
->pdev
, scb_size
* scb_count
,
2678 &scb_dma
->dma_address
);
2684 bufs
= (unsigned char *)&hsgp
[scb_count
* AIC7XXX_MAX_SG
];
2685 #ifdef AIC7XXX_VERBOSE_DEBUGGING
2686 if (aic7xxx_verbose
> 0xffff)
2688 if (p
->scb_data
->numscbs
== 0)
2689 printk(INFO_LEAD
"Allocating initial %ld SCB structures.\n",
2690 p
->host_no
, -1, -1, -1, scb_count
);
2692 printk(INFO_LEAD
"Allocating %ld additional SCB structures.\n",
2693 p
->host_no
, -1, -1, -1, scb_count
);
2696 memset(scb_ap
, 0, sizeof (struct aic7xxx_scb
) * scb_count
);
2697 scb_dma
->dma_offset
= (unsigned long)scb_dma
->dma_address
2698 - (unsigned long)hsgp
;
2699 scb_dma
->dma_len
= scb_size
* scb_count
;
2700 for (i
=0; i
< scb_count
; i
++)
2703 scbp
->hscb
= &p
->scb_data
->hscbs
[p
->scb_data
->numscbs
];
2704 scbp
->sg_list
= &hsgp
[i
* AIC7XXX_MAX_SG
];
2705 scbp
->sense_cmd
= bufs
;
2706 scbp
->cmnd
= bufs
+ 6;
2708 scbp
->scb_dma
= scb_dma
;
2709 memset(scbp
->hscb
, 0, sizeof(struct aic7xxx_hwscb
));
2710 scbp
->hscb
->tag
= p
->scb_data
->numscbs
;
2712 * Place in the scb array; never is removed
2714 p
->scb_data
->scb_array
[p
->scb_data
->numscbs
++] = scbp
;
2715 scbq_insert_tail(&p
->scb_data
->free_scbs
, scbp
);
2717 scbp
->kmalloc_ptr
= scb_ap
;
2722 /*+F*************************************************************************
2724 * aic7xxx_queue_cmd_complete
2727 * Due to race conditions present in the SCSI subsystem, it is easier
2728 * to queue completed commands, then call scsi_done() on them when
2729 * we're finished. This function queues the completed commands.
2730 *-F*************************************************************************/
2732 aic7xxx_queue_cmd_complete(struct aic7xxx_host
*p
, Scsi_Cmnd
*cmd
)
2734 cmd
->host_scribble
= (char *)p
->completeq
.head
;
2735 p
->completeq
.head
= cmd
;
2738 /*+F*************************************************************************
2740 * aic7xxx_done_cmds_complete
2743 * Process the completed command queue.
2744 *-F*************************************************************************/
2746 aic7xxx_done_cmds_complete(struct aic7xxx_host
*p
)
2749 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,1,95)
2750 unsigned int cpu_flags
= 0;
2754 while (p
->completeq
.head
!= NULL
)
2756 cmd
= p
->completeq
.head
;
2757 p
->completeq
.head
= (Scsi_Cmnd
*)cmd
->host_scribble
;
2758 cmd
->host_scribble
= NULL
;
2759 cmd
->scsi_done(cmd
);
2764 /*+F*************************************************************************
2769 * Free the scb and insert into the free scb list.
2770 *-F*************************************************************************/
2772 aic7xxx_free_scb(struct aic7xxx_host
*p
, struct aic7xxx_scb
*scb
)
2775 scb
->flags
= SCB_FREE
;
2779 scb
->tag_action
= 0;
2780 scb
->hscb
->control
= 0;
2781 scb
->hscb
->target_status
= 0;
2782 scb
->hscb
->target_channel_lun
= SCB_LIST_NULL
;
2784 scbq_insert_head(&p
->scb_data
->free_scbs
, scb
);
2787 /*+F*************************************************************************
2792 * Calls the higher level scsi done function and frees the scb.
2793 *-F*************************************************************************/
2795 aic7xxx_done(struct aic7xxx_host
*p
, struct aic7xxx_scb
*scb
)
2797 Scsi_Cmnd
*cmd
= scb
->cmd
;
2798 int tindex
= TARGET_INDEX(cmd
);
2799 struct aic7xxx_scb
*scbp
;
2800 unsigned char queue_depth
;
2802 if (cmd
->use_sg
> 1)
2804 struct scatterlist
*sg
;
2806 sg
= (struct scatterlist
*)cmd
->request_buffer
;
2807 pci_unmap_sg(p
->pdev
, sg
, cmd
->use_sg
, scsi_to_pci_dma_dir(cmd
->sc_data_direction
));
2809 else if (cmd
->request_bufflen
)
2810 pci_unmap_single(p
->pdev
, aic7xxx_mapping(cmd
),
2811 cmd
->request_bufflen
,
2812 scsi_to_pci_dma_dir(cmd
->sc_data_direction
));
2813 if (scb
->flags
& SCB_SENSE
)
2815 pci_unmap_single(p
->pdev
,
2816 le32_to_cpu(scb
->sg_list
[0].address
),
2817 sizeof(cmd
->sense_buffer
),
2818 PCI_DMA_FROMDEVICE
);
2820 if (scb
->flags
& SCB_RECOVERY_SCB
)
2822 p
->flags
&= ~AHC_ABORT_PENDING
;
2824 if (scb
->flags
& SCB_RESET
)
2826 cmd
->result
= (DID_RESET
<< 16) | (cmd
->result
& 0xffff);
2828 else if (scb
->flags
& SCB_ABORT
)
2830 cmd
->result
= (DID_RESET
<< 16) | (cmd
->result
& 0xffff);
2832 else if (!(p
->dev_flags
[tindex
] & DEVICE_SCANNED
))
2834 if ( (cmd
->cmnd
[0] == INQUIRY
) && (cmd
->result
== DID_OK
) )
2838 p
->dev_flags
[tindex
] |= DEVICE_PRESENT
;
2841 struct scatterlist
*sg
;
2843 sg
= (struct scatterlist
*)cmd
->request_buffer
;
2844 buffer
= (char *)sg
[0].address
;
2848 buffer
= (char *)cmd
->request_buffer
;
2850 #define WIDE_INQUIRY_BITS 0x60
2851 #define SYNC_INQUIRY_BITS 0x10
2852 #define SCSI_VERSION_BITS 0x07
2853 #define SCSI_DT_BIT 0x04
2854 if ( (buffer
[7] & WIDE_INQUIRY_BITS
) &&
2855 (p
->features
& AHC_WIDE
) )
2857 p
->needwdtr
|= (1<<tindex
);
2858 p
->needwdtr_copy
|= (1<<tindex
);
2859 p
->transinfo
[tindex
].goal_width
= p
->transinfo
[tindex
].user_width
;
2863 p
->needwdtr
&= ~(1<<tindex
);
2864 p
->needwdtr_copy
&= ~(1<<tindex
);
2866 aic7xxx_set_width(p
, cmd
->target
, cmd
->channel
, cmd
->lun
,
2867 MSG_EXT_WDTR_BUS_8_BIT
, (AHC_TRANS_ACTIVE
|
2870 unpause_sequencer(p
, FALSE
);
2872 if ( (buffer
[7] & SYNC_INQUIRY_BITS
) &&
2873 p
->transinfo
[tindex
].user_offset
)
2875 p
->transinfo
[tindex
].goal_period
= p
->transinfo
[tindex
].user_period
;
2876 p
->transinfo
[tindex
].goal_options
= p
->transinfo
[tindex
].user_options
;
2877 if (p
->features
& AHC_ULTRA2
)
2878 p
->transinfo
[tindex
].goal_offset
= MAX_OFFSET_ULTRA2
;
2879 else if (p
->transinfo
[tindex
].goal_width
== MSG_EXT_WDTR_BUS_16_BIT
)
2880 p
->transinfo
[tindex
].goal_offset
= MAX_OFFSET_16BIT
;
2882 p
->transinfo
[tindex
].goal_offset
= MAX_OFFSET_8BIT
;
2883 if ( (((buffer
[2] & SCSI_VERSION_BITS
) == 3) ||
2884 (buffer
[56] & SCSI_DT_BIT
) ||
2885 (p
->dev_flags
[tindex
] & DEVICE_SCSI_3
) ) &&
2886 (p
->transinfo
[tindex
].user_period
<= 9) &&
2887 (p
->transinfo
[tindex
].user_options
) )
2889 p
->needppr
|= (1<<tindex
);
2890 p
->needppr_copy
|= (1<<tindex
);
2891 p
->needsdtr
&= ~(1<<tindex
);
2892 p
->needsdtr_copy
&= ~(1<<tindex
);
2893 p
->needwdtr
&= ~(1<<tindex
);
2894 p
->needwdtr_copy
&= ~(1<<tindex
);
2895 p
->dev_flags
[tindex
] |= DEVICE_SCSI_3
;
2899 p
->needsdtr
|= (1<<tindex
);
2900 p
->needsdtr_copy
|= (1<<tindex
);
2901 p
->transinfo
[tindex
].goal_period
=
2902 MAX(10, p
->transinfo
[tindex
].goal_period
);
2903 p
->transinfo
[tindex
].goal_options
= 0;
2908 p
->needsdtr
&= ~(1<<tindex
);
2909 p
->needsdtr_copy
&= ~(1<<tindex
);
2910 p
->transinfo
[tindex
].goal_period
= 255;
2911 p
->transinfo
[tindex
].goal_offset
= 0;
2912 p
->transinfo
[tindex
].goal_options
= 0;
2915 * This is needed to work around a sequencer bug for now. Regardless
2916 * of the controller in use, if we have a Quantum drive, we need to
2917 * limit the speed to 80MByte/sec. As soon as I get a fixed version
2918 * of the sequencer, this code will get yanked.
2920 if(!strncmp(buffer
+ 8, "QUANTUM", 7) &&
2921 p
->transinfo
[tindex
].goal_options
)
2923 p
->transinfo
[tindex
].goal_period
=
2924 MAX(p
->transinfo
[tindex
].goal_period
, 10);
2925 p
->transinfo
[tindex
].goal_options
= 0;
2926 p
->needppr
&= ~(1<<tindex
);
2927 p
->needppr_copy
&= ~(1<<tindex
);
2928 p
->needsdtr
|= (1<<tindex
);
2929 p
->needsdtr_copy
|= (1<<tindex
);
2930 p
->needwdtr
|= (1<<tindex
);
2931 p
->needwdtr_copy
|= (1<<tindex
);
2934 * Get the INQUIRY checksum. We use this on Ultra 160/m
2935 * and older devices both. It allows us to drop speed on any bus type
2936 * while at the same time giving us the needed domain validation for
2939 * Note: We only get the checksum and set the SCANNED bit if this is
2940 * one of our dtr commands. If we don't do this, then we end up
2941 * getting bad checksum results on the mid-level SCSI code's INQUIRY
2944 if(p
->dev_dtr_cmnd
[tindex
] == cmd
) {
2945 unsigned int checksum
= 0;
2949 ibuffer
= (int *)buffer
;
2950 for( i
= 0; i
< (cmd
->request_bufflen
>> 2); i
++)
2952 checksum
+= ibuffer
[i
];
2954 p
->dev_checksum
[tindex
] = checksum
;
2955 p
->dev_flags
[tindex
] |= DEVICE_SCANNED
;
2956 p
->dev_flags
[tindex
] |= DEVICE_PRINT_DTR
;
2958 #undef WIDE_INQUIRY_BITS
2959 #undef SYNC_INQUIRY_BITS
2960 #undef SCSI_VERSION_BITS
2964 else if ((scb
->flags
& SCB_MSGOUT_BITS
) != 0)
2966 unsigned short mask
;
2967 int message_error
= FALSE
;
2969 mask
= 0x01 << tindex
;
2972 * Check to see if we get an invalid message or a message error
2973 * after failing to negotiate a wide or sync transfer message.
2975 if ((scb
->flags
& SCB_SENSE
) &&
2976 ((scb
->cmd
->sense_buffer
[12] == 0x43) || /* INVALID_MESSAGE */
2977 (scb
->cmd
->sense_buffer
[12] == 0x49))) /* MESSAGE_ERROR */
2979 message_error
= TRUE
;
2982 if (scb
->flags
& SCB_MSGOUT_WDTR
)
2984 p
->dtr_pending
&= ~mask
;
2987 if ( (aic7xxx_verbose
& VERBOSE_NEGOTIATION2
) &&
2988 (p
->dev_flags
[tindex
] & DEVICE_PRINT_DTR
) )
2990 printk(INFO_LEAD
"Device failed to complete Wide Negotiation "
2991 "processing and\n", p
->host_no
, CTL_OF_SCB(scb
));
2992 printk(INFO_LEAD
"returned a sense error code for invalid message, "
2993 "disabling future\n", p
->host_no
, CTL_OF_SCB(scb
));
2994 printk(INFO_LEAD
"Wide negotiation to this device.\n", p
->host_no
,
2997 p
->needwdtr
&= ~mask
;
2998 p
->needwdtr_copy
&= ~mask
;
3001 if (scb
->flags
& SCB_MSGOUT_SDTR
)
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 Sync 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
"Sync negotiation to this device.\n", p
->host_no
,
3015 p
->dev_flags
[tindex
] &= ~DEVICE_PRINT_DTR
;
3017 p
->needsdtr
&= ~mask
;
3018 p
->needsdtr_copy
&= ~mask
;
3021 if (scb
->flags
& SCB_MSGOUT_PPR
)
3023 p
->dtr_pending
&= ~mask
;
3026 if ( (aic7xxx_verbose
& VERBOSE_NEGOTIATION2
) &&
3027 (p
->dev_flags
[tindex
] & DEVICE_PRINT_DTR
) )
3029 printk(INFO_LEAD
"Device failed to complete Parallel Protocol "
3030 "Request processing and\n", p
->host_no
, CTL_OF_SCB(scb
));
3031 printk(INFO_LEAD
"returned a sense error code for invalid message, "
3032 "disabling future\n", p
->host_no
, CTL_OF_SCB(scb
));
3033 printk(INFO_LEAD
"Parallel Protocol Request negotiation to this "
3034 "device.\n", p
->host_no
, CTL_OF_SCB(scb
));
3037 * Disable PPR negotiation and revert back to WDTR and SDTR setup
3039 p
->needppr
&= ~mask
;
3040 p
->needppr_copy
&= ~mask
;
3041 p
->needsdtr
|= mask
;
3042 p
->needsdtr_copy
|= mask
;
3043 p
->needwdtr
|= mask
;
3044 p
->needwdtr_copy
|= mask
;
3048 queue_depth
= p
->dev_temp_queue_depth
[tindex
];
3049 if (queue_depth
>= p
->dev_active_cmds
[tindex
])
3051 scbp
= scbq_remove_head(&p
->delayed_scbs
[tindex
]);
3054 if (queue_depth
== 1)
3057 * Give extra preference to untagged devices, such as CD-R devices
3058 * This makes it more likely that a drive *won't* stuff up while
3059 * waiting on data at a critical time, such as CD-R writing and
3060 * audio CD ripping operations. Should also benefit tape drives.
3062 scbq_insert_head(&p
->waiting_scbs
, scbp
);
3066 scbq_insert_tail(&p
->waiting_scbs
, scbp
);
3068 #ifdef AIC7XXX_VERBOSE_DEBUGGING
3069 if (aic7xxx_verbose
> 0xffff)
3070 printk(INFO_LEAD
"Moving SCB from delayed to waiting queue.\n",
3071 p
->host_no
, CTL_OF_SCB(scbp
));
3073 if (queue_depth
> p
->dev_active_cmds
[tindex
])
3075 scbp
= scbq_remove_head(&p
->delayed_scbs
[tindex
]);
3077 scbq_insert_tail(&p
->waiting_scbs
, scbp
);
3081 if ( !(scb
->tag_action
) && (p
->tagenable
& (1<<tindex
)) )
3083 p
->dev_temp_queue_depth
[tindex
] = p
->dev_max_queue_depth
[tindex
];
3085 p
->dev_active_cmds
[tindex
]--;
3092 * XXX: we should actually know how much actually transferred
3093 * XXX: for each command, but apparently that's too difficult.
3095 * We set a lower limit of 512 bytes on the transfer length. We
3096 * ignore anything less than this because we don't have a real
3097 * reason to count it. Read/Writes to tapes are usually about 20K
3098 * and disks are a minimum of 512 bytes unless you want to count
3099 * non-read/write commands (such as TEST_UNIT_READY) which we don't
3101 actual
= scb
->sg_length
;
3102 if ((actual
>= 512) && (((cmd
->result
>> 16) & 0xf) == DID_OK
))
3104 struct aic7xxx_xferstats
*sp
;
3105 #ifdef AIC7XXX_PROC_STATS
3108 #endif /* AIC7XXX_PROC_STATS */
3110 sp
= &p
->stats
[TARGET_INDEX(cmd
)];
3113 * For block devices, cmd->request.cmd is always == either READ or
3114 * WRITE. For character devices, this isn't always set properly, so
3115 * we check data_cmnd[0]. This catches the conditions for st.c, but
3116 * I'm still not sure if request.cmd is valid for sg devices.
3118 if ( (cmd
->request
.cmd
== WRITE
) || (cmd
->data_cmnd
[0] == WRITE_6
) ||
3119 (cmd
->data_cmnd
[0] == WRITE_FILEMARKS
) )
3122 #ifdef AIC7XXX_VERBOSE_DEBUGGING
3123 if ( (sp
->w_total
> 16) && (aic7xxx_verbose
> 0xffff) )
3124 aic7xxx_verbose
&= 0xffff;
3126 #ifdef AIC7XXX_PROC_STATS
3128 #endif /* AIC7XXX_PROC_STATS */
3133 #ifdef AIC7XXX_VERBOSE_DEBUGGING
3134 if ( (sp
->r_total
> 16) && (aic7xxx_verbose
> 0xffff) )
3135 aic7xxx_verbose
&= 0xffff;
3137 #ifdef AIC7XXX_PROC_STATS
3139 #endif /* AIC7XXX_PROC_STATS */
3141 #ifdef AIC7XXX_PROC_STATS
3160 #endif /* AIC7XXX_PROC_STATS */
3163 aic7xxx_free_scb(p
, scb
);
3164 aic7xxx_queue_cmd_complete(p
, cmd
);
3168 /*+F*************************************************************************
3170 * aic7xxx_run_done_queue
3173 * Calls the aic7xxx_done() for the Scsi_Cmnd of each scb in the
3174 * aborted list, and adds each scb to the free list. If complete
3175 * is TRUE, we also process the commands complete list.
3176 *-F*************************************************************************/
3178 aic7xxx_run_done_queue(struct aic7xxx_host
*p
, /*complete*/ int complete
)
3180 struct aic7xxx_scb
*scb
;
3183 for (i
= 0; i
< p
->scb_data
->numscbs
; i
++)
3185 scb
= p
->scb_data
->scb_array
[i
];
3186 if (scb
->flags
& SCB_QUEUED_FOR_DONE
)
3188 if (aic7xxx_verbose
& (VERBOSE_ABORT_PROCESS
| VERBOSE_RESET_PROCESS
))
3189 printk(INFO_LEAD
"Aborting scb %d\n",
3190 p
->host_no
, CTL_OF_SCB(scb
), scb
->hscb
->tag
);
3192 aic7xxx_done(p
, scb
);
3195 if (aic7xxx_verbose
& (VERBOSE_ABORT_RETURN
| VERBOSE_RESET_RETURN
))
3197 printk(INFO_LEAD
"%d commands found and queued for "
3198 "completion.\n", p
->host_no
, -1, -1, -1, found
);
3202 aic7xxx_done_cmds_complete(p
);
3206 /*+F*************************************************************************
3208 * aic7xxx_abort_waiting_scb
3211 * Manipulate the waiting for selection list and return the
3212 * scb that follows the one that we remove.
3213 *-F*************************************************************************/
3214 static unsigned char
3215 aic7xxx_abort_waiting_scb(struct aic7xxx_host
*p
, struct aic7xxx_scb
*scb
,
3216 unsigned char scbpos
, unsigned char prev
)
3218 unsigned char curscb
, next
;
3221 * Select the SCB we want to abort and pull the next pointer out of it.
3223 curscb
= aic_inb(p
, SCBPTR
);
3224 aic_outb(p
, scbpos
, SCBPTR
);
3225 next
= aic_inb(p
, SCB_NEXT
);
3227 aic7xxx_add_curscb_to_free_list(p
);
3230 * Update the waiting list
3232 if (prev
== SCB_LIST_NULL
)
3237 aic_outb(p
, next
, WAITING_SCBH
);
3242 * Select the scb that pointed to us and update its next pointer.
3244 aic_outb(p
, prev
, SCBPTR
);
3245 aic_outb(p
, next
, SCB_NEXT
);
3248 * Point us back at the original scb position and inform the SCSI
3249 * system that the command has been aborted.
3251 aic_outb(p
, curscb
, SCBPTR
);
3255 /*+F*************************************************************************
3257 * aic7xxx_search_qinfifo
3260 * Search the queue-in FIFO for matching SCBs and conditionally
3261 * requeue. Returns the number of matching SCBs.
3262 *-F*************************************************************************/
3264 aic7xxx_search_qinfifo(struct aic7xxx_host
*p
, int target
, int channel
,
3265 int lun
, unsigned char tag
, int flags
, int requeue
,
3266 volatile scb_queue_type
*queue
)
3269 unsigned char qinpos
, qintail
;
3270 struct aic7xxx_scb
*scbp
;
3273 qinpos
= aic_inb(p
, QINPOS
);
3274 qintail
= p
->qinfifonext
;
3276 p
->qinfifonext
= qinpos
;
3278 while (qinpos
!= qintail
)
3280 scbp
= p
->scb_data
->scb_array
[p
->qinfifo
[qinpos
++]];
3281 if (aic7xxx_match_scb(p
, scbp
, target
, channel
, lun
, tag
))
3284 * We found an scb that needs to be removed.
3286 if (requeue
&& (queue
!= NULL
))
3288 if (scbp
->flags
& SCB_WAITINGQ
)
3290 scbq_remove(queue
, scbp
);
3291 scbq_remove(&p
->waiting_scbs
, scbp
);
3292 scbq_remove(&p
->delayed_scbs
[TARGET_INDEX(scbp
->cmd
)], scbp
);
3293 p
->dev_active_cmds
[TARGET_INDEX(scbp
->cmd
)]++;
3296 scbq_insert_tail(queue
, scbp
);
3297 p
->dev_active_cmds
[TARGET_INDEX(scbp
->cmd
)]--;
3299 scbp
->flags
|= SCB_WAITINGQ
;
3300 if ( !(scbp
->tag_action
& TAG_ENB
) )
3302 aic7xxx_index_busy_target(p
, scbp
->hscb
->target_channel_lun
,
3308 p
->qinfifo
[p
->qinfifonext
++] = scbp
->hscb
->tag
;
3313 * Preserve any SCB_RECOVERY_SCB flags on this scb then set the
3314 * flags we were called with, presumeably so aic7xxx_run_done_queue
3317 scbp
->flags
= flags
| (scbp
->flags
& SCB_RECOVERY_SCB
);
3318 if (aic7xxx_index_busy_target(p
, scbp
->hscb
->target_channel_lun
,
3319 FALSE
) == scbp
->hscb
->tag
)
3321 aic7xxx_index_busy_target(p
, scbp
->hscb
->target_channel_lun
,
3329 p
->qinfifo
[p
->qinfifonext
++] = scbp
->hscb
->tag
;
3333 * Now that we've done the work, clear out any left over commands in the
3334 * qinfifo and update the KERNEL_QINPOS down on the card.
3336 * NOTE: This routine expect the sequencer to already be paused when
3337 * it is run....make sure it's that way!
3339 qinpos
= p
->qinfifonext
;
3340 while(qinpos
!= qintail
)
3342 p
->qinfifo
[qinpos
++] = SCB_LIST_NULL
;
3344 if (p
->features
& AHC_QUEUE_REGS
)
3345 aic_outb(p
, p
->qinfifonext
, HNSCB_QOFF
);
3347 aic_outb(p
, p
->qinfifonext
, KERNEL_QINPOS
);
3352 /*+F*************************************************************************
3354 * aic7xxx_scb_on_qoutfifo
3357 * Is the scb that was passed to us currently on the qoutfifo?
3358 *-F*************************************************************************/
3360 aic7xxx_scb_on_qoutfifo(struct aic7xxx_host
*p
, struct aic7xxx_scb
*scb
)
3364 while(p
->qoutfifo
[(p
->qoutfifonext
+ i
) & 0xff ] != SCB_LIST_NULL
)
3366 if(p
->qoutfifo
[(p
->qoutfifonext
+ i
) & 0xff ] == scb
->hscb
->tag
)
3375 /*+F*************************************************************************
3377 * aic7xxx_reset_device
3380 * The device at the given target/channel has been reset. Abort
3381 * all active and queued scbs for that target/channel. This function
3382 * need not worry about linked next pointers because if was a MSG_ABORT_TAG
3383 * then we had a tagged command (no linked next), if it was MSG_ABORT or
3384 * MSG_BUS_DEV_RESET then the device won't know about any commands any more
3385 * and no busy commands will exist, and if it was a bus reset, then nothing
3386 * knows about any linked next commands any more. In all cases, we don't
3387 * need to worry about the linked next or busy scb, we just need to clear
3389 *-F*************************************************************************/
3391 aic7xxx_reset_device(struct aic7xxx_host
*p
, int target
, int channel
,
3392 int lun
, unsigned char tag
)
3394 struct aic7xxx_scb
*scbp
;
3395 unsigned char active_scb
, tcl
;
3396 int i
= 0, j
, init_lists
= FALSE
;
3399 * Restore this when we're done
3401 active_scb
= aic_inb(p
, SCBPTR
);
3403 if (aic7xxx_verbose
& (VERBOSE_RESET_PROCESS
| VERBOSE_ABORT_PROCESS
))
3404 printk(INFO_LEAD
"Reset device, active_scb %d\n",
3405 p
->host_no
, channel
, target
, lun
, active_scb
);
3407 * Deal with the busy target and linked next issues.
3410 int min_target
, max_target
;
3411 struct aic7xxx_scb
*scbp
, *prev_scbp
;
3413 /* Make all targets 'relative' to bus A. */
3414 if (target
== ALL_TARGETS
)
3420 max_target
= (p
->features
& AHC_WIDE
) ? 15 : 7;
3429 max_target
= (p
->features
& (AHC_TWIN
|AHC_WIDE
)) ? 15 : 7;
3435 min_target
= target
| (channel
<< 3);
3436 max_target
= min_target
;
3440 for (i
= min_target
; i
<= max_target
; i
++)
3442 if ( i
== p
->scsi_id
)
3446 if (aic7xxx_verbose
& (VERBOSE_ABORT_PROCESS
| VERBOSE_RESET_PROCESS
))
3447 printk(INFO_LEAD
"Cleaning up status information "
3448 "and delayed_scbs.\n", p
->host_no
, channel
, i
, lun
);
3449 p
->dev_flags
[i
] &= ~(BUS_DEVICE_RESET_PENDING
| DEVICE_PARITY_ERROR
);
3450 if ( tag
== SCB_LIST_NULL
)
3452 p
->dev_flags
[i
] |= DEVICE_PRINT_DTR
| DEVICE_RESET_DELAY
;
3453 p
->dev_expires
[i
] = jiffies
+ (4 * HZ
);
3454 p
->dev_timer_active
|= (0x01 << i
);
3455 p
->dev_last_queue_full_count
[i
] = 0;
3456 p
->dev_last_queue_full
[i
] = 0;
3457 p
->dev_temp_queue_depth
[i
] =
3458 p
->dev_max_queue_depth
[i
];
3460 for(j
=0; j
<MAX_LUNS
; j
++)
3463 tcl
= ((i
<< 4) & 0x70) | (channel
<< 3) | j
;
3465 tcl
= (i
<< 4) | (channel
<< 3) | j
;
3466 if ( (aic7xxx_index_busy_target(p
, tcl
, FALSE
) == tag
) ||
3467 (tag
== SCB_LIST_NULL
) )
3468 aic7xxx_index_busy_target(p
, tcl
, /* unbusy */ TRUE
);
3472 scbp
= p
->delayed_scbs
[i
].head
;
3473 while ( (scbp
!= NULL
) && (j
++ <= (p
->scb_data
->numscbs
+ 1)) )
3476 scbp
= scbp
->q_next
;
3477 if ( prev_scbp
== scbp
)
3479 if (aic7xxx_verbose
& (VERBOSE_ABORT
| VERBOSE_RESET
))
3480 printk(WARN_LEAD
"Yikes!! scb->q_next == scb "
3481 "in the delayed_scbs queue!\n", p
->host_no
, channel
, i
, lun
);
3483 prev_scbp
->q_next
= NULL
;
3484 p
->delayed_scbs
[i
].tail
= prev_scbp
;
3486 if (aic7xxx_match_scb(p
, prev_scbp
, target
, channel
, lun
, tag
))
3488 scbq_remove(&p
->delayed_scbs
[i
], prev_scbp
);
3489 if (prev_scbp
->flags
& SCB_WAITINGQ
)
3491 p
->dev_active_cmds
[i
]++;
3494 prev_scbp
->flags
&= ~(SCB_ACTIVE
| SCB_WAITINGQ
);
3495 prev_scbp
->flags
|= SCB_RESET
| SCB_QUEUED_FOR_DONE
;
3498 if ( j
> (p
->scb_data
->maxscbs
+ 1) )
3500 if (aic7xxx_verbose
& (VERBOSE_ABORT
| VERBOSE_RESET
))
3501 printk(WARN_LEAD
"Yikes!! There's a loop in the "
3502 "delayed_scbs queue!\n", p
->host_no
, channel
, i
, lun
);
3503 scbq_init(&p
->delayed_scbs
[i
]);
3505 if ( !(p
->dev_timer_active
& (0x01 << MAX_TARGETS
)) ||
3506 time_after_eq(p
->dev_timer
.expires
, p
->dev_expires
[i
]) )
3508 mod_timer(&p
->dev_timer
, p
->dev_expires
[i
]);
3509 p
->dev_timer_active
|= (0x01 << MAX_TARGETS
);
3514 if (aic7xxx_verbose
& (VERBOSE_ABORT_PROCESS
| VERBOSE_RESET_PROCESS
))
3515 printk(INFO_LEAD
"Cleaning QINFIFO.\n", p
->host_no
, channel
, target
, lun
);
3516 aic7xxx_search_qinfifo(p
, target
, channel
, lun
, tag
,
3517 SCB_RESET
| SCB_QUEUED_FOR_DONE
, /* requeue */ FALSE
, NULL
);
3520 * Search the waiting_scbs queue for matches, this catches any SCB_QUEUED
3521 * ABORT/RESET commands.
3523 if (aic7xxx_verbose
& (VERBOSE_ABORT_PROCESS
| VERBOSE_RESET_PROCESS
))
3524 printk(INFO_LEAD
"Cleaning waiting_scbs.\n", p
->host_no
, channel
,
3527 struct aic7xxx_scb
*scbp
, *prev_scbp
;
3531 scbp
= p
->waiting_scbs
.head
;
3532 while ( (scbp
!= NULL
) && (j
++ <= (p
->scb_data
->numscbs
+ 1)) )
3535 scbp
= scbp
->q_next
;
3536 if ( prev_scbp
== scbp
)
3538 if (aic7xxx_verbose
& (VERBOSE_ABORT
| VERBOSE_RESET
))
3539 printk(WARN_LEAD
"Yikes!! scb->q_next == scb "
3540 "in the waiting_scbs queue!\n", p
->host_no
, CTL_OF_SCB(scbp
));
3542 prev_scbp
->q_next
= NULL
;
3543 p
->waiting_scbs
.tail
= prev_scbp
;
3545 if (aic7xxx_match_scb(p
, prev_scbp
, target
, channel
, lun
, tag
))
3547 scbq_remove(&p
->waiting_scbs
, prev_scbp
);
3548 if (prev_scbp
->flags
& SCB_WAITINGQ
)
3550 p
->dev_active_cmds
[TARGET_INDEX(prev_scbp
->cmd
)]++;
3553 prev_scbp
->flags
&= ~(SCB_ACTIVE
| SCB_WAITINGQ
);
3554 prev_scbp
->flags
|= SCB_RESET
| SCB_QUEUED_FOR_DONE
;
3557 if ( j
> (p
->scb_data
->maxscbs
+ 1) )
3559 if (aic7xxx_verbose
& (VERBOSE_ABORT
| VERBOSE_RESET
))
3560 printk(WARN_LEAD
"Yikes!! There's a loop in the "
3561 "waiting_scbs queue!\n", p
->host_no
, channel
, target
, lun
);
3562 scbq_init(&p
->waiting_scbs
);
3568 * Search waiting for selection list.
3570 if (aic7xxx_verbose
& (VERBOSE_ABORT_PROCESS
| VERBOSE_RESET_PROCESS
))
3571 printk(INFO_LEAD
"Cleaning waiting for selection "
3572 "list.\n", p
->host_no
, channel
, target
, lun
);
3574 unsigned char next
, prev
, scb_index
;
3576 next
= aic_inb(p
, WAITING_SCBH
); /* Start at head of list. */
3577 prev
= SCB_LIST_NULL
;
3579 while ( (next
!= SCB_LIST_NULL
) && (j
++ <= (p
->scb_data
->maxscbs
+ 1)) )
3581 aic_outb(p
, next
, SCBPTR
);
3582 scb_index
= aic_inb(p
, SCB_TAG
);
3583 if (scb_index
>= p
->scb_data
->numscbs
)
3586 * No aic7xxx_verbose check here.....we want to see this since it
3587 * means either the kernel driver or the sequencer screwed things up
3589 printk(WARN_LEAD
"Waiting List inconsistency; SCB index=%d, "
3590 "numscbs=%d\n", p
->host_no
, channel
, target
, lun
, scb_index
,
3591 p
->scb_data
->numscbs
);
3592 next
= aic_inb(p
, SCB_NEXT
);
3593 aic7xxx_add_curscb_to_free_list(p
);
3597 scbp
= p
->scb_data
->scb_array
[scb_index
];
3598 if (aic7xxx_match_scb(p
, scbp
, target
, channel
, lun
, tag
))
3600 next
= aic7xxx_abort_waiting_scb(p
, scbp
, next
, prev
);
3601 if (scbp
->flags
& SCB_WAITINGQ
)
3603 p
->dev_active_cmds
[TARGET_INDEX(scbp
->cmd
)]++;
3606 scbp
->flags
&= ~(SCB_ACTIVE
| SCB_WAITINGQ
);
3607 scbp
->flags
|= SCB_RESET
| SCB_QUEUED_FOR_DONE
;
3608 if (prev
== SCB_LIST_NULL
)
3611 * This is either the first scb on the waiting list, or we
3612 * have already yanked the first and haven't left any behind.
3613 * Either way, we need to turn off the selection hardware if
3614 * it isn't already off.
3616 aic_outb(p
, aic_inb(p
, SCSISEQ
) & ~ENSELO
, SCSISEQ
);
3617 aic_outb(p
, CLRSELTIMEO
, CLRSINT1
);
3623 next
= aic_inb(p
, SCB_NEXT
);
3627 if ( j
> (p
->scb_data
->maxscbs
+ 1) )
3629 printk(WARN_LEAD
"Yikes!! There is a loop in the waiting for "
3630 "selection list!\n", p
->host_no
, channel
, target
, lun
);
3636 * Go through disconnected list and remove any entries we have queued
3637 * for completion, zeroing their control byte too.
3639 if (aic7xxx_verbose
& (VERBOSE_ABORT_PROCESS
| VERBOSE_RESET_PROCESS
))
3640 printk(INFO_LEAD
"Cleaning disconnected scbs "
3641 "list.\n", p
->host_no
, channel
, target
, lun
);
3642 if (p
->flags
& AHC_PAGESCBS
)
3644 unsigned char next
, prev
, scb_index
;
3646 next
= aic_inb(p
, DISCONNECTED_SCBH
);
3647 prev
= SCB_LIST_NULL
;
3649 while ( (next
!= SCB_LIST_NULL
) && (j
++ <= (p
->scb_data
->maxscbs
+ 1)) )
3651 aic_outb(p
, next
, SCBPTR
);
3652 scb_index
= aic_inb(p
, SCB_TAG
);
3653 if (scb_index
> p
->scb_data
->numscbs
)
3655 printk(WARN_LEAD
"Disconnected List inconsistency; SCB index=%d, "
3656 "numscbs=%d\n", p
->host_no
, channel
, target
, lun
, scb_index
,
3657 p
->scb_data
->numscbs
);
3658 next
= aic7xxx_rem_scb_from_disc_list(p
, next
, prev
);
3662 scbp
= p
->scb_data
->scb_array
[scb_index
];
3663 if (aic7xxx_match_scb(p
, scbp
, target
, channel
, lun
, tag
))
3665 next
= aic7xxx_rem_scb_from_disc_list(p
, next
, prev
);
3666 if (scbp
->flags
& SCB_WAITINGQ
)
3668 p
->dev_active_cmds
[TARGET_INDEX(scbp
->cmd
)]++;
3671 scbp
->flags
&= ~(SCB_ACTIVE
| SCB_WAITINGQ
);
3672 scbp
->flags
|= SCB_RESET
| SCB_QUEUED_FOR_DONE
;
3673 scbp
->hscb
->control
= 0;
3678 next
= aic_inb(p
, SCB_NEXT
);
3682 if ( j
> (p
->scb_data
->maxscbs
+ 1) )
3684 printk(WARN_LEAD
"Yikes!! There is a loop in the disconnected list!\n",
3685 p
->host_no
, channel
, target
, lun
);
3691 * Walk the free list making sure no entries on the free list have
3692 * a valid SCB_TAG value or SCB_CONTROL byte.
3694 if (p
->flags
& AHC_PAGESCBS
)
3699 next
= aic_inb(p
, FREE_SCBH
);
3700 if ( (next
>= p
->scb_data
->maxhscbs
) && (next
!= SCB_LIST_NULL
) )
3702 printk(WARN_LEAD
"Bogus FREE_SCBH!.\n", p
->host_no
, channel
,
3705 next
= SCB_LIST_NULL
;
3707 while ( (next
!= SCB_LIST_NULL
) && (j
++ <= (p
->scb_data
->maxscbs
+ 1)) )
3709 aic_outb(p
, next
, SCBPTR
);
3710 if (aic_inb(p
, SCB_TAG
) < p
->scb_data
->numscbs
)
3712 printk(WARN_LEAD
"Free list inconsistency!.\n", p
->host_no
, channel
,
3715 next
= SCB_LIST_NULL
;
3719 aic_outb(p
, SCB_LIST_NULL
, SCB_TAG
);
3720 aic_outb(p
, 0, SCB_CONTROL
);
3721 next
= aic_inb(p
, SCB_NEXT
);
3724 if ( j
> (p
->scb_data
->maxscbs
+ 1) )
3726 printk(WARN_LEAD
"Yikes!! There is a loop in the free list!\n",
3727 p
->host_no
, channel
, target
, lun
);
3733 * Go through the hardware SCB array looking for commands that
3734 * were active but not on any list.
3738 aic_outb(p
, SCB_LIST_NULL
, FREE_SCBH
);
3739 aic_outb(p
, SCB_LIST_NULL
, WAITING_SCBH
);
3740 aic_outb(p
, SCB_LIST_NULL
, DISCONNECTED_SCBH
);
3742 for (i
= p
->scb_data
->maxhscbs
- 1; i
>= 0; i
--)
3744 unsigned char scbid
;
3746 aic_outb(p
, i
, SCBPTR
);
3749 aic_outb(p
, SCB_LIST_NULL
, SCB_TAG
);
3750 aic_outb(p
, SCB_LIST_NULL
, SCB_NEXT
);
3751 aic_outb(p
, 0, SCB_CONTROL
);
3752 aic7xxx_add_curscb_to_free_list(p
);
3756 scbid
= aic_inb(p
, SCB_TAG
);
3757 if (scbid
< p
->scb_data
->numscbs
)
3759 scbp
= p
->scb_data
->scb_array
[scbid
];
3760 if (aic7xxx_match_scb(p
, scbp
, target
, channel
, lun
, tag
))
3762 aic_outb(p
, 0, SCB_CONTROL
);
3763 aic_outb(p
, SCB_LIST_NULL
, SCB_TAG
);
3764 aic7xxx_add_curscb_to_free_list(p
);
3771 * Go through the entire SCB array now and look for commands for
3772 * for this target that are stillactive. These are other (most likely
3773 * tagged) commands that were disconnected when the reset occurred.
3774 * Any commands we find here we know this about, it wasn't on any queue,
3775 * it wasn't in the qinfifo, it wasn't in the disconnected or waiting
3776 * lists, so it really must have been a paged out SCB. In that case,
3777 * we shouldn't need to bother with updating any counters, just mark
3778 * the correct flags and go on.
3780 for (i
= 0; i
< p
->scb_data
->numscbs
; i
++)
3782 scbp
= p
->scb_data
->scb_array
[i
];
3783 if ((scbp
->flags
& SCB_ACTIVE
) &&
3784 aic7xxx_match_scb(p
, scbp
, target
, channel
, lun
, tag
) &&
3785 !aic7xxx_scb_on_qoutfifo(p
, scbp
))
3787 if (scbp
->flags
& SCB_WAITINGQ
)
3789 scbq_remove(&p
->waiting_scbs
, scbp
);
3790 scbq_remove(&p
->delayed_scbs
[TARGET_INDEX(scbp
->cmd
)], scbp
);
3791 p
->dev_active_cmds
[TARGET_INDEX(scbp
->cmd
)]++;
3794 scbp
->flags
|= SCB_RESET
| SCB_QUEUED_FOR_DONE
;
3795 scbp
->flags
&= ~(SCB_ACTIVE
| SCB_WAITINGQ
);
3799 aic_outb(p
, active_scb
, SCBPTR
);
3803 /*+F*************************************************************************
3805 * aic7xxx_clear_intstat
3808 * Clears the interrupt status.
3809 *-F*************************************************************************/
3811 aic7xxx_clear_intstat(struct aic7xxx_host
*p
)
3813 /* Clear any interrupt conditions this may have caused. */
3814 aic_outb(p
, CLRSELDO
| CLRSELDI
| CLRSELINGO
, CLRSINT0
);
3815 aic_outb(p
, CLRSELTIMEO
| CLRATNO
| CLRSCSIRSTI
| CLRBUSFREE
| CLRSCSIPERR
|
3816 CLRPHASECHG
| CLRREQINIT
, CLRSINT1
);
3817 aic_outb(p
, CLRSCSIINT
| CLRSEQINT
| CLRBRKADRINT
| CLRPARERR
, CLRINT
);
3820 /*+F*************************************************************************
3822 * aic7xxx_reset_current_bus
3825 * Reset the current SCSI bus.
3826 *-F*************************************************************************/
3828 aic7xxx_reset_current_bus(struct aic7xxx_host
*p
)
3831 /* Disable reset interrupts. */
3832 aic_outb(p
, aic_inb(p
, SIMODE1
) & ~ENSCSIRST
, SIMODE1
);
3834 /* Turn off the bus' current operations, after all, we shouldn't have any
3835 * valid commands left to cause a RSELI and SELO once we've tossed the
3836 * bus away with this reset, so we might as well shut down the sequencer
3837 * until the bus is restarted as oppossed to saving the current settings
3838 * and restoring them (which makes no sense to me). */
3840 /* Turn on the bus reset. */
3841 aic_outb(p
, aic_inb(p
, SCSISEQ
) | SCSIRSTO
, SCSISEQ
);
3842 while ( (aic_inb(p
, SCSISEQ
) & SCSIRSTO
) == 0)
3846 * Some of the new Ultra2 chipsets need a longer delay after a chip
3847 * reset than just the init setup creates, so we have to delay here
3848 * before we go into a reset in order to make the chips happy.
3850 if (p
->features
& AHC_ULTRA2
)
3855 /* Turn off the bus reset. */
3856 aic_outb(p
, 0, SCSISEQ
);
3859 aic7xxx_clear_intstat(p
);
3860 /* Re-enable reset interrupts. */
3861 aic_outb(p
, aic_inb(p
, SIMODE1
) | ENSCSIRST
, SIMODE1
);
3865 /*+F*************************************************************************
3867 * aic7xxx_reset_channel
3870 * Reset the channel.
3871 *-F*************************************************************************/
3873 aic7xxx_reset_channel(struct aic7xxx_host
*p
, int channel
, int initiate_reset
)
3875 unsigned long offset_min
, offset_max
;
3876 unsigned char sblkctl
;
3879 if (aic7xxx_verbose
& VERBOSE_RESET_PROCESS
)
3880 printk(INFO_LEAD
"Reset channel called, %s initiate reset.\n",
3881 p
->host_no
, channel
, -1, -1, (initiate_reset
==TRUE
) ? "will" : "won't" );
3886 p
->needsdtr
|= (p
->needsdtr_copy
& 0xFF00);
3887 p
->dtr_pending
&= 0x00FF;
3893 if (p
->features
& AHC_TWIN
)
3896 p
->needsdtr
|= (p
->needsdtr_copy
& 0x00FF);
3897 p
->dtr_pending
&= 0xFF00;
3903 p
->needppr
= p
->needppr_copy
;
3904 p
->needsdtr
= p
->needsdtr_copy
;
3905 p
->needwdtr
= p
->needwdtr_copy
;
3906 p
->dtr_pending
= 0x0;
3908 if (p
->features
& AHC_WIDE
)
3919 while (offset_min
< offset_max
)
3922 * Revert to async/narrow transfers until we renegotiate.
3924 aic_outb(p
, 0, TARG_SCSIRATE
+ offset_min
);
3925 if (p
->features
& AHC_ULTRA2
)
3927 aic_outb(p
, 0, TARG_OFFSET
+ offset_min
);
3933 * Reset the bus and unpause/restart the controller
3935 sblkctl
= aic_inb(p
, SBLKCTL
);
3936 if ( (p
->chip
& AHC_CHIPID_MASK
) == AHC_AIC7770
)
3937 cur_channel
= (sblkctl
& SELBUSB
) >> 3;
3940 if ( (cur_channel
!= channel
) && (p
->features
& AHC_TWIN
) )
3943 * Case 1: Command for another bus is active
3945 if (aic7xxx_verbose
& VERBOSE_RESET_PROCESS
)
3946 printk(INFO_LEAD
"Stealthily resetting idle channel.\n", p
->host_no
,
3949 * Stealthily reset the other bus without upsetting the current bus.
3951 aic_outb(p
, sblkctl
^ SELBUSB
, SBLKCTL
);
3952 aic_outb(p
, aic_inb(p
, SIMODE1
) & ~ENBUSFREE
, SIMODE1
);
3955 aic7xxx_reset_current_bus(p
);
3957 aic_outb(p
, aic_inb(p
, SCSISEQ
) & (ENSELI
|ENRSELI
|ENAUTOATNP
), SCSISEQ
);
3958 aic7xxx_clear_intstat(p
);
3959 aic_outb(p
, sblkctl
, SBLKCTL
);
3964 * Case 2: A command from this bus is active or we're idle.
3966 if (aic7xxx_verbose
& VERBOSE_RESET_PROCESS
)
3967 printk(INFO_LEAD
"Resetting currently active channel.\n", p
->host_no
,
3969 aic_outb(p
, aic_inb(p
, SIMODE1
) & ~(ENBUSFREE
|ENREQINIT
),
3971 p
->flags
&= ~AHC_HANDLING_REQINITS
;
3972 p
->msg_type
= MSG_TYPE_NONE
;
3976 aic7xxx_reset_current_bus(p
);
3978 aic_outb(p
, aic_inb(p
, SCSISEQ
) & (ENSELI
|ENRSELI
|ENAUTOATNP
), SCSISEQ
);
3979 aic7xxx_clear_intstat(p
);
3981 if (aic7xxx_verbose
& VERBOSE_RESET_RETURN
)
3982 printk(INFO_LEAD
"Channel reset\n", p
->host_no
, channel
, -1, -1);
3984 * Clean up all the state information for the pending transactions
3987 aic7xxx_reset_device(p
, ALL_TARGETS
, channel
, ALL_LUNS
, SCB_LIST_NULL
);
3989 if ( !(p
->features
& AHC_TWIN
) )
3991 restart_sequencer(p
);
3997 /*+F*************************************************************************
3999 * aic7xxx_run_waiting_queues
4002 * Scan the awaiting_scbs queue downloading and starting as many
4004 *-F*************************************************************************/
4006 aic7xxx_run_waiting_queues(struct aic7xxx_host
*p
)
4008 struct aic7xxx_scb
*scb
;
4011 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,1,95)
4012 unsigned long cpu_flags
= 0;
4016 if (p
->waiting_scbs
.head
== NULL
)
4022 * First handle SCBs that are waiting but have been assigned a slot.
4025 while ((scb
= scbq_remove_head(&p
->waiting_scbs
)) != NULL
)
4027 tindex
= TARGET_INDEX(scb
->cmd
);
4028 if ( !scb
->tag_action
&& (p
->tagenable
& (1<<tindex
)) )
4030 p
->dev_temp_queue_depth
[tindex
] = 1;
4032 if ( (p
->dev_active_cmds
[tindex
] >=
4033 p
->dev_temp_queue_depth
[tindex
]) ||
4034 (p
->dev_flags
[tindex
] & (DEVICE_RESET_DELAY
|DEVICE_WAS_BUSY
)) ||
4035 (p
->flags
& AHC_RESET_DELAY
) )
4037 scbq_insert_tail(&p
->delayed_scbs
[tindex
], scb
);
4041 scb
->flags
&= ~SCB_WAITINGQ
;
4042 p
->dev_active_cmds
[tindex
]++;
4044 if ( !(scb
->tag_action
) )
4046 aic7xxx_busy_target(p
, scb
);
4048 p
->qinfifo
[p
->qinfifonext
++] = scb
->hscb
->tag
;
4054 if (p
->features
& AHC_QUEUE_REGS
)
4055 aic_outb(p
, p
->qinfifonext
, HNSCB_QOFF
);
4059 aic_outb(p
, p
->qinfifonext
, KERNEL_QINPOS
);
4060 unpause_sequencer(p
, FALSE
);
4062 if (p
->activescbs
> p
->max_activescbs
)
4063 p
->max_activescbs
= p
->activescbs
;
4077 /*+F*************************************************************************
4082 * Check the scsi card for PCI errors and clear the interrupt
4084 * NOTE: If you don't have this function and a 2940 card encounters
4085 * a PCI error condition, the machine will end up locked as the
4086 * interrupt handler gets slammed with non-stop PCI error interrupts
4087 *-F*************************************************************************/
4089 aic7xxx_pci_intr(struct aic7xxx_host
*p
)
4091 unsigned char status1
;
4093 pci_read_config_byte(p
->pdev
, PCI_STATUS
+ 1, &status1
);
4095 if ( (status1
& DPE
) && (aic7xxx_verbose
& VERBOSE_MINOR_ERROR
) )
4096 printk(WARN_LEAD
"Data Parity Error during PCI address or PCI write"
4097 "phase.\n", p
->host_no
, -1, -1, -1);
4098 if ( (status1
& SSE
) && (aic7xxx_verbose
& VERBOSE_MINOR_ERROR
) )
4099 printk(WARN_LEAD
"Signal System Error Detected\n", p
->host_no
,
4101 if ( (status1
& RMA
) && (aic7xxx_verbose
& VERBOSE_MINOR_ERROR
) )
4102 printk(WARN_LEAD
"Received a PCI Master Abort\n", p
->host_no
,
4104 if ( (status1
& RTA
) && (aic7xxx_verbose
& VERBOSE_MINOR_ERROR
) )
4105 printk(WARN_LEAD
"Received a PCI Target Abort\n", p
->host_no
,
4107 if ( (status1
& STA
) && (aic7xxx_verbose
& VERBOSE_MINOR_ERROR
) )
4108 printk(WARN_LEAD
"Signaled a PCI Target Abort\n", p
->host_no
,
4110 if ( (status1
& DPR
) && (aic7xxx_verbose
& VERBOSE_MINOR_ERROR
) )
4111 printk(WARN_LEAD
"Data Parity Error has been reported via PCI pin "
4112 "PERR#\n", p
->host_no
, -1, -1, -1);
4114 pci_write_config_byte(p
->pdev
, PCI_STATUS
+ 1, status1
);
4115 if (status1
& (DPR
|RMA
|RTA
))
4116 aic_outb(p
, CLRPARERR
, CLRINT
);
4118 if ( (aic7xxx_panic_on_abort
) && (p
->spurious_int
> 500) )
4119 aic7xxx_panic_abort(p
, NULL
);
4122 #endif /* CONFIG_PCI */
4124 /*+F*************************************************************************
4129 * Take expired extries off of delayed queues and place on waiting queue
4130 * then run waiting queue to start commands.
4131 ***************************************************************************/
4133 aic7xxx_timer(struct aic7xxx_host
*p
)
4136 unsigned long cpu_flags
= 0;
4137 struct aic7xxx_scb
*scb
;
4139 spin_lock_irqsave(&io_request_lock
, cpu_flags
);
4140 p
->dev_timer_active
&= ~(0x01 << MAX_TARGETS
);
4141 if ( (p
->dev_timer_active
& (0x01 << p
->scsi_id
)) &&
4142 time_after_eq(jiffies
, p
->dev_expires
[p
->scsi_id
]) )
4144 p
->flags
&= ~AHC_RESET_DELAY
;
4145 p
->dev_timer_active
&= ~(0x01 << p
->scsi_id
);
4147 for(i
=0; i
<MAX_TARGETS
; i
++)
4149 if ( (i
!= p
->scsi_id
) &&
4150 (p
->dev_timer_active
& (0x01 << i
)) &&
4151 time_after_eq(jiffies
, p
->dev_expires
[i
]) )
4153 p
->dev_timer_active
&= ~(0x01 << i
);
4154 p
->dev_flags
[i
] &= ~(DEVICE_RESET_DELAY
|DEVICE_WAS_BUSY
);
4155 p
->dev_temp_queue_depth
[i
] = p
->dev_max_queue_depth
[i
];
4157 while ( ((scb
= scbq_remove_head(&p
->delayed_scbs
[i
])) != NULL
) &&
4158 (j
++ < p
->scb_data
->numscbs
) )
4160 scbq_insert_tail(&p
->waiting_scbs
, scb
);
4162 if (j
== p
->scb_data
->numscbs
)
4164 printk(INFO_LEAD
"timer: Yikes, loop in delayed_scbs list.\n",
4165 p
->host_no
, 0, i
, -1);
4166 scbq_init(&p
->delayed_scbs
[i
]);
4167 scbq_init(&p
->waiting_scbs
);
4169 * Well, things are screwed now, wait for a reset to clean the junk
4174 else if ( p
->dev_timer_active
& (0x01 << i
) )
4176 if ( p
->dev_timer_active
& (0x01 << MAX_TARGETS
) )
4178 if ( time_after_eq(p
->dev_timer
.expires
, p
->dev_expires
[i
]) )
4180 p
->dev_timer
.expires
= p
->dev_expires
[i
];
4185 p
->dev_timer
.expires
= p
->dev_expires
[i
];
4186 p
->dev_timer_active
|= (0x01 << MAX_TARGETS
);
4190 if ( p
->dev_timer_active
& (0x01 << MAX_TARGETS
) )
4192 add_timer(&p
->dev_timer
);
4195 aic7xxx_run_waiting_queues(p
);
4196 spin_unlock_irqrestore(&io_request_lock
, cpu_flags
);
4199 /*+F*************************************************************************
4201 * aic7xxx_construct_ppr
4204 * Build up a Parallel Protocol Request message for use with SCSI-3
4206 *-F*************************************************************************/
4208 aic7xxx_construct_ppr(struct aic7xxx_host
*p
, struct aic7xxx_scb
*scb
)
4210 int tindex
= TARGET_INDEX(scb
->cmd
);
4212 p
->msg_buf
[p
->msg_index
++] = MSG_EXTENDED
;
4213 p
->msg_buf
[p
->msg_index
++] = MSG_EXT_PPR_LEN
;
4214 p
->msg_buf
[p
->msg_index
++] = MSG_EXT_PPR
;
4215 p
->msg_buf
[p
->msg_index
++] = p
->transinfo
[tindex
].goal_period
;
4216 p
->msg_buf
[p
->msg_index
++] = 0;
4217 p
->msg_buf
[p
->msg_index
++] = p
->transinfo
[tindex
].goal_offset
;
4218 p
->msg_buf
[p
->msg_index
++] = p
->transinfo
[tindex
].goal_width
;
4219 p
->msg_buf
[p
->msg_index
++] = p
->transinfo
[tindex
].goal_options
;
4223 /*+F*************************************************************************
4225 * aic7xxx_construct_sdtr
4228 * Constucts a synchronous data transfer message in the message
4229 * buffer on the sequencer.
4230 *-F*************************************************************************/
4232 aic7xxx_construct_sdtr(struct aic7xxx_host
*p
, unsigned char period
,
4233 unsigned char offset
)
4235 p
->msg_buf
[p
->msg_index
++] = MSG_EXTENDED
;
4236 p
->msg_buf
[p
->msg_index
++] = MSG_EXT_SDTR_LEN
;
4237 p
->msg_buf
[p
->msg_index
++] = MSG_EXT_SDTR
;
4238 p
->msg_buf
[p
->msg_index
++] = period
;
4239 p
->msg_buf
[p
->msg_index
++] = offset
;
4243 /*+F*************************************************************************
4245 * aic7xxx_construct_wdtr
4248 * Constucts a wide data transfer message in the message buffer
4250 *-F*************************************************************************/
4252 aic7xxx_construct_wdtr(struct aic7xxx_host
*p
, unsigned char bus_width
)
4254 p
->msg_buf
[p
->msg_index
++] = MSG_EXTENDED
;
4255 p
->msg_buf
[p
->msg_index
++] = MSG_EXT_WDTR_LEN
;
4256 p
->msg_buf
[p
->msg_index
++] = MSG_EXT_WDTR
;
4257 p
->msg_buf
[p
->msg_index
++] = bus_width
;
4261 /*+F*************************************************************************
4263 * aic7xxx_calc_residual
4266 * Calculate the residual data not yet transferred.
4267 *-F*************************************************************************/
4269 aic7xxx_calculate_residual (struct aic7xxx_host
*p
, struct aic7xxx_scb
*scb
)
4271 struct aic7xxx_hwscb
*hscb
;
4279 * Don't destroy valid residual information with
4280 * residual coming from a check sense operation.
4282 if (((scb
->hscb
->control
& DISCONNECTED
) == 0) &&
4283 (scb
->flags
& SCB_SENSE
) == 0)
4286 * We had an underflow. At this time, there's only
4287 * one other driver that bothers to check for this,
4288 * and cmd->underflow seems to be set rather half-
4289 * heartedly in the higher-level SCSI code.
4291 actual
= scb
->sg_length
;
4292 for (i
=1; i
< hscb
->residual_SG_segment_count
; i
++)
4294 actual
-= scb
->sg_list
[scb
->sg_count
- i
].length
;
4296 actual
-= (hscb
->residual_data_count
[2] << 16) |
4297 (hscb
->residual_data_count
[1] << 8) |
4298 hscb
->residual_data_count
[0];
4300 if (actual
< cmd
->underflow
)
4302 if (aic7xxx_verbose
& VERBOSE_MINOR_ERROR
)
4303 printk(INFO_LEAD
"Underflow - Wanted %u, %s %u, residual SG "
4304 "count %d.\n", p
->host_no
, CTL_OF_SCB(scb
), cmd
->underflow
,
4305 (cmd
->request
.cmd
== WRITE
) ? "wrote" : "read", actual
,
4306 hscb
->residual_SG_segment_count
);
4307 aic7xxx_error(cmd
) = DID_RETRY_COMMAND
;
4308 aic7xxx_status(cmd
) = hscb
->target_status
;
4313 * Clean out the residual information in the SCB for the
4316 hscb
->residual_data_count
[2] = 0;
4317 hscb
->residual_data_count
[1] = 0;
4318 hscb
->residual_data_count
[0] = 0;
4319 hscb
->residual_SG_segment_count
= 0;
4322 /*+F*************************************************************************
4324 * aic7xxx_handle_device_reset
4327 * Interrupt handler for sequencer interrupts (SEQINT).
4328 *-F*************************************************************************/
4330 aic7xxx_handle_device_reset(struct aic7xxx_host
*p
, int target
, int channel
)
4332 unsigned short targ_mask
;
4333 unsigned char tindex
= target
;
4335 tindex
|= ((channel
& 0x01) << 3);
4337 targ_mask
= (0x01 << tindex
);
4339 * Go back to async/narrow transfers and renegotiate.
4341 p
->needppr
|= (p
->needppr_copy
& targ_mask
);
4342 p
->needsdtr
|= (p
->needsdtr_copy
& targ_mask
);
4343 p
->needwdtr
|= (p
->needwdtr_copy
& targ_mask
);
4344 p
->dtr_pending
&= ~targ_mask
;
4345 aic_outb(p
, 0, TARG_SCSIRATE
+ tindex
);
4346 if (p
->features
& AHC_ULTRA2
)
4347 aic_outb(p
, 0, TARG_OFFSET
+ tindex
);
4348 aic7xxx_reset_device(p
, target
, channel
, ALL_LUNS
, SCB_LIST_NULL
);
4349 if (aic7xxx_verbose
& VERBOSE_RESET_PROCESS
)
4350 printk(INFO_LEAD
"Bus Device Reset delivered.\n", p
->host_no
, channel
,
4352 aic7xxx_run_done_queue(p
, /*complete*/ TRUE
);
4355 /*+F*************************************************************************
4357 * aic7xxx_handle_seqint
4360 * Interrupt handler for sequencer interrupts (SEQINT).
4361 *-F*************************************************************************/
4363 aic7xxx_handle_seqint(struct aic7xxx_host
*p
, unsigned char intstat
)
4365 struct aic7xxx_scb
*scb
;
4366 unsigned short target_mask
;
4367 unsigned char target
, lun
, tindex
;
4368 unsigned char queue_flag
= FALSE
;
4371 target
= ((aic_inb(p
, SAVED_TCL
) >> 4) & 0x0f);
4372 if ( (p
->chip
& AHC_CHIPID_MASK
) == AHC_AIC7770
)
4373 channel
= (aic_inb(p
, SBLKCTL
) & SELBUSB
) >> 3;
4376 tindex
= target
+ (channel
<< 3);
4377 lun
= aic_inb(p
, SAVED_TCL
) & 0x07;
4378 target_mask
= (0x01 << tindex
);
4381 * Go ahead and clear the SEQINT now, that avoids any interrupt race
4382 * conditions later on in case we enable some other interrupt.
4384 aic_outb(p
, CLRSEQINT
, CLRINT
);
4385 switch (intstat
& SEQINT_MASK
)
4389 aic_outb(p
, aic_inb(p
, SCSISEQ
) & (ENSELI
|ENRSELI
|ENAUTOATNP
),
4391 printk(WARN_LEAD
"No active SCB for reconnecting target - Issuing "
4392 "BUS DEVICE RESET.\n", p
->host_no
, channel
, target
, lun
);
4393 printk(WARN_LEAD
" SAVED_TCL=0x%x, ARG_1=0x%x, SEQADDR=0x%x\n",
4394 p
->host_no
, channel
, target
, lun
,
4395 aic_inb(p
, SAVED_TCL
), aic_inb(p
, ARG_1
),
4396 (aic_inb(p
, SEQADDR1
) << 8) | aic_inb(p
, SEQADDR0
));
4397 if (aic7xxx_panic_on_abort
)
4398 aic7xxx_panic_abort(p
, NULL
);
4404 if (aic7xxx_verbose
& VERBOSE_MINOR_ERROR
)
4405 printk(INFO_LEAD
"Rejecting unknown message (0x%x) received from "
4406 "target, SEQ_FLAGS=0x%x\n", p
->host_no
, channel
, target
, lun
,
4407 aic_inb(p
, ACCUM
), aic_inb(p
, SEQ_FLAGS
));
4414 * The reconnecting target either did not send an identify
4415 * message, or did, but we didn't find an SCB to match and
4416 * before it could respond to our ATN/abort, it hit a dataphase.
4417 * The only safe thing to do is to blow it away with a bus
4420 if (aic7xxx_verbose
& (VERBOSE_SEQINT
| VERBOSE_RESET_MID
))
4421 printk(INFO_LEAD
"Target did not send an IDENTIFY message; "
4422 "LASTPHASE 0x%x, SAVED_TCL 0x%x\n", p
->host_no
, channel
, target
,
4423 lun
, aic_inb(p
, LASTPHASE
), aic_inb(p
, SAVED_TCL
));
4425 aic7xxx_reset_channel(p
, channel
, /*initiate reset*/ TRUE
);
4426 aic7xxx_run_done_queue(p
, TRUE
);
4432 if (aic_inb(p
, LASTPHASE
) == P_BUSFREE
)
4434 if (aic7xxx_verbose
& VERBOSE_SEQINT
)
4435 printk(INFO_LEAD
"Missed busfree.\n", p
->host_no
, channel
,
4437 restart_sequencer(p
);
4441 if (aic7xxx_verbose
& VERBOSE_SEQINT
)
4442 printk(INFO_LEAD
"Unknown scsi bus phase, continuing\n", p
->host_no
,
4443 channel
, target
, lun
);
4449 p
->msg_type
= MSG_TYPE_INITIATOR_MSGIN
;
4453 #ifdef AIC7XXX_VERBOSE_DEBUGGING
4454 if (aic7xxx_verbose
> 0xffff)
4455 printk(INFO_LEAD
"Enabling REQINITs for MSG_IN\n", p
->host_no
,
4456 channel
, target
, lun
);
4460 * To actually receive the message, simply turn on
4461 * REQINIT interrupts and let our interrupt handler
4462 * do the rest (REQINIT should already be true).
4464 p
->flags
|= AHC_HANDLING_REQINITS
;
4465 aic_outb(p
, aic_inb(p
, SIMODE1
) | ENREQINIT
, SIMODE1
);
4468 * We don't want the sequencer unpaused yet so we return early
4476 * What we care about here is if we had an outstanding SDTR
4477 * or WDTR message for this target. If we did, this is a
4478 * signal that the target is refusing negotiation.
4480 unsigned char scb_index
;
4481 unsigned char last_msg
;
4483 scb_index
= aic_inb(p
, SCB_TAG
);
4484 scb
= p
->scb_data
->scb_array
[scb_index
];
4485 last_msg
= aic_inb(p
, LAST_MSG
);
4487 if ( (last_msg
== MSG_IDENTIFYFLAG
) &&
4488 (scb
->tag_action
) &&
4489 !(scb
->flags
& SCB_MSGOUT_BITS
) )
4491 if (scb
->tag_action
== MSG_ORDERED_Q_TAG
)
4494 * OK...the device seems able to accept tagged commands, but
4495 * not ordered tag commands, only simple tag commands. So, we
4496 * disable ordered tag commands and go on with life just like
4499 p
->orderedtag
&= ~target_mask
;
4500 scb
->tag_action
= MSG_SIMPLE_Q_TAG
;
4501 scb
->hscb
->control
&= ~SCB_TAG_TYPE
;
4502 scb
->hscb
->control
|= MSG_SIMPLE_Q_TAG
;
4503 aic_outb(p
, scb
->hscb
->control
, SCB_CONTROL
);
4505 * OK..we set the tag type to simple tag command, now we re-assert
4506 * ATNO and hope this will take us into the identify phase again
4507 * so we can resend the tag type and info to the device.
4509 aic_outb(p
, MSG_IDENTIFYFLAG
, MSG_OUT
);
4510 aic_outb(p
, aic_inb(p
, SCSISIGI
) | ATNO
, SCSISIGO
);
4512 else if (scb
->tag_action
== MSG_SIMPLE_Q_TAG
)
4514 unsigned char i
, reset
= 0;
4515 struct aic7xxx_scb
*scbp
;
4518 * Hmmmm....the device is flaking out on tagged commands. The
4519 * bad thing is that we already have tagged commands enabled in
4520 * the device struct in the mid level code. We also have a queue
4521 * set according to the tagged queue depth. Gonna have to live
4522 * with it by controlling our queue depth internally and making
4523 * sure we don't set the tagged command flag any more.
4525 p
->tagenable
&= ~target_mask
;
4526 p
->orderedtag
&= ~target_mask
;
4527 p
->dev_max_queue_depth
[tindex
] =
4528 p
->dev_temp_queue_depth
[tindex
] = 1;
4530 * We set this command up as a bus device reset. However, we have
4531 * to clear the tag type as it's causing us problems. We shouldnt
4532 * have to worry about any other commands being active, since if
4533 * the device is refusing tagged commands, this should be the
4534 * first tagged command sent to the device, however, we do have
4535 * to worry about any other tagged commands that may already be
4536 * in the qinfifo. The easiest way to do this, is to issue a BDR,
4537 * send all the commands back to the mid level code, then let them
4538 * come back and get rebuilt as untagged commands.
4540 scb
->tag_action
= 0;
4541 scb
->hscb
->control
&= ~(TAG_ENB
| SCB_TAG_TYPE
);
4542 aic_outb(p
, scb
->hscb
->control
, SCB_CONTROL
);
4544 old_verbose
= aic7xxx_verbose
;
4545 aic7xxx_verbose
&= ~(VERBOSE_RESET
|VERBOSE_ABORT
);
4546 for (i
=0; i
!=p
->scb_data
->numscbs
; i
++)
4548 scbp
= p
->scb_data
->scb_array
[i
];
4549 if ((scbp
->flags
& SCB_ACTIVE
) && (scbp
!= scb
))
4551 if (aic7xxx_match_scb(p
, scbp
, target
, channel
, lun
, i
))
4553 aic7xxx_reset_device(p
, target
, channel
, lun
, i
);
4556 aic7xxx_run_done_queue(p
, TRUE
);
4559 aic7xxx_verbose
= old_verbose
;
4561 * Wait until after the for loop to set the busy index since
4562 * aic7xxx_reset_device will clear the busy index during its
4565 aic7xxx_busy_target(p
, scb
);
4566 printk(INFO_LEAD
"Device is refusing tagged commands, using "
4567 "untagged I/O.\n", p
->host_no
, channel
, target
, lun
);
4568 aic_outb(p
, MSG_IDENTIFYFLAG
, MSG_OUT
);
4569 aic_outb(p
, aic_inb(p
, SCSISIGI
) | ATNO
, SCSISIGO
);
4572 else if (scb
->flags
& SCB_MSGOUT_PPR
)
4575 * As per the draft specs, any device capable of supporting any of
4576 * the option values other than 0 are not allowed to reject the
4577 * PPR message. Instead, they must negotiate out what they do
4578 * support instead of rejecting our offering or else they cause
4579 * a parity error during msg_out phase to signal that they don't
4580 * like our settings.
4582 p
->needppr
&= ~target_mask
;
4583 p
->needppr_copy
&= ~target_mask
;
4584 aic7xxx_set_width(p
, target
, channel
, lun
, MSG_EXT_WDTR_BUS_8_BIT
,
4585 (AHC_TRANS_ACTIVE
|AHC_TRANS_CUR
|AHC_TRANS_QUITE
));
4586 aic7xxx_set_syncrate(p
, NULL
, target
, channel
, 0, 0, 0,
4587 AHC_TRANS_ACTIVE
|AHC_TRANS_CUR
|AHC_TRANS_QUITE
);
4588 p
->transinfo
[tindex
].goal_options
= 0;
4589 p
->dtr_pending
&= ~target_mask
;
4590 scb
->flags
&= ~SCB_MSGOUT_BITS
;
4591 if(aic7xxx_verbose
& VERBOSE_NEGOTIATION2
)
4593 printk(INFO_LEAD
"Device is rejecting PPR messages, falling "
4594 "back.\n", p
->host_no
, channel
, target
, lun
);
4596 if ( p
->transinfo
[tindex
].goal_width
)
4598 p
->needwdtr
|= target_mask
;
4599 p
->needwdtr_copy
|= target_mask
;
4600 p
->dtr_pending
|= target_mask
;
4601 scb
->flags
|= SCB_MSGOUT_WDTR
;
4603 if ( p
->transinfo
[tindex
].goal_offset
)
4605 p
->needsdtr
|= target_mask
;
4606 p
->needsdtr_copy
|= target_mask
;
4607 if( !(p
->dtr_pending
& target_mask
) )
4609 p
->dtr_pending
|= target_mask
;
4610 scb
->flags
|= SCB_MSGOUT_SDTR
;
4613 if ( p
->dtr_pending
& target_mask
)
4615 aic_outb(p
, HOST_MSG
, MSG_OUT
);
4616 aic_outb(p
, aic_inb(p
, SCSISIGI
) | ATNO
, SCSISIGO
);
4619 else if (scb
->flags
& SCB_MSGOUT_WDTR
)
4622 * note 8bit xfers and clear flag
4624 p
->needwdtr
&= ~target_mask
;
4625 p
->needwdtr_copy
&= ~target_mask
;
4626 p
->dtr_pending
&= ~target_mask
;
4627 scb
->flags
&= ~SCB_MSGOUT_BITS
;
4628 aic7xxx_set_width(p
, target
, channel
, lun
, MSG_EXT_WDTR_BUS_8_BIT
,
4629 (AHC_TRANS_ACTIVE
|AHC_TRANS_GOAL
|AHC_TRANS_CUR
));
4630 aic7xxx_set_syncrate(p
, NULL
, target
, channel
, 0, 0, 0,
4631 AHC_TRANS_ACTIVE
|AHC_TRANS_CUR
|AHC_TRANS_QUITE
);
4632 if(aic7xxx_verbose
& VERBOSE_NEGOTIATION2
)
4634 printk(INFO_LEAD
"Device is rejecting WDTR messages, using "
4635 "narrow transfers.\n", p
->host_no
, channel
, target
, lun
);
4637 p
->needsdtr
|= (p
->needsdtr_copy
& target_mask
);
4639 else if (scb
->flags
& SCB_MSGOUT_SDTR
)
4642 * note asynch xfers and clear flag
4644 p
->needsdtr
&= ~target_mask
;
4645 p
->needsdtr_copy
&= ~target_mask
;
4646 p
->dtr_pending
&= ~target_mask
;
4647 scb
->flags
&= ~SCB_MSGOUT_SDTR
;
4648 aic7xxx_set_syncrate(p
, NULL
, target
, channel
, 0, 0, 0,
4649 (AHC_TRANS_CUR
|AHC_TRANS_ACTIVE
|AHC_TRANS_GOAL
));
4650 if(aic7xxx_verbose
& VERBOSE_NEGOTIATION2
)
4652 printk(INFO_LEAD
"Device is rejecting SDTR messages, using "
4653 "async transfers.\n", p
->host_no
, channel
, target
, lun
);
4656 else if (aic7xxx_verbose
& VERBOSE_SEQINT
)
4659 * Otherwise, we ignore it.
4661 printk(INFO_LEAD
"Received MESSAGE_REJECT for unknown cause. "
4662 "Ignoring.\n", p
->host_no
, channel
, target
, lun
);
4669 unsigned char scb_index
;
4670 struct aic7xxx_hwscb
*hscb
;
4673 /* The sequencer will notify us when a command has an error that
4674 * would be of interest to the kernel. This allows us to leave
4675 * the sequencer running in the common case of command completes
4676 * without error. The sequencer will have DMA'd the SCB back
4677 * up to us, so we can reference the drivers SCB array.
4679 * Set the default return value to 0 indicating not to send
4680 * sense. The sense code will change this if needed and this
4681 * reduces code duplication.
4683 aic_outb(p
, 0, RETURN_1
);
4684 scb_index
= aic_inb(p
, SCB_TAG
);
4685 if (scb_index
> p
->scb_data
->numscbs
)
4687 printk(WARN_LEAD
"Invalid SCB during SEQINT 0x%02x, SCB_TAG %d.\n",
4688 p
->host_no
, channel
, target
, lun
, intstat
, scb_index
);
4691 scb
= p
->scb_data
->scb_array
[scb_index
];
4694 if (!(scb
->flags
& SCB_ACTIVE
) || (scb
->cmd
== NULL
))
4696 printk(WARN_LEAD
"Invalid SCB during SEQINT 0x%x, scb %d, flags 0x%x,"
4697 " cmd 0x%lx.\n", p
->host_no
, channel
, target
, lun
, intstat
,
4698 scb_index
, scb
->flags
, (unsigned long) scb
->cmd
);
4703 hscb
->target_status
= aic_inb(p
, SCB_TARGET_STATUS
);
4704 aic7xxx_status(cmd
) = hscb
->target_status
;
4706 cmd
->result
= hscb
->target_status
;
4708 switch (status_byte(hscb
->target_status
))
4711 if (aic7xxx_verbose
& VERBOSE_SEQINT
)
4712 printk(INFO_LEAD
"Interrupted for status of GOOD???\n",
4713 p
->host_no
, CTL_OF_SCB(scb
));
4716 case COMMAND_TERMINATED
:
4717 case CHECK_CONDITION
:
4718 if ( !(scb
->flags
& SCB_SENSE
) )
4721 * Send a sense command to the requesting target.
4722 * XXX - revisit this and get rid of the memcopys.
4724 memcpy(scb
->sense_cmd
, &generic_sense
[0],
4725 sizeof(generic_sense
));
4727 scb
->sense_cmd
[1] = (cmd
->lun
<< 5);
4728 scb
->sense_cmd
[4] = sizeof(cmd
->sense_buffer
);
4730 scb
->sg_list
[0].length
=
4731 cpu_to_le32(sizeof(cmd
->sense_buffer
));
4732 scb
->sg_list
[0].address
=
4733 cpu_to_le32(pci_map_single(p
->pdev
, cmd
->sense_buffer
,
4734 sizeof(cmd
->sense_buffer
),
4735 PCI_DMA_FROMDEVICE
));
4738 * XXX - We should allow disconnection, but can't as it
4739 * might allow overlapped tagged commands.
4741 /* hscb->control &= DISCENB; */
4743 hscb
->target_status
= 0;
4744 hscb
->SG_list_pointer
=
4745 cpu_to_le32(SCB_DMA_ADDR(scb
, scb
->sg_list
));
4746 hscb
->SCSI_cmd_pointer
=
4747 cpu_to_le32(SCB_DMA_ADDR(scb
, scb
->sense_cmd
));
4748 hscb
->data_count
= scb
->sg_list
[0].length
;
4749 hscb
->data_pointer
= scb
->sg_list
[0].address
;
4750 hscb
->SCSI_cmd_length
= COMMAND_SIZE(scb
->sense_cmd
[0]);
4751 hscb
->residual_SG_segment_count
= 0;
4752 hscb
->residual_data_count
[0] = 0;
4753 hscb
->residual_data_count
[1] = 0;
4754 hscb
->residual_data_count
[2] = 0;
4756 scb
->sg_count
= hscb
->SG_segment_count
= 1;
4757 scb
->sg_length
= sizeof(cmd
->sense_buffer
);
4758 scb
->tag_action
= 0;
4759 scb
->flags
|= SCB_SENSE
;
4761 * Ensure the target is busy since this will be an
4762 * an untagged request.
4764 #ifdef AIC7XXX_VERBOSE_DEBUGGING
4765 if (aic7xxx_verbose
& VERBOSE_NEGOTIATION2
)
4767 if (scb
->flags
& SCB_MSGOUT_BITS
)
4768 printk(INFO_LEAD
"Requesting SENSE with %s\n", p
->host_no
,
4769 CTL_OF_SCB(scb
), (scb
->flags
& SCB_MSGOUT_SDTR
) ?
4772 printk(INFO_LEAD
"Requesting SENSE, no MSG\n", p
->host_no
,
4776 aic7xxx_busy_target(p
, scb
);
4777 aic_outb(p
, SEND_SENSE
, RETURN_1
);
4778 aic7xxx_error(cmd
) = DID_OK
;
4780 } /* first time sense, no errors */
4781 aic7xxx_error(cmd
) = DID_ERROR
;
4782 scb
->flags
&= ~SCB_SENSE
;
4786 queue_flag
= TRUE
; /* Mark that this is a QUEUE_FULL and */
4787 case BUSY
: /* drop through to here */
4789 struct aic7xxx_scb
*next_scbp
, *prev_scbp
;
4790 unsigned char active_hscb
, next_hscb
, prev_hscb
, scb_index
;
4792 * We have to look three places for queued commands:
4794 * 2: p->waiting_scbs queue
4795 * 3: WAITING_SCBS list on card (for commands that are started
4796 * but haven't yet made it to the device)
4798 aic7xxx_search_qinfifo(p
, target
, channel
, lun
,
4799 SCB_LIST_NULL
, 0, TRUE
,
4800 &p
->delayed_scbs
[tindex
]);
4801 next_scbp
= p
->waiting_scbs
.head
;
4802 while ( next_scbp
!= NULL
)
4804 prev_scbp
= next_scbp
;
4805 next_scbp
= next_scbp
->q_next
;
4806 if ( aic7xxx_match_scb(p
, prev_scbp
, target
, channel
, lun
,
4809 scbq_remove(&p
->waiting_scbs
, prev_scbp
);
4810 scbq_insert_tail(&p
->delayed_scbs
[tindex
],
4815 active_hscb
= aic_inb(p
, SCBPTR
);
4816 prev_hscb
= next_hscb
= scb_index
= SCB_LIST_NULL
;
4817 next_hscb
= aic_inb(p
, WAITING_SCBH
);
4818 while (next_hscb
!= SCB_LIST_NULL
)
4820 aic_outb(p
, next_hscb
, SCBPTR
);
4821 scb_index
= aic_inb(p
, SCB_TAG
);
4822 if (scb_index
< p
->scb_data
->numscbs
)
4824 next_scbp
= p
->scb_data
->scb_array
[scb_index
];
4825 if (aic7xxx_match_scb(p
, next_scbp
, target
, channel
, lun
,
4828 if (next_scbp
->flags
& SCB_WAITINGQ
)
4830 p
->dev_active_cmds
[tindex
]++;
4832 scbq_remove(&p
->delayed_scbs
[tindex
], next_scbp
);
4833 scbq_remove(&p
->waiting_scbs
, next_scbp
);
4835 scbq_insert_head(&p
->delayed_scbs
[tindex
],
4837 next_scbp
->flags
|= SCB_WAITINGQ
;
4838 p
->dev_active_cmds
[tindex
]--;
4840 next_hscb
= aic_inb(p
, SCB_NEXT
);
4841 aic_outb(p
, 0, SCB_CONTROL
);
4842 aic_outb(p
, SCB_LIST_NULL
, SCB_TAG
);
4843 aic7xxx_add_curscb_to_free_list(p
);
4844 if (prev_hscb
== SCB_LIST_NULL
)
4846 /* We were first on the list,
4847 * so we kill the selection
4848 * hardware. Let the sequencer
4849 * re-init the hardware itself
4851 aic_outb(p
, aic_inb(p
, SCSISEQ
) & ~ENSELO
, SCSISEQ
);
4852 aic_outb(p
, CLRSELTIMEO
, CLRSINT1
);
4853 aic_outb(p
, next_hscb
, WAITING_SCBH
);
4857 aic_outb(p
, prev_hscb
, SCBPTR
);
4858 aic_outb(p
, next_hscb
, SCB_NEXT
);
4863 prev_hscb
= next_hscb
;
4864 next_hscb
= aic_inb(p
, SCB_NEXT
);
4866 } /* scb_index >= p->scb_data->numscbs */
4868 aic_outb(p
, active_hscb
, SCBPTR
);
4869 if (scb
->flags
& SCB_WAITINGQ
)
4871 scbq_remove(&p
->delayed_scbs
[tindex
], scb
);
4872 scbq_remove(&p
->waiting_scbs
, scb
);
4873 p
->dev_active_cmds
[tindex
]++;
4876 scbq_insert_head(&p
->delayed_scbs
[tindex
], scb
);
4877 p
->dev_active_cmds
[tindex
]--;
4879 scb
->flags
|= SCB_WAITINGQ
| SCB_WAS_BUSY
;
4881 if ( !(p
->dev_timer_active
& (0x01 << tindex
)) )
4883 p
->dev_timer_active
|= (0x01 << tindex
);
4884 if ( p
->dev_active_cmds
[tindex
] )
4886 p
->dev_expires
[tindex
] = jiffies
+ HZ
;
4890 p
->dev_expires
[tindex
] = jiffies
+ (HZ
/ 10);
4892 if ( !(p
->dev_timer_active
& (0x01 << MAX_TARGETS
)) )
4894 p
->dev_timer
.expires
= p
->dev_expires
[tindex
];
4895 p
->dev_timer_active
|= (0x01 << MAX_TARGETS
);
4896 add_timer(&p
->dev_timer
);
4898 else if ( time_after_eq(p
->dev_timer
.expires
,
4899 p
->dev_expires
[tindex
]) )
4900 mod_timer(&p
->dev_timer
, p
->dev_expires
[tindex
]);
4902 #ifdef AIC7XXX_VERBOSE_DEBUGGING
4903 if( (aic7xxx_verbose
& VERBOSE_MINOR_ERROR
) ||
4904 (aic7xxx_verbose
> 0xffff) )
4907 printk(INFO_LEAD
"Queue full received; queue depth %d, "
4908 "active %d\n", p
->host_no
, CTL_OF_SCB(scb
),
4909 p
->dev_max_queue_depth
[tindex
],
4910 p
->dev_active_cmds
[tindex
]);
4912 printk(INFO_LEAD
"Target busy\n", p
->host_no
, CTL_OF_SCB(scb
));
4918 if ( p
->dev_last_queue_full
[tindex
] !=
4919 p
->dev_active_cmds
[tindex
] )
4921 p
->dev_last_queue_full
[tindex
] =
4922 p
->dev_active_cmds
[tindex
];
4923 p
->dev_last_queue_full_count
[tindex
] = 0;
4927 p
->dev_last_queue_full_count
[tindex
]++;
4929 if ( (p
->dev_last_queue_full_count
[tindex
] > 14) &&
4930 (p
->dev_active_cmds
[tindex
] > 4) )
4932 if (aic7xxx_verbose
& VERBOSE_NEGOTIATION2
)
4933 printk(INFO_LEAD
"Queue depth reduced to %d\n", p
->host_no
,
4934 CTL_OF_SCB(scb
), p
->dev_active_cmds
[tindex
]);
4935 p
->dev_max_queue_depth
[tindex
] =
4936 p
->dev_active_cmds
[tindex
];
4937 p
->dev_last_queue_full
[tindex
] = 0;
4938 p
->dev_last_queue_full_count
[tindex
] = 0;
4939 p
->dev_temp_queue_depth
[tindex
] =
4940 p
->dev_active_cmds
[tindex
];
4942 else if (p
->dev_active_cmds
[tindex
] == 0)
4944 if (aic7xxx_verbose
& VERBOSE_NEGOTIATION
)
4946 printk(INFO_LEAD
"QUEUE_FULL status received with 0 "
4947 "commands active.\n", p
->host_no
, CTL_OF_SCB(scb
));
4948 printk(INFO_LEAD
"Tagged Command Queueing disabled\n",
4949 p
->host_no
, CTL_OF_SCB(scb
));
4951 p
->dev_max_queue_depth
[tindex
] = 1;
4952 p
->dev_temp_queue_depth
[tindex
] = 1;
4953 scb
->tag_action
= 0;
4954 scb
->hscb
->control
&= ~(MSG_ORDERED_Q_TAG
|MSG_SIMPLE_Q_TAG
);
4958 p
->dev_flags
[tindex
] |= DEVICE_WAS_BUSY
;
4959 p
->dev_temp_queue_depth
[tindex
] =
4960 p
->dev_active_cmds
[tindex
];
4967 if (aic7xxx_verbose
& VERBOSE_SEQINT
)
4968 printk(INFO_LEAD
"Unexpected target status 0x%x.\n", p
->host_no
,
4969 CTL_OF_SCB(scb
), scb
->hscb
->target_status
);
4970 if (!aic7xxx_error(cmd
))
4972 aic7xxx_error(cmd
) = DID_RETRY_COMMAND
;
4982 unsigned char scb_index
, msg_out
;
4984 scb_index
= aic_inb(p
, SCB_TAG
);
4985 msg_out
= aic_inb(p
, MSG_OUT
);
4986 scb
= p
->scb_data
->scb_array
[scb_index
];
4987 p
->msg_index
= p
->msg_len
= 0;
4989 * This SCB had a MK_MESSAGE set in its control byte informing
4990 * the sequencer that we wanted to send a special message to
4994 if ( !(scb
->flags
& SCB_DEVICE_RESET
) &&
4995 (msg_out
== MSG_IDENTIFYFLAG
) &&
4996 (scb
->hscb
->control
& TAG_ENB
) )
4998 p
->msg_buf
[p
->msg_index
++] = scb
->tag_action
;
4999 p
->msg_buf
[p
->msg_index
++] = scb
->hscb
->tag
;
5003 if (scb
->flags
& SCB_DEVICE_RESET
)
5005 p
->msg_buf
[p
->msg_index
++] = MSG_BUS_DEV_RESET
;
5007 if (aic7xxx_verbose
& VERBOSE_RESET_PROCESS
)
5008 printk(INFO_LEAD
"Bus device reset mailed.\n",
5009 p
->host_no
, CTL_OF_SCB(scb
));
5011 else if (scb
->flags
& SCB_ABORT
)
5013 if (scb
->tag_action
)
5015 p
->msg_buf
[p
->msg_index
++] = MSG_ABORT_TAG
;
5019 p
->msg_buf
[p
->msg_index
++] = MSG_ABORT
;
5022 if (aic7xxx_verbose
& VERBOSE_ABORT_PROCESS
)
5023 printk(INFO_LEAD
"Abort message mailed.\n", p
->host_no
,
5026 else if (scb
->flags
& SCB_MSGOUT_PPR
)
5028 if (aic7xxx_verbose
& VERBOSE_NEGOTIATION2
)
5030 printk(INFO_LEAD
"Sending PPR (%d/%d/%d/%d) message.\n",
5031 p
->host_no
, CTL_OF_SCB(scb
),
5032 p
->transinfo
[tindex
].goal_period
,
5033 p
->transinfo
[tindex
].goal_offset
,
5034 p
->transinfo
[tindex
].goal_width
,
5035 p
->transinfo
[tindex
].goal_options
);
5037 aic7xxx_construct_ppr(p
, scb
);
5039 else if (scb
->flags
& SCB_MSGOUT_WDTR
)
5041 if (aic7xxx_verbose
& VERBOSE_NEGOTIATION2
)
5043 printk(INFO_LEAD
"Sending WDTR message.\n", p
->host_no
,
5046 aic7xxx_construct_wdtr(p
, p
->transinfo
[tindex
].goal_width
);
5048 else if (scb
->flags
& SCB_MSGOUT_SDTR
)
5050 unsigned int max_sync
, period
;
5051 unsigned char options
= 0;
5053 * Now that the device is selected, use the bits in SBLKCTL and
5054 * SSTAT2 to determine the max sync rate for this device.
5056 if (p
->features
& AHC_ULTRA2
)
5058 if ( (aic_inb(p
, SBLKCTL
) & ENAB40
) &&
5059 !(aic_inb(p
, SSTAT2
) & EXP_ACTIVE
) )
5061 max_sync
= AHC_SYNCRATE_ULTRA2
;
5065 max_sync
= AHC_SYNCRATE_ULTRA
;
5068 else if (p
->features
& AHC_ULTRA
)
5070 max_sync
= AHC_SYNCRATE_ULTRA
;
5074 max_sync
= AHC_SYNCRATE_FAST
;
5076 period
= p
->transinfo
[tindex
].goal_period
;
5077 aic7xxx_find_syncrate(p
, &period
, max_sync
, &options
);
5078 if (aic7xxx_verbose
& VERBOSE_NEGOTIATION2
)
5080 printk(INFO_LEAD
"Sending SDTR %d/%d message.\n", p
->host_no
,
5081 CTL_OF_SCB(scb
), period
,
5082 p
->transinfo
[tindex
].goal_offset
);
5084 aic7xxx_construct_sdtr(p
, period
,
5085 p
->transinfo
[tindex
].goal_offset
);
5090 panic("aic7xxx: AWAITING_MSG for an SCB that does "
5091 "not have a waiting message.\n");
5094 * We've set everything up to send our message, now to actually do
5095 * so we need to enable reqinit interrupts and let the interrupt
5096 * handler do the rest. We don't want to unpause the sequencer yet
5097 * though so we'll return early. We also have to make sure that
5098 * we clear the SEQINT *BEFORE* we set the REQINIT handler active
5099 * or else it's possible on VLB cards to loose the first REQINIT
5100 * interrupt. Edge triggered EISA cards could also loose this
5101 * interrupt, although PCI and level triggered cards should not
5102 * have this problem since they continually interrupt the kernel
5103 * until we take care of the situation.
5105 scb
->flags
|= SCB_MSGOUT_SENT
;
5107 p
->msg_type
= MSG_TYPE_INITIATOR_MSGOUT
;
5108 p
->flags
|= AHC_HANDLING_REQINITS
;
5109 aic_outb(p
, aic_inb(p
, SIMODE1
) | ENREQINIT
, SIMODE1
);
5116 unsigned char scb_index
= aic_inb(p
, SCB_TAG
);
5117 unsigned char lastphase
= aic_inb(p
, LASTPHASE
);
5120 scb
= (p
->scb_data
->scb_array
[scb_index
]);
5122 * XXX - What do we really want to do on an overrun? The
5123 * mid-level SCSI code should handle this, but for now,
5124 * we'll just indicate that the command should retried.
5125 * If we retrieved sense info on this target, then the
5126 * base SENSE info should have been saved prior to the
5127 * overrun error. In that case, we return DID_OK and let
5128 * the mid level code pick up on the sense info. Otherwise
5129 * we return DID_ERROR so the command will get retried.
5131 if ( !(scb
->flags
& SCB_SENSE
) )
5133 printk(WARN_LEAD
"Data overrun detected in %s phase, tag %d;\n",
5134 p
->host_no
, CTL_OF_SCB(scb
),
5135 (lastphase
== P_DATAIN
) ? "Data-In" : "Data-Out", scb
->hscb
->tag
);
5136 printk(KERN_WARNING
" %s seen Data Phase. Length=%d, NumSGs=%d.\n",
5137 (aic_inb(p
, SEQ_FLAGS
) & DPHASE
) ? "Have" : "Haven't",
5138 scb
->sg_length
, scb
->sg_count
);
5139 for (i
= 0; i
< scb
->sg_count
; i
++)
5141 printk(KERN_WARNING
" sg[%d] - Addr 0x%x : Length %d\n",
5143 le32_to_cpu(scb
->sg_list
[i
].address
),
5144 le32_to_cpu(scb
->sg_list
[i
].length
) );
5146 aic7xxx_error(scb
->cmd
) = DID_ERROR
;
5149 printk(INFO_LEAD
"Data Overrun during SEND_SENSE operation.\n",
5150 p
->host_no
, CTL_OF_SCB(scb
));
5156 unsigned char resid_sgcnt
, index
;
5157 unsigned char scb_index
= aic_inb(p
, SCB_TAG
);
5158 unsigned int cur_addr
, resid_dcnt
;
5159 unsigned int native_addr
, native_length
;
5162 if(scb_index
> p
->scb_data
->numscbs
)
5164 printk(WARN_LEAD
"invalid scb_index during WIDE_RESIDUE.\n",
5165 p
->host_no
, -1, -1, -1);
5167 * XXX: Add error handling here
5171 scb
= p
->scb_data
->scb_array
[scb_index
];
5172 if(!(scb
->flags
& SCB_ACTIVE
) || (scb
->cmd
== NULL
))
5174 printk(WARN_LEAD
"invalid scb during WIDE_RESIDUE flags:0x%x "
5175 "scb->cmd:0x%lx\n", p
->host_no
, CTL_OF_SCB(scb
),
5176 scb
->flags
, (unsigned long)scb
->cmd
);
5181 * We have a valid scb to use on this WIDE_RESIDUE message, so
5182 * we need to walk the sg list looking for this particular sg
5183 * segment, then see if we happen to be at the very beginning of
5184 * the segment. If we are, then we have to back things up to
5185 * the previous segment. If not, then we simply need to remove
5186 * one byte from this segments address and add one to the byte
5189 cur_addr
= aic_inb(p
, SHADDR
) | (aic_inb(p
, SHADDR
+ 1) << 8) |
5190 (aic_inb(p
, SHADDR
+ 2) << 16) | (aic_inb(p
, SHADDR
+ 3) << 24);
5191 resid_sgcnt
= aic_inb(p
, SCB_RESID_SGCNT
);
5192 resid_dcnt
= aic_inb(p
, SCB_RESID_DCNT
) |
5193 (aic_inb(p
, SCB_RESID_DCNT
+ 1) << 8) |
5194 (aic_inb(p
, SCB_RESID_DCNT
+ 2) << 16);
5195 index
= scb
->sg_count
- (resid_sgcnt
+ 1);
5196 native_addr
= le32_to_cpu(scb
->sg_list
[index
].address
);
5197 native_length
= le32_to_cpu(scb
->sg_list
[index
].length
);
5199 * Make sure this is a valid sg_seg for the given pointer
5201 if(cur_addr
< native_addr
||
5202 cur_addr
> (native_addr
+ native_length
+ 1))
5204 printk(WARN_LEAD
"invalid cur_addr:0x%x during WIDE_RESIDUE\n",
5205 p
->host_no
, CTL_OF_SCB(scb
), cur_addr
);
5207 printk(WARN_LEAD
" sg_address[-1]:0x%x sg_length[-1]:%d\n",
5208 p
->host_no
, CTL_OF_SCB(scb
),
5209 le32_to_cpu(scb
->sg_list
[index
- 1].address
),
5210 le32_to_cpu(scb
->sg_list
[index
- 1].length
));
5211 printk(WARN_LEAD
" sg_address:0x%x sg_length:%d\n",
5212 p
->host_no
, CTL_OF_SCB(scb
),
5213 native_addr
, native_length
);
5215 printk(WARN_LEAD
" sg_address[1]:0x%x sg_length[1]:%d\n",
5216 p
->host_no
, CTL_OF_SCB(scb
),
5217 le32_to_cpu(scb
->sg_list
[index
+ 1].address
),
5218 le32_to_cpu(scb
->sg_list
[index
+ 1].length
));
5219 printk(WARN_LEAD
" cur_address:0x%x resid_dcnt:0x%06x\n",
5220 p
->host_no
, CTL_OF_SCB(scb
),
5221 cur_addr
, resid_dcnt
);
5225 if( (resid_sgcnt
== 0) &&
5226 ((resid_dcnt
== 0) || (resid_dcnt
== 0xffffff)))
5229 * We are at the end of the transfer and this is about a byte
5230 * we ignored already (because the sequencer knew this was
5231 * the last segment and set the adapter to ignore any wide
5232 * residue bytes that might come through, which is only done
5233 * on the last scatter gather segment of transfers).
5237 else if(cur_addr
== native_addr
)
5240 * If our current address matches the sg_seg->address then we
5241 * have to back up the sg array to the previous segment and set
5242 * it up to have only one byte of transfer left to go.
5246 printk(WARN_LEAD
"bogus WIDE_RESIDUE message, no data has been "
5247 "transferred.\n", p
->host_no
, CTL_OF_SCB(scb
));
5252 cur_addr
= le32_to_cpu(scb
->sg_list
[index
].address
) +
5253 le32_to_cpu(scb
->sg_list
[index
].length
) - 1;
5254 native_addr
= aic_inb(p
, SG_NEXT
) | (aic_inb(p
, SG_NEXT
+ 1) << 8)
5255 | (aic_inb(p
, SG_NEXT
+ 2) << 16) | (aic_inb(p
, SG_NEXT
+ 3) << 24);
5256 native_addr
-= SG_SIZEOF
;
5257 aic_outb(p
, resid_sgcnt
, SG_COUNT
);
5258 aic_outb(p
, resid_sgcnt
, SCB_RESID_SGCNT
);
5259 aic_outb(p
, native_addr
& 0xff, SG_NEXT
);
5260 aic_outb(p
, (native_addr
>> 8) & 0xff, SG_NEXT
+ 1);
5261 aic_outb(p
, (native_addr
>> 16) & 0xff, SG_NEXT
+ 2);
5262 aic_outb(p
, (native_addr
>> 24) & 0xff, SG_NEXT
+ 3);
5263 aic_outb(p
, 1, SCB_RESID_DCNT
);
5264 aic_outb(p
, 0, SCB_RESID_DCNT
+ 1);
5265 aic_outb(p
, 0, SCB_RESID_DCNT
+ 2);
5266 aic_outb(p
, 1, HCNT
);
5267 aic_outb(p
, 0, HCNT
+ 1);
5268 aic_outb(p
, 0, HCNT
+ 2);
5269 aic_outb(p
, cur_addr
& 0xff, HADDR
);
5270 aic_outb(p
, (cur_addr
>> 8) & 0xff, HADDR
+ 1);
5271 aic_outb(p
, (cur_addr
>> 16) & 0xff, HADDR
+ 2);
5272 aic_outb(p
, (cur_addr
>> 24) & 0xff, HADDR
+ 3);
5277 * Back the data pointer up by one and add one to the remaining
5278 * byte count. Then store that in the HCNT and HADDR registers.
5282 aic_outb(p
, resid_dcnt
& 0xff, SCB_RESID_DCNT
);
5283 aic_outb(p
, (resid_dcnt
>> 8) & 0xff, SCB_RESID_DCNT
+ 1);
5284 aic_outb(p
, (resid_dcnt
>> 16) & 0xff, SCB_RESID_DCNT
+ 2);
5285 aic_outb(p
, resid_dcnt
& 0xff, HCNT
);
5286 aic_outb(p
, (resid_dcnt
>> 8) & 0xff, HCNT
+ 1);
5287 aic_outb(p
, (resid_dcnt
>> 16) & 0xff, HCNT
+ 2);
5288 aic_outb(p
, cur_addr
& 0xff, HADDR
);
5289 aic_outb(p
, (cur_addr
>> 8) & 0xff, HADDR
+ 1);
5290 aic_outb(p
, (cur_addr
>> 16) & 0xff, HADDR
+ 2);
5291 aic_outb(p
, (cur_addr
>> 24) & 0xff, HADDR
+ 3);
5294 * The sequencer actually wants to find the new address and byte
5295 * count in the SHCNT and SHADDR register sets. These registers
5296 * are a shadow of the regular HCNT and HADDR registers. On the
5297 * Ultra2 controllers, these registers are read only and the way
5298 * we have to set their values is to put the values we want into
5299 * the HCNT and HADDR registers and then output PRELOADEN into
5300 * the DFCNTRL register which causes the card to latch the current
5301 * values in the HADDR and HCNT registers and drop it through to
5302 * the shadow registers. On older cards we copy them directly
5305 if(p
->features
& AHC_ULTRA2
)
5307 aic_outb(p
, aic_inb(p
, DMAPARAMS
), DFCNTRL
);
5310 while(((aic_inb(p
, SSTAT0
) & SDONE
) != 0) && (i
++ < 1000))
5314 aic_outb(p
, aic_inb(p
, DMAPARAMS
) & ~(SCSIEN
|HDMAEN
), DFCNTRL
);
5317 while(((aic_inb(p
, DFCNTRL
) & (SCSIEN
|HDMAEN
)) != 0) && (i
++ < 1000))
5324 aic_outb(p
, resid_dcnt
& 0xff, STCNT
);
5325 aic_outb(p
, (resid_dcnt
>> 8) & 0xff, STCNT
+ 1);
5326 aic_outb(p
, (resid_dcnt
>> 16) & 0xff, STCNT
+ 2);
5327 aic_outb(p
, cur_addr
& 0xff, SHADDR
);
5328 aic_outb(p
, (cur_addr
>> 8) & 0xff, SHADDR
+ 1);
5329 aic_outb(p
, (cur_addr
>> 16) & 0xff, SHADDR
+ 2);
5330 aic_outb(p
, (cur_addr
>> 24) & 0xff, SHADDR
+ 3);
5339 printk(INFO_LEAD
"Tracepoint #1 reached.\n", p
->host_no
,
5340 channel
, target
, lun
);
5346 printk(INFO_LEAD
"Tracepoint #2 reached.\n", p
->host_no
,
5347 channel
, target
, lun
);
5351 /* XXX Fill these in later */
5352 case MSG_BUFFER_BUSY
:
5353 printk("aic7xxx: Message buffer busy.\n");
5355 case MSGIN_PHASEMIS
:
5356 printk("aic7xxx: Message-in phasemis.\n");
5360 default: /* unknown */
5361 printk(WARN_LEAD
"Unknown SEQINT, INTSTAT 0x%x, SCSISIGI 0x%x.\n",
5362 p
->host_no
, channel
, target
, lun
, intstat
,
5363 aic_inb(p
, SCSISIGI
));
5368 * Clear the sequencer interrupt and unpause the sequencer.
5370 unpause_sequencer(p
, /* unpause always */ TRUE
);
5373 /*+F*************************************************************************
5378 * Parses incoming messages into actions on behalf of
5379 * aic7xxx_handle_reqinit
5380 *_F*************************************************************************/
5382 aic7xxx_parse_msg(struct aic7xxx_host
*p
, struct aic7xxx_scb
*scb
)
5384 int reject
, reply
, done
;
5385 unsigned char target_scsirate
, tindex
;
5386 unsigned short target_mask
;
5387 unsigned char target
, channel
, lun
;
5389 target
= scb
->cmd
->target
;
5390 channel
= scb
->cmd
->channel
;
5391 lun
= scb
->cmd
->lun
;
5392 reply
= reject
= done
= FALSE
;
5393 tindex
= TARGET_INDEX(scb
->cmd
);
5394 target_scsirate
= aic_inb(p
, TARG_SCSIRATE
+ tindex
);
5395 target_mask
= (0x01 << tindex
);
5398 * Parse as much of the message as is availible,
5399 * rejecting it if we don't support it. When
5400 * the entire message is availible and has been
5401 * handled, return TRUE indicating that we have
5402 * parsed an entire message.
5405 if (p
->msg_buf
[0] != MSG_EXTENDED
)
5411 * Just accept the length byte outright and perform
5412 * more checking once we know the message type.
5415 if ( !reject
&& (p
->msg_len
> 2) )
5417 switch(p
->msg_buf
[2])
5421 unsigned int period
, offset
;
5422 unsigned char maxsync
, saved_offset
, options
;
5423 struct aic7xxx_syncrate
*syncrate
;
5425 if (p
->msg_buf
[1] != MSG_EXT_SDTR_LEN
)
5431 if (p
->msg_len
< (MSG_EXT_SDTR_LEN
+ 2))
5436 period
= p
->msg_buf
[3];
5437 saved_offset
= offset
= p
->msg_buf
[4];
5441 * Even if we are an Ultra3 card, don't allow Ultra3 sync rates when
5442 * using the SDTR messages. We need the PPR messages to enable the
5443 * higher speeds that include things like Dual Edge clocking.
5445 if (p
->features
& AHC_ULTRA2
)
5447 if ( (aic_inb(p
, SBLKCTL
) & ENAB40
) &&
5448 !(aic_inb(p
, SSTAT2
) & EXP_ACTIVE
) )
5450 maxsync
= AHC_SYNCRATE_ULTRA2
;
5454 maxsync
= AHC_SYNCRATE_ULTRA
;
5457 else if (p
->features
& AHC_ULTRA
)
5459 maxsync
= AHC_SYNCRATE_ULTRA
;
5463 maxsync
= AHC_SYNCRATE_FAST
;
5466 * We might have a device that is starting negotiation with us
5467 * before we can start up negotiation with it....be prepared to
5468 * have a device ask for a higher speed then we want to give it
5471 if ( (scb
->flags
& (SCB_MSGOUT_SENT
|SCB_MSGOUT_SDTR
)) !=
5472 (SCB_MSGOUT_SENT
|SCB_MSGOUT_SDTR
) )
5474 if (!(p
->dev_flags
[tindex
] & DEVICE_SCANNED
) &&
5475 !(p
->needsdtr_copy
& target_mask
) &&
5476 (p
->transinfo
[tindex
].user_offset
) )
5479 * Not only is the device starting this up, but it also hasn't
5480 * been scanned yet, so this would likely be our TUR or our
5481 * INQUIRY command at scan time, so we need to use the
5482 * settings from the SEEPROM if they existed. Of course, even
5483 * if we didn't find a SEEPROM, we stuffed default values into
5484 * the user settings anyway, so use those in all cases.
5486 p
->transinfo
[tindex
].goal_period
=
5487 p
->transinfo
[tindex
].user_period
;
5488 if(p
->features
& AHC_ULTRA2
)
5490 p
->transinfo
[tindex
].goal_offset
= MAX_OFFSET_ULTRA2
;
5492 else if (p
->transinfo
[tindex
].cur_width
)
5494 p
->transinfo
[tindex
].goal_offset
= MAX_OFFSET_16BIT
;
5498 p
->transinfo
[tindex
].goal_offset
= MAX_OFFSET_8BIT
;
5500 p
->needsdtr_copy
|= target_mask
;
5502 if (aic7xxx_verbose
& VERBOSE_NEGOTIATION2
)
5504 printk(INFO_LEAD
"Received pre-emptive SDTR message from "
5505 "target.\n", p
->host_no
, CTL_OF_SCB(scb
));
5507 if ( !p
->transinfo
[tindex
].goal_offset
)
5509 if ( p
->transinfo
[tindex
].goal_period
> period
)
5510 period
= p
->transinfo
[tindex
].goal_period
;
5513 syncrate
= aic7xxx_find_syncrate(p
, &period
, maxsync
, &options
);
5514 aic7xxx_validate_offset(p
, syncrate
, &offset
,
5515 target_scsirate
& WIDEXFER
);
5516 aic7xxx_set_syncrate(p
, syncrate
, target
, channel
, period
,
5517 offset
, options
, AHC_TRANS_ACTIVE
|AHC_TRANS_CUR
);
5520 * Did we drop to async? Or are we sending a reply? If we are,
5521 * then we have to make sure that the reply value reflects the proper
5522 * settings so we need to set the goal values according to what
5525 if ( (offset
!= saved_offset
) ||
5526 ((scb
->flags
& (SCB_MSGOUT_SENT
|SCB_MSGOUT_SDTR
)) !=
5527 (SCB_MSGOUT_SENT
|SCB_MSGOUT_SDTR
) ) )
5529 aic7xxx_set_syncrate(p
, syncrate
, target
, channel
, period
, offset
,
5530 options
, AHC_TRANS_GOAL
|AHC_TRANS_QUITE
);
5534 * Did we start this, if not, or if we went to low and had to
5535 * go async, then send an SDTR back to the target
5537 p
->needsdtr
&= ~target_mask
;
5538 p
->dtr_pending
&= ~target_mask
;
5539 if ( ((scb
->flags
& (SCB_MSGOUT_SENT
|SCB_MSGOUT_SDTR
)) !=
5540 (SCB_MSGOUT_SENT
|SCB_MSGOUT_SDTR
)) ||
5541 (offset
!= saved_offset
) )
5544 p
->dtr_pending
|= target_mask
;
5545 scb
->flags
&= ~SCB_MSGOUT_BITS
;
5546 scb
->flags
|= SCB_MSGOUT_SDTR
;
5547 aic_outb(p
, HOST_MSG
, MSG_OUT
);
5548 aic_outb(p
, aic_inb(p
, SCSISIGO
) | ATNO
, SCSISIGO
);
5555 unsigned char bus_width
;
5557 if (p
->msg_buf
[1] != MSG_EXT_WDTR_LEN
)
5563 if (p
->msg_len
< (MSG_EXT_WDTR_LEN
+ 2))
5568 bus_width
= p
->msg_buf
[3];
5569 if ( (scb
->flags
& (SCB_MSGOUT_SENT
|SCB_MSGOUT_WDTR
)) ==
5570 (SCB_MSGOUT_SENT
|SCB_MSGOUT_WDTR
) )
5577 if ( (aic7xxx_verbose
& VERBOSE_NEGOTIATION2
) &&
5578 ((p
->dev_flags
[tindex
] & DEVICE_PRINT_DTR
) ||
5579 (aic7xxx_verbose
> 0xffff)) )
5581 printk(INFO_LEAD
"Requesting %d bit transfers, rejecting.\n",
5582 p
->host_no
, CTL_OF_SCB(scb
), 8 * (0x01 << bus_width
));
5584 } /* We fall through on purpose */
5585 case MSG_EXT_WDTR_BUS_8_BIT
:
5587 bus_width
= MSG_EXT_WDTR_BUS_8_BIT
;
5588 p
->needwdtr_copy
&= ~target_mask
;
5591 case MSG_EXT_WDTR_BUS_16_BIT
:
5596 p
->dtr_pending
&= ~target_mask
;
5597 p
->needwdtr
&= ~target_mask
;
5601 if ( !(p
->dev_flags
[tindex
] & DEVICE_SCANNED
) )
5604 * Well, we now know the WDTR and SYNC caps of this device since
5605 * it contacted us first, mark it as such and copy the user stuff
5606 * over to the goal stuff.
5608 p
->transinfo
[tindex
].goal_period
=
5609 p
->transinfo
[tindex
].user_period
;
5610 if(p
->transinfo
[tindex
].user_offset
)
5612 if(p
->features
& AHC_ULTRA2
)
5614 p
->transinfo
[tindex
].goal_offset
= MAX_OFFSET_ULTRA2
;
5616 else if( p
->transinfo
[tindex
].user_width
&&
5617 (bus_width
== MSG_EXT_WDTR_BUS_16_BIT
) &&
5618 p
->features
& AHC_WIDE
)
5620 p
->transinfo
[tindex
].goal_offset
= MAX_OFFSET_16BIT
;
5624 p
->transinfo
[tindex
].goal_offset
= MAX_OFFSET_8BIT
;
5627 p
->transinfo
[tindex
].goal_width
=
5628 p
->transinfo
[tindex
].user_width
;
5629 p
->needwdtr_copy
|= target_mask
;
5630 p
->needsdtr_copy
|= target_mask
;
5632 if (aic7xxx_verbose
& VERBOSE_NEGOTIATION2
)
5634 printk(INFO_LEAD
"Received pre-emptive WDTR message from "
5635 "target.\n", p
->host_no
, CTL_OF_SCB(scb
));
5641 if ( (p
->features
& AHC_WIDE
) &&
5642 (p
->transinfo
[tindex
].goal_width
==
5643 MSG_EXT_WDTR_BUS_16_BIT
) )
5645 bus_width
= MSG_EXT_WDTR_BUS_16_BIT
;
5648 } /* Fall through if we aren't a wide card */
5649 case MSG_EXT_WDTR_BUS_8_BIT
:
5651 p
->needwdtr_copy
&= ~target_mask
;
5652 bus_width
= MSG_EXT_WDTR_BUS_8_BIT
;
5653 aic7xxx_set_width(p
, target
, channel
, lun
, bus_width
,
5654 AHC_TRANS_GOAL
|AHC_TRANS_QUITE
);
5659 scb
->flags
&= ~SCB_MSGOUT_BITS
;
5660 scb
->flags
|= SCB_MSGOUT_WDTR
;
5661 p
->needwdtr
&= ~target_mask
;
5662 p
->dtr_pending
|= target_mask
;
5663 aic_outb(p
, HOST_MSG
, MSG_OUT
);
5664 aic_outb(p
, aic_inb(p
, SCSISIGO
) | ATNO
, SCSISIGO
);
5666 aic7xxx_set_width(p
, target
, channel
, lun
, bus_width
,
5667 AHC_TRANS_ACTIVE
|AHC_TRANS_CUR
);
5670 * By virtue of the SCSI spec, a WDTR message negates any existing
5671 * SDTR negotiations. So, even if needsdtr isn't marked for this
5672 * device, we still have to do a new SDTR message if the device
5673 * supports SDTR at all. Therefore, we check needsdtr_copy instead
5676 aic7xxx_set_syncrate(p
, NULL
, target
, channel
, 0, 0, 0,
5677 AHC_TRANS_ACTIVE
|AHC_TRANS_CUR
|AHC_TRANS_QUITE
);
5678 p
->needsdtr
|= (p
->needsdtr_copy
& target_mask
);
5684 unsigned char bus_width
, trans_options
, new_trans_options
;
5685 unsigned int period
, offset
;
5686 unsigned char maxsync
, saved_offset
;
5687 struct aic7xxx_syncrate
*syncrate
;
5689 if (p
->msg_buf
[1] != MSG_EXT_PPR_LEN
)
5695 if (p
->msg_len
< (MSG_EXT_PPR_LEN
+ 2))
5700 period
= p
->msg_buf
[3];
5701 offset
= saved_offset
= p
->msg_buf
[5];
5702 bus_width
= p
->msg_buf
[6];
5703 trans_options
= new_trans_options
= p
->msg_buf
[7] & 0xf;
5705 if(aic7xxx_verbose
& VERBOSE_NEGOTIATION2
)
5707 printk(INFO_LEAD
"Parsing PPR message (%d/%d/%d/%d)\n",
5708 p
->host_no
, CTL_OF_SCB(scb
), period
, offset
, bus_width
,
5712 if ( (aic_inb(p
, SBLKCTL
) & ENAB40
) &&
5713 !(aic_inb(p
, SSTAT2
) & EXP_ACTIVE
) )
5715 if(p
->features
& AHC_ULTRA3
)
5717 maxsync
= AHC_SYNCRATE_ULTRA3
;
5721 maxsync
= AHC_SYNCRATE_ULTRA2
;
5726 maxsync
= AHC_SYNCRATE_ULTRA
;
5729 * We might have a device that is starting negotiation with us
5730 * before we can start up negotiation with it....be prepared to
5731 * have a device ask for a higher speed then we want to give it
5734 if ( (scb
->flags
& (SCB_MSGOUT_SENT
|SCB_MSGOUT_PPR
)) !=
5735 (SCB_MSGOUT_SENT
|SCB_MSGOUT_PPR
) )
5738 scb
->flags
&= ~SCB_MSGOUT_BITS
;
5739 scb
->flags
|= SCB_MSGOUT_PPR
;
5740 p
->dev_flags
[tindex
] |= DEVICE_SCSI_3
;
5741 if (!(p
->dev_flags
[tindex
] & DEVICE_SCANNED
))
5744 * Not only is the device starting this up, but it also hasn't
5745 * been scanned yet, so this would likely be our TUR or our
5746 * INQUIRY command at scan time, so we need to use the
5747 * settings from the SEEPROM if they existed. Of course, even
5748 * if we didn't find a SEEPROM, we stuffed default values into
5749 * the user settings anyway, so use those in all cases.
5751 p
->transinfo
[tindex
].goal_period
=
5752 p
->transinfo
[tindex
].user_period
;
5753 if(p
->transinfo
[tindex
].user_offset
)
5755 if(p
->features
& AHC_ULTRA2
)
5757 p
->transinfo
[tindex
].goal_offset
= MAX_OFFSET_ULTRA2
;
5759 else if( p
->transinfo
[tindex
].user_width
&&
5760 (bus_width
== MSG_EXT_WDTR_BUS_16_BIT
) &&
5761 p
->features
& AHC_WIDE
)
5763 p
->transinfo
[tindex
].goal_offset
= MAX_OFFSET_16BIT
;
5767 p
->transinfo
[tindex
].goal_offset
= MAX_OFFSET_8BIT
;
5770 p
->transinfo
[tindex
].goal_width
=
5771 p
->transinfo
[tindex
].user_width
;
5772 p
->transinfo
[tindex
].goal_options
=
5773 p
->transinfo
[tindex
].user_options
;
5775 if (aic7xxx_verbose
& VERBOSE_NEGOTIATION2
)
5777 printk(INFO_LEAD
"Received pre-emptive PPR message from "
5778 "target.\n", p
->host_no
, CTL_OF_SCB(scb
));
5780 if ( !p
->transinfo
[tindex
].goal_offset
)
5782 if ( p
->transinfo
[tindex
].goal_period
> period
)
5783 period
= p
->transinfo
[tindex
].goal_period
;
5784 if ( p
->transinfo
[tindex
].goal_options
== 0 )
5785 new_trans_options
= 0;
5790 if ( (p
->features
& AHC_WIDE
) &&
5791 (p
->transinfo
[tindex
].goal_width
==
5792 MSG_EXT_WDTR_BUS_16_BIT
) )
5794 bus_width
= MSG_EXT_WDTR_BUS_16_BIT
;
5797 } /* Fall through if we aren't a wide card */
5798 case MSG_EXT_WDTR_BUS_8_BIT
:
5800 p
->needwdtr_copy
&= ~target_mask
;
5801 bus_width
= MSG_EXT_WDTR_BUS_8_BIT
;
5802 aic7xxx_set_width(p
, target
, channel
, lun
, bus_width
,
5803 AHC_TRANS_GOAL
|AHC_TRANS_QUITE
);
5807 if ( (p
->transinfo
[tindex
].goal_period
> 9) ||
5808 (p
->transinfo
[tindex
].goal_options
== 0) )
5810 scb
->flags
&= ~SCB_MSGOUT_BITS
;
5813 p
->needppr
&= ~(1 << tindex
);
5814 p
->needppr_copy
&= ~(1 << tindex
);
5815 if ( p
->transinfo
[tindex
].goal_offset
)
5817 p
->needsdtr
|= (1 << tindex
);
5818 p
->needsdtr_copy
|= (1 << tindex
);
5820 if ( p
->transinfo
[tindex
].goal_width
)
5822 p
->needwdtr
|= (1 << tindex
);
5823 p
->needwdtr_copy
|= (1 << tindex
);
5834 if ( (aic7xxx_verbose
& VERBOSE_NEGOTIATION2
) &&
5835 ((p
->dev_flags
[tindex
] & DEVICE_PRINT_DTR
) ||
5836 (aic7xxx_verbose
> 0xffff)) )
5838 printk(INFO_LEAD
"Requesting %d bit transfers, rejecting.\n",
5839 p
->host_no
, CTL_OF_SCB(scb
), 8 * (0x01 << bus_width
));
5841 } /* We fall through on purpose */
5842 case MSG_EXT_WDTR_BUS_8_BIT
:
5845 * According to the spec, if we aren't wide, we also can't be
5846 * Dual Edge so clear the options byte
5848 new_trans_options
= 0;
5849 bus_width
= MSG_EXT_WDTR_BUS_8_BIT
;
5852 case MSG_EXT_WDTR_BUS_16_BIT
:
5861 aic7xxx_set_width(p
, target
, channel
, lun
, bus_width
,
5862 AHC_TRANS_ACTIVE
|AHC_TRANS_CUR
);
5863 syncrate
= aic7xxx_find_syncrate(p
, &period
, maxsync
,
5864 &new_trans_options
);
5865 aic7xxx_validate_offset(p
, syncrate
, &offset
, bus_width
);
5866 aic7xxx_set_syncrate(p
, syncrate
, target
, channel
, period
,
5867 offset
, new_trans_options
,
5868 AHC_TRANS_ACTIVE
|AHC_TRANS_CUR
);
5871 p
->dtr_pending
&= ~target_mask
;
5872 p
->needppr
&= ~target_mask
;
5875 p
->dtr_pending
|= target_mask
;
5876 scb
->flags
&= ~SCB_MSGOUT_BITS
;
5877 scb
->flags
|= SCB_MSGOUT_PPR
;
5878 aic_outb(p
, HOST_MSG
, MSG_OUT
);
5879 aic_outb(p
, aic_inb(p
, SCSISIGO
) | ATNO
, SCSISIGO
);
5889 } /* end of switch(p->msg_type) */
5890 } /* end of if (!reject && (p->msg_len > 2)) */
5892 if (!reply
&& reject
)
5894 aic_outb(p
, MSG_MESSAGE_REJECT
, MSG_OUT
);
5895 aic_outb(p
, aic_inb(p
, SCSISIGO
) | ATNO
, SCSISIGO
);
5902 /*+F*************************************************************************
5904 * aic7xxx_handle_reqinit
5907 * Interrupt handler for REQINIT interrupts (used to transfer messages to
5908 * and from devices).
5909 *_F*************************************************************************/
5911 aic7xxx_handle_reqinit(struct aic7xxx_host
*p
, struct aic7xxx_scb
*scb
)
5913 unsigned char lastbyte
;
5914 unsigned char phasemis
;
5919 case MSG_TYPE_INITIATOR_MSGOUT
:
5921 if (p
->msg_len
== 0)
5922 panic("aic7xxx: REQINIT with no active message!\n");
5924 lastbyte
= (p
->msg_index
== (p
->msg_len
- 1));
5925 phasemis
= ( aic_inb(p
, SCSISIGI
) & PHASE_MASK
) != P_MESGOUT
;
5927 if (lastbyte
|| phasemis
)
5929 /* Time to end the message */
5931 p
->msg_type
= MSG_TYPE_NONE
;
5933 * NOTE-TO-MYSELF: If you clear the REQINIT after you
5934 * disable REQINITs, then cases of REJECT_MSG stop working
5937 aic_outb(p
, aic_inb(p
, SIMODE1
) & ~ENREQINIT
, SIMODE1
);
5938 aic_outb(p
, CLRSCSIINT
, CLRINT
);
5939 p
->flags
&= ~AHC_HANDLING_REQINITS
;
5943 aic_outb(p
, p
->msg_buf
[p
->msg_index
], SINDEX
);
5944 aic_outb(p
, 0, RETURN_1
);
5945 #ifdef AIC7XXX_VERBOSE_DEBUGGING
5946 if (aic7xxx_verbose
> 0xffff)
5947 printk(INFO_LEAD
"Completed sending of REQINIT message.\n",
5948 p
->host_no
, CTL_OF_SCB(scb
));
5953 aic_outb(p
, MSGOUT_PHASEMIS
, RETURN_1
);
5954 #ifdef AIC7XXX_VERBOSE_DEBUGGING
5955 if (aic7xxx_verbose
> 0xffff)
5956 printk(INFO_LEAD
"PHASEMIS while sending REQINIT message.\n",
5957 p
->host_no
, CTL_OF_SCB(scb
));
5960 unpause_sequencer(p
, TRUE
);
5965 * Present the byte on the bus (clearing REQINIT) but don't
5966 * unpause the sequencer.
5968 aic_outb(p
, CLRREQINIT
, CLRSINT1
);
5969 aic_outb(p
, CLRSCSIINT
, CLRINT
);
5970 aic_outb(p
, p
->msg_buf
[p
->msg_index
++], SCSIDATL
);
5974 case MSG_TYPE_INITIATOR_MSGIN
:
5976 phasemis
= ( aic_inb(p
, SCSISIGI
) & PHASE_MASK
) != P_MESGIN
;
5981 /* Pull the byte in without acking it */
5982 p
->msg_buf
[p
->msg_index
] = aic_inb(p
, SCSIBUSL
);
5983 done
= aic7xxx_parse_msg(p
, scb
);
5985 aic_outb(p
, CLRREQINIT
, CLRSINT1
);
5986 aic_outb(p
, CLRSCSIINT
, CLRINT
);
5987 aic_inb(p
, SCSIDATL
);
5990 if (phasemis
|| done
)
5992 #ifdef AIC7XXX_VERBOSE_DEBUGGING
5993 if (aic7xxx_verbose
> 0xffff)
5996 printk(INFO_LEAD
"PHASEMIS while receiving REQINIT message.\n",
5997 p
->host_no
, CTL_OF_SCB(scb
));
5999 printk(INFO_LEAD
"Completed receipt of REQINIT message.\n",
6000 p
->host_no
, CTL_OF_SCB(scb
));
6003 /* Time to end our message session */
6005 p
->msg_type
= MSG_TYPE_NONE
;
6006 aic_outb(p
, aic_inb(p
, SIMODE1
) & ~ENREQINIT
, SIMODE1
);
6007 aic_outb(p
, CLRSCSIINT
, CLRINT
);
6008 p
->flags
&= ~AHC_HANDLING_REQINITS
;
6009 unpause_sequencer(p
, TRUE
);
6015 panic("aic7xxx: Unknown REQINIT message type.\n");
6018 } /* End of switch(p->msg_type) */
6021 /*+F*************************************************************************
6023 * aic7xxx_handle_scsiint
6026 * Interrupt handler for SCSI interrupts (SCSIINT).
6027 *-F*************************************************************************/
6029 aic7xxx_handle_scsiint(struct aic7xxx_host
*p
, unsigned char intstat
)
6031 unsigned char scb_index
;
6032 unsigned char status
;
6033 struct aic7xxx_scb
*scb
;
6035 scb_index
= aic_inb(p
, SCB_TAG
);
6036 status
= aic_inb(p
, SSTAT1
);
6038 if (scb_index
< p
->scb_data
->numscbs
)
6040 scb
= p
->scb_data
->scb_array
[scb_index
];
6041 if ((scb
->flags
& SCB_ACTIVE
) == 0)
6052 if ((status
& SCSIRSTI
) != 0)
6056 if ( (p
->chip
& AHC_CHIPID_MASK
) == AHC_AIC7770
)
6057 channel
= (aic_inb(p
, SBLKCTL
) & SELBUSB
) >> 3;
6061 if (aic7xxx_verbose
& VERBOSE_RESET
)
6062 printk(WARN_LEAD
"Someone else reset the channel!!\n",
6063 p
->host_no
, channel
, -1, -1);
6064 if (aic7xxx_panic_on_abort
)
6065 aic7xxx_panic_abort(p
, NULL
);
6067 * Go through and abort all commands for the channel, but do not
6068 * reset the channel again.
6070 aic7xxx_reset_channel(p
, channel
, /* Initiate Reset */ FALSE
);
6071 aic7xxx_run_done_queue(p
, TRUE
);
6074 else if ( ((status
& BUSFREE
) != 0) && ((status
& SELTO
) == 0) )
6077 * First look at what phase we were last in. If it's message-out,
6078 * chances are pretty good that the bus free was in response to
6079 * one of our abort requests.
6081 unsigned char lastphase
= aic_inb(p
, LASTPHASE
);
6082 unsigned char saved_tcl
= aic_inb(p
, SAVED_TCL
);
6083 unsigned char target
= (saved_tcl
>> 4) & 0x0F;
6085 int printerror
= TRUE
;
6087 if ( (p
->chip
& AHC_CHIPID_MASK
) == AHC_AIC7770
)
6088 channel
= (aic_inb(p
, SBLKCTL
) & SELBUSB
) >> 3;
6092 aic_outb(p
, aic_inb(p
, SCSISEQ
) & (ENSELI
|ENRSELI
|ENAUTOATNP
),
6094 if (lastphase
== P_MESGOUT
)
6096 unsigned char message
;
6098 message
= aic_inb(p
, SINDEX
);
6100 if ((message
== MSG_ABORT
) || (message
== MSG_ABORT_TAG
))
6102 if (aic7xxx_verbose
& VERBOSE_ABORT_PROCESS
)
6103 printk(INFO_LEAD
"SCB %d abort delivered.\n", p
->host_no
,
6104 CTL_OF_SCB(scb
), scb
->hscb
->tag
);
6105 aic7xxx_reset_device(p
, target
, channel
, ALL_LUNS
,
6106 (message
== MSG_ABORT
) ? SCB_LIST_NULL
: scb
->hscb
->tag
);
6107 aic7xxx_run_done_queue(p
, TRUE
);
6111 else if (message
== MSG_BUS_DEV_RESET
)
6113 aic7xxx_handle_device_reset(p
, target
, channel
);
6118 if ( (scb
!= NULL
) &&
6119 (scb
->cmd
== p
->dev_dtr_cmnd
[TARGET_INDEX(scb
->cmd
)]) )
6122 * This might be a SCSI-3 device that is dropping the bus due to
6123 * errors and signalling that we should reduce the transfer speed.
6124 * All we have to do is complete this command (since it's a negotiation
6125 * command already) and the checksum routine should flag an error and
6126 * reduce the speed setting and renegotiate. We call the reset routing
6127 * just to clean out the hardware from this scb.
6130 aic7xxx_reset_device(p
, target
, channel
, ALL_LUNS
, scb
->hscb
->tag
);
6131 aic7xxx_run_done_queue(p
, TRUE
);
6134 if (printerror
!= 0)
6140 if ((scb
->hscb
->control
& TAG_ENB
) != 0)
6142 tag
= scb
->hscb
->tag
;
6146 tag
= SCB_LIST_NULL
;
6148 aic7xxx_reset_device(p
, target
, channel
, ALL_LUNS
, tag
);
6149 aic7xxx_run_done_queue(p
, TRUE
);
6153 aic7xxx_reset_device(p
, target
, channel
, ALL_LUNS
, SCB_LIST_NULL
);
6154 aic7xxx_run_done_queue(p
, TRUE
);
6156 printk(INFO_LEAD
"Unexpected busfree, LASTPHASE = 0x%x, "
6157 "SEQADDR = 0x%x\n", p
->host_no
, channel
, target
, -1, lastphase
,
6158 (aic_inb(p
, SEQADDR1
) << 8) | aic_inb(p
, SEQADDR0
));
6161 aic_outb(p
, MSG_NOOP
, MSG_OUT
);
6162 aic_outb(p
, aic_inb(p
, SIMODE1
) & ~(ENBUSFREE
|ENREQINIT
),
6164 p
->flags
&= ~AHC_HANDLING_REQINITS
;
6165 aic_outb(p
, CLRBUSFREE
, CLRSINT1
);
6166 aic_outb(p
, CLRSCSIINT
, CLRINT
);
6167 restart_sequencer(p
);
6168 unpause_sequencer(p
, TRUE
);
6170 else if ((status
& SELTO
) != 0)
6172 unsigned char scbptr
;
6173 unsigned char nextscb
;
6176 scbptr
= aic_inb(p
, WAITING_SCBH
);
6177 if (scbptr
> p
->scb_data
->maxhscbs
)
6180 * I'm still trying to track down exactly how this happens, but until
6181 * I find it, this code will make sure we aren't passing bogus values
6182 * into the SCBPTR register, even if that register will just wrap
6183 * things around, we still don't like having out of range variables.
6185 * NOTE: Don't check the aic7xxx_verbose variable, I want this message
6186 * to always be displayed.
6188 printk(INFO_LEAD
"Invalid WAITING_SCBH value %d, improvising.\n",
6189 p
->host_no
, -1, -1, -1, scbptr
);
6190 if (p
->scb_data
->maxhscbs
> 4)
6191 scbptr
&= (p
->scb_data
->maxhscbs
- 1);
6195 aic_outb(p
, scbptr
, SCBPTR
);
6196 scb_index
= aic_inb(p
, SCB_TAG
);
6199 if (scb_index
< p
->scb_data
->numscbs
)
6201 scb
= p
->scb_data
->scb_array
[scb_index
];
6202 if ((scb
->flags
& SCB_ACTIVE
) == 0)
6209 printk(WARN_LEAD
"Referenced SCB %d not valid during SELTO.\n",
6210 p
->host_no
, -1, -1, -1, scb_index
);
6211 printk(KERN_WARNING
" SCSISEQ = 0x%x SEQADDR = 0x%x SSTAT0 = 0x%x "
6212 "SSTAT1 = 0x%x\n", aic_inb(p
, SCSISEQ
),
6213 aic_inb(p
, SEQADDR0
) | (aic_inb(p
, SEQADDR1
) << 8),
6214 aic_inb(p
, SSTAT0
), aic_inb(p
, SSTAT1
));
6215 if (aic7xxx_panic_on_abort
)
6216 aic7xxx_panic_abort(p
, NULL
);
6221 cmd
->result
= (DID_TIME_OUT
<< 16);
6224 * Clear out this hardware SCB
6226 aic_outb(p
, 0, SCB_CONTROL
);
6229 * Clear out a few values in the card that are in an undetermined
6232 aic_outb(p
, MSG_NOOP
, MSG_OUT
);
6235 * Shift the waiting for selection queue forward
6237 nextscb
= aic_inb(p
, SCB_NEXT
);
6238 aic_outb(p
, nextscb
, WAITING_SCBH
);
6241 * Put this SCB back on the free list.
6243 aic7xxx_add_curscb_to_free_list(p
);
6244 #ifdef AIC7XXX_VERBOSE_DEBUGGING
6245 if (aic7xxx_verbose
> 0xffff)
6246 printk(INFO_LEAD
"Selection Timeout.\n", p
->host_no
, CTL_OF_SCB(scb
));
6248 if (scb
->flags
& SCB_QUEUED_ABORT
)
6251 * We know that this particular SCB had to be the queued abort since
6252 * the disconnected SCB would have gotten a reconnect instead.
6253 * What we need to do then is to let the command timeout again so
6254 * we get a reset since this abort just failed.
6259 else if (scb
->cmd
== p
->dev_dtr_cmnd
[TARGET_INDEX(scb
->cmd
)])
6262 * Turn off the needsdtr, needwdtr, and needppr bits since this device
6263 * doesn't seem to exist.
6265 p
->needppr
&= ~(0x01 << TARGET_INDEX(scb
->cmd
));
6266 p
->needppr_copy
&= ~(0x01 << TARGET_INDEX(scb
->cmd
));
6267 p
->needsdtr
&= ~(0x01 << TARGET_INDEX(scb
->cmd
));
6268 p
->needsdtr_copy
&= ~(0x01 << TARGET_INDEX(scb
->cmd
));
6269 p
->needwdtr
&= ~(0x01 << TARGET_INDEX(scb
->cmd
));
6270 p
->needwdtr_copy
&= ~(0x01 << TARGET_INDEX(scb
->cmd
));
6274 * Keep the sequencer from trying to restart any selections
6276 aic_outb(p
, aic_inb(p
, SCSISEQ
) & ~ENSELO
, SCSISEQ
);
6278 * Make sure the data bits on the bus are released
6279 * Don't do this on 7770 chipsets, it makes them give us
6280 * a BRKADDRINT and kills the card.
6282 if( (p
->chip
& ~AHC_CHIPID_MASK
) == AHC_PCI
)
6283 aic_outb(p
, 0, SCSIBUSL
);
6286 * Delay for the selection timeout delay period then stop the selection
6289 aic_outb(p
, CLRSELINGO
, CLRSINT0
);
6291 * Clear out all the interrupt status bits
6293 aic_outb(p
, aic_inb(p
, SIMODE1
) & ~(ENREQINIT
|ENBUSFREE
), SIMODE1
);
6294 p
->flags
&= ~AHC_HANDLING_REQINITS
;
6295 aic_outb(p
, CLRSELTIMEO
| CLRBUSFREE
, CLRSINT1
);
6296 aic_outb(p
, CLRSCSIINT
, CLRINT
);
6298 * Restarting the sequencer will stop the selection and make sure devices
6299 * are allowed to reselect in.
6301 restart_sequencer(p
);
6302 unpause_sequencer(p
, TRUE
);
6304 else if (scb
== NULL
)
6306 printk(WARN_LEAD
"aic7xxx_isr - referenced scb not valid "
6307 "during scsiint 0x%x scb(%d)\n"
6308 " SIMODE0 0x%x, SIMODE1 0x%x, SSTAT0 0x%x, SEQADDR 0x%x\n",
6309 p
->host_no
, -1, -1, -1, status
, scb_index
, aic_inb(p
, SIMODE0
),
6310 aic_inb(p
, SIMODE1
), aic_inb(p
, SSTAT0
),
6311 (aic_inb(p
, SEQADDR1
) << 8) | aic_inb(p
, SEQADDR0
));
6313 * Turn off the interrupt and set status to zero, so that it
6314 * falls through the rest of the SCSIINT code.
6316 aic_outb(p
, status
, CLRSINT1
);
6317 aic_outb(p
, CLRSCSIINT
, CLRINT
);
6318 unpause_sequencer(p
, /* unpause always */ TRUE
);
6321 else if (status
& SCSIPERR
)
6324 * Determine the bus phase and queue an appropriate message.
6328 unsigned char mesg_out
= MSG_NOOP
;
6329 unsigned char lastphase
= aic_inb(p
, LASTPHASE
);
6330 unsigned char sstat2
= aic_inb(p
, SSTAT2
);
6331 unsigned char tindex
= TARGET_INDEX(scb
->cmd
);
6341 mesg_out
= MSG_INITIATOR_DET_ERR
;
6347 phase
= "Message-Out";
6351 mesg_out
= MSG_INITIATOR_DET_ERR
;
6354 phase
= "Message-In";
6355 mesg_out
= MSG_PARITY_ERROR
;
6363 * A parity error has occurred during a data
6364 * transfer phase. Flag it and continue.
6366 if( (p
->features
& AHC_ULTRA3
) &&
6367 (aic_inb(p
, SCSIRATE
) & AHC_SYNCRATE_CRC
) &&
6368 (lastphase
== P_DATAIN
) )
6370 printk(WARN_LEAD
"CRC error during %s phase.\n",
6371 p
->host_no
, CTL_OF_SCB(scb
), phase
);
6372 if(sstat2
& CRCVALERR
)
6374 printk(WARN_LEAD
" CRC error in intermediate CRC packet.\n",
6375 p
->host_no
, CTL_OF_SCB(scb
));
6377 if(sstat2
& CRCENDERR
)
6379 printk(WARN_LEAD
" CRC error in ending CRC packet.\n",
6380 p
->host_no
, CTL_OF_SCB(scb
));
6382 if(sstat2
& CRCREQERR
)
6384 printk(WARN_LEAD
" Target incorrectly requested a CRC packet.\n",
6385 p
->host_no
, CTL_OF_SCB(scb
));
6387 if(sstat2
& DUAL_EDGE_ERROR
)
6389 printk(WARN_LEAD
" Dual Edge transmission error.\n",
6390 p
->host_no
, CTL_OF_SCB(scb
));
6393 else if( (lastphase
== P_MESGOUT
) &&
6394 (cmd
== p
->dev_dtr_cmnd
[tindex
]) &&
6395 (scb
->flags
& SCB_MSGOUT_PPR
) )
6398 * As per the draft specs, any device capable of supporting any of
6399 * the option values other than 0 are not allowed to reject the
6400 * PPR message. Instead, they must negotiate out what they do
6401 * support instead of rejecting our offering or else they cause
6402 * a parity error during msg_out phase to signal that they don't
6403 * like our settings.
6405 p
->needppr
&= ~(1 << tindex
);
6406 p
->needppr_copy
&= ~(1 << tindex
);
6407 aic7xxx_set_width(p
, scb
->cmd
->target
, scb
->cmd
->channel
, scb
->cmd
->lun
,
6408 MSG_EXT_WDTR_BUS_8_BIT
,
6409 (AHC_TRANS_ACTIVE
|AHC_TRANS_CUR
|AHC_TRANS_QUITE
));
6410 aic7xxx_set_syncrate(p
, NULL
, scb
->cmd
->target
, scb
->cmd
->channel
, 0, 0,
6411 0, AHC_TRANS_ACTIVE
|AHC_TRANS_CUR
|AHC_TRANS_QUITE
);
6412 p
->transinfo
[tindex
].goal_options
= 0;
6413 p
->dtr_pending
&= ~(1 << tindex
);
6414 scb
->flags
&= ~SCB_MSGOUT_BITS
;
6415 if(aic7xxx_verbose
& VERBOSE_NEGOTIATION2
)
6417 printk(INFO_LEAD
"parity error during PPR message, reverting "
6418 "to WDTR/SDTR\n", p
->host_no
, CTL_OF_SCB(scb
));
6420 if ( p
->transinfo
[tindex
].goal_width
)
6422 p
->needwdtr
|= (1 << tindex
);
6423 p
->needwdtr_copy
|= (1 << tindex
);
6425 if ( p
->transinfo
[tindex
].goal_offset
)
6427 if( p
->transinfo
[tindex
].goal_period
<= 9 )
6429 p
->transinfo
[tindex
].goal_period
= 10;
6431 p
->needsdtr
|= (1 << tindex
);
6432 p
->needsdtr_copy
|= (1 << tindex
);
6436 else if(p
->dev_flags
[tindex
] & DEVICE_PARITY_ERROR
)
6438 struct aic7xxx_syncrate
*syncrate
;
6439 unsigned int period
= p
->transinfo
[tindex
].cur_period
;
6440 unsigned char options
= p
->transinfo
[tindex
].cur_options
;
6442 * oops, we had a failure, lower the transfer rate and try again. It's
6443 * worth noting here that it might be wise to also check for typical
6444 * wide setting on narrow cable type problems and try disabling wide
6445 * instead of slowing down if those exist. That's hard to do with simple
6448 printk(WARN_LEAD
"Parity error during %s phase.\n",
6449 p
->host_no
, CTL_OF_SCB(scb
), phase
);
6450 if((syncrate
= aic7xxx_find_syncrate(p
, &period
, 0, &options
)) != NULL
)
6453 if( (syncrate
->rate
[0] != NULL
) &&
6454 (!(p
->features
& AHC_ULTRA2
) || (syncrate
->sxfr_ultra2
== 0)) )
6456 p
->transinfo
[tindex
].goal_period
= syncrate
->period
;
6457 if( p
->transinfo
[tindex
].goal_period
> 9 )
6459 p
->transinfo
[tindex
].goal_options
= 0;
6460 p
->needppr
&= ~(1<<tindex
);
6461 p
->needsdtr
|= (1<<tindex
);
6462 p
->needppr_copy
&= ~(1<<tindex
);
6463 p
->needsdtr_copy
|= (1<<tindex
);
6464 if (p
->transinfo
[tindex
].goal_width
)
6466 p
->needwdtr
|= (1<<tindex
);
6467 p
->needwdtr_copy
|= (1<<tindex
);
6471 else if (p
->transinfo
[tindex
].goal_width
)
6473 p
->transinfo
[tindex
].goal_width
= 0;
6474 p
->needwdtr
&= ~(1<<tindex
);
6475 p
->needwdtr_copy
&= ~(1<<tindex
);
6476 p
->transinfo
[tindex
].goal_offset
=
6477 p
->transinfo
[tindex
].user_offset
;
6478 p
->transinfo
[tindex
].goal_period
=
6479 p
->transinfo
[tindex
].user_period
;
6480 p
->transinfo
[tindex
].goal_options
=
6481 p
->transinfo
[tindex
].user_options
;
6482 if( p
->transinfo
[tindex
].goal_period
<= 9 )
6484 p
->needppr
|= (1<<tindex
);
6485 p
->needsdtr
&= ~(1<<tindex
);
6486 p
->needppr_copy
|= (1<<tindex
);
6487 p
->needsdtr_copy
&= ~(1<<tindex
);
6491 p
->needppr
&= ~(1<<tindex
);
6492 p
->needsdtr
|= (1<<tindex
);
6493 p
->needppr_copy
&= ~(1<<tindex
);
6494 p
->needsdtr_copy
|= (1<<tindex
);
6499 p
->transinfo
[tindex
].goal_offset
= 0;
6500 p
->transinfo
[tindex
].goal_period
= 255;
6501 p
->transinfo
[tindex
].goal_options
= 0;
6502 p
->transinfo
[tindex
].goal_width
= 0;
6503 p
->needppr
&= ~(1<<tindex
);
6504 p
->needsdtr
&= ~(1<<tindex
);
6505 p
->needwdtr
&= ~(1<<tindex
);
6506 p
->needppr_copy
&= ~(1<<tindex
);
6507 p
->needsdtr_copy
&= ~(1<<tindex
);
6508 p
->needwdtr_copy
&= ~(1<<tindex
);
6511 p
->dev_flags
[tindex
] &= ~DEVICE_PARITY_ERROR
;
6515 p
->dev_flags
[tindex
] |= DEVICE_PARITY_ERROR
;
6519 * We've set the hardware to assert ATN if we get a parity
6520 * error on "in" phases, so all we need to do is stuff the
6521 * message buffer with the appropriate message. "In" phases
6522 * have set mesg_out to something other than MSG_NOP.
6524 if (mesg_out
!= MSG_NOOP
)
6526 aic_outb(p
, mesg_out
, MSG_OUT
);
6527 aic_outb(p
, aic_inb(p
, SCSISIGI
) | ATNO
, SCSISIGO
);
6530 aic_outb(p
, CLRSCSIPERR
, CLRSINT1
);
6531 aic_outb(p
, CLRSCSIINT
, CLRINT
);
6532 unpause_sequencer(p
, /* unpause_always */ TRUE
);
6534 else if ( (status
& REQINIT
) &&
6535 (p
->flags
& AHC_HANDLING_REQINITS
) )
6537 #ifdef AIC7XXX_VERBOSE_DEBUGGING
6538 if (aic7xxx_verbose
> 0xffff)
6539 printk(INFO_LEAD
"Handling REQINIT, SSTAT1=0x%x.\n", p
->host_no
,
6540 CTL_OF_SCB(scb
), aic_inb(p
, SSTAT1
));
6542 aic7xxx_handle_reqinit(p
, scb
);
6548 * We don't know what's going on. Turn off the
6549 * interrupt source and try to continue.
6551 if (aic7xxx_verbose
& VERBOSE_SCSIINT
)
6552 printk(INFO_LEAD
"Unknown SCSIINT status, SSTAT1(0x%x).\n",
6553 p
->host_no
, -1, -1, -1, status
);
6554 aic_outb(p
, status
, CLRSINT1
);
6555 aic_outb(p
, CLRSCSIINT
, CLRINT
);
6556 unpause_sequencer(p
, /* unpause always */ TRUE
);
6561 aic7xxx_done(p
, scb
);
6565 #ifdef AIC7XXX_VERBOSE_DEBUGGING
6567 aic7xxx_check_scbs(struct aic7xxx_host
*p
, char *buffer
)
6569 unsigned char saved_scbptr
, free_scbh
, dis_scbh
, wait_scbh
, temp
;
6571 static unsigned char scb_status
[AIC7XXX_MAXSCB
];
6573 #define SCB_NO_LIST 0
6574 #define SCB_FREE_LIST 1
6575 #define SCB_WAITING_LIST 2
6576 #define SCB_DISCONNECTED_LIST 4
6577 #define SCB_CURRENTLY_ACTIVE 8
6580 * Note, these checks will fail on a regular basis once the machine moves
6581 * beyond the bus scan phase. The problem is race conditions concerning
6582 * the scbs and where they are linked in. When you have 30 or so commands
6583 * outstanding on the bus, and run this twice with every interrupt, the
6584 * chances get pretty good that you'll catch the sequencer with an SCB
6585 * only partially linked in. Therefore, once we pass the scan phase
6586 * of the bus, we really should disable this function.
6589 memset(&scb_status
[0], 0, sizeof(scb_status
));
6591 saved_scbptr
= aic_inb(p
, SCBPTR
);
6592 if (saved_scbptr
>= p
->scb_data
->maxhscbs
)
6594 printk("Bogus SCBPTR %d\n", saved_scbptr
);
6597 scb_status
[saved_scbptr
] = SCB_CURRENTLY_ACTIVE
;
6598 free_scbh
= aic_inb(p
, FREE_SCBH
);
6599 if ( (free_scbh
!= SCB_LIST_NULL
) &&
6600 (free_scbh
>= p
->scb_data
->maxhscbs
) )
6602 printk("Bogus FREE_SCBH %d\n", free_scbh
);
6608 while( (temp
!= SCB_LIST_NULL
) && (temp
< p
->scb_data
->maxhscbs
) )
6610 if(scb_status
[temp
] & 0x07)
6612 printk("HSCB %d on multiple lists, status 0x%02x", temp
,
6613 scb_status
[temp
] | SCB_FREE_LIST
);
6616 scb_status
[temp
] |= SCB_FREE_LIST
;
6617 aic_outb(p
, temp
, SCBPTR
);
6618 temp
= aic_inb(p
, SCB_NEXT
);
6622 dis_scbh
= aic_inb(p
, DISCONNECTED_SCBH
);
6623 if ( (dis_scbh
!= SCB_LIST_NULL
) &&
6624 (dis_scbh
>= p
->scb_data
->maxhscbs
) )
6626 printk("Bogus DISCONNECTED_SCBH %d\n", dis_scbh
);
6632 while( (temp
!= SCB_LIST_NULL
) && (temp
< p
->scb_data
->maxhscbs
) )
6634 if(scb_status
[temp
] & 0x07)
6636 printk("HSCB %d on multiple lists, status 0x%02x", temp
,
6637 scb_status
[temp
] | SCB_DISCONNECTED_LIST
);
6640 scb_status
[temp
] |= SCB_DISCONNECTED_LIST
;
6641 aic_outb(p
, temp
, SCBPTR
);
6642 temp
= aic_inb(p
, SCB_NEXT
);
6646 wait_scbh
= aic_inb(p
, WAITING_SCBH
);
6647 if ( (wait_scbh
!= SCB_LIST_NULL
) &&
6648 (wait_scbh
>= p
->scb_data
->maxhscbs
) )
6650 printk("Bogus WAITING_SCBH %d\n", wait_scbh
);
6656 while( (temp
!= SCB_LIST_NULL
) && (temp
< p
->scb_data
->maxhscbs
) )
6658 if(scb_status
[temp
] & 0x07)
6660 printk("HSCB %d on multiple lists, status 0x%02x", temp
,
6661 scb_status
[temp
] | SCB_WAITING_LIST
);
6664 scb_status
[temp
] |= SCB_WAITING_LIST
;
6665 aic_outb(p
, temp
, SCBPTR
);
6666 temp
= aic_inb(p
, SCB_NEXT
);
6671 for(i
=0; i
< p
->scb_data
->maxhscbs
; i
++)
6673 aic_outb(p
, i
, SCBPTR
);
6674 temp
= aic_inb(p
, SCB_NEXT
);
6675 if ( ((temp
!= SCB_LIST_NULL
) &&
6676 (temp
>= p
->scb_data
->maxhscbs
)) )
6678 printk("HSCB %d bad, SCB_NEXT invalid(%d).\n", i
, temp
);
6683 printk("HSCB %d bad, SCB_NEXT points to self.\n", i
);
6686 if (scb_status
[i
] == 0)
6690 printk("Too many lost scbs.\n");
6694 aic_outb(p
, saved_scbptr
, SCBPTR
);
6695 unpause_sequencer(p
, FALSE
);
6698 printk("Bogus parameters found in card SCB array structures.\n");
6699 printk("%s\n", buffer
);
6700 aic7xxx_panic_abort(p
, NULL
);
6707 /*+F*************************************************************************
6709 * aic7xxx_handle_command_completion_intr
6712 * SCSI command completion interrupt handler.
6713 *-F*************************************************************************/
6715 aic7xxx_handle_command_completion_intr(struct aic7xxx_host
*p
)
6717 struct aic7xxx_scb
*scb
= NULL
;
6719 unsigned char scb_index
, tindex
;
6721 #ifdef AIC7XXX_VERBOSE_DEBUGGING
6722 if( (p
->isr_count
< 16) && (aic7xxx_verbose
> 0xffff) )
6723 printk(INFO_LEAD
"Command Complete Int.\n", p
->host_no
, -1, -1, -1);
6727 * Read the INTSTAT location after clearing the CMDINT bit. This forces
6728 * any posted PCI writes to flush to memory. Gerard Roudier suggested
6729 * this fix to the possible race of clearing the CMDINT bit but not
6730 * having all command bytes flushed onto the qoutfifo.
6732 aic_outb(p
, CLRCMDINT
, CLRINT
);
6733 aic_inb(p
, INTSTAT
);
6735 * The sequencer will continue running when it
6736 * issues this interrupt. There may be >1 commands
6737 * finished, so loop until we've processed them all.
6740 while (p
->qoutfifo
[p
->qoutfifonext
] != SCB_LIST_NULL
)
6742 scb_index
= p
->qoutfifo
[p
->qoutfifonext
];
6743 p
->qoutfifo
[p
->qoutfifonext
++] = SCB_LIST_NULL
;
6744 if ( scb_index
>= p
->scb_data
->numscbs
)
6746 printk(WARN_LEAD
"CMDCMPLT with invalid SCB index %d\n", p
->host_no
,
6747 -1, -1, -1, scb_index
);
6750 scb
= p
->scb_data
->scb_array
[scb_index
];
6751 if (!(scb
->flags
& SCB_ACTIVE
) || (scb
->cmd
== NULL
))
6753 printk(WARN_LEAD
"CMDCMPLT without command for SCB %d, SCB flags "
6754 "0x%x, cmd 0x%lx\n", p
->host_no
, -1, -1, -1, scb_index
, scb
->flags
,
6755 (unsigned long) scb
->cmd
);
6758 tindex
= TARGET_INDEX(scb
->cmd
);
6759 if (scb
->flags
& SCB_QUEUED_ABORT
)
6762 if ( ((aic_inb(p
, LASTPHASE
) & PHASE_MASK
) != P_BUSFREE
) &&
6763 (aic_inb(p
, SCB_TAG
) == scb
->hscb
->tag
) )
6765 unpause_sequencer(p
, FALSE
);
6768 aic7xxx_reset_device(p
, scb
->cmd
->target
, scb
->cmd
->channel
,
6769 scb
->cmd
->lun
, scb
->hscb
->tag
);
6770 scb
->flags
&= ~(SCB_QUEUED_FOR_DONE
| SCB_RESET
| SCB_ABORT
|
6772 unpause_sequencer(p
, FALSE
);
6774 else if (scb
->flags
& SCB_ABORT
)
6777 * We started to abort this, but it completed on us, let it
6778 * through as successful
6780 scb
->flags
&= ~(SCB_ABORT
|SCB_RESET
);
6782 else if (scb
->flags
& SCB_SENSE
)
6784 char *buffer
= &scb
->cmd
->sense_buffer
[0];
6785 if (scb
->cmd
== p
->dev_dtr_cmnd
[tindex
])
6787 struct aic7xxx_scb
*old_scb
;
6789 * We have valid sense data, send it back immediately.
6791 old_scb
= p
->scb_data
->scb_array
[scb
->cmd
->next
->tag
];
6792 *old_scb
->cmd
->sense_buffer
= *scb
->cmd
->sense_buffer
;
6793 old_scb
->hscb
->target_status
= scb
->hscb
->target_status
;
6794 old_scb
->cmd
->result
= scb
->hscb
->target_status
;
6795 old_scb
->cmd
->result
|= (DID_ERROR
<< 16);
6796 aic7xxx_status(old_scb
->cmd
) = scb
->hscb
->target_status
;
6797 scbq_remove(&p
->waiting_scbs
, old_scb
);
6798 scbq_remove(&p
->delayed_scbs
[tindex
], old_scb
);
6799 scb
->cmd
->next
= NULL
;
6800 aic7xxx_done(p
, scb
);
6801 aic7xxx_done(p
, old_scb
);
6804 else if (buffer
[12] == 0x47 || buffer
[12] == 0x54)
6807 * SCSI errors, run domain validation and re-run negotiation
6809 p
->needdv
|= (1<<tindex
);
6811 * Signal that we need to re-negotiate things, this also gets us our
6812 * INQUIRY command to re-checksum off of.
6814 p
->needppr
|= (p
->needppr_copy
& (1<<tindex
));
6815 p
->needsdtr
|= (p
->needsdtr_copy
& (1<<tindex
));
6816 p
->needwdtr
|= (p
->needwdtr_copy
& (1<<tindex
));
6819 switch (status_byte(scb
->hscb
->target_status
))
6823 scb
->hscb
->target_status
= 0;
6824 scb
->cmd
->result
= 0;
6825 aic7xxx_error(scb
->cmd
) = DID_OK
;
6829 if (scb
->hscb
->residual_SG_segment_count
!= 0)
6831 aic7xxx_calculate_residual(p
, scb
);
6833 cmd
->result
|= (aic7xxx_error(cmd
) << 16);
6834 aic7xxx_done(p
, scb
);
6840 /*+F*************************************************************************
6845 * SCSI controller interrupt handler.
6846 *-F*************************************************************************/
6848 aic7xxx_isr(int irq
, void *dev_id
, struct pt_regs
*regs
)
6850 struct aic7xxx_host
*p
;
6851 unsigned char intstat
;
6853 p
= (struct aic7xxx_host
*)dev_id
;
6856 * Just a few sanity checks. Make sure that we have an int pending.
6857 * Also, if PCI, then we are going to check for a PCI bus error status
6858 * should we get too many spurious interrupts.
6860 if (!((intstat
= aic_inb(p
, INTSTAT
)) & INT_PEND
))
6863 if ( (p
->chip
& AHC_PCI
) && (p
->spurious_int
> 500) &&
6864 !(p
->flags
& AHC_HANDLING_REQINITS
) )
6866 if ( aic_inb(p
, ERROR
) & PCIERRSTAT
)
6868 aic7xxx_pci_intr(p
);
6870 p
->spurious_int
= 0;
6872 else if ( !(p
->flags
& AHC_HANDLING_REQINITS
) )
6880 p
->spurious_int
= 0;
6883 * Keep track of interrupts for /proc/scsi
6887 #ifdef AIC7XXX_VERBOSE_DEBUGGING
6888 if ( (p
->isr_count
< 16) && (aic7xxx_verbose
> 0xffff) &&
6889 (aic7xxx_panic_on_abort
) && (p
->flags
& AHC_PAGESCBS
) )
6890 aic7xxx_check_scbs(p
, "Bogus settings at start of interrupt.");
6894 * Handle all the interrupt sources - especially for SCSI
6895 * interrupts, we won't get a second chance at them.
6897 if (intstat
& CMDCMPLT
)
6899 aic7xxx_handle_command_completion_intr(p
);
6902 if (intstat
& BRKADRINT
)
6905 unsigned char errno
= aic_inb(p
, ERROR
);
6907 printk(KERN_ERR
"(scsi%d) BRKADRINT error(0x%x):\n", p
->host_no
, errno
);
6908 for (i
= 0; i
< NUMBER(hard_error
); i
++)
6910 if (errno
& hard_error
[i
].errno
)
6912 printk(KERN_ERR
" %s\n", hard_error
[i
].errmesg
);
6915 printk(KERN_ERR
"(scsi%d) SEQADDR=0x%x\n", p
->host_no
,
6916 (((aic_inb(p
, SEQADDR1
) << 8) & 0x100) | aic_inb(p
, SEQADDR0
)));
6917 if (aic7xxx_panic_on_abort
)
6918 aic7xxx_panic_abort(p
, NULL
);
6920 if (errno
& PCIERRSTAT
)
6921 aic7xxx_pci_intr(p
);
6923 if (errno
& (SQPARERR
| ILLOPCODE
| ILLSADDR
))
6926 panic("aic7xxx: unrecoverable BRKADRINT.\n");
6928 if (errno
& ILLHADDR
)
6930 printk(KERN_ERR
"(scsi%d) BUG! Driver accessed chip without first "
6931 "pausing controller!\n", p
->host_no
);
6933 #ifdef AIC7XXX_VERBOSE_DEBUGGING
6934 if (errno
& DPARERR
)
6936 if (aic_inb(p
, DMAPARAMS
) & DIRECTION
)
6937 printk("(scsi%d) while DMAing SCB from host to card.\n", p
->host_no
);
6939 printk("(scsi%d) while DMAing SCB from card to host.\n", p
->host_no
);
6942 aic_outb(p
, CLRPARERR
| CLRBRKADRINT
, CLRINT
);
6943 unpause_sequencer(p
, FALSE
);
6946 if (intstat
& SEQINT
)
6949 * Read the CCSCBCTL register to work around a bug in the Ultra2 cards
6951 if(p
->features
& AHC_ULTRA2
)
6953 aic_inb(p
, CCSCBCTL
);
6955 aic7xxx_handle_seqint(p
, intstat
);
6958 if (intstat
& SCSIINT
)
6960 aic7xxx_handle_scsiint(p
, intstat
);
6963 #ifdef AIC7XXX_VERBOSE_DEBUGGING
6964 if ( (p
->isr_count
< 16) && (aic7xxx_verbose
> 0xffff) &&
6965 (aic7xxx_panic_on_abort
) && (p
->flags
& AHC_PAGESCBS
) )
6966 aic7xxx_check_scbs(p
, "Bogus settings at end of interrupt.");
6971 /*+F*************************************************************************
6976 * This is a gross hack to solve a problem in linux kernels 2.1.85 and
6977 * above. Please, children, do not try this at home, and if you ever see
6978 * anything like it, please inform the Gross Hack Police immediately
6979 *-F*************************************************************************/
6981 do_aic7xxx_isr(int irq
, void *dev_id
, struct pt_regs
*regs
)
6983 unsigned long cpu_flags
;
6984 struct aic7xxx_host
*p
;
6986 p
= (struct aic7xxx_host
*)dev_id
;
6989 spin_lock_irqsave(&io_request_lock
, cpu_flags
);
6990 if(test_and_set_bit(AHC_IN_ISR_BIT
, (void *)&p
->flags
))
6992 spin_unlock_irqrestore(&io_request_lock
, cpu_flags
);
6997 aic7xxx_isr(irq
, dev_id
, regs
);
6998 } while ( (aic_inb(p
, INTSTAT
) & INT_PEND
) );
6999 aic7xxx_done_cmds_complete(p
);
7000 aic7xxx_run_waiting_queues(p
);
7001 clear_bit(AHC_IN_ISR_BIT
, (void *)&p
->flags
);
7002 spin_unlock_irqrestore(&io_request_lock
, cpu_flags
);
7005 /*+F*************************************************************************
7007 * aic7xxx_device_queue_depth
7010 * Determines the queue depth for a given device. There are two ways
7011 * a queue depth can be obtained for a tagged queueing device. One
7012 * way is the default queue depth which is determined by whether
7013 * AIC7XXX_CMDS_PER_DEVICE is defined. If it is defined, then it is used
7014 * as the default queue depth. Otherwise, we use either 4 or 8 as the
7015 * default queue depth (dependent on the number of hardware SCBs).
7016 * The other way we determine queue depth is through the use of the
7017 * aic7xxx_tag_info array which is enabled by defining
7018 * AIC7XXX_TAGGED_QUEUEING_BY_DEVICE. This array can be initialized
7019 * with queue depths for individual devices. It also allows tagged
7020 * queueing to be [en|dis]abled for a specific adapter.
7021 *-F*************************************************************************/
7023 aic7xxx_device_queue_depth(struct aic7xxx_host
*p
, Scsi_Device
*device
)
7025 int default_depth
= 3;
7026 unsigned char tindex
;
7027 unsigned short target_mask
;
7029 tindex
= device
->id
| (device
->channel
<< 3);
7030 target_mask
= (1 << tindex
);
7032 if (p
->dev_max_queue_depth
[tindex
] > 1)
7035 * We've already scanned this device, leave it alone
7037 return(p
->dev_max_queue_depth
[tindex
]);
7040 device
->queue_depth
= default_depth
;
7041 p
->dev_temp_queue_depth
[tindex
] = 1;
7042 p
->dev_max_queue_depth
[tindex
] = 1;
7043 p
->tagenable
&= ~target_mask
;
7045 if (device
->tagged_supported
)
7047 int tag_enabled
= TRUE
;
7049 default_depth
= AIC7XXX_CMDS_PER_DEVICE
;
7051 if (!(p
->discenable
& target_mask
))
7053 if (aic7xxx_verbose
& VERBOSE_NEGOTIATION2
)
7054 printk(INFO_LEAD
"Disconnection disabled, unable to "
7055 "enable tagged queueing.\n",
7056 p
->host_no
, device
->channel
, device
->id
, device
->lun
);
7060 if (p
->instance
>= NUMBER(aic7xxx_tag_info
))
7062 static int print_warning
= TRUE
;
7065 printk(KERN_INFO
"aic7xxx: WARNING, insufficient tag_info instances for"
7066 " installed controllers.\n");
7067 printk(KERN_INFO
"aic7xxx: Please update the aic7xxx_tag_info array in"
7068 " the aic7xxx.c source file.\n");
7069 print_warning
= FALSE
;
7071 device
->queue_depth
= default_depth
;
7076 if (aic7xxx_tag_info
[p
->instance
].tag_commands
[tindex
] == 255)
7078 tag_enabled
= FALSE
;
7079 device
->queue_depth
= 3; /* Tagged queueing is disabled. */
7081 else if (aic7xxx_tag_info
[p
->instance
].tag_commands
[tindex
] == 0)
7083 device
->queue_depth
= default_depth
;
7087 device
->queue_depth
=
7088 aic7xxx_tag_info
[p
->instance
].tag_commands
[tindex
];
7091 if ((device
->tagged_queue
== 0) && tag_enabled
)
7093 if (aic7xxx_verbose
& VERBOSE_NEGOTIATION2
)
7095 printk(INFO_LEAD
"Enabled tagged queuing, queue depth %d.\n",
7096 p
->host_no
, device
->channel
, device
->id
,
7097 device
->lun
, device
->queue_depth
);
7099 p
->dev_max_queue_depth
[tindex
] = device
->queue_depth
;
7100 p
->dev_temp_queue_depth
[tindex
] = device
->queue_depth
;
7101 p
->tagenable
|= target_mask
;
7102 p
->orderedtag
|= target_mask
;
7103 device
->tagged_queue
= 1;
7104 device
->current_tag
= SCB_LIST_NULL
;
7108 return(p
->dev_max_queue_depth
[tindex
]);
7111 /*+F*************************************************************************
7113 * aic7xxx_select_queue_depth
7116 * Sets the queue depth for each SCSI device hanging off the input
7117 * host adapter. We use a queue depth of 2 for devices that do not
7118 * support tagged queueing. If AIC7XXX_CMDS_PER_LUN is defined, we
7119 * use that for tagged queueing devices; otherwise we use our own
7120 * algorithm for determining the queue depth based on the maximum
7121 * SCBs for the controller.
7122 *-F*************************************************************************/
7124 aic7xxx_select_queue_depth(struct Scsi_Host
*host
,
7125 Scsi_Device
*scsi_devs
)
7127 Scsi_Device
*device
;
7128 struct aic7xxx_host
*p
= (struct aic7xxx_host
*) host
->hostdata
;
7132 for (device
= scsi_devs
; device
!= NULL
; device
= device
->next
)
7134 if (device
->host
== host
)
7136 scbnum
+= aic7xxx_device_queue_depth(p
, device
);
7139 while (scbnum
> p
->scb_data
->numscbs
)
7142 * Pre-allocate the needed SCBs to get around the possibility of having
7143 * to allocate some when memory is more or less exhausted and we need
7144 * the SCB in order to perform a swap operation (possible deadlock)
7146 if ( aic7xxx_allocate_scb(p
) == 0 )
7151 /*+F*************************************************************************
7156 * Probing for EISA boards: it looks like the first two bytes
7157 * are a manufacturer code - three characters, five bits each:
7159 * BYTE 0 BYTE 1 BYTE 2 BYTE 3
7160 * ?1111122 22233333 PPPPPPPP RRRRRRRR
7162 * The characters are baselined off ASCII '@', so add that value
7163 * to each to get the real ASCII code for it. The next two bytes
7164 * appear to be a product and revision number, probably vendor-
7165 * specific. This is what is being searched for at each port,
7166 * and what should probably correspond to the ID= field in the
7167 * ECU's .cfg file for the card - if your card is not detected,
7168 * make sure your signature is listed in the array.
7170 * The fourth byte's lowest bit seems to be an enabled/disabled
7171 * flag (rest of the bits are reserved?).
7173 * NOTE: This function is only needed on Intel and Alpha platforms,
7174 * the other platforms we support don't have EISA/VLB busses. So,
7175 * we #ifdef this entire function to avoid compiler warnings about
7176 * an unused function.
7177 *-F*************************************************************************/
7178 #if defined(__i386__) || defined(__alpha__)
7180 aic7xxx_probe(int slot
, int base
, ahc_flag_type
*flags
)
7183 unsigned char buf
[4];
7187 unsigned char signature
[sizeof(buf
)];
7191 { 4, { 0x04, 0x90, 0x77, 0x70 },
7192 AHC_AIC7770
|AHC_EISA
, FALSE
}, /* mb 7770 */
7193 { 4, { 0x04, 0x90, 0x77, 0x71 },
7194 AHC_AIC7770
|AHC_EISA
, FALSE
}, /* host adapter 274x */
7195 { 4, { 0x04, 0x90, 0x77, 0x56 },
7196 AHC_AIC7770
|AHC_VL
, FALSE
}, /* 284x BIOS enabled */
7197 { 4, { 0x04, 0x90, 0x77, 0x57 },
7198 AHC_AIC7770
|AHC_VL
, TRUE
} /* 284x BIOS disabled */
7202 * The VL-bus cards need to be primed by
7203 * writing before a signature check.
7205 for (i
= 0; i
< sizeof(buf
); i
++)
7207 outb(0x80 + i
, base
);
7208 buf
[i
] = inb(base
+ i
);
7211 for (i
= 0; i
< NUMBER(AIC7xxx
); i
++)
7214 * Signature match on enabled card?
7216 if (!memcmp(buf
, AIC7xxx
[i
].signature
, AIC7xxx
[i
].n
))
7218 if (inb(base
+ 4) & 1)
7220 if (AIC7xxx
[i
].bios_disabled
)
7222 *flags
|= AHC_USEDEFAULTS
;
7226 *flags
|= AHC_BIOS_ENABLED
;
7231 printk("aic7xxx: <Adaptec 7770 SCSI Host Adapter> "
7232 "disabled at slot %d, ignored.\n", slot
);
7238 #endif /* (__i386__) || (__alpha__) */
7241 /*+F*************************************************************************
7246 * Reads the 2840 serial EEPROM and returns 1 if successful and 0 if
7249 * See read_seeprom (for the 2940) for the instruction set of the 93C46
7252 * The 2840 interface to the 93C46 serial EEPROM is through the
7253 * STATUS_2840 and SEECTL_2840 registers. The CS_2840, CK_2840, and
7254 * DO_2840 bits of the SEECTL_2840 register are connected to the chip
7255 * select, clock, and data out lines respectively of the serial EEPROM.
7256 * The DI_2840 bit of the STATUS_2840 is connected to the data in line
7257 * of the serial EEPROM. The EEPROM_TF bit of STATUS_2840 register is
7258 * useful in that it gives us an 800 nsec timer. After a read from the
7259 * SEECTL_2840 register the timing flag is cleared and goes high 800 nsec
7261 *-F*************************************************************************/
7263 read_284x_seeprom(struct aic7xxx_host
*p
, struct seeprom_config
*sc
)
7267 unsigned short checksum
= 0;
7268 unsigned short *seeprom
= (unsigned short *) sc
;
7269 struct seeprom_cmd
{
7271 unsigned char bits
[3];
7273 struct seeprom_cmd seeprom_read
= {3, {1, 1, 0}};
7275 #define CLOCK_PULSE(p) \
7276 while ((aic_inb(p, STATUS_2840) & EEPROM_TF) == 0) \
7278 ; /* Do nothing */ \
7280 (void) aic_inb(p, SEECTL_2840);
7283 * Read the first 32 registers of the seeprom. For the 2840,
7284 * the 93C46 SEEPROM is a 1024-bit device with 64 16-bit registers
7285 * but only the first 32 are used by Adaptec BIOS. The loop
7286 * will range from 0 to 31.
7288 for (k
= 0; k
< (sizeof(*sc
) / 2); k
++)
7291 * Send chip select for one clock cycle.
7293 aic_outb(p
, CK_2840
| CS_2840
, SEECTL_2840
);
7297 * Now we're ready to send the read command followed by the
7298 * address of the 16-bit register we want to read.
7300 for (i
= 0; i
< seeprom_read
.len
; i
++)
7302 temp
= CS_2840
| seeprom_read
.bits
[i
];
7303 aic_outb(p
, temp
, SEECTL_2840
);
7305 temp
= temp
^ CK_2840
;
7306 aic_outb(p
, temp
, SEECTL_2840
);
7310 * Send the 6 bit address (MSB first, LSB last).
7312 for (i
= 5; i
>= 0; i
--)
7315 temp
= (temp
>> i
) & 1; /* Mask out all but lower bit. */
7316 temp
= CS_2840
| temp
;
7317 aic_outb(p
, temp
, SEECTL_2840
);
7319 temp
= temp
^ CK_2840
;
7320 aic_outb(p
, temp
, SEECTL_2840
);
7325 * Now read the 16 bit register. An initial 0 precedes the
7326 * register contents which begins with bit 15 (MSB) and ends
7327 * with bit 0 (LSB). The initial 0 will be shifted off the
7328 * top of our word as we let the loop run from 0 to 16.
7330 for (i
= 0; i
<= 16; i
++)
7333 aic_outb(p
, temp
, SEECTL_2840
);
7335 temp
= temp
^ CK_2840
;
7336 seeprom
[k
] = (seeprom
[k
] << 1) | (aic_inb(p
, STATUS_2840
) & DI_2840
);
7337 aic_outb(p
, temp
, SEECTL_2840
);
7341 * The serial EEPROM has a checksum in the last word. Keep a
7342 * running checksum for all words read except for the last
7343 * word. We'll verify the checksum after all words have been
7346 if (k
< (sizeof(*sc
) / 2) - 1)
7348 checksum
= checksum
+ seeprom
[k
];
7352 * Reset the chip select for the next command cycle.
7354 aic_outb(p
, 0, SEECTL_2840
);
7356 aic_outb(p
, CK_2840
, SEECTL_2840
);
7358 aic_outb(p
, 0, SEECTL_2840
);
7363 printk("Computed checksum 0x%x, checksum read 0x%x\n", checksum
, sc
->checksum
);
7364 printk("Serial EEPROM:");
7365 for (k
= 0; k
< (sizeof(*sc
) / 2); k
++)
7367 if (((k
% 8) == 0) && (k
!= 0))
7371 printk(" 0x%x", seeprom
[k
]);
7376 if (checksum
!= sc
->checksum
)
7378 printk("aic7xxx: SEEPROM checksum error, ignoring SEEPROM settings.\n");
7386 #define CLOCK_PULSE(p) \
7391 pause_sequencer(p); /* This is just to generate some PCI */ \
7392 /* traffic so the PCI read is flushed */ \
7393 /* it shouldn't be needed, but some */ \
7394 /* chipsets do indeed appear to need */ \
7395 /* something to force PCI reads to get */ \
7397 udelay(1); /* Do nothing */ \
7398 } while (((aic_inb(p, SEECTL) & SEERDY) == 0) && (++limit < 1000)); \
7401 /*+F*************************************************************************
7406 * Acquires access to the memory port on PCI controllers.
7407 *-F*************************************************************************/
7409 acquire_seeprom(struct aic7xxx_host
*p
)
7413 * Request access of the memory port. When access is
7414 * granted, SEERDY will go high. We use a 1 second
7415 * timeout which should be near 1 second more than
7416 * is needed. Reason: after the 7870 chip reset, there
7417 * should be no contention.
7419 aic_outb(p
, SEEMS
, SEECTL
);
7421 if ((aic_inb(p
, SEECTL
) & SEERDY
) == 0)
7423 aic_outb(p
, 0, SEECTL
);
7429 /*+F*************************************************************************
7434 * Releases access to the memory port on PCI controllers.
7435 *-F*************************************************************************/
7437 release_seeprom(struct aic7xxx_host
*p
)
7440 * Make sure the SEEPROM is ready before we release it.
7443 aic_outb(p
, 0, SEECTL
);
7446 /*+F*************************************************************************
7451 * Reads the serial EEPROM and returns 1 if successful and 0 if
7454 * The instruction set of the 93C46/56/66 chips is as follows:
7457 * Function Bit Code Address Data Description
7458 * -------------------------------------------------------------------
7459 * READ 1 10 A5 - A0 Reads data stored in memory,
7460 * starting at specified address
7461 * EWEN 1 00 11XXXX Write enable must precede
7462 * all programming modes
7463 * ERASE 1 11 A5 - A0 Erase register A5A4A3A2A1A0
7464 * WRITE 1 01 A5 - A0 D15 - D0 Writes register
7465 * ERAL 1 00 10XXXX Erase all registers
7466 * WRAL 1 00 01XXXX D15 - D0 Writes to all registers
7467 * EWDS 1 00 00XXXX Disables all programming
7469 * *Note: A value of X for address is a don't care condition.
7470 * *Note: The 93C56 and 93C66 have 8 address bits.
7473 * The 93C46 has a four wire interface: clock, chip select, data in, and
7474 * data out. In order to perform one of the above functions, you need
7475 * to enable the chip select for a clock period (typically a minimum of
7476 * 1 usec, with the clock high and low a minimum of 750 and 250 nsec
7477 * respectively. While the chip select remains high, you can clock in
7478 * the instructions (above) starting with the start bit, followed by the
7479 * OP code, Address, and Data (if needed). For the READ instruction, the
7480 * requested 16-bit register contents is read from the data out line but
7481 * is preceded by an initial zero (leading 0, followed by 16-bits, MSB
7482 * first). The clock cycling from low to high initiates the next data
7483 * bit to be sent from the chip.
7485 * The 78xx interface to the 93C46 serial EEPROM is through the SEECTL
7486 * register. After successful arbitration for the memory port, the
7487 * SEECS bit of the SEECTL register is connected to the chip select.
7488 * The SEECK, SEEDO, and SEEDI are connected to the clock, data out,
7489 * and data in lines respectively. The SEERDY bit of SEECTL is useful
7490 * in that it gives us an 800 nsec timer. After a write to the SEECTL
7491 * register, the SEERDY goes high 800 nsec later. The one exception
7492 * to this is when we first request access to the memory port. The
7493 * SEERDY goes high to signify that access has been granted and, for
7494 * this case, has no implied timing.
7495 *-F*************************************************************************/
7497 read_seeprom(struct aic7xxx_host
*p
, int offset
,
7498 unsigned short *scarray
, unsigned int len
, seeprom_chip_type chip
)
7502 unsigned short checksum
= 0;
7503 struct seeprom_cmd
{
7505 unsigned char bits
[3];
7507 struct seeprom_cmd seeprom_read
= {3, {1, 1, 0}};
7510 * Request access of the memory port.
7512 if (acquire_seeprom(p
) == 0)
7518 * Read 'len' registers of the seeprom. For the 7870, the 93C46
7519 * SEEPROM is a 1024-bit device with 64 16-bit registers but only
7520 * the first 32 are used by Adaptec BIOS. Some adapters use the
7521 * 93C56 SEEPROM which is a 2048-bit device. The loop will range
7522 * from 0 to 'len' - 1.
7524 for (k
= 0; k
< len
; k
++)
7527 * Send chip select for one clock cycle.
7529 aic_outb(p
, SEEMS
| SEECK
| SEECS
, SEECTL
);
7533 * Now we're ready to send the read command followed by the
7534 * address of the 16-bit register we want to read.
7536 for (i
= 0; i
< seeprom_read
.len
; i
++)
7538 temp
= SEEMS
| SEECS
| (seeprom_read
.bits
[i
] << 1);
7539 aic_outb(p
, temp
, SEECTL
);
7541 temp
= temp
^ SEECK
;
7542 aic_outb(p
, temp
, SEECTL
);
7546 * Send the 6 or 8 bit address (MSB first, LSB last).
7548 for (i
= ((int) chip
- 1); i
>= 0; i
--)
7551 temp
= (temp
>> i
) & 1; /* Mask out all but lower bit. */
7552 temp
= SEEMS
| SEECS
| (temp
<< 1);
7553 aic_outb(p
, temp
, SEECTL
);
7555 temp
= temp
^ SEECK
;
7556 aic_outb(p
, temp
, SEECTL
);
7561 * Now read the 16 bit register. An initial 0 precedes the
7562 * register contents which begins with bit 15 (MSB) and ends
7563 * with bit 0 (LSB). The initial 0 will be shifted off the
7564 * top of our word as we let the loop run from 0 to 16.
7566 for (i
= 0; i
<= 16; i
++)
7568 temp
= SEEMS
| SEECS
;
7569 aic_outb(p
, temp
, SEECTL
);
7571 temp
= temp
^ SEECK
;
7572 scarray
[k
] = (scarray
[k
] << 1) | (aic_inb(p
, SEECTL
) & SEEDI
);
7573 aic_outb(p
, temp
, SEECTL
);
7578 * The serial EEPROM should have a checksum in the last word.
7579 * Keep a running checksum for all words read except for the
7580 * last word. We'll verify the checksum after all words have
7585 checksum
= checksum
+ scarray
[k
];
7589 * Reset the chip select for the next command cycle.
7591 aic_outb(p
, SEEMS
, SEECTL
);
7593 aic_outb(p
, SEEMS
| SEECK
, SEECTL
);
7595 aic_outb(p
, SEEMS
, SEECTL
);
7600 * Release access to the memory port and the serial EEPROM.
7605 printk("Computed checksum 0x%x, checksum read 0x%x\n",
7606 checksum
, scarray
[len
- 1]);
7607 printk("Serial EEPROM:");
7608 for (k
= 0; k
< len
; k
++)
7610 if (((k
% 8) == 0) && (k
!= 0))
7614 printk(" 0x%x", scarray
[k
]);
7618 if ( (checksum
!= scarray
[len
- 1]) || (checksum
== 0) )
7626 /*+F*************************************************************************
7631 * Reads the BRDCTL register.
7632 *-F*************************************************************************/
7633 static unsigned char
7634 read_brdctl(struct aic7xxx_host
*p
)
7636 unsigned char brdctl
, value
;
7639 * Make sure the SEEPROM is ready before we access it
7642 if (p
->features
& AHC_ULTRA2
)
7644 brdctl
= BRDRW_ULTRA2
;
7645 aic_outb(p
, brdctl
, BRDCTL
);
7647 value
= aic_inb(p
, BRDCTL
);
7652 if ( !((p
->chip
& AHC_CHIPID_MASK
) == AHC_AIC7895
) ||
7653 (p
->flags
& AHC_CHNLB
) )
7657 aic_outb(p
, brdctl
, BRDCTL
);
7659 value
= aic_inb(p
, BRDCTL
);
7661 aic_outb(p
, 0, BRDCTL
);
7666 /*+F*************************************************************************
7671 * Writes a value to the BRDCTL register.
7672 *-F*************************************************************************/
7674 write_brdctl(struct aic7xxx_host
*p
, unsigned char value
)
7676 unsigned char brdctl
;
7679 * Make sure the SEEPROM is ready before we access it
7682 if (p
->features
& AHC_ULTRA2
)
7685 aic_outb(p
, brdctl
, BRDCTL
);
7687 brdctl
|= BRDSTB_ULTRA2
;
7688 aic_outb(p
, brdctl
, BRDCTL
);
7690 brdctl
&= ~BRDSTB_ULTRA2
;
7691 aic_outb(p
, brdctl
, BRDCTL
);
7699 if ( !((p
->chip
& AHC_CHIPID_MASK
) == AHC_AIC7895
) ||
7700 (p
->flags
& AHC_CHNLB
) )
7704 brdctl
= BRDSTB
| BRDCS
;
7705 aic_outb(p
, brdctl
, BRDCTL
);
7708 aic_outb(p
, brdctl
, BRDCTL
);
7711 aic_outb(p
, brdctl
, BRDCTL
);
7714 aic_outb(p
, brdctl
, BRDCTL
);
7719 /*+F*************************************************************************
7721 * aic785x_cable_detect
7724 * Detect the cables that are present on aic785x class controller chips
7725 *-F*************************************************************************/
7727 aic785x_cable_detect(struct aic7xxx_host
*p
, int *int_50
,
7728 int *ext_present
, int *eeprom
)
7730 unsigned char brdctl
;
7732 aic_outb(p
, BRDRW
| BRDCS
, BRDCTL
);
7734 aic_outb(p
, 0, BRDCTL
);
7736 brdctl
= aic_inb(p
, BRDCTL
);
7738 *int_50
= !(brdctl
& BRDDAT5
);
7739 *ext_present
= !(brdctl
& BRDDAT6
);
7740 *eeprom
= (aic_inb(p
, SPIOCAP
) & EEPROM
);
7745 /*+F*************************************************************************
7747 * aic2940_uwpro_cable_detect
7750 * Detect the cables that are present on the 2940-UWPro cards
7752 * NOTE: This function assumes the SEEPROM will have already been acquired
7753 * prior to invocation of this function.
7754 *-F*************************************************************************/
7756 aic2940_uwpro_wide_cable_detect(struct aic7xxx_host
*p
, int *int_68
,
7757 int *ext_68
, int *eeprom
)
7759 unsigned char brdctl
;
7762 * First read the status of our cables. Set the rom bank to
7763 * 0 since the bank setting serves as a multiplexor for the
7764 * cable detection logic. BRDDAT5 controls the bank switch.
7769 * Now we read the state of the internal 68 connector. BRDDAT6
7770 * is don't care, BRDDAT7 is internal 68. The cable is
7771 * present if the bit is 0
7773 brdctl
= read_brdctl(p
);
7774 *int_68
= !(brdctl
& BRDDAT7
);
7777 * Set the bank bit in brdctl and then read the external cable state
7778 * and the EEPROM status
7780 write_brdctl(p
, BRDDAT5
);
7781 brdctl
= read_brdctl(p
);
7783 *ext_68
= !(brdctl
& BRDDAT6
);
7784 *eeprom
= !(brdctl
& BRDDAT7
);
7787 * We're done, the calling function will release the SEEPROM for us
7791 /*+F*************************************************************************
7793 * aic787x_cable_detect
7796 * Detect the cables that are present on aic787x class controller chips
7798 * NOTE: This function assumes the SEEPROM will have already been acquired
7799 * prior to invocation of this function.
7800 *-F*************************************************************************/
7802 aic787x_cable_detect(struct aic7xxx_host
*p
, int *int_50
, int *int_68
,
7803 int *ext_present
, int *eeprom
)
7805 unsigned char brdctl
;
7808 * First read the status of our cables. Set the rom bank to
7809 * 0 since the bank setting serves as a multiplexor for the
7810 * cable detection logic. BRDDAT5 controls the bank switch.
7815 * Now we read the state of the two internal connectors. BRDDAT6
7816 * is internal 50, BRDDAT7 is internal 68. For each, the cable is
7817 * present if the bit is 0
7819 brdctl
= read_brdctl(p
);
7820 *int_50
= !(brdctl
& BRDDAT6
);
7821 *int_68
= !(brdctl
& BRDDAT7
);
7824 * Set the bank bit in brdctl and then read the external cable state
7825 * and the EEPROM status
7827 write_brdctl(p
, BRDDAT5
);
7828 brdctl
= read_brdctl(p
);
7830 *ext_present
= !(brdctl
& BRDDAT6
);
7831 *eeprom
= !(brdctl
& BRDDAT7
);
7834 * We're done, the calling function will release the SEEPROM for us
7838 /*+F*************************************************************************
7840 * aic787x_ultra2_term_detect
7843 * Detect the termination settings present on ultra2 class controllers
7845 * NOTE: This function assumes the SEEPROM will have already been acquired
7846 * prior to invocation of this function.
7847 *-F*************************************************************************/
7849 aic7xxx_ultra2_term_detect(struct aic7xxx_host
*p
, int *enableSE_low
,
7850 int *enableSE_high
, int *enableLVD_low
,
7851 int *enableLVD_high
, int *eprom_present
)
7853 unsigned char brdctl
;
7855 brdctl
= read_brdctl(p
);
7857 *eprom_present
= (brdctl
& BRDDAT7
);
7858 *enableSE_high
= (brdctl
& BRDDAT6
);
7859 *enableSE_low
= (brdctl
& BRDDAT5
);
7860 *enableLVD_high
= (brdctl
& BRDDAT4
);
7861 *enableLVD_low
= (brdctl
& BRDDAT3
);
7864 /*+F*************************************************************************
7866 * configure_termination
7869 * Configures the termination settings on PCI adapters that have
7870 * SEEPROMs available.
7871 *-F*************************************************************************/
7873 configure_termination(struct aic7xxx_host
*p
)
7875 int internal50_present
= 0;
7876 int internal68_present
= 0;
7877 int external_present
= 0;
7878 int eprom_present
= 0;
7879 int enableSE_low
= 0;
7880 int enableSE_high
= 0;
7881 int enableLVD_low
= 0;
7882 int enableLVD_high
= 0;
7883 unsigned char brddat
= 0;
7884 unsigned char max_target
= 0;
7885 unsigned char sxfrctl1
= aic_inb(p
, SXFRCTL1
);
7887 if (acquire_seeprom(p
))
7889 if (p
->features
& (AHC_WIDE
|AHC_TWIN
))
7893 aic_outb(p
, SEEMS
| SEECS
, SEECTL
);
7894 sxfrctl1
&= ~STPWEN
;
7896 * The termination/cable detection logic is split into three distinct
7897 * groups. Ultra2 and later controllers, 2940UW-Pro controllers, and
7898 * older 7850, 7860, 7870, 7880, and 7895 controllers. Each has its
7899 * own unique way of detecting their cables and writing the results
7902 if (p
->features
& AHC_ULTRA2
)
7905 * As long as user hasn't overridden term settings, always check the
7906 * cable detection logic
7908 if (aic7xxx_override_term
== -1)
7910 aic7xxx_ultra2_term_detect(p
, &enableSE_low
, &enableSE_high
,
7911 &enableLVD_low
, &enableLVD_high
,
7916 * If the user is overriding settings, then they have been preserved
7917 * to here as fake adapter_control entries. Parse them and allow
7918 * them to override the detected settings (if we even did detection).
7920 if (!(p
->adapter_control
& CFSEAUTOTERM
))
7922 enableSE_low
= (p
->adapter_control
& CFSTERM
);
7923 enableSE_high
= (p
->adapter_control
& CFWSTERM
);
7925 if (!(p
->adapter_control
& CFAUTOTERM
))
7927 enableLVD_low
= enableLVD_high
= (p
->adapter_control
& CFLVDSTERM
);
7931 * Now take those settings that we have and translate them into the
7932 * values that must be written into the registers.
7934 * Flash Enable = BRDDAT7
7935 * Secondary High Term Enable = BRDDAT6
7936 * Secondary Low Term Enable = BRDDAT5
7937 * LVD/Primary High Term Enable = BRDDAT4
7938 * LVD/Primary Low Term Enable = STPWEN bit in SXFRCTL1
7940 if (enableLVD_low
!= 0)
7943 p
->flags
|= AHC_TERM_ENB_LVD
;
7944 if (aic7xxx_verbose
& VERBOSE_PROBE2
)
7945 printk(KERN_INFO
"(scsi%d) LVD/Primary Low byte termination "
7946 "Enabled\n", p
->host_no
);
7949 if (enableLVD_high
!= 0)
7952 if (aic7xxx_verbose
& VERBOSE_PROBE2
)
7953 printk(KERN_INFO
"(scsi%d) LVD/Primary High byte termination "
7954 "Enabled\n", p
->host_no
);
7957 if (enableSE_low
!= 0)
7960 if (aic7xxx_verbose
& VERBOSE_PROBE2
)
7961 printk(KERN_INFO
"(scsi%d) Secondary Low byte termination "
7962 "Enabled\n", p
->host_no
);
7965 if (enableSE_high
!= 0)
7968 if (aic7xxx_verbose
& VERBOSE_PROBE2
)
7969 printk(KERN_INFO
"(scsi%d) Secondary High byte termination "
7970 "Enabled\n", p
->host_no
);
7973 else if (p
->features
& AHC_NEW_AUTOTERM
)
7976 * The 50 pin connector termination is controlled by STPWEN in the
7977 * SXFRCTL1 register. Since the Adaptec docs typically say the
7978 * controller is not allowed to be in the middle of a cable and
7979 * this is the only connection on that stub of the bus, there is
7980 * no need to even check for narrow termination, it's simply
7984 if (aic7xxx_verbose
& VERBOSE_PROBE2
)
7985 printk(KERN_INFO
"(scsi%d) Narrow channel termination Enabled\n",
7988 if (p
->adapter_control
& CFAUTOTERM
)
7990 aic2940_uwpro_wide_cable_detect(p
, &internal68_present
,
7993 printk(KERN_INFO
"(scsi%d) Cables present (Int-50 %s, Int-68 %s, "
7994 "Ext-68 %s)\n", p
->host_no
,
7996 internal68_present
? "YES" : "NO",
7997 external_present
? "YES" : "NO");
7998 if (aic7xxx_verbose
& VERBOSE_PROBE2
)
7999 printk(KERN_INFO
"(scsi%d) EEPROM %s present.\n", p
->host_no
,
8000 eprom_present
? "is" : "is not");
8001 if (internal68_present
&& external_present
)
8004 p
->flags
&= ~AHC_TERM_ENB_SE_HIGH
;
8005 if (aic7xxx_verbose
& VERBOSE_PROBE2
)
8006 printk(KERN_INFO
"(scsi%d) Wide channel termination Disabled\n",
8012 p
->flags
|= AHC_TERM_ENB_SE_HIGH
;
8013 if (aic7xxx_verbose
& VERBOSE_PROBE2
)
8014 printk(KERN_INFO
"(scsi%d) Wide channel termination Enabled\n",
8021 * The termination of the Wide channel is done more like normal
8022 * though, and the setting of this termination is done by writing
8023 * either a 0 or 1 to BRDDAT6 of the BRDDAT register
8025 if (p
->adapter_control
& CFWSTERM
)
8028 p
->flags
|= AHC_TERM_ENB_SE_HIGH
;
8029 if (aic7xxx_verbose
& VERBOSE_PROBE2
)
8030 printk(KERN_INFO
"(scsi%d) Wide channel termination Enabled\n",
8041 if (p
->adapter_control
& CFAUTOTERM
)
8043 if (p
->flags
& AHC_MOTHERBOARD
)
8045 printk(KERN_INFO
"(scsi%d) Warning - detected auto-termination\n",
8047 printk(KERN_INFO
"(scsi%d) Please verify driver detected settings "
8048 "are correct.\n", p
->host_no
);
8049 printk(KERN_INFO
"(scsi%d) If not, then please properly set the "
8050 "device termination\n", p
->host_no
);
8051 printk(KERN_INFO
"(scsi%d) in the Adaptec SCSI BIOS by hitting "
8052 "CTRL-A when prompted\n", p
->host_no
);
8053 printk(KERN_INFO
"(scsi%d) during machine bootup.\n", p
->host_no
);
8055 /* Configure auto termination. */
8057 if ( (p
->chip
& AHC_CHIPID_MASK
) >= AHC_AIC7870
)
8059 aic787x_cable_detect(p
, &internal50_present
, &internal68_present
,
8060 &external_present
, &eprom_present
);
8064 aic785x_cable_detect(p
, &internal50_present
, &external_present
,
8068 if (max_target
<= 8)
8069 internal68_present
= 0;
8073 printk(KERN_INFO
"(scsi%d) Cables present (Int-50 %s, Int-68 %s, "
8074 "Ext-68 %s)\n", p
->host_no
,
8075 internal50_present
? "YES" : "NO",
8076 internal68_present
? "YES" : "NO",
8077 external_present
? "YES" : "NO");
8081 printk(KERN_INFO
"(scsi%d) Cables present (Int-50 %s, Ext-50 %s)\n",
8083 internal50_present
? "YES" : "NO",
8084 external_present
? "YES" : "NO");
8086 if (aic7xxx_verbose
& VERBOSE_PROBE2
)
8087 printk(KERN_INFO
"(scsi%d) EEPROM %s present.\n", p
->host_no
,
8088 eprom_present
? "is" : "is not");
8091 * Now set the termination based on what we found. BRDDAT6
8092 * controls wide termination enable.
8093 * Flash Enable = BRDDAT7
8094 * SE High Term Enable = BRDDAT6
8096 if (internal50_present
&& internal68_present
&& external_present
)
8098 printk(KERN_INFO
"(scsi%d) Illegal cable configuration!! Only two\n",
8100 printk(KERN_INFO
"(scsi%d) connectors on the SCSI controller may be "
8101 "in use at a time!\n", p
->host_no
);
8103 * Force termination (low and high byte) on. This is safer than
8104 * leaving it completely off, especially since this message comes
8105 * most often from motherboard controllers that don't even have 3
8106 * connectors, but instead are failing the cable detection.
8108 internal50_present
= external_present
= 0;
8109 enableSE_high
= enableSE_low
= 1;
8112 if ((max_target
> 8) &&
8113 ((external_present
== 0) || (internal68_present
== 0)) )
8116 p
->flags
|= AHC_TERM_ENB_SE_HIGH
;
8117 if (aic7xxx_verbose
& VERBOSE_PROBE2
)
8118 printk(KERN_INFO
"(scsi%d) SE High byte termination Enabled\n",
8122 if ( ((internal50_present
? 1 : 0) +
8123 (internal68_present
? 1 : 0) +
8124 (external_present
? 1 : 0)) <= 1 )
8127 p
->flags
|= AHC_TERM_ENB_SE_LOW
;
8128 if (aic7xxx_verbose
& VERBOSE_PROBE2
)
8129 printk(KERN_INFO
"(scsi%d) SE Low byte termination Enabled\n",
8133 else /* p->adapter_control & CFAUTOTERM */
8135 if (p
->adapter_control
& CFSTERM
)
8138 if (aic7xxx_verbose
& VERBOSE_PROBE2
)
8139 printk(KERN_INFO
"(scsi%d) SE Low byte termination Enabled\n",
8143 if (p
->adapter_control
& CFWSTERM
)
8146 if (aic7xxx_verbose
& VERBOSE_PROBE2
)
8147 printk(KERN_INFO
"(scsi%d) SE High byte termination Enabled\n",
8153 aic_outb(p
, sxfrctl1
, SXFRCTL1
);
8154 write_brdctl(p
, brddat
);
8159 /*+F*************************************************************************
8164 * Detects the maximum number of SCBs for the controller and returns
8165 * the count and a mask in p (p->maxscbs, p->qcntmask).
8166 *-F*************************************************************************/
8168 detect_maxscb(struct aic7xxx_host
*p
)
8173 * It's possible that we've already done this for multichannel
8176 if (p
->scb_data
->maxhscbs
== 0)
8179 * We haven't initialized the SCB settings yet. Walk the SCBs to
8180 * determince how many there are.
8182 aic_outb(p
, 0, FREE_SCBH
);
8184 for (i
= 0; i
< AIC7XXX_MAXSCB
; i
++)
8186 aic_outb(p
, i
, SCBPTR
);
8187 aic_outb(p
, i
, SCB_CONTROL
);
8188 if (aic_inb(p
, SCB_CONTROL
) != i
)
8190 aic_outb(p
, 0, SCBPTR
);
8191 if (aic_inb(p
, SCB_CONTROL
) != 0)
8194 aic_outb(p
, i
, SCBPTR
);
8195 aic_outb(p
, 0, SCB_CONTROL
); /* Clear the control byte. */
8196 aic_outb(p
, i
+ 1, SCB_NEXT
); /* Set the next pointer. */
8197 aic_outb(p
, SCB_LIST_NULL
, SCB_TAG
); /* Make the tag invalid. */
8198 aic_outb(p
, SCB_LIST_NULL
, SCB_BUSYTARGETS
); /* no busy untagged */
8199 aic_outb(p
, SCB_LIST_NULL
, SCB_BUSYTARGETS
+1);/* targets active yet */
8200 aic_outb(p
, SCB_LIST_NULL
, SCB_BUSYTARGETS
+2);
8201 aic_outb(p
, SCB_LIST_NULL
, SCB_BUSYTARGETS
+3);
8204 /* Make sure the last SCB terminates the free list. */
8205 aic_outb(p
, i
- 1, SCBPTR
);
8206 aic_outb(p
, SCB_LIST_NULL
, SCB_NEXT
);
8208 /* Ensure we clear the first (0) SCBs control byte. */
8209 aic_outb(p
, 0, SCBPTR
);
8210 aic_outb(p
, 0, SCB_CONTROL
);
8212 p
->scb_data
->maxhscbs
= i
;
8214 * Use direct indexing instead for speed
8216 if ( i
== AIC7XXX_MAXSCB
)
8217 p
->flags
&= ~AHC_PAGESCBS
;
8222 /*+F*************************************************************************
8227 * Register a Adaptec aic7xxx chip SCSI controller with the kernel.
8228 *-F*************************************************************************/
8230 aic7xxx_register(Scsi_Host_Template
*template, struct aic7xxx_host
*p
,
8236 unsigned char term
, scsi_conf
;
8237 struct Scsi_Host
*host
;
8241 p
->scb_data
->maxscbs
= AIC7XXX_MAXSCB
;
8242 host
->can_queue
= AIC7XXX_MAXSCB
;
8243 host
->cmd_per_lun
= 3;
8244 host
->sg_tablesize
= AIC7XXX_MAX_SG
;
8245 host
->select_queue_depths
= aic7xxx_select_queue_depth
;
8246 host
->this_id
= p
->scsi_id
;
8247 host
->io_port
= p
->base
;
8248 host
->n_io_port
= 0xFF;
8249 host
->base
= p
->mbase
;
8251 if (p
->features
& AHC_WIDE
)
8255 if (p
->features
& AHC_TWIN
)
8257 host
->max_channel
= 1;
8261 p
->host_no
= host
->host_no
;
8262 host
->unique_id
= p
->instance
;
8265 p
->completeq
.head
= NULL
;
8266 p
->completeq
.tail
= NULL
;
8267 scbq_init(&p
->scb_data
->free_scbs
);
8268 scbq_init(&p
->waiting_scbs
);
8269 init_timer(&p
->dev_timer
);
8270 p
->dev_timer
.data
= (unsigned long)p
;
8271 p
->dev_timer
.function
= (void *)aic7xxx_timer
;
8272 p
->dev_timer_active
= 0;
8275 * We currently have no commands of any type
8278 p
->qoutfifonext
= 0;
8280 for (i
= 0; i
< MAX_TARGETS
; i
++)
8282 p
->dev_commands_sent
[i
] = 0;
8283 p
->dev_flags
[i
] = 0;
8284 p
->dev_active_cmds
[i
] = 0;
8285 p
->dev_last_queue_full
[i
] = 0;
8286 p
->dev_last_queue_full_count
[i
] = 0;
8287 p
->dev_max_queue_depth
[i
] = 1;
8288 p
->dev_temp_queue_depth
[i
] = 1;
8289 p
->dev_expires
[i
] = 0;
8290 scbq_init(&p
->delayed_scbs
[i
]);
8293 printk(KERN_INFO
"(scsi%d) <%s> found at ", p
->host_no
,
8294 board_names
[p
->board_name_index
]);
8297 case (AHC_AIC7770
|AHC_EISA
):
8298 printk("EISA slot %d\n", p
->pci_device_fn
);
8300 case (AHC_AIC7770
|AHC_VL
):
8301 printk("VLB slot %d\n", p
->pci_device_fn
);
8304 printk("PCI %d/%d/%d\n", p
->pci_bus
, PCI_SLOT(p
->pci_device_fn
),
8305 PCI_FUNC(p
->pci_device_fn
));
8308 if (p
->features
& AHC_TWIN
)
8310 printk(KERN_INFO
"(scsi%d) Twin Channel, A SCSI ID %d, B SCSI ID %d, ",
8311 p
->host_no
, p
->scsi_id
, p
->scsi_id_b
);
8319 if ((p
->flags
& AHC_MULTI_CHANNEL
) != 0)
8323 if ( (p
->flags
& (AHC_CHNLB
|AHC_CHNLC
)) != 0 )
8325 channel
= (p
->flags
& AHC_CHNLB
) ? " B" : " C";
8328 if (p
->features
& AHC_WIDE
)
8330 printk(KERN_INFO
"(scsi%d) Wide ", p
->host_no
);
8334 printk(KERN_INFO
"(scsi%d) Narrow ", p
->host_no
);
8336 printk("Channel%s, SCSI ID=%d, ", channel
, p
->scsi_id
);
8338 aic_outb(p
, 0, SEQ_FLAGS
);
8342 printk("%d/%d SCBs\n", p
->scb_data
->maxhscbs
, p
->scb_data
->maxscbs
);
8343 if (aic7xxx_verbose
& VERBOSE_PROBE2
)
8345 printk(KERN_INFO
"(scsi%d) BIOS %sabled, IO Port 0x%lx, IRQ %d\n",
8346 p
->host_no
, (p
->flags
& AHC_BIOS_ENABLED
) ? "en" : "dis",
8348 printk(KERN_INFO
"(scsi%d) IO Memory at 0x%lx, MMAP Memory at 0x%lx\n",
8349 p
->host_no
, p
->mbase
, (unsigned long)p
->maddr
);
8354 * Now that we know our instance number, we can set the flags we need to
8355 * force termination if need be.
8357 if (aic7xxx_stpwlev
!= -1)
8360 * This option only applies to PCI controllers.
8362 if ( (p
->chip
& ~AHC_CHIPID_MASK
) == AHC_PCI
)
8364 unsigned char devconfig
;
8366 pci_read_config_byte(p
->pdev
, DEVCONFIG
, &devconfig
);
8367 if ( (aic7xxx_stpwlev
>> p
->instance
) & 0x01 )
8369 devconfig
|= STPWLEVEL
;
8370 if (aic7xxx_verbose
& VERBOSE_PROBE2
)
8371 printk("(scsi%d) Force setting STPWLEVEL bit\n", p
->host_no
);
8375 devconfig
&= ~STPWLEVEL
;
8376 if (aic7xxx_verbose
& VERBOSE_PROBE2
)
8377 printk("(scsi%d) Force clearing STPWLEVEL bit\n", p
->host_no
);
8379 pci_write_config_byte(p
->pdev
, DEVCONFIG
, devconfig
);
8385 * That took care of devconfig and stpwlev, now for the actual termination
8388 if (aic7xxx_override_term
!= -1)
8391 * Again, this only applies to PCI controllers. We don't have problems
8392 * with the termination on 274x controllers to the best of my knowledge.
8394 if ( (p
->chip
& ~AHC_CHIPID_MASK
) == AHC_PCI
)
8396 unsigned char term_override
;
8398 term_override
= ( (aic7xxx_override_term
>> (p
->instance
* 4)) & 0x0f);
8399 p
->adapter_control
&=
8400 ~(CFSTERM
|CFWSTERM
|CFLVDSTERM
|CFAUTOTERM
|CFSEAUTOTERM
);
8401 if ( (p
->features
& AHC_ULTRA2
) && (term_override
& 0x0c) )
8403 p
->adapter_control
|= CFLVDSTERM
;
8405 if (term_override
& 0x02)
8407 p
->adapter_control
|= CFWSTERM
;
8409 if (term_override
& 0x01)
8411 p
->adapter_control
|= CFSTERM
;
8416 if ( (p
->flags
& AHC_SEEPROM_FOUND
) || (aic7xxx_override_term
!= -1) )
8418 if (p
->features
& AHC_SPIOCAP
)
8420 if ( aic_inb(p
, SPIOCAP
) & SSPIOCPS
)
8422 * Update the settings in sxfrctl1 to match the termination
8425 configure_termination(p
);
8427 else if ((p
->chip
& AHC_CHIPID_MASK
) >= AHC_AIC7870
)
8429 configure_termination(p
);
8434 * Set the SCSI Id, SXFRCTL0, SXFRCTL1, and SIMODE1, for both channels
8436 if (p
->features
& AHC_TWIN
)
8438 /* Select channel B */
8439 aic_outb(p
, aic_inb(p
, SBLKCTL
) | SELBUSB
, SBLKCTL
);
8441 if ((p
->flags
& AHC_SEEPROM_FOUND
) || (aic7xxx_override_term
!= -1))
8442 term
= (aic_inb(p
, SXFRCTL1
) & STPWEN
);
8444 term
= ((p
->flags
& AHC_TERM_ENB_B
) ? STPWEN
: 0);
8446 aic_outb(p
, p
->scsi_id_b
, SCSIID
);
8447 scsi_conf
= aic_inb(p
, SCSICONF
+ 1);
8448 aic_outb(p
, DFON
| SPIOEN
, SXFRCTL0
);
8449 aic_outb(p
, (scsi_conf
& ENSPCHK
) | aic7xxx_seltime
| term
|
8450 ENSTIMER
| ACTNEGEN
, SXFRCTL1
);
8451 aic_outb(p
, 0, SIMODE0
);
8452 aic_outb(p
, ENSELTIMO
| ENSCSIRST
| ENSCSIPERR
, SIMODE1
);
8453 aic_outb(p
, 0, SCSIRATE
);
8455 /* Select channel A */
8456 aic_outb(p
, aic_inb(p
, SBLKCTL
) & ~SELBUSB
, SBLKCTL
);
8459 if (p
->features
& AHC_ULTRA2
)
8461 aic_outb(p
, p
->scsi_id
, SCSIID_ULTRA2
);
8465 aic_outb(p
, p
->scsi_id
, SCSIID
);
8467 if ((p
->flags
& AHC_SEEPROM_FOUND
) || (aic7xxx_override_term
!= -1))
8468 term
= (aic_inb(p
, SXFRCTL1
) & STPWEN
);
8470 term
= ((p
->flags
& (AHC_TERM_ENB_A
|AHC_TERM_ENB_LVD
)) ? STPWEN
: 0);
8471 scsi_conf
= aic_inb(p
, SCSICONF
);
8472 aic_outb(p
, DFON
| SPIOEN
, SXFRCTL0
);
8473 aic_outb(p
, (scsi_conf
& ENSPCHK
) | aic7xxx_seltime
| term
|
8474 ENSTIMER
| ACTNEGEN
, SXFRCTL1
);
8475 aic_outb(p
, 0, SIMODE0
);
8477 * If we are a cardbus adapter then don't enable SCSI reset detection.
8478 * We shouldn't likely be sharing SCSI busses with someone else, and
8479 * if we don't have a cable currently plugged into the controller then
8480 * we won't have a power source for the SCSI termination, which means
8481 * we'll see infinite incoming bus resets.
8483 if(p
->flags
& AHC_NO_STPWEN
)
8484 aic_outb(p
, ENSELTIMO
| ENSCSIPERR
, SIMODE1
);
8486 aic_outb(p
, ENSELTIMO
| ENSCSIRST
| ENSCSIPERR
, SIMODE1
);
8487 aic_outb(p
, 0, SCSIRATE
);
8488 if ( p
->features
& AHC_ULTRA2
)
8489 aic_outb(p
, 0, SCSIOFFSET
);
8492 * Look at the information that board initialization or the board
8493 * BIOS has left us. In the lower four bits of each target's
8494 * scratch space any value other than 0 indicates that we should
8495 * initiate synchronous transfers. If it's zero, the user or the
8496 * BIOS has decided to disable synchronous negotiation to that
8497 * target so we don't activate the needsdtr flag.
8499 if ((p
->features
& (AHC_TWIN
|AHC_WIDE
)) == 0)
8508 if (!(aic7xxx_no_reset
))
8511 * If we reset the bus, then clear the transfer settings, else leave
8514 for (i
= 0; i
< max_targets
; i
++)
8516 aic_outb(p
, 0, TARG_SCSIRATE
+ i
);
8517 if (p
->features
& AHC_ULTRA2
)
8519 aic_outb(p
, 0, TARG_OFFSET
+ i
);
8521 p
->transinfo
[i
].cur_offset
= 0;
8522 p
->transinfo
[i
].cur_period
= 0;
8523 p
->transinfo
[i
].cur_width
= MSG_EXT_WDTR_BUS_8_BIT
;
8527 * If we reset the bus, then clear the transfer settings, else leave
8530 aic_outb(p
, 0, ULTRA_ENB
);
8531 aic_outb(p
, 0, ULTRA_ENB
+ 1);
8536 * Allocate enough hardware scbs to handle the maximum number of
8537 * concurrent transactions we can have. We have to make sure that
8538 * the allocated memory is contiguous memory. The Linux kmalloc
8539 * routine should only allocate contiguous memory, but note that
8540 * this could be a problem if kmalloc() is changed.
8544 unsigned int hscb_physaddr
;
8546 array_size
= p
->scb_data
->maxscbs
* sizeof(struct aic7xxx_hwscb
);
8547 if (p
->scb_data
->hscbs
== NULL
)
8549 /* pci_alloc_consistent enforces the alignment already and
8550 * clears the area as well.
8552 p
->scb_data
->hscbs
= pci_alloc_consistent(p
->pdev
, array_size
,
8553 &p
->scb_data
->hscbs_dma
);
8554 /* We have to use pci_free_consistent, not kfree */
8555 p
->scb_data
->hscb_kmalloc_ptr
= NULL
;
8556 p
->scb_data
->hscbs_dma_len
= array_size
;
8558 if (p
->scb_data
->hscbs
== NULL
)
8560 printk("(scsi%d) Unable to allocate hardware SCB array; "
8561 "failing detection.\n", p
->host_no
);
8562 aic_outb(p
, 0, SIMODE1
);
8567 hscb_physaddr
= p
->scb_data
->hscbs_dma
;
8568 aic_outb(p
, hscb_physaddr
& 0xFF, HSCB_ADDR
);
8569 aic_outb(p
, (hscb_physaddr
>> 8) & 0xFF, HSCB_ADDR
+ 1);
8570 aic_outb(p
, (hscb_physaddr
>> 16) & 0xFF, HSCB_ADDR
+ 2);
8571 aic_outb(p
, (hscb_physaddr
>> 24) & 0xFF, HSCB_ADDR
+ 3);
8573 /* Set up the fifo areas at the same time */
8574 p
->untagged_scbs
= pci_alloc_consistent(p
->pdev
, 3*256, &p
->fifo_dma
);
8575 if (p
->untagged_scbs
== NULL
)
8577 printk("(scsi%d) Unable to allocate hardware FIFO arrays; "
8578 "failing detection.\n", p
->host_no
);
8583 p
->qoutfifo
= p
->untagged_scbs
+ 256;
8584 p
->qinfifo
= p
->qoutfifo
+ 256;
8585 for (i
= 0; i
< 256; i
++)
8587 p
->untagged_scbs
[i
] = SCB_LIST_NULL
;
8588 p
->qinfifo
[i
] = SCB_LIST_NULL
;
8589 p
->qoutfifo
[i
] = SCB_LIST_NULL
;
8592 hscb_physaddr
= p
->fifo_dma
;
8593 aic_outb(p
, hscb_physaddr
& 0xFF, SCBID_ADDR
);
8594 aic_outb(p
, (hscb_physaddr
>> 8) & 0xFF, SCBID_ADDR
+ 1);
8595 aic_outb(p
, (hscb_physaddr
>> 16) & 0xFF, SCBID_ADDR
+ 2);
8596 aic_outb(p
, (hscb_physaddr
>> 24) & 0xFF, SCBID_ADDR
+ 3);
8599 /* The Q-FIFOs we just set up are all empty */
8600 aic_outb(p
, 0, QINPOS
);
8601 aic_outb(p
, 0, KERNEL_QINPOS
);
8602 aic_outb(p
, 0, QOUTPOS
);
8604 if(p
->features
& AHC_QUEUE_REGS
)
8606 aic_outb(p
, SCB_QSIZE_256
, QOFF_CTLSTA
);
8607 aic_outb(p
, 0, SDSCB_QOFF
);
8608 aic_outb(p
, 0, SNSCB_QOFF
);
8609 aic_outb(p
, 0, HNSCB_QOFF
);
8613 * We don't have any waiting selections or disconnected SCBs.
8615 aic_outb(p
, SCB_LIST_NULL
, WAITING_SCBH
);
8616 aic_outb(p
, SCB_LIST_NULL
, DISCONNECTED_SCBH
);
8619 * Message out buffer starts empty
8621 aic_outb(p
, MSG_NOOP
, MSG_OUT
);
8622 aic_outb(p
, MSG_NOOP
, LAST_MSG
);
8625 * Set all the other asundry items that haven't been set yet.
8626 * This includes just dumping init values to a lot of registers simply
8627 * to make sure they've been touched and are ready for use parity wise
8630 aic_outb(p
, 0, TMODE_CMDADDR
);
8631 aic_outb(p
, 0, TMODE_CMDADDR
+ 1);
8632 aic_outb(p
, 0, TMODE_CMDADDR
+ 2);
8633 aic_outb(p
, 0, TMODE_CMDADDR
+ 3);
8634 aic_outb(p
, 0, TMODE_CMDADDR_NEXT
);
8637 * Link us into the list of valid hosts
8639 p
->next
= first_aic7xxx
;
8643 * Allocate the first set of scbs for this controller. This is to stream-
8644 * line code elsewhere in the driver. If we have to check for the existence
8645 * of scbs in certain code sections, it slows things down. However, as
8646 * soon as we register the IRQ for this card, we could get an interrupt that
8647 * includes possibly the SCSI_RSTI interrupt. If we catch that interrupt
8648 * then we are likely to segfault if we don't have at least one chunk of
8649 * SCBs allocated or add checks all through the reset code to make sure
8650 * that the SCBs have been allocated which is an invalid running condition
8651 * and therefore I think it's preferable to simply pre-allocate the first
8654 aic7xxx_allocate_scb(p
);
8657 * Load the sequencer program, then re-enable the board -
8658 * resetting the AIC-7770 disables it, leaving the lights
8659 * on with nobody home.
8664 * Make sure the AUTOFLUSHDIS bit is *not* set in the SBLKCTL register
8666 aic_outb(p
, aic_inb(p
, SBLKCTL
) & ~AUTOFLUSHDIS
, SBLKCTL
);
8668 if ( (p
->chip
& AHC_CHIPID_MASK
) == AHC_AIC7770
)
8670 aic_outb(p
, ENABLE
, BCTL
); /* Enable the boards BUS drivers. */
8673 if ( !(aic7xxx_no_reset
) )
8675 if (p
->features
& AHC_TWIN
)
8677 if (aic7xxx_verbose
& VERBOSE_PROBE2
)
8678 printk(KERN_INFO
"(scsi%d) Resetting channel B\n", p
->host_no
);
8679 aic_outb(p
, aic_inb(p
, SBLKCTL
) | SELBUSB
, SBLKCTL
);
8680 aic7xxx_reset_current_bus(p
);
8681 aic_outb(p
, aic_inb(p
, SBLKCTL
) & ~SELBUSB
, SBLKCTL
);
8683 /* Reset SCSI bus A. */
8684 if (aic7xxx_verbose
& VERBOSE_PROBE2
)
8685 { /* In case we are a 3940, 3985, or 7895, print the right channel */
8687 if (p
->flags
& AHC_MULTI_CHANNEL
)
8690 if (p
->flags
& (AHC_CHNLB
|AHC_CHNLC
))
8691 channel
= (p
->flags
& AHC_CHNLB
) ? " B" : " C";
8693 printk(KERN_INFO
"(scsi%d) Resetting channel%s\n", p
->host_no
, channel
);
8696 aic7xxx_reset_current_bus(p
);
8699 * Delay for the reset delay by setting the timer, this will delay
8700 * future commands sent to any devices.
8702 p
->flags
|= AHC_RESET_DELAY
;
8703 for(i
=0; i
<MAX_TARGETS
; i
++)
8705 p
->dev_expires
[i
] = jiffies
+ (4 * HZ
);
8706 p
->dev_timer_active
|= (0x01 << i
);
8708 p
->dev_timer
.expires
= p
->dev_expires
[p
->scsi_id
];
8709 add_timer(&p
->dev_timer
);
8710 p
->dev_timer_active
|= (0x01 << MAX_TARGETS
);
8716 printk(KERN_INFO
"(scsi%d) Not resetting SCSI bus. Note: Don't use "
8717 "the no_reset\n", p
->host_no
);
8718 printk(KERN_INFO
"(scsi%d) option unless you have a verifiable need "
8719 "for it.\n", p
->host_no
);
8724 * Register IRQ with the kernel. Only allow sharing IRQs with
8727 if (!(p
->chip
& AHC_PCI
))
8729 result
= (request_irq(p
->irq
, do_aic7xxx_isr
, 0, "aic7xxx", p
));
8733 result
= (request_irq(p
->irq
, do_aic7xxx_isr
, SA_SHIRQ
,
8737 result
= (request_irq(p
->irq
, do_aic7xxx_isr
, SA_INTERRUPT
| SA_SHIRQ
,
8743 printk(KERN_WARNING
"(scsi%d) Couldn't register IRQ %d, ignoring "
8744 "controller.\n", p
->host_no
, p
->irq
);
8745 aic_outb(p
, 0, SIMODE1
);
8750 if(aic_inb(p
, INTSTAT
) & INT_PEND
)
8751 printk(INFO_LEAD
"spurious interrupt during configuration, cleared.\n",
8752 p
->host_no
, -1, -1 , -1);
8753 aic7xxx_clear_intstat(p
);
8755 unpause_sequencer(p
, /* unpause_always */ TRUE
);
8760 /*+F*************************************************************************
8762 * aic7xxx_chip_reset
8765 * Perform a chip reset on the aic7xxx SCSI controller. The controller
8766 * is paused upon return.
8767 *-F*************************************************************************/
8769 aic7xxx_chip_reset(struct aic7xxx_host
*p
)
8771 unsigned char sblkctl
;
8775 * For some 274x boards, we must clear the CHIPRST bit and pause
8776 * the sequencer. For some reason, this makes the driver work.
8778 aic_outb(p
, PAUSE
| CHIPRST
, HCNTRL
);
8781 * In the future, we may call this function as a last resort for
8782 * error handling. Let's be nice and not do any unecessary delays.
8784 wait
= 1000; /* 1 msec (1000 * 1 msec) */
8785 while (--wait
&& !(aic_inb(p
, HCNTRL
) & CHIPRSTACK
))
8787 udelay(1); /* 1 usec */
8792 sblkctl
= aic_inb(p
, SBLKCTL
) & (SELBUSB
|SELWIDE
);
8793 if (p
->chip
& AHC_PCI
)
8794 sblkctl
&= ~SELBUSB
;
8797 case 0: /* normal narrow card */
8799 case 2: /* Wide card */
8800 p
->features
|= AHC_WIDE
;
8802 case 8: /* Twin card */
8803 p
->features
|= AHC_TWIN
;
8804 p
->flags
|= AHC_MULTI_CHANNEL
;
8806 default: /* hmmm...we don't know what this is */
8807 printk(KERN_WARNING
"aic7xxx: Unsupported adapter type %d, ignoring.\n",
8808 aic_inb(p
, SBLKCTL
) & 0x0a);
8814 /*+F*************************************************************************
8819 * Allocate and initialize a host structure. Returns NULL upon error
8820 * and a pointer to a aic7xxx_host struct upon success.
8821 *-F*************************************************************************/
8822 static struct aic7xxx_host
*
8823 aic7xxx_alloc(Scsi_Host_Template
*sht
, struct aic7xxx_host
*temp
)
8825 struct aic7xxx_host
*p
= NULL
;
8826 struct Scsi_Host
*host
;
8830 * Allocate a storage area by registering us with the mid-level
8833 host
= scsi_register(sht
, sizeof(struct aic7xxx_host
));
8837 p
= (struct aic7xxx_host
*) host
->hostdata
;
8838 memset(p
, 0, sizeof(struct aic7xxx_host
));
8842 p
->scb_data
= kmalloc(sizeof(scb_data_type
), GFP_ATOMIC
);
8843 if (p
->scb_data
!= NULL
)
8845 memset(p
->scb_data
, 0, sizeof(scb_data_type
));
8846 scbq_init (&p
->scb_data
->free_scbs
);
8851 * For some reason we don't have enough memory. Free the
8852 * allocated memory for the aic7xxx_host struct, and return NULL.
8854 release_region(p
->base
, MAXREG
- MINREG
);
8855 scsi_unregister(host
);
8858 p
->host_no
= host
->host_no
;
8861 for (i
=0; i
<MAX_TARGETS
; i
++)
8863 p
->transinfo
[i
].goal_period
= 255;
8864 p
->transinfo
[i
].goal_offset
= 0;
8865 p
->transinfo
[i
].goal_options
= 0;
8866 p
->transinfo
[i
].goal_width
= MSG_EXT_WDTR_BUS_8_BIT
;
8873 /*+F*************************************************************************
8878 * Frees and releases all resources associated with an instance of
8879 * the driver (struct aic7xxx_host *).
8880 *-F*************************************************************************/
8882 aic7xxx_free(struct aic7xxx_host
*p
)
8887 * Free the allocated hardware SCB space.
8889 if (p
->scb_data
!= NULL
)
8891 struct aic7xxx_scb_dma
*scb_dma
= NULL
;
8892 if (p
->scb_data
->hscbs
!= NULL
)
8894 pci_free_consistent(p
->pdev
, p
->scb_data
->hscbs_dma_len
,
8895 p
->scb_data
->hscbs
, p
->scb_data
->hscbs_dma
);
8896 p
->scb_data
->hscbs
= p
->scb_data
->hscb_kmalloc_ptr
= NULL
;
8899 * Free the driver SCBs. These were allocated on an as-need
8900 * basis. We allocated these in groups depending on how many
8901 * we could fit into a given amount of RAM. The tail SCB for
8902 * these allocations has a pointer to the alloced area.
8904 for (i
= 0; i
< p
->scb_data
->numscbs
; i
++)
8906 if (p
->scb_data
->scb_array
[i
]->scb_dma
!= scb_dma
)
8908 scb_dma
= p
->scb_data
->scb_array
[i
]->scb_dma
;
8909 pci_free_consistent(p
->pdev
, scb_dma
->dma_len
,
8910 (void *)((unsigned long)scb_dma
->dma_address
8911 - scb_dma
->dma_offset
),
8912 scb_dma
->dma_address
);
8914 if (p
->scb_data
->scb_array
[i
]->kmalloc_ptr
!= NULL
)
8915 kfree(p
->scb_data
->scb_array
[i
]->kmalloc_ptr
);
8916 p
->scb_data
->scb_array
[i
] = NULL
;
8920 * Free the SCB data area.
8926 * Free any alloced Scsi_Cmnd structures that might be around for
8927 * negotiation purposes....
8929 for (i
= 0; i
< MAX_TARGETS
; i
++)
8931 if(p
->dev_dtr_cmnd
[i
])
8933 if(p
->dev_dtr_cmnd
[i
]->request_buffer
)
8935 kfree(p
->dev_dtr_cmnd
[i
]->request_buffer
);
8937 kfree(p
->dev_dtr_cmnd
[i
]);
8941 pci_free_consistent(p
->pdev
, 3*256, (void *)p
->untagged_scbs
, p
->fifo_dma
);
8944 /*+F*************************************************************************
8946 * aic7xxx_load_seeprom
8949 * Load the seeprom and configure adapter and target settings.
8950 * Returns 1 if the load was successful and 0 otherwise.
8951 *-F*************************************************************************/
8953 aic7xxx_load_seeprom(struct aic7xxx_host
*p
, unsigned char *sxfrctl1
)
8955 int have_seeprom
= 0;
8956 int i
, max_targets
, mask
;
8957 unsigned char scsirate
, scsi_conf
;
8958 unsigned short scarray
[128];
8959 struct seeprom_config
*sc
= (struct seeprom_config
*) scarray
;
8961 if (aic7xxx_verbose
& VERBOSE_PROBE2
)
8963 printk(KERN_INFO
"aic7xxx: Loading serial EEPROM...");
8967 case (AHC_AIC7770
|AHC_EISA
): /* None of these adapters have seeproms. */
8968 if (aic_inb(p
, SCSICONF
) & TERM_ENB
)
8969 p
->flags
|= AHC_TERM_ENB_A
;
8970 if ( (p
->features
& AHC_TWIN
) && (aic_inb(p
, SCSICONF
+ 1) & TERM_ENB
) )
8971 p
->flags
|= AHC_TERM_ENB_B
;
8974 case (AHC_AIC7770
|AHC_VL
):
8975 have_seeprom
= read_284x_seeprom(p
, (struct seeprom_config
*) scarray
);
8979 have_seeprom
= read_seeprom(p
, (p
->flags
& (AHC_CHNLB
|AHC_CHNLC
)),
8980 scarray
, p
->sc_size
, p
->sc_type
);
8983 if(p
->sc_type
== C46
)
8984 have_seeprom
= read_seeprom(p
, (p
->flags
& (AHC_CHNLB
|AHC_CHNLC
)),
8985 scarray
, p
->sc_size
, C56_66
);
8987 have_seeprom
= read_seeprom(p
, (p
->flags
& (AHC_CHNLB
|AHC_CHNLC
)),
8988 scarray
, p
->sc_size
, C46
);
8993 have_seeprom
= read_seeprom(p
, 4*(p
->flags
& (AHC_CHNLB
|AHC_CHNLC
)),
8994 scarray
, p
->sc_size
, p
->sc_type
);
8997 if(p
->sc_type
== C46
)
8998 have_seeprom
= read_seeprom(p
, 4*(p
->flags
& (AHC_CHNLB
|AHC_CHNLC
)),
8999 scarray
, p
->sc_size
, C56_66
);
9001 have_seeprom
= read_seeprom(p
, 4*(p
->flags
& (AHC_CHNLB
|AHC_CHNLC
)),
9002 scarray
, p
->sc_size
, C46
);
9010 if (aic7xxx_verbose
& VERBOSE_PROBE2
)
9012 printk("\naic7xxx: No SEEPROM available.\n");
9014 p
->flags
|= AHC_NEWEEPROM_FMT
;
9015 if (aic_inb(p
, SCSISEQ
) == 0)
9017 p
->flags
|= AHC_USEDEFAULTS
;
9018 p
->flags
&= ~AHC_BIOS_ENABLED
;
9019 p
->scsi_id
= p
->scsi_id_b
= 7;
9020 *sxfrctl1
|= STPWEN
;
9021 if (aic7xxx_verbose
& VERBOSE_PROBE2
)
9023 printk("aic7xxx: Using default values.\n");
9026 else if (aic7xxx_verbose
& VERBOSE_PROBE2
)
9028 printk("aic7xxx: Using leftover BIOS values.\n");
9030 if ( ((p
->chip
& ~AHC_CHIPID_MASK
) == AHC_PCI
) && (*sxfrctl1
& STPWEN
) )
9032 p
->flags
|= AHC_TERM_ENB_SE_LOW
| AHC_TERM_ENB_SE_HIGH
;
9033 sc
->adapter_control
&= ~CFAUTOTERM
;
9034 sc
->adapter_control
|= CFSTERM
| CFWSTERM
| CFLVDSTERM
;
9036 if (aic7xxx_extended
)
9037 p
->flags
|= (AHC_EXTEND_TRANS_A
| AHC_EXTEND_TRANS_B
);
9039 p
->flags
&= ~(AHC_EXTEND_TRANS_A
| AHC_EXTEND_TRANS_B
);
9043 if (aic7xxx_verbose
& VERBOSE_PROBE2
)
9049 * Note things in our flags
9051 p
->flags
|= AHC_SEEPROM_FOUND
;
9054 * Update the settings in sxfrctl1 to match the termination settings.
9059 * Get our SCSI ID from the SEEPROM setting...
9061 p
->scsi_id
= (sc
->brtime_id
& CFSCSIID
);
9064 * First process the settings that are different between the VLB
9065 * and PCI adapter seeproms.
9067 if ((p
->chip
& AHC_CHIPID_MASK
) == AHC_AIC7770
)
9069 /* VLB adapter seeproms */
9070 if (sc
->bios_control
& CF284XEXTEND
)
9071 p
->flags
|= AHC_EXTEND_TRANS_A
;
9073 if (sc
->adapter_control
& CF284XSTERM
)
9075 *sxfrctl1
|= STPWEN
;
9076 p
->flags
|= AHC_TERM_ENB_SE_LOW
| AHC_TERM_ENB_SE_HIGH
;
9081 /* PCI adapter seeproms */
9082 if (sc
->bios_control
& CFEXTEND
)
9083 p
->flags
|= AHC_EXTEND_TRANS_A
;
9084 if (sc
->bios_control
& CFBIOSEN
)
9085 p
->flags
|= AHC_BIOS_ENABLED
;
9087 p
->flags
&= ~AHC_BIOS_ENABLED
;
9089 if (sc
->adapter_control
& CFSTERM
)
9091 *sxfrctl1
|= STPWEN
;
9092 p
->flags
|= AHC_TERM_ENB_SE_LOW
| AHC_TERM_ENB_SE_HIGH
;
9095 memcpy(&p
->sc
, sc
, sizeof(struct seeprom_config
));
9101 * Limit to 16 targets just in case. The 2842 for one is known to
9102 * blow the max_targets setting, future cards might also.
9104 max_targets
= ((p
->features
& (AHC_TWIN
| AHC_WIDE
)) ? 16 : 8);
9108 for (i
= 0; i
< max_targets
; i
++)
9110 if( ((p
->features
& AHC_ULTRA
) &&
9111 !(sc
->adapter_control
& CFULTRAEN
) &&
9112 (sc
->device_flags
[i
] & CFSYNCHISULTRA
)) ||
9113 (sc
->device_flags
[i
] & CFNEWULTRAFORMAT
) )
9115 p
->flags
|= AHC_NEWEEPROM_FMT
;
9121 for (i
= 0; i
< max_targets
; i
++)
9126 if (aic_inb(p
, SCSISEQ
) != 0)
9129 * OK...the BIOS set things up and left behind the settings we need.
9130 * Just make our sc->device_flags[i] entry match what the card has
9131 * set for this device.
9134 ~(aic_inb(p
, DISC_DSB
) | (aic_inb(p
, DISC_DSB
+ 1) << 8) );
9136 (aic_inb(p
, ULTRA_ENB
) | (aic_inb(p
, ULTRA_ENB
+ 1) << 8) );
9137 sc
->device_flags
[i
] = (p
->discenable
& mask
) ? CFDISC
: 0;
9138 if (aic_inb(p
, TARG_SCSIRATE
+ i
) & WIDEXFER
)
9139 sc
->device_flags
[i
] |= CFWIDEB
;
9140 if (p
->features
& AHC_ULTRA2
)
9142 if (aic_inb(p
, TARG_OFFSET
+ i
))
9144 sc
->device_flags
[i
] |= CFSYNCH
;
9145 sc
->device_flags
[i
] |= (aic_inb(p
, TARG_SCSIRATE
+ i
) & 0x07);
9146 if ( (aic_inb(p
, TARG_SCSIRATE
+ i
) & 0x18) == 0x18 )
9147 sc
->device_flags
[i
] |= CFSYNCHISULTRA
;
9152 if (aic_inb(p
, TARG_SCSIRATE
+ i
) & ~WIDEXFER
)
9154 sc
->device_flags
[i
] |= CFSYNCH
;
9155 if (p
->features
& AHC_ULTRA
)
9156 sc
->device_flags
[i
] |= ((p
->ultraenb
& mask
) ?
9157 CFSYNCHISULTRA
: 0);
9164 * Assume the BIOS has NOT been run on this card and nothing between
9165 * the card and the devices is configured yet.
9167 sc
->device_flags
[i
] = CFDISC
;
9168 if (p
->features
& AHC_WIDE
)
9169 sc
->device_flags
[i
] |= CFWIDEB
;
9170 if (p
->features
& AHC_ULTRA3
)
9171 sc
->device_flags
[i
] |= 2;
9172 else if (p
->features
& AHC_ULTRA2
)
9173 sc
->device_flags
[i
] |= 3;
9174 else if (p
->features
& AHC_ULTRA
)
9175 sc
->device_flags
[i
] |= CFSYNCHISULTRA
;
9176 sc
->device_flags
[i
] |= CFSYNCH
;
9177 aic_outb(p
, 0, TARG_SCSIRATE
+ i
);
9178 if (p
->features
& AHC_ULTRA2
)
9179 aic_outb(p
, 0, TARG_OFFSET
+ i
);
9182 if (sc
->device_flags
[i
] & CFDISC
)
9184 p
->discenable
|= mask
;
9186 if (p
->flags
& AHC_NEWEEPROM_FMT
)
9188 if ( !(p
->features
& AHC_ULTRA2
) )
9191 * I know of two different Ultra BIOSes that do this differently.
9192 * One on the Gigabyte 6BXU mb that wants flags[i] & CFXFER to
9193 * be == to 0x03 and SYNCHISULTRA to be true to mean 40MByte/s
9194 * while on the IBM Netfinity 5000 they want the same thing
9195 * to be something else, while flags[i] & CFXFER == 0x03 and
9196 * SYNCHISULTRA false should be 40MByte/s. So, we set both to
9197 * 40MByte/s and the lower speeds be damned. People will have
9198 * to select around the conversely mapped lower speeds in order
9199 * to select lower speeds on these boards.
9201 if ( (sc
->device_flags
[i
] & CFNEWULTRAFORMAT
) &&
9202 ((sc
->device_flags
[i
] & CFXFER
) == 0x03) )
9204 sc
->device_flags
[i
] &= ~CFXFER
;
9205 sc
->device_flags
[i
] |= CFSYNCHISULTRA
;
9207 if (sc
->device_flags
[i
] & CFSYNCHISULTRA
)
9209 p
->ultraenb
|= mask
;
9212 else if ( !(sc
->device_flags
[i
] & CFNEWULTRAFORMAT
) &&
9213 (p
->features
& AHC_ULTRA2
) &&
9214 (sc
->device_flags
[i
] & CFSYNCHISULTRA
) )
9216 p
->ultraenb
|= mask
;
9219 else if (sc
->adapter_control
& CFULTRAEN
)
9221 p
->ultraenb
|= mask
;
9223 if ( (sc
->device_flags
[i
] & CFSYNCH
) == 0)
9225 sc
->device_flags
[i
] &= ~CFXFER
;
9226 p
->ultraenb
&= ~mask
;
9227 p
->transinfo
[i
].user_offset
= 0;
9228 p
->transinfo
[i
].user_period
= 0;
9229 p
->transinfo
[i
].user_options
= 0;
9230 p
->transinfo
[i
].cur_offset
= 0;
9231 p
->transinfo
[i
].cur_period
= 0;
9232 p
->transinfo
[i
].cur_options
= 0;
9233 p
->needsdtr_copy
&= ~mask
;
9237 if (p
->features
& AHC_ULTRA3
)
9239 p
->transinfo
[i
].user_offset
= MAX_OFFSET_ULTRA2
;
9240 p
->transinfo
[i
].cur_offset
= aic_inb(p
, TARG_OFFSET
+ i
);
9241 if( (sc
->device_flags
[i
] & CFXFER
) < 0x03 )
9243 scsirate
= (sc
->device_flags
[i
] & CFXFER
);
9244 p
->transinfo
[i
].user_options
= MSG_EXT_PPR_OPTION_DT_CRC
;
9245 if( (aic_inb(p
, TARG_SCSIRATE
+ i
) & CFXFER
) < 0x03 )
9247 p
->transinfo
[i
].cur_options
=
9248 ((aic_inb(p
, TARG_SCSIRATE
+ i
) & 0x40) ?
9249 MSG_EXT_PPR_OPTION_DT_CRC
: MSG_EXT_PPR_OPTION_DT_UNITS
);
9253 p
->transinfo
[i
].cur_options
= 0;
9258 scsirate
= (sc
->device_flags
[i
] & CFXFER
) |
9259 ((p
->ultraenb
& mask
) ? 0x18 : 0x10);
9260 p
->transinfo
[i
].user_options
= 0;
9261 p
->transinfo
[i
].cur_options
= 0;
9263 p
->transinfo
[i
].user_period
= aic7xxx_find_period(p
, scsirate
,
9264 AHC_SYNCRATE_ULTRA3
);
9265 p
->transinfo
[i
].cur_period
= aic7xxx_find_period(p
,
9266 aic_inb(p
, TARG_SCSIRATE
+ i
),
9267 AHC_SYNCRATE_ULTRA3
);
9269 else if (p
->features
& AHC_ULTRA2
)
9271 p
->transinfo
[i
].user_offset
= MAX_OFFSET_ULTRA2
;
9272 p
->transinfo
[i
].cur_offset
= aic_inb(p
, TARG_OFFSET
+ i
);
9273 scsirate
= (sc
->device_flags
[i
] & CFXFER
) |
9274 ((p
->ultraenb
& mask
) ? 0x18 : 0x10);
9275 p
->transinfo
[i
].user_options
= 0;
9276 p
->transinfo
[i
].cur_options
= 0;
9277 p
->transinfo
[i
].user_period
= aic7xxx_find_period(p
, scsirate
,
9278 AHC_SYNCRATE_ULTRA2
);
9279 p
->transinfo
[i
].cur_period
= aic7xxx_find_period(p
,
9280 aic_inb(p
, TARG_SCSIRATE
+ i
),
9281 AHC_SYNCRATE_ULTRA2
);
9285 scsirate
= (sc
->device_flags
[i
] & CFXFER
) << 4;
9286 p
->transinfo
[i
].user_options
= 0;
9287 p
->transinfo
[i
].cur_options
= 0;
9288 p
->transinfo
[i
].user_offset
= MAX_OFFSET_8BIT
;
9289 if (p
->features
& AHC_ULTRA
)
9292 ultraenb
= aic_inb(p
, ULTRA_ENB
) |
9293 (aic_inb(p
, ULTRA_ENB
+ 1) << 8);
9294 p
->transinfo
[i
].user_period
= aic7xxx_find_period(p
,
9296 (p
->ultraenb
& mask
) ?
9297 AHC_SYNCRATE_ULTRA
:
9299 p
->transinfo
[i
].cur_period
= aic7xxx_find_period(p
,
9300 aic_inb(p
, TARG_SCSIRATE
+ i
),
9302 AHC_SYNCRATE_ULTRA
:
9306 p
->transinfo
[i
].user_period
= aic7xxx_find_period(p
,
9307 scsirate
, AHC_SYNCRATE_FAST
);
9309 p
->needsdtr_copy
|= mask
;
9311 if ( (sc
->device_flags
[i
] & CFWIDEB
) && (p
->features
& AHC_WIDE
) )
9313 p
->transinfo
[i
].user_width
= MSG_EXT_WDTR_BUS_16_BIT
;
9314 p
->needwdtr_copy
|= mask
;
9318 p
->transinfo
[i
].user_width
= MSG_EXT_WDTR_BUS_8_BIT
;
9319 p
->needwdtr_copy
&= ~mask
;
9321 p
->transinfo
[i
].cur_width
=
9322 (aic_inb(p
, TARG_SCSIRATE
+ i
) & WIDEXFER
) ?
9323 MSG_EXT_WDTR_BUS_16_BIT
: MSG_EXT_WDTR_BUS_8_BIT
;
9325 aic_outb(p
, ~(p
->discenable
& 0xFF), DISC_DSB
);
9326 aic_outb(p
, ~((p
->discenable
>> 8) & 0xFF), DISC_DSB
+ 1);
9327 p
->needppr
= p
->needppr_copy
= p
->needdv
= 0;
9328 p
->needwdtr
= p
->needwdtr_copy
;
9329 p
->needsdtr
= p
->needsdtr_copy
;
9333 * We set the p->ultraenb from the SEEPROM to begin with, but now we make
9334 * it match what is already down in the card. If we are doing a reset
9335 * on the card then this will get put back to a default state anyway.
9336 * This allows us to not have to pre-emptively negotiate when using the
9339 if (p
->features
& AHC_ULTRA
)
9340 p
->ultraenb
= aic_inb(p
, ULTRA_ENB
) | (aic_inb(p
, ULTRA_ENB
+ 1) << 8);
9343 scsi_conf
= (p
->scsi_id
& HSCSIID
);
9347 p
->adapter_control
= sc
->adapter_control
;
9348 p
->bios_control
= sc
->bios_control
;
9350 switch (p
->chip
& AHC_CHIPID_MASK
)
9355 if (p
->adapter_control
& CFBPRIMARY
)
9356 p
->flags
|= AHC_CHANNEL_B_PRIMARY
;
9361 if (sc
->adapter_control
& CFSPARITY
)
9362 scsi_conf
|= ENSPCHK
;
9366 scsi_conf
|= ENSPCHK
| RESET_SCSI
;
9370 * Only set the SCSICONF and SCSICONF + 1 registers if we are a PCI card.
9371 * The 2842 and 2742 cards already have these registers set and we don't
9372 * want to muck with them since we don't set all the bits they do.
9374 if ( (p
->chip
& ~AHC_CHIPID_MASK
) == AHC_PCI
)
9376 /* Set the host ID */
9377 aic_outb(p
, scsi_conf
, SCSICONF
);
9378 /* In case we are a wide card */
9379 aic_outb(p
, p
->scsi_id
, SCSICONF
+ 1);
9383 /*+F*************************************************************************
9388 * Try to detect and register an Adaptec 7770 or 7870 SCSI controller.
9390 * XXX - This should really be called aic7xxx_probe(). A sequence of
9391 * probe(), attach()/detach(), and init() makes more sense than
9392 * one do-it-all function. This may be useful when (and if) the
9393 * mid-level SCSI code is overhauled.
9394 *-F*************************************************************************/
9396 aic7xxx_detect(Scsi_Host_Template
*template)
9398 struct aic7xxx_host
*temp_p
= NULL
;
9399 struct aic7xxx_host
*current_p
= NULL
;
9400 struct aic7xxx_host
*list_p
= NULL
;
9402 #if defined(__i386__) || defined(__alpha__)
9403 ahc_flag_type flags
= 0;
9406 unsigned char sxfrctl1
;
9407 #if defined(__i386__) || defined(__alpha__)
9408 unsigned char hcntrl
, hostconf
;
9409 unsigned int slot
, base
;
9414 * If we are called as a module, the aic7xxx pointer may not be null
9415 * and it would point to our bootup string, just like on the lilo
9416 * command line. IF not NULL, then process this config string with
9420 aic7xxx_setup(aic7xxx
);
9421 if(dummy_buffer
[0] != 'P')
9422 printk(KERN_WARNING
"aic7xxx: Please read the file /usr/src/linux/drivers"
9423 "/scsi/README.aic7xxx\n"
9424 "aic7xxx: to see the proper way to specify options to the aic7xxx "
9426 "aic7xxx: Specifically, don't use any commas when passing arguments to\n"
9427 "aic7xxx: insmod or else it might trash certain memory areas.\n");
9430 template->proc_name
= "aic7xxx";
9431 template->sg_tablesize
= AIC7XXX_MAX_SG
;
9442 unsigned short vendor_id
;
9443 unsigned short device_id
;
9445 ahc_flag_type flags
;
9446 ahc_feature features
;
9447 int board_name_index
;
9448 unsigned short seeprom_size
;
9449 unsigned short seeprom_type
;
9450 } const aic_pdevs
[] = {
9451 {PCI_VENDOR_ID_ADAPTEC
, PCI_DEVICE_ID_ADAPTEC_7810
, AHC_NONE
,
9452 AHC_FNONE
, AHC_FENONE
, 1,
9454 {PCI_VENDOR_ID_ADAPTEC
, PCI_DEVICE_ID_ADAPTEC_7850
, AHC_AIC7850
,
9455 AHC_PAGESCBS
, AHC_AIC7850_FE
, 5,
9457 {PCI_VENDOR_ID_ADAPTEC
, PCI_DEVICE_ID_ADAPTEC_7855
, AHC_AIC7850
,
9458 AHC_PAGESCBS
, AHC_AIC7850_FE
, 6,
9460 {PCI_VENDOR_ID_ADAPTEC
, PCI_DEVICE_ID_ADAPTEC_7821
, AHC_AIC7860
,
9461 AHC_PAGESCBS
| AHC_NEWEEPROM_FMT
| AHC_BIOS_ENABLED
,
9464 {PCI_VENDOR_ID_ADAPTEC
, PCI_DEVICE_ID_ADAPTEC_3860
, AHC_AIC7860
,
9465 AHC_PAGESCBS
| AHC_NEWEEPROM_FMT
| AHC_BIOS_ENABLED
,
9468 {PCI_VENDOR_ID_ADAPTEC
, PCI_DEVICE_ID_ADAPTEC_38602
, AHC_AIC7860
,
9469 AHC_PAGESCBS
| AHC_NEWEEPROM_FMT
| AHC_BIOS_ENABLED
,
9472 {PCI_VENDOR_ID_ADAPTEC
, PCI_DEVICE_ID_ADAPTEC_38602
, AHC_AIC7860
,
9473 AHC_PAGESCBS
| AHC_NEWEEPROM_FMT
| AHC_BIOS_ENABLED
,
9476 {PCI_VENDOR_ID_ADAPTEC
, PCI_DEVICE_ID_ADAPTEC_7860
, AHC_AIC7860
,
9477 AHC_PAGESCBS
| AHC_NEWEEPROM_FMT
| AHC_BIOS_ENABLED
| AHC_MOTHERBOARD
,
9480 {PCI_VENDOR_ID_ADAPTEC
, PCI_DEVICE_ID_ADAPTEC_7861
, AHC_AIC7860
,
9481 AHC_PAGESCBS
| AHC_NEWEEPROM_FMT
| AHC_BIOS_ENABLED
,
9484 {PCI_VENDOR_ID_ADAPTEC
, PCI_DEVICE_ID_ADAPTEC_7870
, AHC_AIC7870
,
9485 AHC_PAGESCBS
| AHC_BIOS_ENABLED
| AHC_MOTHERBOARD
,
9488 {PCI_VENDOR_ID_ADAPTEC
, PCI_DEVICE_ID_ADAPTEC_7871
, AHC_AIC7870
,
9489 AHC_PAGESCBS
| AHC_BIOS_ENABLED
, AHC_AIC7870_FE
, 10,
9491 {PCI_VENDOR_ID_ADAPTEC
, PCI_DEVICE_ID_ADAPTEC_7872
, AHC_AIC7870
,
9492 AHC_PAGESCBS
| AHC_BIOS_ENABLED
| AHC_MULTI_CHANNEL
,
9495 {PCI_VENDOR_ID_ADAPTEC
, PCI_DEVICE_ID_ADAPTEC_7873
, AHC_AIC7870
,
9496 AHC_PAGESCBS
| AHC_BIOS_ENABLED
| AHC_MULTI_CHANNEL
,
9499 {PCI_VENDOR_ID_ADAPTEC
, PCI_DEVICE_ID_ADAPTEC_7874
, AHC_AIC7870
,
9500 AHC_PAGESCBS
| AHC_BIOS_ENABLED
, AHC_AIC7870_FE
, 13,
9502 {PCI_VENDOR_ID_ADAPTEC
, PCI_DEVICE_ID_ADAPTEC_7880
, AHC_AIC7880
,
9503 AHC_PAGESCBS
| AHC_BIOS_ENABLED
| AHC_MOTHERBOARD
,
9506 {PCI_VENDOR_ID_ADAPTEC
, PCI_DEVICE_ID_ADAPTEC_7881
, AHC_AIC7880
,
9507 AHC_PAGESCBS
| AHC_BIOS_ENABLED
, AHC_AIC7880_FE
, 15,
9509 {PCI_VENDOR_ID_ADAPTEC
, PCI_DEVICE_ID_ADAPTEC_7882
, AHC_AIC7880
,
9510 AHC_PAGESCBS
| AHC_BIOS_ENABLED
| AHC_MULTI_CHANNEL
,
9513 {PCI_VENDOR_ID_ADAPTEC
, PCI_DEVICE_ID_ADAPTEC_7883
, AHC_AIC7880
,
9514 AHC_PAGESCBS
| AHC_BIOS_ENABLED
| AHC_MULTI_CHANNEL
,
9517 {PCI_VENDOR_ID_ADAPTEC
, PCI_DEVICE_ID_ADAPTEC_7884
, AHC_AIC7880
,
9518 AHC_PAGESCBS
| AHC_BIOS_ENABLED
, AHC_AIC7880_FE
, 18,
9520 {PCI_VENDOR_ID_ADAPTEC
, PCI_DEVICE_ID_ADAPTEC_7885
, AHC_AIC7880
,
9521 AHC_PAGESCBS
| AHC_BIOS_ENABLED
, AHC_AIC7880_FE
, 18,
9523 {PCI_VENDOR_ID_ADAPTEC
, PCI_DEVICE_ID_ADAPTEC_7886
, AHC_AIC7880
,
9524 AHC_PAGESCBS
| AHC_BIOS_ENABLED
, AHC_AIC7880_FE
, 18,
9526 {PCI_VENDOR_ID_ADAPTEC
, PCI_DEVICE_ID_ADAPTEC_7887
, AHC_AIC7880
,
9527 AHC_PAGESCBS
| AHC_BIOS_ENABLED
, AHC_AIC7880_FE
| AHC_NEW_AUTOTERM
, 19,
9529 {PCI_VENDOR_ID_ADAPTEC
, PCI_DEVICE_ID_ADAPTEC_7888
, AHC_AIC7880
,
9530 AHC_PAGESCBS
| AHC_BIOS_ENABLED
, AHC_AIC7880_FE
, 18,
9532 {PCI_VENDOR_ID_ADAPTEC
, PCI_DEVICE_ID_ADAPTEC_7895
, AHC_AIC7895
,
9533 AHC_PAGESCBS
| AHC_NEWEEPROM_FMT
| AHC_BIOS_ENABLED
| AHC_MULTI_CHANNEL
,
9536 {PCI_VENDOR_ID_ADAPTEC2
, PCI_DEVICE_ID_ADAPTEC2_7890
, AHC_AIC7890
,
9537 AHC_PAGESCBS
| AHC_NEWEEPROM_FMT
| AHC_BIOS_ENABLED
,
9540 {PCI_VENDOR_ID_ADAPTEC2
, PCI_DEVICE_ID_ADAPTEC2_7890B
, AHC_AIC7890
,
9541 AHC_PAGESCBS
| AHC_NEWEEPROM_FMT
| AHC_BIOS_ENABLED
,
9544 {PCI_VENDOR_ID_ADAPTEC2
, PCI_DEVICE_ID_ADAPTEC2_2930U2
, AHC_AIC7890
,
9545 AHC_PAGESCBS
| AHC_NEWEEPROM_FMT
| AHC_BIOS_ENABLED
,
9548 {PCI_VENDOR_ID_ADAPTEC2
, PCI_DEVICE_ID_ADAPTEC2_2940U2
, AHC_AIC7890
,
9549 AHC_PAGESCBS
| AHC_NEWEEPROM_FMT
| AHC_BIOS_ENABLED
,
9552 {PCI_VENDOR_ID_ADAPTEC2
, PCI_DEVICE_ID_ADAPTEC2_7896
, AHC_AIC7896
,
9553 AHC_PAGESCBS
| AHC_NEWEEPROM_FMT
| AHC_BIOS_ENABLED
| AHC_MULTI_CHANNEL
,
9556 {PCI_VENDOR_ID_ADAPTEC2
, PCI_DEVICE_ID_ADAPTEC2_3940U2
, AHC_AIC7896
,
9557 AHC_PAGESCBS
| AHC_NEWEEPROM_FMT
| AHC_BIOS_ENABLED
| AHC_MULTI_CHANNEL
,
9560 {PCI_VENDOR_ID_ADAPTEC2
, PCI_DEVICE_ID_ADAPTEC2_3950U2D
, AHC_AIC7896
,
9561 AHC_PAGESCBS
| AHC_NEWEEPROM_FMT
| AHC_BIOS_ENABLED
| AHC_MULTI_CHANNEL
,
9564 {PCI_VENDOR_ID_ADAPTEC
, PCI_DEVICE_ID_ADAPTEC_1480A
, AHC_AIC7860
,
9565 AHC_PAGESCBS
| AHC_NEWEEPROM_FMT
| AHC_BIOS_ENABLED
| AHC_NO_STPWEN
,
9568 {PCI_VENDOR_ID_ADAPTEC2
, PCI_DEVICE_ID_ADAPTEC2_7892A
, AHC_AIC7892
,
9569 AHC_PAGESCBS
| AHC_NEWEEPROM_FMT
| AHC_BIOS_ENABLED
,
9572 {PCI_VENDOR_ID_ADAPTEC2
, PCI_DEVICE_ID_ADAPTEC2_7892B
, AHC_AIC7892
,
9573 AHC_PAGESCBS
| AHC_NEWEEPROM_FMT
| AHC_BIOS_ENABLED
,
9576 {PCI_VENDOR_ID_ADAPTEC2
, PCI_DEVICE_ID_ADAPTEC2_7892D
, AHC_AIC7892
,
9577 AHC_PAGESCBS
| AHC_NEWEEPROM_FMT
| AHC_BIOS_ENABLED
,
9580 {PCI_VENDOR_ID_ADAPTEC2
, PCI_DEVICE_ID_ADAPTEC2_7892P
, AHC_AIC7892
,
9581 AHC_PAGESCBS
| AHC_NEWEEPROM_FMT
| AHC_BIOS_ENABLED
,
9584 {PCI_VENDOR_ID_ADAPTEC2
, PCI_DEVICE_ID_ADAPTEC2_7899A
, AHC_AIC7899
,
9585 AHC_PAGESCBS
| AHC_NEWEEPROM_FMT
| AHC_BIOS_ENABLED
| AHC_MULTI_CHANNEL
,
9588 {PCI_VENDOR_ID_ADAPTEC2
, PCI_DEVICE_ID_ADAPTEC2_7899B
, AHC_AIC7899
,
9589 AHC_PAGESCBS
| AHC_NEWEEPROM_FMT
| AHC_BIOS_ENABLED
| AHC_MULTI_CHANNEL
,
9592 {PCI_VENDOR_ID_ADAPTEC2
, PCI_DEVICE_ID_ADAPTEC2_7899D
, AHC_AIC7899
,
9593 AHC_PAGESCBS
| AHC_NEWEEPROM_FMT
| AHC_BIOS_ENABLED
| AHC_MULTI_CHANNEL
,
9596 {PCI_VENDOR_ID_ADAPTEC2
, PCI_DEVICE_ID_ADAPTEC2_7899P
, AHC_AIC7899
,
9597 AHC_PAGESCBS
| AHC_NEWEEPROM_FMT
| AHC_BIOS_ENABLED
| AHC_MULTI_CHANNEL
,
9602 unsigned short command
;
9603 unsigned int devconfig
, i
, oldverbose
;
9604 struct pci_dev
*pdev
= NULL
;
9606 for (i
= 0; i
< NUMBER(aic_pdevs
); i
++)
9609 while ((pdev
= pci_find_device(aic_pdevs
[i
].vendor_id
,
9610 aic_pdevs
[i
].device_id
,
9612 if (pci_enable_device(pdev
))
9614 if ( i
== 0 ) /* We found one, but it's the 7810 RAID cont. */
9616 if (aic7xxx_verbose
& (VERBOSE_PROBE
|VERBOSE_PROBE2
))
9618 printk(KERN_INFO
"aic7xxx: The 7810 RAID controller is not "
9620 printk(KERN_INFO
" this driver, we are ignoring it.\n");
9623 else if ( (temp_p
= kmalloc(sizeof(struct aic7xxx_host
),
9624 GFP_ATOMIC
)) != NULL
)
9626 memset(temp_p
, 0, sizeof(struct aic7xxx_host
));
9627 temp_p
->chip
= aic_pdevs
[i
].chip
| AHC_PCI
;
9628 temp_p
->flags
= aic_pdevs
[i
].flags
;
9629 temp_p
->features
= aic_pdevs
[i
].features
;
9630 temp_p
->board_name_index
= aic_pdevs
[i
].board_name_index
;
9631 temp_p
->sc_size
= aic_pdevs
[i
].seeprom_size
;
9632 temp_p
->sc_type
= aic_pdevs
[i
].seeprom_type
;
9635 * Read sundry information from PCI BIOS.
9637 temp_p
->irq
= pdev
->irq
;
9638 temp_p
->pdev
= pdev
;
9639 temp_p
->pci_bus
= pdev
->bus
->number
;
9640 temp_p
->pci_device_fn
= pdev
->devfn
;
9641 temp_p
->base
= pci_resource_start(pdev
, 0);
9642 temp_p
->mbase
= pci_resource_start(pdev
, 1);
9644 while(current_p
&& temp_p
)
9646 if ( ((current_p
->pci_bus
== temp_p
->pci_bus
) &&
9647 (current_p
->pci_device_fn
== temp_p
->pci_device_fn
)) ||
9648 (temp_p
->base
&& (current_p
->base
== temp_p
->base
)) ||
9649 (temp_p
->mbase
&& (current_p
->mbase
== temp_p
->mbase
)) )
9651 /* duplicate PCI entry, skip it */
9655 current_p
= current_p
->next
;
9657 if ( temp_p
== NULL
)
9659 if (aic7xxx_verbose
& VERBOSE_PROBE2
)
9660 printk("aic7xxx: <%s> at PCI %d/%d\n",
9661 board_names
[aic_pdevs
[i
].board_name_index
],
9662 PCI_SLOT(pdev
->devfn
),
9663 PCI_FUNC(pdev
->devfn
));
9664 pci_read_config_word(pdev
, PCI_COMMAND
, &command
);
9665 if (aic7xxx_verbose
& VERBOSE_PROBE2
)
9667 printk("aic7xxx: Initial PCI_COMMAND value was 0x%x\n",
9670 #ifdef AIC7XXX_STRICT_PCI_SETUP
9671 command
|= PCI_COMMAND_SERR
| PCI_COMMAND_PARITY
|
9672 PCI_COMMAND_MASTER
| PCI_COMMAND_MEMORY
| PCI_COMMAND_IO
;
9674 command
|= PCI_COMMAND_MASTER
| PCI_COMMAND_MEMORY
| PCI_COMMAND_IO
;
9676 command
&= ~PCI_COMMAND_INVALIDATE
;
9677 if (aic7xxx_pci_parity
== 0)
9678 command
&= ~(PCI_COMMAND_SERR
| PCI_COMMAND_PARITY
);
9679 pci_write_config_word(pdev
, PCI_COMMAND
, command
);
9680 #ifdef AIC7XXX_STRICT_PCI_SETUP
9681 pci_read_config_dword(pdev
, DEVCONFIG
, &devconfig
);
9682 if (aic7xxx_verbose
& VERBOSE_PROBE2
)
9684 printk("aic7xxx: Initial DEVCONFIG value was 0x%x\n", devconfig
);
9686 devconfig
|= 0x80000040;
9687 pci_write_config_dword(pdev
, DEVCONFIG
, devconfig
);
9688 #endif /* AIC7XXX_STRICT_PCI_SETUP */
9690 if(temp_p
->base
&& check_region(temp_p
->base
, MAXREG
- MINREG
))
9692 printk("aic7xxx: <%s> at PCI %d/%d/%d\n",
9693 board_names
[aic_pdevs
[i
].board_name_index
],
9695 PCI_SLOT(temp_p
->pci_device_fn
),
9696 PCI_FUNC(temp_p
->pci_device_fn
));
9697 printk("aic7xxx: I/O ports already in use, ignoring.\n");
9703 temp_p
->unpause
= INTEN
;
9704 temp_p
->pause
= temp_p
->unpause
| PAUSE
;
9705 if ( ((temp_p
->base
== 0) &&
9706 (temp_p
->mbase
== 0)) ||
9707 (temp_p
->irq
== 0) )
9709 printk("aic7xxx: <%s> at PCI %d/%d/%d\n",
9710 board_names
[aic_pdevs
[i
].board_name_index
],
9712 PCI_SLOT(temp_p
->pci_device_fn
),
9713 PCI_FUNC(temp_p
->pci_device_fn
));
9714 printk("aic7xxx: Controller disabled by BIOS, ignoring.\n");
9721 if ( !(temp_p
->base
) || !(temp_p
->flags
& AHC_MULTI_CHANNEL
) ||
9722 ((temp_p
->chip
!= (AHC_AIC7870
| AHC_PCI
)) &&
9723 (temp_p
->chip
!= (AHC_AIC7880
| AHC_PCI
))) )
9725 unsigned long page_offset
, base
;
9727 base
= temp_p
->mbase
& PAGE_MASK
;
9728 page_offset
= temp_p
->mbase
- base
;
9729 temp_p
->maddr
= ioremap_nocache(base
, page_offset
+ 256);
9732 temp_p
->maddr
+= page_offset
;
9734 * We need to check the I/O with the MMAPed address. Some machines
9735 * simply fail to work with MMAPed I/O and certain controllers.
9737 if(aic_inb(temp_p
, HCNTRL
) == 0xff)
9740 * OK.....we failed our test....go back to programmed I/O
9742 printk(KERN_INFO
"aic7xxx: <%s> at PCI %d/%d/%d\n",
9743 board_names
[aic_pdevs
[i
].board_name_index
],
9745 PCI_SLOT(temp_p
->pci_device_fn
),
9746 PCI_FUNC(temp_p
->pci_device_fn
));
9747 printk(KERN_INFO
"aic7xxx: MMAPed I/O failed, reverting to "
9748 "Programmed I/O.\n");
9749 iounmap((void *) (((unsigned long) temp_p
->maddr
) & PAGE_MASK
));
9751 if(temp_p
->base
== 0)
9753 printk("aic7xxx: <%s> at PCI %d/%d/%d\n",
9754 board_names
[aic_pdevs
[i
].board_name_index
],
9756 PCI_SLOT(temp_p
->pci_device_fn
),
9757 PCI_FUNC(temp_p
->pci_device_fn
));
9758 printk("aic7xxx: Controller disabled by BIOS, ignoring.\n");
9769 * Lock out other contenders for our i/o space.
9772 request_region(temp_p
->base
, MAXREG
- MINREG
, "aic7xxx");
9775 * We HAVE to make sure the first pause_sequencer() and all other
9776 * subsequent I/O that isn't PCI config space I/O takes place
9777 * after the MMAPed I/O region is configured and tested. The
9778 * problem is the PowerPC architecture that doesn't support
9779 * programmed I/O at all, so we have to have the MMAP I/O set up
9780 * for this pause to even work on those machines.
9782 pause_sequencer(temp_p
);
9785 * Clear out any pending PCI error status messages. Also set
9786 * verbose to 0 so that we don't emit strange PCI error messages
9787 * while cleaning out the current status bits.
9789 oldverbose
= aic7xxx_verbose
;
9790 aic7xxx_verbose
= 0;
9791 aic7xxx_pci_intr(temp_p
);
9792 aic7xxx_verbose
= oldverbose
;
9794 temp_p
->bios_address
= 0;
9797 * Remember how the card was setup in case there is no seeprom.
9799 if (temp_p
->features
& AHC_ULTRA2
)
9800 temp_p
->scsi_id
= aic_inb(temp_p
, SCSIID_ULTRA2
) & OID
;
9802 temp_p
->scsi_id
= aic_inb(temp_p
, SCSIID
) & OID
;
9804 * Get current termination setting
9806 sxfrctl1
= aic_inb(temp_p
, SXFRCTL1
);
9808 if (aic7xxx_chip_reset(temp_p
) == -1)
9810 release_region(temp_p
->base
, MAXREG
- MINREG
);
9816 * Very quickly put the term setting back into the register since
9817 * the chip reset may cause odd things to happen. This is to keep
9818 * LVD busses with lots of drives from draining the power out of
9819 * the diffsense line before we get around to running the
9820 * configure_termination() function. Also restore the STPWLEVEL
9823 aic_outb(temp_p
, sxfrctl1
, SXFRCTL1
);
9824 pci_write_config_dword(temp_p
->pdev
, DEVCONFIG
, devconfig
);
9828 * We need to set the CHNL? assignments before loading the SEEPROM
9829 * The 3940 and 3985 cards (original stuff, not any of the later
9830 * stuff) are 7870 and 7880 class chips. The Ultra2 stuff falls
9831 * under 7896 and 7897. The 7895 is in a class by itself :)
9833 switch (temp_p
->chip
& AHC_CHIPID_MASK
)
9835 case AHC_AIC7870
: /* 3840 / 3985 */
9836 case AHC_AIC7880
: /* 3840 UW / 3985 UW */
9837 if(temp_p
->flags
& AHC_MULTI_CHANNEL
)
9839 switch(PCI_SLOT(temp_p
->pci_device_fn
))
9842 temp_p
->flags
|= AHC_CHNLB
;
9845 temp_p
->flags
|= AHC_CHNLB
;
9848 temp_p
->flags
|= AHC_CHNLC
;
9856 case AHC_AIC7895
: /* 7895 */
9857 case AHC_AIC7896
: /* 7896/7 */
9858 case AHC_AIC7899
: /* 7899 */
9859 if (PCI_FUNC(pdev
->devfn
) != 0)
9861 temp_p
->flags
|= AHC_CHNLB
;
9864 * The 7895 is the only chipset that sets the SCBSIZE32 param
9865 * in the DEVCONFIG register. The Ultra2 chipsets use
9866 * the DSCOMMAND0 register instead.
9868 if ((temp_p
->chip
& AHC_CHIPID_MASK
) == AHC_AIC7895
)
9870 pci_read_config_dword(pdev
, DEVCONFIG
, &devconfig
);
9871 devconfig
|= SCBSIZE32
;
9872 pci_write_config_dword(pdev
, DEVCONFIG
, devconfig
);
9880 * Loading of the SEEPROM needs to come after we've set the flags
9881 * to indicate possible CHNLB and CHNLC assigments. Otherwise,
9882 * on 394x and 398x cards we'll end up reading the wrong settings
9883 * for channels B and C
9885 switch (temp_p
->chip
& AHC_CHIPID_MASK
)
9889 aic_outb(temp_p
, 0, SCAMCTL
);
9891 * Switch to the alt mode of the chip...
9893 aic_outb(temp_p
, aic_inb(temp_p
, SFUNCT
) | ALT_MODE
, SFUNCT
);
9895 * Set our options...the last two items set our CRC after x byte
9896 * count in target mode...
9898 aic_outb(temp_p
, AUTO_MSGOUT_DE
| DIS_MSGIN_DUALEDGE
, OPTIONMODE
);
9899 aic_outb(temp_p
, 0x00, 0x0b);
9900 aic_outb(temp_p
, 0x10, 0x0a);
9902 * switch back to normal mode...
9904 aic_outb(temp_p
, aic_inb(temp_p
, SFUNCT
) & ~ALT_MODE
, SFUNCT
);
9905 aic_outb(temp_p
, CRCVALCHKEN
| CRCENDCHKEN
| CRCREQCHKEN
|
9906 TARGCRCENDEN
| TARGCRCCNTEN
,
9908 aic_outb(temp_p
, ((aic_inb(temp_p
, DSCOMMAND0
) | USCBSIZE32
|
9909 MPARCKEN
| CIOPARCKEN
| CACHETHEN
) &
9910 ~DPARCKEN
), DSCOMMAND0
);
9911 aic7xxx_load_seeprom(temp_p
, &sxfrctl1
);
9915 aic_outb(temp_p
, 0, SCAMCTL
);
9916 aic_outb(temp_p
, (aic_inb(temp_p
, DSCOMMAND0
) |
9917 CACHETHEN
| MPARCKEN
| USCBSIZE32
|
9918 CIOPARCKEN
) & ~DPARCKEN
, DSCOMMAND0
);
9919 aic7xxx_load_seeprom(temp_p
, &sxfrctl1
);
9924 * Set the DSCOMMAND0 register on these cards different from
9925 * on the 789x cards. Also, read the SEEPROM as well.
9927 aic_outb(temp_p
, (aic_inb(temp_p
, DSCOMMAND0
) |
9928 CACHETHEN
| MPARCKEN
) & ~DPARCKEN
,
9932 aic7xxx_load_seeprom(temp_p
, &sxfrctl1
);
9936 * Check the rev of the chipset before we change DSCOMMAND0
9938 pci_read_config_dword(pdev
, DEVCONFIG
, &devconfig
);
9939 if ((devconfig
& 0xff) >= 1)
9941 aic_outb(temp_p
, (aic_inb(temp_p
, DSCOMMAND0
) |
9942 CACHETHEN
| MPARCKEN
) & ~DPARCKEN
,
9945 aic7xxx_load_seeprom(temp_p
, &sxfrctl1
);
9951 * and then we need another switch based on the type in order to
9952 * make sure the channel B primary flag is set properly on 7895
9953 * controllers....Arrrgggghhh!!! We also have to catch the fact
9954 * that when you disable the BIOS on the 7895 on the Intel DK440LX
9955 * motherboard, and possibly others, it only sets the BIOS disabled
9956 * bit on the A channel...I think I'm starting to lean towards
9959 switch(temp_p
->chip
& AHC_CHIPID_MASK
)
9965 while(current_p
!= NULL
)
9967 if ( (current_p
->pci_bus
== temp_p
->pci_bus
) &&
9968 (PCI_SLOT(current_p
->pci_device_fn
) ==
9969 PCI_SLOT(temp_p
->pci_device_fn
)) )
9971 if ( PCI_FUNC(current_p
->pci_device_fn
) == 0 )
9974 (current_p
->flags
& AHC_CHANNEL_B_PRIMARY
);
9975 temp_p
->flags
&= ~(AHC_BIOS_ENABLED
|AHC_USEDEFAULTS
);
9977 (current_p
->flags
& (AHC_BIOS_ENABLED
|AHC_USEDEFAULTS
));
9982 (temp_p
->flags
& AHC_CHANNEL_B_PRIMARY
);
9983 current_p
->flags
&= ~(AHC_BIOS_ENABLED
|AHC_USEDEFAULTS
);
9985 (temp_p
->flags
& (AHC_BIOS_ENABLED
|AHC_USEDEFAULTS
));
9988 current_p
= current_p
->next
;
9996 * We only support external SCB RAM on the 7895/6/7 chipsets.
9997 * We could support it on the 7890/1 easy enough, but I don't
9998 * know of any 7890/1 based cards that have it. I do know
9999 * of 7895/6/7 cards that have it and they work properly.
10001 switch(temp_p
->chip
& AHC_CHIPID_MASK
)
10008 pci_read_config_dword(pdev
, DEVCONFIG
, &devconfig
);
10009 if (temp_p
->features
& AHC_ULTRA2
)
10011 if ( (aic_inb(temp_p
, DSCOMMAND0
) & RAMPSM_ULTRA2
) &&
10015 aic_inb(temp_p
, DSCOMMAND0
) & ~SCBRAMSEL_ULTRA2
,
10017 temp_p
->flags
|= AHC_EXTERNAL_SRAM
;
10018 devconfig
|= EXTSCBPEN
;
10020 else if (aic_inb(temp_p
, DSCOMMAND0
) & RAMPSM_ULTRA2
)
10022 printk(KERN_INFO
"aic7xxx: <%s> at PCI %d/%d/%d\n",
10023 board_names
[aic_pdevs
[i
].board_name_index
],
10025 PCI_SLOT(temp_p
->pci_device_fn
),
10026 PCI_FUNC(temp_p
->pci_device_fn
));
10027 printk("aic7xxx: external SCB RAM detected, "
10028 "but not enabled\n");
10033 if ((devconfig
& RAMPSM
) && (aic7xxx_scbram
))
10035 devconfig
&= ~SCBRAMSEL
;
10036 devconfig
|= EXTSCBPEN
;
10037 temp_p
->flags
|= AHC_EXTERNAL_SRAM
;
10039 else if (devconfig
& RAMPSM
)
10041 printk(KERN_INFO
"aic7xxx: <%s> at PCI %d/%d/%d\n",
10042 board_names
[aic_pdevs
[i
].board_name_index
],
10044 PCI_SLOT(temp_p
->pci_device_fn
),
10045 PCI_FUNC(temp_p
->pci_device_fn
));
10046 printk("aic7xxx: external SCB RAM detected, "
10047 "but not enabled\n");
10050 pci_write_config_dword(pdev
, DEVCONFIG
, devconfig
);
10051 if ( (temp_p
->flags
& AHC_EXTERNAL_SRAM
) &&
10052 (temp_p
->flags
& AHC_CHNLB
) )
10053 aic_outb(temp_p
, 1, CCSCBBADDR
);
10058 * Take the LED out of diagnostic mode
10061 (aic_inb(temp_p
, SBLKCTL
) & ~(DIAGLEDEN
| DIAGLEDON
)),
10065 * We don't know where this is set in the SEEPROM or by the
10066 * BIOS, so we default to 100%. On Ultra2 controllers, use 75%
10069 if (temp_p
->features
& AHC_ULTRA2
)
10071 aic_outb(temp_p
, RD_DFTHRSH_MAX
| WR_DFTHRSH_MAX
, DFF_THRSH
);
10075 aic_outb(temp_p
, DFTHRSH_100
, DSPCISTATUS
);
10078 if ( list_p
== NULL
)
10080 list_p
= current_p
= temp_p
;
10084 current_p
= list_p
;
10085 while(current_p
->next
!= NULL
)
10086 current_p
= current_p
->next
;
10087 current_p
->next
= temp_p
;
10089 temp_p
->next
= NULL
;
10091 } /* Found an Adaptec PCI device. */
10092 else /* Well, we found one, but we couldn't get any memory */
10094 printk("aic7xxx: Found <%s>\n",
10095 board_names
[aic_pdevs
[i
].board_name_index
]);
10096 printk(KERN_INFO
"aic7xxx: Unable to allocate device memory, "
10099 } /* while(pdev=....) */
10100 } /* for PCI_DEVICES */
10101 } /* PCI BIOS present */
10104 #if defined(__i386__) || defined(__alpha__)
10106 * EISA/VL-bus card signature probe.
10109 while ( (slot
<= MAXSLOT
) &&
10110 !(aic7xxx_no_probe
) )
10112 base
= SLOTBASE(slot
) + MINREG
;
10114 if (check_region(base
, MAXREG
- MINREG
))
10117 * Some other driver has staked a
10118 * claim to this i/o region already.
10121 continue; /* back to the beginning of the for loop */
10124 type
= aic7xxx_probe(slot
, base
+ AHC_HID0
, &flags
);
10130 temp_p
= kmalloc(sizeof(struct aic7xxx_host
), GFP_ATOMIC
);
10131 if (temp_p
== NULL
)
10133 printk(KERN_WARNING
"aic7xxx: Unable to allocate device space.\n");
10135 continue; /* back to the beginning of the while loop */
10138 * Lock out other contenders for our i/o space.
10140 request_region(base
, MAXREG
- MINREG
, "aic7xxx");
10143 * Pause the card preserving the IRQ type. Allow the operator
10144 * to override the IRQ trigger.
10146 if (aic7xxx_irq_trigger
== 1)
10147 hcntrl
= IRQMS
; /* Level */
10148 else if (aic7xxx_irq_trigger
== 0)
10149 hcntrl
= 0; /* Edge */
10151 hcntrl
= inb(base
+ HCNTRL
) & IRQMS
; /* Default */
10152 memset(temp_p
, 0, sizeof(struct aic7xxx_host
));
10153 temp_p
->unpause
= hcntrl
| INTEN
;
10154 temp_p
->pause
= hcntrl
| PAUSE
| INTEN
;
10155 temp_p
->base
= base
;
10158 temp_p
->pci_bus
= 0;
10159 temp_p
->pci_device_fn
= slot
;
10160 aic_outb(temp_p
, hcntrl
| PAUSE
, HCNTRL
);
10161 while( (aic_inb(temp_p
, HCNTRL
) & PAUSE
) == 0 ) ;
10162 if (aic7xxx_chip_reset(temp_p
) == -1)
10165 temp_p
->irq
= aic_inb(temp_p
, INTDEF
) & 0x0F;
10166 temp_p
->flags
|= AHC_PAGESCBS
;
10168 switch (temp_p
->irq
)
10179 printk(KERN_WARNING
"aic7xxx: Host adapter uses unsupported IRQ "
10180 "level %d, ignoring.\n", temp_p
->irq
);
10182 release_region(base
, MAXREG
- MINREG
);
10184 continue; /* back to the beginning of the while loop */
10188 * We are commited now, everything has been checked and this card
10189 * has been found, now we just set it up
10193 * Insert our new struct into the list at the end
10195 if (list_p
== NULL
)
10197 list_p
= current_p
= temp_p
;
10201 current_p
= list_p
;
10202 while (current_p
->next
!= NULL
)
10203 current_p
= current_p
->next
;
10204 current_p
->next
= temp_p
;
10210 temp_p
->board_name_index
= 2;
10211 if (aic7xxx_verbose
& VERBOSE_PROBE2
)
10212 printk("aic7xxx: <%s> at EISA %d\n",
10213 board_names
[2], slot
);
10217 temp_p
->chip
= AHC_AIC7770
| AHC_EISA
;
10218 temp_p
->features
|= AHC_AIC7770_FE
;
10219 temp_p
->bios_control
= aic_inb(temp_p
, HA_274_BIOSCTRL
);
10222 * Get the primary channel information. Right now we don't
10223 * do anything with this, but someday we will be able to inform
10224 * the mid-level SCSI code which channel is primary.
10226 if (temp_p
->board_name_index
== 0)
10228 temp_p
->board_name_index
= 3;
10229 if (aic7xxx_verbose
& VERBOSE_PROBE2
)
10230 printk("aic7xxx: <%s> at EISA %d\n",
10231 board_names
[3], slot
);
10233 if (temp_p
->bios_control
& CHANNEL_B_PRIMARY
)
10235 temp_p
->flags
|= AHC_CHANNEL_B_PRIMARY
;
10238 if ((temp_p
->bios_control
& BIOSMODE
) == BIOSDISABLED
)
10240 temp_p
->flags
&= ~AHC_BIOS_ENABLED
;
10244 temp_p
->flags
&= ~AHC_USEDEFAULTS
;
10245 temp_p
->flags
|= AHC_BIOS_ENABLED
;
10246 if ( (temp_p
->bios_control
& 0x20) == 0 )
10248 temp_p
->bios_address
= 0xcc000;
10249 temp_p
->bios_address
+= (0x4000 * (temp_p
->bios_control
& 0x07));
10253 temp_p
->bios_address
= 0xd0000;
10254 temp_p
->bios_address
+= (0x8000 * (temp_p
->bios_control
& 0x06));
10257 temp_p
->adapter_control
= aic_inb(temp_p
, SCSICONF
) << 8;
10258 temp_p
->adapter_control
|= aic_inb(temp_p
, SCSICONF
+ 1);
10259 if (temp_p
->features
& AHC_WIDE
)
10261 temp_p
->scsi_id
= temp_p
->adapter_control
& HWSCSIID
;
10262 temp_p
->scsi_id_b
= temp_p
->scsi_id
;
10266 temp_p
->scsi_id
= (temp_p
->adapter_control
>> 8) & HSCSIID
;
10267 temp_p
->scsi_id_b
= temp_p
->adapter_control
& HSCSIID
;
10269 aic7xxx_load_seeprom(temp_p
, &sxfrctl1
);
10275 temp_p
->chip
= AHC_AIC7770
| AHC_VL
;
10276 temp_p
->features
|= AHC_AIC7770_FE
;
10278 temp_p
->flags
|= AHC_BIOS_ENABLED
;
10280 temp_p
->flags
&= ~AHC_BIOS_ENABLED
;
10281 if (aic_inb(temp_p
, SCSICONF
) & TERM_ENB
)
10283 aic7xxx_load_seeprom(temp_p
, &sxfrctl1
);
10284 temp_p
->board_name_index
= 4;
10285 if (aic7xxx_verbose
& VERBOSE_PROBE2
)
10286 printk("aic7xxx: <%s> at VLB %d\n",
10287 board_names
[2], slot
);
10288 switch( aic_inb(temp_p
, STATUS_2840
) & BIOS_SEL
)
10291 temp_p
->bios_address
= 0xe0000;
10294 temp_p
->bios_address
= 0xc8000;
10297 temp_p
->bios_address
= 0xd0000;
10300 temp_p
->bios_address
= 0xd8000;
10303 break; /* can't get here */
10307 default: /* Won't get here. */
10310 if (aic7xxx_verbose
& VERBOSE_PROBE2
)
10312 printk(KERN_INFO
"aic7xxx: BIOS %sabled, IO Port 0x%lx, IRQ %d (%s)\n",
10313 (temp_p
->flags
& AHC_USEDEFAULTS
) ? "dis" : "en", temp_p
->base
,
10315 (temp_p
->pause
& IRQMS
) ? "level sensitive" : "edge triggered");
10316 printk(KERN_INFO
"aic7xxx: Extended translation %sabled.\n",
10317 (temp_p
->flags
& AHC_EXTEND_TRANS_A
) ? "en" : "dis");
10321 * Set the FIFO threshold and the bus off time.
10323 hostconf
= aic_inb(temp_p
, HOSTCONF
);
10324 aic_outb(temp_p
, hostconf
& DFTHRSH
, BUSSPD
);
10325 aic_outb(temp_p
, (hostconf
<< 2) & BOFF
, BUSTIME
);
10330 #endif /* defined(__i386__) || defined(__alpha__) */
10333 * Now, we re-order the probed devices by BIOS address and BUS class.
10334 * In general, we follow this algorithm to make the adapters show up
10335 * in the same order under linux that the computer finds them.
10336 * 1: All VLB/EISA cards with BIOS_ENABLED first, according to BIOS
10337 * address, going from lowest to highest.
10338 * 2: All PCI controllers with BIOS_ENABLED next, according to BIOS
10339 * address, going from lowest to highest.
10340 * 3: Remaining VLB/EISA controllers going in slot order.
10341 * 4: Remaining PCI controllers, going in PCI device order (reversable)
10345 struct aic7xxx_host
*sort_list
[4] = { NULL
, NULL
, NULL
, NULL
};
10346 struct aic7xxx_host
*vlb
, *pci
;
10347 struct aic7xxx_host
*prev_p
;
10348 struct aic7xxx_host
*p
;
10349 unsigned char left
;
10351 prev_p
= vlb
= pci
= NULL
;
10354 while (temp_p
!= NULL
)
10356 switch(temp_p
->chip
& ~AHC_CHIPID_MASK
)
10362 if (p
->flags
& AHC_BIOS_ENABLED
)
10363 vlb
= sort_list
[0];
10365 vlb
= sort_list
[2];
10370 temp_p
= temp_p
->next
;
10377 while ( (current_p
!= NULL
) &&
10378 (current_p
->bios_address
< temp_p
->bios_address
))
10380 prev_p
= current_p
;
10381 current_p
= current_p
->next
;
10383 if (prev_p
!= NULL
)
10385 prev_p
->next
= temp_p
;
10386 temp_p
= temp_p
->next
;
10387 prev_p
->next
->next
= current_p
;
10392 temp_p
= temp_p
->next
;
10393 vlb
->next
= current_p
;
10397 if (p
->flags
& AHC_BIOS_ENABLED
)
10398 sort_list
[0] = vlb
;
10400 sort_list
[2] = vlb
;
10404 default: /* All PCI controllers fall through to default */
10408 if (p
->flags
& AHC_BIOS_ENABLED
)
10409 pci
= sort_list
[1];
10411 pci
= sort_list
[3];
10416 temp_p
= temp_p
->next
;
10423 if (!aic7xxx_reverse_scan
)
10425 while ( (current_p
!= NULL
) &&
10426 ( (PCI_SLOT(current_p
->pci_device_fn
) |
10427 (current_p
->pci_bus
<< 8)) <
10428 (PCI_SLOT(temp_p
->pci_device_fn
) |
10429 (temp_p
->pci_bus
<< 8)) ) )
10431 prev_p
= current_p
;
10432 current_p
= current_p
->next
;
10437 while ( (current_p
!= NULL
) &&
10438 ( (PCI_SLOT(current_p
->pci_device_fn
) |
10439 (current_p
->pci_bus
<< 8)) >
10440 (PCI_SLOT(temp_p
->pci_device_fn
) |
10441 (temp_p
->pci_bus
<< 8)) ) )
10443 prev_p
= current_p
;
10444 current_p
= current_p
->next
;
10448 * Are we dealing with a 7895/6/7/9 where we need to sort the
10449 * channels as well, if so, the bios_address values should
10452 if ( (current_p
) && (temp_p
->flags
& AHC_MULTI_CHANNEL
) &&
10453 (temp_p
->pci_bus
== current_p
->pci_bus
) &&
10454 (PCI_SLOT(temp_p
->pci_device_fn
) ==
10455 PCI_SLOT(current_p
->pci_device_fn
)) )
10457 if (temp_p
->flags
& AHC_CHNLB
)
10459 if ( !(temp_p
->flags
& AHC_CHANNEL_B_PRIMARY
) )
10461 prev_p
= current_p
;
10462 current_p
= current_p
->next
;
10467 if (temp_p
->flags
& AHC_CHANNEL_B_PRIMARY
)
10469 prev_p
= current_p
;
10470 current_p
= current_p
->next
;
10474 if (prev_p
!= NULL
)
10476 prev_p
->next
= temp_p
;
10477 temp_p
= temp_p
->next
;
10478 prev_p
->next
->next
= current_p
;
10483 temp_p
= temp_p
->next
;
10484 pci
->next
= current_p
;
10488 if (p
->flags
& AHC_BIOS_ENABLED
)
10489 sort_list
[1] = pci
;
10491 sort_list
[3] = pci
;
10495 } /* End of switch(temp_p->type) */
10496 } /* End of while (temp_p != NULL) */
10498 * At this point, the cards have been broken into 4 sorted lists, now
10499 * we run through the lists in order and register each controller
10505 for (i
=0; i
<NUMBER(sort_list
); i
++)
10507 temp_p
= sort_list
[i
];
10508 while(temp_p
!= NULL
)
10510 template->name
= board_names
[temp_p
->board_name_index
];
10511 p
= aic7xxx_alloc(template, temp_p
);
10514 p
->instance
= found
- left
;
10515 if (aic7xxx_register(template, p
, (--left
)) == 0)
10518 aic7xxx_release(p
->host
);
10519 scsi_unregister(p
->host
);
10521 else if (aic7xxx_dump_card
)
10523 pause_sequencer(p
);
10524 aic7xxx_print_card(p
);
10525 aic7xxx_print_scratch_ram(p
);
10526 unpause_sequencer(p
, TRUE
);
10529 current_p
= temp_p
;
10530 temp_p
= (struct aic7xxx_host
*)temp_p
->next
;
10539 static void aic7xxx_build_negotiation_cmnd(struct aic7xxx_host
*p
,
10540 Scsi_Cmnd
*old_cmd
, int tindex
);
10542 /*+F*************************************************************************
10544 * aic7xxx_allocate_negotiation_command
10547 * allocate the actual command struct and fill in the gaps...
10548 *-F*************************************************************************/
10550 aic7xxx_allocate_negotiation_command(struct aic7xxx_host
*p
,
10551 Scsi_Cmnd
*old_cmd
, int tindex
)
10556 if (!(p
->dev_dtr_cmnd
[tindex
] = kmalloc(sizeof(Scsi_Cmnd
), GFP_ATOMIC
)) )
10560 if (!(buffer
= kmalloc(256, GFP_ATOMIC
)))
10562 kfree(p
->dev_dtr_cmnd
[tindex
]);
10563 p
->dev_dtr_cmnd
[tindex
] = NULL
;
10566 cmd
= p
->dev_dtr_cmnd
[tindex
];
10567 memset(cmd
, 0, sizeof(Scsi_Cmnd
));
10568 memcpy(cmd
, old_cmd
, sizeof(Scsi_Cmnd
));
10569 memset(&cmd
->cmnd
[0], 0, sizeof(cmd
->cmnd
));
10570 memset(&cmd
->data_cmnd
[0], 0, sizeof(cmd
->data_cmnd
));
10572 cmd
->request_bufflen
= 255;
10573 cmd
->request_buffer
= buffer
;
10574 cmd
->sc_data_direction
= SCSI_DATA_READ
;
10575 cmd
->use_sg
= cmd
->old_use_sg
= cmd
->sglist_len
= 0;
10577 cmd
->buffer
= NULL
;
10578 cmd
->underflow
= 0;
10580 cmd
->cmnd
[0] = cmd
->data_cmnd
[0] = INQUIRY
;
10581 cmd
->cmnd
[1] = cmd
->data_cmnd
[1] = 0;
10582 cmd
->cmnd
[2] = cmd
->data_cmnd
[2] = 0;
10583 cmd
->cmnd
[3] = cmd
->data_cmnd
[3] = 0;
10584 cmd
->cmnd
[4] = cmd
->data_cmnd
[4] = 255; /* match what scsi.c does here */
10585 cmd
->cmnd
[5] = cmd
->data_cmnd
[5] = 0;
10589 /*+F*************************************************************************
10591 * aic7xxx_negotiation_complete
10594 * Handle completion events for our Negotiation commands. Clear out the
10595 * struct and get it ready for its next use.
10596 *-F*************************************************************************/
10598 aic7xxx_negotiation_complete(Scsi_Cmnd
*cmd
)
10600 unsigned int checksum
;
10603 struct aic7xxx_host
*p
= (struct aic7xxx_host
*)cmd
->host
->hostdata
;
10604 int tindex
= TARGET_INDEX(cmd
);
10605 struct aic7xxx_syncrate
*syncrate
;
10608 * perform our minimalistic domain validation
10610 if(p
->dev_flags
[tindex
] & DEVICE_SCANNED
)
10612 ibuffer
= (int *)cmd
->request_buffer
;
10614 for(i
= 0; i
< (cmd
->request_bufflen
>> 2); i
++)
10616 checksum
+= ibuffer
[i
];
10618 if( (checksum
!= p
->dev_checksum
[tindex
]) &&
10619 (p
->transinfo
[tindex
].cur_offset
!= 0) )
10621 unsigned int period
= p
->transinfo
[tindex
].cur_period
;
10622 unsigned char options
= p
->transinfo
[tindex
].cur_options
;
10624 if (p
->needdv
& (1<<tindex
))
10627 * oops, we had a failure, lower the transfer rate and try again. It's
10628 * worth noting here that it might be wise to also check for typical
10629 * wide setting on narrow cable type problems and try disabling wide
10630 * instead of slowing down if those exist. That's hard to do with simple
10631 * checksums though.
10633 if(aic7xxx_verbose
& VERBOSE_NEGOTIATION2
)
10635 printk(INFO_LEAD
"reducing SCSI transfer speed due to Domain "
10636 "validation failure.\n", p
->host_no
, CTL_OF_CMD(cmd
));
10638 if((syncrate
= aic7xxx_find_syncrate(p
, &period
, 0, &options
)) != NULL
)
10641 if( (syncrate
->rate
[0] != NULL
) &&
10642 (!(p
->features
& AHC_ULTRA2
) || (syncrate
->sxfr_ultra2
== 0)) )
10644 p
->transinfo
[tindex
].goal_period
= syncrate
->period
;
10645 if( p
->transinfo
[tindex
].goal_period
> 9 )
10647 p
->transinfo
[tindex
].goal_options
= 0;
10648 p
->needppr
&= ~(1<<tindex
);
10649 p
->needsdtr
|= (1<<tindex
);
10650 p
->needppr_copy
&= ~(1<<tindex
);
10651 p
->needsdtr_copy
|= (1<<tindex
);
10652 if (p
->transinfo
[tindex
].goal_width
)
10654 p
->needwdtr
|= (1<<tindex
);
10655 p
->needwdtr_copy
|= (1<<tindex
);
10659 else if (p
->transinfo
[tindex
].goal_width
)
10661 p
->transinfo
[tindex
].goal_width
= 0;
10662 p
->needwdtr
&= ~(1<<tindex
);
10663 p
->needwdtr_copy
&= ~(1<<tindex
);
10664 p
->transinfo
[tindex
].goal_offset
=
10665 p
->transinfo
[tindex
].user_offset
;
10666 p
->transinfo
[tindex
].goal_period
=
10667 p
->transinfo
[tindex
].user_period
;
10668 p
->transinfo
[tindex
].goal_options
=
10669 p
->transinfo
[tindex
].user_options
;
10670 if( p
->transinfo
[tindex
].goal_period
<= 9 )
10672 p
->needppr
|= (1<<tindex
);
10673 p
->needsdtr
&= ~(1<<tindex
);
10674 p
->needppr_copy
|= (1<<tindex
);
10675 p
->needsdtr_copy
&= ~(1<<tindex
);
10679 p
->needppr
&= ~(1<<tindex
);
10680 p
->needsdtr
|= (1<<tindex
);
10681 p
->needppr_copy
&= ~(1<<tindex
);
10682 p
->needsdtr_copy
|= (1<<tindex
);
10687 p
->transinfo
[tindex
].goal_offset
= 0;
10688 p
->transinfo
[tindex
].goal_period
= 255;
10689 p
->transinfo
[tindex
].goal_options
= 0;
10690 p
->transinfo
[tindex
].goal_width
= 0;
10691 p
->needppr
&= ~(1<<tindex
);
10692 p
->needsdtr
&= ~(1<<tindex
);
10693 p
->needwdtr
&= ~(1<<tindex
);
10694 p
->needppr_copy
&= ~(1<<tindex
);
10695 p
->needsdtr_copy
&= ~(1<<tindex
);
10696 p
->needwdtr_copy
&= ~(1<<tindex
);
10699 p
->needdv
&= ~(1<<tindex
);
10703 if(aic7xxx_verbose
& VERBOSE_NEGOTIATION2
)
10705 printk(INFO_LEAD
"Performing Domain validation.\n",
10706 p
->host_no
, CTL_OF_CMD(cmd
));
10709 * Update the checksum in case the INQUIRY data has changed, maybe
10710 * in relation to a change in the mode pages, or whatever.
10712 p
->dev_checksum
[tindex
] = checksum
;
10714 * Signal that we are trying out the domain validation
10716 p
->needdv
|= (1<<tindex
);
10718 * Signal that we need to re-negotiate things, this also gets us our
10719 * INQUIRY command to re-checksum off of.
10721 p
->needppr
|= (p
->needppr_copy
& (1<<tindex
));
10722 p
->needsdtr
|= (p
->needsdtr_copy
& (1<<tindex
));
10723 p
->needwdtr
|= (p
->needwdtr_copy
& (1<<tindex
));
10728 if( (aic7xxx_verbose
& VERBOSE_NEGOTIATION2
) &&
10729 (p
->needdv
& (1<<tindex
)) )
10731 printk(INFO_LEAD
"Successfully completed Domain validation.\n",
10732 p
->host_no
, CTL_OF_CMD(cmd
));
10735 * We successfully did our checksum, so don't leave the needdv flag set
10736 * in case we might have set it last time through.
10738 p
->needdv
&= ~(1<<tindex
);
10742 p
->dtr_pending
&= ~(0x01 << tindex
);
10744 * This looks recursive in the extreme, but if this was a WDTR negotiation
10745 * and we didn't follow up with SDTR yet, then this will get it started.
10746 * For all other cases, this should work out to be a no-op, unless we are
10747 * doing domain validation and happen to need a new negotiation command.
10749 * In case we don't want this to go any further, the cmdcmplt interrupt
10750 * handler will NULL out the cmd->next entry so that the real SCSI command
10751 * can be sent back to the mid layer code with SENSE data intact. We'll
10752 * finish things up when the cmd gets sent back down to us, so no worries.
10756 aic7xxx_build_negotiation_cmnd(p
, cmd
->next
, tindex
);
10761 /*+F*************************************************************************
10763 * aic7xxx_build_negotiation_command
10766 * Build a Scsi_Cmnd structure to perform negotiation with or else send
10767 * a pre-built command specifically for this purpose.
10768 *-F*************************************************************************/
10770 aic7xxx_build_negotiation_cmnd(struct aic7xxx_host
*p
, Scsi_Cmnd
*old_cmd
,
10774 if ( !(p
->dtr_pending
& (1<<tindex
)) &&
10775 ( (p
->needppr
& (1<<tindex
)) ||
10776 (p
->needwdtr
& (1<<tindex
)) ||
10777 (p
->needsdtr
& (1<<tindex
)) ) )
10779 if ( (p
->dev_dtr_cmnd
[tindex
] == NULL
) &&
10780 (aic7xxx_allocate_negotiation_command(p
, old_cmd
, tindex
) == NULL
) )
10785 * Before sending this thing out, we also make the cmd->next pointer
10786 * point to the real command so we can stuff any possible SENSE data
10787 * into the real command instead of this fake command. This has to be
10788 * done each time the command is built, not just the first time, hence
10789 * it's outside of the above if()...
10791 p
->dev_dtr_cmnd
[tindex
]->next
= old_cmd
;
10793 * Clear the buffer so checksums come out right....
10795 memset(p
->dev_dtr_cmnd
[tindex
]->request_buffer
, 0,
10796 p
->dev_dtr_cmnd
[tindex
]->request_bufflen
);
10798 * Remove any commands for this particular device that might be on the
10799 * waiting_scbs queue or qinfifo so that this command goes out first.
10800 * This is vital for our implementation of domain validation.
10802 pause_sequencer(p
);
10803 aic7xxx_search_qinfifo(p
, old_cmd
->target
, old_cmd
->channel
, ALL_LUNS
,
10804 SCB_LIST_NULL
, 0, TRUE
, &p
->delayed_scbs
[tindex
]);
10805 unpause_sequencer(p
, FALSE
);
10807 struct aic7xxx_scb
*scb
, *next
;
10809 scb
= p
->waiting_scbs
.head
;
10812 if( aic7xxx_match_scb(p
, scb
, old_cmd
->target
, old_cmd
->channel
,
10813 ALL_LUNS
, SCB_LIST_NULL
) )
10815 next
= scb
->q_next
;
10816 scbq_remove(&p
->waiting_scbs
, scb
);
10817 scbq_insert_tail(&p
->delayed_scbs
[tindex
], scb
);
10826 aic7xxx_queue(p
->dev_dtr_cmnd
[tindex
],
10827 aic7xxx_negotiation_complete
);
10831 #ifdef AIC7XXX_VERBOSE_DEBUGGING
10832 /*+F*************************************************************************
10834 * aic7xxx_print_scb
10837 * Dump the byte codes for an about to be sent SCB.
10838 *-F*************************************************************************/
10840 aic7xxx_print_scb(struct aic7xxx_host
*p
, struct aic7xxx_scb
*scb
)
10845 x
= (unsigned char *)&scb
->hscb
->control
;
10847 for(i
=0; i
<32; i
++)
10849 printk("%02x ", x
[i
]);
10855 /*+F*************************************************************************
10861 *-F*************************************************************************/
10863 aic7xxx_buildscb(struct aic7xxx_host
*p
, Scsi_Cmnd
*cmd
,
10864 struct aic7xxx_scb
*scb
)
10866 unsigned short mask
;
10867 struct aic7xxx_hwscb
*hscb
;
10868 unsigned char tindex
= TARGET_INDEX(cmd
);
10870 mask
= (0x01 << tindex
);
10874 * Setup the control byte if we need negotiation and have not
10875 * already requested it.
10878 scb
->tag_action
= 0;
10879 cmd
->tag
= hscb
->tag
;
10880 if (p
->discenable
& mask
)
10882 hscb
->control
|= DISCENB
;
10883 if ( (p
->tagenable
& mask
) &&
10884 (cmd
->cmnd
[0] != TEST_UNIT_READY
) )
10886 p
->dev_commands_sent
[tindex
]++;
10887 if (p
->dev_commands_sent
[tindex
] < 200)
10889 hscb
->control
|= MSG_SIMPLE_Q_TAG
;
10890 scb
->tag_action
= MSG_SIMPLE_Q_TAG
;
10894 if (p
->orderedtag
& mask
)
10896 hscb
->control
|= MSG_ORDERED_Q_TAG
;
10897 scb
->tag_action
= MSG_ORDERED_Q_TAG
;
10901 hscb
->control
|= MSG_SIMPLE_Q_TAG
;
10902 scb
->tag_action
= MSG_SIMPLE_Q_TAG
;
10904 p
->dev_commands_sent
[tindex
] = 0;
10908 if ( cmd
== p
->dev_dtr_cmnd
[tindex
] )
10910 p
->dtr_pending
|= mask
;
10911 scb
->tag_action
= 0;
10912 if (p
->dev_flags
[tindex
] & DEVICE_SCANNED
)
10914 hscb
->control
&= DISCENB
;
10915 hscb
->control
|= MK_MESSAGE
;
10916 if(p
->needppr
& mask
)
10918 scb
->flags
|= SCB_MSGOUT_PPR
;
10920 else if(p
->needwdtr
& mask
)
10922 scb
->flags
|= SCB_MSGOUT_WDTR
;
10924 else if(p
->needsdtr
& mask
)
10926 scb
->flags
|= SCB_MSGOUT_SDTR
;
10930 if ( !(p
->dtr_pending
& mask
) &&
10931 ( (p
->needppr
& mask
) ||
10932 (p
->needwdtr
& mask
) ||
10933 (p
->needsdtr
& mask
) ) )
10935 aic7xxx_build_negotiation_cmnd(p
, cmd
, tindex
);
10937 hscb
->target_channel_lun
= ((cmd
->target
<< 4) & 0xF0) |
10938 ((cmd
->channel
& 0x01) << 3) | (cmd
->lun
& 0x07);
10941 * The interpretation of request_buffer and request_bufflen
10942 * changes depending on whether or not use_sg is zero; a
10943 * non-zero use_sg indicates the number of elements in the
10944 * scatter-gather array.
10948 * XXX - this relies on the host data being stored in a
10949 * little-endian format.
10951 hscb
->SCSI_cmd_length
= cmd
->cmd_len
;
10952 memcpy(scb
->cmnd
, cmd
->cmnd
, cmd
->cmd_len
);
10953 hscb
->SCSI_cmd_pointer
= cpu_to_le32(SCB_DMA_ADDR(scb
, scb
->cmnd
));
10957 struct scatterlist
*sg
; /* Must be mid-level SCSI code scatterlist */
10960 * We must build an SG list in adapter format, as the kernel's SG list
10961 * cannot be used directly because of data field size (__alpha__)
10962 * differences and the kernel SG list uses virtual addresses where
10963 * we need physical addresses.
10967 sg
= (struct scatterlist
*)cmd
->request_buffer
;
10968 scb
->sg_length
= 0;
10969 use_sg
= pci_map_sg(p
->pdev
, sg
, cmd
->use_sg
, scsi_to_pci_dma_dir(cmd
->sc_data_direction
));
10971 * Copy the segments into the SG array. NOTE!!! - We used to
10972 * have the first entry both in the data_pointer area and the first
10973 * SG element. That has changed somewhat. We still have the first
10974 * entry in both places, but now we download the address of
10975 * scb->sg_list[1] instead of 0 to the sg pointer in the hscb.
10977 for (i
= 0; i
< use_sg
; i
++)
10979 unsigned int len
= sg_dma_len(sg
+i
);
10980 scb
->sg_list
[i
].address
= cpu_to_le32(sg_dma_address(sg
+i
));
10981 scb
->sg_list
[i
].length
= cpu_to_le32(len
);
10982 scb
->sg_length
+= len
;
10984 /* Copy the first SG into the data pointer area. */
10985 hscb
->data_pointer
= scb
->sg_list
[0].address
;
10986 hscb
->data_count
= scb
->sg_list
[0].length
;
10988 hscb
->SG_segment_count
= i
;
10989 hscb
->SG_list_pointer
= cpu_to_le32(SCB_DMA_ADDR(scb
, &scb
->sg_list
[1]));
10993 if (cmd
->request_bufflen
)
10995 unsigned int address
= pci_map_single(p
->pdev
, cmd
->request_buffer
,
10996 cmd
->request_bufflen
,
10997 scsi_to_pci_dma_dir(cmd
->sc_data_direction
));
10998 aic7xxx_mapping(cmd
) = address
;
10999 scb
->sg_list
[0].address
= cpu_to_le32(address
);
11000 scb
->sg_list
[0].length
= cpu_to_le32(cmd
->request_bufflen
);
11002 scb
->sg_length
= cmd
->request_bufflen
;
11003 hscb
->SG_segment_count
= 1;
11004 hscb
->SG_list_pointer
= cpu_to_le32(SCB_DMA_ADDR(scb
, &scb
->sg_list
[0]));
11005 hscb
->data_count
= scb
->sg_list
[0].length
;
11006 hscb
->data_pointer
= scb
->sg_list
[0].address
;
11011 scb
->sg_length
= 0;
11012 hscb
->SG_segment_count
= 0;
11013 hscb
->SG_list_pointer
= 0;
11014 hscb
->data_count
= 0;
11015 hscb
->data_pointer
= 0;
11020 /*+F*************************************************************************
11025 * Queue a SCB to the controller.
11026 *-F*************************************************************************/
11028 aic7xxx_queue(Scsi_Cmnd
*cmd
, void (*fn
)(Scsi_Cmnd
*))
11030 struct aic7xxx_host
*p
;
11031 struct aic7xxx_scb
*scb
;
11032 #ifdef AIC7XXX_VERBOSE_DEBUGGING
11033 int tindex
= TARGET_INDEX(cmd
);
11035 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,1,95)
11036 unsigned long cpu_flags
= 0;
11039 p
= (struct aic7xxx_host
*) cmd
->host
->hostdata
;
11041 * Check to see if channel was scanned.
11044 #ifdef AIC7XXX_VERBOSE_DEBUGGING
11045 if (!(p
->flags
& AHC_A_SCANNED
) && (cmd
->channel
== 0))
11047 if (aic7xxx_verbose
& VERBOSE_PROBE2
)
11048 printk(INFO_LEAD
"Scanning channel for devices.\n",
11049 p
->host_no
, 0, -1, -1);
11050 p
->flags
|= AHC_A_SCANNED
;
11054 if (!(p
->flags
& AHC_B_SCANNED
) && (cmd
->channel
== 1))
11056 if (aic7xxx_verbose
& VERBOSE_PROBE2
)
11057 printk(INFO_LEAD
"Scanning channel for devices.\n",
11058 p
->host_no
, 1, -1, -1);
11059 p
->flags
|= AHC_B_SCANNED
;
11063 if (p
->dev_active_cmds
[tindex
] > (cmd
->device
->queue_depth
+ 1))
11065 printk(WARN_LEAD
"Commands queued exceeds queue "
11066 "depth, active=%d\n",
11067 p
->host_no
, CTL_OF_CMD(cmd
),
11068 p
->dev_active_cmds
[tindex
]);
11069 if ( p
->dev_active_cmds
[tindex
] > 220 )
11070 p
->dev_active_cmds
[tindex
] = 0;
11074 scb
= scbq_remove_head(&p
->scb_data
->free_scbs
);
11078 aic7xxx_allocate_scb(p
);
11080 scb
= scbq_remove_head(&p
->scb_data
->free_scbs
);
11084 printk(WARN_LEAD
"Couldn't get a free SCB.\n", p
->host_no
,
11086 cmd
->result
= (DID_BUS_BUSY
<< 16);
11088 aic7xxx_queue_cmd_complete(p
, cmd
);
11095 aic7xxx_position(cmd
) = scb
->hscb
->tag
;
11098 * Construct the SCB beforehand, so the sequencer is
11099 * paused a minimal amount of time.
11101 aic7xxx_buildscb(p
, cmd
, scb
);
11104 * Make sure the Scsi_Cmnd pointer is saved, the struct it points to
11105 * is set up properly, and the parity error flag is reset, then send
11106 * the SCB to the sequencer and watch the fun begin.
11108 cmd
->scsi_done
= fn
;
11109 cmd
->result
= DID_OK
;
11110 memset(cmd
->sense_buffer
, 0, sizeof(cmd
->sense_buffer
));
11111 aic7xxx_error(cmd
) = DID_OK
;
11112 aic7xxx_status(cmd
) = 0;
11113 cmd
->host_scribble
= NULL
;
11115 scb
->flags
|= SCB_ACTIVE
| SCB_WAITINGQ
;
11118 scbq_insert_tail(&p
->waiting_scbs
, scb
);
11119 if ( (p
->flags
& (AHC_IN_ISR
| AHC_IN_ABORT
| AHC_IN_RESET
)) == 0)
11121 aic7xxx_run_waiting_queues(p
);
11128 /*+F*************************************************************************
11130 * aic7xxx_bus_device_reset
11133 * Abort or reset the current SCSI command(s). If the scb has not
11134 * previously been aborted, then we attempt to send a BUS_DEVICE_RESET
11135 * message to the target. If the scb has previously been unsuccessfully
11136 * aborted, then we will reset the channel and have all devices renegotiate.
11137 * Returns an enumerated type that indicates the status of the operation.
11138 *-F*************************************************************************/
11140 aic7xxx_bus_device_reset(struct aic7xxx_host
*p
, Scsi_Cmnd
*cmd
)
11142 struct aic7xxx_scb
*scb
;
11143 struct aic7xxx_hwscb
*hscb
;
11146 unsigned char saved_scbptr
, lastphase
;
11147 unsigned char hscb_index
;
11150 scb
= (p
->scb_data
->scb_array
[aic7xxx_position(cmd
)]);
11153 lastphase
= aic_inb(p
, LASTPHASE
);
11154 if (aic7xxx_verbose
& VERBOSE_RESET_PROCESS
)
11156 printk(INFO_LEAD
"Bus Device reset, scb flags 0x%x, ",
11157 p
->host_no
, CTL_OF_SCB(scb
), scb
->flags
);
11161 printk("Data-Out phase\n");
11164 printk("Data-In phase\n");
11167 printk("Command phase\n");
11170 printk("Message-Out phase\n");
11173 printk("Status phase\n");
11176 printk("Message-In phase\n");
11180 * We're not in a valid phase, so assume we're idle.
11182 printk("while idle, LASTPHASE = 0x%x\n", lastphase
);
11185 printk(INFO_LEAD
"SCSISIGI 0x%x, SEQADDR 0x%x, SSTAT0 0x%x, SSTAT1 "
11186 "0x%x\n", p
->host_no
, CTL_OF_SCB(scb
),
11187 aic_inb(p
, SCSISIGI
),
11188 aic_inb(p
, SEQADDR0
) | (aic_inb(p
, SEQADDR1
) << 8),
11189 aic_inb(p
, SSTAT0
), aic_inb(p
, SSTAT1
));
11192 channel
= cmd
->channel
;
11195 * Send a Device Reset Message:
11196 * The target that is holding up the bus may not be the same as
11197 * the one that triggered this timeout (different commands have
11198 * different timeout lengths). Our strategy here is to queue an
11199 * abort message to the timed out target if it is disconnected.
11200 * Otherwise, if we have an active target we stuff the message buffer
11201 * with an abort message and assert ATN in the hopes that the target
11202 * will let go of the bus and go to the mesgout phase. If this
11203 * fails, we'll get another timeout a few seconds later which will
11204 * attempt a bus reset.
11206 saved_scbptr
= aic_inb(p
, SCBPTR
);
11207 disconnected
= FALSE
;
11209 if (lastphase
!= P_BUSFREE
)
11211 if (aic_inb(p
, SCB_TAG
) >= p
->scb_data
->numscbs
)
11213 printk(WARN_LEAD
"Invalid SCB ID %d is active, "
11214 "SCB flags = 0x%x.\n", p
->host_no
,
11215 CTL_OF_CMD(cmd
), scb
->hscb
->tag
, scb
->flags
);
11216 return(SCSI_RESET_ERROR
);
11218 if (scb
->hscb
->tag
== aic_inb(p
, SCB_TAG
))
11220 if ( (lastphase
!= P_MESGOUT
) && (lastphase
!= P_MESGIN
) )
11222 if (aic7xxx_verbose
& VERBOSE_RESET_PROCESS
)
11223 printk(INFO_LEAD
"Device reset message in "
11224 "message buffer\n", p
->host_no
, CTL_OF_SCB(scb
));
11225 scb
->flags
|= SCB_RESET
| SCB_DEVICE_RESET
;
11226 aic7xxx_error(scb
->cmd
) = DID_RESET
;
11227 p
->dev_flags
[TARGET_INDEX(scb
->cmd
)] |=
11228 BUS_DEVICE_RESET_PENDING
;
11229 /* Send the abort message to the active SCB. */
11230 aic_outb(p
, HOST_MSG
, MSG_OUT
);
11231 aic_outb(p
, lastphase
| ATNO
, SCSISIGO
);
11232 return(SCSI_RESET_PENDING
);
11236 /* We want to send out the message, but it could screw an already */
11237 /* in place and being used message. Instead, we return an error */
11238 /* to try and start the bus reset phase since this command is */
11239 /* probably hung (aborts failed, and now reset is failing). We */
11240 /* also make sure to set BUS_DEVICE_RESET_PENDING so we won't try */
11241 /* any more on this device, but instead will escalate to a bus or */
11242 /* host reset (additionally, we won't try to abort any more). */
11243 printk(WARN_LEAD
"Device reset, Message buffer "
11244 "in use\n", p
->host_no
, CTL_OF_SCB(scb
));
11245 scb
->flags
|= SCB_RESET
| SCB_DEVICE_RESET
;
11246 aic7xxx_error(scb
->cmd
) = DID_RESET
;
11247 p
->dev_flags
[TARGET_INDEX(scb
->cmd
)] |=
11248 BUS_DEVICE_RESET_PENDING
;
11249 return(SCSI_RESET_ERROR
);
11252 } /* if (last_phase != P_BUSFREE).....indicates we are idle and can work */
11253 hscb_index
= aic7xxx_find_scb(p
, scb
);
11254 if (hscb_index
== SCB_LIST_NULL
)
11256 disconnected
= (aic7xxx_scb_on_qoutfifo(p
, scb
)) ? FALSE
: TRUE
;
11260 aic_outb(p
, hscb_index
, SCBPTR
);
11261 if (aic_inb(p
, SCB_CONTROL
) & DISCONNECTED
)
11263 disconnected
= TRUE
;
11269 * Simply set the MK_MESSAGE flag and the SEQINT handler will do
11270 * the rest on a reconnect.
11272 scb
->hscb
->control
|= MK_MESSAGE
;
11273 scb
->flags
|= SCB_RESET
| SCB_DEVICE_RESET
;
11274 p
->dev_flags
[TARGET_INDEX(scb
->cmd
)] |=
11275 BUS_DEVICE_RESET_PENDING
;
11276 if (hscb_index
!= SCB_LIST_NULL
)
11278 unsigned char scb_control
;
11280 aic_outb(p
, hscb_index
, SCBPTR
);
11281 scb_control
= aic_inb(p
, SCB_CONTROL
);
11282 aic_outb(p
, scb_control
| MK_MESSAGE
, SCB_CONTROL
);
11285 * Actually requeue this SCB in case we can select the
11286 * device before it reconnects. If the transaction we
11287 * want to abort is not tagged, then this will be the only
11288 * outstanding command and we can simply shove it on the
11289 * qoutfifo and be done. If it is tagged, then it goes right
11290 * in with all the others, no problem :) We need to add it
11291 * to the qinfifo and let the sequencer know it is there.
11292 * Now, the only problem left to deal with is, *IF* this
11293 * command completes, in spite of the MK_MESSAGE bit in the
11294 * control byte, then we need to pick that up in the interrupt
11295 * routine and clean things up. This *shouldn't* ever happen.
11297 if (aic7xxx_verbose
& VERBOSE_RESET_PROCESS
)
11298 printk(INFO_LEAD
"Queueing device reset "
11299 "command.\n", p
->host_no
, CTL_OF_SCB(scb
));
11300 p
->qinfifo
[p
->qinfifonext
++] = scb
->hscb
->tag
;
11301 if (p
->features
& AHC_QUEUE_REGS
)
11302 aic_outb(p
, p
->qinfifonext
, HNSCB_QOFF
);
11304 aic_outb(p
, p
->qinfifonext
, KERNEL_QINPOS
);
11305 scb
->flags
|= SCB_QUEUED_ABORT
;
11306 result
= SCSI_RESET_PENDING
;
11308 else if (result
== -1)
11310 result
= SCSI_RESET_ERROR
;
11312 aic_outb(p
, saved_scbptr
, SCBPTR
);
11317 /*+F*************************************************************************
11319 * aic7xxx_panic_abort
11322 * Abort the current SCSI command(s).
11323 *-F*************************************************************************/
11325 aic7xxx_panic_abort(struct aic7xxx_host
*p
, Scsi_Cmnd
*cmd
)
11328 printk("aic7xxx driver version %s/%s\n", AIC7XXX_C_VERSION
,
11330 printk("Controller type:\n %s\n", board_names
[p
->board_name_index
]);
11331 printk("p->flags=0x%x, p->chip=0x%x, p->features=0x%x, "
11332 "sequencer %s paused\n",
11333 p
->flags
, p
->chip
, p
->features
,
11334 (aic_inb(p
, HCNTRL
) & PAUSE
) ? "is" : "isn't" );
11335 pause_sequencer(p
);
11336 disable_irq(p
->irq
);
11337 aic7xxx_print_card(p
);
11338 aic7xxx_print_scratch_ram(p
);
11339 spin_unlock_irq(&io_request_lock
);
11343 /*+F*************************************************************************
11348 * Abort the current SCSI command(s).
11349 *-F*************************************************************************/
11351 aic7xxx_abort(Scsi_Cmnd
*cmd
)
11353 struct aic7xxx_scb
*scb
= NULL
;
11354 struct aic7xxx_host
*p
;
11355 int result
, found
=0;
11356 unsigned char tmp_char
, saved_hscbptr
, next_hscbptr
, prev_hscbptr
;
11357 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,1,95)
11358 unsigned long cpu_flags
= 0;
11360 Scsi_Cmnd
*cmd_next
, *cmd_prev
;
11362 p
= (struct aic7xxx_host
*) cmd
->host
->hostdata
;
11363 scb
= (p
->scb_data
->scb_array
[aic7xxx_position(cmd
)]);
11366 * I added a new config option to the driver: "panic_on_abort" that will
11367 * cause the driver to panic and the machine to stop on the first abort
11368 * or reset call into the driver. At that point, it prints out a lot of
11369 * usefull information for me which I can then use to try and debug the
11370 * problem. Simply enable the boot time prompt in order to activate this
11373 if (aic7xxx_panic_on_abort
)
11374 aic7xxx_panic_abort(p
, cmd
);
11379 * Run the isr to grab any command in the QOUTFIFO and any other misc.
11380 * assundry tasks. This should also set up the bh handler if there is
11381 * anything to be done, but it won't run until we are done here since
11382 * we are following a straight code path without entering the scheduler
11385 pause_sequencer(p
);
11386 while ( (aic_inb(p
, INTSTAT
) & INT_PEND
) && !(p
->flags
& AHC_IN_ISR
))
11388 aic7xxx_isr(p
->irq
, p
, (void *)NULL
);
11389 pause_sequencer(p
);
11390 aic7xxx_done_cmds_complete(p
);
11393 if ((scb
== NULL
) || (cmd
->serial_number
!= cmd
->serial_number_at_timeout
))
11394 /* Totally bogus cmd since it points beyond our */
11395 { /* valid SCB range or doesn't even match it's own*/
11396 /* timeout serial number. */
11397 if (aic7xxx_verbose
& VERBOSE_ABORT_MID
)
11398 printk(INFO_LEAD
"Abort called with bogus Scsi_Cmnd "
11399 "pointer.\n", p
->host_no
, CTL_OF_CMD(cmd
));
11400 unpause_sequencer(p
, FALSE
);
11402 return(SCSI_ABORT_NOT_RUNNING
);
11404 if (scb
->cmd
!= cmd
) /* Hmmm...either this SCB is currently free with a */
11405 { /* NULL cmd pointer (NULLed out when freed) or it */
11406 /* has already been recycled for another command */
11407 /* Either way, this SCB has nothing to do with this*/
11408 /* command and we need to deal with cmd without */
11409 /* touching the SCB. */
11410 /* The theory here is to return a value that will */
11411 /* make the queued for complete command actually */
11412 /* finish successfully, or to indicate that we */
11413 /* don't have this cmd any more and the mid level */
11414 /* code needs to find it. */
11415 cmd_next
= p
->completeq
.head
;
11417 while (cmd_next
!= NULL
)
11419 if (cmd_next
== cmd
)
11421 if (aic7xxx_verbose
& VERBOSE_ABORT_PROCESS
)
11422 printk(INFO_LEAD
"Abort called for command "
11423 "on completeq, completing.\n", p
->host_no
, CTL_OF_CMD(cmd
));
11424 if ( cmd_prev
== NULL
)
11425 p
->completeq
.head
= (Scsi_Cmnd
*)cmd_next
->host_scribble
;
11427 cmd_prev
->host_scribble
= cmd_next
->host_scribble
;
11428 cmd_next
->scsi_done(cmd_next
);
11429 unpause_sequencer(p
, FALSE
);
11431 return(SCSI_ABORT_NOT_RUNNING
); /* It's already back as a successful
11434 cmd_prev
= cmd_next
;
11435 cmd_next
= (Scsi_Cmnd
*)cmd_next
->host_scribble
;
11437 if (aic7xxx_verbose
& VERBOSE_ABORT_MID
)
11438 printk(INFO_LEAD
"Abort called for already completed"
11439 " command.\n", p
->host_no
, CTL_OF_CMD(cmd
));
11440 unpause_sequencer(p
, FALSE
);
11442 return(SCSI_ABORT_NOT_RUNNING
);
11445 /* At this point we know the following:
11446 * the SCB pointer is valid
11447 * the command pointer passed in to us and the scb->cmd pointer match
11448 * this then means that the command we need to abort is the same as the
11449 * command held by the scb pointer and is a valid abort request.
11450 * Now, we just have to figure out what to do from here. Current plan is:
11451 * if we have already been here on this command, escalate to a reset
11452 * if scb is on waiting list or QINFIFO, send it back as aborted, but
11453 * we also need to be aware of the possibility that we could be using
11454 * a faked negotiation command that is holding this command up, if
11455 * so we need to take care of that command instead, which means we
11456 * would then treat this one like it was sitting around disconnected
11458 * if scb is on WAITING_SCB list in sequencer, free scb and send back
11459 * if scb is disconnected and not completed, abort with abort message
11460 * if scb is currently running, then it may be causing the bus to hang
11461 * so we want a return value that indicates a reset would be appropriate
11462 * if the command does not finish shortly
11463 * if scb is already complete but not on completeq, we're screwed because
11464 * this can't happen (except if the command is in the QOUTFIFO, in which
11465 * case we would like it to complete successfully instead of having to
11467 * All other scenarios already dealt with by previous code.
11470 if ( scb
->flags
& (SCB_ABORT
| SCB_RESET
| SCB_QUEUED_ABORT
) )
11472 if (aic7xxx_verbose
& VERBOSE_ABORT_PROCESS
)
11473 printk(INFO_LEAD
"SCB aborted once already, "
11474 "escalating.\n", p
->host_no
, CTL_OF_SCB(scb
));
11475 unpause_sequencer(p
, FALSE
);
11477 return(SCSI_ABORT_SNOOZE
);
11479 if ( (p
->flags
& (AHC_RESET_PENDING
| AHC_ABORT_PENDING
)) ||
11480 (p
->dev_flags
[TARGET_INDEX(scb
->cmd
)] &
11481 BUS_DEVICE_RESET_PENDING
) )
11483 if (aic7xxx_verbose
& VERBOSE_ABORT_PROCESS
)
11484 printk(INFO_LEAD
"Reset/Abort pending for this "
11485 "device, not wasting our time.\n", p
->host_no
, CTL_OF_SCB(scb
));
11486 unpause_sequencer(p
, FALSE
);
11488 return(SCSI_ABORT_PENDING
);
11492 p
->flags
|= AHC_IN_ABORT
;
11493 if (aic7xxx_verbose
& VERBOSE_ABORT
)
11494 printk(INFO_LEAD
"Aborting scb %d, flags 0x%x\n",
11495 p
->host_no
, CTL_OF_SCB(scb
), scb
->hscb
->tag
, scb
->flags
);
11498 * First, let's check to see if the currently running command is our target
11499 * since if it is, the return is fairly easy and quick since we don't want
11500 * to touch the command in case it might complete, but we do want a timeout
11501 * in case it's actually hung, so we really do nothing, but tell the mid
11502 * level code to reset the timeout.
11505 if ( scb
->hscb
->tag
== aic_inb(p
, SCB_TAG
) )
11508 * Check to see if the sequencer is just sitting on this command, or
11509 * if it's actively being run.
11511 result
= aic_inb(p
, LASTPHASE
);
11514 case P_DATAOUT
: /* For any of these cases, we can assume we are */
11515 case P_DATAIN
: /* an active command and act according. For */
11516 case P_COMMAND
: /* anything else we are going to fall on through*/
11517 case P_STATUS
: /* The SCSI_ABORT_SNOOZE will give us two abort */
11518 case P_MESGOUT
: /* chances to finish and then escalate to a */
11519 case P_MESGIN
: /* reset call */
11520 if (aic7xxx_verbose
& VERBOSE_ABORT_PROCESS
)
11521 printk(INFO_LEAD
"SCB is currently active. "
11522 "Waiting on completion.\n", p
->host_no
, CTL_OF_SCB(scb
));
11523 unpause_sequencer(p
, FALSE
);
11524 p
->flags
&= ~AHC_IN_ABORT
;
11525 scb
->flags
|= SCB_RECOVERY_SCB
; /* Note the fact that we've been */
11526 p
->flags
|= AHC_ABORT_PENDING
; /* here so we will know not to */
11527 DRIVER_UNLOCK
/* muck with other SCBs if this */
11528 return(SCSI_ABORT_PENDING
); /* one doesn't complete and clear */
11535 if ((found
== 0) && (scb
->flags
& SCB_WAITINGQ
))
11537 int tindex
= TARGET_INDEX(cmd
);
11538 unsigned short mask
;
11540 mask
= (1 << tindex
);
11542 if (p
->dtr_pending
& mask
)
11544 if (p
->dev_dtr_cmnd
[tindex
]->next
!= cmd
)
11556 * OK..this means the command we are currently getting an abort
11557 * for has an outstanding negotiation command in front of it.
11558 * We don't really have a way to tie back into the negotiation
11559 * commands, so we just send this back as pending, then it
11560 * will get reset in 2 seconds.
11562 unpause_sequencer(p
, TRUE
);
11563 scb
->flags
|= SCB_ABORT
;
11565 return(SCSI_ABORT_PENDING
);
11567 if (aic7xxx_verbose
& VERBOSE_ABORT_PROCESS
)
11568 printk(INFO_LEAD
"SCB found on waiting list and "
11569 "aborted.\n", p
->host_no
, CTL_OF_SCB(scb
));
11570 scbq_remove(&p
->waiting_scbs
, scb
);
11571 scbq_remove(&p
->delayed_scbs
[tindex
], scb
);
11572 p
->dev_active_cmds
[tindex
]++;
11574 scb
->flags
&= ~(SCB_WAITINGQ
| SCB_ACTIVE
);
11575 scb
->flags
|= SCB_ABORT
| SCB_QUEUED_FOR_DONE
;
11580 * We just checked the waiting_q, now for the QINFIFO
11584 if ( ((found
= aic7xxx_search_qinfifo(p
, cmd
->target
,
11586 cmd
->lun
, scb
->hscb
->tag
, SCB_ABORT
| SCB_QUEUED_FOR_DONE
,
11587 FALSE
, NULL
)) != 0) &&
11588 (aic7xxx_verbose
& VERBOSE_ABORT_PROCESS
))
11589 printk(INFO_LEAD
"SCB found in QINFIFO and "
11590 "aborted.\n", p
->host_no
, CTL_OF_SCB(scb
));
11594 * QINFIFO, waitingq, completeq done. Next, check WAITING_SCB list in card
11599 unsigned char scb_next_ptr
;
11600 prev_hscbptr
= SCB_LIST_NULL
;
11601 saved_hscbptr
= aic_inb(p
, SCBPTR
);
11602 next_hscbptr
= aic_inb(p
, WAITING_SCBH
);
11603 while ( next_hscbptr
!= SCB_LIST_NULL
)
11605 aic_outb(p
, next_hscbptr
, SCBPTR
);
11606 if ( scb
->hscb
->tag
== aic_inb(p
, SCB_TAG
) )
11609 if (aic7xxx_verbose
& VERBOSE_ABORT_PROCESS
)
11610 printk(INFO_LEAD
"SCB found on hardware waiting"
11611 " list and aborted.\n", p
->host_no
, CTL_OF_SCB(scb
));
11612 if ( prev_hscbptr
== SCB_LIST_NULL
)
11614 aic_outb(p
, aic_inb(p
, SCB_NEXT
), WAITING_SCBH
);
11615 /* stop the selection since we just
11616 * grabbed the scb out from under the
11619 aic_outb(p
, aic_inb(p
, SCSISEQ
) & ~ENSELO
, SCSISEQ
);
11620 aic_outb(p
, CLRSELTIMEO
, CLRSINT1
);
11624 scb_next_ptr
= aic_inb(p
, SCB_NEXT
);
11625 aic_outb(p
, prev_hscbptr
, SCBPTR
);
11626 aic_outb(p
, scb_next_ptr
, SCB_NEXT
);
11627 aic_outb(p
, next_hscbptr
, SCBPTR
);
11629 aic_outb(p
, SCB_LIST_NULL
, SCB_TAG
);
11630 aic_outb(p
, 0, SCB_CONTROL
);
11631 aic7xxx_add_curscb_to_free_list(p
);
11632 scb
->flags
= SCB_ABORT
| SCB_QUEUED_FOR_DONE
;
11635 prev_hscbptr
= next_hscbptr
;
11636 next_hscbptr
= aic_inb(p
, SCB_NEXT
);
11638 aic_outb(p
, saved_hscbptr
, SCBPTR
);
11642 * Hmmm...completeq, QOUTFIFO, QINFIFO, WAITING_SCBH, waitingq all checked.
11643 * OK...the sequencer's paused, interrupts are off, and we haven't found the
11644 * command anyplace where it could be easily aborted. Time for the hard
11645 * work. We also know the command is valid. This essentially means the
11646 * command is disconnected, or connected but not into any phases yet, which
11647 * we know due to the tests we ran earlier on the current active scb phase.
11648 * At this point we can queue the abort tag and go on with life.
11653 p
->flags
|= AHC_ABORT_PENDING
;
11654 scb
->flags
|= SCB_QUEUED_ABORT
| SCB_ABORT
| SCB_RECOVERY_SCB
;
11655 scb
->hscb
->control
|= MK_MESSAGE
;
11656 result
=aic7xxx_find_scb(p
, scb
);
11657 if ( result
!= SCB_LIST_NULL
)
11659 saved_hscbptr
= aic_inb(p
, SCBPTR
);
11660 aic_outb(p
, result
, SCBPTR
);
11661 tmp_char
= aic_inb(p
, SCB_CONTROL
);
11662 aic_outb(p
, tmp_char
| MK_MESSAGE
, SCB_CONTROL
);
11663 aic_outb(p
, saved_hscbptr
, SCBPTR
);
11665 if (aic7xxx_verbose
& VERBOSE_ABORT_PROCESS
)
11666 printk(INFO_LEAD
"SCB disconnected. Queueing Abort"
11667 " SCB.\n", p
->host_no
, CTL_OF_SCB(scb
));
11668 p
->qinfifo
[p
->qinfifonext
++] = scb
->hscb
->tag
;
11669 if (p
->features
& AHC_QUEUE_REGS
)
11670 aic_outb(p
, p
->qinfifonext
, HNSCB_QOFF
);
11672 aic_outb(p
, p
->qinfifonext
, KERNEL_QINPOS
);
11676 aic7xxx_run_done_queue(p
, TRUE
);
11677 aic7xxx_run_waiting_queues(p
);
11679 p
->flags
&= ~AHC_IN_ABORT
;
11680 unpause_sequencer(p
, FALSE
);
11684 * On the return value. If we found the command and aborted it, then we know
11685 * it's already sent back and there is no reason for a further timeout, so
11686 * we use SCSI_ABORT_SUCCESS. On the queued abort side, we aren't so certain
11687 * there hasn't been a bus hang or something that might keep the abort from
11688 * from completing. Therefore, we use SCSI_ABORT_PENDING. The first time this
11689 * is passed back, the timeout on the command gets extended, the second time
11690 * we pass this back, the mid level SCSI code calls our reset function, which
11691 * would shake loose a hung bus.
11694 return(SCSI_ABORT_SUCCESS
);
11696 return(SCSI_ABORT_PENDING
);
11700 /*+F*************************************************************************
11705 * Resetting the bus always succeeds - is has to, otherwise the
11706 * kernel will panic! Try a surgical technique - sending a BUS
11707 * DEVICE RESET message - on the offending target before pulling
11708 * the SCSI bus reset line.
11709 *-F*************************************************************************/
11711 aic7xxx_reset(Scsi_Cmnd
*cmd
, unsigned int flags
)
11713 struct aic7xxx_scb
*scb
= NULL
;
11714 struct aic7xxx_host
*p
;
11717 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,1,95)
11718 unsigned long cpu_flags
= 0;
11720 #define DEVICE_RESET 0x01
11721 #define BUS_RESET 0x02
11722 #define HOST_RESET 0x04
11724 #define RESET_DELAY 0x10
11726 Scsi_Cmnd
*cmd_prev
, *cmd_next
;
11731 printk(KERN_WARNING
"(scsi?:?:?:?) Reset called with NULL Scsi_Cmnd "
11732 "pointer, failing.\n");
11733 return(SCSI_RESET_SNOOZE
);
11736 p
= (struct aic7xxx_host
*) cmd
->host
->hostdata
;
11737 scb
= (p
->scb_data
->scb_array
[aic7xxx_position(cmd
)]);
11738 tindex
= TARGET_INDEX(cmd
);
11741 * I added a new config option to the driver: "panic_on_abort" that will
11742 * cause the driver to panic and the machine to stop on the first abort
11743 * or reset call into the driver. At that point, it prints out a lot of
11744 * usefull information for me which I can then use to try and debug the
11745 * problem. Simply enable the boot time prompt in order to activate this
11748 if (aic7xxx_panic_on_abort
)
11749 aic7xxx_panic_abort(p
, cmd
);
11753 pause_sequencer(p
);
11754 while ( (aic_inb(p
, INTSTAT
) & INT_PEND
) && !(p
->flags
& AHC_IN_ISR
))
11756 aic7xxx_isr(p
->irq
, p
, (void *)NULL
);
11757 pause_sequencer(p
);
11758 aic7xxx_done_cmds_complete(p
);
11763 if (aic7xxx_verbose
& VERBOSE_RESET_MID
)
11764 printk(INFO_LEAD
"Reset called with bogus Scsi_Cmnd"
11765 "->SCB mapping, improvising.\n", p
->host_no
, CTL_OF_CMD(cmd
));
11766 if ( flags
& SCSI_RESET_SUGGEST_HOST_RESET
)
11768 action
= HOST_RESET
;
11772 action
= BUS_RESET
;
11775 else if (scb
->cmd
!= cmd
)
11777 if (aic7xxx_verbose
& VERBOSE_RESET_MID
)
11778 printk(INFO_LEAD
"Reset called with recycled SCB "
11779 "for cmd.\n", p
->host_no
, CTL_OF_CMD(cmd
));
11781 cmd_next
= p
->completeq
.head
;
11782 while ( cmd_next
!= NULL
)
11784 if (cmd_next
== cmd
)
11786 if (aic7xxx_verbose
& VERBOSE_RESET_RETURN
)
11787 printk(INFO_LEAD
"Reset, found cmd on completeq"
11788 ", completing.\n", p
->host_no
, CTL_OF_CMD(cmd
));
11789 unpause_sequencer(p
, FALSE
);
11791 return(SCSI_RESET_NOT_RUNNING
);
11793 cmd_prev
= cmd_next
;
11794 cmd_next
= (Scsi_Cmnd
*)cmd_next
->host_scribble
;
11796 if ( !(flags
& SCSI_RESET_SYNCHRONOUS
) )
11798 if (aic7xxx_verbose
& VERBOSE_RESET_RETURN
)
11799 printk(INFO_LEAD
"Reset, cmd not found,"
11800 " failing.\n", p
->host_no
, CTL_OF_CMD(cmd
));
11801 unpause_sequencer(p
, FALSE
);
11803 return(SCSI_RESET_NOT_RUNNING
);
11807 if (aic7xxx_verbose
& VERBOSE_RESET_MID
)
11808 printk(INFO_LEAD
"Reset called, no scb, "
11809 "flags 0x%x\n", p
->host_no
, CTL_OF_CMD(cmd
), flags
);
11811 action
= HOST_RESET
;
11816 if (aic7xxx_verbose
& VERBOSE_RESET_MID
)
11817 printk(INFO_LEAD
"Reset called, scb %d, flags "
11818 "0x%x\n", p
->host_no
, CTL_OF_SCB(scb
), scb
->hscb
->tag
, scb
->flags
);
11819 if ( aic7xxx_scb_on_qoutfifo(p
, scb
) )
11821 if(aic7xxx_verbose
& VERBOSE_RESET_RETURN
)
11822 printk(INFO_LEAD
"SCB on qoutfifo, completing.\n", p
->host_no
,
11824 if ((aic_inb(p
,INTSTAT
) & CMDCMPLT
) == 0)
11825 printk(INFO_LEAD
"missed CMDCMPLT interrupt!\n", p
->host_no
,
11827 aic7xxx_handle_command_completion_intr(p
);
11828 aic7xxx_done_cmds_complete(p
);
11829 aic7xxx_run_waiting_queues(p
);
11830 unpause_sequencer(p
, FALSE
);
11832 return(SCSI_RESET_SUCCESS
);
11834 if ( flags
& SCSI_RESET_SUGGEST_HOST_RESET
)
11836 action
= HOST_RESET
;
11838 else if ( flags
& SCSI_RESET_SUGGEST_BUS_RESET
)
11840 action
= BUS_RESET
;
11844 action
= DEVICE_RESET
;
11847 if ( (action
& DEVICE_RESET
) &&
11848 (p
->dev_flags
[tindex
] & BUS_DEVICE_RESET_PENDING
) )
11850 if (aic7xxx_verbose
& VERBOSE_RESET_PROCESS
)
11851 printk(INFO_LEAD
"Bus device reset already sent to "
11852 "device, escalating.\n", p
->host_no
, CTL_OF_CMD(cmd
));
11853 action
= BUS_RESET
;
11855 if ( (action
& DEVICE_RESET
) &&
11856 (scb
->flags
& SCB_QUEUED_ABORT
) )
11858 if (aic7xxx_verbose
& VERBOSE_RESET_PROCESS
)
11860 printk(INFO_LEAD
"Have already attempted to reach "
11861 "device with queued\n", p
->host_no
, CTL_OF_CMD(cmd
));
11862 printk(INFO_LEAD
"message, will escalate to bus "
11863 "reset.\n", p
->host_no
, CTL_OF_CMD(cmd
));
11865 action
= BUS_RESET
;
11867 if ( (action
& DEVICE_RESET
) &&
11868 (p
->flags
& (AHC_RESET_PENDING
| AHC_ABORT_PENDING
)) )
11870 if (aic7xxx_verbose
& VERBOSE_RESET_PROCESS
)
11871 printk(INFO_LEAD
"Bus device reset stupid when "
11872 "other action has failed.\n", p
->host_no
, CTL_OF_CMD(cmd
));
11873 action
= BUS_RESET
;
11875 if ( (action
& BUS_RESET
) && !(p
->features
& AHC_TWIN
) )
11877 action
= HOST_RESET
;
11879 if ( (p
->dev_flags
[tindex
] & DEVICE_RESET_DELAY
) &&
11880 !(action
& (HOST_RESET
| BUS_RESET
)))
11882 if (aic7xxx_verbose
& VERBOSE_RESET_PROCESS
)
11884 printk(INFO_LEAD
"Reset called too soon after last "
11885 "reset without requesting\n", p
->host_no
, CTL_OF_CMD(cmd
));
11886 printk(INFO_LEAD
"bus or host reset, escalating.\n", p
->host_no
,
11889 action
= BUS_RESET
;
11891 if ( (p
->flags
& AHC_RESET_DELAY
) &&
11892 (action
& (HOST_RESET
| BUS_RESET
)) )
11894 if (aic7xxx_verbose
& VERBOSE_RESET_PROCESS
)
11895 printk(INFO_LEAD
"Reset called too soon after "
11896 "last bus reset, delaying.\n", p
->host_no
, CTL_OF_CMD(cmd
));
11897 action
= RESET_DELAY
;
11900 * By this point, we want to already know what we are going to do and
11901 * only have the following code implement our course of action.
11906 unpause_sequencer(p
, FALSE
);
11908 return(SCSI_RESET_PENDING
);
11911 unpause_sequencer(p
, FALSE
);
11913 return(SCSI_RESET_ERROR
);
11916 p
->flags
|= AHC_IN_RESET
;
11917 result
= aic7xxx_bus_device_reset(p
, cmd
);
11918 aic7xxx_run_done_queue(p
, TRUE
);
11919 /* We can't rely on run_waiting_queues to unpause the sequencer for
11920 * PCI based controllers since we use AAP */
11921 aic7xxx_run_waiting_queues(p
);
11922 unpause_sequencer(p
, FALSE
);
11923 p
->flags
&= ~AHC_IN_RESET
;
11930 p
->flags
|= AHC_IN_RESET
| AHC_RESET_DELAY
;
11931 p
->dev_expires
[p
->scsi_id
] = jiffies
+ (3 * HZ
);
11932 p
->dev_timer_active
|= (0x01 << p
->scsi_id
);
11933 if ( !(p
->dev_timer_active
& (0x01 << MAX_TARGETS
)) ||
11934 time_after_eq(p
->dev_timer
.expires
, p
->dev_expires
[p
->scsi_id
]) )
11936 mod_timer(&p
->dev_timer
, p
->dev_expires
[p
->scsi_id
]);
11937 p
->dev_timer_active
|= (0x01 << MAX_TARGETS
);
11939 aic7xxx_reset_channel(p
, cmd
->channel
, TRUE
);
11940 if ( (p
->features
& AHC_TWIN
) && (action
& HOST_RESET
) )
11942 aic7xxx_reset_channel(p
, cmd
->channel
^ 0x01, TRUE
);
11943 restart_sequencer(p
);
11945 if (action
!= HOST_RESET
)
11946 result
= SCSI_RESET_SUCCESS
| SCSI_RESET_BUS_RESET
;
11949 result
= SCSI_RESET_SUCCESS
| SCSI_RESET_HOST_RESET
;
11950 aic_outb(p
, aic_inb(p
, SIMODE1
) & ~(ENREQINIT
|ENBUSFREE
),
11952 aic7xxx_clear_intstat(p
);
11953 p
->flags
&= ~AHC_HANDLING_REQINITS
;
11954 p
->msg_type
= MSG_TYPE_NONE
;
11958 aic7xxx_run_done_queue(p
, TRUE
);
11960 * If this a SCSI_RESET_SYNCHRONOUS then the command we were given is
11961 * in need of being re-started, so send it on through to aic7xxx_queue
11962 * and let it set until the delay is over. This keeps it from dying
11963 * entirely and avoids getting a bogus dead command back through the
11964 * mid-level code due to too many retries.
11966 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,1,132)
11967 if ( flags
& SCSI_RESET_SYNCHRONOUS
)
11969 cmd
->result
= DID_BUS_BUSY
<< 16;
11973 p
->flags
&= ~AHC_IN_RESET
;
11975 * We can't rely on run_waiting_queues to unpause the sequencer for
11976 * PCI based controllers since we use AAP. NOTE: this also sets
11977 * the timer for the one command we might have queued in the case
11978 * of a synch reset.
11980 aic7xxx_run_waiting_queues(p
);
11981 unpause_sequencer(p
, FALSE
);
11988 /*+F*************************************************************************
11990 * aic7xxx_biosparam
11993 * Return the disk geometry for the given SCSI device.
11994 *-F*************************************************************************/
11996 aic7xxx_biosparam(Disk
*disk
, kdev_t dev
, int geom
[])
11998 int heads
, sectors
, cylinders
, ret
;
11999 struct aic7xxx_host
*p
;
12000 struct buffer_head
*bh
;
12002 p
= (struct aic7xxx_host
*) disk
->device
->host
->hostdata
;
12003 bh
= bread(MKDEV(MAJOR(dev
), MINOR(dev
)&~0xf), 0, 1024);
12007 ret
= scsi_partsize(bh
, disk
->capacity
, &geom
[2], &geom
[0], &geom
[1]);
12015 cylinders
= disk
->capacity
/ (heads
* sectors
);
12017 if ((p
->flags
& AHC_EXTEND_TRANS_A
) && (cylinders
> 1024))
12021 cylinders
= disk
->capacity
/ (heads
* sectors
);
12026 geom
[2] = cylinders
;
12031 /*+F*************************************************************************
12036 * Free the passed in Scsi_Host memory structures prior to unloading the
12038 *-F*************************************************************************/
12040 aic7xxx_release(struct Scsi_Host
*host
)
12042 struct aic7xxx_host
*p
= (struct aic7xxx_host
*) host
->hostdata
;
12043 struct aic7xxx_host
*next
, *prev
;
12046 free_irq(p
->irq
, p
);
12048 release_region(p
->base
, MAXREG
- MINREG
);
12052 iounmap((void *) (((unsigned long) p
->maddr
) & PAGE_MASK
));
12054 #endif /* MMAPIO */
12056 next
= first_aic7xxx
;
12057 while(next
!= NULL
)
12062 first_aic7xxx
= next
->next
;
12064 prev
->next
= next
->next
;
12076 /*+F*************************************************************************
12078 * aic7xxx_print_card
12081 * Print out all of the control registers on the card
12083 * NOTE: This function is not yet safe for use on the VLB and EISA
12084 * controllers, so it isn't used on those controllers at all.
12085 *-F*************************************************************************/
12087 aic7xxx_print_card(struct aic7xxx_host
*p
)
12090 static struct register_ranges
{
12094 { 0, {0,} }, /* none */
12095 {10, {0x00, 0x05, 0x08, 0x11, 0x18, 0x19, 0x1f, 0x1f, 0x60, 0x60, /*7771*/
12096 0x62, 0x66, 0x80, 0x8e, 0x90, 0x95, 0x97, 0x97, 0x9b, 0x9f} },
12097 { 9, {0x00, 0x05, 0x08, 0x11, 0x18, 0x1f, 0x60, 0x60, 0x62, 0x66, /*7850*/
12098 0x80, 0x8e, 0x90, 0x95, 0x97, 0x97, 0x9a, 0x9f} },
12099 { 9, {0x00, 0x05, 0x08, 0x11, 0x18, 0x1f, 0x60, 0x60, 0x62, 0x66, /*7860*/
12100 0x80, 0x8e, 0x90, 0x95, 0x97, 0x97, 0x9a, 0x9f} },
12101 {10, {0x00, 0x05, 0x08, 0x11, 0x18, 0x19, 0x1c, 0x1f, 0x60, 0x60, /*7870*/
12102 0x62, 0x66, 0x80, 0x8e, 0x90, 0x95, 0x97, 0x97, 0x9a, 0x9f} },
12103 {10, {0x00, 0x05, 0x08, 0x11, 0x18, 0x1a, 0x1c, 0x1f, 0x60, 0x60, /*7880*/
12104 0x62, 0x66, 0x80, 0x8e, 0x90, 0x95, 0x97, 0x97, 0x9a, 0x9f} },
12105 {16, {0x00, 0x05, 0x08, 0x11, 0x18, 0x1f, 0x60, 0x60, 0x62, 0x66, /*7890*/
12106 0x84, 0x8e, 0x90, 0x95, 0x97, 0x97, 0x9a, 0x9a, 0x9f, 0x9f,
12107 0xe0, 0xf1, 0xf4, 0xf4, 0xf6, 0xf6, 0xf8, 0xf8, 0xfa, 0xfc,
12109 {12, {0x00, 0x05, 0x08, 0x11, 0x18, 0x19, 0x1b, 0x1f, 0x60, 0x60, /*7895*/
12110 0x62, 0x66, 0x80, 0x8e, 0x90, 0x95, 0x97, 0x97, 0x9a, 0x9a,
12111 0x9f, 0x9f, 0xe0, 0xf1} },
12112 {16, {0x00, 0x05, 0x08, 0x11, 0x18, 0x1f, 0x60, 0x60, 0x62, 0x66, /*7896*/
12113 0x84, 0x8e, 0x90, 0x95, 0x97, 0x97, 0x9a, 0x9a, 0x9f, 0x9f,
12114 0xe0, 0xf1, 0xf4, 0xf4, 0xf6, 0xf6, 0xf8, 0xf8, 0xfa, 0xfc,
12116 {12, {0x00, 0x05, 0x08, 0x11, 0x18, 0x1f, 0x60, 0x60, 0x62, 0x66, /*7892*/
12117 0x84, 0x8e, 0x90, 0x95, 0x97, 0x97, 0x9a, 0x9a, 0x9c, 0x9f,
12118 0xe0, 0xf1, 0xf4, 0xfc} },
12119 {12, {0x00, 0x05, 0x08, 0x11, 0x18, 0x1f, 0x60, 0x60, 0x62, 0x66, /*7899*/
12120 0x84, 0x8e, 0x90, 0x95, 0x97, 0x97, 0x9a, 0x9a, 0x9c, 0x9f,
12121 0xe0, 0xf1, 0xf4, 0xfc} },
12123 chip
= p
->chip
& AHC_CHIPID_MASK
;
12125 board_names
[p
->board_name_index
]);
12126 switch(p
->chip
& ~AHC_CHIPID_MASK
)
12129 printk("VLB Slot %d.\n", p
->pci_device_fn
);
12132 printk("EISA Slot %d.\n", p
->pci_device_fn
);
12136 printk("PCI %d/%d/%d.\n", p
->pci_bus
, PCI_SLOT(p
->pci_device_fn
),
12137 PCI_FUNC(p
->pci_device_fn
));
12142 * the registers on the card....
12144 printk("Card Dump:\n");
12146 for(i
=0; i
<cards_ds
[chip
].num_ranges
; i
++)
12148 for(j
= cards_ds
[chip
].range_val
[ i
* 2 ];
12149 j
<= cards_ds
[chip
].range_val
[ i
* 2 + 1 ] ;
12152 printk("%02x:%02x ", j
, aic_inb(p
, j
));
12164 * If this was an Ultra2 controller, then we just hosed the card in terms
12165 * of the QUEUE REGS. This function is only called at init time or by
12166 * the panic_abort function, so it's safe to assume a generic init time
12170 if(p
->features
& AHC_QUEUE_REGS
)
12172 aic_outb(p
, 0, SDSCB_QOFF
);
12173 aic_outb(p
, 0, SNSCB_QOFF
);
12174 aic_outb(p
, 0, HNSCB_QOFF
);
12179 /*+F*************************************************************************
12181 * aic7xxx_print_scratch_ram
12184 * Print out the scratch RAM values on the card.
12185 *-F*************************************************************************/
12187 aic7xxx_print_scratch_ram(struct aic7xxx_host
*p
)
12192 printk("Scratch RAM:\n");
12193 for(i
= SRAM_BASE
; i
< SEQCTL
; i
++)
12195 printk("%02x:%02x ", i
, aic_inb(p
, i
));
12202 if (p
->features
& AHC_MORE_SRAM
)
12204 for(i
= TARG_OFFSET
; i
< 0x80; i
++)
12206 printk("%02x:%02x ", i
, aic_inb(p
, i
));
12218 #include "aic7xxx_proc.c"
12220 /* Eventually this will go into an include file, but this will be later */
12221 static Scsi_Host_Template driver_template
= AIC7XXX
;
12223 #include "scsi_module.c"
12226 * Overrides for Emacs so that we almost follow Linus's tabbing style.
12227 * Emacs will notice this stuff at the end of the file and automatically
12228 * adjust the settings for this buffer only. This must remain at the end
12230 * ---------------------------------------------------------------------------
12232 * c-indent-level: 2
12233 * c-brace-imaginary-offset: 0
12234 * c-brace-offset: -2
12235 * c-argdecl-indent: 2
12236 * c-label-offset: -2
12237 * c-continued-statement-offset: 2
12238 * c-continued-brace-offset: 0
12239 * indent-tabs-mode: nil