2 * linux/drivers/scsi/wd7000.c
4 * Copyright (C) 1992 Thomas Wuensche
5 * closely related to the aha1542 driver from Tommy Thorn
6 * ( as close as different hardware allows on a lowlevel-driver :-) )
8 * Revised (and renamed) by John Boyd <boyd@cis.ohio-state.edu> to
9 * accommodate Eric Youngdale's modifications to scsi.c. Nov 1992.
11 * Additional changes to support scatter/gather. Dec. 1992. tw/jb
13 * No longer tries to reset SCSI bus at boot (it wasn't working anyway).
14 * Rewritten to support multiple host adapters.
15 * Miscellaneous cleanup.
16 * So far, still doesn't do reset or abort correctly, since I have no idea
17 * how to do them with this board (8^(. Jan 1994 jb
19 * This driver now supports both of the two standard configurations (per
20 * the 3.36 Owner's Manual, my latest reference) by the same method as
21 * before; namely, by looking for a BIOS signature. Thus, the location of
22 * the BIOS signature determines the board configuration. Until I have
23 * time to do something more flexible, users should stick to one of the
26 * Standard configuration for single-adapter systems:
28 * - I/O base address 350h
31 * Standard configuration for a second adapter in a system:
33 * - I/O base address 330h
37 * Anyone who can recompile the kernel is welcome to add others as need
38 * arises, but unpredictable results may occur if there are conflicts.
39 * In any event, if there are multiple adapters in a system, they MUST
40 * use different I/O bases, IRQ levels, and DMA channels, since they will be
41 * indistinguishable (and in direct conflict) otherwise.
43 * As a point of information, the NO_OP command toggles the CMD_RDY bit
44 * of the status port, and this fact could be used as a test for the I/O
45 * base address (or more generally, board detection). There is an interrupt
46 * status port, so IRQ probing could also be done. I suppose the full
47 * DMA diagnostic could be used to detect the DMA channel being used. I
48 * haven't done any of this, though, because I think there's too much of
49 * a chance that such explorations could be destructive, if some other
50 * board's resources are used inadvertently. So, call me a wimp, but I
51 * don't want to try it. The only kind of exploration I trust is memory
52 * exploration, since it's more certain that reading memory won't be
55 * More to my liking would be a LILO boot command line specification, such
56 * as is used by the aha152x driver (and possibly others). I'll look into
57 * it, as I have time...
59 * I get mail occasionally from people who either are using or are
60 * considering using a WD7000 with Linux. There is a variety of
61 * nomenclature describing WD7000's. To the best of my knowledge, the
62 * following is a brief summary (from an old WD doc - I don't work for
63 * them or anything like that):
65 * WD7000-FASST2: This is a WD7000 board with the real-mode SST ROM BIOS
66 * installed. Last I heard, the BIOS was actually done by Columbia
67 * Data Products. The BIOS is only used by this driver (and thus
68 * by Linux) to identify the board; none of it can be executed under
71 * WD7000-ASC: This is the original adapter board, with or without BIOS.
72 * The board uses a WD33C93 or WD33C93A SBIC, which in turn is
73 * controlled by an onboard Z80 processor. The board interface
74 * visible to the host CPU is defined effectively by the Z80's
75 * firmware, and it is this firmware's revision level that is
76 * determined and reported by this driver. (The version of the
77 * on-board BIOS is of no interest whatsoever.) The host CPU has
78 * no access to the SBIC; hence the fact that it is a WD33C93 is
79 * also of no interest to this driver.
83 * WD7000-EX: These are newer versions of the WD7000-ASC. The -ASC is
84 * largely built from discrete components; these boards use more
85 * integration. The -AX is an ISA bus board (like the -ASC),
86 * the -MX is an MCA (i.e., PS/2) bus board), and the -EX is an
89 * At the time of my documentation, the -?X boards were "future" products,
90 * and were not yet available. However, I vaguely recall that Thomas
91 * Wuensche had an -AX, so I believe at least it is supported by this
92 * driver. I have no personal knowledge of either -MX or -EX boards.
94 * P.S. Just recently, I've discovered (directly from WD and Future
95 * Domain) that all but the WD7000-EX have been out of production for
96 * two years now. FD has production rights to the 7000-EX, and are
97 * producing it under a new name, and with a new BIOS. If anyone has
98 * one of the FD boards, it would be nice to come up with a signature
103 * Revisions by Miroslav Zagorac <zaga@fly.cc.fer.hr>
107 * Enhancement for wd7000_detect function has been made, so you don't have
108 * to enter BIOS ROM address in initialisation data (see struct Config).
109 * We cannot detect IRQ, DMA and I/O base address for now, so we have to
110 * enter them as arguments while wd_7000 is detected. If someone has IRQ,
111 * DMA or I/O base address set to some other value, he can enter them in
112 * configuration without any problem. Also I wrote a function wd7000_setup,
113 * so now you can enter WD-7000 definition as kernel arguments,
116 * append="wd7000=IRQ,DMA,IO"
118 * PS: If card BIOS ROM is disabled, function wd7000_detect now will recognize
119 * adapter, unlike the old one. Anyway, BIOS ROM from WD7000 adapter is
120 * useless for Linux. B^)
125 * Autodetecting of I/O base address from wd7000_detect function is removed,
126 * some little bugs removed, etc...
128 * Thanks to Roger Scott for driver debugging.
132 * Added support for /proc file system (/proc/scsi/wd7000/[0...] files).
133 * Now, driver can handle hard disks with capacity >1GB.
137 * Added support for BUS_ON and BUS_OFF parameters in config line.
138 * Miscellaneous cleanup.
142 * WD7000 driver now work on kernels >= 2.1.x
145 * 12/31/2001 - Arnaldo Carvalho de Melo <acme@conectiva.com.br>
147 * use host->host_lock, not io_request_lock, cleanups
149 * 2002/10/04 - Alan Cox <alan@redhat.com>
151 * Use dev_id for interrupts, kill __FUNCTION__ pasting
152 * Add a lock for the scb pool, clean up all other cli/sti usage stuff
153 * Use the adapter lock for the other places we had the cli's
155 * 2002/10/06 - Alan Cox <alan@redhat.com>
157 * Switch to new style error handling
158 * Clean up delay to udelay, and yielding sleeps
159 * Make host reset actually reset the card
160 * Make everything static
162 * 2003/02/12 - Christoph Hellwig <hch@infradead.org>
164 * Cleaned up host template defintion
165 * Removed now obsolete wd7000.h
168 #include <linux/module.h>
169 #include <linux/interrupt.h>
170 #include <linux/kernel.h>
171 #include <linux/types.h>
172 #include <linux/string.h>
173 #include <linux/slab.h>
174 #include <linux/spinlock.h>
175 #include <linux/ioport.h>
176 #include <linux/proc_fs.h>
177 #include <linux/blkdev.h>
178 #include <linux/init.h>
179 #include <linux/stat.h>
181 #include <asm/system.h>
187 #include <scsi/scsicam.h>
190 #define ANY2SCSI_INLINE /* undef this to use old macros */
191 #undef WD7000_DEBUG /* general debug */
193 #define dprintk printk
195 #define dprintk(format,args...)
199 * Mailbox structure sizes.
200 * I prefer to keep the number of ICMBs much larger than the number of
201 * OGMBs. OGMBs are used very quickly by the driver to start one or
202 * more commands, while ICMBs are used by the host adapter per command.
208 * Scb's are shared by all active adapters. So, if they all become busy,
209 * callers may be made to wait in alloc_scbs for them to free. That can
210 * be avoided by setting MAX_SCBS to NUM_CONFIG * WD7000_Q. If you'd
211 * rather conserve memory, use a smaller number (> 0, of course) - things
212 * will should still work OK.
217 * In this version, sg_tablesize now defaults to WD7000_SG, and will
218 * be set to SG_NONE for older boards. This is the reverse of the
219 * previous default, and was changed so that the driver-level
220 * Scsi_Host_Template would reflect the driver's support for scatter/
223 * Also, it has been reported that boards at Revision 6 support scatter/
224 * gather, so the new definition of an "older" board has been changed
232 * WD7000-specific mailbox structure
235 typedef volatile struct mailbox {
237 unchar scbptr[3]; /* SCSI-style - MSB first (big endian) */
241 * This structure should contain all per-adapter global data. I.e., any
242 * new global per-adapter data should put in here.
244 typedef struct adapter {
245 struct Scsi_Host *sh; /* Pointer to Scsi_Host structure */
246 int iobase; /* This adapter's I/O base address */
247 int irq; /* This adapter's IRQ level */
248 int dma; /* This adapter's DMA channel */
249 int int_counter; /* This adapter's interrupt counter */
250 int bus_on; /* This adapter's BUS_ON time */
251 int bus_off; /* This adapter's BUS_OFF time */
252 struct { /* This adapter's mailboxes */
253 Mailbox ogmb[OGMB_CNT]; /* Outgoing mailboxes */
254 Mailbox icmb[ICMB_CNT]; /* Incoming mailboxes */
256 int next_ogmb; /* to reduce contention at mailboxes */
257 unchar control; /* shadows CONTROL port value */
258 unchar rev1, rev2; /* filled in by wd7000_revision */
262 * (linear) base address for ROM BIOS
264 static const long wd7000_biosaddr[] = {
265 0xc0000, 0xc2000, 0xc4000, 0xc6000, 0xc8000, 0xca000, 0xcc000, 0xce000,
266 0xd0000, 0xd2000, 0xd4000, 0xd6000, 0xd8000, 0xda000, 0xdc000, 0xde000
268 #define NUM_ADDRS (sizeof(wd7000_biosaddr)/sizeof(long))
270 static const unsigned short wd7000_iobase[] = {
271 0x0300, 0x0308, 0x0310, 0x0318, 0x0320, 0x0328, 0x0330, 0x0338,
272 0x0340, 0x0348, 0x0350, 0x0358, 0x0360, 0x0368, 0x0370, 0x0378,
273 0x0380, 0x0388, 0x0390, 0x0398, 0x03a0, 0x03a8, 0x03b0, 0x03b8,
274 0x03c0, 0x03c8, 0x03d0, 0x03d8, 0x03e0, 0x03e8, 0x03f0, 0x03f8
276 #define NUM_IOPORTS (sizeof(wd7000_iobase)/sizeof(unsigned short))
278 static const short wd7000_irq[] = { 3, 4, 5, 7, 9, 10, 11, 12, 14, 15 };
279 #define NUM_IRQS (sizeof(wd7000_irq)/sizeof(short))
281 static const short wd7000_dma[] = { 5, 6, 7 };
282 #define NUM_DMAS (sizeof(wd7000_dma)/sizeof(short))
285 * The following is set up by wd7000_detect, and used thereafter for
286 * proc and other global ookups
290 static struct Scsi_Host *wd7000_host[UNITS];
292 #define BUS_ON 64 /* x 125ns = 8000ns (BIOS default) */
293 #define BUS_OFF 15 /* x 125ns = 1875ns (BIOS default) */
296 * Standard Adapter Configurations - used by wd7000_detect
299 short irq; /* IRQ level */
300 short dma; /* DMA channel */
301 unsigned iobase; /* I/O base address */
302 short bus_on; /* Time that WD7000 spends on the AT-bus when */
303 /* transferring data. BIOS default is 8000ns. */
304 short bus_off; /* Time that WD7000 spends OFF THE BUS after */
305 /* while it is transferring data. */
306 /* BIOS default is 1875ns */
310 * Add here your configuration...
312 static Config configs[] = {
313 {15, 6, 0x350, BUS_ON, BUS_OFF}, /* defaults for single adapter */
314 {11, 5, 0x320, BUS_ON, BUS_OFF}, /* defaults for second adapter */
315 {7, 6, 0x350, BUS_ON, BUS_OFF}, /* My configuration (Zaga) */
316 {-1, -1, 0x0, BUS_ON, BUS_OFF} /* Empty slot */
318 #define NUM_CONFIGS (sizeof(configs)/sizeof(Config))
321 * The following list defines strings to look for in the BIOS that identify
322 * it as the WD7000-FASST2 SST BIOS. I suspect that something should be
323 * added for the Future Domain version.
325 typedef struct signature {
326 const char *sig; /* String to look for */
327 unsigned long ofs; /* offset from BIOS base address */
328 unsigned len; /* length of string */
331 static const Signature signatures[] = {
332 {"SSTBIOS", 0x0000d, 7} /* "SSTBIOS" @ offset 0x0000d */
334 #define NUM_SIGNATURES (sizeof(signatures)/sizeof(Signature))
338 * I/O Port Offsets and Bit Definitions
339 * 4 addresses are used. Those not defined here are reserved.
341 #define ASC_STAT 0 /* Status, Read */
342 #define ASC_COMMAND 0 /* Command, Write */
343 #define ASC_INTR_STAT 1 /* Interrupt Status, Read */
344 #define ASC_INTR_ACK 1 /* Acknowledge, Write */
345 #define ASC_CONTROL 2 /* Control, Write */
350 #define INT_IM 0x80 /* Interrupt Image Flag */
351 #define CMD_RDY 0x40 /* Command Port Ready */
352 #define CMD_REJ 0x20 /* Command Port Byte Rejected */
353 #define ASC_INIT 0x10 /* ASC Initialized Flag */
354 #define ASC_STATMASK 0xf0 /* The lower 4 Bytes are reserved */
359 * Unfortunately, I have no idea how to properly use some of these commands,
360 * as the OEM manual does not make it clear. I have not been able to use
361 * enable/disable unsolicited interrupts or the reset commands with any
362 * discernible effect whatsoever. I think they may be related to certain
363 * ICB commands, but again, the OEM manual doesn't make that clear.
365 #define NO_OP 0 /* NO-OP toggles CMD_RDY bit in ASC_STAT */
366 #define INITIALIZATION 1 /* initialization (10 bytes) */
367 #define DISABLE_UNS_INTR 2 /* disable unsolicited interrupts */
368 #define ENABLE_UNS_INTR 3 /* enable unsolicited interrupts */
369 #define INTR_ON_FREE_OGMB 4 /* interrupt on free OGMB */
370 #define SOFT_RESET 5 /* SCSI bus soft reset */
371 #define HARD_RESET_ACK 6 /* SCSI bus hard reset acknowledge */
372 #define START_OGMB 0x80 /* start command in OGMB (n) */
373 #define SCAN_OGMBS 0xc0 /* start multiple commands, signature (n) */
374 /* where (n) = lower 6 bits */
376 * For INITIALIZATION:
378 typedef struct initCmd {
379 unchar op; /* command opcode (= 1) */
380 unchar ID; /* Adapter's SCSI ID */
381 unchar bus_on; /* Bus on time, x 125ns (see below) */
382 unchar bus_off; /* Bus off time, "" "" */
383 unchar rsvd; /* Reserved */
384 unchar mailboxes[3]; /* Address of Mailboxes, MSB first */
385 unchar ogmbs; /* Number of outgoing MBs, max 64, 0,1 = 1 */
386 unchar icmbs; /* Number of incoming MBs, "" "" */
390 * Interrupt Status Port - also returns diagnostic codes at ASC reset
392 * if msb is zero, the lower bits are diagnostic status
394 * 01 No diagnostic error occurred
397 * 04 SBIC register read/write failed
398 * 05 Initialization D-FF failed
399 * 06 Host IRQ D-FF failed
400 * 07 ROM checksum error
401 * Interrupt status (bitwise):
402 * 10NNNNNN outgoing mailbox NNNNNN is free
403 * 11NNNNNN incoming mailbox NNNNNN needs service
405 #define MB_INTR 0xC0 /* Mailbox Service possible/required */
406 #define IMB_INTR 0x40 /* 1 Incoming / 0 Outgoing */
407 #define MB_MASK 0x3f /* mask for mailbox number */
412 #define INT_EN 0x08 /* Interrupt Enable */
413 #define DMA_EN 0x04 /* DMA Enable */
414 #define SCSI_RES 0x02 /* SCSI Reset */
415 #define ASC_RES 0x01 /* ASC Reset */
418 * Driver data structures:
419 * - mb and scbs are required for interfacing with the host adapter.
420 * An SCB has extra fields not visible to the adapter; mb's
421 * _cannot_ do this, since the adapter assumes they are contiguous in
422 * memory, 4 bytes each, with ICMBs following OGMBs, and uses this fact
424 * - An icb is for host-only (non-SCSI) commands. ICBs are 16 bytes each;
425 * the additional bytes are used only by the driver.
426 * - For now, a pool of SCBs are kept in global storage by this driver,
427 * and are allocated and freed as needed.
429 * The 7000-FASST2 marks OGMBs empty as soon as it has _started_ a command,
430 * not when it has finished. Since the SCB must be around for completion,
431 * problems arise when SCBs correspond to OGMBs, which may be reallocated
432 * earlier (or delayed unnecessarily until a command completes).
433 * Mailboxes are used as transient data structures, simply for
434 * carrying SCB addresses to/from the 7000-FASST2.
436 * Note also since SCBs are not "permanently" associated with mailboxes,
437 * there is no need to keep a global list of Scsi_Cmnd pointers indexed
438 * by OGMB. Again, SCBs reference their Scsi_Cmnds directly, so mailbox
439 * indices need not be involved.
443 * WD7000-specific scatter/gather element structure
447 unchar ptr[3]; /* Also SCSI-style - MSB first */
450 typedef struct scb { /* Command Control Block 5.4.1 */
451 unchar op; /* Command Control Block Operation Code */
452 unchar idlun; /* op=0,2:Target Id, op=1:Initiator Id */
453 /* Outbound data transfer, length is checked */
454 /* Inbound data transfer, length is checked */
455 /* Logical Unit Number */
456 unchar cdb[12]; /* SCSI Command Block */
457 volatile unchar status; /* SCSI Return Status */
458 volatile unchar vue; /* Vendor Unique Error Code */
459 unchar maxlen[3]; /* Maximum Data Transfer Length */
460 unchar dataptr[3]; /* SCSI Data Block Pointer */
461 unchar linkptr[3]; /* Next Command Link Pointer */
462 unchar direc; /* Transfer Direction */
463 unchar reserved2[6]; /* SCSI Command Descriptor Block */
464 /* end of hardware SCB */
465 Scsi_Cmnd *SCpnt; /* Scsi_Cmnd using this SCB */
466 Sgb sgb[WD7000_SG]; /* Scatter/gather list for this SCB */
467 Adapter *host; /* host adapter */
468 struct scb *next; /* for lists of scbs */
472 * This driver is written to allow host-only commands to be executed.
473 * These use a 16-byte block called an ICB. The format is extended by the
474 * driver to 18 bytes, to support the status returned in the ICMB and
475 * an execution phase code.
477 * There are other formats besides these; these are the ones I've tried
478 * to use. Formats for some of the defined ICB opcodes are not defined
479 * (notably, get/set unsolicited interrupt status) in my copy of the OEM
480 * manual, and others are ambiguous/hard to follow.
482 #define ICB_OP_MASK 0x80 /* distinguishes scbs from icbs */
483 #define ICB_OP_OPEN_RBUF 0x80 /* open receive buffer */
484 #define ICB_OP_RECV_CMD 0x81 /* receive command from initiator */
485 #define ICB_OP_RECV_DATA 0x82 /* receive data from initiator */
486 #define ICB_OP_RECV_SDATA 0x83 /* receive data with status from init. */
487 #define ICB_OP_SEND_DATA 0x84 /* send data with status to initiator */
488 #define ICB_OP_SEND_STAT 0x86 /* send command status to initiator */
489 /* 0x87 is reserved */
490 #define ICB_OP_READ_INIT 0x88 /* read initialization bytes */
491 #define ICB_OP_READ_ID 0x89 /* read adapter's SCSI ID */
492 #define ICB_OP_SET_UMASK 0x8A /* set unsolicited interrupt mask */
493 #define ICB_OP_GET_UMASK 0x8B /* read unsolicited interrupt mask */
494 #define ICB_OP_GET_REVISION 0x8C /* read firmware revision level */
495 #define ICB_OP_DIAGNOSTICS 0x8D /* execute diagnostics */
496 #define ICB_OP_SET_EPARMS 0x8E /* set execution parameters */
497 #define ICB_OP_GET_EPARMS 0x8F /* read execution parameters */
499 typedef struct icbRecvCmd {
501 unchar IDlun; /* Initiator SCSI ID/lun */
502 unchar len[3]; /* command buffer length */
503 unchar ptr[3]; /* command buffer address */
504 unchar rsvd[7]; /* reserved */
505 volatile unchar vue; /* vendor-unique error code */
506 volatile unchar status; /* returned (icmb) status */
507 volatile unchar phase; /* used by interrupt handler */
510 typedef struct icbSendStat {
512 unchar IDlun; /* Target SCSI ID/lun */
513 unchar stat; /* (outgoing) completion status byte 1 */
514 unchar rsvd[12]; /* reserved */
515 volatile unchar vue; /* vendor-unique error code */
516 volatile unchar status; /* returned (icmb) status */
517 volatile unchar phase; /* used by interrupt handler */
520 typedef struct icbRevLvl {
522 volatile unchar primary; /* primary revision level (returned) */
523 volatile unchar secondary; /* secondary revision level (returned) */
524 unchar rsvd[12]; /* reserved */
525 volatile unchar vue; /* vendor-unique error code */
526 volatile unchar status; /* returned (icmb) status */
527 volatile unchar phase; /* used by interrupt handler */
530 typedef struct icbUnsMask { /* I'm totally guessing here */
532 volatile unchar mask[14]; /* mask bits */
534 unchar rsvd[12]; /* reserved */
536 volatile unchar vue; /* vendor-unique error code */
537 volatile unchar status; /* returned (icmb) status */
538 volatile unchar phase; /* used by interrupt handler */
541 typedef struct icbDiag {
543 unchar type; /* diagnostics type code (0-3) */
544 unchar len[3]; /* buffer length */
545 unchar ptr[3]; /* buffer address */
546 unchar rsvd[7]; /* reserved */
547 volatile unchar vue; /* vendor-unique error code */
548 volatile unchar status; /* returned (icmb) status */
549 volatile unchar phase; /* used by interrupt handler */
552 #define ICB_DIAG_POWERUP 0 /* Power-up diags only */
553 #define ICB_DIAG_WALKING 1 /* walking 1's pattern */
554 #define ICB_DIAG_DMA 2 /* DMA - system memory diags */
555 #define ICB_DIAG_FULL 3 /* do both 1 & 2 */
557 typedef struct icbParms {
559 unchar rsvd1; /* reserved */
560 unchar len[3]; /* parms buffer length */
561 unchar ptr[3]; /* parms buffer address */
562 unchar idx[2]; /* index (MSB-LSB) */
563 unchar rsvd2[5]; /* reserved */
564 volatile unchar vue; /* vendor-unique error code */
565 volatile unchar status; /* returned (icmb) status */
566 volatile unchar phase; /* used by interrupt handler */
569 typedef struct icbAny {
571 unchar data[14]; /* format-specific data */
572 volatile unchar vue; /* vendor-unique error code */
573 volatile unchar status; /* returned (icmb) status */
574 volatile unchar phase; /* used by interrupt handler */
578 unchar op; /* ICB opcode */
579 IcbRecvCmd recv_cmd; /* format for receive command */
580 IcbSendStat send_stat; /* format for send status */
581 IcbRevLvl rev_lvl; /* format for get revision level */
582 IcbDiag diag; /* format for execute diagnostics */
583 IcbParms eparms; /* format for get/set exec parms */
584 IcbAny icb; /* generic format */
590 MODULE_PARM(wd7000, "s");
594 * Driver SCB structure pool.
596 * The SCBs declared here are shared by all host adapters; hence, this
597 * structure is not part of the Adapter structure.
599 static Scb scbs[MAX_SCBS];
600 static Scb *scbfree; /* free list */
601 static int freescbs = MAX_SCBS; /* free list counter */
602 static spinlock_t scbpool_lock; /* guards the scb free list and count */
605 * END of data/declarations - code follows.
607 static void __init setup_error(char *mesg, int *ints)
610 printk(KERN_ERR "wd7000_setup: \"wd7000=%d,%d,0x%x\" -> %s\n", ints[1], ints[2], ints[3], mesg);
611 else if (ints[0] == 4)
612 printk(KERN_ERR "wd7000_setup: \"wd7000=%d,%d,0x%x,%d\" -> %s\n", ints[1], ints[2], ints[3], ints[4], mesg);
614 printk(KERN_ERR "wd7000_setup: \"wd7000=%d,%d,0x%x,%d,%d\" -> %s\n", ints[1], ints[2], ints[3], ints[4], ints[5], mesg);
619 * Note: You can now set these options from the kernel's "command line".
622 * wd7000=<IRQ>,<DMA>,<IO>[,<BUS_ON>[,<BUS_OFF>]]
624 * , where BUS_ON and BUS_OFF are in nanoseconds. BIOS default values
625 * are 8000ns for BUS_ON and 1875ns for BUS_OFF.
629 * will configure the driver for a WD-7000 controller
630 * using IRQ 15 with a DMA channel 6, at IO base address 0x350.
632 static int __init wd7000_setup(char *str)
634 static short wd7000_card_num; /* .bss will zero this */
638 (void) get_options(str, ARRAY_SIZE(ints), ints);
640 if (wd7000_card_num >= NUM_CONFIGS) {
641 printk(KERN_ERR "%s: Too many \"wd7000=\" configurations in " "command line!\n", __FUNCTION__);
645 if ((ints[0] < 3) || (ints[0] > 5)) {
646 printk(KERN_ERR "%s: Error in command line! " "Usage: wd7000=<IRQ>,<DMA>,IO>[,<BUS_ON>" "[,<BUS_OFF>]]\n", __FUNCTION__);
648 for (i = 0; i < NUM_IRQS; i++)
649 if (ints[1] == wd7000_irq[i])
653 setup_error("invalid IRQ.", ints);
656 configs[wd7000_card_num].irq = ints[1];
658 for (i = 0; i < NUM_DMAS; i++)
659 if (ints[2] == wd7000_dma[i])
663 setup_error("invalid DMA channel.", ints);
666 configs[wd7000_card_num].dma = ints[2];
668 for (i = 0; i < NUM_IOPORTS; i++)
669 if (ints[3] == wd7000_iobase[i])
672 if (i == NUM_IOPORTS) {
673 setup_error("invalid I/O base address.", ints);
676 configs[wd7000_card_num].iobase = ints[3];
679 if ((ints[4] < 500) || (ints[4] > 31875)) {
680 setup_error("BUS_ON value is out of range (500" " to 31875 nanoseconds)!", ints);
681 configs[wd7000_card_num].bus_on = BUS_ON;
683 configs[wd7000_card_num].bus_on = ints[4] / 125;
685 configs[wd7000_card_num].bus_on = BUS_ON;
688 if ((ints[5] < 500) || (ints[5] > 31875)) {
689 setup_error("BUS_OFF value is out of range (500" " to 31875 nanoseconds)!", ints);
690 configs[wd7000_card_num].bus_off = BUS_OFF;
692 configs[wd7000_card_num].bus_off = ints[5] / 125;
694 configs[wd7000_card_num].bus_off = BUS_OFF;
696 if (wd7000_card_num) {
697 for (i = 0; i < (wd7000_card_num - 1); i++) {
700 for (; j < wd7000_card_num; j++)
701 if (configs[i].irq == configs[j].irq) {
702 setup_error("duplicated IRQ!", ints);
705 if (configs[i].dma == configs[j].dma) {
706 setup_error("duplicated DMA " "channel!", ints);
709 if (configs[i].iobase == configs[j].iobase) {
710 setup_error("duplicated I/O " "base address!", ints);
716 dprintk(KERN_DEBUG "wd7000_setup: IRQ=%d, DMA=%d, I/O=0x%x, "
717 "BUS_ON=%dns, BUS_OFF=%dns\n", configs[wd7000_card_num].irq, configs[wd7000_card_num].dma, configs[wd7000_card_num].iobase, configs[wd7000_card_num].bus_on * 125, configs[wd7000_card_num].bus_off * 125);
724 __setup("wd7000=", wd7000_setup);
726 #ifdef ANY2SCSI_INLINE
728 * Since they're used a lot, I've redone the following from the macros
729 * formerly in wd7000.h, hopefully to speed them up by getting rid of
730 * all the shifting (it may not matter; GCC might have done as well anyway).
732 * xany2scsi and xscsi2int were not being used, and are no longer defined.
733 * (They were simply 4-byte versions of these routines).
735 typedef union { /* let's cheat... */
737 unchar u[sizeof(int)]; /* the sizeof(int) makes it more portable */
741 static inline void any2scsi(unchar * scsi, int any)
743 *scsi++ = ((i_u) any).u[2];
744 *scsi++ = ((i_u) any).u[1];
745 *scsi++ = ((i_u) any).u[0];
749 static inline int scsi2int(unchar * scsi)
753 result.i = 0; /* clears unused bytes */
754 result.u[2] = *scsi++;
755 result.u[1] = *scsi++;
756 result.u[0] = *scsi++;
762 * These are the old ones - I've just moved them here...
765 #define any2scsi(up, p) (up)[0] = (((unsigned long) (p)) >> 16); \
766 (up)[1] = ((unsigned long) (p)) >> 8; \
767 (up)[2] = ((unsigned long) (p));
770 #define scsi2int(up) ( (((unsigned long) *(up)) << 16) + \
771 (((unsigned long) (up)[1]) << 8) + \
772 ((unsigned long) (up)[2]) )
776 static inline void wd7000_enable_intr(Adapter * host)
778 host->control |= INT_EN;
779 outb(host->control, host->iobase + ASC_CONTROL);
783 static inline void wd7000_enable_dma(Adapter * host)
786 host->control |= DMA_EN;
787 outb(host->control, host->iobase + ASC_CONTROL);
789 flags = claim_dma_lock();
790 set_dma_mode(host->dma, DMA_MODE_CASCADE);
791 enable_dma(host->dma);
792 release_dma_lock(flags);
797 #define WAITnexttimeout 200 /* 2 seconds */
799 static inline short WAIT(unsigned port, unsigned mask, unsigned allof, unsigned noneof)
801 register unsigned WAITbits;
802 register unsigned long WAITtimeout = jiffies + WAITnexttimeout;
804 while (time_before_eq(jiffies, WAITtimeout)) {
805 WAITbits = inb(port) & mask;
807 if (((WAITbits & allof) == allof) && ((WAITbits & noneof) == 0))
815 static inline int command_out(Adapter * host, unchar * cmd, int len)
817 if (!WAIT(host->iobase + ASC_STAT, ASC_STATMASK, CMD_RDY, 0)) {
820 outb(*cmd, host->iobase + ASC_COMMAND);
821 WAIT(host->iobase + ASC_STAT, ASC_STATMASK, CMD_RDY, 0);
822 } while (inb(host->iobase + ASC_STAT) & CMD_REJ);
830 printk(KERN_WARNING "wd7000 command_out: WAIT failed(%d)\n", len + 1);
837 * This version of alloc_scbs is in preparation for supporting multiple
838 * commands per lun and command chaining, by queueing pending commands.
839 * We will need to allocate Scbs in blocks since they will wait to be
840 * executed so there is the possibility of deadlock otherwise.
841 * Also, to keep larger requests from being starved by smaller requests,
842 * we limit access to this routine with an internal busy flag, so that
843 * the satisfiability of a request is not dependent on the size of the
846 static inline Scb *alloc_scbs(struct Scsi_Host *host, int needed)
848 register Scb *scb, *p = NULL;
849 register unsigned long flags;
850 register unsigned long timeout = jiffies + WAITnexttimeout;
851 register unsigned long now;
855 return (NULL); /* sanity check */
857 spin_unlock_irq(host->host_lock);
860 while (freescbs < needed) {
861 timeout = jiffies + WAITnexttimeout;
863 /* FIXME: can we actually just yield here ?? */
864 for (now = jiffies; now == jiffies;)
865 cpu_relax(); /* wait a jiffy */
866 } while (freescbs < needed && time_before_eq(jiffies, timeout));
868 * If we get here with enough free Scbs, we can take them.
869 * Otherwise, we timed out and didn't get enough.
871 if (freescbs < needed) {
872 printk(KERN_ERR "wd7000: can't get enough free SCBs.\n");
877 /* Take the lock, then check we didnt get beaten, if so try again */
878 spin_lock_irqsave(&scbpool_lock, flags);
879 if (freescbs < needed) {
880 spin_unlock_irqrestore(&scbpool_lock, flags);
886 for (i = 0; i < needed; i++) {
892 spin_unlock_irqrestore(&scbpool_lock, flags);
894 spin_lock_irq(host->host_lock);
899 static inline void free_scb(Scb * scb)
901 register unsigned long flags;
903 spin_lock_irqsave(&scbpool_lock, flags);
905 memset(scb, 0, sizeof(Scb));
910 spin_unlock_irqrestore(&scbpool_lock, flags);
914 static inline void init_scbs(void)
918 spin_lock_init(&scbpool_lock);
920 /* This is only ever called before the SCB pool is active */
922 scbfree = &(scbs[0]);
923 memset(scbs, 0, sizeof(scbs));
924 for (i = 0; i < MAX_SCBS - 1; i++) {
925 scbs[i].next = &(scbs[i + 1]);
926 scbs[i].SCpnt = NULL;
928 scbs[MAX_SCBS - 1].next = NULL;
929 scbs[MAX_SCBS - 1].SCpnt = NULL;
933 static int mail_out(Adapter * host, Scb * scbptr)
935 * Note: this can also be used for ICBs; just cast to the parm type.
938 register int i, ogmb;
939 register unsigned long flags;
941 Mailbox *ogmbs = host->mb.ogmb;
942 int *next_ogmb = &(host->next_ogmb);
944 dprintk("wd7000_mail_out: 0x%06lx", (long) scbptr);
946 /* We first look for a free outgoing mailbox */
947 spin_lock_irqsave(host->sh->host_lock, flags);
949 for (i = 0; i < OGMB_CNT; i++) {
950 if (ogmbs[ogmb].status == 0) {
951 dprintk(" using OGMB 0x%x", ogmb);
952 ogmbs[ogmb].status = 1;
953 any2scsi((unchar *) ogmbs[ogmb].scbptr, (int) scbptr);
955 *next_ogmb = (ogmb + 1) % OGMB_CNT;
958 ogmb = (ogmb + 1) % OGMB_CNT;
960 spin_unlock_irqrestore(host->sh->host_lock, flags);
962 dprintk(", scb is 0x%06lx", (long) scbptr);
966 * Alternatively, we might issue the "interrupt on free OGMB",
967 * and sleep, but it must be ensured that it isn't the init
968 * task running. Instead, this version assumes that the caller
969 * will be persistent, and try again. Since it's the adapter
970 * that marks OGMB's free, waiting even with interrupts off
971 * should work, since they are freed very quickly in most cases.
973 dprintk(", no free OGMBs.\n");
977 wd7000_enable_intr(host);
979 start_ogmb = START_OGMB | ogmb;
980 command_out(host, &start_ogmb, 1);
982 dprintk(", awaiting interrupt.\n");
988 static int make_code(unsigned hosterr, unsigned scsierr)
991 int in_error = hosterr;
994 switch ((hosterr >> 8) & 0xff) {
995 case 0: /* Reserved */
998 case 1: /* Command Complete, no errors */
1001 case 2: /* Command complete, error logged in scb status (scsierr) */
1004 case 4: /* Command failed to complete - timeout */
1005 hosterr = DID_TIME_OUT;
1007 case 5: /* Command terminated; Bus reset by external device */
1008 hosterr = DID_RESET;
1010 case 6: /* Unexpected Command Received w/ host as target */
1011 hosterr = DID_BAD_TARGET;
1013 case 80: /* Unexpected Reselection */
1014 case 81: /* Unexpected Selection */
1015 hosterr = DID_BAD_INTR;
1017 case 82: /* Abort Command Message */
1018 hosterr = DID_ABORT;
1020 case 83: /* SCSI Bus Software Reset */
1021 case 84: /* SCSI Bus Hardware Reset */
1022 hosterr = DID_RESET;
1024 default: /* Reserved */
1025 hosterr = DID_ERROR;
1028 if (scsierr || hosterr)
1029 dprintk("\nSCSI command error: SCSI 0x%02x host 0x%04x return %d\n", scsierr, in_error, hosterr);
1031 return (scsierr | (hosterr << 16));
1034 #define wd7000_intr_ack(host) outb (0, host->iobase + ASC_INTR_ACK)
1036 static void wd7000_intr_handle(int irq, void *dev_id, struct pt_regs *regs)
1038 register int flag, icmb, errstatus, icmb_status;
1039 register int host_error, scsi_error;
1040 register Scb *scb; /* for SCSI commands */
1041 register IcbAny *icb; /* for host commands */
1042 register Scsi_Cmnd *SCpnt;
1043 Adapter *host = (Adapter *) dev_id;
1044 Mailbox *icmbs = host->mb.icmb;
1046 host->int_counter++;
1048 dprintk("wd7000_intr_handle: irq = %d, host = 0x%06lx\n", irq, (long) host);
1050 flag = inb(host->iobase + ASC_INTR_STAT);
1052 dprintk("wd7000_intr_handle: intr stat = 0x%02x\n", flag);
1054 if (!(inb(host->iobase + ASC_STAT) & INT_IM)) {
1055 /* NB: these are _very_ possible if IRQ 15 is being used, since
1056 * it's the "garbage collector" on the 2nd 8259 PIC. Specifically,
1057 * any interrupt signal into the 8259 which can't be identified
1058 * comes out as 7 from the 8259, which is 15 to the host. Thus, it
1059 * is a good thing the WD7000 has an interrupt status port, so we
1060 * can sort these out. Otherwise, electrical noise and other such
1061 * problems would be indistinguishable from valid interrupts...
1063 dprintk("wd7000_intr_handle: phantom interrupt...\n");
1064 wd7000_intr_ack(host);
1068 if (flag & MB_INTR) {
1069 /* The interrupt is for a mailbox */
1070 if (!(flag & IMB_INTR)) {
1071 dprintk("wd7000_intr_handle: free outgoing mailbox\n");
1073 * If sleep_on() and the "interrupt on free OGMB" command are
1074 * used in mail_out(), wake_up() should correspondingly be called
1075 * here. For now, we don't need to do anything special.
1077 wd7000_intr_ack(host);
1080 /* The interrupt is for an incoming mailbox */
1081 icmb = flag & MB_MASK;
1082 icmb_status = icmbs[icmb].status;
1083 if (icmb_status & 0x80) { /* unsolicited - result in ICMB */
1084 dprintk("wd7000_intr_handle: unsolicited interrupt 0x%02x\n", icmb_status);
1085 wd7000_intr_ack(host);
1088 /* Aaaargh! (Zaga) */
1089 scb = isa_bus_to_virt(scsi2int((unchar *) icmbs[icmb].scbptr));
1090 icmbs[icmb].status = 0;
1091 if (!(scb->op & ICB_OP_MASK)) { /* an SCB is done */
1093 if (--(SCpnt->SCp.phase) <= 0) { /* all scbs are done */
1094 host_error = scb->vue | (icmb_status << 8);
1095 scsi_error = scb->status;
1096 errstatus = make_code(host_error, scsi_error);
1097 SCpnt->result = errstatus;
1101 SCpnt->scsi_done(SCpnt);
1103 } else { /* an ICB is done */
1104 icb = (IcbAny *) scb;
1105 icb->status = icmb_status;
1108 } /* incoming mailbox */
1111 wd7000_intr_ack(host);
1113 dprintk("wd7000_intr_handle: return from interrupt handler\n");
1116 static irqreturn_t do_wd7000_intr_handle(int irq, void *dev_id,
1117 struct pt_regs *regs)
1119 unsigned long flags;
1120 struct Scsi_Host *host = dev_id;
1122 spin_lock_irqsave(host->host_lock, flags);
1123 wd7000_intr_handle(irq, dev_id, regs);
1124 spin_unlock_irqrestore(host->host_lock, flags);
1129 static int wd7000_queuecommand(Scsi_Cmnd * SCpnt, void (*done) (Scsi_Cmnd *))
1133 register unchar *cdb = (unchar *) SCpnt->cmnd;
1134 register unchar idlun;
1135 register short cdblen;
1136 Adapter *host = (Adapter *) SCpnt->device->host->hostdata;
1138 cdblen = SCpnt->cmd_len;
1139 idlun = ((SCpnt->device->id << 5) & 0xe0) | (SCpnt->device->lun & 7);
1140 SCpnt->scsi_done = done;
1141 SCpnt->SCp.phase = 1;
1142 scb = alloc_scbs(SCpnt->device->host, 1);
1144 memcpy(scb->cdb, cdb, cdblen);
1145 scb->direc = 0x40; /* Disable direction check */
1147 scb->SCpnt = SCpnt; /* so we can find stuff later */
1148 SCpnt->host_scribble = (unchar *) scb;
1151 if (SCpnt->use_sg) {
1152 struct scatterlist *sg = (struct scatterlist *) SCpnt->request_buffer;
1155 if (SCpnt->device->host->sg_tablesize == SG_NONE) {
1156 panic("wd7000_queuecommand: scatter/gather not supported.\n");
1158 dprintk("Using scatter/gather with %d elements.\n", SCpnt->use_sg);
1162 any2scsi(scb->dataptr, (int) sgb);
1163 any2scsi(scb->maxlen, SCpnt->use_sg * sizeof(Sgb));
1165 for (i = 0; i < SCpnt->use_sg; i++) {
1166 any2scsi(sgb[i].ptr, isa_page_to_bus(sg[i].page) + sg[i].offset);
1167 any2scsi(sgb[i].len, sg[i].length);
1171 any2scsi(scb->dataptr, isa_virt_to_bus(SCpnt->request_buffer));
1172 any2scsi(scb->maxlen, SCpnt->request_bufflen);
1175 /* FIXME: drop lock and yield here ? */
1177 while (!mail_out(host, scb))
1178 cpu_relax(); /* keep trying */
1183 static int wd7000_diagnostics(Adapter * host, int code)
1185 static IcbDiag icb = { ICB_OP_DIAGNOSTICS };
1186 static unchar buf[256];
1187 unsigned long timeout;
1190 any2scsi(icb.len, sizeof(buf));
1191 any2scsi(icb.ptr, (int) &buf);
1194 * This routine is only called at init, so there should be OGMBs
1195 * available. I'm assuming so here. If this is going to
1196 * fail, I can just let the timeout catch the failure.
1198 mail_out(host, (struct scb *) &icb);
1199 timeout = jiffies + WAITnexttimeout; /* wait up to 2 seconds */
1200 while (icb.phase && time_before(jiffies, timeout)) {
1201 cpu_relax(); /* wait for completion */
1206 printk("wd7000_diagnostics: timed out.\n");
1209 if (make_code(icb.vue | (icb.status << 8), 0)) {
1210 printk("wd7000_diagnostics: failed (0x%02x,0x%02x)\n", icb.vue, icb.status);
1218 static int wd7000_adapter_reset(Adapter * host)
1220 InitCmd init_cmd = {
1232 * Reset the adapter - only. The SCSI bus was initialized at power-up,
1233 * and we need to do this just so we control the mailboxes, etc.
1235 outb(ASC_RES, host->iobase + ASC_CONTROL);
1236 udelay(40); /* reset pulse: this is 40us, only need 25us */
1237 outb(0, host->iobase + ASC_CONTROL);
1238 host->control = 0; /* this must always shadow ASC_CONTROL */
1240 if (WAIT(host->iobase + ASC_STAT, ASC_STATMASK, CMD_RDY, 0)) {
1241 printk(KERN_ERR "wd7000_init: WAIT timed out.\n");
1242 return -1; /* -1 = not ok */
1245 if ((diag = inb(host->iobase + ASC_INTR_STAT)) != 1) {
1246 printk("wd7000_init: ");
1250 printk(KERN_ERR "RAM failure.\n");
1253 printk(KERN_ERR "FIFO R/W failed\n");
1256 printk(KERN_ERR "SBIC register R/W failed\n");
1259 printk(KERN_ERR "Initialization D-FF failed.\n");
1262 printk(KERN_ERR "Host IRQ D-FF failed.\n");
1265 printk(KERN_ERR "ROM checksum error.\n");
1268 printk(KERN_ERR "diagnostic code 0x%02Xh received.\n", diag);
1272 /* Clear mailboxes */
1273 memset(&(host->mb), 0, sizeof(host->mb));
1275 /* Execute init command */
1276 any2scsi((unchar *) & (init_cmd.mailboxes), (int) &(host->mb));
1277 if (!command_out(host, (unchar *) & init_cmd, sizeof(init_cmd))) {
1278 printk(KERN_ERR "wd7000_adapter_reset: adapter initialization failed.\n");
1282 if (WAIT(host->iobase + ASC_STAT, ASC_STATMASK, ASC_INIT, 0)) {
1283 printk("wd7000_adapter_reset: WAIT timed out.\n");
1289 static int wd7000_init(Adapter * host)
1291 if (wd7000_adapter_reset(host) == -1)
1295 if (request_irq(host->irq, do_wd7000_intr_handle, SA_INTERRUPT, "wd7000", host)) {
1296 printk("wd7000_init: can't get IRQ %d.\n", host->irq);
1299 if (request_dma(host->dma, "wd7000")) {
1300 printk("wd7000_init: can't get DMA channel %d.\n", host->dma);
1301 free_irq(host->irq, host);
1304 wd7000_enable_dma(host);
1305 wd7000_enable_intr(host);
1307 if (!wd7000_diagnostics(host, ICB_DIAG_FULL)) {
1308 free_dma(host->dma);
1309 free_irq(host->irq, NULL);
1317 static void wd7000_revision(Adapter * host)
1319 static IcbRevLvl icb = { ICB_OP_GET_REVISION };
1323 * Like diagnostics, this is only done at init time, in fact, from
1324 * wd7000_detect, so there should be OGMBs available. If it fails,
1325 * the only damage will be that the revision will show up as 0.0,
1326 * which in turn means that scatter/gather will be disabled.
1328 mail_out(host, (struct scb *) &icb);
1330 cpu_relax(); /* wait for completion */
1333 host->rev1 = icb.primary;
1334 host->rev2 = icb.secondary;
1339 #define SPRINTF(args...) { if (pos < (buffer + length)) pos += sprintf (pos, ## args); }
1341 static int wd7000_set_info(char *buffer, int length, struct Scsi_Host *host)
1343 dprintk("Buffer = <%.*s>, length = %d\n", length, buffer, length);
1346 * Currently this is a no-op
1348 dprintk("Sorry, this function is currently out of order...\n");
1353 static int wd7000_proc_info(struct Scsi_Host *host, char *buffer, char **start, off_t offset, int length, int inout)
1355 Adapter *adapter = (Adapter *)host->hostdata;
1356 unsigned long flags;
1359 Mailbox *ogmbs, *icmbs;
1364 * Has data been written to the file ?
1367 return (wd7000_set_info(buffer, length, host));
1369 spin_lock_irqsave(host->host_lock, flags);
1370 SPRINTF("Host scsi%d: Western Digital WD-7000 (rev %d.%d)\n", host->host_no, adapter->rev1, adapter->rev2);
1371 SPRINTF(" IO base: 0x%x\n", adapter->iobase);
1372 SPRINTF(" IRQ: %d\n", adapter->irq);
1373 SPRINTF(" DMA channel: %d\n", adapter->dma);
1374 SPRINTF(" Interrupts: %d\n", adapter->int_counter);
1375 SPRINTF(" BUS_ON time: %d nanoseconds\n", adapter->bus_on * 125);
1376 SPRINTF(" BUS_OFF time: %d nanoseconds\n", adapter->bus_off * 125);
1379 ogmbs = adapter->mb.ogmb;
1380 icmbs = adapter->mb.icmb;
1382 SPRINTF("\nControl port value: 0x%x\n", adapter->control);
1383 SPRINTF("Incoming mailbox:\n");
1384 SPRINTF(" size: %d\n", ICMB_CNT);
1385 SPRINTF(" queued messages: ");
1387 for (i = count = 0; i < ICMB_CNT; i++)
1388 if (icmbs[i].status) {
1390 SPRINTF("0x%x ", i);
1393 SPRINTF(count ? "\n" : "none\n");
1395 SPRINTF("Outgoing mailbox:\n");
1396 SPRINTF(" size: %d\n", OGMB_CNT);
1397 SPRINTF(" next message: 0x%x\n", adapter->next_ogmb);
1398 SPRINTF(" queued messages: ");
1400 for (i = count = 0; i < OGMB_CNT; i++)
1401 if (ogmbs[i].status) {
1403 SPRINTF("0x%x ", i);
1406 SPRINTF(count ? "\n" : "none\n");
1409 spin_unlock_irqrestore(host->host_lock, flags);
1412 * Calculate start of next buffer, and return value.
1414 *start = buffer + offset;
1416 if ((pos - buffer) < offset)
1418 else if ((pos - buffer - offset) < length)
1419 return (pos - buffer - offset);
1426 * Returns the number of adapters this driver is supporting.
1428 * The source for hosts.c says to wait to call scsi_register until 100%
1429 * sure about an adapter. We need to do it a little sooner here; we
1430 * need the storage set up by scsi_register before wd7000_init, and
1431 * changing the location of an Adapter structure is more trouble than
1432 * calling scsi_unregister.
1436 static int wd7000_detect(Scsi_Host_Template * tpnt)
1438 short present = 0, biosaddr_ptr, sig_ptr, i, pass;
1439 short biosptr[NUM_CONFIGS];
1441 Adapter *host = NULL;
1442 struct Scsi_Host *sh;
1445 dprintk("wd7000_detect: started\n");
1449 wd7000_setup(wd7000);
1452 for (i = 0; i < UNITS; wd7000_host[i++] = NULL);
1453 for (i = 0; i < NUM_CONFIGS; biosptr[i++] = -1);
1455 tpnt->proc_name = "wd7000";
1456 tpnt->proc_info = &wd7000_proc_info;
1459 * Set up SCB free list, which is shared by all adapters
1463 for (pass = 0; pass < NUM_CONFIGS; pass++) {
1465 * First, search for BIOS SIGNATURE...
1467 for (biosaddr_ptr = 0; biosaddr_ptr < NUM_ADDRS; biosaddr_ptr++)
1468 for (sig_ptr = 0; sig_ptr < NUM_SIGNATURES; sig_ptr++) {
1469 for (i = 0; i < pass; i++)
1470 if (biosptr[i] == biosaddr_ptr)
1474 void *biosaddr = ioremap(wd7000_biosaddr[biosaddr_ptr] + signatures[sig_ptr].ofs,
1475 signatures[sig_ptr].len);
1476 short bios_match = 0;
1479 bios_match = memcmp((char *) biosaddr, signatures[sig_ptr].sig, signatures[sig_ptr].len);
1490 * BIOS SIGNATURE has been found.
1493 dprintk("wd7000_detect: pass %d\n", pass + 1);
1495 if (biosaddr_ptr == NUM_ADDRS)
1496 dprintk("WD-7000 SST BIOS not detected...\n");
1498 dprintk("WD-7000 SST BIOS detected at 0x%lx: checking...\n", wd7000_biosaddr[biosaddr_ptr]);
1501 if (configs[pass].irq < 0)
1507 iobase = configs[pass].iobase;
1509 dprintk("wd7000_detect: check IO 0x%x region...\n", iobase);
1511 if (request_region(iobase, 4, "wd7000")) {
1513 dprintk("wd7000_detect: ASC reset (IO 0x%x) ...", iobase);
1517 outb(ASC_RES, iobase + ASC_CONTROL);
1518 set_current_state(TASK_UNINTERRUPTIBLE);
1519 schedule_timeout(HZ / 100);
1520 outb(0, iobase + ASC_CONTROL);
1522 if (WAIT(iobase + ASC_STAT, ASC_STATMASK, CMD_RDY, 0)) {
1523 dprintk("failed!\n");
1528 if (inb(iobase + ASC_INTR_STAT) == 1) {
1530 * We register here, to get a pointer to the extra space,
1531 * which we'll use as the Adapter structure (host) for
1532 * this adapter. It is located just after the registered
1533 * Scsi_Host structure (sh), and is located by the empty
1536 sh = scsi_register(tpnt, sizeof(Adapter));
1540 host = (Adapter *) sh->hostdata;
1542 dprintk("wd7000_detect: adapter allocated at 0x%x\n", (int) host);
1543 memset(host, 0, sizeof(Adapter));
1545 host->irq = configs[pass].irq;
1546 host->dma = configs[pass].dma;
1547 host->iobase = iobase;
1548 host->int_counter = 0;
1549 host->bus_on = configs[pass].bus_on;
1550 host->bus_off = configs[pass].bus_off;
1551 host->sh = wd7000_host[unit] = sh;
1554 dprintk("wd7000_detect: Trying init WD-7000 card at IO " "0x%x, IRQ %d, DMA %d...\n", host->iobase, host->irq, host->dma);
1556 if (!wd7000_init(host)) /* Initialization failed */
1557 goto err_unregister;
1560 * OK from here - we'll use this adapter/configuration.
1562 wd7000_revision(host); /* important for scatter/gather */
1565 * For boards before rev 6.0, scatter/gather isn't supported.
1568 sh->sg_tablesize = SG_NONE;
1570 present++; /* count it */
1572 if (biosaddr_ptr != NUM_ADDRS)
1573 biosptr[pass] = biosaddr_ptr;
1575 printk(KERN_INFO "Western Digital WD-7000 (rev %d.%d) ", host->rev1, host->rev2);
1576 printk("using IO 0x%x, IRQ %d, DMA %d.\n", host->iobase, host->irq, host->dma);
1577 printk(" BUS_ON time: %dns, BUS_OFF time: %dns\n", host->bus_on * 125, host->bus_off * 125);
1580 dprintk("wd7000_detect: IO 0x%x region already allocated!\n", iobase);
1585 scsi_unregister(sh);
1587 release_region(iobase, 4);
1592 printk("Failed initialization of WD-7000 SCSI card!\n");
1597 static int wd7000_release(struct Scsi_Host *shost)
1600 free_irq(shost->irq, NULL);
1601 if (shost->io_port && shost->n_io_port)
1602 release_region(shost->io_port, shost->n_io_port);
1603 scsi_unregister(shost);
1608 * I have absolutely NO idea how to do an abort with the WD7000...
1610 static int wd7000_abort(Scsi_Cmnd * SCpnt)
1612 Adapter *host = (Adapter *) SCpnt->device->host->hostdata;
1614 if (inb(host->iobase + ASC_STAT) & INT_IM) {
1615 printk("wd7000_abort: lost interrupt\n");
1616 wd7000_intr_handle(host->irq, NULL, NULL);
1624 * I also have no idea how to do a reset...
1627 static int wd7000_bus_reset(Scsi_Cmnd * SCpnt)
1632 static int wd7000_device_reset(Scsi_Cmnd * SCpnt)
1638 * Last resort. Reinitialize the board.
1641 static int wd7000_host_reset(Scsi_Cmnd * SCpnt)
1643 Adapter *host = (Adapter *) SCpnt->device->host->hostdata;
1645 if (wd7000_adapter_reset(host) < 0)
1647 wd7000_enable_intr(host);
1653 * This was borrowed directly from aha1542.c. (Zaga)
1656 static int wd7000_biosparam(struct scsi_device *sdev,
1657 struct block_device *bdev, sector_t capacity, int *ip)
1659 char b[BDEVNAME_SIZE];
1661 dprintk("wd7000_biosparam: dev=%s, size=%d, ",
1662 bdevname(bdev, b), capacity);
1663 (void)b; /* unused var warning? */
1666 * try default translation
1670 ip[2] = capacity >> 11;
1673 * for disks >1GB do some guessing
1675 if (ip[2] >= 1024) {
1679 * try to figure out the geometry from the partition table
1681 if ((scsicam_bios_param(bdev, capacity, info) < 0) || !(((info[0] == 64) && (info[1] == 32)) || ((info[0] == 255) && (info[1] == 63)))) {
1682 printk("wd7000_biosparam: unable to verify geometry for disk with >1GB.\n" " using extended translation.\n");
1686 ip[2] = (unsigned long) capacity / (255 * 63);
1693 printk(KERN_INFO "%s: current partition table is " "using extended translation.\n", __FUNCTION__);
1697 dprintk("bios geometry: head=%d, sec=%d, cyl=%d\n", ip[0], ip[1], ip[2]);
1698 dprintk("WARNING: check, if the bios geometry is correct.\n");
1703 MODULE_AUTHOR("Thomas Wuensche, John Boyd, Miroslav Zagorac");
1704 MODULE_DESCRIPTION("Driver for the WD7000 series ISA controllers");
1705 MODULE_LICENSE("GPL");
1707 static Scsi_Host_Template driver_template = {
1708 .proc_name = "wd7000",
1709 .proc_info = wd7000_proc_info,
1710 .name = "Western Digital WD-7000",
1711 .detect = wd7000_detect,
1712 .release = wd7000_release,
1713 .queuecommand = wd7000_queuecommand,
1714 .eh_bus_reset_handler = wd7000_bus_reset,
1715 .eh_device_reset_handler = wd7000_device_reset,
1716 .eh_host_reset_handler = wd7000_host_reset,
1717 .bios_param = wd7000_biosparam,
1718 .can_queue = WD7000_Q,
1720 .sg_tablesize = WD7000_SG,
1722 .unchecked_isa_dma = 1,
1723 .use_clustering = ENABLE_CLUSTERING,
1726 #include "scsi_module.c"