sym53c500_cs.c 23 KB

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