fd_mcs.c 39 KB

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