sym53c500_cs.c 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930
  1. /*
  2. * sym53c500_cs.c Bob Tracy (rct@frus.com)
  3. *
  4. * A rewrite of the pcmcia-cs add-on driver for newer (circa 1997)
  5. * New Media Bus Toaster PCMCIA SCSI cards using the Symbios Logic
  6. * 53c500 controller: intended for use with 2.6 and later kernels.
  7. * The pcmcia-cs add-on version of this driver is not supported
  8. * beyond 2.4. It consisted of three files with history/copyright
  9. * information as follows:
  10. *
  11. * SYM53C500.h
  12. * Bob Tracy (rct@frus.com)
  13. * Original by Tom Corner (tcorner@via.at).
  14. * Adapted from NCR53c406a.h which is Copyrighted (C) 1994
  15. * Normunds Saumanis (normunds@rx.tech.swh.lv)
  16. *
  17. * SYM53C500.c
  18. * Bob Tracy (rct@frus.com)
  19. * Original driver by Tom Corner (tcorner@via.at) was adapted
  20. * from NCR53c406a.c which is Copyrighted (C) 1994, 1995, 1996
  21. * Normunds Saumanis (normunds@fi.ibm.com)
  22. *
  23. * sym53c500.c
  24. * Bob Tracy (rct@frus.com)
  25. * Original by Tom Corner (tcorner@via.at) was adapted from a
  26. * driver for the Qlogic SCSI card written by
  27. * David Hinds (dhinds@allegro.stanford.edu).
  28. *
  29. * This program is free software; you can redistribute it and/or modify it
  30. * under the terms of the GNU General Public License as published by the
  31. * Free Software Foundation; either version 2, or (at your option) any
  32. * later version.
  33. *
  34. * This program is distributed in the hope that it will be useful, but
  35. * WITHOUT ANY WARRANTY; without even the implied warranty of
  36. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  37. * General Public License for more details.
  38. */
  39. #define SYM53C500_DEBUG 0
  40. #define VERBOSE_SYM53C500_DEBUG 0
  41. /*
  42. * Set this to 0 if you encounter kernel lockups while transferring
  43. * data in PIO mode. Note this can be changed via "sysfs".
  44. */
  45. #define USE_FAST_PIO 1
  46. /* =============== End of user configurable parameters ============== */
  47. #include <linux/module.h>
  48. #include <linux/moduleparam.h>
  49. #include <linux/errno.h>
  50. #include <linux/init.h>
  51. #include <linux/interrupt.h>
  52. #include <linux/kernel.h>
  53. #include <linux/slab.h>
  54. #include <linux/string.h>
  55. #include <linux/ioport.h>
  56. #include <linux/blkdev.h>
  57. #include <linux/spinlock.h>
  58. #include <linux/bitops.h>
  59. #include <asm/io.h>
  60. #include <asm/dma.h>
  61. #include <asm/irq.h>
  62. #include <scsi/scsi_ioctl.h>
  63. #include <scsi/scsi_cmnd.h>
  64. #include <scsi/scsi_device.h>
  65. #include <scsi/scsi.h>
  66. #include <scsi/scsi_host.h>
  67. #include <pcmcia/cs_types.h>
  68. #include <pcmcia/cs.h>
  69. #include <pcmcia/cistpl.h>
  70. #include <pcmcia/ds.h>
  71. #include <pcmcia/ciscode.h>
  72. /* ================================================================== */
  73. #ifdef PCMCIA_DEBUG
  74. static int pc_debug = PCMCIA_DEBUG;
  75. module_param(pc_debug, int, 0);
  76. #define DEBUG(n, args...) if (pc_debug>(n)) printk(KERN_DEBUG args)
  77. static char *version =
  78. "sym53c500_cs.c 0.9c 2004/10/27 (Bob Tracy)";
  79. #else
  80. #define DEBUG(n, args...)
  81. #endif
  82. /* ================================================================== */
  83. #define SYNC_MODE 0 /* Synchronous transfer mode */
  84. /* Default configuration */
  85. #define C1_IMG 0x07 /* ID=7 */
  86. #define C2_IMG 0x48 /* FE SCSI2 */
  87. #define C3_IMG 0x20 /* CDB */
  88. #define C4_IMG 0x04 /* ANE */
  89. #define C5_IMG 0xa4 /* ? changed from b6= AA PI SIE POL */
  90. #define C7_IMG 0x80 /* added for SYM53C500 t. corner */
  91. /* Hardware Registers: offsets from io_port (base) */
  92. /* Control Register Set 0 */
  93. #define TC_LSB 0x00 /* transfer counter lsb */
  94. #define TC_MSB 0x01 /* transfer counter msb */
  95. #define SCSI_FIFO 0x02 /* scsi fifo register */
  96. #define CMD_REG 0x03 /* command register */
  97. #define STAT_REG 0x04 /* status register */
  98. #define DEST_ID 0x04 /* selection/reselection bus id */
  99. #define INT_REG 0x05 /* interrupt status register */
  100. #define SRTIMOUT 0x05 /* select/reselect timeout reg */
  101. #define SEQ_REG 0x06 /* sequence step register */
  102. #define SYNCPRD 0x06 /* synchronous transfer period */
  103. #define FIFO_FLAGS 0x07 /* indicates # of bytes in fifo */
  104. #define SYNCOFF 0x07 /* synchronous offset register */
  105. #define CONFIG1 0x08 /* configuration register */
  106. #define CLKCONV 0x09 /* clock conversion register */
  107. /* #define TESTREG 0x0A */ /* test mode register */
  108. #define CONFIG2 0x0B /* configuration 2 register */
  109. #define CONFIG3 0x0C /* configuration 3 register */
  110. #define CONFIG4 0x0D /* configuration 4 register */
  111. #define TC_HIGH 0x0E /* transfer counter high */
  112. /* #define FIFO_BOTTOM 0x0F */ /* reserve FIFO byte register */
  113. /* Control Register Set 1 */
  114. /* #define JUMPER_SENSE 0x00 */ /* jumper sense port reg (r/w) */
  115. /* #define SRAM_PTR 0x01 */ /* SRAM address pointer reg (r/w) */
  116. /* #define SRAM_DATA 0x02 */ /* SRAM data register (r/w) */
  117. #define PIO_FIFO 0x04 /* PIO FIFO registers (r/w) */
  118. /* #define PIO_FIFO1 0x05 */ /* */
  119. /* #define PIO_FIFO2 0x06 */ /* */
  120. /* #define PIO_FIFO3 0x07 */ /* */
  121. #define PIO_STATUS 0x08 /* PIO status (r/w) */
  122. /* #define ATA_CMD 0x09 */ /* ATA command/status reg (r/w) */
  123. /* #define ATA_ERR 0x0A */ /* ATA features/error reg (r/w) */
  124. #define PIO_FLAG 0x0B /* PIO flag interrupt enable (r/w) */
  125. #define CONFIG5 0x09 /* configuration 5 register */
  126. /* #define SIGNATURE 0x0E */ /* signature register (r) */
  127. /* #define CONFIG6 0x0F */ /* configuration 6 register (r) */
  128. #define CONFIG7 0x0d
  129. /* select register set 0 */
  130. #define REG0(x) (outb(C4_IMG, (x) + CONFIG4))
  131. /* select register set 1 */
  132. #define REG1(x) outb(C7_IMG, (x) + CONFIG7); outb(C5_IMG, (x) + CONFIG5)
  133. #if SYM53C500_DEBUG
  134. #define DEB(x) x
  135. #else
  136. #define DEB(x)
  137. #endif
  138. #if VERBOSE_SYM53C500_DEBUG
  139. #define VDEB(x) x
  140. #else
  141. #define VDEB(x)
  142. #endif
  143. #define LOAD_DMA_COUNT(x, count) \
  144. outb(count & 0xff, (x) + TC_LSB); \
  145. outb((count >> 8) & 0xff, (x) + TC_MSB); \
  146. outb((count >> 16) & 0xff, (x) + TC_HIGH);
  147. /* Chip commands */
  148. #define DMA_OP 0x80
  149. #define SCSI_NOP 0x00
  150. #define FLUSH_FIFO 0x01
  151. #define CHIP_RESET 0x02
  152. #define SCSI_RESET 0x03
  153. #define RESELECT 0x40
  154. #define SELECT_NO_ATN 0x41
  155. #define SELECT_ATN 0x42
  156. #define SELECT_ATN_STOP 0x43
  157. #define ENABLE_SEL 0x44
  158. #define DISABLE_SEL 0x45
  159. #define SELECT_ATN3 0x46
  160. #define RESELECT3 0x47
  161. #define TRANSFER_INFO 0x10
  162. #define INIT_CMD_COMPLETE 0x11
  163. #define MSG_ACCEPT 0x12
  164. #define TRANSFER_PAD 0x18
  165. #define SET_ATN 0x1a
  166. #define RESET_ATN 0x1b
  167. #define SEND_MSG 0x20
  168. #define SEND_STATUS 0x21
  169. #define SEND_DATA 0x22
  170. #define DISCONN_SEQ 0x23
  171. #define TERMINATE_SEQ 0x24
  172. #define TARG_CMD_COMPLETE 0x25
  173. #define DISCONN 0x27
  174. #define RECV_MSG 0x28
  175. #define RECV_CMD 0x29
  176. #define RECV_DATA 0x2a
  177. #define RECV_CMD_SEQ 0x2b
  178. #define TARGET_ABORT_DMA 0x04
  179. /* ================================================================== */
  180. struct scsi_info_t {
  181. struct pcmcia_device *p_dev;
  182. dev_node_t node;
  183. struct Scsi_Host *host;
  184. unsigned short manf_id;
  185. };
  186. /*
  187. * Repository for per-instance host data.
  188. */
  189. struct sym53c500_data {
  190. struct scsi_cmnd *current_SC;
  191. int fast_pio;
  192. };
  193. enum Phase {
  194. idle,
  195. data_out,
  196. data_in,
  197. command_ph,
  198. status_ph,
  199. message_out,
  200. message_in
  201. };
  202. /* ================================================================== */
  203. static void
  204. chip_init(int io_port)
  205. {
  206. REG1(io_port);
  207. outb(0x01, io_port + PIO_STATUS);
  208. outb(0x00, io_port + PIO_FLAG);
  209. outb(C4_IMG, io_port + CONFIG4); /* REG0(io_port); */
  210. outb(C3_IMG, io_port + CONFIG3);
  211. outb(C2_IMG, io_port + CONFIG2);
  212. outb(C1_IMG, io_port + CONFIG1);
  213. outb(0x05, io_port + CLKCONV); /* clock conversion factor */
  214. outb(0x9C, io_port + SRTIMOUT); /* Selection timeout */
  215. outb(0x05, io_port + SYNCPRD); /* Synchronous transfer period */
  216. outb(SYNC_MODE, io_port + SYNCOFF); /* synchronous mode */
  217. }
  218. static void
  219. SYM53C500_int_host_reset(int io_port)
  220. {
  221. outb(C4_IMG, io_port + CONFIG4); /* REG0(io_port); */
  222. outb(CHIP_RESET, io_port + CMD_REG);
  223. outb(SCSI_NOP, io_port + CMD_REG); /* required after reset */
  224. outb(SCSI_RESET, io_port + CMD_REG);
  225. chip_init(io_port);
  226. }
  227. static __inline__ int
  228. SYM53C500_pio_read(int fast_pio, int base, unsigned char *request, unsigned int reqlen)
  229. {
  230. int i;
  231. int len; /* current scsi fifo size */
  232. REG1(base);
  233. while (reqlen) {
  234. i = inb(base + PIO_STATUS);
  235. /* VDEB(printk("pio_status=%x\n", i)); */
  236. if (i & 0x80)
  237. return 0;
  238. switch (i & 0x1e) {
  239. default:
  240. case 0x10: /* fifo empty */
  241. len = 0;
  242. break;
  243. case 0x0:
  244. len = 1;
  245. break;
  246. case 0x8: /* fifo 1/3 full */
  247. len = 42;
  248. break;
  249. case 0xc: /* fifo 2/3 full */
  250. len = 84;
  251. break;
  252. case 0xe: /* fifo full */
  253. len = 128;
  254. break;
  255. }
  256. if ((i & 0x40) && len == 0) { /* fifo empty and interrupt occurred */
  257. return 0;
  258. }
  259. if (len) {
  260. if (len > reqlen)
  261. len = reqlen;
  262. if (fast_pio && len > 3) {
  263. insl(base + PIO_FIFO, request, len >> 2);
  264. request += len & 0xfc;
  265. reqlen -= len & 0xfc;
  266. } else {
  267. while (len--) {
  268. *request++ = inb(base + PIO_FIFO);
  269. reqlen--;
  270. }
  271. }
  272. }
  273. }
  274. return 0;
  275. }
  276. static __inline__ int
  277. SYM53C500_pio_write(int fast_pio, int base, unsigned char *request, unsigned int reqlen)
  278. {
  279. int i = 0;
  280. int len; /* current scsi fifo size */
  281. REG1(base);
  282. while (reqlen && !(i & 0x40)) {
  283. i = inb(base + PIO_STATUS);
  284. /* VDEB(printk("pio_status=%x\n", i)); */
  285. if (i & 0x80) /* error */
  286. return 0;
  287. switch (i & 0x1e) {
  288. case 0x10:
  289. len = 128;
  290. break;
  291. case 0x0:
  292. len = 84;
  293. break;
  294. case 0x8:
  295. len = 42;
  296. break;
  297. case 0xc:
  298. len = 1;
  299. break;
  300. default:
  301. case 0xe:
  302. len = 0;
  303. break;
  304. }
  305. if (len) {
  306. if (len > reqlen)
  307. len = reqlen;
  308. if (fast_pio && len > 3) {
  309. outsl(base + PIO_FIFO, request, len >> 2);
  310. request += len & 0xfc;
  311. reqlen -= len & 0xfc;
  312. } else {
  313. while (len--) {
  314. outb(*request++, base + PIO_FIFO);
  315. reqlen--;
  316. }
  317. }
  318. }
  319. }
  320. return 0;
  321. }
  322. static irqreturn_t
  323. SYM53C500_intr(int irq, void *dev_id)
  324. {
  325. unsigned long flags;
  326. struct Scsi_Host *dev = dev_id;
  327. DEB(unsigned char fifo_size;)
  328. DEB(unsigned char seq_reg;)
  329. unsigned char status, int_reg;
  330. unsigned char pio_status;
  331. int port_base = dev->io_port;
  332. struct sym53c500_data *data =
  333. (struct sym53c500_data *)dev->hostdata;
  334. struct scsi_cmnd *curSC = data->current_SC;
  335. int fast_pio = data->fast_pio;
  336. spin_lock_irqsave(dev->host_lock, flags);
  337. VDEB(printk("SYM53C500_intr called\n"));
  338. REG1(port_base);
  339. pio_status = inb(port_base + PIO_STATUS);
  340. REG0(port_base);
  341. status = inb(port_base + STAT_REG);
  342. DEB(seq_reg = inb(port_base + SEQ_REG));
  343. int_reg = inb(port_base + INT_REG);
  344. DEB(fifo_size = inb(port_base + FIFO_FLAGS) & 0x1f);
  345. #if SYM53C500_DEBUG
  346. printk("status=%02x, seq_reg=%02x, int_reg=%02x, fifo_size=%02x",
  347. status, seq_reg, int_reg, fifo_size);
  348. printk(", pio=%02x\n", pio_status);
  349. #endif /* SYM53C500_DEBUG */
  350. if (int_reg & 0x80) { /* SCSI reset intr */
  351. DEB(printk("SYM53C500: reset intr received\n"));
  352. curSC->result = DID_RESET << 16;
  353. goto idle_out;
  354. }
  355. if (pio_status & 0x80) {
  356. printk("SYM53C500: Warning: PIO error!\n");
  357. curSC->result = DID_ERROR << 16;
  358. goto idle_out;
  359. }
  360. if (status & 0x20) { /* Parity error */
  361. printk("SYM53C500: Warning: parity error!\n");
  362. curSC->result = DID_PARITY << 16;
  363. goto idle_out;
  364. }
  365. if (status & 0x40) { /* Gross error */
  366. printk("SYM53C500: Warning: gross error!\n");
  367. curSC->result = DID_ERROR << 16;
  368. goto idle_out;
  369. }
  370. if (int_reg & 0x20) { /* Disconnect */
  371. DEB(printk("SYM53C500: disconnect intr received\n"));
  372. if (curSC->SCp.phase != message_in) { /* Unexpected disconnect */
  373. curSC->result = DID_NO_CONNECT << 16;
  374. } else { /* Command complete, return status and message */
  375. curSC->result = (curSC->SCp.Status & 0xff)
  376. | ((curSC->SCp.Message & 0xff) << 8) | (DID_OK << 16);
  377. }
  378. goto idle_out;
  379. }
  380. switch (status & 0x07) { /* scsi phase */
  381. case 0x00: /* DATA-OUT */
  382. if (int_reg & 0x10) { /* Target requesting info transfer */
  383. struct scatterlist *sg;
  384. int i;
  385. curSC->SCp.phase = data_out;
  386. VDEB(printk("SYM53C500: Data-Out phase\n"));
  387. outb(FLUSH_FIFO, port_base + CMD_REG);
  388. LOAD_DMA_COUNT(port_base, scsi_bufflen(curSC)); /* Max transfer size */
  389. outb(TRANSFER_INFO | DMA_OP, port_base + CMD_REG);
  390. scsi_for_each_sg(curSC, sg, scsi_sg_count(curSC), i) {
  391. SYM53C500_pio_write(fast_pio, port_base,
  392. sg_virt(sg), sg->length);
  393. }
  394. REG0(port_base);
  395. }
  396. break;
  397. case 0x01: /* DATA-IN */
  398. if (int_reg & 0x10) { /* Target requesting info transfer */
  399. struct scatterlist *sg;
  400. int i;
  401. curSC->SCp.phase = data_in;
  402. VDEB(printk("SYM53C500: Data-In phase\n"));
  403. outb(FLUSH_FIFO, port_base + CMD_REG);
  404. LOAD_DMA_COUNT(port_base, scsi_bufflen(curSC)); /* Max transfer size */
  405. outb(TRANSFER_INFO | DMA_OP, port_base + CMD_REG);
  406. scsi_for_each_sg(curSC, sg, scsi_sg_count(curSC), i) {
  407. SYM53C500_pio_read(fast_pio, port_base,
  408. sg_virt(sg), sg->length);
  409. }
  410. REG0(port_base);
  411. }
  412. break;
  413. case 0x02: /* COMMAND */
  414. curSC->SCp.phase = command_ph;
  415. printk("SYM53C500: Warning: Unknown interrupt occurred in command phase!\n");
  416. break;
  417. case 0x03: /* STATUS */
  418. curSC->SCp.phase = status_ph;
  419. VDEB(printk("SYM53C500: Status phase\n"));
  420. outb(FLUSH_FIFO, port_base + CMD_REG);
  421. outb(INIT_CMD_COMPLETE, port_base + CMD_REG);
  422. break;
  423. case 0x04: /* Reserved */
  424. case 0x05: /* Reserved */
  425. printk("SYM53C500: WARNING: Reserved phase!!!\n");
  426. break;
  427. case 0x06: /* MESSAGE-OUT */
  428. DEB(printk("SYM53C500: Message-Out phase\n"));
  429. curSC->SCp.phase = message_out;
  430. outb(SET_ATN, port_base + CMD_REG); /* Reject the message */
  431. outb(MSG_ACCEPT, port_base + CMD_REG);
  432. break;
  433. case 0x07: /* MESSAGE-IN */
  434. VDEB(printk("SYM53C500: Message-In phase\n"));
  435. curSC->SCp.phase = message_in;
  436. curSC->SCp.Status = inb(port_base + SCSI_FIFO);
  437. curSC->SCp.Message = inb(port_base + SCSI_FIFO);
  438. VDEB(printk("SCSI FIFO size=%d\n", inb(port_base + FIFO_FLAGS) & 0x1f));
  439. DEB(printk("Status = %02x Message = %02x\n", curSC->SCp.Status, curSC->SCp.Message));
  440. if (curSC->SCp.Message == SAVE_POINTERS || curSC->SCp.Message == DISCONNECT) {
  441. outb(SET_ATN, port_base + CMD_REG); /* Reject message */
  442. DEB(printk("Discarding SAVE_POINTERS message\n"));
  443. }
  444. outb(MSG_ACCEPT, port_base + CMD_REG);
  445. break;
  446. }
  447. out:
  448. spin_unlock_irqrestore(dev->host_lock, flags);
  449. return IRQ_HANDLED;
  450. idle_out:
  451. curSC->SCp.phase = idle;
  452. curSC->scsi_done(curSC);
  453. goto out;
  454. }
  455. static void
  456. SYM53C500_release(struct pcmcia_device *link)
  457. {
  458. struct scsi_info_t *info = link->priv;
  459. struct Scsi_Host *shost = info->host;
  460. DEBUG(0, "SYM53C500_release(0x%p)\n", link);
  461. /*
  462. * Do this before releasing/freeing resources.
  463. */
  464. scsi_remove_host(shost);
  465. /*
  466. * Interrupts getting hosed on card removal. Try
  467. * the following code, mostly from qlogicfas.c.
  468. */
  469. if (shost->irq)
  470. free_irq(shost->irq, shost);
  471. if (shost->io_port && shost->n_io_port)
  472. release_region(shost->io_port, shost->n_io_port);
  473. pcmcia_disable_device(link);
  474. scsi_host_put(shost);
  475. } /* SYM53C500_release */
  476. static const char*
  477. SYM53C500_info(struct Scsi_Host *SChost)
  478. {
  479. static char info_msg[256];
  480. struct sym53c500_data *data =
  481. (struct sym53c500_data *)SChost->hostdata;
  482. DEB(printk("SYM53C500_info called\n"));
  483. (void)snprintf(info_msg, sizeof(info_msg),
  484. "SYM53C500 at 0x%lx, IRQ %d, %s PIO mode.",
  485. SChost->io_port, SChost->irq, data->fast_pio ? "fast" : "slow");
  486. return (info_msg);
  487. }
  488. static int
  489. SYM53C500_queue(struct scsi_cmnd *SCpnt, void (*done)(struct scsi_cmnd *))
  490. {
  491. int i;
  492. int port_base = SCpnt->device->host->io_port;
  493. struct sym53c500_data *data =
  494. (struct sym53c500_data *)SCpnt->device->host->hostdata;
  495. VDEB(printk("SYM53C500_queue called\n"));
  496. DEB(printk("cmd=%02x, cmd_len=%02x, target=%02x, lun=%02x, bufflen=%d\n",
  497. SCpnt->cmnd[0], SCpnt->cmd_len, SCpnt->device->id,
  498. SCpnt->device->lun, scsi_bufflen(SCpnt)));
  499. VDEB(for (i = 0; i < SCpnt->cmd_len; i++)
  500. printk("cmd[%d]=%02x ", i, SCpnt->cmnd[i]));
  501. VDEB(printk("\n"));
  502. data->current_SC = SCpnt;
  503. data->current_SC->scsi_done = done;
  504. data->current_SC->SCp.phase = command_ph;
  505. data->current_SC->SCp.Status = 0;
  506. data->current_SC->SCp.Message = 0;
  507. /* We are locked here already by the mid layer */
  508. REG0(port_base);
  509. outb(scmd_id(SCpnt), port_base + DEST_ID); /* set destination */
  510. outb(FLUSH_FIFO, port_base + CMD_REG); /* reset the fifos */
  511. for (i = 0; i < SCpnt->cmd_len; i++) {
  512. outb(SCpnt->cmnd[i], port_base + SCSI_FIFO);
  513. }
  514. outb(SELECT_NO_ATN, port_base + CMD_REG);
  515. return 0;
  516. }
  517. static int
  518. SYM53C500_host_reset(struct scsi_cmnd *SCpnt)
  519. {
  520. int port_base = SCpnt->device->host->io_port;
  521. DEB(printk("SYM53C500_host_reset called\n"));
  522. spin_lock_irq(SCpnt->device->host->host_lock);
  523. SYM53C500_int_host_reset(port_base);
  524. spin_unlock_irq(SCpnt->device->host->host_lock);
  525. return SUCCESS;
  526. }
  527. static int
  528. SYM53C500_biosparm(struct scsi_device *disk,
  529. struct block_device *dev,
  530. sector_t capacity, int *info_array)
  531. {
  532. int size;
  533. DEB(printk("SYM53C500_biosparm called\n"));
  534. size = capacity;
  535. info_array[0] = 64; /* heads */
  536. info_array[1] = 32; /* sectors */
  537. info_array[2] = size >> 11; /* cylinders */
  538. if (info_array[2] > 1024) { /* big disk */
  539. info_array[0] = 255;
  540. info_array[1] = 63;
  541. info_array[2] = size / (255 * 63);
  542. }
  543. return 0;
  544. }
  545. static ssize_t
  546. SYM53C500_show_pio(struct device *dev, struct device_attribute *attr,
  547. char *buf)
  548. {
  549. struct Scsi_Host *SHp = class_to_shost(dev);
  550. struct sym53c500_data *data =
  551. (struct sym53c500_data *)SHp->hostdata;
  552. return snprintf(buf, 4, "%d\n", data->fast_pio);
  553. }
  554. static ssize_t
  555. SYM53C500_store_pio(struct device *dev, struct device_attribute *attr,
  556. const char *buf, size_t count)
  557. {
  558. int pio;
  559. struct Scsi_Host *SHp = class_to_shost(dev);
  560. struct sym53c500_data *data =
  561. (struct sym53c500_data *)SHp->hostdata;
  562. pio = simple_strtoul(buf, NULL, 0);
  563. if (pio == 0 || pio == 1) {
  564. data->fast_pio = pio;
  565. return count;
  566. }
  567. else
  568. return -EINVAL;
  569. }
  570. /*
  571. * SCSI HBA device attributes we want to
  572. * make available via sysfs.
  573. */
  574. static struct device_attribute SYM53C500_pio_attr = {
  575. .attr = {
  576. .name = "fast_pio",
  577. .mode = (S_IRUGO | S_IWUSR),
  578. },
  579. .show = SYM53C500_show_pio,
  580. .store = SYM53C500_store_pio,
  581. };
  582. static struct device_attribute *SYM53C500_shost_attrs[] = {
  583. &SYM53C500_pio_attr,
  584. NULL,
  585. };
  586. /*
  587. * scsi_host_template initializer
  588. */
  589. static struct scsi_host_template sym53c500_driver_template = {
  590. .module = THIS_MODULE,
  591. .name = "SYM53C500",
  592. .info = SYM53C500_info,
  593. .queuecommand = SYM53C500_queue,
  594. .eh_host_reset_handler = SYM53C500_host_reset,
  595. .bios_param = SYM53C500_biosparm,
  596. .proc_name = "SYM53C500",
  597. .can_queue = 1,
  598. .this_id = 7,
  599. .sg_tablesize = 32,
  600. .cmd_per_lun = 1,
  601. .use_clustering = ENABLE_CLUSTERING,
  602. .shost_attrs = SYM53C500_shost_attrs
  603. };
  604. #define CS_CHECK(fn, ret) \
  605. do { last_fn = (fn); if ((last_ret = (ret)) != 0) goto cs_failed; } while (0)
  606. static int
  607. SYM53C500_config(struct pcmcia_device *link)
  608. {
  609. struct scsi_info_t *info = link->priv;
  610. tuple_t tuple;
  611. cisparse_t parse;
  612. int i, last_ret, last_fn;
  613. int irq_level, port_base;
  614. unsigned short tuple_data[32];
  615. struct Scsi_Host *host;
  616. struct scsi_host_template *tpnt = &sym53c500_driver_template;
  617. struct sym53c500_data *data;
  618. DEBUG(0, "SYM53C500_config(0x%p)\n", link);
  619. info->manf_id = link->manf_id;
  620. tuple.TupleData = (cisdata_t *)tuple_data;
  621. tuple.TupleDataMax = 64;
  622. tuple.TupleOffset = 0;
  623. tuple.DesiredTuple = CISTPL_CFTABLE_ENTRY;
  624. CS_CHECK(GetFirstTuple, pcmcia_get_first_tuple(link, &tuple));
  625. while (1) {
  626. if (pcmcia_get_tuple_data(link, &tuple) != 0 ||
  627. pcmcia_parse_tuple(link, &tuple, &parse) != 0)
  628. goto next_entry;
  629. link->conf.ConfigIndex = parse.cftable_entry.index;
  630. link->io.BasePort1 = parse.cftable_entry.io.win[0].base;
  631. link->io.NumPorts1 = parse.cftable_entry.io.win[0].len;
  632. if (link->io.BasePort1 != 0) {
  633. i = pcmcia_request_io(link, &link->io);
  634. if (i == CS_SUCCESS)
  635. break;
  636. }
  637. next_entry:
  638. CS_CHECK(GetNextTuple, pcmcia_get_next_tuple(link, &tuple));
  639. }
  640. CS_CHECK(RequestIRQ, pcmcia_request_irq(link, &link->irq));
  641. CS_CHECK(RequestConfiguration, pcmcia_request_configuration(link, &link->conf));
  642. /*
  643. * That's the trouble with copying liberally from another driver.
  644. * Some things probably aren't relevant, and I suspect this entire
  645. * section dealing with manufacturer IDs can be scrapped. --rct
  646. */
  647. if ((info->manf_id == MANFID_MACNICA) ||
  648. (info->manf_id == MANFID_PIONEER) ||
  649. (info->manf_id == 0x0098)) {
  650. /* set ATAcmd */
  651. outb(0xb4, link->io.BasePort1 + 0xd);
  652. outb(0x24, link->io.BasePort1 + 0x9);
  653. outb(0x04, link->io.BasePort1 + 0xd);
  654. }
  655. /*
  656. * irq_level == 0 implies tpnt->can_queue == 0, which
  657. * is not supported in 2.6. Thus, only irq_level > 0
  658. * will be allowed.
  659. *
  660. * Possible port_base values are as follows:
  661. *
  662. * 0x130, 0x230, 0x280, 0x290,
  663. * 0x320, 0x330, 0x340, 0x350
  664. */
  665. port_base = link->io.BasePort1;
  666. irq_level = link->irq.AssignedIRQ;
  667. DEB(printk("SYM53C500: port_base=0x%x, irq=%d, fast_pio=%d\n",
  668. port_base, irq_level, USE_FAST_PIO);)
  669. chip_init(port_base);
  670. host = scsi_host_alloc(tpnt, sizeof(struct sym53c500_data));
  671. if (!host) {
  672. printk("SYM53C500: Unable to register host, giving up.\n");
  673. goto err_release;
  674. }
  675. data = (struct sym53c500_data *)host->hostdata;
  676. if (irq_level > 0) {
  677. if (request_irq(irq_level, SYM53C500_intr, IRQF_SHARED, "SYM53C500", host)) {
  678. printk("SYM53C500: unable to allocate IRQ %d\n", irq_level);
  679. goto err_free_scsi;
  680. }
  681. DEB(printk("SYM53C500: allocated IRQ %d\n", irq_level));
  682. } else if (irq_level == 0) {
  683. DEB(printk("SYM53C500: No interrupts detected\n"));
  684. goto err_free_scsi;
  685. } else {
  686. DEB(printk("SYM53C500: Shouldn't get here!\n"));
  687. goto err_free_scsi;
  688. }
  689. host->unique_id = port_base;
  690. host->irq = irq_level;
  691. host->io_port = port_base;
  692. host->n_io_port = 0x10;
  693. host->dma_channel = -1;
  694. /*
  695. * Note fast_pio is set to USE_FAST_PIO by
  696. * default, but can be changed via "sysfs".
  697. */
  698. data->fast_pio = USE_FAST_PIO;
  699. sprintf(info->node.dev_name, "scsi%d", host->host_no);
  700. link->dev_node = &info->node;
  701. info->host = host;
  702. if (scsi_add_host(host, NULL))
  703. goto err_free_irq;
  704. scsi_scan_host(host);
  705. return 0;
  706. err_free_irq:
  707. free_irq(irq_level, host);
  708. err_free_scsi:
  709. scsi_host_put(host);
  710. err_release:
  711. release_region(port_base, 0x10);
  712. printk(KERN_INFO "sym53c500_cs: no SCSI devices found\n");
  713. return -ENODEV;
  714. cs_failed:
  715. cs_error(link, last_fn, last_ret);
  716. SYM53C500_release(link);
  717. return -ENODEV;
  718. } /* SYM53C500_config */
  719. static int sym53c500_resume(struct pcmcia_device *link)
  720. {
  721. struct scsi_info_t *info = link->priv;
  722. /* See earlier comment about manufacturer IDs. */
  723. if ((info->manf_id == MANFID_MACNICA) ||
  724. (info->manf_id == MANFID_PIONEER) ||
  725. (info->manf_id == 0x0098)) {
  726. outb(0x80, link->io.BasePort1 + 0xd);
  727. outb(0x24, link->io.BasePort1 + 0x9);
  728. outb(0x04, link->io.BasePort1 + 0xd);
  729. }
  730. /*
  731. * If things don't work after a "resume",
  732. * this is a good place to start looking.
  733. */
  734. SYM53C500_int_host_reset(link->io.BasePort1);
  735. return 0;
  736. }
  737. static void
  738. SYM53C500_detach(struct pcmcia_device *link)
  739. {
  740. DEBUG(0, "SYM53C500_detach(0x%p)\n", link);
  741. SYM53C500_release(link);
  742. kfree(link->priv);
  743. link->priv = NULL;
  744. } /* SYM53C500_detach */
  745. static int
  746. SYM53C500_probe(struct pcmcia_device *link)
  747. {
  748. struct scsi_info_t *info;
  749. DEBUG(0, "SYM53C500_attach()\n");
  750. /* Create new SCSI device */
  751. info = kzalloc(sizeof(*info), GFP_KERNEL);
  752. if (!info)
  753. return -ENOMEM;
  754. info->p_dev = link;
  755. link->priv = info;
  756. link->io.NumPorts1 = 16;
  757. link->io.Attributes1 = IO_DATA_PATH_WIDTH_AUTO;
  758. link->io.IOAddrLines = 10;
  759. link->irq.Attributes = IRQ_TYPE_EXCLUSIVE;
  760. link->irq.IRQInfo1 = IRQ_LEVEL_ID;
  761. link->conf.Attributes = CONF_ENABLE_IRQ;
  762. link->conf.IntType = INT_MEMORY_AND_IO;
  763. return SYM53C500_config(link);
  764. } /* SYM53C500_attach */
  765. MODULE_AUTHOR("Bob Tracy <rct@frus.com>");
  766. MODULE_DESCRIPTION("SYM53C500 PCMCIA SCSI driver");
  767. MODULE_LICENSE("GPL");
  768. static struct pcmcia_device_id sym53c500_ids[] = {
  769. PCMCIA_DEVICE_PROD_ID12("BASICS by New Media Corporation", "SCSI Sym53C500", 0x23c78a9d, 0x0099e7f7),
  770. PCMCIA_DEVICE_PROD_ID12("New Media Corporation", "SCSI Bus Toaster Sym53C500", 0x085a850b, 0x45432eb8),
  771. PCMCIA_DEVICE_PROD_ID2("SCSI9000", 0x21648f44),
  772. PCMCIA_DEVICE_NULL,
  773. };
  774. MODULE_DEVICE_TABLE(pcmcia, sym53c500_ids);
  775. static struct pcmcia_driver sym53c500_cs_driver = {
  776. .owner = THIS_MODULE,
  777. .drv = {
  778. .name = "sym53c500_cs",
  779. },
  780. .probe = SYM53C500_probe,
  781. .remove = SYM53C500_detach,
  782. .id_table = sym53c500_ids,
  783. .resume = sym53c500_resume,
  784. };
  785. static int __init
  786. init_sym53c500_cs(void)
  787. {
  788. return pcmcia_register_driver(&sym53c500_cs_driver);
  789. }
  790. static void __exit
  791. exit_sym53c500_cs(void)
  792. {
  793. pcmcia_unregister_driver(&sym53c500_cs_driver);
  794. }
  795. module_init(init_sym53c500_cs);
  796. module_exit(exit_sym53c500_cs);