1 #include <linux/types.h>
3 #include <linux/blkdev.h>
4 #include <linux/sched.h>
5 #include <linux/version.h>
6 #include <linux/init.h>
7 #include <linux/interrupt.h>
11 #include <asm/pgtable.h>
12 #include <asm/amigaints.h>
13 #include <asm/amigahw.h>
14 #include <linux/zorro.h>
16 #include <linux/spinlock.h>
19 #include <scsi/scsi_host.h>
23 #include<linux/stat.h>
25 #define DMA(ptr) ((gvp11_scsiregs *)((ptr)->base))
26 #define HDATA(ptr) ((struct WD33C93_hostdata *)((ptr)->hostdata))
28 static irqreturn_t gvp11_intr (int irq, void *_instance, struct pt_regs *fp)
32 struct Scsi_Host *instance = (struct Scsi_Host *)_instance;
34 status = DMA(instance)->CNTR;
35 if (!(status & GVP11_DMAC_INT_PENDING))
38 spin_lock_irqsave(instance->host_lock, flags);
39 wd33c93_intr(instance);
40 spin_unlock_irqrestore(instance->host_lock, flags);
44 static int gvp11_xfer_mask = 0;
46 void gvp11_setup (char *str, int *ints)
48 gvp11_xfer_mask = ints[1];
51 static int dma_setup (Scsi_Cmnd *cmd, int dir_in)
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(cmd->device->host)->dma_xfer_mask ||
60 (!dir_in && mm_end_of_chunk (addr, cmd->SCp.this_residual)))
62 HDATA(cmd->device->host)->dma_bounce_len = (cmd->SCp.this_residual + 511)
65 if( !scsi_alloc_out_of_range ) {
66 HDATA(cmd->device->host)->dma_bounce_buffer =
67 kmalloc (HDATA(cmd->device->host)->dma_bounce_len, GFP_KERNEL);
68 HDATA(cmd->device->host)->dma_buffer_pool = BUF_SCSI_ALLOCED;
71 if (scsi_alloc_out_of_range ||
72 !HDATA(cmd->device->host)->dma_bounce_buffer) {
73 HDATA(cmd->device->host)->dma_bounce_buffer =
74 amiga_chip_alloc(HDATA(cmd->device->host)->dma_bounce_len,
75 "GVP II SCSI Bounce Buffer");
77 if(!HDATA(cmd->device->host)->dma_bounce_buffer)
79 HDATA(cmd->device->host)->dma_bounce_len = 0;
83 HDATA(cmd->device->host)->dma_buffer_pool = BUF_CHIP_ALLOCED;
86 /* check if the address of the bounce buffer is OK */
87 addr = virt_to_bus(HDATA(cmd->device->host)->dma_bounce_buffer);
89 if (addr & HDATA(cmd->device->host)->dma_xfer_mask) {
90 /* fall back to Chip RAM if address out of range */
91 if( HDATA(cmd->device->host)->dma_buffer_pool == BUF_SCSI_ALLOCED) {
92 kfree (HDATA(cmd->device->host)->dma_bounce_buffer);
93 scsi_alloc_out_of_range = 1;
95 amiga_chip_free (HDATA(cmd->device->host)->dma_bounce_buffer);
98 HDATA(cmd->device->host)->dma_bounce_buffer =
99 amiga_chip_alloc(HDATA(cmd->device->host)->dma_bounce_len,
100 "GVP II SCSI Bounce Buffer");
102 if(!HDATA(cmd->device->host)->dma_bounce_buffer)
104 HDATA(cmd->device->host)->dma_bounce_len = 0;
108 addr = virt_to_bus(HDATA(cmd->device->host)->dma_bounce_buffer);
109 HDATA(cmd->device->host)->dma_buffer_pool = BUF_CHIP_ALLOCED;
113 /* copy to bounce buffer for a write */
114 memcpy (HDATA(cmd->device->host)->dma_bounce_buffer,
115 cmd->SCp.ptr, cmd->SCp.this_residual);
119 /* setup dma direction */
121 cntr |= GVP11_DMAC_DIR_WRITE;
123 HDATA(cmd->device->host)->dma_dir = dir_in;
124 DMA(cmd->device->host)->CNTR = cntr;
126 /* setup DMA *physical* address */
127 DMA(cmd->device->host)->ACR = addr;
130 /* invalidate any cache */
131 cache_clear (addr, cmd->SCp.this_residual);
133 /* push any dirty cache */
134 cache_push (addr, cmd->SCp.this_residual);
136 if ((bank_mask = (~HDATA(cmd->device->host)->dma_xfer_mask >> 18) & 0x01c0))
137 DMA(cmd->device->host)->BANK = bank_mask & (addr >> 18);
140 DMA(cmd->device->host)->ST_DMA = 1;
146 static void dma_stop (struct Scsi_Host *instance, Scsi_Cmnd *SCpnt,
150 DMA(instance)->SP_DMA = 1;
151 /* remove write bit from CONTROL bits */
152 DMA(instance)->CNTR = GVP11_DMAC_INT_ENABLE;
154 /* copy from a bounce buffer, if necessary */
155 if (status && HDATA(instance)->dma_bounce_buffer) {
156 if (HDATA(instance)->dma_dir && SCpnt)
157 memcpy (SCpnt->SCp.ptr,
158 HDATA(instance)->dma_bounce_buffer,
159 SCpnt->SCp.this_residual);
161 if (HDATA(instance)->dma_buffer_pool == BUF_SCSI_ALLOCED)
162 kfree (HDATA(instance)->dma_bounce_buffer);
164 amiga_chip_free(HDATA(instance)->dma_bounce_buffer);
166 HDATA(instance)->dma_bounce_buffer = NULL;
167 HDATA(instance)->dma_bounce_len = 0;
171 #define CHECK_WD33C93
173 int __init gvp11_detect(Scsi_Host_Template *tpnt)
175 static unsigned char called = 0;
176 struct Scsi_Host *instance;
177 unsigned long address;
179 struct zorro_dev *z = NULL;
180 unsigned int default_dma_xfer_mask;
184 volatile unsigned char *sasr_3393, *scmd_3393;
185 unsigned char save_sasr;
189 if (!MACH_IS_AMIGA || called)
193 tpnt->proc_name = "GVP11";
194 tpnt->proc_info = &wd33c93_proc_info;
196 while ((z = zorro_find_device(ZORRO_WILDCARD, z))) {
198 * This should (hopefully) be the correct way to identify
199 * all the different GVP SCSI controllers (except for the
203 if (z->id == ZORRO_PROD_GVP_COMBO_030_R3_SCSI ||
204 z->id == ZORRO_PROD_GVP_SERIES_II)
205 default_dma_xfer_mask = ~0x00ffffff;
206 else if (z->id == ZORRO_PROD_GVP_GFORCE_030_SCSI ||
207 z->id == ZORRO_PROD_GVP_A530_SCSI ||
208 z->id == ZORRO_PROD_GVP_COMBO_030_R4_SCSI)
209 default_dma_xfer_mask = ~0x01ffffff;
210 else if (z->id == ZORRO_PROD_GVP_A1291 ||
211 z->id == ZORRO_PROD_GVP_GFORCE_040_SCSI_1)
212 default_dma_xfer_mask = ~0x07ffffff;
217 * Rumors state that some GVP ram boards use the same product
218 * code as the SCSI controllers. Therefore if the board-size
219 * is not 64KB we asume it is a ram board and bail out.
221 if (z->resource.end-z->resource.start != 0xffff)
224 address = z->resource.start;
225 if (!request_mem_region(address, 256, "wd33c93"))
231 * These darn GVP boards are a problem - it can be tough to tell
232 * whether or not they include a SCSI controller. This is the
233 * ultimate Yet-Another-GVP-Detection-Hack in that it actually
234 * probes for a WD33c93 chip: If we find one, it's extremely
235 * likely that this card supports SCSI, regardless of Product_
236 * Code, Board_Size, etc.
239 /* Get pointers to the presumed register locations and save contents */
241 sasr_3393 = &(((gvp11_scsiregs *)(ZTWO_VADDR(address)))->SASR);
242 scmd_3393 = &(((gvp11_scsiregs *)(ZTWO_VADDR(address)))->SCMD);
243 save_sasr = *sasr_3393;
245 /* First test the AuxStatus Reg */
247 q = *sasr_3393; /* read it */
248 if (q & 0x08) /* bit 3 should always be clear */
250 *sasr_3393 = WD_AUXILIARY_STATUS; /* setup indirect address */
251 if (*sasr_3393 == WD_AUXILIARY_STATUS) { /* shouldn't retain the write */
252 *sasr_3393 = save_sasr; /* Oops - restore this byte */
255 if (*sasr_3393 != q) { /* should still read the same */
256 *sasr_3393 = save_sasr; /* Oops - restore this byte */
259 if (*scmd_3393 != q) /* and so should the image at 0x1f */
263 /* Ok, we probably have a wd33c93, but let's check a few other places
264 * for good measure. Make sure that this works for both 'A and 'B
268 *sasr_3393 = WD_SCSI_STATUS;
270 *sasr_3393 = WD_SCSI_STATUS;
272 *sasr_3393 = WD_SCSI_STATUS;
274 *sasr_3393 = WD_SCSI_STATUS;
276 if (qq != q) /* should be read only */
278 *sasr_3393 = 0x1e; /* this register is unimplemented */
286 if (qq != q || qq != 0xff) /* should be read only, all 1's */
288 *sasr_3393 = WD_TIMEOUT_PERIOD;
290 *sasr_3393 = WD_TIMEOUT_PERIOD;
292 *sasr_3393 = WD_TIMEOUT_PERIOD;
294 *sasr_3393 = WD_TIMEOUT_PERIOD;
296 if (qq != (~q & 0xff)) /* should be read/write */
300 instance = scsi_register (tpnt, sizeof (struct WD33C93_hostdata));
303 instance->base = ZTWO_VADDR(address);
304 instance->irq = IRQ_AMIGA_PORTS;
305 instance->unique_id = z->slotaddr;
308 HDATA(instance)->dma_xfer_mask = gvp11_xfer_mask;
310 HDATA(instance)->dma_xfer_mask = default_dma_xfer_mask;
313 DMA(instance)->secret2 = 1;
314 DMA(instance)->secret1 = 0;
315 DMA(instance)->secret3 = 15;
316 while (DMA(instance)->CNTR & GVP11_DMAC_BUSY) ;
317 DMA(instance)->CNTR = 0;
319 DMA(instance)->BANK = 0;
321 epc = *(unsigned short *)(ZTWO_VADDR(address) + 0x8000);
324 * Check for 14MHz SCSI clock
326 regs.SASR = &(DMA(instance)->SASR);
327 regs.SCMD = &(DMA(instance)->SCMD);
328 wd33c93_init(instance, regs, dma_setup, dma_stop,
329 (epc & GVP_SCSICLKMASK) ? WD33C93_FS_8_10
332 request_irq(IRQ_AMIGA_PORTS, gvp11_intr, SA_SHIRQ, "GVP11 SCSI",
334 DMA(instance)->CNTR = GVP11_DMAC_INT_ENABLE;
339 release_mem_region(address, 256);
345 static int gvp11_bus_reset(Scsi_Cmnd *cmd)
347 /* FIXME perform bus-specific reset */
349 /* FIXME 2: shouldn't we no-op this function (return
350 FAILED), and fall back to host reset function,
351 wd33c93_host_reset ? */
353 spin_lock_irq(cmd->device->host->host_lock);
354 wd33c93_host_reset(cmd);
355 spin_unlock_irq(cmd->device->host->host_lock);
365 static Scsi_Host_Template driver_template = {
366 .proc_name = "GVP11",
367 .name = "GVP Series II SCSI",
368 .detect = gvp11_detect,
369 .release = gvp11_release,
370 .queuecommand = wd33c93_queuecommand,
371 .eh_abort_handler = wd33c93_abort,
372 .eh_bus_reset_handler = gvp11_bus_reset,
373 .eh_host_reset_handler = wd33c93_host_reset,
374 .can_queue = CAN_QUEUE,
376 .sg_tablesize = SG_ALL,
377 .cmd_per_lun = CMD_PER_LUN,
378 .use_clustering = DISABLE_CLUSTERING
382 #include "scsi_module.c"
384 int gvp11_release(struct Scsi_Host *instance)
387 DMA(instance)->CNTR = 0;
388 release_mem_region(ZTWO_PADDR(instance->base), 256);
389 free_irq(IRQ_AMIGA_PORTS, instance);
395 MODULE_LICENSE("GPL");