sun3_scsi.c 16 KB

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