1 /* $Id: wd7000.c,v 1.1.1.1 2005/04/11 02:50:37 jack Exp $
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 #include <linux/module.h>
148 #include <linux/kernel.h>
149 #include <linux/types.h>
150 #include <linux/string.h>
151 #include <linux/sched.h>
152 #include <linux/slab.h>
153 #include <linux/spinlock.h>
154 #include <asm/system.h>
157 #include <linux/ioport.h>
158 #include <linux/proc_fs.h>
159 #include <linux/blk.h>
160 #include <linux/version.h>
161 #include <linux/init.h>
165 #include <scsi/scsicam.h>
167 #define ANY2SCSI_INLINE /* undef this to use old macros */
168 #undef WD7000_DEBUG /* general debug */
171 #include <linux/stat.h>
174 * Mailbox structure sizes.
175 * I prefer to keep the number of ICMBs much larger than the number of
176 * OGMBs. OGMBs are used very quickly by the driver to start one or
177 * more commands, while ICMBs are used by the host adapter per command.
183 * Scb's are shared by all active adapters. So, if they all become busy,
184 * callers may be made to wait in alloc_scbs for them to free. That can
185 * be avoided by setting MAX_SCBS to NUM_CONFIG * WD7000_Q. If you'd
186 * rather conserve memory, use a smaller number (> 0, of course) - things
187 * will should still work OK.
192 * WD7000-specific mailbox structure
195 typedef volatile struct mailbox {
197 unchar scbptr[3]; /* SCSI-style - MSB first (big endian) */
201 * This structure should contain all per-adapter global data. I.e., any
202 * new global per-adapter data should put in here.
204 typedef struct adapter {
205 struct Scsi_Host *sh; /* Pointer to Scsi_Host structure */
206 int iobase; /* This adapter's I/O base address */
207 int irq; /* This adapter's IRQ level */
208 int dma; /* This adapter's DMA channel */
209 int int_counter; /* This adapter's interrupt counter */
210 int bus_on; /* This adapter's BUS_ON time */
211 int bus_off; /* This adapter's BUS_OFF time */
212 struct { /* This adapter's mailboxes */
213 Mailbox ogmb[OGMB_CNT]; /* Outgoing mailboxes */
214 Mailbox icmb[ICMB_CNT]; /* Incoming mailboxes */
216 int next_ogmb; /* to reduce contention at mailboxes */
217 unchar control; /* shadows CONTROL port value */
218 unchar rev1, rev2; /* filled in by wd7000_revision */
222 * (linear) base address for ROM BIOS
224 static const long wd7000_biosaddr[] =
226 0xc0000, 0xc2000, 0xc4000, 0xc6000, 0xc8000, 0xca000, 0xcc000, 0xce000,
227 0xd0000, 0xd2000, 0xd4000, 0xd6000, 0xd8000, 0xda000, 0xdc000, 0xde000
229 #define NUM_ADDRS (sizeof(wd7000_biosaddr)/sizeof(long))
231 static const unsigned short wd7000_iobase[] =
233 0x0300, 0x0308, 0x0310, 0x0318, 0x0320, 0x0328, 0x0330, 0x0338,
234 0x0340, 0x0348, 0x0350, 0x0358, 0x0360, 0x0368, 0x0370, 0x0378,
235 0x0380, 0x0388, 0x0390, 0x0398, 0x03a0, 0x03a8, 0x03b0, 0x03b8,
236 0x03c0, 0x03c8, 0x03d0, 0x03d8, 0x03e0, 0x03e8, 0x03f0, 0x03f8
238 #define NUM_IOPORTS (sizeof(wd7000_iobase)/sizeof(unsigned short))
240 static const short wd7000_irq[] = { 3, 4, 5, 7, 9, 10, 11, 12, 14, 15 };
241 #define NUM_IRQS (sizeof(wd7000_irq)/sizeof(short))
243 static const short wd7000_dma[] = { 5, 6, 7 };
244 #define NUM_DMAS (sizeof(wd7000_dma)/sizeof(short))
251 #define IRQS (IRQ_MAX - IRQ_MIN + 1)
254 * The following is set up by wd7000_detect, and used thereafter by
255 * wd7000_intr_handle to map the irq level to the corresponding Adapter.
256 * Note that if SA_INTERRUPT is not used, wd7000_intr_handle must be
257 * changed to pick up the IRQ level correctly.
259 static struct Scsi_Host *wd7000_host[IRQS];
261 #define BUS_ON 64 /* x 125ns = 8000ns (BIOS default) */
262 #define BUS_OFF 15 /* x 125ns = 1875ns (BIOS default) */
265 * Standard Adapter Configurations - used by wd7000_detect
268 short irq; /* IRQ level */
269 short dma; /* DMA channel */
270 unsigned iobase; /* I/O base address */
271 short bus_on; /* Time that WD7000 spends on the AT-bus when */
272 /* transferring data. BIOS default is 8000ns. */
273 short bus_off; /* Time that WD7000 spends OFF THE BUS after */
274 /* while it is transferring data. */
275 /* BIOS default is 1875ns */
279 * Add here your configuration...
281 static Config configs[] =
283 { 15, 6, 0x350, BUS_ON, BUS_OFF }, /* defaults for single adapter */
284 { 11, 5, 0x320, BUS_ON, BUS_OFF }, /* defaults for second adapter */
285 { 7, 6, 0x350, BUS_ON, BUS_OFF }, /* My configuration (Zaga) */
286 { -1, -1, 0x0, BUS_ON, BUS_OFF } /* Empty slot */
288 #define NUM_CONFIGS (sizeof(configs)/sizeof(Config))
291 * The following list defines strings to look for in the BIOS that identify
292 * it as the WD7000-FASST2 SST BIOS. I suspect that something should be
293 * added for the Future Domain version.
295 typedef struct signature {
296 const char *sig; /* String to look for */
297 unsigned long ofs; /* offset from BIOS base address */
298 unsigned len; /* length of string */
301 static const Signature signatures[] =
303 {"SSTBIOS", 0x0000d, 7} /* "SSTBIOS" @ offset 0x0000d */
305 #define NUM_SIGNATURES (sizeof(signatures)/sizeof(Signature))
309 * I/O Port Offsets and Bit Definitions
310 * 4 addresses are used. Those not defined here are reserved.
312 #define ASC_STAT 0 /* Status, Read */
313 #define ASC_COMMAND 0 /* Command, Write */
314 #define ASC_INTR_STAT 1 /* Interrupt Status, Read */
315 #define ASC_INTR_ACK 1 /* Acknowledge, Write */
316 #define ASC_CONTROL 2 /* Control, Write */
321 #define INT_IM 0x80 /* Interrupt Image Flag */
322 #define CMD_RDY 0x40 /* Command Port Ready */
323 #define CMD_REJ 0x20 /* Command Port Byte Rejected */
324 #define ASC_INIT 0x10 /* ASC Initialized Flag */
325 #define ASC_STATMASK 0xf0 /* The lower 4 Bytes are reserved */
330 * Unfortunately, I have no idea how to properly use some of these commands,
331 * as the OEM manual does not make it clear. I have not been able to use
332 * enable/disable unsolicited interrupts or the reset commands with any
333 * discernible effect whatsoever. I think they may be related to certain
334 * ICB commands, but again, the OEM manual doesn't make that clear.
336 #define NO_OP 0 /* NO-OP toggles CMD_RDY bit in ASC_STAT */
337 #define INITIALIZATION 1 /* initialization (10 bytes) */
338 #define DISABLE_UNS_INTR 2 /* disable unsolicited interrupts */
339 #define ENABLE_UNS_INTR 3 /* enable unsolicited interrupts */
340 #define INTR_ON_FREE_OGMB 4 /* interrupt on free OGMB */
341 #define SOFT_RESET 5 /* SCSI bus soft reset */
342 #define HARD_RESET_ACK 6 /* SCSI bus hard reset acknowledge */
343 #define START_OGMB 0x80 /* start command in OGMB (n) */
344 #define SCAN_OGMBS 0xc0 /* start multiple commands, signature (n) */
345 /* where (n) = lower 6 bits */
347 * For INITIALIZATION:
349 typedef struct initCmd {
350 unchar op; /* command opcode (= 1) */
351 unchar ID; /* Adapter's SCSI ID */
352 unchar bus_on; /* Bus on time, x 125ns (see below) */
353 unchar bus_off; /* Bus off time, "" "" */
354 unchar rsvd; /* Reserved */
355 unchar mailboxes[3]; /* Address of Mailboxes, MSB first */
356 unchar ogmbs; /* Number of outgoing MBs, max 64, 0,1 = 1 */
357 unchar icmbs; /* Number of incoming MBs, "" "" */
361 * Interrupt Status Port - also returns diagnostic codes at ASC reset
363 * if msb is zero, the lower bits are diagnostic status
365 * 01 No diagnostic error occurred
368 * 04 SBIC register read/write failed
369 * 05 Initialization D-FF failed
370 * 06 Host IRQ D-FF failed
371 * 07 ROM checksum error
372 * Interrupt status (bitwise):
373 * 10NNNNNN outgoing mailbox NNNNNN is free
374 * 11NNNNNN incoming mailbox NNNNNN needs service
376 #define MB_INTR 0xC0 /* Mailbox Service possible/required */
377 #define IMB_INTR 0x40 /* 1 Incoming / 0 Outgoing */
378 #define MB_MASK 0x3f /* mask for mailbox number */
383 #define INT_EN 0x08 /* Interrupt Enable */
384 #define DMA_EN 0x04 /* DMA Enable */
385 #define SCSI_RES 0x02 /* SCSI Reset */
386 #define ASC_RES 0x01 /* ASC Reset */
389 * Driver data structures:
390 * - mb and scbs are required for interfacing with the host adapter.
391 * An SCB has extra fields not visible to the adapter; mb's
392 * _cannot_ do this, since the adapter assumes they are contiguous in
393 * memory, 4 bytes each, with ICMBs following OGMBs, and uses this fact
395 * - An icb is for host-only (non-SCSI) commands. ICBs are 16 bytes each;
396 * the additional bytes are used only by the driver.
397 * - For now, a pool of SCBs are kept in global storage by this driver,
398 * and are allocated and freed as needed.
400 * The 7000-FASST2 marks OGMBs empty as soon as it has _started_ a command,
401 * not when it has finished. Since the SCB must be around for completion,
402 * problems arise when SCBs correspond to OGMBs, which may be reallocated
403 * earlier (or delayed unnecessarily until a command completes).
404 * Mailboxes are used as transient data structures, simply for
405 * carrying SCB addresses to/from the 7000-FASST2.
407 * Note also since SCBs are not "permanently" associated with mailboxes,
408 * there is no need to keep a global list of Scsi_Cmnd pointers indexed
409 * by OGMB. Again, SCBs reference their Scsi_Cmnds directly, so mailbox
410 * indices need not be involved.
414 * WD7000-specific scatter/gather element structure
418 unchar ptr[3]; /* Also SCSI-style - MSB first */
421 typedef struct scb { /* Command Control Block 5.4.1 */
422 unchar op; /* Command Control Block Operation Code */
423 unchar idlun; /* op=0,2:Target Id, op=1:Initiator Id */
424 /* Outbound data transfer, length is checked */
425 /* Inbound data transfer, length is checked */
426 /* Logical Unit Number */
427 unchar cdb[12]; /* SCSI Command Block */
428 volatile unchar status; /* SCSI Return Status */
429 volatile unchar vue; /* Vendor Unique Error Code */
430 unchar maxlen[3]; /* Maximum Data Transfer Length */
431 unchar dataptr[3]; /* SCSI Data Block Pointer */
432 unchar linkptr[3]; /* Next Command Link Pointer */
433 unchar direc; /* Transfer Direction */
434 unchar reserved2[6]; /* SCSI Command Descriptor Block */
435 /* end of hardware SCB */
436 Scsi_Cmnd *SCpnt; /* Scsi_Cmnd using this SCB */
437 Sgb sgb[WD7000_SG]; /* Scatter/gather list for this SCB */
438 Adapter *host; /* host adapter */
439 struct scb *next; /* for lists of scbs */
443 * This driver is written to allow host-only commands to be executed.
444 * These use a 16-byte block called an ICB. The format is extended by the
445 * driver to 18 bytes, to support the status returned in the ICMB and
446 * an execution phase code.
448 * There are other formats besides these; these are the ones I've tried
449 * to use. Formats for some of the defined ICB opcodes are not defined
450 * (notably, get/set unsolicited interrupt status) in my copy of the OEM
451 * manual, and others are ambiguous/hard to follow.
453 #define ICB_OP_MASK 0x80 /* distinguishes scbs from icbs */
454 #define ICB_OP_OPEN_RBUF 0x80 /* open receive buffer */
455 #define ICB_OP_RECV_CMD 0x81 /* receive command from initiator */
456 #define ICB_OP_RECV_DATA 0x82 /* receive data from initiator */
457 #define ICB_OP_RECV_SDATA 0x83 /* receive data with status from init. */
458 #define ICB_OP_SEND_DATA 0x84 /* send data with status to initiator */
459 #define ICB_OP_SEND_STAT 0x86 /* send command status to initiator */
460 /* 0x87 is reserved */
461 #define ICB_OP_READ_INIT 0x88 /* read initialization bytes */
462 #define ICB_OP_READ_ID 0x89 /* read adapter's SCSI ID */
463 #define ICB_OP_SET_UMASK 0x8A /* set unsolicited interrupt mask */
464 #define ICB_OP_GET_UMASK 0x8B /* read unsolicited interrupt mask */
465 #define ICB_OP_GET_REVISION 0x8C /* read firmware revision level */
466 #define ICB_OP_DIAGNOSTICS 0x8D /* execute diagnostics */
467 #define ICB_OP_SET_EPARMS 0x8E /* set execution parameters */
468 #define ICB_OP_GET_EPARMS 0x8F /* read execution parameters */
470 typedef struct icbRecvCmd {
472 unchar IDlun; /* Initiator SCSI ID/lun */
473 unchar len[3]; /* command buffer length */
474 unchar ptr[3]; /* command buffer address */
475 unchar rsvd[7]; /* reserved */
476 volatile unchar vue; /* vendor-unique error code */
477 volatile unchar status; /* returned (icmb) status */
478 volatile unchar phase; /* used by interrupt handler */
481 typedef struct icbSendStat {
483 unchar IDlun; /* Target SCSI ID/lun */
484 unchar stat; /* (outgoing) completion status byte 1 */
485 unchar rsvd[12]; /* reserved */
486 volatile unchar vue; /* vendor-unique error code */
487 volatile unchar status; /* returned (icmb) status */
488 volatile unchar phase; /* used by interrupt handler */
491 typedef struct icbRevLvl {
493 volatile unchar primary; /* primary revision level (returned) */
494 volatile unchar secondary; /* secondary revision level (returned) */
495 unchar rsvd[12]; /* reserved */
496 volatile unchar vue; /* vendor-unique error code */
497 volatile unchar status; /* returned (icmb) status */
498 volatile unchar phase; /* used by interrupt handler */
501 typedef struct icbUnsMask { /* I'm totally guessing here */
503 volatile unchar mask[14]; /* mask bits */
505 unchar rsvd[12]; /* reserved */
507 volatile unchar vue; /* vendor-unique error code */
508 volatile unchar status; /* returned (icmb) status */
509 volatile unchar phase; /* used by interrupt handler */
512 typedef struct icbDiag {
514 unchar type; /* diagnostics type code (0-3) */
515 unchar len[3]; /* buffer length */
516 unchar ptr[3]; /* buffer address */
517 unchar rsvd[7]; /* reserved */
518 volatile unchar vue; /* vendor-unique error code */
519 volatile unchar status; /* returned (icmb) status */
520 volatile unchar phase; /* used by interrupt handler */
523 #define ICB_DIAG_POWERUP 0 /* Power-up diags only */
524 #define ICB_DIAG_WALKING 1 /* walking 1's pattern */
525 #define ICB_DIAG_DMA 2 /* DMA - system memory diags */
526 #define ICB_DIAG_FULL 3 /* do both 1 & 2 */
528 typedef struct icbParms {
530 unchar rsvd1; /* reserved */
531 unchar len[3]; /* parms buffer length */
532 unchar ptr[3]; /* parms buffer address */
533 unchar idx[2]; /* index (MSB-LSB) */
534 unchar rsvd2[5]; /* reserved */
535 volatile unchar vue; /* vendor-unique error code */
536 volatile unchar status; /* returned (icmb) status */
537 volatile unchar phase; /* used by interrupt handler */
540 typedef struct icbAny {
542 unchar data[14]; /* format-specific data */
543 volatile unchar vue; /* vendor-unique error code */
544 volatile unchar status; /* returned (icmb) status */
545 volatile unchar phase; /* used by interrupt handler */
549 unchar op; /* ICB opcode */
550 IcbRecvCmd recv_cmd; /* format for receive command */
551 IcbSendStat send_stat; /* format for send status */
552 IcbRevLvl rev_lvl; /* format for get revision level */
553 IcbDiag diag; /* format for execute diagnostics */
554 IcbParms eparms; /* format for get/set exec parms */
555 IcbAny icb; /* generic format */
560 static char * wd7000 = NULL;
561 MODULE_PARM(wd7000, "s");
565 * Driver SCB structure pool.
567 * The SCBs declared here are shared by all host adapters; hence, this
568 * structure is not part of the Adapter structure.
570 static Scb scbs[MAX_SCBS];
571 static Scb *scbfree = NULL; /* free list */
572 static int freescbs = MAX_SCBS; /* free list counter */
575 * END of data/declarations - code follows.
577 static void setup_error (char *mesg, int *ints)
580 printk ("wd7000_setup: \"wd7000=%d,%d,0x%x\" -> %s\n",
581 ints[1], ints[2], ints[3], mesg);
582 else if (ints[0] == 4)
583 printk ("wd7000_setup: \"wd7000=%d,%d,0x%x,%d\" -> %s\n",
584 ints[1], ints[2], ints[3], ints[4], mesg);
586 printk ("wd7000_setup: \"wd7000=%d,%d,0x%x,%d,%d\" -> %s\n",
587 ints[1], ints[2], ints[3], ints[4], ints[5], mesg);
592 * Note: You can now set these options from the kernel's "command line".
595 * wd7000=<IRQ>,<DMA>,<IO>[,<BUS_ON>[,<BUS_OFF>]]
597 * , where BUS_ON and BUS_OFF are in nanoseconds. BIOS default values
598 * are 8000ns for BUS_ON and 1875ns for BUS_OFF.
602 * will configure the driver for a WD-7000 controller
603 * using IRQ 15 with a DMA channel 6, at IO base address 0x350.
605 static int __init wd7000_setup(char *str)
607 static short wd7000_card_num = 0;
611 (void)get_options(str, ARRAY_SIZE(ints), ints);
613 if (wd7000_card_num >= NUM_CONFIGS) {
614 printk("wd7000_setup: Too many \"wd7000=\" configurations in "
619 if ((ints[0] < 3) || (ints[0] > 5)) {
620 printk("wd7000_setup: Error in command line! "
621 "Usage: wd7000=<IRQ>,<DMA>,IO>[,<BUS_ON>[,<BUS_OFF>]]\n");
623 for (i = 0; i < NUM_IRQS; i++)
624 if (ints[1] == wd7000_irq[i])
628 setup_error("invalid IRQ.", ints);
631 configs[wd7000_card_num].irq = ints[1];
633 for (i = 0; i < NUM_DMAS; i++)
634 if (ints[2] == wd7000_dma[i])
638 setup_error("invalid DMA channel.", ints);
641 configs[wd7000_card_num].dma = ints[2];
643 for (i = 0; i < NUM_IOPORTS; i++)
644 if (ints[3] == wd7000_iobase[i])
647 if (i == NUM_IOPORTS) {
648 setup_error("invalid I/O base address.", ints);
651 configs[wd7000_card_num].iobase = ints[3];
654 if ((ints[4] < 500) || (ints[4] > 31875)) {
655 setup_error("BUS_ON value is out of range (500 to 31875 nanoseconds)!", ints);
656 configs[wd7000_card_num].bus_on = BUS_ON;
658 configs[wd7000_card_num].bus_on = ints[4] / 125;
660 configs[wd7000_card_num].bus_on = BUS_ON;
663 if ((ints[5] < 500) || (ints[5] > 31875)) {
664 setup_error("BUS_OFF value is out of range (500 to 31875 nanoseconds)!", ints);
665 configs[wd7000_card_num].bus_off = BUS_OFF;
667 configs[wd7000_card_num].bus_off = ints[5] / 125;
669 configs[wd7000_card_num].bus_off = BUS_OFF;
671 if (wd7000_card_num) {
672 for (i = 0; i < (wd7000_card_num - 1); i++)
673 for (j = i + 1; j < wd7000_card_num; j++)
674 if (configs[i].irq == configs[j].irq) {
675 setup_error("duplicated IRQ!", ints);
677 } else if (configs[i].dma == configs[j].dma) {
678 setup_error("duplicated DMA channel!", ints);
680 } else if (configs[i].iobase == configs[j].iobase) {
681 setup_error ("duplicated I/O base address!", ints);
687 printk ("wd7000_setup: IRQ=%d, DMA=%d, I/O=0x%x, BUS_ON=%dns, BUS_OFF=%dns\n",
688 configs[wd7000_card_num].irq,
689 configs[wd7000_card_num].dma,
690 configs[wd7000_card_num].iobase,
691 configs[wd7000_card_num].bus_on * 125,
692 configs[wd7000_card_num].bus_off * 125);
700 __setup("wd7000=", wd7000_setup);
702 #ifdef ANY2SCSI_INLINE
704 * Since they're used a lot, I've redone the following from the macros
705 * formerly in wd7000.h, hopefully to speed them up by getting rid of
706 * all the shifting (it may not matter; GCC might have done as well anyway).
708 * xany2scsi and xscsi2int were not being used, and are no longer defined.
709 * (They were simply 4-byte versions of these routines).
711 typedef union { /* let's cheat... */
713 unchar u[sizeof (int)]; /* the sizeof(int) makes it more portable */
717 static inline void any2scsi (unchar * scsi, int any)
719 *scsi++ = ((i_u) any).u[2];
720 *scsi++ = ((i_u) any).u[1];
721 *scsi++ = ((i_u) any).u[0];
725 static inline int scsi2int (unchar * scsi)
729 result.i = 0; /* clears unused bytes */
730 result.u[2] = *scsi++;
731 result.u[1] = *scsi++;
732 result.u[0] = *scsi++;
738 * These are the old ones - I've just moved them here...
741 #define any2scsi(up, p) (up)[0] = (((unsigned long) (p)) >> 16); \
742 (up)[1] = ((unsigned long) (p)) >> 8; \
743 (up)[2] = ((unsigned long) (p));
746 #define scsi2int(up) ( (((unsigned long) *(up)) << 16) + \
747 (((unsigned long) (up)[1]) << 8) + \
748 ((unsigned long) (up)[2]) )
752 static inline void wd7000_enable_intr (Adapter *host)
754 host->control |= INT_EN;
755 outb (host->control, host->iobase + ASC_CONTROL);
759 static inline void wd7000_enable_dma (Adapter *host)
762 host->control |= DMA_EN;
763 outb (host->control, host->iobase + ASC_CONTROL);
765 flags = claim_dma_lock();
766 set_dma_mode (host->dma, DMA_MODE_CASCADE);
767 enable_dma (host->dma);
768 release_dma_lock(flags);
773 #define WAITnexttimeout 200 /* 2 seconds */
775 static inline short WAIT (unsigned port, unsigned mask, unsigned allof, unsigned noneof)
777 register unsigned WAITbits;
778 register unsigned long WAITtimeout = jiffies + WAITnexttimeout;
780 while (time_before_eq(jiffies, WAITtimeout)) {
781 WAITbits = inb (port) & mask;
783 if (((WAITbits & allof) == allof) && ((WAITbits & noneof) == 0))
791 static inline void delay (unsigned how_long)
793 register unsigned long time = jiffies + how_long;
795 while (time_before(jiffies, time));
799 static inline int command_out (Adapter * host, unchar * cmd, int len)
801 if (!WAIT (host->iobase + ASC_STAT, ASC_STATMASK, CMD_RDY, 0)) {
804 outb (*cmd, host->iobase + ASC_COMMAND);
805 WAIT (host->iobase + ASC_STAT, ASC_STATMASK, CMD_RDY, 0);
806 } while (inb (host->iobase + ASC_STAT) & CMD_REJ);
814 printk ("wd7000 command_out: WAIT failed(%d)\n", len + 1);
821 * This version of alloc_scbs is in preparation for supporting multiple
822 * commands per lun and command chaining, by queueing pending commands.
823 * We will need to allocate Scbs in blocks since they will wait to be
824 * executed so there is the possibility of deadlock otherwise.
825 * Also, to keep larger requests from being starved by smaller requests,
826 * we limit access to this routine with an internal busy flag, so that
827 * the satisfiability of a request is not dependent on the size of the
830 static inline Scb *alloc_scbs (int needed)
832 register Scb *scb, *p;
833 register unsigned long flags;
834 register unsigned long timeout = jiffies + WAITnexttimeout;
835 register unsigned long now;
840 return (NULL); /* sanity check */
844 while (busy) { /* someone else is allocating */
845 spin_unlock_irq(&io_request_lock);
846 for (now = jiffies; now == jiffies; ); /* wait a jiffy */
847 spin_lock_irq(&io_request_lock);
849 busy = 1; /* not busy now; it's our turn */
851 while (freescbs < needed) {
852 timeout = jiffies + WAITnexttimeout;
854 spin_unlock_irq(&io_request_lock);
855 for (now = jiffies; now == jiffies; ); /* wait a jiffy */
856 spin_lock_irq(&io_request_lock);
857 } while (freescbs < needed && time_before_eq(jiffies, timeout));
859 * If we get here with enough free Scbs, we can take them.
860 * Otherwise, we timed out and didn't get enough.
862 if (freescbs < needed) {
864 printk (KERN_ERR "wd7000: can't get enough free SCBs.\n");
865 restore_flags (flags);
871 for (i = 0; i < needed; i++) {
876 busy = 0; /* we're done */
878 restore_flags (flags);
884 static inline void free_scb (Scb *scb)
886 register unsigned long flags;
891 memset (scb, 0, sizeof (Scb));
896 restore_flags (flags);
900 static inline void init_scbs (void)
908 scbfree = &(scbs[0]);
909 memset (scbs, 0, sizeof (scbs));
910 for (i = 0; i < MAX_SCBS - 1; i++) {
911 scbs[i].next = &(scbs[i + 1]);
912 scbs[i].SCpnt = NULL;
914 scbs[MAX_SCBS - 1].next = NULL;
915 scbs[MAX_SCBS - 1].SCpnt = NULL;
917 restore_flags (flags);
921 static int mail_out (Adapter *host, Scb *scbptr)
923 * Note: this can also be used for ICBs; just cast to the parm type.
926 register int i, ogmb;
927 register unsigned long flags;
929 Mailbox *ogmbs = host->mb.ogmb;
930 int *next_ogmb = &(host->next_ogmb);
933 printk ("wd7000_mail_out: 0x%06lx", (long) scbptr);
936 /* We first look for a free outgoing mailbox */
940 for (i = 0; i < OGMB_CNT; i++) {
941 if (ogmbs[ogmb].status == 0) {
943 printk (" using OGMB 0x%x", ogmb);
945 ogmbs[ogmb].status = 1;
946 any2scsi ((unchar *) ogmbs[ogmb].scbptr, (int) scbptr);
948 *next_ogmb = (ogmb + 1) % OGMB_CNT;
952 ogmb = (ogmb + 1) % OGMB_CNT;
954 restore_flags (flags);
957 printk (", scb is 0x%06lx", (long) scbptr);
962 * Alternatively, we might issue the "interrupt on free OGMB",
963 * and sleep, but it must be ensured that it isn't the init
964 * task running. Instead, this version assumes that the caller
965 * will be persistent, and try again. Since it's the adapter
966 * that marks OGMB's free, waiting even with interrupts off
967 * should work, since they are freed very quickly in most cases.
970 printk (", no free OGMBs.\n");
975 wd7000_enable_intr (host);
977 start_ogmb = START_OGMB | ogmb;
978 command_out (host, &start_ogmb, 1);
981 printk (", awaiting interrupt.\n");
988 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 printk ("\nSCSI command error: SCSI 0x%02x host 0x%04x return %d\n",
1030 scsierr, in_error, hosterr);
1032 return (scsierr | (hosterr << 16));
1036 static void wd7000_scsi_done (Scsi_Cmnd *SCpnt)
1039 printk ("wd7000_scsi_done: 0x%06lx\n", (long) SCpnt);
1042 SCpnt->SCp.phase = 0;
1046 #define wd7000_intr_ack(host) outb (0, host->iobase + ASC_INTR_ACK)
1048 void wd7000_intr_handle (int irq, void *dev_id, struct pt_regs *regs)
1050 register int flag, icmb, errstatus, icmb_status;
1051 register int host_error, scsi_error;
1052 register Scb *scb; /* for SCSI commands */
1053 register IcbAny *icb; /* for host commands */
1054 register Scsi_Cmnd *SCpnt;
1055 Adapter *host = (Adapter *) wd7000_host[irq - IRQ_MIN]->hostdata; /* This MUST be set!!! */
1056 Mailbox *icmbs = host->mb.icmb;
1058 host->int_counter++;
1061 printk ("wd7000_intr_handle: irq = %d, host = 0x%06lx\n", irq, (long) host);
1064 flag = inb (host->iobase + ASC_INTR_STAT);
1067 printk ("wd7000_intr_handle: intr stat = 0x%02x\n", flag);
1070 if (!(inb (host->iobase + ASC_STAT) & INT_IM)) {
1071 /* NB: these are _very_ possible if IRQ 15 is being used, since
1072 * it's the "garbage collector" on the 2nd 8259 PIC. Specifically,
1073 * any interrupt signal into the 8259 which can't be identified
1074 * comes out as 7 from the 8259, which is 15 to the host. Thus, it
1075 * is a good thing the WD7000 has an interrupt status port, so we
1076 * can sort these out. Otherwise, electrical noise and other such
1077 * problems would be indistinguishable from valid interrupts...
1080 printk ("wd7000_intr_handle: phantom interrupt...\n");
1082 wd7000_intr_ack (host);
1086 if (flag & MB_INTR) {
1087 /* The interrupt is for a mailbox */
1088 if (!(flag & IMB_INTR)) {
1090 printk ("wd7000_intr_handle: free outgoing mailbox\n");
1093 * If sleep_on() and the "interrupt on free OGMB" command are
1094 * used in mail_out(), wake_up() should correspondingly be called
1095 * here. For now, we don't need to do anything special.
1097 wd7000_intr_ack (host);
1101 /* The interrupt is for an incoming mailbox */
1102 icmb = flag & MB_MASK;
1103 icmb_status = icmbs[icmb].status;
1104 if (icmb_status & 0x80) { /* unsolicited - result in ICMB */
1106 printk ("wd7000_intr_handle: unsolicited interrupt 0x%02x\n",
1109 wd7000_intr_ack (host);
1112 /* Aaaargh! (Zaga) */
1113 scb = bus_to_virt(scsi2int ((unchar *) icmbs[icmb].scbptr));
1114 icmbs[icmb].status = 0;
1115 if (!(scb->op & ICB_OP_MASK)) { /* an SCB is done */
1117 if (--(SCpnt->SCp.phase) <= 0) { /* all scbs are done */
1118 host_error = scb->vue | (icmb_status << 8);
1119 scsi_error = scb->status;
1120 errstatus = make_code (host_error, scsi_error);
1121 SCpnt->result = errstatus;
1125 SCpnt->scsi_done (SCpnt);
1128 else { /* an ICB is done */
1129 icb = (IcbAny *) scb;
1130 icb->status = icmb_status;
1133 } /* incoming mailbox */
1136 wd7000_intr_ack (host);
1139 printk ("wd7000_intr_handle: return from interrupt handler\n");
1143 void do_wd7000_intr_handle (int irq, void *dev_id, struct pt_regs *regs)
1145 unsigned long flags;
1147 spin_lock_irqsave(&io_request_lock, flags);
1148 wd7000_intr_handle(irq, dev_id, regs);
1149 spin_unlock_irqrestore(&io_request_lock, flags);
1153 int wd7000_queuecommand (Scsi_Cmnd *SCpnt, void (*done) (Scsi_Cmnd *))
1157 register unchar *cdb = (unchar *) SCpnt->cmnd;
1158 register unchar idlun;
1159 register short cdblen;
1160 Adapter *host = (Adapter *) SCpnt->host->hostdata;
1162 cdblen = SCpnt->cmd_len;
1163 idlun = ((SCpnt->target << 5) & 0xe0) | (SCpnt->lun & 7);
1164 SCpnt->scsi_done = done;
1165 SCpnt->SCp.phase = 1;
1166 scb = alloc_scbs (1);
1168 memcpy (scb->cdb, cdb, cdblen);
1169 scb->direc = 0x40; /* Disable direction check */
1171 scb->SCpnt = SCpnt; /* so we can find stuff later */
1172 SCpnt->host_scribble = (unchar *) scb;
1175 if (SCpnt->use_sg) {
1176 struct scatterlist *sg = (struct scatterlist *) SCpnt->request_buffer;
1179 if (SCpnt->host->sg_tablesize == SG_NONE) {
1180 panic ("wd7000_queuecommand: scatter/gather not supported.\n");
1183 printk ("Using scatter/gather with %d elements.\n", SCpnt->use_sg);
1188 any2scsi (scb->dataptr, (int) sgb);
1189 any2scsi (scb->maxlen, SCpnt->use_sg * sizeof (Sgb));
1191 for (i = 0; i < SCpnt->use_sg; i++) {
1192 any2scsi (sgb[i].ptr, (int) sg[i].address);
1193 any2scsi (sgb[i].len, sg[i].length);
1198 any2scsi (scb->dataptr, (int) SCpnt->request_buffer);
1199 any2scsi (scb->maxlen, SCpnt->request_bufflen);
1202 while (!mail_out (host, scb)); /* keep trying */
1208 int wd7000_command (Scsi_Cmnd *SCpnt)
1210 wd7000_queuecommand (SCpnt, wd7000_scsi_done);
1212 while (SCpnt->SCp.phase > 0)
1213 barrier (); /* phase counts scbs down to 0 */
1215 return (SCpnt->result);
1219 int wd7000_diagnostics (Adapter *host, int code)
1221 static IcbDiag icb = {ICB_OP_DIAGNOSTICS};
1222 static unchar buf[256];
1223 unsigned long timeout;
1226 any2scsi (icb.len, sizeof (buf));
1227 any2scsi (icb.ptr, (int) &buf);
1230 * This routine is only called at init, so there should be OGMBs
1231 * available. I'm assuming so here. If this is going to
1232 * fail, I can just let the timeout catch the failure.
1234 mail_out (host, (struct scb *) &icb);
1235 timeout = jiffies + WAITnexttimeout; /* wait up to 2 seconds */
1236 while (icb.phase && time_before(jiffies, timeout))
1237 barrier (); /* wait for completion */
1240 printk ("wd7000_diagnostics: timed out.\n");
1243 if (make_code (icb.vue | (icb.status << 8), 0)) {
1244 printk ("wd7000_diagnostics: failed (0x%02x,0x%02x)\n",
1245 icb.vue, icb.status);
1253 int wd7000_init (Adapter *host)
1269 * Reset the adapter - only. The SCSI bus was initialized at power-up,
1270 * and we need to do this just so we control the mailboxes, etc.
1272 outb (ASC_RES, host->iobase + ASC_CONTROL);
1273 delay (1); /* reset pulse: this is 10ms, only need 25us */
1274 outb (0, host->iobase + ASC_CONTROL);
1275 host->control = 0; /* this must always shadow ASC_CONTROL */
1277 if (WAIT (host->iobase + ASC_STAT, ASC_STATMASK, CMD_RDY, 0)) {
1278 printk ("wd7000_init: WAIT timed out.\n");
1279 return (0); /* 0 = not ok */
1282 if ((diag = inb (host->iobase + ASC_INTR_STAT)) != 1) {
1283 printk ("wd7000_init: ");
1286 case 2: printk ("RAM failure.\n");
1288 case 3: printk ("FIFO R/W failed\n");
1290 case 4: printk ("SBIC register R/W failed\n");
1292 case 5: printk ("Initialization D-FF failed.\n");
1294 case 6: printk ("Host IRQ D-FF failed.\n");
1296 case 7: printk ("ROM checksum error.\n");
1298 default: printk ("diagnostic code 0x%02Xh received.\n", diag);
1303 /* Clear mailboxes */
1304 memset (&(host->mb), 0, sizeof (host->mb));
1306 /* Execute init command */
1307 any2scsi ((unchar *) & (init_cmd.mailboxes), (int) &(host->mb));
1308 if (!command_out (host, (unchar *) &init_cmd, sizeof (init_cmd))) {
1309 printk ("wd7000_init: adapter initialization failed.\n");
1313 if (WAIT (host->iobase + ASC_STAT, ASC_STATMASK, ASC_INIT, 0)) {
1314 printk ("wd7000_init: WAIT timed out.\n");
1318 if (request_irq (host->irq, do_wd7000_intr_handle, SA_INTERRUPT, "wd7000", NULL)) {
1319 printk ("wd7000_init: can't get IRQ %d.\n", host->irq);
1322 if (request_dma (host->dma, "wd7000")) {
1323 printk ("wd7000_init: can't get DMA channel %d.\n", host->dma);
1324 free_irq (host->irq, NULL);
1327 wd7000_enable_dma (host);
1328 wd7000_enable_intr (host);
1330 if (!wd7000_diagnostics (host, ICB_DIAG_FULL)) {
1331 free_dma (host->dma);
1332 free_irq (host->irq, NULL);
1340 void wd7000_revision (Adapter *host)
1342 static IcbRevLvl icb =
1343 {ICB_OP_GET_REVISION};
1347 * Like diagnostics, this is only done at init time, in fact, from
1348 * wd7000_detect, so there should be OGMBs available. If it fails,
1349 * the only damage will be that the revision will show up as 0.0,
1350 * which in turn means that scatter/gather will be disabled.
1352 mail_out (host, (struct scb *) &icb);
1354 barrier (); /* wait for completion */
1355 host->rev1 = icb.primary;
1356 host->rev2 = icb.secondary;
1361 #define SPRINTF(args...) { if (pos < (buffer + length)) pos += sprintf (pos, ## args); }
1363 int wd7000_set_info (char *buffer, int length, struct Scsi_Host *host)
1365 unsigned long flags;
1371 printk ("Buffer = <%.*s>, length = %d\n", length, buffer, length);
1375 * Currently this is a no-op
1377 printk ("Sorry, this function is currently out of order...\n");
1379 restore_flags (flags);
1385 int wd7000_proc_info (char *buffer, char **start, off_t offset, int length, int hostno, int inout)
1387 struct Scsi_Host *host = NULL;
1390 unsigned long flags;
1395 Mailbox *ogmbs, *icmbs;
1400 * Find the specified host board.
1402 for (i = 0; i < IRQS; i++)
1403 if (wd7000_host[i] && (wd7000_host[i]->host_no == hostno)) {
1404 host = wd7000_host[i];
1416 * Has data been written to the file ?
1419 return (wd7000_set_info (buffer, length, host));
1421 adapter = (Adapter *) host->hostdata;
1426 SPRINTF ("Host scsi%d: Western Digital WD-7000 (rev %d.%d)\n", hostno, adapter->rev1, adapter->rev2);
1427 SPRINTF (" IO base: 0x%x\n", adapter->iobase);
1428 SPRINTF (" IRQ: %d\n", adapter->irq);
1429 SPRINTF (" DMA channel: %d\n", adapter->dma);
1430 SPRINTF (" Interrupts: %d\n", adapter->int_counter);
1431 SPRINTF (" BUS_ON time: %d nanoseconds\n", adapter->bus_on * 125);
1432 SPRINTF (" BUS_OFF time: %d nanoseconds\n", adapter->bus_off * 125);
1435 ogmbs = adapter->mb.ogmb;
1436 icmbs = adapter->mb.icmb;
1438 SPRINTF ("\nControl port value: 0x%x\n", adapter->control);
1439 SPRINTF ("Incoming mailbox:\n");
1440 SPRINTF (" size: %d\n", ICMB_CNT);
1441 SPRINTF (" queued messages: ");
1443 for (i = count = 0; i < ICMB_CNT; i++)
1444 if (icmbs[i].status) {
1446 SPRINTF ("0x%x ", i);
1449 SPRINTF (count ? "\n" : "none\n");
1451 SPRINTF ("Outgoing mailbox:\n");
1452 SPRINTF (" size: %d\n", OGMB_CNT);
1453 SPRINTF (" next message: 0x%x\n", adapter->next_ogmb);
1454 SPRINTF (" queued messages: ");
1456 for (i = count = 0; i < OGMB_CNT; i++)
1457 if (ogmbs[i].status) {
1459 SPRINTF ("0x%x ", i);
1462 SPRINTF (count ? "\n" : "none\n");
1466 * Display driver information for each device attached to the board.
1468 scd = host->host_queue;
1470 SPRINTF ("\nAttached devices: %s\n", scd ? "" : "none");
1472 for ( ; scd; scd = scd->next)
1473 if (scd->host->host_no == hostno) {
1474 SPRINTF (" [Channel: %02d, Id: %02d, Lun: %02d] ",
1475 scd->channel, scd->id, scd->lun);
1476 SPRINTF ("%s ", (scd->type < MAX_SCSI_DEVICE_CODE) ?
1477 scsi_device_types[(short) scd->type] : "Unknown device");
1479 for (i = 0; (i < 8) && (scd->vendor[i] >= 0x20); i++)
1480 SPRINTF ("%c", scd->vendor[i]);
1483 for (i = 0; (i < 16) && (scd->model[i] >= 0x20); i++)
1484 SPRINTF ("%c", scd->model[i]);
1490 restore_flags (flags);
1493 * Calculate start of next buffer, and return value.
1495 *start = buffer + offset;
1497 if ((pos - buffer) < offset)
1499 else if ((pos - buffer - offset) < length)
1500 return (pos - buffer - offset);
1507 * Returns the number of adapters this driver is supporting.
1509 * The source for hosts.c says to wait to call scsi_register until 100%
1510 * sure about an adapter. We need to do it a little sooner here; we
1511 * need the storage set up by scsi_register before wd7000_init, and
1512 * changing the location of an Adapter structure is more trouble than
1513 * calling scsi_unregister.
1516 int wd7000_detect (Scsi_Host_Template *tpnt)
1518 short present = 0, biosaddr_ptr, sig_ptr, i, pass;
1519 short biosptr[NUM_CONFIGS];
1521 Adapter *host = NULL;
1522 struct Scsi_Host *sh;
1525 printk ("wd7000_detect: started\n");
1530 wd7000_setup(wd7000);
1533 for (i = 0; i < IRQS; wd7000_host[i++] = NULL) ;
1534 for (i = 0; i < NUM_CONFIGS; biosptr[i++] = -1) ;
1536 tpnt->proc_name = "wd7000";
1537 tpnt->proc_info = &wd7000_proc_info;
1540 * Set up SCB free list, which is shared by all adapters
1544 for (pass = 0; pass < NUM_CONFIGS; pass++) {
1546 * First, search for BIOS SIGNATURE...
1548 for (biosaddr_ptr = 0; biosaddr_ptr < NUM_ADDRS; biosaddr_ptr++)
1549 for (sig_ptr = 0; sig_ptr < NUM_SIGNATURES; sig_ptr++) {
1550 for (i = 0; i < pass; i++)
1551 if (biosptr[i] == biosaddr_ptr)
1555 void *biosaddr = ioremap (wd7000_biosaddr[biosaddr_ptr] +
1556 signatures[sig_ptr].ofs,
1557 signatures[sig_ptr].len);
1561 bios_match = memcmp ((char *) biosaddr, signatures[sig_ptr].sig,
1562 signatures[sig_ptr].len);
1573 * BIOS SIGNATURE has been found.
1576 printk ("wd7000_detect: pass %d\n", pass + 1);
1578 if (biosaddr_ptr == NUM_ADDRS)
1579 printk ("WD-7000 SST BIOS not detected...\n");
1581 printk ("WD-7000 SST BIOS detected at 0x%lx: checking...\n",
1582 wd7000_biosaddr[biosaddr_ptr]);
1585 if (configs[pass].irq < 0)
1588 iobase = configs[pass].iobase;
1591 printk ("wd7000_detect: check IO 0x%x region...\n", iobase);
1594 if (request_region (iobase, 4, "wd7000")) {
1597 printk ("wd7000_detect: ASC reset (IO 0x%x) ...", iobase);
1602 outb (ASC_RES, iobase + ASC_CONTROL);
1604 outb (0, iobase + ASC_CONTROL);
1606 if (WAIT (iobase + ASC_STAT, ASC_STATMASK, CMD_RDY, 0))
1609 printk ("failed!\n");
1618 if (inb (iobase + ASC_INTR_STAT) == 1) {
1620 * We register here, to get a pointer to the extra space,
1621 * which we'll use as the Adapter structure (host) for
1622 * this adapter. It is located just after the registered
1623 * Scsi_Host structure (sh), and is located by the empty
1626 sh = scsi_register (tpnt, sizeof (Adapter));
1630 host = (Adapter *) sh->hostdata;
1633 printk ("wd7000_detect: adapter allocated at 0x%x\n", (int) host);
1636 memset (host, 0, sizeof (Adapter));
1638 host->irq = configs[pass].irq;
1639 host->dma = configs[pass].dma;
1640 host->iobase = iobase;
1641 host->int_counter = 0;
1642 host->bus_on = configs[pass].bus_on;
1643 host->bus_off = configs[pass].bus_off;
1644 host->sh = wd7000_host[host->irq - IRQ_MIN] = sh;
1647 printk ("wd7000_detect: Trying init WD-7000 card at IO "
1648 "0x%x, IRQ %d, DMA %d...\n",
1649 host->iobase, host->irq, host->dma);
1652 if (!wd7000_init (host)) /* Initialization failed */
1653 goto err_unregister;
1656 * OK from here - we'll use this adapter/configuration.
1658 wd7000_revision (host); /* important for scatter/gather */
1661 * For boards before rev 6.0, scatter/gather isn't supported.
1664 sh->sg_tablesize = SG_NONE;
1666 present++; /* count it */
1668 if (biosaddr_ptr != NUM_ADDRS)
1669 biosptr[pass] = biosaddr_ptr;
1671 printk ("Western Digital WD-7000 (rev %d.%d) ",
1672 host->rev1, host->rev2);
1673 printk ("using IO 0x%x, IRQ %d, DMA %d.\n",
1674 host->iobase, host->irq, host->dma);
1675 printk (" BUS_ON time: %dns, BUS_OFF time: %dns\n",
1676 host->bus_on * 125, host->bus_off * 125);
1682 printk ("wd7000_detect: IO 0x%x region already allocated!\n", iobase);
1688 scsi_unregister (sh);
1690 release_region(iobase, 4);
1695 printk ("Failed initialization of WD-7000 SCSI card!\n");
1702 * I have absolutely NO idea how to do an abort with the WD7000...
1704 int wd7000_abort (Scsi_Cmnd *SCpnt)
1706 Adapter *host = (Adapter *) SCpnt->host->hostdata;
1708 if (inb (host->iobase + ASC_STAT) & INT_IM) {
1709 printk ("wd7000_abort: lost interrupt\n");
1710 wd7000_intr_handle (host->irq, NULL, NULL);
1712 return (SCSI_ABORT_SUCCESS);
1715 return (SCSI_ABORT_SNOOZE);
1720 * I also have no idea how to do a reset...
1722 int wd7000_reset (Scsi_Cmnd *SCpnt, unsigned int unused)
1724 return (SCSI_RESET_PUNT);
1729 * This was borrowed directly from aha1542.c. (Zaga)
1731 int wd7000_biosparam (Disk *disk, kdev_t dev, int *ip)
1734 printk ("wd7000_biosparam: dev=%s, size=%d, ", kdevname (dev), disk->capacity);
1738 * try default translation
1742 ip[2] = disk->capacity / (64 * 32);
1745 * for disks >1GB do some guessing
1747 if (ip[2] >= 1024) {
1751 * try to figure out the geometry from the partition table
1753 if ((scsicam_bios_param (disk, dev, info) < 0) ||
1754 !(((info[0] == 64) && (info[1] == 32)) ||
1755 ((info[0] == 255) && (info[1] == 63)))) {
1756 printk ("wd7000_biosparam: unable to verify geometry for disk with >1GB.\n"
1757 " using extended translation.\n");
1761 ip[2] = disk->capacity / (255 * 63);
1769 printk ("wd7000_biosparam: current partition table is using extended translation.\n");
1774 printk ("bios geometry: head=%d, sec=%d, cyl=%d\n", ip[0], ip[1], ip[2]);
1775 printk ("WARNING: check, if the bios geometry is correct.\n");
1781 MODULE_LICENSE("GPL");
1783 /* Eventually this will go into an include file, but this will be later */
1784 static Scsi_Host_Template driver_template = WD7000;
1786 #include "scsi_module.c"