sym53c500_cs.c 23 KB

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