aha1740.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679
  1. /* $Id$
  2. * 1993/03/31
  3. * linux/kernel/aha1740.c
  4. *
  5. * Based loosely on aha1542.c which is
  6. * Copyright (C) 1992 Tommy Thorn and
  7. * Modified by Eric Youngdale
  8. *
  9. * This file is aha1740.c, written and
  10. * Copyright (C) 1992,1993 Brad McLean
  11. * brad@saturn.gaylord.com or brad@bradpc.gaylord.com.
  12. *
  13. * Modifications to makecode and queuecommand
  14. * for proper handling of multiple devices courteously
  15. * provided by Michael Weller, March, 1993
  16. *
  17. * Multiple adapter support, extended translation detection,
  18. * update to current scsi subsystem changes, proc fs support,
  19. * working (!) module support based on patches from Andreas Arens,
  20. * by Andreas Degert <ad@papyrus.hamburg.com>, 2/1997
  21. *
  22. * aha1740_makecode may still need even more work
  23. * if it doesn't work for your devices, take a look.
  24. *
  25. * Reworked for new_eh and new locking by Alan Cox <alan@lxorguk.ukuu.org.uk>
  26. *
  27. * Converted to EISA and generic DMA APIs by Marc Zyngier
  28. * <maz@wild-wind.fr.eu.org>, 4/2003.
  29. *
  30. * Shared interrupt support added by Rask Ingemann Lambertsen
  31. * <rask@sygehus.dk>, 10/2003
  32. *
  33. * For the avoidance of doubt the "preferred form" of this code is one which
  34. * is in an open non patent encumbered format. Where cryptographic key signing
  35. * forms part of the process of creating an executable the information
  36. * including keys needed to generate an equivalently functional executable
  37. * are deemed to be part of the source code.
  38. */
  39. #include <linux/blkdev.h>
  40. #include <linux/interrupt.h>
  41. #include <linux/module.h>
  42. #include <linux/kernel.h>
  43. #include <linux/types.h>
  44. #include <linux/string.h>
  45. #include <linux/ioport.h>
  46. #include <linux/proc_fs.h>
  47. #include <linux/stat.h>
  48. #include <linux/init.h>
  49. #include <linux/device.h>
  50. #include <linux/eisa.h>
  51. #include <linux/dma-mapping.h>
  52. #include <linux/gfp.h>
  53. #include <asm/dma.h>
  54. #include <asm/io.h>
  55. #include "scsi.h"
  56. #include <scsi/scsi_host.h>
  57. #include "aha1740.h"
  58. /* IF YOU ARE HAVING PROBLEMS WITH THIS DRIVER, AND WANT TO WATCH
  59. IT WORK, THEN:
  60. #define DEBUG
  61. */
  62. #ifdef DEBUG
  63. #define DEB(x) x
  64. #else
  65. #define DEB(x)
  66. #endif
  67. struct aha1740_hostdata {
  68. struct eisa_device *edev;
  69. unsigned int translation;
  70. unsigned int last_ecb_used;
  71. dma_addr_t ecb_dma_addr;
  72. struct ecb ecb[AHA1740_ECBS];
  73. };
  74. struct aha1740_sg {
  75. struct aha1740_chain sg_chain[AHA1740_SCATTER];
  76. dma_addr_t sg_dma_addr;
  77. dma_addr_t buf_dma_addr;
  78. };
  79. #define HOSTDATA(host) ((struct aha1740_hostdata *) &host->hostdata)
  80. static inline struct ecb *ecb_dma_to_cpu (struct Scsi_Host *host,
  81. dma_addr_t dma)
  82. {
  83. struct aha1740_hostdata *hdata = HOSTDATA (host);
  84. dma_addr_t offset;
  85. offset = dma - hdata->ecb_dma_addr;
  86. return (struct ecb *)(((char *) hdata->ecb) + (unsigned int) offset);
  87. }
  88. static inline dma_addr_t ecb_cpu_to_dma (struct Scsi_Host *host, void *cpu)
  89. {
  90. struct aha1740_hostdata *hdata = HOSTDATA (host);
  91. dma_addr_t offset;
  92. offset = (char *) cpu - (char *) hdata->ecb;
  93. return hdata->ecb_dma_addr + offset;
  94. }
  95. static int aha1740_show_info(struct seq_file *m, struct Scsi_Host *shpnt)
  96. {
  97. struct aha1740_hostdata *host = HOSTDATA(shpnt);
  98. seq_printf(m, "aha174x at IO:%lx, IRQ %d, SLOT %d.\n"
  99. "Extended translation %sabled.\n",
  100. shpnt->io_port, shpnt->irq, host->edev->slot,
  101. host->translation ? "en" : "dis");
  102. return 0;
  103. }
  104. static int aha1740_makecode(unchar *sense, unchar *status)
  105. {
  106. struct statusword
  107. {
  108. ushort don:1, /* Command Done - No Error */
  109. du:1, /* Data underrun */
  110. :1, qf:1, /* Queue full */
  111. sc:1, /* Specification Check */
  112. dor:1, /* Data overrun */
  113. ch:1, /* Chaining Halted */
  114. intr:1, /* Interrupt issued */
  115. asa:1, /* Additional Status Available */
  116. sns:1, /* Sense information Stored */
  117. :1, ini:1, /* Initialization Required */
  118. me:1, /* Major error or exception */
  119. :1, eca:1, /* Extended Contingent alliance */
  120. :1;
  121. } status_word;
  122. int retval = DID_OK;
  123. status_word = * (struct statusword *) status;
  124. #ifdef DEBUG
  125. printk("makecode from %x,%x,%x,%x %x,%x,%x,%x",
  126. status[0], status[1], status[2], status[3],
  127. sense[0], sense[1], sense[2], sense[3]);
  128. #endif
  129. if (!status_word.don) { /* Anything abnormal was detected */
  130. if ( (status[1]&0x18) || status_word.sc ) {
  131. /*Additional info available*/
  132. /* Use the supplied info for further diagnostics */
  133. switch ( status[2] ) {
  134. case 0x12:
  135. if ( status_word.dor )
  136. retval=DID_ERROR; /* It's an Overrun */
  137. /* If not overrun, assume underrun and
  138. * ignore it! */
  139. case 0x00: /* No info, assume no error, should
  140. * not occur */
  141. break;
  142. case 0x11:
  143. case 0x21:
  144. retval=DID_TIME_OUT;
  145. break;
  146. case 0x0a:
  147. retval=DID_BAD_TARGET;
  148. break;
  149. case 0x04:
  150. case 0x05:
  151. retval=DID_ABORT;
  152. /* Either by this driver or the
  153. * AHA1740 itself */
  154. break;
  155. default:
  156. retval=DID_ERROR; /* No further
  157. * diagnostics
  158. * possible */
  159. }
  160. } else {
  161. /* Michael suggests, and Brad concurs: */
  162. if ( status_word.qf ) {
  163. retval = DID_TIME_OUT; /* forces a redo */
  164. /* I think this specific one should
  165. * not happen -Brad */
  166. printk("aha1740.c: WARNING: AHA1740 queue overflow!\n");
  167. } else
  168. if ( status[0]&0x60 ) {
  169. /* Didn't find a better error */
  170. retval = DID_ERROR;
  171. }
  172. /* In any other case return DID_OK so for example
  173. CONDITION_CHECKS make it through to the appropriate
  174. device driver */
  175. }
  176. }
  177. /* Under all circumstances supply the target status -Michael */
  178. return status[3] | retval << 16;
  179. }
  180. static int aha1740_test_port(unsigned int base)
  181. {
  182. if ( inb(PORTADR(base)) & PORTADDR_ENH )
  183. return 1; /* Okay, we're all set */
  184. printk("aha174x: Board detected, but not in enhanced mode, so disabled it.\n");
  185. return 0;
  186. }
  187. /* A "high" level interrupt handler */
  188. static irqreturn_t aha1740_intr_handle(int irq, void *dev_id)
  189. {
  190. struct Scsi_Host *host = (struct Scsi_Host *) dev_id;
  191. void (*my_done)(struct scsi_cmnd *);
  192. int errstatus, adapstat;
  193. int number_serviced;
  194. struct ecb *ecbptr;
  195. struct scsi_cmnd *SCtmp;
  196. unsigned int base;
  197. unsigned long flags;
  198. int handled = 0;
  199. struct aha1740_sg *sgptr;
  200. struct eisa_device *edev;
  201. if (!host)
  202. panic("aha1740.c: Irq from unknown host!\n");
  203. spin_lock_irqsave(host->host_lock, flags);
  204. base = host->io_port;
  205. number_serviced = 0;
  206. edev = HOSTDATA(host)->edev;
  207. while(inb(G2STAT(base)) & G2STAT_INTPEND) {
  208. handled = 1;
  209. DEB(printk("aha1740_intr top of loop.\n"));
  210. adapstat = inb(G2INTST(base));
  211. ecbptr = ecb_dma_to_cpu (host, inl(MBOXIN0(base)));
  212. outb(G2CNTRL_IRST,G2CNTRL(base)); /* interrupt reset */
  213. switch ( adapstat & G2INTST_MASK ) {
  214. case G2INTST_CCBRETRY:
  215. case G2INTST_CCBERROR:
  216. case G2INTST_CCBGOOD:
  217. /* Host Ready -> Mailbox in complete */
  218. outb(G2CNTRL_HRDY,G2CNTRL(base));
  219. if (!ecbptr) {
  220. printk("Aha1740 null ecbptr in interrupt (%x,%x,%x,%d)\n",
  221. inb(G2STAT(base)),adapstat,
  222. inb(G2INTST(base)), number_serviced++);
  223. continue;
  224. }
  225. SCtmp = ecbptr->SCpnt;
  226. if (!SCtmp) {
  227. printk("Aha1740 null SCtmp in interrupt (%x,%x,%x,%d)\n",
  228. inb(G2STAT(base)),adapstat,
  229. inb(G2INTST(base)), number_serviced++);
  230. continue;
  231. }
  232. sgptr = (struct aha1740_sg *) SCtmp->host_scribble;
  233. scsi_dma_unmap(SCtmp);
  234. /* Free the sg block */
  235. dma_free_coherent (&edev->dev,
  236. sizeof (struct aha1740_sg),
  237. SCtmp->host_scribble,
  238. sgptr->sg_dma_addr);
  239. /* Fetch the sense data, and tuck it away, in
  240. the required slot. The Adaptec
  241. automatically fetches it, and there is no
  242. guarantee that we will still have it in the
  243. cdb when we come back */
  244. if ( (adapstat & G2INTST_MASK) == G2INTST_CCBERROR ) {
  245. memcpy(SCtmp->sense_buffer, ecbptr->sense,
  246. SCSI_SENSE_BUFFERSIZE);
  247. errstatus = aha1740_makecode(ecbptr->sense,ecbptr->status);
  248. } else
  249. errstatus = 0;
  250. DEB(if (errstatus)
  251. printk("aha1740_intr_handle: returning %6x\n",
  252. errstatus));
  253. SCtmp->result = errstatus;
  254. my_done = ecbptr->done;
  255. memset(ecbptr,0,sizeof(struct ecb));
  256. if ( my_done )
  257. my_done(SCtmp);
  258. break;
  259. case G2INTST_HARDFAIL:
  260. printk(KERN_ALERT "aha1740 hardware failure!\n");
  261. panic("aha1740.c"); /* Goodbye */
  262. case G2INTST_ASNEVENT:
  263. printk("aha1740 asynchronous event: %02x %02x %02x %02x %02x\n",
  264. adapstat,
  265. inb(MBOXIN0(base)),
  266. inb(MBOXIN1(base)),
  267. inb(MBOXIN2(base)),
  268. inb(MBOXIN3(base))); /* Say What? */
  269. /* Host Ready -> Mailbox in complete */
  270. outb(G2CNTRL_HRDY,G2CNTRL(base));
  271. break;
  272. case G2INTST_CMDGOOD:
  273. /* set immediate command success flag here: */
  274. break;
  275. case G2INTST_CMDERROR:
  276. /* Set immediate command failure flag here: */
  277. break;
  278. }
  279. number_serviced++;
  280. }
  281. spin_unlock_irqrestore(host->host_lock, flags);
  282. return IRQ_RETVAL(handled);
  283. }
  284. static int aha1740_queuecommand_lck(struct scsi_cmnd * SCpnt,
  285. void (*done)(struct scsi_cmnd *))
  286. {
  287. unchar direction;
  288. unchar *cmd = (unchar *) SCpnt->cmnd;
  289. unchar target = scmd_id(SCpnt);
  290. struct aha1740_hostdata *host = HOSTDATA(SCpnt->device->host);
  291. unsigned long flags;
  292. dma_addr_t sg_dma;
  293. struct aha1740_sg *sgptr;
  294. int ecbno, nseg;
  295. DEB(int i);
  296. if(*cmd == REQUEST_SENSE) {
  297. SCpnt->result = 0;
  298. done(SCpnt);
  299. return 0;
  300. }
  301. #ifdef DEBUG
  302. if (*cmd == READ_10 || *cmd == WRITE_10)
  303. i = xscsi2int(cmd+2);
  304. else if (*cmd == READ_6 || *cmd == WRITE_6)
  305. i = scsi2int(cmd+2);
  306. else
  307. i = -1;
  308. printk("aha1740_queuecommand: dev %d cmd %02x pos %d len %d ",
  309. target, *cmd, i, bufflen);
  310. printk("scsi cmd:");
  311. for (i = 0; i < SCpnt->cmd_len; i++) printk("%02x ", cmd[i]);
  312. printk("\n");
  313. #endif
  314. /* locate an available ecb */
  315. spin_lock_irqsave(SCpnt->device->host->host_lock, flags);
  316. ecbno = host->last_ecb_used + 1; /* An optimization */
  317. if (ecbno >= AHA1740_ECBS)
  318. ecbno = 0;
  319. do {
  320. if (!host->ecb[ecbno].cmdw)
  321. break;
  322. ecbno++;
  323. if (ecbno >= AHA1740_ECBS)
  324. ecbno = 0;
  325. } while (ecbno != host->last_ecb_used);
  326. if (host->ecb[ecbno].cmdw)
  327. panic("Unable to find empty ecb for aha1740.\n");
  328. host->ecb[ecbno].cmdw = AHA1740CMD_INIT; /* SCSI Initiator Command
  329. doubles as reserved flag */
  330. host->last_ecb_used = ecbno;
  331. spin_unlock_irqrestore(SCpnt->device->host->host_lock, flags);
  332. #ifdef DEBUG
  333. printk("Sending command (%d %x)...", ecbno, done);
  334. #endif
  335. host->ecb[ecbno].cdblen = SCpnt->cmd_len; /* SCSI Command
  336. * Descriptor Block
  337. * Length */
  338. direction = 0;
  339. if (*cmd == READ_10 || *cmd == READ_6)
  340. direction = 1;
  341. else if (*cmd == WRITE_10 || *cmd == WRITE_6)
  342. direction = 0;
  343. memcpy(host->ecb[ecbno].cdb, cmd, SCpnt->cmd_len);
  344. SCpnt->host_scribble = dma_alloc_coherent (&host->edev->dev,
  345. sizeof (struct aha1740_sg),
  346. &sg_dma, GFP_ATOMIC);
  347. if(SCpnt->host_scribble == NULL) {
  348. printk(KERN_WARNING "aha1740: out of memory in queuecommand!\n");
  349. return 1;
  350. }
  351. sgptr = (struct aha1740_sg *) SCpnt->host_scribble;
  352. sgptr->sg_dma_addr = sg_dma;
  353. nseg = scsi_dma_map(SCpnt);
  354. BUG_ON(nseg < 0);
  355. if (nseg) {
  356. struct scatterlist *sg;
  357. struct aha1740_chain * cptr;
  358. int i;
  359. DEB(unsigned char * ptr);
  360. host->ecb[ecbno].sg = 1; /* SCSI Initiator Command
  361. * w/scatter-gather*/
  362. cptr = sgptr->sg_chain;
  363. scsi_for_each_sg(SCpnt, sg, nseg, i) {
  364. cptr[i].datalen = sg_dma_len (sg);
  365. cptr[i].dataptr = sg_dma_address (sg);
  366. }
  367. host->ecb[ecbno].datalen = nseg * sizeof(struct aha1740_chain);
  368. host->ecb[ecbno].dataptr = sg_dma;
  369. #ifdef DEBUG
  370. printk("cptr %x: ",cptr);
  371. ptr = (unsigned char *) cptr;
  372. for(i=0;i<24;i++) printk("%02x ", ptr[i]);
  373. #endif
  374. } else {
  375. host->ecb[ecbno].datalen = 0;
  376. host->ecb[ecbno].dataptr = 0;
  377. }
  378. host->ecb[ecbno].lun = SCpnt->device->lun;
  379. host->ecb[ecbno].ses = 1; /* Suppress underrun errors */
  380. host->ecb[ecbno].dir = direction;
  381. host->ecb[ecbno].ars = 1; /* Yes, get the sense on an error */
  382. host->ecb[ecbno].senselen = 12;
  383. host->ecb[ecbno].senseptr = ecb_cpu_to_dma (SCpnt->device->host,
  384. host->ecb[ecbno].sense);
  385. host->ecb[ecbno].statusptr = ecb_cpu_to_dma (SCpnt->device->host,
  386. host->ecb[ecbno].status);
  387. host->ecb[ecbno].done = done;
  388. host->ecb[ecbno].SCpnt = SCpnt;
  389. #ifdef DEBUG
  390. {
  391. int i;
  392. printk("aha1740_command: sending.. ");
  393. for (i = 0; i < sizeof(host->ecb[ecbno]) - 10; i++)
  394. printk("%02x ", ((unchar *)&host->ecb[ecbno])[i]);
  395. }
  396. printk("\n");
  397. #endif
  398. if (done) {
  399. /* The Adaptec Spec says the card is so fast that the loops
  400. will only be executed once in the code below. Even if this
  401. was true with the fastest processors when the spec was
  402. written, it doesn't seem to be true with today's fast
  403. processors. We print a warning if the code is executed more
  404. often than LOOPCNT_WARN. If this happens, it should be
  405. investigated. If the count reaches LOOPCNT_MAX, we assume
  406. something is broken; since there is no way to return an
  407. error (the return value is ignored by the mid-level scsi
  408. layer) we have to panic (and maybe that's the best thing we
  409. can do then anyhow). */
  410. #define LOOPCNT_WARN 10 /* excessive mbxout wait -> syslog-msg */
  411. #define LOOPCNT_MAX 1000000 /* mbxout deadlock -> panic() after ~ 2 sec. */
  412. int loopcnt;
  413. unsigned int base = SCpnt->device->host->io_port;
  414. DEB(printk("aha1740[%d] critical section\n",ecbno));
  415. spin_lock_irqsave(SCpnt->device->host->host_lock, flags);
  416. for (loopcnt = 0; ; loopcnt++) {
  417. if (inb(G2STAT(base)) & G2STAT_MBXOUT) break;
  418. if (loopcnt == LOOPCNT_WARN) {
  419. printk("aha1740[%d]_mbxout wait!\n",ecbno);
  420. }
  421. if (loopcnt == LOOPCNT_MAX)
  422. panic("aha1740.c: mbxout busy!\n");
  423. }
  424. outl (ecb_cpu_to_dma (SCpnt->device->host, host->ecb + ecbno),
  425. MBOXOUT0(base));
  426. for (loopcnt = 0; ; loopcnt++) {
  427. if (! (inb(G2STAT(base)) & G2STAT_BUSY)) break;
  428. if (loopcnt == LOOPCNT_WARN) {
  429. printk("aha1740[%d]_attn wait!\n",ecbno);
  430. }
  431. if (loopcnt == LOOPCNT_MAX)
  432. panic("aha1740.c: attn wait failed!\n");
  433. }
  434. outb(ATTN_START | (target & 7), ATTN(base)); /* Start it up */
  435. spin_unlock_irqrestore(SCpnt->device->host->host_lock, flags);
  436. DEB(printk("aha1740[%d] request queued.\n",ecbno));
  437. } else
  438. printk(KERN_ALERT "aha1740_queuecommand: done can't be NULL\n");
  439. return 0;
  440. }
  441. static DEF_SCSI_QCMD(aha1740_queuecommand)
  442. /* Query the board for its irq_level and irq_type. Nothing else matters
  443. in enhanced mode on an EISA bus. */
  444. static void aha1740_getconfig(unsigned int base, unsigned int *irq_level,
  445. unsigned int *irq_type,
  446. unsigned int *translation)
  447. {
  448. static int intab[] = { 9, 10, 11, 12, 0, 14, 15, 0 };
  449. *irq_level = intab[inb(INTDEF(base)) & 0x7];
  450. *irq_type = (inb(INTDEF(base)) & 0x8) >> 3;
  451. *translation = inb(RESV1(base)) & 0x1;
  452. outb(inb(INTDEF(base)) | 0x10, INTDEF(base));
  453. }
  454. static int aha1740_biosparam(struct scsi_device *sdev,
  455. struct block_device *dev,
  456. sector_t capacity, int* ip)
  457. {
  458. int size = capacity;
  459. int extended = HOSTDATA(sdev->host)->translation;
  460. DEB(printk("aha1740_biosparam\n"));
  461. if (extended && (ip[2] > 1024)) {
  462. ip[0] = 255;
  463. ip[1] = 63;
  464. ip[2] = size / (255 * 63);
  465. } else {
  466. ip[0] = 64;
  467. ip[1] = 32;
  468. ip[2] = size >> 11;
  469. }
  470. return 0;
  471. }
  472. static int aha1740_eh_abort_handler (struct scsi_cmnd *dummy)
  473. {
  474. /*
  475. * From Alan Cox :
  476. * The AHA1740 has firmware handled abort/reset handling. The "head in
  477. * sand" kernel code is correct for once 8)
  478. *
  479. * So we define a dummy handler just to keep the kernel SCSI code as
  480. * quiet as possible...
  481. */
  482. return SUCCESS;
  483. }
  484. static struct scsi_host_template aha1740_template = {
  485. .module = THIS_MODULE,
  486. .proc_name = "aha1740",
  487. .show_info = aha1740_show_info,
  488. .name = "Adaptec 174x (EISA)",
  489. .queuecommand = aha1740_queuecommand,
  490. .bios_param = aha1740_biosparam,
  491. .can_queue = AHA1740_ECBS,
  492. .this_id = 7,
  493. .sg_tablesize = AHA1740_SCATTER,
  494. .use_clustering = ENABLE_CLUSTERING,
  495. .eh_abort_handler = aha1740_eh_abort_handler,
  496. };
  497. static int aha1740_probe (struct device *dev)
  498. {
  499. int slotbase, rc;
  500. unsigned int irq_level, irq_type, translation;
  501. struct Scsi_Host *shpnt;
  502. struct aha1740_hostdata *host;
  503. struct eisa_device *edev = to_eisa_device (dev);
  504. DEB(printk("aha1740_probe: \n"));
  505. slotbase = edev->base_addr + EISA_VENDOR_ID_OFFSET;
  506. if (!request_region(slotbase, SLOTSIZE, "aha1740")) /* See if in use */
  507. return -EBUSY;
  508. if (!aha1740_test_port(slotbase))
  509. goto err_release_region;
  510. aha1740_getconfig(slotbase,&irq_level,&irq_type,&translation);
  511. if ((inb(G2STAT(slotbase)) &
  512. (G2STAT_MBXOUT|G2STAT_BUSY)) != G2STAT_MBXOUT) {
  513. /* If the card isn't ready, hard reset it */
  514. outb(G2CNTRL_HRST, G2CNTRL(slotbase));
  515. outb(0, G2CNTRL(slotbase));
  516. }
  517. printk(KERN_INFO "Configuring slot %d at IO:%x, IRQ %u (%s)\n",
  518. edev->slot, slotbase, irq_level, irq_type ? "edge" : "level");
  519. printk(KERN_INFO "aha174x: Extended translation %sabled.\n",
  520. translation ? "en" : "dis");
  521. shpnt = scsi_host_alloc(&aha1740_template,
  522. sizeof(struct aha1740_hostdata));
  523. if(shpnt == NULL)
  524. goto err_release_region;
  525. shpnt->base = 0;
  526. shpnt->io_port = slotbase;
  527. shpnt->n_io_port = SLOTSIZE;
  528. shpnt->irq = irq_level;
  529. shpnt->dma_channel = 0xff;
  530. host = HOSTDATA(shpnt);
  531. host->edev = edev;
  532. host->translation = translation;
  533. host->ecb_dma_addr = dma_map_single (&edev->dev, host->ecb,
  534. sizeof (host->ecb),
  535. DMA_BIDIRECTIONAL);
  536. if (!host->ecb_dma_addr) {
  537. printk (KERN_ERR "aha1740_probe: Couldn't map ECB, giving up\n");
  538. scsi_host_put (shpnt);
  539. goto err_host_put;
  540. }
  541. DEB(printk("aha1740_probe: enable interrupt channel %d\n",irq_level));
  542. if (request_irq(irq_level,aha1740_intr_handle,irq_type ? 0 : IRQF_SHARED,
  543. "aha1740",shpnt)) {
  544. printk(KERN_ERR "aha1740_probe: Unable to allocate IRQ %d.\n",
  545. irq_level);
  546. goto err_unmap;
  547. }
  548. eisa_set_drvdata (edev, shpnt);
  549. rc = scsi_add_host (shpnt, dev);
  550. if (rc)
  551. goto err_irq;
  552. scsi_scan_host (shpnt);
  553. return 0;
  554. err_irq:
  555. free_irq(irq_level, shpnt);
  556. err_unmap:
  557. dma_unmap_single (&edev->dev, host->ecb_dma_addr,
  558. sizeof (host->ecb), DMA_BIDIRECTIONAL);
  559. err_host_put:
  560. scsi_host_put (shpnt);
  561. err_release_region:
  562. release_region(slotbase, SLOTSIZE);
  563. return -ENODEV;
  564. }
  565. static int aha1740_remove (struct device *dev)
  566. {
  567. struct Scsi_Host *shpnt = dev_get_drvdata(dev);
  568. struct aha1740_hostdata *host = HOSTDATA (shpnt);
  569. scsi_remove_host(shpnt);
  570. free_irq (shpnt->irq, shpnt);
  571. dma_unmap_single (dev, host->ecb_dma_addr,
  572. sizeof (host->ecb), DMA_BIDIRECTIONAL);
  573. release_region (shpnt->io_port, SLOTSIZE);
  574. scsi_host_put (shpnt);
  575. return 0;
  576. }
  577. static struct eisa_device_id aha1740_ids[] = {
  578. { "ADP0000" }, /* 1740 */
  579. { "ADP0001" }, /* 1740A */
  580. { "ADP0002" }, /* 1742A */
  581. { "ADP0400" }, /* 1744 */
  582. { "" }
  583. };
  584. MODULE_DEVICE_TABLE(eisa, aha1740_ids);
  585. static struct eisa_driver aha1740_driver = {
  586. .id_table = aha1740_ids,
  587. .driver = {
  588. .name = "aha1740",
  589. .probe = aha1740_probe,
  590. .remove = aha1740_remove,
  591. },
  592. };
  593. static __init int aha1740_init (void)
  594. {
  595. return eisa_driver_register (&aha1740_driver);
  596. }
  597. static __exit void aha1740_exit (void)
  598. {
  599. eisa_driver_unregister (&aha1740_driver);
  600. }
  601. module_init (aha1740_init);
  602. module_exit (aha1740_exit);
  603. MODULE_LICENSE("GPL");