fdomain.c 56 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783
  1. /* fdomain.c -- Future Domain TMC-16x0 SCSI driver
  2. * Created: Sun May 3 18:53:19 1992 by faith@cs.unc.edu
  3. * Revised: Mon Dec 28 21:59:02 1998 by faith@acm.org
  4. * Author: Rickard E. Faith, faith@cs.unc.edu
  5. * Copyright 1992-1996, 1998 Rickard E. Faith (faith@acm.org)
  6. * Shared IRQ supported added 7/7/2001 Alan Cox <alan@lxorguk.ukuu.org.uk>
  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. * This program is distributed in the hope that it will be useful, but
  12. * WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * General Public License for more details.
  15. * You should have received a copy of the GNU General Public License along
  16. * with this program; if not, write to the Free Software Foundation, Inc.,
  17. * 675 Mass Ave, Cambridge, MA 02139, USA.
  18. **************************************************************************
  19. SUMMARY:
  20. Future Domain BIOS versions supported for autodetect:
  21. 2.0, 3.0, 3.2, 3.4 (1.0), 3.5 (2.0), 3.6, 3.61
  22. Chips are supported:
  23. TMC-1800, TMC-18C50, TMC-18C30, TMC-36C70
  24. Boards supported:
  25. Future Domain TMC-1650, TMC-1660, TMC-1670, TMC-1680, TMC-1610M/MER/MEX
  26. Future Domain TMC-3260 (PCI)
  27. Quantum ISA-200S, ISA-250MG
  28. Adaptec AHA-2920A (PCI) [BUT *NOT* AHA-2920C -- use aic7xxx instead]
  29. IBM ?
  30. LILO/INSMOD command-line options:
  31. fdomain=<PORT_BASE>,<IRQ>[,<ADAPTER_ID>]
  32. NOTE:
  33. The Adaptec AHA-2920C has an Adaptec AIC-7850 chip on it.
  34. Use the aic7xxx driver for this board.
  35. The Adaptec AHA-2920A has a Future Domain chip on it, so this is the right
  36. driver for that card. Unfortunately, the boxes will probably just say
  37. "2920", so you'll have to look on the card for a Future Domain logo, or a
  38. letter after the 2920.
  39. THANKS:
  40. Thanks to Adaptec for providing PCI boards for testing. This finally
  41. enabled me to test the PCI detection and correct it for PCI boards that do
  42. not have a BIOS at a standard ISA location. For PCI boards, LILO/INSMOD
  43. command-line options should no longer be needed. --RF 18Nov98
  44. DESCRIPTION:
  45. This is the Linux low-level SCSI driver for Future Domain TMC-1660/1680
  46. TMC-1650/1670, and TMC-3260 SCSI host adapters. The 1650 and 1670 have a
  47. 25-pin external connector, whereas the 1660 and 1680 have a SCSI-2 50-pin
  48. high-density external connector. The 1670 and 1680 have floppy disk
  49. controllers built in. The TMC-3260 is a PCI bus card.
  50. Future Domain's older boards are based on the TMC-1800 chip, and this
  51. driver was originally written for a TMC-1680 board with the TMC-1800 chip.
  52. More recently, boards are being produced with the TMC-18C50 and TMC-18C30
  53. chips. The latest and greatest board may not work with this driver. If
  54. you have to patch this driver so that it will recognize your board's BIOS
  55. signature, then the driver may fail to function after the board is
  56. detected.
  57. Please note that the drive ordering that Future Domain implemented in BIOS
  58. versions 3.4 and 3.5 is the opposite of the order (currently) used by the
  59. rest of the SCSI industry. If you have BIOS version 3.4 or 3.5, and have
  60. more than one drive, then the drive ordering will be the reverse of that
  61. which you see under DOS. For example, under DOS SCSI ID 0 will be D: and
  62. SCSI ID 1 will be C: (the boot device). Under Linux, SCSI ID 0 will be
  63. /dev/sda and SCSI ID 1 will be /dev/sdb. The Linux ordering is consistent
  64. with that provided by all the other SCSI drivers for Linux. If you want
  65. this changed, you will probably have to patch the higher level SCSI code.
  66. If you do so, please send me patches that are protected by #ifdefs.
  67. If you have a TMC-8xx or TMC-9xx board, then this is not the driver for
  68. your board. Please refer to the Seagate driver for more information and
  69. possible support.
  70. HISTORY:
  71. Linux Driver Driver
  72. Version Version Date Support/Notes
  73. 0.0 3 May 1992 V2.0 BIOS; 1800 chip
  74. 0.97 1.9 28 Jul 1992
  75. 0.98.6 3.1 27 Nov 1992
  76. 0.99 3.2 9 Dec 1992
  77. 0.99.3 3.3 10 Jan 1993 V3.0 BIOS
  78. 0.99.5 3.5 18 Feb 1993
  79. 0.99.10 3.6 15 May 1993 V3.2 BIOS; 18C50 chip
  80. 0.99.11 3.17 3 Jul 1993 (now under RCS)
  81. 0.99.12 3.18 13 Aug 1993
  82. 0.99.14 5.6 31 Oct 1993 (reselection code removed)
  83. 0.99.15 5.9 23 Jan 1994 V3.4 BIOS (preliminary)
  84. 1.0.8/1.1.1 5.15 1 Apr 1994 V3.4 BIOS; 18C30 chip (preliminary)
  85. 1.0.9/1.1.3 5.16 7 Apr 1994 V3.4 BIOS; 18C30 chip
  86. 1.1.38 5.18 30 Jul 1994 36C70 chip (PCI version of 18C30)
  87. 1.1.62 5.20 2 Nov 1994 V3.5 BIOS
  88. 1.1.73 5.22 7 Dec 1994 Quantum ISA-200S board; V2.0 BIOS
  89. 1.1.82 5.26 14 Jan 1995 V3.5 BIOS; TMC-1610M/MER/MEX board
  90. 1.2.10 5.28 5 Jun 1995 Quantum ISA-250MG board; V2.0, V2.01 BIOS
  91. 1.3.4 5.31 23 Jun 1995 PCI BIOS-32 detection (preliminary)
  92. 1.3.7 5.33 4 Jul 1995 PCI BIOS-32 detection
  93. 1.3.28 5.36 17 Sep 1995 V3.61 BIOS; LILO command-line support
  94. 1.3.34 5.39 12 Oct 1995 V3.60 BIOS; /proc
  95. 1.3.72 5.39 8 Feb 1996 Adaptec AHA-2920 board
  96. 1.3.85 5.41 4 Apr 1996
  97. 2.0.12 5.44 8 Aug 1996 Use ID 7 for all PCI cards
  98. 2.1.1 5.45 2 Oct 1996 Update ROM accesses for 2.1.x
  99. 2.1.97 5.46 23 Apr 1998 Rewritten PCI detection routines [mj]
  100. 2.1.11x 5.47 9 Aug 1998 Touched for 8 SCSI disk majors support
  101. 5.48 18 Nov 1998 BIOS no longer needed for PCI detection
  102. 2.2.0 5.50 28 Dec 1998 Support insmod parameters
  103. REFERENCES USED:
  104. "TMC-1800 SCSI Chip Specification (FDC-1800T)", Future Domain Corporation,
  105. 1990.
  106. "Technical Reference Manual: 18C50 SCSI Host Adapter Chip", Future Domain
  107. Corporation, January 1992.
  108. "LXT SCSI Products: Specifications and OEM Technical Manual (Revision
  109. B/September 1991)", Maxtor Corporation, 1991.
  110. "7213S product Manual (Revision P3)", Maxtor Corporation, 1992.
  111. "Draft Proposed American National Standard: Small Computer System
  112. Interface - 2 (SCSI-2)", Global Engineering Documents. (X3T9.2/86-109,
  113. revision 10h, October 17, 1991)
  114. Private communications, Drew Eckhardt (drew@cs.colorado.edu) and Eric
  115. Youngdale (ericy@cais.com), 1992.
  116. Private communication, Tuong Le (Future Domain Engineering department),
  117. 1994. (Disk geometry computations for Future Domain BIOS version 3.4, and
  118. TMC-18C30 detection.)
  119. Hogan, Thom. The Programmer's PC Sourcebook. Microsoft Press, 1988. Page
  120. 60 (2.39: Disk Partition Table Layout).
  121. "18C30 Technical Reference Manual", Future Domain Corporation, 1993, page
  122. 6-1.
  123. NOTES ON REFERENCES:
  124. The Maxtor manuals were free. Maxtor telephone technical support is
  125. great!
  126. The Future Domain manuals were $25 and $35. They document the chip, not
  127. the TMC-16x0 boards, so some information I had to guess at. In 1992,
  128. Future Domain sold DOS BIOS source for $250 and the UN*X driver source was
  129. $750, but these required a non-disclosure agreement, so even if I could
  130. have afforded them, they would *not* have been useful for writing this
  131. publicly distributable driver. Future Domain technical support has
  132. provided some information on the phone and have sent a few useful FAXs.
  133. They have been much more helpful since they started to recognize that the
  134. word "Linux" refers to an operating system :-).
  135. ALPHA TESTERS:
  136. There are many other alpha testers that come and go as the driver
  137. develops. The people listed here were most helpful in times of greatest
  138. need (mostly early on -- I've probably left out a few worthy people in
  139. more recent times):
  140. Todd Carrico (todd@wutc.wustl.edu), Dan Poirier (poirier@cs.unc.edu ), Ken
  141. Corey (kenc@sol.acs.unt.edu), C. de Bruin (bruin@bruin@sterbbs.nl), Sakari
  142. Aaltonen (sakaria@vipunen.hit.fi), John Rice (rice@xanth.cs.odu.edu), Brad
  143. Yearwood (brad@optilink.com), and Ray Toy (toy@soho.crd.ge.com).
  144. Special thanks to Tien-Wan Yang (twyang@cs.uh.edu), who graciously lent me
  145. his 18C50-based card for debugging. He is the sole reason that this
  146. driver works with the 18C50 chip.
  147. Thanks to Dave Newman (dnewman@crl.com) for providing initial patches for
  148. the version 3.4 BIOS.
  149. Thanks to James T. McKinley (mckinley@msupa.pa.msu.edu) for providing
  150. patches that support the TMC-3260, a PCI bus card with the 36C70 chip.
  151. The 36C70 chip appears to be "completely compatible" with the 18C30 chip.
  152. Thanks to Eric Kasten (tigger@petroglyph.cl.msu.edu) for providing the
  153. patch for the version 3.5 BIOS.
  154. Thanks for Stephen Henson (shenson@nyx10.cs.du.edu) for providing the
  155. patch for the Quantum ISA-200S SCSI adapter.
  156. Thanks to Adam Bowen for the signature to the 1610M/MER/MEX scsi cards, to
  157. Martin Andrews (andrewm@ccfadm.eeg.ccf.org) for the signature to some
  158. random TMC-1680 repackaged by IBM; and to Mintak Ng (mintak@panix.com) for
  159. the version 3.61 BIOS signature.
  160. Thanks for Mark Singer (elf@netcom.com) and Richard Simpson
  161. (rsimpson@ewrcsdra.demon.co.uk) for more Quantum signatures and detective
  162. work on the Quantum RAM layout.
  163. Special thanks to James T. McKinley (mckinley@msupa.pa.msu.edu) for
  164. providing patches for proper PCI BIOS32-mediated detection of the TMC-3260
  165. card (a PCI bus card with the 36C70 chip). Please send James PCI-related
  166. bug reports.
  167. Thanks to Tom Cavin (tec@usa1.com) for preliminary command-line option
  168. patches.
  169. New PCI detection code written by Martin Mares <mj@atrey.karlin.mff.cuni.cz>
  170. Insmod parameter code based on patches from Daniel Graham
  171. <graham@balance.uoregon.edu>.
  172. All of the alpha testers deserve much thanks.
  173. NOTES ON USER DEFINABLE OPTIONS:
  174. DEBUG: This turns on the printing of various debug information.
  175. ENABLE_PARITY: This turns on SCSI parity checking. With the current
  176. driver, all attached devices must support SCSI parity. If none of your
  177. devices support parity, then you can probably get the driver to work by
  178. turning this option off. I have no way of testing this, however, and it
  179. would appear that no one ever uses this option.
  180. FIFO_COUNT: The host adapter has an 8K cache (host adapters based on the
  181. 18C30 chip have a 2k cache). When this many 512 byte blocks are filled by
  182. the SCSI device, an interrupt will be raised. Therefore, this could be as
  183. low as 0, or as high as 16. Note, however, that values which are too high
  184. or too low seem to prevent any interrupts from occurring, and thereby lock
  185. up the machine. I have found that 2 is a good number, but throughput may
  186. be increased by changing this value to values which are close to 2.
  187. Please let me know if you try any different values.
  188. RESELECTION: This is no longer an option, since I gave up trying to
  189. implement it in version 4.x of this driver. It did not improve
  190. performance at all and made the driver unstable (because I never found one
  191. of the two race conditions which were introduced by the multiple
  192. outstanding command code). The instability seems a very high price to pay
  193. just so that you don't have to wait for the tape to rewind. If you want
  194. this feature implemented, send me patches. I'll be happy to send a copy
  195. of my (broken) driver to anyone who would like to see a copy.
  196. **************************************************************************/
  197. #include <linux/module.h>
  198. #include <linux/init.h>
  199. #include <linux/interrupt.h>
  200. #include <linux/blkdev.h>
  201. #include <linux/spinlock.h>
  202. #include <linux/errno.h>
  203. #include <linux/string.h>
  204. #include <linux/ioport.h>
  205. #include <linux/proc_fs.h>
  206. #include <linux/pci.h>
  207. #include <linux/stat.h>
  208. #include <linux/delay.h>
  209. #include <linux/io.h>
  210. #include <linux/slab.h>
  211. #include <scsi/scsicam.h>
  212. #include <scsi/scsi.h>
  213. #include <scsi/scsi_cmnd.h>
  214. #include <scsi/scsi_device.h>
  215. #include <scsi/scsi_host.h>
  216. #include <scsi/scsi_ioctl.h>
  217. #include "fdomain.h"
  218. #ifndef PCMCIA
  219. MODULE_AUTHOR("Rickard E. Faith");
  220. MODULE_DESCRIPTION("Future domain SCSI driver");
  221. MODULE_LICENSE("GPL");
  222. #endif
  223. #define VERSION "$Revision: 5.51 $"
  224. /* START OF USER DEFINABLE OPTIONS */
  225. #define DEBUG 0 /* Enable debugging output */
  226. #define ENABLE_PARITY 1 /* Enable SCSI Parity */
  227. #define FIFO_COUNT 2 /* Number of 512 byte blocks before INTR */
  228. /* END OF USER DEFINABLE OPTIONS */
  229. #if DEBUG
  230. #define EVERY_ACCESS 0 /* Write a line on every scsi access */
  231. #define ERRORS_ONLY 1 /* Only write a line if there is an error */
  232. #define DEBUG_DETECT 0 /* Debug fdomain_16x0_detect() */
  233. #define DEBUG_MESSAGES 1 /* Debug MESSAGE IN phase */
  234. #define DEBUG_ABORT 1 /* Debug abort() routine */
  235. #define DEBUG_RESET 1 /* Debug reset() routine */
  236. #define DEBUG_RACE 1 /* Debug interrupt-driven race condition */
  237. #else
  238. #define EVERY_ACCESS 0 /* LEAVE THESE ALONE--CHANGE THE ONES ABOVE */
  239. #define ERRORS_ONLY 0
  240. #define DEBUG_DETECT 0
  241. #define DEBUG_MESSAGES 0
  242. #define DEBUG_ABORT 0
  243. #define DEBUG_RESET 0
  244. #define DEBUG_RACE 0
  245. #endif
  246. /* Errors are reported on the line, so we don't need to report them again */
  247. #if EVERY_ACCESS
  248. #undef ERRORS_ONLY
  249. #define ERRORS_ONLY 0
  250. #endif
  251. #if ENABLE_PARITY
  252. #define PARITY_MASK 0x08
  253. #else
  254. #define PARITY_MASK 0x00
  255. #endif
  256. enum chip_type {
  257. unknown = 0x00,
  258. tmc1800 = 0x01,
  259. tmc18c50 = 0x02,
  260. tmc18c30 = 0x03,
  261. };
  262. enum {
  263. in_arbitration = 0x02,
  264. in_selection = 0x04,
  265. in_other = 0x08,
  266. disconnect = 0x10,
  267. aborted = 0x20,
  268. sent_ident = 0x40,
  269. };
  270. enum in_port_type {
  271. Read_SCSI_Data = 0,
  272. SCSI_Status = 1,
  273. TMC_Status = 2,
  274. FIFO_Status = 3, /* tmc18c50/tmc18c30 only */
  275. Interrupt_Cond = 4, /* tmc18c50/tmc18c30 only */
  276. LSB_ID_Code = 5,
  277. MSB_ID_Code = 6,
  278. Read_Loopback = 7,
  279. SCSI_Data_NoACK = 8,
  280. Interrupt_Status = 9,
  281. Configuration1 = 10,
  282. Configuration2 = 11, /* tmc18c50/tmc18c30 only */
  283. Read_FIFO = 12,
  284. FIFO_Data_Count = 14
  285. };
  286. enum out_port_type {
  287. Write_SCSI_Data = 0,
  288. SCSI_Cntl = 1,
  289. Interrupt_Cntl = 2,
  290. SCSI_Mode_Cntl = 3,
  291. TMC_Cntl = 4,
  292. Memory_Cntl = 5, /* tmc18c50/tmc18c30 only */
  293. Write_Loopback = 7,
  294. IO_Control = 11, /* tmc18c30 only */
  295. Write_FIFO = 12
  296. };
  297. /* .bss will zero all the static variables below */
  298. static int port_base;
  299. static unsigned long bios_base;
  300. static void __iomem * bios_mem;
  301. static int bios_major;
  302. static int bios_minor;
  303. static int PCI_bus;
  304. #ifdef CONFIG_PCI
  305. static struct pci_dev *PCI_dev;
  306. #endif
  307. static int Quantum; /* Quantum board variant */
  308. static int interrupt_level;
  309. static volatile int in_command;
  310. static struct scsi_cmnd *current_SC;
  311. static enum chip_type chip = unknown;
  312. static int adapter_mask;
  313. static int this_id;
  314. static int setup_called;
  315. #if DEBUG_RACE
  316. static volatile int in_interrupt_flag;
  317. #endif
  318. static int FIFO_Size = 0x2000; /* 8k FIFO for
  319. pre-tmc18c30 chips */
  320. static irqreturn_t do_fdomain_16x0_intr( int irq, void *dev_id );
  321. /* Allow insmod parameters to be like LILO parameters. For example:
  322. insmod fdomain fdomain=0x140,11 */
  323. static char * fdomain = NULL;
  324. module_param(fdomain, charp, 0);
  325. #ifndef PCMCIA
  326. static unsigned long addresses[] = {
  327. 0xc8000,
  328. 0xca000,
  329. 0xce000,
  330. 0xde000,
  331. 0xcc000, /* Extra addresses for PCI boards */
  332. 0xd0000,
  333. 0xe0000,
  334. };
  335. #define ADDRESS_COUNT ARRAY_SIZE(addresses)
  336. static unsigned short ports[] = { 0x140, 0x150, 0x160, 0x170 };
  337. #define PORT_COUNT ARRAY_SIZE(ports)
  338. static unsigned short ints[] = { 3, 5, 10, 11, 12, 14, 15, 0 };
  339. #endif /* !PCMCIA */
  340. /*
  341. READ THIS BEFORE YOU ADD A SIGNATURE!
  342. READING THIS SHORT NOTE CAN SAVE YOU LOTS OF TIME!
  343. READ EVERY WORD, ESPECIALLY THE WORD *NOT*
  344. This driver works *ONLY* for Future Domain cards using the TMC-1800,
  345. TMC-18C50, or TMC-18C30 chip. This includes models TMC-1650, 1660, 1670,
  346. and 1680. These are all 16-bit cards.
  347. The following BIOS signature signatures are for boards which do *NOT*
  348. work with this driver (these TMC-8xx and TMC-9xx boards may work with the
  349. Seagate driver):
  350. FUTURE DOMAIN CORP. (C) 1986-1988 V4.0I 03/16/88
  351. FUTURE DOMAIN CORP. (C) 1986-1989 V5.0C2/14/89
  352. FUTURE DOMAIN CORP. (C) 1986-1989 V6.0A7/28/89
  353. FUTURE DOMAIN CORP. (C) 1986-1990 V6.0105/31/90
  354. FUTURE DOMAIN CORP. (C) 1986-1990 V6.0209/18/90
  355. FUTURE DOMAIN CORP. (C) 1986-1990 V7.009/18/90
  356. FUTURE DOMAIN CORP. (C) 1992 V8.00.004/02/92
  357. (The cards which do *NOT* work are all 8-bit cards -- although some of
  358. them have a 16-bit form-factor, the upper 8-bits are used only for IRQs
  359. and are *NOT* used for data. You can tell the difference by following
  360. the tracings on the circuit board -- if only the IRQ lines are involved,
  361. you have a "8-bit" card, and should *NOT* use this driver.)
  362. */
  363. #ifndef PCMCIA
  364. static struct signature {
  365. const char *signature;
  366. int sig_offset;
  367. int sig_length;
  368. int major_bios_version;
  369. int minor_bios_version;
  370. int flag; /* 1 == PCI_bus, 2 == ISA_200S, 3 == ISA_250MG, 4 == ISA_200S */
  371. } signatures[] = {
  372. /* 1 2 3 4 5 6 */
  373. /* 123456789012345678901234567890123456789012345678901234567890 */
  374. { "FUTURE DOMAIN CORP. (C) 1986-1990 1800-V2.07/28/89", 5, 50, 2, 0, 0 },
  375. { "FUTURE DOMAIN CORP. (C) 1986-1990 1800-V1.07/28/89", 5, 50, 2, 0, 0 },
  376. { "FUTURE DOMAIN CORP. (C) 1986-1990 1800-V2.07/28/89", 72, 50, 2, 0, 2 },
  377. { "FUTURE DOMAIN CORP. (C) 1986-1990 1800-V2.0", 73, 43, 2, 0, 3 },
  378. { "FUTURE DOMAIN CORP. (C) 1991 1800-V2.0.", 72, 39, 2, 0, 4 },
  379. { "FUTURE DOMAIN CORP. (C) 1992 V3.00.004/02/92", 5, 44, 3, 0, 0 },
  380. { "FUTURE DOMAIN TMC-18XX (C) 1993 V3.203/12/93", 5, 44, 3, 2, 0 },
  381. { "IBM F1 P2 BIOS v1.0104/29/93", 5, 28, 3, -1, 0 },
  382. { "Future Domain Corp. V1.0008/18/93", 5, 33, 3, 4, 0 },
  383. { "Future Domain Corp. V1.0008/18/93", 26, 33, 3, 4, 1 },
  384. { "Adaptec AHA-2920 PCI-SCSI Card", 42, 31, 3, -1, 1 },
  385. { "IBM F1 P264/32", 5, 14, 3, -1, 1 },
  386. /* This next signature may not be a 3.5 bios */
  387. { "Future Domain Corp. V2.0108/18/93", 5, 33, 3, 5, 0 },
  388. { "FUTURE DOMAIN CORP. V3.5008/18/93", 5, 34, 3, 5, 0 },
  389. { "FUTURE DOMAIN 18c30/18c50/1800 (C) 1994 V3.5", 5, 44, 3, 5, 0 },
  390. { "FUTURE DOMAIN CORP. V3.6008/18/93", 5, 34, 3, 6, 0 },
  391. { "FUTURE DOMAIN CORP. V3.6108/18/93", 5, 34, 3, 6, 0 },
  392. { "FUTURE DOMAIN TMC-18XX", 5, 22, -1, -1, 0 },
  393. /* READ NOTICE ABOVE *BEFORE* YOU WASTE YOUR TIME ADDING A SIGNATURE
  394. Also, fix the disk geometry code for your signature and send your
  395. changes for faith@cs.unc.edu. Above all, do *NOT* change any old
  396. signatures!
  397. Note that the last line will match a "generic" 18XX bios. Because
  398. Future Domain has changed the host SCSI ID and/or the location of the
  399. geometry information in the on-board RAM area for each of the first
  400. three BIOS's, it is still important to enter a fully qualified
  401. signature in the table for any new BIOS's (after the host SCSI ID and
  402. geometry location are verified). */
  403. };
  404. #define SIGNATURE_COUNT ARRAY_SIZE(signatures)
  405. #endif /* !PCMCIA */
  406. static void print_banner( struct Scsi_Host *shpnt )
  407. {
  408. if (!shpnt) return; /* This won't ever happen */
  409. if (bios_major < 0 && bios_minor < 0) {
  410. printk(KERN_INFO "scsi%d: <fdomain> No BIOS; using scsi id %d\n",
  411. shpnt->host_no, shpnt->this_id);
  412. } else {
  413. printk(KERN_INFO "scsi%d: <fdomain> BIOS version ", shpnt->host_no);
  414. if (bios_major >= 0) printk("%d.", bios_major);
  415. else printk("?.");
  416. if (bios_minor >= 0) printk("%d", bios_minor);
  417. else printk("?.");
  418. printk( " at 0x%lx using scsi id %d\n",
  419. bios_base, shpnt->this_id );
  420. }
  421. /* If this driver works for later FD PCI
  422. boards, we will have to modify banner
  423. for additional PCI cards, but for now if
  424. it's PCI it's a TMC-3260 - JTM */
  425. printk(KERN_INFO "scsi%d: <fdomain> %s chip at 0x%x irq ",
  426. shpnt->host_no,
  427. chip == tmc1800 ? "TMC-1800" : (chip == tmc18c50 ? "TMC-18C50" : (chip == tmc18c30 ? (PCI_bus ? "TMC-36C70 (PCI bus)" : "TMC-18C30") : "Unknown")),
  428. port_base);
  429. if (interrupt_level)
  430. printk("%d", interrupt_level);
  431. else
  432. printk("<none>");
  433. printk( "\n" );
  434. }
  435. int fdomain_setup(char *str)
  436. {
  437. int ints[4];
  438. (void)get_options(str, ARRAY_SIZE(ints), ints);
  439. if (setup_called++ || ints[0] < 2 || ints[0] > 3) {
  440. printk(KERN_INFO "scsi: <fdomain> Usage: fdomain=<PORT_BASE>,<IRQ>[,<ADAPTER_ID>]\n");
  441. printk(KERN_ERR "scsi: <fdomain> Bad LILO/INSMOD parameters?\n");
  442. return 0;
  443. }
  444. port_base = ints[0] >= 1 ? ints[1] : 0;
  445. interrupt_level = ints[0] >= 2 ? ints[2] : 0;
  446. this_id = ints[0] >= 3 ? ints[3] : 0;
  447. bios_major = bios_minor = -1; /* Use geometry for BIOS version >= 3.4 */
  448. ++setup_called;
  449. return 1;
  450. }
  451. __setup("fdomain=", fdomain_setup);
  452. static void do_pause(unsigned amount) /* Pause for amount*10 milliseconds */
  453. {
  454. mdelay(10*amount);
  455. }
  456. static inline void fdomain_make_bus_idle( void )
  457. {
  458. outb(0, port_base + SCSI_Cntl);
  459. outb(0, port_base + SCSI_Mode_Cntl);
  460. if (chip == tmc18c50 || chip == tmc18c30)
  461. outb(0x21 | PARITY_MASK, port_base + TMC_Cntl); /* Clear forced intr. */
  462. else
  463. outb(0x01 | PARITY_MASK, port_base + TMC_Cntl);
  464. }
  465. static int fdomain_is_valid_port( int port )
  466. {
  467. #if DEBUG_DETECT
  468. printk( " (%x%x),",
  469. inb( port + MSB_ID_Code ), inb( port + LSB_ID_Code ) );
  470. #endif
  471. /* The MCA ID is a unique id for each MCA compatible board. We
  472. are using ISA boards, but Future Domain provides the MCA ID
  473. anyway. We can use this ID to ensure that this is a Future
  474. Domain TMC-1660/TMC-1680.
  475. */
  476. if (inb( port + LSB_ID_Code ) != 0xe9) { /* test for 0x6127 id */
  477. if (inb( port + LSB_ID_Code ) != 0x27) return 0;
  478. if (inb( port + MSB_ID_Code ) != 0x61) return 0;
  479. chip = tmc1800;
  480. } else { /* test for 0xe960 id */
  481. if (inb( port + MSB_ID_Code ) != 0x60) return 0;
  482. chip = tmc18c50;
  483. /* Try to toggle 32-bit mode. This only
  484. works on an 18c30 chip. (User reports
  485. say this works, so we should switch to
  486. it in the near future.) */
  487. outb( 0x80, port + IO_Control );
  488. if ((inb( port + Configuration2 ) & 0x80) == 0x80) {
  489. outb( 0x00, port + IO_Control );
  490. if ((inb( port + Configuration2 ) & 0x80) == 0x00) {
  491. chip = tmc18c30;
  492. FIFO_Size = 0x800; /* 2k FIFO */
  493. }
  494. }
  495. /* If that failed, we are an 18c50. */
  496. }
  497. return 1;
  498. }
  499. static int fdomain_test_loopback( void )
  500. {
  501. int i;
  502. int result;
  503. for (i = 0; i < 255; i++) {
  504. outb( i, port_base + Write_Loopback );
  505. result = inb( port_base + Read_Loopback );
  506. if (i != result)
  507. return 1;
  508. }
  509. return 0;
  510. }
  511. #ifndef PCMCIA
  512. /* fdomain_get_irq assumes that we have a valid MCA ID for a
  513. TMC-1660/TMC-1680 Future Domain board. Now, check to be sure the
  514. bios_base matches these ports. If someone was unlucky enough to have
  515. purchased more than one Future Domain board, then they will have to
  516. modify this code, as we only detect one board here. [The one with the
  517. lowest bios_base.]
  518. Note that this routine is only used for systems without a PCI BIOS32
  519. (e.g., ISA bus). For PCI bus systems, this routine will likely fail
  520. unless one of the IRQs listed in the ints array is used by the board.
  521. Sometimes it is possible to use the computer's BIOS setup screen to
  522. configure a PCI system so that one of these IRQs will be used by the
  523. Future Domain card. */
  524. static int fdomain_get_irq( int base )
  525. {
  526. int options = inb(base + Configuration1);
  527. #if DEBUG_DETECT
  528. printk("scsi: <fdomain> Options = %x\n", options);
  529. #endif
  530. /* Check for board with lowest bios_base --
  531. this isn't valid for the 18c30 or for
  532. boards on the PCI bus, so just assume we
  533. have the right board. */
  534. if (chip != tmc18c30 && !PCI_bus && addresses[(options & 0xc0) >> 6 ] != bios_base)
  535. return 0;
  536. return ints[(options & 0x0e) >> 1];
  537. }
  538. static int fdomain_isa_detect( int *irq, int *iobase )
  539. {
  540. int i, j;
  541. int base = 0xdeadbeef;
  542. int flag = 0;
  543. #if DEBUG_DETECT
  544. printk( "scsi: <fdomain> fdomain_isa_detect:" );
  545. #endif
  546. for (i = 0; i < ADDRESS_COUNT; i++) {
  547. void __iomem *p = ioremap(addresses[i], 0x2000);
  548. if (!p)
  549. continue;
  550. #if DEBUG_DETECT
  551. printk( " %lx(%lx),", addresses[i], bios_base );
  552. #endif
  553. for (j = 0; j < SIGNATURE_COUNT; j++) {
  554. if (check_signature(p + signatures[j].sig_offset,
  555. signatures[j].signature,
  556. signatures[j].sig_length )) {
  557. bios_major = signatures[j].major_bios_version;
  558. bios_minor = signatures[j].minor_bios_version;
  559. PCI_bus = (signatures[j].flag == 1);
  560. Quantum = (signatures[j].flag > 1) ? signatures[j].flag : 0;
  561. bios_base = addresses[i];
  562. bios_mem = p;
  563. goto found;
  564. }
  565. }
  566. iounmap(p);
  567. }
  568. found:
  569. if (bios_major == 2) {
  570. /* The TMC-1660/TMC-1680 has a RAM area just after the BIOS ROM.
  571. Assuming the ROM is enabled (otherwise we wouldn't have been
  572. able to read the ROM signature :-), then the ROM sets up the
  573. RAM area with some magic numbers, such as a list of port
  574. base addresses and a list of the disk "geometry" reported to
  575. DOS (this geometry has nothing to do with physical geometry).
  576. */
  577. switch (Quantum) {
  578. case 2: /* ISA_200S */
  579. case 3: /* ISA_250MG */
  580. base = readb(bios_mem + 0x1fa2) + (readb(bios_mem + 0x1fa3) << 8);
  581. break;
  582. case 4: /* ISA_200S (another one) */
  583. base = readb(bios_mem + 0x1fa3) + (readb(bios_mem + 0x1fa4) << 8);
  584. break;
  585. default:
  586. base = readb(bios_mem + 0x1fcc) + (readb(bios_mem + 0x1fcd) << 8);
  587. break;
  588. }
  589. #if DEBUG_DETECT
  590. printk( " %x,", base );
  591. #endif
  592. for (i = 0; i < PORT_COUNT; i++) {
  593. if (base == ports[i]) {
  594. if (!request_region(base, 0x10, "fdomain"))
  595. break;
  596. if (!fdomain_is_valid_port(base)) {
  597. release_region(base, 0x10);
  598. break;
  599. }
  600. *irq = fdomain_get_irq( base );
  601. *iobase = base;
  602. return 1;
  603. }
  604. }
  605. /* This is a bad sign. It usually means that someone patched the
  606. BIOS signature list (the signatures variable) to contain a BIOS
  607. signature for a board *OTHER THAN* the TMC-1660/TMC-1680. */
  608. #if DEBUG_DETECT
  609. printk( " RAM FAILED, " );
  610. #endif
  611. }
  612. /* Anyway, the alternative to finding the address in the RAM is to just
  613. search through every possible port address for one that is attached
  614. to the Future Domain card. Don't panic, though, about reading all
  615. these random port addresses -- there are rumors that the Future
  616. Domain BIOS does something very similar.
  617. Do not, however, check ports which the kernel knows are being used by
  618. another driver. */
  619. for (i = 0; i < PORT_COUNT; i++) {
  620. base = ports[i];
  621. if (!request_region(base, 0x10, "fdomain")) {
  622. #if DEBUG_DETECT
  623. printk( " (%x inuse),", base );
  624. #endif
  625. continue;
  626. }
  627. #if DEBUG_DETECT
  628. printk( " %x,", base );
  629. #endif
  630. flag = fdomain_is_valid_port(base);
  631. if (flag)
  632. break;
  633. release_region(base, 0x10);
  634. }
  635. #if DEBUG_DETECT
  636. if (flag) printk( " SUCCESS\n" );
  637. else printk( " FAILURE\n" );
  638. #endif
  639. if (!flag) return 0; /* iobase not found */
  640. *irq = fdomain_get_irq( base );
  641. *iobase = base;
  642. return 1; /* success */
  643. }
  644. #else /* PCMCIA */
  645. static int fdomain_isa_detect( int *irq, int *iobase )
  646. {
  647. if (irq)
  648. *irq = 0;
  649. if (iobase)
  650. *iobase = 0;
  651. return 0;
  652. }
  653. #endif /* !PCMCIA */
  654. /* PCI detection function: int fdomain_pci_bios_detect(int* irq, int*
  655. iobase) This function gets the Interrupt Level and I/O base address from
  656. the PCI configuration registers. */
  657. #ifdef CONFIG_PCI
  658. static int fdomain_pci_bios_detect( int *irq, int *iobase, struct pci_dev **ret_pdev )
  659. {
  660. unsigned int pci_irq; /* PCI interrupt line */
  661. unsigned long pci_base; /* PCI I/O base address */
  662. struct pci_dev *pdev = NULL;
  663. #if DEBUG_DETECT
  664. /* Tell how to print a list of the known PCI devices from bios32 and
  665. list vendor and device IDs being used if in debug mode. */
  666. printk( "scsi: <fdomain> INFO: use lspci -v to see list of PCI devices\n" );
  667. printk( "scsi: <fdomain> TMC-3260 detect:"
  668. " Using Vendor ID: 0x%x and Device ID: 0x%x\n",
  669. PCI_VENDOR_ID_FD,
  670. PCI_DEVICE_ID_FD_36C70 );
  671. #endif
  672. if ((pdev = pci_get_device(PCI_VENDOR_ID_FD, PCI_DEVICE_ID_FD_36C70, pdev)) == NULL)
  673. return 0;
  674. if (pci_enable_device(pdev))
  675. goto fail;
  676. #if DEBUG_DETECT
  677. printk( "scsi: <fdomain> TMC-3260 detect:"
  678. " PCI bus %u, device %u, function %u\n",
  679. pdev->bus->number,
  680. PCI_SLOT(pdev->devfn),
  681. PCI_FUNC(pdev->devfn));
  682. #endif
  683. /* We now have the appropriate device function for the FD board so we
  684. just read the PCI config info from the registers. */
  685. pci_base = pci_resource_start(pdev, 0);
  686. pci_irq = pdev->irq;
  687. if (!request_region( pci_base, 0x10, "fdomain" ))
  688. goto fail;
  689. /* Now we have the I/O base address and interrupt from the PCI
  690. configuration registers. */
  691. *irq = pci_irq;
  692. *iobase = pci_base;
  693. *ret_pdev = pdev;
  694. #if DEBUG_DETECT
  695. printk( "scsi: <fdomain> TMC-3260 detect:"
  696. " IRQ = %d, I/O base = 0x%x [0x%lx]\n", *irq, *iobase, pci_base );
  697. #endif
  698. if (!fdomain_is_valid_port(pci_base)) {
  699. printk(KERN_ERR "scsi: <fdomain> PCI card detected, but driver not loaded (invalid port)\n" );
  700. release_region(pci_base, 0x10);
  701. goto fail;
  702. }
  703. /* Fill in a few global variables. Ugh. */
  704. bios_major = bios_minor = -1;
  705. PCI_bus = 1;
  706. PCI_dev = pdev;
  707. Quantum = 0;
  708. bios_base = 0;
  709. return 1;
  710. fail:
  711. pci_dev_put(pdev);
  712. return 0;
  713. }
  714. #endif
  715. struct Scsi_Host *__fdomain_16x0_detect(struct scsi_host_template *tpnt )
  716. {
  717. int retcode;
  718. struct Scsi_Host *shpnt;
  719. struct pci_dev *pdev = NULL;
  720. if (setup_called) {
  721. #if DEBUG_DETECT
  722. printk( "scsi: <fdomain> No BIOS, using port_base = 0x%x, irq = %d\n",
  723. port_base, interrupt_level );
  724. #endif
  725. if (!request_region(port_base, 0x10, "fdomain")) {
  726. printk( "scsi: <fdomain> port 0x%x is busy\n", port_base );
  727. printk( "scsi: <fdomain> Bad LILO/INSMOD parameters?\n" );
  728. return NULL;
  729. }
  730. if (!fdomain_is_valid_port( port_base )) {
  731. printk( "scsi: <fdomain> Cannot locate chip at port base 0x%x\n",
  732. port_base );
  733. printk( "scsi: <fdomain> Bad LILO/INSMOD parameters?\n" );
  734. release_region(port_base, 0x10);
  735. return NULL;
  736. }
  737. } else {
  738. int flag = 0;
  739. #ifdef CONFIG_PCI
  740. /* Try PCI detection first */
  741. flag = fdomain_pci_bios_detect( &interrupt_level, &port_base, &pdev );
  742. #endif
  743. if (!flag) {
  744. /* Then try ISA bus detection */
  745. flag = fdomain_isa_detect( &interrupt_level, &port_base );
  746. if (!flag) {
  747. printk( "scsi: <fdomain> Detection failed (no card)\n" );
  748. return NULL;
  749. }
  750. }
  751. }
  752. fdomain_16x0_bus_reset(NULL);
  753. if (fdomain_test_loopback()) {
  754. printk(KERN_ERR "scsi: <fdomain> Detection failed (loopback test failed at port base 0x%x)\n", port_base);
  755. if (setup_called) {
  756. printk(KERN_ERR "scsi: <fdomain> Bad LILO/INSMOD parameters?\n");
  757. }
  758. goto fail;
  759. }
  760. if (this_id) {
  761. tpnt->this_id = (this_id & 0x07);
  762. adapter_mask = (1 << tpnt->this_id);
  763. } else {
  764. if (PCI_bus || (bios_major == 3 && bios_minor >= 2) || bios_major < 0) {
  765. tpnt->this_id = 7;
  766. adapter_mask = 0x80;
  767. } else {
  768. tpnt->this_id = 6;
  769. adapter_mask = 0x40;
  770. }
  771. }
  772. /* Print out a banner here in case we can't
  773. get resources. */
  774. shpnt = scsi_register( tpnt, 0 );
  775. if(shpnt == NULL) {
  776. release_region(port_base, 0x10);
  777. return NULL;
  778. }
  779. shpnt->irq = interrupt_level;
  780. shpnt->io_port = port_base;
  781. shpnt->n_io_port = 0x10;
  782. print_banner( shpnt );
  783. /* Log IRQ with kernel */
  784. if (!interrupt_level) {
  785. printk(KERN_ERR "scsi: <fdomain> Card Detected, but driver not loaded (no IRQ)\n" );
  786. goto fail;
  787. } else {
  788. /* Register the IRQ with the kernel */
  789. retcode = request_irq( interrupt_level,
  790. do_fdomain_16x0_intr, pdev?IRQF_SHARED:0, "fdomain", shpnt);
  791. if (retcode < 0) {
  792. if (retcode == -EINVAL) {
  793. printk(KERN_ERR "scsi: <fdomain> IRQ %d is bad!\n", interrupt_level );
  794. printk(KERN_ERR " This shouldn't happen!\n" );
  795. printk(KERN_ERR " Send mail to faith@acm.org\n" );
  796. } else if (retcode == -EBUSY) {
  797. printk(KERN_ERR "scsi: <fdomain> IRQ %d is already in use!\n", interrupt_level );
  798. printk(KERN_ERR " Please use another IRQ!\n" );
  799. } else {
  800. printk(KERN_ERR "scsi: <fdomain> Error getting IRQ %d\n", interrupt_level );
  801. printk(KERN_ERR " This shouldn't happen!\n" );
  802. printk(KERN_ERR " Send mail to faith@acm.org\n" );
  803. }
  804. printk(KERN_ERR "scsi: <fdomain> Detected, but driver not loaded (IRQ)\n" );
  805. goto fail;
  806. }
  807. }
  808. return shpnt;
  809. fail:
  810. pci_dev_put(pdev);
  811. release_region(port_base, 0x10);
  812. return NULL;
  813. }
  814. static int fdomain_16x0_detect(struct scsi_host_template *tpnt)
  815. {
  816. if (fdomain)
  817. fdomain_setup(fdomain);
  818. return (__fdomain_16x0_detect(tpnt) != NULL);
  819. }
  820. static const char *fdomain_16x0_info( struct Scsi_Host *ignore )
  821. {
  822. static char buffer[128];
  823. char *pt;
  824. strcpy( buffer, "Future Domain 16-bit SCSI Driver Version" );
  825. if (strchr( VERSION, ':')) { /* Assume VERSION is an RCS Revision string */
  826. strcat( buffer, strchr( VERSION, ':' ) + 1 );
  827. pt = strrchr( buffer, '$') - 1;
  828. if (!pt) /* Stripped RCS Revision string? */
  829. pt = buffer + strlen( buffer ) - 1;
  830. if (*pt != ' ')
  831. ++pt;
  832. *pt = '\0';
  833. } else { /* Assume VERSION is a number */
  834. strcat( buffer, " " VERSION );
  835. }
  836. return buffer;
  837. }
  838. #if 0
  839. static int fdomain_arbitrate( void )
  840. {
  841. int status = 0;
  842. unsigned long timeout;
  843. #if EVERY_ACCESS
  844. printk( "fdomain_arbitrate()\n" );
  845. #endif
  846. outb(0x00, port_base + SCSI_Cntl); /* Disable data drivers */
  847. outb(adapter_mask, port_base + SCSI_Data_NoACK); /* Set our id bit */
  848. outb(0x04 | PARITY_MASK, port_base + TMC_Cntl); /* Start arbitration */
  849. timeout = 500;
  850. do {
  851. status = inb(port_base + TMC_Status); /* Read adapter status */
  852. if (status & 0x02) /* Arbitration complete */
  853. return 0;
  854. mdelay(1); /* Wait one millisecond */
  855. } while (--timeout);
  856. /* Make bus idle */
  857. fdomain_make_bus_idle();
  858. #if EVERY_ACCESS
  859. printk( "Arbitration failed, status = %x\n", status );
  860. #endif
  861. #if ERRORS_ONLY
  862. printk( "scsi: <fdomain> Arbitration failed, status = %x\n", status );
  863. #endif
  864. return 1;
  865. }
  866. #endif
  867. static int fdomain_select( int target )
  868. {
  869. int status;
  870. unsigned long timeout;
  871. #if ERRORS_ONLY
  872. static int flag = 0;
  873. #endif
  874. outb(0x82, port_base + SCSI_Cntl); /* Bus Enable + Select */
  875. outb(adapter_mask | (1 << target), port_base + SCSI_Data_NoACK);
  876. /* Stop arbitration and enable parity */
  877. outb(PARITY_MASK, port_base + TMC_Cntl);
  878. timeout = 350; /* 350 msec */
  879. do {
  880. status = inb(port_base + SCSI_Status); /* Read adapter status */
  881. if (status & 1) { /* Busy asserted */
  882. /* Enable SCSI Bus (on error, should make bus idle with 0) */
  883. outb(0x80, port_base + SCSI_Cntl);
  884. return 0;
  885. }
  886. mdelay(1); /* wait one msec */
  887. } while (--timeout);
  888. /* Make bus idle */
  889. fdomain_make_bus_idle();
  890. #if EVERY_ACCESS
  891. if (!target) printk( "Selection failed\n" );
  892. #endif
  893. #if ERRORS_ONLY
  894. if (!target) {
  895. if (!flag) /* Skip first failure for all chips. */
  896. ++flag;
  897. else
  898. printk( "scsi: <fdomain> Selection failed\n" );
  899. }
  900. #endif
  901. return 1;
  902. }
  903. static void my_done(int error)
  904. {
  905. if (in_command) {
  906. in_command = 0;
  907. outb(0x00, port_base + Interrupt_Cntl);
  908. fdomain_make_bus_idle();
  909. current_SC->result = error;
  910. if (current_SC->scsi_done)
  911. current_SC->scsi_done( current_SC );
  912. else panic( "scsi: <fdomain> current_SC->scsi_done() == NULL" );
  913. } else {
  914. panic( "scsi: <fdomain> my_done() called outside of command\n" );
  915. }
  916. #if DEBUG_RACE
  917. in_interrupt_flag = 0;
  918. #endif
  919. }
  920. static irqreturn_t do_fdomain_16x0_intr(int irq, void *dev_id)
  921. {
  922. unsigned long flags;
  923. int status;
  924. int done = 0;
  925. unsigned data_count;
  926. /* The fdomain_16x0_intr is only called via
  927. the interrupt handler. The goal of the
  928. sti() here is to allow other
  929. interruptions while this routine is
  930. running. */
  931. /* Check for other IRQ sources */
  932. if ((inb(port_base + TMC_Status) & 0x01) == 0)
  933. return IRQ_NONE;
  934. /* It is our IRQ */
  935. outb(0x00, port_base + Interrupt_Cntl);
  936. /* We usually have one spurious interrupt after each command. Ignore it. */
  937. if (!in_command || !current_SC) { /* Spurious interrupt */
  938. #if EVERY_ACCESS
  939. printk( "Spurious interrupt, in_command = %d, current_SC = %x\n",
  940. in_command, current_SC );
  941. #endif
  942. return IRQ_NONE;
  943. }
  944. /* Abort calls my_done, so we do nothing here. */
  945. if (current_SC->SCp.phase & aborted) {
  946. #if DEBUG_ABORT
  947. printk( "scsi: <fdomain> Interrupt after abort, ignoring\n" );
  948. #endif
  949. /*
  950. return IRQ_HANDLED; */
  951. }
  952. #if DEBUG_RACE
  953. ++in_interrupt_flag;
  954. #endif
  955. if (current_SC->SCp.phase & in_arbitration) {
  956. status = inb(port_base + TMC_Status); /* Read adapter status */
  957. if (!(status & 0x02)) {
  958. #if EVERY_ACCESS
  959. printk( " AFAIL " );
  960. #endif
  961. spin_lock_irqsave(current_SC->device->host->host_lock, flags);
  962. my_done( DID_BUS_BUSY << 16 );
  963. spin_unlock_irqrestore(current_SC->device->host->host_lock, flags);
  964. return IRQ_HANDLED;
  965. }
  966. current_SC->SCp.phase = in_selection;
  967. outb(0x40 | FIFO_COUNT, port_base + Interrupt_Cntl);
  968. outb(0x82, port_base + SCSI_Cntl); /* Bus Enable + Select */
  969. outb(adapter_mask | (1 << scmd_id(current_SC)), port_base + SCSI_Data_NoACK);
  970. /* Stop arbitration and enable parity */
  971. outb(0x10 | PARITY_MASK, port_base + TMC_Cntl);
  972. #if DEBUG_RACE
  973. in_interrupt_flag = 0;
  974. #endif
  975. return IRQ_HANDLED;
  976. } else if (current_SC->SCp.phase & in_selection) {
  977. status = inb(port_base + SCSI_Status);
  978. if (!(status & 0x01)) {
  979. /* Try again, for slow devices */
  980. if (fdomain_select( scmd_id(current_SC) )) {
  981. #if EVERY_ACCESS
  982. printk( " SFAIL " );
  983. #endif
  984. spin_lock_irqsave(current_SC->device->host->host_lock, flags);
  985. my_done( DID_NO_CONNECT << 16 );
  986. spin_unlock_irqrestore(current_SC->device->host->host_lock, flags);
  987. return IRQ_HANDLED;
  988. } else {
  989. #if EVERY_ACCESS
  990. printk( " AltSel " );
  991. #endif
  992. /* Stop arbitration and enable parity */
  993. outb(0x10 | PARITY_MASK, port_base + TMC_Cntl);
  994. }
  995. }
  996. current_SC->SCp.phase = in_other;
  997. outb(0x90 | FIFO_COUNT, port_base + Interrupt_Cntl);
  998. outb(0x80, port_base + SCSI_Cntl);
  999. #if DEBUG_RACE
  1000. in_interrupt_flag = 0;
  1001. #endif
  1002. return IRQ_HANDLED;
  1003. }
  1004. /* current_SC->SCp.phase == in_other: this is the body of the routine */
  1005. status = inb(port_base + SCSI_Status);
  1006. if (status & 0x10) { /* REQ */
  1007. switch (status & 0x0e) {
  1008. case 0x08: /* COMMAND OUT */
  1009. outb(current_SC->cmnd[current_SC->SCp.sent_command++],
  1010. port_base + Write_SCSI_Data);
  1011. #if EVERY_ACCESS
  1012. printk( "CMD = %x,",
  1013. current_SC->cmnd[ current_SC->SCp.sent_command - 1] );
  1014. #endif
  1015. break;
  1016. case 0x00: /* DATA OUT -- tmc18c50/tmc18c30 only */
  1017. if (chip != tmc1800 && !current_SC->SCp.have_data_in) {
  1018. current_SC->SCp.have_data_in = -1;
  1019. outb(0xd0 | PARITY_MASK, port_base + TMC_Cntl);
  1020. }
  1021. break;
  1022. case 0x04: /* DATA IN -- tmc18c50/tmc18c30 only */
  1023. if (chip != tmc1800 && !current_SC->SCp.have_data_in) {
  1024. current_SC->SCp.have_data_in = 1;
  1025. outb(0x90 | PARITY_MASK, port_base + TMC_Cntl);
  1026. }
  1027. break;
  1028. case 0x0c: /* STATUS IN */
  1029. current_SC->SCp.Status = inb(port_base + Read_SCSI_Data);
  1030. #if EVERY_ACCESS
  1031. printk( "Status = %x, ", current_SC->SCp.Status );
  1032. #endif
  1033. #if ERRORS_ONLY
  1034. if (current_SC->SCp.Status
  1035. && current_SC->SCp.Status != 2
  1036. && current_SC->SCp.Status != 8) {
  1037. printk( "scsi: <fdomain> target = %d, command = %x, status = %x\n",
  1038. current_SC->device->id,
  1039. current_SC->cmnd[0],
  1040. current_SC->SCp.Status );
  1041. }
  1042. #endif
  1043. break;
  1044. case 0x0a: /* MESSAGE OUT */
  1045. outb(MESSAGE_REJECT, port_base + Write_SCSI_Data); /* Reject */
  1046. break;
  1047. case 0x0e: /* MESSAGE IN */
  1048. current_SC->SCp.Message = inb(port_base + Read_SCSI_Data);
  1049. #if EVERY_ACCESS
  1050. printk( "Message = %x, ", current_SC->SCp.Message );
  1051. #endif
  1052. if (!current_SC->SCp.Message) ++done;
  1053. #if DEBUG_MESSAGES || EVERY_ACCESS
  1054. if (current_SC->SCp.Message) {
  1055. printk( "scsi: <fdomain> message = %x\n",
  1056. current_SC->SCp.Message );
  1057. }
  1058. #endif
  1059. break;
  1060. }
  1061. }
  1062. if (chip == tmc1800 && !current_SC->SCp.have_data_in
  1063. && (current_SC->SCp.sent_command >= current_SC->cmd_len)) {
  1064. if(current_SC->sc_data_direction == DMA_TO_DEVICE)
  1065. {
  1066. current_SC->SCp.have_data_in = -1;
  1067. outb(0xd0 | PARITY_MASK, port_base + TMC_Cntl);
  1068. }
  1069. else
  1070. {
  1071. current_SC->SCp.have_data_in = 1;
  1072. outb(0x90 | PARITY_MASK, port_base + TMC_Cntl);
  1073. }
  1074. }
  1075. if (current_SC->SCp.have_data_in == -1) { /* DATA OUT */
  1076. while ((data_count = FIFO_Size - inw(port_base + FIFO_Data_Count)) > 512) {
  1077. #if EVERY_ACCESS
  1078. printk( "DC=%d, ", data_count ) ;
  1079. #endif
  1080. if (data_count > current_SC->SCp.this_residual)
  1081. data_count = current_SC->SCp.this_residual;
  1082. if (data_count > 0) {
  1083. #if EVERY_ACCESS
  1084. printk( "%d OUT, ", data_count );
  1085. #endif
  1086. if (data_count == 1) {
  1087. outb(*current_SC->SCp.ptr++, port_base + Write_FIFO);
  1088. --current_SC->SCp.this_residual;
  1089. } else {
  1090. data_count >>= 1;
  1091. outsw(port_base + Write_FIFO, current_SC->SCp.ptr, data_count);
  1092. current_SC->SCp.ptr += 2 * data_count;
  1093. current_SC->SCp.this_residual -= 2 * data_count;
  1094. }
  1095. }
  1096. if (!current_SC->SCp.this_residual) {
  1097. if (current_SC->SCp.buffers_residual) {
  1098. --current_SC->SCp.buffers_residual;
  1099. ++current_SC->SCp.buffer;
  1100. current_SC->SCp.ptr = sg_virt(current_SC->SCp.buffer);
  1101. current_SC->SCp.this_residual = current_SC->SCp.buffer->length;
  1102. } else
  1103. break;
  1104. }
  1105. }
  1106. }
  1107. if (current_SC->SCp.have_data_in == 1) { /* DATA IN */
  1108. while ((data_count = inw(port_base + FIFO_Data_Count)) > 0) {
  1109. #if EVERY_ACCESS
  1110. printk( "DC=%d, ", data_count );
  1111. #endif
  1112. if (data_count > current_SC->SCp.this_residual)
  1113. data_count = current_SC->SCp.this_residual;
  1114. if (data_count) {
  1115. #if EVERY_ACCESS
  1116. printk( "%d IN, ", data_count );
  1117. #endif
  1118. if (data_count == 1) {
  1119. *current_SC->SCp.ptr++ = inb(port_base + Read_FIFO);
  1120. --current_SC->SCp.this_residual;
  1121. } else {
  1122. data_count >>= 1; /* Number of words */
  1123. insw(port_base + Read_FIFO, current_SC->SCp.ptr, data_count);
  1124. current_SC->SCp.ptr += 2 * data_count;
  1125. current_SC->SCp.this_residual -= 2 * data_count;
  1126. }
  1127. }
  1128. if (!current_SC->SCp.this_residual
  1129. && current_SC->SCp.buffers_residual) {
  1130. --current_SC->SCp.buffers_residual;
  1131. ++current_SC->SCp.buffer;
  1132. current_SC->SCp.ptr = sg_virt(current_SC->SCp.buffer);
  1133. current_SC->SCp.this_residual = current_SC->SCp.buffer->length;
  1134. }
  1135. }
  1136. }
  1137. if (done) {
  1138. #if EVERY_ACCESS
  1139. printk( " ** IN DONE %d ** ", current_SC->SCp.have_data_in );
  1140. #endif
  1141. #if ERRORS_ONLY
  1142. if (current_SC->cmnd[0] == REQUEST_SENSE && !current_SC->SCp.Status) {
  1143. char *buf = scsi_sglist(current_SC);
  1144. if ((unsigned char)(*(buf + 2)) & 0x0f) {
  1145. unsigned char key;
  1146. unsigned char code;
  1147. unsigned char qualifier;
  1148. key = (unsigned char)(*(buf + 2)) & 0x0f;
  1149. code = (unsigned char)(*(buf + 12));
  1150. qualifier = (unsigned char)(*(buf + 13));
  1151. if (key != UNIT_ATTENTION
  1152. && !(key == NOT_READY
  1153. && code == 0x04
  1154. && (!qualifier || qualifier == 0x02 || qualifier == 0x01))
  1155. && !(key == ILLEGAL_REQUEST && (code == 0x25
  1156. || code == 0x24
  1157. || !code)))
  1158. printk( "scsi: <fdomain> REQUEST SENSE"
  1159. " Key = %x, Code = %x, Qualifier = %x\n",
  1160. key, code, qualifier );
  1161. }
  1162. }
  1163. #endif
  1164. #if EVERY_ACCESS
  1165. printk( "BEFORE MY_DONE. . ." );
  1166. #endif
  1167. spin_lock_irqsave(current_SC->device->host->host_lock, flags);
  1168. my_done( (current_SC->SCp.Status & 0xff)
  1169. | ((current_SC->SCp.Message & 0xff) << 8) | (DID_OK << 16) );
  1170. spin_unlock_irqrestore(current_SC->device->host->host_lock, flags);
  1171. #if EVERY_ACCESS
  1172. printk( "RETURNING.\n" );
  1173. #endif
  1174. } else {
  1175. if (current_SC->SCp.phase & disconnect) {
  1176. outb(0xd0 | FIFO_COUNT, port_base + Interrupt_Cntl);
  1177. outb(0x00, port_base + SCSI_Cntl);
  1178. } else {
  1179. outb(0x90 | FIFO_COUNT, port_base + Interrupt_Cntl);
  1180. }
  1181. }
  1182. #if DEBUG_RACE
  1183. in_interrupt_flag = 0;
  1184. #endif
  1185. return IRQ_HANDLED;
  1186. }
  1187. static int fdomain_16x0_queue_lck(struct scsi_cmnd *SCpnt,
  1188. void (*done)(struct scsi_cmnd *))
  1189. {
  1190. if (in_command) {
  1191. panic( "scsi: <fdomain> fdomain_16x0_queue() NOT REENTRANT!\n" );
  1192. }
  1193. #if EVERY_ACCESS
  1194. printk( "queue: target = %d cmnd = 0x%02x pieces = %d size = %u\n",
  1195. SCpnt->target,
  1196. *(unsigned char *)SCpnt->cmnd,
  1197. scsi_sg_count(SCpnt),
  1198. scsi_bufflen(SCpnt));
  1199. #endif
  1200. fdomain_make_bus_idle();
  1201. current_SC = SCpnt; /* Save this for the done function */
  1202. current_SC->scsi_done = done;
  1203. /* Initialize static data */
  1204. if (scsi_sg_count(current_SC)) {
  1205. current_SC->SCp.buffer = scsi_sglist(current_SC);
  1206. current_SC->SCp.ptr = sg_virt(current_SC->SCp.buffer);
  1207. current_SC->SCp.this_residual = current_SC->SCp.buffer->length;
  1208. current_SC->SCp.buffers_residual = scsi_sg_count(current_SC) - 1;
  1209. } else {
  1210. current_SC->SCp.ptr = NULL;
  1211. current_SC->SCp.this_residual = 0;
  1212. current_SC->SCp.buffer = NULL;
  1213. current_SC->SCp.buffers_residual = 0;
  1214. }
  1215. current_SC->SCp.Status = 0;
  1216. current_SC->SCp.Message = 0;
  1217. current_SC->SCp.have_data_in = 0;
  1218. current_SC->SCp.sent_command = 0;
  1219. current_SC->SCp.phase = in_arbitration;
  1220. /* Start arbitration */
  1221. outb(0x00, port_base + Interrupt_Cntl);
  1222. outb(0x00, port_base + SCSI_Cntl); /* Disable data drivers */
  1223. outb(adapter_mask, port_base + SCSI_Data_NoACK); /* Set our id bit */
  1224. ++in_command;
  1225. outb(0x20, port_base + Interrupt_Cntl);
  1226. outb(0x14 | PARITY_MASK, port_base + TMC_Cntl); /* Start arbitration */
  1227. return 0;
  1228. }
  1229. static DEF_SCSI_QCMD(fdomain_16x0_queue)
  1230. #if DEBUG_ABORT
  1231. static void print_info(struct scsi_cmnd *SCpnt)
  1232. {
  1233. unsigned int imr;
  1234. unsigned int irr;
  1235. unsigned int isr;
  1236. if (!SCpnt || !SCpnt->device || !SCpnt->device->host) {
  1237. printk(KERN_WARNING "scsi: <fdomain> Cannot provide detailed information\n");
  1238. return;
  1239. }
  1240. printk(KERN_INFO "%s\n", fdomain_16x0_info( SCpnt->device->host ) );
  1241. print_banner(SCpnt->device->host);
  1242. switch (SCpnt->SCp.phase) {
  1243. case in_arbitration: printk("arbitration"); break;
  1244. case in_selection: printk("selection"); break;
  1245. case in_other: printk("other"); break;
  1246. default: printk("unknown"); break;
  1247. }
  1248. printk( " (%d), target = %d cmnd = 0x%02x pieces = %d size = %u\n",
  1249. SCpnt->SCp.phase,
  1250. SCpnt->device->id,
  1251. *(unsigned char *)SCpnt->cmnd,
  1252. scsi_sg_count(SCpnt),
  1253. scsi_bufflen(SCpnt));
  1254. printk( "sent_command = %d, have_data_in = %d, timeout = %d\n",
  1255. SCpnt->SCp.sent_command,
  1256. SCpnt->SCp.have_data_in,
  1257. SCpnt->timeout );
  1258. #if DEBUG_RACE
  1259. printk( "in_interrupt_flag = %d\n", in_interrupt_flag );
  1260. #endif
  1261. imr = (inb( 0x0a1 ) << 8) + inb( 0x21 );
  1262. outb( 0x0a, 0xa0 );
  1263. irr = inb( 0xa0 ) << 8;
  1264. outb( 0x0a, 0x20 );
  1265. irr += inb( 0x20 );
  1266. outb( 0x0b, 0xa0 );
  1267. isr = inb( 0xa0 ) << 8;
  1268. outb( 0x0b, 0x20 );
  1269. isr += inb( 0x20 );
  1270. /* Print out interesting information */
  1271. printk( "IMR = 0x%04x", imr );
  1272. if (imr & (1 << interrupt_level))
  1273. printk( " (masked)" );
  1274. printk( ", IRR = 0x%04x, ISR = 0x%04x\n", irr, isr );
  1275. printk( "SCSI Status = 0x%02x\n", inb(port_base + SCSI_Status));
  1276. printk( "TMC Status = 0x%02x", inb(port_base + TMC_Status));
  1277. if (inb((port_base + TMC_Status) & 1))
  1278. printk( " (interrupt)" );
  1279. printk( "\n" );
  1280. printk("Interrupt Status = 0x%02x", inb(port_base + Interrupt_Status));
  1281. if (inb(port_base + Interrupt_Status) & 0x08)
  1282. printk( " (enabled)" );
  1283. printk( "\n" );
  1284. if (chip == tmc18c50 || chip == tmc18c30) {
  1285. printk("FIFO Status = 0x%02x\n", inb(port_base + FIFO_Status));
  1286. printk( "Int. Condition = 0x%02x\n",
  1287. inb( port_base + Interrupt_Cond ) );
  1288. }
  1289. printk( "Configuration 1 = 0x%02x\n", inb( port_base + Configuration1 ) );
  1290. if (chip == tmc18c50 || chip == tmc18c30)
  1291. printk( "Configuration 2 = 0x%02x\n",
  1292. inb( port_base + Configuration2 ) );
  1293. }
  1294. #endif
  1295. static int fdomain_16x0_abort(struct scsi_cmnd *SCpnt)
  1296. {
  1297. #if EVERY_ACCESS || ERRORS_ONLY || DEBUG_ABORT
  1298. printk( "scsi: <fdomain> abort " );
  1299. #endif
  1300. if (!in_command) {
  1301. #if EVERY_ACCESS || ERRORS_ONLY
  1302. printk( " (not in command)\n" );
  1303. #endif
  1304. return FAILED;
  1305. } else printk( "\n" );
  1306. #if DEBUG_ABORT
  1307. print_info( SCpnt );
  1308. #endif
  1309. fdomain_make_bus_idle();
  1310. current_SC->SCp.phase |= aborted;
  1311. current_SC->result = DID_ABORT << 16;
  1312. /* Aborts are not done well. . . */
  1313. my_done(DID_ABORT << 16);
  1314. return SUCCESS;
  1315. }
  1316. int fdomain_16x0_bus_reset(struct scsi_cmnd *SCpnt)
  1317. {
  1318. unsigned long flags;
  1319. local_irq_save(flags);
  1320. outb(1, port_base + SCSI_Cntl);
  1321. do_pause( 2 );
  1322. outb(0, port_base + SCSI_Cntl);
  1323. do_pause( 115 );
  1324. outb(0, port_base + SCSI_Mode_Cntl);
  1325. outb(PARITY_MASK, port_base + TMC_Cntl);
  1326. local_irq_restore(flags);
  1327. return SUCCESS;
  1328. }
  1329. static int fdomain_16x0_biosparam(struct scsi_device *sdev,
  1330. struct block_device *bdev,
  1331. sector_t capacity, int *info_array)
  1332. {
  1333. int drive;
  1334. int size = capacity;
  1335. unsigned long offset;
  1336. struct drive_info {
  1337. unsigned short cylinders;
  1338. unsigned char heads;
  1339. unsigned char sectors;
  1340. } i;
  1341. /* NOTES:
  1342. The RAM area starts at 0x1f00 from the bios_base address.
  1343. For BIOS Version 2.0:
  1344. The drive parameter table seems to start at 0x1f30.
  1345. The first byte's purpose is not known.
  1346. Next is the cylinder, head, and sector information.
  1347. The last 4 bytes appear to be the drive's size in sectors.
  1348. The other bytes in the drive parameter table are unknown.
  1349. If anyone figures them out, please send me mail, and I will
  1350. update these notes.
  1351. Tape drives do not get placed in this table.
  1352. There is another table at 0x1fea:
  1353. If the byte is 0x01, then the SCSI ID is not in use.
  1354. If the byte is 0x18 or 0x48, then the SCSI ID is in use,
  1355. although tapes don't seem to be in this table. I haven't
  1356. seen any other numbers (in a limited sample).
  1357. 0x1f2d is a drive count (i.e., not including tapes)
  1358. The table at 0x1fcc are I/O ports addresses for the various
  1359. operations. I calculate these by hand in this driver code.
  1360. For the ISA-200S version of BIOS Version 2.0:
  1361. The drive parameter table starts at 0x1f33.
  1362. WARNING: Assume that the table entry is 25 bytes long. Someone needs
  1363. to check this for the Quantum ISA-200S card.
  1364. For BIOS Version 3.2:
  1365. The drive parameter table starts at 0x1f70. Each entry is
  1366. 0x0a bytes long. Heads are one less than we need to report.
  1367. */
  1368. if (MAJOR(bdev->bd_dev) != SCSI_DISK0_MAJOR) {
  1369. printk("scsi: <fdomain> fdomain_16x0_biosparam: too many disks");
  1370. return 0;
  1371. }
  1372. drive = MINOR(bdev->bd_dev) >> 4;
  1373. if (bios_major == 2) {
  1374. switch (Quantum) {
  1375. case 2: /* ISA_200S */
  1376. /* The value of 25 has never been verified.
  1377. It should probably be 15. */
  1378. offset = 0x1f33 + drive * 25;
  1379. break;
  1380. case 3: /* ISA_250MG */
  1381. offset = 0x1f36 + drive * 15;
  1382. break;
  1383. case 4: /* ISA_200S (another one) */
  1384. offset = 0x1f34 + drive * 15;
  1385. break;
  1386. default:
  1387. offset = 0x1f31 + drive * 25;
  1388. break;
  1389. }
  1390. memcpy_fromio( &i, bios_mem + offset, sizeof( struct drive_info ) );
  1391. info_array[0] = i.heads;
  1392. info_array[1] = i.sectors;
  1393. info_array[2] = i.cylinders;
  1394. } else if (bios_major == 3
  1395. && bios_minor >= 0
  1396. && bios_minor < 4) { /* 3.0 and 3.2 BIOS */
  1397. memcpy_fromio( &i, bios_mem + 0x1f71 + drive * 10,
  1398. sizeof( struct drive_info ) );
  1399. info_array[0] = i.heads + 1;
  1400. info_array[1] = i.sectors;
  1401. info_array[2] = i.cylinders;
  1402. } else { /* 3.4 BIOS (and up?) */
  1403. /* This algorithm was provided by Future Domain (much thanks!). */
  1404. unsigned char *p = scsi_bios_ptable(bdev);
  1405. if (p && p[65] == 0xaa && p[64] == 0x55 /* Partition table valid */
  1406. && p[4]) { /* Partition type */
  1407. /* The partition table layout is as follows:
  1408. Start: 0x1b3h
  1409. Offset: 0 = partition status
  1410. 1 = starting head
  1411. 2 = starting sector and cylinder (word, encoded)
  1412. 4 = partition type
  1413. 5 = ending head
  1414. 6 = ending sector and cylinder (word, encoded)
  1415. 8 = starting absolute sector (double word)
  1416. c = number of sectors (double word)
  1417. Signature: 0x1fe = 0x55aa
  1418. So, this algorithm assumes:
  1419. 1) the first partition table is in use,
  1420. 2) the data in the first entry is correct, and
  1421. 3) partitions never divide cylinders
  1422. Note that (1) may be FALSE for NetBSD (and other BSD flavors),
  1423. as well as for Linux. Note also, that Linux doesn't pay any
  1424. attention to the fields that are used by this algorithm -- it
  1425. only uses the absolute sector data. Recent versions of Linux's
  1426. fdisk(1) will fill this data in correctly, and forthcoming
  1427. versions will check for consistency.
  1428. Checking for a non-zero partition type is not part of the
  1429. Future Domain algorithm, but it seemed to be a reasonable thing
  1430. to do, especially in the Linux and BSD worlds. */
  1431. info_array[0] = p[5] + 1; /* heads */
  1432. info_array[1] = p[6] & 0x3f; /* sectors */
  1433. } else {
  1434. /* Note that this new method guarantees that there will always be
  1435. less than 1024 cylinders on a platter. This is good for drives
  1436. up to approximately 7.85GB (where 1GB = 1024 * 1024 kB). */
  1437. if ((unsigned int)size >= 0x7e0000U) {
  1438. info_array[0] = 0xff; /* heads = 255 */
  1439. info_array[1] = 0x3f; /* sectors = 63 */
  1440. } else if ((unsigned int)size >= 0x200000U) {
  1441. info_array[0] = 0x80; /* heads = 128 */
  1442. info_array[1] = 0x3f; /* sectors = 63 */
  1443. } else {
  1444. info_array[0] = 0x40; /* heads = 64 */
  1445. info_array[1] = 0x20; /* sectors = 32 */
  1446. }
  1447. }
  1448. /* For both methods, compute the cylinders */
  1449. info_array[2] = (unsigned int)size / (info_array[0] * info_array[1] );
  1450. kfree(p);
  1451. }
  1452. return 0;
  1453. }
  1454. static int fdomain_16x0_release(struct Scsi_Host *shpnt)
  1455. {
  1456. if (shpnt->irq)
  1457. free_irq(shpnt->irq, shpnt);
  1458. if (shpnt->io_port && shpnt->n_io_port)
  1459. release_region(shpnt->io_port, shpnt->n_io_port);
  1460. if (PCI_bus)
  1461. pci_dev_put(PCI_dev);
  1462. return 0;
  1463. }
  1464. struct scsi_host_template fdomain_driver_template = {
  1465. .module = THIS_MODULE,
  1466. .name = "fdomain",
  1467. .proc_name = "fdomain",
  1468. .detect = fdomain_16x0_detect,
  1469. .info = fdomain_16x0_info,
  1470. .queuecommand = fdomain_16x0_queue,
  1471. .eh_abort_handler = fdomain_16x0_abort,
  1472. .eh_bus_reset_handler = fdomain_16x0_bus_reset,
  1473. .bios_param = fdomain_16x0_biosparam,
  1474. .release = fdomain_16x0_release,
  1475. .can_queue = 1,
  1476. .this_id = 6,
  1477. .sg_tablesize = 64,
  1478. .use_clustering = DISABLE_CLUSTERING,
  1479. };
  1480. #ifndef PCMCIA
  1481. #if defined(CONFIG_PCI) && defined(MODULE)
  1482. static struct pci_device_id fdomain_pci_tbl[] = {
  1483. { PCI_VENDOR_ID_FD, PCI_DEVICE_ID_FD_36C70,
  1484. PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0UL },
  1485. { }
  1486. };
  1487. MODULE_DEVICE_TABLE(pci, fdomain_pci_tbl);
  1488. #endif
  1489. #define driver_template fdomain_driver_template
  1490. #include "scsi_module.c"
  1491. #endif