]>
git.proxmox.com Git - mirror_ubuntu-jammy-kernel.git/blob - drivers/scsi/wd33c93.c
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
);
165 #ifdef CONFIG_WD33C93_PIO
167 read_wd33c93(const wd33c93_regs regs
, uchar reg_num
)
171 outb(reg_num
, regs
.SASR
);
172 data
= inb(regs
.SCMD
);
176 static inline unsigned long
177 read_wd33c93_count(const wd33c93_regs regs
)
181 outb(WD_TRANSFER_COUNT_MSB
, regs
.SASR
);
182 value
= inb(regs
.SCMD
) << 16;
183 value
|= inb(regs
.SCMD
) << 8;
184 value
|= inb(regs
.SCMD
);
189 read_aux_stat(const wd33c93_regs regs
)
191 return inb(regs
.SASR
);
195 write_wd33c93(const wd33c93_regs regs
, uchar reg_num
, uchar value
)
197 outb(reg_num
, regs
.SASR
);
198 outb(value
, regs
.SCMD
);
202 write_wd33c93_count(const wd33c93_regs regs
, unsigned long value
)
204 outb(WD_TRANSFER_COUNT_MSB
, regs
.SASR
);
205 outb((value
>> 16) & 0xff, regs
.SCMD
);
206 outb((value
>> 8) & 0xff, regs
.SCMD
);
207 outb( value
& 0xff, regs
.SCMD
);
210 #define write_wd33c93_cmd(regs, cmd) \
211 write_wd33c93((regs), WD_COMMAND, (cmd))
214 write_wd33c93_cdb(const wd33c93_regs regs
, uint len
, uchar cmnd
[])
218 outb(WD_CDB_1
, regs
.SASR
);
219 for (i
=0; i
<len
; i
++)
220 outb(cmnd
[i
], regs
.SCMD
);
223 #else /* CONFIG_WD33C93_PIO */
225 read_wd33c93(const wd33c93_regs regs
, uchar reg_num
)
227 *regs
.SASR
= reg_num
;
233 read_wd33c93_count(const wd33c93_regs regs
)
237 *regs
.SASR
= WD_TRANSFER_COUNT_MSB
;
239 value
= *regs
.SCMD
<< 16;
240 value
|= *regs
.SCMD
<< 8;
247 read_aux_stat(const wd33c93_regs regs
)
253 write_wd33c93(const wd33c93_regs regs
, uchar reg_num
, uchar value
)
255 *regs
.SASR
= reg_num
;
262 write_wd33c93_count(const wd33c93_regs regs
, unsigned long value
)
264 *regs
.SASR
= WD_TRANSFER_COUNT_MSB
;
266 *regs
.SCMD
= value
>> 16;
267 *regs
.SCMD
= value
>> 8;
273 write_wd33c93_cmd(const wd33c93_regs regs
, uchar cmd
)
275 *regs
.SASR
= WD_COMMAND
;
282 write_wd33c93_cdb(const wd33c93_regs regs
, uint len
, uchar cmnd
[])
286 *regs
.SASR
= WD_CDB_1
;
287 for (i
= 0; i
< len
; i
++)
288 *regs
.SCMD
= cmnd
[i
];
290 #endif /* CONFIG_WD33C93_PIO */
293 read_1_byte(const wd33c93_regs regs
)
298 write_wd33c93(regs
, WD_CONTROL
, CTRL_IDI
| CTRL_EDI
| CTRL_POLLED
);
299 write_wd33c93_cmd(regs
, WD_CMD_TRANS_INFO
| 0x80);
301 asr
= read_aux_stat(regs
);
303 x
= read_wd33c93(regs
, WD_DATA
);
304 } while (!(asr
& ASR_INT
));
309 round_period(unsigned int period
, const struct sx_period
*sx_table
)
313 for (x
= 1; sx_table
[x
].period_ns
; x
++) {
314 if ((period
<= sx_table
[x
- 0].period_ns
) &&
315 (period
> sx_table
[x
- 1].period_ns
)) {
323 * Calculate Synchronous Transfer Register value from SDTR code.
326 calc_sync_xfer(unsigned int period
, unsigned int offset
, unsigned int fast
,
327 const struct sx_period
*sx_table
)
329 /* When doing Fast SCSI synchronous data transfers, the corresponding
330 * value in 'sx_table' is two times the actually used transfer period.
334 if (offset
&& fast
) {
340 period
*= 4; /* convert SDTR code to ns */
341 result
= sx_table
[round_period(period
,sx_table
)].reg_value
;
342 result
|= (offset
< OPTIMUM_SX_OFF
) ? offset
: OPTIMUM_SX_OFF
;
348 * Calculate SDTR code bytes [3],[4] from period and offset.
351 calc_sync_msg(unsigned int period
, unsigned int offset
, unsigned int fast
,
354 /* 'period' is a "normal"-mode value, like the ones in 'sx_table'. The
355 * actually used transfer period for Fast SCSI synchronous data
356 * transfers is half that value.
366 wd33c93_queuecommand_lck(struct scsi_cmnd
*cmd
,
367 void (*done
)(struct scsi_cmnd
*))
369 struct WD33C93_hostdata
*hostdata
;
370 struct scsi_cmnd
*tmp
;
372 hostdata
= (struct WD33C93_hostdata
*) cmd
->device
->host
->hostdata
;
375 printk("Q-%d-%02x( ", cmd
->device
->id
, cmd
->cmnd
[0]))
377 /* Set up a few fields in the scsi_cmnd structure for our own use:
378 * - host_scribble is the pointer to the next cmd in the input queue
379 * - scsi_done points to the routine we call when a cmd is finished
380 * - result is what you'd expect
382 cmd
->host_scribble
= NULL
;
383 cmd
->scsi_done
= done
;
386 /* We use the Scsi_Pointer structure that's included with each command
387 * as a scratchpad (as it's intended to be used!). The handy thing about
388 * the SCp.xxx fields is that they're always associated with a given
389 * cmd, and are preserved across disconnect-reselect. This means we
390 * can pretty much ignore SAVE_POINTERS and RESTORE_POINTERS messages
391 * if we keep all the critical pointers and counters in SCp:
392 * - SCp.ptr is the pointer into the RAM buffer
393 * - SCp.this_residual is the size of that buffer
394 * - SCp.buffer points to the current scatter-gather buffer
395 * - SCp.buffers_residual tells us how many S.G. buffers there are
396 * - SCp.have_data_in is not used
397 * - SCp.sent_command is not used
398 * - SCp.phase records this command's SRCID_ER bit setting
401 if (scsi_bufflen(cmd
)) {
402 cmd
->SCp
.buffer
= scsi_sglist(cmd
);
403 cmd
->SCp
.buffers_residual
= scsi_sg_count(cmd
) - 1;
404 cmd
->SCp
.ptr
= sg_virt(cmd
->SCp
.buffer
);
405 cmd
->SCp
.this_residual
= cmd
->SCp
.buffer
->length
;
407 cmd
->SCp
.buffer
= NULL
;
408 cmd
->SCp
.buffers_residual
= 0;
410 cmd
->SCp
.this_residual
= 0;
413 /* WD docs state that at the conclusion of a "LEVEL2" command, the
414 * status byte can be retrieved from the LUN register. Apparently,
415 * this is the case only for *uninterrupted* LEVEL2 commands! If
416 * there are any unexpected phases entered, even if they are 100%
417 * legal (different devices may choose to do things differently),
418 * the LEVEL2 command sequence is exited. This often occurs prior
419 * to receiving the status byte, in which case the driver does a
420 * status phase interrupt and gets the status byte on its own.
421 * While such a command can then be "resumed" (ie restarted to
422 * finish up as a LEVEL2 command), the LUN register will NOT be
423 * a valid status byte at the command's conclusion, and we must
424 * use the byte obtained during the earlier interrupt. Here, we
425 * preset SCp.Status to an illegal value (0xff) so that when
426 * this command finally completes, we can tell where the actual
427 * status byte is stored.
430 cmd
->SCp
.Status
= ILLEGAL_STATUS_BYTE
;
433 * Add the cmd to the end of 'input_Q'. Note that REQUEST SENSE
434 * commands are added to the head of the queue so that the desired
435 * sense data is not lost before REQUEST_SENSE executes.
438 spin_lock_irq(&hostdata
->lock
);
440 if (!(hostdata
->input_Q
) || (cmd
->cmnd
[0] == REQUEST_SENSE
)) {
441 cmd
->host_scribble
= (uchar
*) hostdata
->input_Q
;
442 hostdata
->input_Q
= cmd
;
443 } else { /* find the end of the queue */
444 for (tmp
= (struct scsi_cmnd
*) hostdata
->input_Q
;
446 tmp
= (struct scsi_cmnd
*) tmp
->host_scribble
) ;
447 tmp
->host_scribble
= (uchar
*) cmd
;
450 /* We know that there's at least one command in 'input_Q' now.
451 * Go see if any of them are runnable!
454 wd33c93_execute(cmd
->device
->host
);
456 DB(DB_QUEUE_COMMAND
, printk(")Q "))
458 spin_unlock_irq(&hostdata
->lock
);
462 DEF_SCSI_QCMD(wd33c93_queuecommand
)
465 * This routine attempts to start a scsi command. If the host_card is
466 * already connected, we give up immediately. Otherwise, look through
467 * the input_Q, using the first command we find that's intended
468 * for a currently non-busy target/lun.
470 * wd33c93_execute() is always called with interrupts disabled or from
471 * the wd33c93_intr itself, which means that a wd33c93 interrupt
472 * cannot occur while we are in here.
475 wd33c93_execute(struct Scsi_Host
*instance
)
477 struct WD33C93_hostdata
*hostdata
=
478 (struct WD33C93_hostdata
*) instance
->hostdata
;
479 const wd33c93_regs regs
= hostdata
->regs
;
480 struct scsi_cmnd
*cmd
, *prev
;
482 DB(DB_EXECUTE
, printk("EX("))
483 if (hostdata
->selecting
|| hostdata
->connected
) {
484 DB(DB_EXECUTE
, printk(")EX-0 "))
489 * Search through the input_Q for a command destined
490 * for an idle target/lun.
493 cmd
= (struct scsi_cmnd
*) hostdata
->input_Q
;
496 if (!(hostdata
->busy
[cmd
->device
->id
] &
497 (1 << (cmd
->device
->lun
& 0xff))))
500 cmd
= (struct scsi_cmnd
*) cmd
->host_scribble
;
503 /* quit if queue empty or all possible targets are busy */
506 DB(DB_EXECUTE
, printk(")EX-1 "))
510 /* remove command from queue */
513 prev
->host_scribble
= cmd
->host_scribble
;
515 hostdata
->input_Q
= (struct scsi_cmnd
*) cmd
->host_scribble
;
517 #ifdef PROC_STATISTICS
518 hostdata
->cmd_cnt
[cmd
->device
->id
]++;
522 * Start the selection process
525 if (cmd
->sc_data_direction
== DMA_TO_DEVICE
)
526 write_wd33c93(regs
, WD_DESTINATION_ID
, cmd
->device
->id
);
528 write_wd33c93(regs
, WD_DESTINATION_ID
, cmd
->device
->id
| DSTID_DPD
);
530 /* Now we need to figure out whether or not this command is a good
531 * candidate for disconnect/reselect. We guess to the best of our
532 * ability, based on a set of hierarchical rules. When several
533 * devices are operating simultaneously, disconnects are usually
534 * an advantage. In a single device system, or if only 1 device
535 * is being accessed, transfers usually go faster if disconnects
538 * + Commands should NEVER disconnect if hostdata->disconnect =
539 * DIS_NEVER (this holds for tape drives also), and ALWAYS
540 * disconnect if hostdata->disconnect = DIS_ALWAYS.
541 * + Tape drive commands should always be allowed to disconnect.
542 * + Disconnect should be allowed if disconnected_Q isn't empty.
543 * + Commands should NOT disconnect if input_Q is empty.
544 * + Disconnect should be allowed if there are commands in input_Q
545 * for a different target/lun. In this case, the other commands
546 * should be made disconnect-able, if not already.
548 * I know, I know - this code would flunk me out of any
549 * "C Programming 101" class ever offered. But it's easy
550 * to change around and experiment with for now.
553 cmd
->SCp
.phase
= 0; /* assume no disconnect */
554 if (hostdata
->disconnect
== DIS_NEVER
)
556 if (hostdata
->disconnect
== DIS_ALWAYS
)
558 if (cmd
->device
->type
== 1) /* tape drive? */
560 if (hostdata
->disconnected_Q
) /* other commands disconnected? */
562 if (!(hostdata
->input_Q
)) /* input_Q empty? */
564 for (prev
= (struct scsi_cmnd
*) hostdata
->input_Q
; prev
;
565 prev
= (struct scsi_cmnd
*) prev
->host_scribble
) {
566 if ((prev
->device
->id
!= cmd
->device
->id
) ||
567 (prev
->device
->lun
!= cmd
->device
->lun
)) {
568 for (prev
= (struct scsi_cmnd
*) hostdata
->input_Q
; prev
;
569 prev
= (struct scsi_cmnd
*) prev
->host_scribble
)
580 #ifdef PROC_STATISTICS
581 hostdata
->disc_allowed_cnt
[cmd
->device
->id
]++;
586 write_wd33c93(regs
, WD_SOURCE_ID
, ((cmd
->SCp
.phase
) ? SRCID_ER
: 0));
588 write_wd33c93(regs
, WD_TARGET_LUN
, (u8
)cmd
->device
->lun
);
589 write_wd33c93(regs
, WD_SYNCHRONOUS_TRANSFER
,
590 hostdata
->sync_xfer
[cmd
->device
->id
]);
591 hostdata
->busy
[cmd
->device
->id
] |= (1 << (cmd
->device
->lun
& 0xFF));
593 if ((hostdata
->level2
== L2_NONE
) ||
594 (hostdata
->sync_stat
[cmd
->device
->id
] == SS_UNSET
)) {
597 * Do a 'Select-With-ATN' command. This will end with
598 * one of the following interrupts:
599 * CSR_RESEL_AM: failure - can try again later.
600 * CSR_TIMEOUT: failure - give up.
601 * CSR_SELECT: success - proceed.
604 hostdata
->selecting
= cmd
;
606 /* Every target has its own synchronous transfer setting, kept in the
607 * sync_xfer array, and a corresponding status byte in sync_stat[].
608 * Each target's sync_stat[] entry is initialized to SX_UNSET, and its
609 * sync_xfer[] entry is initialized to the default/safe value. SS_UNSET
610 * means that the parameters are undetermined as yet, and that we
611 * need to send an SDTR message to this device after selection is
612 * complete: We set SS_FIRST to tell the interrupt routine to do so.
613 * If we've been asked not to try synchronous transfers on this
614 * target (and _all_ luns within it), we'll still send the SDTR message
615 * later, but at that time we'll negotiate for async by specifying a
616 * sync fifo depth of 0.
618 if (hostdata
->sync_stat
[cmd
->device
->id
] == SS_UNSET
)
619 hostdata
->sync_stat
[cmd
->device
->id
] = SS_FIRST
;
620 hostdata
->state
= S_SELECTING
;
621 write_wd33c93_count(regs
, 0); /* guarantee a DATA_PHASE interrupt */
622 write_wd33c93_cmd(regs
, WD_CMD_SEL_ATN
);
626 * Do a 'Select-With-ATN-Xfer' command. This will end with
627 * one of the following interrupts:
628 * CSR_RESEL_AM: failure - can try again later.
629 * CSR_TIMEOUT: failure - give up.
630 * anything else: success - proceed.
633 hostdata
->connected
= cmd
;
634 write_wd33c93(regs
, WD_COMMAND_PHASE
, 0);
636 /* copy command_descriptor_block into WD chip
637 * (take advantage of auto-incrementing)
640 write_wd33c93_cdb(regs
, cmd
->cmd_len
, cmd
->cmnd
);
642 /* The wd33c93 only knows about Group 0, 1, and 5 commands when
643 * it's doing a 'select-and-transfer'. To be safe, we write the
644 * size of the CDB into the OWN_ID register for every case. This
645 * way there won't be problems with vendor-unique, audio, etc.
648 write_wd33c93(regs
, WD_OWN_ID
, cmd
->cmd_len
);
650 /* When doing a non-disconnect command with DMA, we can save
651 * ourselves a DATA phase interrupt later by setting everything
655 if ((cmd
->SCp
.phase
== 0) && (hostdata
->no_dma
== 0)) {
656 if (hostdata
->dma_setup(cmd
,
657 (cmd
->sc_data_direction
== DMA_TO_DEVICE
) ?
658 DATA_OUT_DIR
: DATA_IN_DIR
))
659 write_wd33c93_count(regs
, 0); /* guarantee a DATA_PHASE interrupt */
661 write_wd33c93_count(regs
,
662 cmd
->SCp
.this_residual
);
663 write_wd33c93(regs
, WD_CONTROL
,
664 CTRL_IDI
| CTRL_EDI
| hostdata
->dma_mode
);
665 hostdata
->dma
= D_DMA_RUNNING
;
668 write_wd33c93_count(regs
, 0); /* guarantee a DATA_PHASE interrupt */
670 hostdata
->state
= S_RUNNING_LEVEL2
;
671 write_wd33c93_cmd(regs
, WD_CMD_SEL_ATN_XFER
);
675 * Since the SCSI bus can handle only 1 connection at a time,
676 * we get out of here now. If the selection fails, or when
677 * the command disconnects, we'll come back to this routine
678 * to search the input_Q again...
682 printk("%s)EX-2 ", (cmd
->SCp
.phase
) ? "d:" : ""))
686 transfer_pio(const wd33c93_regs regs
, uchar
* buf
, int cnt
,
687 int data_in_dir
, struct WD33C93_hostdata
*hostdata
)
692 printk("(%p,%d,%s:", buf
, cnt
, data_in_dir
? "in" : "out"))
694 write_wd33c93(regs
, WD_CONTROL
, CTRL_IDI
| CTRL_EDI
| CTRL_POLLED
);
695 write_wd33c93_count(regs
, cnt
);
696 write_wd33c93_cmd(regs
, WD_CMD_TRANS_INFO
);
699 asr
= read_aux_stat(regs
);
701 *buf
++ = read_wd33c93(regs
, WD_DATA
);
702 } while (!(asr
& ASR_INT
));
705 asr
= read_aux_stat(regs
);
707 write_wd33c93(regs
, WD_DATA
, *buf
++);
708 } while (!(asr
& ASR_INT
));
711 /* Note: we are returning with the interrupt UN-cleared.
712 * Since (presumably) an entire I/O operation has
713 * completed, the bus phase is probably different, and
714 * the interrupt routine will discover this when it
715 * responds to the uncleared int.
721 transfer_bytes(const wd33c93_regs regs
, struct scsi_cmnd
*cmd
,
724 struct WD33C93_hostdata
*hostdata
;
725 unsigned long length
;
727 hostdata
= (struct WD33C93_hostdata
*) cmd
->device
->host
->hostdata
;
729 /* Normally, you'd expect 'this_residual' to be non-zero here.
730 * In a series of scatter-gather transfers, however, this
731 * routine will usually be called with 'this_residual' equal
732 * to 0 and 'buffers_residual' non-zero. This means that a
733 * previous transfer completed, clearing 'this_residual', and
734 * now we need to setup the next scatter-gather buffer as the
735 * source or destination for THIS transfer.
737 if (!cmd
->SCp
.this_residual
&& cmd
->SCp
.buffers_residual
) {
738 cmd
->SCp
.buffer
= sg_next(cmd
->SCp
.buffer
);
739 --cmd
->SCp
.buffers_residual
;
740 cmd
->SCp
.this_residual
= cmd
->SCp
.buffer
->length
;
741 cmd
->SCp
.ptr
= sg_virt(cmd
->SCp
.buffer
);
743 if (!cmd
->SCp
.this_residual
) /* avoid bogus setups */
746 write_wd33c93(regs
, WD_SYNCHRONOUS_TRANSFER
,
747 hostdata
->sync_xfer
[cmd
->device
->id
]);
749 /* 'hostdata->no_dma' is TRUE if we don't even want to try DMA.
750 * Update 'this_residual' and 'ptr' after 'transfer_pio()' returns.
753 if (hostdata
->no_dma
|| hostdata
->dma_setup(cmd
, data_in_dir
)) {
754 #ifdef PROC_STATISTICS
757 transfer_pio(regs
, (uchar
*) cmd
->SCp
.ptr
,
758 cmd
->SCp
.this_residual
, data_in_dir
, hostdata
);
759 length
= cmd
->SCp
.this_residual
;
760 cmd
->SCp
.this_residual
= read_wd33c93_count(regs
);
761 cmd
->SCp
.ptr
+= (length
- cmd
->SCp
.this_residual
);
764 /* We are able to do DMA (in fact, the Amiga hardware is
765 * already going!), so start up the wd33c93 in DMA mode.
766 * We set 'hostdata->dma' = D_DMA_RUNNING so that when the
767 * transfer completes and causes an interrupt, we're
768 * reminded to tell the Amiga to shut down its end. We'll
769 * postpone the updating of 'this_residual' and 'ptr'
774 #ifdef PROC_STATISTICS
777 write_wd33c93(regs
, WD_CONTROL
, CTRL_IDI
| CTRL_EDI
| hostdata
->dma_mode
);
778 write_wd33c93_count(regs
, cmd
->SCp
.this_residual
);
780 if ((hostdata
->level2
>= L2_DATA
) ||
781 (hostdata
->level2
== L2_BASIC
&& cmd
->SCp
.phase
== 0)) {
782 write_wd33c93(regs
, WD_COMMAND_PHASE
, 0x45);
783 write_wd33c93_cmd(regs
, WD_CMD_SEL_ATN_XFER
);
784 hostdata
->state
= S_RUNNING_LEVEL2
;
786 write_wd33c93_cmd(regs
, WD_CMD_TRANS_INFO
);
788 hostdata
->dma
= D_DMA_RUNNING
;
793 wd33c93_intr(struct Scsi_Host
*instance
)
795 struct WD33C93_hostdata
*hostdata
=
796 (struct WD33C93_hostdata
*) instance
->hostdata
;
797 const wd33c93_regs regs
= hostdata
->regs
;
798 struct scsi_cmnd
*patch
, *cmd
;
799 uchar asr
, sr
, phs
, id
, lun
, *ucp
, msg
;
800 unsigned long length
, flags
;
802 asr
= read_aux_stat(regs
);
803 if (!(asr
& ASR_INT
) || (asr
& ASR_BSY
))
806 spin_lock_irqsave(&hostdata
->lock
, flags
);
808 #ifdef PROC_STATISTICS
812 cmd
= (struct scsi_cmnd
*) hostdata
->connected
; /* assume we're connected */
813 sr
= read_wd33c93(regs
, WD_SCSI_STATUS
); /* clear the interrupt */
814 phs
= read_wd33c93(regs
, WD_COMMAND_PHASE
);
816 DB(DB_INTR
, printk("{%02x:%02x-", asr
, sr
))
818 /* After starting a DMA transfer, the next interrupt
819 * is guaranteed to be in response to completion of
820 * the transfer. Since the Amiga DMA hardware runs in
821 * in an open-ended fashion, it needs to be told when
822 * to stop; do that here if D_DMA_RUNNING is true.
823 * Also, we have to update 'this_residual' and 'ptr'
824 * based on the contents of the TRANSFER_COUNT register,
825 * in case the device decided to do an intermediate
826 * disconnect (a device may do this if it has to do a
827 * seek, or just to be nice and let other devices have
828 * some bus time during long transfers). After doing
829 * whatever is needed, we go on and service the WD3393
830 * interrupt normally.
832 if (hostdata
->dma
== D_DMA_RUNNING
) {
834 printk("[%p/%d:", cmd
->SCp
.ptr
, cmd
->SCp
.this_residual
))
835 hostdata
->dma_stop(cmd
->device
->host
, cmd
, 1);
836 hostdata
->dma
= D_DMA_OFF
;
837 length
= cmd
->SCp
.this_residual
;
838 cmd
->SCp
.this_residual
= read_wd33c93_count(regs
);
839 cmd
->SCp
.ptr
+= (length
- cmd
->SCp
.this_residual
);
841 printk("%p/%d]", cmd
->SCp
.ptr
, cmd
->SCp
.this_residual
))
844 /* Respond to the specific WD3393 interrupt - there are quite a few! */
847 DB(DB_INTR
, printk("TIMEOUT"))
849 if (hostdata
->state
== S_RUNNING_LEVEL2
)
850 hostdata
->connected
= NULL
;
852 cmd
= (struct scsi_cmnd
*) hostdata
->selecting
; /* get a valid cmd */
853 hostdata
->selecting
= NULL
;
856 cmd
->result
= DID_NO_CONNECT
<< 16;
857 hostdata
->busy
[cmd
->device
->id
] &= ~(1 << (cmd
->device
->lun
& 0xff));
858 hostdata
->state
= S_UNCONNECTED
;
862 * There is a window of time within the scsi_done() path
863 * of execution where interrupts are turned back on full
864 * blast and left that way. During that time we could
865 * reconnect to a disconnected command, then we'd bomb
866 * out below. We could also end up executing two commands
867 * at _once_. ...just so you know why the restore_flags()
871 spin_unlock_irqrestore(&hostdata
->lock
, flags
);
873 /* We are not connected to a target - check to see if there
874 * are commands waiting to be executed.
877 wd33c93_execute(instance
);
880 /* Note: this interrupt should not occur in a LEVEL2 command */
883 DB(DB_INTR
, printk("SELECT"))
884 hostdata
->connected
= cmd
=
885 (struct scsi_cmnd
*) hostdata
->selecting
;
886 hostdata
->selecting
= NULL
;
888 /* construct an IDENTIFY message with correct disconnect bit */
890 hostdata
->outgoing_msg
[0] = IDENTIFY(0, cmd
->device
->lun
);
892 hostdata
->outgoing_msg
[0] |= 0x40;
894 if (hostdata
->sync_stat
[cmd
->device
->id
] == SS_FIRST
) {
896 hostdata
->sync_stat
[cmd
->device
->id
] = SS_WAITING
;
898 /* Tack on a 2nd message to ask about synchronous transfers. If we've
899 * been asked to do only asynchronous transfers on this device, we
900 * request a fifo depth of 0, which is equivalent to async - should
901 * solve the problems some people have had with GVP's Guru ROM.
904 hostdata
->outgoing_msg
[1] = EXTENDED_MESSAGE
;
905 hostdata
->outgoing_msg
[2] = 3;
906 hostdata
->outgoing_msg
[3] = EXTENDED_SDTR
;
907 if (hostdata
->no_sync
& (1 << cmd
->device
->id
)) {
908 calc_sync_msg(hostdata
->default_sx_per
, 0,
909 0, hostdata
->outgoing_msg
+ 4);
911 calc_sync_msg(optimum_sx_per(hostdata
),
914 hostdata
->outgoing_msg
+ 4);
916 hostdata
->outgoing_len
= 6;
918 ucp
= hostdata
->outgoing_msg
+ 1;
919 printk(" sending SDTR %02x03%02x%02x%02x ",
920 ucp
[0], ucp
[2], ucp
[3], ucp
[4]);
923 hostdata
->outgoing_len
= 1;
925 hostdata
->state
= S_CONNECTED
;
926 spin_unlock_irqrestore(&hostdata
->lock
, flags
);
929 case CSR_XFER_DONE
| PHS_DATA_IN
:
930 case CSR_UNEXP
| PHS_DATA_IN
:
931 case CSR_SRV_REQ
| PHS_DATA_IN
:
933 printk("IN-%d.%d", cmd
->SCp
.this_residual
,
934 cmd
->SCp
.buffers_residual
))
935 transfer_bytes(regs
, cmd
, DATA_IN_DIR
);
936 if (hostdata
->state
!= S_RUNNING_LEVEL2
)
937 hostdata
->state
= S_CONNECTED
;
938 spin_unlock_irqrestore(&hostdata
->lock
, flags
);
941 case CSR_XFER_DONE
| PHS_DATA_OUT
:
942 case CSR_UNEXP
| PHS_DATA_OUT
:
943 case CSR_SRV_REQ
| PHS_DATA_OUT
:
945 printk("OUT-%d.%d", cmd
->SCp
.this_residual
,
946 cmd
->SCp
.buffers_residual
))
947 transfer_bytes(regs
, cmd
, DATA_OUT_DIR
);
948 if (hostdata
->state
!= S_RUNNING_LEVEL2
)
949 hostdata
->state
= S_CONNECTED
;
950 spin_unlock_irqrestore(&hostdata
->lock
, flags
);
953 /* Note: this interrupt should not occur in a LEVEL2 command */
955 case CSR_XFER_DONE
| PHS_COMMAND
:
956 case CSR_UNEXP
| PHS_COMMAND
:
957 case CSR_SRV_REQ
| PHS_COMMAND
:
958 DB(DB_INTR
, printk("CMND-%02x", cmd
->cmnd
[0]))
959 transfer_pio(regs
, cmd
->cmnd
, cmd
->cmd_len
, DATA_OUT_DIR
,
961 hostdata
->state
= S_CONNECTED
;
962 spin_unlock_irqrestore(&hostdata
->lock
, flags
);
965 case CSR_XFER_DONE
| PHS_STATUS
:
966 case CSR_UNEXP
| PHS_STATUS
:
967 case CSR_SRV_REQ
| PHS_STATUS
:
968 DB(DB_INTR
, printk("STATUS="))
969 cmd
->SCp
.Status
= read_1_byte(regs
);
970 DB(DB_INTR
, printk("%02x", cmd
->SCp
.Status
))
971 if (hostdata
->level2
>= L2_BASIC
) {
972 sr
= read_wd33c93(regs
, WD_SCSI_STATUS
); /* clear interrupt */
974 hostdata
->state
= S_RUNNING_LEVEL2
;
975 write_wd33c93(regs
, WD_COMMAND_PHASE
, 0x50);
976 write_wd33c93_cmd(regs
, WD_CMD_SEL_ATN_XFER
);
978 hostdata
->state
= S_CONNECTED
;
980 spin_unlock_irqrestore(&hostdata
->lock
, flags
);
983 case CSR_XFER_DONE
| PHS_MESS_IN
:
984 case CSR_UNEXP
| PHS_MESS_IN
:
985 case CSR_SRV_REQ
| PHS_MESS_IN
:
986 DB(DB_INTR
, printk("MSG_IN="))
988 msg
= read_1_byte(regs
);
989 sr
= read_wd33c93(regs
, WD_SCSI_STATUS
); /* clear interrupt */
992 hostdata
->incoming_msg
[hostdata
->incoming_ptr
] = msg
;
993 if (hostdata
->incoming_msg
[0] == EXTENDED_MESSAGE
)
994 msg
= EXTENDED_MESSAGE
;
996 hostdata
->incoming_ptr
= 0;
998 cmd
->SCp
.Message
= msg
;
1001 case COMMAND_COMPLETE
:
1002 DB(DB_INTR
, printk("CCMP"))
1003 write_wd33c93_cmd(regs
, WD_CMD_NEGATE_ACK
);
1004 hostdata
->state
= S_PRE_CMP_DISC
;
1008 DB(DB_INTR
, printk("SDP"))
1009 write_wd33c93_cmd(regs
, WD_CMD_NEGATE_ACK
);
1010 hostdata
->state
= S_CONNECTED
;
1013 case RESTORE_POINTERS
:
1014 DB(DB_INTR
, printk("RDP"))
1015 if (hostdata
->level2
>= L2_BASIC
) {
1016 write_wd33c93(regs
, WD_COMMAND_PHASE
, 0x45);
1017 write_wd33c93_cmd(regs
, WD_CMD_SEL_ATN_XFER
);
1018 hostdata
->state
= S_RUNNING_LEVEL2
;
1020 write_wd33c93_cmd(regs
, WD_CMD_NEGATE_ACK
);
1021 hostdata
->state
= S_CONNECTED
;
1026 DB(DB_INTR
, printk("DIS"))
1027 cmd
->device
->disconnect
= 1;
1028 write_wd33c93_cmd(regs
, WD_CMD_NEGATE_ACK
);
1029 hostdata
->state
= S_PRE_TMP_DISC
;
1032 case MESSAGE_REJECT
:
1033 DB(DB_INTR
, printk("REJ"))
1037 if (hostdata
->sync_stat
[cmd
->device
->id
] == SS_WAITING
) {
1038 hostdata
->sync_stat
[cmd
->device
->id
] = SS_SET
;
1039 /* we want default_sx_per, not DEFAULT_SX_PER */
1040 hostdata
->sync_xfer
[cmd
->device
->id
] =
1041 calc_sync_xfer(hostdata
->default_sx_per
1042 / 4, 0, 0, hostdata
->sx_table
);
1044 write_wd33c93_cmd(regs
, WD_CMD_NEGATE_ACK
);
1045 hostdata
->state
= S_CONNECTED
;
1048 case EXTENDED_MESSAGE
:
1049 DB(DB_INTR
, printk("EXT"))
1051 ucp
= hostdata
->incoming_msg
;
1054 printk("%02x", ucp
[hostdata
->incoming_ptr
]);
1056 /* Is this the last byte of the extended message? */
1058 if ((hostdata
->incoming_ptr
>= 2) &&
1059 (hostdata
->incoming_ptr
== (ucp
[1] + 1))) {
1061 switch (ucp
[2]) { /* what's the EXTENDED code? */
1063 /* default to default async period */
1064 id
= calc_sync_xfer(hostdata
->
1065 default_sx_per
/ 4, 0,
1066 0, hostdata
->sx_table
);
1067 if (hostdata
->sync_stat
[cmd
->device
->id
] !=
1070 /* A device has sent an unsolicited SDTR message; rather than go
1071 * through the effort of decoding it and then figuring out what
1072 * our reply should be, we're just gonna say that we have a
1073 * synchronous fifo depth of 0. This will result in asynchronous
1074 * transfers - not ideal but so much easier.
1075 * Actually, this is OK because it assures us that if we don't
1076 * specifically ask for sync transfers, we won't do any.
1079 write_wd33c93_cmd(regs
, WD_CMD_ASSERT_ATN
); /* want MESS_OUT */
1080 hostdata
->outgoing_msg
[0] =
1082 hostdata
->outgoing_msg
[1] = 3;
1083 hostdata
->outgoing_msg
[2] =
1085 calc_sync_msg(hostdata
->
1087 0, hostdata
->outgoing_msg
+ 3);
1088 hostdata
->outgoing_len
= 5;
1090 if (ucp
[4]) /* well, sync transfer */
1091 id
= calc_sync_xfer(ucp
[3], ucp
[4],
1093 hostdata
->sx_table
);
1094 else if (ucp
[3]) /* very unlikely... */
1095 id
= calc_sync_xfer(ucp
[3], ucp
[4],
1096 0, hostdata
->sx_table
);
1098 hostdata
->sync_xfer
[cmd
->device
->id
] = id
;
1100 printk(" sync_xfer=%02x\n",
1101 hostdata
->sync_xfer
[cmd
->device
->id
]);
1103 hostdata
->sync_stat
[cmd
->device
->id
] =
1105 write_wd33c93_cmd(regs
,
1107 hostdata
->state
= S_CONNECTED
;
1110 write_wd33c93_cmd(regs
, WD_CMD_ASSERT_ATN
); /* want MESS_OUT */
1111 printk("sending WDTR ");
1112 hostdata
->outgoing_msg
[0] =
1114 hostdata
->outgoing_msg
[1] = 2;
1115 hostdata
->outgoing_msg
[2] =
1117 hostdata
->outgoing_msg
[3] = 0; /* 8 bit transfer width */
1118 hostdata
->outgoing_len
= 4;
1119 write_wd33c93_cmd(regs
,
1121 hostdata
->state
= S_CONNECTED
;
1124 write_wd33c93_cmd(regs
, WD_CMD_ASSERT_ATN
); /* want MESS_OUT */
1126 ("Rejecting Unknown Extended Message(%02x). ",
1128 hostdata
->outgoing_msg
[0] =
1130 hostdata
->outgoing_len
= 1;
1131 write_wd33c93_cmd(regs
,
1133 hostdata
->state
= S_CONNECTED
;
1136 hostdata
->incoming_ptr
= 0;
1139 /* We need to read more MESS_IN bytes for the extended message */
1142 hostdata
->incoming_ptr
++;
1143 write_wd33c93_cmd(regs
, WD_CMD_NEGATE_ACK
);
1144 hostdata
->state
= S_CONNECTED
;
1149 printk("Rejecting Unknown Message(%02x) ", msg
);
1150 write_wd33c93_cmd(regs
, WD_CMD_ASSERT_ATN
); /* want MESS_OUT */
1151 hostdata
->outgoing_msg
[0] = MESSAGE_REJECT
;
1152 hostdata
->outgoing_len
= 1;
1153 write_wd33c93_cmd(regs
, WD_CMD_NEGATE_ACK
);
1154 hostdata
->state
= S_CONNECTED
;
1156 spin_unlock_irqrestore(&hostdata
->lock
, flags
);
1159 /* Note: this interrupt will occur only after a LEVEL2 command */
1161 case CSR_SEL_XFER_DONE
:
1163 /* Make sure that reselection is enabled at this point - it may
1164 * have been turned off for the command that just completed.
1167 write_wd33c93(regs
, WD_SOURCE_ID
, SRCID_ER
);
1169 DB(DB_INTR
, printk("SX-DONE"))
1170 cmd
->SCp
.Message
= COMMAND_COMPLETE
;
1171 lun
= read_wd33c93(regs
, WD_TARGET_LUN
);
1172 DB(DB_INTR
, printk(":%d.%d", cmd
->SCp
.Status
, lun
))
1173 hostdata
->connected
= NULL
;
1174 hostdata
->busy
[cmd
->device
->id
] &= ~(1 << (cmd
->device
->lun
& 0xff));
1175 hostdata
->state
= S_UNCONNECTED
;
1176 if (cmd
->SCp
.Status
== ILLEGAL_STATUS_BYTE
)
1177 cmd
->SCp
.Status
= lun
;
1178 if (cmd
->cmnd
[0] == REQUEST_SENSE
1179 && cmd
->SCp
.Status
!= SAM_STAT_GOOD
) {
1180 set_host_byte(cmd
, DID_ERROR
);
1182 set_host_byte(cmd
, DID_OK
);
1183 scsi_msg_to_host_byte(cmd
, cmd
->SCp
.Message
);
1184 set_status_byte(cmd
, cmd
->SCp
.Status
);
1186 cmd
->scsi_done(cmd
);
1188 /* We are no longer connected to a target - check to see if
1189 * there are commands waiting to be executed.
1191 spin_unlock_irqrestore(&hostdata
->lock
, flags
);
1192 wd33c93_execute(instance
);
1195 ("%02x:%02x:%02x: Unknown SEL_XFER_DONE phase!!---",
1197 spin_unlock_irqrestore(&hostdata
->lock
, flags
);
1201 /* Note: this interrupt will occur only after a LEVEL2 command */
1204 DB(DB_INTR
, printk("SDP"))
1205 hostdata
->state
= S_RUNNING_LEVEL2
;
1206 write_wd33c93(regs
, WD_COMMAND_PHASE
, 0x41);
1207 write_wd33c93_cmd(regs
, WD_CMD_SEL_ATN_XFER
);
1208 spin_unlock_irqrestore(&hostdata
->lock
, flags
);
1211 case CSR_XFER_DONE
| PHS_MESS_OUT
:
1212 case CSR_UNEXP
| PHS_MESS_OUT
:
1213 case CSR_SRV_REQ
| PHS_MESS_OUT
:
1214 DB(DB_INTR
, printk("MSG_OUT="))
1216 /* To get here, we've probably requested MESSAGE_OUT and have
1217 * already put the correct bytes in outgoing_msg[] and filled
1218 * in outgoing_len. We simply send them out to the SCSI bus.
1219 * Sometimes we get MESSAGE_OUT phase when we're not expecting
1220 * it - like when our SDTR message is rejected by a target. Some
1221 * targets send the REJECT before receiving all of the extended
1222 * message, and then seem to go back to MESSAGE_OUT for a byte
1223 * or two. Not sure why, or if I'm doing something wrong to
1224 * cause this to happen. Regardless, it seems that sending
1225 * NOP messages in these situations results in no harm and
1226 * makes everyone happy.
1228 if (hostdata
->outgoing_len
== 0) {
1229 hostdata
->outgoing_len
= 1;
1230 hostdata
->outgoing_msg
[0] = NOP
;
1232 transfer_pio(regs
, hostdata
->outgoing_msg
,
1233 hostdata
->outgoing_len
, DATA_OUT_DIR
, hostdata
);
1234 DB(DB_INTR
, printk("%02x", hostdata
->outgoing_msg
[0]))
1235 hostdata
->outgoing_len
= 0;
1236 hostdata
->state
= S_CONNECTED
;
1237 spin_unlock_irqrestore(&hostdata
->lock
, flags
);
1240 case CSR_UNEXP_DISC
:
1242 /* I think I've seen this after a request-sense that was in response
1243 * to an error condition, but not sure. We certainly need to do
1244 * something when we get this interrupt - the question is 'what?'.
1245 * Let's think positively, and assume some command has finished
1246 * in a legal manner (like a command that provokes a request-sense),
1247 * so we treat it as a normal command-complete-disconnect.
1250 /* Make sure that reselection is enabled at this point - it may
1251 * have been turned off for the command that just completed.
1254 write_wd33c93(regs
, WD_SOURCE_ID
, SRCID_ER
);
1256 printk(" - Already disconnected! ");
1257 hostdata
->state
= S_UNCONNECTED
;
1258 spin_unlock_irqrestore(&hostdata
->lock
, flags
);
1261 DB(DB_INTR
, printk("UNEXP_DISC"))
1262 hostdata
->connected
= NULL
;
1263 hostdata
->busy
[cmd
->device
->id
] &= ~(1 << (cmd
->device
->lun
& 0xff));
1264 hostdata
->state
= S_UNCONNECTED
;
1265 if (cmd
->cmnd
[0] == REQUEST_SENSE
&&
1266 cmd
->SCp
.Status
!= SAM_STAT_GOOD
) {
1267 set_host_byte(cmd
, DID_ERROR
);
1269 set_host_byte(cmd
, DID_OK
);
1270 scsi_msg_to_host_byte(cmd
, cmd
->SCp
.Message
);
1271 set_status_byte(cmd
, cmd
->SCp
.Status
);
1273 cmd
->scsi_done(cmd
);
1275 /* We are no longer connected to a target - check to see if
1276 * there are commands waiting to be executed.
1278 /* look above for comments on scsi_done() */
1279 spin_unlock_irqrestore(&hostdata
->lock
, flags
);
1280 wd33c93_execute(instance
);
1285 /* Make sure that reselection is enabled at this point - it may
1286 * have been turned off for the command that just completed.
1289 write_wd33c93(regs
, WD_SOURCE_ID
, SRCID_ER
);
1290 DB(DB_INTR
, printk("DISC"))
1292 printk(" - Already disconnected! ");
1293 hostdata
->state
= S_UNCONNECTED
;
1295 switch (hostdata
->state
) {
1296 case S_PRE_CMP_DISC
:
1297 hostdata
->connected
= NULL
;
1298 hostdata
->busy
[cmd
->device
->id
] &= ~(1 << (cmd
->device
->lun
& 0xff));
1299 hostdata
->state
= S_UNCONNECTED
;
1300 DB(DB_INTR
, printk(":%d", cmd
->SCp
.Status
))
1301 if (cmd
->cmnd
[0] == REQUEST_SENSE
1302 && cmd
->SCp
.Status
!= SAM_STAT_GOOD
) {
1303 set_host_byte(cmd
, DID_ERROR
);
1305 set_host_byte(cmd
, DID_OK
);
1306 scsi_msg_to_host_byte(cmd
, cmd
->SCp
.Message
);
1307 set_status_byte(cmd
, cmd
->SCp
.Status
);
1309 cmd
->scsi_done(cmd
);
1311 case S_PRE_TMP_DISC
:
1312 case S_RUNNING_LEVEL2
:
1313 cmd
->host_scribble
= (uchar
*) hostdata
->disconnected_Q
;
1314 hostdata
->disconnected_Q
= cmd
;
1315 hostdata
->connected
= NULL
;
1316 hostdata
->state
= S_UNCONNECTED
;
1318 #ifdef PROC_STATISTICS
1319 hostdata
->disc_done_cnt
[cmd
->device
->id
]++;
1324 printk("*** Unexpected DISCONNECT interrupt! ***");
1325 hostdata
->state
= S_UNCONNECTED
;
1328 /* We are no longer connected to a target - check to see if
1329 * there are commands waiting to be executed.
1331 spin_unlock_irqrestore(&hostdata
->lock
, flags
);
1332 wd33c93_execute(instance
);
1337 DB(DB_INTR
, printk("RESEL%s", sr
== CSR_RESEL_AM
? "_AM" : ""))
1339 /* Old chips (pre -A ???) don't have advanced features and will
1340 * generate CSR_RESEL. In that case we have to extract the LUN the
1341 * hard way (see below).
1342 * First we have to make sure this reselection didn't
1343 * happen during Arbitration/Selection of some other device.
1344 * If yes, put losing command back on top of input_Q.
1346 if (hostdata
->level2
<= L2_NONE
) {
1348 if (hostdata
->selecting
) {
1349 cmd
= (struct scsi_cmnd
*) hostdata
->selecting
;
1350 hostdata
->selecting
= NULL
;
1351 hostdata
->busy
[cmd
->device
->id
] &= ~(1 << (cmd
->device
->lun
& 0xff));
1352 cmd
->host_scribble
=
1353 (uchar
*) hostdata
->input_Q
;
1354 hostdata
->input_Q
= cmd
;
1362 hostdata
->busy
[cmd
->device
->id
] &=
1363 ~(1 << (cmd
->device
->lun
& 0xff));
1364 cmd
->host_scribble
=
1365 (uchar
*) hostdata
->input_Q
;
1366 hostdata
->input_Q
= cmd
;
1369 ("---%02x:%02x:%02x-TROUBLE: Intrusive ReSelect!---",
1378 /* OK - find out which device reselected us. */
1380 id
= read_wd33c93(regs
, WD_SOURCE_ID
);
1383 /* and extract the lun from the ID message. (Note that we don't
1384 * bother to check for a valid message here - I guess this is
1385 * not the right way to go, but...)
1388 if (sr
== CSR_RESEL_AM
) {
1389 lun
= read_wd33c93(regs
, WD_DATA
);
1390 if (hostdata
->level2
< L2_RESELECT
)
1391 write_wd33c93_cmd(regs
, WD_CMD_NEGATE_ACK
);
1394 /* Old chip; wait for msgin phase to pick up the LUN. */
1395 for (lun
= 255; lun
; lun
--) {
1396 if ((asr
= read_aux_stat(regs
)) & ASR_INT
)
1400 if (!(asr
& ASR_INT
)) {
1402 ("wd33c93: Reselected without IDENTIFY\n");
1405 /* Verify this is a change to MSG_IN and read the message */
1406 sr
= read_wd33c93(regs
, WD_SCSI_STATUS
);
1408 if (sr
== (CSR_ABORT
| PHS_MESS_IN
) ||
1409 sr
== (CSR_UNEXP
| PHS_MESS_IN
) ||
1410 sr
== (CSR_SRV_REQ
| PHS_MESS_IN
)) {
1411 /* Got MSG_IN, grab target LUN */
1412 lun
= read_1_byte(regs
);
1413 /* Now we expect a 'paused with ACK asserted' int.. */
1414 asr
= read_aux_stat(regs
);
1415 if (!(asr
& ASR_INT
)) {
1417 asr
= read_aux_stat(regs
);
1418 if (!(asr
& ASR_INT
))
1420 ("wd33c93: No int after LUN on RESEL (%02x)\n",
1423 sr
= read_wd33c93(regs
, WD_SCSI_STATUS
);
1425 if (sr
!= CSR_MSGIN
)
1427 ("wd33c93: Not paused with ACK on RESEL (%02x)\n",
1430 write_wd33c93_cmd(regs
,
1434 ("wd33c93: Not MSG_IN on reselect (%02x)\n",
1441 /* Now we look for the command that's reconnecting. */
1443 cmd
= (struct scsi_cmnd
*) hostdata
->disconnected_Q
;
1446 if (id
== cmd
->device
->id
&& lun
== (u8
)cmd
->device
->lun
)
1449 cmd
= (struct scsi_cmnd
*) cmd
->host_scribble
;
1452 /* Hmm. Couldn't find a valid command.... What to do? */
1456 ("---TROUBLE: target %d.%d not in disconnect queue---",
1458 spin_unlock_irqrestore(&hostdata
->lock
, flags
);
1462 /* Ok, found the command - now start it up again. */
1465 patch
->host_scribble
= cmd
->host_scribble
;
1467 hostdata
->disconnected_Q
=
1468 (struct scsi_cmnd
*) cmd
->host_scribble
;
1469 hostdata
->connected
= cmd
;
1471 /* We don't need to worry about 'initialize_SCp()' or 'hostdata->busy[]'
1472 * because these things are preserved over a disconnect.
1473 * But we DO need to fix the DPD bit so it's correct for this command.
1476 if (cmd
->sc_data_direction
== DMA_TO_DEVICE
)
1477 write_wd33c93(regs
, WD_DESTINATION_ID
, cmd
->device
->id
);
1479 write_wd33c93(regs
, WD_DESTINATION_ID
,
1480 cmd
->device
->id
| DSTID_DPD
);
1481 if (hostdata
->level2
>= L2_RESELECT
) {
1482 write_wd33c93_count(regs
, 0); /* we want a DATA_PHASE interrupt */
1483 write_wd33c93(regs
, WD_COMMAND_PHASE
, 0x45);
1484 write_wd33c93_cmd(regs
, WD_CMD_SEL_ATN_XFER
);
1485 hostdata
->state
= S_RUNNING_LEVEL2
;
1487 hostdata
->state
= S_CONNECTED
;
1489 spin_unlock_irqrestore(&hostdata
->lock
, flags
);
1493 printk("--UNKNOWN INTERRUPT:%02x:%02x:%02x--", asr
, sr
, phs
);
1494 spin_unlock_irqrestore(&hostdata
->lock
, flags
);
1497 DB(DB_INTR
, printk("} "))
1502 reset_wd33c93(struct Scsi_Host
*instance
)
1504 struct WD33C93_hostdata
*hostdata
=
1505 (struct WD33C93_hostdata
*) instance
->hostdata
;
1506 const wd33c93_regs regs
= hostdata
->regs
;
1509 #ifdef CONFIG_SGI_IP22
1512 extern void sgiwd93_reset(unsigned long);
1513 /* wait 'til the chip gets some time for us */
1514 while ((read_aux_stat(regs
) & ASR_BSY
) && busycount
++ < 100)
1517 * there are scsi devices out there, which manage to lock up
1518 * the wd33c93 in a busy condition. In this state it won't
1519 * accept the reset command. The only way to solve this is to
1520 * give the chip a hardware reset (if possible). The code below
1521 * does this for the SGI Indy, where this is possible
1524 if (read_aux_stat(regs
) & ASR_BSY
)
1525 sgiwd93_reset(instance
->base
); /* yeah, give it the hard one */
1529 write_wd33c93(regs
, WD_OWN_ID
, OWNID_EAF
| OWNID_RAF
|
1530 instance
->this_id
| hostdata
->clock_freq
);
1531 write_wd33c93(regs
, WD_CONTROL
, CTRL_IDI
| CTRL_EDI
| CTRL_POLLED
);
1532 write_wd33c93(regs
, WD_SYNCHRONOUS_TRANSFER
,
1533 calc_sync_xfer(hostdata
->default_sx_per
/ 4,
1534 DEFAULT_SX_OFF
, 0, hostdata
->sx_table
));
1535 write_wd33c93(regs
, WD_COMMAND
, WD_CMD_RESET
);
1538 #ifdef CONFIG_MVME147_SCSI
1539 udelay(25); /* The old wd33c93 on MVME147 needs this, at least */
1542 while (!(read_aux_stat(regs
) & ASR_INT
))
1544 sr
= read_wd33c93(regs
, WD_SCSI_STATUS
);
1546 hostdata
->microcode
= read_wd33c93(regs
, WD_CDB_1
);
1548 hostdata
->chip
= C_WD33C93
;
1549 else if (sr
== 0x01) {
1550 write_wd33c93(regs
, WD_QUEUE_TAG
, 0xa5); /* any random number */
1551 sr
= read_wd33c93(regs
, WD_QUEUE_TAG
);
1553 hostdata
->chip
= C_WD33C93B
;
1554 write_wd33c93(regs
, WD_QUEUE_TAG
, 0);
1556 hostdata
->chip
= C_WD33C93A
;
1558 hostdata
->chip
= C_UNKNOWN_CHIP
;
1560 if (hostdata
->chip
!= C_WD33C93B
) /* Fast SCSI unavailable */
1563 write_wd33c93(regs
, WD_TIMEOUT_PERIOD
, TIMEOUT_PERIOD_VALUE
);
1564 write_wd33c93(regs
, WD_CONTROL
, CTRL_IDI
| CTRL_EDI
| CTRL_POLLED
);
1568 wd33c93_host_reset(struct scsi_cmnd
* SCpnt
)
1570 struct Scsi_Host
*instance
;
1571 struct WD33C93_hostdata
*hostdata
;
1574 instance
= SCpnt
->device
->host
;
1575 spin_lock_irq(instance
->host_lock
);
1576 hostdata
= (struct WD33C93_hostdata
*) instance
->hostdata
;
1578 printk("scsi%d: reset. ", instance
->host_no
);
1579 disable_irq(instance
->irq
);
1581 hostdata
->dma_stop(instance
, NULL
, 0);
1582 for (i
= 0; i
< 8; i
++) {
1583 hostdata
->busy
[i
] = 0;
1584 hostdata
->sync_xfer
[i
] =
1585 calc_sync_xfer(DEFAULT_SX_PER
/ 4, DEFAULT_SX_OFF
,
1586 0, hostdata
->sx_table
);
1587 hostdata
->sync_stat
[i
] = SS_UNSET
; /* using default sync values */
1589 hostdata
->input_Q
= NULL
;
1590 hostdata
->selecting
= NULL
;
1591 hostdata
->connected
= NULL
;
1592 hostdata
->disconnected_Q
= NULL
;
1593 hostdata
->state
= S_UNCONNECTED
;
1594 hostdata
->dma
= D_DMA_OFF
;
1595 hostdata
->incoming_ptr
= 0;
1596 hostdata
->outgoing_len
= 0;
1598 reset_wd33c93(instance
);
1599 SCpnt
->result
= DID_RESET
<< 16;
1600 enable_irq(instance
->irq
);
1601 spin_unlock_irq(instance
->host_lock
);
1606 wd33c93_abort(struct scsi_cmnd
* cmd
)
1608 struct Scsi_Host
*instance
;
1609 struct WD33C93_hostdata
*hostdata
;
1611 struct scsi_cmnd
*tmp
, *prev
;
1613 disable_irq(cmd
->device
->host
->irq
);
1615 instance
= cmd
->device
->host
;
1616 hostdata
= (struct WD33C93_hostdata
*) instance
->hostdata
;
1617 regs
= hostdata
->regs
;
1620 * Case 1 : If the command hasn't been issued yet, we simply remove it
1624 tmp
= (struct scsi_cmnd
*) hostdata
->input_Q
;
1629 prev
->host_scribble
= cmd
->host_scribble
;
1632 (struct scsi_cmnd
*) cmd
->host_scribble
;
1633 cmd
->host_scribble
= NULL
;
1634 cmd
->result
= DID_ABORT
<< 16;
1636 ("scsi%d: Abort - removing command from input_Q. ",
1638 enable_irq(cmd
->device
->host
->irq
);
1639 cmd
->scsi_done(cmd
);
1643 tmp
= (struct scsi_cmnd
*) tmp
->host_scribble
;
1647 * Case 2 : If the command is connected, we're going to fail the abort
1648 * and let the high level SCSI driver retry at a later time or
1651 * Timeouts, and therefore aborted commands, will be highly unlikely
1652 * and handling them cleanly in this situation would make the common
1653 * case of noresets less efficient, and would pollute our code. So,
1657 if (hostdata
->connected
== cmd
) {
1659 unsigned long timeout
;
1661 printk("scsi%d: Aborting connected command - ",
1664 printk("stopping DMA - ");
1665 if (hostdata
->dma
== D_DMA_RUNNING
) {
1666 hostdata
->dma_stop(instance
, cmd
, 0);
1667 hostdata
->dma
= D_DMA_OFF
;
1670 printk("sending wd33c93 ABORT command - ");
1671 write_wd33c93(regs
, WD_CONTROL
,
1672 CTRL_IDI
| CTRL_EDI
| CTRL_POLLED
);
1673 write_wd33c93_cmd(regs
, WD_CMD_ABORT
);
1675 /* Now we have to attempt to flush out the FIFO... */
1677 printk("flushing fifo - ");
1680 asr
= read_aux_stat(regs
);
1682 read_wd33c93(regs
, WD_DATA
);
1683 } while (!(asr
& ASR_INT
) && timeout
-- > 0);
1684 sr
= read_wd33c93(regs
, WD_SCSI_STATUS
);
1686 ("asr=%02x, sr=%02x, %ld bytes un-transferred (timeout=%ld) - ",
1687 asr
, sr
, read_wd33c93_count(regs
), timeout
);
1690 * Abort command processed.
1692 * We must disconnect.
1695 printk("sending wd33c93 DISCONNECT command - ");
1696 write_wd33c93_cmd(regs
, WD_CMD_DISCONNECT
);
1699 asr
= read_aux_stat(regs
);
1700 while ((asr
& ASR_CIP
) && timeout
-- > 0)
1701 asr
= read_aux_stat(regs
);
1702 sr
= read_wd33c93(regs
, WD_SCSI_STATUS
);
1703 printk("asr=%02x, sr=%02x.", asr
, sr
);
1705 hostdata
->busy
[cmd
->device
->id
] &= ~(1 << (cmd
->device
->lun
& 0xff));
1706 hostdata
->connected
= NULL
;
1707 hostdata
->state
= S_UNCONNECTED
;
1708 cmd
->result
= DID_ABORT
<< 16;
1711 wd33c93_execute(instance
);
1713 enable_irq(cmd
->device
->host
->irq
);
1714 cmd
->scsi_done(cmd
);
1719 * Case 3: If the command is currently disconnected from the bus,
1720 * we're not going to expend much effort here: Let's just return
1721 * an ABORT_SNOOZE and hope for the best...
1724 tmp
= (struct scsi_cmnd
*) hostdata
->disconnected_Q
;
1728 ("scsi%d: Abort - command found on disconnected_Q - ",
1730 printk("Abort SNOOZE. ");
1731 enable_irq(cmd
->device
->host
->irq
);
1734 tmp
= (struct scsi_cmnd
*) tmp
->host_scribble
;
1738 * Case 4 : If we reached this point, the command was not found in any of
1741 * We probably reached this point because of an unlikely race condition
1742 * between the command completing successfully and the abortion code,
1743 * so we won't panic, but we will notify the user in case something really
1748 wd33c93_execute(instance
);
1750 enable_irq(cmd
->device
->host
->irq
);
1751 printk("scsi%d: warning : SCSI command probably completed successfully"
1752 " before abortion. ", instance
->host_no
);
1756 #define MAX_WD33C93_HOSTS 4
1757 #define MAX_SETUP_ARGS ARRAY_SIZE(setup_args)
1758 #define SETUP_BUFFER_SIZE 200
1759 static char setup_buffer
[SETUP_BUFFER_SIZE
];
1760 static char setup_used
[MAX_SETUP_ARGS
];
1761 static int done_setup
= 0;
1764 wd33c93_setup(char *str
)
1769 /* The kernel does some processing of the command-line before calling
1770 * this function: If it begins with any decimal or hex number arguments,
1771 * ints[0] = how many numbers found and ints[1] through [n] are the values
1772 * themselves. str points to where the non-numeric arguments (if any)
1773 * start: We do our own parsing of those. We construct synthetic 'nosync'
1774 * keywords out of numeric args (to maintain compatibility with older
1775 * versions) and then add the rest of the arguments.
1781 strncpy(p1
, str
, SETUP_BUFFER_SIZE
- strlen(setup_buffer
));
1782 setup_buffer
[SETUP_BUFFER_SIZE
- 1] = '\0';
1785 while (*p1
&& (i
< MAX_SETUP_ARGS
)) {
1786 p2
= strchr(p1
, ',');
1798 for (i
= 0; i
< MAX_SETUP_ARGS
; i
++)
1804 __setup("wd33c93=", wd33c93_setup
);
1806 /* check_setup_args() returns index if key found, 0 if not
1809 check_setup_args(char *key
, int *flags
, int *val
, char *buf
)
1814 for (x
= 0; x
< MAX_SETUP_ARGS
; x
++) {
1817 if (!strncmp(setup_args
[x
], key
, strlen(key
)))
1819 if (!strncmp(setup_args
[x
], "next", strlen("next")))
1822 if (x
== MAX_SETUP_ARGS
)
1825 cp
= setup_args
[x
] + strlen(key
);
1830 if ((*cp
>= '0') && (*cp
<= '9')) {
1831 *val
= simple_strtoul(cp
, NULL
, 0);
1837 * Calculate internal data-transfer-clock cycle from input-clock
1838 * frequency (/MHz) and fill 'sx_table'.
1840 * The original driver used to rely on a fixed sx_table, containing periods
1841 * for (only) the lower limits of the respective input-clock-frequency ranges
1842 * (8-10/12-15/16-20 MHz). Although it seems, that no problems occurred with
1843 * this setting so far, it might be desirable to adjust the transfer periods
1844 * closer to the really attached, possibly 25% higher, input-clock, since
1845 * - the wd33c93 may really use a significant shorter period, than it has
1846 * negotiated (eg. thrashing the target, which expects 4/8MHz, with 5/10MHz
1848 * - the wd33c93 may ask the target for a lower transfer rate, than the target
1849 * is capable of (eg. negotiating for an assumed minimum of 252ns instead of
1850 * possible 200ns, which indeed shows up in tests as an approx. 10% lower
1853 static inline unsigned int
1854 round_4(unsigned int x
)
1867 calc_sx_table(unsigned int mhz
, struct sx_period sx_table
[9])
1871 d
= 2; /* divisor for 8-10 MHz input-clock */
1873 d
= 3; /* divisor for 12-15 MHz input-clock */
1875 d
= 4; /* divisor for 16-20 MHz input-clock */
1877 d
= (100000 * d
) / 2 / mhz
; /* 100 x DTCC / nanosec */
1879 sx_table
[0].period_ns
= 1;
1880 sx_table
[0].reg_value
= 0x20;
1881 for (i
= 1; i
< 8; i
++) {
1882 sx_table
[i
].period_ns
= round_4((i
+1)*d
/ 100);
1883 sx_table
[i
].reg_value
= (i
+1)*0x10;
1885 sx_table
[7].reg_value
= 0;
1886 sx_table
[8].period_ns
= 0;
1887 sx_table
[8].reg_value
= 0;
1891 * check and, maybe, map an init- or "clock:"- argument.
1894 set_clk_freq(int freq
, int *mhz
)
1897 if (WD33C93_FS_8_10
== freq
)
1899 else if (WD33C93_FS_12_15
== freq
)
1901 else if (WD33C93_FS_16_20
== freq
)
1903 else if (freq
> 7 && freq
< 11)
1904 x
= WD33C93_FS_8_10
;
1905 else if (freq
> 11 && freq
< 16)
1906 x
= WD33C93_FS_12_15
;
1907 else if (freq
> 15 && freq
< 21)
1908 x
= WD33C93_FS_16_20
;
1910 /* Hmm, wouldn't it be safer to assume highest freq here? */
1911 x
= WD33C93_FS_8_10
;
1919 * to be used with the resync: fast: ... options
1921 static inline void set_resync ( struct WD33C93_hostdata
*hd
, int mask
)
1924 for (i
= 0; i
< 8; i
++)
1925 if (mask
& (1 << i
))
1926 hd
->sync_stat
[i
] = SS_UNSET
;
1930 wd33c93_init(struct Scsi_Host
*instance
, const wd33c93_regs regs
,
1931 dma_setup_t setup
, dma_stop_t stop
, int clock_freq
)
1933 struct WD33C93_hostdata
*hostdata
;
1939 if (!done_setup
&& setup_strings
)
1940 wd33c93_setup(setup_strings
);
1942 hostdata
= (struct WD33C93_hostdata
*) instance
->hostdata
;
1944 hostdata
->regs
= regs
;
1945 hostdata
->clock_freq
= set_clk_freq(clock_freq
, &i
);
1946 calc_sx_table(i
, hostdata
->sx_table
);
1947 hostdata
->dma_setup
= setup
;
1948 hostdata
->dma_stop
= stop
;
1949 hostdata
->dma_bounce_buffer
= NULL
;
1950 hostdata
->dma_bounce_len
= 0;
1951 for (i
= 0; i
< 8; i
++) {
1952 hostdata
->busy
[i
] = 0;
1953 hostdata
->sync_xfer
[i
] =
1954 calc_sync_xfer(DEFAULT_SX_PER
/ 4, DEFAULT_SX_OFF
,
1955 0, hostdata
->sx_table
);
1956 hostdata
->sync_stat
[i
] = SS_UNSET
; /* using default sync values */
1957 #ifdef PROC_STATISTICS
1958 hostdata
->cmd_cnt
[i
] = 0;
1959 hostdata
->disc_allowed_cnt
[i
] = 0;
1960 hostdata
->disc_done_cnt
[i
] = 0;
1963 hostdata
->input_Q
= NULL
;
1964 hostdata
->selecting
= NULL
;
1965 hostdata
->connected
= NULL
;
1966 hostdata
->disconnected_Q
= NULL
;
1967 hostdata
->state
= S_UNCONNECTED
;
1968 hostdata
->dma
= D_DMA_OFF
;
1969 hostdata
->level2
= L2_BASIC
;
1970 hostdata
->disconnect
= DIS_ADAPTIVE
;
1971 hostdata
->args
= DEBUG_DEFAULTS
;
1972 hostdata
->incoming_ptr
= 0;
1973 hostdata
->outgoing_len
= 0;
1974 hostdata
->default_sx_per
= DEFAULT_SX_PER
;
1975 hostdata
->no_dma
= 0; /* default is DMA enabled */
1977 #ifdef PROC_INTERFACE
1978 hostdata
->proc
= PR_VERSION
| PR_INFO
| PR_STATISTICS
|
1979 PR_CONNECTED
| PR_INPUTQ
| PR_DISCQ
| PR_STOP
;
1980 #ifdef PROC_STATISTICS
1981 hostdata
->dma_cnt
= 0;
1982 hostdata
->pio_cnt
= 0;
1983 hostdata
->int_cnt
= 0;
1987 if (check_setup_args("clock", &flags
, &val
, buf
)) {
1988 hostdata
->clock_freq
= set_clk_freq(val
, &val
);
1989 calc_sx_table(val
, hostdata
->sx_table
);
1992 if (check_setup_args("nosync", &flags
, &val
, buf
))
1993 hostdata
->no_sync
= val
;
1995 if (check_setup_args("nodma", &flags
, &val
, buf
))
1996 hostdata
->no_dma
= (val
== -1) ? 1 : val
;
1998 if (check_setup_args("period", &flags
, &val
, buf
))
1999 hostdata
->default_sx_per
=
2000 hostdata
->sx_table
[round_period((unsigned int) val
,
2001 hostdata
->sx_table
)].period_ns
;
2003 if (check_setup_args("disconnect", &flags
, &val
, buf
)) {
2004 if ((val
>= DIS_NEVER
) && (val
<= DIS_ALWAYS
))
2005 hostdata
->disconnect
= val
;
2007 hostdata
->disconnect
= DIS_ADAPTIVE
;
2010 if (check_setup_args("level2", &flags
, &val
, buf
))
2011 hostdata
->level2
= val
;
2013 if (check_setup_args("debug", &flags
, &val
, buf
))
2014 hostdata
->args
= val
& DB_MASK
;
2016 if (check_setup_args("burst", &flags
, &val
, buf
))
2017 hostdata
->dma_mode
= val
? CTRL_BURST
:CTRL_DMA
;
2019 if (WD33C93_FS_16_20
== hostdata
->clock_freq
/* divisor 4 */
2020 && check_setup_args("fast", &flags
, &val
, buf
))
2021 hostdata
->fast
= !!val
;
2023 if ((i
= check_setup_args("next", &flags
, &val
, buf
))) {
2025 setup_used
[--i
] = 1;
2027 #ifdef PROC_INTERFACE
2028 if (check_setup_args("proc", &flags
, &val
, buf
))
2029 hostdata
->proc
= val
;
2032 spin_lock_irq(&hostdata
->lock
);
2033 reset_wd33c93(instance
);
2034 spin_unlock_irq(&hostdata
->lock
);
2036 printk("wd33c93-%d: chip=%s/%d no_sync=0x%x no_dma=%d",
2038 (hostdata
->chip
== C_WD33C93
) ? "WD33c93" : (hostdata
->chip
==
2040 "WD33c93A" : (hostdata
->chip
==
2041 C_WD33C93B
) ? "WD33c93B" : "unknown",
2042 hostdata
->microcode
, hostdata
->no_sync
, hostdata
->no_dma
);
2044 printk(" debug_flags=0x%02x\n", hostdata
->args
);
2046 printk(" debugging=OFF\n");
2048 printk(" setup_args=");
2049 for (i
= 0; i
< MAX_SETUP_ARGS
; i
++)
2050 printk("%s,", setup_args
[i
]);
2052 printk(" Version %s - %s\n", WD33C93_VERSION
, WD33C93_DATE
);
2055 int wd33c93_write_info(struct Scsi_Host
*instance
, char *buf
, int len
)
2057 #ifdef PROC_INTERFACE
2059 struct WD33C93_hostdata
*hd
;
2062 hd
= (struct WD33C93_hostdata
*) instance
->hostdata
;
2064 /* We accept the following
2065 * keywords (same format as command-line, but arguments are not optional):
2079 for (bp
= buf
; *bp
; ) {
2080 while (',' == *bp
|| ' ' == *bp
)
2082 if (!strncmp(bp
, "debug:", 6)) {
2083 hd
->args
= simple_strtoul(bp
+6, &bp
, 0) & DB_MASK
;
2084 } else if (!strncmp(bp
, "disconnect:", 11)) {
2085 x
= simple_strtoul(bp
+11, &bp
, 0);
2086 if (x
< DIS_NEVER
|| x
> DIS_ALWAYS
)
2089 } else if (!strncmp(bp
, "period:", 7)) {
2090 x
= simple_strtoul(bp
+7, &bp
, 0);
2091 hd
->default_sx_per
=
2092 hd
->sx_table
[round_period((unsigned int) x
,
2093 hd
->sx_table
)].period_ns
;
2094 } else if (!strncmp(bp
, "resync:", 7)) {
2095 set_resync(hd
, (int)simple_strtoul(bp
+7, &bp
, 0));
2096 } else if (!strncmp(bp
, "proc:", 5)) {
2097 hd
->proc
= simple_strtoul(bp
+5, &bp
, 0);
2098 } else if (!strncmp(bp
, "nodma:", 6)) {
2099 hd
->no_dma
= simple_strtoul(bp
+6, &bp
, 0);
2100 } else if (!strncmp(bp
, "level2:", 7)) {
2101 hd
->level2
= simple_strtoul(bp
+7, &bp
, 0);
2102 } else if (!strncmp(bp
, "burst:", 6)) {
2104 simple_strtol(bp
+6, &bp
, 0) ? CTRL_BURST
:CTRL_DMA
;
2105 } else if (!strncmp(bp
, "fast:", 5)) {
2106 x
= !!simple_strtol(bp
+5, &bp
, 0);
2108 set_resync(hd
, 0xff);
2110 } else if (!strncmp(bp
, "nosync:", 7)) {
2111 x
= simple_strtoul(bp
+7, &bp
, 0);
2112 set_resync(hd
, x
^ hd
->no_sync
);
2115 break; /* unknown keyword,syntax-error,... */
2125 wd33c93_show_info(struct seq_file
*m
, struct Scsi_Host
*instance
)
2127 #ifdef PROC_INTERFACE
2128 struct WD33C93_hostdata
*hd
;
2129 struct scsi_cmnd
*cmd
;
2132 hd
= (struct WD33C93_hostdata
*) instance
->hostdata
;
2134 spin_lock_irq(&hd
->lock
);
2135 if (hd
->proc
& PR_VERSION
)
2136 seq_printf(m
, "\nVersion %s - %s.",
2137 WD33C93_VERSION
, WD33C93_DATE
);
2139 if (hd
->proc
& PR_INFO
) {
2140 seq_printf(m
, "\nclock_freq=%02x no_sync=%02x no_dma=%d"
2141 " dma_mode=%02x fast=%d",
2142 hd
->clock_freq
, hd
->no_sync
, hd
->no_dma
, hd
->dma_mode
, hd
->fast
);
2143 seq_puts(m
, "\nsync_xfer[] = ");
2144 for (x
= 0; x
< 7; x
++)
2145 seq_printf(m
, "\t%02x", hd
->sync_xfer
[x
]);
2146 seq_puts(m
, "\nsync_stat[] = ");
2147 for (x
= 0; x
< 7; x
++)
2148 seq_printf(m
, "\t%02x", hd
->sync_stat
[x
]);
2150 #ifdef PROC_STATISTICS
2151 if (hd
->proc
& PR_STATISTICS
) {
2152 seq_puts(m
, "\ncommands issued: ");
2153 for (x
= 0; x
< 7; x
++)
2154 seq_printf(m
, "\t%ld", hd
->cmd_cnt
[x
]);
2155 seq_puts(m
, "\ndisconnects allowed:");
2156 for (x
= 0; x
< 7; x
++)
2157 seq_printf(m
, "\t%ld", hd
->disc_allowed_cnt
[x
]);
2158 seq_puts(m
, "\ndisconnects done: ");
2159 for (x
= 0; x
< 7; x
++)
2160 seq_printf(m
, "\t%ld", hd
->disc_done_cnt
[x
]);
2162 "\ninterrupts: %ld, DATA_PHASE ints: %ld DMA, %ld PIO",
2163 hd
->int_cnt
, hd
->dma_cnt
, hd
->pio_cnt
);
2166 if (hd
->proc
& PR_CONNECTED
) {
2167 seq_puts(m
, "\nconnected: ");
2168 if (hd
->connected
) {
2169 cmd
= (struct scsi_cmnd
*) hd
->connected
;
2170 seq_printf(m
, " %d:%llu(%02x)",
2171 cmd
->device
->id
, cmd
->device
->lun
, cmd
->cmnd
[0]);
2174 if (hd
->proc
& PR_INPUTQ
) {
2175 seq_puts(m
, "\ninput_Q: ");
2176 cmd
= (struct scsi_cmnd
*) hd
->input_Q
;
2178 seq_printf(m
, " %d:%llu(%02x)",
2179 cmd
->device
->id
, cmd
->device
->lun
, cmd
->cmnd
[0]);
2180 cmd
= (struct scsi_cmnd
*) cmd
->host_scribble
;
2183 if (hd
->proc
& PR_DISCQ
) {
2184 seq_puts(m
, "\ndisconnected_Q:");
2185 cmd
= (struct scsi_cmnd
*) hd
->disconnected_Q
;
2187 seq_printf(m
, " %d:%llu(%02x)",
2188 cmd
->device
->id
, cmd
->device
->lun
, cmd
->cmnd
[0]);
2189 cmd
= (struct scsi_cmnd
*) cmd
->host_scribble
;
2193 spin_unlock_irq(&hd
->lock
);
2194 #endif /* PROC_INTERFACE */
2198 EXPORT_SYMBOL(wd33c93_host_reset
);
2199 EXPORT_SYMBOL(wd33c93_init
);
2200 EXPORT_SYMBOL(wd33c93_abort
);
2201 EXPORT_SYMBOL(wd33c93_queuecommand
);
2202 EXPORT_SYMBOL(wd33c93_intr
);
2203 EXPORT_SYMBOL(wd33c93_show_info
);
2204 EXPORT_SYMBOL(wd33c93_write_info
);