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: Thu Oct 12 15:59:37 1995 by r.faith@ieee.org 4 * Author: Rickard E. Faith, faith@cs.unc.edu 5 * Copyright 1992, 1993, 1994, 1995 Rickard E. Faith 6 * 7 * $Id: fdomain.c,v 5.39 1995/10/12 20:31:47 root Exp $ 8
9 * This program is free software; you can redistribute it and/or modify it 10 * under the terms of the GNU General Public License as published by the 11 * Free Software Foundation; either version 2, or (at your option) any 12 * later version. 13
14 * This program is distributed in the hope that it will be useful, but 15 * WITHOUT ANY WARRANTY; without even the implied warranty of 16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 17 * General Public License for more details. 18
19 * You should have received a copy of the GNU General Public License along 20 * with this program; if not, write to the Free Software Foundation, Inc., 21 * 675 Mass Ave, Cambridge, MA 02139, USA. 22
23 ************************************************************************** 24 25 DESCRIPTION: 26
27 This is the Linux low-level SCSI driver for Future Domain TMC-1660/1680 28 TMC-1650/1670, and TMC-3260 SCSI host adapters. The 1650 and 1670 have a 29 25-pin external connector, whereas the 1660 and 1680 have a SCSI-2 50-pin 30 high-density external connector. The 1670 and 1680 have floppy disk 31 controllers built in. The TMC-3260 is a PCI bus card. 32
33 Future Domain's older boards are based on the TMC-1800 chip, and this 34 driver was originally written for a TMC-1680 board with the TMC-1800 chip. 35 More recently, boards are being produced with the TMC-18C50 and TMC-18C30 36 chips. The latest and greatest board may not work with this driver. If 37 you have to patch this driver so that it will recognize your board's BIOS 38 signature, then the driver may fail to function after the board is 39 detected. 40
41 The following BIOS versions are supported: 2.0, 3.0, 3.2, 3.4, and 3.5. 42 The following chips are supported: TMC-1800, TMC-18C50, TMC-18C30. 43 Reports suggest that the driver will also work with the 36C70 chip and 44 with the Quantum ISA-200S and ISA-250MG SCSI adapters. 45
46 Please note that the drive ordering that Future Domain implemented in BIOS 47 versions 3.4 and 3.5 is the opposite of the order (currently) used by the 48 rest of the SCSI industry. If you have BIOS version 3.4 or 3.5, and have 49 more then one drive, then the drive ordering will be the reverse of that 50 which you see under DOS. For example, under DOS SCSI ID 0 will be D: and 51 SCSI ID 1 will be C: (the boot device). Under Linux, SCSI ID 0 will be 52 /dev/sda and SCSI ID 1 will be /dev/sdb. The Linux ordering is consistent 53 with that provided by all the other SCSI drivers for Linux. If you want 54 this changed, send me patches that are protected by #ifdefs. 55
56 If you have a TMC-8xx or TMC-9xx board, then this is not the driver for 57 your board. Please refer to the Seagate driver for more information and 58 possible support. 59
60 61
62 REFERENCES USED: 63
64 "TMC-1800 SCSI Chip Specification (FDC-1800T)", Future Domain Corporation, 65 1990. 66
67 "Technical Reference Manual: 18C50 SCSI Host Adapter Chip", Future Domain 68 Corporation, January 1992. 69
70 "LXT SCSI Products: Specifications and OEM Technical Manual (Revision 71 B/September 1991)", Maxtor Corporation, 1991. 72
73 "7213S product Manual (Revision P3)", Maxtor Corporation, 1992. 74
75 "Draft Proposed American National Standard: Small Computer System 76 Interface - 2 (SCSI-2)", Global Engineering Documents. (X3T9.2/86-109, 77 revision 10h, October 17, 1991) 78
79 Private communications, Drew Eckhardt (drew@cs.colorado.edu) and Eric 80 Youngdale (ericy@cais.com), 1992. 81
82 Private communication, Tuong Le (Future Domain Engineering department), 83 1994. (Disk geometry computations for Future Domain BIOS version 3.4, and 84 TMC-18C30 detection.) 85
86 Hogan, Thom. The Programmer's PC Sourcebook. Microsoft Press, 1988. Page 87 60 (2.39: Disk Partition Table Layout). 88
89 "18C30 Technical Reference Manual", Future Domain Corporation, 1993, page 90 6-1. 91
92
93 94 NOTES ON REFERENCES: 95
96 The Maxtor manuals were free. Maxtor telephone technical support is 97 great! 98
99 The Future Domain manuals were $25 and $35. They document the chip, not 100 the TMC-16x0 boards, so some information I had to guess at. In 1992, 101 Future Domain sold DOS BIOS source for $250 and the UN*X driver source was 102 $750, but these required a non-disclosure agreement, so even if I could 103 have afforded them, they would *not* have been useful for writing this 104 publically distributable driver. Future Domain technical support has 105 provided some information on the phone and have sent a few useful FAXs. 106 They have been much more helpful since they started to recognize that the 107 word "Linux" refers to an operating system :-). 108
109 110
111 ALPHA TESTERS: 112
113 There are many other alpha testers that come and go as the driver 114 develops. The people listed here were most helpful in times of greatest 115 need (mostly early on -- I've probably left out a few worthy people in 116 more recent times): 117
118 Todd Carrico (todd@wutc.wustl.edu), Dan Poirier (poirier@cs.unc.edu ), Ken 119 Corey (kenc@sol.acs.unt.edu), C. de Bruin (bruin@bruin@sterbbs.nl), Sakari 120 Aaltonen (sakaria@vipunen.hit.fi), John Rice (rice@xanth.cs.odu.edu), Brad 121 Yearwood (brad@optilink.com), and Ray Toy (toy@soho.crd.ge.com). 122
123 Special thanks to Tien-Wan Yang (twyang@cs.uh.edu), who graciously lent me 124 his 18C50-based card for debugging. He is the sole reason that this 125 driver works with the 18C50 chip. 126
127 Thanks to Dave Newman (dnewman@crl.com) for providing initial patches for 128 the version 3.4 BIOS. 129
130 Thanks to James T. McKinley (mckinley@msupa.pa.msu.edu) for providing 131 patches that support the TMC-3260, a PCI bus card with the 36C70 chip. 132 The 36C70 chip appears to be "completely compatible" with the 18C30 chip. 133
134 Thanks to Eric Kasten (tigger@petroglyph.cl.msu.edu) for providing the 135 patch for the version 3.5 BIOS. 136
137 Thanks for Stephen Henson (shenson@nyx10.cs.du.edu) for providing the 138 patch for the Quantum ISA-200S SCSI adapter. 139 140 Thanks to Adam Bowen for the signature to the 1610M/MER/MEX scsi cards, to 141 Martin Andrews (andrewm@ccfadm.eeg.ccf.org) for the signature to some 142 random TMC-1680 repackaged by IBM; and to Mintak Ng (mintak@panix.com) for 143 the version 3.61 BIOS siganture. 144
145 Thanks for Mark Singer (elf@netcom.com) and Richard Simpson 146 (rsimpson@ewrcsdra.demon.co.uk) for more Quantum signatures and detective 147 work on the Quantum RAM layout. 148
149 Special thanks to James T. McKinley (mckinley@msupa.pa.msu.edu) for 150 providing patches for proper PCI BIOS32-mediated detection of the TMC-3260 151 card (a PCI bus card with the 36C70 chip). Please send James PCI-related 152 bug reports. 153
154 Thanks to Tom Cavin (tec@usa1.com) for preliminary command-line option 155 patches. 156 157 All of the alpha testers deserve much thanks. 158
159
160
161 NOTES ON USER DEFINABLE OPTIONS: 162
163 DEBUG: This turns on the printing of various debug information. 164
165 ENABLE_PARITY: This turns on SCSI parity checking. With the current 166 driver, all attached devices must support SCSI parity. If none of your 167 devices support parity, then you can probably get the driver to work by 168 turning this option off. I have no way of testing this, however. 169
170 FIFO_COUNT: The host adapter has an 8K cache (host adapters based on the 171 18C30 chip have a 2k cache). When this many 512 byte blocks are filled by 172 the SCSI device, an interrupt will be raised. Therefore, this could be as 173 low as 0, or as high as 16. Note, however, that values which are too high 174 or too low seem to prevent any interrupts from occurring, and thereby lock 175 up the machine. I have found that 2 is a good number, but throughput may 176 be increased by changing this value to values which are close to 2. 177 Please let me know if you try any different values. 178
179 DO_DETECT: This activates some old scan code which was needed before the 180 high level drivers got fixed. If you are having trouble with the driver, 181 turning this on should not hurt, and might help. Please let me know if 182 this is the case, since this code will be removed from future drivers. 183
184 RESELECTION: This is no longer an option, since I gave up trying to 185 implement it in version 4.x of this driver. It did not improve 186 performance at all and made the driver unstable (because I never found one 187 of the two race conditions which were introduced by the multiple 188 outstanding command code). The instability seems a very high price to pay 189 just so that you don't have to wait for the tape to rewind. If you want 190 this feature implemented, send me patches. I'll be happy to send a copy 191 of my (broken) driver to anyone who would like to see a copy. 192
193 **************************************************************************/ 194
195 #ifdefMODULE 196 #include <linux/module.h>
197 #endif 198
199 #include <linux/sched.h>
200 #include <asm/io.h>
201 #include <linux/blk.h>
202 #include "scsi.h"
203 #include "hosts.h"
204 #include "fdomain.h"
205 #include <asm/system.h>
206 #include <linux/errno.h>
207 #include <linux/string.h>
208 #include <linux/ioport.h>
209 #include <linux/proc_fs.h>
210 #include <linux/bios32.h>
211 #include <linux/pci.h>
212 #include <linux/stat.h>
213
214 #include <linux/config.h> /* for CONFIG_PCI */ 215
216 structproc_dir_entryproc_scsi_fdomain = { 217 PROC_SCSI_FDOMAIN, 7, "fdomain",
218 S_IFDIR | S_IRUGO | S_IXUGO, 2
219 };
220
221 #defineVERSION "$Revision: 5.39 $"
222
223 /* START OF USER DEFINABLE OPTIONS */ 224
225 #defineDEBUG 1 /* Enable debugging output */ 226 #defineENABLE_PARITY 1 /* Enable SCSI Parity */ 227 #defineFIFO_COUNT 2 /* Number of 512 byte blocks before INTR */ 228 #defineDO_DETECT 0 /* Do device detection here (see scsi.c) */ 229
230 /* END OF USER DEFINABLE OPTIONS */ 231
232 #ifDEBUG 233 #defineEVERY_ACCESS 0 /* Write a line on every scsi access */ 234 #defineERRORS_ONLY 1 /* Only write a line if there is an error */ 235 #defineDEBUG_DETECT 0 /* Debug fdomain_16x0_detect() */ 236 #defineDEBUG_MESSAGES 1 /* Debug MESSAGE IN phase */ 237 #defineDEBUG_ABORT 1 /* Debug abort() routine */ 238 #defineDEBUG_RESET 1 /* Debug reset() routine */ 239 #defineDEBUG_RACE 1 /* Debug interrupt-driven race condition */ 240 #else 241 #defineEVERY_ACCESS 0 /* LEAVE THESE ALONE--CHANGE THE ONES ABOVE */ 242 #defineERRORS_ONLY 0
243 #defineDEBUG_DETECT 0
244 #defineDEBUG_MESSAGES 0
245 #defineDEBUG_ABORT 0
246 #defineDEBUG_RESET 0
247 #defineDEBUG_RACE 0
248 #endif 249
250 /* Errors are reported on the line, so we don't need to report them again */ 251 #ifEVERY_ACCESS 252 #undefERRORS_ONLY 253 #defineERRORS_ONLY 0
254 #endif 255
256 #ifENABLE_PARITY 257 #definePARITY_MASK 0x08
258 #else 259 #definePARITY_MASK 0x00
260 #endif 261
262 enumchip_type{ 263 unknown = 0x00,
264 tmc1800 = 0x01,
265 tmc18c50 = 0x02,
266 tmc18c30 = 0x03,
267 };
268
269 enum{ 270 in_arbitration = 0x02,
271 in_selection = 0x04,
272 in_other = 0x08,
273 disconnect = 0x10,
274 aborted = 0x20,
275 sent_ident = 0x40,
276 };
277
278 enum in_port_type { 279 Read_SCSI_Data = 0,
280 SCSI_Status = 1,
281 TMC_Status = 2,
282 FIFO_Status = 3, /* tmc18c50/tmc18c30 only */ 283 Interrupt_Cond = 4, /* tmc18c50/tmc18c30 only */ 284 LSB_ID_Code = 5,
285 MSB_ID_Code = 6,
286 Read_Loopback = 7,
287 SCSI_Data_NoACK = 8,
288 Interrupt_Status = 9,
289 Configuration1 = 10,
290 Configuration2 = 11, /* tmc18c50/tmc18c30 only */ 291 Read_FIFO = 12,
292 FIFO_Data_Count = 14
293 };
294
295 enum out_port_type { 296 Write_SCSI_Data = 0,
297 SCSI_Cntl = 1,
298 Interrupt_Cntl = 2,
299 SCSI_Mode_Cntl = 3,
300 TMC_Cntl = 4,
301 Memory_Cntl = 5, /* tmc18c50/tmc18c30 only */ 302 Write_Loopback = 7,
303 IO_Control = 11, /* tmc18c30 only */ 304 Write_FIFO = 12
305 };
306
307 staticintport_base = 0;
308 staticvoid *bios_base = NULL;
309 staticintbios_major = 0;
310 staticintbios_minor = 0;
311 staticintPCI_bus = 0;
312 staticintQuantum = 0; /* Quantum board variant */ 313 staticintinterrupt_level = 0;
314 staticvolatileintin_command = 0;
315 staticScsi_Cmnd *current_SC = NULL;
316 staticenumchip_typechip = unknown;
317 staticintadapter_mask = 0;
318 staticintthis_id = 0;
319 staticintsetup_called = 0;
320
321 #ifDEBUG_RACE 322 staticvolatileintin_interrupt_flag = 0;
323 #endif 324
325 staticintSCSI_Mode_Cntl_port;
326 staticintFIFO_Data_Count_port;
327 staticintInterrupt_Cntl_port;
328 staticintInterrupt_Status_port;
329 staticintRead_FIFO_port;
330 staticintRead_SCSI_Data_port;
331 staticintSCSI_Cntl_port;
332 staticintSCSI_Data_NoACK_port;
333 staticintSCSI_Status_port;
334 staticintTMC_Cntl_port;
335 staticintTMC_Status_port;
336 staticintWrite_FIFO_port;
337 staticintWrite_SCSI_Data_port;
338
339 staticintFIFO_Size = 0x2000; /* 8k FIFO for 340 pre-tmc18c30 chips */ 341
342 externvoidfdomain_16x0_intr( intirq, void *dev_id, structpt_regs * regs );
343
344 staticvoid *addresses[] = { 345 (void *)0xc8000,
346 (void *)0xca000,
347 (void *)0xce000,
348 (void *)0xde000,
349 (void *)0xd0000, /* Extra addresses for PCI boards */ 350 (void *)0xe0000,
351 };
352 #defineADDRESS_COUNT (sizeof( addresses ) / sizeof( unsigned ))
353
354 staticunsignedshortports[] = { 0x140, 0x150, 0x160, 0x170 };
355 #definePORT_COUNT (sizeof( ports ) / sizeof( unsignedshort ))
356
357 staticunsignedshortints[] = { 3, 5, 10, 11, 12, 14, 15, 0 };
358
359 /* 360
361 READ THIS BEFORE YOU ADD A SIGNATURE! 362
363 READING THIS SHORT NOTE CAN SAVE YOU LOTS OF TIME! 364
365 READ EVERY WORD, ESPECIALLY THE WORD *NOT* 366
367 This driver works *ONLY* for Future Domain cards using the TMC-1800, 368 TMC-18C50, or TMC-18C30 chip. This includes models TMC-1650, 1660, 1670, 369 and 1680. 370
371 The following BIOS signature signatures are for boards which do *NOT* 372 work with this driver (these TMC-8xx and TMC-9xx boards may work with the 373 Seagate driver): 374
375 FUTURE DOMAIN CORP. (C) 1986-1988 V4.0I 03/16/88 376 FUTURE DOMAIN CORP. (C) 1986-1989 V5.0C2/14/89 377 FUTURE DOMAIN CORP. (C) 1986-1989 V6.0A7/28/89 378 FUTURE DOMAIN CORP. (C) 1986-1990 V6.0105/31/90 379 FUTURE DOMAIN CORP. (C) 1986-1990 V6.0209/18/90 380 FUTURE DOMAIN CORP. (C) 1986-1990 V7.009/18/90 381 FUTURE DOMAIN CORP. (C) 1992 V8.00.004/02/92 382
383 */ 384
385 structsignature{ 386 constchar *signature;
387 intsig_offset;
388 intsig_length;
389 intmajor_bios_version;
390 intminor_bios_version;
391 intflag; /* 1 == PCI_bus, 2 == ISA_200S, 3 == ISA_250MG, 4 == ISA_200S */ 392 }signatures[] = { 393 /* 1 2 3 4 5 6 */ 394 /* 123456789012345678901234567890123456789012345678901234567890 */ 395 { "FUTURE DOMAIN CORP. (C) 1986-1990 1800-V2.07/28/89", 5, 50, 2, 0, 0 },
396 { "FUTURE DOMAIN CORP. (C) 1986-1990 1800-V1.07/28/89", 5, 50, 2, 0, 0 },
397 { "FUTURE DOMAIN CORP. (C) 1986-1990 1800-V2.07/28/89", 72, 50, 2, 0, 2 },
398 { "FUTURE DOMAIN CORP. (C) 1986-1990 1800-V2.0", 73, 43, 2, 0, 3 },
399 { "FUTURE DOMAIN CORP. (C) 1991 1800-V2.0.", 72, 39, 2, 0, 4 },
400 { "FUTURE DOMAIN CORP. (C) 1992 V3.00.004/02/92", 5, 44, 3, 0, 0 },
401 { "FUTURE DOMAIN TMC-18XX (C) 1993 V3.203/12/93", 5, 44, 3, 2, 0 },
402 { "IBM F1 P2 BIOS v1.0104/29/93", 5, 28, 3, -1, 0 },
403 { "Future Domain Corp. V1.0008/18/93", 5, 33, 3, 4, 0 },
404 { "Future Domain Corp. V1.0008/18/93", 26, 33, 3, 4, 1 },
405 /* This next signature may not be a 3.5 bios */ 406 { "Future Domain Corp. V2.0108/18/93", 5, 33, 3, 5, 0 },
407 { "FUTURE DOMAIN CORP. V3.5008/18/93", 5, 34, 3, 5, 0 },
408 { "FUTURE DOMAIN 18c30/18c50/1800 (C) 1994 V3.5", 5, 44, 3, 5, 0 },
409 { "FUTURE DOMAIN CORP. V3.6008/18/93", 5, 34, 3, 6, 0 },
410 { "FUTURE DOMAIN CORP. V3.6108/18/93", 5, 34, 3, 6, 0 },
411 { "FUTURE DOMAIN TMC-18XX", 5, 22, -1, -1, 0 },
412
413 /* READ NOTICE ABOVE *BEFORE* YOU WASTE YOUR TIME ADDING A SIGNATURE 414 Also, fix the disk geometry code for your signature and send your 415 changes for faith@cs.unc.edu. Above all, do *NOT* change any old 416 signatures! 417
418 Note that the last line will match a "generic" 18XX bios. Because 419 Future Domain has changed the host SCSI ID and/or the location of the 420 geometry information in the on-board RAM area for each of the first 421 three BIOS's, it is still important to enter a fully qualified 422 signature in the table for any new BIOS's (after the host SCSI ID and 423 geometry location are verified). */ 424 };
425
426 #defineSIGNATURE_COUNT (sizeof( signatures ) / sizeof( structsignature ))
427
428 staticvoidprint_banner( structScsi_Host *shpnt )
429 { 430 if (!shpnt) return; /* This won't ever happen */ 431
432 if (bios_major < 0 && bios_minor < 0) { 433 printk( "scsi%d <fdomain>: No BIOS; using scsi id %d\n",
434 shpnt->host_no, shpnt->this_id );
435 }else{ 436 printk( "scsi%d <fdomain>: BIOS version ", shpnt->host_no );
437
438 if (bios_major >= 0) printk( "%d.", bios_major );
439 elseprintk( "?." );
440
441 if (bios_minor >= 0) printk( "%d", bios_minor );
442 elseprintk( "?." );
443
444 printk( " at 0x%x using scsi id %d\n",
445 (unsigned)bios_base, shpnt->this_id );
446 } 447
448 /* If this driver works for later FD PCI 449 boards, we will have to modify banner 450 for additional PCI cards, but for now if 451 it's PCI it's a TMC-3260 - JTM */ 452 printk( "scsi%d <fdomain>: %s chip at 0x%x irq ",
453 shpnt->host_no,
454 chip == tmc1800 ? "TMC-1800"
455 : (chip == tmc18c50 ? "TMC-18C50"
456 : (chip == tmc18c30 ?
457 (PCI_bus ? "TMC-36C70 (PCI bus)" : "TMC-18C30")
458 : "Unknown")),
459 port_base );
460
461 if (interrupt_level) printk( "%d", interrupt_level );
462 elseprintk( "<none>" );
463
464 printk( "\n" );
465 } 466
467 voidfdomain_setup( char *str, int *ints )
/* */ 468 { 469 if (setup_called++ || ints[0] < 2 || ints[0] > 3) { 470 printk( "fdomain: usage: fdomain=<PORT_BASE>,<IRQ>[,<ADAPTER_ID>]\n" );
471 printk( "fdomain: bad LILO parameters?\n" );
472 } 473
474 port_base = ints[0] >= 1 ? ints[1] : 0;
475 interrupt_level = ints[0] >= 2 ? ints[2] : 0;
476 this_id = ints[0] >= 3 ? ints[3] : 0;
477
478 bios_major = bios_minor = -1; /* Use geometry for BIOS version >= 3.4 */ 479 } 480
481
482 staticvoiddo_pause( unsignedamount ) /* Pause for amount*10 milliseconds *//* */ 483 { 484 unsignedlongthe_time = jiffies + amount; /* 0.01 seconds per jiffy */ 485
486 while (jiffies < the_time);
487 } 488
489 inlinestaticvoidfdomain_make_bus_idle( void )
/* */ 490 { 491 outb( 0, SCSI_Cntl_port );
492 outb( 0, SCSI_Mode_Cntl_port );
493 if (chip == tmc18c50 || chip == tmc18c30)
494 outb( 0x21 | PARITY_MASK, TMC_Cntl_port ); /* Clear forced intr. */ 495 else 496 outb( 0x01 | PARITY_MASK, TMC_Cntl_port );
497 } 498
499 staticintfdomain_is_valid_port( intport )
/* */ 500 { 501 #ifDEBUG_DETECT 502 printk( " (%x%x),",
503 inb( port + MSB_ID_Code ), inb( port + LSB_ID_Code ) );
504 #endif 505
506 /* The MCA ID is a unique id for each MCA compatible board. We 507 are using ISA boards, but Future Domain provides the MCA ID 508 anyway. We can use this ID to ensure that this is a Future 509 Domain TMC-1660/TMC-1680. 510 */ 511
512 if (inb( port + LSB_ID_Code ) != 0xe9) {/* test for 0x6127 id */ 513 if (inb( port + LSB_ID_Code ) != 0x27) return 0;
514 if (inb( port + MSB_ID_Code ) != 0x61) return 0;
515 chip = tmc1800;
516 }else{/* test for 0xe960 id */ 517 if (inb( port + MSB_ID_Code ) != 0x60) return 0;
518 chip = tmc18c50;
519
520 #if 0
521
522 /* Try to toggle 32-bit mode. This only 523 works on an 18c30 chip. (User reports 524 say that this doesn't work at all, so 525 we'll use the other method.) */ 526
527 outb( 0x80, port + IO_Control );
528 if ((inb( port + Configuration2 ) & 0x80) == 0x80) { 529 outb( 0x00, port + IO_Control );
530 if ((inb( port + Configuration2 ) & 0x80) == 0x00) { 531 chip = tmc18c30;
532 FIFO_Size = 0x800; /* 2k FIFO */ 533 } 534 } 535 #else 536
537 /* That should have worked, but appears to 538 have problems. Lets assume it is an 539 18c30 if the RAM is disabled. */ 540
541 if (inb( port + Configuration2 ) & 0x02) { 542 chip = tmc18c30;
543 FIFO_Size = 0x800; /* 2k FIFO */ 544 } 545 #endif 546 /* If that failed, we are an 18c50. */ 547 } 548
549 return 1;
550 } 551
552 staticintfdomain_test_loopback( void )
/* */ 553 { 554 inti;
555 intresult;
556
557 for (i = 0; i < 255; i++) { 558 outb( i, port_base + Write_Loopback );
559 result = inb( port_base + Read_Loopback );
560 if (i != result)
561 return 1;
562 } 563 return 0;
564 } 565
566 /* fdomain_get_irq assumes that we have a valid MCA ID for a 567 TMC-1660/TMC-1680 Future Domain board. Now, check to be sure the 568 bios_base matches these ports. If someone was unlucky enough to have 569 purchased more than one Future Domain board, then they will have to 570 modify this code, as we only detect one board here. [The one with the 571 lowest bios_base.] 572
573 Note that this routine is only used for systems without a PCI BIOS32 574 (e.g., ISA bus). For PCI bus systems, this routine will likely fail 575 unless one of the IRQs listed in the ints array is used by the board. 576 Sometimes it is possible to use the computer's BIOS setup screen to 577 configure a PCI system so that one of these IRQs will be used by the 578 Future Domain card. */ 579
580 staticintfdomain_get_irq( intbase )
/* */ 581 { 582 intoptions = inb( base + Configuration1 );
583
584 #ifDEBUG_DETECT 585 printk( " Options = %x\n", options );
586 #endif 587
588 /* Check for board with lowest bios_base -- 589 this isn't valid for the 18c30 or for 590 boards on the PCI bus, so just assume we 591 have the right board. */ 592
593 if (chip != tmc18c30 594 && !PCI_bus 595 && addresses[ (options & 0xc0) >> 6 ] != bios_base) return 0;
596
597 returnints[ (options & 0x0e) >> 1 ];
598 } 599
600 staticintfdomain_isa_detect( int *irq, int *iobase )
/* */ 601 { 602 inti;
603 intbase;
604 intflag = 0;
605
606 if (bios_major == 2) { 607 /* The TMC-1660/TMC-1680 has a RAM area just after the BIOS ROM. 608 Assuming the ROM is enabled (otherwise we wouldn't have been 609 able to read the ROM signature :-), then the ROM sets up the 610 RAM area with some magic numbers, such as a list of port 611 base addresses and a list of the disk "geometry" reported to 612 DOS (this geometry has nothing to do with physical geometry). 613 */ 614
615 switch (Quantum) { 616 case 2: /* ISA_200S */ 617 case 3: /* ISA_250MG */ 618 base = *((char *)bios_base + 0x1fa2)
619 + (*((char *)bios_base + 0x1fa3) << 8);
620 break;
621 case 4: /* ISA_200S (another one) */ 622 base = *((char *)bios_base + 0x1fa3)
623 + (*((char *)bios_base + 0x1fa4) << 8);
624 break;
625 default:
626 base = *((char *)bios_base + 0x1fcc)
627 + (*((char *)bios_base + 0x1fcd) << 8);
628 break;
629 } 630
631 #ifDEBUG_DETECT 632 printk( " %x,", base );
633 #endif 634
635 for (flag = 0, i = 0; !flag && i < PORT_COUNT; i++) { 636 if (base == ports[i])
637 ++flag;
638 } 639
640 if (flag && fdomain_is_valid_port( base )) { 641 *irq = fdomain_get_irq( base );
642 *iobase = base;
643 return 1;
644 } 645
646 /* This is a bad sign. It usually means that someone patched the 647 BIOS signature list (the signatures variable) to contain a BIOS 648 signature for a board *OTHER THAN* the TMC-1660/TMC-1680. */ 649
650 #ifDEBUG_DETECT 651 printk( " RAM FAILED, " );
652 #endif 653 } 654
655 /* Anyway, the alternative to finding the address in the RAM is to just 656 search through every possible port address for one that is attached 657 to the Future Domain card. Don't panic, though, about reading all 658 these random port addresses -- there are rumors that the Future 659 Domain BIOS does something very similar. 660
661 Do not, however, check ports which the kernel knows are being used by 662 another driver. */ 663
664 for (i = 0; i < PORT_COUNT; i++) { 665 base = ports[i];
666 if (check_region( base, 0x10 )) { 667 #ifDEBUG_DETECT 668 printk( " (%x inuse),", base );
669 #endif 670 continue;
671 } 672 #ifDEBUG_DETECT 673 printk( " %x,", base );
674 #endif 675 if ((flag = fdomain_is_valid_port( base ))) break;
676 } 677
678 if (!flag) return 0; /* iobase not found */ 679
680 *irq = fdomain_get_irq( base );
681 *iobase = base;
682
683 return 1; /* success */ 684 } 685
686 staticintfdomain_pci_nobios_detect( int *irq, int *iobase )
/* */ 687 { 688 inti;
689 intflag = 0;
690
691 /* The proper way of doing this is to use ask the PCI bus for the device 692 IRQ and interrupt level. But we can't do that if PCI BIOS32 support 693 isn't compiled into the kernel, or if a PCI BIOS32 isn't present. 694
695 Instead, we scan down a bunch of addresses (Future Domain tech 696 support says we will probably find the address before we get to 697 0xf800). This works fine on some systems -- other systems may have 698 to scan more addresses. If you have to modify this section for your 699 installation, please send mail to faith@cs.unc.edu. */ 700
701 for (i = 0xfff8; i > 0xe000; i -= 8) { 702 if (check_region( i, 0x10 )) { 703 #ifDEBUG_DETECT 704 printk( " (%x inuse)," , i );
705 #endif 706 continue;
707 } 708 if ((flag = fdomain_is_valid_port( i ))) break;
709 } 710
711 if (!flag) return 0; /* iobase not found */ 712
713 *irq = fdomain_get_irq( i );
714 *iobase = i;
715
716 return 1; /* success */ 717 } 718
719 /* PCI detection function: int fdomain_pci_bios_detect(int* irq, int* 720 iobase) This function gets the Interrupt Level and I/O base address from 721 the PCI configuration registers. The I/O base address is masked with 722 0xfff8 since on my card the address read from the PCI config registers 723 is off by one from the actual I/O base address necessary for accessing 724 the status and control registers on the card (PCI config register gives 725 0xf801, actual address is 0xf800). This is likely a bug in the FD 726 config code that writes to the PCI registers, however using a mask 727 should be safe since I think the scan done by the card to determine the 728 I/O base is done in increments of 8 (i.e., 0xf800, 0xf808, ...), at 729 least the old scan code we used to use to get the I/O base did... Also, 730 the device ID from the PCI config registers is 0x0 and should be 0x60e9 731 as it is in the status registers (offset 5 from I/O base). If this is 732 changed in future hardware/BIOS changes it will need to be fixed in this 733 detection function. Comments, bug reports, etc... on this function 734 should be sent to mckinley@msupa.pa.msu.edu - James T. McKinley. */ 735
736 #ifdefCONFIG_PCI 737 staticintfdomain_pci_bios_detect( int *irq, int *iobase )
/* */ 738 { 739 interror;
740 unsignedcharpci_bus, pci_dev_fn; /* PCI bus & device function */ 741 unsignedcharpci_irq; /* PCI interrupt line */ 742 unsignedintpci_base; /* PCI I/O base address */ 743 unsignedshortpci_vendor, pci_device; /* PCI vendor & device IDs */ 744
745 /* If the PCI BIOS doesn't exist, use the old-style detection routines. 746 Otherwise, get the I/O base address and interrupt from the PCI config 747 registers. */ 748
749 if (!pcibios_present()) returnfdomain_pci_nobios_detect( irq, iobase );
750
751 #ifDEBUG_DETECT 752 /* Tell how to print a list of the known PCI devices from bios32 and 753 list vendor and device IDs being used if in debug mode. */ 754
755 printk( "\nINFO: cat /proc/pci to see list of PCI devices from bios32\n" );
756 printk( "\nTMC-3260 detect:"
757 " Using PCI Vendor ID: 0x%x, PCI Device ID: 0x%x\n",
758 PCI_VENDOR_ID_FD,
759 PCI_DEVICE_ID_FD_36C70 );
760 #endif 761
762 /* We will have to change this if more than 1 PCI bus is present and the 763 FD scsi host is not on the first bus (i.e., a PCI to PCI bridge, 764 which is not supported by bios32 right now anyway). This should 765 probably be done by a call to pcibios_find_device but I can't get it 766 to work... Also the device ID reported from the PCI config registers 767 does not match the device ID quoted in the tech manual or available 768 from offset 5 from the I/O base address. It should be 0x60E9, but it 769 is 0x0 if read from the PCI config registers. I guess the FD folks 770 neglected to write it to the PCI registers... This loop is necessary 771 to get the device function (at least until someone can get 772 pcibios_find_device to work, I cannot but 53c7,8xx.c uses it...). */ 773
774 pci_bus = 0;
775
776 for (pci_dev_fn = 0x0; pci_dev_fn < 0xff; pci_dev_fn++) { 777 pcibios_read_config_word( pci_bus,
778 pci_dev_fn,
779 PCI_VENDOR_ID,
780 &pci_vendor );
781
782 if (pci_vendor == PCI_VENDOR_ID_FD) { 783 pcibios_read_config_word( pci_bus,
784 pci_dev_fn,
785 PCI_DEVICE_ID,
786 &pci_device );
787
788 if (pci_device == PCI_DEVICE_ID_FD_36C70) { 789 /* Break out once we have the correct device. If other FD 790 PCI devices are added to this driver we will need to add 791 an or of the other PCI_DEVICE_ID_FD_XXXXX's here. */ 792 break;
793 }else{ 794 /* If we can't find an FD scsi card we give up. */ 795 return 0;
796 } 797 } 798 } 799
800 #ifDEBUG_DETECT 801 printk( "Future Domain 36C70 : at PCI bus %u, device %u, function %u\n",
802 pci_bus,
803 (pci_dev_fn & 0xf8) >> 3,
804 pci_dev_fn & 7 );
805 #endif 806
807 /* We now have the appropriate device function for the FD board so we 808 just read the PCI config info from the registers. */ 809
810 if ((error = pcibios_read_config_dword( pci_bus,
811 pci_dev_fn,
812 PCI_BASE_ADDRESS_0,
813 &pci_base ))
814 || (error = pcibios_read_config_byte( pci_bus,
815 pci_dev_fn,
816 PCI_INTERRUPT_LINE,
817 &pci_irq ))) { 818 printk ( "PCI ERROR: Future Domain 36C70 not initializing"
819 " due to error reading configuration space\n" );
820 return 0;
821 }else{ 822 #ifDEBUG_DETECT 823 printk( "TMC-3260 PCI: IRQ = %u, I/O base = 0x%lx\n",
824 pci_irq, pci_base );
825 #endif 826
827 /* Now we have the I/O base address and interrupt from the PCI 828 configuration registers. Unfortunately it seems that the I/O base 829 address is off by one on my card so I mask it with 0xfff8. This 830 must be some kind of goof in the FD code that does the autoconfig 831 and writes to the PCI registers (or maybe I just don't understand 832 something). If they fix it in later versions of the card or BIOS 833 we may have to adjust the address based on the signature or 834 something... */ 835
836 *irq = pci_irq;
837 *iobase = (pci_base & 0xfff8);
838
839 #ifDEBUG_DETECT 840 printk( "TMC-3260 fix: Masking I/O base address with 0xff00.\n" );
841 printk( "TMC-3260: IRQ = %d, I/O base = 0x%x\n", *irq, *iobase );
842 #endif 843
844 if (!fdomain_is_valid_port( *iobase )) return 0;
845 return 1;
846 } 847 return 0;
848 } 849 #endif 850
851 intfdomain_16x0_detect( Scsi_Host_Template *tpnt )
/* */ 852 { 853 inti, j;
854 intretcode;
855 structScsi_Host *shpnt;
856 #ifDO_DETECT 857 constintbuflen = 255;
858 Scsi_CmndSCinit;
859 unsignedchardo_inquiry[] = {INQUIRY, 0, 0, 0, buflen, 0 };
860 unsignedchardo_request_sense[] = {REQUEST_SENSE, 0, 0, 0, buflen, 0 };
861 unsignedchardo_read_capacity[] = {READ_CAPACITY,
862 0, 0, 0, 0, 0, 0, 0, 0, 0 };
863 unsignedcharbuf[buflen];
864 #endif 865
866 #ifDEBUG_DETECT 867 printk( "fdomain_16x0_detect()," );
868 #endif 869 tpnt->proc_dir = &proc_scsi_fdomain;
870
871 if (setup_called) { 872 #ifDEBUG_DETECT 873 printk( "no BIOS, using port_base = 0x%x, irq = %d\n",
874 port_base, interrupt_level );
875 #endif 876 if (!fdomain_is_valid_port( port_base )) { 877 printk( "fdomain: cannot locate chip at port base 0x%x\n",
878 port_base );
879 printk( "fdomain: bad LILO parameters?\n" );
880 return 0;
881 } 882 }else{ 883 intflag = 0;
884
885 for (i = 0; !bios_base && i < ADDRESS_COUNT; i++) { 886 #ifDEBUG_DETECT 887 printk( " %x(%x),", (unsigned)addresses[i], (unsigned)bios_base );
888 #endif 889 for (j = 0; !bios_base && j < SIGNATURE_COUNT; j++) { 890 if (!memcmp( ((char *)addresses[i] + signatures[j].sig_offset),
891 signatures[j].signature, signatures[j].sig_length )) { 892 bios_major = signatures[j].major_bios_version;
893 bios_minor = signatures[j].minor_bios_version;
894 PCI_bus = (signatures[j].flag == 1);
895 Quantum = (signatures[j].flag > 1) ? signatures[j].flag : 0;
896 bios_base = addresses[i];
897 } 898 } 899 } 900
901 if (!bios_base) { 902 #ifDEBUG_DETECT 903 printk( " FAILED: NO BIOS\n" );
904 #endif 905 return 0;
906 } 907
908 if (!PCI_bus) { 909 flag = fdomain_isa_detect( &interrupt_level, &port_base );
910 }else{ 911 #ifdefCONFIG_PCI 912 flag = fdomain_pci_bios_detect( &interrupt_level, &port_base );
913 #else 914 flag = fdomain_pci_nobios_detect( &interrupt_level, &port_base );
915 #endif 916 } 917
918 if (!flag) { 919 #ifDEBUG_DETECT 920 printk( " FAILED: NO PORT\n" );
921 #endif 922 #ifdefCONFIG_PCI 923 printk( "\nTMC-3260 36C70 PCI scsi chip detection failed.\n" );
924 printk( "Send mail to mckinley@msupa.pa.msu.edu.\n" );
925 #endif 926 return 0; /* Cannot find valid set of ports */ 927 } 928 } 929
930 SCSI_Mode_Cntl_port = port_base + SCSI_Mode_Cntl;
931 FIFO_Data_Count_port = port_base + FIFO_Data_Count;
932 Interrupt_Cntl_port = port_base + Interrupt_Cntl;
933 Interrupt_Status_port = port_base + Interrupt_Status;
934 Read_FIFO_port = port_base + Read_FIFO;
935 Read_SCSI_Data_port = port_base + Read_SCSI_Data;
936 SCSI_Cntl_port = port_base + SCSI_Cntl;
937 SCSI_Data_NoACK_port = port_base + SCSI_Data_NoACK;
938 SCSI_Status_port = port_base + SCSI_Status;
939 TMC_Cntl_port = port_base + TMC_Cntl;
940 TMC_Status_port = port_base + TMC_Status;
941 Write_FIFO_port = port_base + Write_FIFO;
942 Write_SCSI_Data_port = port_base + Write_SCSI_Data;
943
944 fdomain_16x0_reset( NULL );
945
946 if (fdomain_test_loopback()) { 947 #ifDEBUG_DETECT 948 printk( "fdomain: LOOPBACK TEST FAILED, FAILING DETECT!\n" );
949 #endif 950 if (setup_called) { 951 printk( "fdomain: loopback test failed at port base 0x%x\n",
952 port_base );
953 printk( "fdomain: bad LILO parameters?\n" );
954 } 955 return 0;
956 } 957
958 if (this_id) { 959 tpnt->this_id = (this_id & 0x07);
960 adapter_mask = (1 << tpnt->this_id);
961 }else{ 962 if ((bios_major == 3 && bios_minor >= 2) || bios_major < 0) { 963 tpnt->this_id = 7;
964 adapter_mask = 0x80;
965 }else{ 966 tpnt->this_id = 6;
967 adapter_mask = 0x40;
968 } 969 } 970
971 /* Print out a banner here in case we can't 972 get resources. */ 973
974 shpnt = scsi_register( tpnt, 0 );
975 print_banner( shpnt );
976
977 /* Log IRQ with kernel */ 978 if (!interrupt_level) { 979 panic( "fdomain: *NO* interrupt level selected!\n" );
980 }else{ 981 /* Register the IRQ with the kernel */ 982
983 retcode = request_irq( interrupt_level,
984 fdomain_16x0_intr, SA_INTERRUPT, "fdomain", NULL);
985
986 if (retcode < 0) { 987 if (retcode == -EINVAL) { 988 printk( "fdomain: IRQ %d is bad!\n", interrupt_level );
989 printk( " This shouldn't happen!\n" );
990 printk( " Send mail to faith@cs.unc.edu\n" );
991 }elseif (retcode == -EBUSY) { 992 printk( "fdomain: IRQ %d is already in use!\n", interrupt_level );
993 printk( " Please use another IRQ!\n" );
994 }else{ 995 printk( "fdomain: Error getting IRQ %d\n", interrupt_level );
996 printk( " This shouldn't happen!\n" );
997 printk( " Send mail to faith@cs.unc.edu\n" );
998 } 999 panic( "fdomain: Driver requires interruptions\n" );
1000 }1001 }1002
1003 /* Log I/O ports with kernel */1004 request_region( port_base, 0x10, "fdomain" );
1005
1006 #ifDO_DETECT1007
1008 /* These routines are here because of the way the SCSI bus behaves after1009 a reset. This appropriate behavior was not handled correctly by the1010 higher level SCSI routines when I first wrote this driver. Now,1011 however, correct scan routines are part of scsi.c and these routines1012 are no longer needed. However, this code is still good for1013 debugging. */1014
1015 SCinit.request_buffer = SCinit.buffer = buf;
1016 SCinit.request_bufflen = SCinit.bufflen = sizeof(buf)-1;
1017 SCinit.use_sg = 0;
1018 SCinit.lun = 0;
1019
1020 printk( "fdomain: detection routine scanning for devices:\n" );
1021 for (i = 0; i < 8; i++) {1022 SCinit.target = i;
1023 if (i == tpnt->this_id) /* Skip host adapter */1024 continue;
1025 memcpy(SCinit.cmnd, do_request_sense, sizeof(do_request_sense));
1026 retcode = fdomain_16x0_command(&SCinit);
1027 if (!retcode) {1028 memcpy(SCinit.cmnd, do_inquiry, sizeof(do_inquiry));
1029 retcode = fdomain_16x0_command(&SCinit);
1030 if (!retcode) {1031 printk( " SCSI ID %d: ", i );
1032 for (j = 8; j < (buf[4] < 32 ? buf[4] : 32); j++)
1033 printk( "%c", buf[j] >= 20 ? buf[j] : ' ' );
1034 memcpy(SCinit.cmnd, do_read_capacity, sizeof(do_read_capacity));
1035 retcode = fdomain_16x0_command(&SCinit);
1036 if (!retcode) {1037 unsignedlongblocks, size, capacity;
1038
1039 blocks = (buf[0] << 24) | (buf[1] << 16)
1040 | (buf[2] << 8) | buf[3];
1041 size = (buf[4] << 24) | (buf[5] << 16) | (buf[6] << 8) | buf[7];
1042 capacity = +( +(blocks / 1024L) * +(size * 10L)) / 1024L;
1043
1044 printk( "%lu MB (%lu byte blocks)",
1045 ((capacity + 5L) / 10L), size );
1046 }else{1047 memcpy(SCinit.cmnd, do_request_sense, sizeof(do_request_sense));
1048 retcode = fdomain_16x0_command(&SCinit);
1049 }1050 printk ("\n" );
1051 }else{1052 memcpy(SCinit.cmnd, do_request_sense, sizeof(do_request_sense));
1053 retcode = fdomain_16x0_command(&SCinit);
1054 }1055 }1056 }1057 #endif1058
1059 return 1; /* Maximum of one adapter will be detected. */1060 }1061
1062 constchar *fdomain_16x0_info( structScsi_Host *ignore )
/* */1063 {1064 staticcharbuffer[80];
1065 char *pt;
1066
1067 strcpy( buffer, "Future Domain TMC-16x0 SCSI driver, version" );
1068 if (strchr( VERSION, ':')) {/* Assume VERSION is an RCS Revision string */1069 strcat( buffer, strchr( VERSION, ':' ) + 1 );
1070 pt = strrchr( buffer, '$') - 1;
1071 if (!pt) /* Stripped RCS Revision string? */1072 pt = buffer + strlen( buffer ) - 1;
1073 if (*pt != ' ')
1074 ++pt;
1075 *pt = '\0';
1076 }else{/* Assume VERSION is a number */1077 strcat( buffer, " " VERSION );
1078 }1079
1080 returnbuffer;
1081 }1082
1083 /* First pass at /proc information routine. */1084 /*1085 * inout : decides on the direction of the dataflow and the meaning of the 1086 * variables1087 * buffer: If inout==FALSE data is beeing written to it else read from it1088 * *start: If inout==FALSE start of the valid data in the buffer1089 * offset: If inout==FALSE offset from the beginning of the imaginary file 1090 * from which we start writing into the buffer1091 * length: If inout==FALSE max number of bytes to be written into the buffer 1092 * else number of bytes in the buffer1093 */1094 intfdomain_16x0_proc_info( char *buffer, char **start, off_toffset,
/* */1095 intlength, inthostno, intinout )
1096 {1097 constchar *info = fdomain_16x0_info( NULL );
1098 intlen;
1099 intpos;
1100 intbegin;
1101
1102 if (inout) return(-ENOSYS);
1103
1104 begin = 0;
1105 strcpy( buffer, info );
1106 strcat( buffer, "\n" );
1107
1108 pos = len = strlen( buffer );
1109
1110 if(pos < offset) {1111 len = 0;
1112 begin = pos;
1113 }1114
1115 *start = buffer + (offset - begin); /* Start of wanted data */1116 len -= (offset - begin);
1117 if(len > length) len = length;
1118
1119 return(len);
1120 }1121
1122 #if 0
1123 staticint fdomain_arbitrate( void )
/* */1124 {1125 intstatus = 0;
1126 unsignedlongtimeout;
1127
1128 #ifEVERY_ACCESS1129 printk( "fdomain_arbitrate()\n" );
1130 #endif1131
1132 outb( 0x00, SCSI_Cntl_port ); /* Disable data drivers */1133 outb( adapter_mask, port_base + SCSI_Data_NoACK ); /* Set our id bit */1134 outb( 0x04 | PARITY_MASK, TMC_Cntl_port ); /* Start arbitration */1135
1136 timeout = jiffies + 50; /* 500 mS */1137 while (jiffies < timeout) {1138 status = inb( TMC_Status_port ); /* Read adapter status */1139 if (status & 0x02) /* Arbitration complete */1140 return 0;
1141 }1142
1143 /* Make bus idle */1144 fdomain_make_bus_idle();
1145
1146 #ifEVERY_ACCESS1147 printk( "Arbitration failed, status = %x\n", status );
1148 #endif1149 #ifERRORS_ONLY1150 printk( "fdomain: Arbitration failed, status = %x\n", status );
1151 #endif1152 return 1;
1153 }1154 #endif1155
1156 staticintfdomain_select( inttarget )
/* */1157 {1158 intstatus;
1159 unsignedlongtimeout;
1160 staticintflag = 0;
1161
1162
1163 outb( 0x82, SCSI_Cntl_port ); /* Bus Enable + Select */1164 outb( adapter_mask | (1 << target), SCSI_Data_NoACK_port );
1165
1166 /* Stop arbitration and enable parity */1167 outb( PARITY_MASK, TMC_Cntl_port );
1168
1169 timeout = jiffies + 35; /* 350mS -- because of timeouts1170 (was 250mS) */1171
1172 while (jiffies < timeout) {1173 status = inb( SCSI_Status_port ); /* Read adapter status */1174 if (status & 1) {/* Busy asserted */1175 /* Enable SCSI Bus (on error, should make bus idle with 0) */1176 outb( 0x80, SCSI_Cntl_port );
1177 return 0;
1178 }1179 }1180 /* Make bus idle */1181 fdomain_make_bus_idle();
1182 #ifEVERY_ACCESS1183 if (!target) printk( "Selection failed\n" );
1184 #endif1185 #ifERRORS_ONLY1186 if (!target) {1187 if (chip == tmc18c30 && !flag) /* Skip first failure for 18C30 chips. */1188 ++flag;
1189 else1190 printk( "fdomain: Selection failed\n" );
1191 }1192 #endif1193 return 1;
1194 }1195
1196 voidmy_done( interror )
/* */1197 {1198 if (in_command) {1199 in_command = 0;
1200 outb( 0x00, Interrupt_Cntl_port );
1201 fdomain_make_bus_idle();
1202 current_SC->result = error;
1203 if (current_SC->scsi_done)
1204 current_SC->scsi_done( current_SC );
1205 elsepanic( "fdomain: current_SC->scsi_done() == NULL" );
1206 }else{1207 panic( "fdomain: my_done() called outside of command\n" );
1208 }1209 #ifDEBUG_RACE1210 in_interrupt_flag = 0;
1211 #endif1212 }1213
1214 voidfdomain_16x0_intr( intirq, void *dev_id, structpt_regs * regs )
/* */1215 {1216 intstatus;
1217 intdone = 0;
1218 unsigneddata_count;
1219
1220 /* The fdomain_16x0_intr is only called via1221 the interrupt handler. The goal of the1222 sti() here is to allow other1223 interruptions while this routine is1224 running. */1225
1226 sti(); /* Yes, we really want sti() here */1227
1228 outb( 0x00, Interrupt_Cntl_port );
1229
1230 /* We usually have one spurious interrupt after each command. Ignore it. */1231 if (!in_command || !current_SC) {/* Spurious interrupt */1232 #ifEVERY_ACCESS1233 printk( "Spurious interrupt, in_command = %d, current_SC = %x\n",
1234 in_command, current_SC );
1235 #endif1236 return;
1237 }1238
1239 /* Abort calls my_done, so we do nothing here. */1240 if (current_SC->SCp.phase & aborted) {1241 #ifDEBUG_ABORT1242 printk( "Interrupt after abort, ignoring\n" );
1243 #endif1244 /*1245 return; */1246 }1247
1248 #ifDEBUG_RACE1249 ++in_interrupt_flag;
1250 #endif1251
1252 if (current_SC->SCp.phase & in_arbitration) {1253 status = inb( TMC_Status_port ); /* Read adapter status */1254 if (!(status & 0x02)) {1255 #ifEVERY_ACCESS1256 printk( " AFAIL " );
1257 #endif1258 my_done( DID_BUS_BUSY << 16 );
1259 return;
1260 }1261 current_SC->SCp.phase = in_selection;
1262
1263 outb( 0x40 | FIFO_COUNT, Interrupt_Cntl_port );
1264
1265 outb( 0x82, SCSI_Cntl_port ); /* Bus Enable + Select */1266 outb( adapter_mask | (1 << current_SC->target), SCSI_Data_NoACK_port );
1267
1268 /* Stop arbitration and enable parity */1269 outb( 0x10 | PARITY_MASK, TMC_Cntl_port );
1270 #ifDEBUG_RACE1271 in_interrupt_flag = 0;
1272 #endif1273 return;
1274 }elseif (current_SC->SCp.phase & in_selection) {1275 status = inb( SCSI_Status_port );
1276 if (!(status & 0x01)) {1277 /* Try again, for slow devices */1278 if (fdomain_select( current_SC->target )) {1279 #ifEVERY_ACCESS1280 printk( " SFAIL " );
1281 #endif1282 my_done( DID_NO_CONNECT << 16 );
1283 return;
1284 }else{1285 #ifEVERY_ACCESS1286 printk( " AltSel " );
1287 #endif1288 /* Stop arbitration and enable parity */1289 outb( 0x10 | PARITY_MASK, TMC_Cntl_port );
1290 }1291 }1292 current_SC->SCp.phase = in_other;
1293 outb( 0x90 | FIFO_COUNT, Interrupt_Cntl_port );
1294 outb( 0x80, SCSI_Cntl_port );
1295 #ifDEBUG_RACE1296 in_interrupt_flag = 0;
1297 #endif1298 return;
1299 }1300
1301 /* current_SC->SCp.phase == in_other: this is the body of the routine */1302
1303 status = inb( SCSI_Status_port );
1304
1305 if (status & 0x10) {/* REQ */1306
1307 switch (status & 0x0e) {1308
1309 case 0x08: /* COMMAND OUT */1310 outb( current_SC->cmnd[current_SC->SCp.sent_command++],
1311 Write_SCSI_Data_port );
1312 #ifEVERY_ACCESS1313 printk( "CMD = %x,",
1314 current_SC->cmnd[ current_SC->SCp.sent_command - 1] );
1315 #endif1316 break;
1317 case 0x00: /* DATA OUT -- tmc18c50/tmc18c30 only */1318 if (chip != tmc1800 && !current_SC->SCp.have_data_in) {1319 current_SC->SCp.have_data_in = -1;
1320 outb( 0xd0 | PARITY_MASK, TMC_Cntl_port );
1321 }1322 break;
1323 case 0x04: /* DATA IN -- tmc18c50/tmc18c30 only */1324 if (chip != tmc1800 && !current_SC->SCp.have_data_in) {1325 current_SC->SCp.have_data_in = 1;
1326 outb( 0x90 | PARITY_MASK, TMC_Cntl_port );
1327 }1328 break;
1329 case 0x0c: /* STATUS IN */1330 current_SC->SCp.Status = inb( Read_SCSI_Data_port );
1331 #ifEVERY_ACCESS1332 printk( "Status = %x, ", current_SC->SCp.Status );
1333 #endif1334 #ifERRORS_ONLY1335 if (current_SC->SCp.Status && current_SC->SCp.Status != 2) {1336 printk( "fdomain: target = %d, command = %x, status = %x\n",
1337 current_SC->target,
1338 current_SC->cmnd[0],
1339 current_SC->SCp.Status );
1340 }1341 #endif1342 break;
1343 case 0x0a: /* MESSAGE OUT */1344 outb( MESSAGE_REJECT, Write_SCSI_Data_port ); /* Reject */1345 break;
1346 case 0x0e: /* MESSAGE IN */1347 current_SC->SCp.Message = inb( Read_SCSI_Data_port );
1348 #ifEVERY_ACCESS1349 printk( "Message = %x, ", current_SC->SCp.Message );
1350 #endif1351 if (!current_SC->SCp.Message) ++done;
1352 #ifDEBUG_MESSAGES || EVERY_ACCESS1353 if (current_SC->SCp.Message) {1354 printk( "fdomain: message = %x\n", current_SC->SCp.Message );
1355 }1356 #endif1357 break;
1358 }1359 }1360
1361 if (chip == tmc18001362 && !current_SC->SCp.have_data_in1363 && (current_SC->SCp.sent_command1364 >= current_SC->cmd_len)) {1365 /* We have to get the FIFO direction1366 correct, so I've made a table based1367 on the SCSI Standard of which commands1368 appear to require a DATA OUT phase.1369 */1370 /*1371 p. 94: Command for all device types1372 CHANGE DEFINITION 40 DATA OUT1373 COMPARE 39 DATA OUT1374 COPY 18 DATA OUT1375 COPY AND VERIFY 3a DATA OUT1376 INQUIRY 12 1377 LOG SELECT 4c DATA OUT1378 LOG SENSE 4d1379 MODE SELECT (6) 15 DATA OUT1380 MODE SELECT (10) 55 DATA OUT1381 MODE SENSE (6) 1a1382 MODE SENSE (10) 5a1383 READ BUFFER 3c1384 RECEIVE DIAGNOSTIC RESULTS 1c1385 REQUEST SENSE 031386 SEND DIAGNOSTIC 1d DATA OUT1387 TEST UNIT READY 001388 WRITE BUFFER 3b DATA OUT1389
1390 p.178: Commands for direct-access devices (not listed on p. 94)1391 FORMAT UNIT 04 DATA OUT1392 LOCK-UNLOCK CACHE 361393 PRE-FETCH 341394 PREVENT-ALLOW MEDIUM REMOVAL 1e1395 READ (6)/RECEIVE 081396 READ (10) 3c1397 READ CAPACITY 251398 READ DEFECT DATA (10) 371399 READ LONG 3e1400 REASSIGN BLOCKS 07 DATA OUT1401 RELEASE 171402 RESERVE 16 DATA OUT1403 REZERO UNIT/REWIND 011404 SEARCH DATA EQUAL (10) 31 DATA OUT1405 SEARCH DATA HIGH (10) 30 DATA OUT1406 SEARCH DATA LOW (10) 32 DATA OUT1407 SEEK (6) 0b1408 SEEK (10) 2b1409 SET LIMITS (10) 331410 START STOP UNIT 1b1411 SYNCHRONIZE CACHE 351412 VERIFY (10) 2f1413 WRITE (6)/PRINT/SEND 0a DATA OUT1414 WRITE (10)/SEND 2a DATA OUT1415 WRITE AND VERIFY (10) 2e DATA OUT1416 WRITE LONG 3f DATA OUT1417 WRITE SAME 41 DATA OUT ?1418
1419 p. 261: Commands for sequential-access devices (not previously listed)1420 ERASE 191421 LOAD UNLOAD 1b1422 LOCATE 2b1423 READ BLOCK LIMITS 051424 READ POSITION 341425 READ REVERSE 0f1426 RECOVER BUFFERED DATA 141427 SPACE 111428 WRITE FILEMARKS 10 ?1429
1430 p. 298: Commands for printer devices (not previously listed)1431 ****** NOT SUPPORTED BY THIS DRIVER, since 0b is SEEK (6) *****1432 SLEW AND PRINT 0b DATA OUT -- same as seek1433 STOP PRINT 1b1434 SYNCHRONIZE BUFFER 101435
1436 p. 315: Commands for processor devices (not previously listed)1437 1438 p. 321: Commands for write-once devices (not previously listed)1439 MEDIUM SCAN 381440 READ (12) a81441 SEARCH DATA EQUAL (12) b1 DATA OUT1442 SEARCH DATA HIGH (12) b0 DATA OUT1443 SEARCH DATA LOW (12) b2 DATA OUT1444 SET LIMITS (12) b31445 VERIFY (12) af1446 WRITE (12) aa DATA OUT1447 WRITE AND VERIFY (12) ae DATA OUT1448
1449 p. 332: Commands for CD-ROM devices (not previously listed)1450 PAUSE/RESUME 4b1451 PLAY AUDIO (10) 451452 PLAY AUDIO (12) a51453 PLAY AUDIO MSF 471454 PLAY TRACK RELATIVE (10) 491455 PLAY TRACK RELATIVE (12) a91456 READ HEADER 441457 READ SUB-CHANNEL 421458 READ TOC 431459
1460 p. 370: Commands for scanner devices (not previously listed)1461 GET DATA BUFFER STATUS 341462 GET WINDOW 251463 OBJECT POSITION 311464 SCAN 1b1465 SET WINDOW 24 DATA OUT1466
1467 p. 391: Commands for optical memory devices (not listed)1468 ERASE (10) 2c1469 ERASE (12) ac1470 MEDIUM SCAN 38 DATA OUT1471 READ DEFECT DATA (12) b71472 READ GENERATION 291473 READ UPDATED BLOCK 2d1474 UPDATE BLOCK 3d DATA OUT1475
1476 p. 419: Commands for medium changer devices (not listed)1477 EXCHANGE MEDIUM 461478 INITIALIZE ELEMENT STATUS 071479 MOVE MEDIUM a51480 POSITION TO ELEMENT 2b1481 READ ELEMENT STATUS b81482 REQUEST VOL. ELEMENT ADDRESS b51483 SEND VOLUME TAG b6 DATA OUT1484
1485 p. 454: Commands for communications devices (not listed previously)1486 GET MESSAGE (6) 081487 GET MESSAGE (10) 281488 GET MESSAGE (12) a81489 */1490
1491 switch (current_SC->cmnd[0]) {1492 caseCHANGE_DEFINITION: caseCOMPARE: caseCOPY:
1493 caseCOPY_VERIFY: caseLOG_SELECT: caseMODE_SELECT:
1494 caseMODE_SELECT_10: caseSEND_DIAGNOSTIC: caseWRITE_BUFFER:
1495
1496 caseFORMAT_UNIT: caseREASSIGN_BLOCKS: caseRESERVE:
1497 caseSEARCH_EQUAL: caseSEARCH_HIGH: caseSEARCH_LOW:
1498 caseWRITE_6: caseWRITE_10: caseWRITE_VERIFY:
1499 case 0x3f: case 0x41:
1500
1501 case 0xb1: case 0xb0: case 0xb2:
1502 case 0xaa: case 0xae:
1503
1504 case 0x24:
1505
1506 case 0x38: case 0x3d:
1507
1508 case 0xb6:
1509
1510 case 0xea: /* alternate number for WRITE LONG */1511
1512 current_SC->SCp.have_data_in = -1;
1513 outb( 0xd0 | PARITY_MASK, TMC_Cntl_port );
1514 break;
1515
1516 case 0x00:
1517 default:
1518
1519 current_SC->SCp.have_data_in = 1;
1520 outb( 0x90 | PARITY_MASK, TMC_Cntl_port );
1521 break;
1522 }1523 }1524
1525 if (current_SC->SCp.have_data_in == -1) {/* DATA OUT */1526 while ( (data_count = FIFO_Size - inw( FIFO_Data_Count_port )) > 512 ) {1527 #ifEVERY_ACCESS1528 printk( "DC=%d, ", data_count ) ;
1529 #endif1530 if (data_count > current_SC->SCp.this_residual)
1531 data_count = current_SC->SCp.this_residual;
1532 if (data_count > 0) {1533 #ifEVERY_ACCESS1534 printk( "%d OUT, ", data_count );
1535 #endif1536 if (data_count == 1) {1537 outb( *current_SC->SCp.ptr++, Write_FIFO_port );
1538 --current_SC->SCp.this_residual;
1539 }else{1540 data_count >>= 1;
1541 outsw( Write_FIFO_port, current_SC->SCp.ptr, data_count );
1542 current_SC->SCp.ptr += 2 * data_count;
1543 current_SC->SCp.this_residual -= 2 * data_count;
1544 }1545 }1546 if (!current_SC->SCp.this_residual) {1547 if (current_SC->SCp.buffers_residual) {1548 --current_SC->SCp.buffers_residual;
1549 ++current_SC->SCp.buffer;
1550 current_SC->SCp.ptr = current_SC->SCp.buffer->address;
1551 current_SC->SCp.this_residual = current_SC->SCp.buffer->length;
1552 }else1553 break;
1554 }1555 }1556 }1557
1558 if (current_SC->SCp.have_data_in == 1) {/* DATA IN */1559 while ((data_count = inw( FIFO_Data_Count_port )) > 0) {1560 #ifEVERY_ACCESS1561 printk( "DC=%d, ", data_count );
1562 #endif1563 if (data_count > current_SC->SCp.this_residual)
1564 data_count = current_SC->SCp.this_residual;
1565 if (data_count) {1566 #ifEVERY_ACCESS1567 printk( "%d IN, ", data_count );
1568 #endif1569 if (data_count == 1) {1570 *current_SC->SCp.ptr++ = inb( Read_FIFO_port );
1571 --current_SC->SCp.this_residual;
1572 }else{1573 data_count >>= 1; /* Number of words */1574 insw( Read_FIFO_port, current_SC->SCp.ptr, data_count );
1575 current_SC->SCp.ptr += 2 * data_count;
1576 current_SC->SCp.this_residual -= 2 * data_count;
1577 }1578 }1579 if (!current_SC->SCp.this_residual1580 && current_SC->SCp.buffers_residual) {1581 --current_SC->SCp.buffers_residual;
1582 ++current_SC->SCp.buffer;
1583 current_SC->SCp.ptr = current_SC->SCp.buffer->address;
1584 current_SC->SCp.this_residual = current_SC->SCp.buffer->length;
1585 }1586 }1587 }1588
1589 if (done) {1590 #ifEVERY_ACCESS1591 printk( " ** IN DONE %d ** ", current_SC->SCp.have_data_in );
1592 #endif1593
1594 #ifERRORS_ONLY1595 if (current_SC->cmnd[0] == REQUEST_SENSE && !current_SC->SCp.Status) {1596 if ((unsignedchar)(*((char *)current_SC->request_buffer+2)) & 0x0f) {1597 unsignedcharkey;
1598 unsignedcharcode;
1599 unsignedcharqualifier;
1600
1601 key = (unsignedchar)(*((char *)current_SC->request_buffer + 2))
1602 & 0x0f;
1603 code = (unsignedchar)(*((char *)current_SC->request_buffer + 12));
1604 qualifier = (unsignedchar)(*((char *)current_SC->request_buffer1605 + 13));
1606
1607 if (!(key == UNIT_ATTENTION && (code == 0x29 || !code))
1608 && !(key == NOT_READY1609 && code == 0x04
1610 && (!qualifier || qualifier == 0x02 || qualifier == 0x01))
1611 && !(key == ILLEGAL_REQUEST && (code == 0x25
1612 || code == 0x24
1613 || !code)))
1614
1615 printk( "fdomain: REQUEST SENSE "
1616 "Key = %x, Code = %x, Qualifier = %x\n",
1617 key, code, qualifier );
1618 }1619 }1620 #endif1621 #ifEVERY_ACCESS1622 printk( "BEFORE MY_DONE. . ." );
1623 #endif1624 my_done( (current_SC->SCp.Status & 0xff)
1625 | ((current_SC->SCp.Message & 0xff) << 8) | (DID_OK << 16) );
1626 #ifEVERY_ACCESS1627 printk( "RETURNING.\n" );
1628 #endif1629
1630 }else{1631 if (current_SC->SCp.phase & disconnect) {1632 outb( 0xd0 | FIFO_COUNT, Interrupt_Cntl_port );
1633 outb( 0x00, SCSI_Cntl_port );
1634 }else{1635 outb( 0x90 | FIFO_COUNT, Interrupt_Cntl_port );
1636 }1637 }1638 #ifDEBUG_RACE1639 in_interrupt_flag = 0;
1640 #endif1641 return;
1642 }1643
1644 intfdomain_16x0_queue( Scsi_Cmnd * SCpnt, void (*done)(Scsi_Cmnd *))
/* */1645 {1646 if (in_command) {1647 panic( "fdomain: fdomain_16x0_queue() NOT REENTRANT!\n" );
1648 }1649 #ifEVERY_ACCESS1650 printk( "queue: target = %d cmnd = 0x%02x pieces = %d size = %u\n",
1651 SCpnt->target,
1652 *(unsignedchar *)SCpnt->cmnd,
1653 SCpnt->use_sg,
1654 SCpnt->request_bufflen );
1655 #endif1656
1657 fdomain_make_bus_idle();
1658
1659 current_SC = SCpnt; /* Save this for the done function */1660 current_SC->scsi_done = done;
1661
1662 /* Initialize static data */1663
1664 if (current_SC->use_sg) {1665 current_SC->SCp.buffer =
1666 (structscatterlist *)current_SC->request_buffer;
1667 current_SC->SCp.ptr = current_SC->SCp.buffer->address;
1668 current_SC->SCp.this_residual = current_SC->SCp.buffer->length;
1669 current_SC->SCp.buffers_residual = current_SC->use_sg - 1;
1670 }else{1671 current_SC->SCp.ptr = (char *)current_SC->request_buffer;
1672 current_SC->SCp.this_residual = current_SC->request_bufflen;
1673 current_SC->SCp.buffer = NULL;
1674 current_SC->SCp.buffers_residual = 0;
1675 }1676
1677
1678 current_SC->SCp.Status = 0;
1679 current_SC->SCp.Message = 0;
1680 current_SC->SCp.have_data_in = 0;
1681 current_SC->SCp.sent_command = 0;
1682 current_SC->SCp.phase = in_arbitration;
1683
1684 /* Start arbitration */1685 outb( 0x00, Interrupt_Cntl_port );
1686 outb( 0x00, SCSI_Cntl_port ); /* Disable data drivers */1687 outb( adapter_mask, SCSI_Data_NoACK_port ); /* Set our id bit */1688 ++in_command;
1689 outb( 0x20, Interrupt_Cntl_port );
1690 outb( 0x14 | PARITY_MASK, TMC_Cntl_port ); /* Start arbitration */1691
1692 return 0;
1693 }1694
1695 /* The following code, which simulates the old-style command function, was1696 taken from Tommy Thorn's aha1542.c file. This code is Copyright (C)1697 1992 Tommy Thorn. */1698
1699 staticvolatileintinternal_done_flag = 0;
1700 staticvolatileintinternal_done_errcode = 0;
1701
1702 staticvoidinternal_done( Scsi_Cmnd *SCpnt )
/* */1703 {1704 internal_done_errcode = SCpnt->result;
1705 ++internal_done_flag;
1706 }1707
1708 intfdomain_16x0_command( Scsi_Cmnd *SCpnt )
/* */1709 {1710 fdomain_16x0_queue( SCpnt, internal_done );
1711
1712 while (!internal_done_flag)
1713 ;
1714 internal_done_flag = 0;
1715 returninternal_done_errcode;
1716 }1717
1718 /* End of code derived from Tommy Thorn's work. */1719
1720 voidprint_info( Scsi_Cmnd *SCpnt )
/* */1721 {1722 unsignedintimr;
1723 unsignedintirr;
1724 unsignedintisr;
1725
1726 if (!SCpnt || !SCpnt->host) {1727 printk( "fdomain: cannot provide detailed information\n" );
1728 }1729
1730 printk( "%s\n", fdomain_16x0_info( SCpnt->host ) );
1731 print_banner( SCpnt->host );
1732 switch (SCpnt->SCp.phase) {1733 casein_arbitration: printk( "arbitration " ); break;
1734 casein_selection: printk( "selection " ); break;
1735 casein_other: printk( "other " ); break;
1736 default: printk( "unknown " ); break;
1737 }1738
1739 printk( "(%d), target = %d cmnd = 0x%02x pieces = %d size = %u\n",
1740 SCpnt->SCp.phase,
1741 SCpnt->target,
1742 *(unsignedchar *)SCpnt->cmnd,
1743 SCpnt->use_sg,
1744 SCpnt->request_bufflen );
1745 printk( "sent_command = %d, have_data_in = %d, timeout = %d\n",
1746 SCpnt->SCp.sent_command,
1747 SCpnt->SCp.have_data_in,
1748 SCpnt->timeout );
1749 #ifDEBUG_RACE1750 printk( "in_interrupt_flag = %d\n", in_interrupt_flag );
1751 #endif1752
1753 imr = (inb( 0x0a1 ) << 8) + inb( 0x21 );
1754 outb( 0x0a, 0xa0 );
1755 irr = inb( 0xa0 ) << 8;
1756 outb( 0x0a, 0x20 );
1757 irr += inb( 0x20 );
1758 outb( 0x0b, 0xa0 );
1759 isr = inb( 0xa0 ) << 8;
1760 outb( 0x0b, 0x20 );
1761 isr += inb( 0x20 );
1762
1763 /* Print out interesting information */1764 printk( "IMR = 0x%04x", imr );
1765 if (imr & (1 << interrupt_level))
1766 printk( " (masked)" );
1767 printk( ", IRR = 0x%04x, ISR = 0x%04x\n", irr, isr );
1768
1769 printk( "SCSI Status = 0x%02x\n", inb( SCSI_Status_port ) );
1770 printk( "TMC Status = 0x%02x", inb( TMC_Status_port ) );
1771 if (inb( TMC_Status_port & 1))
1772 printk( " (interrupt)" );
1773 printk( "\n" );
1774 printk( "Interrupt Status = 0x%02x", inb( Interrupt_Status_port ) );
1775 if (inb( Interrupt_Status_port ) & 0x08)
1776 printk( " (enabled)" );
1777 printk( "\n" );
1778 if (chip == tmc18c50 || chip == tmc18c30) {1779 printk( "FIFO Status = 0x%02x\n", inb( port_base + FIFO_Status ) );
1780 printk( "Int. Condition = 0x%02x\n",
1781 inb( port_base + Interrupt_Cond ) );
1782 }1783 printk( "Configuration 1 = 0x%02x\n", inb( port_base + Configuration1 ) );
1784 if (chip == tmc18c50 || chip == tmc18c30)
1785 printk( "Configuration 2 = 0x%02x\n",
1786 inb( port_base + Configuration2 ) );
1787 }1788
1789 intfdomain_16x0_abort( Scsi_Cmnd *SCpnt)
/* */1790 {1791 unsignedlongflags;
1792 #ifEVERY_ACCESS || ERRORS_ONLY || DEBUG_ABORT1793 printk( "fdomain: abort " );
1794 #endif1795
1796 save_flags( flags );
1797 cli();
1798 if (!in_command) {1799 #ifEVERY_ACCESS || ERRORS_ONLY1800 printk( " (not in command)\n" );
1801 #endif1802 restore_flags( flags );
1803 returnSCSI_ABORT_NOT_RUNNING;
1804 }elseprintk( "\n" );
1805
1806 #ifDEBUG_ABORT1807 print_info( SCpnt );
1808 #endif1809
1810 fdomain_make_bus_idle();
1811
1812 current_SC->SCp.phase |= aborted;
1813
1814 current_SC->result = DID_ABORT << 16;
1815
1816 restore_flags( flags );
1817
1818 /* Aborts are not done well. . . */1819 my_done( DID_ABORT << 16 );
1820
1821 returnSCSI_ABORT_SUCCESS;
1822 }1823
1824 intfdomain_16x0_reset( Scsi_Cmnd *SCpnt )
/* */1825 {1826 #ifDEBUG_RESET1827 staticintcalled_once = 0;
1828 #endif1829
1830 #ifERRORS_ONLY1831 if (SCpnt) printk( "fdomain: SCSI Bus Reset\n" );
1832 #endif1833
1834 #ifDEBUG_RESET1835 if (called_once) print_info( current_SC );
1836 called_once = 1;
1837 #endif1838
1839 outb( 1, SCSI_Cntl_port );
1840 do_pause( 2 );
1841 outb( 0, SCSI_Cntl_port );
1842 do_pause( 115 );
1843 outb( 0, SCSI_Mode_Cntl_port );
1844 outb( PARITY_MASK, TMC_Cntl_port );
1845
1846 /* Unless this is the very first call (i.e., SCPnt == NULL), everything1847 is probably hosed at this point. We will, however, try to keep1848 things going by informing the high-level code that we need help. */1849
1850 returnSCSI_RESET_WAKEUP;
1851 }1852
1853 #include "sd.h"
1854 #include "scsi_ioctl.h"
1855
1856 intfdomain_16x0_biosparam( Scsi_Disk *disk, kdev_tdev, int *info_array )
/* */1857 {1858 intdrive;
1859 unsignedcharbuf[512 + sizeof( int ) * 2];
1860 intsize = disk->capacity;
1861 int *sizes = (int *)buf;
1862 unsignedchar *data = (unsignedchar *)(sizes + 2);
1863 unsignedchardo_read[] = {READ_6, 0, 0, 0, 1, 0 };
1864 intretcode;
1865 structdrive_info{1866 unsignedshortcylinders;
1867 unsignedcharheads;
1868 unsignedcharsectors;
1869 } *i;
1870
1871 /* NOTES:1872 The RAM area starts at 0x1f00 from the bios_base address.1873
1874 For BIOS Version 2.0:1875 1876 The drive parameter table seems to start at 0x1f30.1877 The first byte's purpose is not known.1878 Next is the cylinder, head, and sector information.1879 The last 4 bytes appear to be the drive's size in sectors.1880 The other bytes in the drive parameter table are unknown.1881 If anyone figures them out, please send me mail, and I will1882 update these notes.1883
1884 Tape drives do not get placed in this table.1885
1886 There is another table at 0x1fea:1887 If the byte is 0x01, then the SCSI ID is not in use.1888 If the byte is 0x18 or 0x48, then the SCSI ID is in use,1889 although tapes don't seem to be in this table. I haven't1890 seen any other numbers (in a limited sample).1891
1892 0x1f2d is a drive count (i.e., not including tapes)1893
1894 The table at 0x1fcc are I/O ports addresses for the various1895 operations. I calculate these by hand in this driver code.1896
1897 1898 1899 For the ISA-200S version of BIOS Version 2.0:1900
1901 The drive parameter table starts at 0x1f33.1902
1903 WARNING: Assume that the table entry is 25 bytes long. Someone needs1904 to check this for the Quantum ISA-200S card.1905
1906 1907 1908 For BIOS Version 3.2:1909
1910 The drive parameter table starts at 0x1f70. Each entry is1911 0x0a bytes long. Heads are one less than we need to report.1912 */1913
1914 drive = MINOR(dev) / 16;
1915
1916 if (bios_major == 2) {1917 switch (Quantum) {1918 case 2: /* ISA_200S */1919 /* The value of 25 has never been verified.1920 It should probably be 15. */1921 i = (structdrive_info *)( (char *)bios_base + 0x1f33 + drive * 25 );
1922 break;
1923 case 3: /* ISA_250MG */1924 i = (structdrive_info *)( (char *)bios_base + 0x1f36 + drive * 15 );
1925 break;
1926 case 4: /* ISA_200S (another one) */1927 i = (structdrive_info *)( (char *)bios_base + 0x1f34 + drive * 15 );
1928 break;
1929 default:
1930 i = (structdrive_info *)( (char *)bios_base + 0x1f31 + drive * 25 );
1931 break;
1932 }1933 info_array[0] = i->heads;
1934 info_array[1] = i->sectors;
1935 info_array[2] = i->cylinders;
1936 }elseif (bios_major == 3
1937 && bios_minor >= 0
1938 && bios_minor < 4) {/* 3.0 and 3.2 BIOS */1939 i = (structdrive_info *)( (char *)bios_base + 0x1f71 + drive * 10 );
1940 info_array[0] = i->heads + 1;
1941 info_array[1] = i->sectors;
1942 info_array[2] = i->cylinders;
1943 }else{/* 3.4 BIOS (and up?) */1944 /* This algorithm was provided by Future Domain (much thanks!). */1945
1946 sizes[0] = 0; /* zero bytes out */1947 sizes[1] = 512; /* one sector in */1948 memcpy( data, do_read, sizeof( do_read ) );
1949 retcode = kernel_scsi_ioctl( disk->device,
1950 SCSI_IOCTL_SEND_COMMAND,
1951 (void *)buf );
1952 if (!retcode/* SCSI command ok */1953 && data[511] == 0xaa && data[510] == 0x55 /* Partition table valid */1954 && data[0x1c2]) {/* Partition type */1955
1956 /* The partition table layout is as follows:1957
1958 Start: 0x1b3h1959 Offset: 0 = partition status1960 1 = starting head1961 2 = starting sector and cylinder (word, encoded)1962 4 = partition type1963 5 = ending head1964 6 = ending sector and cylinder (word, encoded)1965 8 = starting absolute sector (double word)1966 c = number of sectors (double word)1967 Signature: 0x1fe = 0x55aa1968
1969 So, this algorithm assumes:1970 1) the first partition table is in use,1971 2) the data in the first entry is correct, and1972 3) partitions never divide cylinders1973
1974 Note that (1) may be FALSE for NetBSD (and other BSD flavors),1975 as well as for Linux. Note also, that Linux doesn't pay any1976 attention to the fields that are used by this algorithm -- it1977 only uses the absolute sector data. Recent versions of Linux's1978 fdisk(1) will fill this data in correctly, and forthcoming1979 versions will check for consistency.1980
1981 Checking for a non-zero partition type is not part of the1982 Future Domain algorithm, but it seemed to be a reasonable thing1983 to do, especially in the Linux and BSD worlds. */1984
1985 info_array[0] = data[0x1c3] + 1; /* heads */1986 info_array[1] = data[0x1c4] & 0x3f; /* sectors */1987 }else{1988
1989 /* Note that this new method guarantees that there will always be1990 less than 1024 cylinders on a platter. This is good for drives1991 up to approximately 7.85GB (where 1GB = 1024 * 1024 kB). */1992
1993 if ((unsignedint)size >= 0x7e0000U) {1994 info_array[0] = 0xff; /* heads = 255 */1995 info_array[1] = 0x3f; /* sectors = 63 */1996 }elseif ((unsignedint)size >= 0x200000U) {1997 info_array[0] = 0x80; /* heads = 128 */1998 info_array[1] = 0x3f; /* sectors = 63 */1999 }else{2000 info_array[0] = 0x40; /* heads = 64 */2001 info_array[1] = 0x20; /* sectors = 32 */2002 }2003 }2004 /* For both methods, compute the cylinders */2005 info_array[2] = (unsignedint)size / (info_array[0] * info_array[1] );
2006 }2007
2008 return 0;
2009 }2010
2011 #ifdefMODULE2012 /* Eventually this will go into an include file, but this will be later */2013 Scsi_Host_Templatedriver_template = FDOMAIN_16X0;
2014
2015 #include "scsi_module.c"
2016 #endif