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>
25 static irqreturn_t gvp11_intr(int irq, void *data)
27 struct Scsi_Host *instance = data;
28 gvp11_scsiregs *regs = (gvp11_scsiregs *)(instance->base);
29 unsigned int status = regs->CNTR;
32 if (!(status & GVP11_DMAC_INT_PENDING))
35 spin_lock_irqsave(instance->host_lock, flags);
36 wd33c93_intr(instance);
37 spin_unlock_irqrestore(instance->host_lock, flags);
41 static int gvp11_xfer_mask = 0;
43 void gvp11_setup(char *str, int *ints)
45 gvp11_xfer_mask = ints[1];
48 static int dma_setup(struct scsi_cmnd *cmd, int dir_in)
50 struct Scsi_Host *instance = cmd->device->host;
51 struct WD33C93_hostdata *hdata = shost_priv(instance);
52 gvp11_scsiregs *regs = (gvp11_scsiregs *)(instance->base);
53 unsigned short cntr = GVP11_DMAC_INT_ENABLE;
54 unsigned long addr = virt_to_bus(cmd->SCp.ptr);
56 static int scsi_alloc_out_of_range = 0;
58 /* use bounce buffer if the physical address is bad */
59 if (addr & hdata->dma_xfer_mask) {
60 hdata->dma_bounce_len = (cmd->SCp.this_residual + 511) & ~0x1ff;
62 if (!scsi_alloc_out_of_range) {
63 hdata->dma_bounce_buffer =
64 kmalloc(hdata->dma_bounce_len, GFP_KERNEL);
65 hdata->dma_buffer_pool = BUF_SCSI_ALLOCED;
68 if (scsi_alloc_out_of_range ||
69 !hdata->dma_bounce_buffer) {
70 hdata->dma_bounce_buffer =
71 amiga_chip_alloc(hdata->dma_bounce_len,
72 "GVP II SCSI Bounce Buffer");
74 if (!hdata->dma_bounce_buffer) {
75 hdata->dma_bounce_len = 0;
79 hdata->dma_buffer_pool = BUF_CHIP_ALLOCED;
82 /* check if the address of the bounce buffer is OK */
83 addr = virt_to_bus(hdata->dma_bounce_buffer);
85 if (addr & hdata->dma_xfer_mask) {
86 /* fall back to Chip RAM if address out of range */
87 if (hdata->dma_buffer_pool == BUF_SCSI_ALLOCED) {
88 kfree(hdata->dma_bounce_buffer);
89 scsi_alloc_out_of_range = 1;
91 amiga_chip_free(hdata->dma_bounce_buffer);
94 hdata->dma_bounce_buffer =
95 amiga_chip_alloc(hdata->dma_bounce_len,
96 "GVP II SCSI Bounce Buffer");
98 if (!hdata->dma_bounce_buffer) {
99 hdata->dma_bounce_len = 0;
103 addr = virt_to_bus(hdata->dma_bounce_buffer);
104 hdata->dma_buffer_pool = BUF_CHIP_ALLOCED;
108 /* copy to bounce buffer for a write */
109 memcpy(hdata->dma_bounce_buffer, cmd->SCp.ptr,
110 cmd->SCp.this_residual);
114 /* setup dma direction */
116 cntr |= GVP11_DMAC_DIR_WRITE;
118 hdata->dma_dir = dir_in;
121 /* setup DMA *physical* address */
125 /* invalidate any cache */
126 cache_clear(addr, cmd->SCp.this_residual);
128 /* push any dirty cache */
129 cache_push(addr, cmd->SCp.this_residual);
132 bank_mask = (~hdata->dma_xfer_mask >> 18) & 0x01c0;
134 regs->BANK = bank_mask & (addr >> 18);
143 static void dma_stop(struct Scsi_Host *instance, struct scsi_cmnd *SCpnt,
146 gvp11_scsiregs *regs = (gvp11_scsiregs *)(instance->base);
147 struct WD33C93_hostdata *hdata = shost_priv(instance);
151 /* remove write bit from CONTROL bits */
152 regs->CNTR = GVP11_DMAC_INT_ENABLE;
154 /* copy from a bounce buffer, if necessary */
155 if (status && hdata->dma_bounce_buffer) {
156 if (hdata->dma_dir && SCpnt)
157 memcpy(SCpnt->SCp.ptr, hdata->dma_bounce_buffer,
158 SCpnt->SCp.this_residual);
160 if (hdata->dma_buffer_pool == BUF_SCSI_ALLOCED)
161 kfree(hdata->dma_bounce_buffer);
163 amiga_chip_free(hdata->dma_bounce_buffer);
165 hdata->dma_bounce_buffer = NULL;
166 hdata->dma_bounce_len = 0;
170 #define CHECK_WD33C93
172 int __init gvp11_detect(struct scsi_host_template *tpnt)
174 static unsigned char called = 0;
175 struct Scsi_Host *instance;
176 unsigned long address;
178 struct zorro_dev *z = NULL;
179 unsigned int default_dma_xfer_mask;
180 struct WD33C93_hostdata *hdata;
181 gvp11_scsiregs *regs;
185 volatile unsigned char *sasr_3393, *scmd_3393;
186 unsigned char save_sasr;
190 if (!MACH_IS_AMIGA || called)
194 tpnt->proc_name = "GVP11";
195 tpnt->proc_info = &wd33c93_proc_info;
197 while ((z = zorro_find_device(ZORRO_WILDCARD, z))) {
199 * This should (hopefully) be the correct way to identify
200 * all the different GVP SCSI controllers (except for the
204 if (z->id == ZORRO_PROD_GVP_COMBO_030_R3_SCSI ||
205 z->id == ZORRO_PROD_GVP_SERIES_II)
206 default_dma_xfer_mask = ~0x00ffffff;
207 else if (z->id == ZORRO_PROD_GVP_GFORCE_030_SCSI ||
208 z->id == ZORRO_PROD_GVP_A530_SCSI ||
209 z->id == ZORRO_PROD_GVP_COMBO_030_R4_SCSI)
210 default_dma_xfer_mask = ~0x01ffffff;
211 else if (z->id == ZORRO_PROD_GVP_A1291 ||
212 z->id == ZORRO_PROD_GVP_GFORCE_040_SCSI_1)
213 default_dma_xfer_mask = ~0x07ffffff;
218 * Rumors state that some GVP ram boards use the same product
219 * code as the SCSI controllers. Therefore if the board-size
220 * is not 64KB we asume it is a ram board and bail out.
222 if (z->resource.end - z->resource.start != 0xffff)
225 address = z->resource.start;
226 if (!request_mem_region(address, 256, "wd33c93"))
232 * These darn GVP boards are a problem - it can be tough to tell
233 * whether or not they include a SCSI controller. This is the
234 * ultimate Yet-Another-GVP-Detection-Hack in that it actually
235 * probes for a WD33c93 chip: If we find one, it's extremely
236 * likely that this card supports SCSI, regardless of Product_
237 * Code, Board_Size, etc.
240 /* Get pointers to the presumed register locations and save contents */
242 sasr_3393 = &(((gvp11_scsiregs *)(ZTWO_VADDR(address)))->SASR);
243 scmd_3393 = &(((gvp11_scsiregs *)(ZTWO_VADDR(address)))->SCMD);
244 save_sasr = *sasr_3393;
246 /* First test the AuxStatus Reg */
248 q = *sasr_3393; /* read it */
249 if (q & 0x08) /* bit 3 should always be clear */
251 *sasr_3393 = WD_AUXILIARY_STATUS; /* setup indirect address */
252 if (*sasr_3393 == WD_AUXILIARY_STATUS) { /* shouldn't retain the write */
253 *sasr_3393 = save_sasr; /* Oops - restore this byte */
256 if (*sasr_3393 != q) { /* should still read the same */
257 *sasr_3393 = save_sasr; /* Oops - restore this byte */
260 if (*scmd_3393 != q) /* and so should the image at 0x1f */
264 * Ok, we probably have a wd33c93, but let's check a few other places
265 * for good measure. Make sure that this works for both 'A and 'B
269 *sasr_3393 = WD_SCSI_STATUS;
271 *sasr_3393 = WD_SCSI_STATUS;
273 *sasr_3393 = WD_SCSI_STATUS;
275 *sasr_3393 = WD_SCSI_STATUS;
277 if (qq != q) /* should be read only */
279 *sasr_3393 = 0x1e; /* this register is unimplemented */
287 if (qq != q || qq != 0xff) /* should be read only, all 1's */
289 *sasr_3393 = WD_TIMEOUT_PERIOD;
291 *sasr_3393 = WD_TIMEOUT_PERIOD;
293 *sasr_3393 = WD_TIMEOUT_PERIOD;
295 *sasr_3393 = WD_TIMEOUT_PERIOD;
297 if (qq != (~q & 0xff)) /* should be read/write */
301 instance = scsi_register(tpnt, sizeof(struct WD33C93_hostdata));
302 if (instance == NULL)
304 instance->base = ZTWO_VADDR(address);
305 instance->irq = IRQ_AMIGA_PORTS;
306 instance->unique_id = z->slotaddr;
308 hdata = shost_priv(instance);
310 hdata->dma_xfer_mask = gvp11_xfer_mask;
312 hdata->dma_xfer_mask = default_dma_xfer_mask;
314 regs = (gvp11_scsiregs *)(instance->base);
318 while (regs->CNTR & GVP11_DMAC_BUSY)
324 epc = *(unsigned short *)(ZTWO_VADDR(address) + 0x8000);
327 * Check for 14MHz SCSI clock
329 wdregs.SASR = ®s->SASR;
330 wdregs.SCMD = ®s->SCMD;
331 hdata->no_sync = 0xff;
333 hdata->dma_mode = CTRL_DMA;
334 wd33c93_init(instance, wdregs, dma_setup, dma_stop,
335 (epc & GVP_SCSICLKMASK) ? WD33C93_FS_8_10
338 if (request_irq(IRQ_AMIGA_PORTS, gvp11_intr, IRQF_SHARED,
339 "GVP11 SCSI", instance))
341 regs->CNTR = GVP11_DMAC_INT_ENABLE;
346 scsi_unregister(instance);
348 release_mem_region(address, 256);
354 static int gvp11_bus_reset(struct scsi_cmnd *cmd)
356 /* FIXME perform bus-specific reset */
358 /* FIXME 2: shouldn't we no-op this function (return
359 FAILED), and fall back to host reset function,
360 wd33c93_host_reset ? */
362 spin_lock_irq(cmd->device->host->host_lock);
363 wd33c93_host_reset(cmd);
364 spin_unlock_irq(cmd->device->host->host_lock);
374 static struct scsi_host_template driver_template = {
375 .proc_name = "GVP11",
376 .name = "GVP Series II SCSI",
377 .detect = gvp11_detect,
378 .release = gvp11_release,
379 .queuecommand = wd33c93_queuecommand,
380 .eh_abort_handler = wd33c93_abort,
381 .eh_bus_reset_handler = gvp11_bus_reset,
382 .eh_host_reset_handler = wd33c93_host_reset,
383 .can_queue = CAN_QUEUE,
385 .sg_tablesize = SG_ALL,
386 .cmd_per_lun = CMD_PER_LUN,
387 .use_clustering = DISABLE_CLUSTERING
391 #include "scsi_module.c"
393 int gvp11_release(struct Scsi_Host *instance)
396 gvp11_scsiregs *regs = (gvp11_scsiregs *)(instance->base);
399 release_mem_region(ZTWO_PADDR(instance->base), 256);
400 free_irq(IRQ_AMIGA_PORTS, instance);
405 MODULE_LICENSE("GPL");