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/kernel.h>
20 #include <linux/delay.h>
21 #include <linux/types.h>
22 #include <linux/string.h>
23 #include <linux/malloc.h>
24 #include <linux/blk.h>
25 #include <linux/proc_fs.h>
26 #include <linux/stat.h>
33 #include <linux/zorro.h>
35 #include <asm/amigaints.h>
36 #include <asm/amigahw.h>
38 #include <asm/pgtable.h>
42 static int dma_bytes_sent(struct NCR_ESP
*esp
, int fifo_count
);
43 static int dma_can_transfer(struct NCR_ESP
*esp
, Scsi_Cmnd
*sp
);
44 static void dma_dump_state(struct NCR_ESP
*esp
);
45 static void dma_init_read(struct NCR_ESP
*esp
, __u32 addr
, int length
);
46 static void dma_init_write(struct NCR_ESP
*esp
, __u32 addr
, int length
);
47 static void dma_ints_off(struct NCR_ESP
*esp
);
48 static void dma_ints_on(struct NCR_ESP
*esp
);
49 static int dma_irq_p(struct NCR_ESP
*esp
);
50 static int dma_ports_p(struct NCR_ESP
*esp
);
51 static void dma_setup(struct NCR_ESP
*esp
, __u32 addr
, int count
, int write
);
53 volatile unsigned char cmd_buffer
[16];
54 /* This is where all commands are put
55 * before they are transfered to the ESP chip
59 /***************************************************************** Detection */
60 int __init
blz1230_esp_detect(Scsi_Host_Template
*tpnt
)
63 const struct ConfigDev
*esp_dev
;
65 unsigned long address
;
66 struct ESP_regs
*eregs
;
69 if ((key
= zorro_find(ZORRO_PROD_PHASE5_BLIZZARD_1230_IV_1260
, 0, 0))){
71 if ((key
= zorro_find(ZORRO_PROD_PHASE5_BLIZZARD_1230_II_FASTLANE_Z3_CYBERSCSI_CYBERSTORM060
, 0, 0))){
73 esp_dev
= zorro_get_board(key
);
75 /* Do some magic to figure out if the blizzard is
76 * equipped with a SCSI controller
78 address
= (unsigned long)ZTWO_VADDR(esp_dev
->cd_BoardAddr
);
80 eregs
= (struct ESP_regs
*)(address
+ BLZ1230_ESP_ADDR
);
82 eregs
= (struct ESP_regs
*)(address
+ BLZ1230II_ESP_ADDR
);
85 esp
= esp_allocate(tpnt
, (void *) esp_dev
);
87 esp_write(eregs
->esp_cfg1
, (ESP_CONFIG1_PENABLE
| 7));
89 if(esp_read(eregs
->esp_cfg1
) != (ESP_CONFIG1_PENABLE
| 7)){
91 scsi_unregister(esp
->ehost
);
92 return 0; /* Bail out if address did not hold data */
95 /* Do command transfer with programmed I/O */
98 /* Required functions */
99 esp
->dma_bytes_sent
= &dma_bytes_sent
;
100 esp
->dma_can_transfer
= &dma_can_transfer
;
101 esp
->dma_dump_state
= &dma_dump_state
;
102 esp
->dma_init_read
= &dma_init_read
;
103 esp
->dma_init_write
= &dma_init_write
;
104 esp
->dma_ints_off
= &dma_ints_off
;
105 esp
->dma_ints_on
= &dma_ints_on
;
106 esp
->dma_irq_p
= &dma_irq_p
;
107 esp
->dma_ports_p
= &dma_ports_p
;
108 esp
->dma_setup
= &dma_setup
;
110 /* Optional functions */
111 esp
->dma_barrier
= 0;
113 esp
->dma_invalidate
= 0;
114 esp
->dma_irq_entry
= 0;
115 esp
->dma_irq_exit
= 0;
117 esp
->dma_led_off
= 0;
121 /* SCSI chip speed */
122 esp
->cfreq
= 40000000;
124 /* The DMA registers on the Blizzard are mapped
125 * relative to the device (i.e. in the same Zorro
129 esp
->dregs
= (void *)(address
+ BLZ1230_DMA_ADDR
);
131 esp
->dregs
= (void *)(address
+ BLZ1230II_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
;
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 zorro_config_board(key
, 0);
156 printk("ESP: Total of %d ESP hosts found, %d actually in use.\n", nesps
, esps_in_use
);
157 esps_running
= esps_in_use
;
163 /************************************************************* DMA Functions */
164 static int dma_bytes_sent(struct NCR_ESP
*esp
, int fifo_count
)
166 /* Since the Blizzard DMA is fully dedicated to the ESP chip,
167 * the number of bytes sent (to the ESP chip) equals the number
168 * of bytes in the FIFO - there is no buffering in the DMA controller.
169 * XXXX Do I read this right? It is from host to ESP, right?
174 static int dma_can_transfer(struct NCR_ESP
*esp
, Scsi_Cmnd
*sp
)
176 /* I don't think there's any limit on the Blizzard DMA. So we use what
177 * the ESP chip can handle (24 bit).
179 unsigned long sz
= sp
->SCp
.this_residual
;
185 static void dma_dump_state(struct NCR_ESP
*esp
)
187 ESPLOG(("intreq:<%04x>, intena:<%04x>\n",
188 custom
.intreqr
, custom
.intenar
));
191 void dma_init_read(struct NCR_ESP
*esp
, __u32 addr
, int length
)
194 struct blz1230_dma_registers
*dregs
=
195 (struct blz1230_dma_registers
*) (esp
->dregs
);
197 struct blz1230II_dma_registers
*dregs
=
198 (struct blz1230II_dma_registers
*) (esp
->dregs
);
201 cache_clear(addr
, length
);
204 addr
&= ~(BLZ1230_DMA_WRITE
);
206 /* First set latch */
207 dregs
->dma_latch
= (addr
>> 24) & 0xff;
209 /* Then pump the address to the DMA address register */
211 dregs
->dma_addr
= (addr
>> 24) & 0xff;
213 dregs
->dma_addr
= (addr
>> 16) & 0xff;
214 dregs
->dma_addr
= (addr
>> 8) & 0xff;
215 dregs
->dma_addr
= (addr
) & 0xff;
218 void dma_init_write(struct NCR_ESP
*esp
, __u32 addr
, int length
)
221 struct blz1230_dma_registers
*dregs
=
222 (struct blz1230_dma_registers
*) (esp
->dregs
);
224 struct blz1230II_dma_registers
*dregs
=
225 (struct blz1230II_dma_registers
*) (esp
->dregs
);
228 cache_push(addr
, length
);
231 addr
|= BLZ1230_DMA_WRITE
;
233 /* First set latch */
234 dregs
->dma_latch
= (addr
>> 24) & 0xff;
236 /* Then pump the address to the DMA address register */
238 dregs
->dma_addr
= (addr
>> 24) & 0xff;
240 dregs
->dma_addr
= (addr
>> 16) & 0xff;
241 dregs
->dma_addr
= (addr
>> 8) & 0xff;
242 dregs
->dma_addr
= (addr
) & 0xff;
245 static void dma_ints_off(struct NCR_ESP
*esp
)
247 disable_irq(esp
->irq
);
250 static void dma_ints_on(struct NCR_ESP
*esp
)
252 enable_irq(esp
->irq
);
255 static int dma_irq_p(struct NCR_ESP
*esp
)
257 return (esp_read(esp
->eregs
->esp_status
) & ESP_STAT_INTR
);
260 static int dma_ports_p(struct NCR_ESP
*esp
)
262 return ((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!
271 dma_init_read(esp
, addr
, count
);
273 dma_init_write(esp
, addr
, count
);
283 Scsi_Host_Template driver_template
= SCSI_BLZ1230
;
285 #include "scsi_module.c"
289 int blz1230_esp_release(struct Scsi_Host
*instance
)
294 key
= ((struct NCR_ESP
*)instance
->hostdata
)->slot
;
295 esp_deallocate((struct NCR_ESP
*)instance
->hostdata
);
297 zorro_unconfig_board(key
, 0);
298 free_irq(IRQ_AMIGA_PORTS
, esp_intr
);