2 * sgiwd93.c: SGI WD93 scsi driver.
4 * Copyright (C) 1996 David S. Miller (dm@engr.sgi.com)
5 * 1999 Andrew R. Baker (andrewb@uab.edu)
6 * - Support for 2nd SCSI controller on Indigo2
7 * 2001 Florian Lohoff (flo@rfc822.org)
8 * - Delete HPC scatter gather (Read corruption on
10 * - Cleanup wback cache handling
12 * (In all truth, Jed Schimmel wrote all this code.)
15 #include <linux/init.h>
16 #include <linux/types.h>
18 #include <linux/blk.h>
19 #include <linux/version.h>
20 #include <linux/delay.h>
21 #include <linux/spinlock.h>
24 #include <asm/pgtable.h>
25 #include <asm/sgialib.h>
26 #include <asm/sgi/sgi.h>
27 #include <asm/sgi/sgimc.h>
28 #include <asm/sgi/sgihpc.h>
29 #include <asm/sgi/sgint23.h>
38 #include <linux/stat.h>
41 struct hpc_dma_desc desc;
42 u32 _padding; /* align to quadword boundary */
45 struct Scsi_Host *sgiwd93_host = NULL;
46 struct Scsi_Host *sgiwd93_host1 = NULL;
48 /* Wuff wuff, wuff, wd33c93.c, wuff wuff, object oriented, bow wow. */
49 static inline void write_wd33c93_count(const wd33c93_regs regs,
52 *regs.SASR = WD_TRANSFER_COUNT_MSB;
54 *regs.SCMD = ((value >> 16) & 0xff);
55 *regs.SCMD = ((value >> 8) & 0xff);
56 *regs.SCMD = ((value >> 0) & 0xff);
60 static inline unsigned long read_wd33c93_count(const wd33c93_regs regs)
64 *regs.SASR = WD_TRANSFER_COUNT_MSB;
66 value = ((*regs.SCMD & 0xff) << 16);
67 value |= ((*regs.SCMD & 0xff) << 8);
68 value |= ((*regs.SCMD & 0xff) << 0);
74 static void sgiwd93_intr(int irq, void *dev_id, struct pt_regs *regs)
78 spin_lock_irqsave(&io_request_lock, flags);
79 wd33c93_intr((struct Scsi_Host *) dev_id);
80 spin_unlock_irqrestore(&io_request_lock, flags);
86 void fill_hpc_entries (struct hpc_chunk **hcp, char *addr, unsigned long len)
88 unsigned long physaddr;
91 physaddr = PHYSADDR(addr);
94 * even cntinfo could be up to 16383, without
95 * magic only 8192 works correctly
97 count = len > 8192 ? 8192 : len;
98 (*hcp)->desc.pbuf = physaddr;
99 (*hcp)->desc.cntinfo = count;
106 static int dma_setup(Scsi_Cmnd *cmd, int datainp)
108 struct WD33C93_hostdata *hdata = (struct WD33C93_hostdata *)cmd->host->hostdata;
109 struct hpc3_scsiregs *hregs = (struct hpc3_scsiregs *) cmd->host->base;
110 struct hpc_chunk *hcp = (struct hpc_chunk *) hdata->dma_bounce_buffer;
113 printk("dma_setup: datainp<%d> hcp<%p> ",
117 hdata->dma_dir = datainp;
120 * wd33c93 shouldn't pass us bogus dma_setups, but
121 * it does:-( The other wd33c93 drivers deal with
122 * it the same way (which isn't that obvious).
123 * IMHO a better fix would be, not to do these
124 * dma setups in the first place
126 if (cmd->SCp.ptr == NULL)
129 fill_hpc_entries (&hcp, cmd->SCp.ptr,cmd->SCp.this_residual);
131 /* To make sure, if we trip an HPC bug, that we transfer
132 * every single byte, we tag on an extra zero length dma
133 * descriptor at the end of the chain.
136 hcp->desc.cntinfo = (HPCDMA_EOX);
142 /* Start up the HPC. */
143 hregs->ndptr = PHYSADDR(hdata->dma_bounce_buffer);
145 dma_cache_inv((unsigned long) cmd->SCp.ptr, cmd->SCp.this_residual);
146 hregs->ctrl = (HPC3_SCTRL_ACTIVE);
148 dma_cache_wback_inv((unsigned long) cmd->SCp.ptr, cmd->SCp.this_residual);
149 hregs->ctrl = (HPC3_SCTRL_ACTIVE | HPC3_SCTRL_DIR);
155 static void dma_stop(struct Scsi_Host *instance, Scsi_Cmnd *SCpnt,
158 struct WD33C93_hostdata *hdata = (struct WD33C93_hostdata *)instance->hostdata;
159 struct hpc3_scsiregs *hregs;
164 hregs = (struct hpc3_scsiregs *) SCpnt->host->base;
167 printk("dma_stop: status<%d> ", status);
170 /* First stop the HPC and flush it's FIFO. */
172 hregs->ctrl |= HPC3_SCTRL_FLUSH;
173 while(hregs->ctrl & HPC3_SCTRL_ACTIVE)
183 void sgiwd93_reset(unsigned long base)
185 struct hpc3_scsiregs *hregs = (struct hpc3_scsiregs *) base;
187 hregs->ctrl = HPC3_SCTRL_CRESET;
192 static inline void init_hpc_chain(uchar *buf)
194 struct hpc_chunk *hcp = (struct hpc_chunk *) buf;
195 unsigned long start, end;
197 start = (unsigned long) buf;
198 end = start + PAGE_SIZE;
200 hcp->desc.pnext = PHYSADDR((hcp + 1));
201 hcp->desc.cntinfo = HPCDMA_EOX;
203 start += sizeof(struct hpc_chunk);
206 hcp->desc.pnext = PHYSADDR(buf);
208 /* Force flush to memory */
209 dma_cache_wback_inv((unsigned long) buf, PAGE_SIZE);
212 int __init sgiwd93_detect(Scsi_Host_Template *SGIblows)
214 static unsigned char called = 0;
215 struct hpc3_scsiregs *hregs = &hpc3c0->scsi_chan0;
216 struct hpc3_scsiregs *hregs1 = &hpc3c0->scsi_chan1;
217 struct WD33C93_hostdata *hdata;
218 struct WD33C93_hostdata *hdata1;
223 return 0; /* Should bitch on the console about this... */
225 SGIblows->proc_name = "SGIWD93";
227 sgiwd93_host = scsi_register(SGIblows, sizeof(struct WD33C93_hostdata));
228 if(sgiwd93_host == NULL)
230 sgiwd93_host->base = (unsigned long) hregs;
231 sgiwd93_host->irq = SGI_WD93_0_IRQ;
233 buf = (uchar *) get_free_page(GFP_KERNEL);
235 printk(KERN_WARNING "sgiwd93: Could not allocate memory for host0 buffer.\n");
236 scsi_unregister(sgiwd93_host);
241 /* HPC_SCSI_REG0 | 0x03 | KSEG1 */
242 regs.SASR = (unsigned char*) KSEG1ADDR (0x1fbc0003);
243 regs.SCMD = (unsigned char*) KSEG1ADDR (0x1fbc0007);
244 wd33c93_init(sgiwd93_host, regs, dma_setup, dma_stop, WD33C93_FS_16_20);
246 hdata = (struct WD33C93_hostdata *)sgiwd93_host->hostdata;
248 hdata->dma_bounce_buffer = (uchar *) (KSEG1ADDR(buf));
250 if (request_irq(SGI_WD93_0_IRQ, sgiwd93_intr, 0, "SGI WD93", (void *) sgiwd93_host)) {
251 printk(KERN_WARNING "sgiwd93: Could not register IRQ %d (for host 0).\n", SGI_WD93_0_IRQ);
255 free_page((unsigned long)buf);
256 scsi_unregister(sgiwd93_host);
259 /* set up second controller on the Indigo2 */
261 sgiwd93_host1 = scsi_register(SGIblows, sizeof(struct WD33C93_hostdata));
262 if(sgiwd93_host1 != NULL)
264 sgiwd93_host1->base = (unsigned long) hregs1;
265 sgiwd93_host1->irq = SGI_WD93_1_IRQ;
267 buf = (uchar *) get_free_page(GFP_KERNEL);
269 printk(KERN_WARNING "sgiwd93: Could not allocate memory for host1 buffer.\n");
270 scsi_unregister(sgiwd93_host1);
272 return 1; /* We registered host0 so return success*/
276 /* HPC_SCSI_REG1 | 0x03 | KSEG1 */
277 regs.SASR = (unsigned char*) KSEG1ADDR(0x1fbc8003);
278 regs.SCMD = (unsigned char*) KSEG1ADDR(0x1fbc8007);
279 wd33c93_init(sgiwd93_host1, regs, dma_setup, dma_stop,
282 hdata1 = (struct WD33C93_hostdata *)sgiwd93_host1->hostdata;
284 hdata1->dma_bounce_buffer = (uchar *) (KSEG1ADDR(buf));
286 if (request_irq(SGI_WD93_1_IRQ, sgiwd93_intr, 0, "SGI WD93", (void *) sgiwd93_host1)) {
287 printk(KERN_WARNING "sgiwd93: Could not allocate irq %d (for host1).\n", SGI_WD93_1_IRQ);
291 free_page((unsigned long)buf);
292 scsi_unregister(sgiwd93_host1);
293 /* Fall through since host0 registered OK */
300 return 1; /* Found one. */
307 static Scsi_Host_Template driver_template = SGIWD93_SCSI;
309 #include "scsi_module.c"
311 int sgiwd93_release(struct Scsi_Host *instance)
314 free_irq(SGI_WD93_0_IRQ, sgiwd93_intr);
315 free_page(KSEG0ADDR(hdata->dma_bounce_buffer));
318 free_irq(SGI_WD93_1_IRQ, sgiwd93_intr);
319 free_page(KSEG0ADDR(hdata1->dma_bounce_buffer));