sun3_scsi.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667
  1. /*
  2. * Sun3 SCSI stuff by Erik Verbruggen (erik@bigmama.xtdnet.nl)
  3. *
  4. * Sun3 DMA routines added by Sam Creasey (sammy@sammy.net)
  5. *
  6. * VME support added by Sam Creasey
  7. *
  8. * TODO: modify this driver to support multiple Sun3 SCSI VME boards
  9. *
  10. * Adapted from mac_scsinew.c:
  11. */
  12. /*
  13. * Generic Macintosh NCR5380 driver
  14. *
  15. * Copyright 1998, Michael Schmitz <mschmitz@lbl.gov>
  16. *
  17. * derived in part from:
  18. */
  19. /*
  20. * Generic Generic NCR5380 driver
  21. *
  22. * Copyright 1995, Russell King
  23. */
  24. #include <linux/types.h>
  25. #include <linux/delay.h>
  26. #include <linux/module.h>
  27. #include <linux/ioport.h>
  28. #include <linux/init.h>
  29. #include <linux/blkdev.h>
  30. #include <linux/platform_device.h>
  31. #include <asm/io.h>
  32. #include <asm/dvma.h>
  33. #include <scsi/scsi_host.h>
  34. /* minimum number of bytes to do dma on */
  35. #define DMA_MIN_SIZE 129
  36. /* Definitions for the core NCR5380 driver. */
  37. #define NCR5380_implementation_fields /* none */
  38. #define NCR5380_read(reg) in_8(hostdata->io + (reg))
  39. #define NCR5380_write(reg, value) out_8(hostdata->io + (reg), value)
  40. #define NCR5380_queue_command sun3scsi_queue_command
  41. #define NCR5380_host_reset sun3scsi_host_reset
  42. #define NCR5380_abort sun3scsi_abort
  43. #define NCR5380_info sun3scsi_info
  44. #define NCR5380_dma_xfer_len sun3scsi_dma_xfer_len
  45. #define NCR5380_dma_recv_setup sun3scsi_dma_count
  46. #define NCR5380_dma_send_setup sun3scsi_dma_count
  47. #define NCR5380_dma_residual sun3scsi_dma_residual
  48. #include "NCR5380.h"
  49. /* dma regs start at regbase + 8, directly after the NCR regs */
  50. struct sun3_dma_regs {
  51. unsigned short dma_addr_hi; /* vme only */
  52. unsigned short dma_addr_lo; /* vme only */
  53. unsigned short dma_count_hi; /* vme only */
  54. unsigned short dma_count_lo; /* vme only */
  55. unsigned short udc_data; /* udc dma data reg (obio only) */
  56. unsigned short udc_addr; /* uda dma addr reg (obio only) */
  57. unsigned short fifo_data; /* fifo data reg,
  58. * holds extra byte on odd dma reads
  59. */
  60. unsigned short fifo_count;
  61. unsigned short csr; /* control/status reg */
  62. unsigned short bpack_hi; /* vme only */
  63. unsigned short bpack_lo; /* vme only */
  64. unsigned short ivect; /* vme only */
  65. unsigned short fifo_count_hi; /* vme only */
  66. };
  67. /* ucd chip specific regs - live in dvma space */
  68. struct sun3_udc_regs {
  69. unsigned short rsel; /* select regs to load */
  70. unsigned short addr_hi; /* high word of addr */
  71. unsigned short addr_lo; /* low word */
  72. unsigned short count; /* words to be xfer'd */
  73. unsigned short mode_hi; /* high word of channel mode */
  74. unsigned short mode_lo; /* low word of channel mode */
  75. };
  76. /* addresses of the udc registers */
  77. #define UDC_MODE 0x38
  78. #define UDC_CSR 0x2e /* command/status */
  79. #define UDC_CHN_HI 0x26 /* chain high word */
  80. #define UDC_CHN_LO 0x22 /* chain lo word */
  81. #define UDC_CURA_HI 0x1a /* cur reg A high */
  82. #define UDC_CURA_LO 0x0a /* cur reg A low */
  83. #define UDC_CURB_HI 0x12 /* cur reg B high */
  84. #define UDC_CURB_LO 0x02 /* cur reg B low */
  85. #define UDC_MODE_HI 0x56 /* mode reg high */
  86. #define UDC_MODE_LO 0x52 /* mode reg low */
  87. #define UDC_COUNT 0x32 /* words to xfer */
  88. /* some udc commands */
  89. #define UDC_RESET 0
  90. #define UDC_CHN_START 0xa0 /* start chain */
  91. #define UDC_INT_ENABLE 0x32 /* channel 1 int on */
  92. /* udc mode words */
  93. #define UDC_MODE_HIWORD 0x40
  94. #define UDC_MODE_LSEND 0xc2
  95. #define UDC_MODE_LRECV 0xd2
  96. /* udc reg selections */
  97. #define UDC_RSEL_SEND 0x282
  98. #define UDC_RSEL_RECV 0x182
  99. /* bits in csr reg */
  100. #define CSR_DMA_ACTIVE 0x8000
  101. #define CSR_DMA_CONFLICT 0x4000
  102. #define CSR_DMA_BUSERR 0x2000
  103. #define CSR_FIFO_EMPTY 0x400 /* fifo flushed? */
  104. #define CSR_SDB_INT 0x200 /* sbc interrupt pending */
  105. #define CSR_DMA_INT 0x100 /* dma interrupt pending */
  106. #define CSR_LEFT 0xc0
  107. #define CSR_LEFT_3 0xc0
  108. #define CSR_LEFT_2 0x80
  109. #define CSR_LEFT_1 0x40
  110. #define CSR_PACK_ENABLE 0x20
  111. #define CSR_DMA_ENABLE 0x10
  112. #define CSR_SEND 0x8 /* 1 = send 0 = recv */
  113. #define CSR_FIFO 0x2 /* reset fifo */
  114. #define CSR_INTR 0x4 /* interrupt enable */
  115. #define CSR_SCSI 0x1
  116. #define VME_DATA24 0x3d00
  117. extern int sun3_map_test(unsigned long, char *);
  118. static int setup_can_queue = -1;
  119. module_param(setup_can_queue, int, 0);
  120. static int setup_cmd_per_lun = -1;
  121. module_param(setup_cmd_per_lun, int, 0);
  122. static int setup_sg_tablesize = -1;
  123. module_param(setup_sg_tablesize, int, 0);
  124. static int setup_hostid = -1;
  125. module_param(setup_hostid, int, 0);
  126. /* ms to wait after hitting dma regs */
  127. #define SUN3_DMA_DELAY 10
  128. /* dvma buffer to allocate -- 32k should hopefully be more than sufficient */
  129. #define SUN3_DVMA_BUFSIZE 0xe000
  130. static struct scsi_cmnd *sun3_dma_setup_done;
  131. static volatile struct sun3_dma_regs *dregs;
  132. static struct sun3_udc_regs *udc_regs;
  133. static unsigned char *sun3_dma_orig_addr;
  134. static unsigned long sun3_dma_orig_count;
  135. static int sun3_dma_active;
  136. static unsigned long last_residual;
  137. #ifndef SUN3_SCSI_VME
  138. /* dma controller register access functions */
  139. static inline unsigned short sun3_udc_read(unsigned char reg)
  140. {
  141. unsigned short ret;
  142. dregs->udc_addr = UDC_CSR;
  143. udelay(SUN3_DMA_DELAY);
  144. ret = dregs->udc_data;
  145. udelay(SUN3_DMA_DELAY);
  146. return ret;
  147. }
  148. static inline void sun3_udc_write(unsigned short val, unsigned char reg)
  149. {
  150. dregs->udc_addr = reg;
  151. udelay(SUN3_DMA_DELAY);
  152. dregs->udc_data = val;
  153. udelay(SUN3_DMA_DELAY);
  154. }
  155. #endif
  156. // safe bits for the CSR
  157. #define CSR_GOOD 0x060f
  158. static irqreturn_t scsi_sun3_intr(int irq, void *dev)
  159. {
  160. struct Scsi_Host *instance = dev;
  161. unsigned short csr = dregs->csr;
  162. int handled = 0;
  163. #ifdef SUN3_SCSI_VME
  164. dregs->csr &= ~CSR_DMA_ENABLE;
  165. #endif
  166. if(csr & ~CSR_GOOD) {
  167. if (csr & CSR_DMA_BUSERR)
  168. shost_printk(KERN_ERR, instance, "bus error in DMA\n");
  169. if (csr & CSR_DMA_CONFLICT)
  170. shost_printk(KERN_ERR, instance, "DMA conflict\n");
  171. handled = 1;
  172. }
  173. if(csr & (CSR_SDB_INT | CSR_DMA_INT)) {
  174. NCR5380_intr(irq, dev);
  175. handled = 1;
  176. }
  177. return IRQ_RETVAL(handled);
  178. }
  179. /* sun3scsi_dma_setup() -- initialize the dma controller for a read/write */
  180. static int sun3scsi_dma_setup(struct NCR5380_hostdata *hostdata,
  181. unsigned char *data, int count, int write_flag)
  182. {
  183. void *addr;
  184. if(sun3_dma_orig_addr != NULL)
  185. dvma_unmap(sun3_dma_orig_addr);
  186. #ifdef SUN3_SCSI_VME
  187. addr = (void *)dvma_map_vme((unsigned long) data, count);
  188. #else
  189. addr = (void *)dvma_map((unsigned long) data, count);
  190. #endif
  191. sun3_dma_orig_addr = addr;
  192. sun3_dma_orig_count = count;
  193. #ifndef SUN3_SCSI_VME
  194. dregs->fifo_count = 0;
  195. sun3_udc_write(UDC_RESET, UDC_CSR);
  196. /* reset fifo */
  197. dregs->csr &= ~CSR_FIFO;
  198. dregs->csr |= CSR_FIFO;
  199. #endif
  200. /* set direction */
  201. if(write_flag)
  202. dregs->csr |= CSR_SEND;
  203. else
  204. dregs->csr &= ~CSR_SEND;
  205. #ifdef SUN3_SCSI_VME
  206. dregs->csr |= CSR_PACK_ENABLE;
  207. dregs->dma_addr_hi = ((unsigned long)addr >> 16);
  208. dregs->dma_addr_lo = ((unsigned long)addr & 0xffff);
  209. dregs->dma_count_hi = 0;
  210. dregs->dma_count_lo = 0;
  211. dregs->fifo_count_hi = 0;
  212. dregs->fifo_count = 0;
  213. #else
  214. /* byte count for fifo */
  215. dregs->fifo_count = count;
  216. sun3_udc_write(UDC_RESET, UDC_CSR);
  217. /* reset fifo */
  218. dregs->csr &= ~CSR_FIFO;
  219. dregs->csr |= CSR_FIFO;
  220. if(dregs->fifo_count != count) {
  221. shost_printk(KERN_ERR, hostdata->host,
  222. "FIFO mismatch %04x not %04x\n",
  223. dregs->fifo_count, (unsigned int) count);
  224. NCR5380_dprint(NDEBUG_DMA, hostdata->host);
  225. }
  226. /* setup udc */
  227. udc_regs->addr_hi = (((unsigned long)(addr) & 0xff0000) >> 8);
  228. udc_regs->addr_lo = ((unsigned long)(addr) & 0xffff);
  229. udc_regs->count = count/2; /* count in words */
  230. udc_regs->mode_hi = UDC_MODE_HIWORD;
  231. if(write_flag) {
  232. if(count & 1)
  233. udc_regs->count++;
  234. udc_regs->mode_lo = UDC_MODE_LSEND;
  235. udc_regs->rsel = UDC_RSEL_SEND;
  236. } else {
  237. udc_regs->mode_lo = UDC_MODE_LRECV;
  238. udc_regs->rsel = UDC_RSEL_RECV;
  239. }
  240. /* announce location of regs block */
  241. sun3_udc_write(((dvma_vtob(udc_regs) & 0xff0000) >> 8),
  242. UDC_CHN_HI);
  243. sun3_udc_write((dvma_vtob(udc_regs) & 0xffff), UDC_CHN_LO);
  244. /* set dma master on */
  245. sun3_udc_write(0xd, UDC_MODE);
  246. /* interrupt enable */
  247. sun3_udc_write(UDC_INT_ENABLE, UDC_CSR);
  248. #endif
  249. return count;
  250. }
  251. static int sun3scsi_dma_count(struct NCR5380_hostdata *hostdata,
  252. unsigned char *data, int count)
  253. {
  254. return count;
  255. }
  256. static inline int sun3scsi_dma_recv_setup(struct NCR5380_hostdata *hostdata,
  257. unsigned char *data, int count)
  258. {
  259. return sun3scsi_dma_setup(hostdata, data, count, 0);
  260. }
  261. static inline int sun3scsi_dma_send_setup(struct NCR5380_hostdata *hostdata,
  262. unsigned char *data, int count)
  263. {
  264. return sun3scsi_dma_setup(hostdata, data, count, 1);
  265. }
  266. static int sun3scsi_dma_residual(struct NCR5380_hostdata *hostdata)
  267. {
  268. return last_residual;
  269. }
  270. static int sun3scsi_dma_xfer_len(struct NCR5380_hostdata *hostdata,
  271. struct scsi_cmnd *cmd)
  272. {
  273. int wanted_len = cmd->SCp.this_residual;
  274. if (wanted_len < DMA_MIN_SIZE || blk_rq_is_passthrough(cmd->request))
  275. return 0;
  276. return wanted_len;
  277. }
  278. static inline int sun3scsi_dma_start(unsigned long count, unsigned char *data)
  279. {
  280. #ifdef SUN3_SCSI_VME
  281. unsigned short csr;
  282. csr = dregs->csr;
  283. dregs->dma_count_hi = (sun3_dma_orig_count >> 16);
  284. dregs->dma_count_lo = (sun3_dma_orig_count & 0xffff);
  285. dregs->fifo_count_hi = (sun3_dma_orig_count >> 16);
  286. dregs->fifo_count = (sun3_dma_orig_count & 0xffff);
  287. /* if(!(csr & CSR_DMA_ENABLE))
  288. * dregs->csr |= CSR_DMA_ENABLE;
  289. */
  290. #else
  291. sun3_udc_write(UDC_CHN_START, UDC_CSR);
  292. #endif
  293. return 0;
  294. }
  295. /* clean up after our dma is done */
  296. static int sun3scsi_dma_finish(int write_flag)
  297. {
  298. unsigned short __maybe_unused count;
  299. unsigned short fifo;
  300. int ret = 0;
  301. sun3_dma_active = 0;
  302. #ifdef SUN3_SCSI_VME
  303. dregs->csr &= ~CSR_DMA_ENABLE;
  304. fifo = dregs->fifo_count;
  305. if (write_flag) {
  306. if ((fifo > 0) && (fifo < sun3_dma_orig_count))
  307. fifo++;
  308. }
  309. last_residual = fifo;
  310. /* empty bytes from the fifo which didn't make it */
  311. if ((!write_flag) && (dregs->csr & CSR_LEFT)) {
  312. unsigned char *vaddr;
  313. vaddr = (unsigned char *)dvma_vmetov(sun3_dma_orig_addr);
  314. vaddr += (sun3_dma_orig_count - fifo);
  315. vaddr--;
  316. switch (dregs->csr & CSR_LEFT) {
  317. case CSR_LEFT_3:
  318. *vaddr = (dregs->bpack_lo & 0xff00) >> 8;
  319. vaddr--;
  320. case CSR_LEFT_2:
  321. *vaddr = (dregs->bpack_hi & 0x00ff);
  322. vaddr--;
  323. case CSR_LEFT_1:
  324. *vaddr = (dregs->bpack_hi & 0xff00) >> 8;
  325. break;
  326. }
  327. }
  328. #else
  329. // check to empty the fifo on a read
  330. if(!write_flag) {
  331. int tmo = 20000; /* .2 sec */
  332. while(1) {
  333. if(dregs->csr & CSR_FIFO_EMPTY)
  334. break;
  335. if(--tmo <= 0) {
  336. printk("sun3scsi: fifo failed to empty!\n");
  337. return 1;
  338. }
  339. udelay(10);
  340. }
  341. }
  342. dregs->udc_addr = 0x32;
  343. udelay(SUN3_DMA_DELAY);
  344. count = 2 * dregs->udc_data;
  345. udelay(SUN3_DMA_DELAY);
  346. fifo = dregs->fifo_count;
  347. last_residual = fifo;
  348. /* empty bytes from the fifo which didn't make it */
  349. if((!write_flag) && (count - fifo) == 2) {
  350. unsigned short data;
  351. unsigned char *vaddr;
  352. data = dregs->fifo_data;
  353. vaddr = (unsigned char *)dvma_btov(sun3_dma_orig_addr);
  354. vaddr += (sun3_dma_orig_count - fifo);
  355. vaddr[-2] = (data & 0xff00) >> 8;
  356. vaddr[-1] = (data & 0xff);
  357. }
  358. #endif
  359. dvma_unmap(sun3_dma_orig_addr);
  360. sun3_dma_orig_addr = NULL;
  361. #ifdef SUN3_SCSI_VME
  362. dregs->dma_addr_hi = 0;
  363. dregs->dma_addr_lo = 0;
  364. dregs->dma_count_hi = 0;
  365. dregs->dma_count_lo = 0;
  366. dregs->fifo_count = 0;
  367. dregs->fifo_count_hi = 0;
  368. dregs->csr &= ~CSR_SEND;
  369. /* dregs->csr |= CSR_DMA_ENABLE; */
  370. #else
  371. sun3_udc_write(UDC_RESET, UDC_CSR);
  372. dregs->fifo_count = 0;
  373. dregs->csr &= ~CSR_SEND;
  374. /* reset fifo */
  375. dregs->csr &= ~CSR_FIFO;
  376. dregs->csr |= CSR_FIFO;
  377. #endif
  378. sun3_dma_setup_done = NULL;
  379. return ret;
  380. }
  381. #include "NCR5380.c"
  382. #ifdef SUN3_SCSI_VME
  383. #define SUN3_SCSI_NAME "Sun3 NCR5380 VME SCSI"
  384. #define DRV_MODULE_NAME "sun3_scsi_vme"
  385. #else
  386. #define SUN3_SCSI_NAME "Sun3 NCR5380 SCSI"
  387. #define DRV_MODULE_NAME "sun3_scsi"
  388. #endif
  389. #define PFX DRV_MODULE_NAME ": "
  390. static struct scsi_host_template sun3_scsi_template = {
  391. .module = THIS_MODULE,
  392. .proc_name = DRV_MODULE_NAME,
  393. .name = SUN3_SCSI_NAME,
  394. .info = sun3scsi_info,
  395. .queuecommand = sun3scsi_queue_command,
  396. .eh_abort_handler = sun3scsi_abort,
  397. .eh_host_reset_handler = sun3scsi_host_reset,
  398. .can_queue = 16,
  399. .this_id = 7,
  400. .sg_tablesize = 1,
  401. .cmd_per_lun = 2,
  402. .use_clustering = DISABLE_CLUSTERING,
  403. .cmd_size = NCR5380_CMD_SIZE,
  404. };
  405. static int __init sun3_scsi_probe(struct platform_device *pdev)
  406. {
  407. struct Scsi_Host *instance;
  408. struct NCR5380_hostdata *hostdata;
  409. int error;
  410. struct resource *irq, *mem;
  411. void __iomem *ioaddr;
  412. int host_flags = 0;
  413. #ifdef SUN3_SCSI_VME
  414. int i;
  415. #endif
  416. if (setup_can_queue > 0)
  417. sun3_scsi_template.can_queue = setup_can_queue;
  418. if (setup_cmd_per_lun > 0)
  419. sun3_scsi_template.cmd_per_lun = setup_cmd_per_lun;
  420. if (setup_sg_tablesize > 0)
  421. sun3_scsi_template.sg_tablesize = setup_sg_tablesize;
  422. if (setup_hostid >= 0)
  423. sun3_scsi_template.this_id = setup_hostid & 7;
  424. #ifdef SUN3_SCSI_VME
  425. ioaddr = NULL;
  426. for (i = 0; i < 2; i++) {
  427. unsigned char x;
  428. irq = platform_get_resource(pdev, IORESOURCE_IRQ, i);
  429. mem = platform_get_resource(pdev, IORESOURCE_MEM, i);
  430. if (!irq || !mem)
  431. break;
  432. ioaddr = sun3_ioremap(mem->start, resource_size(mem),
  433. SUN3_PAGE_TYPE_VME16);
  434. dregs = (struct sun3_dma_regs *)(ioaddr + 8);
  435. if (sun3_map_test((unsigned long)dregs, &x)) {
  436. unsigned short oldcsr;
  437. oldcsr = dregs->csr;
  438. dregs->csr = 0;
  439. udelay(SUN3_DMA_DELAY);
  440. if (dregs->csr == 0x1400)
  441. break;
  442. dregs->csr = oldcsr;
  443. }
  444. iounmap(ioaddr);
  445. ioaddr = NULL;
  446. }
  447. if (!ioaddr)
  448. return -ENODEV;
  449. #else
  450. irq = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
  451. mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  452. if (!irq || !mem)
  453. return -ENODEV;
  454. ioaddr = ioremap(mem->start, resource_size(mem));
  455. dregs = (struct sun3_dma_regs *)(ioaddr + 8);
  456. udc_regs = dvma_malloc(sizeof(struct sun3_udc_regs));
  457. if (!udc_regs) {
  458. pr_err(PFX "couldn't allocate DVMA memory!\n");
  459. iounmap(ioaddr);
  460. return -ENOMEM;
  461. }
  462. #endif
  463. instance = scsi_host_alloc(&sun3_scsi_template,
  464. sizeof(struct NCR5380_hostdata));
  465. if (!instance) {
  466. error = -ENOMEM;
  467. goto fail_alloc;
  468. }
  469. instance->irq = irq->start;
  470. hostdata = shost_priv(instance);
  471. hostdata->base = mem->start;
  472. hostdata->io = ioaddr;
  473. error = NCR5380_init(instance, host_flags);
  474. if (error)
  475. goto fail_init;
  476. error = request_irq(instance->irq, scsi_sun3_intr, 0,
  477. "NCR5380", instance);
  478. if (error) {
  479. pr_err(PFX "scsi%d: IRQ %d not free, bailing out\n",
  480. instance->host_no, instance->irq);
  481. goto fail_irq;
  482. }
  483. dregs->csr = 0;
  484. udelay(SUN3_DMA_DELAY);
  485. dregs->csr = CSR_SCSI | CSR_FIFO | CSR_INTR;
  486. udelay(SUN3_DMA_DELAY);
  487. dregs->fifo_count = 0;
  488. #ifdef SUN3_SCSI_VME
  489. dregs->fifo_count_hi = 0;
  490. dregs->dma_addr_hi = 0;
  491. dregs->dma_addr_lo = 0;
  492. dregs->dma_count_hi = 0;
  493. dregs->dma_count_lo = 0;
  494. dregs->ivect = VME_DATA24 | (instance->irq & 0xff);
  495. #endif
  496. NCR5380_maybe_reset_bus(instance);
  497. error = scsi_add_host(instance, NULL);
  498. if (error)
  499. goto fail_host;
  500. platform_set_drvdata(pdev, instance);
  501. scsi_scan_host(instance);
  502. return 0;
  503. fail_host:
  504. free_irq(instance->irq, instance);
  505. fail_irq:
  506. NCR5380_exit(instance);
  507. fail_init:
  508. scsi_host_put(instance);
  509. fail_alloc:
  510. if (udc_regs)
  511. dvma_free(udc_regs);
  512. iounmap(ioaddr);
  513. return error;
  514. }
  515. static int __exit sun3_scsi_remove(struct platform_device *pdev)
  516. {
  517. struct Scsi_Host *instance = platform_get_drvdata(pdev);
  518. struct NCR5380_hostdata *hostdata = shost_priv(instance);
  519. void __iomem *ioaddr = hostdata->io;
  520. scsi_remove_host(instance);
  521. free_irq(instance->irq, instance);
  522. NCR5380_exit(instance);
  523. scsi_host_put(instance);
  524. if (udc_regs)
  525. dvma_free(udc_regs);
  526. iounmap(ioaddr);
  527. return 0;
  528. }
  529. static struct platform_driver sun3_scsi_driver = {
  530. .remove = __exit_p(sun3_scsi_remove),
  531. .driver = {
  532. .name = DRV_MODULE_NAME,
  533. },
  534. };
  535. module_platform_driver_probe(sun3_scsi_driver, sun3_scsi_probe);
  536. MODULE_ALIAS("platform:" DRV_MODULE_NAME);
  537. MODULE_LICENSE("GPL");