aha1740.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677
  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)(Scsi_Cmnd *);
  192. int errstatus, adapstat;
  193. int number_serviced;
  194. struct ecb *ecbptr;
  195. 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(Scsi_Cmnd * SCpnt, void (*done)(Scsi_Cmnd *))
  285. {
  286. unchar direction;
  287. unchar *cmd = (unchar *) SCpnt->cmnd;
  288. unchar target = scmd_id(SCpnt);
  289. struct aha1740_hostdata *host = HOSTDATA(SCpnt->device->host);
  290. unsigned long flags;
  291. dma_addr_t sg_dma;
  292. struct aha1740_sg *sgptr;
  293. int ecbno, nseg;
  294. DEB(int i);
  295. if(*cmd == REQUEST_SENSE) {
  296. SCpnt->result = 0;
  297. done(SCpnt);
  298. return 0;
  299. }
  300. #ifdef DEBUG
  301. if (*cmd == READ_10 || *cmd == WRITE_10)
  302. i = xscsi2int(cmd+2);
  303. else if (*cmd == READ_6 || *cmd == WRITE_6)
  304. i = scsi2int(cmd+2);
  305. else
  306. i = -1;
  307. printk("aha1740_queuecommand: dev %d cmd %02x pos %d len %d ",
  308. target, *cmd, i, bufflen);
  309. printk("scsi cmd:");
  310. for (i = 0; i < SCpnt->cmd_len; i++) printk("%02x ", cmd[i]);
  311. printk("\n");
  312. #endif
  313. /* locate an available ecb */
  314. spin_lock_irqsave(SCpnt->device->host->host_lock, flags);
  315. ecbno = host->last_ecb_used + 1; /* An optimization */
  316. if (ecbno >= AHA1740_ECBS)
  317. ecbno = 0;
  318. do {
  319. if (!host->ecb[ecbno].cmdw)
  320. break;
  321. ecbno++;
  322. if (ecbno >= AHA1740_ECBS)
  323. ecbno = 0;
  324. } while (ecbno != host->last_ecb_used);
  325. if (host->ecb[ecbno].cmdw)
  326. panic("Unable to find empty ecb for aha1740.\n");
  327. host->ecb[ecbno].cmdw = AHA1740CMD_INIT; /* SCSI Initiator Command
  328. doubles as reserved flag */
  329. host->last_ecb_used = ecbno;
  330. spin_unlock_irqrestore(SCpnt->device->host->host_lock, flags);
  331. #ifdef DEBUG
  332. printk("Sending command (%d %x)...", ecbno, done);
  333. #endif
  334. host->ecb[ecbno].cdblen = SCpnt->cmd_len; /* SCSI Command
  335. * Descriptor Block
  336. * Length */
  337. direction = 0;
  338. if (*cmd == READ_10 || *cmd == READ_6)
  339. direction = 1;
  340. else if (*cmd == WRITE_10 || *cmd == WRITE_6)
  341. direction = 0;
  342. memcpy(host->ecb[ecbno].cdb, cmd, SCpnt->cmd_len);
  343. SCpnt->host_scribble = dma_alloc_coherent (&host->edev->dev,
  344. sizeof (struct aha1740_sg),
  345. &sg_dma, GFP_ATOMIC);
  346. if(SCpnt->host_scribble == NULL) {
  347. printk(KERN_WARNING "aha1740: out of memory in queuecommand!\n");
  348. return 1;
  349. }
  350. sgptr = (struct aha1740_sg *) SCpnt->host_scribble;
  351. sgptr->sg_dma_addr = sg_dma;
  352. nseg = scsi_dma_map(SCpnt);
  353. BUG_ON(nseg < 0);
  354. if (nseg) {
  355. struct scatterlist *sg;
  356. struct aha1740_chain * cptr;
  357. int i;
  358. DEB(unsigned char * ptr);
  359. host->ecb[ecbno].sg = 1; /* SCSI Initiator Command
  360. * w/scatter-gather*/
  361. cptr = sgptr->sg_chain;
  362. scsi_for_each_sg(SCpnt, sg, nseg, i) {
  363. cptr[i].datalen = sg_dma_len (sg);
  364. cptr[i].dataptr = sg_dma_address (sg);
  365. }
  366. host->ecb[ecbno].datalen = nseg * sizeof(struct aha1740_chain);
  367. host->ecb[ecbno].dataptr = sg_dma;
  368. #ifdef DEBUG
  369. printk("cptr %x: ",cptr);
  370. ptr = (unsigned char *) cptr;
  371. for(i=0;i<24;i++) printk("%02x ", ptr[i]);
  372. #endif
  373. } else {
  374. host->ecb[ecbno].datalen = 0;
  375. host->ecb[ecbno].dataptr = 0;
  376. }
  377. host->ecb[ecbno].lun = SCpnt->device->lun;
  378. host->ecb[ecbno].ses = 1; /* Suppress underrun errors */
  379. host->ecb[ecbno].dir = direction;
  380. host->ecb[ecbno].ars = 1; /* Yes, get the sense on an error */
  381. host->ecb[ecbno].senselen = 12;
  382. host->ecb[ecbno].senseptr = ecb_cpu_to_dma (SCpnt->device->host,
  383. host->ecb[ecbno].sense);
  384. host->ecb[ecbno].statusptr = ecb_cpu_to_dma (SCpnt->device->host,
  385. host->ecb[ecbno].status);
  386. host->ecb[ecbno].done = done;
  387. host->ecb[ecbno].SCpnt = SCpnt;
  388. #ifdef DEBUG
  389. {
  390. int i;
  391. printk("aha1740_command: sending.. ");
  392. for (i = 0; i < sizeof(host->ecb[ecbno]) - 10; i++)
  393. printk("%02x ", ((unchar *)&host->ecb[ecbno])[i]);
  394. }
  395. printk("\n");
  396. #endif
  397. if (done) {
  398. /* The Adaptec Spec says the card is so fast that the loops
  399. will only be executed once in the code below. Even if this
  400. was true with the fastest processors when the spec was
  401. written, it doesn't seem to be true with today's fast
  402. processors. We print a warning if the code is executed more
  403. often than LOOPCNT_WARN. If this happens, it should be
  404. investigated. If the count reaches LOOPCNT_MAX, we assume
  405. something is broken; since there is no way to return an
  406. error (the return value is ignored by the mid-level scsi
  407. layer) we have to panic (and maybe that's the best thing we
  408. can do then anyhow). */
  409. #define LOOPCNT_WARN 10 /* excessive mbxout wait -> syslog-msg */
  410. #define LOOPCNT_MAX 1000000 /* mbxout deadlock -> panic() after ~ 2 sec. */
  411. int loopcnt;
  412. unsigned int base = SCpnt->device->host->io_port;
  413. DEB(printk("aha1740[%d] critical section\n",ecbno));
  414. spin_lock_irqsave(SCpnt->device->host->host_lock, flags);
  415. for (loopcnt = 0; ; loopcnt++) {
  416. if (inb(G2STAT(base)) & G2STAT_MBXOUT) break;
  417. if (loopcnt == LOOPCNT_WARN) {
  418. printk("aha1740[%d]_mbxout wait!\n",ecbno);
  419. }
  420. if (loopcnt == LOOPCNT_MAX)
  421. panic("aha1740.c: mbxout busy!\n");
  422. }
  423. outl (ecb_cpu_to_dma (SCpnt->device->host, host->ecb + ecbno),
  424. MBOXOUT0(base));
  425. for (loopcnt = 0; ; loopcnt++) {
  426. if (! (inb(G2STAT(base)) & G2STAT_BUSY)) break;
  427. if (loopcnt == LOOPCNT_WARN) {
  428. printk("aha1740[%d]_attn wait!\n",ecbno);
  429. }
  430. if (loopcnt == LOOPCNT_MAX)
  431. panic("aha1740.c: attn wait failed!\n");
  432. }
  433. outb(ATTN_START | (target & 7), ATTN(base)); /* Start it up */
  434. spin_unlock_irqrestore(SCpnt->device->host->host_lock, flags);
  435. DEB(printk("aha1740[%d] request queued.\n",ecbno));
  436. } else
  437. printk(KERN_ALERT "aha1740_queuecommand: done can't be NULL\n");
  438. return 0;
  439. }
  440. static DEF_SCSI_QCMD(aha1740_queuecommand)
  441. /* Query the board for its irq_level and irq_type. Nothing else matters
  442. in enhanced mode on an EISA bus. */
  443. static void aha1740_getconfig(unsigned int base, unsigned int *irq_level,
  444. unsigned int *irq_type,
  445. unsigned int *translation)
  446. {
  447. static int intab[] = { 9, 10, 11, 12, 0, 14, 15, 0 };
  448. *irq_level = intab[inb(INTDEF(base)) & 0x7];
  449. *irq_type = (inb(INTDEF(base)) & 0x8) >> 3;
  450. *translation = inb(RESV1(base)) & 0x1;
  451. outb(inb(INTDEF(base)) | 0x10, INTDEF(base));
  452. }
  453. static int aha1740_biosparam(struct scsi_device *sdev,
  454. struct block_device *dev,
  455. sector_t capacity, int* ip)
  456. {
  457. int size = capacity;
  458. int extended = HOSTDATA(sdev->host)->translation;
  459. DEB(printk("aha1740_biosparam\n"));
  460. if (extended && (ip[2] > 1024)) {
  461. ip[0] = 255;
  462. ip[1] = 63;
  463. ip[2] = size / (255 * 63);
  464. } else {
  465. ip[0] = 64;
  466. ip[1] = 32;
  467. ip[2] = size >> 11;
  468. }
  469. return 0;
  470. }
  471. static int aha1740_eh_abort_handler (Scsi_Cmnd *dummy)
  472. {
  473. /*
  474. * From Alan Cox :
  475. * The AHA1740 has firmware handled abort/reset handling. The "head in
  476. * sand" kernel code is correct for once 8)
  477. *
  478. * So we define a dummy handler just to keep the kernel SCSI code as
  479. * quiet as possible...
  480. */
  481. return SUCCESS;
  482. }
  483. static struct scsi_host_template aha1740_template = {
  484. .module = THIS_MODULE,
  485. .proc_name = "aha1740",
  486. .show_info = aha1740_show_info,
  487. .name = "Adaptec 174x (EISA)",
  488. .queuecommand = aha1740_queuecommand,
  489. .bios_param = aha1740_biosparam,
  490. .can_queue = AHA1740_ECBS,
  491. .this_id = 7,
  492. .sg_tablesize = AHA1740_SCATTER,
  493. .use_clustering = ENABLE_CLUSTERING,
  494. .eh_abort_handler = aha1740_eh_abort_handler,
  495. };
  496. static int aha1740_probe (struct device *dev)
  497. {
  498. int slotbase, rc;
  499. unsigned int irq_level, irq_type, translation;
  500. struct Scsi_Host *shpnt;
  501. struct aha1740_hostdata *host;
  502. struct eisa_device *edev = to_eisa_device (dev);
  503. DEB(printk("aha1740_probe: \n"));
  504. slotbase = edev->base_addr + EISA_VENDOR_ID_OFFSET;
  505. if (!request_region(slotbase, SLOTSIZE, "aha1740")) /* See if in use */
  506. return -EBUSY;
  507. if (!aha1740_test_port(slotbase))
  508. goto err_release_region;
  509. aha1740_getconfig(slotbase,&irq_level,&irq_type,&translation);
  510. if ((inb(G2STAT(slotbase)) &
  511. (G2STAT_MBXOUT|G2STAT_BUSY)) != G2STAT_MBXOUT) {
  512. /* If the card isn't ready, hard reset it */
  513. outb(G2CNTRL_HRST, G2CNTRL(slotbase));
  514. outb(0, G2CNTRL(slotbase));
  515. }
  516. printk(KERN_INFO "Configuring slot %d at IO:%x, IRQ %u (%s)\n",
  517. edev->slot, slotbase, irq_level, irq_type ? "edge" : "level");
  518. printk(KERN_INFO "aha174x: Extended translation %sabled.\n",
  519. translation ? "en" : "dis");
  520. shpnt = scsi_host_alloc(&aha1740_template,
  521. sizeof(struct aha1740_hostdata));
  522. if(shpnt == NULL)
  523. goto err_release_region;
  524. shpnt->base = 0;
  525. shpnt->io_port = slotbase;
  526. shpnt->n_io_port = SLOTSIZE;
  527. shpnt->irq = irq_level;
  528. shpnt->dma_channel = 0xff;
  529. host = HOSTDATA(shpnt);
  530. host->edev = edev;
  531. host->translation = translation;
  532. host->ecb_dma_addr = dma_map_single (&edev->dev, host->ecb,
  533. sizeof (host->ecb),
  534. DMA_BIDIRECTIONAL);
  535. if (!host->ecb_dma_addr) {
  536. printk (KERN_ERR "aha1740_probe: Couldn't map ECB, giving up\n");
  537. scsi_unregister (shpnt);
  538. goto err_host_put;
  539. }
  540. DEB(printk("aha1740_probe: enable interrupt channel %d\n",irq_level));
  541. if (request_irq(irq_level,aha1740_intr_handle,irq_type ? 0 : IRQF_SHARED,
  542. "aha1740",shpnt)) {
  543. printk(KERN_ERR "aha1740_probe: Unable to allocate IRQ %d.\n",
  544. irq_level);
  545. goto err_unmap;
  546. }
  547. eisa_set_drvdata (edev, shpnt);
  548. rc = scsi_add_host (shpnt, dev);
  549. if (rc)
  550. goto err_irq;
  551. scsi_scan_host (shpnt);
  552. return 0;
  553. err_irq:
  554. free_irq(irq_level, shpnt);
  555. err_unmap:
  556. dma_unmap_single (&edev->dev, host->ecb_dma_addr,
  557. sizeof (host->ecb), DMA_BIDIRECTIONAL);
  558. err_host_put:
  559. scsi_host_put (shpnt);
  560. err_release_region:
  561. release_region(slotbase, SLOTSIZE);
  562. return -ENODEV;
  563. }
  564. static int aha1740_remove (struct device *dev)
  565. {
  566. struct Scsi_Host *shpnt = dev_get_drvdata(dev);
  567. struct aha1740_hostdata *host = HOSTDATA (shpnt);
  568. scsi_remove_host(shpnt);
  569. free_irq (shpnt->irq, shpnt);
  570. dma_unmap_single (dev, host->ecb_dma_addr,
  571. sizeof (host->ecb), DMA_BIDIRECTIONAL);
  572. release_region (shpnt->io_port, SLOTSIZE);
  573. scsi_host_put (shpnt);
  574. return 0;
  575. }
  576. static struct eisa_device_id aha1740_ids[] = {
  577. { "ADP0000" }, /* 1740 */
  578. { "ADP0001" }, /* 1740A */
  579. { "ADP0002" }, /* 1742A */
  580. { "ADP0400" }, /* 1744 */
  581. { "" }
  582. };
  583. MODULE_DEVICE_TABLE(eisa, aha1740_ids);
  584. static struct eisa_driver aha1740_driver = {
  585. .id_table = aha1740_ids,
  586. .driver = {
  587. .name = "aha1740",
  588. .probe = aha1740_probe,
  589. .remove = aha1740_remove,
  590. },
  591. };
  592. static __init int aha1740_init (void)
  593. {
  594. return eisa_driver_register (&aha1740_driver);
  595. }
  596. static __exit void aha1740_exit (void)
  597. {
  598. eisa_driver_unregister (&aha1740_driver);
  599. }
  600. module_init (aha1740_init);
  601. module_exit (aha1740_exit);
  602. MODULE_LICENSE("GPL");