patch-2.4.25 linux-2.4.25/drivers/scsi/sgiwd93.c
Next file: linux-2.4.25/drivers/scsi/st.c
Previous file: linux-2.4.25/drivers/scsi/qlogicfas.c
Back to the patch index
Back to the overall index
- Lines: 420
- Date:
2004-02-18 05:36:31.000000000 -0800
- Orig file:
linux-2.4.24/drivers/scsi/sgiwd93.c
- Orig date:
2003-08-25 04:44:42.000000000 -0700
diff -urN linux-2.4.24/drivers/scsi/sgiwd93.c linux-2.4.25/drivers/scsi/sgiwd93.c
@@ -1,23 +1,23 @@
/*
- * sgiwd93.c: SGI WD93 scsi driver.
+ * This file is subject to the terms and conditions of the GNU General Public
+ * License. See the file "COPYING" in the main directory of this archive
+ * for more details.
*
* Copyright (C) 1996 David S. Miller (dm@engr.sgi.com)
- * 1999 Andrew R. Baker (andrewb@uab.edu)
- * - Support for 2nd SCSI controller on Indigo2
- * 2001 Florian Lohoff (flo@rfc822.org)
- * - Delete HPC scatter gather (Read corruption on
- * multiple disks)
- * - Cleanup wback cache handling
+ * Copyright (C) 1999 Andrew R. Baker (andrewb@uab.edu)
+ * Copyright (C) 2001 Florian Lohoff (flo@rfc822.org)
+ * Copyright (C) 2003 Ralf Baechle (ralf@linux-mips.org)
*
* (In all truth, Jed Schimmel wrote all this code.)
- *
*/
#include <linux/init.h>
+#include <linux/interrupt.h>
#include <linux/types.h>
#include <linux/mm.h>
#include <linux/blk.h>
#include <linux/version.h>
#include <linux/delay.h>
+#include <linux/pci.h>
#include <linux/spinlock.h>
#include <asm/page.h>
@@ -37,13 +37,29 @@
#include <linux/stat.h>
+#if 0
+#define DPRINTK(args...) printk(args)
+#else
+#define DPRINTK(args...)
+#endif
+
+#define HDATA(ptr) ((struct ip22_hostdata *)((ptr)->hostdata))
+
+struct ip22_hostdata {
+ struct WD33C93_hostdata wh;
+ struct hpc_data {
+ dma_addr_t dma;
+ void * cpu;
+ } hd;
+};
+
struct hpc_chunk {
struct hpc_dma_desc desc;
u32 _padding; /* align to quadword boundary */
};
-struct Scsi_Host *sgiwd93_host = NULL;
-struct Scsi_Host *sgiwd93_host1 = NULL;
+struct Scsi_Host *sgiwd93_host;
+struct Scsi_Host *sgiwd93_host1;
/* Wuff wuff, wuff, wd33c93.c, wuff wuff, object oriented, bow wow. */
static inline void write_wd33c93_count(const wd33c93_regs regs,
@@ -79,74 +95,70 @@
spin_unlock_irqrestore(&io_request_lock, flags);
}
-#undef DEBUG_DMA
-
static inline
-void fill_hpc_entries (struct hpc_chunk **hcp, char *addr, unsigned long len)
+void fill_hpc_entries(struct hpc_chunk *hcp, Scsi_Cmnd *cmd, int datainp)
{
- unsigned long physaddr;
+ unsigned long len = cmd->SCp.this_residual;
+ void *addr = cmd->SCp.ptr;
+ dma_addr_t physaddr;
unsigned long count;
-
- physaddr = PHYSADDR(addr);
+
+ physaddr = pci_map_single(NULL, addr, len,
+ scsi_to_pci_dma_dir(cmd->sc_data_direction));
+ cmd->SCp.dma_handle = physaddr;
+
while (len) {
/*
* even cntinfo could be up to 16383, without
* magic only 8192 works correctly
*/
count = len > 8192 ? 8192 : len;
- (*hcp)->desc.pbuf = physaddr;
- (*hcp)->desc.cntinfo = count;
- (*hcp)++;
+ hcp->desc.pbuf = physaddr;
+ hcp->desc.cntinfo = count;
+ hcp++;
len -= count;
physaddr += count;
}
+
+ /*
+ * To make sure, if we trip an HPC bug, that we transfer every single
+ * byte, we tag on an extra zero length dma descriptor at the end of
+ * the chain.
+ */
+ hcp->desc.pbuf = 0;
+ hcp->desc.cntinfo = HPCDMA_EOX;
}
static int dma_setup(Scsi_Cmnd *cmd, int datainp)
{
- struct WD33C93_hostdata *hdata = (struct WD33C93_hostdata *)cmd->host->hostdata;
- struct hpc3_scsiregs *hregs = (struct hpc3_scsiregs *) cmd->host->base;
- struct hpc_chunk *hcp = (struct hpc_chunk *) hdata->dma_bounce_buffer;
-
-#ifdef DEBUG_DMA
- printk("dma_setup: datainp<%d> hcp<%p> ",
- datainp, hcp);
-#endif
+ struct ip22_hostdata *hdata = HDATA(cmd->host);
+ struct hpc3_scsiregs *hregs =
+ (struct hpc3_scsiregs *) cmd->host->base;
+ struct hpc_chunk *hcp = (struct hpc_chunk *) hdata->hd.cpu;
- hdata->dma_dir = datainp;
+ DPRINTK("dma_setup: datainp<%d> hcp<%p> ", datainp, hcp);
+
+ hdata->wh.dma_dir = datainp;
/*
- * wd33c93 shouldn't pass us bogus dma_setups, but
- * it does:-( The other wd33c93 drivers deal with
- * it the same way (which isn't that obvious).
- * IMHO a better fix would be, not to do these
- * dma setups in the first place
+ * wd33c93 shouldn't pass us bogus dma_setups, but it does:-( The
+ * other wd33c93 drivers deal with it the same way (which isn't that
+ * obvious). IMHO a better fix would be, not to do these dma setups
+ * in the first place.
*/
if (cmd->SCp.ptr == NULL || cmd->SCp.this_residual == 0)
return 1;
- fill_hpc_entries (&hcp, cmd->SCp.ptr, cmd->SCp.this_residual);
+ fill_hpc_entries(hcp, cmd, datainp);
- /* To make sure, if we trip an HPC bug, that we transfer
- * every single byte, we tag on an extra zero length dma
- * descriptor at the end of the chain.
- */
- hcp->desc.pbuf = 0;
- hcp->desc.cntinfo = (HPCDMA_EOX);
-
-#ifdef DEBUG_DMA
- printk(" HPCGO\n");
-#endif
+ DPRINTK(" HPCGO\n");
/* Start up the HPC. */
- hregs->ndptr = PHYSADDR(hdata->dma_bounce_buffer);
- if(datainp) {
- dma_cache_inv((unsigned long) cmd->SCp.ptr, cmd->SCp.this_residual);
- hregs->ctrl = (HPC3_SCTRL_ACTIVE);
- } else {
- dma_cache_wback_inv((unsigned long) cmd->SCp.ptr, cmd->SCp.this_residual);
- hregs->ctrl = (HPC3_SCTRL_ACTIVE | HPC3_SCTRL_DIR);
- }
+ hregs->ndptr = hdata->hd.dma;
+ if (datainp)
+ hregs->ctrl = HPC3_SCTRL_ACTIVE;
+ else
+ hregs->ctrl = HPC3_SCTRL_ACTIVE | HPC3_SCTRL_DIR;
return 0;
}
@@ -154,7 +166,7 @@
static void dma_stop(struct Scsi_Host *instance, Scsi_Cmnd *SCpnt,
int status)
{
- struct WD33C93_hostdata *hdata = (struct WD33C93_hostdata *)instance->hostdata;
+ struct ip22_hostdata *hdata = HDATA(instance);
struct hpc3_scsiregs *hregs;
if (!SCpnt)
@@ -162,21 +174,19 @@
hregs = (struct hpc3_scsiregs *) SCpnt->host->base;
-#ifdef DEBUG_DMA
- printk("dma_stop: status<%d> ", status);
-#endif
+ DPRINTK("dma_stop: status<%d> ", status);
/* First stop the HPC and flush it's FIFO. */
- if(hdata->dma_dir) {
+ if (hdata->wh.dma_dir) {
hregs->ctrl |= HPC3_SCTRL_FLUSH;
- while(hregs->ctrl & HPC3_SCTRL_ACTIVE)
+ while (hregs->ctrl & HPC3_SCTRL_ACTIVE)
barrier();
}
hregs->ctrl = 0;
+ pci_unmap_single(NULL, SCpnt->SCp.dma_handle, SCpnt->SCp.this_residual,
+ scsi_to_pci_dma_dir(SCpnt->sc_data_direction));
-#ifdef DEBUG_DMA
- printk("\n");
-#endif
+ DPRINTK("\n");
}
void sgiwd93_reset(unsigned long base)
@@ -184,119 +194,97 @@
struct hpc3_scsiregs *hregs = (struct hpc3_scsiregs *) base;
hregs->ctrl = HPC3_SCTRL_CRESET;
- udelay (50);
+ udelay(50);
hregs->ctrl = 0;
}
-static inline void init_hpc_chain(uchar *buf)
+static inline void init_hpc_chain(struct hpc_data *hd)
{
- struct hpc_chunk *hcp = (struct hpc_chunk *) buf;
+ struct hpc_chunk *hcp = (struct hpc_chunk *) hd->cpu;
+ struct hpc_chunk *dma = (struct hpc_chunk *) hd->dma;
unsigned long start, end;
- start = (unsigned long) buf;
+ start = (unsigned long) hcp;
end = start + PAGE_SIZE;
- while(start < end) {
- hcp->desc.pnext = PHYSADDR((hcp + 1));
+ while (start < end) {
+ hcp->desc.pnext = (u32) (dma + 1);
hcp->desc.cntinfo = HPCDMA_EOX;
- hcp++;
+ hcp++; dma++;
start += sizeof(struct hpc_chunk);
};
hcp--;
- hcp->desc.pnext = PHYSADDR(buf);
-
- /* Force flush to memory */
- dma_cache_wback_inv((unsigned long) buf, PAGE_SIZE);
+ hcp->desc.pnext = hd->dma;
}
-int __init sgiwd93_detect(Scsi_Host_Template *SGIblows)
+static struct Scsi_Host * __init sgiwd93_setup_scsi(
+ Scsi_Host_Template *SGIblows, int unit, int irq,
+ struct hpc3_scsiregs *hregs, unsigned char *wdregs)
{
- static unsigned char called = 0;
- struct hpc3_scsiregs *hregs = &hpc3c0->scsi_chan0;
- struct hpc3_scsiregs *hregs1 = &hpc3c0->scsi_chan1;
- struct WD33C93_hostdata *hdata;
- struct WD33C93_hostdata *hdata1;
+ struct ip22_hostdata *hdata;
+ struct Scsi_Host *host;
wd33c93_regs regs;
- uchar *buf;
-
- if(called)
- return 0; /* Should bitch on the console about this... */
- SGIblows->proc_name = "SGIWD93";
-
- sgiwd93_host = scsi_register(SGIblows, sizeof(struct WD33C93_hostdata));
- if(sgiwd93_host == NULL)
- return 0;
- sgiwd93_host->base = (unsigned long) hregs;
- sgiwd93_host->irq = SGI_WD93_0_IRQ;
-
- buf = (uchar *) get_zeroed_page(GFP_KERNEL);
- if (!buf) {
- printk(KERN_WARNING "sgiwd93: Could not allocate memory for host0 buffer.\n");
- scsi_unregister(sgiwd93_host);
- return 0;
+ host = scsi_register(SGIblows, sizeof(struct ip22_hostdata));
+ if (!host)
+ return NULL;
+
+ host->base = (unsigned long) hregs;
+ host->irq = irq;
+
+ hdata = HDATA(host);
+ hdata->hd.cpu = pci_alloc_consistent(NULL, PAGE_SIZE, &hdata->hd.dma);
+ if (!hdata->hd.cpu) {
+ printk(KERN_WARNING "sgiwd93: Could not allocate memory for "
+ "host %d buffer.\n", unit);
+ goto out_unregister;
}
- init_hpc_chain(buf);
-
- /* HPC_SCSI_REG0 | 0x03 | KSEG1 */
- regs.SASR = (unsigned char*) KSEG1ADDR (0x1fbc0003);
- regs.SCMD = (unsigned char*) KSEG1ADDR (0x1fbc0007);
- wd33c93_init(sgiwd93_host, regs, dma_setup, dma_stop, WD33C93_FS_16_20);
-
- hdata = (struct WD33C93_hostdata *)sgiwd93_host->hostdata;
- hdata->no_sync = 0;
- hdata->dma_bounce_buffer = (uchar *) (KSEG1ADDR(buf));
+ init_hpc_chain(&hdata->hd);
- if (request_irq(SGI_WD93_0_IRQ, sgiwd93_intr, 0, "SGI WD93", (void *) sgiwd93_host)) {
- printk(KERN_WARNING "sgiwd93: Could not register IRQ %d (for host 0).\n", SGI_WD93_0_IRQ);
-#ifdef MODULE
- wd33c93_release();
-#endif
- free_page((unsigned long)buf);
- scsi_unregister(sgiwd93_host);
- return 0;
+ regs.SASR = wdregs + 3;
+ regs.SCMD = wdregs + 7;
+
+ wd33c93_init(host, regs, dma_setup, dma_stop, WD33C93_FS_16_20);
+
+ hdata->wh.no_sync = 0;
+
+ if (request_irq(irq, sgiwd93_intr, 0, "SGI WD93", (void *) host)) {
+ printk(KERN_WARNING "sgiwd93: Could not register irq %d "
+ "for host %d.\n", irq, unit);
+ goto out_free;
}
- /* set up second controller on the Indigo2 */
- if(ip22_is_fullhouse()) {
- sgiwd93_host1 = scsi_register(SGIblows, sizeof(struct WD33C93_hostdata));
- if(sgiwd93_host1 != NULL)
- {
- sgiwd93_host1->base = (unsigned long) hregs1;
- sgiwd93_host1->irq = SGI_WD93_1_IRQ;
-
- buf = (uchar *) get_zeroed_page(GFP_KERNEL);
- if (!buf) {
- printk(KERN_WARNING "sgiwd93: Could not allocate memory for host1 buffer.\n");
- scsi_unregister(sgiwd93_host1);
- called = 1;
- return 1; /* We registered host0 so return success*/
- }
- init_hpc_chain(buf);
-
- /* HPC_SCSI_REG1 | 0x03 | KSEG1 */
- regs.SASR = (unsigned char*) KSEG1ADDR(0x1fbc8003);
- regs.SCMD = (unsigned char*) KSEG1ADDR(0x1fbc8007);
- wd33c93_init(sgiwd93_host1, regs, dma_setup, dma_stop,
- WD33C93_FS_16_20);
-
- hdata1 = (struct WD33C93_hostdata *)sgiwd93_host1->hostdata;
- hdata1->no_sync = 0;
- hdata1->dma_bounce_buffer = (uchar *) (KSEG1ADDR(buf));
-
- if (request_irq(SGI_WD93_1_IRQ, sgiwd93_intr, 0, "SGI WD93", (void *) sgiwd93_host1)) {
- printk(KERN_WARNING "sgiwd93: Could not allocate irq %d (for host1).\n", SGI_WD93_1_IRQ);
-#ifdef MODULE
- wd33c93_release();
-#endif
- free_page((unsigned long)buf);
- scsi_unregister(sgiwd93_host1);
- /* Fall through since host0 registered OK */
- }
- }
+ return host;
+
+out_free:
+ pci_free_consistent(NULL, PAGE_SIZE, hdata->hd.cpu, hdata->hd.dma);
+ wd33c93_release();
+
+out_unregister:
+ scsi_unregister(host);
+
+ return NULL;
+}
+
+int __init sgiwd93_detect(Scsi_Host_Template *SGIblows)
+{
+ int found = 0;
+
+ SGIblows->proc_name = "SGIWD93";
+ sgiwd93_host = sgiwd93_setup_scsi(SGIblows, 0, SGI_WD93_0_IRQ,
+ &hpc3c0->scsi_chan0,
+ (unsigned char *)hpc3c0->scsi0_ext);
+ if (sgiwd93_host)
+ found++;
+
+ /* Set up second controller on the Indigo2 */
+ if (ip22_is_fullhouse()) {
+ sgiwd93_host1 = sgiwd93_setup_scsi(SGIblows, 1, SGI_WD93_1_IRQ,
+ &hpc3c0->scsi_chan1,
+ (unsigned char *)hpc3c0->scsi1_ext);
+ if (sgiwd93_host1)
+ found++;
}
-
- called = 1;
- return 1; /* Found one. */
+ return found;
}
#define HOSTS_C
@@ -311,11 +299,12 @@
{
#ifdef MODULE
free_irq(SGI_WD93_0_IRQ, sgiwd93_intr);
- free_page(KSEG0ADDR(hdata->dma_bounce_buffer));
+ pci_free_consistent(NULL, PAGE_SIZE, hdata->hd.cpu, hdata->hd.dma);
wd33c93_release();
- if(ip22_is_fullhouse()) {
+ if (ip22_is_fullhouse()) {
free_irq(SGI_WD93_1_IRQ, sgiwd93_intr);
- free_page(KSEG0ADDR(hdata1->dma_bounce_buffer));
+ pci_free_consistent(NULL, PAGE_SIZE, hdata1->hd.cpu,
+ hdata1->hd.dma);
wd33c93_release();
}
#endif
FUNET's LINUX-ADM group, linux-adm@nic.funet.fi
TCL-scripts by Sam Shen (who was at: slshen@lbl.gov)