2005-04-17 05:20:36 +07:00
|
|
|
/*
|
|
|
|
* 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)
|
|
|
|
* Copyright (C) 1999 Andrew R. Baker (andrewb@uab.edu)
|
|
|
|
* Copyright (C) 2001 Florian Lohoff (flo@rfc822.org)
|
2007-05-11 21:48:58 +07:00
|
|
|
* Copyright (C) 2003, 07 Ralf Baechle (ralf@linux-mips.org)
|
2005-04-17 05:20:36 +07:00
|
|
|
*
|
|
|
|
* (In all truth, Jed Schimmel wrote all this code.)
|
|
|
|
*/
|
2007-05-11 21:48:58 +07:00
|
|
|
|
|
|
|
#undef DEBUG
|
|
|
|
|
2005-04-17 05:20:36 +07:00
|
|
|
#include <linux/delay.h>
|
|
|
|
#include <linux/dma-mapping.h>
|
2007-05-11 21:48:58 +07:00
|
|
|
#include <linux/gfp.h>
|
|
|
|
#include <linux/interrupt.h>
|
|
|
|
#include <linux/init.h>
|
|
|
|
#include <linux/kernel.h>
|
|
|
|
#include <linux/types.h>
|
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/platform_device.h>
|
2005-04-17 05:20:36 +07:00
|
|
|
#include <linux/spinlock.h>
|
|
|
|
|
|
|
|
#include <asm/sgi/hpc3.h>
|
|
|
|
#include <asm/sgi/ip22.h>
|
2007-05-11 21:48:58 +07:00
|
|
|
#include <asm/sgi/wd.h>
|
2005-04-17 05:20:36 +07:00
|
|
|
|
|
|
|
#include "scsi.h"
|
|
|
|
#include "wd33c93.h"
|
|
|
|
|
|
|
|
struct ip22_hostdata {
|
|
|
|
struct WD33C93_hostdata wh;
|
2008-01-27 06:25:53 +07:00
|
|
|
dma_addr_t dma;
|
|
|
|
void *cpu;
|
|
|
|
struct device *dev;
|
2005-04-17 05:20:36 +07:00
|
|
|
};
|
|
|
|
|
2007-05-11 21:48:58 +07:00
|
|
|
#define host_to_hostdata(host) ((struct ip22_hostdata *)((host)->hostdata))
|
|
|
|
|
2005-04-17 05:20:36 +07:00
|
|
|
struct hpc_chunk {
|
|
|
|
struct hpc_dma_desc desc;
|
|
|
|
u32 _padding; /* align to quadword boundary */
|
|
|
|
};
|
|
|
|
|
2008-01-27 06:25:53 +07:00
|
|
|
/* space for hpc dma descriptors */
|
|
|
|
#define HPC_DMA_SIZE PAGE_SIZE
|
|
|
|
|
|
|
|
#define DMA_DIR(d) ((d == DATA_OUT_DIR) ? DMA_TO_DEVICE : DMA_FROM_DEVICE)
|
|
|
|
|
IRQ: Maintain regs pointer globally rather than passing to IRQ handlers
Maintain a per-CPU global "struct pt_regs *" variable which can be used instead
of passing regs around manually through all ~1800 interrupt handlers in the
Linux kernel.
The regs pointer is used in few places, but it potentially costs both stack
space and code to pass it around. On the FRV arch, removing the regs parameter
from all the genirq function results in a 20% speed up of the IRQ exit path
(ie: from leaving timer_interrupt() to leaving do_IRQ()).
Where appropriate, an arch may override the generic storage facility and do
something different with the variable. On FRV, for instance, the address is
maintained in GR28 at all times inside the kernel as part of general exception
handling.
Having looked over the code, it appears that the parameter may be handed down
through up to twenty or so layers of functions. Consider a USB character
device attached to a USB hub, attached to a USB controller that posts its
interrupts through a cascaded auxiliary interrupt controller. A character
device driver may want to pass regs to the sysrq handler through the input
layer which adds another few layers of parameter passing.
I've build this code with allyesconfig for x86_64 and i386. I've runtested the
main part of the code on FRV and i386, though I can't test most of the drivers.
I've also done partial conversion for powerpc and MIPS - these at least compile
with minimal configurations.
This will affect all archs. Mostly the changes should be relatively easy.
Take do_IRQ(), store the regs pointer at the beginning, saving the old one:
struct pt_regs *old_regs = set_irq_regs(regs);
And put the old one back at the end:
set_irq_regs(old_regs);
Don't pass regs through to generic_handle_irq() or __do_IRQ().
In timer_interrupt(), this sort of change will be necessary:
- update_process_times(user_mode(regs));
- profile_tick(CPU_PROFILING, regs);
+ update_process_times(user_mode(get_irq_regs()));
+ profile_tick(CPU_PROFILING);
I'd like to move update_process_times()'s use of get_irq_regs() into itself,
except that i386, alone of the archs, uses something other than user_mode().
Some notes on the interrupt handling in the drivers:
(*) input_dev() is now gone entirely. The regs pointer is no longer stored in
the input_dev struct.
(*) finish_unlinks() in drivers/usb/host/ohci-q.c needs checking. It does
something different depending on whether it's been supplied with a regs
pointer or not.
(*) Various IRQ handler function pointers have been moved to type
irq_handler_t.
Signed-Off-By: David Howells <dhowells@redhat.com>
(cherry picked from 1b16e7ac850969f38b375e511e3fa2f474a33867 commit)
2006-10-05 20:55:46 +07:00
|
|
|
static irqreturn_t sgiwd93_intr(int irq, void *dev_id)
|
2005-04-17 05:20:36 +07:00
|
|
|
{
|
2007-05-11 21:48:58 +07:00
|
|
|
struct Scsi_Host * host = dev_id;
|
2005-04-17 05:20:36 +07:00
|
|
|
unsigned long flags;
|
|
|
|
|
|
|
|
spin_lock_irqsave(host->host_lock, flags);
|
|
|
|
wd33c93_intr(host);
|
|
|
|
spin_unlock_irqrestore(host->host_lock, flags);
|
|
|
|
|
|
|
|
return IRQ_HANDLED;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline
|
2008-01-27 06:25:53 +07:00
|
|
|
void fill_hpc_entries(struct ip22_hostdata *hd, struct scsi_cmnd *cmd, int din)
|
2005-04-17 05:20:36 +07:00
|
|
|
{
|
|
|
|
unsigned long len = cmd->SCp.this_residual;
|
|
|
|
void *addr = cmd->SCp.ptr;
|
|
|
|
dma_addr_t physaddr;
|
|
|
|
unsigned long count;
|
2008-01-27 06:25:53 +07:00
|
|
|
struct hpc_chunk *hcp;
|
2005-04-17 05:20:36 +07:00
|
|
|
|
2008-01-27 06:25:53 +07:00
|
|
|
physaddr = dma_map_single(hd->dev, addr, len, DMA_DIR(din));
|
2005-04-17 05:20:36 +07:00
|
|
|
cmd->SCp.dma_handle = physaddr;
|
2008-01-27 06:25:53 +07:00
|
|
|
hcp = hd->cpu;
|
2005-04-17 05:20:36 +07:00
|
|
|
|
|
|
|
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++;
|
|
|
|
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;
|
2008-01-27 06:25:53 +07:00
|
|
|
dma_cache_sync(hd->dev, hd->cpu,
|
|
|
|
(unsigned long)(hcp + 1) - (unsigned long)hd->cpu,
|
|
|
|
DMA_TO_DEVICE);
|
2005-04-17 05:20:36 +07:00
|
|
|
}
|
|
|
|
|
2006-09-13 04:49:33 +07:00
|
|
|
static int dma_setup(struct scsi_cmnd *cmd, int datainp)
|
2005-04-17 05:20:36 +07:00
|
|
|
{
|
2007-05-11 21:48:58 +07:00
|
|
|
struct ip22_hostdata *hdata = host_to_hostdata(cmd->device->host);
|
2005-04-17 05:20:36 +07:00
|
|
|
struct hpc3_scsiregs *hregs =
|
|
|
|
(struct hpc3_scsiregs *) cmd->device->host->base;
|
|
|
|
|
2008-01-27 06:25:53 +07:00
|
|
|
pr_debug("dma_setup: datainp<%d> hcp<%p> ", datainp, hdata->cpu);
|
2005-04-17 05:20:36 +07:00
|
|
|
|
|
|
|
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.
|
|
|
|
*/
|
|
|
|
if (cmd->SCp.ptr == NULL || cmd->SCp.this_residual == 0)
|
|
|
|
return 1;
|
|
|
|
|
2008-01-27 06:25:53 +07:00
|
|
|
fill_hpc_entries(hdata, cmd, datainp);
|
2005-04-17 05:20:36 +07:00
|
|
|
|
2007-05-11 21:48:58 +07:00
|
|
|
pr_debug(" HPCGO\n");
|
2005-04-17 05:20:36 +07:00
|
|
|
|
|
|
|
/* Start up the HPC. */
|
2008-01-27 06:25:53 +07:00
|
|
|
hregs->ndptr = hdata->dma;
|
2005-04-17 05:20:36 +07:00
|
|
|
if (datainp)
|
|
|
|
hregs->ctrl = HPC3_SCTRL_ACTIVE;
|
|
|
|
else
|
|
|
|
hregs->ctrl = HPC3_SCTRL_ACTIVE | HPC3_SCTRL_DIR;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2006-09-13 04:49:33 +07:00
|
|
|
static void dma_stop(struct Scsi_Host *instance, struct scsi_cmnd *SCpnt,
|
2005-04-17 05:20:36 +07:00
|
|
|
int status)
|
|
|
|
{
|
2007-05-11 21:48:58 +07:00
|
|
|
struct ip22_hostdata *hdata = host_to_hostdata(instance);
|
2005-04-17 05:20:36 +07:00
|
|
|
struct hpc3_scsiregs *hregs;
|
|
|
|
|
|
|
|
if (!SCpnt)
|
|
|
|
return;
|
|
|
|
|
2008-01-27 06:25:53 +07:00
|
|
|
if (SCpnt->SCp.ptr == NULL || SCpnt->SCp.this_residual == 0)
|
|
|
|
return;
|
|
|
|
|
2005-04-17 05:20:36 +07:00
|
|
|
hregs = (struct hpc3_scsiregs *) SCpnt->device->host->base;
|
|
|
|
|
2007-05-11 21:48:58 +07:00
|
|
|
pr_debug("dma_stop: status<%d> ", status);
|
2005-04-17 05:20:36 +07:00
|
|
|
|
|
|
|
/* First stop the HPC and flush it's FIFO. */
|
|
|
|
if (hdata->wh.dma_dir) {
|
|
|
|
hregs->ctrl |= HPC3_SCTRL_FLUSH;
|
|
|
|
while (hregs->ctrl & HPC3_SCTRL_ACTIVE)
|
|
|
|
barrier();
|
|
|
|
}
|
|
|
|
hregs->ctrl = 0;
|
2008-01-27 06:25:53 +07:00
|
|
|
dma_unmap_single(hdata->dev, SCpnt->SCp.dma_handle,
|
|
|
|
SCpnt->SCp.this_residual,
|
|
|
|
DMA_DIR(hdata->wh.dma_dir));
|
2005-04-17 05:20:36 +07:00
|
|
|
|
2007-05-11 21:48:58 +07:00
|
|
|
pr_debug("\n");
|
2005-04-17 05:20:36 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
void sgiwd93_reset(unsigned long base)
|
|
|
|
{
|
|
|
|
struct hpc3_scsiregs *hregs = (struct hpc3_scsiregs *) base;
|
|
|
|
|
|
|
|
hregs->ctrl = HPC3_SCTRL_CRESET;
|
|
|
|
udelay(50);
|
|
|
|
hregs->ctrl = 0;
|
|
|
|
}
|
2007-12-14 07:14:23 +07:00
|
|
|
EXPORT_SYMBOL_GPL(sgiwd93_reset);
|
2005-04-17 05:20:36 +07:00
|
|
|
|
2008-01-27 06:25:53 +07:00
|
|
|
static inline void init_hpc_chain(struct ip22_hostdata *hdata)
|
2005-04-17 05:20:36 +07:00
|
|
|
{
|
2008-01-27 06:25:53 +07:00
|
|
|
struct hpc_chunk *hcp = (struct hpc_chunk *)hdata->cpu;
|
|
|
|
dma_addr_t dma = hdata->dma;
|
2005-04-17 05:20:36 +07:00
|
|
|
unsigned long start, end;
|
|
|
|
|
|
|
|
start = (unsigned long) hcp;
|
2008-01-27 06:25:53 +07:00
|
|
|
end = start + HPC_DMA_SIZE;
|
2005-04-17 05:20:36 +07:00
|
|
|
while (start < end) {
|
2008-01-27 06:25:53 +07:00
|
|
|
hcp->desc.pnext = (u32) (dma + sizeof(struct hpc_chunk));
|
2005-04-17 05:20:36 +07:00
|
|
|
hcp->desc.cntinfo = HPCDMA_EOX;
|
2008-01-27 06:25:53 +07:00
|
|
|
hcp++;
|
|
|
|
dma += sizeof(struct hpc_chunk);
|
2005-04-17 05:20:36 +07:00
|
|
|
start += sizeof(struct hpc_chunk);
|
|
|
|
};
|
|
|
|
hcp--;
|
2008-01-27 06:25:53 +07:00
|
|
|
hcp->desc.pnext = hdata->dma;
|
2005-04-17 05:20:36 +07:00
|
|
|
}
|
|
|
|
|
2007-05-11 21:48:58 +07:00
|
|
|
static int sgiwd93_bus_reset(struct scsi_cmnd *cmd)
|
|
|
|
{
|
|
|
|
/* FIXME perform bus-specific reset */
|
|
|
|
|
|
|
|
/* FIXME 2: kill this function, and let midlayer fallback
|
|
|
|
to the same result, calling wd33c93_host_reset() */
|
|
|
|
|
|
|
|
spin_lock_irq(cmd->device->host->host_lock);
|
|
|
|
wd33c93_host_reset(cmd);
|
|
|
|
spin_unlock_irq(cmd->device->host->host_lock);
|
|
|
|
|
|
|
|
return SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Kludge alert - the SCSI code calls the abort and reset method with int
|
|
|
|
* arguments not with pointers. So this is going to blow up beautyfully
|
|
|
|
* on 64-bit systems with memory outside the compat address spaces.
|
|
|
|
*/
|
|
|
|
static struct scsi_host_template sgiwd93_template = {
|
|
|
|
.module = THIS_MODULE,
|
|
|
|
.proc_name = "SGIWD93",
|
|
|
|
.name = "SGI WD93",
|
|
|
|
.queuecommand = wd33c93_queuecommand,
|
|
|
|
.eh_abort_handler = wd33c93_abort,
|
|
|
|
.eh_bus_reset_handler = sgiwd93_bus_reset,
|
|
|
|
.eh_host_reset_handler = wd33c93_host_reset,
|
|
|
|
.can_queue = 16,
|
|
|
|
.this_id = 7,
|
|
|
|
.sg_tablesize = SG_ALL,
|
|
|
|
.cmd_per_lun = 8,
|
|
|
|
.use_clustering = DISABLE_CLUSTERING,
|
|
|
|
};
|
|
|
|
|
2010-02-05 02:56:50 +07:00
|
|
|
static int __devinit sgiwd93_probe(struct platform_device *pdev)
|
2005-04-17 05:20:36 +07:00
|
|
|
{
|
2007-05-11 21:48:58 +07:00
|
|
|
struct sgiwd93_platform_data *pd = pdev->dev.platform_data;
|
|
|
|
unsigned char *wdregs = pd->wdregs;
|
|
|
|
struct hpc3_scsiregs *hregs = pd->hregs;
|
2005-04-17 05:20:36 +07:00
|
|
|
struct ip22_hostdata *hdata;
|
|
|
|
struct Scsi_Host *host;
|
|
|
|
wd33c93_regs regs;
|
2007-05-11 21:48:58 +07:00
|
|
|
unsigned int unit = pd->unit;
|
|
|
|
unsigned int irq = pd->irq;
|
|
|
|
int err;
|
|
|
|
|
|
|
|
host = scsi_host_alloc(&sgiwd93_template, sizeof(struct ip22_hostdata));
|
|
|
|
if (!host) {
|
|
|
|
err = -ENOMEM;
|
|
|
|
goto out;
|
|
|
|
}
|
2005-04-17 05:20:36 +07:00
|
|
|
|
|
|
|
host->base = (unsigned long) hregs;
|
|
|
|
host->irq = irq;
|
|
|
|
|
2007-05-11 21:48:58 +07:00
|
|
|
hdata = host_to_hostdata(host);
|
2008-01-27 06:25:53 +07:00
|
|
|
hdata->dev = &pdev->dev;
|
|
|
|
hdata->cpu = dma_alloc_noncoherent(&pdev->dev, HPC_DMA_SIZE,
|
|
|
|
&hdata->dma, GFP_KERNEL);
|
|
|
|
if (!hdata->cpu) {
|
2005-04-17 05:20:36 +07:00
|
|
|
printk(KERN_WARNING "sgiwd93: Could not allocate memory for "
|
|
|
|
"host %d buffer.\n", unit);
|
2007-05-11 21:48:58 +07:00
|
|
|
err = -ENOMEM;
|
|
|
|
goto out_put;
|
2005-04-17 05:20:36 +07:00
|
|
|
}
|
2007-05-11 21:48:58 +07:00
|
|
|
|
2008-01-27 06:25:53 +07:00
|
|
|
init_hpc_chain(hdata);
|
2005-04-17 05:20:36 +07:00
|
|
|
|
|
|
|
regs.SASR = wdregs + 3;
|
|
|
|
regs.SCMD = wdregs + 7;
|
|
|
|
|
2008-03-22 04:25:43 +07:00
|
|
|
hdata->wh.no_sync = 0;
|
|
|
|
hdata->wh.fast = 1;
|
|
|
|
hdata->wh.dma_mode = CTRL_BURST;
|
2005-04-17 05:20:36 +07:00
|
|
|
|
2008-03-22 04:25:43 +07:00
|
|
|
wd33c93_init(host, regs, dma_setup, dma_stop, WD33C93_FS_MHZ(20));
|
2005-04-17 05:20:36 +07:00
|
|
|
|
2007-05-11 21:48:58 +07:00
|
|
|
err = request_irq(irq, sgiwd93_intr, 0, "SGI WD93", host);
|
|
|
|
if (err) {
|
2005-04-17 05:20:36 +07:00
|
|
|
printk(KERN_WARNING "sgiwd93: Could not register irq %d "
|
|
|
|
"for host %d.\n", irq, unit);
|
|
|
|
goto out_free;
|
|
|
|
}
|
|
|
|
|
2007-05-11 21:48:58 +07:00
|
|
|
platform_set_drvdata(pdev, host);
|
2005-04-17 05:20:36 +07:00
|
|
|
|
2007-05-11 21:48:58 +07:00
|
|
|
err = scsi_add_host(host, NULL);
|
|
|
|
if (err)
|
|
|
|
goto out_irq;
|
2005-04-17 05:20:36 +07:00
|
|
|
|
2007-05-11 21:48:58 +07:00
|
|
|
scsi_scan_host(host);
|
2005-04-17 05:20:36 +07:00
|
|
|
|
2007-05-11 21:48:58 +07:00
|
|
|
return 0;
|
2005-04-17 05:20:36 +07:00
|
|
|
|
2007-05-11 21:48:58 +07:00
|
|
|
out_irq:
|
|
|
|
free_irq(irq, host);
|
|
|
|
out_free:
|
2008-01-27 06:25:53 +07:00
|
|
|
dma_free_noncoherent(&pdev->dev, HPC_DMA_SIZE, hdata->cpu, hdata->dma);
|
2007-05-11 21:48:58 +07:00
|
|
|
out_put:
|
|
|
|
scsi_host_put(host);
|
|
|
|
out:
|
2005-04-17 05:20:36 +07:00
|
|
|
|
2007-05-11 21:48:58 +07:00
|
|
|
return err;
|
2005-04-17 05:20:36 +07:00
|
|
|
}
|
|
|
|
|
2008-12-16 20:04:44 +07:00
|
|
|
static int __exit sgiwd93_remove(struct platform_device *pdev)
|
2005-04-17 05:20:36 +07:00
|
|
|
{
|
2007-05-11 21:48:58 +07:00
|
|
|
struct Scsi_Host *host = platform_get_drvdata(pdev);
|
|
|
|
struct ip22_hostdata *hdata = (struct ip22_hostdata *) host->hostdata;
|
|
|
|
struct sgiwd93_platform_data *pd = pdev->dev.platform_data;
|
|
|
|
|
|
|
|
scsi_remove_host(host);
|
|
|
|
free_irq(pd->irq, host);
|
2008-01-27 06:25:53 +07:00
|
|
|
dma_free_noncoherent(&pdev->dev, HPC_DMA_SIZE, hdata->cpu, hdata->dma);
|
2007-05-11 21:48:58 +07:00
|
|
|
scsi_host_put(host);
|
2008-12-16 20:04:44 +07:00
|
|
|
return 0;
|
2007-05-11 21:48:58 +07:00
|
|
|
}
|
2005-05-28 18:56:31 +07:00
|
|
|
|
2007-05-11 21:48:58 +07:00
|
|
|
static struct platform_driver sgiwd93_driver = {
|
|
|
|
.probe = sgiwd93_probe,
|
|
|
|
.remove = __devexit_p(sgiwd93_remove),
|
|
|
|
.driver = {
|
2008-04-19 03:57:19 +07:00
|
|
|
.name = "sgiwd93",
|
|
|
|
.owner = THIS_MODULE,
|
2007-05-11 21:48:58 +07:00
|
|
|
}
|
|
|
|
};
|
2005-05-28 18:57:14 +07:00
|
|
|
|
2007-05-11 21:48:58 +07:00
|
|
|
static int __init sgiwd93_module_init(void)
|
|
|
|
{
|
|
|
|
return platform_driver_register(&sgiwd93_driver);
|
|
|
|
}
|
2005-05-28 18:56:31 +07:00
|
|
|
|
2007-05-11 21:48:58 +07:00
|
|
|
static void __exit sgiwd93_module_exit(void)
|
|
|
|
{
|
|
|
|
return platform_driver_unregister(&sgiwd93_driver);
|
2005-04-17 05:20:36 +07:00
|
|
|
}
|
|
|
|
|
2007-05-11 21:48:58 +07:00
|
|
|
module_init(sgiwd93_module_init);
|
|
|
|
module_exit(sgiwd93_module_exit);
|
|
|
|
|
|
|
|
MODULE_DESCRIPTION("SGI WD33C93 driver");
|
|
|
|
MODULE_AUTHOR("Ralf Baechle <ralf@linux-mips.org>");
|
|
|
|
MODULE_LICENSE("GPL");
|
2008-04-19 03:57:19 +07:00
|
|
|
MODULE_ALIAS("platform:sgiwd93");
|