[NETFILTER]: Fix IP_NF_CONNTRACK_NETLINK dependency
[hh.org.git] / drivers / scsi / a3000.c
blobf425d424bf08714e739a8457f3a94be5237bafcc
1 #include <linux/types.h>
2 #include <linux/mm.h>
3 #include <linux/blkdev.h>
4 #include <linux/sched.h>
5 #include <linux/ioport.h>
6 #include <linux/init.h>
7 #include <linux/spinlock.h>
8 #include <linux/interrupt.h>
10 #include <asm/setup.h>
11 #include <asm/page.h>
12 #include <asm/pgtable.h>
13 #include <asm/amigaints.h>
14 #include <asm/amigahw.h>
15 #include <asm/irq.h>
17 #include "scsi.h"
18 #include <scsi/scsi_host.h>
19 #include "wd33c93.h"
20 #include "a3000.h"
22 #include<linux/stat.h>
24 #define DMA(ptr) ((a3000_scsiregs *)((ptr)->base))
25 #define HDATA(ptr) ((struct WD33C93_hostdata *)((ptr)->hostdata))
27 static struct Scsi_Host *a3000_host = NULL;
29 static irqreturn_t a3000_intr (int irq, void *dummy, struct pt_regs *fp)
31 unsigned long flags;
32 unsigned int status = DMA(a3000_host)->ISTR;
34 if (!(status & ISTR_INT_P))
35 return IRQ_NONE;
36 if (status & ISTR_INTS)
38 spin_lock_irqsave(a3000_host->host_lock, flags);
39 wd33c93_intr (a3000_host);
40 spin_unlock_irqrestore(a3000_host->host_lock, flags);
41 return IRQ_HANDLED;
43 printk("Non-serviced A3000 SCSI-interrupt? ISTR = %02x\n", status);
44 return IRQ_NONE;
47 static int dma_setup (Scsi_Cmnd *cmd, int dir_in)
49 unsigned short cntr = CNTR_PDMD | CNTR_INTEN;
50 unsigned long addr = virt_to_bus(cmd->SCp.ptr);
53 * if the physical address has the wrong alignment, or if
54 * physical address is bad, or if it is a write and at the
55 * end of a physical memory chunk, then allocate a bounce
56 * buffer
58 if (addr & A3000_XFER_MASK ||
59 (!dir_in && mm_end_of_chunk (addr, cmd->SCp.this_residual)))
61 HDATA(a3000_host)->dma_bounce_len = (cmd->SCp.this_residual + 511)
62 & ~0x1ff;
63 HDATA(a3000_host)->dma_bounce_buffer =
64 kmalloc (HDATA(a3000_host)->dma_bounce_len, GFP_KERNEL);
66 /* can't allocate memory; use PIO */
67 if (!HDATA(a3000_host)->dma_bounce_buffer) {
68 HDATA(a3000_host)->dma_bounce_len = 0;
69 return 1;
72 if (!dir_in) {
73 /* copy to bounce buffer for a write */
74 if (cmd->use_sg) {
75 memcpy (HDATA(a3000_host)->dma_bounce_buffer,
76 cmd->SCp.ptr, cmd->SCp.this_residual);
77 } else
78 memcpy (HDATA(a3000_host)->dma_bounce_buffer,
79 cmd->request_buffer, cmd->request_bufflen);
82 addr = virt_to_bus(HDATA(a3000_host)->dma_bounce_buffer);
85 /* setup dma direction */
86 if (!dir_in)
87 cntr |= CNTR_DDIR;
89 /* remember direction */
90 HDATA(a3000_host)->dma_dir = dir_in;
92 DMA(a3000_host)->CNTR = cntr;
94 /* setup DMA *physical* address */
95 DMA(a3000_host)->ACR = addr;
97 if (dir_in)
98 /* invalidate any cache */
99 cache_clear (addr, cmd->SCp.this_residual);
100 else
101 /* push any dirty cache */
102 cache_push (addr, cmd->SCp.this_residual);
104 /* start DMA */
105 mb(); /* make sure setup is completed */
106 DMA(a3000_host)->ST_DMA = 1;
107 mb(); /* make sure DMA has started before next IO */
109 /* return success */
110 return 0;
113 static void dma_stop (struct Scsi_Host *instance, Scsi_Cmnd *SCpnt,
114 int status)
116 /* disable SCSI interrupts */
117 unsigned short cntr = CNTR_PDMD;
119 if (!HDATA(instance)->dma_dir)
120 cntr |= CNTR_DDIR;
122 DMA(instance)->CNTR = cntr;
123 mb(); /* make sure CNTR is updated before next IO */
125 /* flush if we were reading */
126 if (HDATA(instance)->dma_dir) {
127 DMA(instance)->FLUSH = 1;
128 mb(); /* don't allow prefetch */
129 while (!(DMA(instance)->ISTR & ISTR_FE_FLG))
130 barrier();
131 mb(); /* no IO until FLUSH is done */
134 /* clear a possible interrupt */
135 /* I think that this CINT is only necessary if you are
136 * using the terminal count features. HM 7 Mar 1994
138 DMA(instance)->CINT = 1;
140 /* stop DMA */
141 DMA(instance)->SP_DMA = 1;
142 mb(); /* make sure DMA is stopped before next IO */
144 /* restore the CONTROL bits (minus the direction flag) */
145 DMA(instance)->CNTR = CNTR_PDMD | CNTR_INTEN;
146 mb(); /* make sure CNTR is updated before next IO */
148 /* copy from a bounce buffer, if necessary */
149 if (status && HDATA(instance)->dma_bounce_buffer) {
150 if (SCpnt && SCpnt->use_sg) {
151 if (HDATA(instance)->dma_dir && SCpnt)
152 memcpy (SCpnt->SCp.ptr,
153 HDATA(instance)->dma_bounce_buffer,
154 SCpnt->SCp.this_residual);
155 kfree (HDATA(instance)->dma_bounce_buffer);
156 HDATA(instance)->dma_bounce_buffer = NULL;
157 HDATA(instance)->dma_bounce_len = 0;
158 } else {
159 if (HDATA(instance)->dma_dir && SCpnt)
160 memcpy (SCpnt->request_buffer,
161 HDATA(instance)->dma_bounce_buffer,
162 SCpnt->request_bufflen);
164 kfree (HDATA(instance)->dma_bounce_buffer);
165 HDATA(instance)->dma_bounce_buffer = NULL;
166 HDATA(instance)->dma_bounce_len = 0;
171 int __init a3000_detect(struct scsi_host_template *tpnt)
173 wd33c93_regs regs;
175 if (!MACH_IS_AMIGA || !AMIGAHW_PRESENT(A3000_SCSI))
176 return 0;
177 if (!request_mem_region(0xDD0000, 256, "wd33c93"))
178 return 0;
180 tpnt->proc_name = "A3000";
181 tpnt->proc_info = &wd33c93_proc_info;
183 a3000_host = scsi_register (tpnt, sizeof(struct WD33C93_hostdata));
184 if (a3000_host == NULL)
185 goto fail_register;
187 a3000_host->base = ZTWO_VADDR(0xDD0000);
188 a3000_host->irq = IRQ_AMIGA_PORTS;
189 DMA(a3000_host)->DAWR = DAWR_A3000;
190 regs.SASR = &(DMA(a3000_host)->SASR);
191 regs.SCMD = &(DMA(a3000_host)->SCMD);
192 wd33c93_init(a3000_host, regs, dma_setup, dma_stop, WD33C93_FS_12_15);
193 if (request_irq(IRQ_AMIGA_PORTS, a3000_intr, SA_SHIRQ, "A3000 SCSI",
194 a3000_intr))
195 goto fail_irq;
196 DMA(a3000_host)->CNTR = CNTR_PDMD | CNTR_INTEN;
198 return 1;
200 fail_irq:
201 wd33c93_release();
202 scsi_unregister(a3000_host);
203 fail_register:
204 release_mem_region(0xDD0000, 256);
205 return 0;
208 static int a3000_bus_reset(Scsi_Cmnd *cmd)
210 /* FIXME perform bus-specific reset */
212 /* FIXME 2: kill this entire function, which should
213 cause mid-layer to call wd33c93_host_reset anyway? */
215 spin_lock_irq(cmd->device->host->host_lock);
216 wd33c93_host_reset(cmd);
217 spin_unlock_irq(cmd->device->host->host_lock);
219 return SUCCESS;
222 #define HOSTS_C
224 static struct scsi_host_template driver_template = {
225 .proc_name = "A3000",
226 .name = "Amiga 3000 built-in SCSI",
227 .detect = a3000_detect,
228 .release = a3000_release,
229 .queuecommand = wd33c93_queuecommand,
230 .eh_abort_handler = wd33c93_abort,
231 .eh_bus_reset_handler = a3000_bus_reset,
232 .eh_host_reset_handler = wd33c93_host_reset,
233 .can_queue = CAN_QUEUE,
234 .this_id = 7,
235 .sg_tablesize = SG_ALL,
236 .cmd_per_lun = CMD_PER_LUN,
237 .use_clustering = ENABLE_CLUSTERING
241 #include "scsi_module.c"
243 int a3000_release(struct Scsi_Host *instance)
245 wd33c93_release();
246 DMA(instance)->CNTR = 0;
247 release_mem_region(0xDD0000, 256);
248 free_irq(IRQ_AMIGA_PORTS, a3000_intr);
249 return 1;
252 MODULE_LICENSE("GPL");