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
146 #include <linux/module.h>
150 #include <linux/kernel.h>
151 #include <linux/types.h>
152 #include <linux/string.h>
153 #include <linux/sched.h>
154 #include <linux/malloc.h>
155 #include <asm/system.h>
156 #include <asm/spinlock.h>
159 #include <linux/ioport.h>
160 #include <linux/proc_fs.h>
161 #include <linux/blk.h>
162 #include <linux/version.h>
166 #include <scsi/scsicam.h>
168 #define ANY2SCSI_INLINE /* undef this to use old macros */
169 #undef WD7000_DEBUG /* general debug */
172 #include <linux/stat.h>
175 struct proc_dir_entry proc_scsi_wd7000
=
180 S_IFDIR
| S_IRUGO
| S_IXUGO
,
186 * Mailbox structure sizes.
187 * I prefer to keep the number of ICMBs much larger than the number of
188 * OGMBs. OGMBs are used very quickly by the driver to start one or
189 * more commands, while ICMBs are used by the host adapter per command.
195 * Scb's are shared by all active adapters. So, if they all become busy,
196 * callers may be made to wait in alloc_scbs for them to free. That can
197 * be avoided by setting MAX_SCBS to NUM_CONFIG * WD7000_Q. If you'd
198 * rather conserve memory, use a smaller number (> 0, of course) - things
199 * will should still work OK.
204 * WD7000-specific mailbox structure
207 typedef volatile struct mailbox
{
209 unchar scbptr
[3]; /* SCSI-style - MSB first (big endian) */
213 * This structure should contain all per-adapter global data. I.e., any
214 * new global per-adapter data should put in here.
216 typedef struct adapter
{
217 struct Scsi_Host
*sh
; /* Pointer to Scsi_Host structure */
218 int iobase
; /* This adapter's I/O base address */
219 int irq
; /* This adapter's IRQ level */
220 int dma
; /* This adapter's DMA channel */
221 int int_counter
; /* This adapter's interrupt counter */
222 int bus_on
; /* This adapter's BUS_ON time */
223 int bus_off
; /* This adapter's BUS_OFF time */
224 struct { /* This adapter's mailboxes */
225 Mailbox ogmb
[OGMB_CNT
]; /* Outgoing mailboxes */
226 Mailbox icmb
[ICMB_CNT
]; /* Incoming mailboxes */
228 int next_ogmb
; /* to reduce contention at mailboxes */
229 unchar control
; /* shadows CONTROL port value */
230 unchar rev1
, rev2
; /* filled in by wd7000_revision */
234 * (linear) base address for ROM BIOS
236 static const long wd7000_biosaddr
[] =
238 0xc0000, 0xc2000, 0xc4000, 0xc6000, 0xc8000, 0xca000, 0xcc000, 0xce000,
239 0xd0000, 0xd2000, 0xd4000, 0xd6000, 0xd8000, 0xda000, 0xdc000, 0xde000
241 #define NUM_ADDRS (sizeof(wd7000_biosaddr)/sizeof(long))
243 static const unsigned short wd7000_iobase
[] =
245 0x0300, 0x0308, 0x0310, 0x0318, 0x0320, 0x0328, 0x0330, 0x0338,
246 0x0340, 0x0348, 0x0350, 0x0358, 0x0360, 0x0368, 0x0370, 0x0378,
247 0x0380, 0x0388, 0x0390, 0x0398, 0x03a0, 0x03a8, 0x03b0, 0x03b8,
248 0x03c0, 0x03c8, 0x03d0, 0x03d8, 0x03e0, 0x03e8, 0x03f0, 0x03f8
250 #define NUM_IOPORTS (sizeof(wd7000_iobase)/sizeof(unsigned short))
252 static const short wd7000_irq
[] = { 3, 4, 5, 7, 9, 10, 11, 12, 14, 15 };
253 #define NUM_IRQS (sizeof(wd7000_irq)/sizeof(short))
255 static const short wd7000_dma
[] = { 5, 6, 7 };
256 #define NUM_DMAS (sizeof(wd7000_dma)/sizeof(short))
263 #define IRQS (IRQ_MAX - IRQ_MIN + 1)
266 * The following is set up by wd7000_detect, and used thereafter by
267 * wd7000_intr_handle to map the irq level to the corresponding Adapter.
268 * Note that if SA_INTERRUPT is not used, wd7000_intr_handle must be
269 * changed to pick up the IRQ level correctly.
271 static struct Scsi_Host
*wd7000_host
[IRQS
];
273 #define BUS_ON 64 /* x 125ns = 8000ns (BIOS default) */
274 #define BUS_OFF 15 /* x 125ns = 1875ns (BIOS default) */
277 * Standard Adapter Configurations - used by wd7000_detect
280 short irq
; /* IRQ level */
281 short dma
; /* DMA channel */
282 unsigned iobase
; /* I/O base address */
283 short bus_on
; /* Time that WD7000 spends on the AT-bus when */
284 /* transferring data. BIOS default is 8000ns. */
285 short bus_off
; /* Time that WD7000 spends OFF THE BUS after */
286 /* while it is transferring data. */
287 /* BIOS default is 1875ns */
291 * Add here your configuration...
293 static Config configs
[] =
295 { 15, 6, 0x350, BUS_ON
, BUS_OFF
}, /* defaults for single adapter */
296 { 11, 5, 0x320, BUS_ON
, BUS_OFF
}, /* defaults for second adapter */
297 { 7, 6, 0x350, BUS_ON
, BUS_OFF
}, /* My configuration (Zaga) */
298 { -1, -1, 0x0, BUS_ON
, BUS_OFF
} /* Empty slot */
300 #define NUM_CONFIGS (sizeof(configs)/sizeof(Config))
303 * The following list defines strings to look for in the BIOS that identify
304 * it as the WD7000-FASST2 SST BIOS. I suspect that something should be
305 * added for the Future Domain version.
307 typedef struct signature
{
308 const char *sig
; /* String to look for */
309 unsigned long ofs
; /* offset from BIOS base address */
310 unsigned len
; /* length of string */
313 static const Signature signatures
[] =
315 {"SSTBIOS", 0x0000d, 7} /* "SSTBIOS" @ offset 0x0000d */
317 #define NUM_SIGNATURES (sizeof(signatures)/sizeof(Signature))
321 * I/O Port Offsets and Bit Definitions
322 * 4 addresses are used. Those not defined here are reserved.
324 #define ASC_STAT 0 /* Status, Read */
325 #define ASC_COMMAND 0 /* Command, Write */
326 #define ASC_INTR_STAT 1 /* Interrupt Status, Read */
327 #define ASC_INTR_ACK 1 /* Acknowledge, Write */
328 #define ASC_CONTROL 2 /* Control, Write */
333 #define INT_IM 0x80 /* Interrupt Image Flag */
334 #define CMD_RDY 0x40 /* Command Port Ready */
335 #define CMD_REJ 0x20 /* Command Port Byte Rejected */
336 #define ASC_INIT 0x10 /* ASC Initialized Flag */
337 #define ASC_STATMASK 0xf0 /* The lower 4 Bytes are reserved */
342 * Unfortunately, I have no idea how to properly use some of these commands,
343 * as the OEM manual does not make it clear. I have not been able to use
344 * enable/disable unsolicited interrupts or the reset commands with any
345 * discernible effect whatsoever. I think they may be related to certain
346 * ICB commands, but again, the OEM manual doesn't make that clear.
348 #define NO_OP 0 /* NO-OP toggles CMD_RDY bit in ASC_STAT */
349 #define INITIALIZATION 1 /* initialization (10 bytes) */
350 #define DISABLE_UNS_INTR 2 /* disable unsolicited interrupts */
351 #define ENABLE_UNS_INTR 3 /* enable unsolicited interrupts */
352 #define INTR_ON_FREE_OGMB 4 /* interrupt on free OGMB */
353 #define SOFT_RESET 5 /* SCSI bus soft reset */
354 #define HARD_RESET_ACK 6 /* SCSI bus hard reset acknowledge */
355 #define START_OGMB 0x80 /* start command in OGMB (n) */
356 #define SCAN_OGMBS 0xc0 /* start multiple commands, signature (n) */
357 /* where (n) = lower 6 bits */
359 * For INITIALIZATION:
361 typedef struct initCmd
{
362 unchar op
; /* command opcode (= 1) */
363 unchar ID
; /* Adapter's SCSI ID */
364 unchar bus_on
; /* Bus on time, x 125ns (see below) */
365 unchar bus_off
; /* Bus off time, "" "" */
366 unchar rsvd
; /* Reserved */
367 unchar mailboxes
[3]; /* Address of Mailboxes, MSB first */
368 unchar ogmbs
; /* Number of outgoing MBs, max 64, 0,1 = 1 */
369 unchar icmbs
; /* Number of incoming MBs, "" "" */
373 * Interrupt Status Port - also returns diagnostic codes at ASC reset
375 * if msb is zero, the lower bits are diagnostic status
377 * 01 No diagnostic error occurred
380 * 04 SBIC register read/write failed
381 * 05 Initialization D-FF failed
382 * 06 Host IRQ D-FF failed
383 * 07 ROM checksum error
384 * Interrupt status (bitwise):
385 * 10NNNNNN outgoing mailbox NNNNNN is free
386 * 11NNNNNN incoming mailbox NNNNNN needs service
388 #define MB_INTR 0xC0 /* Mailbox Service possible/required */
389 #define IMB_INTR 0x40 /* 1 Incoming / 0 Outgoing */
390 #define MB_MASK 0x3f /* mask for mailbox number */
395 #define INT_EN 0x08 /* Interrupt Enable */
396 #define DMA_EN 0x04 /* DMA Enable */
397 #define SCSI_RES 0x02 /* SCSI Reset */
398 #define ASC_RES 0x01 /* ASC Reset */
401 * Driver data structures:
402 * - mb and scbs are required for interfacing with the host adapter.
403 * An SCB has extra fields not visible to the adapter; mb's
404 * _cannot_ do this, since the adapter assumes they are contiguous in
405 * memory, 4 bytes each, with ICMBs following OGMBs, and uses this fact
407 * - An icb is for host-only (non-SCSI) commands. ICBs are 16 bytes each;
408 * the additional bytes are used only by the driver.
409 * - For now, a pool of SCBs are kept in global storage by this driver,
410 * and are allocated and freed as needed.
412 * The 7000-FASST2 marks OGMBs empty as soon as it has _started_ a command,
413 * not when it has finished. Since the SCB must be around for completion,
414 * problems arise when SCBs correspond to OGMBs, which may be reallocated
415 * earlier (or delayed unnecessarily until a command completes).
416 * Mailboxes are used as transient data structures, simply for
417 * carrying SCB addresses to/from the 7000-FASST2.
419 * Note also since SCBs are not "permanently" associated with mailboxes,
420 * there is no need to keep a global list of Scsi_Cmnd pointers indexed
421 * by OGMB. Again, SCBs reference their Scsi_Cmnds directly, so mailbox
422 * indices need not be involved.
426 * WD7000-specific scatter/gather element structure
430 unchar ptr
[3]; /* Also SCSI-style - MSB first */
433 typedef struct scb
{ /* Command Control Block 5.4.1 */
434 unchar op
; /* Command Control Block Operation Code */
435 unchar idlun
; /* op=0,2:Target Id, op=1:Initiator Id */
436 /* Outbound data transfer, length is checked */
437 /* Inbound data transfer, length is checked */
438 /* Logical Unit Number */
439 unchar cdb
[12]; /* SCSI Command Block */
440 volatile unchar status
; /* SCSI Return Status */
441 volatile unchar vue
; /* Vendor Unique Error Code */
442 unchar maxlen
[3]; /* Maximum Data Transfer Length */
443 unchar dataptr
[3]; /* SCSI Data Block Pointer */
444 unchar linkptr
[3]; /* Next Command Link Pointer */
445 unchar direc
; /* Transfer Direction */
446 unchar reserved2
[6]; /* SCSI Command Descriptor Block */
447 /* end of hardware SCB */
448 Scsi_Cmnd
*SCpnt
; /* Scsi_Cmnd using this SCB */
449 Sgb sgb
[WD7000_SG
]; /* Scatter/gather list for this SCB */
450 Adapter
*host
; /* host adapter */
451 struct scb
*next
; /* for lists of scbs */
455 * This driver is written to allow host-only commands to be executed.
456 * These use a 16-byte block called an ICB. The format is extended by the
457 * driver to 18 bytes, to support the status returned in the ICMB and
458 * an execution phase code.
460 * There are other formats besides these; these are the ones I've tried
461 * to use. Formats for some of the defined ICB opcodes are not defined
462 * (notably, get/set unsolicited interrupt status) in my copy of the OEM
463 * manual, and others are ambiguous/hard to follow.
465 #define ICB_OP_MASK 0x80 /* distinguishes scbs from icbs */
466 #define ICB_OP_OPEN_RBUF 0x80 /* open receive buffer */
467 #define ICB_OP_RECV_CMD 0x81 /* receive command from initiator */
468 #define ICB_OP_RECV_DATA 0x82 /* receive data from initiator */
469 #define ICB_OP_RECV_SDATA 0x83 /* receive data with status from init. */
470 #define ICB_OP_SEND_DATA 0x84 /* send data with status to initiator */
471 #define ICB_OP_SEND_STAT 0x86 /* send command status to initiator */
472 /* 0x87 is reserved */
473 #define ICB_OP_READ_INIT 0x88 /* read initialization bytes */
474 #define ICB_OP_READ_ID 0x89 /* read adapter's SCSI ID */
475 #define ICB_OP_SET_UMASK 0x8A /* set unsolicited interrupt mask */
476 #define ICB_OP_GET_UMASK 0x8B /* read unsolicited interrupt mask */
477 #define ICB_OP_GET_REVISION 0x8C /* read firmware revision level */
478 #define ICB_OP_DIAGNOSTICS 0x8D /* execute diagnostics */
479 #define ICB_OP_SET_EPARMS 0x8E /* set execution parameters */
480 #define ICB_OP_GET_EPARMS 0x8F /* read execution parameters */
482 typedef struct icbRecvCmd
{
484 unchar IDlun
; /* Initiator SCSI ID/lun */
485 unchar len
[3]; /* command buffer length */
486 unchar ptr
[3]; /* command buffer address */
487 unchar rsvd
[7]; /* reserved */
488 volatile unchar vue
; /* vendor-unique error code */
489 volatile unchar status
; /* returned (icmb) status */
490 volatile unchar phase
; /* used by interrupt handler */
493 typedef struct icbSendStat
{
495 unchar IDlun
; /* Target SCSI ID/lun */
496 unchar stat
; /* (outgoing) completion status byte 1 */
497 unchar rsvd
[12]; /* reserved */
498 volatile unchar vue
; /* vendor-unique error code */
499 volatile unchar status
; /* returned (icmb) status */
500 volatile unchar phase
; /* used by interrupt handler */
503 typedef struct icbRevLvl
{
505 volatile unchar primary
; /* primary revision level (returned) */
506 volatile unchar secondary
; /* secondary revision level (returned) */
507 unchar rsvd
[12]; /* reserved */
508 volatile unchar vue
; /* vendor-unique error code */
509 volatile unchar status
; /* returned (icmb) status */
510 volatile unchar phase
; /* used by interrupt handler */
513 typedef struct icbUnsMask
{ /* I'm totally guessing here */
515 volatile unchar mask
[14]; /* mask bits */
517 unchar rsvd
[12]; /* reserved */
519 volatile unchar vue
; /* vendor-unique error code */
520 volatile unchar status
; /* returned (icmb) status */
521 volatile unchar phase
; /* used by interrupt handler */
524 typedef struct icbDiag
{
526 unchar type
; /* diagnostics type code (0-3) */
527 unchar len
[3]; /* buffer length */
528 unchar ptr
[3]; /* buffer address */
529 unchar rsvd
[7]; /* reserved */
530 volatile unchar vue
; /* vendor-unique error code */
531 volatile unchar status
; /* returned (icmb) status */
532 volatile unchar phase
; /* used by interrupt handler */
535 #define ICB_DIAG_POWERUP 0 /* Power-up diags only */
536 #define ICB_DIAG_WALKING 1 /* walking 1's pattern */
537 #define ICB_DIAG_DMA 2 /* DMA - system memory diags */
538 #define ICB_DIAG_FULL 3 /* do both 1 & 2 */
540 typedef struct icbParms
{
542 unchar rsvd1
; /* reserved */
543 unchar len
[3]; /* parms buffer length */
544 unchar ptr
[3]; /* parms buffer address */
545 unchar idx
[2]; /* index (MSB-LSB) */
546 unchar rsvd2
[5]; /* 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 typedef struct icbAny
{
554 unchar data
[14]; /* format-specific data */
555 volatile unchar vue
; /* vendor-unique error code */
556 volatile unchar status
; /* returned (icmb) status */
557 volatile unchar phase
; /* used by interrupt handler */
561 unchar op
; /* ICB opcode */
562 IcbRecvCmd recv_cmd
; /* format for receive command */
563 IcbSendStat send_stat
; /* format for send status */
564 IcbRevLvl rev_lvl
; /* format for get revision level */
565 IcbDiag diag
; /* format for execute diagnostics */
566 IcbParms eparms
; /* format for get/set exec parms */
567 IcbAny icb
; /* generic format */
573 * Driver SCB structure pool.
575 * The SCBs declared here are shared by all host adapters; hence, this
576 * structure is not part of the Adapter structure.
578 static Scb scbs
[MAX_SCBS
];
579 static Scb
*scbfree
= NULL
; /* free list */
580 static int freescbs
= MAX_SCBS
; /* free list counter */
583 * END of data/declarations - code follows.
585 static void setup_error (char *mesg
, int *ints
)
588 printk ("wd7000_setup: \"wd7000=%d,%d,0x%x\" -> %s\n",
589 ints
[1], ints
[2], ints
[3], mesg
);
590 else if (ints
[0] == 4)
591 printk ("wd7000_setup: \"wd7000=%d,%d,0x%x,%d\" -> %s\n",
592 ints
[1], ints
[2], ints
[3], ints
[4], mesg
);
594 printk ("wd7000_setup: \"wd7000=%d,%d,0x%x,%d,%d\" -> %s\n",
595 ints
[1], ints
[2], ints
[3], ints
[4], ints
[5], mesg
);
600 * Note: You can now set these options from the kernel's "command line".
603 * wd7000=<IRQ>,<DMA>,<IO>[,<BUS_ON>[,<BUS_OFF>]]
605 * , where BUS_ON and BUS_OFF are in nanoseconds. BIOS default values
606 * are 8000ns for BUS_ON and 1875ns for BUS_OFF.
610 * will configure the driver for a WD-7000 controller
611 * using IRQ 15 with a DMA channel 6, at IO base address 0x350.
613 void wd7000_setup (char *str
, int *ints
)
615 static short wd7000_card_num
= 0;
618 if (wd7000_card_num
>= NUM_CONFIGS
) {
619 printk ("wd7000_setup: Too many \"wd7000=\" configurations in "
624 if ((ints
[0] < 3) || (ints
[0] > 5))
625 printk ("wd7000_setup: Error in command line! "
626 "Usage: wd7000=<IRQ>,<DMA>,IO>[,<BUS_ON>[,<BUS_OFF>]]\n");
628 for (i
= 0; i
< NUM_IRQS
; i
++)
629 if (ints
[1] == wd7000_irq
[i
])
633 setup_error ("invalid IRQ.", ints
);
637 configs
[wd7000_card_num
].irq
= ints
[1];
639 for (i
= 0; i
< NUM_DMAS
; i
++)
640 if (ints
[2] == wd7000_dma
[i
])
644 setup_error ("invalid DMA channel.", ints
);
648 configs
[wd7000_card_num
].dma
= ints
[2];
650 for (i
= 0; i
< NUM_IOPORTS
; i
++)
651 if (ints
[3] == wd7000_iobase
[i
])
654 if (i
== NUM_IOPORTS
) {
655 setup_error ("invalid I/O base address.", ints
);
659 configs
[wd7000_card_num
].iobase
= ints
[3];
662 if ((ints
[4] < 500) || (ints
[4] > 31875)) {
663 setup_error ("BUS_ON value is out of range (500 to 31875 nanoseconds)!",
665 configs
[wd7000_card_num
].bus_on
= BUS_ON
;
668 configs
[wd7000_card_num
].bus_on
= ints
[4] / 125;
671 configs
[wd7000_card_num
].bus_on
= BUS_ON
;
674 if ((ints
[5] < 500) || (ints
[5] > 31875)) {
675 setup_error ("BUS_OFF value is out of range (500 to 31875 nanoseconds)!",
677 configs
[wd7000_card_num
].bus_off
= BUS_OFF
;
680 configs
[wd7000_card_num
].bus_off
= ints
[5] / 125;
683 configs
[wd7000_card_num
].bus_off
= BUS_OFF
;
685 if (wd7000_card_num
) {
686 for (i
= 0; i
< (wd7000_card_num
- 1); i
++)
687 for (j
= i
+ 1; j
< wd7000_card_num
; j
++)
688 if (configs
[i
].irq
== configs
[j
].irq
) {
689 setup_error ("duplicated IRQ!", ints
);
692 else if (configs
[i
].dma
== configs
[j
].dma
) {
693 setup_error ("duplicated DMA channel!", ints
);
696 else if (configs
[i
].iobase
== configs
[j
].iobase
) {
697 setup_error ("duplicated I/O base address!", ints
);
703 printk ("wd7000_setup: IRQ=%d, DMA=%d, I/O=0x%x, BUS_ON=%dns, BUS_OFF=%dns\n",
704 configs
[wd7000_card_num
].irq
,
705 configs
[wd7000_card_num
].dma
,
706 configs
[wd7000_card_num
].iobase
,
707 configs
[wd7000_card_num
].bus_on
* 125,
708 configs
[wd7000_card_num
].bus_off
* 125);
716 #ifdef ANY2SCSI_INLINE
718 * Since they're used a lot, I've redone the following from the macros
719 * formerly in wd7000.h, hopefully to speed them up by getting rid of
720 * all the shifting (it may not matter; GCC might have done as well anyway).
722 * xany2scsi and xscsi2int were not being used, and are no longer defined.
723 * (They were simply 4-byte versions of these routines).
725 typedef union { /* let's cheat... */
727 unchar u
[sizeof (int)]; /* the sizeof(int) makes it more portable */
731 static inline void any2scsi (unchar
* scsi
, int any
)
733 *scsi
++ = ((i_u
) any
).u
[2];
734 *scsi
++ = ((i_u
) any
).u
[1];
735 *scsi
++ = ((i_u
) any
).u
[0];
739 static inline int scsi2int (unchar
* scsi
)
743 result
.i
= 0; /* clears unused bytes */
744 result
.u
[2] = *scsi
++;
745 result
.u
[1] = *scsi
++;
746 result
.u
[0] = *scsi
++;
752 * These are the old ones - I've just moved them here...
755 #define any2scsi(up, p) (up)[0] = (((unsigned long) (p)) >> 16); \
756 (up)[1] = ((unsigned long) (p)) >> 8; \
757 (up)[2] = ((unsigned long) (p));
760 #define scsi2int(up) ( (((unsigned long) *(up)) << 16) + \
761 (((unsigned long) (up)[1]) << 8) + \
762 ((unsigned long) (up)[2]) )
766 static inline void wd7000_enable_intr (Adapter
*host
)
768 host
->control
|= INT_EN
;
769 outb (host
->control
, host
->iobase
+ ASC_CONTROL
);
773 static inline void wd7000_enable_dma (Adapter
*host
)
776 host
->control
|= DMA_EN
;
777 outb (host
->control
, host
->iobase
+ ASC_CONTROL
);
779 flags
= claim_dma_lock();
780 set_dma_mode (host
->dma
, DMA_MODE_CASCADE
);
781 enable_dma (host
->dma
);
782 release_dma_lock(flags
);
787 #define WAITnexttimeout 200 /* 2 seconds */
789 static inline short WAIT (unsigned port
, unsigned mask
, unsigned allof
, unsigned noneof
)
791 register unsigned WAITbits
;
792 register unsigned long WAITtimeout
= jiffies
+ WAITnexttimeout
;
794 while (time_before_eq(jiffies
, WAITtimeout
)) {
795 WAITbits
= inb (port
) & mask
;
797 if (((WAITbits
& allof
) == allof
) && ((WAITbits
& noneof
) == 0))
805 static inline void delay (unsigned how_long
)
807 register unsigned long time
= jiffies
+ how_long
;
809 while (time_before(jiffies
, time
));
813 static inline int command_out (Adapter
* host
, unchar
* cmd
, int len
)
815 if (!WAIT (host
->iobase
+ ASC_STAT
, ASC_STATMASK
, CMD_RDY
, 0)) {
818 outb (*cmd
, host
->iobase
+ ASC_COMMAND
);
819 WAIT (host
->iobase
+ ASC_STAT
, ASC_STATMASK
, CMD_RDY
, 0);
820 } while (inb (host
->iobase
+ ASC_STAT
) & CMD_REJ
);
828 printk ("wd7000 command_out: WAIT failed(%d)\n", len
+ 1);
835 * This version of alloc_scbs is in preparation for supporting multiple
836 * commands per lun and command chaining, by queueing pending commands.
837 * We will need to allocate Scbs in blocks since they will wait to be
838 * executed so there is the possibility of deadlock otherwise.
839 * Also, to keep larger requests from being starved by smaller requests,
840 * we limit access to this routine with an internal busy flag, so that
841 * the satisfiability of a request is not dependent on the size of the
844 static inline Scb
*alloc_scbs (int needed
)
846 register Scb
*scb
, *p
;
847 register unsigned long flags
;
848 register unsigned long timeout
= jiffies
+ WAITnexttimeout
;
849 register unsigned long now
;
854 return (NULL
); /* sanity check */
858 while (busy
) { /* someone else is allocating */
859 spin_unlock_irq(&io_request_lock
);
860 for (now
= jiffies
; now
== jiffies
; ); /* wait a jiffy */
861 spin_lock_irq(&io_request_lock
);
863 busy
= 1; /* not busy now; it's our turn */
865 while (freescbs
< needed
) {
866 timeout
= jiffies
+ WAITnexttimeout
;
868 spin_unlock_irq(&io_request_lock
);
869 for (now
= jiffies
; now
== jiffies
; ); /* wait a jiffy */
870 spin_lock_irq(&io_request_lock
);
871 } while (freescbs
< needed
&& time_before_eq(jiffies
, timeout
));
873 * If we get here with enough free Scbs, we can take them.
874 * Otherwise, we timed out and didn't get enough.
876 if (freescbs
< needed
) {
878 panic ("wd7000: can't get enough free SCBs.\n");
879 restore_flags (flags
);
885 for (i
= 0; i
< needed
; i
++) {
890 busy
= 0; /* we're done */
892 restore_flags (flags
);
898 static inline void free_scb (Scb
*scb
)
900 register unsigned long flags
;
905 memset (scb
, 0, sizeof (Scb
));
910 restore_flags (flags
);
914 static inline void init_scbs (void)
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
;
931 restore_flags (flags
);
935 static int mail_out (Adapter
*host
, Scb
*scbptr
)
937 * Note: this can also be used for ICBs; just cast to the parm type.
940 register int i
, ogmb
;
941 register unsigned long flags
;
943 Mailbox
*ogmbs
= host
->mb
.ogmb
;
944 int *next_ogmb
= &(host
->next_ogmb
);
947 printk ("wd7000_mail_out: 0x%06lx", (long) scbptr
);
950 /* We first look for a free outgoing mailbox */
954 for (i
= 0; i
< OGMB_CNT
; i
++) {
955 if (ogmbs
[ogmb
].status
== 0) {
957 printk (" using OGMB 0x%x", ogmb
);
959 ogmbs
[ogmb
].status
= 1;
960 any2scsi ((unchar
*) ogmbs
[ogmb
].scbptr
, (int) scbptr
);
962 *next_ogmb
= (ogmb
+ 1) % OGMB_CNT
;
966 ogmb
= (++ogmb
) % OGMB_CNT
;
968 restore_flags (flags
);
971 printk (", scb is 0x%06lx", (long) scbptr
);
976 * Alternatively, we might issue the "interrupt on free OGMB",
977 * and sleep, but it must be ensured that it isn't the init
978 * task running. Instead, this version assumes that the caller
979 * will be persistent, and try again. Since it's the adapter
980 * that marks OGMB's free, waiting even with interrupts off
981 * should work, since they are freed very quickly in most cases.
984 printk (", no free OGMBs.\n");
989 wd7000_enable_intr (host
);
991 start_ogmb
= START_OGMB
| ogmb
;
992 command_out (host
, &start_ogmb
, 1);
995 printk (", awaiting interrupt.\n");
1002 int make_code (unsigned hosterr
, unsigned scsierr
)
1005 int in_error
= hosterr
;
1008 switch ((hosterr
>> 8) & 0xff) {
1009 case 0: /* Reserved */
1010 hosterr
= DID_ERROR
;
1012 case 1: /* Command Complete, no errors */
1015 case 2: /* Command complete, error logged in scb status (scsierr) */
1018 case 4: /* Command failed to complete - timeout */
1019 hosterr
= DID_TIME_OUT
;
1021 case 5: /* Command terminated; Bus reset by external device */
1022 hosterr
= DID_RESET
;
1024 case 6: /* Unexpected Command Received w/ host as target */
1025 hosterr
= DID_BAD_TARGET
;
1027 case 80: /* Unexpected Reselection */
1028 case 81: /* Unexpected Selection */
1029 hosterr
= DID_BAD_INTR
;
1031 case 82: /* Abort Command Message */
1032 hosterr
= DID_ABORT
;
1034 case 83: /* SCSI Bus Software Reset */
1035 case 84: /* SCSI Bus Hardware Reset */
1036 hosterr
= DID_RESET
;
1038 default: /* Reserved */
1039 hosterr
= DID_ERROR
;
1042 if (scsierr
|| hosterr
)
1043 printk ("\nSCSI command error: SCSI 0x%02x host 0x%04x return %d\n",
1044 scsierr
, in_error
, hosterr
);
1046 return (scsierr
| (hosterr
<< 16));
1050 static void wd7000_scsi_done (Scsi_Cmnd
*SCpnt
)
1053 printk ("wd7000_scsi_done: 0x%06lx\n", (long) SCpnt
);
1056 SCpnt
->SCp
.phase
= 0;
1060 #define wd7000_intr_ack(host) outb (0, host->iobase + ASC_INTR_ACK)
1062 void wd7000_intr_handle (int irq
, void *dev_id
, struct pt_regs
*regs
)
1064 register int flag
, icmb
, errstatus
, icmb_status
;
1065 register int host_error
, scsi_error
;
1066 register Scb
*scb
; /* for SCSI commands */
1067 register IcbAny
*icb
; /* for host commands */
1068 register Scsi_Cmnd
*SCpnt
;
1069 Adapter
*host
= (Adapter
*) wd7000_host
[irq
- IRQ_MIN
]->hostdata
; /* This MUST be set!!! */
1070 Mailbox
*icmbs
= host
->mb
.icmb
;
1072 host
->int_counter
++;
1075 printk ("wd7000_intr_handle: irq = %d, host = 0x%06lx\n", irq
, (long) host
);
1078 flag
= inb (host
->iobase
+ ASC_INTR_STAT
);
1081 printk ("wd7000_intr_handle: intr stat = 0x%02x\n", flag
);
1084 if (!(inb (host
->iobase
+ ASC_STAT
) & INT_IM
)) {
1085 /* NB: these are _very_ possible if IRQ 15 is being used, since
1086 * it's the "garbage collector" on the 2nd 8259 PIC. Specifically,
1087 * any interrupt signal into the 8259 which can't be identified
1088 * comes out as 7 from the 8259, which is 15 to the host. Thus, it
1089 * is a good thing the WD7000 has an interrupt status port, so we
1090 * can sort these out. Otherwise, electrical noise and other such
1091 * problems would be indistinguishable from valid interrupts...
1094 printk ("wd7000_intr_handle: phantom interrupt...\n");
1096 wd7000_intr_ack (host
);
1100 if (flag
& MB_INTR
) {
1101 /* The interrupt is for a mailbox */
1102 if (!(flag
& IMB_INTR
)) {
1104 printk ("wd7000_intr_handle: free outgoing mailbox\n");
1107 * If sleep_on() and the "interrupt on free OGMB" command are
1108 * used in mail_out(), wake_up() should correspondingly be called
1109 * here. For now, we don't need to do anything special.
1111 wd7000_intr_ack (host
);
1115 /* The interrupt is for an incoming mailbox */
1116 icmb
= flag
& MB_MASK
;
1117 icmb_status
= icmbs
[icmb
].status
;
1118 if (icmb_status
& 0x80) { /* unsolicited - result in ICMB */
1120 printk ("wd7000_intr_handle: unsolicited interrupt 0x%02x\n",
1123 wd7000_intr_ack (host
);
1126 /* Aaaargh! (Zaga) */
1127 scb
= bus_to_virt(scsi2int ((unchar
*) icmbs
[icmb
].scbptr
));
1128 icmbs
[icmb
].status
= 0;
1129 if (!(scb
->op
& ICB_OP_MASK
)) { /* an SCB is done */
1131 if (--(SCpnt
->SCp
.phase
) <= 0) { /* all scbs are done */
1132 host_error
= scb
->vue
| (icmb_status
<< 8);
1133 scsi_error
= scb
->status
;
1134 errstatus
= make_code (host_error
, scsi_error
);
1135 SCpnt
->result
= errstatus
;
1139 SCpnt
->scsi_done (SCpnt
);
1142 else { /* an ICB is done */
1143 icb
= (IcbAny
*) scb
;
1144 icb
->status
= icmb_status
;
1147 } /* incoming mailbox */
1150 wd7000_intr_ack (host
);
1153 printk ("wd7000_intr_handle: return from interrupt handler\n");
1157 void do_wd7000_intr_handle (int irq
, void *dev_id
, struct pt_regs
*regs
)
1159 unsigned long flags
;
1161 spin_lock_irqsave(&io_request_lock
, flags
);
1162 wd7000_intr_handle(irq
, dev_id
, regs
);
1163 spin_unlock_irqrestore(&io_request_lock
, flags
);
1167 int wd7000_queuecommand (Scsi_Cmnd
*SCpnt
, void (*done
) (Scsi_Cmnd
*))
1171 register unchar
*cdb
= (unchar
*) SCpnt
->cmnd
;
1172 register unchar idlun
;
1173 register short cdblen
;
1174 Adapter
*host
= (Adapter
*) SCpnt
->host
->hostdata
;
1176 cdblen
= SCpnt
->cmd_len
;
1177 idlun
= ((SCpnt
->target
<< 5) & 0xe0) | (SCpnt
->lun
& 7);
1178 SCpnt
->scsi_done
= done
;
1179 SCpnt
->SCp
.phase
= 1;
1180 scb
= alloc_scbs (1);
1182 memcpy (scb
->cdb
, cdb
, cdblen
);
1183 scb
->direc
= 0x40; /* Disable direction check */
1185 scb
->SCpnt
= SCpnt
; /* so we can find stuff later */
1186 SCpnt
->host_scribble
= (unchar
*) scb
;
1189 if (SCpnt
->use_sg
) {
1190 struct scatterlist
*sg
= (struct scatterlist
*) SCpnt
->request_buffer
;
1193 if (SCpnt
->host
->sg_tablesize
== SG_NONE
) {
1194 panic ("wd7000_queuecommand: scatter/gather not supported.\n");
1197 printk ("Using scatter/gather with %d elements.\n", SCpnt
->use_sg
);
1202 any2scsi (scb
->dataptr
, (int) sgb
);
1203 any2scsi (scb
->maxlen
, SCpnt
->use_sg
* sizeof (Sgb
));
1205 for (i
= 0; i
< SCpnt
->use_sg
; i
++) {
1206 any2scsi (sgb
[i
].ptr
, (int) sg
[i
].address
);
1207 any2scsi (sgb
[i
].len
, sg
[i
].length
);
1212 any2scsi (scb
->dataptr
, (int) SCpnt
->request_buffer
);
1213 any2scsi (scb
->maxlen
, SCpnt
->request_bufflen
);
1216 while (!mail_out (host
, scb
)); /* keep trying */
1222 int wd7000_command (Scsi_Cmnd
*SCpnt
)
1224 wd7000_queuecommand (SCpnt
, wd7000_scsi_done
);
1226 while (SCpnt
->SCp
.phase
> 0)
1227 barrier (); /* phase counts scbs down to 0 */
1229 return (SCpnt
->result
);
1233 int wd7000_diagnostics (Adapter
*host
, int code
)
1235 static IcbDiag icb
= {ICB_OP_DIAGNOSTICS
};
1236 static unchar buf
[256];
1237 unsigned long timeout
;
1240 any2scsi (icb
.len
, sizeof (buf
));
1241 any2scsi (icb
.ptr
, (int) &buf
);
1244 * This routine is only called at init, so there should be OGMBs
1245 * available. I'm assuming so here. If this is going to
1246 * fail, I can just let the timeout catch the failure.
1248 mail_out (host
, (struct scb
*) &icb
);
1249 timeout
= jiffies
+ WAITnexttimeout
; /* wait up to 2 seconds */
1250 while (icb
.phase
&& time_before(jiffies
, timeout
))
1251 barrier (); /* wait for completion */
1254 printk ("wd7000_diagnostics: timed out.\n");
1257 if (make_code (icb
.vue
| (icb
.status
<< 8), 0)) {
1258 printk ("wd7000_diagnostics: failed (0x%02x,0x%02x)\n",
1259 icb
.vue
, icb
.status
);
1267 int wd7000_init (Adapter
*host
)
1283 * Reset the adapter - only. The SCSI bus was initialized at power-up,
1284 * and we need to do this just so we control the mailboxes, etc.
1286 outb (ASC_RES
, host
->iobase
+ ASC_CONTROL
);
1287 delay (1); /* reset pulse: this is 10ms, only need 25us */
1288 outb (0, host
->iobase
+ ASC_CONTROL
);
1289 host
->control
= 0; /* this must always shadow ASC_CONTROL */
1291 if (WAIT (host
->iobase
+ ASC_STAT
, ASC_STATMASK
, CMD_RDY
, 0)) {
1292 printk ("wd7000_init: WAIT timed out.\n");
1293 return (0); /* 0 = not ok */
1296 if ((diag
= inb (host
->iobase
+ ASC_INTR_STAT
)) != 1) {
1297 printk ("wd7000_init: ");
1300 case 2: printk ("RAM failure.\n");
1302 case 3: printk ("FIFO R/W failed\n");
1304 case 4: printk ("SBIC register R/W failed\n");
1306 case 5: printk ("Initialization D-FF failed.\n");
1308 case 6: printk ("Host IRQ D-FF failed.\n");
1310 case 7: printk ("ROM checksum error.\n");
1312 default: printk ("diagnostic code 0x%02Xh received.\n", diag
);
1317 /* Clear mailboxes */
1318 memset (&(host
->mb
), 0, sizeof (host
->mb
));
1320 /* Execute init command */
1321 any2scsi ((unchar
*) & (init_cmd
.mailboxes
), (int) &(host
->mb
));
1322 if (!command_out (host
, (unchar
*) &init_cmd
, sizeof (init_cmd
))) {
1323 printk ("wd7000_init: adapter initialization failed.\n");
1327 if (WAIT (host
->iobase
+ ASC_STAT
, ASC_STATMASK
, ASC_INIT
, 0)) {
1328 printk ("wd7000_init: WAIT timed out.\n");
1332 if (request_irq (host
->irq
, do_wd7000_intr_handle
, SA_INTERRUPT
, "wd7000", NULL
)) {
1333 printk ("wd7000_init: can't get IRQ %d.\n", host
->irq
);
1336 if (request_dma (host
->dma
, "wd7000")) {
1337 printk ("wd7000_init: can't get DMA channel %d.\n", host
->dma
);
1338 free_irq (host
->irq
, NULL
);
1341 wd7000_enable_dma (host
);
1342 wd7000_enable_intr (host
);
1344 if (!wd7000_diagnostics (host
, ICB_DIAG_FULL
)) {
1345 free_dma (host
->dma
);
1346 free_irq (host
->irq
, NULL
);
1354 void wd7000_revision (Adapter
*host
)
1356 static IcbRevLvl icb
=
1357 {ICB_OP_GET_REVISION
};
1361 * Like diagnostics, this is only done at init time, in fact, from
1362 * wd7000_detect, so there should be OGMBs available. If it fails,
1363 * the only damage will be that the revision will show up as 0.0,
1364 * which in turn means that scatter/gather will be disabled.
1366 mail_out (host
, (struct scb
*) &icb
);
1368 barrier (); /* wait for completion */
1369 host
->rev1
= icb
.primary
;
1370 host
->rev2
= icb
.secondary
;
1375 #define SPRINTF(args...) { if (pos < (buffer + length)) pos += sprintf (pos, ## args); }
1377 int wd7000_set_info (char *buffer
, int length
, struct Scsi_Host
*host
)
1379 unsigned long flags
;
1385 printk ("Buffer = <%.*s>, length = %d\n", length
, buffer
, length
);
1389 * Currently this is a no-op
1391 printk ("Sorry, this function is currently out of order...\n");
1393 restore_flags (flags
);
1399 int wd7000_proc_info (char *buffer
, char **start
, off_t offset
, int length
, int hostno
, int inout
)
1401 struct Scsi_Host
*host
= NULL
;
1404 unsigned long flags
;
1409 Mailbox
*ogmbs
, *icmbs
;
1414 * Find the specified host board.
1416 for (i
= 0; i
< IRQS
; i
++)
1417 if (wd7000_host
[i
] && (wd7000_host
[i
]->host_no
== hostno
)) {
1418 host
= wd7000_host
[i
];
1430 * Has data been written to the file ?
1433 return (wd7000_set_info (buffer
, length
, host
));
1435 adapter
= (Adapter
*) host
->hostdata
;
1440 SPRINTF ("Host scsi%d: Western Digital WD-7000 (rev %d.%d)\n", hostno
, adapter
->rev1
, adapter
->rev2
);
1441 SPRINTF (" IO base: 0x%x\n", adapter
->iobase
);
1442 SPRINTF (" IRQ: %d\n", adapter
->irq
);
1443 SPRINTF (" DMA channel: %d\n", adapter
->dma
);
1444 SPRINTF (" Interrupts: %d\n", adapter
->int_counter
);
1445 SPRINTF (" BUS_ON time: %d nanoseconds\n", adapter
->bus_on
* 125);
1446 SPRINTF (" BUS_OFF time: %d nanoseconds\n", adapter
->bus_off
* 125);
1449 ogmbs
= adapter
->mb
.ogmb
;
1450 icmbs
= adapter
->mb
.icmb
;
1452 SPRINTF ("\nControl port value: 0x%x\n", adapter
->control
);
1453 SPRINTF ("Incoming mailbox:\n");
1454 SPRINTF (" size: %d\n", ICMB_CNT
);
1455 SPRINTF (" queued messages: ");
1457 for (i
= count
= 0; i
< ICMB_CNT
; i
++)
1458 if (icmbs
[i
].status
) {
1460 SPRINTF ("0x%x ", i
);
1463 SPRINTF (count
? "\n" : "none\n");
1465 SPRINTF ("Outgoing mailbox:\n");
1466 SPRINTF (" size: %d\n", OGMB_CNT
);
1467 SPRINTF (" next message: 0x%x\n", adapter
->next_ogmb
);
1468 SPRINTF (" queued messages: ");
1470 for (i
= count
= 0; i
< OGMB_CNT
; i
++)
1471 if (ogmbs
[i
].status
) {
1473 SPRINTF ("0x%x ", i
);
1476 SPRINTF (count
? "\n" : "none\n");
1480 * Display driver information for each device attached to the board.
1482 scd
= host
->host_queue
;
1484 SPRINTF ("\nAttached devices: %s\n", scd
? "" : "none");
1486 for ( ; scd
; scd
= scd
->next
)
1487 if (scd
->host
->host_no
== hostno
) {
1488 SPRINTF (" [Channel: %02d, Id: %02d, Lun: %02d] ",
1489 scd
->channel
, scd
->id
, scd
->lun
);
1490 SPRINTF ("%s ", (scd
->type
< MAX_SCSI_DEVICE_CODE
) ?
1491 scsi_device_types
[(short) scd
->type
] : "Unknown device");
1493 for (i
= 0; (i
< 8) && (scd
->vendor
[i
] >= 0x20); i
++)
1494 SPRINTF ("%c", scd
->vendor
[i
]);
1497 for (i
= 0; (i
< 16) && (scd
->model
[i
] >= 0x20); i
++)
1498 SPRINTF ("%c", scd
->model
[i
]);
1504 restore_flags (flags
);
1507 * Calculate start of next buffer, and return value.
1509 *start
= buffer
+ offset
;
1511 if ((pos
- buffer
) < offset
)
1513 else if ((pos
- buffer
- offset
) < length
)
1514 return (pos
- buffer
- offset
);
1521 * Returns the number of adapters this driver is supporting.
1523 * The source for hosts.c says to wait to call scsi_register until 100%
1524 * sure about an adapter. We need to do it a little sooner here; we
1525 * need the storage set up by scsi_register before wd7000_init, and
1526 * changing the location of an Adapter structure is more trouble than
1527 * calling scsi_unregister.
1530 int wd7000_detect (Scsi_Host_Template
*tpnt
)
1532 short present
= 0, biosaddr_ptr
, sig_ptr
, i
, pass
;
1533 short biosptr
[NUM_CONFIGS
];
1535 Adapter
*host
= NULL
;
1536 struct Scsi_Host
*sh
;
1539 printk ("wd7000_detect: started\n");
1542 for (i
= 0; i
< IRQS
; wd7000_host
[i
++] = NULL
) ;
1543 for (i
= 0; i
< NUM_CONFIGS
; biosptr
[i
++] = -1) ;
1545 tpnt
->proc_dir
= &proc_scsi_wd7000
;
1546 tpnt
->proc_info
= &wd7000_proc_info
;
1549 * Set up SCB free list, which is shared by all adapters
1553 for (pass
= 0; pass
< NUM_CONFIGS
; pass
++) {
1555 * First, search for BIOS SIGNATURE...
1557 for (biosaddr_ptr
= 0; biosaddr_ptr
< NUM_ADDRS
; biosaddr_ptr
++)
1558 for (sig_ptr
= 0; sig_ptr
< NUM_SIGNATURES
; sig_ptr
++) {
1559 for (i
= 0; i
< pass
; i
++)
1560 if (biosptr
[i
] == biosaddr_ptr
)
1564 void *biosaddr
= ioremap (wd7000_biosaddr
[biosaddr_ptr
] +
1565 signatures
[sig_ptr
].ofs
,
1566 signatures
[sig_ptr
].len
);
1570 bios_match
= memcmp ((char *) biosaddr
, signatures
[sig_ptr
].sig
,
1571 signatures
[sig_ptr
].len
);
1582 * BIOS SIGNATURE has been found.
1585 printk ("wd7000_detect: pass %d\n", pass
+ 1);
1587 if (biosaddr_ptr
== NUM_ADDRS
)
1588 printk ("WD-7000 SST BIOS not detected...\n");
1590 printk ("WD-7000 SST BIOS detected at 0x%lx: checking...\n",
1591 wd7000_biosaddr
[biosaddr_ptr
]);
1594 if (configs
[pass
].irq
< 0)
1597 iobase
= configs
[pass
].iobase
;
1600 printk ("wd7000_detect: check IO 0x%x region...\n", iobase
);
1603 if (!check_region (iobase
, 4)) {
1606 printk ("wd7000_detect: ASC reset (IO 0x%x) ...", iobase
);
1611 outb (ASC_RES
, iobase
+ ASC_CONTROL
);
1613 outb (0, iobase
+ ASC_CONTROL
);
1615 if (WAIT (iobase
+ ASC_STAT
, ASC_STATMASK
, CMD_RDY
, 0))
1618 printk ("failed!\n");
1627 if (inb (iobase
+ ASC_INTR_STAT
) == 1) {
1629 * We register here, to get a pointer to the extra space,
1630 * which we'll use as the Adapter structure (host) for
1631 * this adapter. It is located just after the registered
1632 * Scsi_Host structure (sh), and is located by the empty
1635 sh
= scsi_register (tpnt
, sizeof (Adapter
));
1636 host
= (Adapter
*) sh
->hostdata
;
1639 printk ("wd7000_detect: adapter allocated at 0x%x\n", (int) host
);
1642 memset (host
, 0, sizeof (Adapter
));
1644 host
->irq
= configs
[pass
].irq
;
1645 host
->dma
= configs
[pass
].dma
;
1646 host
->iobase
= iobase
;
1647 host
->int_counter
= 0;
1648 host
->bus_on
= configs
[pass
].bus_on
;
1649 host
->bus_off
= configs
[pass
].bus_off
;
1650 host
->sh
= wd7000_host
[host
->irq
- IRQ_MIN
] = sh
;
1653 printk ("wd7000_detect: Trying init WD-7000 card at IO "
1654 "0x%x, IRQ %d, DMA %d...\n",
1655 host
->iobase
, host
->irq
, host
->dma
);
1658 if (!wd7000_init (host
)) { /* Initialization failed */
1659 scsi_unregister (sh
);
1665 * OK from here - we'll use this adapter/configuration.
1667 wd7000_revision (host
); /* important for scatter/gather */
1670 * Register our ports.
1672 request_region (host
->iobase
, 4, "wd7000");
1675 * For boards before rev 6.0, scatter/gather isn't supported.
1678 sh
->sg_tablesize
= SG_NONE
;
1680 present
++; /* count it */
1682 if (biosaddr_ptr
!= NUM_ADDRS
)
1683 biosptr
[pass
] = biosaddr_ptr
;
1685 printk ("Western Digital WD-7000 (rev %d.%d) ",
1686 host
->rev1
, host
->rev2
);
1687 printk ("using IO 0x%x, IRQ %d, DMA %d.\n",
1688 host
->iobase
, host
->irq
, host
->dma
);
1689 printk (" BUS_ON time: %dns, BUS_OFF time: %dns\n",
1690 host
->bus_on
* 125, host
->bus_off
* 125);
1696 printk ("wd7000_detect: IO 0x%x region already allocated!\n", iobase
);
1702 printk ("Failed initialization of WD-7000 SCSI card!\n");
1709 * I have absolutely NO idea how to do an abort with the WD7000...
1711 int wd7000_abort (Scsi_Cmnd
*SCpnt
)
1713 Adapter
*host
= (Adapter
*) SCpnt
->host
->hostdata
;
1715 if (inb (host
->iobase
+ ASC_STAT
) & INT_IM
) {
1716 printk ("wd7000_abort: lost interrupt\n");
1717 wd7000_intr_handle (host
->irq
, NULL
, NULL
);
1719 return (SCSI_ABORT_SUCCESS
);
1722 return (SCSI_ABORT_SNOOZE
);
1727 * I also have no idea how to do a reset...
1729 int wd7000_reset (Scsi_Cmnd
*SCpnt
, unsigned int unused
)
1731 return (SCSI_RESET_PUNT
);
1736 * This was borrowed directly from aha1542.c. (Zaga)
1738 int wd7000_biosparam (Disk
*disk
, kdev_t dev
, int *ip
)
1741 printk ("wd7000_biosparam: dev=%s, size=%d, ", kdevname (dev
), disk
->capacity
);
1745 * try default translation
1749 ip
[2] = disk
->capacity
/ (64 * 32);
1752 * for disks >1GB do some guessing
1754 if (ip
[2] >= 1024) {
1758 * try to figure out the geometry from the partition table
1760 if ((scsicam_bios_param (disk
, dev
, info
) < 0) ||
1761 !(((info
[0] == 64) && (info
[1] == 32)) ||
1762 ((info
[0] == 255) && (info
[1] == 63)))) {
1763 printk ("wd7000_biosparam: unable to verify geometry for disk with >1GB.\n"
1764 " using extended translation.\n");
1768 ip
[2] = disk
->capacity
/ (255 * 63);
1776 printk ("wd7000_biosparam: current partition table is using extended translation.\n");
1781 printk ("bios geometry: head=%d, sec=%d, cyl=%d\n", ip
[0], ip
[1], ip
[2]);
1782 printk ("WARNING: check, if the bios geometry is correct.\n");
1789 /* Eventually this will go into an include file, but this will be later */
1790 Scsi_Host_Template driver_template
= WD7000
;
1792 #include "scsi_module.c"