1 /* cyberstorm.c: Driver for CyberStorm SCSI Controller.
3 * Copyright (C) 1996 Jesper Skov (jskov@cygnus.co.uk)
5 * The CyberStorm SCSI driver is based on David S. Miller's ESP driver
6 * for the Sparc computers.
8 * This work was made possible by Phase5 who willingly (and most generously)
9 * supported me with hardware and all the information I needed.
14 * 1) Figure out how to make a cleaner merge with the sparc driver with regard
15 * to the caches and the Sparc MMU mapping.
16 * 2) Make as few routines required outside the generic driver. A lot of the
17 * routines in this file used to be inline!
20 #include <linux/module.h>
22 #include <linux/init.h>
23 #include <linux/kernel.h>
24 #include <linux/delay.h>
25 #include <linux/types.h>
26 #include <linux/string.h>
27 #include <linux/malloc.h>
28 #include <linux/blk.h>
29 #include <linux/proc_fs.h>
30 #include <linux/stat.h>
35 #include "cyberstorm.h"
37 #include <linux/zorro.h>
39 #include <asm/amigaints.h>
40 #include <asm/amigahw.h>
42 #include <asm/pgtable.h>
44 static int dma_bytes_sent(struct NCR_ESP
*esp
, int fifo_count
);
45 static int dma_can_transfer(struct NCR_ESP
*esp
, Scsi_Cmnd
*sp
);
46 static void dma_dump_state(struct NCR_ESP
*esp
);
47 static void dma_init_read(struct NCR_ESP
*esp
, __u32 addr
, int length
);
48 static void dma_init_write(struct NCR_ESP
*esp
, __u32 addr
, int length
);
49 static void dma_ints_off(struct NCR_ESP
*esp
);
50 static void dma_ints_on(struct NCR_ESP
*esp
);
51 static int dma_irq_p(struct NCR_ESP
*esp
);
52 static void dma_led_off(struct NCR_ESP
*esp
);
53 static void dma_led_on(struct NCR_ESP
*esp
);
54 static int dma_ports_p(struct NCR_ESP
*esp
);
55 static void dma_setup(struct NCR_ESP
*esp
, __u32 addr
, int count
, int write
);
57 static unsigned char ctrl_data
= 0; /* Keep backup of the stuff written
58 * to ctrl_reg. Always write a copy
59 * to this register when writing to
60 * the hardware register!
63 volatile unsigned char cmd_buffer
[16];
64 /* This is where all commands are put
65 * before they are transfered to the ESP chip
69 /***************************************************************** Detection */
70 int __init
cyber_esp_detect(Scsi_Host_Template
*tpnt
)
73 struct zorro_dev
*z
= NULL
;
74 unsigned long address
;
76 while ((z
= zorro_find_device(ZORRO_WILDCARD
, z
))) {
77 unsigned long board
= z
->resource
.start
;
78 if ((z
->id
== ZORRO_PROD_PHASE5_BLIZZARD_1220_CYBERSTORM
||
79 z
->id
== ZORRO_PROD_PHASE5_BLIZZARD_1230_II_FASTLANE_Z3_CYBERSCSI_CYBERSTORM060
) &&
80 request_mem_region(board
+CYBER_ESP_ADDR
,
81 sizeof(struct ESP_regs
), "NCR53C9x")) {
82 /* Figure out if this is a CyberStorm or really a
83 * Fastlane/Blizzard Mk II by looking at the board size.
84 * CyberStorm maps 64kB
85 * (ZORRO_PROD_PHASE5_BLIZZARD_1220_CYBERSTORM does anyway)
87 if(z
->resource
.end
-board
!= 0xffff) {
88 release_mem_region(board
+CYBER_ESP_ADDR
,
89 sizeof(struct ESP_regs
));
92 esp
= esp_allocate(tpnt
, (void *)board
+CYBER_ESP_ADDR
);
94 /* Do command transfer with programmed I/O */
97 /* Required functions */
98 esp
->dma_bytes_sent
= &dma_bytes_sent
;
99 esp
->dma_can_transfer
= &dma_can_transfer
;
100 esp
->dma_dump_state
= &dma_dump_state
;
101 esp
->dma_init_read
= &dma_init_read
;
102 esp
->dma_init_write
= &dma_init_write
;
103 esp
->dma_ints_off
= &dma_ints_off
;
104 esp
->dma_ints_on
= &dma_ints_on
;
105 esp
->dma_irq_p
= &dma_irq_p
;
106 esp
->dma_ports_p
= &dma_ports_p
;
107 esp
->dma_setup
= &dma_setup
;
109 /* Optional functions */
110 esp
->dma_barrier
= 0;
112 esp
->dma_invalidate
= 0;
113 esp
->dma_irq_entry
= 0;
114 esp
->dma_irq_exit
= 0;
115 esp
->dma_led_on
= &dma_led_on
;
116 esp
->dma_led_off
= &dma_led_off
;
120 /* SCSI chip speed */
121 esp
->cfreq
= 40000000;
123 /* The DMA registers on the CyberStorm are mapped
124 * relative to the device (i.e. in the same Zorro
127 address
= (unsigned long)ZTWO_VADDR(board
);
128 esp
->dregs
= (void *)(address
+ CYBER_DMA_ADDR
);
130 /* ESP register base */
131 esp
->eregs
= (struct ESP_regs
*)(address
+ CYBER_ESP_ADDR
);
133 /* Set the command buffer */
134 esp
->esp_command
= (volatile unsigned char*) cmd_buffer
;
135 esp
->esp_command_dvma
= virt_to_bus(cmd_buffer
);
137 esp
->irq
= IRQ_AMIGA_PORTS
;
138 request_irq(IRQ_AMIGA_PORTS
, esp_intr
, SA_SHIRQ
,
139 "CyberStorm SCSI", esp_intr
);
140 /* Figure out our scsi ID on the bus */
141 /* The DMA cond flag contains a hardcoded jumper bit
142 * which can be used to select host number 6 or 7.
143 * However, even though it may change, we use a hardcoded
148 /* We don't have a differential SCSI-bus. */
153 printk("ESP: Total of %d ESP hosts found, %d actually in use.\n", nesps
, esps_in_use
);
154 esps_running
= esps_in_use
;
161 /************************************************************* DMA Functions */
162 static int dma_bytes_sent(struct NCR_ESP
*esp
, int fifo_count
)
164 /* Since the CyberStorm DMA is fully dedicated to the ESP chip,
165 * the number of bytes sent (to the ESP chip) equals the number
166 * of bytes in the FIFO - there is no buffering in the DMA controller.
167 * XXXX Do I read this right? It is from host to ESP, right?
172 static int dma_can_transfer(struct NCR_ESP
*esp
, Scsi_Cmnd
*sp
)
174 /* I don't think there's any limit on the CyberDMA. So we use what
175 * the ESP chip can handle (24 bit).
177 unsigned long sz
= sp
->SCp
.this_residual
;
183 static void dma_dump_state(struct NCR_ESP
*esp
)
185 ESPLOG(("esp%d: dma -- cond_reg<%02x>\n",
186 esp
->esp_id
, ((struct cyber_dma_registers
*)
187 (esp
->dregs
))->cond_reg
));
188 ESPLOG(("intreq:<%04x>, intena:<%04x>\n",
189 custom
.intreqr
, custom
.intenar
));
192 static void dma_init_read(struct NCR_ESP
*esp
, __u32 addr
, int length
)
194 struct cyber_dma_registers
*dregs
=
195 (struct cyber_dma_registers
*) esp
->dregs
;
197 cache_clear(addr
, length
);
200 dregs
->dma_addr0
= (addr
>> 24) & 0xff;
201 dregs
->dma_addr1
= (addr
>> 16) & 0xff;
202 dregs
->dma_addr2
= (addr
>> 8) & 0xff;
203 dregs
->dma_addr3
= (addr
) & 0xff;
204 ctrl_data
&= ~(CYBER_DMA_WRITE
);
206 /* Check if physical address is outside Z2 space and of
207 * block length/block aligned in memory. If this is the
208 * case, enable 32 bit transfer. In all other cases, fall back
209 * to 16 bit transfer.
210 * Obviously 32 bit transfer should be enabled if the DMA address
211 * and length are 32 bit aligned. However, this leads to some
212 * strange behavior. Even 64 bit aligned addr/length fails.
213 * Until I've found a reason for this, 32 bit transfer is only
214 * used for full-block transfers (1kB).
218 if((addr
& 0x3fc) || length
& 0x3ff || ((addr
> 0x200000) &&
220 ctrl_data
&= ~(CYBER_DMA_Z3
); /* Z2, do 16 bit DMA */
222 ctrl_data
|= CYBER_DMA_Z3
; /* CHIP/Z3, do 32 bit DMA */
224 ctrl_data
&= ~(CYBER_DMA_Z3
); /* Z2, do 16 bit DMA */
226 dregs
->ctrl_reg
= ctrl_data
;
229 static void dma_init_write(struct NCR_ESP
*esp
, __u32 addr
, int length
)
231 struct cyber_dma_registers
*dregs
=
232 (struct cyber_dma_registers
*) esp
->dregs
;
234 cache_push(addr
, length
);
237 dregs
->dma_addr0
= (addr
>> 24) & 0xff;
238 dregs
->dma_addr1
= (addr
>> 16) & 0xff;
239 dregs
->dma_addr2
= (addr
>> 8) & 0xff;
240 dregs
->dma_addr3
= (addr
) & 0xff;
241 ctrl_data
|= CYBER_DMA_WRITE
;
243 /* See comment above */
245 if((addr
& 0x3fc) || length
& 0x3ff || ((addr
> 0x200000) &&
247 ctrl_data
&= ~(CYBER_DMA_Z3
); /* Z2, do 16 bit DMA */
249 ctrl_data
|= CYBER_DMA_Z3
; /* CHIP/Z3, do 32 bit DMA */
251 ctrl_data
&= ~(CYBER_DMA_Z3
); /* Z2, do 16 bit DMA */
253 dregs
->ctrl_reg
= ctrl_data
;
256 static void dma_ints_off(struct NCR_ESP
*esp
)
258 disable_irq(esp
->irq
);
261 static void dma_ints_on(struct NCR_ESP
*esp
)
263 enable_irq(esp
->irq
);
266 static int dma_irq_p(struct NCR_ESP
*esp
)
268 /* It's important to check the DMA IRQ bit in the correct way! */
269 return ((esp_read(esp
->eregs
->esp_status
) & ESP_STAT_INTR
) &&
270 ((((struct cyber_dma_registers
*)(esp
->dregs
))->cond_reg
) &
271 CYBER_DMA_HNDL_INTR
));
274 static void dma_led_off(struct NCR_ESP
*esp
)
276 ctrl_data
&= ~CYBER_DMA_LED
;
277 ((struct cyber_dma_registers
*)(esp
->dregs
))->ctrl_reg
= ctrl_data
;
280 static void dma_led_on(struct NCR_ESP
*esp
)
282 ctrl_data
|= CYBER_DMA_LED
;
283 ((struct cyber_dma_registers
*)(esp
->dregs
))->ctrl_reg
= ctrl_data
;
286 static int dma_ports_p(struct NCR_ESP
*esp
)
288 return ((custom
.intenar
) & IF_PORTS
);
291 static void dma_setup(struct NCR_ESP
*esp
, __u32 addr
, int count
, int write
)
293 /* On the Sparc, DMA_ST_WRITE means "move data from device to memory"
294 * so when (write) is true, it actually means READ!
297 dma_init_read(esp
, addr
, count
);
299 dma_init_write(esp
, addr
, count
);
305 #include "cyberstorm.h"
307 static Scsi_Host_Template driver_template
= SCSI_CYBERSTORM
;
309 #include "scsi_module.c"
311 int cyber_esp_release(struct Scsi_Host
*instance
)
314 unsigned long address
= (unsigned long)((struct NCR_ESP
*)instance
->hostdata
)->edev
;
316 esp_deallocate((struct NCR_ESP
*)instance
->hostdata
);
318 release_mem_region(address
, sizeof(struct ESP_regs
));
319 free_irq(IRQ_AMIGA_PORTS
, esp_intr
);