Linux 2.6.22-rc3
[linux-2.6/next.git] / drivers / scsi / cyberstormII.c
blobe336e853e66fb03affd5524e6f37a74519ad401c
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/init.h>
19 #include <linux/kernel.h>
20 #include <linux/delay.h>
21 #include <linux/types.h>
22 #include <linux/string.h>
23 #include <linux/slab.h>
24 #include <linux/blkdev.h>
25 #include <linux/proc_fs.h>
26 #include <linux/stat.h>
27 #include <linux/interrupt.h>
29 #include "scsi.h"
30 #include <scsi/scsi_host.h>
31 #include "NCR53C9x.h"
33 #include <linux/zorro.h>
34 #include <asm/irq.h>
35 #include <asm/amigaints.h>
36 #include <asm/amigahw.h>
38 #include <asm/pgtable.h>
40 /* The controller registers can be found in the Z2 config area at these
41 * offsets:
43 #define CYBERII_ESP_ADDR 0x1ff03
44 #define CYBERII_DMA_ADDR 0x1ff43
47 /* The CyberStorm II DMA interface */
48 struct cyberII_dma_registers {
49 volatile unsigned char cond_reg; /* DMA cond (ro) [0x000] */
50 #define ctrl_reg cond_reg /* DMA control (wo) [0x000] */
51 unsigned char dmapad4[0x3f];
52 volatile unsigned char dma_addr0; /* DMA address (MSB) [0x040] */
53 unsigned char dmapad1[3];
54 volatile unsigned char dma_addr1; /* DMA address [0x044] */
55 unsigned char dmapad2[3];
56 volatile unsigned char dma_addr2; /* DMA address [0x048] */
57 unsigned char dmapad3[3];
58 volatile unsigned char dma_addr3; /* DMA address (LSB) [0x04c] */
61 /* DMA control bits */
62 #define CYBERII_DMA_LED 0x02 /* HD led control 1 = on */
64 static int dma_bytes_sent(struct NCR_ESP *esp, int fifo_count);
65 static int dma_can_transfer(struct NCR_ESP *esp, Scsi_Cmnd *sp);
66 static void dma_dump_state(struct NCR_ESP *esp);
67 static void dma_init_read(struct NCR_ESP *esp, __u32 addr, int length);
68 static void dma_init_write(struct NCR_ESP *esp, __u32 addr, int length);
69 static void dma_ints_off(struct NCR_ESP *esp);
70 static void dma_ints_on(struct NCR_ESP *esp);
71 static int dma_irq_p(struct NCR_ESP *esp);
72 static void dma_led_off(struct NCR_ESP *esp);
73 static void dma_led_on(struct NCR_ESP *esp);
74 static int dma_ports_p(struct NCR_ESP *esp);
75 static void dma_setup(struct NCR_ESP *esp, __u32 addr, int count, int write);
77 static volatile unsigned char cmd_buffer[16];
78 /* This is where all commands are put
79 * before they are transferred to the ESP chip
80 * via PIO.
83 /***************************************************************** Detection */
84 int __init cyberII_esp_detect(struct scsi_host_template *tpnt)
86 struct NCR_ESP *esp;
87 struct zorro_dev *z = NULL;
88 unsigned long address;
89 struct ESP_regs *eregs;
91 if ((z = zorro_find_device(ZORRO_PROD_PHASE5_CYBERSTORM_MK_II, z))) {
92 unsigned long board = z->resource.start;
93 if (request_mem_region(board+CYBERII_ESP_ADDR,
94 sizeof(struct ESP_regs), "NCR53C9x")) {
95 /* Do some magic to figure out if the CyberStorm Mk II
96 * is equipped with a SCSI controller
98 address = (unsigned long)ZTWO_VADDR(board);
99 eregs = (struct ESP_regs *)(address + CYBERII_ESP_ADDR);
101 esp = esp_allocate(tpnt, (void *)board + CYBERII_ESP_ADDR, 0);
103 esp_write(eregs->esp_cfg1, (ESP_CONFIG1_PENABLE | 7));
104 udelay(5);
105 if(esp_read(eregs->esp_cfg1) != (ESP_CONFIG1_PENABLE | 7)) {
106 esp_deallocate(esp);
107 scsi_unregister(esp->ehost);
108 release_mem_region(board+CYBERII_ESP_ADDR,
109 sizeof(struct ESP_regs));
110 return 0; /* Bail out if address did not hold data */
113 /* Do command transfer with programmed I/O */
114 esp->do_pio_cmds = 1;
116 /* Required functions */
117 esp->dma_bytes_sent = &dma_bytes_sent;
118 esp->dma_can_transfer = &dma_can_transfer;
119 esp->dma_dump_state = &dma_dump_state;
120 esp->dma_init_read = &dma_init_read;
121 esp->dma_init_write = &dma_init_write;
122 esp->dma_ints_off = &dma_ints_off;
123 esp->dma_ints_on = &dma_ints_on;
124 esp->dma_irq_p = &dma_irq_p;
125 esp->dma_ports_p = &dma_ports_p;
126 esp->dma_setup = &dma_setup;
128 /* Optional functions */
129 esp->dma_barrier = 0;
130 esp->dma_drain = 0;
131 esp->dma_invalidate = 0;
132 esp->dma_irq_entry = 0;
133 esp->dma_irq_exit = 0;
134 esp->dma_led_on = &dma_led_on;
135 esp->dma_led_off = &dma_led_off;
136 esp->dma_poll = 0;
137 esp->dma_reset = 0;
139 /* SCSI chip speed */
140 esp->cfreq = 40000000;
142 /* The DMA registers on the CyberStorm are mapped
143 * relative to the device (i.e. in the same Zorro
144 * I/O block).
146 esp->dregs = (void *)(address + CYBERII_DMA_ADDR);
148 /* ESP register base */
149 esp->eregs = eregs;
151 /* Set the command buffer */
152 esp->esp_command = cmd_buffer;
153 esp->esp_command_dvma = virt_to_bus((void *)cmd_buffer);
155 esp->irq = IRQ_AMIGA_PORTS;
156 request_irq(IRQ_AMIGA_PORTS, esp_intr, IRQF_SHARED,
157 "CyberStorm SCSI Mk II", esp->ehost);
159 /* Figure out our scsi ID on the bus */
160 esp->scsi_id = 7;
162 /* We don't have a differential SCSI-bus. */
163 esp->diff = 0;
165 esp_initialize(esp);
167 printk("ESP: Total of %d ESP hosts found, %d actually in use.\n", nesps, esps_in_use);
168 esps_running = esps_in_use;
169 return esps_in_use;
172 return 0;
175 /************************************************************* DMA Functions */
176 static int dma_bytes_sent(struct NCR_ESP *esp, int fifo_count)
178 /* Since the CyberStorm DMA is fully dedicated to the ESP chip,
179 * the number of bytes sent (to the ESP chip) equals the number
180 * of bytes in the FIFO - there is no buffering in the DMA controller.
181 * XXXX Do I read this right? It is from host to ESP, right?
183 return fifo_count;
186 static int dma_can_transfer(struct NCR_ESP *esp, Scsi_Cmnd *sp)
188 /* I don't think there's any limit on the CyberDMA. So we use what
189 * the ESP chip can handle (24 bit).
191 unsigned long sz = sp->SCp.this_residual;
192 if(sz > 0x1000000)
193 sz = 0x1000000;
194 return sz;
197 static void dma_dump_state(struct NCR_ESP *esp)
199 ESPLOG(("esp%d: dma -- cond_reg<%02x>\n",
200 esp->esp_id, ((struct cyberII_dma_registers *)
201 (esp->dregs))->cond_reg));
202 ESPLOG(("intreq:<%04x>, intena:<%04x>\n",
203 amiga_custom.intreqr, amiga_custom.intenar));
206 static void dma_init_read(struct NCR_ESP *esp, __u32 addr, int length)
208 struct cyberII_dma_registers *dregs =
209 (struct cyberII_dma_registers *) esp->dregs;
211 cache_clear(addr, length);
213 addr &= ~(1);
214 dregs->dma_addr0 = (addr >> 24) & 0xff;
215 dregs->dma_addr1 = (addr >> 16) & 0xff;
216 dregs->dma_addr2 = (addr >> 8) & 0xff;
217 dregs->dma_addr3 = (addr ) & 0xff;
220 static void dma_init_write(struct NCR_ESP *esp, __u32 addr, int length)
222 struct cyberII_dma_registers *dregs =
223 (struct cyberII_dma_registers *) esp->dregs;
225 cache_push(addr, length);
227 addr |= 1;
228 dregs->dma_addr0 = (addr >> 24) & 0xff;
229 dregs->dma_addr1 = (addr >> 16) & 0xff;
230 dregs->dma_addr2 = (addr >> 8) & 0xff;
231 dregs->dma_addr3 = (addr ) & 0xff;
234 static void dma_ints_off(struct NCR_ESP *esp)
236 disable_irq(esp->irq);
239 static void dma_ints_on(struct NCR_ESP *esp)
241 enable_irq(esp->irq);
244 static int dma_irq_p(struct NCR_ESP *esp)
246 /* It's important to check the DMA IRQ bit in the correct way! */
247 return (esp_read(esp->eregs->esp_status) & ESP_STAT_INTR);
250 static void dma_led_off(struct NCR_ESP *esp)
252 ((struct cyberII_dma_registers *)(esp->dregs))->ctrl_reg &= ~CYBERII_DMA_LED;
255 static void dma_led_on(struct NCR_ESP *esp)
257 ((struct cyberII_dma_registers *)(esp->dregs))->ctrl_reg |= CYBERII_DMA_LED;
260 static int dma_ports_p(struct NCR_ESP *esp)
262 return ((amiga_custom.intenar) & IF_PORTS);
265 static void dma_setup(struct NCR_ESP *esp, __u32 addr, int count, int write)
267 /* On the Sparc, DMA_ST_WRITE means "move data from device to memory"
268 * so when (write) is true, it actually means READ!
270 if(write){
271 dma_init_read(esp, addr, count);
272 } else {
273 dma_init_write(esp, addr, count);
277 #define HOSTS_C
279 int cyberII_esp_release(struct Scsi_Host *instance)
281 #ifdef MODULE
282 unsigned long address = (unsigned long)((struct NCR_ESP *)instance->hostdata)->edev;
284 esp_deallocate((struct NCR_ESP *)instance->hostdata);
285 esp_release();
286 release_mem_region(address, sizeof(struct ESP_regs));
287 free_irq(IRQ_AMIGA_PORTS, esp_intr);
288 #endif
289 return 1;
293 static struct scsi_host_template driver_template = {
294 .proc_name = "esp-cyberstormII",
295 .proc_info = esp_proc_info,
296 .name = "CyberStorm Mk II SCSI",
297 .detect = cyberII_esp_detect,
298 .slave_alloc = esp_slave_alloc,
299 .slave_destroy = esp_slave_destroy,
300 .release = cyberII_esp_release,
301 .queuecommand = esp_queue,
302 .eh_abort_handler = esp_abort,
303 .eh_bus_reset_handler = esp_reset,
304 .can_queue = 7,
305 .this_id = 7,
306 .sg_tablesize = SG_ALL,
307 .cmd_per_lun = 1,
308 .use_clustering = ENABLE_CLUSTERING
312 #include "scsi_module.c"
314 MODULE_LICENSE("GPL");