1 /* fdomain.c -- Future Domain TMC-16x0 SCSI driver
2 * Created: Sun May 3 18:53:19 1992 by faith@cs.unc.edu
3 * Revised: Mon Dec 28 21:59:02 1998 by faith@acm.org
4 * Author: Rickard E. Faith, faith@cs.unc.edu
5 * Copyright 1992-1996, 1998 Rickard E. Faith (faith@acm.org)
6 * Shared IRQ supported added 7/7/2001 Alan Cox <alan@redhat.com>
8 * This program is free software; you can redistribute it and/or modify it
9 * under the terms of the GNU General Public License as published by the
10 * Free Software Foundation; either version 2, or (at your option) any
13 * This program is distributed in the hope that it will be useful, but
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * General Public License for more details.
18 * You should have received a copy of the GNU General Public License along
19 * with this program; if not, write to the Free Software Foundation, Inc.,
20 * 675 Mass Ave, Cambridge, MA 02139, USA.
22 **************************************************************************
26 Future Domain BIOS versions supported for autodetect:
27 2.0, 3.0, 3.2, 3.4 (1.0), 3.5 (2.0), 3.6, 3.61
29 TMC-1800, TMC-18C50, TMC-18C30, TMC-36C70
31 Future Domain TMC-1650, TMC-1660, TMC-1670, TMC-1680, TMC-1610M/MER/MEX
32 Future Domain TMC-3260 (PCI)
33 Quantum ISA-200S, ISA-250MG
34 Adaptec AHA-2920A (PCI) [BUT *NOT* AHA-2920C -- use aic7xxx instead]
36 LILO/INSMOD command-line options:
37 fdomain=<PORT_BASE>,<IRQ>[,<ADAPTER_ID>]
43 The Adaptec AHA-2920C has an Adaptec AIC-7850 chip on it.
44 Use the aic7xxx driver for this board.
46 The Adaptec AHA-2920A has a Future Domain chip on it, so this is the right
47 driver for that card. Unfortunately, the boxes will probably just say
48 "2920", so you'll have to look on the card for a Future Domain logo, or a
49 letter after the 2920.
55 Thanks to Adaptec for providing PCI boards for testing. This finally
56 enabled me to test the PCI detection and correct it for PCI boards that do
57 not have a BIOS at a standard ISA location. For PCI boards, LILO/INSMOD
58 command-line options should no longer be needed. --RF 18Nov98
64 This is the Linux low-level SCSI driver for Future Domain TMC-1660/1680
65 TMC-1650/1670, and TMC-3260 SCSI host adapters. The 1650 and 1670 have a
66 25-pin external connector, whereas the 1660 and 1680 have a SCSI-2 50-pin
67 high-density external connector. The 1670 and 1680 have floppy disk
68 controllers built in. The TMC-3260 is a PCI bus card.
70 Future Domain's older boards are based on the TMC-1800 chip, and this
71 driver was originally written for a TMC-1680 board with the TMC-1800 chip.
72 More recently, boards are being produced with the TMC-18C50 and TMC-18C30
73 chips. The latest and greatest board may not work with this driver. If
74 you have to patch this driver so that it will recognize your board's BIOS
75 signature, then the driver may fail to function after the board is
78 Please note that the drive ordering that Future Domain implemented in BIOS
79 versions 3.4 and 3.5 is the opposite of the order (currently) used by the
80 rest of the SCSI industry. If you have BIOS version 3.4 or 3.5, and have
81 more then one drive, then the drive ordering will be the reverse of that
82 which you see under DOS. For example, under DOS SCSI ID 0 will be D: and
83 SCSI ID 1 will be C: (the boot device). Under Linux, SCSI ID 0 will be
84 /dev/sda and SCSI ID 1 will be /dev/sdb. The Linux ordering is consistent
85 with that provided by all the other SCSI drivers for Linux. If you want
86 this changed, you will probably have to patch the higher level SCSI code.
87 If you do so, please send me patches that are protected by #ifdefs.
89 If you have a TMC-8xx or TMC-9xx board, then this is not the driver for
90 your board. Please refer to the Seagate driver for more information and
98 Version Version Date Support/Notes
100 0.0 3 May 1992 V2.0 BIOS; 1800 chip
102 0.98.6 3.1 27 Nov 1992
105 0.99.3 3.3 10 Jan 1993 V3.0 BIOS
106 0.99.5 3.5 18 Feb 1993
107 0.99.10 3.6 15 May 1993 V3.2 BIOS; 18C50 chip
108 0.99.11 3.17 3 Jul 1993 (now under RCS)
109 0.99.12 3.18 13 Aug 1993
110 0.99.14 5.6 31 Oct 1993 (reselection code removed)
112 0.99.15 5.9 23 Jan 1994 V3.4 BIOS (preliminary)
113 1.0.8/1.1.1 5.15 1 Apr 1994 V3.4 BIOS; 18C30 chip (preliminary)
114 1.0.9/1.1.3 5.16 7 Apr 1994 V3.4 BIOS; 18C30 chip
115 1.1.38 5.18 30 Jul 1994 36C70 chip (PCI version of 18C30)
116 1.1.62 5.20 2 Nov 1994 V3.5 BIOS
117 1.1.73 5.22 7 Dec 1994 Quantum ISA-200S board; V2.0 BIOS
119 1.1.82 5.26 14 Jan 1995 V3.5 BIOS; TMC-1610M/MER/MEX board
120 1.2.10 5.28 5 Jun 1995 Quantum ISA-250MG board; V2.0, V2.01 BIOS
121 1.3.4 5.31 23 Jun 1995 PCI BIOS-32 detection (preliminary)
122 1.3.7 5.33 4 Jul 1995 PCI BIOS-32 detection
123 1.3.28 5.36 17 Sep 1995 V3.61 BIOS; LILO command-line support
124 1.3.34 5.39 12 Oct 1995 V3.60 BIOS; /proc
125 1.3.72 5.39 8 Feb 1996 Adaptec AHA-2920 board
126 1.3.85 5.41 4 Apr 1996
127 2.0.12 5.44 8 Aug 1996 Use ID 7 for all PCI cards
128 2.1.1 5.45 2 Oct 1996 Update ROM accesses for 2.1.x
129 2.1.97 5.46 23 Apr 1998 Rewritten PCI detection routines [mj]
130 2.1.11x 5.47 9 Aug 1998 Touched for 8 SCSI disk majors support
131 5.48 18 Nov 1998 BIOS no longer needed for PCI detection
132 2.2.0 5.50 28 Dec 1998 Support insmod parameters
137 "TMC-1800 SCSI Chip Specification (FDC-1800T)", Future Domain Corporation,
140 "Technical Reference Manual: 18C50 SCSI Host Adapter Chip", Future Domain
141 Corporation, January 1992.
143 "LXT SCSI Products: Specifications and OEM Technical Manual (Revision
144 B/September 1991)", Maxtor Corporation, 1991.
146 "7213S product Manual (Revision P3)", Maxtor Corporation, 1992.
148 "Draft Proposed American National Standard: Small Computer System
149 Interface - 2 (SCSI-2)", Global Engineering Documents. (X3T9.2/86-109,
150 revision 10h, October 17, 1991)
152 Private communications, Drew Eckhardt (drew@cs.colorado.edu) and Eric
153 Youngdale (ericy@cais.com), 1992.
155 Private communication, Tuong Le (Future Domain Engineering department),
156 1994. (Disk geometry computations for Future Domain BIOS version 3.4, and
157 TMC-18C30 detection.)
159 Hogan, Thom. The Programmer's PC Sourcebook. Microsoft Press, 1988. Page
160 60 (2.39: Disk Partition Table Layout).
162 "18C30 Technical Reference Manual", Future Domain Corporation, 1993, page
169 The Maxtor manuals were free. Maxtor telephone technical support is
172 The Future Domain manuals were $25 and $35. They document the chip, not
173 the TMC-16x0 boards, so some information I had to guess at. In 1992,
174 Future Domain sold DOS BIOS source for $250 and the UN*X driver source was
175 $750, but these required a non-disclosure agreement, so even if I could
176 have afforded them, they would *not* have been useful for writing this
177 publically distributable driver. Future Domain technical support has
178 provided some information on the phone and have sent a few useful FAXs.
179 They have been much more helpful since they started to recognize that the
180 word "Linux" refers to an operating system :-).
186 There are many other alpha testers that come and go as the driver
187 develops. The people listed here were most helpful in times of greatest
188 need (mostly early on -- I've probably left out a few worthy people in
191 Todd Carrico (todd@wutc.wustl.edu), Dan Poirier (poirier@cs.unc.edu ), Ken
192 Corey (kenc@sol.acs.unt.edu), C. de Bruin (bruin@bruin@sterbbs.nl), Sakari
193 Aaltonen (sakaria@vipunen.hit.fi), John Rice (rice@xanth.cs.odu.edu), Brad
194 Yearwood (brad@optilink.com), and Ray Toy (toy@soho.crd.ge.com).
196 Special thanks to Tien-Wan Yang (twyang@cs.uh.edu), who graciously lent me
197 his 18C50-based card for debugging. He is the sole reason that this
198 driver works with the 18C50 chip.
200 Thanks to Dave Newman (dnewman@crl.com) for providing initial patches for
201 the version 3.4 BIOS.
203 Thanks to James T. McKinley (mckinley@msupa.pa.msu.edu) for providing
204 patches that support the TMC-3260, a PCI bus card with the 36C70 chip.
205 The 36C70 chip appears to be "completely compatible" with the 18C30 chip.
207 Thanks to Eric Kasten (tigger@petroglyph.cl.msu.edu) for providing the
208 patch for the version 3.5 BIOS.
210 Thanks for Stephen Henson (shenson@nyx10.cs.du.edu) for providing the
211 patch for the Quantum ISA-200S SCSI adapter.
213 Thanks to Adam Bowen for the signature to the 1610M/MER/MEX scsi cards, to
214 Martin Andrews (andrewm@ccfadm.eeg.ccf.org) for the signature to some
215 random TMC-1680 repackaged by IBM; and to Mintak Ng (mintak@panix.com) for
216 the version 3.61 BIOS signature.
218 Thanks for Mark Singer (elf@netcom.com) and Richard Simpson
219 (rsimpson@ewrcsdra.demon.co.uk) for more Quantum signatures and detective
220 work on the Quantum RAM layout.
222 Special thanks to James T. McKinley (mckinley@msupa.pa.msu.edu) for
223 providing patches for proper PCI BIOS32-mediated detection of the TMC-3260
224 card (a PCI bus card with the 36C70 chip). Please send James PCI-related
227 Thanks to Tom Cavin (tec@usa1.com) for preliminary command-line option
230 New PCI detection code written by Martin Mares <mj@atrey.karlin.mff.cuni.cz>
232 Insmod parameter code based on patches from Daniel Graham
233 <graham@balance.uoregon.edu>.
235 All of the alpha testers deserve much thanks.
239 NOTES ON USER DEFINABLE OPTIONS:
241 DEBUG: This turns on the printing of various debug information.
243 ENABLE_PARITY: This turns on SCSI parity checking. With the current
244 driver, all attached devices must support SCSI parity. If none of your
245 devices support parity, then you can probably get the driver to work by
246 turning this option off. I have no way of testing this, however, and it
247 would appear that no one ever uses this option.
249 FIFO_COUNT: The host adapter has an 8K cache (host adapters based on the
250 18C30 chip have a 2k cache). When this many 512 byte blocks are filled by
251 the SCSI device, an interrupt will be raised. Therefore, this could be as
252 low as 0, or as high as 16. Note, however, that values which are too high
253 or too low seem to prevent any interrupts from occurring, and thereby lock
254 up the machine. I have found that 2 is a good number, but throughput may
255 be increased by changing this value to values which are close to 2.
256 Please let me know if you try any different values.
258 DO_DETECT: This activates some old scan code which was needed before the
259 high level drivers got fixed. If you are having trouble with the driver,
260 turning this on should not hurt, and might help. Please let me know if
261 this is the case, since this code will be removed from future drivers.
263 RESELECTION: This is no longer an option, since I gave up trying to
264 implement it in version 4.x of this driver. It did not improve
265 performance at all and made the driver unstable (because I never found one
266 of the two race conditions which were introduced by the multiple
267 outstanding command code). The instability seems a very high price to pay
268 just so that you don't have to wait for the tape to rewind. If you want
269 this feature implemented, send me patches. I'll be happy to send a copy
270 of my (broken) driver to anyone who would like to see a copy.
272 **************************************************************************/
274 #include <linux/module.h>
280 #include <linux/init.h>
281 #include <linux/sched.h>
283 #include <linux/blk.h>
287 #include <asm/system.h>
288 #include <linux/spinlock.h>
289 #include <linux/errno.h>
290 #include <linux/string.h>
291 #include <linux/ioport.h>
292 #include <linux/proc_fs.h>
293 #include <linux/pci.h>
294 #include <linux/stat.h>
295 #include <linux/delay.h>
297 #include <linux/config.h> /* for CONFIG_PCI */
299 #define VERSION "$Revision: 1.1.1.1 $"
301 /* START OF USER DEFINABLE OPTIONS */
303 #define DEBUG 1 /* Enable debugging output */
304 #define ENABLE_PARITY 1 /* Enable SCSI Parity */
305 #define FIFO_COUNT 2 /* Number of 512 byte blocks before INTR */
306 #define DO_DETECT 0 /* Do device detection here (see scsi.c) */
308 /* END OF USER DEFINABLE OPTIONS */
311 #define EVERY_ACCESS 0 /* Write a line on every scsi access */
312 #define ERRORS_ONLY 1 /* Only write a line if there is an error */
313 #define DEBUG_DETECT 0 /* Debug fdomain_16x0_detect() */
314 #define DEBUG_MESSAGES 1 /* Debug MESSAGE IN phase */
315 #define DEBUG_ABORT 1 /* Debug abort() routine */
316 #define DEBUG_RESET 1 /* Debug reset() routine */
317 #define DEBUG_RACE 1 /* Debug interrupt-driven race condition */
319 #define EVERY_ACCESS 0 /* LEAVE THESE ALONE--CHANGE THE ONES ABOVE */
320 #define ERRORS_ONLY 0
321 #define DEBUG_DETECT 0
322 #define DEBUG_MESSAGES 0
323 #define DEBUG_ABORT 0
324 #define DEBUG_RESET 0
328 /* Errors are reported on the line, so we don't need to report them again */
331 #define ERRORS_ONLY 0
335 #define PARITY_MASK 0x08
337 #define PARITY_MASK 0x00
348 in_arbitration = 0x02,
360 FIFO_Status = 3, /* tmc18c50/tmc18c30 only */
361 Interrupt_Cond = 4, /* tmc18c50/tmc18c30 only */
366 Interrupt_Status = 9,
368 Configuration2 = 11, /* tmc18c50/tmc18c30 only */
379 Memory_Cntl = 5, /* tmc18c50/tmc18c30 only */
381 IO_Control = 11, /* tmc18c30 only */
385 static int port_base = 0;
386 static unsigned long bios_base = 0;
387 static int bios_major = 0;
388 static int bios_minor = 0;
389 static int PCI_bus = 0;
390 static int Quantum = 0; /* Quantum board variant */
391 static int interrupt_level = 0;
392 static volatile int in_command = 0;
393 static Scsi_Cmnd *current_SC = NULL;
394 static enum chip_type chip = unknown;
395 static int adapter_mask = 0;
396 static int this_id = 0;
397 static int setup_called = 0;
400 static volatile int in_interrupt_flag = 0;
403 static int SCSI_Mode_Cntl_port;
404 static int FIFO_Data_Count_port;
405 static int Interrupt_Cntl_port;
406 static int Interrupt_Status_port;
407 static int Read_FIFO_port;
408 static int Read_SCSI_Data_port;
409 static int SCSI_Cntl_port;
410 static int SCSI_Data_NoACK_port;
411 static int SCSI_Status_port;
412 static int TMC_Cntl_port;
413 static int TMC_Status_port;
414 static int Write_FIFO_port;
415 static int Write_SCSI_Data_port;
417 static int FIFO_Size = 0x2000; /* 8k FIFO for
418 pre-tmc18c30 chips */
420 extern void do_fdomain_16x0_intr( int irq, void *dev_id,
421 struct pt_regs * regs );
424 /* Allow insmod parameters to be like LILO
425 parameters. For example:
426 insmod fdomain fdomain=0x140,11
428 static char * fdomain = NULL;
429 MODULE_PARM(fdomain, "s");
432 static unsigned long addresses[] = {
437 0xcc000, /* Extra addresses for PCI boards */
441 #define ADDRESS_COUNT (sizeof( addresses ) / sizeof( unsigned ))
443 static unsigned short ports[] = { 0x140, 0x150, 0x160, 0x170 };
444 #define PORT_COUNT (sizeof( ports ) / sizeof( unsigned short ))
446 static unsigned short ints[] = { 3, 5, 10, 11, 12, 14, 15, 0 };
450 READ THIS BEFORE YOU ADD A SIGNATURE!
452 READING THIS SHORT NOTE CAN SAVE YOU LOTS OF TIME!
454 READ EVERY WORD, ESPECIALLY THE WORD *NOT*
456 This driver works *ONLY* for Future Domain cards using the TMC-1800,
457 TMC-18C50, or TMC-18C30 chip. This includes models TMC-1650, 1660, 1670,
458 and 1680. These are all 16-bit cards.
460 The following BIOS signature signatures are for boards which do *NOT*
461 work with this driver (these TMC-8xx and TMC-9xx boards may work with the
464 FUTURE DOMAIN CORP. (C) 1986-1988 V4.0I 03/16/88
465 FUTURE DOMAIN CORP. (C) 1986-1989 V5.0C2/14/89
466 FUTURE DOMAIN CORP. (C) 1986-1989 V6.0A7/28/89
467 FUTURE DOMAIN CORP. (C) 1986-1990 V6.0105/31/90
468 FUTURE DOMAIN CORP. (C) 1986-1990 V6.0209/18/90
469 FUTURE DOMAIN CORP. (C) 1986-1990 V7.009/18/90
470 FUTURE DOMAIN CORP. (C) 1992 V8.00.004/02/92
472 (The cards which do *NOT* work are all 8-bit cards -- although some of
473 them have a 16-bit form-factor, the upper 8-bits are used only for IRQs
474 and are *NOT* used for data. You can tell the difference by following
475 the tracings on the circuit board -- if only the IRQ lines are involved,
476 you have a "8-bit" card, and should *NOT* use this driver.)
481 const char *signature;
484 int major_bios_version;
485 int minor_bios_version;
486 int flag; /* 1 == PCI_bus, 2 == ISA_200S, 3 == ISA_250MG, 4 == ISA_200S */
489 /* 123456789012345678901234567890123456789012345678901234567890 */
490 { "FUTURE DOMAIN CORP. (C) 1986-1990 1800-V2.07/28/89", 5, 50, 2, 0, 0 },
491 { "FUTURE DOMAIN CORP. (C) 1986-1990 1800-V1.07/28/89", 5, 50, 2, 0, 0 },
492 { "FUTURE DOMAIN CORP. (C) 1986-1990 1800-V2.07/28/89", 72, 50, 2, 0, 2 },
493 { "FUTURE DOMAIN CORP. (C) 1986-1990 1800-V2.0", 73, 43, 2, 0, 3 },
494 { "FUTURE DOMAIN CORP. (C) 1991 1800-V2.0.", 72, 39, 2, 0, 4 },
495 { "FUTURE DOMAIN CORP. (C) 1992 V3.00.004/02/92", 5, 44, 3, 0, 0 },
496 { "FUTURE DOMAIN TMC-18XX (C) 1993 V3.203/12/93", 5, 44, 3, 2, 0 },
497 { "IBM F1 P2 BIOS v1.0104/29/93", 5, 28, 3, -1, 0 },
498 { "Future Domain Corp. V1.0008/18/93", 5, 33, 3, 4, 0 },
499 { "Future Domain Corp. V1.0008/18/93", 26, 33, 3, 4, 1 },
500 { "Adaptec AHA-2920 PCI-SCSI Card", 42, 31, 3, -1, 1 },
501 { "IBM F1 P264/32", 5, 14, 3, -1, 1 },
502 /* This next signature may not be a 3.5 bios */
503 { "Future Domain Corp. V2.0108/18/93", 5, 33, 3, 5, 0 },
504 { "FUTURE DOMAIN CORP. V3.5008/18/93", 5, 34, 3, 5, 0 },
505 { "FUTURE DOMAIN 18c30/18c50/1800 (C) 1994 V3.5", 5, 44, 3, 5, 0 },
506 { "FUTURE DOMAIN CORP. V3.6008/18/93", 5, 34, 3, 6, 0 },
507 { "FUTURE DOMAIN CORP. V3.6108/18/93", 5, 34, 3, 6, 0 },
508 { "FUTURE DOMAIN TMC-18XX", 5, 22, -1, -1, 0 },
510 /* READ NOTICE ABOVE *BEFORE* YOU WASTE YOUR TIME ADDING A SIGNATURE
511 Also, fix the disk geometry code for your signature and send your
512 changes for faith@cs.unc.edu. Above all, do *NOT* change any old
515 Note that the last line will match a "generic" 18XX bios. Because
516 Future Domain has changed the host SCSI ID and/or the location of the
517 geometry information in the on-board RAM area for each of the first
518 three BIOS's, it is still important to enter a fully qualified
519 signature in the table for any new BIOS's (after the host SCSI ID and
520 geometry location are verified). */
523 #define SIGNATURE_COUNT (sizeof( signatures ) / sizeof( struct signature ))
525 static void print_banner( struct Scsi_Host *shpnt )
527 if (!shpnt) return; /* This won't ever happen */
529 if (bios_major < 0 && bios_minor < 0) {
530 printk( "scsi%d: <fdomain> No BIOS; using scsi id %d\n",
531 shpnt->host_no, shpnt->this_id );
533 printk( "scsi%d: <fdomain> BIOS version ", shpnt->host_no );
535 if (bios_major >= 0) printk( "%d.", bios_major );
538 if (bios_minor >= 0) printk( "%d", bios_minor );
541 printk( " at 0x%lx using scsi id %d\n",
542 bios_base, shpnt->this_id );
545 /* If this driver works for later FD PCI
546 boards, we will have to modify banner
547 for additional PCI cards, but for now if
548 it's PCI it's a TMC-3260 - JTM */
549 printk( "scsi%d: <fdomain> %s chip at 0x%x irq ",
551 chip == tmc1800 ? "TMC-1800"
552 : (chip == tmc18c50 ? "TMC-18C50"
553 : (chip == tmc18c30 ?
554 (PCI_bus ? "TMC-36C70 (PCI bus)" : "TMC-18C30")
558 if (interrupt_level) printk( "%d", interrupt_level );
559 else printk( "<none>" );
564 static int __init fdomain_setup( char *str )
568 (void)get_options(str, ARRAY_SIZE(ints), ints);
570 if (setup_called++ || ints[0] < 2 || ints[0] > 3) {
571 printk( "scsi: <fdomain>"
572 " Usage: fdomain=<PORT_BASE>,<IRQ>[,<ADAPTER_ID>]\n" );
573 printk( "scsi: <fdomain> Bad LILO/INSMOD parameters?\n" );
577 port_base = ints[0] >= 1 ? ints[1] : 0;
578 interrupt_level = ints[0] >= 2 ? ints[2] : 0;
579 this_id = ints[0] >= 3 ? ints[3] : 0;
581 bios_major = bios_minor = -1; /* Use geometry for BIOS version >= 3.4 */
586 __setup("fdomain=", fdomain_setup);
589 static void do_pause( unsigned amount ) /* Pause for amount*10 milliseconds */
594 inline static void fdomain_make_bus_idle( void )
596 outb( 0, SCSI_Cntl_port );
597 outb( 0, SCSI_Mode_Cntl_port );
598 if (chip == tmc18c50 || chip == tmc18c30)
599 outb( 0x21 | PARITY_MASK, TMC_Cntl_port ); /* Clear forced intr. */
601 outb( 0x01 | PARITY_MASK, TMC_Cntl_port );
604 static int fdomain_is_valid_port( int port )
608 inb( port + MSB_ID_Code ), inb( port + LSB_ID_Code ) );
611 /* The MCA ID is a unique id for each MCA compatible board. We
612 are using ISA boards, but Future Domain provides the MCA ID
613 anyway. We can use this ID to ensure that this is a Future
614 Domain TMC-1660/TMC-1680.
617 if (inb( port + LSB_ID_Code ) != 0xe9) { /* test for 0x6127 id */
618 if (inb( port + LSB_ID_Code ) != 0x27) return 0;
619 if (inb( port + MSB_ID_Code ) != 0x61) return 0;
621 } else { /* test for 0xe960 id */
622 if (inb( port + MSB_ID_Code ) != 0x60) return 0;
625 /* Try to toggle 32-bit mode. This only
626 works on an 18c30 chip. (User reports
627 say this works, so we should switch to
628 it in the near future.) */
630 outb( 0x80, port + IO_Control );
631 if ((inb( port + Configuration2 ) & 0x80) == 0x80) {
632 outb( 0x00, port + IO_Control );
633 if ((inb( port + Configuration2 ) & 0x80) == 0x00) {
635 FIFO_Size = 0x800; /* 2k FIFO */
638 /* If that failed, we are an 18c50. */
644 static int fdomain_test_loopback( void )
649 for (i = 0; i < 255; i++) {
650 outb( i, port_base + Write_Loopback );
651 result = inb( port_base + Read_Loopback );
658 /* fdomain_get_irq assumes that we have a valid MCA ID for a
659 TMC-1660/TMC-1680 Future Domain board. Now, check to be sure the
660 bios_base matches these ports. If someone was unlucky enough to have
661 purchased more than one Future Domain board, then they will have to
662 modify this code, as we only detect one board here. [The one with the
665 Note that this routine is only used for systems without a PCI BIOS32
666 (e.g., ISA bus). For PCI bus systems, this routine will likely fail
667 unless one of the IRQs listed in the ints array is used by the board.
668 Sometimes it is possible to use the computer's BIOS setup screen to
669 configure a PCI system so that one of these IRQs will be used by the
670 Future Domain card. */
672 static int fdomain_get_irq( int base )
674 int options = inb( base + Configuration1 );
677 printk( "scsi: <fdomain> Options = %x\n", options );
680 /* Check for board with lowest bios_base --
681 this isn't valid for the 18c30 or for
682 boards on the PCI bus, so just assume we
683 have the right board. */
687 && addresses[ (options & 0xc0) >> 6 ] != bios_base) return 0;
689 return ints[ (options & 0x0e) >> 1 ];
692 static int fdomain_isa_detect( int *irq, int *iobase )
695 int base = 0xdeadbeef;
699 printk( "scsi: <fdomain> fdomain_isa_detect:" );
703 for (i = 0; !bios_base && i < ADDRESS_COUNT; i++) {
705 printk( " %lx(%lx),", addresses[i], bios_base );
707 for (j = 0; !bios_base && j < SIGNATURE_COUNT; j++) {
708 if (isa_check_signature(addresses[i] + signatures[j].sig_offset,
709 signatures[j].signature,
710 signatures[j].sig_length )) {
711 bios_major = signatures[j].major_bios_version;
712 bios_minor = signatures[j].minor_bios_version;
713 PCI_bus = (signatures[j].flag == 1);
714 Quantum = (signatures[j].flag > 1) ? signatures[j].flag : 0;
715 bios_base = addresses[i];
720 if (bios_major == 2) {
721 /* The TMC-1660/TMC-1680 has a RAM area just after the BIOS ROM.
722 Assuming the ROM is enabled (otherwise we wouldn't have been
723 able to read the ROM signature :-), then the ROM sets up the
724 RAM area with some magic numbers, such as a list of port
725 base addresses and a list of the disk "geometry" reported to
726 DOS (this geometry has nothing to do with physical geometry).
730 case 2: /* ISA_200S */
731 case 3: /* ISA_250MG */
732 base = isa_readb(bios_base + 0x1fa2) + (isa_readb(bios_base + 0x1fa3) << 8);
734 case 4: /* ISA_200S (another one) */
735 base = isa_readb(bios_base + 0x1fa3) + (isa_readb(bios_base + 0x1fa4) << 8);
738 base = isa_readb(bios_base + 0x1fcc) + (isa_readb(bios_base + 0x1fcd) << 8);
743 printk( " %x,", base );
746 for (flag = 0, i = 0; !flag && i < PORT_COUNT; i++) {
747 if (base == ports[i])
751 if (flag && fdomain_is_valid_port( base )) {
752 *irq = fdomain_get_irq( base );
757 /* This is a bad sign. It usually means that someone patched the
758 BIOS signature list (the signatures variable) to contain a BIOS
759 signature for a board *OTHER THAN* the TMC-1660/TMC-1680. */
762 printk( " RAM FAILED, " );
766 /* Anyway, the alternative to finding the address in the RAM is to just
767 search through every possible port address for one that is attached
768 to the Future Domain card. Don't panic, though, about reading all
769 these random port addresses -- there are rumors that the Future
770 Domain BIOS does something very similar.
772 Do not, however, check ports which the kernel knows are being used by
775 for (i = 0; i < PORT_COUNT; i++) {
777 if (check_region( base, 0x10 )) {
779 printk( " (%x inuse),", base );
784 printk( " %x,", base );
786 if ((flag = fdomain_is_valid_port( base ))) break;
790 if (flag) printk( " SUCCESS\n" );
791 else printk( " FAILURE\n" );
794 if (!flag) return 0; /* iobase not found */
796 *irq = fdomain_get_irq( base );
799 return 1; /* success */
802 /* PCI detection function: int fdomain_pci_bios_detect(int* irq, int*
803 iobase) This function gets the Interrupt Level and I/O base address from
804 the PCI configuration registers. */
807 static int fdomain_pci_bios_detect( int *irq, int *iobase, struct pci_dev **ret_pdev )
809 unsigned int pci_irq; /* PCI interrupt line */
810 unsigned long pci_base; /* PCI I/O base address */
811 struct pci_dev *pdev = NULL;
813 if (!pci_present()) return 0;
816 /* Tell how to print a list of the known PCI devices from bios32 and
817 list vendor and device IDs being used if in debug mode. */
819 printk( "scsi: <fdomain> INFO: use lspci -v to see list of PCI devices\n" );
820 printk( "scsi: <fdomain> TMC-3260 detect:"
821 " Using Vendor ID: 0x%x and Device ID: 0x%x\n",
823 PCI_DEVICE_ID_FD_36C70 );
826 if ((pdev = pci_find_device(PCI_VENDOR_ID_FD,
827 PCI_DEVICE_ID_FD_36C70,
830 if (pci_enable_device(pdev)) return 0;
833 printk( "scsi: <fdomain> TMC-3260 detect:"
834 " PCI bus %u, device %u, function %u\n",
836 PCI_SLOT(pdev->devfn),
837 PCI_FUNC(pdev->devfn));
840 /* We now have the appropriate device function for the FD board so we
841 just read the PCI config info from the registers. */
843 pci_base = pci_resource_start(pdev, 0);
846 /* Now we have the I/O base address and interrupt from the PCI
847 configuration registers. */
854 printk( "scsi: <fdomain> TMC-3260 detect:"
855 " IRQ = %d, I/O base = 0x%x [0x%lx]\n", *irq, *iobase, pci_base );
858 if (!fdomain_is_valid_port( *iobase )) {
859 printk( "scsi: <fdomain>"
860 " PCI card detected, but driver not loaded (invalid port)\n" );
864 /* Fill in a few global variables. Ugh. */
865 bios_major = bios_minor = -1;
874 int fdomain_16x0_detect( Scsi_Host_Template *tpnt )
877 struct Scsi_Host *shpnt;
878 struct pci_dev *pdev = NULL;
882 const int buflen = 255;
884 unsigned char do_inquiry[] = { INQUIRY, 0, 0, 0, buflen, 0 };
885 unsigned char do_request_sense[] = { REQUEST_SENSE, 0, 0, 0, buflen, 0 };
886 unsigned char do_read_capacity[] = { READ_CAPACITY,
887 0, 0, 0, 0, 0, 0, 0, 0, 0 };
888 unsigned char buf[buflen];
891 tpnt->proc_name = "fdomain";
895 fdomain_setup(fdomain);
900 printk( "scsi: <fdomain> No BIOS, using port_base = 0x%x, irq = %d\n",
901 port_base, interrupt_level );
903 if (!fdomain_is_valid_port( port_base )) {
904 printk( "scsi: <fdomain> Cannot locate chip at port base 0x%x\n",
906 printk( "scsi: <fdomain> Bad LILO/INSMOD parameters?\n" );
913 /* Try PCI detection first */
914 flag = fdomain_pci_bios_detect( &interrupt_level, &port_base, &pdev );
917 /* Then try ISA bus detection */
918 flag = fdomain_isa_detect( &interrupt_level, &port_base );
921 printk( "scsi: <fdomain> Detection failed (no card)\n" );
927 SCSI_Mode_Cntl_port = port_base + SCSI_Mode_Cntl;
928 FIFO_Data_Count_port = port_base + FIFO_Data_Count;
929 Interrupt_Cntl_port = port_base + Interrupt_Cntl;
930 Interrupt_Status_port = port_base + Interrupt_Status;
931 Read_FIFO_port = port_base + Read_FIFO;
932 Read_SCSI_Data_port = port_base + Read_SCSI_Data;
933 SCSI_Cntl_port = port_base + SCSI_Cntl;
934 SCSI_Data_NoACK_port = port_base + SCSI_Data_NoACK;
935 SCSI_Status_port = port_base + SCSI_Status;
936 TMC_Cntl_port = port_base + TMC_Cntl;
937 TMC_Status_port = port_base + TMC_Status;
938 Write_FIFO_port = port_base + Write_FIFO;
939 Write_SCSI_Data_port = port_base + Write_SCSI_Data;
941 fdomain_16x0_reset( NULL, 0 );
943 if (fdomain_test_loopback()) {
944 printk( "scsi: <fdomain> Detection failed"
945 " (loopback test failed at port base 0x%x)\n", port_base );
947 printk( "scsi: <fdomain> Bad LILO/INSMOD parameters?\n" );
953 tpnt->this_id = (this_id & 0x07);
954 adapter_mask = (1 << tpnt->this_id);
956 if (PCI_bus || (bios_major == 3 && bios_minor >= 2) || bios_major < 0) {
965 /* Print out a banner here in case we can't
968 shpnt = scsi_register( tpnt, 0 );
971 shpnt->irq = interrupt_level;
972 shpnt->io_port = port_base;
973 scsi_set_pci_device(shpnt, pdev);
974 shpnt->n_io_port = 0x10;
975 print_banner( shpnt );
977 /* Log IRQ with kernel */
978 if (!interrupt_level) {
979 printk( "scsi: <fdomain>"
980 " Card Detected, but driver not loaded (no IRQ)\n" );
983 /* Register the IRQ with the kernel */
985 retcode = request_irq( interrupt_level,
986 do_fdomain_16x0_intr, pdev?SA_SHIRQ:0, "fdomain", shpnt);
989 if (retcode == -EINVAL) {
990 printk( "scsi: <fdomain> IRQ %d is bad!\n", interrupt_level );
991 printk( " This shouldn't happen!\n" );
992 printk( " Send mail to faith@acm.org\n" );
993 } else if (retcode == -EBUSY) {
994 printk( "scsi: <fdomain> IRQ %d is already in use!\n",
996 printk( " Please use another IRQ!\n" );
998 printk( "scsi: <fdomain> Error getting IRQ %d\n",
1000 printk( " This shouldn't happen!\n" );
1001 printk( " Send mail to faith@acm.org\n" );
1003 printk( "scsi: <fdomain> Detected, but driver not loaded (IRQ)\n" );
1008 /* Log I/O ports with kernel */
1009 request_region( port_base, 0x10, "fdomain" );
1013 /* These routines are here because of the way the SCSI bus behaves after
1014 a reset. This appropriate behavior was not handled correctly by the
1015 higher level SCSI routines when I first wrote this driver. Now,
1016 however, correct scan routines are part of scsi.c and these routines
1017 are no longer needed. However, this code is still good for
1020 SCinit.request_buffer = SCinit.buffer = buf;
1021 SCinit.request_bufflen = SCinit.bufflen = sizeof(buf)-1;
1025 printk( "scsi: <fdomain> detection routine scanning for devices:\n" );
1026 for (i = 0; i < 8; i++) {
1028 if (i == tpnt->this_id) /* Skip host adapter */
1030 memcpy(SCinit.cmnd, do_request_sense, sizeof(do_request_sense));
1031 retcode = fdomain_16x0_command(&SCinit);
1033 memcpy(SCinit.cmnd, do_inquiry, sizeof(do_inquiry));
1034 retcode = fdomain_16x0_command(&SCinit);
1036 printk( " SCSI ID %d: ", i );
1037 for (j = 8; j < (buf[4] < 32 ? buf[4] : 32); j++)
1038 printk( "%c", buf[j] >= 20 ? buf[j] : ' ' );
1039 memcpy(SCinit.cmnd, do_read_capacity, sizeof(do_read_capacity));
1040 retcode = fdomain_16x0_command(&SCinit);
1042 unsigned long blocks, size, capacity;
1044 blocks = (buf[0] << 24) | (buf[1] << 16)
1045 | (buf[2] << 8) | buf[3];
1046 size = (buf[4] << 24) | (buf[5] << 16) | (buf[6] << 8) | buf[7];
1047 capacity = +( +(blocks / 1024L) * +(size * 10L)) / 1024L;
1049 printk( "%lu MB (%lu byte blocks)",
1050 ((capacity + 5L) / 10L), size );
1052 memcpy(SCinit.cmnd, do_request_sense, sizeof(do_request_sense));
1053 retcode = fdomain_16x0_command(&SCinit);
1057 memcpy(SCinit.cmnd, do_request_sense, sizeof(do_request_sense));
1058 retcode = fdomain_16x0_command(&SCinit);
1064 return 1; /* Maximum of one adapter will be detected. */
1067 const char *fdomain_16x0_info( struct Scsi_Host *ignore )
1069 static char buffer[128];
1072 strcpy( buffer, "Future Domain 16-bit SCSI Driver Version" );
1073 if (strchr( VERSION, ':')) { /* Assume VERSION is an RCS Revision string */
1074 strcat( buffer, strchr( VERSION, ':' ) + 1 );
1075 pt = strrchr( buffer, '$') - 1;
1076 if (!pt) /* Stripped RCS Revision string? */
1077 pt = buffer + strlen( buffer ) - 1;
1081 } else { /* Assume VERSION is a number */
1082 strcat( buffer, " " VERSION );
1088 /* First pass at /proc information routine. */
1090 * inout : decides on the direction of the dataflow and the meaning of the
1092 * buffer: If inout==FALSE data is being written to it else read from it
1093 * *start: If inout==FALSE start of the valid data in the buffer
1094 * offset: If inout==FALSE offset from the beginning of the imaginary file
1095 * from which we start writing into the buffer
1096 * length: If inout==FALSE max number of bytes to be written into the buffer
1097 * else number of bytes in the buffer
1099 int fdomain_16x0_proc_info( char *buffer, char **start, off_t offset,
1100 int length, int hostno, int inout )
1102 const char *info = fdomain_16x0_info( NULL );
1107 if (inout) return(-ENOSYS);
1110 strcpy( buffer, info );
1111 strcat( buffer, "\n" );
1113 pos = len = strlen( buffer );
1120 *start = buffer + (offset - begin); /* Start of wanted data */
1121 len -= (offset - begin);
1122 if(len > length) len = length;
1128 static int fdomain_arbitrate( void )
1131 unsigned long timeout;
1134 printk( "fdomain_arbitrate()\n" );
1137 outb( 0x00, SCSI_Cntl_port ); /* Disable data drivers */
1138 outb( adapter_mask, port_base + SCSI_Data_NoACK ); /* Set our id bit */
1139 outb( 0x04 | PARITY_MASK, TMC_Cntl_port ); /* Start arbitration */
1143 status = inb( TMC_Status_port ); /* Read adapter status */
1144 if (status & 0x02) /* Arbitration complete */
1146 mdelay(1); /* Wait one millisecond */
1147 } while (--timeout);
1150 fdomain_make_bus_idle();
1153 printk( "Arbitration failed, status = %x\n", status );
1156 printk( "scsi: <fdomain> Arbitration failed, status = %x\n", status );
1162 static int fdomain_select( int target )
1165 unsigned long timeout;
1166 static int flag = 0;
1169 outb( 0x82, SCSI_Cntl_port ); /* Bus Enable + Select */
1170 outb( adapter_mask | (1 << target), SCSI_Data_NoACK_port );
1172 /* Stop arbitration and enable parity */
1173 outb( PARITY_MASK, TMC_Cntl_port );
1175 timeout = 350; /* 350 msec */
1178 status = inb( SCSI_Status_port ); /* Read adapter status */
1179 if (status & 1) { /* Busy asserted */
1180 /* Enable SCSI Bus (on error, should make bus idle with 0) */
1181 outb( 0x80, SCSI_Cntl_port );
1184 mdelay(1); /* wait one msec */
1185 } while (--timeout);
1187 fdomain_make_bus_idle();
1189 if (!target) printk( "Selection failed\n" );
1193 if (!flag) /* Skip first failure for all chips. */
1196 printk( "scsi: <fdomain> Selection failed\n" );
1202 void my_done( int error )
1206 outb( 0x00, Interrupt_Cntl_port );
1207 fdomain_make_bus_idle();
1208 current_SC->result = error;
1209 if (current_SC->scsi_done)
1210 current_SC->scsi_done( current_SC );
1211 else panic( "scsi: <fdomain> current_SC->scsi_done() == NULL" );
1213 panic( "scsi: <fdomain> my_done() called outside of command\n" );
1216 in_interrupt_flag = 0;
1220 void do_fdomain_16x0_intr( int irq, void *dev_id, struct pt_regs * regs )
1222 unsigned long flags;
1225 unsigned data_count;
1227 /* The fdomain_16x0_intr is only called via
1228 the interrupt handler. The goal of the
1229 sti() here is to allow other
1230 interruptions while this routine is
1233 /* Check for other IRQ sources */
1234 if((inb(TMC_Status_port)&0x01)==0)
1238 outb( 0x00, Interrupt_Cntl_port );
1240 /* We usually have one spurious interrupt after each command. Ignore it. */
1241 if (!in_command || !current_SC) { /* Spurious interrupt */
1243 printk( "Spurious interrupt, in_command = %d, current_SC = %x\n",
1244 in_command, current_SC );
1249 /* Abort calls my_done, so we do nothing here. */
1250 if (current_SC->SCp.phase & aborted) {
1252 printk( "scsi: <fdomain> Interrupt after abort, ignoring\n" );
1259 ++in_interrupt_flag;
1262 if (current_SC->SCp.phase & in_arbitration) {
1263 status = inb( TMC_Status_port ); /* Read adapter status */
1264 if (!(status & 0x02)) {
1266 printk( " AFAIL " );
1268 spin_lock_irqsave(&io_request_lock, flags);
1269 my_done( DID_BUS_BUSY << 16 );
1270 spin_unlock_irqrestore(&io_request_lock, flags);
1273 current_SC->SCp.phase = in_selection;
1275 outb( 0x40 | FIFO_COUNT, Interrupt_Cntl_port );
1277 outb( 0x82, SCSI_Cntl_port ); /* Bus Enable + Select */
1278 outb( adapter_mask | (1 << current_SC->target), SCSI_Data_NoACK_port );
1280 /* Stop arbitration and enable parity */
1281 outb( 0x10 | PARITY_MASK, TMC_Cntl_port );
1283 in_interrupt_flag = 0;
1286 } else if (current_SC->SCp.phase & in_selection) {
1287 status = inb( SCSI_Status_port );
1288 if (!(status & 0x01)) {
1289 /* Try again, for slow devices */
1290 if (fdomain_select( current_SC->target )) {
1292 printk( " SFAIL " );
1294 spin_lock_irqsave(&io_request_lock, flags);
1295 my_done( DID_NO_CONNECT << 16 );
1296 spin_unlock_irqrestore(&io_request_lock, flags);
1300 printk( " AltSel " );
1302 /* Stop arbitration and enable parity */
1303 outb( 0x10 | PARITY_MASK, TMC_Cntl_port );
1306 current_SC->SCp.phase = in_other;
1307 outb( 0x90 | FIFO_COUNT, Interrupt_Cntl_port );
1308 outb( 0x80, SCSI_Cntl_port );
1310 in_interrupt_flag = 0;
1315 /* current_SC->SCp.phase == in_other: this is the body of the routine */
1317 status = inb( SCSI_Status_port );
1319 if (status & 0x10) { /* REQ */
1321 switch (status & 0x0e) {
1323 case 0x08: /* COMMAND OUT */
1324 outb( current_SC->cmnd[current_SC->SCp.sent_command++],
1325 Write_SCSI_Data_port );
1327 printk( "CMD = %x,",
1328 current_SC->cmnd[ current_SC->SCp.sent_command - 1] );
1331 case 0x00: /* DATA OUT -- tmc18c50/tmc18c30 only */
1332 if (chip != tmc1800 && !current_SC->SCp.have_data_in) {
1333 current_SC->SCp.have_data_in = -1;
1334 outb( 0xd0 | PARITY_MASK, TMC_Cntl_port );
1337 case 0x04: /* DATA IN -- tmc18c50/tmc18c30 only */
1338 if (chip != tmc1800 && !current_SC->SCp.have_data_in) {
1339 current_SC->SCp.have_data_in = 1;
1340 outb( 0x90 | PARITY_MASK, TMC_Cntl_port );
1343 case 0x0c: /* STATUS IN */
1344 current_SC->SCp.Status = inb( Read_SCSI_Data_port );
1346 printk( "Status = %x, ", current_SC->SCp.Status );
1349 if (current_SC->SCp.Status
1350 && current_SC->SCp.Status != 2
1351 && current_SC->SCp.Status != 8) {
1352 printk( "scsi: <fdomain> target = %d, command = %x, status = %x\n",
1354 current_SC->cmnd[0],
1355 current_SC->SCp.Status );
1359 case 0x0a: /* MESSAGE OUT */
1360 outb( MESSAGE_REJECT, Write_SCSI_Data_port ); /* Reject */
1362 case 0x0e: /* MESSAGE IN */
1363 current_SC->SCp.Message = inb( Read_SCSI_Data_port );
1365 printk( "Message = %x, ", current_SC->SCp.Message );
1367 if (!current_SC->SCp.Message) ++done;
1368 #if DEBUG_MESSAGES || EVERY_ACCESS
1369 if (current_SC->SCp.Message) {
1370 printk( "scsi: <fdomain> message = %x\n",
1371 current_SC->SCp.Message );
1379 && !current_SC->SCp.have_data_in
1380 && (current_SC->SCp.sent_command
1381 >= current_SC->cmd_len)) {
1382 /* We have to get the FIFO direction
1383 correct, so I've made a table based
1384 on the SCSI Standard of which commands
1385 appear to require a DATA OUT phase.
1388 p. 94: Command for all device types
1389 CHANGE DEFINITION 40 DATA OUT
1392 COPY AND VERIFY 3a DATA OUT
1394 LOG SELECT 4c DATA OUT
1396 MODE SELECT (6) 15 DATA OUT
1397 MODE SELECT (10) 55 DATA OUT
1401 RECEIVE DIAGNOSTIC RESULTS 1c
1403 SEND DIAGNOSTIC 1d DATA OUT
1405 WRITE BUFFER 3b DATA OUT
1407 p.178: Commands for direct-access devices (not listed on p. 94)
1408 FORMAT UNIT 04 DATA OUT
1409 LOCK-UNLOCK CACHE 36
1411 PREVENT-ALLOW MEDIUM REMOVAL 1e
1415 READ DEFECT DATA (10) 37
1417 REASSIGN BLOCKS 07 DATA OUT
1420 REZERO UNIT/REWIND 01
1421 SEARCH DATA EQUAL (10) 31 DATA OUT
1422 SEARCH DATA HIGH (10) 30 DATA OUT
1423 SEARCH DATA LOW (10) 32 DATA OUT
1428 SYNCHRONIZE CACHE 35
1430 WRITE (6)/PRINT/SEND 0a DATA OUT
1431 WRITE (10)/SEND 2a DATA OUT
1432 WRITE AND VERIFY (10) 2e DATA OUT
1433 WRITE LONG 3f DATA OUT
1434 WRITE SAME 41 DATA OUT ?
1436 p. 261: Commands for sequential-access devices (not previously listed)
1440 READ BLOCK LIMITS 05
1443 RECOVER BUFFERED DATA 14
1445 WRITE FILEMARKS 10 ?
1447 p. 298: Commands for printer devices (not previously listed)
1448 ****** NOT SUPPORTED BY THIS DRIVER, since 0b is SEEK (6) *****
1449 SLEW AND PRINT 0b DATA OUT -- same as seek
1451 SYNCHRONIZE BUFFER 10
1453 p. 315: Commands for processor devices (not previously listed)
1455 p. 321: Commands for write-once devices (not previously listed)
1458 SEARCH DATA EQUAL (12) b1 DATA OUT
1459 SEARCH DATA HIGH (12) b0 DATA OUT
1460 SEARCH DATA LOW (12) b2 DATA OUT
1463 WRITE (12) aa DATA OUT
1464 WRITE AND VERIFY (12) ae DATA OUT
1466 p. 332: Commands for CD-ROM devices (not previously listed)
1471 PLAY TRACK RELATIVE (10) 49
1472 PLAY TRACK RELATIVE (12) a9
1477 p. 370: Commands for scanner devices (not previously listed)
1478 GET DATA BUFFER STATUS 34
1482 SET WINDOW 24 DATA OUT
1484 p. 391: Commands for optical memory devices (not listed)
1487 MEDIUM SCAN 38 DATA OUT
1488 READ DEFECT DATA (12) b7
1490 READ UPDATED BLOCK 2d
1491 UPDATE BLOCK 3d DATA OUT
1493 p. 419: Commands for medium changer devices (not listed)
1495 INITIALIZE ELEMENT STATUS 07
1497 POSITION TO ELEMENT 2b
1498 READ ELEMENT STATUS b8
1499 REQUEST VOL. ELEMENT ADDRESS b5
1500 SEND VOLUME TAG b6 DATA OUT
1502 p. 454: Commands for communications devices (not listed previously)
1508 switch (current_SC->cmnd[0]) {
1509 case CHANGE_DEFINITION: case COMPARE: case COPY:
1510 case COPY_VERIFY: case LOG_SELECT: case MODE_SELECT:
1511 case MODE_SELECT_10: case SEND_DIAGNOSTIC: case WRITE_BUFFER:
1513 case FORMAT_UNIT: case REASSIGN_BLOCKS: case RESERVE:
1514 case SEARCH_EQUAL: case SEARCH_HIGH: case SEARCH_LOW:
1515 case WRITE_6: case WRITE_10: case WRITE_VERIFY:
1516 case 0x3f: case 0x41:
1518 case 0xb1: case 0xb0: case 0xb2:
1519 case 0xaa: case 0xae:
1523 case 0x38: case 0x3d:
1527 case 0xea: /* alternate number for WRITE LONG */
1529 current_SC->SCp.have_data_in = -1;
1530 outb( 0xd0 | PARITY_MASK, TMC_Cntl_port );
1536 current_SC->SCp.have_data_in = 1;
1537 outb( 0x90 | PARITY_MASK, TMC_Cntl_port );
1542 if (current_SC->SCp.have_data_in == -1) { /* DATA OUT */
1543 while ( (data_count = FIFO_Size - inw( FIFO_Data_Count_port )) > 512 ) {
1545 printk( "DC=%d, ", data_count ) ;
1547 if (data_count > current_SC->SCp.this_residual)
1548 data_count = current_SC->SCp.this_residual;
1549 if (data_count > 0) {
1551 printk( "%d OUT, ", data_count );
1553 if (data_count == 1) {
1554 outb( *current_SC->SCp.ptr++, Write_FIFO_port );
1555 --current_SC->SCp.this_residual;
1558 outsw( Write_FIFO_port, current_SC->SCp.ptr, data_count );
1559 current_SC->SCp.ptr += 2 * data_count;
1560 current_SC->SCp.this_residual -= 2 * data_count;
1563 if (!current_SC->SCp.this_residual) {
1564 if (current_SC->SCp.buffers_residual) {
1565 --current_SC->SCp.buffers_residual;
1566 ++current_SC->SCp.buffer;
1567 current_SC->SCp.ptr = current_SC->SCp.buffer->address;
1568 current_SC->SCp.this_residual = current_SC->SCp.buffer->length;
1575 if (current_SC->SCp.have_data_in == 1) { /* DATA IN */
1576 while ((data_count = inw( FIFO_Data_Count_port )) > 0) {
1578 printk( "DC=%d, ", data_count );
1580 if (data_count > current_SC->SCp.this_residual)
1581 data_count = current_SC->SCp.this_residual;
1584 printk( "%d IN, ", data_count );
1586 if (data_count == 1) {
1587 *current_SC->SCp.ptr++ = inb( Read_FIFO_port );
1588 --current_SC->SCp.this_residual;
1590 data_count >>= 1; /* Number of words */
1591 insw( Read_FIFO_port, current_SC->SCp.ptr, data_count );
1592 current_SC->SCp.ptr += 2 * data_count;
1593 current_SC->SCp.this_residual -= 2 * data_count;
1596 if (!current_SC->SCp.this_residual
1597 && current_SC->SCp.buffers_residual) {
1598 --current_SC->SCp.buffers_residual;
1599 ++current_SC->SCp.buffer;
1600 current_SC->SCp.ptr = current_SC->SCp.buffer->address;
1601 current_SC->SCp.this_residual = current_SC->SCp.buffer->length;
1608 printk( " ** IN DONE %d ** ", current_SC->SCp.have_data_in );
1612 if (current_SC->cmnd[0] == REQUEST_SENSE && !current_SC->SCp.Status) {
1613 if ((unsigned char)(*((char *)current_SC->request_buffer+2)) & 0x0f) {
1616 unsigned char qualifier;
1618 key = (unsigned char)(*((char *)current_SC->request_buffer + 2))
1620 code = (unsigned char)(*((char *)current_SC->request_buffer + 12));
1621 qualifier = (unsigned char)(*((char *)current_SC->request_buffer
1624 if (key != UNIT_ATTENTION
1625 && !(key == NOT_READY
1627 && (!qualifier || qualifier == 0x02 || qualifier == 0x01))
1628 && !(key == ILLEGAL_REQUEST && (code == 0x25
1632 printk( "scsi: <fdomain> REQUEST SENSE"
1633 " Key = %x, Code = %x, Qualifier = %x\n",
1634 key, code, qualifier );
1639 printk( "BEFORE MY_DONE. . ." );
1641 spin_lock_irqsave(&io_request_lock, flags);
1642 my_done( (current_SC->SCp.Status & 0xff)
1643 | ((current_SC->SCp.Message & 0xff) << 8) | (DID_OK << 16) );
1644 spin_unlock_irqrestore(&io_request_lock, flags);
1646 printk( "RETURNING.\n" );
1650 if (current_SC->SCp.phase & disconnect) {
1651 outb( 0xd0 | FIFO_COUNT, Interrupt_Cntl_port );
1652 outb( 0x00, SCSI_Cntl_port );
1654 outb( 0x90 | FIFO_COUNT, Interrupt_Cntl_port );
1658 in_interrupt_flag = 0;
1663 int fdomain_16x0_queue( Scsi_Cmnd * SCpnt, void (*done)(Scsi_Cmnd *))
1666 panic( "scsi: <fdomain> fdomain_16x0_queue() NOT REENTRANT!\n" );
1669 printk( "queue: target = %d cmnd = 0x%02x pieces = %d size = %u\n",
1671 *(unsigned char *)SCpnt->cmnd,
1673 SCpnt->request_bufflen );
1676 fdomain_make_bus_idle();
1678 current_SC = SCpnt; /* Save this for the done function */
1679 current_SC->scsi_done = done;
1681 /* Initialize static data */
1683 if (current_SC->use_sg) {
1684 current_SC->SCp.buffer =
1685 (struct scatterlist *)current_SC->request_buffer;
1686 current_SC->SCp.ptr = current_SC->SCp.buffer->address;
1687 current_SC->SCp.this_residual = current_SC->SCp.buffer->length;
1688 current_SC->SCp.buffers_residual = current_SC->use_sg - 1;
1690 current_SC->SCp.ptr = (char *)current_SC->request_buffer;
1691 current_SC->SCp.this_residual = current_SC->request_bufflen;
1692 current_SC->SCp.buffer = NULL;
1693 current_SC->SCp.buffers_residual = 0;
1697 current_SC->SCp.Status = 0;
1698 current_SC->SCp.Message = 0;
1699 current_SC->SCp.have_data_in = 0;
1700 current_SC->SCp.sent_command = 0;
1701 current_SC->SCp.phase = in_arbitration;
1703 /* Start arbitration */
1704 outb( 0x00, Interrupt_Cntl_port );
1705 outb( 0x00, SCSI_Cntl_port ); /* Disable data drivers */
1706 outb( adapter_mask, SCSI_Data_NoACK_port ); /* Set our id bit */
1708 outb( 0x20, Interrupt_Cntl_port );
1709 outb( 0x14 | PARITY_MASK, TMC_Cntl_port ); /* Start arbitration */
1714 /* The following code, which simulates the old-style command function, was
1715 taken from Tommy Thorn's aha1542.c file. This code is Copyright (C)
1716 1992 Tommy Thorn. */
1718 static volatile int internal_done_flag = 0;
1719 static volatile int internal_done_errcode = 0;
1721 static void internal_done( Scsi_Cmnd *SCpnt )
1723 internal_done_errcode = SCpnt->result;
1724 ++internal_done_flag;
1727 int fdomain_16x0_command( Scsi_Cmnd *SCpnt )
1729 fdomain_16x0_queue( SCpnt, internal_done );
1731 while (!internal_done_flag)
1733 internal_done_flag = 0;
1734 return internal_done_errcode;
1737 /* End of code derived from Tommy Thorn's work. */
1739 void print_info( Scsi_Cmnd *SCpnt )
1745 if (!SCpnt || !SCpnt->host) {
1746 printk( "scsi: <fdomain> Cannot provide detailed information\n" );
1750 printk( "%s\n", fdomain_16x0_info( SCpnt->host ) );
1751 print_banner( SCpnt->host );
1752 switch (SCpnt->SCp.phase) {
1753 case in_arbitration: printk( "arbitration " ); break;
1754 case in_selection: printk( "selection " ); break;
1755 case in_other: printk( "other " ); break;
1756 default: printk( "unknown " ); break;
1759 printk( "(%d), target = %d cmnd = 0x%02x pieces = %d size = %u\n",
1762 *(unsigned char *)SCpnt->cmnd,
1764 SCpnt->request_bufflen );
1765 printk( "sent_command = %d, have_data_in = %d, timeout = %d\n",
1766 SCpnt->SCp.sent_command,
1767 SCpnt->SCp.have_data_in,
1770 printk( "in_interrupt_flag = %d\n", in_interrupt_flag );
1773 imr = (inb( 0x0a1 ) << 8) + inb( 0x21 );
1775 irr = inb( 0xa0 ) << 8;
1779 isr = inb( 0xa0 ) << 8;
1783 /* Print out interesting information */
1784 printk( "IMR = 0x%04x", imr );
1785 if (imr & (1 << interrupt_level))
1786 printk( " (masked)" );
1787 printk( ", IRR = 0x%04x, ISR = 0x%04x\n", irr, isr );
1789 printk( "SCSI Status = 0x%02x\n", inb( SCSI_Status_port ) );
1790 printk( "TMC Status = 0x%02x", inb( TMC_Status_port ) );
1791 if (inb( TMC_Status_port & 1))
1792 printk( " (interrupt)" );
1794 printk( "Interrupt Status = 0x%02x", inb( Interrupt_Status_port ) );
1795 if (inb( Interrupt_Status_port ) & 0x08)
1796 printk( " (enabled)" );
1798 if (chip == tmc18c50 || chip == tmc18c30) {
1799 printk( "FIFO Status = 0x%02x\n", inb( port_base + FIFO_Status ) );
1800 printk( "Int. Condition = 0x%02x\n",
1801 inb( port_base + Interrupt_Cond ) );
1803 printk( "Configuration 1 = 0x%02x\n", inb( port_base + Configuration1 ) );
1804 if (chip == tmc18c50 || chip == tmc18c30)
1805 printk( "Configuration 2 = 0x%02x\n",
1806 inb( port_base + Configuration2 ) );
1809 int fdomain_16x0_abort( Scsi_Cmnd *SCpnt)
1811 unsigned long flags;
1812 #if EVERY_ACCESS || ERRORS_ONLY || DEBUG_ABORT
1813 printk( "scsi: <fdomain> abort " );
1816 save_flags( flags );
1819 #if EVERY_ACCESS || ERRORS_ONLY
1820 printk( " (not in command)\n" );
1822 restore_flags( flags );
1823 return SCSI_ABORT_NOT_RUNNING;
1824 } else printk( "\n" );
1827 print_info( SCpnt );
1830 fdomain_make_bus_idle();
1832 current_SC->SCp.phase |= aborted;
1834 current_SC->result = DID_ABORT << 16;
1836 restore_flags( flags );
1838 /* Aborts are not done well. . . */
1839 my_done( DID_ABORT << 16 );
1841 return SCSI_ABORT_SUCCESS;
1844 int fdomain_16x0_reset( Scsi_Cmnd *SCpnt, unsigned int ignored )
1847 static int called_once = 0;
1851 if (SCpnt) printk( "scsi: <fdomain> SCSI Bus Reset\n" );
1855 if (called_once) print_info( current_SC );
1859 outb( 1, SCSI_Cntl_port );
1861 outb( 0, SCSI_Cntl_port );
1863 outb( 0, SCSI_Mode_Cntl_port );
1864 outb( PARITY_MASK, TMC_Cntl_port );
1866 /* Unless this is the very first call (i.e., SCPnt == NULL), everything
1867 is probably hosed at this point. We will, however, try to keep
1868 things going by informing the high-level code that we need help. */
1870 return SCSI_RESET_WAKEUP;
1874 #include <scsi/scsi_ioctl.h>
1876 int fdomain_16x0_biosparam( Scsi_Disk *disk, kdev_t dev, int *info_array )
1879 unsigned char buf[512 + sizeof (Scsi_Ioctl_Command)];
1880 Scsi_Ioctl_Command *sic = (Scsi_Ioctl_Command *) buf;
1881 int size = disk->capacity;
1882 unsigned char *data = sic->data;
1883 unsigned char do_read[] = { READ_6, 0, 0, 0, 1, 0 };
1885 unsigned long offset;
1887 unsigned short cylinders;
1888 unsigned char heads;
1889 unsigned char sectors;
1893 The RAM area starts at 0x1f00 from the bios_base address.
1895 For BIOS Version 2.0:
1897 The drive parameter table seems to start at 0x1f30.
1898 The first byte's purpose is not known.
1899 Next is the cylinder, head, and sector information.
1900 The last 4 bytes appear to be the drive's size in sectors.
1901 The other bytes in the drive parameter table are unknown.
1902 If anyone figures them out, please send me mail, and I will
1905 Tape drives do not get placed in this table.
1907 There is another table at 0x1fea:
1908 If the byte is 0x01, then the SCSI ID is not in use.
1909 If the byte is 0x18 or 0x48, then the SCSI ID is in use,
1910 although tapes don't seem to be in this table. I haven't
1911 seen any other numbers (in a limited sample).
1913 0x1f2d is a drive count (i.e., not including tapes)
1915 The table at 0x1fcc are I/O ports addresses for the various
1916 operations. I calculate these by hand in this driver code.
1920 For the ISA-200S version of BIOS Version 2.0:
1922 The drive parameter table starts at 0x1f33.
1924 WARNING: Assume that the table entry is 25 bytes long. Someone needs
1925 to check this for the Quantum ISA-200S card.
1929 For BIOS Version 3.2:
1931 The drive parameter table starts at 0x1f70. Each entry is
1932 0x0a bytes long. Heads are one less than we need to report.
1935 if (MAJOR(dev) != SCSI_DISK0_MAJOR) {
1936 printk("scsi: <fdomain> fdomain_16x0_biosparam: too many disks");
1939 drive = MINOR(dev) >> 4;
1941 if (bios_major == 2) {
1943 case 2: /* ISA_200S */
1944 /* The value of 25 has never been verified.
1945 It should probably be 15. */
1946 offset = bios_base + 0x1f33 + drive * 25;
1948 case 3: /* ISA_250MG */
1949 offset = bios_base + 0x1f36 + drive * 15;
1951 case 4: /* ISA_200S (another one) */
1952 offset = bios_base + 0x1f34 + drive * 15;
1955 offset = bios_base + 0x1f31 + drive * 25;
1958 isa_memcpy_fromio( &i, offset, sizeof( struct drive_info ) );
1959 info_array[0] = i.heads;
1960 info_array[1] = i.sectors;
1961 info_array[2] = i.cylinders;
1962 } else if (bios_major == 3
1964 && bios_minor < 4) { /* 3.0 and 3.2 BIOS */
1965 memcpy_fromio( &i, bios_base + 0x1f71 + drive * 10,
1966 sizeof( struct drive_info ) );
1967 info_array[0] = i.heads + 1;
1968 info_array[1] = i.sectors;
1969 info_array[2] = i.cylinders;
1970 } else { /* 3.4 BIOS (and up?) */
1971 /* This algorithm was provided by Future Domain (much thanks!). */
1973 sic->inlen = 0; /* zero bytes out */
1974 sic->outlen = 512; /* one sector in */
1975 memcpy( data, do_read, sizeof( do_read ) );
1976 retcode = kernel_scsi_ioctl( disk->device,
1977 SCSI_IOCTL_SEND_COMMAND,
1979 if (!retcode /* SCSI command ok */
1980 && data[511] == 0xaa && data[510] == 0x55 /* Partition table valid */
1981 && data[0x1c2]) { /* Partition type */
1983 /* The partition table layout is as follows:
1986 Offset: 0 = partition status
1988 2 = starting sector and cylinder (word, encoded)
1991 6 = ending sector and cylinder (word, encoded)
1992 8 = starting absolute sector (double word)
1993 c = number of sectors (double word)
1994 Signature: 0x1fe = 0x55aa
1996 So, this algorithm assumes:
1997 1) the first partition table is in use,
1998 2) the data in the first entry is correct, and
1999 3) partitions never divide cylinders
2001 Note that (1) may be FALSE for NetBSD (and other BSD flavors),
2002 as well as for Linux. Note also, that Linux doesn't pay any
2003 attention to the fields that are used by this algorithm -- it
2004 only uses the absolute sector data. Recent versions of Linux's
2005 fdisk(1) will fill this data in correctly, and forthcoming
2006 versions will check for consistency.
2008 Checking for a non-zero partition type is not part of the
2009 Future Domain algorithm, but it seemed to be a reasonable thing
2010 to do, especially in the Linux and BSD worlds. */
2012 info_array[0] = data[0x1c3] + 1; /* heads */
2013 info_array[1] = data[0x1c4] & 0x3f; /* sectors */
2016 /* Note that this new method guarantees that there will always be
2017 less than 1024 cylinders on a platter. This is good for drives
2018 up to approximately 7.85GB (where 1GB = 1024 * 1024 kB). */
2020 if ((unsigned int)size >= 0x7e0000U) {
2021 info_array[0] = 0xff; /* heads = 255 */
2022 info_array[1] = 0x3f; /* sectors = 63 */
2023 } else if ((unsigned int)size >= 0x200000U) {
2024 info_array[0] = 0x80; /* heads = 128 */
2025 info_array[1] = 0x3f; /* sectors = 63 */
2027 info_array[0] = 0x40; /* heads = 64 */
2028 info_array[1] = 0x20; /* sectors = 32 */
2031 /* For both methods, compute the cylinders */
2032 info_array[2] = (unsigned int)size / (info_array[0] * info_array[1] );
2038 int fdomain_16x0_release(struct Scsi_Host *shpnt)
2041 free_irq(shpnt->irq, shpnt);
2042 if (shpnt->io_port && shpnt->n_io_port)
2043 release_region(shpnt->io_port, shpnt->n_io_port);
2047 MODULE_LICENSE("GPL");
2049 /* Eventually this will go into an include file, but this will be later */
2050 static Scsi_Host_Template driver_template = FDOMAIN_16X0;
2052 #include "scsi_module.c"