2 * jazz_esp.c: Driver for SCSI chip on Mips Magnum Boards (JAZZ architecture)
4 * Copyright (C) 1997 Thomas Boegndoerfer (tsbogend@alpha.franken.de)
6 * jazz_esp is based on David S. Miller's ESP driver and cyber_esp
9 #include <linux/kernel.h>
10 #include <linux/delay.h>
11 #include <linux/types.h>
12 #include <linux/string.h>
13 #include <linux/malloc.h>
14 #include <linux/blk.h>
15 #include <linux/proc_fs.h>
16 #include <linux/stat.h>
25 #include <asm/jazzdma.h>
28 #include <asm/pgtable.h>
30 static int dma_bytes_sent(struct NCR_ESP
*esp
, int fifo_count
);
31 static int dma_can_transfer(struct NCR_ESP
*esp
, Scsi_Cmnd
*sp
);
32 static void dma_dump_state(struct NCR_ESP
*esp
);
33 static void dma_init_read(struct NCR_ESP
*esp
, __u32 vaddress
, int length
);
34 static void dma_init_write(struct NCR_ESP
*esp
, __u32 vaddress
, int length
);
35 static void dma_ints_off(struct NCR_ESP
*esp
);
36 static void dma_ints_on(struct NCR_ESP
*esp
);
37 static int dma_irq_p(struct NCR_ESP
*esp
);
38 static int dma_ports_p(struct NCR_ESP
*esp
);
39 static void dma_setup(struct NCR_ESP
*esp
, __u32 addr
, int count
, int write
);
40 static void dma_mmu_get_scsi_one (struct NCR_ESP
*esp
, Scsi_Cmnd
*sp
);
41 static void dma_mmu_get_scsi_sgl (struct NCR_ESP
*esp
, Scsi_Cmnd
*sp
);
42 static void dma_mmu_release_scsi_one (struct NCR_ESP
*esp
, Scsi_Cmnd
*sp
);
43 static void dma_mmu_release_scsi_sgl (struct NCR_ESP
*esp
, Scsi_Cmnd
*sp
);
44 static void dma_advance_sg (Scsi_Cmnd
*sp
);
45 static void dma_led_off(struct NCR_ESP
*);
46 static void dma_led_on(struct NCR_ESP
*);
49 volatile unsigned char cmd_buffer
[16];
50 /* This is where all commands are put
51 * before they are trasfered to the ESP chip
55 /***************************************************************** Detection */
56 int jazz_esp_detect(Scsi_Host_Template
*tpnt
)
59 struct ConfigDev
*esp_dev
;
62 * first assumption it is there:-)
66 esp
= esp_allocate(tpnt
, (void *) esp_dev
);
68 /* Do command transfer with programmed I/O */
71 /* Required functions */
72 esp
->dma_bytes_sent
= &dma_bytes_sent
;
73 esp
->dma_can_transfer
= &dma_can_transfer
;
74 esp
->dma_dump_state
= &dma_dump_state
;
75 esp
->dma_init_read
= &dma_init_read
;
76 esp
->dma_init_write
= &dma_init_write
;
77 esp
->dma_ints_off
= &dma_ints_off
;
78 esp
->dma_ints_on
= &dma_ints_on
;
79 esp
->dma_irq_p
= &dma_irq_p
;
80 esp
->dma_ports_p
= &dma_ports_p
;
81 esp
->dma_setup
= &dma_setup
;
83 /* Optional functions */
86 esp
->dma_invalidate
= 0;
87 esp
->dma_irq_entry
= 0;
88 esp
->dma_irq_exit
= 0;
91 esp
->dma_led_off
= &dma_led_off
;
92 esp
->dma_led_on
= &dma_led_on
;
94 /* virtual DMA functions */
95 esp
->dma_mmu_get_scsi_one
= &dma_mmu_get_scsi_one
;
96 esp
->dma_mmu_get_scsi_sgl
= &dma_mmu_get_scsi_sgl
;
97 esp
->dma_mmu_release_scsi_one
= &dma_mmu_release_scsi_one
;
98 esp
->dma_mmu_release_scsi_sgl
= &dma_mmu_release_scsi_sgl
;
99 esp
->dma_advance_sg
= &dma_advance_sg
;
102 /* SCSI chip speed */
103 esp
->cfreq
= 40000000;
106 * we don't give the address of DMA channel, but the number
107 * of DMA channel, so we can use the jazz DMA functions
110 esp
->dregs
= JAZZ_SCSI_DMA
;
112 /* ESP register base */
113 esp
->eregs
= (struct ESP_regs
*)(JAZZ_SCSI_BASE
);
115 /* Set the command buffer */
116 esp
->esp_command
= (volatile unsigned char *)cmd_buffer
;
118 /* get virtual dma address for command buffer */
119 esp
->esp_command_dvma
= vdma_alloc(PHYSADDR(cmd_buffer
), sizeof (cmd_buffer
));
121 esp
->irq
= JAZZ_SCSI_IRQ
;
122 request_irq(JAZZ_SCSI_IRQ
, esp_intr
, SA_INTERRUPT
, "JAZZ SCSI",
126 * FIXME, look if the scsi id is availabe from NVRAM
130 /* Check for differential SCSI-bus */
131 /* What is this stuff? */
136 printk("ESP: Total of %d ESP hosts found, %d actually in use.\n", nesps
,esps_in_use
);
137 esps_running
= esps_in_use
;
143 /************************************************************* DMA Functions */
144 static int dma_bytes_sent(struct NCR_ESP
*esp
, int fifo_count
)
149 static int dma_can_transfer(struct NCR_ESP
*esp
, Scsi_Cmnd
*sp
)
152 * maximum DMA size is 1MB
154 unsigned long sz
= sp
->SCp
.this_residual
;
160 static void dma_dump_state(struct NCR_ESP
*esp
)
163 ESPLOG(("esp%d: dma -- enable <%08x> residue <%08x\n",
164 esp
->esp_id
, vdma_get_enable((int)esp
->dregs
), vdma_get_resdiue((int)esp
->dregs
)));
167 static void dma_init_read(struct NCR_ESP
*esp
, __u32 vaddress
, int length
)
169 dma_cache_wback_inv ((unsigned long)phys_to_virt(vdma_log2phys(vaddress
)), length
);
170 vdma_disable ((int)esp
->dregs
);
171 vdma_set_mode ((int)esp
->dregs
, DMA_MODE_READ
);
172 vdma_set_addr ((int)esp
->dregs
, vaddress
);
173 vdma_set_count ((int)esp
->dregs
, length
);
174 vdma_enable ((int)esp
->dregs
);
177 static void dma_init_write(struct NCR_ESP
*esp
, __u32 vaddress
, int length
)
179 dma_cache_wback_inv ((unsigned long)phys_to_virt(vdma_log2phys(vaddress
)), length
);
180 vdma_disable ((int)esp
->dregs
);
181 vdma_set_mode ((int)esp
->dregs
, DMA_MODE_WRITE
);
182 vdma_set_addr ((int)esp
->dregs
, vaddress
);
183 vdma_set_count ((int)esp
->dregs
, length
);
184 vdma_enable ((int)esp
->dregs
);
187 static void dma_ints_off(struct NCR_ESP
*esp
)
189 disable_irq(esp
->irq
);
192 static void dma_ints_on(struct NCR_ESP
*esp
)
194 enable_irq(esp
->irq
);
197 static int dma_irq_p(struct NCR_ESP
*esp
)
199 return (esp_read(esp
->eregs
->esp_status
) & ESP_STAT_INTR
);
202 static int dma_ports_p(struct NCR_ESP
*esp
)
204 int enable
= vdma_get_enable((int)esp
->dregs
);
206 return (enable
& R4030_CHNL_ENABLE
);
209 static void dma_setup(struct NCR_ESP
*esp
, __u32 addr
, int count
, int write
)
212 * On the Sparc, DMA_ST_WRITE means "move data from device to memory"
213 * so when (write) is true, it actually means READ!
216 dma_init_read(esp
, addr
, count
);
218 dma_init_write(esp
, addr
, count
);
222 static void dma_mmu_get_scsi_one (struct NCR_ESP
*esp
, Scsi_Cmnd
*sp
)
224 sp
->SCp
.have_data_in
= vdma_alloc(PHYSADDR(sp
->SCp
.buffer
), sp
->SCp
.this_residual
);
225 sp
->SCp
.ptr
= (char *)((unsigned long)sp
->SCp
.have_data_in
);
228 static void dma_mmu_get_scsi_sgl (struct NCR_ESP
*esp
, Scsi_Cmnd
*sp
)
230 int sz
= sp
->SCp
.buffers_residual
;
231 struct mmu_sglist
*sg
= (struct mmu_sglist
*) sp
->SCp
.buffer
;
234 sg
[sz
].dvma_addr
= vdma_alloc(PHYSADDR(sg
[sz
].addr
), sg
[sz
].len
);
237 sp
->SCp
.ptr
=(char *)((unsigned long)sp
->SCp
.buffer
->dvma_address
);
240 static void dma_mmu_release_scsi_one (struct NCR_ESP
*esp
, Scsi_Cmnd
*sp
)
242 vdma_free(sp
->SCp
.have_data_in
);
245 static void dma_mmu_release_scsi_sgl (struct NCR_ESP
*esp
, Scsi_Cmnd
*sp
)
247 int sz
= sp
->use_sg
- 1;
248 struct mmu_sglist
*sg
= (struct mmu_sglist
*)sp
->buffer
;
251 vdma_free(sg
[sz
].dvma_addr
);
256 static void dma_advance_sg (Scsi_Cmnd
*sp
)
258 sp
->SCp
.ptr
= (char *)((unsigned long)sp
->SCp
.buffer
->dvma_address
);
261 #define JAZZ_HDC_LED 0xe000d100 /* FIXME, find correct address */
263 static void dma_led_off(struct NCR_ESP
*esp
)
266 *(unsigned char *)JAZZ_HDC_LED
= 0;
270 static void dma_led_on(struct NCR_ESP
*esp
)
273 *(unsigned char *)JAZZ_HDC_LED
= 1;