sym53c500_cs.c 24 KB

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