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 #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)
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(struct 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 HDATA(cmd->device->host)->dma_bounce_len =
61 (cmd->SCp.this_residual + 511) & ~0x1ff;
63 if (!scsi_alloc_out_of_range) {
64 HDATA(cmd->device->host)->dma_bounce_buffer =
65 kmalloc(HDATA(cmd->device->host)->dma_bounce_len,
67 HDATA(cmd->device->host)->dma_buffer_pool =
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) {
78 HDATA(cmd->device->host)->dma_bounce_len = 0;
82 HDATA(cmd->device->host)->dma_buffer_pool =
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 ==
93 kfree(HDATA(cmd->device->host)->dma_bounce_buffer);
94 scsi_alloc_out_of_range = 1;
96 amiga_chip_free(HDATA(cmd->device->host)->dma_bounce_buffer);
99 HDATA(cmd->device->host)->dma_bounce_buffer =
100 amiga_chip_alloc(HDATA(cmd->device->host)->dma_bounce_len,
101 "GVP II SCSI Bounce Buffer");
103 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 =
114 /* copy to bounce buffer for a write */
115 memcpy(HDATA(cmd->device->host)->dma_bounce_buffer,
116 cmd->SCp.ptr, cmd->SCp.this_residual);
120 /* setup dma direction */
122 cntr |= GVP11_DMAC_DIR_WRITE;
124 HDATA(cmd->device->host)->dma_dir = dir_in;
125 DMA(cmd->device->host)->CNTR = cntr;
127 /* setup DMA *physical* address */
128 DMA(cmd->device->host)->ACR = addr;
131 /* invalidate any cache */
132 cache_clear(addr, cmd->SCp.this_residual);
134 /* push any dirty cache */
135 cache_push(addr, cmd->SCp.this_residual);
138 if ((bank_mask = (~HDATA(cmd->device->host)->dma_xfer_mask >> 18) & 0x01c0))
139 DMA(cmd->device->host)->BANK = bank_mask & (addr >> 18);
142 DMA(cmd->device->host)->ST_DMA = 1;
148 static void dma_stop(struct Scsi_Host *instance, struct scsi_cmnd *SCpnt,
152 DMA(instance)->SP_DMA = 1;
153 /* remove write bit from CONTROL bits */
154 DMA(instance)->CNTR = GVP11_DMAC_INT_ENABLE;
156 /* copy from a bounce buffer, if necessary */
157 if (status && HDATA(instance)->dma_bounce_buffer) {
158 if (HDATA(instance)->dma_dir && SCpnt)
159 memcpy(SCpnt->SCp.ptr,
160 HDATA(instance)->dma_bounce_buffer,
161 SCpnt->SCp.this_residual);
163 if (HDATA(instance)->dma_buffer_pool == BUF_SCSI_ALLOCED)
164 kfree(HDATA(instance)->dma_bounce_buffer);
166 amiga_chip_free(HDATA(instance)->dma_bounce_buffer);
168 HDATA(instance)->dma_bounce_buffer = NULL;
169 HDATA(instance)->dma_bounce_len = 0;
173 #define CHECK_WD33C93
175 int __init gvp11_detect(struct scsi_host_template *tpnt)
177 static unsigned char called = 0;
178 struct Scsi_Host *instance;
179 unsigned long address;
181 struct zorro_dev *z = NULL;
182 unsigned int default_dma_xfer_mask;
186 volatile unsigned char *sasr_3393, *scmd_3393;
187 unsigned char save_sasr;
191 if (!MACH_IS_AMIGA || called)
195 tpnt->proc_name = "GVP11";
196 tpnt->proc_info = &wd33c93_proc_info;
198 while ((z = zorro_find_device(ZORRO_WILDCARD, z))) {
200 * This should (hopefully) be the correct way to identify
201 * all the different GVP SCSI controllers (except for the
205 if (z->id == ZORRO_PROD_GVP_COMBO_030_R3_SCSI ||
206 z->id == ZORRO_PROD_GVP_SERIES_II)
207 default_dma_xfer_mask = ~0x00ffffff;
208 else if (z->id == ZORRO_PROD_GVP_GFORCE_030_SCSI ||
209 z->id == ZORRO_PROD_GVP_A530_SCSI ||
210 z->id == ZORRO_PROD_GVP_COMBO_030_R4_SCSI)
211 default_dma_xfer_mask = ~0x01ffffff;
212 else if (z->id == ZORRO_PROD_GVP_A1291 ||
213 z->id == ZORRO_PROD_GVP_GFORCE_040_SCSI_1)
214 default_dma_xfer_mask = ~0x07ffffff;
219 * Rumors state that some GVP ram boards use the same product
220 * code as the SCSI controllers. Therefore if the board-size
221 * is not 64KB we asume it is a ram board and bail out.
223 if (z->resource.end - z->resource.start != 0xffff)
226 address = z->resource.start;
227 if (!request_mem_region(address, 256, "wd33c93"))
233 * These darn GVP boards are a problem - it can be tough to tell
234 * whether or not they include a SCSI controller. This is the
235 * ultimate Yet-Another-GVP-Detection-Hack in that it actually
236 * probes for a WD33c93 chip: If we find one, it's extremely
237 * likely that this card supports SCSI, regardless of Product_
238 * Code, Board_Size, etc.
241 /* Get pointers to the presumed register locations and save contents */
243 sasr_3393 = &(((gvp11_scsiregs *)(ZTWO_VADDR(address)))->SASR);
244 scmd_3393 = &(((gvp11_scsiregs *)(ZTWO_VADDR(address)))->SCMD);
245 save_sasr = *sasr_3393;
247 /* First test the AuxStatus Reg */
249 q = *sasr_3393; /* read it */
250 if (q & 0x08) /* bit 3 should always be clear */
252 *sasr_3393 = WD_AUXILIARY_STATUS; /* setup indirect address */
253 if (*sasr_3393 == WD_AUXILIARY_STATUS) { /* shouldn't retain the write */
254 *sasr_3393 = save_sasr; /* Oops - restore this byte */
257 if (*sasr_3393 != q) { /* should still read the same */
258 *sasr_3393 = save_sasr; /* Oops - restore this byte */
261 if (*scmd_3393 != q) /* and so should the image at 0x1f */
265 * Ok, we probably have a wd33c93, but let's check a few other places
266 * for good measure. Make sure that this works for both 'A and 'B
270 *sasr_3393 = WD_SCSI_STATUS;
272 *sasr_3393 = WD_SCSI_STATUS;
274 *sasr_3393 = WD_SCSI_STATUS;
276 *sasr_3393 = WD_SCSI_STATUS;
278 if (qq != q) /* should be read only */
280 *sasr_3393 = 0x1e; /* this register is unimplemented */
288 if (qq != q || qq != 0xff) /* should be read only, all 1's */
290 *sasr_3393 = WD_TIMEOUT_PERIOD;
292 *sasr_3393 = WD_TIMEOUT_PERIOD;
294 *sasr_3393 = WD_TIMEOUT_PERIOD;
296 *sasr_3393 = WD_TIMEOUT_PERIOD;
298 if (qq != (~q & 0xff)) /* should be read/write */
302 instance = scsi_register(tpnt, sizeof(struct WD33C93_hostdata));
303 if (instance == NULL)
305 instance->base = ZTWO_VADDR(address);
306 instance->irq = IRQ_AMIGA_PORTS;
307 instance->unique_id = z->slotaddr;
310 HDATA(instance)->dma_xfer_mask = gvp11_xfer_mask;
312 HDATA(instance)->dma_xfer_mask = default_dma_xfer_mask;
314 DMA(instance)->secret2 = 1;
315 DMA(instance)->secret1 = 0;
316 DMA(instance)->secret3 = 15;
317 while (DMA(instance)->CNTR & GVP11_DMAC_BUSY)
319 DMA(instance)->CNTR = 0;
321 DMA(instance)->BANK = 0;
323 epc = *(unsigned short *)(ZTWO_VADDR(address) + 0x8000);
326 * Check for 14MHz SCSI clock
328 regs.SASR = &(DMA(instance)->SASR);
329 regs.SCMD = &(DMA(instance)->SCMD);
330 HDATA(instance)->no_sync = 0xff;
331 HDATA(instance)->fast = 0;
332 HDATA(instance)->dma_mode = CTRL_DMA;
333 wd33c93_init(instance, regs, dma_setup, dma_stop,
334 (epc & GVP_SCSICLKMASK) ? WD33C93_FS_8_10
337 if (request_irq(IRQ_AMIGA_PORTS, gvp11_intr, IRQF_SHARED,
338 "GVP11 SCSI", instance))
340 DMA(instance)->CNTR = GVP11_DMAC_INT_ENABLE;
345 scsi_unregister(instance);
347 release_mem_region(address, 256);
353 static int gvp11_bus_reset(struct scsi_cmnd *cmd)
355 /* FIXME perform bus-specific reset */
357 /* FIXME 2: shouldn't we no-op this function (return
358 FAILED), and fall back to host reset function,
359 wd33c93_host_reset ? */
361 spin_lock_irq(cmd->device->host->host_lock);
362 wd33c93_host_reset(cmd);
363 spin_unlock_irq(cmd->device->host->host_lock);
373 static struct scsi_host_template driver_template = {
374 .proc_name = "GVP11",
375 .name = "GVP Series II SCSI",
376 .detect = gvp11_detect,
377 .release = gvp11_release,
378 .queuecommand = wd33c93_queuecommand,
379 .eh_abort_handler = wd33c93_abort,
380 .eh_bus_reset_handler = gvp11_bus_reset,
381 .eh_host_reset_handler = wd33c93_host_reset,
382 .can_queue = CAN_QUEUE,
384 .sg_tablesize = SG_ALL,
385 .cmd_per_lun = CMD_PER_LUN,
386 .use_clustering = DISABLE_CLUSTERING
390 #include "scsi_module.c"
392 int gvp11_release(struct Scsi_Host *instance)
395 DMA(instance)->CNTR = 0;
396 release_mem_region(ZTWO_PADDR(instance->base), 256);
397 free_irq(IRQ_AMIGA_PORTS, instance);
402 MODULE_LICENSE("GPL");