2 * Copyright (c) 1996 John Shifflett, GeoLog Consulting
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2, or (at your option)
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
18 * Drew Eckhardt's excellent 'Generic NCR5380' sources from Linux-PC
19 * provided much of the inspiration and some of the code for this
20 * driver. Everything I know about Amiga DMA was gleaned from careful
21 * reading of Hamish Mcdonald's original wd33c93 driver; in fact, I
22 * borrowed shamelessly from all over that source. Thanks Hamish!
24 * _This_ driver is (I feel) an improvement over the old one in
27 * - Target Disconnection/Reconnection is now supported. Any
28 * system with more than one device active on the SCSI bus
29 * will benefit from this. The driver defaults to what I
30 * call 'adaptive disconnect' - meaning that each command
31 * is evaluated individually as to whether or not it should
32 * be run with the option to disconnect/reselect (if the
33 * device chooses), or as a "SCSI-bus-hog".
35 * - Synchronous data transfers are now supported. Because of
36 * a few devices that choke after telling the driver that
37 * they can do sync transfers, we don't automatically use
38 * this faster protocol - it can be enabled via the command-
39 * line on a device-by-device basis.
41 * - Runtime operating parameters can now be specified through
42 * the 'amiboot' or the 'insmod' command line. For amiboot do:
43 * "amiboot [usual stuff] wd33c93=blah,blah,blah"
44 * The defaults should be good for most people. See the comment
45 * for 'setup_strings' below for more details.
47 * - The old driver relied exclusively on what the Western Digital
48 * docs call "Combination Level 2 Commands", which are a great
49 * idea in that the CPU is relieved of a lot of interrupt
50 * overhead. However, by accepting a certain (user-settable)
51 * amount of additional interrupts, this driver achieves
52 * better control over the SCSI bus, and data transfers are
53 * almost as fast while being much easier to define, track,
58 * more speed. linked commands.
61 * People with bug reports, wish-lists, complaints, comments,
62 * or improvements are asked to pah-leeez email me (John Shifflett)
63 * at john@geolog.com or jshiffle@netcom.com! I'm anxious to get
64 * this thing into as good a shape as possible, and I'm positive
65 * there are lots of lurking bugs and "Stupid Places".
69 * Added support for pre -A chips, which don't have advanced features
70 * and will generate CSR_RESEL rather than CSR_RESEL_AM.
71 * Richard Hirst <richard@sleepie.demon.co.uk> August 2000
73 * Added support for Burst Mode DMA and Fast SCSI. Enabled the use of
74 * default_sx_per for asynchronous data transfers. Added adjustment
75 * of transfer periods in sx_table to the actual input-clock.
76 * peter fuerst <post@pfrst.de> February 2007
79 #include <linux/module.h>
81 #include <linux/string.h>
82 #include <linux/delay.h>
83 #include <linux/init.h>
84 #include <linux/interrupt.h>
85 #include <linux/blkdev.h>
87 #include <scsi/scsi.h>
88 #include <scsi/scsi_cmnd.h>
89 #include <scsi/scsi_device.h>
90 #include <scsi/scsi_host.h>
94 #define optimum_sx_per(hostdata) (hostdata)->sx_table[1].period_ns
97 #define WD33C93_VERSION "1.26++"
98 #define WD33C93_DATE "10/Feb/2007"
100 MODULE_AUTHOR("John Shifflett");
101 MODULE_DESCRIPTION("Generic WD33C93 SCSI driver");
102 MODULE_LICENSE("GPL");
105 * 'setup_strings' is a single string used to pass operating parameters and
106 * settings from the kernel/module command-line to the driver. 'setup_args[]'
107 * is an array of strings that define the compile-time default values for
108 * these settings. If Linux boots with an amiboot or insmod command-line,
109 * those settings are combined with 'setup_args[]'. Note that amiboot
110 * command-lines are prefixed with "wd33c93=" while insmod uses a
111 * "setup_strings=" prefix. The driver recognizes the following keywords
112 * (lower case required) and arguments:
114 * - nosync:bitmask -bitmask is a byte where the 1st 7 bits correspond with
115 * the 7 possible SCSI devices. Set a bit to negotiate for
116 * asynchronous transfers on that device. To maintain
117 * backwards compatibility, a command-line such as
118 * "wd33c93=255" will be automatically translated to
119 * "wd33c93=nosync:0xff".
120 * - nodma:x -x = 1 to disable DMA, x = 0 to enable it. Argument is
121 * optional - if not present, same as "nodma:1".
122 * - period:ns -ns is the minimum # of nanoseconds in a SCSI data transfer
123 * period. Default is 500; acceptable values are 250 - 1000.
124 * - disconnect:x -x = 0 to never allow disconnects, 2 to always allow them.
125 * x = 1 does 'adaptive' disconnects, which is the default
126 * and generally the best choice.
127 * - debug:x -If 'DEBUGGING_ON' is defined, x is a bit mask that causes
128 * various types of debug output to printed - see the DB_xxx
129 * defines in wd33c93.h
130 * - clock:x -x = clock input in MHz for WD33c93 chip. Normal values
131 * would be from 8 through 20. Default is 8.
132 * - burst:x -x = 1 to use Burst Mode (or Demand-Mode) DMA, x = 0 to use
133 * Single Byte DMA, which is the default. Argument is
134 * optional - if not present, same as "burst:1".
135 * - fast:x -x = 1 to enable Fast SCSI, which is only effective with
136 * input-clock divisor 4 (WD33C93_FS_16_20), x = 0 to disable
137 * it, which is the default. Argument is optional - if not
138 * present, same as "fast:1".
139 * - next -No argument. Used to separate blocks of keywords when
140 * there's more than one host adapter in the system.
143 * - Numeric arguments can be decimal or the '0x' form of hex notation. There
144 * _must_ be a colon between a keyword and its numeric argument, with no
146 * - Keywords are separated by commas, no spaces, in the standard kernel
147 * command-line manner.
148 * - A keyword in the 'nth' comma-separated command-line member will overwrite
149 * the 'nth' element of setup_args[]. A blank command-line member (in
150 * other words, a comma with no preceding keyword) will _not_ overwrite
151 * the corresponding setup_args[] element.
152 * - If a keyword is used more than once, the first one applies to the first
153 * SCSI host found, the second to the second card, etc, unless the 'next'
154 * keyword is used to change the order.
156 * Some amiboot examples (for insmod, use 'setup_strings' instead of 'wd33c93'):
157 * - wd33c93=nosync:255
160 * - wd33c93=disconnect:2,nosync:0x08,period:250
161 * - wd33c93=debug:0x1c
164 /* Normally, no defaults are specified */
165 static char *setup_args
[] = { "", "", "", "", "", "", "", "", "", "" };
167 static char *setup_strings
;
168 module_param(setup_strings
, charp
, 0);
170 static void wd33c93_execute(struct Scsi_Host
*instance
);
172 #ifdef CONFIG_WD33C93_PIO
174 read_wd33c93(const wd33c93_regs regs
, uchar reg_num
)
178 outb(reg_num
, regs
.SASR
);
179 data
= inb(regs
.SCMD
);
183 static inline unsigned long
184 read_wd33c93_count(const wd33c93_regs regs
)
188 outb(WD_TRANSFER_COUNT_MSB
, regs
.SASR
);
189 value
= inb(regs
.SCMD
) << 16;
190 value
|= inb(regs
.SCMD
) << 8;
191 value
|= inb(regs
.SCMD
);
196 read_aux_stat(const wd33c93_regs regs
)
198 return inb(regs
.SASR
);
202 write_wd33c93(const wd33c93_regs regs
, uchar reg_num
, uchar value
)
204 outb(reg_num
, regs
.SASR
);
205 outb(value
, regs
.SCMD
);
209 write_wd33c93_count(const wd33c93_regs regs
, unsigned long value
)
211 outb(WD_TRANSFER_COUNT_MSB
, regs
.SASR
);
212 outb((value
>> 16) & 0xff, regs
.SCMD
);
213 outb((value
>> 8) & 0xff, regs
.SCMD
);
214 outb( value
& 0xff, regs
.SCMD
);
217 #define write_wd33c93_cmd(regs, cmd) \
218 write_wd33c93((regs), WD_COMMAND, (cmd))
221 write_wd33c93_cdb(const wd33c93_regs regs
, uint len
, uchar cmnd
[])
225 outb(WD_CDB_1
, regs
.SASR
);
226 for (i
=0; i
<len
; i
++)
227 outb(cmnd
[i
], regs
.SCMD
);
230 #else /* CONFIG_WD33C93_PIO */
232 read_wd33c93(const wd33c93_regs regs
, uchar reg_num
)
234 *regs
.SASR
= reg_num
;
240 read_wd33c93_count(const wd33c93_regs regs
)
244 *regs
.SASR
= WD_TRANSFER_COUNT_MSB
;
246 value
= *regs
.SCMD
<< 16;
247 value
|= *regs
.SCMD
<< 8;
254 read_aux_stat(const wd33c93_regs regs
)
260 write_wd33c93(const wd33c93_regs regs
, uchar reg_num
, uchar value
)
262 *regs
.SASR
= reg_num
;
269 write_wd33c93_count(const wd33c93_regs regs
, unsigned long value
)
271 *regs
.SASR
= WD_TRANSFER_COUNT_MSB
;
273 *regs
.SCMD
= value
>> 16;
274 *regs
.SCMD
= value
>> 8;
280 write_wd33c93_cmd(const wd33c93_regs regs
, uchar cmd
)
282 *regs
.SASR
= WD_COMMAND
;
289 write_wd33c93_cdb(const wd33c93_regs regs
, uint len
, uchar cmnd
[])
293 *regs
.SASR
= WD_CDB_1
;
294 for (i
= 0; i
< len
; i
++)
295 *regs
.SCMD
= cmnd
[i
];
297 #endif /* CONFIG_WD33C93_PIO */
300 read_1_byte(const wd33c93_regs regs
)
305 write_wd33c93(regs
, WD_CONTROL
, CTRL_IDI
| CTRL_EDI
| CTRL_POLLED
);
306 write_wd33c93_cmd(regs
, WD_CMD_TRANS_INFO
| 0x80);
308 asr
= read_aux_stat(regs
);
310 x
= read_wd33c93(regs
, WD_DATA
);
311 } while (!(asr
& ASR_INT
));
316 round_period(unsigned int period
, const struct sx_period
*sx_table
)
320 for (x
= 1; sx_table
[x
].period_ns
; x
++) {
321 if ((period
<= sx_table
[x
- 0].period_ns
) &&
322 (period
> sx_table
[x
- 1].period_ns
)) {
330 * Calculate Synchronous Transfer Register value from SDTR code.
333 calc_sync_xfer(unsigned int period
, unsigned int offset
, unsigned int fast
,
334 const struct sx_period
*sx_table
)
336 /* When doing Fast SCSI synchronous data transfers, the corresponding
337 * value in 'sx_table' is two times the actually used transfer period.
341 if (offset
&& fast
) {
347 period
*= 4; /* convert SDTR code to ns */
348 result
= sx_table
[round_period(period
,sx_table
)].reg_value
;
349 result
|= (offset
< OPTIMUM_SX_OFF
) ? offset
: OPTIMUM_SX_OFF
;
355 * Calculate SDTR code bytes [3],[4] from period and offset.
358 calc_sync_msg(unsigned int period
, unsigned int offset
, unsigned int fast
,
361 /* 'period' is a "normal"-mode value, like the ones in 'sx_table'. The
362 * actually used transfer period for Fast SCSI synchronous data
363 * transfers is half that value.
373 wd33c93_queuecommand(struct scsi_cmnd
*cmd
,
374 void (*done
)(struct scsi_cmnd
*))
376 struct WD33C93_hostdata
*hostdata
;
377 struct scsi_cmnd
*tmp
;
379 hostdata
= (struct WD33C93_hostdata
*) cmd
->device
->host
->hostdata
;
382 printk("Q-%d-%02x-%ld( ", cmd
->device
->id
, cmd
->cmnd
[0], cmd
->pid
))
384 /* Set up a few fields in the scsi_cmnd structure for our own use:
385 * - host_scribble is the pointer to the next cmd in the input queue
386 * - scsi_done points to the routine we call when a cmd is finished
387 * - result is what you'd expect
389 cmd
->host_scribble
= NULL
;
390 cmd
->scsi_done
= done
;
393 /* We use the Scsi_Pointer structure that's included with each command
394 * as a scratchpad (as it's intended to be used!). The handy thing about
395 * the SCp.xxx fields is that they're always associated with a given
396 * cmd, and are preserved across disconnect-reselect. This means we
397 * can pretty much ignore SAVE_POINTERS and RESTORE_POINTERS messages
398 * if we keep all the critical pointers and counters in SCp:
399 * - SCp.ptr is the pointer into the RAM buffer
400 * - SCp.this_residual is the size of that buffer
401 * - SCp.buffer points to the current scatter-gather buffer
402 * - SCp.buffers_residual tells us how many S.G. buffers there are
403 * - SCp.have_data_in is not used
404 * - SCp.sent_command is not used
405 * - SCp.phase records this command's SRCID_ER bit setting
409 cmd
->SCp
.buffer
= (struct scatterlist
*) cmd
->request_buffer
;
410 cmd
->SCp
.buffers_residual
= cmd
->use_sg
- 1;
411 cmd
->SCp
.ptr
= page_address(cmd
->SCp
.buffer
->page
) +
412 cmd
->SCp
.buffer
->offset
;
413 cmd
->SCp
.this_residual
= cmd
->SCp
.buffer
->length
;
415 cmd
->SCp
.buffer
= NULL
;
416 cmd
->SCp
.buffers_residual
= 0;
417 cmd
->SCp
.ptr
= (char *) cmd
->request_buffer
;
418 cmd
->SCp
.this_residual
= cmd
->request_bufflen
;
421 /* WD docs state that at the conclusion of a "LEVEL2" command, the
422 * status byte can be retrieved from the LUN register. Apparently,
423 * this is the case only for *uninterrupted* LEVEL2 commands! If
424 * there are any unexpected phases entered, even if they are 100%
425 * legal (different devices may choose to do things differently),
426 * the LEVEL2 command sequence is exited. This often occurs prior
427 * to receiving the status byte, in which case the driver does a
428 * status phase interrupt and gets the status byte on its own.
429 * While such a command can then be "resumed" (ie restarted to
430 * finish up as a LEVEL2 command), the LUN register will NOT be
431 * a valid status byte at the command's conclusion, and we must
432 * use the byte obtained during the earlier interrupt. Here, we
433 * preset SCp.Status to an illegal value (0xff) so that when
434 * this command finally completes, we can tell where the actual
435 * status byte is stored.
438 cmd
->SCp
.Status
= ILLEGAL_STATUS_BYTE
;
441 * Add the cmd to the end of 'input_Q'. Note that REQUEST SENSE
442 * commands are added to the head of the queue so that the desired
443 * sense data is not lost before REQUEST_SENSE executes.
446 spin_lock_irq(&hostdata
->lock
);
448 if (!(hostdata
->input_Q
) || (cmd
->cmnd
[0] == REQUEST_SENSE
)) {
449 cmd
->host_scribble
= (uchar
*) hostdata
->input_Q
;
450 hostdata
->input_Q
= cmd
;
451 } else { /* find the end of the queue */
452 for (tmp
= (struct scsi_cmnd
*) hostdata
->input_Q
;
454 tmp
= (struct scsi_cmnd
*) tmp
->host_scribble
) ;
455 tmp
->host_scribble
= (uchar
*) cmd
;
458 /* We know that there's at least one command in 'input_Q' now.
459 * Go see if any of them are runnable!
462 wd33c93_execute(cmd
->device
->host
);
464 DB(DB_QUEUE_COMMAND
, printk(")Q-%ld ", cmd
->pid
))
466 spin_unlock_irq(&hostdata
->lock
);
471 * This routine attempts to start a scsi command. If the host_card is
472 * already connected, we give up immediately. Otherwise, look through
473 * the input_Q, using the first command we find that's intended
474 * for a currently non-busy target/lun.
476 * wd33c93_execute() is always called with interrupts disabled or from
477 * the wd33c93_intr itself, which means that a wd33c93 interrupt
478 * cannot occur while we are in here.
481 wd33c93_execute(struct Scsi_Host
*instance
)
483 struct WD33C93_hostdata
*hostdata
=
484 (struct WD33C93_hostdata
*) instance
->hostdata
;
485 const wd33c93_regs regs
= hostdata
->regs
;
486 struct scsi_cmnd
*cmd
, *prev
;
488 DB(DB_EXECUTE
, printk("EX("))
489 if (hostdata
->selecting
|| hostdata
->connected
) {
490 DB(DB_EXECUTE
, printk(")EX-0 "))
495 * Search through the input_Q for a command destined
496 * for an idle target/lun.
499 cmd
= (struct scsi_cmnd
*) hostdata
->input_Q
;
502 if (!(hostdata
->busy
[cmd
->device
->id
] & (1 << cmd
->device
->lun
)))
505 cmd
= (struct scsi_cmnd
*) cmd
->host_scribble
;
508 /* quit if queue empty or all possible targets are busy */
511 DB(DB_EXECUTE
, printk(")EX-1 "))
515 /* remove command from queue */
518 prev
->host_scribble
= cmd
->host_scribble
;
520 hostdata
->input_Q
= (struct scsi_cmnd
*) cmd
->host_scribble
;
522 #ifdef PROC_STATISTICS
523 hostdata
->cmd_cnt
[cmd
->device
->id
]++;
527 * Start the selection process
530 if (cmd
->sc_data_direction
== DMA_TO_DEVICE
)
531 write_wd33c93(regs
, WD_DESTINATION_ID
, cmd
->device
->id
);
533 write_wd33c93(regs
, WD_DESTINATION_ID
, cmd
->device
->id
| DSTID_DPD
);
535 /* Now we need to figure out whether or not this command is a good
536 * candidate for disconnect/reselect. We guess to the best of our
537 * ability, based on a set of hierarchical rules. When several
538 * devices are operating simultaneously, disconnects are usually
539 * an advantage. In a single device system, or if only 1 device
540 * is being accessed, transfers usually go faster if disconnects
543 * + Commands should NEVER disconnect if hostdata->disconnect =
544 * DIS_NEVER (this holds for tape drives also), and ALWAYS
545 * disconnect if hostdata->disconnect = DIS_ALWAYS.
546 * + Tape drive commands should always be allowed to disconnect.
547 * + Disconnect should be allowed if disconnected_Q isn't empty.
548 * + Commands should NOT disconnect if input_Q is empty.
549 * + Disconnect should be allowed if there are commands in input_Q
550 * for a different target/lun. In this case, the other commands
551 * should be made disconnect-able, if not already.
553 * I know, I know - this code would flunk me out of any
554 * "C Programming 101" class ever offered. But it's easy
555 * to change around and experiment with for now.
558 cmd
->SCp
.phase
= 0; /* assume no disconnect */
559 if (hostdata
->disconnect
== DIS_NEVER
)
561 if (hostdata
->disconnect
== DIS_ALWAYS
)
563 if (cmd
->device
->type
== 1) /* tape drive? */
565 if (hostdata
->disconnected_Q
) /* other commands disconnected? */
567 if (!(hostdata
->input_Q
)) /* input_Q empty? */
569 for (prev
= (struct scsi_cmnd
*) hostdata
->input_Q
; prev
;
570 prev
= (struct scsi_cmnd
*) prev
->host_scribble
) {
571 if ((prev
->device
->id
!= cmd
->device
->id
) ||
572 (prev
->device
->lun
!= cmd
->device
->lun
)) {
573 for (prev
= (struct scsi_cmnd
*) hostdata
->input_Q
; prev
;
574 prev
= (struct scsi_cmnd
*) prev
->host_scribble
)
585 #ifdef PROC_STATISTICS
586 hostdata
->disc_allowed_cnt
[cmd
->device
->id
]++;
591 write_wd33c93(regs
, WD_SOURCE_ID
, ((cmd
->SCp
.phase
) ? SRCID_ER
: 0));
593 write_wd33c93(regs
, WD_TARGET_LUN
, cmd
->device
->lun
);
594 write_wd33c93(regs
, WD_SYNCHRONOUS_TRANSFER
,
595 hostdata
->sync_xfer
[cmd
->device
->id
]);
596 hostdata
->busy
[cmd
->device
->id
] |= (1 << cmd
->device
->lun
);
598 if ((hostdata
->level2
== L2_NONE
) ||
599 (hostdata
->sync_stat
[cmd
->device
->id
] == SS_UNSET
)) {
602 * Do a 'Select-With-ATN' command. This will end with
603 * one of the following interrupts:
604 * CSR_RESEL_AM: failure - can try again later.
605 * CSR_TIMEOUT: failure - give up.
606 * CSR_SELECT: success - proceed.
609 hostdata
->selecting
= cmd
;
611 /* Every target has its own synchronous transfer setting, kept in the
612 * sync_xfer array, and a corresponding status byte in sync_stat[].
613 * Each target's sync_stat[] entry is initialized to SX_UNSET, and its
614 * sync_xfer[] entry is initialized to the default/safe value. SS_UNSET
615 * means that the parameters are undetermined as yet, and that we
616 * need to send an SDTR message to this device after selection is
617 * complete: We set SS_FIRST to tell the interrupt routine to do so.
618 * If we've been asked not to try synchronous transfers on this
619 * target (and _all_ luns within it), we'll still send the SDTR message
620 * later, but at that time we'll negotiate for async by specifying a
621 * sync fifo depth of 0.
623 if (hostdata
->sync_stat
[cmd
->device
->id
] == SS_UNSET
)
624 hostdata
->sync_stat
[cmd
->device
->id
] = SS_FIRST
;
625 hostdata
->state
= S_SELECTING
;
626 write_wd33c93_count(regs
, 0); /* guarantee a DATA_PHASE interrupt */
627 write_wd33c93_cmd(regs
, WD_CMD_SEL_ATN
);
631 * Do a 'Select-With-ATN-Xfer' command. This will end with
632 * one of the following interrupts:
633 * CSR_RESEL_AM: failure - can try again later.
634 * CSR_TIMEOUT: failure - give up.
635 * anything else: success - proceed.
638 hostdata
->connected
= cmd
;
639 write_wd33c93(regs
, WD_COMMAND_PHASE
, 0);
641 /* copy command_descriptor_block into WD chip
642 * (take advantage of auto-incrementing)
645 write_wd33c93_cdb(regs
, cmd
->cmd_len
, cmd
->cmnd
);
647 /* The wd33c93 only knows about Group 0, 1, and 5 commands when
648 * it's doing a 'select-and-transfer'. To be safe, we write the
649 * size of the CDB into the OWN_ID register for every case. This
650 * way there won't be problems with vendor-unique, audio, etc.
653 write_wd33c93(regs
, WD_OWN_ID
, cmd
->cmd_len
);
655 /* When doing a non-disconnect command with DMA, we can save
656 * ourselves a DATA phase interrupt later by setting everything
660 if ((cmd
->SCp
.phase
== 0) && (hostdata
->no_dma
== 0)) {
661 if (hostdata
->dma_setup(cmd
,
662 (cmd
->sc_data_direction
== DMA_TO_DEVICE
) ?
663 DATA_OUT_DIR
: DATA_IN_DIR
))
664 write_wd33c93_count(regs
, 0); /* guarantee a DATA_PHASE interrupt */
666 write_wd33c93_count(regs
,
667 cmd
->SCp
.this_residual
);
668 write_wd33c93(regs
, WD_CONTROL
,
669 CTRL_IDI
| CTRL_EDI
| hostdata
->dma_mode
);
670 hostdata
->dma
= D_DMA_RUNNING
;
673 write_wd33c93_count(regs
, 0); /* guarantee a DATA_PHASE interrupt */
675 hostdata
->state
= S_RUNNING_LEVEL2
;
676 write_wd33c93_cmd(regs
, WD_CMD_SEL_ATN_XFER
);
680 * Since the SCSI bus can handle only 1 connection at a time,
681 * we get out of here now. If the selection fails, or when
682 * the command disconnects, we'll come back to this routine
683 * to search the input_Q again...
687 printk("%s%ld)EX-2 ", (cmd
->SCp
.phase
) ? "d:" : "", cmd
->pid
))
691 transfer_pio(const wd33c93_regs regs
, uchar
* buf
, int cnt
,
692 int data_in_dir
, struct WD33C93_hostdata
*hostdata
)
697 printk("(%p,%d,%s:", buf
, cnt
, data_in_dir
? "in" : "out"))
699 write_wd33c93(regs
, WD_CONTROL
, CTRL_IDI
| CTRL_EDI
| CTRL_POLLED
);
700 write_wd33c93_count(regs
, cnt
);
701 write_wd33c93_cmd(regs
, WD_CMD_TRANS_INFO
);
704 asr
= read_aux_stat(regs
);
706 *buf
++ = read_wd33c93(regs
, WD_DATA
);
707 } while (!(asr
& ASR_INT
));
710 asr
= read_aux_stat(regs
);
712 write_wd33c93(regs
, WD_DATA
, *buf
++);
713 } while (!(asr
& ASR_INT
));
716 /* Note: we are returning with the interrupt UN-cleared.
717 * Since (presumably) an entire I/O operation has
718 * completed, the bus phase is probably different, and
719 * the interrupt routine will discover this when it
720 * responds to the uncleared int.
726 transfer_bytes(const wd33c93_regs regs
, struct scsi_cmnd
*cmd
,
729 struct WD33C93_hostdata
*hostdata
;
730 unsigned long length
;
732 hostdata
= (struct WD33C93_hostdata
*) cmd
->device
->host
->hostdata
;
734 /* Normally, you'd expect 'this_residual' to be non-zero here.
735 * In a series of scatter-gather transfers, however, this
736 * routine will usually be called with 'this_residual' equal
737 * to 0 and 'buffers_residual' non-zero. This means that a
738 * previous transfer completed, clearing 'this_residual', and
739 * now we need to setup the next scatter-gather buffer as the
740 * source or destination for THIS transfer.
742 if (!cmd
->SCp
.this_residual
&& cmd
->SCp
.buffers_residual
) {
744 --cmd
->SCp
.buffers_residual
;
745 cmd
->SCp
.this_residual
= cmd
->SCp
.buffer
->length
;
746 cmd
->SCp
.ptr
= page_address(cmd
->SCp
.buffer
->page
) +
747 cmd
->SCp
.buffer
->offset
;
749 if (!cmd
->SCp
.this_residual
) /* avoid bogus setups */
752 write_wd33c93(regs
, WD_SYNCHRONOUS_TRANSFER
,
753 hostdata
->sync_xfer
[cmd
->device
->id
]);
755 /* 'hostdata->no_dma' is TRUE if we don't even want to try DMA.
756 * Update 'this_residual' and 'ptr' after 'transfer_pio()' returns.
759 if (hostdata
->no_dma
|| hostdata
->dma_setup(cmd
, data_in_dir
)) {
760 #ifdef PROC_STATISTICS
763 transfer_pio(regs
, (uchar
*) cmd
->SCp
.ptr
,
764 cmd
->SCp
.this_residual
, data_in_dir
, hostdata
);
765 length
= cmd
->SCp
.this_residual
;
766 cmd
->SCp
.this_residual
= read_wd33c93_count(regs
);
767 cmd
->SCp
.ptr
+= (length
- cmd
->SCp
.this_residual
);
770 /* We are able to do DMA (in fact, the Amiga hardware is
771 * already going!), so start up the wd33c93 in DMA mode.
772 * We set 'hostdata->dma' = D_DMA_RUNNING so that when the
773 * transfer completes and causes an interrupt, we're
774 * reminded to tell the Amiga to shut down its end. We'll
775 * postpone the updating of 'this_residual' and 'ptr'
780 #ifdef PROC_STATISTICS
783 write_wd33c93(regs
, WD_CONTROL
, CTRL_IDI
| CTRL_EDI
| hostdata
->dma_mode
);
784 write_wd33c93_count(regs
, cmd
->SCp
.this_residual
);
786 if ((hostdata
->level2
>= L2_DATA
) ||
787 (hostdata
->level2
== L2_BASIC
&& cmd
->SCp
.phase
== 0)) {
788 write_wd33c93(regs
, WD_COMMAND_PHASE
, 0x45);
789 write_wd33c93_cmd(regs
, WD_CMD_SEL_ATN_XFER
);
790 hostdata
->state
= S_RUNNING_LEVEL2
;
792 write_wd33c93_cmd(regs
, WD_CMD_TRANS_INFO
);
794 hostdata
->dma
= D_DMA_RUNNING
;
799 wd33c93_intr(struct Scsi_Host
*instance
)
801 struct WD33C93_hostdata
*hostdata
=
802 (struct WD33C93_hostdata
*) instance
->hostdata
;
803 const wd33c93_regs regs
= hostdata
->regs
;
804 struct scsi_cmnd
*patch
, *cmd
;
805 uchar asr
, sr
, phs
, id
, lun
, *ucp
, msg
;
806 unsigned long length
, flags
;
808 asr
= read_aux_stat(regs
);
809 if (!(asr
& ASR_INT
) || (asr
& ASR_BSY
))
812 spin_lock_irqsave(&hostdata
->lock
, flags
);
814 #ifdef PROC_STATISTICS
818 cmd
= (struct scsi_cmnd
*) hostdata
->connected
; /* assume we're connected */
819 sr
= read_wd33c93(regs
, WD_SCSI_STATUS
); /* clear the interrupt */
820 phs
= read_wd33c93(regs
, WD_COMMAND_PHASE
);
822 DB(DB_INTR
, printk("{%02x:%02x-", asr
, sr
))
824 /* After starting a DMA transfer, the next interrupt
825 * is guaranteed to be in response to completion of
826 * the transfer. Since the Amiga DMA hardware runs in
827 * in an open-ended fashion, it needs to be told when
828 * to stop; do that here if D_DMA_RUNNING is true.
829 * Also, we have to update 'this_residual' and 'ptr'
830 * based on the contents of the TRANSFER_COUNT register,
831 * in case the device decided to do an intermediate
832 * disconnect (a device may do this if it has to do a
833 * seek, or just to be nice and let other devices have
834 * some bus time during long transfers). After doing
835 * whatever is needed, we go on and service the WD3393
836 * interrupt normally.
838 if (hostdata
->dma
== D_DMA_RUNNING
) {
840 printk("[%p/%d:", cmd
->SCp
.ptr
, cmd
->SCp
.this_residual
))
841 hostdata
->dma_stop(cmd
->device
->host
, cmd
, 1);
842 hostdata
->dma
= D_DMA_OFF
;
843 length
= cmd
->SCp
.this_residual
;
844 cmd
->SCp
.this_residual
= read_wd33c93_count(regs
);
845 cmd
->SCp
.ptr
+= (length
- cmd
->SCp
.this_residual
);
847 printk("%p/%d]", cmd
->SCp
.ptr
, cmd
->SCp
.this_residual
))
850 /* Respond to the specific WD3393 interrupt - there are quite a few! */
853 DB(DB_INTR
, printk("TIMEOUT"))
855 if (hostdata
->state
== S_RUNNING_LEVEL2
)
856 hostdata
->connected
= NULL
;
858 cmd
= (struct scsi_cmnd
*) hostdata
->selecting
; /* get a valid cmd */
859 hostdata
->selecting
= NULL
;
862 cmd
->result
= DID_NO_CONNECT
<< 16;
863 hostdata
->busy
[cmd
->device
->id
] &= ~(1 << cmd
->device
->lun
);
864 hostdata
->state
= S_UNCONNECTED
;
868 * There is a window of time within the scsi_done() path
869 * of execution where interrupts are turned back on full
870 * blast and left that way. During that time we could
871 * reconnect to a disconnected command, then we'd bomb
872 * out below. We could also end up executing two commands
873 * at _once_. ...just so you know why the restore_flags()
877 spin_unlock_irqrestore(&hostdata
->lock
, flags
);
879 /* We are not connected to a target - check to see if there
880 * are commands waiting to be executed.
883 wd33c93_execute(instance
);
886 /* Note: this interrupt should not occur in a LEVEL2 command */
889 DB(DB_INTR
, printk("SELECT"))
890 hostdata
->connected
= cmd
=
891 (struct scsi_cmnd
*) hostdata
->selecting
;
892 hostdata
->selecting
= NULL
;
894 /* construct an IDENTIFY message with correct disconnect bit */
896 hostdata
->outgoing_msg
[0] = (0x80 | 0x00 | cmd
->device
->lun
);
898 hostdata
->outgoing_msg
[0] |= 0x40;
900 if (hostdata
->sync_stat
[cmd
->device
->id
] == SS_FIRST
) {
902 hostdata
->sync_stat
[cmd
->device
->id
] = SS_WAITING
;
904 /* Tack on a 2nd message to ask about synchronous transfers. If we've
905 * been asked to do only asynchronous transfers on this device, we
906 * request a fifo depth of 0, which is equivalent to async - should
907 * solve the problems some people have had with GVP's Guru ROM.
910 hostdata
->outgoing_msg
[1] = EXTENDED_MESSAGE
;
911 hostdata
->outgoing_msg
[2] = 3;
912 hostdata
->outgoing_msg
[3] = EXTENDED_SDTR
;
913 if (hostdata
->no_sync
& (1 << cmd
->device
->id
)) {
914 calc_sync_msg(hostdata
->default_sx_per
, 0,
915 0, hostdata
->outgoing_msg
+ 4);
917 calc_sync_msg(optimum_sx_per(hostdata
),
920 hostdata
->outgoing_msg
+ 4);
922 hostdata
->outgoing_len
= 6;
924 ucp
= hostdata
->outgoing_msg
+ 1;
925 printk(" sending SDTR %02x03%02x%02x%02x ",
926 ucp
[0], ucp
[2], ucp
[3], ucp
[4]);
929 hostdata
->outgoing_len
= 1;
931 hostdata
->state
= S_CONNECTED
;
932 spin_unlock_irqrestore(&hostdata
->lock
, flags
);
935 case CSR_XFER_DONE
| PHS_DATA_IN
:
936 case CSR_UNEXP
| PHS_DATA_IN
:
937 case CSR_SRV_REQ
| PHS_DATA_IN
:
939 printk("IN-%d.%d", cmd
->SCp
.this_residual
,
940 cmd
->SCp
.buffers_residual
))
941 transfer_bytes(regs
, cmd
, DATA_IN_DIR
);
942 if (hostdata
->state
!= S_RUNNING_LEVEL2
)
943 hostdata
->state
= S_CONNECTED
;
944 spin_unlock_irqrestore(&hostdata
->lock
, flags
);
947 case CSR_XFER_DONE
| PHS_DATA_OUT
:
948 case CSR_UNEXP
| PHS_DATA_OUT
:
949 case CSR_SRV_REQ
| PHS_DATA_OUT
:
951 printk("OUT-%d.%d", cmd
->SCp
.this_residual
,
952 cmd
->SCp
.buffers_residual
))
953 transfer_bytes(regs
, cmd
, DATA_OUT_DIR
);
954 if (hostdata
->state
!= S_RUNNING_LEVEL2
)
955 hostdata
->state
= S_CONNECTED
;
956 spin_unlock_irqrestore(&hostdata
->lock
, flags
);
959 /* Note: this interrupt should not occur in a LEVEL2 command */
961 case CSR_XFER_DONE
| PHS_COMMAND
:
962 case CSR_UNEXP
| PHS_COMMAND
:
963 case CSR_SRV_REQ
| PHS_COMMAND
:
964 DB(DB_INTR
, printk("CMND-%02x,%ld", cmd
->cmnd
[0], cmd
->pid
))
965 transfer_pio(regs
, cmd
->cmnd
, cmd
->cmd_len
, DATA_OUT_DIR
,
967 hostdata
->state
= S_CONNECTED
;
968 spin_unlock_irqrestore(&hostdata
->lock
, flags
);
971 case CSR_XFER_DONE
| PHS_STATUS
:
972 case CSR_UNEXP
| PHS_STATUS
:
973 case CSR_SRV_REQ
| PHS_STATUS
:
974 DB(DB_INTR
, printk("STATUS="))
975 cmd
->SCp
.Status
= read_1_byte(regs
);
976 DB(DB_INTR
, printk("%02x", cmd
->SCp
.Status
))
977 if (hostdata
->level2
>= L2_BASIC
) {
978 sr
= read_wd33c93(regs
, WD_SCSI_STATUS
); /* clear interrupt */
980 hostdata
->state
= S_RUNNING_LEVEL2
;
981 write_wd33c93(regs
, WD_COMMAND_PHASE
, 0x50);
982 write_wd33c93_cmd(regs
, WD_CMD_SEL_ATN_XFER
);
984 hostdata
->state
= S_CONNECTED
;
986 spin_unlock_irqrestore(&hostdata
->lock
, flags
);
989 case CSR_XFER_DONE
| PHS_MESS_IN
:
990 case CSR_UNEXP
| PHS_MESS_IN
:
991 case CSR_SRV_REQ
| PHS_MESS_IN
:
992 DB(DB_INTR
, printk("MSG_IN="))
994 msg
= read_1_byte(regs
);
995 sr
= read_wd33c93(regs
, WD_SCSI_STATUS
); /* clear interrupt */
998 hostdata
->incoming_msg
[hostdata
->incoming_ptr
] = msg
;
999 if (hostdata
->incoming_msg
[0] == EXTENDED_MESSAGE
)
1000 msg
= EXTENDED_MESSAGE
;
1002 hostdata
->incoming_ptr
= 0;
1004 cmd
->SCp
.Message
= msg
;
1007 case COMMAND_COMPLETE
:
1008 DB(DB_INTR
, printk("CCMP-%ld", cmd
->pid
))
1009 write_wd33c93_cmd(regs
, WD_CMD_NEGATE_ACK
);
1010 hostdata
->state
= S_PRE_CMP_DISC
;
1014 DB(DB_INTR
, printk("SDP"))
1015 write_wd33c93_cmd(regs
, WD_CMD_NEGATE_ACK
);
1016 hostdata
->state
= S_CONNECTED
;
1019 case RESTORE_POINTERS
:
1020 DB(DB_INTR
, printk("RDP"))
1021 if (hostdata
->level2
>= L2_BASIC
) {
1022 write_wd33c93(regs
, WD_COMMAND_PHASE
, 0x45);
1023 write_wd33c93_cmd(regs
, WD_CMD_SEL_ATN_XFER
);
1024 hostdata
->state
= S_RUNNING_LEVEL2
;
1026 write_wd33c93_cmd(regs
, WD_CMD_NEGATE_ACK
);
1027 hostdata
->state
= S_CONNECTED
;
1032 DB(DB_INTR
, printk("DIS"))
1033 cmd
->device
->disconnect
= 1;
1034 write_wd33c93_cmd(regs
, WD_CMD_NEGATE_ACK
);
1035 hostdata
->state
= S_PRE_TMP_DISC
;
1038 case MESSAGE_REJECT
:
1039 DB(DB_INTR
, printk("REJ"))
1043 if (hostdata
->sync_stat
[cmd
->device
->id
] == SS_WAITING
) {
1044 hostdata
->sync_stat
[cmd
->device
->id
] = SS_SET
;
1045 /* we want default_sx_per, not DEFAULT_SX_PER */
1046 hostdata
->sync_xfer
[cmd
->device
->id
] =
1047 calc_sync_xfer(hostdata
->default_sx_per
1048 / 4, 0, 0, hostdata
->sx_table
);
1050 write_wd33c93_cmd(regs
, WD_CMD_NEGATE_ACK
);
1051 hostdata
->state
= S_CONNECTED
;
1054 case EXTENDED_MESSAGE
:
1055 DB(DB_INTR
, printk("EXT"))
1057 ucp
= hostdata
->incoming_msg
;
1060 printk("%02x", ucp
[hostdata
->incoming_ptr
]);
1062 /* Is this the last byte of the extended message? */
1064 if ((hostdata
->incoming_ptr
>= 2) &&
1065 (hostdata
->incoming_ptr
== (ucp
[1] + 1))) {
1067 switch (ucp
[2]) { /* what's the EXTENDED code? */
1069 /* default to default async period */
1070 id
= calc_sync_xfer(hostdata
->
1071 default_sx_per
/ 4, 0,
1072 0, hostdata
->sx_table
);
1073 if (hostdata
->sync_stat
[cmd
->device
->id
] !=
1076 /* A device has sent an unsolicited SDTR message; rather than go
1077 * through the effort of decoding it and then figuring out what
1078 * our reply should be, we're just gonna say that we have a
1079 * synchronous fifo depth of 0. This will result in asynchronous
1080 * transfers - not ideal but so much easier.
1081 * Actually, this is OK because it assures us that if we don't
1082 * specifically ask for sync transfers, we won't do any.
1085 write_wd33c93_cmd(regs
, WD_CMD_ASSERT_ATN
); /* want MESS_OUT */
1086 hostdata
->outgoing_msg
[0] =
1088 hostdata
->outgoing_msg
[1] = 3;
1089 hostdata
->outgoing_msg
[2] =
1091 calc_sync_msg(hostdata
->
1093 0, hostdata
->outgoing_msg
+ 3);
1094 hostdata
->outgoing_len
= 5;
1096 if (ucp
[4]) /* well, sync transfer */
1097 id
= calc_sync_xfer(ucp
[3], ucp
[4],
1099 hostdata
->sx_table
);
1100 else if (ucp
[3]) /* very unlikely... */
1101 id
= calc_sync_xfer(ucp
[3], ucp
[4],
1102 0, hostdata
->sx_table
);
1104 hostdata
->sync_xfer
[cmd
->device
->id
] = id
;
1106 printk(" sync_xfer=%02x\n",
1107 hostdata
->sync_xfer
[cmd
->device
->id
]);
1109 hostdata
->sync_stat
[cmd
->device
->id
] =
1111 write_wd33c93_cmd(regs
,
1113 hostdata
->state
= S_CONNECTED
;
1116 write_wd33c93_cmd(regs
, WD_CMD_ASSERT_ATN
); /* want MESS_OUT */
1117 printk("sending WDTR ");
1118 hostdata
->outgoing_msg
[0] =
1120 hostdata
->outgoing_msg
[1] = 2;
1121 hostdata
->outgoing_msg
[2] =
1123 hostdata
->outgoing_msg
[3] = 0; /* 8 bit transfer width */
1124 hostdata
->outgoing_len
= 4;
1125 write_wd33c93_cmd(regs
,
1127 hostdata
->state
= S_CONNECTED
;
1130 write_wd33c93_cmd(regs
, WD_CMD_ASSERT_ATN
); /* want MESS_OUT */
1132 ("Rejecting Unknown Extended Message(%02x). ",
1134 hostdata
->outgoing_msg
[0] =
1136 hostdata
->outgoing_len
= 1;
1137 write_wd33c93_cmd(regs
,
1139 hostdata
->state
= S_CONNECTED
;
1142 hostdata
->incoming_ptr
= 0;
1145 /* We need to read more MESS_IN bytes for the extended message */
1148 hostdata
->incoming_ptr
++;
1149 write_wd33c93_cmd(regs
, WD_CMD_NEGATE_ACK
);
1150 hostdata
->state
= S_CONNECTED
;
1155 printk("Rejecting Unknown Message(%02x) ", msg
);
1156 write_wd33c93_cmd(regs
, WD_CMD_ASSERT_ATN
); /* want MESS_OUT */
1157 hostdata
->outgoing_msg
[0] = MESSAGE_REJECT
;
1158 hostdata
->outgoing_len
= 1;
1159 write_wd33c93_cmd(regs
, WD_CMD_NEGATE_ACK
);
1160 hostdata
->state
= S_CONNECTED
;
1162 spin_unlock_irqrestore(&hostdata
->lock
, flags
);
1165 /* Note: this interrupt will occur only after a LEVEL2 command */
1167 case CSR_SEL_XFER_DONE
:
1169 /* Make sure that reselection is enabled at this point - it may
1170 * have been turned off for the command that just completed.
1173 write_wd33c93(regs
, WD_SOURCE_ID
, SRCID_ER
);
1175 DB(DB_INTR
, printk("SX-DONE-%ld", cmd
->pid
))
1176 cmd
->SCp
.Message
= COMMAND_COMPLETE
;
1177 lun
= read_wd33c93(regs
, WD_TARGET_LUN
);
1178 DB(DB_INTR
, printk(":%d.%d", cmd
->SCp
.Status
, lun
))
1179 hostdata
->connected
= NULL
;
1180 hostdata
->busy
[cmd
->device
->id
] &= ~(1 << cmd
->device
->lun
);
1181 hostdata
->state
= S_UNCONNECTED
;
1182 if (cmd
->SCp
.Status
== ILLEGAL_STATUS_BYTE
)
1183 cmd
->SCp
.Status
= lun
;
1184 if (cmd
->cmnd
[0] == REQUEST_SENSE
1185 && cmd
->SCp
.Status
!= GOOD
)
1188 result
& 0x00ffff) | (DID_ERROR
<< 16);
1191 cmd
->SCp
.Status
| (cmd
->SCp
.Message
<< 8);
1192 cmd
->scsi_done(cmd
);
1194 /* We are no longer connected to a target - check to see if
1195 * there are commands waiting to be executed.
1197 spin_unlock_irqrestore(&hostdata
->lock
, flags
);
1198 wd33c93_execute(instance
);
1201 ("%02x:%02x:%02x-%ld: Unknown SEL_XFER_DONE phase!!---",
1202 asr
, sr
, phs
, cmd
->pid
);
1203 spin_unlock_irqrestore(&hostdata
->lock
, flags
);
1207 /* Note: this interrupt will occur only after a LEVEL2 command */
1210 DB(DB_INTR
, printk("SDP"))
1211 hostdata
->state
= S_RUNNING_LEVEL2
;
1212 write_wd33c93(regs
, WD_COMMAND_PHASE
, 0x41);
1213 write_wd33c93_cmd(regs
, WD_CMD_SEL_ATN_XFER
);
1214 spin_unlock_irqrestore(&hostdata
->lock
, flags
);
1217 case CSR_XFER_DONE
| PHS_MESS_OUT
:
1218 case CSR_UNEXP
| PHS_MESS_OUT
:
1219 case CSR_SRV_REQ
| PHS_MESS_OUT
:
1220 DB(DB_INTR
, printk("MSG_OUT="))
1222 /* To get here, we've probably requested MESSAGE_OUT and have
1223 * already put the correct bytes in outgoing_msg[] and filled
1224 * in outgoing_len. We simply send them out to the SCSI bus.
1225 * Sometimes we get MESSAGE_OUT phase when we're not expecting
1226 * it - like when our SDTR message is rejected by a target. Some
1227 * targets send the REJECT before receiving all of the extended
1228 * message, and then seem to go back to MESSAGE_OUT for a byte
1229 * or two. Not sure why, or if I'm doing something wrong to
1230 * cause this to happen. Regardless, it seems that sending
1231 * NOP messages in these situations results in no harm and
1232 * makes everyone happy.
1234 if (hostdata
->outgoing_len
== 0) {
1235 hostdata
->outgoing_len
= 1;
1236 hostdata
->outgoing_msg
[0] = NOP
;
1238 transfer_pio(regs
, hostdata
->outgoing_msg
,
1239 hostdata
->outgoing_len
, DATA_OUT_DIR
, hostdata
);
1240 DB(DB_INTR
, printk("%02x", hostdata
->outgoing_msg
[0]))
1241 hostdata
->outgoing_len
= 0;
1242 hostdata
->state
= S_CONNECTED
;
1243 spin_unlock_irqrestore(&hostdata
->lock
, flags
);
1246 case CSR_UNEXP_DISC
:
1248 /* I think I've seen this after a request-sense that was in response
1249 * to an error condition, but not sure. We certainly need to do
1250 * something when we get this interrupt - the question is 'what?'.
1251 * Let's think positively, and assume some command has finished
1252 * in a legal manner (like a command that provokes a request-sense),
1253 * so we treat it as a normal command-complete-disconnect.
1256 /* Make sure that reselection is enabled at this point - it may
1257 * have been turned off for the command that just completed.
1260 write_wd33c93(regs
, WD_SOURCE_ID
, SRCID_ER
);
1262 printk(" - Already disconnected! ");
1263 hostdata
->state
= S_UNCONNECTED
;
1264 spin_unlock_irqrestore(&hostdata
->lock
, flags
);
1267 DB(DB_INTR
, printk("UNEXP_DISC-%ld", cmd
->pid
))
1268 hostdata
->connected
= NULL
;
1269 hostdata
->busy
[cmd
->device
->id
] &= ~(1 << cmd
->device
->lun
);
1270 hostdata
->state
= S_UNCONNECTED
;
1271 if (cmd
->cmnd
[0] == REQUEST_SENSE
&& cmd
->SCp
.Status
!= GOOD
)
1273 (cmd
->result
& 0x00ffff) | (DID_ERROR
<< 16);
1275 cmd
->result
= cmd
->SCp
.Status
| (cmd
->SCp
.Message
<< 8);
1276 cmd
->scsi_done(cmd
);
1278 /* We are no longer connected to a target - check to see if
1279 * there are commands waiting to be executed.
1281 /* look above for comments on scsi_done() */
1282 spin_unlock_irqrestore(&hostdata
->lock
, flags
);
1283 wd33c93_execute(instance
);
1288 /* Make sure that reselection is enabled at this point - it may
1289 * have been turned off for the command that just completed.
1292 write_wd33c93(regs
, WD_SOURCE_ID
, SRCID_ER
);
1293 DB(DB_INTR
, printk("DISC-%ld", cmd
->pid
))
1295 printk(" - Already disconnected! ");
1296 hostdata
->state
= S_UNCONNECTED
;
1298 switch (hostdata
->state
) {
1299 case S_PRE_CMP_DISC
:
1300 hostdata
->connected
= NULL
;
1301 hostdata
->busy
[cmd
->device
->id
] &= ~(1 << cmd
->device
->lun
);
1302 hostdata
->state
= S_UNCONNECTED
;
1303 DB(DB_INTR
, printk(":%d", cmd
->SCp
.Status
))
1304 if (cmd
->cmnd
[0] == REQUEST_SENSE
1305 && cmd
->SCp
.Status
!= GOOD
)
1308 result
& 0x00ffff) | (DID_ERROR
<< 16);
1311 cmd
->SCp
.Status
| (cmd
->SCp
.Message
<< 8);
1312 cmd
->scsi_done(cmd
);
1314 case S_PRE_TMP_DISC
:
1315 case S_RUNNING_LEVEL2
:
1316 cmd
->host_scribble
= (uchar
*) hostdata
->disconnected_Q
;
1317 hostdata
->disconnected_Q
= cmd
;
1318 hostdata
->connected
= NULL
;
1319 hostdata
->state
= S_UNCONNECTED
;
1321 #ifdef PROC_STATISTICS
1322 hostdata
->disc_done_cnt
[cmd
->device
->id
]++;
1327 printk("*** Unexpected DISCONNECT interrupt! ***");
1328 hostdata
->state
= S_UNCONNECTED
;
1331 /* We are no longer connected to a target - check to see if
1332 * there are commands waiting to be executed.
1334 spin_unlock_irqrestore(&hostdata
->lock
, flags
);
1335 wd33c93_execute(instance
);
1340 DB(DB_INTR
, printk("RESEL%s", sr
== CSR_RESEL_AM
? "_AM" : ""))
1342 /* Old chips (pre -A ???) don't have advanced features and will
1343 * generate CSR_RESEL. In that case we have to extract the LUN the
1344 * hard way (see below).
1345 * First we have to make sure this reselection didn't
1346 * happen during Arbitration/Selection of some other device.
1347 * If yes, put losing command back on top of input_Q.
1349 if (hostdata
->level2
<= L2_NONE
) {
1351 if (hostdata
->selecting
) {
1352 cmd
= (struct scsi_cmnd
*) hostdata
->selecting
;
1353 hostdata
->selecting
= NULL
;
1354 hostdata
->busy
[cmd
->device
->id
] &= ~(1 << cmd
->device
->lun
);
1355 cmd
->host_scribble
=
1356 (uchar
*) hostdata
->input_Q
;
1357 hostdata
->input_Q
= cmd
;
1365 hostdata
->busy
[cmd
->device
->id
] &=
1366 ~(1 << cmd
->device
->lun
);
1367 cmd
->host_scribble
=
1368 (uchar
*) hostdata
->input_Q
;
1369 hostdata
->input_Q
= cmd
;
1372 ("---%02x:%02x:%02x-TROUBLE: Intrusive ReSelect!---",
1381 /* OK - find out which device reselected us. */
1383 id
= read_wd33c93(regs
, WD_SOURCE_ID
);
1386 /* and extract the lun from the ID message. (Note that we don't
1387 * bother to check for a valid message here - I guess this is
1388 * not the right way to go, but...)
1391 if (sr
== CSR_RESEL_AM
) {
1392 lun
= read_wd33c93(regs
, WD_DATA
);
1393 if (hostdata
->level2
< L2_RESELECT
)
1394 write_wd33c93_cmd(regs
, WD_CMD_NEGATE_ACK
);
1397 /* Old chip; wait for msgin phase to pick up the LUN. */
1398 for (lun
= 255; lun
; lun
--) {
1399 if ((asr
= read_aux_stat(regs
)) & ASR_INT
)
1403 if (!(asr
& ASR_INT
)) {
1405 ("wd33c93: Reselected without IDENTIFY\n");
1408 /* Verify this is a change to MSG_IN and read the message */
1409 sr
= read_wd33c93(regs
, WD_SCSI_STATUS
);
1411 if (sr
== (CSR_ABORT
| PHS_MESS_IN
) ||
1412 sr
== (CSR_UNEXP
| PHS_MESS_IN
) ||
1413 sr
== (CSR_SRV_REQ
| PHS_MESS_IN
)) {
1414 /* Got MSG_IN, grab target LUN */
1415 lun
= read_1_byte(regs
);
1416 /* Now we expect a 'paused with ACK asserted' int.. */
1417 asr
= read_aux_stat(regs
);
1418 if (!(asr
& ASR_INT
)) {
1420 asr
= read_aux_stat(regs
);
1421 if (!(asr
& ASR_INT
))
1423 ("wd33c93: No int after LUN on RESEL (%02x)\n",
1426 sr
= read_wd33c93(regs
, WD_SCSI_STATUS
);
1428 if (sr
!= CSR_MSGIN
)
1430 ("wd33c93: Not paused with ACK on RESEL (%02x)\n",
1433 write_wd33c93_cmd(regs
,
1437 ("wd33c93: Not MSG_IN on reselect (%02x)\n",
1444 /* Now we look for the command that's reconnecting. */
1446 cmd
= (struct scsi_cmnd
*) hostdata
->disconnected_Q
;
1449 if (id
== cmd
->device
->id
&& lun
== cmd
->device
->lun
)
1452 cmd
= (struct scsi_cmnd
*) cmd
->host_scribble
;
1455 /* Hmm. Couldn't find a valid command.... What to do? */
1459 ("---TROUBLE: target %d.%d not in disconnect queue---",
1461 spin_unlock_irqrestore(&hostdata
->lock
, flags
);
1465 /* Ok, found the command - now start it up again. */
1468 patch
->host_scribble
= cmd
->host_scribble
;
1470 hostdata
->disconnected_Q
=
1471 (struct scsi_cmnd
*) cmd
->host_scribble
;
1472 hostdata
->connected
= cmd
;
1474 /* We don't need to worry about 'initialize_SCp()' or 'hostdata->busy[]'
1475 * because these things are preserved over a disconnect.
1476 * But we DO need to fix the DPD bit so it's correct for this command.
1479 if (cmd
->sc_data_direction
== DMA_TO_DEVICE
)
1480 write_wd33c93(regs
, WD_DESTINATION_ID
, cmd
->device
->id
);
1482 write_wd33c93(regs
, WD_DESTINATION_ID
,
1483 cmd
->device
->id
| DSTID_DPD
);
1484 if (hostdata
->level2
>= L2_RESELECT
) {
1485 write_wd33c93_count(regs
, 0); /* we want a DATA_PHASE interrupt */
1486 write_wd33c93(regs
, WD_COMMAND_PHASE
, 0x45);
1487 write_wd33c93_cmd(regs
, WD_CMD_SEL_ATN_XFER
);
1488 hostdata
->state
= S_RUNNING_LEVEL2
;
1490 hostdata
->state
= S_CONNECTED
;
1492 DB(DB_INTR
, printk("-%ld", cmd
->pid
))
1493 spin_unlock_irqrestore(&hostdata
->lock
, flags
);
1497 printk("--UNKNOWN INTERRUPT:%02x:%02x:%02x--", asr
, sr
, phs
);
1498 spin_unlock_irqrestore(&hostdata
->lock
, flags
);
1501 DB(DB_INTR
, printk("} "))
1506 reset_wd33c93(struct Scsi_Host
*instance
)
1508 struct WD33C93_hostdata
*hostdata
=
1509 (struct WD33C93_hostdata
*) instance
->hostdata
;
1510 const wd33c93_regs regs
= hostdata
->regs
;
1513 #ifdef CONFIG_SGI_IP22
1516 extern void sgiwd93_reset(unsigned long);
1517 /* wait 'til the chip gets some time for us */
1518 while ((read_aux_stat(regs
) & ASR_BSY
) && busycount
++ < 100)
1521 * there are scsi devices out there, which manage to lock up
1522 * the wd33c93 in a busy condition. In this state it won't
1523 * accept the reset command. The only way to solve this is to
1524 * give the chip a hardware reset (if possible). The code below
1525 * does this for the SGI Indy, where this is possible
1528 if (read_aux_stat(regs
) & ASR_BSY
)
1529 sgiwd93_reset(instance
->base
); /* yeah, give it the hard one */
1533 write_wd33c93(regs
, WD_OWN_ID
, OWNID_EAF
| OWNID_RAF
|
1534 instance
->this_id
| hostdata
->clock_freq
);
1535 write_wd33c93(regs
, WD_CONTROL
, CTRL_IDI
| CTRL_EDI
| CTRL_POLLED
);
1536 write_wd33c93(regs
, WD_SYNCHRONOUS_TRANSFER
,
1537 calc_sync_xfer(hostdata
->default_sx_per
/ 4,
1538 DEFAULT_SX_OFF
, 0, hostdata
->sx_table
));
1539 write_wd33c93(regs
, WD_COMMAND
, WD_CMD_RESET
);
1542 #ifdef CONFIG_MVME147_SCSI
1543 udelay(25); /* The old wd33c93 on MVME147 needs this, at least */
1546 while (!(read_aux_stat(regs
) & ASR_INT
))
1548 sr
= read_wd33c93(regs
, WD_SCSI_STATUS
);
1550 hostdata
->microcode
= read_wd33c93(regs
, WD_CDB_1
);
1552 hostdata
->chip
= C_WD33C93
;
1553 else if (sr
== 0x01) {
1554 write_wd33c93(regs
, WD_QUEUE_TAG
, 0xa5); /* any random number */
1555 sr
= read_wd33c93(regs
, WD_QUEUE_TAG
);
1557 hostdata
->chip
= C_WD33C93B
;
1558 write_wd33c93(regs
, WD_QUEUE_TAG
, 0);
1560 hostdata
->chip
= C_WD33C93A
;
1562 hostdata
->chip
= C_UNKNOWN_CHIP
;
1564 if (hostdata
->chip
!= C_WD33C93B
) /* Fast SCSI unavailable */
1567 write_wd33c93(regs
, WD_TIMEOUT_PERIOD
, TIMEOUT_PERIOD_VALUE
);
1568 write_wd33c93(regs
, WD_CONTROL
, CTRL_IDI
| CTRL_EDI
| CTRL_POLLED
);
1572 wd33c93_host_reset(struct scsi_cmnd
* SCpnt
)
1574 struct Scsi_Host
*instance
;
1575 struct WD33C93_hostdata
*hostdata
;
1578 instance
= SCpnt
->device
->host
;
1579 hostdata
= (struct WD33C93_hostdata
*) instance
->hostdata
;
1581 printk("scsi%d: reset. ", instance
->host_no
);
1582 disable_irq(instance
->irq
);
1584 hostdata
->dma_stop(instance
, NULL
, 0);
1585 for (i
= 0; i
< 8; i
++) {
1586 hostdata
->busy
[i
] = 0;
1587 hostdata
->sync_xfer
[i
] =
1588 calc_sync_xfer(DEFAULT_SX_PER
/ 4, DEFAULT_SX_OFF
,
1589 0, hostdata
->sx_table
);
1590 hostdata
->sync_stat
[i
] = SS_UNSET
; /* using default sync values */
1592 hostdata
->input_Q
= NULL
;
1593 hostdata
->selecting
= NULL
;
1594 hostdata
->connected
= NULL
;
1595 hostdata
->disconnected_Q
= NULL
;
1596 hostdata
->state
= S_UNCONNECTED
;
1597 hostdata
->dma
= D_DMA_OFF
;
1598 hostdata
->incoming_ptr
= 0;
1599 hostdata
->outgoing_len
= 0;
1601 reset_wd33c93(instance
);
1602 SCpnt
->result
= DID_RESET
<< 16;
1603 enable_irq(instance
->irq
);
1608 wd33c93_abort(struct scsi_cmnd
* cmd
)
1610 struct Scsi_Host
*instance
;
1611 struct WD33C93_hostdata
*hostdata
;
1613 struct scsi_cmnd
*tmp
, *prev
;
1615 disable_irq(cmd
->device
->host
->irq
);
1617 instance
= cmd
->device
->host
;
1618 hostdata
= (struct WD33C93_hostdata
*) instance
->hostdata
;
1619 regs
= hostdata
->regs
;
1622 * Case 1 : If the command hasn't been issued yet, we simply remove it
1626 tmp
= (struct scsi_cmnd
*) hostdata
->input_Q
;
1631 prev
->host_scribble
= cmd
->host_scribble
;
1634 (struct scsi_cmnd
*) cmd
->host_scribble
;
1635 cmd
->host_scribble
= NULL
;
1636 cmd
->result
= DID_ABORT
<< 16;
1638 ("scsi%d: Abort - removing command %ld from input_Q. ",
1639 instance
->host_no
, cmd
->pid
);
1640 enable_irq(cmd
->device
->host
->irq
);
1641 cmd
->scsi_done(cmd
);
1645 tmp
= (struct scsi_cmnd
*) tmp
->host_scribble
;
1649 * Case 2 : If the command is connected, we're going to fail the abort
1650 * and let the high level SCSI driver retry at a later time or
1653 * Timeouts, and therefore aborted commands, will be highly unlikely
1654 * and handling them cleanly in this situation would make the common
1655 * case of noresets less efficient, and would pollute our code. So,
1659 if (hostdata
->connected
== cmd
) {
1661 unsigned long timeout
;
1663 printk("scsi%d: Aborting connected command %ld - ",
1664 instance
->host_no
, cmd
->pid
);
1666 printk("stopping DMA - ");
1667 if (hostdata
->dma
== D_DMA_RUNNING
) {
1668 hostdata
->dma_stop(instance
, cmd
, 0);
1669 hostdata
->dma
= D_DMA_OFF
;
1672 printk("sending wd33c93 ABORT command - ");
1673 write_wd33c93(regs
, WD_CONTROL
,
1674 CTRL_IDI
| CTRL_EDI
| CTRL_POLLED
);
1675 write_wd33c93_cmd(regs
, WD_CMD_ABORT
);
1677 /* Now we have to attempt to flush out the FIFO... */
1679 printk("flushing fifo - ");
1682 asr
= read_aux_stat(regs
);
1684 read_wd33c93(regs
, WD_DATA
);
1685 } while (!(asr
& ASR_INT
) && timeout
-- > 0);
1686 sr
= read_wd33c93(regs
, WD_SCSI_STATUS
);
1688 ("asr=%02x, sr=%02x, %ld bytes un-transferred (timeout=%ld) - ",
1689 asr
, sr
, read_wd33c93_count(regs
), timeout
);
1692 * Abort command processed.
1694 * We must disconnect.
1697 printk("sending wd33c93 DISCONNECT command - ");
1698 write_wd33c93_cmd(regs
, WD_CMD_DISCONNECT
);
1701 asr
= read_aux_stat(regs
);
1702 while ((asr
& ASR_CIP
) && timeout
-- > 0)
1703 asr
= read_aux_stat(regs
);
1704 sr
= read_wd33c93(regs
, WD_SCSI_STATUS
);
1705 printk("asr=%02x, sr=%02x.", asr
, sr
);
1707 hostdata
->busy
[cmd
->device
->id
] &= ~(1 << cmd
->device
->lun
);
1708 hostdata
->connected
= NULL
;
1709 hostdata
->state
= S_UNCONNECTED
;
1710 cmd
->result
= DID_ABORT
<< 16;
1713 wd33c93_execute(instance
);
1715 enable_irq(cmd
->device
->host
->irq
);
1716 cmd
->scsi_done(cmd
);
1721 * Case 3: If the command is currently disconnected from the bus,
1722 * we're not going to expend much effort here: Let's just return
1723 * an ABORT_SNOOZE and hope for the best...
1726 tmp
= (struct scsi_cmnd
*) hostdata
->disconnected_Q
;
1730 ("scsi%d: Abort - command %ld found on disconnected_Q - ",
1731 instance
->host_no
, cmd
->pid
);
1732 printk("Abort SNOOZE. ");
1733 enable_irq(cmd
->device
->host
->irq
);
1736 tmp
= (struct scsi_cmnd
*) tmp
->host_scribble
;
1740 * Case 4 : If we reached this point, the command was not found in any of
1743 * We probably reached this point because of an unlikely race condition
1744 * between the command completing successfully and the abortion code,
1745 * so we won't panic, but we will notify the user in case something really
1750 wd33c93_execute(instance
);
1752 enable_irq(cmd
->device
->host
->irq
);
1753 printk("scsi%d: warning : SCSI command probably completed successfully"
1754 " before abortion. ", instance
->host_no
);
1758 #define MAX_WD33C93_HOSTS 4
1759 #define MAX_SETUP_ARGS ARRAY_SIZE(setup_args)
1760 #define SETUP_BUFFER_SIZE 200
1761 static char setup_buffer
[SETUP_BUFFER_SIZE
];
1762 static char setup_used
[MAX_SETUP_ARGS
];
1763 static int done_setup
= 0;
1766 wd33c93_setup(char *str
)
1771 /* The kernel does some processing of the command-line before calling
1772 * this function: If it begins with any decimal or hex number arguments,
1773 * ints[0] = how many numbers found and ints[1] through [n] are the values
1774 * themselves. str points to where the non-numeric arguments (if any)
1775 * start: We do our own parsing of those. We construct synthetic 'nosync'
1776 * keywords out of numeric args (to maintain compatibility with older
1777 * versions) and then add the rest of the arguments.
1783 strncpy(p1
, str
, SETUP_BUFFER_SIZE
- strlen(setup_buffer
));
1784 setup_buffer
[SETUP_BUFFER_SIZE
- 1] = '\0';
1787 while (*p1
&& (i
< MAX_SETUP_ARGS
)) {
1788 p2
= strchr(p1
, ',');
1800 for (i
= 0; i
< MAX_SETUP_ARGS
; i
++)
1806 __setup("wd33c93=", wd33c93_setup
);
1808 /* check_setup_args() returns index if key found, 0 if not
1811 check_setup_args(char *key
, int *flags
, int *val
, char *buf
)
1816 for (x
= 0; x
< MAX_SETUP_ARGS
; x
++) {
1819 if (!strncmp(setup_args
[x
], key
, strlen(key
)))
1821 if (!strncmp(setup_args
[x
], "next", strlen("next")))
1824 if (x
== MAX_SETUP_ARGS
)
1827 cp
= setup_args
[x
] + strlen(key
);
1832 if ((*cp
>= '0') && (*cp
<= '9')) {
1833 *val
= simple_strtoul(cp
, NULL
, 0);
1839 * Calculate internal data-transfer-clock cycle from input-clock
1840 * frequency (/MHz) and fill 'sx_table'.
1842 * The original driver used to rely on a fixed sx_table, containing periods
1843 * for (only) the lower limits of the respective input-clock-frequency ranges
1844 * (8-10/12-15/16-20 MHz). Although it seems, that no problems ocurred with
1845 * this setting so far, it might be desirable to adjust the transfer periods
1846 * closer to the really attached, possibly 25% higher, input-clock, since
1847 * - the wd33c93 may really use a significant shorter period, than it has
1848 * negotiated (eg. thrashing the target, which expects 4/8MHz, with 5/10MHz
1850 * - the wd33c93 may ask the target for a lower transfer rate, than the target
1851 * is capable of (eg. negotiating for an assumed minimum of 252ns instead of
1852 * possible 200ns, which indeed shows up in tests as an approx. 10% lower
1855 static inline unsigned int
1856 round_4(unsigned int x
)
1868 calc_sx_table(unsigned int mhz
, struct sx_period sx_table
[9])
1872 d
= 2; /* divisor for 8-10 MHz input-clock */
1874 d
= 3; /* divisor for 12-15 MHz input-clock */
1876 d
= 4; /* divisor for 16-20 MHz input-clock */
1878 d
= (100000 * d
) / 2 / mhz
; /* 100 x DTCC / nanosec */
1880 sx_table
[0].period_ns
= 1;
1881 sx_table
[0].reg_value
= 0x20;
1882 for (i
= 1; i
< 8; i
++) {
1883 sx_table
[i
].period_ns
= round_4((i
+1)*d
/ 100);
1884 sx_table
[i
].reg_value
= (i
+1)*0x10;
1886 sx_table
[7].reg_value
= 0;
1887 sx_table
[8].period_ns
= 0;
1888 sx_table
[8].reg_value
= 0;
1892 * check and, maybe, map an init- or "clock:"- argument.
1895 set_clk_freq(int freq
, int *mhz
)
1898 if (WD33C93_FS_8_10
== freq
)
1900 else if (WD33C93_FS_12_15
== freq
)
1902 else if (WD33C93_FS_16_20
== freq
)
1904 else if (freq
> 7 && freq
< 11)
1905 x
= WD33C93_FS_8_10
;
1906 else if (freq
> 11 && freq
< 16)
1907 x
= WD33C93_FS_12_15
;
1908 else if (freq
> 15 && freq
< 21)
1909 x
= WD33C93_FS_16_20
;
1911 /* Hmm, wouldn't it be safer to assume highest freq here? */
1912 x
= WD33C93_FS_8_10
;
1920 * to be used with the resync: fast: ... options
1922 static inline void set_resync ( struct WD33C93_hostdata
*hd
, int mask
)
1925 for (i
= 0; i
< 8; i
++)
1926 if (mask
& (1 << i
))
1927 hd
->sync_stat
[i
] = SS_UNSET
;
1931 wd33c93_init(struct Scsi_Host
*instance
, const wd33c93_regs regs
,
1932 dma_setup_t setup
, dma_stop_t stop
, int clock_freq
)
1934 struct WD33C93_hostdata
*hostdata
;
1940 if (!done_setup
&& setup_strings
)
1941 wd33c93_setup(setup_strings
);
1943 hostdata
= (struct WD33C93_hostdata
*) instance
->hostdata
;
1945 hostdata
->regs
= regs
;
1946 hostdata
->clock_freq
= set_clk_freq(clock_freq
, &i
);
1947 calc_sx_table(i
, hostdata
->sx_table
);
1948 hostdata
->dma_setup
= setup
;
1949 hostdata
->dma_stop
= stop
;
1950 hostdata
->dma_bounce_buffer
= NULL
;
1951 hostdata
->dma_bounce_len
= 0;
1952 for (i
= 0; i
< 8; i
++) {
1953 hostdata
->busy
[i
] = 0;
1954 hostdata
->sync_xfer
[i
] =
1955 calc_sync_xfer(DEFAULT_SX_PER
/ 4, DEFAULT_SX_OFF
,
1956 0, hostdata
->sx_table
);
1957 hostdata
->sync_stat
[i
] = SS_UNSET
; /* using default sync values */
1958 #ifdef PROC_STATISTICS
1959 hostdata
->cmd_cnt
[i
] = 0;
1960 hostdata
->disc_allowed_cnt
[i
] = 0;
1961 hostdata
->disc_done_cnt
[i
] = 0;
1964 hostdata
->input_Q
= NULL
;
1965 hostdata
->selecting
= NULL
;
1966 hostdata
->connected
= NULL
;
1967 hostdata
->disconnected_Q
= NULL
;
1968 hostdata
->state
= S_UNCONNECTED
;
1969 hostdata
->dma
= D_DMA_OFF
;
1970 hostdata
->level2
= L2_BASIC
;
1971 hostdata
->disconnect
= DIS_ADAPTIVE
;
1972 hostdata
->args
= DEBUG_DEFAULTS
;
1973 hostdata
->incoming_ptr
= 0;
1974 hostdata
->outgoing_len
= 0;
1975 hostdata
->default_sx_per
= DEFAULT_SX_PER
;
1976 hostdata
->no_sync
= 0xff; /* sync defaults to off */
1977 hostdata
->no_dma
= 0; /* default is DMA enabled */
1978 hostdata
->fast
= 0; /* default is Fast SCSI transfers disabled */
1979 hostdata
->dma_mode
= CTRL_DMA
; /* default is Single Byte DMA */
1981 #ifdef PROC_INTERFACE
1982 hostdata
->proc
= PR_VERSION
| PR_INFO
| PR_STATISTICS
|
1983 PR_CONNECTED
| PR_INPUTQ
| PR_DISCQ
| PR_STOP
;
1984 #ifdef PROC_STATISTICS
1985 hostdata
->dma_cnt
= 0;
1986 hostdata
->pio_cnt
= 0;
1987 hostdata
->int_cnt
= 0;
1991 if (check_setup_args("clock", &flags
, &val
, buf
)) {
1992 hostdata
->clock_freq
= set_clk_freq(val
, &val
);
1993 calc_sx_table(val
, hostdata
->sx_table
);
1996 if (check_setup_args("nosync", &flags
, &val
, buf
))
1997 hostdata
->no_sync
= val
;
1999 if (check_setup_args("nodma", &flags
, &val
, buf
))
2000 hostdata
->no_dma
= (val
== -1) ? 1 : val
;
2002 if (check_setup_args("period", &flags
, &val
, buf
))
2003 hostdata
->default_sx_per
=
2004 hostdata
->sx_table
[round_period((unsigned int) val
,
2005 hostdata
->sx_table
)].period_ns
;
2007 if (check_setup_args("disconnect", &flags
, &val
, buf
)) {
2008 if ((val
>= DIS_NEVER
) && (val
<= DIS_ALWAYS
))
2009 hostdata
->disconnect
= val
;
2011 hostdata
->disconnect
= DIS_ADAPTIVE
;
2014 if (check_setup_args("level2", &flags
, &val
, buf
))
2015 hostdata
->level2
= val
;
2017 if (check_setup_args("debug", &flags
, &val
, buf
))
2018 hostdata
->args
= val
& DB_MASK
;
2020 if (check_setup_args("burst", &flags
, &val
, buf
))
2021 hostdata
->dma_mode
= val
? CTRL_BURST
:CTRL_DMA
;
2023 if (WD33C93_FS_16_20
== hostdata
->clock_freq
/* divisor 4 */
2024 && check_setup_args("fast", &flags
, &val
, buf
))
2025 hostdata
->fast
= !!val
;
2027 if ((i
= check_setup_args("next", &flags
, &val
, buf
))) {
2029 setup_used
[--i
] = 1;
2031 #ifdef PROC_INTERFACE
2032 if (check_setup_args("proc", &flags
, &val
, buf
))
2033 hostdata
->proc
= val
;
2036 spin_lock_irq(&hostdata
->lock
);
2037 reset_wd33c93(instance
);
2038 spin_unlock_irq(&hostdata
->lock
);
2040 printk("wd33c93-%d: chip=%s/%d no_sync=0x%x no_dma=%d",
2042 (hostdata
->chip
== C_WD33C93
) ? "WD33c93" : (hostdata
->chip
==
2044 "WD33c93A" : (hostdata
->chip
==
2045 C_WD33C93B
) ? "WD33c93B" : "unknown",
2046 hostdata
->microcode
, hostdata
->no_sync
, hostdata
->no_dma
);
2048 printk(" debug_flags=0x%02x\n", hostdata
->args
);
2050 printk(" debugging=OFF\n");
2052 printk(" setup_args=");
2053 for (i
= 0; i
< MAX_SETUP_ARGS
; i
++)
2054 printk("%s,", setup_args
[i
]);
2056 printk(" Version %s - %s, Compiled %s at %s\n",
2057 WD33C93_VERSION
, WD33C93_DATE
, __DATE__
, __TIME__
);
2061 wd33c93_proc_info(struct Scsi_Host
*instance
, char *buf
, char **start
, off_t off
, int len
, int in
)
2064 #ifdef PROC_INTERFACE
2068 struct WD33C93_hostdata
*hd
;
2069 struct scsi_cmnd
*cmd
;
2071 static int stop
= 0;
2073 hd
= (struct WD33C93_hostdata
*) instance
->hostdata
;
2075 /* If 'in' is TRUE we need to _read_ the proc file. We accept the following
2076 * keywords (same format as command-line, but arguments are not optional):
2091 for (bp
= buf
; *bp
; ) {
2092 while (',' == *bp
|| ' ' == *bp
)
2094 if (!strncmp(bp
, "debug:", 6)) {
2095 hd
->args
= simple_strtoul(bp
+6, &bp
, 0) & DB_MASK
;
2096 } else if (!strncmp(bp
, "disconnect:", 11)) {
2097 x
= simple_strtoul(bp
+11, &bp
, 0);
2098 if (x
< DIS_NEVER
|| x
> DIS_ALWAYS
)
2101 } else if (!strncmp(bp
, "period:", 7)) {
2102 x
= simple_strtoul(bp
+7, &bp
, 0);
2103 hd
->default_sx_per
=
2104 hd
->sx_table
[round_period((unsigned int) x
,
2105 hd
->sx_table
)].period_ns
;
2106 } else if (!strncmp(bp
, "resync:", 7)) {
2107 set_resync(hd
, (int)simple_strtoul(bp
+7, &bp
, 0));
2108 } else if (!strncmp(bp
, "proc:", 5)) {
2109 hd
->proc
= simple_strtoul(bp
+5, &bp
, 0);
2110 } else if (!strncmp(bp
, "nodma:", 6)) {
2111 hd
->no_dma
= simple_strtoul(bp
+6, &bp
, 0);
2112 } else if (!strncmp(bp
, "level2:", 7)) {
2113 hd
->level2
= simple_strtoul(bp
+7, &bp
, 0);
2114 } else if (!strncmp(bp
, "burst:", 6)) {
2116 simple_strtol(bp
+6, &bp
, 0) ? CTRL_BURST
:CTRL_DMA
;
2117 } else if (!strncmp(bp
, "fast:", 5)) {
2118 x
= !!simple_strtol(bp
+5, &bp
, 0);
2120 set_resync(hd
, 0xff);
2122 } else if (!strncmp(bp
, "nosync:", 7)) {
2123 x
= simple_strtoul(bp
+7, &bp
, 0);
2124 set_resync(hd
, x
^ hd
->no_sync
);
2127 break; /* unknown keyword,syntax-error,... */
2133 spin_lock_irq(&hd
->lock
);
2136 if (hd
->proc
& PR_VERSION
) {
2137 sprintf(tbuf
, "\nVersion %s - %s. Compiled %s %s",
2138 WD33C93_VERSION
, WD33C93_DATE
, __DATE__
, __TIME__
);
2141 if (hd
->proc
& PR_INFO
) {
2142 sprintf(tbuf
, "\nclock_freq=%02x no_sync=%02x no_dma=%d"
2143 " dma_mode=%02x fast=%d",
2144 hd
->clock_freq
, hd
->no_sync
, hd
->no_dma
, hd
->dma_mode
, hd
->fast
);
2146 strcat(bp
, "\nsync_xfer[] = ");
2147 for (x
= 0; x
< 7; x
++) {
2148 sprintf(tbuf
, "\t%02x", hd
->sync_xfer
[x
]);
2151 strcat(bp
, "\nsync_stat[] = ");
2152 for (x
= 0; x
< 7; x
++) {
2153 sprintf(tbuf
, "\t%02x", hd
->sync_stat
[x
]);
2157 #ifdef PROC_STATISTICS
2158 if (hd
->proc
& PR_STATISTICS
) {
2159 strcat(bp
, "\ncommands issued: ");
2160 for (x
= 0; x
< 7; x
++) {
2161 sprintf(tbuf
, "\t%ld", hd
->cmd_cnt
[x
]);
2164 strcat(bp
, "\ndisconnects allowed:");
2165 for (x
= 0; x
< 7; x
++) {
2166 sprintf(tbuf
, "\t%ld", hd
->disc_allowed_cnt
[x
]);
2169 strcat(bp
, "\ndisconnects done: ");
2170 for (x
= 0; x
< 7; x
++) {
2171 sprintf(tbuf
, "\t%ld", hd
->disc_done_cnt
[x
]);
2175 "\ninterrupts: %ld, DATA_PHASE ints: %ld DMA, %ld PIO",
2176 hd
->int_cnt
, hd
->dma_cnt
, hd
->pio_cnt
);
2180 if (hd
->proc
& PR_CONNECTED
) {
2181 strcat(bp
, "\nconnected: ");
2182 if (hd
->connected
) {
2183 cmd
= (struct scsi_cmnd
*) hd
->connected
;
2184 sprintf(tbuf
, " %ld-%d:%d(%02x)",
2185 cmd
->pid
, cmd
->device
->id
, cmd
->device
->lun
, cmd
->cmnd
[0]);
2189 if (hd
->proc
& PR_INPUTQ
) {
2190 strcat(bp
, "\ninput_Q: ");
2191 cmd
= (struct scsi_cmnd
*) hd
->input_Q
;
2193 sprintf(tbuf
, " %ld-%d:%d(%02x)",
2194 cmd
->pid
, cmd
->device
->id
, cmd
->device
->lun
, cmd
->cmnd
[0]);
2196 cmd
= (struct scsi_cmnd
*) cmd
->host_scribble
;
2199 if (hd
->proc
& PR_DISCQ
) {
2200 strcat(bp
, "\ndisconnected_Q:");
2201 cmd
= (struct scsi_cmnd
*) hd
->disconnected_Q
;
2203 sprintf(tbuf
, " %ld-%d:%d(%02x)",
2204 cmd
->pid
, cmd
->device
->id
, cmd
->device
->lun
, cmd
->cmnd
[0]);
2206 cmd
= (struct scsi_cmnd
*) cmd
->host_scribble
;
2210 spin_unlock_irq(&hd
->lock
);
2216 if (off
> 0x40000) /* ALWAYS stop after 256k bytes have been read */
2218 if (hd
->proc
& PR_STOP
) /* stop every other time */
2222 #else /* PROC_INTERFACE */
2226 #endif /* PROC_INTERFACE */
2231 wd33c93_release(void)
2235 EXPORT_SYMBOL(wd33c93_host_reset
);
2236 EXPORT_SYMBOL(wd33c93_init
);
2237 EXPORT_SYMBOL(wd33c93_release
);
2238 EXPORT_SYMBOL(wd33c93_abort
);
2239 EXPORT_SYMBOL(wd33c93_queuecommand
);
2240 EXPORT_SYMBOL(wd33c93_intr
);
2241 EXPORT_SYMBOL(wd33c93_proc_info
);