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))
27 static irqreturn_t
gvp11_intr(int irq
, void *_instance
)
31 struct Scsi_Host
*instance
= (struct Scsi_Host
*)_instance
;
33 status
= DMA(instance
)->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 unsigned short cntr
= GVP11_DMAC_INT_ENABLE
;
55 unsigned long addr
= virt_to_bus(cmd
->SCp
.ptr
);
57 static int scsi_alloc_out_of_range
= 0;
59 /* use bounce buffer if the physical address is bad */
60 if (addr
& hdata
->dma_xfer_mask
) {
61 hdata
->dma_bounce_len
= (cmd
->SCp
.this_residual
+ 511) & ~0x1ff;
63 if (!scsi_alloc_out_of_range
) {
64 hdata
->dma_bounce_buffer
=
65 kmalloc(hdata
->dma_bounce_len
, GFP_KERNEL
);
66 hdata
->dma_buffer_pool
= BUF_SCSI_ALLOCED
;
69 if (scsi_alloc_out_of_range
||
70 !hdata
->dma_bounce_buffer
) {
71 hdata
->dma_bounce_buffer
=
72 amiga_chip_alloc(hdata
->dma_bounce_len
,
73 "GVP II SCSI Bounce Buffer");
75 if (!hdata
->dma_bounce_buffer
) {
76 hdata
->dma_bounce_len
= 0;
80 hdata
->dma_buffer_pool
= BUF_CHIP_ALLOCED
;
83 /* check if the address of the bounce buffer is OK */
84 addr
= virt_to_bus(hdata
->dma_bounce_buffer
);
86 if (addr
& hdata
->dma_xfer_mask
) {
87 /* fall back to Chip RAM if address out of range */
88 if (hdata
->dma_buffer_pool
== BUF_SCSI_ALLOCED
) {
89 kfree(hdata
->dma_bounce_buffer
);
90 scsi_alloc_out_of_range
= 1;
92 amiga_chip_free(hdata
->dma_bounce_buffer
);
95 hdata
->dma_bounce_buffer
=
96 amiga_chip_alloc(hdata
->dma_bounce_len
,
97 "GVP II SCSI Bounce Buffer");
99 if (!hdata
->dma_bounce_buffer
) {
100 hdata
->dma_bounce_len
= 0;
104 addr
= virt_to_bus(hdata
->dma_bounce_buffer
);
105 hdata
->dma_buffer_pool
= BUF_CHIP_ALLOCED
;
109 /* copy to bounce buffer for a write */
110 memcpy(hdata
->dma_bounce_buffer
, cmd
->SCp
.ptr
,
111 cmd
->SCp
.this_residual
);
115 /* setup dma direction */
117 cntr
|= GVP11_DMAC_DIR_WRITE
;
119 hdata
->dma_dir
= dir_in
;
120 DMA(cmd
->device
->host
)->CNTR
= cntr
;
122 /* setup DMA *physical* address */
123 DMA(cmd
->device
->host
)->ACR
= addr
;
126 /* invalidate any cache */
127 cache_clear(addr
, cmd
->SCp
.this_residual
);
129 /* push any dirty cache */
130 cache_push(addr
, cmd
->SCp
.this_residual
);
133 bank_mask
= (~hdata
->dma_xfer_mask
>> 18) & 0x01c0;
135 DMA(cmd
->device
->host
)->BANK
= bank_mask
& (addr
>> 18);
138 DMA(cmd
->device
->host
)->ST_DMA
= 1;
144 static void dma_stop(struct Scsi_Host
*instance
, struct scsi_cmnd
*SCpnt
,
147 struct WD33C93_hostdata
*hdata
= shost_priv(instance
);
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
->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
;
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
));
301 if (instance
== NULL
)
303 instance
->base
= ZTWO_VADDR(address
);
304 instance
->irq
= IRQ_AMIGA_PORTS
;
305 instance
->unique_id
= z
->slotaddr
;
307 hdata
= shost_priv(instance
);
309 hdata
->dma_xfer_mask
= gvp11_xfer_mask
;
311 hdata
->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
)
318 DMA(instance
)->CNTR
= 0;
320 DMA(instance
)->BANK
= 0;
322 epc
= *(unsigned short *)(ZTWO_VADDR(address
) + 0x8000);
325 * Check for 14MHz SCSI clock
327 regs
.SASR
= &(DMA(instance
)->SASR
);
328 regs
.SCMD
= &(DMA(instance
)->SCMD
);
329 hdata
->no_sync
= 0xff;
331 hdata
->dma_mode
= CTRL_DMA
;
332 wd33c93_init(instance
, regs
, dma_setup
, dma_stop
,
333 (epc
& GVP_SCSICLKMASK
) ? WD33C93_FS_8_10
336 if (request_irq(IRQ_AMIGA_PORTS
, gvp11_intr
, IRQF_SHARED
,
337 "GVP11 SCSI", instance
))
339 DMA(instance
)->CNTR
= GVP11_DMAC_INT_ENABLE
;
344 scsi_unregister(instance
);
346 release_mem_region(address
, 256);
352 static int gvp11_bus_reset(struct scsi_cmnd
*cmd
)
354 /* FIXME perform bus-specific reset */
356 /* FIXME 2: shouldn't we no-op this function (return
357 FAILED), and fall back to host reset function,
358 wd33c93_host_reset ? */
360 spin_lock_irq(cmd
->device
->host
->host_lock
);
361 wd33c93_host_reset(cmd
);
362 spin_unlock_irq(cmd
->device
->host
->host_lock
);
372 static struct scsi_host_template driver_template
= {
373 .proc_name
= "GVP11",
374 .name
= "GVP Series II SCSI",
375 .detect
= gvp11_detect
,
376 .release
= gvp11_release
,
377 .queuecommand
= wd33c93_queuecommand
,
378 .eh_abort_handler
= wd33c93_abort
,
379 .eh_bus_reset_handler
= gvp11_bus_reset
,
380 .eh_host_reset_handler
= wd33c93_host_reset
,
381 .can_queue
= CAN_QUEUE
,
383 .sg_tablesize
= SG_ALL
,
384 .cmd_per_lun
= CMD_PER_LUN
,
385 .use_clustering
= DISABLE_CLUSTERING
389 #include "scsi_module.c"
391 int gvp11_release(struct Scsi_Host
*instance
)
394 DMA(instance
)->CNTR
= 0;
395 release_mem_region(ZTWO_PADDR(instance
->base
), 256);
396 free_irq(IRQ_AMIGA_PORTS
, instance
);
401 MODULE_LICENSE("GPL");