2 * in2000.c - Linux device driver for the
3 * Always IN2000 ISA SCSI card.
5 * Copyright (c) 1996 John Shifflett, GeoLog Consulting
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)
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.
19 * For the avoidance of doubt the "preferred form" of this code is one which
20 * is in an open non patent encumbered format. Where cryptographic key signing
21 * forms part of the process of creating an executable the information
22 * including keys needed to generate an equivalently functional executable
23 * are deemed to be part of the source code.
25 * Drew Eckhardt's excellent 'Generic NCR5380' sources provided
26 * much of the inspiration and some of the code for this driver.
27 * The Linux IN2000 driver distributed in the Linux kernels through
28 * version 1.2.13 was an extremely valuable reference on the arcane
29 * (and still mysterious) workings of the IN2000's fifo. It also
30 * is where I lifted in2000_biosparam(), the gist of the card
31 * detection scheme, and other bits of code. Many thanks to the
32 * talented and courageous people who wrote, contributed to, and
33 * maintained that driver (including Brad McLean, Shaun Savage,
34 * Bill Earnest, Larry Doolittle, Roger Sunshine, John Luckey,
35 * Matt Postiff, Peter Lu, zerucha@shell.portal.com, and Eric
36 * Youngdale). I should also mention the driver written by
37 * Hamish Macdonald for the (GASP!) Amiga A2091 card, included
38 * in the Linux-m68k distribution; it gave me a good initial
39 * understanding of the proper way to run a WD33c93 chip, and I
40 * ended up stealing lots of code from it.
42 * _This_ driver is (I feel) an improvement over the old one in
44 * - All problems relating to the data size of a SCSI request are
45 * gone (as far as I know). The old driver couldn't handle
46 * swapping to partitions because that involved 4k blocks, nor
47 * could it deal with the st.c tape driver unmodified, because
48 * that usually involved 4k - 32k blocks. The old driver never
49 * quite got away from a morbid dependence on 2k block sizes -
50 * which of course is the size of the card's fifo.
52 * - Target Disconnection/Reconnection is now supported. Any
53 * system with more than one device active on the SCSI bus
54 * will benefit from this. The driver defaults to what I'm
55 * calling 'adaptive disconnect' - meaning that each command
56 * is evaluated individually as to whether or not it should
57 * be run with the option to disconnect/reselect (if the
58 * device chooses), or as a "SCSI-bus-hog".
60 * - Synchronous data transfers are now supported. Because there
61 * are a few devices (and many improperly terminated systems)
62 * that choke when doing sync, the default is sync DISABLED
63 * for all devices. This faster protocol can (and should!)
64 * be enabled on selected devices via the command-line.
66 * - Runtime operating parameters can now be specified through
67 * either the LILO or the 'insmod' command line. For LILO do:
68 * "in2000=blah,blah,blah"
69 * and with insmod go like:
70 * "insmod /usr/src/linux/modules/in2000.o setup_strings=blah,blah"
71 * The defaults should be good for most people. See the comment
72 * for 'setup_strings' below for more details.
74 * - The old driver relied exclusively on what the Western Digital
75 * docs call "Combination Level 2 Commands", which are a great
76 * idea in that the CPU is relieved of a lot of interrupt
77 * overhead. However, by accepting a certain (user-settable)
78 * amount of additional interrupts, this driver achieves
79 * better control over the SCSI bus, and data transfers are
80 * almost as fast while being much easier to define, track,
83 * - You can force detection of a card whose BIOS has been disabled.
85 * - Multiple IN2000 cards might almost be supported. I've tried to
86 * keep it in mind, but have no way to test...
90 * tagged queuing. multiple cards.
94 * When using this or any other SCSI driver as a module, you'll
95 * find that with the stock kernel, at most _two_ SCSI hard
96 * drives will be linked into the device list (ie, usable).
97 * If your IN2000 card has more than 2 disks on its bus, you
98 * might want to change the define of 'SD_EXTRA_DEVS' in the
99 * 'hosts.h' file from 2 to whatever is appropriate. It took
100 * me a while to track down this surprisingly obscure and
101 * undocumented little "feature".
104 * People with bug reports, wish-lists, complaints, comments,
105 * or improvements are asked to pah-leeez email me (John Shifflett)
106 * at john@geolog.com or jshiffle@netcom.com! I'm anxious to get
107 * this thing into as good a shape as possible, and I'm positive
108 * there are lots of lurking bugs and "Stupid Places".
110 * Updated for Linux 2.5 by Alan Cox <alan@redhat.com>
111 * - Using new_eh handler
112 * - Hopefully got all the locking right again
113 * See "FIXME" notes for items that could do with more work
116 #include <linux/module.h>
117 #include <linux/blkdev.h>
118 #include <linux/interrupt.h>
119 #include <linux/string.h>
120 #include <linux/delay.h>
121 #include <linux/proc_fs.h>
122 #include <linux/ioport.h>
123 #include <linux/stat.h>
126 #include <asm/system.h>
131 #define IN2000_VERSION "1.33-2.5"
132 #define IN2000_DATE "2002/11/03"
138 * 'setup_strings' is a single string used to pass operating parameters and
139 * settings from the kernel/module command-line to the driver. 'setup_args[]'
140 * is an array of strings that define the compile-time default values for
141 * these settings. If Linux boots with a LILO or insmod command-line, those
142 * settings are combined with 'setup_args[]'. Note that LILO command-lines
143 * are prefixed with "in2000=" while insmod uses a "setup_strings=" prefix.
144 * The driver recognizes the following keywords (lower case required) and
147 * - ioport:addr -Where addr is IO address of a (usually ROM-less) card.
148 * - noreset -No optional args. Prevents SCSI bus reset at boot time.
149 * - nosync:x -x is a bitmask where the 1st 7 bits correspond with
150 * the 7 possible SCSI devices (bit 0 for device #0, etc).
151 * Set a bit to PREVENT sync negotiation on that device.
152 * The driver default is sync DISABLED on all devices.
153 * - period:ns -ns is the minimum # of nanoseconds in a SCSI data transfer
154 * period. Default is 500; acceptable values are 250 - 1000.
155 * - disconnect:x -x = 0 to never allow disconnects, 2 to always allow them.
156 * x = 1 does 'adaptive' disconnects, which is the default
157 * and generally the best choice.
158 * - debug:x -If 'DEBUGGING_ON' is defined, x is a bitmask that causes
159 * various types of debug output to printed - see the DB_xxx
160 * defines in in2000.h
161 * - proc:x -If 'PROC_INTERFACE' is defined, x is a bitmask that
162 * determines how the /proc interface works and what it
163 * does - see the PR_xxx defines in in2000.h
166 * - Numeric arguments can be decimal or the '0x' form of hex notation. There
167 * _must_ be a colon between a keyword and its numeric argument, with no
169 * - Keywords are separated by commas, no spaces, in the standard kernel
170 * command-line manner.
171 * - A keyword in the 'nth' comma-separated command-line member will overwrite
172 * the 'nth' element of setup_args[]. A blank command-line member (in
173 * other words, a comma with no preceding keyword) will _not_ overwrite
174 * the corresponding setup_args[] element.
176 * A few LILO examples (for insmod, use 'setup_strings' instead of 'in2000'):
177 * - in2000=ioport:0x220,noreset
178 * - in2000=period:250,disconnect:2,nosync:0x03
179 * - in2000=debug:0x1e
183 /* Normally, no defaults are specified... */
184 static char *setup_args[] = { "", "", "", "", "", "", "", "", "" };
186 /* filled in by 'insmod' */
187 static char *setup_strings = 0;
190 MODULE_PARM(setup_strings, "s");
193 static inline uchar read_3393(struct IN2000_hostdata *hostdata, uchar reg_num)
195 write1_io(reg_num, IO_WD_ADDR);
196 return read1_io(IO_WD_DATA);
200 #define READ_AUX_STAT() read1_io(IO_WD_ASR)
203 static inline void write_3393(struct IN2000_hostdata *hostdata, uchar reg_num, uchar value)
205 write1_io(reg_num, IO_WD_ADDR);
206 write1_io(value, IO_WD_DATA);
210 static inline void write_3393_cmd(struct IN2000_hostdata *hostdata, uchar cmd)
212 /* while (READ_AUX_STAT() & ASR_CIP)
214 write1_io(WD_COMMAND, IO_WD_ADDR);
215 write1_io(cmd, IO_WD_DATA);
219 static uchar read_1_byte(struct IN2000_hostdata *hostdata)
223 write_3393(hostdata, WD_CONTROL, CTRL_IDI | CTRL_EDI | CTRL_POLLED);
224 write_3393_cmd(hostdata, WD_CMD_TRANS_INFO | 0x80);
226 asr = READ_AUX_STAT();
228 x = read_3393(hostdata, WD_DATA);
229 } while (!(asr & ASR_INT));
234 static void write_3393_count(struct IN2000_hostdata *hostdata, unsigned long value)
236 write1_io(WD_TRANSFER_COUNT_MSB, IO_WD_ADDR);
237 write1_io((value >> 16), IO_WD_DATA);
238 write1_io((value >> 8), IO_WD_DATA);
239 write1_io(value, IO_WD_DATA);
243 static unsigned long read_3393_count(struct IN2000_hostdata *hostdata)
247 write1_io(WD_TRANSFER_COUNT_MSB, IO_WD_ADDR);
248 value = read1_io(IO_WD_DATA) << 16;
249 value |= read1_io(IO_WD_DATA) << 8;
250 value |= read1_io(IO_WD_DATA);
255 /* The 33c93 needs to be told which direction a command transfers its
256 * data; we use this function to figure it out. Returns true if there
257 * will be a DATA_OUT phase with this command, false otherwise.
258 * (Thanks to Joerg Dorchain for the research and suggestion.)
260 static int is_dir_out(Scsi_Cmnd * cmd)
262 switch (cmd->cmnd[0]) {
270 case WRITE_VERIFY_12:
277 case SEARCH_EQUAL_12:
281 case REASSIGN_BLOCKS:
286 case SEND_DIAGNOSTIC:
287 case CHANGE_DEFINITION:
291 case SEND_VOLUME_TAG:
301 static struct sx_period sx_table[] = {
313 static int round_period(unsigned int period)
317 for (x = 1; sx_table[x].period_ns; x++) {
318 if ((period <= sx_table[x - 0].period_ns) && (period > sx_table[x - 1].period_ns)) {
325 static uchar calc_sync_xfer(unsigned int period, unsigned int offset)
329 period *= 4; /* convert SDTR code to ns */
330 result = sx_table[round_period(period)].reg_value;
331 result |= (offset < OPTIMUM_SX_OFF) ? offset : OPTIMUM_SX_OFF;
337 static void in2000_execute(struct Scsi_Host *instance);
339 static int in2000_queuecommand(Scsi_Cmnd * cmd, void (*done) (Scsi_Cmnd *))
341 struct Scsi_Host *instance;
342 struct IN2000_hostdata *hostdata;
345 instance = cmd->device->host;
346 hostdata = (struct IN2000_hostdata *) instance->hostdata;
348 DB(DB_QUEUE_COMMAND, printk("Q-%d-%02x-%ld(", cmd->device->id, cmd->cmnd[0], cmd->pid))
350 /* Set up a few fields in the Scsi_Cmnd structure for our own use:
351 * - host_scribble is the pointer to the next cmd in the input queue
352 * - scsi_done points to the routine we call when a cmd is finished
353 * - result is what you'd expect
355 cmd->host_scribble = NULL;
356 cmd->scsi_done = done;
359 /* We use the Scsi_Pointer structure that's included with each command
360 * as a scratchpad (as it's intended to be used!). The handy thing about
361 * the SCp.xxx fields is that they're always associated with a given
362 * cmd, and are preserved across disconnect-reselect. This means we
363 * can pretty much ignore SAVE_POINTERS and RESTORE_POINTERS messages
364 * if we keep all the critical pointers and counters in SCp:
365 * - SCp.ptr is the pointer into the RAM buffer
366 * - SCp.this_residual is the size of that buffer
367 * - SCp.buffer points to the current scatter-gather buffer
368 * - SCp.buffers_residual tells us how many S.G. buffers there are
369 * - SCp.have_data_in helps keep track of >2048 byte transfers
370 * - SCp.sent_command is not used
371 * - SCp.phase records this command's SRCID_ER bit setting
375 cmd->SCp.buffer = (struct scatterlist *) cmd->buffer;
376 cmd->SCp.buffers_residual = cmd->use_sg - 1;
377 cmd->SCp.ptr = (char *) page_address(cmd->SCp.buffer->page) + cmd->SCp.buffer->offset;
378 cmd->SCp.this_residual = cmd->SCp.buffer->length;
380 cmd->SCp.buffer = NULL;
381 cmd->SCp.buffers_residual = 0;
382 cmd->SCp.ptr = (char *) cmd->request_buffer;
383 cmd->SCp.this_residual = cmd->request_bufflen;
385 cmd->SCp.have_data_in = 0;
387 /* We don't set SCp.phase here - that's done in in2000_execute() */
389 /* WD docs state that at the conclusion of a "LEVEL2" command, the
390 * status byte can be retrieved from the LUN register. Apparently,
391 * this is the case only for *uninterrupted* LEVEL2 commands! If
392 * there are any unexpected phases entered, even if they are 100%
393 * legal (different devices may choose to do things differently),
394 * the LEVEL2 command sequence is exited. This often occurs prior
395 * to receiving the status byte, in which case the driver does a
396 * status phase interrupt and gets the status byte on its own.
397 * While such a command can then be "resumed" (ie restarted to
398 * finish up as a LEVEL2 command), the LUN register will NOT be
399 * a valid status byte at the command's conclusion, and we must
400 * use the byte obtained during the earlier interrupt. Here, we
401 * preset SCp.Status to an illegal value (0xff) so that when
402 * this command finally completes, we can tell where the actual
403 * status byte is stored.
406 cmd->SCp.Status = ILLEGAL_STATUS_BYTE;
408 /* We need to disable interrupts before messing with the input
409 * queue and calling in2000_execute().
413 * Add the cmd to the end of 'input_Q'. Note that REQUEST_SENSE
414 * commands are added to the head of the queue so that the desired
415 * sense data is not lost before REQUEST_SENSE executes.
418 if (!(hostdata->input_Q) || (cmd->cmnd[0] == REQUEST_SENSE)) {
419 cmd->host_scribble = (uchar *) hostdata->input_Q;
420 hostdata->input_Q = cmd;
421 } else { /* find the end of the queue */
422 for (tmp = (Scsi_Cmnd *) hostdata->input_Q; tmp->host_scribble; tmp = (Scsi_Cmnd *) tmp->host_scribble);
423 tmp->host_scribble = (uchar *) cmd;
426 /* We know that there's at least one command in 'input_Q' now.
427 * Go see if any of them are runnable!
430 in2000_execute(cmd->device->host);
432 DB(DB_QUEUE_COMMAND, printk(")Q-%ld ", cmd->pid))
439 * This routine attempts to start a scsi command. If the host_card is
440 * already connected, we give up immediately. Otherwise, look through
441 * the input_Q, using the first command we find that's intended
442 * for a currently non-busy target/lun.
443 * Note that this function is always called with interrupts already
444 * disabled (either from in2000_queuecommand() or in2000_intr()).
446 static void in2000_execute(struct Scsi_Host *instance)
448 struct IN2000_hostdata *hostdata;
449 Scsi_Cmnd *cmd, *prev;
453 unsigned short flushbuf[16];
456 hostdata = (struct IN2000_hostdata *) instance->hostdata;
458 DB(DB_EXECUTE, printk("EX("))
460 if (hostdata->selecting || hostdata->connected) {
462 DB(DB_EXECUTE, printk(")EX-0 "))
468 * Search through the input_Q for a command destined
469 * for an idle target/lun.
472 cmd = (Scsi_Cmnd *) hostdata->input_Q;
475 if (!(hostdata->busy[cmd->device->id] & (1 << cmd->device->lun)))
478 cmd = (Scsi_Cmnd *) cmd->host_scribble;
481 /* quit if queue empty or all possible targets are busy */
485 DB(DB_EXECUTE, printk(")EX-1 "))
490 /* remove command from queue */
493 prev->host_scribble = cmd->host_scribble;
495 hostdata->input_Q = (Scsi_Cmnd *) cmd->host_scribble;
497 #ifdef PROC_STATISTICS
498 hostdata->cmd_cnt[cmd->device->id]++;
502 * Start the selection process
506 write_3393(hostdata, WD_DESTINATION_ID, cmd->device->id);
508 write_3393(hostdata, WD_DESTINATION_ID, cmd->device->id | DSTID_DPD);
510 /* Now we need to figure out whether or not this command is a good
511 * candidate for disconnect/reselect. We guess to the best of our
512 * ability, based on a set of hierarchical rules. When several
513 * devices are operating simultaneously, disconnects are usually
514 * an advantage. In a single device system, or if only 1 device
515 * is being accessed, transfers usually go faster if disconnects
518 * + Commands should NEVER disconnect if hostdata->disconnect =
519 * DIS_NEVER (this holds for tape drives also), and ALWAYS
520 * disconnect if hostdata->disconnect = DIS_ALWAYS.
521 * + Tape drive commands should always be allowed to disconnect.
522 * + Disconnect should be allowed if disconnected_Q isn't empty.
523 * + Commands should NOT disconnect if input_Q is empty.
524 * + Disconnect should be allowed if there are commands in input_Q
525 * for a different target/lun. In this case, the other commands
526 * should be made disconnect-able, if not already.
528 * I know, I know - this code would flunk me out of any
529 * "C Programming 101" class ever offered. But it's easy
530 * to change around and experiment with for now.
533 cmd->SCp.phase = 0; /* assume no disconnect */
534 if (hostdata->disconnect == DIS_NEVER)
536 if (hostdata->disconnect == DIS_ALWAYS)
538 if (cmd->device->type == 1) /* tape drive? */
540 if (hostdata->disconnected_Q) /* other commands disconnected? */
542 if (!(hostdata->input_Q)) /* input_Q empty? */
544 for (prev = (Scsi_Cmnd *) hostdata->input_Q; prev; prev = (Scsi_Cmnd *) prev->host_scribble) {
545 if ((prev->device->id != cmd->device->id) || (prev->device->lun != cmd->device->lun)) {
546 for (prev = (Scsi_Cmnd *) hostdata->input_Q; prev; prev = (Scsi_Cmnd *) prev->host_scribble)
556 #ifdef PROC_STATISTICS
557 hostdata->disc_allowed_cnt[cmd->device->id]++;
561 write_3393(hostdata, WD_SOURCE_ID, ((cmd->SCp.phase) ? SRCID_ER : 0));
563 write_3393(hostdata, WD_TARGET_LUN, cmd->device->lun);
564 write_3393(hostdata, WD_SYNCHRONOUS_TRANSFER, hostdata->sync_xfer[cmd->device->id]);
565 hostdata->busy[cmd->device->id] |= (1 << cmd->device->lun);
567 if ((hostdata->level2 <= L2_NONE) || (hostdata->sync_stat[cmd->device->id] == SS_UNSET)) {
570 * Do a 'Select-With-ATN' command. This will end with
571 * one of the following interrupts:
572 * CSR_RESEL_AM: failure - can try again later.
573 * CSR_TIMEOUT: failure - give up.
574 * CSR_SELECT: success - proceed.
577 hostdata->selecting = cmd;
579 /* Every target has its own synchronous transfer setting, kept in
580 * the sync_xfer array, and a corresponding status byte in sync_stat[].
581 * Each target's sync_stat[] entry is initialized to SS_UNSET, and its
582 * sync_xfer[] entry is initialized to the default/safe value. SS_UNSET
583 * means that the parameters are undetermined as yet, and that we
584 * need to send an SDTR message to this device after selection is
585 * complete. We set SS_FIRST to tell the interrupt routine to do so,
586 * unless we don't want to even _try_ synchronous transfers: In this
587 * case we set SS_SET to make the defaults final.
589 if (hostdata->sync_stat[cmd->device->id] == SS_UNSET) {
590 if (hostdata->sync_off & (1 << cmd->device->id))
591 hostdata->sync_stat[cmd->device->id] = SS_SET;
593 hostdata->sync_stat[cmd->device->id] = SS_FIRST;
595 hostdata->state = S_SELECTING;
596 write_3393_count(hostdata, 0); /* this guarantees a DATA_PHASE interrupt */
597 write_3393_cmd(hostdata, WD_CMD_SEL_ATN);
603 * Do a 'Select-With-ATN-Xfer' command. This will end with
604 * one of the following interrupts:
605 * CSR_RESEL_AM: failure - can try again later.
606 * CSR_TIMEOUT: failure - give up.
607 * anything else: success - proceed.
610 hostdata->connected = cmd;
611 write_3393(hostdata, WD_COMMAND_PHASE, 0);
613 /* copy command_descriptor_block into WD chip
614 * (take advantage of auto-incrementing)
617 write1_io(WD_CDB_1, IO_WD_ADDR);
618 for (i = 0; i < cmd->cmd_len; i++)
619 write1_io(cmd->cmnd[i], IO_WD_DATA);
621 /* The wd33c93 only knows about Group 0, 1, and 5 commands when
622 * it's doing a 'select-and-transfer'. To be safe, we write the
623 * size of the CDB into the OWN_ID register for every case. This
624 * way there won't be problems with vendor-unique, audio, etc.
627 write_3393(hostdata, WD_OWN_ID, cmd->cmd_len);
629 /* When doing a non-disconnect command, we can save ourselves a DATA
630 * phase interrupt later by setting everything up now. With writes we
631 * need to pre-fill the fifo; if there's room for the 32 flush bytes,
632 * put them in there too - that'll avoid a fifo interrupt. Reads are
634 * KLUDGE NOTE: It seems that you can't completely fill the fifo here:
635 * This results in the IO_FIFO_COUNT register rolling over to zero,
636 * and apparently the gate array logic sees this as empty, not full,
637 * so the 3393 chip is never signalled to start reading from the
638 * fifo. Or maybe it's seen as a permanent fifo interrupt condition.
639 * Regardless, we fix this by temporarily pretending that the fifo
640 * is 16 bytes smaller. (I see now that the old driver has a comment
641 * about "don't fill completely" in an analogous place - must be the
642 * same deal.) This results in CDROM, swap partitions, and tape drives
643 * needing an extra interrupt per write command - I think we can live
647 if (!(cmd->SCp.phase)) {
648 write_3393_count(hostdata, cmd->SCp.this_residual);
649 write_3393(hostdata, WD_CONTROL, CTRL_IDI | CTRL_EDI | CTRL_BUS);
650 write1_io(0, IO_FIFO_WRITE); /* clear fifo counter, write mode */
652 if (is_dir_out(cmd)) {
653 hostdata->fifo = FI_FIFO_WRITING;
654 if ((i = cmd->SCp.this_residual) > (IN2000_FIFO_SIZE - 16))
655 i = IN2000_FIFO_SIZE - 16;
656 cmd->SCp.have_data_in = i; /* this much data in fifo */
657 i >>= 1; /* Gulp. Assuming modulo 2. */
658 sp = (unsigned short *) cmd->SCp.ptr;
659 f = hostdata->io_base + IO_FIFO;
666 write2_io(*sp++, IO_FIFO);
670 /* Is there room for the flush bytes? */
672 if (cmd->SCp.have_data_in <= ((IN2000_FIFO_SIZE - 16) - 32)) {
681 write2_io(0, IO_FIFO);
689 write1_io(0, IO_FIFO_READ); /* put fifo in read mode */
690 hostdata->fifo = FI_FIFO_READING;
691 cmd->SCp.have_data_in = 0; /* nothing transferred yet */
695 write_3393_count(hostdata, 0); /* this guarantees a DATA_PHASE interrupt */
697 hostdata->state = S_RUNNING_LEVEL2;
698 write_3393_cmd(hostdata, WD_CMD_SEL_ATN_XFER);
702 * Since the SCSI bus can handle only 1 connection at a time,
703 * we get out of here now. If the selection fails, or when
704 * the command disconnects, we'll come back to this routine
705 * to search the input_Q again...
708 DB(DB_EXECUTE, printk("%s%ld)EX-2 ", (cmd->SCp.phase) ? "d:" : "", cmd->pid))
714 static void transfer_pio(uchar * buf, int cnt, int data_in_dir, struct IN2000_hostdata *hostdata)
718 DB(DB_TRANSFER, printk("(%p,%d,%s)", buf, cnt, data_in_dir ? "in" : "out"))
720 write_3393(hostdata, WD_CONTROL, CTRL_IDI | CTRL_EDI | CTRL_POLLED);
721 write_3393_count(hostdata, cnt);
722 write_3393_cmd(hostdata, WD_CMD_TRANS_INFO);
725 asr = READ_AUX_STAT();
727 *buf++ = read_3393(hostdata, WD_DATA);
728 } while (!(asr & ASR_INT));
731 asr = READ_AUX_STAT();
733 write_3393(hostdata, WD_DATA, *buf++);
734 } while (!(asr & ASR_INT));
737 /* Note: we are returning with the interrupt UN-cleared.
738 * Since (presumably) an entire I/O operation has
739 * completed, the bus phase is probably different, and
740 * the interrupt routine will discover this when it
741 * responds to the uncleared int.
748 static void transfer_bytes(Scsi_Cmnd * cmd, int data_in_dir)
750 struct IN2000_hostdata *hostdata;
755 hostdata = (struct IN2000_hostdata *) cmd->device->host->hostdata;
757 /* Normally, you'd expect 'this_residual' to be non-zero here.
758 * In a series of scatter-gather transfers, however, this
759 * routine will usually be called with 'this_residual' equal
760 * to 0 and 'buffers_residual' non-zero. This means that a
761 * previous transfer completed, clearing 'this_residual', and
762 * now we need to setup the next scatter-gather buffer as the
763 * source or destination for THIS transfer.
765 if (!cmd->SCp.this_residual && cmd->SCp.buffers_residual) {
767 --cmd->SCp.buffers_residual;
768 cmd->SCp.this_residual = cmd->SCp.buffer->length;
769 cmd->SCp.ptr = page_address(cmd->SCp.buffer->page) + cmd->SCp.buffer->offset;
772 /* Set up hardware registers */
774 write_3393(hostdata, WD_SYNCHRONOUS_TRANSFER, hostdata->sync_xfer[cmd->device->id]);
775 write_3393_count(hostdata, cmd->SCp.this_residual);
776 write_3393(hostdata, WD_CONTROL, CTRL_IDI | CTRL_EDI | CTRL_BUS);
777 write1_io(0, IO_FIFO_WRITE); /* zero counter, assume write */
779 /* Reading is easy. Just issue the command and return - we'll
780 * get an interrupt later when we have actual data to worry about.
784 write1_io(0, IO_FIFO_READ);
785 if ((hostdata->level2 >= L2_DATA) || (hostdata->level2 == L2_BASIC && cmd->SCp.phase == 0)) {
786 write_3393(hostdata, WD_COMMAND_PHASE, 0x45);
787 write_3393_cmd(hostdata, WD_CMD_SEL_ATN_XFER);
788 hostdata->state = S_RUNNING_LEVEL2;
790 write_3393_cmd(hostdata, WD_CMD_TRANS_INFO);
791 hostdata->fifo = FI_FIFO_READING;
792 cmd->SCp.have_data_in = 0;
796 /* Writing is more involved - we'll start the WD chip and write as
797 * much data to the fifo as we can right now. Later interrupts will
798 * write any bytes that don't make it at this stage.
801 if ((hostdata->level2 >= L2_DATA) || (hostdata->level2 == L2_BASIC && cmd->SCp.phase == 0)) {
802 write_3393(hostdata, WD_COMMAND_PHASE, 0x45);
803 write_3393_cmd(hostdata, WD_CMD_SEL_ATN_XFER);
804 hostdata->state = S_RUNNING_LEVEL2;
806 write_3393_cmd(hostdata, WD_CMD_TRANS_INFO);
807 hostdata->fifo = FI_FIFO_WRITING;
808 sp = (unsigned short *) cmd->SCp.ptr;
810 if ((i = cmd->SCp.this_residual) > IN2000_FIFO_SIZE)
811 i = IN2000_FIFO_SIZE;
812 cmd->SCp.have_data_in = i;
813 i >>= 1; /* Gulp. We assume this_residual is modulo 2 */
814 f = hostdata->io_base + IO_FIFO;
821 write2_io(*sp++, IO_FIFO);
828 /* We need to use spin_lock_irqsave() & spin_unlock_irqrestore() in this
829 * function in order to work in an SMP environment. (I'd be surprised
830 * if the driver is ever used by anyone on a real multi-CPU motherboard,
831 * but it _does_ need to be able to compile and run in an SMP kernel.)
834 static irqreturn_t in2000_intr(int irqnum, void *dev_id, struct pt_regs *ptregs)
836 struct Scsi_Host *instance = dev_id;
837 struct IN2000_hostdata *hostdata;
838 Scsi_Cmnd *patch, *cmd;
839 uchar asr, sr, phs, id, lun, *ucp, msg;
841 unsigned long length;
846 hostdata = (struct IN2000_hostdata *) instance->hostdata;
848 /* Get the spin_lock and disable further ints, for SMP */
850 spin_lock_irqsave(instance->host_lock, flags);
852 #ifdef PROC_STATISTICS
856 /* The IN2000 card has 2 interrupt sources OR'ed onto its IRQ line - the
857 * WD3393 chip and the 2k fifo (which is actually a dual-port RAM combined
858 * with a big logic array, so it's a little different than what you might
859 * expect). As far as I know, there's no reason that BOTH can't be active
860 * at the same time, but there's a problem: while we can read the 3393
861 * to tell if _it_ wants an interrupt, I don't know of a way to ask the
862 * fifo the same question. The best we can do is check the 3393 and if
863 * it _isn't_ the source of the interrupt, then we can be pretty sure
864 * that the fifo is the culprit.
865 * UPDATE: I have it on good authority (Bill Earnest) that bit 0 of the
866 * IO_FIFO_COUNT register mirrors the fifo interrupt state. I
867 * assume that bit clear means interrupt active. As it turns
868 * out, the driver really doesn't need to check for this after
869 * all, so my remarks above about a 'problem' can safely be
870 * ignored. The way the logic is set up, there's no advantage
871 * (that I can see) to worrying about it.
873 * It seems that the fifo interrupt signal is negated when we extract
874 * bytes during read or write bytes during write.
875 * - fifo will interrupt when data is moving from it to the 3393, and
876 * there are 31 (or less?) bytes left to go. This is sort of short-
877 * sighted: what if you don't WANT to do more? In any case, our
878 * response is to push more into the fifo - either actual data or
879 * dummy bytes if need be. Note that we apparently have to write at
880 * least 32 additional bytes to the fifo after an interrupt in order
881 * to get it to release the ones it was holding on to - writing fewer
882 * than 32 will result in another fifo int.
883 * UPDATE: Again, info from Bill Earnest makes this more understandable:
884 * 32 bytes = two counts of the fifo counter register. He tells
885 * me that the fifo interrupt is a non-latching signal derived
886 * from a straightforward boolean interpretation of the 7
887 * highest bits of the fifo counter and the fifo-read/fifo-write
888 * state. Who'd a thought?
891 write1_io(0, IO_LED_ON);
892 asr = READ_AUX_STAT();
893 if (!(asr & ASR_INT)) { /* no WD33c93 interrupt? */
895 /* Ok. This is definitely a FIFO-only interrupt.
897 * If FI_FIFO_READING is set, there are up to 2048 bytes waiting to be read,
898 * maybe more to come from the SCSI bus. Read as many as we can out of the
899 * fifo and into memory at the location of SCp.ptr[SCp.have_data_in], and
900 * update have_data_in afterwards.
902 * If we have FI_FIFO_WRITING, the FIFO has almost run out of bytes to move
903 * into the WD3393 chip (I think the interrupt happens when there are 31
904 * bytes left, but it may be fewer...). The 3393 is still waiting, so we
905 * shove some more into the fifo, which gets things moving again. If the
906 * original SCSI command specified more than 2048 bytes, there may still
907 * be some of that data left: fine - use it (from SCp.ptr[SCp.have_data_in]).
908 * Don't forget to update have_data_in. If we've already written out the
909 * entire buffer, feed 32 dummy bytes to the fifo - they're needed to
910 * push out the remaining real data.
911 * (Big thanks to Bill Earnest for getting me out of the mud in here.)
914 cmd = (Scsi_Cmnd *) hostdata->connected; /* assume we're connected */
915 CHECK_NULL(cmd, "fifo_int")
917 if (hostdata->fifo == FI_FIFO_READING) {
919 DB(DB_FIFO, printk("{R:%02x} ", read1_io(IO_FIFO_COUNT)))
921 sp = (unsigned short *) (cmd->SCp.ptr + cmd->SCp.have_data_in);
922 i = read1_io(IO_FIFO_COUNT) & 0xfe;
923 i <<= 2; /* # of words waiting in the fifo */
924 f = hostdata->io_base + IO_FIFO;
931 *sp++ = read2_io(IO_FIFO);
935 i = sp - (unsigned short *) (cmd->SCp.ptr + cmd->SCp.have_data_in);
937 cmd->SCp.have_data_in += i;
940 else if (hostdata->fifo == FI_FIFO_WRITING) {
942 DB(DB_FIFO, printk("{W:%02x} ", read1_io(IO_FIFO_COUNT)))
944 /* If all bytes have been written to the fifo, flush out the stragglers.
945 * Note that while writing 16 dummy words seems arbitrary, we don't
946 * have another choice that I can see. What we really want is to read
947 * the 3393 transfer count register (that would tell us how many bytes
948 * needed flushing), but the TRANSFER_INFO command hasn't completed
949 * yet (not enough bytes!) and that register won't be accessible. So,
950 * we use 16 words - a number obtained through trial and error.
951 * UPDATE: Bill says this is exactly what Always does, so there.
952 * More thanks due him for help in this section.
954 if (cmd->SCp.this_residual == cmd->SCp.have_data_in) {
956 while (i--) /* write 32 dummy bytes */
957 write2_io(0, IO_FIFO);
960 /* If there are still bytes left in the SCSI buffer, write as many as we
961 * can out to the fifo.
965 sp = (unsigned short *) (cmd->SCp.ptr + cmd->SCp.have_data_in);
966 i = cmd->SCp.this_residual - cmd->SCp.have_data_in; /* bytes yet to go */
967 j = read1_io(IO_FIFO_COUNT) & 0xfe;
968 j <<= 2; /* how many words the fifo has room for */
972 write2_io(*sp++, IO_FIFO);
974 i = sp - (unsigned short *) (cmd->SCp.ptr + cmd->SCp.have_data_in);
976 cmd->SCp.have_data_in += i;
981 printk("*** Spurious FIFO interrupt ***");
984 write1_io(0, IO_LED_OFF);
986 /* release the SMP spin_lock and restore irq state */
987 spin_unlock_irqrestore(instance->host_lock, flags);
991 /* This interrupt was triggered by the WD33c93 chip. The fifo interrupt
992 * may also be asserted, but we don't bother to check it: we get more
993 * detailed info from FIFO_READING and FIFO_WRITING (see below).
996 cmd = (Scsi_Cmnd *) hostdata->connected; /* assume we're connected */
997 sr = read_3393(hostdata, WD_SCSI_STATUS); /* clear the interrupt */
998 phs = read_3393(hostdata, WD_COMMAND_PHASE);
1000 if (!cmd && (sr != CSR_RESEL_AM && sr != CSR_TIMEOUT && sr != CSR_SELECT)) {
1001 printk("\nNR:wd-intr-1\n");
1002 write1_io(0, IO_LED_OFF);
1004 /* release the SMP spin_lock and restore irq state */
1005 spin_unlock_irqrestore(instance->host_lock, flags);
1009 DB(DB_INTR, printk("{%02x:%02x-", asr, sr))
1011 /* After starting a FIFO-based transfer, the next _WD3393_ interrupt is
1012 * guaranteed to be in response to the completion of the transfer.
1013 * If we were reading, there's probably data in the fifo that needs
1014 * to be copied into RAM - do that here. Also, we have to update
1015 * 'this_residual' and 'ptr' based on the contents of the
1016 * TRANSFER_COUNT register, in case the device decided to do an
1017 * intermediate disconnect (a device may do this if it has to
1018 * do a seek, or just to be nice and let other devices have
1019 * some bus time during long transfers).
1020 * After doing whatever is necessary with the fifo, we go on and
1021 * service the WD3393 interrupt normally.
1023 if (hostdata->fifo == FI_FIFO_READING) {
1025 /* buffer index = start-of-buffer + #-of-bytes-already-read */
1027 sp = (unsigned short *) (cmd->SCp.ptr + cmd->SCp.have_data_in);
1029 /* bytes remaining in fifo = (total-wanted - #-not-got) - #-already-read */
1031 i = (cmd->SCp.this_residual - read_3393_count(hostdata)) - cmd->SCp.have_data_in;
1032 i >>= 1; /* Gulp. We assume this will always be modulo 2 */
1033 f = hostdata->io_base + IO_FIFO;
1040 *sp++ = read2_io(IO_FIFO);
1044 hostdata->fifo = FI_FIFO_UNUSED;
1045 length = cmd->SCp.this_residual;
1046 cmd->SCp.this_residual = read_3393_count(hostdata);
1047 cmd->SCp.ptr += (length - cmd->SCp.this_residual);
1049 DB(DB_TRANSFER, printk("(%p,%d)", cmd->SCp.ptr, cmd->SCp.this_residual))
1053 else if (hostdata->fifo == FI_FIFO_WRITING) {
1054 hostdata->fifo = FI_FIFO_UNUSED;
1055 length = cmd->SCp.this_residual;
1056 cmd->SCp.this_residual = read_3393_count(hostdata);
1057 cmd->SCp.ptr += (length - cmd->SCp.this_residual);
1059 DB(DB_TRANSFER, printk("(%p,%d)", cmd->SCp.ptr, cmd->SCp.this_residual))
1063 /* Respond to the specific WD3393 interrupt - there are quite a few! */
1068 DB(DB_INTR, printk("TIMEOUT"))
1070 if (hostdata->state == S_RUNNING_LEVEL2)
1071 hostdata->connected = NULL;
1073 cmd = (Scsi_Cmnd *) hostdata->selecting; /* get a valid cmd */
1074 CHECK_NULL(cmd, "csr_timeout")
1075 hostdata->selecting = NULL;
1078 cmd->result = DID_NO_CONNECT << 16;
1079 hostdata->busy[cmd->device->id] &= ~(1 << cmd->device->lun);
1080 hostdata->state = S_UNCONNECTED;
1081 cmd->scsi_done(cmd);
1083 /* We are not connected to a target - check to see if there
1084 * are commands waiting to be executed.
1087 in2000_execute(instance);
1091 /* Note: this interrupt should not occur in a LEVEL2 command */
1094 DB(DB_INTR, printk("SELECT"))
1095 hostdata->connected = cmd = (Scsi_Cmnd *) hostdata->selecting;
1096 CHECK_NULL(cmd, "csr_select")
1097 hostdata->selecting = NULL;
1099 /* construct an IDENTIFY message with correct disconnect bit */
1101 hostdata->outgoing_msg[0] = (0x80 | 0x00 | cmd->device->lun);
1103 hostdata->outgoing_msg[0] |= 0x40;
1105 if (hostdata->sync_stat[cmd->device->id] == SS_FIRST) {
1107 printk(" sending SDTR ");
1110 hostdata->sync_stat[cmd->device->id] = SS_WAITING;
1112 /* tack on a 2nd message to ask about synchronous transfers */
1114 hostdata->outgoing_msg[1] = EXTENDED_MESSAGE;
1115 hostdata->outgoing_msg[2] = 3;
1116 hostdata->outgoing_msg[3] = EXTENDED_SDTR;
1117 hostdata->outgoing_msg[4] = OPTIMUM_SX_PER / 4;
1118 hostdata->outgoing_msg[5] = OPTIMUM_SX_OFF;
1119 hostdata->outgoing_len = 6;
1121 hostdata->outgoing_len = 1;
1123 hostdata->state = S_CONNECTED;
1127 case CSR_XFER_DONE | PHS_DATA_IN:
1128 case CSR_UNEXP | PHS_DATA_IN:
1129 case CSR_SRV_REQ | PHS_DATA_IN:
1130 DB(DB_INTR, printk("IN-%d.%d", cmd->SCp.this_residual, cmd->SCp.buffers_residual))
1131 transfer_bytes(cmd, DATA_IN_DIR);
1132 if (hostdata->state != S_RUNNING_LEVEL2)
1133 hostdata->state = S_CONNECTED;
1137 case CSR_XFER_DONE | PHS_DATA_OUT:
1138 case CSR_UNEXP | PHS_DATA_OUT:
1139 case CSR_SRV_REQ | PHS_DATA_OUT:
1140 DB(DB_INTR, printk("OUT-%d.%d", cmd->SCp.this_residual, cmd->SCp.buffers_residual))
1141 transfer_bytes(cmd, DATA_OUT_DIR);
1142 if (hostdata->state != S_RUNNING_LEVEL2)
1143 hostdata->state = S_CONNECTED;
1147 /* Note: this interrupt should not occur in a LEVEL2 command */
1149 case CSR_XFER_DONE | PHS_COMMAND:
1150 case CSR_UNEXP | PHS_COMMAND:
1151 case CSR_SRV_REQ | PHS_COMMAND:
1152 DB(DB_INTR, printk("CMND-%02x,%ld", cmd->cmnd[0], cmd->pid))
1153 transfer_pio(cmd->cmnd, cmd->cmd_len, DATA_OUT_DIR, hostdata);
1154 hostdata->state = S_CONNECTED;
1158 case CSR_XFER_DONE | PHS_STATUS:
1159 case CSR_UNEXP | PHS_STATUS:
1160 case CSR_SRV_REQ | PHS_STATUS:
1161 DB(DB_INTR, printk("STATUS="))
1163 cmd->SCp.Status = read_1_byte(hostdata);
1164 DB(DB_INTR, printk("%02x", cmd->SCp.Status))
1165 if (hostdata->level2 >= L2_BASIC) {
1166 sr = read_3393(hostdata, WD_SCSI_STATUS); /* clear interrupt */
1167 hostdata->state = S_RUNNING_LEVEL2;
1168 write_3393(hostdata, WD_COMMAND_PHASE, 0x50);
1169 write_3393_cmd(hostdata, WD_CMD_SEL_ATN_XFER);
1171 hostdata->state = S_CONNECTED;
1176 case CSR_XFER_DONE | PHS_MESS_IN:
1177 case CSR_UNEXP | PHS_MESS_IN:
1178 case CSR_SRV_REQ | PHS_MESS_IN:
1179 DB(DB_INTR, printk("MSG_IN="))
1181 msg = read_1_byte(hostdata);
1182 sr = read_3393(hostdata, WD_SCSI_STATUS); /* clear interrupt */
1184 hostdata->incoming_msg[hostdata->incoming_ptr] = msg;
1185 if (hostdata->incoming_msg[0] == EXTENDED_MESSAGE)
1186 msg = EXTENDED_MESSAGE;
1188 hostdata->incoming_ptr = 0;
1190 cmd->SCp.Message = msg;
1193 case COMMAND_COMPLETE:
1194 DB(DB_INTR, printk("CCMP-%ld", cmd->pid))
1195 write_3393_cmd(hostdata, WD_CMD_NEGATE_ACK);
1196 hostdata->state = S_PRE_CMP_DISC;
1200 DB(DB_INTR, printk("SDP"))
1201 write_3393_cmd(hostdata, WD_CMD_NEGATE_ACK);
1202 hostdata->state = S_CONNECTED;
1205 case RESTORE_POINTERS:
1206 DB(DB_INTR, printk("RDP"))
1207 if (hostdata->level2 >= L2_BASIC) {
1208 write_3393(hostdata, WD_COMMAND_PHASE, 0x45);
1209 write_3393_cmd(hostdata, WD_CMD_SEL_ATN_XFER);
1210 hostdata->state = S_RUNNING_LEVEL2;
1212 write_3393_cmd(hostdata, WD_CMD_NEGATE_ACK);
1213 hostdata->state = S_CONNECTED;
1218 DB(DB_INTR, printk("DIS"))
1219 cmd->device->disconnect = 1;
1220 write_3393_cmd(hostdata, WD_CMD_NEGATE_ACK);
1221 hostdata->state = S_PRE_TMP_DISC;
1224 case MESSAGE_REJECT:
1225 DB(DB_INTR, printk("REJ"))
1229 if (hostdata->sync_stat[cmd->device->id] == SS_WAITING)
1230 hostdata->sync_stat[cmd->device->id] = SS_SET;
1231 write_3393_cmd(hostdata, WD_CMD_NEGATE_ACK);
1232 hostdata->state = S_CONNECTED;
1235 case EXTENDED_MESSAGE:
1236 DB(DB_INTR, printk("EXT"))
1238 ucp = hostdata->incoming_msg;
1241 printk("%02x", ucp[hostdata->incoming_ptr]);
1243 /* Is this the last byte of the extended message? */
1245 if ((hostdata->incoming_ptr >= 2) && (hostdata->incoming_ptr == (ucp[1] + 1))) {
1247 switch (ucp[2]) { /* what's the EXTENDED code? */
1249 id = calc_sync_xfer(ucp[3], ucp[4]);
1250 if (hostdata->sync_stat[cmd->device->id] != SS_WAITING) {
1252 /* A device has sent an unsolicited SDTR message; rather than go
1253 * through the effort of decoding it and then figuring out what
1254 * our reply should be, we're just gonna say that we have a
1255 * synchronous fifo depth of 0. This will result in asynchronous
1256 * transfers - not ideal but so much easier.
1257 * Actually, this is OK because it assures us that if we don't
1258 * specifically ask for sync transfers, we won't do any.
1261 write_3393_cmd(hostdata, WD_CMD_ASSERT_ATN); /* want MESS_OUT */
1262 hostdata->outgoing_msg[0] = EXTENDED_MESSAGE;
1263 hostdata->outgoing_msg[1] = 3;
1264 hostdata->outgoing_msg[2] = EXTENDED_SDTR;
1265 hostdata->outgoing_msg[3] = hostdata->default_sx_per / 4;
1266 hostdata->outgoing_msg[4] = 0;
1267 hostdata->outgoing_len = 5;
1268 hostdata->sync_xfer[cmd->device->id] = calc_sync_xfer(hostdata->default_sx_per / 4, 0);
1270 hostdata->sync_xfer[cmd->device->id] = id;
1273 printk("sync_xfer=%02x", hostdata->sync_xfer[cmd->device->id]);
1275 hostdata->sync_stat[cmd->device->id] = SS_SET;
1276 write_3393_cmd(hostdata, WD_CMD_NEGATE_ACK);
1277 hostdata->state = S_CONNECTED;
1280 write_3393_cmd(hostdata, WD_CMD_ASSERT_ATN); /* want MESS_OUT */
1281 printk("sending WDTR ");
1282 hostdata->outgoing_msg[0] = EXTENDED_MESSAGE;
1283 hostdata->outgoing_msg[1] = 2;
1284 hostdata->outgoing_msg[2] = EXTENDED_WDTR;
1285 hostdata->outgoing_msg[3] = 0; /* 8 bit transfer width */
1286 hostdata->outgoing_len = 4;
1287 write_3393_cmd(hostdata, WD_CMD_NEGATE_ACK);
1288 hostdata->state = S_CONNECTED;
1291 write_3393_cmd(hostdata, WD_CMD_ASSERT_ATN); /* want MESS_OUT */
1292 printk("Rejecting Unknown Extended Message(%02x). ", ucp[2]);
1293 hostdata->outgoing_msg[0] = MESSAGE_REJECT;
1294 hostdata->outgoing_len = 1;
1295 write_3393_cmd(hostdata, WD_CMD_NEGATE_ACK);
1296 hostdata->state = S_CONNECTED;
1299 hostdata->incoming_ptr = 0;
1302 /* We need to read more MESS_IN bytes for the extended message */
1305 hostdata->incoming_ptr++;
1306 write_3393_cmd(hostdata, WD_CMD_NEGATE_ACK);
1307 hostdata->state = S_CONNECTED;
1312 printk("Rejecting Unknown Message(%02x) ", msg);
1313 write_3393_cmd(hostdata, WD_CMD_ASSERT_ATN); /* want MESS_OUT */
1314 hostdata->outgoing_msg[0] = MESSAGE_REJECT;
1315 hostdata->outgoing_len = 1;
1316 write_3393_cmd(hostdata, WD_CMD_NEGATE_ACK);
1317 hostdata->state = S_CONNECTED;
1322 /* Note: this interrupt will occur only after a LEVEL2 command */
1324 case CSR_SEL_XFER_DONE:
1326 /* Make sure that reselection is enabled at this point - it may
1327 * have been turned off for the command that just completed.
1330 write_3393(hostdata, WD_SOURCE_ID, SRCID_ER);
1332 DB(DB_INTR, printk("SX-DONE-%ld", cmd->pid))
1333 cmd->SCp.Message = COMMAND_COMPLETE;
1334 lun = read_3393(hostdata, WD_TARGET_LUN);
1335 DB(DB_INTR, printk(":%d.%d", cmd->SCp.Status, lun))
1336 hostdata->connected = NULL;
1337 hostdata->busy[cmd->device->id] &= ~(1 << cmd->device->lun);
1338 hostdata->state = S_UNCONNECTED;
1339 if (cmd->SCp.Status == ILLEGAL_STATUS_BYTE)
1340 cmd->SCp.Status = lun;
1341 if (cmd->cmnd[0] == REQUEST_SENSE && cmd->SCp.Status != GOOD)
1342 cmd->result = (cmd->result & 0x00ffff) | (DID_ERROR << 16);
1344 cmd->result = cmd->SCp.Status | (cmd->SCp.Message << 8);
1345 cmd->scsi_done(cmd);
1347 /* We are no longer connected to a target - check to see if
1348 * there are commands waiting to be executed.
1351 in2000_execute(instance);
1353 printk("%02x:%02x:%02x-%ld: Unknown SEL_XFER_DONE phase!!---", asr, sr, phs, cmd->pid);
1358 /* Note: this interrupt will occur only after a LEVEL2 command */
1361 DB(DB_INTR, printk("SDP"))
1362 hostdata->state = S_RUNNING_LEVEL2;
1363 write_3393(hostdata, WD_COMMAND_PHASE, 0x41);
1364 write_3393_cmd(hostdata, WD_CMD_SEL_ATN_XFER);
1368 case CSR_XFER_DONE | PHS_MESS_OUT:
1369 case CSR_UNEXP | PHS_MESS_OUT:
1370 case CSR_SRV_REQ | PHS_MESS_OUT:
1371 DB(DB_INTR, printk("MSG_OUT="))
1373 /* To get here, we've probably requested MESSAGE_OUT and have
1374 * already put the correct bytes in outgoing_msg[] and filled
1375 * in outgoing_len. We simply send them out to the SCSI bus.
1376 * Sometimes we get MESSAGE_OUT phase when we're not expecting
1377 * it - like when our SDTR message is rejected by a target. Some
1378 * targets send the REJECT before receiving all of the extended
1379 * message, and then seem to go back to MESSAGE_OUT for a byte
1380 * or two. Not sure why, or if I'm doing something wrong to
1381 * cause this to happen. Regardless, it seems that sending
1382 * NOP messages in these situations results in no harm and
1383 * makes everyone happy.
1385 if (hostdata->outgoing_len == 0) {
1386 hostdata->outgoing_len = 1;
1387 hostdata->outgoing_msg[0] = NOP;
1389 transfer_pio(hostdata->outgoing_msg, hostdata->outgoing_len, DATA_OUT_DIR, hostdata);
1390 DB(DB_INTR, printk("%02x", hostdata->outgoing_msg[0]))
1391 hostdata->outgoing_len = 0;
1392 hostdata->state = S_CONNECTED;
1396 case CSR_UNEXP_DISC:
1398 /* I think I've seen this after a request-sense that was in response
1399 * to an error condition, but not sure. We certainly need to do
1400 * something when we get this interrupt - the question is 'what?'.
1401 * Let's think positively, and assume some command has finished
1402 * in a legal manner (like a command that provokes a request-sense),
1403 * so we treat it as a normal command-complete-disconnect.
1407 /* Make sure that reselection is enabled at this point - it may
1408 * have been turned off for the command that just completed.
1411 write_3393(hostdata, WD_SOURCE_ID, SRCID_ER);
1413 printk(" - Already disconnected! ");
1414 hostdata->state = S_UNCONNECTED;
1416 /* release the SMP spin_lock and restore irq state */
1417 spin_unlock_irqrestore(instance->host_lock, flags);
1420 DB(DB_INTR, printk("UNEXP_DISC-%ld", cmd->pid))
1421 hostdata->connected = NULL;
1422 hostdata->busy[cmd->device->id] &= ~(1 << cmd->device->lun);
1423 hostdata->state = S_UNCONNECTED;
1424 if (cmd->cmnd[0] == REQUEST_SENSE && cmd->SCp.Status != GOOD)
1425 cmd->result = (cmd->result & 0x00ffff) | (DID_ERROR << 16);
1427 cmd->result = cmd->SCp.Status | (cmd->SCp.Message << 8);
1428 cmd->scsi_done(cmd);
1430 /* We are no longer connected to a target - check to see if
1431 * there are commands waiting to be executed.
1434 in2000_execute(instance);
1440 /* Make sure that reselection is enabled at this point - it may
1441 * have been turned off for the command that just completed.
1444 write_3393(hostdata, WD_SOURCE_ID, SRCID_ER);
1445 DB(DB_INTR, printk("DISC-%ld", cmd->pid))
1447 printk(" - Already disconnected! ");
1448 hostdata->state = S_UNCONNECTED;
1450 switch (hostdata->state) {
1451 case S_PRE_CMP_DISC:
1452 hostdata->connected = NULL;
1453 hostdata->busy[cmd->device->id] &= ~(1 << cmd->device->lun);
1454 hostdata->state = S_UNCONNECTED;
1455 DB(DB_INTR, printk(":%d", cmd->SCp.Status))
1456 if (cmd->cmnd[0] == REQUEST_SENSE && cmd->SCp.Status != GOOD)
1457 cmd->result = (cmd->result & 0x00ffff) | (DID_ERROR << 16);
1459 cmd->result = cmd->SCp.Status | (cmd->SCp.Message << 8);
1460 cmd->scsi_done(cmd);
1462 case S_PRE_TMP_DISC:
1463 case S_RUNNING_LEVEL2:
1464 cmd->host_scribble = (uchar *) hostdata->disconnected_Q;
1465 hostdata->disconnected_Q = cmd;
1466 hostdata->connected = NULL;
1467 hostdata->state = S_UNCONNECTED;
1469 #ifdef PROC_STATISTICS
1470 hostdata->disc_done_cnt[cmd->device->id]++;
1475 printk("*** Unexpected DISCONNECT interrupt! ***");
1476 hostdata->state = S_UNCONNECTED;
1479 /* We are no longer connected to a target - check to see if
1480 * there are commands waiting to be executed.
1483 in2000_execute(instance);
1488 DB(DB_INTR, printk("RESEL"))
1490 /* First we have to make sure this reselection didn't */
1491 /* happen during Arbitration/Selection of some other device. */
1492 /* If yes, put losing command back on top of input_Q. */
1493 if (hostdata->level2 <= L2_NONE) {
1495 if (hostdata->selecting) {
1496 cmd = (Scsi_Cmnd *) hostdata->selecting;
1497 hostdata->selecting = NULL;
1498 hostdata->busy[cmd->device->id] &= ~(1 << cmd->device->lun);
1499 cmd->host_scribble = (uchar *) hostdata->input_Q;
1500 hostdata->input_Q = cmd;
1508 hostdata->busy[cmd->device->id] &= ~(1 << cmd->device->lun);
1509 cmd->host_scribble = (uchar *) hostdata->input_Q;
1510 hostdata->input_Q = cmd;
1512 printk("---%02x:%02x:%02x-TROUBLE: Intrusive ReSelect!---", asr, sr, phs);
1520 /* OK - find out which device reselected us. */
1522 id = read_3393(hostdata, WD_SOURCE_ID);
1525 /* and extract the lun from the ID message. (Note that we don't
1526 * bother to check for a valid message here - I guess this is
1527 * not the right way to go, but....)
1530 lun = read_3393(hostdata, WD_DATA);
1531 if (hostdata->level2 < L2_RESELECT)
1532 write_3393_cmd(hostdata, WD_CMD_NEGATE_ACK);
1535 /* Now we look for the command that's reconnecting. */
1537 cmd = (Scsi_Cmnd *) hostdata->disconnected_Q;
1540 if (id == cmd->device->id && lun == cmd->device->lun)
1543 cmd = (Scsi_Cmnd *) cmd->host_scribble;
1546 /* Hmm. Couldn't find a valid command.... What to do? */
1549 printk("---TROUBLE: target %d.%d not in disconnect queue---", id, lun);
1553 /* Ok, found the command - now start it up again. */
1556 patch->host_scribble = cmd->host_scribble;
1558 hostdata->disconnected_Q = (Scsi_Cmnd *) cmd->host_scribble;
1559 hostdata->connected = cmd;
1561 /* We don't need to worry about 'initialize_SCp()' or 'hostdata->busy[]'
1562 * because these things are preserved over a disconnect.
1563 * But we DO need to fix the DPD bit so it's correct for this command.
1566 if (is_dir_out(cmd))
1567 write_3393(hostdata, WD_DESTINATION_ID, cmd->device->id);
1569 write_3393(hostdata, WD_DESTINATION_ID, cmd->device->id | DSTID_DPD);
1570 if (hostdata->level2 >= L2_RESELECT) {
1571 write_3393_count(hostdata, 0); /* we want a DATA_PHASE interrupt */
1572 write_3393(hostdata, WD_COMMAND_PHASE, 0x45);
1573 write_3393_cmd(hostdata, WD_CMD_SEL_ATN_XFER);
1574 hostdata->state = S_RUNNING_LEVEL2;
1576 hostdata->state = S_CONNECTED;
1578 DB(DB_INTR, printk("-%ld", cmd->pid))
1582 printk("--UNKNOWN INTERRUPT:%02x:%02x:%02x--", asr, sr, phs);
1585 write1_io(0, IO_LED_OFF);
1587 DB(DB_INTR, printk("} "))
1589 /* release the SMP spin_lock and restore irq state */
1590 spin_unlock_irqrestore(instance->host_lock, flags);
1596 #define RESET_CARD 0
1597 #define RESET_CARD_AND_BUS 1
1601 * Caller must hold instance lock!
1604 static int reset_hardware(struct Scsi_Host *instance, int type)
1606 struct IN2000_hostdata *hostdata;
1609 hostdata = (struct IN2000_hostdata *) instance->hostdata;
1611 write1_io(0, IO_LED_ON);
1612 if (type == RESET_CARD_AND_BUS) {
1613 write1_io(0, IO_CARD_RESET);
1614 x = read1_io(IO_HARDWARE);
1616 x = read_3393(hostdata, WD_SCSI_STATUS); /* clear any WD intrpt */
1617 write_3393(hostdata, WD_OWN_ID, instance->this_id | OWNID_EAF | OWNID_RAF | OWNID_FS_8);
1618 write_3393(hostdata, WD_CONTROL, CTRL_IDI | CTRL_EDI | CTRL_POLLED);
1619 write_3393(hostdata, WD_SYNCHRONOUS_TRANSFER, calc_sync_xfer(hostdata->default_sx_per / 4, DEFAULT_SX_OFF));
1621 write1_io(0, IO_FIFO_WRITE); /* clear fifo counter */
1622 write1_io(0, IO_FIFO_READ); /* start fifo out in read mode */
1623 write_3393(hostdata, WD_COMMAND, WD_CMD_RESET);
1624 /* FIXME: timeout ?? */
1625 while (!(READ_AUX_STAT() & ASR_INT))
1626 cpu_relax(); /* wait for RESET to complete */
1628 x = read_3393(hostdata, WD_SCSI_STATUS); /* clear interrupt */
1630 write_3393(hostdata, WD_QUEUE_TAG, 0xa5); /* any random number */
1631 qt = read_3393(hostdata, WD_QUEUE_TAG);
1634 write_3393(hostdata, WD_QUEUE_TAG, 0);
1636 write_3393(hostdata, WD_TIMEOUT_PERIOD, TIMEOUT_PERIOD_VALUE);
1637 write_3393(hostdata, WD_CONTROL, CTRL_IDI | CTRL_EDI | CTRL_POLLED);
1638 write1_io(0, IO_LED_OFF);
1644 static int in2000_bus_reset(Scsi_Cmnd * cmd)
1646 struct Scsi_Host *instance;
1647 struct IN2000_hostdata *hostdata;
1650 instance = cmd->device->host;
1651 hostdata = (struct IN2000_hostdata *) instance->hostdata;
1653 printk(KERN_WARNING "scsi%d: Reset. ", instance->host_no);
1655 /* do scsi-reset here */
1657 reset_hardware(instance, RESET_CARD_AND_BUS);
1658 for (x = 0; x < 8; x++) {
1659 hostdata->busy[x] = 0;
1660 hostdata->sync_xfer[x] = calc_sync_xfer(DEFAULT_SX_PER / 4, DEFAULT_SX_OFF);
1661 hostdata->sync_stat[x] = SS_UNSET; /* using default sync values */
1663 hostdata->input_Q = NULL;
1664 hostdata->selecting = NULL;
1665 hostdata->connected = NULL;
1666 hostdata->disconnected_Q = NULL;
1667 hostdata->state = S_UNCONNECTED;
1668 hostdata->fifo = FI_FIFO_UNUSED;
1669 hostdata->incoming_ptr = 0;
1670 hostdata->outgoing_len = 0;
1672 cmd->result = DID_RESET << 16;
1676 static int in2000_host_reset(Scsi_Cmnd * cmd)
1681 static int in2000_device_reset(Scsi_Cmnd * cmd)
1687 static int in2000_abort(Scsi_Cmnd * cmd)
1689 struct Scsi_Host *instance;
1690 struct IN2000_hostdata *hostdata;
1691 Scsi_Cmnd *tmp, *prev;
1693 unsigned long timeout;
1695 instance = cmd->device->host;
1696 hostdata = (struct IN2000_hostdata *) instance->hostdata;
1698 printk(KERN_DEBUG "scsi%d: Abort-", instance->host_no);
1699 printk("(asr=%02x,count=%ld,resid=%d,buf_resid=%d,have_data=%d,FC=%02x)- ", READ_AUX_STAT(), read_3393_count(hostdata), cmd->SCp.this_residual, cmd->SCp.buffers_residual, cmd->SCp.have_data_in, read1_io(IO_FIFO_COUNT));
1702 * Case 1 : If the command hasn't been issued yet, we simply remove it
1706 tmp = (Scsi_Cmnd *) hostdata->input_Q;
1711 prev->host_scribble = cmd->host_scribble;
1712 cmd->host_scribble = NULL;
1713 cmd->result = DID_ABORT << 16;
1714 printk(KERN_WARNING "scsi%d: Abort - removing command %ld from input_Q. ", instance->host_no, cmd->pid);
1715 cmd->scsi_done(cmd);
1719 tmp = (Scsi_Cmnd *) tmp->host_scribble;
1723 * Case 2 : If the command is connected, we're going to fail the abort
1724 * and let the high level SCSI driver retry at a later time or
1727 * Timeouts, and therefore aborted commands, will be highly unlikely
1728 * and handling them cleanly in this situation would make the common
1729 * case of noresets less efficient, and would pollute our code. So,
1733 if (hostdata->connected == cmd) {
1735 printk(KERN_WARNING "scsi%d: Aborting connected command %ld - ", instance->host_no, cmd->pid);
1737 printk("sending wd33c93 ABORT command - ");
1738 write_3393(hostdata, WD_CONTROL, CTRL_IDI | CTRL_EDI | CTRL_POLLED);
1739 write_3393_cmd(hostdata, WD_CMD_ABORT);
1741 /* Now we have to attempt to flush out the FIFO... */
1743 printk("flushing fifo - ");
1746 asr = READ_AUX_STAT();
1748 read_3393(hostdata, WD_DATA);
1749 } while (!(asr & ASR_INT) && timeout-- > 0);
1750 sr = read_3393(hostdata, WD_SCSI_STATUS);
1751 printk("asr=%02x, sr=%02x, %ld bytes un-transferred (timeout=%ld) - ", asr, sr, read_3393_count(hostdata), timeout);
1754 * Abort command processed.
1756 * We must disconnect.
1759 printk("sending wd33c93 DISCONNECT command - ");
1760 write_3393_cmd(hostdata, WD_CMD_DISCONNECT);
1763 asr = READ_AUX_STAT();
1764 while ((asr & ASR_CIP) && timeout-- > 0)
1765 asr = READ_AUX_STAT();
1766 sr = read_3393(hostdata, WD_SCSI_STATUS);
1767 printk("asr=%02x, sr=%02x.", asr, sr);
1769 hostdata->busy[cmd->device->id] &= ~(1 << cmd->device->lun);
1770 hostdata->connected = NULL;
1771 hostdata->state = S_UNCONNECTED;
1772 cmd->result = DID_ABORT << 16;
1773 cmd->scsi_done(cmd);
1775 in2000_execute(instance);
1781 * Case 3: If the command is currently disconnected from the bus,
1782 * we're not going to expend much effort here: Let's just return
1783 * an ABORT_SNOOZE and hope for the best...
1786 for (tmp = (Scsi_Cmnd *) hostdata->disconnected_Q; tmp; tmp = (Scsi_Cmnd *) tmp->host_scribble)
1788 printk(KERN_DEBUG "scsi%d: unable to abort disconnected command.\n", instance->host_no);
1793 * Case 4 : If we reached this point, the command was not found in any of
1796 * We probably reached this point because of an unlikely race condition
1797 * between the command completing successfully and the abortion code,
1798 * so we won't panic, but we will notify the user in case something really
1802 in2000_execute(instance);
1804 printk("scsi%d: warning : SCSI command probably completed successfully" " before abortion. ", instance->host_no);
1810 #define MAX_IN2000_HOSTS 3
1811 #define MAX_SETUP_ARGS (sizeof(setup_args) / sizeof(char *))
1812 #define SETUP_BUFFER_SIZE 200
1813 static char setup_buffer[SETUP_BUFFER_SIZE];
1814 static char setup_used[MAX_SETUP_ARGS];
1815 static int done_setup = 0;
1817 static void __init in2000_setup(char *str, int *ints)
1822 strlcpy(setup_buffer, str, SETUP_BUFFER_SIZE);
1825 while (*p1 && (i < MAX_SETUP_ARGS)) {
1826 p2 = strchr(p1, ',');
1838 for (i = 0; i < MAX_SETUP_ARGS; i++)
1844 /* check_setup_args() returns index if key found, 0 if not
1847 static int __init check_setup_args(char *key, int *val, char *buf)
1852 for (x = 0; x < MAX_SETUP_ARGS; x++) {
1855 if (!strncmp(setup_args[x], key, strlen(key)))
1858 if (x == MAX_SETUP_ARGS)
1861 cp = setup_args[x] + strlen(key);
1866 if ((*cp >= '0') && (*cp <= '9')) {
1867 *val = simple_strtoul(cp, NULL, 0);
1874 /* The "correct" (ie portable) way to access memory-mapped hardware
1875 * such as the IN2000 EPROM and dip switch is through the use of
1876 * special macros declared in 'asm/io.h'. We use readb() and readl()
1877 * when reading from the card's BIOS area in in2000_detect().
1879 static u32 bios_tab[] in2000__INITDATA = {
1886 static unsigned short base_tab[] in2000__INITDATA = {
1893 static int int_tab[] in2000__INITDATA = {
1901 static int __init in2000_detect(Scsi_Host_Template * tpnt)
1903 struct Scsi_Host *instance;
1904 struct IN2000_hostdata *hostdata;
1908 unsigned short base;
1911 unsigned long flags;
1915 /* Thanks to help from Bill Earnest, probing for IN2000 cards is a
1916 * pretty straightforward and fool-proof operation. There are 3
1917 * possible locations for the IN2000 EPROM in memory space - if we
1918 * find a BIOS signature, we can read the dip switch settings from
1919 * the byte at BIOS+32 (shadowed in by logic on the card). From 2
1920 * of the switch bits we get the card's address in IO space. There's
1921 * an image of the dip switch there, also, so we have a way to back-
1922 * check that this really is an IN2000 card. Very nifty. Use the
1923 * 'ioport:xx' command-line parameter if your BIOS EPROM is absent
1927 if (!done_setup && setup_strings)
1928 in2000_setup(setup_strings, 0);
1931 for (bios = 0; bios_tab[bios]; bios++) {
1932 if (check_setup_args("ioport", &val, buf)) {
1934 switches = ~inb(base + IO_SWITCHES) & 0xff;
1935 printk("Forcing IN2000 detection at IOport 0x%x ", base);
1939 * There have been a couple of BIOS versions with different layouts
1940 * for the obvious ID strings. We look for the 2 most common ones and
1941 * hope that they cover all the cases...
1943 else if (isa_readl(bios_tab[bios] + 0x10) == 0x41564f4e || isa_readl(bios_tab[bios] + 0x30) == 0x61776c41) {
1944 printk("Found IN2000 BIOS at 0x%x ", (unsigned int) bios_tab[bios]);
1946 /* Read the switch image that's mapped into EPROM space */
1948 switches = ~((isa_readb(bios_tab[bios] + 0x20) & 0xff));
1950 /* Find out where the IO space is */
1952 x = switches & (SW_ADDR0 | SW_ADDR1);
1955 /* Check for the IN2000 signature in IO space. */
1957 x = ~inb(base + IO_SWITCHES) & 0xff;
1958 if (x != switches) {
1959 printk("Bad IO signature: %02x vs %02x.\n", x, switches);
1965 /* OK. We have a base address for the IO ports - run a few safety checks */
1967 if (!(switches & SW_BIT7)) { /* I _think_ all cards do this */
1968 printk("There is no IN-2000 SCSI card at IOport 0x%03x!\n", base);
1972 /* Let's assume any hardware version will work, although the driver
1973 * has only been tested on 0x21, 0x22, 0x25, 0x26, and 0x27. We'll
1974 * print out the rev number for reference later, but accept them all.
1977 hrev = inb(base + IO_HARDWARE);
1979 /* Bit 2 tells us if interrupts are disabled */
1980 if (switches & SW_DISINT) {
1981 printk("The IN-2000 SCSI card at IOport 0x%03x ", base);
1982 printk("is not configured for interrupt operation!\n");
1983 printk("This driver requires an interrupt: cancelling detection.\n");
1987 /* Ok. We accept that there's an IN2000 at ioaddr 'base'. Now
1991 tpnt->proc_name = "in2000";
1992 instance = scsi_register(tpnt, sizeof(struct IN2000_hostdata));
1993 if (instance == NULL)
1996 hostdata = (struct IN2000_hostdata *) instance->hostdata;
1997 instance->io_port = hostdata->io_base = base;
1998 hostdata->dip_switch = switches;
1999 hostdata->hrev = hrev;
2001 write1_io(0, IO_FIFO_WRITE); /* clear fifo counter */
2002 write1_io(0, IO_FIFO_READ); /* start fifo out in read mode */
2003 write1_io(0, IO_INTR_MASK); /* allow all ints */
2004 x = int_tab[(switches & (SW_INT0 | SW_INT1)) >> SW_INT_SHIFT];
2005 if (request_irq(x, in2000_intr, SA_INTERRUPT, "in2000", instance)) {
2006 printk("in2000_detect: Unable to allocate IRQ.\n");
2011 instance->n_io_port = 13;
2012 request_region(base, 13, "in2000"); /* lock in this IO space for our use */
2014 for (x = 0; x < 8; x++) {
2015 hostdata->busy[x] = 0;
2016 hostdata->sync_xfer[x] = calc_sync_xfer(DEFAULT_SX_PER / 4, DEFAULT_SX_OFF);
2017 hostdata->sync_stat[x] = SS_UNSET; /* using default sync values */
2018 #ifdef PROC_STATISTICS
2019 hostdata->cmd_cnt[x] = 0;
2020 hostdata->disc_allowed_cnt[x] = 0;
2021 hostdata->disc_done_cnt[x] = 0;
2024 hostdata->input_Q = NULL;
2025 hostdata->selecting = NULL;
2026 hostdata->connected = NULL;
2027 hostdata->disconnected_Q = NULL;
2028 hostdata->state = S_UNCONNECTED;
2029 hostdata->fifo = FI_FIFO_UNUSED;
2030 hostdata->level2 = L2_BASIC;
2031 hostdata->disconnect = DIS_ADAPTIVE;
2032 hostdata->args = DEBUG_DEFAULTS;
2033 hostdata->incoming_ptr = 0;
2034 hostdata->outgoing_len = 0;
2035 hostdata->default_sx_per = DEFAULT_SX_PER;
2037 /* Older BIOS's had a 'sync on/off' switch - use its setting */
2039 if (isa_readl(bios_tab[bios] + 0x10) == 0x41564f4e && (switches & SW_SYNC_DOS5))
2040 hostdata->sync_off = 0x00; /* sync defaults to on */
2042 hostdata->sync_off = 0xff; /* sync defaults to off */
2044 #ifdef PROC_INTERFACE
2045 hostdata->proc = PR_VERSION | PR_INFO | PR_STATISTICS | PR_CONNECTED | PR_INPUTQ | PR_DISCQ | PR_STOP;
2046 #ifdef PROC_STATISTICS
2047 hostdata->int_cnt = 0;
2051 if (check_setup_args("nosync", &val, buf))
2052 hostdata->sync_off = val;
2054 if (check_setup_args("period", &val, buf))
2055 hostdata->default_sx_per = sx_table[round_period((unsigned int) val)].period_ns;
2057 if (check_setup_args("disconnect", &val, buf)) {
2058 if ((val >= DIS_NEVER) && (val <= DIS_ALWAYS))
2059 hostdata->disconnect = val;
2061 hostdata->disconnect = DIS_ADAPTIVE;
2064 if (check_setup_args("noreset", &val, buf))
2065 hostdata->args ^= A_NO_SCSI_RESET;
2067 if (check_setup_args("level2", &val, buf))
2068 hostdata->level2 = val;
2070 if (check_setup_args("debug", &val, buf))
2071 hostdata->args = (val & DB_MASK);
2073 #ifdef PROC_INTERFACE
2074 if (check_setup_args("proc", &val, buf))
2075 hostdata->proc = val;
2079 /* FIXME: not strictly needed I think but the called code expects
2081 spin_lock_irqsave(instance->host_lock, flags);
2082 x = reset_hardware(instance, (hostdata->args & A_NO_SCSI_RESET) ? RESET_CARD : RESET_CARD_AND_BUS);
2083 spin_unlock_irqrestore(instance->host_lock, flags);
2085 hostdata->microcode = read_3393(hostdata, WD_CDB_1);
2088 hostdata->chip = C_WD33C93B;
2090 hostdata->chip = C_WD33C93A;
2092 hostdata->chip = C_WD33C93;
2094 printk("dip_switch=%02x irq=%d ioport=%02x floppy=%s sync/DOS5=%s ", (switches & 0x7f), instance->irq, hostdata->io_base, (switches & SW_FLOPPY) ? "Yes" : "No", (switches & SW_SYNC_DOS5) ? "Yes" : "No");
2095 printk("hardware_ver=%02x chip=%s microcode=%02x\n", hrev, (hostdata->chip == C_WD33C93) ? "WD33c93" : (hostdata->chip == C_WD33C93A) ? "WD33c93A" : (hostdata->chip == C_WD33C93B) ? "WD33c93B" : "unknown", hostdata->microcode);
2097 printk("setup_args = ");
2098 for (x = 0; x < MAX_SETUP_ARGS; x++)
2099 printk("%s,", setup_args[x]);
2102 if (hostdata->sync_off == 0xff)
2103 printk("Sync-transfer DISABLED on all devices: ENABLE from command-line\n");
2104 printk("IN2000 driver version %s - %s\n", IN2000_VERSION, IN2000_DATE);
2107 return detect_count;
2110 static int in2000_release(struct Scsi_Host *shost)
2113 free_irq(shost->irq, shost);
2114 if (shost->io_port && shost->n_io_port)
2115 release_region(shost->io_port, shost->n_io_port);
2119 /* NOTE: I lifted this function straight out of the old driver,
2120 * and have not tested it. Presumably it does what it's
2124 static int in2000_biosparam(struct scsi_device *sdev, struct block_device *bdev, sector_t capacity, int *iinfo)
2131 iinfo[2] = size >> 11;
2133 /* This should approximate the large drive handling that the DOS ASPI manager
2134 uses. Drives very near the boundaries may not be handled correctly (i.e.
2135 near 2.0 Gb and 4.0 Gb) */
2137 if (iinfo[2] > 1024) {
2140 iinfo[2] = (unsigned long) capacity / (iinfo[0] * iinfo[1]);
2142 if (iinfo[2] > 1024) {
2145 iinfo[2] = (unsigned long) capacity / (iinfo[0] * iinfo[1]);
2147 if (iinfo[2] > 1024) {
2150 iinfo[2] = (unsigned long) capacity / (iinfo[0] * iinfo[1]);
2156 static int in2000_proc_info(struct Scsi_Host *instance, char *buf, char **start, off_t off, int len, int in)
2159 #ifdef PROC_INTERFACE
2163 unsigned long flags;
2164 struct IN2000_hostdata *hd;
2167 static int stop = 0;
2169 hd = (struct IN2000_hostdata *) instance->hostdata;
2171 /* If 'in' is TRUE we need to _read_ the proc file. We accept the following
2172 * keywords (same format as command-line, but only ONE per read):
2183 if (!strncmp(bp, "debug:", 6)) {
2185 hd->args = simple_strtoul(bp, NULL, 0) & DB_MASK;
2186 } else if (!strncmp(bp, "disconnect:", 11)) {
2188 x = simple_strtoul(bp, NULL, 0);
2189 if (x < DIS_NEVER || x > DIS_ALWAYS)
2192 } else if (!strncmp(bp, "period:", 7)) {
2194 x = simple_strtoul(bp, NULL, 0);
2195 hd->default_sx_per = sx_table[round_period((unsigned int) x)].period_ns;
2196 } else if (!strncmp(bp, "resync:", 7)) {
2198 x = simple_strtoul(bp, NULL, 0);
2199 for (i = 0; i < 7; i++)
2201 hd->sync_stat[i] = SS_UNSET;
2202 } else if (!strncmp(bp, "proc:", 5)) {
2204 hd->proc = simple_strtoul(bp, NULL, 0);
2205 } else if (!strncmp(bp, "level2:", 7)) {
2207 hd->level2 = simple_strtoul(bp, NULL, 0);
2212 spin_lock_irqsave(instance->host_lock, flags);
2215 if (hd->proc & PR_VERSION) {
2216 sprintf(tbuf, "\nVersion %s - %s. Compiled %s %s", IN2000_VERSION, IN2000_DATE, __DATE__, __TIME__);
2219 if (hd->proc & PR_INFO) {
2220 sprintf(tbuf, "\ndip_switch=%02x: irq=%d io=%02x floppy=%s sync/DOS5=%s", (hd->dip_switch & 0x7f), instance->irq, hd->io_base, (hd->dip_switch & 0x40) ? "Yes" : "No", (hd->dip_switch & 0x20) ? "Yes" : "No");
2222 strcat(bp, "\nsync_xfer[] = ");
2223 for (x = 0; x < 7; x++) {
2224 sprintf(tbuf, "\t%02x", hd->sync_xfer[x]);
2227 strcat(bp, "\nsync_stat[] = ");
2228 for (x = 0; x < 7; x++) {
2229 sprintf(tbuf, "\t%02x", hd->sync_stat[x]);
2233 #ifdef PROC_STATISTICS
2234 if (hd->proc & PR_STATISTICS) {
2235 strcat(bp, "\ncommands issued: ");
2236 for (x = 0; x < 7; x++) {
2237 sprintf(tbuf, "\t%ld", hd->cmd_cnt[x]);
2240 strcat(bp, "\ndisconnects allowed:");
2241 for (x = 0; x < 7; x++) {
2242 sprintf(tbuf, "\t%ld", hd->disc_allowed_cnt[x]);
2245 strcat(bp, "\ndisconnects done: ");
2246 for (x = 0; x < 7; x++) {
2247 sprintf(tbuf, "\t%ld", hd->disc_done_cnt[x]);
2250 sprintf(tbuf, "\ninterrupts: \t%ld", hd->int_cnt);
2254 if (hd->proc & PR_CONNECTED) {
2255 strcat(bp, "\nconnected: ");
2256 if (hd->connected) {
2257 cmd = (Scsi_Cmnd *) hd->connected;
2258 sprintf(tbuf, " %ld-%d:%d(%02x)", cmd->pid, cmd->device->id, cmd->device->lun, cmd->cmnd[0]);
2262 if (hd->proc & PR_INPUTQ) {
2263 strcat(bp, "\ninput_Q: ");
2264 cmd = (Scsi_Cmnd *) hd->input_Q;
2266 sprintf(tbuf, " %ld-%d:%d(%02x)", cmd->pid, cmd->device->id, cmd->device->lun, cmd->cmnd[0]);
2268 cmd = (Scsi_Cmnd *) cmd->host_scribble;
2271 if (hd->proc & PR_DISCQ) {
2272 strcat(bp, "\ndisconnected_Q:");
2273 cmd = (Scsi_Cmnd *) hd->disconnected_Q;
2275 sprintf(tbuf, " %ld-%d:%d(%02x)", cmd->pid, cmd->device->id, cmd->device->lun, cmd->cmnd[0]);
2277 cmd = (Scsi_Cmnd *) cmd->host_scribble;
2280 if (hd->proc & PR_TEST) {
2281 ; /* insert your own custom function here */
2284 spin_unlock_irqrestore(instance->host_lock, flags);
2288 return 0; /* return 0 to signal end-of-file */
2290 if (off > 0x40000) /* ALWAYS stop after 256k bytes have been read */
2292 if (hd->proc & PR_STOP) /* stop every other time */
2296 #else /* PROC_INTERFACE */
2300 #endif /* PROC_INTERFACE */
2304 MODULE_LICENSE("GPL");
2307 static Scsi_Host_Template driver_template = {
2308 .proc_name = "in2000",
2309 .proc_info = in2000_proc_info,
2310 .name = "Always IN2000",
2311 .detect = in2000_detect,
2312 .release = in2000_release,
2313 .queuecommand = in2000_queuecommand,
2314 .eh_abort_handler = in2000_abort,
2315 .eh_bus_reset_handler = in2000_bus_reset,
2316 .eh_device_reset_handler = in2000_device_reset,
2317 .eh_host_reset_handler = in2000_host_reset,
2318 .bios_param = in2000_biosparam,
2319 .can_queue = IN2000_CAN_Q,
2320 .this_id = IN2000_HOST_ID,
2321 .sg_tablesize = IN2000_SG,
2322 .cmd_per_lun = IN2000_CPL,
2323 .use_clustering = DISABLE_CLUSTERING,
2325 #include "scsi_module.c"