sym53c500_cs.c 23 KB

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