[SCSI] Remove no-op implementations of SCSI EH hooks
[pandora-kernel.git] / drivers / scsi / arm / cumana_1.c
1 /*
2  * Generic Generic NCR5380 driver
3  *
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>
13
14 #include <asm/ecard.h>
15 #include <asm/io.h>
16 #include <asm/irq.h>
17 #include <asm/system.h>
18
19 #include "../scsi.h"
20 #include <scsi/scsi_host.h>
21
22 #include <scsi/scsicam.h>
23
24 #define AUTOSENSE
25 #define PSEUDO_DMA
26
27 #define CUMANASCSI_PUBLIC_RELEASE 1
28
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
37
38 #define BOARD_NORMAL    0
39 #define BOARD_NCR53C400 1
40
41 #include "../NCR5380.h"
42
43 void cumanascsi_setup(char *str, int *ints)
44 {
45 }
46
47 const char *cumanascsi_info(struct Scsi_Host *spnt)
48 {
49         return "";
50 }
51
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))
67
68 static inline int
69 NCR5380_pwrite(struct Scsi_Host *instance, unsigned char *addr, int len)
70 {
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
81
82   if(!len) return 0;
83
84   CTRL(iobase, 0x02);
85   laddr = (unsigned long *)addr;
86   while(len >= 32)
87   {
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;
106   }
107
108   addr = (unsigned char *)laddr;
109   CTRL(iobase, 0x12);
110   while(len > 0)
111   {
112     int status;
113     status = STAT(iobase);
114     if(status & 0x80)
115       goto end;
116     if(status & 0x40)
117     {
118       OUT(*addr++, dma_io);
119       if(--len == 0)
120         break;
121     }
122
123     status = STAT(iobase);
124     if(status & 0x80)
125       goto end;
126     if(status & 0x40)
127     {
128       OUT(*addr++, dma_io);
129       if(--len == 0)
130         break;
131     }
132   }
133 end:
134   CTRL(iobase, oldctrl|0x40);
135   return len;
136 }
137
138 static inline int
139 NCR5380_pread(struct Scsi_Host *instance, unsigned char *addr, int len)
140 {
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
151
152   if(!len) return 0;
153
154   CTRL(iobase, 0x00);
155   laddr = (unsigned long *)addr;
156   while(len >= 32)
157   {
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;
175   }
176
177   addr = (unsigned char *)laddr;
178   CTRL(iobase, 0x10);
179   while(len > 0)
180   {
181     int status;
182     status = STAT(iobase);
183     if(status & 0x80)
184       goto end;
185     if(status & 0x40)
186     {
187       *addr++ = IN(dma_io);
188       if(--len == 0)
189         break;
190     }
191
192     status = STAT(iobase);
193     if(status & 0x80)
194       goto end;
195     if(status & 0x40)
196     {
197       *addr++ = IN(dma_io);
198       if(--len == 0)
199         break;
200     }
201   }
202 end:
203   CTRL(iobase, oldctrl|0x40);
204   return len;
205 }
206
207 #undef STAT
208 #undef CTRL
209 #undef IN
210 #undef OUT
211
212 #define CTRL(p,v) outb(*ctrl = (v), (p) - 577)
213
214 static char cumanascsi_read(struct Scsi_Host *instance, int reg)
215 {
216         unsigned int iobase = instance->io_port;
217         int i;
218         int *ctrl = &((struct NCR5380_hostdata *)instance->hostdata)->ctrl;
219
220         CTRL(iobase, 0);
221         i = inb(iobase + 64 + reg);
222         CTRL(iobase, 0x40);
223
224         return i;
225 }
226
227 static void cumanascsi_write(struct Scsi_Host *instance, int reg, int value)
228 {
229         int iobase = instance->io_port;
230         int *ctrl = &((struct NCR5380_hostdata *)instance->hostdata)->ctrl;
231
232         CTRL(iobase, 0);
233         outb(value, iobase + 64 + reg);
234         CTRL(iobase, 0x40);
235 }
236
237 #undef CTRL
238
239 #include "../NCR5380.c"
240
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_bus_reset_handler   = NCR5380_bus_reset,
248         .can_queue              = 16,
249         .this_id                = 7,
250         .sg_tablesize           = SG_ALL,
251         .cmd_per_lun            = 2,
252         .unchecked_isa_dma      = 0,
253         .use_clustering         = DISABLE_CLUSTERING,
254         .proc_name              = "CumanaSCSI-1",
255 };
256
257 static int __devinit
258 cumanascsi1_probe(struct expansion_card *ec, const struct ecard_id *id)
259 {
260         struct Scsi_Host *host;
261         int ret = -ENOMEM;
262
263         host = scsi_host_alloc(&cumanascsi_template, sizeof(struct NCR5380_hostdata));
264         if (!host)
265                 goto out;
266
267         host->io_port = ecard_address(ec, ECARD_IOC, ECARD_SLOW) + 0x800;
268         host->irq = ec->irq;
269
270         NCR5380_init(host, 0);
271
272         host->n_io_port = 255;
273         if (!(request_region(host->io_port, host->n_io_port, "CumanaSCSI-1"))) {
274                 ret = -EBUSY;
275                 goto out_free;
276         }
277
278         ((struct NCR5380_hostdata *)host->hostdata)->ctrl = 0;
279         outb(0x00, host->io_port - 577);
280
281         ret = request_irq(host->irq, cumanascsi_intr, SA_INTERRUPT,
282                           "CumanaSCSI-1", host);
283         if (ret) {
284                 printk("scsi%d: IRQ%d not free: %d\n",
285                     host->host_no, host->irq, ret);
286                 goto out_release;
287         }
288
289         printk("scsi%d: at port 0x%08lx irq %d",
290                 host->host_no, host->io_port, host->irq);
291         printk(" options CAN_QUEUE=%d CMD_PER_LUN=%d release=%d",
292                 host->can_queue, host->cmd_per_lun, CUMANASCSI_PUBLIC_RELEASE);
293         printk("\nscsi%d:", host->host_no);
294         NCR5380_print_options(host);
295         printk("\n");
296
297         ret = scsi_add_host(host, &ec->dev);
298         if (ret)
299                 goto out_free_irq;
300
301         scsi_scan_host(host);
302         goto out;
303
304  out_free_irq:
305         free_irq(host->irq, host);
306  out_release:
307         release_region(host->io_port, host->n_io_port);
308  out_free:
309         scsi_host_put(host);
310  out:
311         return ret;
312 }
313
314 static void __devexit cumanascsi1_remove(struct expansion_card *ec)
315 {
316         struct Scsi_Host *host = ecard_get_drvdata(ec);
317
318         ecard_set_drvdata(ec, NULL);
319
320         scsi_remove_host(host);
321         free_irq(host->irq, host);
322         NCR5380_exit(host);
323         release_region(host->io_port, host->n_io_port);
324         scsi_host_put(host);
325 }
326
327 static const struct ecard_id cumanascsi1_cids[] = {
328         { MANU_CUMANA, PROD_CUMANA_SCSI_1 },
329         { 0xffff, 0xffff }
330 };
331
332 static struct ecard_driver cumanascsi1_driver = {
333         .probe          = cumanascsi1_probe,
334         .remove         = __devexit_p(cumanascsi1_remove),
335         .id_table       = cumanascsi1_cids,
336         .drv = {
337                 .name           = "cumanascsi1",
338         },
339 };
340
341 static int __init cumanascsi_init(void)
342 {
343         return ecard_register_driver(&cumanascsi1_driver);
344 }
345
346 static void __exit cumanascsi_exit(void)
347 {
348         ecard_remove_driver(&cumanascsi1_driver);
349 }
350
351 module_init(cumanascsi_init);
352 module_exit(cumanascsi_exit);
353
354 MODULE_DESCRIPTION("Cumana SCSI-1 driver for Acorn machines");
355 MODULE_LICENSE("GPL");