* added 0.99 linux version
[mascara-docs.git] / i386 / linux / linux-2.3.21 / drivers / scsi / cyberstormII.c
blob3f2b85de819e69f7ff133e4864b5853d34168d56
1 /* cyberstormII.c: Driver for CyberStorm SCSI Mk II
3 * Copyright (C) 1996 Jesper Skov (jskov@cygnus.co.uk)
5 * This driver is based on cyberstorm.c
6 */
8 /* TODO:
10 * 1) Figure out how to make a cleaner merge with the sparc driver with regard
11 * to the caches and the Sparc MMU mapping.
12 * 2) Make as few routines required outside the generic driver. A lot of the
13 * routines in this file used to be inline!
16 #include <linux/module.h>
18 #include <linux/kernel.h>
19 #include <linux/delay.h>
20 #include <linux/types.h>
21 #include <linux/string.h>
22 #include <linux/malloc.h>
23 #include <linux/blk.h>
24 #include <linux/proc_fs.h>
25 #include <linux/stat.h>
27 #include "scsi.h"
28 #include "hosts.h"
29 #include "NCR53C9x.h"
30 #include "cyberstormII.h"
32 #include <linux/zorro.h>
33 #include <asm/irq.h>
34 #include <asm/amigaints.h>
35 #include <asm/amigahw.h>
37 #include <asm/pgtable.h>
39 static int dma_bytes_sent(struct NCR_ESP *esp, int fifo_count);
40 static int dma_can_transfer(struct NCR_ESP *esp, Scsi_Cmnd *sp);
41 static void dma_dump_state(struct NCR_ESP *esp);
42 static void dma_init_read(struct NCR_ESP *esp, __u32 addr, int length);
43 static void dma_init_write(struct NCR_ESP *esp, __u32 addr, int length);
44 static void dma_ints_off(struct NCR_ESP *esp);
45 static void dma_ints_on(struct NCR_ESP *esp);
46 static int dma_irq_p(struct NCR_ESP *esp);
47 static void dma_led_off(struct NCR_ESP *esp);
48 static void dma_led_on(struct NCR_ESP *esp);
49 static int dma_ports_p(struct NCR_ESP *esp);
50 static void dma_setup(struct NCR_ESP *esp, __u32 addr, int count, int write);
52 volatile unsigned char cmd_buffer[16];
53 /* This is where all commands are put
54 * before they are transfered to the ESP chip
55 * via PIO.
58 /***************************************************************** Detection */
59 int __init cyberII_esp_detect(Scsi_Host_Template *tpnt)
61 struct NCR_ESP *esp;
62 const struct ConfigDev *esp_dev;
63 unsigned int key;
64 unsigned long address;
65 struct ESP_regs *eregs;
67 if((key = zorro_find(ZORRO_PROD_PHASE5_CYBERSTORM_MK_II, 0, 0))){
68 esp_dev = zorro_get_board(key);
70 /* Do some magic to figure out if the CyberStorm Mk II
71 * is equipped with a SCSI controller
73 address = (unsigned long)ZTWO_VADDR(esp_dev->cd_BoardAddr);
74 eregs = (struct ESP_regs *)(address + CYBERII_ESP_ADDR);
76 esp = esp_allocate(tpnt, (void *) esp_dev);
78 esp_write(eregs->esp_cfg1, (ESP_CONFIG1_PENABLE | 7));
79 udelay(5);
80 if(esp_read(eregs->esp_cfg1) != (ESP_CONFIG1_PENABLE | 7)) {
81 esp_deallocate(esp);
82 scsi_unregister(esp->ehost);
83 return 0; /* Bail out if address did not hold data */
86 /* Do command transfer with programmed I/O */
87 esp->do_pio_cmds = 1;
89 /* Required functions */
90 esp->dma_bytes_sent = &dma_bytes_sent;
91 esp->dma_can_transfer = &dma_can_transfer;
92 esp->dma_dump_state = &dma_dump_state;
93 esp->dma_init_read = &dma_init_read;
94 esp->dma_init_write = &dma_init_write;
95 esp->dma_ints_off = &dma_ints_off;
96 esp->dma_ints_on = &dma_ints_on;
97 esp->dma_irq_p = &dma_irq_p;
98 esp->dma_ports_p = &dma_ports_p;
99 esp->dma_setup = &dma_setup;
101 /* Optional functions */
102 esp->dma_barrier = 0;
103 esp->dma_drain = 0;
104 esp->dma_invalidate = 0;
105 esp->dma_irq_entry = 0;
106 esp->dma_irq_exit = 0;
107 esp->dma_led_on = &dma_led_on;
108 esp->dma_led_off = &dma_led_off;
109 esp->dma_poll = 0;
110 esp->dma_reset = 0;
112 /* SCSI chip speed */
113 esp->cfreq = 40000000;
115 /* The DMA registers on the CyberStorm are mapped
116 * relative to the device (i.e. in the same Zorro
117 * I/O block).
119 esp->dregs = (void *)(address + CYBERII_DMA_ADDR);
121 /* ESP register base */
122 esp->eregs = eregs;
124 /* Set the command buffer */
125 esp->esp_command = (volatile unsigned char*) cmd_buffer;
126 esp->esp_command_dvma = virt_to_bus(cmd_buffer);
128 esp->irq = IRQ_AMIGA_PORTS;
129 esp->slot = key;
130 request_irq(IRQ_AMIGA_PORTS, esp_intr, SA_SHIRQ,
131 "CyberStorm SCSI Mk II", esp_intr);
133 /* Figure out our scsi ID on the bus */
134 esp->scsi_id = 7;
136 /* We don't have a differential SCSI-bus. */
137 esp->diff = 0;
139 esp_initialize(esp);
141 zorro_config_board(key, 0);
143 printk("ESP: Total of %d ESP hosts found, %d actually in use.\n", nesps, esps_in_use);
144 esps_running = esps_in_use;
145 return esps_in_use;
147 return 0;
150 /************************************************************* DMA Functions */
151 static int dma_bytes_sent(struct NCR_ESP *esp, int fifo_count)
153 /* Since the CyberStorm DMA is fully dedicated to the ESP chip,
154 * the number of bytes sent (to the ESP chip) equals the number
155 * of bytes in the FIFO - there is no buffering in the DMA controller.
156 * XXXX Do I read this right? It is from host to ESP, right?
158 return fifo_count;
161 static int dma_can_transfer(struct NCR_ESP *esp, Scsi_Cmnd *sp)
163 /* I don't think there's any limit on the CyberDMA. So we use what
164 * the ESP chip can handle (24 bit).
166 unsigned long sz = sp->SCp.this_residual;
167 if(sz > 0x1000000)
168 sz = 0x1000000;
169 return sz;
172 static void dma_dump_state(struct NCR_ESP *esp)
174 ESPLOG(("esp%d: dma -- cond_reg<%02x>\n",
175 esp->esp_id, ((struct cyberII_dma_registers *)
176 (esp->dregs))->cond_reg));
177 ESPLOG(("intreq:<%04x>, intena:<%04x>\n",
178 custom.intreqr, custom.intenar));
181 static void dma_init_read(struct NCR_ESP *esp, __u32 addr, int length)
183 struct cyberII_dma_registers *dregs =
184 (struct cyberII_dma_registers *) esp->dregs;
186 cache_clear(addr, length);
188 addr &= ~(1);
189 dregs->dma_addr0 = (addr >> 24) & 0xff;
190 dregs->dma_addr1 = (addr >> 16) & 0xff;
191 dregs->dma_addr2 = (addr >> 8) & 0xff;
192 dregs->dma_addr3 = (addr ) & 0xff;
195 static void dma_init_write(struct NCR_ESP *esp, __u32 addr, int length)
197 struct cyberII_dma_registers *dregs =
198 (struct cyberII_dma_registers *) esp->dregs;
200 cache_push(addr, length);
202 addr |= 1;
203 dregs->dma_addr0 = (addr >> 24) & 0xff;
204 dregs->dma_addr1 = (addr >> 16) & 0xff;
205 dregs->dma_addr2 = (addr >> 8) & 0xff;
206 dregs->dma_addr3 = (addr ) & 0xff;
209 static void dma_ints_off(struct NCR_ESP *esp)
211 disable_irq(esp->irq);
214 static void dma_ints_on(struct NCR_ESP *esp)
216 enable_irq(esp->irq);
219 static int dma_irq_p(struct NCR_ESP *esp)
221 /* It's important to check the DMA IRQ bit in the correct way! */
222 return (esp_read(esp->eregs->esp_status) & ESP_STAT_INTR);
225 static void dma_led_off(struct NCR_ESP *esp)
227 ((struct cyberII_dma_registers *)(esp->dregs))->ctrl_reg &= ~CYBERII_DMA_LED;
230 static void dma_led_on(struct NCR_ESP *esp)
232 ((struct cyberII_dma_registers *)(esp->dregs))->ctrl_reg |= CYBERII_DMA_LED;
235 static int dma_ports_p(struct NCR_ESP *esp)
237 return ((custom.intenar) & IF_PORTS);
240 static void dma_setup(struct NCR_ESP *esp, __u32 addr, int count, int write)
242 /* On the Sparc, DMA_ST_WRITE means "move data from device to memory"
243 * so when (write) is true, it actually means READ!
245 if(write){
246 dma_init_read(esp, addr, count);
247 } else {
248 dma_init_write(esp, addr, count);
252 #ifdef MODULE
254 #define HOSTS_C
256 #include "cyberstormII.h"
258 Scsi_Host_Template driver_template = SCSI_CYBERSTORMII;
260 #include "scsi_module.c"
262 #endif
264 int cyberII_esp_release(struct Scsi_Host *instance)
266 #ifdef MODULE
267 unsigned int key;
269 key = ((struct NCR_ESP *)instance->hostdata)->slot;
270 esp_deallocate((struct NCR_ESP *)instance->hostdata);
271 esp_release();
272 zorro_unconfig_board(key, 0);
273 free_irq(IRQ_AMIGA_PORTS, esp_intr);
274 #endif
275 return 1;