[TG3]: Set minimal hw interrupt mitigation.
[linux-2.6/verdex.git] / drivers / scsi / arm / cumana_1.c
blob27271bfc01d70a63ef5d288ae65c34bbf45b27b9
1 /*
2 * Generic Generic NCR5380 driver
4 * Copyright 1995-2002, Russell King
5 */
6 #include <linux/module.h>
7 #include <linux/signal.h>
8 #include <linux/sched.h>
9 #include <linux/ioport.h>
10 #include <linux/delay.h>
11 #include <linux/blkdev.h>
12 #include <linux/init.h>
14 #include <asm/ecard.h>
15 #include <asm/io.h>
16 #include <asm/irq.h>
17 #include <asm/system.h>
19 #include "../scsi.h"
20 #include <scsi/scsi_host.h>
22 #include <scsi/scsicam.h>
24 #define AUTOSENSE
25 #define PSEUDO_DMA
27 #define CUMANASCSI_PUBLIC_RELEASE 1
29 #define NCR5380_implementation_fields int port, ctrl
30 #define NCR5380_local_declare() struct Scsi_Host *_instance
31 #define NCR5380_setup(instance) _instance = instance
32 #define NCR5380_read(reg) cumanascsi_read(_instance, reg)
33 #define NCR5380_write(reg, value) cumanascsi_write(_instance, reg, value)
34 #define NCR5380_intr cumanascsi_intr
35 #define NCR5380_queue_command cumanascsi_queue_command
36 #define NCR5380_proc_info cumanascsi_proc_info
38 #define BOARD_NORMAL 0
39 #define BOARD_NCR53C400 1
41 #include "../NCR5380.h"
43 void cumanascsi_setup(char *str, int *ints)
47 const char *cumanascsi_info(struct Scsi_Host *spnt)
49 return "";
52 #ifdef NOT_EFFICIENT
53 #define CTRL(p,v) outb(*ctrl = (v), (p) - 577)
54 #define STAT(p) inb((p)+1)
55 #define IN(p) inb((p))
56 #define OUT(v,p) outb((v), (p))
57 #else
58 #define CTRL(p,v) (p[-2308] = (*ctrl = (v)))
59 #define STAT(p) (p[4])
60 #define IN(p) (*(p))
61 #define IN2(p) ((unsigned short)(*(volatile unsigned long *)(p)))
62 #define OUT(v,p) (*(p) = (v))
63 #define OUT2(v,p) (*((volatile unsigned long *)(p)) = (v))
64 #endif
65 #define L(v) (((v)<<16)|((v) & 0x0000ffff))
66 #define H(v) (((v)>>16)|((v) & 0xffff0000))
68 static inline int
69 NCR5380_pwrite(struct Scsi_Host *instance, unsigned char *addr, int len)
71 int *ctrl = &((struct NCR5380_hostdata *)instance->hostdata)->ctrl;
72 int oldctrl = *ctrl;
73 unsigned long *laddr;
74 #ifdef NOT_EFFICIENT
75 int iobase = instance->io_port;
76 int dma_io = iobase & ~(0x3C0000>>2);
77 #else
78 volatile unsigned char *iobase = (unsigned char *)ioaddr(instance->io_port);
79 volatile unsigned char *dma_io = (unsigned char *)((int)iobase & ~0x3C0000);
80 #endif
82 if(!len) return 0;
84 CTRL(iobase, 0x02);
85 laddr = (unsigned long *)addr;
86 while(len >= 32)
88 int status;
89 unsigned long v;
90 status = STAT(iobase);
91 if(status & 0x80)
92 goto end;
93 if(!(status & 0x40))
94 continue;
95 v=*laddr++; OUT2(L(v),dma_io); OUT2(H(v),dma_io);
96 v=*laddr++; OUT2(L(v),dma_io); OUT2(H(v),dma_io);
97 v=*laddr++; OUT2(L(v),dma_io); OUT2(H(v),dma_io);
98 v=*laddr++; OUT2(L(v),dma_io); OUT2(H(v),dma_io);
99 v=*laddr++; OUT2(L(v),dma_io); OUT2(H(v),dma_io);
100 v=*laddr++; OUT2(L(v),dma_io); OUT2(H(v),dma_io);
101 v=*laddr++; OUT2(L(v),dma_io); OUT2(H(v),dma_io);
102 v=*laddr++; OUT2(L(v),dma_io); OUT2(H(v),dma_io);
103 len -= 32;
104 if(len == 0)
105 break;
108 addr = (unsigned char *)laddr;
109 CTRL(iobase, 0x12);
110 while(len > 0)
112 int status;
113 status = STAT(iobase);
114 if(status & 0x80)
115 goto end;
116 if(status & 0x40)
118 OUT(*addr++, dma_io);
119 if(--len == 0)
120 break;
123 status = STAT(iobase);
124 if(status & 0x80)
125 goto end;
126 if(status & 0x40)
128 OUT(*addr++, dma_io);
129 if(--len == 0)
130 break;
133 end:
134 CTRL(iobase, oldctrl|0x40);
135 return len;
138 static inline int
139 NCR5380_pread(struct Scsi_Host *instance, unsigned char *addr, int len)
141 int *ctrl = &((struct NCR5380_hostdata *)instance->hostdata)->ctrl;
142 int oldctrl = *ctrl;
143 unsigned long *laddr;
144 #ifdef NOT_EFFICIENT
145 int iobase = instance->io_port;
146 int dma_io = iobase & ~(0x3C0000>>2);
147 #else
148 volatile unsigned char *iobase = (unsigned char *)ioaddr(instance->io_port);
149 volatile unsigned char *dma_io = (unsigned char *)((int)iobase & ~0x3C0000);
150 #endif
152 if(!len) return 0;
154 CTRL(iobase, 0x00);
155 laddr = (unsigned long *)addr;
156 while(len >= 32)
158 int status;
159 status = STAT(iobase);
160 if(status & 0x80)
161 goto end;
162 if(!(status & 0x40))
163 continue;
164 *laddr++ = IN2(dma_io)|(IN2(dma_io)<<16);
165 *laddr++ = IN2(dma_io)|(IN2(dma_io)<<16);
166 *laddr++ = IN2(dma_io)|(IN2(dma_io)<<16);
167 *laddr++ = IN2(dma_io)|(IN2(dma_io)<<16);
168 *laddr++ = IN2(dma_io)|(IN2(dma_io)<<16);
169 *laddr++ = IN2(dma_io)|(IN2(dma_io)<<16);
170 *laddr++ = IN2(dma_io)|(IN2(dma_io)<<16);
171 *laddr++ = IN2(dma_io)|(IN2(dma_io)<<16);
172 len -= 32;
173 if(len == 0)
174 break;
177 addr = (unsigned char *)laddr;
178 CTRL(iobase, 0x10);
179 while(len > 0)
181 int status;
182 status = STAT(iobase);
183 if(status & 0x80)
184 goto end;
185 if(status & 0x40)
187 *addr++ = IN(dma_io);
188 if(--len == 0)
189 break;
192 status = STAT(iobase);
193 if(status & 0x80)
194 goto end;
195 if(status & 0x40)
197 *addr++ = IN(dma_io);
198 if(--len == 0)
199 break;
202 end:
203 CTRL(iobase, oldctrl|0x40);
204 return len;
207 #undef STAT
208 #undef CTRL
209 #undef IN
210 #undef OUT
212 #define CTRL(p,v) outb(*ctrl = (v), (p) - 577)
214 static char cumanascsi_read(struct Scsi_Host *instance, int reg)
216 unsigned int iobase = instance->io_port;
217 int i;
218 int *ctrl = &((struct NCR5380_hostdata *)instance->hostdata)->ctrl;
220 CTRL(iobase, 0);
221 i = inb(iobase + 64 + reg);
222 CTRL(iobase, 0x40);
224 return i;
227 static void cumanascsi_write(struct Scsi_Host *instance, int reg, int value)
229 int iobase = instance->io_port;
230 int *ctrl = &((struct NCR5380_hostdata *)instance->hostdata)->ctrl;
232 CTRL(iobase, 0);
233 outb(value, iobase + 64 + reg);
234 CTRL(iobase, 0x40);
237 #undef CTRL
239 #include "../NCR5380.c"
241 static Scsi_Host_Template cumanascsi_template = {
242 .module = THIS_MODULE,
243 .name = "Cumana 16-bit SCSI",
244 .info = cumanascsi_info,
245 .queuecommand = cumanascsi_queue_command,
246 .eh_abort_handler = NCR5380_abort,
247 .eh_device_reset_handler= NCR5380_device_reset,
248 .eh_bus_reset_handler = NCR5380_bus_reset,
249 .eh_host_reset_handler = NCR5380_host_reset,
250 .can_queue = 16,
251 .this_id = 7,
252 .sg_tablesize = SG_ALL,
253 .cmd_per_lun = 2,
254 .unchecked_isa_dma = 0,
255 .use_clustering = DISABLE_CLUSTERING,
256 .proc_name = "CumanaSCSI-1",
259 static int __devinit
260 cumanascsi1_probe(struct expansion_card *ec, const struct ecard_id *id)
262 struct Scsi_Host *host;
263 int ret = -ENOMEM;
265 host = scsi_host_alloc(&cumanascsi_template, sizeof(struct NCR5380_hostdata));
266 if (!host)
267 goto out;
269 host->io_port = ecard_address(ec, ECARD_IOC, ECARD_SLOW) + 0x800;
270 host->irq = ec->irq;
272 NCR5380_init(host, 0);
274 host->n_io_port = 255;
275 if (!(request_region(host->io_port, host->n_io_port, "CumanaSCSI-1"))) {
276 ret = -EBUSY;
277 goto out_free;
280 ((struct NCR5380_hostdata *)host->hostdata)->ctrl = 0;
281 outb(0x00, host->io_port - 577);
283 ret = request_irq(host->irq, cumanascsi_intr, SA_INTERRUPT,
284 "CumanaSCSI-1", host);
285 if (ret) {
286 printk("scsi%d: IRQ%d not free: %d\n",
287 host->host_no, host->irq, ret);
288 goto out_release;
291 printk("scsi%d: at port 0x%08lx irq %d",
292 host->host_no, host->io_port, host->irq);
293 printk(" options CAN_QUEUE=%d CMD_PER_LUN=%d release=%d",
294 host->can_queue, host->cmd_per_lun, CUMANASCSI_PUBLIC_RELEASE);
295 printk("\nscsi%d:", host->host_no);
296 NCR5380_print_options(host);
297 printk("\n");
299 ret = scsi_add_host(host, &ec->dev);
300 if (ret)
301 goto out_free_irq;
303 scsi_scan_host(host);
304 goto out;
306 out_free_irq:
307 free_irq(host->irq, host);
308 out_release:
309 release_region(host->io_port, host->n_io_port);
310 out_free:
311 scsi_host_put(host);
312 out:
313 return ret;
316 static void __devexit cumanascsi1_remove(struct expansion_card *ec)
318 struct Scsi_Host *host = ecard_get_drvdata(ec);
320 ecard_set_drvdata(ec, NULL);
322 scsi_remove_host(host);
323 free_irq(host->irq, host);
324 NCR5380_exit(host);
325 release_region(host->io_port, host->n_io_port);
326 scsi_host_put(host);
329 static const struct ecard_id cumanascsi1_cids[] = {
330 { MANU_CUMANA, PROD_CUMANA_SCSI_1 },
331 { 0xffff, 0xffff }
334 static struct ecard_driver cumanascsi1_driver = {
335 .probe = cumanascsi1_probe,
336 .remove = __devexit_p(cumanascsi1_remove),
337 .id_table = cumanascsi1_cids,
338 .drv = {
339 .name = "cumanascsi1",
343 static int __init cumanascsi_init(void)
345 return ecard_register_driver(&cumanascsi1_driver);
348 static void __exit cumanascsi_exit(void)
350 ecard_remove_driver(&cumanascsi1_driver);
353 module_init(cumanascsi_init);
354 module_exit(cumanascsi_exit);
356 MODULE_DESCRIPTION("Cumana SCSI-1 driver for Acorn machines");
357 MODULE_LICENSE("GPL");