1 /* fastlane.c: Driver for Phase5's Fastlane SCSI Controller.
3 * Copyright (C) 1996 Jesper Skov (jskov@cygnus.co.uk)
5 * This driver is based on the CyberStorm driver, hence the occasional
6 * reference to CyberStorm.
8 * Betatesting & crucial adjustments by
9 * Patrik Rak (prak3264@ss1000.ms.mff.cuni.cz)
15 * o According to the doc from laire, it is required to reset the DMA when
16 * the transfer is done. ATM we reset DMA just before every new
17 * dma_init_(read|write).
19 * 1) Figure out how to make a cleaner merge with the sparc driver with regard
20 * to the caches and the Sparc MMU mapping.
21 * 2) Make as few routines required outside the generic driver. A lot of the
22 * routines in this file used to be inline!
25 #include <linux/module.h>
27 #include <linux/init.h>
28 #include <linux/kernel.h>
29 #include <linux/delay.h>
30 #include <linux/types.h>
31 #include <linux/string.h>
32 #include <linux/slab.h>
33 #include <linux/blk.h>
34 #include <linux/proc_fs.h>
35 #include <linux/stat.h>
42 #include <linux/zorro.h>
45 #include <asm/amigaints.h>
46 #include <asm/amigahw.h>
48 #include <asm/pgtable.h>
50 /* Such day has just come... */
52 /* Let this defined unless you really need to enable DMA IRQ one day */
56 static int dma_bytes_sent(struct NCR_ESP *esp, int fifo_count);
57 static int dma_can_transfer(struct NCR_ESP *esp, Scsi_Cmnd *sp);
58 static inline void dma_clear(struct NCR_ESP *esp);
59 static void dma_dump_state(struct NCR_ESP *esp);
60 static void dma_init_read(struct NCR_ESP *esp, __u32 addr, int length);
61 static void dma_init_write(struct NCR_ESP *esp, __u32 vaddr, int length);
62 static void dma_ints_off(struct NCR_ESP *esp);
63 static void dma_ints_on(struct NCR_ESP *esp);
64 static int dma_irq_p(struct NCR_ESP *esp);
65 static void dma_irq_exit(struct NCR_ESP *esp);
66 static void dma_led_off(struct NCR_ESP *esp);
67 static void dma_led_on(struct NCR_ESP *esp);
68 static int dma_ports_p(struct NCR_ESP *esp);
69 static void dma_setup(struct NCR_ESP *esp, __u32 addr, int count, int write);
71 static unsigned char ctrl_data = 0; /* Keep backup of the stuff written
72 * to ctrl_reg. Always write a copy
73 * to this register when writing to
74 * the hardware register!
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
83 /***************************************************************** Detection */
84 int __init fastlane_esp_detect(Scsi_Host_Template *tpnt)
87 struct zorro_dev *z = NULL;
88 unsigned long address;
90 if ((z = zorro_find_device(ZORRO_PROD_PHASE5_BLIZZARD_1230_II_FASTLANE_Z3_CYBERSCSI_CYBERSTORM060, z))) {
91 unsigned long board = z->resource.start;
92 if (request_mem_region(board+FASTLANE_ESP_ADDR,
93 sizeof(struct ESP_regs), "NCR53C9x")) {
94 /* Check if this is really a fastlane controller. The problem
95 * is that also the cyberstorm and blizzard controllers use
96 * this ID value. Fortunately only Fastlane maps in Z3 space
98 if (board < 0x1000000) {
101 esp = esp_allocate(tpnt, (void *)board+FASTLANE_ESP_ADDR);
103 /* Do command transfer with programmed I/O */
104 esp->do_pio_cmds = 1;
106 /* Required functions */
107 esp->dma_bytes_sent = &dma_bytes_sent;
108 esp->dma_can_transfer = &dma_can_transfer;
109 esp->dma_dump_state = &dma_dump_state;
110 esp->dma_init_read = &dma_init_read;
111 esp->dma_init_write = &dma_init_write;
112 esp->dma_ints_off = &dma_ints_off;
113 esp->dma_ints_on = &dma_ints_on;
114 esp->dma_irq_p = &dma_irq_p;
115 esp->dma_ports_p = &dma_ports_p;
116 esp->dma_setup = &dma_setup;
118 /* Optional functions */
119 esp->dma_barrier = 0;
121 esp->dma_invalidate = 0;
122 esp->dma_irq_entry = 0;
123 esp->dma_irq_exit = &dma_irq_exit;
124 esp->dma_led_on = &dma_led_on;
125 esp->dma_led_off = &dma_led_off;
129 /* Initialize the portBits (enable IRQs) */
130 ctrl_data = (FASTLANE_DMA_FCODE |
137 /* SCSI chip clock */
138 esp->cfreq = 40000000;
141 /* Map the physical address space into virtual kernel space */
142 address = (unsigned long)
143 ioremap_nocache(board, z->resource.end-board+1);
146 printk("Could not remap Fastlane controller memory!");
151 /* The DMA registers on the Fastlane are mapped
152 * relative to the device (i.e. in the same Zorro
155 esp->dregs = (void *)(address + FASTLANE_DMA_ADDR);
157 /* ESP register base */
158 esp->eregs = (struct ESP_regs *)(address + FASTLANE_ESP_ADDR);
161 esp->edev = (void *) address;
163 /* Set the command buffer */
164 esp->esp_command = (volatile unsigned char*) cmd_buffer;
165 esp->esp_command_dvma = virt_to_bus(cmd_buffer);
167 esp->irq = IRQ_AMIGA_PORTS;
168 esp->slot = board+FASTLANE_ESP_ADDR;
169 if (request_irq(IRQ_AMIGA_PORTS, esp_intr, SA_SHIRQ,
170 "Fastlane SCSI", esp_intr)) {
171 printk(KERN_WARNING "Fastlane: Could not get IRQ%d, aborting.\n", IRQ_AMIGA_PORTS);
178 /* We don't have a differential SCSI-bus. */
184 printk("ESP: Total of %d ESP hosts found, %d actually in use.\n", nesps, esps_in_use);
185 esps_running = esps_in_use;
192 iounmap((void *)address);
194 scsi_unregister (esp->ehost);
196 release_mem_region(z->resource.start+FASTLANE_ESP_ADDR,
197 sizeof(struct ESP_regs));
202 /************************************************************* DMA Functions */
203 static int dma_bytes_sent(struct NCR_ESP *esp, int fifo_count)
205 /* Since the Fastlane DMA is fully dedicated to the ESP chip,
206 * the number of bytes sent (to the ESP chip) equals the number
207 * of bytes in the FIFO - there is no buffering in the DMA controller.
208 * XXXX Do I read this right? It is from host to ESP, right?
213 static int dma_can_transfer(struct NCR_ESP *esp, Scsi_Cmnd *sp)
215 unsigned long sz = sp->SCp.this_residual;
221 static void dma_dump_state(struct NCR_ESP *esp)
223 ESPLOG(("esp%d: dma -- cond_reg<%02x>\n",
224 esp->esp_id, ((struct fastlane_dma_registers *)
225 (esp->dregs))->cond_reg));
226 ESPLOG(("intreq:<%04x>, intena:<%04x>\n",
227 custom.intreqr, custom.intenar));
230 static void dma_init_read(struct NCR_ESP *esp, __u32 addr, int length)
232 struct fastlane_dma_registers *dregs =
233 (struct fastlane_dma_registers *) (esp->dregs);
236 cache_clear(addr, length);
240 t = (unsigned long *)((addr & 0x00ffffff) + esp->edev);
242 dregs->clear_strobe = 0;
245 ctrl_data = (ctrl_data & FASTLANE_DMA_MASK) | FASTLANE_DMA_ENABLE;
246 dregs->ctrl_reg = ctrl_data;
249 static void dma_init_write(struct NCR_ESP *esp, __u32 addr, int length)
251 struct fastlane_dma_registers *dregs =
252 (struct fastlane_dma_registers *) (esp->dregs);
255 cache_push(addr, length);
259 t = (unsigned long *)((addr & 0x00ffffff) + (esp->edev));
261 dregs->clear_strobe = 0;
264 ctrl_data = ((ctrl_data & FASTLANE_DMA_MASK) |
265 FASTLANE_DMA_ENABLE |
267 dregs->ctrl_reg = ctrl_data;
270 static inline void dma_clear(struct NCR_ESP *esp)
272 struct fastlane_dma_registers *dregs =
273 (struct fastlane_dma_registers *) (esp->dregs);
276 ctrl_data = (ctrl_data & FASTLANE_DMA_MASK);
277 dregs->ctrl_reg = ctrl_data;
279 t = (unsigned long *)(esp->edev);
281 dregs->clear_strobe = 0;
286 static void dma_ints_off(struct NCR_ESP *esp)
288 disable_irq(esp->irq);
291 static void dma_ints_on(struct NCR_ESP *esp)
293 enable_irq(esp->irq);
296 static void dma_irq_exit(struct NCR_ESP *esp)
298 struct fastlane_dma_registers *dregs =
299 (struct fastlane_dma_registers *) (esp->dregs);
301 dregs->ctrl_reg = ctrl_data & ~(FASTLANE_DMA_EDI|FASTLANE_DMA_ESI);
305 dregs->ctrl_reg = ctrl_data;
308 static int dma_irq_p(struct NCR_ESP *esp)
310 struct fastlane_dma_registers *dregs =
311 (struct fastlane_dma_registers *) (esp->dregs);
312 unsigned char dma_status;
314 dma_status = dregs->cond_reg;
316 if(dma_status & FASTLANE_DMA_IACT)
317 return 0; /* not our IRQ */
319 /* Return non-zero if ESP requested IRQ */
322 (dma_status & FASTLANE_DMA_CREQ) &&
324 (!(dma_status & FASTLANE_DMA_MINT)) &&
325 (esp_read(((struct ESP_regs *) (esp->eregs))->esp_status) & ESP_STAT_INTR));
328 static void dma_led_off(struct NCR_ESP *esp)
330 ctrl_data &= ~FASTLANE_DMA_LED;
331 ((struct fastlane_dma_registers *)(esp->dregs))->ctrl_reg = ctrl_data;
334 static void dma_led_on(struct NCR_ESP *esp)
336 ctrl_data |= FASTLANE_DMA_LED;
337 ((struct fastlane_dma_registers *)(esp->dregs))->ctrl_reg = ctrl_data;
340 static int dma_ports_p(struct NCR_ESP *esp)
342 return ((custom.intenar) & IF_PORTS);
345 static void dma_setup(struct NCR_ESP *esp, __u32 addr, int count, int write)
347 /* On the Sparc, DMA_ST_WRITE means "move data from device to memory"
348 * so when (write) is true, it actually means READ!
351 dma_init_read(esp, addr, count);
353 dma_init_write(esp, addr, count);
359 #include "fastlane.h"
361 static Scsi_Host_Template driver_template = SCSI_FASTLANE;
362 #include "scsi_module.c"
364 int fastlane_esp_release(struct Scsi_Host *instance)
367 unsigned long address = (unsigned long)((struct NCR_ESP *)instance->hostdata)->edev;
368 esp_deallocate((struct NCR_ESP *)instance->hostdata);
370 release_mem_region(address, sizeof(struct ESP_regs));
371 free_irq(IRQ_AMIGA_PORTS, esp_intr);
376 MODULE_LICENSE("GPL");