Import 2.3.18pre1
[davej-history.git] / drivers / scsi / aha152x.c
blob6fc7e3f249ea5a77d2f9731d25db24d86890784d
1 /* aha152x.c -- Adaptec AHA-152x driver
2 * Author: Jürgen E. Fischer, fischer@et-inf.fho-emden.de
3 * Copyright 1993, 1994, 1995, 1996 Jürgen E. Fischer
6 * This driver is based on
7 * fdomain.c -- Future Domain TMC-16x0 driver
8 * which is
9 * Copyright 1992, 1993 Rickard E. Faith (faith@cs.unc.edu)
12 * This program is free software; you can redistribute it and/or modify it
13 * under the terms of the GNU General Public License as published by the
14 * Free Software Foundation; either version 2, or (at your option) any
15 * later version.
17 * This program is distributed in the hope that it will be useful, but
18 * WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 * General Public License for more details.
23 * $Id: aha152x.c,v 1.18 1996/09/07 20:10:40 fischer Exp $
25 * $Log: aha152x.c,v $
26 * Revision 1.18 1996/09/07 20:10:40 fischer
27 * - fixed can_queue handling (multiple outstanding commands working again)
29 * Revision 1.17 1996/08/17 16:05:14 fischer
30 * - biosparam improved
31 * - interrupt verification
32 * - updated documentation
33 * - cleanups
35 * Revision 1.16 1996/06/09 00:04:56 root
36 * - added configuration symbols for insmod (aha152x/aha152x1)
38 * Revision 1.15 1996/04/30 14:52:06 fischer
39 * - proc info fixed
40 * - support for extended translation for >1GB disks
42 * Revision 1.14 1996/01/17 15:11:20 fischer
43 * - fixed lockup in MESSAGE IN phase after reconnection
45 * Revision 1.13 1996/01/09 02:15:53 fischer
46 * - some cleanups
47 * - moved request_irq behind controller initialization
48 * (to avoid spurious interrupts)
50 * Revision 1.12 1995/12/16 12:26:07 fischer
51 * - barrier()s added
52 * - configurable RESET delay added
54 * Revision 1.11 1995/12/06 21:18:35 fischer
55 * - some minor updates
57 * Revision 1.10 1995/07/22 19:18:45 fischer
58 * - support for 2 controllers
59 * - started synchronous data transfers (not working yet)
61 * Revision 1.9 1995/03/18 09:20:24 root
62 * - patches for PCMCIA and modules
64 * Revision 1.8 1995/01/21 22:07:19 root
65 * - snarf_region => request_region
66 * - aha152x_intr interface change
68 * Revision 1.7 1995/01/02 23:19:36 root
69 * - updated COMMAND_SIZE to cmd_len
70 * - changed sti() to restore_flags()
71 * - fixed some #ifdef which generated warnings
73 * Revision 1.6 1994/11/24 20:35:27 root
74 * - problem with odd number of bytes in fifo fixed
76 * Revision 1.5 1994/10/30 14:39:56 root
77 * - abort code fixed
78 * - debugging improved
80 * Revision 1.4 1994/09/12 11:33:01 root
81 * - irqaction to request_irq
82 * - abortion updated
84 * Revision 1.3 1994/08/04 13:53:05 root
85 * - updates for mid-level-driver changes
86 * - accept unexpected BUSFREE phase as error condition
87 * - parity check now configurable
89 * Revision 1.2 1994/07/03 12:56:36 root
90 * - cleaned up debugging code
91 * - more tweaking on reset delays
92 * - updated abort/reset code (pretty untested...)
94 * Revision 1.1 1994/05/28 21:18:49 root
95 * - update for mid-level interface change (abort-reset)
96 * - delays after resets adjusted for some slow devices
98 * Revision 1.0 1994/03/25 12:52:00 root
99 * - Fixed "more data than expected" problem
100 * - added new BIOS signatures
102 * Revision 0.102 1994/01/31 20:44:12 root
103 * - minor changes in insw/outsw handling
105 * Revision 0.101 1993/12/13 01:16:27 root
106 * - fixed STATUS phase (non-GOOD stati were dropped sometimes;
107 * fixes problems with CD-ROM sector size detection & media change)
109 * Revision 0.100 1993/12/10 16:58:47 root
110 * - fix for unsuccessful selections in case of non-continuous id assignments
111 * on the scsi bus.
113 * Revision 0.99 1993/10/24 16:19:59 root
114 * - fixed DATA IN (rare read errors gone)
116 * Revision 0.98 1993/10/17 12:54:44 root
117 * - fixed some recent fixes (shame on me)
118 * - moved initialization of scratch area to aha152x_queue
120 * Revision 0.97 1993/10/09 18:53:53 root
121 * - DATA IN fixed. Rarely left data in the fifo.
123 * Revision 0.96 1993/10/03 00:53:59 root
124 * - minor changes on DATA IN
126 * Revision 0.95 1993/09/24 10:36:01 root
127 * - change handling of MSGI after reselection
128 * - fixed sti/cli
129 * - minor changes
131 * Revision 0.94 1993/09/18 14:08:22 root
132 * - fixed bug in multiple outstanding command code
133 * - changed detection
134 * - support for kernel command line configuration
135 * - reset corrected
136 * - changed message handling
138 * Revision 0.93 1993/09/15 20:41:19 root
139 * - fixed bugs with multiple outstanding commands
141 * Revision 0.92 1993/09/13 02:46:33 root
142 * - multiple outstanding commands work (no problems with IBM drive)
144 * Revision 0.91 1993/09/12 20:51:46 root
145 * added multiple outstanding commands
146 * (some problem with this $%&? IBM device remain)
148 * Revision 0.9 1993/09/12 11:11:22 root
149 * - corrected auto-configuration
150 * - changed the auto-configuration (added some '#define's)
151 * - added support for dis-/reconnection
153 * Revision 0.8 1993/09/06 23:09:39 root
154 * - added support for the drive activity light
155 * - minor changes
157 * Revision 0.7 1993/09/05 14:30:15 root
158 * - improved phase detection
159 * - now using the new snarf_region code of 0.99pl13
161 * Revision 0.6 1993/09/02 11:01:38 root
162 * first public release; added some signatures and biosparam()
164 * Revision 0.5 1993/08/30 10:23:30 root
165 * fixed timing problems with my IBM drive
167 * Revision 0.4 1993/08/29 14:06:52 root
168 * fixed some problems with timeouts due incomplete commands
170 * Revision 0.3 1993/08/28 15:55:03 root
171 * writing data works too. mounted and worked on a dos partition
173 * Revision 0.2 1993/08/27 22:42:07 root
174 * reading data works. Mounted a msdos partition.
176 * Revision 0.1 1993/08/25 13:38:30 root
177 * first "damn thing doesn't work" version
179 * Revision 0.0 1993/08/14 19:54:25 root
180 * empty function bodies; detect() works.
183 **************************************************************************
187 DESCRIPTION:
189 This is the Linux low-level SCSI driver for Adaptec AHA-1520/1522 SCSI
190 host adapters.
193 CONFIGURATION ARGUMENTS:
195 IOPORT base io address (0x340/0x140)
196 IRQ interrupt level (9-12; default 11)
197 SCSI_ID scsi id of controller (0-7; default 7)
198 RECONNECT allow targets to disconnect from the bus (0/1; default 1 [on])
199 PARITY enable parity checking (0/1; default 1 [on])
200 SYNCHRONOUS enable synchronous transfers (0/1; default 0 [off])
201 (NOT WORKING YET)
202 DELAY: bus reset delay (default 100)
203 EXT_TRANS: enable extended translation (0/1: default 0 [off])
204 (see NOTES below)
206 COMPILE TIME CONFIGURATION (put into AHA152X in drivers/scsi/Makefile):
208 -DAUTOCONF
209 use configuration the controller reports (AHA-152x only)
211 -DSKIP_BIOSTEST
212 Don't test for BIOS signature (AHA-1510 or disabled BIOS)
214 -DSETUP0="{ IOPORT, IRQ, SCSI_ID, RECONNECT, PARITY, SYNCHRONOUS, DELAY, EXT_TRANS }"
215 override for the first controller
217 -DSETUP1="{ IOPORT, IRQ, SCSI_ID, RECONNECT, PARITY, SYNCHRONOUS, DELAY, EXT_TRANS }"
218 override for the second controller
221 LILO COMMAND LINE OPTIONS:
223 aha152x=<IOPORT>[,<IRQ>[,<SCSI-ID>[,<RECONNECT>[,<PARITY>[,<SYNCHRONOUS>[,<DELAY> [,<EXT_TRANS]]]]]]]
225 The normal configuration can be overridden by specifying a command line.
226 When you do this, the BIOS test is skipped. Entered values have to be
227 valid (known). Don't use values that aren't supported under normal
228 operation. If you think that you need other values: contact me.
229 For two controllers use the aha152x statement twice.
232 SYMBOLS FOR MODULE CONFIGURATION:
234 aha152x=IOPORT,IRQ,SCSI_ID,RECONNECT,PARITY,SYNCHRONOUS,DELAY,EXT_TRANS
235 configuration override of first controller
238 aha152x1=IOPORT,IRQ,SCSI_ID,RECONNECT,PARITY,SYNCHRONOUS,DELAY,EXT_TRANS
239 configuration override of second controller
242 NOTES ON EXT_TRANS:
244 SCSI uses block numbers to address blocks/sectors on a device.
245 The BIOS uses a cylinder/head/sector addressing scheme (C/H/S)
246 scheme instead. DOS expects a BIOS or driver that understands this
247 C/H/S addressing.
249 The number of cylinders/heads/sectors is called geometry and is required
250 as base for requests in C/H/S addressing. SCSI only knows about the
251 total capacity of disks in blocks (sectors).
253 Therefore the SCSI BIOS/DOS driver has to calculate a logical/virtual
254 geometry just to be able to support that addressing scheme. The geometry
255 returned by the SCSI BIOS is a pure calculation and has nothing to
256 do with the real/physical geometry of the disk (which is usually
257 irrelevant anyway).
259 Basically this has no impact at all on Linux, because it also uses block
260 instead of C/H/S addressing. Unfortunately C/H/S addressing is also used
261 in the partition table and therefore every operating system has to know
262 the right geometry to be able to interpret it.
264 Moreover there are certain limitations to the C/H/S addressing scheme,
265 namely the address space is limited to upto 255 heads, upto 63 sectors
266 and a maximum of 1023 cylinders.
268 The AHA-1522 BIOS calculates the geometry by fixing the number of heads
269 to 64, the number of sectors to 32 and by calculating the number of
270 cylinders by dividing the capacity reported by the disk by 64*32 (1 MB).
271 This is considered to be the default translation.
273 With respect to the limit of 1023 cylinders using C/H/S you can only
274 address the first GB of your disk in the partition table. Therefore
275 BIOSes of some newer controllers based on the AIC-6260/6360 support
276 extended translation. This means that the BIOS uses 255 for heads,
277 63 for sectors and then divides the capacity of the disk by 255*63
278 (about 8 MB), as soon it sees a disk greater than 1 GB. That results
279 in a maximum of about 8 GB addressable diskspace in the partition table
280 (but there are already bigger disks out there today).
282 To make it even more complicated the translation mode might/might
283 not be configurable in certain BIOS setups.
285 This driver does some more or less failsafe guessing to get the
286 geometry right in most cases:
288 - for disks<1GB: use default translation (C/32/64)
289 - for disks>1GB:
290 - take current geometry from the partition table
291 (using scsicam_bios_param and accept only `valid' geometries,
292 ie. either (C/32/64) or (C/63/255)). This can be extended
293 translation even if it's not enabled in the driver.
294 - if that fails, take extended translation if enabled by override,
295 kernel or module parameter, otherwise take default translation and
296 ask the user for verification. This might on not yet partitioned
297 disks or
300 REFERENCES USED:
302 "AIC-6260 SCSI Chip Specification", Adaptec Corporation.
304 "SCSI COMPUTER SYSTEM INTERFACE - 2 (SCSI-2)", X3T9.2/86-109 rev. 10h
306 "Writing a SCSI device driver for Linux", Rik Faith (faith@cs.unc.edu)
308 "Kernel Hacker's Guide", Michael K. Johnson (johnsonm@sunsite.unc.edu)
310 "Adaptec 1520/1522 User's Guide", Adaptec Corporation.
312 Michael K. Johnson (johnsonm@sunsite.unc.edu)
314 Drew Eckhardt (drew@cs.colorado.edu)
316 Eric Youngdale (ericy@cais.com)
318 special thanks to Eric Youngdale for the free(!) supplying the
319 documentation on the chip.
321 **************************************************************************/
323 #ifdef PCMCIA
324 #define MODULE
325 #endif
327 #include <linux/module.h>
329 #ifdef PCMCIA
330 #undef MODULE
331 #endif
333 #include <linux/sched.h>
334 #include <asm/io.h>
335 #include <linux/blk.h>
336 #include"scsi.h"
337 #include"sd.h"
338 #include"hosts.h"
339 #include"constants.h"
340 #include <asm/system.h>
341 #include <linux/errno.h>
342 #include <linux/string.h>
343 #include <linux/wait.h>
344 #include <linux/ioport.h>
345 #include <linux/proc_fs.h>
346 #include <linux/interrupt.h>
348 #include"aha152x.h"
349 #include <linux/stat.h>
351 #include <scsi/scsicam.h>
353 struct proc_dir_entry proc_scsi_aha152x =
355 PROC_SCSI_AHA152X,7,"aha152x",
356 S_IFDIR | S_IRUGO | S_IXUGO,2
359 /* DEFINES */
361 /* For PCMCIA cards, always use AUTOCONF */
362 #if defined(PCMCIA) || defined(MODULE)
363 #if !defined(AUTOCONF)
364 #define AUTOCONF
365 #endif
366 #endif
368 #if !defined(AUTOCONF) && !defined(SETUP0)
369 #error define AUTOCONF or SETUP0
370 #endif
372 #if defined(DEBUG_AHA152X)
374 #undef SKIP_PORTS/* don't display ports */
376 #undef DEBUG_QUEUE/* debug queue() */
377 #undef DEBUG_RESET/* debug reset() */
378 #undef DEBUG_INTR/* debug intr() */
379 #undef DEBUG_SELECTION/* debug selection part in intr() */
380 #undef DEBUG_MSGO/* debug message out phase in intr() */
381 #undef DEBUG_MSGI/* debug message in phase in intr() */
382 #undef DEBUG_STATUS/* debug status phase in intr() */
383 #undef DEBUG_CMD/* debug command phase in intr() */
384 #undef DEBUG_DATAI/* debug data in phase in intr() */
385 #undef DEBUG_DATAO/* debug data out phase in intr() */
386 #undef DEBUG_ABORT/* debug abort() */
387 #undef DEBUG_DONE/* debug done() */
388 #undef DEBUG_BIOSPARAM/* debug biosparam() */
390 #undef DEBUG_RACE/* debug race conditions */
391 #undef DEBUG_PHASES/* debug phases (useful to trace) */
392 #undef DEBUG_QUEUES/* debug reselection */
394 /* recently used for debugging */
395 #if 0
396 #endif
398 #define DEBUG_SELECTION
399 #define DEBUG_PHASES
400 #define DEBUG_RESET
401 #define DEBUG_ABORT
403 #define DEBUG_DEFAULT (debug_reset|debug_abort)
405 #endif
407 /* END OF DEFINES */
409 externlong loops_per_sec;
411 #define DELAY_DEFAULT 100
413 /* some additional "phases" for getphase() */
414 #define P_BUSFREE 1
415 #define P_PARITY 2
417 /* possible irq range */
418 #ifdef PCMCIA
419 #define IRQ_MIN 0
420 #define IRQ_MAX 16
421 #else
422 #define IRQ_MIN 9
423 #define IRQ_MAX 12
424 #endif
425 #define IRQS IRQ_MAX-IRQ_MIN+1
427 enum{
428 not_issued =0x0001,
429 in_selection =0x0002,
430 disconnected =0x0004,
431 aborted =0x0008,
432 sent_ident =0x0010,
433 in_other =0x0020,
434 in_sync =0x0040,
435 sync_ok =0x0080,
438 #if defined(MODULE)
439 #if defined(DEBUG_AHA152X)
440 int aha152x[] =
441 {0,11,7,1,1,0, DELAY_DEFAULT,0, DEBUG_DEFAULT};
442 int aha152x1[] =
443 {0,11,7,1,1,0, DELAY_DEFAULT,0, DEBUG_DEFAULT};
444 MODULE_PARM(aha152x,"1-9i");
445 MODULE_PARM(aha152x1,"1-9i");
446 #else
447 int aha152x[] =
448 {0,11,7,1,1,0, DELAY_DEFAULT,0};
449 int aha152x1[] =
450 {0,11,7,1,1,0, DELAY_DEFAULT,0};
451 MODULE_PARM(aha152x,"1-8i");
452 MODULE_PARM(aha152x1,"1-8i");
453 #endif
454 #endif
456 /* set by aha152x_setup according to the command line */
457 static int setup_count =0;
458 static int registered_count =0;
459 static struct aha152x_setup {
460 int io_port;
461 int irq;
462 int scsiid;
463 int reconnect;
464 int parity;
465 int synchronous;
466 int delay;
467 int ext_trans;
468 #ifdef DEBUG_AHA152X
469 int debug;
470 #endif
471 char*conf;
472 } setup[2];
474 static struct Scsi_Host *aha152x_host[IRQS];
476 #define HOSTDATA(shpnt) ((struct aha152x_hostdata *) &shpnt->hostdata)
477 #define CURRENT_SC (HOSTDATA(shpnt)->current_SC)
478 #define ISSUE_SC (HOSTDATA(shpnt)->issue_SC)
479 #define DISCONNECTED_SC (HOSTDATA(shpnt)->disconnected_SC)
480 #define DELAY (HOSTDATA(shpnt)->delay)
481 #define EXT_TRANS (HOSTDATA(shpnt)->ext_trans)
482 #define SYNCRATE (HOSTDATA(shpnt)->syncrate[CURRENT_SC->target])
483 #define MSG(i) (HOSTDATA(shpnt)->message[i])
484 #define MSGLEN (HOSTDATA(shpnt)->message_len)
485 #define ADDMSG(x) (MSG(MSGLEN++)=x)
487 struct aha152x_hostdata {
488 Scsi_Cmnd *issue_SC;
489 Scsi_Cmnd *current_SC;
490 Scsi_Cmnd *disconnected_SC;
491 int aborting;
492 int abortion_complete;
493 int abort_result;
494 int commands;
496 int reconnect;
497 int parity;
498 int synchronous;
499 int delay;
500 int ext_trans;
502 int swint;
503 int service;
505 unsigned char syncrate[8];
507 unsigned char message[256];
508 int message_len;
510 #ifdef DEBUG_AHA152X
511 int debug;
512 #endif
515 static voidaha152x_intr(int irq,void*dev_id,struct pt_regs *);
516 voidaha152x_done(struct Scsi_Host *shpnt,int error);
517 voidaha152x_setup(char*str,int*ints);
518 intaha152x_checksetup(struct aha152x_setup *setup);
520 static voidaha152x_reset_ports(struct Scsi_Host *shpnt);
521 static voidaha152x_panic(struct Scsi_Host *shpnt,char*msg);
523 static voiddisp_ports(struct Scsi_Host *shpnt);
524 static voidshow_command(Scsi_Cmnd * ptr);
525 static voidshow_queues(struct Scsi_Host *shpnt);
526 static voiddisp_enintr(struct Scsi_Host *shpnt);
528 #if defined(DEBUG_RACE)
529 static voidenter_driver(const char*);
530 static voidleave_driver(const char*);
531 #endif
533 /* possible i/o addresses for the AIC-6260 */
534 static unsigned short ports[] =
536 0x340,/* default first */
537 0x140
539 #define PORT_COUNT (sizeof(ports) / sizeof(unsigned short))
541 #if !defined(SKIP_BIOSTEST)
542 /* possible locations for the Adaptec BIOS */
543 static unsigned int addresses[] =
545 0xdc000,/* default first */
546 0xc8000,
547 0xcc000,
548 0xd0000,
549 0xd4000,
550 0xd8000,
551 0xe0000,
552 0xeb800,/* VTech Platinum SMP */
553 0xf0000,
555 #define ADDRESS_COUNT (sizeof(addresses) / sizeof(unsigned int))
557 /* signatures for various AIC-6[23]60 based controllers.
558 The point in detecting signatures is to avoid useless and maybe
559 harmful probes on ports. I'm not sure that all listed boards pass
560 auto-configuration. For those which fail the BIOS signature is
561 obsolete, because user intervention to supply the configuration is
562 needed anyway. May be an information whether or not the BIOS supports
563 extended translation could be also useful here. */
564 static struct signature {
565 unsigned char*signature;
566 int sig_offset;
567 int sig_length;
568 } signatures[] =
572 "Adaptec AHA-1520 BIOS",0x102e,21
573 },/* Adaptec 152x */
575 "Adaptec AHA-1520B",0x0b,19
576 },/* Adaptec 152x rev B */
578 "Adaptec ASW-B626 BIOS",0x1029,21
579 },/* on-board controller */
581 "Adaptec BIOS: ASW-B626",0x0f,22
582 },/* on-board controller */
584 "Adaptec ASW-B626 S2",0x2e6c,19
585 },/* on-board controller */
587 "Adaptec BIOS:AIC-6360",0xc,21
588 },/* on-board controller */
590 "ScsiPro SP-360 BIOS",0x2873,19
591 },/* ScsiPro-Controller */
593 "GA-400 LOCAL BUS SCSI BIOS",0x102e,26
594 },/* Gigabyte Local-Bus-SCSI */
596 "Adaptec BIOS:AVA-282X",0xc,21
597 },/* Adaptec 282x */
599 "Adaptec IBM Dock II SCSI",0x2edd,24
600 },/* IBM Thinkpad Dock II */
602 "Adaptec BIOS:AHA-1532P",0x1c,22
603 },/* IBM Thinkpad Dock II SCSI */
605 "DTC3520A Host Adapter BIOS",0x318a,26
606 },/* DTC 3520A ISA SCSI */
609 #define SIGNATURE_COUNT (sizeof(signatures) / sizeof(struct signature))
610 #endif
613 static voiddo_pause(unsigned amount)
614 {/* Pause for amount*10 milliseconds */
615 unsigned long the_time = jiffies + amount;/* 0.01 seconds per jiffy */
617 while(time_before(jiffies, the_time))
618 barrier();
622 * queue services:
624 staticinlinevoidappend_SC(Scsi_Cmnd ** SC, Scsi_Cmnd * new_SC)
626 Scsi_Cmnd *end;
628 new_SC->host_scribble = (unsigned char*) NULL;
629 if(!*SC)
630 *SC = new_SC;
631 else{
632 for(end = *SC; end->host_scribble; end = (Scsi_Cmnd *) end->host_scribble);
633 end->host_scribble = (unsigned char*) new_SC;
637 staticinline Scsi_Cmnd *remove_first_SC(Scsi_Cmnd ** SC)
639 Scsi_Cmnd *ptr;
641 ptr = *SC;
642 if(ptr)
643 *SC = (Scsi_Cmnd *) (*SC)->host_scribble;
644 return ptr;
647 staticinline Scsi_Cmnd *remove_SC(Scsi_Cmnd ** SC,int target,int lun)
649 Scsi_Cmnd *ptr, *prev;
651 for(ptr = *SC, prev = NULL;
652 ptr && ((ptr->target != target) || (ptr->lun != lun));
653 prev = ptr, ptr = (Scsi_Cmnd *) ptr->host_scribble);
655 if(ptr) {
656 if(prev)
657 prev->host_scribble = ptr->host_scribble;
658 else
659 *SC = (Scsi_Cmnd *) ptr->host_scribble;
661 return ptr;
665 * read inbound byte and wait for ACK to get low
667 static voidmake_acklow(struct Scsi_Host *shpnt)
669 SETPORT(SXFRCTL0, CH1 | SPIOEN);
670 GETPORT(SCSIDAT);
671 SETPORT(SXFRCTL0, CH1);
673 while(TESTHI(SCSISIG, ACKI))
674 barrier();
678 * detect current phase more reliable:
679 * phase is valid, when the target asserts REQ after we've deasserted ACK.
681 * return value is a valid phase or an error code.
683 * errorcodes:
684 * P_BUSFREE BUS FREE phase detected
685 * P_PARITY parity error in DATA phase
687 static intgetphase(struct Scsi_Host *shpnt)
689 int phase, sstat1;
691 while(1) {
693 while(!((sstat1 =GETPORT(SSTAT1)) & (BUSFREE | SCSIRSTI | REQINIT)))
694 barrier();
695 if(sstat1 & BUSFREE)
696 return P_BUSFREE;
697 if(sstat1 & SCSIRSTI) {
698 printk("aha152x: RESET IN\n");
699 SETPORT(SSTAT1, SCSIRSTI);
701 }while(TESTHI(SCSISIG, ACKI) ||TESTLO(SSTAT1, REQINIT));
703 SETPORT(SSTAT1, CLRSCSIPERR);
705 phase =GETPORT(SCSISIG) & P_MASK;
707 if(TESTHI(SSTAT1, SCSIPERR)) {
708 if((phase & (CDO | MSGO)) ==0)/* DATA phase */
709 return P_PARITY;
711 make_acklow(shpnt);
712 }else
713 return phase;
717 /* called from init/main.c */
718 voidaha152x_setup(char*str,int*ints)
720 if(setup_count >2)
721 panic("aha152x: you can only configure up to two controllers\n");
723 setup[setup_count].conf = str;
724 setup[setup_count].io_port = ints[0] >=1? ints[1] :0x340;
725 setup[setup_count].irq = ints[0] >=2? ints[2] :11;
726 setup[setup_count].scsiid = ints[0] >=3? ints[3] :7;
727 setup[setup_count].reconnect = ints[0] >=4? ints[4] :1;
728 setup[setup_count].parity = ints[0] >=5? ints[5] :1;
729 setup[setup_count].synchronous = ints[0] >=6? ints[6] :0/* FIXME: 1 */;
730 setup[setup_count].delay = ints[0] >=7? ints[7] : DELAY_DEFAULT;
731 setup[setup_count].ext_trans = ints[0] >=8? ints[8] :0;
732 #ifdef DEBUG_AHA152X
733 setup[setup_count].debug = ints[0] >=9? ints[9] : DEBUG_DEFAULT;
734 if(ints[0] >9) {
735 printk("aha152x: usage: aha152x=<IOBASE>[,<IRQ>[,<SCSI ID>"
736 "[,<RECONNECT>[,<PARITY>[,<SYNCHRONOUS>[,<DELAY>[,<EXT_TRANS>[,<DEBUG>]]]]]]]]\n");
737 #else
738 if(ints[0] >8) {
739 printk("aha152x: usage: aha152x=<IOBASE>[,<IRQ>[,<SCSI ID>"
740 "[,<RECONNECT>[,<PARITY>[,<SYNCHRONOUS>[,<DELAY>[,<EXT_TRANS>]]]]]]]\n");
741 #endif
742 }else
743 setup_count++;
747 * Test, if port_base is valid.
749 static intaha152x_porttest(int io_port)
751 int i;
753 if(check_region(io_port, IO_RANGE))
754 return0;
756 SETPORT(io_port + O_DMACNTRL1,0);/* reset stack pointer */
757 for(i =0; i <16; i++)
758 SETPORT(io_port + O_STACK, i);
760 SETPORT(io_port + O_DMACNTRL1,0);/* reset stack pointer */
761 for(i =0; i <16&&GETPORT(io_port + O_STACK) == i; i++);
763 return(i ==16);
766 intaha152x_checksetup(struct aha152x_setup *setup)
768 int i;
770 #ifndef PCMCIA
771 for(i =0; i < PORT_COUNT && (setup->io_port != ports[i]); i++);
773 if(i == PORT_COUNT)
774 return0;
775 #endif
777 if(!aha152x_porttest(setup->io_port))
778 return0;
780 if((setup->irq < IRQ_MIN) || (setup->irq > IRQ_MAX))
781 return0;
783 if((setup->scsiid <0) || (setup->scsiid >7))
784 return0;
786 if((setup->reconnect <0) || (setup->reconnect >1))
787 return0;
789 if((setup->parity <0) || (setup->parity >1))
790 return0;
792 if((setup->synchronous <0) || (setup->synchronous >1))
793 return0;
795 if((setup->ext_trans <0) || (setup->ext_trans >1))
796 return0;
799 return1;
802 voidaha152x_swintr(int irqno,void*dev_id,struct pt_regs *regs)
804 struct Scsi_Host *shpnt = aha152x_host[irqno - IRQ_MIN];
806 if(!shpnt)
807 panic("aha152x: catched software interrupt for unknown controller.\n");
809 HOSTDATA(shpnt)->swint++;
813 intaha152x_detect(Scsi_Host_Template * tpnt)
815 int i, j, ok;
816 #if defined(AUTOCONF)
817 aha152x_config conf;
818 #endif
820 tpnt->proc_dir = &proc_scsi_aha152x;
822 for(i =0; i < IRQS; i++)
823 aha152x_host[i] = (struct Scsi_Host *) NULL;
825 if(setup_count) {
826 printk("aha152x: processing commandline: ");
828 for(i =0; i < setup_count; i++)
829 if(!aha152x_checksetup(&setup[i])) {
830 printk("\naha152x: %s\n", setup[i].conf);
831 printk("aha152x: invalid line (controller=%d)\n", i +1);
833 printk("ok\n");
835 #ifdef SETUP0
836 if(setup_count <2) {
837 struct aha152x_setup override = SETUP0;
839 if(setup_count ==0|| (override.io_port != setup[0].io_port))
840 if(!aha152x_checksetup(&override)) {
841 printk("\naha152x: invalid override SETUP0={0x%x,%d,%d,%d,%d,%d,%d,%d}\n",
842 override.io_port,
843 override.irq,
844 override.scsiid,
845 override.reconnect,
846 override.parity,
847 override.synchronous,
848 override.delay,
849 override.ext_trans);
850 }else
851 setup[setup_count++] = override;
853 #endif
855 #ifdef SETUP1
856 if(setup_count <2) {
857 struct aha152x_setup override = SETUP1;
859 if(setup_count ==0|| (override.io_port != setup[0].io_port))
860 if(!aha152x_checksetup(&override)) {
861 printk("\naha152x: invalid override SETUP1={0x%x,%d,%d,%d,%d,%d,%d,%d}\n",
862 override.io_port,
863 override.irq,
864 override.scsiid,
865 override.reconnect,
866 override.parity,
867 override.synchronous,
868 override.delay,
869 override.ext_trans);
870 }else
871 setup[setup_count++] = override;
873 #endif
875 #if defined(MODULE)
876 if(setup_count <2&& aha152x[0] !=0) {
877 setup[setup_count].conf ="";
878 setup[setup_count].io_port = aha152x[0];
879 setup[setup_count].irq = aha152x[1];
880 setup[setup_count].scsiid = aha152x[2];
881 setup[setup_count].reconnect = aha152x[3];
882 setup[setup_count].parity = aha152x[4];
883 setup[setup_count].synchronous = aha152x[5];
884 setup[setup_count].delay = aha152x[6];
885 setup[setup_count].ext_trans = aha152x[7];
886 #ifdef DEBUG_AHA152X
887 setup[setup_count].debug = aha152x[8];
888 #endif
889 if(aha152x_checksetup(&setup[setup_count]))
890 setup_count++;
891 else
892 printk("\naha152x: invalid module argument aha152x=0x%x,%d,%d,%d,%d,%d,%d,%d\n",
893 setup[setup_count].io_port,
894 setup[setup_count].irq,
895 setup[setup_count].scsiid,
896 setup[setup_count].reconnect,
897 setup[setup_count].parity,
898 setup[setup_count].synchronous,
899 setup[setup_count].delay,
900 setup[setup_count].ext_trans);
902 if(setup_count <2&& aha152x1[0] !=0) {
903 setup[setup_count].conf ="";
904 setup[setup_count].io_port = aha152x1[0];
905 setup[setup_count].irq = aha152x1[1];
906 setup[setup_count].scsiid = aha152x1[2];
907 setup[setup_count].reconnect = aha152x1[3];
908 setup[setup_count].parity = aha152x1[4];
909 setup[setup_count].synchronous = aha152x1[5];
910 setup[setup_count].delay = aha152x1[6];
911 setup[setup_count].ext_trans = aha152x1[7];
912 #ifdef DEBUG_AHA152X
913 setup[setup_count].debug = aha152x1[8];
914 #endif
915 if(aha152x_checksetup(&setup[setup_count]))
916 setup_count++;
917 else
918 printk("\naha152x: invalid module argument aha152x1=0x%x,%d,%d,%d,%d,%d,%d,%d\n",
919 setup[setup_count].io_port,
920 setup[setup_count].irq,
921 setup[setup_count].scsiid,
922 setup[setup_count].reconnect,
923 setup[setup_count].parity,
924 setup[setup_count].synchronous,
925 setup[setup_count].delay,
926 setup[setup_count].ext_trans);
928 #endif
930 #if defined(AUTOCONF)
931 if(setup_count <2) {
932 #if !defined(SKIP_BIOSTEST)
933 ok =0;
934 for(i =0; i < ADDRESS_COUNT && !ok; i++)
935 for(j =0; (j < SIGNATURE_COUNT) && !ok; j++)
936 ok =check_signature(addresses[i] + signatures[j].sig_offset,
937 signatures[j].signature, signatures[j].sig_length);
939 if(!ok && setup_count ==0)
940 return0;
942 printk("aha152x: BIOS test: passed, ");
943 #else
944 printk("aha152x: ");
945 #endif/* !SKIP_BIOSTEST */
947 ok =0;
948 for(i =0; i < PORT_COUNT && setup_count <2; i++) {
949 if((setup_count ==1) && (setup[0].io_port == ports[i]))
950 continue;
952 if(aha152x_porttest(ports[i])) {
953 ok++;
954 setup[setup_count].io_port = ports[i];
956 conf.cf_port =
957 (GETPORT(ports[i] + O_PORTA) <<8) +GETPORT(ports[i] + O_PORTB);
959 setup[setup_count].irq = IRQ_MIN + conf.cf_irq;
960 setup[setup_count].scsiid = conf.cf_id;
961 setup[setup_count].reconnect = conf.cf_tardisc;
962 setup[setup_count].parity = !conf.cf_parity;
963 setup[setup_count].synchronous =0/* FIXME: conf.cf_syncneg */;
964 setup[setup_count].delay = DELAY_DEFAULT;
965 setup[setup_count].ext_trans =0;
966 #ifdef DEBUG_AHA152X
967 setup[setup_count].debug = DEBUG_DEFAULT;
968 #endif
969 setup_count++;
973 if(ok)
974 printk("auto configuration: ok, ");
976 #endif
978 printk("detected %d controller(s)\n", setup_count);
980 for(i =0; i < setup_count; i++) {
981 struct Scsi_Host *shpnt;
982 unsigned long int the_time;
984 shpnt = aha152x_host[setup[i].irq - IRQ_MIN] =
985 scsi_register(tpnt,sizeof(struct aha152x_hostdata));
986 registered_count++;
988 shpnt->io_port = setup[i].io_port;
989 shpnt->n_io_port = IO_RANGE;
990 shpnt->irq = setup[i].irq;
992 ISSUE_SC = (Scsi_Cmnd *) NULL;
993 CURRENT_SC = (Scsi_Cmnd *) NULL;
994 DISCONNECTED_SC = (Scsi_Cmnd *) NULL;
996 HOSTDATA(shpnt)->reconnect = setup[i].reconnect;
997 HOSTDATA(shpnt)->parity = setup[i].parity;
998 HOSTDATA(shpnt)->synchronous = setup[i].synchronous;
999 HOSTDATA(shpnt)->delay = setup[i].delay;
1000 HOSTDATA(shpnt)->ext_trans = setup[i].ext_trans;
1001 #ifdef DEBUG_AHA152X
1002 HOSTDATA(shpnt)->debug = setup[i].debug;
1003 #endif
1005 HOSTDATA(shpnt)->aborting =0;
1006 HOSTDATA(shpnt)->abortion_complete =0;
1007 HOSTDATA(shpnt)->abort_result =0;
1008 HOSTDATA(shpnt)->commands =0;
1010 HOSTDATA(shpnt)->message_len =0;
1012 for(j =0; j <8; j++)
1013 HOSTDATA(shpnt)->syncrate[j] =0;
1015 SETPORT(SCSIID, setup[i].scsiid <<4);
1016 shpnt->this_id = setup[i].scsiid;
1018 if(setup[i].reconnect)
1019 shpnt->can_queue = AHA152X_MAXQUEUE;
1021 /* RESET OUT */
1022 SETBITS(SCSISEQ, SCSIRSTO);
1023 do_pause(30);
1024 CLRBITS(SCSISEQ, SCSIRSTO);
1025 do_pause(setup[i].delay);
1027 aha152x_reset_ports(shpnt);
1029 printk("aha152x%d: vital data: PORTBASE=0x%03lx, IRQ=%d, SCSI ID=%d,"
1030 " reconnect=%s, parity=%s, synchronous=%s, delay=%d, extended translation=%s\n",
1032 shpnt->io_port,
1033 shpnt->irq,
1034 shpnt->this_id,
1035 HOSTDATA(shpnt)->reconnect ?"enabled":"disabled",
1036 HOSTDATA(shpnt)->parity ?"enabled":"disabled",
1037 HOSTDATA(shpnt)->synchronous ?"enabled":"disabled",
1038 HOSTDATA(shpnt)->delay,
1039 HOSTDATA(shpnt)->ext_trans ?"enabled":"disabled");
1041 request_region(shpnt->io_port, IO_RANGE,"aha152x");/* Register */
1043 /* not expecting any interrupts */
1044 SETPORT(SIMODE0,0);
1045 SETPORT(SIMODE1,0);
1047 SETBITS(DMACNTRL0, INTEN);
1049 ok =request_irq(shpnt->irq, aha152x_swintr, SA_INTERRUPT,"aha152x", shpnt);
1050 if(ok <0) {
1051 if(ok == -EINVAL)
1052 printk("aha152x%d: bad IRQ %d.\n", i, shpnt->irq);
1053 else if(ok == -EBUSY)
1054 printk("aha152x%d: IRQ %d already in use.\n", i, shpnt->irq);
1055 else
1056 printk("\naha152x%d: Unexpected error code %d on requesting IRQ %d.\n", i, ok, shpnt->irq);
1057 printk("aha152x: driver needs an IRQ.\n");
1059 scsi_unregister(shpnt);
1060 registered_count--;
1061 release_region(shpnt->io_port, IO_RANGE);
1062 shpnt = aha152x_host[shpnt->irq - IRQ_MIN] =0;
1063 continue;
1065 HOSTDATA(shpnt)->swint =0;
1067 printk("aha152x: trying software interrupt, ");
1068 SETBITS(DMACNTRL0, SWINT);
1070 the_time = jiffies +100;
1071 while(!HOSTDATA(shpnt)->swint &&time_before(jiffies, the_time))
1072 barrier();
1074 free_irq(shpnt->irq, shpnt);
1076 if(!HOSTDATA(shpnt)->swint) {
1077 if(TESTHI(DMASTAT, INTSTAT)) {
1078 printk("lost.\n");
1079 }else{
1080 printk("failed.\n");
1083 printk("aha152x: IRQ %d possibly wrong. Please verify.\n", shpnt->irq);
1085 scsi_unregister(shpnt);
1086 registered_count--;
1087 release_region(shpnt->io_port, IO_RANGE);
1088 shpnt = aha152x_host[shpnt->irq - IRQ_MIN] =0;
1089 continue;
1091 printk("ok.\n");
1093 CLRBITS(DMACNTRL0, SWINT);
1095 /* clear interrupts */
1096 SETPORT(SSTAT0,0x7f);
1097 SETPORT(SSTAT1,0xef);
1099 if(request_irq(shpnt->irq, aha152x_intr, SA_INTERRUPT,"aha152x", shpnt) <0) {
1100 printk("aha152x: failed to reassign interrupt.\n");
1104 return(registered_count >0);
1108 intaha152x_release(struct Scsi_Host *shpnt)
1110 if(shpnt->irq)
1111 free_irq(shpnt->irq, shpnt);
1112 if(shpnt->io_port)
1113 release_region(shpnt->io_port, IO_RANGE);
1115 return0;
1119 * Queue a command and setup interrupts for a free bus.
1121 intaha152x_queue(Scsi_Cmnd * SCpnt,void(*done) (Scsi_Cmnd *))
1123 struct Scsi_Host *shpnt = SCpnt->host;
1124 unsigned long flags;
1126 #if defined(DEBUG_RACE)
1127 enter_driver("queue");
1128 #else
1129 #if defined(DEBUG_QUEUE)
1130 if(HOSTDATA(shpnt)->debug & debug_queue)
1131 printk("aha152x: queue(), ");
1132 #endif
1133 #endif
1135 #if defined(DEBUG_QUEUE)
1136 if(HOSTDATA(shpnt)->debug & debug_queue) {
1137 printk("SCpnt (target = %d lun = %d cmnd = ",
1138 SCpnt->target, SCpnt->lun);
1139 print_command(SCpnt->cmnd);
1140 printk(", cmd_len=%d, pieces = %d size = %u), ",
1141 SCpnt->cmd_len, SCpnt->use_sg, SCpnt->request_bufflen);
1142 disp_ports(shpnt);
1144 #endif
1146 SCpnt->scsi_done = done;
1148 /* setup scratch area
1149 SCp.ptr : buffer pointer
1150 SCp.this_residual : buffer length
1151 SCp.buffer : next buffer
1152 SCp.buffers_residual : left buffers in list
1153 SCp.phase : current state of the command */
1154 SCpnt->SCp.phase = not_issued;
1155 if(SCpnt->use_sg) {
1156 SCpnt->SCp.buffer = (struct scatterlist *) SCpnt->request_buffer;
1157 SCpnt->SCp.ptr = SCpnt->SCp.buffer->address;
1158 SCpnt->SCp.this_residual = SCpnt->SCp.buffer->length;
1159 SCpnt->SCp.buffers_residual = SCpnt->use_sg -1;
1160 }else{
1161 SCpnt->SCp.ptr = (char*) SCpnt->request_buffer;
1162 SCpnt->SCp.this_residual = SCpnt->request_bufflen;
1163 SCpnt->SCp.buffer = NULL;
1164 SCpnt->SCp.buffers_residual =0;
1167 SCpnt->SCp.Status = CHECK_CONDITION;
1168 SCpnt->SCp.Message =0;
1169 SCpnt->SCp.have_data_in =0;
1170 SCpnt->SCp.sent_command =0;
1172 /* Turn led on, when this is the first command. */
1173 save_flags(flags);
1174 cli();
1175 HOSTDATA(shpnt)->commands++;
1176 if(HOSTDATA(shpnt)->commands ==1)
1177 SETPORT(PORTA,1);
1179 #if defined(DEBUG_QUEUES)
1180 if(HOSTDATA(shpnt)->debug & debug_queues)
1181 printk("i+ (%d), ",HOSTDATA(shpnt)->commands);
1182 #endif
1183 append_SC(&ISSUE_SC, SCpnt);
1185 /* Enable bus free interrupt, when we aren't currently on the bus */
1186 if(!CURRENT_SC) {
1187 SETPORT(SIMODE0, DISCONNECTED_SC ? ENSELDI :0);
1188 SETPORT(SIMODE1, ISSUE_SC ? ENBUSFREE :0);
1190 restore_flags(flags);
1192 #if defined(DEBUG_RACE)
1193 leave_driver("queue");
1194 #endif
1196 return0;
1200 * We only support commands in interrupt-driven fashion
1202 intaha152x_command(Scsi_Cmnd * SCpnt)
1204 printk("aha152x: interrupt driven driver; use aha152x_queue()\n");
1205 return-1;
1209 * Abort a queued command
1210 * (commands that are on the bus can't be aborted easily)
1212 intaha152x_abort(Scsi_Cmnd * SCpnt)
1214 struct Scsi_Host *shpnt = SCpnt->host;
1215 unsigned long flags;
1216 Scsi_Cmnd *ptr, *prev;
1218 save_flags(flags);
1219 cli();
1221 #if defined(DEBUG_ABORT)
1222 if(HOSTDATA(shpnt)->debug & debug_abort) {
1223 printk("aha152x: abort(), SCpnt=0x%08x, ", (unsigned int) SCpnt);
1224 show_queues(shpnt);
1226 #endif
1228 /* look for command in issue queue */
1229 for(ptr = ISSUE_SC, prev = NULL;
1230 ptr && ptr != SCpnt;
1231 prev = ptr, ptr = (Scsi_Cmnd *) ptr->host_scribble);
1233 if(ptr) {
1234 /* dequeue */
1235 if(prev)
1236 prev->host_scribble = ptr->host_scribble;
1237 else
1238 ISSUE_SC = (Scsi_Cmnd *) ptr->host_scribble;
1240 HOSTDATA(shpnt)->commands--;
1242 restore_flags(flags);
1244 ptr->host_scribble = NULL;
1245 ptr->result = DID_ABORT <<16;
1246 spin_lock_irqsave(&io_request_lock, flags);
1247 ptr->scsi_done(ptr);
1248 spin_unlock_irqrestore(&io_request_lock, flags);
1250 return SCSI_ABORT_SUCCESS;
1252 /* if the bus is busy or a command is currently processed,
1253 we can't do anything more */
1254 if(TESTLO(SSTAT1, BUSFREE) || (CURRENT_SC && CURRENT_SC != SCpnt)) {
1255 /* fail abortion, if bus is busy */
1257 if(!CURRENT_SC)
1258 printk("bus busy w/o current command, ");
1260 restore_flags(flags);
1262 return SCSI_ABORT_BUSY;
1264 /* bus is free */
1266 if(CURRENT_SC) {
1267 HOSTDATA(shpnt)->commands--;
1269 /* target entered bus free before COMMAND COMPLETE, nothing to abort */
1270 restore_flags(flags);
1271 spin_lock_irqsave(&io_request_lock, flags);
1272 CURRENT_SC->result = DID_ERROR <<16;
1273 CURRENT_SC->scsi_done(CURRENT_SC);
1274 CURRENT_SC = (Scsi_Cmnd *) NULL;
1275 spin_unlock_irqrestore(&io_request_lock, flags);
1277 return SCSI_ABORT_SUCCESS;
1279 /* look for command in disconnected queue */
1280 for(ptr = DISCONNECTED_SC, prev = NULL;
1281 ptr && ptr != SCpnt;
1282 prev = ptr, ptr = (Scsi_Cmnd *) ptr->host_scribble);
1284 if(!ptr) {
1285 /* command wasn't found */
1286 printk("command not found\n");
1287 restore_flags(flags);
1289 return SCSI_ABORT_NOT_RUNNING;
1291 if(!HOSTDATA(shpnt)->aborting) {
1292 /* dequeue */
1293 if(prev)
1294 prev->host_scribble = ptr->host_scribble;
1295 else
1296 DISCONNECTED_SC = (Scsi_Cmnd *) ptr->host_scribble;
1298 HOSTDATA(shpnt)->commands--;
1300 /* set command current and initiate selection,
1301 let the interrupt routine take care of the abortion */
1302 CURRENT_SC = ptr;
1303 ptr->SCp.phase = in_selection | aborted;
1304 SETPORT(SCSIID, (shpnt->this_id << OID_) | CURRENT_SC->target);
1306 ADDMSG(ABORT);
1308 /* enable interrupts for SELECTION OUT DONE and SELECTION TIME OUT */
1309 SETPORT(SIMODE0, ENSELDO | (DISCONNECTED_SC ? ENSELDI :0));
1310 SETPORT(SIMODE1, ENSELTIMO);
1312 /* Enable SELECTION OUT sequence */
1313 SETBITS(SCSISEQ, ENSELO | ENAUTOATNO);
1315 SETBITS(DMACNTRL0, INTEN);
1316 HOSTDATA(shpnt)->abort_result = SCSI_ABORT_SUCCESS;
1317 HOSTDATA(shpnt)->aborting++;
1318 HOSTDATA(shpnt)->abortion_complete =0;
1320 restore_flags(flags);
1322 /* sleep until the abortion is complete */
1323 while(!HOSTDATA(shpnt)->abortion_complete)
1324 barrier();
1325 HOSTDATA(shpnt)->aborting =0;
1327 returnHOSTDATA(shpnt)->abort_result;
1328 }else{
1329 /* we're already aborting a command */
1330 restore_flags(flags);
1332 return SCSI_ABORT_BUSY;
1337 * Restore default values to the AIC-6260 registers and reset the fifos
1339 static voidaha152x_reset_ports(struct Scsi_Host *shpnt)
1341 /* disable interrupts */
1342 SETPORT(DMACNTRL0, RSTFIFO);
1344 SETPORT(SCSISEQ,0);
1346 SETPORT(SXFRCTL1,0);
1347 SETPORT(SCSISIG,0);
1348 SETPORT(SCSIRATE,0);
1350 /* clear all interrupt conditions */
1351 SETPORT(SSTAT0,0x7f);
1352 SETPORT(SSTAT1,0xef);
1354 SETPORT(SSTAT4, SYNCERR | FWERR | FRERR);
1356 SETPORT(DMACNTRL0,0);
1357 SETPORT(DMACNTRL1,0);
1359 SETPORT(BRSTCNTRL,0xf1);
1361 /* clear SCSI fifo and transfer count */
1362 SETPORT(SXFRCTL0, CH1 | CLRCH1 | CLRSTCNT);
1363 SETPORT(SXFRCTL0, CH1);
1365 /* enable interrupts */
1366 SETPORT(SIMODE0, DISCONNECTED_SC ? ENSELDI :0);
1367 SETPORT(SIMODE1, ISSUE_SC ? ENBUSFREE :0);
1371 * Reset registers, reset a hanging bus and
1372 * kill active and disconnected commands for target w/o soft reset
1374 intaha152x_reset(Scsi_Cmnd * SCpnt,unsigned int unused)
1376 struct Scsi_Host *shpnt = SCpnt->host;
1377 unsigned long flags;
1378 Scsi_Cmnd *ptr, *prev, *next;
1380 aha152x_reset_ports(shpnt);
1382 /* Reset, if bus hangs */
1383 if(TESTLO(SSTAT1, BUSFREE)) {
1384 CLRBITS(DMACNTRL0, INTEN);
1386 #if defined(DEBUG_RESET)
1387 if(HOSTDATA(shpnt)->debug & debug_reset) {
1388 printk("aha152x: reset(), bus not free: SCSI RESET OUT\n");
1389 show_queues(shpnt);
1391 #endif
1393 ptr = CURRENT_SC;
1394 if(ptr && !ptr->device->soft_reset) {
1395 ptr->host_scribble = NULL;
1396 ptr->result = DID_RESET <<16;
1397 ptr->scsi_done(CURRENT_SC);
1398 CURRENT_SC = NULL;
1400 save_flags(flags);
1401 cli();
1402 prev = NULL;
1403 ptr = DISCONNECTED_SC;
1404 while(ptr) {
1405 if(!ptr->device->soft_reset) {
1406 if(prev)
1407 prev->host_scribble = ptr->host_scribble;
1408 else
1409 DISCONNECTED_SC = (Scsi_Cmnd *) ptr->host_scribble;
1411 next = (Scsi_Cmnd *) ptr->host_scribble;
1413 ptr->host_scribble = NULL;
1414 ptr->result = DID_RESET <<16;
1415 spin_lock_irqsave(&io_request_lock, flags);
1416 ptr->scsi_done(ptr);
1417 spin_unlock_irqrestore(&io_request_lock, flags);
1419 ptr = next;
1420 }else{
1421 prev = ptr;
1422 ptr = (Scsi_Cmnd *) ptr->host_scribble;
1425 restore_flags(flags);
1427 #if defined(DEBUG_RESET)
1428 if(HOSTDATA(shpnt)->debug & debug_reset) {
1429 printk("commands on targets w/ soft-resets:\n");
1430 show_queues(shpnt);
1432 #endif
1434 /* RESET OUT */
1435 SETPORT(SCSISEQ, SCSIRSTO);
1436 do_pause(30);
1437 SETPORT(SCSISEQ,0);
1438 do_pause(DELAY);
1440 SETPORT(SIMODE0, DISCONNECTED_SC ? ENSELDI :0);
1441 SETPORT(SIMODE1, ISSUE_SC ? ENBUSFREE :0);
1443 SETPORT(DMACNTRL0, INTEN);
1445 return SCSI_RESET_SUCCESS;
1449 * Return the "logical geometry"
1451 intaha152x_biosparam(Scsi_Disk * disk, kdev_t dev,int*info_array)
1453 struct Scsi_Host *shpnt = disk->device->host;
1455 #if defined(DEBUG_BIOSPARAM)
1456 if(HOSTDATA(shpnt)->debug & debug_biosparam)
1457 printk("aha152x_biosparam: dev=%s, size=%d, ",
1458 kdevname(dev), disk->capacity);
1459 #endif
1461 /* try default translation */
1462 info_array[0] =64;
1463 info_array[1] =32;
1464 info_array[2] = disk->capacity / (64*32);
1466 /* for disks >1GB do some guessing */
1467 if(info_array[2] >=1024) {
1468 int info[3];
1470 /* try to figure out the geometry from the partition table */
1471 if(scsicam_bios_param(disk, dev, info) <0||
1472 !((info[0] ==64&& info[1] ==32) || (info[0] ==255&& info[1] ==63))) {
1473 if(EXT_TRANS) {
1474 printk("aha152x: unable to verify geometry for disk with >1GB.\n"
1475 " using extended translation.\n");
1476 info_array[0] =255;
1477 info_array[1] =63;
1478 info_array[2] = disk->capacity / (255*63);
1479 }else{
1480 printk("aha152x: unable to verify geometry for disk with >1GB.\n"
1481 " Using default translation. Please verify yourself.\n"
1482 " Perhaps you need to enable extended translation in the driver.\n"
1483 " See /usr/src/linux/drivers/scsi/aha152x.c for details.\n");
1485 }else{
1486 info_array[0] = info[0];
1487 info_array[1] = info[1];
1488 info_array[2] = info[2];
1490 if(info[0] ==255&& !EXT_TRANS) {
1491 printk("aha152x: current partition table is using extended translation.\n"
1492 " using it also, although it's not explicty enabled.\n");
1496 #if defined(DEBUG_BIOSPARAM)
1497 if(HOSTDATA(shpnt)->debug & debug_biosparam) {
1498 printk("bios geometry: head=%d, sec=%d, cyl=%d\n",
1499 info_array[0], info_array[1], info_array[2]);
1500 printk("WARNING: check, if the bios geometry is correct.\n");
1502 #endif
1504 return0;
1508 * Internal done function
1510 voidaha152x_done(struct Scsi_Host *shpnt,int error)
1512 unsigned long flags;
1513 Scsi_Cmnd *done_SC;
1515 #if defined(DEBUG_DONE)
1516 if(HOSTDATA(shpnt)->debug & debug_done) {
1517 printk("\naha152x: done(), ");
1518 disp_ports(shpnt);
1520 #endif
1522 if(CURRENT_SC) {
1523 #if defined(DEBUG_DONE)
1524 if(HOSTDATA(shpnt)->debug & debug_done)
1525 printk("done(%x), ", error);
1526 #endif
1528 save_flags(flags);
1529 cli();
1531 done_SC = CURRENT_SC;
1532 CURRENT_SC = NULL;
1534 /* turn led off, when no commands are in the driver */
1535 HOSTDATA(shpnt)->commands--;
1536 if(!HOSTDATA(shpnt)->commands)
1537 SETPORT(PORTA,0);/* turn led off */
1539 #if defined(DEBUG_QUEUES)
1540 if(HOSTDATA(shpnt)->debug & debug_queues)
1541 printk("ok (%d), ",HOSTDATA(shpnt)->commands);
1542 #endif
1543 restore_flags(flags);
1545 SETPORT(SIMODE0, DISCONNECTED_SC ? ENSELDI :0);
1546 SETPORT(SIMODE1, ISSUE_SC ? ENBUSFREE :0);
1548 #if 0
1549 /* Why poll for the BUS FREE phase, when we have setup the interrupt!? */
1550 #if defined(DEBUG_PHASES)
1551 if(HOSTDATA(shpnt)->debug & debug_phases)
1552 printk("BUS FREE loop, ");
1553 #endif
1554 while(TESTLO(SSTAT1, BUSFREE))
1555 barrier();
1556 #if defined(DEBUG_PHASES)
1557 if(HOSTDATA(shpnt)->debug & debug_phases)
1558 printk("BUS FREE\n");
1559 #endif
1560 #endif
1562 done_SC->result = error;
1563 if(done_SC->scsi_done) {
1564 #if defined(DEBUG_DONE)
1565 if(HOSTDATA(shpnt)->debug & debug_done)
1566 printk("calling scsi_done, ");
1567 #endif
1568 spin_lock_irqsave(&io_request_lock, flags);
1569 done_SC->scsi_done(done_SC);
1570 spin_unlock_irqrestore(&io_request_lock, flags);
1571 #if defined(DEBUG_DONE)
1572 if(HOSTDATA(shpnt)->debug & debug_done)
1573 printk("done returned, ");
1574 #endif
1575 }else
1576 panic("aha152x: current_SC->scsi_done() == NULL");
1577 }else
1578 aha152x_panic(shpnt,"done() called outside of command");
1582 static voidaha152x_complete(struct Scsi_Host *);
1584 static struct tq_struct aha152x_tq;
1587 * Run service completions on the card with interrupts enabled.
1590 static voidaha152x_run(void)
1592 int i;
1593 for(i =0; i < IRQS; i++) {
1594 struct Scsi_Host *shpnt = aha152x_host[i];
1595 if(shpnt &&HOSTDATA(shpnt)->service) {
1596 HOSTDATA(shpnt)->service =0;
1597 aha152x_complete(shpnt);
1603 * Interrupts handler (main routine of the driver)
1606 static voidaha152x_intr(int irqno,void*dev_id,struct pt_regs *regs)
1608 struct Scsi_Host *shpnt = aha152x_host[irqno - IRQ_MIN];
1610 #if defined(DEBUG_RACE)
1611 enter_driver("intr");
1612 #else
1613 #if defined(DEBUG_INTR)
1614 if(HOSTDATA(shpnt)->debug & debug_intr)
1615 printk("\naha152x: intr(), ");
1616 #endif
1617 #endif
1619 if(!shpnt)
1620 panic("aha152x: catched interrupt for unknown controller.\n");
1622 /* no more interrupts from the controller, while we're busy.
1623 INTEN is restored by the BH handler */
1625 CLRBITS(DMACNTRL0, INTEN);
1627 /* Poke the BH handler */
1629 HOSTDATA(shpnt)->service =1;
1630 aha152x_tq.routine = (void*) aha152x_run;
1631 queue_task(&aha152x_tq, &tq_immediate);
1632 mark_bh(IMMEDIATE_BH);
1635 static voidaha152x_complete(struct Scsi_Host *shpnt)
1637 unsigned int flags;
1638 int done =0, phase;
1640 /* disconnected target is trying to reconnect.
1641 Only possible, if we have disconnected nexuses and
1642 nothing is occupying the bus.
1645 if(TESTHI(SSTAT0, SELDI) &&
1646 DISCONNECTED_SC &&
1647 (!CURRENT_SC || (CURRENT_SC->SCp.phase & in_selection))) {
1648 int identify_msg, target, i;
1650 /* Avoid conflicts when a target reconnects
1651 while we are trying to connect to another. */
1652 if(CURRENT_SC) {
1653 #if defined(DEBUG_QUEUES)
1654 if(HOSTDATA(shpnt)->debug & debug_queues)
1655 printk("i+, ");
1656 #endif
1657 save_flags(flags);
1658 cli();
1659 append_SC(&ISSUE_SC, CURRENT_SC);
1660 CURRENT_SC = NULL;
1661 restore_flags(flags);
1663 /* disable sequences */
1664 SETPORT(SCSISEQ,0);
1665 SETPORT(SSTAT0, CLRSELDI);
1666 SETPORT(SSTAT1, CLRBUSFREE);
1668 #if defined(DEBUG_QUEUES) || defined(DEBUG_PHASES)
1669 if(HOSTDATA(shpnt)->debug & (debug_queues | debug_phases))
1670 printk("reselected, ");
1671 #endif
1673 i =GETPORT(SELID) & ~(1<< shpnt->this_id);
1674 target =0;
1676 if(i ==0)
1677 aha152x_panic(shpnt,"reconnecting target unknown");
1679 for(; (i &1) ==0; target++, i >>=1);
1681 #if defined(DEBUG_QUEUES)
1682 if(HOSTDATA(shpnt)->debug & debug_queues)
1683 printk("SELID=%02x, target=%d, ",GETPORT(SELID), target);
1684 #endif
1685 SETPORT(SCSIID, (shpnt->this_id << OID_) | target);
1686 SETPORT(SCSISEQ, ENRESELI);
1688 if(TESTLO(SSTAT0, SELDI))
1689 aha152x_panic(shpnt,"RESELI failed");
1691 SETPORT(SCSIRATE,HOSTDATA(shpnt)->syncrate[target] &0x7f);
1693 SETPORT(SCSISIG, P_MSGI);
1695 /* Get identify message */
1696 if((i =getphase(shpnt)) != P_MSGI) {
1697 printk("target doesn't enter MSGI to identify (phase=%02x)\n", i);
1698 aha152x_panic(shpnt,"unknown lun");
1700 SETPORT(SCSISEQ,0);
1702 SETPORT(SXFRCTL0, CH1);
1704 identify_msg =GETPORT(SCSIBUS);
1706 if(!(identify_msg & IDENTIFY_BASE)) {
1707 printk("target=%d, inbound message (%02x) != IDENTIFY\n",
1708 target, identify_msg);
1709 aha152x_panic(shpnt,"unknown lun");
1711 #if defined(DEBUG_QUEUES)
1712 if(HOSTDATA(shpnt)->debug & debug_queues)
1713 printk("identify=%02x, lun=%d, ", identify_msg, identify_msg &0x3f);
1714 #endif
1716 save_flags(flags);
1717 cli();
1719 #if defined(DEBUG_QUEUES)
1720 if(HOSTDATA(shpnt)->debug & debug_queues)
1721 printk("d-, ");
1722 #endif
1723 CURRENT_SC =remove_SC(&DISCONNECTED_SC, target, identify_msg &0x3f);
1725 if(!CURRENT_SC) {
1726 printk("lun=%d, ", identify_msg &0x3f);
1727 aha152x_panic(shpnt,"no disconnected command for that lun");
1729 CURRENT_SC->SCp.phase &= ~disconnected;
1730 restore_flags(flags);
1732 make_acklow(shpnt);
1733 if(getphase(shpnt) != P_MSGI) {
1734 SETPORT(SIMODE0,0);
1735 SETPORT(SIMODE1, ENPHASEMIS | ENBUSFREE);
1736 #if defined(DEBUG_RACE)
1737 leave_driver("(reselected) intr");
1738 #endif
1739 SETBITS(DMACNTRL0, INTEN);
1740 return;
1743 /* Check, if we aren't busy with a command */
1744 if(!CURRENT_SC) {
1745 /* bus is free to issue a queued command */
1746 if(TESTHI(SSTAT1, BUSFREE) && ISSUE_SC) {
1747 save_flags(flags);
1748 cli();
1749 #if defined(DEBUG_QUEUES)
1750 if(HOSTDATA(shpnt)->debug & debug_queues)
1751 printk("i-, ");
1752 #endif
1753 CURRENT_SC =remove_first_SC(&ISSUE_SC);
1754 restore_flags(flags);
1756 #if defined(DEBUG_INTR) || defined(DEBUG_SELECTION) || defined(DEBUG_PHASES)
1757 if(HOSTDATA(shpnt)->debug & (debug_intr | debug_selection | debug_phases))
1758 printk("issuing command, ");
1759 #endif
1760 CURRENT_SC->SCp.phase = in_selection;
1762 #if defined(DEBUG_INTR) || defined(DEBUG_SELECTION) || defined(DEBUG_PHASES)
1763 if(HOSTDATA(shpnt)->debug & (debug_intr | debug_selection | debug_phases))
1764 printk("selecting %d, ", CURRENT_SC->target);
1765 #endif
1766 SETPORT(SCSIID, (shpnt->this_id << OID_) | CURRENT_SC->target);
1768 /* Enable interrupts for SELECTION OUT DONE and SELECTION OUT INITIATED */
1769 SETPORT(SXFRCTL1,HOSTDATA(shpnt)->parity ? (ENSPCHK | ENSTIMER) : ENSTIMER);
1771 /* enable interrupts for SELECTION OUT DONE and SELECTION TIME OUT */
1772 SETPORT(SIMODE0, ENSELDO | (DISCONNECTED_SC ? ENSELDI :0));
1773 SETPORT(SIMODE1, ENSELTIMO);
1775 /* Enable SELECTION OUT sequence */
1776 SETBITS(SCSISEQ, ENSELO | ENAUTOATNO);
1778 }else{
1779 /* No command we are busy with and no new to issue */
1780 printk("aha152x: ignoring spurious interrupt, nothing to do\n");
1781 if(TESTHI(DMACNTRL0, SWINT)) {
1782 printk("aha152x: SWINT is set! Why?\n");
1783 CLRBITS(DMACNTRL0, SWINT);
1785 show_queues(shpnt);
1788 #if defined(DEBUG_RACE)
1789 leave_driver("(selecting) intr");
1790 #endif
1791 SETBITS(DMACNTRL0, INTEN);
1792 return;
1794 /* the bus is busy with something */
1796 #if defined(DEBUG_INTR)
1797 if(HOSTDATA(shpnt)->debug & debug_intr)
1798 disp_ports(shpnt);
1799 #endif
1801 /* we are waiting for the result of a selection attempt */
1802 if(CURRENT_SC->SCp.phase & in_selection) {
1803 if(TESTLO(SSTAT1, SELTO)) {
1804 /* no timeout */
1805 if(TESTHI(SSTAT0, SELDO)) {
1806 /* clear BUS FREE interrupt */
1807 SETPORT(SSTAT1, CLRBUSFREE);
1809 /* Disable SELECTION OUT sequence */
1810 CLRBITS(SCSISEQ, ENSELO | ENAUTOATNO);
1812 /* Disable SELECTION OUT DONE interrupt */
1813 CLRBITS(SIMODE0, ENSELDO);
1814 CLRBITS(SIMODE1, ENSELTIMO);
1816 if(TESTLO(SSTAT0, SELDO)) {
1817 printk("aha152x: passing bus free condition\n");
1819 #if defined(DEBUG_RACE)
1820 leave_driver("(passing bus free) intr");
1821 #endif
1822 SETBITS(DMACNTRL0, INTEN);
1824 if(CURRENT_SC->SCp.phase & aborted) {
1825 HOSTDATA(shpnt)->abort_result = SCSI_ABORT_ERROR;
1826 HOSTDATA(shpnt)->abortion_complete++;
1828 aha152x_done(shpnt, DID_NO_CONNECT <<16);
1830 return;
1832 #if defined(DEBUG_SELECTION) || defined(DEBUG_PHASES)
1833 if(HOSTDATA(shpnt)->debug & (debug_selection | debug_phases))
1834 printk("SELDO (SELID=%x), ",GETPORT(SELID));
1835 #endif
1837 /* selection was done */
1838 SETPORT(SSTAT0, CLRSELDO);
1840 #if defined(DEBUG_ABORT)
1841 if((HOSTDATA(shpnt)->debug & debug_abort) && (CURRENT_SC->SCp.phase & aborted))
1842 printk("(ABORT) target selected, ");
1843 #endif
1845 CURRENT_SC->SCp.phase &= ~in_selection;
1846 CURRENT_SC->SCp.phase |= in_other;
1848 ADDMSG(IDENTIFY(HOSTDATA(shpnt)->reconnect, CURRENT_SC->lun));
1850 if(!(SYNCRATE &0x80) &&HOSTDATA(shpnt)->synchronous) {
1851 ADDMSG(EXTENDED_MESSAGE);
1852 ADDMSG(3);
1853 ADDMSG(EXTENDED_SDTR);
1854 ADDMSG(50);
1855 ADDMSG(8);
1857 printk("outbound SDTR: ");
1858 print_msg(&MSG(MSGLEN -5));
1860 SYNCRATE =0x80;
1861 CURRENT_SC->SCp.phase |= in_sync;
1863 #if defined(DEBUG_RACE)
1864 leave_driver("(SELDO) intr");
1865 #endif
1866 SETPORT(SCSIRATE, SYNCRATE &0x7f);
1868 SETPORT(SCSISIG, P_MSGO);
1870 SETPORT(SIMODE0,0);
1871 SETPORT(SIMODE1, ENREQINIT | ENBUSFREE);
1872 SETBITS(DMACNTRL0, INTEN);
1874 return;
1875 }else
1876 aha152x_panic(shpnt,"neither timeout nor selection\007");
1877 }else{
1878 #if defined(DEBUG_SELECTION) || defined(DEBUG_PHASES)
1879 if(HOSTDATA(shpnt)->debug & (debug_selection | debug_phases))
1880 printk("SELTO, ");
1881 #endif
1882 /* end selection attempt */
1883 CLRBITS(SCSISEQ, ENSELO | ENAUTOATNO);
1885 /* timeout */
1886 SETPORT(SSTAT1, CLRSELTIMO);
1888 SETPORT(SIMODE0, DISCONNECTED_SC ? ENSELDI :0);
1889 SETPORT(SIMODE1, ISSUE_SC ? ENBUSFREE :0);
1890 SETBITS(DMACNTRL0, INTEN);
1891 #if defined(DEBUG_RACE)
1892 leave_driver("(SELTO) intr");
1893 #endif
1895 if(CURRENT_SC->SCp.phase & aborted) {
1896 #if defined(DEBUG_ABORT)
1897 if(HOSTDATA(shpnt)->debug & debug_abort)
1898 printk("(ABORT) selection timeout, ");
1899 #endif
1900 HOSTDATA(shpnt)->abort_result = SCSI_ABORT_ERROR;
1901 HOSTDATA(shpnt)->abortion_complete++;
1903 if(TESTLO(SSTAT0, SELINGO))
1904 /* ARBITRATION not won */
1905 aha152x_done(shpnt, DID_BUS_BUSY <<16);
1906 else
1907 /* ARBITRATION won, but SELECTION failed */
1908 aha152x_done(shpnt, DID_NO_CONNECT <<16);
1910 return;
1913 /* enable interrupt, when target leaves current phase */
1914 phase =getphase(shpnt);
1915 if(!(phase & ~P_MASK))/* "real" phase */
1916 SETPORT(SCSISIG, phase);
1917 SETPORT(SSTAT1, CLRPHASECHG);
1918 CURRENT_SC->SCp.phase =
1919 (CURRENT_SC->SCp.phase & ~((P_MASK |1) <<16)) | (phase <<16);
1921 /* information transfer phase */
1922 switch(phase) {
1923 case P_MSGO:/* MESSAGE OUT */
1925 int i, identify =0, abort =0;
1927 #if defined(DEBUG_INTR) || defined(DEBUG_MSGO) || defined(DEBUG_PHASES)
1928 if(HOSTDATA(shpnt)->debug & (debug_intr | debug_msgo | debug_phases))
1929 printk("MESSAGE OUT, ");
1930 #endif
1931 if(MSGLEN ==0) {
1932 ADDMSG(MESSAGE_REJECT);
1933 #if defined(DEBUG_MSGO)
1934 if(HOSTDATA(shpnt)->debug & debug_msgo)
1935 printk("unexpected MESSAGE OUT phase; rejecting, ");
1936 #endif
1938 CLRBITS(SXFRCTL0, ENDMA);
1940 SETPORT(SIMODE0,0);
1941 SETPORT(SIMODE1, ENPHASEMIS | ENREQINIT | ENBUSFREE);
1943 /* wait for data latch to become ready or a phase change */
1944 while(TESTLO(DMASTAT, INTSTAT))
1945 barrier();
1947 #if defined(DEBUG_MSGO)
1948 if(HOSTDATA(shpnt)->debug & debug_msgo) {
1949 int i;
1951 printk("messages (");
1952 for(i =0; i < MSGLEN; i +=print_msg(&MSG(i)),printk(" "));
1953 printk("), ");
1955 #endif
1957 for(i =0; i < MSGLEN &&TESTLO(SSTAT1, PHASEMIS); i++) {
1958 #if defined(DEBUG_MSGO)
1959 if(HOSTDATA(shpnt)->debug & debug_msgo)
1960 printk("%x ",MSG(i));
1961 #endif
1962 if(i == MSGLEN -1) {
1963 /* Leave MESSAGE OUT after transfer */
1964 SETPORT(SSTAT1, CLRATNO);
1966 SETPORT(SCSIDAT,MSG(i));
1968 make_acklow(shpnt);
1969 getphase(shpnt);
1971 if(MSG(i) ==IDENTIFY(HOSTDATA(shpnt)->reconnect, CURRENT_SC->lun))
1972 identify++;
1974 if(MSG(i) == ABORT)
1975 abort++;
1979 MSGLEN =0;
1981 if(identify)
1982 CURRENT_SC->SCp.phase |= sent_ident;
1984 if(abort) {
1985 /* revive abort(); abort() enables interrupts */
1986 HOSTDATA(shpnt)->abort_result = SCSI_ABORT_SUCCESS;
1987 HOSTDATA(shpnt)->abortion_complete++;
1989 CURRENT_SC->SCp.phase &= ~(P_MASK <<16);
1991 /* exit */
1992 SETBITS(DMACNTRL0, INTEN);
1993 #if defined(DEBUG_RACE)
1994 leave_driver("(ABORT) intr");
1995 #endif
1996 aha152x_done(shpnt, DID_ABORT <<16);
1998 return;
2001 break;
2003 case P_CMD:/* COMMAND phase */
2004 #if defined(DEBUG_INTR) || defined(DEBUG_CMD) || defined(DEBUG_PHASES)
2005 if(HOSTDATA(shpnt)->debug & (debug_intr | debug_cmd | debug_phases))
2006 printk("COMMAND, ");
2007 #endif
2008 if(!(CURRENT_SC->SCp.sent_command)) {
2009 int i;
2011 CLRBITS(SXFRCTL0, ENDMA);
2013 SETPORT(SIMODE0,0);
2014 SETPORT(SIMODE1, ENPHASEMIS | ENREQINIT | ENBUSFREE);
2016 /* wait for data latch to become ready or a phase change */
2017 while(TESTLO(DMASTAT, INTSTAT))
2018 barrier();
2020 for(i =0; i < CURRENT_SC->cmd_len &&TESTLO(SSTAT1, PHASEMIS); i++) {
2021 SETPORT(SCSIDAT, CURRENT_SC->cmnd[i]);
2023 make_acklow(shpnt);
2024 getphase(shpnt);
2027 if(i < CURRENT_SC->cmd_len &&TESTHI(SSTAT1, PHASEMIS))
2028 aha152x_panic(shpnt,"target left COMMAND");
2030 CURRENT_SC->SCp.sent_command++;
2031 }else
2032 aha152x_panic(shpnt,"Nothing to send while in COMMAND");
2033 break;
2035 case P_MSGI:/* MESSAGE IN phase */
2037 int start_sync =0;
2039 #if defined(DEBUG_INTR) || defined(DEBUG_MSGI) || defined(DEBUG_PHASES)
2040 if(HOSTDATA(shpnt)->debug & (debug_intr | debug_msgi | debug_phases))
2041 printk("MESSAGE IN, ");
2042 #endif
2043 SETPORT(SXFRCTL0, CH1);
2045 SETPORT(SIMODE0,0);
2046 SETPORT(SIMODE1, ENBUSFREE);
2048 while(phase == P_MSGI) {
2049 CURRENT_SC->SCp.Message =GETPORT(SCSIDAT);
2050 switch(CURRENT_SC->SCp.Message) {
2051 case DISCONNECT:
2052 #if defined(DEBUG_MSGI) || defined(DEBUG_PHASES)
2053 if(HOSTDATA(shpnt)->debug & (debug_msgi | debug_phases))
2054 printk("target disconnected, ");
2055 #endif
2056 CURRENT_SC->SCp.Message =0;
2057 CURRENT_SC->SCp.phase |= disconnected;
2058 if(!HOSTDATA(shpnt)->reconnect)
2059 aha152x_panic(shpnt,"target was not allowed to disconnect");
2061 break;
2063 case COMMAND_COMPLETE:
2064 #if defined(DEBUG_MSGI) || defined(DEBUG_PHASES)
2065 if(HOSTDATA(shpnt)->debug & (debug_msgi | debug_phases))
2066 printk("inbound message (COMMAND COMPLETE), ");
2067 #endif
2068 done++;
2069 break;
2071 case MESSAGE_REJECT:
2072 if(CURRENT_SC->SCp.phase & in_sync) {
2073 CURRENT_SC->SCp.phase &= ~in_sync;
2074 SYNCRATE =0x80;
2075 printk("synchronous rejected, ");
2076 }else
2077 printk("inbound message (MESSAGE REJECT), ");
2078 #if defined(DEBUG_MSGI)
2079 if(HOSTDATA(shpnt)->debug & debug_msgi)
2080 printk("inbound message (MESSAGE REJECT), ");
2081 #endif
2082 break;
2084 case SAVE_POINTERS:
2085 #if defined(DEBUG_MSGI)
2086 if(HOSTDATA(shpnt)->debug & debug_msgi)
2087 printk("inbound message (SAVE DATA POINTERS), ");
2088 #endif
2089 break;
2091 case RESTORE_POINTERS:
2092 #if defined(DEBUG_MSGI)
2093 if(HOSTDATA(shpnt)->debug & debug_msgi)
2094 printk("inbound message (RESTORE DATA POINTERS), ");
2095 #endif
2096 break;
2098 case EXTENDED_MESSAGE:
2100 char buffer[16];
2101 int i;
2103 #if defined(DEBUG_MSGI)
2104 if(HOSTDATA(shpnt)->debug & debug_msgi)
2105 printk("inbound message (EXTENDED MESSAGE), ");
2106 #endif
2107 make_acklow(shpnt);
2108 if(getphase(shpnt) != P_MSGI)
2109 break;
2111 buffer[0] = EXTENDED_MESSAGE;
2112 buffer[1] =GETPORT(SCSIDAT);
2114 for(i =0; i < buffer[1] &&
2115 (make_acklow(shpnt),getphase(shpnt) == P_MSGI); i++)
2116 buffer[2+ i] =GETPORT(SCSIDAT);
2118 #if defined(DEBUG_MSGI)
2119 if(HOSTDATA(shpnt)->debug & debug_msgi)
2120 print_msg(buffer);
2121 #endif
2123 switch(buffer[2]) {
2124 case EXTENDED_SDTR:
2126 long ticks;
2128 if(buffer[1] !=3)
2129 aha152x_panic(shpnt,"SDTR message length != 3");
2131 if(!HOSTDATA(shpnt)->synchronous)
2132 break;
2134 printk("inbound SDTR: ");
2135 print_msg(buffer);
2137 ticks = (buffer[3] *4+49) /50;
2139 if(CURRENT_SC->SCp.phase & in_sync) {
2140 /* we initiated SDTR */
2141 if(ticks >9|| buffer[4] <1|| buffer[4] >8)
2142 aha152x_panic(shpnt,"received SDTR invalid");
2144 SYNCRATE |= ((ticks -2) <<4) + buffer[4];
2145 }else if(ticks <=9&& buffer[4] >=1) {
2146 if(buffer[4] >8)
2147 buffer[4] =8;
2149 ADDMSG(EXTENDED_MESSAGE);
2150 ADDMSG(3);
2151 ADDMSG(EXTENDED_SDTR);
2152 if(ticks <4) {
2153 ticks =4;
2154 ADDMSG(50);
2155 }else
2156 ADDMSG(buffer[3]);
2158 ADDMSG(buffer[4]);
2160 printk("outbound SDTR: ");
2161 print_msg(&MSG(MSGLEN -5));
2163 CURRENT_SC->SCp.phase |= in_sync;
2165 SYNCRATE |= ((ticks -2) <<4) + buffer[4];
2167 start_sync++;
2168 }else{
2169 /* requested SDTR is too slow, do it asynchronously */
2170 ADDMSG(MESSAGE_REJECT);
2171 SYNCRATE =0;
2174 SETPORT(SCSIRATE, SYNCRATE &0x7f);
2176 break;
2178 case EXTENDED_MODIFY_DATA_POINTER:
2179 case EXTENDED_EXTENDED_IDENTIFY:
2180 case EXTENDED_WDTR:
2181 default:
2182 ADDMSG(MESSAGE_REJECT);
2183 break;
2186 break;
2188 default:
2189 printk("unsupported inbound message %x, ", CURRENT_SC->SCp.Message);
2190 break;
2194 make_acklow(shpnt);
2195 phase =getphase(shpnt);
2198 if(start_sync)
2199 CURRENT_SC->SCp.phase |= in_sync;
2200 else
2201 CURRENT_SC->SCp.phase &= ~in_sync;
2203 if(MSGLEN >0)
2204 SETPORT(SCSISIG, P_MSGI | ATNO);
2206 /* clear SCSI fifo on BUSFREE */
2207 if(phase == P_BUSFREE)
2208 SETPORT(SXFRCTL0, CH1 | CLRCH1);
2210 if(CURRENT_SC->SCp.phase & disconnected) {
2211 save_flags(flags);
2212 cli();
2213 #if defined(DEBUG_QUEUES)
2214 if(HOSTDATA(shpnt)->debug & debug_queues)
2215 printk("d+, ");
2216 #endif
2217 append_SC(&DISCONNECTED_SC, CURRENT_SC);
2218 CURRENT_SC->SCp.phase |=1<<16;
2219 CURRENT_SC = NULL;
2220 restore_flags(flags);
2222 SETBITS(SCSISEQ, ENRESELI);
2224 SETPORT(SIMODE0, DISCONNECTED_SC ? ENSELDI :0);
2225 SETPORT(SIMODE1, ISSUE_SC ? ENBUSFREE :0);
2227 SETBITS(DMACNTRL0, INTEN);
2229 return;
2232 break;
2234 case P_STATUS:/* STATUS IN phase */
2235 #if defined(DEBUG_STATUS) || defined(DEBUG_INTR) || defined(DEBUG_PHASES)
2236 if(HOSTDATA(shpnt)->debug & (debug_status | debug_intr | debug_phases))
2237 printk("STATUS, ");
2238 #endif
2239 SETPORT(SXFRCTL0, CH1);
2241 SETPORT(SIMODE0,0);
2242 SETPORT(SIMODE1, ENREQINIT | ENBUSFREE);
2244 if(TESTHI(SSTAT1, PHASEMIS))
2245 printk("aha152x: passing STATUS phase");
2247 CURRENT_SC->SCp.Status =GETPORT(SCSIBUS);
2248 make_acklow(shpnt);
2249 getphase(shpnt);
2251 #if defined(DEBUG_STATUS)
2252 if(HOSTDATA(shpnt)->debug & debug_status) {
2253 printk("inbound status ");
2254 print_status(CURRENT_SC->SCp.Status);
2255 printk(", ");
2257 #endif
2258 break;
2260 case P_DATAI:/* DATA IN phase */
2262 int fifodata, data_count, done;
2264 #if defined(DEBUG_DATAI) || defined(DEBUG_INTR) || defined(DEBUG_PHASES)
2265 if(HOSTDATA(shpnt)->debug & (debug_datai | debug_intr | debug_phases))
2266 printk("DATA IN, ");
2267 #endif
2269 #if 0
2270 if(GETPORT(FIFOSTAT) ||GETPORT(SSTAT2) & (SFULL | SFCNT))
2271 printk("aha152x: P_DATAI: %d(%d) bytes left in FIFO, resetting\n",
2272 GETPORT(FIFOSTAT),GETPORT(SSTAT2) & (SFULL | SFCNT));
2273 #endif
2275 /* reset host fifo */
2276 SETPORT(DMACNTRL0, RSTFIFO);
2277 SETPORT(DMACNTRL0, RSTFIFO | ENDMA);
2279 SETPORT(SXFRCTL0, CH1 | SCSIEN | DMAEN);
2281 SETPORT(SIMODE0,0);
2282 SETPORT(SIMODE1, ENPHASEMIS | ENBUSFREE);
2284 /* done is set when the FIFO is empty after the target left DATA IN */
2285 done =0;
2287 /* while the target stays in DATA to transfer data */
2288 while(!done) {
2289 #if defined(DEBUG_DATAI)
2290 if(HOSTDATA(shpnt)->debug & debug_datai)
2291 printk("expecting data, ");
2292 #endif
2293 /* wait for PHASEMIS or full FIFO */
2294 while(TESTLO(DMASTAT, DFIFOFULL | INTSTAT))
2295 barrier();
2297 #if defined(DEBUG_DATAI)
2298 if(HOSTDATA(shpnt)->debug & debug_datai)
2299 printk("ok, ");
2300 #endif
2302 if(TESTHI(DMASTAT, DFIFOFULL))
2303 fifodata =GETPORT(FIFOSTAT);
2304 else{
2305 /* wait for SCSI fifo to get empty */
2306 while(TESTLO(SSTAT2, SEMPTY))
2307 barrier();
2309 /* rest of data in FIFO */
2310 fifodata =GETPORT(FIFOSTAT);
2311 #if defined(DEBUG_DATAI)
2312 if(HOSTDATA(shpnt)->debug & debug_datai)
2313 printk("last transfer, ");
2314 #endif
2315 done =1;
2318 #if defined(DEBUG_DATAI)
2319 if(HOSTDATA(shpnt)->debug & debug_datai)
2320 printk("fifodata=%d, ", fifodata);
2321 #endif
2323 while(fifodata && CURRENT_SC->SCp.this_residual) {
2324 data_count = fifodata;
2326 /* limit data transfer to size of first sg buffer */
2327 if(data_count > CURRENT_SC->SCp.this_residual)
2328 data_count = CURRENT_SC->SCp.this_residual;
2330 fifodata -= data_count;
2332 #if defined(DEBUG_DATAI)
2333 if(HOSTDATA(shpnt)->debug & debug_datai)
2334 printk("data_count=%d, ", data_count);
2335 #endif
2337 if(data_count &1) {
2338 /* get a single byte in byte mode */
2339 SETBITS(DMACNTRL0, _8BIT);
2340 *CURRENT_SC->SCp.ptr++ =GETPORT(DATAPORT);
2341 CURRENT_SC->SCp.this_residual--;
2343 if(data_count >1) {
2344 CLRBITS(DMACNTRL0, _8BIT);
2345 data_count >>=1;/* Number of words */
2346 insw(DATAPORT, CURRENT_SC->SCp.ptr, data_count);
2347 #if defined(DEBUG_DATAI)
2348 if(HOSTDATA(shpnt)->debug & debug_datai)
2349 /* show what comes with the last transfer */
2350 if(done) {
2351 #if 0
2352 int i;
2353 unsigned char*data;
2354 #endif
2356 printk("data on last transfer (%d bytes) ",
2357 2* data_count);
2358 #if 0
2359 printk("data on last transfer (%d bytes: ",
2360 2* data_count);
2361 data = (unsigned char*) CURRENT_SC->SCp.ptr;
2362 for(i =0; i <2* data_count; i++)
2363 printk("%2x ", *data++);
2364 printk("), ");
2365 #endif
2367 #endif
2368 CURRENT_SC->SCp.ptr +=2* data_count;
2369 CURRENT_SC->SCp.this_residual -=2* data_count;
2371 /* if this buffer is full and there are more buffers left */
2372 if(!CURRENT_SC->SCp.this_residual &&
2373 CURRENT_SC->SCp.buffers_residual) {
2374 /* advance to next buffer */
2375 CURRENT_SC->SCp.buffers_residual--;
2376 CURRENT_SC->SCp.buffer++;
2377 CURRENT_SC->SCp.ptr = CURRENT_SC->SCp.buffer->address;
2378 CURRENT_SC->SCp.this_residual = CURRENT_SC->SCp.buffer->length;
2383 * FIFO should be empty
2385 if(fifodata >0) {
2386 printk("aha152x: more data than expected (%d bytes)\n",
2387 GETPORT(FIFOSTAT));
2388 SETBITS(DMACNTRL0, _8BIT);
2389 printk("aha152x: data (");
2390 while(fifodata--)
2391 printk("%2x ",GETPORT(DATAPORT));
2392 printk(")\n");
2394 #if defined(DEBUG_DATAI)
2395 if(HOSTDATA(shpnt)->debug & debug_datai)
2396 if(!fifodata)
2397 printk("fifo empty, ");
2398 else
2399 printk("something left in fifo, ");
2400 #endif
2403 #if defined(DEBUG_DATAI)
2404 if((HOSTDATA(shpnt)->debug & debug_datai) &&
2405 (CURRENT_SC->SCp.buffers_residual ||
2406 CURRENT_SC->SCp.this_residual))
2407 printk("left buffers (buffers=%d, bytes=%d), ",
2408 CURRENT_SC->SCp.buffers_residual, CURRENT_SC->SCp.this_residual);
2409 #endif
2410 /* transfer can be considered ended, when SCSIEN reads back zero */
2411 CLRBITS(SXFRCTL0, SCSIEN | DMAEN);
2412 while(TESTHI(SXFRCTL0, SCSIEN))
2413 barrier();
2414 CLRBITS(DMACNTRL0, ENDMA);
2416 #if defined(DEBUG_DATAI) || defined(DEBUG_INTR)
2417 if(HOSTDATA(shpnt)->debug & (debug_datai | debug_intr))
2418 printk("got %d bytes, ",GETSTCNT());
2419 #endif
2421 CURRENT_SC->SCp.have_data_in++;
2423 break;
2425 case P_DATAO:/* DATA OUT phase */
2427 int data_count;
2429 #if defined(DEBUG_DATAO) || defined(DEBUG_INTR) || defined(DEBUG_PHASES)
2430 if(HOSTDATA(shpnt)->debug & (debug_datao | debug_intr | debug_phases))
2431 printk("DATA OUT, ");
2432 #endif
2433 #if defined(DEBUG_DATAO)
2434 if(HOSTDATA(shpnt)->debug & debug_datao)
2435 printk("got data to send (bytes=%d, buffers=%d), ",
2436 CURRENT_SC->SCp.this_residual,
2437 CURRENT_SC->SCp.buffers_residual);
2438 #endif
2440 if(GETPORT(FIFOSTAT) ||GETPORT(SSTAT2) & (SFULL | SFCNT)) {
2441 printk("%d(%d) left in FIFO, ",
2442 GETPORT(FIFOSTAT),GETPORT(SSTAT2) & (SFULL | SFCNT));
2443 aha152x_panic(shpnt,"FIFO should be empty");
2445 SETPORT(SXFRCTL0, CH1 | CLRSTCNT | CLRCH1);
2446 SETPORT(SXFRCTL0, SCSIEN | DMAEN | CH1);
2448 SETPORT(DMACNTRL0, WRITE_READ | RSTFIFO);
2449 SETPORT(DMACNTRL0, ENDMA | WRITE_READ);
2451 SETPORT(SIMODE0,0);
2452 SETPORT(SIMODE1, ENPHASEMIS | ENBUSFREE);
2454 /* while current buffer is not empty or
2455 there are more buffers to transfer */
2456 while(TESTLO(SSTAT1, PHASEMIS) &&
2457 (CURRENT_SC->SCp.this_residual ||
2458 CURRENT_SC->SCp.buffers_residual)) {
2459 #if defined(DEBUG_DATAO)
2460 if(HOSTDATA(shpnt)->debug & debug_datao)
2461 printk("sending data (left: bytes=%d, buffers=%d), waiting, ",
2462 CURRENT_SC->SCp.this_residual,
2463 CURRENT_SC->SCp.buffers_residual);
2464 #endif
2465 /* transfer rest of buffer, but max. 128 byte */
2466 data_count =
2467 CURRENT_SC->SCp.this_residual >128?
2468 128: CURRENT_SC->SCp.this_residual;
2470 #if defined(DEBUG_DATAO)
2471 if(HOSTDATA(shpnt)->debug & debug_datao)
2472 printk("data_count=%d, ", data_count);
2473 #endif
2475 if(data_count &1) {
2476 /* put a single byte in byte mode */
2477 SETBITS(DMACNTRL0, _8BIT);
2478 SETPORT(DATAPORT, *CURRENT_SC->SCp.ptr++);
2479 CURRENT_SC->SCp.this_residual--;
2481 if(data_count >1) {
2482 CLRBITS(DMACNTRL0, _8BIT);
2483 data_count >>=1;/* number of words */
2484 outsw(DATAPORT, CURRENT_SC->SCp.ptr, data_count);
2485 CURRENT_SC->SCp.ptr +=2* data_count;
2486 CURRENT_SC->SCp.this_residual -=2* data_count;
2488 /* wait for FIFO to get empty */
2489 while(TESTLO(DMASTAT, DFIFOEMP | INTSTAT))
2490 barrier();
2492 #if defined(DEBUG_DATAO)
2493 if(HOSTDATA(shpnt)->debug & debug_datao)
2494 printk("fifo (%d bytes), transfered (%d bytes), ",
2495 GETPORT(FIFOSTAT),GETSTCNT());
2496 #endif
2498 /* if this buffer is empty and there are more buffers left */
2499 if(TESTLO(SSTAT1, PHASEMIS) &&
2500 !CURRENT_SC->SCp.this_residual &&
2501 CURRENT_SC->SCp.buffers_residual) {
2502 /* advance to next buffer */
2503 CURRENT_SC->SCp.buffers_residual--;
2504 CURRENT_SC->SCp.buffer++;
2505 CURRENT_SC->SCp.ptr = CURRENT_SC->SCp.buffer->address;
2506 CURRENT_SC->SCp.this_residual = CURRENT_SC->SCp.buffer->length;
2510 if(CURRENT_SC->SCp.this_residual || CURRENT_SC->SCp.buffers_residual) {
2511 /* target leaves DATA OUT for an other phase (perhaps disconnect) */
2513 /* data in fifos has to be resend */
2514 data_count =GETPORT(SSTAT2) & (SFULL | SFCNT);
2516 data_count +=GETPORT(FIFOSTAT);
2517 CURRENT_SC->SCp.ptr -= data_count;
2518 CURRENT_SC->SCp.this_residual += data_count;
2519 #if defined(DEBUG_DATAO)
2520 if(HOSTDATA(shpnt)->debug & debug_datao)
2521 printk("left data (bytes=%d, buffers=%d), fifos (bytes=%d), "
2522 "transfer incomplete, resetting fifo, ",
2523 CURRENT_SC->SCp.this_residual,
2524 CURRENT_SC->SCp.buffers_residual,
2525 data_count);
2526 #endif
2527 SETPORT(DMACNTRL0, WRITE_READ | RSTFIFO);
2528 CLRBITS(SXFRCTL0, SCSIEN | DMAEN);
2529 CLRBITS(DMACNTRL0, ENDMA);
2530 }else{
2531 #if defined(DEBUG_DATAO)
2532 if(HOSTDATA(shpnt)->debug & debug_datao)
2533 printk("waiting for SCSI fifo to get empty, ");
2534 #endif
2535 /* wait for SCSI fifo to get empty */
2536 while(TESTLO(SSTAT2, SEMPTY))
2537 barrier();
2538 #if defined(DEBUG_DATAO)
2539 if(HOSTDATA(shpnt)->debug & debug_datao)
2540 printk("ok, left data (bytes=%d, buffers=%d) ",
2541 CURRENT_SC->SCp.this_residual,
2542 CURRENT_SC->SCp.buffers_residual);
2543 #endif
2544 CLRBITS(SXFRCTL0, SCSIEN | DMAEN);
2546 /* transfer can be considered ended, when SCSIEN reads back zero */
2547 while(TESTHI(SXFRCTL0, SCSIEN))
2548 barrier();
2550 CLRBITS(DMACNTRL0, ENDMA);
2553 #if defined(DEBUG_DATAO) || defined(DEBUG_INTR)
2554 if(HOSTDATA(shpnt)->debug & (debug_datao | debug_intr))
2555 printk("sent %d data bytes, ",GETSTCNT());
2556 #endif
2558 break;
2560 case P_BUSFREE:/* BUSFREE */
2561 #if defined(DEBUG_RACE)
2562 leave_driver("(BUSFREE) intr");
2563 #endif
2564 #if defined(DEBUG_PHASES)
2565 if(HOSTDATA(shpnt)->debug & debug_phases)
2566 printk("unexpected BUS FREE, ");
2567 #endif
2568 CURRENT_SC->SCp.phase &= ~(P_MASK <<16);
2570 aha152x_done(shpnt, DID_ERROR <<16);/* Don't know any better */
2571 return;
2572 break;
2574 case P_PARITY:/* parity error in DATA phase */
2575 #if defined(DEBUG_RACE)
2576 leave_driver("(DID_PARITY) intr");
2577 #endif
2578 printk("PARITY error in DATA phase, ");
2580 CURRENT_SC->SCp.phase &= ~(P_MASK <<16);
2582 SETBITS(DMACNTRL0, INTEN);
2583 aha152x_done(shpnt, DID_PARITY <<16);
2584 return;
2585 break;
2587 default:
2588 printk("aha152x: unexpected phase\n");
2589 break;
2592 if(done) {
2593 #if defined(DEBUG_INTR)
2594 if(HOSTDATA(shpnt)->debug & debug_intr)
2595 printk("command done.\n");
2596 #endif
2597 #if defined(DEBUG_RACE)
2598 leave_driver("(done) intr");
2599 #endif
2601 SETPORT(SIMODE0, DISCONNECTED_SC ? ENSELDI :0);
2602 SETPORT(SIMODE1, ISSUE_SC ? ENBUSFREE :0);
2603 SETPORT(SCSISEQ, DISCONNECTED_SC ? ENRESELI :0);
2605 SETBITS(DMACNTRL0, INTEN);
2607 aha152x_done(shpnt,
2608 (CURRENT_SC->SCp.Status &0xff)
2609 | ((CURRENT_SC->SCp.Message &0xff) <<8)
2610 | (DID_OK <<16));
2612 #if defined(DEBUG_RACE)
2613 printk("done returned (DID_OK: Status=%x; Message=%x).\n",
2614 CURRENT_SC->SCp.Status, CURRENT_SC->SCp.Message);
2615 #endif
2616 return;
2618 if(CURRENT_SC)
2619 CURRENT_SC->SCp.phase |=1<<16;
2621 SETPORT(SIMODE0,0);
2622 SETPORT(SIMODE1, ENPHASEMIS | ENBUSFREE);
2623 #if defined(DEBUG_INTR)
2624 if(HOSTDATA(shpnt)->debug & debug_intr)
2625 disp_enintr(shpnt);
2626 #endif
2627 #if defined(DEBUG_RACE)
2628 leave_driver("(PHASEEND) intr");
2629 #endif
2631 SETBITS(DMACNTRL0, INTEN);
2632 return;
2636 * Dump the current driver status and panic...
2638 static voidaha152x_panic(struct Scsi_Host *shpnt,char*msg)
2640 printk("\naha152x: %s\n", msg);
2641 show_queues(shpnt);
2642 panic("aha152x panic");
2646 * Display registers of AIC-6260
2648 static voiddisp_ports(struct Scsi_Host *shpnt)
2650 #ifdef DEBUG_AHA152X
2651 int s;
2653 #ifdef SKIP_PORTS
2654 if(HOSTDATA(shpnt)->debug & debug_skipports)
2655 return;
2656 #endif
2658 printk("\n%s: ", CURRENT_SC ?"on bus":"waiting");
2660 s =GETPORT(SCSISEQ);
2661 printk("SCSISEQ (");
2662 if(s & TEMODEO)
2663 printk("TARGET MODE ");
2664 if(s & ENSELO)
2665 printk("SELO ");
2666 if(s & ENSELI)
2667 printk("SELI ");
2668 if(s & ENRESELI)
2669 printk("RESELI ");
2670 if(s & ENAUTOATNO)
2671 printk("AUTOATNO ");
2672 if(s & ENAUTOATNI)
2673 printk("AUTOATNI ");
2674 if(s & ENAUTOATNP)
2675 printk("AUTOATNP ");
2676 if(s & SCSIRSTO)
2677 printk("SCSIRSTO ");
2678 printk(");");
2680 printk(" SCSISIG (");
2681 s =GETPORT(SCSISIG);
2682 switch(s & P_MASK) {
2683 case P_DATAO:
2684 printk("DATA OUT");
2685 break;
2686 case P_DATAI:
2687 printk("DATA IN");
2688 break;
2689 case P_CMD:
2690 printk("COMMAND");
2691 break;
2692 case P_STATUS:
2693 printk("STATUS");
2694 break;
2695 case P_MSGO:
2696 printk("MESSAGE OUT");
2697 break;
2698 case P_MSGI:
2699 printk("MESSAGE IN");
2700 break;
2701 default:
2702 printk("*illegal*");
2703 break;
2706 printk("); ");
2708 printk("INTSTAT (%s); ",TESTHI(DMASTAT, INTSTAT) ?"hi":"lo");
2710 printk("SSTAT (");
2711 s =GETPORT(SSTAT0);
2712 if(s & TARGET)
2713 printk("TARGET ");
2714 if(s & SELDO)
2715 printk("SELDO ");
2716 if(s & SELDI)
2717 printk("SELDI ");
2718 if(s & SELINGO)
2719 printk("SELINGO ");
2720 if(s & SWRAP)
2721 printk("SWRAP ");
2722 if(s & SDONE)
2723 printk("SDONE ");
2724 if(s & SPIORDY)
2725 printk("SPIORDY ");
2726 if(s & DMADONE)
2727 printk("DMADONE ");
2729 s =GETPORT(SSTAT1);
2730 if(s & SELTO)
2731 printk("SELTO ");
2732 if(s & ATNTARG)
2733 printk("ATNTARG ");
2734 if(s & SCSIRSTI)
2735 printk("SCSIRSTI ");
2736 if(s & PHASEMIS)
2737 printk("PHASEMIS ");
2738 if(s & BUSFREE)
2739 printk("BUSFREE ");
2740 if(s & SCSIPERR)
2741 printk("SCSIPERR ");
2742 if(s & PHASECHG)
2743 printk("PHASECHG ");
2744 if(s & REQINIT)
2745 printk("REQINIT ");
2746 printk("); ");
2749 printk("SSTAT (");
2751 s =GETPORT(SSTAT0) &GETPORT(SIMODE0);
2753 if(s & TARGET)
2754 printk("TARGET ");
2755 if(s & SELDO)
2756 printk("SELDO ");
2757 if(s & SELDI)
2758 printk("SELDI ");
2759 if(s & SELINGO)
2760 printk("SELINGO ");
2761 if(s & SWRAP)
2762 printk("SWRAP ");
2763 if(s & SDONE)
2764 printk("SDONE ");
2765 if(s & SPIORDY)
2766 printk("SPIORDY ");
2767 if(s & DMADONE)
2768 printk("DMADONE ");
2770 s =GETPORT(SSTAT1) &GETPORT(SIMODE1);
2772 if(s & SELTO)
2773 printk("SELTO ");
2774 if(s & ATNTARG)
2775 printk("ATNTARG ");
2776 if(s & SCSIRSTI)
2777 printk("SCSIRSTI ");
2778 if(s & PHASEMIS)
2779 printk("PHASEMIS ");
2780 if(s & BUSFREE)
2781 printk("BUSFREE ");
2782 if(s & SCSIPERR)
2783 printk("SCSIPERR ");
2784 if(s & PHASECHG)
2785 printk("PHASECHG ");
2786 if(s & REQINIT)
2787 printk("REQINIT ");
2788 printk("); ");
2790 printk("SXFRCTL0 (");
2792 s =GETPORT(SXFRCTL0);
2793 if(s & SCSIEN)
2794 printk("SCSIEN ");
2795 if(s & DMAEN)
2796 printk("DMAEN ");
2797 if(s & CH1)
2798 printk("CH1 ");
2799 if(s & CLRSTCNT)
2800 printk("CLRSTCNT ");
2801 if(s & SPIOEN)
2802 printk("SPIOEN ");
2803 if(s & CLRCH1)
2804 printk("CLRCH1 ");
2805 printk("); ");
2807 printk("SIGNAL (");
2809 s =GETPORT(SCSISIG);
2810 if(s & ATNI)
2811 printk("ATNI ");
2812 if(s & SELI)
2813 printk("SELI ");
2814 if(s & BSYI)
2815 printk("BSYI ");
2816 if(s & REQI)
2817 printk("REQI ");
2818 if(s & ACKI)
2819 printk("ACKI ");
2820 printk("); ");
2822 printk("SELID (%02x), ",GETPORT(SELID));
2824 printk("SSTAT2 (");
2826 s =GETPORT(SSTAT2);
2827 if(s & SOFFSET)
2828 printk("SOFFSET ");
2829 if(s & SEMPTY)
2830 printk("SEMPTY ");
2831 if(s & SFULL)
2832 printk("SFULL ");
2833 printk("); SFCNT (%d); ", s & (SFULL | SFCNT));
2835 s =GETPORT(SSTAT3);
2836 printk("SCSICNT (%d), OFFCNT(%d), ", (s &0xf0) >>4, s &0x0f);
2838 printk("SSTAT4 (");
2839 s =GETPORT(SSTAT4);
2840 if(s & SYNCERR)
2841 printk("SYNCERR ");
2842 if(s & FWERR)
2843 printk("FWERR ");
2844 if(s & FRERR)
2845 printk("FRERR ");
2846 printk("); ");
2848 printk("DMACNTRL0 (");
2849 s =GETPORT(DMACNTRL0);
2850 printk("%s ", s & _8BIT ?"8BIT":"16BIT");
2851 printk("%s ", s & DMA ?"DMA":"PIO");
2852 printk("%s ", s & WRITE_READ ?"WRITE":"READ");
2853 if(s & ENDMA)
2854 printk("ENDMA ");
2855 if(s & INTEN)
2856 printk("INTEN ");
2857 if(s & RSTFIFO)
2858 printk("RSTFIFO ");
2859 if(s & SWINT)
2860 printk("SWINT ");
2861 printk("); ");
2863 printk("DMASTAT (");
2864 s =GETPORT(DMASTAT);
2865 if(s & ATDONE)
2866 printk("ATDONE ");
2867 if(s & WORDRDY)
2868 printk("WORDRDY ");
2869 if(s & DFIFOFULL)
2870 printk("DFIFOFULL ");
2871 if(s & DFIFOEMP)
2872 printk("DFIFOEMP ");
2873 printk(")");
2875 printk("\n");
2876 #endif
2880 * display enabled interrupts
2882 static voiddisp_enintr(struct Scsi_Host *shpnt)
2884 int s;
2886 printk("enabled interrupts (");
2888 s =GETPORT(SIMODE0);
2889 if(s & ENSELDO)
2890 printk("ENSELDO ");
2891 if(s & ENSELDI)
2892 printk("ENSELDI ");
2893 if(s & ENSELINGO)
2894 printk("ENSELINGO ");
2895 if(s & ENSWRAP)
2896 printk("ENSWRAP ");
2897 if(s & ENSDONE)
2898 printk("ENSDONE ");
2899 if(s & ENSPIORDY)
2900 printk("ENSPIORDY ");
2901 if(s & ENDMADONE)
2902 printk("ENDMADONE ");
2904 s =GETPORT(SIMODE1);
2905 if(s & ENSELTIMO)
2906 printk("ENSELTIMO ");
2907 if(s & ENATNTARG)
2908 printk("ENATNTARG ");
2909 if(s & ENPHASEMIS)
2910 printk("ENPHASEMIS ");
2911 if(s & ENBUSFREE)
2912 printk("ENBUSFREE ");
2913 if(s & ENSCSIPERR)
2914 printk("ENSCSIPERR ");
2915 if(s & ENPHASECHG)
2916 printk("ENPHASECHG ");
2917 if(s & ENREQINIT)
2918 printk("ENREQINIT ");
2919 printk(")\n");
2922 #if defined(DEBUG_RACE)
2924 static const char*should_leave;
2925 static int in_driver =0;
2928 * Only one routine can be in the driver at once.
2930 static voidenter_driver(const char*func)
2932 unsigned long flags;
2934 save_flags(flags);
2935 cli();
2936 printk("aha152x: entering %s() (%x)\n", func, jiffies);
2937 if(in_driver) {
2938 printk("%s should leave first.\n", should_leave);
2939 panic("aha152x: already in driver\n");
2941 in_driver++;
2942 should_leave = func;
2943 restore_flags(flags);
2946 static voidleave_driver(const char*func)
2948 unsigned long flags;
2950 save_flags(flags);
2951 cli();
2952 printk("\naha152x: leaving %s() (%x)\n", func, jiffies);
2953 if(!in_driver) {
2954 printk("aha152x: %s already left.\n", should_leave);
2955 panic("aha152x: %s already left driver.\n");
2957 in_driver--;
2958 should_leave = func;
2959 restore_flags(flags);
2961 #endif
2964 * Show the command data of a command
2966 static voidshow_command(Scsi_Cmnd * ptr)
2968 printk("0x%08x: target=%d; lun=%d; cmnd=(",
2969 (unsigned int) ptr, ptr->target, ptr->lun);
2971 print_command(ptr->cmnd);
2973 printk("); residual=%d; buffers=%d; phase |",
2974 ptr->SCp.this_residual, ptr->SCp.buffers_residual);
2976 if(ptr->SCp.phase & not_issued)
2977 printk("not issued|");
2978 if(ptr->SCp.phase & in_selection)
2979 printk("in selection|");
2980 if(ptr->SCp.phase & disconnected)
2981 printk("disconnected|");
2982 if(ptr->SCp.phase & aborted)
2983 printk("aborted|");
2984 if(ptr->SCp.phase & sent_ident)
2985 printk("send_ident|");
2986 if(ptr->SCp.phase & in_other) {
2987 printk("; in other(");
2988 switch((ptr->SCp.phase >>16) & P_MASK) {
2989 case P_DATAO:
2990 printk("DATA OUT");
2991 break;
2992 case P_DATAI:
2993 printk("DATA IN");
2994 break;
2995 case P_CMD:
2996 printk("COMMAND");
2997 break;
2998 case P_STATUS:
2999 printk("STATUS");
3000 break;
3001 case P_MSGO:
3002 printk("MESSAGE OUT");
3003 break;
3004 case P_MSGI:
3005 printk("MESSAGE IN");
3006 break;
3007 default:
3008 printk("*illegal*");
3009 break;
3011 printk(")");
3012 if(ptr->SCp.phase & (1<<16))
3013 printk("; phaseend");
3015 printk("; next=0x%08x\n", (unsigned int) ptr->host_scribble);
3019 * Dump the queued data
3021 static voidshow_queues(struct Scsi_Host *shpnt)
3023 unsigned long flags;
3024 Scsi_Cmnd *ptr;
3026 save_flags(flags);
3027 cli();
3028 printk("QUEUE STATUS:\nissue_SC:\n");
3029 for(ptr = ISSUE_SC; ptr; ptr = (Scsi_Cmnd *) ptr->host_scribble)
3030 show_command(ptr);
3032 printk("current_SC:\n");
3033 if(CURRENT_SC)
3034 show_command(CURRENT_SC);
3035 else
3036 printk("none\n");
3038 printk("disconnected_SC:\n");
3039 for(ptr = DISCONNECTED_SC; ptr; ptr = (Scsi_Cmnd *) ptr->host_scribble)
3040 show_command(ptr);
3042 disp_ports(shpnt);
3043 disp_enintr(shpnt);
3044 restore_flags(flags);
3047 intaha152x_set_info(char*buffer,int length,struct Scsi_Host *shpnt)
3049 return(-ENOSYS);/* Currently this is a no-op */
3052 #undef SPRINTF
3053 #define SPRINTF(args...) pos += sprintf(pos, ## args)
3055 static intget_command(char*pos, Scsi_Cmnd * ptr)
3057 char*start = pos;
3058 int i;
3060 SPRINTF("0x%08x: target=%d; lun=%d; cmnd=( ",
3061 (unsigned int) ptr, ptr->target, ptr->lun);
3063 for(i =0; i <COMMAND_SIZE(ptr->cmnd[0]); i++)
3064 SPRINTF("0x%02x ", ptr->cmnd[i]);
3066 SPRINTF("); residual=%d; buffers=%d; phase |",
3067 ptr->SCp.this_residual, ptr->SCp.buffers_residual);
3069 if(ptr->SCp.phase & not_issued)
3070 SPRINTF("not issued|");
3071 if(ptr->SCp.phase & in_selection)
3072 SPRINTF("in selection|");
3073 if(ptr->SCp.phase & disconnected)
3074 SPRINTF("disconnected|");
3075 if(ptr->SCp.phase & aborted)
3076 SPRINTF("aborted|");
3077 if(ptr->SCp.phase & sent_ident)
3078 SPRINTF("send_ident|");
3079 if(ptr->SCp.phase & in_other) {
3080 SPRINTF("; in other(");
3081 switch((ptr->SCp.phase >>16) & P_MASK) {
3082 case P_DATAO:
3083 SPRINTF("DATA OUT");
3084 break;
3085 case P_DATAI:
3086 SPRINTF("DATA IN");
3087 break;
3088 case P_CMD:
3089 SPRINTF("COMMAND");
3090 break;
3091 case P_STATUS:
3092 SPRINTF("STATUS");
3093 break;
3094 case P_MSGO:
3095 SPRINTF("MESSAGE OUT");
3096 break;
3097 case P_MSGI:
3098 SPRINTF("MESSAGE IN");
3099 break;
3100 default:
3101 SPRINTF("*illegal*");
3102 break;
3104 SPRINTF(")");
3105 if(ptr->SCp.phase & (1<<16))
3106 SPRINTF("; phaseend");
3108 SPRINTF("; next=0x%08x\n", (unsigned int) ptr->host_scribble);
3110 return(pos - start);
3113 static intget_ports(struct Scsi_Host *shpnt,char*pos)
3115 char*start = pos;
3116 int s;
3118 #ifdef SKIP_PORTS
3119 if(HOSTDATA(shpnt)->debug & debug_skipports)
3120 return;
3121 #endif
3123 SPRINTF("\n%s: ", CURRENT_SC ?"on bus":"waiting");
3125 s =GETPORT(SCSISEQ);
3126 SPRINTF("SCSISEQ (");
3127 if(s & TEMODEO)
3128 SPRINTF("TARGET MODE ");
3129 if(s & ENSELO)
3130 SPRINTF("SELO ");
3131 if(s & ENSELI)
3132 SPRINTF("SELI ");
3133 if(s & ENRESELI)
3134 SPRINTF("RESELI ");
3135 if(s & ENAUTOATNO)
3136 SPRINTF("AUTOATNO ");
3137 if(s & ENAUTOATNI)
3138 SPRINTF("AUTOATNI ");
3139 if(s & ENAUTOATNP)
3140 SPRINTF("AUTOATNP ");
3141 if(s & SCSIRSTO)
3142 SPRINTF("SCSIRSTO ");
3143 SPRINTF(");");
3145 SPRINTF(" SCSISIG (");
3146 s =GETPORT(SCSISIG);
3147 switch(s & P_MASK) {
3148 case P_DATAO:
3149 SPRINTF("DATA OUT");
3150 break;
3151 case P_DATAI:
3152 SPRINTF("DATA IN");
3153 break;
3154 case P_CMD:
3155 SPRINTF("COMMAND");
3156 break;
3157 case P_STATUS:
3158 SPRINTF("STATUS");
3159 break;
3160 case P_MSGO:
3161 SPRINTF("MESSAGE OUT");
3162 break;
3163 case P_MSGI:
3164 SPRINTF("MESSAGE IN");
3165 break;
3166 default:
3167 SPRINTF("*illegal*");
3168 break;
3171 SPRINTF("); ");
3173 SPRINTF("INTSTAT (%s); ",TESTHI(DMASTAT, INTSTAT) ?"hi":"lo");
3175 SPRINTF("SSTAT (");
3176 s =GETPORT(SSTAT0);
3177 if(s & TARGET)
3178 SPRINTF("TARGET ");
3179 if(s & SELDO)
3180 SPRINTF("SELDO ");
3181 if(s & SELDI)
3182 SPRINTF("SELDI ");
3183 if(s & SELINGO)
3184 SPRINTF("SELINGO ");
3185 if(s & SWRAP)
3186 SPRINTF("SWRAP ");
3187 if(s & SDONE)
3188 SPRINTF("SDONE ");
3189 if(s & SPIORDY)
3190 SPRINTF("SPIORDY ");
3191 if(s & DMADONE)
3192 SPRINTF("DMADONE ");
3194 s =GETPORT(SSTAT1);
3195 if(s & SELTO)
3196 SPRINTF("SELTO ");
3197 if(s & ATNTARG)
3198 SPRINTF("ATNTARG ");
3199 if(s & SCSIRSTI)
3200 SPRINTF("SCSIRSTI ");
3201 if(s & PHASEMIS)
3202 SPRINTF("PHASEMIS ");
3203 if(s & BUSFREE)
3204 SPRINTF("BUSFREE ");
3205 if(s & SCSIPERR)
3206 SPRINTF("SCSIPERR ");
3207 if(s & PHASECHG)
3208 SPRINTF("PHASECHG ");
3209 if(s & REQINIT)
3210 SPRINTF("REQINIT ");
3211 SPRINTF("); ");
3214 SPRINTF("SSTAT (");
3216 s =GETPORT(SSTAT0) &GETPORT(SIMODE0);
3218 if(s & TARGET)
3219 SPRINTF("TARGET ");
3220 if(s & SELDO)
3221 SPRINTF("SELDO ");
3222 if(s & SELDI)
3223 SPRINTF("SELDI ");
3224 if(s & SELINGO)
3225 SPRINTF("SELINGO ");
3226 if(s & SWRAP)
3227 SPRINTF("SWRAP ");
3228 if(s & SDONE)
3229 SPRINTF("SDONE ");
3230 if(s & SPIORDY)
3231 SPRINTF("SPIORDY ");
3232 if(s & DMADONE)
3233 SPRINTF("DMADONE ");
3235 s =GETPORT(SSTAT1) &GETPORT(SIMODE1);
3237 if(s & SELTO)
3238 SPRINTF("SELTO ");
3239 if(s & ATNTARG)
3240 SPRINTF("ATNTARG ");
3241 if(s & SCSIRSTI)
3242 SPRINTF("SCSIRSTI ");
3243 if(s & PHASEMIS)
3244 SPRINTF("PHASEMIS ");
3245 if(s & BUSFREE)
3246 SPRINTF("BUSFREE ");
3247 if(s & SCSIPERR)
3248 SPRINTF("SCSIPERR ");
3249 if(s & PHASECHG)
3250 SPRINTF("PHASECHG ");
3251 if(s & REQINIT)
3252 SPRINTF("REQINIT ");
3253 SPRINTF("); ");
3255 SPRINTF("SXFRCTL0 (");
3257 s =GETPORT(SXFRCTL0);
3258 if(s & SCSIEN)
3259 SPRINTF("SCSIEN ");
3260 if(s & DMAEN)
3261 SPRINTF("DMAEN ");
3262 if(s & CH1)
3263 SPRINTF("CH1 ");
3264 if(s & CLRSTCNT)
3265 SPRINTF("CLRSTCNT ");
3266 if(s & SPIOEN)
3267 SPRINTF("SPIOEN ");
3268 if(s & CLRCH1)
3269 SPRINTF("CLRCH1 ");
3270 SPRINTF("); ");
3272 SPRINTF("SIGNAL (");
3274 s =GETPORT(SCSISIG);
3275 if(s & ATNI)
3276 SPRINTF("ATNI ");
3277 if(s & SELI)
3278 SPRINTF("SELI ");
3279 if(s & BSYI)
3280 SPRINTF("BSYI ");
3281 if(s & REQI)
3282 SPRINTF("REQI ");
3283 if(s & ACKI)
3284 SPRINTF("ACKI ");
3285 SPRINTF("); ");
3287 SPRINTF("SELID (%02x), ",GETPORT(SELID));
3289 SPRINTF("SSTAT2 (");
3291 s =GETPORT(SSTAT2);
3292 if(s & SOFFSET)
3293 SPRINTF("SOFFSET ");
3294 if(s & SEMPTY)
3295 SPRINTF("SEMPTY ");
3296 if(s & SFULL)
3297 SPRINTF("SFULL ");
3298 SPRINTF("); SFCNT (%d); ", s & (SFULL | SFCNT));
3300 s =GETPORT(SSTAT3);
3301 SPRINTF("SCSICNT (%d), OFFCNT(%d), ", (s &0xf0) >>4, s &0x0f);
3303 SPRINTF("SSTAT4 (");
3304 s =GETPORT(SSTAT4);
3305 if(s & SYNCERR)
3306 SPRINTF("SYNCERR ");
3307 if(s & FWERR)
3308 SPRINTF("FWERR ");
3309 if(s & FRERR)
3310 SPRINTF("FRERR ");
3311 SPRINTF("); ");
3313 SPRINTF("DMACNTRL0 (");
3314 s =GETPORT(DMACNTRL0);
3315 SPRINTF("%s ", s & _8BIT ?"8BIT":"16BIT");
3316 SPRINTF("%s ", s & DMA ?"DMA":"PIO");
3317 SPRINTF("%s ", s & WRITE_READ ?"WRITE":"READ");
3318 if(s & ENDMA)
3319 SPRINTF("ENDMA ");
3320 if(s & INTEN)
3321 SPRINTF("INTEN ");
3322 if(s & RSTFIFO)
3323 SPRINTF("RSTFIFO ");
3324 if(s & SWINT)
3325 SPRINTF("SWINT ");
3326 SPRINTF("); ");
3328 SPRINTF("DMASTAT (");
3329 s =GETPORT(DMASTAT);
3330 if(s & ATDONE)
3331 SPRINTF("ATDONE ");
3332 if(s & WORDRDY)
3333 SPRINTF("WORDRDY ");
3334 if(s & DFIFOFULL)
3335 SPRINTF("DFIFOFULL ");
3336 if(s & DFIFOEMP)
3337 SPRINTF("DFIFOEMP ");
3338 SPRINTF(")\n\n");
3340 SPRINTF("enabled interrupts (");
3342 s =GETPORT(SIMODE0);
3343 if(s & ENSELDO)
3344 SPRINTF("ENSELDO ");
3345 if(s & ENSELDI)
3346 SPRINTF("ENSELDI ");
3347 if(s & ENSELINGO)
3348 SPRINTF("ENSELINGO ");
3349 if(s & ENSWRAP)
3350 SPRINTF("ENSWRAP ");
3351 if(s & ENSDONE)
3352 SPRINTF("ENSDONE ");
3353 if(s & ENSPIORDY)
3354 SPRINTF("ENSPIORDY ");
3355 if(s & ENDMADONE)
3356 SPRINTF("ENDMADONE ");
3358 s =GETPORT(SIMODE1);
3359 if(s & ENSELTIMO)
3360 SPRINTF("ENSELTIMO ");
3361 if(s & ENATNTARG)
3362 SPRINTF("ENATNTARG ");
3363 if(s & ENPHASEMIS)
3364 SPRINTF("ENPHASEMIS ");
3365 if(s & ENBUSFREE)
3366 SPRINTF("ENBUSFREE ");
3367 if(s & ENSCSIPERR)
3368 SPRINTF("ENSCSIPERR ");
3369 if(s & ENPHASECHG)
3370 SPRINTF("ENPHASECHG ");
3371 if(s & ENREQINIT)
3372 SPRINTF("ENREQINIT ");
3373 SPRINTF(")\n");
3375 return(pos - start);
3378 #undef SPRINTF
3379 #define SPRINTF(args...) do { if(pos < buffer + length) pos += sprintf(pos, ## args); } while(0)
3381 intaha152x_proc_info(char*buffer,char**start,
3382 off_t offset,int length,int hostno,int inout)
3384 int i;
3385 char*pos = buffer;
3386 struct Scsi_Host *shpnt;
3387 unsigned long flags;
3388 Scsi_Cmnd *ptr;
3390 for(i =0, shpnt = (struct Scsi_Host *) NULL; i < IRQS; i++)
3391 if(aha152x_host[i] && aha152x_host[i]->host_no == hostno)
3392 shpnt = aha152x_host[i];
3394 if(!shpnt)
3395 return(-ESRCH);
3397 if(inout)/* Has data been written to the file ? */
3398 return(aha152x_set_info(buffer, length, shpnt));
3400 SPRINTF(AHA152X_REVID "\n");
3402 save_flags(flags);
3403 cli();
3405 SPRINTF("ioports 0x%04lx to 0x%04lx\n",
3406 shpnt->io_port, shpnt->io_port + shpnt->n_io_port -1);
3407 SPRINTF("interrupt 0x%02x\n", shpnt->irq);
3408 SPRINTF("disconnection/reconnection %s\n",
3409 HOSTDATA(shpnt)->reconnect ?"enabled":"disabled");
3410 SPRINTF("parity checking %s\n",
3411 HOSTDATA(shpnt)->parity ?"enabled":"disabled");
3412 SPRINTF("synchronous transfers %s\n",
3413 HOSTDATA(shpnt)->synchronous ?"enabled":"disabled");
3414 SPRINTF("%d commands currently queued\n",HOSTDATA(shpnt)->commands);
3416 if(HOSTDATA(shpnt)->synchronous) {
3417 #if 0
3418 SPRINTF("synchronously operating targets (tick=%ld ns):\n",
3419 250000000/ loops_per_sec);
3420 for(i =0; i <8; i++)
3421 if(HOSTDATA(shpnt)->syncrate[i] &0x7f)
3422 SPRINTF("target %d: period %dT/%ldns; req/ack offset %d\n",
3424 (((HOSTDATA(shpnt)->syncrate[i] &0x70) >>4) +2),
3425 (((HOSTDATA(shpnt)->syncrate[i] &0x70) >>4) +2) *
3426 250000000/ loops_per_sec,
3427 HOSTDATA(shpnt)->syncrate[i] &0x0f);
3428 #else
3429 SPRINTF("synchronously operating targets (tick=50 ns):\n");
3430 for(i =0; i <8; i++)
3431 if(HOSTDATA(shpnt)->syncrate[i] &0x7f)
3432 SPRINTF("target %d: period %dT/%dns; req/ack offset %d\n",
3434 (((HOSTDATA(shpnt)->syncrate[i] &0x70) >>4) +2),
3435 (((HOSTDATA(shpnt)->syncrate[i] &0x70) >>4) +2) *50,
3436 HOSTDATA(shpnt)->syncrate[i] &0x0f);
3437 #endif
3439 #ifdef DEBUG_AHA152X
3440 #define PDEBUG(flags,txt) if(HOSTDATA(shpnt)->debug & flags) SPRINTF("(%s) ", txt);
3442 SPRINTF("enabled debugging options: ");
3444 PDEBUG(debug_skipports,"skip ports");
3445 PDEBUG(debug_queue,"queue");
3446 PDEBUG(debug_intr,"interrupt");
3447 PDEBUG(debug_selection,"selection");
3448 PDEBUG(debug_msgo,"message out");
3449 PDEBUG(debug_msgi,"message in");
3450 PDEBUG(debug_status,"status");
3451 PDEBUG(debug_cmd,"command");
3452 PDEBUG(debug_datai,"data in");
3453 PDEBUG(debug_datao,"data out");
3454 PDEBUG(debug_abort,"abort");
3455 PDEBUG(debug_done,"done");
3456 PDEBUG(debug_biosparam,"bios parameters");
3457 PDEBUG(debug_phases,"phases");
3458 PDEBUG(debug_queues,"queues");
3459 PDEBUG(debug_reset,"reset");
3461 SPRINTF("\n");
3462 #endif
3464 SPRINTF("\nqueue status:\n");
3465 if(ISSUE_SC) {
3466 SPRINTF("not yet issued commands:\n");
3467 for(ptr = ISSUE_SC; ptr; ptr = (Scsi_Cmnd *) ptr->host_scribble)
3468 pos +=get_command(pos, ptr);
3469 }else
3470 SPRINTF("no not yet issued commands\n");
3472 if(CURRENT_SC) {
3473 SPRINTF("current command:\n");
3474 pos +=get_command(pos, CURRENT_SC);
3475 }else
3476 SPRINTF("no current command\n");
3478 if(DISCONNECTED_SC) {
3479 SPRINTF("disconnected commands:\n");
3480 for(ptr = DISCONNECTED_SC; ptr; ptr = (Scsi_Cmnd *) ptr->host_scribble)
3481 pos +=get_command(pos, ptr);
3482 }else
3483 SPRINTF("no disconnected commands\n");
3485 restore_flags(flags);
3487 pos +=get_ports(shpnt, pos);
3489 *start = buffer + offset;
3490 if(pos - buffer < offset)
3491 return0;
3492 else if(pos - buffer - offset < length)
3493 return pos - buffer - offset;
3494 else
3495 return length;
3498 #ifdef MODULE
3499 /* Eventually this will go into an include file, but this will be later */
3500 Scsi_Host_Template driver_template = AHA152X;
3502 #include"scsi_module.c"
3503 #endif
close