1 /* $Id: aha1542.c,v 1.1 1992/07/24 06:27:38 root Exp root $
2 * linux/kernel/aha1542.c
4 * Copyright (C) 1992 Tommy Thorn
5 * Copyright (C) 1993, 1994, 1995 Eric Youngdale
7 * Modified by Eric Youngdale
8 * Use request_irq and request_dma to help prevent unexpected conflicts
9 * Set up on-board DMA controller, such that we do not have to
10 * have the bios enabled to use the aha1542.
11 * Modified by David Gentzel
12 * Don't call request_dma if dma mask is 0 (for BusLogic BT-445S VL-Bus
14 * Modified by Matti Aarnio
15 * Accept parameters from LILO cmd-line. -- 1-Oct-94
16 * Modified by Mike McLagan <mike.mclagan@linux.org>
17 * Recognise extended mode on AHA1542CP, different bit than 1542CF
19 * Modified by Bjorn L. Thordarson and Einar Thor Einarsson
20 * Recognize that DMA0 is valid DMA channel -- 13-Jul-98
21 * Modified by Chris Faulhaber <jedgar@fxp.org>
22 * Added module command-line options
24 * Modified by Adam Fritzler <mid@auk.cx>
25 * Added proper detection of the AHA-1640 (MCA version of AHA-1540)
28 #include <linux/config.h>
29 #include <linux/module.h>
31 #include <linux/kernel.h>
32 #include <linux/types.h>
33 #include <linux/string.h>
34 #include <linux/ioport.h>
35 #include <linux/delay.h>
36 #include <linux/sched.h>
37 #include <linux/proc_fs.h>
38 #include <linux/init.h>
39 #include <linux/spinlock.h>
40 #include <linux/pci.h>
41 #include <linux/isapnp.h>
43 #include <asm/system.h>
45 #include <linux/blk.h>
46 #include <linux/mca.h>
54 #define SCSI_PA(address) virt_to_bus(address)
56 static void BAD_DMA(void *address
, unsigned int length
)
58 printk(KERN_CRIT
"buf vaddress %p paddress 0x%lx length %d\n",
62 panic("Buffer at physical address > 16Mb used for aha1542");
65 static void BAD_SG_DMA(Scsi_Cmnd
* SCpnt
,
66 struct scatterlist
*sgpnt
,
70 printk(KERN_CRIT
"sgpnt[%d:%d] addr %p/0x%lx alt %p/0x%lx length %d\n",
72 sgpnt
[badseg
].address
,
73 SCSI_PA(sgpnt
[badseg
].address
),
74 sgpnt
[badseg
].alt_address
,
75 sgpnt
[badseg
].alt_address
? SCSI_PA(sgpnt
[badseg
].alt_address
) : 0,
76 sgpnt
[badseg
].length
);
79 * Not safe to continue.
81 panic("Buffer at physical address > 16Mb used for aha1542");
84 #include<linux/stat.h>
93 static const char RCSid[] = "$Header: /usr/src/linux/kernel/blk_drv/scsi/RCS/aha1542.c,v 1.1 1992/07/24 06:27:38 root Exp root $";
96 /* The adaptec can be configured for quite a number of addresses, but
97 I generally do not want the card poking around at random. We allow
98 two addresses - this allows people to use the Adaptec with a Midi
99 card, which also used 0x330 -- can be overridden with LILO! */
101 #define MAXBOARDS 4 /* Increase this and the sizes of the
102 arrays below, if you need more.. */
104 /* Boards 3,4 slots are reserved for ISAPnP/MCA scans */
106 static unsigned int bases
[MAXBOARDS
] = {0x330, 0x334, 0, 0};
108 /* set by aha1542_setup according to the command line */
110 static int setup_called
[MAXBOARDS
];
111 static int setup_buson
[MAXBOARDS
];
112 static int setup_busoff
[MAXBOARDS
];
113 static int setup_dmaspeed
[MAXBOARDS
] = { -1, -1, -1, -1 };
115 static char *setup_str
[MAXBOARDS
];
118 * LILO/Module params: aha1542=<PORTBASE>[,<BUSON>,<BUSOFF>[,<DMASPEED>]]
120 * Where: <PORTBASE> is any of the valid AHA addresses:
121 * 0x130, 0x134, 0x230, 0x234, 0x330, 0x334
122 * <BUSON> is the time (in microsecs) that AHA spends on the AT-bus
123 * when transferring data. 1542A power-on default is 11us,
124 * valid values are in range: 2..15 (decimal)
125 * <BUSOFF> is the time that AHA spends OFF THE BUS after while
126 * it is transferring data (not to monopolize the bus).
127 * Power-on default is 4us, valid range: 1..64 microseconds.
128 * <DMASPEED> Default is jumper selected (1542A: on the J1),
129 * but experimenter can alter it with this.
130 * Valid values: 5, 6, 7, 8, 10 (MB/s)
131 * Factory default is 5 MB/s.
136 int aha1542
[] = {0x330, 11, 4, -1};
137 MODULE_PARM(aha1542
, "1-4i");
138 MODULE_PARM(isapnp
, "i");
143 #define BIOS_TRANSLATION_1632 0 /* Used by some old 1542A boards */
144 #define BIOS_TRANSLATION_6432 1 /* Default case these days */
145 #define BIOS_TRANSLATION_25563 2 /* Big disk case */
147 struct aha1542_hostdata
{
148 /* This will effectively start both of them at the first mailbox */
149 int bios_translation
; /* Mapping bios uses - for compatibility */
150 int aha1542_last_mbi_used
;
151 int aha1542_last_mbo_used
;
152 Scsi_Cmnd
*SCint
[AHA1542_MAILBOXES
];
153 struct mailbox mb
[2 * AHA1542_MAILBOXES
];
154 struct ccb ccb
[AHA1542_MAILBOXES
];
157 #define HOSTDATA(host) ((struct aha1542_hostdata *) &host->hostdata)
159 static struct Scsi_Host
*aha_host
[7]; /* One for each IRQ level (9-15) */
164 #define WAITnexttimeout 3000000
166 static void setup_mailboxes(int base_io
, struct Scsi_Host
*shpnt
);
167 static int aha1542_restart(struct Scsi_Host
*shost
);
168 static void aha1542_intr_handle(int irq
, void *dev_id
, struct pt_regs
*regs
);
169 static void do_aha1542_intr_handle(int irq
, void *dev_id
, struct pt_regs
*regs
);
171 #define aha1542_intr_reset(base) outb(IRST, CONTROL(base))
173 #define WAIT(port, mask, allof, noneof) \
174 { register int WAITbits; \
175 register int WAITtimeout = WAITnexttimeout; \
177 WAITbits = inb(port) & (mask); \
178 if ((WAITbits & (allof)) == (allof) && ((WAITbits & (noneof)) == 0)) \
180 if (--WAITtimeout == 0) goto fail; \
184 /* Similar to WAIT, except we use the udelay call to regulate the
185 amount of time we wait. */
186 #define WAITd(port, mask, allof, noneof, timeout) \
187 { register int WAITbits; \
188 register int WAITtimeout = timeout; \
190 WAITbits = inb(port) & (mask); \
191 if ((WAITbits & (allof)) == (allof) && ((WAITbits & (noneof)) == 0)) \
194 if (--WAITtimeout == 0) goto fail; \
198 static void aha1542_stat(void)
200 /* int s = inb(STATUS), i = inb(INTRFLAGS);
201 printk("status=%x intrflags=%x\n", s, i, WAITnexttimeout-WAITtimeout); */
204 /* This is a bit complicated, but we need to make sure that an interrupt
205 routine does not send something out while we are in the middle of this.
206 Fortunately, it is only at boot time that multi-byte messages
208 static int aha1542_out(unsigned int base
, unchar
* cmdp
, int len
)
210 unsigned long flags
= 0;
215 WAIT(STATUS(base
), CDF
, 0, CDF
);
217 if (inb(STATUS(base
)) & CDF
) {
218 restore_flags(flags
);
221 outb(*cmdp
, DATA(base
));
222 restore_flags(flags
);
228 WAIT(STATUS(base
), CDF
, 0, CDF
);
229 outb(*cmdp
++, DATA(base
));
231 restore_flags(flags
);
235 restore_flags(flags
);
236 printk(KERN_ERR
"aha1542_out failed(%d): ", len
+ 1);
241 /* Only used at boot time, so we do not need to worry about latency as much
244 static int aha1542_in(unsigned int base
, unchar
* cmdp
, int len
)
251 WAIT(STATUS(base
), DF
, DF
, 0);
252 *cmdp
++ = inb(DATA(base
));
254 restore_flags(flags
);
257 restore_flags(flags
);
258 printk(KERN_ERR
"aha1542_in failed(%d): ", len
+ 1);
263 /* Similar to aha1542_in, except that we wait a very short period of time.
264 We use this if we know the board is alive and awake, but we are not sure
265 if the board will respond to the command we are about to send or not */
266 static int aha1542_in1(unsigned int base
, unchar
* cmdp
, int len
)
273 WAITd(STATUS(base
), DF
, DF
, 0, 100);
274 *cmdp
++ = inb(DATA(base
));
276 restore_flags(flags
);
279 restore_flags(flags
);
283 static int makecode(unsigned hosterr
, unsigned scsierr
)
287 case 0xa: /* Linked command complete without error and linked normally */
288 case 0xb: /* Linked command complete without error, interrupt generated */
292 case 0x11: /* Selection time out-The initiator selection or target
293 reselection was not complete within the SCSI Time out period */
294 hosterr
= DID_TIME_OUT
;
297 case 0x12: /* Data overrun/underrun-The target attempted to transfer more data
298 than was allocated by the Data Length field or the sum of the
299 Scatter / Gather Data Length fields. */
301 case 0x13: /* Unexpected bus free-The target dropped the SCSI BSY at an unexpected time. */
303 case 0x15: /* MBO command was not 00, 01 or 02-The first byte of the CB was
304 invalid. This usually indicates a software failure. */
306 case 0x16: /* Invalid CCB Operation Code-The first byte of the CCB was invalid.
307 This usually indicates a software failure. */
309 case 0x17: /* Linked CCB does not have the same LUN-A subsequent CCB of a set
310 of linked CCB's does not specify the same logical unit number as
312 case 0x18: /* Invalid Target Direction received from Host-The direction of a
313 Target Mode CCB was invalid. */
315 case 0x19: /* Duplicate CCB Received in Target Mode-More than once CCB was
316 received to service data transfer between the same target LUN
317 and initiator SCSI ID in the same direction. */
319 case 0x1a: /* Invalid CCB or Segment List Parameter-A segment list with a zero
320 length segment or invalid segment list boundaries was received.
321 A CCB parameter was invalid. */
322 DEB(printk("Aha1542: %x %x\n", hosterr
, scsierr
));
323 hosterr
= DID_ERROR
; /* Couldn't find any better */
326 case 0x14: /* Target bus phase sequence failure-An invalid bus phase or bus
327 phase sequence was requested by the target. The host adapter
328 will generate a SCSI Reset Condition, notifying the host with
333 printk(KERN_ERR
"aha1542: makecode: unknown hoststatus %x\n", hosterr
);
336 return scsierr
| (hosterr
<< 16);
339 static int aha1542_test_port(int bse
, struct Scsi_Host
*shpnt
)
341 unchar inquiry_cmd
[] = {CMD_INQUIRY
};
342 unchar inquiry_result
[4];
345 volatile int debug
= 0;
347 /* Quick and dirty test for presence of the card. */
348 if (inb(STATUS(bse
)) == 0xff)
351 /* Reset the adapter. I ought to make a hard reset, but it's not really necessary */
353 /* DEB(printk("aha1542_test_port called \n")); */
355 /* In case some other card was probing here, reset interrupts */
356 aha1542_intr_reset(bse
); /* reset interrupts, so they don't block */
358 outb(SRST
| IRST
/*|SCRST */ , CONTROL(bse
));
360 mdelay(20); /* Wait a little bit for things to settle down. */
363 /* Expect INIT and IDLE, any of the others are bad */
364 WAIT(STATUS(bse
), STATMASK
, INIT
| IDLE
, STST
| DIAGF
| INVDCMD
| DF
| CDF
);
367 /* Shouldn't have generated any interrupts during reset */
368 if (inb(INTRFLAGS(bse
)) & INTRMASK
)
372 /* Perform a host adapter inquiry instead so we do not need to set
373 up the mailboxes ahead of time */
375 aha1542_out(bse
, inquiry_cmd
, 1);
379 cmdp
= &inquiry_result
[0];
382 WAIT(STATUS(bse
), DF
, DF
, 0);
383 *cmdp
++ = inb(DATA(bse
));
387 /* Reading port should reset DF */
388 if (inb(STATUS(bse
)) & DF
)
392 /* When HACC, command is completed, and we're though testing */
393 WAIT(INTRFLAGS(bse
), HACC
, HACC
, 0);
394 /* now initialize adapter */
397 /* Clear interrupts */
398 outb(IRST
, CONTROL(bse
));
402 return debug
; /* 1 = ok */
404 return 0; /* 0 = not ok */
407 /* A quick wrapper for do_aha1542_intr_handle to grab the spin lock */
408 static void do_aha1542_intr_handle(int irq
, void *dev_id
, struct pt_regs
*regs
)
412 spin_lock_irqsave(&io_request_lock
, flags
);
413 aha1542_intr_handle(irq
, dev_id
, regs
);
414 spin_unlock_irqrestore(&io_request_lock
, flags
);
417 /* A "high" level interrupt handler */
418 static void aha1542_intr_handle(int irq
, void *dev_id
, struct pt_regs
*regs
)
420 void (*my_done
) (Scsi_Cmnd
*) = NULL
;
421 int errstatus
, mbi
, mbo
, mbistatus
;
424 struct Scsi_Host
*shost
;
431 shost
= aha_host
[irq
- 9];
435 mb
= HOSTDATA(shost
)->mb
;
436 ccb
= HOSTDATA(shost
)->ccb
;
440 flag
= inb(INTRFLAGS(shost
->io_port
));
441 printk(KERN_DEBUG
"aha1542_intr_handle: ");
442 if (!(flag
& ANYINTR
))
443 printk("no interrupt?");
452 printk("status %02x\n", inb(STATUS(shost
->io_port
)));
459 flag
= inb(INTRFLAGS(shost
->io_port
));
461 /* Check for unusual interrupts. If any of these happen, we should
462 probably do something special, but for now just printing a message
463 is sufficient. A SCSI reset detected is something that we really
464 need to deal with in some way. */
475 aha1542_intr_reset(shost
->io_port
);
479 mbi
= HOSTDATA(shost
)->aha1542_last_mbi_used
+ 1;
480 if (mbi
>= 2 * AHA1542_MAILBOXES
)
481 mbi
= AHA1542_MAILBOXES
;
484 if (mb
[mbi
].status
!= 0)
487 if (mbi
>= 2 * AHA1542_MAILBOXES
)
488 mbi
= AHA1542_MAILBOXES
;
489 } while (mbi
!= HOSTDATA(shost
)->aha1542_last_mbi_used
);
491 if (mb
[mbi
].status
== 0) {
492 restore_flags(flags
);
493 /* Hmm, no mail. Must have read it the last time around */
494 if (!number_serviced
&& !needs_restart
)
495 printk(KERN_WARNING
"aha1542.c: interrupt received, but no mail.\n");
496 /* We detected a reset. Restart all pending commands for
497 devices that use the hard reset option */
499 aha1542_restart(shost
);
503 mbo
= (scsi2int(mb
[mbi
].ccbptr
) - (SCSI_PA(&ccb
[0]))) / sizeof(struct ccb
);
504 mbistatus
= mb
[mbi
].status
;
506 HOSTDATA(shost
)->aha1542_last_mbi_used
= mbi
;
507 restore_flags(flags
);
511 if (ccb
[mbo
].tarstat
| ccb
[mbo
].hastat
)
512 printk(KERN_DEBUG
"aha1542_command: returning %x (status %d)\n",
513 ccb
[mbo
].tarstat
+ ((int) ccb
[mbo
].hastat
<< 16), mb
[mbi
].status
);
518 continue; /* Aborted command not found */
521 printk(KERN_DEBUG
"...done %d %d\n", mbo
, mbi
);
524 SCtmp
= HOSTDATA(shost
)->SCint
[mbo
];
526 if (!SCtmp
|| !SCtmp
->scsi_done
) {
527 printk(KERN_WARNING
"aha1542_intr_handle: Unexpected interrupt\n");
528 printk(KERN_WARNING
"tarstat=%x, hastat=%x idlun=%x ccb#=%d \n", ccb
[mbo
].tarstat
,
529 ccb
[mbo
].hastat
, ccb
[mbo
].idlun
, mbo
);
532 my_done
= SCtmp
->scsi_done
;
533 if (SCtmp
->host_scribble
) {
534 scsi_free(SCtmp
->host_scribble
, 512);
535 SCtmp
->host_scribble
= 0;
537 /* Fetch the sense data, and tuck it away, in the required slot. The
538 Adaptec automatically fetches it, and there is no guarantee that
539 we will still have it in the cdb when we come back */
540 if (ccb
[mbo
].tarstat
== 2)
541 memcpy(SCtmp
->sense_buffer
, &ccb
[mbo
].cdb
[ccb
[mbo
].cdblen
],
542 sizeof(SCtmp
->sense_buffer
));
545 /* is there mail :-) */
547 /* more error checking left out here */
549 /* This is surely wrong, but I don't know what's right */
550 errstatus
= makecode(ccb
[mbo
].hastat
, ccb
[mbo
].tarstat
);
556 printk(KERN_DEBUG
"(aha1542 error:%x %x %x) ", errstatus
,
557 ccb
[mbo
].hastat
, ccb
[mbo
].tarstat
);
560 if (ccb
[mbo
].tarstat
== 2) {
564 DEB(printk("aha1542_intr_handle: sense:"));
566 for (i
= 0; i
< 12; i
++)
567 printk("%02x ", ccb
[mbo
].cdb
[ccb
[mbo
].cdblen
+ i
]);
571 DEB(printk("aha1542_intr_handle: buf:"));
572 for (i = 0; i < bufflen; i++)
573 printk("%02x ", ((unchar *)buff)[i]);
577 DEB(if (errstatus
) printk("aha1542_intr_handle: returning %6x\n", errstatus
));
578 SCtmp
->result
= errstatus
;
579 HOSTDATA(shost
)->SCint
[mbo
] = NULL
; /* This effectively frees up the mailbox slot, as
580 far as queuecommand is concerned */
586 int aha1542_queuecommand(Scsi_Cmnd
* SCpnt
, void (*done
) (Scsi_Cmnd
*))
588 unchar ahacmd
= CMD_START_SCSI
;
590 unchar
*cmd
= (unchar
*) SCpnt
->cmnd
;
591 unchar target
= SCpnt
->target
;
592 unchar lun
= SCpnt
->lun
;
594 void *buff
= SCpnt
->request_buffer
;
595 int bufflen
= SCpnt
->request_bufflen
;
602 mb
= HOSTDATA(SCpnt
->host
)->mb
;
603 ccb
= HOSTDATA(SCpnt
->host
)->ccb
;
605 DEB(if (target
> 1) {
606 SCpnt
->result
= DID_TIME_OUT
<< 16;
607 done(SCpnt
); return 0;
611 if (*cmd
== REQUEST_SENSE
) {
612 /* Don't do the command - we have the sense data already */
614 /* scsi_request_sense() provides a buffer of size 256,
615 so there is no reason to expect equality */
616 if (bufflen
!= sizeof(SCpnt
->sense_buffer
))
617 printk(KERN_CRIT
"aha1542: Wrong buffer length supplied "
618 "for request sense (%d)\n", bufflen
);
625 if (*cmd
== READ_10
|| *cmd
== WRITE_10
)
626 i
= xscsi2int(cmd
+ 2);
627 else if (*cmd
== READ_6
|| *cmd
== WRITE_6
)
628 i
= scsi2int(cmd
+ 2);
632 printk(KERN_DEBUG
"aha1542_queuecommand: dev %d cmd %02x pos %d len %d ", target
, *cmd
, i
, bufflen
);
634 printk(KERN_DEBUG
"aha1542_command: dev %d cmd %02x pos %d len %d ", target
, *cmd
, i
, bufflen
);
636 printk(KERN_DEBUG
"aha1542_queuecommand: dumping scsi cmd:");
637 for (i
= 0; i
< SCpnt
->cmd_len
; i
++)
638 printk("%02x ", cmd
[i
]);
640 if (*cmd
== WRITE_10
|| *cmd
== WRITE_6
)
641 return 0; /* we are still testing, so *don't* write */
643 /* Use the outgoing mailboxes in a round-robin fashion, because this
644 is how the host adapter will scan for them */
648 mbo
= HOSTDATA(SCpnt
->host
)->aha1542_last_mbo_used
+ 1;
649 if (mbo
>= AHA1542_MAILBOXES
)
653 if (mb
[mbo
].status
== 0 && HOSTDATA(SCpnt
->host
)->SCint
[mbo
] == NULL
)
656 if (mbo
>= AHA1542_MAILBOXES
)
658 } while (mbo
!= HOSTDATA(SCpnt
->host
)->aha1542_last_mbo_used
);
660 if (mb
[mbo
].status
|| HOSTDATA(SCpnt
->host
)->SCint
[mbo
])
661 panic("Unable to find empty mailbox for aha1542.\n");
663 HOSTDATA(SCpnt
->host
)->SCint
[mbo
] = SCpnt
; /* This will effectively prevent someone else from
664 screwing with this cdb. */
666 HOSTDATA(SCpnt
->host
)->aha1542_last_mbo_used
= mbo
;
667 restore_flags(flags
);
670 printk(KERN_DEBUG
"Sending command (%d %x)...", mbo
, done
);
673 any2scsi(mb
[mbo
].ccbptr
, SCSI_PA(&ccb
[mbo
])); /* This gets trashed for some reason */
675 memset(&ccb
[mbo
], 0, sizeof(struct ccb
));
677 ccb
[mbo
].cdblen
= SCpnt
->cmd_len
;
680 if (*cmd
== READ_10
|| *cmd
== READ_6
)
682 else if (*cmd
== WRITE_10
|| *cmd
== WRITE_6
)
685 memcpy(ccb
[mbo
].cdb
, cmd
, ccb
[mbo
].cdblen
);
688 struct scatterlist
*sgpnt
;
694 ccb
[mbo
].op
= 2; /* SCSI Initiator Command w/scatter-gather */
695 SCpnt
->host_scribble
= (unsigned char *) scsi_malloc(512);
696 sgpnt
= (struct scatterlist
*) SCpnt
->request_buffer
;
697 cptr
= (struct chain
*) SCpnt
->host_scribble
;
699 panic("aha1542.c: unable to allocate DMA memory\n");
700 for (i
= 0; i
< SCpnt
->use_sg
; i
++) {
701 if (sgpnt
[i
].length
== 0 || SCpnt
->use_sg
> 16 ||
702 (((int) sgpnt
[i
].address
) & 1) || (sgpnt
[i
].length
& 1)) {
704 printk(KERN_CRIT
"Bad segment list supplied to aha1542.c (%d, %d)\n", SCpnt
->use_sg
, i
);
705 for (i
= 0; i
< SCpnt
->use_sg
; i
++) {
706 printk(KERN_CRIT
"%d: %x %x %d\n", i
, (unsigned int) sgpnt
[i
].address
, (unsigned int) sgpnt
[i
].alt_address
,
709 printk(KERN_CRIT
"cptr %x: ", (unsigned int) cptr
);
710 ptr
= (unsigned char *) &cptr
[i
];
711 for (i
= 0; i
< 18; i
++)
712 printk("%02x ", ptr
[i
]);
713 panic("Foooooooood fight!");
715 any2scsi(cptr
[i
].dataptr
, SCSI_PA(sgpnt
[i
].address
));
716 if (SCSI_PA(sgpnt
[i
].address
+ sgpnt
[i
].length
- 1) > ISA_DMA_THRESHOLD
)
717 BAD_SG_DMA(SCpnt
, sgpnt
, SCpnt
->use_sg
, i
);
718 any2scsi(cptr
[i
].datalen
, sgpnt
[i
].length
);
720 any2scsi(ccb
[mbo
].datalen
, SCpnt
->use_sg
* sizeof(struct chain
));
721 any2scsi(ccb
[mbo
].dataptr
, SCSI_PA(cptr
));
723 printk("cptr %x: ", cptr
);
724 ptr
= (unsigned char *) cptr
;
725 for (i
= 0; i
< 18; i
++)
726 printk("%02x ", ptr
[i
]);
729 ccb
[mbo
].op
= 0; /* SCSI Initiator Command */
730 SCpnt
->host_scribble
= NULL
;
731 any2scsi(ccb
[mbo
].datalen
, bufflen
);
732 if (buff
&& SCSI_PA(buff
+ bufflen
- 1) > ISA_DMA_THRESHOLD
)
733 BAD_DMA(buff
, bufflen
);
734 any2scsi(ccb
[mbo
].dataptr
, SCSI_PA(buff
));
736 ccb
[mbo
].idlun
= (target
& 7) << 5 | direction
| (lun
& 7); /*SCSI Target Id */
737 ccb
[mbo
].rsalen
= 16;
738 ccb
[mbo
].linkptr
[0] = ccb
[mbo
].linkptr
[1] = ccb
[mbo
].linkptr
[2] = 0;
739 ccb
[mbo
].commlinkid
= 0;
744 printk(KERN_DEBUG
"aha1542_command: sending.. ");
745 for (i
= 0; i
< sizeof(ccb
[mbo
]) - 10; i
++)
746 printk("%02x ", ((unchar
*) & ccb
[mbo
])[i
]);
751 DEB(printk("aha1542_queuecommand: now waiting for interrupt ");
753 SCpnt
->scsi_done
= done
;
755 aha1542_out(SCpnt
->host
->io_port
, &ahacmd
, 1); /* start scsi command */
758 printk("aha1542_queuecommand: done can't be NULL\n");
763 static void internal_done(Scsi_Cmnd
* SCpnt
)
768 int aha1542_command(Scsi_Cmnd
* SCpnt
)
770 DEB(printk("aha1542_command: ..calling aha1542_queuecommand\n"));
772 aha1542_queuecommand(SCpnt
, internal_done
);
774 SCpnt
->SCp
.Status
= 0;
775 while (!SCpnt
->SCp
.Status
)
777 return SCpnt
->result
;
780 /* Initialize mailboxes */
781 static void setup_mailboxes(int bse
, struct Scsi_Host
*shpnt
)
787 unchar cmd
[5] = { CMD_MBINIT
, AHA1542_MAILBOXES
, 0, 0, 0};
789 mb
= HOSTDATA(shpnt
)->mb
;
790 ccb
= HOSTDATA(shpnt
)->ccb
;
792 for (i
= 0; i
< AHA1542_MAILBOXES
; i
++) {
793 mb
[i
].status
= mb
[AHA1542_MAILBOXES
+ i
].status
= 0;
794 any2scsi(mb
[i
].ccbptr
, SCSI_PA(&ccb
[i
]));
796 aha1542_intr_reset(bse
); /* reset interrupts, so they don't block */
797 any2scsi((cmd
+ 2), SCSI_PA(mb
));
798 aha1542_out(bse
, cmd
, 5);
799 WAIT(INTRFLAGS(bse
), INTRMASK
, HACC
, 0);
802 printk(KERN_ERR
"aha1542_detect: failed setting up mailboxes\n");
804 aha1542_intr_reset(bse
);
807 static int aha1542_getconfig(int base_io
, unsigned char *irq_level
, unsigned char *dma_chan
, unsigned char *scsi_id
)
809 unchar inquiry_cmd
[] = {CMD_RETCONF
};
810 unchar inquiry_result
[3];
812 i
= inb(STATUS(base_io
));
814 i
= inb(DATA(base_io
));
816 aha1542_out(base_io
, inquiry_cmd
, 1);
817 aha1542_in(base_io
, inquiry_result
, 3);
818 WAIT(INTRFLAGS(base_io
), INTRMASK
, HACC
, 0);
821 printk(KERN_ERR
"aha1542_detect: query board settings\n");
823 aha1542_intr_reset(base_io
);
824 switch (inquiry_result
[0]) {
838 /* This means that the adapter, although Adaptec 1542 compatible, doesn't use a DMA channel.
839 Currently only aware of the BusLogic BT-445S VL-Bus adapter which needs this. */
843 printk(KERN_ERR
"Unable to determine Adaptec DMA priority. Disabling board\n");
846 switch (inquiry_result
[1]) {
866 printk(KERN_ERR
"Unable to determine Adaptec IRQ level. Disabling board\n");
869 *scsi_id
= inquiry_result
[2] & 7;
873 /* This function should only be called for 1542C boards - we can detect
874 the special firmware settings and unlock the board */
876 static int aha1542_mbenable(int base
)
878 static unchar mbenable_cmd
[3];
879 static unchar mbenable_result
[2];
882 retval
= BIOS_TRANSLATION_6432
;
884 mbenable_cmd
[0] = CMD_EXTBIOS
;
885 aha1542_out(base
, mbenable_cmd
, 1);
886 if (aha1542_in1(base
, mbenable_result
, 2))
888 WAITd(INTRFLAGS(base
), INTRMASK
, HACC
, 0, 100);
889 aha1542_intr_reset(base
);
891 if ((mbenable_result
[0] & 0x08) || mbenable_result
[1]) {
892 mbenable_cmd
[0] = CMD_MBENABLE
;
894 mbenable_cmd
[2] = mbenable_result
[1];
896 if ((mbenable_result
[0] & 0x08) && (mbenable_result
[1] & 0x03))
897 retval
= BIOS_TRANSLATION_25563
;
899 aha1542_out(base
, mbenable_cmd
, 3);
900 WAIT(INTRFLAGS(base
), INTRMASK
, HACC
, 0);
904 printk(KERN_ERR
"aha1542_mbenable: Mailbox init failed\n");
906 aha1542_intr_reset(base
);
910 /* Query the board to find out if it is a 1542 or a 1740, or whatever. */
911 static int aha1542_query(int base_io
, int *transl
)
913 unchar inquiry_cmd
[] = {CMD_INQUIRY
};
914 unchar inquiry_result
[4];
916 i
= inb(STATUS(base_io
));
918 i
= inb(DATA(base_io
));
920 aha1542_out(base_io
, inquiry_cmd
, 1);
921 aha1542_in(base_io
, inquiry_result
, 4);
922 WAIT(INTRFLAGS(base_io
), INTRMASK
, HACC
, 0);
925 printk(KERN_ERR
"aha1542_detect: query card type\n");
927 aha1542_intr_reset(base_io
);
929 *transl
= BIOS_TRANSLATION_6432
; /* Default case */
931 /* For an AHA1740 series board, we ignore the board since there is a
932 hardware bug which can lead to wrong blocks being returned if the board
933 is operating in the 1542 emulation mode. Since there is an extended mode
934 driver, we simply ignore the board and let the 1740 driver pick it up.
937 if (inquiry_result
[0] == 0x43) {
938 printk(KERN_INFO
"aha1542.c: Emulation mode not supported for AHA 174N hardware.\n");
942 /* Always call this - boards that do not support extended bios translation
943 will ignore the command, and we will set the proper default */
945 *transl
= aha1542_mbenable(base_io
);
950 /* called from init/main.c */
951 void __init
aha1542_setup(char *str
, int *ints
)
953 const char *ahausage
= "aha1542: usage: aha1542=<PORTBASE>[,<BUSON>,<BUSOFF>[,<DMASPEED>]]\n";
954 static int setup_idx
= 0;
957 if (setup_idx
>= MAXBOARDS
) {
958 printk(KERN_ERR
"aha1542: aha1542_setup called too many times! Bad LILO params ?\n");
959 printk(KERN_ERR
" Entryline 1: %s\n", setup_str
[0]);
960 printk(KERN_ERR
" Entryline 2: %s\n", setup_str
[1]);
961 printk(KERN_ERR
" This line: %s\n", str
);
964 if (ints
[0] < 1 || ints
[0] > 4) {
965 printk(KERN_ERR
"aha1542: %s\n", str
);
967 printk(KERN_ERR
"aha1542: Wrong parameters may cause system malfunction.. We try anyway..\n");
969 setup_called
[setup_idx
] = ints
[0];
970 setup_str
[setup_idx
] = str
;
972 setup_portbase
= ints
[0] >= 1 ? ints
[1] : 0; /* Preserve the default value.. */
973 setup_buson
[setup_idx
] = ints
[0] >= 2 ? ints
[2] : 7;
974 setup_busoff
[setup_idx
] = ints
[0] >= 3 ? ints
[3] : 5;
995 printk(KERN_ERR
"aha1542: %s\n", str
);
997 printk(KERN_ERR
"aha1542: Valid values for DMASPEED are 5-8, 10 MB/s. Using jumper defaults.\n");
1000 setup_dmaspeed
[setup_idx
] = atbt
;
1002 if (setup_portbase
!= 0)
1003 bases
[setup_idx
] = setup_portbase
;
1008 /* return non-zero on detection */
1009 int aha1542_detect(Scsi_Host_Template
* tpnt
)
1011 unsigned char dma_chan
;
1012 unsigned char irq_level
;
1013 unsigned char scsi_id
;
1014 unsigned long flags
;
1015 unsigned int base_io
;
1017 struct Scsi_Host
*shpnt
= NULL
;
1021 DEB(printk("aha1542_detect: \n"));
1023 tpnt
->proc_name
= "aha1542";
1026 bases
[0] = aha1542
[0];
1027 setup_buson
[0]=aha1542
[1];
1028 setup_busoff
[0] = aha1542
[2];
1031 switch (aha1542
[3]) {
1048 setup_dmaspeed
[0] = atbt
;
1053 * Find MicroChannel cards (AHA1640)
1060 for (indx
= 0; (slot
!= MCA_NOTFOUND
) &&
1061 (indx
< sizeof(bases
)/sizeof(bases
[0])); indx
++) {
1066 /* Detect only AHA-1640 cards -- MCA ID 0F1F */
1067 slot
= mca_find_unused_adapter(0x0f1f, slot
);
1068 if (slot
== MCA_NOTFOUND
)
1073 pos
= mca_read_stored_pos(slot
, 3);
1075 /* Decode address */
1079 bases
[indx
] = 0x334;
1081 bases
[indx
] = 0x234;
1084 bases
[indx
] = 0x134;
1089 bases
[indx
] = 0x330;
1091 bases
[indx
] = 0x230;
1094 bases
[indx
] = 0x130;
1098 /* No need to decode IRQ and Arb level -- those are
1099 * read off the card later.
1101 printk(KERN_INFO
"Found an AHA-1640 in MCA slot %d, I/O 0x%04x\n", slot
, bases
[indx
]);
1103 mca_set_adapter_name(slot
, "Adapter AHA-1640");
1104 mca_set_adapter_procfn(slot
, NULL
, NULL
);
1105 mca_mark_as_used(slot
);
1115 * Hunt for ISA Plug'n'Pray Adaptecs (AHA1535)
1120 struct pci_dev
*pdev
= NULL
;
1121 for(indx
= 0; indx
<sizeof(bases
)/sizeof(bases
[0]);indx
++)
1125 pdev
= isapnp_find_dev(NULL
, ISAPNP_VENDOR('A', 'D', 'P'),
1126 ISAPNP_FUNCTION(0x1542), pdev
);
1130 * Activate the PnP card
1133 if(pdev
->prepare(pdev
)<0)
1136 if(!(pdev
->resource
[0].flags
&IORESOURCE_IO
))
1139 pdev
->resource
[0].flags
|=IORESOURCE_AUTO
;
1141 if(pdev
->activate(pdev
)<0)
1144 bases
[indx
] = pdev
->resource
[0].start
;
1146 /* The card can be queried for its DMA, we have
1147 the DMA set up that is enough */
1149 printk(KERN_INFO
"ISAPnP found an AHA1535 at I/O 0x%03X\n", bases
[indx
]);
1152 for (indx
= 0; indx
< sizeof(bases
) / sizeof(bases
[0]); indx
++)
1153 if (bases
[indx
] != 0 && !check_region(bases
[indx
], 4)) {
1154 shpnt
= scsi_register(tpnt
,
1155 sizeof(struct aha1542_hostdata
));
1159 /* For now we do this - until kmalloc is more intelligent
1160 we are resigned to stupid hacks like this */
1161 if (SCSI_PA(shpnt
) >= ISA_DMA_THRESHOLD
) {
1162 printk(KERN_ERR
"Invalid address for shpnt with 1542.\n");
1165 if (!aha1542_test_port(bases
[indx
], shpnt
))
1169 base_io
= bases
[indx
];
1171 /* Set the Bus on/off-times as not to ruin floppy performance */
1173 unchar oncmd
[] = {CMD_BUSON_TIME
, 7};
1174 unchar offcmd
[] = {CMD_BUSOFF_TIME
, 5};
1176 if (setup_called
[indx
]) {
1177 oncmd
[1] = setup_buson
[indx
];
1178 offcmd
[1] = setup_busoff
[indx
];
1180 aha1542_intr_reset(base_io
);
1181 aha1542_out(base_io
, oncmd
, 2);
1182 WAIT(INTRFLAGS(base_io
), INTRMASK
, HACC
, 0);
1183 aha1542_intr_reset(base_io
);
1184 aha1542_out(base_io
, offcmd
, 2);
1185 WAIT(INTRFLAGS(base_io
), INTRMASK
, HACC
, 0);
1186 if (setup_dmaspeed
[indx
] >= 0) {
1187 unchar dmacmd
[] = {CMD_DMASPEED
, 0};
1188 dmacmd
[1] = setup_dmaspeed
[indx
];
1189 aha1542_intr_reset(base_io
);
1190 aha1542_out(base_io
, dmacmd
, 2);
1191 WAIT(INTRFLAGS(base_io
), INTRMASK
, HACC
, 0);
1195 printk(KERN_ERR
"aha1542_detect: setting bus on/off-time failed\n");
1197 aha1542_intr_reset(base_io
);
1199 if (aha1542_query(base_io
, &trans
))
1202 if (aha1542_getconfig(base_io
, &irq_level
, &dma_chan
, &scsi_id
) == -1)
1205 printk(KERN_INFO
"Configuring Adaptec (SCSI-ID %d) at IO:%x, IRQ %d", scsi_id
, base_io
, irq_level
);
1206 if (dma_chan
!= 0xFF)
1207 printk(", DMA priority %d", dma_chan
);
1210 DEB(aha1542_stat());
1211 setup_mailboxes(base_io
, shpnt
);
1213 DEB(aha1542_stat());
1215 DEB(printk("aha1542_detect: enable interrupt channel %d\n", irq_level
));
1218 if (request_irq(irq_level
, do_aha1542_intr_handle
, 0, "aha1542", NULL
)) {
1219 printk(KERN_ERR
"Unable to allocate IRQ for adaptec controller.\n");
1220 restore_flags(flags
);
1223 if (dma_chan
!= 0xFF) {
1224 if (request_dma(dma_chan
, "aha1542")) {
1225 printk(KERN_ERR
"Unable to allocate DMA channel for Adaptec.\n");
1226 free_irq(irq_level
, NULL
);
1227 restore_flags(flags
);
1230 if (dma_chan
== 0 || dma_chan
>= 5) {
1231 set_dma_mode(dma_chan
, DMA_MODE_CASCADE
);
1232 enable_dma(dma_chan
);
1235 aha_host
[irq_level
- 9] = shpnt
;
1236 shpnt
->this_id
= scsi_id
;
1237 shpnt
->unique_id
= base_io
;
1238 shpnt
->io_port
= base_io
;
1239 shpnt
->n_io_port
= 4; /* Number of bytes of I/O space used */
1240 shpnt
->dma_channel
= dma_chan
;
1241 shpnt
->irq
= irq_level
;
1242 HOSTDATA(shpnt
)->bios_translation
= trans
;
1243 if (trans
== BIOS_TRANSLATION_25563
)
1244 printk(KERN_INFO
"aha1542.c: Using extended bios translation\n");
1245 HOSTDATA(shpnt
)->aha1542_last_mbi_used
= (2 * AHA1542_MAILBOXES
- 1);
1246 HOSTDATA(shpnt
)->aha1542_last_mbo_used
= (AHA1542_MAILBOXES
- 1);
1247 memset(HOSTDATA(shpnt
)->SCint
, 0, sizeof(HOSTDATA(shpnt
)->SCint
));
1248 restore_flags(flags
);
1250 DEB(printk(" *** READ CAPACITY ***\n"));
1254 static unchar cmd
[] = { READ_CAPACITY
, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
1257 for (i
= 0; i
< sizeof(buf
); ++i
)
1259 for (i
= 0; i
< 2; ++i
)
1260 if (!aha1542_command(i
, cmd
, buf
, sizeof(buf
))) {
1261 printk(KERN_DEBUG
"aha_detect: LU %d sector_size %d device_size %d\n",
1262 i
, xscsi2int(buf
+ 4), xscsi2int(buf
));
1266 DEB(printk(" *** NOW RUNNING MY OWN TEST *** \n"));
1268 for (i
= 0; i
< 4; ++i
) {
1269 unsigned char cmd
[10];
1274 xany2scsi(cmd
+ 2, i
);
1279 aha1542_command(0, cmd
, buffer
, 512);
1282 request_region(bases
[indx
], 4, "aha1542"); /* Register the IO ports that we use */
1286 scsi_unregister(shpnt
);
1294 static int aha1542_restart(struct Scsi_Host
*shost
)
1299 unchar ahacmd
= CMD_START_SCSI
;
1302 for (i
= 0; i
< AHA1542_MAILBOXES
; i
++)
1303 if (HOSTDATA(shost
)->SCint
[i
] &&
1304 !(HOSTDATA(shost
)->SCint
[i
]->device
->soft_reset
)) {
1306 HOSTDATA(shost
)->mb
[i
].status
= 1; /* Indicate ready to restart... */
1310 printk(KERN_DEBUG
"Potential to restart %d stalled commands...\n", count
);
1312 /* start scsi command */
1314 aha1542_out(shost
->io_port
, &ahacmd
, 1);
1319 int aha1542_abort(Scsi_Cmnd
* SCpnt
)
1323 * The abort command does not leave the device in a clean state where
1324 * it is available to be used again. Until this gets worked out, we
1325 * will leave it commented out.
1328 printk(KERN_ERR
"aha1542.c: Unable to abort command for target %d\n",
1334 * This is a device reset. This is handled by sending a special command
1337 int aha1542_dev_reset(Scsi_Cmnd
* SCpnt
)
1339 unsigned long flags
;
1341 unchar target
= SCpnt
->target
;
1342 unchar lun
= SCpnt
->lun
;
1345 unchar ahacmd
= CMD_START_SCSI
;
1347 ccb
= HOSTDATA(SCpnt
->host
)->ccb
;
1348 mb
= HOSTDATA(SCpnt
->host
)->mb
;
1352 mbo
= HOSTDATA(SCpnt
->host
)->aha1542_last_mbo_used
+ 1;
1353 if (mbo
>= AHA1542_MAILBOXES
)
1357 if (mb
[mbo
].status
== 0 && HOSTDATA(SCpnt
->host
)->SCint
[mbo
] == NULL
)
1360 if (mbo
>= AHA1542_MAILBOXES
)
1362 } while (mbo
!= HOSTDATA(SCpnt
->host
)->aha1542_last_mbo_used
);
1364 if (mb
[mbo
].status
|| HOSTDATA(SCpnt
->host
)->SCint
[mbo
])
1365 panic("Unable to find empty mailbox for aha1542.\n");
1367 HOSTDATA(SCpnt
->host
)->SCint
[mbo
] = SCpnt
; /* This will effectively
1368 prevent someone else from
1369 screwing with this cdb. */
1371 HOSTDATA(SCpnt
->host
)->aha1542_last_mbo_used
= mbo
;
1372 restore_flags(flags
);
1374 any2scsi(mb
[mbo
].ccbptr
, SCSI_PA(&ccb
[mbo
])); /* This gets trashed for some reason */
1376 memset(&ccb
[mbo
], 0, sizeof(struct ccb
));
1378 ccb
[mbo
].op
= 0x81; /* BUS DEVICE RESET */
1380 ccb
[mbo
].idlun
= (target
& 7) << 5 | (lun
& 7); /*SCSI Target Id */
1382 ccb
[mbo
].linkptr
[0] = ccb
[mbo
].linkptr
[1] = ccb
[mbo
].linkptr
[2] = 0;
1383 ccb
[mbo
].commlinkid
= 0;
1386 * Now tell the 1542 to flush all pending commands for this
1389 aha1542_out(SCpnt
->host
->io_port
, &ahacmd
, 1);
1391 printk(KERN_WARNING
"aha1542.c: Trying device reset for target %d\n", SCpnt
->target
);
1396 #ifdef ERIC_neverdef
1398 * With the 1542 we apparently never get an interrupt to
1399 * acknowledge a device reset being sent. Then again, Leonard
1400 * says we are doing this wrong in the first place...
1402 * Take a wait and see attitude. If we get spurious interrupts,
1403 * then the device reset is doing something sane and useful, and
1404 * we will wait for the interrupt to post completion.
1406 printk(KERN_WARNING
"Sent BUS DEVICE RESET to target %d\n", SCpnt
->target
);
1409 * Free the command block for all commands running on this
1412 for (i
= 0; i
< AHA1542_MAILBOXES
; i
++) {
1413 if (HOSTDATA(SCpnt
->host
)->SCint
[i
] &&
1414 HOSTDATA(SCpnt
->host
)->SCint
[i
]->target
== SCpnt
->target
) {
1416 SCtmp
= HOSTDATA(SCpnt
->host
)->SCint
[i
];
1417 if (SCtmp
->host_scribble
) {
1418 scsi_free(SCtmp
->host_scribble
, 512);
1419 SCtmp
->host_scribble
= NULL
;
1421 HOSTDATA(SCpnt
->host
)->SCint
[i
] = NULL
;
1422 HOSTDATA(SCpnt
->host
)->mb
[i
].status
= 0;
1428 #endif /* ERIC_neverdef */
1431 int aha1542_bus_reset(Scsi_Cmnd
* SCpnt
)
1436 * This does a scsi reset for all devices on the bus.
1437 * In principle, we could also reset the 1542 - should
1438 * we do this? Try this first, and we can add that later
1439 * if it turns out to be useful.
1441 outb(SCRST
, CONTROL(SCpnt
->host
->io_port
));
1444 * Wait for the thing to settle down a bit. Unfortunately
1445 * this is going to basically lock up the machine while we
1446 * wait for this to complete. To be 100% correct, we need to
1447 * check for timeout, and if we are doing something like this
1448 * we are pretty desperate anyways.
1450 spin_unlock_irq(&io_request_lock
);
1452 spin_lock_irq(&io_request_lock
);
1454 WAIT(STATUS(SCpnt
->host
->io_port
),
1455 STATMASK
, INIT
| IDLE
, STST
| DIAGF
| INVDCMD
| DF
| CDF
);
1458 * Now try to pick up the pieces. For all pending commands,
1459 * free any internal data structures, and basically clear things
1460 * out. We do not try and restart any commands or anything -
1461 * the strategy handler takes care of that crap.
1463 printk(KERN_WARNING
"Sent BUS RESET to scsi host %d\n", SCpnt
->host
->host_no
);
1465 for (i
= 0; i
< AHA1542_MAILBOXES
; i
++) {
1466 if (HOSTDATA(SCpnt
->host
)->SCint
[i
] != NULL
) {
1468 SCtmp
= HOSTDATA(SCpnt
->host
)->SCint
[i
];
1471 if (SCtmp
->device
->soft_reset
) {
1473 * If this device implements the soft reset option,
1474 * then it is still holding onto the command, and
1475 * may yet complete it. In this case, we don't
1480 if (SCtmp
->host_scribble
) {
1481 scsi_free(SCtmp
->host_scribble
, 512);
1482 SCtmp
->host_scribble
= NULL
;
1484 HOSTDATA(SCpnt
->host
)->SCint
[i
] = NULL
;
1485 HOSTDATA(SCpnt
->host
)->mb
[i
].status
= 0;
1495 int aha1542_host_reset(Scsi_Cmnd
* SCpnt
)
1500 * This does a scsi reset for all devices on the bus.
1501 * In principle, we could also reset the 1542 - should
1502 * we do this? Try this first, and we can add that later
1503 * if it turns out to be useful.
1505 outb(HRST
| SCRST
, CONTROL(SCpnt
->host
->io_port
));
1508 * Wait for the thing to settle down a bit. Unfortunately
1509 * this is going to basically lock up the machine while we
1510 * wait for this to complete. To be 100% correct, we need to
1511 * check for timeout, and if we are doing something like this
1512 * we are pretty desperate anyways.
1514 spin_unlock_irq(&io_request_lock
);
1516 spin_lock_irq(&io_request_lock
);
1518 WAIT(STATUS(SCpnt
->host
->io_port
),
1519 STATMASK
, INIT
| IDLE
, STST
| DIAGF
| INVDCMD
| DF
| CDF
);
1522 * We need to do this too before the 1542 can interact with
1525 setup_mailboxes(SCpnt
->host
->io_port
, SCpnt
->host
);
1528 * Now try to pick up the pieces. For all pending commands,
1529 * free any internal data structures, and basically clear things
1530 * out. We do not try and restart any commands or anything -
1531 * the strategy handler takes care of that crap.
1533 printk(KERN_WARNING
"Sent BUS RESET to scsi host %d\n", SCpnt
->host
->host_no
);
1535 for (i
= 0; i
< AHA1542_MAILBOXES
; i
++) {
1536 if (HOSTDATA(SCpnt
->host
)->SCint
[i
] != NULL
) {
1538 SCtmp
= HOSTDATA(SCpnt
->host
)->SCint
[i
];
1540 if (SCtmp
->device
->soft_reset
) {
1542 * If this device implements the soft reset option,
1543 * then it is still holding onto the command, and
1544 * may yet complete it. In this case, we don't
1549 if (SCtmp
->host_scribble
) {
1550 scsi_free(SCtmp
->host_scribble
, 512);
1551 SCtmp
->host_scribble
= NULL
;
1553 HOSTDATA(SCpnt
->host
)->SCint
[i
] = NULL
;
1554 HOSTDATA(SCpnt
->host
)->mb
[i
].status
= 0;
1565 * These are the old error handling routines. They are only temporarily
1566 * here while we play with the new error handling code.
1568 int aha1542_old_abort(Scsi_Cmnd
* SCpnt
)
1571 unchar ahacmd
= CMD_START_SCSI
;
1572 unsigned long flags
;
1576 printk(KERN_DEBUG
"In aha1542_abort: %x %x\n",
1577 inb(STATUS(SCpnt
->host
->io_port
)),
1578 inb(INTRFLAGS(SCpnt
->host
->io_port
)));
1582 mb
= HOSTDATA(SCpnt
->host
)->mb
;
1583 mbi
= HOSTDATA(SCpnt
->host
)->aha1542_last_mbi_used
+ 1;
1584 if (mbi
>= 2 * AHA1542_MAILBOXES
)
1585 mbi
= AHA1542_MAILBOXES
;
1588 if (mb
[mbi
].status
!= 0)
1591 if (mbi
>= 2 * AHA1542_MAILBOXES
)
1592 mbi
= AHA1542_MAILBOXES
;
1593 } while (mbi
!= HOSTDATA(SCpnt
->host
)->aha1542_last_mbi_used
);
1594 restore_flags(flags
);
1596 if (mb
[mbi
].status
) {
1597 printk(KERN_ERR
"Lost interrupt discovered on irq %d - attempting to recover\n",
1599 aha1542_intr_handle(SCpnt
->host
->irq
, NULL
);
1602 /* OK, no lost interrupt. Try looking to see how many pending commands
1603 we think we have. */
1605 for (i
= 0; i
< AHA1542_MAILBOXES
; i
++)
1606 if (HOSTDATA(SCpnt
->host
)->SCint
[i
]) {
1607 if (HOSTDATA(SCpnt
->host
)->SCint
[i
] == SCpnt
) {
1608 printk(KERN_ERR
"Timed out command pending for %s\n",
1609 kdevname(SCpnt
->request
.rq_dev
));
1610 if (HOSTDATA(SCpnt
->host
)->mb
[i
].status
) {
1611 printk(KERN_ERR
"OGMB still full - restarting\n");
1612 aha1542_out(SCpnt
->host
->io_port
, &ahacmd
, 1);
1615 printk(KERN_ERR
"Other pending command %s\n",
1616 kdevname(SCpnt
->request
.rq_dev
));
1620 DEB(printk("aha1542_abort\n"));
1624 for (mbo
= 0; mbo
< AHA1542_MAILBOXES
; mbo
++)
1625 if (SCpnt
== HOSTDATA(SCpnt
->host
)->SCint
[mbo
]) {
1626 mb
[mbo
].status
= 2; /* Abort command */
1627 aha1542_out(SCpnt
->host
->io_port
, &ahacmd
, 1); /* start scsi command */
1628 restore_flags(flags
);
1632 return SCSI_ABORT_SNOOZE
;
1635 /* We do not implement a reset function here, but the upper level code
1636 assumes that it will get some kind of response for the command in
1637 SCpnt. We must oblige, or the command will hang the scsi system.
1638 For a first go, we assume that the 1542 notifies us with all of the
1639 pending commands (it does implement soft reset, after all). */
1641 int aha1542_old_reset(Scsi_Cmnd
* SCpnt
, unsigned int reset_flags
)
1643 unchar ahacmd
= CMD_START_SCSI
;
1647 * See if a bus reset was suggested.
1649 if (reset_flags
& SCSI_RESET_SUGGEST_BUS_RESET
) {
1651 * This does a scsi reset for all devices on the bus.
1652 * In principle, we could also reset the 1542 - should
1653 * we do this? Try this first, and we can add that later
1654 * if it turns out to be useful.
1656 outb(HRST
| SCRST
, CONTROL(SCpnt
->host
->io_port
));
1659 * Wait for the thing to settle down a bit. Unfortunately
1660 * this is going to basically lock up the machine while we
1661 * wait for this to complete. To be 100% correct, we need to
1662 * check for timeout, and if we are doing something like this
1663 * we are pretty desperate anyways.
1665 WAIT(STATUS(SCpnt
->host
->io_port
),
1666 STATMASK
, INIT
| IDLE
, STST
| DIAGF
| INVDCMD
| DF
| CDF
);
1669 * We need to do this too before the 1542 can interact with
1672 setup_mailboxes(SCpnt
->host
->io_port
, SCpnt
->host
);
1675 * Now try to pick up the pieces. Restart all commands
1676 * that are currently active on the bus, and reset all of
1677 * the datastructures. We have some time to kill while
1678 * things settle down, so print a nice message.
1680 printk(KERN_WARNING
"Sent BUS RESET to scsi host %d\n", SCpnt
->host
->host_no
);
1682 for (i
= 0; i
< AHA1542_MAILBOXES
; i
++)
1683 if (HOSTDATA(SCpnt
->host
)->SCint
[i
] != NULL
) {
1685 SCtmp
= HOSTDATA(SCpnt
->host
)->SCint
[i
];
1686 SCtmp
->result
= DID_RESET
<< 16;
1687 if (SCtmp
->host_scribble
) {
1688 scsi_free(SCtmp
->host_scribble
, 512);
1689 SCtmp
->host_scribble
= NULL
;
1691 printk(KERN_WARNING
"Sending DID_RESET for target %d\n", SCpnt
->target
);
1692 SCtmp
->scsi_done(SCpnt
);
1694 HOSTDATA(SCpnt
->host
)->SCint
[i
] = NULL
;
1695 HOSTDATA(SCpnt
->host
)->mb
[i
].status
= 0;
1698 * Now tell the mid-level code what we did here. Since
1699 * we have restarted all of the outstanding commands,
1700 * then report SUCCESS.
1702 return (SCSI_RESET_SUCCESS
| SCSI_RESET_BUS_RESET
);
1704 printk(KERN_CRIT
"aha1542.c: Unable to perform hard reset.\n");
1705 printk(KERN_CRIT
"Power cycle machine to reset\n");
1706 return (SCSI_RESET_ERROR
| SCSI_RESET_BUS_RESET
);
1710 /* This does a selective reset of just the one device */
1711 /* First locate the ccb for this command */
1712 for (i
= 0; i
< AHA1542_MAILBOXES
; i
++)
1713 if (HOSTDATA(SCpnt
->host
)->SCint
[i
] == SCpnt
) {
1714 HOSTDATA(SCpnt
->host
)->ccb
[i
].op
= 0x81; /* BUS DEVICE RESET */
1715 /* Now tell the 1542 to flush all pending commands for this target */
1716 aha1542_out(SCpnt
->host
->io_port
, &ahacmd
, 1);
1718 /* Here is the tricky part. What to do next. Do we get an interrupt
1719 for the commands that we aborted with the specified target, or
1720 do we generate this on our own? Try it without first and see
1722 printk(KERN_WARNING
"Sent BUS DEVICE RESET to target %d\n", SCpnt
->target
);
1724 /* If the first does not work, then try the second. I think the
1725 first option is more likely to be correct. Free the command
1726 block for all commands running on this target... */
1727 for (i
= 0; i
< AHA1542_MAILBOXES
; i
++)
1728 if (HOSTDATA(SCpnt
->host
)->SCint
[i
] &&
1729 HOSTDATA(SCpnt
->host
)->SCint
[i
]->target
== SCpnt
->target
) {
1731 SCtmp
= HOSTDATA(SCpnt
->host
)->SCint
[i
];
1732 SCtmp
->result
= DID_RESET
<< 16;
1733 if (SCtmp
->host_scribble
) {
1734 scsi_free(SCtmp
->host_scribble
, 512);
1735 SCtmp
->host_scribble
= NULL
;
1737 printk(KERN_WARNING
"Sending DID_RESET for target %d\n", SCpnt
->target
);
1738 SCtmp
->scsi_done(SCpnt
);
1740 HOSTDATA(SCpnt
->host
)->SCint
[i
] = NULL
;
1741 HOSTDATA(SCpnt
->host
)->mb
[i
].status
= 0;
1743 return SCSI_RESET_SUCCESS
;
1746 /* No active command at this time, so this means that each time we got
1747 some kind of response the last time through. Tell the mid-level code
1748 to request sense information in order to decide what to do next. */
1749 return SCSI_RESET_PUNT
;
1754 int aha1542_biosparam(Scsi_Disk
* disk
, kdev_t dev
, int *ip
)
1756 int translation_algorithm
;
1757 int size
= disk
->capacity
;
1759 translation_algorithm
= HOSTDATA(disk
->device
->host
)->bios_translation
;
1761 if ((size
>> 11) > 1024 && translation_algorithm
== BIOS_TRANSLATION_25563
) {
1762 /* Please verify that this is the same as what DOS returns */
1765 ip
[2] = size
/ 255 / 63;
1776 /* Eventually this will go into an include file, but this will be later */
1777 static Scsi_Host_Template driver_template
= AHA1542
;
1779 #include "scsi_module.c"