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
));
1157 /* For now we do this - until kmalloc is more intelligent
1158 we are resigned to stupid hacks like this */
1159 if (SCSI_PA(shpnt
) >= ISA_DMA_THRESHOLD
) {
1160 printk(KERN_ERR
"Invalid address for shpnt with 1542.\n");
1163 if (!aha1542_test_port(bases
[indx
], shpnt
))
1167 base_io
= bases
[indx
];
1169 /* Set the Bus on/off-times as not to ruin floppy performance */
1171 unchar oncmd
[] = {CMD_BUSON_TIME
, 7};
1172 unchar offcmd
[] = {CMD_BUSOFF_TIME
, 5};
1174 if (setup_called
[indx
]) {
1175 oncmd
[1] = setup_buson
[indx
];
1176 offcmd
[1] = setup_busoff
[indx
];
1178 aha1542_intr_reset(base_io
);
1179 aha1542_out(base_io
, oncmd
, 2);
1180 WAIT(INTRFLAGS(base_io
), INTRMASK
, HACC
, 0);
1181 aha1542_intr_reset(base_io
);
1182 aha1542_out(base_io
, offcmd
, 2);
1183 WAIT(INTRFLAGS(base_io
), INTRMASK
, HACC
, 0);
1184 if (setup_dmaspeed
[indx
] >= 0) {
1185 unchar dmacmd
[] = {CMD_DMASPEED
, 0};
1186 dmacmd
[1] = setup_dmaspeed
[indx
];
1187 aha1542_intr_reset(base_io
);
1188 aha1542_out(base_io
, dmacmd
, 2);
1189 WAIT(INTRFLAGS(base_io
), INTRMASK
, HACC
, 0);
1193 printk(KERN_ERR
"aha1542_detect: setting bus on/off-time failed\n");
1195 aha1542_intr_reset(base_io
);
1197 if (aha1542_query(base_io
, &trans
))
1200 if (aha1542_getconfig(base_io
, &irq_level
, &dma_chan
, &scsi_id
) == -1)
1203 printk(KERN_INFO
"Configuring Adaptec (SCSI-ID %d) at IO:%x, IRQ %d", scsi_id
, base_io
, irq_level
);
1204 if (dma_chan
!= 0xFF)
1205 printk(", DMA priority %d", dma_chan
);
1208 DEB(aha1542_stat());
1209 setup_mailboxes(base_io
, shpnt
);
1211 DEB(aha1542_stat());
1213 DEB(printk("aha1542_detect: enable interrupt channel %d\n", irq_level
));
1216 if (request_irq(irq_level
, do_aha1542_intr_handle
, 0, "aha1542", NULL
)) {
1217 printk(KERN_ERR
"Unable to allocate IRQ for adaptec controller.\n");
1218 restore_flags(flags
);
1221 if (dma_chan
!= 0xFF) {
1222 if (request_dma(dma_chan
, "aha1542")) {
1223 printk(KERN_ERR
"Unable to allocate DMA channel for Adaptec.\n");
1224 free_irq(irq_level
, NULL
);
1225 restore_flags(flags
);
1228 if (dma_chan
== 0 || dma_chan
>= 5) {
1229 set_dma_mode(dma_chan
, DMA_MODE_CASCADE
);
1230 enable_dma(dma_chan
);
1233 aha_host
[irq_level
- 9] = shpnt
;
1234 shpnt
->this_id
= scsi_id
;
1235 shpnt
->unique_id
= base_io
;
1236 shpnt
->io_port
= base_io
;
1237 shpnt
->n_io_port
= 4; /* Number of bytes of I/O space used */
1238 shpnt
->dma_channel
= dma_chan
;
1239 shpnt
->irq
= irq_level
;
1240 HOSTDATA(shpnt
)->bios_translation
= trans
;
1241 if (trans
== BIOS_TRANSLATION_25563
)
1242 printk(KERN_INFO
"aha1542.c: Using extended bios translation\n");
1243 HOSTDATA(shpnt
)->aha1542_last_mbi_used
= (2 * AHA1542_MAILBOXES
- 1);
1244 HOSTDATA(shpnt
)->aha1542_last_mbo_used
= (AHA1542_MAILBOXES
- 1);
1245 memset(HOSTDATA(shpnt
)->SCint
, 0, sizeof(HOSTDATA(shpnt
)->SCint
));
1246 restore_flags(flags
);
1248 DEB(printk(" *** READ CAPACITY ***\n"));
1252 static unchar cmd
[] = { READ_CAPACITY
, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
1255 for (i
= 0; i
< sizeof(buf
); ++i
)
1257 for (i
= 0; i
< 2; ++i
)
1258 if (!aha1542_command(i
, cmd
, buf
, sizeof(buf
))) {
1259 printk(KERN_DEBUG
"aha_detect: LU %d sector_size %d device_size %d\n",
1260 i
, xscsi2int(buf
+ 4), xscsi2int(buf
));
1264 DEB(printk(" *** NOW RUNNING MY OWN TEST *** \n"));
1266 for (i
= 0; i
< 4; ++i
) {
1267 unsigned char cmd
[10];
1272 xany2scsi(cmd
+ 2, i
);
1277 aha1542_command(0, cmd
, buffer
, 512);
1280 request_region(bases
[indx
], 4, "aha1542"); /* Register the IO ports that we use */
1284 scsi_unregister(shpnt
);
1292 static int aha1542_restart(struct Scsi_Host
*shost
)
1297 unchar ahacmd
= CMD_START_SCSI
;
1300 for (i
= 0; i
< AHA1542_MAILBOXES
; i
++)
1301 if (HOSTDATA(shost
)->SCint
[i
] &&
1302 !(HOSTDATA(shost
)->SCint
[i
]->device
->soft_reset
)) {
1304 HOSTDATA(shost
)->mb
[i
].status
= 1; /* Indicate ready to restart... */
1308 printk(KERN_DEBUG
"Potential to restart %d stalled commands...\n", count
);
1310 /* start scsi command */
1312 aha1542_out(shost
->io_port
, &ahacmd
, 1);
1317 int aha1542_abort(Scsi_Cmnd
* SCpnt
)
1321 * The abort command does not leave the device in a clean state where
1322 * it is available to be used again. Until this gets worked out, we
1323 * will leave it commented out.
1326 printk(KERN_ERR
"aha1542.c: Unable to abort command for target %d\n",
1332 * This is a device reset. This is handled by sending a special command
1335 int aha1542_dev_reset(Scsi_Cmnd
* SCpnt
)
1337 unsigned long flags
;
1339 unchar target
= SCpnt
->target
;
1340 unchar lun
= SCpnt
->lun
;
1343 unchar ahacmd
= CMD_START_SCSI
;
1345 ccb
= HOSTDATA(SCpnt
->host
)->ccb
;
1346 mb
= HOSTDATA(SCpnt
->host
)->mb
;
1350 mbo
= HOSTDATA(SCpnt
->host
)->aha1542_last_mbo_used
+ 1;
1351 if (mbo
>= AHA1542_MAILBOXES
)
1355 if (mb
[mbo
].status
== 0 && HOSTDATA(SCpnt
->host
)->SCint
[mbo
] == NULL
)
1358 if (mbo
>= AHA1542_MAILBOXES
)
1360 } while (mbo
!= HOSTDATA(SCpnt
->host
)->aha1542_last_mbo_used
);
1362 if (mb
[mbo
].status
|| HOSTDATA(SCpnt
->host
)->SCint
[mbo
])
1363 panic("Unable to find empty mailbox for aha1542.\n");
1365 HOSTDATA(SCpnt
->host
)->SCint
[mbo
] = SCpnt
; /* This will effectively
1366 prevent someone else from
1367 screwing with this cdb. */
1369 HOSTDATA(SCpnt
->host
)->aha1542_last_mbo_used
= mbo
;
1370 restore_flags(flags
);
1372 any2scsi(mb
[mbo
].ccbptr
, SCSI_PA(&ccb
[mbo
])); /* This gets trashed for some reason */
1374 memset(&ccb
[mbo
], 0, sizeof(struct ccb
));
1376 ccb
[mbo
].op
= 0x81; /* BUS DEVICE RESET */
1378 ccb
[mbo
].idlun
= (target
& 7) << 5 | (lun
& 7); /*SCSI Target Id */
1380 ccb
[mbo
].linkptr
[0] = ccb
[mbo
].linkptr
[1] = ccb
[mbo
].linkptr
[2] = 0;
1381 ccb
[mbo
].commlinkid
= 0;
1384 * Now tell the 1542 to flush all pending commands for this
1387 aha1542_out(SCpnt
->host
->io_port
, &ahacmd
, 1);
1389 printk(KERN_WARNING
"aha1542.c: Trying device reset for target %d\n", SCpnt
->target
);
1394 #ifdef ERIC_neverdef
1396 * With the 1542 we apparently never get an interrupt to
1397 * acknowledge a device reset being sent. Then again, Leonard
1398 * says we are doing this wrong in the first place...
1400 * Take a wait and see attitude. If we get spurious interrupts,
1401 * then the device reset is doing something sane and useful, and
1402 * we will wait for the interrupt to post completion.
1404 printk(KERN_WARNING
"Sent BUS DEVICE RESET to target %d\n", SCpnt
->target
);
1407 * Free the command block for all commands running on this
1410 for (i
= 0; i
< AHA1542_MAILBOXES
; i
++) {
1411 if (HOSTDATA(SCpnt
->host
)->SCint
[i
] &&
1412 HOSTDATA(SCpnt
->host
)->SCint
[i
]->target
== SCpnt
->target
) {
1414 SCtmp
= HOSTDATA(SCpnt
->host
)->SCint
[i
];
1415 if (SCtmp
->host_scribble
) {
1416 scsi_free(SCtmp
->host_scribble
, 512);
1418 HOSTDATA(SCpnt
->host
)->SCint
[i
] = NULL
;
1419 HOSTDATA(SCpnt
->host
)->mb
[i
].status
= 0;
1425 #endif /* ERIC_neverdef */
1428 int aha1542_bus_reset(Scsi_Cmnd
* SCpnt
)
1433 * This does a scsi reset for all devices on the bus.
1434 * In principle, we could also reset the 1542 - should
1435 * we do this? Try this first, and we can add that later
1436 * if it turns out to be useful.
1438 outb(SCRST
, CONTROL(SCpnt
->host
->io_port
));
1441 * Wait for the thing to settle down a bit. Unfortunately
1442 * this is going to basically lock up the machine while we
1443 * wait for this to complete. To be 100% correct, we need to
1444 * check for timeout, and if we are doing something like this
1445 * we are pretty desperate anyways.
1447 spin_unlock_irq(&io_request_lock
);
1449 spin_lock_irq(&io_request_lock
);
1451 WAIT(STATUS(SCpnt
->host
->io_port
),
1452 STATMASK
, INIT
| IDLE
, STST
| DIAGF
| INVDCMD
| DF
| CDF
);
1455 * Now try to pick up the pieces. For all pending commands,
1456 * free any internal data structures, and basically clear things
1457 * out. We do not try and restart any commands or anything -
1458 * the strategy handler takes care of that crap.
1460 printk(KERN_WARNING
"Sent BUS RESET to scsi host %d\n", SCpnt
->host
->host_no
);
1462 for (i
= 0; i
< AHA1542_MAILBOXES
; i
++) {
1463 if (HOSTDATA(SCpnt
->host
)->SCint
[i
] != NULL
) {
1465 SCtmp
= HOSTDATA(SCpnt
->host
)->SCint
[i
];
1468 if (SCtmp
->device
->soft_reset
) {
1470 * If this device implements the soft reset option,
1471 * then it is still holding onto the command, and
1472 * may yet complete it. In this case, we don't
1477 if (SCtmp
->host_scribble
) {
1478 scsi_free(SCtmp
->host_scribble
, 512);
1480 HOSTDATA(SCpnt
->host
)->SCint
[i
] = NULL
;
1481 HOSTDATA(SCpnt
->host
)->mb
[i
].status
= 0;
1491 int aha1542_host_reset(Scsi_Cmnd
* SCpnt
)
1496 * This does a scsi reset for all devices on the bus.
1497 * In principle, we could also reset the 1542 - should
1498 * we do this? Try this first, and we can add that later
1499 * if it turns out to be useful.
1501 outb(HRST
| SCRST
, CONTROL(SCpnt
->host
->io_port
));
1504 * Wait for the thing to settle down a bit. Unfortunately
1505 * this is going to basically lock up the machine while we
1506 * wait for this to complete. To be 100% correct, we need to
1507 * check for timeout, and if we are doing something like this
1508 * we are pretty desperate anyways.
1510 spin_unlock_irq(&io_request_lock
);
1512 spin_lock_irq(&io_request_lock
);
1514 WAIT(STATUS(SCpnt
->host
->io_port
),
1515 STATMASK
, INIT
| IDLE
, STST
| DIAGF
| INVDCMD
| DF
| CDF
);
1518 * We need to do this too before the 1542 can interact with
1521 setup_mailboxes(SCpnt
->host
->io_port
, SCpnt
->host
);
1524 * Now try to pick up the pieces. For all pending commands,
1525 * free any internal data structures, and basically clear things
1526 * out. We do not try and restart any commands or anything -
1527 * the strategy handler takes care of that crap.
1529 printk(KERN_WARNING
"Sent BUS RESET to scsi host %d\n", SCpnt
->host
->host_no
);
1531 for (i
= 0; i
< AHA1542_MAILBOXES
; i
++) {
1532 if (HOSTDATA(SCpnt
->host
)->SCint
[i
] != NULL
) {
1534 SCtmp
= HOSTDATA(SCpnt
->host
)->SCint
[i
];
1536 if (SCtmp
->device
->soft_reset
) {
1538 * If this device implements the soft reset option,
1539 * then it is still holding onto the command, and
1540 * may yet complete it. In this case, we don't
1545 if (SCtmp
->host_scribble
) {
1546 scsi_free(SCtmp
->host_scribble
, 512);
1548 HOSTDATA(SCpnt
->host
)->SCint
[i
] = NULL
;
1549 HOSTDATA(SCpnt
->host
)->mb
[i
].status
= 0;
1560 * These are the old error handling routines. They are only temporarily
1561 * here while we play with the new error handling code.
1563 int aha1542_old_abort(Scsi_Cmnd
* SCpnt
)
1566 unchar ahacmd
= CMD_START_SCSI
;
1567 unsigned long flags
;
1571 printk(KERN_DEBUG
"In aha1542_abort: %x %x\n",
1572 inb(STATUS(SCpnt
->host
->io_port
)),
1573 inb(INTRFLAGS(SCpnt
->host
->io_port
)));
1577 mb
= HOSTDATA(SCpnt
->host
)->mb
;
1578 mbi
= HOSTDATA(SCpnt
->host
)->aha1542_last_mbi_used
+ 1;
1579 if (mbi
>= 2 * AHA1542_MAILBOXES
)
1580 mbi
= AHA1542_MAILBOXES
;
1583 if (mb
[mbi
].status
!= 0)
1586 if (mbi
>= 2 * AHA1542_MAILBOXES
)
1587 mbi
= AHA1542_MAILBOXES
;
1588 } while (mbi
!= HOSTDATA(SCpnt
->host
)->aha1542_last_mbi_used
);
1589 restore_flags(flags
);
1591 if (mb
[mbi
].status
) {
1592 printk(KERN_ERR
"Lost interrupt discovered on irq %d - attempting to recover\n",
1594 aha1542_intr_handle(SCpnt
->host
->irq
, NULL
);
1597 /* OK, no lost interrupt. Try looking to see how many pending commands
1598 we think we have. */
1600 for (i
= 0; i
< AHA1542_MAILBOXES
; i
++)
1601 if (HOSTDATA(SCpnt
->host
)->SCint
[i
]) {
1602 if (HOSTDATA(SCpnt
->host
)->SCint
[i
] == SCpnt
) {
1603 printk(KERN_ERR
"Timed out command pending for %s\n",
1604 kdevname(SCpnt
->request
.rq_dev
));
1605 if (HOSTDATA(SCpnt
->host
)->mb
[i
].status
) {
1606 printk(KERN_ERR
"OGMB still full - restarting\n");
1607 aha1542_out(SCpnt
->host
->io_port
, &ahacmd
, 1);
1610 printk(KERN_ERR
"Other pending command %s\n",
1611 kdevname(SCpnt
->request
.rq_dev
));
1615 DEB(printk("aha1542_abort\n"));
1619 for (mbo
= 0; mbo
< AHA1542_MAILBOXES
; mbo
++)
1620 if (SCpnt
== HOSTDATA(SCpnt
->host
)->SCint
[mbo
]) {
1621 mb
[mbo
].status
= 2; /* Abort command */
1622 aha1542_out(SCpnt
->host
->io_port
, &ahacmd
, 1); /* start scsi command */
1623 restore_flags(flags
);
1627 return SCSI_ABORT_SNOOZE
;
1630 /* We do not implement a reset function here, but the upper level code
1631 assumes that it will get some kind of response for the command in
1632 SCpnt. We must oblige, or the command will hang the scsi system.
1633 For a first go, we assume that the 1542 notifies us with all of the
1634 pending commands (it does implement soft reset, after all). */
1636 int aha1542_old_reset(Scsi_Cmnd
* SCpnt
, unsigned int reset_flags
)
1638 unchar ahacmd
= CMD_START_SCSI
;
1642 * See if a bus reset was suggested.
1644 if (reset_flags
& SCSI_RESET_SUGGEST_BUS_RESET
) {
1646 * This does a scsi reset for all devices on the bus.
1647 * In principle, we could also reset the 1542 - should
1648 * we do this? Try this first, and we can add that later
1649 * if it turns out to be useful.
1651 outb(HRST
| SCRST
, CONTROL(SCpnt
->host
->io_port
));
1654 * Wait for the thing to settle down a bit. Unfortunately
1655 * this is going to basically lock up the machine while we
1656 * wait for this to complete. To be 100% correct, we need to
1657 * check for timeout, and if we are doing something like this
1658 * we are pretty desperate anyways.
1660 WAIT(STATUS(SCpnt
->host
->io_port
),
1661 STATMASK
, INIT
| IDLE
, STST
| DIAGF
| INVDCMD
| DF
| CDF
);
1664 * We need to do this too before the 1542 can interact with
1667 setup_mailboxes(SCpnt
->host
->io_port
, SCpnt
->host
);
1670 * Now try to pick up the pieces. Restart all commands
1671 * that are currently active on the bus, and reset all of
1672 * the datastructures. We have some time to kill while
1673 * things settle down, so print a nice message.
1675 printk(KERN_WARNING
"Sent BUS RESET to scsi host %d\n", SCpnt
->host
->host_no
);
1677 for (i
= 0; i
< AHA1542_MAILBOXES
; i
++)
1678 if (HOSTDATA(SCpnt
->host
)->SCint
[i
] != NULL
) {
1680 SCtmp
= HOSTDATA(SCpnt
->host
)->SCint
[i
];
1681 SCtmp
->result
= DID_RESET
<< 16;
1682 if (SCtmp
->host_scribble
)
1683 scsi_free(SCtmp
->host_scribble
, 512);
1684 printk(KERN_WARNING
"Sending DID_RESET for target %d\n", SCpnt
->target
);
1685 SCtmp
->scsi_done(SCpnt
);
1687 HOSTDATA(SCpnt
->host
)->SCint
[i
] = NULL
;
1688 HOSTDATA(SCpnt
->host
)->mb
[i
].status
= 0;
1691 * Now tell the mid-level code what we did here. Since
1692 * we have restarted all of the outstanding commands,
1693 * then report SUCCESS.
1695 return (SCSI_RESET_SUCCESS
| SCSI_RESET_BUS_RESET
);
1697 printk(KERN_CRIT
"aha1542.c: Unable to perform hard reset.\n");
1698 printk(KERN_CRIT
"Power cycle machine to reset\n");
1699 return (SCSI_RESET_ERROR
| SCSI_RESET_BUS_RESET
);
1703 /* This does a selective reset of just the one device */
1704 /* First locate the ccb for this command */
1705 for (i
= 0; i
< AHA1542_MAILBOXES
; i
++)
1706 if (HOSTDATA(SCpnt
->host
)->SCint
[i
] == SCpnt
) {
1707 HOSTDATA(SCpnt
->host
)->ccb
[i
].op
= 0x81; /* BUS DEVICE RESET */
1708 /* Now tell the 1542 to flush all pending commands for this target */
1709 aha1542_out(SCpnt
->host
->io_port
, &ahacmd
, 1);
1711 /* Here is the tricky part. What to do next. Do we get an interrupt
1712 for the commands that we aborted with the specified target, or
1713 do we generate this on our own? Try it without first and see
1715 printk(KERN_WARNING
"Sent BUS DEVICE RESET to target %d\n", SCpnt
->target
);
1717 /* If the first does not work, then try the second. I think the
1718 first option is more likely to be correct. Free the command
1719 block for all commands running on this target... */
1720 for (i
= 0; i
< AHA1542_MAILBOXES
; i
++)
1721 if (HOSTDATA(SCpnt
->host
)->SCint
[i
] &&
1722 HOSTDATA(SCpnt
->host
)->SCint
[i
]->target
== SCpnt
->target
) {
1724 SCtmp
= HOSTDATA(SCpnt
->host
)->SCint
[i
];
1725 SCtmp
->result
= DID_RESET
<< 16;
1726 if (SCtmp
->host_scribble
)
1727 scsi_free(SCtmp
->host_scribble
, 512);
1728 printk(KERN_WARNING
"Sending DID_RESET for target %d\n", SCpnt
->target
);
1729 SCtmp
->scsi_done(SCpnt
);
1731 HOSTDATA(SCpnt
->host
)->SCint
[i
] = NULL
;
1732 HOSTDATA(SCpnt
->host
)->mb
[i
].status
= 0;
1734 return SCSI_RESET_SUCCESS
;
1737 /* No active command at this time, so this means that each time we got
1738 some kind of response the last time through. Tell the mid-level code
1739 to request sense information in order to decide what to do next. */
1740 return SCSI_RESET_PUNT
;
1745 int aha1542_biosparam(Scsi_Disk
* disk
, kdev_t dev
, int *ip
)
1747 int translation_algorithm
;
1748 int size
= disk
->capacity
;
1750 translation_algorithm
= HOSTDATA(disk
->device
->host
)->bios_translation
;
1752 if ((size
>> 11) > 1024 && translation_algorithm
== BIOS_TRANSLATION_25563
) {
1753 /* Please verify that this is the same as what DOS returns */
1756 ip
[2] = size
/ 255 / 63;
1768 /* Eventually this will go into an include file, but this will be later */
1769 Scsi_Host_Template driver_template
= AHA1542
;
1771 #include "scsi_module.c"