2 * linux/drivers/acorn/scsi/cumana_2.c
4 * Copyright (C) 1997-2005 Russell King
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation.
11 * 30-08-1997 RMK 0.0.0 Created, READONLY version.
12 * 22-01-1998 RMK 0.0.1 Updated to 2.1.80.
13 * 15-04-1998 RMK 0.0.1 Only do PIO if FAS216 will allow it.
14 * 02-05-1998 RMK 0.0.2 Updated & added DMA support.
15 * 27-06-1998 RMK Changed asm/delay.h to linux/delay.h
16 * 18-08-1998 RMK 0.0.3 Fixed synchronous transfer depth.
17 * 02-04-2000 RMK 0.0.4 Updated for new error handling code.
19 #include <linux/module.h>
20 #include <linux/blkdev.h>
21 #include <linux/kernel.h>
22 #include <linux/string.h>
23 #include <linux/ioport.h>
24 #include <linux/sched.h>
25 #include <linux/proc_fs.h>
26 #include <linux/delay.h>
27 #include <linux/interrupt.h>
28 #include <linux/init.h>
29 #include <linux/dma-mapping.h>
32 #include <asm/ecard.h>
34 #include <asm/pgtable.h>
37 #include <scsi/scsi_host.h>
41 #include <scsi/scsicam.h>
43 #define CUMANASCSI2_STATUS (0x0000)
44 #define STATUS_INT (1 << 0)
45 #define STATUS_DRQ (1 << 1)
46 #define STATUS_LATCHED (1 << 3)
48 #define CUMANASCSI2_ALATCH (0x0014)
49 #define ALATCH_ENA_INT (3)
50 #define ALATCH_DIS_INT (2)
51 #define ALATCH_ENA_TERM (5)
52 #define ALATCH_DIS_TERM (4)
53 #define ALATCH_ENA_BIT32 (11)
54 #define ALATCH_DIS_BIT32 (10)
55 #define ALATCH_ENA_DMA (13)
56 #define ALATCH_DIS_DMA (12)
57 #define ALATCH_DMA_OUT (15)
58 #define ALATCH_DMA_IN (14)
60 #define CUMANASCSI2_PSEUDODMA (0x0200)
62 #define CUMANASCSI2_FAS216_OFFSET (0x0300)
63 #define CUMANASCSI2_FAS216_SHIFT 2
68 #define VERSION "1.00 (13/11/2002 2.5.47)"
71 * Use term=0,1,0,0,0 to turn terminators on/off
73 static int term
[MAX_ECARDS
] = { 1, 1, 1, 1, 1, 1, 1, 1 };
77 struct cumanascsi2_info
{
79 struct expansion_card
*ec
;
81 unsigned int terms
; /* Terminator state */
82 struct scatterlist sg
[NR_SG
]; /* Scatter DMA list */
85 #define CSTATUS_IRQ (1 << 0)
86 #define CSTATUS_DRQ (1 << 1)
88 /* Prototype: void cumanascsi_2_irqenable(ec, irqnr)
89 * Purpose : Enable interrupts on Cumana SCSI 2 card
90 * Params : ec - expansion card structure
91 * : irqnr - interrupt number
94 cumanascsi_2_irqenable(struct expansion_card
*ec
, int irqnr
)
96 struct cumanascsi2_info
*info
= ec
->irq_data
;
97 writeb(ALATCH_ENA_INT
, info
->base
+ CUMANASCSI2_ALATCH
);
100 /* Prototype: void cumanascsi_2_irqdisable(ec, irqnr)
101 * Purpose : Disable interrupts on Cumana SCSI 2 card
102 * Params : ec - expansion card structure
103 * : irqnr - interrupt number
106 cumanascsi_2_irqdisable(struct expansion_card
*ec
, int irqnr
)
108 struct cumanascsi2_info
*info
= ec
->irq_data
;
109 writeb(ALATCH_DIS_INT
, info
->base
+ CUMANASCSI2_ALATCH
);
112 static const expansioncard_ops_t cumanascsi_2_ops
= {
113 .irqenable
= cumanascsi_2_irqenable
,
114 .irqdisable
= cumanascsi_2_irqdisable
,
117 /* Prototype: void cumanascsi_2_terminator_ctl(host, on_off)
118 * Purpose : Turn the Cumana SCSI 2 terminators on or off
119 * Params : host - card to turn on/off
120 * : on_off - !0 to turn on, 0 to turn off
123 cumanascsi_2_terminator_ctl(struct Scsi_Host
*host
, int on_off
)
125 struct cumanascsi2_info
*info
= (struct cumanascsi2_info
*)host
->hostdata
;
129 writeb(ALATCH_ENA_TERM
, info
->base
+ CUMANASCSI2_ALATCH
);
132 writeb(ALATCH_DIS_TERM
, info
->base
+ CUMANASCSI2_ALATCH
);
136 /* Prototype: void cumanascsi_2_intr(irq, *dev_id, *regs)
137 * Purpose : handle interrupts from Cumana SCSI 2 card
138 * Params : irq - interrupt number
139 * dev_id - user-defined (Scsi_Host structure)
140 * regs - processor registers at interrupt
143 cumanascsi_2_intr(int irq
, void *dev_id
, struct pt_regs
*regs
)
145 struct cumanascsi2_info
*info
= dev_id
;
147 return fas216_intr(&info
->info
);
150 /* Prototype: fasdmatype_t cumanascsi_2_dma_setup(host, SCpnt, direction, min_type)
151 * Purpose : initialises DMA/PIO
152 * Params : host - host
154 * direction - DMA on to/off of card
155 * min_type - minimum DMA support that we must have for this transfer
156 * Returns : type of transfer to be performed
159 cumanascsi_2_dma_setup(struct Scsi_Host
*host
, struct scsi_pointer
*SCp
,
160 fasdmadir_t direction
, fasdmatype_t min_type
)
162 struct cumanascsi2_info
*info
= (struct cumanascsi2_info
*)host
->hostdata
;
163 struct device
*dev
= scsi_get_device(host
);
164 int dmach
= info
->info
.scsi
.dma
;
166 writeb(ALATCH_DIS_DMA
, info
->base
+ CUMANASCSI2_ALATCH
);
168 if (dmach
!= NO_DMA
&&
169 (min_type
== fasdma_real_all
|| SCp
->this_residual
>= 512)) {
170 int bufs
, map_dir
, dma_dir
, alatch_dir
;
172 bufs
= copy_SCp_to_sg(&info
->sg
[0], SCp
, NR_SG
);
174 if (direction
== DMA_OUT
)
175 map_dir
= DMA_TO_DEVICE
,
176 dma_dir
= DMA_MODE_WRITE
,
177 alatch_dir
= ALATCH_DMA_OUT
;
179 map_dir
= DMA_FROM_DEVICE
,
180 dma_dir
= DMA_MODE_READ
,
181 alatch_dir
= ALATCH_DMA_IN
;
183 dma_map_sg(dev
, info
->sg
, bufs
+ 1, map_dir
);
186 set_dma_sg(dmach
, info
->sg
, bufs
+ 1);
187 writeb(alatch_dir
, info
->base
+ CUMANASCSI2_ALATCH
);
188 set_dma_mode(dmach
, dma_dir
);
190 writeb(ALATCH_ENA_DMA
, info
->base
+ CUMANASCSI2_ALATCH
);
191 writeb(ALATCH_DIS_BIT32
, info
->base
+ CUMANASCSI2_ALATCH
);
192 return fasdma_real_all
;
196 * If we're not doing DMA,
197 * we'll do pseudo DMA
203 * Prototype: void cumanascsi_2_dma_pseudo(host, SCpnt, direction, transfer)
204 * Purpose : handles pseudo DMA
205 * Params : host - host
207 * direction - DMA on to/off of card
208 * transfer - minimum number of bytes we expect to transfer
211 cumanascsi_2_dma_pseudo(struct Scsi_Host
*host
, struct scsi_pointer
*SCp
,
212 fasdmadir_t direction
, int transfer
)
214 struct cumanascsi2_info
*info
= (struct cumanascsi2_info
*)host
->hostdata
;
218 length
= SCp
->this_residual
;
221 if (direction
== DMA_OUT
)
225 unsigned int status
= readb(info
->base
+ CUMANASCSI2_STATUS
);
227 if (status
& STATUS_INT
)
230 if (!(status
& STATUS_DRQ
))
233 word
= *addr
| *(addr
+ 1) << 8;
234 writew(word
, info
->base
+ CUMANASCSI2_PSEUDODMA
);
239 printk ("PSEUDO_OUT???\n");
242 if (transfer
&& (transfer
& 255)) {
243 while (length
>= 256) {
244 unsigned int status
= readb(info
->base
+ CUMANASCSI2_STATUS
);
246 if (status
& STATUS_INT
)
249 if (!(status
& STATUS_DRQ
))
252 readsw(info
->base
+ CUMANASCSI2_PSEUDODMA
,
261 unsigned int status
= readb(info
->base
+ CUMANASCSI2_STATUS
);
263 if (status
& STATUS_INT
)
266 if (!(status
& STATUS_DRQ
))
269 word
= readw(info
->base
+ CUMANASCSI2_PSEUDODMA
);
279 /* Prototype: int cumanascsi_2_dma_stop(host, SCpnt)
280 * Purpose : stops DMA/PIO
281 * Params : host - host
285 cumanascsi_2_dma_stop(struct Scsi_Host
*host
, struct scsi_pointer
*SCp
)
287 struct cumanascsi2_info
*info
= (struct cumanascsi2_info
*)host
->hostdata
;
288 if (info
->info
.scsi
.dma
!= NO_DMA
) {
289 writeb(ALATCH_DIS_DMA
, info
->base
+ CUMANASCSI2_ALATCH
);
290 disable_dma(info
->info
.scsi
.dma
);
294 /* Prototype: const char *cumanascsi_2_info(struct Scsi_Host * host)
295 * Purpose : returns a descriptive string about this interface,
296 * Params : host - driver host structure to return info for.
297 * Returns : pointer to a static buffer containing null terminated string.
299 const char *cumanascsi_2_info(struct Scsi_Host
*host
)
301 struct cumanascsi2_info
*info
= (struct cumanascsi2_info
*)host
->hostdata
;
302 static char string
[150];
304 sprintf(string
, "%s (%s) in slot %d v%s terminators o%s",
305 host
->hostt
->name
, info
->info
.scsi
.type
, info
->ec
->slot_no
,
306 VERSION
, info
->terms
? "n" : "ff");
311 /* Prototype: int cumanascsi_2_set_proc_info(struct Scsi_Host *host, char *buffer, int length)
312 * Purpose : Set a driver specific function
313 * Params : host - host to setup
314 * : buffer - buffer containing string describing operation
315 * : length - length of string
316 * Returns : -EINVAL, or 0
319 cumanascsi_2_set_proc_info(struct Scsi_Host
*host
, char *buffer
, int length
)
323 if (length
>= 11 && strcmp(buffer
, "CUMANASCSI2") == 0) {
327 if (length
>= 5 && strncmp(buffer
, "term=", 5) == 0) {
328 if (buffer
[5] == '1')
329 cumanascsi_2_terminator_ctl(host
, 1);
330 else if (buffer
[5] == '0')
331 cumanascsi_2_terminator_ctl(host
, 0);
342 /* Prototype: int cumanascsi_2_proc_info(char *buffer, char **start, off_t offset,
343 * int length, int host_no, int inout)
344 * Purpose : Return information about the driver to a user process accessing
345 * the /proc filesystem.
346 * Params : buffer - a buffer to write information to
347 * start - a pointer into this buffer set by this routine to the start
348 * of the required information.
349 * offset - offset into information that we have read upto.
350 * length - length of buffer
351 * host_no - host number to return information for
352 * inout - 0 for reading, 1 for writing.
353 * Returns : length of data written to buffer.
355 int cumanascsi_2_proc_info (struct Scsi_Host
*host
, char *buffer
, char **start
, off_t offset
,
356 int length
, int inout
)
358 struct cumanascsi2_info
*info
;
363 return cumanascsi_2_set_proc_info(host
, buffer
, length
);
365 info
= (struct cumanascsi2_info
*)host
->hostdata
;
367 p
+= sprintf(p
, "Cumana SCSI II driver v%s\n", VERSION
);
368 p
+= fas216_print_host(&info
->info
, p
);
369 p
+= sprintf(p
, "Term : o%s\n",
370 info
->terms
? "n" : "ff");
372 p
+= fas216_print_stats(&info
->info
, p
);
373 p
+= fas216_print_devices(&info
->info
, p
);
375 *start
= buffer
+ offset
;
376 pos
= p
- buffer
- offset
;
383 static struct scsi_host_template cumanascsi2_template
= {
384 .module
= THIS_MODULE
,
385 .proc_info
= cumanascsi_2_proc_info
,
386 .name
= "Cumana SCSI II",
387 .info
= cumanascsi_2_info
,
388 .queuecommand
= fas216_queue_command
,
389 .eh_host_reset_handler
= fas216_eh_host_reset
,
390 .eh_bus_reset_handler
= fas216_eh_bus_reset
,
391 .eh_device_reset_handler
= fas216_eh_device_reset
,
392 .eh_abort_handler
= fas216_eh_abort
,
395 .sg_tablesize
= SG_ALL
,
397 .use_clustering
= DISABLE_CLUSTERING
,
398 .proc_name
= "cumanascsi2",
402 cumanascsi2_probe(struct expansion_card
*ec
, const struct ecard_id
*id
)
404 struct Scsi_Host
*host
;
405 struct cumanascsi2_info
*info
;
406 unsigned long resbase
, reslen
;
410 ret
= ecard_request_resources(ec
);
414 resbase
= ecard_resource_start(ec
, ECARD_RES_MEMC
);
415 reslen
= ecard_resource_len(ec
, ECARD_RES_MEMC
);
416 base
= ioremap(resbase
, reslen
);
422 host
= scsi_host_alloc(&cumanascsi2_template
,
423 sizeof(struct cumanascsi2_info
));
429 ecard_set_drvdata(ec
, host
);
431 info
= (struct cumanascsi2_info
*)host
->hostdata
;
435 cumanascsi_2_terminator_ctl(host
, term
[ec
->slot_no
]);
437 info
->info
.scsi
.io_base
= base
+ CUMANASCSI2_FAS216_OFFSET
;
438 info
->info
.scsi
.io_shift
= CUMANASCSI2_FAS216_SHIFT
;
439 info
->info
.scsi
.irq
= ec
->irq
;
440 info
->info
.scsi
.dma
= ec
->dma
;
441 info
->info
.ifcfg
.clockrate
= 40; /* MHz */
442 info
->info
.ifcfg
.select_timeout
= 255;
443 info
->info
.ifcfg
.asyncperiod
= 200; /* ns */
444 info
->info
.ifcfg
.sync_max_depth
= 7;
445 info
->info
.ifcfg
.cntl3
= CNTL3_BS8
| CNTL3_FASTSCSI
| CNTL3_FASTCLK
;
446 info
->info
.ifcfg
.disconnect_ok
= 1;
447 info
->info
.ifcfg
.wide_max_size
= 0;
448 info
->info
.ifcfg
.capabilities
= FASCAP_PSEUDODMA
;
449 info
->info
.dma
.setup
= cumanascsi_2_dma_setup
;
450 info
->info
.dma
.pseudo
= cumanascsi_2_dma_pseudo
;
451 info
->info
.dma
.stop
= cumanascsi_2_dma_stop
;
453 ec
->irqaddr
= info
->base
+ CUMANASCSI2_STATUS
;
454 ec
->irqmask
= STATUS_INT
;
456 ec
->ops
= &cumanascsi_2_ops
;
458 ret
= fas216_init(host
);
462 ret
= request_irq(ec
->irq
, cumanascsi_2_intr
,
463 SA_INTERRUPT
, "cumanascsi2", info
);
465 printk("scsi%d: IRQ%d not free: %d\n",
466 host
->host_no
, ec
->irq
, ret
);
470 if (info
->info
.scsi
.dma
!= NO_DMA
) {
471 if (request_dma(info
->info
.scsi
.dma
, "cumanascsi2")) {
472 printk("scsi%d: DMA%d not free, using PIO\n",
473 host
->host_no
, info
->info
.scsi
.dma
);
474 info
->info
.scsi
.dma
= NO_DMA
;
476 set_dma_speed(info
->info
.scsi
.dma
, 180);
477 info
->info
.ifcfg
.capabilities
|= FASCAP_DMA
;
481 ret
= fas216_add(host
, &ec
->dev
);
485 if (info
->info
.scsi
.dma
!= NO_DMA
)
486 free_dma(info
->info
.scsi
.dma
);
487 free_irq(ec
->irq
, host
);
490 fas216_release(host
);
499 ecard_release_resources(ec
);
505 static void __devexit
cumanascsi2_remove(struct expansion_card
*ec
)
507 struct Scsi_Host
*host
= ecard_get_drvdata(ec
);
508 struct cumanascsi2_info
*info
= (struct cumanascsi2_info
*)host
->hostdata
;
510 ecard_set_drvdata(ec
, NULL
);
513 if (info
->info
.scsi
.dma
!= NO_DMA
)
514 free_dma(info
->info
.scsi
.dma
);
515 free_irq(ec
->irq
, info
);
519 fas216_release(host
);
521 ecard_release_resources(ec
);
524 static const struct ecard_id cumanascsi2_cids
[] = {
525 { MANU_CUMANA
, PROD_CUMANA_SCSI_2
},
529 static struct ecard_driver cumanascsi2_driver
= {
530 .probe
= cumanascsi2_probe
,
531 .remove
= __devexit_p(cumanascsi2_remove
),
532 .id_table
= cumanascsi2_cids
,
534 .name
= "cumanascsi2",
538 static int __init
cumanascsi2_init(void)
540 return ecard_register_driver(&cumanascsi2_driver
);
543 static void __exit
cumanascsi2_exit(void)
545 ecard_remove_driver(&cumanascsi2_driver
);
548 module_init(cumanascsi2_init
);
549 module_exit(cumanascsi2_exit
);
551 MODULE_AUTHOR("Russell King");
552 MODULE_DESCRIPTION("Cumana SCSI-2 driver for Acorn machines");
553 MODULE_PARM(term
, "1-8i");
554 MODULE_PARM_DESC(term
, "SCSI bus termination");
555 MODULE_LICENSE("GPL");