1 /* blz1230.c: Driver for Blizzard 1230 SCSI IV 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.
11 * 1) Figure out how to make a cleaner merge with the sparc driver with regard
12 * to the caches and the Sparc MMU mapping.
13 * 2) Make as few routines required outside the generic driver. A lot of the
14 * routines in this file used to be inline!
17 #include <linux/module.h>
19 #include <linux/init.h>
20 #include <linux/kernel.h>
21 #include <linux/delay.h>
22 #include <linux/types.h>
23 #include <linux/string.h>
24 #include <linux/malloc.h>
25 #include <linux/blk.h>
26 #include <linux/proc_fs.h>
27 #include <linux/stat.h>
34 #include <linux/zorro.h>
36 #include <asm/amigaints.h>
37 #include <asm/amigahw.h>
39 #include <asm/pgtable.h>
43 static int dma_bytes_sent(struct NCR_ESP
*esp
, int fifo_count
);
44 static int dma_can_transfer(struct NCR_ESP
*esp
, Scsi_Cmnd
*sp
);
45 static void dma_dump_state(struct NCR_ESP
*esp
);
46 static void dma_init_read(struct NCR_ESP
*esp
, __u32 addr
, int length
);
47 static void dma_init_write(struct NCR_ESP
*esp
, __u32 addr
, int length
);
48 static void dma_ints_off(struct NCR_ESP
*esp
);
49 static void dma_ints_on(struct NCR_ESP
*esp
);
50 static int dma_irq_p(struct NCR_ESP
*esp
);
51 static int dma_ports_p(struct NCR_ESP
*esp
);
52 static void dma_setup(struct NCR_ESP
*esp
, __u32 addr
, int count
, int write
);
54 volatile unsigned char cmd_buffer
[16];
55 /* This is where all commands are put
56 * before they are transfered to the ESP chip
60 /***************************************************************** Detection */
61 int __init
blz1230_esp_detect(Scsi_Host_Template
*tpnt
)
64 struct zorro_dev
*z
= NULL
;
65 unsigned long address
;
66 struct ESP_regs
*eregs
;
69 #define REAL_BLZ1230_ID ZORRO_PROD_PHASE5_BLIZZARD_1230_IV_1260
70 #define REAL_BLZ1230_ESP_ADDR BLZ1230_ESP_ADDR
71 #define REAL_BLZ1230_DMA_ADDR BLZ1230_DMA_ADDR
73 #define REAL_BLZ1230_ID ZORRO_PROD_PHASE5_BLIZZARD_1230_II_FASTLANE_Z3_CYBERSCSI_CYBERSTORM060
74 #define REAL_BLZ1230_ESP_ADDR BLZ1230II_ESP_ADDR
75 #define REAL_BLZ1230_DMA_ADDR BLZ1230II_DMA_ADDR
78 if ((z
= zorro_find_device(REAL_BLZ1230_ID
, z
))) {
79 unsigned long board
= z
->resource
.start
;
80 if (request_mem_region(board
+REAL_BLZ1230_ESP_ADDR
,
81 sizeof(struct ESP_regs
), "NCR53C9x")) {
82 /* Do some magic to figure out if the blizzard is
83 * equipped with a SCSI controller
85 address
= ZTWO_VADDR(board
);
86 eregs
= (struct ESP_regs
*)(address
+ REAL_BLZ1230_ESP_ADDR
);
87 esp
= esp_allocate(tpnt
, (void *)board
+REAL_BLZ1230_ESP_ADDR
);
89 esp_write(eregs
->esp_cfg1
, (ESP_CONFIG1_PENABLE
| 7));
91 if(esp_read(eregs
->esp_cfg1
) != (ESP_CONFIG1_PENABLE
| 7)){
93 scsi_unregister(esp
->ehost
);
94 release_mem_region(board
+REAL_BLZ1230_ESP_ADDR
,
95 sizeof(struct ESP_regs
));
96 return 0; /* Bail out if address did not hold data */
99 /* Do command transfer with programmed I/O */
100 esp
->do_pio_cmds
= 1;
102 /* Required functions */
103 esp
->dma_bytes_sent
= &dma_bytes_sent
;
104 esp
->dma_can_transfer
= &dma_can_transfer
;
105 esp
->dma_dump_state
= &dma_dump_state
;
106 esp
->dma_init_read
= &dma_init_read
;
107 esp
->dma_init_write
= &dma_init_write
;
108 esp
->dma_ints_off
= &dma_ints_off
;
109 esp
->dma_ints_on
= &dma_ints_on
;
110 esp
->dma_irq_p
= &dma_irq_p
;
111 esp
->dma_ports_p
= &dma_ports_p
;
112 esp
->dma_setup
= &dma_setup
;
114 /* Optional functions */
115 esp
->dma_barrier
= 0;
117 esp
->dma_invalidate
= 0;
118 esp
->dma_irq_entry
= 0;
119 esp
->dma_irq_exit
= 0;
121 esp
->dma_led_off
= 0;
125 /* SCSI chip speed */
126 esp
->cfreq
= 40000000;
128 /* The DMA registers on the Blizzard are mapped
129 * relative to the device (i.e. in the same Zorro
132 esp
->dregs
= (void *)(address
+ REAL_BLZ1230_DMA_ADDR
);
134 /* ESP register base */
137 /* Set the command buffer */
138 esp
->esp_command
= (volatile unsigned char*) cmd_buffer
;
139 esp
->esp_command_dvma
= virt_to_bus(cmd_buffer
);
141 esp
->irq
= IRQ_AMIGA_PORTS
;
142 esp
->slot
= board
+REAL_BLZ1230_ESP_ADDR
;
143 request_irq(IRQ_AMIGA_PORTS
, esp_intr
, SA_SHIRQ
,
144 "Blizzard 1230 SCSI IV", esp_intr
);
146 /* Figure out our scsi ID on the bus */
149 /* We don't have a differential SCSI-bus. */
154 printk("ESP: Total of %d ESP hosts found, %d actually in use.\n", nesps
, esps_in_use
);
155 esps_running
= esps_in_use
;
162 /************************************************************* DMA Functions */
163 static int dma_bytes_sent(struct NCR_ESP
*esp
, int fifo_count
)
165 /* Since the Blizzard DMA is fully dedicated to the ESP chip,
166 * the number of bytes sent (to the ESP chip) equals the number
167 * of bytes in the FIFO - there is no buffering in the DMA controller.
168 * XXXX Do I read this right? It is from host to ESP, right?
173 static int dma_can_transfer(struct NCR_ESP
*esp
, Scsi_Cmnd
*sp
)
175 /* I don't think there's any limit on the Blizzard DMA. So we use what
176 * the ESP chip can handle (24 bit).
178 unsigned long sz
= sp
->SCp
.this_residual
;
184 static void dma_dump_state(struct NCR_ESP
*esp
)
186 ESPLOG(("intreq:<%04x>, intena:<%04x>\n",
187 custom
.intreqr
, custom
.intenar
));
190 void dma_init_read(struct NCR_ESP
*esp
, __u32 addr
, int length
)
193 struct blz1230_dma_registers
*dregs
=
194 (struct blz1230_dma_registers
*) (esp
->dregs
);
196 struct blz1230II_dma_registers
*dregs
=
197 (struct blz1230II_dma_registers
*) (esp
->dregs
);
200 cache_clear(addr
, length
);
203 addr
&= ~(BLZ1230_DMA_WRITE
);
205 /* First set latch */
206 dregs
->dma_latch
= (addr
>> 24) & 0xff;
208 /* Then pump the address to the DMA address register */
210 dregs
->dma_addr
= (addr
>> 24) & 0xff;
212 dregs
->dma_addr
= (addr
>> 16) & 0xff;
213 dregs
->dma_addr
= (addr
>> 8) & 0xff;
214 dregs
->dma_addr
= (addr
) & 0xff;
217 void dma_init_write(struct NCR_ESP
*esp
, __u32 addr
, int length
)
220 struct blz1230_dma_registers
*dregs
=
221 (struct blz1230_dma_registers
*) (esp
->dregs
);
223 struct blz1230II_dma_registers
*dregs
=
224 (struct blz1230II_dma_registers
*) (esp
->dregs
);
227 cache_push(addr
, length
);
230 addr
|= BLZ1230_DMA_WRITE
;
232 /* First set latch */
233 dregs
->dma_latch
= (addr
>> 24) & 0xff;
235 /* Then pump the address to the DMA address register */
237 dregs
->dma_addr
= (addr
>> 24) & 0xff;
239 dregs
->dma_addr
= (addr
>> 16) & 0xff;
240 dregs
->dma_addr
= (addr
>> 8) & 0xff;
241 dregs
->dma_addr
= (addr
) & 0xff;
244 static void dma_ints_off(struct NCR_ESP
*esp
)
246 disable_irq(esp
->irq
);
249 static void dma_ints_on(struct NCR_ESP
*esp
)
251 enable_irq(esp
->irq
);
254 static int dma_irq_p(struct NCR_ESP
*esp
)
256 return (esp_read(esp
->eregs
->esp_status
) & ESP_STAT_INTR
);
259 static int dma_ports_p(struct NCR_ESP
*esp
)
261 return ((custom
.intenar
) & IF_PORTS
);
264 static void dma_setup(struct NCR_ESP
*esp
, __u32 addr
, int count
, int write
)
266 /* On the Sparc, DMA_ST_WRITE means "move data from device to memory"
267 * so when (write) is true, it actually means READ!
270 dma_init_read(esp
, addr
, count
);
272 dma_init_write(esp
, addr
, count
);
280 static Scsi_Host_Template driver_template
= SCSI_BLZ1230
;
282 #include "scsi_module.c"
284 int blz1230_esp_release(struct Scsi_Host
*instance
)
287 unsigned long address
= (unsigned long)((struct NCR_ESP
*)instance
->hostdata
)->edev
;
288 esp_deallocate((struct NCR_ESP
*)instance
->hostdata
);
290 release_mem_region(address
, sizeof(struct ESP_regs
));
291 free_irq(IRQ_AMIGA_PORTS
, esp_intr
);