2 * Copyright (c) 1996 John Shifflett, GeoLog Consulting
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2, or (at your option)
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
18 * Drew Eckhardt's excellent 'Generic NCR5380' sources from Linux-PC
19 * provided much of the inspiration and some of the code for this
20 * driver. Everything I know about Amiga DMA was gleaned from careful
21 * reading of Hamish Mcdonald's original wd33c93 driver; in fact, I
22 * borrowed shamelessly from all over that source. Thanks Hamish!
24 * _This_ driver is (I feel) an improvement over the old one in
27 * - Target Disconnection/Reconnection is now supported. Any
28 * system with more than one device active on the SCSI bus
29 * will benefit from this. The driver defaults to what I
30 * call 'adaptive disconnect' - meaning that each command
31 * is evaluated individually as to whether or not it should
32 * be run with the option to disconnect/reselect (if the
33 * device chooses), or as a "SCSI-bus-hog".
35 * - Synchronous data transfers are now supported. Because of
36 * a few devices that choke after telling the driver that
37 * they can do sync transfers, we don't automatically use
38 * this faster protocol - it can be enabled via the command-
39 * line on a device-by-device basis.
41 * - Runtime operating parameters can now be specified through
42 * the 'amiboot' or the 'insmod' command line. For amiboot do:
43 * "amiboot [usual stuff] wd33c93=blah,blah,blah"
44 * The defaults should be good for most people. See the comment
45 * for 'setup_strings' below for more details.
47 * - The old driver relied exclusively on what the Western Digital
48 * docs call "Combination Level 2 Commands", which are a great
49 * idea in that the CPU is relieved of a lot of interrupt
50 * overhead. However, by accepting a certain (user-settable)
51 * amount of additional interrupts, this driver achieves
52 * better control over the SCSI bus, and data transfers are
53 * almost as fast while being much easier to define, track,
58 * more speed. linked commands.
61 * People with bug reports, wish-lists, complaints, comments,
62 * or improvements are asked to pah-leeez email me (John Shifflett)
63 * at john@geolog.com or jshiffle@netcom.com! I'm anxious to get
64 * this thing into as good a shape as possible, and I'm positive
65 * there are lots of lurking bugs and "Stupid Places".
69 * Added support for pre -A chips, which don't have advanced features
70 * and will generate CSR_RESEL rather than CSR_RESEL_AM.
71 * Richard Hirst <richard@sleepie.demon.co.uk> August 2000
73 * Added support for Burst Mode DMA and Fast SCSI. Enabled the use of
74 * default_sx_per for asynchronous data transfers. Added adjustment
75 * of transfer periods in sx_table to the actual input-clock.
76 * peter fuerst <post@pfrst.de> February 2007
79 #include <linux/module.h>
81 #include <linux/string.h>
82 #include <linux/delay.h>
83 #include <linux/init.h>
84 #include <linux/interrupt.h>
85 #include <linux/blkdev.h>
87 #include <scsi/scsi.h>
88 #include <scsi/scsi_cmnd.h>
89 #include <scsi/scsi_device.h>
90 #include <scsi/scsi_host.h>
96 #define optimum_sx_per(hostdata) (hostdata)->sx_table[1].period_ns
99 #define WD33C93_VERSION "1.26++"
100 #define WD33C93_DATE "10/Feb/2007"
102 MODULE_AUTHOR("John Shifflett");
103 MODULE_DESCRIPTION("Generic WD33C93 SCSI driver");
104 MODULE_LICENSE("GPL");
107 * 'setup_strings' is a single string used to pass operating parameters and
108 * settings from the kernel/module command-line to the driver. 'setup_args[]'
109 * is an array of strings that define the compile-time default values for
110 * these settings. If Linux boots with an amiboot or insmod command-line,
111 * those settings are combined with 'setup_args[]'. Note that amiboot
112 * command-lines are prefixed with "wd33c93=" while insmod uses a
113 * "setup_strings=" prefix. The driver recognizes the following keywords
114 * (lower case required) and arguments:
116 * - nosync:bitmask -bitmask is a byte where the 1st 7 bits correspond with
117 * the 7 possible SCSI devices. Set a bit to negotiate for
118 * asynchronous transfers on that device. To maintain
119 * backwards compatibility, a command-line such as
120 * "wd33c93=255" will be automatically translated to
121 * "wd33c93=nosync:0xff".
122 * - nodma:x -x = 1 to disable DMA, x = 0 to enable it. Argument is
123 * optional - if not present, same as "nodma:1".
124 * - period:ns -ns is the minimum # of nanoseconds in a SCSI data transfer
125 * period. Default is 500; acceptable values are 250 - 1000.
126 * - disconnect:x -x = 0 to never allow disconnects, 2 to always allow them.
127 * x = 1 does 'adaptive' disconnects, which is the default
128 * and generally the best choice.
129 * - debug:x -If 'DEBUGGING_ON' is defined, x is a bit mask that causes
130 * various types of debug output to printed - see the DB_xxx
131 * defines in wd33c93.h
132 * - clock:x -x = clock input in MHz for WD33c93 chip. Normal values
133 * would be from 8 through 20. Default is 8.
134 * - burst:x -x = 1 to use Burst Mode (or Demand-Mode) DMA, x = 0 to use
135 * Single Byte DMA, which is the default. Argument is
136 * optional - if not present, same as "burst:1".
137 * - fast:x -x = 1 to enable Fast SCSI, which is only effective with
138 * input-clock divisor 4 (WD33C93_FS_16_20), x = 0 to disable
139 * it, which is the default. Argument is optional - if not
140 * present, same as "fast:1".
141 * - next -No argument. Used to separate blocks of keywords when
142 * there's more than one host adapter in the system.
145 * - Numeric arguments can be decimal or the '0x' form of hex notation. There
146 * _must_ be a colon between a keyword and its numeric argument, with no
148 * - Keywords are separated by commas, no spaces, in the standard kernel
149 * command-line manner.
150 * - A keyword in the 'nth' comma-separated command-line member will overwrite
151 * the 'nth' element of setup_args[]. A blank command-line member (in
152 * other words, a comma with no preceding keyword) will _not_ overwrite
153 * the corresponding setup_args[] element.
154 * - If a keyword is used more than once, the first one applies to the first
155 * SCSI host found, the second to the second card, etc, unless the 'next'
156 * keyword is used to change the order.
158 * Some amiboot examples (for insmod, use 'setup_strings' instead of 'wd33c93'):
159 * - wd33c93=nosync:255
162 * - wd33c93=disconnect:2,nosync:0x08,period:250
163 * - wd33c93=debug:0x1c
166 /* Normally, no defaults are specified */
167 static char *setup_args
[] = { "", "", "", "", "", "", "", "", "", "" };
169 static char *setup_strings
;
170 module_param(setup_strings
, charp
, 0);
172 static void wd33c93_execute(struct Scsi_Host
*instance
);
174 #ifdef CONFIG_WD33C93_PIO
176 read_wd33c93(const wd33c93_regs regs
, uchar reg_num
)
180 outb(reg_num
, regs
.SASR
);
181 data
= inb(regs
.SCMD
);
185 static inline unsigned long
186 read_wd33c93_count(const wd33c93_regs regs
)
190 outb(WD_TRANSFER_COUNT_MSB
, regs
.SASR
);
191 value
= inb(regs
.SCMD
) << 16;
192 value
|= inb(regs
.SCMD
) << 8;
193 value
|= inb(regs
.SCMD
);
198 read_aux_stat(const wd33c93_regs regs
)
200 return inb(regs
.SASR
);
204 write_wd33c93(const wd33c93_regs regs
, uchar reg_num
, uchar value
)
206 outb(reg_num
, regs
.SASR
);
207 outb(value
, regs
.SCMD
);
211 write_wd33c93_count(const wd33c93_regs regs
, unsigned long value
)
213 outb(WD_TRANSFER_COUNT_MSB
, regs
.SASR
);
214 outb((value
>> 16) & 0xff, regs
.SCMD
);
215 outb((value
>> 8) & 0xff, regs
.SCMD
);
216 outb( value
& 0xff, regs
.SCMD
);
219 #define write_wd33c93_cmd(regs, cmd) \
220 write_wd33c93((regs), WD_COMMAND, (cmd))
223 write_wd33c93_cdb(const wd33c93_regs regs
, uint len
, uchar cmnd
[])
227 outb(WD_CDB_1
, regs
.SASR
);
228 for (i
=0; i
<len
; i
++)
229 outb(cmnd
[i
], regs
.SCMD
);
232 #else /* CONFIG_WD33C93_PIO */
234 read_wd33c93(const wd33c93_regs regs
, uchar reg_num
)
236 *regs
.SASR
= reg_num
;
242 read_wd33c93_count(const wd33c93_regs regs
)
246 *regs
.SASR
= WD_TRANSFER_COUNT_MSB
;
248 value
= *regs
.SCMD
<< 16;
249 value
|= *regs
.SCMD
<< 8;
256 read_aux_stat(const wd33c93_regs regs
)
262 write_wd33c93(const wd33c93_regs regs
, uchar reg_num
, uchar value
)
264 *regs
.SASR
= reg_num
;
271 write_wd33c93_count(const wd33c93_regs regs
, unsigned long value
)
273 *regs
.SASR
= WD_TRANSFER_COUNT_MSB
;
275 *regs
.SCMD
= value
>> 16;
276 *regs
.SCMD
= value
>> 8;
282 write_wd33c93_cmd(const wd33c93_regs regs
, uchar cmd
)
284 *regs
.SASR
= WD_COMMAND
;
291 write_wd33c93_cdb(const wd33c93_regs regs
, uint len
, uchar cmnd
[])
295 *regs
.SASR
= WD_CDB_1
;
296 for (i
= 0; i
< len
; i
++)
297 *regs
.SCMD
= cmnd
[i
];
299 #endif /* CONFIG_WD33C93_PIO */
302 read_1_byte(const wd33c93_regs regs
)
307 write_wd33c93(regs
, WD_CONTROL
, CTRL_IDI
| CTRL_EDI
| CTRL_POLLED
);
308 write_wd33c93_cmd(regs
, WD_CMD_TRANS_INFO
| 0x80);
310 asr
= read_aux_stat(regs
);
312 x
= read_wd33c93(regs
, WD_DATA
);
313 } while (!(asr
& ASR_INT
));
318 round_period(unsigned int period
, const struct sx_period
*sx_table
)
322 for (x
= 1; sx_table
[x
].period_ns
; x
++) {
323 if ((period
<= sx_table
[x
- 0].period_ns
) &&
324 (period
> sx_table
[x
- 1].period_ns
)) {
332 * Calculate Synchronous Transfer Register value from SDTR code.
335 calc_sync_xfer(unsigned int period
, unsigned int offset
, unsigned int fast
,
336 const struct sx_period
*sx_table
)
338 /* When doing Fast SCSI synchronous data transfers, the corresponding
339 * value in 'sx_table' is two times the actually used transfer period.
343 if (offset
&& fast
) {
349 period
*= 4; /* convert SDTR code to ns */
350 result
= sx_table
[round_period(period
,sx_table
)].reg_value
;
351 result
|= (offset
< OPTIMUM_SX_OFF
) ? offset
: OPTIMUM_SX_OFF
;
357 * Calculate SDTR code bytes [3],[4] from period and offset.
360 calc_sync_msg(unsigned int period
, unsigned int offset
, unsigned int fast
,
363 /* 'period' is a "normal"-mode value, like the ones in 'sx_table'. The
364 * actually used transfer period for Fast SCSI synchronous data
365 * transfers is half that value.
375 wd33c93_queuecommand(struct scsi_cmnd
*cmd
,
376 void (*done
)(struct scsi_cmnd
*))
378 struct WD33C93_hostdata
*hostdata
;
379 struct scsi_cmnd
*tmp
;
381 hostdata
= (struct WD33C93_hostdata
*) cmd
->device
->host
->hostdata
;
384 printk("Q-%d-%02x-%ld( ", cmd
->device
->id
, cmd
->cmnd
[0], cmd
->serial_number
))
386 /* Set up a few fields in the scsi_cmnd structure for our own use:
387 * - host_scribble is the pointer to the next cmd in the input queue
388 * - scsi_done points to the routine we call when a cmd is finished
389 * - result is what you'd expect
391 cmd
->host_scribble
= NULL
;
392 cmd
->scsi_done
= done
;
395 /* We use the Scsi_Pointer structure that's included with each command
396 * as a scratchpad (as it's intended to be used!). The handy thing about
397 * the SCp.xxx fields is that they're always associated with a given
398 * cmd, and are preserved across disconnect-reselect. This means we
399 * can pretty much ignore SAVE_POINTERS and RESTORE_POINTERS messages
400 * if we keep all the critical pointers and counters in SCp:
401 * - SCp.ptr is the pointer into the RAM buffer
402 * - SCp.this_residual is the size of that buffer
403 * - SCp.buffer points to the current scatter-gather buffer
404 * - SCp.buffers_residual tells us how many S.G. buffers there are
405 * - SCp.have_data_in is not used
406 * - SCp.sent_command is not used
407 * - SCp.phase records this command's SRCID_ER bit setting
411 cmd
->SCp
.buffer
= (struct scatterlist
*) cmd
->request_buffer
;
412 cmd
->SCp
.buffers_residual
= cmd
->use_sg
- 1;
413 cmd
->SCp
.ptr
= page_address(cmd
->SCp
.buffer
->page
) +
414 cmd
->SCp
.buffer
->offset
;
415 cmd
->SCp
.this_residual
= cmd
->SCp
.buffer
->length
;
417 cmd
->SCp
.buffer
= NULL
;
418 cmd
->SCp
.buffers_residual
= 0;
419 cmd
->SCp
.ptr
= (char *) cmd
->request_buffer
;
420 cmd
->SCp
.this_residual
= cmd
->request_bufflen
;
423 /* WD docs state that at the conclusion of a "LEVEL2" command, the
424 * status byte can be retrieved from the LUN register. Apparently,
425 * this is the case only for *uninterrupted* LEVEL2 commands! If
426 * there are any unexpected phases entered, even if they are 100%
427 * legal (different devices may choose to do things differently),
428 * the LEVEL2 command sequence is exited. This often occurs prior
429 * to receiving the status byte, in which case the driver does a
430 * status phase interrupt and gets the status byte on its own.
431 * While such a command can then be "resumed" (ie restarted to
432 * finish up as a LEVEL2 command), the LUN register will NOT be
433 * a valid status byte at the command's conclusion, and we must
434 * use the byte obtained during the earlier interrupt. Here, we
435 * preset SCp.Status to an illegal value (0xff) so that when
436 * this command finally completes, we can tell where the actual
437 * status byte is stored.
440 cmd
->SCp
.Status
= ILLEGAL_STATUS_BYTE
;
443 * Add the cmd to the end of 'input_Q'. Note that REQUEST SENSE
444 * commands are added to the head of the queue so that the desired
445 * sense data is not lost before REQUEST_SENSE executes.
448 spin_lock_irq(&hostdata
->lock
);
450 if (!(hostdata
->input_Q
) || (cmd
->cmnd
[0] == REQUEST_SENSE
)) {
451 cmd
->host_scribble
= (uchar
*) hostdata
->input_Q
;
452 hostdata
->input_Q
= cmd
;
453 } else { /* find the end of the queue */
454 for (tmp
= (struct scsi_cmnd
*) hostdata
->input_Q
;
456 tmp
= (struct scsi_cmnd
*) tmp
->host_scribble
) ;
457 tmp
->host_scribble
= (uchar
*) cmd
;
460 /* We know that there's at least one command in 'input_Q' now.
461 * Go see if any of them are runnable!
464 wd33c93_execute(cmd
->device
->host
);
466 DB(DB_QUEUE_COMMAND
, printk(")Q-%ld ", cmd
->serial_number
))
468 spin_unlock_irq(&hostdata
->lock
);
473 * This routine attempts to start a scsi command. If the host_card is
474 * already connected, we give up immediately. Otherwise, look through
475 * the input_Q, using the first command we find that's intended
476 * for a currently non-busy target/lun.
478 * wd33c93_execute() is always called with interrupts disabled or from
479 * the wd33c93_intr itself, which means that a wd33c93 interrupt
480 * cannot occur while we are in here.
483 wd33c93_execute(struct Scsi_Host
*instance
)
485 struct WD33C93_hostdata
*hostdata
=
486 (struct WD33C93_hostdata
*) instance
->hostdata
;
487 const wd33c93_regs regs
= hostdata
->regs
;
488 struct scsi_cmnd
*cmd
, *prev
;
490 DB(DB_EXECUTE
, printk("EX("))
491 if (hostdata
->selecting
|| hostdata
->connected
) {
492 DB(DB_EXECUTE
, printk(")EX-0 "))
497 * Search through the input_Q for a command destined
498 * for an idle target/lun.
501 cmd
= (struct scsi_cmnd
*) hostdata
->input_Q
;
504 if (!(hostdata
->busy
[cmd
->device
->id
] & (1 << cmd
->device
->lun
)))
507 cmd
= (struct scsi_cmnd
*) cmd
->host_scribble
;
510 /* quit if queue empty or all possible targets are busy */
513 DB(DB_EXECUTE
, printk(")EX-1 "))
517 /* remove command from queue */
520 prev
->host_scribble
= cmd
->host_scribble
;
522 hostdata
->input_Q
= (struct scsi_cmnd
*) cmd
->host_scribble
;
524 #ifdef PROC_STATISTICS
525 hostdata
->cmd_cnt
[cmd
->device
->id
]++;
529 * Start the selection process
532 if (cmd
->sc_data_direction
== DMA_TO_DEVICE
)
533 write_wd33c93(regs
, WD_DESTINATION_ID
, cmd
->device
->id
);
535 write_wd33c93(regs
, WD_DESTINATION_ID
, cmd
->device
->id
| DSTID_DPD
);
537 /* Now we need to figure out whether or not this command is a good
538 * candidate for disconnect/reselect. We guess to the best of our
539 * ability, based on a set of hierarchical rules. When several
540 * devices are operating simultaneously, disconnects are usually
541 * an advantage. In a single device system, or if only 1 device
542 * is being accessed, transfers usually go faster if disconnects
545 * + Commands should NEVER disconnect if hostdata->disconnect =
546 * DIS_NEVER (this holds for tape drives also), and ALWAYS
547 * disconnect if hostdata->disconnect = DIS_ALWAYS.
548 * + Tape drive commands should always be allowed to disconnect.
549 * + Disconnect should be allowed if disconnected_Q isn't empty.
550 * + Commands should NOT disconnect if input_Q is empty.
551 * + Disconnect should be allowed if there are commands in input_Q
552 * for a different target/lun. In this case, the other commands
553 * should be made disconnect-able, if not already.
555 * I know, I know - this code would flunk me out of any
556 * "C Programming 101" class ever offered. But it's easy
557 * to change around and experiment with for now.
560 cmd
->SCp
.phase
= 0; /* assume no disconnect */
561 if (hostdata
->disconnect
== DIS_NEVER
)
563 if (hostdata
->disconnect
== DIS_ALWAYS
)
565 if (cmd
->device
->type
== 1) /* tape drive? */
567 if (hostdata
->disconnected_Q
) /* other commands disconnected? */
569 if (!(hostdata
->input_Q
)) /* input_Q empty? */
571 for (prev
= (struct scsi_cmnd
*) hostdata
->input_Q
; prev
;
572 prev
= (struct scsi_cmnd
*) prev
->host_scribble
) {
573 if ((prev
->device
->id
!= cmd
->device
->id
) ||
574 (prev
->device
->lun
!= cmd
->device
->lun
)) {
575 for (prev
= (struct scsi_cmnd
*) hostdata
->input_Q
; prev
;
576 prev
= (struct scsi_cmnd
*) prev
->host_scribble
)
587 #ifdef PROC_STATISTICS
588 hostdata
->disc_allowed_cnt
[cmd
->device
->id
]++;
593 write_wd33c93(regs
, WD_SOURCE_ID
, ((cmd
->SCp
.phase
) ? SRCID_ER
: 0));
595 write_wd33c93(regs
, WD_TARGET_LUN
, cmd
->device
->lun
);
596 write_wd33c93(regs
, WD_SYNCHRONOUS_TRANSFER
,
597 hostdata
->sync_xfer
[cmd
->device
->id
]);
598 hostdata
->busy
[cmd
->device
->id
] |= (1 << cmd
->device
->lun
);
600 if ((hostdata
->level2
== L2_NONE
) ||
601 (hostdata
->sync_stat
[cmd
->device
->id
] == SS_UNSET
)) {
604 * Do a 'Select-With-ATN' command. This will end with
605 * one of the following interrupts:
606 * CSR_RESEL_AM: failure - can try again later.
607 * CSR_TIMEOUT: failure - give up.
608 * CSR_SELECT: success - proceed.
611 hostdata
->selecting
= cmd
;
613 /* Every target has its own synchronous transfer setting, kept in the
614 * sync_xfer array, and a corresponding status byte in sync_stat[].
615 * Each target's sync_stat[] entry is initialized to SX_UNSET, and its
616 * sync_xfer[] entry is initialized to the default/safe value. SS_UNSET
617 * means that the parameters are undetermined as yet, and that we
618 * need to send an SDTR message to this device after selection is
619 * complete: We set SS_FIRST to tell the interrupt routine to do so.
620 * If we've been asked not to try synchronous transfers on this
621 * target (and _all_ luns within it), we'll still send the SDTR message
622 * later, but at that time we'll negotiate for async by specifying a
623 * sync fifo depth of 0.
625 if (hostdata
->sync_stat
[cmd
->device
->id
] == SS_UNSET
)
626 hostdata
->sync_stat
[cmd
->device
->id
] = SS_FIRST
;
627 hostdata
->state
= S_SELECTING
;
628 write_wd33c93_count(regs
, 0); /* guarantee a DATA_PHASE interrupt */
629 write_wd33c93_cmd(regs
, WD_CMD_SEL_ATN
);
633 * Do a 'Select-With-ATN-Xfer' command. This will end with
634 * one of the following interrupts:
635 * CSR_RESEL_AM: failure - can try again later.
636 * CSR_TIMEOUT: failure - give up.
637 * anything else: success - proceed.
640 hostdata
->connected
= cmd
;
641 write_wd33c93(regs
, WD_COMMAND_PHASE
, 0);
643 /* copy command_descriptor_block into WD chip
644 * (take advantage of auto-incrementing)
647 write_wd33c93_cdb(regs
, cmd
->cmd_len
, cmd
->cmnd
);
649 /* The wd33c93 only knows about Group 0, 1, and 5 commands when
650 * it's doing a 'select-and-transfer'. To be safe, we write the
651 * size of the CDB into the OWN_ID register for every case. This
652 * way there won't be problems with vendor-unique, audio, etc.
655 write_wd33c93(regs
, WD_OWN_ID
, cmd
->cmd_len
);
657 /* When doing a non-disconnect command with DMA, we can save
658 * ourselves a DATA phase interrupt later by setting everything
662 if ((cmd
->SCp
.phase
== 0) && (hostdata
->no_dma
== 0)) {
663 if (hostdata
->dma_setup(cmd
,
664 (cmd
->sc_data_direction
== DMA_TO_DEVICE
) ?
665 DATA_OUT_DIR
: DATA_IN_DIR
))
666 write_wd33c93_count(regs
, 0); /* guarantee a DATA_PHASE interrupt */
668 write_wd33c93_count(regs
,
669 cmd
->SCp
.this_residual
);
670 write_wd33c93(regs
, WD_CONTROL
,
671 CTRL_IDI
| CTRL_EDI
| hostdata
->dma_mode
);
672 hostdata
->dma
= D_DMA_RUNNING
;
675 write_wd33c93_count(regs
, 0); /* guarantee a DATA_PHASE interrupt */
677 hostdata
->state
= S_RUNNING_LEVEL2
;
678 write_wd33c93_cmd(regs
, WD_CMD_SEL_ATN_XFER
);
682 * Since the SCSI bus can handle only 1 connection at a time,
683 * we get out of here now. If the selection fails, or when
684 * the command disconnects, we'll come back to this routine
685 * to search the input_Q again...
689 printk("%s%ld)EX-2 ", (cmd
->SCp
.phase
) ? "d:" : "", cmd
->serial_number
))
693 transfer_pio(const wd33c93_regs regs
, uchar
* buf
, int cnt
,
694 int data_in_dir
, struct WD33C93_hostdata
*hostdata
)
699 printk("(%p,%d,%s:", buf
, cnt
, data_in_dir
? "in" : "out"))
701 write_wd33c93(regs
, WD_CONTROL
, CTRL_IDI
| CTRL_EDI
| CTRL_POLLED
);
702 write_wd33c93_count(regs
, cnt
);
703 write_wd33c93_cmd(regs
, WD_CMD_TRANS_INFO
);
706 asr
= read_aux_stat(regs
);
708 *buf
++ = read_wd33c93(regs
, WD_DATA
);
709 } while (!(asr
& ASR_INT
));
712 asr
= read_aux_stat(regs
);
714 write_wd33c93(regs
, WD_DATA
, *buf
++);
715 } while (!(asr
& ASR_INT
));
718 /* Note: we are returning with the interrupt UN-cleared.
719 * Since (presumably) an entire I/O operation has
720 * completed, the bus phase is probably different, and
721 * the interrupt routine will discover this when it
722 * responds to the uncleared int.
728 transfer_bytes(const wd33c93_regs regs
, struct scsi_cmnd
*cmd
,
731 struct WD33C93_hostdata
*hostdata
;
732 unsigned long length
;
734 hostdata
= (struct WD33C93_hostdata
*) cmd
->device
->host
->hostdata
;
736 /* Normally, you'd expect 'this_residual' to be non-zero here.
737 * In a series of scatter-gather transfers, however, this
738 * routine will usually be called with 'this_residual' equal
739 * to 0 and 'buffers_residual' non-zero. This means that a
740 * previous transfer completed, clearing 'this_residual', and
741 * now we need to setup the next scatter-gather buffer as the
742 * source or destination for THIS transfer.
744 if (!cmd
->SCp
.this_residual
&& cmd
->SCp
.buffers_residual
) {
746 --cmd
->SCp
.buffers_residual
;
747 cmd
->SCp
.this_residual
= cmd
->SCp
.buffer
->length
;
748 cmd
->SCp
.ptr
= page_address(cmd
->SCp
.buffer
->page
) +
749 cmd
->SCp
.buffer
->offset
;
751 if (!cmd
->SCp
.this_residual
) /* avoid bogus setups */
754 write_wd33c93(regs
, WD_SYNCHRONOUS_TRANSFER
,
755 hostdata
->sync_xfer
[cmd
->device
->id
]);
757 /* 'hostdata->no_dma' is TRUE if we don't even want to try DMA.
758 * Update 'this_residual' and 'ptr' after 'transfer_pio()' returns.
761 if (hostdata
->no_dma
|| hostdata
->dma_setup(cmd
, data_in_dir
)) {
762 #ifdef PROC_STATISTICS
765 transfer_pio(regs
, (uchar
*) cmd
->SCp
.ptr
,
766 cmd
->SCp
.this_residual
, data_in_dir
, hostdata
);
767 length
= cmd
->SCp
.this_residual
;
768 cmd
->SCp
.this_residual
= read_wd33c93_count(regs
);
769 cmd
->SCp
.ptr
+= (length
- cmd
->SCp
.this_residual
);
772 /* We are able to do DMA (in fact, the Amiga hardware is
773 * already going!), so start up the wd33c93 in DMA mode.
774 * We set 'hostdata->dma' = D_DMA_RUNNING so that when the
775 * transfer completes and causes an interrupt, we're
776 * reminded to tell the Amiga to shut down its end. We'll
777 * postpone the updating of 'this_residual' and 'ptr'
782 #ifdef PROC_STATISTICS
785 write_wd33c93(regs
, WD_CONTROL
, CTRL_IDI
| CTRL_EDI
| hostdata
->dma_mode
);
786 write_wd33c93_count(regs
, cmd
->SCp
.this_residual
);
788 if ((hostdata
->level2
>= L2_DATA
) ||
789 (hostdata
->level2
== L2_BASIC
&& cmd
->SCp
.phase
== 0)) {
790 write_wd33c93(regs
, WD_COMMAND_PHASE
, 0x45);
791 write_wd33c93_cmd(regs
, WD_CMD_SEL_ATN_XFER
);
792 hostdata
->state
= S_RUNNING_LEVEL2
;
794 write_wd33c93_cmd(regs
, WD_CMD_TRANS_INFO
);
796 hostdata
->dma
= D_DMA_RUNNING
;
801 wd33c93_intr(struct Scsi_Host
*instance
)
803 struct WD33C93_hostdata
*hostdata
=
804 (struct WD33C93_hostdata
*) instance
->hostdata
;
805 const wd33c93_regs regs
= hostdata
->regs
;
806 struct scsi_cmnd
*patch
, *cmd
;
807 uchar asr
, sr
, phs
, id
, lun
, *ucp
, msg
;
808 unsigned long length
, flags
;
810 asr
= read_aux_stat(regs
);
811 if (!(asr
& ASR_INT
) || (asr
& ASR_BSY
))
814 spin_lock_irqsave(&hostdata
->lock
, flags
);
816 #ifdef PROC_STATISTICS
820 cmd
= (struct scsi_cmnd
*) hostdata
->connected
; /* assume we're connected */
821 sr
= read_wd33c93(regs
, WD_SCSI_STATUS
); /* clear the interrupt */
822 phs
= read_wd33c93(regs
, WD_COMMAND_PHASE
);
824 DB(DB_INTR
, printk("{%02x:%02x-", asr
, sr
))
826 /* After starting a DMA transfer, the next interrupt
827 * is guaranteed to be in response to completion of
828 * the transfer. Since the Amiga DMA hardware runs in
829 * in an open-ended fashion, it needs to be told when
830 * to stop; do that here if D_DMA_RUNNING is true.
831 * Also, we have to update 'this_residual' and 'ptr'
832 * based on the contents of the TRANSFER_COUNT register,
833 * in case the device decided to do an intermediate
834 * disconnect (a device may do this if it has to do a
835 * seek, or just to be nice and let other devices have
836 * some bus time during long transfers). After doing
837 * whatever is needed, we go on and service the WD3393
838 * interrupt normally.
840 if (hostdata
->dma
== D_DMA_RUNNING
) {
842 printk("[%p/%d:", cmd
->SCp
.ptr
, cmd
->SCp
.this_residual
))
843 hostdata
->dma_stop(cmd
->device
->host
, cmd
, 1);
844 hostdata
->dma
= D_DMA_OFF
;
845 length
= cmd
->SCp
.this_residual
;
846 cmd
->SCp
.this_residual
= read_wd33c93_count(regs
);
847 cmd
->SCp
.ptr
+= (length
- cmd
->SCp
.this_residual
);
849 printk("%p/%d]", cmd
->SCp
.ptr
, cmd
->SCp
.this_residual
))
852 /* Respond to the specific WD3393 interrupt - there are quite a few! */
855 DB(DB_INTR
, printk("TIMEOUT"))
857 if (hostdata
->state
== S_RUNNING_LEVEL2
)
858 hostdata
->connected
= NULL
;
860 cmd
= (struct scsi_cmnd
*) hostdata
->selecting
; /* get a valid cmd */
861 hostdata
->selecting
= NULL
;
864 cmd
->result
= DID_NO_CONNECT
<< 16;
865 hostdata
->busy
[cmd
->device
->id
] &= ~(1 << cmd
->device
->lun
);
866 hostdata
->state
= S_UNCONNECTED
;
870 * There is a window of time within the scsi_done() path
871 * of execution where interrupts are turned back on full
872 * blast and left that way. During that time we could
873 * reconnect to a disconnected command, then we'd bomb
874 * out below. We could also end up executing two commands
875 * at _once_. ...just so you know why the restore_flags()
879 spin_unlock_irqrestore(&hostdata
->lock
, flags
);
881 /* We are not connected to a target - check to see if there
882 * are commands waiting to be executed.
885 wd33c93_execute(instance
);
888 /* Note: this interrupt should not occur in a LEVEL2 command */
891 DB(DB_INTR
, printk("SELECT"))
892 hostdata
->connected
= cmd
=
893 (struct scsi_cmnd
*) hostdata
->selecting
;
894 hostdata
->selecting
= NULL
;
896 /* construct an IDENTIFY message with correct disconnect bit */
898 hostdata
->outgoing_msg
[0] = (0x80 | 0x00 | cmd
->device
->lun
);
900 hostdata
->outgoing_msg
[0] |= 0x40;
902 if (hostdata
->sync_stat
[cmd
->device
->id
] == SS_FIRST
) {
904 hostdata
->sync_stat
[cmd
->device
->id
] = SS_WAITING
;
906 /* Tack on a 2nd message to ask about synchronous transfers. If we've
907 * been asked to do only asynchronous transfers on this device, we
908 * request a fifo depth of 0, which is equivalent to async - should
909 * solve the problems some people have had with GVP's Guru ROM.
912 hostdata
->outgoing_msg
[1] = EXTENDED_MESSAGE
;
913 hostdata
->outgoing_msg
[2] = 3;
914 hostdata
->outgoing_msg
[3] = EXTENDED_SDTR
;
915 if (hostdata
->no_sync
& (1 << cmd
->device
->id
)) {
916 calc_sync_msg(hostdata
->default_sx_per
, 0,
917 0, hostdata
->outgoing_msg
+ 4);
919 calc_sync_msg(optimum_sx_per(hostdata
),
922 hostdata
->outgoing_msg
+ 4);
924 hostdata
->outgoing_len
= 6;
926 ucp
= hostdata
->outgoing_msg
+ 1;
927 printk(" sending SDTR %02x03%02x%02x%02x ",
928 ucp
[0], ucp
[2], ucp
[3], ucp
[4]);
931 hostdata
->outgoing_len
= 1;
933 hostdata
->state
= S_CONNECTED
;
934 spin_unlock_irqrestore(&hostdata
->lock
, flags
);
937 case CSR_XFER_DONE
| PHS_DATA_IN
:
938 case CSR_UNEXP
| PHS_DATA_IN
:
939 case CSR_SRV_REQ
| PHS_DATA_IN
:
941 printk("IN-%d.%d", cmd
->SCp
.this_residual
,
942 cmd
->SCp
.buffers_residual
))
943 transfer_bytes(regs
, cmd
, DATA_IN_DIR
);
944 if (hostdata
->state
!= S_RUNNING_LEVEL2
)
945 hostdata
->state
= S_CONNECTED
;
946 spin_unlock_irqrestore(&hostdata
->lock
, flags
);
949 case CSR_XFER_DONE
| PHS_DATA_OUT
:
950 case CSR_UNEXP
| PHS_DATA_OUT
:
951 case CSR_SRV_REQ
| PHS_DATA_OUT
:
953 printk("OUT-%d.%d", cmd
->SCp
.this_residual
,
954 cmd
->SCp
.buffers_residual
))
955 transfer_bytes(regs
, cmd
, DATA_OUT_DIR
);
956 if (hostdata
->state
!= S_RUNNING_LEVEL2
)
957 hostdata
->state
= S_CONNECTED
;
958 spin_unlock_irqrestore(&hostdata
->lock
, flags
);
961 /* Note: this interrupt should not occur in a LEVEL2 command */
963 case CSR_XFER_DONE
| PHS_COMMAND
:
964 case CSR_UNEXP
| PHS_COMMAND
:
965 case CSR_SRV_REQ
| PHS_COMMAND
:
966 DB(DB_INTR
, printk("CMND-%02x,%ld", cmd
->cmnd
[0], cmd
->serial_number
))
967 transfer_pio(regs
, cmd
->cmnd
, cmd
->cmd_len
, DATA_OUT_DIR
,
969 hostdata
->state
= S_CONNECTED
;
970 spin_unlock_irqrestore(&hostdata
->lock
, flags
);
973 case CSR_XFER_DONE
| PHS_STATUS
:
974 case CSR_UNEXP
| PHS_STATUS
:
975 case CSR_SRV_REQ
| PHS_STATUS
:
976 DB(DB_INTR
, printk("STATUS="))
977 cmd
->SCp
.Status
= read_1_byte(regs
);
978 DB(DB_INTR
, printk("%02x", cmd
->SCp
.Status
))
979 if (hostdata
->level2
>= L2_BASIC
) {
980 sr
= read_wd33c93(regs
, WD_SCSI_STATUS
); /* clear interrupt */
982 hostdata
->state
= S_RUNNING_LEVEL2
;
983 write_wd33c93(regs
, WD_COMMAND_PHASE
, 0x50);
984 write_wd33c93_cmd(regs
, WD_CMD_SEL_ATN_XFER
);
986 hostdata
->state
= S_CONNECTED
;
988 spin_unlock_irqrestore(&hostdata
->lock
, flags
);
991 case CSR_XFER_DONE
| PHS_MESS_IN
:
992 case CSR_UNEXP
| PHS_MESS_IN
:
993 case CSR_SRV_REQ
| PHS_MESS_IN
:
994 DB(DB_INTR
, printk("MSG_IN="))
996 msg
= read_1_byte(regs
);
997 sr
= read_wd33c93(regs
, WD_SCSI_STATUS
); /* clear interrupt */
1000 hostdata
->incoming_msg
[hostdata
->incoming_ptr
] = msg
;
1001 if (hostdata
->incoming_msg
[0] == EXTENDED_MESSAGE
)
1002 msg
= EXTENDED_MESSAGE
;
1004 hostdata
->incoming_ptr
= 0;
1006 cmd
->SCp
.Message
= msg
;
1009 case COMMAND_COMPLETE
:
1010 DB(DB_INTR
, printk("CCMP-%ld", cmd
->serial_number
))
1011 write_wd33c93_cmd(regs
, WD_CMD_NEGATE_ACK
);
1012 hostdata
->state
= S_PRE_CMP_DISC
;
1016 DB(DB_INTR
, printk("SDP"))
1017 write_wd33c93_cmd(regs
, WD_CMD_NEGATE_ACK
);
1018 hostdata
->state
= S_CONNECTED
;
1021 case RESTORE_POINTERS
:
1022 DB(DB_INTR
, printk("RDP"))
1023 if (hostdata
->level2
>= L2_BASIC
) {
1024 write_wd33c93(regs
, WD_COMMAND_PHASE
, 0x45);
1025 write_wd33c93_cmd(regs
, WD_CMD_SEL_ATN_XFER
);
1026 hostdata
->state
= S_RUNNING_LEVEL2
;
1028 write_wd33c93_cmd(regs
, WD_CMD_NEGATE_ACK
);
1029 hostdata
->state
= S_CONNECTED
;
1034 DB(DB_INTR
, printk("DIS"))
1035 cmd
->device
->disconnect
= 1;
1036 write_wd33c93_cmd(regs
, WD_CMD_NEGATE_ACK
);
1037 hostdata
->state
= S_PRE_TMP_DISC
;
1040 case MESSAGE_REJECT
:
1041 DB(DB_INTR
, printk("REJ"))
1045 if (hostdata
->sync_stat
[cmd
->device
->id
] == SS_WAITING
) {
1046 hostdata
->sync_stat
[cmd
->device
->id
] = SS_SET
;
1047 /* we want default_sx_per, not DEFAULT_SX_PER */
1048 hostdata
->sync_xfer
[cmd
->device
->id
] =
1049 calc_sync_xfer(hostdata
->default_sx_per
1050 / 4, 0, 0, hostdata
->sx_table
);
1052 write_wd33c93_cmd(regs
, WD_CMD_NEGATE_ACK
);
1053 hostdata
->state
= S_CONNECTED
;
1056 case EXTENDED_MESSAGE
:
1057 DB(DB_INTR
, printk("EXT"))
1059 ucp
= hostdata
->incoming_msg
;
1062 printk("%02x", ucp
[hostdata
->incoming_ptr
]);
1064 /* Is this the last byte of the extended message? */
1066 if ((hostdata
->incoming_ptr
>= 2) &&
1067 (hostdata
->incoming_ptr
== (ucp
[1] + 1))) {
1069 switch (ucp
[2]) { /* what's the EXTENDED code? */
1071 /* default to default async period */
1072 id
= calc_sync_xfer(hostdata
->
1073 default_sx_per
/ 4, 0,
1074 0, hostdata
->sx_table
);
1075 if (hostdata
->sync_stat
[cmd
->device
->id
] !=
1078 /* A device has sent an unsolicited SDTR message; rather than go
1079 * through the effort of decoding it and then figuring out what
1080 * our reply should be, we're just gonna say that we have a
1081 * synchronous fifo depth of 0. This will result in asynchronous
1082 * transfers - not ideal but so much easier.
1083 * Actually, this is OK because it assures us that if we don't
1084 * specifically ask for sync transfers, we won't do any.
1087 write_wd33c93_cmd(regs
, WD_CMD_ASSERT_ATN
); /* want MESS_OUT */
1088 hostdata
->outgoing_msg
[0] =
1090 hostdata
->outgoing_msg
[1] = 3;
1091 hostdata
->outgoing_msg
[2] =
1093 calc_sync_msg(hostdata
->
1095 0, hostdata
->outgoing_msg
+ 3);
1096 hostdata
->outgoing_len
= 5;
1098 if (ucp
[4]) /* well, sync transfer */
1099 id
= calc_sync_xfer(ucp
[3], ucp
[4],
1101 hostdata
->sx_table
);
1102 else if (ucp
[3]) /* very unlikely... */
1103 id
= calc_sync_xfer(ucp
[3], ucp
[4],
1104 0, hostdata
->sx_table
);
1106 hostdata
->sync_xfer
[cmd
->device
->id
] = id
;
1108 printk(" sync_xfer=%02x\n",
1109 hostdata
->sync_xfer
[cmd
->device
->id
]);
1111 hostdata
->sync_stat
[cmd
->device
->id
] =
1113 write_wd33c93_cmd(regs
,
1115 hostdata
->state
= S_CONNECTED
;
1118 write_wd33c93_cmd(regs
, WD_CMD_ASSERT_ATN
); /* want MESS_OUT */
1119 printk("sending WDTR ");
1120 hostdata
->outgoing_msg
[0] =
1122 hostdata
->outgoing_msg
[1] = 2;
1123 hostdata
->outgoing_msg
[2] =
1125 hostdata
->outgoing_msg
[3] = 0; /* 8 bit transfer width */
1126 hostdata
->outgoing_len
= 4;
1127 write_wd33c93_cmd(regs
,
1129 hostdata
->state
= S_CONNECTED
;
1132 write_wd33c93_cmd(regs
, WD_CMD_ASSERT_ATN
); /* want MESS_OUT */
1134 ("Rejecting Unknown Extended Message(%02x). ",
1136 hostdata
->outgoing_msg
[0] =
1138 hostdata
->outgoing_len
= 1;
1139 write_wd33c93_cmd(regs
,
1141 hostdata
->state
= S_CONNECTED
;
1144 hostdata
->incoming_ptr
= 0;
1147 /* We need to read more MESS_IN bytes for the extended message */
1150 hostdata
->incoming_ptr
++;
1151 write_wd33c93_cmd(regs
, WD_CMD_NEGATE_ACK
);
1152 hostdata
->state
= S_CONNECTED
;
1157 printk("Rejecting Unknown Message(%02x) ", msg
);
1158 write_wd33c93_cmd(regs
, WD_CMD_ASSERT_ATN
); /* want MESS_OUT */
1159 hostdata
->outgoing_msg
[0] = MESSAGE_REJECT
;
1160 hostdata
->outgoing_len
= 1;
1161 write_wd33c93_cmd(regs
, WD_CMD_NEGATE_ACK
);
1162 hostdata
->state
= S_CONNECTED
;
1164 spin_unlock_irqrestore(&hostdata
->lock
, flags
);
1167 /* Note: this interrupt will occur only after a LEVEL2 command */
1169 case CSR_SEL_XFER_DONE
:
1171 /* Make sure that reselection is enabled at this point - it may
1172 * have been turned off for the command that just completed.
1175 write_wd33c93(regs
, WD_SOURCE_ID
, SRCID_ER
);
1177 DB(DB_INTR
, printk("SX-DONE-%ld", cmd
->serial_number
))
1178 cmd
->SCp
.Message
= COMMAND_COMPLETE
;
1179 lun
= read_wd33c93(regs
, WD_TARGET_LUN
);
1180 DB(DB_INTR
, printk(":%d.%d", cmd
->SCp
.Status
, lun
))
1181 hostdata
->connected
= NULL
;
1182 hostdata
->busy
[cmd
->device
->id
] &= ~(1 << cmd
->device
->lun
);
1183 hostdata
->state
= S_UNCONNECTED
;
1184 if (cmd
->SCp
.Status
== ILLEGAL_STATUS_BYTE
)
1185 cmd
->SCp
.Status
= lun
;
1186 if (cmd
->cmnd
[0] == REQUEST_SENSE
1187 && cmd
->SCp
.Status
!= GOOD
)
1190 result
& 0x00ffff) | (DID_ERROR
<< 16);
1193 cmd
->SCp
.Status
| (cmd
->SCp
.Message
<< 8);
1194 cmd
->scsi_done(cmd
);
1196 /* We are no longer connected to a target - check to see if
1197 * there are commands waiting to be executed.
1199 spin_unlock_irqrestore(&hostdata
->lock
, flags
);
1200 wd33c93_execute(instance
);
1203 ("%02x:%02x:%02x-%ld: Unknown SEL_XFER_DONE phase!!---",
1204 asr
, sr
, phs
, cmd
->serial_number
);
1205 spin_unlock_irqrestore(&hostdata
->lock
, flags
);
1209 /* Note: this interrupt will occur only after a LEVEL2 command */
1212 DB(DB_INTR
, printk("SDP"))
1213 hostdata
->state
= S_RUNNING_LEVEL2
;
1214 write_wd33c93(regs
, WD_COMMAND_PHASE
, 0x41);
1215 write_wd33c93_cmd(regs
, WD_CMD_SEL_ATN_XFER
);
1216 spin_unlock_irqrestore(&hostdata
->lock
, flags
);
1219 case CSR_XFER_DONE
| PHS_MESS_OUT
:
1220 case CSR_UNEXP
| PHS_MESS_OUT
:
1221 case CSR_SRV_REQ
| PHS_MESS_OUT
:
1222 DB(DB_INTR
, printk("MSG_OUT="))
1224 /* To get here, we've probably requested MESSAGE_OUT and have
1225 * already put the correct bytes in outgoing_msg[] and filled
1226 * in outgoing_len. We simply send them out to the SCSI bus.
1227 * Sometimes we get MESSAGE_OUT phase when we're not expecting
1228 * it - like when our SDTR message is rejected by a target. Some
1229 * targets send the REJECT before receiving all of the extended
1230 * message, and then seem to go back to MESSAGE_OUT for a byte
1231 * or two. Not sure why, or if I'm doing something wrong to
1232 * cause this to happen. Regardless, it seems that sending
1233 * NOP messages in these situations results in no harm and
1234 * makes everyone happy.
1236 if (hostdata
->outgoing_len
== 0) {
1237 hostdata
->outgoing_len
= 1;
1238 hostdata
->outgoing_msg
[0] = NOP
;
1240 transfer_pio(regs
, hostdata
->outgoing_msg
,
1241 hostdata
->outgoing_len
, DATA_OUT_DIR
, hostdata
);
1242 DB(DB_INTR
, printk("%02x", hostdata
->outgoing_msg
[0]))
1243 hostdata
->outgoing_len
= 0;
1244 hostdata
->state
= S_CONNECTED
;
1245 spin_unlock_irqrestore(&hostdata
->lock
, flags
);
1248 case CSR_UNEXP_DISC
:
1250 /* I think I've seen this after a request-sense that was in response
1251 * to an error condition, but not sure. We certainly need to do
1252 * something when we get this interrupt - the question is 'what?'.
1253 * Let's think positively, and assume some command has finished
1254 * in a legal manner (like a command that provokes a request-sense),
1255 * so we treat it as a normal command-complete-disconnect.
1258 /* Make sure that reselection is enabled at this point - it may
1259 * have been turned off for the command that just completed.
1262 write_wd33c93(regs
, WD_SOURCE_ID
, SRCID_ER
);
1264 printk(" - Already disconnected! ");
1265 hostdata
->state
= S_UNCONNECTED
;
1266 spin_unlock_irqrestore(&hostdata
->lock
, flags
);
1269 DB(DB_INTR
, printk("UNEXP_DISC-%ld", cmd
->serial_number
))
1270 hostdata
->connected
= NULL
;
1271 hostdata
->busy
[cmd
->device
->id
] &= ~(1 << cmd
->device
->lun
);
1272 hostdata
->state
= S_UNCONNECTED
;
1273 if (cmd
->cmnd
[0] == REQUEST_SENSE
&& cmd
->SCp
.Status
!= GOOD
)
1275 (cmd
->result
& 0x00ffff) | (DID_ERROR
<< 16);
1277 cmd
->result
= cmd
->SCp
.Status
| (cmd
->SCp
.Message
<< 8);
1278 cmd
->scsi_done(cmd
);
1280 /* We are no longer connected to a target - check to see if
1281 * there are commands waiting to be executed.
1283 /* look above for comments on scsi_done() */
1284 spin_unlock_irqrestore(&hostdata
->lock
, flags
);
1285 wd33c93_execute(instance
);
1290 /* Make sure that reselection is enabled at this point - it may
1291 * have been turned off for the command that just completed.
1294 write_wd33c93(regs
, WD_SOURCE_ID
, SRCID_ER
);
1295 DB(DB_INTR
, printk("DISC-%ld", cmd
->serial_number
))
1297 printk(" - Already disconnected! ");
1298 hostdata
->state
= S_UNCONNECTED
;
1300 switch (hostdata
->state
) {
1301 case S_PRE_CMP_DISC
:
1302 hostdata
->connected
= NULL
;
1303 hostdata
->busy
[cmd
->device
->id
] &= ~(1 << cmd
->device
->lun
);
1304 hostdata
->state
= S_UNCONNECTED
;
1305 DB(DB_INTR
, printk(":%d", cmd
->SCp
.Status
))
1306 if (cmd
->cmnd
[0] == REQUEST_SENSE
1307 && cmd
->SCp
.Status
!= GOOD
)
1310 result
& 0x00ffff) | (DID_ERROR
<< 16);
1313 cmd
->SCp
.Status
| (cmd
->SCp
.Message
<< 8);
1314 cmd
->scsi_done(cmd
);
1316 case S_PRE_TMP_DISC
:
1317 case S_RUNNING_LEVEL2
:
1318 cmd
->host_scribble
= (uchar
*) hostdata
->disconnected_Q
;
1319 hostdata
->disconnected_Q
= cmd
;
1320 hostdata
->connected
= NULL
;
1321 hostdata
->state
= S_UNCONNECTED
;
1323 #ifdef PROC_STATISTICS
1324 hostdata
->disc_done_cnt
[cmd
->device
->id
]++;
1329 printk("*** Unexpected DISCONNECT interrupt! ***");
1330 hostdata
->state
= S_UNCONNECTED
;
1333 /* We are no longer connected to a target - check to see if
1334 * there are commands waiting to be executed.
1336 spin_unlock_irqrestore(&hostdata
->lock
, flags
);
1337 wd33c93_execute(instance
);
1342 DB(DB_INTR
, printk("RESEL%s", sr
== CSR_RESEL_AM
? "_AM" : ""))
1344 /* Old chips (pre -A ???) don't have advanced features and will
1345 * generate CSR_RESEL. In that case we have to extract the LUN the
1346 * hard way (see below).
1347 * First we have to make sure this reselection didn't
1348 * happen during Arbitration/Selection of some other device.
1349 * If yes, put losing command back on top of input_Q.
1351 if (hostdata
->level2
<= L2_NONE
) {
1353 if (hostdata
->selecting
) {
1354 cmd
= (struct scsi_cmnd
*) hostdata
->selecting
;
1355 hostdata
->selecting
= NULL
;
1356 hostdata
->busy
[cmd
->device
->id
] &= ~(1 << cmd
->device
->lun
);
1357 cmd
->host_scribble
=
1358 (uchar
*) hostdata
->input_Q
;
1359 hostdata
->input_Q
= cmd
;
1367 hostdata
->busy
[cmd
->device
->id
] &=
1368 ~(1 << cmd
->device
->lun
);
1369 cmd
->host_scribble
=
1370 (uchar
*) hostdata
->input_Q
;
1371 hostdata
->input_Q
= cmd
;
1374 ("---%02x:%02x:%02x-TROUBLE: Intrusive ReSelect!---",
1383 /* OK - find out which device reselected us. */
1385 id
= read_wd33c93(regs
, WD_SOURCE_ID
);
1388 /* and extract the lun from the ID message. (Note that we don't
1389 * bother to check for a valid message here - I guess this is
1390 * not the right way to go, but...)
1393 if (sr
== CSR_RESEL_AM
) {
1394 lun
= read_wd33c93(regs
, WD_DATA
);
1395 if (hostdata
->level2
< L2_RESELECT
)
1396 write_wd33c93_cmd(regs
, WD_CMD_NEGATE_ACK
);
1399 /* Old chip; wait for msgin phase to pick up the LUN. */
1400 for (lun
= 255; lun
; lun
--) {
1401 if ((asr
= read_aux_stat(regs
)) & ASR_INT
)
1405 if (!(asr
& ASR_INT
)) {
1407 ("wd33c93: Reselected without IDENTIFY\n");
1410 /* Verify this is a change to MSG_IN and read the message */
1411 sr
= read_wd33c93(regs
, WD_SCSI_STATUS
);
1413 if (sr
== (CSR_ABORT
| PHS_MESS_IN
) ||
1414 sr
== (CSR_UNEXP
| PHS_MESS_IN
) ||
1415 sr
== (CSR_SRV_REQ
| PHS_MESS_IN
)) {
1416 /* Got MSG_IN, grab target LUN */
1417 lun
= read_1_byte(regs
);
1418 /* Now we expect a 'paused with ACK asserted' int.. */
1419 asr
= read_aux_stat(regs
);
1420 if (!(asr
& ASR_INT
)) {
1422 asr
= read_aux_stat(regs
);
1423 if (!(asr
& ASR_INT
))
1425 ("wd33c93: No int after LUN on RESEL (%02x)\n",
1428 sr
= read_wd33c93(regs
, WD_SCSI_STATUS
);
1430 if (sr
!= CSR_MSGIN
)
1432 ("wd33c93: Not paused with ACK on RESEL (%02x)\n",
1435 write_wd33c93_cmd(regs
,
1439 ("wd33c93: Not MSG_IN on reselect (%02x)\n",
1446 /* Now we look for the command that's reconnecting. */
1448 cmd
= (struct scsi_cmnd
*) hostdata
->disconnected_Q
;
1451 if (id
== cmd
->device
->id
&& lun
== cmd
->device
->lun
)
1454 cmd
= (struct scsi_cmnd
*) cmd
->host_scribble
;
1457 /* Hmm. Couldn't find a valid command.... What to do? */
1461 ("---TROUBLE: target %d.%d not in disconnect queue---",
1463 spin_unlock_irqrestore(&hostdata
->lock
, flags
);
1467 /* Ok, found the command - now start it up again. */
1470 patch
->host_scribble
= cmd
->host_scribble
;
1472 hostdata
->disconnected_Q
=
1473 (struct scsi_cmnd
*) cmd
->host_scribble
;
1474 hostdata
->connected
= cmd
;
1476 /* We don't need to worry about 'initialize_SCp()' or 'hostdata->busy[]'
1477 * because these things are preserved over a disconnect.
1478 * But we DO need to fix the DPD bit so it's correct for this command.
1481 if (cmd
->sc_data_direction
== DMA_TO_DEVICE
)
1482 write_wd33c93(regs
, WD_DESTINATION_ID
, cmd
->device
->id
);
1484 write_wd33c93(regs
, WD_DESTINATION_ID
,
1485 cmd
->device
->id
| DSTID_DPD
);
1486 if (hostdata
->level2
>= L2_RESELECT
) {
1487 write_wd33c93_count(regs
, 0); /* we want a DATA_PHASE interrupt */
1488 write_wd33c93(regs
, WD_COMMAND_PHASE
, 0x45);
1489 write_wd33c93_cmd(regs
, WD_CMD_SEL_ATN_XFER
);
1490 hostdata
->state
= S_RUNNING_LEVEL2
;
1492 hostdata
->state
= S_CONNECTED
;
1494 DB(DB_INTR
, printk("-%ld", cmd
->serial_number
))
1495 spin_unlock_irqrestore(&hostdata
->lock
, flags
);
1499 printk("--UNKNOWN INTERRUPT:%02x:%02x:%02x--", asr
, sr
, phs
);
1500 spin_unlock_irqrestore(&hostdata
->lock
, flags
);
1503 DB(DB_INTR
, printk("} "))
1508 reset_wd33c93(struct Scsi_Host
*instance
)
1510 struct WD33C93_hostdata
*hostdata
=
1511 (struct WD33C93_hostdata
*) instance
->hostdata
;
1512 const wd33c93_regs regs
= hostdata
->regs
;
1515 #ifdef CONFIG_SGI_IP22
1518 extern void sgiwd93_reset(unsigned long);
1519 /* wait 'til the chip gets some time for us */
1520 while ((read_aux_stat(regs
) & ASR_BSY
) && busycount
++ < 100)
1523 * there are scsi devices out there, which manage to lock up
1524 * the wd33c93 in a busy condition. In this state it won't
1525 * accept the reset command. The only way to solve this is to
1526 * give the chip a hardware reset (if possible). The code below
1527 * does this for the SGI Indy, where this is possible
1530 if (read_aux_stat(regs
) & ASR_BSY
)
1531 sgiwd93_reset(instance
->base
); /* yeah, give it the hard one */
1535 write_wd33c93(regs
, WD_OWN_ID
, OWNID_EAF
| OWNID_RAF
|
1536 instance
->this_id
| hostdata
->clock_freq
);
1537 write_wd33c93(regs
, WD_CONTROL
, CTRL_IDI
| CTRL_EDI
| CTRL_POLLED
);
1538 write_wd33c93(regs
, WD_SYNCHRONOUS_TRANSFER
,
1539 calc_sync_xfer(hostdata
->default_sx_per
/ 4,
1540 DEFAULT_SX_OFF
, 0, hostdata
->sx_table
));
1541 write_wd33c93(regs
, WD_COMMAND
, WD_CMD_RESET
);
1544 #ifdef CONFIG_MVME147_SCSI
1545 udelay(25); /* The old wd33c93 on MVME147 needs this, at least */
1548 while (!(read_aux_stat(regs
) & ASR_INT
))
1550 sr
= read_wd33c93(regs
, WD_SCSI_STATUS
);
1552 hostdata
->microcode
= read_wd33c93(regs
, WD_CDB_1
);
1554 hostdata
->chip
= C_WD33C93
;
1555 else if (sr
== 0x01) {
1556 write_wd33c93(regs
, WD_QUEUE_TAG
, 0xa5); /* any random number */
1557 sr
= read_wd33c93(regs
, WD_QUEUE_TAG
);
1559 hostdata
->chip
= C_WD33C93B
;
1560 write_wd33c93(regs
, WD_QUEUE_TAG
, 0);
1562 hostdata
->chip
= C_WD33C93A
;
1564 hostdata
->chip
= C_UNKNOWN_CHIP
;
1566 if (hostdata
->chip
!= C_WD33C93B
) /* Fast SCSI unavailable */
1569 write_wd33c93(regs
, WD_TIMEOUT_PERIOD
, TIMEOUT_PERIOD_VALUE
);
1570 write_wd33c93(regs
, WD_CONTROL
, CTRL_IDI
| CTRL_EDI
| CTRL_POLLED
);
1574 wd33c93_host_reset(struct scsi_cmnd
* SCpnt
)
1576 struct Scsi_Host
*instance
;
1577 struct WD33C93_hostdata
*hostdata
;
1580 instance
= SCpnt
->device
->host
;
1581 hostdata
= (struct WD33C93_hostdata
*) instance
->hostdata
;
1583 printk("scsi%d: reset. ", instance
->host_no
);
1584 disable_irq(instance
->irq
);
1586 hostdata
->dma_stop(instance
, NULL
, 0);
1587 for (i
= 0; i
< 8; i
++) {
1588 hostdata
->busy
[i
] = 0;
1589 hostdata
->sync_xfer
[i
] =
1590 calc_sync_xfer(DEFAULT_SX_PER
/ 4, DEFAULT_SX_OFF
,
1591 0, hostdata
->sx_table
);
1592 hostdata
->sync_stat
[i
] = SS_UNSET
; /* using default sync values */
1594 hostdata
->input_Q
= NULL
;
1595 hostdata
->selecting
= NULL
;
1596 hostdata
->connected
= NULL
;
1597 hostdata
->disconnected_Q
= NULL
;
1598 hostdata
->state
= S_UNCONNECTED
;
1599 hostdata
->dma
= D_DMA_OFF
;
1600 hostdata
->incoming_ptr
= 0;
1601 hostdata
->outgoing_len
= 0;
1603 reset_wd33c93(instance
);
1604 SCpnt
->result
= DID_RESET
<< 16;
1605 enable_irq(instance
->irq
);
1610 wd33c93_abort(struct scsi_cmnd
* cmd
)
1612 struct Scsi_Host
*instance
;
1613 struct WD33C93_hostdata
*hostdata
;
1615 struct scsi_cmnd
*tmp
, *prev
;
1617 disable_irq(cmd
->device
->host
->irq
);
1619 instance
= cmd
->device
->host
;
1620 hostdata
= (struct WD33C93_hostdata
*) instance
->hostdata
;
1621 regs
= hostdata
->regs
;
1624 * Case 1 : If the command hasn't been issued yet, we simply remove it
1628 tmp
= (struct scsi_cmnd
*) hostdata
->input_Q
;
1633 prev
->host_scribble
= cmd
->host_scribble
;
1636 (struct scsi_cmnd
*) cmd
->host_scribble
;
1637 cmd
->host_scribble
= NULL
;
1638 cmd
->result
= DID_ABORT
<< 16;
1640 ("scsi%d: Abort - removing command %ld from input_Q. ",
1641 instance
->host_no
, cmd
->serial_number
);
1642 enable_irq(cmd
->device
->host
->irq
);
1643 cmd
->scsi_done(cmd
);
1647 tmp
= (struct scsi_cmnd
*) tmp
->host_scribble
;
1651 * Case 2 : If the command is connected, we're going to fail the abort
1652 * and let the high level SCSI driver retry at a later time or
1655 * Timeouts, and therefore aborted commands, will be highly unlikely
1656 * and handling them cleanly in this situation would make the common
1657 * case of noresets less efficient, and would pollute our code. So,
1661 if (hostdata
->connected
== cmd
) {
1663 unsigned long timeout
;
1665 printk("scsi%d: Aborting connected command %ld - ",
1666 instance
->host_no
, cmd
->serial_number
);
1668 printk("stopping DMA - ");
1669 if (hostdata
->dma
== D_DMA_RUNNING
) {
1670 hostdata
->dma_stop(instance
, cmd
, 0);
1671 hostdata
->dma
= D_DMA_OFF
;
1674 printk("sending wd33c93 ABORT command - ");
1675 write_wd33c93(regs
, WD_CONTROL
,
1676 CTRL_IDI
| CTRL_EDI
| CTRL_POLLED
);
1677 write_wd33c93_cmd(regs
, WD_CMD_ABORT
);
1679 /* Now we have to attempt to flush out the FIFO... */
1681 printk("flushing fifo - ");
1684 asr
= read_aux_stat(regs
);
1686 read_wd33c93(regs
, WD_DATA
);
1687 } while (!(asr
& ASR_INT
) && timeout
-- > 0);
1688 sr
= read_wd33c93(regs
, WD_SCSI_STATUS
);
1690 ("asr=%02x, sr=%02x, %ld bytes un-transferred (timeout=%ld) - ",
1691 asr
, sr
, read_wd33c93_count(regs
), timeout
);
1694 * Abort command processed.
1696 * We must disconnect.
1699 printk("sending wd33c93 DISCONNECT command - ");
1700 write_wd33c93_cmd(regs
, WD_CMD_DISCONNECT
);
1703 asr
= read_aux_stat(regs
);
1704 while ((asr
& ASR_CIP
) && timeout
-- > 0)
1705 asr
= read_aux_stat(regs
);
1706 sr
= read_wd33c93(regs
, WD_SCSI_STATUS
);
1707 printk("asr=%02x, sr=%02x.", asr
, sr
);
1709 hostdata
->busy
[cmd
->device
->id
] &= ~(1 << cmd
->device
->lun
);
1710 hostdata
->connected
= NULL
;
1711 hostdata
->state
= S_UNCONNECTED
;
1712 cmd
->result
= DID_ABORT
<< 16;
1715 wd33c93_execute(instance
);
1717 enable_irq(cmd
->device
->host
->irq
);
1718 cmd
->scsi_done(cmd
);
1723 * Case 3: If the command is currently disconnected from the bus,
1724 * we're not going to expend much effort here: Let's just return
1725 * an ABORT_SNOOZE and hope for the best...
1728 tmp
= (struct scsi_cmnd
*) hostdata
->disconnected_Q
;
1732 ("scsi%d: Abort - command %ld found on disconnected_Q - ",
1733 instance
->host_no
, cmd
->serial_number
);
1734 printk("Abort SNOOZE. ");
1735 enable_irq(cmd
->device
->host
->irq
);
1738 tmp
= (struct scsi_cmnd
*) tmp
->host_scribble
;
1742 * Case 4 : If we reached this point, the command was not found in any of
1745 * We probably reached this point because of an unlikely race condition
1746 * between the command completing successfully and the abortion code,
1747 * so we won't panic, but we will notify the user in case something really
1752 wd33c93_execute(instance
);
1754 enable_irq(cmd
->device
->host
->irq
);
1755 printk("scsi%d: warning : SCSI command probably completed successfully"
1756 " before abortion. ", instance
->host_no
);
1760 #define MAX_WD33C93_HOSTS 4
1761 #define MAX_SETUP_ARGS ARRAY_SIZE(setup_args)
1762 #define SETUP_BUFFER_SIZE 200
1763 static char setup_buffer
[SETUP_BUFFER_SIZE
];
1764 static char setup_used
[MAX_SETUP_ARGS
];
1765 static int done_setup
= 0;
1768 wd33c93_setup(char *str
)
1773 /* The kernel does some processing of the command-line before calling
1774 * this function: If it begins with any decimal or hex number arguments,
1775 * ints[0] = how many numbers found and ints[1] through [n] are the values
1776 * themselves. str points to where the non-numeric arguments (if any)
1777 * start: We do our own parsing of those. We construct synthetic 'nosync'
1778 * keywords out of numeric args (to maintain compatibility with older
1779 * versions) and then add the rest of the arguments.
1785 strncpy(p1
, str
, SETUP_BUFFER_SIZE
- strlen(setup_buffer
));
1786 setup_buffer
[SETUP_BUFFER_SIZE
- 1] = '\0';
1789 while (*p1
&& (i
< MAX_SETUP_ARGS
)) {
1790 p2
= strchr(p1
, ',');
1802 for (i
= 0; i
< MAX_SETUP_ARGS
; i
++)
1808 __setup("wd33c93=", wd33c93_setup
);
1810 /* check_setup_args() returns index if key found, 0 if not
1813 check_setup_args(char *key
, int *flags
, int *val
, char *buf
)
1818 for (x
= 0; x
< MAX_SETUP_ARGS
; x
++) {
1821 if (!strncmp(setup_args
[x
], key
, strlen(key
)))
1823 if (!strncmp(setup_args
[x
], "next", strlen("next")))
1826 if (x
== MAX_SETUP_ARGS
)
1829 cp
= setup_args
[x
] + strlen(key
);
1834 if ((*cp
>= '0') && (*cp
<= '9')) {
1835 *val
= simple_strtoul(cp
, NULL
, 0);
1841 * Calculate internal data-transfer-clock cycle from input-clock
1842 * frequency (/MHz) and fill 'sx_table'.
1844 * The original driver used to rely on a fixed sx_table, containing periods
1845 * for (only) the lower limits of the respective input-clock-frequency ranges
1846 * (8-10/12-15/16-20 MHz). Although it seems, that no problems ocurred with
1847 * this setting so far, it might be desirable to adjust the transfer periods
1848 * closer to the really attached, possibly 25% higher, input-clock, since
1849 * - the wd33c93 may really use a significant shorter period, than it has
1850 * negotiated (eg. thrashing the target, which expects 4/8MHz, with 5/10MHz
1852 * - the wd33c93 may ask the target for a lower transfer rate, than the target
1853 * is capable of (eg. negotiating for an assumed minimum of 252ns instead of
1854 * possible 200ns, which indeed shows up in tests as an approx. 10% lower
1857 static inline unsigned int
1858 round_4(unsigned int x
)
1870 calc_sx_table(unsigned int mhz
, struct sx_period sx_table
[9])
1874 d
= 2; /* divisor for 8-10 MHz input-clock */
1876 d
= 3; /* divisor for 12-15 MHz input-clock */
1878 d
= 4; /* divisor for 16-20 MHz input-clock */
1880 d
= (100000 * d
) / 2 / mhz
; /* 100 x DTCC / nanosec */
1882 sx_table
[0].period_ns
= 1;
1883 sx_table
[0].reg_value
= 0x20;
1884 for (i
= 1; i
< 8; i
++) {
1885 sx_table
[i
].period_ns
= round_4((i
+1)*d
/ 100);
1886 sx_table
[i
].reg_value
= (i
+1)*0x10;
1888 sx_table
[7].reg_value
= 0;
1889 sx_table
[8].period_ns
= 0;
1890 sx_table
[8].reg_value
= 0;
1894 * check and, maybe, map an init- or "clock:"- argument.
1897 set_clk_freq(int freq
, int *mhz
)
1900 if (WD33C93_FS_8_10
== freq
)
1902 else if (WD33C93_FS_12_15
== freq
)
1904 else if (WD33C93_FS_16_20
== freq
)
1906 else if (freq
> 7 && freq
< 11)
1907 x
= WD33C93_FS_8_10
;
1908 else if (freq
> 11 && freq
< 16)
1909 x
= WD33C93_FS_12_15
;
1910 else if (freq
> 15 && freq
< 21)
1911 x
= WD33C93_FS_16_20
;
1913 /* Hmm, wouldn't it be safer to assume highest freq here? */
1914 x
= WD33C93_FS_8_10
;
1922 * to be used with the resync: fast: ... options
1924 static inline void set_resync ( struct WD33C93_hostdata
*hd
, int mask
)
1927 for (i
= 0; i
< 8; i
++)
1928 if (mask
& (1 << i
))
1929 hd
->sync_stat
[i
] = SS_UNSET
;
1933 wd33c93_init(struct Scsi_Host
*instance
, const wd33c93_regs regs
,
1934 dma_setup_t setup
, dma_stop_t stop
, int clock_freq
)
1936 struct WD33C93_hostdata
*hostdata
;
1942 if (!done_setup
&& setup_strings
)
1943 wd33c93_setup(setup_strings
);
1945 hostdata
= (struct WD33C93_hostdata
*) instance
->hostdata
;
1947 hostdata
->regs
= regs
;
1948 hostdata
->clock_freq
= set_clk_freq(clock_freq
, &i
);
1949 calc_sx_table(i
, hostdata
->sx_table
);
1950 hostdata
->dma_setup
= setup
;
1951 hostdata
->dma_stop
= stop
;
1952 hostdata
->dma_bounce_buffer
= NULL
;
1953 hostdata
->dma_bounce_len
= 0;
1954 for (i
= 0; i
< 8; i
++) {
1955 hostdata
->busy
[i
] = 0;
1956 hostdata
->sync_xfer
[i
] =
1957 calc_sync_xfer(DEFAULT_SX_PER
/ 4, DEFAULT_SX_OFF
,
1958 0, hostdata
->sx_table
);
1959 hostdata
->sync_stat
[i
] = SS_UNSET
; /* using default sync values */
1960 #ifdef PROC_STATISTICS
1961 hostdata
->cmd_cnt
[i
] = 0;
1962 hostdata
->disc_allowed_cnt
[i
] = 0;
1963 hostdata
->disc_done_cnt
[i
] = 0;
1966 hostdata
->input_Q
= NULL
;
1967 hostdata
->selecting
= NULL
;
1968 hostdata
->connected
= NULL
;
1969 hostdata
->disconnected_Q
= NULL
;
1970 hostdata
->state
= S_UNCONNECTED
;
1971 hostdata
->dma
= D_DMA_OFF
;
1972 hostdata
->level2
= L2_BASIC
;
1973 hostdata
->disconnect
= DIS_ADAPTIVE
;
1974 hostdata
->args
= DEBUG_DEFAULTS
;
1975 hostdata
->incoming_ptr
= 0;
1976 hostdata
->outgoing_len
= 0;
1977 hostdata
->default_sx_per
= DEFAULT_SX_PER
;
1978 hostdata
->no_sync
= 0xff; /* sync defaults to off */
1979 hostdata
->no_dma
= 0; /* default is DMA enabled */
1980 hostdata
->fast
= 0; /* default is Fast SCSI transfers disabled */
1981 hostdata
->dma_mode
= CTRL_DMA
; /* default is Single Byte DMA */
1983 #ifdef PROC_INTERFACE
1984 hostdata
->proc
= PR_VERSION
| PR_INFO
| PR_STATISTICS
|
1985 PR_CONNECTED
| PR_INPUTQ
| PR_DISCQ
| PR_STOP
;
1986 #ifdef PROC_STATISTICS
1987 hostdata
->dma_cnt
= 0;
1988 hostdata
->pio_cnt
= 0;
1989 hostdata
->int_cnt
= 0;
1993 if (check_setup_args("clock", &flags
, &val
, buf
)) {
1994 hostdata
->clock_freq
= set_clk_freq(val
, &val
);
1995 calc_sx_table(val
, hostdata
->sx_table
);
1998 if (check_setup_args("nosync", &flags
, &val
, buf
))
1999 hostdata
->no_sync
= val
;
2001 if (check_setup_args("nodma", &flags
, &val
, buf
))
2002 hostdata
->no_dma
= (val
== -1) ? 1 : val
;
2004 if (check_setup_args("period", &flags
, &val
, buf
))
2005 hostdata
->default_sx_per
=
2006 hostdata
->sx_table
[round_period((unsigned int) val
,
2007 hostdata
->sx_table
)].period_ns
;
2009 if (check_setup_args("disconnect", &flags
, &val
, buf
)) {
2010 if ((val
>= DIS_NEVER
) && (val
<= DIS_ALWAYS
))
2011 hostdata
->disconnect
= val
;
2013 hostdata
->disconnect
= DIS_ADAPTIVE
;
2016 if (check_setup_args("level2", &flags
, &val
, buf
))
2017 hostdata
->level2
= val
;
2019 if (check_setup_args("debug", &flags
, &val
, buf
))
2020 hostdata
->args
= val
& DB_MASK
;
2022 if (check_setup_args("burst", &flags
, &val
, buf
))
2023 hostdata
->dma_mode
= val
? CTRL_BURST
:CTRL_DMA
;
2025 if (WD33C93_FS_16_20
== hostdata
->clock_freq
/* divisor 4 */
2026 && check_setup_args("fast", &flags
, &val
, buf
))
2027 hostdata
->fast
= !!val
;
2029 if ((i
= check_setup_args("next", &flags
, &val
, buf
))) {
2031 setup_used
[--i
] = 1;
2033 #ifdef PROC_INTERFACE
2034 if (check_setup_args("proc", &flags
, &val
, buf
))
2035 hostdata
->proc
= val
;
2038 spin_lock_irq(&hostdata
->lock
);
2039 reset_wd33c93(instance
);
2040 spin_unlock_irq(&hostdata
->lock
);
2042 printk("wd33c93-%d: chip=%s/%d no_sync=0x%x no_dma=%d",
2044 (hostdata
->chip
== C_WD33C93
) ? "WD33c93" : (hostdata
->chip
==
2046 "WD33c93A" : (hostdata
->chip
==
2047 C_WD33C93B
) ? "WD33c93B" : "unknown",
2048 hostdata
->microcode
, hostdata
->no_sync
, hostdata
->no_dma
);
2050 printk(" debug_flags=0x%02x\n", hostdata
->args
);
2052 printk(" debugging=OFF\n");
2054 printk(" setup_args=");
2055 for (i
= 0; i
< MAX_SETUP_ARGS
; i
++)
2056 printk("%s,", setup_args
[i
]);
2058 printk(" Version %s - %s, Compiled %s at %s\n",
2059 WD33C93_VERSION
, WD33C93_DATE
, __DATE__
, __TIME__
);
2063 wd33c93_proc_info(struct Scsi_Host
*instance
, char *buf
, char **start
, off_t off
, int len
, int in
)
2066 #ifdef PROC_INTERFACE
2070 struct WD33C93_hostdata
*hd
;
2071 struct scsi_cmnd
*cmd
;
2073 static int stop
= 0;
2075 hd
= (struct WD33C93_hostdata
*) instance
->hostdata
;
2077 /* If 'in' is TRUE we need to _read_ the proc file. We accept the following
2078 * keywords (same format as command-line, but arguments are not optional):
2093 for (bp
= buf
; *bp
; ) {
2094 while (',' == *bp
|| ' ' == *bp
)
2096 if (!strncmp(bp
, "debug:", 6)) {
2097 hd
->args
= simple_strtoul(bp
+6, &bp
, 0) & DB_MASK
;
2098 } else if (!strncmp(bp
, "disconnect:", 11)) {
2099 x
= simple_strtoul(bp
+11, &bp
, 0);
2100 if (x
< DIS_NEVER
|| x
> DIS_ALWAYS
)
2103 } else if (!strncmp(bp
, "period:", 7)) {
2104 x
= simple_strtoul(bp
+7, &bp
, 0);
2105 hd
->default_sx_per
=
2106 hd
->sx_table
[round_period((unsigned int) x
,
2107 hd
->sx_table
)].period_ns
;
2108 } else if (!strncmp(bp
, "resync:", 7)) {
2109 set_resync(hd
, (int)simple_strtoul(bp
+7, &bp
, 0));
2110 } else if (!strncmp(bp
, "proc:", 5)) {
2111 hd
->proc
= simple_strtoul(bp
+5, &bp
, 0);
2112 } else if (!strncmp(bp
, "nodma:", 6)) {
2113 hd
->no_dma
= simple_strtoul(bp
+6, &bp
, 0);
2114 } else if (!strncmp(bp
, "level2:", 7)) {
2115 hd
->level2
= simple_strtoul(bp
+7, &bp
, 0);
2116 } else if (!strncmp(bp
, "burst:", 6)) {
2118 simple_strtol(bp
+6, &bp
, 0) ? CTRL_BURST
:CTRL_DMA
;
2119 } else if (!strncmp(bp
, "fast:", 5)) {
2120 x
= !!simple_strtol(bp
+5, &bp
, 0);
2122 set_resync(hd
, 0xff);
2124 } else if (!strncmp(bp
, "nosync:", 7)) {
2125 x
= simple_strtoul(bp
+7, &bp
, 0);
2126 set_resync(hd
, x
^ hd
->no_sync
);
2129 break; /* unknown keyword,syntax-error,... */
2135 spin_lock_irq(&hd
->lock
);
2138 if (hd
->proc
& PR_VERSION
) {
2139 sprintf(tbuf
, "\nVersion %s - %s. Compiled %s %s",
2140 WD33C93_VERSION
, WD33C93_DATE
, __DATE__
, __TIME__
);
2143 if (hd
->proc
& PR_INFO
) {
2144 sprintf(tbuf
, "\nclock_freq=%02x no_sync=%02x no_dma=%d"
2145 " dma_mode=%02x fast=%d",
2146 hd
->clock_freq
, hd
->no_sync
, hd
->no_dma
, hd
->dma_mode
, hd
->fast
);
2148 strcat(bp
, "\nsync_xfer[] = ");
2149 for (x
= 0; x
< 7; x
++) {
2150 sprintf(tbuf
, "\t%02x", hd
->sync_xfer
[x
]);
2153 strcat(bp
, "\nsync_stat[] = ");
2154 for (x
= 0; x
< 7; x
++) {
2155 sprintf(tbuf
, "\t%02x", hd
->sync_stat
[x
]);
2159 #ifdef PROC_STATISTICS
2160 if (hd
->proc
& PR_STATISTICS
) {
2161 strcat(bp
, "\ncommands issued: ");
2162 for (x
= 0; x
< 7; x
++) {
2163 sprintf(tbuf
, "\t%ld", hd
->cmd_cnt
[x
]);
2166 strcat(bp
, "\ndisconnects allowed:");
2167 for (x
= 0; x
< 7; x
++) {
2168 sprintf(tbuf
, "\t%ld", hd
->disc_allowed_cnt
[x
]);
2171 strcat(bp
, "\ndisconnects done: ");
2172 for (x
= 0; x
< 7; x
++) {
2173 sprintf(tbuf
, "\t%ld", hd
->disc_done_cnt
[x
]);
2177 "\ninterrupts: %ld, DATA_PHASE ints: %ld DMA, %ld PIO",
2178 hd
->int_cnt
, hd
->dma_cnt
, hd
->pio_cnt
);
2182 if (hd
->proc
& PR_CONNECTED
) {
2183 strcat(bp
, "\nconnected: ");
2184 if (hd
->connected
) {
2185 cmd
= (struct scsi_cmnd
*) hd
->connected
;
2186 sprintf(tbuf
, " %ld-%d:%d(%02x)",
2187 cmd
->serial_number
, cmd
->device
->id
, cmd
->device
->lun
, cmd
->cmnd
[0]);
2191 if (hd
->proc
& PR_INPUTQ
) {
2192 strcat(bp
, "\ninput_Q: ");
2193 cmd
= (struct scsi_cmnd
*) hd
->input_Q
;
2195 sprintf(tbuf
, " %ld-%d:%d(%02x)",
2196 cmd
->serial_number
, cmd
->device
->id
, cmd
->device
->lun
, cmd
->cmnd
[0]);
2198 cmd
= (struct scsi_cmnd
*) cmd
->host_scribble
;
2201 if (hd
->proc
& PR_DISCQ
) {
2202 strcat(bp
, "\ndisconnected_Q:");
2203 cmd
= (struct scsi_cmnd
*) hd
->disconnected_Q
;
2205 sprintf(tbuf
, " %ld-%d:%d(%02x)",
2206 cmd
->serial_number
, cmd
->device
->id
, cmd
->device
->lun
, cmd
->cmnd
[0]);
2208 cmd
= (struct scsi_cmnd
*) cmd
->host_scribble
;
2212 spin_unlock_irq(&hd
->lock
);
2218 if (off
> 0x40000) /* ALWAYS stop after 256k bytes have been read */
2220 if (hd
->proc
& PR_STOP
) /* stop every other time */
2224 #else /* PROC_INTERFACE */
2228 #endif /* PROC_INTERFACE */
2233 wd33c93_release(void)
2237 EXPORT_SYMBOL(wd33c93_host_reset
);
2238 EXPORT_SYMBOL(wd33c93_init
);
2239 EXPORT_SYMBOL(wd33c93_release
);
2240 EXPORT_SYMBOL(wd33c93_abort
);
2241 EXPORT_SYMBOL(wd33c93_queuecommand
);
2242 EXPORT_SYMBOL(wd33c93_intr
);
2243 EXPORT_SYMBOL(wd33c93_proc_info
);