2005-04-17 06:20:36 +08:00
|
|
|
/*
|
|
|
|
* Copyright (c) 1999-2005 Petko Manolov (petkan@users.sourceforge.net)
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License version 2 as
|
|
|
|
* published by the Free Software Foundation.
|
|
|
|
*
|
|
|
|
* ChangeLog:
|
|
|
|
* .... Most of the time spent on reading sources & docs.
|
|
|
|
* v0.2.x First official release for the Linux kernel.
|
|
|
|
* v0.3.0 Beutified and structured, some bugs fixed.
|
|
|
|
* v0.3.x URBifying bulk requests and bugfixing. First relatively
|
|
|
|
* stable release. Still can touch device's registers only
|
|
|
|
* from top-halves.
|
|
|
|
* v0.4.0 Control messages remained unurbified are now URBs.
|
|
|
|
* Now we can touch the HW at any time.
|
|
|
|
* v0.4.9 Control urbs again use process context to wait. Argh...
|
|
|
|
* Some long standing bugs (enable_net_traffic) fixed.
|
|
|
|
* Also nasty trick about resubmiting control urb from
|
|
|
|
* interrupt context used. Please let me know how it
|
|
|
|
* behaves. Pegasus II support added since this version.
|
|
|
|
* TODO: suppressing HCD warnings spewage on disconnect.
|
|
|
|
* v0.4.13 Ethernet address is now set at probe(), not at open()
|
|
|
|
* time as this seems to break dhcpd.
|
|
|
|
* v0.5.0 branch to 2.5.x kernels
|
|
|
|
* v0.5.1 ethtool support added
|
|
|
|
* v0.5.5 rx socket buffers are in a pool and the their allocation
|
|
|
|
* is out of the interrupt routine.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/sched.h>
|
|
|
|
#include <linux/slab.h>
|
|
|
|
#include <linux/init.h>
|
|
|
|
#include <linux/delay.h>
|
|
|
|
#include <linux/netdevice.h>
|
|
|
|
#include <linux/etherdevice.h>
|
|
|
|
#include <linux/ethtool.h>
|
|
|
|
#include <linux/mii.h>
|
|
|
|
#include <linux/usb.h>
|
|
|
|
#include <linux/module.h>
|
|
|
|
#include <asm/byteorder.h>
|
|
|
|
#include <asm/uaccess.h>
|
|
|
|
#include "pegasus.h"
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Version Information
|
|
|
|
*/
|
2006-09-28 05:25:37 +08:00
|
|
|
#define DRIVER_VERSION "v0.6.14 (2006/09/27)"
|
2005-04-17 06:20:36 +08:00
|
|
|
#define DRIVER_AUTHOR "Petko Manolov <petkan@users.sourceforge.net>"
|
|
|
|
#define DRIVER_DESC "Pegasus/Pegasus II USB Ethernet driver"
|
|
|
|
|
|
|
|
static const char driver_name[] = "pegasus";
|
|
|
|
|
|
|
|
#undef PEGASUS_WRITE_EEPROM
|
|
|
|
#define BMSR_MEDIA (BMSR_10HALF | BMSR_10FULL | BMSR_100HALF | \
|
|
|
|
BMSR_100FULL | BMSR_ANEGCAPABLE)
|
|
|
|
|
|
|
|
static int loopback = 0;
|
|
|
|
static int mii_mode = 0;
|
2005-11-15 15:55:18 +08:00
|
|
|
static char *devid=NULL;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
static struct usb_eth_dev usb_dev_id[] = {
|
|
|
|
#define PEGASUS_DEV(pn, vid, pid, flags) \
|
|
|
|
{.name = pn, .vendor = vid, .device = pid, .private = flags},
|
2009-10-13 15:32:02 +08:00
|
|
|
#define PEGASUS_DEV_CLASS(pn, vid, pid, dclass, flags) \
|
|
|
|
PEGASUS_DEV(pn, vid, pid, flags)
|
2005-04-17 06:20:36 +08:00
|
|
|
#include "pegasus.h"
|
|
|
|
#undef PEGASUS_DEV
|
2009-10-13 15:32:02 +08:00
|
|
|
#undef PEGASUS_DEV_CLASS
|
2005-11-15 15:55:18 +08:00
|
|
|
{NULL, 0, 0, 0},
|
2005-04-17 06:20:36 +08:00
|
|
|
{NULL, 0, 0, 0}
|
|
|
|
};
|
|
|
|
|
|
|
|
static struct usb_device_id pegasus_ids[] = {
|
|
|
|
#define PEGASUS_DEV(pn, vid, pid, flags) \
|
|
|
|
{.match_flags = USB_DEVICE_ID_MATCH_DEVICE, .idVendor = vid, .idProduct = pid},
|
2009-10-13 15:32:02 +08:00
|
|
|
/*
|
|
|
|
* The Belkin F8T012xx1 bluetooth adaptor has the same vendor and product
|
|
|
|
* IDs as the Belkin F5D5050, so we need to teach the pegasus driver to
|
|
|
|
* ignore adaptors belonging to the "Wireless" class 0xE0. For this one
|
|
|
|
* case anyway, seeing as the pegasus is for "Wired" adaptors.
|
|
|
|
*/
|
|
|
|
#define PEGASUS_DEV_CLASS(pn, vid, pid, dclass, flags) \
|
|
|
|
{.match_flags = (USB_DEVICE_ID_MATCH_DEVICE | USB_DEVICE_ID_MATCH_DEV_CLASS), \
|
|
|
|
.idVendor = vid, .idProduct = pid, .bDeviceClass = dclass},
|
2005-04-17 06:20:36 +08:00
|
|
|
#include "pegasus.h"
|
|
|
|
#undef PEGASUS_DEV
|
2009-10-13 15:32:02 +08:00
|
|
|
#undef PEGASUS_DEV_CLASS
|
2005-11-15 15:55:18 +08:00
|
|
|
{},
|
2005-04-17 06:20:36 +08:00
|
|
|
{}
|
|
|
|
};
|
|
|
|
|
|
|
|
MODULE_AUTHOR(DRIVER_AUTHOR);
|
|
|
|
MODULE_DESCRIPTION(DRIVER_DESC);
|
|
|
|
MODULE_LICENSE("GPL");
|
|
|
|
module_param(loopback, bool, 0);
|
|
|
|
module_param(mii_mode, bool, 0);
|
2005-11-15 15:55:18 +08:00
|
|
|
module_param(devid, charp, 0);
|
2005-04-17 06:20:36 +08:00
|
|
|
MODULE_PARM_DESC(loopback, "Enable MAC loopback mode (bit 0)");
|
|
|
|
MODULE_PARM_DESC(mii_mode, "Enable HomePNA mode (bit 0),default=MII mode = 0");
|
2005-11-15 15:55:18 +08:00
|
|
|
MODULE_PARM_DESC(devid, "The format is: 'DEV_name:VendorID:DeviceID:Flags'");
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
/* use ethtool to change the level for any given device */
|
|
|
|
static int msg_level = -1;
|
|
|
|
module_param (msg_level, int, 0);
|
|
|
|
MODULE_PARM_DESC (msg_level, "Override default message level");
|
|
|
|
|
|
|
|
MODULE_DEVICE_TABLE(usb, pegasus_ids);
|
2009-01-09 03:22:25 +08:00
|
|
|
static const struct net_device_ops pegasus_netdev_ops;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
static int update_eth_regs_async(pegasus_t *);
|
|
|
|
/* Aargh!!! I _really_ hate such tweaks */
|
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 21:55:46 +08:00
|
|
|
static void ctrl_callback(struct urb *urb)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
pegasus_t *pegasus = urb->context;
|
2008-12-19 15:00:59 +08:00
|
|
|
int status = urb->status;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
if (!pegasus)
|
|
|
|
return;
|
|
|
|
|
2008-12-19 15:00:59 +08:00
|
|
|
switch (status) {
|
2005-04-17 06:20:36 +08:00
|
|
|
case 0:
|
|
|
|
if (pegasus->flags & ETH_REGS_CHANGE) {
|
|
|
|
pegasus->flags &= ~ETH_REGS_CHANGE;
|
|
|
|
pegasus->flags |= ETH_REGS_CHANGED;
|
|
|
|
update_eth_regs_async(pegasus);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case -EINPROGRESS:
|
|
|
|
return;
|
|
|
|
case -ENOENT:
|
|
|
|
break;
|
|
|
|
default:
|
2010-02-17 18:30:24 +08:00
|
|
|
if (net_ratelimit())
|
|
|
|
netif_dbg(pegasus, drv, pegasus->net,
|
|
|
|
"%s, status %d\n", __func__, status);
|
|
|
|
break;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
pegasus->flags &= ~ETH_REGS_CHANGED;
|
|
|
|
wake_up(&pegasus->ctrl_wait);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int get_registers(pegasus_t * pegasus, __u16 indx, __u16 size,
|
|
|
|
void *data)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
char *buffer;
|
|
|
|
DECLARE_WAITQUEUE(wait, current);
|
|
|
|
|
|
|
|
buffer = kmalloc(size, GFP_KERNEL);
|
|
|
|
if (!buffer) {
|
2010-02-17 18:30:24 +08:00
|
|
|
netif_warn(pegasus, drv, pegasus->net,
|
|
|
|
"out of memory in %s\n", __func__);
|
2005-04-17 06:20:36 +08:00
|
|
|
return -ENOMEM;
|
|
|
|
}
|
|
|
|
add_wait_queue(&pegasus->ctrl_wait, &wait);
|
|
|
|
set_current_state(TASK_UNINTERRUPTIBLE);
|
|
|
|
while (pegasus->flags & ETH_REGS_CHANGED)
|
|
|
|
schedule();
|
|
|
|
remove_wait_queue(&pegasus->ctrl_wait, &wait);
|
|
|
|
set_current_state(TASK_RUNNING);
|
|
|
|
|
|
|
|
pegasus->dr.bRequestType = PEGASUS_REQT_READ;
|
|
|
|
pegasus->dr.bRequest = PEGASUS_REQ_GET_REGS;
|
|
|
|
pegasus->dr.wValue = cpu_to_le16(0);
|
2008-10-30 05:25:51 +08:00
|
|
|
pegasus->dr.wIndex = cpu_to_le16(indx);
|
|
|
|
pegasus->dr.wLength = cpu_to_le16(size);
|
2005-04-17 06:20:36 +08:00
|
|
|
pegasus->ctrl_urb->transfer_buffer_length = size;
|
|
|
|
|
|
|
|
usb_fill_control_urb(pegasus->ctrl_urb, pegasus->usb,
|
|
|
|
usb_rcvctrlpipe(pegasus->usb, 0),
|
|
|
|
(char *) &pegasus->dr,
|
|
|
|
buffer, size, ctrl_callback, pegasus);
|
|
|
|
|
|
|
|
add_wait_queue(&pegasus->ctrl_wait, &wait);
|
|
|
|
set_current_state(TASK_UNINTERRUPTIBLE);
|
|
|
|
|
|
|
|
/* using ATOMIC, we'd never wake up if we slept */
|
|
|
|
if ((ret = usb_submit_urb(pegasus->ctrl_urb, GFP_ATOMIC))) {
|
2006-11-23 22:40:17 +08:00
|
|
|
set_current_state(TASK_RUNNING);
|
2006-05-27 01:17:03 +08:00
|
|
|
if (ret == -ENODEV)
|
|
|
|
netif_device_detach(pegasus->net);
|
2010-02-17 18:30:24 +08:00
|
|
|
if (net_ratelimit())
|
|
|
|
netif_err(pegasus, drv, pegasus->net,
|
|
|
|
"%s, status %d\n", __func__, ret);
|
2005-04-17 06:20:36 +08:00
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
schedule();
|
|
|
|
out:
|
|
|
|
remove_wait_queue(&pegasus->ctrl_wait, &wait);
|
|
|
|
memcpy(data, buffer, size);
|
|
|
|
kfree(buffer);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int set_registers(pegasus_t * pegasus, __u16 indx, __u16 size,
|
|
|
|
void *data)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
char *buffer;
|
|
|
|
DECLARE_WAITQUEUE(wait, current);
|
|
|
|
|
|
|
|
buffer = kmalloc(size, GFP_KERNEL);
|
|
|
|
if (!buffer) {
|
2010-02-17 18:30:24 +08:00
|
|
|
netif_warn(pegasus, drv, pegasus->net,
|
|
|
|
"out of memory in %s\n", __func__);
|
2005-04-17 06:20:36 +08:00
|
|
|
return -ENOMEM;
|
|
|
|
}
|
|
|
|
memcpy(buffer, data, size);
|
|
|
|
|
|
|
|
add_wait_queue(&pegasus->ctrl_wait, &wait);
|
|
|
|
set_current_state(TASK_UNINTERRUPTIBLE);
|
|
|
|
while (pegasus->flags & ETH_REGS_CHANGED)
|
|
|
|
schedule();
|
|
|
|
remove_wait_queue(&pegasus->ctrl_wait, &wait);
|
|
|
|
set_current_state(TASK_RUNNING);
|
|
|
|
|
|
|
|
pegasus->dr.bRequestType = PEGASUS_REQT_WRITE;
|
|
|
|
pegasus->dr.bRequest = PEGASUS_REQ_SET_REGS;
|
|
|
|
pegasus->dr.wValue = cpu_to_le16(0);
|
2008-10-30 05:25:51 +08:00
|
|
|
pegasus->dr.wIndex = cpu_to_le16(indx);
|
|
|
|
pegasus->dr.wLength = cpu_to_le16(size);
|
2005-04-17 06:20:36 +08:00
|
|
|
pegasus->ctrl_urb->transfer_buffer_length = size;
|
|
|
|
|
|
|
|
usb_fill_control_urb(pegasus->ctrl_urb, pegasus->usb,
|
|
|
|
usb_sndctrlpipe(pegasus->usb, 0),
|
|
|
|
(char *) &pegasus->dr,
|
|
|
|
buffer, size, ctrl_callback, pegasus);
|
|
|
|
|
|
|
|
add_wait_queue(&pegasus->ctrl_wait, &wait);
|
|
|
|
set_current_state(TASK_UNINTERRUPTIBLE);
|
|
|
|
|
|
|
|
if ((ret = usb_submit_urb(pegasus->ctrl_urb, GFP_ATOMIC))) {
|
2006-05-27 01:17:03 +08:00
|
|
|
if (ret == -ENODEV)
|
|
|
|
netif_device_detach(pegasus->net);
|
2010-02-17 18:30:24 +08:00
|
|
|
netif_err(pegasus, drv, pegasus->net,
|
|
|
|
"%s, status %d\n", __func__, ret);
|
2005-04-17 06:20:36 +08:00
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
schedule();
|
|
|
|
out:
|
|
|
|
remove_wait_queue(&pegasus->ctrl_wait, &wait);
|
|
|
|
kfree(buffer);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int set_register(pegasus_t * pegasus, __u16 indx, __u8 data)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
char *tmp;
|
|
|
|
DECLARE_WAITQUEUE(wait, current);
|
|
|
|
|
|
|
|
tmp = kmalloc(1, GFP_KERNEL);
|
|
|
|
if (!tmp) {
|
2010-02-17 18:30:24 +08:00
|
|
|
netif_warn(pegasus, drv, pegasus->net,
|
|
|
|
"out of memory in %s\n", __func__);
|
2005-04-17 06:20:36 +08:00
|
|
|
return -ENOMEM;
|
|
|
|
}
|
|
|
|
memcpy(tmp, &data, 1);
|
|
|
|
add_wait_queue(&pegasus->ctrl_wait, &wait);
|
|
|
|
set_current_state(TASK_UNINTERRUPTIBLE);
|
|
|
|
while (pegasus->flags & ETH_REGS_CHANGED)
|
|
|
|
schedule();
|
|
|
|
remove_wait_queue(&pegasus->ctrl_wait, &wait);
|
|
|
|
set_current_state(TASK_RUNNING);
|
|
|
|
|
|
|
|
pegasus->dr.bRequestType = PEGASUS_REQT_WRITE;
|
|
|
|
pegasus->dr.bRequest = PEGASUS_REQ_SET_REG;
|
|
|
|
pegasus->dr.wValue = cpu_to_le16(data);
|
2008-10-30 05:25:51 +08:00
|
|
|
pegasus->dr.wIndex = cpu_to_le16(indx);
|
2005-04-17 06:20:36 +08:00
|
|
|
pegasus->dr.wLength = cpu_to_le16(1);
|
|
|
|
pegasus->ctrl_urb->transfer_buffer_length = 1;
|
|
|
|
|
|
|
|
usb_fill_control_urb(pegasus->ctrl_urb, pegasus->usb,
|
|
|
|
usb_sndctrlpipe(pegasus->usb, 0),
|
|
|
|
(char *) &pegasus->dr,
|
2006-03-30 14:59:22 +08:00
|
|
|
tmp, 1, ctrl_callback, pegasus);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
add_wait_queue(&pegasus->ctrl_wait, &wait);
|
|
|
|
set_current_state(TASK_UNINTERRUPTIBLE);
|
|
|
|
|
|
|
|
if ((ret = usb_submit_urb(pegasus->ctrl_urb, GFP_ATOMIC))) {
|
2006-05-27 01:17:03 +08:00
|
|
|
if (ret == -ENODEV)
|
|
|
|
netif_device_detach(pegasus->net);
|
2010-02-17 18:30:24 +08:00
|
|
|
if (net_ratelimit())
|
|
|
|
netif_err(pegasus, drv, pegasus->net,
|
|
|
|
"%s, status %d\n", __func__, ret);
|
2005-04-17 06:20:36 +08:00
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
schedule();
|
|
|
|
out:
|
|
|
|
remove_wait_queue(&pegasus->ctrl_wait, &wait);
|
|
|
|
kfree(tmp);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int update_eth_regs_async(pegasus_t * pegasus)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
pegasus->dr.bRequestType = PEGASUS_REQT_WRITE;
|
|
|
|
pegasus->dr.bRequest = PEGASUS_REQ_SET_REGS;
|
2009-06-18 15:03:47 +08:00
|
|
|
pegasus->dr.wValue = cpu_to_le16(0);
|
2005-04-17 06:20:36 +08:00
|
|
|
pegasus->dr.wIndex = cpu_to_le16(EthCtrl0);
|
|
|
|
pegasus->dr.wLength = cpu_to_le16(3);
|
|
|
|
pegasus->ctrl_urb->transfer_buffer_length = 3;
|
|
|
|
|
|
|
|
usb_fill_control_urb(pegasus->ctrl_urb, pegasus->usb,
|
|
|
|
usb_sndctrlpipe(pegasus->usb, 0),
|
|
|
|
(char *) &pegasus->dr,
|
|
|
|
pegasus->eth_regs, 3, ctrl_callback, pegasus);
|
|
|
|
|
2006-05-27 01:17:03 +08:00
|
|
|
if ((ret = usb_submit_urb(pegasus->ctrl_urb, GFP_ATOMIC))) {
|
|
|
|
if (ret == -ENODEV)
|
|
|
|
netif_device_detach(pegasus->net);
|
2010-02-17 18:30:24 +08:00
|
|
|
netif_err(pegasus, drv, pegasus->net,
|
|
|
|
"%s, status %d\n", __func__, ret);
|
2006-05-27 01:17:03 +08:00
|
|
|
}
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2007-04-24 22:20:06 +08:00
|
|
|
/* Returns 0 on success, error on failure */
|
2005-04-17 06:20:36 +08:00
|
|
|
static int read_mii_word(pegasus_t * pegasus, __u8 phy, __u8 indx, __u16 * regd)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
__u8 data[4] = { phy, 0, 0, indx };
|
|
|
|
__le16 regdi;
|
|
|
|
int ret;
|
|
|
|
|
2005-11-15 15:48:23 +08:00
|
|
|
set_register(pegasus, PhyCtrl, 0);
|
|
|
|
set_registers(pegasus, PhyAddr, sizeof (data), data);
|
|
|
|
set_register(pegasus, PhyCtrl, (indx | PHY_READ));
|
2005-04-17 06:20:36 +08:00
|
|
|
for (i = 0; i < REG_TIMEOUT; i++) {
|
|
|
|
ret = get_registers(pegasus, PhyCtrl, 1, data);
|
2006-05-02 05:02:45 +08:00
|
|
|
if (ret == -ESHUTDOWN)
|
|
|
|
goto fail;
|
2005-04-17 06:20:36 +08:00
|
|
|
if (data[0] & PHY_DONE)
|
|
|
|
break;
|
|
|
|
}
|
2010-02-17 18:30:24 +08:00
|
|
|
|
|
|
|
if (i >= REG_TIMEOUT)
|
|
|
|
goto fail;
|
|
|
|
|
|
|
|
ret = get_registers(pegasus, PhyData, 2, ®di);
|
|
|
|
*regd = le16_to_cpu(regdi);
|
|
|
|
return ret;
|
|
|
|
|
2006-05-02 05:02:45 +08:00
|
|
|
fail:
|
2010-02-17 18:30:24 +08:00
|
|
|
netif_warn(pegasus, drv, pegasus->net, "%s failed\n", __func__);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2005-11-15 15:48:23 +08:00
|
|
|
return ret;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static int mdio_read(struct net_device *dev, int phy_id, int loc)
|
|
|
|
{
|
|
|
|
pegasus_t *pegasus = (pegasus_t *) netdev_priv(dev);
|
|
|
|
u16 res;
|
|
|
|
|
|
|
|
read_mii_word(pegasus, phy_id, loc, &res);
|
|
|
|
return (int)res;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int write_mii_word(pegasus_t * pegasus, __u8 phy, __u8 indx, __u16 regd)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
__u8 data[4] = { phy, 0, 0, indx };
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
data[1] = (u8) regd;
|
|
|
|
data[2] = (u8) (regd >> 8);
|
2005-11-15 15:48:23 +08:00
|
|
|
set_register(pegasus, PhyCtrl, 0);
|
|
|
|
set_registers(pegasus, PhyAddr, sizeof(data), data);
|
|
|
|
set_register(pegasus, PhyCtrl, (indx | PHY_WRITE));
|
2005-04-17 06:20:36 +08:00
|
|
|
for (i = 0; i < REG_TIMEOUT; i++) {
|
|
|
|
ret = get_registers(pegasus, PhyCtrl, 1, data);
|
2006-05-02 05:02:45 +08:00
|
|
|
if (ret == -ESHUTDOWN)
|
|
|
|
goto fail;
|
2005-04-17 06:20:36 +08:00
|
|
|
if (data[0] & PHY_DONE)
|
|
|
|
break;
|
|
|
|
}
|
2010-02-17 18:30:24 +08:00
|
|
|
|
|
|
|
if (i >= REG_TIMEOUT)
|
|
|
|
goto fail;
|
|
|
|
|
|
|
|
return ret;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2006-05-02 05:02:45 +08:00
|
|
|
fail:
|
2010-02-17 18:30:24 +08:00
|
|
|
netif_warn(pegasus, drv, pegasus->net, "%s failed\n", __func__);
|
2005-11-15 15:48:23 +08:00
|
|
|
return -ETIMEDOUT;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void mdio_write(struct net_device *dev, int phy_id, int loc, int val)
|
|
|
|
{
|
|
|
|
pegasus_t *pegasus = (pegasus_t *) netdev_priv(dev);
|
|
|
|
|
|
|
|
write_mii_word(pegasus, phy_id, loc, val);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int read_eprom_word(pegasus_t * pegasus, __u8 index, __u16 * retdata)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
__u8 tmp;
|
|
|
|
__le16 retdatai;
|
|
|
|
int ret;
|
|
|
|
|
2005-11-15 15:48:23 +08:00
|
|
|
set_register(pegasus, EpromCtrl, 0);
|
|
|
|
set_register(pegasus, EpromOffset, index);
|
|
|
|
set_register(pegasus, EpromCtrl, EPROM_READ);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
for (i = 0; i < REG_TIMEOUT; i++) {
|
|
|
|
ret = get_registers(pegasus, EpromCtrl, 1, &tmp);
|
|
|
|
if (tmp & EPROM_DONE)
|
|
|
|
break;
|
2006-05-02 05:02:45 +08:00
|
|
|
if (ret == -ESHUTDOWN)
|
|
|
|
goto fail;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
2010-02-17 18:30:24 +08:00
|
|
|
if (i >= REG_TIMEOUT)
|
|
|
|
goto fail;
|
|
|
|
|
|
|
|
ret = get_registers(pegasus, EpromData, 2, &retdatai);
|
|
|
|
*retdata = le16_to_cpu(retdatai);
|
|
|
|
return ret;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2006-05-02 05:02:45 +08:00
|
|
|
fail:
|
2010-02-17 18:30:24 +08:00
|
|
|
netif_warn(pegasus, drv, pegasus->net, "%s failed\n", __func__);
|
2005-11-15 15:48:23 +08:00
|
|
|
return -ETIMEDOUT;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef PEGASUS_WRITE_EEPROM
|
|
|
|
static inline void enable_eprom_write(pegasus_t * pegasus)
|
|
|
|
{
|
|
|
|
__u8 tmp;
|
|
|
|
int ret;
|
|
|
|
|
2005-11-15 15:48:23 +08:00
|
|
|
get_registers(pegasus, EthCtrl2, 1, &tmp);
|
|
|
|
set_register(pegasus, EthCtrl2, tmp | EPROM_WR_ENABLE);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline void disable_eprom_write(pegasus_t * pegasus)
|
|
|
|
{
|
|
|
|
__u8 tmp;
|
|
|
|
int ret;
|
|
|
|
|
2005-11-15 15:48:23 +08:00
|
|
|
get_registers(pegasus, EthCtrl2, 1, &tmp);
|
|
|
|
set_register(pegasus, EpromCtrl, 0);
|
|
|
|
set_register(pegasus, EthCtrl2, tmp & ~EPROM_WR_ENABLE);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static int write_eprom_word(pegasus_t * pegasus, __u8 index, __u16 data)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
__u8 tmp, d[4] = { 0x3f, 0, 0, EPROM_WRITE };
|
|
|
|
int ret;
|
2009-06-18 15:03:47 +08:00
|
|
|
__le16 le_data = cpu_to_le16(data);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2005-11-15 15:48:23 +08:00
|
|
|
set_registers(pegasus, EpromOffset, 4, d);
|
2005-04-17 06:20:36 +08:00
|
|
|
enable_eprom_write(pegasus);
|
2005-11-15 15:48:23 +08:00
|
|
|
set_register(pegasus, EpromOffset, index);
|
2009-06-18 15:03:47 +08:00
|
|
|
set_registers(pegasus, EpromData, 2, &le_data);
|
2005-11-15 15:48:23 +08:00
|
|
|
set_register(pegasus, EpromCtrl, EPROM_WRITE);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
for (i = 0; i < REG_TIMEOUT; i++) {
|
|
|
|
ret = get_registers(pegasus, EpromCtrl, 1, &tmp);
|
2006-05-02 05:02:45 +08:00
|
|
|
if (ret == -ESHUTDOWN)
|
|
|
|
goto fail;
|
2005-04-17 06:20:36 +08:00
|
|
|
if (tmp & EPROM_DONE)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
disable_eprom_write(pegasus);
|
2010-02-17 18:30:24 +08:00
|
|
|
if (i >= REG_TIMEOUT)
|
|
|
|
goto fail;
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
|
2006-05-02 05:02:45 +08:00
|
|
|
fail:
|
2010-02-17 18:30:24 +08:00
|
|
|
netif_warn(pegasus, drv, pegasus->net, "%s failed\n", __func__);
|
2005-11-15 15:48:23 +08:00
|
|
|
return -ETIMEDOUT;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
#endif /* PEGASUS_WRITE_EEPROM */
|
|
|
|
|
|
|
|
static inline void get_node_id(pegasus_t * pegasus, __u8 * id)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
__u16 w16;
|
|
|
|
|
|
|
|
for (i = 0; i < 3; i++) {
|
|
|
|
read_eprom_word(pegasus, i, &w16);
|
2008-10-30 05:25:51 +08:00
|
|
|
((__le16 *) id)[i] = cpu_to_le16(w16);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void set_ethernet_addr(pegasus_t * pegasus)
|
|
|
|
{
|
|
|
|
__u8 node_id[6];
|
|
|
|
|
2006-09-28 05:25:37 +08:00
|
|
|
if (pegasus->features & PEGASUS_II) {
|
|
|
|
get_registers(pegasus, 0x10, sizeof(node_id), node_id);
|
|
|
|
} else {
|
|
|
|
get_node_id(pegasus, node_id);
|
|
|
|
set_registers(pegasus, EthID, sizeof (node_id), node_id);
|
|
|
|
}
|
2005-04-17 06:20:36 +08:00
|
|
|
memcpy(pegasus->net->dev_addr, node_id, sizeof (node_id));
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline int reset_mac(pegasus_t * pegasus)
|
|
|
|
{
|
|
|
|
__u8 data = 0x8;
|
|
|
|
int i;
|
|
|
|
|
2005-11-15 15:48:23 +08:00
|
|
|
set_register(pegasus, EthCtrl1, data);
|
2005-04-17 06:20:36 +08:00
|
|
|
for (i = 0; i < REG_TIMEOUT; i++) {
|
2005-11-15 15:48:23 +08:00
|
|
|
get_registers(pegasus, EthCtrl1, 1, &data);
|
2005-04-17 06:20:36 +08:00
|
|
|
if (~data & 0x08) {
|
|
|
|
if (loopback & 1)
|
|
|
|
break;
|
|
|
|
if (mii_mode && (pegasus->features & HAS_HOME_PNA))
|
2005-11-15 15:48:23 +08:00
|
|
|
set_register(pegasus, Gpio1, 0x34);
|
2005-04-17 06:20:36 +08:00
|
|
|
else
|
2005-11-15 15:48:23 +08:00
|
|
|
set_register(pegasus, Gpio1, 0x26);
|
|
|
|
set_register(pegasus, Gpio0, pegasus->features);
|
|
|
|
set_register(pegasus, Gpio0, DEFAULT_GPIO_SET);
|
2005-04-17 06:20:36 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (i == REG_TIMEOUT)
|
2005-11-15 15:48:23 +08:00
|
|
|
return -ETIMEDOUT;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
if (usb_dev_id[pegasus->dev_index].vendor == VENDOR_LINKSYS ||
|
|
|
|
usb_dev_id[pegasus->dev_index].vendor == VENDOR_DLINK) {
|
2005-11-15 15:48:23 +08:00
|
|
|
set_register(pegasus, Gpio0, 0x24);
|
|
|
|
set_register(pegasus, Gpio0, 0x26);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
if (usb_dev_id[pegasus->dev_index].vendor == VENDOR_ELCON) {
|
|
|
|
__u16 auxmode;
|
|
|
|
read_mii_word(pegasus, 3, 0x1b, &auxmode);
|
|
|
|
write_mii_word(pegasus, 3, 0x1b, auxmode | 4);
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int enable_net_traffic(struct net_device *dev, struct usb_device *usb)
|
|
|
|
{
|
|
|
|
__u16 linkpart;
|
|
|
|
__u8 data[4];
|
|
|
|
pegasus_t *pegasus = netdev_priv(dev);
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
read_mii_word(pegasus, pegasus->phy, MII_LPA, &linkpart);
|
|
|
|
data[0] = 0xc9;
|
|
|
|
data[1] = 0;
|
|
|
|
if (linkpart & (ADVERTISE_100FULL | ADVERTISE_10FULL))
|
|
|
|
data[1] |= 0x20; /* set full duplex */
|
|
|
|
if (linkpart & (ADVERTISE_100FULL | ADVERTISE_100HALF))
|
|
|
|
data[1] |= 0x10; /* set 100 Mbps */
|
|
|
|
if (mii_mode)
|
|
|
|
data[1] = 0;
|
|
|
|
data[2] = (loopback & 1) ? 0x09 : 0x01;
|
|
|
|
|
|
|
|
memcpy(pegasus->eth_regs, data, sizeof (data));
|
|
|
|
ret = set_registers(pegasus, EthCtrl0, 3, data);
|
|
|
|
|
|
|
|
if (usb_dev_id[pegasus->dev_index].vendor == VENDOR_LINKSYS ||
|
2006-01-29 00:48:33 +08:00
|
|
|
usb_dev_id[pegasus->dev_index].vendor == VENDOR_LINKSYS2 ||
|
2005-04-17 06:20:36 +08:00
|
|
|
usb_dev_id[pegasus->dev_index].vendor == VENDOR_DLINK) {
|
|
|
|
u16 auxmode;
|
|
|
|
read_mii_word(pegasus, 0, 0x1b, &auxmode);
|
|
|
|
write_mii_word(pegasus, 0, 0x1b, auxmode | 4);
|
|
|
|
}
|
|
|
|
|
2005-11-15 15:48:23 +08:00
|
|
|
return ret;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void fill_skb_pool(pegasus_t * pegasus)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < RX_SKBS; i++) {
|
|
|
|
if (pegasus->rx_pool[i])
|
|
|
|
continue;
|
|
|
|
pegasus->rx_pool[i] = dev_alloc_skb(PEGASUS_MTU + 2);
|
|
|
|
/*
|
|
|
|
** we give up if the allocation fail. the tasklet will be
|
|
|
|
** rescheduled again anyway...
|
|
|
|
*/
|
|
|
|
if (pegasus->rx_pool[i] == NULL)
|
|
|
|
return;
|
|
|
|
skb_reserve(pegasus->rx_pool[i], 2);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void free_skb_pool(pegasus_t * pegasus)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < RX_SKBS; i++) {
|
|
|
|
if (pegasus->rx_pool[i]) {
|
|
|
|
dev_kfree_skb(pegasus->rx_pool[i]);
|
|
|
|
pegasus->rx_pool[i] = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline struct sk_buff *pull_skb(pegasus_t * pegasus)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
struct sk_buff *skb;
|
|
|
|
|
|
|
|
for (i = 0; i < RX_SKBS; i++) {
|
|
|
|
if (likely(pegasus->rx_pool[i] != NULL)) {
|
|
|
|
skb = pegasus->rx_pool[i];
|
|
|
|
pegasus->rx_pool[i] = NULL;
|
|
|
|
return skb;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
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 21:55:46 +08:00
|
|
|
static void read_bulk_callback(struct urb *urb)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
pegasus_t *pegasus = urb->context;
|
|
|
|
struct net_device *net;
|
|
|
|
int rx_status, count = urb->actual_length;
|
2008-12-19 15:00:59 +08:00
|
|
|
int status = urb->status;
|
2005-04-17 06:20:36 +08:00
|
|
|
u8 *buf = urb->transfer_buffer;
|
|
|
|
__u16 pkt_len;
|
|
|
|
|
|
|
|
if (!pegasus)
|
|
|
|
return;
|
|
|
|
|
|
|
|
net = pegasus->net;
|
|
|
|
if (!netif_device_present(net) || !netif_running(net))
|
|
|
|
return;
|
|
|
|
|
2008-12-19 15:00:59 +08:00
|
|
|
switch (status) {
|
2005-04-17 06:20:36 +08:00
|
|
|
case 0:
|
|
|
|
break;
|
2006-09-19 13:49:02 +08:00
|
|
|
case -ETIME:
|
2010-02-17 18:30:24 +08:00
|
|
|
netif_dbg(pegasus, rx_err, net, "reset MAC\n");
|
2005-04-17 06:20:36 +08:00
|
|
|
pegasus->flags &= ~PEGASUS_RX_BUSY;
|
|
|
|
break;
|
|
|
|
case -EPIPE: /* stall, or disconnect from TT */
|
|
|
|
/* FIXME schedule work to clear the halt */
|
2010-02-17 18:30:24 +08:00
|
|
|
netif_warn(pegasus, rx_err, net, "no rx stall recovery\n");
|
2005-04-17 06:20:36 +08:00
|
|
|
return;
|
|
|
|
case -ENOENT:
|
|
|
|
case -ECONNRESET:
|
|
|
|
case -ESHUTDOWN:
|
2010-02-17 18:30:24 +08:00
|
|
|
netif_dbg(pegasus, ifdown, net, "rx unlink, %d\n", status);
|
2005-04-17 06:20:36 +08:00
|
|
|
return;
|
|
|
|
default:
|
2010-02-17 18:30:24 +08:00
|
|
|
netif_dbg(pegasus, rx_err, net, "RX status %d\n", status);
|
2005-04-17 06:20:36 +08:00
|
|
|
goto goon;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!count || count < 4)
|
|
|
|
goto goon;
|
|
|
|
|
|
|
|
rx_status = buf[count - 2];
|
|
|
|
if (rx_status & 0x1e) {
|
2010-02-17 18:30:24 +08:00
|
|
|
netif_dbg(pegasus, rx_err, net,
|
|
|
|
"RX packet error %x\n", rx_status);
|
2005-04-17 06:20:36 +08:00
|
|
|
pegasus->stats.rx_errors++;
|
|
|
|
if (rx_status & 0x06) // long or runt
|
|
|
|
pegasus->stats.rx_length_errors++;
|
|
|
|
if (rx_status & 0x08)
|
|
|
|
pegasus->stats.rx_crc_errors++;
|
|
|
|
if (rx_status & 0x10) // extra bits
|
|
|
|
pegasus->stats.rx_frame_errors++;
|
|
|
|
goto goon;
|
|
|
|
}
|
|
|
|
if (pegasus->chip == 0x8513) {
|
|
|
|
pkt_len = le32_to_cpu(*(__le32 *)urb->transfer_buffer);
|
|
|
|
pkt_len &= 0x0fff;
|
|
|
|
pegasus->rx_skb->data += 2;
|
|
|
|
} else {
|
|
|
|
pkt_len = buf[count - 3] << 8;
|
|
|
|
pkt_len += buf[count - 4];
|
|
|
|
pkt_len &= 0xfff;
|
|
|
|
pkt_len -= 8;
|
|
|
|
}
|
|
|
|
|
2005-09-22 15:49:24 +08:00
|
|
|
/*
|
|
|
|
* If the packet is unreasonably long, quietly drop it rather than
|
|
|
|
* kernel panicing by calling skb_put.
|
|
|
|
*/
|
|
|
|
if (pkt_len > PEGASUS_MTU)
|
|
|
|
goto goon;
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
/*
|
|
|
|
* at this point we are sure pegasus->rx_skb != NULL
|
|
|
|
* so we go ahead and pass up the packet.
|
|
|
|
*/
|
|
|
|
skb_put(pegasus->rx_skb, pkt_len);
|
|
|
|
pegasus->rx_skb->protocol = eth_type_trans(pegasus->rx_skb, net);
|
|
|
|
netif_rx(pegasus->rx_skb);
|
|
|
|
pegasus->stats.rx_packets++;
|
|
|
|
pegasus->stats.rx_bytes += pkt_len;
|
|
|
|
|
|
|
|
if (pegasus->flags & PEGASUS_UNPLUG)
|
|
|
|
return;
|
|
|
|
|
|
|
|
spin_lock(&pegasus->rx_pool_lock);
|
|
|
|
pegasus->rx_skb = pull_skb(pegasus);
|
|
|
|
spin_unlock(&pegasus->rx_pool_lock);
|
|
|
|
|
|
|
|
if (pegasus->rx_skb == NULL)
|
|
|
|
goto tl_sched;
|
|
|
|
goon:
|
|
|
|
usb_fill_bulk_urb(pegasus->rx_urb, pegasus->usb,
|
|
|
|
usb_rcvbulkpipe(pegasus->usb, 1),
|
|
|
|
pegasus->rx_skb->data, PEGASUS_MTU + 8,
|
|
|
|
read_bulk_callback, pegasus);
|
2006-05-27 01:17:03 +08:00
|
|
|
rx_status = usb_submit_urb(pegasus->rx_urb, GFP_ATOMIC);
|
|
|
|
if (rx_status == -ENODEV)
|
|
|
|
netif_device_detach(pegasus->net);
|
|
|
|
else if (rx_status) {
|
2005-04-17 06:20:36 +08:00
|
|
|
pegasus->flags |= PEGASUS_RX_URB_FAIL;
|
|
|
|
goto tl_sched;
|
|
|
|
} else {
|
|
|
|
pegasus->flags &= ~PEGASUS_RX_URB_FAIL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
tl_sched:
|
|
|
|
tasklet_schedule(&pegasus->rx_tl);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void rx_fixup(unsigned long data)
|
|
|
|
{
|
|
|
|
pegasus_t *pegasus;
|
|
|
|
unsigned long flags;
|
2006-05-27 01:17:03 +08:00
|
|
|
int status;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
pegasus = (pegasus_t *) data;
|
|
|
|
if (pegasus->flags & PEGASUS_UNPLUG)
|
|
|
|
return;
|
|
|
|
|
|
|
|
spin_lock_irqsave(&pegasus->rx_pool_lock, flags);
|
|
|
|
fill_skb_pool(pegasus);
|
|
|
|
if (pegasus->flags & PEGASUS_RX_URB_FAIL)
|
|
|
|
if (pegasus->rx_skb)
|
|
|
|
goto try_again;
|
|
|
|
if (pegasus->rx_skb == NULL) {
|
|
|
|
pegasus->rx_skb = pull_skb(pegasus);
|
|
|
|
}
|
|
|
|
if (pegasus->rx_skb == NULL) {
|
2010-02-17 18:30:24 +08:00
|
|
|
netif_warn(pegasus, rx_err, pegasus->net, "low on memory\n");
|
2005-04-17 06:20:36 +08:00
|
|
|
tasklet_schedule(&pegasus->rx_tl);
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
usb_fill_bulk_urb(pegasus->rx_urb, pegasus->usb,
|
|
|
|
usb_rcvbulkpipe(pegasus->usb, 1),
|
|
|
|
pegasus->rx_skb->data, PEGASUS_MTU + 8,
|
|
|
|
read_bulk_callback, pegasus);
|
|
|
|
try_again:
|
2006-05-27 01:17:03 +08:00
|
|
|
status = usb_submit_urb(pegasus->rx_urb, GFP_ATOMIC);
|
|
|
|
if (status == -ENODEV)
|
|
|
|
netif_device_detach(pegasus->net);
|
|
|
|
else if (status) {
|
2005-04-17 06:20:36 +08:00
|
|
|
pegasus->flags |= PEGASUS_RX_URB_FAIL;
|
|
|
|
tasklet_schedule(&pegasus->rx_tl);
|
|
|
|
} else {
|
|
|
|
pegasus->flags &= ~PEGASUS_RX_URB_FAIL;
|
|
|
|
}
|
|
|
|
done:
|
|
|
|
spin_unlock_irqrestore(&pegasus->rx_pool_lock, flags);
|
|
|
|
}
|
|
|
|
|
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 21:55:46 +08:00
|
|
|
static void write_bulk_callback(struct urb *urb)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
pegasus_t *pegasus = urb->context;
|
2007-07-23 16:05:52 +08:00
|
|
|
struct net_device *net;
|
2008-12-19 15:00:59 +08:00
|
|
|
int status = urb->status;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
if (!pegasus)
|
|
|
|
return;
|
|
|
|
|
2007-07-23 16:05:52 +08:00
|
|
|
net = pegasus->net;
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
if (!netif_device_present(net) || !netif_running(net))
|
|
|
|
return;
|
|
|
|
|
2008-12-19 15:00:59 +08:00
|
|
|
switch (status) {
|
2005-04-17 06:20:36 +08:00
|
|
|
case -EPIPE:
|
|
|
|
/* FIXME schedule_work() to clear the tx halt */
|
|
|
|
netif_stop_queue(net);
|
2010-02-17 18:30:24 +08:00
|
|
|
netif_warn(pegasus, tx_err, net, "no tx stall recovery\n");
|
2005-04-17 06:20:36 +08:00
|
|
|
return;
|
|
|
|
case -ENOENT:
|
|
|
|
case -ECONNRESET:
|
|
|
|
case -ESHUTDOWN:
|
2010-02-17 18:30:24 +08:00
|
|
|
netif_dbg(pegasus, ifdown, net, "tx unlink, %d\n", status);
|
2005-04-17 06:20:36 +08:00
|
|
|
return;
|
|
|
|
default:
|
2010-02-17 18:30:24 +08:00
|
|
|
netif_info(pegasus, tx_err, net, "TX status %d\n", status);
|
2005-04-17 06:20:36 +08:00
|
|
|
/* FALL THROUGH */
|
|
|
|
case 0:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
net->trans_start = jiffies;
|
|
|
|
netif_wake_queue(net);
|
|
|
|
}
|
|
|
|
|
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 21:55:46 +08:00
|
|
|
static void intr_callback(struct urb *urb)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
pegasus_t *pegasus = urb->context;
|
|
|
|
struct net_device *net;
|
2008-12-19 15:00:59 +08:00
|
|
|
int res, status = urb->status;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
if (!pegasus)
|
|
|
|
return;
|
|
|
|
net = pegasus->net;
|
|
|
|
|
2008-12-19 15:00:59 +08:00
|
|
|
switch (status) {
|
2005-04-17 06:20:36 +08:00
|
|
|
case 0:
|
|
|
|
break;
|
|
|
|
case -ECONNRESET: /* unlink */
|
|
|
|
case -ENOENT:
|
|
|
|
case -ESHUTDOWN:
|
|
|
|
return;
|
|
|
|
default:
|
|
|
|
/* some Pegasus-I products report LOTS of data
|
|
|
|
* toggle errors... avoid log spamming
|
|
|
|
*/
|
2010-02-17 18:30:24 +08:00
|
|
|
netif_dbg(pegasus, timer, net, "intr status %d\n", status);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (urb->actual_length >= 6) {
|
|
|
|
u8 * d = urb->transfer_buffer;
|
|
|
|
|
|
|
|
/* byte 0 == tx_status1, reg 2B */
|
|
|
|
if (d[0] & (TX_UNDERRUN|EXCESSIVE_COL
|
|
|
|
|LATE_COL|JABBER_TIMEOUT)) {
|
|
|
|
pegasus->stats.tx_errors++;
|
|
|
|
if (d[0] & TX_UNDERRUN)
|
|
|
|
pegasus->stats.tx_fifo_errors++;
|
|
|
|
if (d[0] & (EXCESSIVE_COL | JABBER_TIMEOUT))
|
|
|
|
pegasus->stats.tx_aborted_errors++;
|
|
|
|
if (d[0] & LATE_COL)
|
|
|
|
pegasus->stats.tx_window_errors++;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* d[5].LINK_STATUS lies on some adapters.
|
|
|
|
* d[0].NO_CARRIER kicks in only with failed TX.
|
|
|
|
* ... so monitoring with MII may be safest.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* bytes 3-4 == rx_lostpkt, reg 2E/2F */
|
|
|
|
pegasus->stats.rx_missed_errors += ((d[3] & 0x7f) << 8) | d[4];
|
|
|
|
}
|
|
|
|
|
2008-12-19 15:00:59 +08:00
|
|
|
res = usb_submit_urb(urb, GFP_ATOMIC);
|
|
|
|
if (res == -ENODEV)
|
2006-05-27 01:17:03 +08:00
|
|
|
netif_device_detach(pegasus->net);
|
2010-02-17 18:30:24 +08:00
|
|
|
if (res)
|
|
|
|
netif_err(pegasus, timer, net,
|
|
|
|
"can't resubmit interrupt urb, %d\n", res);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void pegasus_tx_timeout(struct net_device *net)
|
|
|
|
{
|
|
|
|
pegasus_t *pegasus = netdev_priv(net);
|
2010-02-17 18:30:24 +08:00
|
|
|
netif_warn(pegasus, timer, net, "tx timeout\n");
|
2005-04-17 06:20:36 +08:00
|
|
|
usb_unlink_urb(pegasus->tx_urb);
|
|
|
|
pegasus->stats.tx_errors++;
|
|
|
|
}
|
|
|
|
|
2009-09-01 03:50:45 +08:00
|
|
|
static netdev_tx_t pegasus_start_xmit(struct sk_buff *skb,
|
|
|
|
struct net_device *net)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
pegasus_t *pegasus = netdev_priv(net);
|
|
|
|
int count = ((skb->len + 2) & 0x3f) ? skb->len + 2 : skb->len + 3;
|
|
|
|
int res;
|
|
|
|
__u16 l16 = skb->len;
|
|
|
|
|
|
|
|
netif_stop_queue(net);
|
|
|
|
|
|
|
|
((__le16 *) pegasus->tx_buff)[0] = cpu_to_le16(l16);
|
2007-03-28 05:55:52 +08:00
|
|
|
skb_copy_from_linear_data(skb, pegasus->tx_buff + 2, skb->len);
|
2005-04-17 06:20:36 +08:00
|
|
|
usb_fill_bulk_urb(pegasus->tx_urb, pegasus->usb,
|
|
|
|
usb_sndbulkpipe(pegasus->usb, 2),
|
|
|
|
pegasus->tx_buff, count,
|
|
|
|
write_bulk_callback, pegasus);
|
|
|
|
if ((res = usb_submit_urb(pegasus->tx_urb, GFP_ATOMIC))) {
|
2010-02-17 18:30:24 +08:00
|
|
|
netif_warn(pegasus, tx_err, net, "fail tx, %d\n", res);
|
2005-04-17 06:20:36 +08:00
|
|
|
switch (res) {
|
|
|
|
case -EPIPE: /* stall, or disconnect from TT */
|
|
|
|
/* cleanup should already have been scheduled */
|
|
|
|
break;
|
|
|
|
case -ENODEV: /* disconnect() upcoming */
|
2009-04-17 16:40:19 +08:00
|
|
|
case -EPERM:
|
2006-05-27 01:17:03 +08:00
|
|
|
netif_device_detach(pegasus->net);
|
2005-04-17 06:20:36 +08:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
pegasus->stats.tx_errors++;
|
|
|
|
netif_start_queue(net);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
pegasus->stats.tx_packets++;
|
|
|
|
pegasus->stats.tx_bytes += skb->len;
|
|
|
|
net->trans_start = jiffies;
|
|
|
|
}
|
|
|
|
dev_kfree_skb(skb);
|
|
|
|
|
2009-06-23 14:03:08 +08:00
|
|
|
return NETDEV_TX_OK;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static struct net_device_stats *pegasus_netdev_stats(struct net_device *dev)
|
|
|
|
{
|
|
|
|
return &((pegasus_t *) netdev_priv(dev))->stats;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void disable_net_traffic(pegasus_t * pegasus)
|
|
|
|
{
|
2009-06-18 15:03:47 +08:00
|
|
|
__le16 tmp = cpu_to_le16(0);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2009-06-18 15:03:47 +08:00
|
|
|
set_registers(pegasus, EthCtrl0, sizeof(tmp), &tmp);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline void get_interrupt_interval(pegasus_t * pegasus)
|
|
|
|
{
|
2009-06-18 15:03:47 +08:00
|
|
|
u16 data;
|
|
|
|
u8 interval;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2009-06-18 15:03:47 +08:00
|
|
|
read_eprom_word(pegasus, 4, &data);
|
|
|
|
interval = data >> 8;
|
2005-09-22 15:49:24 +08:00
|
|
|
if (pegasus->usb->speed != USB_SPEED_HIGH) {
|
2009-06-18 15:03:47 +08:00
|
|
|
if (interval < 0x80) {
|
2010-02-17 18:30:24 +08:00
|
|
|
netif_info(pegasus, timer, pegasus->net,
|
|
|
|
"intr interval changed from %ums to %ums\n",
|
|
|
|
interval, 0x80);
|
2009-06-18 15:03:47 +08:00
|
|
|
interval = 0x80;
|
|
|
|
data = (data & 0x00FF) | ((u16)interval << 8);
|
2005-09-22 15:49:24 +08:00
|
|
|
#ifdef PEGASUS_WRITE_EEPROM
|
2009-06-18 15:03:47 +08:00
|
|
|
write_eprom_word(pegasus, 4, data);
|
2005-04-17 06:20:36 +08:00
|
|
|
#endif
|
2005-09-22 15:49:24 +08:00
|
|
|
}
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
2009-06-18 15:03:47 +08:00
|
|
|
pegasus->intr_interval = interval;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void set_carrier(struct net_device *net)
|
|
|
|
{
|
|
|
|
pegasus_t *pegasus = netdev_priv(net);
|
|
|
|
u16 tmp;
|
|
|
|
|
2007-04-24 22:20:06 +08:00
|
|
|
if (read_mii_word(pegasus, pegasus->phy, MII_BMSR, &tmp))
|
2005-04-17 06:20:36 +08:00
|
|
|
return;
|
2005-09-22 15:49:24 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
if (tmp & BMSR_LSTATUS)
|
|
|
|
netif_carrier_on(net);
|
|
|
|
else
|
|
|
|
netif_carrier_off(net);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void free_all_urbs(pegasus_t * pegasus)
|
|
|
|
{
|
|
|
|
usb_free_urb(pegasus->intr_urb);
|
|
|
|
usb_free_urb(pegasus->tx_urb);
|
|
|
|
usb_free_urb(pegasus->rx_urb);
|
|
|
|
usb_free_urb(pegasus->ctrl_urb);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void unlink_all_urbs(pegasus_t * pegasus)
|
|
|
|
{
|
|
|
|
usb_kill_urb(pegasus->intr_urb);
|
|
|
|
usb_kill_urb(pegasus->tx_urb);
|
|
|
|
usb_kill_urb(pegasus->rx_urb);
|
|
|
|
usb_kill_urb(pegasus->ctrl_urb);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int alloc_urbs(pegasus_t * pegasus)
|
|
|
|
{
|
|
|
|
pegasus->ctrl_urb = usb_alloc_urb(0, GFP_KERNEL);
|
|
|
|
if (!pegasus->ctrl_urb) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
pegasus->rx_urb = usb_alloc_urb(0, GFP_KERNEL);
|
|
|
|
if (!pegasus->rx_urb) {
|
|
|
|
usb_free_urb(pegasus->ctrl_urb);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
pegasus->tx_urb = usb_alloc_urb(0, GFP_KERNEL);
|
|
|
|
if (!pegasus->tx_urb) {
|
|
|
|
usb_free_urb(pegasus->rx_urb);
|
|
|
|
usb_free_urb(pegasus->ctrl_urb);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
pegasus->intr_urb = usb_alloc_urb(0, GFP_KERNEL);
|
|
|
|
if (!pegasus->intr_urb) {
|
|
|
|
usb_free_urb(pegasus->tx_urb);
|
|
|
|
usb_free_urb(pegasus->rx_urb);
|
|
|
|
usb_free_urb(pegasus->ctrl_urb);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int pegasus_open(struct net_device *net)
|
|
|
|
{
|
|
|
|
pegasus_t *pegasus = netdev_priv(net);
|
|
|
|
int res;
|
|
|
|
|
|
|
|
if (pegasus->rx_skb == NULL)
|
|
|
|
pegasus->rx_skb = pull_skb(pegasus);
|
|
|
|
/*
|
|
|
|
** Note: no point to free the pool. it is empty :-)
|
|
|
|
*/
|
|
|
|
if (!pegasus->rx_skb)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
res = set_registers(pegasus, EthID, 6, net->dev_addr);
|
|
|
|
|
|
|
|
usb_fill_bulk_urb(pegasus->rx_urb, pegasus->usb,
|
|
|
|
usb_rcvbulkpipe(pegasus->usb, 1),
|
|
|
|
pegasus->rx_skb->data, PEGASUS_MTU + 8,
|
|
|
|
read_bulk_callback, pegasus);
|
|
|
|
if ((res = usb_submit_urb(pegasus->rx_urb, GFP_KERNEL))) {
|
2006-05-27 01:17:03 +08:00
|
|
|
if (res == -ENODEV)
|
|
|
|
netif_device_detach(pegasus->net);
|
2010-02-17 18:30:24 +08:00
|
|
|
netif_dbg(pegasus, ifup, net, "failed rx_urb, %d\n", res);
|
2005-04-17 06:20:36 +08:00
|
|
|
goto exit;
|
|
|
|
}
|
|
|
|
|
|
|
|
usb_fill_int_urb(pegasus->intr_urb, pegasus->usb,
|
|
|
|
usb_rcvintpipe(pegasus->usb, 3),
|
|
|
|
pegasus->intr_buff, sizeof (pegasus->intr_buff),
|
|
|
|
intr_callback, pegasus, pegasus->intr_interval);
|
|
|
|
if ((res = usb_submit_urb(pegasus->intr_urb, GFP_KERNEL))) {
|
2006-05-27 01:17:03 +08:00
|
|
|
if (res == -ENODEV)
|
|
|
|
netif_device_detach(pegasus->net);
|
2010-02-17 18:30:24 +08:00
|
|
|
netif_dbg(pegasus, ifup, net, "failed intr_urb, %d\n", res);
|
2005-04-17 06:20:36 +08:00
|
|
|
usb_kill_urb(pegasus->rx_urb);
|
|
|
|
goto exit;
|
|
|
|
}
|
|
|
|
if ((res = enable_net_traffic(net, pegasus->usb))) {
|
2010-02-17 18:30:24 +08:00
|
|
|
netif_dbg(pegasus, ifup, net,
|
|
|
|
"can't enable_net_traffic() - %d\n", res);
|
2005-04-17 06:20:36 +08:00
|
|
|
res = -EIO;
|
|
|
|
usb_kill_urb(pegasus->rx_urb);
|
|
|
|
usb_kill_urb(pegasus->intr_urb);
|
|
|
|
free_skb_pool(pegasus);
|
|
|
|
goto exit;
|
|
|
|
}
|
|
|
|
set_carrier(net);
|
|
|
|
netif_start_queue(net);
|
2010-02-17 18:30:24 +08:00
|
|
|
netif_dbg(pegasus, ifup, net, "open\n");
|
2005-04-17 06:20:36 +08:00
|
|
|
res = 0;
|
|
|
|
exit:
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int pegasus_close(struct net_device *net)
|
|
|
|
{
|
|
|
|
pegasus_t *pegasus = netdev_priv(net);
|
|
|
|
|
|
|
|
netif_stop_queue(net);
|
|
|
|
if (!(pegasus->flags & PEGASUS_UNPLUG))
|
|
|
|
disable_net_traffic(pegasus);
|
|
|
|
tasklet_kill(&pegasus->rx_tl);
|
|
|
|
unlink_all_urbs(pegasus);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void pegasus_get_drvinfo(struct net_device *dev,
|
|
|
|
struct ethtool_drvinfo *info)
|
|
|
|
{
|
|
|
|
pegasus_t *pegasus = netdev_priv(dev);
|
|
|
|
strncpy(info->driver, driver_name, sizeof (info->driver) - 1);
|
|
|
|
strncpy(info->version, DRIVER_VERSION, sizeof (info->version) - 1);
|
|
|
|
usb_make_path(pegasus->usb, info->bus_info, sizeof (info->bus_info));
|
|
|
|
}
|
|
|
|
|
|
|
|
/* also handles three patterns of some kind in hardware */
|
|
|
|
#define WOL_SUPPORTED (WAKE_MAGIC|WAKE_PHY)
|
|
|
|
|
|
|
|
static void
|
|
|
|
pegasus_get_wol(struct net_device *dev, struct ethtool_wolinfo *wol)
|
|
|
|
{
|
|
|
|
pegasus_t *pegasus = netdev_priv(dev);
|
|
|
|
|
|
|
|
wol->supported = WAKE_MAGIC | WAKE_PHY;
|
|
|
|
wol->wolopts = pegasus->wolopts;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
pegasus_set_wol(struct net_device *dev, struct ethtool_wolinfo *wol)
|
|
|
|
{
|
|
|
|
pegasus_t *pegasus = netdev_priv(dev);
|
|
|
|
u8 reg78 = 0x04;
|
|
|
|
|
|
|
|
if (wol->wolopts & ~WOL_SUPPORTED)
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
if (wol->wolopts & WAKE_MAGIC)
|
|
|
|
reg78 |= 0x80;
|
|
|
|
if (wol->wolopts & WAKE_PHY)
|
|
|
|
reg78 |= 0x40;
|
|
|
|
/* FIXME this 0x10 bit still needs to get set in the chip... */
|
|
|
|
if (wol->wolopts)
|
|
|
|
pegasus->eth_regs[0] |= 0x10;
|
|
|
|
else
|
|
|
|
pegasus->eth_regs[0] &= ~0x10;
|
|
|
|
pegasus->wolopts = wol->wolopts;
|
|
|
|
return set_register(pegasus, WakeupControl, reg78);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void pegasus_reset_wol(struct net_device *dev)
|
|
|
|
{
|
|
|
|
struct ethtool_wolinfo wol;
|
|
|
|
|
|
|
|
memset(&wol, 0, sizeof wol);
|
|
|
|
(void) pegasus_set_wol(dev, &wol);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
pegasus_get_settings(struct net_device *dev, struct ethtool_cmd *ecmd)
|
|
|
|
{
|
|
|
|
pegasus_t *pegasus;
|
|
|
|
|
|
|
|
pegasus = netdev_priv(dev);
|
|
|
|
mii_ethtool_gset(&pegasus->mii, ecmd);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
pegasus_set_settings(struct net_device *dev, struct ethtool_cmd *ecmd)
|
|
|
|
{
|
|
|
|
pegasus_t *pegasus = netdev_priv(dev);
|
|
|
|
return mii_ethtool_sset(&pegasus->mii, ecmd);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int pegasus_nway_reset(struct net_device *dev)
|
|
|
|
{
|
|
|
|
pegasus_t *pegasus = netdev_priv(dev);
|
|
|
|
return mii_nway_restart(&pegasus->mii);
|
|
|
|
}
|
|
|
|
|
|
|
|
static u32 pegasus_get_link(struct net_device *dev)
|
|
|
|
{
|
|
|
|
pegasus_t *pegasus = netdev_priv(dev);
|
|
|
|
return mii_link_ok(&pegasus->mii);
|
|
|
|
}
|
|
|
|
|
|
|
|
static u32 pegasus_get_msglevel(struct net_device *dev)
|
|
|
|
{
|
|
|
|
pegasus_t *pegasus = netdev_priv(dev);
|
|
|
|
return pegasus->msg_enable;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void pegasus_set_msglevel(struct net_device *dev, u32 v)
|
|
|
|
{
|
|
|
|
pegasus_t *pegasus = netdev_priv(dev);
|
|
|
|
pegasus->msg_enable = v;
|
|
|
|
}
|
|
|
|
|
2009-09-02 16:03:33 +08:00
|
|
|
static const struct ethtool_ops ops = {
|
2005-04-17 06:20:36 +08:00
|
|
|
.get_drvinfo = pegasus_get_drvinfo,
|
|
|
|
.get_settings = pegasus_get_settings,
|
|
|
|
.set_settings = pegasus_set_settings,
|
|
|
|
.nway_reset = pegasus_nway_reset,
|
|
|
|
.get_link = pegasus_get_link,
|
|
|
|
.get_msglevel = pegasus_get_msglevel,
|
|
|
|
.set_msglevel = pegasus_set_msglevel,
|
|
|
|
.get_wol = pegasus_get_wol,
|
|
|
|
.set_wol = pegasus_set_wol,
|
|
|
|
};
|
|
|
|
|
|
|
|
static int pegasus_ioctl(struct net_device *net, struct ifreq *rq, int cmd)
|
|
|
|
{
|
|
|
|
__u16 *data = (__u16 *) & rq->ifr_ifru;
|
|
|
|
pegasus_t *pegasus = netdev_priv(net);
|
|
|
|
int res;
|
|
|
|
|
|
|
|
switch (cmd) {
|
|
|
|
case SIOCDEVPRIVATE:
|
|
|
|
data[0] = pegasus->phy;
|
|
|
|
case SIOCDEVPRIVATE + 1:
|
|
|
|
read_mii_word(pegasus, data[0], data[1] & 0x1f, &data[3]);
|
|
|
|
res = 0;
|
|
|
|
break;
|
|
|
|
case SIOCDEVPRIVATE + 2:
|
|
|
|
if (!capable(CAP_NET_ADMIN))
|
|
|
|
return -EPERM;
|
|
|
|
write_mii_word(pegasus, pegasus->phy, data[1] & 0x1f, data[2]);
|
|
|
|
res = 0;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
res = -EOPNOTSUPP;
|
|
|
|
}
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void pegasus_set_multicast(struct net_device *net)
|
|
|
|
{
|
|
|
|
pegasus_t *pegasus = netdev_priv(net);
|
|
|
|
|
|
|
|
if (net->flags & IFF_PROMISC) {
|
|
|
|
pegasus->eth_regs[EthCtrl2] |= RX_PROMISCUOUS;
|
2010-02-17 18:30:24 +08:00
|
|
|
netif_info(pegasus, link, net, "Promiscuous mode enabled\n");
|
2010-02-08 12:30:35 +08:00
|
|
|
} else if (!netdev_mc_empty(net) || (net->flags & IFF_ALLMULTI)) {
|
2005-04-17 06:20:36 +08:00
|
|
|
pegasus->eth_regs[EthCtrl0] |= RX_MULTICAST;
|
|
|
|
pegasus->eth_regs[EthCtrl2] &= ~RX_PROMISCUOUS;
|
2010-02-17 18:30:24 +08:00
|
|
|
netif_dbg(pegasus, link, net, "set allmulti\n");
|
2005-04-17 06:20:36 +08:00
|
|
|
} else {
|
|
|
|
pegasus->eth_regs[EthCtrl0] &= ~RX_MULTICAST;
|
|
|
|
pegasus->eth_regs[EthCtrl2] &= ~RX_PROMISCUOUS;
|
|
|
|
}
|
|
|
|
|
2008-09-03 02:34:24 +08:00
|
|
|
pegasus->ctrl_urb->status = 0;
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
pegasus->flags |= ETH_REGS_CHANGE;
|
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 21:55:46 +08:00
|
|
|
ctrl_callback(pegasus->ctrl_urb);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static __u8 mii_phy_probe(pegasus_t * pegasus)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
__u16 tmp;
|
|
|
|
|
|
|
|
for (i = 0; i < 32; i++) {
|
|
|
|
read_mii_word(pegasus, i, MII_BMSR, &tmp);
|
|
|
|
if (tmp == 0 || tmp == 0xffff || (tmp & BMSR_MEDIA) == 0)
|
|
|
|
continue;
|
|
|
|
else
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0xff;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void setup_pegasus_II(pegasus_t * pegasus)
|
|
|
|
{
|
|
|
|
__u8 data = 0xa5;
|
|
|
|
|
2005-11-15 15:48:23 +08:00
|
|
|
set_register(pegasus, Reg1d, 0);
|
|
|
|
set_register(pegasus, Reg7b, 1);
|
2005-04-17 06:20:36 +08:00
|
|
|
mdelay(100);
|
|
|
|
if ((pegasus->features & HAS_HOME_PNA) && mii_mode)
|
2005-11-15 15:48:23 +08:00
|
|
|
set_register(pegasus, Reg7b, 0);
|
2005-04-17 06:20:36 +08:00
|
|
|
else
|
2005-11-15 15:48:23 +08:00
|
|
|
set_register(pegasus, Reg7b, 2);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2005-11-15 15:48:23 +08:00
|
|
|
set_register(pegasus, 0x83, data);
|
|
|
|
get_registers(pegasus, 0x83, 1, &data);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
if (data == 0xa5) {
|
|
|
|
pegasus->chip = 0x8513;
|
|
|
|
} else {
|
|
|
|
pegasus->chip = 0;
|
|
|
|
}
|
|
|
|
|
2005-11-15 15:48:23 +08:00
|
|
|
set_register(pegasus, 0x80, 0xc0);
|
|
|
|
set_register(pegasus, 0x83, 0xff);
|
|
|
|
set_register(pegasus, 0x84, 0x01);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
if (pegasus->features & HAS_HOME_PNA && mii_mode)
|
2005-11-15 15:48:23 +08:00
|
|
|
set_register(pegasus, Reg81, 6);
|
2005-04-17 06:20:36 +08:00
|
|
|
else
|
2005-11-15 15:48:23 +08:00
|
|
|
set_register(pegasus, Reg81, 2);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-11-16 16:36:08 +08:00
|
|
|
static int pegasus_count;
|
2005-04-17 06:20:36 +08:00
|
|
|
static struct workqueue_struct *pegasus_workqueue = NULL;
|
|
|
|
#define CARRIER_CHECK_DELAY (2 * HZ)
|
|
|
|
|
2006-11-22 22:57:56 +08:00
|
|
|
static void check_carrier(struct work_struct *work)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2006-11-22 22:57:56 +08:00
|
|
|
pegasus_t *pegasus = container_of(work, pegasus_t, carrier_check.work);
|
2005-04-17 06:20:36 +08:00
|
|
|
set_carrier(pegasus->net);
|
|
|
|
if (!(pegasus->flags & PEGASUS_UNPLUG)) {
|
|
|
|
queue_delayed_work(pegasus_workqueue, &pegasus->carrier_check,
|
|
|
|
CARRIER_CHECK_DELAY);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-07-31 03:39:02 +08:00
|
|
|
static int pegasus_blacklisted(struct usb_device *udev)
|
|
|
|
{
|
|
|
|
struct usb_device_descriptor *udd = &udev->descriptor;
|
|
|
|
|
|
|
|
/* Special quirk to keep the driver from handling the Belkin Bluetooth
|
|
|
|
* dongle which happens to have the same ID.
|
|
|
|
*/
|
2009-06-18 15:03:47 +08:00
|
|
|
if ((udd->idVendor == cpu_to_le16(VENDOR_BELKIN)) &&
|
|
|
|
(udd->idProduct == cpu_to_le16(0x0121)) &&
|
2008-07-31 03:39:02 +08:00
|
|
|
(udd->bDeviceClass == USB_CLASS_WIRELESS_CONTROLLER) &&
|
|
|
|
(udd->bDeviceProtocol == 1))
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2008-11-16 16:36:08 +08:00
|
|
|
/* we rely on probe() and remove() being serialized so we
|
|
|
|
* don't need extra locking on pegasus_count.
|
|
|
|
*/
|
|
|
|
static void pegasus_dec_workqueue(void)
|
|
|
|
{
|
|
|
|
pegasus_count--;
|
|
|
|
if (pegasus_count == 0) {
|
|
|
|
destroy_workqueue(pegasus_workqueue);
|
|
|
|
pegasus_workqueue = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
static int pegasus_probe(struct usb_interface *intf,
|
|
|
|
const struct usb_device_id *id)
|
|
|
|
{
|
|
|
|
struct usb_device *dev = interface_to_usbdev(intf);
|
|
|
|
struct net_device *net;
|
|
|
|
pegasus_t *pegasus;
|
|
|
|
int dev_index = id - pegasus_ids;
|
|
|
|
int res = -ENOMEM;
|
|
|
|
|
2008-11-16 16:36:08 +08:00
|
|
|
if (pegasus_blacklisted(dev))
|
|
|
|
return -ENODEV;
|
2008-07-31 03:39:02 +08:00
|
|
|
|
2008-11-16 16:36:08 +08:00
|
|
|
if (pegasus_count == 0) {
|
|
|
|
pegasus_workqueue = create_singlethread_workqueue("pegasus");
|
|
|
|
if (!pegasus_workqueue)
|
|
|
|
return -ENOMEM;
|
2008-07-31 03:39:02 +08:00
|
|
|
}
|
2008-11-16 16:36:08 +08:00
|
|
|
pegasus_count++;
|
|
|
|
|
|
|
|
usb_get_dev(dev);
|
2008-07-31 03:39:02 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
net = alloc_etherdev(sizeof(struct pegasus));
|
|
|
|
if (!net) {
|
|
|
|
dev_err(&intf->dev, "can't allocate %s\n", "device");
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
pegasus = netdev_priv(net);
|
|
|
|
pegasus->dev_index = dev_index;
|
|
|
|
init_waitqueue_head(&pegasus->ctrl_wait);
|
|
|
|
|
|
|
|
if (!alloc_urbs(pegasus)) {
|
|
|
|
dev_err(&intf->dev, "can't allocate %s\n", "urbs");
|
|
|
|
goto out1;
|
|
|
|
}
|
|
|
|
|
|
|
|
tasklet_init(&pegasus->rx_tl, rx_fixup, (unsigned long) pegasus);
|
|
|
|
|
2006-11-22 22:57:56 +08:00
|
|
|
INIT_DELAYED_WORK(&pegasus->carrier_check, check_carrier);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
pegasus->intf = intf;
|
|
|
|
pegasus->usb = dev;
|
|
|
|
pegasus->net = net;
|
2009-01-09 03:22:25 +08:00
|
|
|
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
net->watchdog_timeo = PEGASUS_TX_TIMEOUT;
|
2009-01-09 03:22:25 +08:00
|
|
|
net->netdev_ops = &pegasus_netdev_ops;
|
2005-04-17 06:20:36 +08:00
|
|
|
SET_ETHTOOL_OPS(net, &ops);
|
|
|
|
pegasus->mii.dev = net;
|
|
|
|
pegasus->mii.mdio_read = mdio_read;
|
|
|
|
pegasus->mii.mdio_write = mdio_write;
|
|
|
|
pegasus->mii.phy_id_mask = 0x1f;
|
|
|
|
pegasus->mii.reg_num_mask = 0x1f;
|
|
|
|
spin_lock_init(&pegasus->rx_pool_lock);
|
|
|
|
pegasus->msg_enable = netif_msg_init (msg_level, NETIF_MSG_DRV
|
|
|
|
| NETIF_MSG_PROBE | NETIF_MSG_LINK);
|
|
|
|
|
|
|
|
pegasus->features = usb_dev_id[dev_index].private;
|
|
|
|
get_interrupt_interval(pegasus);
|
|
|
|
if (reset_mac(pegasus)) {
|
|
|
|
dev_err(&intf->dev, "can't reset MAC\n");
|
|
|
|
res = -EIO;
|
|
|
|
goto out2;
|
|
|
|
}
|
|
|
|
set_ethernet_addr(pegasus);
|
|
|
|
fill_skb_pool(pegasus);
|
|
|
|
if (pegasus->features & PEGASUS_II) {
|
|
|
|
dev_info(&intf->dev, "setup Pegasus II specific registers\n");
|
|
|
|
setup_pegasus_II(pegasus);
|
|
|
|
}
|
|
|
|
pegasus->phy = mii_phy_probe(pegasus);
|
|
|
|
if (pegasus->phy == 0xff) {
|
|
|
|
dev_warn(&intf->dev, "can't locate MII phy, using default\n");
|
|
|
|
pegasus->phy = 1;
|
|
|
|
}
|
|
|
|
pegasus->mii.phy_id = pegasus->phy;
|
|
|
|
usb_set_intfdata(intf, pegasus);
|
|
|
|
SET_NETDEV_DEV(net, &intf->dev);
|
|
|
|
pegasus_reset_wol(net);
|
|
|
|
res = register_netdev(net);
|
|
|
|
if (res)
|
|
|
|
goto out3;
|
|
|
|
queue_delayed_work(pegasus_workqueue, &pegasus->carrier_check,
|
|
|
|
CARRIER_CHECK_DELAY);
|
|
|
|
|
2008-10-28 06:59:26 +08:00
|
|
|
dev_info(&intf->dev, "%s, %s, %pM\n",
|
2007-10-04 08:59:30 +08:00
|
|
|
net->name,
|
|
|
|
usb_dev_id[dev_index].name,
|
2008-10-28 06:59:26 +08:00
|
|
|
net->dev_addr);
|
2005-04-17 06:20:36 +08:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
out3:
|
|
|
|
usb_set_intfdata(intf, NULL);
|
|
|
|
free_skb_pool(pegasus);
|
|
|
|
out2:
|
|
|
|
free_all_urbs(pegasus);
|
|
|
|
out1:
|
|
|
|
free_netdev(net);
|
|
|
|
out:
|
|
|
|
usb_put_dev(dev);
|
2008-11-16 16:36:08 +08:00
|
|
|
pegasus_dec_workqueue();
|
2005-04-17 06:20:36 +08:00
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void pegasus_disconnect(struct usb_interface *intf)
|
|
|
|
{
|
|
|
|
struct pegasus *pegasus = usb_get_intfdata(intf);
|
|
|
|
|
|
|
|
usb_set_intfdata(intf, NULL);
|
|
|
|
if (!pegasus) {
|
|
|
|
dev_dbg(&intf->dev, "unregistering non-bound device?\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
pegasus->flags |= PEGASUS_UNPLUG;
|
|
|
|
cancel_delayed_work(&pegasus->carrier_check);
|
|
|
|
unregister_netdev(pegasus->net);
|
|
|
|
usb_put_dev(interface_to_usbdev(intf));
|
2005-09-22 15:49:24 +08:00
|
|
|
unlink_all_urbs(pegasus);
|
2005-04-17 06:20:36 +08:00
|
|
|
free_all_urbs(pegasus);
|
|
|
|
free_skb_pool(pegasus);
|
2007-04-26 08:40:23 +08:00
|
|
|
if (pegasus->rx_skb != NULL) {
|
2005-04-17 06:20:36 +08:00
|
|
|
dev_kfree_skb(pegasus->rx_skb);
|
2007-04-26 08:40:23 +08:00
|
|
|
pegasus->rx_skb = NULL;
|
|
|
|
}
|
2005-04-17 06:20:36 +08:00
|
|
|
free_netdev(pegasus->net);
|
2008-11-16 16:36:08 +08:00
|
|
|
pegasus_dec_workqueue();
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
2005-04-19 08:39:22 +08:00
|
|
|
static int pegasus_suspend (struct usb_interface *intf, pm_message_t message)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
struct pegasus *pegasus = usb_get_intfdata(intf);
|
|
|
|
|
|
|
|
netif_device_detach (pegasus->net);
|
2006-05-02 05:02:45 +08:00
|
|
|
cancel_delayed_work(&pegasus->carrier_check);
|
2005-04-19 08:39:22 +08:00
|
|
|
if (netif_running(pegasus->net)) {
|
|
|
|
usb_kill_urb(pegasus->rx_urb);
|
|
|
|
usb_kill_urb(pegasus->intr_urb);
|
|
|
|
}
|
2005-04-17 06:20:36 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int pegasus_resume (struct usb_interface *intf)
|
|
|
|
{
|
|
|
|
struct pegasus *pegasus = usb_get_intfdata(intf);
|
|
|
|
|
|
|
|
netif_device_attach (pegasus->net);
|
2005-04-19 08:39:22 +08:00
|
|
|
if (netif_running(pegasus->net)) {
|
|
|
|
pegasus->rx_urb->status = 0;
|
|
|
|
pegasus->rx_urb->actual_length = 0;
|
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 21:55:46 +08:00
|
|
|
read_bulk_callback(pegasus->rx_urb);
|
2005-04-19 08:39:22 +08:00
|
|
|
|
|
|
|
pegasus->intr_urb->status = 0;
|
|
|
|
pegasus->intr_urb->actual_length = 0;
|
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 21:55:46 +08:00
|
|
|
intr_callback(pegasus->intr_urb);
|
2005-04-19 08:39:22 +08:00
|
|
|
}
|
2006-05-02 05:02:45 +08:00
|
|
|
queue_delayed_work(pegasus_workqueue, &pegasus->carrier_check,
|
|
|
|
CARRIER_CHECK_DELAY);
|
2005-04-17 06:20:36 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-01-09 03:22:25 +08:00
|
|
|
static const struct net_device_ops pegasus_netdev_ops = {
|
|
|
|
.ndo_open = pegasus_open,
|
|
|
|
.ndo_stop = pegasus_close,
|
|
|
|
.ndo_do_ioctl = pegasus_ioctl,
|
|
|
|
.ndo_start_xmit = pegasus_start_xmit,
|
|
|
|
.ndo_set_multicast_list = pegasus_set_multicast,
|
|
|
|
.ndo_get_stats = pegasus_netdev_stats,
|
|
|
|
.ndo_tx_timeout = pegasus_tx_timeout,
|
2009-07-10 01:59:01 +08:00
|
|
|
.ndo_change_mtu = eth_change_mtu,
|
2009-07-10 01:54:35 +08:00
|
|
|
.ndo_set_mac_address = eth_mac_addr,
|
|
|
|
.ndo_validate_addr = eth_validate_addr,
|
2009-01-09 03:22:25 +08:00
|
|
|
};
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
static struct usb_driver pegasus_driver = {
|
|
|
|
.name = driver_name,
|
|
|
|
.probe = pegasus_probe,
|
|
|
|
.disconnect = pegasus_disconnect,
|
|
|
|
.id_table = pegasus_ids,
|
|
|
|
.suspend = pegasus_suspend,
|
|
|
|
.resume = pegasus_resume,
|
|
|
|
};
|
|
|
|
|
2008-11-16 16:36:08 +08:00
|
|
|
static void __init parse_id(char *id)
|
2005-11-15 15:55:18 +08:00
|
|
|
{
|
|
|
|
unsigned int vendor_id=0, device_id=0, flags=0, i=0;
|
|
|
|
char *token, *name=NULL;
|
|
|
|
|
|
|
|
if ((token = strsep(&id, ":")) != NULL)
|
|
|
|
name = token;
|
|
|
|
/* name now points to a null terminated string*/
|
|
|
|
if ((token = strsep(&id, ":")) != NULL)
|
|
|
|
vendor_id = simple_strtoul(token, NULL, 16);
|
|
|
|
if ((token = strsep(&id, ":")) != NULL)
|
|
|
|
device_id = simple_strtoul(token, NULL, 16);
|
|
|
|
flags = simple_strtoul(id, NULL, 16);
|
|
|
|
pr_info("%s: new device %s, vendor ID 0x%04x, device ID 0x%04x, flags: 0x%x\n",
|
|
|
|
driver_name, name, vendor_id, device_id, flags);
|
|
|
|
|
|
|
|
if (vendor_id > 0x10000 || vendor_id == 0)
|
|
|
|
return;
|
|
|
|
if (device_id > 0x10000 || device_id == 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
for (i=0; usb_dev_id[i].name; i++);
|
|
|
|
usb_dev_id[i].name = name;
|
|
|
|
usb_dev_id[i].vendor = vendor_id;
|
|
|
|
usb_dev_id[i].device = device_id;
|
|
|
|
usb_dev_id[i].private = flags;
|
|
|
|
pegasus_ids[i].match_flags = USB_DEVICE_ID_MATCH_DEVICE;
|
|
|
|
pegasus_ids[i].idVendor = vendor_id;
|
|
|
|
pegasus_ids[i].idProduct = device_id;
|
|
|
|
}
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
static int __init pegasus_init(void)
|
|
|
|
{
|
|
|
|
pr_info("%s: %s, " DRIVER_DESC "\n", driver_name, DRIVER_VERSION);
|
2005-11-15 15:55:18 +08:00
|
|
|
if (devid)
|
|
|
|
parse_id(devid);
|
2005-04-17 06:20:36 +08:00
|
|
|
return usb_register(&pegasus_driver);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void __exit pegasus_exit(void)
|
|
|
|
{
|
|
|
|
usb_deregister(&pegasus_driver);
|
|
|
|
}
|
|
|
|
|
|
|
|
module_init(pegasus_init);
|
|
|
|
module_exit(pegasus_exit);
|