1 /* cyberstorm.c: Driver for CyberStorm SCSI Controller. 3 * Copyright (C) 1996 Jesper Skov (jskov@cygnus.co.uk) 5 * The CyberStorm SCSI driver is based on David S. Miller's ESP driver 6 * for the Sparc computers. 8 * This work was made possible by Phase5 who willingly (and most generously) 9 * supported me with hardware and all the information I needed. 14 * 1) Figure out how to make a cleaner merge with the sparc driver with regard 15 * to the caches and the Sparc MMU mapping. 16 * 2) Make as few routines required outside the generic driver. A lot of the 17 * routines in this file used to be inline! 20 #include <linux/module.h> 22 #include <linux/kernel.h> 23 #include <linux/delay.h> 24 #include <linux/types.h> 25 #include <linux/string.h> 26 #include <linux/malloc.h> 27 #include <linux/blk.h> 28 #include <linux/proc_fs.h> 29 #include <linux/stat.h> 34 #include"cyberstorm.h" 36 #include <linux/zorro.h> 38 #include <asm/amigaints.h> 39 #include <asm/amigahw.h> 41 #include <asm/pgtable.h> 43 static intdma_bytes_sent(struct NCR_ESP
*esp
,int fifo_count
); 44 static intdma_can_transfer(struct NCR_ESP
*esp
, Scsi_Cmnd
*sp
); 45 static voiddma_dump_state(struct NCR_ESP
*esp
); 46 static voiddma_init_read(struct NCR_ESP
*esp
, __u32 addr
,int length
); 47 static voiddma_init_write(struct NCR_ESP
*esp
, __u32 addr
,int length
); 48 static voiddma_ints_off(struct NCR_ESP
*esp
); 49 static voiddma_ints_on(struct NCR_ESP
*esp
); 50 static intdma_irq_p(struct NCR_ESP
*esp
); 51 static voiddma_led_off(struct NCR_ESP
*esp
); 52 static voiddma_led_on(struct NCR_ESP
*esp
); 53 static intdma_ports_p(struct NCR_ESP
*esp
); 54 static voiddma_setup(struct NCR_ESP
*esp
, __u32 addr
,int count
,int write
); 56 static unsigned char ctrl_data
=0;/* Keep backup of the stuff written 57 * to ctrl_reg. Always write a copy 58 * to this register when writing to 59 * the hardware register! 62 volatileunsigned char cmd_buffer
[16]; 63 /* This is where all commands are put 64 * before they are transfered to the ESP chip 68 /***************************************************************** Detection */ 69 int __init
cyber_esp_detect(Scsi_Host_Template
*tpnt
) 72 const struct ConfigDev
*esp_dev
; 74 unsigned long address
; 77 if((key
=zorro_find(ZORRO_PROD_PHASE5_BLIZZARD_1220_CYBERSTORM
,0,0)) || 78 (key
=zorro_find(ZORRO_PROD_PHASE5_BLIZZARD_1230_II_FASTLANE_Z3_CYBERSCSI_CYBERSTORM060
,0,0))){ 79 esp_dev
=zorro_get_board(key
); 81 /* Figure out if this is a CyberStorm or really a 82 * Fastlane/Blizzard Mk II by looking at the board size. 83 * CyberStorm maps 64kB 84 * (ZORRO_PROD_PHASE5_BLIZZARD_1220_CYBERSTORM does anyway) 86 if((unsigned long)esp_dev
->cd_BoardSize
!=0x10000) 89 esp
=esp_allocate(tpnt
, (void*) esp_dev
); 91 /* Do command transfer with programmed I/O */ 94 /* Required functions */ 95 esp
->dma_bytes_sent
= &dma_bytes_sent
; 96 esp
->dma_can_transfer
= &dma_can_transfer
; 97 esp
->dma_dump_state
= &dma_dump_state
; 98 esp
->dma_init_read
= &dma_init_read
; 99 esp
->dma_init_write
= &dma_init_write
; 100 esp
->dma_ints_off
= &dma_ints_off
; 101 esp
->dma_ints_on
= &dma_ints_on
; 102 esp
->dma_irq_p
= &dma_irq_p
; 103 esp
->dma_ports_p
= &dma_ports_p
; 104 esp
->dma_setup
= &dma_setup
; 106 /* Optional functions */ 109 esp
->dma_invalidate
=0; 110 esp
->dma_irq_entry
=0; 111 esp
->dma_irq_exit
=0; 112 esp
->dma_led_on
= &dma_led_on
; 113 esp
->dma_led_off
= &dma_led_off
; 117 /* SCSI chip speed */ 118 esp
->cfreq
=40000000; 120 /* The DMA registers on the CyberStorm are mapped 121 * relative to the device (i.e. in the same Zorro 124 address
= (unsigned long)ZTWO_VADDR(esp_dev
->cd_BoardAddr
); 125 esp
->dregs
= (void*)(address
+ CYBER_DMA_ADDR
); 127 /* ESP register base */ 128 esp
->eregs
= (struct ESP_regs
*)(address
+ CYBER_ESP_ADDR
); 130 /* Set the command buffer */ 131 esp
->esp_command
= (volatileunsigned char*) cmd_buffer
; 132 esp
->esp_command_dvma
=virt_to_bus(cmd_buffer
); 134 esp
->irq
= IRQ_AMIGA_PORTS
; 136 request_irq(IRQ_AMIGA_PORTS
, esp_intr
, SA_SHIRQ
, 137 "CyberStorm SCSI", esp_intr
); 138 /* Figure out our scsi ID on the bus */ 139 /* The DMA cond flag contains a hardcoded jumper bit 140 * which can be used to select host number 6 or 7. 141 * However, even though it may change, we use a hardcoded 146 /* We don't have a differential SCSI-bus. */ 151 zorro_config_board(key
,0); 153 printk("ESP: Total of %d ESP hosts found, %d actually in use.\n", nesps
, esps_in_use
); 154 esps_running
= esps_in_use
; 160 /************************************************************* DMA Functions */ 161 static intdma_bytes_sent(struct NCR_ESP
*esp
,int fifo_count
) 163 /* Since the CyberStorm DMA is fully dedicated to the ESP chip, 164 * the number of bytes sent (to the ESP chip) equals the number 165 * of bytes in the FIFO - there is no buffering in the DMA controller. 166 * XXXX Do I read this right? It is from host to ESP, right? 171 static intdma_can_transfer(struct NCR_ESP
*esp
, Scsi_Cmnd
*sp
) 173 /* I don't think there's any limit on the CyberDMA. So we use what 174 * the ESP chip can handle (24 bit). 176 unsigned long sz
= sp
->SCp
.this_residual
; 182 static voiddma_dump_state(struct NCR_ESP
*esp
) 184 ESPLOG(("esp%d: dma -- cond_reg<%02x>\n", 185 esp
->esp_id
, ((struct cyber_dma_registers
*) 186 (esp
->dregs
))->cond_reg
)); 187 ESPLOG(("intreq:<%04x>, intena:<%04x>\n", 188 custom
.intreqr
, custom
.intenar
)); 191 static voiddma_init_read(struct NCR_ESP
*esp
, __u32 addr
,int length
) 193 struct cyber_dma_registers
*dregs
= 194 (struct cyber_dma_registers
*) esp
->dregs
; 196 cache_clear(addr
, length
); 199 dregs
->dma_addr0
= (addr
>>24) &0xff; 200 dregs
->dma_addr1
= (addr
>>16) &0xff; 201 dregs
->dma_addr2
= (addr
>>8) &0xff; 202 dregs
->dma_addr3
= (addr
) &0xff; 203 ctrl_data
&= ~(CYBER_DMA_WRITE
); 205 /* Check if physical address is outside Z2 space and of 206 * block length/block aligned in memory. If this is the 207 * case, enable 32 bit transfer. In all other cases, fall back 208 * to 16 bit transfer. 209 * Obviously 32 bit transfer should be enabled if the DMA address 210 * and length are 32 bit aligned. However, this leads to some 211 * strange behavior. Even 64 bit aligned addr/length fails. 212 * Until I've found a reason for this, 32 bit transfer is only 213 * used for full-block transfers (1kB). 217 if((addr
&0x3fc) || length
&0x3ff|| ((addr
>0x200000) && 219 ctrl_data
&= ~(CYBER_DMA_Z3
);/* Z2, do 16 bit DMA */ 221 ctrl_data
|= CYBER_DMA_Z3
;/* CHIP/Z3, do 32 bit DMA */ 223 ctrl_data
&= ~(CYBER_DMA_Z3
);/* Z2, do 16 bit DMA */ 225 dregs
->ctrl_reg
= ctrl_data
; 228 static voiddma_init_write(struct NCR_ESP
*esp
, __u32 addr
,int length
) 230 struct cyber_dma_registers
*dregs
= 231 (struct cyber_dma_registers
*) esp
->dregs
; 233 cache_push(addr
, length
); 236 dregs
->dma_addr0
= (addr
>>24) &0xff; 237 dregs
->dma_addr1
= (addr
>>16) &0xff; 238 dregs
->dma_addr2
= (addr
>>8) &0xff; 239 dregs
->dma_addr3
= (addr
) &0xff; 240 ctrl_data
|= CYBER_DMA_WRITE
; 242 /* See comment above */ 244 if((addr
&0x3fc) || length
&0x3ff|| ((addr
>0x200000) && 246 ctrl_data
&= ~(CYBER_DMA_Z3
);/* Z2, do 16 bit DMA */ 248 ctrl_data
|= CYBER_DMA_Z3
;/* CHIP/Z3, do 32 bit DMA */ 250 ctrl_data
&= ~(CYBER_DMA_Z3
);/* Z2, do 16 bit DMA */ 252 dregs
->ctrl_reg
= ctrl_data
; 255 static voiddma_ints_off(struct NCR_ESP
*esp
) 257 disable_irq(esp
->irq
); 260 static voiddma_ints_on(struct NCR_ESP
*esp
) 262 enable_irq(esp
->irq
); 265 static intdma_irq_p(struct NCR_ESP
*esp
) 267 /* It's important to check the DMA IRQ bit in the correct way! */ 268 return((esp_read(esp
->eregs
->esp_status
) & ESP_STAT_INTR
) && 269 ((((struct cyber_dma_registers
*)(esp
->dregs
))->cond_reg
) & 270 CYBER_DMA_HNDL_INTR
)); 273 static voiddma_led_off(struct NCR_ESP
*esp
) 275 ctrl_data
&= ~CYBER_DMA_LED
; 276 ((struct cyber_dma_registers
*)(esp
->dregs
))->ctrl_reg
= ctrl_data
; 279 static voiddma_led_on(struct NCR_ESP
*esp
) 281 ctrl_data
|= CYBER_DMA_LED
; 282 ((struct cyber_dma_registers
*)(esp
->dregs
))->ctrl_reg
= ctrl_data
; 285 static intdma_ports_p(struct NCR_ESP
*esp
) 287 return((custom
.intenar
) & IF_PORTS
); 290 static voiddma_setup(struct NCR_ESP
*esp
, __u32 addr
,int count
,int write
) 292 /* On the Sparc, DMA_ST_WRITE means "move data from device to memory" 293 * so when (write) is true, it actually means READ! 296 dma_init_read(esp
, addr
, count
); 298 dma_init_write(esp
, addr
, count
); 306 #include"cyberstorm.h" 308 Scsi_Host_Template driver_template
= SCSI_CYBERSTORM
; 310 #include"scsi_module.c" 314 intcyber_esp_release(struct Scsi_Host
*instance
) 319 key
= ((struct NCR_ESP
*)instance
->hostdata
)->slot
; 320 esp_deallocate((struct NCR_ESP
*)instance
->hostdata
); 322 zorro_unconfig_board(key
,0); 323 free_irq(IRQ_AMIGA_PORTS
, esp_intr
);