1 |
1626 |
jcastillo |
/*
|
2 |
|
|
* wd33c93.c - Linux-68k device driver for the Commodore
|
3 |
|
|
* Amiga A2091/590 SCSI controller card
|
4 |
|
|
*
|
5 |
|
|
* Copyright (c) 1996 John Shifflett, GeoLog Consulting
|
6 |
|
|
* john@geolog.com
|
7 |
|
|
* jshiffle@netcom.com
|
8 |
|
|
*
|
9 |
|
|
* This program is free software; you can redistribute it and/or modify
|
10 |
|
|
* it under the terms of the GNU General Public License as published by
|
11 |
|
|
* the Free Software Foundation; either version 2, or (at your option)
|
12 |
|
|
* any later version.
|
13 |
|
|
*
|
14 |
|
|
* This program is distributed in the hope that it will be useful,
|
15 |
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
16 |
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
17 |
|
|
* GNU General Public License for more details.
|
18 |
|
|
*
|
19 |
|
|
*
|
20 |
|
|
* Drew Eckhardt's excellent 'Generic NCR5380' sources from Linux-PC
|
21 |
|
|
* provided much of the inspiration and some of the code for this
|
22 |
|
|
* driver. Everything I know about Amiga DMA was gleaned from careful
|
23 |
|
|
* reading of Hamish Mcdonald's original wd33c93 driver; in fact, I
|
24 |
|
|
* borrowed shamelessly from all over that source. Thanks Hamish!
|
25 |
|
|
*
|
26 |
|
|
* _This_ driver is (I feel) an improvement over the old one in
|
27 |
|
|
* several respects:
|
28 |
|
|
*
|
29 |
|
|
* - Target Disconnection/Reconnection is now supported. Any
|
30 |
|
|
* system with more than one device active on the SCSI bus
|
31 |
|
|
* will benefit from this. The driver defaults to what I'm
|
32 |
|
|
* 'adaptive disconnect' - meaning that each command is
|
33 |
|
|
* evaluated individually as to whether or not it should
|
34 |
|
|
* be run with the option to disconnect/reselect (if the
|
35 |
|
|
* device chooses), or as a "SCSI-bus-hog".
|
36 |
|
|
*
|
37 |
|
|
* - Synchronous data transfers are now supported. Because of
|
38 |
|
|
* a few devices that choke after telling the driver that
|
39 |
|
|
* they can do sync transfers, we don't automatically use
|
40 |
|
|
* this faster protocol - it can be enabled via the command-
|
41 |
|
|
* line on a device-by-device basis.
|
42 |
|
|
*
|
43 |
|
|
* - Runtime operating parameters can now be specified through
|
44 |
|
|
* the 'amiboot' or the 'insmod' command line. For amiboot do:
|
45 |
|
|
* "amiboot [usual stuff] wd33c93=blah,blah,blah"
|
46 |
|
|
* The defaults should be good for most people. See the comment
|
47 |
|
|
* for 'setup_strings' below for more details.
|
48 |
|
|
*
|
49 |
|
|
* - The old driver relied exclusively on what the Western Digital
|
50 |
|
|
* docs call "Combination Level 2 Commands", which are a great
|
51 |
|
|
* idea in that the CPU is relieved of a lot of interrupt
|
52 |
|
|
* overhead. However, by accepting a certain (user-settable)
|
53 |
|
|
* amount of additional interrupts, this driver achieves
|
54 |
|
|
* better control over the SCSI bus, and data transfers are
|
55 |
|
|
* almost as fast while being much easier to define, track,
|
56 |
|
|
* and debug.
|
57 |
|
|
*
|
58 |
|
|
*
|
59 |
|
|
* TODO:
|
60 |
|
|
* more speed. linked commands.
|
61 |
|
|
*
|
62 |
|
|
*
|
63 |
|
|
* People with bug reports, wish-lists, complaints, comments,
|
64 |
|
|
* or improvements are asked to pah-leeez email me (John Shifflett)
|
65 |
|
|
* at john@geolog.com or jshiffle@netcom.com! I'm anxious to get
|
66 |
|
|
* this thing into as good a shape as possible, and I'm positive
|
67 |
|
|
* there are lots of lurking bugs and "Stupid Places".
|
68 |
|
|
*
|
69 |
|
|
*/
|
70 |
|
|
|
71 |
|
|
#include <asm/system.h>
|
72 |
|
|
#include <linux/sched.h>
|
73 |
|
|
#include <linux/string.h>
|
74 |
|
|
#include <linux/delay.h>
|
75 |
|
|
#include <linux/version.h>
|
76 |
|
|
|
77 |
|
|
#if LINUX_VERSION_CODE >= 0x010300
|
78 |
|
|
#include <linux/blk.h>
|
79 |
|
|
#else
|
80 |
|
|
#include "../block/blk.h"
|
81 |
|
|
#endif
|
82 |
|
|
|
83 |
|
|
#include "scsi.h"
|
84 |
|
|
#include "hosts.h"
|
85 |
|
|
#include "wd33c93.h"
|
86 |
|
|
|
87 |
|
|
#ifdef MODULE
|
88 |
|
|
#include <linux/module.h>
|
89 |
|
|
#endif
|
90 |
|
|
|
91 |
|
|
/* Leave this undefined for now - need to make some changes in the
|
92 |
|
|
* a3000/a2019/gvp11 files to get it working right
|
93 |
|
|
*/
|
94 |
|
|
/*#define PROC_INTERFACE*/ /* add code for /proc/scsi/wd33c93/xxx interface */
|
95 |
|
|
|
96 |
|
|
#define SYNC_DEBUG /* extra info on sync negotiation printed */
|
97 |
|
|
#define DEBUGGING_ON /* enable command-line debugging bitmask */
|
98 |
|
|
#define DEBUG_DEFAULTS 0 /* default debugging bitmask */
|
99 |
|
|
|
100 |
|
|
#define WD33C93_VERSION "1.21"
|
101 |
|
|
#define WD33C93_DATE "20/Apr/1996"
|
102 |
|
|
|
103 |
|
|
#ifdef DEBUGGING_ON
|
104 |
|
|
#define DB(f,a) if (hostdata->args & (f)) a;
|
105 |
|
|
#else
|
106 |
|
|
#define DB(f,a)
|
107 |
|
|
#endif
|
108 |
|
|
|
109 |
|
|
#define IS_DIR_OUT(cmd) ((cmd)->cmnd[0] == WRITE_6 || \
|
110 |
|
|
(cmd)->cmnd[0] == WRITE_10 || \
|
111 |
|
|
(cmd)->cmnd[0] == WRITE_12)
|
112 |
|
|
|
113 |
|
|
|
114 |
|
|
/*
|
115 |
|
|
* setup_strings is an array of strings that define some of the operating
|
116 |
|
|
* parameters and settings for this driver. It is used unless an amiboot
|
117 |
|
|
* or insmod command line has been specified, in which case those settings
|
118 |
|
|
* are combined with the ones here. The driver recognizes the following
|
119 |
|
|
* keywords (lower case required) and arguments:
|
120 |
|
|
*
|
121 |
|
|
* - nosync:bitmask -bitmask is a byte where the 1st 7 bits correspond with
|
122 |
|
|
* the 7 possible SCSI devices. Set a bit to prevent sync
|
123 |
|
|
* negotiation on that device. To maintain backwards
|
124 |
|
|
* compatibility, a command-line such as "wd33c93=255" will
|
125 |
|
|
* be automatically translated to "wd33c93=nosync:0xff".
|
126 |
|
|
* - period:ns -ns is the minimum # of nanoseconds in a SCSI data transfer
|
127 |
|
|
* period. Default is 500; acceptable values are 250 - 1000.
|
128 |
|
|
* - disconnect:x -x = 0 to never allow disconnects, 2 to always allow them.
|
129 |
|
|
* x = 1 does 'adaptive' disconnects, which is the default
|
130 |
|
|
* and generally the best choice.
|
131 |
|
|
* - debug:x -If 'DEBUGGING_ON' is defined, x is a bit mask that causes
|
132 |
|
|
* various types of debug output to printed - see the DB_xxx
|
133 |
|
|
* defines in wd33c93.h
|
134 |
|
|
* - clock:x -x = clock input in MHz for WD33c93 chip. Normal values
|
135 |
|
|
* would be from 8 through 20. Default is 8.
|
136 |
|
|
* - next -No argument. Used to separate blocks of keywords when
|
137 |
|
|
* there's more than one host adapter in the system.
|
138 |
|
|
*
|
139 |
|
|
* Syntax Notes:
|
140 |
|
|
* - Numeric arguments can be decimal or the '0x' form of hex notation. There
|
141 |
|
|
* _must_ be a colon between a keyword and its numeric argument, with no
|
142 |
|
|
* spaces.
|
143 |
|
|
* - Keywords are separated by commas, no spaces, in the standard kernel
|
144 |
|
|
* command-line manner, except in the case of 'setup_strings[]' (see
|
145 |
|
|
* below), which is simply a C array of pointers to char. Each element
|
146 |
|
|
* in the array is a string comprising one keyword & argument.
|
147 |
|
|
* - A keyword in the 'nth' comma-separated command-line member will overwrite
|
148 |
|
|
* the 'nth' element of setup_strings[]. A blank command-line member (in
|
149 |
|
|
* other words, a comma with no preceding keyword) will _not_ overwrite
|
150 |
|
|
* the corresponding setup_strings[] element.
|
151 |
|
|
* - If a keyword is used more than once, the first one applies to the first
|
152 |
|
|
* SCSI host found, the second to the second card, etc, unless the 'next'
|
153 |
|
|
* keyword is used to change the order.
|
154 |
|
|
*
|
155 |
|
|
* Some amiboot examples (for insmod, use 'setup_strings' instead of 'wd33c93'):
|
156 |
|
|
* - wd33c93=nosync:255
|
157 |
|
|
* - wd33c93=disconnect:2,nosync:0x08,period:250
|
158 |
|
|
* - wd33c93=debug:0x1c
|
159 |
|
|
*/
|
160 |
|
|
|
161 |
|
|
static char *setup_strings[] =
|
162 |
|
|
{"","","","","","","","","","","",""};
|
163 |
|
|
|
164 |
|
|
#ifdef PROC_INTERFACE
|
165 |
|
|
unsigned long disc_allowed_total;
|
166 |
|
|
unsigned long disc_taken_total;
|
167 |
|
|
#endif
|
168 |
|
|
|
169 |
|
|
|
170 |
|
|
inline uchar read_wd33c93(wd33c93_regs *regp,uchar reg_num)
|
171 |
|
|
{
|
172 |
|
|
regp->SASR = reg_num;
|
173 |
|
|
return(regp->SCMD);
|
174 |
|
|
}
|
175 |
|
|
|
176 |
|
|
|
177 |
|
|
#define READ_AUX_STAT() (regp->SASR)
|
178 |
|
|
|
179 |
|
|
|
180 |
|
|
inline void write_wd33c93(wd33c93_regs *regp,uchar reg_num, uchar value)
|
181 |
|
|
{
|
182 |
|
|
regp->SASR = reg_num;
|
183 |
|
|
regp->SCMD = value;
|
184 |
|
|
}
|
185 |
|
|
|
186 |
|
|
|
187 |
|
|
inline void write_wd33c93_cmd(wd33c93_regs *regp, uchar cmd)
|
188 |
|
|
{
|
189 |
|
|
regp->SASR = WD_COMMAND;
|
190 |
|
|
regp->SCMD = cmd;
|
191 |
|
|
}
|
192 |
|
|
|
193 |
|
|
|
194 |
|
|
inline uchar read_1_byte(wd33c93_regs *regp)
|
195 |
|
|
{
|
196 |
|
|
uchar asr;
|
197 |
|
|
uchar x = 0;
|
198 |
|
|
|
199 |
|
|
write_wd33c93(regp, WD_CONTROL, CTRL_IDI | CTRL_EDI | CTRL_POLLED);
|
200 |
|
|
write_wd33c93_cmd(regp, WD_CMD_TRANS_INFO|0x80);
|
201 |
|
|
do {
|
202 |
|
|
asr = READ_AUX_STAT();
|
203 |
|
|
if (asr & ASR_DBR)
|
204 |
|
|
x = read_wd33c93(regp, WD_DATA);
|
205 |
|
|
} while (!(asr & ASR_INT));
|
206 |
|
|
return x;
|
207 |
|
|
}
|
208 |
|
|
|
209 |
|
|
|
210 |
|
|
void write_wd33c93_count(wd33c93_regs *regp,unsigned long value)
|
211 |
|
|
{
|
212 |
|
|
regp->SASR = WD_TRANSFER_COUNT_MSB;
|
213 |
|
|
regp->SCMD = value >> 16;
|
214 |
|
|
regp->SCMD = value >> 8;
|
215 |
|
|
regp->SCMD = value;
|
216 |
|
|
}
|
217 |
|
|
|
218 |
|
|
|
219 |
|
|
unsigned long read_wd33c93_count(wd33c93_regs *regp)
|
220 |
|
|
{
|
221 |
|
|
unsigned long value;
|
222 |
|
|
|
223 |
|
|
regp->SASR = WD_TRANSFER_COUNT_MSB;
|
224 |
|
|
value = regp->SCMD << 16;
|
225 |
|
|
value |= regp->SCMD << 8;
|
226 |
|
|
value |= regp->SCMD;
|
227 |
|
|
return value;
|
228 |
|
|
}
|
229 |
|
|
|
230 |
|
|
|
231 |
|
|
|
232 |
|
|
static struct sx_period sx_table[] = {
|
233 |
|
|
{ 1, 0x20},
|
234 |
|
|
{252, 0x20},
|
235 |
|
|
{376, 0x30},
|
236 |
|
|
{500, 0x40},
|
237 |
|
|
{624, 0x50},
|
238 |
|
|
{752, 0x60},
|
239 |
|
|
{876, 0x70},
|
240 |
|
|
{1000,0x00},
|
241 |
|
|
{0, 0} };
|
242 |
|
|
|
243 |
|
|
int round_period(unsigned int period)
|
244 |
|
|
{
|
245 |
|
|
int x;
|
246 |
|
|
|
247 |
|
|
for (x=1; sx_table[x].period_ns; x++) {
|
248 |
|
|
if ((period <= sx_table[x-0].period_ns) &&
|
249 |
|
|
(period > sx_table[x-1].period_ns)) {
|
250 |
|
|
return x;
|
251 |
|
|
}
|
252 |
|
|
}
|
253 |
|
|
return 7;
|
254 |
|
|
}
|
255 |
|
|
|
256 |
|
|
uchar calc_sync_xfer(unsigned int period, unsigned int offset)
|
257 |
|
|
{
|
258 |
|
|
uchar result;
|
259 |
|
|
|
260 |
|
|
period *= 4; /* convert SDTR code to ns */
|
261 |
|
|
result = sx_table[round_period(period)].reg_value;
|
262 |
|
|
result |= (offset < OPTIMUM_SX_OFF)?offset:OPTIMUM_SX_OFF;
|
263 |
|
|
return result;
|
264 |
|
|
}
|
265 |
|
|
|
266 |
|
|
|
267 |
|
|
|
268 |
|
|
void wd33c93_execute(struct Scsi_Host *instance);
|
269 |
|
|
|
270 |
|
|
int wd33c93_queuecommand (Scsi_Cmnd *cmd, void (*done)(Scsi_Cmnd *))
|
271 |
|
|
{
|
272 |
|
|
struct WD33C93_hostdata *hostdata;
|
273 |
|
|
Scsi_Cmnd *tmp;
|
274 |
|
|
unsigned long flags;
|
275 |
|
|
|
276 |
|
|
|
277 |
|
|
save_flags(flags);
|
278 |
|
|
cli();
|
279 |
|
|
hostdata = (struct WD33C93_hostdata *)cmd->host->hostdata;
|
280 |
|
|
|
281 |
|
|
DB(DB_QUEUE_COMMAND,printk("Q-%d-%02x-%ld( ",cmd->target,cmd->cmnd[0],cmd->pid))
|
282 |
|
|
|
283 |
|
|
/* Set up a few fields in the Scsi_Cmnd structure for our own use:
|
284 |
|
|
* - host_scribble is the pointer to the next cmd in the input queue
|
285 |
|
|
* - scsi_done points to the routine we call when a cmd is finished
|
286 |
|
|
* - result is what you'd expect
|
287 |
|
|
*/
|
288 |
|
|
|
289 |
|
|
cmd->host_scribble = NULL;
|
290 |
|
|
cmd->scsi_done = done;
|
291 |
|
|
cmd->result = 0;
|
292 |
|
|
|
293 |
|
|
/* We use the Scsi_Pointer structure that's included with each command
|
294 |
|
|
* as a scratchpad (as it's intended to be used!). The handy thing about
|
295 |
|
|
* the SCp.xxx fields is that they're always associated with a given
|
296 |
|
|
* cmd, and are preserved across disconnect-reselect. This means we
|
297 |
|
|
* can pretty much ignore SAVE_POINTERS and RESTORE_POINTERS messages
|
298 |
|
|
* if we keep all the critical pointers and counters in SCp:
|
299 |
|
|
* - SCp.ptr is the pointer into the RAM buffer
|
300 |
|
|
* - SCp.this_residual is the size of that buffer
|
301 |
|
|
* - SCp.buffer points to the current scatter-gather buffer
|
302 |
|
|
* - SCp.buffers_residual tells us how many S.G. buffers there are
|
303 |
|
|
* - SCp.have_data_in is not used
|
304 |
|
|
* - SCp.sent_command is not used
|
305 |
|
|
* - SCp.phase records this command's SRCID_ER bit setting
|
306 |
|
|
*/
|
307 |
|
|
|
308 |
|
|
if (cmd->use_sg) {
|
309 |
|
|
cmd->SCp.buffer = (struct scatterlist *)cmd->buffer;
|
310 |
|
|
cmd->SCp.buffers_residual = cmd->use_sg - 1;
|
311 |
|
|
cmd->SCp.ptr = (char *)cmd->SCp.buffer->address;
|
312 |
|
|
cmd->SCp.this_residual = cmd->SCp.buffer->length;
|
313 |
|
|
}
|
314 |
|
|
else {
|
315 |
|
|
cmd->SCp.buffer = NULL;
|
316 |
|
|
cmd->SCp.buffers_residual = 0;
|
317 |
|
|
cmd->SCp.ptr = (char *)cmd->request_buffer;
|
318 |
|
|
cmd->SCp.this_residual = cmd->request_bufflen;
|
319 |
|
|
}
|
320 |
|
|
|
321 |
|
|
/* Preset the command status to GOOD, since that's the normal case */
|
322 |
|
|
|
323 |
|
|
cmd->SCp.Status = GOOD;
|
324 |
|
|
|
325 |
|
|
/*
|
326 |
|
|
* Add the cmd to the end of 'input_Q'. Note that REQUEST SENSE
|
327 |
|
|
* commands are added to the head of the queue so that the desired
|
328 |
|
|
* sense data is not lost before REQUEST_SENSE executes.
|
329 |
|
|
*/
|
330 |
|
|
|
331 |
|
|
if (!(hostdata->input_Q) || (cmd->cmnd[0] == REQUEST_SENSE)) {
|
332 |
|
|
cmd->host_scribble = (uchar *)hostdata->input_Q;
|
333 |
|
|
hostdata->input_Q = cmd;
|
334 |
|
|
}
|
335 |
|
|
else { /* find the end of the queue */
|
336 |
|
|
for (tmp=(Scsi_Cmnd *)hostdata->input_Q; tmp->host_scribble;
|
337 |
|
|
tmp=(Scsi_Cmnd *)tmp->host_scribble)
|
338 |
|
|
;
|
339 |
|
|
tmp->host_scribble = (uchar *)cmd;
|
340 |
|
|
}
|
341 |
|
|
|
342 |
|
|
/* We know that there's at least one command in 'input_Q' now.
|
343 |
|
|
* Go see if any of them are runnable!
|
344 |
|
|
*/
|
345 |
|
|
|
346 |
|
|
wd33c93_execute(cmd->host);
|
347 |
|
|
|
348 |
|
|
DB(DB_QUEUE_COMMAND,printk(")Q-%ld ",cmd->pid))
|
349 |
|
|
|
350 |
|
|
restore_flags(flags);
|
351 |
|
|
return 0;
|
352 |
|
|
}
|
353 |
|
|
|
354 |
|
|
|
355 |
|
|
|
356 |
|
|
/*
|
357 |
|
|
* This routine attempts to start a scsi command. If the host_card is
|
358 |
|
|
* already connected, we give up immediately. Otherwise, look through
|
359 |
|
|
* the input_Q, using the first command we find that's intended
|
360 |
|
|
* for a currently non-busy target/lun.
|
361 |
|
|
*/
|
362 |
|
|
void wd33c93_execute (struct Scsi_Host *instance)
|
363 |
|
|
{
|
364 |
|
|
struct WD33C93_hostdata *hostdata;
|
365 |
|
|
wd33c93_regs *regp;
|
366 |
|
|
Scsi_Cmnd *cmd, *prev;
|
367 |
|
|
unsigned long flags;
|
368 |
|
|
int i;
|
369 |
|
|
|
370 |
|
|
|
371 |
|
|
save_flags(flags);
|
372 |
|
|
cli();
|
373 |
|
|
hostdata = (struct WD33C93_hostdata *)instance->hostdata;
|
374 |
|
|
regp = hostdata->regp;
|
375 |
|
|
|
376 |
|
|
DB(DB_EXECUTE,printk("EX("))
|
377 |
|
|
|
378 |
|
|
if (hostdata->selecting || hostdata->connected) {
|
379 |
|
|
|
380 |
|
|
DB(DB_EXECUTE,printk(")EX-0 "))
|
381 |
|
|
|
382 |
|
|
restore_flags(flags);
|
383 |
|
|
return;
|
384 |
|
|
}
|
385 |
|
|
|
386 |
|
|
/*
|
387 |
|
|
* Search through the input_Q for a command destined
|
388 |
|
|
* for an idle target/lun.
|
389 |
|
|
*/
|
390 |
|
|
|
391 |
|
|
cmd = (Scsi_Cmnd *)hostdata->input_Q;
|
392 |
|
|
prev = 0;
|
393 |
|
|
while (cmd) {
|
394 |
|
|
if (!(hostdata->busy[cmd->target] & (1 << cmd->lun)))
|
395 |
|
|
break;
|
396 |
|
|
prev = cmd;
|
397 |
|
|
cmd = (Scsi_Cmnd *)cmd->host_scribble;
|
398 |
|
|
}
|
399 |
|
|
|
400 |
|
|
/* quit if queue empty or all possible targets are busy */
|
401 |
|
|
|
402 |
|
|
if (!cmd) {
|
403 |
|
|
|
404 |
|
|
DB(DB_EXECUTE,printk(")EX-1 "))
|
405 |
|
|
|
406 |
|
|
restore_flags(flags);
|
407 |
|
|
return;
|
408 |
|
|
}
|
409 |
|
|
|
410 |
|
|
/* remove command from queue */
|
411 |
|
|
|
412 |
|
|
if (prev)
|
413 |
|
|
prev->host_scribble = cmd->host_scribble;
|
414 |
|
|
else
|
415 |
|
|
hostdata->input_Q = (Scsi_Cmnd *)cmd->host_scribble;
|
416 |
|
|
|
417 |
|
|
/*
|
418 |
|
|
* Start the selection process
|
419 |
|
|
*/
|
420 |
|
|
|
421 |
|
|
if (IS_DIR_OUT(cmd))
|
422 |
|
|
write_wd33c93(regp, WD_DESTINATION_ID, cmd->target);
|
423 |
|
|
else
|
424 |
|
|
write_wd33c93(regp, WD_DESTINATION_ID, cmd->target | DSTID_DPD);
|
425 |
|
|
|
426 |
|
|
/* Now we need to figure out whether or not this command is a good
|
427 |
|
|
* candidate for disconnect/reselect. We guess to the best of our
|
428 |
|
|
* ability, based on a set of hierarchical rules. When several
|
429 |
|
|
* devices are operating simultaneously, disconnects are usually
|
430 |
|
|
* an advantage. In a single device system, or if only 1 device
|
431 |
|
|
* is being accessed, transfers usually go faster if disconnects
|
432 |
|
|
* are not allowed:
|
433 |
|
|
*
|
434 |
|
|
* + Commands should NEVER disconnect if hostdata->disconnect =
|
435 |
|
|
* DIS_NEVER (this holds for tape drives also), and ALWAYS
|
436 |
|
|
* disconnect if hostdata->disconnect = DIS_ALWAYS.
|
437 |
|
|
* + Tape drive commands should always be allowed to disconnect.
|
438 |
|
|
* + Disconnect should be allowed if disconnected_Q isn't empty.
|
439 |
|
|
* + Commands should NOT disconnect if input_Q is empty.
|
440 |
|
|
* + Disconnect should be allowed if there are commands in input_Q
|
441 |
|
|
* for a different target/lun. In this case, the other commands
|
442 |
|
|
* should be made disconnect-able, if not already.
|
443 |
|
|
*
|
444 |
|
|
* I know, I know - this code would flunk me out of any
|
445 |
|
|
* "C Programming 101" class ever offered. But it's easy
|
446 |
|
|
* to change around and experiment with for now.
|
447 |
|
|
*/
|
448 |
|
|
|
449 |
|
|
cmd->SCp.phase = 0; /* assume no disconnect */
|
450 |
|
|
if (hostdata->disconnect == DIS_NEVER)
|
451 |
|
|
goto no;
|
452 |
|
|
if (hostdata->disconnect == DIS_ALWAYS)
|
453 |
|
|
goto yes;
|
454 |
|
|
if (cmd->device->type == 1) /* tape drive? */
|
455 |
|
|
goto yes;
|
456 |
|
|
if (hostdata->disconnected_Q) /* other commands disconnected? */
|
457 |
|
|
goto yes;
|
458 |
|
|
if (!(hostdata->input_Q)) /* input_Q empty? */
|
459 |
|
|
goto no;
|
460 |
|
|
for (prev=(Scsi_Cmnd *)hostdata->input_Q; prev;
|
461 |
|
|
prev=(Scsi_Cmnd *)prev->host_scribble) {
|
462 |
|
|
if ((prev->target != cmd->target) || (prev->lun != cmd->lun)) {
|
463 |
|
|
for (prev=(Scsi_Cmnd *)hostdata->input_Q; prev;
|
464 |
|
|
prev=(Scsi_Cmnd *)prev->host_scribble)
|
465 |
|
|
prev->SCp.phase = 1;
|
466 |
|
|
goto yes;
|
467 |
|
|
}
|
468 |
|
|
}
|
469 |
|
|
goto no;
|
470 |
|
|
|
471 |
|
|
yes:
|
472 |
|
|
cmd->SCp.phase = 1;
|
473 |
|
|
|
474 |
|
|
#ifdef PROC_INTERFACE
|
475 |
|
|
disc_allowed_total++;
|
476 |
|
|
#endif
|
477 |
|
|
|
478 |
|
|
no:
|
479 |
|
|
write_wd33c93(regp, WD_SOURCE_ID, ((cmd->SCp.phase)?SRCID_ER:0));
|
480 |
|
|
|
481 |
|
|
write_wd33c93(regp, WD_TARGET_LUN, cmd->lun);
|
482 |
|
|
write_wd33c93(regp,WD_SYNCHRONOUS_TRANSFER,hostdata->sync_xfer[cmd->target]);
|
483 |
|
|
hostdata->busy[cmd->target] |= (1 << cmd->lun);
|
484 |
|
|
|
485 |
|
|
if ((hostdata->level2 == L2_NONE) ||
|
486 |
|
|
(hostdata->sync_stat[cmd->target] == SS_UNSET)) {
|
487 |
|
|
|
488 |
|
|
/*
|
489 |
|
|
* Do a 'Select-With-ATN' command. This will end with
|
490 |
|
|
* one of the following interrupts:
|
491 |
|
|
* CSR_RESEL_AM: failure - can try again later.
|
492 |
|
|
* CSR_TIMEOUT: failure - give up.
|
493 |
|
|
* CSR_SELECT: success - proceed.
|
494 |
|
|
*/
|
495 |
|
|
|
496 |
|
|
hostdata->selecting = cmd;
|
497 |
|
|
|
498 |
|
|
/* Every target has its own synchronous transfer setting, kept in the
|
499 |
|
|
* sync_xfer array, and a corresponding status byte in sync_stat[].
|
500 |
|
|
* Each target's sync_stat[] entry is initialized to SX_UNSET, and its
|
501 |
|
|
* sync_xfer[] entry is initialized to the default/safe value. SS_UNSET
|
502 |
|
|
* means that the parameters are undetermined as yet, and that we
|
503 |
|
|
* need to send an SDTR message to this device after selection is
|
504 |
|
|
* complete. We set SS_FIRST to tell the interrupt routine to do so,
|
505 |
|
|
* unless we've been asked not to try synchronous transfers on this
|
506 |
|
|
* target (and _all_ luns within it): In this case we set SS_SET to
|
507 |
|
|
* make the defaults final.
|
508 |
|
|
*/
|
509 |
|
|
if (hostdata->sync_stat[cmd->target] == SS_UNSET) {
|
510 |
|
|
if (hostdata->no_sync & (1 << cmd->target))
|
511 |
|
|
hostdata->sync_stat[cmd->target] = SS_SET;
|
512 |
|
|
else
|
513 |
|
|
hostdata->sync_stat[cmd->target] = SS_FIRST;
|
514 |
|
|
}
|
515 |
|
|
hostdata->state = S_SELECTING;
|
516 |
|
|
write_wd33c93_count(regp,0); /* guarantee a DATA_PHASE interrupt */
|
517 |
|
|
write_wd33c93_cmd(regp, WD_CMD_SEL_ATN);
|
518 |
|
|
}
|
519 |
|
|
|
520 |
|
|
else {
|
521 |
|
|
|
522 |
|
|
/*
|
523 |
|
|
* Do a 'Select-With-ATN-Xfer' command. This will end with
|
524 |
|
|
* one of the following interrupts:
|
525 |
|
|
* CSR_RESEL_AM: failure - can try again later.
|
526 |
|
|
* CSR_TIMEOUT: failure - give up.
|
527 |
|
|
* anything else: success - proceed.
|
528 |
|
|
*/
|
529 |
|
|
|
530 |
|
|
hostdata->connected = cmd;
|
531 |
|
|
write_wd33c93(regp, WD_COMMAND_PHASE, 0);
|
532 |
|
|
|
533 |
|
|
/* copy command_descriptor_block into WD chip
|
534 |
|
|
* (take advantage of auto-incrementing)
|
535 |
|
|
*/
|
536 |
|
|
|
537 |
|
|
regp->SASR = WD_CDB_1;
|
538 |
|
|
for (i=0; i<cmd->cmd_len; i++)
|
539 |
|
|
regp->SCMD = cmd->cmnd[i];
|
540 |
|
|
|
541 |
|
|
/* The wd33c93 only knows about Group 0, 1, and 5 commands when
|
542 |
|
|
* it's doing a 'select-and-transfer'. To be safe, we write the
|
543 |
|
|
* size of the CDB into the OWN_ID register for every case. This
|
544 |
|
|
* way there won't be problems with vendor-unique, audio, etc.
|
545 |
|
|
*/
|
546 |
|
|
|
547 |
|
|
write_wd33c93(regp, WD_OWN_ID, cmd->cmd_len);
|
548 |
|
|
|
549 |
|
|
/* When doing a non-disconnect command, we can save ourselves a DATA
|
550 |
|
|
* phase interrupt later by setting everything up now.
|
551 |
|
|
*/
|
552 |
|
|
|
553 |
|
|
if (cmd->SCp.phase == 0) {
|
554 |
|
|
if (hostdata->dma_setup(cmd,
|
555 |
|
|
(IS_DIR_OUT(cmd))?DATA_OUT_DIR:DATA_IN_DIR))
|
556 |
|
|
write_wd33c93_count(regp,0); /* guarantee a DATA_PHASE interrupt */
|
557 |
|
|
else {
|
558 |
|
|
write_wd33c93_count(regp, cmd->SCp.this_residual);
|
559 |
|
|
write_wd33c93(regp,WD_CONTROL, CTRL_IDI | CTRL_EDI | CTRL_DMA);
|
560 |
|
|
hostdata->dma = D_DMA_RUNNING;
|
561 |
|
|
}
|
562 |
|
|
}
|
563 |
|
|
else
|
564 |
|
|
write_wd33c93_count(regp,0); /* guarantee a DATA_PHASE interrupt */
|
565 |
|
|
|
566 |
|
|
hostdata->state = S_RUNNING_LEVEL2;
|
567 |
|
|
write_wd33c93_cmd(regp, WD_CMD_SEL_ATN_XFER);
|
568 |
|
|
}
|
569 |
|
|
|
570 |
|
|
/*
|
571 |
|
|
* Since the SCSI bus can handle only 1 connection at a time,
|
572 |
|
|
* we get out of here now. If the selection fails, or when
|
573 |
|
|
* the command disconnects, we'll come back to this routine
|
574 |
|
|
* to search the input_Q again...
|
575 |
|
|
*/
|
576 |
|
|
|
577 |
|
|
DB(DB_EXECUTE,printk("%s%ld)EX-2 ",(cmd->SCp.phase)?"d:":"",cmd->pid))
|
578 |
|
|
|
579 |
|
|
restore_flags(flags);
|
580 |
|
|
}
|
581 |
|
|
|
582 |
|
|
|
583 |
|
|
|
584 |
|
|
void transfer_pio(wd33c93_regs *regp, uchar *buf, int cnt,
|
585 |
|
|
int data_in_dir, struct WD33C93_hostdata *hostdata)
|
586 |
|
|
{
|
587 |
|
|
uchar asr;
|
588 |
|
|
|
589 |
|
|
DB(DB_TRANSFER,printk("(%p,%d,%s)",buf,cnt,data_in_dir?"in":"out"))
|
590 |
|
|
|
591 |
|
|
write_wd33c93(regp, WD_CONTROL, CTRL_IDI | CTRL_EDI | CTRL_POLLED);
|
592 |
|
|
write_wd33c93_count(regp,cnt);
|
593 |
|
|
write_wd33c93_cmd(regp, WD_CMD_TRANS_INFO);
|
594 |
|
|
if (data_in_dir) {
|
595 |
|
|
do {
|
596 |
|
|
asr = READ_AUX_STAT();
|
597 |
|
|
if (asr & ASR_DBR)
|
598 |
|
|
*buf++ = read_wd33c93(regp, WD_DATA);
|
599 |
|
|
} while (!(asr & ASR_INT));
|
600 |
|
|
}
|
601 |
|
|
else {
|
602 |
|
|
do {
|
603 |
|
|
asr = READ_AUX_STAT();
|
604 |
|
|
if (asr & ASR_DBR)
|
605 |
|
|
write_wd33c93(regp, WD_DATA, *buf++);
|
606 |
|
|
} while (!(asr & ASR_INT));
|
607 |
|
|
}
|
608 |
|
|
|
609 |
|
|
/* Note: we are returning with the interrupt UN-cleared.
|
610 |
|
|
* Since (presumably) an entire I/O operation has
|
611 |
|
|
* completed, the bus phase is probably different, and
|
612 |
|
|
* the interrupt routine will discover this when it
|
613 |
|
|
* responds to the uncleared int.
|
614 |
|
|
*/
|
615 |
|
|
|
616 |
|
|
}
|
617 |
|
|
|
618 |
|
|
|
619 |
|
|
|
620 |
|
|
void transfer_bytes(wd33c93_regs *regp, Scsi_Cmnd *cmd, int data_in_dir)
|
621 |
|
|
{
|
622 |
|
|
struct WD33C93_hostdata *hostdata;
|
623 |
|
|
|
624 |
|
|
hostdata = (struct WD33C93_hostdata *)cmd->host->hostdata;
|
625 |
|
|
|
626 |
|
|
/* Normally, you'd expect 'this_residual' to be non-zero here.
|
627 |
|
|
* In a series of scatter-gather transfers, however, this
|
628 |
|
|
* routine will usually be called with 'this_residual' equal
|
629 |
|
|
* to 0 and 'buffers_residual' non-zero. This means that a
|
630 |
|
|
* previous transfer completed, clearing 'this_residual', and
|
631 |
|
|
* now we need to setup the next scatter-gather buffer as the
|
632 |
|
|
* source or destination for THIS transfer.
|
633 |
|
|
*/
|
634 |
|
|
if (!cmd->SCp.this_residual && cmd->SCp.buffers_residual) {
|
635 |
|
|
++cmd->SCp.buffer;
|
636 |
|
|
--cmd->SCp.buffers_residual;
|
637 |
|
|
cmd->SCp.this_residual = cmd->SCp.buffer->length;
|
638 |
|
|
cmd->SCp.ptr = cmd->SCp.buffer->address;
|
639 |
|
|
}
|
640 |
|
|
|
641 |
|
|
write_wd33c93(regp,WD_SYNCHRONOUS_TRANSFER,hostdata->sync_xfer[cmd->target]);
|
642 |
|
|
|
643 |
|
|
/* 'dma_setup()' will return TRUE if we can't do DMA. */
|
644 |
|
|
|
645 |
|
|
if (hostdata->dma_setup(cmd, data_in_dir)) {
|
646 |
|
|
transfer_pio(regp, (uchar *)&cmd->SCp.ptr, cmd->SCp.this_residual,
|
647 |
|
|
data_in_dir, hostdata);
|
648 |
|
|
}
|
649 |
|
|
|
650 |
|
|
/* We are able to do DMA (in fact, the Amiga hardware is
|
651 |
|
|
* already going!), so start up the wd33c93 in DMA mode.
|
652 |
|
|
* We set 'hostdata->dma' = D_DMA_RUNNING so that when the
|
653 |
|
|
* transfer completes and causes an interrupt, we're
|
654 |
|
|
* reminded to tell the Amiga to shut down its end. We'll
|
655 |
|
|
* postpone the updating of 'this_residual' and 'ptr'
|
656 |
|
|
* until then.
|
657 |
|
|
*/
|
658 |
|
|
|
659 |
|
|
else {
|
660 |
|
|
write_wd33c93(regp, WD_CONTROL, CTRL_IDI | CTRL_EDI | CTRL_DMA);
|
661 |
|
|
write_wd33c93_count(regp,cmd->SCp.this_residual);
|
662 |
|
|
|
663 |
|
|
if ((hostdata->level2 >= L2_DATA) || (cmd->SCp.phase == 0)) {
|
664 |
|
|
write_wd33c93(regp, WD_COMMAND_PHASE, 0x45);
|
665 |
|
|
write_wd33c93_cmd(regp, WD_CMD_SEL_ATN_XFER);
|
666 |
|
|
hostdata->state = S_RUNNING_LEVEL2;
|
667 |
|
|
}
|
668 |
|
|
else
|
669 |
|
|
write_wd33c93_cmd(regp, WD_CMD_TRANS_INFO);
|
670 |
|
|
|
671 |
|
|
hostdata->dma = D_DMA_RUNNING;
|
672 |
|
|
}
|
673 |
|
|
}
|
674 |
|
|
|
675 |
|
|
|
676 |
|
|
|
677 |
|
|
void wd33c93_intr (struct Scsi_Host *instance)
|
678 |
|
|
{
|
679 |
|
|
struct WD33C93_hostdata *hostdata;
|
680 |
|
|
Scsi_Cmnd *patch, *cmd;
|
681 |
|
|
wd33c93_regs *regp;
|
682 |
|
|
unsigned long flags;
|
683 |
|
|
uchar asr, sr, phs, id, lun, *ucp, msg;
|
684 |
|
|
unsigned long length;
|
685 |
|
|
|
686 |
|
|
|
687 |
|
|
hostdata = (struct WD33C93_hostdata *)instance->hostdata;
|
688 |
|
|
regp = hostdata->regp;
|
689 |
|
|
|
690 |
|
|
asr = READ_AUX_STAT();
|
691 |
|
|
if (!(asr & ASR_INT) || (asr & ASR_BSY))
|
692 |
|
|
return;
|
693 |
|
|
|
694 |
|
|
/* OK - it should be safe to re-enable system interrupts */
|
695 |
|
|
|
696 |
|
|
save_flags(flags);
|
697 |
|
|
sti();
|
698 |
|
|
|
699 |
|
|
cmd = (Scsi_Cmnd *)hostdata->connected; /* assume we're connected */
|
700 |
|
|
sr = read_wd33c93(regp, WD_SCSI_STATUS); /* clear the interrupt */
|
701 |
|
|
phs = read_wd33c93(regp, WD_COMMAND_PHASE);
|
702 |
|
|
|
703 |
|
|
DB(DB_INTR,printk("{%02x:%02x-",asr,sr))
|
704 |
|
|
|
705 |
|
|
/* After starting a DMA transfer, the next interrupt
|
706 |
|
|
* is guaranteed to be in response to completion of
|
707 |
|
|
* the transfer. Since the Amiga DMA hardware runs in
|
708 |
|
|
* in an open-ended fashion, it needs to be told when
|
709 |
|
|
* to stop; do that here if D_DMA_RUNNING is true.
|
710 |
|
|
* Also, we have to update 'this_residual' and 'ptr'
|
711 |
|
|
* based on the contents of the TRANSFER_COUNT register,
|
712 |
|
|
* in case the device decided to do an intermediate
|
713 |
|
|
* disconnect (a device may do this if it has to do a
|
714 |
|
|
* seek, or just to be nice and let other devices have
|
715 |
|
|
* some bus time during long transfers). After doing
|
716 |
|
|
* whatever is needed, we go on and service the WD3393
|
717 |
|
|
* interrupt normally.
|
718 |
|
|
*/
|
719 |
|
|
|
720 |
|
|
if (hostdata->dma == D_DMA_RUNNING) {
|
721 |
|
|
DB(DB_TRANSFER,printk("[%p/%d:",cmd->SCp.ptr,cmd->SCp.this_residual))
|
722 |
|
|
hostdata->dma_stop(cmd->host, cmd, 1);
|
723 |
|
|
hostdata->dma = D_DMA_OFF;
|
724 |
|
|
length = cmd->SCp.this_residual;
|
725 |
|
|
cmd->SCp.this_residual = read_wd33c93_count(regp);
|
726 |
|
|
cmd->SCp.ptr += (length - cmd->SCp.this_residual);
|
727 |
|
|
DB(DB_TRANSFER,printk("%p/%d]",cmd->SCp.ptr,cmd->SCp.this_residual))
|
728 |
|
|
}
|
729 |
|
|
|
730 |
|
|
/* Respond to the specific WD3393 interrupt - there are quite a few! */
|
731 |
|
|
|
732 |
|
|
switch (sr) {
|
733 |
|
|
|
734 |
|
|
case CSR_TIMEOUT:
|
735 |
|
|
DB(DB_INTR,printk("TIMEOUT"))
|
736 |
|
|
|
737 |
|
|
cli();
|
738 |
|
|
if (hostdata->state == S_RUNNING_LEVEL2)
|
739 |
|
|
hostdata->connected = NULL;
|
740 |
|
|
else {
|
741 |
|
|
cmd = (Scsi_Cmnd *)hostdata->selecting; /* get a valid cmd */
|
742 |
|
|
hostdata->selecting = NULL;
|
743 |
|
|
}
|
744 |
|
|
|
745 |
|
|
cmd->result = DID_NO_CONNECT << 16;
|
746 |
|
|
hostdata->busy[cmd->target] &= ~(1 << cmd->lun);
|
747 |
|
|
hostdata->state = S_UNCONNECTED;
|
748 |
|
|
cmd->scsi_done(cmd);
|
749 |
|
|
|
750 |
|
|
/* We are not connected to a target - check to see if there
|
751 |
|
|
* are commands waiting to be executed.
|
752 |
|
|
*/
|
753 |
|
|
|
754 |
|
|
sti();
|
755 |
|
|
wd33c93_execute(instance);
|
756 |
|
|
break;
|
757 |
|
|
|
758 |
|
|
|
759 |
|
|
/* Note: this interrupt should not occur in a LEVEL2 command */
|
760 |
|
|
|
761 |
|
|
case CSR_SELECT:
|
762 |
|
|
cli();
|
763 |
|
|
DB(DB_INTR,printk("SELECT"))
|
764 |
|
|
hostdata->connected = cmd = (Scsi_Cmnd *)hostdata->selecting;
|
765 |
|
|
hostdata->selecting = NULL;
|
766 |
|
|
|
767 |
|
|
/* construct an IDENTIFY message with correct disconnect bit */
|
768 |
|
|
|
769 |
|
|
hostdata->outgoing_msg[0] = (0x80 | 0x00 | cmd->lun);
|
770 |
|
|
if (cmd->SCp.phase)
|
771 |
|
|
hostdata->outgoing_msg[0] |= 0x40;
|
772 |
|
|
|
773 |
|
|
if (hostdata->sync_stat[cmd->target] == SS_FIRST) {
|
774 |
|
|
#ifdef SYNC_DEBUG
|
775 |
|
|
printk(" sending SDTR ");
|
776 |
|
|
#endif
|
777 |
|
|
|
778 |
|
|
hostdata->sync_stat[cmd->target] = SS_WAITING;
|
779 |
|
|
|
780 |
|
|
/* tack on a 2nd message to ask about synchronous transfers */
|
781 |
|
|
|
782 |
|
|
hostdata->outgoing_msg[1] = EXTENDED_MESSAGE;
|
783 |
|
|
hostdata->outgoing_msg[2] = 3;
|
784 |
|
|
hostdata->outgoing_msg[3] = EXTENDED_SDTR;
|
785 |
|
|
hostdata->outgoing_msg[4] = OPTIMUM_SX_PER/4;
|
786 |
|
|
hostdata->outgoing_msg[5] = OPTIMUM_SX_OFF;
|
787 |
|
|
hostdata->outgoing_len = 6;
|
788 |
|
|
}
|
789 |
|
|
else
|
790 |
|
|
hostdata->outgoing_len = 1;
|
791 |
|
|
|
792 |
|
|
hostdata->state = S_CONNECTED;
|
793 |
|
|
break;
|
794 |
|
|
|
795 |
|
|
|
796 |
|
|
case CSR_XFER_DONE|PHS_DATA_IN:
|
797 |
|
|
case CSR_UNEXP |PHS_DATA_IN:
|
798 |
|
|
case CSR_SRV_REQ |PHS_DATA_IN:
|
799 |
|
|
DB(DB_INTR,printk("IN-%d.%d",cmd->SCp.this_residual,cmd->SCp.buffers_residual))
|
800 |
|
|
transfer_bytes(regp, cmd, DATA_IN_DIR);
|
801 |
|
|
if (hostdata->state != S_RUNNING_LEVEL2)
|
802 |
|
|
hostdata->state = S_CONNECTED;
|
803 |
|
|
break;
|
804 |
|
|
|
805 |
|
|
|
806 |
|
|
case CSR_XFER_DONE|PHS_DATA_OUT:
|
807 |
|
|
case CSR_UNEXP |PHS_DATA_OUT:
|
808 |
|
|
case CSR_SRV_REQ |PHS_DATA_OUT:
|
809 |
|
|
DB(DB_INTR,printk("OUT-%d.%d",cmd->SCp.this_residual,cmd->SCp.buffers_residual))
|
810 |
|
|
transfer_bytes(regp, cmd, DATA_OUT_DIR);
|
811 |
|
|
if (hostdata->state != S_RUNNING_LEVEL2)
|
812 |
|
|
hostdata->state = S_CONNECTED;
|
813 |
|
|
break;
|
814 |
|
|
|
815 |
|
|
|
816 |
|
|
/* Note: this interrupt should not occur in a LEVEL2 command */
|
817 |
|
|
|
818 |
|
|
case CSR_XFER_DONE|PHS_COMMAND:
|
819 |
|
|
case CSR_UNEXP |PHS_COMMAND:
|
820 |
|
|
case CSR_SRV_REQ |PHS_COMMAND:
|
821 |
|
|
DB(DB_INTR,printk("CMND-%02x,%ld",cmd->cmnd[0],cmd->pid))
|
822 |
|
|
transfer_pio(regp, cmd->cmnd, cmd->cmd_len, DATA_OUT_DIR, hostdata);
|
823 |
|
|
hostdata->state = S_CONNECTED;
|
824 |
|
|
break;
|
825 |
|
|
|
826 |
|
|
|
827 |
|
|
case CSR_XFER_DONE|PHS_STATUS:
|
828 |
|
|
case CSR_UNEXP |PHS_STATUS:
|
829 |
|
|
case CSR_SRV_REQ |PHS_STATUS:
|
830 |
|
|
DB(DB_INTR,printk("STATUS"))
|
831 |
|
|
|
832 |
|
|
cmd->SCp.Status = read_1_byte(regp);
|
833 |
|
|
if (hostdata->level2 >= L2_BASIC) {
|
834 |
|
|
sr = read_wd33c93(regp, WD_SCSI_STATUS); /* clear interrupt */
|
835 |
|
|
hostdata->state = S_RUNNING_LEVEL2;
|
836 |
|
|
write_wd33c93(regp, WD_COMMAND_PHASE, 0x50);
|
837 |
|
|
write_wd33c93_cmd(regp, WD_CMD_SEL_ATN_XFER);
|
838 |
|
|
}
|
839 |
|
|
else {
|
840 |
|
|
DB(DB_INTR,printk("=%02x",cmd->SCp.Status))
|
841 |
|
|
hostdata->state = S_CONNECTED;
|
842 |
|
|
}
|
843 |
|
|
break;
|
844 |
|
|
|
845 |
|
|
|
846 |
|
|
case CSR_XFER_DONE|PHS_MESS_IN:
|
847 |
|
|
case CSR_UNEXP |PHS_MESS_IN:
|
848 |
|
|
case CSR_SRV_REQ |PHS_MESS_IN:
|
849 |
|
|
DB(DB_INTR,printk("MSG_IN="))
|
850 |
|
|
|
851 |
|
|
cli();
|
852 |
|
|
msg = read_1_byte(regp);
|
853 |
|
|
sr = read_wd33c93(regp, WD_SCSI_STATUS); /* clear interrupt */
|
854 |
|
|
|
855 |
|
|
hostdata->incoming_msg[hostdata->incoming_ptr] = msg;
|
856 |
|
|
if (hostdata->incoming_msg[0] == EXTENDED_MESSAGE)
|
857 |
|
|
msg = EXTENDED_MESSAGE;
|
858 |
|
|
else
|
859 |
|
|
hostdata->incoming_ptr = 0;
|
860 |
|
|
|
861 |
|
|
cmd->SCp.Message = msg;
|
862 |
|
|
switch (msg) {
|
863 |
|
|
|
864 |
|
|
case COMMAND_COMPLETE:
|
865 |
|
|
DB(DB_INTR,printk("CCMP-%ld",cmd->pid))
|
866 |
|
|
write_wd33c93_cmd(regp,WD_CMD_NEGATE_ACK);
|
867 |
|
|
hostdata->state = S_PRE_CMP_DISC;
|
868 |
|
|
break;
|
869 |
|
|
|
870 |
|
|
case SAVE_POINTERS:
|
871 |
|
|
DB(DB_INTR,printk("SDP"))
|
872 |
|
|
write_wd33c93_cmd(regp,WD_CMD_NEGATE_ACK);
|
873 |
|
|
hostdata->state = S_CONNECTED;
|
874 |
|
|
break;
|
875 |
|
|
|
876 |
|
|
case RESTORE_POINTERS:
|
877 |
|
|
DB(DB_INTR,printk("RDP"))
|
878 |
|
|
if (hostdata->level2 >= L2_BASIC) {
|
879 |
|
|
write_wd33c93(regp, WD_COMMAND_PHASE, 0x45);
|
880 |
|
|
write_wd33c93_cmd(regp, WD_CMD_SEL_ATN_XFER);
|
881 |
|
|
hostdata->state = S_RUNNING_LEVEL2;
|
882 |
|
|
}
|
883 |
|
|
else {
|
884 |
|
|
write_wd33c93_cmd(regp, WD_CMD_NEGATE_ACK);
|
885 |
|
|
hostdata->state = S_CONNECTED;
|
886 |
|
|
}
|
887 |
|
|
break;
|
888 |
|
|
|
889 |
|
|
case DISCONNECT:
|
890 |
|
|
DB(DB_INTR,printk("DIS"))
|
891 |
|
|
cmd->device->disconnect = 1;
|
892 |
|
|
write_wd33c93_cmd(regp,WD_CMD_NEGATE_ACK);
|
893 |
|
|
hostdata->state = S_PRE_TMP_DISC;
|
894 |
|
|
break;
|
895 |
|
|
|
896 |
|
|
case MESSAGE_REJECT:
|
897 |
|
|
DB(DB_INTR,printk("REJ"))
|
898 |
|
|
#ifdef SYNC_DEBUG
|
899 |
|
|
printk("-REJ-");
|
900 |
|
|
#endif
|
901 |
|
|
if (hostdata->sync_stat[cmd->target] == SS_WAITING)
|
902 |
|
|
hostdata->sync_stat[cmd->target] = SS_SET;
|
903 |
|
|
write_wd33c93_cmd(regp,WD_CMD_NEGATE_ACK);
|
904 |
|
|
hostdata->state = S_CONNECTED;
|
905 |
|
|
break;
|
906 |
|
|
|
907 |
|
|
case EXTENDED_MESSAGE:
|
908 |
|
|
DB(DB_INTR,printk("EXT"))
|
909 |
|
|
|
910 |
|
|
ucp = hostdata->incoming_msg;
|
911 |
|
|
|
912 |
|
|
#ifdef SYNC_DEBUG
|
913 |
|
|
printk("%02x",ucp[hostdata->incoming_ptr]);
|
914 |
|
|
#endif
|
915 |
|
|
/* Is this the last byte of the extended message? */
|
916 |
|
|
|
917 |
|
|
if ((hostdata->incoming_ptr >= 2) &&
|
918 |
|
|
(hostdata->incoming_ptr == (ucp[1] + 1))) {
|
919 |
|
|
|
920 |
|
|
switch (ucp[2]) { /* what's the EXTENDED code? */
|
921 |
|
|
case EXTENDED_SDTR:
|
922 |
|
|
id = calc_sync_xfer(ucp[3],ucp[4]);
|
923 |
|
|
if (hostdata->sync_stat[cmd->target] != SS_WAITING) {
|
924 |
|
|
|
925 |
|
|
/* A device has sent an unsolicited SDTR message; rather than go
|
926 |
|
|
* through the effort of decoding it and then figuring out what
|
927 |
|
|
* our reply should be, we're just gonna say that we have a
|
928 |
|
|
* synchronous fifo depth of 0. This will result in asynchronous
|
929 |
|
|
* transfers - not ideal but so much easier.
|
930 |
|
|
* Actually, this is OK because it assures us that if we don't
|
931 |
|
|
* specifically ask for sync transfers, we won't do any.
|
932 |
|
|
*/
|
933 |
|
|
|
934 |
|
|
write_wd33c93_cmd(regp,WD_CMD_ASSERT_ATN); /* want MESS_OUT */
|
935 |
|
|
hostdata->outgoing_msg[0] = EXTENDED_MESSAGE;
|
936 |
|
|
hostdata->outgoing_msg[1] = 3;
|
937 |
|
|
hostdata->outgoing_msg[2] = EXTENDED_SDTR;
|
938 |
|
|
hostdata->outgoing_msg[3] = hostdata->default_sx_per/4;
|
939 |
|
|
hostdata->outgoing_msg[4] = 0;
|
940 |
|
|
hostdata->outgoing_len = 5;
|
941 |
|
|
hostdata->sync_xfer[cmd->target] =
|
942 |
|
|
calc_sync_xfer(hostdata->default_sx_per/4,0);
|
943 |
|
|
}
|
944 |
|
|
else {
|
945 |
|
|
hostdata->sync_xfer[cmd->target] = id;
|
946 |
|
|
}
|
947 |
|
|
#ifdef SYNC_DEBUG
|
948 |
|
|
printk("sync_xfer=%02x",hostdata->sync_xfer[cmd->target]);
|
949 |
|
|
#endif
|
950 |
|
|
hostdata->sync_stat[cmd->target] = SS_SET;
|
951 |
|
|
write_wd33c93_cmd(regp,WD_CMD_NEGATE_ACK);
|
952 |
|
|
hostdata->state = S_CONNECTED;
|
953 |
|
|
break;
|
954 |
|
|
case EXTENDED_WDTR:
|
955 |
|
|
write_wd33c93_cmd(regp,WD_CMD_ASSERT_ATN); /* want MESS_OUT */
|
956 |
|
|
printk("sending WDTR ");
|
957 |
|
|
hostdata->outgoing_msg[0] = EXTENDED_MESSAGE;
|
958 |
|
|
hostdata->outgoing_msg[1] = 2;
|
959 |
|
|
hostdata->outgoing_msg[2] = EXTENDED_WDTR;
|
960 |
|
|
hostdata->outgoing_msg[3] = 0; /* 8 bit transfer width */
|
961 |
|
|
hostdata->outgoing_len = 4;
|
962 |
|
|
write_wd33c93_cmd(regp,WD_CMD_NEGATE_ACK);
|
963 |
|
|
hostdata->state = S_CONNECTED;
|
964 |
|
|
break;
|
965 |
|
|
default:
|
966 |
|
|
write_wd33c93_cmd(regp,WD_CMD_ASSERT_ATN); /* want MESS_OUT */
|
967 |
|
|
printk("Rejecting Unknown Extended Message(%02x). ",ucp[2]);
|
968 |
|
|
hostdata->outgoing_msg[0] = MESSAGE_REJECT;
|
969 |
|
|
hostdata->outgoing_len = 1;
|
970 |
|
|
write_wd33c93_cmd(regp,WD_CMD_NEGATE_ACK);
|
971 |
|
|
hostdata->state = S_CONNECTED;
|
972 |
|
|
break;
|
973 |
|
|
}
|
974 |
|
|
hostdata->incoming_ptr = 0;
|
975 |
|
|
}
|
976 |
|
|
|
977 |
|
|
/* We need to read more MESS_IN bytes for the extended message */
|
978 |
|
|
|
979 |
|
|
else {
|
980 |
|
|
hostdata->incoming_ptr++;
|
981 |
|
|
write_wd33c93_cmd(regp,WD_CMD_NEGATE_ACK);
|
982 |
|
|
hostdata->state = S_CONNECTED;
|
983 |
|
|
}
|
984 |
|
|
break;
|
985 |
|
|
|
986 |
|
|
default:
|
987 |
|
|
printk("Rejecting Unknown Message(%02x) ",msg);
|
988 |
|
|
write_wd33c93_cmd(regp,WD_CMD_ASSERT_ATN); /* want MESS_OUT */
|
989 |
|
|
hostdata->outgoing_msg[0] = MESSAGE_REJECT;
|
990 |
|
|
hostdata->outgoing_len = 1;
|
991 |
|
|
write_wd33c93_cmd(regp,WD_CMD_NEGATE_ACK);
|
992 |
|
|
hostdata->state = S_CONNECTED;
|
993 |
|
|
}
|
994 |
|
|
break;
|
995 |
|
|
|
996 |
|
|
|
997 |
|
|
/* Note: this interrupt will occur only after a LEVEL2 command */
|
998 |
|
|
|
999 |
|
|
case CSR_SEL_XFER_DONE:
|
1000 |
|
|
cli();
|
1001 |
|
|
|
1002 |
|
|
/* Make sure that reselection is enabled at this point - it may
|
1003 |
|
|
* have been turned off for the command that just completed.
|
1004 |
|
|
*/
|
1005 |
|
|
|
1006 |
|
|
write_wd33c93(regp,WD_SOURCE_ID, SRCID_ER);
|
1007 |
|
|
if (phs == 0x60) {
|
1008 |
|
|
DB(DB_INTR,printk("SX-DONE-%ld",cmd->pid))
|
1009 |
|
|
cmd->SCp.Message = COMMAND_COMPLETE;
|
1010 |
|
|
lun = read_wd33c93(regp, WD_TARGET_LUN);
|
1011 |
|
|
if (cmd->SCp.Status == GOOD)
|
1012 |
|
|
cmd->SCp.Status = lun;
|
1013 |
|
|
hostdata->connected = NULL;
|
1014 |
|
|
if (cmd->cmnd[0] != REQUEST_SENSE)
|
1015 |
|
|
cmd->result = cmd->SCp.Status | (cmd->SCp.Message << 8);
|
1016 |
|
|
else if (cmd->SCp.Status != GOOD)
|
1017 |
|
|
cmd->result = (cmd->result & 0x00ffff) | (DID_ERROR << 16);
|
1018 |
|
|
hostdata->busy[cmd->target] &= ~(1 << cmd->lun);
|
1019 |
|
|
hostdata->state = S_UNCONNECTED;
|
1020 |
|
|
cmd->scsi_done(cmd);
|
1021 |
|
|
|
1022 |
|
|
/* We are no longer connected to a target - check to see if
|
1023 |
|
|
* there are commands waiting to be executed.
|
1024 |
|
|
*/
|
1025 |
|
|
|
1026 |
|
|
wd33c93_execute(instance);
|
1027 |
|
|
}
|
1028 |
|
|
else {
|
1029 |
|
|
printk("%02x:%02x:%02x-%ld: Unknown SEL_XFER_DONE phase!!---",asr,sr,phs,cmd->pid);
|
1030 |
|
|
}
|
1031 |
|
|
break;
|
1032 |
|
|
|
1033 |
|
|
|
1034 |
|
|
/* Note: this interrupt will occur only after a LEVEL2 command */
|
1035 |
|
|
|
1036 |
|
|
case CSR_SDP:
|
1037 |
|
|
DB(DB_INTR,printk("SDP"))
|
1038 |
|
|
hostdata->state = S_RUNNING_LEVEL2;
|
1039 |
|
|
write_wd33c93(regp, WD_COMMAND_PHASE, 0x41);
|
1040 |
|
|
write_wd33c93_cmd(regp, WD_CMD_SEL_ATN_XFER);
|
1041 |
|
|
break;
|
1042 |
|
|
|
1043 |
|
|
|
1044 |
|
|
case CSR_XFER_DONE|PHS_MESS_OUT:
|
1045 |
|
|
case CSR_UNEXP |PHS_MESS_OUT:
|
1046 |
|
|
case CSR_SRV_REQ |PHS_MESS_OUT:
|
1047 |
|
|
DB(DB_INTR,printk("MSG_OUT="))
|
1048 |
|
|
|
1049 |
|
|
/* To get here, we've probably requested MESSAGE_OUT and have
|
1050 |
|
|
* already put the correct bytes in outgoing_msg[] and filled
|
1051 |
|
|
* in outgoing_len. We simply send them out to the SCSI bus.
|
1052 |
|
|
* Sometimes we get MESSAGE_OUT phase when we're not expecting
|
1053 |
|
|
* it - like when our SDTR message is rejected by a target. Some
|
1054 |
|
|
* targets send the REJECT before receiving all of the extended
|
1055 |
|
|
* message, and then seem to go back to MESSAGE_OUT for a byte
|
1056 |
|
|
* or two. Not sure why, or if I'm doing something wrong to
|
1057 |
|
|
* cause this to happen. Regardless, it seems that sending
|
1058 |
|
|
* NOP messages in these situations results in no harm and
|
1059 |
|
|
* makes everyone happy.
|
1060 |
|
|
*/
|
1061 |
|
|
|
1062 |
|
|
if (hostdata->outgoing_len == 0) {
|
1063 |
|
|
hostdata->outgoing_len = 1;
|
1064 |
|
|
hostdata->outgoing_msg[0] = NOP;
|
1065 |
|
|
}
|
1066 |
|
|
transfer_pio(regp, hostdata->outgoing_msg, hostdata->outgoing_len,
|
1067 |
|
|
DATA_OUT_DIR, hostdata);
|
1068 |
|
|
DB(DB_INTR,printk("%02x",hostdata->outgoing_msg[0]))
|
1069 |
|
|
hostdata->outgoing_len = 0;
|
1070 |
|
|
hostdata->state = S_CONNECTED;
|
1071 |
|
|
break;
|
1072 |
|
|
|
1073 |
|
|
|
1074 |
|
|
case CSR_UNEXP_DISC:
|
1075 |
|
|
|
1076 |
|
|
/* I think I've seen this after a request-sense that was in response
|
1077 |
|
|
* to an error condition, but not sure. We certainly need to do
|
1078 |
|
|
* something when we get this interrupt - the question is 'what?'.
|
1079 |
|
|
* Let's think positively, and assume some command has finished
|
1080 |
|
|
* in a legal manner (like a command that provokes a request-sense),
|
1081 |
|
|
* so we treat it as a normal command-complete-disconnect.
|
1082 |
|
|
*/
|
1083 |
|
|
|
1084 |
|
|
cli();
|
1085 |
|
|
|
1086 |
|
|
/* Make sure that reselection is enabled at this point - it may
|
1087 |
|
|
* have been turned off for the command that just completed.
|
1088 |
|
|
*/
|
1089 |
|
|
|
1090 |
|
|
write_wd33c93(regp,WD_SOURCE_ID, SRCID_ER);
|
1091 |
|
|
if (cmd == NULL) {
|
1092 |
|
|
printk(" - Already disconnected! ");
|
1093 |
|
|
hostdata->state = S_UNCONNECTED;
|
1094 |
|
|
return;
|
1095 |
|
|
}
|
1096 |
|
|
DB(DB_INTR,printk("UNEXP_DISC-%ld",cmd->pid))
|
1097 |
|
|
hostdata->connected = NULL;
|
1098 |
|
|
hostdata->busy[cmd->target] &= ~(1 << cmd->lun);
|
1099 |
|
|
hostdata->state = S_UNCONNECTED;
|
1100 |
|
|
if (cmd->cmnd[0] != REQUEST_SENSE)
|
1101 |
|
|
cmd->result = cmd->SCp.Status | (cmd->SCp.Message << 8);
|
1102 |
|
|
else if (cmd->SCp.Status != GOOD)
|
1103 |
|
|
cmd->result = (cmd->result & 0x00ffff) | (DID_ERROR << 16);
|
1104 |
|
|
cmd->scsi_done(cmd);
|
1105 |
|
|
|
1106 |
|
|
/* We are no longer connected to a target - check to see if
|
1107 |
|
|
* there are commands waiting to be executed.
|
1108 |
|
|
*/
|
1109 |
|
|
|
1110 |
|
|
wd33c93_execute(instance);
|
1111 |
|
|
break;
|
1112 |
|
|
|
1113 |
|
|
|
1114 |
|
|
case CSR_DISC:
|
1115 |
|
|
cli();
|
1116 |
|
|
|
1117 |
|
|
/* Make sure that reselection is enabled at this point - it may
|
1118 |
|
|
* have been turned off for the command that just completed.
|
1119 |
|
|
*/
|
1120 |
|
|
|
1121 |
|
|
write_wd33c93(regp,WD_SOURCE_ID, SRCID_ER);
|
1122 |
|
|
DB(DB_INTR,printk("DISC-%ld",cmd->pid))
|
1123 |
|
|
if (cmd == NULL) {
|
1124 |
|
|
printk(" - Already disconnected! ");
|
1125 |
|
|
hostdata->state = S_UNCONNECTED;
|
1126 |
|
|
}
|
1127 |
|
|
switch (hostdata->state) {
|
1128 |
|
|
case S_PRE_CMP_DISC:
|
1129 |
|
|
hostdata->connected = NULL;
|
1130 |
|
|
hostdata->busy[cmd->target] &= ~(1 << cmd->lun);
|
1131 |
|
|
hostdata->state = S_UNCONNECTED;
|
1132 |
|
|
if (cmd->cmnd[0] != REQUEST_SENSE)
|
1133 |
|
|
cmd->result = cmd->SCp.Status | (cmd->SCp.Message << 8);
|
1134 |
|
|
else if (cmd->SCp.Status != GOOD)
|
1135 |
|
|
cmd->result = (cmd->result & 0x00ffff) | (DID_ERROR << 16);
|
1136 |
|
|
cmd->scsi_done(cmd);
|
1137 |
|
|
break;
|
1138 |
|
|
case S_PRE_TMP_DISC:
|
1139 |
|
|
case S_RUNNING_LEVEL2:
|
1140 |
|
|
cmd->host_scribble = (uchar *)hostdata->disconnected_Q;
|
1141 |
|
|
hostdata->disconnected_Q = cmd;
|
1142 |
|
|
hostdata->connected = NULL;
|
1143 |
|
|
hostdata->state = S_UNCONNECTED;
|
1144 |
|
|
|
1145 |
|
|
#ifdef PROC_INTERFACE
|
1146 |
|
|
disc_taken_total++;
|
1147 |
|
|
#endif
|
1148 |
|
|
|
1149 |
|
|
break;
|
1150 |
|
|
default:
|
1151 |
|
|
printk("*** Unexpected DISCONNECT interrupt! ***");
|
1152 |
|
|
hostdata->state = S_UNCONNECTED;
|
1153 |
|
|
}
|
1154 |
|
|
|
1155 |
|
|
/* We are no longer connected to a target - check to see if
|
1156 |
|
|
* there are commands waiting to be executed.
|
1157 |
|
|
*/
|
1158 |
|
|
|
1159 |
|
|
wd33c93_execute(instance);
|
1160 |
|
|
break;
|
1161 |
|
|
|
1162 |
|
|
|
1163 |
|
|
case CSR_RESEL_AM:
|
1164 |
|
|
DB(DB_INTR,printk("RESEL"))
|
1165 |
|
|
|
1166 |
|
|
cli();
|
1167 |
|
|
|
1168 |
|
|
/* First we have to make sure this reselection didn't */
|
1169 |
|
|
/* happen during Arbitration/Selection of some other device. */
|
1170 |
|
|
/* If yes, put losing command back on top of input_Q. */
|
1171 |
|
|
|
1172 |
|
|
if (hostdata->level2 <= L2_NONE) {
|
1173 |
|
|
|
1174 |
|
|
if (hostdata->selecting) {
|
1175 |
|
|
cmd = (Scsi_Cmnd *)hostdata->selecting;
|
1176 |
|
|
hostdata->selecting = NULL;
|
1177 |
|
|
hostdata->busy[cmd->target] &= ~(1 << cmd->lun);
|
1178 |
|
|
cmd->host_scribble = (uchar *)hostdata->input_Q;
|
1179 |
|
|
hostdata->input_Q = cmd;
|
1180 |
|
|
}
|
1181 |
|
|
}
|
1182 |
|
|
|
1183 |
|
|
else {
|
1184 |
|
|
|
1185 |
|
|
if (cmd) {
|
1186 |
|
|
if (phs == 0x00) {
|
1187 |
|
|
hostdata->busy[cmd->target] &= ~(1 << cmd->lun);
|
1188 |
|
|
cmd->host_scribble = (uchar *)hostdata->input_Q;
|
1189 |
|
|
hostdata->input_Q = cmd;
|
1190 |
|
|
}
|
1191 |
|
|
else {
|
1192 |
|
|
printk("---%02x:%02x:%02x-TROUBLE: Intrusive ReSelect!---",asr,sr,phs);
|
1193 |
|
|
while (1)
|
1194 |
|
|
printk("\r");
|
1195 |
|
|
}
|
1196 |
|
|
}
|
1197 |
|
|
|
1198 |
|
|
}
|
1199 |
|
|
|
1200 |
|
|
/* OK - find out which device reselected us. */
|
1201 |
|
|
|
1202 |
|
|
id = read_wd33c93(regp, WD_SOURCE_ID);
|
1203 |
|
|
id &= SRCID_MASK;
|
1204 |
|
|
|
1205 |
|
|
/* and extract the lun from the ID message. (Note that we don't
|
1206 |
|
|
* bother to check for a valid message here - I guess this is
|
1207 |
|
|
* not the right way to go, but...)
|
1208 |
|
|
*/
|
1209 |
|
|
|
1210 |
|
|
lun = read_wd33c93(regp, WD_DATA);
|
1211 |
|
|
if (hostdata->level2 < L2_RESELECT)
|
1212 |
|
|
write_wd33c93_cmd(regp,WD_CMD_NEGATE_ACK);
|
1213 |
|
|
lun &= 7;
|
1214 |
|
|
|
1215 |
|
|
/* Now we look for the command that's reconnecting. */
|
1216 |
|
|
|
1217 |
|
|
cmd = (Scsi_Cmnd *)hostdata->disconnected_Q;
|
1218 |
|
|
patch = NULL;
|
1219 |
|
|
while (cmd) {
|
1220 |
|
|
if (id == cmd->target && lun == cmd->lun)
|
1221 |
|
|
break;
|
1222 |
|
|
patch = cmd;
|
1223 |
|
|
cmd = (Scsi_Cmnd *)cmd->host_scribble;
|
1224 |
|
|
}
|
1225 |
|
|
|
1226 |
|
|
/* Hmm. Couldn't find a valid command.... What to do? */
|
1227 |
|
|
|
1228 |
|
|
if (!cmd) {
|
1229 |
|
|
printk("---TROUBLE: target %d.%d not in disconnect queue---",id,lun);
|
1230 |
|
|
return;
|
1231 |
|
|
}
|
1232 |
|
|
|
1233 |
|
|
/* Ok, found the command - now start it up again. */
|
1234 |
|
|
|
1235 |
|
|
if (patch)
|
1236 |
|
|
patch->host_scribble = cmd->host_scribble;
|
1237 |
|
|
else
|
1238 |
|
|
hostdata->disconnected_Q = (Scsi_Cmnd *)cmd->host_scribble;
|
1239 |
|
|
hostdata->connected = cmd;
|
1240 |
|
|
|
1241 |
|
|
/* We don't need to worry about 'initialize_SCp()' or 'hostdata->busy[]'
|
1242 |
|
|
* because these things are preserved over a disconnect.
|
1243 |
|
|
* But we DO need to fix the DPD bit so it's correct for this command.
|
1244 |
|
|
*/
|
1245 |
|
|
|
1246 |
|
|
if (IS_DIR_OUT(cmd))
|
1247 |
|
|
write_wd33c93(regp, WD_DESTINATION_ID, cmd->target);
|
1248 |
|
|
else
|
1249 |
|
|
write_wd33c93(regp, WD_DESTINATION_ID, cmd->target | DSTID_DPD);
|
1250 |
|
|
if (hostdata->level2 >= L2_RESELECT) {
|
1251 |
|
|
write_wd33c93_count(regp, 0); /* we want a DATA_PHASE interrupt */
|
1252 |
|
|
write_wd33c93(regp, WD_COMMAND_PHASE, 0x45);
|
1253 |
|
|
write_wd33c93_cmd(regp, WD_CMD_SEL_ATN_XFER);
|
1254 |
|
|
hostdata->state = S_RUNNING_LEVEL2;
|
1255 |
|
|
}
|
1256 |
|
|
else
|
1257 |
|
|
hostdata->state = S_CONNECTED;
|
1258 |
|
|
|
1259 |
|
|
DB(DB_INTR,printk("-%ld",cmd->pid))
|
1260 |
|
|
break;
|
1261 |
|
|
|
1262 |
|
|
default:
|
1263 |
|
|
printk("--UNKNOWN INTERRUPT:%02x:%02x:%02x--",asr,sr,phs);
|
1264 |
|
|
}
|
1265 |
|
|
|
1266 |
|
|
restore_flags(flags);
|
1267 |
|
|
|
1268 |
|
|
DB(DB_INTR,printk("} "))
|
1269 |
|
|
|
1270 |
|
|
}
|
1271 |
|
|
|
1272 |
|
|
|
1273 |
|
|
|
1274 |
|
|
void reset_wd33c93(struct Scsi_Host *instance)
|
1275 |
|
|
{
|
1276 |
|
|
struct WD33C93_hostdata *hostdata;
|
1277 |
|
|
wd33c93_regs *regp;
|
1278 |
|
|
uchar sr;
|
1279 |
|
|
|
1280 |
|
|
hostdata = (struct WD33C93_hostdata *)instance->hostdata;
|
1281 |
|
|
regp = hostdata->regp;
|
1282 |
|
|
|
1283 |
|
|
write_wd33c93(regp, WD_OWN_ID, OWNID_EAF | OWNID_RAF |
|
1284 |
|
|
instance->this_id | hostdata->clock_freq);
|
1285 |
|
|
write_wd33c93(regp, WD_CONTROL, CTRL_IDI | CTRL_EDI | CTRL_POLLED);
|
1286 |
|
|
write_wd33c93(regp, WD_SYNCHRONOUS_TRANSFER,
|
1287 |
|
|
calc_sync_xfer(hostdata->default_sx_per/4,DEFAULT_SX_OFF));
|
1288 |
|
|
write_wd33c93(regp, WD_COMMAND, WD_CMD_RESET);
|
1289 |
|
|
|
1290 |
|
|
while (!(READ_AUX_STAT() & ASR_INT))
|
1291 |
|
|
;
|
1292 |
|
|
sr = read_wd33c93(regp, WD_SCSI_STATUS);
|
1293 |
|
|
|
1294 |
|
|
hostdata->microcode = read_wd33c93(regp, WD_CDB_1);
|
1295 |
|
|
if (sr == 0x00)
|
1296 |
|
|
hostdata->chip = C_WD33C93;
|
1297 |
|
|
else if (sr == 0x01) {
|
1298 |
|
|
write_wd33c93(regp, WD_QUEUE_TAG, 0xa5); /* any random number */
|
1299 |
|
|
sr = read_wd33c93(regp, WD_QUEUE_TAG);
|
1300 |
|
|
if (sr == 0xa5) {
|
1301 |
|
|
hostdata->chip = C_WD33C93B;
|
1302 |
|
|
write_wd33c93(regp, WD_QUEUE_TAG, 0);
|
1303 |
|
|
}
|
1304 |
|
|
else
|
1305 |
|
|
hostdata->chip = C_WD33C93A;
|
1306 |
|
|
}
|
1307 |
|
|
else
|
1308 |
|
|
hostdata->chip = C_UNKNOWN_CHIP;
|
1309 |
|
|
|
1310 |
|
|
write_wd33c93(regp, WD_TIMEOUT_PERIOD, TIMEOUT_PERIOD_VALUE);
|
1311 |
|
|
write_wd33c93(regp, WD_CONTROL, CTRL_IDI | CTRL_EDI | CTRL_POLLED);
|
1312 |
|
|
}
|
1313 |
|
|
|
1314 |
|
|
|
1315 |
|
|
|
1316 |
|
|
#if LINUX_VERSION_CODE >= 0x010300
|
1317 |
|
|
int wd33c93_reset(Scsi_Cmnd *SCpnt, unsigned int reset_flags)
|
1318 |
|
|
#else
|
1319 |
|
|
int wd33c93_reset(Scsi_Cmnd *SCpnt)
|
1320 |
|
|
#endif
|
1321 |
|
|
{
|
1322 |
|
|
unsigned long flags;
|
1323 |
|
|
struct Scsi_Host *instance;
|
1324 |
|
|
struct WD33C93_hostdata *hostdata;
|
1325 |
|
|
int i;
|
1326 |
|
|
|
1327 |
|
|
instance = SCpnt->host;
|
1328 |
|
|
hostdata = (struct WD33C93_hostdata *)instance->hostdata;
|
1329 |
|
|
|
1330 |
|
|
printk("scsi%d: reset. ", instance->host_no);
|
1331 |
|
|
save_flags(flags);
|
1332 |
|
|
cli();
|
1333 |
|
|
|
1334 |
|
|
((struct WD33C93_hostdata *)instance->hostdata)->dma_stop(instance,NULL,0);
|
1335 |
|
|
for (i = 0; i < 8; i++) {
|
1336 |
|
|
hostdata->busy[i] = 0;
|
1337 |
|
|
hostdata->sync_xfer[i] = calc_sync_xfer(DEFAULT_SX_PER/4,DEFAULT_SX_OFF);
|
1338 |
|
|
hostdata->sync_stat[i] = SS_UNSET; /* using default sync values */
|
1339 |
|
|
}
|
1340 |
|
|
hostdata->input_Q = NULL;
|
1341 |
|
|
hostdata->selecting = NULL;
|
1342 |
|
|
hostdata->connected = NULL;
|
1343 |
|
|
hostdata->disconnected_Q = NULL;
|
1344 |
|
|
hostdata->state = S_UNCONNECTED;
|
1345 |
|
|
hostdata->dma = D_DMA_OFF;
|
1346 |
|
|
hostdata->incoming_ptr = 0;
|
1347 |
|
|
hostdata->outgoing_len = 0;
|
1348 |
|
|
|
1349 |
|
|
reset_wd33c93(instance);
|
1350 |
|
|
SCpnt->result = DID_RESET << 16;
|
1351 |
|
|
restore_flags(flags);
|
1352 |
|
|
return 0;
|
1353 |
|
|
}
|
1354 |
|
|
|
1355 |
|
|
|
1356 |
|
|
|
1357 |
|
|
int wd33c93_abort (Scsi_Cmnd *cmd)
|
1358 |
|
|
{
|
1359 |
|
|
struct Scsi_Host *instance;
|
1360 |
|
|
struct WD33C93_hostdata *hostdata;
|
1361 |
|
|
wd33c93_regs *regp;
|
1362 |
|
|
Scsi_Cmnd *tmp, *prev;
|
1363 |
|
|
unsigned long flags;
|
1364 |
|
|
|
1365 |
|
|
save_flags (flags);
|
1366 |
|
|
cli();
|
1367 |
|
|
|
1368 |
|
|
instance = cmd->host;
|
1369 |
|
|
hostdata = (struct WD33C93_hostdata *)instance->hostdata;
|
1370 |
|
|
regp = hostdata->regp;
|
1371 |
|
|
|
1372 |
|
|
/*
|
1373 |
|
|
* Case 1 : If the command hasn't been issued yet, we simply remove it
|
1374 |
|
|
* from the input_Q.
|
1375 |
|
|
*/
|
1376 |
|
|
|
1377 |
|
|
tmp = (Scsi_Cmnd *)hostdata->input_Q;
|
1378 |
|
|
prev = 0;
|
1379 |
|
|
while (tmp) {
|
1380 |
|
|
if (tmp == cmd) {
|
1381 |
|
|
if (prev)
|
1382 |
|
|
prev->host_scribble = cmd->host_scribble;
|
1383 |
|
|
cmd->host_scribble = NULL;
|
1384 |
|
|
cmd->result = DID_ABORT << 16;
|
1385 |
|
|
printk("scsi%d: Abort - removing command %ld from input_Q. ",
|
1386 |
|
|
instance->host_no, cmd->pid);
|
1387 |
|
|
cmd->scsi_done(cmd);
|
1388 |
|
|
restore_flags(flags);
|
1389 |
|
|
return SCSI_ABORT_SUCCESS;
|
1390 |
|
|
}
|
1391 |
|
|
prev = tmp;
|
1392 |
|
|
tmp = (Scsi_Cmnd *)tmp->host_scribble;
|
1393 |
|
|
}
|
1394 |
|
|
|
1395 |
|
|
/*
|
1396 |
|
|
* Case 2 : If the command is connected, we're going to fail the abort
|
1397 |
|
|
* and let the high level SCSI driver retry at a later time or
|
1398 |
|
|
* issue a reset.
|
1399 |
|
|
*
|
1400 |
|
|
* Timeouts, and therefore aborted commands, will be highly unlikely
|
1401 |
|
|
* and handling them cleanly in this situation would make the common
|
1402 |
|
|
* case of noresets less efficient, and would pollute our code. So,
|
1403 |
|
|
* we fail.
|
1404 |
|
|
*/
|
1405 |
|
|
|
1406 |
|
|
if (hostdata->connected == cmd) {
|
1407 |
|
|
uchar sr, asr;
|
1408 |
|
|
unsigned long timeout;
|
1409 |
|
|
|
1410 |
|
|
printk("scsi%d: Aborting connected command %ld - ",
|
1411 |
|
|
instance->host_no, cmd->pid);
|
1412 |
|
|
|
1413 |
|
|
printk("stopping DMA - ");
|
1414 |
|
|
if (hostdata->dma == D_DMA_RUNNING) {
|
1415 |
|
|
hostdata->dma_stop(instance, cmd, 0);
|
1416 |
|
|
hostdata->dma = D_DMA_OFF;
|
1417 |
|
|
}
|
1418 |
|
|
|
1419 |
|
|
printk("sending wd33c93 ABORT command - ");
|
1420 |
|
|
write_wd33c93(regp, WD_CONTROL, CTRL_IDI | CTRL_EDI | CTRL_POLLED);
|
1421 |
|
|
write_wd33c93_cmd(regp, WD_CMD_ABORT);
|
1422 |
|
|
|
1423 |
|
|
/* Now we have to attempt to flush out the FIFO... */
|
1424 |
|
|
|
1425 |
|
|
printk("flushing fifo - ");
|
1426 |
|
|
timeout = 1000000;
|
1427 |
|
|
do {
|
1428 |
|
|
asr = READ_AUX_STAT();
|
1429 |
|
|
if (asr & ASR_DBR)
|
1430 |
|
|
read_wd33c93(regp, WD_DATA);
|
1431 |
|
|
} while (!(asr & ASR_INT) && timeout-- > 0);
|
1432 |
|
|
sr = read_wd33c93(regp, WD_SCSI_STATUS);
|
1433 |
|
|
printk("asr=%02x, sr=%02x, %ld bytes un-transferred (timeout=%ld) - ",
|
1434 |
|
|
asr, sr, read_wd33c93_count(regp), timeout);
|
1435 |
|
|
|
1436 |
|
|
/*
|
1437 |
|
|
* Abort command processed.
|
1438 |
|
|
* Still connected.
|
1439 |
|
|
* We must disconnect.
|
1440 |
|
|
*/
|
1441 |
|
|
|
1442 |
|
|
printk("sending wd33c93 DISCONNECT command - ");
|
1443 |
|
|
write_wd33c93_cmd(regp, WD_CMD_DISCONNECT);
|
1444 |
|
|
|
1445 |
|
|
timeout = 1000000;
|
1446 |
|
|
asr = READ_AUX_STAT();
|
1447 |
|
|
while ((asr & ASR_CIP) && timeout-- > 0)
|
1448 |
|
|
asr = READ_AUX_STAT();
|
1449 |
|
|
sr = read_wd33c93(regp, WD_SCSI_STATUS);
|
1450 |
|
|
printk("asr=%02x, sr=%02x.",asr,sr);
|
1451 |
|
|
|
1452 |
|
|
hostdata->busy[cmd->target] &= ~(1 << cmd->lun);
|
1453 |
|
|
hostdata->connected = NULL;
|
1454 |
|
|
hostdata->state = S_UNCONNECTED;
|
1455 |
|
|
cmd->result = DID_ABORT << 16;
|
1456 |
|
|
cmd->scsi_done(cmd);
|
1457 |
|
|
|
1458 |
|
|
/* sti();*/
|
1459 |
|
|
wd33c93_execute (instance);
|
1460 |
|
|
|
1461 |
|
|
restore_flags(flags);
|
1462 |
|
|
return SCSI_ABORT_SUCCESS;
|
1463 |
|
|
}
|
1464 |
|
|
|
1465 |
|
|
/*
|
1466 |
|
|
* Case 3: If the command is currently disconnected from the bus,
|
1467 |
|
|
* we're not going to expend much effort here: Let's just return
|
1468 |
|
|
* an ABORT_SNOOZE and hope for the best...
|
1469 |
|
|
*/
|
1470 |
|
|
|
1471 |
|
|
tmp = (Scsi_Cmnd *)hostdata->disconnected_Q;
|
1472 |
|
|
while (tmp) {
|
1473 |
|
|
if (tmp == cmd) {
|
1474 |
|
|
printk("scsi%d: Abort - command %ld found on disconnected_Q - ",
|
1475 |
|
|
instance->host_no, cmd->pid);
|
1476 |
|
|
printk("returning ABORT_SNOOZE. ");
|
1477 |
|
|
restore_flags(flags);
|
1478 |
|
|
return SCSI_ABORT_SNOOZE;
|
1479 |
|
|
}
|
1480 |
|
|
tmp = (Scsi_Cmnd *)tmp->host_scribble;
|
1481 |
|
|
}
|
1482 |
|
|
|
1483 |
|
|
/*
|
1484 |
|
|
* Case 4 : If we reached this point, the command was not found in any of
|
1485 |
|
|
* the queues.
|
1486 |
|
|
*
|
1487 |
|
|
* We probably reached this point because of an unlikely race condition
|
1488 |
|
|
* between the command completing successfully and the abortion code,
|
1489 |
|
|
* so we won't panic, but we will notify the user in case something really
|
1490 |
|
|
* broke.
|
1491 |
|
|
*/
|
1492 |
|
|
|
1493 |
|
|
/* sti();*/
|
1494 |
|
|
wd33c93_execute (instance);
|
1495 |
|
|
|
1496 |
|
|
restore_flags(flags);
|
1497 |
|
|
printk("scsi%d: warning : SCSI command probably completed successfully"
|
1498 |
|
|
" before abortion. ", instance->host_no);
|
1499 |
|
|
return SCSI_ABORT_NOT_RUNNING;
|
1500 |
|
|
}
|
1501 |
|
|
|
1502 |
|
|
|
1503 |
|
|
|
1504 |
|
|
#define MAX_WD33C93_HOSTS 4
|
1505 |
|
|
#define MAX_SETUP_STRINGS (sizeof(setup_strings) / sizeof(char *))
|
1506 |
|
|
#define SETUP_BUFFER_SIZE 200
|
1507 |
|
|
static char setup_buffer[SETUP_BUFFER_SIZE];
|
1508 |
|
|
static char setup_used[MAX_SETUP_STRINGS];
|
1509 |
|
|
|
1510 |
|
|
void wd33c93_setup (char *str, int *ints)
|
1511 |
|
|
{
|
1512 |
|
|
int i,x;
|
1513 |
|
|
char *p1,*p2;
|
1514 |
|
|
|
1515 |
|
|
/* The kernel does some processing of the command-line before calling
|
1516 |
|
|
* this function: If it begins with any decimal or hex number arguments,
|
1517 |
|
|
* ints[0] = how many numbers found and ints[1] through [n] are the values
|
1518 |
|
|
* themselves. str points to where the non-numeric arguments (if any)
|
1519 |
|
|
* start: We do our own parsing of those. We construct synthetic 'nosync'
|
1520 |
|
|
* keywords out of numeric args (to maintain compatibility with older
|
1521 |
|
|
* versions) and then add the rest of the arguments.
|
1522 |
|
|
*/
|
1523 |
|
|
|
1524 |
|
|
p1 = setup_buffer;
|
1525 |
|
|
*p1 = '\0';
|
1526 |
|
|
if (ints[0]) {
|
1527 |
|
|
for (i=0; i<ints[0]; i++) {
|
1528 |
|
|
x = vsprintf(p1,"nosync:0x%02x,",&(ints[i+1]));
|
1529 |
|
|
p1 += x;
|
1530 |
|
|
}
|
1531 |
|
|
}
|
1532 |
|
|
if (str)
|
1533 |
|
|
strncpy(p1, str, SETUP_BUFFER_SIZE - strlen(setup_buffer));
|
1534 |
|
|
setup_buffer[SETUP_BUFFER_SIZE - 1] = '\0';
|
1535 |
|
|
p1 = setup_buffer;
|
1536 |
|
|
i = 0;
|
1537 |
|
|
while (*p1 && (i < MAX_SETUP_STRINGS)) {
|
1538 |
|
|
p2 = strchr(p1, ',');
|
1539 |
|
|
if (p2) {
|
1540 |
|
|
*p2 = '\0';
|
1541 |
|
|
if (p1 != p2)
|
1542 |
|
|
setup_strings[i] = p1;
|
1543 |
|
|
p1 = p2 + 1;
|
1544 |
|
|
i++;
|
1545 |
|
|
}
|
1546 |
|
|
else {
|
1547 |
|
|
setup_strings[i] = p1;
|
1548 |
|
|
break;
|
1549 |
|
|
}
|
1550 |
|
|
}
|
1551 |
|
|
for (i=0; i<MAX_SETUP_STRINGS; i++)
|
1552 |
|
|
setup_used[i] = 0;
|
1553 |
|
|
}
|
1554 |
|
|
|
1555 |
|
|
|
1556 |
|
|
/* check_setup_strings() returns index if key found, 0 if not
|
1557 |
|
|
*/
|
1558 |
|
|
|
1559 |
|
|
int check_setup_strings(char *key, int *flags, int *val, char *buf)
|
1560 |
|
|
{
|
1561 |
|
|
int x;
|
1562 |
|
|
char *cp;
|
1563 |
|
|
|
1564 |
|
|
for (x=0; x<MAX_SETUP_STRINGS; x++) {
|
1565 |
|
|
if (setup_used[x])
|
1566 |
|
|
continue;
|
1567 |
|
|
if (!strncmp(setup_strings[x], key, strlen(key)))
|
1568 |
|
|
break;
|
1569 |
|
|
if (!strncmp(setup_strings[x], "next", strlen("next")))
|
1570 |
|
|
return 0;
|
1571 |
|
|
}
|
1572 |
|
|
if (x == MAX_SETUP_STRINGS)
|
1573 |
|
|
return 0;
|
1574 |
|
|
setup_used[x] = 1;
|
1575 |
|
|
cp = setup_strings[x] + strlen(key);
|
1576 |
|
|
*val = -1;
|
1577 |
|
|
if (*cp != ':')
|
1578 |
|
|
return ++x;
|
1579 |
|
|
cp++;
|
1580 |
|
|
if ((*cp >= '0') && (*cp <= '9')) {
|
1581 |
|
|
*val = simple_strtoul(cp,NULL,0);
|
1582 |
|
|
}
|
1583 |
|
|
return ++x;
|
1584 |
|
|
}
|
1585 |
|
|
|
1586 |
|
|
|
1587 |
|
|
|
1588 |
|
|
void wd33c93_init (struct Scsi_Host *instance, wd33c93_regs *regs,
|
1589 |
|
|
dma_setup_t setup, dma_stop_t stop, int clock_freq)
|
1590 |
|
|
{
|
1591 |
|
|
struct WD33C93_hostdata *hostdata;
|
1592 |
|
|
int i;
|
1593 |
|
|
int flags;
|
1594 |
|
|
int val;
|
1595 |
|
|
char buf[32];
|
1596 |
|
|
|
1597 |
|
|
hostdata = (struct WD33C93_hostdata *)instance->hostdata;
|
1598 |
|
|
|
1599 |
|
|
hostdata->regp = regs;
|
1600 |
|
|
hostdata->clock_freq = clock_freq;
|
1601 |
|
|
hostdata->dma_setup = setup;
|
1602 |
|
|
hostdata->dma_stop = stop;
|
1603 |
|
|
hostdata->dma_bounce_buffer = NULL;
|
1604 |
|
|
hostdata->dma_bounce_len = 0;
|
1605 |
|
|
for (i = 0; i < 8; i++) {
|
1606 |
|
|
hostdata->busy[i] = 0;
|
1607 |
|
|
hostdata->sync_xfer[i] = calc_sync_xfer(DEFAULT_SX_PER/4,DEFAULT_SX_OFF);
|
1608 |
|
|
hostdata->sync_stat[i] = SS_UNSET; /* using default sync values */
|
1609 |
|
|
}
|
1610 |
|
|
hostdata->input_Q = NULL;
|
1611 |
|
|
hostdata->selecting = NULL;
|
1612 |
|
|
hostdata->connected = NULL;
|
1613 |
|
|
hostdata->disconnected_Q = NULL;
|
1614 |
|
|
hostdata->state = S_UNCONNECTED;
|
1615 |
|
|
hostdata->dma = D_DMA_OFF;
|
1616 |
|
|
hostdata->level2 = L2_BASIC;
|
1617 |
|
|
hostdata->disconnect = DIS_ADAPTIVE;
|
1618 |
|
|
hostdata->args = DEBUG_DEFAULTS;
|
1619 |
|
|
hostdata->incoming_ptr = 0;
|
1620 |
|
|
hostdata->outgoing_len = 0;
|
1621 |
|
|
hostdata->default_sx_per = DEFAULT_SX_PER;
|
1622 |
|
|
hostdata->no_sync = 0xff; /* sync defaults to off */
|
1623 |
|
|
|
1624 |
|
|
#ifdef PROC_INTERFACE
|
1625 |
|
|
hostdata->proc = PR_VERSION|PR_INFO|PR_TOTALS|
|
1626 |
|
|
PR_CONNECTED|PR_INPUTQ|PR_DISCQ|
|
1627 |
|
|
PR_STOP;
|
1628 |
|
|
|
1629 |
|
|
disc_allowed_total = 0;
|
1630 |
|
|
disc_taken_total = 0;
|
1631 |
|
|
#endif
|
1632 |
|
|
|
1633 |
|
|
|
1634 |
|
|
if (check_setup_strings("nosync",&flags,&val,buf))
|
1635 |
|
|
hostdata->no_sync = val;
|
1636 |
|
|
|
1637 |
|
|
if (check_setup_strings("period",&flags,&val,buf))
|
1638 |
|
|
hostdata->default_sx_per = sx_table[round_period((unsigned int)val)].period_ns;
|
1639 |
|
|
|
1640 |
|
|
if (check_setup_strings("disconnect",&flags,&val,buf)) {
|
1641 |
|
|
if ((val >= DIS_NEVER) && (val <= DIS_ALWAYS))
|
1642 |
|
|
hostdata->disconnect = val;
|
1643 |
|
|
else
|
1644 |
|
|
hostdata->disconnect = DIS_ADAPTIVE;
|
1645 |
|
|
}
|
1646 |
|
|
|
1647 |
|
|
if (check_setup_strings("debug",&flags,&val,buf))
|
1648 |
|
|
hostdata->args = val & DB_MASK;
|
1649 |
|
|
|
1650 |
|
|
if (check_setup_strings("clock",&flags,&val,buf)) {
|
1651 |
|
|
if (val>7 && val<11)
|
1652 |
|
|
val = WD33C93_FS_8_10;
|
1653 |
|
|
else if (val>11 && val<16)
|
1654 |
|
|
val = WD33C93_FS_12_15;
|
1655 |
|
|
else if (val>15 && val<21)
|
1656 |
|
|
val = WD33C93_FS_16_20;
|
1657 |
|
|
else
|
1658 |
|
|
val = WD33C93_FS_8_10;
|
1659 |
|
|
hostdata->clock_freq = val;
|
1660 |
|
|
}
|
1661 |
|
|
|
1662 |
|
|
if ((i = check_setup_strings("next",&flags,&val,buf))) {
|
1663 |
|
|
while (i)
|
1664 |
|
|
setup_used[--i] = 1;
|
1665 |
|
|
}
|
1666 |
|
|
|
1667 |
|
|
#ifdef PROC_INTERFACE
|
1668 |
|
|
if (check_setup_strings("proc",&flags,&val,buf))
|
1669 |
|
|
hostdata->proc = val;
|
1670 |
|
|
#endif
|
1671 |
|
|
|
1672 |
|
|
|
1673 |
|
|
cli();
|
1674 |
|
|
reset_wd33c93(instance);
|
1675 |
|
|
sti();
|
1676 |
|
|
|
1677 |
|
|
printk("wd33c93-%d: chip=%s microcode=%02x\n",instance->host_no,
|
1678 |
|
|
(hostdata->chip==C_WD33C93)?"WD33c93":
|
1679 |
|
|
(hostdata->chip==C_WD33C93A)?"WD33c93A":
|
1680 |
|
|
(hostdata->chip==C_WD33C93B)?"WD33c93B":"unknown",
|
1681 |
|
|
hostdata->microcode);
|
1682 |
|
|
|
1683 |
|
|
#ifdef DEBUGGING_ON
|
1684 |
|
|
printk("wd33c93-%d: setup_strings=",instance->host_no);
|
1685 |
|
|
for (i=0; i<MAX_SETUP_STRINGS; i++)
|
1686 |
|
|
printk("%s,",setup_strings[i]);
|
1687 |
|
|
printk("\n");
|
1688 |
|
|
printk("wd33c93-%d: debug_flags = %04x\n",instance->host_no,hostdata->args);
|
1689 |
|
|
#endif
|
1690 |
|
|
printk("wd33c93-%d: driver version %s - %s\n",instance->host_no,
|
1691 |
|
|
WD33C93_VERSION,WD33C93_DATE);
|
1692 |
|
|
printk("wd33c93-%d: compiled on %s at %s\n",instance->host_no,
|
1693 |
|
|
__DATE__,__TIME__);
|
1694 |
|
|
}
|
1695 |
|
|
|
1696 |
|
|
|
1697 |
|
|
int wd33c93_proc_info(char *buf, char **start, off_t off, int len, int hn, int in)
|
1698 |
|
|
{
|
1699 |
|
|
|
1700 |
|
|
#ifdef PROC_INTERFACE
|
1701 |
|
|
|
1702 |
|
|
char *bp;
|
1703 |
|
|
char tbuf[128];
|
1704 |
|
|
unsigned long flags;
|
1705 |
|
|
struct Scsi_Host *instance;
|
1706 |
|
|
struct WD33C93_hostdata *hd;
|
1707 |
|
|
Scsi_Cmnd *cmd;
|
1708 |
|
|
int x,i;
|
1709 |
|
|
static int stop = 0;
|
1710 |
|
|
|
1711 |
|
|
for (instance=instance_list; instance; instance=instance->next) {
|
1712 |
|
|
if (instance->host_no == hn)
|
1713 |
|
|
break;
|
1714 |
|
|
}
|
1715 |
|
|
if (!instance) {
|
1716 |
|
|
printk("*** Hmm... Can't find host #%d!\n",hn);
|
1717 |
|
|
return (-ESRCH);
|
1718 |
|
|
}
|
1719 |
|
|
hd = (struct WD33C93_hostdata *)instance->hostdata;
|
1720 |
|
|
|
1721 |
|
|
/* If 'in' is TRUE we need to _read_ the proc file. We accept the following
|
1722 |
|
|
* keywords (same format as command-line, but only ONE per read):
|
1723 |
|
|
* debug
|
1724 |
|
|
* disconnect
|
1725 |
|
|
* period
|
1726 |
|
|
* resync
|
1727 |
|
|
* proc
|
1728 |
|
|
*/
|
1729 |
|
|
|
1730 |
|
|
if (in) {
|
1731 |
|
|
buf[len] = '\0';
|
1732 |
|
|
bp = buf;
|
1733 |
|
|
if (!strncmp(bp,"debug:",6)) {
|
1734 |
|
|
bp += 6;
|
1735 |
|
|
hd->args = simple_strtoul(bp,NULL,0) & DB_MASK;
|
1736 |
|
|
}
|
1737 |
|
|
else if (!strncmp(bp,"disconnect:",11)) {
|
1738 |
|
|
bp += 11;
|
1739 |
|
|
x = simple_strtoul(bp,NULL,0);
|
1740 |
|
|
if (x < DIS_NEVER || x > DIS_ALWAYS)
|
1741 |
|
|
x = DIS_ADAPTIVE;
|
1742 |
|
|
hd->disconnect = x;
|
1743 |
|
|
}
|
1744 |
|
|
else if (!strncmp(bp,"period:",7)) {
|
1745 |
|
|
bp += 7;
|
1746 |
|
|
x = simple_strtoul(bp,NULL,0);
|
1747 |
|
|
hd->default_sx_per = sx_table[round_period((unsigned int)x)].period_ns;
|
1748 |
|
|
}
|
1749 |
|
|
else if (!strncmp(bp,"resync:",7)) {
|
1750 |
|
|
bp += 7;
|
1751 |
|
|
x = simple_strtoul(bp,NULL,0);
|
1752 |
|
|
for (i=0; i<7; i++)
|
1753 |
|
|
if (x & (1<<i))
|
1754 |
|
|
hd->sync_stat[i] = SS_UNSET;
|
1755 |
|
|
}
|
1756 |
|
|
else if (!strncmp(bp,"proc:",5)) {
|
1757 |
|
|
bp += 5;
|
1758 |
|
|
hd->proc = simple_strtoul(bp,NULL,0);
|
1759 |
|
|
}
|
1760 |
|
|
return len;
|
1761 |
|
|
}
|
1762 |
|
|
|
1763 |
|
|
save_flags(flags);
|
1764 |
|
|
cli();
|
1765 |
|
|
bp = buf;
|
1766 |
|
|
*bp = '\0';
|
1767 |
|
|
if (hd->proc & PR_VERSION) {
|
1768 |
|
|
sprintf(tbuf,"\nVersion %s - %s. Compiled %s %s",
|
1769 |
|
|
WD33C93_VERSION,WD33C93_DATE,__DATE__,__TIME__);
|
1770 |
|
|
strcat(bp,tbuf);
|
1771 |
|
|
}
|
1772 |
|
|
if (hd->proc & PR_INFO) {
|
1773 |
|
|
;
|
1774 |
|
|
}
|
1775 |
|
|
if (hd->proc & PR_TOTALS) {
|
1776 |
|
|
sprintf(tbuf,"\n%ld disc_allowed, %ld disc_taken",
|
1777 |
|
|
disc_allowed_total,disc_taken_total);
|
1778 |
|
|
strcat(bp,tbuf);
|
1779 |
|
|
}
|
1780 |
|
|
if (hd->proc & PR_CONNECTED) {
|
1781 |
|
|
strcat(bp,"\nconnected: ");
|
1782 |
|
|
if (hd->connected) {
|
1783 |
|
|
cmd = (Scsi_Cmnd *)hd->connected;
|
1784 |
|
|
sprintf(tbuf," %ld-%d:%d(%02x)",
|
1785 |
|
|
cmd->pid, cmd->target, cmd->lun, cmd->cmnd[0]);
|
1786 |
|
|
strcat(bp,tbuf);
|
1787 |
|
|
}
|
1788 |
|
|
}
|
1789 |
|
|
if (hd->proc & PR_INPUTQ) {
|
1790 |
|
|
strcat(bp,"\ninput_Q: ");
|
1791 |
|
|
cmd = (Scsi_Cmnd *)hd->input_Q;
|
1792 |
|
|
while (cmd) {
|
1793 |
|
|
sprintf(tbuf," %ld-%d:%d(%02x)",
|
1794 |
|
|
cmd->pid, cmd->target, cmd->lun, cmd->cmnd[0]);
|
1795 |
|
|
strcat(bp,tbuf);
|
1796 |
|
|
cmd = (Scsi_Cmnd *)cmd->host_scribble;
|
1797 |
|
|
}
|
1798 |
|
|
}
|
1799 |
|
|
if (hd->proc & PR_DISCQ) {
|
1800 |
|
|
strcat(bp,"\ndisconnected_Q:");
|
1801 |
|
|
cmd = (Scsi_Cmnd *)hd->disconnected_Q;
|
1802 |
|
|
while (cmd) {
|
1803 |
|
|
sprintf(tbuf," %ld-%d:%d(%02x)",
|
1804 |
|
|
cmd->pid, cmd->target, cmd->lun, cmd->cmnd[0]);
|
1805 |
|
|
strcat(bp,tbuf);
|
1806 |
|
|
cmd = (Scsi_Cmnd *)cmd->host_scribble;
|
1807 |
|
|
}
|
1808 |
|
|
}
|
1809 |
|
|
strcat(bp,"\n");
|
1810 |
|
|
restore_flags(flags);
|
1811 |
|
|
*start = buf;
|
1812 |
|
|
if (stop) {
|
1813 |
|
|
stop = 0;
|
1814 |
|
|
return 0;
|
1815 |
|
|
}
|
1816 |
|
|
if (off > 0x40000) /* ALWAYS stop after 256k bytes have been read */
|
1817 |
|
|
stop = 1;;
|
1818 |
|
|
if (hd->proc & PR_STOP) /* stop every other time */
|
1819 |
|
|
stop = 1;
|
1820 |
|
|
return strlen(bp);
|
1821 |
|
|
|
1822 |
|
|
#else /* PROC_INTERFACE */
|
1823 |
|
|
|
1824 |
|
|
return 0;
|
1825 |
|
|
|
1826 |
|
|
#endif /* PROC_INTERFACE */
|
1827 |
|
|
|
1828 |
|
|
}
|
1829 |
|
|
|
1830 |
|
|
|
1831 |
|
|
#ifdef MODULE
|
1832 |
|
|
|
1833 |
|
|
Scsi_Host_Template driver_template = WD33C93;
|
1834 |
|
|
|
1835 |
|
|
#include "scsi_module.c"
|
1836 |
|
|
|
1837 |
|
|
#endif
|
1838 |
|
|
|