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
25 * Added proper detection of the AHA-1640 (MCA version of AHA-1540)
28 #include <linux/module.h>
29 #include <linux/interrupt.h>
30 #include <linux/kernel.h>
31 #include <linux/types.h>
32 #include <linux/string.h>
33 #include <linux/ioport.h>
34 #include <linux/delay.h>
35 #include <linux/proc_fs.h>
36 #include <linux/init.h>
37 #include <linux/spinlock.h>
38 #include <linux/isapnp.h>
39 #include <linux/blkdev.h>
40 #include <linux/mca.h>
41 #include <linux/mca-legacy.h>
42 #include <linux/slab.h>
45 #include <asm/system.h>
49 #include <scsi/scsi_host.h>
52 #define SCSI_BUF_PA(address) isa_virt_to_bus(address)
53 #define SCSI_SG_PA(sgent) (isa_page_to_bus(sg_page((sgent))) + (sgent)->offset)
55 static void BAD_SG_DMA(Scsi_Cmnd
* SCpnt
,
56 struct scatterlist
*sgp
,
60 printk(KERN_CRIT
"sgpnt[%d:%d] page %p/0x%llx length %u\n",
61 badseg
, nseg
, sg_virt(sgp
),
62 (unsigned long long)SCSI_SG_PA(sgp
),
66 * Not safe to continue.
68 panic("Buffer at physical address > 16Mb used for aha1542");
71 #include<linux/stat.h>
80 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 $";
83 /* The adaptec can be configured for quite a number of addresses, but
84 I generally do not want the card poking around at random. We allow
85 two addresses - this allows people to use the Adaptec with a Midi
86 card, which also used 0x330 -- can be overridden with LILO! */
88 #define MAXBOARDS 4 /* Increase this and the sizes of the
89 arrays below, if you need more.. */
91 /* Boards 3,4 slots are reserved for ISAPnP/MCA scans */
93 static unsigned int bases
[MAXBOARDS
] __initdata
= {0x330, 0x334, 0, 0};
95 /* set by aha1542_setup according to the command line; they also may
96 be marked __initdata, but require zero initializers then */
98 static int setup_called
[MAXBOARDS
];
99 static int setup_buson
[MAXBOARDS
];
100 static int setup_busoff
[MAXBOARDS
];
101 static int setup_dmaspeed
[MAXBOARDS
] __initdata
= { -1, -1, -1, -1 };
104 * LILO/Module params: aha1542=<PORTBASE>[,<BUSON>,<BUSOFF>[,<DMASPEED>]]
106 * Where: <PORTBASE> is any of the valid AHA addresses:
107 * 0x130, 0x134, 0x230, 0x234, 0x330, 0x334
108 * <BUSON> is the time (in microsecs) that AHA spends on the AT-bus
109 * when transferring data. 1542A power-on default is 11us,
110 * valid values are in range: 2..15 (decimal)
111 * <BUSOFF> is the time that AHA spends OFF THE BUS after while
112 * it is transferring data (not to monopolize the bus).
113 * Power-on default is 4us, valid range: 1..64 microseconds.
114 * <DMASPEED> Default is jumper selected (1542A: on the J1),
115 * but experimenter can alter it with this.
116 * Valid values: 5, 6, 7, 8, 10 (MB/s)
117 * Factory default is 5 MB/s.
121 static int isapnp
= 0;
122 static int aha1542
[] = {0x330, 11, 4, -1};
123 module_param_array(aha1542
, int, NULL
, 0);
124 module_param(isapnp
, bool, 0);
126 static struct isapnp_device_id id_table
[] __initdata
= {
128 ISAPNP_ANY_ID
, ISAPNP_ANY_ID
,
129 ISAPNP_VENDOR('A', 'D', 'P'), ISAPNP_FUNCTION(0x1542),
135 MODULE_DEVICE_TABLE(isapnp
, id_table
);
138 static int isapnp
= 1;
141 #define BIOS_TRANSLATION_1632 0 /* Used by some old 1542A boards */
142 #define BIOS_TRANSLATION_6432 1 /* Default case these days */
143 #define BIOS_TRANSLATION_25563 2 /* Big disk case */
145 struct aha1542_hostdata
{
146 /* This will effectively start both of them at the first mailbox */
147 int bios_translation
; /* Mapping bios uses - for compatibility */
148 int aha1542_last_mbi_used
;
149 int aha1542_last_mbo_used
;
150 Scsi_Cmnd
*SCint
[AHA1542_MAILBOXES
];
151 struct mailbox mb
[2 * AHA1542_MAILBOXES
];
152 struct ccb ccb
[AHA1542_MAILBOXES
];
155 #define HOSTDATA(host) ((struct aha1542_hostdata *) &host->hostdata)
157 static DEFINE_SPINLOCK(aha1542_lock
);
161 #define WAITnexttimeout 3000000
163 static void setup_mailboxes(int base_io
, struct Scsi_Host
*shpnt
);
164 static int aha1542_restart(struct Scsi_Host
*shost
);
165 static void aha1542_intr_handle(struct Scsi_Host
*shost
);
167 #define aha1542_intr_reset(base) outb(IRST, CONTROL(base))
169 #define WAIT(port, mask, allof, noneof) \
170 { register int WAITbits; \
171 register int WAITtimeout = WAITnexttimeout; \
173 WAITbits = inb(port) & (mask); \
174 if ((WAITbits & (allof)) == (allof) && ((WAITbits & (noneof)) == 0)) \
176 if (--WAITtimeout == 0) goto fail; \
180 /* Similar to WAIT, except we use the udelay call to regulate the
181 amount of time we wait. */
182 #define WAITd(port, mask, allof, noneof, timeout) \
183 { register int WAITbits; \
184 register int WAITtimeout = timeout; \
186 WAITbits = inb(port) & (mask); \
187 if ((WAITbits & (allof)) == (allof) && ((WAITbits & (noneof)) == 0)) \
190 if (--WAITtimeout == 0) goto fail; \
194 static void aha1542_stat(void)
196 /* int s = inb(STATUS), i = inb(INTRFLAGS);
197 printk("status=%x intrflags=%x\n", s, i, WAITnexttimeout-WAITtimeout); */
200 /* This is a bit complicated, but we need to make sure that an interrupt
201 routine does not send something out while we are in the middle of this.
202 Fortunately, it is only at boot time that multi-byte messages
204 static int aha1542_out(unsigned int base
, unchar
* cmdp
, int len
)
206 unsigned long flags
= 0;
212 WAIT(STATUS(base
), CDF
, 0, CDF
);
213 spin_lock_irqsave(&aha1542_lock
, flags
);
214 if (inb(STATUS(base
)) & CDF
) {
215 spin_unlock_irqrestore(&aha1542_lock
, flags
);
218 outb(*cmdp
, DATA(base
));
219 spin_unlock_irqrestore(&aha1542_lock
, flags
);
223 spin_lock_irqsave(&aha1542_lock
, flags
);
226 WAIT(STATUS(base
), CDF
, 0, CDF
);
227 outb(*cmdp
++, DATA(base
));
229 spin_unlock_irqrestore(&aha1542_lock
, flags
);
234 spin_unlock_irqrestore(&aha1542_lock
, flags
);
235 printk(KERN_ERR
"aha1542_out failed(%d): ", len
+ 1);
240 /* Only used at boot time, so we do not need to worry about latency as much
243 static int __init
aha1542_in(unsigned int base
, unchar
* cmdp
, int len
)
247 spin_lock_irqsave(&aha1542_lock
, flags
);
249 WAIT(STATUS(base
), DF
, DF
, 0);
250 *cmdp
++ = inb(DATA(base
));
252 spin_unlock_irqrestore(&aha1542_lock
, flags
);
255 spin_unlock_irqrestore(&aha1542_lock
, flags
);
256 printk(KERN_ERR
"aha1542_in failed(%d): ", len
+ 1);
261 /* Similar to aha1542_in, except that we wait a very short period of time.
262 We use this if we know the board is alive and awake, but we are not sure
263 if the board will respond to the command we are about to send or not */
264 static int __init
aha1542_in1(unsigned int base
, unchar
* cmdp
, int len
)
268 spin_lock_irqsave(&aha1542_lock
, flags
);
270 WAITd(STATUS(base
), DF
, DF
, 0, 100);
271 *cmdp
++ = inb(DATA(base
));
273 spin_unlock_irqrestore(&aha1542_lock
, flags
);
276 spin_unlock_irqrestore(&aha1542_lock
, flags
);
280 static int makecode(unsigned hosterr
, unsigned scsierr
)
284 case 0xa: /* Linked command complete without error and linked normally */
285 case 0xb: /* Linked command complete without error, interrupt generated */
289 case 0x11: /* Selection time out-The initiator selection or target
290 reselection was not complete within the SCSI Time out period */
291 hosterr
= DID_TIME_OUT
;
294 case 0x12: /* Data overrun/underrun-The target attempted to transfer more data
295 than was allocated by the Data Length field or the sum of the
296 Scatter / Gather Data Length fields. */
298 case 0x13: /* Unexpected bus free-The target dropped the SCSI BSY at an unexpected time. */
300 case 0x15: /* MBO command was not 00, 01 or 02-The first byte of the CB was
301 invalid. This usually indicates a software failure. */
303 case 0x16: /* Invalid CCB Operation Code-The first byte of the CCB was invalid.
304 This usually indicates a software failure. */
306 case 0x17: /* Linked CCB does not have the same LUN-A subsequent CCB of a set
307 of linked CCB's does not specify the same logical unit number as
309 case 0x18: /* Invalid Target Direction received from Host-The direction of a
310 Target Mode CCB was invalid. */
312 case 0x19: /* Duplicate CCB Received in Target Mode-More than once CCB was
313 received to service data transfer between the same target LUN
314 and initiator SCSI ID in the same direction. */
316 case 0x1a: /* Invalid CCB or Segment List Parameter-A segment list with a zero
317 length segment or invalid segment list boundaries was received.
318 A CCB parameter was invalid. */
319 DEB(printk("Aha1542: %x %x\n", hosterr
, scsierr
));
320 hosterr
= DID_ERROR
; /* Couldn't find any better */
323 case 0x14: /* Target bus phase sequence failure-An invalid bus phase or bus
324 phase sequence was requested by the target. The host adapter
325 will generate a SCSI Reset Condition, notifying the host with
330 printk(KERN_ERR
"aha1542: makecode: unknown hoststatus %x\n", hosterr
);
333 return scsierr
| (hosterr
<< 16);
336 static int __init
aha1542_test_port(int bse
, struct Scsi_Host
*shpnt
)
338 unchar inquiry_cmd
[] = {CMD_INQUIRY
};
339 unchar inquiry_result
[4];
342 volatile int debug
= 0;
344 /* Quick and dirty test for presence of the card. */
345 if (inb(STATUS(bse
)) == 0xff)
348 /* Reset the adapter. I ought to make a hard reset, but it's not really necessary */
350 /* DEB(printk("aha1542_test_port called \n")); */
352 /* In case some other card was probing here, reset interrupts */
353 aha1542_intr_reset(bse
); /* reset interrupts, so they don't block */
355 outb(SRST
| IRST
/*|SCRST */ , CONTROL(bse
));
357 mdelay(20); /* Wait a little bit for things to settle down. */
360 /* Expect INIT and IDLE, any of the others are bad */
361 WAIT(STATUS(bse
), STATMASK
, INIT
| IDLE
, STST
| DIAGF
| INVDCMD
| DF
| CDF
);
364 /* Shouldn't have generated any interrupts during reset */
365 if (inb(INTRFLAGS(bse
)) & INTRMASK
)
369 /* Perform a host adapter inquiry instead so we do not need to set
370 up the mailboxes ahead of time */
372 aha1542_out(bse
, inquiry_cmd
, 1);
376 cmdp
= &inquiry_result
[0];
379 WAIT(STATUS(bse
), DF
, DF
, 0);
380 *cmdp
++ = inb(DATA(bse
));
384 /* Reading port should reset DF */
385 if (inb(STATUS(bse
)) & DF
)
389 /* When HACC, command is completed, and we're though testing */
390 WAIT(INTRFLAGS(bse
), HACC
, HACC
, 0);
391 /* now initialize adapter */
394 /* Clear interrupts */
395 outb(IRST
, CONTROL(bse
));
399 return debug
; /* 1 = ok */
401 return 0; /* 0 = not ok */
404 /* A quick wrapper for do_aha1542_intr_handle to grab the spin lock */
405 static irqreturn_t
do_aha1542_intr_handle(int dummy
, void *dev_id
)
408 struct Scsi_Host
*shost
= dev_id
;
410 spin_lock_irqsave(shost
->host_lock
, flags
);
411 aha1542_intr_handle(shost
);
412 spin_unlock_irqrestore(shost
->host_lock
, flags
);
416 /* A "high" level interrupt handler */
417 static void aha1542_intr_handle(struct Scsi_Host
*shost
)
419 void (*my_done
) (Scsi_Cmnd
*) = NULL
;
420 int errstatus
, mbi
, mbo
, mbistatus
;
429 mb
= HOSTDATA(shost
)->mb
;
430 ccb
= HOSTDATA(shost
)->ccb
;
434 flag
= inb(INTRFLAGS(shost
->io_port
));
435 printk(KERN_DEBUG
"aha1542_intr_handle: ");
436 if (!(flag
& ANYINTR
))
437 printk("no interrupt?");
446 printk("status %02x\n", inb(STATUS(shost
->io_port
)));
453 flag
= inb(INTRFLAGS(shost
->io_port
));
455 /* Check for unusual interrupts. If any of these happen, we should
456 probably do something special, but for now just printing a message
457 is sufficient. A SCSI reset detected is something that we really
458 need to deal with in some way. */
469 aha1542_intr_reset(shost
->io_port
);
471 spin_lock_irqsave(&aha1542_lock
, flags
);
472 mbi
= HOSTDATA(shost
)->aha1542_last_mbi_used
+ 1;
473 if (mbi
>= 2 * AHA1542_MAILBOXES
)
474 mbi
= AHA1542_MAILBOXES
;
477 if (mb
[mbi
].status
!= 0)
480 if (mbi
>= 2 * AHA1542_MAILBOXES
)
481 mbi
= AHA1542_MAILBOXES
;
482 } while (mbi
!= HOSTDATA(shost
)->aha1542_last_mbi_used
);
484 if (mb
[mbi
].status
== 0) {
485 spin_unlock_irqrestore(&aha1542_lock
, flags
);
486 /* Hmm, no mail. Must have read it the last time around */
487 if (!number_serviced
&& !needs_restart
)
488 printk(KERN_WARNING
"aha1542.c: interrupt received, but no mail.\n");
489 /* We detected a reset. Restart all pending commands for
490 devices that use the hard reset option */
492 aha1542_restart(shost
);
496 mbo
= (scsi2int(mb
[mbi
].ccbptr
) - (SCSI_BUF_PA(&ccb
[0]))) / sizeof(struct ccb
);
497 mbistatus
= mb
[mbi
].status
;
499 HOSTDATA(shost
)->aha1542_last_mbi_used
= mbi
;
500 spin_unlock_irqrestore(&aha1542_lock
, flags
);
504 if (ccb
[mbo
].tarstat
| ccb
[mbo
].hastat
)
505 printk(KERN_DEBUG
"aha1542_command: returning %x (status %d)\n",
506 ccb
[mbo
].tarstat
+ ((int) ccb
[mbo
].hastat
<< 16), mb
[mbi
].status
);
511 continue; /* Aborted command not found */
514 printk(KERN_DEBUG
"...done %d %d\n", mbo
, mbi
);
517 SCtmp
= HOSTDATA(shost
)->SCint
[mbo
];
519 if (!SCtmp
|| !SCtmp
->scsi_done
) {
520 printk(KERN_WARNING
"aha1542_intr_handle: Unexpected interrupt\n");
521 printk(KERN_WARNING
"tarstat=%x, hastat=%x idlun=%x ccb#=%d \n", ccb
[mbo
].tarstat
,
522 ccb
[mbo
].hastat
, ccb
[mbo
].idlun
, mbo
);
525 my_done
= SCtmp
->scsi_done
;
526 kfree(SCtmp
->host_scribble
);
527 SCtmp
->host_scribble
= NULL
;
528 /* Fetch the sense data, and tuck it away, in the required slot. The
529 Adaptec automatically fetches it, and there is no guarantee that
530 we will still have it in the cdb when we come back */
531 if (ccb
[mbo
].tarstat
== 2)
532 memcpy(SCtmp
->sense_buffer
, &ccb
[mbo
].cdb
[ccb
[mbo
].cdblen
],
533 SCSI_SENSE_BUFFERSIZE
);
536 /* is there mail :-) */
538 /* more error checking left out here */
540 /* This is surely wrong, but I don't know what's right */
541 errstatus
= makecode(ccb
[mbo
].hastat
, ccb
[mbo
].tarstat
);
547 printk(KERN_DEBUG
"(aha1542 error:%x %x %x) ", errstatus
,
548 ccb
[mbo
].hastat
, ccb
[mbo
].tarstat
);
551 if (ccb
[mbo
].tarstat
== 2) {
555 DEB(printk("aha1542_intr_handle: sense:"));
557 for (i
= 0; i
< 12; i
++)
558 printk("%02x ", ccb
[mbo
].cdb
[ccb
[mbo
].cdblen
+ i
]);
562 DEB(printk("aha1542_intr_handle: buf:"));
563 for (i = 0; i < bufflen; i++)
564 printk("%02x ", ((unchar *)buff)[i]);
568 DEB(if (errstatus
) printk("aha1542_intr_handle: returning %6x\n", errstatus
));
569 SCtmp
->result
= errstatus
;
570 HOSTDATA(shost
)->SCint
[mbo
] = NULL
; /* This effectively frees up the mailbox slot, as
571 far as queuecommand is concerned */
577 static int aha1542_queuecommand(Scsi_Cmnd
* SCpnt
, void (*done
) (Scsi_Cmnd
*))
579 unchar ahacmd
= CMD_START_SCSI
;
581 unchar
*cmd
= (unchar
*) SCpnt
->cmnd
;
582 unchar target
= SCpnt
->device
->id
;
583 unchar lun
= SCpnt
->device
->lun
;
585 int bufflen
= scsi_bufflen(SCpnt
);
592 mb
= HOSTDATA(SCpnt
->device
->host
)->mb
;
593 ccb
= HOSTDATA(SCpnt
->device
->host
)->ccb
;
595 DEB(if (target
> 1) {
596 SCpnt
->result
= DID_TIME_OUT
<< 16;
597 done(SCpnt
); return 0;
601 if (*cmd
== REQUEST_SENSE
) {
602 /* Don't do the command - we have the sense data already */
604 /* scsi_request_sense() provides a buffer of size 256,
605 so there is no reason to expect equality */
606 if (bufflen
!= SCSI_SENSE_BUFFERSIZE
)
607 printk(KERN_CRIT
"aha1542: Wrong buffer length supplied "
608 "for request sense (%d)\n", bufflen
);
615 if (*cmd
== READ_10
|| *cmd
== WRITE_10
)
616 i
= xscsi2int(cmd
+ 2);
617 else if (*cmd
== READ_6
|| *cmd
== WRITE_6
)
618 i
= scsi2int(cmd
+ 2);
622 printk(KERN_DEBUG
"aha1542_queuecommand: dev %d cmd %02x pos %d len %d ", target
, *cmd
, i
, bufflen
);
624 printk(KERN_DEBUG
"aha1542_command: dev %d cmd %02x pos %d len %d ", target
, *cmd
, i
, bufflen
);
626 printk(KERN_DEBUG
"aha1542_queuecommand: dumping scsi cmd:");
627 for (i
= 0; i
< SCpnt
->cmd_len
; i
++)
628 printk("%02x ", cmd
[i
]);
630 if (*cmd
== WRITE_10
|| *cmd
== WRITE_6
)
631 return 0; /* we are still testing, so *don't* write */
633 /* Use the outgoing mailboxes in a round-robin fashion, because this
634 is how the host adapter will scan for them */
636 spin_lock_irqsave(&aha1542_lock
, flags
);
637 mbo
= HOSTDATA(SCpnt
->device
->host
)->aha1542_last_mbo_used
+ 1;
638 if (mbo
>= AHA1542_MAILBOXES
)
642 if (mb
[mbo
].status
== 0 && HOSTDATA(SCpnt
->device
->host
)->SCint
[mbo
] == NULL
)
645 if (mbo
>= AHA1542_MAILBOXES
)
647 } while (mbo
!= HOSTDATA(SCpnt
->device
->host
)->aha1542_last_mbo_used
);
649 if (mb
[mbo
].status
|| HOSTDATA(SCpnt
->device
->host
)->SCint
[mbo
])
650 panic("Unable to find empty mailbox for aha1542.\n");
652 HOSTDATA(SCpnt
->device
->host
)->SCint
[mbo
] = SCpnt
; /* This will effectively prevent someone else from
653 screwing with this cdb. */
655 HOSTDATA(SCpnt
->device
->host
)->aha1542_last_mbo_used
= mbo
;
656 spin_unlock_irqrestore(&aha1542_lock
, flags
);
659 printk(KERN_DEBUG
"Sending command (%d %x)...", mbo
, done
);
662 any2scsi(mb
[mbo
].ccbptr
, SCSI_BUF_PA(&ccb
[mbo
])); /* This gets trashed for some reason */
664 memset(&ccb
[mbo
], 0, sizeof(struct ccb
));
666 ccb
[mbo
].cdblen
= SCpnt
->cmd_len
;
669 if (*cmd
== READ_10
|| *cmd
== READ_6
)
671 else if (*cmd
== WRITE_10
|| *cmd
== WRITE_6
)
674 memcpy(ccb
[mbo
].cdb
, cmd
, ccb
[mbo
].cdblen
);
677 struct scatterlist
*sg
;
682 int i
, sg_count
= scsi_sg_count(SCpnt
);
683 ccb
[mbo
].op
= 2; /* SCSI Initiator Command w/scatter-gather */
684 SCpnt
->host_scribble
= kmalloc(sizeof(*cptr
)*sg_count
,
685 GFP_KERNEL
| GFP_DMA
);
686 cptr
= (struct chain
*) SCpnt
->host_scribble
;
688 /* free the claimed mailbox slot */
689 HOSTDATA(SCpnt
->device
->host
)->SCint
[mbo
] = NULL
;
690 return SCSI_MLQUEUE_HOST_BUSY
;
692 scsi_for_each_sg(SCpnt
, sg
, sg_count
, i
) {
693 any2scsi(cptr
[i
].dataptr
, SCSI_SG_PA(sg
));
694 if (SCSI_SG_PA(sg
) + sg
->length
- 1 > ISA_DMA_THRESHOLD
)
695 BAD_SG_DMA(SCpnt
, scsi_sglist(SCpnt
), sg_count
, i
);
696 any2scsi(cptr
[i
].datalen
, sg
->length
);
698 any2scsi(ccb
[mbo
].datalen
, sg_count
* sizeof(struct chain
));
699 any2scsi(ccb
[mbo
].dataptr
, SCSI_BUF_PA(cptr
));
701 printk("cptr %x: ", cptr
);
702 ptr
= (unsigned char *) cptr
;
703 for (i
= 0; i
< 18; i
++)
704 printk("%02x ", ptr
[i
]);
707 ccb
[mbo
].op
= 0; /* SCSI Initiator Command */
708 SCpnt
->host_scribble
= NULL
;
709 any2scsi(ccb
[mbo
].datalen
, 0);
710 any2scsi(ccb
[mbo
].dataptr
, 0);
712 ccb
[mbo
].idlun
= (target
& 7) << 5 | direction
| (lun
& 7); /*SCSI Target Id */
713 ccb
[mbo
].rsalen
= 16;
714 ccb
[mbo
].linkptr
[0] = ccb
[mbo
].linkptr
[1] = ccb
[mbo
].linkptr
[2] = 0;
715 ccb
[mbo
].commlinkid
= 0;
720 printk(KERN_DEBUG
"aha1542_command: sending.. ");
721 for (i
= 0; i
< sizeof(ccb
[mbo
]) - 10; i
++)
722 printk("%02x ", ((unchar
*) & ccb
[mbo
])[i
]);
727 DEB(printk("aha1542_queuecommand: now waiting for interrupt ");
729 SCpnt
->scsi_done
= done
;
731 aha1542_out(SCpnt
->device
->host
->io_port
, &ahacmd
, 1); /* start scsi command */
734 printk("aha1542_queuecommand: done can't be NULL\n");
739 /* Initialize mailboxes */
740 static void setup_mailboxes(int bse
, struct Scsi_Host
*shpnt
)
746 unchar cmd
[5] = { CMD_MBINIT
, AHA1542_MAILBOXES
, 0, 0, 0};
748 mb
= HOSTDATA(shpnt
)->mb
;
749 ccb
= HOSTDATA(shpnt
)->ccb
;
751 for (i
= 0; i
< AHA1542_MAILBOXES
; i
++) {
752 mb
[i
].status
= mb
[AHA1542_MAILBOXES
+ i
].status
= 0;
753 any2scsi(mb
[i
].ccbptr
, SCSI_BUF_PA(&ccb
[i
]));
755 aha1542_intr_reset(bse
); /* reset interrupts, so they don't block */
756 any2scsi((cmd
+ 2), SCSI_BUF_PA(mb
));
757 aha1542_out(bse
, cmd
, 5);
758 WAIT(INTRFLAGS(bse
), INTRMASK
, HACC
, 0);
761 printk(KERN_ERR
"aha1542_detect: failed setting up mailboxes\n");
763 aha1542_intr_reset(bse
);
766 static int __init
aha1542_getconfig(int base_io
, unsigned char *irq_level
, unsigned char *dma_chan
, unsigned char *scsi_id
)
768 unchar inquiry_cmd
[] = {CMD_RETCONF
};
769 unchar inquiry_result
[3];
771 i
= inb(STATUS(base_io
));
773 i
= inb(DATA(base_io
));
775 aha1542_out(base_io
, inquiry_cmd
, 1);
776 aha1542_in(base_io
, inquiry_result
, 3);
777 WAIT(INTRFLAGS(base_io
), INTRMASK
, HACC
, 0);
780 printk(KERN_ERR
"aha1542_detect: query board settings\n");
782 aha1542_intr_reset(base_io
);
783 switch (inquiry_result
[0]) {
797 /* This means that the adapter, although Adaptec 1542 compatible, doesn't use a DMA channel.
798 Currently only aware of the BusLogic BT-445S VL-Bus adapter which needs this. */
802 printk(KERN_ERR
"Unable to determine Adaptec DMA priority. Disabling board\n");
805 switch (inquiry_result
[1]) {
825 printk(KERN_ERR
"Unable to determine Adaptec IRQ level. Disabling board\n");
828 *scsi_id
= inquiry_result
[2] & 7;
832 /* This function should only be called for 1542C boards - we can detect
833 the special firmware settings and unlock the board */
835 static int __init
aha1542_mbenable(int base
)
837 static unchar mbenable_cmd
[3];
838 static unchar mbenable_result
[2];
841 retval
= BIOS_TRANSLATION_6432
;
843 mbenable_cmd
[0] = CMD_EXTBIOS
;
844 aha1542_out(base
, mbenable_cmd
, 1);
845 if (aha1542_in1(base
, mbenable_result
, 2))
847 WAITd(INTRFLAGS(base
), INTRMASK
, HACC
, 0, 100);
848 aha1542_intr_reset(base
);
850 if ((mbenable_result
[0] & 0x08) || mbenable_result
[1]) {
851 mbenable_cmd
[0] = CMD_MBENABLE
;
853 mbenable_cmd
[2] = mbenable_result
[1];
855 if ((mbenable_result
[0] & 0x08) && (mbenable_result
[1] & 0x03))
856 retval
= BIOS_TRANSLATION_25563
;
858 aha1542_out(base
, mbenable_cmd
, 3);
859 WAIT(INTRFLAGS(base
), INTRMASK
, HACC
, 0);
863 printk(KERN_ERR
"aha1542_mbenable: Mailbox init failed\n");
865 aha1542_intr_reset(base
);
869 /* Query the board to find out if it is a 1542 or a 1740, or whatever. */
870 static int __init
aha1542_query(int base_io
, int *transl
)
872 unchar inquiry_cmd
[] = {CMD_INQUIRY
};
873 unchar inquiry_result
[4];
875 i
= inb(STATUS(base_io
));
877 i
= inb(DATA(base_io
));
879 aha1542_out(base_io
, inquiry_cmd
, 1);
880 aha1542_in(base_io
, inquiry_result
, 4);
881 WAIT(INTRFLAGS(base_io
), INTRMASK
, HACC
, 0);
884 printk(KERN_ERR
"aha1542_detect: query card type\n");
886 aha1542_intr_reset(base_io
);
888 *transl
= BIOS_TRANSLATION_6432
; /* Default case */
890 /* For an AHA1740 series board, we ignore the board since there is a
891 hardware bug which can lead to wrong blocks being returned if the board
892 is operating in the 1542 emulation mode. Since there is an extended mode
893 driver, we simply ignore the board and let the 1740 driver pick it up.
896 if (inquiry_result
[0] == 0x43) {
897 printk(KERN_INFO
"aha1542.c: Emulation mode not supported for AHA 174N hardware.\n");
901 /* Always call this - boards that do not support extended bios translation
902 will ignore the command, and we will set the proper default */
904 *transl
= aha1542_mbenable(base_io
);
910 static char *setup_str
[MAXBOARDS
] __initdata
;
911 static int setup_idx
= 0;
913 static void __init
aha1542_setup(char *str
, int *ints
)
915 const char *ahausage
= "aha1542: usage: aha1542=<PORTBASE>[,<BUSON>,<BUSOFF>[,<DMASPEED>]]\n";
918 if (setup_idx
>= MAXBOARDS
) {
919 printk(KERN_ERR
"aha1542: aha1542_setup called too many times! Bad LILO params ?\n");
920 printk(KERN_ERR
" Entryline 1: %s\n", setup_str
[0]);
921 printk(KERN_ERR
" Entryline 2: %s\n", setup_str
[1]);
922 printk(KERN_ERR
" This line: %s\n", str
);
925 if (ints
[0] < 1 || ints
[0] > 4) {
926 printk(KERN_ERR
"aha1542: %s\n", str
);
928 printk(KERN_ERR
"aha1542: Wrong parameters may cause system malfunction.. We try anyway..\n");
930 setup_called
[setup_idx
] = ints
[0];
931 setup_str
[setup_idx
] = str
;
933 setup_portbase
= ints
[0] >= 1 ? ints
[1] : 0; /* Preserve the default value.. */
934 setup_buson
[setup_idx
] = ints
[0] >= 2 ? ints
[2] : 7;
935 setup_busoff
[setup_idx
] = ints
[0] >= 3 ? ints
[3] : 5;
956 printk(KERN_ERR
"aha1542: %s\n", str
);
958 printk(KERN_ERR
"aha1542: Valid values for DMASPEED are 5-8, 10 MB/s. Using jumper defaults.\n");
961 setup_dmaspeed
[setup_idx
] = atbt
;
963 if (setup_portbase
!= 0)
964 bases
[setup_idx
] = setup_portbase
;
969 static int __init
do_setup(char *str
)
975 get_options(str
, ARRAY_SIZE(ints
), ints
);
976 aha1542_setup(str
,ints
);
978 return count
<setup_idx
;
981 __setup("aha1542=",do_setup
);
984 /* return non-zero on detection */
985 static int __init
aha1542_detect(struct scsi_host_template
* tpnt
)
987 unsigned char dma_chan
;
988 unsigned char irq_level
;
989 unsigned char scsi_id
;
991 unsigned int base_io
;
993 struct Scsi_Host
*shpnt
= NULL
;
997 DEB(printk("aha1542_detect: \n"));
999 tpnt
->proc_name
= "aha1542";
1002 bases
[0] = aha1542
[0];
1003 setup_buson
[0] = aha1542
[1];
1004 setup_busoff
[0] = aha1542
[2];
1007 switch (aha1542
[3]) {
1024 setup_dmaspeed
[0] = atbt
;
1029 * Find MicroChannel cards (AHA1640)
1031 #ifdef CONFIG_MCA_LEGACY
1036 for (indx
= 0; (slot
!= MCA_NOTFOUND
) && (indx
< ARRAY_SIZE(bases
)); indx
++) {
1041 /* Detect only AHA-1640 cards -- MCA ID 0F1F */
1042 slot
= mca_find_unused_adapter(0x0f1f, slot
);
1043 if (slot
== MCA_NOTFOUND
)
1047 pos
= mca_read_stored_pos(slot
, 3);
1049 /* Decode address */
1053 bases
[indx
] = 0x334;
1055 bases
[indx
] = 0x234;
1058 bases
[indx
] = 0x134;
1063 bases
[indx
] = 0x330;
1065 bases
[indx
] = 0x230;
1068 bases
[indx
] = 0x130;
1072 /* No need to decode IRQ and Arb level -- those are
1073 * read off the card later.
1075 printk(KERN_INFO
"Found an AHA-1640 in MCA slot %d, I/O 0x%04x\n", slot
, bases
[indx
]);
1077 mca_set_adapter_name(slot
, "Adapter AHA-1640");
1078 mca_set_adapter_procfn(slot
, NULL
, NULL
);
1079 mca_mark_as_used(slot
);
1089 * Hunt for ISA Plug'n'Pray Adaptecs (AHA1535)
1094 struct pnp_dev
*pdev
= NULL
;
1095 for(indx
= 0; indx
< ARRAY_SIZE(bases
); indx
++) {
1098 pdev
= pnp_find_dev(NULL
, ISAPNP_VENDOR('A', 'D', 'P'),
1099 ISAPNP_FUNCTION(0x1542), pdev
);
1103 * Activate the PnP card
1106 if(pnp_device_attach(pdev
)<0)
1109 if(pnp_activate_dev(pdev
)<0) {
1110 pnp_device_detach(pdev
);
1114 if(!pnp_port_valid(pdev
, 0)) {
1115 pnp_device_detach(pdev
);
1119 bases
[indx
] = pnp_port_start(pdev
, 0);
1121 /* The card can be queried for its DMA, we have
1122 the DMA set up that is enough */
1124 printk(KERN_INFO
"ISAPnP found an AHA1535 at I/O 0x%03X\n", bases
[indx
]);
1127 for (indx
= 0; indx
< ARRAY_SIZE(bases
); indx
++)
1128 if (bases
[indx
] != 0 && request_region(bases
[indx
], 4, "aha1542")) {
1129 shpnt
= scsi_register(tpnt
,
1130 sizeof(struct aha1542_hostdata
));
1133 release_region(bases
[indx
], 4);
1136 /* For now we do this - until kmalloc is more intelligent
1137 we are resigned to stupid hacks like this */
1138 if (SCSI_BUF_PA(shpnt
) >= ISA_DMA_THRESHOLD
) {
1139 printk(KERN_ERR
"Invalid address for shpnt with 1542.\n");
1142 if (!aha1542_test_port(bases
[indx
], shpnt
))
1146 base_io
= bases
[indx
];
1148 /* Set the Bus on/off-times as not to ruin floppy performance */
1150 unchar oncmd
[] = {CMD_BUSON_TIME
, 7};
1151 unchar offcmd
[] = {CMD_BUSOFF_TIME
, 5};
1153 if (setup_called
[indx
]) {
1154 oncmd
[1] = setup_buson
[indx
];
1155 offcmd
[1] = setup_busoff
[indx
];
1157 aha1542_intr_reset(base_io
);
1158 aha1542_out(base_io
, oncmd
, 2);
1159 WAIT(INTRFLAGS(base_io
), INTRMASK
, HACC
, 0);
1160 aha1542_intr_reset(base_io
);
1161 aha1542_out(base_io
, offcmd
, 2);
1162 WAIT(INTRFLAGS(base_io
), INTRMASK
, HACC
, 0);
1163 if (setup_dmaspeed
[indx
] >= 0) {
1164 unchar dmacmd
[] = {CMD_DMASPEED
, 0};
1165 dmacmd
[1] = setup_dmaspeed
[indx
];
1166 aha1542_intr_reset(base_io
);
1167 aha1542_out(base_io
, dmacmd
, 2);
1168 WAIT(INTRFLAGS(base_io
), INTRMASK
, HACC
, 0);
1172 printk(KERN_ERR
"aha1542_detect: setting bus on/off-time failed\n");
1174 aha1542_intr_reset(base_io
);
1176 if (aha1542_query(base_io
, &trans
))
1179 if (aha1542_getconfig(base_io
, &irq_level
, &dma_chan
, &scsi_id
) == -1)
1182 printk(KERN_INFO
"Configuring Adaptec (SCSI-ID %d) at IO:%x, IRQ %d", scsi_id
, base_io
, irq_level
);
1183 if (dma_chan
!= 0xFF)
1184 printk(", DMA priority %d", dma_chan
);
1187 DEB(aha1542_stat());
1188 setup_mailboxes(base_io
, shpnt
);
1190 DEB(aha1542_stat());
1192 DEB(printk("aha1542_detect: enable interrupt channel %d\n", irq_level
));
1193 spin_lock_irqsave(&aha1542_lock
, flags
);
1194 if (request_irq(irq_level
, do_aha1542_intr_handle
, 0,
1195 "aha1542", shpnt
)) {
1196 printk(KERN_ERR
"Unable to allocate IRQ for adaptec controller.\n");
1197 spin_unlock_irqrestore(&aha1542_lock
, flags
);
1200 if (dma_chan
!= 0xFF) {
1201 if (request_dma(dma_chan
, "aha1542")) {
1202 printk(KERN_ERR
"Unable to allocate DMA channel for Adaptec.\n");
1203 free_irq(irq_level
, shpnt
);
1204 spin_unlock_irqrestore(&aha1542_lock
, flags
);
1207 if (dma_chan
== 0 || dma_chan
>= 5) {
1208 set_dma_mode(dma_chan
, DMA_MODE_CASCADE
);
1209 enable_dma(dma_chan
);
1213 shpnt
->this_id
= scsi_id
;
1214 shpnt
->unique_id
= base_io
;
1215 shpnt
->io_port
= base_io
;
1216 shpnt
->n_io_port
= 4; /* Number of bytes of I/O space used */
1217 shpnt
->dma_channel
= dma_chan
;
1218 shpnt
->irq
= irq_level
;
1219 HOSTDATA(shpnt
)->bios_translation
= trans
;
1220 if (trans
== BIOS_TRANSLATION_25563
)
1221 printk(KERN_INFO
"aha1542.c: Using extended bios translation\n");
1222 HOSTDATA(shpnt
)->aha1542_last_mbi_used
= (2 * AHA1542_MAILBOXES
- 1);
1223 HOSTDATA(shpnt
)->aha1542_last_mbo_used
= (AHA1542_MAILBOXES
- 1);
1224 memset(HOSTDATA(shpnt
)->SCint
, 0, sizeof(HOSTDATA(shpnt
)->SCint
));
1225 spin_unlock_irqrestore(&aha1542_lock
, flags
);
1227 DEB(printk(" *** READ CAPACITY ***\n"));
1231 static unchar cmd
[] = { READ_CAPACITY
, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
1234 for (i
= 0; i
< sizeof(buf
); ++i
)
1236 for (i
= 0; i
< 2; ++i
)
1237 if (!aha1542_command(i
, cmd
, buf
, sizeof(buf
))) {
1238 printk(KERN_DEBUG
"aha_detect: LU %d sector_size %d device_size %d\n",
1239 i
, xscsi2int(buf
+ 4), xscsi2int(buf
));
1243 DEB(printk(" *** NOW RUNNING MY OWN TEST *** \n"));
1245 for (i
= 0; i
< 4; ++i
) {
1246 unsigned char cmd
[10];
1251 xany2scsi(cmd
+ 2, i
);
1256 aha1542_command(0, cmd
, buffer
, 512);
1262 release_region(bases
[indx
], 4);
1263 scsi_unregister(shpnt
);
1271 static int aha1542_release(struct Scsi_Host
*shost
)
1274 free_irq(shost
->irq
, shost
);
1275 if (shost
->dma_channel
!= 0xff)
1276 free_dma(shost
->dma_channel
);
1277 if (shost
->io_port
&& shost
->n_io_port
)
1278 release_region(shost
->io_port
, shost
->n_io_port
);
1279 scsi_unregister(shost
);
1283 static int aha1542_restart(struct Scsi_Host
*shost
)
1288 unchar ahacmd
= CMD_START_SCSI
;
1291 for (i
= 0; i
< AHA1542_MAILBOXES
; i
++)
1292 if (HOSTDATA(shost
)->SCint
[i
] &&
1293 !(HOSTDATA(shost
)->SCint
[i
]->device
->soft_reset
)) {
1295 HOSTDATA(shost
)->mb
[i
].status
= 1; /* Indicate ready to restart... */
1299 printk(KERN_DEBUG
"Potential to restart %d stalled commands...\n", count
);
1301 /* start scsi command */
1303 aha1542_out(shost
->io_port
, &ahacmd
, 1);
1309 * This is a device reset. This is handled by sending a special command
1312 static int aha1542_dev_reset(Scsi_Cmnd
* SCpnt
)
1314 unsigned long flags
;
1316 unchar target
= SCpnt
->device
->id
;
1317 unchar lun
= SCpnt
->device
->lun
;
1320 unchar ahacmd
= CMD_START_SCSI
;
1322 ccb
= HOSTDATA(SCpnt
->device
->host
)->ccb
;
1323 mb
= HOSTDATA(SCpnt
->device
->host
)->mb
;
1325 spin_lock_irqsave(&aha1542_lock
, flags
);
1326 mbo
= HOSTDATA(SCpnt
->device
->host
)->aha1542_last_mbo_used
+ 1;
1327 if (mbo
>= AHA1542_MAILBOXES
)
1331 if (mb
[mbo
].status
== 0 && HOSTDATA(SCpnt
->device
->host
)->SCint
[mbo
] == NULL
)
1334 if (mbo
>= AHA1542_MAILBOXES
)
1336 } while (mbo
!= HOSTDATA(SCpnt
->device
->host
)->aha1542_last_mbo_used
);
1338 if (mb
[mbo
].status
|| HOSTDATA(SCpnt
->device
->host
)->SCint
[mbo
])
1339 panic("Unable to find empty mailbox for aha1542.\n");
1341 HOSTDATA(SCpnt
->device
->host
)->SCint
[mbo
] = SCpnt
; /* This will effectively
1342 prevent someone else from
1343 screwing with this cdb. */
1345 HOSTDATA(SCpnt
->device
->host
)->aha1542_last_mbo_used
= mbo
;
1346 spin_unlock_irqrestore(&aha1542_lock
, flags
);
1348 any2scsi(mb
[mbo
].ccbptr
, SCSI_BUF_PA(&ccb
[mbo
])); /* This gets trashed for some reason */
1350 memset(&ccb
[mbo
], 0, sizeof(struct ccb
));
1352 ccb
[mbo
].op
= 0x81; /* BUS DEVICE RESET */
1354 ccb
[mbo
].idlun
= (target
& 7) << 5 | (lun
& 7); /*SCSI Target Id */
1356 ccb
[mbo
].linkptr
[0] = ccb
[mbo
].linkptr
[1] = ccb
[mbo
].linkptr
[2] = 0;
1357 ccb
[mbo
].commlinkid
= 0;
1360 * Now tell the 1542 to flush all pending commands for this
1363 aha1542_out(SCpnt
->device
->host
->io_port
, &ahacmd
, 1);
1365 scmd_printk(KERN_WARNING
, SCpnt
,
1366 "Trying device reset for target\n");
1371 #ifdef ERIC_neverdef
1373 * With the 1542 we apparently never get an interrupt to
1374 * acknowledge a device reset being sent. Then again, Leonard
1375 * says we are doing this wrong in the first place...
1377 * Take a wait and see attitude. If we get spurious interrupts,
1378 * then the device reset is doing something sane and useful, and
1379 * we will wait for the interrupt to post completion.
1381 printk(KERN_WARNING
"Sent BUS DEVICE RESET to target %d\n", SCpnt
->target
);
1384 * Free the command block for all commands running on this
1387 for (i
= 0; i
< AHA1542_MAILBOXES
; i
++) {
1388 if (HOSTDATA(SCpnt
->host
)->SCint
[i
] &&
1389 HOSTDATA(SCpnt
->host
)->SCint
[i
]->target
== SCpnt
->target
) {
1391 SCtmp
= HOSTDATA(SCpnt
->host
)->SCint
[i
];
1392 kfree(SCtmp
->host_scribble
);
1393 SCtmp
->host_scribble
= NULL
;
1394 HOSTDATA(SCpnt
->host
)->SCint
[i
] = NULL
;
1395 HOSTDATA(SCpnt
->host
)->mb
[i
].status
= 0;
1401 #endif /* ERIC_neverdef */
1404 static int aha1542_bus_reset(Scsi_Cmnd
* SCpnt
)
1409 * This does a scsi reset for all devices on the bus.
1410 * In principle, we could also reset the 1542 - should
1411 * we do this? Try this first, and we can add that later
1412 * if it turns out to be useful.
1414 outb(SCRST
, CONTROL(SCpnt
->device
->host
->io_port
));
1417 * Wait for the thing to settle down a bit. Unfortunately
1418 * this is going to basically lock up the machine while we
1419 * wait for this to complete. To be 100% correct, we need to
1420 * check for timeout, and if we are doing something like this
1421 * we are pretty desperate anyways.
1425 spin_lock_irq(SCpnt
->device
->host
->host_lock
);
1427 WAIT(STATUS(SCpnt
->device
->host
->io_port
),
1428 STATMASK
, INIT
| IDLE
, STST
| DIAGF
| INVDCMD
| DF
| CDF
);
1431 * Now try to pick up the pieces. For all pending commands,
1432 * free any internal data structures, and basically clear things
1433 * out. We do not try and restart any commands or anything -
1434 * the strategy handler takes care of that crap.
1436 printk(KERN_WARNING
"Sent BUS RESET to scsi host %d\n", SCpnt
->device
->host
->host_no
);
1438 for (i
= 0; i
< AHA1542_MAILBOXES
; i
++) {
1439 if (HOSTDATA(SCpnt
->device
->host
)->SCint
[i
] != NULL
) {
1441 SCtmp
= HOSTDATA(SCpnt
->device
->host
)->SCint
[i
];
1444 if (SCtmp
->device
->soft_reset
) {
1446 * If this device implements the soft reset option,
1447 * then it is still holding onto the command, and
1448 * may yet complete it. In this case, we don't
1453 kfree(SCtmp
->host_scribble
);
1454 SCtmp
->host_scribble
= NULL
;
1455 HOSTDATA(SCpnt
->device
->host
)->SCint
[i
] = NULL
;
1456 HOSTDATA(SCpnt
->device
->host
)->mb
[i
].status
= 0;
1460 spin_unlock_irq(SCpnt
->device
->host
->host_lock
);
1464 spin_unlock_irq(SCpnt
->device
->host
->host_lock
);
1468 static int aha1542_host_reset(Scsi_Cmnd
* SCpnt
)
1473 * This does a scsi reset for all devices on the bus.
1474 * In principle, we could also reset the 1542 - should
1475 * we do this? Try this first, and we can add that later
1476 * if it turns out to be useful.
1478 outb(HRST
| SCRST
, CONTROL(SCpnt
->device
->host
->io_port
));
1481 * Wait for the thing to settle down a bit. Unfortunately
1482 * this is going to basically lock up the machine while we
1483 * wait for this to complete. To be 100% correct, we need to
1484 * check for timeout, and if we are doing something like this
1485 * we are pretty desperate anyways.
1488 spin_lock_irq(SCpnt
->device
->host
->host_lock
);
1490 WAIT(STATUS(SCpnt
->device
->host
->io_port
),
1491 STATMASK
, INIT
| IDLE
, STST
| DIAGF
| INVDCMD
| DF
| CDF
);
1494 * We need to do this too before the 1542 can interact with
1497 setup_mailboxes(SCpnt
->device
->host
->io_port
, SCpnt
->device
->host
);
1500 * Now try to pick up the pieces. For all pending commands,
1501 * free any internal data structures, and basically clear things
1502 * out. We do not try and restart any commands or anything -
1503 * the strategy handler takes care of that crap.
1505 printk(KERN_WARNING
"Sent BUS RESET to scsi host %d\n", SCpnt
->device
->host
->host_no
);
1507 for (i
= 0; i
< AHA1542_MAILBOXES
; i
++) {
1508 if (HOSTDATA(SCpnt
->device
->host
)->SCint
[i
] != NULL
) {
1510 SCtmp
= HOSTDATA(SCpnt
->device
->host
)->SCint
[i
];
1512 if (SCtmp
->device
->soft_reset
) {
1514 * If this device implements the soft reset option,
1515 * then it is still holding onto the command, and
1516 * may yet complete it. In this case, we don't
1521 kfree(SCtmp
->host_scribble
);
1522 SCtmp
->host_scribble
= NULL
;
1523 HOSTDATA(SCpnt
->device
->host
)->SCint
[i
] = NULL
;
1524 HOSTDATA(SCpnt
->device
->host
)->mb
[i
].status
= 0;
1528 spin_unlock_irq(SCpnt
->device
->host
->host_lock
);
1532 spin_unlock_irq(SCpnt
->device
->host
->host_lock
);
1538 * These are the old error handling routines. They are only temporarily
1539 * here while we play with the new error handling code.
1541 static int aha1542_old_abort(Scsi_Cmnd
* SCpnt
)
1544 unchar ahacmd
= CMD_START_SCSI
;
1545 unsigned long flags
;
1549 printk(KERN_DEBUG
"In aha1542_abort: %x %x\n",
1550 inb(STATUS(SCpnt
->host
->io_port
)),
1551 inb(INTRFLAGS(SCpnt
->host
->io_port
)));
1553 spin_lock_irqsave(&aha1542_lock
, flags
);
1554 mb
= HOSTDATA(SCpnt
->host
)->mb
;
1555 mbi
= HOSTDATA(SCpnt
->host
)->aha1542_last_mbi_used
+ 1;
1556 if (mbi
>= 2 * AHA1542_MAILBOXES
)
1557 mbi
= AHA1542_MAILBOXES
;
1560 if (mb
[mbi
].status
!= 0)
1563 if (mbi
>= 2 * AHA1542_MAILBOXES
)
1564 mbi
= AHA1542_MAILBOXES
;
1565 } while (mbi
!= HOSTDATA(SCpnt
->host
)->aha1542_last_mbi_used
);
1566 spin_unlock_irqrestore(&aha1542_lock
, flags
);
1568 if (mb
[mbi
].status
) {
1569 printk(KERN_ERR
"Lost interrupt discovered on irq %d - attempting to recover\n",
1571 aha1542_intr_handle(SCpnt
->host
, NULL
);
1574 /* OK, no lost interrupt. Try looking to see how many pending commands
1575 we think we have. */
1577 for (i
= 0; i
< AHA1542_MAILBOXES
; i
++)
1578 if (HOSTDATA(SCpnt
->host
)->SCint
[i
]) {
1579 if (HOSTDATA(SCpnt
->host
)->SCint
[i
] == SCpnt
) {
1580 printk(KERN_ERR
"Timed out command pending for %s\n",
1581 SCpnt
->request
->rq_disk
?
1582 SCpnt
->request
->rq_disk
->disk_name
: "?"
1584 if (HOSTDATA(SCpnt
->host
)->mb
[i
].status
) {
1585 printk(KERN_ERR
"OGMB still full - restarting\n");
1586 aha1542_out(SCpnt
->host
->io_port
, &ahacmd
, 1);
1589 printk(KERN_ERR
"Other pending command %s\n",
1590 SCpnt
->request
->rq_disk
?
1591 SCpnt
->request
->rq_disk
->disk_name
: "?"
1596 DEB(printk("aha1542_abort\n"));
1598 spin_lock_irqsave(&aha1542_lock
, flags
);
1599 for (mbo
= 0; mbo
< AHA1542_MAILBOXES
; mbo
++) {
1600 if (SCpnt
== HOSTDATA(SCpnt
->host
)->SCint
[mbo
]) {
1601 mb
[mbo
].status
= 2; /* Abort command */
1602 aha1542_out(SCpnt
->host
->io_port
, &ahacmd
, 1); /* start scsi command */
1603 spin_unlock_irqrestore(&aha1542_lock
, flags
);
1607 if (AHA1542_MAILBOXES
== mbo
)
1608 spin_unlock_irqrestore(&aha1542_lock
, flags
);
1610 return SCSI_ABORT_SNOOZE
;
1613 /* We do not implement a reset function here, but the upper level code
1614 assumes that it will get some kind of response for the command in
1615 SCpnt. We must oblige, or the command will hang the scsi system.
1616 For a first go, we assume that the 1542 notifies us with all of the
1617 pending commands (it does implement soft reset, after all). */
1619 static int aha1542_old_reset(Scsi_Cmnd
* SCpnt
, unsigned int reset_flags
)
1621 unchar ahacmd
= CMD_START_SCSI
;
1625 * See if a bus reset was suggested.
1627 if (reset_flags
& SCSI_RESET_SUGGEST_BUS_RESET
) {
1629 * This does a scsi reset for all devices on the bus.
1630 * In principle, we could also reset the 1542 - should
1631 * we do this? Try this first, and we can add that later
1632 * if it turns out to be useful.
1634 outb(HRST
| SCRST
, CONTROL(SCpnt
->host
->io_port
));
1637 * Wait for the thing to settle down a bit. Unfortunately
1638 * this is going to basically lock up the machine while we
1639 * wait for this to complete. To be 100% correct, we need to
1640 * check for timeout, and if we are doing something like this
1641 * we are pretty desperate anyways.
1643 WAIT(STATUS(SCpnt
->host
->io_port
),
1644 STATMASK
, INIT
| IDLE
, STST
| DIAGF
| INVDCMD
| DF
| CDF
);
1647 * We need to do this too before the 1542 can interact with
1650 setup_mailboxes(SCpnt
->host
->io_port
, SCpnt
->host
);
1653 * Now try to pick up the pieces. Restart all commands
1654 * that are currently active on the bus, and reset all of
1655 * the datastructures. We have some time to kill while
1656 * things settle down, so print a nice message.
1658 printk(KERN_WARNING
"Sent BUS RESET to scsi host %d\n", SCpnt
->host
->host_no
);
1660 for (i
= 0; i
< AHA1542_MAILBOXES
; i
++)
1661 if (HOSTDATA(SCpnt
->host
)->SCint
[i
] != NULL
) {
1663 SCtmp
= HOSTDATA(SCpnt
->host
)->SCint
[i
];
1664 SCtmp
->result
= DID_RESET
<< 16;
1665 kfree(SCtmp
->host_scribble
);
1666 SCtmp
->host_scribble
= NULL
;
1667 printk(KERN_WARNING
"Sending DID_RESET for target %d\n", SCpnt
->target
);
1668 SCtmp
->scsi_done(SCpnt
);
1670 HOSTDATA(SCpnt
->host
)->SCint
[i
] = NULL
;
1671 HOSTDATA(SCpnt
->host
)->mb
[i
].status
= 0;
1674 * Now tell the mid-level code what we did here. Since
1675 * we have restarted all of the outstanding commands,
1676 * then report SUCCESS.
1678 return (SCSI_RESET_SUCCESS
| SCSI_RESET_BUS_RESET
);
1680 printk(KERN_CRIT
"aha1542.c: Unable to perform hard reset.\n");
1681 printk(KERN_CRIT
"Power cycle machine to reset\n");
1682 return (SCSI_RESET_ERROR
| SCSI_RESET_BUS_RESET
);
1686 /* This does a selective reset of just the one device */
1687 /* First locate the ccb for this command */
1688 for (i
= 0; i
< AHA1542_MAILBOXES
; i
++)
1689 if (HOSTDATA(SCpnt
->host
)->SCint
[i
] == SCpnt
) {
1690 HOSTDATA(SCpnt
->host
)->ccb
[i
].op
= 0x81; /* BUS DEVICE RESET */
1691 /* Now tell the 1542 to flush all pending commands for this target */
1692 aha1542_out(SCpnt
->host
->io_port
, &ahacmd
, 1);
1694 /* Here is the tricky part. What to do next. Do we get an interrupt
1695 for the commands that we aborted with the specified target, or
1696 do we generate this on our own? Try it without first and see
1698 printk(KERN_WARNING
"Sent BUS DEVICE RESET to target %d\n", SCpnt
->target
);
1700 /* If the first does not work, then try the second. I think the
1701 first option is more likely to be correct. Free the command
1702 block for all commands running on this target... */
1703 for (i
= 0; i
< AHA1542_MAILBOXES
; i
++)
1704 if (HOSTDATA(SCpnt
->host
)->SCint
[i
] &&
1705 HOSTDATA(SCpnt
->host
)->SCint
[i
]->target
== SCpnt
->target
) {
1707 SCtmp
= HOSTDATA(SCpnt
->host
)->SCint
[i
];
1708 SCtmp
->result
= DID_RESET
<< 16;
1709 kfree(SCtmp
->host_scribble
);
1710 SCtmp
->host_scribble
= NULL
;
1711 printk(KERN_WARNING
"Sending DID_RESET for target %d\n", SCpnt
->target
);
1712 SCtmp
->scsi_done(SCpnt
);
1714 HOSTDATA(SCpnt
->host
)->SCint
[i
] = NULL
;
1715 HOSTDATA(SCpnt
->host
)->mb
[i
].status
= 0;
1717 return SCSI_RESET_SUCCESS
;
1720 /* No active command at this time, so this means that each time we got
1721 some kind of response the last time through. Tell the mid-level code
1722 to request sense information in order to decide what to do next. */
1723 return SCSI_RESET_PUNT
;
1725 #endif /* end of big comment block around old_abort + old_reset */
1727 static int aha1542_biosparam(struct scsi_device
*sdev
,
1728 struct block_device
*bdev
, sector_t capacity
, int *ip
)
1730 int translation_algorithm
;
1731 int size
= capacity
;
1733 translation_algorithm
= HOSTDATA(sdev
->host
)->bios_translation
;
1735 if ((size
>> 11) > 1024 && translation_algorithm
== BIOS_TRANSLATION_25563
) {
1736 /* Please verify that this is the same as what DOS returns */
1739 ip
[2] = size
/ 255 / 63;
1748 MODULE_LICENSE("GPL");
1751 static struct scsi_host_template driver_template
= {
1752 .proc_name
= "aha1542",
1753 .name
= "Adaptec 1542",
1754 .detect
= aha1542_detect
,
1755 .release
= aha1542_release
,
1756 .queuecommand
= aha1542_queuecommand
,
1757 .eh_device_reset_handler
= aha1542_dev_reset
,
1758 .eh_bus_reset_handler
= aha1542_bus_reset
,
1759 .eh_host_reset_handler
= aha1542_host_reset
,
1760 .bios_param
= aha1542_biosparam
,
1761 .can_queue
= AHA1542_MAILBOXES
,
1763 .sg_tablesize
= AHA1542_SCATTER
,
1764 .cmd_per_lun
= AHA1542_CMDLUN
,
1765 .unchecked_isa_dma
= 1,
1766 .use_clustering
= ENABLE_CLUSTERING
,
1768 #include "scsi_module.c"