1 #include <linux/types.h>
3 #include <linux/slab.h>
4 #include <linux/blkdev.h>
5 #include <linux/init.h>
6 #include <linux/interrupt.h>
10 #include <asm/pgtable.h>
11 #include <asm/amigaints.h>
12 #include <asm/amigahw.h>
13 #include <linux/zorro.h>
15 #include <linux/spinlock.h>
18 #include <scsi/scsi_host.h>
22 #include <linux/stat.h>
27 static irqreturn_t gvp11_intr(int irq, void *data)
29 struct Scsi_Host *instance = data;
30 struct gvp11_scsiregs *regs = (struct gvp11_scsiregs *)(instance->base);
31 unsigned int status = regs->CNTR;
34 if (!(status & GVP11_DMAC_INT_PENDING))
37 spin_lock_irqsave(instance->host_lock, flags);
38 wd33c93_intr(instance);
39 spin_unlock_irqrestore(instance->host_lock, flags);
43 static int gvp11_xfer_mask = 0;
45 void gvp11_setup(char *str, int *ints)
47 gvp11_xfer_mask = ints[1];
50 static int dma_setup(struct scsi_cmnd *cmd, int dir_in)
52 struct Scsi_Host *instance = cmd->device->host;
53 struct WD33C93_hostdata *hdata = shost_priv(instance);
54 struct gvp11_scsiregs *regs = (struct gvp11_scsiregs *)(instance->base);
55 unsigned short cntr = GVP11_DMAC_INT_ENABLE;
56 unsigned long addr = virt_to_bus(cmd->SCp.ptr);
58 static int scsi_alloc_out_of_range = 0;
60 /* use bounce buffer if the physical address is bad */
61 if (addr & hdata->dma_xfer_mask) {
62 hdata->dma_bounce_len = (cmd->SCp.this_residual + 511) & ~0x1ff;
64 if (!scsi_alloc_out_of_range) {
65 hdata->dma_bounce_buffer =
66 kmalloc(hdata->dma_bounce_len, GFP_KERNEL);
67 hdata->dma_buffer_pool = BUF_SCSI_ALLOCED;
70 if (scsi_alloc_out_of_range ||
71 !hdata->dma_bounce_buffer) {
72 hdata->dma_bounce_buffer =
73 amiga_chip_alloc(hdata->dma_bounce_len,
74 "GVP II SCSI Bounce Buffer");
76 if (!hdata->dma_bounce_buffer) {
77 hdata->dma_bounce_len = 0;
81 hdata->dma_buffer_pool = BUF_CHIP_ALLOCED;
84 /* check if the address of the bounce buffer is OK */
85 addr = virt_to_bus(hdata->dma_bounce_buffer);
87 if (addr & hdata->dma_xfer_mask) {
88 /* fall back to Chip RAM if address out of range */
89 if (hdata->dma_buffer_pool == BUF_SCSI_ALLOCED) {
90 kfree(hdata->dma_bounce_buffer);
91 scsi_alloc_out_of_range = 1;
93 amiga_chip_free(hdata->dma_bounce_buffer);
96 hdata->dma_bounce_buffer =
97 amiga_chip_alloc(hdata->dma_bounce_len,
98 "GVP II SCSI Bounce Buffer");
100 if (!hdata->dma_bounce_buffer) {
101 hdata->dma_bounce_len = 0;
105 addr = virt_to_bus(hdata->dma_bounce_buffer);
106 hdata->dma_buffer_pool = BUF_CHIP_ALLOCED;
110 /* copy to bounce buffer for a write */
111 memcpy(hdata->dma_bounce_buffer, cmd->SCp.ptr,
112 cmd->SCp.this_residual);
116 /* setup dma direction */
118 cntr |= GVP11_DMAC_DIR_WRITE;
120 hdata->dma_dir = dir_in;
123 /* setup DMA *physical* address */
127 /* invalidate any cache */
128 cache_clear(addr, cmd->SCp.this_residual);
130 /* push any dirty cache */
131 cache_push(addr, cmd->SCp.this_residual);
134 bank_mask = (~hdata->dma_xfer_mask >> 18) & 0x01c0;
136 regs->BANK = bank_mask & (addr >> 18);
145 static void dma_stop(struct Scsi_Host *instance, struct scsi_cmnd *SCpnt,
148 struct gvp11_scsiregs *regs = (struct gvp11_scsiregs *)(instance->base);
149 struct WD33C93_hostdata *hdata = shost_priv(instance);
153 /* remove write bit from CONTROL bits */
154 regs->CNTR = GVP11_DMAC_INT_ENABLE;
156 /* copy from a bounce buffer, if necessary */
157 if (status && hdata->dma_bounce_buffer) {
158 if (hdata->dma_dir && SCpnt)
159 memcpy(SCpnt->SCp.ptr, hdata->dma_bounce_buffer,
160 SCpnt->SCp.this_residual);
162 if (hdata->dma_buffer_pool == BUF_SCSI_ALLOCED)
163 kfree(hdata->dma_bounce_buffer);
165 amiga_chip_free(hdata->dma_bounce_buffer);
167 hdata->dma_bounce_buffer = NULL;
168 hdata->dma_bounce_len = 0;
172 static int __init check_wd33c93(struct gvp11_scsiregs *regs)
175 volatile unsigned char *sasr_3393, *scmd_3393;
176 unsigned char save_sasr;
180 * These darn GVP boards are a problem - it can be tough to tell
181 * whether or not they include a SCSI controller. This is the
182 * ultimate Yet-Another-GVP-Detection-Hack in that it actually
183 * probes for a WD33c93 chip: If we find one, it's extremely
184 * likely that this card supports SCSI, regardless of Product_
185 * Code, Board_Size, etc.
188 /* Get pointers to the presumed register locations and save contents */
190 sasr_3393 = ®s->SASR;
191 scmd_3393 = ®s->SCMD;
192 save_sasr = *sasr_3393;
194 /* First test the AuxStatus Reg */
196 q = *sasr_3393; /* read it */
197 if (q & 0x08) /* bit 3 should always be clear */
199 *sasr_3393 = WD_AUXILIARY_STATUS; /* setup indirect address */
200 if (*sasr_3393 == WD_AUXILIARY_STATUS) { /* shouldn't retain the write */
201 *sasr_3393 = save_sasr; /* Oops - restore this byte */
204 if (*sasr_3393 != q) { /* should still read the same */
205 *sasr_3393 = save_sasr; /* Oops - restore this byte */
208 if (*scmd_3393 != q) /* and so should the image at 0x1f */
212 * Ok, we probably have a wd33c93, but let's check a few other places
213 * for good measure. Make sure that this works for both 'A and 'B
217 *sasr_3393 = WD_SCSI_STATUS;
219 *sasr_3393 = WD_SCSI_STATUS;
221 *sasr_3393 = WD_SCSI_STATUS;
223 *sasr_3393 = WD_SCSI_STATUS;
225 if (qq != q) /* should be read only */
227 *sasr_3393 = 0x1e; /* this register is unimplemented */
235 if (qq != q || qq != 0xff) /* should be read only, all 1's */
237 *sasr_3393 = WD_TIMEOUT_PERIOD;
239 *sasr_3393 = WD_TIMEOUT_PERIOD;
241 *sasr_3393 = WD_TIMEOUT_PERIOD;
243 *sasr_3393 = WD_TIMEOUT_PERIOD;
245 if (qq != (~q & 0xff)) /* should be read/write */
247 #endif /* CHECK_WD33C93 */
252 int __init gvp11_detect(struct scsi_host_template *tpnt)
254 static unsigned char called = 0;
255 struct Scsi_Host *instance;
256 unsigned long address;
258 struct zorro_dev *z = NULL;
259 unsigned int default_dma_xfer_mask;
260 struct WD33C93_hostdata *hdata;
261 struct gvp11_scsiregs *regs;
265 if (!MACH_IS_AMIGA || called)
269 tpnt->proc_name = "GVP11";
270 tpnt->proc_info = &wd33c93_proc_info;
272 while ((z = zorro_find_device(ZORRO_WILDCARD, z))) {
274 * This should (hopefully) be the correct way to identify
275 * all the different GVP SCSI controllers (except for the
279 if (z->id == ZORRO_PROD_GVP_COMBO_030_R3_SCSI ||
280 z->id == ZORRO_PROD_GVP_SERIES_II)
281 default_dma_xfer_mask = ~0x00ffffff;
282 else if (z->id == ZORRO_PROD_GVP_GFORCE_030_SCSI ||
283 z->id == ZORRO_PROD_GVP_A530_SCSI ||
284 z->id == ZORRO_PROD_GVP_COMBO_030_R4_SCSI)
285 default_dma_xfer_mask = ~0x01ffffff;
286 else if (z->id == ZORRO_PROD_GVP_A1291 ||
287 z->id == ZORRO_PROD_GVP_GFORCE_040_SCSI_1)
288 default_dma_xfer_mask = ~0x07ffffff;
293 * Rumors state that some GVP ram boards use the same product
294 * code as the SCSI controllers. Therefore if the board-size
295 * is not 64KB we asume it is a ram board and bail out.
297 if (z->resource.end - z->resource.start != 0xffff)
300 address = z->resource.start;
301 if (!request_mem_region(address, 256, "wd33c93"))
304 regs = (struct gvp11_scsiregs *)(ZTWO_VADDR(address));
305 if (check_wd33c93(regs))
308 instance = scsi_register(tpnt, sizeof(struct WD33C93_hostdata));
309 if (instance == NULL)
311 instance->base = ZTWO_VADDR(address);
312 instance->irq = IRQ_AMIGA_PORTS;
313 instance->unique_id = z->slotaddr;
315 hdata = shost_priv(instance);
317 hdata->dma_xfer_mask = gvp11_xfer_mask;
319 hdata->dma_xfer_mask = default_dma_xfer_mask;
324 while (regs->CNTR & GVP11_DMAC_BUSY)
330 epc = *(unsigned short *)(ZTWO_VADDR(address) + 0x8000);
333 * Check for 14MHz SCSI clock
335 wdregs.SASR = ®s->SASR;
336 wdregs.SCMD = ®s->SCMD;
337 hdata->no_sync = 0xff;
339 hdata->dma_mode = CTRL_DMA;
340 wd33c93_init(instance, wdregs, dma_setup, dma_stop,
341 (epc & GVP_SCSICLKMASK) ? WD33C93_FS_8_10
344 if (request_irq(IRQ_AMIGA_PORTS, gvp11_intr, IRQF_SHARED,
345 "GVP11 SCSI", instance))
347 regs->CNTR = GVP11_DMAC_INT_ENABLE;
352 scsi_unregister(instance);
354 release_mem_region(address, 256);
360 static int gvp11_bus_reset(struct scsi_cmnd *cmd)
362 /* FIXME perform bus-specific reset */
364 /* FIXME 2: shouldn't we no-op this function (return
365 FAILED), and fall back to host reset function,
366 wd33c93_host_reset ? */
368 spin_lock_irq(cmd->device->host->host_lock);
369 wd33c93_host_reset(cmd);
370 spin_unlock_irq(cmd->device->host->host_lock);
380 static struct scsi_host_template driver_template = {
381 .proc_name = "GVP11",
382 .name = "GVP Series II SCSI",
383 .detect = gvp11_detect,
384 .release = gvp11_release,
385 .queuecommand = wd33c93_queuecommand,
386 .eh_abort_handler = wd33c93_abort,
387 .eh_bus_reset_handler = gvp11_bus_reset,
388 .eh_host_reset_handler = wd33c93_host_reset,
389 .can_queue = CAN_QUEUE,
391 .sg_tablesize = SG_ALL,
392 .cmd_per_lun = CMD_PER_LUN,
393 .use_clustering = DISABLE_CLUSTERING
397 #include "scsi_module.c"
399 int gvp11_release(struct Scsi_Host *instance)
402 struct gvp11_scsiregs *regs = (struct gvp11_scsiregs *)(instance->base);
405 release_mem_region(ZTWO_PADDR(instance->base), 256);
406 free_irq(IRQ_AMIGA_PORTS, instance);
411 MODULE_LICENSE("GPL");