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)
7 * This program is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License as published by the
9 * Free Software Foundation; either version 2, or (at your option) any
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License for more details.
17 * You should have received a copy of the GNU General Public License along
18 * with this program; if not, write to the Free Software Foundation, Inc.,
19 * 675 Mass Ave, Cambridge, MA 02139, USA.
21 **************************************************************************
25 Future Domain BIOS versions supported for autodetect:
26 2.0, 3.0, 3.2, 3.4 (1.0), 3.5 (2.0), 3.6, 3.61
28 TMC-1800, TMC-18C50, TMC-18C30, TMC-36C70
30 Future Domain TMC-1650, TMC-1660, TMC-1670, TMC-1680, TMC-1610M/MER/MEX
31 Future Domain TMC-3260 (PCI)
32 Quantum ISA-200S, ISA-250MG
33 Adaptec AHA-2920A (PCI) [BUT *NOT* AHA-2920C -- use aic7xxx instead]
35 LILO/INSMOD command-line options:
36 fdomain=<PORT_BASE>,<IRQ>[,<ADAPTER_ID>]
42 The Adaptec AHA-2920C has an Adaptec AIC-7850 chip on it.
43 Use the aic7xxx driver for this board.
45 The Adaptec AHA-2920A has a Future Domain chip on it, so this is the right
46 driver for that card. Unfortunately, the boxes will probably just say
47 "2920", so you'll have to look on the card for a Future Domain logo, or a
48 letter after the 2920.
54 Thanks to Adaptec for providing PCI boards for testing. This finally
55 enabled me to test the PCI detection and correct it for PCI boards that do
56 not have a BIOS at a standard ISA location. For PCI boards, LILO/INSMOD
57 command-line options should no longer be needed. --RF 18Nov98
63 This is the Linux low-level SCSI driver for Future Domain TMC-1660/1680
64 TMC-1650/1670, and TMC-3260 SCSI host adapters. The 1650 and 1670 have a
65 25-pin external connector, whereas the 1660 and 1680 have a SCSI-2 50-pin
66 high-density external connector. The 1670 and 1680 have floppy disk
67 controllers built in. The TMC-3260 is a PCI bus card.
69 Future Domain's older boards are based on the TMC-1800 chip, and this
70 driver was originally written for a TMC-1680 board with the TMC-1800 chip.
71 More recently, boards are being produced with the TMC-18C50 and TMC-18C30
72 chips. The latest and greatest board may not work with this driver. If
73 you have to patch this driver so that it will recognize your board's BIOS
74 signature, then the driver may fail to function after the board is
77 Please note that the drive ordering that Future Domain implemented in BIOS
78 versions 3.4 and 3.5 is the opposite of the order (currently) used by the
79 rest of the SCSI industry. If you have BIOS version 3.4 or 3.5, and have
80 more then one drive, then the drive ordering will be the reverse of that
81 which you see under DOS. For example, under DOS SCSI ID 0 will be D: and
82 SCSI ID 1 will be C: (the boot device). Under Linux, SCSI ID 0 will be
83 /dev/sda and SCSI ID 1 will be /dev/sdb. The Linux ordering is consistent
84 with that provided by all the other SCSI drivers for Linux. If you want
85 this changed, you will probably have to patch the higher level SCSI code.
86 If you do so, please send me patches that are protected by #ifdefs.
88 If you have a TMC-8xx or TMC-9xx board, then this is not the driver for
89 your board. Please refer to the Seagate driver for more information and
97 Version Version Date Support/Notes
99 0.0 3 May 1992 V2.0 BIOS; 1800 chip
101 0.98.6 3.1 27 Nov 1992
104 0.99.3 3.3 10 Jan 1993 V3.0 BIOS
105 0.99.5 3.5 18 Feb 1993
106 0.99.10 3.6 15 May 1993 V3.2 BIOS; 18C50 chip
107 0.99.11 3.17 3 Jul 1993 (now under RCS)
108 0.99.12 3.18 13 Aug 1993
109 0.99.14 5.6 31 Oct 1993 (reselection code removed)
111 0.99.15 5.9 23 Jan 1994 V3.4 BIOS (preliminary)
112 1.0.8/1.1.1 5.15 1 Apr 1994 V3.4 BIOS; 18C30 chip (preliminary)
113 1.0.9/1.1.3 5.16 7 Apr 1994 V3.4 BIOS; 18C30 chip
114 1.1.38 5.18 30 Jul 1994 36C70 chip (PCI version of 18C30)
115 1.1.62 5.20 2 Nov 1994 V3.5 BIOS
116 1.1.73 5.22 7 Dec 1994 Quantum ISA-200S board; V2.0 BIOS
118 1.1.82 5.26 14 Jan 1995 V3.5 BIOS; TMC-1610M/MER/MEX board
119 1.2.10 5.28 5 Jun 1995 Quantum ISA-250MG board; V2.0, V2.01 BIOS
120 1.3.4 5.31 23 Jun 1995 PCI BIOS-32 detection (preliminary)
121 1.3.7 5.33 4 Jul 1995 PCI BIOS-32 detection
122 1.3.28 5.36 17 Sep 1995 V3.61 BIOS; LILO command-line support
123 1.3.34 5.39 12 Oct 1995 V3.60 BIOS; /proc
124 1.3.72 5.39 8 Feb 1996 Adaptec AHA-2920 board
125 1.3.85 5.41 4 Apr 1996
126 2.0.12 5.44 8 Aug 1996 Use ID 7 for all PCI cards
127 2.1.1 5.45 2 Oct 1996 Update ROM accesses for 2.1.x
128 2.1.97 5.46 23 Apr 1998 Rewritten PCI detection routines [mj]
129 2.1.11x 5.47 9 Aug 1998 Touched for 8 SCSI disk majors support
130 5.48 18 Nov 1998 BIOS no longer needed for PCI detection
131 2.2.0 5.50 28 Dec 1998 Support insmod parameters
136 "TMC-1800 SCSI Chip Specification (FDC-1800T)", Future Domain Corporation,
139 "Technical Reference Manual: 18C50 SCSI Host Adapter Chip", Future Domain
140 Corporation, January 1992.
142 "LXT SCSI Products: Specifications and OEM Technical Manual (Revision
143 B/September 1991)", Maxtor Corporation, 1991.
145 "7213S product Manual (Revision P3)", Maxtor Corporation, 1992.
147 "Draft Proposed American National Standard: Small Computer System
148 Interface - 2 (SCSI-2)", Global Engineering Documents. (X3T9.2/86-109,
149 revision 10h, October 17, 1991)
151 Private communications, Drew Eckhardt (drew@cs.colorado.edu) and Eric
152 Youngdale (ericy@cais.com), 1992.
154 Private communication, Tuong Le (Future Domain Engineering department),
155 1994. (Disk geometry computations for Future Domain BIOS version 3.4, and
156 TMC-18C30 detection.)
158 Hogan, Thom. The Programmer's PC Sourcebook. Microsoft Press, 1988. Page
159 60 (2.39: Disk Partition Table Layout).
161 "18C30 Technical Reference Manual", Future Domain Corporation, 1993, page
168 The Maxtor manuals were free. Maxtor telephone technical support is
171 The Future Domain manuals were $25 and $35. They document the chip, not
172 the TMC-16x0 boards, so some information I had to guess at. In 1992,
173 Future Domain sold DOS BIOS source for $250 and the UN*X driver source was
174 $750, but these required a non-disclosure agreement, so even if I could
175 have afforded them, they would *not* have been useful for writing this
176 publically distributable driver. Future Domain technical support has
177 provided some information on the phone and have sent a few useful FAXs.
178 They have been much more helpful since they started to recognize that the
179 word "Linux" refers to an operating system :-).
185 There are many other alpha testers that come and go as the driver
186 develops. The people listed here were most helpful in times of greatest
187 need (mostly early on -- I've probably left out a few worthy people in
190 Todd Carrico (todd@wutc.wustl.edu), Dan Poirier (poirier@cs.unc.edu ), Ken
191 Corey (kenc@sol.acs.unt.edu), C. de Bruin (bruin@bruin@sterbbs.nl), Sakari
192 Aaltonen (sakaria@vipunen.hit.fi), John Rice (rice@xanth.cs.odu.edu), Brad
193 Yearwood (brad@optilink.com), and Ray Toy (toy@soho.crd.ge.com).
195 Special thanks to Tien-Wan Yang (twyang@cs.uh.edu), who graciously lent me
196 his 18C50-based card for debugging. He is the sole reason that this
197 driver works with the 18C50 chip.
199 Thanks to Dave Newman (dnewman@crl.com) for providing initial patches for
200 the version 3.4 BIOS.
202 Thanks to James T. McKinley (mckinley@msupa.pa.msu.edu) for providing
203 patches that support the TMC-3260, a PCI bus card with the 36C70 chip.
204 The 36C70 chip appears to be "completely compatible" with the 18C30 chip.
206 Thanks to Eric Kasten (tigger@petroglyph.cl.msu.edu) for providing the
207 patch for the version 3.5 BIOS.
209 Thanks for Stephen Henson (shenson@nyx10.cs.du.edu) for providing the
210 patch for the Quantum ISA-200S SCSI adapter.
212 Thanks to Adam Bowen for the signature to the 1610M/MER/MEX scsi cards, to
213 Martin Andrews (andrewm@ccfadm.eeg.ccf.org) for the signature to some
214 random TMC-1680 repackaged by IBM; and to Mintak Ng (mintak@panix.com) for
215 the version 3.61 BIOS signature.
217 Thanks for Mark Singer (elf@netcom.com) and Richard Simpson
218 (rsimpson@ewrcsdra.demon.co.uk) for more Quantum signatures and detective
219 work on the Quantum RAM layout.
221 Special thanks to James T. McKinley (mckinley@msupa.pa.msu.edu) for
222 providing patches for proper PCI BIOS32-mediated detection of the TMC-3260
223 card (a PCI bus card with the 36C70 chip). Please send James PCI-related
226 Thanks to Tom Cavin (tec@usa1.com) for preliminary command-line option
229 New PCI detection code written by Martin Mares <mj@atrey.karlin.mff.cuni.cz>
231 Insmod parameter code based on patches from Daniel Graham
232 <graham@balance.uoregon.edu>.
234 All of the alpha testers deserve much thanks.
238 NOTES ON USER DEFINABLE OPTIONS:
240 DEBUG: This turns on the printing of various debug information.
242 ENABLE_PARITY: This turns on SCSI parity checking. With the current
243 driver, all attached devices must support SCSI parity. If none of your
244 devices support parity, then you can probably get the driver to work by
245 turning this option off. I have no way of testing this, however, and it
246 would appear that no one ever uses this option.
248 FIFO_COUNT: The host adapter has an 8K cache (host adapters based on the
249 18C30 chip have a 2k cache). When this many 512 byte blocks are filled by
250 the SCSI device, an interrupt will be raised. Therefore, this could be as
251 low as 0, or as high as 16. Note, however, that values which are too high
252 or too low seem to prevent any interrupts from occurring, and thereby lock
253 up the machine. I have found that 2 is a good number, but throughput may
254 be increased by changing this value to values which are close to 2.
255 Please let me know if you try any different values.
257 DO_DETECT: This activates some old scan code which was needed before the
258 high level drivers got fixed. If you are having trouble with the driver,
259 turning this on should not hurt, and might help. Please let me know if
260 this is the case, since this code will be removed from future drivers.
262 RESELECTION: This is no longer an option, since I gave up trying to
263 implement it in version 4.x of this driver. It did not improve
264 performance at all and made the driver unstable (because I never found one
265 of the two race conditions which were introduced by the multiple
266 outstanding command code). The instability seems a very high price to pay
267 just so that you don't have to wait for the tape to rewind. If you want
268 this feature implemented, send me patches. I'll be happy to send a copy
269 of my (broken) driver to anyone who would like to see a copy.
271 **************************************************************************/
278 #include <linux/module.h>
285 #include <linux/sched.h>
287 #include <linux/blk.h>
291 #include <asm/system.h>
292 #include <linux/spinlock.h>
293 #include <linux/errno.h>
294 #include <linux/string.h>
295 #include <linux/ioport.h>
296 #include <linux/proc_fs.h>
297 #include <linux/pci.h>
298 #include <linux/stat.h>
299 #include <linux/delay.h>
301 #include <linux/config.h> /* for CONFIG_PCI */
303 struct proc_dir_entry proc_scsi_fdomain
= {
304 PROC_SCSI_FDOMAIN
, 7, "fdomain",
305 S_IFDIR
| S_IRUGO
| S_IXUGO
, 2
308 #define VERSION "$Revision: 5.50 $"
310 /* START OF USER DEFINABLE OPTIONS */
312 #define DEBUG 1 /* Enable debugging output */
313 #define ENABLE_PARITY 1 /* Enable SCSI Parity */
314 #define FIFO_COUNT 2 /* Number of 512 byte blocks before INTR */
315 #define DO_DETECT 0 /* Do device detection here (see scsi.c) */
317 /* END OF USER DEFINABLE OPTIONS */
320 #define EVERY_ACCESS 0 /* Write a line on every scsi access */
321 #define ERRORS_ONLY 1 /* Only write a line if there is an error */
322 #define DEBUG_DETECT 0 /* Debug fdomain_16x0_detect() */
323 #define DEBUG_MESSAGES 1 /* Debug MESSAGE IN phase */
324 #define DEBUG_ABORT 1 /* Debug abort() routine */
325 #define DEBUG_RESET 1 /* Debug reset() routine */
326 #define DEBUG_RACE 1 /* Debug interrupt-driven race condition */
328 #define EVERY_ACCESS 0 /* LEAVE THESE ALONE--CHANGE THE ONES ABOVE */
329 #define ERRORS_ONLY 0
330 #define DEBUG_DETECT 0
331 #define DEBUG_MESSAGES 0
332 #define DEBUG_ABORT 0
333 #define DEBUG_RESET 0
337 /* Errors are reported on the line, so we don't need to report them again */
340 #define ERRORS_ONLY 0
344 #define PARITY_MASK 0x08
346 #define PARITY_MASK 0x00
357 in_arbitration
= 0x02,
369 FIFO_Status
= 3, /* tmc18c50/tmc18c30 only */
370 Interrupt_Cond
= 4, /* tmc18c50/tmc18c30 only */
375 Interrupt_Status
= 9,
377 Configuration2
= 11, /* tmc18c50/tmc18c30 only */
388 Memory_Cntl
= 5, /* tmc18c50/tmc18c30 only */
390 IO_Control
= 11, /* tmc18c30 only */
394 static int port_base
= 0;
395 static unsigned long bios_base
= 0;
396 static int bios_major
= 0;
397 static int bios_minor
= 0;
398 static int PCI_bus
= 0;
399 static int Quantum
= 0; /* Quantum board variant */
400 static int interrupt_level
= 0;
401 static volatile int in_command
= 0;
402 static Scsi_Cmnd
*current_SC
= NULL
;
403 static enum chip_type chip
= unknown
;
404 static int adapter_mask
= 0;
405 static int this_id
= 0;
406 static int setup_called
= 0;
409 static volatile int in_interrupt_flag
= 0;
412 static int SCSI_Mode_Cntl_port
;
413 static int FIFO_Data_Count_port
;
414 static int Interrupt_Cntl_port
;
415 static int Interrupt_Status_port
;
416 static int Read_FIFO_port
;
417 static int Read_SCSI_Data_port
;
418 static int SCSI_Cntl_port
;
419 static int SCSI_Data_NoACK_port
;
420 static int SCSI_Status_port
;
421 static int TMC_Cntl_port
;
422 static int TMC_Status_port
;
423 static int Write_FIFO_port
;
424 static int Write_SCSI_Data_port
;
426 static int FIFO_Size
= 0x2000; /* 8k FIFO for
427 pre-tmc18c30 chips */
429 extern void do_fdomain_16x0_intr( int irq
, void *dev_id
,
430 struct pt_regs
* regs
);
433 /* Allow insmod parameters to be like LILO
434 parameters. For example:
435 insmod fdomain fdomain=0x140,11
437 static int fdomain
[]={ 0, 0, 0 };
438 MODULE_PARM(fdomain
, "2-3i");
441 static unsigned long addresses
[] = {
446 0xcc000, /* Extra addresses for PCI boards */
450 #define ADDRESS_COUNT (sizeof( addresses ) / sizeof( unsigned ))
452 static unsigned short ports
[] = { 0x140, 0x150, 0x160, 0x170 };
453 #define PORT_COUNT (sizeof( ports ) / sizeof( unsigned short ))
455 static unsigned short ints
[] = { 3, 5, 10, 11, 12, 14, 15, 0 };
459 READ THIS BEFORE YOU ADD A SIGNATURE!
461 READING THIS SHORT NOTE CAN SAVE YOU LOTS OF TIME!
463 READ EVERY WORD, ESPECIALLY THE WORD *NOT*
465 This driver works *ONLY* for Future Domain cards using the TMC-1800,
466 TMC-18C50, or TMC-18C30 chip. This includes models TMC-1650, 1660, 1670,
467 and 1680. These are all 16-bit cards.
469 The following BIOS signature signatures are for boards which do *NOT*
470 work with this driver (these TMC-8xx and TMC-9xx boards may work with the
473 FUTURE DOMAIN CORP. (C) 1986-1988 V4.0I 03/16/88
474 FUTURE DOMAIN CORP. (C) 1986-1989 V5.0C2/14/89
475 FUTURE DOMAIN CORP. (C) 1986-1989 V6.0A7/28/89
476 FUTURE DOMAIN CORP. (C) 1986-1990 V6.0105/31/90
477 FUTURE DOMAIN CORP. (C) 1986-1990 V6.0209/18/90
478 FUTURE DOMAIN CORP. (C) 1986-1990 V7.009/18/90
479 FUTURE DOMAIN CORP. (C) 1992 V8.00.004/02/92
481 (The cards which do *NOT* work are all 8-bit cards -- although some of
482 them have a 16-bit form-factor, the upper 8-bits are used only for IRQs
483 and are *NOT* used for data. You can tell the difference by following
484 the tracings on the circuit board -- if only the IRQ lines are involved,
485 you have a "8-bit" card, and should *NOT* use this driver.)
490 const char *signature
;
493 int major_bios_version
;
494 int minor_bios_version
;
495 int flag
; /* 1 == PCI_bus, 2 == ISA_200S, 3 == ISA_250MG, 4 == ISA_200S */
498 /* 123456789012345678901234567890123456789012345678901234567890 */
499 { "FUTURE DOMAIN CORP. (C) 1986-1990 1800-V2.07/28/89", 5, 50, 2, 0, 0 },
500 { "FUTURE DOMAIN CORP. (C) 1986-1990 1800-V1.07/28/89", 5, 50, 2, 0, 0 },
501 { "FUTURE DOMAIN CORP. (C) 1986-1990 1800-V2.07/28/89", 72, 50, 2, 0, 2 },
502 { "FUTURE DOMAIN CORP. (C) 1986-1990 1800-V2.0", 73, 43, 2, 0, 3 },
503 { "FUTURE DOMAIN CORP. (C) 1991 1800-V2.0.", 72, 39, 2, 0, 4 },
504 { "FUTURE DOMAIN CORP. (C) 1992 V3.00.004/02/92", 5, 44, 3, 0, 0 },
505 { "FUTURE DOMAIN TMC-18XX (C) 1993 V3.203/12/93", 5, 44, 3, 2, 0 },
506 { "IBM F1 P2 BIOS v1.0104/29/93", 5, 28, 3, -1, 0 },
507 { "Future Domain Corp. V1.0008/18/93", 5, 33, 3, 4, 0 },
508 { "Future Domain Corp. V1.0008/18/93", 26, 33, 3, 4, 1 },
509 { "Adaptec AHA-2920 PCI-SCSI Card", 42, 31, 3, -1, 1 },
510 { "IBM F1 P264/32", 5, 14, 3, -1, 1 },
511 /* This next signature may not be a 3.5 bios */
512 { "Future Domain Corp. V2.0108/18/93", 5, 33, 3, 5, 0 },
513 { "FUTURE DOMAIN CORP. V3.5008/18/93", 5, 34, 3, 5, 0 },
514 { "FUTURE DOMAIN 18c30/18c50/1800 (C) 1994 V3.5", 5, 44, 3, 5, 0 },
515 { "FUTURE DOMAIN CORP. V3.6008/18/93", 5, 34, 3, 6, 0 },
516 { "FUTURE DOMAIN CORP. V3.6108/18/93", 5, 34, 3, 6, 0 },
517 { "FUTURE DOMAIN TMC-18XX", 5, 22, -1, -1, 0 },
519 /* READ NOTICE ABOVE *BEFORE* YOU WASTE YOUR TIME ADDING A SIGNATURE
520 Also, fix the disk geometry code for your signature and send your
521 changes for faith@cs.unc.edu. Above all, do *NOT* change any old
524 Note that the last line will match a "generic" 18XX bios. Because
525 Future Domain has changed the host SCSI ID and/or the location of the
526 geometry information in the on-board RAM area for each of the first
527 three BIOS's, it is still important to enter a fully qualified
528 signature in the table for any new BIOS's (after the host SCSI ID and
529 geometry location are verified). */
532 #define SIGNATURE_COUNT (sizeof( signatures ) / sizeof( struct signature ))
534 static void print_banner( struct Scsi_Host
*shpnt
)
536 if (!shpnt
) return; /* This won't ever happen */
538 if (bios_major
< 0 && bios_minor
< 0) {
539 printk( "scsi%d: <fdomain> No BIOS; using scsi id %d\n",
540 shpnt
->host_no
, shpnt
->this_id
);
542 printk( "scsi%d: <fdomain> BIOS version ", shpnt
->host_no
);
544 if (bios_major
>= 0) printk( "%d.", bios_major
);
547 if (bios_minor
>= 0) printk( "%d", bios_minor
);
550 printk( " at 0x%lx using scsi id %d\n",
551 bios_base
, shpnt
->this_id
);
554 /* If this driver works for later FD PCI
555 boards, we will have to modify banner
556 for additional PCI cards, but for now if
557 it's PCI it's a TMC-3260 - JTM */
558 printk( "scsi%d: <fdomain> %s chip at 0x%x irq ",
560 chip
== tmc1800
? "TMC-1800"
561 : (chip
== tmc18c50
? "TMC-18C50"
562 : (chip
== tmc18c30
?
563 (PCI_bus
? "TMC-36C70 (PCI bus)" : "TMC-18C30")
567 if (interrupt_level
) printk( "%d", interrupt_level
);
568 else printk( "<none>" );
573 void fdomain_setup( char *str
, int *ints
)
575 if (setup_called
++ || ints
[0] < 2 || ints
[0] > 3) {
576 printk( "scsi: <fdomain>"
577 " Usage: fdomain=<PORT_BASE>,<IRQ>[,<ADAPTER_ID>]\n" );
578 printk( "scsi: <fdomain> Bad LILO/INSMOD parameters?\n" );
581 port_base
= ints
[0] >= 1 ? ints
[1] : 0;
582 interrupt_level
= ints
[0] >= 2 ? ints
[2] : 0;
583 this_id
= ints
[0] >= 3 ? ints
[3] : 0;
585 bios_major
= bios_minor
= -1; /* Use geometry for BIOS version >= 3.4 */
589 static void do_pause( unsigned amount
) /* Pause for amount*10 milliseconds */
596 inline static void fdomain_make_bus_idle( void )
598 outb( 0, SCSI_Cntl_port
);
599 outb( 0, SCSI_Mode_Cntl_port
);
600 if (chip
== tmc18c50
|| chip
== tmc18c30
)
601 outb( 0x21 | PARITY_MASK
, TMC_Cntl_port
); /* Clear forced intr. */
603 outb( 0x01 | PARITY_MASK
, TMC_Cntl_port
);
606 static int fdomain_is_valid_port( int port
)
610 inb( port
+ MSB_ID_Code
), inb( port
+ LSB_ID_Code
) );
613 /* The MCA ID is a unique id for each MCA compatible board. We
614 are using ISA boards, but Future Domain provides the MCA ID
615 anyway. We can use this ID to ensure that this is a Future
616 Domain TMC-1660/TMC-1680.
619 if (inb( port
+ LSB_ID_Code
) != 0xe9) { /* test for 0x6127 id */
620 if (inb( port
+ LSB_ID_Code
) != 0x27) return 0;
621 if (inb( port
+ MSB_ID_Code
) != 0x61) return 0;
623 } else { /* test for 0xe960 id */
624 if (inb( port
+ MSB_ID_Code
) != 0x60) return 0;
627 /* Try to toggle 32-bit mode. This only
628 works on an 18c30 chip. (User reports
629 say this works, so we should switch to
630 it in the near future.) */
632 outb( 0x80, port
+ IO_Control
);
633 if ((inb( port
+ Configuration2
) & 0x80) == 0x80) {
634 outb( 0x00, port
+ IO_Control
);
635 if ((inb( port
+ Configuration2
) & 0x80) == 0x00) {
637 FIFO_Size
= 0x800; /* 2k FIFO */
640 /* If that failed, we are an 18c50. */
646 static int fdomain_test_loopback( void )
651 for (i
= 0; i
< 255; i
++) {
652 outb( i
, port_base
+ Write_Loopback
);
653 result
= inb( port_base
+ Read_Loopback
);
660 /* fdomain_get_irq assumes that we have a valid MCA ID for a
661 TMC-1660/TMC-1680 Future Domain board. Now, check to be sure the
662 bios_base matches these ports. If someone was unlucky enough to have
663 purchased more than one Future Domain board, then they will have to
664 modify this code, as we only detect one board here. [The one with the
667 Note that this routine is only used for systems without a PCI BIOS32
668 (e.g., ISA bus). For PCI bus systems, this routine will likely fail
669 unless one of the IRQs listed in the ints array is used by the board.
670 Sometimes it is possible to use the computer's BIOS setup screen to
671 configure a PCI system so that one of these IRQs will be used by the
672 Future Domain card. */
674 static int fdomain_get_irq( int base
)
676 int options
= inb( base
+ Configuration1
);
679 printk( "scsi: <fdomain> Options = %x\n", options
);
682 /* Check for board with lowest bios_base --
683 this isn't valid for the 18c30 or for
684 boards on the PCI bus, so just assume we
685 have the right board. */
689 && addresses
[ (options
& 0xc0) >> 6 ] != bios_base
) return 0;
691 return ints
[ (options
& 0x0e) >> 1 ];
694 static int fdomain_isa_detect( int *irq
, int *iobase
)
701 printk( "scsi: <fdomain> fdomain_isa_detect:" );
704 for (i
= 0; !bios_base
&& i
< ADDRESS_COUNT
; i
++) {
706 printk( " %lx(%lx),", addresses
[i
], bios_base
);
708 for (j
= 0; !bios_base
&& j
< SIGNATURE_COUNT
; j
++) {
709 if (check_signature(addresses
[i
] + signatures
[j
].sig_offset
,
710 signatures
[j
].signature
,
711 signatures
[j
].sig_length
)) {
712 bios_major
= signatures
[j
].major_bios_version
;
713 bios_minor
= signatures
[j
].minor_bios_version
;
714 PCI_bus
= (signatures
[j
].flag
== 1);
715 Quantum
= (signatures
[j
].flag
> 1) ? signatures
[j
].flag
: 0;
716 bios_base
= addresses
[i
];
721 if (bios_major
== 2) {
722 /* The TMC-1660/TMC-1680 has a RAM area just after the BIOS ROM.
723 Assuming the ROM is enabled (otherwise we wouldn't have been
724 able to read the ROM signature :-), then the ROM sets up the
725 RAM area with some magic numbers, such as a list of port
726 base addresses and a list of the disk "geometry" reported to
727 DOS (this geometry has nothing to do with physical geometry).
731 case 2: /* ISA_200S */
732 case 3: /* ISA_250MG */
733 base
= readb(bios_base
+ 0x1fa2) + (readb(bios_base
+ 0x1fa3) << 8);
735 case 4: /* ISA_200S (another one) */
736 base
= readb(bios_base
+ 0x1fa3) + (readb(bios_base
+ 0x1fa4) << 8);
739 base
= readb(bios_base
+ 0x1fcc) + (readb(bios_base
+ 0x1fcd) << 8);
744 printk( " %x,", base
);
747 for (flag
= 0, i
= 0; !flag
&& i
< PORT_COUNT
; i
++) {
748 if (base
== ports
[i
])
752 if (flag
&& fdomain_is_valid_port( base
)) {
753 *irq
= fdomain_get_irq( base
);
758 /* This is a bad sign. It usually means that someone patched the
759 BIOS signature list (the signatures variable) to contain a BIOS
760 signature for a board *OTHER THAN* the TMC-1660/TMC-1680. */
763 printk( " RAM FAILED, " );
767 /* Anyway, the alternative to finding the address in the RAM is to just
768 search through every possible port address for one that is attached
769 to the Future Domain card. Don't panic, though, about reading all
770 these random port addresses -- there are rumors that the Future
771 Domain BIOS does something very similar.
773 Do not, however, check ports which the kernel knows are being used by
776 for (i
= 0; i
< PORT_COUNT
; i
++) {
778 if (check_region( base
, 0x10 )) {
780 printk( " (%x inuse),", base
);
785 printk( " %x,", base
);
787 if ((flag
= fdomain_is_valid_port( base
))) break;
791 if (flag
) printk( " SUCCESS\n" );
792 else printk( " FAILURE\n" );
795 if (!flag
) return 0; /* iobase not found */
797 *irq
= fdomain_get_irq( base
);
800 return 1; /* success */
803 /* PCI detection function: int fdomain_pci_bios_detect(int* irq, int*
804 iobase) This function gets the Interrupt Level and I/O base address from
805 the PCI configuration registers. */
808 static int fdomain_pci_bios_detect( int *irq
, int *iobase
)
810 unsigned int pci_irq
; /* PCI interrupt line */
811 unsigned long pci_base
; /* PCI I/O base address */
812 struct pci_dev
*pdev
= NULL
;
814 if (!pci_present()) return 0;
817 /* Tell how to print a list of the known PCI devices from bios32 and
818 list vendor and device IDs being used if in debug mode. */
820 printk( "scsi: <fdomain> INFO: use lspci -v to see list of PCI devices\n" );
821 printk( "scsi: <fdomain> TMC-3260 detect:"
822 " Using Vendor ID: 0x%x and Device ID: 0x%x\n",
824 PCI_DEVICE_ID_FD_36C70
);
827 if ((pdev
= pci_find_device(PCI_VENDOR_ID_FD
,
828 PCI_DEVICE_ID_FD_36C70
,
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
= pdev
->resource
[0].start
;
846 /* Now we have the I/O base address and interrupt from the PCI
847 configuration registers. */
853 printk( "scsi: <fdomain> TMC-3260 detect:"
854 " IRQ = %d, I/O base = 0x%x [0x%lx]\n", *irq
, *iobase
, pci_base
);
857 if (!fdomain_is_valid_port( *iobase
)) {
858 printk( "scsi: <fdomain>"
859 " PCI card detected, but driver not loaded (invalid port)\n" );
863 /* Fill in a few global variables. Ugh. */
864 bios_major
= bios_minor
= -1;
873 int fdomain_16x0_detect( Scsi_Host_Template
*tpnt
)
876 struct Scsi_Host
*shpnt
;
878 const int buflen
= 255;
880 unsigned char do_inquiry
[] = { INQUIRY
, 0, 0, 0, buflen
, 0 };
881 unsigned char do_request_sense
[] = { REQUEST_SENSE
, 0, 0, 0, buflen
, 0 };
882 unsigned char do_read_capacity
[] = { READ_CAPACITY
,
883 0, 0, 0, 0, 0, 0, 0, 0, 0 };
884 unsigned char buf
[buflen
];
887 tpnt
->proc_dir
= &proc_scsi_fdomain
;
890 if (fdomain
[0] || fdomain
[1] || fdomain
[2]) {
891 port_base
= fdomain
[0];
892 interrupt_level
= fdomain
[1];
893 this_id
= fdomain
[2];
894 bios_major
= bios_minor
= -1;
901 printk( "scsi: <fdomain> No BIOS, using port_base = 0x%x, irq = %d\n",
902 port_base
, interrupt_level
);
904 if (!fdomain_is_valid_port( port_base
)) {
905 printk( "scsi: <fdomain> Cannot locate chip at port base 0x%x\n",
907 printk( "scsi: <fdomain> Bad LILO/INSMOD parameters?\n" );
914 /* Try PCI detection first */
915 flag
= fdomain_pci_bios_detect( &interrupt_level
, &port_base
);
918 /* Then try ISA bus detection */
919 flag
= fdomain_isa_detect( &interrupt_level
, &port_base
);
922 printk( "scsi: <fdomain> Detection failed (no card)\n" );
928 SCSI_Mode_Cntl_port
= port_base
+ SCSI_Mode_Cntl
;
929 FIFO_Data_Count_port
= port_base
+ FIFO_Data_Count
;
930 Interrupt_Cntl_port
= port_base
+ Interrupt_Cntl
;
931 Interrupt_Status_port
= port_base
+ Interrupt_Status
;
932 Read_FIFO_port
= port_base
+ Read_FIFO
;
933 Read_SCSI_Data_port
= port_base
+ Read_SCSI_Data
;
934 SCSI_Cntl_port
= port_base
+ SCSI_Cntl
;
935 SCSI_Data_NoACK_port
= port_base
+ SCSI_Data_NoACK
;
936 SCSI_Status_port
= port_base
+ SCSI_Status
;
937 TMC_Cntl_port
= port_base
+ TMC_Cntl
;
938 TMC_Status_port
= port_base
+ TMC_Status
;
939 Write_FIFO_port
= port_base
+ Write_FIFO
;
940 Write_SCSI_Data_port
= port_base
+ Write_SCSI_Data
;
942 fdomain_16x0_reset( NULL
, 0 );
944 if (fdomain_test_loopback()) {
945 printk( "scsi: <fdomain> Detection failed"
946 " (loopback test failed at port base 0x%x)\n", port_base
);
948 printk( "scsi: <fdomain> Bad LILO/INSMOD parameters?\n" );
954 tpnt
->this_id
= (this_id
& 0x07);
955 adapter_mask
= (1 << tpnt
->this_id
);
957 if (PCI_bus
|| (bios_major
== 3 && bios_minor
>= 2) || bios_major
< 0) {
966 /* Print out a banner here in case we can't
969 shpnt
= scsi_register( tpnt
, 0 );
970 shpnt
->irq
= interrupt_level
;
971 shpnt
->io_port
= port_base
;
972 shpnt
->n_io_port
= 0x10;
973 print_banner( shpnt
);
975 /* Log IRQ with kernel */
976 if (!interrupt_level
) {
977 printk( "scsi: <fdomain>"
978 " Card Detected, but driver not loaded (no IRQ)\n" );
981 /* Register the IRQ with the kernel */
983 retcode
= request_irq( interrupt_level
,
984 do_fdomain_16x0_intr
, 0, "fdomain", NULL
);
987 if (retcode
== -EINVAL
) {
988 printk( "scsi: <fdomain> IRQ %d is bad!\n", interrupt_level
);
989 printk( " This shouldn't happen!\n" );
990 printk( " Send mail to faith@acm.org\n" );
991 } else if (retcode
== -EBUSY
) {
992 printk( "scsi: <fdomain> IRQ %d is already in use!\n",
994 printk( " Please use another IRQ!\n" );
996 printk( "scsi: <fdomain> Error getting IRQ %d\n",
998 printk( " This shouldn't happen!\n" );
999 printk( " Send mail to faith@acm.org\n" );
1001 printk( "scsi: <fdomain> Detected, but driver not loaded (IRQ)\n" );
1006 /* Log I/O ports with kernel */
1007 request_region( port_base
, 0x10, "fdomain" );
1011 /* These routines are here because of the way the SCSI bus behaves after
1012 a reset. This appropriate behavior was not handled correctly by the
1013 higher level SCSI routines when I first wrote this driver. Now,
1014 however, correct scan routines are part of scsi.c and these routines
1015 are no longer needed. However, this code is still good for
1018 SCinit
.request_buffer
= SCinit
.buffer
= buf
;
1019 SCinit
.request_bufflen
= SCinit
.bufflen
= sizeof(buf
)-1;
1023 printk( "scsi: <fdomain> detection routine scanning for devices:\n" );
1024 for (i
= 0; i
< 8; i
++) {
1026 if (i
== tpnt
->this_id
) /* Skip host adapter */
1028 memcpy(SCinit
.cmnd
, do_request_sense
, sizeof(do_request_sense
));
1029 retcode
= fdomain_16x0_command(&SCinit
);
1031 memcpy(SCinit
.cmnd
, do_inquiry
, sizeof(do_inquiry
));
1032 retcode
= fdomain_16x0_command(&SCinit
);
1034 printk( " SCSI ID %d: ", i
);
1035 for (j
= 8; j
< (buf
[4] < 32 ? buf
[4] : 32); j
++)
1036 printk( "%c", buf
[j
] >= 20 ? buf
[j
] : ' ' );
1037 memcpy(SCinit
.cmnd
, do_read_capacity
, sizeof(do_read_capacity
));
1038 retcode
= fdomain_16x0_command(&SCinit
);
1040 unsigned long blocks
, size
, capacity
;
1042 blocks
= (buf
[0] << 24) | (buf
[1] << 16)
1043 | (buf
[2] << 8) | buf
[3];
1044 size
= (buf
[4] << 24) | (buf
[5] << 16) | (buf
[6] << 8) | buf
[7];
1045 capacity
= +( +(blocks
/ 1024L) * +(size
* 10L)) / 1024L;
1047 printk( "%lu MB (%lu byte blocks)",
1048 ((capacity
+ 5L) / 10L), size
);
1050 memcpy(SCinit
.cmnd
, do_request_sense
, sizeof(do_request_sense
));
1051 retcode
= fdomain_16x0_command(&SCinit
);
1055 memcpy(SCinit
.cmnd
, do_request_sense
, sizeof(do_request_sense
));
1056 retcode
= fdomain_16x0_command(&SCinit
);
1062 return 1; /* Maximum of one adapter will be detected. */
1065 const char *fdomain_16x0_info( struct Scsi_Host
*ignore
)
1067 static char buffer
[128];
1070 strcpy( buffer
, "Future Domain 16-bit SCSI Driver Version" );
1071 if (strchr( VERSION
, ':')) { /* Assume VERSION is an RCS Revision string */
1072 strcat( buffer
, strchr( VERSION
, ':' ) + 1 );
1073 pt
= strrchr( buffer
, '$') - 1;
1074 if (!pt
) /* Stripped RCS Revision string? */
1075 pt
= buffer
+ strlen( buffer
) - 1;
1079 } else { /* Assume VERSION is a number */
1080 strcat( buffer
, " " VERSION
);
1086 /* First pass at /proc information routine. */
1088 * inout : decides on the direction of the dataflow and the meaning of the
1090 * buffer: If inout==FALSE data is being written to it else read from it
1091 * *start: If inout==FALSE start of the valid data in the buffer
1092 * offset: If inout==FALSE offset from the beginning of the imaginary file
1093 * from which we start writing into the buffer
1094 * length: If inout==FALSE max number of bytes to be written into the buffer
1095 * else number of bytes in the buffer
1097 int fdomain_16x0_proc_info( char *buffer
, char **start
, off_t offset
,
1098 int length
, int hostno
, int inout
)
1100 const char *info
= fdomain_16x0_info( NULL
);
1105 if (inout
) return(-ENOSYS
);
1108 strcpy( buffer
, info
);
1109 strcat( buffer
, "\n" );
1111 pos
= len
= strlen( buffer
);
1118 *start
= buffer
+ (offset
- begin
); /* Start of wanted data */
1119 len
-= (offset
- begin
);
1120 if(len
> length
) len
= length
;
1126 static int fdomain_arbitrate( void )
1129 unsigned long timeout
;
1132 printk( "fdomain_arbitrate()\n" );
1135 outb( 0x00, SCSI_Cntl_port
); /* Disable data drivers */
1136 outb( adapter_mask
, port_base
+ SCSI_Data_NoACK
); /* Set our id bit */
1137 outb( 0x04 | PARITY_MASK
, TMC_Cntl_port
); /* Start arbitration */
1141 status
= inb( TMC_Status_port
); /* Read adapter status */
1142 if (status
& 0x02) /* Arbitration complete */
1144 mdelay(1); /* Wait one millisecond */
1145 } while (--timeout
);
1148 fdomain_make_bus_idle();
1151 printk( "Arbitration failed, status = %x\n", status
);
1154 printk( "scsi: <fdomain> Arbitration failed, status = %x\n", status
);
1160 static int fdomain_select( int target
)
1163 unsigned long timeout
;
1164 static int flag
= 0;
1167 outb( 0x82, SCSI_Cntl_port
); /* Bus Enable + Select */
1168 outb( adapter_mask
| (1 << target
), SCSI_Data_NoACK_port
);
1170 /* Stop arbitration and enable parity */
1171 outb( PARITY_MASK
, TMC_Cntl_port
);
1173 timeout
= 350; /* 350 msec */
1176 status
= inb( SCSI_Status_port
); /* Read adapter status */
1177 if (status
& 1) { /* Busy asserted */
1178 /* Enable SCSI Bus (on error, should make bus idle with 0) */
1179 outb( 0x80, SCSI_Cntl_port
);
1182 mdelay(1); /* wait one msec */
1183 } while (--timeout
);
1185 fdomain_make_bus_idle();
1187 if (!target
) printk( "Selection failed\n" );
1191 if (!flag
) /* Skip first failure for all chips. */
1194 printk( "scsi: <fdomain> Selection failed\n" );
1200 void my_done( int error
)
1204 outb( 0x00, Interrupt_Cntl_port
);
1205 fdomain_make_bus_idle();
1206 current_SC
->result
= error
;
1207 if (current_SC
->scsi_done
)
1208 current_SC
->scsi_done( current_SC
);
1209 else panic( "scsi: <fdomain> current_SC->scsi_done() == NULL" );
1211 panic( "scsi: <fdomain> my_done() called outside of command\n" );
1214 in_interrupt_flag
= 0;
1218 void do_fdomain_16x0_intr( int irq
, void *dev_id
, struct pt_regs
* regs
)
1220 unsigned long flags
;
1223 unsigned data_count
;
1225 /* The fdomain_16x0_intr is only called via
1226 the interrupt handler. The goal of the
1227 sti() here is to allow other
1228 interruptions while this routine is
1231 /* sti(); Yes, we really want sti() here if we want to lock up our machine */
1233 outb( 0x00, Interrupt_Cntl_port
);
1235 /* We usually have one spurious interrupt after each command. Ignore it. */
1236 if (!in_command
|| !current_SC
) { /* Spurious interrupt */
1238 printk( "Spurious interrupt, in_command = %d, current_SC = %x\n",
1239 in_command
, current_SC
);
1244 /* Abort calls my_done, so we do nothing here. */
1245 if (current_SC
->SCp
.phase
& aborted
) {
1247 printk( "scsi: <fdomain> Interrupt after abort, ignoring\n" );
1254 ++in_interrupt_flag
;
1257 if (current_SC
->SCp
.phase
& in_arbitration
) {
1258 status
= inb( TMC_Status_port
); /* Read adapter status */
1259 if (!(status
& 0x02)) {
1261 printk( " AFAIL " );
1263 spin_lock_irqsave(&io_request_lock
, flags
);
1264 my_done( DID_BUS_BUSY
<< 16 );
1265 spin_unlock_irqrestore(&io_request_lock
, flags
);
1268 current_SC
->SCp
.phase
= in_selection
;
1270 outb( 0x40 | FIFO_COUNT
, Interrupt_Cntl_port
);
1272 outb( 0x82, SCSI_Cntl_port
); /* Bus Enable + Select */
1273 outb( adapter_mask
| (1 << current_SC
->target
), SCSI_Data_NoACK_port
);
1275 /* Stop arbitration and enable parity */
1276 outb( 0x10 | PARITY_MASK
, TMC_Cntl_port
);
1278 in_interrupt_flag
= 0;
1281 } else if (current_SC
->SCp
.phase
& in_selection
) {
1282 status
= inb( SCSI_Status_port
);
1283 if (!(status
& 0x01)) {
1284 /* Try again, for slow devices */
1285 if (fdomain_select( current_SC
->target
)) {
1287 printk( " SFAIL " );
1289 spin_lock_irqsave(&io_request_lock
, flags
);
1290 my_done( DID_NO_CONNECT
<< 16 );
1291 spin_unlock_irqrestore(&io_request_lock
, flags
);
1295 printk( " AltSel " );
1297 /* Stop arbitration and enable parity */
1298 outb( 0x10 | PARITY_MASK
, TMC_Cntl_port
);
1301 current_SC
->SCp
.phase
= in_other
;
1302 outb( 0x90 | FIFO_COUNT
, Interrupt_Cntl_port
);
1303 outb( 0x80, SCSI_Cntl_port
);
1305 in_interrupt_flag
= 0;
1310 /* current_SC->SCp.phase == in_other: this is the body of the routine */
1312 status
= inb( SCSI_Status_port
);
1314 if (status
& 0x10) { /* REQ */
1316 switch (status
& 0x0e) {
1318 case 0x08: /* COMMAND OUT */
1319 outb( current_SC
->cmnd
[current_SC
->SCp
.sent_command
++],
1320 Write_SCSI_Data_port
);
1322 printk( "CMD = %x,",
1323 current_SC
->cmnd
[ current_SC
->SCp
.sent_command
- 1] );
1326 case 0x00: /* DATA OUT -- tmc18c50/tmc18c30 only */
1327 if (chip
!= tmc1800
&& !current_SC
->SCp
.have_data_in
) {
1328 current_SC
->SCp
.have_data_in
= -1;
1329 outb( 0xd0 | PARITY_MASK
, TMC_Cntl_port
);
1332 case 0x04: /* DATA IN -- tmc18c50/tmc18c30 only */
1333 if (chip
!= tmc1800
&& !current_SC
->SCp
.have_data_in
) {
1334 current_SC
->SCp
.have_data_in
= 1;
1335 outb( 0x90 | PARITY_MASK
, TMC_Cntl_port
);
1338 case 0x0c: /* STATUS IN */
1339 current_SC
->SCp
.Status
= inb( Read_SCSI_Data_port
);
1341 printk( "Status = %x, ", current_SC
->SCp
.Status
);
1344 if (current_SC
->SCp
.Status
1345 && current_SC
->SCp
.Status
!= 2
1346 && current_SC
->SCp
.Status
!= 8) {
1347 printk( "scsi: <fdomain> target = %d, command = %x, status = %x\n",
1349 current_SC
->cmnd
[0],
1350 current_SC
->SCp
.Status
);
1354 case 0x0a: /* MESSAGE OUT */
1355 outb( MESSAGE_REJECT
, Write_SCSI_Data_port
); /* Reject */
1357 case 0x0e: /* MESSAGE IN */
1358 current_SC
->SCp
.Message
= inb( Read_SCSI_Data_port
);
1360 printk( "Message = %x, ", current_SC
->SCp
.Message
);
1362 if (!current_SC
->SCp
.Message
) ++done
;
1363 #if DEBUG_MESSAGES || EVERY_ACCESS
1364 if (current_SC
->SCp
.Message
) {
1365 printk( "scsi: <fdomain> message = %x\n",
1366 current_SC
->SCp
.Message
);
1374 && !current_SC
->SCp
.have_data_in
1375 && (current_SC
->SCp
.sent_command
1376 >= current_SC
->cmd_len
)) {
1377 /* We have to get the FIFO direction
1378 correct, so I've made a table based
1379 on the SCSI Standard of which commands
1380 appear to require a DATA OUT phase.
1383 p. 94: Command for all device types
1384 CHANGE DEFINITION 40 DATA OUT
1387 COPY AND VERIFY 3a DATA OUT
1389 LOG SELECT 4c DATA OUT
1391 MODE SELECT (6) 15 DATA OUT
1392 MODE SELECT (10) 55 DATA OUT
1396 RECEIVE DIAGNOSTIC RESULTS 1c
1398 SEND DIAGNOSTIC 1d DATA OUT
1400 WRITE BUFFER 3b DATA OUT
1402 p.178: Commands for direct-access devices (not listed on p. 94)
1403 FORMAT UNIT 04 DATA OUT
1404 LOCK-UNLOCK CACHE 36
1406 PREVENT-ALLOW MEDIUM REMOVAL 1e
1410 READ DEFECT DATA (10) 37
1412 REASSIGN BLOCKS 07 DATA OUT
1415 REZERO UNIT/REWIND 01
1416 SEARCH DATA EQUAL (10) 31 DATA OUT
1417 SEARCH DATA HIGH (10) 30 DATA OUT
1418 SEARCH DATA LOW (10) 32 DATA OUT
1423 SYNCHRONIZE CACHE 35
1425 WRITE (6)/PRINT/SEND 0a DATA OUT
1426 WRITE (10)/SEND 2a DATA OUT
1427 WRITE AND VERIFY (10) 2e DATA OUT
1428 WRITE LONG 3f DATA OUT
1429 WRITE SAME 41 DATA OUT ?
1431 p. 261: Commands for sequential-access devices (not previously listed)
1435 READ BLOCK LIMITS 05
1438 RECOVER BUFFERED DATA 14
1440 WRITE FILEMARKS 10 ?
1442 p. 298: Commands for printer devices (not previously listed)
1443 ****** NOT SUPPORTED BY THIS DRIVER, since 0b is SEEK (6) *****
1444 SLEW AND PRINT 0b DATA OUT -- same as seek
1446 SYNCHRONIZE BUFFER 10
1448 p. 315: Commands for processor devices (not previously listed)
1450 p. 321: Commands for write-once devices (not previously listed)
1453 SEARCH DATA EQUAL (12) b1 DATA OUT
1454 SEARCH DATA HIGH (12) b0 DATA OUT
1455 SEARCH DATA LOW (12) b2 DATA OUT
1458 WRITE (12) aa DATA OUT
1459 WRITE AND VERIFY (12) ae DATA OUT
1461 p. 332: Commands for CD-ROM devices (not previously listed)
1466 PLAY TRACK RELATIVE (10) 49
1467 PLAY TRACK RELATIVE (12) a9
1472 p. 370: Commands for scanner devices (not previously listed)
1473 GET DATA BUFFER STATUS 34
1477 SET WINDOW 24 DATA OUT
1479 p. 391: Commands for optical memory devices (not listed)
1482 MEDIUM SCAN 38 DATA OUT
1483 READ DEFECT DATA (12) b7
1485 READ UPDATED BLOCK 2d
1486 UPDATE BLOCK 3d DATA OUT
1488 p. 419: Commands for medium changer devices (not listed)
1490 INITIALIZE ELEMENT STATUS 07
1492 POSITION TO ELEMENT 2b
1493 READ ELEMENT STATUS b8
1494 REQUEST VOL. ELEMENT ADDRESS b5
1495 SEND VOLUME TAG b6 DATA OUT
1497 p. 454: Commands for communications devices (not listed previously)
1503 switch (current_SC
->cmnd
[0]) {
1504 case CHANGE_DEFINITION
: case COMPARE
: case COPY
:
1505 case COPY_VERIFY
: case LOG_SELECT
: case MODE_SELECT
:
1506 case MODE_SELECT_10
: case SEND_DIAGNOSTIC
: case WRITE_BUFFER
:
1508 case FORMAT_UNIT
: case REASSIGN_BLOCKS
: case RESERVE
:
1509 case SEARCH_EQUAL
: case SEARCH_HIGH
: case SEARCH_LOW
:
1510 case WRITE_6
: case WRITE_10
: case WRITE_VERIFY
:
1511 case 0x3f: case 0x41:
1513 case 0xb1: case 0xb0: case 0xb2:
1514 case 0xaa: case 0xae:
1518 case 0x38: case 0x3d:
1522 case 0xea: /* alternate number for WRITE LONG */
1524 current_SC
->SCp
.have_data_in
= -1;
1525 outb( 0xd0 | PARITY_MASK
, TMC_Cntl_port
);
1531 current_SC
->SCp
.have_data_in
= 1;
1532 outb( 0x90 | PARITY_MASK
, TMC_Cntl_port
);
1537 if (current_SC
->SCp
.have_data_in
== -1) { /* DATA OUT */
1538 while ( (data_count
= FIFO_Size
- inw( FIFO_Data_Count_port
)) > 512 ) {
1540 printk( "DC=%d, ", data_count
) ;
1542 if (data_count
> current_SC
->SCp
.this_residual
)
1543 data_count
= current_SC
->SCp
.this_residual
;
1544 if (data_count
> 0) {
1546 printk( "%d OUT, ", data_count
);
1548 if (data_count
== 1) {
1549 outb( *current_SC
->SCp
.ptr
++, Write_FIFO_port
);
1550 --current_SC
->SCp
.this_residual
;
1553 outsw( Write_FIFO_port
, current_SC
->SCp
.ptr
, data_count
);
1554 current_SC
->SCp
.ptr
+= 2 * data_count
;
1555 current_SC
->SCp
.this_residual
-= 2 * data_count
;
1558 if (!current_SC
->SCp
.this_residual
) {
1559 if (current_SC
->SCp
.buffers_residual
) {
1560 --current_SC
->SCp
.buffers_residual
;
1561 ++current_SC
->SCp
.buffer
;
1562 current_SC
->SCp
.ptr
= current_SC
->SCp
.buffer
->address
;
1563 current_SC
->SCp
.this_residual
= current_SC
->SCp
.buffer
->length
;
1570 if (current_SC
->SCp
.have_data_in
== 1) { /* DATA IN */
1571 while ((data_count
= inw( FIFO_Data_Count_port
)) > 0) {
1573 printk( "DC=%d, ", data_count
);
1575 if (data_count
> current_SC
->SCp
.this_residual
)
1576 data_count
= current_SC
->SCp
.this_residual
;
1579 printk( "%d IN, ", data_count
);
1581 if (data_count
== 1) {
1582 *current_SC
->SCp
.ptr
++ = inb( Read_FIFO_port
);
1583 --current_SC
->SCp
.this_residual
;
1585 data_count
>>= 1; /* Number of words */
1586 insw( Read_FIFO_port
, current_SC
->SCp
.ptr
, data_count
);
1587 current_SC
->SCp
.ptr
+= 2 * data_count
;
1588 current_SC
->SCp
.this_residual
-= 2 * data_count
;
1591 if (!current_SC
->SCp
.this_residual
1592 && current_SC
->SCp
.buffers_residual
) {
1593 --current_SC
->SCp
.buffers_residual
;
1594 ++current_SC
->SCp
.buffer
;
1595 current_SC
->SCp
.ptr
= current_SC
->SCp
.buffer
->address
;
1596 current_SC
->SCp
.this_residual
= current_SC
->SCp
.buffer
->length
;
1603 printk( " ** IN DONE %d ** ", current_SC
->SCp
.have_data_in
);
1607 if (current_SC
->cmnd
[0] == REQUEST_SENSE
&& !current_SC
->SCp
.Status
) {
1608 if ((unsigned char)(*((char *)current_SC
->request_buffer
+2)) & 0x0f) {
1611 unsigned char qualifier
;
1613 key
= (unsigned char)(*((char *)current_SC
->request_buffer
+ 2))
1615 code
= (unsigned char)(*((char *)current_SC
->request_buffer
+ 12));
1616 qualifier
= (unsigned char)(*((char *)current_SC
->request_buffer
1619 if (key
!= UNIT_ATTENTION
1620 && !(key
== NOT_READY
1622 && (!qualifier
|| qualifier
== 0x02 || qualifier
== 0x01))
1623 && !(key
== ILLEGAL_REQUEST
&& (code
== 0x25
1627 printk( "scsi: <fdomain> REQUEST SENSE"
1628 " Key = %x, Code = %x, Qualifier = %x\n",
1629 key
, code
, qualifier
);
1634 printk( "BEFORE MY_DONE. . ." );
1636 spin_lock_irqsave(&io_request_lock
, flags
);
1637 my_done( (current_SC
->SCp
.Status
& 0xff)
1638 | ((current_SC
->SCp
.Message
& 0xff) << 8) | (DID_OK
<< 16) );
1639 spin_unlock_irqrestore(&io_request_lock
, flags
);
1641 printk( "RETURNING.\n" );
1645 if (current_SC
->SCp
.phase
& disconnect
) {
1646 outb( 0xd0 | FIFO_COUNT
, Interrupt_Cntl_port
);
1647 outb( 0x00, SCSI_Cntl_port
);
1649 outb( 0x90 | FIFO_COUNT
, Interrupt_Cntl_port
);
1653 in_interrupt_flag
= 0;
1658 int fdomain_16x0_queue( Scsi_Cmnd
* SCpnt
, void (*done
)(Scsi_Cmnd
*))
1661 panic( "scsi: <fdomain> fdomain_16x0_queue() NOT REENTRANT!\n" );
1664 printk( "queue: target = %d cmnd = 0x%02x pieces = %d size = %u\n",
1666 *(unsigned char *)SCpnt
->cmnd
,
1668 SCpnt
->request_bufflen
);
1671 fdomain_make_bus_idle();
1673 current_SC
= SCpnt
; /* Save this for the done function */
1674 current_SC
->scsi_done
= done
;
1676 /* Initialize static data */
1678 if (current_SC
->use_sg
) {
1679 current_SC
->SCp
.buffer
=
1680 (struct scatterlist
*)current_SC
->request_buffer
;
1681 current_SC
->SCp
.ptr
= current_SC
->SCp
.buffer
->address
;
1682 current_SC
->SCp
.this_residual
= current_SC
->SCp
.buffer
->length
;
1683 current_SC
->SCp
.buffers_residual
= current_SC
->use_sg
- 1;
1685 current_SC
->SCp
.ptr
= (char *)current_SC
->request_buffer
;
1686 current_SC
->SCp
.this_residual
= current_SC
->request_bufflen
;
1687 current_SC
->SCp
.buffer
= NULL
;
1688 current_SC
->SCp
.buffers_residual
= 0;
1692 current_SC
->SCp
.Status
= 0;
1693 current_SC
->SCp
.Message
= 0;
1694 current_SC
->SCp
.have_data_in
= 0;
1695 current_SC
->SCp
.sent_command
= 0;
1696 current_SC
->SCp
.phase
= in_arbitration
;
1698 /* Start arbitration */
1699 outb( 0x00, Interrupt_Cntl_port
);
1700 outb( 0x00, SCSI_Cntl_port
); /* Disable data drivers */
1701 outb( adapter_mask
, SCSI_Data_NoACK_port
); /* Set our id bit */
1703 outb( 0x20, Interrupt_Cntl_port
);
1704 outb( 0x14 | PARITY_MASK
, TMC_Cntl_port
); /* Start arbitration */
1709 /* The following code, which simulates the old-style command function, was
1710 taken from Tommy Thorn's aha1542.c file. This code is Copyright (C)
1711 1992 Tommy Thorn. */
1713 static volatile int internal_done_flag
= 0;
1714 static volatile int internal_done_errcode
= 0;
1716 static void internal_done( Scsi_Cmnd
*SCpnt
)
1718 internal_done_errcode
= SCpnt
->result
;
1719 ++internal_done_flag
;
1722 int fdomain_16x0_command( Scsi_Cmnd
*SCpnt
)
1724 fdomain_16x0_queue( SCpnt
, internal_done
);
1726 while (!internal_done_flag
)
1728 internal_done_flag
= 0;
1729 return internal_done_errcode
;
1732 /* End of code derived from Tommy Thorn's work. */
1734 void print_info( Scsi_Cmnd
*SCpnt
)
1740 if (!SCpnt
|| !SCpnt
->host
) {
1741 printk( "scsi: <fdomain> Cannot provide detailed information\n" );
1745 printk( "%s\n", fdomain_16x0_info( SCpnt
->host
) );
1746 print_banner( SCpnt
->host
);
1747 switch (SCpnt
->SCp
.phase
) {
1748 case in_arbitration
: printk( "arbitration " ); break;
1749 case in_selection
: printk( "selection " ); break;
1750 case in_other
: printk( "other " ); break;
1751 default: printk( "unknown " ); break;
1754 printk( "(%d), target = %d cmnd = 0x%02x pieces = %d size = %u\n",
1757 *(unsigned char *)SCpnt
->cmnd
,
1759 SCpnt
->request_bufflen
);
1760 printk( "sent_command = %d, have_data_in = %d, timeout = %d\n",
1761 SCpnt
->SCp
.sent_command
,
1762 SCpnt
->SCp
.have_data_in
,
1765 printk( "in_interrupt_flag = %d\n", in_interrupt_flag
);
1768 imr
= (inb( 0x0a1 ) << 8) + inb( 0x21 );
1770 irr
= inb( 0xa0 ) << 8;
1774 isr
= inb( 0xa0 ) << 8;
1778 /* Print out interesting information */
1779 printk( "IMR = 0x%04x", imr
);
1780 if (imr
& (1 << interrupt_level
))
1781 printk( " (masked)" );
1782 printk( ", IRR = 0x%04x, ISR = 0x%04x\n", irr
, isr
);
1784 printk( "SCSI Status = 0x%02x\n", inb( SCSI_Status_port
) );
1785 printk( "TMC Status = 0x%02x", inb( TMC_Status_port
) );
1786 if (inb( TMC_Status_port
& 1))
1787 printk( " (interrupt)" );
1789 printk( "Interrupt Status = 0x%02x", inb( Interrupt_Status_port
) );
1790 if (inb( Interrupt_Status_port
) & 0x08)
1791 printk( " (enabled)" );
1793 if (chip
== tmc18c50
|| chip
== tmc18c30
) {
1794 printk( "FIFO Status = 0x%02x\n", inb( port_base
+ FIFO_Status
) );
1795 printk( "Int. Condition = 0x%02x\n",
1796 inb( port_base
+ Interrupt_Cond
) );
1798 printk( "Configuration 1 = 0x%02x\n", inb( port_base
+ Configuration1
) );
1799 if (chip
== tmc18c50
|| chip
== tmc18c30
)
1800 printk( "Configuration 2 = 0x%02x\n",
1801 inb( port_base
+ Configuration2
) );
1804 int fdomain_16x0_abort( Scsi_Cmnd
*SCpnt
)
1806 unsigned long flags
;
1807 #if EVERY_ACCESS || ERRORS_ONLY || DEBUG_ABORT
1808 printk( "scsi: <fdomain> abort " );
1811 save_flags( flags
);
1814 #if EVERY_ACCESS || ERRORS_ONLY
1815 printk( " (not in command)\n" );
1817 restore_flags( flags
);
1818 return SCSI_ABORT_NOT_RUNNING
;
1819 } else printk( "\n" );
1822 print_info( SCpnt
);
1825 fdomain_make_bus_idle();
1827 current_SC
->SCp
.phase
|= aborted
;
1829 current_SC
->result
= DID_ABORT
<< 16;
1831 restore_flags( flags
);
1833 /* Aborts are not done well. . . */
1834 my_done( DID_ABORT
<< 16 );
1836 return SCSI_ABORT_SUCCESS
;
1839 int fdomain_16x0_reset( Scsi_Cmnd
*SCpnt
, unsigned int ignored
)
1842 static int called_once
= 0;
1846 if (SCpnt
) printk( "scsi: <fdomain> SCSI Bus Reset\n" );
1850 if (called_once
) print_info( current_SC
);
1854 outb( 1, SCSI_Cntl_port
);
1856 outb( 0, SCSI_Cntl_port
);
1858 outb( 0, SCSI_Mode_Cntl_port
);
1859 outb( PARITY_MASK
, TMC_Cntl_port
);
1861 /* Unless this is the very first call (i.e., SCPnt == NULL), everything
1862 is probably hosed at this point. We will, however, try to keep
1863 things going by informing the high-level code that we need help. */
1865 return SCSI_RESET_WAKEUP
;
1869 #include <scsi/scsi_ioctl.h>
1871 int fdomain_16x0_biosparam( Scsi_Disk
*disk
, kdev_t dev
, int *info_array
)
1874 unsigned char buf
[512 + sizeof (Scsi_Ioctl_Command
)];
1875 Scsi_Ioctl_Command
*sic
= (Scsi_Ioctl_Command
*) buf
;
1876 int size
= disk
->capacity
;
1877 unsigned char *data
= sic
->data
;
1878 unsigned char do_read
[] = { READ_6
, 0, 0, 0, 1, 0 };
1880 unsigned long offset
;
1882 unsigned short cylinders
;
1883 unsigned char heads
;
1884 unsigned char sectors
;
1888 The RAM area starts at 0x1f00 from the bios_base address.
1890 For BIOS Version 2.0:
1892 The drive parameter table seems to start at 0x1f30.
1893 The first byte's purpose is not known.
1894 Next is the cylinder, head, and sector information.
1895 The last 4 bytes appear to be the drive's size in sectors.
1896 The other bytes in the drive parameter table are unknown.
1897 If anyone figures them out, please send me mail, and I will
1900 Tape drives do not get placed in this table.
1902 There is another table at 0x1fea:
1903 If the byte is 0x01, then the SCSI ID is not in use.
1904 If the byte is 0x18 or 0x48, then the SCSI ID is in use,
1905 although tapes don't seem to be in this table. I haven't
1906 seen any other numbers (in a limited sample).
1908 0x1f2d is a drive count (i.e., not including tapes)
1910 The table at 0x1fcc are I/O ports addresses for the various
1911 operations. I calculate these by hand in this driver code.
1915 For the ISA-200S version of BIOS Version 2.0:
1917 The drive parameter table starts at 0x1f33.
1919 WARNING: Assume that the table entry is 25 bytes long. Someone needs
1920 to check this for the Quantum ISA-200S card.
1924 For BIOS Version 3.2:
1926 The drive parameter table starts at 0x1f70. Each entry is
1927 0x0a bytes long. Heads are one less than we need to report.
1930 if (MAJOR(dev
) != SCSI_DISK0_MAJOR
) {
1931 printk("scsi: <fdomain> fdomain_16x0_biosparam: too many disks");
1934 drive
= MINOR(dev
) >> 4;
1936 if (bios_major
== 2) {
1938 case 2: /* ISA_200S */
1939 /* The value of 25 has never been verified.
1940 It should probably be 15. */
1941 offset
= bios_base
+ 0x1f33 + drive
* 25;
1943 case 3: /* ISA_250MG */
1944 offset
= bios_base
+ 0x1f36 + drive
* 15;
1946 case 4: /* ISA_200S (another one) */
1947 offset
= bios_base
+ 0x1f34 + drive
* 15;
1950 offset
= bios_base
+ 0x1f31 + drive
* 25;
1953 memcpy_fromio( &i
, offset
, sizeof( struct drive_info
) );
1954 info_array
[0] = i
.heads
;
1955 info_array
[1] = i
.sectors
;
1956 info_array
[2] = i
.cylinders
;
1957 } else if (bios_major
== 3
1959 && bios_minor
< 4) { /* 3.0 and 3.2 BIOS */
1960 memcpy_fromio( &i
, bios_base
+ 0x1f71 + drive
* 10,
1961 sizeof( struct drive_info
) );
1962 info_array
[0] = i
.heads
+ 1;
1963 info_array
[1] = i
.sectors
;
1964 info_array
[2] = i
.cylinders
;
1965 } else { /* 3.4 BIOS (and up?) */
1966 /* This algorithm was provided by Future Domain (much thanks!). */
1968 sic
->inlen
= 0; /* zero bytes out */
1969 sic
->outlen
= 512; /* one sector in */
1970 memcpy( data
, do_read
, sizeof( do_read
) );
1971 retcode
= kernel_scsi_ioctl( disk
->device
,
1972 SCSI_IOCTL_SEND_COMMAND
,
1974 if (!retcode
/* SCSI command ok */
1975 && data
[511] == 0xaa && data
[510] == 0x55 /* Partition table valid */
1976 && data
[0x1c2]) { /* Partition type */
1978 /* The partition table layout is as follows:
1981 Offset: 0 = partition status
1983 2 = starting sector and cylinder (word, encoded)
1986 6 = ending sector and cylinder (word, encoded)
1987 8 = starting absolute sector (double word)
1988 c = number of sectors (double word)
1989 Signature: 0x1fe = 0x55aa
1991 So, this algorithm assumes:
1992 1) the first partition table is in use,
1993 2) the data in the first entry is correct, and
1994 3) partitions never divide cylinders
1996 Note that (1) may be FALSE for NetBSD (and other BSD flavors),
1997 as well as for Linux. Note also, that Linux doesn't pay any
1998 attention to the fields that are used by this algorithm -- it
1999 only uses the absolute sector data. Recent versions of Linux's
2000 fdisk(1) will fill this data in correctly, and forthcoming
2001 versions will check for consistency.
2003 Checking for a non-zero partition type is not part of the
2004 Future Domain algorithm, but it seemed to be a reasonable thing
2005 to do, especially in the Linux and BSD worlds. */
2007 info_array
[0] = data
[0x1c3] + 1; /* heads */
2008 info_array
[1] = data
[0x1c4] & 0x3f; /* sectors */
2011 /* Note that this new method guarantees that there will always be
2012 less than 1024 cylinders on a platter. This is good for drives
2013 up to approximately 7.85GB (where 1GB = 1024 * 1024 kB). */
2015 if ((unsigned int)size
>= 0x7e0000U
) {
2016 info_array
[0] = 0xff; /* heads = 255 */
2017 info_array
[1] = 0x3f; /* sectors = 63 */
2018 } else if ((unsigned int)size
>= 0x200000U
) {
2019 info_array
[0] = 0x80; /* heads = 128 */
2020 info_array
[1] = 0x3f; /* sectors = 63 */
2022 info_array
[0] = 0x40; /* heads = 64 */
2023 info_array
[1] = 0x20; /* sectors = 32 */
2026 /* For both methods, compute the cylinders */
2027 info_array
[2] = (unsigned int)size
/ (info_array
[0] * info_array
[1] );
2034 /* Eventually this will go into an include file, but this will be later */
2035 Scsi_Host_Template driver_template
= FDOMAIN_16X0
;
2037 #include "scsi_module.c"