2005-10-10 06:51:27 -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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#define DEBUG
|
|
|
|
|
|
|
|
#include <linux/init.h>
|
2007-10-12 06:59:56 -07:00
|
|
|
#include <linux/io.h>
|
2005-10-10 06:51:27 -07:00
|
|
|
#include <linux/kernel.h>
|
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/netdevice.h>
|
|
|
|
#include <linux/etherdevice.h>
|
2005-10-29 11:07:23 -07:00
|
|
|
#include <linux/platform_device.h>
|
2005-10-10 06:51:27 -07:00
|
|
|
#include <asm/mips-boards/simint.h>
|
|
|
|
|
|
|
|
#include "mipsnet.h" /* actual device IO mapping */
|
|
|
|
|
|
|
|
#define MIPSNET_VERSION "2005-06-20"
|
|
|
|
|
|
|
|
#define mipsnet_reg_address(dev, field) (dev->base_addr + field_offset(field))
|
|
|
|
|
|
|
|
static char mipsnet_string[] = "mipsnet";
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Copy data from the MIPSNET rx data port
|
|
|
|
*/
|
|
|
|
static int ioiocpy_frommipsnet(struct net_device *dev, unsigned char *kdata,
|
|
|
|
int len)
|
|
|
|
{
|
|
|
|
uint32_t available_len = inl(mipsnet_reg_address(dev, rxDataCount));
|
|
|
|
if (available_len < len)
|
|
|
|
return -EFAULT;
|
|
|
|
|
2007-10-12 06:59:56 -07:00
|
|
|
for (; len > 0; len--, kdata++)
|
2005-10-10 06:51:27 -07:00
|
|
|
*kdata = inb(mipsnet_reg_address(dev, rxDataBuffer));
|
|
|
|
|
|
|
|
return inl(mipsnet_reg_address(dev, rxDataCount));
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline ssize_t mipsnet_put_todevice(struct net_device *dev,
|
|
|
|
struct sk_buff *skb)
|
|
|
|
{
|
|
|
|
int count_to_go = skb->len;
|
|
|
|
char *buf_ptr = skb->data;
|
|
|
|
|
|
|
|
pr_debug("%s: %s(): telling MIPSNET txDataCount(%d)\n",
|
2007-10-12 06:59:56 -07:00
|
|
|
dev->name, __FUNCTION__, skb->len);
|
2005-10-10 06:51:27 -07:00
|
|
|
|
|
|
|
outl(skb->len, mipsnet_reg_address(dev, txDataCount));
|
|
|
|
|
|
|
|
pr_debug("%s: %s(): sending data to MIPSNET txDataBuffer(%d)\n",
|
2007-10-12 06:59:56 -07:00
|
|
|
dev->name, __FUNCTION__, skb->len);
|
2005-10-10 06:51:27 -07:00
|
|
|
|
2007-10-12 06:59:56 -07:00
|
|
|
for (; count_to_go; buf_ptr++, count_to_go--)
|
2005-10-10 06:51:27 -07:00
|
|
|
outb(*buf_ptr, mipsnet_reg_address(dev, txDataBuffer));
|
|
|
|
|
2007-10-03 17:41:50 -07:00
|
|
|
dev->stats.tx_packets++;
|
|
|
|
dev->stats.tx_bytes += skb->len;
|
2005-10-10 06:51:27 -07:00
|
|
|
|
|
|
|
return skb->len;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int mipsnet_xmit(struct sk_buff *skb, struct net_device *dev)
|
|
|
|
{
|
|
|
|
pr_debug("%s:%s(): transmitting %d bytes\n",
|
2007-10-12 06:59:56 -07:00
|
|
|
dev->name, __FUNCTION__, skb->len);
|
2005-10-10 06:51:27 -07:00
|
|
|
|
|
|
|
/* Only one packet at a time. Once TXDONE interrupt is serviced, the
|
|
|
|
* queue will be restarted.
|
|
|
|
*/
|
|
|
|
netif_stop_queue(dev);
|
|
|
|
mipsnet_put_todevice(dev, skb);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline ssize_t mipsnet_get_fromdev(struct net_device *dev, size_t count)
|
|
|
|
{
|
|
|
|
struct sk_buff *skb;
|
|
|
|
size_t len = count;
|
|
|
|
|
2007-10-12 06:59:56 -07:00
|
|
|
skb = alloc_skb(len + 2, GFP_KERNEL);
|
|
|
|
if (!skb) {
|
2007-10-03 17:41:50 -07:00
|
|
|
dev->stats.rx_dropped++;
|
2005-10-10 06:51:27 -07:00
|
|
|
return -ENOMEM;
|
|
|
|
}
|
|
|
|
|
|
|
|
skb_reserve(skb, 2);
|
|
|
|
if (ioiocpy_frommipsnet(dev, skb_put(skb, len), len))
|
|
|
|
return -EFAULT;
|
|
|
|
|
|
|
|
skb->protocol = eth_type_trans(skb, dev);
|
|
|
|
skb->ip_summed = CHECKSUM_UNNECESSARY;
|
|
|
|
|
|
|
|
pr_debug("%s:%s(): pushing RXed data to kernel\n",
|
2007-10-12 06:59:56 -07:00
|
|
|
dev->name, __FUNCTION__);
|
2005-10-10 06:51:27 -07:00
|
|
|
netif_rx(skb);
|
|
|
|
|
2007-10-03 17:41:50 -07:00
|
|
|
dev->stats.rx_packets++;
|
|
|
|
dev->stats.rx_bytes += len;
|
2005-10-10 06:51:27 -07:00
|
|
|
|
|
|
|
return count;
|
|
|
|
}
|
|
|
|
|
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 06:55:46 -07:00
|
|
|
static irqreturn_t mipsnet_interrupt(int irq, void *dev_id)
|
2005-10-10 06:51:27 -07:00
|
|
|
{
|
|
|
|
struct net_device *dev = dev_id;
|
|
|
|
|
|
|
|
irqreturn_t retval = IRQ_NONE;
|
|
|
|
uint64_t interruptFlags;
|
|
|
|
|
|
|
|
if (irq == dev->irq) {
|
|
|
|
pr_debug("%s:%s(): irq %d for device\n",
|
2007-10-12 06:59:56 -07:00
|
|
|
dev->name, __FUNCTION__, irq);
|
2005-10-10 06:51:27 -07:00
|
|
|
|
|
|
|
retval = IRQ_HANDLED;
|
|
|
|
|
|
|
|
interruptFlags =
|
|
|
|
inl(mipsnet_reg_address(dev, interruptControl));
|
|
|
|
pr_debug("%s:%s(): intCtl=0x%016llx\n", dev->name,
|
2007-10-12 06:59:56 -07:00
|
|
|
__FUNCTION__, interruptFlags);
|
2005-10-10 06:51:27 -07:00
|
|
|
|
|
|
|
if (interruptFlags & MIPSNET_INTCTL_TXDONE) {
|
|
|
|
pr_debug("%s:%s(): got TXDone\n",
|
2007-10-12 06:59:56 -07:00
|
|
|
dev->name, __FUNCTION__);
|
2005-10-10 06:51:27 -07:00
|
|
|
outl(MIPSNET_INTCTL_TXDONE,
|
|
|
|
mipsnet_reg_address(dev, interruptControl));
|
2007-10-12 06:59:56 -07:00
|
|
|
/* only one packet at a time, we are done. */
|
2005-10-10 06:51:27 -07:00
|
|
|
netif_wake_queue(dev);
|
|
|
|
} else if (interruptFlags & MIPSNET_INTCTL_RXDONE) {
|
|
|
|
pr_debug("%s:%s(): got RX data\n",
|
2007-10-12 06:59:56 -07:00
|
|
|
dev->name, __FUNCTION__);
|
2005-10-10 06:51:27 -07:00
|
|
|
mipsnet_get_fromdev(dev,
|
2007-10-12 06:59:56 -07:00
|
|
|
inl(mipsnet_reg_address(dev, rxDataCount)));
|
2005-10-10 06:51:27 -07:00
|
|
|
pr_debug("%s:%s(): clearing RX int\n",
|
2007-10-12 06:59:56 -07:00
|
|
|
dev->name, __FUNCTION__);
|
2005-10-10 06:51:27 -07:00
|
|
|
outl(MIPSNET_INTCTL_RXDONE,
|
|
|
|
mipsnet_reg_address(dev, interruptControl));
|
|
|
|
|
|
|
|
} else if (interruptFlags & MIPSNET_INTCTL_TESTBIT) {
|
|
|
|
pr_debug("%s:%s(): got test interrupt\n",
|
2007-10-12 06:59:56 -07:00
|
|
|
dev->name, __FUNCTION__);
|
|
|
|
/*
|
|
|
|
* TESTBIT is cleared on read.
|
|
|
|
* And takes effect after a write with 0
|
|
|
|
*/
|
2005-10-10 06:51:27 -07:00
|
|
|
outl(0, mipsnet_reg_address(dev, interruptControl));
|
|
|
|
} else {
|
|
|
|
pr_debug("%s:%s(): no valid fags 0x%016llx\n",
|
2007-10-12 06:59:56 -07:00
|
|
|
dev->name, __FUNCTION__, interruptFlags);
|
|
|
|
/* Maybe shared IRQ, just ignore, no clearing. */
|
2005-10-10 06:51:27 -07:00
|
|
|
retval = IRQ_NONE;
|
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
|
|
|
printk(KERN_INFO "%s: %s(): irq %d for unknown device\n",
|
|
|
|
dev->name, __FUNCTION__, irq);
|
|
|
|
retval = IRQ_NONE;
|
|
|
|
}
|
|
|
|
return retval;
|
2007-10-12 06:59:56 -07:00
|
|
|
}
|
2005-10-10 06:51:27 -07:00
|
|
|
|
|
|
|
static int mipsnet_open(struct net_device *dev)
|
|
|
|
{
|
|
|
|
int err;
|
|
|
|
pr_debug("%s: mipsnet_open\n", dev->name);
|
|
|
|
|
|
|
|
err = request_irq(dev->irq, &mipsnet_interrupt,
|
2006-07-01 19:29:39 -07:00
|
|
|
IRQF_SHARED, dev->name, (void *) dev);
|
2005-10-10 06:51:27 -07:00
|
|
|
|
|
|
|
if (err) {
|
|
|
|
pr_debug("%s: %s(): can't get irq %d\n",
|
2007-10-12 06:59:56 -07:00
|
|
|
dev->name, __FUNCTION__, dev->irq);
|
2005-10-10 06:51:27 -07:00
|
|
|
release_region(dev->base_addr, MIPSNET_IO_EXTENT);
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
pr_debug("%s: %s(): got IO region at 0x%04lx and irq %d for dev.\n",
|
2007-10-12 06:59:56 -07:00
|
|
|
dev->name, __FUNCTION__, dev->base_addr, dev->irq);
|
2005-10-10 06:51:27 -07:00
|
|
|
|
|
|
|
|
|
|
|
netif_start_queue(dev);
|
|
|
|
|
2007-10-12 06:59:56 -07:00
|
|
|
/* test interrupt handler */
|
2005-10-10 06:51:27 -07:00
|
|
|
outl(MIPSNET_INTCTL_TESTBIT,
|
|
|
|
mipsnet_reg_address(dev, interruptControl));
|
|
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int mipsnet_close(struct net_device *dev)
|
|
|
|
{
|
|
|
|
pr_debug("%s: %s()\n", dev->name, __FUNCTION__);
|
|
|
|
netif_stop_queue(dev);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void mipsnet_set_mclist(struct net_device *dev)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
static int __init mipsnet_probe(struct device *dev)
|
|
|
|
{
|
|
|
|
struct net_device *netdev;
|
|
|
|
int err;
|
|
|
|
|
2007-10-03 17:41:50 -07:00
|
|
|
netdev = alloc_etherdev(0);
|
2005-10-10 06:51:27 -07:00
|
|
|
if (!netdev) {
|
|
|
|
err = -ENOMEM;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
dev_set_drvdata(dev, netdev);
|
|
|
|
|
|
|
|
netdev->open = mipsnet_open;
|
|
|
|
netdev->stop = mipsnet_close;
|
|
|
|
netdev->hard_start_xmit = mipsnet_xmit;
|
|
|
|
netdev->set_multicast_list = mipsnet_set_mclist;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* TODO: probe for these or load them from PARAM
|
|
|
|
*/
|
|
|
|
netdev->base_addr = 0x4200;
|
2007-06-20 14:27:10 -07:00
|
|
|
netdev->irq = MIPS_CPU_IRQ_BASE + MIPSCPU_INT_MB0 +
|
2007-10-12 06:59:56 -07:00
|
|
|
inl(mipsnet_reg_address(netdev, interruptInfo));
|
2005-10-10 06:51:27 -07:00
|
|
|
|
2007-10-12 06:59:56 -07:00
|
|
|
/* Get the io region now, get irq on open() */
|
2005-10-10 06:51:27 -07:00
|
|
|
if (!request_region(netdev->base_addr, MIPSNET_IO_EXTENT, "mipsnet")) {
|
|
|
|
pr_debug("%s: %s(): IO region {start: 0x%04lux, len: %d} "
|
2007-10-12 06:59:56 -07:00
|
|
|
"for dev is not availble.\n", netdev->name,
|
|
|
|
__FUNCTION__, netdev->base_addr, MIPSNET_IO_EXTENT);
|
2005-10-10 06:51:27 -07:00
|
|
|
err = -EBUSY;
|
|
|
|
goto out_free_netdev;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Lacking any better mechanism to allocate a MAC address we use a
|
|
|
|
* random one ...
|
|
|
|
*/
|
|
|
|
random_ether_addr(netdev->dev_addr);
|
|
|
|
|
|
|
|
err = register_netdev(netdev);
|
|
|
|
if (err) {
|
|
|
|
printk(KERN_ERR "MIPSNet: failed to register netdev.\n");
|
|
|
|
goto out_free_region;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
out_free_region:
|
|
|
|
release_region(netdev->base_addr, MIPSNET_IO_EXTENT);
|
|
|
|
|
|
|
|
out_free_netdev:
|
|
|
|
free_netdev(netdev);
|
|
|
|
|
|
|
|
out:
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int __devexit mipsnet_device_remove(struct device *device)
|
|
|
|
{
|
|
|
|
struct net_device *dev = dev_get_drvdata(device);
|
|
|
|
|
|
|
|
unregister_netdev(dev);
|
|
|
|
release_region(dev->base_addr, MIPSNET_IO_EXTENT);
|
|
|
|
free_netdev(dev);
|
|
|
|
dev_set_drvdata(device, NULL);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct device_driver mipsnet_driver = {
|
|
|
|
.name = mipsnet_string,
|
|
|
|
.bus = &platform_bus_type,
|
|
|
|
.probe = mipsnet_probe,
|
|
|
|
.remove = __devexit_p(mipsnet_device_remove),
|
|
|
|
};
|
|
|
|
|
|
|
|
static int __init mipsnet_init_module(void)
|
|
|
|
{
|
|
|
|
int err;
|
|
|
|
|
|
|
|
printk(KERN_INFO "MIPSNet Ethernet driver. Version: %s. "
|
|
|
|
"(c)2005 MIPS Technologies, Inc.\n", MIPSNET_VERSION);
|
|
|
|
|
2007-03-18 16:21:22 -07:00
|
|
|
err = driver_register(&mipsnet_driver);
|
|
|
|
if (err)
|
2005-10-10 06:51:27 -07:00
|
|
|
printk(KERN_ERR "Driver registration failed\n");
|
|
|
|
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void __exit mipsnet_exit_module(void)
|
|
|
|
{
|
|
|
|
pr_debug("MIPSNet Ethernet driver exiting\n");
|
|
|
|
|
|
|
|
driver_unregister(&mipsnet_driver);
|
|
|
|
}
|
|
|
|
|
|
|
|
module_init(mipsnet_init_module);
|
|
|
|
module_exit(mipsnet_exit_module);
|