fdomain.c 56 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760
  1. /* fdomain.c -- Future Domain TMC-16x0 SCSI driver
  2. * Created: Sun May 3 18:53:19 1992 by faith@cs.unc.edu
  3. * Revised: Mon Dec 28 21:59:02 1998 by faith@acm.org
  4. * Author: Rickard E. Faith, faith@cs.unc.edu
  5. * Copyright 1992-1996, 1998 Rickard E. Faith (faith@acm.org)
  6. * Shared IRQ supported added 7/7/2001 Alan Cox <alan@redhat.com>
  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. publically 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 <scsi/scsicam.h>
  211. #include <asm/system.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. MODULE_AUTHOR("Rickard E. Faith");
  219. MODULE_DESCRIPTION("Future domain SCSI driver");
  220. MODULE_LICENSE("GPL");
  221. #define VERSION "$Revision: 1.1.1.1 $"
  222. /* START OF USER DEFINABLE OPTIONS */
  223. #define DEBUG 0 /* Enable debugging output */
  224. #define ENABLE_PARITY 1 /* Enable SCSI Parity */
  225. #define FIFO_COUNT 2 /* Number of 512 byte blocks before INTR */
  226. /* END OF USER DEFINABLE OPTIONS */
  227. #if DEBUG
  228. #define EVERY_ACCESS 0 /* Write a line on every scsi access */
  229. #define ERRORS_ONLY 1 /* Only write a line if there is an error */
  230. #define DEBUG_DETECT 0 /* Debug fdomain_16x0_detect() */
  231. #define DEBUG_MESSAGES 1 /* Debug MESSAGE IN phase */
  232. #define DEBUG_ABORT 1 /* Debug abort() routine */
  233. #define DEBUG_RESET 1 /* Debug reset() routine */
  234. #define DEBUG_RACE 1 /* Debug interrupt-driven race condition */
  235. #else
  236. #define EVERY_ACCESS 0 /* LEAVE THESE ALONE--CHANGE THE ONES ABOVE */
  237. #define ERRORS_ONLY 0
  238. #define DEBUG_DETECT 0
  239. #define DEBUG_MESSAGES 0
  240. #define DEBUG_ABORT 0
  241. #define DEBUG_RESET 0
  242. #define DEBUG_RACE 0
  243. #endif
  244. /* Errors are reported on the line, so we don't need to report them again */
  245. #if EVERY_ACCESS
  246. #undef ERRORS_ONLY
  247. #define ERRORS_ONLY 0
  248. #endif
  249. #if ENABLE_PARITY
  250. #define PARITY_MASK 0x08
  251. #else
  252. #define PARITY_MASK 0x00
  253. #endif
  254. enum chip_type {
  255. unknown = 0x00,
  256. tmc1800 = 0x01,
  257. tmc18c50 = 0x02,
  258. tmc18c30 = 0x03,
  259. };
  260. enum {
  261. in_arbitration = 0x02,
  262. in_selection = 0x04,
  263. in_other = 0x08,
  264. disconnect = 0x10,
  265. aborted = 0x20,
  266. sent_ident = 0x40,
  267. };
  268. enum in_port_type {
  269. Read_SCSI_Data = 0,
  270. SCSI_Status = 1,
  271. TMC_Status = 2,
  272. FIFO_Status = 3, /* tmc18c50/tmc18c30 only */
  273. Interrupt_Cond = 4, /* tmc18c50/tmc18c30 only */
  274. LSB_ID_Code = 5,
  275. MSB_ID_Code = 6,
  276. Read_Loopback = 7,
  277. SCSI_Data_NoACK = 8,
  278. Interrupt_Status = 9,
  279. Configuration1 = 10,
  280. Configuration2 = 11, /* tmc18c50/tmc18c30 only */
  281. Read_FIFO = 12,
  282. FIFO_Data_Count = 14
  283. };
  284. enum out_port_type {
  285. Write_SCSI_Data = 0,
  286. SCSI_Cntl = 1,
  287. Interrupt_Cntl = 2,
  288. SCSI_Mode_Cntl = 3,
  289. TMC_Cntl = 4,
  290. Memory_Cntl = 5, /* tmc18c50/tmc18c30 only */
  291. Write_Loopback = 7,
  292. IO_Control = 11, /* tmc18c30 only */
  293. Write_FIFO = 12
  294. };
  295. /* .bss will zero all the static variables below */
  296. static int port_base;
  297. static unsigned long bios_base;
  298. static void __iomem * bios_mem;
  299. static int bios_major;
  300. static int bios_minor;
  301. static int PCI_bus;
  302. static struct pci_dev *PCI_dev;
  303. static int Quantum; /* Quantum board variant */
  304. static int interrupt_level;
  305. static volatile int in_command;
  306. static struct scsi_cmnd *current_SC;
  307. static enum chip_type chip = unknown;
  308. static int adapter_mask;
  309. static int this_id;
  310. static int setup_called;
  311. #if DEBUG_RACE
  312. static volatile int in_interrupt_flag;
  313. #endif
  314. static int FIFO_Size = 0x2000; /* 8k FIFO for
  315. pre-tmc18c30 chips */
  316. static irqreturn_t do_fdomain_16x0_intr( int irq, void *dev_id );
  317. /* Allow insmod parameters to be like LILO parameters. For example:
  318. insmod fdomain fdomain=0x140,11 */
  319. static char * fdomain = NULL;
  320. module_param(fdomain, charp, 0);
  321. static unsigned long addresses[] = {
  322. 0xc8000,
  323. 0xca000,
  324. 0xce000,
  325. 0xde000,
  326. 0xcc000, /* Extra addresses for PCI boards */
  327. 0xd0000,
  328. 0xe0000,
  329. };
  330. #define ADDRESS_COUNT ARRAY_SIZE(addresses)
  331. static unsigned short ports[] = { 0x140, 0x150, 0x160, 0x170 };
  332. #define PORT_COUNT ARRAY_SIZE(ports)
  333. static unsigned short ints[] = { 3, 5, 10, 11, 12, 14, 15, 0 };
  334. /*
  335. READ THIS BEFORE YOU ADD A SIGNATURE!
  336. READING THIS SHORT NOTE CAN SAVE YOU LOTS OF TIME!
  337. READ EVERY WORD, ESPECIALLY THE WORD *NOT*
  338. This driver works *ONLY* for Future Domain cards using the TMC-1800,
  339. TMC-18C50, or TMC-18C30 chip. This includes models TMC-1650, 1660, 1670,
  340. and 1680. These are all 16-bit cards.
  341. The following BIOS signature signatures are for boards which do *NOT*
  342. work with this driver (these TMC-8xx and TMC-9xx boards may work with the
  343. Seagate driver):
  344. FUTURE DOMAIN CORP. (C) 1986-1988 V4.0I 03/16/88
  345. FUTURE DOMAIN CORP. (C) 1986-1989 V5.0C2/14/89
  346. FUTURE DOMAIN CORP. (C) 1986-1989 V6.0A7/28/89
  347. FUTURE DOMAIN CORP. (C) 1986-1990 V6.0105/31/90
  348. FUTURE DOMAIN CORP. (C) 1986-1990 V6.0209/18/90
  349. FUTURE DOMAIN CORP. (C) 1986-1990 V7.009/18/90
  350. FUTURE DOMAIN CORP. (C) 1992 V8.00.004/02/92
  351. (The cards which do *NOT* work are all 8-bit cards -- although some of
  352. them have a 16-bit form-factor, the upper 8-bits are used only for IRQs
  353. and are *NOT* used for data. You can tell the difference by following
  354. the tracings on the circuit board -- if only the IRQ lines are involved,
  355. you have a "8-bit" card, and should *NOT* use this driver.)
  356. */
  357. static struct signature {
  358. const char *signature;
  359. int sig_offset;
  360. int sig_length;
  361. int major_bios_version;
  362. int minor_bios_version;
  363. int flag; /* 1 == PCI_bus, 2 == ISA_200S, 3 == ISA_250MG, 4 == ISA_200S */
  364. } signatures[] = {
  365. /* 1 2 3 4 5 6 */
  366. /* 123456789012345678901234567890123456789012345678901234567890 */
  367. { "FUTURE DOMAIN CORP. (C) 1986-1990 1800-V2.07/28/89", 5, 50, 2, 0, 0 },
  368. { "FUTURE DOMAIN CORP. (C) 1986-1990 1800-V1.07/28/89", 5, 50, 2, 0, 0 },
  369. { "FUTURE DOMAIN CORP. (C) 1986-1990 1800-V2.07/28/89", 72, 50, 2, 0, 2 },
  370. { "FUTURE DOMAIN CORP. (C) 1986-1990 1800-V2.0", 73, 43, 2, 0, 3 },
  371. { "FUTURE DOMAIN CORP. (C) 1991 1800-V2.0.", 72, 39, 2, 0, 4 },
  372. { "FUTURE DOMAIN CORP. (C) 1992 V3.00.004/02/92", 5, 44, 3, 0, 0 },
  373. { "FUTURE DOMAIN TMC-18XX (C) 1993 V3.203/12/93", 5, 44, 3, 2, 0 },
  374. { "IBM F1 P2 BIOS v1.0104/29/93", 5, 28, 3, -1, 0 },
  375. { "Future Domain Corp. V1.0008/18/93", 5, 33, 3, 4, 0 },
  376. { "Future Domain Corp. V1.0008/18/93", 26, 33, 3, 4, 1 },
  377. { "Adaptec AHA-2920 PCI-SCSI Card", 42, 31, 3, -1, 1 },
  378. { "IBM F1 P264/32", 5, 14, 3, -1, 1 },
  379. /* This next signature may not be a 3.5 bios */
  380. { "Future Domain Corp. V2.0108/18/93", 5, 33, 3, 5, 0 },
  381. { "FUTURE DOMAIN CORP. V3.5008/18/93", 5, 34, 3, 5, 0 },
  382. { "FUTURE DOMAIN 18c30/18c50/1800 (C) 1994 V3.5", 5, 44, 3, 5, 0 },
  383. { "FUTURE DOMAIN CORP. V3.6008/18/93", 5, 34, 3, 6, 0 },
  384. { "FUTURE DOMAIN CORP. V3.6108/18/93", 5, 34, 3, 6, 0 },
  385. { "FUTURE DOMAIN TMC-18XX", 5, 22, -1, -1, 0 },
  386. /* READ NOTICE ABOVE *BEFORE* YOU WASTE YOUR TIME ADDING A SIGNATURE
  387. Also, fix the disk geometry code for your signature and send your
  388. changes for faith@cs.unc.edu. Above all, do *NOT* change any old
  389. signatures!
  390. Note that the last line will match a "generic" 18XX bios. Because
  391. Future Domain has changed the host SCSI ID and/or the location of the
  392. geometry information in the on-board RAM area for each of the first
  393. three BIOS's, it is still important to enter a fully qualified
  394. signature in the table for any new BIOS's (after the host SCSI ID and
  395. geometry location are verified). */
  396. };
  397. #define SIGNATURE_COUNT ARRAY_SIZE(signatures)
  398. static void print_banner( struct Scsi_Host *shpnt )
  399. {
  400. if (!shpnt) return; /* This won't ever happen */
  401. if (bios_major < 0 && bios_minor < 0) {
  402. printk(KERN_INFO "scsi%d: <fdomain> No BIOS; using scsi id %d\n",
  403. shpnt->host_no, shpnt->this_id);
  404. } else {
  405. printk(KERN_INFO "scsi%d: <fdomain> BIOS version ", shpnt->host_no);
  406. if (bios_major >= 0) printk("%d.", bios_major);
  407. else printk("?.");
  408. if (bios_minor >= 0) printk("%d", bios_minor);
  409. else printk("?.");
  410. printk( " at 0x%lx using scsi id %d\n",
  411. bios_base, shpnt->this_id );
  412. }
  413. /* If this driver works for later FD PCI
  414. boards, we will have to modify banner
  415. for additional PCI cards, but for now if
  416. it's PCI it's a TMC-3260 - JTM */
  417. printk(KERN_INFO "scsi%d: <fdomain> %s chip at 0x%x irq ",
  418. shpnt->host_no,
  419. chip == tmc1800 ? "TMC-1800" : (chip == tmc18c50 ? "TMC-18C50" : (chip == tmc18c30 ? (PCI_bus ? "TMC-36C70 (PCI bus)" : "TMC-18C30") : "Unknown")),
  420. port_base);
  421. if (interrupt_level)
  422. printk("%d", interrupt_level);
  423. else
  424. printk("<none>");
  425. printk( "\n" );
  426. }
  427. int fdomain_setup(char *str)
  428. {
  429. int ints[4];
  430. (void)get_options(str, ARRAY_SIZE(ints), ints);
  431. if (setup_called++ || ints[0] < 2 || ints[0] > 3) {
  432. printk(KERN_INFO "scsi: <fdomain> Usage: fdomain=<PORT_BASE>,<IRQ>[,<ADAPTER_ID>]\n");
  433. printk(KERN_ERR "scsi: <fdomain> Bad LILO/INSMOD parameters?\n");
  434. return 0;
  435. }
  436. port_base = ints[0] >= 1 ? ints[1] : 0;
  437. interrupt_level = ints[0] >= 2 ? ints[2] : 0;
  438. this_id = ints[0] >= 3 ? ints[3] : 0;
  439. bios_major = bios_minor = -1; /* Use geometry for BIOS version >= 3.4 */
  440. ++setup_called;
  441. return 1;
  442. }
  443. __setup("fdomain=", fdomain_setup);
  444. static void do_pause(unsigned amount) /* Pause for amount*10 milliseconds */
  445. {
  446. mdelay(10*amount);
  447. }
  448. static inline void fdomain_make_bus_idle( void )
  449. {
  450. outb(0, port_base + SCSI_Cntl);
  451. outb(0, port_base + SCSI_Mode_Cntl);
  452. if (chip == tmc18c50 || chip == tmc18c30)
  453. outb(0x21 | PARITY_MASK, port_base + TMC_Cntl); /* Clear forced intr. */
  454. else
  455. outb(0x01 | PARITY_MASK, port_base + TMC_Cntl);
  456. }
  457. static int fdomain_is_valid_port( int port )
  458. {
  459. #if DEBUG_DETECT
  460. printk( " (%x%x),",
  461. inb( port + MSB_ID_Code ), inb( port + LSB_ID_Code ) );
  462. #endif
  463. /* The MCA ID is a unique id for each MCA compatible board. We
  464. are using ISA boards, but Future Domain provides the MCA ID
  465. anyway. We can use this ID to ensure that this is a Future
  466. Domain TMC-1660/TMC-1680.
  467. */
  468. if (inb( port + LSB_ID_Code ) != 0xe9) { /* test for 0x6127 id */
  469. if (inb( port + LSB_ID_Code ) != 0x27) return 0;
  470. if (inb( port + MSB_ID_Code ) != 0x61) return 0;
  471. chip = tmc1800;
  472. } else { /* test for 0xe960 id */
  473. if (inb( port + MSB_ID_Code ) != 0x60) return 0;
  474. chip = tmc18c50;
  475. /* Try to toggle 32-bit mode. This only
  476. works on an 18c30 chip. (User reports
  477. say this works, so we should switch to
  478. it in the near future.) */
  479. outb( 0x80, port + IO_Control );
  480. if ((inb( port + Configuration2 ) & 0x80) == 0x80) {
  481. outb( 0x00, port + IO_Control );
  482. if ((inb( port + Configuration2 ) & 0x80) == 0x00) {
  483. chip = tmc18c30;
  484. FIFO_Size = 0x800; /* 2k FIFO */
  485. }
  486. }
  487. /* If that failed, we are an 18c50. */
  488. }
  489. return 1;
  490. }
  491. static int fdomain_test_loopback( void )
  492. {
  493. int i;
  494. int result;
  495. for (i = 0; i < 255; i++) {
  496. outb( i, port_base + Write_Loopback );
  497. result = inb( port_base + Read_Loopback );
  498. if (i != result)
  499. return 1;
  500. }
  501. return 0;
  502. }
  503. /* fdomain_get_irq assumes that we have a valid MCA ID for a
  504. TMC-1660/TMC-1680 Future Domain board. Now, check to be sure the
  505. bios_base matches these ports. If someone was unlucky enough to have
  506. purchased more than one Future Domain board, then they will have to
  507. modify this code, as we only detect one board here. [The one with the
  508. lowest bios_base.]
  509. Note that this routine is only used for systems without a PCI BIOS32
  510. (e.g., ISA bus). For PCI bus systems, this routine will likely fail
  511. unless one of the IRQs listed in the ints array is used by the board.
  512. Sometimes it is possible to use the computer's BIOS setup screen to
  513. configure a PCI system so that one of these IRQs will be used by the
  514. Future Domain card. */
  515. static int fdomain_get_irq( int base )
  516. {
  517. int options = inb(base + Configuration1);
  518. #if DEBUG_DETECT
  519. printk("scsi: <fdomain> Options = %x\n", options);
  520. #endif
  521. /* Check for board with lowest bios_base --
  522. this isn't valid for the 18c30 or for
  523. boards on the PCI bus, so just assume we
  524. have the right board. */
  525. if (chip != tmc18c30 && !PCI_bus && addresses[(options & 0xc0) >> 6 ] != bios_base)
  526. return 0;
  527. return ints[(options & 0x0e) >> 1];
  528. }
  529. static int fdomain_isa_detect( int *irq, int *iobase )
  530. {
  531. #ifndef PCMCIA
  532. int i, j;
  533. int base = 0xdeadbeef;
  534. int flag = 0;
  535. #if DEBUG_DETECT
  536. printk( "scsi: <fdomain> fdomain_isa_detect:" );
  537. #endif
  538. for (i = 0; i < ADDRESS_COUNT; i++) {
  539. void __iomem *p = ioremap(addresses[i], 0x2000);
  540. if (!p)
  541. continue;
  542. #if DEBUG_DETECT
  543. printk( " %lx(%lx),", addresses[i], bios_base );
  544. #endif
  545. for (j = 0; j < SIGNATURE_COUNT; j++) {
  546. if (check_signature(p + signatures[j].sig_offset,
  547. signatures[j].signature,
  548. signatures[j].sig_length )) {
  549. bios_major = signatures[j].major_bios_version;
  550. bios_minor = signatures[j].minor_bios_version;
  551. PCI_bus = (signatures[j].flag == 1);
  552. Quantum = (signatures[j].flag > 1) ? signatures[j].flag : 0;
  553. bios_base = addresses[i];
  554. bios_mem = p;
  555. goto found;
  556. }
  557. }
  558. iounmap(p);
  559. }
  560. found:
  561. if (bios_major == 2) {
  562. /* The TMC-1660/TMC-1680 has a RAM area just after the BIOS ROM.
  563. Assuming the ROM is enabled (otherwise we wouldn't have been
  564. able to read the ROM signature :-), then the ROM sets up the
  565. RAM area with some magic numbers, such as a list of port
  566. base addresses and a list of the disk "geometry" reported to
  567. DOS (this geometry has nothing to do with physical geometry).
  568. */
  569. switch (Quantum) {
  570. case 2: /* ISA_200S */
  571. case 3: /* ISA_250MG */
  572. base = readb(bios_mem + 0x1fa2) + (readb(bios_mem + 0x1fa3) << 8);
  573. break;
  574. case 4: /* ISA_200S (another one) */
  575. base = readb(bios_mem + 0x1fa3) + (readb(bios_mem + 0x1fa4) << 8);
  576. break;
  577. default:
  578. base = readb(bios_mem + 0x1fcc) + (readb(bios_mem + 0x1fcd) << 8);
  579. break;
  580. }
  581. #if DEBUG_DETECT
  582. printk( " %x,", base );
  583. #endif
  584. for (i = 0; i < PORT_COUNT; i++) {
  585. if (base == ports[i]) {
  586. if (!request_region(base, 0x10, "fdomain"))
  587. break;
  588. if (!fdomain_is_valid_port(base)) {
  589. release_region(base, 0x10);
  590. break;
  591. }
  592. *irq = fdomain_get_irq( base );
  593. *iobase = base;
  594. return 1;
  595. }
  596. }
  597. /* This is a bad sign. It usually means that someone patched the
  598. BIOS signature list (the signatures variable) to contain a BIOS
  599. signature for a board *OTHER THAN* the TMC-1660/TMC-1680. */
  600. #if DEBUG_DETECT
  601. printk( " RAM FAILED, " );
  602. #endif
  603. }
  604. /* Anyway, the alternative to finding the address in the RAM is to just
  605. search through every possible port address for one that is attached
  606. to the Future Domain card. Don't panic, though, about reading all
  607. these random port addresses -- there are rumors that the Future
  608. Domain BIOS does something very similar.
  609. Do not, however, check ports which the kernel knows are being used by
  610. another driver. */
  611. for (i = 0; i < PORT_COUNT; i++) {
  612. base = ports[i];
  613. if (!request_region(base, 0x10, "fdomain")) {
  614. #if DEBUG_DETECT
  615. printk( " (%x inuse),", base );
  616. #endif
  617. continue;
  618. }
  619. #if DEBUG_DETECT
  620. printk( " %x,", base );
  621. #endif
  622. flag = fdomain_is_valid_port(base);
  623. if (flag)
  624. break;
  625. release_region(base, 0x10);
  626. }
  627. #if DEBUG_DETECT
  628. if (flag) printk( " SUCCESS\n" );
  629. else printk( " FAILURE\n" );
  630. #endif
  631. if (!flag) return 0; /* iobase not found */
  632. *irq = fdomain_get_irq( base );
  633. *iobase = base;
  634. return 1; /* success */
  635. #else
  636. return 0;
  637. #endif
  638. }
  639. /* PCI detection function: int fdomain_pci_bios_detect(int* irq, int*
  640. iobase) This function gets the Interrupt Level and I/O base address from
  641. the PCI configuration registers. */
  642. #ifdef CONFIG_PCI
  643. static int fdomain_pci_bios_detect( int *irq, int *iobase, struct pci_dev **ret_pdev )
  644. {
  645. unsigned int pci_irq; /* PCI interrupt line */
  646. unsigned long pci_base; /* PCI I/O base address */
  647. struct pci_dev *pdev = NULL;
  648. #if DEBUG_DETECT
  649. /* Tell how to print a list of the known PCI devices from bios32 and
  650. list vendor and device IDs being used if in debug mode. */
  651. printk( "scsi: <fdomain> INFO: use lspci -v to see list of PCI devices\n" );
  652. printk( "scsi: <fdomain> TMC-3260 detect:"
  653. " Using Vendor ID: 0x%x and Device ID: 0x%x\n",
  654. PCI_VENDOR_ID_FD,
  655. PCI_DEVICE_ID_FD_36C70 );
  656. #endif
  657. if ((pdev = pci_get_device(PCI_VENDOR_ID_FD, PCI_DEVICE_ID_FD_36C70, pdev)) == NULL)
  658. return 0;
  659. if (pci_enable_device(pdev))
  660. goto fail;
  661. #if DEBUG_DETECT
  662. printk( "scsi: <fdomain> TMC-3260 detect:"
  663. " PCI bus %u, device %u, function %u\n",
  664. pdev->bus->number,
  665. PCI_SLOT(pdev->devfn),
  666. PCI_FUNC(pdev->devfn));
  667. #endif
  668. /* We now have the appropriate device function for the FD board so we
  669. just read the PCI config info from the registers. */
  670. pci_base = pci_resource_start(pdev, 0);
  671. pci_irq = pdev->irq;
  672. if (!request_region( pci_base, 0x10, "fdomain" ))
  673. goto fail;
  674. /* Now we have the I/O base address and interrupt from the PCI
  675. configuration registers. */
  676. *irq = pci_irq;
  677. *iobase = pci_base;
  678. *ret_pdev = pdev;
  679. #if DEBUG_DETECT
  680. printk( "scsi: <fdomain> TMC-3260 detect:"
  681. " IRQ = %d, I/O base = 0x%x [0x%lx]\n", *irq, *iobase, pci_base );
  682. #endif
  683. if (!fdomain_is_valid_port(pci_base)) {
  684. printk(KERN_ERR "scsi: <fdomain> PCI card detected, but driver not loaded (invalid port)\n" );
  685. release_region(pci_base, 0x10);
  686. goto fail;
  687. }
  688. /* Fill in a few global variables. Ugh. */
  689. bios_major = bios_minor = -1;
  690. PCI_bus = 1;
  691. PCI_dev = pdev;
  692. Quantum = 0;
  693. bios_base = 0;
  694. return 1;
  695. fail:
  696. pci_dev_put(pdev);
  697. return 0;
  698. }
  699. #endif
  700. struct Scsi_Host *__fdomain_16x0_detect(struct scsi_host_template *tpnt )
  701. {
  702. int retcode;
  703. struct Scsi_Host *shpnt;
  704. struct pci_dev *pdev = NULL;
  705. if (setup_called) {
  706. #if DEBUG_DETECT
  707. printk( "scsi: <fdomain> No BIOS, using port_base = 0x%x, irq = %d\n",
  708. port_base, interrupt_level );
  709. #endif
  710. if (!request_region(port_base, 0x10, "fdomain")) {
  711. printk( "scsi: <fdomain> port 0x%x is busy\n", port_base );
  712. printk( "scsi: <fdomain> Bad LILO/INSMOD parameters?\n" );
  713. return NULL;
  714. }
  715. if (!fdomain_is_valid_port( port_base )) {
  716. printk( "scsi: <fdomain> Cannot locate chip at port base 0x%x\n",
  717. port_base );
  718. printk( "scsi: <fdomain> Bad LILO/INSMOD parameters?\n" );
  719. release_region(port_base, 0x10);
  720. return NULL;
  721. }
  722. } else {
  723. int flag = 0;
  724. #ifdef CONFIG_PCI
  725. /* Try PCI detection first */
  726. flag = fdomain_pci_bios_detect( &interrupt_level, &port_base, &pdev );
  727. #endif
  728. if (!flag) {
  729. /* Then try ISA bus detection */
  730. flag = fdomain_isa_detect( &interrupt_level, &port_base );
  731. if (!flag) {
  732. printk( "scsi: <fdomain> Detection failed (no card)\n" );
  733. return NULL;
  734. }
  735. }
  736. }
  737. fdomain_16x0_bus_reset(NULL);
  738. if (fdomain_test_loopback()) {
  739. printk(KERN_ERR "scsi: <fdomain> Detection failed (loopback test failed at port base 0x%x)\n", port_base);
  740. if (setup_called) {
  741. printk(KERN_ERR "scsi: <fdomain> Bad LILO/INSMOD parameters?\n");
  742. }
  743. goto fail;
  744. }
  745. if (this_id) {
  746. tpnt->this_id = (this_id & 0x07);
  747. adapter_mask = (1 << tpnt->this_id);
  748. } else {
  749. if (PCI_bus || (bios_major == 3 && bios_minor >= 2) || bios_major < 0) {
  750. tpnt->this_id = 7;
  751. adapter_mask = 0x80;
  752. } else {
  753. tpnt->this_id = 6;
  754. adapter_mask = 0x40;
  755. }
  756. }
  757. /* Print out a banner here in case we can't
  758. get resources. */
  759. shpnt = scsi_register( tpnt, 0 );
  760. if(shpnt == NULL) {
  761. release_region(port_base, 0x10);
  762. return NULL;
  763. }
  764. shpnt->irq = interrupt_level;
  765. shpnt->io_port = port_base;
  766. shpnt->n_io_port = 0x10;
  767. print_banner( shpnt );
  768. /* Log IRQ with kernel */
  769. if (!interrupt_level) {
  770. printk(KERN_ERR "scsi: <fdomain> Card Detected, but driver not loaded (no IRQ)\n" );
  771. goto fail;
  772. } else {
  773. /* Register the IRQ with the kernel */
  774. retcode = request_irq( interrupt_level,
  775. do_fdomain_16x0_intr, pdev?IRQF_SHARED:0, "fdomain", shpnt);
  776. if (retcode < 0) {
  777. if (retcode == -EINVAL) {
  778. printk(KERN_ERR "scsi: <fdomain> IRQ %d is bad!\n", interrupt_level );
  779. printk(KERN_ERR " This shouldn't happen!\n" );
  780. printk(KERN_ERR " Send mail to faith@acm.org\n" );
  781. } else if (retcode == -EBUSY) {
  782. printk(KERN_ERR "scsi: <fdomain> IRQ %d is already in use!\n", interrupt_level );
  783. printk(KERN_ERR " Please use another IRQ!\n" );
  784. } else {
  785. printk(KERN_ERR "scsi: <fdomain> Error getting IRQ %d\n", interrupt_level );
  786. printk(KERN_ERR " This shouldn't happen!\n" );
  787. printk(KERN_ERR " Send mail to faith@acm.org\n" );
  788. }
  789. printk(KERN_ERR "scsi: <fdomain> Detected, but driver not loaded (IRQ)\n" );
  790. goto fail;
  791. }
  792. }
  793. return shpnt;
  794. fail:
  795. pci_dev_put(pdev);
  796. release_region(port_base, 0x10);
  797. return NULL;
  798. }
  799. static int fdomain_16x0_detect(struct scsi_host_template *tpnt)
  800. {
  801. if (fdomain)
  802. fdomain_setup(fdomain);
  803. return (__fdomain_16x0_detect(tpnt) != NULL);
  804. }
  805. static const char *fdomain_16x0_info( struct Scsi_Host *ignore )
  806. {
  807. static char buffer[128];
  808. char *pt;
  809. strcpy( buffer, "Future Domain 16-bit SCSI Driver Version" );
  810. if (strchr( VERSION, ':')) { /* Assume VERSION is an RCS Revision string */
  811. strcat( buffer, strchr( VERSION, ':' ) + 1 );
  812. pt = strrchr( buffer, '$') - 1;
  813. if (!pt) /* Stripped RCS Revision string? */
  814. pt = buffer + strlen( buffer ) - 1;
  815. if (*pt != ' ')
  816. ++pt;
  817. *pt = '\0';
  818. } else { /* Assume VERSION is a number */
  819. strcat( buffer, " " VERSION );
  820. }
  821. return buffer;
  822. }
  823. #if 0
  824. static int fdomain_arbitrate( void )
  825. {
  826. int status = 0;
  827. unsigned long timeout;
  828. #if EVERY_ACCESS
  829. printk( "fdomain_arbitrate()\n" );
  830. #endif
  831. outb(0x00, port_base + SCSI_Cntl); /* Disable data drivers */
  832. outb(adapter_mask, port_base + SCSI_Data_NoACK); /* Set our id bit */
  833. outb(0x04 | PARITY_MASK, port_base + TMC_Cntl); /* Start arbitration */
  834. timeout = 500;
  835. do {
  836. status = inb(port_base + TMC_Status); /* Read adapter status */
  837. if (status & 0x02) /* Arbitration complete */
  838. return 0;
  839. mdelay(1); /* Wait one millisecond */
  840. } while (--timeout);
  841. /* Make bus idle */
  842. fdomain_make_bus_idle();
  843. #if EVERY_ACCESS
  844. printk( "Arbitration failed, status = %x\n", status );
  845. #endif
  846. #if ERRORS_ONLY
  847. printk( "scsi: <fdomain> Arbitration failed, status = %x\n", status );
  848. #endif
  849. return 1;
  850. }
  851. #endif
  852. static int fdomain_select( int target )
  853. {
  854. int status;
  855. unsigned long timeout;
  856. #if ERRORS_ONLY
  857. static int flag = 0;
  858. #endif
  859. outb(0x82, port_base + SCSI_Cntl); /* Bus Enable + Select */
  860. outb(adapter_mask | (1 << target), port_base + SCSI_Data_NoACK);
  861. /* Stop arbitration and enable parity */
  862. outb(PARITY_MASK, port_base + TMC_Cntl);
  863. timeout = 350; /* 350 msec */
  864. do {
  865. status = inb(port_base + SCSI_Status); /* Read adapter status */
  866. if (status & 1) { /* Busy asserted */
  867. /* Enable SCSI Bus (on error, should make bus idle with 0) */
  868. outb(0x80, port_base + SCSI_Cntl);
  869. return 0;
  870. }
  871. mdelay(1); /* wait one msec */
  872. } while (--timeout);
  873. /* Make bus idle */
  874. fdomain_make_bus_idle();
  875. #if EVERY_ACCESS
  876. if (!target) printk( "Selection failed\n" );
  877. #endif
  878. #if ERRORS_ONLY
  879. if (!target) {
  880. if (!flag) /* Skip first failure for all chips. */
  881. ++flag;
  882. else
  883. printk( "scsi: <fdomain> Selection failed\n" );
  884. }
  885. #endif
  886. return 1;
  887. }
  888. static void my_done(int error)
  889. {
  890. if (in_command) {
  891. in_command = 0;
  892. outb(0x00, port_base + Interrupt_Cntl);
  893. fdomain_make_bus_idle();
  894. current_SC->result = error;
  895. if (current_SC->scsi_done)
  896. current_SC->scsi_done( current_SC );
  897. else panic( "scsi: <fdomain> current_SC->scsi_done() == NULL" );
  898. } else {
  899. panic( "scsi: <fdomain> my_done() called outside of command\n" );
  900. }
  901. #if DEBUG_RACE
  902. in_interrupt_flag = 0;
  903. #endif
  904. }
  905. static irqreturn_t do_fdomain_16x0_intr(int irq, void *dev_id)
  906. {
  907. unsigned long flags;
  908. int status;
  909. int done = 0;
  910. unsigned data_count;
  911. /* The fdomain_16x0_intr is only called via
  912. the interrupt handler. The goal of the
  913. sti() here is to allow other
  914. interruptions while this routine is
  915. running. */
  916. /* Check for other IRQ sources */
  917. if ((inb(port_base + TMC_Status) & 0x01) == 0)
  918. return IRQ_NONE;
  919. /* It is our IRQ */
  920. outb(0x00, port_base + Interrupt_Cntl);
  921. /* We usually have one spurious interrupt after each command. Ignore it. */
  922. if (!in_command || !current_SC) { /* Spurious interrupt */
  923. #if EVERY_ACCESS
  924. printk( "Spurious interrupt, in_command = %d, current_SC = %x\n",
  925. in_command, current_SC );
  926. #endif
  927. return IRQ_NONE;
  928. }
  929. /* Abort calls my_done, so we do nothing here. */
  930. if (current_SC->SCp.phase & aborted) {
  931. #if DEBUG_ABORT
  932. printk( "scsi: <fdomain> Interrupt after abort, ignoring\n" );
  933. #endif
  934. /*
  935. return IRQ_HANDLED; */
  936. }
  937. #if DEBUG_RACE
  938. ++in_interrupt_flag;
  939. #endif
  940. if (current_SC->SCp.phase & in_arbitration) {
  941. status = inb(port_base + TMC_Status); /* Read adapter status */
  942. if (!(status & 0x02)) {
  943. #if EVERY_ACCESS
  944. printk( " AFAIL " );
  945. #endif
  946. spin_lock_irqsave(current_SC->device->host->host_lock, flags);
  947. my_done( DID_BUS_BUSY << 16 );
  948. spin_unlock_irqrestore(current_SC->device->host->host_lock, flags);
  949. return IRQ_HANDLED;
  950. }
  951. current_SC->SCp.phase = in_selection;
  952. outb(0x40 | FIFO_COUNT, port_base + Interrupt_Cntl);
  953. outb(0x82, port_base + SCSI_Cntl); /* Bus Enable + Select */
  954. outb(adapter_mask | (1 << scmd_id(current_SC)), port_base + SCSI_Data_NoACK);
  955. /* Stop arbitration and enable parity */
  956. outb(0x10 | PARITY_MASK, port_base + TMC_Cntl);
  957. #if DEBUG_RACE
  958. in_interrupt_flag = 0;
  959. #endif
  960. return IRQ_HANDLED;
  961. } else if (current_SC->SCp.phase & in_selection) {
  962. status = inb(port_base + SCSI_Status);
  963. if (!(status & 0x01)) {
  964. /* Try again, for slow devices */
  965. if (fdomain_select( scmd_id(current_SC) )) {
  966. #if EVERY_ACCESS
  967. printk( " SFAIL " );
  968. #endif
  969. spin_lock_irqsave(current_SC->device->host->host_lock, flags);
  970. my_done( DID_NO_CONNECT << 16 );
  971. spin_unlock_irqrestore(current_SC->device->host->host_lock, flags);
  972. return IRQ_HANDLED;
  973. } else {
  974. #if EVERY_ACCESS
  975. printk( " AltSel " );
  976. #endif
  977. /* Stop arbitration and enable parity */
  978. outb(0x10 | PARITY_MASK, port_base + TMC_Cntl);
  979. }
  980. }
  981. current_SC->SCp.phase = in_other;
  982. outb(0x90 | FIFO_COUNT, port_base + Interrupt_Cntl);
  983. outb(0x80, port_base + SCSI_Cntl);
  984. #if DEBUG_RACE
  985. in_interrupt_flag = 0;
  986. #endif
  987. return IRQ_HANDLED;
  988. }
  989. /* current_SC->SCp.phase == in_other: this is the body of the routine */
  990. status = inb(port_base + SCSI_Status);
  991. if (status & 0x10) { /* REQ */
  992. switch (status & 0x0e) {
  993. case 0x08: /* COMMAND OUT */
  994. outb(current_SC->cmnd[current_SC->SCp.sent_command++],
  995. port_base + Write_SCSI_Data);
  996. #if EVERY_ACCESS
  997. printk( "CMD = %x,",
  998. current_SC->cmnd[ current_SC->SCp.sent_command - 1] );
  999. #endif
  1000. break;
  1001. case 0x00: /* DATA OUT -- tmc18c50/tmc18c30 only */
  1002. if (chip != tmc1800 && !current_SC->SCp.have_data_in) {
  1003. current_SC->SCp.have_data_in = -1;
  1004. outb(0xd0 | PARITY_MASK, port_base + TMC_Cntl);
  1005. }
  1006. break;
  1007. case 0x04: /* DATA IN -- tmc18c50/tmc18c30 only */
  1008. if (chip != tmc1800 && !current_SC->SCp.have_data_in) {
  1009. current_SC->SCp.have_data_in = 1;
  1010. outb(0x90 | PARITY_MASK, port_base + TMC_Cntl);
  1011. }
  1012. break;
  1013. case 0x0c: /* STATUS IN */
  1014. current_SC->SCp.Status = inb(port_base + Read_SCSI_Data);
  1015. #if EVERY_ACCESS
  1016. printk( "Status = %x, ", current_SC->SCp.Status );
  1017. #endif
  1018. #if ERRORS_ONLY
  1019. if (current_SC->SCp.Status
  1020. && current_SC->SCp.Status != 2
  1021. && current_SC->SCp.Status != 8) {
  1022. printk( "scsi: <fdomain> target = %d, command = %x, status = %x\n",
  1023. current_SC->device->id,
  1024. current_SC->cmnd[0],
  1025. current_SC->SCp.Status );
  1026. }
  1027. #endif
  1028. break;
  1029. case 0x0a: /* MESSAGE OUT */
  1030. outb(MESSAGE_REJECT, port_base + Write_SCSI_Data); /* Reject */
  1031. break;
  1032. case 0x0e: /* MESSAGE IN */
  1033. current_SC->SCp.Message = inb(port_base + Read_SCSI_Data);
  1034. #if EVERY_ACCESS
  1035. printk( "Message = %x, ", current_SC->SCp.Message );
  1036. #endif
  1037. if (!current_SC->SCp.Message) ++done;
  1038. #if DEBUG_MESSAGES || EVERY_ACCESS
  1039. if (current_SC->SCp.Message) {
  1040. printk( "scsi: <fdomain> message = %x\n",
  1041. current_SC->SCp.Message );
  1042. }
  1043. #endif
  1044. break;
  1045. }
  1046. }
  1047. if (chip == tmc1800 && !current_SC->SCp.have_data_in
  1048. && (current_SC->SCp.sent_command >= current_SC->cmd_len)) {
  1049. if(current_SC->sc_data_direction == DMA_TO_DEVICE)
  1050. {
  1051. current_SC->SCp.have_data_in = -1;
  1052. outb(0xd0 | PARITY_MASK, port_base + TMC_Cntl);
  1053. }
  1054. else
  1055. {
  1056. current_SC->SCp.have_data_in = 1;
  1057. outb(0x90 | PARITY_MASK, port_base + TMC_Cntl);
  1058. }
  1059. }
  1060. if (current_SC->SCp.have_data_in == -1) { /* DATA OUT */
  1061. while ((data_count = FIFO_Size - inw(port_base + FIFO_Data_Count)) > 512) {
  1062. #if EVERY_ACCESS
  1063. printk( "DC=%d, ", data_count ) ;
  1064. #endif
  1065. if (data_count > current_SC->SCp.this_residual)
  1066. data_count = current_SC->SCp.this_residual;
  1067. if (data_count > 0) {
  1068. #if EVERY_ACCESS
  1069. printk( "%d OUT, ", data_count );
  1070. #endif
  1071. if (data_count == 1) {
  1072. outb(*current_SC->SCp.ptr++, port_base + Write_FIFO);
  1073. --current_SC->SCp.this_residual;
  1074. } else {
  1075. data_count >>= 1;
  1076. outsw(port_base + Write_FIFO, current_SC->SCp.ptr, data_count);
  1077. current_SC->SCp.ptr += 2 * data_count;
  1078. current_SC->SCp.this_residual -= 2 * data_count;
  1079. }
  1080. }
  1081. if (!current_SC->SCp.this_residual) {
  1082. if (current_SC->SCp.buffers_residual) {
  1083. --current_SC->SCp.buffers_residual;
  1084. ++current_SC->SCp.buffer;
  1085. current_SC->SCp.ptr = page_address(current_SC->SCp.buffer->page) + current_SC->SCp.buffer->offset;
  1086. current_SC->SCp.this_residual = current_SC->SCp.buffer->length;
  1087. } else
  1088. break;
  1089. }
  1090. }
  1091. }
  1092. if (current_SC->SCp.have_data_in == 1) { /* DATA IN */
  1093. while ((data_count = inw(port_base + FIFO_Data_Count)) > 0) {
  1094. #if EVERY_ACCESS
  1095. printk( "DC=%d, ", data_count );
  1096. #endif
  1097. if (data_count > current_SC->SCp.this_residual)
  1098. data_count = current_SC->SCp.this_residual;
  1099. if (data_count) {
  1100. #if EVERY_ACCESS
  1101. printk( "%d IN, ", data_count );
  1102. #endif
  1103. if (data_count == 1) {
  1104. *current_SC->SCp.ptr++ = inb(port_base + Read_FIFO);
  1105. --current_SC->SCp.this_residual;
  1106. } else {
  1107. data_count >>= 1; /* Number of words */
  1108. insw(port_base + Read_FIFO, current_SC->SCp.ptr, data_count);
  1109. current_SC->SCp.ptr += 2 * data_count;
  1110. current_SC->SCp.this_residual -= 2 * data_count;
  1111. }
  1112. }
  1113. if (!current_SC->SCp.this_residual
  1114. && current_SC->SCp.buffers_residual) {
  1115. --current_SC->SCp.buffers_residual;
  1116. ++current_SC->SCp.buffer;
  1117. current_SC->SCp.ptr = page_address(current_SC->SCp.buffer->page) + current_SC->SCp.buffer->offset;
  1118. current_SC->SCp.this_residual = current_SC->SCp.buffer->length;
  1119. }
  1120. }
  1121. }
  1122. if (done) {
  1123. #if EVERY_ACCESS
  1124. printk( " ** IN DONE %d ** ", current_SC->SCp.have_data_in );
  1125. #endif
  1126. #if ERRORS_ONLY
  1127. if (current_SC->cmnd[0] == REQUEST_SENSE && !current_SC->SCp.Status) {
  1128. if ((unsigned char)(*((char *)current_SC->request_buffer+2)) & 0x0f) {
  1129. unsigned char key;
  1130. unsigned char code;
  1131. unsigned char qualifier;
  1132. key = (unsigned char)(*((char *)current_SC->request_buffer + 2))
  1133. & 0x0f;
  1134. code = (unsigned char)(*((char *)current_SC->request_buffer + 12));
  1135. qualifier = (unsigned char)(*((char *)current_SC->request_buffer
  1136. + 13));
  1137. if (key != UNIT_ATTENTION
  1138. && !(key == NOT_READY
  1139. && code == 0x04
  1140. && (!qualifier || qualifier == 0x02 || qualifier == 0x01))
  1141. && !(key == ILLEGAL_REQUEST && (code == 0x25
  1142. || code == 0x24
  1143. || !code)))
  1144. printk( "scsi: <fdomain> REQUEST SENSE"
  1145. " Key = %x, Code = %x, Qualifier = %x\n",
  1146. key, code, qualifier );
  1147. }
  1148. }
  1149. #endif
  1150. #if EVERY_ACCESS
  1151. printk( "BEFORE MY_DONE. . ." );
  1152. #endif
  1153. spin_lock_irqsave(current_SC->device->host->host_lock, flags);
  1154. my_done( (current_SC->SCp.Status & 0xff)
  1155. | ((current_SC->SCp.Message & 0xff) << 8) | (DID_OK << 16) );
  1156. spin_unlock_irqrestore(current_SC->device->host->host_lock, flags);
  1157. #if EVERY_ACCESS
  1158. printk( "RETURNING.\n" );
  1159. #endif
  1160. } else {
  1161. if (current_SC->SCp.phase & disconnect) {
  1162. outb(0xd0 | FIFO_COUNT, port_base + Interrupt_Cntl);
  1163. outb(0x00, port_base + SCSI_Cntl);
  1164. } else {
  1165. outb(0x90 | FIFO_COUNT, port_base + Interrupt_Cntl);
  1166. }
  1167. }
  1168. #if DEBUG_RACE
  1169. in_interrupt_flag = 0;
  1170. #endif
  1171. return IRQ_HANDLED;
  1172. }
  1173. static int fdomain_16x0_queue(struct scsi_cmnd *SCpnt,
  1174. void (*done)(struct scsi_cmnd *))
  1175. {
  1176. if (in_command) {
  1177. panic( "scsi: <fdomain> fdomain_16x0_queue() NOT REENTRANT!\n" );
  1178. }
  1179. #if EVERY_ACCESS
  1180. printk( "queue: target = %d cmnd = 0x%02x pieces = %d size = %u\n",
  1181. SCpnt->target,
  1182. *(unsigned char *)SCpnt->cmnd,
  1183. SCpnt->use_sg,
  1184. SCpnt->request_bufflen );
  1185. #endif
  1186. fdomain_make_bus_idle();
  1187. current_SC = SCpnt; /* Save this for the done function */
  1188. current_SC->scsi_done = done;
  1189. /* Initialize static data */
  1190. if (current_SC->use_sg) {
  1191. current_SC->SCp.buffer =
  1192. (struct scatterlist *)current_SC->request_buffer;
  1193. current_SC->SCp.ptr = page_address(current_SC->SCp.buffer->page) + current_SC->SCp.buffer->offset;
  1194. current_SC->SCp.this_residual = current_SC->SCp.buffer->length;
  1195. current_SC->SCp.buffers_residual = current_SC->use_sg - 1;
  1196. } else {
  1197. current_SC->SCp.ptr = (char *)current_SC->request_buffer;
  1198. current_SC->SCp.this_residual = current_SC->request_bufflen;
  1199. current_SC->SCp.buffer = NULL;
  1200. current_SC->SCp.buffers_residual = 0;
  1201. }
  1202. current_SC->SCp.Status = 0;
  1203. current_SC->SCp.Message = 0;
  1204. current_SC->SCp.have_data_in = 0;
  1205. current_SC->SCp.sent_command = 0;
  1206. current_SC->SCp.phase = in_arbitration;
  1207. /* Start arbitration */
  1208. outb(0x00, port_base + Interrupt_Cntl);
  1209. outb(0x00, port_base + SCSI_Cntl); /* Disable data drivers */
  1210. outb(adapter_mask, port_base + SCSI_Data_NoACK); /* Set our id bit */
  1211. ++in_command;
  1212. outb(0x20, port_base + Interrupt_Cntl);
  1213. outb(0x14 | PARITY_MASK, port_base + TMC_Cntl); /* Start arbitration */
  1214. return 0;
  1215. }
  1216. #if DEBUG_ABORT
  1217. static void print_info(struct scsi_cmnd *SCpnt)
  1218. {
  1219. unsigned int imr;
  1220. unsigned int irr;
  1221. unsigned int isr;
  1222. if (!SCpnt || !SCpnt->device || !SCpnt->device->host) {
  1223. printk(KERN_WARNING "scsi: <fdomain> Cannot provide detailed information\n");
  1224. return;
  1225. }
  1226. printk(KERN_INFO "%s\n", fdomain_16x0_info( SCpnt->device->host ) );
  1227. print_banner(SCpnt->device->host);
  1228. switch (SCpnt->SCp.phase) {
  1229. case in_arbitration: printk("arbitration"); break;
  1230. case in_selection: printk("selection"); break;
  1231. case in_other: printk("other"); break;
  1232. default: printk("unknown"); break;
  1233. }
  1234. printk( " (%d), target = %d cmnd = 0x%02x pieces = %d size = %u\n",
  1235. SCpnt->SCp.phase,
  1236. SCpnt->device->id,
  1237. *(unsigned char *)SCpnt->cmnd,
  1238. SCpnt->use_sg,
  1239. SCpnt->request_bufflen );
  1240. printk( "sent_command = %d, have_data_in = %d, timeout = %d\n",
  1241. SCpnt->SCp.sent_command,
  1242. SCpnt->SCp.have_data_in,
  1243. SCpnt->timeout );
  1244. #if DEBUG_RACE
  1245. printk( "in_interrupt_flag = %d\n", in_interrupt_flag );
  1246. #endif
  1247. imr = (inb( 0x0a1 ) << 8) + inb( 0x21 );
  1248. outb( 0x0a, 0xa0 );
  1249. irr = inb( 0xa0 ) << 8;
  1250. outb( 0x0a, 0x20 );
  1251. irr += inb( 0x20 );
  1252. outb( 0x0b, 0xa0 );
  1253. isr = inb( 0xa0 ) << 8;
  1254. outb( 0x0b, 0x20 );
  1255. isr += inb( 0x20 );
  1256. /* Print out interesting information */
  1257. printk( "IMR = 0x%04x", imr );
  1258. if (imr & (1 << interrupt_level))
  1259. printk( " (masked)" );
  1260. printk( ", IRR = 0x%04x, ISR = 0x%04x\n", irr, isr );
  1261. printk( "SCSI Status = 0x%02x\n", inb(port_base + SCSI_Status));
  1262. printk( "TMC Status = 0x%02x", inb(port_base + TMC_Status));
  1263. if (inb((port_base + TMC_Status) & 1))
  1264. printk( " (interrupt)" );
  1265. printk( "\n" );
  1266. printk("Interrupt Status = 0x%02x", inb(port_base + Interrupt_Status));
  1267. if (inb(port_base + Interrupt_Status) & 0x08)
  1268. printk( " (enabled)" );
  1269. printk( "\n" );
  1270. if (chip == tmc18c50 || chip == tmc18c30) {
  1271. printk("FIFO Status = 0x%02x\n", inb(port_base + FIFO_Status));
  1272. printk( "Int. Condition = 0x%02x\n",
  1273. inb( port_base + Interrupt_Cond ) );
  1274. }
  1275. printk( "Configuration 1 = 0x%02x\n", inb( port_base + Configuration1 ) );
  1276. if (chip == tmc18c50 || chip == tmc18c30)
  1277. printk( "Configuration 2 = 0x%02x\n",
  1278. inb( port_base + Configuration2 ) );
  1279. }
  1280. #endif
  1281. static int fdomain_16x0_abort(struct scsi_cmnd *SCpnt)
  1282. {
  1283. #if EVERY_ACCESS || ERRORS_ONLY || DEBUG_ABORT
  1284. printk( "scsi: <fdomain> abort " );
  1285. #endif
  1286. if (!in_command) {
  1287. #if EVERY_ACCESS || ERRORS_ONLY
  1288. printk( " (not in command)\n" );
  1289. #endif
  1290. return FAILED;
  1291. } else printk( "\n" );
  1292. #if DEBUG_ABORT
  1293. print_info( SCpnt );
  1294. #endif
  1295. fdomain_make_bus_idle();
  1296. current_SC->SCp.phase |= aborted;
  1297. current_SC->result = DID_ABORT << 16;
  1298. /* Aborts are not done well. . . */
  1299. my_done(DID_ABORT << 16);
  1300. return SUCCESS;
  1301. }
  1302. int fdomain_16x0_bus_reset(struct scsi_cmnd *SCpnt)
  1303. {
  1304. unsigned long flags;
  1305. local_irq_save(flags);
  1306. outb(1, port_base + SCSI_Cntl);
  1307. do_pause( 2 );
  1308. outb(0, port_base + SCSI_Cntl);
  1309. do_pause( 115 );
  1310. outb(0, port_base + SCSI_Mode_Cntl);
  1311. outb(PARITY_MASK, port_base + TMC_Cntl);
  1312. local_irq_restore(flags);
  1313. return SUCCESS;
  1314. }
  1315. static int fdomain_16x0_biosparam(struct scsi_device *sdev,
  1316. struct block_device *bdev,
  1317. sector_t capacity, int *info_array)
  1318. {
  1319. int drive;
  1320. int size = capacity;
  1321. unsigned long offset;
  1322. struct drive_info {
  1323. unsigned short cylinders;
  1324. unsigned char heads;
  1325. unsigned char sectors;
  1326. } i;
  1327. /* NOTES:
  1328. The RAM area starts at 0x1f00 from the bios_base address.
  1329. For BIOS Version 2.0:
  1330. The drive parameter table seems to start at 0x1f30.
  1331. The first byte's purpose is not known.
  1332. Next is the cylinder, head, and sector information.
  1333. The last 4 bytes appear to be the drive's size in sectors.
  1334. The other bytes in the drive parameter table are unknown.
  1335. If anyone figures them out, please send me mail, and I will
  1336. update these notes.
  1337. Tape drives do not get placed in this table.
  1338. There is another table at 0x1fea:
  1339. If the byte is 0x01, then the SCSI ID is not in use.
  1340. If the byte is 0x18 or 0x48, then the SCSI ID is in use,
  1341. although tapes don't seem to be in this table. I haven't
  1342. seen any other numbers (in a limited sample).
  1343. 0x1f2d is a drive count (i.e., not including tapes)
  1344. The table at 0x1fcc are I/O ports addresses for the various
  1345. operations. I calculate these by hand in this driver code.
  1346. For the ISA-200S version of BIOS Version 2.0:
  1347. The drive parameter table starts at 0x1f33.
  1348. WARNING: Assume that the table entry is 25 bytes long. Someone needs
  1349. to check this for the Quantum ISA-200S card.
  1350. For BIOS Version 3.2:
  1351. The drive parameter table starts at 0x1f70. Each entry is
  1352. 0x0a bytes long. Heads are one less than we need to report.
  1353. */
  1354. if (MAJOR(bdev->bd_dev) != SCSI_DISK0_MAJOR) {
  1355. printk("scsi: <fdomain> fdomain_16x0_biosparam: too many disks");
  1356. return 0;
  1357. }
  1358. drive = MINOR(bdev->bd_dev) >> 4;
  1359. if (bios_major == 2) {
  1360. switch (Quantum) {
  1361. case 2: /* ISA_200S */
  1362. /* The value of 25 has never been verified.
  1363. It should probably be 15. */
  1364. offset = 0x1f33 + drive * 25;
  1365. break;
  1366. case 3: /* ISA_250MG */
  1367. offset = 0x1f36 + drive * 15;
  1368. break;
  1369. case 4: /* ISA_200S (another one) */
  1370. offset = 0x1f34 + drive * 15;
  1371. break;
  1372. default:
  1373. offset = 0x1f31 + drive * 25;
  1374. break;
  1375. }
  1376. memcpy_fromio( &i, bios_mem + offset, sizeof( struct drive_info ) );
  1377. info_array[0] = i.heads;
  1378. info_array[1] = i.sectors;
  1379. info_array[2] = i.cylinders;
  1380. } else if (bios_major == 3
  1381. && bios_minor >= 0
  1382. && bios_minor < 4) { /* 3.0 and 3.2 BIOS */
  1383. memcpy_fromio( &i, bios_mem + 0x1f71 + drive * 10,
  1384. sizeof( struct drive_info ) );
  1385. info_array[0] = i.heads + 1;
  1386. info_array[1] = i.sectors;
  1387. info_array[2] = i.cylinders;
  1388. } else { /* 3.4 BIOS (and up?) */
  1389. /* This algorithm was provided by Future Domain (much thanks!). */
  1390. unsigned char *p = scsi_bios_ptable(bdev);
  1391. if (p && p[65] == 0xaa && p[64] == 0x55 /* Partition table valid */
  1392. && p[4]) { /* Partition type */
  1393. /* The partition table layout is as follows:
  1394. Start: 0x1b3h
  1395. Offset: 0 = partition status
  1396. 1 = starting head
  1397. 2 = starting sector and cylinder (word, encoded)
  1398. 4 = partition type
  1399. 5 = ending head
  1400. 6 = ending sector and cylinder (word, encoded)
  1401. 8 = starting absolute sector (double word)
  1402. c = number of sectors (double word)
  1403. Signature: 0x1fe = 0x55aa
  1404. So, this algorithm assumes:
  1405. 1) the first partition table is in use,
  1406. 2) the data in the first entry is correct, and
  1407. 3) partitions never divide cylinders
  1408. Note that (1) may be FALSE for NetBSD (and other BSD flavors),
  1409. as well as for Linux. Note also, that Linux doesn't pay any
  1410. attention to the fields that are used by this algorithm -- it
  1411. only uses the absolute sector data. Recent versions of Linux's
  1412. fdisk(1) will fill this data in correctly, and forthcoming
  1413. versions will check for consistency.
  1414. Checking for a non-zero partition type is not part of the
  1415. Future Domain algorithm, but it seemed to be a reasonable thing
  1416. to do, especially in the Linux and BSD worlds. */
  1417. info_array[0] = p[5] + 1; /* heads */
  1418. info_array[1] = p[6] & 0x3f; /* sectors */
  1419. } else {
  1420. /* Note that this new method guarantees that there will always be
  1421. less than 1024 cylinders on a platter. This is good for drives
  1422. up to approximately 7.85GB (where 1GB = 1024 * 1024 kB). */
  1423. if ((unsigned int)size >= 0x7e0000U) {
  1424. info_array[0] = 0xff; /* heads = 255 */
  1425. info_array[1] = 0x3f; /* sectors = 63 */
  1426. } else if ((unsigned int)size >= 0x200000U) {
  1427. info_array[0] = 0x80; /* heads = 128 */
  1428. info_array[1] = 0x3f; /* sectors = 63 */
  1429. } else {
  1430. info_array[0] = 0x40; /* heads = 64 */
  1431. info_array[1] = 0x20; /* sectors = 32 */
  1432. }
  1433. }
  1434. /* For both methods, compute the cylinders */
  1435. info_array[2] = (unsigned int)size / (info_array[0] * info_array[1] );
  1436. kfree(p);
  1437. }
  1438. return 0;
  1439. }
  1440. static int fdomain_16x0_release(struct Scsi_Host *shpnt)
  1441. {
  1442. if (shpnt->irq)
  1443. free_irq(shpnt->irq, shpnt);
  1444. if (shpnt->io_port && shpnt->n_io_port)
  1445. release_region(shpnt->io_port, shpnt->n_io_port);
  1446. if (PCI_bus)
  1447. pci_dev_put(PCI_dev);
  1448. return 0;
  1449. }
  1450. struct scsi_host_template fdomain_driver_template = {
  1451. .module = THIS_MODULE,
  1452. .name = "fdomain",
  1453. .proc_name = "fdomain",
  1454. .detect = fdomain_16x0_detect,
  1455. .info = fdomain_16x0_info,
  1456. .queuecommand = fdomain_16x0_queue,
  1457. .eh_abort_handler = fdomain_16x0_abort,
  1458. .eh_bus_reset_handler = fdomain_16x0_bus_reset,
  1459. .bios_param = fdomain_16x0_biosparam,
  1460. .release = fdomain_16x0_release,
  1461. .can_queue = 1,
  1462. .this_id = 6,
  1463. .sg_tablesize = 64,
  1464. .cmd_per_lun = 1,
  1465. .use_clustering = DISABLE_CLUSTERING,
  1466. };
  1467. #ifndef PCMCIA
  1468. static struct pci_device_id fdomain_pci_tbl[] __devinitdata = {
  1469. { PCI_VENDOR_ID_FD, PCI_DEVICE_ID_FD_36C70,
  1470. PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0UL },
  1471. { }
  1472. };
  1473. MODULE_DEVICE_TABLE(pci, fdomain_pci_tbl);
  1474. #define driver_template fdomain_driver_template
  1475. #include "scsi_module.c"
  1476. #endif