blob: ba51699827063597407e096d73d25f50d5bc7b50 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * Sun3 SCSI stuff by Erik Verbruggen (erik@bigmama.xtdnet.nl)
3 *
4 * Sun3 DMA routines added by Sam Creasey (sammy@sammy.net)
5 *
Finn Thain757f5ba2014-03-18 11:42:24 +11006 * VME support added by Sam Creasey
7 *
8 * TODO: modify this driver to support multiple Sun3 SCSI VME boards
9 *
Linus Torvalds1da177e2005-04-16 15:20:36 -070010 * 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
Linus Torvalds1da177e2005-04-16 15:20:36 -070023 */
24
Linus Torvalds1da177e2005-04-16 15:20:36 -070025#include <linux/types.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070026#include <linux/delay.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070027#include <linux/module.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070028#include <linux/ioport.h>
29#include <linux/init.h>
30#include <linux/blkdev.h>
Finn Thain0d31f872014-11-13 12:21:28 +110031#include <linux/platform_device.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070032
33#include <asm/io.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070034#include <asm/dvma.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070035
36/* dma on! */
37#define REAL_DMA
38
Linus Torvalds1da177e2005-04-16 15:20:36 -070039#include <scsi/scsi_host.h>
40#include "sun3_scsi.h"
Finn Thain9f6620a2014-03-18 11:42:23 +110041#include "NCR5380.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070042
Finn Thain757f5ba2014-03-18 11:42:24 +110043extern int sun3_map_test(unsigned long, char *);
Linus Torvalds1da177e2005-04-16 15:20:36 -070044
Linus Torvalds1da177e2005-04-16 15:20:36 -070045/*#define RESET_BOOT */
Linus Torvalds1da177e2005-04-16 15:20:36 -070046/* #define SUPPORT_TAGS */
47
Finn Thain757f5ba2014-03-18 11:42:24 +110048#ifdef SUN3_SCSI_VME
49#define ENABLE_IRQ()
50#else
Linus Torvalds1da177e2005-04-16 15:20:36 -070051#define ENABLE_IRQ() enable_irq( IRQ_SUN3_SCSI );
Finn Thain757f5ba2014-03-18 11:42:24 +110052#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -070053
54
Linus Torvalds1da177e2005-04-16 15:20:36 -070055static int setup_can_queue = -1;
56module_param(setup_can_queue, int, 0);
57static int setup_cmd_per_lun = -1;
58module_param(setup_cmd_per_lun, int, 0);
59static int setup_sg_tablesize = -1;
60module_param(setup_sg_tablesize, int, 0);
61#ifdef SUPPORT_TAGS
62static int setup_use_tagged_queuing = -1;
63module_param(setup_use_tagged_queuing, int, 0);
64#endif
65static int setup_hostid = -1;
66module_param(setup_hostid, int, 0);
67
Henne811c9362006-10-03 19:51:59 +020068static struct scsi_cmnd *sun3_dma_setup_done = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -070069
Michael Schmitz2b0f8342014-05-02 20:43:01 +120070#define RESET_RUN_DONE
71
Linus Torvalds1da177e2005-04-16 15:20:36 -070072#define AFTER_RESET_DELAY (HZ/2)
73
74/* ms to wait after hitting dma regs */
75#define SUN3_DMA_DELAY 10
76
77/* dvma buffer to allocate -- 32k should hopefully be more than sufficient */
78#define SUN3_DVMA_BUFSIZE 0xe000
79
80/* minimum number of bytes to do dma on */
81#define SUN3_DMA_MINSIZE 128
82
Finn Thain0d31f872014-11-13 12:21:28 +110083static unsigned char *sun3_scsi_regp;
Linus Torvalds1da177e2005-04-16 15:20:36 -070084static volatile struct sun3_dma_regs *dregs;
Finn Thain0d31f872014-11-13 12:21:28 +110085static struct sun3_udc_regs *udc_regs;
Linus Torvalds1da177e2005-04-16 15:20:36 -070086static unsigned char *sun3_dma_orig_addr = NULL;
87static unsigned long sun3_dma_orig_count = 0;
88static int sun3_dma_active = 0;
89static unsigned long last_residual = 0;
Finn Thain0d31f872014-11-13 12:21:28 +110090static struct Scsi_Host *default_instance;
Linus Torvalds1da177e2005-04-16 15:20:36 -070091
92/*
93 * NCR 5380 register access functions
94 */
95
96static inline unsigned char sun3scsi_read(int reg)
97{
Finn Thain0d31f872014-11-13 12:21:28 +110098 return in_8(sun3_scsi_regp + reg);
Linus Torvalds1da177e2005-04-16 15:20:36 -070099}
100
101static inline void sun3scsi_write(int reg, int value)
102{
Finn Thain0d31f872014-11-13 12:21:28 +1100103 out_8(sun3_scsi_regp + reg, value);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700104}
105
Finn Thain757f5ba2014-03-18 11:42:24 +1100106#ifndef SUN3_SCSI_VME
Linus Torvalds1da177e2005-04-16 15:20:36 -0700107/* dma controller register access functions */
108
109static inline unsigned short sun3_udc_read(unsigned char reg)
110{
111 unsigned short ret;
112
113 dregs->udc_addr = UDC_CSR;
114 udelay(SUN3_DMA_DELAY);
115 ret = dregs->udc_data;
116 udelay(SUN3_DMA_DELAY);
117
118 return ret;
119}
120
121static inline void sun3_udc_write(unsigned short val, unsigned char reg)
122{
123 dregs->udc_addr = reg;
124 udelay(SUN3_DMA_DELAY);
125 dregs->udc_data = val;
126 udelay(SUN3_DMA_DELAY);
127}
Finn Thain757f5ba2014-03-18 11:42:24 +1100128#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700129
Linus Torvalds1da177e2005-04-16 15:20:36 -0700130#ifdef RESET_BOOT
Linus Torvalds1da177e2005-04-16 15:20:36 -0700131static void sun3_scsi_reset_boot(struct Scsi_Host *instance)
132{
133 unsigned long end;
134
135 NCR5380_local_declare();
136 NCR5380_setup(instance);
137
138 /*
139 * Do a SCSI reset to clean up the bus during initialization. No
140 * messing with the queues, interrupts, or locks necessary here.
141 */
142
143 printk( "Sun3 SCSI: resetting the SCSI bus..." );
144
145 /* switch off SCSI IRQ - catch an interrupt without IRQ bit set else */
146// sun3_disable_irq( IRQ_SUN3_SCSI );
147
148 /* get in phase */
149 NCR5380_write( TARGET_COMMAND_REG,
150 PHASE_SR_TO_TCR( NCR5380_read(STATUS_REG) ));
151
152 /* assert RST */
153 NCR5380_write( INITIATOR_COMMAND_REG, ICR_BASE | ICR_ASSERT_RST );
154
155 /* The min. reset hold time is 25us, so 40us should be enough */
156 udelay( 50 );
157
158 /* reset RST and interrupt */
159 NCR5380_write( INITIATOR_COMMAND_REG, ICR_BASE );
160 NCR5380_read( RESET_PARITY_INTERRUPT_REG );
161
162 for( end = jiffies + AFTER_RESET_DELAY; time_before(jiffies, end); )
163 barrier();
164
165 /* switch on SCSI IRQ again */
166// sun3_enable_irq( IRQ_SUN3_SCSI );
167
168 printk( " done\n" );
169}
170#endif
171
Linus Torvalds1da177e2005-04-16 15:20:36 -0700172// safe bits for the CSR
173#define CSR_GOOD 0x060f
174
David Howells7d12e782006-10-05 14:55:46 +0100175static irqreturn_t scsi_sun3_intr(int irq, void *dummy)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700176{
177 unsigned short csr = dregs->csr;
178 int handled = 0;
179
Finn Thain757f5ba2014-03-18 11:42:24 +1100180#ifdef SUN3_SCSI_VME
181 dregs->csr &= ~CSR_DMA_ENABLE;
182#endif
183
Linus Torvalds1da177e2005-04-16 15:20:36 -0700184 if(csr & ~CSR_GOOD) {
185 if(csr & CSR_DMA_BUSERR) {
186 printk("scsi%d: bus error in dma\n", default_instance->host_no);
187 }
188
189 if(csr & CSR_DMA_CONFLICT) {
190 printk("scsi%d: dma conflict\n", default_instance->host_no);
191 }
192 handled = 1;
193 }
194
195 if(csr & (CSR_SDB_INT | CSR_DMA_INT)) {
David Howells7d12e782006-10-05 14:55:46 +0100196 NCR5380_intr(irq, dummy);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700197 handled = 1;
198 }
199
200 return IRQ_RETVAL(handled);
201}
202
203/*
204 * Debug stuff - to be called on NMI, or sysrq key. Use at your own risk;
205 * reentering NCR5380_print_status seems to have ugly side effects
206 */
207
208/* this doesn't seem to get used at all -- sam */
209#if 0
210void sun3_sun3_debug (void)
211{
212 unsigned long flags;
213 NCR5380_local_declare();
214
215 if (default_instance) {
216 local_irq_save(flags);
217 NCR5380_print_status(default_instance);
218 local_irq_restore(flags);
219 }
220}
221#endif
222
223
224/* sun3scsi_dma_setup() -- initialize the dma controller for a read/write */
225static unsigned long sun3scsi_dma_setup(void *data, unsigned long count, int write_flag)
226{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700227 void *addr;
228
229 if(sun3_dma_orig_addr != NULL)
230 dvma_unmap(sun3_dma_orig_addr);
231
Finn Thain757f5ba2014-03-18 11:42:24 +1100232#ifdef SUN3_SCSI_VME
233 addr = (void *)dvma_map_vme((unsigned long) data, count);
234#else
Linus Torvalds1da177e2005-04-16 15:20:36 -0700235 addr = (void *)dvma_map((unsigned long) data, count);
Finn Thain757f5ba2014-03-18 11:42:24 +1100236#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700237
238 sun3_dma_orig_addr = addr;
239 sun3_dma_orig_count = count;
Finn Thain757f5ba2014-03-18 11:42:24 +1100240
241#ifndef SUN3_SCSI_VME
Linus Torvalds1da177e2005-04-16 15:20:36 -0700242 dregs->fifo_count = 0;
243 sun3_udc_write(UDC_RESET, UDC_CSR);
244
245 /* reset fifo */
246 dregs->csr &= ~CSR_FIFO;
247 dregs->csr |= CSR_FIFO;
Finn Thain757f5ba2014-03-18 11:42:24 +1100248#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700249
250 /* set direction */
251 if(write_flag)
252 dregs->csr |= CSR_SEND;
253 else
254 dregs->csr &= ~CSR_SEND;
255
Finn Thain757f5ba2014-03-18 11:42:24 +1100256#ifdef SUN3_SCSI_VME
257 dregs->csr |= CSR_PACK_ENABLE;
258
259 dregs->dma_addr_hi = ((unsigned long)addr >> 16);
260 dregs->dma_addr_lo = ((unsigned long)addr & 0xffff);
261
262 dregs->dma_count_hi = 0;
263 dregs->dma_count_lo = 0;
264 dregs->fifo_count_hi = 0;
265 dregs->fifo_count = 0;
266#else
Linus Torvalds1da177e2005-04-16 15:20:36 -0700267 /* byte count for fifo */
268 dregs->fifo_count = count;
269
270 sun3_udc_write(UDC_RESET, UDC_CSR);
271
272 /* reset fifo */
273 dregs->csr &= ~CSR_FIFO;
274 dregs->csr |= CSR_FIFO;
275
276 if(dregs->fifo_count != count) {
277 printk("scsi%d: fifo_mismatch %04x not %04x\n",
278 default_instance->host_no, dregs->fifo_count,
279 (unsigned int) count);
Finn Thaind614f062014-03-18 11:42:16 +1100280 NCR5380_dprint(NDEBUG_DMA, default_instance);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700281 }
282
283 /* setup udc */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700284 udc_regs->addr_hi = (((unsigned long)(addr) & 0xff0000) >> 8);
285 udc_regs->addr_lo = ((unsigned long)(addr) & 0xffff);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700286 udc_regs->count = count/2; /* count in words */
287 udc_regs->mode_hi = UDC_MODE_HIWORD;
288 if(write_flag) {
289 if(count & 1)
290 udc_regs->count++;
291 udc_regs->mode_lo = UDC_MODE_LSEND;
292 udc_regs->rsel = UDC_RSEL_SEND;
293 } else {
294 udc_regs->mode_lo = UDC_MODE_LRECV;
295 udc_regs->rsel = UDC_RSEL_RECV;
296 }
297
298 /* announce location of regs block */
299 sun3_udc_write(((dvma_vtob(udc_regs) & 0xff0000) >> 8),
300 UDC_CHN_HI);
301
302 sun3_udc_write((dvma_vtob(udc_regs) & 0xffff), UDC_CHN_LO);
303
304 /* set dma master on */
305 sun3_udc_write(0xd, UDC_MODE);
306
307 /* interrupt enable */
308 sun3_udc_write(UDC_INT_ENABLE, UDC_CSR);
Finn Thain757f5ba2014-03-18 11:42:24 +1100309#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700310
311 return count;
312
313}
314
Finn Thain757f5ba2014-03-18 11:42:24 +1100315#ifndef SUN3_SCSI_VME
Linus Torvalds1da177e2005-04-16 15:20:36 -0700316static inline unsigned long sun3scsi_dma_count(struct Scsi_Host *instance)
317{
318 unsigned short resid;
319
320 dregs->udc_addr = 0x32;
321 udelay(SUN3_DMA_DELAY);
322 resid = dregs->udc_data;
323 udelay(SUN3_DMA_DELAY);
324 resid *= 2;
325
326 return (unsigned long) resid;
327}
Finn Thain757f5ba2014-03-18 11:42:24 +1100328#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700329
330static inline unsigned long sun3scsi_dma_residual(struct Scsi_Host *instance)
331{
332 return last_residual;
333}
334
Henne811c9362006-10-03 19:51:59 +0200335static inline unsigned long sun3scsi_dma_xfer_len(unsigned long wanted,
336 struct scsi_cmnd *cmd,
337 int write_flag)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700338{
Christoph Hellwig33659eb2010-08-07 18:17:56 +0200339 if (cmd->request->cmd_type == REQ_TYPE_FS)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700340 return wanted;
341 else
342 return 0;
343}
344
345static inline int sun3scsi_dma_start(unsigned long count, unsigned char *data)
346{
Finn Thain757f5ba2014-03-18 11:42:24 +1100347#ifdef SUN3_SCSI_VME
348 unsigned short csr;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700349
Finn Thain757f5ba2014-03-18 11:42:24 +1100350 csr = dregs->csr;
351
352 dregs->dma_count_hi = (sun3_dma_orig_count >> 16);
353 dregs->dma_count_lo = (sun3_dma_orig_count & 0xffff);
354
355 dregs->fifo_count_hi = (sun3_dma_orig_count >> 16);
356 dregs->fifo_count = (sun3_dma_orig_count & 0xffff);
357
358/* if(!(csr & CSR_DMA_ENABLE))
359 * dregs->csr |= CSR_DMA_ENABLE;
360 */
361#else
Linus Torvalds1da177e2005-04-16 15:20:36 -0700362 sun3_udc_write(UDC_CHN_START, UDC_CSR);
Finn Thain757f5ba2014-03-18 11:42:24 +1100363#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700364
365 return 0;
366}
367
368/* clean up after our dma is done */
369static int sun3scsi_dma_finish(int write_flag)
370{
Finn Thain757f5ba2014-03-18 11:42:24 +1100371 unsigned short __maybe_unused count;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700372 unsigned short fifo;
373 int ret = 0;
374
375 sun3_dma_active = 0;
Finn Thain757f5ba2014-03-18 11:42:24 +1100376
377#ifdef SUN3_SCSI_VME
378 dregs->csr &= ~CSR_DMA_ENABLE;
379
380 fifo = dregs->fifo_count;
381 if (write_flag) {
382 if ((fifo > 0) && (fifo < sun3_dma_orig_count))
383 fifo++;
384 }
385
386 last_residual = fifo;
387 /* empty bytes from the fifo which didn't make it */
388 if ((!write_flag) && (dregs->csr & CSR_LEFT)) {
389 unsigned char *vaddr;
390
391 vaddr = (unsigned char *)dvma_vmetov(sun3_dma_orig_addr);
392
393 vaddr += (sun3_dma_orig_count - fifo);
394 vaddr--;
395
396 switch (dregs->csr & CSR_LEFT) {
397 case CSR_LEFT_3:
398 *vaddr = (dregs->bpack_lo & 0xff00) >> 8;
399 vaddr--;
400
401 case CSR_LEFT_2:
402 *vaddr = (dregs->bpack_hi & 0x00ff);
403 vaddr--;
404
405 case CSR_LEFT_1:
406 *vaddr = (dregs->bpack_hi & 0xff00) >> 8;
407 break;
408 }
409 }
410#else
Linus Torvalds1da177e2005-04-16 15:20:36 -0700411 // check to empty the fifo on a read
412 if(!write_flag) {
413 int tmo = 20000; /* .2 sec */
414
415 while(1) {
416 if(dregs->csr & CSR_FIFO_EMPTY)
417 break;
418
419 if(--tmo <= 0) {
420 printk("sun3scsi: fifo failed to empty!\n");
421 return 1;
422 }
423 udelay(10);
424 }
425 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700426
427 count = sun3scsi_dma_count(default_instance);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700428
429 fifo = dregs->fifo_count;
430 last_residual = fifo;
431
432 /* empty bytes from the fifo which didn't make it */
433 if((!write_flag) && (count - fifo) == 2) {
434 unsigned short data;
435 unsigned char *vaddr;
436
437 data = dregs->fifo_data;
438 vaddr = (unsigned char *)dvma_btov(sun3_dma_orig_addr);
439
440 vaddr += (sun3_dma_orig_count - fifo);
441
442 vaddr[-2] = (data & 0xff00) >> 8;
443 vaddr[-1] = (data & 0xff);
444 }
Finn Thain757f5ba2014-03-18 11:42:24 +1100445#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700446
447 dvma_unmap(sun3_dma_orig_addr);
448 sun3_dma_orig_addr = NULL;
Finn Thain757f5ba2014-03-18 11:42:24 +1100449
450#ifdef SUN3_SCSI_VME
451 dregs->dma_addr_hi = 0;
452 dregs->dma_addr_lo = 0;
453 dregs->dma_count_hi = 0;
454 dregs->dma_count_lo = 0;
455
456 dregs->fifo_count = 0;
457 dregs->fifo_count_hi = 0;
458
459 dregs->csr &= ~CSR_SEND;
460/* dregs->csr |= CSR_DMA_ENABLE; */
461#else
Linus Torvalds1da177e2005-04-16 15:20:36 -0700462 sun3_udc_write(UDC_RESET, UDC_CSR);
463 dregs->fifo_count = 0;
464 dregs->csr &= ~CSR_SEND;
465
466 /* reset fifo */
467 dregs->csr &= ~CSR_FIFO;
468 dregs->csr |= CSR_FIFO;
Finn Thain757f5ba2014-03-18 11:42:24 +1100469#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700470
471 sun3_dma_setup_done = NULL;
472
473 return ret;
474
475}
476
477#include "sun3_NCR5380.c"
478
Finn Thain0d31f872014-11-13 12:21:28 +1100479#ifdef SUN3_SCSI_VME
480#define SUN3_SCSI_NAME "Sun3 NCR5380 VME SCSI"
481#define DRV_MODULE_NAME "sun3_scsi_vme"
482#else
483#define SUN3_SCSI_NAME "Sun3 NCR5380 SCSI"
484#define DRV_MODULE_NAME "sun3_scsi"
485#endif
486
487#define PFX DRV_MODULE_NAME ": "
488
489static struct scsi_host_template sun3_scsi_template = {
490 .module = THIS_MODULE,
491 .proc_name = DRV_MODULE_NAME,
Geert Uytterhoeven9dcc26c2013-04-10 13:52:09 +0200492 .show_info = sun3scsi_show_info,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700493 .name = SUN3_SCSI_NAME,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700494 .info = sun3scsi_info,
495 .queuecommand = sun3scsi_queue_command,
496 .eh_abort_handler = sun3scsi_abort,
497 .eh_bus_reset_handler = sun3scsi_bus_reset,
Finn Thaind572f65f2014-11-12 16:12:00 +1100498 .can_queue = 16,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700499 .this_id = 7,
Finn Thaind572f65f2014-11-12 16:12:00 +1100500 .sg_tablesize = SG_NONE,
501 .cmd_per_lun = 2,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700502 .use_clustering = DISABLE_CLUSTERING
503};
504
Finn Thain0d31f872014-11-13 12:21:28 +1100505static int __init sun3_scsi_probe(struct platform_device *pdev)
506{
507 struct Scsi_Host *instance;
508 int error;
509 struct resource *irq, *mem;
510 unsigned char *ioaddr;
511#ifdef SUN3_SCSI_VME
512 int i;
513#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700514
Finn Thain0d31f872014-11-13 12:21:28 +1100515 if (setup_can_queue > 0)
516 sun3_scsi_template.can_queue = setup_can_queue;
517 if (setup_cmd_per_lun > 0)
518 sun3_scsi_template.cmd_per_lun = setup_cmd_per_lun;
519 if (setup_sg_tablesize >= 0)
520 sun3_scsi_template.sg_tablesize = setup_sg_tablesize;
521 if (setup_hostid >= 0)
522 sun3_scsi_template.this_id = setup_hostid & 7;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700523
Finn Thain0d31f872014-11-13 12:21:28 +1100524#ifdef SUPPORT_TAGS
525 if (setup_use_tagged_queuing < 0)
526 setup_use_tagged_queuing = 1;
527#endif
528
529#ifdef SUN3_SCSI_VME
530 ioaddr = NULL;
531 for (i = 0; i < 2; i++) {
532 unsigned char x;
533
534 irq = platform_get_resource(pdev, IORESOURCE_IRQ, i);
535 mem = platform_get_resource(pdev, IORESOURCE_MEM, i);
536 if (!irq || !mem)
537 break;
538
539 ioaddr = sun3_ioremap(mem->start, resource_size(mem),
540 SUN3_PAGE_TYPE_VME16);
541 dregs = (struct sun3_dma_regs *)(ioaddr + 8);
542
543 if (sun3_map_test((unsigned long)dregs, &x)) {
544 unsigned short oldcsr;
545
546 oldcsr = dregs->csr;
547 dregs->csr = 0;
548 udelay(SUN3_DMA_DELAY);
549 if (dregs->csr == 0x1400)
550 break;
551
552 dregs->csr = oldcsr;
553 }
554
555 iounmap(ioaddr);
556 ioaddr = NULL;
557 }
558 if (!ioaddr)
559 return -ENODEV;
560#else
561 irq = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
562 mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
563 if (!irq || !mem)
564 return -ENODEV;
565
566 ioaddr = ioremap(mem->start, resource_size(mem));
567 dregs = (struct sun3_dma_regs *)(ioaddr + 8);
568
569 udc_regs = dvma_malloc(sizeof(struct sun3_udc_regs));
570 if (!udc_regs) {
571 pr_err(PFX "couldn't allocate DVMA memory!\n");
572 iounmap(ioaddr);
573 return -ENOMEM;
574 }
575#endif
576
577 sun3_scsi_regp = ioaddr;
578
579 instance = scsi_host_alloc(&sun3_scsi_template,
580 sizeof(struct NCR5380_hostdata));
581 if (!instance) {
582 error = -ENOMEM;
583 goto fail_alloc;
584 }
585 default_instance = instance;
586
587 instance->io_port = (unsigned long)ioaddr;
588 instance->irq = irq->start;
589
590 NCR5380_init(instance, 0);
591
592 error = request_irq(instance->irq, scsi_sun3_intr, 0,
593 "NCR5380", instance);
594 if (error) {
595#ifdef REAL_DMA
596 pr_err(PFX "scsi%d: IRQ %d not free, bailing out\n",
597 instance->host_no, instance->irq);
598 goto fail_irq;
599#else
600 pr_warn(PFX "scsi%d: IRQ %d not free, interrupts disabled\n",
601 instance->host_no, instance->irq);
602 instance->irq = NO_IRQ;
603#endif
604 }
605
606 dregs->csr = 0;
607 udelay(SUN3_DMA_DELAY);
608 dregs->csr = CSR_SCSI | CSR_FIFO | CSR_INTR;
609 udelay(SUN3_DMA_DELAY);
610 dregs->fifo_count = 0;
611#ifdef SUN3_SCSI_VME
612 dregs->fifo_count_hi = 0;
613 dregs->dma_addr_hi = 0;
614 dregs->dma_addr_lo = 0;
615 dregs->dma_count_hi = 0;
616 dregs->dma_count_lo = 0;
617
618 dregs->ivect = VME_DATA24 | (instance->irq & 0xff);
619#endif
620
621#ifdef RESET_BOOT
622 sun3_scsi_reset_boot(instance);
623#endif
624
625 error = scsi_add_host(instance, NULL);
626 if (error)
627 goto fail_host;
628
629 platform_set_drvdata(pdev, instance);
630
631 scsi_scan_host(instance);
632 return 0;
633
634fail_host:
635 if (instance->irq != NO_IRQ)
636 free_irq(instance->irq, instance);
637fail_irq:
638 NCR5380_exit(instance);
639 scsi_host_put(instance);
640fail_alloc:
641 if (udc_regs)
642 dvma_free(udc_regs);
643 iounmap(sun3_scsi_regp);
644 return error;
645}
646
647static int __exit sun3_scsi_remove(struct platform_device *pdev)
648{
649 struct Scsi_Host *instance = platform_get_drvdata(pdev);
650
651 scsi_remove_host(instance);
652 if (instance->irq != NO_IRQ)
653 free_irq(instance->irq, instance);
654 NCR5380_exit(instance);
655 scsi_host_put(instance);
656 if (udc_regs)
657 dvma_free(udc_regs);
658 iounmap(sun3_scsi_regp);
659 return 0;
660}
661
662static struct platform_driver sun3_scsi_driver = {
663 .remove = __exit_p(sun3_scsi_remove),
664 .driver = {
665 .name = DRV_MODULE_NAME,
666 .owner = THIS_MODULE,
667 },
668};
669
670module_platform_driver_probe(sun3_scsi_driver, sun3_scsi_probe);
671
672MODULE_ALIAS("platform:" DRV_MODULE_NAME);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700673MODULE_LICENSE("GPL");