]>
Commit | Line | Data |
---|---|---|
1da177e4 LT |
1 | #include <linux/types.h> |
2 | #include <linux/mm.h> | |
5a0e3ad6 | 3 | #include <linux/slab.h> |
1da177e4 | 4 | #include <linux/blkdev.h> |
1da177e4 LT |
5 | #include <linux/init.h> |
6 | #include <linux/interrupt.h> | |
7 | ||
8 | #include <asm/setup.h> | |
9 | #include <asm/page.h> | |
10 | #include <asm/pgtable.h> | |
11 | #include <asm/amigaints.h> | |
12 | #include <asm/amigahw.h> | |
13 | #include <linux/zorro.h> | |
14 | #include <asm/irq.h> | |
15 | #include <linux/spinlock.h> | |
16 | ||
17 | #include "scsi.h" | |
18 | #include <scsi/scsi_host.h> | |
19 | #include "wd33c93.h" | |
20 | #include "a2091.h" | |
21 | ||
09bc85b0 | 22 | #include <linux/stat.h> |
1da177e4 | 23 | |
09bc85b0 | 24 | |
5880f486 AB |
25 | static int a2091_release(struct Scsi_Host *instance); |
26 | ||
b1de6ab7 | 27 | static irqreturn_t a2091_intr(int irq, void *data) |
1da177e4 | 28 | { |
b1de6ab7 | 29 | struct Scsi_Host *instance = data; |
56522e39 | 30 | struct a2091_scsiregs *regs = (struct a2091_scsiregs *)(instance->base); |
b1de6ab7 | 31 | unsigned int status = regs->ISTR; |
09bc85b0 | 32 | unsigned long flags; |
09bc85b0 | 33 | |
09bc85b0 GU |
34 | if (!(status & (ISTR_INT_F | ISTR_INT_P)) || !(status & ISTR_INTS)) |
35 | return IRQ_NONE; | |
36 | ||
37 | spin_lock_irqsave(instance->host_lock, flags); | |
38 | wd33c93_intr(instance); | |
39 | spin_unlock_irqrestore(instance->host_lock, flags); | |
40 | return IRQ_HANDLED; | |
1da177e4 LT |
41 | } |
42 | ||
65396410 | 43 | static int dma_setup(struct scsi_cmnd *cmd, int dir_in) |
1da177e4 | 44 | { |
6d1d5d43 GU |
45 | struct Scsi_Host *instance = cmd->device->host; |
46 | struct WD33C93_hostdata *hdata = shost_priv(instance); | |
56522e39 | 47 | struct a2091_scsiregs *regs = (struct a2091_scsiregs *)(instance->base); |
09bc85b0 GU |
48 | unsigned short cntr = CNTR_PDMD | CNTR_INTEN; |
49 | unsigned long addr = virt_to_bus(cmd->SCp.ptr); | |
1da177e4 | 50 | |
09bc85b0 | 51 | /* don't allow DMA if the physical address is bad */ |
1da177e4 | 52 | if (addr & A2091_XFER_MASK) { |
6d1d5d43 GU |
53 | hdata->dma_bounce_len = (cmd->SCp.this_residual + 511) & ~0x1ff; |
54 | hdata->dma_bounce_buffer = kmalloc(hdata->dma_bounce_len, | |
55 | GFP_KERNEL); | |
09bc85b0 GU |
56 | |
57 | /* can't allocate memory; use PIO */ | |
6d1d5d43 GU |
58 | if (!hdata->dma_bounce_buffer) { |
59 | hdata->dma_bounce_len = 0; | |
09bc85b0 GU |
60 | return 1; |
61 | } | |
62 | ||
63 | /* get the physical address of the bounce buffer */ | |
6d1d5d43 | 64 | addr = virt_to_bus(hdata->dma_bounce_buffer); |
09bc85b0 GU |
65 | |
66 | /* the bounce buffer may not be in the first 16M of physmem */ | |
67 | if (addr & A2091_XFER_MASK) { | |
68 | /* we could use chipmem... maybe later */ | |
6d1d5d43 GU |
69 | kfree(hdata->dma_bounce_buffer); |
70 | hdata->dma_bounce_buffer = NULL; | |
71 | hdata->dma_bounce_len = 0; | |
09bc85b0 GU |
72 | return 1; |
73 | } | |
74 | ||
75 | if (!dir_in) { | |
76 | /* copy to bounce buffer for a write */ | |
6d1d5d43 GU |
77 | memcpy(hdata->dma_bounce_buffer, cmd->SCp.ptr, |
78 | cmd->SCp.this_residual); | |
09bc85b0 | 79 | } |
1da177e4 | 80 | } |
1da177e4 | 81 | |
09bc85b0 GU |
82 | /* setup dma direction */ |
83 | if (!dir_in) | |
84 | cntr |= CNTR_DDIR; | |
1da177e4 | 85 | |
09bc85b0 | 86 | /* remember direction */ |
6d1d5d43 | 87 | hdata->dma_dir = dir_in; |
1da177e4 | 88 | |
b1de6ab7 | 89 | regs->CNTR = cntr; |
1da177e4 | 90 | |
09bc85b0 | 91 | /* setup DMA *physical* address */ |
b1de6ab7 | 92 | regs->ACR = addr; |
1da177e4 | 93 | |
09bc85b0 GU |
94 | if (dir_in) { |
95 | /* invalidate any cache */ | |
96 | cache_clear(addr, cmd->SCp.this_residual); | |
97 | } else { | |
98 | /* push any dirty cache */ | |
99 | cache_push(addr, cmd->SCp.this_residual); | |
100 | } | |
101 | /* start DMA */ | |
b1de6ab7 | 102 | regs->ST_DMA = 1; |
1da177e4 | 103 | |
09bc85b0 GU |
104 | /* return success */ |
105 | return 0; | |
1da177e4 LT |
106 | } |
107 | ||
65396410 | 108 | static void dma_stop(struct Scsi_Host *instance, struct scsi_cmnd *SCpnt, |
09bc85b0 | 109 | int status) |
1da177e4 | 110 | { |
6d1d5d43 | 111 | struct WD33C93_hostdata *hdata = shost_priv(instance); |
56522e39 | 112 | struct a2091_scsiregs *regs = (struct a2091_scsiregs *)(instance->base); |
6d1d5d43 | 113 | |
09bc85b0 GU |
114 | /* disable SCSI interrupts */ |
115 | unsigned short cntr = CNTR_PDMD; | |
116 | ||
6d1d5d43 | 117 | if (!hdata->dma_dir) |
09bc85b0 GU |
118 | cntr |= CNTR_DDIR; |
119 | ||
120 | /* disable SCSI interrupts */ | |
b1de6ab7 | 121 | regs->CNTR = cntr; |
09bc85b0 GU |
122 | |
123 | /* flush if we were reading */ | |
6d1d5d43 | 124 | if (hdata->dma_dir) { |
b1de6ab7 GU |
125 | regs->FLUSH = 1; |
126 | while (!(regs->ISTR & ISTR_FE_FLG)) | |
09bc85b0 GU |
127 | ; |
128 | } | |
129 | ||
130 | /* clear a possible interrupt */ | |
b1de6ab7 | 131 | regs->CINT = 1; |
09bc85b0 GU |
132 | |
133 | /* stop DMA */ | |
b1de6ab7 | 134 | regs->SP_DMA = 1; |
09bc85b0 GU |
135 | |
136 | /* restore the CONTROL bits (minus the direction flag) */ | |
b1de6ab7 | 137 | regs->CNTR = CNTR_PDMD | CNTR_INTEN; |
09bc85b0 GU |
138 | |
139 | /* copy from a bounce buffer, if necessary */ | |
6d1d5d43 GU |
140 | if (status && hdata->dma_bounce_buffer) { |
141 | if (hdata->dma_dir) | |
142 | memcpy(SCpnt->SCp.ptr, hdata->dma_bounce_buffer, | |
09bc85b0 | 143 | SCpnt->SCp.this_residual); |
6d1d5d43 GU |
144 | kfree(hdata->dma_bounce_buffer); |
145 | hdata->dma_bounce_buffer = NULL; | |
146 | hdata->dma_bounce_len = 0; | |
09bc85b0 | 147 | } |
1da177e4 LT |
148 | } |
149 | ||
5880f486 | 150 | static int __init a2091_detect(struct scsi_host_template *tpnt) |
1da177e4 | 151 | { |
09bc85b0 GU |
152 | static unsigned char called = 0; |
153 | struct Scsi_Host *instance; | |
154 | unsigned long address; | |
155 | struct zorro_dev *z = NULL; | |
b1de6ab7 | 156 | wd33c93_regs wdregs; |
56522e39 | 157 | struct a2091_scsiregs *regs; |
6d1d5d43 | 158 | struct WD33C93_hostdata *hdata; |
09bc85b0 GU |
159 | int num_a2091 = 0; |
160 | ||
161 | if (!MACH_IS_AMIGA || called) | |
162 | return 0; | |
163 | called = 1; | |
164 | ||
165 | tpnt->proc_name = "A2091"; | |
166 | tpnt->proc_info = &wd33c93_proc_info; | |
167 | ||
168 | while ((z = zorro_find_device(ZORRO_WILDCARD, z))) { | |
169 | if (z->id != ZORRO_PROD_CBM_A590_A2091_1 && | |
170 | z->id != ZORRO_PROD_CBM_A590_A2091_2) | |
171 | continue; | |
172 | address = z->resource.start; | |
173 | if (!request_mem_region(address, 256, "wd33c93")) | |
174 | continue; | |
175 | ||
176 | instance = scsi_register(tpnt, sizeof(struct WD33C93_hostdata)); | |
177 | if (instance == NULL) | |
178 | goto release; | |
179 | instance->base = ZTWO_VADDR(address); | |
180 | instance->irq = IRQ_AMIGA_PORTS; | |
181 | instance->unique_id = z->slotaddr; | |
56522e39 | 182 | regs = (struct a2091_scsiregs *)(instance->base); |
b1de6ab7 GU |
183 | regs->DAWR = DAWR_A2091; |
184 | wdregs.SASR = ®s->SASR; | |
185 | wdregs.SCMD = ®s->SCMD; | |
6d1d5d43 GU |
186 | hdata = shost_priv(instance); |
187 | hdata->no_sync = 0xff; | |
188 | hdata->fast = 0; | |
189 | hdata->dma_mode = CTRL_DMA; | |
b1de6ab7 | 190 | wd33c93_init(instance, wdregs, dma_setup, dma_stop, |
09bc85b0 GU |
191 | WD33C93_FS_8_10); |
192 | if (request_irq(IRQ_AMIGA_PORTS, a2091_intr, IRQF_SHARED, | |
193 | "A2091 SCSI", instance)) | |
194 | goto unregister; | |
b1de6ab7 | 195 | regs->CNTR = CNTR_PDMD | CNTR_INTEN; |
09bc85b0 GU |
196 | num_a2091++; |
197 | continue; | |
d38f47a9 GU |
198 | |
199 | unregister: | |
09bc85b0 | 200 | scsi_unregister(instance); |
d38f47a9 | 201 | release: |
09bc85b0 GU |
202 | release_mem_region(address, 256); |
203 | } | |
1da177e4 | 204 | |
09bc85b0 | 205 | return num_a2091; |
1da177e4 LT |
206 | } |
207 | ||
65396410 | 208 | static int a2091_bus_reset(struct scsi_cmnd *cmd) |
1da177e4 LT |
209 | { |
210 | /* FIXME perform bus-specific reset */ | |
68b3aa7c | 211 | |
df0ae249 JG |
212 | /* FIXME 2: kill this function, and let midlayer fall back |
213 | to the same action, calling wd33c93_host_reset() */ | |
214 | ||
68b3aa7c | 215 | spin_lock_irq(cmd->device->host->host_lock); |
1da177e4 | 216 | wd33c93_host_reset(cmd); |
68b3aa7c JG |
217 | spin_unlock_irq(cmd->device->host->host_lock); |
218 | ||
1da177e4 LT |
219 | return SUCCESS; |
220 | } | |
221 | ||
222 | #define HOSTS_C | |
223 | ||
d0be4a7d | 224 | static struct scsi_host_template driver_template = { |
1da177e4 LT |
225 | .proc_name = "A2901", |
226 | .name = "Commodore A2091/A590 SCSI", | |
227 | .detect = a2091_detect, | |
228 | .release = a2091_release, | |
229 | .queuecommand = wd33c93_queuecommand, | |
230 | .eh_abort_handler = wd33c93_abort, | |
231 | .eh_bus_reset_handler = a2091_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 = DISABLE_CLUSTERING | |
238 | }; | |
239 | ||
240 | ||
241 | #include "scsi_module.c" | |
242 | ||
5880f486 | 243 | static int a2091_release(struct Scsi_Host *instance) |
1da177e4 LT |
244 | { |
245 | #ifdef MODULE | |
56522e39 | 246 | struct a2091_scsiregs *regs = (struct a2091_scsiregs *)(instance->base); |
b1de6ab7 GU |
247 | |
248 | regs->CNTR = 0; | |
1da177e4 LT |
249 | release_mem_region(ZTWO_PADDR(instance->base), 256); |
250 | free_irq(IRQ_AMIGA_PORTS, instance); | |
1da177e4 LT |
251 | #endif |
252 | return 1; | |
253 | } | |
254 | ||
255 | MODULE_LICENSE("GPL"); |