Guest User

Untitled

a guest
Mar 3rd, 2018
478
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 65.95 KB | None | 0 0
  1. /* fdomain.c -- Future Domain TMC-16x0 SCSI driver
  2. * Created: Sun May 3 18:53:19 1992 by faith@cs.unc.edu
  3. * Revised: Mon Dec 28 21:59:02 1998 by faith@acm.org
  4. * Author: Rickard E. Faith, faith@cs.unc.edu
  5. * Copyright 1992-1996, 1998 Rickard E. Faith (faith@acm.org)
  6.  
  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
  10. * later version.
  11.  
  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.
  16.  
  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.
  20.  
  21. **************************************************************************
  22.  
  23. SUMMARY:
  24.  
  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
  27. Chips are supported:
  28. TMC-1800, TMC-18C50, TMC-18C30, TMC-36C70
  29. Boards supported:
  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]
  34. IBM ?
  35. LILO/INSMOD command-line options:
  36. fdomain=<PORT_BASE>,<IRQ>[,<ADAPTER_ID>]
  37.  
  38.  
  39.  
  40. NOTE:
  41.  
  42. The Adaptec AHA-2920C has an Adaptec AIC-7850 chip on it.
  43. Use the aic7xxx driver for this board.
  44.  
  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.
  49.  
  50.  
  51.  
  52. THANKS:
  53.  
  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
  58.  
  59.  
  60.  
  61. DESCRIPTION:
  62.  
  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.
  68.  
  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
  75. detected.
  76.  
  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.
  87.  
  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
  90. possible support.
  91.  
  92.  
  93.  
  94. HISTORY:
  95.  
  96. Linux Driver Driver
  97. Version Version Date Support/Notes
  98.  
  99. 0.0 3 May 1992 V2.0 BIOS; 1800 chip
  100. 0.97 1.9 28 Jul 1992
  101. 0.98.6 3.1 27 Nov 1992
  102. 0.99 3.2 9 Dec 1992
  103.  
  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)
  110.  
  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
  117.  
  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
  132.  
  133.  
  134. REFERENCES USED:
  135.  
  136. "TMC-1800 SCSI Chip Specification (FDC-1800T)", Future Domain Corporation,
  137. 1990.
  138.  
  139. "Technical Reference Manual: 18C50 SCSI Host Adapter Chip", Future Domain
  140. Corporation, January 1992.
  141.  
  142. "LXT SCSI Products: Specifications and OEM Technical Manual (Revision
  143. B/September 1991)", Maxtor Corporation, 1991.
  144.  
  145. "7213S product Manual (Revision P3)", Maxtor Corporation, 1992.
  146.  
  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)
  150.  
  151. Private communications, Drew Eckhardt (drew@cs.colorado.edu) and Eric
  152. Youngdale (ericy@cais.com), 1992.
  153.  
  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.)
  157.  
  158. Hogan, Thom. The Programmer's PC Sourcebook. Microsoft Press, 1988. Page
  159. 60 (2.39: Disk Partition Table Layout).
  160.  
  161. "18C30 Technical Reference Manual", Future Domain Corporation, 1993, page
  162. 6-1.
  163.  
  164.  
  165.  
  166. NOTES ON REFERENCES:
  167.  
  168. The Maxtor manuals were free. Maxtor telephone technical support is
  169. great!
  170.  
  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 :-).
  180.  
  181.  
  182.  
  183. ALPHA TESTERS:
  184.  
  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
  188. more recent times):
  189.  
  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).
  194.  
  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.
  198.  
  199. Thanks to Dave Newman (dnewman@crl.com) for providing initial patches for
  200. the version 3.4 BIOS.
  201.  
  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.
  205.  
  206. Thanks to Eric Kasten (tigger@petroglyph.cl.msu.edu) for providing the
  207. patch for the version 3.5 BIOS.
  208.  
  209. Thanks for Stephen Henson (shenson@nyx10.cs.du.edu) for providing the
  210. patch for the Quantum ISA-200S SCSI adapter.
  211.  
  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.
  216.  
  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.
  220.  
  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
  224. bug reports.
  225.  
  226. Thanks to Tom Cavin (tec@usa1.com) for preliminary command-line option
  227. patches.
  228.  
  229. New PCI detection code written by Martin Mares <mj@atrey.karlin.mff.cuni.cz>
  230.  
  231. Insmod parameter code based on patches from Daniel Graham
  232. <graham@balance.uoregon.edu>.
  233.  
  234. All of the alpha testers deserve much thanks.
  235.  
  236.  
  237.  
  238. NOTES ON USER DEFINABLE OPTIONS:
  239.  
  240. DEBUG: This turns on the printing of various debug information.
  241.  
  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.
  247.  
  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.
  256.  
  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.
  261.  
  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.
  270.  
  271. **************************************************************************/
  272.  
  273. #ifdef PCMCIA
  274. #define MODULE
  275. #endif
  276.  
  277. #ifdef MODULE
  278. #include <linux/module.h>
  279. #endif
  280.  
  281. #ifdef PCMCIA
  282. #undef MODULE
  283. #endif
  284.  
  285. #include <linux/sched.h>
  286. #include <asm/io.h>
  287. #include <linux/blk.h>
  288. #include "scsi.h"
  289. #include "hosts.h"
  290. #include "fdomain.h"
  291. #include <asm/system.h>
  292. #include <asm/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>
  300.  
  301. #include <linux/config.h> /* for CONFIG_PCI */
  302.  
  303. struct proc_dir_entry proc_scsi_fdomain = {
  304. PROC_SCSI_FDOMAIN, 7, "fdomain",
  305. S_IFDIR | S_IRUGO | S_IXUGO, 2
  306. };
  307.  
  308. #define VERSION "$Revision: 5.50 $"
  309.  
  310. /* START OF USER DEFINABLE OPTIONS */
  311.  
  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) */
  316.  
  317. /* END OF USER DEFINABLE OPTIONS */
  318.  
  319. #if DEBUG
  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 */
  327. #else
  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
  334. #define DEBUG_RACE 0
  335. #endif
  336.  
  337. /* Errors are reported on the line, so we don't need to report them again */
  338. #if EVERY_ACCESS
  339. #undef ERRORS_ONLY
  340. #define ERRORS_ONLY 0
  341. #endif
  342.  
  343. #if ENABLE_PARITY
  344. #define PARITY_MASK 0x08
  345. #else
  346. #define PARITY_MASK 0x00
  347. #endif
  348.  
  349. enum chip_type {
  350. unknown = 0x00,
  351. tmc1800 = 0x01,
  352. tmc18c50 = 0x02,
  353. tmc18c30 = 0x03,
  354. };
  355.  
  356. enum {
  357. in_arbitration = 0x02,
  358. in_selection = 0x04,
  359. in_other = 0x08,
  360. disconnect = 0x10,
  361. aborted = 0x20,
  362. sent_ident = 0x40,
  363. };
  364.  
  365. enum in_port_type {
  366. Read_SCSI_Data = 0,
  367. SCSI_Status = 1,
  368. TMC_Status = 2,
  369. FIFO_Status = 3, /* tmc18c50/tmc18c30 only */
  370. Interrupt_Cond = 4, /* tmc18c50/tmc18c30 only */
  371. LSB_ID_Code = 5,
  372. MSB_ID_Code = 6,
  373. Read_Loopback = 7,
  374. SCSI_Data_NoACK = 8,
  375. Interrupt_Status = 9,
  376. Configuration1 = 10,
  377. Configuration2 = 11, /* tmc18c50/tmc18c30 only */
  378. Read_FIFO = 12,
  379. FIFO_Data_Count = 14
  380. };
  381.  
  382. enum out_port_type {
  383. Write_SCSI_Data = 0,
  384. SCSI_Cntl = 1,
  385. Interrupt_Cntl = 2,
  386. SCSI_Mode_Cntl = 3,
  387. TMC_Cntl = 4,
  388. Memory_Cntl = 5, /* tmc18c50/tmc18c30 only */
  389. Write_Loopback = 7,
  390. IO_Control = 11, /* tmc18c30 only */
  391. Write_FIFO = 12
  392. };
  393.  
  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;
  407.  
  408. #if DEBUG_RACE
  409. static volatile int in_interrupt_flag = 0;
  410. #endif
  411.  
  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;
  425.  
  426. static int FIFO_Size = 0x2000; /* 8k FIFO for
  427. pre-tmc18c30 chips */
  428.  
  429. extern void do_fdomain_16x0_intr( int irq, void *dev_id,
  430. struct pt_regs * regs );
  431.  
  432. #ifdef MODULE
  433. /* Allow insmod parameters to be like LILO
  434. parameters. For example:
  435. insmod fdomain fdomain=0x140,11
  436. */
  437. static int fdomain[]={ 0, 0, 0 };
  438. MODULE_PARM(fdomain, "2-3i");
  439. #endif
  440.  
  441. static unsigned long addresses[] = {
  442. 0xc8000,
  443. 0xca000,
  444. 0xce000,
  445. 0xde000,
  446. 0xcc000, /* Extra addresses for PCI boards */
  447. 0xd0000,
  448. 0xe0000,
  449. };
  450. #define ADDRESS_COUNT (sizeof( addresses ) / sizeof( unsigned ))
  451.  
  452. static unsigned short ports[] = { 0x140, 0x150, 0x160, 0x170 };
  453. #define PORT_COUNT (sizeof( ports ) / sizeof( unsigned short ))
  454.  
  455. static unsigned short ints[] = { 3, 5, 10, 11, 12, 14, 15, 0 };
  456.  
  457. /*
  458.  
  459. READ THIS BEFORE YOU ADD A SIGNATURE!
  460.  
  461. READING THIS SHORT NOTE CAN SAVE YOU LOTS OF TIME!
  462.  
  463. READ EVERY WORD, ESPECIALLY THE WORD *NOT*
  464.  
  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.
  468.  
  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
  471. Seagate driver):
  472.  
  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
  480.  
  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.)
  486.  
  487. */
  488.  
  489. struct signature {
  490. const char *signature;
  491. int sig_offset;
  492. int sig_length;
  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 */
  496. } signatures[] = {
  497. /* 1 2 3 4 5 6 */
  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 },
  518.  
  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
  522. signatures!
  523.  
  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). */
  530. };
  531.  
  532. #define SIGNATURE_COUNT (sizeof( signatures ) / sizeof( struct signature ))
  533.  
  534. static void print_banner( struct Scsi_Host *shpnt )
  535. {
  536. if (!shpnt) return; /* This won't ever happen */
  537.  
  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 );
  541. } else {
  542. printk( "scsi%d: <fdomain> BIOS version ", shpnt->host_no );
  543.  
  544. if (bios_major >= 0) printk( "%d.", bios_major );
  545. else printk( "?." );
  546.  
  547. if (bios_minor >= 0) printk( "%d", bios_minor );
  548. else printk( "?." );
  549.  
  550. printk( " at 0x%lx using scsi id %d\n",
  551. bios_base, shpnt->this_id );
  552. }
  553.  
  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 ",
  559. shpnt->host_no,
  560. chip == tmc1800 ? "TMC-1800"
  561. : (chip == tmc18c50 ? "TMC-18C50"
  562. : (chip == tmc18c30 ?
  563. (PCI_bus ? "TMC-36C70 (PCI bus)" : "TMC-18C30")
  564. : "Unknown")),
  565. port_base );
  566.  
  567. if (interrupt_level) printk( "%d", interrupt_level );
  568. else printk( "<none>" );
  569.  
  570. printk( "\n" );
  571. }
  572.  
  573. void fdomain_setup( char *str, int *ints )
  574. {
  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" );
  579. }
  580.  
  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;
  584.  
  585. bios_major = bios_minor = -1; /* Use geometry for BIOS version >= 3.4 */
  586. }
  587.  
  588.  
  589. static void do_pause( unsigned amount ) /* Pause for amount*10 milliseconds */
  590. {
  591. do {
  592. udelay(10*1000);
  593. } while (--amount);
  594. }
  595.  
  596. inline static void fdomain_make_bus_idle( void )
  597. {
  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. */
  602. else
  603. outb( 0x01 | PARITY_MASK, TMC_Cntl_port );
  604. }
  605.  
  606. static int fdomain_is_valid_port( int port )
  607. {
  608. #if DEBUG_DETECT
  609. printk( " (%x%x),",
  610. inb( port + MSB_ID_Code ), inb( port + LSB_ID_Code ) );
  611. #endif
  612.  
  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.
  617. */
  618.  
  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;
  622. chip = tmc1800;
  623. } else { /* test for 0xe960 id */
  624. if (inb( port + MSB_ID_Code ) != 0x60) return 0;
  625. chip = tmc18c50;
  626.  
  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.) */
  631.  
  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) {
  636. chip = tmc18c30;
  637. FIFO_Size = 0x800; /* 2k FIFO */
  638. }
  639. }
  640. /* If that failed, we are an 18c50. */
  641. }
  642.  
  643. return 1;
  644. }
  645.  
  646. static int fdomain_test_loopback( void )
  647. {
  648. int i;
  649. int result;
  650.  
  651. for (i = 0; i < 255; i++) {
  652. outb( i, port_base + Write_Loopback );
  653. result = inb( port_base + Read_Loopback );
  654. if (i != result)
  655. return 1;
  656. }
  657. return 0;
  658. }
  659.  
  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
  665. lowest bios_base.]
  666.  
  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. */
  673.  
  674. static int fdomain_get_irq( int base )
  675. {
  676. int options = inb( base + Configuration1 );
  677.  
  678. #if DEBUG_DETECT
  679. printk( "scsi: <fdomain> Options = %x\n", options );
  680. #endif
  681.  
  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. */
  686.  
  687. if (chip != tmc18c30
  688. && !PCI_bus
  689. && addresses[ (options & 0xc0) >> 6 ] != bios_base) return 0;
  690.  
  691. return ints[ (options & 0x0e) >> 1 ];
  692. }
  693.  
  694. static int fdomain_isa_detect( int *irq, int *iobase )
  695. {
  696. int i, j;
  697. int base;
  698. int flag = 0;
  699.  
  700. #if DEBUG_DETECT
  701. printk( "scsi: <fdomain> fdomain_isa_detect:" );
  702. #endif
  703.  
  704. for (i = 0; !bios_base && i < ADDRESS_COUNT; i++) {
  705. #if DEBUG_DETECT
  706. printk( " %lx(%lx),", addresses[i], bios_base );
  707. #endif
  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];
  717. }
  718. }
  719. }
  720.  
  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).
  728. */
  729.  
  730. switch (Quantum) {
  731. case 2: /* ISA_200S */
  732. case 3: /* ISA_250MG */
  733. base = readb(bios_base + 0x1fa2) + (readb(bios_base + 0x1fa3) << 8);
  734. break;
  735. case 4: /* ISA_200S (another one) */
  736. base = readb(bios_base + 0x1fa3) + (readb(bios_base + 0x1fa4) << 8);
  737. break;
  738. default:
  739. base = readb(bios_base + 0x1fcc) + (readb(bios_base + 0x1fcd) << 8);
  740. break;
  741. }
  742.  
  743. #if DEBUG_DETECT
  744. printk( " %x,", base );
  745. #endif
  746.  
  747. for (flag = 0, i = 0; !flag && i < PORT_COUNT; i++) {
  748. if (base == ports[i])
  749. ++flag;
  750. }
  751.  
  752. if (flag && fdomain_is_valid_port( base )) {
  753. *irq = fdomain_get_irq( base );
  754. *iobase = base;
  755. return 1;
  756. }
  757.  
  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. */
  761.  
  762. #if DEBUG_DETECT
  763. printk( " RAM FAILED, " );
  764. #endif
  765. }
  766.  
  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.
  772.  
  773. Do not, however, check ports which the kernel knows are being used by
  774. another driver. */
  775.  
  776. for (i = 0; i < PORT_COUNT; i++) {
  777. base = ports[i];
  778. if (check_region( base, 0x10 )) {
  779. #if DEBUG_DETECT
  780. printk( " (%x inuse),", base );
  781. #endif
  782. continue;
  783. }
  784. #if DEBUG_DETECT
  785. printk( " %x,", base );
  786. #endif
  787. if ((flag = fdomain_is_valid_port( base ))) break;
  788. }
  789.  
  790. #if DEBUG_DETECT
  791. if (flag) printk( " SUCCESS\n" );
  792. else printk( " FAILURE\n" );
  793. #endif
  794.  
  795. if (!flag) return 0; /* iobase not found */
  796.  
  797. *irq = fdomain_get_irq( base );
  798. *iobase = base;
  799.  
  800. return 1; /* success */
  801. }
  802.  
  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. */
  806.  
  807. #ifdef CONFIG_PCI
  808. static int fdomain_pci_bios_detect( int *irq, int *iobase )
  809. {
  810. unsigned int pci_irq; /* PCI interrupt line */
  811. unsigned long pci_base; /* PCI I/O base address */
  812. struct pci_dev *pdev = NULL;
  813.  
  814. if (!pci_present()) return 0;
  815.  
  816. #if DEBUG_DETECT
  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. */
  819.  
  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",
  823. PCI_VENDOR_ID_FD,
  824. PCI_DEVICE_ID_FD_36C70 );
  825. #endif
  826.  
  827. if ((pdev = pci_find_device(PCI_VENDOR_ID_FD,
  828. PCI_DEVICE_ID_FD_36C70,
  829. pdev)) == NULL)
  830. return 0;
  831.  
  832. #if DEBUG_DETECT
  833. printk( "scsi: <fdomain> TMC-3260 detect:"
  834. " PCI bus %u, device %u, function %u\n",
  835. pdev->bus->number,
  836. PCI_SLOT(pdev->devfn),
  837. PCI_FUNC(pdev->devfn));
  838. #endif
  839.  
  840. /* We now have the appropriate device function for the FD board so we
  841. just read the PCI config info from the registers. */
  842.  
  843. pci_base = pdev->base_address[0];
  844. pci_irq = pdev->irq;
  845.  
  846. /* Now we have the I/O base address and interrupt from the PCI
  847. configuration registers. */
  848.  
  849. *irq = pci_irq;
  850. *iobase = (pci_base & PCI_BASE_ADDRESS_IO_MASK);
  851.  
  852. #if DEBUG_DETECT
  853. printk( "scsi: <fdomain> TMC-3260 detect:"
  854. " IRQ = %d, I/O base = 0x%x [0x%lx]\n", *irq, *iobase, pci_base );
  855. #endif
  856.  
  857. if (!fdomain_is_valid_port( *iobase )) {
  858. printk( "scsi: <fdomain>"
  859. " PCI card detected, but driver not loaded (invalid port)\n" );
  860. return 0;
  861. }
  862.  
  863. /* Fill in a few global variables. Ugh. */
  864. bios_major = bios_minor = -1;
  865. PCI_bus = 1;
  866. Quantum = 0;
  867. bios_base = 0;
  868.  
  869. return 1;
  870. }
  871. #endif
  872.  
  873. int fdomain_16x0_detect( Scsi_Host_Template *tpnt )
  874. {
  875. int retcode;
  876. struct Scsi_Host *shpnt;
  877. #if DO_DETECT
  878. const int buflen = 255;
  879. Scsi_Cmnd SCinit;
  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];
  885. #endif
  886.  
  887. tpnt->proc_dir = &proc_scsi_fdomain;
  888.  
  889. #ifdef MODULE
  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;
  895. ++setup_called;
  896. }
  897. #endif
  898.  
  899. if (setup_called) {
  900. #if DEBUG_DETECT
  901. printk( "scsi: <fdomain> No BIOS, using port_base = 0x%x, irq = %d\n",
  902. port_base, interrupt_level );
  903. #endif
  904. if (!fdomain_is_valid_port( port_base )) {
  905. printk( "scsi: <fdomain> Cannot locate chip at port base 0x%x\n",
  906. port_base );
  907. printk( "scsi: <fdomain> Bad LILO/INSMOD parameters?\n" );
  908. return 0;
  909. }
  910. } else {
  911. int flag = 0;
  912.  
  913. #ifdef CONFIG_PCI
  914. /* Try PCI detection first */
  915. flag = fdomain_pci_bios_detect( &interrupt_level, &port_base );
  916. #endif
  917. if (!flag) {
  918. /* Then try ISA bus detection */
  919. flag = fdomain_isa_detect( &interrupt_level, &port_base );
  920.  
  921. if (!flag) {
  922. printk( "scsi: <fdomain> Detection failed (no card)\n" );
  923. return 0;
  924. }
  925. }
  926. }
  927.  
  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;
  941.  
  942. fdomain_16x0_reset( NULL, 0 );
  943.  
  944. if (fdomain_test_loopback()) {
  945. printk( "scsi: <fdomain> Detection failed"
  946. " (loopback test failed at port base 0x%x)\n", port_base );
  947. if (setup_called) {
  948. printk( "scsi: <fdomain> Bad LILO/INSMOD parameters?\n" );
  949. }
  950. return 0;
  951. }
  952.  
  953. if (this_id) {
  954. tpnt->this_id = (this_id & 0x07);
  955. adapter_mask = (1 << tpnt->this_id);
  956. } else {
  957. if (PCI_bus || (bios_major == 3 && bios_minor >= 2) || bios_major < 0) {
  958. tpnt->this_id = 7;
  959. adapter_mask = 0x80;
  960. } else {
  961. tpnt->this_id = 6;
  962. adapter_mask = 0x40;
  963. }
  964. }
  965.  
  966. /* Print out a banner here in case we can't
  967. get resources. */
  968.  
  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 );
  974.  
  975. /* Log IRQ with kernel */
  976. if (!interrupt_level) {
  977. printk( "scsi: <fdomain>"
  978. " Card Detected, but driver not loaded (no IRQ)\n" );
  979. return 0;
  980. } else {
  981. /* Register the IRQ with the kernel */
  982.  
  983. retcode = request_irq( interrupt_level,
  984. do_fdomain_16x0_intr, 0, "fdomain", NULL);
  985.  
  986. if (retcode < 0) {
  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",
  993. interrupt_level );
  994. printk( " Please use another IRQ!\n" );
  995. } else {
  996. printk( "scsi: <fdomain> Error getting IRQ %d\n",
  997. interrupt_level );
  998. printk( " This shouldn't happen!\n" );
  999. printk( " Send mail to faith@acm.org\n" );
  1000. }
  1001. printk( "scsi: <fdomain> Detected, but driver not loaded (IRQ)\n" );
  1002. return 0;
  1003. }
  1004. }
  1005.  
  1006. /* Log I/O ports with kernel */
  1007. request_region( port_base, 0x10, "fdomain" );
  1008.  
  1009. #if DO_DETECT
  1010.  
  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
  1016. debugging. */
  1017.  
  1018. SCinit.request_buffer = SCinit.buffer = buf;
  1019. SCinit.request_bufflen = SCinit.bufflen = sizeof(buf)-1;
  1020. SCinit.use_sg = 0;
  1021. SCinit.lun = 0;
  1022.  
  1023. printk( "scsi: <fdomain> detection routine scanning for devices:\n" );
  1024. for (i = 0; i < 8; i++) {
  1025. SCinit.target = i;
  1026. if (i == tpnt->this_id) /* Skip host adapter */
  1027. continue;
  1028. memcpy(SCinit.cmnd, do_request_sense, sizeof(do_request_sense));
  1029. retcode = fdomain_16x0_command(&SCinit);
  1030. if (!retcode) {
  1031. memcpy(SCinit.cmnd, do_inquiry, sizeof(do_inquiry));
  1032. retcode = fdomain_16x0_command(&SCinit);
  1033. if (!retcode) {
  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);
  1039. if (!retcode) {
  1040. unsigned long blocks, size, capacity;
  1041.  
  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;
  1046.  
  1047. printk( "%lu MB (%lu byte blocks)",
  1048. ((capacity + 5L) / 10L), size );
  1049. } else {
  1050. memcpy(SCinit.cmnd, do_request_sense, sizeof(do_request_sense));
  1051. retcode = fdomain_16x0_command(&SCinit);
  1052. }
  1053. printk ("\n" );
  1054. } else {
  1055. memcpy(SCinit.cmnd, do_request_sense, sizeof(do_request_sense));
  1056. retcode = fdomain_16x0_command(&SCinit);
  1057. }
  1058. }
  1059. }
  1060. #endif
  1061.  
  1062. return 1; /* Maximum of one adapter will be detected. */
  1063. }
  1064.  
  1065. const char *fdomain_16x0_info( struct Scsi_Host *ignore )
  1066. {
  1067. static char buffer[128];
  1068. char *pt;
  1069.  
  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;
  1076. if (*pt != ' ')
  1077. ++pt;
  1078. *pt = '\0';
  1079. } else { /* Assume VERSION is a number */
  1080. strcat( buffer, " " VERSION );
  1081. }
  1082.  
  1083. return buffer;
  1084. }
  1085.  
  1086. /* First pass at /proc information routine. */
  1087. /*
  1088. * inout : decides on the direction of the dataflow and the meaning of the
  1089. * variables
  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
  1096. */
  1097. int fdomain_16x0_proc_info( char *buffer, char **start, off_t offset,
  1098. int length, int hostno, int inout )
  1099. {
  1100. const char *info = fdomain_16x0_info( NULL );
  1101. int len;
  1102. int pos;
  1103. int begin;
  1104.  
  1105. if (inout) return(-ENOSYS);
  1106.  
  1107. begin = 0;
  1108. strcpy( buffer, info );
  1109. strcat( buffer, "\n" );
  1110.  
  1111. pos = len = strlen( buffer );
  1112.  
  1113. if(pos < offset) {
  1114. len = 0;
  1115. begin = pos;
  1116. }
  1117.  
  1118. *start = buffer + (offset - begin); /* Start of wanted data */
  1119. len -= (offset - begin);
  1120. if(len > length) len = length;
  1121.  
  1122. return(len);
  1123. }
  1124.  
  1125. #if 0
  1126. static int fdomain_arbitrate( void )
  1127. {
  1128. int status = 0;
  1129. unsigned long timeout;
  1130.  
  1131. #if EVERY_ACCESS
  1132. printk( "fdomain_arbitrate()\n" );
  1133. #endif
  1134.  
  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 */
  1138.  
  1139. timeout = 500;
  1140. do {
  1141. status = inb( TMC_Status_port ); /* Read adapter status */
  1142. if (status & 0x02) /* Arbitration complete */
  1143. return 0;
  1144. mdelay(1); /* Wait one millisecond */
  1145. } while (--timeout);
  1146.  
  1147. /* Make bus idle */
  1148. fdomain_make_bus_idle();
  1149.  
  1150. #if EVERY_ACCESS
  1151. printk( "Arbitration failed, status = %x\n", status );
  1152. #endif
  1153. #if ERRORS_ONLY
  1154. printk( "scsi: <fdomain> Arbitration failed, status = %x\n", status );
  1155. #endif
  1156. return 1;
  1157. }
  1158. #endif
  1159.  
  1160. static int fdomain_select( int target )
  1161. {
  1162. int status;
  1163. unsigned long timeout;
  1164. static int flag = 0;
  1165.  
  1166.  
  1167. outb( 0x82, SCSI_Cntl_port ); /* Bus Enable + Select */
  1168. outb( adapter_mask | (1 << target), SCSI_Data_NoACK_port );
  1169.  
  1170. /* Stop arbitration and enable parity */
  1171. outb( PARITY_MASK, TMC_Cntl_port );
  1172.  
  1173. timeout = 350; /* 350 msec */
  1174.  
  1175. do {
  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 );
  1180. return 0;
  1181. }
  1182. mdelay(1); /* wait one msec */
  1183. } while (--timeout);
  1184. /* Make bus idle */
  1185. fdomain_make_bus_idle();
  1186. #if EVERY_ACCESS
  1187. if (!target) printk( "Selection failed\n" );
  1188. #endif
  1189. #if ERRORS_ONLY
  1190. if (!target) {
  1191. if (!flag) /* Skip first failure for all chips. */
  1192. ++flag;
  1193. else
  1194. printk( "scsi: <fdomain> Selection failed\n" );
  1195. }
  1196. #endif
  1197. return 1;
  1198. }
  1199.  
  1200. void my_done( int error )
  1201. {
  1202. if (in_command) {
  1203. in_command = 0;
  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" );
  1210. } else {
  1211. panic( "scsi: <fdomain> my_done() called outside of command\n" );
  1212. }
  1213. #if DEBUG_RACE
  1214. in_interrupt_flag = 0;
  1215. #endif
  1216. }
  1217.  
  1218. void do_fdomain_16x0_intr( int irq, void *dev_id, struct pt_regs * regs )
  1219. {
  1220. unsigned long flags;
  1221. int status;
  1222. int done = 0;
  1223. unsigned data_count;
  1224.  
  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
  1229. running. */
  1230.  
  1231. /* sti(); Yes, we really want sti() here if we want to lock up our machine */
  1232.  
  1233. outb( 0x00, Interrupt_Cntl_port );
  1234.  
  1235. /* We usually have one spurious interrupt after each command. Ignore it. */
  1236. if (!in_command || !current_SC) { /* Spurious interrupt */
  1237. #if EVERY_ACCESS
  1238. printk( "Spurious interrupt, in_command = %d, current_SC = %x\n",
  1239. in_command, current_SC );
  1240. #endif
  1241. return;
  1242. }
  1243.  
  1244. /* Abort calls my_done, so we do nothing here. */
  1245. if (current_SC->SCp.phase & aborted) {
  1246. #if DEBUG_ABORT
  1247. printk( "scsi: <fdomain> Interrupt after abort, ignoring\n" );
  1248. #endif
  1249. /*
  1250. return; */
  1251. }
  1252.  
  1253. #if DEBUG_RACE
  1254. ++in_interrupt_flag;
  1255. #endif
  1256.  
  1257. if (current_SC->SCp.phase & in_arbitration) {
  1258. status = inb( TMC_Status_port ); /* Read adapter status */
  1259. if (!(status & 0x02)) {
  1260. #if EVERY_ACCESS
  1261. printk( " AFAIL " );
  1262. #endif
  1263. spin_lock_irqsave(&io_request_lock, flags);
  1264. my_done( DID_BUS_BUSY << 16 );
  1265. spin_unlock_irqrestore(&io_request_lock, flags);
  1266. return;
  1267. }
  1268. current_SC->SCp.phase = in_selection;
  1269.  
  1270. outb( 0x40 | FIFO_COUNT, Interrupt_Cntl_port );
  1271.  
  1272. outb( 0x82, SCSI_Cntl_port ); /* Bus Enable + Select */
  1273. outb( adapter_mask | (1 << current_SC->target), SCSI_Data_NoACK_port );
  1274.  
  1275. /* Stop arbitration and enable parity */
  1276. outb( 0x10 | PARITY_MASK, TMC_Cntl_port );
  1277. #if DEBUG_RACE
  1278. in_interrupt_flag = 0;
  1279. #endif
  1280. return;
  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 )) {
  1286. #if EVERY_ACCESS
  1287. printk( " SFAIL " );
  1288. #endif
  1289. spin_lock_irqsave(&io_request_lock, flags);
  1290. my_done( DID_NO_CONNECT << 16 );
  1291. spin_unlock_irqrestore(&io_request_lock, flags);
  1292. return;
  1293. } else {
  1294. #if EVERY_ACCESS
  1295. printk( " AltSel " );
  1296. #endif
  1297. /* Stop arbitration and enable parity */
  1298. outb( 0x10 | PARITY_MASK, TMC_Cntl_port );
  1299. }
  1300. }
  1301. current_SC->SCp.phase = in_other;
  1302. outb( 0x90 | FIFO_COUNT, Interrupt_Cntl_port );
  1303. outb( 0x80, SCSI_Cntl_port );
  1304. #if DEBUG_RACE
  1305. in_interrupt_flag = 0;
  1306. #endif
  1307. return;
  1308. }
  1309.  
  1310. /* current_SC->SCp.phase == in_other: this is the body of the routine */
  1311.  
  1312. status = inb( SCSI_Status_port );
  1313.  
  1314. if (status & 0x10) { /* REQ */
  1315.  
  1316. switch (status & 0x0e) {
  1317.  
  1318. case 0x08: /* COMMAND OUT */
  1319. outb( current_SC->cmnd[current_SC->SCp.sent_command++],
  1320. Write_SCSI_Data_port );
  1321. #if EVERY_ACCESS
  1322. printk( "CMD = %x,",
  1323. current_SC->cmnd[ current_SC->SCp.sent_command - 1] );
  1324. #endif
  1325. break;
  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 );
  1330. }
  1331. break;
  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 );
  1336. }
  1337. break;
  1338. case 0x0c: /* STATUS IN */
  1339. current_SC->SCp.Status = inb( Read_SCSI_Data_port );
  1340. #if EVERY_ACCESS
  1341. printk( "Status = %x, ", current_SC->SCp.Status );
  1342. #endif
  1343. #if ERRORS_ONLY
  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",
  1348. current_SC->target,
  1349. current_SC->cmnd[0],
  1350. current_SC->SCp.Status );
  1351. }
  1352. #endif
  1353. break;
  1354. case 0x0a: /* MESSAGE OUT */
  1355. outb( MESSAGE_REJECT, Write_SCSI_Data_port ); /* Reject */
  1356. break;
  1357. case 0x0e: /* MESSAGE IN */
  1358. current_SC->SCp.Message = inb( Read_SCSI_Data_port );
  1359. #if EVERY_ACCESS
  1360. printk( "Message = %x, ", current_SC->SCp.Message );
  1361. #endif
  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 );
  1367. }
  1368. #endif
  1369. break;
  1370. }
  1371. }
  1372.  
  1373. if (chip == tmc1800
  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.
  1381. */
  1382. /*
  1383. p. 94: Command for all device types
  1384. CHANGE DEFINITION 40 DATA OUT
  1385. COMPARE 39 DATA OUT
  1386. COPY 18 DATA OUT
  1387. COPY AND VERIFY 3a DATA OUT
  1388. INQUIRY 12
  1389. LOG SELECT 4c DATA OUT
  1390. LOG SENSE 4d
  1391. MODE SELECT (6) 15 DATA OUT
  1392. MODE SELECT (10) 55 DATA OUT
  1393. MODE SENSE (6) 1a
  1394. MODE SENSE (10) 5a
  1395. READ BUFFER 3c
  1396. RECEIVE DIAGNOSTIC RESULTS 1c
  1397. REQUEST SENSE 03
  1398. SEND DIAGNOSTIC 1d DATA OUT
  1399. TEST UNIT READY 00
  1400. WRITE BUFFER 3b DATA OUT
  1401.  
  1402. p.178: Commands for direct-access devices (not listed on p. 94)
  1403. FORMAT UNIT 04 DATA OUT
  1404. LOCK-UNLOCK CACHE 36
  1405. PRE-FETCH 34
  1406. PREVENT-ALLOW MEDIUM REMOVAL 1e
  1407. READ (6)/RECEIVE 08
  1408. READ (10) 3c
  1409. READ CAPACITY 25
  1410. READ DEFECT DATA (10) 37
  1411. READ LONG 3e
  1412. REASSIGN BLOCKS 07 DATA OUT
  1413. RELEASE 17
  1414. RESERVE 16 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
  1419. SEEK (6) 0b
  1420. SEEK (10) 2b
  1421. SET LIMITS (10) 33
  1422. START STOP UNIT 1b
  1423. SYNCHRONIZE CACHE 35
  1424. VERIFY (10) 2f
  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 ?
  1430.  
  1431. p. 261: Commands for sequential-access devices (not previously listed)
  1432. ERASE 19
  1433. LOAD UNLOAD 1b
  1434. LOCATE 2b
  1435. READ BLOCK LIMITS 05
  1436. READ POSITION 34
  1437. READ REVERSE 0f
  1438. RECOVER BUFFERED DATA 14
  1439. SPACE 11
  1440. WRITE FILEMARKS 10 ?
  1441.  
  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
  1445. STOP PRINT 1b
  1446. SYNCHRONIZE BUFFER 10
  1447.  
  1448. p. 315: Commands for processor devices (not previously listed)
  1449.  
  1450. p. 321: Commands for write-once devices (not previously listed)
  1451. MEDIUM SCAN 38
  1452. READ (12) a8
  1453. SEARCH DATA EQUAL (12) b1 DATA OUT
  1454. SEARCH DATA HIGH (12) b0 DATA OUT
  1455. SEARCH DATA LOW (12) b2 DATA OUT
  1456. SET LIMITS (12) b3
  1457. VERIFY (12) af
  1458. WRITE (12) aa DATA OUT
  1459. WRITE AND VERIFY (12) ae DATA OUT
  1460.  
  1461. p. 332: Commands for CD-ROM devices (not previously listed)
  1462. PAUSE/RESUME 4b
  1463. PLAY AUDIO (10) 45
  1464. PLAY AUDIO (12) a5
  1465. PLAY AUDIO MSF 47
  1466. PLAY TRACK RELATIVE (10) 49
  1467. PLAY TRACK RELATIVE (12) a9
  1468. READ HEADER 44
  1469. READ SUB-CHANNEL 42
  1470. READ TOC 43
  1471.  
  1472. p. 370: Commands for scanner devices (not previously listed)
  1473. GET DATA BUFFER STATUS 34
  1474. GET WINDOW 25
  1475. OBJECT POSITION 31
  1476. SCAN 1b
  1477. SET WINDOW 24 DATA OUT
  1478.  
  1479. p. 391: Commands for optical memory devices (not listed)
  1480. ERASE (10) 2c
  1481. ERASE (12) ac
  1482. MEDIUM SCAN 38 DATA OUT
  1483. READ DEFECT DATA (12) b7
  1484. READ GENERATION 29
  1485. READ UPDATED BLOCK 2d
  1486. UPDATE BLOCK 3d DATA OUT
  1487.  
  1488. p. 419: Commands for medium changer devices (not listed)
  1489. EXCHANGE MEDIUM 46
  1490. INITIALIZE ELEMENT STATUS 07
  1491. MOVE MEDIUM a5
  1492. POSITION TO ELEMENT 2b
  1493. READ ELEMENT STATUS b8
  1494. REQUEST VOL. ELEMENT ADDRESS b5
  1495. SEND VOLUME TAG b6 DATA OUT
  1496.  
  1497. p. 454: Commands for communications devices (not listed previously)
  1498. GET MESSAGE (6) 08
  1499. GET MESSAGE (10) 28
  1500. GET MESSAGE (12) a8
  1501. */
  1502.  
  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:
  1507.  
  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:
  1512.  
  1513. case 0xb1: case 0xb0: case 0xb2:
  1514. case 0xaa: case 0xae:
  1515.  
  1516. case 0x24:
  1517.  
  1518. case 0x38: case 0x3d:
  1519.  
  1520. case 0xb6:
  1521.  
  1522. case 0xea: /* alternate number for WRITE LONG */
  1523.  
  1524. current_SC->SCp.have_data_in = -1;
  1525. outb( 0xd0 | PARITY_MASK, TMC_Cntl_port );
  1526. break;
  1527.  
  1528. case 0x00:
  1529. default:
  1530.  
  1531. current_SC->SCp.have_data_in = 1;
  1532. outb( 0x90 | PARITY_MASK, TMC_Cntl_port );
  1533. break;
  1534. }
  1535. }
  1536.  
  1537. if (current_SC->SCp.have_data_in == -1) { /* DATA OUT */
  1538. while ( (data_count = FIFO_Size - inw( FIFO_Data_Count_port )) > 512 ) {
  1539. #if EVERY_ACCESS
  1540. printk( "DC=%d, ", data_count ) ;
  1541. #endif
  1542. if (data_count > current_SC->SCp.this_residual)
  1543. data_count = current_SC->SCp.this_residual;
  1544. if (data_count > 0) {
  1545. #if EVERY_ACCESS
  1546. printk( "%d OUT, ", data_count );
  1547. #endif
  1548. if (data_count == 1) {
  1549. outb( *current_SC->SCp.ptr++, Write_FIFO_port );
  1550. --current_SC->SCp.this_residual;
  1551. } else {
  1552. data_count >>= 1;
  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;
  1556. }
  1557. }
  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;
  1564. } else
  1565. break;
  1566. }
  1567. }
  1568. }
  1569.  
  1570. if (current_SC->SCp.have_data_in == 1) { /* DATA IN */
  1571. while ((data_count = inw( FIFO_Data_Count_port )) > 0) {
  1572. #if EVERY_ACCESS
  1573. printk( "DC=%d, ", data_count );
  1574. #endif
  1575. if (data_count > current_SC->SCp.this_residual)
  1576. data_count = current_SC->SCp.this_residual;
  1577. if (data_count) {
  1578. #if EVERY_ACCESS
  1579. printk( "%d IN, ", data_count );
  1580. #endif
  1581. if (data_count == 1) {
  1582. *current_SC->SCp.ptr++ = inb( Read_FIFO_port );
  1583. --current_SC->SCp.this_residual;
  1584. } else {
  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;
  1589. }
  1590. }
  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;
  1597. }
  1598. }
  1599. }
  1600.  
  1601. if (done) {
  1602. #if EVERY_ACCESS
  1603. printk( " ** IN DONE %d ** ", current_SC->SCp.have_data_in );
  1604. #endif
  1605.  
  1606. #if ERRORS_ONLY
  1607. if (current_SC->cmnd[0] == REQUEST_SENSE && !current_SC->SCp.Status) {
  1608. if ((unsigned char)(*((char *)current_SC->request_buffer+2)) & 0x0f) {
  1609. unsigned char key;
  1610. unsigned char code;
  1611. unsigned char qualifier;
  1612.  
  1613. key = (unsigned char)(*((char *)current_SC->request_buffer + 2))
  1614. & 0x0f;
  1615. code = (unsigned char)(*((char *)current_SC->request_buffer + 12));
  1616. qualifier = (unsigned char)(*((char *)current_SC->request_buffer
  1617. + 13));
  1618.  
  1619. if (key != UNIT_ATTENTION
  1620. && !(key == NOT_READY
  1621. && code == 0x04
  1622. && (!qualifier || qualifier == 0x02 || qualifier == 0x01))
  1623. && !(key == ILLEGAL_REQUEST && (code == 0x25
  1624. || code == 0x24
  1625. || !code)))
  1626.  
  1627. printk( "scsi: <fdomain> REQUEST SENSE"
  1628. " Key = %x, Code = %x, Qualifier = %x\n",
  1629. key, code, qualifier );
  1630. }
  1631. }
  1632. #endif
  1633. #if EVERY_ACCESS
  1634. printk( "BEFORE MY_DONE. . ." );
  1635. #endif
  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);
  1640. #if EVERY_ACCESS
  1641. printk( "RETURNING.\n" );
  1642. #endif
  1643.  
  1644. } else {
  1645. if (current_SC->SCp.phase & disconnect) {
  1646. outb( 0xd0 | FIFO_COUNT, Interrupt_Cntl_port );
  1647. outb( 0x00, SCSI_Cntl_port );
  1648. } else {
  1649. outb( 0x90 | FIFO_COUNT, Interrupt_Cntl_port );
  1650. }
  1651. }
  1652. #if DEBUG_RACE
  1653. in_interrupt_flag = 0;
  1654. #endif
  1655. return;
  1656. }
  1657.  
  1658. int fdomain_16x0_queue( Scsi_Cmnd * SCpnt, void (*done)(Scsi_Cmnd *))
  1659. {
  1660. if (in_command) {
  1661. panic( "scsi: <fdomain> fdomain_16x0_queue() NOT REENTRANT!\n" );
  1662. }
  1663. #if EVERY_ACCESS
  1664. printk( "queue: target = %d cmnd = 0x%02x pieces = %d size = %u\n",
  1665. SCpnt->target,
  1666. *(unsigned char *)SCpnt->cmnd,
  1667. SCpnt->use_sg,
  1668. SCpnt->request_bufflen );
  1669. #endif
  1670.  
  1671. fdomain_make_bus_idle();
  1672.  
  1673. current_SC = SCpnt; /* Save this for the done function */
  1674. current_SC->scsi_done = done;
  1675.  
  1676. /* Initialize static data */
  1677.  
  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;
  1684. } else {
  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;
  1689. }
  1690.  
  1691.  
  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;
  1697.  
  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 */
  1702. ++in_command;
  1703. outb( 0x20, Interrupt_Cntl_port );
  1704. outb( 0x14 | PARITY_MASK, TMC_Cntl_port ); /* Start arbitration */
  1705.  
  1706. return 0;
  1707. }
  1708.  
  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. */
  1712.  
  1713. static volatile int internal_done_flag = 0;
  1714. static volatile int internal_done_errcode = 0;
  1715.  
  1716. static void internal_done( Scsi_Cmnd *SCpnt )
  1717. {
  1718. internal_done_errcode = SCpnt->result;
  1719. ++internal_done_flag;
  1720. }
  1721.  
  1722. int fdomain_16x0_command( Scsi_Cmnd *SCpnt )
  1723. {
  1724. fdomain_16x0_queue( SCpnt, internal_done );
  1725.  
  1726. while (!internal_done_flag)
  1727. ;
  1728. internal_done_flag = 0;
  1729. return internal_done_errcode;
  1730. }
  1731.  
  1732. /* End of code derived from Tommy Thorn's work. */
  1733.  
  1734. void print_info( Scsi_Cmnd *SCpnt )
  1735. {
  1736. unsigned int imr;
  1737. unsigned int irr;
  1738. unsigned int isr;
  1739.  
  1740. if (!SCpnt || !SCpnt->host) {
  1741. printk( "scsi: <fdomain> Cannot provide detailed information\n" );
  1742. return;
  1743. }
  1744.  
  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;
  1752. }
  1753.  
  1754. printk( "(%d), target = %d cmnd = 0x%02x pieces = %d size = %u\n",
  1755. SCpnt->SCp.phase,
  1756. SCpnt->target,
  1757. *(unsigned char *)SCpnt->cmnd,
  1758. SCpnt->use_sg,
  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,
  1763. SCpnt->timeout );
  1764. #if DEBUG_RACE
  1765. printk( "in_interrupt_flag = %d\n", in_interrupt_flag );
  1766. #endif
  1767.  
  1768. imr = (inb( 0x0a1 ) << 8) + inb( 0x21 );
  1769. outb( 0x0a, 0xa0 );
  1770. irr = inb( 0xa0 ) << 8;
  1771. outb( 0x0a, 0x20 );
  1772. irr += inb( 0x20 );
  1773. outb( 0x0b, 0xa0 );
  1774. isr = inb( 0xa0 ) << 8;
  1775. outb( 0x0b, 0x20 );
  1776. isr += inb( 0x20 );
  1777.  
  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 );
  1783.  
  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)" );
  1788. printk( "\n" );
  1789. printk( "Interrupt Status = 0x%02x", inb( Interrupt_Status_port ) );
  1790. if (inb( Interrupt_Status_port ) & 0x08)
  1791. printk( " (enabled)" );
  1792. printk( "\n" );
  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 ) );
  1797. }
  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 ) );
  1802. }
  1803.  
  1804. int fdomain_16x0_abort( Scsi_Cmnd *SCpnt)
  1805. {
  1806. unsigned long flags;
  1807. #if EVERY_ACCESS || ERRORS_ONLY || DEBUG_ABORT
  1808. printk( "scsi: <fdomain> abort " );
  1809. #endif
  1810.  
  1811. save_flags( flags );
  1812. cli();
  1813. if (!in_command) {
  1814. #if EVERY_ACCESS || ERRORS_ONLY
  1815. printk( " (not in command)\n" );
  1816. #endif
  1817. restore_flags( flags );
  1818. return SCSI_ABORT_NOT_RUNNING;
  1819. } else printk( "\n" );
  1820.  
  1821. #if DEBUG_ABORT
  1822. print_info( SCpnt );
  1823. #endif
  1824.  
  1825. fdomain_make_bus_idle();
  1826.  
  1827. current_SC->SCp.phase |= aborted;
  1828.  
  1829. current_SC->result = DID_ABORT << 16;
  1830.  
  1831. restore_flags( flags );
  1832.  
  1833. /* Aborts are not done well. . . */
  1834. my_done( DID_ABORT << 16 );
  1835.  
  1836. return SCSI_ABORT_SUCCESS;
  1837. }
  1838.  
  1839. int fdomain_16x0_reset( Scsi_Cmnd *SCpnt, unsigned int ignored )
  1840. {
  1841. #if DEBUG_RESET
  1842. static int called_once = 0;
  1843. #endif
  1844.  
  1845. #if ERRORS_ONLY
  1846. if (SCpnt) printk( "scsi: <fdomain> SCSI Bus Reset\n" );
  1847. #endif
  1848.  
  1849. #if DEBUG_RESET
  1850. if (called_once) print_info( current_SC );
  1851. called_once = 1;
  1852. #endif
  1853.  
  1854. outb( 1, SCSI_Cntl_port );
  1855. do_pause( 2 );
  1856. outb( 0, SCSI_Cntl_port );
  1857. do_pause( 115 );
  1858. outb( 0, SCSI_Mode_Cntl_port );
  1859. outb( PARITY_MASK, TMC_Cntl_port );
  1860.  
  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. */
  1864.  
  1865. return SCSI_RESET_WAKEUP;
  1866. }
  1867.  
  1868. #include "sd.h"
  1869. #include <scsi/scsi_ioctl.h>
  1870.  
  1871. int fdomain_16x0_biosparam( Scsi_Disk *disk, kdev_t dev, int *info_array )
  1872. {
  1873. int drive;
  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 };
  1879. int retcode;
  1880. unsigned long offset;
  1881. struct drive_info {
  1882. unsigned short cylinders;
  1883. unsigned char heads;
  1884. unsigned char sectors;
  1885. } i;
  1886.  
  1887. /* NOTES:
  1888. The RAM area starts at 0x1f00 from the bios_base address.
  1889.  
  1890. For BIOS Version 2.0:
  1891.  
  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
  1898. update these notes.
  1899.  
  1900. Tape drives do not get placed in this table.
  1901.  
  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).
  1907.  
  1908. 0x1f2d is a drive count (i.e., not including tapes)
  1909.  
  1910. The table at 0x1fcc are I/O ports addresses for the various
  1911. operations. I calculate these by hand in this driver code.
  1912.  
  1913.  
  1914.  
  1915. For the ISA-200S version of BIOS Version 2.0:
  1916.  
  1917. The drive parameter table starts at 0x1f33.
  1918.  
  1919. WARNING: Assume that the table entry is 25 bytes long. Someone needs
  1920. to check this for the Quantum ISA-200S card.
  1921.  
  1922.  
  1923.  
  1924. For BIOS Version 3.2:
  1925.  
  1926. The drive parameter table starts at 0x1f70. Each entry is
  1927. 0x0a bytes long. Heads are one less than we need to report.
  1928. */
  1929.  
  1930. if (MAJOR(dev) != SCSI_DISK0_MAJOR) {
  1931. printk("scsi: <fdomain> fdomain_16x0_biosparam: too many disks");
  1932. return 0;
  1933. }
  1934. drive = MINOR(dev) >> 4;
  1935.  
  1936. if (bios_major == 2) {
  1937. switch (Quantum) {
  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;
  1942. break;
  1943. case 3: /* ISA_250MG */
  1944. offset = bios_base + 0x1f36 + drive * 15;
  1945. break;
  1946. case 4: /* ISA_200S (another one) */
  1947. offset = bios_base + 0x1f34 + drive * 15;
  1948. break;
  1949. default:
  1950. offset = bios_base + 0x1f31 + drive * 25;
  1951. break;
  1952. }
  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
  1958. && bios_minor >= 0
  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!). */
  1967.  
  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,
  1973. sic );
  1974. if (!retcode /* SCSI command ok */
  1975. && data[511] == 0xaa && data[510] == 0x55 /* Partition table valid */
  1976. && data[0x1c2]) { /* Partition type */
  1977.  
  1978. /* The partition table layout is as follows:
  1979.  
  1980. Start: 0x1b3h
  1981. Offset: 0 = partition status
  1982. 1 = starting head
  1983. 2 = starting sector and cylinder (word, encoded)
  1984. 4 = partition type
  1985. 5 = ending head
  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
  1990.  
  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
  1995.  
  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.
  2002.  
  2003. Checking for
Add Comment
Please, Sign In to add comment