1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * Copyright (c) 1996 John Shifflett, GeoLog Consulting
9 * Drew Eckhardt's excellent 'Generic NCR5380' sources from Linux-PC
10 * provided much of the inspiration and some of the code for this
11 * driver. Everything I know about Amiga DMA was gleaned from careful
12 * reading of Hamish Mcdonald's original wd33c93 driver; in fact, I
13 * borrowed shamelessly from all over that source. Thanks Hamish!
15 * _This_ driver is (I feel) an improvement over the old one in
18 * - Target Disconnection/Reconnection is now supported. Any
19 * system with more than one device active on the SCSI bus
20 * will benefit from this. The driver defaults to what I
21 * call 'adaptive disconnect' - meaning that each command
22 * is evaluated individually as to whether or not it should
23 * be run with the option to disconnect/reselect (if the
24 * device chooses), or as a "SCSI-bus-hog".
26 * - Synchronous data transfers are now supported. Because of
27 * a few devices that choke after telling the driver that
28 * they can do sync transfers, we don't automatically use
29 * this faster protocol - it can be enabled via the command-
30 * line on a device-by-device basis.
32 * - Runtime operating parameters can now be specified through
33 * the 'amiboot' or the 'insmod' command line. For amiboot do:
34 * "amiboot [usual stuff] wd33c93=blah,blah,blah"
35 * The defaults should be good for most people. See the comment
36 * for 'setup_strings' below for more details.
38 * - The old driver relied exclusively on what the Western Digital
39 * docs call "Combination Level 2 Commands", which are a great
40 * idea in that the CPU is relieved of a lot of interrupt
41 * overhead. However, by accepting a certain (user-settable)
42 * amount of additional interrupts, this driver achieves
43 * better control over the SCSI bus, and data transfers are
44 * almost as fast while being much easier to define, track,
49 * more speed. linked commands.
52 * People with bug reports, wish-lists, complaints, comments,
53 * or improvements are asked to pah-leeez email me (John Shifflett)
54 * at john@geolog.com or jshiffle@netcom.com! I'm anxious to get
55 * this thing into as good a shape as possible, and I'm positive
56 * there are lots of lurking bugs and "Stupid Places".
60 * Added support for pre -A chips, which don't have advanced features
61 * and will generate CSR_RESEL rather than CSR_RESEL_AM.
62 * Richard Hirst <richard@sleepie.demon.co.uk> August 2000
64 * Added support for Burst Mode DMA and Fast SCSI. Enabled the use of
65 * default_sx_per for asynchronous data transfers. Added adjustment
66 * of transfer periods in sx_table to the actual input-clock.
67 * peter fuerst <post@pfrst.de> February 2007
70 #include <linux/module.h>
72 #include <linux/string.h>
73 #include <linux/delay.h>
74 #include <linux/init.h>
75 #include <linux/interrupt.h>
76 #include <linux/blkdev.h>
78 #include <scsi/scsi.h>
79 #include <scsi/scsi_cmnd.h>
80 #include <scsi/scsi_device.h>
81 #include <scsi/scsi_host.h>
87 #define optimum_sx_per(hostdata) (hostdata)->sx_table[1].period_ns
90 #define WD33C93_VERSION "1.26++"
91 #define WD33C93_DATE "10/Feb/2007"
93 MODULE_AUTHOR("John Shifflett");
94 MODULE_DESCRIPTION("Generic WD33C93 SCSI driver");
95 MODULE_LICENSE("GPL");
98 * 'setup_strings' is a single string used to pass operating parameters and
99 * settings from the kernel/module command-line to the driver. 'setup_args[]'
100 * is an array of strings that define the compile-time default values for
101 * these settings. If Linux boots with an amiboot or insmod command-line,
102 * those settings are combined with 'setup_args[]'. Note that amiboot
103 * command-lines are prefixed with "wd33c93=" while insmod uses a
104 * "setup_strings=" prefix. The driver recognizes the following keywords
105 * (lower case required) and arguments:
107 * - nosync:bitmask -bitmask is a byte where the 1st 7 bits correspond with
108 * the 7 possible SCSI devices. Set a bit to negotiate for
109 * asynchronous transfers on that device. To maintain
110 * backwards compatibility, a command-line such as
111 * "wd33c93=255" will be automatically translated to
112 * "wd33c93=nosync:0xff".
113 * - nodma:x -x = 1 to disable DMA, x = 0 to enable it. Argument is
114 * optional - if not present, same as "nodma:1".
115 * - period:ns -ns is the minimum # of nanoseconds in a SCSI data transfer
116 * period. Default is 500; acceptable values are 250 - 1000.
117 * - disconnect:x -x = 0 to never allow disconnects, 2 to always allow them.
118 * x = 1 does 'adaptive' disconnects, which is the default
119 * and generally the best choice.
120 * - debug:x -If 'DEBUGGING_ON' is defined, x is a bit mask that causes
121 * various types of debug output to printed - see the DB_xxx
122 * defines in wd33c93.h
123 * - clock:x -x = clock input in MHz for WD33c93 chip. Normal values
124 * would be from 8 through 20. Default is 8.
125 * - burst:x -x = 1 to use Burst Mode (or Demand-Mode) DMA, x = 0 to use
126 * Single Byte DMA, which is the default. Argument is
127 * optional - if not present, same as "burst:1".
128 * - fast:x -x = 1 to enable Fast SCSI, which is only effective with
129 * input-clock divisor 4 (WD33C93_FS_16_20), x = 0 to disable
130 * it, which is the default. Argument is optional - if not
131 * present, same as "fast:1".
132 * - next -No argument. Used to separate blocks of keywords when
133 * there's more than one host adapter in the system.
136 * - Numeric arguments can be decimal or the '0x' form of hex notation. There
137 * _must_ be a colon between a keyword and its numeric argument, with no
139 * - Keywords are separated by commas, no spaces, in the standard kernel
140 * command-line manner.
141 * - A keyword in the 'nth' comma-separated command-line member will overwrite
142 * the 'nth' element of setup_args[]. A blank command-line member (in
143 * other words, a comma with no preceding keyword) will _not_ overwrite
144 * the corresponding setup_args[] element.
145 * - If a keyword is used more than once, the first one applies to the first
146 * SCSI host found, the second to the second card, etc, unless the 'next'
147 * keyword is used to change the order.
149 * Some amiboot examples (for insmod, use 'setup_strings' instead of 'wd33c93'):
150 * - wd33c93=nosync:255
153 * - wd33c93=disconnect:2,nosync:0x08,period:250
154 * - wd33c93=debug:0x1c
157 /* Normally, no defaults are specified */
158 static char *setup_args
[] = { "", "", "", "", "", "", "", "", "", "" };
160 static char *setup_strings
;
161 module_param(setup_strings
, charp
, 0);
163 static void wd33c93_execute(struct Scsi_Host
*instance
);
166 read_wd33c93(const wd33c93_regs regs
, uchar reg_num
)
168 *regs
.SASR
= reg_num
;
174 read_wd33c93_count(const wd33c93_regs regs
)
178 *regs
.SASR
= WD_TRANSFER_COUNT_MSB
;
180 value
= *regs
.SCMD
<< 16;
181 value
|= *regs
.SCMD
<< 8;
188 read_aux_stat(const wd33c93_regs regs
)
194 write_wd33c93(const wd33c93_regs regs
, uchar reg_num
, uchar value
)
196 *regs
.SASR
= reg_num
;
203 write_wd33c93_count(const wd33c93_regs regs
, unsigned long value
)
205 *regs
.SASR
= WD_TRANSFER_COUNT_MSB
;
207 *regs
.SCMD
= value
>> 16;
208 *regs
.SCMD
= value
>> 8;
214 write_wd33c93_cmd(const wd33c93_regs regs
, uchar cmd
)
216 *regs
.SASR
= WD_COMMAND
;
223 write_wd33c93_cdb(const wd33c93_regs regs
, uint len
, uchar cmnd
[])
227 *regs
.SASR
= WD_CDB_1
;
228 for (i
= 0; i
< len
; i
++)
229 *regs
.SCMD
= cmnd
[i
];
233 read_1_byte(const wd33c93_regs regs
)
238 write_wd33c93(regs
, WD_CONTROL
, CTRL_IDI
| CTRL_EDI
| CTRL_POLLED
);
239 write_wd33c93_cmd(regs
, WD_CMD_TRANS_INFO
| 0x80);
241 asr
= read_aux_stat(regs
);
243 x
= read_wd33c93(regs
, WD_DATA
);
244 } while (!(asr
& ASR_INT
));
249 round_period(unsigned int period
, const struct sx_period
*sx_table
)
253 for (x
= 1; sx_table
[x
].period_ns
; x
++) {
254 if ((period
<= sx_table
[x
- 0].period_ns
) &&
255 (period
> sx_table
[x
- 1].period_ns
)) {
263 * Calculate Synchronous Transfer Register value from SDTR code.
266 calc_sync_xfer(unsigned int period
, unsigned int offset
, unsigned int fast
,
267 const struct sx_period
*sx_table
)
269 /* When doing Fast SCSI synchronous data transfers, the corresponding
270 * value in 'sx_table' is two times the actually used transfer period.
274 if (offset
&& fast
) {
280 period
*= 4; /* convert SDTR code to ns */
281 result
= sx_table
[round_period(period
,sx_table
)].reg_value
;
282 result
|= (offset
< OPTIMUM_SX_OFF
) ? offset
: OPTIMUM_SX_OFF
;
288 * Calculate SDTR code bytes [3],[4] from period and offset.
291 calc_sync_msg(unsigned int period
, unsigned int offset
, unsigned int fast
,
294 /* 'period' is a "normal"-mode value, like the ones in 'sx_table'. The
295 * actually used transfer period for Fast SCSI synchronous data
296 * transfers is half that value.
305 static int wd33c93_queuecommand_lck(struct scsi_cmnd
*cmd
)
307 struct scsi_pointer
*scsi_pointer
= WD33C93_scsi_pointer(cmd
);
308 struct WD33C93_hostdata
*hostdata
;
309 struct scsi_cmnd
*tmp
;
311 hostdata
= (struct WD33C93_hostdata
*) cmd
->device
->host
->hostdata
;
314 printk("Q-%d-%02x( ", cmd
->device
->id
, cmd
->cmnd
[0]))
316 /* Set up a few fields in the scsi_cmnd structure for our own use:
317 * - host_scribble is the pointer to the next cmd in the input queue
318 * - result is what you'd expect
320 cmd
->host_scribble
= NULL
;
323 /* We use the Scsi_Pointer structure that's included with each command
324 * as a scratchpad (as it's intended to be used!). The handy thing about
325 * the SCp.xxx fields is that they're always associated with a given
326 * cmd, and are preserved across disconnect-reselect. This means we
327 * can pretty much ignore SAVE_POINTERS and RESTORE_POINTERS messages
328 * if we keep all the critical pointers and counters in SCp:
329 * - SCp.ptr is the pointer into the RAM buffer
330 * - SCp.this_residual is the size of that buffer
331 * - SCp.buffer points to the current scatter-gather buffer
332 * - SCp.buffers_residual tells us how many S.G. buffers there are
333 * - SCp.have_data_in is not used
334 * - SCp.sent_command is not used
335 * - SCp.phase records this command's SRCID_ER bit setting
338 if (scsi_bufflen(cmd
)) {
339 scsi_pointer
->buffer
= scsi_sglist(cmd
);
340 scsi_pointer
->buffers_residual
= scsi_sg_count(cmd
) - 1;
341 scsi_pointer
->ptr
= sg_virt(scsi_pointer
->buffer
);
342 scsi_pointer
->this_residual
= scsi_pointer
->buffer
->length
;
344 scsi_pointer
->buffer
= NULL
;
345 scsi_pointer
->buffers_residual
= 0;
346 scsi_pointer
->ptr
= NULL
;
347 scsi_pointer
->this_residual
= 0;
350 /* WD docs state that at the conclusion of a "LEVEL2" command, the
351 * status byte can be retrieved from the LUN register. Apparently,
352 * this is the case only for *uninterrupted* LEVEL2 commands! If
353 * there are any unexpected phases entered, even if they are 100%
354 * legal (different devices may choose to do things differently),
355 * the LEVEL2 command sequence is exited. This often occurs prior
356 * to receiving the status byte, in which case the driver does a
357 * status phase interrupt and gets the status byte on its own.
358 * While such a command can then be "resumed" (ie restarted to
359 * finish up as a LEVEL2 command), the LUN register will NOT be
360 * a valid status byte at the command's conclusion, and we must
361 * use the byte obtained during the earlier interrupt. Here, we
362 * preset SCp.Status to an illegal value (0xff) so that when
363 * this command finally completes, we can tell where the actual
364 * status byte is stored.
367 scsi_pointer
->Status
= ILLEGAL_STATUS_BYTE
;
370 * Add the cmd to the end of 'input_Q'. Note that REQUEST SENSE
371 * commands are added to the head of the queue so that the desired
372 * sense data is not lost before REQUEST_SENSE executes.
375 spin_lock_irq(&hostdata
->lock
);
377 if (!(hostdata
->input_Q
) || (cmd
->cmnd
[0] == REQUEST_SENSE
)) {
378 cmd
->host_scribble
= (uchar
*) hostdata
->input_Q
;
379 hostdata
->input_Q
= cmd
;
380 } else { /* find the end of the queue */
381 for (tmp
= (struct scsi_cmnd
*) hostdata
->input_Q
;
383 tmp
= (struct scsi_cmnd
*) tmp
->host_scribble
) ;
384 tmp
->host_scribble
= (uchar
*) cmd
;
387 /* We know that there's at least one command in 'input_Q' now.
388 * Go see if any of them are runnable!
391 wd33c93_execute(cmd
->device
->host
);
393 DB(DB_QUEUE_COMMAND
, printk(")Q "))
395 spin_unlock_irq(&hostdata
->lock
);
399 DEF_SCSI_QCMD(wd33c93_queuecommand
)
402 * This routine attempts to start a scsi command. If the host_card is
403 * already connected, we give up immediately. Otherwise, look through
404 * the input_Q, using the first command we find that's intended
405 * for a currently non-busy target/lun.
407 * wd33c93_execute() is always called with interrupts disabled or from
408 * the wd33c93_intr itself, which means that a wd33c93 interrupt
409 * cannot occur while we are in here.
412 wd33c93_execute(struct Scsi_Host
*instance
)
414 struct scsi_pointer
*scsi_pointer
;
415 struct WD33C93_hostdata
*hostdata
=
416 (struct WD33C93_hostdata
*) instance
->hostdata
;
417 const wd33c93_regs regs
= hostdata
->regs
;
418 struct scsi_cmnd
*cmd
, *prev
;
420 DB(DB_EXECUTE
, printk("EX("))
421 if (hostdata
->selecting
|| hostdata
->connected
) {
422 DB(DB_EXECUTE
, printk(")EX-0 "))
427 * Search through the input_Q for a command destined
428 * for an idle target/lun.
431 cmd
= (struct scsi_cmnd
*) hostdata
->input_Q
;
434 if (!(hostdata
->busy
[cmd
->device
->id
] &
435 (1 << (cmd
->device
->lun
& 0xff))))
438 cmd
= (struct scsi_cmnd
*) cmd
->host_scribble
;
441 /* quit if queue empty or all possible targets are busy */
444 DB(DB_EXECUTE
, printk(")EX-1 "))
448 /* remove command from queue */
451 prev
->host_scribble
= cmd
->host_scribble
;
453 hostdata
->input_Q
= (struct scsi_cmnd
*) cmd
->host_scribble
;
455 #ifdef PROC_STATISTICS
456 hostdata
->cmd_cnt
[cmd
->device
->id
]++;
460 * Start the selection process
463 if (cmd
->sc_data_direction
== DMA_TO_DEVICE
)
464 write_wd33c93(regs
, WD_DESTINATION_ID
, cmd
->device
->id
);
466 write_wd33c93(regs
, WD_DESTINATION_ID
, cmd
->device
->id
| DSTID_DPD
);
468 /* Now we need to figure out whether or not this command is a good
469 * candidate for disconnect/reselect. We guess to the best of our
470 * ability, based on a set of hierarchical rules. When several
471 * devices are operating simultaneously, disconnects are usually
472 * an advantage. In a single device system, or if only 1 device
473 * is being accessed, transfers usually go faster if disconnects
476 * + Commands should NEVER disconnect if hostdata->disconnect =
477 * DIS_NEVER (this holds for tape drives also), and ALWAYS
478 * disconnect if hostdata->disconnect = DIS_ALWAYS.
479 * + Tape drive commands should always be allowed to disconnect.
480 * + Disconnect should be allowed if disconnected_Q isn't empty.
481 * + Commands should NOT disconnect if input_Q is empty.
482 * + Disconnect should be allowed if there are commands in input_Q
483 * for a different target/lun. In this case, the other commands
484 * should be made disconnect-able, if not already.
486 * I know, I know - this code would flunk me out of any
487 * "C Programming 101" class ever offered. But it's easy
488 * to change around and experiment with for now.
491 scsi_pointer
= WD33C93_scsi_pointer(cmd
);
492 scsi_pointer
->phase
= 0; /* assume no disconnect */
493 if (hostdata
->disconnect
== DIS_NEVER
)
495 if (hostdata
->disconnect
== DIS_ALWAYS
)
497 if (cmd
->device
->type
== 1) /* tape drive? */
499 if (hostdata
->disconnected_Q
) /* other commands disconnected? */
501 if (!(hostdata
->input_Q
)) /* input_Q empty? */
503 for (prev
= (struct scsi_cmnd
*) hostdata
->input_Q
; prev
;
504 prev
= (struct scsi_cmnd
*) prev
->host_scribble
) {
505 if ((prev
->device
->id
!= cmd
->device
->id
) ||
506 (prev
->device
->lun
!= cmd
->device
->lun
)) {
507 for (prev
= (struct scsi_cmnd
*) hostdata
->input_Q
; prev
;
508 prev
= (struct scsi_cmnd
*) prev
->host_scribble
)
509 WD33C93_scsi_pointer(prev
)->phase
= 1;
517 scsi_pointer
->phase
= 1;
519 #ifdef PROC_STATISTICS
520 hostdata
->disc_allowed_cnt
[cmd
->device
->id
]++;
525 write_wd33c93(regs
, WD_SOURCE_ID
, scsi_pointer
->phase
? SRCID_ER
: 0);
527 write_wd33c93(regs
, WD_TARGET_LUN
, (u8
)cmd
->device
->lun
);
528 write_wd33c93(regs
, WD_SYNCHRONOUS_TRANSFER
,
529 hostdata
->sync_xfer
[cmd
->device
->id
]);
530 hostdata
->busy
[cmd
->device
->id
] |= (1 << (cmd
->device
->lun
& 0xFF));
532 if ((hostdata
->level2
== L2_NONE
) ||
533 (hostdata
->sync_stat
[cmd
->device
->id
] == SS_UNSET
)) {
536 * Do a 'Select-With-ATN' command. This will end with
537 * one of the following interrupts:
538 * CSR_RESEL_AM: failure - can try again later.
539 * CSR_TIMEOUT: failure - give up.
540 * CSR_SELECT: success - proceed.
543 hostdata
->selecting
= cmd
;
545 /* Every target has its own synchronous transfer setting, kept in the
546 * sync_xfer array, and a corresponding status byte in sync_stat[].
547 * Each target's sync_stat[] entry is initialized to SX_UNSET, and its
548 * sync_xfer[] entry is initialized to the default/safe value. SS_UNSET
549 * means that the parameters are undetermined as yet, and that we
550 * need to send an SDTR message to this device after selection is
551 * complete: We set SS_FIRST to tell the interrupt routine to do so.
552 * If we've been asked not to try synchronous transfers on this
553 * target (and _all_ luns within it), we'll still send the SDTR message
554 * later, but at that time we'll negotiate for async by specifying a
555 * sync fifo depth of 0.
557 if (hostdata
->sync_stat
[cmd
->device
->id
] == SS_UNSET
)
558 hostdata
->sync_stat
[cmd
->device
->id
] = SS_FIRST
;
559 hostdata
->state
= S_SELECTING
;
560 write_wd33c93_count(regs
, 0); /* guarantee a DATA_PHASE interrupt */
561 write_wd33c93_cmd(regs
, WD_CMD_SEL_ATN
);
565 * Do a 'Select-With-ATN-Xfer' command. This will end with
566 * one of the following interrupts:
567 * CSR_RESEL_AM: failure - can try again later.
568 * CSR_TIMEOUT: failure - give up.
569 * anything else: success - proceed.
572 hostdata
->connected
= cmd
;
573 write_wd33c93(regs
, WD_COMMAND_PHASE
, 0);
575 /* copy command_descriptor_block into WD chip
576 * (take advantage of auto-incrementing)
579 write_wd33c93_cdb(regs
, cmd
->cmd_len
, cmd
->cmnd
);
581 /* The wd33c93 only knows about Group 0, 1, and 5 commands when
582 * it's doing a 'select-and-transfer'. To be safe, we write the
583 * size of the CDB into the OWN_ID register for every case. This
584 * way there won't be problems with vendor-unique, audio, etc.
587 write_wd33c93(regs
, WD_OWN_ID
, cmd
->cmd_len
);
589 /* When doing a non-disconnect command with DMA, we can save
590 * ourselves a DATA phase interrupt later by setting everything
594 if (scsi_pointer
->phase
== 0 && hostdata
->no_dma
== 0) {
595 if (hostdata
->dma_setup(cmd
,
596 (cmd
->sc_data_direction
== DMA_TO_DEVICE
) ?
597 DATA_OUT_DIR
: DATA_IN_DIR
))
598 write_wd33c93_count(regs
, 0); /* guarantee a DATA_PHASE interrupt */
600 write_wd33c93_count(regs
,
601 scsi_pointer
->this_residual
);
602 write_wd33c93(regs
, WD_CONTROL
,
603 CTRL_IDI
| CTRL_EDI
| hostdata
->dma_mode
);
604 hostdata
->dma
= D_DMA_RUNNING
;
607 write_wd33c93_count(regs
, 0); /* guarantee a DATA_PHASE interrupt */
609 hostdata
->state
= S_RUNNING_LEVEL2
;
610 write_wd33c93_cmd(regs
, WD_CMD_SEL_ATN_XFER
);
614 * Since the SCSI bus can handle only 1 connection at a time,
615 * we get out of here now. If the selection fails, or when
616 * the command disconnects, we'll come back to this routine
617 * to search the input_Q again...
621 printk("%s)EX-2 ", scsi_pointer
->phase
? "d:" : ""))
625 transfer_pio(const wd33c93_regs regs
, uchar
* buf
, int cnt
,
626 int data_in_dir
, struct WD33C93_hostdata
*hostdata
)
631 printk("(%p,%d,%s:", buf
, cnt
, data_in_dir
? "in" : "out"))
633 write_wd33c93(regs
, WD_CONTROL
, CTRL_IDI
| CTRL_EDI
| CTRL_POLLED
);
634 write_wd33c93_count(regs
, cnt
);
635 write_wd33c93_cmd(regs
, WD_CMD_TRANS_INFO
);
638 asr
= read_aux_stat(regs
);
640 *buf
++ = read_wd33c93(regs
, WD_DATA
);
641 } while (!(asr
& ASR_INT
));
644 asr
= read_aux_stat(regs
);
646 write_wd33c93(regs
, WD_DATA
, *buf
++);
647 } while (!(asr
& ASR_INT
));
650 /* Note: we are returning with the interrupt UN-cleared.
651 * Since (presumably) an entire I/O operation has
652 * completed, the bus phase is probably different, and
653 * the interrupt routine will discover this when it
654 * responds to the uncleared int.
660 transfer_bytes(const wd33c93_regs regs
, struct scsi_cmnd
*cmd
,
663 struct scsi_pointer
*scsi_pointer
= WD33C93_scsi_pointer(cmd
);
664 struct WD33C93_hostdata
*hostdata
;
665 unsigned long length
;
667 hostdata
= (struct WD33C93_hostdata
*) cmd
->device
->host
->hostdata
;
669 /* Normally, you'd expect 'this_residual' to be non-zero here.
670 * In a series of scatter-gather transfers, however, this
671 * routine will usually be called with 'this_residual' equal
672 * to 0 and 'buffers_residual' non-zero. This means that a
673 * previous transfer completed, clearing 'this_residual', and
674 * now we need to setup the next scatter-gather buffer as the
675 * source or destination for THIS transfer.
677 if (!scsi_pointer
->this_residual
&& scsi_pointer
->buffers_residual
) {
678 scsi_pointer
->buffer
= sg_next(scsi_pointer
->buffer
);
679 --scsi_pointer
->buffers_residual
;
680 scsi_pointer
->this_residual
= scsi_pointer
->buffer
->length
;
681 scsi_pointer
->ptr
= sg_virt(scsi_pointer
->buffer
);
683 if (!scsi_pointer
->this_residual
) /* avoid bogus setups */
686 write_wd33c93(regs
, WD_SYNCHRONOUS_TRANSFER
,
687 hostdata
->sync_xfer
[cmd
->device
->id
]);
689 /* 'hostdata->no_dma' is TRUE if we don't even want to try DMA.
690 * Update 'this_residual' and 'ptr' after 'transfer_pio()' returns.
693 if (hostdata
->no_dma
|| hostdata
->dma_setup(cmd
, data_in_dir
)) {
694 #ifdef PROC_STATISTICS
697 transfer_pio(regs
, (uchar
*) scsi_pointer
->ptr
,
698 scsi_pointer
->this_residual
, data_in_dir
,
700 length
= scsi_pointer
->this_residual
;
701 scsi_pointer
->this_residual
= read_wd33c93_count(regs
);
702 scsi_pointer
->ptr
+= length
- scsi_pointer
->this_residual
;
705 /* We are able to do DMA (in fact, the Amiga hardware is
706 * already going!), so start up the wd33c93 in DMA mode.
707 * We set 'hostdata->dma' = D_DMA_RUNNING so that when the
708 * transfer completes and causes an interrupt, we're
709 * reminded to tell the Amiga to shut down its end. We'll
710 * postpone the updating of 'this_residual' and 'ptr'
715 #ifdef PROC_STATISTICS
718 write_wd33c93(regs
, WD_CONTROL
, CTRL_IDI
| CTRL_EDI
| hostdata
->dma_mode
);
719 write_wd33c93_count(regs
, scsi_pointer
->this_residual
);
721 if ((hostdata
->level2
>= L2_DATA
) ||
722 (hostdata
->level2
== L2_BASIC
&& scsi_pointer
->phase
== 0)) {
723 write_wd33c93(regs
, WD_COMMAND_PHASE
, 0x45);
724 write_wd33c93_cmd(regs
, WD_CMD_SEL_ATN_XFER
);
725 hostdata
->state
= S_RUNNING_LEVEL2
;
727 write_wd33c93_cmd(regs
, WD_CMD_TRANS_INFO
);
729 hostdata
->dma
= D_DMA_RUNNING
;
734 wd33c93_intr(struct Scsi_Host
*instance
)
736 struct scsi_pointer
*scsi_pointer
;
737 struct WD33C93_hostdata
*hostdata
=
738 (struct WD33C93_hostdata
*) instance
->hostdata
;
739 const wd33c93_regs regs
= hostdata
->regs
;
740 struct scsi_cmnd
*patch
, *cmd
;
741 uchar asr
, sr
, phs
, id
, lun
, *ucp
, msg
;
742 unsigned long length
, flags
;
744 asr
= read_aux_stat(regs
);
745 if (!(asr
& ASR_INT
) || (asr
& ASR_BSY
))
748 spin_lock_irqsave(&hostdata
->lock
, flags
);
750 #ifdef PROC_STATISTICS
754 cmd
= (struct scsi_cmnd
*) hostdata
->connected
; /* assume we're connected */
755 scsi_pointer
= WD33C93_scsi_pointer(cmd
);
756 sr
= read_wd33c93(regs
, WD_SCSI_STATUS
); /* clear the interrupt */
757 phs
= read_wd33c93(regs
, WD_COMMAND_PHASE
);
759 DB(DB_INTR
, printk("{%02x:%02x-", asr
, sr
))
761 /* After starting a DMA transfer, the next interrupt
762 * is guaranteed to be in response to completion of
763 * the transfer. Since the Amiga DMA hardware runs in
764 * in an open-ended fashion, it needs to be told when
765 * to stop; do that here if D_DMA_RUNNING is true.
766 * Also, we have to update 'this_residual' and 'ptr'
767 * based on the contents of the TRANSFER_COUNT register,
768 * in case the device decided to do an intermediate
769 * disconnect (a device may do this if it has to do a
770 * seek, or just to be nice and let other devices have
771 * some bus time during long transfers). After doing
772 * whatever is needed, we go on and service the WD3393
773 * interrupt normally.
775 if (hostdata
->dma
== D_DMA_RUNNING
) {
777 printk("[%p/%d:", scsi_pointer
->ptr
, scsi_pointer
->this_residual
))
778 hostdata
->dma_stop(cmd
->device
->host
, cmd
, 1);
779 hostdata
->dma
= D_DMA_OFF
;
780 length
= scsi_pointer
->this_residual
;
781 scsi_pointer
->this_residual
= read_wd33c93_count(regs
);
782 scsi_pointer
->ptr
+= length
- scsi_pointer
->this_residual
;
784 printk("%p/%d]", scsi_pointer
->ptr
, scsi_pointer
->this_residual
))
787 /* Respond to the specific WD3393 interrupt - there are quite a few! */
790 DB(DB_INTR
, printk("TIMEOUT"))
792 if (hostdata
->state
== S_RUNNING_LEVEL2
)
793 hostdata
->connected
= NULL
;
795 cmd
= (struct scsi_cmnd
*) hostdata
->selecting
; /* get a valid cmd */
796 hostdata
->selecting
= NULL
;
799 cmd
->result
= DID_NO_CONNECT
<< 16;
800 hostdata
->busy
[cmd
->device
->id
] &= ~(1 << (cmd
->device
->lun
& 0xff));
801 hostdata
->state
= S_UNCONNECTED
;
805 * There is a window of time within the scsi_done() path
806 * of execution where interrupts are turned back on full
807 * blast and left that way. During that time we could
808 * reconnect to a disconnected command, then we'd bomb
809 * out below. We could also end up executing two commands
810 * at _once_. ...just so you know why the restore_flags()
814 spin_unlock_irqrestore(&hostdata
->lock
, flags
);
816 /* We are not connected to a target - check to see if there
817 * are commands waiting to be executed.
820 wd33c93_execute(instance
);
823 /* Note: this interrupt should not occur in a LEVEL2 command */
826 DB(DB_INTR
, printk("SELECT"))
827 hostdata
->connected
= cmd
=
828 (struct scsi_cmnd
*) hostdata
->selecting
;
829 hostdata
->selecting
= NULL
;
831 /* construct an IDENTIFY message with correct disconnect bit */
833 hostdata
->outgoing_msg
[0] = IDENTIFY(0, cmd
->device
->lun
);
834 if (WD33C93_scsi_pointer(cmd
)->phase
)
835 hostdata
->outgoing_msg
[0] |= 0x40;
837 if (hostdata
->sync_stat
[cmd
->device
->id
] == SS_FIRST
) {
839 hostdata
->sync_stat
[cmd
->device
->id
] = SS_WAITING
;
841 /* Tack on a 2nd message to ask about synchronous transfers. If we've
842 * been asked to do only asynchronous transfers on this device, we
843 * request a fifo depth of 0, which is equivalent to async - should
844 * solve the problems some people have had with GVP's Guru ROM.
847 hostdata
->outgoing_msg
[1] = EXTENDED_MESSAGE
;
848 hostdata
->outgoing_msg
[2] = 3;
849 hostdata
->outgoing_msg
[3] = EXTENDED_SDTR
;
850 if (hostdata
->no_sync
& (1 << cmd
->device
->id
)) {
851 calc_sync_msg(hostdata
->default_sx_per
, 0,
852 0, hostdata
->outgoing_msg
+ 4);
854 calc_sync_msg(optimum_sx_per(hostdata
),
857 hostdata
->outgoing_msg
+ 4);
859 hostdata
->outgoing_len
= 6;
861 ucp
= hostdata
->outgoing_msg
+ 1;
862 printk(" sending SDTR %02x03%02x%02x%02x ",
863 ucp
[0], ucp
[2], ucp
[3], ucp
[4]);
866 hostdata
->outgoing_len
= 1;
868 hostdata
->state
= S_CONNECTED
;
869 spin_unlock_irqrestore(&hostdata
->lock
, flags
);
872 case CSR_XFER_DONE
| PHS_DATA_IN
:
873 case CSR_UNEXP
| PHS_DATA_IN
:
874 case CSR_SRV_REQ
| PHS_DATA_IN
:
876 printk("IN-%d.%d", scsi_pointer
->this_residual
,
877 scsi_pointer
->buffers_residual
))
878 transfer_bytes(regs
, cmd
, DATA_IN_DIR
);
879 if (hostdata
->state
!= S_RUNNING_LEVEL2
)
880 hostdata
->state
= S_CONNECTED
;
881 spin_unlock_irqrestore(&hostdata
->lock
, flags
);
884 case CSR_XFER_DONE
| PHS_DATA_OUT
:
885 case CSR_UNEXP
| PHS_DATA_OUT
:
886 case CSR_SRV_REQ
| PHS_DATA_OUT
:
888 printk("OUT-%d.%d", scsi_pointer
->this_residual
,
889 scsi_pointer
->buffers_residual
))
890 transfer_bytes(regs
, cmd
, DATA_OUT_DIR
);
891 if (hostdata
->state
!= S_RUNNING_LEVEL2
)
892 hostdata
->state
= S_CONNECTED
;
893 spin_unlock_irqrestore(&hostdata
->lock
, flags
);
896 /* Note: this interrupt should not occur in a LEVEL2 command */
898 case CSR_XFER_DONE
| PHS_COMMAND
:
899 case CSR_UNEXP
| PHS_COMMAND
:
900 case CSR_SRV_REQ
| PHS_COMMAND
:
901 DB(DB_INTR
, printk("CMND-%02x", cmd
->cmnd
[0]))
902 transfer_pio(regs
, cmd
->cmnd
, cmd
->cmd_len
, DATA_OUT_DIR
,
904 hostdata
->state
= S_CONNECTED
;
905 spin_unlock_irqrestore(&hostdata
->lock
, flags
);
908 case CSR_XFER_DONE
| PHS_STATUS
:
909 case CSR_UNEXP
| PHS_STATUS
:
910 case CSR_SRV_REQ
| PHS_STATUS
:
911 DB(DB_INTR
, printk("STATUS="))
912 scsi_pointer
->Status
= read_1_byte(regs
);
913 DB(DB_INTR
, printk("%02x", scsi_pointer
->Status
))
914 if (hostdata
->level2
>= L2_BASIC
) {
915 sr
= read_wd33c93(regs
, WD_SCSI_STATUS
); /* clear interrupt */
917 hostdata
->state
= S_RUNNING_LEVEL2
;
918 write_wd33c93(regs
, WD_COMMAND_PHASE
, 0x50);
919 write_wd33c93_cmd(regs
, WD_CMD_SEL_ATN_XFER
);
921 hostdata
->state
= S_CONNECTED
;
923 spin_unlock_irqrestore(&hostdata
->lock
, flags
);
926 case CSR_XFER_DONE
| PHS_MESS_IN
:
927 case CSR_UNEXP
| PHS_MESS_IN
:
928 case CSR_SRV_REQ
| PHS_MESS_IN
:
929 DB(DB_INTR
, printk("MSG_IN="))
931 msg
= read_1_byte(regs
);
932 sr
= read_wd33c93(regs
, WD_SCSI_STATUS
); /* clear interrupt */
935 hostdata
->incoming_msg
[hostdata
->incoming_ptr
] = msg
;
936 if (hostdata
->incoming_msg
[0] == EXTENDED_MESSAGE
)
937 msg
= EXTENDED_MESSAGE
;
939 hostdata
->incoming_ptr
= 0;
941 scsi_pointer
->Message
= msg
;
944 case COMMAND_COMPLETE
:
945 DB(DB_INTR
, printk("CCMP"))
946 write_wd33c93_cmd(regs
, WD_CMD_NEGATE_ACK
);
947 hostdata
->state
= S_PRE_CMP_DISC
;
951 DB(DB_INTR
, printk("SDP"))
952 write_wd33c93_cmd(regs
, WD_CMD_NEGATE_ACK
);
953 hostdata
->state
= S_CONNECTED
;
956 case RESTORE_POINTERS
:
957 DB(DB_INTR
, printk("RDP"))
958 if (hostdata
->level2
>= L2_BASIC
) {
959 write_wd33c93(regs
, WD_COMMAND_PHASE
, 0x45);
960 write_wd33c93_cmd(regs
, WD_CMD_SEL_ATN_XFER
);
961 hostdata
->state
= S_RUNNING_LEVEL2
;
963 write_wd33c93_cmd(regs
, WD_CMD_NEGATE_ACK
);
964 hostdata
->state
= S_CONNECTED
;
969 DB(DB_INTR
, printk("DIS"))
970 cmd
->device
->disconnect
= 1;
971 write_wd33c93_cmd(regs
, WD_CMD_NEGATE_ACK
);
972 hostdata
->state
= S_PRE_TMP_DISC
;
976 DB(DB_INTR
, printk("REJ"))
980 if (hostdata
->sync_stat
[cmd
->device
->id
] == SS_WAITING
) {
981 hostdata
->sync_stat
[cmd
->device
->id
] = SS_SET
;
982 /* we want default_sx_per, not DEFAULT_SX_PER */
983 hostdata
->sync_xfer
[cmd
->device
->id
] =
984 calc_sync_xfer(hostdata
->default_sx_per
985 / 4, 0, 0, hostdata
->sx_table
);
987 write_wd33c93_cmd(regs
, WD_CMD_NEGATE_ACK
);
988 hostdata
->state
= S_CONNECTED
;
991 case EXTENDED_MESSAGE
:
992 DB(DB_INTR
, printk("EXT"))
994 ucp
= hostdata
->incoming_msg
;
997 printk("%02x", ucp
[hostdata
->incoming_ptr
]);
999 /* Is this the last byte of the extended message? */
1001 if ((hostdata
->incoming_ptr
>= 2) &&
1002 (hostdata
->incoming_ptr
== (ucp
[1] + 1))) {
1004 switch (ucp
[2]) { /* what's the EXTENDED code? */
1006 /* default to default async period */
1007 id
= calc_sync_xfer(hostdata
->
1008 default_sx_per
/ 4, 0,
1009 0, hostdata
->sx_table
);
1010 if (hostdata
->sync_stat
[cmd
->device
->id
] !=
1013 /* A device has sent an unsolicited SDTR message; rather than go
1014 * through the effort of decoding it and then figuring out what
1015 * our reply should be, we're just gonna say that we have a
1016 * synchronous fifo depth of 0. This will result in asynchronous
1017 * transfers - not ideal but so much easier.
1018 * Actually, this is OK because it assures us that if we don't
1019 * specifically ask for sync transfers, we won't do any.
1022 write_wd33c93_cmd(regs
, WD_CMD_ASSERT_ATN
); /* want MESS_OUT */
1023 hostdata
->outgoing_msg
[0] =
1025 hostdata
->outgoing_msg
[1] = 3;
1026 hostdata
->outgoing_msg
[2] =
1028 calc_sync_msg(hostdata
->
1030 0, hostdata
->outgoing_msg
+ 3);
1031 hostdata
->outgoing_len
= 5;
1033 if (ucp
[4]) /* well, sync transfer */
1034 id
= calc_sync_xfer(ucp
[3], ucp
[4],
1036 hostdata
->sx_table
);
1037 else if (ucp
[3]) /* very unlikely... */
1038 id
= calc_sync_xfer(ucp
[3], ucp
[4],
1039 0, hostdata
->sx_table
);
1041 hostdata
->sync_xfer
[cmd
->device
->id
] = id
;
1043 printk(" sync_xfer=%02x\n",
1044 hostdata
->sync_xfer
[cmd
->device
->id
]);
1046 hostdata
->sync_stat
[cmd
->device
->id
] =
1048 write_wd33c93_cmd(regs
,
1050 hostdata
->state
= S_CONNECTED
;
1053 write_wd33c93_cmd(regs
, WD_CMD_ASSERT_ATN
); /* want MESS_OUT */
1054 printk("sending WDTR ");
1055 hostdata
->outgoing_msg
[0] =
1057 hostdata
->outgoing_msg
[1] = 2;
1058 hostdata
->outgoing_msg
[2] =
1060 hostdata
->outgoing_msg
[3] = 0; /* 8 bit transfer width */
1061 hostdata
->outgoing_len
= 4;
1062 write_wd33c93_cmd(regs
,
1064 hostdata
->state
= S_CONNECTED
;
1067 write_wd33c93_cmd(regs
, WD_CMD_ASSERT_ATN
); /* want MESS_OUT */
1069 ("Rejecting Unknown Extended Message(%02x). ",
1071 hostdata
->outgoing_msg
[0] =
1073 hostdata
->outgoing_len
= 1;
1074 write_wd33c93_cmd(regs
,
1076 hostdata
->state
= S_CONNECTED
;
1079 hostdata
->incoming_ptr
= 0;
1082 /* We need to read more MESS_IN bytes for the extended message */
1085 hostdata
->incoming_ptr
++;
1086 write_wd33c93_cmd(regs
, WD_CMD_NEGATE_ACK
);
1087 hostdata
->state
= S_CONNECTED
;
1092 printk("Rejecting Unknown Message(%02x) ", msg
);
1093 write_wd33c93_cmd(regs
, WD_CMD_ASSERT_ATN
); /* want MESS_OUT */
1094 hostdata
->outgoing_msg
[0] = MESSAGE_REJECT
;
1095 hostdata
->outgoing_len
= 1;
1096 write_wd33c93_cmd(regs
, WD_CMD_NEGATE_ACK
);
1097 hostdata
->state
= S_CONNECTED
;
1099 spin_unlock_irqrestore(&hostdata
->lock
, flags
);
1102 /* Note: this interrupt will occur only after a LEVEL2 command */
1104 case CSR_SEL_XFER_DONE
:
1106 /* Make sure that reselection is enabled at this point - it may
1107 * have been turned off for the command that just completed.
1110 write_wd33c93(regs
, WD_SOURCE_ID
, SRCID_ER
);
1112 DB(DB_INTR
, printk("SX-DONE"))
1113 scsi_pointer
->Message
= COMMAND_COMPLETE
;
1114 lun
= read_wd33c93(regs
, WD_TARGET_LUN
);
1115 DB(DB_INTR
, printk(":%d.%d", scsi_pointer
->Status
, lun
))
1116 hostdata
->connected
= NULL
;
1117 hostdata
->busy
[cmd
->device
->id
] &= ~(1 << (cmd
->device
->lun
& 0xff));
1118 hostdata
->state
= S_UNCONNECTED
;
1119 if (scsi_pointer
->Status
== ILLEGAL_STATUS_BYTE
)
1120 scsi_pointer
->Status
= lun
;
1121 if (cmd
->cmnd
[0] == REQUEST_SENSE
1122 && scsi_pointer
->Status
!= SAM_STAT_GOOD
) {
1123 set_host_byte(cmd
, DID_ERROR
);
1125 set_host_byte(cmd
, DID_OK
);
1126 scsi_msg_to_host_byte(cmd
, scsi_pointer
->Message
);
1127 set_status_byte(cmd
, scsi_pointer
->Status
);
1131 /* We are no longer connected to a target - check to see if
1132 * there are commands waiting to be executed.
1134 spin_unlock_irqrestore(&hostdata
->lock
, flags
);
1135 wd33c93_execute(instance
);
1138 ("%02x:%02x:%02x: Unknown SEL_XFER_DONE phase!!---",
1140 spin_unlock_irqrestore(&hostdata
->lock
, flags
);
1144 /* Note: this interrupt will occur only after a LEVEL2 command */
1147 DB(DB_INTR
, printk("SDP"))
1148 hostdata
->state
= S_RUNNING_LEVEL2
;
1149 write_wd33c93(regs
, WD_COMMAND_PHASE
, 0x41);
1150 write_wd33c93_cmd(regs
, WD_CMD_SEL_ATN_XFER
);
1151 spin_unlock_irqrestore(&hostdata
->lock
, flags
);
1154 case CSR_XFER_DONE
| PHS_MESS_OUT
:
1155 case CSR_UNEXP
| PHS_MESS_OUT
:
1156 case CSR_SRV_REQ
| PHS_MESS_OUT
:
1157 DB(DB_INTR
, printk("MSG_OUT="))
1159 /* To get here, we've probably requested MESSAGE_OUT and have
1160 * already put the correct bytes in outgoing_msg[] and filled
1161 * in outgoing_len. We simply send them out to the SCSI bus.
1162 * Sometimes we get MESSAGE_OUT phase when we're not expecting
1163 * it - like when our SDTR message is rejected by a target. Some
1164 * targets send the REJECT before receiving all of the extended
1165 * message, and then seem to go back to MESSAGE_OUT for a byte
1166 * or two. Not sure why, or if I'm doing something wrong to
1167 * cause this to happen. Regardless, it seems that sending
1168 * NOP messages in these situations results in no harm and
1169 * makes everyone happy.
1171 if (hostdata
->outgoing_len
== 0) {
1172 hostdata
->outgoing_len
= 1;
1173 hostdata
->outgoing_msg
[0] = NOP
;
1175 transfer_pio(regs
, hostdata
->outgoing_msg
,
1176 hostdata
->outgoing_len
, DATA_OUT_DIR
, hostdata
);
1177 DB(DB_INTR
, printk("%02x", hostdata
->outgoing_msg
[0]))
1178 hostdata
->outgoing_len
= 0;
1179 hostdata
->state
= S_CONNECTED
;
1180 spin_unlock_irqrestore(&hostdata
->lock
, flags
);
1183 case CSR_UNEXP_DISC
:
1185 /* I think I've seen this after a request-sense that was in response
1186 * to an error condition, but not sure. We certainly need to do
1187 * something when we get this interrupt - the question is 'what?'.
1188 * Let's think positively, and assume some command has finished
1189 * in a legal manner (like a command that provokes a request-sense),
1190 * so we treat it as a normal command-complete-disconnect.
1193 /* Make sure that reselection is enabled at this point - it may
1194 * have been turned off for the command that just completed.
1197 write_wd33c93(regs
, WD_SOURCE_ID
, SRCID_ER
);
1199 printk(" - Already disconnected! ");
1200 hostdata
->state
= S_UNCONNECTED
;
1201 spin_unlock_irqrestore(&hostdata
->lock
, flags
);
1204 DB(DB_INTR
, printk("UNEXP_DISC"))
1205 hostdata
->connected
= NULL
;
1206 hostdata
->busy
[cmd
->device
->id
] &= ~(1 << (cmd
->device
->lun
& 0xff));
1207 hostdata
->state
= S_UNCONNECTED
;
1208 if (cmd
->cmnd
[0] == REQUEST_SENSE
&&
1209 scsi_pointer
->Status
!= SAM_STAT_GOOD
) {
1210 set_host_byte(cmd
, DID_ERROR
);
1212 set_host_byte(cmd
, DID_OK
);
1213 scsi_msg_to_host_byte(cmd
, scsi_pointer
->Message
);
1214 set_status_byte(cmd
, scsi_pointer
->Status
);
1218 /* We are no longer connected to a target - check to see if
1219 * there are commands waiting to be executed.
1221 /* look above for comments on scsi_done() */
1222 spin_unlock_irqrestore(&hostdata
->lock
, flags
);
1223 wd33c93_execute(instance
);
1228 /* Make sure that reselection is enabled at this point - it may
1229 * have been turned off for the command that just completed.
1232 write_wd33c93(regs
, WD_SOURCE_ID
, SRCID_ER
);
1233 DB(DB_INTR
, printk("DISC"))
1235 printk(" - Already disconnected! ");
1236 hostdata
->state
= S_UNCONNECTED
;
1238 switch (hostdata
->state
) {
1239 case S_PRE_CMP_DISC
:
1240 hostdata
->connected
= NULL
;
1241 hostdata
->busy
[cmd
->device
->id
] &= ~(1 << (cmd
->device
->lun
& 0xff));
1242 hostdata
->state
= S_UNCONNECTED
;
1243 DB(DB_INTR
, printk(":%d", scsi_pointer
->Status
))
1244 if (cmd
->cmnd
[0] == REQUEST_SENSE
1245 && scsi_pointer
->Status
!= SAM_STAT_GOOD
) {
1246 set_host_byte(cmd
, DID_ERROR
);
1248 set_host_byte(cmd
, DID_OK
);
1249 scsi_msg_to_host_byte(cmd
, scsi_pointer
->Message
);
1250 set_status_byte(cmd
, scsi_pointer
->Status
);
1254 case S_PRE_TMP_DISC
:
1255 case S_RUNNING_LEVEL2
:
1256 cmd
->host_scribble
= (uchar
*) hostdata
->disconnected_Q
;
1257 hostdata
->disconnected_Q
= cmd
;
1258 hostdata
->connected
= NULL
;
1259 hostdata
->state
= S_UNCONNECTED
;
1261 #ifdef PROC_STATISTICS
1262 hostdata
->disc_done_cnt
[cmd
->device
->id
]++;
1267 printk("*** Unexpected DISCONNECT interrupt! ***");
1268 hostdata
->state
= S_UNCONNECTED
;
1271 /* We are no longer connected to a target - check to see if
1272 * there are commands waiting to be executed.
1274 spin_unlock_irqrestore(&hostdata
->lock
, flags
);
1275 wd33c93_execute(instance
);
1280 DB(DB_INTR
, printk("RESEL%s", sr
== CSR_RESEL_AM
? "_AM" : ""))
1282 /* Old chips (pre -A ???) don't have advanced features and will
1283 * generate CSR_RESEL. In that case we have to extract the LUN the
1284 * hard way (see below).
1285 * First we have to make sure this reselection didn't
1286 * happen during Arbitration/Selection of some other device.
1287 * If yes, put losing command back on top of input_Q.
1289 if (hostdata
->level2
<= L2_NONE
) {
1291 if (hostdata
->selecting
) {
1292 cmd
= (struct scsi_cmnd
*) hostdata
->selecting
;
1293 hostdata
->selecting
= NULL
;
1294 hostdata
->busy
[cmd
->device
->id
] &= ~(1 << (cmd
->device
->lun
& 0xff));
1295 cmd
->host_scribble
=
1296 (uchar
*) hostdata
->input_Q
;
1297 hostdata
->input_Q
= cmd
;
1305 hostdata
->busy
[cmd
->device
->id
] &=
1306 ~(1 << (cmd
->device
->lun
& 0xff));
1307 cmd
->host_scribble
=
1308 (uchar
*) hostdata
->input_Q
;
1309 hostdata
->input_Q
= cmd
;
1312 ("---%02x:%02x:%02x-TROUBLE: Intrusive ReSelect!---",
1321 /* OK - find out which device reselected us. */
1323 id
= read_wd33c93(regs
, WD_SOURCE_ID
);
1326 /* and extract the lun from the ID message. (Note that we don't
1327 * bother to check for a valid message here - I guess this is
1328 * not the right way to go, but...)
1331 if (sr
== CSR_RESEL_AM
) {
1332 lun
= read_wd33c93(regs
, WD_DATA
);
1333 if (hostdata
->level2
< L2_RESELECT
)
1334 write_wd33c93_cmd(regs
, WD_CMD_NEGATE_ACK
);
1337 /* Old chip; wait for msgin phase to pick up the LUN. */
1338 for (lun
= 255; lun
; lun
--) {
1339 if ((asr
= read_aux_stat(regs
)) & ASR_INT
)
1343 if (!(asr
& ASR_INT
)) {
1345 ("wd33c93: Reselected without IDENTIFY\n");
1348 /* Verify this is a change to MSG_IN and read the message */
1349 sr
= read_wd33c93(regs
, WD_SCSI_STATUS
);
1351 if (sr
== (CSR_ABORT
| PHS_MESS_IN
) ||
1352 sr
== (CSR_UNEXP
| PHS_MESS_IN
) ||
1353 sr
== (CSR_SRV_REQ
| PHS_MESS_IN
)) {
1354 /* Got MSG_IN, grab target LUN */
1355 lun
= read_1_byte(regs
);
1356 /* Now we expect a 'paused with ACK asserted' int.. */
1357 asr
= read_aux_stat(regs
);
1358 if (!(asr
& ASR_INT
)) {
1360 asr
= read_aux_stat(regs
);
1361 if (!(asr
& ASR_INT
))
1363 ("wd33c93: No int after LUN on RESEL (%02x)\n",
1366 sr
= read_wd33c93(regs
, WD_SCSI_STATUS
);
1368 if (sr
!= CSR_MSGIN
)
1370 ("wd33c93: Not paused with ACK on RESEL (%02x)\n",
1373 write_wd33c93_cmd(regs
,
1377 ("wd33c93: Not MSG_IN on reselect (%02x)\n",
1384 /* Now we look for the command that's reconnecting. */
1386 cmd
= (struct scsi_cmnd
*) hostdata
->disconnected_Q
;
1389 if (id
== cmd
->device
->id
&& lun
== (u8
)cmd
->device
->lun
)
1392 cmd
= (struct scsi_cmnd
*) cmd
->host_scribble
;
1395 /* Hmm. Couldn't find a valid command.... What to do? */
1399 ("---TROUBLE: target %d.%d not in disconnect queue---",
1401 spin_unlock_irqrestore(&hostdata
->lock
, flags
);
1405 /* Ok, found the command - now start it up again. */
1408 patch
->host_scribble
= cmd
->host_scribble
;
1410 hostdata
->disconnected_Q
=
1411 (struct scsi_cmnd
*) cmd
->host_scribble
;
1412 hostdata
->connected
= cmd
;
1414 /* We don't need to worry about 'initialize_SCp()' or 'hostdata->busy[]'
1415 * because these things are preserved over a disconnect.
1416 * But we DO need to fix the DPD bit so it's correct for this command.
1419 if (cmd
->sc_data_direction
== DMA_TO_DEVICE
)
1420 write_wd33c93(regs
, WD_DESTINATION_ID
, cmd
->device
->id
);
1422 write_wd33c93(regs
, WD_DESTINATION_ID
,
1423 cmd
->device
->id
| DSTID_DPD
);
1424 if (hostdata
->level2
>= L2_RESELECT
) {
1425 write_wd33c93_count(regs
, 0); /* we want a DATA_PHASE interrupt */
1426 write_wd33c93(regs
, WD_COMMAND_PHASE
, 0x45);
1427 write_wd33c93_cmd(regs
, WD_CMD_SEL_ATN_XFER
);
1428 hostdata
->state
= S_RUNNING_LEVEL2
;
1430 hostdata
->state
= S_CONNECTED
;
1432 spin_unlock_irqrestore(&hostdata
->lock
, flags
);
1436 printk("--UNKNOWN INTERRUPT:%02x:%02x:%02x--", asr
, sr
, phs
);
1437 spin_unlock_irqrestore(&hostdata
->lock
, flags
);
1440 DB(DB_INTR
, printk("} "))
1445 reset_wd33c93(struct Scsi_Host
*instance
)
1447 struct WD33C93_hostdata
*hostdata
=
1448 (struct WD33C93_hostdata
*) instance
->hostdata
;
1449 const wd33c93_regs regs
= hostdata
->regs
;
1452 #ifdef CONFIG_SGI_IP22
1455 extern void sgiwd93_reset(unsigned long);
1456 /* wait 'til the chip gets some time for us */
1457 while ((read_aux_stat(regs
) & ASR_BSY
) && busycount
++ < 100)
1460 * there are scsi devices out there, which manage to lock up
1461 * the wd33c93 in a busy condition. In this state it won't
1462 * accept the reset command. The only way to solve this is to
1463 * give the chip a hardware reset (if possible). The code below
1464 * does this for the SGI Indy, where this is possible
1467 if (read_aux_stat(regs
) & ASR_BSY
)
1468 sgiwd93_reset(instance
->base
); /* yeah, give it the hard one */
1472 write_wd33c93(regs
, WD_OWN_ID
, OWNID_EAF
| OWNID_RAF
|
1473 instance
->this_id
| hostdata
->clock_freq
);
1474 write_wd33c93(regs
, WD_CONTROL
, CTRL_IDI
| CTRL_EDI
| CTRL_POLLED
);
1475 write_wd33c93(regs
, WD_SYNCHRONOUS_TRANSFER
,
1476 calc_sync_xfer(hostdata
->default_sx_per
/ 4,
1477 DEFAULT_SX_OFF
, 0, hostdata
->sx_table
));
1478 write_wd33c93(regs
, WD_COMMAND
, WD_CMD_RESET
);
1481 #ifdef CONFIG_MVME147_SCSI
1482 udelay(25); /* The old wd33c93 on MVME147 needs this, at least */
1485 while (!(read_aux_stat(regs
) & ASR_INT
))
1487 sr
= read_wd33c93(regs
, WD_SCSI_STATUS
);
1489 hostdata
->microcode
= read_wd33c93(regs
, WD_CDB_1
);
1491 hostdata
->chip
= C_WD33C93
;
1492 else if (sr
== 0x01) {
1493 write_wd33c93(regs
, WD_QUEUE_TAG
, 0xa5); /* any random number */
1494 sr
= read_wd33c93(regs
, WD_QUEUE_TAG
);
1496 hostdata
->chip
= C_WD33C93B
;
1497 write_wd33c93(regs
, WD_QUEUE_TAG
, 0);
1499 hostdata
->chip
= C_WD33C93A
;
1501 hostdata
->chip
= C_UNKNOWN_CHIP
;
1503 if (hostdata
->chip
!= C_WD33C93B
) /* Fast SCSI unavailable */
1506 write_wd33c93(regs
, WD_TIMEOUT_PERIOD
, TIMEOUT_PERIOD_VALUE
);
1507 write_wd33c93(regs
, WD_CONTROL
, CTRL_IDI
| CTRL_EDI
| CTRL_POLLED
);
1511 wd33c93_host_reset(struct scsi_cmnd
* SCpnt
)
1513 struct Scsi_Host
*instance
;
1514 struct WD33C93_hostdata
*hostdata
;
1517 instance
= SCpnt
->device
->host
;
1518 spin_lock_irq(instance
->host_lock
);
1519 hostdata
= (struct WD33C93_hostdata
*) instance
->hostdata
;
1521 printk("scsi%d: reset. ", instance
->host_no
);
1522 disable_irq(instance
->irq
);
1524 hostdata
->dma_stop(instance
, NULL
, 0);
1525 for (i
= 0; i
< 8; i
++) {
1526 hostdata
->busy
[i
] = 0;
1527 hostdata
->sync_xfer
[i
] =
1528 calc_sync_xfer(DEFAULT_SX_PER
/ 4, DEFAULT_SX_OFF
,
1529 0, hostdata
->sx_table
);
1530 hostdata
->sync_stat
[i
] = SS_UNSET
; /* using default sync values */
1532 hostdata
->input_Q
= NULL
;
1533 hostdata
->selecting
= NULL
;
1534 hostdata
->connected
= NULL
;
1535 hostdata
->disconnected_Q
= NULL
;
1536 hostdata
->state
= S_UNCONNECTED
;
1537 hostdata
->dma
= D_DMA_OFF
;
1538 hostdata
->incoming_ptr
= 0;
1539 hostdata
->outgoing_len
= 0;
1541 reset_wd33c93(instance
);
1542 SCpnt
->result
= DID_RESET
<< 16;
1543 enable_irq(instance
->irq
);
1544 spin_unlock_irq(instance
->host_lock
);
1549 wd33c93_abort(struct scsi_cmnd
* cmd
)
1551 struct Scsi_Host
*instance
;
1552 struct WD33C93_hostdata
*hostdata
;
1554 struct scsi_cmnd
*tmp
, *prev
;
1556 disable_irq(cmd
->device
->host
->irq
);
1558 instance
= cmd
->device
->host
;
1559 hostdata
= (struct WD33C93_hostdata
*) instance
->hostdata
;
1560 regs
= hostdata
->regs
;
1563 * Case 1 : If the command hasn't been issued yet, we simply remove it
1567 tmp
= (struct scsi_cmnd
*) hostdata
->input_Q
;
1572 prev
->host_scribble
= cmd
->host_scribble
;
1575 (struct scsi_cmnd
*) cmd
->host_scribble
;
1576 cmd
->host_scribble
= NULL
;
1577 cmd
->result
= DID_ABORT
<< 16;
1579 ("scsi%d: Abort - removing command from input_Q. ",
1581 enable_irq(cmd
->device
->host
->irq
);
1586 tmp
= (struct scsi_cmnd
*) tmp
->host_scribble
;
1590 * Case 2 : If the command is connected, we're going to fail the abort
1591 * and let the high level SCSI driver retry at a later time or
1594 * Timeouts, and therefore aborted commands, will be highly unlikely
1595 * and handling them cleanly in this situation would make the common
1596 * case of noresets less efficient, and would pollute our code. So,
1600 if (hostdata
->connected
== cmd
) {
1602 unsigned long timeout
;
1604 printk("scsi%d: Aborting connected command - ",
1607 printk("stopping DMA - ");
1608 if (hostdata
->dma
== D_DMA_RUNNING
) {
1609 hostdata
->dma_stop(instance
, cmd
, 0);
1610 hostdata
->dma
= D_DMA_OFF
;
1613 printk("sending wd33c93 ABORT command - ");
1614 write_wd33c93(regs
, WD_CONTROL
,
1615 CTRL_IDI
| CTRL_EDI
| CTRL_POLLED
);
1616 write_wd33c93_cmd(regs
, WD_CMD_ABORT
);
1618 /* Now we have to attempt to flush out the FIFO... */
1620 printk("flushing fifo - ");
1623 asr
= read_aux_stat(regs
);
1625 read_wd33c93(regs
, WD_DATA
);
1626 } while (!(asr
& ASR_INT
) && timeout
-- > 0);
1627 sr
= read_wd33c93(regs
, WD_SCSI_STATUS
);
1629 ("asr=%02x, sr=%02x, %ld bytes un-transferred (timeout=%ld) - ",
1630 asr
, sr
, read_wd33c93_count(regs
), timeout
);
1633 * Abort command processed.
1635 * We must disconnect.
1638 printk("sending wd33c93 DISCONNECT command - ");
1639 write_wd33c93_cmd(regs
, WD_CMD_DISCONNECT
);
1642 asr
= read_aux_stat(regs
);
1643 while ((asr
& ASR_CIP
) && timeout
-- > 0)
1644 asr
= read_aux_stat(regs
);
1645 sr
= read_wd33c93(regs
, WD_SCSI_STATUS
);
1646 printk("asr=%02x, sr=%02x.", asr
, sr
);
1648 hostdata
->busy
[cmd
->device
->id
] &= ~(1 << (cmd
->device
->lun
& 0xff));
1649 hostdata
->connected
= NULL
;
1650 hostdata
->state
= S_UNCONNECTED
;
1651 cmd
->result
= DID_ABORT
<< 16;
1654 wd33c93_execute(instance
);
1656 enable_irq(cmd
->device
->host
->irq
);
1662 * Case 3: If the command is currently disconnected from the bus,
1663 * we're not going to expend much effort here: Let's just return
1664 * an ABORT_SNOOZE and hope for the best...
1667 tmp
= (struct scsi_cmnd
*) hostdata
->disconnected_Q
;
1671 ("scsi%d: Abort - command found on disconnected_Q - ",
1673 printk("Abort SNOOZE. ");
1674 enable_irq(cmd
->device
->host
->irq
);
1677 tmp
= (struct scsi_cmnd
*) tmp
->host_scribble
;
1681 * Case 4 : If we reached this point, the command was not found in any of
1684 * We probably reached this point because of an unlikely race condition
1685 * between the command completing successfully and the abortion code,
1686 * so we won't panic, but we will notify the user in case something really
1691 wd33c93_execute(instance
);
1693 enable_irq(cmd
->device
->host
->irq
);
1694 printk("scsi%d: warning : SCSI command probably completed successfully"
1695 " before abortion. ", instance
->host_no
);
1699 #define MAX_WD33C93_HOSTS 4
1700 #define MAX_SETUP_ARGS ARRAY_SIZE(setup_args)
1701 #define SETUP_BUFFER_SIZE 200
1702 static char setup_buffer
[SETUP_BUFFER_SIZE
];
1703 static char setup_used
[MAX_SETUP_ARGS
];
1704 static int done_setup
= 0;
1707 wd33c93_setup(char *str
)
1712 /* The kernel does some processing of the command-line before calling
1713 * this function: If it begins with any decimal or hex number arguments,
1714 * ints[0] = how many numbers found and ints[1] through [n] are the values
1715 * themselves. str points to where the non-numeric arguments (if any)
1716 * start: We do our own parsing of those. We construct synthetic 'nosync'
1717 * keywords out of numeric args (to maintain compatibility with older
1718 * versions) and then add the rest of the arguments.
1724 strscpy(p1
, str
, SETUP_BUFFER_SIZE
);
1726 while (*p1
&& (i
< MAX_SETUP_ARGS
)) {
1727 p2
= strchr(p1
, ',');
1739 for (i
= 0; i
< MAX_SETUP_ARGS
; i
++)
1745 __setup("wd33c93=", wd33c93_setup
);
1747 /* check_setup_args() returns index if key found, 0 if not
1750 check_setup_args(char *key
, int *flags
, int *val
, char *buf
)
1755 for (x
= 0; x
< MAX_SETUP_ARGS
; x
++) {
1758 if (!strncmp(setup_args
[x
], key
, strlen(key
)))
1760 if (!strncmp(setup_args
[x
], "next", strlen("next")))
1763 if (x
== MAX_SETUP_ARGS
)
1766 cp
= setup_args
[x
] + strlen(key
);
1771 if ((*cp
>= '0') && (*cp
<= '9')) {
1772 *val
= simple_strtoul(cp
, NULL
, 0);
1778 * Calculate internal data-transfer-clock cycle from input-clock
1779 * frequency (/MHz) and fill 'sx_table'.
1781 * The original driver used to rely on a fixed sx_table, containing periods
1782 * for (only) the lower limits of the respective input-clock-frequency ranges
1783 * (8-10/12-15/16-20 MHz). Although it seems, that no problems occurred with
1784 * this setting so far, it might be desirable to adjust the transfer periods
1785 * closer to the really attached, possibly 25% higher, input-clock, since
1786 * - the wd33c93 may really use a significant shorter period, than it has
1787 * negotiated (eg. thrashing the target, which expects 4/8MHz, with 5/10MHz
1789 * - the wd33c93 may ask the target for a lower transfer rate, than the target
1790 * is capable of (eg. negotiating for an assumed minimum of 252ns instead of
1791 * possible 200ns, which indeed shows up in tests as an approx. 10% lower
1794 static inline unsigned int
1795 round_4(unsigned int x
)
1808 calc_sx_table(unsigned int mhz
, struct sx_period sx_table
[9])
1812 d
= 2; /* divisor for 8-10 MHz input-clock */
1814 d
= 3; /* divisor for 12-15 MHz input-clock */
1816 d
= 4; /* divisor for 16-20 MHz input-clock */
1818 d
= (100000 * d
) / 2 / mhz
; /* 100 x DTCC / nanosec */
1820 sx_table
[0].period_ns
= 1;
1821 sx_table
[0].reg_value
= 0x20;
1822 for (i
= 1; i
< 8; i
++) {
1823 sx_table
[i
].period_ns
= round_4((i
+1)*d
/ 100);
1824 sx_table
[i
].reg_value
= (i
+1)*0x10;
1826 sx_table
[7].reg_value
= 0;
1827 sx_table
[8].period_ns
= 0;
1828 sx_table
[8].reg_value
= 0;
1832 * check and, maybe, map an init- or "clock:"- argument.
1835 set_clk_freq(int freq
, int *mhz
)
1838 if (WD33C93_FS_8_10
== freq
)
1840 else if (WD33C93_FS_12_15
== freq
)
1842 else if (WD33C93_FS_16_20
== freq
)
1844 else if (freq
> 7 && freq
< 11)
1845 x
= WD33C93_FS_8_10
;
1846 else if (freq
> 11 && freq
< 16)
1847 x
= WD33C93_FS_12_15
;
1848 else if (freq
> 15 && freq
< 21)
1849 x
= WD33C93_FS_16_20
;
1851 /* Hmm, wouldn't it be safer to assume highest freq here? */
1852 x
= WD33C93_FS_8_10
;
1860 * to be used with the resync: fast: ... options
1862 static inline void set_resync ( struct WD33C93_hostdata
*hd
, int mask
)
1865 for (i
= 0; i
< 8; i
++)
1866 if (mask
& (1 << i
))
1867 hd
->sync_stat
[i
] = SS_UNSET
;
1871 wd33c93_init(struct Scsi_Host
*instance
, const wd33c93_regs regs
,
1872 dma_setup_t setup
, dma_stop_t stop
, int clock_freq
)
1874 struct WD33C93_hostdata
*hostdata
;
1880 if (!done_setup
&& setup_strings
)
1881 wd33c93_setup(setup_strings
);
1883 hostdata
= (struct WD33C93_hostdata
*) instance
->hostdata
;
1885 hostdata
->regs
= regs
;
1886 hostdata
->clock_freq
= set_clk_freq(clock_freq
, &i
);
1887 calc_sx_table(i
, hostdata
->sx_table
);
1888 hostdata
->dma_setup
= setup
;
1889 hostdata
->dma_stop
= stop
;
1890 hostdata
->dma_bounce_buffer
= NULL
;
1891 hostdata
->dma_bounce_len
= 0;
1892 for (i
= 0; i
< 8; i
++) {
1893 hostdata
->busy
[i
] = 0;
1894 hostdata
->sync_xfer
[i
] =
1895 calc_sync_xfer(DEFAULT_SX_PER
/ 4, DEFAULT_SX_OFF
,
1896 0, hostdata
->sx_table
);
1897 hostdata
->sync_stat
[i
] = SS_UNSET
; /* using default sync values */
1898 #ifdef PROC_STATISTICS
1899 hostdata
->cmd_cnt
[i
] = 0;
1900 hostdata
->disc_allowed_cnt
[i
] = 0;
1901 hostdata
->disc_done_cnt
[i
] = 0;
1904 hostdata
->input_Q
= NULL
;
1905 hostdata
->selecting
= NULL
;
1906 hostdata
->connected
= NULL
;
1907 hostdata
->disconnected_Q
= NULL
;
1908 hostdata
->state
= S_UNCONNECTED
;
1909 hostdata
->dma
= D_DMA_OFF
;
1910 hostdata
->level2
= L2_BASIC
;
1911 hostdata
->disconnect
= DIS_ADAPTIVE
;
1912 hostdata
->args
= DEBUG_DEFAULTS
;
1913 hostdata
->incoming_ptr
= 0;
1914 hostdata
->outgoing_len
= 0;
1915 hostdata
->default_sx_per
= DEFAULT_SX_PER
;
1916 hostdata
->no_dma
= 0; /* default is DMA enabled */
1918 #ifdef PROC_INTERFACE
1919 hostdata
->proc
= PR_VERSION
| PR_INFO
| PR_STATISTICS
|
1920 PR_CONNECTED
| PR_INPUTQ
| PR_DISCQ
| PR_STOP
;
1921 #ifdef PROC_STATISTICS
1922 hostdata
->dma_cnt
= 0;
1923 hostdata
->pio_cnt
= 0;
1924 hostdata
->int_cnt
= 0;
1928 if (check_setup_args("clock", &flags
, &val
, buf
)) {
1929 hostdata
->clock_freq
= set_clk_freq(val
, &val
);
1930 calc_sx_table(val
, hostdata
->sx_table
);
1933 if (check_setup_args("nosync", &flags
, &val
, buf
))
1934 hostdata
->no_sync
= val
;
1936 if (check_setup_args("nodma", &flags
, &val
, buf
))
1937 hostdata
->no_dma
= (val
== -1) ? 1 : val
;
1939 if (check_setup_args("period", &flags
, &val
, buf
))
1940 hostdata
->default_sx_per
=
1941 hostdata
->sx_table
[round_period((unsigned int) val
,
1942 hostdata
->sx_table
)].period_ns
;
1944 if (check_setup_args("disconnect", &flags
, &val
, buf
)) {
1945 if ((val
>= DIS_NEVER
) && (val
<= DIS_ALWAYS
))
1946 hostdata
->disconnect
= val
;
1948 hostdata
->disconnect
= DIS_ADAPTIVE
;
1951 if (check_setup_args("level2", &flags
, &val
, buf
))
1952 hostdata
->level2
= val
;
1954 if (check_setup_args("debug", &flags
, &val
, buf
))
1955 hostdata
->args
= val
& DB_MASK
;
1957 if (check_setup_args("burst", &flags
, &val
, buf
))
1958 hostdata
->dma_mode
= val
? CTRL_BURST
:CTRL_DMA
;
1960 if (WD33C93_FS_16_20
== hostdata
->clock_freq
/* divisor 4 */
1961 && check_setup_args("fast", &flags
, &val
, buf
))
1962 hostdata
->fast
= !!val
;
1964 if ((i
= check_setup_args("next", &flags
, &val
, buf
))) {
1966 setup_used
[--i
] = 1;
1968 #ifdef PROC_INTERFACE
1969 if (check_setup_args("proc", &flags
, &val
, buf
))
1970 hostdata
->proc
= val
;
1973 spin_lock_irq(&hostdata
->lock
);
1974 reset_wd33c93(instance
);
1975 spin_unlock_irq(&hostdata
->lock
);
1977 printk("wd33c93-%d: chip=%s/%d no_sync=0x%x no_dma=%d",
1979 (hostdata
->chip
== C_WD33C93
) ? "WD33c93" : (hostdata
->chip
==
1981 "WD33c93A" : (hostdata
->chip
==
1982 C_WD33C93B
) ? "WD33c93B" : "unknown",
1983 hostdata
->microcode
, hostdata
->no_sync
, hostdata
->no_dma
);
1985 printk(" debug_flags=0x%02x\n", hostdata
->args
);
1987 printk(" debugging=OFF\n");
1989 printk(" setup_args=");
1990 for (i
= 0; i
< MAX_SETUP_ARGS
; i
++)
1991 printk("%s,", setup_args
[i
]);
1993 printk(" Version %s - %s\n", WD33C93_VERSION
, WD33C93_DATE
);
1996 int wd33c93_write_info(struct Scsi_Host
*instance
, char *buf
, int len
)
1998 #ifdef PROC_INTERFACE
2000 struct WD33C93_hostdata
*hd
;
2003 hd
= (struct WD33C93_hostdata
*) instance
->hostdata
;
2005 /* We accept the following
2006 * keywords (same format as command-line, but arguments are not optional):
2020 for (bp
= buf
; *bp
; ) {
2021 while (',' == *bp
|| ' ' == *bp
)
2023 if (!strncmp(bp
, "debug:", 6)) {
2024 hd
->args
= simple_strtoul(bp
+6, &bp
, 0) & DB_MASK
;
2025 } else if (!strncmp(bp
, "disconnect:", 11)) {
2026 x
= simple_strtoul(bp
+11, &bp
, 0);
2027 if (x
< DIS_NEVER
|| x
> DIS_ALWAYS
)
2030 } else if (!strncmp(bp
, "period:", 7)) {
2031 x
= simple_strtoul(bp
+7, &bp
, 0);
2032 hd
->default_sx_per
=
2033 hd
->sx_table
[round_period((unsigned int) x
,
2034 hd
->sx_table
)].period_ns
;
2035 } else if (!strncmp(bp
, "resync:", 7)) {
2036 set_resync(hd
, (int)simple_strtoul(bp
+7, &bp
, 0));
2037 } else if (!strncmp(bp
, "proc:", 5)) {
2038 hd
->proc
= simple_strtoul(bp
+5, &bp
, 0);
2039 } else if (!strncmp(bp
, "nodma:", 6)) {
2040 hd
->no_dma
= simple_strtoul(bp
+6, &bp
, 0);
2041 } else if (!strncmp(bp
, "level2:", 7)) {
2042 hd
->level2
= simple_strtoul(bp
+7, &bp
, 0);
2043 } else if (!strncmp(bp
, "burst:", 6)) {
2045 simple_strtol(bp
+6, &bp
, 0) ? CTRL_BURST
:CTRL_DMA
;
2046 } else if (!strncmp(bp
, "fast:", 5)) {
2047 x
= !!simple_strtol(bp
+5, &bp
, 0);
2049 set_resync(hd
, 0xff);
2051 } else if (!strncmp(bp
, "nosync:", 7)) {
2052 x
= simple_strtoul(bp
+7, &bp
, 0);
2053 set_resync(hd
, x
^ hd
->no_sync
);
2056 break; /* unknown keyword,syntax-error,... */
2066 wd33c93_show_info(struct seq_file
*m
, struct Scsi_Host
*instance
)
2068 #ifdef PROC_INTERFACE
2069 struct WD33C93_hostdata
*hd
;
2070 struct scsi_cmnd
*cmd
;
2073 hd
= (struct WD33C93_hostdata
*) instance
->hostdata
;
2075 spin_lock_irq(&hd
->lock
);
2076 if (hd
->proc
& PR_VERSION
)
2077 seq_printf(m
, "\nVersion %s - %s.",
2078 WD33C93_VERSION
, WD33C93_DATE
);
2080 if (hd
->proc
& PR_INFO
) {
2081 seq_printf(m
, "\nclock_freq=%02x no_sync=%02x no_dma=%d"
2082 " dma_mode=%02x fast=%d",
2083 hd
->clock_freq
, hd
->no_sync
, hd
->no_dma
, hd
->dma_mode
, hd
->fast
);
2084 seq_puts(m
, "\nsync_xfer[] = ");
2085 for (x
= 0; x
< 7; x
++)
2086 seq_printf(m
, "\t%02x", hd
->sync_xfer
[x
]);
2087 seq_puts(m
, "\nsync_stat[] = ");
2088 for (x
= 0; x
< 7; x
++)
2089 seq_printf(m
, "\t%02x", hd
->sync_stat
[x
]);
2091 #ifdef PROC_STATISTICS
2092 if (hd
->proc
& PR_STATISTICS
) {
2093 seq_puts(m
, "\ncommands issued: ");
2094 for (x
= 0; x
< 7; x
++)
2095 seq_printf(m
, "\t%ld", hd
->cmd_cnt
[x
]);
2096 seq_puts(m
, "\ndisconnects allowed:");
2097 for (x
= 0; x
< 7; x
++)
2098 seq_printf(m
, "\t%ld", hd
->disc_allowed_cnt
[x
]);
2099 seq_puts(m
, "\ndisconnects done: ");
2100 for (x
= 0; x
< 7; x
++)
2101 seq_printf(m
, "\t%ld", hd
->disc_done_cnt
[x
]);
2103 "\ninterrupts: %ld, DATA_PHASE ints: %ld DMA, %ld PIO",
2104 hd
->int_cnt
, hd
->dma_cnt
, hd
->pio_cnt
);
2107 if (hd
->proc
& PR_CONNECTED
) {
2108 seq_puts(m
, "\nconnected: ");
2109 if (hd
->connected
) {
2110 cmd
= (struct scsi_cmnd
*) hd
->connected
;
2111 seq_printf(m
, " %d:%llu(%02x)",
2112 cmd
->device
->id
, cmd
->device
->lun
, cmd
->cmnd
[0]);
2115 if (hd
->proc
& PR_INPUTQ
) {
2116 seq_puts(m
, "\ninput_Q: ");
2117 cmd
= (struct scsi_cmnd
*) hd
->input_Q
;
2119 seq_printf(m
, " %d:%llu(%02x)",
2120 cmd
->device
->id
, cmd
->device
->lun
, cmd
->cmnd
[0]);
2121 cmd
= (struct scsi_cmnd
*) cmd
->host_scribble
;
2124 if (hd
->proc
& PR_DISCQ
) {
2125 seq_puts(m
, "\ndisconnected_Q:");
2126 cmd
= (struct scsi_cmnd
*) hd
->disconnected_Q
;
2128 seq_printf(m
, " %d:%llu(%02x)",
2129 cmd
->device
->id
, cmd
->device
->lun
, cmd
->cmnd
[0]);
2130 cmd
= (struct scsi_cmnd
*) cmd
->host_scribble
;
2134 spin_unlock_irq(&hd
->lock
);
2135 #endif /* PROC_INTERFACE */
2139 EXPORT_SYMBOL(wd33c93_host_reset
);
2140 EXPORT_SYMBOL(wd33c93_init
);
2141 EXPORT_SYMBOL(wd33c93_abort
);
2142 EXPORT_SYMBOL(wd33c93_queuecommand
);
2143 EXPORT_SYMBOL(wd33c93_intr
);
2144 EXPORT_SYMBOL(wd33c93_show_info
);
2145 EXPORT_SYMBOL(wd33c93_write_info
);