|
|
1.1 root 1: /*+M*************************************************************************
2: * Adaptec AIC7xxx device driver for Linux.
3: *
4: * Copyright (c) 1994 John Aycock
5: * The University of Calgary Department of Computer Science.
6: *
7: * This program is free software; you can redistribute it and/or modify
8: * it under the terms of the GNU General Public License as published by
9: * the Free Software Foundation; either version 2, or (at your option)
10: * any later version.
11: *
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.
16: *
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.
20: *
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), ...
29: *
30: * --------------------------------------------------------------------------
31: *
32: * Modifications by Daniel M. Eischen ([email protected]):
33: *
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.
37: *
38: * Parts of this driver were also based on the FreeBSD driver by
39: * Justin T. Gibbs. His copyright follows:
40: *
41: * --------------------------------------------------------------------------
42: * Copyright (c) 1994-1997 Justin Gibbs.
43: * All rights reserved.
44: *
45: * Redistribution and use in source and binary forms, with or without
46: * modification, are permitted provided that the following conditions
47: * are met:
48: * 1. Redistributions of source code must retain the above copyright
49: * notice, this list of conditions, and the following disclaimer,
50: * without modification, immediately at the beginning of the file.
51: * 2. Redistributions in binary form must reproduce the above copyright
52: * notice, this list of conditions and the following disclaimer in the
53: * documentation and/or other materials provided with the distribution.
54: * 3. The name of the author may not be used to endorse or promote products
55: * derived from this software without specific prior written permission.
56: *
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.
63: *
64: * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
65: * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
66: * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
67: * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
68: * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
69: * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
70: * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
71: * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
72: * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
73: * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
74: * SUCH DAMAGE.
75: *
76: * $Id: aic7xxx.c,v 1.1 1999/04/26 05:54:15 tb Exp $
77: *---------------------------------------------------------------------------
78: *
79: * Thanks also go to (in alphabetical order) the following:
80: *
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
85: *
86: * A Boot time option was also added for not resetting the scsi bus.
87: *
88: * Form: aic7xxx=extended
89: * aic7xxx=no_reset
90: * aic7xxx=ultra
91: * aic7xxx=irq_trigger:[0,1] # 0 edge, 1 level
92: * aic7xxx=verbose
93: *
94: * Daniel M. Eischen, [email protected], 1/23/97
95: *
96: * $Id: aic7xxx.c,v 1.1 1999/04/26 05:54:15 tb Exp $
97: *-M*************************************************************************/
98:
99: /*+M**************************************************************************
100: *
101: * Further driver modifications made by Doug Ledford <[email protected]>
102: *
103: * Copyright (c) 1997-1998 Doug Ledford
104: *
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.
109: *
110: * Modifications made to the aic7xxx.c,v 4.1 driver from Dan Eischen include
111: * but are not limited to:
112: *
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
122: *
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.
137: *
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.
157: *
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 :)
163: *
164: *_M*************************************************************************/
165:
166: /*
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.
171: */
172:
173: /*
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:
178: *
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
187: * overlapping.
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.
199: *
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
240: * viable.
241: *
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
247: * big con I listed.
248: *
249: * -- July 7, 02:33
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
253: * it goes.
254: */
255:
256: #define AIC7XXX_FAKE_NEGOTIATION_CMDS
257:
258: /*
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.
272: *
273: * -- July 7, 17:09
274: * OK...I need this on my machine for testing, so the default is to
275: * leave it defined.
276: *
277: * -- July 7, 18:49
278: * I needed it for testing, but it didn't make any difference, so back
279: * off she goes.
280: *
281: * -- July 16, 23:04
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
284: * things itself.
285: */
286:
287: #define AIC7XXX_STRICT_PCI_SETUP
288:
289: /*
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.
296: *
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.
301: */
302:
303: /*
304: * #define AIC7XXX_VERBOSE_DEBUGGING
305: */
306:
307: #if defined(MODULE) || defined(PCMCIA)
308: #include <linux/module.h>
309: #endif
310:
311: #if defined(PCMCIA)
312: # undef MODULE
313: #endif
314:
315: #include <stdarg.h>
316: #include <asm/io.h>
317: #include <asm/irq.h>
318: #include <asm/byteorder.h>
319: #include <linux/version.h>
320: #include <linux/string.h>
321: #include <linux/errno.h>
322: #include <linux/kernel.h>
323: #include <linux/ioport.h>
324: #include <linux/delay.h>
325: #include <linux/sched.h>
326: #include <linux/pci.h>
327: #include <linux/proc_fs.h>
328: #include <linux/blk.h>
329: #include <linux/tqueue.h>
330: #include <linux/tasks.h>
331: #include "sd.h"
332: #include "scsi.h"
333: #include "hosts.h"
334: #include "aic7xxx.h"
335:
336: #include "aic7xxx/sequencer.h"
337: #include "aic7xxx/scsi_message.h"
338: #include "aic7xxx_reg.h"
339:
340: #include <linux/stat.h>
341: #include <linux/malloc.h> /* for kmalloc() */
342:
343: #include <linux/config.h> /* for CONFIG_PCI */
344:
345: /*
346: * To generate the correct addresses for the controller to issue
347: * on the bus. Originally added for DEC Alpha support.
348: */
349: #define VIRT_TO_BUS(a) (unsigned int)virt_to_bus((void *)(a))
350:
351: struct proc_dir_entry proc_scsi_aic7xxx = {
352: PROC_SCSI_AIC7XXX, 7, "aic7xxx",
353: S_IFDIR | S_IRUGO | S_IXUGO, 2,
354: 0, 0, 0, NULL, NULL, NULL, NULL, NULL, NULL, NULL
355: };
356:
357: #define AIC7XXX_C_VERSION "5.1.4"
358:
359: #define NUMBER(arr) (sizeof(arr) / sizeof(arr[0]))
360: #define MIN(a,b) (((a) < (b)) ? (a) : (b))
361: #define MAX(a,b) (((a) > (b)) ? (a) : (b))
362: #define ALL_TARGETS -1
363: #define ALL_CHANNELS -1
364: #define ALL_LUNS -1
365: #define MAX_TARGETS 16
366: #define MAX_LUNS 8
367: #ifndef TRUE
368: # define TRUE 1
369: #endif
370: #ifndef FALSE
371: # define FALSE 0
372: #endif
373:
374: #ifndef KERNEL_VERSION
375: # define KERNEL_VERSION(x,y,z) (((x)<<16)+((y)<<8)+(z))
376: #endif
377:
378: /*
379: * We need the bios32.h file if we are kernel version 2.1.92 or less. The
380: * full set of pci_* changes wasn't in place until 2.1.93
381: */
382:
383: #if LINUX_VERSION_CODE <= KERNEL_VERSION(2,1,92)
384: # if defined(__sparc_v9__) || defined(__powerpc__)
385: # error "PPC and Sparc platforms are only support under 2.1.92 and above"
386: # endif
387: # include <linux/bios32.h>
388: #endif
389:
390: #if defined(__powerpc__)
391: # define MMAPIO
392: # ifdef mb
393: # undef mb
394: # endif
395: # define mb() \
396: __asm__ __volatile__("eieio" ::: "memory")
397: #elif defined(__i386__)
398: # define MMAPIO
399: # ifdef mb
400: # undef mb
401: # endif
402: # define mb() \
403: __asm__ __volatile__("lock ; addl $0,0(%%esp)": : :"memory")
404: #elif defined(__alpha__)
405: # ifdef mb
406: # undef mb
407: # endif
408: # define mb() \
409: __asm__ __volatile__("mb": : :"memory")
410: #endif
411:
412: #if LINUX_VERSION_CODE > KERNEL_VERSION(2,1,0)
413: # include <asm/spinlock.h>
414: # include <linux/smp.h>
415: # define cpuid smp_processor_id()
416: # if LINUX_VERSION_CODE < KERNEL_VERSION(2,1,95)
417: # define DRIVER_LOCK_INIT \
418: spin_lock_init(&p->spin_lock);
419: # define DRIVER_LOCK \
420: if(!p->cpu_lock_count[cpuid]) { \
421: spin_lock_irqsave(&p->spin_lock, cpu_flags); \
422: p->cpu_lock_count[cpuid]++; \
423: } else { \
424: p->cpu_lock_count[cpuid]++; \
425: }
426: # define DRIVER_UNLOCK \
427: if(--p->cpu_lock_count[cpuid] == 0) \
428: spin_unlock_irqrestore(&p->spin_lock, cpu_flags);
429: # else
430: # define DRIVER_LOCK_INIT
431: # define DRIVER_LOCK
432: # define DRIVER_UNLOCK
433: # endif
434: #else
435: # define cpuid 0
436: # define DRIVER_LOCK_INIT
437: # define DRIVER_LOCK \
438: save_flags(cpu_flags); \
439: cli();
440: # define DRIVER_UNLOCK \
441: restore_flags(cpu_flags);
442: # define le32_to_cpu(x) (x)
443: # define cpu_to_le32(x) (x)
444: #endif
445:
446: /*
447: * You can try raising me if tagged queueing is enabled, or lowering
448: * me if you only have 4 SCBs.
449: */
450: #ifdef CONFIG_AIC7XXX_CMDS_PER_LUN
451: #define AIC7XXX_CMDS_PER_LUN CONFIG_AIC7XXX_CMDS_PER_LUN
452: #endif
453:
454: /* Set this to the delay in seconds after SCSI bus reset. */
455: #ifdef CONFIG_AIC7XXX_RESET_DELAY
456: #define AIC7XXX_RESET_DELAY CONFIG_AIC7XXX_RESET_DELAY
457: #else
458: #define AIC7XXX_RESET_DELAY 5
459: #endif
460:
461: /*
462: * Control collection of SCSI transfer statistics for the /proc filesystem.
463: *
464: * NOTE: Do NOT enable this when running on kernels version 1.2.x and below.
465: * NOTE: This does affect performance since it has to maintain statistics.
466: */
467: #ifdef CONFIG_AIC7XXX_PROC_STATS
468: #define AIC7XXX_PROC_STATS
469: #endif
470:
471: /*
472: * NOTE: Uncommenting the define below no longer has any effect, the
473: * tagged queue value array is always active now. I've added
474: * a setup option to set this particular array and I'm hoping
475: * insmod will be smart enough to set it properly as well. It's
476: * by use of this array that a person can enable tagged queueing.
477: * The DEFAULT_TAG_COMMANDS define has been changed to disable
478: * tagged queueing by default, so if your devices can handle tagged
479: * queueing you will need to add a line to their lilo.conf file like:
480: * append="aic7xxx=verbose,tag_info:{{32,32,32,32},{32,32,32,32}}"
481: * which will result in the first four devices on the first two
482: * controllers being set to a tagged queue depth of 32.
483: *
484: * Set this for defining the number of tagged commands on a device
485: * by device, and controller by controller basis. The first set
486: * of tagged commands will be used for the first detected aic7xxx
487: * controller, the second set will be used for the second detected
488: * aic7xxx controller, and so on. These values will *only* be used
489: * for targets that are tagged queueing capable; these values will
490: * be ignored in all other cases. The tag_commands is an array of
491: * 16 to allow for wide and twin adapters. Twin adapters will use
492: * indexes 0-7 for channel 0, and indexes 8-15 for channel 1.
493: *
494: * *** Determining commands per LUN ***
495: *
496: * When AIC7XXX_CMDS_PER_LUN is not defined, the driver will use its
497: * own algorithm to determine the commands/LUN. If SCB paging is
498: * enabled, which is always now, the default is 8 commands per lun
499: * that indicates it supports tagged queueing. All non-tagged devices
500: * use an internal queue depth of 3, with no more than one of those
501: * three commands active at one time.
502: */
503: /* #define AIC7XXX_TAGGED_QUEUEING_BY_DEVICE */
504:
505: typedef struct
506: {
507: unsigned char tag_commands[16]; /* Allow for wide/twin adapters. */
508: } adapter_tag_info_t;
509:
510: /*
511: * Make a define that will tell the driver not to use tagged queueing
512: * by default.
513: */
514: #define DEFAULT_TAG_COMMANDS {255, 255, 255, 255, 255, 255, 255, 255,\
515: 255, 255, 255, 255, 255, 255, 255, 255}
516:
517: /*
518: * Modify this as you see fit for your system. By setting tag_commands
519: * to 0, the driver will use it's own algorithm for determining the
520: * number of commands to use (see above). When 255, the driver will
521: * not enable tagged queueing for that particular device. When positive
522: * (> 0) and (< 255) the values in the array are used for the queue_depth.
523: * Note that the maximum value for an entry is 254, but you're insane if
524: * you try to use that many commands on one device.
525: *
526: * In this example, the first line will disable tagged queueing for all
527: * the devices on the first probed aic7xxx adapter.
528: *
529: * The second line enables tagged queueing with 4 commands/LUN for IDs
530: * (1, 2-11, 13-15), disables tagged queueing for ID 12, and tells the
531: * driver to use its own algorithm for ID 1.
532: *
533: * The third line is the same as the first line.
534: *
535: * The fourth line disables tagged queueing for devices 0 and 3. It
536: * enables tagged queueing for the other IDs, with 16 commands/LUN
537: * for IDs 1 and 4, 127 commands/LUN for ID 8, and 4 commands/LUN for
538: * IDs 2, 5-7, and 9-15.
539: */
540:
541: /*
542: * NOTE: The below structure is for reference only, the actual structure
543: * to modify in order to change things is located around line
544: * number 1305
545: adapter_tag_info_t aic7xxx_tag_info[] =
546: {
547: {DEFAULT_TAG_COMMANDS},
548: {{4, 0, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 255, 4, 4, 4}},
549: {DEFAULT_TAG_COMMANDS},
550: {{255, 16, 4, 255, 16, 4, 4, 4, 127, 4, 4, 4, 4, 4, 4, 4}}
551: };
552: */
553:
554: /*
555: * Define an array of board names that can be indexed by aha_type.
556: * Don't forget to change this when changing the types!
557: */
558: static const char *board_names[] = {
559: "AIC-7xxx Unknown", /* AIC_NONE */
560: "Adaptec AIC-7810 Hardware RAID Controller", /* AIC_7810 */
561: "Adaptec AIC-7770 SCSI host adapter", /* AIC_7770 */
562: "Adaptec AHA-274X SCSI host adapter", /* AIC_7771 */
563: "Adaptec AHA-284X SCSI host adapter", /* AIC_284x */
564: "Adaptec AIC-7850 SCSI host adapter", /* AIC_7850 */
565: "Adaptec AIC-7855 SCSI host adapter", /* AIC_7855 */
566: "Adaptec AIC-7860 Ultra SCSI host adapter", /* AIC_7860 */
567: "Adaptec AHA-2940A Ultra SCSI host adapter", /* AIC_7861 */
568: "Adaptec AIC-7870 SCSI host adapter", /* AIC_7870 */
569: "Adaptec AHA-294X SCSI host adapter", /* AIC_7871 */
570: "Adaptec AHA-394X SCSI host adapter", /* AIC_7872 */
571: "Adaptec AHA-398X SCSI host adapter", /* AIC_7873 */
572: "Adaptec AHA-2944 SCSI host adapter", /* AIC_7874 */
573: "Adaptec AIC-7880 Ultra SCSI host adapter", /* AIC_7880 */
574: "Adaptec AHA-294X Ultra SCSI host adapter", /* AIC_7881 */
575: "Adaptec AHA-394X Ultra SCSI host adapter", /* AIC_7882 */
576: "Adaptec AHA-398X Ultra SCSI host adapter", /* AIC_7883 */
577: "Adaptec AHA-2944 Ultra SCSI host adapter", /* AIC_7884 */
578: "Adaptec AIC-7895 Ultra SCSI host adapter", /* AIC_7895 */
579: "Adaptec AIC-7890/1 Ultra2 SCSI host adapter", /* AIC_7890 */
580: "Adaptec AHA-294X Ultra2 SCSI host adapter", /* AIC_7890 */
581: "Adaptec AIC-7896/7 Ultra2 SCSI host adapter", /* AIC_7896 */
582: "Adaptec AHA-394X Ultra2 SCSI host adapter" /* AIC_7897 */
583: };
584:
585: /*
586: * There should be a specific return value for this in scsi.h, but
587: * it seems that most drivers ignore it.
588: */
589: #define DID_UNDERFLOW DID_ERROR
590:
591: /*
592: * What we want to do is have the higher level scsi driver requeue
593: * the command to us. There is no specific driver status for this
594: * condition, but the higher level scsi driver will requeue the
595: * command on a DID_BUS_BUSY error.
596: *
597: * Upon further inspection and testing, it seems that DID_BUS_BUSY
598: * will *always* retry the command. We can get into an infinite loop
599: * if this happens when we really want some sort of counter that
600: * will automatically abort/reset the command after so many retries.
601: * Using DID_ERROR will do just that. (Made by a suggestion by
602: * Doug Ledford 8/1/96)
603: */
604: #define DID_RETRY_COMMAND DID_ERROR
605:
606: #define HSCSIID 0x07
607: #define SCSI_RESET 0x040
608:
609: /*
610: * EISA/VL-bus stuff
611: */
612: #define MINSLOT 1
613: #define MAXSLOT 15
614: #define SLOTBASE(x) ((x) << 12)
615: #define BASE_TO_SLOT(x) ((x) >> 12)
616:
617: /*
618: * Standard EISA Host ID regs (Offset from slot base)
619: */
620: #define AHC_HID0 0x80 /* 0,1: msb of ID2, 2-7: ID1 */
621: #define AHC_HID1 0x81 /* 0-4: ID3, 5-7: LSB ID2 */
622: #define AHC_HID2 0x82 /* product */
623: #define AHC_HID3 0x83 /* firmware revision */
624:
625: /*
626: * AIC-7770 I/O range to reserve for a card
627: */
628: #define MINREG 0xC00
629: #define MAXREG 0xCBF
630:
631: #define INTDEF 0x5C /* Interrupt Definition Register */
632:
633: /*
634: * AIC-78X0 PCI registers
635: */
636: #define CLASS_PROGIF_REVID 0x08
637: #define DEVREVID 0x000000FFul
638: #define PROGINFC 0x0000FF00ul
639: #define SUBCLASS 0x00FF0000ul
640: #define BASECLASS 0xFF000000ul
641:
642: #define CSIZE_LATTIME 0x0C
643: #define CACHESIZE 0x0000003Ful /* only 5 bits */
644: #define LATTIME 0x0000FF00ul
645:
646: #define DEVCONFIG 0x40
647: #define SCBSIZE32 0x00010000ul /* aic789X only */
648: #define MPORTMODE 0x00000400ul /* aic7870 only */
649: #define RAMPSM 0x00000200ul /* aic7870 only */
650: #define RAMPSM_ULTRA2 0x00000004
651: #define VOLSENSE 0x00000100ul
652: #define SCBRAMSEL 0x00000080ul
653: #define SCBRAMSEL_ULTRA2 0x00000008
654: #define MRDCEN 0x00000040ul
655: #define EXTSCBTIME 0x00000020ul /* aic7870 only */
656: #define EXTSCBPEN 0x00000010ul /* aic7870 only */
657: #define BERREN 0x00000008ul
658: #define DACEN 0x00000004ul
659: #define STPWLEVEL 0x00000002ul
660: #define DIFACTNEGEN 0x00000001ul /* aic7870 only */
661:
662: #define SCAMCTL 0x1a /* Ultra2 only */
663: #define CCSCBBADDR 0xf0 /* aic7895/6/7 */
664:
665: /*
666: * Define the different types of SEEPROMs on aic7xxx adapters
667: * and make it also represent the address size used in accessing
668: * its registers. The 93C46 chips have 1024 bits organized into
669: * 64 16-bit words, while the 93C56 chips have 2048 bits organized
670: * into 128 16-bit words. The C46 chips use 6 bits to address
671: * each word, while the C56 and C66 (4096 bits) use 8 bits to
672: * address each word.
673: */
674: typedef enum {C46 = 6, C56_66 = 8} seeprom_chip_type;
675:
676: /*
677: *
678: * Define the format of the SEEPROM registers (16 bits).
679: *
680: */
681: struct seeprom_config {
682:
683: /*
684: * SCSI ID Configuration Flags
685: */
686: #define CFXFER 0x0007 /* synchronous transfer rate */
687: #define CFSYNCH 0x0008 /* enable synchronous transfer */
688: #define CFDISC 0x0010 /* enable disconnection */
689: #define CFWIDEB 0x0020 /* wide bus device (wide card) */
690: #define CFSYNCHISULTRA 0x0040 /* CFSYNC is an ultra offset */
691: #define CFNEWULTRAFORMAT 0x0080 /* Use the Ultra2 SEEPROM format */
692: #define CFSTART 0x0100 /* send start unit SCSI command */
693: #define CFINCBIOS 0x0200 /* include in BIOS scan */
694: #define CFRNFOUND 0x0400 /* report even if not found */
695: #define CFMULTILUN 0x0800 /* probe mult luns in BIOS scan */
696: #define CFWBCACHEYES 0x4000 /* Enable W-Behind Cache on drive */
697: #define CFWBCACHENC 0xc000 /* Don't change W-Behind Cache */
698: /* UNUSED 0x3000 */
699: unsigned short device_flags[16]; /* words 0-15 */
700:
701: /*
702: * BIOS Control Bits
703: */
704: #define CFSUPREM 0x0001 /* support all removable drives */
705: #define CFSUPREMB 0x0002 /* support removable drives for boot only */
706: #define CFBIOSEN 0x0004 /* BIOS enabled */
707: /* UNUSED 0x0008 */
708: #define CFSM2DRV 0x0010 /* support more than two drives */
709: #define CF284XEXTEND 0x0020 /* extended translation (284x cards) */
710: /* UNUSED 0x0040 */
711: #define CFEXTEND 0x0080 /* extended translation enabled */
712: /* UNUSED 0xFF00 */
713: unsigned short bios_control; /* word 16 */
714:
715: /*
716: * Host Adapter Control Bits
717: */
718: #define CFAUTOTERM 0x0001 /* Perform Auto termination */
719: #define CFULTRAEN 0x0002 /* Ultra SCSI speed enable (Ultra cards) */
720: #define CF284XSELTO 0x0003 /* Selection timeout (284x cards) */
721: #define CF284XFIFO 0x000C /* FIFO Threshold (284x cards) */
722: #define CFSTERM 0x0004 /* SCSI low byte termination */
723: #define CFWSTERM 0x0008 /* SCSI high byte termination (wide card) */
724: #define CFSPARITY 0x0010 /* SCSI parity */
725: #define CF284XSTERM 0x0020 /* SCSI low byte termination (284x cards) */
726: #define CFRESETB 0x0040 /* reset SCSI bus at boot */
727: #define CFBPRIMARY 0x0100 /* Channel B primary on 7895 chipsets */
728: #define CFSEAUTOTERM 0x0400 /* aic7890 Perform SE Auto Term */
729: #define CFLVDSTERM 0x0800 /* aic7890 LVD Termination */
730: /* UNUSED 0xF280 */
731: unsigned short adapter_control; /* word 17 */
732:
733: /*
734: * Bus Release, Host Adapter ID
735: */
736: #define CFSCSIID 0x000F /* host adapter SCSI ID */
737: /* UNUSED 0x00F0 */
738: #define CFBRTIME 0xFF00 /* bus release time */
739: unsigned short brtime_id; /* word 18 */
740:
741: /*
742: * Maximum targets
743: */
744: #define CFMAXTARG 0x00FF /* maximum targets */
745: /* UNUSED 0xFF00 */
746: unsigned short max_targets; /* word 19 */
747:
748: unsigned short res_1[11]; /* words 20-30 */
749: unsigned short checksum; /* word 31 */
750: };
751:
752: #define SELBUS_MASK 0x0a
753: #define SELNARROW 0x00
754: #define SELBUSB 0x08
755: #define SINGLE_BUS 0x00
756:
757: #define SCB_TARGET(scb) \
758: (((scb)->hscb->target_channel_lun & TID) >> 4)
759: #define SCB_LUN(scb) \
760: ((scb)->hscb->target_channel_lun & LID)
761: #define SCB_IS_SCSIBUS_B(scb) \
762: (((scb)->hscb->target_channel_lun & SELBUSB) != 0)
763:
764: /*
765: * If an error occurs during a data transfer phase, run the command
766: * to completion - it's easier that way - making a note of the error
767: * condition in this location. This then will modify a DID_OK status
768: * into an appropriate error for the higher-level SCSI code.
769: */
770: #define aic7xxx_error(cmd) ((cmd)->SCp.Status)
771:
772: /*
773: * Keep track of the targets returned status.
774: */
775: #define aic7xxx_status(cmd) ((cmd)->SCp.sent_command)
776:
777: /*
778: * The position of the SCSI commands scb within the scb array.
779: */
780: #define aic7xxx_position(cmd) ((cmd)->SCp.have_data_in)
781:
782: /*
783: * So we can keep track of our host structs
784: */
785: static struct aic7xxx_host *first_aic7xxx = NULL;
786:
787: /*
788: * As of Linux 2.1, the mid-level SCSI code uses virtual addresses
789: * in the scatter-gather lists. We need to convert the virtual
790: * addresses to physical addresses.
791: */
792: struct hw_scatterlist {
793: unsigned int address;
794: unsigned int length;
795: };
796:
797: /*
798: * Maximum number of SG segments these cards can support.
799: */
800: #define AIC7XXX_MAX_SG 128
801:
802: /*
803: * The maximum number of SCBs we could have for ANY type
804: * of card. DON'T FORGET TO CHANGE THE SCB MASK IN THE
805: * SEQUENCER CODE IF THIS IS MODIFIED!
806: */
807: #define AIC7XXX_MAXSCB 255
808:
809:
810: struct aic7xxx_hwscb {
811: /* ------------ Begin hardware supported fields ---------------- */
812: /* 0*/ unsigned char control;
813: /* 1*/ unsigned char target_channel_lun; /* 4/1/3 bits */
814: /* 2*/ unsigned char target_status;
815: /* 3*/ unsigned char SG_segment_count;
816: /* 4*/ unsigned int SG_list_pointer;
817: /* 8*/ unsigned char residual_SG_segment_count;
818: /* 9*/ unsigned char residual_data_count[3];
819: /*12*/ unsigned int data_pointer;
820: /*16*/ unsigned int data_count;
821: /*20*/ unsigned int SCSI_cmd_pointer;
822: /*24*/ unsigned char SCSI_cmd_length;
823: /*25*/ unsigned char tag; /* Index into our kernel SCB array.
824: * Also used as the tag for tagged I/O
825: */
826: #define SCB_PIO_TRANSFER_SIZE 26 /* amount we need to upload/download
827: * via PIO to initialize a transaction.
828: */
829: /*26*/ unsigned char next; /* Used to thread SCBs awaiting selection
830: * or disconnected down in the sequencer.
831: */
832: /*27*/ unsigned char prev;
833: /*28*/ unsigned int pad; /*
834: * Unused by the kernel, but we require
835: * the padding so that the array of
836: * hardware SCBs is alligned on 32 byte
837: * boundaries so the sequencer can index
838: */
839: };
840:
841: typedef enum {
842: SCB_FREE = 0x0000,
843: SCB_WAITINGQ = 0x0002,
844: SCB_ACTIVE = 0x0004,
845: SCB_SENSE = 0x0008,
846: SCB_ABORT = 0x0010,
847: SCB_DEVICE_RESET = 0x0020,
848: SCB_RESET = 0x0040,
849: SCB_RECOVERY_SCB = 0x0080,
850: SCB_WAS_BUSY = 0x0100,
851: SCB_MSGOUT_SENT = 0x0200,
852: SCB_MSGOUT_SDTR = 0x0400,
853: SCB_MSGOUT_WDTR = 0x0800,
854: SCB_MSGOUT_BITS = SCB_MSGOUT_SENT |
855: SCB_MSGOUT_SDTR |
856: SCB_MSGOUT_WDTR,
857: SCB_QUEUED_ABORT = 0x1000,
858: SCB_QUEUED_FOR_DONE = 0x2000
859: } scb_flag_type;
860:
861: typedef enum {
862: AHC_FNONE = 0x00000000,
863: AHC_PAGESCBS = 0x00000001,
864: AHC_CHANNEL_B_PRIMARY = 0x00000002,
865: AHC_USEDEFAULTS = 0x00000004,
866: AHC_INDIRECT_PAGING = 0x00000008,
867: AHC_CHNLB = 0x00000020,
868: AHC_CHNLC = 0x00000040,
869: AHC_EXTEND_TRANS_A = 0x00000100,
870: AHC_EXTEND_TRANS_B = 0x00000200,
871: AHC_TERM_ENB_A = 0x00000400,
872: AHC_TERM_ENB_SE_LOW = 0x00000400,
873: AHC_TERM_ENB_B = 0x00000800,
874: AHC_TERM_ENB_SE_HIGH = 0x00000800,
875: AHC_HANDLING_REQINITS = 0x00001000,
876: AHC_TARGETMODE = 0x00002000,
877: AHC_NEWEEPROM_FMT = 0x00004000,
878: /*
879: * Here ends the FreeBSD defined flags and here begins the linux defined
880: * flags. NOTE: I did not preserve the old flag name during this change
881: * specifically to force me to evaluate what flags were being used properly
882: * and what flags weren't. This way, I could clean up the flag usage on
883: * a use by use basis. Doug Ledford
884: */
885: AHC_A_SCANNED = 0x00100000,
886: AHC_B_SCANNED = 0x00200000,
887: AHC_MULTI_CHANNEL = 0x00400000,
888: AHC_BIOS_ENABLED = 0x00800000,
889: AHC_SEEPROM_FOUND = 0x01000000,
890: AHC_TERM_ENB_LVD = 0x02000000,
891: AHC_ABORT_PENDING = 0x04000000,
892: AHC_RESET_PENDING = 0x08000000,
893: #define AHC_IN_ISR_BIT 28
894: AHC_IN_ISR = 0x10000000,
895: AHC_IN_ABORT = 0x20000000,
896: AHC_IN_RESET = 0x40000000,
897: AHC_EXTERNAL_SRAM = 0x80000000
898: } ahc_flag_type;
899:
900: typedef enum {
901: AHC_NONE = 0x0000,
902: AHC_CHIPID_MASK = 0x00ff,
903: AHC_AIC7770 = 0x0001,
904: AHC_AIC7850 = 0x0002,
905: AHC_AIC7860 = 0x0003,
906: AHC_AIC7870 = 0x0004,
907: AHC_AIC7880 = 0x0005,
908: AHC_AIC7890 = 0x0006,
909: AHC_AIC7895 = 0x0007,
910: AHC_AIC7896 = 0x0008,
911: AHC_VL = 0x0100,
912: AHC_EISA = 0x0200,
913: AHC_PCI = 0x0400,
914: } ahc_chip;
915:
916: typedef enum {
917: AHC_FENONE = 0x0000,
918: AHC_ULTRA = 0x0001,
919: AHC_ULTRA2 = 0x0002,
920: AHC_WIDE = 0x0004,
921: AHC_TWIN = 0x0008,
922: AHC_MORE_SRAM = 0x0010,
923: AHC_CMD_CHAN = 0x0020,
924: AHC_QUEUE_REGS = 0x0040,
925: AHC_SG_PRELOAD = 0x0080,
926: AHC_SPIOCAP = 0x0100,
927: AHC_AIC7770_FE = AHC_FENONE,
928: AHC_AIC7850_FE = AHC_SPIOCAP,
929: AHC_AIC7860_FE = AHC_ULTRA|AHC_SPIOCAP,
930: AHC_AIC7870_FE = AHC_FENONE,
931: AHC_AIC7880_FE = AHC_ULTRA,
932: AHC_AIC7890_FE = AHC_MORE_SRAM|AHC_CMD_CHAN|AHC_ULTRA2|
933: AHC_QUEUE_REGS|AHC_SG_PRELOAD,
934: AHC_AIC7895_FE = AHC_MORE_SRAM|AHC_CMD_CHAN|AHC_ULTRA,
935: AHC_AIC7896_FE = AHC_AIC7890_FE,
936: } ahc_feature;
937:
938: struct aic7xxx_scb {
939: struct aic7xxx_hwscb *hscb; /* corresponding hardware scb */
940: Scsi_Cmnd *cmd; /* Scsi_Cmnd for this scb */
941: struct aic7xxx_scb *q_next; /* next scb in queue */
942: volatile scb_flag_type flags; /* current state of scb */
943: struct hw_scatterlist *sg_list; /* SG list in adapter format */
944: void *kmalloc_ptr;
945: unsigned char tag_action;
946: unsigned char sg_count;
947: unsigned char sense_cmd[6]; /*
948: * Allocate 6 characters for
949: * sense command.
950: */
951: unsigned int sg_length; /* We init this during buildscb so we
952: * don't have to calculate anything
953: * during underflow/overflow/stat code
954: */
955: };
956:
957: /*
958: * Define a linked list of SCBs.
959: */
960: typedef struct {
961: struct aic7xxx_scb *head;
962: struct aic7xxx_scb *tail;
963: } scb_queue_type;
964:
965: static struct {
966: unsigned char errno;
967: const char *errmesg;
968: } hard_error[] = {
969: { ILLHADDR, "Illegal Host Access" },
970: { ILLSADDR, "Illegal Sequencer Address referenced" },
971: { ILLOPCODE, "Illegal Opcode in sequencer program" },
972: { SQPARERR, "Sequencer Ram Parity Error" },
973: { DPARERR, "Data-Path Ram Parity Error" },
974: { MPARERR, "Scratch Ram/SCB Array Ram Parity Error" },
975: { PCIERRSTAT,"PCI Error detected" },
976: { CIOPARERR, "CIOBUS Parity Error" }
977: };
978:
979: static unsigned char
980: generic_sense[] = { REQUEST_SENSE, 0, 0, 0, 255, 0 };
981:
982: typedef struct {
983: scb_queue_type free_scbs; /*
984: * SCBs assigned to free slot on
985: * card (no paging required)
986: */
987: struct aic7xxx_scb *scb_array[AIC7XXX_MAXSCB];
988: struct aic7xxx_hwscb *hscbs;
989: unsigned char numscbs; /* current number of scbs */
990: unsigned char maxhscbs; /* hardware scbs */
991: unsigned char maxscbs; /* max scbs including pageable scbs */
992: void *hscb_kmalloc_ptr;
993: } scb_data_type;
994:
995: struct target_cmd {
996: unsigned char mesg_bytes[4];
997: unsigned char command[28];
998: };
999:
1000: #define AHC_TRANS_CUR 0x0001
1001: #define AHC_TRANS_ACTIVE 0x0002
1002: #define AHC_TRANS_GOAL 0x0004
1003: #define AHC_TRANS_USER 0x0008
1004: #define AHC_TRANS_QUITE 0x0010
1005: typedef struct {
1006: unsigned char cur_width;
1007: unsigned char goal_width;
1008: unsigned char cur_period;
1009: unsigned char goal_period;
1010: unsigned char cur_offset;
1011: unsigned char goal_offset;
1012: unsigned char user_width;
1013: unsigned char user_period;
1014: unsigned char user_offset;
1015: } transinfo_type;
1016:
1017: /*
1018: * Define a structure used for each host adapter. Note, in order to avoid
1019: * problems with architectures I can't test on (because I don't have one,
1020: * such as the Alpha based systems) which happen to give faults for
1021: * non-aligned memory accesses, care was taken to align this structure
1022: * in a way that gauranteed all accesses larger than 8 bits were aligned
1023: * on the appropriate boundary. It's also organized to try and be more
1024: * cache line efficient. Be careful when changing this lest you might hurt
1025: * overall performance and bring down the wrath of the masses.
1026: */
1027: struct aic7xxx_host {
1028: /*
1029: * This is the first 64 bytes in the host struct
1030: */
1031:
1032: struct Scsi_Host *host; /* pointer to scsi host */
1033: struct aic7xxx_host *next; /* allow for multiple IRQs */
1034: int host_no; /* SCSI host number */
1035: unsigned long base; /* card base address */
1036: volatile unsigned char *maddr; /* memory mapped address */
1037: unsigned long mbase; /* I/O memory address */
1038: volatile ahc_flag_type flags;
1039: #if LINUX_VERSION_CODE > KERNEL_VERSION(2,1,0)
1040: spinlock_t spin_lock;
1041: #endif
1042: volatile unsigned char cpu_lock_count[NR_CPUS];
1043: ahc_chip chip; /* chip type */
1044: ahc_feature features; /* chip features */
1045: unsigned long last_reset;
1046: unsigned long isr_count; /* Interrupt count */
1047: unsigned long spurious_int;
1048: struct target_cmd *targetcmds;
1049: unsigned int num_targetcmds;
1050: unsigned short discenable; /* Targets allowed to disconnect */
1051: unsigned short tagenable; /* Targets using tagged I/O */
1052: unsigned short orderedtag; /* Ordered Q tags allowed */
1053: volatile unsigned char activescbs; /* active scbs */
1054: volatile unsigned char max_activescbs;
1055: unsigned char unpause; /* unpause value for HCNTRL */
1056: unsigned char pause; /* pause value for HCNTRL */
1057: volatile unsigned char qoutfifonext;
1058: volatile unsigned char qinfifonext;
1059:
1060: /*
1061: * MAX_TARGETS is currently == 16, so that makes these entries the next
1062: * 64 bytes
1063: */
1064:
1065: #define DEVICE_PRESENT 0x01
1066: #define BUS_DEVICE_RESET_PENDING 0x02
1067: #define DEVICE_TIMEOUT 0x04
1068: #define DEVICE_PRINT_SDTR 0x08
1069: #define DEVICE_PRINT_WDTR 0x10
1070: #define DEVICE_SUCCESS 0x20
1071: #define DEVICE_TAGGED_SUCCESS 0x40
1072: #define DEVICE_SCANNED 0x80
1073: volatile unsigned char dev_flags[MAX_TARGETS];
1074: volatile unsigned char dev_active_cmds[MAX_TARGETS];
1075: volatile unsigned char dev_temp_queue_depth[MAX_TARGETS];
1076: unsigned char dev_commands_sent[MAX_TARGETS];
1077:
1078: /*
1079: * The next 128 (or 256 on 64 bit machines)....
1080: */
1081: Scsi_Cmnd *dev_wdtr_cmnd[MAX_TARGETS];
1082: Scsi_Cmnd *dev_sdtr_cmnd[MAX_TARGETS];
1083:
1084: /*
1085: * The next 64....
1086: */
1087:
1088: long dev_last_reset[MAX_TARGETS];
1089:
1090: /*
1091: * The next 64....
1092: */
1093:
1094: unsigned char dev_mid_level_queue_depth[MAX_TARGETS];
1095: unsigned char dev_last_queue_full[MAX_TARGETS];
1096: unsigned char dev_last_queue_full_count[MAX_TARGETS];
1097: unsigned char dev_max_queue_depth[MAX_TARGETS];
1098:
1099: /*
1100: * The next 128....
1101: */
1102:
1103: volatile scb_queue_type delayed_scbs[MAX_TARGETS];
1104:
1105: /*
1106: *
1107: */
1108:
1109: struct timer_list dev_timer[MAX_TARGETS];
1110:
1111: /*
1112: * The next 64....
1113: */
1114:
1115: unsigned char msg_buf[9]; /* The message for the target */
1116: unsigned char msg_type;
1117: #define MSG_TYPE_NONE 0x00
1118: #define MSG_TYPE_INITIATOR_MSGOUT 0x01
1119: #define MSG_TYPE_INITIATOR_MSGIN 0x02
1120: unsigned char msg_len; /* Length of message */
1121: unsigned char msg_index; /* Index into msg_buf array */
1122: transinfo_type transinfo[MAX_TARGETS];
1123: volatile scb_queue_type waiting_scbs; /*
1124: * SCBs waiting for space in
1125: * the QINFIFO.
1126: */
1127: scb_data_type *scb_data;
1128:
1129: struct aic7xxx_cmd_queue {
1130: Scsi_Cmnd *head;
1131: Scsi_Cmnd *tail;
1132: } completeq;
1133:
1134:
1135: /*
1136: * We put the less frequently used host structure items after the more
1137: * frequently used items to try and ease the burden on the cache subsystem.
1138: * These entries are not *commonly* accessed, whereas the preceding entries
1139: * are accessed very often. The only exceptions are the qinfifo, qoutfifo,
1140: * and untagged_scbs array. But, they are often accessed only once and each
1141: * access into these arrays is likely to blow a cache line, so they are put
1142: * down here so we can minimize the number of cache lines required to hold
1143: * the preceeding entries.
1144: */
1145:
1146: volatile unsigned char untagged_scbs[256];
1147: volatile unsigned char qoutfifo[256];
1148: volatile unsigned char qinfifo[256];
1149: unsigned int irq; /* IRQ for this adapter */
1150: volatile unsigned short needsdtr;
1151: volatile unsigned short sdtr_pending;
1152: volatile unsigned short needwdtr;
1153: volatile unsigned short wdtr_pending;
1154: int instance; /* aic7xxx instance number */
1155: int scsi_id; /* host adapter SCSI ID */
1156: int scsi_id_b; /* channel B for twin adapters */
1157: unsigned int bios_address;
1158: int board_name_index;
1159: unsigned long reset_start;
1160: unsigned short needsdtr_copy; /* default config */
1161: unsigned short needwdtr_copy; /* default config */
1162: unsigned short ultraenb; /* Ultra mode target list */
1163: unsigned short bios_control; /* bios control - SEEPROM */
1164: unsigned short adapter_control; /* adapter control - SEEPROM */
1165: #if LINUX_VERSION_CODE > KERNEL_VERSION(2,1,92)
1166: struct pci_dev *pdev;
1167: #endif
1168: unsigned char pci_bus;
1169: unsigned char pci_device_fn;
1170: struct seeprom_config sc;
1171: unsigned short sc_type;
1172: unsigned short sc_size;
1173:
1174: /*
1175: * Statistics Kept:
1176: *
1177: * Total Xfers (count for each command that has a data xfer),
1178: * broken down further by reads && writes.
1179: *
1180: * Binned sizes, writes && reads:
1181: * < 512, 512, 1-2K, 2-4K, 4-8K, 8-16K, 16-32K, 32-64K, 64K-128K, > 128K
1182: *
1183: * Total amounts read/written above 512 bytes (amts under ignored)
1184: *
1185: * NOTE: Enabling this feature is likely to cause a noticeable performance
1186: * decrease as the accesses into the stats structures blows apart multiple
1187: * cache lines and is CPU time consuming. We keep the xfer count always
1188: * for use by the aic7xxx_proc.c code, but only do the bins if the
1189: * proc stats code is enabled.
1190: */
1191: struct aic7xxx_xferstats {
1192: long xfers; /* total xfer count */
1193: long w_total; /* total writes */
1194: long w_total512; /* 512 byte blocks written */
1195: long r_total; /* total reads */
1196: long r_total512; /* 512 byte blocks read */
1197: #ifdef AIC7XXX_PROC_STATS
1198: long w_bins[10]; /* binned write */
1199: long r_bins[10]; /* binned reads */
1200: #endif /* AIC7XXX_PROC_STATS */
1201: } stats[MAX_TARGETS][MAX_LUNS]; /* [(channel << 3)|target][lun] */
1202: };
1203:
1204: /*
1205: * Valid SCSIRATE values. (p. 3-17)
1206: * Provides a mapping of transfer periods in ns/4 to the proper value to
1207: * stick in the SCSIRATE reg to use that transfer rate.
1208: */
1209: #define AHC_SYNCRATE_ULTRA2 0
1210: #define AHC_SYNCRATE_ULTRA 2
1211: #define AHC_SYNCRATE_FAST 5
1212: static struct aic7xxx_syncrate {
1213: /* Rates in Ultra mode have bit 8 of sxfr set */
1214: #define ULTRA_SXFR 0x100
1215: int sxfr_ultra2;
1216: int sxfr;
1217: unsigned char period;
1218: const char *rate[2];
1219: } aic7xxx_syncrates[] = {
1220: { 0x13, 0x000, 10, {"40.0", "80.0"} },
1221: { 0x14, 0x000, 11, {"33.0", "66.6"} },
1222: { 0x15, 0x100, 12, {"20.0", "40.0"} },
1223: { 0x16, 0x110, 15, {"16.0", "32.0"} },
1224: { 0x17, 0x120, 18, {"13.4", "26.8"} },
1225: { 0x18, 0x000, 25, {"10.0", "20.0"} },
1226: { 0x19, 0x010, 31, {"8.0", "16.0"} },
1227: { 0x1a, 0x020, 37, {"6.67", "13.3"} },
1228: { 0x1b, 0x030, 43, {"5.7", "11.4"} },
1229: { 0x10, 0x040, 50, {"5.0", "10.0"} },
1230: { 0x00, 0x050, 56, {"4.4", "8.8" } },
1231: { 0x00, 0x060, 62, {"4.0", "8.0" } },
1232: { 0x00, 0x070, 68, {"3.6", "7.2" } },
1233: { 0x00, 0x000, 0, {NULL, NULL} },
1234: };
1235:
1236: #define CTL_OF_SCB(scb) (((scb->hscb)->target_channel_lun >> 3) & 0x1), \
1237: (((scb->hscb)->target_channel_lun >> 4) & 0xf), \
1238: ((scb->hscb)->target_channel_lun & 0x07)
1239:
1240: #define CTL_OF_CMD(cmd) ((cmd->channel) & 0x01), \
1241: ((cmd->target) & 0x0f), \
1242: ((cmd->lun) & 0x07)
1243:
1244: #define TARGET_INDEX(cmd) ((cmd)->target | ((cmd)->channel << 3))
1245:
1246: /*
1247: * A nice little define to make doing our printks a little easier
1248: */
1249:
1250: #define WARN_LEAD KERN_WARNING "(scsi%d:%d:%d:%d) "
1251: #define INFO_LEAD KERN_INFO "(scsi%d:%d:%d:%d) "
1252:
1253: /*
1254: * XXX - these options apply unilaterally to _all_ 274x/284x/294x
1255: * cards in the system. This should be fixed. Exceptions to this
1256: * rule are noted in the comments.
1257: */
1258:
1259:
1260: /*
1261: * Skip the scsi bus reset. Non 0 make us skip the reset at startup. This
1262: * has no effect on any later resets that might occur due to things like
1263: * SCSI bus timeouts.
1264: */
1265: static unsigned int aic7xxx_no_reset = 0;
1266: /*
1267: * Certain PCI motherboards will scan PCI devices from highest to lowest,
1268: * others scan from lowest to highest, and they tend to do all kinds of
1269: * strange things when they come into contact with PCI bridge chips. The
1270: * net result of all this is that the PCI card that is actually used to boot
1271: * the machine is very hard to detect. Most motherboards go from lowest
1272: * PCI slot number to highest, and the first SCSI controller found is the
1273: * one you boot from. The only exceptions to this are when a controller
1274: * has its BIOS disabled. So, we by default sort all of our SCSI controllers
1275: * from lowest PCI slot number to highest PCI slot number. We also force
1276: * all controllers with their BIOS disabled to the end of the list. This
1277: * works on *almost* all computers. Where it doesn't work, we have this
1278: * option. Setting this option to non-0 will reverse the order of the sort
1279: * to highest first, then lowest, but will still leave cards with their BIOS
1280: * disabled at the very end. That should fix everyone up unless there are
1281: * really strange cirumstances.
1282: */
1283: static int aic7xxx_reverse_scan = 0;
1284: /*
1285: * This setting enables a hack to fix the IRQ settings on buggy 7895
1286: * MB controller setups:
1287: * -1 == Disable this hack
1288: * 0 == Use the Channel A IRQ for both channels
1289: * 1 == Use the Channel B IRQ for both channels
1290: */
1291: static unsigned int aic7xxx_extended = 0;
1292: /*
1293: * The IRQ trigger method used on EISA controllers. Does not effect PCI cards.
1294: * -1 = Use detected settings.
1295: * 0 = Force Edge triggered mode.
1296: * 1 = Force Level triggered mode.
1297: */
1298: static int aic7xxx_irq_trigger = -1;
1299: /*
1300: * This variable is used to override the termination settings on a controller.
1301: * This should not be used under normal conditions. However, in the case
1302: * that a controller does not have a readable SEEPROM (so that we can't
1303: * read the SEEPROM settings directly) and that a controller has a buggered
1304: * version of the cable detection logic, this can be used to force the
1305: * correct termination. It is preferable to use the manual termination
1306: * settings in the BIOS if possible, but some motherboard controllers store
1307: * those settings in a format we can't read. In other cases, auto term
1308: * should also work, but the chipset was put together with no auto term
1309: * logic (common on motherboard controllers). In those cases, we have
1310: * 32 bits here to work with. That's good for 8 controllers/channels. The
1311: * bits are organized as 4 bits per channel, with scsi0 getting the lowest
1312: * 4 bits in the int. A 1 in a bit position indicates the termination setting
1313: * that corresponds to that bit should be enabled, a 0 is disabled.
1314: * It looks something like this:
1315: *
1316: * 0x0f = 1111-Single Ended Low Byte Termination on/off
1317: * ||\-Single Ended High Byte Termination on/off
1318: * |\-LVD Low Byte Termination on/off
1319: * \-LVD High Byte Termination on/off
1320: *
1321: * For non-Ultra2 controllers, the upper 2 bits are not important. So, to
1322: * enable both high byte and low byte termination on scsi0, I would need to
1323: * make sure that the override_term variable was set to 0x03 (bits 0011).
1324: * To make sure that all termination is enabled on an Ultra2 controller at
1325: * scsi2 and only high byte termination on scsi1 and high and low byte
1326: * termination on scsi0, I would set override_term=0xf23 (bits 1111 0010 0011)
1327: *
1328: * For the most part, users should never have to use this, that's why I
1329: * left it fairly cryptic instead of easy to understand. If you need it,
1330: * most likely someone will be telling you what your's needs to be set to.
1331: */
1332: static int aic7xxx_override_term = -1;
1333: /*
1334: * Certain motherboard chipset controllers tend to screw
1335: * up the polarity of the term enable output pin. Use this variable
1336: * to force the correct polarity for your system. This is a bitfield variable
1337: * similar to the previous one, but this one has one bit per channel instead
1338: * of four.
1339: * 0 = Force the setting to active low.
1340: * 1 = Force setting to active high.
1341: * Most Adaptec cards are active high, several motherboards are active low.
1342: * To force a 2940 card at SCSI 0 to active high and a motherboard 7895
1343: * controller at scsi1 and scsi2 to active low, and a 2910 card at scsi3
1344: * to active high, you would need to set stpwlev=0x9 (bits 1001).
1345: *
1346: * People shouldn't need to use this, but if you are experiencing lots of
1347: * SCSI timeout problems, this may help. There is one sure way to test what
1348: * this option needs to be. Using a boot floppy to boot the system, configure
1349: * your system to enable all SCSI termination (in the Adaptec SCSI BIOS) and
1350: * if needed then also pass a value to override_term to make sure that the
1351: * driver is enabling SCSI termination, then set this variable to either 0
1352: * or 1. When the driver boots, make sure there are *NO* SCSI cables
1353: * connected to your controller. If it finds and inits the controller
1354: * without problem, then the setting you passed to stpwlev was correct. If
1355: * the driver goes into a reset loop and hangs the system, then you need the
1356: * other setting for this variable. If neither setting lets the machine
1357: * boot then you have definite termination problems that may not be fixable.
1358: */
1359: static int aic7xxx_stpwlev = -1;
1360: /*
1361: * Set this to non-0 in order to force the driver to panic the kernel
1362: * and print out debugging info on a SCSI abort or reset cycle.
1363: */
1364: static int aic7xxx_panic_on_abort = 0;
1365: /*
1366: * PCI bus parity checking of the Adaptec controllers. This is somewhat
1367: * dubious at best. To my knowledge, this option has never actually
1368: * solved a PCI parity problem, but on certain machines with broken PCI
1369: * chipset configurations, it can generate tons of false error messages.
1370: * It's included in the driver for completeness.
1371: * 0 = Shut off PCI parity check
1372: * -1 = Normal polarity pci parity checking
1373: * 1 = reverse polarity pci parity checking
1374: *
1375: * NOTE: you can't actually pass -1 on the lilo prompt. So, to set this
1376: * variable to -1 you would actually want to simply pass the variable
1377: * name without a number. That will invert the 0 which will result in
1378: * -1.
1379: */
1380: static int aic7xxx_pci_parity = 0;
1381: /*
1382: * Set this to any non-0 value to cause us to dump the contents of all
1383: * the card's registers in a hex dump format tailored to each model of
1384: * controller.
1385: *
1386: * NOTE: THE CONTROLLER IS LEFT IN AN UNUSEABLE STATE BY THIS OPTION.
1387: * YOU CANNOT BOOT UP WITH THIS OPTION, IT IS FOR DEBUGGING PURPOSES
1388: * ONLY
1389: */
1390: static int aic7xxx_dump_card = 0;
1391: /*
1392: * Set this to a non-0 value to make us dump out the 32 bit instruction
1393: * registers on the card after completing the sequencer download. This
1394: * allows the actual sequencer download to be verified. It is possible
1395: * to use this option and still boot up and run your system. This is
1396: * only intended for debugging purposes.
1397: */
1398: static int aic7xxx_dump_sequencer = 0;
1399: /*
1400: * Certain newer motherboards have put new PCI based devices into the
1401: * IO spaces that used to typically be occupied by VLB or EISA cards.
1402: * This overlap can cause these newer motherboards to lock up when scanned
1403: * for older EISA and VLB devices. Setting this option to non-0 will
1404: * cause the driver to skip scanning for any VLB or EISA controllers and
1405: * only support the PCI controllers. NOTE: this means that if the kernel
1406: * os compiled with PCI support disabled, then setting this to non-0
1407: * would result in never finding any devices :)
1408: */
1409: static int aic7xxx_no_probe = 0;
1410:
1411: /*
1412: * So that insmod can find the variable and make it point to something
1413: */
1414: #ifdef MODULE
1415: static char * aic7xxx = NULL;
1416: #if LINUX_VERSION_CODE > KERNEL_VERSION(2,1,18)
1417: MODULE_PARM(aic7xxx, "s");
1418: #endif
1419:
1420: /*
1421: * Just in case someone uses commas to separate items on the insmod
1422: * command line, we define a dummy buffer here to avoid having insmod
1423: * write wild stuff into our code segment
1424: */
1425: static char dummy_buffer[60] = "Please don't trounce on me insmod!!\n";
1426:
1427: #endif
1428:
1429: /*
1430: * See the comments earlier in the file for what this item is all about
1431: * If you have more than 4 controllers, you will need to increase the
1432: * the number of items in the array below. Additionally, if you don't
1433: * want to have lilo pass a humongous config line to the aic7xxx driver,
1434: * then you can get in and manually adjust these instead of leaving them
1435: * at the default. Pay attention to the comments earlier in this file
1436: * concerning this array if you are going to hand modify these values.
1437: */
1438: static adapter_tag_info_t aic7xxx_tag_info[] =
1439: {
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},
1449: {DEFAULT_TAG_COMMANDS},
1450: {DEFAULT_TAG_COMMANDS},
1451: {DEFAULT_TAG_COMMANDS},
1452: {DEFAULT_TAG_COMMANDS},
1453: {DEFAULT_TAG_COMMANDS},
1454: {DEFAULT_TAG_COMMANDS},
1455: {DEFAULT_TAG_COMMANDS}
1456: };
1457:
1458: #define VERBOSE_NORMAL 0x0000
1459: #define VERBOSE_NEGOTIATION 0x0001
1460: #define VERBOSE_SEQINT 0x0002
1461: #define VERBOSE_SCSIINT 0x0004
1462: #define VERBOSE_PROBE 0x0008
1463: #define VERBOSE_PROBE2 0x0010
1464: #define VERBOSE_NEGOTIATION2 0x0020
1465: #define VERBOSE_MINOR_ERROR 0x0040
1466: #define VERBOSE_TRACING 0x0080
1467: #define VERBOSE_ABORT 0x0f00
1468: #define VERBOSE_ABORT_MID 0x0100
1469: #define VERBOSE_ABORT_FIND 0x0200
1470: #define VERBOSE_ABORT_PROCESS 0x0400
1471: #define VERBOSE_ABORT_RETURN 0x0800
1472: #define VERBOSE_RESET 0xf000
1473: #define VERBOSE_RESET_MID 0x1000
1474: #define VERBOSE_RESET_FIND 0x2000
1475: #define VERBOSE_RESET_PROCESS 0x4000
1476: #define VERBOSE_RESET_RETURN 0x8000
1477: static int aic7xxx_verbose = VERBOSE_NORMAL | VERBOSE_NEGOTIATION |
1478: VERBOSE_PROBE; /* verbose messages */
1479:
1480:
1481: /****************************************************************************
1482: *
1483: * We're going to start putting in function declarations so that order of
1484: * functions is no longer important. As needed, they are added here.
1485: *
1486: ***************************************************************************/
1487:
1488: static void aic7xxx_panic_abort(struct aic7xxx_host *p, Scsi_Cmnd *cmd);
1489: static void aic7xxx_print_card(struct aic7xxx_host *p);
1490: static void aic7xxx_print_scratch_ram(struct aic7xxx_host *p);
1491: static void aic7xxx_print_sequencer(struct aic7xxx_host *p, int downloaded);
1492: #ifdef AIC7XXX_VERBOSE_DEBUGGING
1493: static void aic7xxx_check_scbs(struct aic7xxx_host *p, char *buffer);
1494: #endif
1495:
1496: /****************************************************************************
1497: *
1498: * These functions are now used. They happen to be wrapped in useless
1499: * inb/outb port read/writes around the real reads and writes because it
1500: * seems that certain very fast CPUs have a problem dealing with us when
1501: * going at full speed.
1502: *
1503: ***************************************************************************/
1504:
1505: #if LINUX_VERSION_CODE < KERNEL_VERSION(2,1,0)
1506: static inline void
1507: mdelay(int milliseconds)
1508: {
1509: int i;
1510:
1511: for(i=0; i<milliseconds; i++)
1512: udelay(1000);
1513: }
1514: #endif
1515:
1516: static inline unsigned char
1517: aic_inb(struct aic7xxx_host *p, long port)
1518: {
1519: #ifdef MMAPIO
1520: unsigned char x;
1521: if(p->maddr)
1522: {
1523: x = p->maddr[port];
1524: }
1525: else
1526: {
1527: x = inb(p->base + port);
1528: }
1529: mb();
1530: return(x);
1531: #else
1532: return(inb(p->base + port));
1533: #endif
1534: }
1535:
1536: static inline void
1537: aic_outb(struct aic7xxx_host *p, unsigned char val, long port)
1538: {
1539: #ifdef MMAPIO
1540: if(p->maddr)
1541: {
1542: p->maddr[port] = val;
1543: }
1544: else
1545: {
1546: outb(val, p->base + port);
1547: }
1548: mb();
1549: #else
1550: outb(val, p->base + port);
1551: #endif
1552: }
1553:
1554: /*+F*************************************************************************
1555: * Function:
1556: * aic7xxx_setup
1557: *
1558: * Description:
1559: * Handle Linux boot parameters. This routine allows for assigning a value
1560: * to a parameter with a ':' between the parameter and the value.
1561: * ie. aic7xxx=unpause:0x0A,extended
1562: *-F*************************************************************************/
1563: void
1564: aic7xxx_setup(char *s, int *dummy)
1565: {
1566: int i, n;
1567: char *p;
1568: char *end;
1569:
1570: static struct {
1571: const char *name;
1572: unsigned int *flag;
1573: } options[] = {
1574: { "extended", &aic7xxx_extended },
1575: { "no_reset", &aic7xxx_no_reset },
1576: { "irq_trigger", &aic7xxx_irq_trigger },
1577: { "verbose", &aic7xxx_verbose },
1578: { "reverse_scan",&aic7xxx_reverse_scan },
1579: { "override_term", &aic7xxx_override_term },
1580: { "stpwlev", &aic7xxx_stpwlev },
1581: { "no_probe", &aic7xxx_no_probe },
1582: { "panic_on_abort", &aic7xxx_panic_on_abort },
1583: { "pci_parity", &aic7xxx_pci_parity },
1584: { "dump_card", &aic7xxx_dump_card },
1585: { "dump_sequencer", &aic7xxx_dump_sequencer },
1586: { "tag_info", NULL }
1587: };
1588:
1589: end = strchr(s, '\0');
1590:
1591: for (p = strtok(s, ",."); p; p = strtok(NULL, ",."))
1592: {
1593: for (i = 0; i < NUMBER(options); i++)
1594: {
1595: n = strlen(options[i].name);
1596: if (!strncmp(options[i].name, p, n))
1597: {
1598: if (!strncmp(p, "tag_info", n))
1599: {
1600: if (p[n] == ':')
1601: {
1602: char *base;
1603: char *tok, *tok_end, *tok_end2;
1604: char tok_list[] = { '.', ',', '{', '}', '\0' };
1605: int i, instance = -1, device = -1;
1606: unsigned char done = FALSE;
1607:
1608: base = p;
1609: tok = base + n + 1; /* Forward us just past the ':' */
1610: tok_end = strchr(tok, '\0');
1611: if (tok_end < end)
1612: *tok_end = ',';
1613: while(!done)
1614: {
1615: switch(*tok)
1616: {
1617: case '{':
1618: if (instance == -1)
1619: instance = 0;
1620: else if (device == -1)
1621: device = 0;
1622: tok++;
1623: break;
1624: case '}':
1625: if (device != -1)
1626: device = -1;
1627: else if (instance != -1)
1628: instance = -1;
1629: tok++;
1630: break;
1631: case ',':
1632: case '.':
1633: if (instance == -1)
1634: done = TRUE;
1635: else if (device >= 0)
1636: device++;
1637: else if (instance >= 0)
1638: instance++;
1639: if ( (device >= MAX_TARGETS) ||
1640: (instance >= NUMBER(aic7xxx_tag_info)) )
1641: done = TRUE;
1642: tok++;
1643: if (!done)
1644: {
1645: base = tok;
1646: }
1647: break;
1648: case '\0':
1649: done = TRUE;
1650: break;
1651: default:
1652: done = TRUE;
1653: tok_end = strchr(tok, '\0');
1654: for(i=0; tok_list[i]; i++)
1655: {
1656: tok_end2 = strchr(tok, tok_list[i]);
1657: if ( (tok_end2) && (tok_end2 < tok_end) )
1658: {
1659: tok_end = tok_end2;
1660: done = FALSE;
1661: }
1662: }
1663: if ( (instance >= 0) && (device >= 0) &&
1664: (instance < NUMBER(aic7xxx_tag_info)) &&
1665: (device < MAX_TARGETS) )
1666: aic7xxx_tag_info[instance].tag_commands[device] =
1667: simple_strtoul(tok, NULL, 0) & 0xff;
1668: tok = tok_end;
1669: break;
1670: }
1671: }
1672: while((p != base) && (p != NULL))
1673: p = strtok(NULL, ",.");
1674: }
1675: }
1676: else if (p[n] == ':')
1677: {
1678: *(options[i].flag) = simple_strtoul(p + n + 1, NULL, 0);
1679: }
1680: else if (!strncmp(p, "verbose", n))
1681: {
1682: *(options[i].flag) = 0xff09;
1683: }
1684: else
1685: {
1686: *(options[i].flag) = ~(*(options[i].flag));
1687: }
1688: }
1689: }
1690: }
1691: }
1692:
1693: /*+F*************************************************************************
1694: * Function:
1695: * pause_sequencer
1696: *
1697: * Description:
1698: * Pause the sequencer and wait for it to actually stop - this
1699: * is important since the sequencer can disable pausing for critical
1700: * sections.
1701: *-F*************************************************************************/
1702: static inline void
1703: pause_sequencer(struct aic7xxx_host *p)
1704: {
1705: aic_outb(p, p->pause, HCNTRL);
1706: while ((aic_inb(p, HCNTRL) & PAUSE) == 0)
1707: {
1708: ;
1709: }
1710: }
1711:
1712: /*+F*************************************************************************
1713: * Function:
1714: * unpause_sequencer
1715: *
1716: * Description:
1717: * Unpause the sequencer. Unremarkable, yet done often enough to
1718: * warrant an easy way to do it.
1719: *-F*************************************************************************/
1720: static inline void
1721: unpause_sequencer(struct aic7xxx_host *p, int unpause_always)
1722: {
1723: if (unpause_always ||
1724: ( !(aic_inb(p, INTSTAT) & (SCSIINT | SEQINT | BRKADRINT)) &&
1725: !(p->flags & AHC_HANDLING_REQINITS) ) )
1726: {
1727: aic_outb(p, p->unpause, HCNTRL);
1728: }
1729: }
1730:
1731: /*+F*************************************************************************
1732: * Function:
1733: * restart_sequencer
1734: *
1735: * Description:
1736: * Restart the sequencer program from address zero. This assumes
1737: * that the sequencer is already paused.
1738: *-F*************************************************************************/
1739: static inline void
1740: restart_sequencer(struct aic7xxx_host *p)
1741: {
1742: aic_outb(p, 0, SEQADDR0);
1743: aic_outb(p, 0, SEQADDR1);
1744: aic_outb(p, FASTMODE, SEQCTL);
1745: }
1746:
1747: /*
1748: * We include the aic7xxx_seq.c file here so that the other defines have
1749: * already been made, and so that it comes before the code that actually
1750: * downloads the instructions (since we don't typically use function
1751: * prototype, our code has to be ordered that way, it's a left-over from
1752: * the original driver days.....I should fix it some time DL).
1753: */
1754: #include "aic7xxx_seq.c"
1755:
1756: /*+F*************************************************************************
1757: * Function:
1758: * aic7xxx_check_patch
1759: *
1760: * Description:
1761: * See if the next patch to download should be downloaded.
1762: *-F*************************************************************************/
1763: static int
1764: aic7xxx_check_patch(struct aic7xxx_host *p,
1765: struct sequencer_patch **start_patch, int start_instr, int *skip_addr)
1766: {
1767: struct sequencer_patch *cur_patch;
1768: struct sequencer_patch *last_patch;
1769: int num_patches;
1770:
1771: num_patches = sizeof(sequencer_patches)/sizeof(struct sequencer_patch);
1772: last_patch = &sequencer_patches[num_patches];
1773: cur_patch = *start_patch;
1774:
1775: while ((cur_patch < last_patch) && (start_instr == cur_patch->begin))
1776: {
1777: if (cur_patch->patch_func(p) == 0)
1778: {
1779: /*
1780: * Start rejecting code.
1781: */
1782: *skip_addr = start_instr + cur_patch->skip_instr;
1783: cur_patch += cur_patch->skip_patch;
1784: }
1785: else
1786: {
1787: /*
1788: * Found an OK patch. Advance the patch pointer to the next patch
1789: * and wait for our instruction pointer to get here.
1790: */
1791: cur_patch++;
1792: }
1793: }
1794:
1795: *start_patch = cur_patch;
1796: if (start_instr < *skip_addr)
1797: /*
1798: * Still skipping
1799: */
1800: return (0);
1801: return(1);
1802: }
1803:
1804:
1805: /*+F*************************************************************************
1806: * Function:
1807: * aic7xxx_download_instr
1808: *
1809: * Description:
1810: * Find the next patch to download.
1811: *-F*************************************************************************/
1812: static void
1813: aic7xxx_download_instr(struct aic7xxx_host *p, int instrptr,
1814: unsigned char *dconsts)
1815: {
1816: union ins_formats instr;
1817: struct ins_format1 *fmt1_ins;
1818: struct ins_format3 *fmt3_ins;
1819: unsigned char opcode;
1820:
1821: instr = *(union ins_formats*) &seqprog[instrptr * 4];
1822:
1823: instr.integer = le32_to_cpu(instr.integer);
1824:
1825: fmt1_ins = &instr.format1;
1826: fmt3_ins = NULL;
1827:
1828: /* Pull the opcode */
1829: opcode = instr.format1.opcode;
1830: switch (opcode)
1831: {
1832: case AIC_OP_JMP:
1833: case AIC_OP_JC:
1834: case AIC_OP_JNC:
1835: case AIC_OP_CALL:
1836: case AIC_OP_JNE:
1837: case AIC_OP_JNZ:
1838: case AIC_OP_JE:
1839: case AIC_OP_JZ:
1840: {
1841: struct sequencer_patch *cur_patch;
1842: int address_offset;
1843: unsigned int address;
1844: int skip_addr;
1845: int i;
1846:
1847: fmt3_ins = &instr.format3;
1848: address_offset = 0;
1849: address = fmt3_ins->address;
1850: cur_patch = sequencer_patches;
1851: skip_addr = 0;
1852:
1853: for (i = 0; i < address;)
1854: {
1855: aic7xxx_check_patch(p, &cur_patch, i, &skip_addr);
1856: if (skip_addr > i)
1857: {
1858: int end_addr;
1859:
1860: end_addr = MIN(address, skip_addr);
1861: address_offset += end_addr - i;
1862: i = skip_addr;
1863: }
1864: else
1865: {
1866: i++;
1867: }
1868: }
1869: address -= address_offset;
1870: fmt3_ins->address = address;
1871: /* Fall Through to the next code section */
1872: }
1873: case AIC_OP_OR:
1874: case AIC_OP_AND:
1875: case AIC_OP_XOR:
1876: case AIC_OP_ADD:
1877: case AIC_OP_ADC:
1878: case AIC_OP_BMOV:
1879: if (fmt1_ins->parity != 0)
1880: {
1881: fmt1_ins->immediate = dconsts[fmt1_ins->immediate];
1882: }
1883: fmt1_ins->parity = 0;
1884: /* Fall Through to the next code section */
1885: case AIC_OP_ROL:
1886: if ((p->features & AHC_ULTRA2) != 0)
1887: {
1888: int i, count;
1889:
1890: /* Calculate odd parity for the instruction */
1891: for ( i=0, count=0; i < 31; i++)
1892: {
1893: unsigned int mask;
1894:
1895: mask = 0x01 << i;
1896: if ((instr.integer & mask) != 0)
1897: count++;
1898: }
1899: if (!(count & 0x01))
1900: instr.format1.parity = 1;
1901: }
1902: else
1903: {
1904: if (fmt3_ins != NULL)
1905: {
1906: instr.integer = fmt3_ins->immediate |
1907: (fmt3_ins->source << 8) |
1908: (fmt3_ins->address << 16) |
1909: (fmt3_ins->opcode << 25);
1910: }
1911: else
1912: {
1913: instr.integer = fmt1_ins->immediate |
1914: (fmt1_ins->source << 8) |
1915: (fmt1_ins->destination << 16) |
1916: (fmt1_ins->ret << 24) |
1917: (fmt1_ins->opcode << 25);
1918: }
1919: }
1920: aic_outb(p, (instr.integer & 0xff), SEQRAM);
1921: aic_outb(p, ((instr.integer >> 8) & 0xff), SEQRAM);
1922: aic_outb(p, ((instr.integer >> 16) & 0xff), SEQRAM);
1923: aic_outb(p, ((instr.integer >> 24) & 0xff), SEQRAM);
1924: break;
1925:
1926: default:
1927: panic("aic7xxx: Unknown opcode encountered in sequencer program.");
1928: break;
1929: }
1930: }
1931:
1932:
1933: /*+F*************************************************************************
1934: * Function:
1935: * aic7xxx_loadseq
1936: *
1937: * Description:
1938: * Load the sequencer code into the controller memory.
1939: *-F*************************************************************************/
1940: static void
1941: aic7xxx_loadseq(struct aic7xxx_host *p)
1942: {
1943: struct sequencer_patch *cur_patch;
1944: int i;
1945: int downloaded;
1946: int skip_addr;
1947: unsigned char download_consts[4] = {0, 0, 0, 0};
1948:
1949: if (aic7xxx_verbose & VERBOSE_PROBE)
1950: {
1951: printk(KERN_INFO "(scsi%d) Downloading sequencer code...", p->host_no);
1952: }
1953: download_consts[TMODE_NUMCMDS] = p->num_targetcmds;
1954: cur_patch = &sequencer_patches[0];
1955: downloaded = 0;
1956: skip_addr = 0;
1957:
1958: aic_outb(p, PERRORDIS|LOADRAM|FAILDIS|FASTMODE, SEQCTL);
1959: aic_outb(p, 0, SEQADDR0);
1960: aic_outb(p, 0, SEQADDR1);
1961:
1962: for (i = 0; i < sizeof(seqprog) / 4; i++)
1963: {
1964: if (aic7xxx_check_patch(p, &cur_patch, i, &skip_addr) == 0)
1965: {
1966: /* Skip this instruction for this configuration. */
1967: continue;
1968: }
1969: aic7xxx_download_instr(p, i, &download_consts[0]);
1970: downloaded++;
1971: }
1972:
1973: aic_outb(p, 0, SEQADDR0);
1974: aic_outb(p, 0, SEQADDR1);
1975: aic_outb(p, FASTMODE | FAILDIS, SEQCTL);
1976: unpause_sequencer(p, TRUE);
1977: mdelay(1);
1978: pause_sequencer(p);
1979: aic_outb(p, FASTMODE, SEQCTL);
1980: if (aic7xxx_verbose & VERBOSE_PROBE)
1981: {
1982: printk(" %d instructions downloaded\n", downloaded);
1983: }
1984: if (aic7xxx_dump_sequencer)
1985: aic7xxx_print_sequencer(p, downloaded);
1986: }
1987:
1988: /*+F*************************************************************************
1989: * Function:
1990: * aic7xxx_print_sequencer
1991: *
1992: * Description:
1993: * Print the contents of the sequencer memory to the screen.
1994: *-F*************************************************************************/
1995: static void
1996: aic7xxx_print_sequencer(struct aic7xxx_host *p, int downloaded)
1997: {
1998: int i, k, temp;
1999:
2000: aic_outb(p, PERRORDIS|LOADRAM|FAILDIS|FASTMODE, SEQCTL);
2001: aic_outb(p, 0, SEQADDR0);
2002: aic_outb(p, 0, SEQADDR1);
2003:
2004: k = 0;
2005: for (i=0; i < downloaded; i++)
2006: {
2007: if ( k == 0 )
2008: printk("%03x: ", i);
2009: temp = aic_inb(p, SEQRAM);
2010: temp |= (aic_inb(p, SEQRAM) << 8);
2011: temp |= (aic_inb(p, SEQRAM) << 16);
2012: temp |= (aic_inb(p, SEQRAM) << 24);
2013: printk("%08x", temp);
2014: if ( ++k == 8 )
2015: {
2016: printk("\n");
2017: k = 0;
2018: }
2019: else
2020: printk(" ");
2021: }
2022: aic_outb(p, 0, SEQADDR0);
2023: aic_outb(p, 0, SEQADDR1);
2024: aic_outb(p, FASTMODE | FAILDIS, SEQCTL);
2025: unpause_sequencer(p, TRUE);
2026: mdelay(1);
2027: pause_sequencer(p);
2028: aic_outb(p, FASTMODE, SEQCTL);
2029: printk("\n");
2030: }
2031:
2032: /*+F*************************************************************************
2033: * Function:
2034: * aic7xxx_delay
2035: *
2036: * Description:
2037: * Delay for specified amount of time. We use mdelay because the timer
2038: * interrupt is not guaranteed to be enabled. This will cause an
2039: * infinite loop since jiffies (clock ticks) is not updated.
2040: *-F*************************************************************************/
2041: static void
2042: aic7xxx_delay(int seconds)
2043: {
2044: mdelay(seconds * 1000);
2045: }
2046:
2047: /*+F*************************************************************************
2048: * Function:
2049: * aic7xxx_info
2050: *
2051: * Description:
2052: * Return a string describing the driver.
2053: *-F*************************************************************************/
2054: const char *
2055: aic7xxx_info(struct Scsi_Host *dooh)
2056: {
2057: static char buffer[256];
2058: char *bp;
2059: struct aic7xxx_host *p;
2060:
2061: bp = &buffer[0];
2062: p = (struct aic7xxx_host *)dooh->hostdata;
2063: memset(bp, 0, sizeof(buffer));
2064: strcpy(bp, "Adaptec AHA274x/284x/294x (EISA/VLB/PCI-Fast SCSI) ");
2065: strcat(bp, AIC7XXX_C_VERSION);
2066: strcat(bp, "/");
2067: strcat(bp, AIC7XXX_H_VERSION);
2068: strcat(bp, "\n");
2069: strcat(bp, " <");
2070: strcat(bp, board_names[p->board_name_index]);
2071: strcat(bp, ">");
2072:
2073: return(bp);
2074: }
2075:
2076: /*+F*************************************************************************
2077: * Function:
2078: * aic7xxx_find_syncrate
2079: *
2080: * Description:
2081: * Look up the valid period to SCSIRATE conversion in our table
2082: *-F*************************************************************************/
2083: static struct aic7xxx_syncrate *
2084: aic7xxx_find_syncrate(struct aic7xxx_host *p, unsigned int *period,
2085: unsigned int maxsync)
2086: {
2087: struct aic7xxx_syncrate *syncrate;
2088:
2089: syncrate = &aic7xxx_syncrates[maxsync];
2090: while ( (syncrate->rate[0] != NULL) &&
2091: (!(p->features & AHC_ULTRA2) || syncrate->sxfr_ultra2) )
2092: {
2093: if ( *period <= syncrate->period )
2094: {
2095: /*
2096: * When responding to a target that requests sync, the requested rate
2097: * may fall between two rates that we can output, but still be a rate
2098: * that we can receive. Because of this, we want to respond with the
2099: * same rate that it sent to us even if the persiod we use to send
2100: * data to it is lower. Only lower the response period if we must.
2101: */
2102: if(syncrate == &aic7xxx_syncrates[maxsync])
2103: {
2104: *period = syncrate->period;
2105: }
2106: break;
2107: }
2108: syncrate++;
2109: }
2110: if ( (*period == 0) || (syncrate->rate[0] == NULL) ||
2111: ((p->features & AHC_ULTRA2) && (syncrate->sxfr_ultra2 == 0)) )
2112: {
2113: /*
2114: * Use async transfers for this target
2115: */
2116: *period = 0;
2117: syncrate = NULL;
2118: }
2119: return (syncrate);
2120: }
2121:
2122:
2123: /*+F*************************************************************************
2124: * Function:
2125: * aic7xxx_find_period
2126: *
2127: * Description:
2128: * Look up the valid SCSIRATE to period conversion in our table
2129: *-F*************************************************************************/
2130: static unsigned int
2131: aic7xxx_find_period(struct aic7xxx_host *p, unsigned int scsirate,
2132: unsigned int maxsync)
2133: {
2134: struct aic7xxx_syncrate *syncrate;
2135:
2136: if ((p->features & AHC_ULTRA2) != 0)
2137: {
2138: scsirate &= SXFR_ULTRA2;
2139: }
2140: else
2141: {
2142: scsirate &= SXFR;
2143: }
2144:
2145: syncrate = &aic7xxx_syncrates[maxsync];
2146: while (syncrate->rate[0] != NULL)
2147: {
2148: if ((p->features & AHC_ULTRA2) != 0)
2149: {
2150: if (syncrate->sxfr_ultra2 == 0)
2151: break;
2152: else if (scsirate == syncrate->sxfr_ultra2)
2153: return (syncrate->period);
2154: }
2155: else if (scsirate == (syncrate->sxfr & ~ULTRA_SXFR))
2156: {
2157: return (syncrate->period);
2158: }
2159: syncrate++;
2160: }
2161: return (0); /* async */
2162: }
2163:
2164: /*+F*************************************************************************
2165: * Function:
2166: * aic7xxx_validate_offset
2167: *
2168: * Description:
2169: * Set a valid offset value for a particular card in use and transfer
2170: * settings in use.
2171: *-F*************************************************************************/
2172: static void
2173: aic7xxx_validate_offset(struct aic7xxx_host *p,
2174: struct aic7xxx_syncrate *syncrate, unsigned int *offset, int wide)
2175: {
2176: unsigned int maxoffset;
2177:
2178: /* Limit offset to what the card (and device) can do */
2179: if (syncrate == NULL)
2180: {
2181: maxoffset = 0;
2182: }
2183: else if (p->features & AHC_ULTRA2)
2184: {
2185: maxoffset = MAX_OFFSET_ULTRA2;
2186: }
2187: else
2188: {
2189: if (wide)
2190: maxoffset = MAX_OFFSET_16BIT;
2191: else
2192: maxoffset = MAX_OFFSET_8BIT;
2193: }
2194: *offset = MIN(*offset, maxoffset);
2195: }
2196:
2197: /*+F*************************************************************************
2198: * Function:
2199: * aic7xxx_set_syncrate
2200: *
2201: * Description:
2202: * Set the actual syncrate down in the card and in our host structs
2203: *-F*************************************************************************/
2204: static void
2205: aic7xxx_set_syncrate(struct aic7xxx_host *p, struct aic7xxx_syncrate *syncrate,
2206: int target, int channel, unsigned int period, unsigned int offset,
2207: unsigned int type)
2208: {
2209: unsigned char tindex;
2210: unsigned short target_mask;
2211: unsigned char lun;
2212: unsigned int old_period, old_offset;
2213:
2214: tindex = target | (channel << 3);
2215: target_mask = 0x01 << tindex;
2216: lun = aic_inb(p, SCB_TCL) & 0x07;
2217:
2218: if (syncrate == NULL)
2219: {
2220: period = 0;
2221: offset = 0;
2222: }
2223:
2224: old_period = p->transinfo[tindex].cur_period;
2225: old_offset = p->transinfo[tindex].cur_offset;
2226:
2227:
2228: if (type & AHC_TRANS_CUR)
2229: {
2230: unsigned int scsirate;
2231:
2232: scsirate = aic_inb(p, TARG_SCSIRATE + tindex);
2233: if (p->features & AHC_ULTRA2)
2234: {
2235: scsirate &= ~SXFR_ULTRA2;
2236: if (syncrate != NULL)
2237: {
2238: scsirate |= syncrate->sxfr_ultra2;
2239: }
2240: if (type & AHC_TRANS_ACTIVE)
2241: {
2242: aic_outb(p, offset, SCSIOFFSET);
2243: }
2244: aic_outb(p, offset, TARG_OFFSET + tindex);
2245: }
2246: else /* Not an Ultra2 controller */
2247: {
2248: scsirate &= ~(SXFR|SOFS);
2249: p->ultraenb &= ~target_mask;
2250: if (syncrate != NULL)
2251: {
2252: if (syncrate->sxfr & ULTRA_SXFR)
2253: {
2254: p->ultraenb |= target_mask;
2255: }
2256: scsirate |= (syncrate->sxfr & SXFR);
2257: scsirate |= (offset & SOFS);
2258: }
2259: if (type & AHC_TRANS_ACTIVE)
2260: {
2261: unsigned char sxfrctl0;
2262:
2263: sxfrctl0 = aic_inb(p, SXFRCTL0);
2264: sxfrctl0 &= ~FAST20;
2265: if (p->ultraenb & target_mask)
2266: sxfrctl0 |= FAST20;
2267: aic_outb(p, sxfrctl0, SXFRCTL0);
2268: }
2269: aic_outb(p, p->ultraenb & 0xff, ULTRA_ENB);
2270: aic_outb(p, (p->ultraenb >> 8) & 0xff, ULTRA_ENB + 1 );
2271: }
2272: if (type & AHC_TRANS_ACTIVE)
2273: {
2274: aic_outb(p, scsirate, SCSIRATE);
2275: }
2276: aic_outb(p, scsirate, TARG_SCSIRATE + tindex);
2277: p->transinfo[tindex].cur_period = period;
2278: p->transinfo[tindex].cur_offset = offset;
2279: if ( !(type & AHC_TRANS_QUITE) &&
2280: (aic7xxx_verbose & VERBOSE_NEGOTIATION) &&
2281: (p->dev_flags[tindex] & DEVICE_PRINT_SDTR) )
2282: {
2283: if (offset)
2284: {
2285: int rate_mod = (scsirate & WIDEXFER) ? 1 : 0;
2286:
2287: printk(INFO_LEAD "Synchronous at %s Mbyte/sec, "
2288: "offset %d.\n", p->host_no, channel, target, lun,
2289: syncrate->rate[rate_mod], offset);
2290: }
2291: else
2292: {
2293: printk(INFO_LEAD "Using asynchronous transfers.\n",
2294: p->host_no, channel, target, lun);
2295: }
2296: p->dev_flags[tindex] &= ~DEVICE_PRINT_SDTR;
2297: }
2298: }
2299:
2300: if (type & AHC_TRANS_GOAL)
2301: {
2302: p->transinfo[tindex].goal_period = period;
2303: p->transinfo[tindex].goal_offset = offset;
2304: }
2305:
2306: if (type & AHC_TRANS_USER)
2307: {
2308: p->transinfo[tindex].user_period = period;
2309: p->transinfo[tindex].user_offset = offset;
2310: }
2311: }
2312:
2313: /*+F*************************************************************************
2314: * Function:
2315: * aic7xxx_set_width
2316: *
2317: * Description:
2318: * Set the actual width down in the card and in our host structs
2319: *-F*************************************************************************/
2320: static void
2321: aic7xxx_set_width(struct aic7xxx_host *p, int target, int channel, int lun,
2322: unsigned int width, unsigned int type)
2323: {
2324: unsigned char tindex;
2325: unsigned short target_mask;
2326: unsigned int old_width, new_offset;
2327:
2328: tindex = target | (channel << 3);
2329: target_mask = 1 << tindex;
2330:
2331: old_width = p->transinfo[tindex].cur_width;
2332:
2333: if (p->features & AHC_ULTRA2)
2334: new_offset = MAX_OFFSET_ULTRA2;
2335: else if (width == MSG_EXT_WDTR_BUS_16_BIT)
2336: new_offset = MAX_OFFSET_16BIT;
2337: else
2338: new_offset = MAX_OFFSET_8BIT;
2339:
2340: if (type & AHC_TRANS_CUR)
2341: {
2342: unsigned char scsirate;
2343:
2344: scsirate = aic_inb(p, TARG_SCSIRATE + tindex);
2345:
2346: scsirate &= ~WIDEXFER;
2347: if (width == MSG_EXT_WDTR_BUS_16_BIT)
2348: scsirate |= WIDEXFER;
2349:
2350: aic_outb(p, scsirate, TARG_SCSIRATE + tindex);
2351:
2352: if (type & AHC_TRANS_ACTIVE)
2353: aic_outb(p, scsirate, SCSIRATE);
2354:
2355: p->transinfo[tindex].cur_width = width;
2356:
2357: if ((aic7xxx_verbose & VERBOSE_NEGOTIATION2) &&
2358: (p->dev_flags[tindex] & DEVICE_PRINT_WDTR))
2359: {
2360: printk(INFO_LEAD "Using %s transfers\n", p->host_no, channel, target,
2361: lun, (scsirate & WIDEXFER) ? "Wide(16bit)" : "Narrow(8bit)" );
2362: p->dev_flags[tindex] &= ~DEVICE_PRINT_WDTR;
2363: }
2364: }
2365:
2366: if (type & AHC_TRANS_GOAL)
2367: p->transinfo[tindex].goal_width = width;
2368: if (type & AHC_TRANS_USER)
2369: p->transinfo[tindex].user_width = width;
2370:
2371: /*
2372: * Having just set the width, the SDTR should come next, and we need a valid
2373: * offset for the SDTR. So, we make sure we put a valid one in here now as
2374: * the goal_offset.
2375: */
2376: if (p->transinfo[tindex].goal_offset)
2377: p->transinfo[tindex].goal_offset = new_offset;
2378:
2379: }
2380:
2381: /*+F*************************************************************************
2382: * Function:
2383: * scbq_init
2384: *
2385: * Description:
2386: * SCB queue initialization.
2387: *
2388: *-F*************************************************************************/
2389: static void
2390: scbq_init(volatile scb_queue_type *queue)
2391: {
2392: queue->head = NULL;
2393: queue->tail = NULL;
2394: }
2395:
2396: /*+F*************************************************************************
2397: * Function:
2398: * scbq_insert_head
2399: *
2400: * Description:
2401: * Add an SCB to the head of the list.
2402: *
2403: *-F*************************************************************************/
2404: static inline void
2405: scbq_insert_head(volatile scb_queue_type *queue, struct aic7xxx_scb *scb)
2406: {
2407: #if LINUX_VERSION_CODE < KERNEL_VERSION(2,1,95)
2408: unsigned long cpu_flags;
2409: #endif
2410:
2411: DRIVER_LOCK
2412: scb->q_next = queue->head;
2413: queue->head = scb;
2414: if (queue->tail == NULL) /* If list was empty, update tail. */
2415: queue->tail = queue->head;
2416: DRIVER_UNLOCK
2417: }
2418:
2419: /*+F*************************************************************************
2420: * Function:
2421: * scbq_remove_head
2422: *
2423: * Description:
2424: * Remove an SCB from the head of the list.
2425: *
2426: *-F*************************************************************************/
2427: static inline struct aic7xxx_scb *
2428: scbq_remove_head(volatile scb_queue_type *queue)
2429: {
2430: struct aic7xxx_scb * scbp;
2431: #if LINUX_VERSION_CODE < KERNEL_VERSION(2,1,95)
2432: unsigned long cpu_flags;
2433: #endif
2434:
2435: DRIVER_LOCK
2436: scbp = queue->head;
2437: if (queue->head != NULL)
2438: queue->head = queue->head->q_next;
2439: if (queue->head == NULL) /* If list is now empty, update tail. */
2440: queue->tail = NULL;
2441: DRIVER_UNLOCK
2442: return(scbp);
2443: }
2444:
2445: /*+F*************************************************************************
2446: * Function:
2447: * scbq_remove
2448: *
2449: * Description:
2450: * Removes an SCB from the list.
2451: *
2452: *-F*************************************************************************/
2453: static inline void
2454: scbq_remove(volatile scb_queue_type *queue, struct aic7xxx_scb *scb)
2455: {
2456: #if LINUX_VERSION_CODE < KERNEL_VERSION(2,1,95)
2457: unsigned long cpu_flags;
2458: #endif
2459:
2460: DRIVER_LOCK
2461: if (queue->head == scb)
2462: {
2463: /* At beginning of queue, remove from head. */
2464: scbq_remove_head(queue);
2465: }
2466: else
2467: {
2468: struct aic7xxx_scb *curscb = queue->head;
2469:
2470: /*
2471: * Search until the next scb is the one we're looking for, or
2472: * we run out of queue.
2473: */
2474: while ((curscb != NULL) && (curscb->q_next != scb))
2475: {
2476: curscb = curscb->q_next;
2477: }
2478: if (curscb != NULL)
2479: {
2480: /* Found it. */
2481: curscb->q_next = scb->q_next;
2482: if (scb->q_next == NULL)
2483: {
2484: /* Update the tail when removing the tail. */
2485: queue->tail = curscb;
2486: }
2487: }
2488: }
2489: DRIVER_UNLOCK
2490: }
2491:
2492: /*+F*************************************************************************
2493: * Function:
2494: * scbq_insert_tail
2495: *
2496: * Description:
2497: * Add an SCB at the tail of the list.
2498: *
2499: *-F*************************************************************************/
2500: static inline void
2501: scbq_insert_tail(volatile scb_queue_type *queue, struct aic7xxx_scb *scb)
2502: {
2503: #if LINUX_VERSION_CODE < KERNEL_VERSION(2,1,95)
2504: unsigned long cpu_flags;
2505: #endif
2506:
2507: DRIVER_LOCK
2508: scb->q_next = NULL;
2509: if (queue->tail != NULL) /* Add the scb at the end of the list. */
2510: queue->tail->q_next = scb;
2511: queue->tail = scb; /* Update the tail. */
2512: if (queue->head == NULL) /* If list was empty, update head. */
2513: queue->head = queue->tail;
2514: DRIVER_UNLOCK
2515: }
2516:
2517: /*+F*************************************************************************
2518: * Function:
2519: * aic7xxx_match_scb
2520: *
2521: * Description:
2522: * Checks to see if an scb matches the target/channel as specified.
2523: * If target is ALL_TARGETS (-1), then we're looking for any device
2524: * on the specified channel; this happens when a channel is going
2525: * to be reset and all devices on that channel must be aborted.
2526: *-F*************************************************************************/
2527: static int
2528: aic7xxx_match_scb(struct aic7xxx_host *p, struct aic7xxx_scb *scb,
2529: int target, int channel, int lun, unsigned char tag)
2530: {
2531: int targ = (scb->hscb->target_channel_lun >> 4) & 0x0F;
2532: int chan = (scb->hscb->target_channel_lun >> 3) & 0x01;
2533: int slun = scb->hscb->target_channel_lun & 0x07;
2534: int match;
2535:
2536: match = ((chan == channel) || (channel == ALL_CHANNELS));
2537: if (match != 0)
2538: match = ((targ == target) || (target == ALL_TARGETS));
2539: if (match != 0)
2540: match = ((lun == slun) || (lun == ALL_LUNS));
2541: if (match != 0)
2542: match = ((tag == scb->hscb->tag) || (tag == SCB_LIST_NULL));
2543:
2544: if (aic7xxx_verbose & (VERBOSE_ABORT_PROCESS | VERBOSE_RESET_PROCESS))
2545: {
2546: printk(KERN_INFO "(scsi%d:%d:%d:%d:tag%d) %s search criteria"
2547: " (scsi%d:%d:%d:%d:tag%d)\n", p->host_no, CTL_OF_SCB(scb),
2548: scb->hscb->tag, (match) ? "matches" : "doesn't match",
2549: p->host_no, channel, target, lun, tag);
2550: }
2551:
2552: return (match);
2553: }
2554:
2555: /*+F*************************************************************************
2556: * Function:
2557: * aic7xxx_add_curscb_to_free_list
2558: *
2559: * Description:
2560: * Adds the current scb (in SCBPTR) to the list of free SCBs.
2561: *-F*************************************************************************/
2562: static void
2563: aic7xxx_add_curscb_to_free_list(struct aic7xxx_host *p)
2564: {
2565: /*
2566: * Invalidate the tag so that aic7xxx_find_scb doesn't think
2567: * it's active
2568: */
2569: aic_outb(p, SCB_LIST_NULL, SCB_TAG);
2570: aic_outb(p, 0, SCB_CONTROL);
2571:
2572: aic_outb(p, aic_inb(p, FREE_SCBH), SCB_NEXT);
2573: aic_outb(p, aic_inb(p, SCBPTR), FREE_SCBH);
2574: }
2575:
2576: /*+F*************************************************************************
2577: * Function:
2578: * aic7xxx_rem_scb_from_disc_list
2579: *
2580: * Description:
2581: * Removes the current SCB from the disconnected list and adds it
2582: * to the free list.
2583: *-F*************************************************************************/
2584: static unsigned char
2585: aic7xxx_rem_scb_from_disc_list(struct aic7xxx_host *p, unsigned char scbptr)
2586: {
2587: unsigned char next;
2588: unsigned char prev;
2589:
2590: aic_outb(p, scbptr, SCBPTR);
2591: next = aic_inb(p, SCB_NEXT);
2592: prev = aic_inb(p, SCB_PREV);
2593: aic7xxx_add_curscb_to_free_list(p);
2594:
2595: if (prev != SCB_LIST_NULL)
2596: {
2597: aic_outb(p, prev, SCBPTR);
2598: aic_outb(p, next, SCB_NEXT);
2599: }
2600: else
2601: {
2602: aic_outb(p, next, DISCONNECTED_SCBH);
2603: }
2604:
2605: if (next != SCB_LIST_NULL)
2606: {
2607: aic_outb(p, next, SCBPTR);
2608: aic_outb(p, prev, SCB_PREV);
2609: }
2610: return next;
2611: }
2612:
2613: /*+F*************************************************************************
2614: * Function:
2615: * aic7xxx_busy_target
2616: *
2617: * Description:
2618: * Set the specified target busy.
2619: *-F*************************************************************************/
2620: static inline void
2621: aic7xxx_busy_target(struct aic7xxx_host *p, struct aic7xxx_scb *scb)
2622: {
2623: p->untagged_scbs[scb->hscb->target_channel_lun] = scb->hscb->tag;
2624: }
2625:
2626: /*+F*************************************************************************
2627: * Function:
2628: * aic7xxx_index_busy_target
2629: *
2630: * Description:
2631: * Returns the index of the busy target, and optionally sets the
2632: * target inactive.
2633: *-F*************************************************************************/
2634: static inline unsigned char
2635: aic7xxx_index_busy_target(struct aic7xxx_host *p, unsigned char tcl,
2636: int unbusy)
2637: {
2638: unsigned char busy_scbid;
2639:
2640: busy_scbid = p->untagged_scbs[tcl];
2641: if (unbusy)
2642: {
2643: p->untagged_scbs[tcl] = SCB_LIST_NULL;
2644: }
2645: return (busy_scbid);
2646: }
2647:
2648: /*+F*************************************************************************
2649: * Function:
2650: * aic7xxx_find_scb
2651: *
2652: * Description:
2653: * Look through the SCB array of the card and attempt to find the
2654: * hardware SCB that corresponds to the passed in SCB. Return
2655: * SCB_LIST_NULL if unsuccessful. This routine assumes that the
2656: * card is already paused.
2657: *-F*************************************************************************/
2658: static unsigned char
2659: aic7xxx_find_scb(struct aic7xxx_host *p, struct aic7xxx_scb *scb)
2660: {
2661: unsigned char saved_scbptr;
2662: unsigned char curindex;
2663:
2664: saved_scbptr = aic_inb(p, SCBPTR);
2665: curindex = 0;
2666: for (curindex = 0; curindex < p->scb_data->maxhscbs; curindex++)
2667: {
2668: aic_outb(p, curindex, SCBPTR);
2669: if (aic_inb(p, SCB_TAG) == scb->hscb->tag)
2670: {
2671: break;
2672: }
2673: }
2674: aic_outb(p, saved_scbptr, SCBPTR);
2675: if (curindex >= p->scb_data->maxhscbs)
2676: {
2677: curindex = SCB_LIST_NULL;
2678: }
2679:
2680: return (curindex);
2681: }
2682:
2683: /*+F*************************************************************************
2684: * Function:
2685: * aic7xxx_allocate_scb
2686: *
2687: * Description:
2688: * Get an SCB from the free list or by allocating a new one.
2689: *-F*************************************************************************/
2690: static int
2691: aic7xxx_allocate_scb(struct aic7xxx_host *p)
2692: {
2693: struct aic7xxx_scb *scbp = NULL;
2694: int scb_size = sizeof(struct aic7xxx_scb) +
2695: sizeof (struct hw_scatterlist) * AIC7XXX_MAX_SG;
2696: int i;
2697: int step = PAGE_SIZE / 1024;
2698: unsigned long scb_count = 0;
2699: struct hw_scatterlist *hsgp;
2700: struct aic7xxx_scb *scb_ap;
2701: unsigned long temp;
2702:
2703:
2704: if (p->scb_data->numscbs < p->scb_data->maxscbs)
2705: {
2706: /*
2707: * Calculate the optimal number of SCBs to allocate.
2708: *
2709: * NOTE: This formula works because the sizeof(sg_array) is always
2710: * 1024. Therefore, scb_size * i would always be > PAGE_SIZE *
2711: * (i/step). The (i-1) allows the left hand side of the equation
2712: * to grow into the right hand side to a point of near perfect
2713: * efficiency since scb_size * (i -1) is growing slightly faster
2714: * than the right hand side. If the number of SG array elements
2715: * is changed, this function may not be near so efficient any more.
2716: */
2717: for ( i=step;; i *= 2 )
2718: {
2719: if ( (scb_size * (i-1)) >= ( (PAGE_SIZE * (i/step)) - 64 ) )
2720: {
2721: i /= 2;
2722: break;
2723: }
2724: }
2725: scb_count = MIN( (i-1), p->scb_data->maxscbs - p->scb_data->numscbs);
2726: scb_ap = (struct aic7xxx_scb *)kmalloc(scb_size * scb_count, GFP_ATOMIC);
2727: if (scb_ap != NULL)
2728: {
2729: #ifdef AIC7XXX_VERBOSE_DEBUGGING
2730: if (aic7xxx_verbose > 0xffff)
2731: {
2732: if (p->scb_data->numscbs == 0)
2733: printk(INFO_LEAD "Allocating initial %ld SCB structures.\n",
2734: p->host_no, -1, -1, -1, scb_count);
2735: else
2736: printk(INFO_LEAD "Allocating %ld additional SCB structures.\n",
2737: p->host_no, -1, -1, -1, scb_count);
2738: }
2739: #endif
2740: memset(scb_ap, 0, scb_count * scb_size);
2741: temp = (unsigned long) &scb_ap[scb_count];
2742: temp += 1023;
2743: temp &= ~1023;
2744: hsgp = (struct hw_scatterlist *)temp;
2745: for (i=0; i < scb_count; i++)
2746: {
2747: scbp = &scb_ap[i];
2748: scbp->hscb = &p->scb_data->hscbs[p->scb_data->numscbs];
2749: scbp->sg_list = &hsgp[i * AIC7XXX_MAX_SG];
2750: memset(scbp->hscb, 0, sizeof(struct aic7xxx_hwscb));
2751: scbp->hscb->tag = p->scb_data->numscbs;
2752: /*
2753: * Place in the scb array; never is removed
2754: */
2755: p->scb_data->scb_array[p->scb_data->numscbs++] = scbp;
2756: scbq_insert_head(&p->scb_data->free_scbs, scbp);
2757: }
2758: scbp->kmalloc_ptr = scb_ap;
2759: }
2760: else
2761: {
2762: return(0);
2763: }
2764: }
2765: return(scb_count);
2766: }
2767:
2768: /*+F*************************************************************************
2769: * Function:
2770: * aic7xxx_queue_cmd_complete
2771: *
2772: * Description:
2773: * Due to race conditions present in the SCSI subsystem, it is easier
2774: * to queue completed commands, then call scsi_done() on them when
2775: * we're finished. This function queues the completed commands.
2776: *-F*************************************************************************/
2777: static void
2778: aic7xxx_queue_cmd_complete(struct aic7xxx_host *p, Scsi_Cmnd *cmd)
2779: {
2780: cmd->host_scribble = (char *)p->completeq.head;
2781: p->completeq.head = cmd;
2782: }
2783:
2784: /*+F*************************************************************************
2785: * Function:
2786: * aic7xxx_done_cmds_complete
2787: *
2788: * Description:
2789: * Process the completed command queue.
2790: *-F*************************************************************************/
2791: static void
2792: aic7xxx_done_cmds_complete(struct aic7xxx_host *p)
2793: {
2794: Scsi_Cmnd *cmd;
2795: #if LINUX_VERSION_CODE < KERNEL_VERSION(2,1,95)
2796: unsigned int cpu_flags = 0;
2797:
2798: DRIVER_LOCK
2799: while (p->completeq.head != NULL)
2800: {
2801: cmd = p->completeq.head;
2802: p->completeq.head = (Scsi_Cmnd *)cmd->host_scribble;
2803: cmd->host_scribble = NULL;
2804: sti();
2805: cmd->scsi_done(cmd);
2806: cli();
2807: }
2808: DRIVER_UNLOCK
2809: #else
2810: while (p->completeq.head != NULL)
2811: {
2812: cmd = p->completeq.head;
2813: p->completeq.head = (Scsi_Cmnd *)cmd->host_scribble;
2814: cmd->host_scribble = NULL;
2815: cmd->scsi_done(cmd);
2816: }
2817: #endif
2818: }
2819:
2820: /*+F*************************************************************************
2821: * Function:
2822: * aic7xxx_free_scb
2823: *
2824: * Description:
2825: * Free the scb and insert into the free scb list.
2826: *-F*************************************************************************/
2827: static void
2828: aic7xxx_free_scb(struct aic7xxx_host *p, struct aic7xxx_scb *scb)
2829: {
2830:
2831: scb->flags = SCB_FREE;
2832: scb->cmd = NULL;
2833: scb->sg_count = 0;
2834: scb->sg_length = 0;
2835: scb->tag_action = 0;
2836: scb->hscb->control = 0;
2837: scb->hscb->target_status = 0;
2838: scb->hscb->target_channel_lun = SCB_LIST_NULL;
2839:
2840: scbq_insert_head(&p->scb_data->free_scbs, scb);
2841: }
2842:
2843: /*+F*************************************************************************
2844: * Function:
2845: * aic7xxx_done
2846: *
2847: * Description:
2848: * Calls the higher level scsi done function and frees the scb.
2849: *-F*************************************************************************/
2850: static void
2851: aic7xxx_done(struct aic7xxx_host *p, struct aic7xxx_scb *scb)
2852: {
2853: Scsi_Cmnd *cmd = scb->cmd;
2854: int tindex = TARGET_INDEX(cmd);
2855: struct aic7xxx_scb *scbp;
2856: unsigned char queue_depth;
2857:
2858: if (scb->flags & SCB_RECOVERY_SCB)
2859: {
2860: p->flags &= ~AHC_ABORT_PENDING;
2861: }
2862: if (scb->flags & SCB_RESET)
2863: {
2864: cmd->result = (DID_RESET << 16) | (cmd->result & 0xffff);
2865: }
2866: else if (scb->flags & SCB_ABORT)
2867: {
2868: cmd->result = (DID_RESET << 16) | (cmd->result & 0xffff);
2869: }
2870: else if (!(p->dev_flags[tindex] & DEVICE_SCANNED))
2871: {
2872: if ( (cmd->cmnd[0] == INQUIRY) && (cmd->result == DID_OK) )
2873: {
2874: char *buffer;
2875:
2876: if(cmd->use_sg)
2877: {
2878: struct scatterlist *sg;
2879:
2880: sg = (struct scatterlist *)cmd->request_buffer;
2881: buffer = (char *)sg[0].address;
2882: }
2883: else
2884: {
2885: buffer = (char *)cmd->request_buffer;
2886: }
2887: #define WIDE_INQUIRY_BITS 0x60
2888: #define SYNC_INQUIRY_BITS 0x10
2889: if ( (buffer[7] & WIDE_INQUIRY_BITS) &&
2890: (p->features & AHC_WIDE) )
2891: {
2892: p->needwdtr |= (1<<tindex);
2893: p->needwdtr_copy |= (1<<tindex);
2894: if ( (p->flags & AHC_SEEPROM_FOUND) &&
2895: (p->transinfo[tindex].user_width != MSG_EXT_WDTR_BUS_16_BIT) )
2896: p->transinfo[tindex].goal_width = MSG_EXT_WDTR_BUS_8_BIT;
2897: else
2898: p->transinfo[tindex].goal_width = MSG_EXT_WDTR_BUS_16_BIT;
2899: }
2900: else
2901: {
2902: p->needwdtr &= ~(1<<tindex);
2903: p->needwdtr_copy &= ~(1<<tindex);
2904: pause_sequencer(p);
2905: aic7xxx_set_width(p, cmd->target, cmd->channel, cmd->lun,
2906: MSG_EXT_WDTR_BUS_8_BIT, (AHC_TRANS_ACTIVE |
2907: AHC_TRANS_GOAL |
2908: AHC_TRANS_CUR) );
2909: unpause_sequencer(p, FALSE);
2910: }
2911: if (buffer[7] & SYNC_INQUIRY_BITS)
2912: {
2913: p->needsdtr |= (1<<tindex);
2914: p->needsdtr_copy |= (1<<tindex);
2915:
2916: if (p->flags & AHC_SEEPROM_FOUND)
2917: p->transinfo[tindex].goal_period = p->transinfo[tindex].user_period;
2918: else if (p->features & AHC_ULTRA2)
2919: p->transinfo[tindex].goal_period =
2920: aic7xxx_syncrates[AHC_SYNCRATE_ULTRA2].period;
2921: else if (p->features & AHC_ULTRA)
2922: p->transinfo[tindex].goal_period =
2923: aic7xxx_syncrates[AHC_SYNCRATE_ULTRA].period;
2924: else
2925: p->transinfo[tindex].goal_period =
2926: aic7xxx_syncrates[AHC_SYNCRATE_FAST].period;
2927:
2928: if (p->features & AHC_ULTRA2)
2929: p->transinfo[tindex].goal_offset = MAX_OFFSET_ULTRA2;
2930: else if (p->transinfo[tindex].goal_width == MSG_EXT_WDTR_BUS_16_BIT)
2931: p->transinfo[tindex].goal_offset = MAX_OFFSET_16BIT;
2932: else
2933: p->transinfo[tindex].goal_offset = MAX_OFFSET_8BIT;
2934: }
2935: else
2936: {
2937: p->needsdtr &= ~(1<<tindex);
2938: p->needsdtr_copy &= ~(1<<tindex);
2939: p->transinfo[tindex].goal_period = 0;
2940: p->transinfo[tindex].goal_offset = 0;
2941: }
2942: p->dev_flags[tindex] |= DEVICE_SCANNED;
2943: p->dev_flags[tindex] |= DEVICE_PRINT_WDTR | DEVICE_PRINT_SDTR;
2944: #undef WIDE_INQUIRY_BITS
2945: #undef SYNC_INQUIRY_BITS
2946: }
2947: }
2948: else if ((scb->flags & (SCB_MSGOUT_WDTR | SCB_MSGOUT_SDTR)) != 0)
2949: {
2950: unsigned short mask;
2951: int message_error = FALSE;
2952:
2953: mask = 0x01 << tindex;
2954:
2955: /*
2956: * Check to see if we get an invalid message or a message error
2957: * after failing to negotiate a wide or sync transfer message.
2958: */
2959: if ((scb->flags & SCB_SENSE) &&
2960: ((scb->cmd->sense_buffer[12] == 0x43) || /* INVALID_MESSAGE */
2961: (scb->cmd->sense_buffer[12] == 0x49))) /* MESSAGE_ERROR */
2962: {
2963: message_error = TRUE;
2964: }
2965:
2966: if (scb->flags & SCB_MSGOUT_WDTR)
2967: {
2968: p->wdtr_pending &= ~mask;
2969: if (message_error)
2970: {
2971: if ( (aic7xxx_verbose & VERBOSE_NEGOTIATION2) &&
2972: (p->dev_flags[tindex] & DEVICE_PRINT_WDTR) )
2973: {
2974: printk(INFO_LEAD "Device failed to complete Wide Negotiation "
2975: "processing and\n", p->host_no, CTL_OF_SCB(scb));
2976: printk(INFO_LEAD "returned a sense error code for invalid message, "
2977: "disabling future\n", p->host_no, CTL_OF_SCB(scb));
2978: printk(INFO_LEAD "Wide negotiation to this device.\n", p->host_no,
2979: CTL_OF_SCB(scb));
2980: p->dev_flags[tindex] &= ~DEVICE_PRINT_WDTR;
2981: }
2982: p->needwdtr &= ~mask;
2983: p->needwdtr_copy &= ~mask;
2984: }
2985: }
2986: if (scb->flags & SCB_MSGOUT_SDTR)
2987: {
2988: p->sdtr_pending &= ~mask;
2989: if (message_error)
2990: {
2991: if ( (aic7xxx_verbose & VERBOSE_NEGOTIATION2) &&
2992: (p->dev_flags[tindex] & DEVICE_PRINT_SDTR) )
2993: {
2994: printk(INFO_LEAD "Device failed to complete Sync Negotiation "
2995: "processing and\n", p->host_no, CTL_OF_SCB(scb));
2996: printk(INFO_LEAD "returned a sense error code for invalid message, "
2997: "disabling future\n", p->host_no, CTL_OF_SCB(scb));
2998: printk(INFO_LEAD "Sync negotiation to this device.\n", p->host_no,
2999: CTL_OF_SCB(scb));
3000: p->dev_flags[tindex] &= ~DEVICE_PRINT_SDTR;
3001: }
3002: p->needsdtr &= ~mask;
3003: p->needsdtr_copy &= ~mask;
3004: }
3005: }
3006: }
3007: queue_depth = p->dev_temp_queue_depth[tindex];
3008: if (queue_depth >= p->dev_active_cmds[tindex])
3009: {
3010: scbp = scbq_remove_head(&p->delayed_scbs[tindex]);
3011: if (scbp)
3012: {
3013: if (queue_depth == 1)
3014: {
3015: /*
3016: * Give extra preference to untagged devices, such as CD-R devices
3017: * This makes it more likely that a drive *won't* stuff up while
3018: * waiting on data at a critical time, such as CD-R writing and
3019: * audio CD ripping operations. Should also benefit tape drives.
3020: */
3021: scbq_insert_head(&p->waiting_scbs, scbp);
3022: }
3023: else
3024: {
3025: scbq_insert_tail(&p->waiting_scbs, scbp);
3026: }
3027: #ifdef AIC7XXX_VERBOSE_DEBUGGING
3028: if (aic7xxx_verbose > 0xffff)
3029: printk(INFO_LEAD "Moving SCB from delayed to waiting queue.\n",
3030: p->host_no, CTL_OF_SCB(scbp));
3031: #endif
3032: if (queue_depth > p->dev_active_cmds[tindex])
3033: {
3034: scbp = scbq_remove_head(&p->delayed_scbs[tindex]);
3035: if (scbp)
3036: scbq_insert_tail(&p->waiting_scbs, scbp);
3037: }
3038: }
3039: }
3040: if ( !(scb->tag_action) && (p->tagenable & (1<<tindex)) )
3041: {
3042: p->dev_temp_queue_depth[tindex] = p->dev_max_queue_depth[tindex];
3043: }
3044: p->dev_active_cmds[tindex]--;
3045: p->activescbs--;
3046:
3047: /*
3048: * If this was an untagged I/O, unbusy the target so the sequencer won't
3049: * mistake things later
3050: */
3051: if (aic7xxx_index_busy_target(p, scb->hscb->target_channel_lun, FALSE) ==
3052: scb->hscb->tag)
3053: {
3054: aic7xxx_index_busy_target(p, scb->hscb->target_channel_lun, TRUE);
3055: }
3056:
3057: {
3058: int actual;
3059:
3060: /*
3061: * XXX: we should actually know how much actually transferred
3062: * XXX: for each command, but apparently that's too difficult.
3063: *
3064: * We set a lower limit of 512 bytes on the transfer length. We
3065: * ignore anything less than this because we don't have a real
3066: * reason to count it. Read/Writes to tapes are usually about 20K
3067: * and disks are a minimum of 512 bytes unless you want to count
3068: * non-read/write commands (such as TEST_UNIT_READY) which we don't
3069: */
3070: actual = scb->sg_length;
3071: if ((actual >= 512) && (((cmd->result >> 16) & 0xf) == DID_OK))
3072: {
3073: struct aic7xxx_xferstats *sp;
3074: #ifdef AIC7XXX_PROC_STATS
3075: long *ptr;
3076: int x;
3077: #endif /* AIC7XXX_PROC_STATS */
3078:
3079: sp = &p->stats[TARGET_INDEX(cmd)][cmd->lun & 0x7];
3080: sp->xfers++;
3081: #ifdef AIC7XXX_VERBOSE_DEBUGGING
3082: if ( (sp->xfers > 16) && (aic7xxx_verbose > 0xffff) )
3083: aic7xxx_verbose &= 0xffff;
3084: #endif
3085:
3086: /*
3087: * For block devices, cmd->request.cmd is always == either READ or
3088: * WRITE. For character devices, this isn't always set properly, so
3089: * we check data_cmnd[0]. This catches the conditions for st.c, but
3090: * I'm still not sure if request.cmd is valid for sg devices.
3091: */
3092: if ( (cmd->request.cmd == WRITE) || (cmd->data_cmnd[0] == WRITE_6) ||
3093: (cmd->data_cmnd[0] == WRITE_FILEMARKS) )
3094: {
3095: sp->w_total++;
3096: sp->w_total512 += (actual >> 9);
3097: #ifdef AIC7XXX_PROC_STATS
3098: ptr = sp->w_bins;
3099: #endif /* AIC7XXX_PROC_STATS */
3100: }
3101: else
3102: {
3103: sp->r_total++;
3104: sp->r_total512 += (actual >> 9);
3105: #ifdef AIC7XXX_PROC_STATS
3106: ptr = sp->r_bins;
3107: #endif /* AIC7XXX_PROC_STATS */
3108: }
3109: #ifdef AIC7XXX_PROC_STATS
3110: for (x = 9; x <= 17; x++)
3111: {
3112: if (actual < (1 << x))
3113: {
3114: ptr[x - 9]++;
3115: break;
3116: }
3117: }
3118: if (x > 17)
3119: {
3120: ptr[x - 9]++;
3121: }
3122: #endif /* AIC7XXX_PROC_STATS */
3123: }
3124: }
3125: aic7xxx_free_scb(p, scb);
3126: aic7xxx_queue_cmd_complete(p, cmd);
3127:
3128: }
3129:
3130: /*+F*************************************************************************
3131: * Function:
3132: * aic7xxx_run_done_queue
3133: *
3134: * Description:
3135: * Calls the aic7xxx_done() for the Scsi_Cmnd of each scb in the
3136: * aborted list, and adds each scb to the free list. If complete
3137: * is TRUE, we also process the commands complete list.
3138: *-F*************************************************************************/
3139: static void
3140: aic7xxx_run_done_queue(struct aic7xxx_host *p, /*complete*/ int complete)
3141: {
3142: struct aic7xxx_scb *scb;
3143: int i, found = 0;
3144:
3145: for (i = 0; i < p->scb_data->numscbs; i++)
3146: {
3147: scb = p->scb_data->scb_array[i];
3148: if (scb->flags & SCB_QUEUED_FOR_DONE)
3149: {
3150: if (aic7xxx_verbose & (VERBOSE_ABORT_PROCESS | VERBOSE_RESET_PROCESS))
3151: printk(INFO_LEAD "Aborting scb %d\n",
3152: p->host_no, CTL_OF_SCB(scb), scb->hscb->tag);
3153: found++;
3154: aic7xxx_done(p, scb);
3155: }
3156: }
3157: if (aic7xxx_verbose & (VERBOSE_ABORT_RETURN | VERBOSE_RESET_RETURN))
3158: {
3159: printk(INFO_LEAD "%d commands found and queued for "
3160: "completion.\n", p->host_no, -1, -1, -1, found);
3161: }
3162: if (complete)
3163: {
3164: aic7xxx_done_cmds_complete(p);
3165: }
3166: }
3167:
3168: /*+F*************************************************************************
3169: * Function:
3170: * aic7xxx_abort_waiting_scb
3171: *
3172: * Description:
3173: * Manipulate the waiting for selection list and return the
3174: * scb that follows the one that we remove.
3175: *-F*************************************************************************/
3176: static unsigned char
3177: aic7xxx_abort_waiting_scb(struct aic7xxx_host *p, struct aic7xxx_scb *scb,
3178: unsigned char scbpos, unsigned char prev)
3179: {
3180: unsigned char curscb, next;
3181:
3182: /*
3183: * Select the SCB we want to abort and pull the next pointer out of it.
3184: */
3185: curscb = aic_inb(p, SCBPTR);
3186: aic_outb(p, scbpos, SCBPTR);
3187: next = aic_inb(p, SCB_NEXT);
3188:
3189: aic7xxx_add_curscb_to_free_list(p);
3190:
3191: /*
3192: * Update the waiting list
3193: */
3194: if (prev == SCB_LIST_NULL)
3195: {
3196: /*
3197: * First in the list
3198: */
3199: aic_outb(p, next, WAITING_SCBH);
3200: }
3201: else
3202: {
3203: /*
3204: * Select the scb that pointed to us and update its next pointer.
3205: */
3206: aic_outb(p, prev, SCBPTR);
3207: aic_outb(p, next, SCB_NEXT);
3208: }
3209: /*
3210: * Point us back at the original scb position and inform the SCSI
3211: * system that the command has been aborted.
3212: */
3213: aic_outb(p, curscb, SCBPTR);
3214: return (next);
3215: }
3216:
3217: /*+F*************************************************************************
3218: * Function:
3219: * aic7xxx_search_qinfifo
3220: *
3221: * Description:
3222: * Search the queue-in FIFO for matching SCBs and conditionally
3223: * requeue. Returns the number of matching SCBs.
3224: *-F*************************************************************************/
3225: static int
3226: aic7xxx_search_qinfifo(struct aic7xxx_host *p, int target, int channel,
3227: int lun, unsigned char tag, int flags, int requeue,
3228: volatile scb_queue_type *queue)
3229: {
3230: int found;
3231: unsigned char qinpos, qintail;
3232: struct aic7xxx_scb *scbp;
3233:
3234: found = 0;
3235: qinpos = aic_inb(p, QINPOS);
3236: qintail = p->qinfifonext;
3237:
3238: p->qinfifonext = qinpos;
3239:
3240: while (qinpos != qintail)
3241: {
3242: scbp = p->scb_data->scb_array[p->qinfifo[qinpos++]];
3243: if (aic7xxx_match_scb(p, scbp, target, channel, lun, tag))
3244: {
3245: /*
3246: * We found an scb that needs to be removed.
3247: */
3248: if (requeue && (queue != NULL))
3249: {
3250: if (scbp->flags & SCB_WAITINGQ)
3251: {
3252: scbq_remove(queue, scbp);
3253: scbq_remove(&p->waiting_scbs, scbp);
3254: scbq_remove(&p->delayed_scbs[TARGET_INDEX(scbp->cmd)], scbp);
3255: p->dev_active_cmds[TARGET_INDEX(scbp->cmd)]++;
3256: p->activescbs++;
3257: }
3258: scbq_insert_tail(queue, scbp);
3259: p->dev_active_cmds[TARGET_INDEX(scbp->cmd)]--;
3260: p->activescbs--;
3261: scbp->flags |= SCB_WAITINGQ;
3262: if ( !(scbp->tag_action & TAG_ENB) )
3263: {
3264: aic7xxx_index_busy_target(p, scbp->hscb->target_channel_lun,
3265: TRUE);
3266: }
3267: }
3268: else if (requeue)
3269: {
3270: p->qinfifo[p->qinfifonext++] = scbp->hscb->tag;
3271: }
3272: else
3273: {
3274: /*
3275: * Preserve any SCB_RECOVERY_SCB flags on this scb then set the
3276: * flags we were called with, presumeably so aic7xxx_run_done_queue
3277: * can find this scb
3278: */
3279: scbp->flags = flags | (scbp->flags & SCB_RECOVERY_SCB);
3280: if (aic7xxx_index_busy_target(p, scbp->hscb->target_channel_lun,
3281: FALSE) == scbp->hscb->tag)
3282: {
3283: aic7xxx_index_busy_target(p, scbp->hscb->target_channel_lun,
3284: TRUE);
3285: }
3286: }
3287: found++;
3288: }
3289: else
3290: {
3291: p->qinfifo[p->qinfifonext++] = scbp->hscb->tag;
3292: }
3293: }
3294: /*
3295: * Now that we've done the work, clear out any left over commands in the
3296: * qinfifo and update the KERNEL_QINPOS down on the card.
3297: *
3298: * NOTE: This routine expect the sequencer to already be paused when
3299: * it is run....make sure it's that way!
3300: */
3301: qinpos = p->qinfifonext;
3302: while(qinpos != qintail)
3303: {
3304: p->qinfifo[qinpos++] = SCB_LIST_NULL;
3305: }
3306: if (p->features & AHC_QUEUE_REGS)
3307: aic_outb(p, p->qinfifonext, HNSCB_QOFF);
3308: else
3309: aic_outb(p, p->qinfifonext, KERNEL_QINPOS);
3310:
3311: return (found);
3312: }
3313:
3314: /*+F*************************************************************************
3315: * Function:
3316: * aic7xxx_scb_on_qoutfifo
3317: *
3318: * Description:
3319: * Is the scb that was passed to us currently on the qoutfifo?
3320: *-F*************************************************************************/
3321: static int
3322: aic7xxx_scb_on_qoutfifo(struct aic7xxx_host *p, struct aic7xxx_scb *scb)
3323: {
3324: int i=0;
3325:
3326: while(p->qoutfifo[(p->qoutfifonext + i) & 0xff ] != SCB_LIST_NULL)
3327: {
3328: if(p->qoutfifo[(p->qoutfifonext + i) & 0xff ] == scb->hscb->tag)
3329: return TRUE;
3330: else
3331: i++;
3332: }
3333: return FALSE;
3334: }
3335:
3336:
3337: /*+F*************************************************************************
3338: * Function:
3339: * aic7xxx_reset_device
3340: *
3341: * Description:
3342: * The device at the given target/channel has been reset. Abort
3343: * all active and queued scbs for that target/channel. This function
3344: * need not worry about linked next pointers because if was a MSG_ABORT_TAG
3345: * then we had a tagged command (no linked next), if it was MSG_ABORT or
3346: * MSG_BUS_DEV_RESET then the device won't know about any commands any more
3347: * and no busy commands will exist, and if it was a bus reset, then nothing
3348: * knows about any linked next commands any more. In all cases, we don't
3349: * need to worry about the linked next or busy scb, we just need to clear
3350: * them.
3351: *-F*************************************************************************/
3352: static void
3353: aic7xxx_reset_device(struct aic7xxx_host *p, int target, int channel,
3354: int lun, unsigned char tag)
3355: {
3356: struct aic7xxx_scb *scbp;
3357: unsigned char active_scb, tcl;
3358: int i = 0, j, init_lists = FALSE;
3359:
3360: /*
3361: * Restore this when we're done
3362: */
3363: active_scb = aic_inb(p, SCBPTR);
3364:
3365: if (aic7xxx_verbose & (VERBOSE_RESET_PROCESS | VERBOSE_ABORT_PROCESS))
3366: printk(INFO_LEAD "Reset device, active_scb %d\n",
3367: p->host_no, channel, target, lun, active_scb);
3368: /*
3369: * Deal with the busy target and linked next issues.
3370: */
3371: {
3372: int min_target, max_target;
3373: struct aic7xxx_scb *scbp, *prev_scbp;
3374:
3375: /* Make all targets 'relative' to bus A. */
3376: if (target == ALL_TARGETS)
3377: {
3378: switch (channel)
3379: {
3380: case 0:
3381: min_target = 0;
3382: max_target = (p->features & AHC_WIDE) ? 15 : 7;
3383: break;
3384: case 1:
3385: min_target = 8;
3386: max_target = 15;
3387: break;
3388: case ALL_CHANNELS:
3389: default:
3390: min_target = 0;
3391: max_target = (p->features & (AHC_TWIN|AHC_WIDE)) ? 15 : 7;
3392: break;
3393: }
3394: }
3395: else
3396: {
3397: min_target = target | (channel << 3);
3398: max_target = min_target;
3399: }
3400:
3401:
3402: for (i = min_target; i <= max_target; i++)
3403: {
3404: if (aic7xxx_verbose & (VERBOSE_ABORT_PROCESS | VERBOSE_RESET_PROCESS))
3405: printk(INFO_LEAD "Cleaning up status information "
3406: "and delayed_scbs.\n", p->host_no, channel, i, lun);
3407: if ( !(p->dev_flags[i] & DEVICE_TAGGED_SUCCESS) &&
3408: (p->dev_active_cmds[i]) &&
3409: (p->tagenable & (0x01 << i)) )
3410: {
3411: printk(INFO_LEAD "Device appears to be choking on tagged commands.\n",
3412: p->host_no, channel, i, lun);
3413: printk(INFO_LEAD "Will use untagged I/O instead.\n", p->host_no,
3414: channel, i, lun);
3415: p->dev_max_queue_depth[i] = 1;
3416: p->dev_temp_queue_depth[i] = 1;
3417: p->tagenable &= ~(0x01 << i);
3418: p->orderedtag &= ~(0x01 << i);
3419: }
3420: p->dev_flags[i] &= ~BUS_DEVICE_RESET_PENDING;
3421: if ( tag == SCB_LIST_NULL )
3422: {
3423: p->dev_flags[i] |= DEVICE_PRINT_WDTR | DEVICE_PRINT_SDTR;
3424: p->dev_last_reset[i] = jiffies;
3425: p->dev_last_queue_full_count[i] = 0;
3426: p->dev_last_queue_full[i] = 0;
3427: p->dev_temp_queue_depth[i] =
3428: p->dev_max_queue_depth[i];
3429: /*
3430: * In case this isn't a full bus reset, we want to add a 4 second timer in
3431: * here so that we can delay all re-sent commands for this device for the
3432: * 4 seconds and then have our timer routine pick them back up.
3433: */
3434: if(p->dev_timer[i].expires)
3435: {
3436: del_timer(&p->dev_timer[i]);
3437: }
3438: p->dev_timer[i].expires = jiffies + (4 * HZ);
3439: add_timer(&p->dev_timer[i]);
3440: }
3441: for(j=0; j<MAX_LUNS; j++)
3442: {
3443: if (channel == 1)
3444: tcl = ((i << 4) & 0x70) | (channel << 3) | j;
3445: else
3446: tcl = (i << 4) | (channel << 3) | j;
3447: if ( (aic7xxx_index_busy_target(p, tcl, FALSE) == tag) ||
3448: (tag == SCB_LIST_NULL) )
3449: aic7xxx_index_busy_target(p, tcl, /* unbusy */ TRUE);
3450: }
3451: j = 0;
3452: prev_scbp = NULL;
3453: scbp = p->delayed_scbs[i].head;
3454: while ( (scbp != NULL) && (j++ <= (p->scb_data->numscbs + 1)) )
3455: {
3456: prev_scbp = scbp;
3457: scbp = scbp->q_next;
3458: if ( prev_scbp == scbp )
3459: {
3460: if (aic7xxx_verbose & (VERBOSE_ABORT | VERBOSE_RESET))
3461: printk(WARN_LEAD "Yikes!! scb->q_next == scb "
3462: "in the delayed_scbs queue!\n", p->host_no, channel, i, lun);
3463: scbp = NULL;
3464: prev_scbp->q_next = NULL;
3465: p->delayed_scbs[i].tail = prev_scbp;
3466: }
3467: if (aic7xxx_match_scb(p, prev_scbp, target, channel, lun, tag))
3468: {
3469: scbq_remove(&p->delayed_scbs[i], prev_scbp);
3470: if (prev_scbp->flags & SCB_WAITINGQ)
3471: {
3472: p->dev_active_cmds[i]++;
3473: p->activescbs++;
3474: }
3475: prev_scbp->flags &= ~(SCB_ACTIVE | SCB_WAITINGQ);
3476: prev_scbp->flags |= SCB_RESET | SCB_QUEUED_FOR_DONE;
3477: }
3478: }
3479: if ( j > (p->scb_data->maxscbs + 1) )
3480: {
3481: if (aic7xxx_verbose & (VERBOSE_ABORT | VERBOSE_RESET))
3482: printk(WARN_LEAD "Yikes!! There's a loop in the "
3483: "delayed_scbs queue!\n", p->host_no, channel, i, lun);
3484: scbq_init(&p->delayed_scbs[i]);
3485: }
3486: if ( (p->delayed_scbs[i].head == NULL) &&
3487: (p->dev_timer[i].expires) )
3488: {
3489: del_timer(&p->dev_timer[i]);
3490: p->dev_timer[i].expires = 0;
3491: }
3492: }
3493: }
3494:
3495: if (aic7xxx_verbose & (VERBOSE_ABORT_PROCESS | VERBOSE_RESET_PROCESS))
3496: printk(INFO_LEAD "Cleaning QINFIFO.\n", p->host_no, channel, target, lun );
3497: aic7xxx_search_qinfifo(p, target, channel, lun, tag,
3498: SCB_RESET | SCB_QUEUED_FOR_DONE, /* requeue */ FALSE, NULL);
3499:
3500: /*
3501: * Search the waiting_scbs queue for matches, this catches any SCB_QUEUED
3502: * ABORT/RESET commands.
3503: */
3504: if (aic7xxx_verbose & (VERBOSE_ABORT_PROCESS | VERBOSE_RESET_PROCESS))
3505: printk(INFO_LEAD "Cleaning waiting_scbs.\n", p->host_no, channel,
3506: target, lun );
3507: {
3508: struct aic7xxx_scb *scbp, *prev_scbp;
3509:
3510: j = 0;
3511: prev_scbp = NULL;
3512: scbp = p->waiting_scbs.head;
3513: while ( (scbp != NULL) && (j++ <= (p->scb_data->numscbs + 1)) )
3514: {
3515: prev_scbp = scbp;
3516: scbp = scbp->q_next;
3517: if ( prev_scbp == scbp )
3518: {
3519: if (aic7xxx_verbose & (VERBOSE_ABORT | VERBOSE_RESET))
3520: printk(WARN_LEAD "Yikes!! scb->q_next == scb "
3521: "in the waiting_scbs queue!\n", p->host_no, CTL_OF_SCB(scbp));
3522: scbp = NULL;
3523: prev_scbp->q_next = NULL;
3524: p->waiting_scbs.tail = prev_scbp;
3525: }
3526: if (aic7xxx_match_scb(p, prev_scbp, target, channel, lun, tag))
3527: {
3528: scbq_remove(&p->waiting_scbs, prev_scbp);
3529: if (prev_scbp->flags & SCB_WAITINGQ)
3530: {
3531: p->dev_active_cmds[TARGET_INDEX(prev_scbp->cmd)]++;
3532: p->activescbs++;
3533: }
3534: prev_scbp->flags &= ~(SCB_ACTIVE | SCB_WAITINGQ);
3535: prev_scbp->flags |= SCB_RESET | SCB_QUEUED_FOR_DONE;
3536: }
3537: }
3538: if ( j > (p->scb_data->maxscbs + 1) )
3539: {
3540: if (aic7xxx_verbose & (VERBOSE_ABORT | VERBOSE_RESET))
3541: printk(WARN_LEAD "Yikes!! There's a loop in the "
3542: "waiting_scbs queue!\n", p->host_no, channel, target, lun);
3543: scbq_init(&p->waiting_scbs);
3544: }
3545: }
3546:
3547:
3548: /*
3549: * Search waiting for selection list.
3550: */
3551: if (aic7xxx_verbose & (VERBOSE_ABORT_PROCESS | VERBOSE_RESET_PROCESS))
3552: printk(INFO_LEAD "Cleaning waiting for selection "
3553: "list.\n", p->host_no, channel, target, lun);
3554: {
3555: unsigned char next, prev, scb_index;
3556:
3557: next = aic_inb(p, WAITING_SCBH); /* Start at head of list. */
3558: prev = SCB_LIST_NULL;
3559: j = 0;
3560: while ( (next != SCB_LIST_NULL) && (j++ <= (p->scb_data->maxscbs + 1)) )
3561: {
3562: aic_outb(p, next, SCBPTR);
3563: scb_index = aic_inb(p, SCB_TAG);
3564: if (scb_index >= p->scb_data->numscbs)
3565: {
3566: /*
3567: * No aic7xxx_verbose check here.....we want to see this since it
3568: * means either the kernel driver or the sequencer screwed things up
3569: */
3570: printk(WARN_LEAD "Waiting List inconsistency; SCB index=%d, "
3571: "numscbs=%d\n", p->host_no, channel, target, lun, scb_index,
3572: p->scb_data->numscbs);
3573: next = aic_inb(p, SCB_NEXT);
3574: aic7xxx_add_curscb_to_free_list(p);
3575: }
3576: else
3577: {
3578: scbp = p->scb_data->scb_array[scb_index];
3579: if (aic7xxx_match_scb(p, scbp, target, channel, lun, tag))
3580: {
3581: next = aic7xxx_abort_waiting_scb(p, scbp, next, prev);
3582: if (scbp->flags & SCB_WAITINGQ)
3583: {
3584: p->dev_active_cmds[TARGET_INDEX(scbp->cmd)]++;
3585: p->activescbs++;
3586: }
3587: scbp->flags &= ~(SCB_ACTIVE | SCB_WAITINGQ);
3588: scbp->flags |= SCB_RESET | SCB_QUEUED_FOR_DONE;
3589: if (prev == SCB_LIST_NULL)
3590: {
3591: /*
3592: * This is either the first scb on the waiting list, or we
3593: * have already yanked the first and haven't left any behind.
3594: * Either way, we need to turn off the selection hardware if
3595: * it isn't already off.
3596: */
3597: aic_outb(p, aic_inb(p, SCSISEQ) & ~ENSELO, SCSISEQ);
3598: aic_outb(p, CLRSELTIMEO, CLRSINT1);
3599: }
3600: }
3601: else
3602: {
3603: prev = next;
3604: next = aic_inb(p, SCB_NEXT);
3605: }
3606: }
3607: }
3608: if ( j > (p->scb_data->maxscbs + 1) )
3609: {
3610: printk(WARN_LEAD "Yikes!! There is a loop in the waiting for "
3611: "selection list!\n", p->host_no, channel, target, lun);
3612: init_lists = TRUE;
3613: }
3614: }
3615:
3616: /*
3617: * Go through disconnected list and remove any entries we have queued
3618: * for completion, zeroing their control byte too.
3619: */
3620: if (aic7xxx_verbose & (VERBOSE_ABORT_PROCESS | VERBOSE_RESET_PROCESS))
3621: printk(INFO_LEAD "Cleaning disconnected scbs "
3622: "list.\n", p->host_no, channel, target, lun);
3623: if (p->features & AHC_PAGESCBS)
3624: {
3625: unsigned char next, prev, scb_index;
3626:
3627: next = aic_inb(p, DISCONNECTED_SCBH);
3628: prev = SCB_LIST_NULL;
3629: j = 0;
3630: while ( (next != SCB_LIST_NULL) && (j++ <= (p->scb_data->maxscbs + 1)) )
3631: {
3632: aic_outb(p, next, SCBPTR);
3633: scb_index = aic_inb(p, SCB_TAG);
3634: if (scb_index > p->scb_data->numscbs)
3635: {
3636: printk(WARN_LEAD "Disconnected List inconsistency; SCB index=%d, "
3637: "numscbs=%d\n", p->host_no, channel, target, lun, scb_index,
3638: p->scb_data->numscbs);
3639: next = aic7xxx_rem_scb_from_disc_list(p, next);
3640: }
3641: else
3642: {
3643: scbp = p->scb_data->scb_array[scb_index];
3644: if (aic7xxx_match_scb(p, scbp, target, channel, lun, tag))
3645: {
3646: next = aic7xxx_rem_scb_from_disc_list(p, next);
3647: if (scbp->flags & SCB_WAITINGQ)
3648: {
3649: p->dev_active_cmds[TARGET_INDEX(scbp->cmd)]++;
3650: p->activescbs++;
3651: }
3652: scbp->flags &= ~(SCB_ACTIVE | SCB_WAITINGQ);
3653: scbp->flags |= SCB_RESET | SCB_QUEUED_FOR_DONE;
3654: scbp->hscb->control = 0;
3655: }
3656: else
3657: {
3658: prev = next;
3659: next = aic_inb(p, SCB_NEXT);
3660: }
3661: }
3662: }
3663: if ( j > (p->scb_data->maxscbs + 1) )
3664: {
3665: printk(WARN_LEAD "Yikes!! There is a loop in the disconnected list!\n",
3666: p->host_no, channel, target, lun);
3667: init_lists = TRUE;
3668: }
3669: }
3670:
3671: /*
3672: * Walk the free list making sure no entries on the free list have
3673: * a valid SCB_TAG value or SCB_CONTROL byte.
3674: */
3675: if (p->features & AHC_PAGESCBS)
3676: {
3677: unsigned char next;
3678:
3679: j = 0;
3680: next = aic_inb(p, FREE_SCBH);
3681: if ( (next >= p->scb_data->maxhscbs) && (next != SCB_LIST_NULL) )
3682: {
3683: printk(WARN_LEAD "Bogus FREE_SCBH!.\n", p->host_no, channel,
3684: target, lun);
3685: init_lists = TRUE;
3686: next = SCB_LIST_NULL;
3687: }
3688: while ( (next != SCB_LIST_NULL) && (j++ <= (p->scb_data->maxscbs + 1)) )
3689: {
3690: aic_outb(p, next, SCBPTR);
3691: if (aic_inb(p, SCB_TAG) < p->scb_data->numscbs)
3692: {
3693: printk(WARN_LEAD "Free list inconsistency!.\n", p->host_no, channel,
3694: target, lun);
3695: init_lists = TRUE;
3696: next = SCB_LIST_NULL;
3697: }
3698: else
3699: {
3700: aic_outb(p, SCB_LIST_NULL, SCB_TAG);
3701: aic_outb(p, 0, SCB_CONTROL);
3702: next = aic_inb(p, SCB_NEXT);
3703: }
3704: }
3705: if ( j > (p->scb_data->maxscbs + 1) )
3706: {
3707: printk(WARN_LEAD "Yikes!! There is a loop in the free list!\n",
3708: p->host_no, channel, target, lun);
3709: init_lists = TRUE;
3710: }
3711: }
3712:
3713: /*
3714: * Go through the hardware SCB array looking for commands that
3715: * were active but not on any list.
3716: */
3717: if (init_lists)
3718: {
3719: aic_outb(p, SCB_LIST_NULL, FREE_SCBH);
3720: aic_outb(p, SCB_LIST_NULL, WAITING_SCBH);
3721: aic_outb(p, SCB_LIST_NULL, DISCONNECTED_SCBH);
3722: }
3723: for (i = p->scb_data->maxhscbs - 1; i >= 0; i--)
3724: {
3725: unsigned char scbid;
3726:
3727: aic_outb(p, i, SCBPTR);
3728: if (init_lists)
3729: {
3730: aic_outb(p, SCB_LIST_NULL, SCB_TAG);
3731: aic_outb(p, SCB_LIST_NULL, SCB_NEXT);
3732: aic_outb(p, SCB_LIST_NULL, SCB_PREV);
3733: aic_outb(p, 0, SCB_CONTROL);
3734: aic7xxx_add_curscb_to_free_list(p);
3735: }
3736: else
3737: {
3738: scbid = aic_inb(p, SCB_TAG);
3739: if (scbid < p->scb_data->numscbs)
3740: {
3741: scbp = p->scb_data->scb_array[scbid];
3742: if (aic7xxx_match_scb(p, scbp, target, channel, lun, tag))
3743: {
3744: aic_outb(p, 0, SCB_CONTROL);
3745: aic_outb(p, SCB_LIST_NULL, SCB_TAG);
3746: aic7xxx_add_curscb_to_free_list(p);
3747: }
3748: }
3749: }
3750: }
3751:
3752: /*
3753: * Go through the entire SCB array now and look for commands for
3754: * for this target that are stillactive. These are other (most likely
3755: * tagged) commands that were disconnected when the reset occurred.
3756: * Any commands we find here we know this about, it wasn't on any queue,
3757: * it wasn't in the qinfifo, it wasn't in the disconnected or waiting
3758: * lists, so it really must have been a paged out SCB. In that case,
3759: * we shouldn't need to bother with updating any counters, just mark
3760: * the correct flags and go on.
3761: */
3762: for (i = 0; i < p->scb_data->numscbs; i++)
3763: {
3764: scbp = p->scb_data->scb_array[i];
3765: if ((scbp->flags & SCB_ACTIVE) &&
3766: aic7xxx_match_scb(p, scbp, target, channel, lun, tag) &&
3767: !aic7xxx_scb_on_qoutfifo(p, scbp))
3768: {
3769: if (scbp->flags & SCB_WAITINGQ)
3770: {
3771: scbq_remove(&p->waiting_scbs, scbp);
3772: scbq_remove(&p->delayed_scbs[TARGET_INDEX(scbp->cmd)], scbp);
3773: p->dev_active_cmds[TARGET_INDEX(scbp->cmd)]++;
3774: p->activescbs++;
3775: }
3776: scbp->flags |= SCB_RESET | SCB_QUEUED_FOR_DONE;
3777: scbp->flags &= ~(SCB_ACTIVE | SCB_WAITINGQ);
3778: }
3779: }
3780:
3781: aic_outb(p, active_scb, SCBPTR);
3782: }
3783:
3784:
3785: /*+F*************************************************************************
3786: * Function:
3787: * aic7xxx_clear_intstat
3788: *
3789: * Description:
3790: * Clears the interrupt status.
3791: *-F*************************************************************************/
3792: static void
3793: aic7xxx_clear_intstat(struct aic7xxx_host *p)
3794: {
3795: /* Clear any interrupt conditions this may have caused. */
3796: aic_outb(p, CLRSELDO | CLRSELDI | CLRSELINGO, CLRSINT0);
3797: aic_outb(p, CLRSELTIMEO | CLRATNO | CLRSCSIRSTI | CLRBUSFREE | CLRSCSIPERR |
3798: CLRPHASECHG | CLRREQINIT, CLRSINT1);
3799: aic_outb(p, CLRSCSIINT | CLRSEQINT | CLRBRKADRINT | CLRPARERR, CLRINT);
3800: }
3801:
3802: /*+F*************************************************************************
3803: * Function:
3804: * aic7xxx_reset_current_bus
3805: *
3806: * Description:
3807: * Reset the current SCSI bus.
3808: *-F*************************************************************************/
3809: static void
3810: aic7xxx_reset_current_bus(struct aic7xxx_host *p)
3811: {
3812:
3813: /* Disable reset interrupts. */
3814: aic_outb(p, aic_inb(p, SIMODE1) & ~ENSCSIRST, SIMODE1);
3815:
3816: /* Turn off the bus' current operations, after all, we shouldn't have any
3817: * valid commands left to cause a RSELI and SELO once we've tossed the
3818: * bus away with this reset, so we might as well shut down the sequencer
3819: * until the bus is restarted as oppossed to saving the current settings
3820: * and restoring them (which makes no sense to me). */
3821:
3822: /* Turn on the bus reset. */
3823: aic_outb(p, aic_inb(p, SCSISEQ) | SCSIRSTO, SCSISEQ);
3824: while ( (aic_inb(p, SCSISEQ) & SCSIRSTO) == 0)
3825: mdelay(5);
3826:
3827: mdelay(10);
3828:
3829: /* Turn off the bus reset. */
3830: aic_outb(p, 0, SCSISEQ);
3831: mdelay(5);
3832:
3833: aic7xxx_clear_intstat(p);
3834: /* Re-enable reset interrupts. */
3835: aic_outb(p, aic_inb(p, SIMODE1) | ENSCSIRST, SIMODE1);
3836:
3837: }
3838:
3839: /*+F*************************************************************************
3840: * Function:
3841: * aic7xxx_reset_channel
3842: *
3843: * Description:
3844: * Reset the channel.
3845: *-F*************************************************************************/
3846: static void
3847: aic7xxx_reset_channel(struct aic7xxx_host *p, int channel, int initiate_reset)
3848: {
3849: unsigned long offset_min, offset_max;
3850: unsigned char sblkctl;
3851: int cur_channel;
3852:
3853: if (aic7xxx_verbose & VERBOSE_RESET_PROCESS)
3854: printk(INFO_LEAD "Reset channel called, %s initiate reset.\n",
3855: p->host_no, channel, -1, -1, (initiate_reset==TRUE) ? "will" : "won't" );
3856:
3857:
3858: if (channel == 1)
3859: {
3860: p->needsdtr |= (p->needsdtr_copy & 0xFF00);
3861: p->sdtr_pending &= 0x00FF;
3862: offset_min = 8;
3863: offset_max = 16;
3864: }
3865: else
3866: {
3867: if (p->features & AHC_WIDE)
3868: {
3869: p->needsdtr = p->needsdtr_copy;
3870: p->needwdtr = p->needwdtr_copy;
3871: p->sdtr_pending = 0x0;
3872: p->wdtr_pending = 0x0;
3873: offset_min = 0;
3874: offset_max = 16;
3875: }
3876: else
3877: {
3878: /* Channel A */
3879: p->needsdtr |= (p->needsdtr_copy & 0x00FF);
3880: p->sdtr_pending &= 0xFF00;
3881: offset_min = 0;
3882: offset_max = 8;
3883: }
3884: }
3885:
3886: while (offset_min < offset_max)
3887: {
3888: /*
3889: * Revert to async/narrow transfers until we renegotiate.
3890: */
3891: aic_outb(p, 0, TARG_SCSIRATE + offset_min);
3892: if (p->features & AHC_ULTRA2)
3893: {
3894: aic_outb(p, 0, TARG_OFFSET + offset_min);
3895: }
3896: offset_min++;
3897: }
3898:
3899: /*
3900: * Reset the bus and unpause/restart the controller
3901: */
3902: sblkctl = aic_inb(p, SBLKCTL);
3903: if ( (p->chip & AHC_CHIPID_MASK) == AHC_AIC7770 )
3904: cur_channel = (sblkctl & SELBUSB) >> 3;
3905: else
3906: cur_channel = 0;
3907: if ( (cur_channel != channel) && (p->features & AHC_TWIN) )
3908: {
3909: /*
3910: * Case 1: Command for another bus is active
3911: */
3912: if (aic7xxx_verbose & VERBOSE_RESET_PROCESS)
3913: printk(INFO_LEAD "Stealthily resetting idle channel.\n", p->host_no,
3914: channel, -1, -1);
3915: /*
3916: * Stealthily reset the other bus without upsetting the current bus.
3917: */
3918: aic_outb(p, sblkctl ^ SELBUSB, SBLKCTL);
3919: aic_outb(p, aic_inb(p, SIMODE1) & ~ENBUSFREE, SIMODE1);
3920: if (initiate_reset)
3921: {
3922: aic7xxx_reset_current_bus(p);
3923: }
3924: aic_outb(p, aic_inb(p, SCSISEQ) & (ENSELI|ENRSELI|ENAUTOATNP), SCSISEQ);
3925: aic7xxx_clear_intstat(p);
3926: aic_outb(p, sblkctl, SBLKCTL);
3927: }
3928: else
3929: {
3930: /*
3931: * Case 2: A command from this bus is active or we're idle.
3932: */
3933: if (aic7xxx_verbose & VERBOSE_RESET_PROCESS)
3934: printk(INFO_LEAD "Resetting currently active channel.\n", p->host_no,
3935: channel, -1, -1);
3936: aic_outb(p, aic_inb(p, SIMODE1) & ~(ENBUSFREE|ENREQINIT),
3937: SIMODE1);
3938: p->flags &= ~AHC_HANDLING_REQINITS;
3939: p->msg_type = MSG_TYPE_NONE;
3940: p->msg_len = 0;
3941: if (initiate_reset)
3942: {
3943: aic7xxx_reset_current_bus(p);
3944: }
3945: aic_outb(p, aic_inb(p, SCSISEQ) & (ENSELI|ENRSELI|ENAUTOATNP), SCSISEQ);
3946: aic7xxx_clear_intstat(p);
3947: }
3948: if (aic7xxx_verbose & VERBOSE_RESET_RETURN)
3949: printk(INFO_LEAD "Channel reset\n", p->host_no, channel, -1, -1);
3950: /*
3951: * Clean up all the state information for the pending transactions
3952: * on this bus.
3953: */
3954: aic7xxx_reset_device(p, ALL_TARGETS, channel, ALL_LUNS, SCB_LIST_NULL);
3955:
3956: /*
3957: * Convince Mid Level SCSI code to leave us be for a little bit...
3958: */
3959: p->last_reset = jiffies;
3960: p->host->last_reset = (jiffies + (HZ * AIC7XXX_RESET_DELAY));
3961:
3962: if ( !(p->features & AHC_TWIN) )
3963: {
3964: restart_sequencer(p);
3965: }
3966:
3967: return;
3968: }
3969:
3970: /*+F*************************************************************************
3971: * Function:
3972: * aic7xxx_run_waiting_queues
3973: *
3974: * Description:
3975: * Scan the awaiting_scbs queue downloading and starting as many
3976: * scbs as we can.
3977: *-F*************************************************************************/
3978: static void
3979: aic7xxx_run_waiting_queues(struct aic7xxx_host *p)
3980: {
3981: struct aic7xxx_scb *scb;
3982: int tindex;
3983: int sent;
3984: #if LINUX_VERSION_CODE < KERNEL_VERSION(2,1,95)
3985: unsigned long cpu_flags = 0;
3986: #endif
3987:
3988:
3989: if (p->waiting_scbs.head == NULL)
3990: return;
3991:
3992: sent = 0;
3993:
3994: /*
3995: * First handle SCBs that are waiting but have been assigned a slot.
3996: */
3997: DRIVER_LOCK
3998: while ((scb = scbq_remove_head(&p->waiting_scbs)) != NULL)
3999: {
4000: tindex = TARGET_INDEX(scb->cmd);
4001: if ( !scb->tag_action && (p->tagenable & (1<<tindex)) )
4002: {
4003: #ifdef AIC7XXX_VERBOSE_DEBUGGING
4004: if (aic7xxx_verbose > 0xffff)
4005: printk(INFO_LEAD "Reducing Queue depth for untagged command.\n",
4006: p->host_no, CTL_OF_SCB(scb));
4007: #endif
4008: p->dev_temp_queue_depth[tindex] = 1;
4009: }
4010: if ( (p->dev_active_cmds[tindex] >=
4011: p->dev_temp_queue_depth[tindex]) ||
4012: (p->dev_last_reset[tindex] >= (jiffies - (4 * HZ))) )
4013: {
4014: #ifdef AIC7XXX_VERBOSE_DEBUGGING
4015: if (aic7xxx_verbose > 0xffff)
4016: printk(INFO_LEAD "Moving SCB to Delayed Queue.\n",
4017: p->host_no, CTL_OF_SCB(scb));
4018: #endif
4019: scbq_insert_tail(&p->delayed_scbs[tindex], scb);
4020: if ( !(p->dev_timer[tindex].expires) &&
4021: !(p->dev_active_cmds[tindex]) )
4022: {
4023: p->dev_timer[tindex].expires = p->dev_last_reset[tindex] + (4 * HZ);
4024: add_timer(&p->dev_timer[tindex]);
4025: }
4026: }
4027: else
4028: {
4029: scb->flags &= ~SCB_WAITINGQ;
4030: #ifdef AIC7XXX_VERBOSE_DEBUGGING
4031: if (aic7xxx_verbose > 0xffff)
4032: printk(INFO_LEAD "Sending command %d/0x%x to QINFIFO\n", p->host_no,
4033: CTL_OF_SCB(scb), scb->hscb->tag, scb->flags);
4034: #endif
4035: p->dev_active_cmds[tindex]++;
4036: p->activescbs++;
4037: if ( !(scb->tag_action) )
4038: {
4039: aic7xxx_busy_target(p, scb);
4040: }
4041: p->qinfifo[p->qinfifonext++] = scb->hscb->tag;
4042: sent++;
4043: }
4044: }
4045: if (sent)
4046: {
4047: #ifdef AIC7XXX_VERBOSE_DEBUGGING
4048: if (aic7xxx_verbose > 0xffff)
4049: {
4050: printk(INFO_LEAD "Sending commands to QINFIFO\n", p->host_no,
4051: -1, -1, -1);
4052: if ( (p->isr_count < 16) && (aic7xxx_panic_on_abort) &&
4053: (p->flags & AHC_PAGESCBS) )
4054: aic7xxx_check_scbs(p, "While sending commands to QINFIFO");
4055: }
4056: #endif
4057: if (p->features & AHC_QUEUE_REGS)
4058: aic_outb(p, p->qinfifonext, HNSCB_QOFF);
4059: else
4060: {
4061: pause_sequencer(p);
4062: aic_outb(p, p->qinfifonext, KERNEL_QINPOS);
4063: unpause_sequencer(p, FALSE);
4064: }
4065: if (p->activescbs > p->max_activescbs)
4066: p->max_activescbs = p->activescbs;
4067: }
4068: DRIVER_UNLOCK
4069: }
4070:
4071: #ifdef CONFIG_PCI
4072:
4073: #define DPE 0x80
4074: #define SSE 0x40
4075: #define RMA 0x20
4076: #define RTA 0x10
4077: #define STA 0x08
4078: #define DPR 0x01
4079:
4080: /*+F*************************************************************************
4081: * Function:
4082: * aic7xxx_pci_intr
4083: *
4084: * Description:
4085: * Check the scsi card for PCI errors and clear the interrupt
4086: *
4087: * NOTE: If you don't have this function and a 2940 card encounters
4088: * a PCI error condition, the machine will end up locked as the
4089: * interrupt handler gets slammed with non-stop PCI error interrupts
4090: *-F*************************************************************************/
4091: static void
4092: aic7xxx_pci_intr(struct aic7xxx_host *p)
4093: {
4094: unsigned char status1;
4095:
4096: #if LINUX_VERSION_CODE > KERNEL_VERSION(2,1,92)
4097: pci_read_config_byte(p->pdev, PCI_STATUS + 1, &status1);
4098: #else
4099: pcibios_read_config_byte(p->pci_bus, p->pci_device_fn,
4100: PCI_STATUS + 1, &status1);
4101: #endif
4102:
4103: if ( (status1 & DPE) && (aic7xxx_verbose & VERBOSE_MINOR_ERROR) )
4104: printk(WARN_LEAD "Data Parity Error during PCI address or PCI write"
4105: "phase.\n", p->host_no, -1, -1, -1);
4106: if ( (status1 & SSE) && (aic7xxx_verbose & VERBOSE_MINOR_ERROR) )
4107: printk(WARN_LEAD "Signal System Error Detected\n", p->host_no,
4108: -1, -1, -1);
4109: if ( (status1 & RMA) && (aic7xxx_verbose & VERBOSE_MINOR_ERROR) )
4110: printk(WARN_LEAD "Received a PCI Master Abort\n", p->host_no,
4111: -1, -1, -1);
4112: if ( (status1 & RTA) && (aic7xxx_verbose & VERBOSE_MINOR_ERROR) )
4113: printk(WARN_LEAD "Received a PCI Target Abort\n", p->host_no,
4114: -1, -1, -1);
4115: if ( (status1 & STA) && (aic7xxx_verbose & VERBOSE_MINOR_ERROR) )
4116: printk(WARN_LEAD "Signaled a PCI Target Abort\n", p->host_no,
4117: -1, -1, -1);
4118: if ( (status1 & DPR) && (aic7xxx_verbose & VERBOSE_MINOR_ERROR) )
4119: printk(WARN_LEAD "Data Parity Error has been reported via PCI pin "
4120: "PERR#\n", p->host_no, -1, -1, -1);
4121:
4122: #if LINUX_VERSION_CODE > KERNEL_VERSION(2,1,92)
4123: pci_write_config_byte(p->pdev, PCI_STATUS + 1, status1);
4124: #else
4125: pcibios_write_config_byte(p->pci_bus, p->pci_device_fn,
4126: PCI_STATUS + 1, status1);
4127: #endif
4128: if (status1 & (DPR|RMA|RTA))
4129: aic_outb(p, CLRPARERR, CLRINT);
4130:
4131: if ( (aic7xxx_panic_on_abort) && (p->spurious_int > 500) )
4132: aic7xxx_panic_abort(p, NULL);
4133:
4134: }
4135: #endif /* CONFIG_PCI */
4136:
4137: /*+F*************************************************************************
4138: * Function:
4139: * aic7xxx_timer
4140: *
4141: * Description:
4142: * Take expired extries off of delayed queues and place on waiting queue
4143: * then run waiting queue to start commands.
4144: ***************************************************************************/
4145: static void
4146: aic7xxx_timer(struct aic7xxx_host *p)
4147: {
4148: int i, j;
4149: unsigned long cpu_flags = 0;
4150: struct aic7xxx_scb *scb;
4151:
4152: #if LINUX_VERSION_CODE < KERNEL_VERSION(2,1,95)
4153: DRIVER_LOCK
4154: #else
4155: spin_lock_irqsave(&io_request_lock, cpu_flags);
4156: #endif
4157: for(i=0; i<MAX_TARGETS; i++)
4158: {
4159: if ( (p->dev_timer[i].expires) &&
4160: (p->dev_timer[i].expires <= jiffies) )
4161: {
4162: p->dev_timer[i].expires = 0;
4163: if ( (p->dev_timer[i].prev != NULL) ||
4164: (p->dev_timer[i].next != NULL) )
4165: {
4166: del_timer(&p->dev_timer[i]);
4167: }
4168: p->dev_temp_queue_depth[i] = p->dev_max_queue_depth[i];
4169: j = 0;
4170: while ( ((scb = scbq_remove_head(&p->delayed_scbs[i])) != NULL) &&
4171: (j++ < p->scb_data->numscbs) )
4172: {
4173: scbq_insert_tail(&p->waiting_scbs, scb);
4174: }
4175: if (j == p->scb_data->numscbs)
4176: {
4177: printk(INFO_LEAD "timer: Yikes, loop in delayed_scbs list.\n",
4178: p->host_no, 0, i, -1);
4179: scbq_init(&p->delayed_scbs[i]);
4180: scbq_init(&p->waiting_scbs);
4181: /*
4182: * Well, things are screwed now, wait for a reset to clean the junk
4183: * out.
4184: */
4185: }
4186: }
4187: }
4188: aic7xxx_run_waiting_queues(p);
4189: #if LINUX_VERSION_CODE < KERNEL_VERSION(2,1,95)
4190: DRIVER_UNLOCK
4191: #else
4192: spin_unlock_irqrestore(&io_request_lock, cpu_flags);
4193: #endif
4194: }
4195:
4196: /*+F*************************************************************************
4197: * Function:
4198: * aic7xxx_construct_sdtr
4199: *
4200: * Description:
4201: * Constucts a synchronous data transfer message in the message
4202: * buffer on the sequencer.
4203: *-F*************************************************************************/
4204: static void
4205: aic7xxx_construct_sdtr(struct aic7xxx_host *p, unsigned char period,
4206: unsigned char offset)
4207: {
4208: p->msg_buf[p->msg_index++] = MSG_EXTENDED;
4209: p->msg_buf[p->msg_index++] = MSG_EXT_SDTR_LEN;
4210: p->msg_buf[p->msg_index++] = MSG_EXT_SDTR;
4211: p->msg_buf[p->msg_index++] = period;
4212: p->msg_buf[p->msg_index++] = offset;
4213: p->msg_len += 5;
4214: }
4215:
4216: /*+F*************************************************************************
4217: * Function:
4218: * aic7xxx_construct_wdtr
4219: *
4220: * Description:
4221: * Constucts a wide data transfer message in the message buffer
4222: * on the sequencer.
4223: *-F*************************************************************************/
4224: static void
4225: aic7xxx_construct_wdtr(struct aic7xxx_host *p, unsigned char bus_width)
4226: {
4227: p->msg_buf[p->msg_index++] = MSG_EXTENDED;
4228: p->msg_buf[p->msg_index++] = MSG_EXT_WDTR_LEN;
4229: p->msg_buf[p->msg_index++] = MSG_EXT_WDTR;
4230: p->msg_buf[p->msg_index++] = bus_width;
4231: p->msg_len += 4;
4232: }
4233:
4234: /*+F*************************************************************************
4235: * Function:
4236: * aic7xxx_calc_residual
4237: *
4238: * Description:
4239: * Calculate the residual data not yet transferred.
4240: *-F*************************************************************************/
4241: static void
4242: aic7xxx_calculate_residual (struct aic7xxx_host *p, struct aic7xxx_scb *scb)
4243: {
4244: struct aic7xxx_hwscb *hscb;
4245: Scsi_Cmnd *cmd;
4246: int actual, i;
4247:
4248: cmd = scb->cmd;
4249: hscb = scb->hscb;
4250:
4251: /*
4252: * Don't destroy valid residual information with
4253: * residual coming from a check sense operation.
4254: */
4255: if (((scb->hscb->control & DISCONNECTED) == 0) &&
4256: (scb->flags & SCB_SENSE) == 0)
4257: {
4258: /*
4259: * We had an underflow. At this time, there's only
4260: * one other driver that bothers to check for this,
4261: * and cmd->underflow seems to be set rather half-
4262: * heartedly in the higher-level SCSI code.
4263: */
4264: actual = scb->sg_length;
4265: for (i=1; i < hscb->residual_SG_segment_count; i++)
4266: {
4267: actual -= scb->sg_list[scb->sg_count - i].length;
4268: }
4269: actual -= (hscb->residual_data_count[2] << 16) |
4270: (hscb->residual_data_count[1] << 8) |
4271: hscb->residual_data_count[0];
4272:
4273: if (actual < cmd->underflow)
4274: {
4275: if (aic7xxx_verbose & VERBOSE_MINOR_ERROR)
4276: printk(INFO_LEAD "Underflow - Wanted %u, %s %u, residual SG "
4277: "count %d.\n", p->host_no, CTL_OF_SCB(scb), cmd->underflow,
4278: (cmd->request.cmd == WRITE) ? "wrote" : "read", actual,
4279: hscb->residual_SG_segment_count);
4280: aic7xxx_error(cmd) = DID_RETRY_COMMAND;
4281: aic7xxx_status(cmd) = hscb->target_status;
4282: }
4283: }
4284:
4285: /*
4286: * Clean out the residual information in the SCB for the
4287: * next consumer.
4288: */
4289: hscb->residual_data_count[2] = 0;
4290: hscb->residual_data_count[1] = 0;
4291: hscb->residual_data_count[0] = 0;
4292: hscb->residual_SG_segment_count = 0;
4293: }
4294:
4295: /*+F*************************************************************************
4296: * Function:
4297: * aic7xxx_handle_device_reset
4298: *
4299: * Description:
4300: * Interrupt handler for sequencer interrupts (SEQINT).
4301: *-F*************************************************************************/
4302: static void
4303: aic7xxx_handle_device_reset(struct aic7xxx_host *p, int target, int channel)
4304: {
4305: unsigned short targ_mask;
4306: unsigned char tindex = target;
4307:
4308: tindex |= ((channel & 0x01) << 3);
4309:
4310: targ_mask = (0x01 << tindex);
4311: /*
4312: * Go back to async/narrow transfers and renegotiate.
4313: */
4314: p->needsdtr |= (p->needsdtr_copy & targ_mask);
4315: p->needwdtr |= (p->needwdtr_copy & targ_mask);
4316: p->sdtr_pending &= ~targ_mask;
4317: p->wdtr_pending &= ~targ_mask;
4318: aic_outb(p, 0, TARG_SCSIRATE + tindex);
4319: if (p->features & AHC_ULTRA2)
4320: aic_outb(p, 0, TARG_OFFSET + tindex);
4321: aic7xxx_reset_device(p, target, channel, ALL_LUNS, SCB_LIST_NULL);
4322: if (aic7xxx_verbose & VERBOSE_RESET_PROCESS)
4323: printk(INFO_LEAD "Bus Device Reset delivered.\n", p->host_no, channel,
4324: target, -1);
4325: aic7xxx_run_done_queue(p, /*complete*/ FALSE);
4326: }
4327:
4328: /*+F*************************************************************************
4329: * Function:
4330: * aic7xxx_handle_seqint
4331: *
4332: * Description:
4333: * Interrupt handler for sequencer interrupts (SEQINT).
4334: *-F*************************************************************************/
4335: static void
4336: aic7xxx_handle_seqint(struct aic7xxx_host *p, unsigned char intstat)
4337: {
4338: struct aic7xxx_scb *scb;
4339: unsigned short target_mask;
4340: unsigned char target, lun, tindex;
4341: unsigned char queue_flag = FALSE;
4342: char channel;
4343:
4344: target = ((aic_inb(p, SAVED_TCL) >> 4) & 0x0f);
4345: if ( (p->chip & AHC_CHIPID_MASK) == AHC_AIC7770 )
4346: channel = (aic_inb(p, SBLKCTL) & SELBUSB) >> 3;
4347: else
4348: channel = 0;
4349: tindex = target + (channel << 3);
4350: lun = aic_inb(p, SAVED_TCL) & 0x07;
4351: target_mask = (0x01 << tindex);
4352:
4353: /*
4354: * Go ahead and clear the SEQINT now, that avoids any interrupt race
4355: * conditions later on in case we enable some other interrupt.
4356: */
4357: aic_outb(p, CLRSEQINT, CLRINT);
4358: switch (intstat & SEQINT_MASK)
4359: {
4360: case NO_MATCH:
4361: {
4362: aic_outb(p, aic_inb(p, SCSISEQ) & (ENSELI|ENRSELI|ENAUTOATNP),
4363: SCSISEQ);
4364: printk(WARN_LEAD "No active SCB for reconnecting target - Issuing "
4365: "BUS DEVICE RESET.\n", p->host_no, channel, target, lun);
4366: printk(WARN_LEAD " SAVED_TCL=0x%x, ARG_1=0x%x, SEQADDR=0x%x\n",
4367: p->host_no, channel, target, lun,
4368: aic_inb(p, SAVED_TCL), aic_inb(p, ARG_1),
4369: (aic_inb(p, SEQADDR1) << 8) | aic_inb(p, SEQADDR0));
4370: }
4371: break;
4372:
4373: case SEND_REJECT:
4374: {
4375: if (aic7xxx_verbose & VERBOSE_MINOR_ERROR)
4376: printk(INFO_LEAD "Rejecting unknown message (0x%x) received from "
4377: "target, SEQ_FLAGS=0x%x\n", p->host_no, channel, target, lun,
4378: aic_inb(p, ACCUM), aic_inb(p, SEQ_FLAGS));
4379: }
4380: break;
4381:
4382: case NO_IDENT:
4383: {
4384: /*
4385: * The reconnecting target either did not send an identify
4386: * message, or did, but we didn't find an SCB to match and
4387: * before it could respond to our ATN/abort, it hit a dataphase.
4388: * The only safe thing to do is to blow it away with a bus
4389: * reset.
4390: */
4391: if (aic7xxx_verbose & (VERBOSE_SEQINT | VERBOSE_RESET_MID))
4392: printk(INFO_LEAD "Target did not send an IDENTIFY message; "
4393: "LASTPHASE 0x%x, SAVED_TCL 0x%x\n", p->host_no, channel, target,
4394: lun, aic_inb(p, LASTPHASE), aic_inb(p, SAVED_TCL));
4395:
4396: aic7xxx_reset_channel(p, channel, /*initiate reset*/ TRUE);
4397: aic7xxx_run_done_queue(p, FALSE);
4398:
4399: }
4400: break;
4401:
4402: case BAD_PHASE:
4403: if (aic_inb(p, LASTPHASE) == P_BUSFREE)
4404: {
4405: if (aic7xxx_verbose & VERBOSE_SEQINT)
4406: printk(INFO_LEAD "Missed busfree.\n", p->host_no, channel,
4407: target, lun);
4408: restart_sequencer(p);
4409: }
4410: else
4411: {
4412: if (aic7xxx_verbose & VERBOSE_SEQINT)
4413: printk(INFO_LEAD "Unknown scsi bus phase, continuing\n", p->host_no,
4414: channel, target, lun);
4415: }
4416: break;
4417:
4418: case EXTENDED_MSG:
4419: {
4420: p->msg_type = MSG_TYPE_INITIATOR_MSGIN;
4421: p->msg_len = 0;
4422: p->msg_index = 0;
4423:
4424: #ifdef AIC7XXX_VERBOSE_DEBUGGING
4425: if (aic7xxx_verbose > 0xffff)
4426: printk(INFO_LEAD "Enabling REQINITs for MSG_IN\n", p->host_no,
4427: channel, target, lun);
4428: #endif
4429:
4430: /*
4431: * To actually receive the message, simply turn on
4432: * REQINIT interrupts and let our interrupt handler
4433: * do the rest (REQINIT should already be true).
4434: */
4435: p->flags |= AHC_HANDLING_REQINITS;
4436: aic_outb(p, aic_inb(p, SIMODE1) | ENREQINIT, SIMODE1);
4437:
4438: /*
4439: * We don't want the sequencer unpaused yet so we return early
4440: */
4441: return;
4442: }
4443:
4444: case REJECT_MSG:
4445: {
4446: /*
4447: * What we care about here is if we had an outstanding SDTR
4448: * or WDTR message for this target. If we did, this is a
4449: * signal that the target is refusing negotiation.
4450: */
4451: unsigned char scb_index;
4452: unsigned char last_msg;
4453:
4454: scb_index = aic_inb(p, SCB_TAG);
4455: scb = p->scb_data->scb_array[scb_index];
4456: last_msg = aic_inb(p, LAST_MSG);
4457:
4458: if ( (last_msg == MSG_IDENTIFYFLAG) &&
4459: (scb->tag_action) &&
4460: !(scb->flags & SCB_MSGOUT_BITS) )
4461: {
4462: if ((scb->tag_action == MSG_ORDERED_Q_TAG) &&
4463: (p->dev_flags[tindex] & DEVICE_TAGGED_SUCCESS))
4464: {
4465: /*
4466: * OK...the device seems able to accept tagged commands, but
4467: * not ordered tag commands, only simple tag commands. So, we
4468: * disable ordered tag commands and go on with life just like
4469: * normal.
4470: */
4471: p->orderedtag &= ~target_mask;
4472: scb->tag_action = MSG_SIMPLE_Q_TAG;
4473: scb->hscb->control &= ~SCB_TAG_TYPE;
4474: scb->hscb->control |= MSG_SIMPLE_Q_TAG;
4475: aic_outb(p, scb->hscb->control, SCB_CONTROL);
4476: /*
4477: * OK..we set the tag type to simple tag command, now we re-assert
4478: * ATNO and hope this will take us into the identify phase again
4479: * so we can resend the tag type and info to the device.
4480: */
4481: aic_outb(p, MSG_IDENTIFYFLAG, MSG_OUT);
4482: aic_outb(p, aic_inb(p, SCSISIGI) | ATNO, SCSISIGO);
4483: }
4484: else if ( (scb->tag_action == MSG_SIMPLE_Q_TAG) &&
4485: !(p->dev_flags[tindex] & DEVICE_TAGGED_SUCCESS) )
4486: {
4487: unsigned char i, reset = 0;
4488: struct aic7xxx_scb *scbp;
4489: int old_verbose;
4490: /*
4491: * Hmmmm....the device is flaking out on tagged commands. The
4492: * bad thing is that we already have tagged commands enabled in
4493: * the device struct in the mid level code. We also have a queue
4494: * set according to the tagged queue depth. Gonna have to live
4495: * with it by controlling our queue depth internally and making
4496: * sure we don't set the tagged command flag any more.
4497: */
4498: p->tagenable &= ~target_mask;
4499: p->orderedtag &= ~target_mask;
4500: p->dev_max_queue_depth[tindex] =
4501: p->dev_temp_queue_depth[tindex] = 1;
4502: /*
4503: * We set this command up as a bus device reset. However, we have
4504: * to clear the tag type as it's causing us problems. We shouldnt
4505: * have to worry about any other commands being active, since if
4506: * the device is refusing tagged commands, this should be the
4507: * first tagged command sent to the device, however, we do have
4508: * to worry about any other tagged commands that may already be
4509: * in the qinfifo. The easiest way to do this, is to issue a BDR,
4510: * send all the commands back to the mid level code, then let them
4511: * come back and get rebuilt as untagged commands.
4512: */
4513: scb->tag_action = 0;
4514: scb->hscb->control &= ~(TAG_ENB | SCB_TAG_TYPE);
4515: aic_outb(p, scb->hscb->control, SCB_CONTROL);
4516:
4517: old_verbose = aic7xxx_verbose;
4518: aic7xxx_verbose &= ~(VERBOSE_RESET|VERBOSE_ABORT);
4519: for (i=0; i!=p->scb_data->numscbs; i++)
4520: {
4521: scbp = p->scb_data->scb_array[i];
4522: if ((scbp->flags & SCB_ACTIVE) && (scbp != scb))
4523: {
4524: if (aic7xxx_match_scb(p, scbp, target, channel, lun, i))
4525: {
4526: aic7xxx_reset_device(p, target, channel, lun, i);
4527: reset++;
4528: }
4529: aic7xxx_run_done_queue(p, FALSE);
4530: }
4531: }
4532: aic7xxx_verbose = old_verbose;
4533: /*
4534: * Wait until after the for loop to set the busy index since
4535: * aic7xxx_reset_device will clear the busy index during its
4536: * operation.
4537: */
4538: aic7xxx_busy_target(p, scb);
4539: printk(INFO_LEAD "Device is refusing tagged commands, using "
4540: "untagged I/O.\n", p->host_no, channel, target, lun);
4541: aic_outb(p, MSG_IDENTIFYFLAG, MSG_OUT);
4542: aic_outb(p, aic_inb(p, SCSISIGI) | ATNO, SCSISIGO);
4543: }
4544: }
4545: else if (scb->flags & SCB_MSGOUT_WDTR)
4546: {
4547: /*
4548: * note 8bit xfers and clear flag
4549: */
4550: p->needwdtr &= ~target_mask;
4551: p->needwdtr_copy &= ~target_mask;
4552: p->wdtr_pending &= ~target_mask;
4553: scb->flags &= ~SCB_MSGOUT_BITS;
4554: aic7xxx_set_width(p, target, channel, lun, MSG_EXT_WDTR_BUS_8_BIT,
4555: (AHC_TRANS_ACTIVE|AHC_TRANS_GOAL|AHC_TRANS_CUR));
4556: aic7xxx_set_syncrate(p, NULL, target, channel, 0, 0,
4557: AHC_TRANS_ACTIVE|AHC_TRANS_CUR|AHC_TRANS_QUITE);
4558: if ( (p->needsdtr_copy & target_mask) &&
4559: !(p->sdtr_pending & target_mask) )
4560: {
4561: p->sdtr_pending |= target_mask;
4562: scb->flags |= SCB_MSGOUT_SDTR;
4563: aic_outb(p, HOST_MSG, MSG_OUT);
4564: aic_outb(p, aic_inb(p, SCSISIGO) | ATNO, SCSISIGO);
4565: }
4566: }
4567: else if (scb->flags & SCB_MSGOUT_SDTR)
4568: {
4569: /*
4570: * note asynch xfers and clear flag
4571: */
4572: p->needsdtr &= ~target_mask;
4573: p->needsdtr_copy &= ~target_mask;
4574: p->sdtr_pending &= ~target_mask;
4575: scb->flags &= ~SCB_MSGOUT_SDTR;
4576: aic7xxx_set_syncrate(p, NULL, target, channel, 0, 0,
4577: (AHC_TRANS_CUR|AHC_TRANS_ACTIVE|AHC_TRANS_GOAL));
4578: }
4579: else if (aic7xxx_verbose & VERBOSE_SEQINT)
4580: {
4581: /*
4582: * Otherwise, we ignore it.
4583: */
4584: printk(INFO_LEAD "Received MESSAGE_REJECT for unknown cause. "
4585: "Ignoring.\n", p->host_no, channel, target, lun);
4586: }
4587: }
4588: break;
4589:
4590: case BAD_STATUS:
4591: {
4592: unsigned char scb_index;
4593: struct aic7xxx_hwscb *hscb;
4594: Scsi_Cmnd *cmd;
4595:
4596: /* The sequencer will notify us when a command has an error that
4597: * would be of interest to the kernel. This allows us to leave
4598: * the sequencer running in the common case of command completes
4599: * without error. The sequencer will have DMA'd the SCB back
4600: * up to us, so we can reference the drivers SCB array.
4601: *
4602: * Set the default return value to 0 indicating not to send
4603: * sense. The sense code will change this if needed and this
4604: * reduces code duplication.
4605: */
4606: aic_outb(p, 0, RETURN_1);
4607: scb_index = aic_inb(p, SCB_TAG);
4608: if (scb_index > p->scb_data->numscbs)
4609: {
4610: printk(WARN_LEAD "Invalid SCB during SEQINT 0x%02x, SCB_TAG %d.\n",
4611: p->host_no, channel, target, lun, intstat, scb_index);
4612: break;
4613: }
4614: scb = p->scb_data->scb_array[scb_index];
4615: hscb = scb->hscb;
4616:
4617: if (!(scb->flags & SCB_ACTIVE) || (scb->cmd == NULL))
4618: {
4619: printk(WARN_LEAD "Invalid SCB during SEQINT 0x%x, scb %d, flags 0x%x,"
4620: " cmd 0x%lx.\n", p->host_no, channel, target, lun, intstat,
4621: scb_index, scb->flags, (unsigned long) scb->cmd);
4622: }
4623: else
4624: {
4625: cmd = scb->cmd;
4626: hscb->target_status = aic_inb(p, SCB_TARGET_STATUS);
4627: aic7xxx_status(cmd) = hscb->target_status;
4628:
4629: cmd->result = hscb->target_status;
4630:
4631: switch (status_byte(hscb->target_status))
4632: {
4633: case GOOD:
4634: if (aic7xxx_verbose & VERBOSE_SEQINT)
4635: printk(INFO_LEAD "Interrupted for status of GOOD???\n",
4636: p->host_no, CTL_OF_SCB(scb));
4637: break;
4638:
4639: case COMMAND_TERMINATED:
4640: case CHECK_CONDITION:
4641: if ( !(scb->flags & SCB_SENSE) )
4642: {
4643: /*
4644: * XXX - How do we save the residual (if there is one).
4645: */
4646: if ( hscb->residual_SG_segment_count != 0 )
4647: aic7xxx_calculate_residual(p, scb);
4648:
4649: /*
4650: * Send a sense command to the requesting target.
4651: * XXX - revisit this and get rid of the memcopys.
4652: */
4653: memcpy(&scb->sense_cmd[0], &generic_sense[0],
4654: sizeof(generic_sense));
4655:
4656: scb->sense_cmd[1] = (cmd->lun << 5);
4657: scb->sense_cmd[4] = sizeof(cmd->sense_buffer);
4658:
4659: scb->sg_list[0].address =
4660: cpu_to_le32(VIRT_TO_BUS(&cmd->sense_buffer[0]));
4661: scb->sg_list[0].length =
4662: cpu_to_le32(sizeof(cmd->sense_buffer));
4663:
4664: /*
4665: * XXX - We should allow disconnection, but can't as it
4666: * might allow overlapped tagged commands.
4667: */
4668: /* hscb->control &= DISCENB; */
4669: hscb->control = 0;
4670: hscb->target_status = 0;
4671: hscb->SG_list_pointer =
4672: cpu_to_le32(VIRT_TO_BUS(&scb->sg_list[0]));
4673: hscb->data_pointer = scb->sg_list[0].address;
4674: hscb->data_count = scb->sg_list[0].length;
4675: hscb->SCSI_cmd_pointer =
4676: cpu_to_le32(VIRT_TO_BUS(&scb->sense_cmd[0]));
4677: hscb->SCSI_cmd_length = COMMAND_SIZE(scb->sense_cmd[0]);
4678: hscb->residual_SG_segment_count = 0;
4679: hscb->residual_data_count[0] = 0;
4680: hscb->residual_data_count[1] = 0;
4681: hscb->residual_data_count[2] = 0;
4682:
4683: scb->sg_count = hscb->SG_segment_count = 1;
4684: scb->sg_length = sizeof(cmd->sense_buffer);
4685: scb->tag_action = 0;
4686: /*
4687: * This problem could be caused if the target has lost power
4688: * or found some other way to loose the negotiation settings,
4689: * so if needed, we'll re-negotiate while doing the sense cmd.
4690: * However, if this SCB already was attempting to negotiate,
4691: * then we assume this isn't the problem and skip this part.
4692: */
4693: #ifdef AIC7XXX_FAKE_NEGOTIATION_CMDS
4694: if ( (scb->cmd->cmnd[0] != TEST_UNIT_READY) &&
4695: (p->dev_flags[tindex] & DEVICE_SCANNED) &&
4696: !(p->wdtr_pending & target_mask) &&
4697: !(p->sdtr_pending & target_mask) )
4698: {
4699: p->needwdtr |= (p->needwdtr_copy & target_mask);
4700: p->needsdtr |= (p->needsdtr_copy & target_mask);
4701: }
4702: else if ( (scb->cmd == p->dev_wdtr_cmnd[tindex]) ||
4703: (scb->cmd == p->dev_sdtr_cmnd[tindex]) )
4704: {
4705: /*
4706: * This is already a negotiation command, so we must have
4707: * already done either WDTR or SDTR (or maybe both). So
4708: * we simply check sdtr_pending and needsdtr to see if we
4709: * should throw out SDTR on this command.
4710: *
4711: * Note: Don't check the needsdtr_copy here, instead just
4712: * check to see if WDTR wiped out our SDTR and set needsdtr.
4713: * Even if WDTR did wipe out SDTR and set needsdtr, if
4714: * parse_msg() then turned around and started our SDTR
4715: * in back to back fasion, then conclusion of that should
4716: * have negated any needsdtr setting. That's why we only
4717: * check needsdtr and sdtr_pending.
4718: */
4719: scb->flags &= ~SCB_MSGOUT_BITS;
4720: if ( (scb->cmd == p->dev_wdtr_cmnd[tindex]) &&
4721: !(p->sdtr_pending & target_mask) &&
4722: (p->needsdtr & target_mask) )
4723: {
4724: p->sdtr_pending |= target_mask;
4725: hscb->control |= MK_MESSAGE;
4726: scb->flags |= SCB_MSGOUT_SDTR;
4727: }
4728:
4729: /*
4730: * This is the important part though. We are getting sense
4731: * info back from this device. It's going into a fake
4732: * command. We need to put that into the real command
4733: * instead so that the mid level SCSI code can act upon it.
4734: * So, when we set up these fake commands, the next pointer
4735: * is used to point to the real command. Use that to change
4736: * the address of our sense_buffer[] to the real command.
4737: * However, don't do this if the real command is also a
4738: * TEST_UNIT_READY as it will most likely pull down its own
4739: * SENSE information anyway.
4740: */
4741: if (cmd->next->cmnd[0] != TEST_UNIT_READY)
4742: {
4743: scb->sg_list[0].address =
4744: cpu_to_le32(VIRT_TO_BUS(&cmd->next->sense_buffer[0]));
4745: hscb->data_pointer = scb->sg_list[0].address;
4746: }
4747: }
4748: #else
4749: if ( (scb->cmd->cmnd[0] != TEST_UNIT_READY) &&
4750: !(scb->flags & SCB_MSGOUT_BITS) &&
4751: (scb->cmd->lun == 0) &&
4752: (p->dev_flags[TARGET_INDEX(scb->cmd)] & DEVICE_SCANNED) )
4753: {
4754: if ( (p->needwdtr_copy & target_mask) &&
4755: !(p->wdtr_pending & target_mask) &&
4756: !(p->sdtr_pending & target_mask) )
4757: {
4758: p->needwdtr |= target_mask;
4759: p->wdtr_pending |= target_mask;
4760: hscb->control |= MK_MESSAGE;
4761: scb->flags |= SCB_MSGOUT_WDTR;
4762: }
4763: if ( p->needsdtr_copy & target_mask )
4764: {
4765: p->needsdtr |= target_mask;
4766: if ( !(p->wdtr_pending & target_mask) &&
4767: !(p->sdtr_pending & target_mask) )
4768: {
4769: p->sdtr_pending |= target_mask;
4770: hscb->control |= MK_MESSAGE;
4771: scb->flags |= SCB_MSGOUT_SDTR;
4772: }
4773: }
4774: }
4775: else
4776: scb->flags &= ~SCB_MSGOUT_BITS;
4777: #endif /* AIC7XXX_FAKE_NEGOTIATION_CMDS */
4778: scb->flags |= SCB_SENSE;
4779: /*
4780: * Ensure the target is busy since this will be an
4781: * an untagged request.
4782: */
4783: #ifdef AIC7XXX_VERBOSE_DEBUGGING
4784: if (aic7xxx_verbose > 0xffff)
4785: {
4786: if (scb->flags & SCB_MSGOUT_BITS)
4787: printk(INFO_LEAD "Requesting SENSE with %s\n", p->host_no,
4788: CTL_OF_SCB(scb), (scb->flags & SCB_MSGOUT_SDTR) ?
4789: "SDTR" : "WDTR");
4790: else
4791: printk(INFO_LEAD "Requesting SENSE, no MSG\n", p->host_no,
4792: CTL_OF_SCB(scb));
4793: }
4794: #endif
4795: aic7xxx_busy_target(p, scb);
4796: aic_outb(p, SEND_SENSE, RETURN_1);
4797: aic7xxx_error(cmd) = DID_OK;
4798: break;
4799: } /* first time sense, no errors */
4800: aic7xxx_error(cmd) = DID_OK;
4801: scb->flags &= ~SCB_SENSE;
4802: break;
4803:
4804: case QUEUE_FULL:
4805: queue_flag = TRUE; /* Mark that this is a QUEUE_FULL and */
4806: case BUSY: /* drop through to here */
4807: {
4808: struct aic7xxx_scb *next_scbp, *prev_scbp;
4809: unsigned char active_hscb, next_hscb, prev_hscb, scb_index;
4810: /*
4811: * We have to look three places for queued commands:
4812: * 1: QINFIFO
4813: * 2: p->waiting_scbs queue
4814: * 3: WAITING_SCBS list on card (for commands that are started
4815: * but haven't yet made it to the device)
4816: */
4817: aic7xxx_search_qinfifo(p, target, channel, lun,
4818: SCB_LIST_NULL, 0, TRUE,
4819: &p->delayed_scbs[tindex]);
4820: next_scbp = p->waiting_scbs.head;
4821: while ( next_scbp != NULL )
4822: {
4823: prev_scbp = next_scbp;
4824: next_scbp = next_scbp->q_next;
4825: if ( aic7xxx_match_scb(p, prev_scbp, target, channel, lun,
4826: SCB_LIST_NULL) )
4827: {
4828: scbq_remove(&p->waiting_scbs, prev_scbp);
4829: scbq_insert_tail(&p->delayed_scbs[tindex],
4830: prev_scbp);
4831: }
4832: }
4833: next_scbp = NULL;
4834: active_hscb = aic_inb(p, SCBPTR);
4835: prev_hscb = next_hscb = scb_index = SCB_LIST_NULL;
4836: next_hscb = aic_inb(p, WAITING_SCBH);
4837: while (next_hscb != SCB_LIST_NULL)
4838: {
4839: aic_outb(p, next_hscb, SCBPTR);
4840: scb_index = aic_inb(p, SCB_TAG);
4841: if (scb_index < p->scb_data->numscbs)
4842: {
4843: next_scbp = p->scb_data->scb_array[scb_index];
4844: if (aic7xxx_match_scb(p, next_scbp, target, channel, lun,
4845: SCB_LIST_NULL) )
4846: {
4847: if (next_scbp->flags & SCB_WAITINGQ)
4848: {
4849: p->dev_active_cmds[tindex]++;
4850: p->activescbs--;
4851: scbq_remove(&p->delayed_scbs[tindex], next_scbp);
4852: scbq_remove(&p->waiting_scbs, next_scbp);
4853: }
4854: scbq_insert_head(&p->delayed_scbs[tindex],
4855: next_scbp);
4856: next_scbp->flags |= SCB_WAITINGQ;
4857: p->dev_active_cmds[tindex]--;
4858: p->activescbs--;
4859: next_hscb = aic_inb(p, SCB_NEXT);
4860: aic_outb(p, 0, SCB_CONTROL);
4861: aic_outb(p, SCB_LIST_NULL, SCB_TAG);
4862: aic7xxx_add_curscb_to_free_list(p);
4863: if (prev_hscb == SCB_LIST_NULL)
4864: {
4865: /* We were first on the list,
4866: * so we kill the selection
4867: * hardware. Let the sequencer
4868: * re-init the hardware itself
4869: */
4870: aic_outb(p, aic_inb(p, SCSISEQ) & ~ENSELO, SCSISEQ);
4871: aic_outb(p, CLRSELTIMEO, CLRSINT1);
4872: aic_outb(p, next_hscb, WAITING_SCBH);
4873: }
4874: else
4875: {
4876: aic_outb(p, prev_hscb, SCBPTR);
4877: aic_outb(p, next_hscb, SCB_NEXT);
4878: }
4879: }
4880: else
4881: {
4882: prev_hscb = next_hscb;
4883: next_hscb = aic_inb(p, SCB_NEXT);
4884: }
4885: } /* scb_index >= p->scb_data->numscbs */
4886: }
4887: aic_outb(p, active_hscb, SCBPTR);
4888: if (scb->flags & SCB_WAITINGQ)
4889: {
4890: scbq_remove(&p->delayed_scbs[tindex], scb);
4891: scbq_remove(&p->waiting_scbs, scb);
4892: p->dev_active_cmds[tindex]++;
4893: p->activescbs++;
4894: }
4895: scbq_insert_head(&p->delayed_scbs[tindex], scb);
4896: p->dev_active_cmds[tindex]--;
4897: p->activescbs--;
4898: scb->flags |= SCB_WAITINGQ | SCB_WAS_BUSY;
4899:
4900: if (p->dev_timer[tindex].expires == 0)
4901: {
4902: if ( p->dev_active_cmds[tindex] )
4903: {
4904: p->dev_timer[tindex].expires = jiffies + (HZ * 2);
4905: add_timer(&p->dev_timer[tindex]);
4906: }
4907: else
4908: {
4909: p->dev_timer[tindex].expires = jiffies + (HZ / 2);
4910: add_timer(&p->dev_timer[tindex]);
4911: }
4912: }
4913: #ifdef AIC7XXX_VERBOSE_DEBUGGING
4914: if (aic7xxx_verbose & VERBOSE_MINOR_ERROR)
4915: {
4916: if (queue_flag)
4917: printk(INFO_LEAD "Queue full received; queue depth %d, "
4918: "active %d\n", p->host_no, CTL_OF_SCB(scb),
4919: p->dev_max_queue_depth[tindex],
4920: p->dev_active_cmds[tindex]);
4921: else
4922: printk(INFO_LEAD "Target busy\n", p->host_no, CTL_OF_SCB(scb));
4923:
4924: }
4925: #endif
4926: if (queue_flag)
4927: {
4928: p->dev_temp_queue_depth[tindex] =
4929: p->dev_active_cmds[tindex];
4930: if ( p->dev_last_queue_full[tindex] !=
4931: p->dev_active_cmds[tindex] )
4932: {
4933: p->dev_last_queue_full[tindex] =
4934: p->dev_active_cmds[tindex];
4935: p->dev_last_queue_full_count[tindex] = 0;
4936: }
4937: else
4938: {
4939: p->dev_last_queue_full_count[tindex]++;
4940: }
4941: if ( (p->dev_last_queue_full_count[tindex] > 14) &&
4942: (p->dev_active_cmds[tindex] > 4) )
4943: {
4944: if (aic7xxx_verbose & VERBOSE_NEGOTIATION2)
4945: printk(INFO_LEAD "Queue depth reduced to %d\n", p->host_no,
4946: CTL_OF_SCB(scb), p->dev_active_cmds[tindex]);
4947: p->dev_max_queue_depth[tindex] =
4948: p->dev_active_cmds[tindex];
4949: p->dev_last_queue_full[tindex] = 0;
4950: p->dev_last_queue_full_count[tindex] = 0;
4951: }
4952: }
4953: break;
4954: }
4955:
4956: default:
4957: if (aic7xxx_verbose & VERBOSE_SEQINT)
4958: printk(INFO_LEAD "Unexpected target status 0x%x.\n", p->host_no,
4959: CTL_OF_SCB(scb), scb->hscb->target_status);
4960: if (!aic7xxx_error(cmd))
4961: {
4962: aic7xxx_error(cmd) = DID_RETRY_COMMAND;
4963: }
4964: break;
4965: } /* end switch */
4966: } /* end else of */
4967: }
4968: break;
4969:
4970: case AWAITING_MSG:
4971: {
4972: unsigned char scb_index, msg_out;
4973:
4974: scb_index = aic_inb(p, SCB_TAG);
4975: msg_out = aic_inb(p, MSG_OUT);
4976: scb = p->scb_data->scb_array[scb_index];
4977: p->msg_index = p->msg_len = 0;
4978: /*
4979: * This SCB had a MK_MESSAGE set in its control byte informing
4980: * the sequencer that we wanted to send a special message to
4981: * this target.
4982: */
4983:
4984: if ( !(scb->flags & SCB_DEVICE_RESET) &&
4985: (aic_inb(p, MSG_OUT) == MSG_IDENTIFYFLAG) &&
4986: (scb->hscb->control & TAG_ENB) )
4987: {
4988: p->msg_buf[p->msg_index++] = scb->tag_action;
4989: p->msg_buf[p->msg_index++] = scb->hscb->tag;
4990: p->msg_len += 2;
4991: }
4992:
4993: if (scb->flags & SCB_DEVICE_RESET)
4994: {
4995: p->msg_buf[p->msg_index++] = MSG_BUS_DEV_RESET;
4996: p->msg_len++;
4997: if (aic7xxx_verbose & VERBOSE_RESET_PROCESS)
4998: printk(INFO_LEAD "Bus device reset mailed.\n",
4999: p->host_no, CTL_OF_SCB(scb));
5000: }
5001: else if (scb->flags & SCB_ABORT)
5002: {
5003: if (scb->tag_action)
5004: {
5005: p->msg_buf[p->msg_index++] = MSG_ABORT_TAG;
5006: }
5007: else
5008: {
5009: p->msg_buf[p->msg_index++] = MSG_ABORT;
5010: }
5011: p->msg_len++;
5012: if (aic7xxx_verbose & VERBOSE_ABORT_PROCESS)
5013: printk(INFO_LEAD "Abort message mailed.\n", p->host_no,
5014: CTL_OF_SCB(scb));
5015: }
5016: else if (scb->flags & SCB_MSGOUT_WDTR)
5017: {
5018: #ifdef AIC7XXX_VERBOSE_DEBUGGING
5019: if (aic7xxx_verbose > 0xffff)
5020: printk(INFO_LEAD "Sending WDTR message.\n", p->host_no,
5021: CTL_OF_SCB(scb));
5022: #endif
5023: aic7xxx_construct_wdtr(p,
5024: p->transinfo[TARGET_INDEX(scb->cmd)].goal_width);
5025: }
5026: else if (scb->flags & SCB_MSGOUT_SDTR)
5027: {
5028: unsigned int max_sync, period;
5029: /*
5030: * We need to set an accurate goal_offset instead of
5031: * the ridiculously high one we default to. We should
5032: * now know if we are wide. Plus, the WDTR code will
5033: * set our goal_offset for us as well.
5034: */
5035: if (p->transinfo[tindex].goal_offset)
5036: {
5037: if (p->features & AHC_ULTRA2)
5038: p->transinfo[tindex].goal_offset = MAX_OFFSET_ULTRA2;
5039: else if (p->transinfo[tindex].cur_width == MSG_EXT_WDTR_BUS_16_BIT)
5040: p->transinfo[tindex].goal_offset = MAX_OFFSET_16BIT;
5041: else
5042: p->transinfo[tindex].goal_offset = MAX_OFFSET_8BIT;
5043: }
5044: /*
5045: * Now that the device is selected, use the bits in SBLKCTL and
5046: * SSTAT2 to determine the max sync rate for this device.
5047: */
5048: if (p->features & AHC_ULTRA2)
5049: {
5050: if ( (aic_inb(p, SBLKCTL) & ENAB40) &&
5051: !(aic_inb(p, SSTAT2) & EXP_ACTIVE) )
5052: {
5053: max_sync = AHC_SYNCRATE_ULTRA2;
5054: }
5055: else
5056: {
5057: max_sync = AHC_SYNCRATE_ULTRA;
5058: }
5059: }
5060: else if (p->features & AHC_ULTRA)
5061: {
5062: max_sync = AHC_SYNCRATE_ULTRA;
5063: }
5064: else
5065: {
5066: max_sync = AHC_SYNCRATE_FAST;
5067: }
5068: period = p->transinfo[tindex].goal_period;
5069: aic7xxx_find_syncrate(p, &period, max_sync);
5070: #ifdef AIC7XXX_VERBOSE_DEBUGGING
5071: if (aic7xxx_verbose > 0xffff)
5072: printk(INFO_LEAD "Sending SDTR %d/%d message.\n", p->host_no,
5073: CTL_OF_SCB(scb),
5074: p->transinfo[tindex].goal_period,
5075: p->transinfo[tindex].goal_offset);
5076: #endif
5077: aic7xxx_construct_sdtr(p, period,
5078: p->transinfo[tindex].goal_offset);
5079: }
5080: else
5081: {
5082: sti();
5083: panic("aic7xxx: AWAITING_MSG for an SCB that does "
5084: "not have a waiting message.\n");
5085: }
5086: /*
5087: * We've set everything up to send our message, now to actually do
5088: * so we need to enable reqinit interrupts and let the interrupt
5089: * handler do the rest. We don't want to unpause the sequencer yet
5090: * though so we'll return early. We also have to make sure that
5091: * we clear the SEQINT *BEFORE* we set the REQINIT handler active
5092: * or else it's possible on VLB cards to loose the first REQINIT
5093: * interrupt. Edge triggered EISA cards could also loose this
5094: * interrupt, although PCI and level triggered cards should not
5095: * have this problem since they continually interrupt the kernel
5096: * until we take care of the situation.
5097: */
5098: scb->flags |= SCB_MSGOUT_SENT;
5099: p->msg_index = 0;
5100: p->msg_type = MSG_TYPE_INITIATOR_MSGOUT;
5101: p->flags |= AHC_HANDLING_REQINITS;
5102: aic_outb(p, aic_inb(p, SIMODE1) | ENREQINIT, SIMODE1);
5103: return;
5104: }
5105: break;
5106:
5107: case DATA_OVERRUN:
5108: {
5109: unsigned char scb_index = aic_inb(p, SCB_TAG);
5110: unsigned char lastphase = aic_inb(p, LASTPHASE);
5111: unsigned int i;
5112:
5113: scb = (p->scb_data->scb_array[scb_index]);
5114: /*
5115: * XXX - What do we really want to do on an overrun? The
5116: * mid-level SCSI code should handle this, but for now,
5117: * we'll just indicate that the command should retried.
5118: * If we retrieved sense info on this target, then the
5119: * base SENSE info should have been saved prior to the
5120: * overrun error. In that case, we return DID_OK and let
5121: * the mid level code pick up on the sense info. Otherwise
5122: * we return DID_ERROR so the command will get retried.
5123: */
5124: if ( !(scb->flags & SCB_SENSE) )
5125: {
5126: printk(WARN_LEAD "Data overrun detected in %s phase, tag %d;\n",
5127: p->host_no, CTL_OF_SCB(scb),
5128: (lastphase == P_DATAIN) ? "Data-In" : "Data-Out", scb->hscb->tag);
5129: printk(KERN_WARNING " %s seen Data Phase. Length=%d, NumSGs=%d.\n",
5130: (aic_inb(p, SEQ_FLAGS) & DPHASE) ? "Have" : "Haven't",
5131: scb->sg_length, scb->sg_count);
5132: for (i = 0; i < scb->sg_count; i++)
5133: {
5134: printk(KERN_WARNING " sg[%d] - Addr 0x%x : Length %d\n",
5135: i,
5136: le32_to_cpu(scb->sg_list[i].address),
5137: le32_to_cpu(scb->sg_list[i].length) );
5138: }
5139: aic7xxx_error(scb->cmd) = DID_ERROR;
5140: }
5141: else
5142: printk(INFO_LEAD "Data Overrun during SEND_SENSE operation.\n",
5143: p->host_no, CTL_OF_SCB(scb));
5144: }
5145: break;
5146:
5147: #if AIC7XXX_NOT_YET
5148: case TRACEPOINT:
5149: {
5150: printk(INFO_LEAD "Tracepoint #1 reached.\n", p->host_no, channel,
5151: target, lun);
5152: }
5153: break;
5154:
5155: case TRACEPOINT2:
5156: {
5157: printk(INFO_LEAD "Tracepoint #2 reached.\n", p->host_no, channel,
5158: target, lun);
5159: }
5160: break;
5161:
5162: /* XXX Fill these in later */
5163: case MSG_BUFFER_BUSY:
5164: printk("aic7xxx: Message buffer busy.\n");
5165: break;
5166: case MSGIN_PHASEMIS:
5167: printk("aic7xxx: Message-in phasemis.\n");
5168: break;
5169: #endif
5170:
5171: default: /* unknown */
5172: printk(WARN_LEAD "Unknown SEQINT, INTSTAT 0x%x, SCSISIGI 0x%x.\n",
5173: p->host_no, channel, target, lun, intstat,
5174: aic_inb(p, SCSISIGI));
5175: break;
5176: }
5177:
5178: /*
5179: * Clear the sequencer interrupt and unpause the sequencer.
5180: */
5181: unpause_sequencer(p, /* unpause always */ TRUE);
5182: }
5183:
5184: /*+F*************************************************************************
5185: * Function:
5186: * aic7xxx_parse_msg
5187: *
5188: * Description:
5189: * Parses incoming messages into actions on behalf of
5190: * aic7xxx_handle_reqinit
5191: *_F*************************************************************************/
5192: static int
5193: aic7xxx_parse_msg(struct aic7xxx_host *p, struct aic7xxx_scb *scb)
5194: {
5195: int reject, reply, done;
5196: unsigned char target_scsirate, tindex;
5197: unsigned short target_mask;
5198: unsigned char target, channel, lun;
5199:
5200: target = scb->cmd->target;
5201: channel = scb->cmd->channel;
5202: lun = scb->cmd->lun;
5203: reply = reject = done = FALSE;
5204: tindex = TARGET_INDEX(scb->cmd);
5205: target_scsirate = aic_inb(p, TARG_SCSIRATE + tindex);
5206: target_mask = (0x01 << tindex);
5207:
5208: /*
5209: * Parse as much of the message as is availible,
5210: * rejecting it if we don't support it. When
5211: * the entire message is availible and has been
5212: * handled, return TRUE indicating that we have
5213: * parsed an entire message.
5214: */
5215:
5216: if (p->msg_buf[0] != MSG_EXTENDED)
5217: {
5218: reject = TRUE;
5219: }
5220:
5221: /*
5222: * Just accept the length byte outright and perform
5223: * more checking once we know the message type.
5224: */
5225:
5226: if ( !reject && (p->msg_len > 2) )
5227: {
5228: switch(p->msg_buf[2])
5229: {
5230: case MSG_EXT_SDTR:
5231: {
5232: unsigned int period, offset;
5233: unsigned char maxsync, saved_offset;
5234: struct aic7xxx_syncrate *syncrate;
5235:
5236: if (p->msg_buf[1] != MSG_EXT_SDTR_LEN)
5237: {
5238: reject = TRUE;
5239: break;
5240: }
5241:
5242: if (p->msg_len < (MSG_EXT_SDTR_LEN + 2))
5243: {
5244: break;
5245: }
5246:
5247: period = p->msg_buf[3];
5248: saved_offset = offset = p->msg_buf[4];
5249:
5250: if (p->features & AHC_ULTRA2)
5251: {
5252: if ( (aic_inb(p, SBLKCTL) & ENAB40) &&
5253: !(aic_inb(p, SSTAT2) & EXP_ACTIVE) )
5254: {
5255: maxsync = AHC_SYNCRATE_ULTRA2;
5256: }
5257: else
5258: {
5259: maxsync = AHC_SYNCRATE_ULTRA;
5260: }
5261: }
5262: else if (p->features & AHC_ULTRA)
5263: {
5264: maxsync = AHC_SYNCRATE_ULTRA;
5265: }
5266: else
5267: {
5268: maxsync = AHC_SYNCRATE_FAST;
5269: }
5270:
5271: #ifdef AIC7XXX_VERBOSE_DEBUGGING
5272: if (aic7xxx_verbose > 0xffff)
5273: {
5274: printk(INFO_LEAD "Finished receipt of SDTR, parsing %d/%d\n",
5275: p->host_no, CTL_OF_SCB(scb), period, offset);
5276: syncrate = aic7xxx_find_syncrate(p, &period, maxsync);
5277: printk(INFO_LEAD "After find_syncrate() %d/%d\n",
5278: p->host_no, CTL_OF_SCB(scb), period, offset);
5279: aic7xxx_validate_offset(p, syncrate, &offset,
5280: target_scsirate & WIDEXFER);
5281: printk(INFO_LEAD "After validate_offset() %d/%d\n",
5282: p->host_no, CTL_OF_SCB(scb), period, offset);
5283: aic7xxx_set_syncrate(p, syncrate, target, channel, period,
5284: offset, AHC_TRANS_ACTIVE|AHC_TRANS_CUR);
5285: printk(INFO_LEAD "Final values of Period/Offset as set: %d/%d\n",
5286: p->host_no, CTL_OF_SCB(scb), period, offset);
5287: }
5288: else
5289: {
5290: syncrate = aic7xxx_find_syncrate(p, &period, maxsync);
5291: aic7xxx_validate_offset(p, syncrate, &offset,
5292: target_scsirate & WIDEXFER);
5293: aic7xxx_set_syncrate(p, syncrate, target, channel, period,
5294: offset, AHC_TRANS_ACTIVE|AHC_TRANS_CUR);
5295: }
5296: #else
5297: syncrate = aic7xxx_find_syncrate(p, &period, maxsync);
5298: aic7xxx_validate_offset(p, syncrate, &offset,
5299: target_scsirate & WIDEXFER);
5300: aic7xxx_set_syncrate(p, syncrate, target, channel, period,
5301: offset, AHC_TRANS_ACTIVE|AHC_TRANS_CUR);
5302: #endif
5303:
5304: if (offset == 0)
5305: {
5306: /*
5307: * Uhh ohh, things fell through to async....update the goal
5308: * items and the needsdtr_copy to reflect this...
5309: */
5310: aic7xxx_set_syncrate(p, syncrate, target, channel, period,
5311: offset, AHC_TRANS_GOAL|AHC_TRANS_QUITE);
5312: p->needsdtr_copy &= ~target_mask;
5313: }
5314: /*
5315: * Did we start this, if not, or if we went to low and had to
5316: * go async, then send an SDTR back to the target
5317: */
5318: p->needsdtr &= ~target_mask;
5319: p->sdtr_pending &= ~target_mask;
5320: if ( ((scb->flags & (SCB_MSGOUT_SENT|SCB_MSGOUT_SDTR)) ==
5321: (SCB_MSGOUT_SENT|SCB_MSGOUT_SDTR)) &&
5322: (offset == saved_offset) )
5323: {
5324: scb->flags &= ~SCB_MSGOUT_BITS;
5325: }
5326: else
5327: {
5328: /*
5329: * Send a reply SDTR back. Even if we sent the first one, it
5330: * is valid to send another one out immediately to re-negotiate
5331: * things, and a few devices don't like getting rejects after
5332: * we already sent them one SDTR. Just send an SDTR for async
5333: * this time if need be (or for the correct params if we didn't
5334: * start all of this). If this is a Reject Reply type message,
5335: * then we've put the async settings into the goal area for
5336: * future reference (when we get the AWAITING_MSG interrupt).
5337: * If this is a case where we are responding to the target's
5338: * initiated SDTR, then leave our own goal and user values in
5339: * place (unless the device hasn't been scanned yet, in which
5340: * case, put the user values into the goal values so we don't
5341: * send out an Async message).
5342: */
5343: if ( !(p->dev_flags[tindex] & DEVICE_SCANNED) )
5344: {
5345: p->transinfo[tindex].goal_width =
5346: p->transinfo[tindex].user_width;
5347: p->transinfo[tindex].goal_period =
5348: p->transinfo[tindex].user_period;
5349: p->transinfo[tindex].goal_offset =
5350: p->transinfo[tindex].user_offset;
5351: p->needwdtr_copy |= target_mask;
5352: p->needsdtr_copy |= target_mask;
5353: }
5354: scb->flags &= ~SCB_MSGOUT_BITS;
5355: scb->flags |= SCB_MSGOUT_SDTR;
5356: aic_outb(p, HOST_MSG, MSG_OUT);
5357: aic_outb(p, aic_inb(p, SCSISIGO) | ATNO, SCSISIGO);
5358: }
5359: done = TRUE;
5360: break;
5361: }
5362: case MSG_EXT_WDTR:
5363: {
5364: unsigned char bus_width;
5365:
5366: if (p->msg_buf[1] != MSG_EXT_WDTR_LEN)
5367: {
5368: reject = TRUE;
5369: break;
5370: }
5371:
5372: if (p->msg_len < (MSG_EXT_WDTR_LEN + 2))
5373: {
5374: break;
5375: }
5376:
5377: bus_width = p->msg_buf[3];
5378: if ( (scb->flags & (SCB_MSGOUT_SENT|SCB_MSGOUT_WDTR)) ==
5379: (SCB_MSGOUT_SENT|SCB_MSGOUT_WDTR) )
5380: {
5381: switch(bus_width)
5382: {
5383: default:
5384: {
5385: reject = TRUE;
5386: if ( (aic7xxx_verbose & VERBOSE_NEGOTIATION2) &&
5387: ((p->dev_flags[tindex] & DEVICE_PRINT_WDTR) ||
5388: (aic7xxx_verbose > 0xffff)) )
5389: {
5390: printk(INFO_LEAD "Requesting %d bit transfers, rejecting.\n",
5391: p->host_no, CTL_OF_SCB(scb), 8 * (0x01 << bus_width));
5392: p->dev_flags[tindex] &= ~DEVICE_PRINT_WDTR;
5393: }
5394: } /* We fall through on purpose */
5395: case MSG_EXT_WDTR_BUS_8_BIT:
5396: {
5397: bus_width = MSG_EXT_WDTR_BUS_8_BIT;
5398: p->needwdtr_copy &= ~target_mask;
5399: break;
5400: }
5401: case MSG_EXT_WDTR_BUS_16_BIT:
5402: {
5403: break;
5404: }
5405: }
5406: scb->flags &= ~SCB_MSGOUT_BITS;
5407: p->wdtr_pending &= ~target_mask;
5408: p->needwdtr &= ~target_mask;
5409: }
5410: else
5411: {
5412: scb->flags &= ~SCB_MSGOUT_BITS;
5413: scb->flags |= SCB_MSGOUT_WDTR;
5414: reply = TRUE;
5415: if ( !(p->dev_flags[tindex] & DEVICE_SCANNED) )
5416: {
5417: /*
5418: * Well, we now know the WDTR and SYNC caps of this device since
5419: * it contacted us first, mark it as such and copy the user stuff
5420: * over to the goal stuff.
5421: */
5422: p->transinfo[tindex].goal_width =
5423: p->transinfo[tindex].user_width;
5424: p->transinfo[tindex].goal_period =
5425: p->transinfo[tindex].user_period;
5426: p->transinfo[tindex].goal_offset =
5427: p->transinfo[tindex].user_offset;
5428: p->needwdtr_copy |= target_mask;
5429: p->needsdtr_copy |= target_mask;
5430: }
5431: switch(bus_width)
5432: {
5433: default:
5434: {
5435: if ( (p->features & AHC_WIDE) &&
5436: (p->transinfo[tindex].goal_width ==
5437: MSG_EXT_WDTR_BUS_16_BIT) )
5438: {
5439: bus_width = MSG_EXT_WDTR_BUS_16_BIT;
5440: break;
5441: }
5442: } /* Fall through if we aren't a wide card */
5443: case MSG_EXT_WDTR_BUS_8_BIT:
5444: {
5445: p->needwdtr_copy &= ~target_mask;
5446: bus_width = MSG_EXT_WDTR_BUS_8_BIT;
5447: break;
5448: }
5449: }
5450: p->needwdtr &= ~target_mask;
5451: p->wdtr_pending &= ~target_mask;
5452: aic_outb(p, HOST_MSG, MSG_OUT);
5453: aic_outb(p, aic_inb(p, SCSISIGO) | ATNO, SCSISIGO);
5454: }
5455: aic7xxx_set_width(p, target, channel, lun, bus_width,
5456: AHC_TRANS_ACTIVE|AHC_TRANS_CUR);
5457:
5458: /*
5459: * By virtue of the SCSI spec, a WDTR message negates any existing
5460: * SDTR negotiations. So, even if needsdtr isn't marked for this
5461: * device, we still have to do a new SDTR message if the device
5462: * supports SDTR at all. Therefore, we check needsdtr_copy instead
5463: * of needstr.
5464: */
5465: aic7xxx_set_syncrate(p, NULL, target, channel, 0, 0,
5466: AHC_TRANS_ACTIVE|AHC_TRANS_CUR|AHC_TRANS_QUITE);
5467: if ( (p->needsdtr_copy & target_mask) &&
5468: !(p->sdtr_pending & target_mask))
5469: {
5470: p->needsdtr |= target_mask;
5471: if ( !reject && !reply )
5472: {
5473: scb->flags &= ~SCB_MSGOUT_WDTR;
5474: if (p->transinfo[tindex].goal_period)
5475: {
5476: p->sdtr_pending |= target_mask;
5477: scb->flags |= SCB_MSGOUT_SDTR;
5478: aic_outb(p, HOST_MSG, MSG_OUT);
5479: aic_outb(p, aic_inb(p, SCSISIGO) | ATNO, SCSISIGO);
5480: }
5481: }
5482: }
5483: done = TRUE;
5484: break;
5485: }
5486: default:
5487: {
5488: reject = TRUE;
5489: break;
5490: }
5491: } /* end of switch(p->msg_type) */
5492: } /* end of if (!reject && (p->msg_len > 2)) */
5493:
5494: if (reject)
5495: {
5496: aic_outb(p, MSG_MESSAGE_REJECT, MSG_OUT);
5497: aic_outb(p, aic_inb(p, SCSISIGO) | ATNO, SCSISIGO);
5498: done = TRUE;
5499: }
5500: return(done);
5501: }
5502:
5503:
5504: /*+F*************************************************************************
5505: * Function:
5506: * aic7xxx_handle_reqinit
5507: *
5508: * Description:
5509: * Interrupt handler for REQINIT interrupts (used to transfer messages to
5510: * and from devices).
5511: *_F*************************************************************************/
5512: static void
5513: aic7xxx_handle_reqinit(struct aic7xxx_host *p, struct aic7xxx_scb *scb)
5514: {
5515: unsigned char lastbyte;
5516: unsigned char phasemis;
5517: int done = FALSE;
5518:
5519: switch(p->msg_type)
5520: {
5521: case MSG_TYPE_INITIATOR_MSGOUT:
5522: {
5523: if (p->msg_len == 0)
5524: panic("aic7xxx: REQINIT with no active message!\n");
5525:
5526: lastbyte = (p->msg_index == (p->msg_len - 1));
5527: phasemis = ( aic_inb(p, SCSISIGI) & PHASE_MASK) != P_MESGOUT;
5528:
5529: if (lastbyte || phasemis)
5530: {
5531: /* Time to end the message */
5532: p->msg_len = 0;
5533: p->msg_type = MSG_TYPE_NONE;
5534: /*
5535: * NOTE-TO-MYSELF: If you clear the REQINIT after you
5536: * disable REQINITs, then cases of REJECT_MSG stop working
5537: * and hang the bus
5538: */
5539: aic_outb(p, aic_inb(p, SIMODE1) & ~ENREQINIT, SIMODE1);
5540: aic_outb(p, CLRSCSIINT, CLRINT);
5541: p->flags &= ~AHC_HANDLING_REQINITS;
5542:
5543: if (phasemis == 0)
5544: {
5545: aic_outb(p, p->msg_buf[p->msg_index], SINDEX);
5546: aic_outb(p, 0, RETURN_1);
5547: #ifdef AIC7XXX_VERBOSE_DEBUGGING
5548: if (aic7xxx_verbose > 0xffff)
5549: printk(INFO_LEAD "Completed sending of REQINIT message.\n",
5550: p->host_no, CTL_OF_SCB(scb));
5551: #endif
5552: }
5553: else
5554: {
5555: aic_outb(p, MSGOUT_PHASEMIS, RETURN_1);
5556: #ifdef AIC7XXX_VERBOSE_DEBUGGING
5557: if (aic7xxx_verbose > 0xffff)
5558: printk(INFO_LEAD "PHASEMIS while sending REQINIT message.\n",
5559: p->host_no, CTL_OF_SCB(scb));
5560: #endif
5561: }
5562: unpause_sequencer(p, TRUE);
5563: }
5564: else
5565: {
5566: /*
5567: * Present the byte on the bus (clearing REQINIT) but don't
5568: * unpause the sequencer.
5569: */
5570: aic_outb(p, CLRREQINIT, CLRSINT1);
5571: aic_outb(p, CLRSCSIINT, CLRINT);
5572: aic_outb(p, p->msg_buf[p->msg_index++], SCSIDATL);
5573: }
5574: break;
5575: }
5576: case MSG_TYPE_INITIATOR_MSGIN:
5577: {
5578: phasemis = ( aic_inb(p, SCSISIGI) & PHASE_MASK ) != P_MESGIN;
5579:
5580: if (phasemis == 0)
5581: {
5582: p->msg_len++;
5583: /* Pull the byte in without acking it */
5584: p->msg_buf[p->msg_index] = aic_inb(p, SCSIBUSL);
5585: done = aic7xxx_parse_msg(p, scb);
5586: /* Ack the byte */
5587: aic_outb(p, CLRREQINIT, CLRSINT1);
5588: aic_outb(p, CLRSCSIINT, CLRINT);
5589: aic_inb(p, SCSIDATL);
5590: p->msg_index++;
5591: }
5592: if (phasemis || done)
5593: {
5594: #ifdef AIC7XXX_VERBOSE_DEBUGGING
5595: if (aic7xxx_verbose > 0xffff)
5596: {
5597: if (phasemis)
5598: printk(INFO_LEAD "PHASEMIS while receiving REQINIT message.\n",
5599: p->host_no, CTL_OF_SCB(scb));
5600: else
5601: printk(INFO_LEAD "Completed receipt of REQINIT message.\n",
5602: p->host_no, CTL_OF_SCB(scb));
5603: }
5604: #endif
5605: /* Time to end our message session */
5606: p->msg_len = 0;
5607: p->msg_type = MSG_TYPE_NONE;
5608: aic_outb(p, aic_inb(p, SIMODE1) & ~ENREQINIT, SIMODE1);
5609: aic_outb(p, CLRSCSIINT, CLRINT);
5610: p->flags &= ~AHC_HANDLING_REQINITS;
5611: unpause_sequencer(p, TRUE);
5612: }
5613: break;
5614: }
5615: default:
5616: {
5617: panic("aic7xxx: Unknown REQINIT message type.\n");
5618: break;
5619: }
5620: } /* End of switch(p->msg_type) */
5621: }
5622:
5623: /*+F*************************************************************************
5624: * Function:
5625: * aic7xxx_handle_scsiint
5626: *
5627: * Description:
5628: * Interrupt handler for SCSI interrupts (SCSIINT).
5629: *-F*************************************************************************/
5630: static void
5631: aic7xxx_handle_scsiint(struct aic7xxx_host *p, unsigned char intstat)
5632: {
5633: unsigned char scb_index;
5634: unsigned char status;
5635: struct aic7xxx_scb *scb;
5636:
5637: scb_index = aic_inb(p, SCB_TAG);
5638: status = aic_inb(p, SSTAT1);
5639:
5640: if (scb_index < p->scb_data->numscbs)
5641: {
5642: scb = p->scb_data->scb_array[scb_index];
5643: if ((scb->flags & SCB_ACTIVE) == 0)
5644: {
5645: scb = NULL;
5646: }
5647: }
5648: else
5649: {
5650: scb = NULL;
5651: }
5652:
5653:
5654: if ((status & SCSIRSTI) != 0)
5655: {
5656: int channel;
5657:
5658: if ( (p->chip & AHC_CHIPID_MASK) == AHC_AIC7770 )
5659: channel = (aic_inb(p, SBLKCTL) & SELBUSB) >> 3;
5660: else
5661: channel = 0;
5662:
5663: if (aic7xxx_verbose & VERBOSE_RESET)
5664: printk(WARN_LEAD "Someone else reset the channel!!\n",
5665: p->host_no, channel, -1, -1);
5666: /*
5667: * Go through and abort all commands for the channel, but do not
5668: * reset the channel again.
5669: */
5670: aic7xxx_reset_channel(p, channel, /* Initiate Reset */ FALSE);
5671: aic7xxx_run_done_queue(p, FALSE);
5672: scb = NULL;
5673: }
5674: else if ( ((status & BUSFREE) != 0) && ((status & SELTO) == 0) )
5675: {
5676: /*
5677: * First look at what phase we were last in. If it's message-out,
5678: * chances are pretty good that the bus free was in response to
5679: * one of our abort requests.
5680: */
5681: unsigned char lastphase = aic_inb(p, LASTPHASE);
5682: unsigned char saved_tcl = aic_inb(p, SAVED_TCL);
5683: unsigned char target = (saved_tcl >> 4) & 0x0F;
5684: int channel;
5685: int printerror = TRUE;
5686:
5687: if ( (p->chip & AHC_CHIPID_MASK) == AHC_AIC7770 )
5688: channel = (aic_inb(p, SBLKCTL) & SELBUSB) >> 3;
5689: else
5690: channel = 0;
5691:
5692: aic_outb(p, aic_inb(p, SCSISEQ) & (ENSELI|ENRSELI|ENAUTOATNP),
5693: SCSISEQ);
5694: if (lastphase == P_MESGOUT)
5695: {
5696: unsigned char message;
5697:
5698: message = aic_inb(p, SINDEX);
5699:
5700: if ((message == MSG_ABORT) || (message == MSG_ABORT_TAG))
5701: {
5702: if (aic7xxx_verbose & VERBOSE_ABORT_PROCESS)
5703: printk(INFO_LEAD "SCB %d abort delivered.\n", p->host_no,
5704: CTL_OF_SCB(scb), scb->hscb->tag);
5705: aic7xxx_reset_device(p, target, channel, ALL_LUNS,
5706: (message == MSG_ABORT) ? SCB_LIST_NULL : scb->hscb->tag );
5707: aic7xxx_run_done_queue(p, FALSE);
5708: scb = NULL;
5709: printerror = 0;
5710: }
5711: else if (message == MSG_BUS_DEV_RESET)
5712: {
5713: aic7xxx_handle_device_reset(p, target, channel);
5714: scb = NULL;
5715: printerror = 0;
5716: }
5717: }
5718: if (printerror != 0)
5719: {
5720: if (scb != NULL)
5721: {
5722: unsigned char tag;
5723:
5724: if ((scb->hscb->control & TAG_ENB) != 0)
5725: {
5726: tag = scb->hscb->tag;
5727: }
5728: else
5729: {
5730: tag = SCB_LIST_NULL;
5731: }
5732: aic7xxx_reset_device(p, target, channel, ALL_LUNS, tag);
5733: aic7xxx_run_done_queue(p, FALSE);
5734: }
5735: printk(INFO_LEAD "Unexpected busfree, LASTPHASE = 0x%x, "
5736: "SEQADDR = 0x%x\n", p->host_no, channel, target, -1, lastphase,
5737: (aic_inb(p, SEQADDR1) << 8) | aic_inb(p, SEQADDR0));
5738: scb = NULL;
5739: }
5740: aic_outb(p, MSG_NOOP, MSG_OUT);
5741: aic_outb(p, aic_inb(p, SIMODE1) & ~(ENBUSFREE|ENREQINIT),
5742: SIMODE1);
5743: p->flags &= ~AHC_HANDLING_REQINITS;
5744: aic_outb(p, CLRBUSFREE, CLRSINT1);
5745: aic_outb(p, CLRSCSIINT, CLRINT);
5746: restart_sequencer(p);
5747: unpause_sequencer(p, TRUE);
5748: }
5749: else if ((status & SELTO) != 0)
5750: {
5751: unsigned char scbptr;
5752: unsigned char nextscb;
5753: Scsi_Cmnd *cmd;
5754:
5755: scbptr = aic_inb(p, WAITING_SCBH);
5756: if (scbptr > p->scb_data->maxhscbs)
5757: {
5758: /*
5759: * I'm still trying to track down exactly how this happens, but until
5760: * I find it, this code will make sure we aren't passing bogus values
5761: * into the SCBPTR register, even if that register will just wrap
5762: * things around, we still don't like having out of range variables.
5763: *
5764: * NOTE: Don't check the aic7xxx_verbose variable, I want this message
5765: * to always be displayed.
5766: */
5767: printk(INFO_LEAD "Invalid WAITING_SCBH value %d, improvising.\n",
5768: p->host_no, -1, -1, -1, scbptr);
5769: if (p->scb_data->maxhscbs > 4)
5770: scbptr &= (p->scb_data->maxhscbs - 1);
5771: else
5772: scbptr &= 0x03;
5773: }
5774: aic_outb(p, scbptr, SCBPTR);
5775: scb_index = aic_inb(p, SCB_TAG);
5776:
5777: scb = NULL;
5778: if (scb_index < p->scb_data->numscbs)
5779: {
5780: scb = p->scb_data->scb_array[scb_index];
5781: if ((scb->flags & SCB_ACTIVE) == 0)
5782: {
5783: scb = NULL;
5784: }
5785: }
5786: if (scb == NULL)
5787: {
5788: printk(WARN_LEAD "Referenced SCB %d not valid during SELTO.\n",
5789: p->host_no, -1, -1, -1, scb_index);
5790: printk(KERN_WARNING " SCSISEQ = 0x%x SEQADDR = 0x%x SSTAT0 = 0x%x "
5791: "SSTAT1 = 0x%x\n", aic_inb(p, SCSISEQ),
5792: aic_inb(p, SEQADDR0) | (aic_inb(p, SEQADDR1) << 8),
5793: aic_inb(p, SSTAT0), aic_inb(p, SSTAT1));
5794: if (aic7xxx_panic_on_abort)
5795: aic7xxx_panic_abort(p, NULL);
5796: }
5797: else
5798: {
5799: cmd = scb->cmd;
5800: cmd->result = (DID_TIME_OUT << 16);
5801:
5802: /*
5803: * Clear out this hardware SCB
5804: */
5805: aic_outb(p, 0, SCB_CONTROL);
5806:
5807: /*
5808: * Clear out a few values in the card that are in an undetermined
5809: * state.
5810: */
5811: aic_outb(p, MSG_NOOP, MSG_OUT);
5812:
5813: /*
5814: * Shift the waiting for selection queue forward
5815: */
5816: nextscb = aic_inb(p, SCB_NEXT);
5817: aic_outb(p, nextscb, WAITING_SCBH);
5818:
5819: /*
5820: * Put this SCB back on the free list.
5821: */
5822: aic7xxx_add_curscb_to_free_list(p);
5823: /*
5824: * XXX - If we queued an abort tag, go clean up the disconnected list.
5825: * We know that this particular SCB had to be the queued abort since
5826: * the disconnected SCB would have gotten a reconnect instead.
5827: * However, if this is an abort command, then DID_TIMEOUT isn't
5828: * appropriate, neither is returning the command for that matter.
5829: * What we need to do then is to let the command timeout again so
5830: * we get a reset since this abort just failed.
5831: */
5832: #ifdef AIC7XXX_VERBOSE_DEBUGGING
5833: if (aic7xxx_verbose > 0xffff)
5834: printk(INFO_LEAD "Selection Timeout.\n", p->host_no, CTL_OF_SCB(scb));
5835: #endif
5836: if (p->flags & SCB_QUEUED_ABORT)
5837: {
5838: cmd->result = 0;
5839: scb->flags &= ~SCB_QUEUED_ABORT;
5840: scb = NULL;
5841: }
5842: }
5843: /*
5844: * Restarting the sequencer will stop the selection and make sure devices
5845: * are allowed to reselect in.
5846: */
5847: aic_outb(p, 0, SCSISEQ);
5848: aic_outb(p, aic_inb(p, SIMODE1) & ~(ENREQINIT|ENBUSFREE), SIMODE1);
5849: p->flags &= ~AHC_HANDLING_REQINITS;
5850: aic_outb(p, CLRSELTIMEO | CLRBUSFREE, CLRSINT1);
5851: aic_outb(p, CLRSCSIINT, CLRINT);
5852: restart_sequencer(p);
5853: unpause_sequencer(p, TRUE);
5854: }
5855: else if (scb == NULL)
5856: {
5857: printk(WARN_LEAD "aic7xxx_isr - referenced scb not valid "
5858: "during scsiint 0x%x scb(%d)\n"
5859: " SIMODE0 0x%x, SIMODE1 0x%x, SSTAT0 0x%x, SEQADDR 0x%x\n",
5860: p->host_no, -1, -1, -1, status, scb_index, aic_inb(p, SIMODE0),
5861: aic_inb(p, SIMODE1), aic_inb(p, SSTAT0),
5862: (aic_inb(p, SEQADDR1) << 8) | aic_inb(p, SEQADDR0));
5863: /*
5864: * Turn off the interrupt and set status to zero, so that it
5865: * falls through the rest of the SCSIINT code.
5866: */
5867: aic_outb(p, status, CLRSINT1);
5868: aic_outb(p, CLRSCSIINT, CLRINT);
5869: unpause_sequencer(p, /* unpause always */ TRUE);
5870: scb = NULL;
5871: }
5872: else if (status & SCSIPERR)
5873: {
5874: /*
5875: * Determine the bus phase and queue an appropriate message.
5876: */
5877: char *phase;
5878: Scsi_Cmnd *cmd;
5879: unsigned char mesg_out = MSG_NOOP;
5880: unsigned char lastphase = aic_inb(p, LASTPHASE);
5881:
5882: cmd = scb->cmd;
5883: switch (lastphase)
5884: {
5885: case P_DATAOUT:
5886: phase = "Data-Out";
5887: break;
5888: case P_DATAIN:
5889: phase = "Data-In";
5890: mesg_out = MSG_INITIATOR_DET_ERR;
5891: break;
5892: case P_COMMAND:
5893: phase = "Command";
5894: break;
5895: case P_MESGOUT:
5896: phase = "Message-Out";
5897: break;
5898: case P_STATUS:
5899: phase = "Status";
5900: mesg_out = MSG_INITIATOR_DET_ERR;
5901: break;
5902: case P_MESGIN:
5903: phase = "Message-In";
5904: mesg_out = MSG_PARITY_ERROR;
5905: break;
5906: default:
5907: phase = "unknown";
5908: break;
5909: }
5910:
5911: /*
5912: * A parity error has occurred during a data
5913: * transfer phase. Flag it and continue.
5914: */
5915: printk(WARN_LEAD "Parity error during %s phase.\n",
5916: p->host_no, CTL_OF_SCB(scb), phase);
5917:
5918: /*
5919: * We've set the hardware to assert ATN if we get a parity
5920: * error on "in" phases, so all we need to do is stuff the
5921: * message buffer with the appropriate message. "In" phases
5922: * have set mesg_out to something other than MSG_NOP.
5923: */
5924: if (mesg_out != MSG_NOOP)
5925: {
5926: aic_outb(p, mesg_out, MSG_OUT);
5927: scb = NULL;
5928: }
5929: aic_outb(p, CLRSCSIPERR, CLRSINT1);
5930: aic_outb(p, CLRSCSIINT, CLRINT);
5931: unpause_sequencer(p, /* unpause_always */ TRUE);
5932: }
5933: else if ( (status & REQINIT) &&
5934: (p->flags & AHC_HANDLING_REQINITS) )
5935: {
5936: #ifdef AIC7XXX_VERBOSE_DEBUGGING
5937: if (aic7xxx_verbose > 0xffff)
5938: printk(INFO_LEAD "Handling REQINIT, SSTAT1=0x%x.\n", p->host_no,
5939: CTL_OF_SCB(scb), aic_inb(p, SSTAT1));
5940: #endif
5941: aic7xxx_handle_reqinit(p, scb);
5942: return;
5943: }
5944: else
5945: {
5946: /*
5947: * We don't know what's going on. Turn off the
5948: * interrupt source and try to continue.
5949: */
5950: if (aic7xxx_verbose & VERBOSE_SCSIINT)
5951: printk(INFO_LEAD "Unknown SCSIINT status, SSTAT1(0x%x).\n",
5952: p->host_no, -1, -1, -1, status);
5953: aic_outb(p, status, CLRSINT1);
5954: aic_outb(p, CLRSCSIINT, CLRINT);
5955: unpause_sequencer(p, /* unpause always */ TRUE);
5956: scb = NULL;
5957: }
5958: if (scb != NULL)
5959: {
5960: aic7xxx_done(p, scb);
5961: }
5962: }
5963:
5964: #ifdef AIC7XXX_VERBOSE_DEBUGGING
5965: static void
5966: aic7xxx_check_scbs(struct aic7xxx_host *p, char *buffer)
5967: {
5968: unsigned char saved_scbptr, free_scbh, dis_scbh, wait_scbh, temp;
5969: int i, bogus, lost;
5970: static unsigned char scb_status[AIC7XXX_MAXSCB];
5971:
5972: #define SCB_NO_LIST 0
5973: #define SCB_FREE_LIST 1
5974: #define SCB_WAITING_LIST 2
5975: #define SCB_DISCONNECTED_LIST 4
5976: #define SCB_CURRENTLY_ACTIVE 8
5977:
5978: /*
5979: * Note, these checks will fail on a regular basis once the machine moves
5980: * beyond the bus scan phase. The problem is race conditions concerning
5981: * the scbs and where they are linked in. When you have 30 or so commands
5982: * outstanding on the bus, and run this twice with every interrupt, the
5983: * chances get pretty good that you'll catch the sequencer with an SCB
5984: * only partially linked in. Therefore, once we pass the scan phase
5985: * of the bus, we really should disable this function.
5986: */
5987: bogus = FALSE;
5988: memset(&scb_status[0], 0, sizeof(scb_status));
5989: pause_sequencer(p);
5990: saved_scbptr = aic_inb(p, SCBPTR);
5991: if (saved_scbptr >= p->scb_data->maxhscbs)
5992: {
5993: printk("Bogus SCBPTR %d\n", saved_scbptr);
5994: bogus = TRUE;
5995: }
5996: scb_status[saved_scbptr] = SCB_CURRENTLY_ACTIVE;
5997: free_scbh = aic_inb(p, FREE_SCBH);
5998: if ( (free_scbh != SCB_LIST_NULL) &&
5999: (free_scbh >= p->scb_data->maxhscbs) )
6000: {
6001: printk("Bogus FREE_SCBH %d\n", free_scbh);
6002: bogus = TRUE;
6003: }
6004: else
6005: {
6006: temp = free_scbh;
6007: while( (temp != SCB_LIST_NULL) && (temp < p->scb_data->maxhscbs) )
6008: {
6009: if(scb_status[temp] & 0x07)
6010: {
6011: printk("HSCB %d on multiple lists, status 0x%02x", temp,
6012: scb_status[temp] | SCB_FREE_LIST);
6013: bogus = TRUE;
6014: }
6015: scb_status[temp] |= SCB_FREE_LIST;
6016: aic_outb(p, temp, SCBPTR);
6017: temp = aic_inb(p, SCB_NEXT);
6018: }
6019: }
6020:
6021: dis_scbh = aic_inb(p, DISCONNECTED_SCBH);
6022: if ( (dis_scbh != SCB_LIST_NULL) &&
6023: (dis_scbh >= p->scb_data->maxhscbs) )
6024: {
6025: printk("Bogus DISCONNECTED_SCBH %d\n", dis_scbh);
6026: bogus = TRUE;
6027: }
6028: else
6029: {
6030: temp = dis_scbh;
6031: while( (temp != SCB_LIST_NULL) && (temp < p->scb_data->maxhscbs) )
6032: {
6033: if(scb_status[temp] & 0x07)
6034: {
6035: printk("HSCB %d on multiple lists, status 0x%02x", temp,
6036: scb_status[temp] | SCB_DISCONNECTED_LIST);
6037: bogus = TRUE;
6038: }
6039: scb_status[temp] |= SCB_DISCONNECTED_LIST;
6040: aic_outb(p, temp, SCBPTR);
6041: temp = aic_inb(p, SCB_NEXT);
6042: }
6043: }
6044:
6045: wait_scbh = aic_inb(p, WAITING_SCBH);
6046: if ( (wait_scbh != SCB_LIST_NULL) &&
6047: (wait_scbh >= p->scb_data->maxhscbs) )
6048: {
6049: printk("Bogus WAITING_SCBH %d\n", wait_scbh);
6050: bogus = TRUE;
6051: }
6052: else
6053: {
6054: temp = wait_scbh;
6055: while( (temp != SCB_LIST_NULL) && (temp < p->scb_data->maxhscbs) )
6056: {
6057: if(scb_status[temp] & 0x07)
6058: {
6059: printk("HSCB %d on multiple lists, status 0x%02x", temp,
6060: scb_status[temp] | SCB_WAITING_LIST);
6061: bogus = TRUE;
6062: }
6063: scb_status[temp] |= SCB_WAITING_LIST;
6064: aic_outb(p, temp, SCBPTR);
6065: temp = aic_inb(p, SCB_NEXT);
6066: }
6067: }
6068:
6069: lost=0;
6070: for(i=0; i < p->scb_data->maxhscbs; i++)
6071: {
6072: aic_outb(p, i, SCBPTR);
6073: temp = aic_inb(p, SCB_NEXT);
6074: if ( ((temp != SCB_LIST_NULL) &&
6075: (temp >= p->scb_data->maxhscbs)) )
6076: {
6077: printk("HSCB %d bad, SCB_NEXT invalid(%d).\n", i, temp);
6078: bogus = TRUE;
6079: }
6080: if ( temp == i )
6081: {
6082: printk("HSCB %d bad, SCB_NEXT points to self.\n", i);
6083: bogus = TRUE;
6084: }
6085: temp = aic_inb(p, SCB_PREV);
6086: if ((temp != SCB_LIST_NULL) &&
6087: (temp >= p->scb_data->maxhscbs))
6088: {
6089: printk("HSCB %d bad, SCB_PREV invalid(%d).\n", i, temp);
6090: bogus = TRUE;
6091: }
6092: if (scb_status[i] == 0)
6093: lost++;
6094: if (lost > 1)
6095: {
6096: printk("Too many lost scbs.\n");
6097: bogus=TRUE;
6098: }
6099: }
6100: aic_outb(p, saved_scbptr, SCBPTR);
6101: unpause_sequencer(p, FALSE);
6102: if (bogus)
6103: {
6104: printk("Bogus parameters found in card SCB array structures.\n");
6105: printk("%s\n", buffer);
6106: aic7xxx_panic_abort(p, NULL);
6107: }
6108: return;
6109: }
6110: #endif
6111:
6112: /*+F*************************************************************************
6113: * Function:
6114: * aic7xxx_isr
6115: *
6116: * Description:
6117: * SCSI controller interrupt handler.
6118: *-F*************************************************************************/
6119: static void
6120: aic7xxx_isr(int irq, void *dev_id, struct pt_regs *regs)
6121: {
6122: struct aic7xxx_host *p;
6123: unsigned char intstat;
6124:
6125: p = (struct aic7xxx_host *)dev_id;
6126:
6127: /*
6128: * Just a few sanity checks. Make sure that we have an int pending.
6129: * Also, if PCI, then we are going to check for a PCI bus error status
6130: * should we get too many spurious interrupts.
6131: */
6132: if (!((intstat = aic_inb(p, INTSTAT)) & INT_PEND))
6133: {
6134: #ifdef CONFIG_PCI
6135: if ( (p->chip & AHC_PCI) && (p->spurious_int > 500) &&
6136: !(p->flags & AHC_HANDLING_REQINITS) )
6137: {
6138: if ( aic_inb(p, ERROR) & PCIERRSTAT )
6139: {
6140: aic7xxx_pci_intr(p);
6141: }
6142: p->spurious_int = 0;
6143: }
6144: else if ( !(p->flags & AHC_HANDLING_REQINITS) )
6145: {
6146: p->spurious_int++;
6147: }
6148: #endif
6149: return;
6150: }
6151:
6152: p->spurious_int = 0;
6153:
6154: /*
6155: * Keep track of interrupts for /proc/scsi
6156: */
6157: p->isr_count++;
6158:
6159: #ifdef AIC7XXX_VERBOSE_DEBUGGING
6160: if ( (p->isr_count < 16) && (aic7xxx_verbose > 0xffff) &&
6161: (aic7xxx_panic_on_abort) && (p->flags & AHC_PAGESCBS) )
6162: aic7xxx_check_scbs(p, "Bogus settings at start of interrupt.");
6163: #endif
6164:
6165: /*
6166: * Handle all the interrupt sources - especially for SCSI
6167: * interrupts, we won't get a second chance at them.
6168: */
6169: if (intstat & CMDCMPLT)
6170: {
6171: struct aic7xxx_scb *scb = NULL;
6172: Scsi_Cmnd *cmd;
6173: unsigned char scb_index;
6174:
6175: #ifdef AIC7XXX_VERBOSE_DEBUGGING
6176: if(aic7xxx_verbose > 0xffff)
6177: printk(INFO_LEAD "Command Complete Int.\n", p->host_no, -1, -1, -1);
6178: #endif
6179:
6180: /*
6181: * Clear interrupt status before running the completion loop.
6182: * This eliminates a race condition whereby a command could
6183: * complete between the last check of qoutfifo and the
6184: * CLRCMDINT statement. This would result in us thinking the
6185: * qoutfifo was empty when it wasn't, and in actuality be a lost
6186: * completion interrupt. With multiple devices or tagged queueing
6187: * this could be very bad if we caught all but the last completion
6188: * and no more are imediately sent.
6189: */
6190: aic_outb(p, CLRCMDINT, CLRINT);
6191: /*
6192: * The sequencer will continue running when it
6193: * issues this interrupt. There may be >1 commands
6194: * finished, so loop until we've processed them all.
6195: */
6196:
6197: while (p->qoutfifo[p->qoutfifonext] != SCB_LIST_NULL)
6198: {
6199: scb_index = p->qoutfifo[p->qoutfifonext];
6200: p->qoutfifo[p->qoutfifonext++] = SCB_LIST_NULL;
6201: if ( scb_index >= p->scb_data->numscbs )
6202: scb = NULL;
6203: else
6204: scb = p->scb_data->scb_array[scb_index];
6205: if (scb == NULL)
6206: {
6207: printk(WARN_LEAD "CMDCMPLT with invalid SCB index %d\n", p->host_no,
6208: -1, -1, -1, scb_index);
6209: continue;
6210: }
6211: else if (!(scb->flags & SCB_ACTIVE) || (scb->cmd == NULL))
6212: {
6213: printk(WARN_LEAD "CMDCMPLT without command for SCB %d, SCB flags "
6214: "0x%x, cmd 0x%lx\n", p->host_no, -1, -1, -1, scb_index, scb->flags,
6215: (unsigned long) scb->cmd);
6216: continue;
6217: }
6218: else if (scb->flags & SCB_QUEUED_ABORT)
6219: {
6220: pause_sequencer(p);
6221: if ( ((aic_inb(p, LASTPHASE) & PHASE_MASK) != P_BUSFREE) &&
6222: (aic_inb(p, SCB_TAG) == scb->hscb->tag) )
6223: {
6224: unpause_sequencer(p, FALSE);
6225: continue;
6226: }
6227: aic7xxx_reset_device(p, scb->cmd->target, scb->cmd->channel,
6228: scb->cmd->lun, scb->hscb->tag);
6229: scb->flags &= ~(SCB_QUEUED_FOR_DONE | SCB_RESET | SCB_ABORT |
6230: SCB_QUEUED_ABORT);
6231: unpause_sequencer(p, FALSE);
6232: }
6233: else if (scb->flags & SCB_ABORT)
6234: {
6235: /*
6236: * We started to abort this, but it completed on us, let it
6237: * through as successful
6238: */
6239: scb->flags &= ~(SCB_ABORT|SCB_RESET);
6240: }
6241: switch (status_byte(scb->hscb->target_status))
6242: {
6243: case QUEUE_FULL:
6244: case BUSY:
6245: scb->hscb->target_status = 0;
6246: scb->cmd->result = 0;
6247: aic7xxx_error(scb->cmd) = DID_OK;
6248: break;
6249: default:
6250: cmd = scb->cmd;
6251: if (scb->hscb->residual_SG_segment_count != 0)
6252: {
6253: aic7xxx_calculate_residual(p, scb);
6254: }
6255: cmd->result |= (aic7xxx_error(cmd) << 16);
6256: if (scb->tag_action)
6257: p->dev_flags[TARGET_INDEX(cmd)] |=
6258: DEVICE_TAGGED_SUCCESS | DEVICE_SUCCESS | DEVICE_PRESENT;
6259: else
6260: p->dev_flags[TARGET_INDEX(cmd)] |=
6261: DEVICE_SUCCESS | DEVICE_PRESENT;
6262: aic7xxx_done(p, scb);
6263: break;
6264: }
6265: }
6266: }
6267:
6268: if (intstat & BRKADRINT)
6269: {
6270: int i;
6271: unsigned char errno = aic_inb(p, ERROR);
6272:
6273: printk(KERN_ERR "(scsi%d) BRKADRINT error(0x%x):\n", p->host_no, errno);
6274: for (i = 0; i < NUMBER(hard_error); i++)
6275: {
6276: if (errno & hard_error[i].errno)
6277: {
6278: printk(KERN_ERR " %s\n", hard_error[i].errmesg);
6279: }
6280: }
6281: printk(KERN_ERR "(scsi%d) SEQADDR=0x%x\n", p->host_no,
6282: (((aic_inb(p, SEQADDR1) << 8) & 0x100) | aic_inb(p, SEQADDR0)));
6283: if (aic7xxx_panic_on_abort)
6284: aic7xxx_panic_abort(p, NULL);
6285: #ifdef CONFIG_PCI
6286: if (errno & PCIERRSTAT)
6287: aic7xxx_pci_intr(p);
6288: #endif
6289: if (errno & (SQPARERR | ILLOPCODE | ILLSADDR))
6290: {
6291: sti();
6292: panic("aic7xxx: unrecoverable BRKADRINT.\n");
6293: }
6294: if (errno & ILLHADDR)
6295: {
6296: printk(KERN_ERR "(scsi%d) BUG! Driver accessed chip without first "
6297: "pausing controller!\n", p->host_no);
6298: }
6299: #ifdef AIC7XXX_VERBOSE_DEBUGGING
6300: if (errno & DPARERR)
6301: {
6302: if (aic_inb(p, DMAPARAMS) & DIRECTION)
6303: printk("(scsi%d) while DMAing SCB from host to card.\n", p->host_no);
6304: else
6305: printk("(scsi%d) while DMAing SCB from card to host.\n", p->host_no);
6306: }
6307: #endif
6308: aic_outb(p, CLRPARERR | CLRBRKADRINT, CLRINT);
6309: unpause_sequencer(p, FALSE);
6310: }
6311:
6312: if (intstat & SEQINT)
6313: {
6314: aic7xxx_handle_seqint(p, intstat);
6315: }
6316:
6317: if (intstat & SCSIINT)
6318: {
6319: aic7xxx_handle_scsiint(p, intstat);
6320: }
6321:
6322: #ifdef AIC7XXX_VERBOSE_DEBUGGING
6323: if ( (p->isr_count < 16) && (aic7xxx_verbose > 0xffff) &&
6324: (aic7xxx_panic_on_abort) && (p->flags & AHC_PAGESCBS) )
6325: aic7xxx_check_scbs(p, "Bogus settings at end of interrupt.");
6326: #endif
6327:
6328: }
6329:
6330: /*+F*************************************************************************
6331: * Function:
6332: * do_aic7xxx_isr
6333: *
6334: * Description:
6335: * This is a gross hack to solve a problem in linux kernels 2.1.85 and
6336: * above. Please, children, do not try this at home, and if you ever see
6337: * anything like it, please inform the Gross Hack Police immediately
6338: *-F*************************************************************************/
6339: static void
6340: do_aic7xxx_isr(int irq, void *dev_id, struct pt_regs *regs)
6341: {
6342: unsigned long cpu_flags;
6343: struct aic7xxx_host *p;
6344:
6345: p = (struct aic7xxx_host *)dev_id;
6346: if(!p)
6347: return;
6348: #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,1,95)
6349: spin_lock_irqsave(&io_request_lock, cpu_flags);
6350: if(test_and_set_bit(AHC_IN_ISR_BIT, &p->flags))
6351: {
6352: return;
6353: }
6354: do
6355: {
6356: aic7xxx_isr(irq, dev_id, regs);
6357: } while ( (aic_inb(p, INTSTAT) & INT_PEND) );
6358: aic7xxx_done_cmds_complete(p);
6359: aic7xxx_run_waiting_queues(p);
6360: clear_bit(AHC_IN_ISR_BIT, &p->flags);
6361: spin_unlock_irqrestore(&io_request_lock, cpu_flags);
6362: #else
6363: if(set_bit(AHC_IN_ISR_BIT, (int *)&p->flags))
6364: {
6365: return;
6366: }
6367: DRIVER_LOCK
6368: do
6369: {
6370: aic7xxx_isr(irq, dev_id, regs);
6371: } while ( (aic_inb(p, INTSTAT) & INT_PEND) );
6372: DRIVER_UNLOCK
6373: aic7xxx_done_cmds_complete(p);
6374: aic7xxx_run_waiting_queues(p);
6375: clear_bit(AHC_IN_ISR_BIT, (int *)&p->flags);
6376: #endif
6377: }
6378:
6379: /*+F*************************************************************************
6380: * Function:
6381: * aic7xxx_device_queue_depth
6382: *
6383: * Description:
6384: * Determines the queue depth for a given device. There are two ways
6385: * a queue depth can be obtained for a tagged queueing device. One
6386: * way is the default queue depth which is determined by whether
6387: * AIC7XXX_CMDS_PER_LUN is defined. If it is defined, then it is used
6388: * as the default queue depth. Otherwise, we use either 4 or 8 as the
6389: * default queue depth (dependent on the number of hardware SCBs).
6390: * The other way we determine queue depth is through the use of the
6391: * aic7xxx_tag_info array which is enabled by defining
6392: * AIC7XXX_TAGGED_QUEUEING_BY_DEVICE. This array can be initialized
6393: * with queue depths for individual devices. It also allows tagged
6394: * queueing to be [en|dis]abled for a specific adapter.
6395: *-F*************************************************************************/
6396: static void
6397: aic7xxx_device_queue_depth(struct aic7xxx_host *p, Scsi_Device *device)
6398: {
6399: int default_depth = 3;
6400: unsigned char tindex;
6401: unsigned short target_mask;
6402:
6403: tindex = device->id | (device->channel << 3);
6404: target_mask = (1 << tindex);
6405:
6406: device->queue_depth = default_depth;
6407: p->dev_mid_level_queue_depth[tindex] = 3;
6408: p->dev_temp_queue_depth[tindex] = 1;
6409: p->dev_max_queue_depth[tindex] = 1;
6410: p->tagenable &= ~target_mask;
6411:
6412: if (device->tagged_supported)
6413: {
6414: int tag_enabled = TRUE;
6415:
6416: #ifdef AIC7XXX_CMDS_PER_LUN
6417: default_depth = AIC7XXX_CMDS_PER_LUN;
6418: #else
6419: default_depth = 8; /* Not many SCBs to work with. */
6420: #endif
6421:
6422: if (!(p->discenable & target_mask))
6423: {
6424: if (aic7xxx_verbose & VERBOSE_NEGOTIATION2)
6425: printk(INFO_LEAD "Disconnection disabled, unable to "
6426: "enable tagged queueing.\n",
6427: p->host_no, device->channel, device->id, device->lun);
6428: }
6429: else
6430: {
6431: if (p->instance >= NUMBER(aic7xxx_tag_info))
6432: {
6433: static int print_warning = TRUE;
6434: if(print_warning)
6435: {
6436: printk(KERN_INFO "aic7xxx: WARNING, insufficient tag_info instances for"
6437: " installed controllers.\n");
6438: printk(KERN_INFO "aic7xxx: Please update the aic7xxx_tag_info array in"
6439: " the aic7xxx.c source file.\n");
6440: print_warning = FALSE;
6441: }
6442: device->queue_depth = default_depth;
6443: }
6444: else
6445: {
6446:
6447: if (aic7xxx_tag_info[p->instance].tag_commands[tindex] == 255)
6448: {
6449: tag_enabled = FALSE;
6450: device->queue_depth = 3; /* Tagged queueing is disabled. */
6451: }
6452: else if (aic7xxx_tag_info[p->instance].tag_commands[tindex] == 0)
6453: {
6454: device->queue_depth = default_depth;
6455: }
6456: else
6457: {
6458: device->queue_depth =
6459: aic7xxx_tag_info[p->instance].tag_commands[tindex];
6460: }
6461: }
6462: if ((device->tagged_queue == 0) && tag_enabled)
6463: {
6464: if (aic7xxx_verbose & VERBOSE_NEGOTIATION2)
6465: {
6466: printk(INFO_LEAD "Enabled tagged queuing, queue depth %d.\n",
6467: p->host_no, device->channel, device->id,
6468: device->lun, device->queue_depth);
6469: }
6470: p->dev_max_queue_depth[tindex] = device->queue_depth;
6471: p->dev_temp_queue_depth[tindex] = device->queue_depth;
6472: p->dev_mid_level_queue_depth[tindex] = device->queue_depth;
6473: p->tagenable |= target_mask;
6474: p->orderedtag |= target_mask;
6475: device->tagged_queue = 1;
6476: device->current_tag = SCB_LIST_NULL;
6477: }
6478: }
6479: }
6480: }
6481:
6482: /*+F*************************************************************************
6483: * Function:
6484: * aic7xxx_select_queue_depth
6485: *
6486: * Description:
6487: * Sets the queue depth for each SCSI device hanging off the input
6488: * host adapter. We use a queue depth of 2 for devices that do not
6489: * support tagged queueing. If AIC7XXX_CMDS_PER_LUN is defined, we
6490: * use that for tagged queueing devices; otherwise we use our own
6491: * algorithm for determining the queue depth based on the maximum
6492: * SCBs for the controller.
6493: *-F*************************************************************************/
6494: static void
6495: aic7xxx_select_queue_depth(struct Scsi_Host *host,
6496: Scsi_Device *scsi_devs)
6497: {
6498: Scsi_Device *device;
6499: struct aic7xxx_host *p = (struct aic7xxx_host *) host->hostdata;
6500: int scbnum;
6501:
6502: scbnum = 0;
6503: for (device = scsi_devs; device != NULL; device = device->next)
6504: {
6505: if (device->host == host)
6506: {
6507: aic7xxx_device_queue_depth(p, device);
6508: scbnum += device->queue_depth;
6509: }
6510: }
6511: while (scbnum > p->scb_data->numscbs)
6512: {
6513: /*
6514: * Pre-allocate the needed SCBs to get around the possibility of having
6515: * to allocate some when memory is more or less exhausted and we need
6516: * the SCB in order to perform a swap operation (possible deadlock)
6517: */
6518: if ( aic7xxx_allocate_scb(p) == 0 )
6519: return;
6520: }
6521: }
6522:
6523: /*+F*************************************************************************
6524: * Function:
6525: * aic7xxx_probe
6526: *
6527: * Description:
6528: * Probing for EISA boards: it looks like the first two bytes
6529: * are a manufacturer code - three characters, five bits each:
6530: *
6531: * BYTE 0 BYTE 1 BYTE 2 BYTE 3
6532: * ?1111122 22233333 PPPPPPPP RRRRRRRR
6533: *
6534: * The characters are baselined off ASCII '@', so add that value
6535: * to each to get the real ASCII code for it. The next two bytes
6536: * appear to be a product and revision number, probably vendor-
6537: * specific. This is what is being searched for at each port,
6538: * and what should probably correspond to the ID= field in the
6539: * ECU's .cfg file for the card - if your card is not detected,
6540: * make sure your signature is listed in the array.
6541: *
6542: * The fourth byte's lowest bit seems to be an enabled/disabled
6543: * flag (rest of the bits are reserved?).
6544: *
6545: * NOTE: This function is only needed on Intel and Alpha platforms,
6546: * the other platforms we support don't have EISA/VLB busses. So,
6547: * we #ifdef this entire function to avoid compiler warnings about
6548: * an unused function.
6549: *-F*************************************************************************/
6550: #if defined(__i386__) || defined(__alpha__)
6551: static int
6552: aic7xxx_probe(int slot, int base, ahc_flag_type *flags)
6553: {
6554: int i;
6555: unsigned char buf[4];
6556:
6557: static struct {
6558: int n;
6559: unsigned char signature[sizeof(buf)];
6560: ahc_chip type;
6561: int bios_disabled;
6562: } AIC7xxx[] = {
6563: { 4, { 0x04, 0x90, 0x77, 0x70 },
6564: AHC_AIC7770|AHC_EISA, FALSE }, /* mb 7770 */
6565: { 4, { 0x04, 0x90, 0x77, 0x71 },
6566: AHC_AIC7770|AHC_EISA, FALSE }, /* host adapter 274x */
6567: { 4, { 0x04, 0x90, 0x77, 0x56 },
6568: AHC_AIC7770|AHC_VL, FALSE }, /* 284x BIOS enabled */
6569: { 4, { 0x04, 0x90, 0x77, 0x57 },
6570: AHC_AIC7770|AHC_VL, TRUE } /* 284x BIOS disabled */
6571: };
6572:
6573: /*
6574: * The VL-bus cards need to be primed by
6575: * writing before a signature check.
6576: */
6577: for (i = 0; i < sizeof(buf); i++)
6578: {
6579: outb(0x80 + i, base);
6580: buf[i] = inb(base + i);
6581: }
6582:
6583: for (i = 0; i < NUMBER(AIC7xxx); i++)
6584: {
6585: /*
6586: * Signature match on enabled card?
6587: */
6588: if (!memcmp(buf, AIC7xxx[i].signature, AIC7xxx[i].n))
6589: {
6590: if (inb(base + 4) & 1)
6591: {
6592: if (AIC7xxx[i].bios_disabled)
6593: {
6594: *flags |= AHC_USEDEFAULTS;
6595: }
6596: else
6597: {
6598: *flags |= AHC_BIOS_ENABLED;
6599: }
6600: return (i);
6601: }
6602:
6603: printk("aic7xxx: <Adaptec 7770 SCSI Host Adapter> "
6604: "disabled at slot %d, ignored.\n", slot);
6605: }
6606: }
6607:
6608: return (-1);
6609: }
6610: #endif /* (__i386__) || (__alpha__) */
6611:
6612:
6613: /*+F*************************************************************************
6614: * Function:
6615: * read_2840_seeprom
6616: *
6617: * Description:
6618: * Reads the 2840 serial EEPROM and returns 1 if successful and 0 if
6619: * not successful.
6620: *
6621: * See read_seeprom (for the 2940) for the instruction set of the 93C46
6622: * chip.
6623: *
6624: * The 2840 interface to the 93C46 serial EEPROM is through the
6625: * STATUS_2840 and SEECTL_2840 registers. The CS_2840, CK_2840, and
6626: * DO_2840 bits of the SEECTL_2840 register are connected to the chip
6627: * select, clock, and data out lines respectively of the serial EEPROM.
6628: * The DI_2840 bit of the STATUS_2840 is connected to the data in line
6629: * of the serial EEPROM. The EEPROM_TF bit of STATUS_2840 register is
6630: * useful in that it gives us an 800 nsec timer. After a read from the
6631: * SEECTL_2840 register the timing flag is cleared and goes high 800 nsec
6632: * later.
6633: *-F*************************************************************************/
6634: static int
6635: read_284x_seeprom(struct aic7xxx_host *p, struct seeprom_config *sc)
6636: {
6637: int i = 0, k = 0;
6638: unsigned char temp;
6639: unsigned short checksum = 0;
6640: unsigned short *seeprom = (unsigned short *) sc;
6641: struct seeprom_cmd {
6642: unsigned char len;
6643: unsigned char bits[3];
6644: };
6645: struct seeprom_cmd seeprom_read = {3, {1, 1, 0}};
6646:
6647: #define CLOCK_PULSE(p) \
6648: while ((aic_inb(p, STATUS_2840) & EEPROM_TF) == 0) \
6649: { \
6650: ; /* Do nothing */ \
6651: } \
6652: (void) aic_inb(p, SEECTL_2840);
6653:
6654: /*
6655: * Read the first 32 registers of the seeprom. For the 2840,
6656: * the 93C46 SEEPROM is a 1024-bit device with 64 16-bit registers
6657: * but only the first 32 are used by Adaptec BIOS. The loop
6658: * will range from 0 to 31.
6659: */
6660: for (k = 0; k < (sizeof(*sc) / 2); k++)
6661: {
6662: /*
6663: * Send chip select for one clock cycle.
6664: */
6665: aic_outb(p, CK_2840 | CS_2840, SEECTL_2840);
6666: CLOCK_PULSE(p);
6667:
6668: /*
6669: * Now we're ready to send the read command followed by the
6670: * address of the 16-bit register we want to read.
6671: */
6672: for (i = 0; i < seeprom_read.len; i++)
6673: {
6674: temp = CS_2840 | seeprom_read.bits[i];
6675: aic_outb(p, temp, SEECTL_2840);
6676: CLOCK_PULSE(p);
6677: temp = temp ^ CK_2840;
6678: aic_outb(p, temp, SEECTL_2840);
6679: CLOCK_PULSE(p);
6680: }
6681: /*
6682: * Send the 6 bit address (MSB first, LSB last).
6683: */
6684: for (i = 5; i >= 0; i--)
6685: {
6686: temp = k;
6687: temp = (temp >> i) & 1; /* Mask out all but lower bit. */
6688: temp = CS_2840 | temp;
6689: aic_outb(p, temp, SEECTL_2840);
6690: CLOCK_PULSE(p);
6691: temp = temp ^ CK_2840;
6692: aic_outb(p, temp, SEECTL_2840);
6693: CLOCK_PULSE(p);
6694: }
6695:
6696: /*
6697: * Now read the 16 bit register. An initial 0 precedes the
6698: * register contents which begins with bit 15 (MSB) and ends
6699: * with bit 0 (LSB). The initial 0 will be shifted off the
6700: * top of our word as we let the loop run from 0 to 16.
6701: */
6702: for (i = 0; i <= 16; i++)
6703: {
6704: temp = CS_2840;
6705: aic_outb(p, temp, SEECTL_2840);
6706: CLOCK_PULSE(p);
6707: temp = temp ^ CK_2840;
6708: seeprom[k] = (seeprom[k] << 1) | (aic_inb(p, STATUS_2840) & DI_2840);
6709: aic_outb(p, temp, SEECTL_2840);
6710: CLOCK_PULSE(p);
6711: }
6712: /*
6713: * The serial EEPROM has a checksum in the last word. Keep a
6714: * running checksum for all words read except for the last
6715: * word. We'll verify the checksum after all words have been
6716: * read.
6717: */
6718: if (k < (sizeof(*sc) / 2) - 1)
6719: {
6720: checksum = checksum + seeprom[k];
6721: }
6722:
6723: /*
6724: * Reset the chip select for the next command cycle.
6725: */
6726: aic_outb(p, 0, SEECTL_2840);
6727: CLOCK_PULSE(p);
6728: aic_outb(p, CK_2840, SEECTL_2840);
6729: CLOCK_PULSE(p);
6730: aic_outb(p, 0, SEECTL_2840);
6731: CLOCK_PULSE(p);
6732: }
6733:
6734: #if 0
6735: printk("Computed checksum 0x%x, checksum read 0x%x\n", checksum, sc->checksum);
6736: printk("Serial EEPROM:");
6737: for (k = 0; k < (sizeof(*sc) / 2); k++)
6738: {
6739: if (((k % 8) == 0) && (k != 0))
6740: {
6741: printk("\n ");
6742: }
6743: printk(" 0x%x", seeprom[k]);
6744: }
6745: printk("\n");
6746: #endif
6747:
6748: if (checksum != sc->checksum)
6749: {
6750: printk("aic7xxx: SEEPROM checksum error, ignoring SEEPROM settings.\n");
6751: return (0);
6752: }
6753:
6754: return (1);
6755: #undef CLOCK_PULSE
6756: }
6757:
6758: /*+F*************************************************************************
6759: * Function:
6760: * acquire_seeprom
6761: *
6762: * Description:
6763: * Acquires access to the memory port on PCI controllers.
6764: *-F*************************************************************************/
6765: static int
6766: acquire_seeprom(struct aic7xxx_host *p)
6767: {
6768: int wait;
6769:
6770: /*
6771: * Request access of the memory port. When access is
6772: * granted, SEERDY will go high. We use a 1 second
6773: * timeout which should be near 1 second more than
6774: * is needed. Reason: after the 7870 chip reset, there
6775: * should be no contention.
6776: */
6777: aic_outb(p, SEEMS, SEECTL);
6778: wait = 1000; /* 1000 msec = 1 second */
6779: while ((wait > 0) && ((aic_inb(p, SEECTL) & SEERDY) == 0))
6780: {
6781: wait--;
6782: mdelay(1); /* 1 msec */
6783: }
6784: if ((aic_inb(p, SEECTL) & SEERDY) == 0)
6785: {
6786: aic_outb(p, 0, SEECTL);
6787: return (0);
6788: }
6789: return (1);
6790: }
6791:
6792: /*+F*************************************************************************
6793: * Function:
6794: * release_seeprom
6795: *
6796: * Description:
6797: * Releases access to the memory port on PCI controllers.
6798: *-F*************************************************************************/
6799: static void
6800: release_seeprom(struct aic7xxx_host *p)
6801: {
6802: aic_outb(p, 0, SEECTL);
6803: }
6804:
6805: /*+F*************************************************************************
6806: * Function:
6807: * read_seeprom
6808: *
6809: * Description:
6810: * Reads the serial EEPROM and returns 1 if successful and 0 if
6811: * not successful.
6812: *
6813: * The instruction set of the 93C46/56/66 chips is as follows:
6814: *
6815: * Start OP
6816: * Function Bit Code Address Data Description
6817: * -------------------------------------------------------------------
6818: * READ 1 10 A5 - A0 Reads data stored in memory,
6819: * starting at specified address
6820: * EWEN 1 00 11XXXX Write enable must precede
6821: * all programming modes
6822: * ERASE 1 11 A5 - A0 Erase register A5A4A3A2A1A0
6823: * WRITE 1 01 A5 - A0 D15 - D0 Writes register
6824: * ERAL 1 00 10XXXX Erase all registers
6825: * WRAL 1 00 01XXXX D15 - D0 Writes to all registers
6826: * EWDS 1 00 00XXXX Disables all programming
6827: * instructions
6828: * *Note: A value of X for address is a don't care condition.
6829: * *Note: The 93C56 and 93C66 have 8 address bits.
6830: *
6831: *
6832: * The 93C46 has a four wire interface: clock, chip select, data in, and
6833: * data out. In order to perform one of the above functions, you need
6834: * to enable the chip select for a clock period (typically a minimum of
6835: * 1 usec, with the clock high and low a minimum of 750 and 250 nsec
6836: * respectively. While the chip select remains high, you can clock in
6837: * the instructions (above) starting with the start bit, followed by the
6838: * OP code, Address, and Data (if needed). For the READ instruction, the
6839: * requested 16-bit register contents is read from the data out line but
6840: * is preceded by an initial zero (leading 0, followed by 16-bits, MSB
6841: * first). The clock cycling from low to high initiates the next data
6842: * bit to be sent from the chip.
6843: *
6844: * The 78xx interface to the 93C46 serial EEPROM is through the SEECTL
6845: * register. After successful arbitration for the memory port, the
6846: * SEECS bit of the SEECTL register is connected to the chip select.
6847: * The SEECK, SEEDO, and SEEDI are connected to the clock, data out,
6848: * and data in lines respectively. The SEERDY bit of SEECTL is useful
6849: * in that it gives us an 800 nsec timer. After a write to the SEECTL
6850: * register, the SEERDY goes high 800 nsec later. The one exception
6851: * to this is when we first request access to the memory port. The
6852: * SEERDY goes high to signify that access has been granted and, for
6853: * this case, has no implied timing.
6854: *-F*************************************************************************/
6855: static int
6856: read_seeprom(struct aic7xxx_host *p, int offset,
6857: unsigned short *scarray, unsigned int len, seeprom_chip_type chip)
6858: {
6859: int i = 0, k;
6860: unsigned char temp;
6861: unsigned short checksum = 0;
6862: struct seeprom_cmd {
6863: unsigned char len;
6864: unsigned char bits[3];
6865: };
6866: struct seeprom_cmd seeprom_read = {3, {1, 1, 0}};
6867:
6868: #define CLOCK_PULSE(p) \
6869: while ((aic_inb(p, SEECTL) & SEERDY) == 0) \
6870: { \
6871: ; /* Do nothing */ \
6872: }
6873:
6874: /*
6875: * Request access of the memory port.
6876: */
6877: if (acquire_seeprom(p) == 0)
6878: {
6879: return (0);
6880: }
6881:
6882: /*
6883: * Read 'len' registers of the seeprom. For the 7870, the 93C46
6884: * SEEPROM is a 1024-bit device with 64 16-bit registers but only
6885: * the first 32 are used by Adaptec BIOS. Some adapters use the
6886: * 93C56 SEEPROM which is a 2048-bit device. The loop will range
6887: * from 0 to 'len' - 1.
6888: */
6889: for (k = 0; k < len; k++)
6890: {
6891: /*
6892: * Send chip select for one clock cycle.
6893: */
6894: aic_outb(p, SEEMS | SEECK | SEECS, SEECTL);
6895: CLOCK_PULSE(p);
6896:
6897: /*
6898: * Now we're ready to send the read command followed by the
6899: * address of the 16-bit register we want to read.
6900: */
6901: for (i = 0; i < seeprom_read.len; i++)
6902: {
6903: temp = SEEMS | SEECS | (seeprom_read.bits[i] << 1);
6904: aic_outb(p, temp, SEECTL);
6905: CLOCK_PULSE(p);
6906: temp = temp ^ SEECK;
6907: aic_outb(p, temp, SEECTL);
6908: CLOCK_PULSE(p);
6909: }
6910: /*
6911: * Send the 6 or 8 bit address (MSB first, LSB last).
6912: */
6913: for (i = ((int) chip - 1); i >= 0; i--)
6914: {
6915: temp = k + offset;
6916: temp = (temp >> i) & 1; /* Mask out all but lower bit. */
6917: temp = SEEMS | SEECS | (temp << 1);
6918: aic_outb(p, temp, SEECTL);
6919: CLOCK_PULSE(p);
6920: temp = temp ^ SEECK;
6921: aic_outb(p, temp, SEECTL);
6922: CLOCK_PULSE(p);
6923: }
6924:
6925: /*
6926: * Now read the 16 bit register. An initial 0 precedes the
6927: * register contents which begins with bit 15 (MSB) and ends
6928: * with bit 0 (LSB). The initial 0 will be shifted off the
6929: * top of our word as we let the loop run from 0 to 16.
6930: */
6931: for (i = 0; i <= 16; i++)
6932: {
6933: temp = SEEMS | SEECS;
6934: aic_outb(p, temp, SEECTL);
6935: CLOCK_PULSE(p);
6936: temp = temp ^ SEECK;
6937: scarray[k] = (scarray[k] << 1) | (aic_inb(p, SEECTL) & SEEDI);
6938: aic_outb(p, temp, SEECTL);
6939: CLOCK_PULSE(p);
6940: }
6941:
6942: /*
6943: * The serial EEPROM should have a checksum in the last word.
6944: * Keep a running checksum for all words read except for the
6945: * last word. We'll verify the checksum after all words have
6946: * been read.
6947: */
6948: if (k < (len - 1))
6949: {
6950: checksum = checksum + scarray[k];
6951: }
6952:
6953: /*
6954: * Reset the chip select for the next command cycle.
6955: */
6956: aic_outb(p, SEEMS, SEECTL);
6957: CLOCK_PULSE(p);
6958: aic_outb(p, SEEMS | SEECK, SEECTL);
6959: CLOCK_PULSE(p);
6960: aic_outb(p, SEEMS, SEECTL);
6961: CLOCK_PULSE(p);
6962: }
6963:
6964: /*
6965: * Release access to the memory port and the serial EEPROM.
6966: */
6967: release_seeprom(p);
6968:
6969: #if 0
6970: printk("Computed checksum 0x%x, checksum read 0x%x\n",
6971: checksum, scarray[len - 1]);
6972: printk("Serial EEPROM:");
6973: for (k = 0; k < len; k++)
6974: {
6975: if (((k % 8) == 0) && (k != 0))
6976: {
6977: printk("\n ");
6978: }
6979: printk(" 0x%x", scarray[k]);
6980: }
6981: printk("\n");
6982: #endif
6983: if (checksum != scarray[len - 1])
6984: {
6985: return (0);
6986: }
6987:
6988: return (1);
6989: #undef CLOCK_PULSE
6990: }
6991:
6992: /*+F*************************************************************************
6993: * Function:
6994: * write_brdctl
6995: *
6996: * Description:
6997: * Writes a value to the BRDCTL register.
6998: *-F*************************************************************************/
6999: static void
7000: write_brdctl(struct aic7xxx_host *p, unsigned char value)
7001: {
7002: unsigned char brdctl;
7003:
7004: if ((p->chip & AHC_CHIPID_MASK) == AHC_AIC7895)
7005: {
7006: brdctl = BRDSTB;
7007: if (p->flags & AHC_CHNLB)
7008: brdctl |= BRDCS;
7009: }
7010: else if (p->features & AHC_ULTRA2)
7011: brdctl = 0;
7012: else
7013: brdctl = BRDSTB | BRDCS;
7014: aic_outb(p, brdctl, BRDCTL);
7015: udelay(1);
7016: brdctl |= value;
7017: aic_outb(p, brdctl, BRDCTL);
7018: udelay(1);
7019: if (p->features & AHC_ULTRA2)
7020: brdctl |= BRDSTB_ULTRA2;
7021: else
7022: brdctl &= ~BRDSTB;
7023: aic_outb(p, brdctl, BRDCTL);
7024: udelay(1);
7025: if (p->features & AHC_ULTRA2)
7026: brdctl = 0;
7027: else
7028: brdctl &= ~BRDCS;
7029: aic_outb(p, brdctl, BRDCTL);
7030: udelay(1);
7031: }
7032:
7033: /*+F*************************************************************************
7034: * Function:
7035: * read_brdctl
7036: *
7037: * Description:
7038: * Reads the BRDCTL register.
7039: *-F*************************************************************************/
7040: static unsigned char
7041: read_brdctl(struct aic7xxx_host *p)
7042: {
7043: unsigned char brdctl, value;
7044:
7045: if ((p->chip & AHC_CHIPID_MASK) == AHC_AIC7895)
7046: {
7047: brdctl = BRDRW;
7048: if (p->flags & AHC_CHNLB)
7049: brdctl |= BRDCS;
7050: }
7051: else if (p->features & AHC_ULTRA2)
7052: brdctl = BRDRW_ULTRA2;
7053: else
7054: brdctl = BRDRW | BRDCS;
7055: aic_outb(p, brdctl, BRDCTL);
7056: udelay(1);
7057: value = aic_inb(p, BRDCTL);
7058: aic_outb(p, 0, BRDCTL);
7059: udelay(1);
7060: return (value);
7061: }
7062:
7063: /*+F*************************************************************************
7064: * Function:
7065: * aic785x_cable_detect
7066: *
7067: * Description:
7068: * Detect the cables that are present on aic785x class controller chips
7069: *-F*************************************************************************/
7070: static void
7071: aic785x_cable_detect(struct aic7xxx_host *p, int *int_50,
7072: int *ext_present, int *eeprom)
7073: {
7074: unsigned char brdctl;
7075:
7076: aic_outb(p, BRDRW | BRDCS, BRDCTL);
7077: udelay(1);
7078: aic_outb(p, 0, BRDCTL);
7079: udelay(1);
7080: brdctl = aic_inb(p, BRDCTL);
7081: udelay(1);
7082: *int_50 = !(brdctl & BRDDAT5);
7083: *ext_present = !(brdctl & BRDDAT6);
7084: *eeprom = (aic_inb(p, SPIOCAP) & EEPROM);
7085: }
7086:
7087: /*+F*************************************************************************
7088: * Function:
7089: * aic787x_cable_detect
7090: *
7091: * Description:
7092: * Detect the cables that are present on aic787x class controller chips
7093: *
7094: * NOTE: This functions assumes the SEEPROM will have already been aquired
7095: * prior to invocation of this function.
7096: *-F*************************************************************************/
7097: static void
7098: aic787x_cable_detect(struct aic7xxx_host *p, int *int_50, int *int_68,
7099: int *ext_present, int *eeprom)
7100: {
7101: unsigned char brdctl;
7102:
7103: /*
7104: * First read the status of our cables. Set the rom bank to
7105: * 0 since the bank setting serves as a multiplexor for the
7106: * cable detection logic. BRDDAT5 controls the bank switch.
7107: */
7108: write_brdctl(p, 0);
7109:
7110: /*
7111: * Now we read the state of the two internal connectors. BRDDAT6
7112: * is internal 50, BRDDAT7 is internal 68. For each, the cable is
7113: * present if the bit is 0
7114: */
7115: brdctl = read_brdctl(p);
7116: *int_50 = !(brdctl & BRDDAT6);
7117: *int_68 = !(brdctl & BRDDAT7);
7118:
7119: /*
7120: * Set the bank bit in brdctl and then read the external cable state
7121: * and the EEPROM status
7122: */
7123: write_brdctl(p, BRDDAT5);
7124: brdctl = read_brdctl(p);
7125:
7126: *ext_present = !(brdctl & BRDDAT6);
7127: *eeprom = !(brdctl & BRDDAT7);
7128:
7129: /*
7130: * We're done, the calling function will release the SEEPROM for us
7131: */
7132: }
7133:
7134: /*+F*************************************************************************
7135: * Function:
7136: * aic787x_ultra2_term_detect
7137: *
7138: * Description:
7139: * Detect the termination settings present on ultra2 class controllers
7140: *
7141: * NOTE: This functions assumes the SEEPROM will have already been aquired
7142: * prior to invocation of this function.
7143: *-F*************************************************************************/
7144: static void
7145: aic7xxx_ultra2_term_detect(struct aic7xxx_host *p, int *enableSE_low,
7146: int *enableSE_high, int *enableLVD_low,
7147: int *enableLVD_high, int *eprom_present)
7148: {
7149: unsigned char brdctl;
7150:
7151: brdctl = read_brdctl(p);
7152:
7153: *eprom_present = (brdctl & BRDDAT7);
7154: *enableSE_high = (brdctl & BRDDAT6);
7155: *enableSE_low = (brdctl & BRDDAT5);
7156: *enableLVD_high = (brdctl & BRDDAT4);
7157: *enableLVD_low = (brdctl & BRDDAT3);
7158: }
7159:
7160: /*+F*************************************************************************
7161: * Function:
7162: * configure_termination
7163: *
7164: * Description:
7165: * Configures the termination settings on PCI adapters that have
7166: * SEEPROMs available.
7167: *-F*************************************************************************/
7168: static void
7169: configure_termination(struct aic7xxx_host *p)
7170: {
7171: int internal50_present = 0;
7172: int internal68_present = 0;
7173: int external_present = 0;
7174: int eprom_present = 0;
7175: int enableSE_low = 0;
7176: int enableSE_high = 0;
7177: int enableLVD_low = 0;
7178: int enableLVD_high = 0;
7179: unsigned char brddat = 0;
7180: unsigned char max_target = 0;
7181: unsigned char sxfrctl1 = aic_inb(p, SXFRCTL1);
7182:
7183: if (acquire_seeprom(p))
7184: {
7185: if (p->features & (AHC_WIDE|AHC_TWIN))
7186: max_target = 16;
7187: else
7188: max_target = 8;
7189: aic_outb(p, SEEMS | SEECS, SEECTL);
7190: sxfrctl1 &= ~STPWEN;
7191: if ( (p->adapter_control & CFAUTOTERM) ||
7192: (p->features & AHC_ULTRA2) )
7193: {
7194: if ( (p->adapter_control & CFAUTOTERM) && !(p->features & AHC_ULTRA2) )
7195: {
7196: printk(KERN_INFO "(scsi%d) Warning - detected auto-termination\n",
7197: p->host_no);
7198: printk(KERN_INFO "(scsi%d) Please verify driver detected settings are "
7199: "correct.\n", p->host_no);
7200: printk(KERN_INFO "(scsi%d) If not, then please properly set the device "
7201: "termination\n", p->host_no);
7202: printk(KERN_INFO "(scsi%d) in the Adaptec SCSI BIOS by hitting CTRL-A "
7203: "when prompted\n", p->host_no);
7204: printk(KERN_INFO "(scsi%d) during machine bootup.\n", p->host_no);
7205: }
7206: /* Configure auto termination. */
7207:
7208: if (p->features & AHC_ULTRA2)
7209: {
7210: if (aic7xxx_override_term == -1)
7211: aic7xxx_ultra2_term_detect(p, &enableSE_low, &enableSE_high,
7212: &enableLVD_low, &enableLVD_high,
7213: &eprom_present);
7214: if (!(p->adapter_control & CFSEAUTOTERM))
7215: {
7216: enableSE_low = (p->adapter_control & CFSTERM);
7217: enableSE_high = (p->adapter_control & CFWSTERM);
7218: }
7219: if (!(p->adapter_control & CFAUTOTERM))
7220: {
7221: enableLVD_low = enableLVD_high = (p->adapter_control & CFLVDSTERM);
7222: }
7223: internal50_present = 0;
7224: internal68_present = 1;
7225: external_present = 1;
7226: }
7227: else if ( (p->chip & AHC_CHIPID_MASK) >= AHC_AIC7870 )
7228: {
7229: aic787x_cable_detect(p, &internal50_present, &internal68_present,
7230: &external_present, &eprom_present);
7231: }
7232: else
7233: {
7234: aic785x_cable_detect(p, &internal50_present, &external_present,
7235: &eprom_present);
7236: }
7237:
7238: if (max_target <= 8)
7239: internal68_present = 0;
7240:
7241: if ( !(p->features & AHC_ULTRA2) )
7242: {
7243: if (max_target > 8)
7244: {
7245: printk(KERN_INFO "(scsi%d) Cables present (Int-50 %s, Int-68 %s, "
7246: "Ext-68 %s)\n", p->host_no,
7247: internal50_present ? "YES" : "NO",
7248: internal68_present ? "YES" : "NO",
7249: external_present ? "YES" : "NO");
7250: }
7251: else
7252: {
7253: printk(KERN_INFO "(scsi%d) Cables present (Int-50 %s, Ext-50 %s)\n",
7254: p->host_no,
7255: internal50_present ? "YES" : "NO",
7256: external_present ? "YES" : "NO");
7257: }
7258: }
7259: if (aic7xxx_verbose & VERBOSE_PROBE2)
7260: printk(KERN_INFO "(scsi%d) EEPROM %s present.\n", p->host_no,
7261: eprom_present ? "is" : "is not");
7262:
7263: /*
7264: * Now set the termination based on what we found. BRDDAT6
7265: * controls wide termination enable.
7266: * Flash Enable = BRDDAT7
7267: * SE High Term Enable = BRDDAT6
7268: * SE Low Term Enable = BRDDAT5 (7890)
7269: * LVD High Term Enable = BRDDAT4 (7890)
7270: */
7271: if ( !(p->features & AHC_ULTRA2) &&
7272: (internal50_present && internal68_present && external_present) )
7273: {
7274: printk(KERN_INFO "(scsi%d) Illegal cable configuration!! Only two\n",
7275: p->host_no);
7276: printk(KERN_INFO "(scsi%d) connectors on the SCSI controller may be "
7277: "in use at a time!\n", p->host_no);
7278: /*
7279: * Force termination (low and high byte) on. This is safer than
7280: * leaving it completely off, especially since this message comes
7281: * most often from motherboard controllers that don't even have 3
7282: * connectors, but instead are failing the cable detection.
7283: */
7284: internal50_present = external_present = 0;
7285: enableSE_high = enableSE_low = 1;
7286: }
7287:
7288: if ((max_target > 8) &&
7289: ((external_present == 0) || (internal68_present == 0) ||
7290: (enableSE_high != 0)))
7291: {
7292: brddat |= BRDDAT6;
7293: p->flags |= AHC_TERM_ENB_SE_HIGH;
7294: if (aic7xxx_verbose & VERBOSE_PROBE2)
7295: printk(KERN_INFO "(scsi%d) SE High byte termination Enabled\n",
7296: p->host_no);
7297: }
7298:
7299: if ( (((internal50_present ? 1 : 0) +
7300: (internal68_present ? 1 : 0) +
7301: (external_present ? 1 : 0)) <= 1) ||
7302: (enableSE_low != 0) )
7303: {
7304: if (p->features & AHC_ULTRA2)
7305: brddat |= BRDDAT5;
7306: else
7307: sxfrctl1 |= STPWEN;
7308: p->flags |= AHC_TERM_ENB_SE_LOW;
7309: if (aic7xxx_verbose & VERBOSE_PROBE2)
7310: printk(KERN_INFO "(scsi%d) SE Low byte termination Enabled\n",
7311: p->host_no);
7312: }
7313:
7314: if (enableLVD_low != 0)
7315: {
7316: sxfrctl1 |= STPWEN;
7317: p->flags |= AHC_TERM_ENB_LVD;
7318: if (aic7xxx_verbose & VERBOSE_PROBE2)
7319: printk(KERN_INFO "(scsi%d) LVD Low byte termination Enabled\n",
7320: p->host_no);
7321: }
7322:
7323: if (enableLVD_high != 0)
7324: {
7325: brddat |= BRDDAT4;
7326: if (aic7xxx_verbose & VERBOSE_PROBE2)
7327: printk(KERN_INFO "(scsi%d) LVD High byte termination Enabled\n",
7328: p->host_no);
7329: }
7330: }
7331: else
7332: {
7333: if (p->adapter_control & CFSTERM)
7334: {
7335: if (p->features & AHC_ULTRA2)
7336: brddat |= BRDDAT5;
7337: else
7338: sxfrctl1 |= STPWEN;
7339: if (aic7xxx_verbose & VERBOSE_PROBE2)
7340: printk(KERN_INFO "(scsi%d) SE Low byte termination Enabled\n",
7341: p->host_no);
7342: }
7343:
7344: if (p->adapter_control & CFWSTERM)
7345: {
7346: brddat |= BRDDAT6;
7347: if (aic7xxx_verbose & VERBOSE_PROBE2)
7348: printk(KERN_INFO "(scsi%d) SE High byte termination Enabled\n",
7349: p->host_no);
7350: }
7351: }
7352: write_brdctl(p, brddat);
7353: release_seeprom(p);
7354: aic_outb(p, sxfrctl1, SXFRCTL1);
7355: }
7356: }
7357:
7358: /*+F*************************************************************************
7359: * Function:
7360: * detect_maxscb
7361: *
7362: * Description:
7363: * Detects the maximum number of SCBs for the controller and returns
7364: * the count and a mask in p (p->maxscbs, p->qcntmask).
7365: *-F*************************************************************************/
7366: static void
7367: detect_maxscb(struct aic7xxx_host *p)
7368: {
7369: int i;
7370:
7371: /*
7372: * It's possible that we've already done this for multichannel
7373: * adapters.
7374: */
7375: if (p->scb_data->maxhscbs == 0)
7376: {
7377: /*
7378: * We haven't initialized the SCB settings yet. Walk the SCBs to
7379: * determince how many there are.
7380: */
7381: aic_outb(p, 0, FREE_SCBH);
7382:
7383: for (i = 0; i < AIC7XXX_MAXSCB; i++)
7384: {
7385: aic_outb(p, i, SCBPTR);
7386: aic_outb(p, i, SCB_CONTROL);
7387: if (aic_inb(p, SCB_CONTROL) != i)
7388: break;
7389: aic_outb(p, 0, SCBPTR);
7390: if (aic_inb(p, SCB_CONTROL) != 0)
7391: break;
7392:
7393: aic_outb(p, i, SCBPTR);
7394: aic_outb(p, 0, SCB_CONTROL); /* Clear the control byte. */
7395: aic_outb(p, i + 1, SCB_NEXT); /* Set the next pointer. */
7396: aic_outb(p, i - 1, SCB_PREV); /* Set the prev pointer. */
7397: aic_outb(p, SCB_LIST_NULL, SCB_TAG); /* Make the tag invalid. */
7398: aic_outb(p, SCB_LIST_NULL, SCB_BUSYTARGETS); /* no busy untagged */
7399: aic_outb(p, SCB_LIST_NULL, SCB_BUSYTARGETS+1);/* targets active yet */
7400: aic_outb(p, SCB_LIST_NULL, SCB_BUSYTARGETS+2);
7401: aic_outb(p, SCB_LIST_NULL, SCB_BUSYTARGETS+3);
7402: }
7403:
7404: /* Make sure the last SCB terminates the free list. */
7405: aic_outb(p, i - 1, SCBPTR);
7406: aic_outb(p, SCB_LIST_NULL, SCB_NEXT);
7407:
7408: /* Ensure we clear the first (0) SCBs control byte. */
7409: aic_outb(p, 0, SCBPTR);
7410: aic_outb(p, 0, SCB_CONTROL);
7411:
7412: p->scb_data->maxhscbs = i;
7413: /*
7414: * Use direct indexing instead for speed
7415: */
7416: if ( i == AIC7XXX_MAXSCB )
7417: p->flags &= ~AHC_PAGESCBS;
7418: }
7419:
7420: }
7421:
7422: /*+F*************************************************************************
7423: * Function:
7424: * aic7xxx_register
7425: *
7426: * Description:
7427: * Register a Adaptec aic7xxx chip SCSI controller with the kernel.
7428: *-F*************************************************************************/
7429: static int
7430: aic7xxx_register(Scsi_Host_Template *template, struct aic7xxx_host *p,
7431: int reset_delay)
7432: {
7433: int i, result;
7434: int max_targets;
7435: int found = 1;
7436: unsigned char term, scsi_conf;
7437: struct Scsi_Host *host;
7438:
7439: /*
7440: * Lock out other contenders for our i/o space.
7441: */
7442: request_region(p->base, MAXREG - MINREG, "aic7xxx");
7443:
7444:
7445: host = p->host;
7446:
7447: p->scb_data->maxscbs = AIC7XXX_MAXSCB;
7448: host->can_queue = AIC7XXX_MAXSCB;
7449: host->cmd_per_lun = 3;
7450: host->sg_tablesize = AIC7XXX_MAX_SG;
7451: host->select_queue_depths = aic7xxx_select_queue_depth;
7452: host->this_id = p->scsi_id;
7453: host->io_port = p->base;
7454: host->n_io_port = 0xFF;
7455: host->base = (unsigned char *) p->mbase;
7456: host->irq = p->irq;
7457: if (p->features & AHC_WIDE)
7458: {
7459: host->max_id = 16;
7460: }
7461: if (p->features & AHC_TWIN)
7462: {
7463: host->max_channel = 1;
7464: }
7465:
7466: p->host = host;
7467: p->last_reset = 0;
7468: p->host_no = host->host_no;
7469: host->unique_id = p->instance;
7470: p->isr_count = 0;
7471: p->next = NULL;
7472: p->completeq.head = NULL;
7473: p->completeq.tail = NULL;
7474: scbq_init(&p->scb_data->free_scbs);
7475: scbq_init(&p->waiting_scbs);
7476:
7477: for (i = 0; i < NUMBER(p->untagged_scbs); i++)
7478: {
7479: p->untagged_scbs[i] = SCB_LIST_NULL;
7480: p->qinfifo[i] = SCB_LIST_NULL;
7481: p->qoutfifo[i] = SCB_LIST_NULL;
7482: }
7483: /*
7484: * We currently have no commands of any type
7485: */
7486: p->qinfifonext = 0;
7487: p->qoutfifonext = 0;
7488:
7489: for (i = 0; i < MAX_TARGETS; i++)
7490: {
7491: p->dev_commands_sent[i] = 0;
7492: p->dev_flags[i] = 0;
7493: p->dev_active_cmds[i] = 0;
7494: p->dev_last_reset[i] = 0;
7495: p->dev_last_queue_full[i] = 0;
7496: p->dev_last_queue_full_count[i] = 0;
7497: p->dev_max_queue_depth[i] = 1;
7498: p->dev_temp_queue_depth[i] = 1;
7499: p->dev_mid_level_queue_depth[i] = 3;
7500: scbq_init(&p->delayed_scbs[i]);
7501: init_timer(&p->dev_timer[i]);
7502: p->dev_timer[i].expires = 0;
7503: p->dev_timer[i].data = (unsigned long)p;
7504: p->dev_timer[i].function = (void *)aic7xxx_timer;
7505: }
7506:
7507: printk(KERN_INFO "(scsi%d) <%s> found at ", p->host_no,
7508: board_names[p->board_name_index]);
7509: switch(p->chip)
7510: {
7511: case (AHC_AIC7770|AHC_EISA):
7512: printk("EISA slot %d\n", p->pci_device_fn);
7513: break;
7514: case (AHC_AIC7770|AHC_VL):
7515: printk("VLB slot %d\n", p->pci_device_fn);
7516: break;
7517: default:
7518: printk("PCI %d/%d\n", PCI_SLOT(p->pci_device_fn),
7519: PCI_FUNC(p->pci_device_fn));
7520: break;
7521: }
7522: if (p->features & AHC_TWIN)
7523: {
7524: printk(KERN_INFO "(scsi%d) Twin Channel, A SCSI ID %d, B SCSI ID %d, ",
7525: p->host_no, p->scsi_id, p->scsi_id_b);
7526: }
7527: else
7528: {
7529: char *channel;
7530:
7531: channel = "";
7532:
7533: if ((p->flags & AHC_MULTI_CHANNEL) != 0)
7534: {
7535: channel = " A";
7536:
7537: if ( (p->flags & (AHC_CHNLB|AHC_CHNLC)) != 0 )
7538: {
7539: channel = (p->flags & AHC_CHNLB) ? " B" : " C";
7540: }
7541: }
7542: if (p->features & AHC_WIDE)
7543: {
7544: printk(KERN_INFO "(scsi%d) Wide ", p->host_no);
7545: }
7546: else
7547: {
7548: printk(KERN_INFO "(scsi%d) Narrow ", p->host_no);
7549: }
7550: printk("Channel%s, SCSI ID=%d, ", channel, p->scsi_id);
7551: }
7552: aic_outb(p, 0, SEQ_FLAGS);
7553:
7554: /*
7555: * Detect SCB parameters and initialize the SCB array.
7556: */
7557: detect_maxscb(p);
7558: printk("%d/%d SCBs\n", p->scb_data->maxhscbs, p->scb_data->maxscbs);
7559: if (aic7xxx_verbose & VERBOSE_PROBE2)
7560: {
7561: printk(KERN_INFO "(scsi%d) BIOS %sabled, IO Port 0x%lx, IRQ %d\n",
7562: p->host_no, (p->flags & AHC_BIOS_ENABLED) ? "en" : "dis",
7563: p->base, p->irq);
7564: printk(KERN_INFO "(scsi%d) IO Memory at 0x%lx, MMAP Memory at 0x%lx\n",
7565: p->host_no, p->mbase, (unsigned long)p->maddr);
7566: }
7567:
7568: #ifdef CONFIG_PCI
7569: /*
7570: * Now that we know our instance number, we can set the flags we need to
7571: * force termination if need be.
7572: */
7573: if (aic7xxx_stpwlev != -1)
7574: {
7575: /*
7576: * This option only applies to PCI controllers.
7577: */
7578: if ( (p->chip & ~AHC_CHIPID_MASK) == AHC_PCI)
7579: {
7580: unsigned char devconfig;
7581:
7582: #if LINUX_KERNEL_VERSION > KERNEL_VERSION(2,1,92)
7583: pci_read_config_byte(p->pdev, DEVCONFIG, &devconfig);
7584: #else
7585: pcibios_read_config_byte(p->pci_bus, p->pci_device_fn,
7586: DEVCONFIG, &devconfig);
7587: #endif
7588: if ( (aic7xxx_stpwlev >> p->instance) & 0x01 )
7589: {
7590: devconfig |= 0x02;
7591: if (aic7xxx_verbose & VERBOSE_PROBE2)
7592: printk("(scsi%d) Force setting STPWLEV bit\n", p->host_no);
7593: }
7594: else
7595: {
7596: devconfig &= ~0x02;
7597: if (aic7xxx_verbose & VERBOSE_PROBE2)
7598: printk("(scsi%d) Force clearing STPWLEV bit\n", p->host_no);
7599: }
7600: #if LINUX_KERNEL_VERSION > KERNEL_VERSION(2,1,92)
7601: pci_write_config_byte(p->pdev, DEVCONFIG, devconfig);
7602: #else
7603: pcibios_write_config_byte(p->pci_bus, p->pci_device_fn,
7604: DEVCONFIG, devconfig);
7605: #endif
7606: }
7607: }
7608: #endif
7609:
7610: /*
7611: * That took care of devconfig and stpwlev, now for the actual termination
7612: * settings.
7613: */
7614: if (aic7xxx_override_term != -1)
7615: {
7616: /*
7617: * Again, this only applies to PCI controllers. We don't have problems
7618: * with the termination on 274x controllers to the best of my knowledge.
7619: */
7620: if ( (p->chip & ~AHC_CHIPID_MASK) == AHC_PCI)
7621: {
7622: unsigned char term_override;
7623:
7624: term_override = ( (aic7xxx_override_term >> (p->instance * 4)) & 0x0f);
7625: p->adapter_control &=
7626: ~(CFSTERM|CFWSTERM|CFLVDSTERM|CFAUTOTERM|CFSEAUTOTERM);
7627: if ( (p->features & AHC_ULTRA2) && (term_override & 0x0c) )
7628: {
7629: p->adapter_control |= CFLVDSTERM;
7630: }
7631: if (term_override & 0x02)
7632: {
7633: p->adapter_control |= CFWSTERM;
7634: }
7635: if (term_override & 0x01)
7636: {
7637: p->adapter_control |= CFSTERM;
7638: }
7639: }
7640: }
7641:
7642: if ( (p->flags & AHC_SEEPROM_FOUND) || (aic7xxx_override_term != -1) )
7643: {
7644: if (p->features & AHC_SPIOCAP)
7645: {
7646: if ( aic_inb(p, SPIOCAP) & SSPIOCPS )
7647: /*
7648: * Update the settings in sxfrctl1 to match the termination
7649: * settings.
7650: */
7651: configure_termination(p);
7652: }
7653: else if ((p->chip & AHC_CHIPID_MASK) >= AHC_AIC7870)
7654: {
7655: configure_termination(p);
7656: }
7657: }
7658:
7659: /*
7660: * Clear out any possible pending interrupts.
7661: */
7662: aic7xxx_clear_intstat(p);
7663:
7664: /*
7665: * Set the SCSI Id, SXFRCTL0, SXFRCTL1, and SIMODE1, for both channels
7666: */
7667: if (p->features & AHC_TWIN)
7668: {
7669: /* Select channel B */
7670: aic_outb(p, aic_inb(p, SBLKCTL) | SELBUSB, SBLKCTL);
7671:
7672: term = ((p->flags & AHC_TERM_ENB_B) != 0) ? STPWEN : 0;
7673: aic_outb(p, p->scsi_id_b, SCSIID);
7674: scsi_conf = aic_inb(p, SCSICONF + 1);
7675: aic_outb(p, DFON | SPIOEN, SXFRCTL0);
7676: aic_outb(p, (scsi_conf & ENSPCHK) | term |
7677: ENSTIMER | ACTNEGEN, SXFRCTL1);
7678: aic_outb(p, 0, SIMODE0);
7679: aic_outb(p, ENSELTIMO | ENSCSIRST | ENSCSIPERR, SIMODE1);
7680: aic_outb(p, 0, SCSIRATE);
7681:
7682: /* Select channel A */
7683: aic_outb(p, aic_inb(p, SBLKCTL) & ~SELBUSB, SBLKCTL);
7684: }
7685:
7686: term = ((p->flags & AHC_TERM_ENB_SE_LOW) != 0) ? STPWEN : 0;
7687: if (p->features & AHC_ULTRA2)
7688: aic_outb(p, p->scsi_id, SCSIID_ULTRA2);
7689: else
7690: aic_outb(p, p->scsi_id, SCSIID);
7691: scsi_conf = aic_inb(p, SCSICONF);
7692: aic_outb(p, DFON | SPIOEN, SXFRCTL0);
7693: aic_outb(p, (scsi_conf & ENSPCHK) | term |
7694: ENSTIMER | ACTNEGEN, SXFRCTL1);
7695: aic_outb(p, 0, SIMODE0);
7696: aic_outb(p, ENSELTIMO | ENSCSIRST | ENSCSIPERR, SIMODE1);
7697: aic_outb(p, 0, SCSIRATE);
7698: if ( p->features & AHC_ULTRA2)
7699: aic_outb(p, 0, SCSIOFFSET);
7700:
7701: /*
7702: * Look at the information that board initialization or the board
7703: * BIOS has left us. In the lower four bits of each target's
7704: * scratch space any value other than 0 indicates that we should
7705: * initiate synchronous transfers. If it's zero, the user or the
7706: * BIOS has decided to disable synchronous negotiation to that
7707: * target so we don't activate the needsdtr flag.
7708: */
7709: if ((p->features & (AHC_TWIN|AHC_WIDE)) == 0)
7710: {
7711: max_targets = 8;
7712: }
7713: else
7714: {
7715: max_targets = 16;
7716: }
7717:
7718: if (!(aic7xxx_no_reset))
7719: {
7720: /*
7721: * If we reset the bus, then clear the transfer settings, else leave
7722: * them be
7723: */
7724: for (i = 0; i < max_targets; i++)
7725: {
7726: aic_outb(p, 0, TARG_SCSIRATE + i);
7727: if (p->features & AHC_ULTRA2)
7728: {
7729: aic_outb(p, 0, TARG_OFFSET + i);
7730: }
7731: p->transinfo[i].cur_offset = 0;
7732: p->transinfo[i].cur_period = 0;
7733: p->transinfo[i].cur_width = MSG_EXT_WDTR_BUS_8_BIT;
7734: }
7735:
7736: /*
7737: * If we reset the bus, then clear the transfer settings, else leave
7738: * them be.
7739: */
7740: aic_outb(p, 0, ULTRA_ENB);
7741: aic_outb(p, 0, ULTRA_ENB + 1);
7742: p->ultraenb = 0;
7743: }
7744:
7745: /*
7746: * Allocate enough hardware scbs to handle the maximum number of
7747: * concurrent transactions we can have. We have to make sure that
7748: * the allocated memory is contiguous memory. The Linux kmalloc
7749: * routine should only allocate contiguous memory, but note that
7750: * this could be a problem if kmalloc() is changed.
7751: */
7752: {
7753: size_t array_size;
7754: unsigned int hscb_physaddr;
7755: unsigned long temp;
7756:
7757: array_size = p->scb_data->maxscbs * sizeof(struct aic7xxx_hwscb);
7758: if (p->scb_data->hscbs == NULL)
7759: {
7760: /*
7761: * A little padding so we can align thing the way we want
7762: */
7763: p->scb_data->hscbs = kmalloc(array_size + 0x1f, GFP_ATOMIC);
7764: }
7765: if (p->scb_data->hscbs == NULL)
7766: {
7767: printk("(scsi%d) Unable to allocate hardware SCB array; "
7768: "failing detection.\n", p->host_no);
7769: p->irq = 0;
7770: return(0);
7771: }
7772: /*
7773: * Save the actual kmalloc buffer pointer off, then align our
7774: * buffer to a 32 byte boundary
7775: */
7776: p->scb_data->hscb_kmalloc_ptr = p->scb_data->hscbs;
7777: temp = (unsigned long)p->scb_data->hscbs;
7778: temp += 0x1f;
7779: temp &= ~0x1f;
7780: p->scb_data->hscbs = (struct aic7xxx_hwscb *)temp;
7781: /* At least the control byte of each SCB needs to be 0. */
7782: memset(p->scb_data->hscbs, 0, array_size);
7783:
7784: /* Tell the sequencer where it can find the hardware SCB array. */
7785: hscb_physaddr = VIRT_TO_BUS(p->scb_data->hscbs);
7786: aic_outb(p, hscb_physaddr & 0xFF, HSCB_ADDR);
7787: aic_outb(p, (hscb_physaddr >> 8) & 0xFF, HSCB_ADDR + 1);
7788: aic_outb(p, (hscb_physaddr >> 16) & 0xFF, HSCB_ADDR + 2);
7789: aic_outb(p, (hscb_physaddr >> 24) & 0xFF, HSCB_ADDR + 3);
7790:
7791: /* Set up the fifo areas at the same time */
7792: hscb_physaddr = VIRT_TO_BUS(&p->untagged_scbs[0]);
7793: aic_outb(p, hscb_physaddr & 0xFF, SCBID_ADDR);
7794: aic_outb(p, (hscb_physaddr >> 8) & 0xFF, SCBID_ADDR + 1);
7795: aic_outb(p, (hscb_physaddr >> 16) & 0xFF, SCBID_ADDR + 2);
7796: aic_outb(p, (hscb_physaddr >> 24) & 0xFF, SCBID_ADDR + 3);
7797: }
7798:
7799: /* The Q-FIFOs we just set up are all empty */
7800: aic_outb(p, 0, QINPOS);
7801: aic_outb(p, 0, KERNEL_QINPOS);
7802: aic_outb(p, 0, QOUTPOS);
7803:
7804: if(p->features & AHC_QUEUE_REGS)
7805: {
7806: aic_outb(p, SCB_QSIZE_256, QOFF_CTLSTA);
7807: aic_outb(p, 0, SDSCB_QOFF);
7808: aic_outb(p, 0, SNSCB_QOFF);
7809: aic_outb(p, 0, HNSCB_QOFF);
7810: }
7811:
7812: /*
7813: * We don't have any waiting selections or disconnected SCBs.
7814: */
7815: aic_outb(p, SCB_LIST_NULL, WAITING_SCBH);
7816: aic_outb(p, SCB_LIST_NULL, DISCONNECTED_SCBH);
7817:
7818: /*
7819: * Message out buffer starts empty
7820: */
7821: aic_outb(p, MSG_NOOP, MSG_OUT);
7822: aic_outb(p, MSG_NOOP, LAST_MSG);
7823:
7824: /*
7825: * Set all the other asundry items that haven't been set yet.
7826: * This includes just dumping init values to a lot of registers simply
7827: * to make sure they've been touched and are ready for use parity wise
7828: * speaking.
7829: */
7830: aic_outb(p, 0, TMODE_CMDADDR);
7831: aic_outb(p, 0, TMODE_CMDADDR + 1);
7832: aic_outb(p, 0, TMODE_CMDADDR + 2);
7833: aic_outb(p, 0, TMODE_CMDADDR + 3);
7834: aic_outb(p, 0, TMODE_CMDADDR_NEXT);
7835:
7836: /*
7837: * Link us into the list of valid hosts
7838: */
7839: p->next = first_aic7xxx;
7840: first_aic7xxx = p;
7841:
7842: /*
7843: * Clear out any possible pending interrupts, again.
7844: */
7845: aic7xxx_clear_intstat(p);
7846:
7847: /*
7848: * Allocate the first set of scbs for this controller. This is to stream-
7849: * line code elsewhere in the driver. If we have to check for the existence
7850: * of scbs in certain code sections, it slows things down. However, as
7851: * soon as we register the IRQ for this card, we could get an interrupt that
7852: * includes possibly the SCSI_RSTI interrupt. If we catch that interrupt
7853: * then we are likely to segfault if we don't have at least one chunk of
7854: * SCBs allocated or add checks all through the reset code to make sure
7855: * that the SCBs have been allocated which is an invalid running condition
7856: * and therefore I think it's preferable to simply pre-allocate the first
7857: * chunk of SCBs.
7858: */
7859: aic7xxx_allocate_scb(p);
7860:
7861: /*
7862: * Load the sequencer program, then re-enable the board -
7863: * resetting the AIC-7770 disables it, leaving the lights
7864: * on with nobody home.
7865: */
7866: aic7xxx_loadseq(p);
7867:
7868: if ( (p->chip & AHC_CHIPID_MASK) == AHC_AIC7770 )
7869: {
7870: aic_outb(p, ENABLE, BCTL); /* Enable the boards BUS drivers. */
7871: }
7872:
7873: if ( !(aic7xxx_no_reset) )
7874: {
7875: if (p->features & AHC_TWIN)
7876: {
7877: if (aic7xxx_verbose & VERBOSE_PROBE2)
7878: printk(KERN_INFO "(scsi%d) Resetting channel B\n", p->host_no);
7879: aic_outb(p, aic_inb(p, SBLKCTL) | SELBUSB, SBLKCTL);
7880: aic7xxx_reset_current_bus(p);
7881: aic_outb(p, aic_inb(p, SBLKCTL) & ~SELBUSB, SBLKCTL);
7882: }
7883: /* Reset SCSI bus A. */
7884: if (aic7xxx_verbose & VERBOSE_PROBE2)
7885: { /* In case we are a 3940, 3985, or 7895, print the right channel */
7886: char *channel = "";
7887: if (p->flags & AHC_MULTI_CHANNEL)
7888: {
7889: channel = " A";
7890: if (p->flags & (AHC_CHNLB|AHC_CHNLC))
7891: channel = (p->flags & AHC_CHNLB) ? " B" : " C";
7892: }
7893: printk(KERN_INFO "(scsi%d) Resetting channel%s\n", p->host_no, channel);
7894: }
7895:
7896: /*
7897: * Some of the new Ultra2 chipsets need a longer delay after a chip
7898: * reset than just the init setup creates, so we have to delay here
7899: * before we go into a reset in order to make the chips happy.
7900: */
7901: if (p->features & AHC_ULTRA2)
7902: mdelay(250);
7903: aic7xxx_reset_current_bus(p);
7904:
7905: /*
7906: * Delay for the reset delay.
7907: */
7908: if (!reset_delay)
7909: aic7xxx_delay(AIC7XXX_RESET_DELAY);
7910: }
7911: else
7912: {
7913: if (!reset_delay)
7914: {
7915: printk(KERN_INFO "(scsi%d) Not resetting SCSI bus. Note: Don't use "
7916: "the no_reset\n", p->host_no);
7917: printk(KERN_INFO "(scsi%d) option unless you have a verifiable need "
7918: "for it.\n", p->host_no);
7919: printk(KERN_INFO "(scsi%d) The no_reset option is known to break some "
7920: "systems,\n", p->host_no);
7921: printk(KERN_INFO "(scsi%d) and is not supported by the driver author\n",
7922: p->host_no);
7923: aic7xxx_delay(AIC7XXX_RESET_DELAY);
7924: }
7925: }
7926:
7927: /*
7928: * Register IRQ with the kernel. Only allow sharing IRQs with
7929: * PCI devices.
7930: */
7931: if (!(p->chip & AHC_PCI))
7932: {
7933: result = (request_irq(p->irq, do_aic7xxx_isr, 0, "aic7xxx", p));
7934: }
7935: else
7936: {
7937: result = (request_irq(p->irq, do_aic7xxx_isr, SA_SHIRQ,
7938: "aic7xxx", p));
7939: if (result < 0)
7940: {
7941: result = (request_irq(p->irq, do_aic7xxx_isr, SA_INTERRUPT | SA_SHIRQ,
7942: "aic7xxx", p));
7943: }
7944: }
7945: if (result < 0)
7946: {
7947: printk(KERN_WARNING "(scsi%d) Couldn't register IRQ %d, ignoring "
7948: "controller.\n", p->host_no, p->irq);
7949: p->irq = 0;
7950: return (0);
7951: }
7952:
7953: unpause_sequencer(p, /* unpause_always */ TRUE);
7954:
7955: return (found);
7956: }
7957:
7958: /*+F*************************************************************************
7959: * Function:
7960: * aic7xxx_chip_reset
7961: *
7962: * Description:
7963: * Perform a chip reset on the aic7xxx SCSI controller. The controller
7964: * is paused upon return.
7965: *-F*************************************************************************/
7966: int
7967: aic7xxx_chip_reset(struct aic7xxx_host *p)
7968: {
7969: unsigned char sblkctl;
7970: int wait;
7971:
7972: /*
7973: * For some 274x boards, we must clear the CHIPRST bit and pause
7974: * the sequencer. For some reason, this makes the driver work.
7975: */
7976: aic_outb(p, PAUSE | CHIPRST, HCNTRL);
7977:
7978: /*
7979: * In the future, we may call this function as a last resort for
7980: * error handling. Let's be nice and not do any unecessary delays.
7981: */
7982: wait = 1000; /* 1 second (1000 * 1 msec) */
7983: while (--wait && !(aic_inb(p, HCNTRL) & CHIPRSTACK))
7984: {
7985: mdelay(1); /* 1 msec */
7986: }
7987:
7988: pause_sequencer(p);
7989:
7990: sblkctl = aic_inb(p, SBLKCTL) & (SELBUSB|SELWIDE);
7991: if (p->chip & AHC_PCI)
7992: sblkctl &= ~SELBUSB;
7993: switch( sblkctl )
7994: {
7995: case 0: /* normal narrow card */
7996: break;
7997: case 2: /* Wide card */
7998: p->features |= AHC_WIDE;
7999: break;
8000: case 8: /* Twin card */
8001: p->features |= AHC_TWIN;
8002: p->flags |= AHC_MULTI_CHANNEL;
8003: break;
8004: default: /* hmmm...we don't know what this is */
8005: printk(KERN_WARNING "aic7xxx: Unsupported adapter type %d, ignoring.\n",
8006: aic_inb(p, SBLKCTL) & 0x0a);
8007: return(-1);
8008: }
8009: return(0);
8010: }
8011:
8012: /*+F*************************************************************************
8013: * Function:
8014: * aic7xxx_alloc
8015: *
8016: * Description:
8017: * Allocate and initialize a host structure. Returns NULL upon error
8018: * and a pointer to a aic7xxx_host struct upon success.
8019: *-F*************************************************************************/
8020: static struct aic7xxx_host *
8021: aic7xxx_alloc(Scsi_Host_Template *sht, struct aic7xxx_host *temp)
8022: {
8023: struct aic7xxx_host *p = NULL;
8024: struct Scsi_Host *host;
8025: int i;
8026:
8027: /*
8028: * Allocate a storage area by registering us with the mid-level
8029: * SCSI layer.
8030: */
8031: host = scsi_register(sht, sizeof(struct aic7xxx_host));
8032:
8033: if (host != NULL)
8034: {
8035: p = (struct aic7xxx_host *) host->hostdata;
8036: memset(p, 0, sizeof(struct aic7xxx_host));
8037: *p = *temp;
8038: p->host = host;
8039:
8040: p->scb_data = kmalloc(sizeof(scb_data_type), GFP_ATOMIC);
8041: if (p->scb_data != NULL)
8042: {
8043: memset(p->scb_data, 0, sizeof(scb_data_type));
8044: scbq_init (&p->scb_data->free_scbs);
8045: }
8046: else
8047: {
8048: /*
8049: * For some reason we don't have enough memory. Free the
8050: * allocated memory for the aic7xxx_host struct, and return NULL.
8051: */
8052: release_region(p->base, MAXREG - MINREG);
8053: scsi_unregister(host);
8054: return(NULL);
8055: }
8056: p->host_no = host->host_no;
8057: p->tagenable = 0;
8058: p->orderedtag = 0;
8059: for (i=0; i<MAX_TARGETS; i++)
8060: {
8061: p->transinfo[i].goal_period = 0;
8062: p->transinfo[i].goal_offset = 0;
8063: p->transinfo[i].goal_width = MSG_EXT_WDTR_BUS_8_BIT;
8064: }
8065: DRIVER_LOCK_INIT
8066: }
8067: return (p);
8068: }
8069:
8070: /*+F*************************************************************************
8071: * Function:
8072: * aic7xxx_free
8073: *
8074: * Description:
8075: * Frees and releases all resources associated with an instance of
8076: * the driver (struct aic7xxx_host *).
8077: *-F*************************************************************************/
8078: static void
8079: aic7xxx_free(struct aic7xxx_host *p)
8080: {
8081: int i;
8082:
8083: /*
8084: * Free the allocated hardware SCB space.
8085: */
8086: if (p->scb_data != NULL)
8087: {
8088: if (p->scb_data->hscbs != NULL)
8089: {
8090: kfree(p->scb_data->hscb_kmalloc_ptr);
8091: p->scb_data->hscbs = p->scb_data->hscb_kmalloc_ptr = NULL;
8092: }
8093: /*
8094: * Free the driver SCBs. These were allocated on an as-need
8095: * basis. We allocated these in groups depending on how many
8096: * we could fit into a given amount of RAM. The tail SCB for
8097: * these allocations has a pointer to the alloced area.
8098: */
8099: for (i = 0; i < p->scb_data->numscbs; i++)
8100: {
8101: if (p->scb_data->scb_array[i]->kmalloc_ptr != NULL)
8102: kfree(p->scb_data->scb_array[i]->kmalloc_ptr);
8103: p->scb_data->scb_array[i] = NULL;
8104: }
8105:
8106: /*
8107: * Free the SCB data area.
8108: */
8109: kfree(p->scb_data);
8110: }
8111:
8112: /*
8113: * Free any alloced Scsi_Cmnd structures that might be around for
8114: * negotiation purposes....
8115: */
8116: for (i = 0; i < MAX_TARGETS; i++)
8117: {
8118: if(p->dev_wdtr_cmnd[i])
8119: kfree(p->dev_wdtr_cmnd[i]);
8120: if(p->dev_sdtr_cmnd[i])
8121: kfree(p->dev_sdtr_cmnd[i]);
8122: }
8123:
8124: }
8125:
8126: /*+F*************************************************************************
8127: * Function:
8128: * aic7xxx_load_seeprom
8129: *
8130: * Description:
8131: * Load the seeprom and configure adapter and target settings.
8132: * Returns 1 if the load was successful and 0 otherwise.
8133: *-F*************************************************************************/
8134: static void
8135: aic7xxx_load_seeprom(struct aic7xxx_host *p, unsigned char *sxfrctl1)
8136: {
8137: int have_seeprom = 0;
8138: int i, max_targets, mask;
8139: unsigned char scsirate, scsi_conf;
8140: unsigned short scarray[128];
8141: struct seeprom_config *sc = (struct seeprom_config *) scarray;
8142:
8143: if (aic7xxx_verbose & VERBOSE_PROBE2)
8144: {
8145: printk(KERN_INFO "aic7xxx: Loading serial EEPROM...");
8146: }
8147: switch (p->chip)
8148: {
8149: case (AHC_AIC7770|AHC_EISA): /* None of these adapters have seeproms. */
8150: if (aic_inb(p, SCSICONF) & TERM_ENB)
8151: p->flags |= AHC_TERM_ENB_A;
8152: if ( (p->features & AHC_TWIN) && (aic_inb(p, SCSICONF + 1) & TERM_ENB) )
8153: p->flags |= AHC_TERM_ENB_B;
8154: break;
8155:
8156: case (AHC_AIC7770|AHC_VL):
8157: have_seeprom = read_284x_seeprom(p, (struct seeprom_config *) scarray);
8158: break;
8159:
8160: default:
8161: have_seeprom = read_seeprom(p, (p->flags & (AHC_CHNLB|AHC_CHNLC)),
8162: scarray, p->sc_size, p->sc_type);
8163: if (!have_seeprom)
8164: {
8165: if(p->sc_type == C46)
8166: have_seeprom = read_seeprom(p, (p->flags & (AHC_CHNLB|AHC_CHNLC)),
8167: scarray, p->sc_size, C56_66);
8168: else
8169: have_seeprom = read_seeprom(p, (p->flags & (AHC_CHNLB|AHC_CHNLC)),
8170: scarray, p->sc_size, C46);
8171: }
8172: break;
8173: }
8174:
8175: if (!have_seeprom)
8176: {
8177: if (aic7xxx_verbose & VERBOSE_PROBE2)
8178: {
8179: printk("\naic7xxx: No SEEPROM available.\n");
8180: }
8181: p->flags |= AHC_NEWEEPROM_FMT;
8182: if (aic_inb(p, SCSISEQ) == 0)
8183: {
8184: p->flags |= AHC_USEDEFAULTS;
8185: p->flags &= ~AHC_BIOS_ENABLED;
8186: p->scsi_id = p->scsi_id_b = 7;
8187: *sxfrctl1 |= STPWEN;
8188: if (aic7xxx_verbose & VERBOSE_PROBE2)
8189: {
8190: printk("aic7xxx: Using default values.\n");
8191: }
8192: }
8193: else if (aic7xxx_verbose & VERBOSE_PROBE2)
8194: {
8195: printk("aic7xxx: Using leftover BIOS values.\n");
8196: }
8197: if ( *sxfrctl1 & STPWEN )
8198: {
8199: p->flags |= AHC_TERM_ENB_SE_LOW | AHC_TERM_ENB_SE_HIGH;
8200: sc->adapter_control &= ~CFAUTOTERM;
8201: sc->adapter_control |= CFSTERM | CFWSTERM | CFLVDSTERM;
8202: }
8203: p->flags |= AHC_EXTEND_TRANS_A | AHC_EXTEND_TRANS_B;
8204: }
8205: else
8206: {
8207: if (aic7xxx_verbose & VERBOSE_PROBE2)
8208: {
8209: printk("done\n");
8210: }
8211:
8212: /*
8213: * Note things in our flags
8214: */
8215: p->flags |= AHC_SEEPROM_FOUND;
8216:
8217: /*
8218: * Update the settings in sxfrctl1 to match the termination settings.
8219: */
8220: *sxfrctl1 = 0;
8221:
8222: /*
8223: * Get our SCSI ID from the SEEPROM setting...
8224: */
8225: p->scsi_id = (sc->brtime_id & CFSCSIID);
8226:
8227: /*
8228: * First process the settings that are different between the VLB
8229: * and PCI adapter seeproms.
8230: */
8231: if ((p->chip & AHC_CHIPID_MASK) == AHC_AIC7770)
8232: {
8233: /* VLB adapter seeproms */
8234: if (sc->bios_control & CF284XEXTEND)
8235: p->flags |= AHC_EXTEND_TRANS_A;
8236:
8237: if (sc->adapter_control & CF284XSTERM)
8238: {
8239: *sxfrctl1 |= STPWEN;
8240: p->flags |= AHC_TERM_ENB_SE_LOW | AHC_TERM_ENB_SE_HIGH;
8241: }
8242: }
8243: else
8244: {
8245: /* PCI adapter seeproms */
8246: if (sc->bios_control & CFEXTEND)
8247: p->flags |= AHC_EXTEND_TRANS_A;
8248: if (sc->bios_control & CFBIOSEN)
8249: p->flags |= AHC_BIOS_ENABLED;
8250: else
8251: p->flags &= ~AHC_BIOS_ENABLED;
8252:
8253: if (sc->adapter_control & CFSTERM)
8254: {
8255: *sxfrctl1 |= STPWEN;
8256: p->flags |= AHC_TERM_ENB_SE_LOW | AHC_TERM_ENB_SE_HIGH;
8257: }
8258: }
8259: p->sc = *sc;
8260: }
8261:
8262: p->discenable = 0;
8263:
8264: /*
8265: * Limit to 16 targets just in case. The 2842 for one is known to
8266: * blow the max_targets setting, future cards might also.
8267: */
8268: max_targets = MIN(sc->max_targets & CFMAXTARG,
8269: ((p->features & (AHC_TWIN | AHC_WIDE)) ? 16 : 8));
8270:
8271: if (have_seeprom)
8272: {
8273: for (i = 0; i < max_targets; i++)
8274: {
8275: if( ((p->features & AHC_ULTRA) &&
8276: !(sc->adapter_control & CFULTRAEN) &&
8277: (sc->device_flags[i] & CFSYNCHISULTRA)) ||
8278: (sc->device_flags[i] & CFNEWULTRAFORMAT) )
8279: {
8280: p->flags |= AHC_NEWEEPROM_FMT;
8281: break;
8282: }
8283: }
8284: }
8285:
8286: for (i = 0; i < max_targets; i++)
8287: {
8288: mask = (0x01 << i);
8289: if (!have_seeprom)
8290: {
8291: if(aic_inb(p, SCSISEQ) != 0)
8292: {
8293: /*
8294: * OK...the BIOS set things up and left behind the settings we need.
8295: * Just make our sc->device_flags[i] entry match what the card has
8296: * set for this device.
8297: */
8298: p->discenable =
8299: ~(aic_inb(p, DISC_DSB) | (aic_inb(p, DISC_DSB + 1) << 8) );
8300: p->ultraenb =
8301: (aic_inb(p, ULTRA_ENB) | (aic_inb(p, ULTRA_ENB + 1) << 8) );
8302: sc->device_flags[i] = (p->discenable & mask) ? CFDISC : 0;
8303: if (aic_inb(p, TARG_SCSIRATE + i) & WIDEXFER)
8304: sc->device_flags[i] |= CFWIDEB;
8305: if (p->features & AHC_ULTRA2)
8306: {
8307: if (aic_inb(p, TARG_OFFSET + i))
8308: {
8309: sc->device_flags[i] |= CFSYNCH;
8310: sc->device_flags[i] |= (aic_inb(p, TARG_SCSIRATE + i) & 0x07);
8311: if ( (aic_inb(p, TARG_SCSIRATE + i) & 0x18) == 0x18 )
8312: sc->device_flags[i] |= CFSYNCHISULTRA;
8313: }
8314: }
8315: else
8316: {
8317: if (aic_inb(p, TARG_SCSIRATE + i) & ~WIDEXFER)
8318: {
8319: sc->device_flags[i] |= CFSYNCH;
8320: if (p->features & AHC_ULTRA)
8321: sc->device_flags[i] |= ((p->ultraenb & mask) ?
8322: CFSYNCHISULTRA : 0);
8323: }
8324: }
8325: }
8326: else
8327: {
8328: /*
8329: * Assume the BIOS has NOT been run on this card and nothing between
8330: * the card and the devices is configured yet.
8331: */
8332: sc->device_flags[i] = CFDISC;
8333: if (p->features & AHC_WIDE)
8334: sc->device_flags[i] |= CFWIDEB;
8335: if (p->features & AHC_ULTRA2)
8336: sc->device_flags[i] |= 3;
8337: else if (p->features & AHC_ULTRA)
8338: sc->device_flags[i] |= CFSYNCHISULTRA;
8339: sc->device_flags[i] |= CFSYNCH;
8340: aic_outb(p, 0, TARG_SCSIRATE + i);
8341: if (p->features & AHC_ULTRA2)
8342: aic_outb(p, 0, TARG_OFFSET + i);
8343: }
8344: }
8345: if (sc->device_flags[i] & CFDISC)
8346: {
8347: p->discenable |= mask;
8348: }
8349: if (p->flags & AHC_NEWEEPROM_FMT)
8350: {
8351: if (sc->device_flags[i] & CFSYNCHISULTRA)
8352: {
8353: p->ultraenb |= mask;
8354: }
8355: else if (sc->device_flags[i] & CFNEWULTRAFORMAT)
8356: {
8357: if ( (sc->device_flags[i] & (CFSYNCHISULTRA | CFXFER)) == 0x03 )
8358: {
8359: sc->device_flags[i] &= ~CFXFER;
8360: sc->device_flags[i] |= CFSYNCHISULTRA;
8361: p->ultraenb |= mask;
8362: }
8363: }
8364: }
8365: else if (sc->adapter_control & CFULTRAEN)
8366: {
8367: p->ultraenb |= mask;
8368: }
8369: if ( (sc->device_flags[i] & CFSYNCH) == 0)
8370: {
8371: sc->device_flags[i] &= ~CFXFER;
8372: p->ultraenb &= ~mask;
8373: p->transinfo[i].user_offset = 0;
8374: p->transinfo[i].user_period = 0;
8375: p->transinfo[i].cur_offset = 0;
8376: p->transinfo[i].cur_period = 0;
8377: p->needsdtr_copy &= ~mask;
8378: }
8379: else
8380: {
8381: if (p->features & AHC_ULTRA2)
8382: {
8383: p->transinfo[i].user_offset = MAX_OFFSET_ULTRA2;
8384: p->transinfo[i].cur_offset = aic_inb(p, TARG_OFFSET + i);
8385: scsirate = (sc->device_flags[i] & CFXFER) |
8386: ((p->ultraenb & mask) ? 0x18 : 0x10);
8387: p->transinfo[i].user_period = aic7xxx_find_period(p, scsirate,
8388: AHC_SYNCRATE_ULTRA2);
8389: p->transinfo[i].cur_period = aic7xxx_find_period(p,
8390: aic_inb(p, TARG_SCSIRATE + i),
8391: AHC_SYNCRATE_ULTRA2);
8392: }
8393: else
8394: {
8395: scsirate = (sc->device_flags[i] & CFXFER) << 4;
8396: if (sc->device_flags[i] & CFWIDEB)
8397: p->transinfo[i].user_offset = MAX_OFFSET_16BIT;
8398: else
8399: p->transinfo[i].user_offset = MAX_OFFSET_8BIT;
8400: if (p->features & AHC_ULTRA)
8401: {
8402: short ultraenb;
8403: ultraenb = aic_inb(p, ULTRA_ENB) |
8404: (aic_inb(p, ULTRA_ENB + 1) << 8);
8405: p->transinfo[i].user_period = aic7xxx_find_period(p,
8406: scsirate,
8407: (p->ultraenb & mask) ?
8408: AHC_SYNCRATE_ULTRA :
8409: AHC_SYNCRATE_FAST);
8410: p->transinfo[i].cur_period = aic7xxx_find_period(p,
8411: aic_inb(p, TARG_SCSIRATE + i),
8412: (ultraenb & mask) ?
8413: AHC_SYNCRATE_ULTRA :
8414: AHC_SYNCRATE_FAST);
8415: }
8416: else
8417: p->transinfo[i].user_period = aic7xxx_find_period(p,
8418: scsirate, AHC_SYNCRATE_FAST);
8419: }
8420: p->needsdtr_copy |= mask;
8421: }
8422: if ( (sc->device_flags[i] & CFWIDEB) && (p->features & AHC_WIDE) )
8423: {
8424: p->transinfo[i].user_width = MSG_EXT_WDTR_BUS_16_BIT;
8425: p->needwdtr_copy |= mask;
8426: }
8427: else
8428: {
8429: p->transinfo[i].user_width = MSG_EXT_WDTR_BUS_8_BIT;
8430: p->needwdtr_copy &= ~mask;
8431: }
8432: p->transinfo[i].cur_width =
8433: (aic_inb(p, TARG_SCSIRATE + i) & WIDEXFER) ?
8434: MSG_EXT_WDTR_BUS_16_BIT : MSG_EXT_WDTR_BUS_8_BIT;
8435: }
8436: aic_outb(p, ~(p->discenable & 0xFF), DISC_DSB);
8437: aic_outb(p, ~((p->discenable >> 8) & 0xFF), DISC_DSB + 1);
8438: p->needwdtr = p->needwdtr_copy;
8439: p->needsdtr = p->needsdtr_copy;
8440: p->wdtr_pending = p->sdtr_pending = 0;
8441:
8442: /*
8443: * We set the p->ultraenb from the SEEPROM to begin with, but now we make
8444: * it match what is already down in the card. If we are doing a reset
8445: * on the card then this will get put back to a default state anyway.
8446: * This allows us to not have to pre-emptively negotiate when using the
8447: * no_reset option.
8448: */
8449: if (p->features & AHC_ULTRA)
8450: p->ultraenb = aic_inb(p, ULTRA_ENB) | (aic_inb(p, ULTRA_ENB + 1) << 8);
8451:
8452:
8453: scsi_conf = (p->scsi_id & HSCSIID);
8454:
8455: if(have_seeprom)
8456: {
8457: p->adapter_control = sc->adapter_control;
8458: p->bios_control = sc->bios_control;
8459:
8460: switch (p->chip & AHC_CHIPID_MASK)
8461: {
8462: case AHC_AIC7895:
8463: case AHC_AIC7896:
8464: if (p->adapter_control & CFBPRIMARY)
8465: p->flags |= AHC_CHANNEL_B_PRIMARY;
8466: default:
8467: break;
8468: }
8469:
8470: if (sc->adapter_control & CFSPARITY)
8471: scsi_conf |= ENSPCHK;
8472: }
8473: else
8474: {
8475: scsi_conf |= ENSPCHK | RESET_SCSI;
8476: }
8477:
8478: /*
8479: * Only set the SCSICONF and SCSICONF + 1 registers if we are a PCI card.
8480: * The 2842 and 2742 cards already have these registers set and we don't
8481: * want to muck with them since we don't set all the bits they do.
8482: */
8483: if ( (p->chip & ~AHC_CHIPID_MASK) == AHC_PCI )
8484: {
8485: /* Set the host ID */
8486: aic_outb(p, scsi_conf, SCSICONF);
8487: /* In case we are a wide card */
8488: aic_outb(p, p->scsi_id, SCSICONF + 1);
8489: }
8490: }
8491:
8492: /*+F*************************************************************************
8493: * Function:
8494: * aic7xxx_detect
8495: *
8496: * Description:
8497: * Try to detect and register an Adaptec 7770 or 7870 SCSI controller.
8498: *
8499: * XXX - This should really be called aic7xxx_probe(). A sequence of
8500: * probe(), attach()/detach(), and init() makes more sense than
8501: * one do-it-all function. This may be useful when (and if) the
8502: * mid-level SCSI code is overhauled.
8503: *-F*************************************************************************/
8504: int
8505: aic7xxx_detect(Scsi_Host_Template *template)
8506: {
8507: struct aic7xxx_host *temp_p = NULL;
8508: struct aic7xxx_host *current_p = NULL;
8509: struct aic7xxx_host *list_p = NULL;
8510: int found = 0;
8511: #if defined(__i386__) || defined(__alpha__)
8512: ahc_flag_type flags = 0;
8513: int type;
8514: #endif
8515: unsigned char sxfrctl1;
8516: #if defined(__i386__) || defined(__alpha__)
8517: unsigned char hcntrl, hostconf;
8518: unsigned int slot, base;
8519: #endif
8520:
8521: #ifdef MODULE
8522: /*
8523: * If we are called as a module, the aic7xxx pointer may not be null
8524: * and it would point to our bootup string, just like on the lilo
8525: * command line. IF not NULL, then process this config string with
8526: * aic7xxx_setup
8527: */
8528: if(aic7xxx)
8529: aic7xxx_setup(aic7xxx, NULL);
8530: if(dummy_buffer[0] != 'P')
8531: printk(KERN_WARNING "aic7xxx: Please read the file /usr/src/linux/drivers"
8532: "/scsi/README.aic7xxx\n"
8533: "aic7xxx: to see the proper way to specify options to the aic7xxx "
8534: "module\n"
8535: "aic7xxx: Specifically, don't use any commas when passing arguments to\n"
8536: "aic7xxx: insmod or else it might trash certain memory areas.\n");
8537: #endif
8538:
8539: template->proc_dir = &proc_scsi_aic7xxx;
8540: template->sg_tablesize = AIC7XXX_MAX_SG;
8541:
8542:
8543: #if defined(__i386__) || defined(__alpha__)
8544: /*
8545: * EISA/VL-bus card signature probe.
8546: */
8547: slot = MINSLOT;
8548: while ( (slot <= MAXSLOT) && !(aic7xxx_no_probe) )
8549: {
8550: base = SLOTBASE(slot) + MINREG;
8551:
8552: if (check_region(base, MAXREG - MINREG))
8553: {
8554: /*
8555: * Some other driver has staked a
8556: * claim to this i/o region already.
8557: */
8558: slot++;
8559: continue; /* back to the beginning of the for loop */
8560: }
8561: flags = 0;
8562: type = aic7xxx_probe(slot, base + AHC_HID0, &flags);
8563: if (type == -1)
8564: {
8565: slot++;
8566: continue;
8567: }
8568: temp_p = kmalloc(sizeof(struct aic7xxx_host), GFP_ATOMIC);
8569: if (temp_p == NULL)
8570: {
8571: printk(KERN_WARNING "aic7xxx: Unable to allocate device space.\n");
8572: slot++;
8573: continue; /* back to the beginning of the while loop */
8574: }
8575: /*
8576: * Pause the card preserving the IRQ type. Allow the operator
8577: * to override the IRQ trigger.
8578: */
8579: if (aic7xxx_irq_trigger == 1)
8580: hcntrl = IRQMS; /* Level */
8581: else if (aic7xxx_irq_trigger == 0)
8582: hcntrl = 0; /* Edge */
8583: else
8584: hcntrl = inb(base + HCNTRL) & IRQMS; /* Default */
8585: memset(temp_p, 0, sizeof(struct aic7xxx_host));
8586: temp_p->unpause = hcntrl | INTEN;
8587: temp_p->pause = hcntrl | PAUSE | INTEN;
8588: temp_p->base = base;
8589: temp_p->mbase = 0;
8590: temp_p->maddr = 0;
8591: temp_p->pci_bus = 0;
8592: temp_p->pci_device_fn = slot;
8593: aic_outb(temp_p, hcntrl | PAUSE, HCNTRL);
8594: while( (aic_inb(temp_p, HCNTRL) & PAUSE) == 0 ) ;
8595: if (aic7xxx_chip_reset(temp_p) == -1)
8596: temp_p->irq = 0;
8597: else
8598: temp_p->irq = aic_inb(temp_p, INTDEF) & 0x0F;
8599: temp_p->flags |= AHC_PAGESCBS;
8600:
8601: switch (temp_p->irq)
8602: {
8603: case 9:
8604: case 10:
8605: case 11:
8606: case 12:
8607: case 14:
8608: case 15:
8609: break;
8610:
8611: default:
8612: printk(KERN_WARNING "aic7xxx: Host adapter uses unsupported IRQ "
8613: "level %d, ignoring.\n", temp_p->irq);
8614: kfree(temp_p);
8615: slot++;
8616: continue; /* back to the beginning of the while loop */
8617: }
8618:
8619: /*
8620: * We are commited now, everything has been checked and this card
8621: * has been found, now we just set it up
8622: */
8623:
8624: /*
8625: * Insert our new struct into the list at the end
8626: */
8627: if (list_p == NULL)
8628: {
8629: list_p = current_p = temp_p;
8630: }
8631: else
8632: {
8633: current_p = list_p;
8634: while (current_p->next != NULL)
8635: current_p = current_p->next;
8636: current_p->next = temp_p;
8637: }
8638: if (aic7xxx_extended)
8639: {
8640: temp_p->flags |= AHC_EXTEND_TRANS_A;
8641: if (temp_p->flags & AHC_MULTI_CHANNEL)
8642: temp_p->flags |= AHC_EXTEND_TRANS_B;
8643: }
8644:
8645: switch (type)
8646: {
8647: case 0:
8648: temp_p->board_name_index = 2;
8649: if (aic7xxx_verbose & VERBOSE_PROBE2)
8650: printk("aic7xxx: <%s> at EISA %d\n",
8651: board_names[2], slot);
8652: /* FALLTHROUGH */
8653: case 1:
8654: {
8655: temp_p->chip = AHC_AIC7770 | AHC_EISA;
8656: temp_p->features |= AHC_AIC7770_FE;
8657: temp_p->bios_control = aic_inb(temp_p, HA_274_BIOSCTRL);
8658:
8659: /*
8660: * Get the primary channel information. Right now we don't
8661: * do anything with this, but someday we will be able to inform
8662: * the mid-level SCSI code which channel is primary.
8663: */
8664: if (temp_p->board_name_index == 0)
8665: {
8666: temp_p->board_name_index = 3;
8667: if (aic7xxx_verbose & VERBOSE_PROBE2)
8668: printk("aic7xxx: <%s> at EISA %d\n",
8669: board_names[3], slot);
8670: }
8671: if (temp_p->bios_control & CHANNEL_B_PRIMARY)
8672: {
8673: temp_p->flags |= AHC_CHANNEL_B_PRIMARY;
8674: }
8675:
8676: if ((temp_p->bios_control & BIOSMODE) == BIOSDISABLED)
8677: {
8678: temp_p->flags &= ~AHC_BIOS_ENABLED;
8679: }
8680: else
8681: {
8682: temp_p->flags &= ~AHC_USEDEFAULTS;
8683: temp_p->flags |= AHC_BIOS_ENABLED;
8684: if ( (temp_p->bios_control & 0x20) == 0 )
8685: {
8686: temp_p->bios_address = 0xcc000;
8687: temp_p->bios_address += (0x4000 * (temp_p->bios_control & 0x07));
8688: }
8689: else
8690: {
8691: temp_p->bios_address = 0xd0000;
8692: temp_p->bios_address += (0x8000 * (temp_p->bios_control & 0x06));
8693: }
8694: }
8695: temp_p->adapter_control = aic_inb(temp_p, SCSICONF) << 8;
8696: temp_p->adapter_control |= aic_inb(temp_p, SCSICONF + 1);
8697: if (temp_p->features & AHC_WIDE)
8698: {
8699: temp_p->scsi_id = temp_p->adapter_control & HWSCSIID;
8700: temp_p->scsi_id_b = temp_p->scsi_id;
8701: }
8702: else
8703: {
8704: temp_p->scsi_id = (temp_p->adapter_control >> 8) & HSCSIID;
8705: temp_p->scsi_id_b = temp_p->adapter_control & HSCSIID;
8706: }
8707: aic7xxx_load_seeprom(temp_p, &sxfrctl1);
8708: break;
8709: }
8710:
8711: case 2:
8712: case 3:
8713: temp_p->chip = AHC_AIC7770 | AHC_VL;
8714: temp_p->features |= AHC_AIC7770_FE;
8715: if (type == 2)
8716: temp_p->flags |= AHC_BIOS_ENABLED;
8717: else
8718: temp_p->flags &= ~AHC_BIOS_ENABLED;
8719: if (aic_inb(temp_p, SCSICONF) & TERM_ENB)
8720: sxfrctl1 = STPWEN;
8721: aic7xxx_load_seeprom(temp_p, &sxfrctl1);
8722: temp_p->board_name_index = 4;
8723: if (aic7xxx_verbose & VERBOSE_PROBE2)
8724: printk("aic7xxx: <%s> at VLB %d\n",
8725: board_names[2], slot);
8726: switch( aic_inb(temp_p, STATUS_2840) & BIOS_SEL )
8727: {
8728: case 0x00:
8729: temp_p->bios_address = 0xe0000;
8730: break;
8731: case 0x20:
8732: temp_p->bios_address = 0xc8000;
8733: break;
8734: case 0x40:
8735: temp_p->bios_address = 0xd0000;
8736: break;
8737: case 0x60:
8738: temp_p->bios_address = 0xd8000;
8739: break;
8740: default:
8741: break; /* can't get here */
8742: }
8743: break;
8744:
8745: default: /* Won't get here. */
8746: break;
8747: }
8748: if (aic7xxx_verbose & VERBOSE_PROBE2)
8749: {
8750: printk(KERN_INFO "aic7xxx: BIOS %sabled, IO Port 0x%lx, IRQ %d (%s)\n",
8751: (temp_p->flags & AHC_USEDEFAULTS) ? "dis" : "en", temp_p->base,
8752: temp_p->irq,
8753: (temp_p->pause & IRQMS) ? "level sensitive" : "edge triggered");
8754: printk(KERN_INFO "aic7xxx: Extended translation %sabled.\n",
8755: (temp_p->flags & AHC_EXTEND_TRANS_A) ? "en" : "dis");
8756: }
8757:
8758: /*
8759: * Set the FIFO threshold and the bus off time.
8760: */
8761: hostconf = aic_inb(temp_p, HOSTCONF);
8762: aic_outb(temp_p, hostconf & DFTHRSH, BUSSPD);
8763: aic_outb(temp_p, (hostconf << 2) & BOFF, BUSTIME);
8764: slot++;
8765: found++;
8766: }
8767:
8768: #endif /* defined(__i386__) || defined(__alpha__) */
8769:
8770: #ifdef CONFIG_PCI
8771: /*
8772: * PCI-bus probe.
8773: */
8774: #if LINUX_VERSION_CODE > KERNEL_VERSION(2,1,92)
8775: if (pci_present())
8776: #else
8777: if (pcibios_present())
8778: #endif
8779: {
8780: struct
8781: {
8782: unsigned short vendor_id;
8783: unsigned short device_id;
8784: ahc_chip chip;
8785: ahc_flag_type flags;
8786: ahc_feature features;
8787: int board_name_index;
8788: unsigned short seeprom_size;
8789: unsigned short seeprom_type;
8790: } const aic_pdevs[] = {
8791: {PCI_VENDOR_ID_ADAPTEC, PCI_DEVICE_ID_ADAPTEC_7810, AHC_NONE,
8792: AHC_FNONE, AHC_FENONE, 1,
8793: 32, C46 },
8794: {PCI_VENDOR_ID_ADAPTEC, PCI_DEVICE_ID_ADAPTEC_7850, AHC_AIC7850,
8795: AHC_PAGESCBS, AHC_AIC7850_FE, 5,
8796: 32, C46 },
8797: {PCI_VENDOR_ID_ADAPTEC, PCI_DEVICE_ID_ADAPTEC_7855, AHC_AIC7850,
8798: AHC_PAGESCBS, AHC_AIC7850_FE, 6,
8799: 32, C46 },
8800: {PCI_VENDOR_ID_ADAPTEC, PCI_DEVICE_ID_ADAPTEC_7860, AHC_AIC7860,
8801: AHC_PAGESCBS | AHC_NEWEEPROM_FMT | AHC_BIOS_ENABLED,
8802: AHC_AIC7860_FE, 7,
8803: 32, C46 },
8804: {PCI_VENDOR_ID_ADAPTEC, PCI_DEVICE_ID_ADAPTEC_7861, AHC_AIC7860,
8805: AHC_PAGESCBS | AHC_NEWEEPROM_FMT | AHC_BIOS_ENABLED,
8806: AHC_AIC7860_FE, 8,
8807: 32, C46 },
8808: {PCI_VENDOR_ID_ADAPTEC, PCI_DEVICE_ID_ADAPTEC_7870, AHC_AIC7870,
8809: AHC_PAGESCBS | AHC_BIOS_ENABLED, AHC_AIC7870_FE, 9,
8810: 32, C46 },
8811: {PCI_VENDOR_ID_ADAPTEC, PCI_DEVICE_ID_ADAPTEC_7871, AHC_AIC7870,
8812: AHC_PAGESCBS | AHC_BIOS_ENABLED, AHC_AIC7870_FE, 10,
8813: 32, C46 },
8814: {PCI_VENDOR_ID_ADAPTEC, PCI_DEVICE_ID_ADAPTEC_7872, AHC_AIC7870,
8815: AHC_PAGESCBS | AHC_BIOS_ENABLED | AHC_MULTI_CHANNEL,
8816: AHC_AIC7870_FE, 11,
8817: 32, C56_66 },
8818: {PCI_VENDOR_ID_ADAPTEC, PCI_DEVICE_ID_ADAPTEC_7873, AHC_AIC7870,
8819: AHC_PAGESCBS | AHC_BIOS_ENABLED | AHC_MULTI_CHANNEL,
8820: AHC_AIC7870_FE, 12,
8821: 32, C56_66 },
8822: {PCI_VENDOR_ID_ADAPTEC, PCI_DEVICE_ID_ADAPTEC_7874, AHC_AIC7870,
8823: AHC_PAGESCBS | AHC_BIOS_ENABLED, AHC_AIC7870_FE, 13,
8824: 32, C46 },
8825: {PCI_VENDOR_ID_ADAPTEC, PCI_DEVICE_ID_ADAPTEC_7880, AHC_AIC7880,
8826: AHC_PAGESCBS | AHC_BIOS_ENABLED, AHC_AIC7880_FE, 14,
8827: 32, C46 },
8828: {PCI_VENDOR_ID_ADAPTEC, PCI_DEVICE_ID_ADAPTEC_7881, AHC_AIC7880,
8829: AHC_PAGESCBS | AHC_BIOS_ENABLED, AHC_AIC7880_FE, 15,
8830: 32, C46 },
8831: {PCI_VENDOR_ID_ADAPTEC, PCI_DEVICE_ID_ADAPTEC_7882, AHC_AIC7880,
8832: AHC_PAGESCBS | AHC_BIOS_ENABLED | AHC_MULTI_CHANNEL,
8833: AHC_AIC7880_FE, 16,
8834: 32, C56_66 },
8835: {PCI_VENDOR_ID_ADAPTEC, PCI_DEVICE_ID_ADAPTEC_7883, AHC_AIC7880,
8836: AHC_PAGESCBS | AHC_BIOS_ENABLED | AHC_MULTI_CHANNEL,
8837: AHC_AIC7880_FE, 17,
8838: 32, C56_66 },
8839: {PCI_VENDOR_ID_ADAPTEC, PCI_DEVICE_ID_ADAPTEC_7884, AHC_AIC7880,
8840: AHC_PAGESCBS | AHC_BIOS_ENABLED, AHC_AIC7880_FE, 18,
8841: 32, C46 },
8842: {PCI_VENDOR_ID_ADAPTEC, PCI_DEVICE_ID_ADAPTEC_7895, AHC_AIC7895,
8843: AHC_PAGESCBS | AHC_NEWEEPROM_FMT | AHC_BIOS_ENABLED | AHC_MULTI_CHANNEL,
8844: AHC_AIC7895_FE, 19,
8845: 32, C56_66 },
8846: {PCI_VENDOR_ID_ADAPTEC2, PCI_DEVICE_ID_ADAPTEC2_7890, AHC_AIC7890,
8847: AHC_PAGESCBS | AHC_NEWEEPROM_FMT | AHC_BIOS_ENABLED,
8848: AHC_AIC7890_FE, 20,
8849: 32, C46 },
8850: {PCI_VENDOR_ID_ADAPTEC2, PCI_DEVICE_ID_ADAPTEC2_2940U2, AHC_AIC7890,
8851: AHC_PAGESCBS | AHC_NEWEEPROM_FMT | AHC_BIOS_ENABLED,
8852: AHC_AIC7890_FE, 21,
8853: 32, C46 },
8854: {PCI_VENDOR_ID_ADAPTEC2, PCI_DEVICE_ID_ADAPTEC2_7896, AHC_AIC7896,
8855: AHC_PAGESCBS | AHC_NEWEEPROM_FMT | AHC_BIOS_ENABLED | AHC_MULTI_CHANNEL,
8856: AHC_AIC7896_FE, 22,
8857: 32, C56_66 },
8858: {PCI_VENDOR_ID_ADAPTEC2, PCI_DEVICE_ID_ADAPTEC2_3940U2, AHC_AIC7896,
8859: AHC_PAGESCBS | AHC_NEWEEPROM_FMT | AHC_BIOS_ENABLED | AHC_MULTI_CHANNEL,
8860: AHC_AIC7896_FE, 23,
8861: 32, C56_66 },
8862: };
8863:
8864: unsigned short command;
8865: unsigned int devconfig, i, oldverbose;
8866: #ifdef MMAPIO
8867: unsigned long page_offset, base;
8868: #endif
8869: #if LINUX_VERSION_CODE > KERNEL_VERSION(2,1,92)
8870: struct pci_dev *pdev = NULL;
8871: #else
8872: int index;
8873: unsigned int piobase, mmapbase;
8874: unsigned char pci_bus, pci_devfn, pci_irq;
8875: #endif
8876:
8877: for (i = 0; i < NUMBER(aic_pdevs); i++)
8878: {
8879: #if LINUX_VERSION_CODE > KERNEL_VERSION(2,1,92)
8880: pdev = NULL;
8881: while ((pdev = pci_find_device(aic_pdevs[i].vendor_id,
8882: aic_pdevs[i].device_id,
8883: pdev)))
8884: #else
8885: index = 0;
8886: while (!(pcibios_find_device(aic_pdevs[i].vendor_id,
8887: aic_pdevs[i].device_id,
8888: index++, &pci_bus, &pci_devfn)) )
8889: #endif
8890: {
8891: if ( i == 0 ) /* We found one, but it's the 7810 RAID cont. */
8892: {
8893: if (aic7xxx_verbose & (VERBOSE_PROBE|VERBOSE_PROBE2))
8894: {
8895: printk(KERN_INFO "aic7xxx: The 7810 RAID controller is not "
8896: "supported by\n");
8897: printk(KERN_INFO " this driver, we are ignoring it.\n");
8898: }
8899: }
8900: else if ( (temp_p = kmalloc(sizeof(struct aic7xxx_host),
8901: GFP_ATOMIC)) != NULL )
8902: {
8903: memset(temp_p, 0, sizeof(struct aic7xxx_host));
8904: temp_p->chip = aic_pdevs[i].chip | AHC_PCI;
8905: temp_p->flags = aic_pdevs[i].flags;
8906: temp_p->features = aic_pdevs[i].features;
8907: temp_p->board_name_index = aic_pdevs[i].board_name_index;
8908: temp_p->sc_size = aic_pdevs[i].seeprom_size;
8909: temp_p->sc_type = aic_pdevs[i].seeprom_type;
8910:
8911: /*
8912: * Read sundry information from PCI BIOS.
8913: */
8914: #if LINUX_VERSION_CODE > KERNEL_VERSION(2,1,92)
8915: temp_p->irq = pdev->irq;
8916: temp_p->pdev = pdev;
8917: temp_p->pci_bus = pdev->bus->number;
8918: temp_p->pci_device_fn = pdev->devfn;
8919: temp_p->base = pdev->base_address[0];
8920: temp_p->mbase = pdev->base_address[1];
8921: if (aic7xxx_verbose & VERBOSE_PROBE2)
8922: printk("aic7xxx: <%s> at PCI %d/%d\n",
8923: board_names[aic_pdevs[i].board_name_index],
8924: PCI_SLOT(temp_p->pdev->devfn),
8925: PCI_FUNC(temp_p->pdev->devfn));
8926: pci_read_config_word(pdev, PCI_COMMAND, &command);
8927: if (aic7xxx_verbose & VERBOSE_PROBE2)
8928: {
8929: printk("aic7xxx: Initial PCI_COMMAND value was 0x%x\n",
8930: (int)command);
8931: }
8932: #ifdef AIC7XXX_STRICT_PCI_SETUP
8933: command |= PCI_COMMAND_SERR | PCI_COMMAND_PARITY |
8934: PCI_COMMAND_INVALIDATE | PCI_COMMAND_MASTER |
8935: PCI_COMMAND_MEMORY | PCI_COMMAND_IO;
8936: #else
8937: command |= PCI_COMMAND_MASTER | PCI_COMMAND_MEMORY | PCI_COMMAND_IO;
8938: #endif
8939: if (aic7xxx_pci_parity == 0)
8940: command &= ~(PCI_COMMAND_SERR | PCI_COMMAND_PARITY);
8941: pci_write_config_word(pdev, PCI_COMMAND, command);
8942: #ifdef AIC7XXX_STRICT_PCI_SETUP
8943: pci_read_config_dword(pdev, DEVCONFIG, &devconfig);
8944: if (aic7xxx_verbose & VERBOSE_PROBE2)
8945: {
8946: printk("aic7xxx: Initial DEVCONFIG value was 0x%x\n", devconfig);
8947: }
8948: devconfig |= 0x80000000;
8949: if ((aic7xxx_pci_parity == 0) || (aic7xxx_pci_parity == -1))
8950: {
8951: devconfig &= ~(0x00000008);
8952: }
8953: else
8954: {
8955: devconfig |= 0x00000008;
8956: }
8957: pci_write_config_dword(pdev, DEVCONFIG, devconfig);
8958: #endif /* AIC7XXX_STRICT_PCI_SETUP */
8959: #else /* LINUX_VERSION_CODE > KERNEL_VERSION(2,1,92) */
8960: temp_p->pci_bus = pci_bus;
8961: temp_p->pci_device_fn = pci_devfn;
8962: if (aic7xxx_verbose & VERBOSE_PROBE2)
8963: printk("aic7xxx: <%s> at PCI %d/%d\n",
8964: board_names[aic_pdevs[i].board_name_index],
8965: PCI_SLOT(temp_p->pci_device_fn),
8966: PCI_FUNC(temp_p->pci_device_fn));
8967: pcibios_read_config_byte(pci_bus, pci_devfn, PCI_INTERRUPT_LINE,
8968: &pci_irq);
8969: temp_p->irq = pci_irq;
8970: pcibios_read_config_dword(pci_bus, pci_devfn, PCI_BASE_ADDRESS_0,
8971: &piobase);
8972: temp_p->base = piobase;
8973: pcibios_read_config_dword(pci_bus, pci_devfn, PCI_BASE_ADDRESS_1,
8974: &mmapbase);
8975: temp_p->mbase = mmapbase;
8976: pcibios_read_config_word(pci_bus, pci_devfn, PCI_COMMAND, &command);
8977: if (aic7xxx_verbose & VERBOSE_PROBE2)
8978: {
8979: printk("aic7xxx: Initial PCI_COMMAND value was 0x%x\n",
8980: (int)command);
8981: }
8982: #ifdef AIC7XXX_STRICT_PCI_SETUP
8983: command |= PCI_COMMAND_SERR | PCI_COMMAND_PARITY |
8984: PCI_COMMAND_INVALIDATE | PCI_COMMAND_MASTER |
8985: PCI_COMMAND_MEMORY | PCI_COMMAND_IO;
8986: #else
8987: command |= PCI_COMMAND_MASTER | PCI_COMMAND_MEMORY | PCI_COMMAND_IO;
8988: #endif
8989: if (aic7xxx_pci_parity == 0)
8990: command &= ~(PCI_COMMAND_SERR | PCI_COMMAND_PARITY);
8991: pcibios_write_config_word(pci_bus, pci_devfn, PCI_COMMAND, command);
8992: #ifdef AIC7XXX_STRICT_PCI_SETUP
8993: pcibios_read_config_dword(pci_bus, pci_devfn, DEVCONFIG, &devconfig);
8994: if (aic7xxx_verbose & VERBOSE_PROBE2)
8995: {
8996: printk("aic7xxx: Initial DEVCONFIG value was 0x%x\n", devconfig);
8997: }
8998: devconfig |= 0x80000000;
8999: if ((aic7xxx_pci_parity == 0) || (aic7xxx_pci_parity == -1))
9000: {
9001: devconfig &= ~(0x00000008);
9002: }
9003: else
9004: {
9005: devconfig |= 0x00000008;
9006: }
9007: pcibios_write_config_dword(pci_bus, pci_devfn, DEVCONFIG, devconfig);
9008: #endif /* AIC7XXX_STRICT_PCI_SETUP */
9009: #endif /* LINUIX_VERSION_CODE > KERNEL_VERSION(2,1,92) */
9010:
9011: /*
9012: * The first bit (LSB) of PCI_BASE_ADDRESS_0 is always set, so
9013: * we mask it off.
9014: */
9015: temp_p->base &= PCI_BASE_ADDRESS_IO_MASK;
9016: temp_p->mbase &= PCI_BASE_ADDRESS_MEM_MASK;
9017: temp_p->unpause = INTEN;
9018: temp_p->pause = temp_p->unpause | PAUSE;
9019:
9020: #ifdef MMAPIO
9021: base = temp_p->mbase & PAGE_MASK;
9022: page_offset = temp_p->mbase - base;
9023: #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,1,0)
9024: temp_p->maddr = ioremap_nocache(base, page_offset + 256);
9025: #else
9026: temp_p->maddr = vremap(base, page_offset + 256);
9027: #endif
9028: if(temp_p->maddr)
9029: {
9030: temp_p->maddr += page_offset;
9031: }
9032: #endif
9033:
9034: pause_sequencer(temp_p);
9035:
9036: /*
9037: * Clear out any pending PCI error status messages. Also set
9038: * verbose to 0 so that we don't emit strange PCI error messages
9039: * while cleaning out the current status bits.
9040: */
9041: oldverbose = aic7xxx_verbose;
9042: aic7xxx_verbose = 0;
9043: aic7xxx_pci_intr(temp_p);
9044: aic7xxx_verbose = oldverbose;
9045:
9046: temp_p->bios_address = 0;
9047:
9048: /*
9049: * Remember how the card was setup in case there is no seeprom.
9050: */
9051: if (temp_p->features & AHC_ULTRA2)
9052: temp_p->scsi_id = aic_inb(temp_p, SCSIID_ULTRA2) & OID;
9053: else
9054: temp_p->scsi_id = aic_inb(temp_p, SCSIID) & OID;
9055: /*
9056: * Get current termination setting
9057: */
9058: sxfrctl1 = aic_inb(temp_p, SXFRCTL1) & STPWEN;
9059:
9060: if (aic7xxx_chip_reset(temp_p) == -1)
9061: {
9062: kfree(temp_p);
9063: temp_p = NULL;
9064: continue;
9065: }
9066:
9067: /*
9068: * Doing a switch based upon i is really gross, but since Justin
9069: * changed around the chip ID stuff, we can't use that any more.
9070: * Since we don't scan the devices the same way as FreeBSD, we end
9071: * up doing this gross hack in order to avoid totally splitting
9072: * away from Justin's init code in ahc_pci.c
9073: */
9074: switch (i)
9075: {
9076: case 7: /* 3940 */
9077: case 12: /* 3940-Ultra */
9078: switch(PCI_SLOT(temp_p->pci_device_fn))
9079: {
9080: case 5:
9081: temp_p->flags |= AHC_CHNLB;
9082: break;
9083: default:
9084: break;
9085: }
9086: break;
9087:
9088: case 8: /* 3985 */
9089: case 13: /* 3985-Ultra */
9090: switch(PCI_SLOT(temp_p->pci_device_fn))
9091: {
9092: case 8:
9093: temp_p->flags |= AHC_CHNLB;
9094: break;
9095: case 12:
9096: temp_p->flags |= AHC_CHNLC;
9097: break;
9098: default:
9099: break;
9100: }
9101: break;
9102:
9103: case 15:
9104: case 18:
9105: case 19:
9106: #if LINUX_VERSION_CODE > KERNEL_VERSION(2,1,92)
9107: if (PCI_FUNC(temp_p->pdev->devfn) != 0)
9108: {
9109: temp_p->flags |= AHC_CHNLB;
9110: }
9111: /*
9112: * The 7895 is the only chipset that sets the SCBSIZE32 param
9113: * in the DEVCONFIG register. The Ultra2 chipsets use
9114: * the DSCOMMAND0 register instead.
9115: */
9116: if ((temp_p->chip & AHC_CHIPID_MASK) == AHC_AIC7895)
9117: {
9118: pci_read_config_dword(pdev, DEVCONFIG, &devconfig);
9119: devconfig |= SCBSIZE32;
9120: pci_write_config_dword(pdev, DEVCONFIG, devconfig);
9121: }
9122: #else
9123: if (PCI_FUNC(temp_p->pci_device_fn) != 0)
9124: {
9125: temp_p->flags |= AHC_CHNLB;
9126: }
9127: /*
9128: * The 7895 is the only chipset that sets the SCBSIZE32 param
9129: * in the DEVCONFIG register. The Ultra2 chipsets use
9130: * the DSCOMMAND0 register instead.
9131: */
9132: if ((temp_p->chip & AHC_CHIPID_MASK) == AHC_AIC7895)
9133: {
9134: pcibios_read_config_dword(pci_bus, pci_devfn, DEVCONFIG,
9135: &devconfig);
9136: devconfig |= SCBSIZE32;
9137: pcibios_write_config_dword(pci_bus, pci_devfn, DEVCONFIG,
9138: devconfig);
9139: }
9140: #endif
9141: break;
9142: default:
9143: break;
9144: }
9145:
9146: /*
9147: * Loading of the SEEPROM needs to come after we've set the flags
9148: * to indicate possible CHNLB and CHNLC assigments. Otherwise,
9149: * on 394x and 398x cards we'll end up reading the wrong settings
9150: * for channels B and C
9151: */
9152: switch (temp_p->chip & AHC_CHIPID_MASK)
9153: {
9154: case AHC_AIC7890:
9155: case AHC_AIC7896:
9156: aic_outb(temp_p, 0, SCAMCTL);
9157: /*
9158: * We used to set DPARCKEN in this register, but after talking
9159: * to a tech from Adaptec, I found out they don't use that
9160: * particular bit in their own register settings, and when you
9161: * combine that with the fact that I determined that we were
9162: * seeing Data-Path Parity Errors on things we shouldn't see
9163: * them on, I think there is a bug in the silicon and the way
9164: * to work around it is to disable this particular check. Also
9165: * This bug only showed up on certain commands, so it seems to
9166: * be pattern related or some such. The commands we would
9167: * typically send as a linux TEST_UNIT_READY or INQUIRY command
9168: * could cause it to be triggered, while regular commands that
9169: * actually made reasonable use of the SG array capabilities
9170: * seemed not to cause the problem.
9171: */
9172: /*
9173: aic_outb(temp_p, aic_inb(temp_p, DSCOMMAND0) |
9174: CACHETHEN | DPARCKEN | MPARCKEN |
9175: USCBSIZE32 | CIOPARCKEN,
9176: DSCOMMAND0);
9177: */
9178: aic_outb(temp_p, (aic_inb(temp_p, DSCOMMAND0) |
9179: CACHETHEN | MPARCKEN | USCBSIZE32 |
9180: CIOPARCKEN) & ~DPARCKEN, DSCOMMAND0);
9181: /* FALLTHROUGH */
9182: default:
9183: /*
9184: * We attempt to read a SEEPROM on *everything*. If we fail,
9185: * then we fail, but this covers things like 2910c cards that
9186: * now have SEEPROMs with their 7856 chipset that we would
9187: * otherwise ignore. They still don't have a BIOS, but they
9188: * have a SEEPROM that the SCSISelect utility on the Adaptec
9189: * diskettes can configure.
9190: */
9191: aic7xxx_load_seeprom(temp_p, &sxfrctl1);
9192: break;
9193: case AHC_AIC7850:
9194: case AHC_AIC7860:
9195: /*
9196: * Set the DSCOMMAND0 register on these cards different from
9197: * on the 789x cards. Also, read the SEEPROM as well.
9198: */
9199: aic_outb(temp_p, (aic_inb(temp_p, DSCOMMAND0) |
9200: CACHETHEN | MPARCKEN) & ~DPARCKEN,
9201: DSCOMMAND0);
9202: aic7xxx_load_seeprom(temp_p, &sxfrctl1);
9203: break;
9204: case AHC_AIC7880:
9205: /*
9206: * Only set the DSCOMMAND0 register if this is a Rev B.
9207: * chipset. For those, we also enable Ultra mode by
9208: * force due to brain-damage on the part of some BIOSes
9209: * We overload the devconfig variable here since we can.
9210: */
9211: #if LINUX_VERSION_CODE > KERNEL_VERSION(2,1,92)
9212: pci_read_config_dword(pdev, DEVCONFIG, &devconfig);
9213: #else
9214: pcibios_read_config_dword(pci_bus, pci_devfn, DEVCONFIG,
9215: &devconfig);
9216: #endif
9217: if ((devconfig & 0xff) >= 1)
9218: {
9219: aic_outb(temp_p, (aic_inb(temp_p, DSCOMMAND0) |
9220: CACHETHEN | MPARCKEN) & ~DPARCKEN,
9221: DSCOMMAND0);
9222: }
9223: aic7xxx_load_seeprom(temp_p, &sxfrctl1);
9224: break;
9225: }
9226:
9227:
9228: /*
9229: * and then we need another switch based on the type in order to
9230: * make sure the channel B primary flag is set properly on 7895
9231: * controllers....Arrrgggghhh!!! We also have to catch the fact
9232: * that when you disable the BIOS on the 7895 on the Intel DK440LX
9233: * motherboard, and possibly others, it only sets the BIOS disabled
9234: * bit on the A channel...I think I'm starting to lean towards
9235: * going postal....
9236: */
9237: switch(temp_p->chip & AHC_CHIPID_MASK)
9238: {
9239: case AHC_AIC7895:
9240: case AHC_AIC7896:
9241: current_p = list_p;
9242: while(current_p != NULL)
9243: {
9244: if ( (current_p->pci_bus == temp_p->pci_bus) &&
9245: (PCI_SLOT(current_p->pci_device_fn) ==
9246: PCI_SLOT(temp_p->pci_device_fn)) )
9247: {
9248: if ( PCI_FUNC(current_p->pci_device_fn) == 0 )
9249: {
9250: temp_p->flags |=
9251: (current_p->flags & AHC_CHANNEL_B_PRIMARY);
9252: temp_p->flags &= ~(AHC_BIOS_ENABLED|AHC_USEDEFAULTS);
9253: temp_p->flags |=
9254: (current_p->flags & (AHC_BIOS_ENABLED|AHC_USEDEFAULTS));
9255: }
9256: else
9257: {
9258: current_p->flags |=
9259: (temp_p->flags & AHC_CHANNEL_B_PRIMARY);
9260: current_p->flags &= ~(AHC_BIOS_ENABLED|AHC_USEDEFAULTS);
9261: current_p->flags |=
9262: (temp_p->flags & (AHC_BIOS_ENABLED|AHC_USEDEFAULTS));
9263: }
9264: }
9265: current_p = current_p->next;
9266: }
9267: break;
9268: default:
9269: break;
9270: }
9271:
9272: /*
9273: * We do another switch based on i so that we can exclude all
9274: * 3895 devices from the next option since the 3895 cards use
9275: * shared external SCB RAM while all other cards have dedicated
9276: * external SCB RAM per channel. Also exclude the 7850 and
9277: * 7860 based stuff since they can have garbage in the bit
9278: * that indicates external RAM and get some of this stuff
9279: * wrong as a result.
9280: */
9281: switch(temp_p->chip & AHC_CHIPID_MASK)
9282: {
9283: default:
9284: break;
9285: case AHC_AIC7895:
9286: case AHC_AIC7896:
9287: #if LINUX_VERSION_CODE > KERNEL_VERSION(2,1,92)
9288: pci_read_config_dword(pdev, DEVCONFIG, &devconfig);
9289: #else
9290: pcibios_read_config_dword(pci_bus, pci_devfn, DEVCONFIG,
9291: &devconfig);
9292: #endif
9293: if (temp_p->features & AHC_ULTRA2)
9294: {
9295: if (aic_inb(temp_p, DSCOMMAND0) & RAMPSM_ULTRA2)
9296: {
9297: aic_outb(temp_p,
9298: aic_inb(temp_p, DSCOMMAND0) & ~SCBRAMSEL_ULTRA2,
9299: DSCOMMAND0);
9300: temp_p->flags |= AHC_EXTERNAL_SRAM;
9301: devconfig |= EXTSCBPEN;
9302: }
9303: }
9304: else if (devconfig & RAMPSM)
9305: {
9306: devconfig &= ~SCBRAMSEL;
9307: devconfig |= EXTSCBPEN;
9308: temp_p->flags |= AHC_EXTERNAL_SRAM;
9309: }
9310: #if LINUX_VERSION_CODE > KERNEL_VERSION(2,1,92)
9311: pci_write_config_dword(pdev, DEVCONFIG, devconfig);
9312: #else
9313: pcibios_write_config_dword(pci_bus, pci_devfn, DEVCONFIG,
9314: devconfig);
9315: #endif
9316: if ( (temp_p->flags & AHC_EXTERNAL_SRAM) &&
9317: (temp_p->flags & AHC_CHNLB) )
9318: aic_outb(temp_p, 1, CCSCBBADDR);
9319: break;
9320: }
9321:
9322: /*
9323: * Take the LED out of diagnostic mode
9324: */
9325: aic_outb(temp_p,
9326: (aic_inb(temp_p, SBLKCTL) & ~(DIAGLEDEN | DIAGLEDON)),
9327: SBLKCTL);
9328:
9329: /*
9330: * We don't know where this is set in the SEEPROM or by the
9331: * BIOS, so we default to 100%. On Ultra2 controllers, use 75%
9332: * instead.
9333: */
9334: if (temp_p->features & AHC_ULTRA2)
9335: {
9336: aic_outb(temp_p, RD_DFTHRSH_75 | WR_DFTHRSH_75, DFF_THRSH);
9337: }
9338: else
9339: {
9340: aic_outb(temp_p, DFTHRSH_100, DSPCISTATUS);
9341: }
9342:
9343: if (aic7xxx_extended)
9344: temp_p->flags |= AHC_EXTEND_TRANS_A;
9345:
9346: if ( list_p == NULL )
9347: {
9348: list_p = current_p = temp_p;
9349: }
9350: else
9351: {
9352: current_p = list_p;
9353: while(current_p->next != NULL)
9354: current_p = current_p->next;
9355: current_p->next = temp_p;
9356: }
9357: temp_p->next = NULL;
9358: found++;
9359: } /* Found an Adaptec PCI device. */
9360: else /* Well, we found one, but we couldn't get any memory */
9361: {
9362: printk("aic7xxx: Found <%s>\n",
9363: board_names[aic_pdevs[i].board_name_index]);
9364: printk(KERN_INFO "aic7xxx: Unable to allocate device memory, "
9365: "skipping.\n");
9366: }
9367: } /* while(pdev=....) */
9368: } /* for PCI_DEVICES */
9369: } /* PCI BIOS present */
9370: #endif CONFIG_PCI
9371: /*
9372: * Now, we re-order the probed devices by BIOS address and BUS class.
9373: * In general, we follow this algorithm to make the adapters show up
9374: * in the same order under linux that the computer finds them.
9375: * 1: All VLB/EISA cards with BIOS_ENABLED first, according to BIOS
9376: * address, going from lowest to highest.
9377: * 2: All PCI controllers with BIOS_ENABLED next, according to BIOS
9378: * address, going from lowest to highest.
9379: * 3: Remaining VLB/EISA controllers going in slot order.
9380: * 4: Remaining PCI controllers, going in PCI device order (reversable)
9381: */
9382:
9383: {
9384: struct aic7xxx_host *sort_list[4] = { NULL, NULL, NULL, NULL };
9385: struct aic7xxx_host *vlb, *pci;
9386: struct aic7xxx_host *prev_p;
9387: struct aic7xxx_host *p;
9388: unsigned char left;
9389:
9390: prev_p = vlb = pci = NULL;
9391:
9392: temp_p = list_p;
9393: while (temp_p != NULL)
9394: {
9395: switch(temp_p->chip & ~AHC_CHIPID_MASK)
9396: {
9397: case AHC_EISA:
9398: case AHC_VL:
9399: {
9400: p = temp_p;
9401: if (p->flags & AHC_BIOS_ENABLED)
9402: vlb = sort_list[0];
9403: else
9404: vlb = sort_list[2];
9405:
9406: if (vlb == NULL)
9407: {
9408: vlb = temp_p;
9409: temp_p = temp_p->next;
9410: vlb->next = NULL;
9411: }
9412: else
9413: {
9414: current_p = vlb;
9415: prev_p = NULL;
9416: while ( (current_p != NULL) &&
9417: (current_p->bios_address < temp_p->bios_address))
9418: {
9419: prev_p = current_p;
9420: current_p = current_p->next;
9421: }
9422: if (prev_p != NULL)
9423: {
9424: prev_p->next = temp_p;
9425: temp_p = temp_p->next;
9426: prev_p->next->next = current_p;
9427: }
9428: else
9429: {
9430: vlb = temp_p;
9431: temp_p = temp_p->next;
9432: vlb->next = current_p;
9433: }
9434: }
9435:
9436: if (p->flags & AHC_BIOS_ENABLED)
9437: sort_list[0] = vlb;
9438: else
9439: sort_list[2] = vlb;
9440:
9441: break;
9442: }
9443: default: /* All PCI controllers fall through to default */
9444: {
9445:
9446: p = temp_p;
9447: if (p->flags & AHC_BIOS_ENABLED)
9448: pci = sort_list[1];
9449: else
9450: pci = sort_list[3];
9451:
9452: if (pci == NULL)
9453: {
9454: pci = temp_p;
9455: temp_p = temp_p->next;
9456: pci->next = NULL;
9457: }
9458: else
9459: {
9460: current_p = pci;
9461: prev_p = NULL;
9462: if (!aic7xxx_reverse_scan)
9463: {
9464: while ( (current_p != NULL) &&
9465: ( (PCI_SLOT(current_p->pci_device_fn) |
9466: (current_p->pci_bus << 8)) <
9467: (PCI_SLOT(temp_p->pci_device_fn) |
9468: (temp_p->pci_bus << 8)) ) )
9469: {
9470: prev_p = current_p;
9471: current_p = current_p->next;
9472: }
9473: }
9474: else
9475: {
9476: while ( (current_p != NULL) &&
9477: ( (PCI_SLOT(current_p->pci_device_fn) |
9478: (current_p->pci_bus << 8)) >
9479: (PCI_SLOT(temp_p->pci_device_fn) |
9480: (temp_p->pci_bus << 8)) ) )
9481: {
9482: prev_p = current_p;
9483: current_p = current_p->next;
9484: }
9485: }
9486: /*
9487: * Are we dealing with a 7985 where we need to sort the
9488: * channels as well, if so, the bios_address values should
9489: * be the same
9490: */
9491: if ( (current_p) && (temp_p->flags & AHC_MULTI_CHANNEL) &&
9492: (temp_p->pci_bus == current_p->pci_bus) &&
9493: (PCI_SLOT(temp_p->pci_device_fn) ==
9494: PCI_SLOT(current_p->pci_device_fn)) )
9495: {
9496: if (temp_p->flags & AHC_CHNLB)
9497: {
9498: if ( !(temp_p->flags & AHC_CHANNEL_B_PRIMARY) )
9499: {
9500: prev_p = current_p;
9501: current_p = current_p->next;
9502: }
9503: }
9504: else
9505: {
9506: if (temp_p->flags & AHC_CHANNEL_B_PRIMARY)
9507: {
9508: prev_p = current_p;
9509: current_p = current_p->next;
9510: }
9511: }
9512: }
9513: if (prev_p != NULL)
9514: {
9515: prev_p->next = temp_p;
9516: temp_p = temp_p->next;
9517: prev_p->next->next = current_p;
9518: }
9519: else
9520: {
9521: pci = temp_p;
9522: temp_p = temp_p->next;
9523: pci->next = current_p;
9524: }
9525: }
9526:
9527: if (p->flags & AHC_BIOS_ENABLED)
9528: sort_list[1] = pci;
9529: else
9530: sort_list[3] = pci;
9531:
9532: break;
9533: }
9534: } /* End of switch(temp_p->type) */
9535: } /* End of while (temp_p != NULL) */
9536: /*
9537: * At this point, the cards have been broken into 4 sorted lists, now
9538: * we run through the lists in order and register each controller
9539: */
9540: {
9541: int i;
9542:
9543: left = found;
9544: for (i=0; i<NUMBER(sort_list); i++)
9545: {
9546: temp_p = sort_list[i];
9547: while(temp_p != NULL)
9548: {
9549: template->name = board_names[temp_p->board_name_index];
9550: p = aic7xxx_alloc(template, temp_p);
9551: if (p != NULL)
9552: {
9553: p->instance = found - left;
9554: if (aic7xxx_register(template, p, (--left)) == 0)
9555: {
9556: found--;
9557: aic7xxx_release(p->host);
9558: scsi_unregister(p->host);
9559: }
9560: else if (aic7xxx_dump_card)
9561: {
9562: pause_sequencer(p);
9563: aic7xxx_print_card(p);
9564: aic7xxx_print_scratch_ram(p);
9565: unpause_sequencer(p, TRUE);
9566: }
9567: }
9568: current_p = temp_p;
9569: temp_p = (struct aic7xxx_host *)temp_p->next;
9570: kfree(current_p);
9571: }
9572: }
9573: }
9574: }
9575: return (found);
9576: }
9577:
9578: #ifdef AIC7XXX_FAKE_NEGOTIATION_CMDS
9579:
9580: /*+F*************************************************************************
9581: * Function:
9582: * aic7xxx_negotiation_complete
9583: *
9584: * Description:
9585: * Handle completion events for our Negotiation commands. Clear out the
9586: * struct and get it ready for its next use.
9587: *-F*************************************************************************/
9588: static void
9589: aic7xxx_negotiation_complete(Scsi_Cmnd *cmd)
9590: {
9591: return;
9592: }
9593:
9594: /*+F*************************************************************************
9595: * Function:
9596: * aic7xxx_build_negotiation_command
9597: *
9598: * Description:
9599: * Build a Scsi_Cmnd structure to perform negotiation with or else send
9600: * a pre-built command specifically for this purpose.
9601: *-F*************************************************************************/
9602: static void
9603: aic7xxx_build_negotiation_cmnd(struct aic7xxx_host *p, Scsi_Cmnd *old_cmd,
9604: int tindex)
9605: {
9606:
9607: if ( (p->needwdtr & (1<<tindex)) && !(p->wdtr_pending & (1<<tindex)) )
9608: {
9609: if(p->dev_wdtr_cmnd[tindex] == NULL)
9610: {
9611: Scsi_Cmnd *cmd;
9612:
9613: if (!(p->dev_wdtr_cmnd[tindex] = kmalloc(sizeof(Scsi_Cmnd), GFP_ATOMIC)) )
9614: {
9615: return;
9616: }
9617: cmd = p->dev_wdtr_cmnd[tindex];
9618: memset(cmd, 0, sizeof(Scsi_Cmnd));
9619: memcpy(cmd, old_cmd, sizeof(Scsi_Cmnd));
9620: memset(&cmd->cmnd[0], 0, sizeof(cmd->cmnd));
9621: memset(&cmd->data_cmnd[0], 0, sizeof(cmd->data_cmnd));
9622: cmd->lun = 0;
9623: cmd->request_bufflen = 0;
9624: cmd->request_buffer = NULL;
9625: cmd->use_sg = cmd->old_use_sg = cmd->sglist_len = 0;
9626: cmd->bufflen = 0;
9627: cmd->buffer = NULL;
9628: cmd->underflow = 0;
9629: cmd->cmd_len = 6;
9630: }
9631: /*
9632: * Before sending this thing out, we also amke the cmd->next pointer
9633: * point to the real command so we can stuff any possible SENSE data
9634: * intp the real command instead of this fake command. This has to be
9635: * done each time the command is built, not just the first time, hence
9636: * it's outside of the above if()...
9637: */
9638: p->dev_wdtr_cmnd[tindex]->next = old_cmd;
9639: aic7xxx_queue(p->dev_wdtr_cmnd[tindex],
9640: aic7xxx_negotiation_complete);
9641: }
9642: else if ( (p->needsdtr & (1<<tindex)) && !(p->sdtr_pending & (1<<tindex)) &&
9643: !(p->wdtr_pending & (1<<tindex)) )
9644: {
9645: if(p->dev_sdtr_cmnd[tindex] == NULL)
9646: {
9647: Scsi_Cmnd *cmd;
9648:
9649: if (!(p->dev_sdtr_cmnd[tindex] = kmalloc(sizeof(Scsi_Cmnd), GFP_ATOMIC)) )
9650: {
9651: return;
9652: }
9653: cmd = p->dev_sdtr_cmnd[tindex];
9654: memset(cmd, 0, sizeof(Scsi_Cmnd));
9655: memcpy(cmd, old_cmd, sizeof(Scsi_Cmnd));
9656: memset(&cmd->cmnd[0], 0, sizeof(cmd->cmnd));
9657: memset(&cmd->data_cmnd[0], 0, sizeof(cmd->data_cmnd));
9658: cmd->lun = 0;
9659: cmd->request_bufflen = 0;
9660: cmd->request_buffer = NULL;
9661: cmd->use_sg = cmd->old_use_sg = cmd->sglist_len = 0;
9662: cmd->bufflen = 0;
9663: cmd->buffer = NULL;
9664: cmd->underflow = 0;
9665: cmd->cmd_len = 6;
9666: }
9667: /*
9668: * Before sending this thing out, we also amke the cmd->next pointer
9669: * point to the real command so we can stuff any possible SENSE data
9670: * intp the real command instead of this fake command. This has to be
9671: * done each time the command is built, not just the first time, hence
9672: * it's outside of the above if()...
9673: */
9674: p->dev_sdtr_cmnd[tindex]->next = old_cmd;
9675: aic7xxx_queue(p->dev_sdtr_cmnd[tindex],
9676: aic7xxx_negotiation_complete);
9677: }
9678: }
9679:
9680: #endif
9681:
9682: #ifdef AIC7XXX_VERBOSE_DEBUGGING
9683: /*+F*************************************************************************
9684: * Function:
9685: * aic7xxx_print_scb
9686: *
9687: * Description:
9688: * Dump the byte codes for an about to be sent SCB.
9689: *-F*************************************************************************/
9690: static void
9691: aic7xxx_print_scb(struct aic7xxx_host *p, struct aic7xxx_scb *scb)
9692: {
9693: int i;
9694: unsigned char *x;
9695:
9696: x = (unsigned char *)&scb->hscb->control;
9697:
9698: for(i=0; i<32; i++)
9699: {
9700: printk("%02x ", x[i]);
9701: }
9702: printk("\n");
9703: }
9704: #endif
9705:
9706: /*+F*************************************************************************
9707: * Function:
9708: * aic7xxx_buildscb
9709: *
9710: * Description:
9711: * Build a SCB.
9712: *-F*************************************************************************/
9713: static void
9714: aic7xxx_buildscb(struct aic7xxx_host *p, Scsi_Cmnd *cmd,
9715: struct aic7xxx_scb *scb)
9716: {
9717: unsigned short mask;
9718: struct aic7xxx_hwscb *hscb;
9719:
9720: mask = (0x01 << TARGET_INDEX(cmd));
9721: hscb = scb->hscb;
9722:
9723: /*
9724: * Setup the control byte if we need negotiation and have not
9725: * already requested it.
9726: */
9727: hscb->control = 0;
9728: scb->tag_action = 0;
9729: if (p->discenable & mask)
9730: {
9731: hscb->control |= DISCENB;
9732: if (p->tagenable & mask)
9733: {
9734: cmd->tag = hscb->tag;
9735: p->dev_commands_sent[TARGET_INDEX(cmd)]++;
9736: if (p->dev_commands_sent[TARGET_INDEX(cmd)] < 200)
9737: {
9738: hscb->control |= MSG_SIMPLE_Q_TAG;
9739: scb->tag_action = MSG_SIMPLE_Q_TAG;
9740: }
9741: else
9742: {
9743: if (p->orderedtag & mask)
9744: {
9745: hscb->control |= MSG_ORDERED_Q_TAG;
9746: scb->tag_action = MSG_ORDERED_Q_TAG;
9747: }
9748: else
9749: {
9750: hscb->control |= MSG_SIMPLE_Q_TAG;
9751: scb->tag_action = MSG_SIMPLE_Q_TAG;
9752: }
9753: p->dev_commands_sent[TARGET_INDEX(cmd)] = 0;
9754: }
9755: }
9756: }
9757: if (p->dev_flags[TARGET_INDEX(cmd)] & DEVICE_SCANNED)
9758: {
9759: #ifdef AIC7XXX_FAKE_NEGOTIATION_CMDS
9760: if ( (p->needwdtr & mask) && !(p->wdtr_pending & mask) )
9761: {
9762: if (cmd == p->dev_wdtr_cmnd[TARGET_INDEX(cmd)])
9763: {
9764: p->wdtr_pending |= mask;
9765: scb->flags |= SCB_MSGOUT_WDTR;
9766: hscb->control &= DISCENB;
9767: hscb->control |= MK_MESSAGE;
9768: scb->tag_action = 0;
9769: }
9770: else
9771: {
9772: aic7xxx_build_negotiation_cmnd(p, cmd, TARGET_INDEX(cmd));
9773: }
9774: }
9775: else if ( (p->needsdtr & mask) && !(p->sdtr_pending & mask) &&
9776: !(p->wdtr_pending & mask) )
9777: {
9778: if (cmd == p->dev_sdtr_cmnd[TARGET_INDEX(cmd)])
9779: {
9780: p->sdtr_pending |= mask;
9781: scb->flags |= SCB_MSGOUT_SDTR;
9782: hscb->control &= DISCENB;
9783: hscb->control |= MK_MESSAGE;
9784: scb->tag_action = 0;
9785: }
9786: else if (cmd != p->dev_wdtr_cmnd[TARGET_INDEX(cmd)])
9787: {
9788: aic7xxx_build_negotiation_cmnd(p, cmd, TARGET_INDEX(cmd));
9789: }
9790: }
9791: #else
9792: if ( (p->needwdtr & mask) && !(p->wdtr_pending & mask) &&
9793: !(p->sdtr_pending & mask) && (cmd->lun == 0) )
9794: {
9795: p->wdtr_pending |= mask;
9796: scb->flags |= SCB_MSGOUT_WDTR;
9797: hscb->control &= DISCENB;
9798: hscb->control |= MK_MESSAGE;
9799: scb->tag_action = 0;
9800: #ifdef AIC7XXX_VERBOSE_DEBUGGING
9801: if (aic7xxx_verbose > 0xffff)
9802: printk(INFO_LEAD "Building WDTR command.\n", p->host_no,
9803: CTL_OF_CMD(cmd));
9804: #endif
9805: }
9806: else if ( (p->needsdtr & mask) && !(p->wdtr_pending & mask) &&
9807: !(p->sdtr_pending & mask) && (cmd->lun == 0) )
9808: {
9809: p->sdtr_pending |= mask;
9810: scb->flags |= SCB_MSGOUT_SDTR;
9811: hscb->control &= DISCENB;
9812: hscb->control |= MK_MESSAGE;
9813: scb->tag_action = 0;
9814: #ifdef AIC7XXX_VERBOSE_DEBUGGING
9815: if (aic7xxx_verbose > 0xffff)
9816: printk(INFO_LEAD "Building SDTR command.\n", p->host_no,
9817: CTL_OF_CMD(cmd));
9818: #endif
9819: }
9820: #endif
9821: }
9822: hscb->target_channel_lun = ((cmd->target << 4) & 0xF0) |
9823: ((cmd->channel & 0x01) << 3) | (cmd->lun & 0x07);
9824:
9825: /*
9826: * The interpretation of request_buffer and request_bufflen
9827: * changes depending on whether or not use_sg is zero; a
9828: * non-zero use_sg indicates the number of elements in the
9829: * scatter-gather array.
9830: */
9831:
9832: /*
9833: * XXX - this relies on the host data being stored in a
9834: * little-endian format.
9835: */
9836: hscb->SCSI_cmd_length = cmd->cmd_len;
9837: hscb->SCSI_cmd_pointer = cpu_to_le32(VIRT_TO_BUS(cmd->cmnd));
9838:
9839: if (cmd->use_sg)
9840: {
9841: struct scatterlist *sg; /* Must be mid-level SCSI code scatterlist */
9842:
9843: /*
9844: * We must build an SG list in adapter format, as the kernel's SG list
9845: * cannot be used directly because of data field size (__alpha__)
9846: * differences and the kernel SG list uses virtual addresses where
9847: * we need physical addresses.
9848: */
9849: int i;
9850:
9851: sg = (struct scatterlist *)cmd->request_buffer;
9852: scb->sg_length = 0;
9853: /*
9854: * Copy the segments into the SG array. NOTE!!! - We used to
9855: * have the first entry both in the data_pointer area and the first
9856: * SG element. That has changed somewhat. We still have the first
9857: * entry in both places, but now we download the address of
9858: * scb->sg_list[1] instead of 0 to the sg pointer in the hscb.
9859: */
9860: for (i = 0; i < cmd->use_sg; i++)
9861: {
9862: scb->sg_list[i].address = cpu_to_le32(VIRT_TO_BUS(sg[i].address));
9863: scb->sg_list[i].length = cpu_to_le32(sg[i].length);
9864: scb->sg_length += sg[i].length;
9865: }
9866: /* Copy the first SG into the data pointer area. */
9867: hscb->data_pointer = scb->sg_list[0].address;
9868: hscb->data_count = scb->sg_list[0].length;
9869: scb->sg_count = cmd->use_sg;
9870: hscb->SG_segment_count = cmd->use_sg;
9871: hscb->SG_list_pointer = cpu_to_le32(VIRT_TO_BUS(&scb->sg_list[1]));
9872:
9873: }
9874: else
9875: {
9876: if (cmd->request_bufflen)
9877: {
9878: scb->sg_count = 1;
9879: scb->sg_list[0].address = cpu_to_le32(VIRT_TO_BUS(cmd->request_buffer));
9880: scb->sg_list[0].length = cpu_to_le32(cmd->request_bufflen);
9881: scb->sg_length = cmd->request_bufflen;
9882: hscb->SG_segment_count = 1;
9883: hscb->SG_list_pointer = cpu_to_le32(VIRT_TO_BUS(&scb->sg_list[0]));
9884: hscb->data_count = scb->sg_list[0].length;
9885: hscb->data_pointer = scb->sg_list[0].address;
9886: }
9887: else
9888: {
9889: scb->sg_count = 0;
9890: scb->sg_length = 0;
9891: hscb->SG_segment_count = 0;
9892: hscb->SG_list_pointer = 0;
9893: hscb->data_count = 0;
9894: hscb->data_pointer = 0;
9895: }
9896: }
9897: #ifdef AIC7XXX_VERBOSE_DEBUGGING
9898: if((cmd->cmnd[0] == TEST_UNIT_READY) && (aic7xxx_verbose & VERBOSE_PROBE2))
9899: {
9900: aic7xxx_print_scb(p, scb);
9901: }
9902: #endif
9903: }
9904:
9905: /*+F*************************************************************************
9906: * Function:
9907: * aic7xxx_queue
9908: *
9909: * Description:
9910: * Queue a SCB to the controller.
9911: *-F*************************************************************************/
9912: int
9913: aic7xxx_queue(Scsi_Cmnd *cmd, void (*fn)(Scsi_Cmnd *))
9914: {
9915: struct aic7xxx_host *p;
9916: struct aic7xxx_scb *scb;
9917: #ifdef AIC7XXX_VERBOSE_DEBUGGING
9918: int tindex = TARGET_INDEX(cmd);
9919: #endif
9920: #if LINUX_VERSION_CODE < KERNEL_VERSION(2,1,95)
9921: unsigned long cpu_flags = 0;
9922: #endif
9923:
9924: p = (struct aic7xxx_host *) cmd->host->hostdata;
9925: /*
9926: * Check to see if channel was scanned.
9927: */
9928:
9929: #ifdef AIC7XXX_VERBOSE_DEBUGGING
9930: if (!(p->flags & AHC_A_SCANNED) && (cmd->channel == 0))
9931: {
9932: if (aic7xxx_verbose & VERBOSE_PROBE2)
9933: printk(INFO_LEAD "Scanning channel for devices.\n",
9934: p->host_no, 0, -1, -1);
9935: p->flags |= AHC_A_SCANNED;
9936: }
9937: else
9938: {
9939: if (!(p->flags & AHC_B_SCANNED) && (cmd->channel == 1))
9940: {
9941: if (aic7xxx_verbose & VERBOSE_PROBE2)
9942: printk(INFO_LEAD "Scanning channel for devices.\n",
9943: p->host_no, 1, -1, -1);
9944: p->flags |= AHC_B_SCANNED;
9945: }
9946: }
9947:
9948: if (p->dev_active_cmds[tindex] > (cmd->device->queue_depth + 1))
9949: {
9950: printk(WARN_LEAD "Commands queued exceeds queue "
9951: "depth, active=%d\n",
9952: p->host_no, CTL_OF_CMD(cmd),
9953: p->dev_active_cmds[tindex]);
9954: if ( p->dev_active_cmds[tindex] > 220 )
9955: p->dev_active_cmds[tindex] = 0;
9956: }
9957: #endif
9958:
9959: scb = scbq_remove_head(&p->scb_data->free_scbs);
9960: if (scb == NULL)
9961: {
9962: DRIVER_LOCK
9963: aic7xxx_allocate_scb(p);
9964: DRIVER_UNLOCK
9965: scb = scbq_remove_head(&p->scb_data->free_scbs);
9966: }
9967: if (scb == NULL)
9968: {
9969: printk(WARN_LEAD "Couldn't get a free SCB.\n", p->host_no,
9970: CTL_OF_CMD(cmd));
9971: cmd->result = (DID_BUS_BUSY << 16);
9972: DRIVER_LOCK
9973: aic7xxx_queue_cmd_complete(p, cmd);
9974: DRIVER_UNLOCK
9975: return 0;
9976: }
9977: else
9978: {
9979: scb->cmd = cmd;
9980: aic7xxx_position(cmd) = scb->hscb->tag;
9981:
9982: /*
9983: * Construct the SCB beforehand, so the sequencer is
9984: * paused a minimal amount of time.
9985: */
9986: aic7xxx_buildscb(p, cmd, scb);
9987:
9988: /*
9989: * Make sure the Scsi_Cmnd pointer is saved, the struct it points to
9990: * is set up properly, and the parity error flag is reset, then send
9991: * the SCB to the sequencer and watch the fun begin.
9992: */
9993: cmd->scsi_done = fn;
9994: cmd->result = DID_OK;
9995: memset(cmd->sense_buffer, 0, sizeof(cmd->sense_buffer));
9996: aic7xxx_error(cmd) = DID_OK;
9997: aic7xxx_status(cmd) = 0;
9998: cmd->host_scribble = NULL;
9999:
10000: scb->flags |= SCB_ACTIVE | SCB_WAITINGQ;
10001:
10002: DRIVER_LOCK
10003: scbq_insert_tail(&p->waiting_scbs, scb);
10004: if ( (p->flags & (AHC_IN_ISR | AHC_IN_ABORT | AHC_IN_RESET)) == 0)
10005: {
10006: aic7xxx_run_waiting_queues(p);
10007: }
10008: DRIVER_UNLOCK
10009: }
10010: return (0);
10011: }
10012:
10013: /*+F*************************************************************************
10014: * Function:
10015: * aic7xxx_bus_device_reset
10016: *
10017: * Description:
10018: * Abort or reset the current SCSI command(s). If the scb has not
10019: * previously been aborted, then we attempt to send a BUS_DEVICE_RESET
10020: * message to the target. If the scb has previously been unsuccessfully
10021: * aborted, then we will reset the channel and have all devices renegotiate.
10022: * Returns an enumerated type that indicates the status of the operation.
10023: *-F*************************************************************************/
10024: static int
10025: aic7xxx_bus_device_reset(struct aic7xxx_host *p, Scsi_Cmnd *cmd)
10026: {
10027: struct aic7xxx_scb *scb;
10028: struct aic7xxx_hwscb *hscb;
10029: int result = -1;
10030: int channel;
10031: unsigned char saved_scbptr, lastphase;
10032: unsigned char hscb_index;
10033: int disconnected;
10034:
10035: scb = (p->scb_data->scb_array[aic7xxx_position(cmd)]);
10036: hscb = scb->hscb;
10037:
10038: lastphase = aic_inb(p, LASTPHASE);
10039: if (aic7xxx_verbose & VERBOSE_RESET_PROCESS)
10040: {
10041: printk(INFO_LEAD "Bus Device reset, scb flags 0x%x, ",
10042: p->host_no, CTL_OF_SCB(scb), scb->flags);
10043: switch (lastphase)
10044: {
10045: case P_DATAOUT:
10046: printk("Data-Out phase\n");
10047: break;
10048: case P_DATAIN:
10049: printk("Data-In phase\n");
10050: break;
10051: case P_COMMAND:
10052: printk("Command phase\n");
10053: break;
10054: case P_MESGOUT:
10055: printk("Message-Out phase\n");
10056: break;
10057: case P_STATUS:
10058: printk("Status phase\n");
10059: break;
10060: case P_MESGIN:
10061: printk("Message-In phase\n");
10062: break;
10063: default:
10064: /*
10065: * We're not in a valid phase, so assume we're idle.
10066: */
10067: printk("while idle, LASTPHASE = 0x%x\n", lastphase);
10068: break;
10069: }
10070: printk(INFO_LEAD "SCSISIGI 0x%x, SEQADDR 0x%x, SSTAT0 0x%x, SSTAT1 "
10071: "0x%x\n", p->host_no, CTL_OF_SCB(scb),
10072: aic_inb(p, SCSISIGI),
10073: aic_inb(p, SEQADDR0) | (aic_inb(p, SEQADDR1) << 8),
10074: aic_inb(p, SSTAT0), aic_inb(p, SSTAT1));
10075: }
10076:
10077: channel = cmd->channel;
10078:
10079: /*
10080: * Send a Device Reset Message:
10081: * The target that is holding up the bus may not be the same as
10082: * the one that triggered this timeout (different commands have
10083: * different timeout lengths). Our strategy here is to queue an
10084: * abort message to the timed out target if it is disconnected.
10085: * Otherwise, if we have an active target we stuff the message buffer
10086: * with an abort message and assert ATN in the hopes that the target
10087: * will let go of the bus and go to the mesgout phase. If this
10088: * fails, we'll get another timeout a few seconds later which will
10089: * attempt a bus reset.
10090: */
10091: saved_scbptr = aic_inb(p, SCBPTR);
10092: disconnected = FALSE;
10093:
10094: if (lastphase != P_BUSFREE)
10095: {
10096: if (aic_inb(p, SCB_TAG) >= p->scb_data->numscbs)
10097: {
10098: printk(WARN_LEAD "Invalid SCB ID %d is active, "
10099: "SCB flags = 0x%x.\n", p->host_no,
10100: CTL_OF_CMD(cmd), scb->hscb->tag, scb->flags);
10101: return(SCSI_RESET_ERROR);
10102: }
10103: if (scb->hscb->tag == aic_inb(p, SCB_TAG))
10104: {
10105: if ( (lastphase != P_MESGOUT) && (lastphase != P_MESGIN) )
10106: {
10107: if (aic7xxx_verbose & VERBOSE_RESET_PROCESS)
10108: printk(INFO_LEAD "Device reset message in "
10109: "message buffer\n", p->host_no, CTL_OF_SCB(scb));
10110: scb->flags |= SCB_RESET | SCB_DEVICE_RESET;
10111: aic7xxx_error(scb->cmd) = DID_RESET;
10112: p->dev_flags[TARGET_INDEX(scb->cmd)] &=
10113: ~DEVICE_SUCCESS;
10114: p->dev_flags[TARGET_INDEX(scb->cmd)] |=
10115: BUS_DEVICE_RESET_PENDING;
10116: /* Send the abort message to the active SCB. */
10117: aic_outb(p, HOST_MSG, MSG_OUT);
10118: aic_outb(p, lastphase | ATNO, SCSISIGO);
10119: return(SCSI_RESET_PENDING);
10120: }
10121: else
10122: {
10123: /* We want to send out the message, but it could screw an already */
10124: /* in place and being used message. Instead, we return an error */
10125: /* to try and start the bus reset phase since this command is */
10126: /* probably hung (aborts failed, and now reset is failing). We */
10127: /* also make sure to set BUS_DEVICE_RESET_PENDING so we won't try */
10128: /* any more on this device, but instead will escalate to a bus or */
10129: /* host reset (additionally, we won't try to abort any more). */
10130: printk(WARN_LEAD "Device reset, Message buffer "
10131: "in use\n", p->host_no, CTL_OF_SCB(scb));
10132: scb->flags |= SCB_RESET | SCB_DEVICE_RESET;
10133: aic7xxx_error(scb->cmd) = DID_RESET;
10134: p->dev_flags[TARGET_INDEX(scb->cmd)] &=
10135: ~DEVICE_SUCCESS;
10136: p->dev_flags[TARGET_INDEX(scb->cmd)] |=
10137: BUS_DEVICE_RESET_PENDING;
10138: return(SCSI_RESET_ERROR);
10139: }
10140: }
10141: } /* if (last_phase != P_BUSFREE).....indicates we are idle and can work */
10142: hscb_index = aic7xxx_find_scb(p, scb);
10143: if (hscb_index == SCB_LIST_NULL)
10144: {
10145: disconnected = (aic7xxx_scb_on_qoutfifo(p, scb)) ? FALSE : TRUE;
10146: }
10147: else
10148: {
10149: aic_outb(p, hscb_index, SCBPTR);
10150: if (aic_inb(p, SCB_CONTROL) & DISCONNECTED)
10151: {
10152: disconnected = TRUE;
10153: }
10154: }
10155: if (disconnected)
10156: {
10157: /*
10158: * Simply set the MK_MESSAGE flag and the SEQINT handler will do
10159: * the rest on a reconnect.
10160: */
10161: scb->hscb->control |= MK_MESSAGE;
10162: scb->flags |= SCB_RESET | SCB_DEVICE_RESET;
10163: p->dev_flags[TARGET_INDEX(scb->cmd)] &= ~DEVICE_SUCCESS;
10164: p->dev_flags[TARGET_INDEX(scb->cmd)] |=
10165: BUS_DEVICE_RESET_PENDING;
10166: if (hscb_index != SCB_LIST_NULL)
10167: {
10168: unsigned char scb_control;
10169:
10170: aic_outb(p, hscb_index, SCBPTR);
10171: scb_control = aic_inb(p, SCB_CONTROL);
10172: aic_outb(p, scb_control | MK_MESSAGE, SCB_CONTROL);
10173: }
10174: /*
10175: * Actually requeue this SCB in case we can select the
10176: * device before it reconnects. If the transaction we
10177: * want to abort is not tagged, then this will be the only
10178: * outstanding command and we can simply shove it on the
10179: * qoutfifo and be done. If it is tagged, then it goes right
10180: * in with all the others, no problem :) We need to add it
10181: * to the qinfifo and let the sequencer know it is there.
10182: * Now, the only problem left to deal with is, *IF* this
10183: * command completes, in spite of the MK_MESSAGE bit in the
10184: * control byte, then we need to pick that up in the interrupt
10185: * routine and clean things up. This *shouldn't* ever happen.
10186: */
10187: if (aic7xxx_verbose & VERBOSE_RESET_PROCESS)
10188: printk(INFO_LEAD "Queueing device reset "
10189: "command.\n", p->host_no, CTL_OF_SCB(scb));
10190: p->qinfifo[p->qinfifonext++] = scb->hscb->tag;
10191: if (p->features & AHC_QUEUE_REGS)
10192: aic_outb(p, p->qinfifonext, HNSCB_QOFF);
10193: else
10194: aic_outb(p, p->qinfifonext, KERNEL_QINPOS);
10195: scb->flags |= SCB_QUEUED_ABORT;
10196: result = SCSI_RESET_PENDING;
10197: }
10198: else if (result == -1)
10199: {
10200: result = SCSI_RESET_ERROR;
10201: }
10202: aic_outb(p, saved_scbptr, SCBPTR);
10203: return (result);
10204: }
10205:
10206:
10207: /*+F*************************************************************************
10208: * Function:
10209: * aic7xxx_panic_abort
10210: *
10211: * Description:
10212: * Abort the current SCSI command(s).
10213: *-F*************************************************************************/
10214: void
10215: aic7xxx_panic_abort(struct aic7xxx_host *p, Scsi_Cmnd *cmd)
10216: {
10217: #if LINUX_VERSION_CODE < KERNEL_VERSION(2,1,0)
10218: int i, mask, found, need_tag;
10219: struct aic7xxx_scb *scb;
10220: unsigned char qinpos, hscbp;
10221:
10222: found = FALSE;
10223: #endif
10224:
10225: printk("aic7xxx driver version %s/%s\n", AIC7XXX_C_VERSION,
10226: UTS_RELEASE);
10227: printk("Controller type:\n %s\n", board_names[p->board_name_index]);
10228: printk("p->flags=0x%x, p->chip=0x%x, p->features=0x%x, "
10229: "sequencer %s paused\n",
10230: p->flags, p->chip, p->features,
10231: (aic_inb(p, HCNTRL) & PAUSE) ? "is" : "isn't" );
10232: pause_sequencer(p);
10233: disable_irq(p->irq);
10234: aic7xxx_print_card(p);
10235: aic7xxx_print_scratch_ram(p);
10236: #if LINUX_VERSION_CODE < KERNEL_VERSION(2,1,0)
10237: for(i=0; i<MAX_TARGETS; i++)
10238: {
10239: if(p->dev_flags[i] & DEVICE_PRESENT)
10240: {
10241: mask = (0x01 << i);
10242: printk(INFO_LEAD "dev_flags=0x%x, WDTR:%c/%c/%c, SDTR:%c/%c/%c,"
10243: " q_depth=%d:%d:%d\n",
10244: p->host_no, 0, i, 0, p->dev_flags[i],
10245: (p->wdtr_pending & mask) ? 'Y' : 'N',
10246: (p->needwdtr & mask) ? 'Y' : 'N',
10247: (p->needwdtr_copy & mask) ? 'Y' : 'N',
10248: (p->sdtr_pending & mask) ? 'Y' : 'N',
10249: (p->needsdtr & mask) ? 'Y' : 'N',
10250: (p->needsdtr_copy & mask) ? 'Y' : 'N',
10251: p->dev_active_cmds[i],
10252: p->dev_max_queue_depth[i], p->dev_mid_level_queue_depth[i]);
10253: printk(INFO_LEAD "targ_scsirate=0x%x", p->host_no, 0, i, 0,
10254: aic_inb(p, TARG_SCSIRATE + i));
10255: if (p->features & AHC_ULTRA2)
10256: printk(", targ_offset=%d", aic_inb(p, TARG_OFFSET + i));
10257: printk("\n");
10258: }
10259: }
10260: /*
10261: * Search for this command and see if we can't track it down, it's the
10262: * one causing the timeout. Print out this command first, then all other
10263: * active commands afterwords.
10264: */
10265: need_tag = -1;
10266: if ( cmd )
10267: {
10268: scb = p->scb_data->scb_array[aic7xxx_position(cmd)];
10269: if ( (scb->flags & SCB_ACTIVE) && (scb->cmd == cmd) )
10270: {
10271: printk("Timed out command is scb #%d:\n", scb->hscb->tag);
10272: printk("Tag%d: flags=0x%x, control=0x%x, TCL=0x%x, %s\n", scb->hscb->tag,
10273: scb->flags, scb->hscb->control, scb->hscb->target_channel_lun,
10274: (scb->flags & SCB_WAITINGQ) ? "WAITINGQ" : "Sent" );
10275: need_tag = scb->hscb->tag;
10276: if (scb->flags & SCB_WAITINGQ) found=TRUE;
10277: }
10278: }
10279: printk("QINFIFO: (TAG) ");
10280: qinpos = aic_inb(p, QINPOS);
10281: while ( qinpos != p->qinfifonext )
10282: {
10283: if (p->qinfifo[qinpos] == need_tag)
10284: found=TRUE;
10285: printk("%d ", p->qinfifo[qinpos++]);
10286: }
10287: printk("\n");
10288: printk("Current SCB: (SCBPTR/TAG/CONTROL) %d/%d/0x%x\n", aic_inb(p, SCBPTR),
10289: aic_inb(p, SCB_TAG), aic_inb(p, SCB_CONTROL) );
10290: if (aic_inb(p, SCB_TAG) == need_tag) found=TRUE;
10291: printk("WAITING_SCBS: (SCBPTR/TAG/CONTROL) %d->",
10292: hscbp = aic_inb(p, WAITING_SCBH));
10293: while (hscbp != SCB_LIST_NULL)
10294: {
10295: aic_outb(p, hscbp, SCBPTR);
10296: printk("%d/%d/0x%x ", hscbp, aic_inb(p, SCB_TAG), aic_inb(p, SCB_CONTROL));
10297: hscbp = aic_inb(p, SCB_NEXT);
10298: if (aic_inb(p, SCB_TAG) == need_tag) found=TRUE;
10299: }
10300: printk("\n");
10301: printk("DISCONNECTED_SCBS: (SCBPTR/TAG/CONTROL) %d->",
10302: hscbp = aic_inb(p, DISCONNECTED_SCBH));
10303: while (hscbp != SCB_LIST_NULL)
10304: {
10305: aic_outb(p, hscbp, SCBPTR);
10306: printk("%d/%d/0x%x ", hscbp, aic_inb(p, SCB_TAG), aic_inb(p, SCB_CONTROL));
10307: hscbp = aic_inb(p, SCB_NEXT);
10308: if (aic_inb(p, SCB_TAG) == need_tag) found=TRUE;
10309: }
10310: printk("\n");
10311: printk("FREE_SCBS: (SCBPTR/TAG/CONTROL) %d->",
10312: hscbp = aic_inb(p, FREE_SCBH));
10313: while (hscbp != SCB_LIST_NULL)
10314: {
10315: aic_outb(p, hscbp, SCBPTR);
10316: printk("%d/%d/0x%x ", hscbp, aic_inb(p, SCB_TAG), aic_inb(p, SCB_CONTROL));
10317: hscbp = aic_inb(p, SCB_NEXT);
10318: }
10319: printk("\n");
10320:
10321: if (found == FALSE)
10322: {
10323: /*
10324: * We haven't found the offending SCB yet, and it should be around
10325: * somewhere, so go look for it in the cards SCBs.
10326: */
10327: printk("SCBPTR CONTROL TAG PREV NEXT\n");
10328: for(i=0; i<p->scb_data->maxhscbs; i++)
10329: {
10330: aic_outb(p, i, SCBPTR);
10331: printk(" %3d %02x %02x %02x %02x\n", i,
10332: aic_inb(p, SCB_CONTROL), aic_inb(p, SCB_TAG),
10333: aic_inb(p, SCB_PREV), aic_inb(p, SCB_NEXT));
10334: }
10335: }
10336:
10337:
10338: for (i=0; i < p->scb_data->numscbs; i++)
10339: {
10340: scb = p->scb_data->scb_array[i];
10341: if ( (scb->flags & SCB_ACTIVE) && (scb->cmd != cmd) )
10342: {
10343: printk("Tag%d: flags=0x%x, control=0x%x, TCL=0x%x, %s\n", scb->hscb->tag,
10344: scb->flags, scb->hscb->control, scb->hscb->target_channel_lun,
10345: (scb->flags & SCB_WAITINGQ) ? "WAITINGQ" : "Sent" );
10346: }
10347: }
10348: #endif
10349: sti();
10350: for(;;) barrier();
10351: }
10352:
10353: /*+F*************************************************************************
10354: * Function:
10355: * aic7xxx_abort
10356: *
10357: * Description:
10358: * Abort the current SCSI command(s).
10359: *-F*************************************************************************/
10360: int
10361: aic7xxx_abort(Scsi_Cmnd *cmd)
10362: {
10363: struct aic7xxx_scb *scb = NULL;
10364: struct aic7xxx_host *p;
10365: int result, found=0;
10366: unsigned char tmp_char, saved_hscbptr, next_hscbptr, prev_hscbptr;
10367: #if LINUX_VERSION_CODE < KERNEL_VERSION(2,1,95)
10368: unsigned long cpu_flags = 0;
10369: #endif
10370: Scsi_Cmnd *cmd_next, *cmd_prev;
10371:
10372: p = (struct aic7xxx_host *) cmd->host->hostdata;
10373: scb = (p->scb_data->scb_array[aic7xxx_position(cmd)]);
10374:
10375: /*
10376: * I added a new config option to the driver: "panic_on_abort" that will
10377: * cause the driver to panic and the machine to stop on the first abort
10378: * or reset call into the driver. At that point, it prints out a lot of
10379: * usefull information for me which I can then use to try and debug the
10380: * problem. Simply enable the boot time prompt in order to activate this
10381: * code.
10382: */
10383: if (aic7xxx_panic_on_abort)
10384: aic7xxx_panic_abort(p, cmd);
10385:
10386: DRIVER_LOCK
10387:
10388: /*
10389: * Run the isr to grab any command in the QOUTFIFO and any other misc.
10390: * assundry tasks. This should also set up the bh handler if there is
10391: * anything to be done, but it won't run until we are done here since
10392: * we are following a straight code path without entering the scheduler
10393: * code.
10394: */
10395:
10396: pause_sequencer(p);
10397: while ( (aic_inb(p, INTSTAT) & INT_PEND) && !(p->flags & AHC_IN_ISR))
10398: {
10399: aic7xxx_isr(p->irq, p, (void *)NULL);
10400: pause_sequencer(p);
10401: aic7xxx_done_cmds_complete(p);
10402: }
10403:
10404: if ((scb == NULL) || (cmd->serial_number != cmd->serial_number_at_timeout))
10405: /* Totally bogus cmd since it points beyond our */
10406: { /* valid SCB range or doesn't even match it's own*/
10407: /* timeout serial number. */
10408: if (aic7xxx_verbose & VERBOSE_ABORT_MID)
10409: printk(INFO_LEAD "Abort called with bogus Scsi_Cmnd "
10410: "pointer.\n", p->host_no, CTL_OF_CMD(cmd));
10411: unpause_sequencer(p, FALSE);
10412: DRIVER_UNLOCK
10413: return(SCSI_ABORT_NOT_RUNNING);
10414: }
10415: if (scb->cmd != cmd) /* Hmmm...either this SCB is currently free with a */
10416: { /* NULL cmd pointer (NULLed out when freed) or it */
10417: /* has already been recycled for another command */
10418: /* Either way, this SCB has nothing to do with this*/
10419: /* command and we need to deal with cmd without */
10420: /* touching the SCB. */
10421: /* The theory here is to return a value that will */
10422: /* make the queued for complete command actually */
10423: /* finish successfully, or to indicate that we */
10424: /* don't have this cmd any more and the mid level */
10425: /* code needs to find it. */
10426: cmd_next = p->completeq.head;
10427: cmd_prev = NULL;
10428: while (cmd_next != NULL)
10429: {
10430: if (cmd_next == cmd)
10431: {
10432: if (aic7xxx_verbose & VERBOSE_ABORT_PROCESS)
10433: printk(INFO_LEAD "Abort called for command "
10434: "on completeq, completing.\n", p->host_no, CTL_OF_CMD(cmd));
10435: if ( cmd_prev == NULL )
10436: p->completeq.head = (Scsi_Cmnd *)cmd_next->host_scribble;
10437: else
10438: cmd_prev->host_scribble = cmd_next->host_scribble;
10439: cmd_next->scsi_done(cmd_next);
10440: unpause_sequencer(p, FALSE);
10441: DRIVER_UNLOCK
10442: return(SCSI_ABORT_NOT_RUNNING); /* It's already back as a successful
10443: * completion */
10444: }
10445: cmd_prev = cmd_next;
10446: cmd_next = (Scsi_Cmnd *)cmd_next->host_scribble;
10447: }
10448: if (aic7xxx_verbose & VERBOSE_ABORT_MID)
10449: printk(INFO_LEAD "Abort called for already completed"
10450: " command.\n", p->host_no, CTL_OF_CMD(cmd));
10451: unpause_sequencer(p, FALSE);
10452: DRIVER_UNLOCK
10453: return(SCSI_ABORT_NOT_RUNNING);
10454: }
10455:
10456: /* At this point we know the following:
10457: * the SCB pointer is valid
10458: * the command pointer passed in to us and the scb->cmd pointer match
10459: * this then means that the command we need to abort is the same as the
10460: * command held by the scb pointer and is a valid abort request.
10461: * Now, we just have to figure out what to do from here. Current plan is:
10462: * if we have already been here on this command, escalate to a reset
10463: * if scb is on waiting list or QINFIFO, send it back as aborted, but
10464: * we also need to be aware of the possibility that we could be using
10465: * a faked negotiation command that is holding this command up, if
10466: * so we need to take care of that command instead, which means we
10467: * would then treat this one like it was sitting around disconnected
10468: * instead.
10469: * if scb is on WAITING_SCB list in sequencer, free scb and send back
10470: * if scb is disconnected and not completed, abort with abort message
10471: * if scb is currently running, then it may be causing the bus to hang
10472: * so we want a return value that indicates a reset would be appropriate
10473: * if the command does not finish shortly
10474: * if scb is already complete but not on completeq, we're screwed because
10475: * this can't happen (except if the command is in the QOUTFIFO, in which
10476: * case we would like it to complete successfully instead of having to
10477: * to be re-done)
10478: * All other scenarios already dealt with by previous code.
10479: */
10480:
10481: if ( scb->flags & (SCB_ABORT | SCB_RESET | SCB_QUEUED_ABORT) )
10482: {
10483: if (aic7xxx_verbose & VERBOSE_ABORT_PROCESS)
10484: printk(INFO_LEAD "SCB aborted once already, "
10485: "escalating.\n", p->host_no, CTL_OF_SCB(scb));
10486: unpause_sequencer(p, FALSE);
10487: DRIVER_UNLOCK
10488: return(SCSI_ABORT_SNOOZE);
10489: }
10490: if ( (p->flags & (AHC_RESET_PENDING | AHC_ABORT_PENDING)) ||
10491: (p->dev_flags[TARGET_INDEX(scb->cmd)] &
10492: BUS_DEVICE_RESET_PENDING) )
10493: {
10494: if (aic7xxx_verbose & VERBOSE_ABORT_PROCESS)
10495: printk(INFO_LEAD "Reset/Abort pending for this "
10496: "device, not wasting our time.\n", p->host_no, CTL_OF_SCB(scb));
10497: unpause_sequencer(p, FALSE);
10498: DRIVER_UNLOCK
10499: return(SCSI_ABORT_PENDING);
10500: }
10501:
10502: found = 0;
10503: p->flags |= AHC_IN_ABORT;
10504: if (aic7xxx_verbose & VERBOSE_ABORT)
10505: printk(INFO_LEAD "Aborting scb %d, flags 0x%x\n",
10506: p->host_no, CTL_OF_SCB(scb), scb->hscb->tag, scb->flags);
10507:
10508: /*
10509: * First, let's check to see if the currently running command is our target
10510: * since if it is, the return is fairly easy and quick since we don't want
10511: * to touch the command in case it might complete, but we do want a timeout
10512: * in case it's actually hung, so we really do nothing, but tell the mid
10513: * level code to reset the timeout.
10514: */
10515:
10516: if ( scb->hscb->tag == aic_inb(p, SCB_TAG) )
10517: {
10518: /*
10519: * Check to see if the sequencer is just sitting on this command, or
10520: * if it's actively being run.
10521: */
10522: result = aic_inb(p, LASTPHASE);
10523: switch (result)
10524: {
10525: case P_DATAOUT: /* For any of these cases, we can assume we are */
10526: case P_DATAIN: /* an active command and act according. For */
10527: case P_COMMAND: /* anything else we are going to fall on through*/
10528: case P_STATUS: /* The SCSI_ABORT_SNOOZE will give us two abort */
10529: case P_MESGOUT: /* chances to finish and then escalate to a */
10530: case P_MESGIN: /* reset call */
10531: if (aic7xxx_verbose & VERBOSE_ABORT_PROCESS)
10532: printk(INFO_LEAD "SCB is currently active. "
10533: "Waiting on completion.\n", p->host_no, CTL_OF_SCB(scb));
10534: unpause_sequencer(p, FALSE);
10535: p->flags &= ~AHC_IN_ABORT;
10536: scb->flags |= SCB_RECOVERY_SCB; /* Note the fact that we've been */
10537: p->flags |= AHC_ABORT_PENDING; /* here so we will know not to */
10538: DRIVER_UNLOCK /* muck with other SCBs if this */
10539: return(SCSI_ABORT_PENDING); /* one doesn't complete and clear */
10540: break; /* out. */
10541: default:
10542: break;
10543: }
10544: }
10545:
10546: if ((found == 0) && (scb->flags & SCB_WAITINGQ))
10547: {
10548: int tindex = TARGET_INDEX(cmd);
10549: #ifdef AIC7XXX_FAKE_NEGOTIATION_CMDS
10550: unsigned short mask;
10551:
10552: mask = (1 << tindex);
10553:
10554: if (p->wdtr_pending & mask)
10555: {
10556: if (p->dev_wdtr_cmnd[tindex]->next != cmd)
10557: found = 1;
10558: else
10559: found = 0;
10560: }
10561: else if (p->sdtr_pending & mask)
10562: {
10563: if (p->dev_sdtr_cmnd[tindex]->next != cmd)
10564: found = 1;
10565: else
10566: found = 0;
10567: }
10568: else
10569: {
10570: found = 1;
10571: }
10572: if (found == 0)
10573: {
10574: /*
10575: * OK..this means the command we are currently getting an abort
10576: * for has an outstanding negotiation command in front of it.
10577: * We don't really have a way to tie back into the negotiation
10578: * commands, so we just send this back as pending, then it
10579: * will get reset in 2 seconds.
10580: */
10581: unpause_sequencer(p, TRUE);
10582: scb->flags |= SCB_ABORT;
10583: DRIVER_UNLOCK
10584: return(SCSI_ABORT_PENDING);
10585: }
10586: #endif
10587: if (aic7xxx_verbose & VERBOSE_ABORT_PROCESS)
10588: printk(INFO_LEAD "SCB found on waiting list and "
10589: "aborted.\n", p->host_no, CTL_OF_SCB(scb));
10590: scbq_remove(&p->waiting_scbs, scb);
10591: scbq_remove(&p->delayed_scbs[tindex], scb);
10592: p->dev_active_cmds[tindex]++;
10593: p->activescbs++;
10594: scb->flags &= ~(SCB_WAITINGQ | SCB_ACTIVE);
10595: scb->flags |= SCB_ABORT | SCB_QUEUED_FOR_DONE;
10596: found = 1;
10597: }
10598:
10599: /*
10600: * We just checked the waiting_q, now for the QINFIFO
10601: */
10602: if ( found == 0 )
10603: {
10604: if ( ((found = aic7xxx_search_qinfifo(p, cmd->target,
10605: cmd->channel,
10606: cmd->lun, scb->hscb->tag, SCB_ABORT | SCB_QUEUED_FOR_DONE,
10607: FALSE, NULL)) != 0) &&
10608: (aic7xxx_verbose & VERBOSE_ABORT_PROCESS))
10609: printk(INFO_LEAD "SCB found in QINFIFO and "
10610: "aborted.\n", p->host_no, CTL_OF_SCB(scb));
10611: }
10612:
10613: /*
10614: * QINFIFO, waitingq, completeq done. Next, check WAITING_SCB list in card
10615: */
10616:
10617: if ( found == 0 )
10618: {
10619: unsigned char scb_next_ptr;
10620: prev_hscbptr = SCB_LIST_NULL;
10621: saved_hscbptr = aic_inb(p, SCBPTR);
10622: next_hscbptr = aic_inb(p, WAITING_SCBH);
10623: while ( next_hscbptr != SCB_LIST_NULL )
10624: {
10625: aic_outb(p, next_hscbptr, SCBPTR );
10626: if ( scb->hscb->tag == aic_inb(p, SCB_TAG) )
10627: {
10628: found = 1;
10629: if (aic7xxx_verbose & VERBOSE_ABORT_PROCESS)
10630: printk(INFO_LEAD "SCB found on hardware waiting"
10631: " list and aborted.\n", p->host_no, CTL_OF_SCB(scb));
10632: if ( prev_hscbptr == SCB_LIST_NULL )
10633: {
10634: aic_outb(p, aic_inb(p, SCB_NEXT), WAITING_SCBH);
10635: /* stop the selection since we just
10636: * grabbed the scb out from under the
10637: * card
10638: */
10639: aic_outb(p, aic_inb(p, SCSISEQ) & ~ENSELO, SCSISEQ);
10640: aic_outb(p, CLRSELTIMEO, CLRSINT1);
10641: }
10642: else
10643: {
10644: scb_next_ptr = aic_inb(p, SCB_NEXT);
10645: aic_outb(p, prev_hscbptr, SCBPTR);
10646: aic_outb(p, scb_next_ptr, SCB_NEXT);
10647: aic_outb(p, next_hscbptr, SCBPTR);
10648: }
10649: aic_outb(p, SCB_LIST_NULL, SCB_TAG);
10650: aic_outb(p, 0, SCB_CONTROL);
10651: aic7xxx_add_curscb_to_free_list(p);
10652: scb->flags = SCB_ABORT | SCB_QUEUED_FOR_DONE;
10653: break;
10654: }
10655: prev_hscbptr = next_hscbptr;
10656: next_hscbptr = aic_inb(p, SCB_NEXT);
10657: }
10658: aic_outb(p, saved_hscbptr, SCBPTR );
10659: }
10660:
10661: /*
10662: * Hmmm...completeq, QOUTFIFO, QINFIFO, WAITING_SCBH, waitingq all checked.
10663: * OK...the sequencer's paused, interrupts are off, and we haven't found the
10664: * command anyplace where it could be easily aborted. Time for the hard
10665: * work. We also know the command is valid. This essentially means the
10666: * command is disconnected, or connected but not into any phases yet, which
10667: * we know due to the tests we ran earlier on the current active scb phase.
10668: * At this point we can queue the abort tag and go on with life.
10669: */
10670:
10671: if ( found == 0 )
10672: {
10673: p->flags |= AHC_ABORT_PENDING;
10674: scb->flags |= SCB_QUEUED_ABORT | SCB_ABORT | SCB_RECOVERY_SCB;
10675: scb->hscb->control |= MK_MESSAGE;
10676: result=aic7xxx_find_scb(p, scb);
10677: if ( result != SCB_LIST_NULL )
10678: {
10679: saved_hscbptr = aic_inb(p, SCBPTR);
10680: aic_outb(p, result, SCBPTR);
10681: tmp_char = aic_inb(p, SCB_CONTROL);
10682: aic_outb(p, tmp_char | MK_MESSAGE, SCB_CONTROL);
10683: aic_outb(p, saved_hscbptr, SCBPTR);
10684: }
10685: if (aic7xxx_verbose & VERBOSE_ABORT_PROCESS)
10686: printk(INFO_LEAD "SCB disconnected. Queueing Abort"
10687: " SCB.\n", p->host_no, CTL_OF_SCB(scb));
10688: p->qinfifo[p->qinfifonext++] = scb->hscb->tag;
10689: if (p->features & AHC_QUEUE_REGS)
10690: aic_outb(p, p->qinfifonext, HNSCB_QOFF);
10691: else
10692: aic_outb(p, p->qinfifonext, KERNEL_QINPOS);
10693: }
10694: if (found)
10695: {
10696: aic7xxx_run_done_queue(p, TRUE);
10697: aic7xxx_run_waiting_queues(p);
10698: }
10699: p->flags &= ~AHC_IN_ABORT;
10700: unpause_sequencer(p, FALSE);
10701: DRIVER_UNLOCK
10702:
10703: /*
10704: * On the return value. If we found the command and aborted it, then we know
10705: * it's already sent back and there is no reason for a further timeout, so
10706: * we use SCSI_ABORT_SUCCESS. On the queued abort side, we aren't so certain
10707: * there hasn't been a bus hang or something that might keep the abort from
10708: * from completing. Therefore, we use SCSI_ABORT_PENDING. The first time this
10709: * is passed back, the timeout on the command gets extended, the second time
10710: * we pass this back, the mid level SCSI code calls our reset function, which
10711: * would shake loose a hung bus.
10712: */
10713: if ( found != 0 )
10714: return(SCSI_ABORT_SUCCESS);
10715: else
10716: return(SCSI_ABORT_PENDING);
10717: }
10718:
10719:
10720: /*+F*************************************************************************
10721: * Function:
10722: * aic7xxx_reset
10723: *
10724: * Description:
10725: * Resetting the bus always succeeds - is has to, otherwise the
10726: * kernel will panic! Try a surgical technique - sending a BUS
10727: * DEVICE RESET message - on the offending target before pulling
10728: * the SCSI bus reset line.
10729: *-F*************************************************************************/
10730: int
10731: aic7xxx_reset(Scsi_Cmnd *cmd, unsigned int flags)
10732: {
10733: struct aic7xxx_scb *scb = NULL;
10734: struct aic7xxx_host *p;
10735: int tindex;
10736: int result = -1;
10737: #if LINUX_VERSION_CODE < KERNEL_VERSION(2,1,95)
10738: unsigned long cpu_flags = 0;
10739: #endif
10740: #define DEVICE_RESET 0x01
10741: #define BUS_RESET 0x02
10742: #define HOST_RESET 0x04
10743: #define FAIL 0x08
10744: #define RESET_DELAY 0x10
10745: int action;
10746: Scsi_Cmnd *cmd_prev, *cmd_next;
10747:
10748:
10749: if ( cmd == NULL )
10750: {
10751: printk(KERN_WARNING "(scsi?:?:?:?) Reset called with NULL Scsi_Cmnd "
10752: "pointer, failing.\n");
10753: return(SCSI_RESET_SNOOZE);
10754: }
10755:
10756: p = (struct aic7xxx_host *) cmd->host->hostdata;
10757: scb = (p->scb_data->scb_array[aic7xxx_position(cmd)]);
10758: tindex = TARGET_INDEX(cmd);
10759:
10760: /*
10761: * I added a new config option to the driver: "panic_on_abort" that will
10762: * cause the driver to panic and the machine to stop on the first abort
10763: * or reset call into the driver. At that point, it prints out a lot of
10764: * usefull information for me which I can then use to try and debug the
10765: * problem. Simply enable the boot time prompt in order to activate this
10766: * code.
10767: */
10768: if (aic7xxx_panic_on_abort)
10769: aic7xxx_panic_abort(p, cmd);
10770:
10771: DRIVER_LOCK
10772:
10773: pause_sequencer(p);
10774: while ( (aic_inb(p, INTSTAT) & INT_PEND) && !(p->flags & AHC_IN_ISR))
10775: {
10776: aic7xxx_isr(p->irq, p, (void *)NULL );
10777: pause_sequencer(p);
10778: aic7xxx_done_cmds_complete(p);
10779: }
10780:
10781: if (scb == NULL)
10782: {
10783: if (aic7xxx_verbose & VERBOSE_RESET_MID)
10784: printk(INFO_LEAD "Reset called with bogus Scsi_Cmnd"
10785: "->SCB mapping, improvising.\n", p->host_no, CTL_OF_CMD(cmd));
10786: if ( flags & SCSI_RESET_SUGGEST_HOST_RESET )
10787: {
10788: action = HOST_RESET;
10789: }
10790: else
10791: {
10792: action = BUS_RESET;
10793: }
10794: }
10795: else if (scb->cmd != cmd)
10796: {
10797: if (aic7xxx_verbose & VERBOSE_RESET_MID)
10798: printk(INFO_LEAD "Reset called with recycled SCB "
10799: "for cmd.\n", p->host_no, CTL_OF_CMD(cmd));
10800: cmd_prev = NULL;
10801: cmd_next = p->completeq.head;
10802: while ( cmd_next != NULL )
10803: {
10804: if (cmd_next == cmd)
10805: {
10806: if (aic7xxx_verbose & VERBOSE_RESET_RETURN)
10807: printk(INFO_LEAD "Reset, found cmd on completeq"
10808: ", completing.\n", p->host_no, CTL_OF_CMD(cmd));
10809: unpause_sequencer(p, FALSE);
10810: DRIVER_UNLOCK
10811: return(SCSI_RESET_NOT_RUNNING);
10812: }
10813: cmd_prev = cmd_next;
10814: cmd_next = (Scsi_Cmnd *)cmd_next->host_scribble;
10815: }
10816: if ( !(flags & SCSI_RESET_SYNCHRONOUS) )
10817: {
10818: if (aic7xxx_verbose & VERBOSE_RESET_RETURN)
10819: printk(INFO_LEAD "Reset, cmd not found,"
10820: " failing.\n", p->host_no, CTL_OF_CMD(cmd));
10821: unpause_sequencer(p, FALSE);
10822: DRIVER_UNLOCK
10823: return(SCSI_RESET_NOT_RUNNING);
10824: }
10825: else
10826: {
10827: if (aic7xxx_verbose & VERBOSE_RESET_MID)
10828: printk(INFO_LEAD "Reset called, no scb, "
10829: "flags 0x%x\n", p->host_no, CTL_OF_CMD(cmd), flags);
10830: scb = NULL;
10831: action = HOST_RESET;
10832: }
10833: }
10834: else
10835: {
10836: if (aic7xxx_verbose & VERBOSE_RESET_MID)
10837: printk(INFO_LEAD "Reset called, scb %d, flags "
10838: "0x%x\n", p->host_no, CTL_OF_SCB(scb), scb->hscb->tag, scb->flags);
10839: if ( aic7xxx_scb_on_qoutfifo(p, scb) )
10840: {
10841: if(aic7xxx_verbose & VERBOSE_RESET_RETURN)
10842: printk(INFO_LEAD "SCB on qoutfifo, returning.\n", p->host_no,
10843: CTL_OF_SCB(scb));
10844: unpause_sequencer(p, FALSE);
10845: DRIVER_UNLOCK
10846: return(SCSI_RESET_NOT_RUNNING);
10847: }
10848: if ( flags & SCSI_RESET_SUGGEST_HOST_RESET )
10849: {
10850: action = HOST_RESET;
10851: }
10852: else if ( flags & SCSI_RESET_SUGGEST_BUS_RESET )
10853: {
10854: action = BUS_RESET;
10855: }
10856: else
10857: {
10858: action = DEVICE_RESET;
10859: }
10860: }
10861: if ( (action & DEVICE_RESET) &&
10862: (p->dev_flags[tindex] & BUS_DEVICE_RESET_PENDING) )
10863: {
10864: if (aic7xxx_verbose & VERBOSE_RESET_PROCESS)
10865: printk(INFO_LEAD "Bus device reset already sent to "
10866: "device, escalating.\n", p->host_no, CTL_OF_CMD(cmd));
10867: action = BUS_RESET;
10868: }
10869: if ( (action & DEVICE_RESET) &&
10870: (scb->flags & SCB_QUEUED_ABORT) )
10871: {
10872: if (aic7xxx_verbose & VERBOSE_RESET_PROCESS)
10873: {
10874: printk(INFO_LEAD "Have already attempted to reach "
10875: "device with queued\n", p->host_no, CTL_OF_CMD(cmd));
10876: printk(INFO_LEAD "message, will escalate to bus "
10877: "reset.\n", p->host_no, CTL_OF_CMD(cmd));
10878: }
10879: action = BUS_RESET;
10880: }
10881: if ( (action & DEVICE_RESET) &&
10882: (p->flags & (AHC_RESET_PENDING | AHC_ABORT_PENDING)) )
10883: {
10884: if (aic7xxx_verbose & VERBOSE_RESET_PROCESS)
10885: printk(INFO_LEAD "Bus device reset stupid when "
10886: "other action has failed.\n", p->host_no, CTL_OF_CMD(cmd));
10887: action = BUS_RESET;
10888: }
10889: if ( (action & BUS_RESET) && !(p->features & AHC_TWIN) )
10890: {
10891: action = HOST_RESET;
10892: }
10893: if ( ((jiffies - p->dev_last_reset[tindex]) < (HZ * 3)) &&
10894: !(action & (HOST_RESET | BUS_RESET)))
10895: {
10896: if (aic7xxx_verbose & VERBOSE_RESET_PROCESS)
10897: {
10898: printk(INFO_LEAD "Reset called too soon after last "
10899: "reset without requesting\n", p->host_no, CTL_OF_CMD(cmd));
10900: printk(INFO_LEAD "bus or host reset, escalating.\n", p->host_no,
10901: CTL_OF_CMD(cmd));
10902: }
10903: action = BUS_RESET;
10904: }
10905: if ( ((jiffies - p->last_reset) < (HZ * 3)) &&
10906: (action & (HOST_RESET | BUS_RESET)) )
10907: {
10908: if (aic7xxx_verbose & VERBOSE_RESET_PROCESS)
10909: printk(INFO_LEAD "Reset called too soon after "
10910: "last bus reset, delaying.\n", p->host_no, CTL_OF_CMD(cmd));
10911: action = RESET_DELAY;
10912: }
10913: if ( (action & (BUS_RESET | HOST_RESET)) && (p->flags & AHC_IN_RESET)
10914: && ((jiffies - p->reset_start) > (2 * HZ * 3)) )
10915: {
10916: printk(KERN_ERR "(scsi%d:%d:%d:%d) Yikes!! Card must have left to go "
10917: "back to Adaptec!!\n", p->host_no, CTL_OF_CMD(cmd));
10918: unpause_sequencer(p, FALSE);
10919: DRIVER_UNLOCK
10920: return(SCSI_RESET_SNOOZE);
10921: }
10922: /*
10923: * By this point, we want to already know what we are going to do and
10924: * only have the following code implement our course of action.
10925: */
10926: switch (action)
10927: {
10928: case RESET_DELAY:
10929: unpause_sequencer(p, FALSE);
10930: DRIVER_UNLOCK
10931: return(SCSI_RESET_PENDING);
10932: break;
10933: case FAIL:
10934: unpause_sequencer(p, FALSE);
10935: DRIVER_UNLOCK
10936: return(SCSI_RESET_ERROR);
10937: break;
10938: case DEVICE_RESET:
10939: p->flags |= AHC_IN_RESET;
10940: result = aic7xxx_bus_device_reset(p, cmd);
10941: aic7xxx_run_done_queue(p, TRUE);
10942: /* We can't rely on run_waiting_queues to unpause the sequencer for
10943: * PCI based controllers since we use AAP */
10944: aic7xxx_run_waiting_queues(p);
10945: unpause_sequencer(p, FALSE);
10946: p->flags &= ~AHC_IN_RESET;
10947: DRIVER_UNLOCK
10948: return(result);
10949: break;
10950: case BUS_RESET:
10951: case HOST_RESET:
10952: default:
10953: p->reset_start = jiffies;
10954: p->flags |= AHC_IN_RESET;
10955: aic7xxx_reset_channel(p, cmd->channel, TRUE);
10956: if ( (p->features & AHC_TWIN) && (action & HOST_RESET) )
10957: {
10958: aic7xxx_reset_channel(p, cmd->channel ^ 0x01, TRUE);
10959: restart_sequencer(p);
10960: }
10961: p->last_reset = jiffies;
10962: if (action != HOST_RESET)
10963: result = SCSI_RESET_SUCCESS | SCSI_RESET_BUS_RESET;
10964: else
10965: {
10966: result = SCSI_RESET_SUCCESS | SCSI_RESET_HOST_RESET;
10967: aic_outb(p, aic_inb(p, SIMODE1) & ~(ENREQINIT|ENBUSFREE),
10968: SIMODE1);
10969: aic7xxx_clear_intstat(p);
10970: p->flags &= ~AHC_HANDLING_REQINITS;
10971: p->msg_type = MSG_TYPE_NONE;
10972: p->msg_index = 0;
10973: p->msg_len = 0;
10974: }
10975: aic7xxx_run_done_queue(p, TRUE);
10976: p->flags &= ~AHC_IN_RESET;
10977: /* We can't rely on run_waiting_queues to unpause the sequencer for
10978: * PCI based controllers since we use AAP */
10979: aic7xxx_run_waiting_queues(p);
10980: unpause_sequencer(p, FALSE);
10981: DRIVER_UNLOCK
10982: return(result);
10983: break;
10984: }
10985: }
10986:
10987: /*+F*************************************************************************
10988: * Function:
10989: * aic7xxx_biosparam
10990: *
10991: * Description:
10992: * Return the disk geometry for the given SCSI device.
10993: *-F*************************************************************************/
10994: int
10995: aic7xxx_biosparam(Disk *disk, kdev_t dev, int geom[])
10996: {
10997: int heads, sectors, cylinders;
10998: struct aic7xxx_host *p;
10999:
11000: p = (struct aic7xxx_host *) disk->device->host->hostdata;
11001:
11002: /*
11003: * XXX - if I could portably find the card's configuration
11004: * information, then this could be autodetected instead
11005: * of left to a boot-time switch.
11006: */
11007: heads = 64;
11008: sectors = 32;
11009: cylinders = disk->capacity / (heads * sectors);
11010:
11011: if ((p->flags & AHC_EXTEND_TRANS_A) && (cylinders > 1024))
11012: {
11013: heads = 255;
11014: sectors = 63;
11015: cylinders = disk->capacity / (heads * sectors);
11016: }
11017:
11018: geom[0] = heads;
11019: geom[1] = sectors;
11020: geom[2] = cylinders;
11021:
11022: return (0);
11023: }
11024:
11025: /*+F*************************************************************************
11026: * Function:
11027: * aic7xxx_release
11028: *
11029: * Description:
11030: * Free the passed in Scsi_Host memory structures prior to unloading the
11031: * module.
11032: *-F*************************************************************************/
11033: int
11034: aic7xxx_release(struct Scsi_Host *host)
11035: {
11036: struct aic7xxx_host *p = (struct aic7xxx_host *) host->hostdata;
11037: struct aic7xxx_host *next, *prev;
11038:
11039: if(p->irq)
11040: free_irq(p->irq, p);
11041: release_region(p->base, MAXREG - MINREG);
11042: #ifdef MMAPIO
11043: if(p->maddr)
11044: {
11045: #if LINUX_VERSION_CODE < KERNEL_VERSION(2,1,0)
11046: vfree((void *) (((unsigned long) p->maddr) & PAGE_MASK));
11047: #else
11048: iounmap((void *) (((unsigned long) p->maddr) & PAGE_MASK));
11049: #endif
11050: }
11051: #endif /* MMAPIO */
11052: prev = NULL;
11053: next = first_aic7xxx;
11054: while(next != NULL)
11055: {
11056: if(next == p)
11057: {
11058: if(prev == NULL)
11059: first_aic7xxx = next->next;
11060: else
11061: prev->next = next->next;
11062: }
11063: else
11064: {
11065: prev = next;
11066: }
11067: next = next->next;
11068: }
11069: aic7xxx_free(p);
11070: return(0);
11071: }
11072:
11073: /*+F*************************************************************************
11074: * Function:
11075: * aic7xxx_print_card
11076: *
11077: * Description:
11078: * Print out all of the control registers on the card
11079: *
11080: * NOTE: This function is not yet safe for use on the VLB and EISA
11081: * controllers, so it isn't used on those controllers at all.
11082: *-F*************************************************************************/
11083: static void
11084: aic7xxx_print_card(struct aic7xxx_host *p)
11085: {
11086: int i, j, k, chip;
11087: static struct register_ranges {
11088: int num_ranges;
11089: int range_val[32];
11090: } cards_ds[] = {
11091: { 0, {0,} }, /* none */
11092: {10, {0x00, 0x05, 0x08, 0x11, 0x18, 0x19, 0x1f, 0x1f, 0x60, 0x60, /*7771*/
11093: 0x62, 0x66, 0x80, 0x8e, 0x90, 0x95, 0x97, 0x97, 0x9b, 0x9f} },
11094: { 9, {0x00, 0x05, 0x08, 0x11, 0x18, 0x1f, 0x60, 0x60, 0x62, 0x66, /*7850*/
11095: 0x80, 0x8e, 0x90, 0x95, 0x97, 0x97, 0x9a, 0x9f} },
11096: { 9, {0x00, 0x05, 0x08, 0x11, 0x18, 0x1f, 0x60, 0x60, 0x62, 0x66, /*7860*/
11097: 0x80, 0x8e, 0x90, 0x95, 0x97, 0x97, 0x9a, 0x9f} },
11098: {10, {0x00, 0x05, 0x08, 0x11, 0x18, 0x19, 0x1c, 0x1f, 0x60, 0x60, /*7870*/
11099: 0x62, 0x66, 0x80, 0x8e, 0x90, 0x95, 0x97, 0x97, 0x9a, 0x9f} },
11100: {10, {0x00, 0x05, 0x08, 0x11, 0x18, 0x1a, 0x1c, 0x1f, 0x60, 0x60, /*7880*/
11101: 0x62, 0x66, 0x80, 0x8e, 0x90, 0x95, 0x97, 0x97, 0x9a, 0x9f} },
11102: {16, {0x00, 0x05, 0x08, 0x11, 0x18, 0x1f, 0x60, 0x60, 0x62, 0x66, /*7890*/
11103: 0x84, 0x8e, 0x90, 0x95, 0x97, 0x97, 0x9a, 0x9a, 0x9f, 0x9f,
11104: 0xe0, 0xf1, 0xf4, 0xf4, 0xf6, 0xf6, 0xf8, 0xf8, 0xfa, 0xfc,
11105: 0xfe, 0xff} },
11106: {12, {0x00, 0x05, 0x08, 0x11, 0x18, 0x19, 0x1b, 0x1f, 0x60, 0x60, /*7895*/
11107: 0x62, 0x66, 0x80, 0x8e, 0x90, 0x95, 0x97, 0x97, 0x9a, 0x9a,
11108: 0x9f, 0x9f, 0xe0, 0xf1} },
11109: {16, {0x00, 0x05, 0x08, 0x11, 0x18, 0x1f, 0x60, 0x60, 0x62, 0x66, /*7896*/
11110: 0x84, 0x8e, 0x90, 0x95, 0x97, 0x97, 0x9a, 0x9a, 0x9f, 0x9f,
11111: 0xe0, 0xf1, 0xf4, 0xf4, 0xf6, 0xf6, 0xf8, 0xf8, 0xfa, 0xfc,
11112: 0xfe, 0xff} },
11113: };
11114: #ifdef CONFIG_PCI
11115: static struct register_ranges cards_ns[] = {
11116: { 0, {0,} }, /* none */
11117: { 0, {0,} }, /* 7771 */
11118: { 7, {0x04, 0x08, 0x0c, 0x0e, 0x10, 0x17, 0x28, 0x2b, 0x30, 0x33,
11119: 0x3c, 0x41, 0x43, 0x47} },
11120: { 7, {0x04, 0x08, 0x0c, 0x0e, 0x10, 0x17, 0x28, 0x2b, 0x30, 0x33,
11121: 0x3c, 0x41, 0x43, 0x47} },
11122: { 5, {0x04, 0x08, 0x0c, 0x0e, 0x10, 0x17, 0x30, 0x33, 0x3c, 0x41} },
11123: { 5, {0x04, 0x08, 0x0c, 0x0e, 0x10, 0x17, 0x30, 0x34, 0x3c, 0x47} },
11124: { 5, {0x04, 0x08, 0x0c, 0x1b, 0x30, 0x34, 0x3c, 0x43, 0xdc, 0xe3} },
11125: { 6, {0x04, 0x08, 0x0c, 0x0e, 0x10, 0x17, 0x30, 0x34, 0x3c, 0x47,
11126: 0xdc, 0xe3} },
11127: { 6, {0x04, 0x08, 0x0c, 0x1b, 0x30, 0x34, 0x3c, 0x43, 0xdc, 0xe3,
11128: 0xff, 0xff} }
11129: };
11130: #endif
11131: chip = p->chip & AHC_CHIPID_MASK;
11132: /*
11133: * Let's run through the PCI space first....
11134: */
11135: printk("%s at ",
11136: board_names[p->board_name_index]);
11137: switch(p->chip & ~AHC_CHIPID_MASK)
11138: {
11139: case AHC_VL:
11140: printk("VLB Slot %d.\n", p->pci_device_fn);
11141: break;
11142: case AHC_EISA:
11143: printk("EISA Slot %d.\n", p->pci_device_fn);
11144: break;
11145: case AHC_PCI:
11146: default:
11147: printk("PCI %d/%d.\n", PCI_SLOT(p->pci_device_fn),
11148: PCI_FUNC(p->pci_device_fn));
11149: break;
11150: }
11151:
11152: #ifdef CONFIG_PCI
11153: {
11154: unsigned char temp;
11155:
11156: printk("PCI Dump:\n");
11157: k=0;
11158: for(i=0; i<cards_ns[chip].num_ranges; i++)
11159: {
11160: for(j = cards_ns[chip].range_val[ i * 2 ];
11161: j <= cards_ns[chip].range_val[ i * 2 + 1 ] ;
11162: j++)
11163: {
11164: #if LINUX_VERSION_CODE > KERNEL_VERSION(2,1,92)
11165: pci_read_config_byte(p->pdev, j, &temp);
11166: #else
11167: pcibios_read_config_byte(p->pci_bus, p->pci_device_fn, j, &temp);
11168: #endif
11169: printk("%02x:%02x ", j, temp);
11170: if(++k == 13)
11171: {
11172: printk("\n");
11173: k = 0;
11174: }
11175: }
11176: }
11177: }
11178: if(k != 0)
11179: printk("\n");
11180: #endif /* CONFIG_PCI */
11181:
11182: /*
11183: * Now the registers on the card....
11184: */
11185: printk("Card Dump:\n");
11186: k = 0;
11187: for(i=0; i<cards_ds[chip].num_ranges; i++)
11188: {
11189: for(j = cards_ds[chip].range_val[ i * 2 ];
11190: j <= cards_ds[chip].range_val[ i * 2 + 1 ] ;
11191: j++)
11192: {
11193: printk("%02x:%02x ", j, aic_inb(p, j));
11194: if(++k == 13)
11195: {
11196: printk("\n");
11197: k=0;
11198: }
11199: }
11200: }
11201: if(k != 0)
11202: printk("\n");
11203: if (p->flags & AHC_SEEPROM_FOUND)
11204: {
11205: unsigned short *sc1;
11206: sc1 = (unsigned short *)&p->sc;
11207:
11208: printk("SEEPROM dump.\n");
11209: for(i=1; i<=32; i++)
11210: {
11211: printk("0x%04x", sc1[i-1]);
11212: if ( (i % 8) == 0 )
11213: printk("\n");
11214: else
11215: printk(" ");
11216: }
11217: }
11218:
11219: /*
11220: * If this was an Ultra2 controller, then we just hosed the card in terms
11221: * of the QUEUE REGS. This function is only called at init time or by
11222: * the panic_abort function, so it's safe to assume a generic init time
11223: * setting here
11224: */
11225:
11226: if(p->features & AHC_QUEUE_REGS)
11227: {
11228: aic_outb(p, 0, SDSCB_QOFF);
11229: aic_outb(p, 0, SNSCB_QOFF);
11230: aic_outb(p, 0, HNSCB_QOFF);
11231: }
11232:
11233: }
11234:
11235: /*+F*************************************************************************
11236: * Function:
11237: * aic7xxx_print_scratch_ram
11238: *
11239: * Description:
11240: * Print out the scratch RAM values on the card.
11241: *-F*************************************************************************/
11242: static void
11243: aic7xxx_print_scratch_ram(struct aic7xxx_host *p)
11244: {
11245: int i, k;
11246:
11247: k = 0;
11248: printk("Scratch RAM:\n");
11249: for(i = SRAM_BASE; i < SEQCTL; i++)
11250: {
11251: printk("%02x:%02x ", i, aic_inb(p, i));
11252: if(++k == 13)
11253: {
11254: printk("\n");
11255: k=0;
11256: }
11257: }
11258: if (p->features & AHC_MORE_SRAM)
11259: {
11260: for(i = TARG_OFFSET; i < 0x80; i++)
11261: {
11262: printk("%02x:%02x ", i, aic_inb(p, i));
11263: if(++k == 13)
11264: {
11265: printk("\n");
11266: k=0;
11267: }
11268: }
11269: }
11270: printk("\n");
11271: }
11272:
11273:
11274: #include "aic7xxx_proc.c"
11275:
11276: #ifdef MODULE
11277: /* Eventually this will go into an include file, but this will be later */
11278: Scsi_Host_Template driver_template = AIC7XXX;
11279:
11280: #include "scsi_module.c"
11281: #endif
11282:
11283: /*
11284: * Overrides for Emacs so that we almost follow Linus's tabbing style.
11285: * Emacs will notice this stuff at the end of the file and automatically
11286: * adjust the settings for this buffer only. This must remain at the end
11287: * of the file.
11288: * ---------------------------------------------------------------------------
11289: * Local variables:
11290: * c-indent-level: 2
11291: * c-brace-imaginary-offset: 0
11292: * c-brace-offset: -2
11293: * c-argdecl-indent: 2
11294: * c-label-offset: -2
11295: * c-continued-statement-offset: 2
11296: * c-continued-brace-offset: 0
11297: * indent-tabs-mode: nil
11298: * tab-width: 8
11299: * End:
11300: */
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.