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 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/kernel.h> 19 #include <linux/delay.h> 20 #include <linux/types.h> 21 #include <linux/string.h> 22 #include <linux/malloc.h> 23 #include <linux/blk.h> 24 #include <linux/proc_fs.h> 25 #include <linux/stat.h> 30 #include"cyberstormII.h" 32 #include <linux/zorro.h> 34 #include <asm/amigaints.h> 35 #include <asm/amigahw.h> 37 #include <asm/pgtable.h> 39 static intdma_bytes_sent(struct NCR_ESP
*esp
,int fifo_count
); 40 static intdma_can_transfer(struct NCR_ESP
*esp
, Scsi_Cmnd
*sp
); 41 static voiddma_dump_state(struct NCR_ESP
*esp
); 42 static voiddma_init_read(struct NCR_ESP
*esp
, __u32 addr
,int length
); 43 static voiddma_init_write(struct NCR_ESP
*esp
, __u32 addr
,int length
); 44 static voiddma_ints_off(struct NCR_ESP
*esp
); 45 static voiddma_ints_on(struct NCR_ESP
*esp
); 46 static intdma_irq_p(struct NCR_ESP
*esp
); 47 static voiddma_led_off(struct NCR_ESP
*esp
); 48 static voiddma_led_on(struct NCR_ESP
*esp
); 49 static intdma_ports_p(struct NCR_ESP
*esp
); 50 static voiddma_setup(struct NCR_ESP
*esp
, __u32 addr
,int count
,int write
); 52 volatileunsigned char cmd_buffer
[16]; 53 /* This is where all commands are put 54 * before they are transfered to the ESP chip 58 /***************************************************************** Detection */ 59 int __init
cyberII_esp_detect(Scsi_Host_Template
*tpnt
) 62 const struct ConfigDev
*esp_dev
; 64 unsigned long address
; 65 struct ESP_regs
*eregs
; 67 if((key
=zorro_find(ZORRO_PROD_PHASE5_CYBERSTORM_MK_II
,0,0))){ 68 esp_dev
=zorro_get_board(key
); 70 /* Do some magic to figure out if the CyberStorm Mk II 71 * is equipped with a SCSI controller 73 address
= (unsigned long)ZTWO_VADDR(esp_dev
->cd_BoardAddr
); 74 eregs
= (struct ESP_regs
*)(address
+ CYBERII_ESP_ADDR
); 76 esp
=esp_allocate(tpnt
, (void*) esp_dev
); 78 esp_write(eregs
->esp_cfg1
, (ESP_CONFIG1_PENABLE
|7)); 80 if(esp_read(eregs
->esp_cfg1
) != (ESP_CONFIG1_PENABLE
|7)) { 82 scsi_unregister(esp
->ehost
); 83 return0;/* Bail out if address did not hold data */ 86 /* Do command transfer with programmed I/O */ 89 /* Required functions */ 90 esp
->dma_bytes_sent
= &dma_bytes_sent
; 91 esp
->dma_can_transfer
= &dma_can_transfer
; 92 esp
->dma_dump_state
= &dma_dump_state
; 93 esp
->dma_init_read
= &dma_init_read
; 94 esp
->dma_init_write
= &dma_init_write
; 95 esp
->dma_ints_off
= &dma_ints_off
; 96 esp
->dma_ints_on
= &dma_ints_on
; 97 esp
->dma_irq_p
= &dma_irq_p
; 98 esp
->dma_ports_p
= &dma_ports_p
; 99 esp
->dma_setup
= &dma_setup
; 101 /* Optional functions */ 104 esp
->dma_invalidate
=0; 105 esp
->dma_irq_entry
=0; 106 esp
->dma_irq_exit
=0; 107 esp
->dma_led_on
= &dma_led_on
; 108 esp
->dma_led_off
= &dma_led_off
; 112 /* SCSI chip speed */ 113 esp
->cfreq
=40000000; 115 /* The DMA registers on the CyberStorm are mapped 116 * relative to the device (i.e. in the same Zorro 119 esp
->dregs
= (void*)(address
+ CYBERII_DMA_ADDR
); 121 /* ESP register base */ 124 /* Set the command buffer */ 125 esp
->esp_command
= (volatileunsigned char*) cmd_buffer
; 126 esp
->esp_command_dvma
=virt_to_bus(cmd_buffer
); 128 esp
->irq
= IRQ_AMIGA_PORTS
; 130 request_irq(IRQ_AMIGA_PORTS
, esp_intr
, SA_SHIRQ
, 131 "CyberStorm SCSI Mk II", esp_intr
); 133 /* Figure out our scsi ID on the bus */ 136 /* We don't have a differential SCSI-bus. */ 141 zorro_config_board(key
,0); 143 printk("ESP: Total of %d ESP hosts found, %d actually in use.\n", nesps
, esps_in_use
); 144 esps_running
= esps_in_use
; 150 /************************************************************* DMA Functions */ 151 static intdma_bytes_sent(struct NCR_ESP
*esp
,int fifo_count
) 153 /* Since the CyberStorm DMA is fully dedicated to the ESP chip, 154 * the number of bytes sent (to the ESP chip) equals the number 155 * of bytes in the FIFO - there is no buffering in the DMA controller. 156 * XXXX Do I read this right? It is from host to ESP, right? 161 static intdma_can_transfer(struct NCR_ESP
*esp
, Scsi_Cmnd
*sp
) 163 /* I don't think there's any limit on the CyberDMA. So we use what 164 * the ESP chip can handle (24 bit). 166 unsigned long sz
= sp
->SCp
.this_residual
; 172 static voiddma_dump_state(struct NCR_ESP
*esp
) 174 ESPLOG(("esp%d: dma -- cond_reg<%02x>\n", 175 esp
->esp_id
, ((struct cyberII_dma_registers
*) 176 (esp
->dregs
))->cond_reg
)); 177 ESPLOG(("intreq:<%04x>, intena:<%04x>\n", 178 custom
.intreqr
, custom
.intenar
)); 181 static voiddma_init_read(struct NCR_ESP
*esp
, __u32 addr
,int length
) 183 struct cyberII_dma_registers
*dregs
= 184 (struct cyberII_dma_registers
*) esp
->dregs
; 186 cache_clear(addr
, length
); 189 dregs
->dma_addr0
= (addr
>>24) &0xff; 190 dregs
->dma_addr1
= (addr
>>16) &0xff; 191 dregs
->dma_addr2
= (addr
>>8) &0xff; 192 dregs
->dma_addr3
= (addr
) &0xff; 195 static voiddma_init_write(struct NCR_ESP
*esp
, __u32 addr
,int length
) 197 struct cyberII_dma_registers
*dregs
= 198 (struct cyberII_dma_registers
*) esp
->dregs
; 200 cache_push(addr
, length
); 203 dregs
->dma_addr0
= (addr
>>24) &0xff; 204 dregs
->dma_addr1
= (addr
>>16) &0xff; 205 dregs
->dma_addr2
= (addr
>>8) &0xff; 206 dregs
->dma_addr3
= (addr
) &0xff; 209 static voiddma_ints_off(struct NCR_ESP
*esp
) 211 disable_irq(esp
->irq
); 214 static voiddma_ints_on(struct NCR_ESP
*esp
) 216 enable_irq(esp
->irq
); 219 static intdma_irq_p(struct NCR_ESP
*esp
) 221 /* It's important to check the DMA IRQ bit in the correct way! */ 222 return(esp_read(esp
->eregs
->esp_status
) & ESP_STAT_INTR
); 225 static voiddma_led_off(struct NCR_ESP
*esp
) 227 ((struct cyberII_dma_registers
*)(esp
->dregs
))->ctrl_reg
&= ~CYBERII_DMA_LED
; 230 static voiddma_led_on(struct NCR_ESP
*esp
) 232 ((struct cyberII_dma_registers
*)(esp
->dregs
))->ctrl_reg
|= CYBERII_DMA_LED
; 235 static intdma_ports_p(struct NCR_ESP
*esp
) 237 return((custom
.intenar
) & IF_PORTS
); 240 static voiddma_setup(struct NCR_ESP
*esp
, __u32 addr
,int count
,int write
) 242 /* On the Sparc, DMA_ST_WRITE means "move data from device to memory" 243 * so when (write) is true, it actually means READ! 246 dma_init_read(esp
, addr
, count
); 248 dma_init_write(esp
, addr
, count
); 256 #include"cyberstormII.h" 258 Scsi_Host_Template driver_template
= SCSI_CYBERSTORMII
; 260 #include"scsi_module.c" 264 intcyberII_esp_release(struct Scsi_Host
*instance
) 269 key
= ((struct NCR_ESP
*)instance
->hostdata
)->slot
; 270 esp_deallocate((struct NCR_ESP
*)instance
->hostdata
); 272 zorro_unconfig_board(key
,0); 273 free_irq(IRQ_AMIGA_PORTS
, esp_intr
);