1 #include <linux/types.h>
3 #include <linux/blkdev.h>
4 #include <linux/init.h>
5 #include <linux/interrupt.h>
9 #include <asm/pgtable.h>
10 #include <asm/amigaints.h>
11 #include <asm/amigahw.h>
12 #include <linux/zorro.h>
14 #include <linux/spinlock.h>
17 #include <scsi/scsi_host.h>
21 #include<linux/stat.h>
23 #define DMA(ptr) ((gvp11_scsiregs *)((ptr)->base))
24 #define HDATA(ptr) ((struct WD33C93_hostdata *)((ptr)->hostdata))
26 static irqreturn_t
gvp11_intr (int irq
, void *_instance
)
30 struct Scsi_Host
*instance
= (struct Scsi_Host
*)_instance
;
32 status
= DMA(instance
)->CNTR
;
33 if (!(status
& GVP11_DMAC_INT_PENDING
))
36 spin_lock_irqsave(instance
->host_lock
, flags
);
37 wd33c93_intr(instance
);
38 spin_unlock_irqrestore(instance
->host_lock
, flags
);
42 static int gvp11_xfer_mask
= 0;
44 void gvp11_setup (char *str
, int *ints
)
46 gvp11_xfer_mask
= ints
[1];
49 static int dma_setup(struct scsi_cmnd
*cmd
, int dir_in
)
51 unsigned short cntr
= GVP11_DMAC_INT_ENABLE
;
52 unsigned long addr
= virt_to_bus(cmd
->SCp
.ptr
);
54 static int scsi_alloc_out_of_range
= 0;
56 /* use bounce buffer if the physical address is bad */
57 if (addr
& HDATA(cmd
->device
->host
)->dma_xfer_mask
)
59 HDATA(cmd
->device
->host
)->dma_bounce_len
= (cmd
->SCp
.this_residual
+ 511)
62 if( !scsi_alloc_out_of_range
) {
63 HDATA(cmd
->device
->host
)->dma_bounce_buffer
=
64 kmalloc (HDATA(cmd
->device
->host
)->dma_bounce_len
, GFP_KERNEL
);
65 HDATA(cmd
->device
->host
)->dma_buffer_pool
= BUF_SCSI_ALLOCED
;
68 if (scsi_alloc_out_of_range
||
69 !HDATA(cmd
->device
->host
)->dma_bounce_buffer
) {
70 HDATA(cmd
->device
->host
)->dma_bounce_buffer
=
71 amiga_chip_alloc(HDATA(cmd
->device
->host
)->dma_bounce_len
,
72 "GVP II SCSI Bounce Buffer");
74 if(!HDATA(cmd
->device
->host
)->dma_bounce_buffer
)
76 HDATA(cmd
->device
->host
)->dma_bounce_len
= 0;
80 HDATA(cmd
->device
->host
)->dma_buffer_pool
= BUF_CHIP_ALLOCED
;
83 /* check if the address of the bounce buffer is OK */
84 addr
= virt_to_bus(HDATA(cmd
->device
->host
)->dma_bounce_buffer
);
86 if (addr
& HDATA(cmd
->device
->host
)->dma_xfer_mask
) {
87 /* fall back to Chip RAM if address out of range */
88 if( HDATA(cmd
->device
->host
)->dma_buffer_pool
== BUF_SCSI_ALLOCED
) {
89 kfree (HDATA(cmd
->device
->host
)->dma_bounce_buffer
);
90 scsi_alloc_out_of_range
= 1;
92 amiga_chip_free (HDATA(cmd
->device
->host
)->dma_bounce_buffer
);
95 HDATA(cmd
->device
->host
)->dma_bounce_buffer
=
96 amiga_chip_alloc(HDATA(cmd
->device
->host
)->dma_bounce_len
,
97 "GVP II SCSI Bounce Buffer");
99 if(!HDATA(cmd
->device
->host
)->dma_bounce_buffer
)
101 HDATA(cmd
->device
->host
)->dma_bounce_len
= 0;
105 addr
= virt_to_bus(HDATA(cmd
->device
->host
)->dma_bounce_buffer
);
106 HDATA(cmd
->device
->host
)->dma_buffer_pool
= BUF_CHIP_ALLOCED
;
110 /* copy to bounce buffer for a write */
111 memcpy (HDATA(cmd
->device
->host
)->dma_bounce_buffer
,
112 cmd
->SCp
.ptr
, cmd
->SCp
.this_residual
);
116 /* setup dma direction */
118 cntr
|= GVP11_DMAC_DIR_WRITE
;
120 HDATA(cmd
->device
->host
)->dma_dir
= dir_in
;
121 DMA(cmd
->device
->host
)->CNTR
= cntr
;
123 /* setup DMA *physical* address */
124 DMA(cmd
->device
->host
)->ACR
= addr
;
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
);
133 if ((bank_mask
= (~HDATA(cmd
->device
->host
)->dma_xfer_mask
>> 18) & 0x01c0))
134 DMA(cmd
->device
->host
)->BANK
= bank_mask
& (addr
>> 18);
137 DMA(cmd
->device
->host
)->ST_DMA
= 1;
143 static void dma_stop(struct Scsi_Host
*instance
, struct scsi_cmnd
*SCpnt
,
147 DMA(instance
)->SP_DMA
= 1;
148 /* remove write bit from CONTROL bits */
149 DMA(instance
)->CNTR
= GVP11_DMAC_INT_ENABLE
;
151 /* copy from a bounce buffer, if necessary */
152 if (status
&& HDATA(instance
)->dma_bounce_buffer
) {
153 if (HDATA(instance
)->dma_dir
&& SCpnt
)
154 memcpy (SCpnt
->SCp
.ptr
,
155 HDATA(instance
)->dma_bounce_buffer
,
156 SCpnt
->SCp
.this_residual
);
158 if (HDATA(instance
)->dma_buffer_pool
== BUF_SCSI_ALLOCED
)
159 kfree (HDATA(instance
)->dma_bounce_buffer
);
161 amiga_chip_free(HDATA(instance
)->dma_bounce_buffer
);
163 HDATA(instance
)->dma_bounce_buffer
= NULL
;
164 HDATA(instance
)->dma_bounce_len
= 0;
168 #define CHECK_WD33C93
170 int __init
gvp11_detect(struct scsi_host_template
*tpnt
)
172 static unsigned char called
= 0;
173 struct Scsi_Host
*instance
;
174 unsigned long address
;
176 struct zorro_dev
*z
= NULL
;
177 unsigned int default_dma_xfer_mask
;
181 volatile unsigned char *sasr_3393
, *scmd_3393
;
182 unsigned char save_sasr
;
186 if (!MACH_IS_AMIGA
|| called
)
190 tpnt
->proc_name
= "GVP11";
191 tpnt
->proc_info
= &wd33c93_proc_info
;
193 while ((z
= zorro_find_device(ZORRO_WILDCARD
, z
))) {
195 * This should (hopefully) be the correct way to identify
196 * all the different GVP SCSI controllers (except for the
200 if (z
->id
== ZORRO_PROD_GVP_COMBO_030_R3_SCSI
||
201 z
->id
== ZORRO_PROD_GVP_SERIES_II
)
202 default_dma_xfer_mask
= ~0x00ffffff;
203 else if (z
->id
== ZORRO_PROD_GVP_GFORCE_030_SCSI
||
204 z
->id
== ZORRO_PROD_GVP_A530_SCSI
||
205 z
->id
== ZORRO_PROD_GVP_COMBO_030_R4_SCSI
)
206 default_dma_xfer_mask
= ~0x01ffffff;
207 else if (z
->id
== ZORRO_PROD_GVP_A1291
||
208 z
->id
== ZORRO_PROD_GVP_GFORCE_040_SCSI_1
)
209 default_dma_xfer_mask
= ~0x07ffffff;
214 * Rumors state that some GVP ram boards use the same product
215 * code as the SCSI controllers. Therefore if the board-size
216 * is not 64KB we asume it is a ram board and bail out.
218 if (z
->resource
.end
-z
->resource
.start
!= 0xffff)
221 address
= z
->resource
.start
;
222 if (!request_mem_region(address
, 256, "wd33c93"))
228 * These darn GVP boards are a problem - it can be tough to tell
229 * whether or not they include a SCSI controller. This is the
230 * ultimate Yet-Another-GVP-Detection-Hack in that it actually
231 * probes for a WD33c93 chip: If we find one, it's extremely
232 * likely that this card supports SCSI, regardless of Product_
233 * Code, Board_Size, etc.
236 /* Get pointers to the presumed register locations and save contents */
238 sasr_3393
= &(((gvp11_scsiregs
*)(ZTWO_VADDR(address
)))->SASR
);
239 scmd_3393
= &(((gvp11_scsiregs
*)(ZTWO_VADDR(address
)))->SCMD
);
240 save_sasr
= *sasr_3393
;
242 /* First test the AuxStatus Reg */
244 q
= *sasr_3393
; /* read it */
245 if (q
& 0x08) /* bit 3 should always be clear */
247 *sasr_3393
= WD_AUXILIARY_STATUS
; /* setup indirect address */
248 if (*sasr_3393
== WD_AUXILIARY_STATUS
) { /* shouldn't retain the write */
249 *sasr_3393
= save_sasr
; /* Oops - restore this byte */
252 if (*sasr_3393
!= q
) { /* should still read the same */
253 *sasr_3393
= save_sasr
; /* Oops - restore this byte */
256 if (*scmd_3393
!= q
) /* and so should the image at 0x1f */
260 /* Ok, we probably have a wd33c93, but let's check a few other places
261 * for good measure. Make sure that this works for both 'A and 'B
265 *sasr_3393
= WD_SCSI_STATUS
;
267 *sasr_3393
= WD_SCSI_STATUS
;
269 *sasr_3393
= WD_SCSI_STATUS
;
271 *sasr_3393
= WD_SCSI_STATUS
;
273 if (qq
!= q
) /* should be read only */
275 *sasr_3393
= 0x1e; /* this register is unimplemented */
283 if (qq
!= q
|| qq
!= 0xff) /* should be read only, all 1's */
285 *sasr_3393
= WD_TIMEOUT_PERIOD
;
287 *sasr_3393
= WD_TIMEOUT_PERIOD
;
289 *sasr_3393
= WD_TIMEOUT_PERIOD
;
291 *sasr_3393
= WD_TIMEOUT_PERIOD
;
293 if (qq
!= (~q
& 0xff)) /* should be read/write */
297 instance
= scsi_register (tpnt
, sizeof (struct WD33C93_hostdata
));
300 instance
->base
= ZTWO_VADDR(address
);
301 instance
->irq
= IRQ_AMIGA_PORTS
;
302 instance
->unique_id
= z
->slotaddr
;
305 HDATA(instance
)->dma_xfer_mask
= gvp11_xfer_mask
;
307 HDATA(instance
)->dma_xfer_mask
= default_dma_xfer_mask
;
310 DMA(instance
)->secret2
= 1;
311 DMA(instance
)->secret1
= 0;
312 DMA(instance
)->secret3
= 15;
313 while (DMA(instance
)->CNTR
& GVP11_DMAC_BUSY
) ;
314 DMA(instance
)->CNTR
= 0;
316 DMA(instance
)->BANK
= 0;
318 epc
= *(unsigned short *)(ZTWO_VADDR(address
) + 0x8000);
321 * Check for 14MHz SCSI clock
323 regs
.SASR
= &(DMA(instance
)->SASR
);
324 regs
.SCMD
= &(DMA(instance
)->SCMD
);
325 wd33c93_init(instance
, regs
, dma_setup
, dma_stop
,
326 (epc
& GVP_SCSICLKMASK
) ? WD33C93_FS_8_10
329 request_irq(IRQ_AMIGA_PORTS
, gvp11_intr
, IRQF_SHARED
, "GVP11 SCSI",
331 DMA(instance
)->CNTR
= GVP11_DMAC_INT_ENABLE
;
336 release_mem_region(address
, 256);
342 static int gvp11_bus_reset(struct scsi_cmnd
*cmd
)
344 /* FIXME perform bus-specific reset */
346 /* FIXME 2: shouldn't we no-op this function (return
347 FAILED), and fall back to host reset function,
348 wd33c93_host_reset ? */
350 spin_lock_irq(cmd
->device
->host
->host_lock
);
351 wd33c93_host_reset(cmd
);
352 spin_unlock_irq(cmd
->device
->host
->host_lock
);
362 static struct scsi_host_template driver_template
= {
363 .proc_name
= "GVP11",
364 .name
= "GVP Series II SCSI",
365 .detect
= gvp11_detect
,
366 .release
= gvp11_release
,
367 .queuecommand
= wd33c93_queuecommand
,
368 .eh_abort_handler
= wd33c93_abort
,
369 .eh_bus_reset_handler
= gvp11_bus_reset
,
370 .eh_host_reset_handler
= wd33c93_host_reset
,
371 .can_queue
= CAN_QUEUE
,
373 .sg_tablesize
= SG_ALL
,
374 .cmd_per_lun
= CMD_PER_LUN
,
375 .use_clustering
= DISABLE_CLUSTERING
379 #include "scsi_module.c"
381 int gvp11_release(struct Scsi_Host
*instance
)
384 DMA(instance
)->CNTR
= 0;
385 release_mem_region(ZTWO_PADDR(instance
->base
), 256);
386 free_irq(IRQ_AMIGA_PORTS
, instance
);
392 MODULE_LICENSE("GPL");