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/blkdev.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. */
51 static void sgiwd93_intr(int irq, void *dev_id, struct pt_regs *regs)
54 struct Scsi_Host *dev = dev_id;
56 spin_lock_irqsave(dev->host_lock, flags);
57 wd33c93_intr((struct Scsi_Host *) dev_id);
58 spin_unlock_irqrestore(dev->host_lock, flags);
64 void fill_hpc_entries (struct hpc_chunk **hcp, char *addr, unsigned long len)
66 unsigned long physaddr;
69 physaddr = PHYSADDR(addr);
72 * even cntinfo could be up to 16383, without
73 * magic only 8192 works correctly
75 count = len > 8192 ? 8192 : len;
76 (*hcp)->desc.pbuf = physaddr;
77 (*hcp)->desc.cntinfo = count;
84 static int dma_setup(Scsi_Cmnd *cmd, int datainp)
86 struct WD33C93_hostdata *hdata = (struct WD33C93_hostdata *)cmd->host->hostdata;
87 struct hpc3_scsiregs *hregs = (struct hpc3_scsiregs *) cmd->host->base;
88 struct hpc_chunk *hcp = (struct hpc_chunk *) hdata->dma_bounce_buffer;
91 printk("dma_setup: datainp<%d> hcp<%p> ",
95 hdata->dma_dir = datainp;
98 * wd33c93 shouldn't pass us bogus dma_setups, but
99 * it does:-( The other wd33c93 drivers deal with
100 * it the same way (which isn't that obvious).
101 * IMHO a better fix would be, not to do these
102 * dma setups in the first place
104 if (cmd->SCp.ptr == NULL)
107 fill_hpc_entries (&hcp, cmd->SCp.ptr,cmd->SCp.this_residual);
109 /* To make sure, if we trip an HPC bug, that we transfer
110 * every single byte, we tag on an extra zero length dma
111 * descriptor at the end of the chain.
114 hcp->desc.cntinfo = (HPCDMA_EOX);
120 /* Start up the HPC. */
121 hregs->ndptr = PHYSADDR(hdata->dma_bounce_buffer);
123 dma_cache_inv((unsigned long) cmd->SCp.ptr, cmd->SCp.this_residual);
124 hregs->ctrl = (HPC3_SCTRL_ACTIVE);
126 dma_cache_wback_inv((unsigned long) cmd->SCp.ptr, cmd->SCp.this_residual);
127 hregs->ctrl = (HPC3_SCTRL_ACTIVE | HPC3_SCTRL_DIR);
133 static void dma_stop(struct Scsi_Host *instance, Scsi_Cmnd *SCpnt,
136 struct WD33C93_hostdata *hdata = (struct WD33C93_hostdata *)instance->hostdata;
137 struct hpc3_scsiregs *hregs;
142 hregs = (struct hpc3_scsiregs *) SCpnt->host->base;
145 printk("dma_stop: status<%d> ", status);
148 /* First stop the HPC and flush it's FIFO. */
150 hregs->ctrl |= HPC3_SCTRL_FLUSH;
151 while(hregs->ctrl & HPC3_SCTRL_ACTIVE)
161 void sgiwd93_reset(unsigned long base)
163 struct hpc3_scsiregs *hregs = (struct hpc3_scsiregs *) base;
165 hregs->ctrl = HPC3_SCTRL_CRESET;
170 static inline void init_hpc_chain(uchar *buf)
172 struct hpc_chunk *hcp = (struct hpc_chunk *) buf;
173 unsigned long start, end;
175 start = (unsigned long) buf;
176 end = start + PAGE_SIZE;
178 hcp->desc.pnext = PHYSADDR((hcp + 1));
179 hcp->desc.cntinfo = HPCDMA_EOX;
181 start += sizeof(struct hpc_chunk);
184 hcp->desc.pnext = PHYSADDR(buf);
186 /* Force flush to memory */
187 dma_cache_wback_inv((unsigned long) buf, PAGE_SIZE);
190 int __init sgiwd93_detect(Scsi_Host_Template *SGIblows)
192 static unsigned char called = 0;
193 struct hpc3_scsiregs *hregs = &hpc3c0->scsi_chan0;
194 struct hpc3_scsiregs *hregs1 = &hpc3c0->scsi_chan1;
195 struct WD33C93_hostdata *hdata;
196 struct WD33C93_hostdata *hdata1;
201 return 0; /* Should bitch on the console about this... */
203 SGIblows->proc_name = "SGIWD93";
205 sgiwd93_host = scsi_register(SGIblows, sizeof(struct WD33C93_hostdata));
206 if(sgiwd93_host == NULL)
208 sgiwd93_host->base = (unsigned long) hregs;
209 sgiwd93_host->irq = SGI_WD93_0_IRQ;
211 buf = (uchar *) get_zeroed_page(GFP_KERNEL);
213 printk(KERN_WARNING "sgiwd93: Could not allocate memory for host0 buffer.\n");
214 scsi_unregister(sgiwd93_host);
219 /* HPC_SCSI_REG0 | 0x03 | KSEG1 */
220 regs.SASR = (unsigned char*) KSEG1ADDR (0x1fbc0003);
221 regs.SCMD = (unsigned char*) KSEG1ADDR (0x1fbc0007);
222 wd33c93_init(sgiwd93_host, regs, dma_setup, dma_stop, WD33C93_FS_16_20);
224 hdata = (struct WD33C93_hostdata *)sgiwd93_host->hostdata;
226 hdata->dma_bounce_buffer = (uchar *) (KSEG1ADDR(buf));
228 if (request_irq(SGI_WD93_0_IRQ, sgiwd93_intr, 0, "SGI WD93", (void *) sgiwd93_host)) {
229 printk(KERN_WARNING "sgiwd93: Could not register IRQ %d (for host 0).\n", SGI_WD93_0_IRQ);
231 free_page((unsigned long)buf);
232 scsi_unregister(sgiwd93_host);
235 /* set up second controller on the Indigo2 */
237 sgiwd93_host1 = scsi_register(SGIblows, sizeof(struct WD33C93_hostdata));
238 if(sgiwd93_host1 != NULL)
240 sgiwd93_host1->base = (unsigned long) hregs1;
241 sgiwd93_host1->irq = SGI_WD93_1_IRQ;
243 buf = (uchar *) get_zeroed_page(GFP_KERNEL);
245 printk(KERN_WARNING "sgiwd93: Could not allocate memory for host1 buffer.\n");
246 scsi_unregister(sgiwd93_host1);
248 return 1; /* We registered host0 so return success*/
252 /* HPC_SCSI_REG1 | 0x03 | KSEG1 */
253 regs.SASR = (unsigned char*) KSEG1ADDR(0x1fbc8003);
254 regs.SCMD = (unsigned char*) KSEG1ADDR(0x1fbc8007);
255 wd33c93_init(sgiwd93_host1, regs, dma_setup, dma_stop,
258 hdata1 = (struct WD33C93_hostdata *)sgiwd93_host1->hostdata;
260 hdata1->dma_bounce_buffer = (uchar *) (KSEG1ADDR(buf));
262 if (request_irq(SGI_WD93_1_IRQ, sgiwd93_intr, 0, "SGI WD93", (void *) sgiwd93_host1)) {
263 printk(KERN_WARNING "sgiwd93: Could not allocate irq %d (for host1).\n", SGI_WD93_1_IRQ);
265 free_page((unsigned long)buf);
266 scsi_unregister(sgiwd93_host1);
267 /* Fall through since host0 registered OK */
274 return 1; /* Found one. */
277 int sgiwd93_release(struct Scsi_Host *instance)
279 free_irq(SGI_WD93_0_IRQ, sgiwd93_intr);
280 free_page(KSEG0ADDR(hdata->dma_bounce_buffer));
283 free_irq(SGI_WD93_1_IRQ, sgiwd93_intr);
284 free_page(KSEG0ADDR(hdata1->dma_bounce_buffer));
290 static Scsi_Host_Template driver_template = {
291 .proc_name = "SGIWD93",
293 .detect = sgiwd93_detect,
294 .release = sgiwd93_release,
295 .queuecommand = wd33c93_queuecommand,
296 .abort = wd33c93_abort,
297 .reset = wd33c93_reset,
298 .can_queue = CAN_QUEUE,
300 .sg_tablesize = SG_ALL,
301 .cmd_per_lun = CMD_PER_LUN,
302 .use_clustering = DISABLE_CLUSTERING,
304 #include "scsi_module.c"