fd_mcs.c 39 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355
  1. /* fd_mcs.c -- Future Domain MCS 600/700 (or IBM OEM) driver
  2. *
  3. * FutureDomain MCS-600/700 v0.2 03/11/1998 by ZP Gu (zpg@castle.net)
  4. *
  5. * This driver is cloned from fdomain.* to specifically support
  6. * the Future Domain MCS 600/700 MCA SCSI adapters. Some PS/2s
  7. * also equipped with IBM Fast SCSI Adapter/A which is an OEM
  8. * of MCS 700.
  9. *
  10. * This driver also supports Reply SB16/SCSI card (the SCSI part).
  11. *
  12. * What makes this driver different is that this driver is MCA only
  13. * and it supports multiple adapters in the same system, IRQ
  14. * sharing, some driver statistics, and maps highest SCSI id to sda.
  15. * All cards are auto-detected.
  16. *
  17. * Assumptions: TMC-1800/18C50/18C30, BIOS >= 3.4
  18. *
  19. * LILO command-line options:
  20. * fd_mcs=<FIFO_COUNT>[,<FIFO_SIZE>]
  21. *
  22. * ********************************************************
  23. * Please see Copyrights/Comments in fdomain.* for credits.
  24. * Following is from fdomain.c for acknowledgement:
  25. *
  26. * Created: Sun May 3 18:53:19 1992 by faith@cs.unc.edu
  27. * Revised: Wed Oct 2 11:10:55 1996 by r.faith@ieee.org
  28. * Author: Rickard E. Faith, faith@cs.unc.edu
  29. * Copyright 1992, 1993, 1994, 1995, 1996 Rickard E. Faith
  30. *
  31. * $Id: fdomain.c,v 5.45 1996/10/02 15:13:06 root Exp $
  32. * This program is free software; you can redistribute it and/or modify it
  33. * under the terms of the GNU General Public License as published by the
  34. * Free Software Foundation; either version 2, or (at your option) any
  35. * later version.
  36. * This program is distributed in the hope that it will be useful, but
  37. * WITHOUT ANY WARRANTY; without even the implied warranty of
  38. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  39. * General Public License for more details.
  40. * You should have received a copy of the GNU General Public License along
  41. * with this program; if not, write to the Free Software Foundation, Inc.,
  42. * 675 Mass Ave, Cambridge, MA 02139, USA.
  43. **************************************************************************
  44. NOTES ON USER DEFINABLE OPTIONS:
  45. DEBUG: This turns on the printing of various debug information.
  46. ENABLE_PARITY: This turns on SCSI parity checking. With the current
  47. driver, all attached devices must support SCSI parity. If none of your
  48. devices support parity, then you can probably get the driver to work by
  49. turning this option off. I have no way of testing this, however, and it
  50. would appear that no one ever uses this option.
  51. FIFO_COUNT: The host adapter has an 8K cache (host adapters based on the
  52. 18C30 chip have a 2k cache). When this many 512 byte blocks are filled by
  53. the SCSI device, an interrupt will be raised. Therefore, this could be as
  54. low as 0, or as high as 16. Note, however, that values which are too high
  55. or too low seem to prevent any interrupts from occurring, and thereby lock
  56. up the machine. I have found that 2 is a good number, but throughput may
  57. be increased by changing this value to values which are close to 2.
  58. Please let me know if you try any different values.
  59. [*****Now a runtime option*****]
  60. RESELECTION: This is no longer an option, since I gave up trying to
  61. implement it in version 4.x of this driver. It did not improve
  62. performance at all and made the driver unstable (because I never found one
  63. of the two race conditions which were introduced by the multiple
  64. outstanding command code). The instability seems a very high price to pay
  65. just so that you don't have to wait for the tape to rewind. If you want
  66. this feature implemented, send me patches. I'll be happy to send a copy
  67. of my (broken) driver to anyone who would like to see a copy.
  68. **************************************************************************/
  69. #include <linux/module.h>
  70. #include <linux/init.h>
  71. #include <linux/interrupt.h>
  72. #include <linux/blkdev.h>
  73. #include <linux/errno.h>
  74. #include <linux/string.h>
  75. #include <linux/ioport.h>
  76. #include <linux/proc_fs.h>
  77. #include <linux/delay.h>
  78. #include <linux/mca.h>
  79. #include <linux/spinlock.h>
  80. #include <linux/slab.h>
  81. #include <scsi/scsicam.h>
  82. #include <linux/mca-legacy.h>
  83. #include <asm/io.h>
  84. #include "scsi.h"
  85. #include <scsi/scsi_host.h>
  86. #define DRIVER_VERSION "v0.2 by ZP Gu<zpg@castle.net>"
  87. /* START OF USER DEFINABLE OPTIONS */
  88. #define DEBUG 0 /* Enable debugging output */
  89. #define ENABLE_PARITY 1 /* Enable SCSI Parity */
  90. /* END OF USER DEFINABLE OPTIONS */
  91. #if DEBUG
  92. #define EVERY_ACCESS 0 /* Write a line on every scsi access */
  93. #define ERRORS_ONLY 1 /* Only write a line if there is an error */
  94. #define DEBUG_MESSAGES 1 /* Debug MESSAGE IN phase */
  95. #define DEBUG_ABORT 1 /* Debug abort() routine */
  96. #define DEBUG_RESET 1 /* Debug reset() routine */
  97. #define DEBUG_RACE 1 /* Debug interrupt-driven race condition */
  98. #else
  99. #define EVERY_ACCESS 0 /* LEAVE THESE ALONE--CHANGE THE ONES ABOVE */
  100. #define ERRORS_ONLY 0
  101. #define DEBUG_MESSAGES 0
  102. #define DEBUG_ABORT 0
  103. #define DEBUG_RESET 0
  104. #define DEBUG_RACE 0
  105. #endif
  106. /* Errors are reported on the line, so we don't need to report them again */
  107. #if EVERY_ACCESS
  108. #undef ERRORS_ONLY
  109. #define ERRORS_ONLY 0
  110. #endif
  111. #if ENABLE_PARITY
  112. #define PARITY_MASK 0x08
  113. #else
  114. #define PARITY_MASK 0x00
  115. #endif
  116. enum chip_type {
  117. unknown = 0x00,
  118. tmc1800 = 0x01,
  119. tmc18c50 = 0x02,
  120. tmc18c30 = 0x03,
  121. };
  122. enum {
  123. in_arbitration = 0x02,
  124. in_selection = 0x04,
  125. in_other = 0x08,
  126. disconnect = 0x10,
  127. aborted = 0x20,
  128. sent_ident = 0x40,
  129. };
  130. enum in_port_type {
  131. Read_SCSI_Data = 0,
  132. SCSI_Status = 1,
  133. TMC_Status = 2,
  134. FIFO_Status = 3, /* tmc18c50/tmc18c30 only */
  135. Interrupt_Cond = 4, /* tmc18c50/tmc18c30 only */
  136. LSB_ID_Code = 5,
  137. MSB_ID_Code = 6,
  138. Read_Loopback = 7,
  139. SCSI_Data_NoACK = 8,
  140. Interrupt_Status = 9,
  141. Configuration1 = 10,
  142. Configuration2 = 11, /* tmc18c50/tmc18c30 only */
  143. Read_FIFO = 12,
  144. FIFO_Data_Count = 14
  145. };
  146. enum out_port_type {
  147. Write_SCSI_Data = 0,
  148. SCSI_Cntl = 1,
  149. Interrupt_Cntl = 2,
  150. SCSI_Mode_Cntl = 3,
  151. TMC_Cntl = 4,
  152. Memory_Cntl = 5, /* tmc18c50/tmc18c30 only */
  153. Write_Loopback = 7,
  154. IO_Control = 11, /* tmc18c30 only */
  155. Write_FIFO = 12
  156. };
  157. struct fd_hostdata {
  158. unsigned long _bios_base;
  159. int _bios_major;
  160. int _bios_minor;
  161. volatile int _in_command;
  162. Scsi_Cmnd *_current_SC;
  163. enum chip_type _chip;
  164. int _adapter_mask;
  165. int _fifo_count; /* Number of 512 byte blocks before INTR */
  166. char _adapter_name[64];
  167. #if DEBUG_RACE
  168. volatile int _in_interrupt_flag;
  169. #endif
  170. int _SCSI_Mode_Cntl_port;
  171. int _FIFO_Data_Count_port;
  172. int _Interrupt_Cntl_port;
  173. int _Interrupt_Status_port;
  174. int _Interrupt_Cond_port;
  175. int _Read_FIFO_port;
  176. int _Read_SCSI_Data_port;
  177. int _SCSI_Cntl_port;
  178. int _SCSI_Data_NoACK_port;
  179. int _SCSI_Status_port;
  180. int _TMC_Cntl_port;
  181. int _TMC_Status_port;
  182. int _Write_FIFO_port;
  183. int _Write_SCSI_Data_port;
  184. int _FIFO_Size; /* = 0x2000; 8k FIFO for
  185. pre-tmc18c30 chips */
  186. /* simple stats */
  187. int _Bytes_Read;
  188. int _Bytes_Written;
  189. int _INTR_Processed;
  190. };
  191. #define FD_MAX_HOSTS 3 /* enough? */
  192. #define HOSTDATA(shpnt) ((struct fd_hostdata *) shpnt->hostdata)
  193. #define bios_base (HOSTDATA(shpnt)->_bios_base)
  194. #define bios_major (HOSTDATA(shpnt)->_bios_major)
  195. #define bios_minor (HOSTDATA(shpnt)->_bios_minor)
  196. #define in_command (HOSTDATA(shpnt)->_in_command)
  197. #define current_SC (HOSTDATA(shpnt)->_current_SC)
  198. #define chip (HOSTDATA(shpnt)->_chip)
  199. #define adapter_mask (HOSTDATA(shpnt)->_adapter_mask)
  200. #define FIFO_COUNT (HOSTDATA(shpnt)->_fifo_count)
  201. #define adapter_name (HOSTDATA(shpnt)->_adapter_name)
  202. #if DEBUG_RACE
  203. #define in_interrupt_flag (HOSTDATA(shpnt)->_in_interrupt_flag)
  204. #endif
  205. #define SCSI_Mode_Cntl_port (HOSTDATA(shpnt)->_SCSI_Mode_Cntl_port)
  206. #define FIFO_Data_Count_port (HOSTDATA(shpnt)->_FIFO_Data_Count_port)
  207. #define Interrupt_Cntl_port (HOSTDATA(shpnt)->_Interrupt_Cntl_port)
  208. #define Interrupt_Status_port (HOSTDATA(shpnt)->_Interrupt_Status_port)
  209. #define Interrupt_Cond_port (HOSTDATA(shpnt)->_Interrupt_Cond_port)
  210. #define Read_FIFO_port (HOSTDATA(shpnt)->_Read_FIFO_port)
  211. #define Read_SCSI_Data_port (HOSTDATA(shpnt)->_Read_SCSI_Data_port)
  212. #define SCSI_Cntl_port (HOSTDATA(shpnt)->_SCSI_Cntl_port)
  213. #define SCSI_Data_NoACK_port (HOSTDATA(shpnt)->_SCSI_Data_NoACK_port)
  214. #define SCSI_Status_port (HOSTDATA(shpnt)->_SCSI_Status_port)
  215. #define TMC_Cntl_port (HOSTDATA(shpnt)->_TMC_Cntl_port)
  216. #define TMC_Status_port (HOSTDATA(shpnt)->_TMC_Status_port)
  217. #define Write_FIFO_port (HOSTDATA(shpnt)->_Write_FIFO_port)
  218. #define Write_SCSI_Data_port (HOSTDATA(shpnt)->_Write_SCSI_Data_port)
  219. #define FIFO_Size (HOSTDATA(shpnt)->_FIFO_Size)
  220. #define Bytes_Read (HOSTDATA(shpnt)->_Bytes_Read)
  221. #define Bytes_Written (HOSTDATA(shpnt)->_Bytes_Written)
  222. #define INTR_Processed (HOSTDATA(shpnt)->_INTR_Processed)
  223. struct fd_mcs_adapters_struct {
  224. char *name;
  225. int id;
  226. enum chip_type fd_chip;
  227. int fifo_size;
  228. int fifo_count;
  229. };
  230. #define REPLY_ID 0x5137
  231. static struct fd_mcs_adapters_struct fd_mcs_adapters[] = {
  232. {"Future Domain SCSI Adapter MCS-700(18C50)",
  233. 0x60e9,
  234. tmc18c50,
  235. 0x2000,
  236. 4},
  237. {"Future Domain SCSI Adapter MCS-600/700(TMC-1800)",
  238. 0x6127,
  239. tmc1800,
  240. 0x2000,
  241. 4},
  242. {"Reply Sound Blaster/SCSI Adapter",
  243. REPLY_ID,
  244. tmc18c30,
  245. 0x800,
  246. 2},
  247. };
  248. #define FD_BRDS ARRAY_SIZE(fd_mcs_adapters)
  249. static irqreturn_t fd_mcs_intr(int irq, void *dev_id);
  250. static unsigned long addresses[] = { 0xc8000, 0xca000, 0xce000, 0xde000 };
  251. static unsigned short ports[] = { 0x140, 0x150, 0x160, 0x170 };
  252. static unsigned short interrupts[] = { 3, 5, 10, 11, 12, 14, 15, 0 };
  253. /* host information */
  254. static int found = 0;
  255. static struct Scsi_Host *hosts[FD_MAX_HOSTS + 1] = { NULL };
  256. static int user_fifo_count = 0;
  257. static int user_fifo_size = 0;
  258. #ifndef MODULE
  259. static int __init fd_mcs_setup(char *str)
  260. {
  261. static int done_setup = 0;
  262. int ints[3];
  263. get_options(str, 3, ints);
  264. if (done_setup++ || ints[0] < 1 || ints[0] > 2 || ints[1] < 1 || ints[1] > 16) {
  265. printk("fd_mcs: usage: fd_mcs=FIFO_COUNT, FIFO_SIZE\n");
  266. return 0;
  267. }
  268. user_fifo_count = ints[0] >= 1 ? ints[1] : 0;
  269. user_fifo_size = ints[0] >= 2 ? ints[2] : 0;
  270. return 1;
  271. }
  272. __setup("fd_mcs=", fd_mcs_setup);
  273. #endif /* !MODULE */
  274. static void print_banner(struct Scsi_Host *shpnt)
  275. {
  276. printk("scsi%d <fd_mcs>: ", shpnt->host_no);
  277. if (bios_base) {
  278. printk("BIOS at 0x%lX", bios_base);
  279. } else {
  280. printk("No BIOS");
  281. }
  282. printk(", HostID %d, %s Chip, IRQ %d, IO 0x%lX\n", shpnt->this_id, chip == tmc18c50 ? "TMC-18C50" : (chip == tmc18c30 ? "TMC-18C30" : (chip == tmc1800 ? "TMC-1800" : "Unknown")), shpnt->irq, shpnt->io_port);
  283. }
  284. static void do_pause(unsigned amount)
  285. { /* Pause for amount*10 milliseconds */
  286. do {
  287. mdelay(10);
  288. } while (--amount);
  289. }
  290. static void fd_mcs_make_bus_idle(struct Scsi_Host *shpnt)
  291. {
  292. outb(0, SCSI_Cntl_port);
  293. outb(0, SCSI_Mode_Cntl_port);
  294. if (chip == tmc18c50 || chip == tmc18c30)
  295. outb(0x21 | PARITY_MASK, TMC_Cntl_port); /* Clear forced intr. */
  296. else
  297. outb(0x01 | PARITY_MASK, TMC_Cntl_port);
  298. }
  299. static int fd_mcs_detect(struct scsi_host_template * tpnt)
  300. {
  301. int loop;
  302. struct Scsi_Host *shpnt;
  303. /* get id, port, bios, irq */
  304. int slot;
  305. u_char pos2, pos3, pos4;
  306. int id, port, irq;
  307. unsigned long bios;
  308. /* if not MCA machine, return */
  309. if (!MCA_bus)
  310. return 0;
  311. /* changeable? */
  312. id = 7;
  313. for (loop = 0; loop < FD_BRDS; loop++) {
  314. slot = 0;
  315. while (MCA_NOTFOUND != (slot = mca_find_adapter(fd_mcs_adapters[loop].id, slot))) {
  316. /* if we get this far, an adapter has been detected and is
  317. enabled */
  318. printk(KERN_INFO "scsi <fd_mcs>: %s at slot %d\n", fd_mcs_adapters[loop].name, slot + 1);
  319. pos2 = mca_read_stored_pos(slot, 2);
  320. pos3 = mca_read_stored_pos(slot, 3);
  321. pos4 = mca_read_stored_pos(slot, 4);
  322. /* ready for next probe */
  323. slot++;
  324. if (fd_mcs_adapters[loop].id == REPLY_ID) { /* reply card */
  325. static int reply_irq[] = { 10, 11, 14, 15 };
  326. bios = 0; /* no bios */
  327. if (pos2 & 0x2)
  328. port = ports[pos4 & 0x3];
  329. else
  330. continue;
  331. /* can't really disable it, same as irq=10 */
  332. irq = reply_irq[((pos4 >> 2) & 0x1) + 2 * ((pos4 >> 4) & 0x1)];
  333. } else {
  334. bios = addresses[pos2 >> 6];
  335. port = ports[(pos2 >> 4) & 0x03];
  336. irq = interrupts[(pos2 >> 1) & 0x07];
  337. }
  338. if (irq) {
  339. /* claim the slot */
  340. mca_set_adapter_name(slot - 1, fd_mcs_adapters[loop].name);
  341. /* check irq/region */
  342. if (request_irq(irq, fd_mcs_intr, IRQF_SHARED, "fd_mcs", hosts)) {
  343. printk(KERN_ERR "fd_mcs: interrupt is not available, skipping...\n");
  344. continue;
  345. }
  346. /* request I/O region */
  347. if (request_region(port, 0x10, "fd_mcs")) {
  348. printk(KERN_ERR "fd_mcs: I/O region is already in use, skipping...\n");
  349. continue;
  350. }
  351. /* register */
  352. if (!(shpnt = scsi_register(tpnt, sizeof(struct fd_hostdata)))) {
  353. printk(KERN_ERR "fd_mcs: scsi_register() failed\n");
  354. release_region(port, 0x10);
  355. free_irq(irq, hosts);
  356. continue;
  357. }
  358. /* save name */
  359. strcpy(adapter_name, fd_mcs_adapters[loop].name);
  360. /* chip/fifo */
  361. chip = fd_mcs_adapters[loop].fd_chip;
  362. /* use boot time value if available */
  363. FIFO_COUNT = user_fifo_count ? user_fifo_count : fd_mcs_adapters[loop].fifo_count;
  364. FIFO_Size = user_fifo_size ? user_fifo_size : fd_mcs_adapters[loop].fifo_size;
  365. /* FIXME: Do we need to keep this bit of code inside NOT_USED around at all? */
  366. #ifdef NOT_USED
  367. /* *************************************************** */
  368. /* Try to toggle 32-bit mode. This only
  369. works on an 18c30 chip. (User reports
  370. say this works, so we should switch to
  371. it in the near future.) */
  372. outb(0x80, port + IO_Control);
  373. if ((inb(port + Configuration2) & 0x80) == 0x80) {
  374. outb(0x00, port + IO_Control);
  375. if ((inb(port + Configuration2) & 0x80) == 0x00) {
  376. chip = tmc18c30;
  377. FIFO_Size = 0x800; /* 2k FIFO */
  378. printk("FIRST: chip=%s, fifo_size=0x%x\n", (chip == tmc18c30) ? "tmc18c30" : "tmc18c50", FIFO_Size);
  379. }
  380. }
  381. /* That should have worked, but appears to
  382. have problems. Let's assume it is an
  383. 18c30 if the RAM is disabled. */
  384. if (inb(port + Configuration2) & 0x02) {
  385. chip = tmc18c30;
  386. FIFO_Size = 0x800; /* 2k FIFO */
  387. printk("SECOND: chip=%s, fifo_size=0x%x\n", (chip == tmc18c30) ? "tmc18c30" : "tmc18c50", FIFO_Size);
  388. }
  389. /* *************************************************** */
  390. #endif
  391. /* IBM/ANSI scsi scan ordering */
  392. /* Stick this back in when the scsi.c changes are there */
  393. shpnt->reverse_ordering = 1;
  394. /* saving info */
  395. hosts[found++] = shpnt;
  396. shpnt->this_id = id;
  397. shpnt->irq = irq;
  398. shpnt->io_port = port;
  399. shpnt->n_io_port = 0x10;
  400. /* save */
  401. bios_base = bios;
  402. adapter_mask = (1 << id);
  403. /* save more */
  404. SCSI_Mode_Cntl_port = port + SCSI_Mode_Cntl;
  405. FIFO_Data_Count_port = port + FIFO_Data_Count;
  406. Interrupt_Cntl_port = port + Interrupt_Cntl;
  407. Interrupt_Status_port = port + Interrupt_Status;
  408. Interrupt_Cond_port = port + Interrupt_Cond;
  409. Read_FIFO_port = port + Read_FIFO;
  410. Read_SCSI_Data_port = port + Read_SCSI_Data;
  411. SCSI_Cntl_port = port + SCSI_Cntl;
  412. SCSI_Data_NoACK_port = port + SCSI_Data_NoACK;
  413. SCSI_Status_port = port + SCSI_Status;
  414. TMC_Cntl_port = port + TMC_Cntl;
  415. TMC_Status_port = port + TMC_Status;
  416. Write_FIFO_port = port + Write_FIFO;
  417. Write_SCSI_Data_port = port + Write_SCSI_Data;
  418. Bytes_Read = 0;
  419. Bytes_Written = 0;
  420. INTR_Processed = 0;
  421. /* say something */
  422. print_banner(shpnt);
  423. /* reset */
  424. outb(1, SCSI_Cntl_port);
  425. do_pause(2);
  426. outb(0, SCSI_Cntl_port);
  427. do_pause(115);
  428. outb(0, SCSI_Mode_Cntl_port);
  429. outb(PARITY_MASK, TMC_Cntl_port);
  430. /* done reset */
  431. }
  432. }
  433. if (found == FD_MAX_HOSTS) {
  434. printk("fd_mcs: detecting reached max=%d host adapters.\n", FD_MAX_HOSTS);
  435. break;
  436. }
  437. }
  438. return found;
  439. }
  440. static const char *fd_mcs_info(struct Scsi_Host *shpnt)
  441. {
  442. return adapter_name;
  443. }
  444. static int TOTAL_INTR = 0;
  445. /*
  446. * inout : decides on the direction of the dataflow and the meaning of the
  447. * variables
  448. * buffer: If inout==FALSE data is being written to it else read from it
  449. * *start: If inout==FALSE start of the valid data in the buffer
  450. * offset: If inout==FALSE offset from the beginning of the imaginary file
  451. * from which we start writing into the buffer
  452. * length: If inout==FALSE max number of bytes to be written into the buffer
  453. * else number of bytes in the buffer
  454. */
  455. static int fd_mcs_proc_info(struct Scsi_Host *shpnt, char *buffer, char **start, off_t offset, int length, int inout)
  456. {
  457. int len = 0;
  458. if (inout)
  459. return (-ENOSYS);
  460. *start = buffer + offset;
  461. len += sprintf(buffer + len, "Future Domain MCS-600/700 Driver %s\n", DRIVER_VERSION);
  462. len += sprintf(buffer + len, "HOST #%d: %s\n", shpnt->host_no, adapter_name);
  463. len += sprintf(buffer + len, "FIFO Size=0x%x, FIFO Count=%d\n", FIFO_Size, FIFO_COUNT);
  464. len += sprintf(buffer + len, "DriverCalls=%d, Interrupts=%d, BytesRead=%d, BytesWrite=%d\n\n", TOTAL_INTR, INTR_Processed, Bytes_Read, Bytes_Written);
  465. if ((len -= offset) <= 0)
  466. return 0;
  467. if (len > length)
  468. len = length;
  469. return len;
  470. }
  471. static int fd_mcs_select(struct Scsi_Host *shpnt, int target)
  472. {
  473. int status;
  474. unsigned long timeout;
  475. outb(0x82, SCSI_Cntl_port); /* Bus Enable + Select */
  476. outb(adapter_mask | (1 << target), SCSI_Data_NoACK_port);
  477. /* Stop arbitration and enable parity */
  478. outb(PARITY_MASK, TMC_Cntl_port);
  479. timeout = 350; /* 350mS -- because of timeouts
  480. (was 250mS) */
  481. do {
  482. status = inb(SCSI_Status_port); /* Read adapter status */
  483. if (status & 1) { /* Busy asserted */
  484. /* Enable SCSI Bus (on error, should make bus idle with 0) */
  485. outb(0x80, SCSI_Cntl_port);
  486. return 0;
  487. }
  488. udelay(1000); /* wait one msec */
  489. } while (--timeout);
  490. /* Make bus idle */
  491. fd_mcs_make_bus_idle(shpnt);
  492. #if EVERY_ACCESS
  493. if (!target)
  494. printk("Selection failed\n");
  495. #endif
  496. #if ERRORS_ONLY
  497. if (!target) {
  498. static int flag = 0;
  499. if (!flag) /* Skip first failure for all chips. */
  500. ++flag;
  501. else
  502. printk("fd_mcs: Selection failed\n");
  503. }
  504. #endif
  505. return 1;
  506. }
  507. static void my_done(struct Scsi_Host *shpnt, int error)
  508. {
  509. if (in_command) {
  510. in_command = 0;
  511. outb(0x00, Interrupt_Cntl_port);
  512. fd_mcs_make_bus_idle(shpnt);
  513. current_SC->result = error;
  514. current_SC->scsi_done(current_SC);
  515. } else {
  516. panic("fd_mcs: my_done() called outside of command\n");
  517. }
  518. #if DEBUG_RACE
  519. in_interrupt_flag = 0;
  520. #endif
  521. }
  522. /* only my_done needs to be protected */
  523. static irqreturn_t fd_mcs_intr(int irq, void *dev_id)
  524. {
  525. unsigned long flags;
  526. int status;
  527. int done = 0;
  528. unsigned data_count, tmp_count;
  529. int i = 0;
  530. struct Scsi_Host *shpnt;
  531. TOTAL_INTR++;
  532. /* search for one adapter-response on shared interrupt */
  533. while ((shpnt = hosts[i++])) {
  534. if ((inb(TMC_Status_port)) & 1)
  535. break;
  536. }
  537. /* return if some other device on this IRQ caused the interrupt */
  538. if (!shpnt) {
  539. return IRQ_NONE;
  540. }
  541. INTR_Processed++;
  542. outb(0x00, Interrupt_Cntl_port);
  543. /* Abort calls my_done, so we do nothing here. */
  544. if (current_SC->SCp.phase & aborted) {
  545. #if DEBUG_ABORT
  546. printk("Interrupt after abort, ignoring\n");
  547. #endif
  548. /* return IRQ_HANDLED; */
  549. }
  550. #if DEBUG_RACE
  551. ++in_interrupt_flag;
  552. #endif
  553. if (current_SC->SCp.phase & in_arbitration) {
  554. status = inb(TMC_Status_port); /* Read adapter status */
  555. if (!(status & 0x02)) {
  556. #if EVERY_ACCESS
  557. printk(" AFAIL ");
  558. #endif
  559. spin_lock_irqsave(shpnt->host_lock, flags);
  560. my_done(shpnt, DID_BUS_BUSY << 16);
  561. spin_unlock_irqrestore(shpnt->host_lock, flags);
  562. return IRQ_HANDLED;
  563. }
  564. current_SC->SCp.phase = in_selection;
  565. outb(0x40 | FIFO_COUNT, Interrupt_Cntl_port);
  566. outb(0x82, SCSI_Cntl_port); /* Bus Enable + Select */
  567. outb(adapter_mask | (1 << scmd_id(current_SC)), SCSI_Data_NoACK_port);
  568. /* Stop arbitration and enable parity */
  569. outb(0x10 | PARITY_MASK, TMC_Cntl_port);
  570. #if DEBUG_RACE
  571. in_interrupt_flag = 0;
  572. #endif
  573. return IRQ_HANDLED;
  574. } else if (current_SC->SCp.phase & in_selection) {
  575. status = inb(SCSI_Status_port);
  576. if (!(status & 0x01)) {
  577. /* Try again, for slow devices */
  578. if (fd_mcs_select(shpnt, scmd_id(current_SC))) {
  579. #if EVERY_ACCESS
  580. printk(" SFAIL ");
  581. #endif
  582. spin_lock_irqsave(shpnt->host_lock, flags);
  583. my_done(shpnt, DID_NO_CONNECT << 16);
  584. spin_unlock_irqrestore(shpnt->host_lock, flags);
  585. return IRQ_HANDLED;
  586. } else {
  587. #if EVERY_ACCESS
  588. printk(" AltSel ");
  589. #endif
  590. /* Stop arbitration and enable parity */
  591. outb(0x10 | PARITY_MASK, TMC_Cntl_port);
  592. }
  593. }
  594. current_SC->SCp.phase = in_other;
  595. outb(0x90 | FIFO_COUNT, Interrupt_Cntl_port);
  596. outb(0x80, SCSI_Cntl_port);
  597. #if DEBUG_RACE
  598. in_interrupt_flag = 0;
  599. #endif
  600. return IRQ_HANDLED;
  601. }
  602. /* current_SC->SCp.phase == in_other: this is the body of the routine */
  603. status = inb(SCSI_Status_port);
  604. if (status & 0x10) { /* REQ */
  605. switch (status & 0x0e) {
  606. case 0x08: /* COMMAND OUT */
  607. outb(current_SC->cmnd[current_SC->SCp.sent_command++], Write_SCSI_Data_port);
  608. #if EVERY_ACCESS
  609. printk("CMD = %x,", current_SC->cmnd[current_SC->SCp.sent_command - 1]);
  610. #endif
  611. break;
  612. case 0x00: /* DATA OUT -- tmc18c50/tmc18c30 only */
  613. if (chip != tmc1800 && !current_SC->SCp.have_data_in) {
  614. current_SC->SCp.have_data_in = -1;
  615. outb(0xd0 | PARITY_MASK, TMC_Cntl_port);
  616. }
  617. break;
  618. case 0x04: /* DATA IN -- tmc18c50/tmc18c30 only */
  619. if (chip != tmc1800 && !current_SC->SCp.have_data_in) {
  620. current_SC->SCp.have_data_in = 1;
  621. outb(0x90 | PARITY_MASK, TMC_Cntl_port);
  622. }
  623. break;
  624. case 0x0c: /* STATUS IN */
  625. current_SC->SCp.Status = inb(Read_SCSI_Data_port);
  626. #if EVERY_ACCESS
  627. printk("Status = %x, ", current_SC->SCp.Status);
  628. #endif
  629. #if ERRORS_ONLY
  630. if (current_SC->SCp.Status && current_SC->SCp.Status != 2 && current_SC->SCp.Status != 8) {
  631. printk("ERROR fd_mcs: target = %d, command = %x, status = %x\n", current_SC->device->id, current_SC->cmnd[0], current_SC->SCp.Status);
  632. }
  633. #endif
  634. break;
  635. case 0x0a: /* MESSAGE OUT */
  636. outb(MESSAGE_REJECT, Write_SCSI_Data_port); /* Reject */
  637. break;
  638. case 0x0e: /* MESSAGE IN */
  639. current_SC->SCp.Message = inb(Read_SCSI_Data_port);
  640. #if EVERY_ACCESS
  641. printk("Message = %x, ", current_SC->SCp.Message);
  642. #endif
  643. if (!current_SC->SCp.Message)
  644. ++done;
  645. #if DEBUG_MESSAGES || EVERY_ACCESS
  646. if (current_SC->SCp.Message) {
  647. printk("fd_mcs: message = %x\n", current_SC->SCp.Message);
  648. }
  649. #endif
  650. break;
  651. }
  652. }
  653. if (chip == tmc1800 && !current_SC->SCp.have_data_in && (current_SC->SCp.sent_command >= current_SC->cmd_len)) {
  654. /* We have to get the FIFO direction
  655. correct, so I've made a table based
  656. on the SCSI Standard of which commands
  657. appear to require a DATA OUT phase.
  658. */
  659. /*
  660. p. 94: Command for all device types
  661. CHANGE DEFINITION 40 DATA OUT
  662. COMPARE 39 DATA OUT
  663. COPY 18 DATA OUT
  664. COPY AND VERIFY 3a DATA OUT
  665. INQUIRY 12
  666. LOG SELECT 4c DATA OUT
  667. LOG SENSE 4d
  668. MODE SELECT (6) 15 DATA OUT
  669. MODE SELECT (10) 55 DATA OUT
  670. MODE SENSE (6) 1a
  671. MODE SENSE (10) 5a
  672. READ BUFFER 3c
  673. RECEIVE DIAGNOSTIC RESULTS 1c
  674. REQUEST SENSE 03
  675. SEND DIAGNOSTIC 1d DATA OUT
  676. TEST UNIT READY 00
  677. WRITE BUFFER 3b DATA OUT
  678. p.178: Commands for direct-access devices (not listed on p. 94)
  679. FORMAT UNIT 04 DATA OUT
  680. LOCK-UNLOCK CACHE 36
  681. PRE-FETCH 34
  682. PREVENT-ALLOW MEDIUM REMOVAL 1e
  683. READ (6)/RECEIVE 08
  684. READ (10) 3c
  685. READ CAPACITY 25
  686. READ DEFECT DATA (10) 37
  687. READ LONG 3e
  688. REASSIGN BLOCKS 07 DATA OUT
  689. RELEASE 17
  690. RESERVE 16 DATA OUT
  691. REZERO UNIT/REWIND 01
  692. SEARCH DATA EQUAL (10) 31 DATA OUT
  693. SEARCH DATA HIGH (10) 30 DATA OUT
  694. SEARCH DATA LOW (10) 32 DATA OUT
  695. SEEK (6) 0b
  696. SEEK (10) 2b
  697. SET LIMITS (10) 33
  698. START STOP UNIT 1b
  699. SYNCHRONIZE CACHE 35
  700. VERIFY (10) 2f
  701. WRITE (6)/PRINT/SEND 0a DATA OUT
  702. WRITE (10)/SEND 2a DATA OUT
  703. WRITE AND VERIFY (10) 2e DATA OUT
  704. WRITE LONG 3f DATA OUT
  705. WRITE SAME 41 DATA OUT ?
  706. p. 261: Commands for sequential-access devices (not previously listed)
  707. ERASE 19
  708. LOAD UNLOAD 1b
  709. LOCATE 2b
  710. READ BLOCK LIMITS 05
  711. READ POSITION 34
  712. READ REVERSE 0f
  713. RECOVER BUFFERED DATA 14
  714. SPACE 11
  715. WRITE FILEMARKS 10 ?
  716. p. 298: Commands for printer devices (not previously listed)
  717. ****** NOT SUPPORTED BY THIS DRIVER, since 0b is SEEK (6) *****
  718. SLEW AND PRINT 0b DATA OUT -- same as seek
  719. STOP PRINT 1b
  720. SYNCHRONIZE BUFFER 10
  721. p. 315: Commands for processor devices (not previously listed)
  722. p. 321: Commands for write-once devices (not previously listed)
  723. MEDIUM SCAN 38
  724. READ (12) a8
  725. SEARCH DATA EQUAL (12) b1 DATA OUT
  726. SEARCH DATA HIGH (12) b0 DATA OUT
  727. SEARCH DATA LOW (12) b2 DATA OUT
  728. SET LIMITS (12) b3
  729. VERIFY (12) af
  730. WRITE (12) aa DATA OUT
  731. WRITE AND VERIFY (12) ae DATA OUT
  732. p. 332: Commands for CD-ROM devices (not previously listed)
  733. PAUSE/RESUME 4b
  734. PLAY AUDIO (10) 45
  735. PLAY AUDIO (12) a5
  736. PLAY AUDIO MSF 47
  737. PLAY TRACK RELATIVE (10) 49
  738. PLAY TRACK RELATIVE (12) a9
  739. READ HEADER 44
  740. READ SUB-CHANNEL 42
  741. READ TOC 43
  742. p. 370: Commands for scanner devices (not previously listed)
  743. GET DATA BUFFER STATUS 34
  744. GET WINDOW 25
  745. OBJECT POSITION 31
  746. SCAN 1b
  747. SET WINDOW 24 DATA OUT
  748. p. 391: Commands for optical memory devices (not listed)
  749. ERASE (10) 2c
  750. ERASE (12) ac
  751. MEDIUM SCAN 38 DATA OUT
  752. READ DEFECT DATA (12) b7
  753. READ GENERATION 29
  754. READ UPDATED BLOCK 2d
  755. UPDATE BLOCK 3d DATA OUT
  756. p. 419: Commands for medium changer devices (not listed)
  757. EXCHANGE MEDIUM 46
  758. INITIALIZE ELEMENT STATUS 07
  759. MOVE MEDIUM a5
  760. POSITION TO ELEMENT 2b
  761. READ ELEMENT STATUS b8
  762. REQUEST VOL. ELEMENT ADDRESS b5
  763. SEND VOLUME TAG b6 DATA OUT
  764. p. 454: Commands for communications devices (not listed previously)
  765. GET MESSAGE (6) 08
  766. GET MESSAGE (10) 28
  767. GET MESSAGE (12) a8
  768. */
  769. switch (current_SC->cmnd[0]) {
  770. case CHANGE_DEFINITION:
  771. case COMPARE:
  772. case COPY:
  773. case COPY_VERIFY:
  774. case LOG_SELECT:
  775. case MODE_SELECT:
  776. case MODE_SELECT_10:
  777. case SEND_DIAGNOSTIC:
  778. case WRITE_BUFFER:
  779. case FORMAT_UNIT:
  780. case REASSIGN_BLOCKS:
  781. case RESERVE:
  782. case SEARCH_EQUAL:
  783. case SEARCH_HIGH:
  784. case SEARCH_LOW:
  785. case WRITE_6:
  786. case WRITE_10:
  787. case WRITE_VERIFY:
  788. case 0x3f:
  789. case 0x41:
  790. case 0xb1:
  791. case 0xb0:
  792. case 0xb2:
  793. case 0xaa:
  794. case 0xae:
  795. case 0x24:
  796. case 0x38:
  797. case 0x3d:
  798. case 0xb6:
  799. case 0xea: /* alternate number for WRITE LONG */
  800. current_SC->SCp.have_data_in = -1;
  801. outb(0xd0 | PARITY_MASK, TMC_Cntl_port);
  802. break;
  803. case 0x00:
  804. default:
  805. current_SC->SCp.have_data_in = 1;
  806. outb(0x90 | PARITY_MASK, TMC_Cntl_port);
  807. break;
  808. }
  809. }
  810. if (current_SC->SCp.have_data_in == -1) { /* DATA OUT */
  811. while ((data_count = FIFO_Size - inw(FIFO_Data_Count_port)) > 512) {
  812. #if EVERY_ACCESS
  813. printk("DC=%d, ", data_count);
  814. #endif
  815. if (data_count > current_SC->SCp.this_residual)
  816. data_count = current_SC->SCp.this_residual;
  817. if (data_count > 0) {
  818. #if EVERY_ACCESS
  819. printk("%d OUT, ", data_count);
  820. #endif
  821. if (data_count == 1) {
  822. Bytes_Written++;
  823. outb(*current_SC->SCp.ptr++, Write_FIFO_port);
  824. --current_SC->SCp.this_residual;
  825. } else {
  826. data_count >>= 1;
  827. tmp_count = data_count << 1;
  828. outsw(Write_FIFO_port, current_SC->SCp.ptr, data_count);
  829. current_SC->SCp.ptr += tmp_count;
  830. Bytes_Written += tmp_count;
  831. current_SC->SCp.this_residual -= tmp_count;
  832. }
  833. }
  834. if (!current_SC->SCp.this_residual) {
  835. if (current_SC->SCp.buffers_residual) {
  836. --current_SC->SCp.buffers_residual;
  837. ++current_SC->SCp.buffer;
  838. current_SC->SCp.ptr = sg_virt(current_SC->SCp.buffer);
  839. current_SC->SCp.this_residual = current_SC->SCp.buffer->length;
  840. } else
  841. break;
  842. }
  843. }
  844. } else if (current_SC->SCp.have_data_in == 1) { /* DATA IN */
  845. while ((data_count = inw(FIFO_Data_Count_port)) > 0) {
  846. #if EVERY_ACCESS
  847. printk("DC=%d, ", data_count);
  848. #endif
  849. if (data_count > current_SC->SCp.this_residual)
  850. data_count = current_SC->SCp.this_residual;
  851. if (data_count) {
  852. #if EVERY_ACCESS
  853. printk("%d IN, ", data_count);
  854. #endif
  855. if (data_count == 1) {
  856. Bytes_Read++;
  857. *current_SC->SCp.ptr++ = inb(Read_FIFO_port);
  858. --current_SC->SCp.this_residual;
  859. } else {
  860. data_count >>= 1; /* Number of words */
  861. tmp_count = data_count << 1;
  862. insw(Read_FIFO_port, current_SC->SCp.ptr, data_count);
  863. current_SC->SCp.ptr += tmp_count;
  864. Bytes_Read += tmp_count;
  865. current_SC->SCp.this_residual -= tmp_count;
  866. }
  867. }
  868. if (!current_SC->SCp.this_residual && current_SC->SCp.buffers_residual) {
  869. --current_SC->SCp.buffers_residual;
  870. ++current_SC->SCp.buffer;
  871. current_SC->SCp.ptr = sg_virt(current_SC->SCp.buffer);
  872. current_SC->SCp.this_residual = current_SC->SCp.buffer->length;
  873. }
  874. }
  875. }
  876. if (done) {
  877. #if EVERY_ACCESS
  878. printk(" ** IN DONE %d ** ", current_SC->SCp.have_data_in);
  879. #endif
  880. #if EVERY_ACCESS
  881. printk("BEFORE MY_DONE. . .");
  882. #endif
  883. spin_lock_irqsave(shpnt->host_lock, flags);
  884. my_done(shpnt, (current_SC->SCp.Status & 0xff)
  885. | ((current_SC->SCp.Message & 0xff) << 8) | (DID_OK << 16));
  886. spin_unlock_irqrestore(shpnt->host_lock, flags);
  887. #if EVERY_ACCESS
  888. printk("RETURNING.\n");
  889. #endif
  890. } else {
  891. if (current_SC->SCp.phase & disconnect) {
  892. outb(0xd0 | FIFO_COUNT, Interrupt_Cntl_port);
  893. outb(0x00, SCSI_Cntl_port);
  894. } else {
  895. outb(0x90 | FIFO_COUNT, Interrupt_Cntl_port);
  896. }
  897. }
  898. #if DEBUG_RACE
  899. in_interrupt_flag = 0;
  900. #endif
  901. return IRQ_HANDLED;
  902. }
  903. static int fd_mcs_release(struct Scsi_Host *shpnt)
  904. {
  905. int i, this_host, irq_usage;
  906. release_region(shpnt->io_port, shpnt->n_io_port);
  907. this_host = -1;
  908. irq_usage = 0;
  909. for (i = 0; i < found; i++) {
  910. if (shpnt == hosts[i])
  911. this_host = i;
  912. if (shpnt->irq == hosts[i]->irq)
  913. irq_usage++;
  914. }
  915. /* only for the last one */
  916. if (1 == irq_usage)
  917. free_irq(shpnt->irq, hosts);
  918. found--;
  919. for (i = this_host; i < found; i++)
  920. hosts[i] = hosts[i + 1];
  921. hosts[found] = NULL;
  922. return 0;
  923. }
  924. static int fd_mcs_queue_lck(Scsi_Cmnd * SCpnt, void (*done) (Scsi_Cmnd *))
  925. {
  926. struct Scsi_Host *shpnt = SCpnt->device->host;
  927. if (in_command) {
  928. panic("fd_mcs: fd_mcs_queue() NOT REENTRANT!\n");
  929. }
  930. #if EVERY_ACCESS
  931. printk("queue: target = %d cmnd = 0x%02x pieces = %d size = %u\n",
  932. SCpnt->target, *(unsigned char *) SCpnt->cmnd,
  933. scsi_sg_count(SCpnt), scsi_bufflen(SCpnt));
  934. #endif
  935. fd_mcs_make_bus_idle(shpnt);
  936. SCpnt->scsi_done = done; /* Save this for the done function */
  937. current_SC = SCpnt;
  938. /* Initialize static data */
  939. if (scsi_bufflen(current_SC)) {
  940. current_SC->SCp.buffer = scsi_sglist(current_SC);
  941. current_SC->SCp.ptr = sg_virt(current_SC->SCp.buffer);
  942. current_SC->SCp.this_residual = current_SC->SCp.buffer->length;
  943. current_SC->SCp.buffers_residual = scsi_sg_count(current_SC) - 1;
  944. } else {
  945. current_SC->SCp.ptr = NULL;
  946. current_SC->SCp.this_residual = 0;
  947. current_SC->SCp.buffer = NULL;
  948. current_SC->SCp.buffers_residual = 0;
  949. }
  950. current_SC->SCp.Status = 0;
  951. current_SC->SCp.Message = 0;
  952. current_SC->SCp.have_data_in = 0;
  953. current_SC->SCp.sent_command = 0;
  954. current_SC->SCp.phase = in_arbitration;
  955. /* Start arbitration */
  956. outb(0x00, Interrupt_Cntl_port);
  957. outb(0x00, SCSI_Cntl_port); /* Disable data drivers */
  958. outb(adapter_mask, SCSI_Data_NoACK_port); /* Set our id bit */
  959. in_command = 1;
  960. outb(0x20, Interrupt_Cntl_port);
  961. outb(0x14 | PARITY_MASK, TMC_Cntl_port); /* Start arbitration */
  962. return 0;
  963. }
  964. static DEF_SCSI_QCMD(fd_mcs_queue)
  965. #if DEBUG_ABORT || DEBUG_RESET
  966. static void fd_mcs_print_info(Scsi_Cmnd * SCpnt)
  967. {
  968. unsigned int imr;
  969. unsigned int irr;
  970. unsigned int isr;
  971. struct Scsi_Host *shpnt = SCpnt->host;
  972. if (!SCpnt || !SCpnt->host) {
  973. printk("fd_mcs: cannot provide detailed information\n");
  974. }
  975. printk("%s\n", fd_mcs_info(SCpnt->host));
  976. print_banner(SCpnt->host);
  977. switch (SCpnt->SCp.phase) {
  978. case in_arbitration:
  979. printk("arbitration ");
  980. break;
  981. case in_selection:
  982. printk("selection ");
  983. break;
  984. case in_other:
  985. printk("other ");
  986. break;
  987. default:
  988. printk("unknown ");
  989. break;
  990. }
  991. printk("(%d), target = %d cmnd = 0x%02x pieces = %d size = %u\n",
  992. SCpnt->SCp.phase, SCpnt->device->id, *(unsigned char *) SCpnt->cmnd,
  993. scsi_sg_count(SCpnt), scsi_bufflen(SCpnt));
  994. printk("sent_command = %d, have_data_in = %d, timeout = %d\n", SCpnt->SCp.sent_command, SCpnt->SCp.have_data_in, SCpnt->timeout);
  995. #if DEBUG_RACE
  996. printk("in_interrupt_flag = %d\n", in_interrupt_flag);
  997. #endif
  998. imr = (inb(0x0a1) << 8) + inb(0x21);
  999. outb(0x0a, 0xa0);
  1000. irr = inb(0xa0) << 8;
  1001. outb(0x0a, 0x20);
  1002. irr += inb(0x20);
  1003. outb(0x0b, 0xa0);
  1004. isr = inb(0xa0) << 8;
  1005. outb(0x0b, 0x20);
  1006. isr += inb(0x20);
  1007. /* Print out interesting information */
  1008. printk("IMR = 0x%04x", imr);
  1009. if (imr & (1 << shpnt->irq))
  1010. printk(" (masked)");
  1011. printk(", IRR = 0x%04x, ISR = 0x%04x\n", irr, isr);
  1012. printk("SCSI Status = 0x%02x\n", inb(SCSI_Status_port));
  1013. printk("TMC Status = 0x%02x", inb(TMC_Status_port));
  1014. if (inb(TMC_Status_port) & 1)
  1015. printk(" (interrupt)");
  1016. printk("\n");
  1017. printk("Interrupt Status = 0x%02x", inb(Interrupt_Status_port));
  1018. if (inb(Interrupt_Status_port) & 0x08)
  1019. printk(" (enabled)");
  1020. printk("\n");
  1021. if (chip == tmc18c50 || chip == tmc18c30) {
  1022. printk("FIFO Status = 0x%02x\n", inb(shpnt->io_port + FIFO_Status));
  1023. printk("Int. Condition = 0x%02x\n", inb(shpnt->io_port + Interrupt_Cond));
  1024. }
  1025. printk("Configuration 1 = 0x%02x\n", inb(shpnt->io_port + Configuration1));
  1026. if (chip == tmc18c50 || chip == tmc18c30)
  1027. printk("Configuration 2 = 0x%02x\n", inb(shpnt->io_port + Configuration2));
  1028. }
  1029. #endif
  1030. static int fd_mcs_abort(Scsi_Cmnd * SCpnt)
  1031. {
  1032. struct Scsi_Host *shpnt = SCpnt->device->host;
  1033. unsigned long flags;
  1034. #if EVERY_ACCESS || ERRORS_ONLY || DEBUG_ABORT
  1035. printk("fd_mcs: abort ");
  1036. #endif
  1037. spin_lock_irqsave(shpnt->host_lock, flags);
  1038. if (!in_command) {
  1039. #if EVERY_ACCESS || ERRORS_ONLY
  1040. printk(" (not in command)\n");
  1041. #endif
  1042. spin_unlock_irqrestore(shpnt->host_lock, flags);
  1043. return FAILED;
  1044. } else
  1045. printk("\n");
  1046. #if DEBUG_ABORT
  1047. fd_mcs_print_info(SCpnt);
  1048. #endif
  1049. fd_mcs_make_bus_idle(shpnt);
  1050. current_SC->SCp.phase |= aborted;
  1051. current_SC->result = DID_ABORT << 16;
  1052. /* Aborts are not done well. . . */
  1053. my_done(shpnt, DID_ABORT << 16);
  1054. spin_unlock_irqrestore(shpnt->host_lock, flags);
  1055. return SUCCESS;
  1056. }
  1057. static int fd_mcs_bus_reset(Scsi_Cmnd * SCpnt) {
  1058. struct Scsi_Host *shpnt = SCpnt->device->host;
  1059. unsigned long flags;
  1060. #if DEBUG_RESET
  1061. static int called_once = 0;
  1062. #endif
  1063. #if ERRORS_ONLY
  1064. if (SCpnt)
  1065. printk("fd_mcs: SCSI Bus Reset\n");
  1066. #endif
  1067. #if DEBUG_RESET
  1068. if (called_once)
  1069. fd_mcs_print_info(current_SC);
  1070. called_once = 1;
  1071. #endif
  1072. spin_lock_irqsave(shpnt->host_lock, flags);
  1073. outb(1, SCSI_Cntl_port);
  1074. do_pause(2);
  1075. outb(0, SCSI_Cntl_port);
  1076. do_pause(115);
  1077. outb(0, SCSI_Mode_Cntl_port);
  1078. outb(PARITY_MASK, TMC_Cntl_port);
  1079. spin_unlock_irqrestore(shpnt->host_lock, flags);
  1080. /* Unless this is the very first call (i.e., SCPnt == NULL), everything
  1081. is probably hosed at this point. We will, however, try to keep
  1082. things going by informing the high-level code that we need help. */
  1083. return SUCCESS;
  1084. }
  1085. #include <scsi/scsi_ioctl.h>
  1086. static int fd_mcs_biosparam(struct scsi_device * disk, struct block_device *bdev,
  1087. sector_t capacity, int *info_array)
  1088. {
  1089. unsigned char *p = scsi_bios_ptable(bdev);
  1090. int size = capacity;
  1091. /* BIOS >= 3.4 for MCA cards */
  1092. /* This algorithm was provided by Future Domain (much thanks!). */
  1093. if (p && p[65] == 0xaa && p[64] == 0x55 /* Partition table valid */
  1094. && p[4]) { /* Partition type */
  1095. /* The partition table layout is as follows:
  1096. Start: 0x1b3h
  1097. Offset: 0 = partition status
  1098. 1 = starting head
  1099. 2 = starting sector and cylinder (word, encoded)
  1100. 4 = partition type
  1101. 5 = ending head
  1102. 6 = ending sector and cylinder (word, encoded)
  1103. 8 = starting absolute sector (double word)
  1104. c = number of sectors (double word)
  1105. Signature: 0x1fe = 0x55aa
  1106. So, this algorithm assumes:
  1107. 1) the first partition table is in use,
  1108. 2) the data in the first entry is correct, and
  1109. 3) partitions never divide cylinders
  1110. Note that (1) may be FALSE for NetBSD (and other BSD flavors),
  1111. as well as for Linux. Note also, that Linux doesn't pay any
  1112. attention to the fields that are used by this algorithm -- it
  1113. only uses the absolute sector data. Recent versions of Linux's
  1114. fdisk(1) will fill this data in correctly, and forthcoming
  1115. versions will check for consistency.
  1116. Checking for a non-zero partition type is not part of the
  1117. Future Domain algorithm, but it seemed to be a reasonable thing
  1118. to do, especially in the Linux and BSD worlds. */
  1119. info_array[0] = p[5] + 1; /* heads */
  1120. info_array[1] = p[6] & 0x3f; /* sectors */
  1121. } else {
  1122. /* Note that this new method guarantees that there will always be
  1123. less than 1024 cylinders on a platter. This is good for drives
  1124. up to approximately 7.85GB (where 1GB = 1024 * 1024 kB). */
  1125. if ((unsigned int) size >= 0x7e0000U)
  1126. {
  1127. info_array[0] = 0xff; /* heads = 255 */
  1128. info_array[1] = 0x3f; /* sectors = 63 */
  1129. } else if ((unsigned int) size >= 0x200000U) {
  1130. info_array[0] = 0x80; /* heads = 128 */
  1131. info_array[1] = 0x3f; /* sectors = 63 */
  1132. } else {
  1133. info_array[0] = 0x40; /* heads = 64 */
  1134. info_array[1] = 0x20; /* sectors = 32 */
  1135. }
  1136. }
  1137. /* For both methods, compute the cylinders */
  1138. info_array[2] = (unsigned int) size / (info_array[0] * info_array[1]);
  1139. kfree(p);
  1140. return 0;
  1141. }
  1142. static struct scsi_host_template driver_template = {
  1143. .proc_name = "fd_mcs",
  1144. .proc_info = fd_mcs_proc_info,
  1145. .detect = fd_mcs_detect,
  1146. .release = fd_mcs_release,
  1147. .info = fd_mcs_info,
  1148. .queuecommand = fd_mcs_queue,
  1149. .eh_abort_handler = fd_mcs_abort,
  1150. .eh_bus_reset_handler = fd_mcs_bus_reset,
  1151. .bios_param = fd_mcs_biosparam,
  1152. .can_queue = 1,
  1153. .this_id = 7,
  1154. .sg_tablesize = 64,
  1155. .cmd_per_lun = 1,
  1156. .use_clustering = DISABLE_CLUSTERING,
  1157. };
  1158. #include "scsi_module.c"
  1159. MODULE_LICENSE("GPL");