2005-04-17 06:20:36 +08:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2001 Vojtech Pavlik
|
|
|
|
*
|
|
|
|
* CATC EL1210A NetMate USB Ethernet driver
|
|
|
|
*
|
|
|
|
* Sponsored by SuSE
|
|
|
|
*
|
|
|
|
* Based on the work of
|
|
|
|
* Donald Becker
|
|
|
|
*
|
|
|
|
* Old chipset support added by Simon Evans <spse@secret.org.uk> 2002
|
|
|
|
* - adds support for Belkin F5U011
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
2013-12-06 22:28:46 +08:00
|
|
|
* along with this program; if not, see <http://www.gnu.org/licenses/>.
|
2005-04-17 06:20:36 +08:00
|
|
|
*
|
|
|
|
* Should you need to contact me, the author, you can do so either by
|
|
|
|
* e-mail - mail your message to <vojtech@suse.cz>, or by paper mail:
|
|
|
|
* Vojtech Pavlik, Simunkova 1594, Prague 8, 182 00 Czech Republic
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/kernel.h>
|
|
|
|
#include <linux/string.h>
|
|
|
|
#include <linux/netdevice.h>
|
|
|
|
#include <linux/etherdevice.h>
|
|
|
|
#include <linux/skbuff.h>
|
|
|
|
#include <linux/spinlock.h>
|
|
|
|
#include <linux/ethtool.h>
|
|
|
|
#include <linux/crc32.h>
|
|
|
|
#include <linux/bitops.h>
|
include cleanup: Update gfp.h and slab.h includes to prepare for breaking implicit slab.h inclusion from percpu.h
percpu.h is included by sched.h and module.h and thus ends up being
included when building most .c files. percpu.h includes slab.h which
in turn includes gfp.h making everything defined by the two files
universally available and complicating inclusion dependencies.
percpu.h -> slab.h dependency is about to be removed. Prepare for
this change by updating users of gfp and slab facilities include those
headers directly instead of assuming availability. As this conversion
needs to touch large number of source files, the following script is
used as the basis of conversion.
http://userweb.kernel.org/~tj/misc/slabh-sweep.py
The script does the followings.
* Scan files for gfp and slab usages and update includes such that
only the necessary includes are there. ie. if only gfp is used,
gfp.h, if slab is used, slab.h.
* When the script inserts a new include, it looks at the include
blocks and try to put the new include such that its order conforms
to its surrounding. It's put in the include block which contains
core kernel includes, in the same order that the rest are ordered -
alphabetical, Christmas tree, rev-Xmas-tree or at the end if there
doesn't seem to be any matching order.
* If the script can't find a place to put a new include (mostly
because the file doesn't have fitting include block), it prints out
an error message indicating which .h file needs to be added to the
file.
The conversion was done in the following steps.
1. The initial automatic conversion of all .c files updated slightly
over 4000 files, deleting around 700 includes and adding ~480 gfp.h
and ~3000 slab.h inclusions. The script emitted errors for ~400
files.
2. Each error was manually checked. Some didn't need the inclusion,
some needed manual addition while adding it to implementation .h or
embedding .c file was more appropriate for others. This step added
inclusions to around 150 files.
3. The script was run again and the output was compared to the edits
from #2 to make sure no file was left behind.
4. Several build tests were done and a couple of problems were fixed.
e.g. lib/decompress_*.c used malloc/free() wrappers around slab
APIs requiring slab.h to be added manually.
5. The script was run on all .h files but without automatically
editing them as sprinkling gfp.h and slab.h inclusions around .h
files could easily lead to inclusion dependency hell. Most gfp.h
inclusion directives were ignored as stuff from gfp.h was usually
wildly available and often used in preprocessor macros. Each
slab.h inclusion directive was examined and added manually as
necessary.
6. percpu.h was updated not to include slab.h.
7. Build test were done on the following configurations and failures
were fixed. CONFIG_GCOV_KERNEL was turned off for all tests (as my
distributed build env didn't work with gcov compiles) and a few
more options had to be turned off depending on archs to make things
build (like ipr on powerpc/64 which failed due to missing writeq).
* x86 and x86_64 UP and SMP allmodconfig and a custom test config.
* powerpc and powerpc64 SMP allmodconfig
* sparc and sparc64 SMP allmodconfig
* ia64 SMP allmodconfig
* s390 SMP allmodconfig
* alpha SMP allmodconfig
* um on x86_64 SMP allmodconfig
8. percpu.h modifications were reverted so that it could be applied as
a separate patch and serve as bisection point.
Given the fact that I had only a couple of failures from tests on step
6, I'm fairly confident about the coverage of this conversion patch.
If there is a breakage, it's likely to be something in one of the arch
headers which should be easily discoverable easily on most builds of
the specific arch.
Signed-off-by: Tejun Heo <tj@kernel.org>
Guess-its-ok-by: Christoph Lameter <cl@linux-foundation.org>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Lee Schermerhorn <Lee.Schermerhorn@hp.com>
2010-03-24 16:04:11 +08:00
|
|
|
#include <linux/gfp.h>
|
2016-12-25 03:46:01 +08:00
|
|
|
#include <linux/uaccess.h>
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
#undef DEBUG
|
|
|
|
|
|
|
|
#include <linux/usb.h>
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Version information.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#define DRIVER_VERSION "v2.8"
|
|
|
|
#define DRIVER_AUTHOR "Vojtech Pavlik <vojtech@suse.cz>"
|
|
|
|
#define DRIVER_DESC "CATC EL1210A NetMate USB Ethernet driver"
|
|
|
|
#define SHORT_DRIVER_DESC "EL1210A NetMate USB Ethernet"
|
|
|
|
|
|
|
|
MODULE_AUTHOR(DRIVER_AUTHOR);
|
|
|
|
MODULE_DESCRIPTION(DRIVER_DESC);
|
|
|
|
MODULE_LICENSE("GPL");
|
|
|
|
|
|
|
|
static const char driver_name[] = "catc";
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Some defines.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#define STATS_UPDATE (HZ) /* Time between stats updates */
|
|
|
|
#define TX_TIMEOUT (5*HZ) /* Max time the queue can be stopped */
|
|
|
|
#define PKT_SZ 1536 /* Max Ethernet packet size */
|
|
|
|
#define RX_MAX_BURST 15 /* Max packets per rx buffer (> 0, < 16) */
|
|
|
|
#define TX_MAX_BURST 15 /* Max full sized packets per tx buffer (> 0) */
|
|
|
|
#define CTRL_QUEUE 16 /* Max control requests in flight (power of two) */
|
|
|
|
#define RX_PKT_SZ 1600 /* Max size of receive packet for F5U011 */
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Control requests.
|
|
|
|
*/
|
|
|
|
|
|
|
|
enum control_requests {
|
|
|
|
ReadMem = 0xf1,
|
|
|
|
GetMac = 0xf2,
|
|
|
|
Reset = 0xf4,
|
|
|
|
SetMac = 0xf5,
|
|
|
|
SetRxMode = 0xf5, /* F5U011 only */
|
|
|
|
WriteROM = 0xf8,
|
|
|
|
SetReg = 0xfa,
|
|
|
|
GetReg = 0xfb,
|
|
|
|
WriteMem = 0xfc,
|
|
|
|
ReadROM = 0xfd,
|
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Registers.
|
|
|
|
*/
|
|
|
|
|
|
|
|
enum register_offsets {
|
|
|
|
TxBufCount = 0x20,
|
|
|
|
RxBufCount = 0x21,
|
|
|
|
OpModes = 0x22,
|
|
|
|
TxQed = 0x23,
|
|
|
|
RxQed = 0x24,
|
|
|
|
MaxBurst = 0x25,
|
|
|
|
RxUnit = 0x60,
|
|
|
|
EthStatus = 0x61,
|
|
|
|
StationAddr0 = 0x67,
|
|
|
|
EthStats = 0x69,
|
|
|
|
LEDCtrl = 0x81,
|
|
|
|
};
|
|
|
|
|
|
|
|
enum eth_stats {
|
|
|
|
TxSingleColl = 0x00,
|
|
|
|
TxMultiColl = 0x02,
|
|
|
|
TxExcessColl = 0x04,
|
|
|
|
RxFramErr = 0x06,
|
|
|
|
};
|
|
|
|
|
|
|
|
enum op_mode_bits {
|
|
|
|
Op3MemWaits = 0x03,
|
|
|
|
OpLenInclude = 0x08,
|
|
|
|
OpRxMerge = 0x10,
|
|
|
|
OpTxMerge = 0x20,
|
|
|
|
OpWin95bugfix = 0x40,
|
|
|
|
OpLoopback = 0x80,
|
|
|
|
};
|
|
|
|
|
|
|
|
enum rx_filter_bits {
|
|
|
|
RxEnable = 0x01,
|
|
|
|
RxPolarity = 0x02,
|
|
|
|
RxForceOK = 0x04,
|
|
|
|
RxMultiCast = 0x08,
|
|
|
|
RxPromisc = 0x10,
|
|
|
|
AltRxPromisc = 0x20, /* F5U011 uses different bit */
|
|
|
|
};
|
|
|
|
|
|
|
|
enum led_values {
|
|
|
|
LEDFast = 0x01,
|
|
|
|
LEDSlow = 0x02,
|
|
|
|
LEDFlash = 0x03,
|
|
|
|
LEDPulse = 0x04,
|
|
|
|
LEDLink = 0x08,
|
|
|
|
};
|
|
|
|
|
|
|
|
enum link_status {
|
|
|
|
LinkNoChange = 0,
|
|
|
|
LinkGood = 1,
|
|
|
|
LinkBad = 2
|
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
* The catc struct.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#define CTRL_RUNNING 0
|
|
|
|
#define RX_RUNNING 1
|
|
|
|
#define TX_RUNNING 2
|
|
|
|
|
|
|
|
struct catc {
|
|
|
|
struct net_device *netdev;
|
|
|
|
struct usb_device *usbdev;
|
|
|
|
|
|
|
|
unsigned long flags;
|
|
|
|
|
|
|
|
unsigned int tx_ptr, tx_idx;
|
|
|
|
unsigned int ctrl_head, ctrl_tail;
|
|
|
|
spinlock_t tx_lock, ctrl_lock;
|
|
|
|
|
|
|
|
u8 tx_buf[2][TX_MAX_BURST * (PKT_SZ + 2)];
|
|
|
|
u8 rx_buf[RX_MAX_BURST * (PKT_SZ + 2)];
|
|
|
|
u8 irq_buf[2];
|
|
|
|
u8 ctrl_buf[64];
|
|
|
|
struct usb_ctrlrequest ctrl_dr;
|
|
|
|
|
|
|
|
struct timer_list timer;
|
|
|
|
u8 stats_buf[8];
|
|
|
|
u16 stats_vals[4];
|
|
|
|
unsigned long last_stats;
|
|
|
|
|
|
|
|
u8 multicast[64];
|
|
|
|
|
|
|
|
struct ctrl_queue {
|
|
|
|
u8 dir;
|
|
|
|
u8 request;
|
|
|
|
u16 value;
|
|
|
|
u16 index;
|
|
|
|
void *buf;
|
|
|
|
int len;
|
|
|
|
void (*callback)(struct catc *catc, struct ctrl_queue *q);
|
|
|
|
} ctrl_queue[CTRL_QUEUE];
|
|
|
|
|
|
|
|
struct urb *tx_urb, *rx_urb, *irq_urb, *ctrl_urb;
|
|
|
|
|
|
|
|
u8 is_f5u011; /* Set if device is an F5U011 */
|
|
|
|
u8 rxmode[2]; /* Used for F5U011 */
|
|
|
|
atomic_t recq_sz; /* Used for F5U011 - counter of waiting rx packets */
|
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Useful macros.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#define catc_get_mac(catc, mac) catc_ctrl_msg(catc, USB_DIR_IN, GetMac, 0, 0, mac, 6)
|
|
|
|
#define catc_reset(catc) catc_ctrl_msg(catc, USB_DIR_OUT, Reset, 0, 0, NULL, 0)
|
|
|
|
#define catc_set_reg(catc, reg, val) catc_ctrl_msg(catc, USB_DIR_OUT, SetReg, val, reg, NULL, 0)
|
|
|
|
#define catc_get_reg(catc, reg, buf) catc_ctrl_msg(catc, USB_DIR_IN, GetReg, 0, reg, buf, 1)
|
|
|
|
#define catc_write_mem(catc, addr, buf, size) catc_ctrl_msg(catc, USB_DIR_OUT, WriteMem, 0, addr, buf, size)
|
|
|
|
#define catc_read_mem(catc, addr, buf, size) catc_ctrl_msg(catc, USB_DIR_IN, ReadMem, 0, addr, buf, size)
|
|
|
|
|
|
|
|
#define f5u011_rxmode(catc, rxmode) catc_ctrl_msg(catc, USB_DIR_OUT, SetRxMode, 0, 1, rxmode, 2)
|
|
|
|
#define f5u011_rxmode_async(catc, rxmode) catc_ctrl_async(catc, USB_DIR_OUT, SetRxMode, 0, 1, &rxmode, 2, NULL)
|
|
|
|
#define f5u011_mchash_async(catc, hash) catc_ctrl_async(catc, USB_DIR_OUT, SetRxMode, 0, 2, &hash, 8, NULL)
|
|
|
|
|
|
|
|
#define catc_set_reg_async(catc, reg, val) catc_ctrl_async(catc, USB_DIR_OUT, SetReg, val, reg, NULL, 0, NULL)
|
|
|
|
#define catc_get_reg_async(catc, reg, cb) catc_ctrl_async(catc, USB_DIR_IN, GetReg, 0, reg, NULL, 1, cb)
|
|
|
|
#define catc_write_mem_async(catc, addr, buf, size) catc_ctrl_async(catc, USB_DIR_OUT, WriteMem, 0, addr, buf, size, NULL)
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Receive routines.
|
|
|
|
*/
|
|
|
|
|
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 catc_rx_done(struct urb *urb)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
struct catc *catc = urb->context;
|
|
|
|
u8 *pkt_start = urb->transfer_buffer;
|
|
|
|
struct sk_buff *skb;
|
|
|
|
int pkt_len, pkt_offset = 0;
|
2008-12-19 15:00:59 +08:00
|
|
|
int status = urb->status;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
if (!catc->is_f5u011) {
|
|
|
|
clear_bit(RX_RUNNING, &catc->flags);
|
|
|
|
pkt_offset = 2;
|
|
|
|
}
|
|
|
|
|
2008-12-19 15:00:59 +08:00
|
|
|
if (status) {
|
2012-09-19 17:46:14 +08:00
|
|
|
dev_dbg(&urb->dev->dev, "rx_done, status %d, length %d\n",
|
|
|
|
status, urb->actual_length);
|
2005-04-17 06:20:36 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
do {
|
|
|
|
if(!catc->is_f5u011) {
|
|
|
|
pkt_len = le16_to_cpup((__le16*)pkt_start);
|
|
|
|
if (pkt_len > urb->actual_length) {
|
2009-03-21 03:35:48 +08:00
|
|
|
catc->netdev->stats.rx_length_errors++;
|
|
|
|
catc->netdev->stats.rx_errors++;
|
2005-04-17 06:20:36 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
pkt_len = urb->actual_length;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!(skb = dev_alloc_skb(pkt_len)))
|
|
|
|
return;
|
|
|
|
|
2007-07-11 13:08:12 +08:00
|
|
|
skb_copy_to_linear_data(skb, pkt_start + pkt_offset, pkt_len);
|
2005-04-17 06:20:36 +08:00
|
|
|
skb_put(skb, pkt_len);
|
|
|
|
|
|
|
|
skb->protocol = eth_type_trans(skb, catc->netdev);
|
|
|
|
netif_rx(skb);
|
|
|
|
|
2009-03-21 03:35:48 +08:00
|
|
|
catc->netdev->stats.rx_packets++;
|
|
|
|
catc->netdev->stats.rx_bytes += pkt_len;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
/* F5U011 only does one packet per RX */
|
|
|
|
if (catc->is_f5u011)
|
|
|
|
break;
|
|
|
|
pkt_start += (((pkt_len + 1) >> 6) + 1) << 6;
|
|
|
|
|
|
|
|
} while (pkt_start - (u8 *) urb->transfer_buffer < urb->actual_length);
|
|
|
|
|
|
|
|
if (catc->is_f5u011) {
|
|
|
|
if (atomic_read(&catc->recq_sz)) {
|
2008-12-19 15:00:59 +08:00
|
|
|
int state;
|
2005-04-17 06:20:36 +08:00
|
|
|
atomic_dec(&catc->recq_sz);
|
2012-09-19 17:46:14 +08:00
|
|
|
netdev_dbg(catc->netdev, "getting extra packet\n");
|
2005-04-17 06:20:36 +08:00
|
|
|
urb->dev = catc->usbdev;
|
2008-12-19 15:00:59 +08:00
|
|
|
if ((state = usb_submit_urb(urb, GFP_ATOMIC)) < 0) {
|
2012-09-19 17:46:14 +08:00
|
|
|
netdev_dbg(catc->netdev,
|
|
|
|
"submit(rx_urb) status %d\n", state);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
clear_bit(RX_RUNNING, &catc->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 catc_irq_done(struct urb *urb)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
struct catc *catc = urb->context;
|
|
|
|
u8 *data = urb->transfer_buffer;
|
2008-12-19 15:00:59 +08:00
|
|
|
int status = urb->status;
|
2005-04-17 06:20:36 +08:00
|
|
|
unsigned int hasdata = 0, linksts = LinkNoChange;
|
2008-12-19 15:00:59 +08:00
|
|
|
int res;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
if (!catc->is_f5u011) {
|
|
|
|
hasdata = data[1] & 0x80;
|
|
|
|
if (data[1] & 0x40)
|
|
|
|
linksts = LinkGood;
|
|
|
|
else if (data[1] & 0x20)
|
|
|
|
linksts = LinkBad;
|
|
|
|
} else {
|
|
|
|
hasdata = (unsigned int)(be16_to_cpup((__be16*)data) & 0x0fff);
|
|
|
|
if (data[0] == 0x90)
|
|
|
|
linksts = LinkGood;
|
|
|
|
else if (data[0] == 0xA0)
|
|
|
|
linksts = LinkBad;
|
|
|
|
}
|
|
|
|
|
2008-12-19 15:00:59 +08:00
|
|
|
switch (status) {
|
2005-04-17 06:20:36 +08:00
|
|
|
case 0: /* success */
|
|
|
|
break;
|
|
|
|
case -ECONNRESET: /* unlink */
|
|
|
|
case -ENOENT:
|
|
|
|
case -ESHUTDOWN:
|
|
|
|
return;
|
|
|
|
/* -EPIPE: should clear the halt */
|
|
|
|
default: /* error */
|
2012-09-19 17:46:14 +08:00
|
|
|
dev_dbg(&urb->dev->dev,
|
|
|
|
"irq_done, status %d, data %02x %02x.\n",
|
|
|
|
status, data[0], data[1]);
|
2005-04-17 06:20:36 +08:00
|
|
|
goto resubmit;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (linksts == LinkGood) {
|
|
|
|
netif_carrier_on(catc->netdev);
|
2012-09-19 17:46:14 +08:00
|
|
|
netdev_dbg(catc->netdev, "link ok\n");
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (linksts == LinkBad) {
|
|
|
|
netif_carrier_off(catc->netdev);
|
2012-09-19 17:46:14 +08:00
|
|
|
netdev_dbg(catc->netdev, "link bad\n");
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (hasdata) {
|
|
|
|
if (test_and_set_bit(RX_RUNNING, &catc->flags)) {
|
|
|
|
if (catc->is_f5u011)
|
|
|
|
atomic_inc(&catc->recq_sz);
|
|
|
|
} else {
|
|
|
|
catc->rx_urb->dev = catc->usbdev;
|
2008-12-19 15:00:59 +08:00
|
|
|
if ((res = usb_submit_urb(catc->rx_urb, GFP_ATOMIC)) < 0) {
|
2012-04-26 03:37:47 +08:00
|
|
|
dev_err(&catc->usbdev->dev,
|
|
|
|
"submit(rx_urb) status %d\n", res);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
resubmit:
|
2008-12-19 15:00:59 +08:00
|
|
|
res = usb_submit_urb (urb, GFP_ATOMIC);
|
|
|
|
if (res)
|
2012-04-26 03:37:47 +08:00
|
|
|
dev_err(&catc->usbdev->dev,
|
|
|
|
"can't resubmit intr, %s-%s, status %d\n",
|
|
|
|
catc->usbdev->bus->bus_name,
|
|
|
|
catc->usbdev->devpath, res);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Transmit routines.
|
|
|
|
*/
|
|
|
|
|
2007-03-30 19:11:00 +08:00
|
|
|
static int catc_tx_run(struct catc *catc)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
int status;
|
|
|
|
|
|
|
|
if (catc->is_f5u011)
|
|
|
|
catc->tx_ptr = (catc->tx_ptr + 63) & ~63;
|
|
|
|
|
|
|
|
catc->tx_urb->transfer_buffer_length = catc->tx_ptr;
|
|
|
|
catc->tx_urb->transfer_buffer = catc->tx_buf[catc->tx_idx];
|
|
|
|
catc->tx_urb->dev = catc->usbdev;
|
|
|
|
|
|
|
|
if ((status = usb_submit_urb(catc->tx_urb, GFP_ATOMIC)) < 0)
|
2012-04-26 03:37:47 +08:00
|
|
|
dev_err(&catc->usbdev->dev, "submit(tx_urb), status %d\n",
|
|
|
|
status);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
catc->tx_idx = !catc->tx_idx;
|
|
|
|
catc->tx_ptr = 0;
|
|
|
|
|
2016-05-03 22:33:13 +08:00
|
|
|
netif_trans_update(catc->netdev);
|
2007-03-30 19:11:00 +08:00
|
|
|
return status;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
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 catc_tx_done(struct urb *urb)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
struct catc *catc = urb->context;
|
|
|
|
unsigned long flags;
|
2008-12-19 15:00:59 +08:00
|
|
|
int r, status = urb->status;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2008-12-19 15:00:59 +08:00
|
|
|
if (status == -ECONNRESET) {
|
2012-09-19 17:46:14 +08:00
|
|
|
dev_dbg(&urb->dev->dev, "Tx Reset.\n");
|
2005-04-17 06:20:36 +08:00
|
|
|
urb->status = 0;
|
2016-05-03 22:33:13 +08:00
|
|
|
netif_trans_update(catc->netdev);
|
2009-03-21 03:35:48 +08:00
|
|
|
catc->netdev->stats.tx_errors++;
|
2005-04-17 06:20:36 +08:00
|
|
|
clear_bit(TX_RUNNING, &catc->flags);
|
|
|
|
netif_wake_queue(catc->netdev);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2008-12-19 15:00:59 +08:00
|
|
|
if (status) {
|
2012-09-19 17:46:14 +08:00
|
|
|
dev_dbg(&urb->dev->dev, "tx_done, status %d, length %d\n",
|
|
|
|
status, urb->actual_length);
|
2005-04-17 06:20:36 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
spin_lock_irqsave(&catc->tx_lock, flags);
|
|
|
|
|
2007-03-30 19:11:00 +08:00
|
|
|
if (catc->tx_ptr) {
|
|
|
|
r = catc_tx_run(catc);
|
|
|
|
if (unlikely(r < 0))
|
|
|
|
clear_bit(TX_RUNNING, &catc->flags);
|
|
|
|
} else {
|
2005-04-17 06:20:36 +08:00
|
|
|
clear_bit(TX_RUNNING, &catc->flags);
|
2007-03-30 19:11:00 +08:00
|
|
|
}
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
netif_wake_queue(catc->netdev);
|
|
|
|
|
|
|
|
spin_unlock_irqrestore(&catc->tx_lock, flags);
|
|
|
|
}
|
|
|
|
|
2009-09-01 03:50:45 +08:00
|
|
|
static netdev_tx_t catc_start_xmit(struct sk_buff *skb,
|
|
|
|
struct net_device *netdev)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
struct catc *catc = netdev_priv(netdev);
|
|
|
|
unsigned long flags;
|
2007-03-30 19:11:00 +08:00
|
|
|
int r = 0;
|
2005-04-17 06:20:36 +08:00
|
|
|
char *tx_buf;
|
|
|
|
|
|
|
|
spin_lock_irqsave(&catc->tx_lock, flags);
|
|
|
|
|
|
|
|
catc->tx_ptr = (((catc->tx_ptr - 1) >> 6) + 1) << 6;
|
|
|
|
tx_buf = catc->tx_buf[catc->tx_idx] + catc->tx_ptr;
|
2008-05-21 13:32:11 +08:00
|
|
|
if (catc->is_f5u011)
|
|
|
|
*(__be16 *)tx_buf = cpu_to_be16(skb->len);
|
|
|
|
else
|
|
|
|
*(__le16 *)tx_buf = cpu_to_le16(skb->len);
|
2007-03-28 05:55:52 +08:00
|
|
|
skb_copy_from_linear_data(skb, tx_buf + 2, skb->len);
|
2005-04-17 06:20:36 +08:00
|
|
|
catc->tx_ptr += skb->len + 2;
|
|
|
|
|
2007-03-30 19:11:00 +08:00
|
|
|
if (!test_and_set_bit(TX_RUNNING, &catc->flags)) {
|
|
|
|
r = catc_tx_run(catc);
|
|
|
|
if (r < 0)
|
|
|
|
clear_bit(TX_RUNNING, &catc->flags);
|
|
|
|
}
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2009-12-03 15:58:21 +08:00
|
|
|
if ((catc->is_f5u011 && catc->tx_ptr) ||
|
|
|
|
(catc->tx_ptr >= ((TX_MAX_BURST - 1) * (PKT_SZ + 2))))
|
2005-04-17 06:20:36 +08:00
|
|
|
netif_stop_queue(netdev);
|
|
|
|
|
|
|
|
spin_unlock_irqrestore(&catc->tx_lock, flags);
|
|
|
|
|
2007-03-30 19:11:00 +08:00
|
|
|
if (r >= 0) {
|
2009-03-21 03:35:48 +08:00
|
|
|
catc->netdev->stats.tx_bytes += skb->len;
|
|
|
|
catc->netdev->stats.tx_packets++;
|
2007-03-30 19:11:00 +08:00
|
|
|
}
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
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 void catc_tx_timeout(struct net_device *netdev)
|
|
|
|
{
|
|
|
|
struct catc *catc = netdev_priv(netdev);
|
|
|
|
|
2008-08-15 00:37:34 +08:00
|
|
|
dev_warn(&netdev->dev, "Transmit timed out.\n");
|
2005-04-17 06:20:36 +08:00
|
|
|
usb_unlink_urb(catc->tx_urb);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Control messages.
|
|
|
|
*/
|
|
|
|
|
|
|
|
static int catc_ctrl_msg(struct catc *catc, u8 dir, u8 request, u16 value, u16 index, void *buf, int len)
|
|
|
|
{
|
|
|
|
int retval = usb_control_msg(catc->usbdev,
|
|
|
|
dir ? usb_rcvctrlpipe(catc->usbdev, 0) : usb_sndctrlpipe(catc->usbdev, 0),
|
|
|
|
request, 0x40 | dir, value, index, buf, len, 1000);
|
|
|
|
return retval < 0 ? retval : 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void catc_ctrl_run(struct catc *catc)
|
|
|
|
{
|
|
|
|
struct ctrl_queue *q = catc->ctrl_queue + catc->ctrl_tail;
|
|
|
|
struct usb_device *usbdev = catc->usbdev;
|
|
|
|
struct urb *urb = catc->ctrl_urb;
|
|
|
|
struct usb_ctrlrequest *dr = &catc->ctrl_dr;
|
|
|
|
int status;
|
|
|
|
|
|
|
|
dr->bRequest = q->request;
|
|
|
|
dr->bRequestType = 0x40 | q->dir;
|
|
|
|
dr->wValue = cpu_to_le16(q->value);
|
|
|
|
dr->wIndex = cpu_to_le16(q->index);
|
|
|
|
dr->wLength = cpu_to_le16(q->len);
|
|
|
|
|
|
|
|
urb->pipe = q->dir ? usb_rcvctrlpipe(usbdev, 0) : usb_sndctrlpipe(usbdev, 0);
|
|
|
|
urb->transfer_buffer_length = q->len;
|
|
|
|
urb->transfer_buffer = catc->ctrl_buf;
|
|
|
|
urb->setup_packet = (void *) dr;
|
|
|
|
urb->dev = usbdev;
|
|
|
|
|
|
|
|
if (!q->dir && q->buf && q->len)
|
|
|
|
memcpy(catc->ctrl_buf, q->buf, q->len);
|
|
|
|
|
2011-05-30 15:06:24 +08:00
|
|
|
if ((status = usb_submit_urb(catc->ctrl_urb, GFP_ATOMIC)))
|
2012-04-26 03:37:47 +08:00
|
|
|
dev_err(&catc->usbdev->dev, "submit(ctrl_urb) status %d\n",
|
|
|
|
status);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
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 catc_ctrl_done(struct urb *urb)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
struct catc *catc = urb->context;
|
|
|
|
struct ctrl_queue *q;
|
|
|
|
unsigned long flags;
|
2008-12-19 15:00:59 +08:00
|
|
|
int status = urb->status;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2008-12-19 15:00:59 +08:00
|
|
|
if (status)
|
2012-09-19 17:46:14 +08:00
|
|
|
dev_dbg(&urb->dev->dev, "ctrl_done, status %d, len %d.\n",
|
|
|
|
status, urb->actual_length);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
spin_lock_irqsave(&catc->ctrl_lock, flags);
|
|
|
|
|
|
|
|
q = catc->ctrl_queue + catc->ctrl_tail;
|
|
|
|
|
|
|
|
if (q->dir) {
|
|
|
|
if (q->buf && q->len)
|
|
|
|
memcpy(q->buf, catc->ctrl_buf, q->len);
|
|
|
|
else
|
|
|
|
q->buf = catc->ctrl_buf;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (q->callback)
|
|
|
|
q->callback(catc, q);
|
|
|
|
|
|
|
|
catc->ctrl_tail = (catc->ctrl_tail + 1) & (CTRL_QUEUE - 1);
|
|
|
|
|
|
|
|
if (catc->ctrl_head != catc->ctrl_tail)
|
|
|
|
catc_ctrl_run(catc);
|
|
|
|
else
|
|
|
|
clear_bit(CTRL_RUNNING, &catc->flags);
|
|
|
|
|
|
|
|
spin_unlock_irqrestore(&catc->ctrl_lock, flags);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int catc_ctrl_async(struct catc *catc, u8 dir, u8 request, u16 value,
|
|
|
|
u16 index, void *buf, int len, void (*callback)(struct catc *catc, struct ctrl_queue *q))
|
|
|
|
{
|
|
|
|
struct ctrl_queue *q;
|
|
|
|
int retval = 0;
|
|
|
|
unsigned long flags;
|
|
|
|
|
|
|
|
spin_lock_irqsave(&catc->ctrl_lock, flags);
|
|
|
|
|
|
|
|
q = catc->ctrl_queue + catc->ctrl_head;
|
|
|
|
|
|
|
|
q->dir = dir;
|
|
|
|
q->request = request;
|
|
|
|
q->value = value;
|
|
|
|
q->index = index;
|
|
|
|
q->buf = buf;
|
|
|
|
q->len = len;
|
|
|
|
q->callback = callback;
|
|
|
|
|
|
|
|
catc->ctrl_head = (catc->ctrl_head + 1) & (CTRL_QUEUE - 1);
|
|
|
|
|
|
|
|
if (catc->ctrl_head == catc->ctrl_tail) {
|
2012-04-26 03:37:47 +08:00
|
|
|
dev_err(&catc->usbdev->dev, "ctrl queue full\n");
|
2005-04-17 06:20:36 +08:00
|
|
|
catc->ctrl_tail = (catc->ctrl_tail + 1) & (CTRL_QUEUE - 1);
|
|
|
|
retval = -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!test_and_set_bit(CTRL_RUNNING, &catc->flags))
|
|
|
|
catc_ctrl_run(catc);
|
|
|
|
|
|
|
|
spin_unlock_irqrestore(&catc->ctrl_lock, flags);
|
|
|
|
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Statistics.
|
|
|
|
*/
|
|
|
|
|
|
|
|
static void catc_stats_done(struct catc *catc, struct ctrl_queue *q)
|
|
|
|
{
|
|
|
|
int index = q->index - EthStats;
|
|
|
|
u16 data, last;
|
|
|
|
|
|
|
|
catc->stats_buf[index] = *((char *)q->buf);
|
|
|
|
|
|
|
|
if (index & 1)
|
|
|
|
return;
|
|
|
|
|
|
|
|
data = ((u16)catc->stats_buf[index] << 8) | catc->stats_buf[index + 1];
|
|
|
|
last = catc->stats_vals[index >> 1];
|
|
|
|
|
|
|
|
switch (index) {
|
|
|
|
case TxSingleColl:
|
|
|
|
case TxMultiColl:
|
2009-03-21 03:35:48 +08:00
|
|
|
catc->netdev->stats.collisions += data - last;
|
2005-04-17 06:20:36 +08:00
|
|
|
break;
|
|
|
|
case TxExcessColl:
|
2009-03-21 03:35:48 +08:00
|
|
|
catc->netdev->stats.tx_aborted_errors += data - last;
|
|
|
|
catc->netdev->stats.tx_errors += data - last;
|
2005-04-17 06:20:36 +08:00
|
|
|
break;
|
|
|
|
case RxFramErr:
|
2009-03-21 03:35:48 +08:00
|
|
|
catc->netdev->stats.rx_frame_errors += data - last;
|
|
|
|
catc->netdev->stats.rx_errors += data - last;
|
2005-04-17 06:20:36 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
catc->stats_vals[index >> 1] = data;
|
|
|
|
}
|
|
|
|
|
2017-10-17 08:29:32 +08:00
|
|
|
static void catc_stats_timer(struct timer_list *t)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2017-10-17 08:29:32 +08:00
|
|
|
struct catc *catc = from_timer(catc, t, timer);
|
2005-04-17 06:20:36 +08:00
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < 8; i++)
|
|
|
|
catc_get_reg_async(catc, EthStats + 7 - i, catc_stats_done);
|
|
|
|
|
|
|
|
mod_timer(&catc->timer, jiffies + STATS_UPDATE);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Receive modes. Broadcast, Multicast, Promisc.
|
|
|
|
*/
|
|
|
|
|
|
|
|
static void catc_multicast(unsigned char *addr, u8 *multicast)
|
|
|
|
{
|
|
|
|
u32 crc;
|
|
|
|
|
|
|
|
crc = ether_crc_le(6, addr);
|
|
|
|
multicast[(crc >> 3) & 0x3f] |= 1 << (crc & 7);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void catc_set_multicast_list(struct net_device *netdev)
|
|
|
|
{
|
|
|
|
struct catc *catc = netdev_priv(netdev);
|
2010-04-02 05:22:57 +08:00
|
|
|
struct netdev_hw_addr *ha;
|
2013-10-02 10:04:40 +08:00
|
|
|
u8 broadcast[ETH_ALEN];
|
2005-04-17 06:20:36 +08:00
|
|
|
u8 rx = RxEnable | RxPolarity | RxMultiCast;
|
|
|
|
|
2015-03-03 11:54:48 +08:00
|
|
|
eth_broadcast_addr(broadcast);
|
2005-04-17 06:20:36 +08:00
|
|
|
memset(catc->multicast, 0, 64);
|
|
|
|
|
|
|
|
catc_multicast(broadcast, catc->multicast);
|
|
|
|
catc_multicast(netdev->dev_addr, catc->multicast);
|
|
|
|
|
|
|
|
if (netdev->flags & IFF_PROMISC) {
|
|
|
|
memset(catc->multicast, 0xff, 64);
|
|
|
|
rx |= (!catc->is_f5u011) ? RxPromisc : AltRxPromisc;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (netdev->flags & IFF_ALLMULTI) {
|
|
|
|
memset(catc->multicast, 0xff, 64);
|
|
|
|
} else {
|
2010-04-02 05:22:57 +08:00
|
|
|
netdev_for_each_mc_addr(ha, netdev) {
|
|
|
|
u32 crc = ether_crc_le(6, ha->addr);
|
2005-04-17 06:20:36 +08:00
|
|
|
if (!catc->is_f5u011) {
|
|
|
|
catc->multicast[(crc >> 3) & 0x3f] |= 1 << (crc & 7);
|
|
|
|
} else {
|
|
|
|
catc->multicast[7-(crc >> 29)] |= 1 << ((crc >> 26) & 7);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!catc->is_f5u011) {
|
|
|
|
catc_set_reg_async(catc, RxUnit, rx);
|
|
|
|
catc_write_mem_async(catc, 0xfa80, catc->multicast, 64);
|
|
|
|
} else {
|
|
|
|
f5u011_mchash_async(catc, catc->multicast);
|
|
|
|
if (catc->rxmode[0] != rx) {
|
|
|
|
catc->rxmode[0] = rx;
|
2012-09-19 17:46:14 +08:00
|
|
|
netdev_dbg(catc->netdev,
|
|
|
|
"Setting RX mode to %2.2X %2.2X\n",
|
|
|
|
catc->rxmode[0], catc->rxmode[1]);
|
2005-04-17 06:20:36 +08:00
|
|
|
f5u011_rxmode_async(catc, catc->rxmode);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void catc_get_drvinfo(struct net_device *dev,
|
|
|
|
struct ethtool_drvinfo *info)
|
|
|
|
{
|
|
|
|
struct catc *catc = netdev_priv(dev);
|
2013-01-06 08:44:26 +08:00
|
|
|
strlcpy(info->driver, driver_name, sizeof(info->driver));
|
|
|
|
strlcpy(info->version, DRIVER_VERSION, sizeof(info->version));
|
|
|
|
usb_make_path(catc->usbdev, info->bus_info, sizeof(info->bus_info));
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
2017-03-13 05:08:26 +08:00
|
|
|
static int catc_get_link_ksettings(struct net_device *dev,
|
|
|
|
struct ethtool_link_ksettings *cmd)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
struct catc *catc = netdev_priv(dev);
|
|
|
|
if (!catc->is_f5u011)
|
|
|
|
return -EOPNOTSUPP;
|
|
|
|
|
2017-03-13 05:08:26 +08:00
|
|
|
ethtool_link_ksettings_zero_link_mode(cmd, supported);
|
|
|
|
ethtool_link_ksettings_add_link_mode(cmd, supported, 10baseT_Half);
|
|
|
|
ethtool_link_ksettings_add_link_mode(cmd, supported, TP);
|
|
|
|
|
|
|
|
ethtool_link_ksettings_zero_link_mode(cmd, advertising);
|
|
|
|
ethtool_link_ksettings_add_link_mode(cmd, advertising, 10baseT_Half);
|
|
|
|
ethtool_link_ksettings_add_link_mode(cmd, advertising, TP);
|
|
|
|
|
|
|
|
cmd->base.speed = SPEED_10;
|
|
|
|
cmd->base.duplex = DUPLEX_HALF;
|
|
|
|
cmd->base.port = PORT_TP;
|
|
|
|
cmd->base.phy_address = 0;
|
|
|
|
cmd->base.autoneg = AUTONEG_DISABLE;
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-09-02 16:03:33 +08:00
|
|
|
static const struct ethtool_ops ops = {
|
2005-04-17 06:20:36 +08:00
|
|
|
.get_drvinfo = catc_get_drvinfo,
|
2017-03-13 05:08:26 +08:00
|
|
|
.get_link = ethtool_op_get_link,
|
|
|
|
.get_link_ksettings = catc_get_link_ksettings,
|
2005-04-17 06:20:36 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Open, close.
|
|
|
|
*/
|
|
|
|
|
|
|
|
static int catc_open(struct net_device *netdev)
|
|
|
|
{
|
|
|
|
struct catc *catc = netdev_priv(netdev);
|
|
|
|
int status;
|
|
|
|
|
|
|
|
catc->irq_urb->dev = catc->usbdev;
|
|
|
|
if ((status = usb_submit_urb(catc->irq_urb, GFP_KERNEL)) < 0) {
|
2012-04-26 03:37:47 +08:00
|
|
|
dev_err(&catc->usbdev->dev, "submit(irq_urb) status %d\n",
|
|
|
|
status);
|
2005-04-17 06:20:36 +08:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
netif_start_queue(netdev);
|
|
|
|
|
|
|
|
if (!catc->is_f5u011)
|
|
|
|
mod_timer(&catc->timer, jiffies + STATS_UPDATE);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int catc_stop(struct net_device *netdev)
|
|
|
|
{
|
|
|
|
struct catc *catc = netdev_priv(netdev);
|
|
|
|
|
|
|
|
netif_stop_queue(netdev);
|
|
|
|
|
|
|
|
if (!catc->is_f5u011)
|
|
|
|
del_timer_sync(&catc->timer);
|
|
|
|
|
|
|
|
usb_kill_urb(catc->rx_urb);
|
|
|
|
usb_kill_urb(catc->tx_urb);
|
|
|
|
usb_kill_urb(catc->irq_urb);
|
|
|
|
usb_kill_urb(catc->ctrl_urb);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-03-21 03:35:49 +08:00
|
|
|
static const struct net_device_ops catc_netdev_ops = {
|
|
|
|
.ndo_open = catc_open,
|
|
|
|
.ndo_stop = catc_stop,
|
|
|
|
.ndo_start_xmit = catc_start_xmit,
|
|
|
|
|
|
|
|
.ndo_tx_timeout = catc_tx_timeout,
|
2011-08-16 14:29:01 +08:00
|
|
|
.ndo_set_rx_mode = catc_set_multicast_list,
|
2009-03-21 03:35:49 +08:00
|
|
|
.ndo_set_mac_address = eth_mac_addr,
|
|
|
|
.ndo_validate_addr = eth_validate_addr,
|
|
|
|
};
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
/*
|
|
|
|
* USB probe, disconnect.
|
|
|
|
*/
|
|
|
|
|
|
|
|
static int catc_probe(struct usb_interface *intf, const struct usb_device_id *id)
|
|
|
|
{
|
2012-09-19 17:46:14 +08:00
|
|
|
struct device *dev = &intf->dev;
|
2005-04-17 06:20:36 +08:00
|
|
|
struct usb_device *usbdev = interface_to_usbdev(intf);
|
|
|
|
struct net_device *netdev;
|
|
|
|
struct catc *catc;
|
2013-10-02 10:04:40 +08:00
|
|
|
u8 broadcast[ETH_ALEN];
|
2017-02-05 00:57:04 +08:00
|
|
|
int pktsz, ret;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
if (usb_set_interface(usbdev,
|
|
|
|
intf->altsetting->desc.bInterfaceNumber, 1)) {
|
2012-09-19 17:46:14 +08:00
|
|
|
dev_err(dev, "Can't set altsetting 1.\n");
|
2005-04-17 06:20:36 +08:00
|
|
|
return -EIO;
|
|
|
|
}
|
|
|
|
|
|
|
|
netdev = alloc_etherdev(sizeof(struct catc));
|
|
|
|
if (!netdev)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
catc = netdev_priv(netdev);
|
|
|
|
|
2009-03-21 03:35:49 +08:00
|
|
|
netdev->netdev_ops = &catc_netdev_ops;
|
2005-04-17 06:20:36 +08:00
|
|
|
netdev->watchdog_timeo = TX_TIMEOUT;
|
2014-05-11 08:12:32 +08:00
|
|
|
netdev->ethtool_ops = &ops;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
catc->usbdev = usbdev;
|
|
|
|
catc->netdev = netdev;
|
|
|
|
|
|
|
|
spin_lock_init(&catc->tx_lock);
|
|
|
|
spin_lock_init(&catc->ctrl_lock);
|
|
|
|
|
2017-10-17 08:29:32 +08:00
|
|
|
timer_setup(&catc->timer, catc_stats_timer, 0);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
catc->ctrl_urb = usb_alloc_urb(0, GFP_KERNEL);
|
|
|
|
catc->tx_urb = usb_alloc_urb(0, GFP_KERNEL);
|
|
|
|
catc->rx_urb = usb_alloc_urb(0, GFP_KERNEL);
|
|
|
|
catc->irq_urb = usb_alloc_urb(0, GFP_KERNEL);
|
|
|
|
if ((!catc->ctrl_urb) || (!catc->tx_urb) ||
|
|
|
|
(!catc->rx_urb) || (!catc->irq_urb)) {
|
2012-04-26 03:37:47 +08:00
|
|
|
dev_err(&intf->dev, "No free urbs available.\n");
|
2017-02-05 00:56:56 +08:00
|
|
|
ret = -ENOMEM;
|
|
|
|
goto fail_free;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* The F5U011 has the same vendor/product as the netmate but a device version of 0x130 */
|
|
|
|
if (le16_to_cpu(usbdev->descriptor.idVendor) == 0x0423 &&
|
|
|
|
le16_to_cpu(usbdev->descriptor.idProduct) == 0xa &&
|
|
|
|
le16_to_cpu(catc->usbdev->descriptor.bcdDevice) == 0x0130) {
|
2012-09-19 17:46:14 +08:00
|
|
|
dev_dbg(dev, "Testing for f5u011\n");
|
2005-04-17 06:20:36 +08:00
|
|
|
catc->is_f5u011 = 1;
|
|
|
|
atomic_set(&catc->recq_sz, 0);
|
|
|
|
pktsz = RX_PKT_SZ;
|
|
|
|
} else {
|
|
|
|
pktsz = RX_MAX_BURST * (PKT_SZ + 2);
|
|
|
|
}
|
|
|
|
|
|
|
|
usb_fill_control_urb(catc->ctrl_urb, usbdev, usb_sndctrlpipe(usbdev, 0),
|
|
|
|
NULL, NULL, 0, catc_ctrl_done, catc);
|
|
|
|
|
|
|
|
usb_fill_bulk_urb(catc->tx_urb, usbdev, usb_sndbulkpipe(usbdev, 1),
|
|
|
|
NULL, 0, catc_tx_done, catc);
|
|
|
|
|
|
|
|
usb_fill_bulk_urb(catc->rx_urb, usbdev, usb_rcvbulkpipe(usbdev, 1),
|
|
|
|
catc->rx_buf, pktsz, catc_rx_done, catc);
|
|
|
|
|
|
|
|
usb_fill_int_urb(catc->irq_urb, usbdev, usb_rcvintpipe(usbdev, 2),
|
|
|
|
catc->irq_buf, 2, catc_irq_done, catc, 1);
|
|
|
|
|
|
|
|
if (!catc->is_f5u011) {
|
2017-02-05 00:57:04 +08:00
|
|
|
u32 *buf;
|
|
|
|
int i;
|
|
|
|
|
2012-09-19 17:46:14 +08:00
|
|
|
dev_dbg(dev, "Checking memory size\n");
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2017-02-05 00:57:04 +08:00
|
|
|
buf = kmalloc(4, GFP_KERNEL);
|
|
|
|
if (!buf) {
|
|
|
|
ret = -ENOMEM;
|
|
|
|
goto fail_free;
|
|
|
|
}
|
|
|
|
|
|
|
|
*buf = 0x12345678;
|
|
|
|
catc_write_mem(catc, 0x7a80, buf, 4);
|
|
|
|
*buf = 0x87654321;
|
|
|
|
catc_write_mem(catc, 0xfa80, buf, 4);
|
|
|
|
catc_read_mem(catc, 0x7a80, buf, 4);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2017-02-05 00:57:04 +08:00
|
|
|
switch (*buf) {
|
2005-04-17 06:20:36 +08:00
|
|
|
case 0x12345678:
|
|
|
|
catc_set_reg(catc, TxBufCount, 8);
|
|
|
|
catc_set_reg(catc, RxBufCount, 32);
|
2012-09-19 17:46:14 +08:00
|
|
|
dev_dbg(dev, "64k Memory\n");
|
2005-04-17 06:20:36 +08:00
|
|
|
break;
|
|
|
|
default:
|
2008-08-15 00:37:34 +08:00
|
|
|
dev_warn(&intf->dev,
|
|
|
|
"Couldn't detect memory size, assuming 32k\n");
|
2005-04-17 06:20:36 +08:00
|
|
|
case 0x87654321:
|
|
|
|
catc_set_reg(catc, TxBufCount, 4);
|
|
|
|
catc_set_reg(catc, RxBufCount, 16);
|
2012-09-19 17:46:14 +08:00
|
|
|
dev_dbg(dev, "32k Memory\n");
|
2005-04-17 06:20:36 +08:00
|
|
|
break;
|
|
|
|
}
|
2017-02-05 00:57:04 +08:00
|
|
|
|
|
|
|
kfree(buf);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2012-09-19 17:46:14 +08:00
|
|
|
dev_dbg(dev, "Getting MAC from SEEROM.\n");
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
catc_get_mac(catc, netdev->dev_addr);
|
|
|
|
|
2012-09-19 17:46:14 +08:00
|
|
|
dev_dbg(dev, "Setting MAC into registers.\n");
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
for (i = 0; i < 6; i++)
|
|
|
|
catc_set_reg(catc, StationAddr0 - i, netdev->dev_addr[i]);
|
|
|
|
|
2012-09-19 17:46:14 +08:00
|
|
|
dev_dbg(dev, "Filling the multicast list.\n");
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2015-03-03 11:54:48 +08:00
|
|
|
eth_broadcast_addr(broadcast);
|
2005-04-17 06:20:36 +08:00
|
|
|
catc_multicast(broadcast, catc->multicast);
|
|
|
|
catc_multicast(netdev->dev_addr, catc->multicast);
|
|
|
|
catc_write_mem(catc, 0xfa80, catc->multicast, 64);
|
|
|
|
|
2012-09-19 17:46:14 +08:00
|
|
|
dev_dbg(dev, "Clearing error counters.\n");
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
for (i = 0; i < 8; i++)
|
|
|
|
catc_set_reg(catc, EthStats + i, 0);
|
|
|
|
catc->last_stats = jiffies;
|
|
|
|
|
2012-09-19 17:46:14 +08:00
|
|
|
dev_dbg(dev, "Enabling.\n");
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
catc_set_reg(catc, MaxBurst, RX_MAX_BURST);
|
|
|
|
catc_set_reg(catc, OpModes, OpTxMerge | OpRxMerge | OpLenInclude | Op3MemWaits);
|
|
|
|
catc_set_reg(catc, LEDCtrl, LEDLink);
|
|
|
|
catc_set_reg(catc, RxUnit, RxEnable | RxPolarity | RxMultiCast);
|
|
|
|
} else {
|
2012-09-19 17:46:14 +08:00
|
|
|
dev_dbg(dev, "Performing reset\n");
|
2005-04-17 06:20:36 +08:00
|
|
|
catc_reset(catc);
|
|
|
|
catc_get_mac(catc, netdev->dev_addr);
|
|
|
|
|
2012-09-19 17:46:14 +08:00
|
|
|
dev_dbg(dev, "Setting RX Mode\n");
|
2005-04-17 06:20:36 +08:00
|
|
|
catc->rxmode[0] = RxEnable | RxPolarity | RxMultiCast;
|
|
|
|
catc->rxmode[1] = 0;
|
|
|
|
f5u011_rxmode(catc, catc->rxmode);
|
|
|
|
}
|
2012-09-19 17:46:14 +08:00
|
|
|
dev_dbg(dev, "Init done.\n");
|
2009-12-30 12:06:45 +08:00
|
|
|
printk(KERN_INFO "%s: %s USB Ethernet at usb-%s-%s, %pM.\n",
|
2005-04-17 06:20:36 +08:00
|
|
|
netdev->name, (catc->is_f5u011) ? "Belkin F5U011" : "CATC EL1210A NetMate",
|
2009-12-30 12:06:45 +08:00
|
|
|
usbdev->bus->bus_name, usbdev->devpath, netdev->dev_addr);
|
2005-04-17 06:20:36 +08:00
|
|
|
usb_set_intfdata(intf, catc);
|
|
|
|
|
|
|
|
SET_NETDEV_DEV(netdev, &intf->dev);
|
2017-02-05 00:56:56 +08:00
|
|
|
ret = register_netdev(netdev);
|
|
|
|
if (ret)
|
|
|
|
goto fail_clear_intfdata;
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
return 0;
|
2017-02-05 00:56:56 +08:00
|
|
|
|
|
|
|
fail_clear_intfdata:
|
|
|
|
usb_set_intfdata(intf, NULL);
|
|
|
|
fail_free:
|
|
|
|
usb_free_urb(catc->ctrl_urb);
|
|
|
|
usb_free_urb(catc->tx_urb);
|
|
|
|
usb_free_urb(catc->rx_urb);
|
|
|
|
usb_free_urb(catc->irq_urb);
|
|
|
|
free_netdev(netdev);
|
|
|
|
return ret;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void catc_disconnect(struct usb_interface *intf)
|
|
|
|
{
|
|
|
|
struct catc *catc = usb_get_intfdata(intf);
|
|
|
|
|
|
|
|
usb_set_intfdata(intf, NULL);
|
|
|
|
if (catc) {
|
|
|
|
unregister_netdev(catc->netdev);
|
|
|
|
usb_free_urb(catc->ctrl_urb);
|
|
|
|
usb_free_urb(catc->tx_urb);
|
|
|
|
usb_free_urb(catc->rx_urb);
|
|
|
|
usb_free_urb(catc->irq_urb);
|
|
|
|
free_netdev(catc->netdev);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Module functions and tables.
|
|
|
|
*/
|
|
|
|
|
2017-08-08 23:58:01 +08:00
|
|
|
static const struct usb_device_id catc_id_table[] = {
|
2005-04-17 06:20:36 +08:00
|
|
|
{ USB_DEVICE(0x0423, 0xa) }, /* CATC Netmate, Belkin F5U011 */
|
|
|
|
{ USB_DEVICE(0x0423, 0xc) }, /* CATC Netmate II, Belkin F5U111 */
|
|
|
|
{ USB_DEVICE(0x08d1, 0x1) }, /* smartBridges smartNIC */
|
|
|
|
{ }
|
|
|
|
};
|
|
|
|
|
|
|
|
MODULE_DEVICE_TABLE(usb, catc_id_table);
|
|
|
|
|
|
|
|
static struct usb_driver catc_driver = {
|
|
|
|
.name = driver_name,
|
|
|
|
.probe = catc_probe,
|
|
|
|
.disconnect = catc_disconnect,
|
|
|
|
.id_table = catc_id_table,
|
2012-04-24 01:08:51 +08:00
|
|
|
.disable_hub_initiated_lpm = 1,
|
2005-04-17 06:20:36 +08:00
|
|
|
};
|
|
|
|
|
2011-11-19 01:44:20 +08:00
|
|
|
module_usb_driver(catc_driver);
|