sym53c500_cs.c 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907
  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. struct Scsi_Host *host;
  173. unsigned short manf_id;
  174. };
  175. /*
  176. * Repository for per-instance host data.
  177. */
  178. struct sym53c500_data {
  179. struct scsi_cmnd *current_SC;
  180. int fast_pio;
  181. };
  182. enum Phase {
  183. idle,
  184. data_out,
  185. data_in,
  186. command_ph,
  187. status_ph,
  188. message_out,
  189. message_in
  190. };
  191. /* ================================================================== */
  192. static void
  193. chip_init(int io_port)
  194. {
  195. REG1(io_port);
  196. outb(0x01, io_port + PIO_STATUS);
  197. outb(0x00, io_port + PIO_FLAG);
  198. outb(C4_IMG, io_port + CONFIG4); /* REG0(io_port); */
  199. outb(C3_IMG, io_port + CONFIG3);
  200. outb(C2_IMG, io_port + CONFIG2);
  201. outb(C1_IMG, io_port + CONFIG1);
  202. outb(0x05, io_port + CLKCONV); /* clock conversion factor */
  203. outb(0x9C, io_port + SRTIMOUT); /* Selection timeout */
  204. outb(0x05, io_port + SYNCPRD); /* Synchronous transfer period */
  205. outb(SYNC_MODE, io_port + SYNCOFF); /* synchronous mode */
  206. }
  207. static void
  208. SYM53C500_int_host_reset(int io_port)
  209. {
  210. outb(C4_IMG, io_port + CONFIG4); /* REG0(io_port); */
  211. outb(CHIP_RESET, io_port + CMD_REG);
  212. outb(SCSI_NOP, io_port + CMD_REG); /* required after reset */
  213. outb(SCSI_RESET, io_port + CMD_REG);
  214. chip_init(io_port);
  215. }
  216. static __inline__ int
  217. SYM53C500_pio_read(int fast_pio, int base, unsigned char *request, unsigned int reqlen)
  218. {
  219. int i;
  220. int len; /* current scsi fifo size */
  221. REG1(base);
  222. while (reqlen) {
  223. i = inb(base + PIO_STATUS);
  224. /* VDEB(printk("pio_status=%x\n", i)); */
  225. if (i & 0x80)
  226. return 0;
  227. switch (i & 0x1e) {
  228. default:
  229. case 0x10: /* fifo empty */
  230. len = 0;
  231. break;
  232. case 0x0:
  233. len = 1;
  234. break;
  235. case 0x8: /* fifo 1/3 full */
  236. len = 42;
  237. break;
  238. case 0xc: /* fifo 2/3 full */
  239. len = 84;
  240. break;
  241. case 0xe: /* fifo full */
  242. len = 128;
  243. break;
  244. }
  245. if ((i & 0x40) && len == 0) { /* fifo empty and interrupt occurred */
  246. return 0;
  247. }
  248. if (len) {
  249. if (len > reqlen)
  250. len = reqlen;
  251. if (fast_pio && len > 3) {
  252. insl(base + PIO_FIFO, request, len >> 2);
  253. request += len & 0xfc;
  254. reqlen -= len & 0xfc;
  255. } else {
  256. while (len--) {
  257. *request++ = inb(base + PIO_FIFO);
  258. reqlen--;
  259. }
  260. }
  261. }
  262. }
  263. return 0;
  264. }
  265. static __inline__ int
  266. SYM53C500_pio_write(int fast_pio, int base, unsigned char *request, unsigned int reqlen)
  267. {
  268. int i = 0;
  269. int len; /* current scsi fifo size */
  270. REG1(base);
  271. while (reqlen && !(i & 0x40)) {
  272. i = inb(base + PIO_STATUS);
  273. /* VDEB(printk("pio_status=%x\n", i)); */
  274. if (i & 0x80) /* error */
  275. return 0;
  276. switch (i & 0x1e) {
  277. case 0x10:
  278. len = 128;
  279. break;
  280. case 0x0:
  281. len = 84;
  282. break;
  283. case 0x8:
  284. len = 42;
  285. break;
  286. case 0xc:
  287. len = 1;
  288. break;
  289. default:
  290. case 0xe:
  291. len = 0;
  292. break;
  293. }
  294. if (len) {
  295. if (len > reqlen)
  296. len = reqlen;
  297. if (fast_pio && len > 3) {
  298. outsl(base + PIO_FIFO, request, len >> 2);
  299. request += len & 0xfc;
  300. reqlen -= len & 0xfc;
  301. } else {
  302. while (len--) {
  303. outb(*request++, base + PIO_FIFO);
  304. reqlen--;
  305. }
  306. }
  307. }
  308. }
  309. return 0;
  310. }
  311. static irqreturn_t
  312. SYM53C500_intr(int irq, void *dev_id)
  313. {
  314. unsigned long flags;
  315. struct Scsi_Host *dev = dev_id;
  316. DEB(unsigned char fifo_size;)
  317. DEB(unsigned char seq_reg;)
  318. unsigned char status, int_reg;
  319. unsigned char pio_status;
  320. int port_base = dev->io_port;
  321. struct sym53c500_data *data =
  322. (struct sym53c500_data *)dev->hostdata;
  323. struct scsi_cmnd *curSC = data->current_SC;
  324. int fast_pio = data->fast_pio;
  325. spin_lock_irqsave(dev->host_lock, flags);
  326. VDEB(printk("SYM53C500_intr called\n"));
  327. REG1(port_base);
  328. pio_status = inb(port_base + PIO_STATUS);
  329. REG0(port_base);
  330. status = inb(port_base + STAT_REG);
  331. DEB(seq_reg = inb(port_base + SEQ_REG));
  332. int_reg = inb(port_base + INT_REG);
  333. DEB(fifo_size = inb(port_base + FIFO_FLAGS) & 0x1f);
  334. #if SYM53C500_DEBUG
  335. printk("status=%02x, seq_reg=%02x, int_reg=%02x, fifo_size=%02x",
  336. status, seq_reg, int_reg, fifo_size);
  337. printk(", pio=%02x\n", pio_status);
  338. #endif /* SYM53C500_DEBUG */
  339. if (int_reg & 0x80) { /* SCSI reset intr */
  340. DEB(printk("SYM53C500: reset intr received\n"));
  341. curSC->result = DID_RESET << 16;
  342. goto idle_out;
  343. }
  344. if (pio_status & 0x80) {
  345. printk("SYM53C500: Warning: PIO error!\n");
  346. curSC->result = DID_ERROR << 16;
  347. goto idle_out;
  348. }
  349. if (status & 0x20) { /* Parity error */
  350. printk("SYM53C500: Warning: parity error!\n");
  351. curSC->result = DID_PARITY << 16;
  352. goto idle_out;
  353. }
  354. if (status & 0x40) { /* Gross error */
  355. printk("SYM53C500: Warning: gross error!\n");
  356. curSC->result = DID_ERROR << 16;
  357. goto idle_out;
  358. }
  359. if (int_reg & 0x20) { /* Disconnect */
  360. DEB(printk("SYM53C500: disconnect intr received\n"));
  361. if (curSC->SCp.phase != message_in) { /* Unexpected disconnect */
  362. curSC->result = DID_NO_CONNECT << 16;
  363. } else { /* Command complete, return status and message */
  364. curSC->result = (curSC->SCp.Status & 0xff)
  365. | ((curSC->SCp.Message & 0xff) << 8) | (DID_OK << 16);
  366. }
  367. goto idle_out;
  368. }
  369. switch (status & 0x07) { /* scsi phase */
  370. case 0x00: /* DATA-OUT */
  371. if (int_reg & 0x10) { /* Target requesting info transfer */
  372. struct scatterlist *sg;
  373. int i;
  374. curSC->SCp.phase = data_out;
  375. VDEB(printk("SYM53C500: Data-Out phase\n"));
  376. outb(FLUSH_FIFO, port_base + CMD_REG);
  377. LOAD_DMA_COUNT(port_base, scsi_bufflen(curSC)); /* Max transfer size */
  378. outb(TRANSFER_INFO | DMA_OP, port_base + CMD_REG);
  379. scsi_for_each_sg(curSC, sg, scsi_sg_count(curSC), i) {
  380. SYM53C500_pio_write(fast_pio, port_base,
  381. sg_virt(sg), sg->length);
  382. }
  383. REG0(port_base);
  384. }
  385. break;
  386. case 0x01: /* DATA-IN */
  387. if (int_reg & 0x10) { /* Target requesting info transfer */
  388. struct scatterlist *sg;
  389. int i;
  390. curSC->SCp.phase = data_in;
  391. VDEB(printk("SYM53C500: Data-In phase\n"));
  392. outb(FLUSH_FIFO, port_base + CMD_REG);
  393. LOAD_DMA_COUNT(port_base, scsi_bufflen(curSC)); /* Max transfer size */
  394. outb(TRANSFER_INFO | DMA_OP, port_base + CMD_REG);
  395. scsi_for_each_sg(curSC, sg, scsi_sg_count(curSC), i) {
  396. SYM53C500_pio_read(fast_pio, port_base,
  397. sg_virt(sg), sg->length);
  398. }
  399. REG0(port_base);
  400. }
  401. break;
  402. case 0x02: /* COMMAND */
  403. curSC->SCp.phase = command_ph;
  404. printk("SYM53C500: Warning: Unknown interrupt occurred in command phase!\n");
  405. break;
  406. case 0x03: /* STATUS */
  407. curSC->SCp.phase = status_ph;
  408. VDEB(printk("SYM53C500: Status phase\n"));
  409. outb(FLUSH_FIFO, port_base + CMD_REG);
  410. outb(INIT_CMD_COMPLETE, port_base + CMD_REG);
  411. break;
  412. case 0x04: /* Reserved */
  413. case 0x05: /* Reserved */
  414. printk("SYM53C500: WARNING: Reserved phase!!!\n");
  415. break;
  416. case 0x06: /* MESSAGE-OUT */
  417. DEB(printk("SYM53C500: Message-Out phase\n"));
  418. curSC->SCp.phase = message_out;
  419. outb(SET_ATN, port_base + CMD_REG); /* Reject the message */
  420. outb(MSG_ACCEPT, port_base + CMD_REG);
  421. break;
  422. case 0x07: /* MESSAGE-IN */
  423. VDEB(printk("SYM53C500: Message-In phase\n"));
  424. curSC->SCp.phase = message_in;
  425. curSC->SCp.Status = inb(port_base + SCSI_FIFO);
  426. curSC->SCp.Message = inb(port_base + SCSI_FIFO);
  427. VDEB(printk("SCSI FIFO size=%d\n", inb(port_base + FIFO_FLAGS) & 0x1f));
  428. DEB(printk("Status = %02x Message = %02x\n", curSC->SCp.Status, curSC->SCp.Message));
  429. if (curSC->SCp.Message == SAVE_POINTERS || curSC->SCp.Message == DISCONNECT) {
  430. outb(SET_ATN, port_base + CMD_REG); /* Reject message */
  431. DEB(printk("Discarding SAVE_POINTERS message\n"));
  432. }
  433. outb(MSG_ACCEPT, port_base + CMD_REG);
  434. break;
  435. }
  436. out:
  437. spin_unlock_irqrestore(dev->host_lock, flags);
  438. return IRQ_HANDLED;
  439. idle_out:
  440. curSC->SCp.phase = idle;
  441. curSC->scsi_done(curSC);
  442. goto out;
  443. }
  444. static void
  445. SYM53C500_release(struct pcmcia_device *link)
  446. {
  447. struct scsi_info_t *info = link->priv;
  448. struct Scsi_Host *shost = info->host;
  449. dev_dbg(&link->dev, "SYM53C500_release\n");
  450. /*
  451. * Do this before releasing/freeing resources.
  452. */
  453. scsi_remove_host(shost);
  454. /*
  455. * Interrupts getting hosed on card removal. Try
  456. * the following code, mostly from qlogicfas.c.
  457. */
  458. if (shost->irq)
  459. free_irq(shost->irq, shost);
  460. if (shost->io_port && shost->n_io_port)
  461. release_region(shost->io_port, shost->n_io_port);
  462. pcmcia_disable_device(link);
  463. scsi_host_put(shost);
  464. } /* SYM53C500_release */
  465. static const char*
  466. SYM53C500_info(struct Scsi_Host *SChost)
  467. {
  468. static char info_msg[256];
  469. struct sym53c500_data *data =
  470. (struct sym53c500_data *)SChost->hostdata;
  471. DEB(printk("SYM53C500_info called\n"));
  472. (void)snprintf(info_msg, sizeof(info_msg),
  473. "SYM53C500 at 0x%lx, IRQ %d, %s PIO mode.",
  474. SChost->io_port, SChost->irq, data->fast_pio ? "fast" : "slow");
  475. return (info_msg);
  476. }
  477. static int
  478. SYM53C500_queue(struct scsi_cmnd *SCpnt, void (*done)(struct scsi_cmnd *))
  479. {
  480. int i;
  481. int port_base = SCpnt->device->host->io_port;
  482. struct sym53c500_data *data =
  483. (struct sym53c500_data *)SCpnt->device->host->hostdata;
  484. VDEB(printk("SYM53C500_queue called\n"));
  485. DEB(printk("cmd=%02x, cmd_len=%02x, target=%02x, lun=%02x, bufflen=%d\n",
  486. SCpnt->cmnd[0], SCpnt->cmd_len, SCpnt->device->id,
  487. SCpnt->device->lun, scsi_bufflen(SCpnt)));
  488. VDEB(for (i = 0; i < SCpnt->cmd_len; i++)
  489. printk("cmd[%d]=%02x ", i, SCpnt->cmnd[i]));
  490. VDEB(printk("\n"));
  491. data->current_SC = SCpnt;
  492. data->current_SC->scsi_done = done;
  493. data->current_SC->SCp.phase = command_ph;
  494. data->current_SC->SCp.Status = 0;
  495. data->current_SC->SCp.Message = 0;
  496. /* We are locked here already by the mid layer */
  497. REG0(port_base);
  498. outb(scmd_id(SCpnt), port_base + DEST_ID); /* set destination */
  499. outb(FLUSH_FIFO, port_base + CMD_REG); /* reset the fifos */
  500. for (i = 0; i < SCpnt->cmd_len; i++) {
  501. outb(SCpnt->cmnd[i], port_base + SCSI_FIFO);
  502. }
  503. outb(SELECT_NO_ATN, port_base + CMD_REG);
  504. return 0;
  505. }
  506. static int
  507. SYM53C500_host_reset(struct scsi_cmnd *SCpnt)
  508. {
  509. int port_base = SCpnt->device->host->io_port;
  510. DEB(printk("SYM53C500_host_reset called\n"));
  511. spin_lock_irq(SCpnt->device->host->host_lock);
  512. SYM53C500_int_host_reset(port_base);
  513. spin_unlock_irq(SCpnt->device->host->host_lock);
  514. return SUCCESS;
  515. }
  516. static int
  517. SYM53C500_biosparm(struct scsi_device *disk,
  518. struct block_device *dev,
  519. sector_t capacity, int *info_array)
  520. {
  521. int size;
  522. DEB(printk("SYM53C500_biosparm called\n"));
  523. size = capacity;
  524. info_array[0] = 64; /* heads */
  525. info_array[1] = 32; /* sectors */
  526. info_array[2] = size >> 11; /* cylinders */
  527. if (info_array[2] > 1024) { /* big disk */
  528. info_array[0] = 255;
  529. info_array[1] = 63;
  530. info_array[2] = size / (255 * 63);
  531. }
  532. return 0;
  533. }
  534. static ssize_t
  535. SYM53C500_show_pio(struct device *dev, struct device_attribute *attr,
  536. char *buf)
  537. {
  538. struct Scsi_Host *SHp = class_to_shost(dev);
  539. struct sym53c500_data *data =
  540. (struct sym53c500_data *)SHp->hostdata;
  541. return snprintf(buf, 4, "%d\n", data->fast_pio);
  542. }
  543. static ssize_t
  544. SYM53C500_store_pio(struct device *dev, struct device_attribute *attr,
  545. const char *buf, size_t count)
  546. {
  547. int pio;
  548. struct Scsi_Host *SHp = class_to_shost(dev);
  549. struct sym53c500_data *data =
  550. (struct sym53c500_data *)SHp->hostdata;
  551. pio = simple_strtoul(buf, NULL, 0);
  552. if (pio == 0 || pio == 1) {
  553. data->fast_pio = pio;
  554. return count;
  555. }
  556. else
  557. return -EINVAL;
  558. }
  559. /*
  560. * SCSI HBA device attributes we want to
  561. * make available via sysfs.
  562. */
  563. static struct device_attribute SYM53C500_pio_attr = {
  564. .attr = {
  565. .name = "fast_pio",
  566. .mode = (S_IRUGO | S_IWUSR),
  567. },
  568. .show = SYM53C500_show_pio,
  569. .store = SYM53C500_store_pio,
  570. };
  571. static struct device_attribute *SYM53C500_shost_attrs[] = {
  572. &SYM53C500_pio_attr,
  573. NULL,
  574. };
  575. /*
  576. * scsi_host_template initializer
  577. */
  578. static struct scsi_host_template sym53c500_driver_template = {
  579. .module = THIS_MODULE,
  580. .name = "SYM53C500",
  581. .info = SYM53C500_info,
  582. .queuecommand = SYM53C500_queue,
  583. .eh_host_reset_handler = SYM53C500_host_reset,
  584. .bios_param = SYM53C500_biosparm,
  585. .proc_name = "SYM53C500",
  586. .can_queue = 1,
  587. .this_id = 7,
  588. .sg_tablesize = 32,
  589. .cmd_per_lun = 1,
  590. .use_clustering = ENABLE_CLUSTERING,
  591. .shost_attrs = SYM53C500_shost_attrs
  592. };
  593. static int SYM53C500_config_check(struct pcmcia_device *p_dev,
  594. cistpl_cftable_entry_t *cfg,
  595. cistpl_cftable_entry_t *dflt,
  596. unsigned int vcc,
  597. void *priv_data)
  598. {
  599. p_dev->io.BasePort1 = cfg->io.win[0].base;
  600. p_dev->io.NumPorts1 = cfg->io.win[0].len;
  601. if (p_dev->io.BasePort1 == 0)
  602. return -ENODEV;
  603. return pcmcia_request_io(p_dev, &p_dev->io);
  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->io.BasePort1 + 0xd);
  634. outb(0x24, link->io.BasePort1 + 0x9);
  635. outb(0x04, link->io.BasePort1 + 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->io.BasePort1;
  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->io.BasePort1 + 0xd);
  706. outb(0x24, link->io.BasePort1 + 0x9);
  707. outb(0x04, link->io.BasePort1 + 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->io.BasePort1);
  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->io.NumPorts1 = 16;
  736. link->io.Attributes1 = IO_DATA_PATH_WIDTH_AUTO;
  737. link->io.IOAddrLines = 10;
  738. link->conf.Attributes = CONF_ENABLE_IRQ;
  739. link->conf.IntType = INT_MEMORY_AND_IO;
  740. return SYM53C500_config(link);
  741. } /* SYM53C500_attach */
  742. MODULE_AUTHOR("Bob Tracy <rct@frus.com>");
  743. MODULE_DESCRIPTION("SYM53C500 PCMCIA SCSI driver");
  744. MODULE_LICENSE("GPL");
  745. static struct pcmcia_device_id sym53c500_ids[] = {
  746. PCMCIA_DEVICE_PROD_ID12("BASICS by New Media Corporation", "SCSI Sym53C500", 0x23c78a9d, 0x0099e7f7),
  747. PCMCIA_DEVICE_PROD_ID12("New Media Corporation", "SCSI Bus Toaster Sym53C500", 0x085a850b, 0x45432eb8),
  748. PCMCIA_DEVICE_PROD_ID2("SCSI9000", 0x21648f44),
  749. PCMCIA_DEVICE_NULL,
  750. };
  751. MODULE_DEVICE_TABLE(pcmcia, sym53c500_ids);
  752. static struct pcmcia_driver sym53c500_cs_driver = {
  753. .owner = THIS_MODULE,
  754. .drv = {
  755. .name = "sym53c500_cs",
  756. },
  757. .probe = SYM53C500_probe,
  758. .remove = SYM53C500_detach,
  759. .id_table = sym53c500_ids,
  760. .resume = sym53c500_resume,
  761. };
  762. static int __init
  763. init_sym53c500_cs(void)
  764. {
  765. return pcmcia_register_driver(&sym53c500_cs_driver);
  766. }
  767. static void __exit
  768. exit_sym53c500_cs(void)
  769. {
  770. pcmcia_unregister_driver(&sym53c500_cs_driver);
  771. }
  772. module_init(init_sym53c500_cs);
  773. module_exit(exit_sym53c500_cs);