fdomain.c 56 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784
  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. #ifdef CONFIG_PCI
  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