2006-10-09 05:08:00 +07:00
|
|
|
/*
|
2010-12-21 01:38:47 +07:00
|
|
|
* MOSCHIP MCS7830 based (7730/7830/7832) USB 2.0 Ethernet Devices
|
2006-10-09 05:08:00 +07:00
|
|
|
*
|
|
|
|
* based on usbnet.c, asix.c and the vendor provided mcs7830 driver
|
|
|
|
*
|
2010-01-31 09:58:19 +07:00
|
|
|
* Copyright (C) 2010 Andreas Mohr <andi@lisas.de>
|
2006-10-09 05:08:00 +07:00
|
|
|
* Copyright (C) 2006 Arnd Bergmann <arnd@arndb.de>
|
|
|
|
* Copyright (C) 2003-2005 David Hollis <dhollis@davehollis.com>
|
|
|
|
* Copyright (C) 2005 Phil Chang <pchang23@sbcglobal.net>
|
|
|
|
* Copyright (c) 2002-2003 TiVo Inc.
|
|
|
|
*
|
2010-01-31 09:58:19 +07:00
|
|
|
* Definitions gathered from MOSCHIP, Data Sheet_7830DA.pdf (thanks!).
|
|
|
|
*
|
2010-12-21 01:38:47 +07:00
|
|
|
* 2010-12-19: add 7832 USB PID ("functionality same as MCS7830"),
|
|
|
|
* per active notification by manufacturer
|
|
|
|
*
|
2010-01-31 09:58:19 +07:00
|
|
|
* TODO:
|
|
|
|
* - support HIF_REG_CONFIG_SLEEPMODE/HIF_REG_CONFIG_TXENABLE (via autopm?)
|
|
|
|
* - implement ethtool_ops get_pauseparam/set_pauseparam
|
|
|
|
* via HIF_REG_PAUSE_THRESHOLD (>= revision C only!)
|
|
|
|
* - implement get_eeprom/[set_eeprom]
|
|
|
|
* - switch PHY on/off on ifup/ifdown (perhaps in usbnet.c, via MII)
|
|
|
|
* - mcs7830_get_regs() handling is weird: for rev 2 we return 32 regs,
|
|
|
|
* can access only ~ 24, remaining user buffer is uninitialized garbage
|
|
|
|
* - anything else?
|
|
|
|
*
|
|
|
|
*
|
2006-10-09 05:08:00 +07:00
|
|
|
* 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 21:28:46 +07:00
|
|
|
* along with this program; if not, see <http://www.gnu.org/licenses/>.
|
2006-10-09 05:08:00 +07:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/crc32.h>
|
|
|
|
#include <linux/etherdevice.h>
|
|
|
|
#include <linux/ethtool.h>
|
|
|
|
#include <linux/mii.h>
|
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/netdevice.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 15:04:11 +07:00
|
|
|
#include <linux/slab.h>
|
2006-10-09 05:08:00 +07:00
|
|
|
#include <linux/usb.h>
|
2008-01-26 05:51:45 +07:00
|
|
|
#include <linux/usb/usbnet.h>
|
2006-10-09 05:08:00 +07:00
|
|
|
|
|
|
|
/* requests */
|
|
|
|
#define MCS7830_RD_BMREQ (USB_DIR_IN | USB_TYPE_VENDOR | \
|
|
|
|
USB_RECIP_DEVICE)
|
|
|
|
#define MCS7830_WR_BMREQ (USB_DIR_OUT | USB_TYPE_VENDOR | \
|
|
|
|
USB_RECIP_DEVICE)
|
|
|
|
#define MCS7830_RD_BREQ 0x0E
|
|
|
|
#define MCS7830_WR_BREQ 0x0D
|
|
|
|
|
|
|
|
#define MCS7830_CTRL_TIMEOUT 1000
|
|
|
|
#define MCS7830_MAX_MCAST 64
|
|
|
|
|
|
|
|
#define MCS7830_VENDOR_ID 0x9710
|
2010-12-21 01:38:47 +07:00
|
|
|
#define MCS7832_PRODUCT_ID 0x7832
|
2006-10-09 05:08:00 +07:00
|
|
|
#define MCS7830_PRODUCT_ID 0x7830
|
2008-08-24 03:02:23 +07:00
|
|
|
#define MCS7730_PRODUCT_ID 0x7730
|
|
|
|
|
|
|
|
#define SITECOM_VENDOR_ID 0x0DF6
|
|
|
|
#define LN_030_PRODUCT_ID 0x0021
|
2006-10-09 05:08:00 +07:00
|
|
|
|
|
|
|
#define MCS7830_MII_ADVERTISE (ADVERTISE_PAUSE_CAP | ADVERTISE_100FULL | \
|
|
|
|
ADVERTISE_100HALF | ADVERTISE_10FULL | \
|
|
|
|
ADVERTISE_10HALF | ADVERTISE_CSMA)
|
|
|
|
|
2010-01-31 09:58:26 +07:00
|
|
|
/* HIF_REG_XX corresponding index value */
|
2006-10-09 05:08:00 +07:00
|
|
|
enum {
|
|
|
|
HIF_REG_MULTICAST_HASH = 0x00,
|
|
|
|
HIF_REG_PACKET_GAP1 = 0x08,
|
|
|
|
HIF_REG_PACKET_GAP2 = 0x09,
|
|
|
|
HIF_REG_PHY_DATA = 0x0a,
|
|
|
|
HIF_REG_PHY_CMD1 = 0x0c,
|
|
|
|
HIF_REG_PHY_CMD1_READ = 0x40,
|
|
|
|
HIF_REG_PHY_CMD1_WRITE = 0x20,
|
|
|
|
HIF_REG_PHY_CMD1_PHYADDR = 0x01,
|
|
|
|
HIF_REG_PHY_CMD2 = 0x0d,
|
|
|
|
HIF_REG_PHY_CMD2_PEND_FLAG_BIT = 0x80,
|
|
|
|
HIF_REG_PHY_CMD2_READY_FLAG_BIT = 0x40,
|
|
|
|
HIF_REG_CONFIG = 0x0e,
|
2010-01-31 09:58:33 +07:00
|
|
|
/* hmm, spec sez: "R/W", "Except bit 3" (likely TXENABLE). */
|
2006-10-09 05:08:00 +07:00
|
|
|
HIF_REG_CONFIG_CFG = 0x80,
|
|
|
|
HIF_REG_CONFIG_SPEED100 = 0x40,
|
|
|
|
HIF_REG_CONFIG_FULLDUPLEX_ENABLE = 0x20,
|
|
|
|
HIF_REG_CONFIG_RXENABLE = 0x10,
|
|
|
|
HIF_REG_CONFIG_TXENABLE = 0x08,
|
|
|
|
HIF_REG_CONFIG_SLEEPMODE = 0x04,
|
|
|
|
HIF_REG_CONFIG_ALLMULTICAST = 0x02,
|
2010-01-31 09:58:26 +07:00
|
|
|
HIF_REG_CONFIG_PROMISCUOUS = 0x01,
|
2006-10-09 05:08:00 +07:00
|
|
|
HIF_REG_ETHERNET_ADDR = 0x0f,
|
2010-01-31 09:58:33 +07:00
|
|
|
HIF_REG_FRAME_DROP_COUNTER = 0x15, /* 0..ff; reset: 0 */
|
2006-10-09 05:08:00 +07:00
|
|
|
HIF_REG_PAUSE_THRESHOLD = 0x16,
|
|
|
|
HIF_REG_PAUSE_THRESHOLD_DEFAULT = 0,
|
|
|
|
};
|
|
|
|
|
2010-01-31 09:58:19 +07:00
|
|
|
/* Trailing status byte in Ethernet Rx frame */
|
|
|
|
enum {
|
|
|
|
MCS7830_RX_SHORT_FRAME = 0x01, /* < 64 bytes */
|
|
|
|
MCS7830_RX_LENGTH_ERROR = 0x02, /* framelen != Ethernet length field */
|
|
|
|
MCS7830_RX_ALIGNMENT_ERROR = 0x04, /* non-even number of nibbles */
|
|
|
|
MCS7830_RX_CRC_ERROR = 0x08,
|
|
|
|
MCS7830_RX_LARGE_FRAME = 0x10, /* > 1518 bytes */
|
|
|
|
MCS7830_RX_FRAME_CORRECT = 0x20, /* frame is correct */
|
|
|
|
/* [7:6] reserved */
|
|
|
|
};
|
|
|
|
|
2006-10-09 05:08:00 +07:00
|
|
|
struct mcs7830_data {
|
|
|
|
u8 multi_filter[8];
|
|
|
|
u8 config;
|
|
|
|
};
|
|
|
|
|
|
|
|
static const char driver_name[] = "MOSCHIP usb-ethernet driver";
|
|
|
|
|
|
|
|
static int mcs7830_get_reg(struct usbnet *dev, u16 index, u16 size, void *data)
|
|
|
|
{
|
2012-10-25 02:46:59 +07:00
|
|
|
return usbnet_read_cmd(dev, MCS7830_RD_BREQ, MCS7830_RD_BMREQ,
|
|
|
|
0x0000, index, data, size);
|
2006-10-09 05:08:00 +07:00
|
|
|
}
|
|
|
|
|
2010-01-31 09:58:42 +07:00
|
|
|
static int mcs7830_set_reg(struct usbnet *dev, u16 index, u16 size, const void *data)
|
2006-10-09 05:08:00 +07:00
|
|
|
{
|
2012-10-25 02:46:59 +07:00
|
|
|
return usbnet_write_cmd(dev, MCS7830_WR_BREQ, MCS7830_WR_BMREQ,
|
|
|
|
0x0000, index, data, size);
|
2006-10-09 05:08:00 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
static void mcs7830_set_reg_async(struct usbnet *dev, u16 index, u16 size, void *data)
|
|
|
|
{
|
2012-10-25 02:46:59 +07:00
|
|
|
usbnet_write_cmd_async(dev, MCS7830_WR_BREQ, MCS7830_WR_BMREQ,
|
|
|
|
0x0000, index, data, size);
|
2006-10-09 05:08:00 +07:00
|
|
|
}
|
|
|
|
|
2010-01-31 09:58:42 +07:00
|
|
|
static int mcs7830_hif_get_mac_address(struct usbnet *dev, unsigned char *addr)
|
|
|
|
{
|
|
|
|
int ret = mcs7830_get_reg(dev, HIF_REG_ETHERNET_ADDR, ETH_ALEN, addr);
|
|
|
|
if (ret < 0)
|
|
|
|
return ret;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int mcs7830_hif_set_mac_address(struct usbnet *dev, unsigned char *addr)
|
|
|
|
{
|
|
|
|
int ret = mcs7830_set_reg(dev, HIF_REG_ETHERNET_ADDR, ETH_ALEN, addr);
|
|
|
|
|
|
|
|
if (ret < 0)
|
|
|
|
return ret;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int mcs7830_set_mac_address(struct net_device *netdev, void *p)
|
2006-10-09 05:08:00 +07:00
|
|
|
{
|
|
|
|
int ret;
|
2010-01-31 09:58:42 +07:00
|
|
|
struct usbnet *dev = netdev_priv(netdev);
|
|
|
|
struct sockaddr *addr = p;
|
|
|
|
|
|
|
|
if (netif_running(netdev))
|
|
|
|
return -EBUSY;
|
|
|
|
|
|
|
|
if (!is_valid_ether_addr(addr->sa_data))
|
2012-02-21 09:07:50 +07:00
|
|
|
return -EADDRNOTAVAIL;
|
2010-01-31 09:58:42 +07:00
|
|
|
|
|
|
|
ret = mcs7830_hif_set_mac_address(dev, addr->sa_data);
|
|
|
|
|
2006-10-09 05:08:00 +07:00
|
|
|
if (ret < 0)
|
|
|
|
return ret;
|
2010-01-31 09:58:42 +07:00
|
|
|
|
|
|
|
/* it worked --> adopt it on netdev side */
|
|
|
|
memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len);
|
|
|
|
|
2006-10-09 05:08:00 +07:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int mcs7830_read_phy(struct usbnet *dev, u8 index)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
int i;
|
|
|
|
__le16 val;
|
|
|
|
|
|
|
|
u8 cmd[2] = {
|
|
|
|
HIF_REG_PHY_CMD1_READ | HIF_REG_PHY_CMD1_PHYADDR,
|
|
|
|
HIF_REG_PHY_CMD2_PEND_FLAG_BIT | index,
|
|
|
|
};
|
|
|
|
|
2006-10-09 05:08:02 +07:00
|
|
|
mutex_lock(&dev->phy_mutex);
|
2006-10-09 05:08:00 +07:00
|
|
|
/* write the MII command */
|
|
|
|
ret = mcs7830_set_reg(dev, HIF_REG_PHY_CMD1, 2, cmd);
|
|
|
|
if (ret < 0)
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
/* wait for the data to become valid, should be within < 1ms */
|
|
|
|
for (i = 0; i < 10; i++) {
|
|
|
|
ret = mcs7830_get_reg(dev, HIF_REG_PHY_CMD1, 2, cmd);
|
|
|
|
if ((ret < 0) || (cmd[1] & HIF_REG_PHY_CMD2_READY_FLAG_BIT))
|
|
|
|
break;
|
|
|
|
ret = -EIO;
|
|
|
|
msleep(1);
|
|
|
|
}
|
|
|
|
if (ret < 0)
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
/* read actual register contents */
|
|
|
|
ret = mcs7830_get_reg(dev, HIF_REG_PHY_DATA, 2, &val);
|
|
|
|
if (ret < 0)
|
|
|
|
goto out;
|
|
|
|
ret = le16_to_cpu(val);
|
|
|
|
dev_dbg(&dev->udev->dev, "read PHY reg %02x: %04x (%d tries)\n",
|
|
|
|
index, val, i);
|
|
|
|
out:
|
2006-10-09 05:08:02 +07:00
|
|
|
mutex_unlock(&dev->phy_mutex);
|
2006-10-09 05:08:00 +07:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int mcs7830_write_phy(struct usbnet *dev, u8 index, u16 val)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
int i;
|
|
|
|
__le16 le_val;
|
|
|
|
|
|
|
|
u8 cmd[2] = {
|
|
|
|
HIF_REG_PHY_CMD1_WRITE | HIF_REG_PHY_CMD1_PHYADDR,
|
|
|
|
HIF_REG_PHY_CMD2_PEND_FLAG_BIT | (index & 0x1F),
|
|
|
|
};
|
|
|
|
|
2006-10-09 05:08:02 +07:00
|
|
|
mutex_lock(&dev->phy_mutex);
|
|
|
|
|
2006-10-09 05:08:00 +07:00
|
|
|
/* write the new register contents */
|
|
|
|
le_val = cpu_to_le16(val);
|
|
|
|
ret = mcs7830_set_reg(dev, HIF_REG_PHY_DATA, 2, &le_val);
|
|
|
|
if (ret < 0)
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
/* write the MII command */
|
|
|
|
ret = mcs7830_set_reg(dev, HIF_REG_PHY_CMD1, 2, cmd);
|
|
|
|
if (ret < 0)
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
/* wait for the command to be accepted by the PHY */
|
|
|
|
for (i = 0; i < 10; i++) {
|
|
|
|
ret = mcs7830_get_reg(dev, HIF_REG_PHY_CMD1, 2, cmd);
|
|
|
|
if ((ret < 0) || (cmd[1] & HIF_REG_PHY_CMD2_READY_FLAG_BIT))
|
|
|
|
break;
|
|
|
|
ret = -EIO;
|
|
|
|
msleep(1);
|
|
|
|
}
|
|
|
|
if (ret < 0)
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
ret = 0;
|
|
|
|
dev_dbg(&dev->udev->dev, "write PHY reg %02x: %04x (%d tries)\n",
|
|
|
|
index, val, i);
|
|
|
|
out:
|
2006-10-09 05:08:02 +07:00
|
|
|
mutex_unlock(&dev->phy_mutex);
|
2006-10-09 05:08:00 +07:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This algorithm comes from the original mcs7830 version 1.4 driver,
|
|
|
|
* not sure if it is needed.
|
|
|
|
*/
|
|
|
|
static int mcs7830_set_autoneg(struct usbnet *dev, int ptrUserPhyMode)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
/* Enable all media types */
|
|
|
|
ret = mcs7830_write_phy(dev, MII_ADVERTISE, MCS7830_MII_ADVERTISE);
|
|
|
|
|
|
|
|
/* First reset BMCR */
|
|
|
|
if (!ret)
|
|
|
|
ret = mcs7830_write_phy(dev, MII_BMCR, 0x0000);
|
|
|
|
/* Enable Auto Neg */
|
|
|
|
if (!ret)
|
|
|
|
ret = mcs7830_write_phy(dev, MII_BMCR, BMCR_ANENABLE);
|
|
|
|
/* Restart Auto Neg (Keep the Enable Auto Neg Bit Set) */
|
|
|
|
if (!ret)
|
|
|
|
ret = mcs7830_write_phy(dev, MII_BMCR,
|
|
|
|
BMCR_ANENABLE | BMCR_ANRESTART );
|
2010-12-17 10:25:43 +07:00
|
|
|
return ret;
|
2006-10-09 05:08:00 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* if we can read register 22, the chip revision is C or higher
|
|
|
|
*/
|
|
|
|
static int mcs7830_get_rev(struct usbnet *dev)
|
|
|
|
{
|
|
|
|
u8 dummy[2];
|
|
|
|
int ret;
|
2010-01-31 09:58:33 +07:00
|
|
|
ret = mcs7830_get_reg(dev, HIF_REG_FRAME_DROP_COUNTER, 2, dummy);
|
2006-10-09 05:08:00 +07:00
|
|
|
if (ret > 0)
|
|
|
|
return 2; /* Rev C or later */
|
|
|
|
return 1; /* earlier revision */
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* On rev. C we need to set the pause threshold
|
|
|
|
*/
|
|
|
|
static void mcs7830_rev_C_fixup(struct usbnet *dev)
|
|
|
|
{
|
|
|
|
u8 pause_threshold = HIF_REG_PAUSE_THRESHOLD_DEFAULT;
|
|
|
|
int retry;
|
|
|
|
|
|
|
|
for (retry = 0; retry < 2; retry++) {
|
|
|
|
if (mcs7830_get_rev(dev) == 2) {
|
|
|
|
dev_info(&dev->udev->dev, "applying rev.C fixup\n");
|
|
|
|
mcs7830_set_reg(dev, HIF_REG_PAUSE_THRESHOLD,
|
|
|
|
1, &pause_threshold);
|
|
|
|
}
|
|
|
|
msleep(1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static int mcs7830_mdio_read(struct net_device *netdev, int phy_id,
|
|
|
|
int location)
|
|
|
|
{
|
2008-11-13 14:38:36 +07:00
|
|
|
struct usbnet *dev = netdev_priv(netdev);
|
2006-10-09 05:08:00 +07:00
|
|
|
return mcs7830_read_phy(dev, location);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void mcs7830_mdio_write(struct net_device *netdev, int phy_id,
|
|
|
|
int location, int val)
|
|
|
|
{
|
2008-11-13 14:38:36 +07:00
|
|
|
struct usbnet *dev = netdev_priv(netdev);
|
2006-10-09 05:08:00 +07:00
|
|
|
mcs7830_write_phy(dev, location, val);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int mcs7830_ioctl(struct net_device *net, struct ifreq *rq, int cmd)
|
|
|
|
{
|
|
|
|
struct usbnet *dev = netdev_priv(net);
|
|
|
|
return generic_mii_ioctl(&dev->mii, if_mii(rq), cmd, NULL);
|
|
|
|
}
|
|
|
|
|
2010-01-31 09:58:42 +07:00
|
|
|
static inline struct mcs7830_data *mcs7830_get_data(struct usbnet *dev)
|
|
|
|
{
|
|
|
|
return (struct mcs7830_data *)&dev->data;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void mcs7830_hif_update_multicast_hash(struct usbnet *dev)
|
|
|
|
{
|
|
|
|
struct mcs7830_data *data = mcs7830_get_data(dev);
|
|
|
|
mcs7830_set_reg_async(dev, HIF_REG_MULTICAST_HASH,
|
|
|
|
sizeof data->multi_filter,
|
|
|
|
data->multi_filter);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void mcs7830_hif_update_config(struct usbnet *dev)
|
|
|
|
{
|
|
|
|
/* implementation specific to data->config
|
|
|
|
(argument needs to be heap-based anyway - USB DMA!) */
|
|
|
|
struct mcs7830_data *data = mcs7830_get_data(dev);
|
|
|
|
mcs7830_set_reg_async(dev, HIF_REG_CONFIG, 1, &data->config);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void mcs7830_data_set_multicast(struct net_device *net)
|
2006-10-09 05:08:00 +07:00
|
|
|
{
|
|
|
|
struct usbnet *dev = netdev_priv(net);
|
2010-01-31 09:58:42 +07:00
|
|
|
struct mcs7830_data *data = mcs7830_get_data(dev);
|
|
|
|
|
|
|
|
memset(data->multi_filter, 0, sizeof data->multi_filter);
|
2006-10-09 05:08:00 +07:00
|
|
|
|
|
|
|
data->config = HIF_REG_CONFIG_TXENABLE;
|
|
|
|
|
|
|
|
/* this should not be needed, but it doesn't work otherwise */
|
|
|
|
data->config |= HIF_REG_CONFIG_ALLMULTICAST;
|
|
|
|
|
|
|
|
if (net->flags & IFF_PROMISC) {
|
2010-01-31 09:58:26 +07:00
|
|
|
data->config |= HIF_REG_CONFIG_PROMISCUOUS;
|
2009-12-03 14:58:21 +07:00
|
|
|
} else if (net->flags & IFF_ALLMULTI ||
|
2010-02-08 11:30:35 +07:00
|
|
|
netdev_mc_count(net) > MCS7830_MAX_MCAST) {
|
2006-10-09 05:08:00 +07:00
|
|
|
data->config |= HIF_REG_CONFIG_ALLMULTICAST;
|
2010-02-08 11:30:35 +07:00
|
|
|
} else if (netdev_mc_empty(net)) {
|
2006-10-09 05:08:00 +07:00
|
|
|
/* just broadcast and directed */
|
|
|
|
} else {
|
|
|
|
/* We use the 20 byte dev->data
|
|
|
|
* for our 8 byte filter buffer
|
|
|
|
* to avoid allocating memory that
|
|
|
|
* is tricky to free later */
|
2010-04-02 04:22:57 +07:00
|
|
|
struct netdev_hw_addr *ha;
|
2006-10-09 05:08:00 +07:00
|
|
|
u32 crc_bits;
|
|
|
|
|
|
|
|
/* Build the multicast hash filter. */
|
2010-04-02 04:22:57 +07:00
|
|
|
netdev_for_each_mc_addr(ha, net) {
|
|
|
|
crc_bits = ether_crc(ETH_ALEN, ha->addr) >> 26;
|
2006-10-09 05:08:00 +07:00
|
|
|
data->multi_filter[crc_bits >> 3] |= 1 << (crc_bits & 7);
|
|
|
|
}
|
2010-01-31 09:58:42 +07:00
|
|
|
}
|
|
|
|
}
|
2006-10-09 05:08:00 +07:00
|
|
|
|
2010-01-31 09:58:42 +07:00
|
|
|
static int mcs7830_apply_base_config(struct usbnet *dev)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
/* re-configure known MAC (suspend case etc.) */
|
|
|
|
ret = mcs7830_hif_set_mac_address(dev, dev->net->dev_addr);
|
|
|
|
if (ret) {
|
|
|
|
dev_info(&dev->udev->dev, "Cannot set MAC address\n");
|
|
|
|
goto out;
|
2006-10-09 05:08:00 +07:00
|
|
|
}
|
|
|
|
|
2010-01-31 09:58:42 +07:00
|
|
|
/* Set up PHY */
|
|
|
|
ret = mcs7830_set_autoneg(dev, 0);
|
|
|
|
if (ret) {
|
|
|
|
dev_info(&dev->udev->dev, "Cannot set autoneg\n");
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
mcs7830_hif_update_multicast_hash(dev);
|
|
|
|
mcs7830_hif_update_config(dev);
|
|
|
|
|
|
|
|
mcs7830_rev_C_fixup(dev);
|
|
|
|
ret = 0;
|
|
|
|
out:
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* credits go to asix_set_multicast */
|
|
|
|
static void mcs7830_set_multicast(struct net_device *net)
|
|
|
|
{
|
|
|
|
struct usbnet *dev = netdev_priv(net);
|
|
|
|
|
|
|
|
mcs7830_data_set_multicast(net);
|
|
|
|
|
|
|
|
mcs7830_hif_update_multicast_hash(dev);
|
|
|
|
mcs7830_hif_update_config(dev);
|
2006-10-09 05:08:00 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
static int mcs7830_get_regs_len(struct net_device *net)
|
|
|
|
{
|
|
|
|
struct usbnet *dev = netdev_priv(net);
|
|
|
|
|
|
|
|
switch (mcs7830_get_rev(dev)) {
|
|
|
|
case 1:
|
|
|
|
return 21;
|
|
|
|
case 2:
|
|
|
|
return 32;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void mcs7830_get_drvinfo(struct net_device *net, struct ethtool_drvinfo *drvinfo)
|
|
|
|
{
|
|
|
|
usbnet_get_drvinfo(net, drvinfo);
|
|
|
|
drvinfo->regdump_len = mcs7830_get_regs_len(net);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void mcs7830_get_regs(struct net_device *net, struct ethtool_regs *regs, void *data)
|
|
|
|
{
|
|
|
|
struct usbnet *dev = netdev_priv(net);
|
|
|
|
|
|
|
|
regs->version = mcs7830_get_rev(dev);
|
|
|
|
mcs7830_get_reg(dev, 0, regs->len, data);
|
|
|
|
}
|
|
|
|
|
2009-09-02 15:03:33 +07:00
|
|
|
static const struct ethtool_ops mcs7830_ethtool_ops = {
|
2006-10-09 05:08:00 +07:00
|
|
|
.get_drvinfo = mcs7830_get_drvinfo,
|
|
|
|
.get_regs_len = mcs7830_get_regs_len,
|
|
|
|
.get_regs = mcs7830_get_regs,
|
|
|
|
|
|
|
|
/* common usbnet calls */
|
2006-10-09 05:08:01 +07:00
|
|
|
.get_link = usbnet_get_link,
|
2006-10-09 05:08:00 +07:00
|
|
|
.get_msglevel = usbnet_get_msglevel,
|
|
|
|
.set_msglevel = usbnet_set_msglevel,
|
2006-10-09 05:08:01 +07:00
|
|
|
.get_settings = usbnet_get_settings,
|
|
|
|
.set_settings = usbnet_set_settings,
|
|
|
|
.nway_reset = usbnet_nway_reset,
|
2006-10-09 05:08:00 +07:00
|
|
|
};
|
|
|
|
|
2009-03-21 02:35:57 +07:00
|
|
|
static const struct net_device_ops mcs7830_netdev_ops = {
|
|
|
|
.ndo_open = usbnet_open,
|
|
|
|
.ndo_stop = usbnet_stop,
|
|
|
|
.ndo_start_xmit = usbnet_start_xmit,
|
|
|
|
.ndo_tx_timeout = usbnet_tx_timeout,
|
|
|
|
.ndo_change_mtu = usbnet_change_mtu,
|
|
|
|
.ndo_validate_addr = eth_validate_addr,
|
|
|
|
.ndo_do_ioctl = mcs7830_ioctl,
|
2011-08-16 13:29:01 +07:00
|
|
|
.ndo_set_rx_mode = mcs7830_set_multicast,
|
2010-01-31 09:58:26 +07:00
|
|
|
.ndo_set_mac_address = mcs7830_set_mac_address,
|
2009-03-21 02:35:57 +07:00
|
|
|
};
|
|
|
|
|
2006-10-09 05:08:00 +07:00
|
|
|
static int mcs7830_bind(struct usbnet *dev, struct usb_interface *udev)
|
|
|
|
{
|
|
|
|
struct net_device *net = dev->net;
|
|
|
|
int ret;
|
2010-01-31 09:58:42 +07:00
|
|
|
int retry;
|
2006-10-09 05:08:00 +07:00
|
|
|
|
2010-01-31 09:58:42 +07:00
|
|
|
/* Initial startup: Gather MAC address setting from EEPROM */
|
|
|
|
ret = -EINVAL;
|
|
|
|
for (retry = 0; retry < 5 && ret; retry++)
|
|
|
|
ret = mcs7830_hif_get_mac_address(dev, net->dev_addr);
|
|
|
|
if (ret) {
|
|
|
|
dev_warn(&dev->udev->dev, "Cannot read MAC address\n");
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
mcs7830_data_set_multicast(net);
|
|
|
|
|
|
|
|
ret = mcs7830_apply_base_config(dev);
|
2006-10-09 05:08:00 +07:00
|
|
|
if (ret)
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
net->ethtool_ops = &mcs7830_ethtool_ops;
|
2009-03-21 02:35:57 +07:00
|
|
|
net->netdev_ops = &mcs7830_netdev_ops;
|
2006-10-09 05:08:00 +07:00
|
|
|
|
|
|
|
/* reserve space for the status byte on rx */
|
|
|
|
dev->rx_urb_size = ETH_FRAME_LEN + 1;
|
|
|
|
|
|
|
|
dev->mii.mdio_read = mcs7830_mdio_read;
|
|
|
|
dev->mii.mdio_write = mcs7830_mdio_write;
|
|
|
|
dev->mii.dev = net;
|
|
|
|
dev->mii.phy_id_mask = 0x3f;
|
|
|
|
dev->mii.reg_num_mask = 0x1f;
|
|
|
|
dev->mii.phy_id = *((u8 *) net->dev_addr + 1);
|
|
|
|
|
|
|
|
ret = usbnet_get_endpoints(dev, udev);
|
|
|
|
out:
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2010-01-31 09:58:26 +07:00
|
|
|
/* The chip always appends a status byte that we need to strip */
|
2006-10-09 05:08:00 +07:00
|
|
|
static int mcs7830_rx_fixup(struct usbnet *dev, struct sk_buff *skb)
|
|
|
|
{
|
|
|
|
u8 status;
|
|
|
|
|
2014-02-13 23:50:19 +07:00
|
|
|
/* This check is no longer done by usbnet */
|
|
|
|
if (skb->len < dev->net->hard_header_len) {
|
|
|
|
dev_err(&dev->udev->dev, "unexpected tiny rx frame\n");
|
2006-10-09 05:08:00 +07:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
skb_trim(skb, skb->len - 1);
|
|
|
|
status = skb->data[skb->len];
|
|
|
|
|
2010-01-31 09:58:19 +07:00
|
|
|
if (status != MCS7830_RX_FRAME_CORRECT) {
|
2006-10-09 05:08:00 +07:00
|
|
|
dev_dbg(&dev->udev->dev, "rx fixup status %x\n", status);
|
|
|
|
|
2010-01-31 09:58:19 +07:00
|
|
|
/* hmm, perhaps usbnet.c already sees a globally visible
|
|
|
|
frame error and increments rx_errors on its own already? */
|
|
|
|
dev->net->stats.rx_errors++;
|
|
|
|
|
|
|
|
if (status & (MCS7830_RX_SHORT_FRAME
|
|
|
|
|MCS7830_RX_LENGTH_ERROR
|
|
|
|
|MCS7830_RX_LARGE_FRAME))
|
|
|
|
dev->net->stats.rx_length_errors++;
|
|
|
|
if (status & MCS7830_RX_ALIGNMENT_ERROR)
|
|
|
|
dev->net->stats.rx_frame_errors++;
|
|
|
|
if (status & MCS7830_RX_CRC_ERROR)
|
|
|
|
dev->net->stats.rx_crc_errors++;
|
|
|
|
}
|
|
|
|
|
2006-10-09 05:08:00 +07:00
|
|
|
return skb->len > 0;
|
|
|
|
}
|
|
|
|
|
2012-06-01 17:29:08 +07:00
|
|
|
static void mcs7830_status(struct usbnet *dev, struct urb *urb)
|
|
|
|
{
|
|
|
|
u8 *buf = urb->transfer_buffer;
|
2012-10-12 05:51:41 +07:00
|
|
|
bool link, link_changed;
|
2012-06-01 17:29:08 +07:00
|
|
|
|
|
|
|
if (urb->actual_length < 16)
|
|
|
|
return;
|
|
|
|
|
2013-12-24 00:06:31 +07:00
|
|
|
link = !(buf[1] == 0x20);
|
2012-10-12 05:51:41 +07:00
|
|
|
link_changed = netif_carrier_ok(dev->net) != link;
|
|
|
|
if (link_changed) {
|
2013-12-24 00:06:31 +07:00
|
|
|
usbnet_link_change(dev, link, 0);
|
|
|
|
netdev_dbg(dev->net, "Link Status is: %d\n", link);
|
|
|
|
}
|
2012-06-01 17:29:08 +07:00
|
|
|
}
|
|
|
|
|
2006-10-09 05:08:00 +07:00
|
|
|
static const struct driver_info moschip_info = {
|
2010-12-21 01:38:47 +07:00
|
|
|
.description = "MOSCHIP 7830/7832/7730 usb-NET adapter",
|
2008-08-24 03:02:23 +07:00
|
|
|
.bind = mcs7830_bind,
|
|
|
|
.rx_fixup = mcs7830_rx_fixup,
|
2012-06-01 17:29:08 +07:00
|
|
|
.flags = FLAG_ETHER | FLAG_LINK_INTR,
|
|
|
|
.status = mcs7830_status,
|
2008-08-24 03:02:23 +07:00
|
|
|
.in = 1,
|
|
|
|
.out = 2,
|
|
|
|
};
|
|
|
|
|
|
|
|
static const struct driver_info sitecom_info = {
|
|
|
|
.description = "Sitecom LN-30 usb-NET adapter",
|
2006-10-09 05:08:00 +07:00
|
|
|
.bind = mcs7830_bind,
|
|
|
|
.rx_fixup = mcs7830_rx_fixup,
|
2012-06-01 17:29:08 +07:00
|
|
|
.flags = FLAG_ETHER | FLAG_LINK_INTR,
|
|
|
|
.status = mcs7830_status,
|
2006-10-09 05:08:00 +07:00
|
|
|
.in = 1,
|
|
|
|
.out = 2,
|
|
|
|
};
|
|
|
|
|
|
|
|
static const struct usb_device_id products[] = {
|
2010-12-21 01:38:47 +07:00
|
|
|
{
|
|
|
|
USB_DEVICE(MCS7830_VENDOR_ID, MCS7832_PRODUCT_ID),
|
|
|
|
.driver_info = (unsigned long) &moschip_info,
|
|
|
|
},
|
2006-10-09 05:08:00 +07:00
|
|
|
{
|
|
|
|
USB_DEVICE(MCS7830_VENDOR_ID, MCS7830_PRODUCT_ID),
|
|
|
|
.driver_info = (unsigned long) &moschip_info,
|
|
|
|
},
|
2008-08-24 03:02:23 +07:00
|
|
|
{
|
|
|
|
USB_DEVICE(MCS7830_VENDOR_ID, MCS7730_PRODUCT_ID),
|
|
|
|
.driver_info = (unsigned long) &moschip_info,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
USB_DEVICE(SITECOM_VENDOR_ID, LN_030_PRODUCT_ID),
|
|
|
|
.driver_info = (unsigned long) &sitecom_info,
|
|
|
|
},
|
2006-10-09 05:08:00 +07:00
|
|
|
{},
|
|
|
|
};
|
|
|
|
MODULE_DEVICE_TABLE(usb, products);
|
|
|
|
|
2010-01-31 09:58:42 +07:00
|
|
|
static int mcs7830_reset_resume (struct usb_interface *intf)
|
|
|
|
{
|
|
|
|
/* YES, this function is successful enough that ethtool -d
|
|
|
|
does show same output pre-/post-suspend */
|
|
|
|
|
|
|
|
struct usbnet *dev = usb_get_intfdata(intf);
|
|
|
|
|
|
|
|
mcs7830_apply_base_config(dev);
|
|
|
|
|
|
|
|
usbnet_resume(intf);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2006-10-09 05:08:00 +07:00
|
|
|
static struct usb_driver mcs7830_driver = {
|
|
|
|
.name = driver_name,
|
|
|
|
.id_table = products,
|
|
|
|
.probe = usbnet_probe,
|
|
|
|
.disconnect = usbnet_disconnect,
|
|
|
|
.suspend = usbnet_suspend,
|
|
|
|
.resume = usbnet_resume,
|
2010-01-31 09:58:42 +07:00
|
|
|
.reset_resume = mcs7830_reset_resume,
|
2012-04-24 00:08:51 +07:00
|
|
|
.disable_hub_initiated_lpm = 1,
|
2006-10-09 05:08:00 +07:00
|
|
|
};
|
|
|
|
|
2011-11-19 00:44:20 +07:00
|
|
|
module_usb_driver(mcs7830_driver);
|
2006-10-09 05:08:00 +07:00
|
|
|
|
|
|
|
MODULE_DESCRIPTION("USB to network adapter MCS7830)");
|
|
|
|
MODULE_LICENSE("GPL");
|