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-1998 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_FAKE_NEGOTIATION_CMDS
175 * We now have two distinctly different methods of device negotiation
176 * in this code. The two methods are selected by either defining or not
177 * defining this option. The difference is as follows:
179 * With AIC7XXX_FAKE_NEGOTIATION_CMDS not set (commented out)
180 * When the driver is in need of issuing a negotiation command for any
181 * given device, it will add the negotiation message on to part of a
182 * regular SCSI command for the device. In the process, if the device
183 * is configured for and using tagged queueing, then the code will
184 * also issue that single command as a non-tagged command, attach the
185 * negotiation message to that one command, and use a temporary
186 * queue depth of one to keep the untagged and tagged commands from
188 * Pros: This doesn't use any extra SCB structures, it's simple, it
189 * works most of the time (if not all of the time now), and
190 * since we get the device capability info frmo the INQUIRY data
191 * now, shouldn't cause any problems.
192 * Cons: When we need to send a negotiation command to a device, we
193 * must use a command that is being sent to LUN 0 of the device.
194 * If we try sending one to high LUN numbers, then some devices
195 * get noticeably upset. Since we have to wait for a command with
196 * LUN == 0 to come along, we may not be able to renegotiate when
197 * we want if the user is actually using say LUN 1 of a CD Changer
198 * instead of using LUN 0 for an extended period of time.
200 * With AIC7XXX_FAKE_NEGOTIATION_CMDS defined
201 * When we need to negotiate with a device, instead of attaching our
202 * negotiation message to an existing command, we insert our own
203 * fictional Scsi_Cmnd into the chain that has the negotiation message
204 * attached to it. We send this one command as untagged regardless
205 * of the device type, and we fiddle with the queue depth the same as
206 * we would with the option unset to avoid overlapping commands. The
207 * primary difference between this and the unset option is that the
208 * negotiation message is no longer attached to a specific command,
209 * instead it is its own command and is merely triggered by a
210 * combination of both A) We need to negotiate and B) The mid level
211 * SCSI code has sent us a command. We still don't do any negotiation
212 * unless there is a valid SCSI command to be processed.
213 * Pros: This fixes the problem above in the Cons section. Since we
214 * issue our own fake command, we can set the LUN to 0 regardless
215 * of what the LUN is in the real command. It also means that if
216 * the device get's nasty over negotiation issues, it won't be
217 * showing up on a regular command, so we won't get any SENSE buffer
218 * data or STATUS_BYTE returns to the mid level code that are caused
219 * by snits in the negotiation code.
220 * Cons: We add more code, and more complexity. This means more ways
221 * in which things could break. It means a larger driver. It means
222 * more resource consumption for the fake commands. However, the
223 * biggest problem is this. Take a system where there is a CD-ROM
224 * on the SCSI bus. Someone has a CD in the CD-ROM and is using it.
225 * For some reason the SCSI bus gets reset. We don't touch the
226 * CD-ROM again for quite a period of time (so we don't renegotiate
227 * after the reset until we do touch the CD-ROM again). In the
228 * time while we aren't using the CD-ROM, the current disc is
229 * removed and a new one put in. When we go to check that disc, we
230 * will first have to renegotiate. In so doing, we issue our fake
231 * SCSI command, which happens to be TEST_UNIT_READY. The CD-ROM
232 * negotiates with us, then responds to our fake command with a
233 * CHECK_CONDITION status. We REQUEST_SENSE from the CD-ROM, it
234 * then sends the SENSE data to our fake command to tell it that
235 * it has been through a disc change. There, now we've cleared out
236 * the SENSE data along with our negotiation command, and when the
237 * real command executes, it won't pick up that the CD was changed.
238 * That's the biggest Con to this approach. In the future, I could
239 * probably code around this problem though, so this option is still
242 * So, which command style should you use? I would appreciate it if people
243 * could try out both types. I want to know about any cases where one
244 * method works and the other doesn't. If one method works on significantly
245 * more systems than another, then it will become the default. If the second
246 * option turns out to work best, then I'll find a way to work around that
250 * OK...I just added some code that should make the Con listed for the
251 * fake commands a non issue now. However, it needs testing. For now,
252 * I'm going to make the default to use the fake commands, we'll see how
256 #define AIC7XXX_FAKE_NEGOTIATION_CMDS
259 * AIC7XXX_STRICT_PCI_SETUP
260 * Should we assume the PCI config options on our controllers are set with
261 * sane and proper values, or should we be anal about our PCI config
262 * registers and force them to what we want? The main advantage to
263 * defining this option is on non-Intel hardware where the BIOS may not
264 * have been run to set things up, or if you have one of the BIOSless
265 * Adaptec controllers, such as a 2910, that don't get set up by the
266 * BIOS. However, keep in mind that we really do set the most important
267 * items in the driver regardless of this setting, this only controls some
268 * of the more esoteric PCI options on these cards. In that sense, I
269 * would default to leaving this off. However, if people wish to try
270 * things both ways, that would also help me to know if there are some
271 * machines where it works one way but not another.
274 * OK...I need this on my machine for testing, so the default is to
278 * I needed it for testing, but it didn't make any difference, so back
282 * I turned it back on to try and compensate for the 2.1.x PCI code
283 * which no longer relies solely on the BIOS and now tries to set
287 #define AIC7XXX_STRICT_PCI_SETUP
290 * AIC7XXX_VERBOSE_DEBUGGING
291 * This option enables a lot of extra printk();s in the code, surrounded
292 * by if (aic7xxx_verbose ...) statements. Executing all of those if
293 * statements and the extra checks can get to where it actually does have
294 * an impact on CPU usage and such, as well as code size. Disabling this
295 * define will keep some of those from becoming part of the code.
297 * NOTE: Currently, this option has no real effect, I will be adding the
298 * various #ifdef's in the code later when I've decided a section is
299 * complete and no longer needs debugging. OK...a lot of things are now
300 * surrounded by this define, so turning this off does have an impact.
304 * #define AIC7XXX_VERBOSE_DEBUGGING
308 #include <linux/module.h>
314 #include <linux/version.h>
315 #include <linux/string.h>
316 #include <linux/errno.h>
317 #include <linux/kernel.h>
318 #include <linux/ioport.h>
319 #include <linux/delay.h>
320 #include <linux/sched.h>
321 #include <linux/pci.h>
322 #include <linux/proc_fs.h>
323 #include <linux/blk.h>
324 #include <linux/tqueue.h>
325 #include <linux/tasks.h>
331 #include "aic7xxx/sequencer.h"
332 #include "aic7xxx/scsi_message.h"
333 #include "aic7xxx_reg.h"
335 #include <linux/stat.h>
336 #include <linux/malloc.h> /* for kmalloc() */
338 #include <linux/config.h> /* for CONFIG_PCI */
341 * To generate the correct addresses for the controller to issue
342 * on the bus. Originally added for DEC Alpha support.
344 #define VIRT_TO_BUS(a) (unsigned int)virt_to_bus((void *)(a))
346 struct proc_dir_entry proc_scsi_aic7xxx
= {
347 PROC_SCSI_AIC7XXX
, 7, "aic7xxx",
348 S_IFDIR
| S_IRUGO
| S_IXUGO
, 2,
349 0, 0, 0, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
352 #define AIC7XXX_C_VERSION "5.1.3"
354 #define NUMBER(arr) (sizeof(arr) / sizeof(arr[0]))
355 #define MIN(a,b) (((a) < (b)) ? (a) : (b))
356 #define MAX(a,b) (((a) > (b)) ? (a) : (b))
357 #define ALL_TARGETS -1
358 #define ALL_CHANNELS -1
360 #define MAX_TARGETS 16
369 #ifndef KERNEL_VERSION
370 # define KERNEL_VERSION(x,y,z) (((x)<<16)+((y)<<8)+(z))
374 * We need the bios32.h file if we are kernel version 2.1.92 or less. The
375 * full set of pci_* changes wasn't in place until 2.1.93
378 #if LINUX_VERSION_CODE <= KERNEL_VERSION(2,1,92)
379 # if defined(__sparc_v9__) || defined(__powerpc__)
380 # error "PPC and Sparc platforms are only support under 2.1.92 and above"
382 # include <linux/bios32.h>
385 #if defined(__powerpc__)
391 __asm__ __volatile__("eieio" ::: "memory")
392 #elif defined(__i386__)
398 __asm__ __volatile__("lock ; addl $0,0(%%esp)": : :"memory")
399 #elif defined(__alpha__)
404 __asm__ __volatile__("mb": : :"memory")
407 #if LINUX_VERSION_CODE > KERNEL_VERSION(2,1,0)
408 # include <asm/spinlock.h>
409 # include <linux/smp.h>
410 # define cpuid smp_processor_id()
411 # if LINUX_VERSION_CODE < KERNEL_VERSION(2,1,95)
412 # define DRIVER_LOCK_INIT \
413 spin_lock_init(&p->spin_lock);
414 # define DRIVER_LOCK \
415 if(!p->cpu_lock_count[cpuid]) { \
416 spin_lock_irqsave(&p->spin_lock, cpu_flags); \
417 p->cpu_lock_count[cpuid]++; \
419 p->cpu_lock_count[cpuid]++; \
421 # define DRIVER_UNLOCK \
422 if(--p->cpu_lock_count[cpuid] == 0) \
423 spin_unlock_irqrestore(&p->spin_lock, cpu_flags);
425 # define DRIVER_LOCK_INIT
427 # define DRIVER_UNLOCK
431 # define DRIVER_LOCK_INIT
432 # define DRIVER_LOCK \
433 save_flags(cpu_flags); \
435 # define DRIVER_UNLOCK \
436 restore_flags(cpu_flags);
437 # define le32_to_cpu(x) (x)
438 # define cpu_to_le32(x) (x)
442 * You can try raising me if tagged queueing is enabled, or lowering
443 * me if you only have 4 SCBs.
445 #ifdef CONFIG_AIC7XXX_CMDS_PER_LUN
446 #define AIC7XXX_CMDS_PER_LUN CONFIG_AIC7XXX_CMDS_PER_LUN
449 /* Set this to the delay in seconds after SCSI bus reset. */
450 #ifdef CONFIG_AIC7XXX_RESET_DELAY
451 #define AIC7XXX_RESET_DELAY CONFIG_AIC7XXX_RESET_DELAY
453 #define AIC7XXX_RESET_DELAY 5
457 * Control collection of SCSI transfer statistics for the /proc filesystem.
459 * NOTE: Do NOT enable this when running on kernels version 1.2.x and below.
460 * NOTE: This does affect performance since it has to maintain statistics.
462 #ifdef CONFIG_AIC7XXX_PROC_STATS
463 #define AIC7XXX_PROC_STATS
467 * NOTE: Uncommenting the define below no longer has any effect, the
468 * tagged queue value array is always active now. I've added
469 * a setup option to set this particular array and I'm hoping
470 * insmod will be smart enough to set it properly as well. It's
471 * by use of this array that a person can enable tagged queueing.
472 * The DEFAULT_TAG_COMMANDS define has been changed to disable
473 * tagged queueing by default, so if your devices can handle tagged
474 * queueing you will need to add a line to their lilo.conf file like:
475 * append="aic7xxx=verbose,tag_info:{{32,32,32,32},{32,32,32,32}}"
476 * which will result in the first four devices on the first two
477 * controllers being set to a tagged queue depth of 32.
479 * Set this for defining the number of tagged commands on a device
480 * by device, and controller by controller basis. The first set
481 * of tagged commands will be used for the first detected aic7xxx
482 * controller, the second set will be used for the second detected
483 * aic7xxx controller, and so on. These values will *only* be used
484 * for targets that are tagged queueing capable; these values will
485 * be ignored in all other cases. The tag_commands is an array of
486 * 16 to allow for wide and twin adapters. Twin adapters will use
487 * indexes 0-7 for channel 0, and indexes 8-15 for channel 1.
489 * *** Determining commands per LUN ***
491 * When AIC7XXX_CMDS_PER_LUN is not defined, the driver will use its
492 * own algorithm to determine the commands/LUN. If SCB paging is
493 * enabled, which is always now, the default is 8 commands per lun
494 * that indicates it supports tagged queueing. All non-tagged devices
495 * use an internal queue depth of 3, with no more than one of those
496 * three commands active at one time.
498 /* #define AIC7XXX_TAGGED_QUEUEING_BY_DEVICE */
502 unsigned char tag_commands
[16]; /* Allow for wide/twin adapters. */
503 } adapter_tag_info_t
;
506 * Make a define that will tell the driver not to use tagged queueing
509 #define DEFAULT_TAG_COMMANDS {255, 255, 255, 255, 255, 255, 255, 255,\
510 255, 255, 255, 255, 255, 255, 255, 255}
513 * Modify this as you see fit for your system. By setting tag_commands
514 * to 0, the driver will use it's own algorithm for determining the
515 * number of commands to use (see above). When 255, the driver will
516 * not enable tagged queueing for that particular device. When positive
517 * (> 0) and (< 255) the values in the array are used for the queue_depth.
518 * Note that the maximum value for an entry is 254, but you're insane if
519 * you try to use that many commands on one device.
521 * In this example, the first line will disable tagged queueing for all
522 * the devices on the first probed aic7xxx adapter.
524 * The second line enables tagged queueing with 4 commands/LUN for IDs
525 * (1, 2-11, 13-15), disables tagged queueing for ID 12, and tells the
526 * driver to use its own algorithm for ID 1.
528 * The third line is the same as the first line.
530 * The fourth line disables tagged queueing for devices 0 and 3. It
531 * enables tagged queueing for the other IDs, with 16 commands/LUN
532 * for IDs 1 and 4, 127 commands/LUN for ID 8, and 4 commands/LUN for
533 * IDs 2, 5-7, and 9-15.
537 * NOTE: The below structure is for reference only, the actual structure
538 * to modify in order to change things is located around line
540 adapter_tag_info_t aic7xxx_tag_info[] =
542 {DEFAULT_TAG_COMMANDS},
543 {{4, 0, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 255, 4, 4, 4}},
544 {DEFAULT_TAG_COMMANDS},
545 {{255, 16, 4, 255, 16, 4, 4, 4, 127, 4, 4, 4, 4, 4, 4, 4}}
550 * Define an array of board names that can be indexed by aha_type.
551 * Don't forget to change this when changing the types!
553 static const char *board_names
[] = {
554 "AIC-7xxx Unknown", /* AIC_NONE */
555 "Adaptec AIC-7810 Hardware RAID Controller", /* AIC_7810 */
556 "Adaptec AIC-7770 SCSI host adapter", /* AIC_7770 */
557 "Adaptec AHA-274X SCSI host adapter", /* AIC_7771 */
558 "Adaptec AHA-284X SCSI host adapter", /* AIC_284x */
559 "Adaptec AIC-7850 SCSI host adapter", /* AIC_7850 */
560 "Adaptec AIC-7855 SCSI host adapter", /* AIC_7855 */
561 "Adaptec AIC-7860 Ultra SCSI host adapter", /* AIC_7860 */
562 "Adaptec AHA-2940A Ultra SCSI host adapter", /* AIC_7861 */
563 "Adaptec AIC-7870 SCSI host adapter", /* AIC_7870 */
564 "Adaptec AHA-294X SCSI host adapter", /* AIC_7871 */
565 "Adaptec AHA-394X SCSI host adapter", /* AIC_7872 */
566 "Adaptec AHA-398X SCSI host adapter", /* AIC_7873 */
567 "Adaptec AHA-2944 SCSI host adapter", /* AIC_7874 */
568 "Adaptec AIC-7880 Ultra SCSI host adapter", /* AIC_7880 */
569 "Adaptec AHA-294X Ultra SCSI host adapter", /* AIC_7881 */
570 "Adaptec AHA-394X Ultra SCSI host adapter", /* AIC_7882 */
571 "Adaptec AHA-398X Ultra SCSI host adapter", /* AIC_7883 */
572 "Adaptec AHA-2944 Ultra SCSI host adapter", /* AIC_7884 */
573 "Adaptec AIC-7895 Ultra SCSI host adapter", /* AIC_7895 */
574 "Adaptec AIC-7890/1 Ultra2 SCSI host adapter", /* AIC_7890 */
575 "Adaptec AHA-294X Ultra2 SCSI host adapter", /* AIC_7890 */
576 "Adaptec AIC-7896/7 Ultra2 SCSI host adapter", /* AIC_7896 */
577 "Adaptec AHA-394X Ultra2 SCSI host adapter" /* AIC_7897 */
581 * There should be a specific return value for this in scsi.h, but
582 * it seems that most drivers ignore it.
584 #define DID_UNDERFLOW DID_ERROR
587 * What we want to do is have the higher level scsi driver requeue
588 * the command to us. There is no specific driver status for this
589 * condition, but the higher level scsi driver will requeue the
590 * command on a DID_BUS_BUSY error.
592 * Upon further inspection and testing, it seems that DID_BUS_BUSY
593 * will *always* retry the command. We can get into an infinite loop
594 * if this happens when we really want some sort of counter that
595 * will automatically abort/reset the command after so many retries.
596 * Using DID_ERROR will do just that. (Made by a suggestion by
597 * Doug Ledford 8/1/96)
599 #define DID_RETRY_COMMAND DID_ERROR
602 #define SCSI_RESET 0x040
609 #define SLOTBASE(x) ((x) << 12)
610 #define BASE_TO_SLOT(x) ((x) >> 12)
613 * Standard EISA Host ID regs (Offset from slot base)
615 #define AHC_HID0 0x80 /* 0,1: msb of ID2, 2-7: ID1 */
616 #define AHC_HID1 0x81 /* 0-4: ID3, 5-7: LSB ID2 */
617 #define AHC_HID2 0x82 /* product */
618 #define AHC_HID3 0x83 /* firmware revision */
621 * AIC-7770 I/O range to reserve for a card
626 #define INTDEF 0x5C /* Interrupt Definition Register */
629 * AIC-78X0 PCI registers
631 #define CLASS_PROGIF_REVID 0x08
632 #define DEVREVID 0x000000FFul
633 #define PROGINFC 0x0000FF00ul
634 #define SUBCLASS 0x00FF0000ul
635 #define BASECLASS 0xFF000000ul
637 #define CSIZE_LATTIME 0x0C
638 #define CACHESIZE 0x0000003Ful /* only 5 bits */
639 #define LATTIME 0x0000FF00ul
641 #define DEVCONFIG 0x40
642 #define SCBSIZE32 0x00010000ul /* aic789X only */
643 #define MPORTMODE 0x00000400ul /* aic7870 only */
644 #define RAMPSM 0x00000200ul /* aic7870 only */
645 #define RAMPSM_ULTRA2 0x00000004
646 #define VOLSENSE 0x00000100ul
647 #define SCBRAMSEL 0x00000080ul
648 #define SCBRAMSEL_ULTRA2 0x00000008
649 #define MRDCEN 0x00000040ul
650 #define EXTSCBTIME 0x00000020ul /* aic7870 only */
651 #define EXTSCBPEN 0x00000010ul /* aic7870 only */
652 #define BERREN 0x00000008ul
653 #define DACEN 0x00000004ul
654 #define STPWLEVEL 0x00000002ul
655 #define DIFACTNEGEN 0x00000001ul /* aic7870 only */
657 #define SCAMCTL 0x1a /* Ultra2 only */
658 #define CCSCBBADDR 0xf0 /* aic7895/6/7 */
661 * Define the different types of SEEPROMs on aic7xxx adapters
662 * and make it also represent the address size used in accessing
663 * its registers. The 93C46 chips have 1024 bits organized into
664 * 64 16-bit words, while the 93C56 chips have 2048 bits organized
665 * into 128 16-bit words. The C46 chips use 6 bits to address
666 * each word, while the C56 and C66 (4096 bits) use 8 bits to
669 typedef enum {C46
= 6, C56_66
= 8} seeprom_chip_type
;
673 * Define the format of the SEEPROM registers (16 bits).
676 struct seeprom_config
{
679 * SCSI ID Configuration Flags
681 #define CFXFER 0x0007 /* synchronous transfer rate */
682 #define CFSYNCH 0x0008 /* enable synchronous transfer */
683 #define CFDISC 0x0010 /* enable disconnection */
684 #define CFWIDEB 0x0020 /* wide bus device (wide card) */
685 #define CFSYNCHISULTRA 0x0040 /* CFSYNC is an ultra offset */
687 #define CFSTART 0x0100 /* send start unit SCSI command */
688 #define CFINCBIOS 0x0200 /* include in BIOS scan */
689 #define CFRNFOUND 0x0400 /* report even if not found */
690 #define CFMULTILUN 0x0800 /* probe mult luns in BIOS scan */
692 unsigned short device_flags
[16]; /* words 0-15 */
697 #define CFSUPREM 0x0001 /* support all removable drives */
698 #define CFSUPREMB 0x0002 /* support removable drives for boot only */
699 #define CFBIOSEN 0x0004 /* BIOS enabled */
701 #define CFSM2DRV 0x0010 /* support more than two drives */
702 #define CF284XEXTEND 0x0020 /* extended translation (284x cards) */
704 #define CFEXTEND 0x0080 /* extended translation enabled */
706 unsigned short bios_control
; /* word 16 */
709 * Host Adapter Control Bits
711 #define CFAUTOTERM 0x0001 /* Perform Auto termination */
712 #define CFULTRAEN 0x0002 /* Ultra SCSI speed enable (Ultra cards) */
713 #define CF284XSELTO 0x0003 /* Selection timeout (284x cards) */
714 #define CF284XFIFO 0x000C /* FIFO Threshold (284x cards) */
715 #define CFSTERM 0x0004 /* SCSI low byte termination */
716 #define CFWSTERM 0x0008 /* SCSI high byte termination (wide card) */
717 #define CFSPARITY 0x0010 /* SCSI parity */
718 #define CF284XSTERM 0x0020 /* SCSI low byte termination (284x cards) */
719 #define CFRESETB 0x0040 /* reset SCSI bus at boot */
720 #define CFBPRIMARY 0x0100 /* Channel B primary on 7895 chipsets */
721 #define CFSEAUTOTERM 0x0400 /* aic7890 Perform SE Auto Term */
722 #define CFLVDSTERM 0x0800 /* aic7890 LVD Termination */
724 unsigned short adapter_control
; /* word 17 */
727 * Bus Release, Host Adapter ID
729 #define CFSCSIID 0x000F /* host adapter SCSI ID */
731 #define CFBRTIME 0xFF00 /* bus release time */
732 unsigned short brtime_id
; /* word 18 */
737 #define CFMAXTARG 0x00FF /* maximum targets */
739 unsigned short max_targets
; /* word 19 */
741 unsigned short res_1
[11]; /* words 20-30 */
742 unsigned short checksum
; /* word 31 */
745 #define SELBUS_MASK 0x0a
746 #define SELNARROW 0x00
748 #define SINGLE_BUS 0x00
750 #define SCB_TARGET(scb) \
751 (((scb)->hscb->target_channel_lun & TID) >> 4)
752 #define SCB_LUN(scb) \
753 ((scb)->hscb->target_channel_lun & LID)
754 #define SCB_IS_SCSIBUS_B(scb) \
755 (((scb)->hscb->target_channel_lun & SELBUSB) != 0)
758 * If an error occurs during a data transfer phase, run the command
759 * to completion - it's easier that way - making a note of the error
760 * condition in this location. This then will modify a DID_OK status
761 * into an appropriate error for the higher-level SCSI code.
763 #define aic7xxx_error(cmd) ((cmd)->SCp.Status)
766 * Keep track of the targets returned status.
768 #define aic7xxx_status(cmd) ((cmd)->SCp.sent_command)
771 * The position of the SCSI commands scb within the scb array.
773 #define aic7xxx_position(cmd) ((cmd)->SCp.have_data_in)
776 * So we can keep track of our host structs
778 static struct aic7xxx_host
*first_aic7xxx
= NULL
;
781 * As of Linux 2.1, the mid-level SCSI code uses virtual addresses
782 * in the scatter-gather lists. We need to convert the virtual
783 * addresses to physical addresses.
785 struct hw_scatterlist
{
786 unsigned int address
;
791 * Maximum number of SG segments these cards can support.
793 #define AIC7XXX_MAX_SG 128
796 * The maximum number of SCBs we could have for ANY type
797 * of card. DON'T FORGET TO CHANGE THE SCB MASK IN THE
798 * SEQUENCER CODE IF THIS IS MODIFIED!
800 #define AIC7XXX_MAXSCB 255
803 struct aic7xxx_hwscb
{
804 /* ------------ Begin hardware supported fields ---------------- */
805 /* 0*/ unsigned char control
;
806 /* 1*/ unsigned char target_channel_lun
; /* 4/1/3 bits */
807 /* 2*/ unsigned char target_status
;
808 /* 3*/ unsigned char SG_segment_count
;
809 /* 4*/ unsigned int SG_list_pointer
;
810 /* 8*/ unsigned char residual_SG_segment_count
;
811 /* 9*/ unsigned char residual_data_count
[3];
812 /*12*/ unsigned int data_pointer
;
813 /*16*/ unsigned int data_count
;
814 /*20*/ unsigned int SCSI_cmd_pointer
;
815 /*24*/ unsigned char SCSI_cmd_length
;
816 /*25*/ unsigned char tag
; /* Index into our kernel SCB array.
817 * Also used as the tag for tagged I/O
819 #define SCB_PIO_TRANSFER_SIZE 26 /* amount we need to upload/download
820 * via PIO to initialize a transaction.
822 /*26*/ unsigned char next
; /* Used to thread SCBs awaiting selection
823 * or disconnected down in the sequencer.
825 /*27*/ unsigned char prev
;
826 /*28*/ unsigned int pad
; /*
827 * Unused by the kernel, but we require
828 * the padding so that the array of
829 * hardware SCBs is alligned on 32 byte
830 * boundaries so the sequencer can index
836 SCB_WAITINGQ
= 0x0002,
840 SCB_DEVICE_RESET
= 0x0020,
842 SCB_RECOVERY_SCB
= 0x0080,
843 SCB_WAS_BUSY
= 0x0100,
844 SCB_MSGOUT_SENT
= 0x0200,
845 SCB_MSGOUT_SDTR
= 0x0400,
846 SCB_MSGOUT_WDTR
= 0x0800,
847 SCB_MSGOUT_BITS
= SCB_MSGOUT_SENT
|
850 SCB_QUEUED_ABORT
= 0x1000,
851 SCB_QUEUED_FOR_DONE
= 0x2000
855 AHC_FNONE
= 0x00000000,
856 AHC_PAGESCBS
= 0x00000001,
857 AHC_CHANNEL_B_PRIMARY
= 0x00000002,
858 AHC_USEDEFAULTS
= 0x00000004,
859 AHC_INDIRECT_PAGING
= 0x00000008,
860 AHC_CHNLB
= 0x00000020,
861 AHC_CHNLC
= 0x00000040,
862 AHC_EXTEND_TRANS_A
= 0x00000100,
863 AHC_EXTEND_TRANS_B
= 0x00000200,
864 AHC_TERM_ENB_A
= 0x00000400,
865 AHC_TERM_ENB_SE_LOW
= 0x00000400,
866 AHC_TERM_ENB_B
= 0x00000800,
867 AHC_TERM_ENB_SE_HIGH
= 0x00000800,
868 AHC_HANDLING_REQINITS
= 0x00001000,
869 AHC_TARGETMODE
= 0x00002000,
870 AHC_NEWEEPROM_FMT
= 0x00004000,
872 * Here ends the FreeBSD defined flags and here begins the linux defined
873 * flags. NOTE: I did not preserve the old flag name during this change
874 * specifically to force me to evaluate what flags were being used properly
875 * and what flags weren't. This way, I could clean up the flag usage on
876 * a use by use basis. Doug Ledford
878 AHC_A_SCANNED
= 0x00100000,
879 AHC_B_SCANNED
= 0x00200000,
880 AHC_MULTI_CHANNEL
= 0x00400000,
881 AHC_BIOS_ENABLED
= 0x00800000,
882 AHC_SEEPROM_FOUND
= 0x01000000,
883 AHC_TERM_ENB_LVD
= 0x02000000,
884 AHC_ABORT_PENDING
= 0x04000000,
885 AHC_RESET_PENDING
= 0x08000000,
886 #define AHC_IN_ISR_BIT 28
887 AHC_IN_ISR
= 0x10000000,
888 AHC_IN_ABORT
= 0x20000000,
889 AHC_IN_RESET
= 0x40000000,
890 AHC_EXTERNAL_SRAM
= 0x80000000
895 AHC_CHIPID_MASK
= 0x00ff,
896 AHC_AIC7770
= 0x0001,
897 AHC_AIC7850
= 0x0002,
898 AHC_AIC7860
= 0x0003,
899 AHC_AIC7870
= 0x0004,
900 AHC_AIC7880
= 0x0005,
901 AHC_AIC7890
= 0x0006,
902 AHC_AIC7895
= 0x0007,
903 AHC_AIC7896
= 0x0008,
915 AHC_MORE_SRAM
= 0x0010,
916 AHC_CMD_CHAN
= 0x0020,
917 AHC_QUEUE_REGS
= 0x0040,
918 AHC_SG_PRELOAD
= 0x0080,
919 AHC_SPIOCAP
= 0x0100,
920 AHC_AIC7770_FE
= AHC_FENONE
,
921 AHC_AIC7850_FE
= AHC_SPIOCAP
,
922 AHC_AIC7860_FE
= AHC_ULTRA
|AHC_SPIOCAP
,
923 AHC_AIC7870_FE
= AHC_FENONE
,
924 AHC_AIC7880_FE
= AHC_ULTRA
,
925 AHC_AIC7890_FE
= AHC_MORE_SRAM
|AHC_CMD_CHAN
|AHC_ULTRA2
|
926 AHC_QUEUE_REGS
|AHC_SG_PRELOAD
,
927 AHC_AIC7895_FE
= AHC_MORE_SRAM
|AHC_CMD_CHAN
|AHC_ULTRA
,
928 AHC_AIC7896_FE
= AHC_AIC7890_FE
,
932 struct aic7xxx_hwscb
*hscb
; /* corresponding hardware scb */
933 Scsi_Cmnd
*cmd
; /* Scsi_Cmnd for this scb */
934 struct aic7xxx_scb
*q_next
; /* next scb in queue */
935 volatile scb_flag_type flags
; /* current state of scb */
936 struct hw_scatterlist
*sg_list
; /* SG list in adapter format */
938 unsigned char tag_action
;
939 unsigned char sg_count
;
940 unsigned char sense_cmd
[6]; /*
941 * Allocate 6 characters for
944 unsigned int sg_length
; /* We init this during buildscb so we
945 * don't have to calculate anything
946 * during underflow/overflow/stat code
951 * Define a linked list of SCBs.
954 struct aic7xxx_scb
*head
;
955 struct aic7xxx_scb
*tail
;
962 { ILLHADDR
, "Illegal Host Access" },
963 { ILLSADDR
, "Illegal Sequencer Address referenced" },
964 { ILLOPCODE
, "Illegal Opcode in sequencer program" },
965 { SQPARERR
, "Sequencer Ram Parity Error" },
966 { DPARERR
, "Data-Path Ram Parity Error" },
967 { MPARERR
, "Scratch Ram/SCB Array Ram Parity Error" },
968 { PCIERRSTAT
,"PCI Error detected" },
969 { CIOPARERR
, "CIOBUS Parity Error" }
973 generic_sense
[] = { REQUEST_SENSE
, 0, 0, 0, 255, 0 };
976 scb_queue_type free_scbs
; /*
977 * SCBs assigned to free slot on
978 * card (no paging required)
980 struct aic7xxx_scb
*scb_array
[AIC7XXX_MAXSCB
];
981 struct aic7xxx_hwscb
*hscbs
;
982 unsigned char numscbs
; /* current number of scbs */
983 unsigned char maxhscbs
; /* hardware scbs */
984 unsigned char maxscbs
; /* max scbs including pageable scbs */
985 void *hscb_kmalloc_ptr
;
989 unsigned char mesg_bytes
[4];
990 unsigned char command
[28];
993 #define AHC_TRANS_CUR 0x0001
994 #define AHC_TRANS_ACTIVE 0x0002
995 #define AHC_TRANS_GOAL 0x0004
996 #define AHC_TRANS_USER 0x0008
997 #define AHC_TRANS_QUITE 0x0010
999 unsigned char cur_width
;
1000 unsigned char goal_width
;
1001 unsigned char cur_period
;
1002 unsigned char goal_period
;
1003 unsigned char cur_offset
;
1004 unsigned char goal_offset
;
1005 unsigned char user_width
;
1006 unsigned char user_period
;
1007 unsigned char user_offset
;
1011 * Define a structure used for each host adapter. Note, in order to avoid
1012 * problems with architectures I can't test on (because I don't have one,
1013 * such as the Alpha based systems) which happen to give faults for
1014 * non-aligned memory accesses, care was taken to align this structure
1015 * in a way that gauranteed all accesses larger than 8 bits were aligned
1016 * on the appropriate boundary. It's also organized to try and be more
1017 * cache line efficient. Be careful when changing this lest you might hurt
1018 * overall performance and bring down the wrath of the masses.
1020 struct aic7xxx_host
{
1022 * This is the first 64 bytes in the host struct
1025 struct Scsi_Host
*host
; /* pointer to scsi host */
1026 struct aic7xxx_host
*next
; /* allow for multiple IRQs */
1027 int host_no
; /* SCSI host number */
1028 unsigned long base
; /* card base address */
1029 volatile unsigned char *maddr
; /* memory mapped address */
1030 unsigned long mbase
; /* I/O memory address */
1031 volatile ahc_flag_type flags
;
1032 #if LINUX_VERSION_CODE > KERNEL_VERSION(2,1,0)
1033 spinlock_t spin_lock
;
1035 volatile unsigned char cpu_lock_count
[NR_CPUS
];
1036 ahc_chip chip
; /* chip type */
1037 ahc_feature features
; /* chip features */
1038 unsigned long last_reset
;
1039 unsigned long isr_count
; /* Interrupt count */
1040 unsigned long spurious_int
;
1041 struct target_cmd
*targetcmds
;
1042 unsigned int num_targetcmds
;
1043 unsigned short discenable
; /* Targets allowed to disconnect */
1044 unsigned short tagenable
; /* Targets using tagged I/O */
1045 unsigned short orderedtag
; /* Ordered Q tags allowed */
1046 volatile unsigned char activescbs
; /* active scbs */
1047 volatile unsigned char max_activescbs
;
1048 unsigned char unpause
; /* unpause value for HCNTRL */
1049 unsigned char pause
; /* pause value for HCNTRL */
1050 volatile unsigned char qoutfifonext
;
1051 volatile unsigned char qinfifonext
;
1054 * MAX_TARGETS is currently == 16, so that makes these entries the next
1058 #define DEVICE_PRESENT 0x01
1059 #define BUS_DEVICE_RESET_PENDING 0x02
1060 #define DEVICE_TIMEOUT 0x04
1061 #define DEVICE_PRINT_SDTR 0x08
1062 #define DEVICE_PRINT_WDTR 0x10
1063 #define DEVICE_SUCCESS 0x20
1064 #define DEVICE_TAGGED_SUCCESS 0x40
1065 #define DEVICE_SCANNED 0x80
1066 volatile unsigned char dev_flags
[MAX_TARGETS
];
1067 volatile unsigned char dev_active_cmds
[MAX_TARGETS
];
1068 volatile unsigned char dev_temp_queue_depth
[MAX_TARGETS
];
1069 unsigned char dev_commands_sent
[MAX_TARGETS
];
1072 * The next 128 (or 256 on 64 bit machines)....
1074 Scsi_Cmnd
*dev_wdtr_cmnd
[MAX_TARGETS
];
1075 Scsi_Cmnd
*dev_sdtr_cmnd
[MAX_TARGETS
];
1081 long dev_last_reset
[MAX_TARGETS
];
1087 unsigned char dev_mid_level_queue_depth
[MAX_TARGETS
];
1088 unsigned char dev_last_queue_full
[MAX_TARGETS
];
1089 unsigned char dev_last_queue_full_count
[MAX_TARGETS
];
1090 unsigned char dev_max_queue_depth
[MAX_TARGETS
];
1096 volatile scb_queue_type delayed_scbs
[MAX_TARGETS
];
1102 struct timer_list dev_timer
[MAX_TARGETS
];
1108 unsigned char msg_buf
[9]; /* The message for the target */
1109 unsigned char msg_type
;
1110 #define MSG_TYPE_NONE 0x00
1111 #define MSG_TYPE_INITIATOR_MSGOUT 0x01
1112 #define MSG_TYPE_INITIATOR_MSGIN 0x02
1113 unsigned char msg_len
; /* Length of message */
1114 unsigned char msg_index
; /* Index into msg_buf array */
1115 transinfo_type transinfo
[MAX_TARGETS
];
1116 volatile scb_queue_type waiting_scbs
; /*
1117 * SCBs waiting for space in
1120 scb_data_type
*scb_data
;
1122 struct aic7xxx_cmd_queue
{
1129 * We put the less frequently used host structure items after the more
1130 * frequently used items to try and ease the burden on the cache subsystem.
1131 * These entries are not *commonly* accessed, whereas the preceding entries
1132 * are accessed very often. The only exceptions are the qinfifo, qoutfifo,
1133 * and untagged_scbs array. But, they are often accessed only once and each
1134 * access into these arrays is likely to blow a cache line, so they are put
1135 * down here so we can minimize the number of cache lines required to hold
1136 * the preceeding entries.
1139 volatile unsigned char untagged_scbs
[256];
1140 volatile unsigned char qoutfifo
[256];
1141 volatile unsigned char qinfifo
[256];
1142 unsigned int irq
; /* IRQ for this adapter */
1143 volatile unsigned short needsdtr
;
1144 volatile unsigned short sdtr_pending
;
1145 volatile unsigned short needwdtr
;
1146 volatile unsigned short wdtr_pending
;
1147 int instance
; /* aic7xxx instance number */
1148 int scsi_id
; /* host adapter SCSI ID */
1149 int scsi_id_b
; /* channel B for twin adapters */
1150 unsigned int bios_address
;
1151 int board_name_index
;
1152 unsigned long reset_start
;
1153 unsigned short needsdtr_copy
; /* default config */
1154 unsigned short needwdtr_copy
; /* default config */
1155 unsigned short ultraenb
; /* Ultra mode target list */
1156 unsigned short bios_control
; /* bios control - SEEPROM */
1157 unsigned short adapter_control
; /* adapter control - SEEPROM */
1158 #if LINUX_VERSION_CODE > KERNEL_VERSION(2,1,92)
1159 struct pci_dev
*pdev
;
1161 unsigned char pci_bus
;
1162 unsigned char pci_device_fn
;
1163 struct seeprom_config sc
;
1164 unsigned short sc_type
;
1165 unsigned short sc_size
;
1170 * Total Xfers (count for each command that has a data xfer),
1171 * broken down further by reads && writes.
1173 * Binned sizes, writes && reads:
1174 * < 512, 512, 1-2K, 2-4K, 4-8K, 8-16K, 16-32K, 32-64K, 64K-128K, > 128K
1176 * Total amounts read/written above 512 bytes (amts under ignored)
1178 * NOTE: Enabling this feature is likely to cause a noticeable performance
1179 * decrease as the accesses into the stats structures blows apart multiple
1180 * cache lines and is CPU time consuming. We keep the xfer count always
1181 * for use by the aic7xxx_proc.c code, but only do the bins if the
1182 * proc stats code is enabled.
1184 struct aic7xxx_xferstats
{
1185 long xfers
; /* total xfer count */
1186 long w_total
; /* total writes */
1187 long w_total512
; /* 512 byte blocks written */
1188 long r_total
; /* total reads */
1189 long r_total512
; /* 512 byte blocks read */
1190 #ifdef AIC7XXX_PROC_STATS
1191 long w_bins
[10]; /* binned write */
1192 long r_bins
[10]; /* binned reads */
1193 #endif /* AIC7XXX_PROC_STATS */
1194 } stats
[MAX_TARGETS
][MAX_LUNS
]; /* [(channel << 3)|target][lun] */
1198 * Valid SCSIRATE values. (p. 3-17)
1199 * Provides a mapping of transfer periods in ns/4 to the proper value to
1200 * stick in the SCSIRATE reg to use that transfer rate.
1202 #define AHC_SYNCRATE_ULTRA2 0
1203 #define AHC_SYNCRATE_ULTRA 2
1204 #define AHC_SYNCRATE_FAST 5
1205 static struct aic7xxx_syncrate
{
1206 /* Rates in Ultra mode have bit 8 of sxfr set */
1207 #define ULTRA_SXFR 0x100
1210 unsigned char period
;
1211 const char *rate
[2];
1212 } aic7xxx_syncrates
[] = {
1213 { 0x13, 0x000, 10, {"40.0", "80.0"} },
1214 { 0x14, 0x000, 11, {"33.0", "66.6"} },
1215 { 0x15, 0x100, 12, {"20.0", "40.0"} },
1216 { 0x16, 0x110, 15, {"16.0", "32.0"} },
1217 { 0x17, 0x120, 18, {"13.4", "26.8"} },
1218 { 0x18, 0x000, 25, {"10.0", "20.0"} },
1219 { 0x19, 0x010, 31, {"8.0", "16.0"} },
1220 { 0x1a, 0x020, 37, {"6.67", "13.3"} },
1221 { 0x1b, 0x030, 43, {"5.7", "11.4"} },
1222 { 0x10, 0x040, 50, {"5.0", "10.0"} },
1223 { 0x00, 0x050, 56, {"4.4", "8.8" } },
1224 { 0x00, 0x060, 62, {"4.0", "8.0" } },
1225 { 0x00, 0x070, 68, {"3.6", "7.2" } },
1226 { 0x00, 0x000, 0, {NULL
, NULL
} },
1229 #define CTL_OF_SCB(scb) (((scb->hscb)->target_channel_lun >> 3) & 0x1), \
1230 (((scb->hscb)->target_channel_lun >> 4) & 0xf), \
1231 ((scb->hscb)->target_channel_lun & 0x07)
1233 #define CTL_OF_CMD(cmd) ((cmd->channel) & 0x01), \
1234 ((cmd->target) & 0x0f), \
1237 #define TARGET_INDEX(cmd) ((cmd)->target | ((cmd)->channel << 3))
1240 * A nice little define to make doing our printks a little easier
1243 #define WARN_LEAD KERN_WARNING "(scsi%d:%d:%d:%d) "
1244 #define INFO_LEAD KERN_INFO "(scsi%d:%d:%d:%d) "
1247 * XXX - these options apply unilaterally to _all_ 274x/284x/294x
1248 * cards in the system. This should be fixed. Exceptions to this
1249 * rule are noted in the comments.
1254 * Skip the scsi bus reset. Non 0 make us skip the reset at startup. This
1255 * has no effect on any later resets that might occur due to things like
1256 * SCSI bus timeouts.
1258 static unsigned int aic7xxx_no_reset
= 0;
1260 * Certain PCI motherboards will scan PCI devices from highest to lowest,
1261 * others scan from lowest to highest, and they tend to do all kinds of
1262 * strange things when they come into contact with PCI bridge chips. The
1263 * net result of all this is that the PCI card that is actually used to boot
1264 * the machine is very hard to detect. Most motherboards go from lowest
1265 * PCI slot number to highest, and the first SCSI controller found is the
1266 * one you boot from. The only exceptions to this are when a controller
1267 * has its BIOS disabled. So, we by default sort all of our SCSI controllers
1268 * from lowest PCI slot number to highest PCI slot number. We also force
1269 * all controllers with their BIOS disabled to the end of the list. This
1270 * works on *almost* all computers. Where it doesn't work, we have this
1271 * option. Setting this option to non-0 will reverse the order of the sort
1272 * to highest first, then lowest, but will still leave cards with their BIOS
1273 * disabled at the very end. That should fix everyone up unless there are
1274 * really strange cirumstances.
1276 static int aic7xxx_reverse_scan
= 0;
1278 * This setting enables a hack to fix the IRQ settings on buggy 7895
1279 * MB controller setups:
1280 * -1 == Disable this hack
1281 * 0 == Use the Channel A IRQ for both channels
1282 * 1 == Use the Channel B IRQ for both channels
1284 static unsigned int aic7xxx_extended
= 0;
1286 * The IRQ trigger method used on EISA controllers. Does not effect PCI cards.
1287 * -1 = Use detected settings.
1288 * 0 = Force Edge triggered mode.
1289 * 1 = Force Level triggered mode.
1291 static int aic7xxx_irq_trigger
= -1;
1293 * This variable is used to override the termination settings on a controller.
1294 * This should not be used under normal conditions. However, in the case
1295 * that a controller does not have a readable SEEPROM (so that we can't
1296 * read the SEEPROM settings directly) and that a controller has a buggered
1297 * version of the cable detection logic, this can be used to force the
1298 * correct termination. It is preferable to use the manual termination
1299 * settings in the BIOS if possible, but some motherboard controllers store
1300 * those settings in a format we can't read. In other cases, auto term
1301 * should also work, but the chipset was put together with no auto term
1302 * logic (common on motherboard controllers). In those cases, we have
1303 * 32 bits here to work with. That's good for 8 controllers/channels. The
1304 * bits are organized as 4 bits per channel, with scsi0 getting the lowest
1305 * 4 bits in the int. A 1 in a bit position indicates the termination setting
1306 * that corresponds to that bit should be enabled, a 0 is disabled.
1307 * It looks something like this:
1309 * 0x0f = 1111-Single Ended Low Byte Termination on/off
1310 * ||\-Single Ended High Byte Termination on/off
1311 * |\-LVD Low Byte Termination on/off
1312 * \-LVD High Byte Termination on/off
1314 * For non-Ultra2 controllers, the upper 2 bits are not important. So, to
1315 * enable both high byte and low byte termination on scsi0, I would need to
1316 * make sure that the override_term variable was set to 0x03 (bits 0011).
1317 * To make sure that all termination is enabled on an Ultra2 controller at
1318 * scsi2 and only high byte termination on scsi1 and high and low byte
1319 * termination on scsi0, I would set override_term=0xf23 (bits 1111 0010 0011)
1321 * For the most part, users should never have to use this, that's why I
1322 * left it fairly cryptic instead of easy to understand. If you need it,
1323 * most likely someone will be telling you what your's needs to be set to.
1325 static int aic7xxx_override_term
= -1;
1327 * Certain motherboard chipset controllers tend to screw
1328 * up the polarity of the term enable output pin. Use this variable
1329 * to force the correct polarity for your system. This is a bitfield variable
1330 * similar to the previous one, but this one has one bit per channel instead
1332 * 0 = Force the setting to active low.
1333 * 1 = Force setting to active high.
1334 * Most Adaptec cards are active high, several motherboards are active low.
1335 * To force a 2940 card at SCSI 0 to active high and a motherboard 7895
1336 * controller at scsi1 and scsi2 to active low, and a 2910 card at scsi3
1337 * to active high, you would need to set stpwlev=0x9 (bits 1001).
1339 * People shouldn't need to use this, but if you are experiencing lots of
1340 * SCSI timeout problems, this may help. There is one sure way to test what
1341 * this option needs to be. Using a boot floppy to boot the system, configure
1342 * your system to enable all SCSI termination (in the Adaptec SCSI BIOS) and
1343 * if needed then also pass a value to override_term to make sure that the
1344 * driver is enabling SCSI termination, then set this variable to either 0
1345 * or 1. When the driver boots, make sure there are *NO* SCSI cables
1346 * connected to your controller. If it finds and inits the controller
1347 * without problem, then the setting you passed to stpwlev was correct. If
1348 * the driver goes into a reset loop and hangs the system, then you need the
1349 * other setting for this variable. If neither setting lets the machine
1350 * boot then you have definite termination problems that may not be fixable.
1352 static int aic7xxx_stpwlev
= -1;
1354 * Set this to non-0 in order to force the driver to panic the kernel
1355 * and print out debugging info on a SCSI abort or reset cycle.
1357 static int aic7xxx_panic_on_abort
= 0;
1359 * PCI bus parity checking of the Adaptec controllers. This is somewhat
1360 * dubious at best. To my knowledge, this option has never actually
1361 * solved a PCI parity problem, but on certain machines with broken PCI
1362 * chipset configurations, it can generate tons of false error messages.
1363 * It's included in the driver for completeness.
1364 * 0 = Shut off PCI parity check
1365 * -1 = Normal polarity pci parity checking
1366 * 1 = reverse polarity pci parity checking
1368 * NOTE: you can't actually pass -1 on the lilo prompt. So, to set this
1369 * variable to -1 you would actually want to simply pass the variable
1370 * name without a number. That will invert the 0 which will result in
1373 static int aic7xxx_pci_parity
= 0;
1375 * Set this to any non-0 value to cause us to dump the contents of all
1376 * the card's registers in a hex dump format tailored to each model of
1379 * NOTE: THE CONTROLLER IS LEFT IN AN UNUSEABLE STATE BY THIS OPTION.
1380 * YOU CANNOT BOOT UP WITH THIS OPTION, IT IS FOR DEBUGGING PURPOSES
1383 static int aic7xxx_dump_card
= 0;
1385 * Set this to a non-0 value to make us dump out the 32 bit instruction
1386 * registers on the card after completing the sequencer download. This
1387 * allows the actual sequencer download to be verified. It is possible
1388 * to use this option and still boot up and run your system. This is
1389 * only intended for debugging purposes.
1391 static int aic7xxx_dump_sequencer
= 0;
1393 * Certain newer motherboards have put new PCI based devices into the
1394 * IO spaces that used to typically be occupied by VLB or EISA cards.
1395 * This overlap can cause these newer motherboards to lock up when scanned
1396 * for older EISA and VLB devices. Setting this option to non-0 will
1397 * cause the driver to skip scanning for any VLB or EISA controllers and
1398 * only support the PCI controllers. NOTE: this means that if the kernel
1399 * os compiled with PCI support disabled, then setting this to non-0
1400 * would result in never finding any devices :)
1402 static int aic7xxx_no_probe
= 0;
1405 * So that insmod can find the variable and make it point to something
1408 static char * aic7xxx
= NULL
;
1409 #if LINUX_VERSION_CODE > KERNEL_VERSION(2,1,18)
1410 MODULE_PARM(aic7xxx
, "s");
1414 * Just in case someone uses commas to separate items on the insmod
1415 * command line, we define a dummy buffer here to avoid having insmod
1416 * write wild stuff into our code segment
1418 static char dummy_buffer
[60] = "Please don't trounce on me insmod!!\n";
1423 * See the comments earlier in the file for what this item is all about
1424 * If you have more than 4 controllers, you will need to increase the
1425 * the number of items in the array below. Additionally, if you don't
1426 * want to have lilo pass a humongous config line to the aic7xxx driver,
1427 * then you can get in and manually adjust these instead of leaving them
1428 * at the default. Pay attention to the comments earlier in this file
1429 * concerning this array if you are going to hand modify these values.
1431 static adapter_tag_info_t aic7xxx_tag_info
[] =
1433 {DEFAULT_TAG_COMMANDS
},
1434 {DEFAULT_TAG_COMMANDS
},
1435 {DEFAULT_TAG_COMMANDS
},
1436 {DEFAULT_TAG_COMMANDS
},
1437 {DEFAULT_TAG_COMMANDS
},
1438 {DEFAULT_TAG_COMMANDS
},
1439 {DEFAULT_TAG_COMMANDS
},
1440 {DEFAULT_TAG_COMMANDS
},
1441 {DEFAULT_TAG_COMMANDS
},
1442 {DEFAULT_TAG_COMMANDS
},
1443 {DEFAULT_TAG_COMMANDS
},
1444 {DEFAULT_TAG_COMMANDS
},
1445 {DEFAULT_TAG_COMMANDS
},
1446 {DEFAULT_TAG_COMMANDS
},
1447 {DEFAULT_TAG_COMMANDS
},
1448 {DEFAULT_TAG_COMMANDS
}
1451 #define VERBOSE_NORMAL 0x0000
1452 #define VERBOSE_NEGOTIATION 0x0001
1453 #define VERBOSE_SEQINT 0x0002
1454 #define VERBOSE_SCSIINT 0x0004
1455 #define VERBOSE_PROBE 0x0008
1456 #define VERBOSE_PROBE2 0x0010
1457 #define VERBOSE_NEGOTIATION2 0x0020
1458 #define VERBOSE_MINOR_ERROR 0x0040
1459 #define VERBOSE_TRACING 0x0080
1460 #define VERBOSE_ABORT 0x0f00
1461 #define VERBOSE_ABORT_MID 0x0100
1462 #define VERBOSE_ABORT_FIND 0x0200
1463 #define VERBOSE_ABORT_PROCESS 0x0400
1464 #define VERBOSE_ABORT_RETURN 0x0800
1465 #define VERBOSE_RESET 0xf000
1466 #define VERBOSE_RESET_MID 0x1000
1467 #define VERBOSE_RESET_FIND 0x2000
1468 #define VERBOSE_RESET_PROCESS 0x4000
1469 #define VERBOSE_RESET_RETURN 0x8000
1470 static int aic7xxx_verbose
= VERBOSE_NORMAL
| VERBOSE_NEGOTIATION
|
1471 VERBOSE_PROBE
; /* verbose messages */
1474 /****************************************************************************
1476 * We're going to start putting in function declarations so that order of
1477 * functions is no longer important. As needed, they are added here.
1479 ***************************************************************************/
1481 static void aic7xxx_panic_abort(struct aic7xxx_host
*p
, Scsi_Cmnd
*cmd
);
1482 static void aic7xxx_print_card(struct aic7xxx_host
*p
);
1483 static void aic7xxx_print_scratch_ram(struct aic7xxx_host
*p
);
1484 #ifdef AIC7XXX_VERBOSE_DEBUGGING
1485 static void aic7xxx_print_sequencer(struct aic7xxx_host
*p
, int downloaded
);
1486 static void aic7xxx_check_scbs(struct aic7xxx_host
*p
, char *buffer
);
1489 /****************************************************************************
1491 * These functions are now used. They happen to be wrapped in useless
1492 * inb/outb port read/writes around the real reads and writes because it
1493 * seems that certain very fast CPUs have a problem dealing with us when
1494 * going at full speed.
1496 ***************************************************************************/
1498 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,1,0)
1500 mdelay(int milliseconds
)
1504 for(i
=0; i
<milliseconds
; i
++)
1509 static inline unsigned char
1510 aic_inb(struct aic7xxx_host
*p
, long port
)
1520 x
= inb(p
->base
+ port
);
1525 return(inb(p
->base
+ port
));
1530 aic_outb(struct aic7xxx_host
*p
, unsigned char val
, long port
)
1535 p
->maddr
[port
] = val
;
1539 outb(val
, p
->base
+ port
);
1543 outb(val
, p
->base
+ port
);
1548 aic_outsb(struct aic7xxx_host
*p
, long port
, unsigned char *valp
, size_t size
)
1554 for (i
=0; i
< size
; i
++)
1556 p
->maddr
[port
] = valp
[i
];
1561 outsb(p
->base
+ port
, valp
, size
);
1563 outsb(p
->base
+ port
, valp
, size
);
1567 /*+F*************************************************************************
1572 * Handle Linux boot parameters. This routine allows for assigning a value
1573 * to a parameter with a ':' between the parameter and the value.
1574 * ie. aic7xxx=unpause:0x0A,extended
1575 *-F*************************************************************************/
1577 aic7xxx_setup(char *s
, int *dummy
)
1587 { "extended", &aic7xxx_extended
},
1588 { "no_reset", &aic7xxx_no_reset
},
1589 { "irq_trigger", &aic7xxx_irq_trigger
},
1590 { "verbose", &aic7xxx_verbose
},
1591 { "reverse_scan",&aic7xxx_reverse_scan
},
1592 { "override_term", &aic7xxx_override_term
},
1593 { "stpwlev", &aic7xxx_stpwlev
},
1594 { "no_probe", &aic7xxx_no_probe
},
1595 { "panic_on_abort", &aic7xxx_panic_on_abort
},
1596 { "pci_parity", &aic7xxx_pci_parity
},
1597 { "dump_card", &aic7xxx_dump_card
},
1598 { "dump_sequencer", &aic7xxx_dump_sequencer
},
1599 { "tag_info", NULL
}
1602 end
= strchr(s
, '\0');
1604 for (p
= strtok(s
, ",."); p
; p
= strtok(NULL
, ",."))
1606 for (i
= 0; i
< NUMBER(options
); i
++)
1608 n
= strlen(options
[i
].name
);
1609 if (!strncmp(options
[i
].name
, p
, n
))
1611 if (!strncmp(p
, "tag_info", n
))
1616 char *tok
, *tok_end
, *tok_end2
;
1617 char tok_list
[] = { '.', ',', '{', '}', '\0' };
1618 int i
, instance
= -1, device
= -1;
1619 unsigned char done
= FALSE
;
1622 tok
= base
+ n
+ 1; /* Forward us just past the ':' */
1623 tok_end
= strchr(tok
, '\0');
1633 else if (device
== -1)
1640 else if (instance
!= -1)
1648 else if (device
>= 0)
1650 else if (instance
>= 0)
1652 if ( (device
>= MAX_TARGETS
) ||
1653 (instance
>= NUMBER(aic7xxx_tag_info
)) )
1666 tok_end
= strchr(tok
, '\0');
1667 for(i
=0; tok_list
[i
]; i
++)
1669 tok_end2
= strchr(tok
, tok_list
[i
]);
1670 if ( (tok_end2
) && (tok_end2
< tok_end
) )
1676 if ( (instance
>= 0) && (device
>= 0) &&
1677 (instance
< NUMBER(aic7xxx_tag_info
)) &&
1678 (device
< MAX_TARGETS
) )
1679 aic7xxx_tag_info
[instance
].tag_commands
[device
] =
1680 simple_strtoul(tok
, NULL
, 0) & 0xff;
1685 while((p
!= base
) && (p
!= NULL
))
1686 p
= strtok(NULL
, ",.");
1689 else if (p
[n
] == ':')
1691 *(options
[i
].flag
) = simple_strtoul(p
+ n
+ 1, NULL
, 0);
1693 else if (!strncmp(p
, "verbose", n
))
1695 *(options
[i
].flag
) = 0xff09;
1699 *(options
[i
].flag
) = ~(*(options
[i
].flag
));
1706 /*+F*************************************************************************
1711 * Pause the sequencer and wait for it to actually stop - this
1712 * is important since the sequencer can disable pausing for critical
1714 *-F*************************************************************************/
1716 pause_sequencer(struct aic7xxx_host
*p
)
1718 aic_outb(p
, p
->pause
, HCNTRL
);
1719 while ((aic_inb(p
, HCNTRL
) & PAUSE
) == 0)
1725 /*+F*************************************************************************
1730 * Unpause the sequencer. Unremarkable, yet done often enough to
1731 * warrant an easy way to do it.
1732 *-F*************************************************************************/
1734 unpause_sequencer(struct aic7xxx_host
*p
, int unpause_always
)
1736 if (unpause_always
||
1737 ( !(aic_inb(p
, INTSTAT
) & (SCSIINT
| SEQINT
| BRKADRINT
)) &&
1738 !(p
->flags
& AHC_HANDLING_REQINITS
) ) )
1740 aic_outb(p
, p
->unpause
, HCNTRL
);
1744 /*+F*************************************************************************
1749 * Restart the sequencer program from address zero. This assumes
1750 * that the sequencer is already paused.
1751 *-F*************************************************************************/
1753 restart_sequencer(struct aic7xxx_host
*p
)
1755 aic_outb(p
, FASTMODE
|SEQRESET
, SEQCTL
);
1759 * We include the aic7xxx_seq.c file here so that the other defines have
1760 * already been made, and so that it comes before the code that actually
1761 * downloads the instructions (since we don't typically use function
1762 * prototype, our code has to be ordered that way, it's a left-over from
1763 * the original driver days.....I should fix it some time DL).
1765 #include "aic7xxx_seq.c"
1767 /*+F*************************************************************************
1769 * aic7xxx_check_patch
1772 * See if the next patch to download should be downloaded.
1773 *-F*************************************************************************/
1775 aic7xxx_check_patch(struct aic7xxx_host
*p
,
1776 struct sequencer_patch
**start_patch
, int start_instr
, int *skip_addr
)
1778 struct sequencer_patch
*cur_patch
;
1779 struct sequencer_patch
*last_patch
;
1782 num_patches
= sizeof(sequencer_patches
)/sizeof(struct sequencer_patch
);
1783 last_patch
= &sequencer_patches
[num_patches
];
1784 cur_patch
= *start_patch
;
1786 while ((cur_patch
< last_patch
) && (start_instr
== cur_patch
->begin
))
1788 if (cur_patch
->patch_func(p
) == 0)
1791 * Start rejecting code.
1793 *skip_addr
= start_instr
+ cur_patch
->skip_instr
;
1794 cur_patch
+= cur_patch
->skip_patch
;
1799 * Found an OK patch. Advance the patch pointer to the next patch
1800 * and wait for our instruction pointer to get here.
1806 *start_patch
= cur_patch
;
1807 if (start_instr
< *skip_addr
)
1816 /*+F*************************************************************************
1818 * aic7xxx_download_instr
1821 * Find the next patch to download.
1822 *-F*************************************************************************/
1824 aic7xxx_download_instr(struct aic7xxx_host
*p
, int instrptr
,
1825 unsigned char *dconsts
)
1827 union ins_formats instr
;
1828 struct ins_format1
*fmt1_ins
;
1829 struct ins_format3
*fmt3_ins
;
1830 unsigned char opcode
;
1832 instr
= *(union ins_formats
*) &seqprog
[instrptr
* 4];
1834 fmt1_ins
= &instr
.format1
;
1837 /* Pull the opcode */
1838 opcode
= instr
.format1
.opcode
;
1850 struct sequencer_patch
*cur_patch
;
1852 unsigned int address
;
1856 fmt3_ins
= &instr
.format3
;
1858 address
= fmt3_ins
->address
;
1859 cur_patch
= sequencer_patches
;
1862 for (i
= 0; i
< address
;)
1864 aic7xxx_check_patch(p
, &cur_patch
, i
, &skip_addr
);
1869 end_addr
= MIN(address
, skip_addr
);
1870 address_offset
+= end_addr
- i
;
1878 address
-= address_offset
;
1879 fmt3_ins
->address
= address
;
1880 /* Fall Through to the next code section */
1888 if (fmt1_ins
->parity
!= 0)
1890 fmt1_ins
->immediate
= dconsts
[fmt1_ins
->immediate
];
1892 fmt1_ins
->parity
= 0;
1893 /* Fall Through to the next code section */
1895 if ((p
->features
& AHC_ULTRA2
) != 0)
1899 /* Calculate odd parity for the instruction */
1900 for ( i
=0, count
=0; i
< 31; i
++)
1905 if ((instr
.integer
& mask
) != 0)
1908 if (!(count
& 0x01))
1909 instr
.format1
.parity
= 1;
1913 if (fmt3_ins
!= NULL
)
1915 instr
.integer
= fmt3_ins
->immediate
|
1916 (fmt3_ins
->source
<< 8) |
1917 (fmt3_ins
->address
<< 16) |
1918 (fmt3_ins
->opcode
<< 25);
1922 instr
.integer
= fmt1_ins
->immediate
|
1923 (fmt1_ins
->source
<< 8) |
1924 (fmt1_ins
->destination
<< 16) |
1925 (fmt1_ins
->ret
<< 24) |
1926 (fmt1_ins
->opcode
<< 25);
1929 aic_outsb(p
, SEQRAM
, instr
.bytes
, 4);
1933 panic("aic7xxx: Unknown opcode encountered in sequencer program.");
1939 /*+F*************************************************************************
1944 * Load the sequencer code into the controller memory.
1945 *-F*************************************************************************/
1947 aic7xxx_loadseq(struct aic7xxx_host
*p
)
1949 struct sequencer_patch
*cur_patch
;
1953 unsigned char download_consts
[4] = {0, 0, 0, 0};
1955 if (aic7xxx_verbose
& VERBOSE_PROBE
)
1957 printk(KERN_INFO
"(scsi%d) Downloading sequencer code...", p
->host_no
);
1959 download_consts
[TMODE_NUMCMDS
] = p
->num_targetcmds
;
1960 cur_patch
= &sequencer_patches
[0];
1964 aic_outb(p
, PERRORDIS
|LOADRAM
|FAILDIS
|FASTMODE
, SEQCTL
);
1965 aic_outb(p
, 0, SEQADDR0
);
1966 aic_outb(p
, 0, SEQADDR1
);
1968 for (i
= 0; i
< sizeof(seqprog
) / 4; i
++)
1970 if (aic7xxx_check_patch(p
, &cur_patch
, i
, &skip_addr
) == 0)
1972 /* Skip this instruction for this configuration. */
1975 aic7xxx_download_instr(p
, i
, &download_consts
[0]);
1979 aic_outb(p
, FASTMODE
|SEQRESET
, SEQCTL
);
1980 if (aic7xxx_verbose
& VERBOSE_PROBE
)
1982 printk(" %d instructions downloaded\n", downloaded
);
1984 #ifdef AIC7XXX_VERBOSE_DEBUGGING
1985 if (aic7xxx_dump_sequencer
)
1986 aic7xxx_print_sequencer(p
, downloaded
);
1990 #ifdef AIC7XXX_VERBOSE_DEBUGGING
1991 /*+F*************************************************************************
1993 * aic7xxx_print_sequencer
1996 * Print the contents of the sequencer memory to the screen.
1997 *-F*************************************************************************/
1999 aic7xxx_print_sequencer(struct aic7xxx_host
*p
, int downloaded
)
2003 aic_outb(p
, PERRORDIS
|LOADRAM
|FAILDIS
|FASTMODE
, SEQCTL
);
2004 aic_outb(p
, 0, SEQADDR0
);
2005 aic_outb(p
, 0, SEQADDR1
);
2008 for (i
=0; i
< downloaded
; i
++)
2011 printk("%03x: ", i
);
2012 temp
= aic_inb(p
, SEQRAM
);
2013 temp
|= (aic_inb(p
, SEQRAM
) << 8);
2014 temp
|= (aic_inb(p
, SEQRAM
) << 16);
2015 temp
|= (aic_inb(p
, SEQRAM
) << 24);
2016 printk("%08x", temp
);
2025 aic_outb(p
, FASTMODE
|SEQRESET
, SEQCTL
);
2030 /*+F*************************************************************************
2035 * Delay for specified amount of time. We use mdelay because the timer
2036 * interrupt is not guaranteed to be enabled. This will cause an
2037 * infinite loop since jiffies (clock ticks) is not updated.
2038 *-F*************************************************************************/
2040 aic7xxx_delay(int seconds
)
2042 mdelay(seconds
* 1000);
2045 /*+F*************************************************************************
2050 * Return a string describing the driver.
2051 *-F*************************************************************************/
2053 aic7xxx_info(struct Scsi_Host
*dooh
)
2055 static char buffer
[256];
2057 struct aic7xxx_host
*p
;
2060 p
= (struct aic7xxx_host
*)dooh
->hostdata
;
2061 memset(bp
, 0, sizeof(buffer
));
2062 strcpy(bp
, "Adaptec AHA274x/284x/294x (EISA/VLB/PCI-Fast SCSI) ");
2063 strcat(bp
, AIC7XXX_C_VERSION
);
2065 strcat(bp
, AIC7XXX_H_VERSION
);
2068 strcat(bp
, board_names
[p
->board_name_index
]);
2074 /*+F*************************************************************************
2076 * aic7xxx_find_syncrate
2079 * Look up the valid period to SCSIRATE conversion in our table
2080 *-F*************************************************************************/
2081 static struct aic7xxx_syncrate
*
2082 aic7xxx_find_syncrate(struct aic7xxx_host
*p
, unsigned int *period
,
2083 unsigned int maxsync
)
2085 struct aic7xxx_syncrate
*syncrate
;
2087 syncrate
= &aic7xxx_syncrates
[maxsync
];
2088 while ( (syncrate
->rate
[0] != NULL
) &&
2089 (!(p
->features
& AHC_ULTRA2
) || syncrate
->sxfr_ultra2
) )
2091 if ( *period
<= syncrate
->period
)
2094 * When responding to a target that requests sync, the requested rate
2095 * may fall between two rates that we can output, but still be a rate
2096 * that we can receive. Because of this, we want to respond with the
2097 * same rate that it sent to us even if the persiod we use to send
2098 * data to it is lower. Only lower the response period if we must.
2100 if(syncrate
== &aic7xxx_syncrates
[maxsync
])
2102 *period
= syncrate
->period
;
2108 if ( (*period
== 0) || (syncrate
->rate
[0] == NULL
) ||
2109 ((p
->features
& AHC_ULTRA2
) && (syncrate
->sxfr_ultra2
== 0)) )
2112 * Use async transfers for this target
2121 /*+F*************************************************************************
2123 * aic7xxx_find_period
2126 * Look up the valid SCSIRATE to period conversion in our table
2127 *-F*************************************************************************/
2129 aic7xxx_find_period(struct aic7xxx_host
*p
, unsigned int scsirate
,
2130 unsigned int maxsync
)
2132 struct aic7xxx_syncrate
*syncrate
;
2134 if ((p
->features
& AHC_ULTRA2
) != 0)
2136 scsirate
&= SXFR_ULTRA2
;
2143 syncrate
= &aic7xxx_syncrates
[maxsync
];
2144 while (syncrate
->rate
[0] != NULL
)
2146 if ((p
->features
& AHC_ULTRA2
) != 0)
2148 if (syncrate
->sxfr_ultra2
== 0)
2150 else if (scsirate
== syncrate
->sxfr_ultra2
)
2151 return (syncrate
->period
);
2153 else if (scsirate
== (syncrate
->sxfr
& ~ULTRA_SXFR
))
2155 return (syncrate
->period
);
2159 return (0); /* async */
2162 /*+F*************************************************************************
2164 * aic7xxx_validate_offset
2167 * Set a valid offset value for a particular card in use and transfer
2169 *-F*************************************************************************/
2171 aic7xxx_validate_offset(struct aic7xxx_host
*p
,
2172 struct aic7xxx_syncrate
*syncrate
, unsigned int *offset
, int wide
)
2174 unsigned int maxoffset
;
2176 /* Limit offset to what the card (and device) can do */
2177 if (syncrate
== NULL
)
2181 else if (p
->features
& AHC_ULTRA2
)
2183 maxoffset
= MAX_OFFSET_ULTRA2
;
2188 maxoffset
= MAX_OFFSET_16BIT
;
2190 maxoffset
= MAX_OFFSET_8BIT
;
2192 *offset
= MIN(*offset
, maxoffset
);
2195 /*+F*************************************************************************
2197 * aic7xxx_set_syncrate
2200 * Set the actual syncrate down in the card and in our host structs
2201 *-F*************************************************************************/
2203 aic7xxx_set_syncrate(struct aic7xxx_host
*p
, struct aic7xxx_syncrate
*syncrate
,
2204 int target
, int channel
, unsigned int period
, unsigned int offset
,
2207 unsigned char tindex
;
2208 unsigned short target_mask
;
2210 unsigned int old_period
, old_offset
;
2212 tindex
= target
| (channel
<< 3);
2213 target_mask
= 0x01 << tindex
;
2214 lun
= aic_inb(p
, SCB_TCL
) & 0x07;
2216 if (syncrate
== NULL
)
2222 old_period
= p
->transinfo
[tindex
].cur_period
;
2223 old_offset
= p
->transinfo
[tindex
].cur_offset
;
2226 if (type
& AHC_TRANS_CUR
)
2228 unsigned int scsirate
;
2230 scsirate
= aic_inb(p
, TARG_SCSIRATE
+ tindex
);
2231 if (p
->features
& AHC_ULTRA2
)
2233 scsirate
&= ~SXFR_ULTRA2
;
2234 if (syncrate
!= NULL
)
2236 scsirate
|= syncrate
->sxfr_ultra2
;
2238 if (type
& AHC_TRANS_ACTIVE
)
2240 aic_outb(p
, offset
, SCSIOFFSET
);
2242 aic_outb(p
, offset
, TARG_OFFSET
+ tindex
);
2244 else /* Not an Ultra2 controller */
2246 scsirate
&= ~(SXFR
|SOFS
);
2247 p
->ultraenb
&= ~target_mask
;
2248 if (syncrate
!= NULL
)
2250 if (syncrate
->sxfr
& ULTRA_SXFR
)
2252 p
->ultraenb
|= target_mask
;
2254 scsirate
|= (syncrate
->sxfr
& SXFR
);
2255 scsirate
|= (offset
& SOFS
);
2257 if (type
& AHC_TRANS_ACTIVE
)
2259 unsigned char sxfrctl0
;
2261 sxfrctl0
= aic_inb(p
, SXFRCTL0
);
2262 sxfrctl0
&= ~FAST20
;
2263 if (p
->ultraenb
& target_mask
)
2265 aic_outb(p
, sxfrctl0
, SXFRCTL0
);
2267 aic_outb(p
, p
->ultraenb
& 0xff, ULTRA_ENB
);
2268 aic_outb(p
, (p
->ultraenb
>> 8) & 0xff, ULTRA_ENB
+ 1 );
2270 if (type
& AHC_TRANS_ACTIVE
)
2272 aic_outb(p
, scsirate
, SCSIRATE
);
2274 aic_outb(p
, scsirate
, TARG_SCSIRATE
+ tindex
);
2275 p
->transinfo
[tindex
].cur_period
= period
;
2276 p
->transinfo
[tindex
].cur_offset
= offset
;
2277 if ( !(type
& AHC_TRANS_QUITE
) &&
2278 (aic7xxx_verbose
& VERBOSE_NEGOTIATION
) &&
2279 (p
->dev_flags
[tindex
] & DEVICE_PRINT_SDTR
) )
2283 int rate_mod
= (scsirate
& WIDEXFER
) ? 1 : 0;
2285 printk(INFO_LEAD
"Synchronous at %s Mbyte/sec, "
2286 "offset %d.\n", p
->host_no
, channel
, target
, lun
,
2287 syncrate
->rate
[rate_mod
], offset
);
2291 printk(INFO_LEAD
"Using asynchronous transfers.\n",
2292 p
->host_no
, channel
, target
, lun
);
2294 p
->dev_flags
[tindex
] &= ~DEVICE_PRINT_SDTR
;
2298 if (type
& AHC_TRANS_GOAL
)
2300 p
->transinfo
[tindex
].goal_period
= period
;
2301 p
->transinfo
[tindex
].goal_offset
= offset
;
2304 if (type
& AHC_TRANS_USER
)
2306 p
->transinfo
[tindex
].user_period
= period
;
2307 p
->transinfo
[tindex
].user_offset
= offset
;
2311 /*+F*************************************************************************
2316 * Set the actual width down in the card and in our host structs
2317 *-F*************************************************************************/
2319 aic7xxx_set_width(struct aic7xxx_host
*p
, int target
, int channel
, int lun
,
2320 unsigned int width
, unsigned int type
)
2322 unsigned char tindex
;
2323 unsigned short target_mask
;
2324 unsigned int old_width
, new_offset
;
2326 tindex
= target
| (channel
<< 3);
2327 target_mask
= 1 << tindex
;
2329 old_width
= p
->transinfo
[tindex
].cur_width
;
2331 if (p
->features
& AHC_ULTRA2
)
2332 new_offset
= MAX_OFFSET_ULTRA2
;
2333 else if (width
== MSG_EXT_WDTR_BUS_16_BIT
)
2334 new_offset
= MAX_OFFSET_16BIT
;
2336 new_offset
= MAX_OFFSET_8BIT
;
2338 if (type
& AHC_TRANS_CUR
)
2340 unsigned char scsirate
;
2342 scsirate
= aic_inb(p
, TARG_SCSIRATE
+ tindex
);
2344 scsirate
&= ~WIDEXFER
;
2345 if (width
== MSG_EXT_WDTR_BUS_16_BIT
)
2346 scsirate
|= WIDEXFER
;
2348 aic_outb(p
, scsirate
, TARG_SCSIRATE
+ tindex
);
2350 if (type
& AHC_TRANS_ACTIVE
)
2351 aic_outb(p
, scsirate
, SCSIRATE
);
2353 p
->transinfo
[tindex
].cur_width
= width
;
2355 if ((aic7xxx_verbose
& VERBOSE_NEGOTIATION2
) &&
2356 (p
->dev_flags
[tindex
] & DEVICE_PRINT_WDTR
))
2358 printk(INFO_LEAD
"Using %s transfers\n", p
->host_no
, channel
, target
,
2359 lun
, (scsirate
& WIDEXFER
) ? "Wide(16bit)" : "Narrow(8bit)" );
2360 p
->dev_flags
[tindex
] &= ~DEVICE_PRINT_WDTR
;
2364 if (type
& AHC_TRANS_GOAL
)
2365 p
->transinfo
[tindex
].goal_width
= width
;
2366 if (type
& AHC_TRANS_USER
)
2367 p
->transinfo
[tindex
].user_width
= width
;
2370 * Having just set the width, the SDTR should come next, and we need a valid
2371 * offset for the SDTR. So, we make sure we put a valid one in here now as
2374 if (p
->transinfo
[tindex
].goal_offset
)
2375 p
->transinfo
[tindex
].goal_offset
= new_offset
;
2379 /*+F*************************************************************************
2384 * SCB queue initialization.
2386 *-F*************************************************************************/
2388 scbq_init(volatile scb_queue_type
*queue
)
2394 /*+F*************************************************************************
2399 * Add an SCB to the head of the list.
2401 *-F*************************************************************************/
2403 scbq_insert_head(volatile scb_queue_type
*queue
, struct aic7xxx_scb
*scb
)
2405 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,1,95)
2406 unsigned long cpu_flags
;
2410 scb
->q_next
= queue
->head
;
2412 if (queue
->tail
== NULL
) /* If list was empty, update tail. */
2413 queue
->tail
= queue
->head
;
2417 /*+F*************************************************************************
2422 * Remove an SCB from the head of the list.
2424 *-F*************************************************************************/
2425 static inline struct aic7xxx_scb
*
2426 scbq_remove_head(volatile scb_queue_type
*queue
)
2428 struct aic7xxx_scb
* scbp
;
2429 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,1,95)
2430 unsigned long cpu_flags
;
2435 if (queue
->head
!= NULL
)
2436 queue
->head
= queue
->head
->q_next
;
2437 if (queue
->head
== NULL
) /* If list is now empty, update tail. */
2443 /*+F*************************************************************************
2448 * Removes an SCB from the list.
2450 *-F*************************************************************************/
2452 scbq_remove(volatile scb_queue_type
*queue
, struct aic7xxx_scb
*scb
)
2454 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,1,95)
2455 unsigned long cpu_flags
;
2459 if (queue
->head
== scb
)
2461 /* At beginning of queue, remove from head. */
2462 scbq_remove_head(queue
);
2466 struct aic7xxx_scb
*curscb
= queue
->head
;
2469 * Search until the next scb is the one we're looking for, or
2470 * we run out of queue.
2472 while ((curscb
!= NULL
) && (curscb
->q_next
!= scb
))
2474 curscb
= curscb
->q_next
;
2479 curscb
->q_next
= scb
->q_next
;
2480 if (scb
->q_next
== NULL
)
2482 /* Update the tail when removing the tail. */
2483 queue
->tail
= curscb
;
2490 /*+F*************************************************************************
2495 * Add an SCB at the tail of the list.
2497 *-F*************************************************************************/
2499 scbq_insert_tail(volatile scb_queue_type
*queue
, struct aic7xxx_scb
*scb
)
2501 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,1,95)
2502 unsigned long cpu_flags
;
2507 if (queue
->tail
!= NULL
) /* Add the scb at the end of the list. */
2508 queue
->tail
->q_next
= scb
;
2509 queue
->tail
= scb
; /* Update the tail. */
2510 if (queue
->head
== NULL
) /* If list was empty, update head. */
2511 queue
->head
= queue
->tail
;
2515 /*+F*************************************************************************
2520 * Checks to see if an scb matches the target/channel as specified.
2521 * If target is ALL_TARGETS (-1), then we're looking for any device
2522 * on the specified channel; this happens when a channel is going
2523 * to be reset and all devices on that channel must be aborted.
2524 *-F*************************************************************************/
2526 aic7xxx_match_scb(struct aic7xxx_host
*p
, struct aic7xxx_scb
*scb
,
2527 int target
, int channel
, int lun
, unsigned char tag
)
2529 int targ
= (scb
->hscb
->target_channel_lun
>> 4) & 0x0F;
2530 int chan
= (scb
->hscb
->target_channel_lun
>> 3) & 0x01;
2531 int slun
= scb
->hscb
->target_channel_lun
& 0x07;
2534 match
= ((chan
== channel
) || (channel
== ALL_CHANNELS
));
2536 match
= ((targ
== target
) || (target
== ALL_TARGETS
));
2538 match
= ((lun
== slun
) || (lun
== ALL_LUNS
));
2540 match
= ((tag
== scb
->hscb
->tag
) || (tag
== SCB_LIST_NULL
));
2542 if (aic7xxx_verbose
& (VERBOSE_ABORT_PROCESS
| VERBOSE_RESET_PROCESS
))
2544 printk(KERN_INFO
"(scsi%d:%d:%d:%d:tag%d) %s search criteria"
2545 " (scsi%d:%d:%d:%d:tag%d)\n", p
->host_no
, CTL_OF_SCB(scb
),
2546 scb
->hscb
->tag
, (match
) ? "matches" : "doesn't match",
2547 p
->host_no
, channel
, target
, lun
, tag
);
2553 /*+F*************************************************************************
2555 * aic7xxx_add_curscb_to_free_list
2558 * Adds the current scb (in SCBPTR) to the list of free SCBs.
2559 *-F*************************************************************************/
2561 aic7xxx_add_curscb_to_free_list(struct aic7xxx_host
*p
)
2564 * Invalidate the tag so that aic7xxx_find_scb doesn't think
2567 aic_outb(p
, SCB_LIST_NULL
, SCB_TAG
);
2568 aic_outb(p
, 0, SCB_CONTROL
);
2570 aic_outb(p
, aic_inb(p
, FREE_SCBH
), SCB_NEXT
);
2571 aic_outb(p
, aic_inb(p
, SCBPTR
), FREE_SCBH
);
2574 /*+F*************************************************************************
2576 * aic7xxx_rem_scb_from_disc_list
2579 * Removes the current SCB from the disconnected list and adds it
2581 *-F*************************************************************************/
2582 static unsigned char
2583 aic7xxx_rem_scb_from_disc_list(struct aic7xxx_host
*p
, unsigned char scbptr
)
2588 aic_outb(p
, scbptr
, SCBPTR
);
2589 next
= aic_inb(p
, SCB_NEXT
);
2590 prev
= aic_inb(p
, SCB_PREV
);
2591 aic7xxx_add_curscb_to_free_list(p
);
2593 if (prev
!= SCB_LIST_NULL
)
2595 aic_outb(p
, prev
, SCBPTR
);
2596 aic_outb(p
, next
, SCB_NEXT
);
2600 aic_outb(p
, next
, DISCONNECTED_SCBH
);
2603 if (next
!= SCB_LIST_NULL
)
2605 aic_outb(p
, next
, SCBPTR
);
2606 aic_outb(p
, prev
, SCB_PREV
);
2611 /*+F*************************************************************************
2613 * aic7xxx_busy_target
2616 * Set the specified target busy.
2617 *-F*************************************************************************/
2619 aic7xxx_busy_target(struct aic7xxx_host
*p
, struct aic7xxx_scb
*scb
)
2621 p
->untagged_scbs
[scb
->hscb
->target_channel_lun
] = scb
->hscb
->tag
;
2624 /*+F*************************************************************************
2626 * aic7xxx_index_busy_target
2629 * Returns the index of the busy target, and optionally sets the
2631 *-F*************************************************************************/
2632 static inline unsigned char
2633 aic7xxx_index_busy_target(struct aic7xxx_host
*p
, unsigned char tcl
,
2636 unsigned char busy_scbid
;
2638 busy_scbid
= p
->untagged_scbs
[tcl
];
2641 p
->untagged_scbs
[tcl
] = SCB_LIST_NULL
;
2643 return (busy_scbid
);
2646 /*+F*************************************************************************
2651 * Look through the SCB array of the card and attempt to find the
2652 * hardware SCB that corresponds to the passed in SCB. Return
2653 * SCB_LIST_NULL if unsuccessful. This routine assumes that the
2654 * card is already paused.
2655 *-F*************************************************************************/
2656 static unsigned char
2657 aic7xxx_find_scb(struct aic7xxx_host
*p
, struct aic7xxx_scb
*scb
)
2659 unsigned char saved_scbptr
;
2660 unsigned char curindex
;
2662 saved_scbptr
= aic_inb(p
, SCBPTR
);
2664 for (curindex
= 0; curindex
< p
->scb_data
->maxhscbs
; curindex
++)
2666 aic_outb(p
, curindex
, SCBPTR
);
2667 if (aic_inb(p
, SCB_TAG
) == scb
->hscb
->tag
)
2672 aic_outb(p
, saved_scbptr
, SCBPTR
);
2673 if (curindex
>= p
->scb_data
->maxhscbs
)
2675 curindex
= SCB_LIST_NULL
;
2681 /*+F*************************************************************************
2683 * aic7xxx_allocate_scb
2686 * Get an SCB from the free list or by allocating a new one.
2687 *-F*************************************************************************/
2689 aic7xxx_allocate_scb(struct aic7xxx_host
*p
)
2691 struct aic7xxx_scb
*scbp
= NULL
;
2692 int scb_size
= sizeof(struct aic7xxx_scb
) +
2693 sizeof (struct hw_scatterlist
) * AIC7XXX_MAX_SG
;
2695 int step
= PAGE_SIZE
/ 1024;
2696 unsigned long scb_count
= 0;
2697 struct hw_scatterlist
*hsgp
;
2698 struct aic7xxx_scb
*scb_ap
;
2702 if (p
->scb_data
->numscbs
< p
->scb_data
->maxscbs
)
2705 * Calculate the optimal number of SCBs to allocate.
2707 * NOTE: This formula works because the sizeof(sg_array) is always
2708 * 1024. Therefore, scb_size * i would always be > PAGE_SIZE *
2709 * (i/step). The (i-1) allows the left hand side of the equation
2710 * to grow into the right hand side to a point of near perfect
2711 * efficiency since scb_size * (i -1) is growing slightly faster
2712 * than the right hand side. If the number of SG array elements
2713 * is changed, this function may not be near so efficient any more.
2715 for ( i
=step
;; i
*= 2 )
2717 if ( (scb_size
* (i
-1)) >= ( (PAGE_SIZE
* (i
/step
)) - 64 ) )
2723 scb_count
= MIN( (i
-1), p
->scb_data
->maxscbs
- p
->scb_data
->numscbs
);
2724 scb_ap
= (struct aic7xxx_scb
*)kmalloc(scb_size
* scb_count
, GFP_ATOMIC
);
2727 #ifdef AIC7XXX_VERBOSE_DEBUGGING
2728 if (aic7xxx_verbose
> 0xffff)
2730 if (p
->scb_data
->numscbs
== 0)
2731 printk(INFO_LEAD
"Allocating initial %ld SCB structures.\n",
2732 p
->host_no
, -1, -1, -1, scb_count
);
2734 printk(INFO_LEAD
"Allocating %ld additional SCB structures.\n",
2735 p
->host_no
, -1, -1, -1, scb_count
);
2738 memset(scb_ap
, 0, scb_count
* scb_size
);
2739 temp
= (unsigned long) &scb_ap
[scb_count
];
2742 hsgp
= (struct hw_scatterlist
*)temp
;
2743 for (i
=0; i
< scb_count
; i
++)
2746 scbp
->hscb
= &p
->scb_data
->hscbs
[p
->scb_data
->numscbs
];
2747 scbp
->sg_list
= &hsgp
[i
* AIC7XXX_MAX_SG
];
2748 memset(scbp
->hscb
, 0, sizeof(struct aic7xxx_hwscb
));
2749 scbp
->hscb
->tag
= p
->scb_data
->numscbs
;
2751 * Place in the scb array; never is removed
2753 p
->scb_data
->scb_array
[p
->scb_data
->numscbs
++] = scbp
;
2754 scbq_insert_head(&p
->scb_data
->free_scbs
, scbp
);
2756 scbp
->kmalloc_ptr
= scb_ap
;
2766 /*+F*************************************************************************
2768 * aic7xxx_queue_cmd_complete
2771 * Due to race conditions present in the SCSI subsystem, it is easier
2772 * to queue completed commands, then call scsi_done() on them when
2773 * we're finished. This function queues the completed commands.
2774 *-F*************************************************************************/
2776 aic7xxx_queue_cmd_complete(struct aic7xxx_host
*p
, Scsi_Cmnd
*cmd
)
2778 cmd
->host_scribble
= (char *)p
->completeq
.head
;
2779 p
->completeq
.head
= cmd
;
2782 /*+F*************************************************************************
2784 * aic7xxx_done_cmds_complete
2787 * Process the completed command queue.
2788 *-F*************************************************************************/
2790 aic7xxx_done_cmds_complete(struct aic7xxx_host
*p
)
2793 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,1,95)
2794 unsigned int cpu_flags
= 0;
2797 while (p
->completeq
.head
!= NULL
)
2799 cmd
= p
->completeq
.head
;
2800 p
->completeq
.head
= (Scsi_Cmnd
*)cmd
->host_scribble
;
2801 cmd
->host_scribble
= NULL
;
2803 cmd
->scsi_done(cmd
);
2808 while (p
->completeq
.head
!= NULL
)
2810 cmd
= p
->completeq
.head
;
2811 p
->completeq
.head
= (Scsi_Cmnd
*)cmd
->host_scribble
;
2812 cmd
->host_scribble
= NULL
;
2813 cmd
->scsi_done(cmd
);
2818 /*+F*************************************************************************
2823 * Free the scb and insert into the free scb list.
2824 *-F*************************************************************************/
2826 aic7xxx_free_scb(struct aic7xxx_host
*p
, struct aic7xxx_scb
*scb
)
2829 scb
->flags
= SCB_FREE
;
2833 scb
->tag_action
= 0;
2834 scb
->hscb
->control
= 0;
2835 scb
->hscb
->target_status
= 0;
2836 scb
->hscb
->target_channel_lun
= SCB_LIST_NULL
;
2838 scbq_insert_head(&p
->scb_data
->free_scbs
, scb
);
2841 /*+F*************************************************************************
2846 * Calls the higher level scsi done function and frees the scb.
2847 *-F*************************************************************************/
2849 aic7xxx_done(struct aic7xxx_host
*p
, struct aic7xxx_scb
*scb
)
2851 Scsi_Cmnd
*cmd
= scb
->cmd
;
2852 int tindex
= TARGET_INDEX(cmd
);
2853 struct aic7xxx_scb
*scbp
;
2854 unsigned char queue_depth
;
2856 if (scb
->flags
& SCB_RECOVERY_SCB
)
2858 p
->flags
&= ~AHC_ABORT_PENDING
;
2860 if (scb
->flags
& SCB_RESET
)
2862 cmd
->result
= (DID_RESET
<< 16) | (cmd
->result
& 0xffff);
2864 else if (scb
->flags
& SCB_ABORT
)
2866 cmd
->result
= (DID_RESET
<< 16) | (cmd
->result
& 0xffff);
2868 else if (!(p
->dev_flags
[tindex
] & DEVICE_SCANNED
))
2870 if ( (cmd
->cmnd
[0] == INQUIRY
) && (cmd
->result
== DID_OK
) )
2876 struct scatterlist
*sg
;
2878 sg
= (struct scatterlist
*)cmd
->request_buffer
;
2879 buffer
= (char *)sg
[0].address
;
2883 buffer
= (char *)cmd
->request_buffer
;
2885 #define WIDE_INQUIRY_BITS 0x60
2886 #define SYNC_INQUIRY_BITS 0x10
2887 if ( (buffer
[7] & WIDE_INQUIRY_BITS
) &&
2888 (p
->features
& AHC_WIDE
) )
2890 p
->needwdtr
|= (1<<tindex
);
2891 p
->needwdtr_copy
|= (1<<tindex
);
2892 if ( (p
->flags
& AHC_SEEPROM_FOUND
) &&
2893 (p
->transinfo
[tindex
].user_width
!= MSG_EXT_WDTR_BUS_16_BIT
) )
2894 p
->transinfo
[tindex
].goal_width
= MSG_EXT_WDTR_BUS_8_BIT
;
2896 p
->transinfo
[tindex
].goal_width
= MSG_EXT_WDTR_BUS_16_BIT
;
2900 p
->needwdtr
&= ~(1<<tindex
);
2901 p
->needwdtr_copy
&= ~(1<<tindex
);
2903 aic7xxx_set_width(p
, cmd
->target
, cmd
->channel
, cmd
->lun
,
2904 MSG_EXT_WDTR_BUS_8_BIT
, (AHC_TRANS_ACTIVE
|
2907 unpause_sequencer(p
, FALSE
);
2909 if (buffer
[7] & SYNC_INQUIRY_BITS
)
2911 p
->needsdtr
|= (1<<tindex
);
2912 p
->needsdtr_copy
|= (1<<tindex
);
2914 if (p
->flags
& AHC_SEEPROM_FOUND
)
2915 p
->transinfo
[tindex
].goal_period
= p
->transinfo
[tindex
].user_period
;
2916 else if (p
->features
& AHC_ULTRA2
)
2917 p
->transinfo
[tindex
].goal_period
=
2918 aic7xxx_syncrates
[AHC_SYNCRATE_ULTRA2
].period
;
2919 else if (p
->features
& AHC_ULTRA
)
2920 p
->transinfo
[tindex
].goal_period
=
2921 aic7xxx_syncrates
[AHC_SYNCRATE_ULTRA
].period
;
2923 p
->transinfo
[tindex
].goal_period
=
2924 aic7xxx_syncrates
[AHC_SYNCRATE_FAST
].period
;
2926 if (p
->features
& AHC_ULTRA2
)
2927 p
->transinfo
[tindex
].goal_offset
= MAX_OFFSET_ULTRA2
;
2928 else if (p
->transinfo
[tindex
].goal_width
== MSG_EXT_WDTR_BUS_16_BIT
)
2929 p
->transinfo
[tindex
].goal_offset
= MAX_OFFSET_16BIT
;
2931 p
->transinfo
[tindex
].goal_offset
= MAX_OFFSET_8BIT
;
2935 p
->needsdtr
&= ~(1<<tindex
);
2936 p
->needsdtr_copy
&= ~(1<<tindex
);
2937 p
->transinfo
[tindex
].goal_period
= 0;
2938 p
->transinfo
[tindex
].goal_offset
= 0;
2940 p
->dev_flags
[tindex
] |= DEVICE_SCANNED
;
2941 p
->dev_flags
[tindex
] |= DEVICE_PRINT_WDTR
| DEVICE_PRINT_SDTR
;
2942 #undef WIDE_INQUIRY_BITS
2943 #undef SYNC_INQUIRY_BITS
2946 else if ((scb
->flags
& (SCB_MSGOUT_WDTR
| SCB_MSGOUT_SDTR
)) != 0)
2948 unsigned short mask
;
2949 int message_error
= FALSE
;
2951 mask
= 0x01 << tindex
;
2954 * Check to see if we get an invalid message or a message error
2955 * after failing to negotiate a wide or sync transfer message.
2957 if ((scb
->flags
& SCB_SENSE
) &&
2958 ((scb
->cmd
->sense_buffer
[12] == 0x43) || /* INVALID_MESSAGE */
2959 (scb
->cmd
->sense_buffer
[12] == 0x49))) /* MESSAGE_ERROR */
2961 message_error
= TRUE
;
2964 if (scb
->flags
& SCB_MSGOUT_WDTR
)
2966 p
->wdtr_pending
&= ~mask
;
2969 if ( (aic7xxx_verbose
& VERBOSE_NEGOTIATION2
) &&
2970 (p
->dev_flags
[tindex
] & DEVICE_PRINT_WDTR
) )
2972 printk(INFO_LEAD
"Device failed to complete Wide Negotiation "
2973 "processing and\n", p
->host_no
, CTL_OF_SCB(scb
));
2974 printk(INFO_LEAD
"returned a sense error code for invalid message, "
2975 "disabling future\n", p
->host_no
, CTL_OF_SCB(scb
));
2976 printk(INFO_LEAD
"Wide negotiation to this device.\n", p
->host_no
,
2978 p
->dev_flags
[tindex
] &= ~DEVICE_PRINT_WDTR
;
2980 p
->needwdtr
&= ~mask
;
2981 p
->needwdtr_copy
&= ~mask
;
2984 if (scb
->flags
& SCB_MSGOUT_SDTR
)
2986 p
->sdtr_pending
&= ~mask
;
2989 if ( (aic7xxx_verbose
& VERBOSE_NEGOTIATION2
) &&
2990 (p
->dev_flags
[tindex
] & DEVICE_PRINT_SDTR
) )
2992 printk(INFO_LEAD
"Device failed to complete Sync Negotiation "
2993 "processing and\n", p
->host_no
, CTL_OF_SCB(scb
));
2994 printk(INFO_LEAD
"returned a sense error code for invalid message, "
2995 "disabling future\n", p
->host_no
, CTL_OF_SCB(scb
));
2996 printk(INFO_LEAD
"Sync negotiation to this device.\n", p
->host_no
,
2998 p
->dev_flags
[tindex
] &= ~DEVICE_PRINT_SDTR
;
3000 p
->needsdtr
&= ~mask
;
3001 p
->needsdtr_copy
&= ~mask
;
3005 queue_depth
= p
->dev_temp_queue_depth
[tindex
];
3006 if (queue_depth
>= p
->dev_active_cmds
[tindex
])
3008 scbp
= scbq_remove_head(&p
->delayed_scbs
[tindex
]);
3011 if (queue_depth
== 1)
3014 * Give extra preference to untagged devices, such as CD-R devices
3015 * This makes it more likely that a drive *won't* stuff up while
3016 * waiting on data at a critical time, such as CD-R writing and
3017 * audio CD ripping operations. Should also benefit tape drives.
3019 scbq_insert_head(&p
->waiting_scbs
, scbp
);
3023 scbq_insert_tail(&p
->waiting_scbs
, scbp
);
3025 #ifdef AIC7XXX_VERBOSE_DEBUGGING
3026 if (aic7xxx_verbose
> 0xffff)
3027 printk(INFO_LEAD
"Moving SCB from delayed to waiting queue.\n",
3028 p
->host_no
, CTL_OF_SCB(scbp
));
3030 if (queue_depth
> p
->dev_active_cmds
[tindex
])
3032 scbp
= scbq_remove_head(&p
->delayed_scbs
[tindex
]);
3034 scbq_insert_tail(&p
->waiting_scbs
, scbp
);
3038 if ( !(scb
->tag_action
) && (p
->tagenable
& (1<<tindex
)) )
3040 p
->dev_temp_queue_depth
[tindex
] = p
->dev_max_queue_depth
[tindex
];
3042 p
->dev_active_cmds
[tindex
]--;
3046 * If this was an untagged I/O, unbusy the target so the sequencer won't
3047 * mistake things later
3049 if (aic7xxx_index_busy_target(p
, scb
->hscb
->target_channel_lun
, FALSE
) ==
3052 aic7xxx_index_busy_target(p
, scb
->hscb
->target_channel_lun
, TRUE
);
3059 * XXX: we should actually know how much actually transferred
3060 * XXX: for each command, but apparently that's too difficult.
3062 * We set a lower limit of 512 bytes on the transfer length. We
3063 * ignore anything less than this because we don't have a real
3064 * reason to count it. Read/Writes to tapes are usually about 20K
3065 * and disks are a minimum of 512 bytes unless you want to count
3066 * non-read/write commands (such as TEST_UNIT_READY) which we don't
3068 actual
= scb
->sg_length
;
3069 if ((actual
>= 512) && (((cmd
->result
>> 16) & 0xf) == DID_OK
))
3071 struct aic7xxx_xferstats
*sp
;
3072 #ifdef AIC7XXX_PROC_STATS
3075 #endif /* AIC7XXX_PROC_STATS */
3077 sp
= &p
->stats
[TARGET_INDEX(cmd
)][cmd
->lun
& 0x7];
3079 #ifdef AIC7XXX_VERBOSE_DEBUGGING
3080 if ( (sp
->xfers
> 16) && (aic7xxx_verbose
> 0xffff) )
3081 aic7xxx_verbose
&= 0xffff;
3085 * For block devices, cmd->request.cmd is always == either READ or
3086 * WRITE. For character devices, this isn't always set properly, so
3087 * we check data_cmnd[0]. This catches the conditions for st.c, but
3088 * I'm still not sure if request.cmd is valid for sg devices.
3090 if ( (cmd
->request
.cmd
== WRITE
) || (cmd
->data_cmnd
[0] == WRITE_6
) ||
3091 (cmd
->data_cmnd
[0] == WRITE_FILEMARKS
) )
3094 sp
->w_total512
+= (actual
>> 9);
3095 #ifdef AIC7XXX_PROC_STATS
3097 #endif /* AIC7XXX_PROC_STATS */
3102 sp
->r_total512
+= (actual
>> 9);
3103 #ifdef AIC7XXX_PROC_STATS
3105 #endif /* AIC7XXX_PROC_STATS */
3107 #ifdef AIC7XXX_PROC_STATS
3108 for (x
= 9; x
<= 17; x
++)
3110 if (actual
< (1 << x
))
3120 #endif /* AIC7XXX_PROC_STATS */
3123 aic7xxx_free_scb(p
, scb
);
3124 aic7xxx_queue_cmd_complete(p
, cmd
);
3128 /*+F*************************************************************************
3130 * aic7xxx_run_done_queue
3133 * Calls the aic7xxx_done() for the Scsi_Cmnd of each scb in the
3134 * aborted list, and adds each scb to the free list. If complete
3135 * is TRUE, we also process the commands complete list.
3136 *-F*************************************************************************/
3138 aic7xxx_run_done_queue(struct aic7xxx_host
*p
, /*complete*/ int complete
)
3140 struct aic7xxx_scb
*scb
;
3143 for (i
= 0; i
< p
->scb_data
->numscbs
; i
++)
3145 scb
= p
->scb_data
->scb_array
[i
];
3146 if (scb
->flags
& SCB_QUEUED_FOR_DONE
)
3148 if (aic7xxx_verbose
& (VERBOSE_ABORT_PROCESS
| VERBOSE_RESET_PROCESS
))
3149 printk(INFO_LEAD
"Aborting scb %d\n",
3150 p
->host_no
, CTL_OF_SCB(scb
), scb
->hscb
->tag
);
3152 aic7xxx_done(p
, scb
);
3155 if (aic7xxx_verbose
& (VERBOSE_ABORT_RETURN
| VERBOSE_RESET_RETURN
))
3157 printk(INFO_LEAD
"%d commands found and queued for "
3158 "completion.\n", p
->host_no
, -1, -1, -1, found
);
3162 aic7xxx_done_cmds_complete(p
);
3166 /*+F*************************************************************************
3168 * aic7xxx_abort_waiting_scb
3171 * Manipulate the waiting for selection list and return the
3172 * scb that follows the one that we remove.
3173 *-F*************************************************************************/
3174 static unsigned char
3175 aic7xxx_abort_waiting_scb(struct aic7xxx_host
*p
, struct aic7xxx_scb
*scb
,
3176 unsigned char scbpos
, unsigned char prev
)
3178 unsigned char curscb
, next
;
3181 * Select the SCB we want to abort and pull the next pointer out of it.
3183 curscb
= aic_inb(p
, SCBPTR
);
3184 aic_outb(p
, scbpos
, SCBPTR
);
3185 next
= aic_inb(p
, SCB_NEXT
);
3187 aic7xxx_add_curscb_to_free_list(p
);
3190 * Update the waiting list
3192 if (prev
== SCB_LIST_NULL
)
3197 aic_outb(p
, next
, WAITING_SCBH
);
3202 * Select the scb that pointed to us and update its next pointer.
3204 aic_outb(p
, prev
, SCBPTR
);
3205 aic_outb(p
, next
, SCB_NEXT
);
3208 * Point us back at the original scb position and inform the SCSI
3209 * system that the command has been aborted.
3211 aic_outb(p
, curscb
, SCBPTR
);
3215 /*+F*************************************************************************
3217 * aic7xxx_search_qinfifo
3220 * Search the queue-in FIFO for matching SCBs and conditionally
3221 * requeue. Returns the number of matching SCBs.
3222 *-F*************************************************************************/
3224 aic7xxx_search_qinfifo(struct aic7xxx_host
*p
, int target
, int channel
,
3225 int lun
, unsigned char tag
, int flags
, int requeue
,
3226 volatile scb_queue_type
*queue
)
3229 unsigned char qinpos
, qintail
;
3230 struct aic7xxx_scb
*scbp
;
3233 qinpos
= aic_inb(p
, QINPOS
);
3234 qintail
= p
->qinfifonext
;
3236 p
->qinfifonext
= qinpos
;
3238 while (qinpos
!= qintail
)
3240 scbp
= p
->scb_data
->scb_array
[p
->qinfifo
[qinpos
++]];
3241 if (aic7xxx_match_scb(p
, scbp
, target
, channel
, lun
, tag
))
3244 * We found an scb that needs to be removed.
3246 if (requeue
&& (queue
!= NULL
))
3248 if (scbp
->flags
& SCB_WAITINGQ
)
3250 scbq_remove(queue
, scbp
);
3251 scbq_remove(&p
->waiting_scbs
, scbp
);
3252 scbq_remove(&p
->delayed_scbs
[TARGET_INDEX(scbp
->cmd
)], scbp
);
3253 p
->dev_active_cmds
[TARGET_INDEX(scbp
->cmd
)]++;
3256 scbq_insert_tail(queue
, scbp
);
3257 p
->dev_active_cmds
[TARGET_INDEX(scbp
->cmd
)]--;
3259 scbp
->flags
|= SCB_WAITINGQ
;
3260 if ( !(scbp
->tag_action
& TAG_ENB
) )
3262 aic7xxx_index_busy_target(p
, scbp
->hscb
->target_channel_lun
,
3268 p
->qinfifo
[p
->qinfifonext
++] = scbp
->hscb
->tag
;
3273 * Preserve any SCB_RECOVERY_SCB flags on this scb then set the
3274 * flags we were called with, presumeably so aic7xxx_run_done_queue
3277 scbp
->flags
= flags
| (scbp
->flags
& SCB_RECOVERY_SCB
);
3278 if (aic7xxx_index_busy_target(p
, scbp
->hscb
->target_channel_lun
,
3279 FALSE
) == scbp
->hscb
->tag
)
3281 aic7xxx_index_busy_target(p
, scbp
->hscb
->target_channel_lun
,
3289 p
->qinfifo
[p
->qinfifonext
++] = scbp
->hscb
->tag
;
3293 * Now that we've done the work, clear out any left over commands in the
3294 * qinfifo and update the KERNEL_QINPOS down on the card.
3296 * NOTE: This routine expect the sequencer to already be paused when
3297 * it is run....make sure it's that way!
3299 qinpos
= p
->qinfifonext
;
3300 while(qinpos
!= qintail
)
3302 p
->qinfifo
[qinpos
++] = SCB_LIST_NULL
;
3304 if (p
->features
& AHC_QUEUE_REGS
)
3305 aic_outb(p
, p
->qinfifonext
, HNSCB_QOFF
);
3307 aic_outb(p
, p
->qinfifonext
, KERNEL_QINPOS
);
3312 /*+F*************************************************************************
3314 * aic7xxx_scb_on_qoutfifo
3317 * Is the scb that was passed to us currently on the qoutfifo?
3318 *-F*************************************************************************/
3320 aic7xxx_scb_on_qoutfifo(struct aic7xxx_host
*p
, struct aic7xxx_scb
*scb
)
3324 while(p
->qoutfifo
[(p
->qoutfifonext
+ i
) & 0xff ] != SCB_LIST_NULL
)
3326 if(p
->qoutfifo
[(p
->qoutfifonext
+ i
) & 0xff ] == scb
->hscb
->tag
)
3335 /*+F*************************************************************************
3337 * aic7xxx_reset_device
3340 * The device at the given target/channel has been reset. Abort
3341 * all active and queued scbs for that target/channel. This function
3342 * need not worry about linked next pointers because if was a MSG_ABORT_TAG
3343 * then we had a tagged command (no linked next), if it was MSG_ABORT or
3344 * MSG_BUS_DEV_RESET then the device won't know about any commands any more
3345 * and no busy commands will exist, and if it was a bus reset, then nothing
3346 * knows about any linked next commands any more. In all cases, we don't
3347 * need to worry about the linked next or busy scb, we just need to clear
3349 *-F*************************************************************************/
3351 aic7xxx_reset_device(struct aic7xxx_host
*p
, int target
, int channel
,
3352 int lun
, unsigned char tag
)
3354 struct aic7xxx_scb
*scbp
;
3355 unsigned char active_scb
, tcl
;
3356 int i
= 0, j
, init_lists
= FALSE
;
3359 * Restore this when we're done
3361 active_scb
= aic_inb(p
, SCBPTR
);
3363 if (aic7xxx_verbose
& (VERBOSE_RESET_PROCESS
| VERBOSE_ABORT_PROCESS
))
3364 printk(INFO_LEAD
"Reset device, active_scb %d\n",
3365 p
->host_no
, channel
, target
, lun
, active_scb
);
3367 * Deal with the busy target and linked next issues.
3370 int min_target
, max_target
;
3371 struct aic7xxx_scb
*scbp
, *prev_scbp
;
3373 /* Make all targets 'relative' to bus A. */
3374 if (target
== ALL_TARGETS
)
3380 max_target
= (p
->features
& AHC_WIDE
) ? 15 : 7;
3389 max_target
= (p
->features
& (AHC_TWIN
|AHC_WIDE
)) ? 15 : 7;
3395 min_target
= target
| (channel
<< 3);
3396 max_target
= min_target
;
3400 for (i
= min_target
; i
<= max_target
; i
++)
3402 if (aic7xxx_verbose
& (VERBOSE_ABORT_PROCESS
| VERBOSE_RESET_PROCESS
))
3403 printk(INFO_LEAD
"Cleaning up status information "
3404 "and delayed_scbs.\n", p
->host_no
, channel
, i
, lun
);
3405 if ( !(p
->dev_flags
[i
] & DEVICE_TAGGED_SUCCESS
) &&
3406 (p
->dev_active_cmds
[i
]) &&
3407 (p
->tagenable
& (0x01 << i
)) )
3409 printk(INFO_LEAD
"Device appears to be choking on tagged commands.\n",
3410 p
->host_no
, channel
, i
, lun
);
3411 printk(INFO_LEAD
"Will use untagged I/O instead.\n", p
->host_no
,
3413 p
->dev_max_queue_depth
[i
] = 1;
3414 p
->dev_temp_queue_depth
[i
] = 1;
3415 p
->tagenable
&= ~(0x01 << i
);
3416 p
->orderedtag
&= ~(0x01 << i
);
3418 p
->dev_flags
[i
] &= ~BUS_DEVICE_RESET_PENDING
;
3419 if ( tag
== SCB_LIST_NULL
)
3421 p
->dev_flags
[i
] |= DEVICE_PRINT_WDTR
| DEVICE_PRINT_SDTR
;
3422 p
->dev_last_reset
[i
] = jiffies
;
3423 p
->dev_last_queue_full_count
[i
] = 0;
3424 p
->dev_last_queue_full
[i
] = 0;
3425 p
->dev_temp_queue_depth
[i
] =
3426 p
->dev_max_queue_depth
[i
];
3428 * In case this isn't a full bus reset, we want to add a 4 second timer in
3429 * here so that we can delay all re-sent commands for this device for the
3430 * 4 seconds and then have our timer routine pick them back up.
3432 del_timer(&p
->dev_timer
[i
]);
3433 p
->dev_timer
[i
].expires
= jiffies
+ (4 * HZ
);
3434 add_timer(&p
->dev_timer
[i
]);
3436 for(j
=0; j
<MAX_LUNS
; j
++)
3439 tcl
= ((i
<< 4) & 0x70) | (channel
<< 3) | j
;
3441 tcl
= (i
<< 4) | (channel
<< 3) | j
;
3442 if ( (aic7xxx_index_busy_target(p
, tcl
, FALSE
) == tag
) ||
3443 (tag
== SCB_LIST_NULL
) )
3444 aic7xxx_index_busy_target(p
, tcl
, /* unbusy */ TRUE
);
3448 scbp
= p
->delayed_scbs
[i
].head
;
3449 while ( (scbp
!= NULL
) && (j
++ <= (p
->scb_data
->numscbs
+ 1)) )
3452 scbp
= scbp
->q_next
;
3453 if ( prev_scbp
== scbp
)
3455 if (aic7xxx_verbose
& (VERBOSE_ABORT
| VERBOSE_RESET
))
3456 printk(WARN_LEAD
"Yikes!! scb->q_next == scb "
3457 "in the delayed_scbs queue!\n", p
->host_no
, channel
, i
, lun
);
3459 prev_scbp
->q_next
= NULL
;
3460 p
->delayed_scbs
[i
].tail
= prev_scbp
;
3462 if (aic7xxx_match_scb(p
, prev_scbp
, target
, channel
, lun
, tag
))
3464 scbq_remove(&p
->delayed_scbs
[i
], prev_scbp
);
3465 if (prev_scbp
->flags
& SCB_WAITINGQ
)
3467 p
->dev_active_cmds
[i
]++;
3470 prev_scbp
->flags
&= ~(SCB_ACTIVE
| SCB_WAITINGQ
);
3471 prev_scbp
->flags
|= SCB_RESET
| SCB_QUEUED_FOR_DONE
;
3474 if ( j
> (p
->scb_data
->maxscbs
+ 1) )
3476 if (aic7xxx_verbose
& (VERBOSE_ABORT
| VERBOSE_RESET
))
3477 printk(WARN_LEAD
"Yikes!! There's a loop in the "
3478 "delayed_scbs queue!\n", p
->host_no
, channel
, i
, lun
);
3479 scbq_init(&p
->delayed_scbs
[i
]);
3481 if ( p
->delayed_scbs
[i
].head
== NULL
)
3482 del_timer(&p
->dev_timer
[i
]);
3486 if (aic7xxx_verbose
& (VERBOSE_ABORT_PROCESS
| VERBOSE_RESET_PROCESS
))
3487 printk(INFO_LEAD
"Cleaning QINFIFO.\n", p
->host_no
, channel
, target
, lun
);
3488 aic7xxx_search_qinfifo(p
, target
, channel
, lun
, tag
,
3489 SCB_RESET
| SCB_QUEUED_FOR_DONE
, /* requeue */ FALSE
, NULL
);
3492 * Search the waiting_scbs queue for matches, this catches any SCB_QUEUED
3493 * ABORT/RESET commands.
3495 if (aic7xxx_verbose
& (VERBOSE_ABORT_PROCESS
| VERBOSE_RESET_PROCESS
))
3496 printk(INFO_LEAD
"Cleaning waiting_scbs.\n", p
->host_no
, channel
,
3499 struct aic7xxx_scb
*scbp
, *prev_scbp
;
3503 scbp
= p
->waiting_scbs
.head
;
3504 while ( (scbp
!= NULL
) && (j
++ <= (p
->scb_data
->numscbs
+ 1)) )
3507 scbp
= scbp
->q_next
;
3508 if ( prev_scbp
== scbp
)
3510 if (aic7xxx_verbose
& (VERBOSE_ABORT
| VERBOSE_RESET
))
3511 printk(WARN_LEAD
"Yikes!! scb->q_next == scb "
3512 "in the waiting_scbs queue!\n", p
->host_no
, CTL_OF_SCB(scbp
));
3514 prev_scbp
->q_next
= NULL
;
3515 p
->waiting_scbs
.tail
= prev_scbp
;
3517 if (aic7xxx_match_scb(p
, prev_scbp
, target
, channel
, lun
, tag
))
3519 scbq_remove(&p
->waiting_scbs
, prev_scbp
);
3520 if (prev_scbp
->flags
& SCB_WAITINGQ
)
3522 p
->dev_active_cmds
[TARGET_INDEX(prev_scbp
->cmd
)]++;
3525 prev_scbp
->flags
&= ~(SCB_ACTIVE
| SCB_WAITINGQ
);
3526 prev_scbp
->flags
|= SCB_RESET
| SCB_QUEUED_FOR_DONE
;
3529 if ( j
> (p
->scb_data
->maxscbs
+ 1) )
3531 if (aic7xxx_verbose
& (VERBOSE_ABORT
| VERBOSE_RESET
))
3532 printk(WARN_LEAD
"Yikes!! There's a loop in the "
3533 "waiting_scbs queue!\n", p
->host_no
, channel
, target
, lun
);
3534 scbq_init(&p
->waiting_scbs
);
3540 * Search waiting for selection list.
3542 if (aic7xxx_verbose
& (VERBOSE_ABORT_PROCESS
| VERBOSE_RESET_PROCESS
))
3543 printk(INFO_LEAD
"Cleaning waiting for selection "
3544 "list.\n", p
->host_no
, channel
, target
, lun
);
3546 unsigned char next
, prev
, scb_index
;
3548 next
= aic_inb(p
, WAITING_SCBH
); /* Start at head of list. */
3549 prev
= SCB_LIST_NULL
;
3551 while ( (next
!= SCB_LIST_NULL
) && (j
++ <= (p
->scb_data
->maxscbs
+ 1)) )
3553 aic_outb(p
, next
, SCBPTR
);
3554 scb_index
= aic_inb(p
, SCB_TAG
);
3555 if (scb_index
>= p
->scb_data
->numscbs
)
3558 * No aic7xxx_verbose check here.....we want to see this since it
3559 * means either the kernel driver or the sequencer screwed things up
3561 printk(WARN_LEAD
"Waiting List inconsistency; SCB index=%d, "
3562 "numscbs=%d\n", p
->host_no
, channel
, target
, lun
, scb_index
,
3563 p
->scb_data
->numscbs
);
3564 next
= aic_inb(p
, SCB_NEXT
);
3565 aic7xxx_add_curscb_to_free_list(p
);
3569 scbp
= p
->scb_data
->scb_array
[scb_index
];
3570 if (aic7xxx_match_scb(p
, scbp
, target
, channel
, lun
, tag
))
3572 next
= aic7xxx_abort_waiting_scb(p
, scbp
, next
, prev
);
3573 if (scbp
->flags
& SCB_WAITINGQ
)
3575 p
->dev_active_cmds
[TARGET_INDEX(scbp
->cmd
)]++;
3578 scbp
->flags
&= ~(SCB_ACTIVE
| SCB_WAITINGQ
);
3579 scbp
->flags
|= SCB_RESET
| SCB_QUEUED_FOR_DONE
;
3580 if (prev
== SCB_LIST_NULL
)
3583 * This is either the first scb on the waiting list, or we
3584 * have already yanked the first and haven't left any behind.
3585 * Either way, we need to turn off the selection hardware if
3586 * it isn't already off.
3588 aic_outb(p
, aic_inb(p
, SCSISEQ
) & ~ENSELO
, SCSISEQ
);
3589 aic_outb(p
, CLRSELTIMEO
, CLRSINT1
);
3595 next
= aic_inb(p
, SCB_NEXT
);
3599 if ( j
> (p
->scb_data
->maxscbs
+ 1) )
3601 printk(WARN_LEAD
"Yikes!! There is a loop in the waiting for "
3602 "selection list!\n", p
->host_no
, channel
, target
, lun
);
3608 * Go through disconnected list and remove any entries we have queued
3609 * for completion, zeroing their control byte too.
3611 if (aic7xxx_verbose
& (VERBOSE_ABORT_PROCESS
| VERBOSE_RESET_PROCESS
))
3612 printk(INFO_LEAD
"Cleaning disconnected scbs "
3613 "list.\n", p
->host_no
, channel
, target
, lun
);
3614 if (p
->features
& AHC_PAGESCBS
)
3616 unsigned char next
, prev
, scb_index
;
3618 next
= aic_inb(p
, DISCONNECTED_SCBH
);
3619 prev
= SCB_LIST_NULL
;
3621 while ( (next
!= SCB_LIST_NULL
) && (j
++ <= (p
->scb_data
->maxscbs
+ 1)) )
3623 aic_outb(p
, next
, SCBPTR
);
3624 scb_index
= aic_inb(p
, SCB_TAG
);
3625 if (scb_index
> p
->scb_data
->numscbs
)
3627 printk(WARN_LEAD
"Disconnected List inconsistency; SCB index=%d, "
3628 "numscbs=%d\n", p
->host_no
, channel
, target
, lun
, scb_index
,
3629 p
->scb_data
->numscbs
);
3630 next
= aic7xxx_rem_scb_from_disc_list(p
, next
);
3634 scbp
= p
->scb_data
->scb_array
[scb_index
];
3635 if (aic7xxx_match_scb(p
, scbp
, target
, channel
, lun
, tag
))
3637 next
= aic7xxx_rem_scb_from_disc_list(p
, next
);
3638 if (scbp
->flags
& SCB_WAITINGQ
)
3640 p
->dev_active_cmds
[TARGET_INDEX(scbp
->cmd
)]++;
3643 scbp
->flags
&= ~(SCB_ACTIVE
| SCB_WAITINGQ
);
3644 scbp
->flags
|= SCB_RESET
| SCB_QUEUED_FOR_DONE
;
3645 scbp
->hscb
->control
= 0;
3650 next
= aic_inb(p
, SCB_NEXT
);
3654 if ( j
> (p
->scb_data
->maxscbs
+ 1) )
3656 printk(WARN_LEAD
"Yikes!! There is a loop in the disconnected list!\n",
3657 p
->host_no
, channel
, target
, lun
);
3663 * Walk the free list making sure no entries on the free list have
3664 * a valid SCB_TAG value or SCB_CONTROL byte.
3666 if (p
->features
& AHC_PAGESCBS
)
3671 next
= aic_inb(p
, FREE_SCBH
);
3672 if ( (next
>= p
->scb_data
->maxhscbs
) && (next
!= SCB_LIST_NULL
) )
3674 printk(WARN_LEAD
"Bogus FREE_SCBH!.\n", p
->host_no
, channel
,
3677 next
= SCB_LIST_NULL
;
3679 while ( (next
!= SCB_LIST_NULL
) && (j
++ <= (p
->scb_data
->maxscbs
+ 1)) )
3681 aic_outb(p
, next
, SCBPTR
);
3682 if (aic_inb(p
, SCB_TAG
) < p
->scb_data
->numscbs
)
3684 printk(WARN_LEAD
"Free list inconsistency!.\n", p
->host_no
, channel
,
3687 next
= SCB_LIST_NULL
;
3691 aic_outb(p
, SCB_LIST_NULL
, SCB_TAG
);
3692 aic_outb(p
, 0, SCB_CONTROL
);
3693 next
= aic_inb(p
, SCB_NEXT
);
3696 if ( j
> (p
->scb_data
->maxscbs
+ 1) )
3698 printk(WARN_LEAD
"Yikes!! There is a loop in the free list!\n",
3699 p
->host_no
, channel
, target
, lun
);
3705 * Go through the hardware SCB array looking for commands that
3706 * were active but not on any list.
3710 aic_outb(p
, SCB_LIST_NULL
, FREE_SCBH
);
3711 aic_outb(p
, SCB_LIST_NULL
, WAITING_SCBH
);
3712 aic_outb(p
, SCB_LIST_NULL
, DISCONNECTED_SCBH
);
3714 for (i
= p
->scb_data
->maxhscbs
- 1; i
>= 0; i
--)
3716 unsigned char scbid
;
3718 aic_outb(p
, i
, SCBPTR
);
3721 aic_outb(p
, SCB_LIST_NULL
, SCB_TAG
);
3722 aic_outb(p
, SCB_LIST_NULL
, SCB_NEXT
);
3723 aic_outb(p
, SCB_LIST_NULL
, SCB_PREV
);
3724 aic_outb(p
, 0, SCB_CONTROL
);
3725 aic7xxx_add_curscb_to_free_list(p
);
3729 scbid
= aic_inb(p
, SCB_TAG
);
3730 if (scbid
< p
->scb_data
->numscbs
)
3732 scbp
= p
->scb_data
->scb_array
[scbid
];
3733 if (aic7xxx_match_scb(p
, scbp
, target
, channel
, lun
, tag
))
3735 aic_outb(p
, 0, SCB_CONTROL
);
3736 aic_outb(p
, SCB_LIST_NULL
, SCB_TAG
);
3737 aic7xxx_add_curscb_to_free_list(p
);
3744 * Go through the entire SCB array now and look for commands for
3745 * for this target that are stillactive. These are other (most likely
3746 * tagged) commands that were disconnected when the reset occurred.
3747 * Any commands we find here we know this about, it wasn't on any queue,
3748 * it wasn't in the qinfifo, it wasn't in the disconnected or waiting
3749 * lists, so it really must have been a paged out SCB. In that case,
3750 * we shouldn't need to bother with updating any counters, just mark
3751 * the correct flags and go on.
3753 for (i
= 0; i
< p
->scb_data
->numscbs
; i
++)
3755 scbp
= p
->scb_data
->scb_array
[i
];
3756 if ((scbp
->flags
& SCB_ACTIVE
) &&
3757 aic7xxx_match_scb(p
, scbp
, target
, channel
, lun
, tag
) &&
3758 !aic7xxx_scb_on_qoutfifo(p
, scbp
))
3760 if (scbp
->flags
& SCB_WAITINGQ
)
3762 scbq_remove(&p
->waiting_scbs
, scbp
);
3763 scbq_remove(&p
->delayed_scbs
[TARGET_INDEX(scbp
->cmd
)], scbp
);
3764 p
->dev_active_cmds
[TARGET_INDEX(scbp
->cmd
)]++;
3767 scbp
->flags
|= SCB_RESET
| SCB_QUEUED_FOR_DONE
;
3768 scbp
->flags
&= ~(SCB_ACTIVE
| SCB_WAITINGQ
);
3772 aic_outb(p
, active_scb
, SCBPTR
);
3776 /*+F*************************************************************************
3778 * aic7xxx_clear_intstat
3781 * Clears the interrupt status.
3782 *-F*************************************************************************/
3784 aic7xxx_clear_intstat(struct aic7xxx_host
*p
)
3786 /* Clear any interrupt conditions this may have caused. */
3787 aic_outb(p
, CLRSELDO
| CLRSELDI
| CLRSELINGO
, CLRSINT0
);
3788 aic_outb(p
, CLRSELTIMEO
| CLRATNO
| CLRSCSIRSTI
| CLRBUSFREE
| CLRSCSIPERR
|
3789 CLRPHASECHG
| CLRREQINIT
, CLRSINT1
);
3790 aic_outb(p
, CLRSCSIINT
| CLRSEQINT
| CLRBRKADRINT
| CLRPARERR
, CLRINT
);
3793 /*+F*************************************************************************
3795 * aic7xxx_reset_current_bus
3798 * Reset the current SCSI bus.
3799 *-F*************************************************************************/
3801 aic7xxx_reset_current_bus(struct aic7xxx_host
*p
)
3804 /* Disable reset interrupts. */
3805 aic_outb(p
, aic_inb(p
, SIMODE1
) & ~ENSCSIRST
, SIMODE1
);
3807 /* Turn off the bus' current operations, after all, we shouldn't have any
3808 * valid commands left to cause a RSELI and SELO once we've tossed the
3809 * bus away with this reset, so we might as well shut down the sequencer
3810 * until the bus is restarted as oppossed to saving the current settings
3811 * and restoring them (which makes no sense to me). */
3813 /* Turn on the bus reset. */
3814 aic_outb(p
, aic_inb(p
, SCSISEQ
) | SCSIRSTO
, SCSISEQ
);
3815 while ( (aic_inb(p
, SCSISEQ
) & SCSIRSTO
) == 0)
3820 /* Turn off the bus reset. */
3821 aic_outb(p
, 0, SCSISEQ
);
3824 aic7xxx_clear_intstat(p
);
3825 /* Re-enable reset interrupts. */
3826 aic_outb(p
, aic_inb(p
, SIMODE1
) | ENSCSIRST
, SIMODE1
);
3830 /*+F*************************************************************************
3832 * aic7xxx_reset_channel
3835 * Reset the channel.
3836 *-F*************************************************************************/
3838 aic7xxx_reset_channel(struct aic7xxx_host
*p
, int channel
, int initiate_reset
)
3840 unsigned long offset_min
, offset_max
;
3841 unsigned char sblkctl
;
3844 if (aic7xxx_verbose
& VERBOSE_RESET_PROCESS
)
3845 printk(INFO_LEAD
"Reset channel called, %s initiate reset.\n",
3846 p
->host_no
, channel
, -1, -1, (initiate_reset
==TRUE
) ? "will" : "won't" );
3851 p
->needsdtr
|= (p
->needsdtr_copy
& 0xFF00);
3852 p
->sdtr_pending
&= 0x00FF;
3858 if (p
->features
& AHC_WIDE
)
3860 p
->needsdtr
= p
->needsdtr_copy
;
3861 p
->needwdtr
= p
->needwdtr_copy
;
3862 p
->sdtr_pending
= 0x0;
3863 p
->wdtr_pending
= 0x0;
3870 p
->needsdtr
|= (p
->needsdtr_copy
& 0x00FF);
3871 p
->sdtr_pending
&= 0xFF00;
3877 while (offset_min
< offset_max
)
3880 * Revert to async/narrow transfers until we renegotiate.
3882 aic_outb(p
, 0, TARG_SCSIRATE
+ offset_min
);
3883 if (p
->features
& AHC_ULTRA2
)
3885 aic_outb(p
, 0, TARG_OFFSET
+ offset_min
);
3891 * Reset the bus and unpause/restart the controller
3893 sblkctl
= aic_inb(p
, SBLKCTL
);
3894 if ( (p
->chip
& AHC_CHIPID_MASK
) == AHC_AIC7770
)
3895 cur_channel
= (sblkctl
& SELBUSB
) >> 3;
3898 if ( (cur_channel
!= channel
) && (p
->features
& AHC_TWIN
) )
3901 * Case 1: Command for another bus is active
3903 if (aic7xxx_verbose
& VERBOSE_RESET_PROCESS
)
3904 printk(INFO_LEAD
"Stealthily resetting idle channel.\n", p
->host_no
,
3907 * Stealthily reset the other bus without upsetting the current bus.
3909 aic_outb(p
, sblkctl
^ SELBUSB
, SBLKCTL
);
3910 aic_outb(p
, aic_inb(p
, SIMODE1
) & ~ENBUSFREE
, SIMODE1
);
3913 aic7xxx_reset_current_bus(p
);
3915 aic_outb(p
, aic_inb(p
, SCSISEQ
) & (ENSELI
|ENRSELI
|ENAUTOATNP
), SCSISEQ
);
3916 aic7xxx_clear_intstat(p
);
3917 aic_outb(p
, sblkctl
, SBLKCTL
);
3922 * Case 2: A command from this bus is active or we're idle.
3924 if (aic7xxx_verbose
& VERBOSE_RESET_PROCESS
)
3925 printk(INFO_LEAD
"Resetting currently active channel.\n", p
->host_no
,
3927 aic_outb(p
, aic_inb(p
, SIMODE1
) & ~(ENBUSFREE
|ENREQINIT
),
3929 p
->flags
&= ~AHC_HANDLING_REQINITS
;
3930 p
->msg_type
= MSG_TYPE_NONE
;
3934 aic7xxx_reset_current_bus(p
);
3936 aic_outb(p
, aic_inb(p
, SCSISEQ
) & (ENSELI
|ENRSELI
|ENAUTOATNP
), SCSISEQ
);
3937 aic7xxx_clear_intstat(p
);
3939 if (aic7xxx_verbose
& VERBOSE_RESET_RETURN
)
3940 printk(INFO_LEAD
"Channel reset\n", p
->host_no
, channel
, -1, -1);
3942 * Clean up all the state information for the pending transactions
3945 aic7xxx_reset_device(p
, ALL_TARGETS
, channel
, ALL_LUNS
, SCB_LIST_NULL
);
3948 * Convince Mid Level SCSI code to leave us be for a little bit...
3950 p
->last_reset
= jiffies
;
3951 p
->host
->last_reset
= (jiffies
+ (HZ
* AIC7XXX_RESET_DELAY
));
3953 if ( !(p
->features
& AHC_TWIN
) )
3955 restart_sequencer(p
);
3961 /*+F*************************************************************************
3963 * aic7xxx_run_waiting_queues
3966 * Scan the awaiting_scbs queue downloading and starting as many
3968 *-F*************************************************************************/
3970 aic7xxx_run_waiting_queues(struct aic7xxx_host
*p
)
3972 struct aic7xxx_scb
*scb
;
3975 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,1,95)
3976 unsigned long cpu_flags
= 0;
3980 if (p
->waiting_scbs
.head
== NULL
)
3986 * First handle SCBs that are waiting but have been assigned a slot.
3989 while ((scb
= scbq_remove_head(&p
->waiting_scbs
)) != NULL
)
3991 tindex
= TARGET_INDEX(scb
->cmd
);
3992 if ( !scb
->tag_action
&& (p
->tagenable
& (1<<tindex
)) )
3994 #ifdef AIC7XXX_VERBOSE_DEBUGGING
3995 if (aic7xxx_verbose
> 0xffff)
3996 printk(INFO_LEAD
"Reducing Queue depth for untagged command.\n",
3997 p
->host_no
, CTL_OF_SCB(scb
));
3999 p
->dev_temp_queue_depth
[tindex
] = 1;
4001 if ( (p
->dev_active_cmds
[tindex
] >=
4002 p
->dev_temp_queue_depth
[tindex
]) ||
4003 time_after_eq(p
->dev_last_reset
[tindex
], jiffies
- 4 * HZ
) )
4005 #ifdef AIC7XXX_VERBOSE_DEBUGGING
4006 if (aic7xxx_verbose
> 0xffff)
4007 printk(INFO_LEAD
"Moving SCB to Delayed Queue.\n",
4008 p
->host_no
, CTL_OF_SCB(scb
));
4010 scbq_insert_tail(&p
->delayed_scbs
[tindex
], scb
);
4011 if ( !timer_pending(&p
->dev_timer
[tindex
]) &&
4012 !(p
->dev_active_cmds
[tindex
]) )
4014 p
->dev_timer
[tindex
].expires
= p
->dev_last_reset
[tindex
] + (4 * HZ
);
4015 add_timer(&p
->dev_timer
[tindex
]);
4020 scb
->flags
&= ~SCB_WAITINGQ
;
4021 #ifdef AIC7XXX_VERBOSE_DEBUGGING
4022 if (aic7xxx_verbose
> 0xffff)
4023 printk(INFO_LEAD
"Sending command %d/0x%x to QINFIFO\n", p
->host_no
,
4024 CTL_OF_SCB(scb
), scb
->hscb
->tag
, scb
->flags
);
4026 p
->dev_active_cmds
[tindex
]++;
4028 if ( !(scb
->tag_action
) )
4030 aic7xxx_busy_target(p
, scb
);
4032 p
->qinfifo
[p
->qinfifonext
++] = scb
->hscb
->tag
;
4038 #ifdef AIC7XXX_VERBOSE_DEBUGGING
4039 if (aic7xxx_verbose
> 0xffff)
4041 printk(INFO_LEAD
"Sending commands to QINFIFO\n", p
->host_no
,
4043 if ( (p
->isr_count
< 16) && (aic7xxx_panic_on_abort
) &&
4044 (p
->flags
& AHC_PAGESCBS
) )
4045 aic7xxx_check_scbs(p
, "While sending commands to QINFIFO");
4048 if (p
->features
& AHC_QUEUE_REGS
)
4049 aic_outb(p
, p
->qinfifonext
, HNSCB_QOFF
);
4053 aic_outb(p
, p
->qinfifonext
, KERNEL_QINPOS
);
4054 unpause_sequencer(p
, FALSE
);
4056 if (p
->activescbs
> p
->max_activescbs
)
4057 p
->max_activescbs
= p
->activescbs
;
4071 /*+F*************************************************************************
4076 * Check the scsi card for PCI errors and clear the interrupt
4078 * NOTE: If you don't have this function and a 2940 card encounters
4079 * a PCI error condition, the machine will end up locked as the
4080 * interrupt handler gets slammed with non-stop PCI error interrupts
4081 *-F*************************************************************************/
4083 aic7xxx_pci_intr(struct aic7xxx_host
*p
)
4085 unsigned char status1
;
4087 #if LINUX_VERSION_CODE > KERNEL_VERSION(2,1,92)
4088 pci_read_config_byte(p
->pdev
, PCI_STATUS
+ 1, &status1
);
4090 pcibios_read_config_byte(p
->pci_bus
, p
->pci_device_fn
,
4091 PCI_STATUS
+ 1, &status1
);
4094 if ( (status1
& DPE
) && (aic7xxx_verbose
& VERBOSE_MINOR_ERROR
) )
4095 printk(WARN_LEAD
"Data Parity Error during PCI address or PCI write"
4096 "phase.\n", p
->host_no
, -1, -1, -1);
4097 if ( (status1
& SSE
) && (aic7xxx_verbose
& VERBOSE_MINOR_ERROR
) )
4098 printk(WARN_LEAD
"Signal System Error Detected\n", p
->host_no
,
4100 if ( (status1
& RMA
) && (aic7xxx_verbose
& VERBOSE_MINOR_ERROR
) )
4101 printk(WARN_LEAD
"Received a PCI Master Abort\n", p
->host_no
,
4103 if ( (status1
& RTA
) && (aic7xxx_verbose
& VERBOSE_MINOR_ERROR
) )
4104 printk(WARN_LEAD
"Received a PCI Target Abort\n", p
->host_no
,
4106 if ( (status1
& STA
) && (aic7xxx_verbose
& VERBOSE_MINOR_ERROR
) )
4107 printk(WARN_LEAD
"Signaled a PCI Target Abort\n", p
->host_no
,
4109 if ( (status1
& DPR
) && (aic7xxx_verbose
& VERBOSE_MINOR_ERROR
) )
4110 printk(WARN_LEAD
"Data Parity Error has been reported via PCI pin "
4111 "PERR#\n", p
->host_no
, -1, -1, -1);
4113 #if LINUX_VERSION_CODE > KERNEL_VERSION(2,1,92)
4114 pci_write_config_byte(p
->pdev
, PCI_STATUS
+ 1, status1
);
4116 pcibios_write_config_byte(p
->pci_bus
, p
->pci_device_fn
,
4117 PCI_STATUS
+ 1, status1
);
4119 if (status1
& (DPR
|RMA
|RTA
))
4120 aic_outb(p
, CLRPARERR
, CLRINT
);
4122 if ( (aic7xxx_panic_on_abort
) && (p
->spurious_int
> 500) )
4123 aic7xxx_panic_abort(p
, NULL
);
4126 #endif /* CONFIG_PCI */
4128 /*+F*************************************************************************
4133 * Take expired extries off of delayed queues and place on waiting queue
4134 * then run waiting queue to start commands.
4135 ***************************************************************************/
4137 aic7xxx_timer(struct aic7xxx_host
*p
)
4140 unsigned long cpu_flags
= 0;
4141 struct aic7xxx_scb
*scb
;
4143 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,1,95)
4146 spin_lock_irqsave(&io_request_lock
, cpu_flags
);
4148 for(i
=0; i
<MAX_TARGETS
; i
++)
4150 if ( del_timer(&p
->dev_timer
[i
]) )
4152 p
->dev_temp_queue_depth
[i
] = p
->dev_max_queue_depth
[i
];
4154 while ( ((scb
= scbq_remove_head(&p
->delayed_scbs
[i
])) != NULL
) &&
4155 (j
++ < p
->scb_data
->numscbs
) )
4157 scbq_insert_tail(&p
->waiting_scbs
, scb
);
4159 if (j
== p
->scb_data
->numscbs
)
4161 printk(INFO_LEAD
"timer: Yikes, loop in delayed_scbs list.\n",
4162 p
->host_no
, 0, i
, -1);
4163 scbq_init(&p
->delayed_scbs
[i
]);
4164 scbq_init(&p
->waiting_scbs
);
4166 * Well, things are screwed now, wait for a reset to clean the junk
4172 aic7xxx_run_waiting_queues(p
);
4173 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,1,95)
4176 spin_unlock_irqrestore(&io_request_lock
, cpu_flags
);
4180 /*+F*************************************************************************
4182 * aic7xxx_construct_sdtr
4185 * Constucts a synchronous data transfer message in the message
4186 * buffer on the sequencer.
4187 *-F*************************************************************************/
4189 aic7xxx_construct_sdtr(struct aic7xxx_host
*p
, unsigned char period
,
4190 unsigned char offset
)
4192 p
->msg_buf
[p
->msg_index
++] = MSG_EXTENDED
;
4193 p
->msg_buf
[p
->msg_index
++] = MSG_EXT_SDTR_LEN
;
4194 p
->msg_buf
[p
->msg_index
++] = MSG_EXT_SDTR
;
4195 p
->msg_buf
[p
->msg_index
++] = period
;
4196 p
->msg_buf
[p
->msg_index
++] = offset
;
4200 /*+F*************************************************************************
4202 * aic7xxx_construct_wdtr
4205 * Constucts a wide data transfer message in the message buffer
4207 *-F*************************************************************************/
4209 aic7xxx_construct_wdtr(struct aic7xxx_host
*p
, unsigned char bus_width
)
4211 p
->msg_buf
[p
->msg_index
++] = MSG_EXTENDED
;
4212 p
->msg_buf
[p
->msg_index
++] = MSG_EXT_WDTR_LEN
;
4213 p
->msg_buf
[p
->msg_index
++] = MSG_EXT_WDTR
;
4214 p
->msg_buf
[p
->msg_index
++] = bus_width
;
4218 /*+F*************************************************************************
4220 * aic7xxx_calc_residual
4223 * Calculate the residual data not yet transferred.
4224 *-F*************************************************************************/
4226 aic7xxx_calculate_residual (struct aic7xxx_host
*p
, struct aic7xxx_scb
*scb
)
4228 struct aic7xxx_hwscb
*hscb
;
4236 * Don't destroy valid residual information with
4237 * residual coming from a check sense operation.
4239 if (((scb
->hscb
->control
& DISCONNECTED
) == 0) &&
4240 (scb
->flags
& SCB_SENSE
) == 0)
4243 * We had an underflow. At this time, there's only
4244 * one other driver that bothers to check for this,
4245 * and cmd->underflow seems to be set rather half-
4246 * heartedly in the higher-level SCSI code.
4248 actual
= scb
->sg_length
;
4249 for (i
=1; i
< hscb
->residual_SG_segment_count
; i
++)
4251 actual
-= scb
->sg_list
[scb
->sg_count
- i
].length
;
4253 actual
-= (hscb
->residual_data_count
[2] << 16) |
4254 (hscb
->residual_data_count
[1] << 8) |
4255 hscb
->residual_data_count
[0];
4257 if (actual
< cmd
->underflow
)
4259 if (aic7xxx_verbose
& VERBOSE_MINOR_ERROR
)
4260 printk(INFO_LEAD
"Underflow - Wanted %u, %s %u, residual SG "
4261 "count %d.\n", p
->host_no
, CTL_OF_SCB(scb
), cmd
->underflow
,
4262 (cmd
->request
.cmd
== WRITE
) ? "wrote" : "read", actual
,
4263 hscb
->residual_SG_segment_count
);
4264 aic7xxx_error(cmd
) = DID_RETRY_COMMAND
;
4265 aic7xxx_status(cmd
) = hscb
->target_status
;
4270 * Clean out the residual information in the SCB for the
4273 hscb
->residual_data_count
[2] = 0;
4274 hscb
->residual_data_count
[1] = 0;
4275 hscb
->residual_data_count
[0] = 0;
4276 hscb
->residual_SG_segment_count
= 0;
4279 /*+F*************************************************************************
4281 * aic7xxx_handle_device_reset
4284 * Interrupt handler for sequencer interrupts (SEQINT).
4285 *-F*************************************************************************/
4287 aic7xxx_handle_device_reset(struct aic7xxx_host
*p
, int target
, int channel
)
4289 unsigned short targ_mask
;
4290 unsigned char tindex
= target
;
4292 tindex
|= ((channel
& 0x01) << 3);
4294 targ_mask
= (0x01 << tindex
);
4296 * Go back to async/narrow transfers and renegotiate.
4298 p
->needsdtr
|= (p
->needsdtr_copy
& targ_mask
);
4299 p
->needwdtr
|= (p
->needwdtr_copy
& targ_mask
);
4300 p
->sdtr_pending
&= ~targ_mask
;
4301 p
->wdtr_pending
&= ~targ_mask
;
4302 aic_outb(p
, 0, TARG_SCSIRATE
+ tindex
);
4303 if (p
->features
& AHC_ULTRA2
)
4304 aic_outb(p
, 0, TARG_OFFSET
+ tindex
);
4305 aic7xxx_reset_device(p
, target
, channel
, ALL_LUNS
, SCB_LIST_NULL
);
4306 if (aic7xxx_verbose
& VERBOSE_RESET_PROCESS
)
4307 printk(INFO_LEAD
"Bus Device Reset delivered.\n", p
->host_no
, channel
,
4309 aic7xxx_run_done_queue(p
, /*complete*/ FALSE
);
4312 /*+F*************************************************************************
4314 * aic7xxx_handle_seqint
4317 * Interrupt handler for sequencer interrupts (SEQINT).
4318 *-F*************************************************************************/
4320 aic7xxx_handle_seqint(struct aic7xxx_host
*p
, unsigned char intstat
)
4322 struct aic7xxx_scb
*scb
;
4323 unsigned short target_mask
;
4324 unsigned char target
, lun
, tindex
;
4325 unsigned char queue_flag
= FALSE
;
4328 target
= ((aic_inb(p
, SAVED_TCL
) >> 4) & 0x0f);
4329 if ( (p
->chip
& AHC_CHIPID_MASK
) == AHC_AIC7770
)
4330 channel
= (aic_inb(p
, SBLKCTL
) & SELBUSB
) >> 3;
4333 tindex
= target
+ (channel
<< 3);
4334 lun
= aic_inb(p
, SAVED_TCL
) & 0x07;
4335 target_mask
= (0x01 << tindex
);
4338 * Go ahead and clear the SEQINT now, that avoids any interrupt race
4339 * conditions later on in case we enable some other interrupt.
4341 aic_outb(p
, CLRSEQINT
, CLRINT
);
4342 switch (intstat
& SEQINT_MASK
)
4346 aic_outb(p
, aic_inb(p
, SCSISEQ
) & (ENSELI
|ENRSELI
|ENAUTOATNP
),
4348 printk(WARN_LEAD
"No active SCB for reconnecting target - Issuing "
4349 "BUS DEVICE RESET.\n", p
->host_no
, channel
, target
, lun
);
4350 printk(WARN_LEAD
" SAVED_TCL=0x%x, ARG_1=0x%x, SEQADDR=0x%x\n",
4351 p
->host_no
, channel
, target
, lun
,
4352 aic_inb(p
, SAVED_TCL
), aic_inb(p
, ARG_1
),
4353 (aic_inb(p
, SEQADDR1
) << 8) | aic_inb(p
, SEQADDR0
));
4359 if (aic7xxx_verbose
& VERBOSE_MINOR_ERROR
)
4360 printk(INFO_LEAD
"Rejecting unknown message (0x%x) received from "
4361 "target, SEQ_FLAGS=0x%x\n", p
->host_no
, channel
, target
, lun
,
4362 aic_inb(p
, ACCUM
), aic_inb(p
, SEQ_FLAGS
));
4369 * The reconnecting target either did not send an identify
4370 * message, or did, but we didn't find an SCB to match and
4371 * before it could respond to our ATN/abort, it hit a dataphase.
4372 * The only safe thing to do is to blow it away with a bus
4375 if (aic7xxx_verbose
& (VERBOSE_SEQINT
| VERBOSE_RESET_MID
))
4376 printk(INFO_LEAD
"Target did not send an IDENTIFY message; "
4377 "LASTPHASE 0x%x, SAVED_TCL 0x%x\n", p
->host_no
, channel
, target
,
4378 lun
, aic_inb(p
, LASTPHASE
), aic_inb(p
, SAVED_TCL
));
4380 aic7xxx_reset_channel(p
, channel
, /*initiate reset*/ TRUE
);
4381 aic7xxx_run_done_queue(p
, FALSE
);
4387 if (aic_inb(p
, LASTPHASE
) == P_BUSFREE
)
4389 if (aic7xxx_verbose
& VERBOSE_SEQINT
)
4390 printk(INFO_LEAD
"Missed busfree.\n", p
->host_no
, channel
,
4392 restart_sequencer(p
);
4396 if (aic7xxx_verbose
& VERBOSE_SEQINT
)
4397 printk(INFO_LEAD
"Unknown scsi bus phase, continuing\n", p
->host_no
,
4398 channel
, target
, lun
);
4404 p
->msg_type
= MSG_TYPE_INITIATOR_MSGIN
;
4408 #ifdef AIC7XXX_VERBOSE_DEBUGGING
4409 if (aic7xxx_verbose
> 0xffff)
4410 printk(INFO_LEAD
"Enabling REQINITs for MSG_IN\n", p
->host_no
,
4411 channel
, target
, lun
);
4415 * To actually receive the message, simply turn on
4416 * REQINIT interrupts and let our interrupt handler
4417 * do the rest (REQINIT should already be true).
4419 p
->flags
|= AHC_HANDLING_REQINITS
;
4420 aic_outb(p
, aic_inb(p
, SIMODE1
) | ENREQINIT
, SIMODE1
);
4423 * We don't want the sequencer unpaused yet so we return early
4431 * What we care about here is if we had an outstanding SDTR
4432 * or WDTR message for this target. If we did, this is a
4433 * signal that the target is refusing negotiation.
4435 unsigned char scb_index
;
4436 unsigned char last_msg
;
4438 scb_index
= aic_inb(p
, SCB_TAG
);
4439 scb
= p
->scb_data
->scb_array
[scb_index
];
4440 last_msg
= aic_inb(p
, LAST_MSG
);
4442 if ( (last_msg
== MSG_IDENTIFYFLAG
) &&
4443 (scb
->tag_action
) &&
4444 !(scb
->flags
& SCB_MSGOUT_BITS
) )
4446 if ((scb
->tag_action
== MSG_ORDERED_Q_TAG
) &&
4447 (p
->dev_flags
[tindex
] & DEVICE_TAGGED_SUCCESS
))
4450 * OK...the device seems able to accept tagged commands, but
4451 * not ordered tag commands, only simple tag commands. So, we
4452 * disable ordered tag commands and go on with life just like
4455 p
->orderedtag
&= ~target_mask
;
4456 scb
->tag_action
= MSG_SIMPLE_Q_TAG
;
4457 scb
->hscb
->control
&= ~SCB_TAG_TYPE
;
4458 scb
->hscb
->control
|= MSG_SIMPLE_Q_TAG
;
4459 aic_outb(p
, scb
->hscb
->control
, SCB_CONTROL
);
4461 * OK..we set the tag type to simple tag command, now we re-assert
4462 * ATNO and hope this will take us into the identify phase again
4463 * so we can resend the tag type and info to the device.
4465 aic_outb(p
, MSG_IDENTIFYFLAG
, MSG_OUT
);
4466 aic_outb(p
, aic_inb(p
, SCSISIGI
) | ATNO
, SCSISIGO
);
4468 else if ( (scb
->tag_action
== MSG_SIMPLE_Q_TAG
) &&
4469 !(p
->dev_flags
[tindex
] & DEVICE_TAGGED_SUCCESS
) )
4471 unsigned char i
, reset
= 0;
4472 struct aic7xxx_scb
*scbp
;
4475 * Hmmmm....the device is flaking out on tagged commands. The
4476 * bad thing is that we already have tagged commands enabled in
4477 * the device struct in the mid level code. We also have a queue
4478 * set according to the tagged queue depth. Gonna have to live
4479 * with it by controlling our queue depth internally and making
4480 * sure we don't set the tagged command flag any more.
4482 p
->tagenable
&= ~target_mask
;
4483 p
->orderedtag
&= ~target_mask
;
4484 p
->dev_max_queue_depth
[tindex
] =
4485 p
->dev_temp_queue_depth
[tindex
] = 1;
4487 * We set this command up as a bus device reset. However, we have
4488 * to clear the tag type as it's causing us problems. We shouldnt
4489 * have to worry about any other commands being active, since if
4490 * the device is refusing tagged commands, this should be the
4491 * first tagged command sent to the device, however, we do have
4492 * to worry about any other tagged commands that may already be
4493 * in the qinfifo. The easiest way to do this, is to issue a BDR,
4494 * send all the commands back to the mid level code, then let them
4495 * come back and get rebuilt as untagged commands.
4497 scb
->tag_action
= 0;
4498 scb
->hscb
->control
&= ~(TAG_ENB
| SCB_TAG_TYPE
);
4499 aic_outb(p
, scb
->hscb
->control
, SCB_CONTROL
);
4501 old_verbose
= aic7xxx_verbose
;
4502 aic7xxx_verbose
&= ~(VERBOSE_RESET
|VERBOSE_ABORT
);
4503 for (i
=0; i
!=p
->scb_data
->numscbs
; i
++)
4505 scbp
= p
->scb_data
->scb_array
[i
];
4506 if ((scbp
->flags
& SCB_ACTIVE
) && (scbp
!= scb
))
4508 if (aic7xxx_match_scb(p
, scbp
, target
, channel
, lun
, i
))
4510 aic7xxx_reset_device(p
, target
, channel
, lun
, i
);
4513 aic7xxx_run_done_queue(p
, FALSE
);
4516 aic7xxx_verbose
= old_verbose
;
4518 * Wait until after the for loop to set the busy index since
4519 * aic7xxx_reset_device will clear the busy index during its
4522 aic7xxx_busy_target(p
, scb
);
4523 printk(INFO_LEAD
"Device is refusing tagged commands, using "
4524 "untagged I/O.\n", p
->host_no
, channel
, target
, lun
);
4525 aic_outb(p
, MSG_IDENTIFYFLAG
, MSG_OUT
);
4526 aic_outb(p
, aic_inb(p
, SCSISIGI
) | ATNO
, SCSISIGO
);
4529 else if (scb
->flags
& SCB_MSGOUT_WDTR
)
4532 * note 8bit xfers and clear flag
4534 p
->needwdtr
&= ~target_mask
;
4535 p
->needwdtr_copy
&= ~target_mask
;
4536 p
->wdtr_pending
&= ~target_mask
;
4537 scb
->flags
&= ~SCB_MSGOUT_BITS
;
4538 aic7xxx_set_width(p
, target
, channel
, lun
, MSG_EXT_WDTR_BUS_8_BIT
,
4539 (AHC_TRANS_ACTIVE
|AHC_TRANS_GOAL
|AHC_TRANS_CUR
));
4540 aic7xxx_set_syncrate(p
, NULL
, target
, channel
, 0, 0,
4541 AHC_TRANS_ACTIVE
|AHC_TRANS_CUR
|AHC_TRANS_QUITE
);
4542 if ( (p
->needsdtr_copy
& target_mask
) &&
4543 !(p
->sdtr_pending
& target_mask
) )
4545 p
->sdtr_pending
|= target_mask
;
4546 scb
->flags
|= SCB_MSGOUT_SDTR
;
4547 aic_outb(p
, HOST_MSG
, MSG_OUT
);
4548 aic_outb(p
, aic_inb(p
, SCSISIGO
) | ATNO
, SCSISIGO
);
4551 else if (scb
->flags
& SCB_MSGOUT_SDTR
)
4554 * note asynch xfers and clear flag
4556 p
->needsdtr
&= ~target_mask
;
4557 p
->needsdtr_copy
&= ~target_mask
;
4558 p
->sdtr_pending
&= ~target_mask
;
4559 scb
->flags
&= ~SCB_MSGOUT_SDTR
;
4560 aic7xxx_set_syncrate(p
, NULL
, target
, channel
, 0, 0,
4561 (AHC_TRANS_CUR
|AHC_TRANS_ACTIVE
|AHC_TRANS_GOAL
));
4563 else if (aic7xxx_verbose
& VERBOSE_SEQINT
)
4566 * Otherwise, we ignore it.
4568 printk(INFO_LEAD
"Received MESSAGE_REJECT for unknown cause. "
4569 "Ignoring.\n", p
->host_no
, channel
, target
, lun
);
4576 unsigned char scb_index
;
4577 struct aic7xxx_hwscb
*hscb
;
4580 /* The sequencer will notify us when a command has an error that
4581 * would be of interest to the kernel. This allows us to leave
4582 * the sequencer running in the common case of command completes
4583 * without error. The sequencer will have DMA'd the SCB back
4584 * up to us, so we can reference the drivers SCB array.
4586 * Set the default return value to 0 indicating not to send
4587 * sense. The sense code will change this if needed and this
4588 * reduces code duplication.
4590 aic_outb(p
, 0, RETURN_1
);
4591 scb_index
= aic_inb(p
, SCB_TAG
);
4592 if (scb_index
> p
->scb_data
->numscbs
)
4594 printk(WARN_LEAD
"Invalid SCB during SEQINT 0x%02x, SCB_TAG %d.\n",
4595 p
->host_no
, channel
, target
, lun
, intstat
, scb_index
);
4598 scb
= p
->scb_data
->scb_array
[scb_index
];
4601 if (!(scb
->flags
& SCB_ACTIVE
) || (scb
->cmd
== NULL
))
4603 printk(WARN_LEAD
"Invalid SCB during SEQINT 0x%x, scb %d, flags 0x%x,"
4604 " cmd 0x%lx.\n", p
->host_no
, channel
, target
, lun
, intstat
,
4605 scb_index
, scb
->flags
, (unsigned long) scb
->cmd
);
4610 hscb
->target_status
= aic_inb(p
, SCB_TARGET_STATUS
);
4611 aic7xxx_status(cmd
) = hscb
->target_status
;
4613 cmd
->result
= hscb
->target_status
;
4615 switch (status_byte(hscb
->target_status
))
4618 if (aic7xxx_verbose
& VERBOSE_SEQINT
)
4619 printk(INFO_LEAD
"Interrupted for status of GOOD???\n",
4620 p
->host_no
, CTL_OF_SCB(scb
));
4623 case COMMAND_TERMINATED
:
4624 case CHECK_CONDITION
:
4625 if ( !(scb
->flags
& SCB_SENSE
) )
4628 * XXX - How do we save the residual (if there is one).
4630 if ( hscb
->residual_SG_segment_count
!= 0 )
4631 aic7xxx_calculate_residual(p
, scb
);
4634 * Send a sense command to the requesting target.
4635 * XXX - revisit this and get rid of the memcopys.
4637 memcpy(&scb
->sense_cmd
[0], &generic_sense
[0],
4638 sizeof(generic_sense
));
4640 scb
->sense_cmd
[1] = (cmd
->lun
<< 5);
4641 scb
->sense_cmd
[4] = sizeof(cmd
->sense_buffer
);
4643 scb
->sg_list
[0].address
=
4644 cpu_to_le32(VIRT_TO_BUS(&cmd
->sense_buffer
[0]));
4645 scb
->sg_list
[0].length
=
4646 cpu_to_le32(sizeof(cmd
->sense_buffer
));
4649 * XXX - We should allow disconnection, but can't as it
4650 * might allow overlapped tagged commands.
4652 /* hscb->control &= DISCENB; */
4654 hscb
->target_status
= 0;
4655 hscb
->SG_list_pointer
=
4656 cpu_to_le32(VIRT_TO_BUS(&scb
->sg_list
[0]));
4657 hscb
->data_pointer
= scb
->sg_list
[0].address
;
4658 hscb
->data_count
= scb
->sg_list
[0].length
;
4659 hscb
->SCSI_cmd_pointer
=
4660 cpu_to_le32(VIRT_TO_BUS(&scb
->sense_cmd
[0]));
4661 hscb
->SCSI_cmd_length
= COMMAND_SIZE(scb
->sense_cmd
[0]);
4662 hscb
->residual_SG_segment_count
= 0;
4663 hscb
->residual_data_count
[0] = 0;
4664 hscb
->residual_data_count
[1] = 0;
4665 hscb
->residual_data_count
[2] = 0;
4667 scb
->sg_count
= hscb
->SG_segment_count
= 1;
4668 scb
->sg_length
= sizeof(cmd
->sense_buffer
);
4669 scb
->tag_action
= 0;
4671 * This problem could be caused if the target has lost power
4672 * or found some other way to loose the negotiation settings,
4673 * so if needed, we'll re-negotiate while doing the sense cmd.
4674 * However, if this SCB already was attempting to negotiate,
4675 * then we assume this isn't the problem and skip this part.
4677 #ifdef AIC7XXX_FAKE_NEGOTIATION_CMDS
4678 if ( (scb
->cmd
->cmnd
[0] != TEST_UNIT_READY
) &&
4679 (p
->dev_flags
[tindex
] & DEVICE_SCANNED
) &&
4680 !(p
->wdtr_pending
& target_mask
) &&
4681 !(p
->sdtr_pending
& target_mask
) )
4683 p
->needwdtr
|= (p
->needwdtr_copy
& target_mask
);
4684 p
->needsdtr
|= (p
->needsdtr_copy
& target_mask
);
4686 else if ( (scb
->cmd
== p
->dev_wdtr_cmnd
[tindex
]) ||
4687 (scb
->cmd
== p
->dev_sdtr_cmnd
[tindex
]) )
4690 * This is already a negotiation command, so we must have
4691 * already done either WDTR or SDTR (or maybe both). So
4692 * we simply check sdtr_pending and needsdtr to see if we
4693 * should throw out SDTR on this command.
4695 * Note: Don't check the needsdtr_copy here, instead just
4696 * check to see if WDTR wiped out our SDTR and set needsdtr.
4697 * Even if WDTR did wipe out SDTR and set needsdtr, if
4698 * parse_msg() then turned around and started our SDTR
4699 * in back to back fasion, then conclusion of that should
4700 * have negated any needsdtr setting. That's why we only
4701 * check needsdtr and sdtr_pending.
4703 scb
->flags
&= ~SCB_MSGOUT_BITS
;
4704 if ( (scb
->cmd
== p
->dev_wdtr_cmnd
[tindex
]) &&
4705 !(p
->sdtr_pending
& target_mask
) &&
4706 (p
->needsdtr
& target_mask
) )
4708 p
->sdtr_pending
|= target_mask
;
4709 hscb
->control
|= MK_MESSAGE
;
4710 scb
->flags
|= SCB_MSGOUT_SDTR
;
4714 * This is the important part though. We are getting sense
4715 * info back from this device. It's going into a fake
4716 * command. We need to put that into the real command
4717 * instead so that the mid level SCSI code can act upon it.
4718 * So, when we set up these fake commands, the next pointer
4719 * is used to point to the real command. Use that to change
4720 * the address of our sense_buffer[] to the real command.
4721 * However, don't do this if the real command is also a
4722 * TEST_UNIT_READY as it will most likely pull down its own
4723 * SENSE information anyway.
4725 if (cmd
->next
->cmnd
[0] != TEST_UNIT_READY
)
4727 scb
->sg_list
[0].address
=
4728 cpu_to_le32(VIRT_TO_BUS(&cmd
->next
->sense_buffer
[0]));
4729 hscb
->data_pointer
= scb
->sg_list
[0].address
;
4733 if ( (scb
->cmd
->cmnd
[0] != TEST_UNIT_READY
) &&
4734 !(scb
->flags
& SCB_MSGOUT_BITS
) &&
4735 (scb
->cmd
->lun
== 0) &&
4736 (p
->dev_flags
[TARGET_INDEX(scb
->cmd
)] & DEVICE_SCANNED
) )
4738 if ( (p
->needwdtr_copy
& target_mask
) &&
4739 !(p
->wdtr_pending
& target_mask
) &&
4740 !(p
->sdtr_pending
& target_mask
) )
4742 p
->needwdtr
|= target_mask
;
4743 p
->wdtr_pending
|= target_mask
;
4744 hscb
->control
|= MK_MESSAGE
;
4745 scb
->flags
|= SCB_MSGOUT_WDTR
;
4747 if ( p
->needsdtr_copy
& target_mask
)
4749 p
->needsdtr
|= target_mask
;
4750 if ( !(p
->wdtr_pending
& target_mask
) &&
4751 !(p
->sdtr_pending
& target_mask
) )
4753 p
->sdtr_pending
|= target_mask
;
4754 hscb
->control
|= MK_MESSAGE
;
4755 scb
->flags
|= SCB_MSGOUT_SDTR
;
4760 scb
->flags
&= ~SCB_MSGOUT_BITS
;
4761 #endif /* AIC7XXX_FAKE_NEGOTIATION_CMDS */
4762 scb
->flags
|= SCB_SENSE
;
4764 * Ensure the target is busy since this will be an
4765 * an untagged request.
4767 #ifdef AIC7XXX_VERBOSE_DEBUGGING
4768 if (aic7xxx_verbose
> 0xffff)
4770 if (scb
->flags
& SCB_MSGOUT_BITS
)
4771 printk(INFO_LEAD
"Requesting SENSE with %s\n", p
->host_no
,
4772 CTL_OF_SCB(scb
), (scb
->flags
& SCB_MSGOUT_SDTR
) ?
4775 printk(INFO_LEAD
"Requesting SENSE, no MSG\n", p
->host_no
,
4779 aic7xxx_busy_target(p
, scb
);
4780 aic_outb(p
, SEND_SENSE
, RETURN_1
);
4781 aic7xxx_error(cmd
) = DID_OK
;
4783 } /* first time sense, no errors */
4784 aic7xxx_error(cmd
) = DID_OK
;
4785 scb
->flags
&= ~SCB_SENSE
;
4789 queue_flag
= TRUE
; /* Mark that this is a QUEUE_FULL and */
4790 case BUSY
: /* drop through to here */
4792 struct aic7xxx_scb
*next_scbp
, *prev_scbp
;
4793 unsigned char active_hscb
, next_hscb
, prev_hscb
, scb_index
;
4795 * We have to look three places for queued commands:
4797 * 2: p->waiting_scbs queue
4798 * 3: WAITING_SCBS list on card (for commands that are started
4799 * but haven't yet made it to the device)
4801 aic7xxx_search_qinfifo(p
, target
, channel
, lun
,
4802 SCB_LIST_NULL
, 0, TRUE
,
4803 &p
->delayed_scbs
[tindex
]);
4804 next_scbp
= p
->waiting_scbs
.head
;
4805 while ( next_scbp
!= NULL
)
4807 prev_scbp
= next_scbp
;
4808 next_scbp
= next_scbp
->q_next
;
4809 if ( aic7xxx_match_scb(p
, prev_scbp
, target
, channel
, lun
,
4812 scbq_remove(&p
->waiting_scbs
, prev_scbp
);
4813 scbq_insert_tail(&p
->delayed_scbs
[tindex
],
4818 active_hscb
= aic_inb(p
, SCBPTR
);
4819 prev_hscb
= next_hscb
= scb_index
= SCB_LIST_NULL
;
4820 next_hscb
= aic_inb(p
, WAITING_SCBH
);
4821 while (next_hscb
!= SCB_LIST_NULL
)
4823 aic_outb(p
, next_hscb
, SCBPTR
);
4824 scb_index
= aic_inb(p
, SCB_TAG
);
4825 if (scb_index
< p
->scb_data
->numscbs
)
4827 next_scbp
= p
->scb_data
->scb_array
[scb_index
];
4828 if (aic7xxx_match_scb(p
, next_scbp
, target
, channel
, lun
,
4831 if (next_scbp
->flags
& SCB_WAITINGQ
)
4833 p
->dev_active_cmds
[tindex
]++;
4835 scbq_remove(&p
->delayed_scbs
[tindex
], next_scbp
);
4836 scbq_remove(&p
->waiting_scbs
, next_scbp
);
4838 scbq_insert_head(&p
->delayed_scbs
[tindex
],
4840 next_scbp
->flags
|= SCB_WAITINGQ
;
4841 p
->dev_active_cmds
[tindex
]--;
4843 next_hscb
= aic_inb(p
, SCB_NEXT
);
4844 aic_outb(p
, 0, SCB_CONTROL
);
4845 aic_outb(p
, SCB_LIST_NULL
, SCB_TAG
);
4846 aic7xxx_add_curscb_to_free_list(p
);
4847 if (prev_hscb
== SCB_LIST_NULL
)
4849 /* We were first on the list,
4850 * so we kill the selection
4851 * hardware. Let the sequencer
4852 * re-init the hardware itself
4854 aic_outb(p
, aic_inb(p
, SCSISEQ
) & ~ENSELO
, SCSISEQ
);
4855 aic_outb(p
, CLRSELTIMEO
, CLRSINT1
);
4856 aic_outb(p
, next_hscb
, WAITING_SCBH
);
4860 aic_outb(p
, prev_hscb
, SCBPTR
);
4861 aic_outb(p
, next_hscb
, SCB_NEXT
);
4866 prev_hscb
= next_hscb
;
4867 next_hscb
= aic_inb(p
, SCB_NEXT
);
4869 } /* scb_index >= p->scb_data->numscbs */
4871 aic_outb(p
, active_hscb
, SCBPTR
);
4872 if (scb
->flags
& SCB_WAITINGQ
)
4874 scbq_remove(&p
->delayed_scbs
[tindex
], scb
);
4875 scbq_remove(&p
->waiting_scbs
, scb
);
4876 p
->dev_active_cmds
[tindex
]++;
4879 scbq_insert_head(&p
->delayed_scbs
[tindex
], scb
);
4880 p
->dev_active_cmds
[tindex
]--;
4882 scb
->flags
|= SCB_WAITINGQ
| SCB_WAS_BUSY
;
4884 if ( !timer_pending(&p
->dev_timer
[tindex
]) )
4886 if ( p
->dev_active_cmds
[tindex
] )
4888 p
->dev_timer
[tindex
].expires
= jiffies
+ (HZ
* 2);
4889 add_timer(&p
->dev_timer
[tindex
]);
4893 p
->dev_timer
[tindex
].expires
= jiffies
+ (HZ
/ 2);
4894 add_timer(&p
->dev_timer
[tindex
]);
4897 #ifdef AIC7XXX_VERBOSE_DEBUGGING
4898 if (aic7xxx_verbose
& VERBOSE_MINOR_ERROR
)
4901 printk(INFO_LEAD
"Queue full received; queue depth %d, "
4902 "active %d\n", p
->host_no
, CTL_OF_SCB(scb
),
4903 p
->dev_max_queue_depth
[tindex
],
4904 p
->dev_active_cmds
[tindex
]);
4906 printk(INFO_LEAD
"Target busy\n", p
->host_no
, CTL_OF_SCB(scb
));
4912 p
->dev_temp_queue_depth
[tindex
] =
4913 p
->dev_active_cmds
[tindex
];
4914 if ( p
->dev_last_queue_full
[tindex
] !=
4915 p
->dev_active_cmds
[tindex
] )
4917 p
->dev_last_queue_full
[tindex
] =
4918 p
->dev_active_cmds
[tindex
];
4919 p
->dev_last_queue_full_count
[tindex
] = 0;
4923 p
->dev_last_queue_full_count
[tindex
]++;
4925 if ( (p
->dev_last_queue_full_count
[tindex
] > 14) &&
4926 (p
->dev_active_cmds
[tindex
] > 4) )
4928 if (aic7xxx_verbose
& VERBOSE_NEGOTIATION2
)
4929 printk(INFO_LEAD
"Queue depth reduced to %d\n", p
->host_no
,
4930 CTL_OF_SCB(scb
), p
->dev_active_cmds
[tindex
]);
4931 p
->dev_max_queue_depth
[tindex
] =
4932 p
->dev_active_cmds
[tindex
];
4933 p
->dev_last_queue_full
[tindex
] = 0;
4934 p
->dev_last_queue_full_count
[tindex
] = 0;
4941 if (aic7xxx_verbose
& VERBOSE_SEQINT
)
4942 printk(INFO_LEAD
"Unexpected target status 0x%x.\n", p
->host_no
,
4943 CTL_OF_SCB(scb
), scb
->hscb
->target_status
);
4944 if (!aic7xxx_error(cmd
))
4946 aic7xxx_error(cmd
) = DID_RETRY_COMMAND
;
4956 unsigned char scb_index
, msg_out
;
4958 scb_index
= aic_inb(p
, SCB_TAG
);
4959 msg_out
= aic_inb(p
, MSG_OUT
);
4960 scb
= p
->scb_data
->scb_array
[scb_index
];
4961 p
->msg_index
= p
->msg_len
= 0;
4963 * This SCB had a MK_MESSAGE set in its control byte informing
4964 * the sequencer that we wanted to send a special message to
4968 if ( !(scb
->flags
& SCB_DEVICE_RESET
) &&
4969 (aic_inb(p
, MSG_OUT
) == MSG_IDENTIFYFLAG
) &&
4970 (scb
->hscb
->control
& TAG_ENB
) )
4972 p
->msg_buf
[p
->msg_index
++] = scb
->tag_action
;
4973 p
->msg_buf
[p
->msg_index
++] = scb
->hscb
->tag
;
4977 if (scb
->flags
& SCB_DEVICE_RESET
)
4979 p
->msg_buf
[p
->msg_index
++] = MSG_BUS_DEV_RESET
;
4981 if (aic7xxx_verbose
& VERBOSE_RESET_PROCESS
)
4982 printk(INFO_LEAD
"Bus device reset mailed.\n",
4983 p
->host_no
, CTL_OF_SCB(scb
));
4985 else if (scb
->flags
& SCB_ABORT
)
4987 if (scb
->tag_action
)
4989 p
->msg_buf
[p
->msg_index
++] = MSG_ABORT_TAG
;
4993 p
->msg_buf
[p
->msg_index
++] = MSG_ABORT
;
4996 if (aic7xxx_verbose
& VERBOSE_ABORT_PROCESS
)
4997 printk(INFO_LEAD
"Abort message mailed.\n", p
->host_no
,
5000 else if (scb
->flags
& SCB_MSGOUT_WDTR
)
5002 #ifdef AIC7XXX_VERBOSE_DEBUGGING
5003 if (aic7xxx_verbose
> 0xffff)
5004 printk(INFO_LEAD
"Sending WDTR message.\n", p
->host_no
,
5007 aic7xxx_construct_wdtr(p
,
5008 p
->transinfo
[TARGET_INDEX(scb
->cmd
)].goal_width
);
5010 else if (scb
->flags
& SCB_MSGOUT_SDTR
)
5012 unsigned int max_sync
, period
;
5014 * We need to set an accurate goal_offset instead of
5015 * the ridiculously high one we default to. We should
5016 * now know if we are wide. Plus, the WDTR code will
5017 * set our goal_offset for us as well.
5019 if (p
->transinfo
[tindex
].goal_offset
)
5021 if (p
->features
& AHC_ULTRA2
)
5022 p
->transinfo
[tindex
].goal_offset
= MAX_OFFSET_ULTRA2
;
5023 else if (p
->transinfo
[tindex
].cur_width
== MSG_EXT_WDTR_BUS_16_BIT
)
5024 p
->transinfo
[tindex
].goal_offset
= MAX_OFFSET_16BIT
;
5026 p
->transinfo
[tindex
].goal_offset
= MAX_OFFSET_8BIT
;
5029 * Now that the device is selected, use the bits in SBLKCTL and
5030 * SSTAT2 to determine the max sync rate for this device.
5032 if (p
->features
& AHC_ULTRA2
)
5034 if ( (aic_inb(p
, SBLKCTL
) & ENAB40
) &&
5035 !(aic_inb(p
, SSTAT2
) & EXP_ACTIVE
) )
5037 max_sync
= AHC_SYNCRATE_ULTRA2
;
5041 max_sync
= AHC_SYNCRATE_ULTRA
;
5044 else if (p
->features
& AHC_ULTRA
)
5046 max_sync
= AHC_SYNCRATE_ULTRA
;
5050 max_sync
= AHC_SYNCRATE_FAST
;
5052 period
= p
->transinfo
[tindex
].goal_period
;
5053 aic7xxx_find_syncrate(p
, &period
, max_sync
);
5054 #ifdef AIC7XXX_VERBOSE_DEBUGGING
5055 if (aic7xxx_verbose
> 0xffff)
5056 printk(INFO_LEAD
"Sending SDTR %d/%d message.\n", p
->host_no
,
5058 p
->transinfo
[tindex
].goal_period
,
5059 p
->transinfo
[tindex
].goal_offset
);
5061 aic7xxx_construct_sdtr(p
, period
,
5062 p
->transinfo
[tindex
].goal_offset
);
5067 panic("aic7xxx: AWAITING_MSG for an SCB that does "
5068 "not have a waiting message.\n");
5071 * We've set everything up to send our message, now to actually do
5072 * so we need to enable reqinit interrupts and let the interrupt
5073 * handler do the rest. We don't want to unpause the sequencer yet
5074 * though so we'll return early. We also have to make sure that
5075 * we clear the SEQINT *BEFORE* we set the REQINIT handler active
5076 * or else it's possible on VLB cards to loose the first REQINIT
5077 * interrupt. Edge triggered EISA cards could also loose this
5078 * interrupt, although PCI and level triggered cards should not
5079 * have this problem since they continually interrupt the kernel
5080 * until we take care of the situation.
5082 scb
->flags
|= SCB_MSGOUT_SENT
;
5084 p
->msg_type
= MSG_TYPE_INITIATOR_MSGOUT
;
5085 p
->flags
|= AHC_HANDLING_REQINITS
;
5086 aic_outb(p
, aic_inb(p
, SIMODE1
) | ENREQINIT
, SIMODE1
);
5093 unsigned char scb_index
= aic_inb(p
, SCB_TAG
);
5094 unsigned char lastphase
= aic_inb(p
, LASTPHASE
);
5097 scb
= (p
->scb_data
->scb_array
[scb_index
]);
5099 * XXX - What do we really want to do on an overrun? The
5100 * mid-level SCSI code should handle this, but for now,
5101 * we'll just indicate that the command should retried.
5102 * If we retrieved sense info on this target, then the
5103 * base SENSE info should have been saved prior to the
5104 * overrun error. In that case, we return DID_OK and let
5105 * the mid level code pick up on the sense info. Otherwise
5106 * we return DID_ERROR so the command will get retried.
5108 if ( !(scb
->flags
& SCB_SENSE
) )
5110 printk(WARN_LEAD
"Data overrun detected in %s phase, tag %d;\n",
5111 p
->host_no
, CTL_OF_SCB(scb
),
5112 (lastphase
== P_DATAIN
) ? "Data-In" : "Data-Out", scb
->hscb
->tag
);
5113 printk(KERN_WARNING
" %s seen Data Phase. Length=%d, NumSGs=%d.\n",
5114 (aic_inb(p
, SEQ_FLAGS
) & DPHASE
) ? "Have" : "Haven't",
5115 scb
->sg_length
, scb
->sg_count
);
5116 for (i
= 0; i
< scb
->sg_count
; i
++)
5118 printk(KERN_WARNING
" sg[%d] - Addr 0x%x : Length %d\n",
5120 le32_to_cpu(scb
->sg_list
[i
].address
),
5121 le32_to_cpu(scb
->sg_list
[i
].length
) );
5123 aic7xxx_error(scb
->cmd
) = DID_ERROR
;
5126 printk(INFO_LEAD
"Data Overrun during SEND_SENSE operation.\n",
5127 p
->host_no
, CTL_OF_SCB(scb
));
5134 printk(INFO_LEAD
"Tracepoint #1 reached.\n", p
->host_no
, channel
,
5141 printk(INFO_LEAD
"Tracepoint #2 reached.\n", p
->host_no
, channel
,
5146 /* XXX Fill these in later */
5147 case MSG_BUFFER_BUSY
:
5148 printk("aic7xxx: Message buffer busy.\n");
5150 case MSGIN_PHASEMIS
:
5151 printk("aic7xxx: Message-in phasemis.\n");
5155 default: /* unknown */
5156 printk(WARN_LEAD
"Unknown SEQINT, INTSTAT 0x%x, SCSISIGI 0x%x.\n",
5157 p
->host_no
, channel
, target
, lun
, intstat
,
5158 aic_inb(p
, SCSISIGI
));
5163 * Clear the sequencer interrupt and unpause the sequencer.
5165 unpause_sequencer(p
, /* unpause always */ TRUE
);
5168 /*+F*************************************************************************
5173 * Parses incoming messages into actions on behalf of
5174 * aic7xxx_handle_reqinit
5175 *_F*************************************************************************/
5177 aic7xxx_parse_msg(struct aic7xxx_host
*p
, struct aic7xxx_scb
*scb
)
5179 int reject
, reply
, done
;
5180 unsigned char target_scsirate
, tindex
;
5181 unsigned short target_mask
;
5182 unsigned char target
, channel
, lun
;
5184 target
= scb
->cmd
->target
;
5185 channel
= scb
->cmd
->channel
;
5186 lun
= scb
->cmd
->lun
;
5187 reply
= reject
= done
= FALSE
;
5188 tindex
= TARGET_INDEX(scb
->cmd
);
5189 target_scsirate
= aic_inb(p
, TARG_SCSIRATE
+ tindex
);
5190 target_mask
= (0x01 << tindex
);
5193 * Parse as much of the message as is availible,
5194 * rejecting it if we don't support it. When
5195 * the entire message is availible and has been
5196 * handled, return TRUE indicating that we have
5197 * parsed an entire message.
5200 if (p
->msg_buf
[0] != MSG_EXTENDED
)
5206 * Just accept the length byte outright and perform
5207 * more checking once we know the message type.
5210 if ( !reject
&& (p
->msg_len
> 2) )
5212 switch(p
->msg_buf
[2])
5216 unsigned int period
, offset
;
5217 unsigned char maxsync
, saved_offset
;
5218 struct aic7xxx_syncrate
*syncrate
;
5220 if (p
->msg_buf
[1] != MSG_EXT_SDTR_LEN
)
5226 if (p
->msg_len
< (MSG_EXT_SDTR_LEN
+ 2))
5231 period
= p
->msg_buf
[3];
5232 saved_offset
= offset
= p
->msg_buf
[4];
5234 if (p
->features
& AHC_ULTRA2
)
5236 if ( (aic_inb(p
, SBLKCTL
) & ENAB40
) &&
5237 !(aic_inb(p
, SSTAT2
) & EXP_ACTIVE
) )
5239 maxsync
= AHC_SYNCRATE_ULTRA2
;
5243 maxsync
= AHC_SYNCRATE_ULTRA
;
5246 else if (p
->features
& AHC_ULTRA
)
5248 maxsync
= AHC_SYNCRATE_ULTRA
;
5252 maxsync
= AHC_SYNCRATE_FAST
;
5255 #ifdef AIC7XXX_VERBOSE_DEBUGGING
5256 if (aic7xxx_verbose
> 0xffff)
5258 printk(INFO_LEAD
"Finished receipt of SDTR, parsing %d/%d\n",
5259 p
->host_no
, CTL_OF_SCB(scb
), period
, offset
);
5260 syncrate
= aic7xxx_find_syncrate(p
, &period
, maxsync
);
5261 printk(INFO_LEAD
"After find_syncrate() %d/%d\n",
5262 p
->host_no
, CTL_OF_SCB(scb
), period
, offset
);
5263 aic7xxx_validate_offset(p
, syncrate
, &offset
,
5264 target_scsirate
& WIDEXFER
);
5265 printk(INFO_LEAD
"After validate_offset() %d/%d\n",
5266 p
->host_no
, CTL_OF_SCB(scb
), period
, offset
);
5267 aic7xxx_set_syncrate(p
, syncrate
, target
, channel
, period
,
5268 offset
, AHC_TRANS_ACTIVE
|AHC_TRANS_CUR
);
5269 printk(INFO_LEAD
"Final values of Period/Offset as set: %d/%d\n",
5270 p
->host_no
, CTL_OF_SCB(scb
), period
, offset
);
5274 syncrate
= aic7xxx_find_syncrate(p
, &period
, maxsync
);
5275 aic7xxx_validate_offset(p
, syncrate
, &offset
,
5276 target_scsirate
& WIDEXFER
);
5277 aic7xxx_set_syncrate(p
, syncrate
, target
, channel
, period
,
5278 offset
, AHC_TRANS_ACTIVE
|AHC_TRANS_CUR
);
5281 syncrate
= aic7xxx_find_syncrate(p
, &period
, maxsync
);
5282 aic7xxx_validate_offset(p
, syncrate
, &offset
,
5283 target_scsirate
& WIDEXFER
);
5284 aic7xxx_set_syncrate(p
, syncrate
, target
, channel
, period
,
5285 offset
, AHC_TRANS_ACTIVE
|AHC_TRANS_CUR
);
5291 * Uhh ohh, things fell through to async....update the goal
5292 * items and the needsdtr_copy to reflect this...
5294 aic7xxx_set_syncrate(p
, syncrate
, target
, channel
, period
,
5295 offset
, AHC_TRANS_GOAL
|AHC_TRANS_QUITE
);
5296 p
->needsdtr_copy
&= ~target_mask
;
5299 * Did we start this, if not, or if we went to low and had to
5300 * go async, then send an SDTR back to the target
5302 p
->needsdtr
&= ~target_mask
;
5303 p
->sdtr_pending
&= ~target_mask
;
5304 if ( ((scb
->flags
& (SCB_MSGOUT_SENT
|SCB_MSGOUT_SDTR
)) ==
5305 (SCB_MSGOUT_SENT
|SCB_MSGOUT_SDTR
)) &&
5306 (offset
== saved_offset
) )
5308 scb
->flags
&= ~SCB_MSGOUT_BITS
;
5313 * Send a reply SDTR back. Even if we sent the first one, it
5314 * is valid to send another one out immediately to re-negotiate
5315 * things, and a few devices don't like getting rejects after
5316 * we already sent them one SDTR. Just send an SDTR for async
5317 * this time if need be (or for the correct params if we didn't
5318 * start all of this). If this is a Reject Reply type message,
5319 * then we've put the async settings into the goal area for
5320 * future reference (when we get the AWAITING_MSG interrupt).
5321 * If this is a case where we are responding to the target's
5322 * initiated SDTR, then leave our own goal and user values in
5323 * place (unless the device hasn't been scanned yet, in which
5324 * case, put the user values into the goal values so we don't
5325 * send out an Async message).
5327 if ( !(p
->dev_flags
[tindex
] & DEVICE_SCANNED
) )
5329 p
->transinfo
[tindex
].goal_width
=
5330 p
->transinfo
[tindex
].user_width
;
5331 p
->transinfo
[tindex
].goal_period
=
5332 p
->transinfo
[tindex
].user_period
;
5333 p
->transinfo
[tindex
].goal_offset
=
5334 p
->transinfo
[tindex
].user_offset
;
5335 p
->needwdtr_copy
|= target_mask
;
5336 p
->needsdtr_copy
|= target_mask
;
5338 scb
->flags
&= ~SCB_MSGOUT_BITS
;
5339 scb
->flags
|= SCB_MSGOUT_SDTR
;
5340 aic_outb(p
, HOST_MSG
, MSG_OUT
);
5341 aic_outb(p
, aic_inb(p
, SCSISIGO
) | ATNO
, SCSISIGO
);
5348 unsigned char bus_width
;
5350 if (p
->msg_buf
[1] != MSG_EXT_WDTR_LEN
)
5356 if (p
->msg_len
< (MSG_EXT_WDTR_LEN
+ 2))
5361 bus_width
= p
->msg_buf
[3];
5362 if ( (scb
->flags
& (SCB_MSGOUT_SENT
|SCB_MSGOUT_WDTR
)) ==
5363 (SCB_MSGOUT_SENT
|SCB_MSGOUT_WDTR
) )
5370 if ( (aic7xxx_verbose
& VERBOSE_NEGOTIATION2
) &&
5371 ((p
->dev_flags
[tindex
] & DEVICE_PRINT_WDTR
) ||
5372 (aic7xxx_verbose
> 0xffff)) )
5374 printk(INFO_LEAD
"Requesting %d bit transfers, rejecting.\n",
5375 p
->host_no
, CTL_OF_SCB(scb
), 8 * (0x01 << bus_width
));
5376 p
->dev_flags
[tindex
] &= ~DEVICE_PRINT_WDTR
;
5378 } /* We fall through on purpose */
5379 case MSG_EXT_WDTR_BUS_8_BIT
:
5381 bus_width
= MSG_EXT_WDTR_BUS_8_BIT
;
5382 p
->needwdtr_copy
&= ~target_mask
;
5385 case MSG_EXT_WDTR_BUS_16_BIT
:
5390 scb
->flags
&= ~SCB_MSGOUT_BITS
;
5391 p
->wdtr_pending
&= ~target_mask
;
5392 p
->needwdtr
&= ~target_mask
;
5396 scb
->flags
&= ~SCB_MSGOUT_BITS
;
5397 scb
->flags
|= SCB_MSGOUT_WDTR
;
5399 if ( !(p
->dev_flags
[tindex
] & DEVICE_SCANNED
) )
5402 * Well, we now know the WDTR and SYNC caps of this device since
5403 * it contacted us first, mark it as such and copy the user stuff
5404 * over to the goal stuff.
5406 p
->transinfo
[tindex
].goal_width
=
5407 p
->transinfo
[tindex
].user_width
;
5408 p
->transinfo
[tindex
].goal_period
=
5409 p
->transinfo
[tindex
].user_period
;
5410 p
->transinfo
[tindex
].goal_offset
=
5411 p
->transinfo
[tindex
].user_offset
;
5412 p
->needwdtr_copy
|= target_mask
;
5413 p
->needsdtr_copy
|= target_mask
;
5419 if ( (p
->features
& AHC_WIDE
) &&
5420 (p
->transinfo
[tindex
].goal_width
==
5421 MSG_EXT_WDTR_BUS_16_BIT
) )
5423 bus_width
= MSG_EXT_WDTR_BUS_16_BIT
;
5426 } /* Fall through if we aren't a wide card */
5427 case MSG_EXT_WDTR_BUS_8_BIT
:
5429 p
->needwdtr_copy
&= ~target_mask
;
5430 bus_width
= MSG_EXT_WDTR_BUS_8_BIT
;
5434 p
->needwdtr
&= ~target_mask
;
5435 p
->wdtr_pending
&= ~target_mask
;
5436 aic_outb(p
, HOST_MSG
, MSG_OUT
);
5437 aic_outb(p
, aic_inb(p
, SCSISIGO
) | ATNO
, SCSISIGO
);
5439 aic7xxx_set_width(p
, target
, channel
, lun
, bus_width
,
5440 AHC_TRANS_ACTIVE
|AHC_TRANS_CUR
);
5443 * By virtue of the SCSI spec, a WDTR message negates any existing
5444 * SDTR negotiations. So, even if needsdtr isn't marked for this
5445 * device, we still have to do a new SDTR message if the device
5446 * supports SDTR at all. Therefore, we check needsdtr_copy instead
5449 aic7xxx_set_syncrate(p
, NULL
, target
, channel
, 0, 0,
5450 AHC_TRANS_ACTIVE
|AHC_TRANS_CUR
|AHC_TRANS_QUITE
);
5451 if ( (p
->needsdtr_copy
& target_mask
) &&
5452 !(p
->sdtr_pending
& target_mask
))
5454 p
->needsdtr
|= target_mask
;
5455 if ( !reject
&& !reply
)
5457 scb
->flags
&= ~SCB_MSGOUT_WDTR
;
5458 if (p
->transinfo
[tindex
].goal_period
)
5460 p
->sdtr_pending
|= target_mask
;
5461 scb
->flags
|= SCB_MSGOUT_SDTR
;
5462 aic_outb(p
, HOST_MSG
, MSG_OUT
);
5463 aic_outb(p
, aic_inb(p
, SCSISIGO
) | ATNO
, SCSISIGO
);
5475 } /* end of switch(p->msg_type) */
5476 } /* end of if (!reject && (p->msg_len > 2)) */
5480 aic_outb(p
, MSG_MESSAGE_REJECT
, MSG_OUT
);
5481 aic_outb(p
, aic_inb(p
, SCSISIGO
) | ATNO
, SCSISIGO
);
5488 /*+F*************************************************************************
5490 * aic7xxx_handle_reqinit
5493 * Interrupt handler for REQINIT interrupts (used to transfer messages to
5494 * and from devices).
5495 *_F*************************************************************************/
5497 aic7xxx_handle_reqinit(struct aic7xxx_host
*p
, struct aic7xxx_scb
*scb
)
5499 unsigned char lastbyte
;
5500 unsigned char phasemis
;
5505 case MSG_TYPE_INITIATOR_MSGOUT
:
5507 if (p
->msg_len
== 0)
5508 panic("aic7xxx: REQINIT with no active message!\n");
5510 lastbyte
= (p
->msg_index
== (p
->msg_len
- 1));
5511 phasemis
= ( aic_inb(p
, SCSISIGI
) & PHASE_MASK
) != P_MESGOUT
;
5513 if (lastbyte
|| phasemis
)
5515 /* Time to end the message */
5517 p
->msg_type
= MSG_TYPE_NONE
;
5519 * NOTE-TO-MYSELF: If you clear the REQINIT after you
5520 * disable REQINITs, then cases of REJECT_MSG stop working
5523 aic_outb(p
, aic_inb(p
, SIMODE1
) & ~ENREQINIT
, SIMODE1
);
5524 aic_outb(p
, CLRSCSIINT
, CLRINT
);
5525 p
->flags
&= ~AHC_HANDLING_REQINITS
;
5529 aic_outb(p
, p
->msg_buf
[p
->msg_index
], SINDEX
);
5530 aic_outb(p
, 0, RETURN_1
);
5531 #ifdef AIC7XXX_VERBOSE_DEBUGGING
5532 if (aic7xxx_verbose
> 0xffff)
5533 printk(INFO_LEAD
"Completed sending of REQINIT message.\n",
5534 p
->host_no
, CTL_OF_SCB(scb
));
5539 aic_outb(p
, MSGOUT_PHASEMIS
, RETURN_1
);
5540 #ifdef AIC7XXX_VERBOSE_DEBUGGING
5541 if (aic7xxx_verbose
> 0xffff)
5542 printk(INFO_LEAD
"PHASEMIS while sending REQINIT message.\n",
5543 p
->host_no
, CTL_OF_SCB(scb
));
5546 unpause_sequencer(p
, TRUE
);
5551 * Present the byte on the bus (clearing REQINIT) but don't
5552 * unpause the sequencer.
5554 aic_outb(p
, CLRREQINIT
, CLRSINT1
);
5555 aic_outb(p
, CLRSCSIINT
, CLRINT
);
5556 aic_outb(p
, p
->msg_buf
[p
->msg_index
++], SCSIDATL
);
5560 case MSG_TYPE_INITIATOR_MSGIN
:
5562 phasemis
= ( aic_inb(p
, SCSISIGI
) & PHASE_MASK
) != P_MESGIN
;
5567 /* Pull the byte in without acking it */
5568 p
->msg_buf
[p
->msg_index
] = aic_inb(p
, SCSIBUSL
);
5569 done
= aic7xxx_parse_msg(p
, scb
);
5571 aic_outb(p
, CLRREQINIT
, CLRSINT1
);
5572 aic_outb(p
, CLRSCSIINT
, CLRINT
);
5573 aic_inb(p
, SCSIDATL
);
5576 if (phasemis
|| done
)
5578 #ifdef AIC7XXX_VERBOSE_DEBUGGING
5579 if (aic7xxx_verbose
> 0xffff)
5582 printk(INFO_LEAD
"PHASEMIS while receiving REQINIT message.\n",
5583 p
->host_no
, CTL_OF_SCB(scb
));
5585 printk(INFO_LEAD
"Completed receipt of REQINIT message.\n",
5586 p
->host_no
, CTL_OF_SCB(scb
));
5589 /* Time to end our message session */
5591 p
->msg_type
= MSG_TYPE_NONE
;
5592 aic_outb(p
, aic_inb(p
, SIMODE1
) & ~ENREQINIT
, SIMODE1
);
5593 aic_outb(p
, CLRSCSIINT
, CLRINT
);
5594 p
->flags
&= ~AHC_HANDLING_REQINITS
;
5595 unpause_sequencer(p
, TRUE
);
5601 panic("aic7xxx: Unknown REQINIT message type.\n");
5604 } /* End of switch(p->msg_type) */
5607 /*+F*************************************************************************
5609 * aic7xxx_handle_scsiint
5612 * Interrupt handler for SCSI interrupts (SCSIINT).
5613 *-F*************************************************************************/
5615 aic7xxx_handle_scsiint(struct aic7xxx_host
*p
, unsigned char intstat
)
5617 unsigned char scb_index
;
5618 unsigned char status
;
5619 struct aic7xxx_scb
*scb
;
5621 scb_index
= aic_inb(p
, SCB_TAG
);
5622 status
= aic_inb(p
, SSTAT1
);
5624 if (scb_index
< p
->scb_data
->numscbs
)
5626 scb
= p
->scb_data
->scb_array
[scb_index
];
5627 if ((scb
->flags
& SCB_ACTIVE
) == 0)
5638 if ((status
& SCSIRSTI
) != 0)
5642 if ( (p
->chip
& AHC_CHIPID_MASK
) == AHC_AIC7770
)
5643 channel
= (aic_inb(p
, SBLKCTL
) & SELBUSB
) >> 3;
5647 if (aic7xxx_verbose
& VERBOSE_RESET
)
5648 printk(WARN_LEAD
"Someone else reset the channel!!\n",
5649 p
->host_no
, channel
, -1, -1);
5651 * Go through and abort all commands for the channel, but do not
5652 * reset the channel again.
5654 aic7xxx_reset_channel(p
, channel
, /* Initiate Reset */ FALSE
);
5655 aic7xxx_run_done_queue(p
, FALSE
);
5658 else if ( ((status
& BUSFREE
) != 0) && ((status
& SELTO
) == 0) )
5661 * First look at what phase we were last in. If it's message-out,
5662 * chances are pretty good that the bus free was in response to
5663 * one of our abort requests.
5665 unsigned char lastphase
= aic_inb(p
, LASTPHASE
);
5666 unsigned char saved_tcl
= aic_inb(p
, SAVED_TCL
);
5667 unsigned char target
= (saved_tcl
>> 4) & 0x0F;
5669 int printerror
= TRUE
;
5671 if ( (p
->chip
& AHC_CHIPID_MASK
) == AHC_AIC7770
)
5672 channel
= (aic_inb(p
, SBLKCTL
) & SELBUSB
) >> 3;
5676 aic_outb(p
, aic_inb(p
, SCSISEQ
) & (ENSELI
|ENRSELI
|ENAUTOATNP
),
5678 if (lastphase
== P_MESGOUT
)
5680 unsigned char message
;
5682 message
= aic_inb(p
, SINDEX
);
5684 if ((message
== MSG_ABORT
) || (message
== MSG_ABORT_TAG
))
5686 if (aic7xxx_verbose
& VERBOSE_ABORT_PROCESS
)
5687 printk(INFO_LEAD
"SCB %d abort delivered.\n", p
->host_no
,
5688 CTL_OF_SCB(scb
), scb
->hscb
->tag
);
5689 aic7xxx_reset_device(p
, target
, channel
, ALL_LUNS
,
5690 (message
== MSG_ABORT
) ? SCB_LIST_NULL
: scb
->hscb
->tag
);
5691 aic7xxx_run_done_queue(p
, FALSE
);
5695 else if (message
== MSG_BUS_DEV_RESET
)
5697 aic7xxx_handle_device_reset(p
, target
, channel
);
5702 if (printerror
!= 0)
5708 if ((scb
->hscb
->control
& TAG_ENB
) != 0)
5710 tag
= scb
->hscb
->tag
;
5714 tag
= SCB_LIST_NULL
;
5716 aic7xxx_reset_device(p
, target
, channel
, ALL_LUNS
, tag
);
5717 aic7xxx_run_done_queue(p
, FALSE
);
5719 printk(INFO_LEAD
"Unexpected busfree, LASTPHASE = 0x%x, "
5720 "SEQADDR = 0x%x\n", p
->host_no
, channel
, target
, -1, lastphase
,
5721 (aic_inb(p
, SEQADDR1
) << 8) | aic_inb(p
, SEQADDR0
));
5724 aic_outb(p
, MSG_NOOP
, MSG_OUT
);
5725 aic_outb(p
, aic_inb(p
, SIMODE1
) & ~(ENBUSFREE
|ENREQINIT
),
5727 p
->flags
&= ~AHC_HANDLING_REQINITS
;
5728 aic_outb(p
, CLRBUSFREE
, CLRSINT1
);
5729 aic_outb(p
, CLRSCSIINT
, CLRINT
);
5730 restart_sequencer(p
);
5731 unpause_sequencer(p
, TRUE
);
5733 else if ((status
& SELTO
) != 0)
5735 unsigned char scbptr
;
5736 unsigned char nextscb
;
5739 scbptr
= aic_inb(p
, WAITING_SCBH
);
5740 if (scbptr
> p
->scb_data
->maxhscbs
)
5743 * I'm still trying to track down exactly how this happens, but until
5744 * I find it, this code will make sure we aren't passing bogus values
5745 * into the SCBPTR register, even if that register will just wrap
5746 * things around, we still don't like having out of range variables.
5748 * NOTE: Don't check the aic7xxx_verbose variable, I want this message
5749 * to always be displayed.
5751 printk(INFO_LEAD
"Invalid WAITING_SCBH value %d, improvising.\n",
5752 p
->host_no
, -1, -1, -1, scbptr
);
5753 if (p
->scb_data
->maxhscbs
> 4)
5754 scbptr
&= (p
->scb_data
->maxhscbs
- 1);
5758 aic_outb(p
, scbptr
, SCBPTR
);
5759 scb_index
= aic_inb(p
, SCB_TAG
);
5762 if (scb_index
< p
->scb_data
->numscbs
)
5764 scb
= p
->scb_data
->scb_array
[scb_index
];
5765 if ((scb
->flags
& SCB_ACTIVE
) == 0)
5772 printk(WARN_LEAD
"Referenced SCB %d not valid during SELTO.\n",
5773 p
->host_no
, -1, -1, -1, scb_index
);
5774 printk(KERN_WARNING
" SCSISEQ = 0x%x SEQADDR = 0x%x SSTAT0 = 0x%x "
5775 "SSTAT1 = 0x%x\n", aic_inb(p
, SCSISEQ
),
5776 aic_inb(p
, SEQADDR0
) | (aic_inb(p
, SEQADDR1
) << 8),
5777 aic_inb(p
, SSTAT0
), aic_inb(p
, SSTAT1
));
5778 if (aic7xxx_panic_on_abort
)
5779 aic7xxx_panic_abort(p
, NULL
);
5784 cmd
->result
= (DID_TIME_OUT
<< 16);
5787 * Clear out this hardware SCB
5789 aic_outb(p
, 0, SCB_CONTROL
);
5792 * Clear out a few values in the card that are in an undetermined
5795 aic_outb(p
, MSG_NOOP
, MSG_OUT
);
5798 * Shift the waiting for selection queue forward
5800 nextscb
= aic_inb(p
, SCB_NEXT
);
5801 aic_outb(p
, nextscb
, WAITING_SCBH
);
5804 * Put this SCB back on the free list.
5806 aic7xxx_add_curscb_to_free_list(p
);
5808 * XXX - If we queued an abort tag, go clean up the disconnected list.
5809 * We know that this particular SCB had to be the queued abort since
5810 * the disconnected SCB would have gotten a reconnect instead.
5811 * However, if this is an abort command, then DID_TIMEOUT isn't
5812 * appropriate, neither is returning the command for that matter.
5813 * What we need to do then is to let the command timeout again so
5814 * we get a reset since this abort just failed.
5816 #ifdef AIC7XXX_VERBOSE_DEBUGGING
5817 if (aic7xxx_verbose
> 0xffff)
5818 printk(INFO_LEAD
"Selection Timeout.\n", p
->host_no
, CTL_OF_SCB(scb
));
5820 if (p
->flags
& SCB_QUEUED_ABORT
)
5823 scb
->flags
&= ~SCB_QUEUED_ABORT
;
5828 * Restarting the sequencer will stop the selection and make sure devices
5829 * are allowed to reselect in.
5831 aic_outb(p
, 0, SCSISEQ
);
5832 aic_outb(p
, aic_inb(p
, SIMODE1
) & ~(ENREQINIT
|ENBUSFREE
), SIMODE1
);
5833 p
->flags
&= ~AHC_HANDLING_REQINITS
;
5834 aic_outb(p
, CLRSELTIMEO
| CLRBUSFREE
, CLRSINT1
);
5835 aic_outb(p
, CLRSCSIINT
, CLRINT
);
5836 restart_sequencer(p
);
5837 unpause_sequencer(p
, TRUE
);
5839 else if (scb
== NULL
)
5841 printk(WARN_LEAD
"aic7xxx_isr - referenced scb not valid "
5842 "during scsiint 0x%x scb(%d)\n"
5843 " SIMODE0 0x%x, SIMODE1 0x%x, SSTAT0 0x%x, SEQADDR 0x%x\n",
5844 p
->host_no
, -1, -1, -1, status
, scb_index
, aic_inb(p
, SIMODE0
),
5845 aic_inb(p
, SIMODE1
), aic_inb(p
, SSTAT0
),
5846 (aic_inb(p
, SEQADDR1
) << 8) | aic_inb(p
, SEQADDR0
));
5848 * Turn off the interrupt and set status to zero, so that it
5849 * falls through the rest of the SCSIINT code.
5851 aic_outb(p
, status
, CLRSINT1
);
5852 aic_outb(p
, CLRSCSIINT
, CLRINT
);
5853 unpause_sequencer(p
, /* unpause always */ TRUE
);
5856 else if (status
& SCSIPERR
)
5859 * Determine the bus phase and queue an appropriate message.
5863 unsigned char mesg_out
= MSG_NOOP
;
5864 unsigned char lastphase
= aic_inb(p
, LASTPHASE
);
5874 mesg_out
= MSG_INITIATOR_DET_ERR
;
5880 phase
= "Message-Out";
5884 mesg_out
= MSG_INITIATOR_DET_ERR
;
5887 phase
= "Message-In";
5888 mesg_out
= MSG_PARITY_ERROR
;
5896 * A parity error has occurred during a data
5897 * transfer phase. Flag it and continue.
5899 printk(WARN_LEAD
"Parity error during %s phase.\n",
5900 p
->host_no
, CTL_OF_SCB(scb
), phase
);
5903 * We've set the hardware to assert ATN if we get a parity
5904 * error on "in" phases, so all we need to do is stuff the
5905 * message buffer with the appropriate message. "In" phases
5906 * have set mesg_out to something other than MSG_NOP.
5908 if (mesg_out
!= MSG_NOOP
)
5910 aic_outb(p
, mesg_out
, MSG_OUT
);
5913 aic_outb(p
, CLRSCSIPERR
, CLRSINT1
);
5914 aic_outb(p
, CLRSCSIINT
, CLRINT
);
5915 unpause_sequencer(p
, /* unpause_always */ TRUE
);
5917 else if ( (status
& REQINIT
) &&
5918 (p
->flags
& AHC_HANDLING_REQINITS
) )
5920 #ifdef AIC7XXX_VERBOSE_DEBUGGING
5921 if (aic7xxx_verbose
> 0xffff)
5922 printk(INFO_LEAD
"Handling REQINIT, SSTAT1=0x%x.\n", p
->host_no
,
5923 CTL_OF_SCB(scb
), aic_inb(p
, SSTAT1
));
5925 aic7xxx_handle_reqinit(p
, scb
);
5931 * We don't know what's going on. Turn off the
5932 * interrupt source and try to continue.
5934 if (aic7xxx_verbose
& VERBOSE_SCSIINT
)
5935 printk(INFO_LEAD
"Unknown SCSIINT status, SSTAT1(0x%x).\n",
5936 p
->host_no
, -1, -1, -1, status
);
5937 aic_outb(p
, status
, CLRSINT1
);
5938 aic_outb(p
, CLRSCSIINT
, CLRINT
);
5939 unpause_sequencer(p
, /* unpause always */ TRUE
);
5944 aic7xxx_done(p
, scb
);
5948 #ifdef AIC7XXX_VERBOSE_DEBUGGING
5950 aic7xxx_check_scbs(struct aic7xxx_host
*p
, char *buffer
)
5952 unsigned char saved_scbptr
, free_scbh
, dis_scbh
, wait_scbh
, temp
;
5954 static unsigned char scb_status
[AIC7XXX_MAXSCB
];
5956 #define SCB_NO_LIST 0
5957 #define SCB_FREE_LIST 1
5958 #define SCB_WAITING_LIST 2
5959 #define SCB_DISCONNECTED_LIST 4
5960 #define SCB_CURRENTLY_ACTIVE 8
5963 * Note, these checks will fail on a regular basis once the machine moves
5964 * beyond the bus scan phase. The problem is race conditions concerning
5965 * the scbs and where they are linked in. When you have 30 or so commands
5966 * outstanding on the bus, and run this twice with every interrupt, the
5967 * chances get pretty good that you'll catch the sequencer with an SCB
5968 * only partially linked in. Therefore, once we pass the scan phase
5969 * of the bus, we really should disable this function.
5972 memset(&scb_status
[0], 0, sizeof(scb_status
));
5974 saved_scbptr
= aic_inb(p
, SCBPTR
);
5975 if (saved_scbptr
>= p
->scb_data
->maxhscbs
)
5977 printk("Bogus SCBPTR %d\n", saved_scbptr
);
5980 scb_status
[saved_scbptr
] = SCB_CURRENTLY_ACTIVE
;
5981 free_scbh
= aic_inb(p
, FREE_SCBH
);
5982 if ( (free_scbh
!= SCB_LIST_NULL
) &&
5983 (free_scbh
>= p
->scb_data
->maxhscbs
) )
5985 printk("Bogus FREE_SCBH %d\n", free_scbh
);
5991 while( (temp
!= SCB_LIST_NULL
) && (temp
< p
->scb_data
->maxhscbs
) )
5993 if(scb_status
[temp
] & 0x07)
5995 printk("HSCB %d on multiple lists, status 0x%02x", temp
,
5996 scb_status
[temp
] | SCB_FREE_LIST
);
5999 scb_status
[temp
] |= SCB_FREE_LIST
;
6000 aic_outb(p
, temp
, SCBPTR
);
6001 temp
= aic_inb(p
, SCB_NEXT
);
6005 dis_scbh
= aic_inb(p
, DISCONNECTED_SCBH
);
6006 if ( (dis_scbh
!= SCB_LIST_NULL
) &&
6007 (dis_scbh
>= p
->scb_data
->maxhscbs
) )
6009 printk("Bogus DISCONNECTED_SCBH %d\n", dis_scbh
);
6015 while( (temp
!= SCB_LIST_NULL
) && (temp
< p
->scb_data
->maxhscbs
) )
6017 if(scb_status
[temp
] & 0x07)
6019 printk("HSCB %d on multiple lists, status 0x%02x", temp
,
6020 scb_status
[temp
] | SCB_DISCONNECTED_LIST
);
6023 scb_status
[temp
] |= SCB_DISCONNECTED_LIST
;
6024 aic_outb(p
, temp
, SCBPTR
);
6025 temp
= aic_inb(p
, SCB_NEXT
);
6029 wait_scbh
= aic_inb(p
, WAITING_SCBH
);
6030 if ( (wait_scbh
!= SCB_LIST_NULL
) &&
6031 (wait_scbh
>= p
->scb_data
->maxhscbs
) )
6033 printk("Bogus WAITING_SCBH %d\n", wait_scbh
);
6039 while( (temp
!= SCB_LIST_NULL
) && (temp
< p
->scb_data
->maxhscbs
) )
6041 if(scb_status
[temp
] & 0x07)
6043 printk("HSCB %d on multiple lists, status 0x%02x", temp
,
6044 scb_status
[temp
] | SCB_WAITING_LIST
);
6047 scb_status
[temp
] |= SCB_WAITING_LIST
;
6048 aic_outb(p
, temp
, SCBPTR
);
6049 temp
= aic_inb(p
, SCB_NEXT
);
6054 for(i
=0; i
< p
->scb_data
->maxhscbs
; i
++)
6056 aic_outb(p
, i
, SCBPTR
);
6057 temp
= aic_inb(p
, SCB_NEXT
);
6058 if ( ((temp
!= SCB_LIST_NULL
) &&
6059 (temp
>= p
->scb_data
->maxhscbs
)) )
6061 printk("HSCB %d bad, SCB_NEXT invalid(%d).\n", i
, temp
);
6066 printk("HSCB %d bad, SCB_NEXT points to self.\n", i
);
6069 temp
= aic_inb(p
, SCB_PREV
);
6070 if ((temp
!= SCB_LIST_NULL
) &&
6071 (temp
>= p
->scb_data
->maxhscbs
))
6073 printk("HSCB %d bad, SCB_PREV invalid(%d).\n", i
, temp
);
6076 if (scb_status
[i
] == 0)
6080 printk("Too many lost scbs.\n");
6084 aic_outb(p
, saved_scbptr
, SCBPTR
);
6085 unpause_sequencer(p
, FALSE
);
6088 printk("Bogus parameters found in card SCB array structures.\n");
6089 printk("%s\n", buffer
);
6090 aic7xxx_panic_abort(p
, NULL
);
6096 /*+F*************************************************************************
6101 * SCSI controller interrupt handler.
6102 *-F*************************************************************************/
6104 aic7xxx_isr(int irq
, void *dev_id
, struct pt_regs
*regs
)
6106 struct aic7xxx_host
*p
;
6107 unsigned char intstat
;
6109 p
= (struct aic7xxx_host
*)dev_id
;
6112 * Just a few sanity checks. Make sure that we have an int pending.
6113 * Also, if PCI, then we are going to check for a PCI bus error status
6114 * should we get too many spurious interrupts.
6116 if (!((intstat
= aic_inb(p
, INTSTAT
)) & INT_PEND
))
6119 if ( (p
->chip
& AHC_PCI
) && (p
->spurious_int
> 500) &&
6120 !(p
->flags
& AHC_HANDLING_REQINITS
) )
6122 if ( aic_inb(p
, ERROR
) & PCIERRSTAT
)
6124 aic7xxx_pci_intr(p
);
6126 p
->spurious_int
= 0;
6128 else if ( !(p
->flags
& AHC_HANDLING_REQINITS
) )
6136 p
->spurious_int
= 0;
6139 * Keep track of interrupts for /proc/scsi
6143 #ifdef AIC7XXX_VERBOSE_DEBUGGING
6144 if ( (p
->isr_count
< 16) && (aic7xxx_verbose
> 0xffff) &&
6145 (aic7xxx_panic_on_abort
) && (p
->flags
& AHC_PAGESCBS
) )
6146 aic7xxx_check_scbs(p
, "Bogus settings at start of interrupt.");
6150 * Handle all the interrupt sources - especially for SCSI
6151 * interrupts, we won't get a second chance at them.
6153 if (intstat
& CMDCMPLT
)
6155 struct aic7xxx_scb
*scb
= NULL
;
6157 unsigned char scb_index
;
6159 #ifdef AIC7XXX_VERBOSE_DEBUGGING
6160 if(aic7xxx_verbose
> 0xffff)
6161 printk(INFO_LEAD
"Command Complete Int.\n", p
->host_no
, -1, -1, -1);
6165 * Clear interrupt status before running the completion loop.
6166 * This eliminates a race condition whereby a command could
6167 * complete between the last check of qoutfifo and the
6168 * CLRCMDINT statement. This would result in us thinking the
6169 * qoutfifo was empty when it wasn't, and in actuality be a lost
6170 * completion interrupt. With multiple devices or tagged queueing
6171 * this could be very bad if we caught all but the last completion
6172 * and no more are imediately sent.
6174 aic_outb(p
, CLRCMDINT
, CLRINT
);
6176 * The sequencer will continue running when it
6177 * issues this interrupt. There may be >1 commands
6178 * finished, so loop until we've processed them all.
6181 while (p
->qoutfifo
[p
->qoutfifonext
] != SCB_LIST_NULL
)
6183 scb_index
= p
->qoutfifo
[p
->qoutfifonext
];
6184 p
->qoutfifo
[p
->qoutfifonext
++] = SCB_LIST_NULL
;
6185 if ( scb_index
>= p
->scb_data
->numscbs
)
6188 scb
= p
->scb_data
->scb_array
[scb_index
];
6191 printk(WARN_LEAD
"CMDCMPLT with invalid SCB index %d\n", p
->host_no
,
6192 -1, -1, -1, scb_index
);
6195 else if (!(scb
->flags
& SCB_ACTIVE
) || (scb
->cmd
== NULL
))
6197 printk(WARN_LEAD
"CMDCMPLT without command for SCB %d, SCB flags "
6198 "0x%x, cmd 0x%lx\n", p
->host_no
, -1, -1, -1, scb_index
, scb
->flags
,
6199 (unsigned long) scb
->cmd
);
6202 else if (scb
->flags
& SCB_QUEUED_ABORT
)
6205 if ( ((aic_inb(p
, LASTPHASE
) & PHASE_MASK
) != P_BUSFREE
) &&
6206 (aic_inb(p
, SCB_TAG
) == scb
->hscb
->tag
) )
6208 unpause_sequencer(p
, FALSE
);
6211 aic7xxx_reset_device(p
, scb
->cmd
->target
, scb
->cmd
->channel
,
6212 scb
->cmd
->lun
, scb
->hscb
->tag
);
6213 scb
->flags
&= ~(SCB_QUEUED_FOR_DONE
| SCB_RESET
| SCB_ABORT
|
6215 unpause_sequencer(p
, FALSE
);
6217 else if (scb
->flags
& SCB_ABORT
)
6220 * We started to abort this, but it completed on us, let it
6221 * through as successful
6223 scb
->flags
&= ~(SCB_ABORT
|SCB_RESET
);
6225 switch (status_byte(scb
->hscb
->target_status
))
6229 scb
->hscb
->target_status
= 0;
6230 scb
->cmd
->result
= 0;
6231 aic7xxx_error(scb
->cmd
) = DID_OK
;
6235 if (scb
->hscb
->residual_SG_segment_count
!= 0)
6237 aic7xxx_calculate_residual(p
, scb
);
6239 cmd
->result
|= (aic7xxx_error(cmd
) << 16);
6240 if (scb
->tag_action
)
6241 p
->dev_flags
[TARGET_INDEX(cmd
)] |=
6242 DEVICE_TAGGED_SUCCESS
| DEVICE_SUCCESS
| DEVICE_PRESENT
;
6244 p
->dev_flags
[TARGET_INDEX(cmd
)] |=
6245 DEVICE_SUCCESS
| DEVICE_PRESENT
;
6246 aic7xxx_done(p
, scb
);
6252 if (intstat
& BRKADRINT
)
6255 unsigned char errno
= aic_inb(p
, ERROR
);
6257 printk(KERN_ERR
"(scsi%d) BRKADRINT error(0x%x):\n", p
->host_no
, errno
);
6258 for (i
= 0; i
< NUMBER(hard_error
); i
++)
6260 if (errno
& hard_error
[i
].errno
)
6262 printk(KERN_ERR
" %s\n", hard_error
[i
].errmesg
);
6265 printk(KERN_ERR
"(scsi%d) SEQADDR=0x%x\n", p
->host_no
,
6266 (((aic_inb(p
, SEQADDR1
) << 8) & 0x100) | aic_inb(p
, SEQADDR0
)));
6267 if (aic7xxx_panic_on_abort
)
6268 aic7xxx_panic_abort(p
, NULL
);
6270 if (errno
& PCIERRSTAT
)
6271 aic7xxx_pci_intr(p
);
6273 if (errno
& (SQPARERR
| ILLOPCODE
| ILLSADDR
))
6276 panic("aic7xxx: unrecoverable BRKADRINT.\n");
6278 if (errno
& ILLHADDR
)
6280 printk(KERN_ERR
"(scsi%d) BUG! Driver accessed chip without first "
6281 "pausing controller!\n", p
->host_no
);
6283 #ifdef AIC7XXX_VERBOSE_DEBUGGING
6284 if (errno
& DPARERR
)
6286 if (aic_inb(p
, DMAPARAMS
) & DIRECTION
)
6287 printk("(scsi%d) while DMAing SCB from host to card.\n", p
->host_no
);
6289 printk("(scsi%d) while DMAing SCB from card to host.\n", p
->host_no
);
6292 aic_outb(p
, CLRPARERR
| CLRBRKADRINT
, CLRINT
);
6293 unpause_sequencer(p
, FALSE
);
6296 if (intstat
& SEQINT
)
6298 aic7xxx_handle_seqint(p
, intstat
);
6301 if (intstat
& SCSIINT
)
6303 aic7xxx_handle_scsiint(p
, intstat
);
6306 #ifdef AIC7XXX_VERBOSE_DEBUGGING
6307 if ( (p
->isr_count
< 16) && (aic7xxx_verbose
> 0xffff) &&
6308 (aic7xxx_panic_on_abort
) && (p
->flags
& AHC_PAGESCBS
) )
6309 aic7xxx_check_scbs(p
, "Bogus settings at end of interrupt.");
6314 /*+F*************************************************************************
6319 * This is a gross hack to solve a problem in linux kernels 2.1.85 and
6320 * above. Please, children, do not try this at home, and if you ever see
6321 * anything like it, please inform the Gross Hack Police immediately
6322 *-F*************************************************************************/
6324 do_aic7xxx_isr(int irq
, void *dev_id
, struct pt_regs
*regs
)
6326 unsigned long cpu_flags
;
6327 struct aic7xxx_host
*p
;
6329 p
= (struct aic7xxx_host
*)dev_id
;
6332 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,1,95)
6333 spin_lock_irqsave(&io_request_lock
, cpu_flags
);
6334 if(test_and_set_bit(AHC_IN_ISR_BIT
, &p
->flags
))
6340 aic7xxx_isr(irq
, dev_id
, regs
);
6341 } while ( (aic_inb(p
, INTSTAT
) & INT_PEND
) );
6342 aic7xxx_done_cmds_complete(p
);
6343 aic7xxx_run_waiting_queues(p
);
6344 clear_bit(AHC_IN_ISR_BIT
, &p
->flags
);
6345 spin_unlock_irqrestore(&io_request_lock
, cpu_flags
);
6347 if(set_bit(AHC_IN_ISR_BIT
, (int *)&p
->flags
))
6354 aic7xxx_isr(irq
, dev_id
, regs
);
6355 } while ( (aic_inb(p
, INTSTAT
) & INT_PEND
) );
6357 aic7xxx_done_cmds_complete(p
);
6358 aic7xxx_run_waiting_queues(p
);
6359 clear_bit(AHC_IN_ISR_BIT
, (int *)&p
->flags
);
6363 /*+F*************************************************************************
6365 * aic7xxx_device_queue_depth
6368 * Determines the queue depth for a given device. There are two ways
6369 * a queue depth can be obtained for a tagged queueing device. One
6370 * way is the default queue depth which is determined by whether
6371 * AIC7XXX_CMDS_PER_LUN is defined. If it is defined, then it is used
6372 * as the default queue depth. Otherwise, we use either 4 or 8 as the
6373 * default queue depth (dependent on the number of hardware SCBs).
6374 * The other way we determine queue depth is through the use of the
6375 * aic7xxx_tag_info array which is enabled by defining
6376 * AIC7XXX_TAGGED_QUEUEING_BY_DEVICE. This array can be initialized
6377 * with queue depths for individual devices. It also allows tagged
6378 * queueing to be [en|dis]abled for a specific adapter.
6379 *-F*************************************************************************/
6381 aic7xxx_device_queue_depth(struct aic7xxx_host
*p
, Scsi_Device
*device
)
6383 int default_depth
= 3;
6384 unsigned char tindex
;
6385 unsigned short target_mask
;
6387 tindex
= device
->id
| (device
->channel
<< 3);
6388 target_mask
= (1 << tindex
);
6390 device
->queue_depth
= default_depth
;
6391 p
->dev_mid_level_queue_depth
[tindex
] = 3;
6392 p
->dev_temp_queue_depth
[tindex
] = 1;
6393 p
->dev_max_queue_depth
[tindex
] = 1;
6394 p
->tagenable
&= ~target_mask
;
6396 if (device
->tagged_supported
)
6398 int tag_enabled
= TRUE
;
6400 #ifdef AIC7XXX_CMDS_PER_LUN
6401 default_depth
= AIC7XXX_CMDS_PER_LUN
;
6403 default_depth
= 8; /* Not many SCBs to work with. */
6406 if (!(p
->discenable
& target_mask
))
6408 if (aic7xxx_verbose
& VERBOSE_NEGOTIATION2
)
6409 printk(INFO_LEAD
"Disconnection disabled, unable to "
6410 "enable tagged queueing.\n",
6411 p
->host_no
, device
->channel
, device
->id
, device
->lun
);
6415 if (p
->instance
>= NUMBER(aic7xxx_tag_info
))
6417 static int print_warning
= TRUE
;
6420 printk(KERN_INFO
"aic7xxx: WARNING, insufficient tag_info instances for"
6421 " installed controllers.\n");
6422 printk(KERN_INFO
"aic7xxx: Please update the aic7xxx_tag_info array in"
6423 " the aic7xxx.c source file.\n");
6424 print_warning
= FALSE
;
6426 device
->queue_depth
= default_depth
;
6431 if (aic7xxx_tag_info
[p
->instance
].tag_commands
[tindex
] == 255)
6433 tag_enabled
= FALSE
;
6434 device
->queue_depth
= 3; /* Tagged queueing is disabled. */
6436 else if (aic7xxx_tag_info
[p
->instance
].tag_commands
[tindex
] == 0)
6438 device
->queue_depth
= default_depth
;
6442 device
->queue_depth
=
6443 aic7xxx_tag_info
[p
->instance
].tag_commands
[tindex
];
6446 if ((device
->tagged_queue
== 0) && tag_enabled
)
6448 if (aic7xxx_verbose
& VERBOSE_NEGOTIATION2
)
6450 printk(INFO_LEAD
"Enabled tagged queuing, queue depth %d.\n",
6451 p
->host_no
, device
->channel
, device
->id
,
6452 device
->lun
, device
->queue_depth
);
6454 p
->dev_max_queue_depth
[tindex
] = device
->queue_depth
;
6455 p
->dev_temp_queue_depth
[tindex
] = device
->queue_depth
;
6456 p
->dev_mid_level_queue_depth
[tindex
] = device
->queue_depth
;
6457 p
->tagenable
|= target_mask
;
6458 p
->orderedtag
|= target_mask
;
6459 device
->tagged_queue
= 1;
6460 device
->current_tag
= SCB_LIST_NULL
;
6466 /*+F*************************************************************************
6468 * aic7xxx_select_queue_depth
6471 * Sets the queue depth for each SCSI device hanging off the input
6472 * host adapter. We use a queue depth of 2 for devices that do not
6473 * support tagged queueing. If AIC7XXX_CMDS_PER_LUN is defined, we
6474 * use that for tagged queueing devices; otherwise we use our own
6475 * algorithm for determining the queue depth based on the maximum
6476 * SCBs for the controller.
6477 *-F*************************************************************************/
6479 aic7xxx_select_queue_depth(struct Scsi_Host
*host
,
6480 Scsi_Device
*scsi_devs
)
6482 Scsi_Device
*device
;
6483 struct aic7xxx_host
*p
= (struct aic7xxx_host
*) host
->hostdata
;
6487 for (device
= scsi_devs
; device
!= NULL
; device
= device
->next
)
6489 if (device
->host
== host
)
6491 aic7xxx_device_queue_depth(p
, device
);
6492 scbnum
+= device
->queue_depth
;
6495 while (scbnum
> p
->scb_data
->numscbs
)
6498 * Pre-allocate the needed SCBs to get around the possibility of having
6499 * to allocate some when memory is more or less exhausted and we need
6500 * the SCB in order to perform a swap operation (possible deadlock)
6502 if ( aic7xxx_allocate_scb(p
) == 0 )
6507 /*+F*************************************************************************
6512 * Probing for EISA boards: it looks like the first two bytes
6513 * are a manufacturer code - three characters, five bits each:
6515 * BYTE 0 BYTE 1 BYTE 2 BYTE 3
6516 * ?1111122 22233333 PPPPPPPP RRRRRRRR
6518 * The characters are baselined off ASCII '@', so add that value
6519 * to each to get the real ASCII code for it. The next two bytes
6520 * appear to be a product and revision number, probably vendor-
6521 * specific. This is what is being searched for at each port,
6522 * and what should probably correspond to the ID= field in the
6523 * ECU's .cfg file for the card - if your card is not detected,
6524 * make sure your signature is listed in the array.
6526 * The fourth byte's lowest bit seems to be an enabled/disabled
6527 * flag (rest of the bits are reserved?).
6529 * NOTE: This function is only needed on Intel and Alpha platforms,
6530 * the other platforms we support don't have EISA/VLB busses. So,
6531 * we #ifdef this entire function to avoid compiler warnings about
6532 * an unused function.
6533 *-F*************************************************************************/
6534 #if defined(__i386__) || defined(__alpha__)
6536 aic7xxx_probe(int slot
, int base
, ahc_flag_type
*flags
)
6539 unsigned char buf
[4];
6543 unsigned char signature
[sizeof(buf
)];
6547 { 4, { 0x04, 0x90, 0x77, 0x70 },
6548 AHC_AIC7770
|AHC_EISA
, FALSE
}, /* mb 7770 */
6549 { 4, { 0x04, 0x90, 0x77, 0x71 },
6550 AHC_AIC7770
|AHC_EISA
, FALSE
}, /* host adapter 274x */
6551 { 4, { 0x04, 0x90, 0x77, 0x56 },
6552 AHC_AIC7770
|AHC_VL
, FALSE
}, /* 284x BIOS enabled */
6553 { 4, { 0x04, 0x90, 0x77, 0x57 },
6554 AHC_AIC7770
|AHC_VL
, TRUE
} /* 284x BIOS disabled */
6558 * The VL-bus cards need to be primed by
6559 * writing before a signature check.
6561 for (i
= 0; i
< sizeof(buf
); i
++)
6563 outb(0x80 + i
, base
);
6564 buf
[i
] = inb(base
+ i
);
6567 for (i
= 0; i
< NUMBER(AIC7xxx
); i
++)
6570 * Signature match on enabled card?
6572 if (!memcmp(buf
, AIC7xxx
[i
].signature
, AIC7xxx
[i
].n
))
6574 if (inb(base
+ 4) & 1)
6576 if (AIC7xxx
[i
].bios_disabled
)
6578 *flags
|= AHC_USEDEFAULTS
;
6582 *flags
|= AHC_BIOS_ENABLED
;
6587 printk("aic7xxx: <Adaptec 7770 SCSI Host Adapter> "
6588 "disabled at slot %d, ignored.\n", slot
);
6594 #endif /* (__i386__) || (__alpha__) */
6597 /*+F*************************************************************************
6602 * Reads the 2840 serial EEPROM and returns 1 if successful and 0 if
6605 * See read_seeprom (for the 2940) for the instruction set of the 93C46
6608 * The 2840 interface to the 93C46 serial EEPROM is through the
6609 * STATUS_2840 and SEECTL_2840 registers. The CS_2840, CK_2840, and
6610 * DO_2840 bits of the SEECTL_2840 register are connected to the chip
6611 * select, clock, and data out lines respectively of the serial EEPROM.
6612 * The DI_2840 bit of the STATUS_2840 is connected to the data in line
6613 * of the serial EEPROM. The EEPROM_TF bit of STATUS_2840 register is
6614 * useful in that it gives us an 800 nsec timer. After a read from the
6615 * SEECTL_2840 register the timing flag is cleared and goes high 800 nsec
6617 *-F*************************************************************************/
6619 read_284x_seeprom(struct aic7xxx_host
*p
, struct seeprom_config
*sc
)
6623 unsigned short checksum
= 0;
6624 unsigned short *seeprom
= (unsigned short *) sc
;
6625 struct seeprom_cmd
{
6627 unsigned char bits
[3];
6629 struct seeprom_cmd seeprom_read
= {3, {1, 1, 0}};
6631 #define CLOCK_PULSE(p) \
6632 while ((aic_inb(p, STATUS_2840) & EEPROM_TF) == 0) \
6634 ; /* Do nothing */ \
6636 (void) aic_inb(p, SEECTL_2840);
6639 * Read the first 32 registers of the seeprom. For the 2840,
6640 * the 93C46 SEEPROM is a 1024-bit device with 64 16-bit registers
6641 * but only the first 32 are used by Adaptec BIOS. The loop
6642 * will range from 0 to 31.
6644 for (k
= 0; k
< (sizeof(*sc
) / 2); k
++)
6647 * Send chip select for one clock cycle.
6649 aic_outb(p
, CK_2840
| CS_2840
, SEECTL_2840
);
6653 * Now we're ready to send the read command followed by the
6654 * address of the 16-bit register we want to read.
6656 for (i
= 0; i
< seeprom_read
.len
; i
++)
6658 temp
= CS_2840
| seeprom_read
.bits
[i
];
6659 aic_outb(p
, temp
, SEECTL_2840
);
6661 temp
= temp
^ CK_2840
;
6662 aic_outb(p
, temp
, SEECTL_2840
);
6666 * Send the 6 bit address (MSB first, LSB last).
6668 for (i
= 5; i
>= 0; i
--)
6671 temp
= (temp
>> i
) & 1; /* Mask out all but lower bit. */
6672 temp
= CS_2840
| temp
;
6673 aic_outb(p
, temp
, SEECTL_2840
);
6675 temp
= temp
^ CK_2840
;
6676 aic_outb(p
, temp
, SEECTL_2840
);
6681 * Now read the 16 bit register. An initial 0 precedes the
6682 * register contents which begins with bit 15 (MSB) and ends
6683 * with bit 0 (LSB). The initial 0 will be shifted off the
6684 * top of our word as we let the loop run from 0 to 16.
6686 for (i
= 0; i
<= 16; i
++)
6689 aic_outb(p
, temp
, SEECTL_2840
);
6691 temp
= temp
^ CK_2840
;
6692 seeprom
[k
] = (seeprom
[k
] << 1) | (aic_inb(p
, STATUS_2840
) & DI_2840
);
6693 aic_outb(p
, temp
, SEECTL_2840
);
6697 * The serial EEPROM has a checksum in the last word. Keep a
6698 * running checksum for all words read except for the last
6699 * word. We'll verify the checksum after all words have been
6702 if (k
< (sizeof(*sc
) / 2) - 1)
6704 checksum
= checksum
+ seeprom
[k
];
6708 * Reset the chip select for the next command cycle.
6710 aic_outb(p
, 0, SEECTL_2840
);
6712 aic_outb(p
, CK_2840
, SEECTL_2840
);
6714 aic_outb(p
, 0, SEECTL_2840
);
6719 printk("Computed checksum 0x%x, checksum read 0x%x\n", checksum
, sc
->checksum
);
6720 printk("Serial EEPROM:");
6721 for (k
= 0; k
< (sizeof(*sc
) / 2); k
++)
6723 if (((k
% 8) == 0) && (k
!= 0))
6727 printk(" 0x%x", seeprom
[k
]);
6732 if (checksum
!= sc
->checksum
)
6734 printk("aic7xxx: SEEPROM checksum error, ignoring SEEPROM settings.\n");
6742 /*+F*************************************************************************
6747 * Acquires access to the memory port on PCI controllers.
6748 *-F*************************************************************************/
6750 acquire_seeprom(struct aic7xxx_host
*p
)
6755 * Request access of the memory port. When access is
6756 * granted, SEERDY will go high. We use a 1 second
6757 * timeout which should be near 1 second more than
6758 * is needed. Reason: after the 7870 chip reset, there
6759 * should be no contention.
6761 aic_outb(p
, SEEMS
, SEECTL
);
6762 wait
= 1000; /* 1000 msec = 1 second */
6763 while ((wait
> 0) && ((aic_inb(p
, SEECTL
) & SEERDY
) == 0))
6766 mdelay(1); /* 1 msec */
6768 if ((aic_inb(p
, SEECTL
) & SEERDY
) == 0)
6770 aic_outb(p
, 0, SEECTL
);
6776 /*+F*************************************************************************
6781 * Releases access to the memory port on PCI controllers.
6782 *-F*************************************************************************/
6784 release_seeprom(struct aic7xxx_host
*p
)
6786 aic_outb(p
, 0, SEECTL
);
6789 /*+F*************************************************************************
6794 * Reads the serial EEPROM and returns 1 if successful and 0 if
6797 * The instruction set of the 93C46/56/66 chips is as follows:
6800 * Function Bit Code Address Data Description
6801 * -------------------------------------------------------------------
6802 * READ 1 10 A5 - A0 Reads data stored in memory,
6803 * starting at specified address
6804 * EWEN 1 00 11XXXX Write enable must precede
6805 * all programming modes
6806 * ERASE 1 11 A5 - A0 Erase register A5A4A3A2A1A0
6807 * WRITE 1 01 A5 - A0 D15 - D0 Writes register
6808 * ERAL 1 00 10XXXX Erase all registers
6809 * WRAL 1 00 01XXXX D15 - D0 Writes to all registers
6810 * EWDS 1 00 00XXXX Disables all programming
6812 * *Note: A value of X for address is a don't care condition.
6813 * *Note: The 93C56 and 93C66 have 8 address bits.
6816 * The 93C46 has a four wire interface: clock, chip select, data in, and
6817 * data out. In order to perform one of the above functions, you need
6818 * to enable the chip select for a clock period (typically a minimum of
6819 * 1 usec, with the clock high and low a minimum of 750 and 250 nsec
6820 * respectively. While the chip select remains high, you can clock in
6821 * the instructions (above) starting with the start bit, followed by the
6822 * OP code, Address, and Data (if needed). For the READ instruction, the
6823 * requested 16-bit register contents is read from the data out line but
6824 * is preceded by an initial zero (leading 0, followed by 16-bits, MSB
6825 * first). The clock cycling from low to high initiates the next data
6826 * bit to be sent from the chip.
6828 * The 78xx interface to the 93C46 serial EEPROM is through the SEECTL
6829 * register. After successful arbitration for the memory port, the
6830 * SEECS bit of the SEECTL register is connected to the chip select.
6831 * The SEECK, SEEDO, and SEEDI are connected to the clock, data out,
6832 * and data in lines respectively. The SEERDY bit of SEECTL is useful
6833 * in that it gives us an 800 nsec timer. After a write to the SEECTL
6834 * register, the SEERDY goes high 800 nsec later. The one exception
6835 * to this is when we first request access to the memory port. The
6836 * SEERDY goes high to signify that access has been granted and, for
6837 * this case, has no implied timing.
6838 *-F*************************************************************************/
6840 read_seeprom(struct aic7xxx_host
*p
, int offset
,
6841 unsigned short *scarray
, unsigned int len
, seeprom_chip_type chip
)
6845 unsigned short checksum
= 0;
6846 struct seeprom_cmd
{
6848 unsigned char bits
[3];
6850 struct seeprom_cmd seeprom_read
= {3, {1, 1, 0}};
6852 #define CLOCK_PULSE(p) \
6853 while ((aic_inb(p, SEECTL) & SEERDY) == 0) \
6855 ; /* Do nothing */ \
6859 * Request access of the memory port.
6861 if (acquire_seeprom(p
) == 0)
6867 * Read 'len' registers of the seeprom. For the 7870, the 93C46
6868 * SEEPROM is a 1024-bit device with 64 16-bit registers but only
6869 * the first 32 are used by Adaptec BIOS. Some adapters use the
6870 * 93C56 SEEPROM which is a 2048-bit device. The loop will range
6871 * from 0 to 'len' - 1.
6873 for (k
= 0; k
< len
; k
++)
6876 * Send chip select for one clock cycle.
6878 aic_outb(p
, SEEMS
| SEECK
| SEECS
, SEECTL
);
6882 * Now we're ready to send the read command followed by the
6883 * address of the 16-bit register we want to read.
6885 for (i
= 0; i
< seeprom_read
.len
; i
++)
6887 temp
= SEEMS
| SEECS
| (seeprom_read
.bits
[i
] << 1);
6888 aic_outb(p
, temp
, SEECTL
);
6890 temp
= temp
^ SEECK
;
6891 aic_outb(p
, temp
, SEECTL
);
6895 * Send the 6 or 8 bit address (MSB first, LSB last).
6897 for (i
= ((int) chip
- 1); i
>= 0; i
--)
6900 temp
= (temp
>> i
) & 1; /* Mask out all but lower bit. */
6901 temp
= SEEMS
| SEECS
| (temp
<< 1);
6902 aic_outb(p
, temp
, SEECTL
);
6904 temp
= temp
^ SEECK
;
6905 aic_outb(p
, temp
, SEECTL
);
6910 * Now read the 16 bit register. An initial 0 precedes the
6911 * register contents which begins with bit 15 (MSB) and ends
6912 * with bit 0 (LSB). The initial 0 will be shifted off the
6913 * top of our word as we let the loop run from 0 to 16.
6915 for (i
= 0; i
<= 16; i
++)
6917 temp
= SEEMS
| SEECS
;
6918 aic_outb(p
, temp
, SEECTL
);
6920 temp
= temp
^ SEECK
;
6921 scarray
[k
] = (scarray
[k
] << 1) | (aic_inb(p
, SEECTL
) & SEEDI
);
6922 aic_outb(p
, temp
, SEECTL
);
6927 * The serial EEPROM should have a checksum in the last word.
6928 * Keep a running checksum for all words read except for the
6929 * last word. We'll verify the checksum after all words have
6934 checksum
= checksum
+ scarray
[k
];
6938 * Reset the chip select for the next command cycle.
6940 aic_outb(p
, SEEMS
, SEECTL
);
6942 aic_outb(p
, SEEMS
| SEECK
, SEECTL
);
6944 aic_outb(p
, SEEMS
, SEECTL
);
6949 * Release access to the memory port and the serial EEPROM.
6954 printk("Computed checksum 0x%x, checksum read 0x%x\n",
6955 checksum
, scarray
[len
- 1]);
6956 printk("Serial EEPROM:");
6957 for (k
= 0; k
< len
; k
++)
6959 if (((k
% 8) == 0) && (k
!= 0))
6963 printk(" 0x%x", scarray
[k
]);
6967 if (checksum
!= scarray
[len
- 1])
6976 /*+F*************************************************************************
6981 * Writes a value to the BRDCTL register.
6982 *-F*************************************************************************/
6984 write_brdctl(struct aic7xxx_host
*p
, unsigned char value
)
6986 unsigned char brdctl
;
6988 if ((p
->chip
& AHC_CHIPID_MASK
) == AHC_AIC7895
)
6991 if (p
->flags
& AHC_CHNLB
)
6994 else if (p
->features
& AHC_ULTRA2
)
6997 brdctl
= BRDSTB
| BRDCS
;
6998 aic_outb(p
, brdctl
, BRDCTL
);
7001 aic_outb(p
, brdctl
, BRDCTL
);
7003 if (p
->features
& AHC_ULTRA2
)
7004 brdctl
|= BRDSTB_ULTRA2
;
7007 aic_outb(p
, brdctl
, BRDCTL
);
7009 if (p
->features
& AHC_ULTRA2
)
7013 aic_outb(p
, brdctl
, BRDCTL
);
7017 /*+F*************************************************************************
7022 * Reads the BRDCTL register.
7023 *-F*************************************************************************/
7024 static unsigned char
7025 read_brdctl(struct aic7xxx_host
*p
)
7027 unsigned char brdctl
, value
;
7029 if ((p
->chip
& AHC_CHIPID_MASK
) == AHC_AIC7895
)
7032 if (p
->flags
& AHC_CHNLB
)
7035 else if (p
->features
& AHC_ULTRA2
)
7036 brdctl
= BRDRW_ULTRA2
;
7038 brdctl
= BRDRW
| BRDCS
;
7039 aic_outb(p
, brdctl
, BRDCTL
);
7041 value
= aic_inb(p
, BRDCTL
);
7042 aic_outb(p
, 0, BRDCTL
);
7047 /*+F*************************************************************************
7049 * aic785x_cable_detect
7052 * Detect the cables that are present on aic785x class controller chips
7053 *-F*************************************************************************/
7055 aic785x_cable_detect(struct aic7xxx_host
*p
, int *int_50
,
7056 int *ext_present
, int *eeprom
)
7058 unsigned char brdctl
;
7060 aic_outb(p
, BRDRW
| BRDCS
, BRDCTL
);
7062 aic_outb(p
, 0, BRDCTL
);
7064 brdctl
= aic_inb(p
, BRDCTL
);
7066 *int_50
= !(brdctl
& BRDDAT5
);
7067 *ext_present
= !(brdctl
& BRDDAT6
);
7068 *eeprom
= (aic_inb(p
, SPIOCAP
) & EEPROM
);
7071 /*+F*************************************************************************
7073 * aic787x_cable_detect
7076 * Detect the cables that are present on aic787x class controller chips
7078 * NOTE: This functions assumes the SEEPROM will have already been aquired
7079 * prior to invocation of this function.
7080 *-F*************************************************************************/
7082 aic787x_cable_detect(struct aic7xxx_host
*p
, int *int_50
, int *int_68
,
7083 int *ext_present
, int *eeprom
)
7085 unsigned char brdctl
;
7088 * First read the status of our cables. Set the rom bank to
7089 * 0 since the bank setting serves as a multiplexor for the
7090 * cable detection logic. BRDDAT5 controls the bank switch.
7095 * Now we read the state of the two internal connectors. BRDDAT6
7096 * is internal 50, BRDDAT7 is internal 68. For each, the cable is
7097 * present if the bit is 0
7099 brdctl
= read_brdctl(p
);
7100 *int_50
= !(brdctl
& BRDDAT6
);
7101 *int_68
= !(brdctl
& BRDDAT7
);
7104 * Set the bank bit in brdctl and then read the external cable state
7105 * and the EEPROM status
7107 write_brdctl(p
, BRDDAT5
);
7108 brdctl
= read_brdctl(p
);
7110 *ext_present
= !(brdctl
& BRDDAT6
);
7111 *eeprom
= !(brdctl
& BRDDAT7
);
7114 * We're done, the calling function will release the SEEPROM for us
7118 /*+F*************************************************************************
7120 * aic787x_ultra2_term_detect
7123 * Detect the termination settings present on ultra2 class controllers
7125 * NOTE: This functions assumes the SEEPROM will have already been aquired
7126 * prior to invocation of this function.
7127 *-F*************************************************************************/
7129 aic7xxx_ultra2_term_detect(struct aic7xxx_host
*p
, int *enableSE_low
,
7130 int *enableSE_high
, int *enableLVD_low
,
7131 int *enableLVD_high
, int *eprom_present
)
7133 unsigned char brdctl
;
7135 brdctl
= read_brdctl(p
);
7137 *eprom_present
= (brdctl
& BRDDAT7
);
7138 *enableSE_high
= (brdctl
& BRDDAT6
);
7139 *enableSE_low
= (brdctl
& BRDDAT5
);
7140 *enableLVD_high
= (brdctl
& BRDDAT4
);
7141 *enableLVD_low
= (brdctl
& BRDDAT3
);
7144 /*+F*************************************************************************
7146 * configure_termination
7149 * Configures the termination settings on PCI adapters that have
7150 * SEEPROMs available.
7151 *-F*************************************************************************/
7153 configure_termination(struct aic7xxx_host
*p
)
7155 int internal50_present
= 0;
7156 int internal68_present
= 0;
7157 int external_present
= 0;
7158 int eprom_present
= 0;
7159 int enableSE_low
= 0;
7160 int enableSE_high
= 0;
7161 int enableLVD_low
= 0;
7162 int enableLVD_high
= 0;
7163 unsigned char brddat
= 0;
7164 unsigned char max_target
= 0;
7165 unsigned char sxfrctl1
= aic_inb(p
, SXFRCTL1
);
7167 if (acquire_seeprom(p
))
7169 if (p
->features
& (AHC_WIDE
|AHC_TWIN
))
7173 aic_outb(p
, SEEMS
| SEECS
, SEECTL
);
7174 sxfrctl1
&= ~STPWEN
;
7175 if ( (p
->adapter_control
& CFAUTOTERM
) ||
7176 (p
->features
& AHC_ULTRA2
) )
7178 if ( (p
->adapter_control
& CFAUTOTERM
) && !(p
->features
& AHC_ULTRA2
) )
7180 printk(KERN_INFO
"(scsi%d) Warning - detected auto-termination\n",
7182 printk(KERN_INFO
"(scsi%d) Please verify driver detected settings are "
7183 "correct.\n", p
->host_no
);
7184 printk(KERN_INFO
"(scsi%d) If not, then please properly set the device "
7185 "termination\n", p
->host_no
);
7186 printk(KERN_INFO
"(scsi%d) in the Adaptec SCSI BIOS by hitting CTRL-A "
7187 "when prompted\n", p
->host_no
);
7188 printk(KERN_INFO
"(scsi%d) during machine bootup.\n", p
->host_no
);
7190 /* Configure auto termination. */
7192 if (p
->features
& AHC_ULTRA2
)
7194 if (aic7xxx_override_term
== -1)
7195 aic7xxx_ultra2_term_detect(p
, &enableSE_low
, &enableSE_high
,
7196 &enableLVD_low
, &enableLVD_high
,
7198 if (!(p
->adapter_control
& CFSEAUTOTERM
))
7200 enableSE_low
= (p
->adapter_control
& CFSTERM
);
7201 enableSE_high
= (p
->adapter_control
& CFWSTERM
);
7203 if (!(p
->adapter_control
& CFAUTOTERM
))
7205 enableLVD_low
= enableLVD_high
= (p
->adapter_control
& CFLVDSTERM
);
7207 internal50_present
= 0;
7208 internal68_present
= 1;
7209 external_present
= 1;
7211 else if ( (p
->chip
& AHC_CHIPID_MASK
) >= AHC_AIC7870
)
7213 aic787x_cable_detect(p
, &internal50_present
, &internal68_present
,
7214 &external_present
, &eprom_present
);
7218 aic785x_cable_detect(p
, &internal50_present
, &external_present
,
7222 if (max_target
<= 8)
7223 internal68_present
= 0;
7225 if ( !(p
->features
& AHC_ULTRA2
) )
7229 printk(KERN_INFO
"(scsi%d) Cables present (Int-50 %s, Int-68 %s, "
7230 "Ext-68 %s)\n", p
->host_no
,
7231 internal50_present
? "YES" : "NO",
7232 internal68_present
? "YES" : "NO",
7233 external_present
? "YES" : "NO");
7237 printk(KERN_INFO
"(scsi%d) Cables present (Int-50 %s, Ext-50 %s)\n",
7239 internal50_present
? "YES" : "NO",
7240 external_present
? "YES" : "NO");
7243 if (aic7xxx_verbose
& VERBOSE_PROBE2
)
7244 printk(KERN_INFO
"(scsi%d) EEPROM %s present.\n", p
->host_no
,
7245 eprom_present
? "is" : "is not");
7248 * Now set the termination based on what we found. BRDDAT6
7249 * controls wide termination enable.
7250 * Flash Enable = BRDDAT7
7251 * SE High Term Enable = BRDDAT6
7252 * SE Low Term Enable = BRDDAT5 (7890)
7253 * LVD High Term Enable = BRDDAT4 (7890)
7255 if ( !(p
->features
& AHC_ULTRA2
) &&
7256 (internal50_present
&& internal68_present
&& external_present
) )
7258 printk(KERN_INFO
"(scsi%d) Illegal cable configuration!! Only two\n",
7260 printk(KERN_INFO
"(scsi%d) connectors on the SCSI controller may be "
7261 "in use at a time!\n", p
->host_no
);
7263 * Force termination (low and high byte) on. This is safer than
7264 * leaving it completely off, especially since this message comes
7265 * most often from motherboard controllers that don't even have 3
7266 * connectors, but instead are failing the cable detection.
7268 internal50_present
= external_present
= 0;
7269 enableSE_high
= enableSE_low
= 1;
7272 if ((max_target
> 8) &&
7273 ((external_present
== 0) || (internal68_present
== 0) ||
7274 (enableSE_high
!= 0)))
7277 p
->flags
|= AHC_TERM_ENB_SE_HIGH
;
7278 if (aic7xxx_verbose
& VERBOSE_PROBE2
)
7279 printk(KERN_INFO
"(scsi%d) SE High byte termination Enabled\n",
7283 if ( (((internal50_present
? 1 : 0) +
7284 (internal68_present
? 1 : 0) +
7285 (external_present
? 1 : 0)) <= 1) ||
7286 (enableSE_low
!= 0) )
7288 if (p
->features
& AHC_ULTRA2
)
7292 p
->flags
|= AHC_TERM_ENB_SE_LOW
;
7293 if (aic7xxx_verbose
& VERBOSE_PROBE2
)
7294 printk(KERN_INFO
"(scsi%d) SE Low byte termination Enabled\n",
7298 if (enableLVD_low
!= 0)
7301 p
->flags
|= AHC_TERM_ENB_LVD
;
7302 if (aic7xxx_verbose
& VERBOSE_PROBE2
)
7303 printk(KERN_INFO
"(scsi%d) LVD Low byte termination Enabled\n",
7307 if (enableLVD_high
!= 0)
7310 if (aic7xxx_verbose
& VERBOSE_PROBE2
)
7311 printk(KERN_INFO
"(scsi%d) LVD High byte termination Enabled\n",
7317 if (p
->adapter_control
& CFSTERM
)
7319 if (p
->features
& AHC_ULTRA2
)
7323 if (aic7xxx_verbose
& VERBOSE_PROBE2
)
7324 printk(KERN_INFO
"(scsi%d) SE Low byte termination Enabled\n",
7328 if (p
->adapter_control
& CFWSTERM
)
7331 if (aic7xxx_verbose
& VERBOSE_PROBE2
)
7332 printk(KERN_INFO
"(scsi%d) SE High byte termination Enabled\n",
7336 write_brdctl(p
, brddat
);
7338 aic_outb(p
, sxfrctl1
, SXFRCTL1
);
7342 /*+F*************************************************************************
7347 * Detects the maximum number of SCBs for the controller and returns
7348 * the count and a mask in p (p->maxscbs, p->qcntmask).
7349 *-F*************************************************************************/
7351 detect_maxscb(struct aic7xxx_host
*p
)
7356 * It's possible that we've already done this for multichannel
7359 if (p
->scb_data
->maxhscbs
== 0)
7362 * We haven't initialized the SCB settings yet. Walk the SCBs to
7363 * determince how many there are.
7365 aic_outb(p
, 0, FREE_SCBH
);
7367 for (i
= 0; i
< AIC7XXX_MAXSCB
; i
++)
7369 aic_outb(p
, i
, SCBPTR
);
7370 aic_outb(p
, i
, SCB_CONTROL
);
7371 if (aic_inb(p
, SCB_CONTROL
) != i
)
7373 aic_outb(p
, 0, SCBPTR
);
7374 if (aic_inb(p
, SCB_CONTROL
) != 0)
7377 aic_outb(p
, i
, SCBPTR
);
7378 aic_outb(p
, 0, SCB_CONTROL
); /* Clear the control byte. */
7379 aic_outb(p
, i
+ 1, SCB_NEXT
); /* Set the next pointer. */
7380 aic_outb(p
, i
- 1, SCB_PREV
); /* Set the prev pointer. */
7381 aic_outb(p
, SCB_LIST_NULL
, SCB_TAG
); /* Make the tag invalid. */
7382 aic_outb(p
, SCB_LIST_NULL
, SCB_BUSYTARGETS
); /* no busy untagged */
7383 aic_outb(p
, SCB_LIST_NULL
, SCB_BUSYTARGETS
+1);/* targets active yet */
7384 aic_outb(p
, SCB_LIST_NULL
, SCB_BUSYTARGETS
+2);
7385 aic_outb(p
, SCB_LIST_NULL
, SCB_BUSYTARGETS
+3);
7388 /* Make sure the last SCB terminates the free list. */
7389 aic_outb(p
, i
- 1, SCBPTR
);
7390 aic_outb(p
, SCB_LIST_NULL
, SCB_NEXT
);
7392 /* Ensure we clear the first (0) SCBs control byte. */
7393 aic_outb(p
, 0, SCBPTR
);
7394 aic_outb(p
, 0, SCB_CONTROL
);
7396 p
->scb_data
->maxhscbs
= i
;
7398 * Use direct indexing instead for speed
7400 if ( i
== AIC7XXX_MAXSCB
)
7401 p
->flags
&= ~AHC_PAGESCBS
;
7406 /*+F*************************************************************************
7411 * Register a Adaptec aic7xxx chip SCSI controller with the kernel.
7412 *-F*************************************************************************/
7414 aic7xxx_register(Scsi_Host_Template
*template, struct aic7xxx_host
*p
,
7420 unsigned char term
, scsi_conf
;
7421 struct Scsi_Host
*host
;
7424 * Lock out other contenders for our i/o space.
7426 request_region(p
->base
, MAXREG
- MINREG
, "aic7xxx");
7431 p
->scb_data
->maxscbs
= AIC7XXX_MAXSCB
;
7432 host
->can_queue
= AIC7XXX_MAXSCB
;
7433 host
->cmd_per_lun
= 3;
7434 host
->sg_tablesize
= AIC7XXX_MAX_SG
;
7435 host
->select_queue_depths
= aic7xxx_select_queue_depth
;
7436 host
->this_id
= p
->scsi_id
;
7437 host
->io_port
= p
->base
;
7438 host
->n_io_port
= 0xFF;
7439 host
->base
= (unsigned char *) p
->mbase
;
7441 if (p
->features
& AHC_WIDE
)
7445 if (p
->features
& AHC_TWIN
)
7447 host
->max_channel
= 1;
7451 p
->last_reset
= jiffies
;
7452 p
->host_no
= host
->host_no
;
7453 host
->unique_id
= p
->instance
;
7456 p
->completeq
.head
= NULL
;
7457 p
->completeq
.tail
= NULL
;
7458 scbq_init(&p
->scb_data
->free_scbs
);
7459 scbq_init(&p
->waiting_scbs
);
7461 for (i
= 0; i
< NUMBER(p
->untagged_scbs
); i
++)
7463 p
->untagged_scbs
[i
] = SCB_LIST_NULL
;
7464 p
->qinfifo
[i
] = SCB_LIST_NULL
;
7465 p
->qoutfifo
[i
] = SCB_LIST_NULL
;
7468 * We currently have no commands of any type
7471 p
->qoutfifonext
= 0;
7473 for (i
= 0; i
< MAX_TARGETS
; i
++)
7475 p
->dev_commands_sent
[i
] = 0;
7476 p
->dev_flags
[i
] = 0;
7477 p
->dev_active_cmds
[i
] = 0;
7478 p
->dev_last_reset
[i
] = jiffies
;
7479 p
->dev_last_queue_full
[i
] = 0;
7480 p
->dev_last_queue_full_count
[i
] = 0;
7481 p
->dev_max_queue_depth
[i
] = 1;
7482 p
->dev_temp_queue_depth
[i
] = 1;
7483 p
->dev_mid_level_queue_depth
[i
] = 3;
7484 scbq_init(&p
->delayed_scbs
[i
]);
7485 init_timer(&p
->dev_timer
[i
]);
7486 p
->dev_timer
[i
].data
= (unsigned long)p
;
7487 p
->dev_timer
[i
].function
= (void *)aic7xxx_timer
;
7490 printk(KERN_INFO
"(scsi%d) <%s> found at ", p
->host_no
,
7491 board_names
[p
->board_name_index
]);
7494 case (AHC_AIC7770
|AHC_EISA
):
7495 printk("EISA slot %d\n", p
->pci_device_fn
);
7497 case (AHC_AIC7770
|AHC_VL
):
7498 printk("VLB slot %d\n", p
->pci_device_fn
);
7501 printk("PCI %d/%d\n", PCI_SLOT(p
->pci_device_fn
),
7502 PCI_FUNC(p
->pci_device_fn
));
7505 if (p
->features
& AHC_TWIN
)
7507 printk(KERN_INFO
"(scsi%d) Twin Channel, A SCSI ID %d, B SCSI ID %d, ",
7508 p
->host_no
, p
->scsi_id
, p
->scsi_id_b
);
7516 if ((p
->flags
& AHC_MULTI_CHANNEL
) != 0)
7520 if ( (p
->flags
& (AHC_CHNLB
|AHC_CHNLC
)) != 0 )
7522 channel
= (p
->flags
& AHC_CHNLB
) ? " B" : " C";
7525 if (p
->features
& AHC_WIDE
)
7527 printk(KERN_INFO
"(scsi%d) Wide ", p
->host_no
);
7531 printk(KERN_INFO
"(scsi%d) Narrow ", p
->host_no
);
7533 printk("Channel%s, SCSI ID=%d, ", channel
, p
->scsi_id
);
7535 aic_outb(p
, 0, SEQ_FLAGS
);
7538 * Detect SCB parameters and initialize the SCB array.
7541 printk("%d/%d SCBs\n", p
->scb_data
->maxhscbs
, p
->scb_data
->maxscbs
);
7542 if (aic7xxx_verbose
& VERBOSE_PROBE2
)
7544 printk(KERN_INFO
"(scsi%d) BIOS %sabled, IO Port 0x%lx, IRQ %d\n",
7545 p
->host_no
, (p
->flags
& AHC_BIOS_ENABLED
) ? "en" : "dis",
7547 printk(KERN_INFO
"(scsi%d) IO Memory at 0x%lx, MMAP Memory at 0x%lx\n",
7548 p
->host_no
, p
->mbase
, (unsigned long)p
->maddr
);
7552 * Now that we know our instance number, we can set the flags we need to
7553 * force termination if need be.
7555 if (aic7xxx_stpwlev
!= -1)
7558 * This option only applies to PCI controllers.
7560 if ( (p
->chip
& ~AHC_CHIPID_MASK
) == AHC_PCI
)
7562 unsigned char devconfig
;
7564 #if LINUX_KERNEL_VERSION > KERNEL_VERSION(2,1,92)
7565 pci_read_config_byte(p
->pdev
, DEVCONFIG
, &devconfig
);
7567 pcibios_read_config_byte(p
->pci_bus
, p
->pci_device_fn
,
7568 DEVCONFIG
, &devconfig
);
7570 if ( (aic7xxx_stpwlev
>> p
->instance
) & 0x01 )
7573 if (aic7xxx_verbose
& VERBOSE_PROBE2
)
7574 printk("(scsi%d) Force setting STPWLEV bit\n", p
->host_no
);
7579 if (aic7xxx_verbose
& VERBOSE_PROBE2
)
7580 printk("(scsi%d) Force clearing STPWLEV bit\n", p
->host_no
);
7582 #if LINUX_KERNEL_VERSION > KERNEL_VERSION(2,1,92)
7583 pci_write_config_byte(p
->pdev
, DEVCONFIG
, devconfig
);
7585 pcibios_write_config_byte(p
->pci_bus
, p
->pci_device_fn
,
7586 DEVCONFIG
, devconfig
);
7592 * That took care of devconfig and stpwlev, now for the actual termination
7595 if (aic7xxx_override_term
!= -1)
7598 * Again, this only applies to PCI controllers. We don't have problems
7599 * with the termination on 274x controllers to the best of my knowledge.
7601 if ( (p
->chip
& ~AHC_CHIPID_MASK
) == AHC_PCI
)
7603 unsigned char term_override
;
7605 term_override
= ( (aic7xxx_override_term
>> (p
->instance
* 4)) & 0x0f);
7606 p
->adapter_control
&=
7607 ~(CFSTERM
|CFWSTERM
|CFLVDSTERM
|CFAUTOTERM
|CFSEAUTOTERM
);
7608 if ( (p
->features
& AHC_ULTRA2
) && (term_override
& 0x0c) )
7610 p
->adapter_control
|= CFLVDSTERM
;
7612 if (term_override
& 0x02)
7614 p
->adapter_control
|= CFWSTERM
;
7616 if (term_override
& 0x01)
7618 p
->adapter_control
|= CFSTERM
;
7623 if ( (p
->flags
& AHC_SEEPROM_FOUND
) || (aic7xxx_override_term
!= -1) )
7625 if (p
->features
& AHC_SPIOCAP
)
7627 if ( aic_inb(p
, SPIOCAP
) & SSPIOCPS
)
7629 * Update the settings in sxfrctl1 to match the termination
7632 configure_termination(p
);
7634 else if ((p
->chip
& AHC_CHIPID_MASK
) >= AHC_AIC7870
)
7636 configure_termination(p
);
7641 * Load the sequencer program, then re-enable the board -
7642 * resetting the AIC-7770 disables it, leaving the lights
7643 * on with nobody home.
7647 if ( (p
->chip
& AHC_CHIPID_MASK
) == AHC_AIC7770
)
7649 aic_outb(p
, ENABLE
, BCTL
); /* Enable the boards BUS drivers. */
7651 aic_outb(p
, aic_inb(p
, SBLKCTL
) & ~AUTOFLUSHDIS
, SBLKCTL
);
7654 * Clear out any possible pending interrupts.
7656 aic7xxx_clear_intstat(p
);
7659 * Set the SCSI Id, SXFRCTL0, SXFRCTL1, and SIMODE1, for both channels
7661 if (p
->features
& AHC_TWIN
)
7663 /* Select channel B */
7664 aic_outb(p
, aic_inb(p
, SBLKCTL
) | SELBUSB
, SBLKCTL
);
7666 term
= ((p
->flags
& AHC_TERM_ENB_B
) != 0) ? STPWEN
: 0;
7667 aic_outb(p
, p
->scsi_id_b
, SCSIID
);
7668 scsi_conf
= aic_inb(p
, SCSICONF
+ 1);
7669 aic_outb(p
, DFON
| SPIOEN
, SXFRCTL0
);
7670 aic_outb(p
, (scsi_conf
& ENSPCHK
) | term
|
7671 ENSTIMER
| ACTNEGEN
, SXFRCTL1
);
7672 aic_outb(p
, 0, SIMODE0
);
7673 aic_outb(p
, ENSELTIMO
| ENSCSIRST
| ENSCSIPERR
, SIMODE1
);
7674 aic_outb(p
, 0, SCSIRATE
);
7676 /* Select channel A */
7677 aic_outb(p
, aic_inb(p
, SBLKCTL
) & ~SELBUSB
, SBLKCTL
);
7680 term
= ((p
->flags
& AHC_TERM_ENB_SE_LOW
) != 0) ? STPWEN
: 0;
7681 if (p
->features
& AHC_ULTRA2
)
7682 aic_outb(p
, p
->scsi_id
, SCSIID_ULTRA2
);
7684 aic_outb(p
, p
->scsi_id
, SCSIID
);
7685 scsi_conf
= aic_inb(p
, SCSICONF
);
7686 aic_outb(p
, DFON
| SPIOEN
, SXFRCTL0
);
7687 aic_outb(p
, (scsi_conf
& ENSPCHK
) | term
|
7688 ENSTIMER
| ACTNEGEN
, SXFRCTL1
);
7689 aic_outb(p
, 0, SIMODE0
);
7690 aic_outb(p
, ENSELTIMO
| ENSCSIRST
| ENSCSIPERR
, SIMODE1
);
7691 aic_outb(p
, 0, SCSIRATE
);
7692 if ( p
->features
& AHC_ULTRA2
)
7693 aic_outb(p
, 0, SCSIOFFSET
);
7696 * Look at the information that board initialization or the board
7697 * BIOS has left us. In the lower four bits of each target's
7698 * scratch space any value other than 0 indicates that we should
7699 * initiate synchronous transfers. If it's zero, the user or the
7700 * BIOS has decided to disable synchronous negotiation to that
7701 * target so we don't activate the needsdtr flag.
7703 if ((p
->features
& (AHC_TWIN
|AHC_WIDE
)) == 0)
7712 if (!(aic7xxx_no_reset
))
7715 * If we reset the bus, then clear the transfer settings, else leave
7718 for (i
= 0; i
< max_targets
; i
++)
7720 aic_outb(p
, 0, TARG_SCSIRATE
+ i
);
7721 if (p
->features
& AHC_ULTRA2
)
7723 aic_outb(p
, 0, TARG_OFFSET
+ i
);
7725 p
->transinfo
[i
].cur_offset
= 0;
7726 p
->transinfo
[i
].cur_period
= 0;
7727 p
->transinfo
[i
].cur_width
= MSG_EXT_WDTR_BUS_8_BIT
;
7731 * If we reset the bus, then clear the transfer settings, else leave
7734 aic_outb(p
, 0, ULTRA_ENB
);
7735 aic_outb(p
, 0, ULTRA_ENB
+ 1);
7740 * Allocate enough hardware scbs to handle the maximum number of
7741 * concurrent transactions we can have. We have to make sure that
7742 * the allocated memory is contiguous memory. The Linux kmalloc
7743 * routine should only allocate contiguous memory, but note that
7744 * this could be a problem if kmalloc() is changed.
7748 unsigned int hscb_physaddr
;
7751 array_size
= p
->scb_data
->maxscbs
* sizeof(struct aic7xxx_hwscb
);
7752 if (p
->scb_data
->hscbs
== NULL
)
7755 * A little padding so we can align thing the way we want
7757 p
->scb_data
->hscbs
= kmalloc(array_size
+ 0x1f, GFP_ATOMIC
);
7759 if (p
->scb_data
->hscbs
== NULL
)
7761 printk("(scsi%d) Unable to allocate hardware SCB array; "
7762 "failing detection.\n", p
->host_no
);
7767 * Save the actual kmalloc buffer pointer off, then align our
7768 * buffer to a 32 byte boundary
7770 p
->scb_data
->hscb_kmalloc_ptr
= p
->scb_data
->hscbs
;
7771 temp
= (unsigned long)p
->scb_data
->hscbs
;
7774 p
->scb_data
->hscbs
= (struct aic7xxx_hwscb
*)temp
;
7775 /* At least the control byte of each SCB needs to be 0. */
7776 memset(p
->scb_data
->hscbs
, 0, array_size
);
7778 /* Tell the sequencer where it can find the hardware SCB array. */
7779 hscb_physaddr
= VIRT_TO_BUS(p
->scb_data
->hscbs
);
7780 aic_outb(p
, hscb_physaddr
& 0xFF, HSCB_ADDR
);
7781 aic_outb(p
, (hscb_physaddr
>> 8) & 0xFF, HSCB_ADDR
+ 1);
7782 aic_outb(p
, (hscb_physaddr
>> 16) & 0xFF, HSCB_ADDR
+ 2);
7783 aic_outb(p
, (hscb_physaddr
>> 24) & 0xFF, HSCB_ADDR
+ 3);
7785 /* Set up the fifo areas at the same time */
7786 hscb_physaddr
= VIRT_TO_BUS(&p
->untagged_scbs
[0]);
7787 aic_outb(p
, hscb_physaddr
& 0xFF, SCBID_ADDR
);
7788 aic_outb(p
, (hscb_physaddr
>> 8) & 0xFF, SCBID_ADDR
+ 1);
7789 aic_outb(p
, (hscb_physaddr
>> 16) & 0xFF, SCBID_ADDR
+ 2);
7790 aic_outb(p
, (hscb_physaddr
>> 24) & 0xFF, SCBID_ADDR
+ 3);
7793 /* The Q-FIFOs we just set up are all empty */
7794 aic_outb(p
, 0, QINPOS
);
7795 aic_outb(p
, 0, KERNEL_QINPOS
);
7796 aic_outb(p
, 0, QOUTPOS
);
7798 if(p
->features
& AHC_QUEUE_REGS
)
7800 aic_outb(p
, SCB_QSIZE_256
, QOFF_CTLSTA
);
7801 aic_outb(p
, 0, SDSCB_QOFF
);
7802 aic_outb(p
, 0, SNSCB_QOFF
);
7803 aic_outb(p
, 0, HNSCB_QOFF
);
7807 * We don't have any waiting selections or disconnected SCBs.
7809 aic_outb(p
, SCB_LIST_NULL
, WAITING_SCBH
);
7810 aic_outb(p
, SCB_LIST_NULL
, DISCONNECTED_SCBH
);
7813 * Message out buffer starts empty
7815 aic_outb(p
, MSG_NOOP
, MSG_OUT
);
7816 aic_outb(p
, MSG_NOOP
, LAST_MSG
);
7819 * Set all the other asundry items that haven't been set yet.
7820 * This includes just dumping init values to a lot of registers simply
7821 * to make sure they've been touched and are ready for use parity wise
7824 aic_outb(p
, 0, TMODE_CMDADDR
);
7825 aic_outb(p
, 0, TMODE_CMDADDR
+ 1);
7826 aic_outb(p
, 0, TMODE_CMDADDR
+ 2);
7827 aic_outb(p
, 0, TMODE_CMDADDR
+ 3);
7828 aic_outb(p
, 0, TMODE_CMDADDR_NEXT
);
7831 * Link us into the list of valid hosts
7833 p
->next
= first_aic7xxx
;
7837 * Clear out any possible pending interrupts, again.
7839 aic7xxx_clear_intstat(p
);
7842 * Allocate the first set of scbs for this controller. This is to stream-
7843 * line code elsewhere in the driver. If we have to check for the existence
7844 * of scbs in certain code sections, it slows things down. However, as
7845 * soon as we register the IRQ for this card, we could get an interrupt that
7846 * includes possibly the SCSI_RSTI interrupt. If we catch that interrupt
7847 * then we are likely to segfault if we don't have at least one chunk of
7848 * SCBs allocated or add checks all through the reset code to make sure
7849 * that the SCBs have been allocated which is an invalid running condition
7850 * and therefore I think it's preferable to simply pre-allocate the first
7853 aic7xxx_allocate_scb(p
);
7855 if ( !(aic7xxx_no_reset
) )
7857 if (p
->features
& AHC_TWIN
)
7859 if (aic7xxx_verbose
& VERBOSE_PROBE2
)
7860 printk(KERN_INFO
"(scsi%d) Resetting channel B\n", p
->host_no
);
7861 aic_outb(p
, aic_inb(p
, SBLKCTL
) | SELBUSB
, SBLKCTL
);
7862 aic7xxx_reset_current_bus(p
);
7863 aic_outb(p
, aic_inb(p
, SBLKCTL
) & ~SELBUSB
, SBLKCTL
);
7865 /* Reset SCSI bus A. */
7866 if (aic7xxx_verbose
& VERBOSE_PROBE2
)
7867 { /* In case we are a 3940, 3985, or 7895, print the right channel */
7869 if (p
->flags
& AHC_MULTI_CHANNEL
)
7872 if (p
->flags
& (AHC_CHNLB
|AHC_CHNLC
))
7873 channel
= (p
->flags
& AHC_CHNLB
) ? " B" : " C";
7875 printk(KERN_INFO
"(scsi%d) Resetting channel%s\n", p
->host_no
, channel
);
7879 * Some of the new Ultra2 chipsets need a longer delay after a chip
7880 * reset than just the init setup creates, so we have to delay here
7881 * before we go into a reset in order to make the chips happy.
7883 if (p
->features
& AHC_ULTRA2
)
7885 aic7xxx_reset_current_bus(p
);
7888 * Delay for the reset delay.
7891 aic7xxx_delay(AIC7XXX_RESET_DELAY
);
7897 printk(KERN_INFO
"(scsi%d) Not resetting SCSI bus. Note: Don't use "
7898 "the no_reset\n", p
->host_no
);
7899 printk(KERN_INFO
"(scsi%d) option unless you have a verifiable need "
7900 "for it.\n", p
->host_no
);
7901 printk(KERN_INFO
"(scsi%d) The no_reset option is known to break some "
7902 "systems,\n", p
->host_no
);
7903 printk(KERN_INFO
"(scsi%d) and is not supported by the driver author\n",
7905 aic7xxx_delay(AIC7XXX_RESET_DELAY
);
7910 * Register IRQ with the kernel. Only allow sharing IRQs with
7913 if (!(p
->chip
& AHC_PCI
))
7915 result
= (request_irq(p
->irq
, do_aic7xxx_isr
, 0, "aic7xxx", p
));
7919 result
= (request_irq(p
->irq
, do_aic7xxx_isr
, SA_SHIRQ
,
7923 result
= (request_irq(p
->irq
, do_aic7xxx_isr
, SA_INTERRUPT
| SA_SHIRQ
,
7929 printk(KERN_WARNING
"(scsi%d) Couldn't register IRQ %d, ignoring "
7930 "controller.\n", p
->host_no
, p
->irq
);
7935 unpause_sequencer(p
, /* unpause_always */ TRUE
);
7940 /*+F*************************************************************************
7942 * aic7xxx_chip_reset
7945 * Perform a chip reset on the aic7xxx SCSI controller. The controller
7946 * is paused upon return.
7947 *-F*************************************************************************/
7949 aic7xxx_chip_reset(struct aic7xxx_host
*p
)
7951 unsigned char sblkctl
;
7955 * For some 274x boards, we must clear the CHIPRST bit and pause
7956 * the sequencer. For some reason, this makes the driver work.
7958 aic_outb(p
, PAUSE
| CHIPRST
, HCNTRL
);
7961 * In the future, we may call this function as a last resort for
7962 * error handling. Let's be nice and not do any unecessary delays.
7964 wait
= 1000; /* 1 second (1000 * 1 msec) */
7965 while (--wait
&& !(aic_inb(p
, HCNTRL
) & CHIPRSTACK
))
7967 mdelay(1); /* 1 msec */
7972 sblkctl
= aic_inb(p
, SBLKCTL
) & (SELBUSB
|SELWIDE
);
7973 if (p
->chip
& AHC_PCI
)
7974 sblkctl
&= ~SELBUSB
;
7977 case 0: /* normal narrow card */
7979 case 2: /* Wide card */
7980 p
->features
|= AHC_WIDE
;
7982 case 8: /* Twin card */
7983 p
->features
|= AHC_TWIN
;
7984 p
->flags
|= AHC_MULTI_CHANNEL
;
7986 default: /* hmmm...we don't know what this is */
7987 printk(KERN_WARNING
"aic7xxx: Unsupported adapter type %d, ignoring.\n",
7988 aic_inb(p
, SBLKCTL
) & 0x0a);
7994 /*+F*************************************************************************
7999 * Allocate and initialize a host structure. Returns NULL upon error
8000 * and a pointer to a aic7xxx_host struct upon success.
8001 *-F*************************************************************************/
8002 static struct aic7xxx_host
*
8003 aic7xxx_alloc(Scsi_Host_Template
*sht
, struct aic7xxx_host
*temp
)
8005 struct aic7xxx_host
*p
= NULL
;
8006 struct Scsi_Host
*host
;
8010 * Allocate a storage area by registering us with the mid-level
8013 host
= scsi_register(sht
, sizeof(struct aic7xxx_host
));
8017 p
= (struct aic7xxx_host
*) host
->hostdata
;
8018 memset(p
, 0, sizeof(struct aic7xxx_host
));
8022 p
->scb_data
= kmalloc(sizeof(scb_data_type
), GFP_ATOMIC
);
8023 if (p
->scb_data
!= NULL
)
8025 memset(p
->scb_data
, 0, sizeof(scb_data_type
));
8026 scbq_init (&p
->scb_data
->free_scbs
);
8031 * For some reason we don't have enough memory. Free the
8032 * allocated memory for the aic7xxx_host struct, and return NULL.
8034 release_region(p
->base
, MAXREG
- MINREG
);
8035 scsi_unregister(host
);
8038 p
->host_no
= host
->host_no
;
8041 for (i
=0; i
<MAX_TARGETS
; i
++)
8043 p
->transinfo
[i
].goal_period
= 0;
8044 p
->transinfo
[i
].goal_offset
= 0;
8045 p
->transinfo
[i
].goal_width
= MSG_EXT_WDTR_BUS_8_BIT
;
8052 /*+F*************************************************************************
8057 * Frees and releases all resources associated with an instance of
8058 * the driver (struct aic7xxx_host *).
8059 *-F*************************************************************************/
8061 aic7xxx_free(struct aic7xxx_host
*p
)
8066 * Free the allocated hardware SCB space.
8068 if (p
->scb_data
!= NULL
)
8070 if (p
->scb_data
->hscbs
!= NULL
)
8072 kfree(p
->scb_data
->hscb_kmalloc_ptr
);
8073 p
->scb_data
->hscbs
= p
->scb_data
->hscb_kmalloc_ptr
= NULL
;
8076 * Free the driver SCBs. These were allocated on an as-need
8077 * basis. We allocated these in groups depending on how many
8078 * we could fit into a given amount of RAM. The tail SCB for
8079 * these allocations has a pointer to the alloced area.
8081 for (i
= 0; i
< p
->scb_data
->numscbs
; i
++)
8083 if (p
->scb_data
->scb_array
[i
]->kmalloc_ptr
!= NULL
)
8084 kfree(p
->scb_data
->scb_array
[i
]->kmalloc_ptr
);
8085 p
->scb_data
->scb_array
[i
] = NULL
;
8089 * Free the SCB data area.
8095 * Free any alloced Scsi_Cmnd structures that might be around for
8096 * negotiation purposes....
8098 for (i
= 0; i
< MAX_TARGETS
; i
++)
8100 if(p
->dev_wdtr_cmnd
[i
])
8101 kfree(p
->dev_wdtr_cmnd
[i
]);
8102 if(p
->dev_sdtr_cmnd
[i
])
8103 kfree(p
->dev_sdtr_cmnd
[i
]);
8108 /*+F*************************************************************************
8110 * aic7xxx_load_seeprom
8113 * Load the seeprom and configure adapter and target settings.
8114 * Returns 1 if the load was successful and 0 otherwise.
8115 *-F*************************************************************************/
8117 aic7xxx_load_seeprom(struct aic7xxx_host
*p
, unsigned char *sxfrctl1
)
8119 int have_seeprom
= 0;
8120 int i
, max_targets
, mask
;
8121 unsigned char scsirate
, scsi_conf
;
8122 unsigned short scarray
[128];
8123 struct seeprom_config
*sc
= (struct seeprom_config
*) scarray
;
8125 if (aic7xxx_verbose
& VERBOSE_PROBE2
)
8127 printk(KERN_INFO
"aic7xxx: Loading serial EEPROM...");
8131 case (AHC_AIC7770
|AHC_EISA
): /* None of these adapters have seeproms. */
8132 if (aic_inb(p
, SCSICONF
) & TERM_ENB
)
8133 p
->flags
|= AHC_TERM_ENB_A
;
8134 if ( (p
->features
& AHC_TWIN
) && (aic_inb(p
, SCSICONF
+ 1) & TERM_ENB
) )
8135 p
->flags
|= AHC_TERM_ENB_B
;
8138 case (AHC_AIC7770
|AHC_VL
):
8139 have_seeprom
= read_284x_seeprom(p
, (struct seeprom_config
*) scarray
);
8143 have_seeprom
= read_seeprom(p
, (p
->flags
& (AHC_CHNLB
|AHC_CHNLC
)),
8144 scarray
, p
->sc_size
, p
->sc_type
);
8147 if(p
->sc_type
== C46
)
8148 have_seeprom
= read_seeprom(p
, (p
->flags
& (AHC_CHNLB
|AHC_CHNLC
)),
8149 scarray
, p
->sc_size
, C56_66
);
8151 have_seeprom
= read_seeprom(p
, (p
->flags
& (AHC_CHNLB
|AHC_CHNLC
)),
8152 scarray
, p
->sc_size
, C46
);
8159 if (aic7xxx_verbose
& VERBOSE_PROBE2
)
8161 printk("\naic7xxx: No SEEPROM available.\n");
8163 p
->flags
|= AHC_NEWEEPROM_FMT
;
8164 if (aic_inb(p
, SCSISEQ
) == 0)
8166 p
->flags
|= AHC_USEDEFAULTS
;
8167 p
->flags
&= ~AHC_BIOS_ENABLED
;
8168 p
->scsi_id
= p
->scsi_id_b
= 7;
8169 *sxfrctl1
|= STPWEN
;
8170 if (aic7xxx_verbose
& VERBOSE_PROBE2
)
8172 printk("aic7xxx: Using default values.\n");
8175 else if (aic7xxx_verbose
& VERBOSE_PROBE2
)
8177 printk("aic7xxx: Using leftover BIOS values.\n");
8179 if ( *sxfrctl1
& STPWEN
)
8181 p
->flags
|= AHC_TERM_ENB_SE_LOW
| AHC_TERM_ENB_SE_HIGH
;
8182 sc
->adapter_control
&= ~CFAUTOTERM
;
8183 sc
->adapter_control
|= CFSTERM
| CFWSTERM
| CFLVDSTERM
;
8185 p
->flags
|= AHC_EXTEND_TRANS_A
| AHC_EXTEND_TRANS_B
;
8189 if (aic7xxx_verbose
& VERBOSE_PROBE2
)
8195 * Note things in our flags
8197 p
->flags
|= AHC_SEEPROM_FOUND
;
8200 * Update the settings in sxfrctl1 to match the termination settings.
8205 * Get our SCSI ID from the SEEPROM setting...
8207 p
->scsi_id
= (sc
->brtime_id
& CFSCSIID
);
8210 * First process the settings that are different between the VLB
8211 * and PCI adapter seeproms.
8213 if ((p
->chip
& AHC_CHIPID_MASK
) == AHC_AIC7770
)
8215 /* VLB adapter seeproms */
8216 if (sc
->bios_control
& CF284XEXTEND
)
8217 p
->flags
|= AHC_EXTEND_TRANS_A
;
8219 if (sc
->adapter_control
& CF284XSTERM
)
8221 *sxfrctl1
|= STPWEN
;
8222 p
->flags
|= AHC_TERM_ENB_SE_LOW
| AHC_TERM_ENB_SE_HIGH
;
8227 /* PCI adapter seeproms */
8228 if (sc
->bios_control
& CFEXTEND
)
8229 p
->flags
|= AHC_EXTEND_TRANS_A
;
8230 if (sc
->bios_control
& CFBIOSEN
)
8231 p
->flags
|= AHC_BIOS_ENABLED
;
8233 p
->flags
&= ~AHC_BIOS_ENABLED
;
8235 if (sc
->adapter_control
& CFSTERM
)
8237 *sxfrctl1
|= STPWEN
;
8238 p
->flags
|= AHC_TERM_ENB_SE_LOW
| AHC_TERM_ENB_SE_HIGH
;
8247 * Limit to 16 targets just in case. The 2842 for one is known to
8248 * blow the max_targets setting, future cards might also.
8250 max_targets
= MIN(sc
->max_targets
& CFMAXTARG
,
8251 ((p
->features
& (AHC_TWIN
| AHC_WIDE
)) ? 16 : 8));
8255 for (i
= 0; i
< max_targets
; i
++)
8257 if( (p
->features
& AHC_ULTRA
) &&
8258 !(sc
->adapter_control
& CFULTRAEN
) &&
8259 (sc
->device_flags
[i
] & CFSYNCHISULTRA
) )
8261 p
->flags
|= AHC_NEWEEPROM_FMT
;
8267 for (i
= 0; i
< max_targets
; i
++)
8272 if(aic_inb(p
, SCSISEQ
) != 0)
8275 * OK...the BIOS set things up and left behind the settings we need.
8276 * Just make our sc->device_flags[i] entry match what the card has
8277 * set for this device.
8280 ~(aic_inb(p
, DISC_DSB
) | (aic_inb(p
, DISC_DSB
+ 1) << 8) );
8282 (aic_inb(p
, ULTRA_ENB
) | (aic_inb(p
, ULTRA_ENB
+ 1) << 8) );
8283 sc
->device_flags
[i
] = (p
->discenable
& mask
) ? CFDISC
: 0;
8284 if (aic_inb(p
, TARG_SCSIRATE
+ i
) & WIDEXFER
)
8285 sc
->device_flags
[i
] |= CFWIDEB
;
8286 if (p
->features
& AHC_ULTRA2
)
8288 if (aic_inb(p
, TARG_OFFSET
+ i
))
8290 sc
->device_flags
[i
] |= CFSYNCH
;
8291 sc
->device_flags
[i
] |= (aic_inb(p
, TARG_SCSIRATE
+ i
) & 0x07);
8292 if ( (aic_inb(p
, TARG_SCSIRATE
+ i
) & 0x18) == 0x18 )
8293 sc
->device_flags
[i
] |= CFSYNCHISULTRA
;
8298 if (aic_inb(p
, TARG_SCSIRATE
+ i
) & ~WIDEXFER
)
8300 sc
->device_flags
[i
] |= CFSYNCH
;
8301 if (p
->features
& AHC_ULTRA
)
8302 sc
->device_flags
[i
] |= ((p
->ultraenb
& mask
) ?
8303 CFSYNCHISULTRA
: 0);
8310 * Assume the BIOS has NOT been run on this card and nothing between
8311 * the card and the devices is configured yet.
8313 sc
->device_flags
[i
] = CFDISC
;
8314 if (p
->features
& AHC_WIDE
)
8315 sc
->device_flags
[i
] |= CFWIDEB
;
8316 if (p
->features
& AHC_ULTRA2
)
8317 sc
->device_flags
[i
] |= 3;
8318 else if (p
->features
& AHC_ULTRA
)
8319 sc
->device_flags
[i
] |= CFSYNCHISULTRA
;
8320 sc
->device_flags
[i
] |= CFSYNCH
;
8321 aic_outb(p
, 0, TARG_SCSIRATE
+ i
);
8322 if (p
->features
& AHC_ULTRA2
)
8323 aic_outb(p
, 0, TARG_OFFSET
+ i
);
8326 if (sc
->device_flags
[i
] & CFDISC
)
8328 p
->discenable
|= mask
;
8330 if (p
->flags
& AHC_NEWEEPROM_FMT
)
8332 if (sc
->device_flags
[i
] & CFSYNCHISULTRA
)
8334 p
->ultraenb
|= mask
;
8337 else if (sc
->adapter_control
& CFULTRAEN
)
8339 p
->ultraenb
|= mask
;
8341 if ( (sc
->device_flags
[i
] & CFSYNCH
) == 0)
8343 sc
->device_flags
[i
] &= ~CFXFER
;
8344 p
->ultraenb
&= ~mask
;
8345 p
->transinfo
[i
].user_offset
= 0;
8346 p
->transinfo
[i
].user_period
= 0;
8347 p
->transinfo
[i
].cur_offset
= 0;
8348 p
->transinfo
[i
].cur_period
= 0;
8349 p
->needsdtr_copy
&= ~mask
;
8353 if (p
->features
& AHC_ULTRA2
)
8355 p
->transinfo
[i
].user_offset
= MAX_OFFSET_ULTRA2
;
8356 p
->transinfo
[i
].cur_offset
= aic_inb(p
, TARG_OFFSET
+ i
);
8357 scsirate
= (sc
->device_flags
[i
] & CFXFER
) |
8358 ((p
->ultraenb
& mask
) ? 0x18 : 0x10);
8359 p
->transinfo
[i
].user_period
= aic7xxx_find_period(p
, scsirate
,
8360 AHC_SYNCRATE_ULTRA2
);
8361 p
->transinfo
[i
].cur_period
= aic7xxx_find_period(p
,
8362 aic_inb(p
, TARG_SCSIRATE
+ i
),
8363 AHC_SYNCRATE_ULTRA2
);
8367 scsirate
= (sc
->device_flags
[i
] & CFXFER
) << 4;
8368 if (sc
->device_flags
[i
] & CFWIDEB
)
8369 p
->transinfo
[i
].user_offset
= MAX_OFFSET_16BIT
;
8371 p
->transinfo
[i
].user_offset
= MAX_OFFSET_8BIT
;
8372 if (p
->features
& AHC_ULTRA
)
8375 ultraenb
= aic_inb(p
, ULTRA_ENB
) |
8376 (aic_inb(p
, ULTRA_ENB
+ 1) << 8);
8377 p
->transinfo
[i
].user_period
= aic7xxx_find_period(p
,
8379 (p
->ultraenb
& mask
) ?
8380 AHC_SYNCRATE_ULTRA
:
8382 p
->transinfo
[i
].cur_period
= aic7xxx_find_period(p
,
8383 aic_inb(p
, TARG_SCSIRATE
+ i
),
8385 AHC_SYNCRATE_ULTRA
:
8389 p
->transinfo
[i
].user_period
= aic7xxx_find_period(p
,
8390 scsirate
, AHC_SYNCRATE_FAST
);
8392 p
->needsdtr_copy
|= mask
;
8394 if ( (sc
->device_flags
[i
] & CFWIDEB
) && (p
->features
& AHC_WIDE
) )
8396 p
->transinfo
[i
].user_width
= MSG_EXT_WDTR_BUS_16_BIT
;
8397 p
->needwdtr_copy
|= mask
;
8401 p
->transinfo
[i
].user_width
= MSG_EXT_WDTR_BUS_8_BIT
;
8402 p
->needwdtr_copy
&= ~mask
;
8404 p
->transinfo
[i
].cur_width
=
8405 (aic_inb(p
, TARG_SCSIRATE
+ i
) & WIDEXFER
) ?
8406 MSG_EXT_WDTR_BUS_16_BIT
: MSG_EXT_WDTR_BUS_8_BIT
;
8408 aic_outb(p
, ~(p
->discenable
& 0xFF), DISC_DSB
);
8409 aic_outb(p
, ~((p
->discenable
>> 8) & 0xFF), DISC_DSB
+ 1);
8410 p
->needwdtr
= p
->needwdtr_copy
;
8411 p
->needsdtr
= p
->needsdtr_copy
;
8412 p
->wdtr_pending
= p
->sdtr_pending
= 0;
8415 * We set the p->ultraenb from the SEEPROM to begin with, but now we make
8416 * it match what is already down in the card. If we are doing a reset
8417 * on the card then this will get put back to a default state anyway.
8418 * This allows us to not have to pre-emptively negotiate when using the
8421 if (p
->features
& AHC_ULTRA
)
8422 p
->ultraenb
= aic_inb(p
, ULTRA_ENB
) | (aic_inb(p
, ULTRA_ENB
+ 1) << 8);
8425 scsi_conf
= (p
->scsi_id
& HSCSIID
);
8429 p
->adapter_control
= sc
->adapter_control
;
8430 p
->bios_control
= sc
->bios_control
;
8432 switch (p
->chip
& AHC_CHIPID_MASK
)
8436 if (p
->adapter_control
& CFBPRIMARY
)
8437 p
->flags
|= AHC_CHANNEL_B_PRIMARY
;
8442 if (sc
->adapter_control
& CFSPARITY
)
8443 scsi_conf
|= ENSPCHK
;
8447 scsi_conf
|= ENSPCHK
| RESET_SCSI
;
8451 * Only set the SCSICONF and SCSICONF + 1 registers if we are a PCI card.
8452 * The 2842 and 2742 cards already have these registers set and we don't
8453 * want to muck with them since we don't set all the bits they do.
8455 if ( (p
->chip
& ~AHC_CHIPID_MASK
) == AHC_PCI
)
8457 /* Set the host ID */
8458 aic_outb(p
, scsi_conf
, SCSICONF
);
8459 /* In case we are a wide card */
8460 aic_outb(p
, p
->scsi_id
, SCSICONF
+ 1);
8464 /*+F*************************************************************************
8469 * Try to detect and register an Adaptec 7770 or 7870 SCSI controller.
8471 * XXX - This should really be called aic7xxx_probe(). A sequence of
8472 * probe(), attach()/detach(), and init() makes more sense than
8473 * one do-it-all function. This may be useful when (and if) the
8474 * mid-level SCSI code is overhauled.
8475 *-F*************************************************************************/
8477 aic7xxx_detect(Scsi_Host_Template
*template)
8479 struct aic7xxx_host
*temp_p
= NULL
;
8480 struct aic7xxx_host
*current_p
= NULL
;
8481 struct aic7xxx_host
*list_p
= NULL
;
8483 ahc_flag_type flags
= 0;
8485 unsigned char sxfrctl1
;
8486 #if defined(__i386__) || defined(__alpha__)
8487 unsigned char hcntrl
, hostconf
;
8488 unsigned int slot
, base
;
8493 * If we are called as a module, the aic7xxx pointer may not be null
8494 * and it would point to our bootup string, just like on the lilo
8495 * command line. IF not NULL, then process this config string with
8499 aic7xxx_setup(aic7xxx
, NULL
);
8500 if(dummy_buffer
[0] != 'P')
8501 printk(KERN_WARNING
"aic7xxx: Please read the file /usr/src/linux/drivers"
8502 "/scsi/README.aic7xxx\n"
8503 "aic7xxx: to see the proper way to specify options to the aic7xxx "
8505 "aic7xxx: Specifically, don't use any commas when passing arguments to\n"
8506 "aic7xxx: insmod or else it might trash certain memory areas.\n");
8509 template->proc_dir
= &proc_scsi_aic7xxx
;
8510 template->sg_tablesize
= AIC7XXX_MAX_SG
;
8513 #if defined(__i386__) || defined(__alpha__)
8515 * EISA/VL-bus card signature probe.
8518 while ( (slot
<= MAXSLOT
) && !(aic7xxx_no_probe
) )
8520 base
= SLOTBASE(slot
) + MINREG
;
8522 if (check_region(base
, MAXREG
- MINREG
))
8525 * Some other driver has staked a
8526 * claim to this i/o region already.
8529 continue; /* back to the beginning of the for loop */
8532 type
= aic7xxx_probe(slot
, base
+ AHC_HID0
, &flags
);
8538 temp_p
= kmalloc(sizeof(struct aic7xxx_host
), GFP_ATOMIC
);
8541 printk(KERN_WARNING
"aic7xxx: Unable to allocate device space.\n");
8543 continue; /* back to the beginning of the while loop */
8546 * Pause the card preserving the IRQ type. Allow the operator
8547 * to override the IRQ trigger.
8549 if (aic7xxx_irq_trigger
== 1)
8550 hcntrl
= IRQMS
; /* Level */
8551 else if (aic7xxx_irq_trigger
== 0)
8552 hcntrl
= 0; /* Edge */
8554 hcntrl
= inb(base
+ HCNTRL
) & IRQMS
; /* Default */
8555 memset(temp_p
, 0, sizeof(struct aic7xxx_host
));
8556 temp_p
->unpause
= hcntrl
| INTEN
;
8557 temp_p
->pause
= hcntrl
| PAUSE
| INTEN
;
8558 temp_p
->base
= base
;
8561 temp_p
->pci_bus
= 0;
8562 temp_p
->pci_device_fn
= slot
;
8563 aic_outb(temp_p
, hcntrl
| PAUSE
, HCNTRL
);
8564 while( (aic_inb(temp_p
, HCNTRL
) & PAUSE
) == 0 ) ;
8565 if (aic7xxx_chip_reset(temp_p
) == -1)
8568 temp_p
->irq
= aic_inb(temp_p
, INTDEF
) & 0x0F;
8569 temp_p
->flags
|= AHC_PAGESCBS
;
8571 switch (temp_p
->irq
)
8582 printk(KERN_WARNING
"aic7xxx: Host adapter uses unsupported IRQ "
8583 "level %d, ignoring.\n", temp_p
->irq
);
8586 continue; /* back to the beginning of the while loop */
8590 * We are commited now, everything has been checked and this card
8591 * has been found, now we just set it up
8595 * Insert our new struct into the list at the end
8599 list_p
= current_p
= temp_p
;
8604 while (current_p
->next
!= NULL
)
8605 current_p
= current_p
->next
;
8606 current_p
->next
= temp_p
;
8608 if (aic7xxx_extended
)
8610 temp_p
->flags
|= AHC_EXTEND_TRANS_A
;
8611 if (temp_p
->flags
& AHC_MULTI_CHANNEL
)
8612 temp_p
->flags
|= AHC_EXTEND_TRANS_B
;
8618 temp_p
->board_name_index
= 2;
8619 if (aic7xxx_verbose
& VERBOSE_PROBE2
)
8620 printk("aic7xxx: <%s> at EISA %d\n",
8621 board_names
[2], slot
);
8625 temp_p
->chip
= AHC_AIC7770
| AHC_EISA
;
8626 temp_p
->features
|= AHC_AIC7770_FE
;
8627 temp_p
->bios_control
= aic_inb(temp_p
, HA_274_BIOSCTRL
);
8630 * Get the primary channel information. Right now we don't
8631 * do anything with this, but someday we will be able to inform
8632 * the mid-level SCSI code which channel is primary.
8634 if (temp_p
->board_name_index
== 0)
8636 temp_p
->board_name_index
= 3;
8637 if (aic7xxx_verbose
& VERBOSE_PROBE2
)
8638 printk("aic7xxx: <%s> at EISA %d\n",
8639 board_names
[3], slot
);
8641 if (temp_p
->bios_control
& CHANNEL_B_PRIMARY
)
8643 temp_p
->flags
|= AHC_CHANNEL_B_PRIMARY
;
8646 if ((temp_p
->bios_control
& BIOSMODE
) == BIOSDISABLED
)
8648 temp_p
->flags
&= ~AHC_BIOS_ENABLED
;
8652 temp_p
->flags
&= ~AHC_USEDEFAULTS
;
8653 temp_p
->flags
|= AHC_BIOS_ENABLED
;
8654 if ( (temp_p
->bios_control
& 0x20) == 0 )
8656 temp_p
->bios_address
= 0xcc000;
8657 temp_p
->bios_address
+= (0x4000 * (temp_p
->bios_control
& 0x07));
8661 temp_p
->bios_address
= 0xd0000;
8662 temp_p
->bios_address
+= (0x8000 * (temp_p
->bios_control
& 0x06));
8665 temp_p
->adapter_control
= aic_inb(temp_p
, SCSICONF
) << 8;
8666 temp_p
->adapter_control
|= aic_inb(temp_p
, SCSICONF
+ 1);
8667 if (temp_p
->features
& AHC_WIDE
)
8669 temp_p
->scsi_id
= temp_p
->adapter_control
& HWSCSIID
;
8670 temp_p
->scsi_id_b
= temp_p
->scsi_id
;
8674 temp_p
->scsi_id
= (temp_p
->adapter_control
>> 8) & HSCSIID
;
8675 temp_p
->scsi_id_b
= temp_p
->adapter_control
& HSCSIID
;
8677 aic7xxx_load_seeprom(temp_p
, &sxfrctl1
);
8683 temp_p
->chip
= AHC_AIC7770
| AHC_VL
;
8684 temp_p
->features
|= AHC_AIC7770_FE
;
8686 temp_p
->flags
|= AHC_BIOS_ENABLED
;
8688 temp_p
->flags
&= ~AHC_BIOS_ENABLED
;
8689 if (aic_inb(temp_p
, SCSICONF
) & TERM_ENB
)
8691 aic7xxx_load_seeprom(temp_p
, &sxfrctl1
);
8692 temp_p
->board_name_index
= 4;
8693 if (aic7xxx_verbose
& VERBOSE_PROBE2
)
8694 printk("aic7xxx: <%s> at VLB %d\n",
8695 board_names
[2], slot
);
8696 switch( aic_inb(temp_p
, STATUS_2840
) & BIOS_SEL
)
8699 temp_p
->bios_address
= 0xe0000;
8702 temp_p
->bios_address
= 0xc8000;
8705 temp_p
->bios_address
= 0xd0000;
8708 temp_p
->bios_address
= 0xd8000;
8711 break; /* can't get here */
8715 default: /* Won't get here. */
8718 if (aic7xxx_verbose
& VERBOSE_PROBE2
)
8720 printk(KERN_INFO
"aic7xxx: BIOS %sabled, IO Port 0x%lx, IRQ %d (%s)\n",
8721 (temp_p
->flags
& AHC_USEDEFAULTS
) ? "dis" : "en", temp_p
->base
,
8723 (temp_p
->pause
& IRQMS
) ? "level sensitive" : "edge triggered");
8724 printk(KERN_INFO
"aic7xxx: Extended translation %sabled.\n",
8725 (temp_p
->flags
& AHC_EXTEND_TRANS_A
) ? "en" : "dis");
8729 * Set the FIFO threshold and the bus off time.
8731 hostconf
= aic_inb(temp_p
, HOSTCONF
);
8732 aic_outb(temp_p
, hostconf
& DFTHRSH
, BUSSPD
);
8733 aic_outb(temp_p
, (hostconf
<< 2) & BOFF
, BUSTIME
);
8738 #endif /* defined(__i386__) || defined(__alpha__) */
8744 #if LINUX_VERSION_CODE > KERNEL_VERSION(2,1,92)
8747 if (pcibios_present())
8752 unsigned short vendor_id
;
8753 unsigned short device_id
;
8755 ahc_flag_type flags
;
8756 ahc_feature features
;
8757 int board_name_index
;
8758 unsigned short seeprom_size
;
8759 unsigned short seeprom_type
;
8760 } const aic_pdevs
[] = {
8761 {PCI_VENDOR_ID_ADAPTEC
, PCI_DEVICE_ID_ADAPTEC_7810
, AHC_NONE
,
8762 AHC_FNONE
, AHC_FENONE
, 1,
8764 {PCI_VENDOR_ID_ADAPTEC
, PCI_DEVICE_ID_ADAPTEC_7850
, AHC_AIC7850
,
8765 AHC_PAGESCBS
, AHC_AIC7850_FE
, 5,
8767 {PCI_VENDOR_ID_ADAPTEC
, PCI_DEVICE_ID_ADAPTEC_7855
, AHC_AIC7850
,
8768 AHC_PAGESCBS
, AHC_AIC7850_FE
, 6,
8770 {PCI_VENDOR_ID_ADAPTEC
, PCI_DEVICE_ID_ADAPTEC_7860
, AHC_AIC7860
,
8771 AHC_PAGESCBS
| AHC_NEWEEPROM_FMT
| AHC_BIOS_ENABLED
,
8774 {PCI_VENDOR_ID_ADAPTEC
, PCI_DEVICE_ID_ADAPTEC_7861
, AHC_AIC7860
,
8775 AHC_PAGESCBS
| AHC_NEWEEPROM_FMT
| AHC_BIOS_ENABLED
,
8778 {PCI_VENDOR_ID_ADAPTEC
, PCI_DEVICE_ID_ADAPTEC_7870
, AHC_AIC7870
,
8779 AHC_PAGESCBS
| AHC_BIOS_ENABLED
, AHC_AIC7870_FE
, 9,
8781 {PCI_VENDOR_ID_ADAPTEC
, PCI_DEVICE_ID_ADAPTEC_7871
, AHC_AIC7870
,
8782 AHC_PAGESCBS
| AHC_BIOS_ENABLED
, AHC_AIC7870_FE
, 10,
8784 {PCI_VENDOR_ID_ADAPTEC
, PCI_DEVICE_ID_ADAPTEC_7872
, AHC_AIC7870
,
8785 AHC_PAGESCBS
| AHC_BIOS_ENABLED
| AHC_MULTI_CHANNEL
,
8788 {PCI_VENDOR_ID_ADAPTEC
, PCI_DEVICE_ID_ADAPTEC_7873
, AHC_AIC7870
,
8789 AHC_PAGESCBS
| AHC_BIOS_ENABLED
| AHC_MULTI_CHANNEL
,
8792 {PCI_VENDOR_ID_ADAPTEC
, PCI_DEVICE_ID_ADAPTEC_7874
, AHC_AIC7870
,
8793 AHC_PAGESCBS
| AHC_BIOS_ENABLED
, AHC_AIC7870_FE
, 13,
8795 {PCI_VENDOR_ID_ADAPTEC
, PCI_DEVICE_ID_ADAPTEC_7880
, AHC_AIC7880
,
8796 AHC_PAGESCBS
| AHC_BIOS_ENABLED
, AHC_AIC7880_FE
, 14,
8798 {PCI_VENDOR_ID_ADAPTEC
, PCI_DEVICE_ID_ADAPTEC_7881
, AHC_AIC7880
,
8799 AHC_PAGESCBS
| AHC_BIOS_ENABLED
, AHC_AIC7880_FE
, 15,
8801 {PCI_VENDOR_ID_ADAPTEC
, PCI_DEVICE_ID_ADAPTEC_7882
, AHC_AIC7880
,
8802 AHC_PAGESCBS
| AHC_BIOS_ENABLED
| AHC_MULTI_CHANNEL
,
8805 {PCI_VENDOR_ID_ADAPTEC
, PCI_DEVICE_ID_ADAPTEC_7883
, AHC_AIC7880
,
8806 AHC_PAGESCBS
| AHC_BIOS_ENABLED
| AHC_MULTI_CHANNEL
,
8809 {PCI_VENDOR_ID_ADAPTEC
, PCI_DEVICE_ID_ADAPTEC_7884
, AHC_AIC7880
,
8810 AHC_PAGESCBS
| AHC_BIOS_ENABLED
, AHC_AIC7880_FE
, 18,
8812 {PCI_VENDOR_ID_ADAPTEC
, PCI_DEVICE_ID_ADAPTEC_7895
, AHC_AIC7895
,
8813 AHC_PAGESCBS
| AHC_NEWEEPROM_FMT
| AHC_BIOS_ENABLED
| AHC_MULTI_CHANNEL
,
8816 {PCI_VENDOR_ID_ADAPTEC2
, PCI_DEVICE_ID_ADAPTEC2_7890
, AHC_AIC7890
,
8817 AHC_PAGESCBS
| AHC_NEWEEPROM_FMT
| AHC_BIOS_ENABLED
,
8820 {PCI_VENDOR_ID_ADAPTEC2
, PCI_DEVICE_ID_ADAPTEC2_2940U2
, AHC_AIC7890
,
8821 AHC_PAGESCBS
| AHC_NEWEEPROM_FMT
| AHC_BIOS_ENABLED
,
8824 {PCI_VENDOR_ID_ADAPTEC2
, PCI_DEVICE_ID_ADAPTEC2_7896
, AHC_AIC7896
,
8825 AHC_PAGESCBS
| AHC_NEWEEPROM_FMT
| AHC_BIOS_ENABLED
| AHC_MULTI_CHANNEL
,
8828 {PCI_VENDOR_ID_ADAPTEC2
, PCI_DEVICE_ID_ADAPTEC2_3940U2
, AHC_AIC7896
,
8829 AHC_PAGESCBS
| AHC_NEWEEPROM_FMT
| AHC_BIOS_ENABLED
| AHC_MULTI_CHANNEL
,
8834 unsigned short command
;
8835 unsigned int devconfig
, i
, oldverbose
;
8837 unsigned long page_offset
, base
;
8839 #if LINUX_VERSION_CODE > KERNEL_VERSION(2,1,92)
8840 struct pci_dev
*pdev
= NULL
;
8843 unsigned int piobase
, mmapbase
;
8844 unsigned char pci_bus
, pci_devfn
, pci_irq
;
8847 for (i
= 0; i
< NUMBER(aic_pdevs
); i
++)
8849 #if LINUX_VERSION_CODE > KERNEL_VERSION(2,1,92)
8851 while ((pdev
= pci_find_device(aic_pdevs
[i
].vendor_id
,
8852 aic_pdevs
[i
].device_id
,
8856 while (!(pcibios_find_device(aic_pdevs
[i
].vendor_id
,
8857 aic_pdevs
[i
].device_id
,
8858 index
++, &pci_bus
, &pci_devfn
)) )
8861 if ( i
== 0 ) /* We found one, but it's the 7810 RAID cont. */
8863 if (aic7xxx_verbose
& (VERBOSE_PROBE
|VERBOSE_PROBE2
))
8865 printk(KERN_INFO
"aic7xxx: The 7810 RAID controller is not "
8867 printk(KERN_INFO
" this driver, we are ignoring it.\n");
8870 else if ( (temp_p
= kmalloc(sizeof(struct aic7xxx_host
),
8871 GFP_ATOMIC
)) != NULL
)
8873 memset(temp_p
, 0, sizeof(struct aic7xxx_host
));
8874 temp_p
->chip
= aic_pdevs
[i
].chip
| AHC_PCI
;
8875 temp_p
->flags
= aic_pdevs
[i
].flags
;
8876 temp_p
->features
= aic_pdevs
[i
].features
;
8877 temp_p
->board_name_index
= aic_pdevs
[i
].board_name_index
;
8878 temp_p
->sc_size
= aic_pdevs
[i
].seeprom_size
;
8879 temp_p
->sc_type
= aic_pdevs
[i
].seeprom_type
;
8882 * Read sundry information from PCI BIOS.
8884 #if LINUX_VERSION_CODE > KERNEL_VERSION(2,1,92)
8885 temp_p
->irq
= pdev
->irq
;
8886 temp_p
->pdev
= pdev
;
8887 temp_p
->pci_bus
= pdev
->bus
->number
;
8888 temp_p
->pci_device_fn
= pdev
->devfn
;
8889 temp_p
->base
= pdev
->base_address
[0];
8890 temp_p
->mbase
= pdev
->base_address
[1];
8891 if (aic7xxx_verbose
& VERBOSE_PROBE2
)
8892 printk("aic7xxx: <%s> at PCI %d/%d\n",
8893 board_names
[aic_pdevs
[i
].board_name_index
],
8894 PCI_SLOT(temp_p
->pdev
->devfn
),
8895 PCI_FUNC(temp_p
->pdev
->devfn
));
8896 pci_read_config_word(pdev
, PCI_COMMAND
, &command
);
8897 if (aic7xxx_verbose
& VERBOSE_PROBE2
)
8899 printk("aic7xxx: Initial PCI_COMMAND value was 0x%x\n",
8902 #ifdef AIC7XXX_STRICT_PCI_SETUP
8903 command
|= PCI_COMMAND_SERR
| PCI_COMMAND_PARITY
|
8904 PCI_COMMAND_INVALIDATE
| PCI_COMMAND_MASTER
|
8905 PCI_COMMAND_MEMORY
| PCI_COMMAND_IO
;
8907 command
|= PCI_COMMAND_MASTER
| PCI_COMMAND_MEMORY
| PCI_COMMAND_IO
;
8909 if (aic7xxx_pci_parity
== 0)
8910 command
&= ~(PCI_COMMAND_SERR
| PCI_COMMAND_PARITY
);
8911 pci_write_config_word(pdev
, PCI_COMMAND
, command
);
8912 #ifdef AIC7XXX_STRICT_PCI_SETUP
8913 pci_read_config_dword(pdev
, DEVCONFIG
, &devconfig
);
8914 if (aic7xxx_verbose
& VERBOSE_PROBE2
)
8916 printk("aic7xxx: Initial DEVCONFIG value was 0x%x\n", devconfig
);
8918 devconfig
|= 0x80000000;
8919 if ((aic7xxx_pci_parity
== 0) || (aic7xxx_pci_parity
== -1))
8921 devconfig
&= ~(0x00000008);
8925 devconfig
|= 0x00000008;
8927 pci_write_config_dword(pdev
, DEVCONFIG
, devconfig
);
8928 #endif /* AIC7XXX_STRICT_PCI_SETUP */
8929 #else /* LINUX_VERSION_CODE > KERNEL_VERSION(2,1,92) */
8930 temp_p
->pci_bus
= pci_bus
;
8931 temp_p
->pci_device_fn
= pci_devfn
;
8932 if (aic7xxx_verbose
& VERBOSE_PROBE2
)
8933 printk("aic7xxx: <%s> at PCI %d/%d\n",
8934 board_names
[aic_pdevs
[i
].board_name_index
],
8935 PCI_SLOT(temp_p
->pci_device_fn
),
8936 PCI_FUNC(temp_p
->pci_device_fn
));
8937 pcibios_read_config_byte(pci_bus
, pci_devfn
, PCI_INTERRUPT_LINE
,
8939 temp_p
->irq
= pci_irq
;
8940 pcibios_read_config_dword(pci_bus
, pci_devfn
, PCI_BASE_ADDRESS_0
,
8942 temp_p
->base
= piobase
;
8943 pcibios_read_config_dword(pci_bus
, pci_devfn
, PCI_BASE_ADDRESS_1
,
8945 temp_p
->mbase
= mmapbase
;
8946 pcibios_read_config_word(pci_bus
, pci_devfn
, PCI_COMMAND
, &command
);
8947 if (aic7xxx_verbose
& VERBOSE_PROBE2
)
8949 printk("aic7xxx: Initial PCI_COMMAND value was 0x%x\n",
8952 #ifdef AIC7XXX_STRICT_PCI_SETUP
8953 command
|= PCI_COMMAND_SERR
| PCI_COMMAND_PARITY
|
8954 PCI_COMMAND_INVALIDATE
| PCI_COMMAND_MASTER
|
8955 PCI_COMMAND_MEMORY
| PCI_COMMAND_IO
;
8957 command
|= PCI_COMMAND_MASTER
| PCI_COMMAND_MEMORY
| PCI_COMMAND_IO
;
8959 if (aic7xxx_pci_parity
== 0)
8960 command
&= ~(PCI_COMMAND_SERR
| PCI_COMMAND_PARITY
);
8961 pcibios_write_config_word(pci_bus
, pci_devfn
, PCI_COMMAND
, command
);
8962 #ifdef AIC7XXX_STRICT_PCI_SETUP
8963 pcibios_read_config_dword(pci_bus
, pci_devfn
, DEVCONFIG
, &devconfig
);
8964 if (aic7xxx_verbose
& VERBOSE_PROBE2
)
8966 printk("aic7xxx: Initial DEVCONFIG value was 0x%x\n", devconfig
);
8968 devconfig
|= 0x80000000;
8969 if ((aic7xxx_pci_parity
== 0) || (aic7xxx_pci_parity
== -1))
8971 devconfig
&= ~(0x00000008);
8975 devconfig
|= 0x00000008;
8977 pcibios_write_config_dword(pci_bus
, pci_devfn
, DEVCONFIG
, devconfig
);
8978 #endif /* AIC7XXX_STRICT_PCI_SETUP */
8979 #endif /* LINUIX_VERSION_CODE > KERNEL_VERSION(2,1,92) */
8982 * The first bit (LSB) of PCI_BASE_ADDRESS_0 is always set, so
8985 temp_p
->base
&= PCI_BASE_ADDRESS_IO_MASK
;
8986 temp_p
->mbase
&= PCI_BASE_ADDRESS_MEM_MASK
;
8987 temp_p
->unpause
= INTEN
;
8988 temp_p
->pause
= temp_p
->unpause
| PAUSE
;
8991 base
= temp_p
->mbase
& PAGE_MASK
;
8992 page_offset
= temp_p
->mbase
- base
;
8993 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,1,0)
8994 temp_p
->maddr
= ioremap_nocache(base
, page_offset
+ 256);
8996 temp_p
->maddr
= vremap(base
, page_offset
+ 256);
9000 temp_p
->maddr
+= page_offset
;
9004 pause_sequencer(temp_p
);
9007 * Clear out any pending PCI error status messages. Also set
9008 * verbose to 0 so that we don't emit strange PCI error messages
9009 * while cleaning out the current status bits.
9011 oldverbose
= aic7xxx_verbose
;
9012 aic7xxx_verbose
= 0;
9013 aic7xxx_pci_intr(temp_p
);
9014 aic7xxx_verbose
= oldverbose
;
9016 temp_p
->bios_address
= 0;
9019 * Remember how the card was setup in case there is no seeprom.
9021 if (temp_p
->features
& AHC_ULTRA2
)
9022 temp_p
->scsi_id
= aic_inb(temp_p
, SCSIID_ULTRA2
) & OID
;
9024 temp_p
->scsi_id
= aic_inb(temp_p
, SCSIID
) & OID
;
9026 * Get current termination setting
9028 sxfrctl1
= aic_inb(temp_p
, SXFRCTL1
) & STPWEN
;
9030 if (aic7xxx_chip_reset(temp_p
) == -1)
9038 * Doing a switch based upon i is really gross, but since Justin
9039 * changed around the chip ID stuff, we can't use that any more.
9040 * Since we don't scan the devices the same way as FreeBSD, we end
9041 * up doing this gross hack in order to avoid totally splitting
9042 * away from Justin's init code in ahc_pci.c
9047 case 12: /* 3940-Ultra */
9048 switch(PCI_SLOT(temp_p
->pci_device_fn
))
9051 temp_p
->flags
|= AHC_CHNLB
;
9059 case 13: /* 3985-Ultra */
9060 switch(PCI_SLOT(temp_p
->pci_device_fn
))
9063 temp_p
->flags
|= AHC_CHNLB
;
9066 temp_p
->flags
|= AHC_CHNLC
;
9076 #if LINUX_VERSION_CODE > KERNEL_VERSION(2,1,92)
9077 if (PCI_FUNC(temp_p
->pdev
->devfn
) != 0)
9079 temp_p
->flags
|= AHC_CHNLB
;
9082 * The 7895 is the only chipset that sets the SCBSIZE32 param
9083 * in the DEVCONFIG register. The Ultra2 chipsets use
9084 * the DSCOMMAND0 register instead.
9086 if ((temp_p
->chip
& AHC_CHIPID_MASK
) == AHC_AIC7895
)
9088 pci_read_config_dword(pdev
, DEVCONFIG
, &devconfig
);
9089 devconfig
|= SCBSIZE32
;
9090 pci_write_config_dword(pdev
, DEVCONFIG
, devconfig
);
9093 if (PCI_FUNC(temp_p
->pci_device_fn
) != 0)
9095 temp_p
->flags
|= AHC_CHNLB
;
9098 * The 7895 is the only chipset that sets the SCBSIZE32 param
9099 * in the DEVCONFIG register. The Ultra2 chipsets use
9100 * the DSCOMMAND0 register instead.
9102 if ((temp_p
->chip
& AHC_CHIPID_MASK
) == AHC_AIC7895
)
9104 pcibios_read_config_dword(pci_bus
, pci_devfn
, DEVCONFIG
,
9106 devconfig
|= SCBSIZE32
;
9107 pcibios_write_config_dword(pci_bus
, pci_devfn
, DEVCONFIG
,
9117 * Loading of the SEEPROM needs to come after we've set the flags
9118 * to indicate possible CHNLB and CHNLC assigments. Otherwise,
9119 * on 394x and 398x cards we'll end up reading the wrong settings
9120 * for channels B and C
9122 switch (temp_p
->chip
& AHC_CHIPID_MASK
)
9126 aic_outb(temp_p
, 0, SCAMCTL
);
9128 * We used to set DPARCKEN in this register, but after talking
9129 * to a tech from Adaptec, I found out they don't use that
9130 * particular bit in their own register settings, and when you
9131 * combine that with the fact that I determined that we were
9132 * seeing Data-Path Parity Errors on things we shouldn't see
9133 * them on, I think there is a bug in the silicon and the way
9134 * to work around it is to disable this particular check. Also
9135 * This bug only showed up on certain commands, so it seems to
9136 * be pattern related or some such. The commands we would
9137 * typically send as a linux TEST_UNIT_READY or INQUIRY command
9138 * could cause it to be triggered, while regular commands that
9139 * actually made reasonable use of the SG array capabilities
9140 * seemed not to cause the problem.
9143 aic_outb(temp_p, aic_inb(temp_p, DSCOMMAND0) |
9144 CACHETHEN | DPARCKEN | MPARCKEN |
9145 USCBSIZE32 | CIOPARCKEN,
9148 aic_outb(temp_p
, (aic_inb(temp_p
, DSCOMMAND0
) |
9149 CACHETHEN
| MPARCKEN
| USCBSIZE32
|
9150 CIOPARCKEN
) & ~DPARCKEN
, DSCOMMAND0
);
9154 * We attempt to read a SEEPROM on *everything*. If we fail,
9155 * then we fail, but this covers things like 2910c cards that
9156 * now have SEEPROMs with their 7856 chipset that we would
9157 * otherwise ignore. They still don't have a BIOS, but they
9158 * have a SEEPROM that the SCSISelect utility on the Adaptec
9159 * diskettes can configure.
9161 aic7xxx_load_seeprom(temp_p
, &sxfrctl1
);
9166 * Set the DSCOMMAND0 register on these cards different from
9167 * on the 789x cards. Also, read the SEEPROM as well.
9169 aic_outb(temp_p
, (aic_inb(temp_p
, DSCOMMAND0
) |
9170 CACHETHEN
| MPARCKEN
) & ~DPARCKEN
,
9172 aic7xxx_load_seeprom(temp_p
, &sxfrctl1
);
9176 * Only set the DSCOMMAND0 register if this is a Rev B.
9177 * chipset. For those, we also enable Ultra mode by
9178 * force due to brain-damage on the part of some BIOSes
9179 * We overload the devconfig variable here since we can.
9181 #if LINUX_VERSION_CODE > KERNEL_VERSION(2,1,92)
9182 pci_read_config_dword(pdev
, DEVCONFIG
, &devconfig
);
9184 pcibios_read_config_dword(pci_bus
, pci_devfn
, DEVCONFIG
,
9187 if ((devconfig
& 0xff) >= 1)
9189 aic_outb(temp_p
, (aic_inb(temp_p
, DSCOMMAND0
) |
9190 CACHETHEN
| MPARCKEN
) & ~DPARCKEN
,
9193 aic7xxx_load_seeprom(temp_p
, &sxfrctl1
);
9199 * and then we need another switch based on the type in order to
9200 * make sure the channel B primary flag is set properly on 7895
9201 * controllers....Arrrgggghhh!!! We also have to catch the fact
9202 * that when you disable the BIOS on the 7895 on the Intel DK440LX
9203 * motherboard, and possibly others, it only sets the BIOS disabled
9204 * bit on the A channel...I think I'm starting to lean towards
9207 switch(temp_p
->chip
& AHC_CHIPID_MASK
)
9212 while(current_p
!= NULL
)
9214 if ( (current_p
->pci_bus
== temp_p
->pci_bus
) &&
9215 (PCI_SLOT(current_p
->pci_device_fn
) ==
9216 PCI_SLOT(temp_p
->pci_device_fn
)) )
9218 if ( PCI_FUNC(current_p
->pci_device_fn
) == 0 )
9221 (current_p
->flags
& AHC_CHANNEL_B_PRIMARY
);
9222 temp_p
->flags
&= ~(AHC_BIOS_ENABLED
|AHC_USEDEFAULTS
);
9224 (current_p
->flags
& (AHC_BIOS_ENABLED
|AHC_USEDEFAULTS
));
9229 (temp_p
->flags
& AHC_CHANNEL_B_PRIMARY
);
9230 current_p
->flags
&= ~(AHC_BIOS_ENABLED
|AHC_USEDEFAULTS
);
9232 (temp_p
->flags
& (AHC_BIOS_ENABLED
|AHC_USEDEFAULTS
));
9235 current_p
= current_p
->next
;
9243 * We do another switch based on i so that we can exclude all
9244 * 3895 devices from the next option since the 3895 cards use
9245 * shared external SCB RAM while all other cards have dedicated
9246 * external SCB RAM per channel. Also exclude the 7850 and
9247 * 7860 based stuff since they can have garbage in the bit
9248 * that indicates external RAM and get some of this stuff
9249 * wrong as a result.
9251 switch(temp_p
->chip
& AHC_CHIPID_MASK
)
9257 #if LINUX_VERSION_CODE > KERNEL_VERSION(2,1,92)
9258 pci_read_config_dword(pdev
, DEVCONFIG
, &devconfig
);
9260 pcibios_read_config_dword(pci_bus
, pci_devfn
, DEVCONFIG
,
9263 if (temp_p
->features
& AHC_ULTRA2
)
9265 if (aic_inb(temp_p
, DSCOMMAND0
) & RAMPSM_ULTRA2
)
9268 aic_inb(temp_p
, DSCOMMAND0
) & ~SCBRAMSEL_ULTRA2
,
9270 temp_p
->flags
|= AHC_EXTERNAL_SRAM
;
9271 devconfig
|= EXTSCBPEN
;
9274 else if (devconfig
& RAMPSM
)
9276 devconfig
&= ~SCBRAMSEL
;
9277 devconfig
|= EXTSCBPEN
;
9278 temp_p
->flags
|= AHC_EXTERNAL_SRAM
;
9280 #if LINUX_VERSION_CODE > KERNEL_VERSION(2,1,92)
9281 pci_write_config_dword(pdev
, DEVCONFIG
, devconfig
);
9283 pcibios_write_config_dword(pci_bus
, pci_devfn
, DEVCONFIG
,
9286 if ( (temp_p
->flags
& AHC_EXTERNAL_SRAM
) &&
9287 (temp_p
->flags
& AHC_CHNLB
) )
9288 aic_outb(temp_p
, 1, CCSCBBADDR
);
9293 * Take the LED out of diagnostic mode
9296 (aic_inb(temp_p
, SBLKCTL
) & ~(DIAGLEDEN
| DIAGLEDON
)),
9300 * We don't know where this is set in the SEEPROM or by the
9301 * BIOS, so we default to 100%. On Ultra2 controllers, use 75%
9304 if (temp_p
->features
& AHC_ULTRA2
)
9306 aic_outb(temp_p
, RD_DFTHRSH_75
| WR_DFTHRSH_75
, DFF_THRSH
);
9310 aic_outb(temp_p
, DFTHRSH_100
, DSPCISTATUS
);
9313 if (aic7xxx_extended
)
9314 temp_p
->flags
|= AHC_EXTEND_TRANS_A
;
9316 if ( list_p
== NULL
)
9318 list_p
= current_p
= temp_p
;
9323 while(current_p
->next
!= NULL
)
9324 current_p
= current_p
->next
;
9325 current_p
->next
= temp_p
;
9327 temp_p
->next
= NULL
;
9329 } /* Found an Adaptec PCI device. */
9330 else /* Well, we found one, but we couldn't get any memory */
9332 printk("aic7xxx: Found <%s>\n",
9333 board_names
[aic_pdevs
[i
].board_name_index
]);
9334 printk(KERN_INFO
"aic7xxx: Unable to allocate device memory, "
9337 } /* while(pdev=....) */
9338 } /* for PCI_DEVICES */
9339 } /* PCI BIOS present */
9342 * Now, we re-order the probed devices by BIOS address and BUS class.
9343 * In general, we follow this algorithm to make the adapters show up
9344 * in the same order under linux that the computer finds them.
9345 * 1: All VLB/EISA cards with BIOS_ENABLED first, according to BIOS
9346 * address, going from lowest to highest.
9347 * 2: All PCI controllers with BIOS_ENABLED next, according to BIOS
9348 * address, going from lowest to highest.
9349 * 3: Remaining VLB/EISA controllers going in slot order.
9350 * 4: Remaining PCI controllers, going in PCI device order (reversable)
9354 struct aic7xxx_host
*sort_list
[4] = { NULL
, NULL
, NULL
, NULL
};
9355 struct aic7xxx_host
*vlb
, *pci
;
9356 struct aic7xxx_host
*prev_p
;
9357 struct aic7xxx_host
*p
;
9360 prev_p
= vlb
= pci
= NULL
;
9363 while (temp_p
!= NULL
)
9365 switch(temp_p
->chip
& ~AHC_CHIPID_MASK
)
9371 if (p
->flags
& AHC_BIOS_ENABLED
)
9379 temp_p
= temp_p
->next
;
9386 while ( (current_p
!= NULL
) &&
9387 (current_p
->bios_address
< temp_p
->bios_address
))
9390 current_p
= current_p
->next
;
9394 prev_p
->next
= temp_p
;
9395 temp_p
= temp_p
->next
;
9396 prev_p
->next
->next
= current_p
;
9401 temp_p
= temp_p
->next
;
9402 vlb
->next
= current_p
;
9406 if (p
->flags
& AHC_BIOS_ENABLED
)
9413 default: /* All PCI controllers fall through to default */
9417 if (p
->flags
& AHC_BIOS_ENABLED
)
9425 temp_p
= temp_p
->next
;
9432 if (!aic7xxx_reverse_scan
)
9434 while ( (current_p
!= NULL
) &&
9435 ( (PCI_SLOT(current_p
->pci_device_fn
) |
9436 (current_p
->pci_bus
<< 8)) <
9437 (PCI_SLOT(temp_p
->pci_device_fn
) |
9438 (temp_p
->pci_bus
<< 8)) ) )
9441 current_p
= current_p
->next
;
9446 while ( (current_p
!= NULL
) &&
9447 ( (PCI_SLOT(current_p
->pci_device_fn
) |
9448 (current_p
->pci_bus
<< 8)) >
9449 (PCI_SLOT(temp_p
->pci_device_fn
) |
9450 (temp_p
->pci_bus
<< 8)) ) )
9453 current_p
= current_p
->next
;
9457 * Are we dealing with a 7985 where we need to sort the
9458 * channels as well, if so, the bios_address values should
9461 if ( (current_p
) && (temp_p
->flags
& AHC_MULTI_CHANNEL
) &&
9462 (temp_p
->pci_bus
== current_p
->pci_bus
) &&
9463 (PCI_SLOT(temp_p
->pci_device_fn
) ==
9464 PCI_SLOT(current_p
->pci_device_fn
)) )
9466 if (temp_p
->flags
& AHC_CHNLB
)
9468 if ( !(temp_p
->flags
& AHC_CHANNEL_B_PRIMARY
) )
9471 current_p
= current_p
->next
;
9476 if (temp_p
->flags
& AHC_CHANNEL_B_PRIMARY
)
9479 current_p
= current_p
->next
;
9485 prev_p
->next
= temp_p
;
9486 temp_p
= temp_p
->next
;
9487 prev_p
->next
->next
= current_p
;
9492 temp_p
= temp_p
->next
;
9493 pci
->next
= current_p
;
9497 if (p
->flags
& AHC_BIOS_ENABLED
)
9504 } /* End of switch(temp_p->type) */
9505 } /* End of while (temp_p != NULL) */
9507 * At this point, the cards have been broken into 4 sorted lists, now
9508 * we run through the lists in order and register each controller
9514 for (i
=0; i
<NUMBER(sort_list
); i
++)
9516 temp_p
= sort_list
[i
];
9517 while(temp_p
!= NULL
)
9519 template->name
= board_names
[temp_p
->board_name_index
];
9520 p
= aic7xxx_alloc(template, temp_p
);
9523 p
->instance
= found
- left
;
9524 if (aic7xxx_register(template, p
, (--left
)) == 0)
9527 aic7xxx_release(p
->host
);
9528 scsi_unregister(p
->host
);
9530 else if (aic7xxx_dump_card
)
9533 aic7xxx_print_card(p
);
9534 aic7xxx_print_scratch_ram(p
);
9535 unpause_sequencer(p
, TRUE
);
9539 temp_p
= (struct aic7xxx_host
*)temp_p
->next
;
9548 #ifdef AIC7XXX_FAKE_NEGOTIATION_CMDS
9550 /*+F*************************************************************************
9552 * aic7xxx_negotiation_complete
9555 * Handle completion events for our Negotiation commands. Clear out the
9556 * struct and get it ready for its next use.
9557 *-F*************************************************************************/
9559 aic7xxx_negotiation_complete(Scsi_Cmnd
*cmd
)
9564 /*+F*************************************************************************
9566 * aic7xxx_build_negotiation_command
9569 * Build a Scsi_Cmnd structure to perform negotiation with or else send
9570 * a pre-built command specifically for this purpose.
9571 *-F*************************************************************************/
9573 aic7xxx_build_negotiation_cmnd(struct aic7xxx_host
*p
, Scsi_Cmnd
*old_cmd
,
9577 if ( (p
->needwdtr
& (1<<tindex
)) && !(p
->wdtr_pending
& (1<<tindex
)) )
9579 if(p
->dev_wdtr_cmnd
[tindex
] == NULL
)
9583 if (!(p
->dev_wdtr_cmnd
[tindex
] = kmalloc(sizeof(Scsi_Cmnd
), GFP_ATOMIC
)) )
9587 cmd
= p
->dev_wdtr_cmnd
[tindex
];
9588 memset(cmd
, 0, sizeof(Scsi_Cmnd
));
9589 memcpy(cmd
, old_cmd
, sizeof(Scsi_Cmnd
));
9590 memset(&cmd
->cmnd
[0], 0, sizeof(cmd
->cmnd
));
9591 memset(&cmd
->data_cmnd
[0], 0, sizeof(cmd
->data_cmnd
));
9593 cmd
->request_bufflen
= 0;
9594 cmd
->request_buffer
= NULL
;
9595 cmd
->use_sg
= cmd
->old_use_sg
= cmd
->sglist_len
= 0;
9602 * Before sending this thing out, we also amke the cmd->next pointer
9603 * point to the real command so we can stuff any possible SENSE data
9604 * intp the real command instead of this fake command. This has to be
9605 * done each time the command is built, not just the first time, hence
9606 * it's outside of the above if()...
9608 p
->dev_wdtr_cmnd
[tindex
]->next
= old_cmd
;
9609 aic7xxx_queue(p
->dev_wdtr_cmnd
[tindex
],
9610 aic7xxx_negotiation_complete
);
9612 else if ( (p
->needsdtr
& (1<<tindex
)) && !(p
->sdtr_pending
& (1<<tindex
)) &&
9613 !(p
->wdtr_pending
& (1<<tindex
)) )
9615 if(p
->dev_sdtr_cmnd
[tindex
] == NULL
)
9619 if (!(p
->dev_sdtr_cmnd
[tindex
] = kmalloc(sizeof(Scsi_Cmnd
), GFP_ATOMIC
)) )
9623 cmd
= p
->dev_sdtr_cmnd
[tindex
];
9624 memset(cmd
, 0, sizeof(Scsi_Cmnd
));
9625 memcpy(cmd
, old_cmd
, sizeof(Scsi_Cmnd
));
9626 memset(&cmd
->cmnd
[0], 0, sizeof(cmd
->cmnd
));
9627 memset(&cmd
->data_cmnd
[0], 0, sizeof(cmd
->data_cmnd
));
9629 cmd
->request_bufflen
= 0;
9630 cmd
->request_buffer
= NULL
;
9631 cmd
->use_sg
= cmd
->old_use_sg
= cmd
->sglist_len
= 0;
9638 * Before sending this thing out, we also amke the cmd->next pointer
9639 * point to the real command so we can stuff any possible SENSE data
9640 * intp the real command instead of this fake command. This has to be
9641 * done each time the command is built, not just the first time, hence
9642 * it's outside of the above if()...
9644 p
->dev_sdtr_cmnd
[tindex
]->next
= old_cmd
;
9645 aic7xxx_queue(p
->dev_sdtr_cmnd
[tindex
],
9646 aic7xxx_negotiation_complete
);
9652 #ifdef AIC7XXX_VERBOSE_DEBUGGING
9653 /*+F*************************************************************************
9658 * Dump the byte codes for an about to be sent SCB.
9659 *-F*************************************************************************/
9661 aic7xxx_print_scb(struct aic7xxx_host
*p
, struct aic7xxx_scb
*scb
)
9666 x
= (unsigned char *)&scb
->hscb
->control
;
9670 printk("%02x ", x
[i
]);
9676 /*+F*************************************************************************
9682 *-F*************************************************************************/
9684 aic7xxx_buildscb(struct aic7xxx_host
*p
, Scsi_Cmnd
*cmd
,
9685 struct aic7xxx_scb
*scb
)
9687 unsigned short mask
;
9688 struct aic7xxx_hwscb
*hscb
;
9690 mask
= (0x01 << TARGET_INDEX(cmd
));
9694 * Setup the control byte if we need negotiation and have not
9695 * already requested it.
9698 scb
->tag_action
= 0;
9699 if (p
->discenable
& mask
)
9701 hscb
->control
|= DISCENB
;
9702 if (p
->tagenable
& mask
)
9704 cmd
->tag
= hscb
->tag
;
9705 p
->dev_commands_sent
[TARGET_INDEX(cmd
)]++;
9706 if (p
->dev_commands_sent
[TARGET_INDEX(cmd
)] < 200)
9708 hscb
->control
|= MSG_SIMPLE_Q_TAG
;
9709 scb
->tag_action
= MSG_SIMPLE_Q_TAG
;
9713 if (p
->orderedtag
& mask
)
9715 hscb
->control
|= MSG_ORDERED_Q_TAG
;
9716 scb
->tag_action
= MSG_ORDERED_Q_TAG
;
9720 hscb
->control
|= MSG_SIMPLE_Q_TAG
;
9721 scb
->tag_action
= MSG_SIMPLE_Q_TAG
;
9723 p
->dev_commands_sent
[TARGET_INDEX(cmd
)] = 0;
9727 if (p
->dev_flags
[TARGET_INDEX(cmd
)] & DEVICE_SCANNED
)
9729 #ifdef AIC7XXX_FAKE_NEGOTIATION_CMDS
9730 if ( (p
->needwdtr
& mask
) && !(p
->wdtr_pending
& mask
) )
9732 if (cmd
== p
->dev_wdtr_cmnd
[TARGET_INDEX(cmd
)])
9734 p
->wdtr_pending
|= mask
;
9735 scb
->flags
|= SCB_MSGOUT_WDTR
;
9736 hscb
->control
&= DISCENB
;
9737 hscb
->control
|= MK_MESSAGE
;
9738 scb
->tag_action
= 0;
9742 aic7xxx_build_negotiation_cmnd(p
, cmd
, TARGET_INDEX(cmd
));
9745 else if ( (p
->needsdtr
& mask
) && !(p
->sdtr_pending
& mask
) &&
9746 !(p
->wdtr_pending
& mask
) )
9748 if (cmd
== p
->dev_sdtr_cmnd
[TARGET_INDEX(cmd
)])
9750 p
->sdtr_pending
|= mask
;
9751 scb
->flags
|= SCB_MSGOUT_SDTR
;
9752 hscb
->control
&= DISCENB
;
9753 hscb
->control
|= MK_MESSAGE
;
9754 scb
->tag_action
= 0;
9756 else if (cmd
!= p
->dev_wdtr_cmnd
[TARGET_INDEX(cmd
)])
9758 aic7xxx_build_negotiation_cmnd(p
, cmd
, TARGET_INDEX(cmd
));
9762 if ( (p
->needwdtr
& mask
) && !(p
->wdtr_pending
& mask
) &&
9763 !(p
->sdtr_pending
& mask
) && (cmd
->lun
== 0) )
9765 p
->wdtr_pending
|= mask
;
9766 scb
->flags
|= SCB_MSGOUT_WDTR
;
9767 hscb
->control
&= DISCENB
;
9768 hscb
->control
|= MK_MESSAGE
;
9769 scb
->tag_action
= 0;
9770 #ifdef AIC7XXX_VERBOSE_DEBUGGING
9771 if (aic7xxx_verbose
> 0xffff)
9772 printk(INFO_LEAD
"Building WDTR command.\n", p
->host_no
,
9776 else if ( (p
->needsdtr
& mask
) && !(p
->wdtr_pending
& mask
) &&
9777 !(p
->sdtr_pending
& mask
) && (cmd
->lun
== 0) )
9779 p
->sdtr_pending
|= mask
;
9780 scb
->flags
|= SCB_MSGOUT_SDTR
;
9781 hscb
->control
&= DISCENB
;
9782 hscb
->control
|= MK_MESSAGE
;
9783 scb
->tag_action
= 0;
9784 #ifdef AIC7XXX_VERBOSE_DEBUGGING
9785 if (aic7xxx_verbose
> 0xffff)
9786 printk(INFO_LEAD
"Building SDTR command.\n", p
->host_no
,
9792 hscb
->target_channel_lun
= ((cmd
->target
<< 4) & 0xF0) |
9793 ((cmd
->channel
& 0x01) << 3) | (cmd
->lun
& 0x07);
9796 * The interpretation of request_buffer and request_bufflen
9797 * changes depending on whether or not use_sg is zero; a
9798 * non-zero use_sg indicates the number of elements in the
9799 * scatter-gather array.
9803 * XXX - this relies on the host data being stored in a
9804 * little-endian format.
9806 hscb
->SCSI_cmd_length
= cmd
->cmd_len
;
9807 hscb
->SCSI_cmd_pointer
= cpu_to_le32(VIRT_TO_BUS(cmd
->cmnd
));
9811 struct scatterlist
*sg
; /* Must be mid-level SCSI code scatterlist */
9814 * We must build an SG list in adapter format, as the kernel's SG list
9815 * cannot be used directly because of data field size (__alpha__)
9816 * differences and the kernel SG list uses virtual addresses where
9817 * we need physical addresses.
9821 sg
= (struct scatterlist
*)cmd
->request_buffer
;
9824 * Copy the segments into the SG array. NOTE!!! - We used to
9825 * have the first entry both in the data_pointer area and the first
9826 * SG element. That has changed somewhat. We still have the first
9827 * entry in both places, but now we download the address of
9828 * scb->sg_list[1] instead of 0 to the sg pointer in the hscb.
9830 for (i
= 0; i
< cmd
->use_sg
; i
++)
9832 scb
->sg_list
[i
].address
= cpu_to_le32(VIRT_TO_BUS(sg
[i
].address
));
9833 scb
->sg_list
[i
].length
= cpu_to_le32(sg
[i
].length
);
9834 scb
->sg_length
+= sg
[i
].length
;
9836 /* Copy the first SG into the data pointer area. */
9837 hscb
->data_pointer
= scb
->sg_list
[0].address
;
9838 hscb
->data_count
= scb
->sg_list
[0].length
;
9839 scb
->sg_count
= cmd
->use_sg
;
9840 hscb
->SG_segment_count
= cmd
->use_sg
;
9841 hscb
->SG_list_pointer
= cpu_to_le32(VIRT_TO_BUS(&scb
->sg_list
[1]));
9846 if (cmd
->request_bufflen
)
9849 scb
->sg_list
[0].address
= cpu_to_le32(VIRT_TO_BUS(cmd
->request_buffer
));
9850 scb
->sg_list
[0].length
= cpu_to_le32(cmd
->request_bufflen
);
9851 scb
->sg_length
= cmd
->request_bufflen
;
9852 hscb
->SG_segment_count
= 1;
9853 hscb
->SG_list_pointer
= cpu_to_le32(VIRT_TO_BUS(&scb
->sg_list
[0]));
9854 hscb
->data_count
= scb
->sg_list
[0].length
;
9855 hscb
->data_pointer
= scb
->sg_list
[0].address
;
9861 hscb
->SG_segment_count
= 0;
9862 hscb
->SG_list_pointer
= 0;
9863 hscb
->data_count
= 0;
9864 hscb
->data_pointer
= 0;
9867 #ifdef AIC7XXX_VERBOSE_DEBUGGING
9868 if((cmd
->cmnd
[0] == TEST_UNIT_READY
) && (aic7xxx_verbose
& VERBOSE_PROBE2
))
9870 aic7xxx_print_scb(p
, scb
);
9875 /*+F*************************************************************************
9880 * Queue a SCB to the controller.
9881 *-F*************************************************************************/
9883 aic7xxx_queue(Scsi_Cmnd
*cmd
, void (*fn
)(Scsi_Cmnd
*))
9885 struct aic7xxx_host
*p
;
9886 struct aic7xxx_scb
*scb
;
9887 #ifdef AIC7XXX_VERBOSE_DEBUGGING
9888 int tindex
= TARGET_INDEX(cmd
);
9890 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,1,95)
9891 unsigned long cpu_flags
= 0;
9894 p
= (struct aic7xxx_host
*) cmd
->host
->hostdata
;
9896 * Check to see if channel was scanned.
9899 #ifdef AIC7XXX_VERBOSE_DEBUGGING
9900 if (!(p
->flags
& AHC_A_SCANNED
) && (cmd
->channel
== 0))
9902 if (aic7xxx_verbose
& VERBOSE_PROBE2
)
9903 printk(INFO_LEAD
"Scanning channel for devices.\n",
9904 p
->host_no
, 0, -1, -1);
9905 p
->flags
|= AHC_A_SCANNED
;
9909 if (!(p
->flags
& AHC_B_SCANNED
) && (cmd
->channel
== 1))
9911 if (aic7xxx_verbose
& VERBOSE_PROBE2
)
9912 printk(INFO_LEAD
"Scanning channel for devices.\n",
9913 p
->host_no
, 1, -1, -1);
9914 p
->flags
|= AHC_B_SCANNED
;
9918 if (p
->dev_active_cmds
[tindex
] > (cmd
->device
->queue_depth
+ 1))
9920 printk(WARN_LEAD
"Commands queued exceeds queue "
9921 "depth, active=%d\n",
9922 p
->host_no
, CTL_OF_CMD(cmd
),
9923 p
->dev_active_cmds
[tindex
]);
9924 if ( p
->dev_active_cmds
[tindex
] > 220 )
9925 p
->dev_active_cmds
[tindex
] = 0;
9929 scb
= scbq_remove_head(&p
->scb_data
->free_scbs
);
9933 aic7xxx_allocate_scb(p
);
9935 scb
= scbq_remove_head(&p
->scb_data
->free_scbs
);
9939 printk(WARN_LEAD
"Couldn't get a free SCB.\n", p
->host_no
,
9941 cmd
->result
= (DID_BUS_BUSY
<< 16);
9943 aic7xxx_queue_cmd_complete(p
, cmd
);
9950 aic7xxx_position(cmd
) = scb
->hscb
->tag
;
9953 * Construct the SCB beforehand, so the sequencer is
9954 * paused a minimal amount of time.
9956 aic7xxx_buildscb(p
, cmd
, scb
);
9959 * Make sure the Scsi_Cmnd pointer is saved, the struct it points to
9960 * is set up properly, and the parity error flag is reset, then send
9961 * the SCB to the sequencer and watch the fun begin.
9963 cmd
->scsi_done
= fn
;
9964 cmd
->result
= DID_OK
;
9965 memset(cmd
->sense_buffer
, 0, sizeof(cmd
->sense_buffer
));
9966 aic7xxx_error(cmd
) = DID_OK
;
9967 aic7xxx_status(cmd
) = 0;
9968 cmd
->host_scribble
= NULL
;
9970 scb
->flags
|= SCB_ACTIVE
| SCB_WAITINGQ
;
9973 scbq_insert_tail(&p
->waiting_scbs
, scb
);
9974 if ( (p
->flags
& (AHC_IN_ISR
| AHC_IN_ABORT
| AHC_IN_RESET
)) == 0)
9976 aic7xxx_run_waiting_queues(p
);
9983 /*+F*************************************************************************
9985 * aic7xxx_bus_device_reset
9988 * Abort or reset the current SCSI command(s). If the scb has not
9989 * previously been aborted, then we attempt to send a BUS_DEVICE_RESET
9990 * message to the target. If the scb has previously been unsuccessfully
9991 * aborted, then we will reset the channel and have all devices renegotiate.
9992 * Returns an enumerated type that indicates the status of the operation.
9993 *-F*************************************************************************/
9995 aic7xxx_bus_device_reset(struct aic7xxx_host
*p
, Scsi_Cmnd
*cmd
)
9997 struct aic7xxx_scb
*scb
;
9998 struct aic7xxx_hwscb
*hscb
;
10001 unsigned char saved_scbptr
, lastphase
;
10002 unsigned char hscb_index
;
10005 scb
= (p
->scb_data
->scb_array
[aic7xxx_position(cmd
)]);
10008 lastphase
= aic_inb(p
, LASTPHASE
);
10009 if (aic7xxx_verbose
& VERBOSE_RESET_PROCESS
)
10011 printk(INFO_LEAD
"Bus Device reset, scb flags 0x%x, ",
10012 p
->host_no
, CTL_OF_SCB(scb
), scb
->flags
);
10016 printk("Data-Out phase\n");
10019 printk("Data-In phase\n");
10022 printk("Command phase\n");
10025 printk("Message-Out phase\n");
10028 printk("Status phase\n");
10031 printk("Message-In phase\n");
10035 * We're not in a valid phase, so assume we're idle.
10037 printk("while idle, LASTPHASE = 0x%x\n", lastphase
);
10040 printk(INFO_LEAD
"SCSISIGI 0x%x, SEQADDR 0x%x, SSTAT0 0x%x, SSTAT1 "
10041 "0x%x\n", p
->host_no
, CTL_OF_SCB(scb
),
10042 aic_inb(p
, SCSISIGI
),
10043 aic_inb(p
, SEQADDR0
) | (aic_inb(p
, SEQADDR1
) << 8),
10044 aic_inb(p
, SSTAT0
), aic_inb(p
, SSTAT1
));
10047 channel
= cmd
->channel
;
10050 * Send a Device Reset Message:
10051 * The target that is holding up the bus may not be the same as
10052 * the one that triggered this timeout (different commands have
10053 * different timeout lengths). Our strategy here is to queue an
10054 * abort message to the timed out target if it is disconnected.
10055 * Otherwise, if we have an active target we stuff the message buffer
10056 * with an abort message and assert ATN in the hopes that the target
10057 * will let go of the bus and go to the mesgout phase. If this
10058 * fails, we'll get another timeout a few seconds later which will
10059 * attempt a bus reset.
10061 saved_scbptr
= aic_inb(p
, SCBPTR
);
10062 disconnected
= FALSE
;
10064 if (lastphase
!= P_BUSFREE
)
10066 if (aic_inb(p
, SCB_TAG
) >= p
->scb_data
->numscbs
)
10068 printk(WARN_LEAD
"Invalid SCB ID %d is active, "
10069 "SCB flags = 0x%x.\n", p
->host_no
,
10070 CTL_OF_CMD(cmd
), scb
->hscb
->tag
, scb
->flags
);
10071 return(SCSI_RESET_ERROR
);
10073 if (scb
->hscb
->tag
== aic_inb(p
, SCB_TAG
))
10075 if ( (lastphase
!= P_MESGOUT
) && (lastphase
!= P_MESGIN
) )
10077 if (aic7xxx_verbose
& VERBOSE_RESET_PROCESS
)
10078 printk(INFO_LEAD
"Device reset message in "
10079 "message buffer\n", p
->host_no
, CTL_OF_SCB(scb
));
10080 scb
->flags
|= SCB_RESET
| SCB_DEVICE_RESET
;
10081 aic7xxx_error(scb
->cmd
) = DID_RESET
;
10082 p
->dev_flags
[TARGET_INDEX(scb
->cmd
)] &=
10084 p
->dev_flags
[TARGET_INDEX(scb
->cmd
)] |=
10085 BUS_DEVICE_RESET_PENDING
;
10086 /* Send the abort message to the active SCB. */
10087 aic_outb(p
, HOST_MSG
, MSG_OUT
);
10088 aic_outb(p
, lastphase
| ATNO
, SCSISIGO
);
10089 return(SCSI_RESET_PENDING
);
10093 /* We want to send out the message, but it could screw an already */
10094 /* in place and being used message. Instead, we return an error */
10095 /* to try and start the bus reset phase since this command is */
10096 /* probably hung (aborts failed, and now reset is failing). We */
10097 /* also make sure to set BUS_DEVICE_RESET_PENDING so we won't try */
10098 /* any more on this device, but instead will escalate to a bus or */
10099 /* host reset (additionally, we won't try to abort any more). */
10100 printk(WARN_LEAD
"Device reset, Message buffer "
10101 "in use\n", p
->host_no
, CTL_OF_SCB(scb
));
10102 scb
->flags
|= SCB_RESET
| SCB_DEVICE_RESET
;
10103 aic7xxx_error(scb
->cmd
) = DID_RESET
;
10104 p
->dev_flags
[TARGET_INDEX(scb
->cmd
)] &=
10106 p
->dev_flags
[TARGET_INDEX(scb
->cmd
)] |=
10107 BUS_DEVICE_RESET_PENDING
;
10108 return(SCSI_RESET_ERROR
);
10111 } /* if (last_phase != P_BUSFREE).....indicates we are idle and can work */
10112 hscb_index
= aic7xxx_find_scb(p
, scb
);
10113 if (hscb_index
== SCB_LIST_NULL
)
10115 disconnected
= (aic7xxx_scb_on_qoutfifo(p
, scb
)) ? FALSE
: TRUE
;
10119 aic_outb(p
, hscb_index
, SCBPTR
);
10120 if (aic_inb(p
, SCB_CONTROL
) & DISCONNECTED
)
10122 disconnected
= TRUE
;
10128 * Simply set the MK_MESSAGE flag and the SEQINT handler will do
10129 * the rest on a reconnect.
10131 scb
->hscb
->control
|= MK_MESSAGE
;
10132 scb
->flags
|= SCB_RESET
| SCB_DEVICE_RESET
;
10133 p
->dev_flags
[TARGET_INDEX(scb
->cmd
)] &= ~DEVICE_SUCCESS
;
10134 p
->dev_flags
[TARGET_INDEX(scb
->cmd
)] |=
10135 BUS_DEVICE_RESET_PENDING
;
10136 if (hscb_index
!= SCB_LIST_NULL
)
10138 unsigned char scb_control
;
10140 aic_outb(p
, hscb_index
, SCBPTR
);
10141 scb_control
= aic_inb(p
, SCB_CONTROL
);
10142 aic_outb(p
, scb_control
| MK_MESSAGE
, SCB_CONTROL
);
10145 * Actually requeue this SCB in case we can select the
10146 * device before it reconnects. If the transaction we
10147 * want to abort is not tagged, then this will be the only
10148 * outstanding command and we can simply shove it on the
10149 * qoutfifo and be done. If it is tagged, then it goes right
10150 * in with all the others, no problem :) We need to add it
10151 * to the qinfifo and let the sequencer know it is there.
10152 * Now, the only problem left to deal with is, *IF* this
10153 * command completes, in spite of the MK_MESSAGE bit in the
10154 * control byte, then we need to pick that up in the interrupt
10155 * routine and clean things up. This *shouldn't* ever happen.
10157 if (aic7xxx_verbose
& VERBOSE_RESET_PROCESS
)
10158 printk(INFO_LEAD
"Queueing device reset "
10159 "command.\n", p
->host_no
, CTL_OF_SCB(scb
));
10160 p
->qinfifo
[p
->qinfifonext
++] = scb
->hscb
->tag
;
10161 if (p
->features
& AHC_QUEUE_REGS
)
10162 aic_outb(p
, p
->qinfifonext
, HNSCB_QOFF
);
10164 aic_outb(p
, p
->qinfifonext
, KERNEL_QINPOS
);
10165 scb
->flags
|= SCB_QUEUED_ABORT
;
10166 result
= SCSI_RESET_PENDING
;
10168 else if (result
== -1)
10170 result
= SCSI_RESET_ERROR
;
10172 aic_outb(p
, saved_scbptr
, SCBPTR
);
10177 /*+F*************************************************************************
10179 * aic7xxx_panic_abort
10182 * Abort the current SCSI command(s).
10183 *-F*************************************************************************/
10185 aic7xxx_panic_abort(struct aic7xxx_host
*p
, Scsi_Cmnd
*cmd
)
10187 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,1,0)
10188 int i
, mask
, found
, need_tag
;
10189 struct aic7xxx_scb
*scb
;
10190 unsigned char qinpos
, hscbp
;
10195 printk("aic7xxx driver version %s/%s\n", AIC7XXX_C_VERSION
,
10197 printk("Controller type:\n %s\n", board_names
[p
->board_name_index
]);
10198 printk("p->flags=0x%x, p->chip=0x%x, p->features=0x%x, "
10199 "sequencer %s paused\n",
10200 p
->flags
, p
->chip
, p
->features
,
10201 (aic_inb(p
, HCNTRL
) & PAUSE
) ? "is" : "isn't" );
10202 pause_sequencer(p
);
10203 disable_irq(p
->irq
);
10204 aic7xxx_print_card(p
);
10205 aic7xxx_print_scratch_ram(p
);
10206 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,1,0)
10207 for(i
=0; i
<MAX_TARGETS
; i
++)
10209 if(p
->dev_flags
[i
] & DEVICE_PRESENT
)
10211 mask
= (0x01 << i
);
10212 printk(INFO_LEAD
"dev_flags=0x%x, WDTR:%c/%c/%c, SDTR:%c/%c/%c,"
10213 " q_depth=%d:%d:%d\n",
10214 p
->host_no
, 0, i
, 0, p
->dev_flags
[i
],
10215 (p
->wdtr_pending
& mask
) ? 'Y' : 'N',
10216 (p
->needwdtr
& mask
) ? 'Y' : 'N',
10217 (p
->needwdtr_copy
& mask
) ? 'Y' : 'N',
10218 (p
->sdtr_pending
& mask
) ? 'Y' : 'N',
10219 (p
->needsdtr
& mask
) ? 'Y' : 'N',
10220 (p
->needsdtr_copy
& mask
) ? 'Y' : 'N',
10221 p
->dev_active_cmds
[i
],
10222 p
->dev_max_queue_depth
[i
], p
->dev_mid_level_queue_depth
[i
]);
10223 printk(INFO_LEAD
"targ_scsirate=0x%x", p
->host_no
, 0, i
, 0,
10224 aic_inb(p
, TARG_SCSIRATE
+ i
));
10225 if (p
->features
& AHC_ULTRA2
)
10226 printk(", targ_offset=%d", aic_inb(p
, TARG_OFFSET
+ i
));
10231 * Search for this command and see if we can't track it down, it's the
10232 * one causing the timeout. Print out this command first, then all other
10233 * active commands afterwords.
10238 scb
= p
->scb_data
->scb_array
[aic7xxx_position(cmd
)];
10239 if ( (scb
->flags
& SCB_ACTIVE
) && (scb
->cmd
== cmd
) )
10241 printk("Timed out command is scb #%d:\n", scb
->hscb
->tag
);
10242 printk("Tag%d: flags=0x%x, control=0x%x, TCL=0x%x, %s\n", scb
->hscb
->tag
,
10243 scb
->flags
, scb
->hscb
->control
, scb
->hscb
->target_channel_lun
,
10244 (scb
->flags
& SCB_WAITINGQ
) ? "WAITINGQ" : "Sent" );
10245 need_tag
= scb
->hscb
->tag
;
10246 if (scb
->flags
& SCB_WAITINGQ
) found
=TRUE
;
10249 printk("QINFIFO: (TAG) ");
10250 qinpos
= aic_inb(p
, QINPOS
);
10251 while ( qinpos
!= p
->qinfifonext
)
10253 if (p
->qinfifo
[qinpos
] == need_tag
)
10255 printk("%d ", p
->qinfifo
[qinpos
++]);
10258 printk("Current SCB: (SCBPTR/TAG/CONTROL) %d/%d/0x%x\n", aic_inb(p
, SCBPTR
),
10259 aic_inb(p
, SCB_TAG
), aic_inb(p
, SCB_CONTROL
) );
10260 if (aic_inb(p
, SCB_TAG
) == need_tag
) found
=TRUE
;
10261 printk("WAITING_SCBS: (SCBPTR/TAG/CONTROL) %d->",
10262 hscbp
= aic_inb(p
, WAITING_SCBH
));
10263 while (hscbp
!= SCB_LIST_NULL
)
10265 aic_outb(p
, hscbp
, SCBPTR
);
10266 printk("%d/%d/0x%x ", hscbp
, aic_inb(p
, SCB_TAG
), aic_inb(p
, SCB_CONTROL
));
10267 hscbp
= aic_inb(p
, SCB_NEXT
);
10268 if (aic_inb(p
, SCB_TAG
) == need_tag
) found
=TRUE
;
10271 printk("DISCONNECTED_SCBS: (SCBPTR/TAG/CONTROL) %d->",
10272 hscbp
= aic_inb(p
, DISCONNECTED_SCBH
));
10273 while (hscbp
!= SCB_LIST_NULL
)
10275 aic_outb(p
, hscbp
, SCBPTR
);
10276 printk("%d/%d/0x%x ", hscbp
, aic_inb(p
, SCB_TAG
), aic_inb(p
, SCB_CONTROL
));
10277 hscbp
= aic_inb(p
, SCB_NEXT
);
10278 if (aic_inb(p
, SCB_TAG
) == need_tag
) found
=TRUE
;
10281 printk("FREE_SCBS: (SCBPTR/TAG/CONTROL) %d->",
10282 hscbp
= aic_inb(p
, FREE_SCBH
));
10283 while (hscbp
!= SCB_LIST_NULL
)
10285 aic_outb(p
, hscbp
, SCBPTR
);
10286 printk("%d/%d/0x%x ", hscbp
, aic_inb(p
, SCB_TAG
), aic_inb(p
, SCB_CONTROL
));
10287 hscbp
= aic_inb(p
, SCB_NEXT
);
10291 if (found
== FALSE
)
10294 * We haven't found the offending SCB yet, and it should be around
10295 * somewhere, so go look for it in the cards SCBs.
10297 printk("SCBPTR CONTROL TAG PREV NEXT\n");
10298 for(i
=0; i
<p
->scb_data
->maxhscbs
; i
++)
10300 aic_outb(p
, i
, SCBPTR
);
10301 printk(" %3d %02x %02x %02x %02x\n", i
,
10302 aic_inb(p
, SCB_CONTROL
), aic_inb(p
, SCB_TAG
),
10303 aic_inb(p
, SCB_PREV
), aic_inb(p
, SCB_NEXT
));
10308 for (i
=0; i
< p
->scb_data
->numscbs
; i
++)
10310 scb
= p
->scb_data
->scb_array
[i
];
10311 if ( (scb
->flags
& SCB_ACTIVE
) && (scb
->cmd
!= cmd
) )
10313 printk("Tag%d: flags=0x%x, control=0x%x, TCL=0x%x, %s\n", scb
->hscb
->tag
,
10314 scb
->flags
, scb
->hscb
->control
, scb
->hscb
->target_channel_lun
,
10315 (scb
->flags
& SCB_WAITINGQ
) ? "WAITINGQ" : "Sent" );
10323 /*+F*************************************************************************
10328 * Abort the current SCSI command(s).
10329 *-F*************************************************************************/
10331 aic7xxx_abort(Scsi_Cmnd
*cmd
)
10333 struct aic7xxx_scb
*scb
= NULL
;
10334 struct aic7xxx_host
*p
;
10335 int result
, found
=0;
10336 unsigned char tmp_char
, saved_hscbptr
, next_hscbptr
, prev_hscbptr
;
10337 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,1,95)
10338 unsigned long cpu_flags
= 0;
10340 Scsi_Cmnd
*cmd_next
, *cmd_prev
;
10342 p
= (struct aic7xxx_host
*) cmd
->host
->hostdata
;
10343 scb
= (p
->scb_data
->scb_array
[aic7xxx_position(cmd
)]);
10346 * I added a new config option to the driver: "panic_on_abort" that will
10347 * cause the driver to panic and the machine to stop on the first abort
10348 * or reset call into the driver. At that point, it prints out a lot of
10349 * usefull information for me which I can then use to try and debug the
10350 * problem. Simply enable the boot time prompt in order to activate this
10353 if (aic7xxx_panic_on_abort
)
10354 aic7xxx_panic_abort(p
, cmd
);
10359 * Run the isr to grab any command in the QOUTFIFO and any other misc.
10360 * assundry tasks. This should also set up the bh handler if there is
10361 * anything to be done, but it won't run until we are done here since
10362 * we are following a straight code path without entering the scheduler
10366 pause_sequencer(p
);
10367 while ( (aic_inb(p
, INTSTAT
) & INT_PEND
) && !(p
->flags
& AHC_IN_ISR
))
10369 aic7xxx_isr(p
->irq
, p
, (void *)NULL
);
10370 pause_sequencer(p
);
10371 aic7xxx_done_cmds_complete(p
);
10374 if ((scb
== NULL
) || (cmd
->serial_number
!= cmd
->serial_number_at_timeout
))
10375 /* Totally bogus cmd since it points beyond our */
10376 { /* valid SCB range or doesn't even match it's own*/
10377 /* timeout serial number. */
10378 if (aic7xxx_verbose
& VERBOSE_ABORT_MID
)
10379 printk(INFO_LEAD
"Abort called with bogus Scsi_Cmnd "
10380 "pointer.\n", p
->host_no
, CTL_OF_CMD(cmd
));
10381 unpause_sequencer(p
, FALSE
);
10383 return(SCSI_ABORT_NOT_RUNNING
);
10385 if (scb
->cmd
!= cmd
) /* Hmmm...either this SCB is currently free with a */
10386 { /* NULL cmd pointer (NULLed out when freed) or it */
10387 /* has already been recycled for another command */
10388 /* Either way, this SCB has nothing to do with this*/
10389 /* command and we need to deal with cmd without */
10390 /* touching the SCB. */
10391 /* The theory here is to return a value that will */
10392 /* make the queued for complete command actually */
10393 /* finish successfully, or to indicate that we */
10394 /* don't have this cmd any more and the mid level */
10395 /* code needs to find it. */
10396 cmd_next
= p
->completeq
.head
;
10398 while (cmd_next
!= NULL
)
10400 if (cmd_next
== cmd
)
10402 if (aic7xxx_verbose
& VERBOSE_ABORT_PROCESS
)
10403 printk(INFO_LEAD
"Abort called for command "
10404 "on completeq, completing.\n", p
->host_no
, CTL_OF_CMD(cmd
));
10405 if ( cmd_prev
== NULL
)
10406 p
->completeq
.head
= (Scsi_Cmnd
*)cmd_next
->host_scribble
;
10408 cmd_prev
->host_scribble
= cmd_next
->host_scribble
;
10409 cmd_next
->scsi_done(cmd_next
);
10410 unpause_sequencer(p
, FALSE
);
10412 return(SCSI_ABORT_NOT_RUNNING
); /* It's already back as a successful
10415 cmd_prev
= cmd_next
;
10416 cmd_next
= (Scsi_Cmnd
*)cmd_next
->host_scribble
;
10418 if (aic7xxx_verbose
& VERBOSE_ABORT_MID
)
10419 printk(INFO_LEAD
"Abort called for already completed"
10420 " command.\n", p
->host_no
, CTL_OF_CMD(cmd
));
10421 unpause_sequencer(p
, FALSE
);
10423 return(SCSI_ABORT_NOT_RUNNING
);
10426 /* At this point we know the following:
10427 * the SCB pointer is valid
10428 * the command pointer passed in to us and the scb->cmd pointer match
10429 * this then means that the command we need to abort is the same as the
10430 * command held by the scb pointer and is a valid abort request.
10431 * Now, we just have to figure out what to do from here. Current plan is:
10432 * if we have already been here on this command, escalate to a reset
10433 * if scb is on waiting list or QINFIFO, send it back as aborted, but
10434 * we also need to be aware of the possibility that we could be using
10435 * a faked negotiation command that is holding this command up, if
10436 * so we need to take care of that command instead, which means we
10437 * would then treat this one like it was sitting around disconnected
10439 * if scb is on WAITING_SCB list in sequencer, free scb and send back
10440 * if scb is disconnected and not completed, abort with abort message
10441 * if scb is currently running, then it may be causing the bus to hang
10442 * so we want a return value that indicates a reset would be appropriate
10443 * if the command does not finish shortly
10444 * if scb is already complete but not on completeq, we're screwed because
10445 * this can't happen (except if the command is in the QOUTFIFO, in which
10446 * case we would like it to complete successfully instead of having to
10448 * All other scenarios already dealt with by previous code.
10451 if ( scb
->flags
& (SCB_ABORT
| SCB_RESET
| SCB_QUEUED_ABORT
) )
10453 if (aic7xxx_verbose
& VERBOSE_ABORT_PROCESS
)
10454 printk(INFO_LEAD
"SCB aborted once already, "
10455 "escalating.\n", p
->host_no
, CTL_OF_SCB(scb
));
10456 unpause_sequencer(p
, FALSE
);
10458 return(SCSI_ABORT_SNOOZE
);
10460 if ( (p
->flags
& (AHC_RESET_PENDING
| AHC_ABORT_PENDING
)) ||
10461 (p
->dev_flags
[TARGET_INDEX(scb
->cmd
)] &
10462 BUS_DEVICE_RESET_PENDING
) )
10464 if (aic7xxx_verbose
& VERBOSE_ABORT_PROCESS
)
10465 printk(INFO_LEAD
"Reset/Abort pending for this "
10466 "device, not wasting our time.\n", p
->host_no
, CTL_OF_SCB(scb
));
10467 unpause_sequencer(p
, FALSE
);
10469 return(SCSI_ABORT_PENDING
);
10473 p
->flags
|= AHC_IN_ABORT
;
10474 if (aic7xxx_verbose
& VERBOSE_ABORT
)
10475 printk(INFO_LEAD
"Aborting scb %d, flags 0x%x\n",
10476 p
->host_no
, CTL_OF_SCB(scb
), scb
->hscb
->tag
, scb
->flags
);
10479 * First, let's check to see if the currently running command is our target
10480 * since if it is, the return is fairly easy and quick since we don't want
10481 * to touch the command in case it might complete, but we do want a timeout
10482 * in case it's actually hung, so we really do nothing, but tell the mid
10483 * level code to reset the timeout.
10486 if ( scb
->hscb
->tag
== aic_inb(p
, SCB_TAG
) )
10489 * Check to see if the sequencer is just sitting on this command, or
10490 * if it's actively being run.
10492 result
= aic_inb(p
, LASTPHASE
);
10495 case P_DATAOUT
: /* For any of these cases, we can assume we are */
10496 case P_DATAIN
: /* an active command and act according. For */
10497 case P_COMMAND
: /* anything else we are going to fall on through*/
10498 case P_STATUS
: /* The SCSI_ABORT_SNOOZE will give us two abort */
10499 case P_MESGOUT
: /* chances to finish and then escalate to a */
10500 case P_MESGIN
: /* reset call */
10501 if (aic7xxx_verbose
& VERBOSE_ABORT_PROCESS
)
10502 printk(INFO_LEAD
"SCB is currently active. "
10503 "Waiting on completion.\n", p
->host_no
, CTL_OF_SCB(scb
));
10504 unpause_sequencer(p
, FALSE
);
10505 p
->flags
&= ~AHC_IN_ABORT
;
10506 scb
->flags
|= SCB_RECOVERY_SCB
; /* Note the fact that we've been */
10507 p
->flags
|= AHC_ABORT_PENDING
; /* here so we will know not to */
10508 DRIVER_UNLOCK
/* muck with other SCBs if this */
10509 return(SCSI_ABORT_PENDING
); /* one doesn't complete and clear */
10516 if ((found
== 0) && (scb
->flags
& SCB_WAITINGQ
))
10518 int tindex
= TARGET_INDEX(cmd
);
10519 #ifdef AIC7XXX_FAKE_NEGOTIATION_CMDS
10520 unsigned short mask
;
10522 mask
= (1 << tindex
);
10524 if (p
->wdtr_pending
& mask
)
10526 if (p
->dev_wdtr_cmnd
[tindex
]->next
!= cmd
)
10531 else if (p
->sdtr_pending
& mask
)
10533 if (p
->dev_sdtr_cmnd
[tindex
]->next
!= cmd
)
10545 * OK..this means the command we are currently getting an abort
10546 * for has an outstanding negotiation command in front of it.
10547 * We don't really have a way to tie back into the negotiation
10548 * commands, so we just send this back as pending, then it
10549 * will get reset in 2 seconds.
10551 unpause_sequencer(p
, TRUE
);
10552 scb
->flags
|= SCB_ABORT
;
10554 return(SCSI_ABORT_PENDING
);
10557 if (aic7xxx_verbose
& VERBOSE_ABORT_PROCESS
)
10558 printk(INFO_LEAD
"SCB found on waiting list and "
10559 "aborted.\n", p
->host_no
, CTL_OF_SCB(scb
));
10560 scbq_remove(&p
->waiting_scbs
, scb
);
10561 scbq_remove(&p
->delayed_scbs
[tindex
], scb
);
10562 p
->dev_active_cmds
[tindex
]++;
10564 scb
->flags
&= ~(SCB_WAITINGQ
| SCB_ACTIVE
);
10565 scb
->flags
|= SCB_ABORT
| SCB_QUEUED_FOR_DONE
;
10570 * We just checked the waiting_q, now for the QINFIFO
10574 if ( ((found
= aic7xxx_search_qinfifo(p
, cmd
->target
,
10576 cmd
->lun
, scb
->hscb
->tag
, SCB_ABORT
| SCB_QUEUED_FOR_DONE
,
10577 FALSE
, NULL
)) != 0) &&
10578 (aic7xxx_verbose
& VERBOSE_ABORT_PROCESS
))
10579 printk(INFO_LEAD
"SCB found in QINFIFO and "
10580 "aborted.\n", p
->host_no
, CTL_OF_SCB(scb
));
10584 * QINFIFO, waitingq, completeq done. Next, check WAITING_SCB list in card
10589 unsigned char scb_next_ptr
;
10590 prev_hscbptr
= SCB_LIST_NULL
;
10591 saved_hscbptr
= aic_inb(p
, SCBPTR
);
10592 next_hscbptr
= aic_inb(p
, WAITING_SCBH
);
10593 while ( next_hscbptr
!= SCB_LIST_NULL
)
10595 aic_outb(p
, next_hscbptr
, SCBPTR
);
10596 if ( scb
->hscb
->tag
== aic_inb(p
, SCB_TAG
) )
10599 if (aic7xxx_verbose
& VERBOSE_ABORT_PROCESS
)
10600 printk(INFO_LEAD
"SCB found on hardware waiting"
10601 " list and aborted.\n", p
->host_no
, CTL_OF_SCB(scb
));
10602 if ( prev_hscbptr
== SCB_LIST_NULL
)
10604 aic_outb(p
, aic_inb(p
, SCB_NEXT
), WAITING_SCBH
);
10605 /* stop the selection since we just
10606 * grabbed the scb out from under the
10609 aic_outb(p
, aic_inb(p
, SCSISEQ
) & ~ENSELO
, SCSISEQ
);
10610 aic_outb(p
, CLRSELTIMEO
, CLRSINT1
);
10614 scb_next_ptr
= aic_inb(p
, SCB_NEXT
);
10615 aic_outb(p
, prev_hscbptr
, SCBPTR
);
10616 aic_outb(p
, scb_next_ptr
, SCB_NEXT
);
10617 aic_outb(p
, next_hscbptr
, SCBPTR
);
10619 aic_outb(p
, SCB_LIST_NULL
, SCB_TAG
);
10620 aic_outb(p
, 0, SCB_CONTROL
);
10621 aic7xxx_add_curscb_to_free_list(p
);
10622 scb
->flags
= SCB_ABORT
| SCB_QUEUED_FOR_DONE
;
10625 prev_hscbptr
= next_hscbptr
;
10626 next_hscbptr
= aic_inb(p
, SCB_NEXT
);
10628 aic_outb(p
, saved_hscbptr
, SCBPTR
);
10632 * Hmmm...completeq, QOUTFIFO, QINFIFO, WAITING_SCBH, waitingq all checked.
10633 * OK...the sequencer's paused, interrupts are off, and we haven't found the
10634 * command anyplace where it could be easily aborted. Time for the hard
10635 * work. We also know the command is valid. This essentially means the
10636 * command is disconnected, or connected but not into any phases yet, which
10637 * we know due to the tests we ran earlier on the current active scb phase.
10638 * At this point we can queue the abort tag and go on with life.
10643 p
->flags
|= AHC_ABORT_PENDING
;
10644 scb
->flags
|= SCB_QUEUED_ABORT
| SCB_ABORT
| SCB_RECOVERY_SCB
;
10645 scb
->hscb
->control
|= MK_MESSAGE
;
10646 result
=aic7xxx_find_scb(p
, scb
);
10647 if ( result
!= SCB_LIST_NULL
)
10649 saved_hscbptr
= aic_inb(p
, SCBPTR
);
10650 aic_outb(p
, result
, SCBPTR
);
10651 tmp_char
= aic_inb(p
, SCB_CONTROL
);
10652 aic_outb(p
, tmp_char
| MK_MESSAGE
, SCB_CONTROL
);
10653 aic_outb(p
, saved_hscbptr
, SCBPTR
);
10655 if (aic7xxx_verbose
& VERBOSE_ABORT_PROCESS
)
10656 printk(INFO_LEAD
"SCB disconnected. Queueing Abort"
10657 " SCB.\n", p
->host_no
, CTL_OF_SCB(scb
));
10658 p
->qinfifo
[p
->qinfifonext
++] = scb
->hscb
->tag
;
10659 if (p
->features
& AHC_QUEUE_REGS
)
10660 aic_outb(p
, p
->qinfifonext
, HNSCB_QOFF
);
10662 aic_outb(p
, p
->qinfifonext
, KERNEL_QINPOS
);
10666 aic7xxx_run_done_queue(p
, TRUE
);
10667 aic7xxx_run_waiting_queues(p
);
10669 p
->flags
&= ~AHC_IN_ABORT
;
10670 unpause_sequencer(p
, FALSE
);
10674 * On the return value. If we found the command and aborted it, then we know
10675 * it's already sent back and there is no reason for a further timeout, so
10676 * we use SCSI_ABORT_SUCCESS. On the queued abort side, we aren't so certain
10677 * there hasn't been a bus hang or something that might keep the abort from
10678 * from completing. Therefore, we use SCSI_ABORT_PENDING. The first time this
10679 * is passed back, the timeout on the command gets extended, the second time
10680 * we pass this back, the mid level SCSI code calls our reset function, which
10681 * would shake loose a hung bus.
10684 return(SCSI_ABORT_SUCCESS
);
10686 return(SCSI_ABORT_PENDING
);
10690 /*+F*************************************************************************
10695 * Resetting the bus always succeeds - is has to, otherwise the
10696 * kernel will panic! Try a surgical technique - sending a BUS
10697 * DEVICE RESET message - on the offending target before pulling
10698 * the SCSI bus reset line.
10699 *-F*************************************************************************/
10701 aic7xxx_reset(Scsi_Cmnd
*cmd
, unsigned int flags
)
10703 struct aic7xxx_scb
*scb
= NULL
;
10704 struct aic7xxx_host
*p
;
10707 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,1,95)
10708 unsigned long cpu_flags
= 0;
10710 #define DEVICE_RESET 0x01
10711 #define BUS_RESET 0x02
10712 #define HOST_RESET 0x04
10714 #define RESET_DELAY 0x10
10716 Scsi_Cmnd
*cmd_prev
, *cmd_next
;
10721 printk(KERN_WARNING
"(scsi?:?:?:?) Reset called with NULL Scsi_Cmnd "
10722 "pointer, failing.\n");
10723 return(SCSI_RESET_SNOOZE
);
10726 p
= (struct aic7xxx_host
*) cmd
->host
->hostdata
;
10727 scb
= (p
->scb_data
->scb_array
[aic7xxx_position(cmd
)]);
10728 tindex
= TARGET_INDEX(cmd
);
10731 * I added a new config option to the driver: "panic_on_abort" that will
10732 * cause the driver to panic and the machine to stop on the first abort
10733 * or reset call into the driver. At that point, it prints out a lot of
10734 * usefull information for me which I can then use to try and debug the
10735 * problem. Simply enable the boot time prompt in order to activate this
10738 if (aic7xxx_panic_on_abort
)
10739 aic7xxx_panic_abort(p
, cmd
);
10743 pause_sequencer(p
);
10744 while ( (aic_inb(p
, INTSTAT
) & INT_PEND
) && !(p
->flags
& AHC_IN_ISR
))
10746 aic7xxx_isr(p
->irq
, p
, (void *)NULL
);
10747 pause_sequencer(p
);
10748 aic7xxx_done_cmds_complete(p
);
10753 if (aic7xxx_verbose
& VERBOSE_RESET_MID
)
10754 printk(INFO_LEAD
"Reset called with bogus Scsi_Cmnd"
10755 "->SCB mapping, improvising.\n", p
->host_no
, CTL_OF_CMD(cmd
));
10756 if ( flags
& SCSI_RESET_SUGGEST_HOST_RESET
)
10758 action
= HOST_RESET
;
10762 action
= BUS_RESET
;
10765 else if (scb
->cmd
!= cmd
)
10767 if (aic7xxx_verbose
& VERBOSE_RESET_MID
)
10768 printk(INFO_LEAD
"Reset called with recycled SCB "
10769 "for cmd.\n", p
->host_no
, CTL_OF_CMD(cmd
));
10771 cmd_next
= p
->completeq
.head
;
10772 while ( cmd_next
!= NULL
)
10774 if (cmd_next
== cmd
)
10776 if (aic7xxx_verbose
& VERBOSE_RESET_RETURN
)
10777 printk(INFO_LEAD
"Reset, found cmd on completeq"
10778 ", completing.\n", p
->host_no
, CTL_OF_CMD(cmd
));
10779 unpause_sequencer(p
, FALSE
);
10781 return(SCSI_RESET_NOT_RUNNING
);
10783 cmd_prev
= cmd_next
;
10784 cmd_next
= (Scsi_Cmnd
*)cmd_next
->host_scribble
;
10786 if ( !(flags
& SCSI_RESET_SYNCHRONOUS
) )
10788 if (aic7xxx_verbose
& VERBOSE_RESET_RETURN
)
10789 printk(INFO_LEAD
"Reset, cmd not found,"
10790 " failing.\n", p
->host_no
, CTL_OF_CMD(cmd
));
10791 unpause_sequencer(p
, FALSE
);
10793 return(SCSI_RESET_NOT_RUNNING
);
10797 if (aic7xxx_verbose
& VERBOSE_RESET_MID
)
10798 printk(INFO_LEAD
"Reset called, no scb, "
10799 "flags 0x%x\n", p
->host_no
, CTL_OF_CMD(cmd
), flags
);
10801 action
= HOST_RESET
;
10806 if (aic7xxx_verbose
& VERBOSE_RESET_MID
)
10807 printk(INFO_LEAD
"Reset called, scb %d, flags "
10808 "0x%x\n", p
->host_no
, CTL_OF_SCB(scb
), scb
->hscb
->tag
, scb
->flags
);
10809 if ( aic7xxx_scb_on_qoutfifo(p
, scb
) )
10811 if(aic7xxx_verbose
& VERBOSE_RESET_RETURN
)
10812 printk(INFO_LEAD
"SCB on qoutfifo, returning.\n", p
->host_no
,
10814 unpause_sequencer(p
, FALSE
);
10816 return(SCSI_RESET_NOT_RUNNING
);
10818 if ( flags
& SCSI_RESET_SUGGEST_HOST_RESET
)
10820 action
= HOST_RESET
;
10822 else if ( flags
& SCSI_RESET_SUGGEST_BUS_RESET
)
10824 action
= BUS_RESET
;
10828 action
= DEVICE_RESET
;
10831 if ( (action
& DEVICE_RESET
) &&
10832 (p
->dev_flags
[tindex
] & BUS_DEVICE_RESET_PENDING
) )
10834 if (aic7xxx_verbose
& VERBOSE_RESET_PROCESS
)
10835 printk(INFO_LEAD
"Bus device reset already sent to "
10836 "device, escalating.\n", p
->host_no
, CTL_OF_CMD(cmd
));
10837 action
= BUS_RESET
;
10839 if ( (action
& DEVICE_RESET
) &&
10840 (scb
->flags
& SCB_QUEUED_ABORT
) )
10842 if (aic7xxx_verbose
& VERBOSE_RESET_PROCESS
)
10844 printk(INFO_LEAD
"Have already attempted to reach "
10845 "device with queued\n", p
->host_no
, CTL_OF_CMD(cmd
));
10846 printk(INFO_LEAD
"message, will escalate to bus "
10847 "reset.\n", p
->host_no
, CTL_OF_CMD(cmd
));
10849 action
= BUS_RESET
;
10851 if ( (action
& DEVICE_RESET
) &&
10852 (p
->flags
& (AHC_RESET_PENDING
| AHC_ABORT_PENDING
)) )
10854 if (aic7xxx_verbose
& VERBOSE_RESET_PROCESS
)
10855 printk(INFO_LEAD
"Bus device reset stupid when "
10856 "other action has failed.\n", p
->host_no
, CTL_OF_CMD(cmd
));
10857 action
= BUS_RESET
;
10859 if ( (action
& BUS_RESET
) && !(p
->features
& AHC_TWIN
) )
10861 action
= HOST_RESET
;
10863 if ( ((jiffies
- p
->dev_last_reset
[tindex
]) < (HZ
* 3)) &&
10864 !(action
& (HOST_RESET
| BUS_RESET
)))
10866 if (aic7xxx_verbose
& VERBOSE_RESET_PROCESS
)
10868 printk(INFO_LEAD
"Reset called too soon after last "
10869 "reset without requesting\n", p
->host_no
, CTL_OF_CMD(cmd
));
10870 printk(INFO_LEAD
"bus or host reset, escalating.\n", p
->host_no
,
10873 action
= BUS_RESET
;
10875 if ( ((jiffies
- p
->last_reset
) < (HZ
* 3)) &&
10876 (action
& (HOST_RESET
| BUS_RESET
)) )
10878 if (aic7xxx_verbose
& VERBOSE_RESET_PROCESS
)
10879 printk(INFO_LEAD
"Reset called too soon after "
10880 "last bus reset, delaying.\n", p
->host_no
, CTL_OF_CMD(cmd
));
10881 action
= RESET_DELAY
;
10883 if ( (action
& (BUS_RESET
| HOST_RESET
)) && (p
->flags
& AHC_IN_RESET
)
10884 && ((jiffies
- p
->reset_start
) > (2 * HZ
* 3)) )
10886 printk(KERN_ERR
"(scsi%d:%d:%d:%d) Yikes!! Card must have left to go "
10887 "back to Adaptec!!\n", p
->host_no
, CTL_OF_CMD(cmd
));
10888 unpause_sequencer(p
, FALSE
);
10890 return(SCSI_RESET_SNOOZE
);
10893 * By this point, we want to already know what we are going to do and
10894 * only have the following code implement our course of action.
10899 unpause_sequencer(p
, FALSE
);
10901 return(SCSI_RESET_PENDING
);
10904 unpause_sequencer(p
, FALSE
);
10906 return(SCSI_RESET_ERROR
);
10909 p
->flags
|= AHC_IN_RESET
;
10910 result
= aic7xxx_bus_device_reset(p
, cmd
);
10911 aic7xxx_run_done_queue(p
, TRUE
);
10912 /* We can't rely on run_waiting_queues to unpause the sequencer for
10913 * PCI based controllers since we use AAP */
10914 aic7xxx_run_waiting_queues(p
);
10915 unpause_sequencer(p
, FALSE
);
10916 p
->flags
&= ~AHC_IN_RESET
;
10923 p
->reset_start
= jiffies
;
10924 p
->flags
|= AHC_IN_RESET
;
10925 aic7xxx_reset_channel(p
, cmd
->channel
, TRUE
);
10926 if ( (p
->features
& AHC_TWIN
) && (action
& HOST_RESET
) )
10928 aic7xxx_reset_channel(p
, cmd
->channel
^ 0x01, TRUE
);
10929 restart_sequencer(p
);
10931 p
->last_reset
= jiffies
;
10932 if (action
!= HOST_RESET
)
10933 result
= SCSI_RESET_SUCCESS
| SCSI_RESET_BUS_RESET
;
10936 result
= SCSI_RESET_SUCCESS
| SCSI_RESET_HOST_RESET
;
10937 aic_outb(p
, aic_inb(p
, SIMODE1
) & ~(ENREQINIT
|ENBUSFREE
),
10939 aic7xxx_clear_intstat(p
);
10940 p
->flags
&= ~AHC_HANDLING_REQINITS
;
10941 p
->msg_type
= MSG_TYPE_NONE
;
10945 aic7xxx_run_done_queue(p
, TRUE
);
10946 p
->flags
&= ~AHC_IN_RESET
;
10947 /* We can't rely on run_waiting_queues to unpause the sequencer for
10948 * PCI based controllers since we use AAP */
10949 aic7xxx_run_waiting_queues(p
);
10950 unpause_sequencer(p
, FALSE
);
10957 /*+F*************************************************************************
10959 * aic7xxx_biosparam
10962 * Return the disk geometry for the given SCSI device.
10963 *-F*************************************************************************/
10965 aic7xxx_biosparam(Disk
*disk
, kdev_t dev
, int geom
[])
10967 int heads
, sectors
, cylinders
;
10968 struct aic7xxx_host
*p
;
10970 p
= (struct aic7xxx_host
*) disk
->device
->host
->hostdata
;
10973 * XXX - if I could portably find the card's configuration
10974 * information, then this could be autodetected instead
10975 * of left to a boot-time switch.
10979 cylinders
= disk
->capacity
/ (heads
* sectors
);
10981 if ((p
->flags
& AHC_EXTEND_TRANS_A
) && (cylinders
> 1024))
10985 cylinders
= disk
->capacity
/ (heads
* sectors
);
10990 geom
[2] = cylinders
;
10995 /*+F*************************************************************************
11000 * Free the passed in Scsi_Host memory structures prior to unloading the
11002 *-F*************************************************************************/
11004 aic7xxx_release(struct Scsi_Host
*host
)
11006 struct aic7xxx_host
*p
= (struct aic7xxx_host
*) host
->hostdata
;
11007 struct aic7xxx_host
*next
, *prev
;
11010 free_irq(p
->irq
, p
);
11011 release_region(p
->base
, MAXREG
- MINREG
);
11015 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,1,0)
11016 vfree((void *) (((unsigned long) p
->maddr
) & PAGE_MASK
));
11018 iounmap((void *) (((unsigned long) p
->maddr
) & PAGE_MASK
));
11021 #endif /* MMAPIO */
11023 next
= first_aic7xxx
;
11024 while(next
!= NULL
)
11029 first_aic7xxx
= next
->next
;
11031 prev
->next
= next
->next
;
11043 /*+F*************************************************************************
11045 * aic7xxx_print_card
11048 * Print out all of the control registers on the card
11050 * NOTE: This function is not yet safe for use on the VLB and EISA
11051 * controllers, so it isn't used on those controllers at all.
11052 *-F*************************************************************************/
11054 aic7xxx_print_card(struct aic7xxx_host
*p
)
11057 static struct register_ranges
{
11061 { 0, {0,} }, /* none */
11062 {10, {0x00, 0x05, 0x08, 0x11, 0x18, 0x19, 0x1f, 0x1f, 0x60, 0x60, /*7771*/
11063 0x62, 0x66, 0x80, 0x8e, 0x90, 0x95, 0x97, 0x97, 0x9b, 0x9f} },
11064 { 9, {0x00, 0x05, 0x08, 0x11, 0x18, 0x1f, 0x60, 0x60, 0x62, 0x66, /*7850*/
11065 0x80, 0x8e, 0x90, 0x95, 0x97, 0x97, 0x9a, 0x9f} },
11066 { 9, {0x00, 0x05, 0x08, 0x11, 0x18, 0x1f, 0x60, 0x60, 0x62, 0x66, /*7860*/
11067 0x80, 0x8e, 0x90, 0x95, 0x97, 0x97, 0x9a, 0x9f} },
11068 {10, {0x00, 0x05, 0x08, 0x11, 0x18, 0x19, 0x1c, 0x1f, 0x60, 0x60, /*7870*/
11069 0x62, 0x66, 0x80, 0x8e, 0x90, 0x95, 0x97, 0x97, 0x9a, 0x9f} },
11070 {10, {0x00, 0x05, 0x08, 0x11, 0x18, 0x1a, 0x1c, 0x1f, 0x60, 0x60, /*7880*/
11071 0x62, 0x66, 0x80, 0x8e, 0x90, 0x95, 0x97, 0x97, 0x9a, 0x9f} },
11072 {16, {0x00, 0x05, 0x08, 0x11, 0x18, 0x1f, 0x60, 0x60, 0x62, 0x66, /*7890*/
11073 0x84, 0x8e, 0x90, 0x95, 0x97, 0x97, 0x9a, 0x9a, 0x9f, 0x9f,
11074 0xe0, 0xf1, 0xf4, 0xf4, 0xf6, 0xf6, 0xf8, 0xf8, 0xfa, 0xfc,
11076 {12, {0x00, 0x05, 0x08, 0x11, 0x18, 0x19, 0x1b, 0x1f, 0x60, 0x60, /*7895*/
11077 0x62, 0x66, 0x80, 0x8e, 0x90, 0x95, 0x97, 0x97, 0x9a, 0x9a,
11078 0x9f, 0x9f, 0xe0, 0xf1} },
11079 {16, {0x00, 0x05, 0x08, 0x11, 0x18, 0x1f, 0x60, 0x60, 0x62, 0x66, /*7896*/
11080 0x84, 0x8e, 0x90, 0x95, 0x97, 0x97, 0x9a, 0x9a, 0x9f, 0x9f,
11081 0xe0, 0xf1, 0xf4, 0xf4, 0xf6, 0xf6, 0xf8, 0xf8, 0xfa, 0xfc,
11085 static struct register_ranges cards_ns
[] = {
11086 { 0, {0,} }, /* none */
11087 { 0, {0,} }, /* 7771 */
11088 { 7, {0x04, 0x08, 0x0c, 0x0e, 0x10, 0x17, 0x28, 0x2b, 0x30, 0x33,
11089 0x3c, 0x41, 0x43, 0x47} },
11090 { 7, {0x04, 0x08, 0x0c, 0x0e, 0x10, 0x17, 0x28, 0x2b, 0x30, 0x33,
11091 0x3c, 0x41, 0x43, 0x47} },
11092 { 5, {0x04, 0x08, 0x0c, 0x0e, 0x10, 0x17, 0x30, 0x33, 0x3c, 0x41} },
11093 { 5, {0x04, 0x08, 0x0c, 0x0e, 0x10, 0x17, 0x30, 0x34, 0x3c, 0x47} },
11094 { 5, {0x04, 0x08, 0x0c, 0x1b, 0x30, 0x34, 0x3c, 0x43, 0xdc, 0xe3} },
11095 { 6, {0x04, 0x08, 0x0c, 0x0e, 0x10, 0x17, 0x30, 0x34, 0x3c, 0x47,
11097 { 6, {0x04, 0x08, 0x0c, 0x1b, 0x30, 0x34, 0x3c, 0x43, 0xdc, 0xe3,
11101 chip
= p
->chip
& AHC_CHIPID_MASK
;
11103 * Let's run through the PCI space first....
11106 board_names
[p
->board_name_index
]);
11107 switch(p
->chip
& ~AHC_CHIPID_MASK
)
11110 printk("VLB Slot %d.\n", p
->pci_device_fn
);
11113 printk("EISA Slot %d.\n", p
->pci_device_fn
);
11117 printk("PCI %d/%d.\n", PCI_SLOT(p
->pci_device_fn
),
11118 PCI_FUNC(p
->pci_device_fn
));
11124 unsigned char temp
;
11126 printk("PCI Dump:\n");
11128 for(i
=0; i
<cards_ns
[chip
].num_ranges
; i
++)
11130 for(j
= cards_ns
[chip
].range_val
[ i
* 2 ];
11131 j
<= cards_ns
[chip
].range_val
[ i
* 2 + 1 ] ;
11134 #if LINUX_VERSION_CODE > KERNEL_VERSION(2,1,92)
11135 pci_read_config_byte(p
->pdev
, j
, &temp
);
11137 pcibios_read_config_byte(p
->pci_bus
, p
->pci_device_fn
, j
, &temp
);
11139 printk("%02x:%02x ", j
, temp
);
11150 #endif /* CONFIG_PCI */
11153 * Now the registers on the card....
11155 printk("Card Dump:\n");
11157 for(i
=0; i
<cards_ds
[chip
].num_ranges
; i
++)
11159 for(j
= cards_ds
[chip
].range_val
[ i
* 2 ];
11160 j
<= cards_ds
[chip
].range_val
[ i
* 2 + 1 ] ;
11163 printk("%02x:%02x ", j
, aic_inb(p
, j
));
11173 if (p
->flags
& AHC_SEEPROM_FOUND
)
11175 unsigned short *sc1
;
11176 sc1
= (unsigned short *)&p
->sc
;
11178 printk("SEEPROM dump.\n");
11179 for(i
=1; i
<=32; i
++)
11181 printk("0x%04x", sc1
[i
-1]);
11182 if ( (i
% 8) == 0 )
11190 * If this was an Ultra2 controller, then we just hosed the card in terms
11191 * of the QUEUE REGS. This function is only called at init time or by
11192 * the panic_abort function, so it's safe to assume a generic init time
11196 if(p
->features
& AHC_QUEUE_REGS
)
11198 aic_outb(p
, 0, SDSCB_QOFF
);
11199 aic_outb(p
, 0, SNSCB_QOFF
);
11200 aic_outb(p
, 0, HNSCB_QOFF
);
11205 /*+F*************************************************************************
11207 * aic7xxx_print_scratch_ram
11210 * Print out the scratch RAM values on the card.
11211 *-F*************************************************************************/
11213 aic7xxx_print_scratch_ram(struct aic7xxx_host
*p
)
11218 printk("Scratch RAM:\n");
11219 for(i
= SRAM_BASE
; i
< SEQCTL
; i
++)
11221 printk("%02x:%02x ", i
, aic_inb(p
, i
));
11228 if (p
->features
& AHC_MORE_SRAM
)
11230 for(i
= TARG_OFFSET
; i
< 0x80; i
++)
11232 printk("%02x:%02x ", i
, aic_inb(p
, i
));
11244 #include "aic7xxx_proc.c"
11247 /* Eventually this will go into an include file, but this will be later */
11248 Scsi_Host_Template driver_template
= AIC7XXX
;
11250 #include "scsi_module.c"
11254 * Overrides for Emacs so that we almost follow Linus's tabbing style.
11255 * Emacs will notice this stuff at the end of the file and automatically
11256 * adjust the settings for this buffer only. This must remain at the end
11258 * ---------------------------------------------------------------------------
11260 * c-indent-level: 2
11261 * c-brace-imaginary-offset: 0
11262 * c-brace-offset: -2
11263 * c-argdecl-indent: 2
11264 * c-label-offset: -2
11265 * c-continued-statement-offset: 2
11266 * c-continued-brace-offset: 0
11267 * indent-tabs-mode: nil