1 #include <linux/types.h>
4 #include <linux/sched.h>
5 #include <linux/version.h>
6 #include <linux/init.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>
22 #include<linux/stat.h>
24 struct proc_dir_entry proc_scsi_gvp11
= {
25 PROC_SCSI_GVP11
, 5, "GVP11",
26 S_IFDIR
| S_IRUGO
| S_IXUGO
, 2
29 #define DMA(ptr) ((gvp11_scsiregs *)((ptr)->base))
30 #define HDATA(ptr) ((struct WD33C93_hostdata *)((ptr)->hostdata))
32 static struct Scsi_Host
*first_instance
= NULL
;
33 static Scsi_Host_Template
*gvp11_template
;
35 static void gvp11_intr (int irq
, void *dummy
, struct pt_regs
*fp
)
39 struct Scsi_Host
*instance
;
41 for (instance
= first_instance
; instance
&&
42 instance
->hostt
== gvp11_template
; instance
= instance
->next
)
44 status
= DMA(instance
)->CNTR
;
45 if (!(status
& GVP11_DMAC_INT_PENDING
))
48 spin_lock_irqsave(&io_request_lock
, flags
);
49 wd33c93_intr (instance
);
50 spin_unlock_irqrestore(&io_request_lock
, flags
);
54 static int gvp11_xfer_mask
= 0;
56 void gvp11_setup (char *str
, int *ints
)
58 gvp11_xfer_mask
= ints
[1];
61 static int dma_setup (Scsi_Cmnd
*cmd
, int dir_in
)
63 unsigned short cntr
= GVP11_DMAC_INT_ENABLE
;
64 unsigned long addr
= virt_to_bus(cmd
->SCp
.ptr
);
66 static int scsi_alloc_out_of_range
= 0;
68 /* use bounce buffer if the physical address is bad */
69 if (addr
& HDATA(cmd
->host
)->dma_xfer_mask
||
70 (!dir_in
&& mm_end_of_chunk (addr
, cmd
->SCp
.this_residual
)))
72 HDATA(cmd
->host
)->dma_bounce_len
= (cmd
->SCp
.this_residual
+ 511)
75 if( !scsi_alloc_out_of_range
) {
76 HDATA(cmd
->host
)->dma_bounce_buffer
=
77 scsi_malloc (HDATA(cmd
->host
)->dma_bounce_len
);
78 HDATA(cmd
->host
)->dma_buffer_pool
= BUF_SCSI_ALLOCED
;
81 if ( scsi_alloc_out_of_range
|| !HDATA(cmd
->host
)->dma_bounce_buffer
) {
82 HDATA(cmd
->host
)->dma_bounce_buffer
=
83 amiga_chip_alloc(HDATA(cmd
->host
)->dma_bounce_len
);
85 if(!HDATA(cmd
->host
)->dma_bounce_buffer
)
87 HDATA(cmd
->host
)->dma_bounce_len
= 0;
91 HDATA(cmd
->host
)->dma_buffer_pool
= BUF_CHIP_ALLOCED
;
94 /* check if the address of the bounce buffer is OK */
95 addr
= virt_to_bus(HDATA(cmd
->host
)->dma_bounce_buffer
);
97 if (addr
& HDATA(cmd
->host
)->dma_xfer_mask
) {
98 /* fall back to Chip RAM if address out of range */
99 if( HDATA(cmd
->host
)->dma_buffer_pool
== BUF_SCSI_ALLOCED
) {
100 scsi_free (HDATA(cmd
->host
)->dma_bounce_buffer
,
101 HDATA(cmd
->host
)->dma_bounce_len
);
102 scsi_alloc_out_of_range
= 1;
104 amiga_chip_free (HDATA(cmd
->host
)->dma_bounce_buffer
);
107 HDATA(cmd
->host
)->dma_bounce_buffer
=
108 amiga_chip_alloc(HDATA(cmd
->host
)->dma_bounce_len
);
110 if(!HDATA(cmd
->host
)->dma_bounce_buffer
)
112 HDATA(cmd
->host
)->dma_bounce_len
= 0;
116 addr
= virt_to_bus(HDATA(cmd
->host
)->dma_bounce_buffer
);
117 HDATA(cmd
->host
)->dma_buffer_pool
= BUF_CHIP_ALLOCED
;
121 /* copy to bounce buffer for a write */
122 memcpy (HDATA(cmd
->host
)->dma_bounce_buffer
,
123 cmd
->SCp
.ptr
, cmd
->SCp
.this_residual
);
127 /* setup dma direction */
129 cntr
|= GVP11_DMAC_DIR_WRITE
;
131 HDATA(cmd
->host
)->dma_dir
= dir_in
;
132 DMA(cmd
->host
)->CNTR
= cntr
;
134 /* setup DMA *physical* address */
135 DMA(cmd
->host
)->ACR
= addr
;
138 /* invalidate any cache */
139 cache_clear (addr
, cmd
->SCp
.this_residual
);
141 /* push any dirty cache */
142 cache_push (addr
, cmd
->SCp
.this_residual
);
144 if ((bank_mask
= (~HDATA(cmd
->host
)->dma_xfer_mask
>> 18) & 0x01c0))
145 DMA(cmd
->host
)->BANK
= bank_mask
& (addr
>> 18);
148 DMA(cmd
->host
)->ST_DMA
= 1;
154 static void dma_stop (struct Scsi_Host
*instance
, Scsi_Cmnd
*SCpnt
,
158 DMA(instance
)->SP_DMA
= 1;
159 /* remove write bit from CONTROL bits */
160 DMA(instance
)->CNTR
= GVP11_DMAC_INT_ENABLE
;
162 /* copy from a bounce buffer, if necessary */
163 if (status
&& HDATA(instance
)->dma_bounce_buffer
) {
164 if (HDATA(instance
)->dma_dir
&& SCpnt
)
165 memcpy (SCpnt
->SCp
.ptr
,
166 HDATA(instance
)->dma_bounce_buffer
,
167 SCpnt
->SCp
.this_residual
);
169 if (HDATA(instance
)->dma_buffer_pool
== BUF_SCSI_ALLOCED
)
170 scsi_free (HDATA(instance
)->dma_bounce_buffer
,
171 HDATA(instance
)->dma_bounce_len
);
173 amiga_chip_free(HDATA(instance
)->dma_bounce_buffer
);
175 HDATA(instance
)->dma_bounce_buffer
= NULL
;
176 HDATA(instance
)->dma_bounce_len
= 0;
180 static int num_gvp11
= 0;
182 #define CHECK_WD33C93
184 int __init
gvp11_detect(Scsi_Host_Template
*tpnt
)
186 static unsigned char called
= 0;
187 struct Scsi_Host
*instance
;
190 unsigned int key
= 0, skey
;
191 const struct ConfigDev
*cd
;
192 unsigned int default_dma_xfer_mask
;
194 volatile unsigned char *sasr_3393
, *scmd_3393
;
195 unsigned char save_sasr
;
199 if (!MACH_IS_AMIGA
|| called
)
203 tpnt
->proc_dir
= &proc_scsi_gvp11
;
204 tpnt
->proc_info
= &wd33c93_proc_info
;
208 * This should (hopefully) be the correct way to identify
209 * all the different GVP SCSI controllers (except for the
214 if ((key
= zorro_find(ZORRO_PROD_GVP_COMBO_030_R3_SCSI
, 0, skey
)) ||
215 (key
= zorro_find(ZORRO_PROD_GVP_SERIES_II
, 0, skey
)))
216 default_dma_xfer_mask
= ~0x00ffffff;
217 else if ((key
= zorro_find(ZORRO_PROD_GVP_GFORCE_030_SCSI
, 0, skey
)) ||
218 (key
= zorro_find(ZORRO_PROD_GVP_A530_SCSI
, 0, skey
)) ||
219 (key
= zorro_find(ZORRO_PROD_GVP_COMBO_030_R4_SCSI
, 0, skey
)))
220 default_dma_xfer_mask
= ~0x01ffffff;
221 else if ((key
= zorro_find(ZORRO_PROD_GVP_A1291
, 0, skey
)) ||
222 (key
= zorro_find(ZORRO_PROD_GVP_GFORCE_040_SCSI_1
, 0, skey
)))
223 default_dma_xfer_mask
= ~0x07ffffff;
227 cd
= zorro_get_board(key
);
228 address
= cd
->cd_BoardAddr
;
231 * Rumors state that some GVP ram boards use the same product
232 * code as the SCSI controllers. Therefore if the board-size
233 * is not 64KB we asume it is a ram board and bail out.
235 if (cd
->cd_BoardSize
!= 0x10000)
241 * These darn GVP boards are a problem - it can be tough to tell
242 * whether or not they include a SCSI controller. This is the
243 * ultimate Yet-Another-GVP-Detection-Hack in that it actually
244 * probes for a WD33c93 chip: If we find one, it's extremely
245 * likely that this card supports SCSI, regardless of Product_
246 * Code, Board_Size, etc.
249 /* Get pointers to the presumed register locations and save contents */
251 sasr_3393
= &(((gvp11_scsiregs
*)(ZTWO_VADDR(address
)))->SASR
);
252 scmd_3393
= &(((gvp11_scsiregs
*)(ZTWO_VADDR(address
)))->SCMD
);
253 save_sasr
= *sasr_3393
;
255 /* First test the AuxStatus Reg */
257 q
= *sasr_3393
; /* read it */
258 if (q
& 0x08) /* bit 3 should always be clear */
260 *sasr_3393
= WD_AUXILIARY_STATUS
; /* setup indirect address */
261 if (*sasr_3393
== WD_AUXILIARY_STATUS
) { /* shouldn't retain the write */
262 *sasr_3393
= save_sasr
; /* Oops - restore this byte */
265 if (*sasr_3393
!= q
) { /* should still read the same */
266 *sasr_3393
= save_sasr
; /* Oops - restore this byte */
269 if (*scmd_3393
!= q
) /* and so should the image at 0x1f */
273 /* Ok, we probably have a wd33c93, but let's check a few other places
274 * for good measure. Make sure that this works for both 'A and 'B
278 *sasr_3393
= WD_SCSI_STATUS
;
280 *sasr_3393
= WD_SCSI_STATUS
;
282 *sasr_3393
= WD_SCSI_STATUS
;
284 *sasr_3393
= WD_SCSI_STATUS
;
286 if (qq
!= q
) /* should be read only */
288 *sasr_3393
= 0x1e; /* this register is unimplemented */
296 if (qq
!= q
|| qq
!= 0xff) /* should be read only, all 1's */
298 *sasr_3393
= WD_TIMEOUT_PERIOD
;
300 *sasr_3393
= WD_TIMEOUT_PERIOD
;
302 *sasr_3393
= WD_TIMEOUT_PERIOD
;
304 *sasr_3393
= WD_TIMEOUT_PERIOD
;
306 if (qq
!= (~q
& 0xff)) /* should be read/write */
310 instance
= scsi_register (tpnt
, sizeof (struct WD33C93_hostdata
));
311 instance
->base
= (unsigned char *)ZTWO_VADDR(address
);
312 instance
->irq
= IRQ_AMIGA_PORTS
;
313 instance
->unique_id
= key
;
316 HDATA(instance
)->dma_xfer_mask
= gvp11_xfer_mask
;
318 HDATA(instance
)->dma_xfer_mask
= default_dma_xfer_mask
;
321 DMA(instance
)->secret2
= 1;
322 DMA(instance
)->secret1
= 0;
323 DMA(instance
)->secret3
= 15;
324 while (DMA(instance
)->CNTR
& GVP11_DMAC_BUSY
) ;
325 DMA(instance
)->CNTR
= 0;
327 DMA(instance
)->BANK
= 0;
329 epc
= *(unsigned short *)(ZTWO_VADDR(address
) + 0x8000);
332 * Check for 14MHz SCSI clock
334 if (epc
& GVP_SCSICLKMASK
)
335 wd33c93_init(instance
, (wd33c93_regs
*)&(DMA(instance
)->SASR
),
336 dma_setup
, dma_stop
, WD33C93_FS_8_10
);
338 wd33c93_init(instance
, (wd33c93_regs
*)&(DMA(instance
)->SASR
),
339 dma_setup
, dma_stop
, WD33C93_FS_12_15
);
341 if (num_gvp11
++ == 0) {
342 first_instance
= instance
;
343 gvp11_template
= instance
->hostt
;
344 request_irq(IRQ_AMIGA_PORTS
, gvp11_intr
, SA_SHIRQ
,
345 "GVP11 SCSI", gvp11_intr
);
347 DMA(instance
)->CNTR
= GVP11_DMAC_INT_ENABLE
;
348 zorro_config_board(key
, 0);
361 Scsi_Host_Template driver_template
= GVP11_SCSI
;
363 #include "scsi_module.c"
367 int gvp11_release(struct Scsi_Host
*instance
)
370 DMA(instance
)->CNTR
= 0;
371 zorro_unconfig_board(instance
->unique_id
, 0);
372 if (--num_gvp11
== 0)
373 free_irq(IRQ_AMIGA_PORTS
, gvp11_intr
);