2010-03-16 08:46:46 +00:00
|
|
|
/***************************************************************************
|
|
|
|
*
|
|
|
|
* Copyright (C) 2007-2010 SMSC
|
|
|
|
*
|
|
|
|
* 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
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
|
|
*
|
|
|
|
*****************************************************************************/
|
|
|
|
|
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/kmod.h>
|
|
|
|
#include <linux/init.h>
|
|
|
|
#include <linux/netdevice.h>
|
|
|
|
#include <linux/etherdevice.h>
|
|
|
|
#include <linux/ethtool.h>
|
|
|
|
#include <linux/mii.h>
|
|
|
|
#include <linux/usb.h>
|
2012-10-30 07:46:32 +00:00
|
|
|
#include <linux/bitrev.h>
|
|
|
|
#include <linux/crc16.h>
|
2010-03-16 08:46:46 +00:00
|
|
|
#include <linux/crc32.h>
|
|
|
|
#include <linux/usb/usbnet.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 08:04:11 +00:00
|
|
|
#include <linux/slab.h>
|
2010-03-16 08:46:46 +00:00
|
|
|
#include "smsc75xx.h"
|
|
|
|
|
|
|
|
#define SMSC_CHIPNAME "smsc75xx"
|
|
|
|
#define SMSC_DRIVER_VERSION "1.0.0"
|
|
|
|
#define HS_USB_PKT_SIZE (512)
|
|
|
|
#define FS_USB_PKT_SIZE (64)
|
|
|
|
#define DEFAULT_HS_BURST_CAP_SIZE (16 * 1024 + 5 * HS_USB_PKT_SIZE)
|
|
|
|
#define DEFAULT_FS_BURST_CAP_SIZE (6 * 1024 + 33 * FS_USB_PKT_SIZE)
|
|
|
|
#define DEFAULT_BULK_IN_DELAY (0x00002000)
|
|
|
|
#define MAX_SINGLE_PACKET_SIZE (9000)
|
|
|
|
#define LAN75XX_EEPROM_MAGIC (0x7500)
|
|
|
|
#define EEPROM_MAC_OFFSET (0x01)
|
|
|
|
#define DEFAULT_TX_CSUM_ENABLE (true)
|
|
|
|
#define DEFAULT_RX_CSUM_ENABLE (true)
|
|
|
|
#define DEFAULT_TSO_ENABLE (true)
|
|
|
|
#define SMSC75XX_INTERNAL_PHY_ID (1)
|
|
|
|
#define SMSC75XX_TX_OVERHEAD (8)
|
|
|
|
#define MAX_RX_FIFO_SIZE (20 * 1024)
|
|
|
|
#define MAX_TX_FIFO_SIZE (12 * 1024)
|
|
|
|
#define USB_VENDOR_ID_SMSC (0x0424)
|
|
|
|
#define USB_PRODUCT_ID_LAN7500 (0x7500)
|
|
|
|
#define USB_PRODUCT_ID_LAN7505 (0x7505)
|
2011-11-08 07:30:40 +00:00
|
|
|
#define RXW_PADDING 2
|
2012-11-28 05:59:47 +00:00
|
|
|
#define SUPPORTED_WAKE (WAKE_PHY | WAKE_UCAST | WAKE_BCAST | \
|
2012-10-30 07:46:32 +00:00
|
|
|
WAKE_MCAST | WAKE_ARP | WAKE_MAGIC)
|
2010-03-16 08:46:46 +00:00
|
|
|
|
|
|
|
#define check_warn(ret, fmt, args...) \
|
|
|
|
({ if (ret < 0) netdev_warn(dev->net, fmt, ##args); })
|
|
|
|
|
|
|
|
#define check_warn_return(ret, fmt, args...) \
|
|
|
|
({ if (ret < 0) { netdev_warn(dev->net, fmt, ##args); return ret; } })
|
|
|
|
|
|
|
|
#define check_warn_goto_done(ret, fmt, args...) \
|
|
|
|
({ if (ret < 0) { netdev_warn(dev->net, fmt, ##args); goto done; } })
|
|
|
|
|
|
|
|
struct smsc75xx_priv {
|
|
|
|
struct usbnet *dev;
|
|
|
|
u32 rfe_ctl;
|
2012-09-28 00:57:53 +00:00
|
|
|
u32 wolopts;
|
2010-03-16 08:46:46 +00:00
|
|
|
u32 multicast_hash_table[DP_SEL_VHF_HASH_LEN];
|
|
|
|
struct mutex dataport_mutex;
|
|
|
|
spinlock_t rfe_ctl_lock;
|
|
|
|
struct work_struct set_multicast;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct usb_context {
|
|
|
|
struct usb_ctrlrequest req;
|
|
|
|
struct usbnet *dev;
|
|
|
|
};
|
|
|
|
|
2011-12-19 14:08:01 +00:00
|
|
|
static bool turbo_mode = true;
|
2010-03-16 08:46:46 +00:00
|
|
|
module_param(turbo_mode, bool, 0644);
|
|
|
|
MODULE_PARM_DESC(turbo_mode, "Enable multiple frames per Rx transaction");
|
|
|
|
|
2012-11-06 04:53:05 +00:00
|
|
|
static int __must_check __smsc75xx_read_reg(struct usbnet *dev, u32 index,
|
|
|
|
u32 *data, int in_pm)
|
2010-03-16 08:46:46 +00:00
|
|
|
{
|
2012-10-24 19:47:03 +00:00
|
|
|
u32 buf;
|
2010-03-16 08:46:46 +00:00
|
|
|
int ret;
|
2012-11-06 04:53:05 +00:00
|
|
|
int (*fn)(struct usbnet *, u8, u8, u16, u16, void *, u16);
|
2010-03-16 08:46:46 +00:00
|
|
|
|
|
|
|
BUG_ON(!dev);
|
|
|
|
|
2012-11-06 04:53:05 +00:00
|
|
|
if (!in_pm)
|
|
|
|
fn = usbnet_read_cmd;
|
|
|
|
else
|
|
|
|
fn = usbnet_read_cmd_nopm;
|
|
|
|
|
|
|
|
ret = fn(dev, USB_VENDOR_REQUEST_READ_REGISTER, USB_DIR_IN
|
|
|
|
| USB_TYPE_VENDOR | USB_RECIP_DEVICE,
|
|
|
|
0, index, &buf, 4);
|
2010-03-16 08:46:46 +00:00
|
|
|
if (unlikely(ret < 0))
|
2012-11-24 01:27:49 +00:00
|
|
|
netdev_warn(dev->net, "Failed to read reg index 0x%08x: %d\n",
|
|
|
|
index, ret);
|
2010-03-16 08:46:46 +00:00
|
|
|
|
2012-10-24 19:47:03 +00:00
|
|
|
le32_to_cpus(&buf);
|
|
|
|
*data = buf;
|
2010-03-16 08:46:46 +00:00
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2012-11-06 04:53:05 +00:00
|
|
|
static int __must_check __smsc75xx_write_reg(struct usbnet *dev, u32 index,
|
|
|
|
u32 data, int in_pm)
|
2010-03-16 08:46:46 +00:00
|
|
|
{
|
2012-10-24 19:47:03 +00:00
|
|
|
u32 buf;
|
2010-03-16 08:46:46 +00:00
|
|
|
int ret;
|
2012-11-06 04:53:05 +00:00
|
|
|
int (*fn)(struct usbnet *, u8, u8, u16, u16, const void *, u16);
|
2010-03-16 08:46:46 +00:00
|
|
|
|
|
|
|
BUG_ON(!dev);
|
|
|
|
|
2012-11-06 04:53:05 +00:00
|
|
|
if (!in_pm)
|
|
|
|
fn = usbnet_write_cmd;
|
|
|
|
else
|
|
|
|
fn = usbnet_write_cmd_nopm;
|
|
|
|
|
2012-10-24 19:47:03 +00:00
|
|
|
buf = data;
|
|
|
|
cpu_to_le32s(&buf);
|
2010-03-16 08:46:46 +00:00
|
|
|
|
2012-11-06 04:53:05 +00:00
|
|
|
ret = fn(dev, USB_VENDOR_REQUEST_WRITE_REGISTER, USB_DIR_OUT
|
|
|
|
| USB_TYPE_VENDOR | USB_RECIP_DEVICE,
|
|
|
|
0, index, &buf, 4);
|
2010-03-16 08:46:46 +00:00
|
|
|
if (unlikely(ret < 0))
|
2012-11-24 01:27:49 +00:00
|
|
|
netdev_warn(dev->net, "Failed to write reg index 0x%08x: %d\n",
|
|
|
|
index, ret);
|
2010-03-16 08:46:46 +00:00
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2012-11-06 04:53:05 +00:00
|
|
|
static int __must_check smsc75xx_read_reg_nopm(struct usbnet *dev, u32 index,
|
|
|
|
u32 *data)
|
|
|
|
{
|
|
|
|
return __smsc75xx_read_reg(dev, index, data, 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int __must_check smsc75xx_write_reg_nopm(struct usbnet *dev, u32 index,
|
|
|
|
u32 data)
|
|
|
|
{
|
|
|
|
return __smsc75xx_write_reg(dev, index, data, 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int __must_check smsc75xx_read_reg(struct usbnet *dev, u32 index,
|
|
|
|
u32 *data)
|
|
|
|
{
|
|
|
|
return __smsc75xx_read_reg(dev, index, data, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int __must_check smsc75xx_write_reg(struct usbnet *dev, u32 index,
|
|
|
|
u32 data)
|
|
|
|
{
|
|
|
|
return __smsc75xx_write_reg(dev, index, data, 0);
|
|
|
|
}
|
|
|
|
|
2012-09-28 00:57:53 +00:00
|
|
|
static int smsc75xx_set_feature(struct usbnet *dev, u32 feature)
|
|
|
|
{
|
|
|
|
if (WARN_ON_ONCE(!dev))
|
|
|
|
return -EINVAL;
|
|
|
|
|
2012-11-06 04:53:05 +00:00
|
|
|
return usbnet_write_cmd_nopm(dev, USB_REQ_SET_FEATURE,
|
|
|
|
USB_DIR_OUT | USB_RECIP_DEVICE,
|
|
|
|
feature, 0, NULL, 0);
|
2012-09-28 00:57:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int smsc75xx_clear_feature(struct usbnet *dev, u32 feature)
|
|
|
|
{
|
|
|
|
if (WARN_ON_ONCE(!dev))
|
|
|
|
return -EINVAL;
|
|
|
|
|
2012-11-06 04:53:05 +00:00
|
|
|
return usbnet_write_cmd_nopm(dev, USB_REQ_CLEAR_FEATURE,
|
|
|
|
USB_DIR_OUT | USB_RECIP_DEVICE,
|
|
|
|
feature, 0, NULL, 0);
|
2012-09-28 00:57:53 +00:00
|
|
|
}
|
|
|
|
|
2010-03-16 08:46:46 +00:00
|
|
|
/* Loop until the read is completed with timeout
|
|
|
|
* called with phy_mutex held */
|
2012-11-28 05:59:47 +00:00
|
|
|
static __must_check int __smsc75xx_phy_wait_not_busy(struct usbnet *dev,
|
|
|
|
int in_pm)
|
2010-03-16 08:46:46 +00:00
|
|
|
{
|
|
|
|
unsigned long start_time = jiffies;
|
|
|
|
u32 val;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
do {
|
2012-11-28 05:59:47 +00:00
|
|
|
ret = __smsc75xx_read_reg(dev, MII_ACCESS, &val, in_pm);
|
2012-11-24 01:27:49 +00:00
|
|
|
check_warn_return(ret, "Error reading MII_ACCESS\n");
|
2010-03-16 08:46:46 +00:00
|
|
|
|
|
|
|
if (!(val & MII_ACCESS_BUSY))
|
|
|
|
return 0;
|
|
|
|
} while (!time_after(jiffies, start_time + HZ));
|
|
|
|
|
|
|
|
return -EIO;
|
|
|
|
}
|
|
|
|
|
2012-11-28 05:59:47 +00:00
|
|
|
static int __smsc75xx_mdio_read(struct net_device *netdev, int phy_id, int idx,
|
|
|
|
int in_pm)
|
2010-03-16 08:46:46 +00:00
|
|
|
{
|
|
|
|
struct usbnet *dev = netdev_priv(netdev);
|
|
|
|
u32 val, addr;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
mutex_lock(&dev->phy_mutex);
|
|
|
|
|
|
|
|
/* confirm MII not busy */
|
2012-11-28 05:59:47 +00:00
|
|
|
ret = __smsc75xx_phy_wait_not_busy(dev, in_pm);
|
2012-11-24 01:27:49 +00:00
|
|
|
check_warn_goto_done(ret, "MII is busy in smsc75xx_mdio_read\n");
|
2010-03-16 08:46:46 +00:00
|
|
|
|
|
|
|
/* set the address, index & direction (read from PHY) */
|
|
|
|
phy_id &= dev->mii.phy_id_mask;
|
|
|
|
idx &= dev->mii.reg_num_mask;
|
|
|
|
addr = ((phy_id << MII_ACCESS_PHY_ADDR_SHIFT) & MII_ACCESS_PHY_ADDR)
|
|
|
|
| ((idx << MII_ACCESS_REG_ADDR_SHIFT) & MII_ACCESS_REG_ADDR)
|
2012-04-30 07:56:51 +00:00
|
|
|
| MII_ACCESS_READ | MII_ACCESS_BUSY;
|
2012-11-28 05:59:47 +00:00
|
|
|
ret = __smsc75xx_write_reg(dev, MII_ACCESS, addr, in_pm);
|
2012-11-24 01:27:49 +00:00
|
|
|
check_warn_goto_done(ret, "Error writing MII_ACCESS\n");
|
2010-03-16 08:46:46 +00:00
|
|
|
|
2012-11-28 05:59:47 +00:00
|
|
|
ret = __smsc75xx_phy_wait_not_busy(dev, in_pm);
|
2012-11-24 01:27:49 +00:00
|
|
|
check_warn_goto_done(ret, "Timed out reading MII reg %02X\n", idx);
|
2010-03-16 08:46:46 +00:00
|
|
|
|
2012-11-28 05:59:47 +00:00
|
|
|
ret = __smsc75xx_read_reg(dev, MII_DATA, &val, in_pm);
|
2012-11-24 01:27:49 +00:00
|
|
|
check_warn_goto_done(ret, "Error reading MII_DATA\n");
|
2010-03-16 08:46:46 +00:00
|
|
|
|
|
|
|
ret = (u16)(val & 0xFFFF);
|
|
|
|
|
|
|
|
done:
|
|
|
|
mutex_unlock(&dev->phy_mutex);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2012-11-28 05:59:47 +00:00
|
|
|
static void __smsc75xx_mdio_write(struct net_device *netdev, int phy_id,
|
|
|
|
int idx, int regval, int in_pm)
|
2010-03-16 08:46:46 +00:00
|
|
|
{
|
|
|
|
struct usbnet *dev = netdev_priv(netdev);
|
|
|
|
u32 val, addr;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
mutex_lock(&dev->phy_mutex);
|
|
|
|
|
|
|
|
/* confirm MII not busy */
|
2012-11-28 05:59:47 +00:00
|
|
|
ret = __smsc75xx_phy_wait_not_busy(dev, in_pm);
|
2012-11-24 01:27:49 +00:00
|
|
|
check_warn_goto_done(ret, "MII is busy in smsc75xx_mdio_write\n");
|
2010-03-16 08:46:46 +00:00
|
|
|
|
|
|
|
val = regval;
|
2012-11-28 05:59:47 +00:00
|
|
|
ret = __smsc75xx_write_reg(dev, MII_DATA, val, in_pm);
|
2012-11-24 01:27:49 +00:00
|
|
|
check_warn_goto_done(ret, "Error writing MII_DATA\n");
|
2010-03-16 08:46:46 +00:00
|
|
|
|
|
|
|
/* set the address, index & direction (write to PHY) */
|
|
|
|
phy_id &= dev->mii.phy_id_mask;
|
|
|
|
idx &= dev->mii.reg_num_mask;
|
|
|
|
addr = ((phy_id << MII_ACCESS_PHY_ADDR_SHIFT) & MII_ACCESS_PHY_ADDR)
|
|
|
|
| ((idx << MII_ACCESS_REG_ADDR_SHIFT) & MII_ACCESS_REG_ADDR)
|
2012-04-30 07:56:51 +00:00
|
|
|
| MII_ACCESS_WRITE | MII_ACCESS_BUSY;
|
2012-11-28 05:59:47 +00:00
|
|
|
ret = __smsc75xx_write_reg(dev, MII_ACCESS, addr, in_pm);
|
2012-11-24 01:27:49 +00:00
|
|
|
check_warn_goto_done(ret, "Error writing MII_ACCESS\n");
|
2010-03-16 08:46:46 +00:00
|
|
|
|
2012-11-28 05:59:47 +00:00
|
|
|
ret = __smsc75xx_phy_wait_not_busy(dev, in_pm);
|
2012-11-24 01:27:49 +00:00
|
|
|
check_warn_goto_done(ret, "Timed out writing MII reg %02X\n", idx);
|
2010-03-16 08:46:46 +00:00
|
|
|
|
|
|
|
done:
|
|
|
|
mutex_unlock(&dev->phy_mutex);
|
|
|
|
}
|
|
|
|
|
2012-11-28 05:59:47 +00:00
|
|
|
static int smsc75xx_mdio_read_nopm(struct net_device *netdev, int phy_id,
|
|
|
|
int idx)
|
|
|
|
{
|
|
|
|
return __smsc75xx_mdio_read(netdev, phy_id, idx, 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void smsc75xx_mdio_write_nopm(struct net_device *netdev, int phy_id,
|
|
|
|
int idx, int regval)
|
|
|
|
{
|
|
|
|
__smsc75xx_mdio_write(netdev, phy_id, idx, regval, 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int smsc75xx_mdio_read(struct net_device *netdev, int phy_id, int idx)
|
|
|
|
{
|
|
|
|
return __smsc75xx_mdio_read(netdev, phy_id, idx, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void smsc75xx_mdio_write(struct net_device *netdev, int phy_id, int idx,
|
|
|
|
int regval)
|
|
|
|
{
|
|
|
|
__smsc75xx_mdio_write(netdev, phy_id, idx, regval, 0);
|
|
|
|
}
|
|
|
|
|
2010-03-16 08:46:46 +00:00
|
|
|
static int smsc75xx_wait_eeprom(struct usbnet *dev)
|
|
|
|
{
|
|
|
|
unsigned long start_time = jiffies;
|
|
|
|
u32 val;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
do {
|
|
|
|
ret = smsc75xx_read_reg(dev, E2P_CMD, &val);
|
2012-11-24 01:27:49 +00:00
|
|
|
check_warn_return(ret, "Error reading E2P_CMD\n");
|
2010-03-16 08:46:46 +00:00
|
|
|
|
|
|
|
if (!(val & E2P_CMD_BUSY) || (val & E2P_CMD_TIMEOUT))
|
|
|
|
break;
|
|
|
|
udelay(40);
|
|
|
|
} while (!time_after(jiffies, start_time + HZ));
|
|
|
|
|
|
|
|
if (val & (E2P_CMD_TIMEOUT | E2P_CMD_BUSY)) {
|
2012-11-24 01:27:49 +00:00
|
|
|
netdev_warn(dev->net, "EEPROM read operation timeout\n");
|
2010-03-16 08:46:46 +00:00
|
|
|
return -EIO;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int smsc75xx_eeprom_confirm_not_busy(struct usbnet *dev)
|
|
|
|
{
|
|
|
|
unsigned long start_time = jiffies;
|
|
|
|
u32 val;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
do {
|
|
|
|
ret = smsc75xx_read_reg(dev, E2P_CMD, &val);
|
2012-11-24 01:27:49 +00:00
|
|
|
check_warn_return(ret, "Error reading E2P_CMD\n");
|
2010-03-16 08:46:46 +00:00
|
|
|
|
|
|
|
if (!(val & E2P_CMD_BUSY))
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
udelay(40);
|
|
|
|
} while (!time_after(jiffies, start_time + HZ));
|
|
|
|
|
2012-11-24 01:27:49 +00:00
|
|
|
netdev_warn(dev->net, "EEPROM is busy\n");
|
2010-03-16 08:46:46 +00:00
|
|
|
return -EIO;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int smsc75xx_read_eeprom(struct usbnet *dev, u32 offset, u32 length,
|
|
|
|
u8 *data)
|
|
|
|
{
|
|
|
|
u32 val;
|
|
|
|
int i, ret;
|
|
|
|
|
|
|
|
BUG_ON(!dev);
|
|
|
|
BUG_ON(!data);
|
|
|
|
|
|
|
|
ret = smsc75xx_eeprom_confirm_not_busy(dev);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
for (i = 0; i < length; i++) {
|
|
|
|
val = E2P_CMD_BUSY | E2P_CMD_READ | (offset & E2P_CMD_ADDR);
|
|
|
|
ret = smsc75xx_write_reg(dev, E2P_CMD, val);
|
2012-11-24 01:27:49 +00:00
|
|
|
check_warn_return(ret, "Error writing E2P_CMD\n");
|
2010-03-16 08:46:46 +00:00
|
|
|
|
|
|
|
ret = smsc75xx_wait_eeprom(dev);
|
|
|
|
if (ret < 0)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
ret = smsc75xx_read_reg(dev, E2P_DATA, &val);
|
2012-11-24 01:27:49 +00:00
|
|
|
check_warn_return(ret, "Error reading E2P_DATA\n");
|
2010-03-16 08:46:46 +00:00
|
|
|
|
|
|
|
data[i] = val & 0xFF;
|
|
|
|
offset++;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int smsc75xx_write_eeprom(struct usbnet *dev, u32 offset, u32 length,
|
|
|
|
u8 *data)
|
|
|
|
{
|
|
|
|
u32 val;
|
|
|
|
int i, ret;
|
|
|
|
|
|
|
|
BUG_ON(!dev);
|
|
|
|
BUG_ON(!data);
|
|
|
|
|
|
|
|
ret = smsc75xx_eeprom_confirm_not_busy(dev);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
/* Issue write/erase enable command */
|
|
|
|
val = E2P_CMD_BUSY | E2P_CMD_EWEN;
|
|
|
|
ret = smsc75xx_write_reg(dev, E2P_CMD, val);
|
2012-11-24 01:27:49 +00:00
|
|
|
check_warn_return(ret, "Error writing E2P_CMD\n");
|
2010-03-16 08:46:46 +00:00
|
|
|
|
|
|
|
ret = smsc75xx_wait_eeprom(dev);
|
|
|
|
if (ret < 0)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
for (i = 0; i < length; i++) {
|
|
|
|
|
|
|
|
/* Fill data register */
|
|
|
|
val = data[i];
|
|
|
|
ret = smsc75xx_write_reg(dev, E2P_DATA, val);
|
2012-11-24 01:27:49 +00:00
|
|
|
check_warn_return(ret, "Error writing E2P_DATA\n");
|
2010-03-16 08:46:46 +00:00
|
|
|
|
|
|
|
/* Send "write" command */
|
|
|
|
val = E2P_CMD_BUSY | E2P_CMD_WRITE | (offset & E2P_CMD_ADDR);
|
|
|
|
ret = smsc75xx_write_reg(dev, E2P_CMD, val);
|
2012-11-24 01:27:49 +00:00
|
|
|
check_warn_return(ret, "Error writing E2P_CMD\n");
|
2010-03-16 08:46:46 +00:00
|
|
|
|
|
|
|
ret = smsc75xx_wait_eeprom(dev);
|
|
|
|
if (ret < 0)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
offset++;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int smsc75xx_dataport_wait_not_busy(struct usbnet *dev)
|
|
|
|
{
|
|
|
|
int i, ret;
|
|
|
|
|
|
|
|
for (i = 0; i < 100; i++) {
|
|
|
|
u32 dp_sel;
|
|
|
|
ret = smsc75xx_read_reg(dev, DP_SEL, &dp_sel);
|
2012-11-24 01:27:49 +00:00
|
|
|
check_warn_return(ret, "Error reading DP_SEL\n");
|
2010-03-16 08:46:46 +00:00
|
|
|
|
|
|
|
if (dp_sel & DP_SEL_DPRDY)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
udelay(40);
|
|
|
|
}
|
|
|
|
|
2012-11-24 01:27:49 +00:00
|
|
|
netdev_warn(dev->net, "smsc75xx_dataport_wait_not_busy timed out\n");
|
2010-03-16 08:46:46 +00:00
|
|
|
|
|
|
|
return -EIO;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int smsc75xx_dataport_write(struct usbnet *dev, u32 ram_select, u32 addr,
|
|
|
|
u32 length, u32 *buf)
|
|
|
|
{
|
|
|
|
struct smsc75xx_priv *pdata = (struct smsc75xx_priv *)(dev->data[0]);
|
|
|
|
u32 dp_sel;
|
|
|
|
int i, ret;
|
|
|
|
|
|
|
|
mutex_lock(&pdata->dataport_mutex);
|
|
|
|
|
|
|
|
ret = smsc75xx_dataport_wait_not_busy(dev);
|
2012-11-24 01:27:49 +00:00
|
|
|
check_warn_goto_done(ret, "smsc75xx_dataport_write busy on entry\n");
|
2010-03-16 08:46:46 +00:00
|
|
|
|
|
|
|
ret = smsc75xx_read_reg(dev, DP_SEL, &dp_sel);
|
2012-11-24 01:27:49 +00:00
|
|
|
check_warn_goto_done(ret, "Error reading DP_SEL\n");
|
2010-03-16 08:46:46 +00:00
|
|
|
|
|
|
|
dp_sel &= ~DP_SEL_RSEL;
|
|
|
|
dp_sel |= ram_select;
|
|
|
|
ret = smsc75xx_write_reg(dev, DP_SEL, dp_sel);
|
2012-11-24 01:27:49 +00:00
|
|
|
check_warn_goto_done(ret, "Error writing DP_SEL\n");
|
2010-03-16 08:46:46 +00:00
|
|
|
|
|
|
|
for (i = 0; i < length; i++) {
|
|
|
|
ret = smsc75xx_write_reg(dev, DP_ADDR, addr + i);
|
2012-11-24 01:27:49 +00:00
|
|
|
check_warn_goto_done(ret, "Error writing DP_ADDR\n");
|
2010-03-16 08:46:46 +00:00
|
|
|
|
|
|
|
ret = smsc75xx_write_reg(dev, DP_DATA, buf[i]);
|
2012-11-24 01:27:49 +00:00
|
|
|
check_warn_goto_done(ret, "Error writing DP_DATA\n");
|
2010-03-16 08:46:46 +00:00
|
|
|
|
|
|
|
ret = smsc75xx_write_reg(dev, DP_CMD, DP_CMD_WRITE);
|
2012-11-24 01:27:49 +00:00
|
|
|
check_warn_goto_done(ret, "Error writing DP_CMD\n");
|
2010-03-16 08:46:46 +00:00
|
|
|
|
|
|
|
ret = smsc75xx_dataport_wait_not_busy(dev);
|
2012-11-24 01:27:49 +00:00
|
|
|
check_warn_goto_done(ret, "smsc75xx_dataport_write timeout\n");
|
2010-03-16 08:46:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
done:
|
|
|
|
mutex_unlock(&pdata->dataport_mutex);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* returns hash bit number for given MAC address */
|
|
|
|
static u32 smsc75xx_hash(char addr[ETH_ALEN])
|
|
|
|
{
|
|
|
|
return (ether_crc(ETH_ALEN, addr) >> 23) & 0x1ff;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void smsc75xx_deferred_multicast_write(struct work_struct *param)
|
|
|
|
{
|
|
|
|
struct smsc75xx_priv *pdata =
|
|
|
|
container_of(param, struct smsc75xx_priv, set_multicast);
|
|
|
|
struct usbnet *dev = pdata->dev;
|
|
|
|
int ret;
|
|
|
|
|
2012-11-24 01:27:49 +00:00
|
|
|
netif_dbg(dev, drv, dev->net, "deferred multicast write 0x%08x\n",
|
|
|
|
pdata->rfe_ctl);
|
2010-03-16 08:46:46 +00:00
|
|
|
|
|
|
|
smsc75xx_dataport_write(dev, DP_SEL_VHF, DP_SEL_VHF_VLAN_LEN,
|
|
|
|
DP_SEL_VHF_HASH_LEN, pdata->multicast_hash_table);
|
|
|
|
|
|
|
|
ret = smsc75xx_write_reg(dev, RFE_CTL, pdata->rfe_ctl);
|
2012-11-24 01:27:49 +00:00
|
|
|
check_warn(ret, "Error writing RFE_CRL\n");
|
2010-03-16 08:46:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void smsc75xx_set_multicast(struct net_device *netdev)
|
|
|
|
{
|
|
|
|
struct usbnet *dev = netdev_priv(netdev);
|
|
|
|
struct smsc75xx_priv *pdata = (struct smsc75xx_priv *)(dev->data[0]);
|
|
|
|
unsigned long flags;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
spin_lock_irqsave(&pdata->rfe_ctl_lock, flags);
|
|
|
|
|
|
|
|
pdata->rfe_ctl &=
|
|
|
|
~(RFE_CTL_AU | RFE_CTL_AM | RFE_CTL_DPF | RFE_CTL_MHF);
|
|
|
|
pdata->rfe_ctl |= RFE_CTL_AB;
|
|
|
|
|
|
|
|
for (i = 0; i < DP_SEL_VHF_HASH_LEN; i++)
|
|
|
|
pdata->multicast_hash_table[i] = 0;
|
|
|
|
|
|
|
|
if (dev->net->flags & IFF_PROMISC) {
|
2012-11-24 01:27:49 +00:00
|
|
|
netif_dbg(dev, drv, dev->net, "promiscuous mode enabled\n");
|
2010-03-16 08:46:46 +00:00
|
|
|
pdata->rfe_ctl |= RFE_CTL_AM | RFE_CTL_AU;
|
|
|
|
} else if (dev->net->flags & IFF_ALLMULTI) {
|
2012-11-24 01:27:49 +00:00
|
|
|
netif_dbg(dev, drv, dev->net, "receive all multicast enabled\n");
|
2010-03-16 08:46:46 +00:00
|
|
|
pdata->rfe_ctl |= RFE_CTL_AM | RFE_CTL_DPF;
|
|
|
|
} else if (!netdev_mc_empty(dev->net)) {
|
2010-04-01 21:22:57 +00:00
|
|
|
struct netdev_hw_addr *ha;
|
2010-03-16 08:46:46 +00:00
|
|
|
|
2012-11-24 01:27:49 +00:00
|
|
|
netif_dbg(dev, drv, dev->net, "receive multicast hash filter\n");
|
2010-03-16 08:46:46 +00:00
|
|
|
|
|
|
|
pdata->rfe_ctl |= RFE_CTL_MHF | RFE_CTL_DPF;
|
|
|
|
|
2010-04-01 21:22:57 +00:00
|
|
|
netdev_for_each_mc_addr(ha, netdev) {
|
|
|
|
u32 bitnum = smsc75xx_hash(ha->addr);
|
2010-03-16 08:46:46 +00:00
|
|
|
pdata->multicast_hash_table[bitnum / 32] |=
|
|
|
|
(1 << (bitnum % 32));
|
|
|
|
}
|
|
|
|
} else {
|
2012-11-24 01:27:49 +00:00
|
|
|
netif_dbg(dev, drv, dev->net, "receive own packets only\n");
|
2010-03-16 08:46:46 +00:00
|
|
|
pdata->rfe_ctl |= RFE_CTL_DPF;
|
|
|
|
}
|
|
|
|
|
|
|
|
spin_unlock_irqrestore(&pdata->rfe_ctl_lock, flags);
|
|
|
|
|
|
|
|
/* defer register writes to a sleepable context */
|
|
|
|
schedule_work(&pdata->set_multicast);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int smsc75xx_update_flowcontrol(struct usbnet *dev, u8 duplex,
|
|
|
|
u16 lcladv, u16 rmtadv)
|
|
|
|
{
|
|
|
|
u32 flow = 0, fct_flow = 0;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
if (duplex == DUPLEX_FULL) {
|
|
|
|
u8 cap = mii_resolve_flowctrl_fdx(lcladv, rmtadv);
|
|
|
|
|
|
|
|
if (cap & FLOW_CTRL_TX) {
|
|
|
|
flow = (FLOW_TX_FCEN | 0xFFFF);
|
|
|
|
/* set fct_flow thresholds to 20% and 80% */
|
|
|
|
fct_flow = (8 << 8) | 32;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (cap & FLOW_CTRL_RX)
|
|
|
|
flow |= FLOW_RX_FCEN;
|
|
|
|
|
2012-11-24 01:27:49 +00:00
|
|
|
netif_dbg(dev, link, dev->net, "rx pause %s, tx pause %s\n",
|
|
|
|
(cap & FLOW_CTRL_RX ? "enabled" : "disabled"),
|
|
|
|
(cap & FLOW_CTRL_TX ? "enabled" : "disabled"));
|
2010-03-16 08:46:46 +00:00
|
|
|
} else {
|
2012-11-24 01:27:49 +00:00
|
|
|
netif_dbg(dev, link, dev->net, "half duplex\n");
|
2010-03-16 08:46:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ret = smsc75xx_write_reg(dev, FLOW, flow);
|
2012-11-24 01:27:49 +00:00
|
|
|
check_warn_return(ret, "Error writing FLOW\n");
|
2010-03-16 08:46:46 +00:00
|
|
|
|
|
|
|
ret = smsc75xx_write_reg(dev, FCT_FLOW, fct_flow);
|
2012-11-24 01:27:49 +00:00
|
|
|
check_warn_return(ret, "Error writing FCT_FLOW\n");
|
2010-03-16 08:46:46 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int smsc75xx_link_reset(struct usbnet *dev)
|
|
|
|
{
|
|
|
|
struct mii_if_info *mii = &dev->mii;
|
2011-04-27 18:32:38 +00:00
|
|
|
struct ethtool_cmd ecmd = { .cmd = ETHTOOL_GSET };
|
2010-03-16 08:46:46 +00:00
|
|
|
u16 lcladv, rmtadv;
|
|
|
|
int ret;
|
|
|
|
|
2012-05-04 00:57:12 +00:00
|
|
|
/* write to clear phy interrupt status */
|
2012-05-04 00:57:11 +00:00
|
|
|
smsc75xx_mdio_write(dev->net, mii->phy_id, PHY_INT_SRC,
|
|
|
|
PHY_INT_SRC_CLEAR_ALL);
|
2010-03-16 08:46:46 +00:00
|
|
|
|
|
|
|
ret = smsc75xx_write_reg(dev, INT_STS, INT_STS_CLEAR_ALL);
|
2012-11-24 01:27:49 +00:00
|
|
|
check_warn_return(ret, "Error writing INT_STS\n");
|
2010-03-16 08:46:46 +00:00
|
|
|
|
|
|
|
mii_check_media(mii, 1, 1);
|
|
|
|
mii_ethtool_gset(&dev->mii, &ecmd);
|
|
|
|
lcladv = smsc75xx_mdio_read(dev->net, mii->phy_id, MII_ADVERTISE);
|
|
|
|
rmtadv = smsc75xx_mdio_read(dev->net, mii->phy_id, MII_LPA);
|
|
|
|
|
2012-11-24 01:27:49 +00:00
|
|
|
netif_dbg(dev, link, dev->net, "speed: %u duplex: %d lcladv: %04x rmtadv: %04x\n",
|
|
|
|
ethtool_cmd_speed(&ecmd), ecmd.duplex, lcladv, rmtadv);
|
2010-03-16 08:46:46 +00:00
|
|
|
|
|
|
|
return smsc75xx_update_flowcontrol(dev, ecmd.duplex, lcladv, rmtadv);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void smsc75xx_status(struct usbnet *dev, struct urb *urb)
|
|
|
|
{
|
|
|
|
u32 intdata;
|
|
|
|
|
|
|
|
if (urb->actual_length != 4) {
|
2012-11-24 01:27:49 +00:00
|
|
|
netdev_warn(dev->net, "unexpected urb length %d\n",
|
|
|
|
urb->actual_length);
|
2010-03-16 08:46:46 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
memcpy(&intdata, urb->transfer_buffer, 4);
|
|
|
|
le32_to_cpus(&intdata);
|
|
|
|
|
2012-11-24 01:27:49 +00:00
|
|
|
netif_dbg(dev, link, dev->net, "intdata: 0x%08X\n", intdata);
|
2010-03-16 08:46:46 +00:00
|
|
|
|
|
|
|
if (intdata & INT_ENP_PHY_INT)
|
|
|
|
usbnet_defer_kevent(dev, EVENT_LINK_RESET);
|
|
|
|
else
|
2012-11-24 01:27:49 +00:00
|
|
|
netdev_warn(dev->net, "unexpected interrupt, intdata=0x%08X\n",
|
|
|
|
intdata);
|
2010-03-16 08:46:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int smsc75xx_ethtool_get_eeprom_len(struct net_device *net)
|
|
|
|
{
|
|
|
|
return MAX_EEPROM_SIZE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int smsc75xx_ethtool_get_eeprom(struct net_device *netdev,
|
|
|
|
struct ethtool_eeprom *ee, u8 *data)
|
|
|
|
{
|
|
|
|
struct usbnet *dev = netdev_priv(netdev);
|
|
|
|
|
|
|
|
ee->magic = LAN75XX_EEPROM_MAGIC;
|
|
|
|
|
|
|
|
return smsc75xx_read_eeprom(dev, ee->offset, ee->len, data);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int smsc75xx_ethtool_set_eeprom(struct net_device *netdev,
|
|
|
|
struct ethtool_eeprom *ee, u8 *data)
|
|
|
|
{
|
|
|
|
struct usbnet *dev = netdev_priv(netdev);
|
|
|
|
|
|
|
|
if (ee->magic != LAN75XX_EEPROM_MAGIC) {
|
2012-11-24 01:27:49 +00:00
|
|
|
netdev_warn(dev->net, "EEPROM: magic value mismatch: 0x%x\n",
|
|
|
|
ee->magic);
|
2010-03-16 08:46:46 +00:00
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return smsc75xx_write_eeprom(dev, ee->offset, ee->len, data);
|
|
|
|
}
|
|
|
|
|
2012-09-28 00:57:53 +00:00
|
|
|
static void smsc75xx_ethtool_get_wol(struct net_device *net,
|
|
|
|
struct ethtool_wolinfo *wolinfo)
|
|
|
|
{
|
|
|
|
struct usbnet *dev = netdev_priv(net);
|
|
|
|
struct smsc75xx_priv *pdata = (struct smsc75xx_priv *)(dev->data[0]);
|
|
|
|
|
|
|
|
wolinfo->supported = SUPPORTED_WAKE;
|
|
|
|
wolinfo->wolopts = pdata->wolopts;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int smsc75xx_ethtool_set_wol(struct net_device *net,
|
|
|
|
struct ethtool_wolinfo *wolinfo)
|
|
|
|
{
|
|
|
|
struct usbnet *dev = netdev_priv(net);
|
|
|
|
struct smsc75xx_priv *pdata = (struct smsc75xx_priv *)(dev->data[0]);
|
|
|
|
|
|
|
|
pdata->wolopts = wolinfo->wolopts & SUPPORTED_WAKE;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2010-03-16 08:46:46 +00:00
|
|
|
static const struct ethtool_ops smsc75xx_ethtool_ops = {
|
|
|
|
.get_link = usbnet_get_link,
|
|
|
|
.nway_reset = usbnet_nway_reset,
|
|
|
|
.get_drvinfo = usbnet_get_drvinfo,
|
|
|
|
.get_msglevel = usbnet_get_msglevel,
|
|
|
|
.set_msglevel = usbnet_set_msglevel,
|
|
|
|
.get_settings = usbnet_get_settings,
|
|
|
|
.set_settings = usbnet_set_settings,
|
|
|
|
.get_eeprom_len = smsc75xx_ethtool_get_eeprom_len,
|
|
|
|
.get_eeprom = smsc75xx_ethtool_get_eeprom,
|
|
|
|
.set_eeprom = smsc75xx_ethtool_set_eeprom,
|
2012-09-28 00:57:53 +00:00
|
|
|
.get_wol = smsc75xx_ethtool_get_wol,
|
|
|
|
.set_wol = smsc75xx_ethtool_set_wol,
|
2010-03-16 08:46:46 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static int smsc75xx_ioctl(struct net_device *netdev, struct ifreq *rq, int cmd)
|
|
|
|
{
|
|
|
|
struct usbnet *dev = netdev_priv(netdev);
|
|
|
|
|
|
|
|
if (!netif_running(netdev))
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
return generic_mii_ioctl(&dev->mii, if_mii(rq), cmd, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void smsc75xx_init_mac_address(struct usbnet *dev)
|
|
|
|
{
|
|
|
|
/* try reading mac address from EEPROM */
|
|
|
|
if (smsc75xx_read_eeprom(dev, EEPROM_MAC_OFFSET, ETH_ALEN,
|
|
|
|
dev->net->dev_addr) == 0) {
|
|
|
|
if (is_valid_ether_addr(dev->net->dev_addr)) {
|
|
|
|
/* eeprom values are valid so use them */
|
|
|
|
netif_dbg(dev, ifup, dev->net,
|
2012-11-24 01:27:49 +00:00
|
|
|
"MAC address read from EEPROM\n");
|
2010-03-16 08:46:46 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* no eeprom, or eeprom values are invalid. generate random MAC */
|
2012-02-15 06:45:39 +00:00
|
|
|
eth_hw_addr_random(dev->net);
|
2012-11-24 01:27:49 +00:00
|
|
|
netif_dbg(dev, ifup, dev->net, "MAC address set to eth_random_addr\n");
|
2010-03-16 08:46:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int smsc75xx_set_mac_address(struct usbnet *dev)
|
|
|
|
{
|
|
|
|
u32 addr_lo = dev->net->dev_addr[0] | dev->net->dev_addr[1] << 8 |
|
|
|
|
dev->net->dev_addr[2] << 16 | dev->net->dev_addr[3] << 24;
|
|
|
|
u32 addr_hi = dev->net->dev_addr[4] | dev->net->dev_addr[5] << 8;
|
|
|
|
|
|
|
|
int ret = smsc75xx_write_reg(dev, RX_ADDRH, addr_hi);
|
2012-11-24 01:27:49 +00:00
|
|
|
check_warn_return(ret, "Failed to write RX_ADDRH: %d\n", ret);
|
2010-03-16 08:46:46 +00:00
|
|
|
|
|
|
|
ret = smsc75xx_write_reg(dev, RX_ADDRL, addr_lo);
|
2012-11-24 01:27:49 +00:00
|
|
|
check_warn_return(ret, "Failed to write RX_ADDRL: %d\n", ret);
|
2010-03-16 08:46:46 +00:00
|
|
|
|
|
|
|
addr_hi |= ADDR_FILTX_FB_VALID;
|
|
|
|
ret = smsc75xx_write_reg(dev, ADDR_FILTX, addr_hi);
|
2012-11-24 01:27:49 +00:00
|
|
|
check_warn_return(ret, "Failed to write ADDR_FILTX: %d\n", ret);
|
2010-03-16 08:46:46 +00:00
|
|
|
|
|
|
|
ret = smsc75xx_write_reg(dev, ADDR_FILTX + 4, addr_lo);
|
2012-11-24 01:27:49 +00:00
|
|
|
check_warn_return(ret, "Failed to write ADDR_FILTX+4: %d\n", ret);
|
2010-03-16 08:46:46 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int smsc75xx_phy_initialize(struct usbnet *dev)
|
|
|
|
{
|
2012-04-30 07:56:54 +00:00
|
|
|
int bmcr, ret, timeout = 0;
|
2010-03-16 08:46:46 +00:00
|
|
|
|
|
|
|
/* Initialize MII structure */
|
|
|
|
dev->mii.dev = dev->net;
|
|
|
|
dev->mii.mdio_read = smsc75xx_mdio_read;
|
|
|
|
dev->mii.mdio_write = smsc75xx_mdio_write;
|
|
|
|
dev->mii.phy_id_mask = 0x1f;
|
|
|
|
dev->mii.reg_num_mask = 0x1f;
|
2012-04-30 07:56:55 +00:00
|
|
|
dev->mii.supports_gmii = 1;
|
2010-03-16 08:46:46 +00:00
|
|
|
dev->mii.phy_id = SMSC75XX_INTERNAL_PHY_ID;
|
|
|
|
|
|
|
|
/* reset phy and wait for reset to complete */
|
|
|
|
smsc75xx_mdio_write(dev->net, dev->mii.phy_id, MII_BMCR, BMCR_RESET);
|
|
|
|
|
|
|
|
do {
|
|
|
|
msleep(10);
|
|
|
|
bmcr = smsc75xx_mdio_read(dev->net, dev->mii.phy_id, MII_BMCR);
|
2012-11-24 01:27:49 +00:00
|
|
|
check_warn_return(bmcr, "Error reading MII_BMCR\n");
|
2010-03-16 08:46:46 +00:00
|
|
|
timeout++;
|
2012-04-30 07:56:53 +00:00
|
|
|
} while ((bmcr & BMCR_RESET) && (timeout < 100));
|
2010-03-16 08:46:46 +00:00
|
|
|
|
|
|
|
if (timeout >= 100) {
|
2012-11-24 01:27:49 +00:00
|
|
|
netdev_warn(dev->net, "timeout on PHY Reset\n");
|
2010-03-16 08:46:46 +00:00
|
|
|
return -EIO;
|
|
|
|
}
|
|
|
|
|
|
|
|
smsc75xx_mdio_write(dev->net, dev->mii.phy_id, MII_ADVERTISE,
|
|
|
|
ADVERTISE_ALL | ADVERTISE_CSMA | ADVERTISE_PAUSE_CAP |
|
|
|
|
ADVERTISE_PAUSE_ASYM);
|
2012-04-30 07:56:55 +00:00
|
|
|
smsc75xx_mdio_write(dev->net, dev->mii.phy_id, MII_CTRL1000,
|
|
|
|
ADVERTISE_1000FULL);
|
2010-03-16 08:46:46 +00:00
|
|
|
|
2012-04-30 07:56:54 +00:00
|
|
|
/* read and write to clear phy interrupt status */
|
|
|
|
ret = smsc75xx_mdio_read(dev->net, dev->mii.phy_id, PHY_INT_SRC);
|
2012-11-24 01:27:49 +00:00
|
|
|
check_warn_return(ret, "Error reading PHY_INT_SRC\n");
|
2012-04-30 07:56:54 +00:00
|
|
|
smsc75xx_mdio_write(dev->net, dev->mii.phy_id, PHY_INT_SRC, 0xffff);
|
2010-03-16 08:46:46 +00:00
|
|
|
|
|
|
|
smsc75xx_mdio_write(dev->net, dev->mii.phy_id, PHY_INT_MASK,
|
|
|
|
PHY_INT_MASK_DEFAULT);
|
|
|
|
mii_nway_restart(&dev->mii);
|
|
|
|
|
2012-11-24 01:27:49 +00:00
|
|
|
netif_dbg(dev, ifup, dev->net, "phy initialised successfully\n");
|
2010-03-16 08:46:46 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int smsc75xx_set_rx_max_frame_length(struct usbnet *dev, int size)
|
|
|
|
{
|
|
|
|
int ret = 0;
|
|
|
|
u32 buf;
|
|
|
|
bool rxenabled;
|
|
|
|
|
|
|
|
ret = smsc75xx_read_reg(dev, MAC_RX, &buf);
|
2012-11-24 01:27:49 +00:00
|
|
|
check_warn_return(ret, "Failed to read MAC_RX: %d\n", ret);
|
2010-03-16 08:46:46 +00:00
|
|
|
|
|
|
|
rxenabled = ((buf & MAC_RX_RXEN) != 0);
|
|
|
|
|
|
|
|
if (rxenabled) {
|
|
|
|
buf &= ~MAC_RX_RXEN;
|
|
|
|
ret = smsc75xx_write_reg(dev, MAC_RX, buf);
|
2012-11-24 01:27:49 +00:00
|
|
|
check_warn_return(ret, "Failed to write MAC_RX: %d\n", ret);
|
2010-03-16 08:46:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* add 4 to size for FCS */
|
|
|
|
buf &= ~MAC_RX_MAX_SIZE;
|
|
|
|
buf |= (((size + 4) << MAC_RX_MAX_SIZE_SHIFT) & MAC_RX_MAX_SIZE);
|
|
|
|
|
|
|
|
ret = smsc75xx_write_reg(dev, MAC_RX, buf);
|
2012-11-24 01:27:49 +00:00
|
|
|
check_warn_return(ret, "Failed to write MAC_RX: %d\n", ret);
|
2010-03-16 08:46:46 +00:00
|
|
|
|
|
|
|
if (rxenabled) {
|
|
|
|
buf |= MAC_RX_RXEN;
|
|
|
|
ret = smsc75xx_write_reg(dev, MAC_RX, buf);
|
2012-11-24 01:27:49 +00:00
|
|
|
check_warn_return(ret, "Failed to write MAC_RX: %d\n", ret);
|
2010-03-16 08:46:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int smsc75xx_change_mtu(struct net_device *netdev, int new_mtu)
|
|
|
|
{
|
|
|
|
struct usbnet *dev = netdev_priv(netdev);
|
|
|
|
|
|
|
|
int ret = smsc75xx_set_rx_max_frame_length(dev, new_mtu);
|
2012-11-24 01:27:49 +00:00
|
|
|
check_warn_return(ret, "Failed to set mac rx frame length\n");
|
2010-03-16 08:46:46 +00:00
|
|
|
|
|
|
|
return usbnet_change_mtu(netdev, new_mtu);
|
|
|
|
}
|
|
|
|
|
2011-04-02 03:56:23 +00:00
|
|
|
/* Enable or disable Rx checksum offload engine */
|
2011-11-15 15:29:55 +00:00
|
|
|
static int smsc75xx_set_features(struct net_device *netdev,
|
|
|
|
netdev_features_t features)
|
2011-04-02 03:56:23 +00:00
|
|
|
{
|
|
|
|
struct usbnet *dev = netdev_priv(netdev);
|
|
|
|
struct smsc75xx_priv *pdata = (struct smsc75xx_priv *)(dev->data[0]);
|
|
|
|
unsigned long flags;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
spin_lock_irqsave(&pdata->rfe_ctl_lock, flags);
|
|
|
|
|
|
|
|
if (features & NETIF_F_RXCSUM)
|
|
|
|
pdata->rfe_ctl |= RFE_CTL_TCPUDP_CKM | RFE_CTL_IP_CKM;
|
|
|
|
else
|
|
|
|
pdata->rfe_ctl &= ~(RFE_CTL_TCPUDP_CKM | RFE_CTL_IP_CKM);
|
|
|
|
|
|
|
|
spin_unlock_irqrestore(&pdata->rfe_ctl_lock, flags);
|
|
|
|
/* it's racing here! */
|
|
|
|
|
|
|
|
ret = smsc75xx_write_reg(dev, RFE_CTL, pdata->rfe_ctl);
|
2012-11-24 01:27:49 +00:00
|
|
|
check_warn_return(ret, "Error writing RFE_CTL\n");
|
2011-04-02 03:56:23 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-11-06 04:53:05 +00:00
|
|
|
static int smsc75xx_wait_ready(struct usbnet *dev, int in_pm)
|
2012-09-28 00:57:51 +00:00
|
|
|
{
|
|
|
|
int timeout = 0;
|
|
|
|
|
|
|
|
do {
|
|
|
|
u32 buf;
|
2012-11-06 04:53:05 +00:00
|
|
|
int ret;
|
|
|
|
|
|
|
|
ret = __smsc75xx_read_reg(dev, PMT_CTL, &buf, in_pm);
|
|
|
|
|
2012-11-24 01:27:49 +00:00
|
|
|
check_warn_return(ret, "Failed to read PMT_CTL: %d\n", ret);
|
2012-09-28 00:57:51 +00:00
|
|
|
|
|
|
|
if (buf & PMT_CTL_DEV_RDY)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
msleep(10);
|
|
|
|
timeout++;
|
|
|
|
} while (timeout < 100);
|
|
|
|
|
2012-11-24 01:27:49 +00:00
|
|
|
netdev_warn(dev->net, "timeout waiting for device ready\n");
|
2012-09-28 00:57:51 +00:00
|
|
|
return -EIO;
|
|
|
|
}
|
|
|
|
|
2010-03-16 08:46:46 +00:00
|
|
|
static int smsc75xx_reset(struct usbnet *dev)
|
|
|
|
{
|
|
|
|
struct smsc75xx_priv *pdata = (struct smsc75xx_priv *)(dev->data[0]);
|
|
|
|
u32 buf;
|
|
|
|
int ret = 0, timeout;
|
|
|
|
|
2012-11-24 01:27:49 +00:00
|
|
|
netif_dbg(dev, ifup, dev->net, "entering smsc75xx_reset\n");
|
2010-03-16 08:46:46 +00:00
|
|
|
|
2012-11-06 04:53:05 +00:00
|
|
|
ret = smsc75xx_wait_ready(dev, 0);
|
2012-11-24 01:27:49 +00:00
|
|
|
check_warn_return(ret, "device not ready in smsc75xx_reset\n");
|
2012-09-28 00:57:51 +00:00
|
|
|
|
2010-03-16 08:46:46 +00:00
|
|
|
ret = smsc75xx_read_reg(dev, HW_CFG, &buf);
|
2012-11-24 01:27:49 +00:00
|
|
|
check_warn_return(ret, "Failed to read HW_CFG: %d\n", ret);
|
2010-03-16 08:46:46 +00:00
|
|
|
|
|
|
|
buf |= HW_CFG_LRST;
|
|
|
|
|
|
|
|
ret = smsc75xx_write_reg(dev, HW_CFG, buf);
|
2012-11-24 01:27:49 +00:00
|
|
|
check_warn_return(ret, "Failed to write HW_CFG: %d\n", ret);
|
2010-03-16 08:46:46 +00:00
|
|
|
|
|
|
|
timeout = 0;
|
|
|
|
do {
|
|
|
|
msleep(10);
|
|
|
|
ret = smsc75xx_read_reg(dev, HW_CFG, &buf);
|
2012-11-24 01:27:49 +00:00
|
|
|
check_warn_return(ret, "Failed to read HW_CFG: %d\n", ret);
|
2010-03-16 08:46:46 +00:00
|
|
|
timeout++;
|
|
|
|
} while ((buf & HW_CFG_LRST) && (timeout < 100));
|
|
|
|
|
|
|
|
if (timeout >= 100) {
|
2012-11-24 01:27:49 +00:00
|
|
|
netdev_warn(dev->net, "timeout on completion of Lite Reset\n");
|
2010-03-16 08:46:46 +00:00
|
|
|
return -EIO;
|
|
|
|
}
|
|
|
|
|
2012-11-24 01:27:49 +00:00
|
|
|
netif_dbg(dev, ifup, dev->net, "Lite reset complete, resetting PHY\n");
|
2010-03-16 08:46:46 +00:00
|
|
|
|
|
|
|
ret = smsc75xx_read_reg(dev, PMT_CTL, &buf);
|
2012-11-24 01:27:49 +00:00
|
|
|
check_warn_return(ret, "Failed to read PMT_CTL: %d\n", ret);
|
2010-03-16 08:46:46 +00:00
|
|
|
|
|
|
|
buf |= PMT_CTL_PHY_RST;
|
|
|
|
|
|
|
|
ret = smsc75xx_write_reg(dev, PMT_CTL, buf);
|
2012-11-24 01:27:49 +00:00
|
|
|
check_warn_return(ret, "Failed to write PMT_CTL: %d\n", ret);
|
2010-03-16 08:46:46 +00:00
|
|
|
|
|
|
|
timeout = 0;
|
|
|
|
do {
|
|
|
|
msleep(10);
|
|
|
|
ret = smsc75xx_read_reg(dev, PMT_CTL, &buf);
|
2012-11-24 01:27:49 +00:00
|
|
|
check_warn_return(ret, "Failed to read PMT_CTL: %d\n", ret);
|
2010-03-16 08:46:46 +00:00
|
|
|
timeout++;
|
|
|
|
} while ((buf & PMT_CTL_PHY_RST) && (timeout < 100));
|
|
|
|
|
|
|
|
if (timeout >= 100) {
|
2012-11-24 01:27:49 +00:00
|
|
|
netdev_warn(dev->net, "timeout waiting for PHY Reset\n");
|
2010-03-16 08:46:46 +00:00
|
|
|
return -EIO;
|
|
|
|
}
|
|
|
|
|
2012-11-24 01:27:49 +00:00
|
|
|
netif_dbg(dev, ifup, dev->net, "PHY reset complete\n");
|
2010-03-16 08:46:46 +00:00
|
|
|
|
|
|
|
smsc75xx_init_mac_address(dev);
|
|
|
|
|
|
|
|
ret = smsc75xx_set_mac_address(dev);
|
2012-11-24 01:27:49 +00:00
|
|
|
check_warn_return(ret, "Failed to set mac address\n");
|
2010-03-16 08:46:46 +00:00
|
|
|
|
2012-11-24 01:27:49 +00:00
|
|
|
netif_dbg(dev, ifup, dev->net, "MAC Address: %pM\n",
|
|
|
|
dev->net->dev_addr);
|
2010-03-16 08:46:46 +00:00
|
|
|
|
|
|
|
ret = smsc75xx_read_reg(dev, HW_CFG, &buf);
|
2012-11-24 01:27:49 +00:00
|
|
|
check_warn_return(ret, "Failed to read HW_CFG: %d\n", ret);
|
2010-03-16 08:46:46 +00:00
|
|
|
|
2012-11-24 01:27:49 +00:00
|
|
|
netif_dbg(dev, ifup, dev->net, "Read Value from HW_CFG : 0x%08x\n",
|
|
|
|
buf);
|
2010-03-16 08:46:46 +00:00
|
|
|
|
|
|
|
buf |= HW_CFG_BIR;
|
|
|
|
|
|
|
|
ret = smsc75xx_write_reg(dev, HW_CFG, buf);
|
2012-11-24 01:27:49 +00:00
|
|
|
check_warn_return(ret, "Failed to write HW_CFG: %d\n", ret);
|
2010-03-16 08:46:46 +00:00
|
|
|
|
|
|
|
ret = smsc75xx_read_reg(dev, HW_CFG, &buf);
|
2012-11-24 01:27:49 +00:00
|
|
|
check_warn_return(ret, "Failed to read HW_CFG: %d\n", ret);
|
2010-03-16 08:46:46 +00:00
|
|
|
|
2012-11-24 01:27:49 +00:00
|
|
|
netif_dbg(dev, ifup, dev->net, "Read Value from HW_CFG after writing HW_CFG_BIR: 0x%08x\n",
|
|
|
|
buf);
|
2010-03-16 08:46:46 +00:00
|
|
|
|
|
|
|
if (!turbo_mode) {
|
|
|
|
buf = 0;
|
|
|
|
dev->rx_urb_size = MAX_SINGLE_PACKET_SIZE;
|
|
|
|
} else if (dev->udev->speed == USB_SPEED_HIGH) {
|
|
|
|
buf = DEFAULT_HS_BURST_CAP_SIZE / HS_USB_PKT_SIZE;
|
|
|
|
dev->rx_urb_size = DEFAULT_HS_BURST_CAP_SIZE;
|
|
|
|
} else {
|
|
|
|
buf = DEFAULT_FS_BURST_CAP_SIZE / FS_USB_PKT_SIZE;
|
|
|
|
dev->rx_urb_size = DEFAULT_FS_BURST_CAP_SIZE;
|
|
|
|
}
|
|
|
|
|
2012-11-24 01:27:49 +00:00
|
|
|
netif_dbg(dev, ifup, dev->net, "rx_urb_size=%ld\n",
|
|
|
|
(ulong)dev->rx_urb_size);
|
2010-03-16 08:46:46 +00:00
|
|
|
|
|
|
|
ret = smsc75xx_write_reg(dev, BURST_CAP, buf);
|
2012-11-24 01:27:49 +00:00
|
|
|
check_warn_return(ret, "Failed to write BURST_CAP: %d\n", ret);
|
2010-03-16 08:46:46 +00:00
|
|
|
|
|
|
|
ret = smsc75xx_read_reg(dev, BURST_CAP, &buf);
|
2012-11-24 01:27:49 +00:00
|
|
|
check_warn_return(ret, "Failed to read BURST_CAP: %d\n", ret);
|
2010-03-16 08:46:46 +00:00
|
|
|
|
|
|
|
netif_dbg(dev, ifup, dev->net,
|
2012-11-24 01:27:49 +00:00
|
|
|
"Read Value from BURST_CAP after writing: 0x%08x\n", buf);
|
2010-03-16 08:46:46 +00:00
|
|
|
|
|
|
|
ret = smsc75xx_write_reg(dev, BULK_IN_DLY, DEFAULT_BULK_IN_DELAY);
|
2012-11-24 01:27:49 +00:00
|
|
|
check_warn_return(ret, "Failed to write BULK_IN_DLY: %d\n", ret);
|
2010-03-16 08:46:46 +00:00
|
|
|
|
|
|
|
ret = smsc75xx_read_reg(dev, BULK_IN_DLY, &buf);
|
2012-11-24 01:27:49 +00:00
|
|
|
check_warn_return(ret, "Failed to read BULK_IN_DLY: %d\n", ret);
|
2010-03-16 08:46:46 +00:00
|
|
|
|
|
|
|
netif_dbg(dev, ifup, dev->net,
|
2012-11-24 01:27:49 +00:00
|
|
|
"Read Value from BULK_IN_DLY after writing: 0x%08x\n", buf);
|
2010-03-16 08:46:46 +00:00
|
|
|
|
|
|
|
if (turbo_mode) {
|
|
|
|
ret = smsc75xx_read_reg(dev, HW_CFG, &buf);
|
2012-11-24 01:27:49 +00:00
|
|
|
check_warn_return(ret, "Failed to read HW_CFG: %d\n", ret);
|
2010-03-16 08:46:46 +00:00
|
|
|
|
2012-11-24 01:27:49 +00:00
|
|
|
netif_dbg(dev, ifup, dev->net, "HW_CFG: 0x%08x\n", buf);
|
2010-03-16 08:46:46 +00:00
|
|
|
|
|
|
|
buf |= (HW_CFG_MEF | HW_CFG_BCE);
|
|
|
|
|
|
|
|
ret = smsc75xx_write_reg(dev, HW_CFG, buf);
|
2012-11-24 01:27:49 +00:00
|
|
|
check_warn_return(ret, "Failed to write HW_CFG: %d\n", ret);
|
2010-03-16 08:46:46 +00:00
|
|
|
|
|
|
|
ret = smsc75xx_read_reg(dev, HW_CFG, &buf);
|
2012-11-24 01:27:49 +00:00
|
|
|
check_warn_return(ret, "Failed to read HW_CFG: %d\n", ret);
|
2010-03-16 08:46:46 +00:00
|
|
|
|
2012-11-24 01:27:49 +00:00
|
|
|
netif_dbg(dev, ifup, dev->net, "HW_CFG: 0x%08x\n", buf);
|
2010-03-16 08:46:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* set FIFO sizes */
|
|
|
|
buf = (MAX_RX_FIFO_SIZE - 512) / 512;
|
|
|
|
ret = smsc75xx_write_reg(dev, FCT_RX_FIFO_END, buf);
|
2012-11-24 01:27:49 +00:00
|
|
|
check_warn_return(ret, "Failed to write FCT_RX_FIFO_END: %d\n", ret);
|
2010-03-16 08:46:46 +00:00
|
|
|
|
2012-11-24 01:27:49 +00:00
|
|
|
netif_dbg(dev, ifup, dev->net, "FCT_RX_FIFO_END set to 0x%08x\n", buf);
|
2010-03-16 08:46:46 +00:00
|
|
|
|
|
|
|
buf = (MAX_TX_FIFO_SIZE - 512) / 512;
|
|
|
|
ret = smsc75xx_write_reg(dev, FCT_TX_FIFO_END, buf);
|
2012-11-24 01:27:49 +00:00
|
|
|
check_warn_return(ret, "Failed to write FCT_TX_FIFO_END: %d\n", ret);
|
2010-03-16 08:46:46 +00:00
|
|
|
|
2012-11-24 01:27:49 +00:00
|
|
|
netif_dbg(dev, ifup, dev->net, "FCT_TX_FIFO_END set to 0x%08x\n", buf);
|
2010-03-16 08:46:46 +00:00
|
|
|
|
|
|
|
ret = smsc75xx_write_reg(dev, INT_STS, INT_STS_CLEAR_ALL);
|
2012-11-24 01:27:49 +00:00
|
|
|
check_warn_return(ret, "Failed to write INT_STS: %d\n", ret);
|
2010-03-16 08:46:46 +00:00
|
|
|
|
|
|
|
ret = smsc75xx_read_reg(dev, ID_REV, &buf);
|
2012-11-24 01:27:49 +00:00
|
|
|
check_warn_return(ret, "Failed to read ID_REV: %d\n", ret);
|
2010-03-16 08:46:46 +00:00
|
|
|
|
2012-11-24 01:27:49 +00:00
|
|
|
netif_dbg(dev, ifup, dev->net, "ID_REV = 0x%08x\n", buf);
|
2010-03-16 08:46:46 +00:00
|
|
|
|
2012-05-04 00:57:13 +00:00
|
|
|
ret = smsc75xx_read_reg(dev, E2P_CMD, &buf);
|
2012-11-24 01:27:49 +00:00
|
|
|
check_warn_return(ret, "Failed to read E2P_CMD: %d\n", ret);
|
2010-03-16 08:46:46 +00:00
|
|
|
|
2012-05-04 00:57:13 +00:00
|
|
|
/* only set default GPIO/LED settings if no EEPROM is detected */
|
|
|
|
if (!(buf & E2P_CMD_LOADED)) {
|
|
|
|
ret = smsc75xx_read_reg(dev, LED_GPIO_CFG, &buf);
|
2012-11-24 01:27:49 +00:00
|
|
|
check_warn_return(ret, "Failed to read LED_GPIO_CFG: %d\n",
|
|
|
|
ret);
|
2010-03-16 08:46:46 +00:00
|
|
|
|
2012-05-04 00:57:13 +00:00
|
|
|
buf &= ~(LED_GPIO_CFG_LED2_FUN_SEL | LED_GPIO_CFG_LED10_FUN_SEL);
|
|
|
|
buf |= LED_GPIO_CFG_LEDGPIO_EN | LED_GPIO_CFG_LED2_FUN_SEL;
|
|
|
|
|
|
|
|
ret = smsc75xx_write_reg(dev, LED_GPIO_CFG, buf);
|
2012-11-24 01:27:49 +00:00
|
|
|
check_warn_return(ret, "Failed to write LED_GPIO_CFG: %d\n",
|
|
|
|
ret);
|
2012-05-04 00:57:13 +00:00
|
|
|
}
|
2010-03-16 08:46:46 +00:00
|
|
|
|
|
|
|
ret = smsc75xx_write_reg(dev, FLOW, 0);
|
2012-11-24 01:27:49 +00:00
|
|
|
check_warn_return(ret, "Failed to write FLOW: %d\n", ret);
|
2010-03-16 08:46:46 +00:00
|
|
|
|
|
|
|
ret = smsc75xx_write_reg(dev, FCT_FLOW, 0);
|
2012-11-24 01:27:49 +00:00
|
|
|
check_warn_return(ret, "Failed to write FCT_FLOW: %d\n", ret);
|
2010-03-16 08:46:46 +00:00
|
|
|
|
|
|
|
/* Don't need rfe_ctl_lock during initialisation */
|
|
|
|
ret = smsc75xx_read_reg(dev, RFE_CTL, &pdata->rfe_ctl);
|
2012-11-24 01:27:49 +00:00
|
|
|
check_warn_return(ret, "Failed to read RFE_CTL: %d\n", ret);
|
2010-03-16 08:46:46 +00:00
|
|
|
|
|
|
|
pdata->rfe_ctl |= RFE_CTL_AB | RFE_CTL_DPF;
|
|
|
|
|
|
|
|
ret = smsc75xx_write_reg(dev, RFE_CTL, pdata->rfe_ctl);
|
2012-11-24 01:27:49 +00:00
|
|
|
check_warn_return(ret, "Failed to write RFE_CTL: %d\n", ret);
|
2010-03-16 08:46:46 +00:00
|
|
|
|
|
|
|
ret = smsc75xx_read_reg(dev, RFE_CTL, &pdata->rfe_ctl);
|
2012-11-24 01:27:49 +00:00
|
|
|
check_warn_return(ret, "Failed to read RFE_CTL: %d\n", ret);
|
2010-03-16 08:46:46 +00:00
|
|
|
|
2012-11-24 01:27:49 +00:00
|
|
|
netif_dbg(dev, ifup, dev->net, "RFE_CTL set to 0x%08x\n",
|
|
|
|
pdata->rfe_ctl);
|
2010-03-16 08:46:46 +00:00
|
|
|
|
|
|
|
/* Enable or disable checksum offload engines */
|
2011-04-02 03:56:23 +00:00
|
|
|
smsc75xx_set_features(dev->net, dev->net->features);
|
2010-03-16 08:46:46 +00:00
|
|
|
|
|
|
|
smsc75xx_set_multicast(dev->net);
|
|
|
|
|
|
|
|
ret = smsc75xx_phy_initialize(dev);
|
2012-11-24 01:27:49 +00:00
|
|
|
check_warn_return(ret, "Failed to initialize PHY: %d\n", ret);
|
2010-03-16 08:46:46 +00:00
|
|
|
|
|
|
|
ret = smsc75xx_read_reg(dev, INT_EP_CTL, &buf);
|
2012-11-24 01:27:49 +00:00
|
|
|
check_warn_return(ret, "Failed to read INT_EP_CTL: %d\n", ret);
|
2010-03-16 08:46:46 +00:00
|
|
|
|
|
|
|
/* enable PHY interrupts */
|
|
|
|
buf |= INT_ENP_PHY_INT;
|
|
|
|
|
|
|
|
ret = smsc75xx_write_reg(dev, INT_EP_CTL, buf);
|
2012-11-24 01:27:49 +00:00
|
|
|
check_warn_return(ret, "Failed to write INT_EP_CTL: %d\n", ret);
|
2010-03-16 08:46:46 +00:00
|
|
|
|
2012-04-30 07:56:56 +00:00
|
|
|
/* allow mac to detect speed and duplex from phy */
|
|
|
|
ret = smsc75xx_read_reg(dev, MAC_CR, &buf);
|
2012-11-24 01:27:49 +00:00
|
|
|
check_warn_return(ret, "Failed to read MAC_CR: %d\n", ret);
|
2012-04-30 07:56:56 +00:00
|
|
|
|
|
|
|
buf |= (MAC_CR_ADD | MAC_CR_ASD);
|
|
|
|
ret = smsc75xx_write_reg(dev, MAC_CR, buf);
|
2012-11-24 01:27:49 +00:00
|
|
|
check_warn_return(ret, "Failed to write MAC_CR: %d\n", ret);
|
2012-04-30 07:56:56 +00:00
|
|
|
|
2010-03-16 08:46:46 +00:00
|
|
|
ret = smsc75xx_read_reg(dev, MAC_TX, &buf);
|
2012-11-24 01:27:49 +00:00
|
|
|
check_warn_return(ret, "Failed to read MAC_TX: %d\n", ret);
|
2010-03-16 08:46:46 +00:00
|
|
|
|
|
|
|
buf |= MAC_TX_TXEN;
|
|
|
|
|
|
|
|
ret = smsc75xx_write_reg(dev, MAC_TX, buf);
|
2012-11-24 01:27:49 +00:00
|
|
|
check_warn_return(ret, "Failed to write MAC_TX: %d\n", ret);
|
2010-03-16 08:46:46 +00:00
|
|
|
|
2012-11-24 01:27:49 +00:00
|
|
|
netif_dbg(dev, ifup, dev->net, "MAC_TX set to 0x%08x\n", buf);
|
2010-03-16 08:46:46 +00:00
|
|
|
|
|
|
|
ret = smsc75xx_read_reg(dev, FCT_TX_CTL, &buf);
|
2012-11-24 01:27:49 +00:00
|
|
|
check_warn_return(ret, "Failed to read FCT_TX_CTL: %d\n", ret);
|
2010-03-16 08:46:46 +00:00
|
|
|
|
|
|
|
buf |= FCT_TX_CTL_EN;
|
|
|
|
|
|
|
|
ret = smsc75xx_write_reg(dev, FCT_TX_CTL, buf);
|
2012-11-24 01:27:49 +00:00
|
|
|
check_warn_return(ret, "Failed to write FCT_TX_CTL: %d\n", ret);
|
2010-03-16 08:46:46 +00:00
|
|
|
|
2012-11-24 01:27:49 +00:00
|
|
|
netif_dbg(dev, ifup, dev->net, "FCT_TX_CTL set to 0x%08x\n", buf);
|
2010-03-16 08:46:46 +00:00
|
|
|
|
|
|
|
ret = smsc75xx_set_rx_max_frame_length(dev, 1514);
|
2012-11-24 01:27:49 +00:00
|
|
|
check_warn_return(ret, "Failed to set max rx frame length\n");
|
2010-03-16 08:46:46 +00:00
|
|
|
|
|
|
|
ret = smsc75xx_read_reg(dev, MAC_RX, &buf);
|
2012-11-24 01:27:49 +00:00
|
|
|
check_warn_return(ret, "Failed to read MAC_RX: %d\n", ret);
|
2010-03-16 08:46:46 +00:00
|
|
|
|
|
|
|
buf |= MAC_RX_RXEN;
|
|
|
|
|
|
|
|
ret = smsc75xx_write_reg(dev, MAC_RX, buf);
|
2012-11-24 01:27:49 +00:00
|
|
|
check_warn_return(ret, "Failed to write MAC_RX: %d\n", ret);
|
2010-03-16 08:46:46 +00:00
|
|
|
|
2012-11-24 01:27:49 +00:00
|
|
|
netif_dbg(dev, ifup, dev->net, "MAC_RX set to 0x%08x\n", buf);
|
2010-03-16 08:46:46 +00:00
|
|
|
|
|
|
|
ret = smsc75xx_read_reg(dev, FCT_RX_CTL, &buf);
|
2012-11-24 01:27:49 +00:00
|
|
|
check_warn_return(ret, "Failed to read FCT_RX_CTL: %d\n", ret);
|
2010-03-16 08:46:46 +00:00
|
|
|
|
|
|
|
buf |= FCT_RX_CTL_EN;
|
|
|
|
|
|
|
|
ret = smsc75xx_write_reg(dev, FCT_RX_CTL, buf);
|
2012-11-24 01:27:49 +00:00
|
|
|
check_warn_return(ret, "Failed to write FCT_RX_CTL: %d\n", ret);
|
2010-03-16 08:46:46 +00:00
|
|
|
|
2012-11-24 01:27:49 +00:00
|
|
|
netif_dbg(dev, ifup, dev->net, "FCT_RX_CTL set to 0x%08x\n", buf);
|
2010-03-16 08:46:46 +00:00
|
|
|
|
2012-11-24 01:27:49 +00:00
|
|
|
netif_dbg(dev, ifup, dev->net, "smsc75xx_reset, return 0\n");
|
2010-03-16 08:46:46 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const struct net_device_ops smsc75xx_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 = smsc75xx_change_mtu,
|
|
|
|
.ndo_set_mac_address = eth_mac_addr,
|
|
|
|
.ndo_validate_addr = eth_validate_addr,
|
|
|
|
.ndo_do_ioctl = smsc75xx_ioctl,
|
2011-08-16 06:29:01 +00:00
|
|
|
.ndo_set_rx_mode = smsc75xx_set_multicast,
|
2011-04-02 03:56:23 +00:00
|
|
|
.ndo_set_features = smsc75xx_set_features,
|
2010-03-16 08:46:46 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static int smsc75xx_bind(struct usbnet *dev, struct usb_interface *intf)
|
|
|
|
{
|
|
|
|
struct smsc75xx_priv *pdata = NULL;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
printk(KERN_INFO SMSC_CHIPNAME " v" SMSC_DRIVER_VERSION "\n");
|
|
|
|
|
|
|
|
ret = usbnet_get_endpoints(dev, intf);
|
2012-11-24 01:27:49 +00:00
|
|
|
check_warn_return(ret, "usbnet_get_endpoints failed: %d\n", ret);
|
2010-03-16 08:46:46 +00:00
|
|
|
|
|
|
|
dev->data[0] = (unsigned long)kzalloc(sizeof(struct smsc75xx_priv),
|
|
|
|
GFP_KERNEL);
|
|
|
|
|
|
|
|
pdata = (struct smsc75xx_priv *)(dev->data[0]);
|
|
|
|
if (!pdata) {
|
2012-11-24 01:27:49 +00:00
|
|
|
netdev_warn(dev->net, "Unable to allocate smsc75xx_priv\n");
|
2010-03-16 08:46:46 +00:00
|
|
|
return -ENOMEM;
|
|
|
|
}
|
|
|
|
|
|
|
|
pdata->dev = dev;
|
|
|
|
|
|
|
|
spin_lock_init(&pdata->rfe_ctl_lock);
|
|
|
|
mutex_init(&pdata->dataport_mutex);
|
|
|
|
|
|
|
|
INIT_WORK(&pdata->set_multicast, smsc75xx_deferred_multicast_write);
|
|
|
|
|
2011-04-02 03:56:23 +00:00
|
|
|
if (DEFAULT_TX_CSUM_ENABLE) {
|
|
|
|
dev->net->features |= NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM;
|
|
|
|
if (DEFAULT_TSO_ENABLE)
|
|
|
|
dev->net->features |= NETIF_F_SG |
|
|
|
|
NETIF_F_TSO | NETIF_F_TSO6;
|
|
|
|
}
|
|
|
|
if (DEFAULT_RX_CSUM_ENABLE)
|
|
|
|
dev->net->features |= NETIF_F_RXCSUM;
|
2010-03-16 08:46:46 +00:00
|
|
|
|
2011-04-02 03:56:23 +00:00
|
|
|
dev->net->hw_features = NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM |
|
|
|
|
NETIF_F_SG | NETIF_F_TSO | NETIF_F_TSO6 | NETIF_F_RXCSUM;
|
2010-03-16 08:46:46 +00:00
|
|
|
|
|
|
|
/* Init all registers */
|
|
|
|
ret = smsc75xx_reset(dev);
|
2012-11-28 05:59:45 +00:00
|
|
|
check_warn_return(ret, "smsc75xx_reset error %d\n", ret);
|
2010-03-16 08:46:46 +00:00
|
|
|
|
|
|
|
dev->net->netdev_ops = &smsc75xx_netdev_ops;
|
|
|
|
dev->net->ethtool_ops = &smsc75xx_ethtool_ops;
|
|
|
|
dev->net->flags |= IFF_MULTICAST;
|
|
|
|
dev->net->hard_header_len += SMSC75XX_TX_OVERHEAD;
|
2012-04-15 11:38:29 +00:00
|
|
|
dev->hard_mtu = dev->net->mtu + dev->net->hard_header_len;
|
2010-03-16 08:46:46 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void smsc75xx_unbind(struct usbnet *dev, struct usb_interface *intf)
|
|
|
|
{
|
|
|
|
struct smsc75xx_priv *pdata = (struct smsc75xx_priv *)(dev->data[0]);
|
|
|
|
if (pdata) {
|
2012-11-24 01:27:49 +00:00
|
|
|
netif_dbg(dev, ifdown, dev->net, "free pdata\n");
|
2010-03-16 08:46:46 +00:00
|
|
|
kfree(pdata);
|
|
|
|
pdata = NULL;
|
|
|
|
dev->data[0] = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-10-30 07:46:32 +00:00
|
|
|
static u16 smsc_crc(const u8 *buffer, size_t len)
|
|
|
|
{
|
|
|
|
return bitrev16(crc16(0xFFFF, buffer, len));
|
|
|
|
}
|
|
|
|
|
|
|
|
static int smsc75xx_write_wuff(struct usbnet *dev, int filter, u32 wuf_cfg,
|
|
|
|
u32 wuf_mask1)
|
|
|
|
{
|
|
|
|
int cfg_base = WUF_CFGX + filter * 4;
|
|
|
|
int mask_base = WUF_MASKX + filter * 16;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
ret = smsc75xx_write_reg(dev, cfg_base, wuf_cfg);
|
2012-11-24 01:27:49 +00:00
|
|
|
check_warn_return(ret, "Error writing WUF_CFGX\n");
|
2012-10-30 07:46:32 +00:00
|
|
|
|
|
|
|
ret = smsc75xx_write_reg(dev, mask_base, wuf_mask1);
|
2012-11-24 01:27:49 +00:00
|
|
|
check_warn_return(ret, "Error writing WUF_MASKX\n");
|
2012-10-30 07:46:32 +00:00
|
|
|
|
|
|
|
ret = smsc75xx_write_reg(dev, mask_base + 4, 0);
|
2012-11-24 01:27:49 +00:00
|
|
|
check_warn_return(ret, "Error writing WUF_MASKX\n");
|
2012-10-30 07:46:32 +00:00
|
|
|
|
|
|
|
ret = smsc75xx_write_reg(dev, mask_base + 8, 0);
|
2012-11-24 01:27:49 +00:00
|
|
|
check_warn_return(ret, "Error writing WUF_MASKX\n");
|
2012-10-30 07:46:32 +00:00
|
|
|
|
|
|
|
ret = smsc75xx_write_reg(dev, mask_base + 12, 0);
|
2012-11-24 01:27:49 +00:00
|
|
|
check_warn_return(ret, "Error writing WUF_MASKX\n");
|
2012-10-30 07:46:32 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-11-28 05:59:46 +00:00
|
|
|
static int smsc75xx_enter_suspend0(struct usbnet *dev)
|
|
|
|
{
|
|
|
|
u32 val;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
ret = smsc75xx_read_reg_nopm(dev, PMT_CTL, &val);
|
|
|
|
check_warn_return(ret, "Error reading PMT_CTL\n");
|
|
|
|
|
|
|
|
val &= (~(PMT_CTL_SUS_MODE | PMT_CTL_PHY_RST));
|
|
|
|
val |= PMT_CTL_SUS_MODE_0 | PMT_CTL_WOL_EN | PMT_CTL_WUPS;
|
|
|
|
|
|
|
|
ret = smsc75xx_write_reg_nopm(dev, PMT_CTL, val);
|
|
|
|
check_warn_return(ret, "Error writing PMT_CTL\n");
|
|
|
|
|
|
|
|
smsc75xx_set_feature(dev, USB_DEVICE_REMOTE_WAKEUP);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-11-28 05:59:47 +00:00
|
|
|
static int smsc75xx_enter_suspend1(struct usbnet *dev)
|
|
|
|
{
|
|
|
|
u32 val;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
ret = smsc75xx_read_reg_nopm(dev, PMT_CTL, &val);
|
|
|
|
check_warn_return(ret, "Error reading PMT_CTL\n");
|
|
|
|
|
|
|
|
val &= ~(PMT_CTL_SUS_MODE | PMT_CTL_WUPS | PMT_CTL_PHY_RST);
|
|
|
|
val |= PMT_CTL_SUS_MODE_1;
|
|
|
|
|
|
|
|
ret = smsc75xx_write_reg_nopm(dev, PMT_CTL, val);
|
|
|
|
check_warn_return(ret, "Error writing PMT_CTL\n");
|
|
|
|
|
|
|
|
/* clear wol status, enable energy detection */
|
|
|
|
val &= ~PMT_CTL_WUPS;
|
|
|
|
val |= (PMT_CTL_WUPS_ED | PMT_CTL_ED_EN);
|
|
|
|
|
|
|
|
ret = smsc75xx_write_reg_nopm(dev, PMT_CTL, val);
|
|
|
|
check_warn_return(ret, "Error writing PMT_CTL\n");
|
|
|
|
|
|
|
|
smsc75xx_set_feature(dev, USB_DEVICE_REMOTE_WAKEUP);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-11-28 05:59:46 +00:00
|
|
|
static int smsc75xx_enter_suspend2(struct usbnet *dev)
|
|
|
|
{
|
|
|
|
u32 val;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
ret = smsc75xx_read_reg_nopm(dev, PMT_CTL, &val);
|
|
|
|
check_warn_return(ret, "Error reading PMT_CTL\n");
|
|
|
|
|
|
|
|
val &= ~(PMT_CTL_SUS_MODE | PMT_CTL_WUPS | PMT_CTL_PHY_RST);
|
|
|
|
val |= PMT_CTL_SUS_MODE_2;
|
|
|
|
|
|
|
|
ret = smsc75xx_write_reg_nopm(dev, PMT_CTL, val);
|
|
|
|
check_warn_return(ret, "Error writing PMT_CTL\n");
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-11-28 05:59:47 +00:00
|
|
|
static int smsc75xx_enable_phy_wakeup_interrupts(struct usbnet *dev, u16 mask)
|
|
|
|
{
|
|
|
|
struct mii_if_info *mii = &dev->mii;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
netdev_dbg(dev->net, "enabling PHY wakeup interrupts\n");
|
|
|
|
|
|
|
|
/* read to clear */
|
|
|
|
ret = smsc75xx_mdio_read_nopm(dev->net, mii->phy_id, PHY_INT_SRC);
|
|
|
|
check_warn_return(ret, "Error reading PHY_INT_SRC\n");
|
|
|
|
|
|
|
|
/* enable interrupt source */
|
|
|
|
ret = smsc75xx_mdio_read_nopm(dev->net, mii->phy_id, PHY_INT_MASK);
|
|
|
|
check_warn_return(ret, "Error reading PHY_INT_MASK\n");
|
|
|
|
|
|
|
|
ret |= mask;
|
|
|
|
|
|
|
|
smsc75xx_mdio_write_nopm(dev->net, mii->phy_id, PHY_INT_MASK, ret);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int smsc75xx_link_ok_nopm(struct usbnet *dev)
|
|
|
|
{
|
|
|
|
struct mii_if_info *mii = &dev->mii;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
/* first, a dummy read, needed to latch some MII phys */
|
|
|
|
ret = smsc75xx_mdio_read_nopm(dev->net, mii->phy_id, MII_BMSR);
|
|
|
|
check_warn_return(ret, "Error reading MII_BMSR\n");
|
|
|
|
|
|
|
|
ret = smsc75xx_mdio_read_nopm(dev->net, mii->phy_id, MII_BMSR);
|
|
|
|
check_warn_return(ret, "Error reading MII_BMSR\n");
|
|
|
|
|
|
|
|
return !!(ret & BMSR_LSTATUS);
|
|
|
|
}
|
|
|
|
|
2012-09-28 00:57:52 +00:00
|
|
|
static int smsc75xx_suspend(struct usb_interface *intf, pm_message_t message)
|
|
|
|
{
|
|
|
|
struct usbnet *dev = usb_get_intfdata(intf);
|
2012-09-28 00:57:53 +00:00
|
|
|
struct smsc75xx_priv *pdata = (struct smsc75xx_priv *)(dev->data[0]);
|
2012-11-28 05:59:47 +00:00
|
|
|
u32 val, link_up;
|
2012-09-28 00:57:52 +00:00
|
|
|
int ret;
|
|
|
|
|
|
|
|
ret = usbnet_suspend(intf, message);
|
2012-11-28 05:59:48 +00:00
|
|
|
check_warn_goto_done(ret, "usbnet_suspend error\n");
|
2012-09-28 00:57:52 +00:00
|
|
|
|
2012-11-28 05:59:47 +00:00
|
|
|
/* determine if link is up using only _nopm functions */
|
|
|
|
link_up = smsc75xx_link_ok_nopm(dev);
|
|
|
|
|
|
|
|
/* if no wol options set, or if link is down and we're not waking on
|
|
|
|
* PHY activity, enter lowest power SUSPEND2 mode
|
|
|
|
*/
|
|
|
|
if (!(pdata->wolopts & SUPPORTED_WAKE) ||
|
|
|
|
!(link_up || (pdata->wolopts & WAKE_PHY))) {
|
2012-11-24 01:27:49 +00:00
|
|
|
netdev_info(dev->net, "entering SUSPEND2 mode\n");
|
2012-09-28 00:57:53 +00:00
|
|
|
|
|
|
|
/* disable energy detect (link up) & wake up events */
|
2012-11-06 04:53:05 +00:00
|
|
|
ret = smsc75xx_read_reg_nopm(dev, WUCSR, &val);
|
2012-11-28 05:59:48 +00:00
|
|
|
check_warn_goto_done(ret, "Error reading WUCSR\n");
|
2012-09-28 00:57:53 +00:00
|
|
|
|
|
|
|
val &= ~(WUCSR_MPEN | WUCSR_WUEN);
|
|
|
|
|
2012-11-06 04:53:05 +00:00
|
|
|
ret = smsc75xx_write_reg_nopm(dev, WUCSR, val);
|
2012-11-28 05:59:48 +00:00
|
|
|
check_warn_goto_done(ret, "Error writing WUCSR\n");
|
2012-09-28 00:57:53 +00:00
|
|
|
|
2012-11-06 04:53:05 +00:00
|
|
|
ret = smsc75xx_read_reg_nopm(dev, PMT_CTL, &val);
|
2012-11-28 05:59:48 +00:00
|
|
|
check_warn_goto_done(ret, "Error reading PMT_CTL\n");
|
2012-09-28 00:57:53 +00:00
|
|
|
|
|
|
|
val &= ~(PMT_CTL_ED_EN | PMT_CTL_WOL_EN);
|
|
|
|
|
2012-11-06 04:53:05 +00:00
|
|
|
ret = smsc75xx_write_reg_nopm(dev, PMT_CTL, val);
|
2012-11-28 05:59:48 +00:00
|
|
|
check_warn_goto_done(ret, "Error writing PMT_CTL\n");
|
2012-09-28 00:57:53 +00:00
|
|
|
|
2012-11-28 05:59:48 +00:00
|
|
|
ret = smsc75xx_enter_suspend2(dev);
|
|
|
|
goto done;
|
2012-09-28 00:57:53 +00:00
|
|
|
}
|
|
|
|
|
2012-11-28 05:59:47 +00:00
|
|
|
if (pdata->wolopts & WAKE_PHY) {
|
|
|
|
ret = smsc75xx_enable_phy_wakeup_interrupts(dev,
|
|
|
|
(PHY_INT_MASK_ANEG_COMP | PHY_INT_MASK_LINK_DOWN));
|
2012-11-28 05:59:48 +00:00
|
|
|
check_warn_goto_done(ret, "error enabling PHY wakeup ints\n");
|
2012-11-28 05:59:47 +00:00
|
|
|
|
|
|
|
/* if link is down then configure EDPD and enter SUSPEND1,
|
|
|
|
* otherwise enter SUSPEND0 below
|
|
|
|
*/
|
|
|
|
if (!link_up) {
|
|
|
|
struct mii_if_info *mii = &dev->mii;
|
|
|
|
netdev_info(dev->net, "entering SUSPEND1 mode\n");
|
|
|
|
|
|
|
|
/* enable energy detect power-down mode */
|
|
|
|
ret = smsc75xx_mdio_read_nopm(dev->net, mii->phy_id,
|
|
|
|
PHY_MODE_CTRL_STS);
|
2012-11-28 05:59:48 +00:00
|
|
|
check_warn_goto_done(ret, "Error reading PHY_MODE_CTRL_STS\n");
|
2012-11-28 05:59:47 +00:00
|
|
|
|
|
|
|
ret |= MODE_CTRL_STS_EDPWRDOWN;
|
|
|
|
|
|
|
|
smsc75xx_mdio_write_nopm(dev->net, mii->phy_id,
|
|
|
|
PHY_MODE_CTRL_STS, ret);
|
|
|
|
|
|
|
|
/* enter SUSPEND1 mode */
|
2012-11-28 05:59:48 +00:00
|
|
|
ret = smsc75xx_enter_suspend1(dev);
|
|
|
|
goto done;
|
2012-11-28 05:59:47 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-10-30 07:46:32 +00:00
|
|
|
if (pdata->wolopts & (WAKE_MCAST | WAKE_ARP)) {
|
|
|
|
int i, filter = 0;
|
|
|
|
|
|
|
|
/* disable all filters */
|
|
|
|
for (i = 0; i < WUF_NUM; i++) {
|
2012-11-06 04:53:05 +00:00
|
|
|
ret = smsc75xx_write_reg_nopm(dev, WUF_CFGX + i * 4, 0);
|
2012-11-28 05:59:48 +00:00
|
|
|
check_warn_goto_done(ret, "Error writing WUF_CFGX\n");
|
2012-10-30 07:46:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (pdata->wolopts & WAKE_MCAST) {
|
|
|
|
const u8 mcast[] = {0x01, 0x00, 0x5E};
|
2012-11-24 01:27:49 +00:00
|
|
|
netdev_info(dev->net, "enabling multicast detection\n");
|
2012-10-30 07:46:32 +00:00
|
|
|
|
|
|
|
val = WUF_CFGX_EN | WUF_CFGX_ATYPE_MULTICAST
|
|
|
|
| smsc_crc(mcast, 3);
|
|
|
|
ret = smsc75xx_write_wuff(dev, filter++, val, 0x0007);
|
2012-11-28 05:59:48 +00:00
|
|
|
check_warn_goto_done(ret, "Error writing wakeup filter\n");
|
2012-10-30 07:46:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (pdata->wolopts & WAKE_ARP) {
|
|
|
|
const u8 arp[] = {0x08, 0x06};
|
2012-11-24 01:27:49 +00:00
|
|
|
netdev_info(dev->net, "enabling ARP detection\n");
|
2012-10-30 07:46:32 +00:00
|
|
|
|
|
|
|
val = WUF_CFGX_EN | WUF_CFGX_ATYPE_ALL | (0x0C << 16)
|
|
|
|
| smsc_crc(arp, 2);
|
|
|
|
ret = smsc75xx_write_wuff(dev, filter++, val, 0x0003);
|
2012-11-28 05:59:48 +00:00
|
|
|
check_warn_goto_done(ret, "Error writing wakeup filter\n");
|
2012-10-30 07:46:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* clear any pending pattern match packet status */
|
2012-11-06 04:53:05 +00:00
|
|
|
ret = smsc75xx_read_reg_nopm(dev, WUCSR, &val);
|
2012-11-28 05:59:48 +00:00
|
|
|
check_warn_goto_done(ret, "Error reading WUCSR\n");
|
2012-10-30 07:46:32 +00:00
|
|
|
|
|
|
|
val |= WUCSR_WUFR;
|
|
|
|
|
2012-11-06 04:53:05 +00:00
|
|
|
ret = smsc75xx_write_reg_nopm(dev, WUCSR, val);
|
2012-11-28 05:59:48 +00:00
|
|
|
check_warn_goto_done(ret, "Error writing WUCSR\n");
|
2012-10-30 07:46:32 +00:00
|
|
|
|
2012-11-24 01:27:49 +00:00
|
|
|
netdev_info(dev->net, "enabling packet match detection\n");
|
2012-11-06 04:53:05 +00:00
|
|
|
ret = smsc75xx_read_reg_nopm(dev, WUCSR, &val);
|
2012-11-28 05:59:48 +00:00
|
|
|
check_warn_goto_done(ret, "Error reading WUCSR\n");
|
2012-10-30 07:46:32 +00:00
|
|
|
|
|
|
|
val |= WUCSR_WUEN;
|
|
|
|
|
2012-11-06 04:53:05 +00:00
|
|
|
ret = smsc75xx_write_reg_nopm(dev, WUCSR, val);
|
2012-11-28 05:59:48 +00:00
|
|
|
check_warn_goto_done(ret, "Error writing WUCSR\n");
|
2012-10-30 07:46:32 +00:00
|
|
|
} else {
|
2012-11-24 01:27:49 +00:00
|
|
|
netdev_info(dev->net, "disabling packet match detection\n");
|
2012-11-06 04:53:05 +00:00
|
|
|
ret = smsc75xx_read_reg_nopm(dev, WUCSR, &val);
|
2012-11-28 05:59:48 +00:00
|
|
|
check_warn_goto_done(ret, "Error reading WUCSR\n");
|
2012-09-28 00:57:53 +00:00
|
|
|
|
2012-10-30 07:46:32 +00:00
|
|
|
val &= ~WUCSR_WUEN;
|
2012-09-28 00:57:52 +00:00
|
|
|
|
2012-11-06 04:53:05 +00:00
|
|
|
ret = smsc75xx_write_reg_nopm(dev, WUCSR, val);
|
2012-11-28 05:59:48 +00:00
|
|
|
check_warn_goto_done(ret, "Error writing WUCSR\n");
|
2012-09-28 00:57:53 +00:00
|
|
|
}
|
|
|
|
|
2012-10-30 07:46:32 +00:00
|
|
|
/* disable magic, bcast & unicast wakeup sources */
|
2012-11-06 04:53:05 +00:00
|
|
|
ret = smsc75xx_read_reg_nopm(dev, WUCSR, &val);
|
2012-11-28 05:59:48 +00:00
|
|
|
check_warn_goto_done(ret, "Error reading WUCSR\n");
|
2012-09-28 00:57:53 +00:00
|
|
|
|
2012-10-30 07:46:32 +00:00
|
|
|
val &= ~(WUCSR_MPEN | WUCSR_BCST_EN | WUCSR_PFDA_EN);
|
|
|
|
|
2012-11-06 04:53:05 +00:00
|
|
|
ret = smsc75xx_write_reg_nopm(dev, WUCSR, val);
|
2012-11-28 05:59:48 +00:00
|
|
|
check_warn_goto_done(ret, "Error writing WUCSR\n");
|
2012-10-30 07:46:32 +00:00
|
|
|
|
2012-11-28 05:59:47 +00:00
|
|
|
if (pdata->wolopts & WAKE_PHY) {
|
|
|
|
netdev_info(dev->net, "enabling PHY wakeup\n");
|
|
|
|
|
|
|
|
ret = smsc75xx_read_reg_nopm(dev, PMT_CTL, &val);
|
2012-11-28 05:59:48 +00:00
|
|
|
check_warn_goto_done(ret, "Error reading PMT_CTL\n");
|
2012-11-28 05:59:47 +00:00
|
|
|
|
|
|
|
/* clear wol status, enable energy detection */
|
|
|
|
val &= ~PMT_CTL_WUPS;
|
|
|
|
val |= (PMT_CTL_WUPS_ED | PMT_CTL_ED_EN);
|
|
|
|
|
|
|
|
ret = smsc75xx_write_reg_nopm(dev, PMT_CTL, val);
|
2012-11-28 05:59:48 +00:00
|
|
|
check_warn_goto_done(ret, "Error writing PMT_CTL\n");
|
2012-11-28 05:59:47 +00:00
|
|
|
}
|
|
|
|
|
2012-09-28 00:57:53 +00:00
|
|
|
if (pdata->wolopts & WAKE_MAGIC) {
|
2012-11-24 01:27:49 +00:00
|
|
|
netdev_info(dev->net, "enabling magic packet wakeup\n");
|
2012-11-06 04:53:05 +00:00
|
|
|
ret = smsc75xx_read_reg_nopm(dev, WUCSR, &val);
|
2012-11-28 05:59:48 +00:00
|
|
|
check_warn_goto_done(ret, "Error reading WUCSR\n");
|
2012-10-30 07:46:32 +00:00
|
|
|
|
|
|
|
/* clear any pending magic packet status */
|
|
|
|
val |= WUCSR_MPR | WUCSR_MPEN;
|
|
|
|
|
2012-11-06 04:53:05 +00:00
|
|
|
ret = smsc75xx_write_reg_nopm(dev, WUCSR, val);
|
2012-11-28 05:59:48 +00:00
|
|
|
check_warn_goto_done(ret, "Error writing WUCSR\n");
|
2012-09-28 00:57:53 +00:00
|
|
|
}
|
|
|
|
|
2012-10-30 07:46:32 +00:00
|
|
|
if (pdata->wolopts & WAKE_BCAST) {
|
2012-11-24 01:27:49 +00:00
|
|
|
netdev_info(dev->net, "enabling broadcast detection\n");
|
2012-11-06 04:53:05 +00:00
|
|
|
ret = smsc75xx_read_reg_nopm(dev, WUCSR, &val);
|
2012-11-28 05:59:48 +00:00
|
|
|
check_warn_goto_done(ret, "Error reading WUCSR\n");
|
2012-09-28 00:57:53 +00:00
|
|
|
|
2012-10-30 07:46:32 +00:00
|
|
|
val |= WUCSR_BCAST_FR | WUCSR_BCST_EN;
|
2012-09-28 00:57:52 +00:00
|
|
|
|
2012-11-06 04:53:05 +00:00
|
|
|
ret = smsc75xx_write_reg_nopm(dev, WUCSR, val);
|
2012-11-28 05:59:48 +00:00
|
|
|
check_warn_goto_done(ret, "Error writing WUCSR\n");
|
2012-10-30 07:46:32 +00:00
|
|
|
}
|
2012-09-28 00:57:53 +00:00
|
|
|
|
2012-10-30 07:46:32 +00:00
|
|
|
if (pdata->wolopts & WAKE_UCAST) {
|
2012-11-24 01:27:49 +00:00
|
|
|
netdev_info(dev->net, "enabling unicast detection\n");
|
2012-11-06 04:53:05 +00:00
|
|
|
ret = smsc75xx_read_reg_nopm(dev, WUCSR, &val);
|
2012-11-28 05:59:48 +00:00
|
|
|
check_warn_goto_done(ret, "Error reading WUCSR\n");
|
2012-10-30 07:46:32 +00:00
|
|
|
|
|
|
|
val |= WUCSR_WUFR | WUCSR_PFDA_EN;
|
2012-09-28 00:57:53 +00:00
|
|
|
|
2012-11-06 04:53:05 +00:00
|
|
|
ret = smsc75xx_write_reg_nopm(dev, WUCSR, val);
|
2012-11-28 05:59:48 +00:00
|
|
|
check_warn_goto_done(ret, "Error writing WUCSR\n");
|
2012-10-30 07:46:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* enable receiver to enable frame reception */
|
2012-11-06 04:53:05 +00:00
|
|
|
ret = smsc75xx_read_reg_nopm(dev, MAC_RX, &val);
|
2012-11-28 05:59:48 +00:00
|
|
|
check_warn_goto_done(ret, "Failed to read MAC_RX: %d\n", ret);
|
2012-09-28 00:57:53 +00:00
|
|
|
|
|
|
|
val |= MAC_RX_RXEN;
|
|
|
|
|
2012-11-06 04:53:05 +00:00
|
|
|
ret = smsc75xx_write_reg_nopm(dev, MAC_RX, val);
|
2012-11-28 05:59:48 +00:00
|
|
|
check_warn_goto_done(ret, "Failed to write MAC_RX: %d\n", ret);
|
2012-09-28 00:57:53 +00:00
|
|
|
|
|
|
|
/* some wol options are enabled, so enter SUSPEND0 */
|
2012-11-24 01:27:49 +00:00
|
|
|
netdev_info(dev->net, "entering SUSPEND0 mode\n");
|
2012-11-28 05:59:48 +00:00
|
|
|
ret = smsc75xx_enter_suspend0(dev);
|
|
|
|
|
|
|
|
done:
|
|
|
|
if (ret)
|
|
|
|
usbnet_resume(intf);
|
|
|
|
return ret;
|
2012-09-28 00:57:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int smsc75xx_resume(struct usb_interface *intf)
|
|
|
|
{
|
|
|
|
struct usbnet *dev = usb_get_intfdata(intf);
|
2012-09-28 00:57:53 +00:00
|
|
|
struct smsc75xx_priv *pdata = (struct smsc75xx_priv *)(dev->data[0]);
|
2012-09-28 00:57:52 +00:00
|
|
|
int ret;
|
|
|
|
u32 val;
|
|
|
|
|
2012-10-30 07:46:32 +00:00
|
|
|
if (pdata->wolopts) {
|
2012-11-24 01:27:49 +00:00
|
|
|
netdev_info(dev->net, "resuming from SUSPEND0\n");
|
2012-09-28 00:57:52 +00:00
|
|
|
|
2012-09-28 00:57:53 +00:00
|
|
|
smsc75xx_clear_feature(dev, USB_DEVICE_REMOTE_WAKEUP);
|
2012-09-28 00:57:52 +00:00
|
|
|
|
2012-10-30 07:46:32 +00:00
|
|
|
/* Disable wakeup sources */
|
2012-11-06 04:53:05 +00:00
|
|
|
ret = smsc75xx_read_reg_nopm(dev, WUCSR, &val);
|
2012-11-24 01:27:49 +00:00
|
|
|
check_warn_return(ret, "Error reading WUCSR\n");
|
2012-09-28 00:57:52 +00:00
|
|
|
|
2012-10-30 07:46:32 +00:00
|
|
|
val &= ~(WUCSR_WUEN | WUCSR_MPEN | WUCSR_PFDA_EN
|
|
|
|
| WUCSR_BCST_EN);
|
2012-09-28 00:57:52 +00:00
|
|
|
|
2012-11-06 04:53:05 +00:00
|
|
|
ret = smsc75xx_write_reg_nopm(dev, WUCSR, val);
|
2012-11-24 01:27:49 +00:00
|
|
|
check_warn_return(ret, "Error writing WUCSR\n");
|
2012-09-28 00:57:53 +00:00
|
|
|
|
|
|
|
/* clear wake-up status */
|
2012-11-06 04:53:05 +00:00
|
|
|
ret = smsc75xx_read_reg_nopm(dev, PMT_CTL, &val);
|
2012-11-24 01:27:49 +00:00
|
|
|
check_warn_return(ret, "Error reading PMT_CTL\n");
|
2012-09-28 00:57:53 +00:00
|
|
|
|
|
|
|
val &= ~PMT_CTL_WOL_EN;
|
|
|
|
val |= PMT_CTL_WUPS;
|
|
|
|
|
2012-11-06 04:53:05 +00:00
|
|
|
ret = smsc75xx_write_reg_nopm(dev, PMT_CTL, val);
|
2012-11-24 01:27:49 +00:00
|
|
|
check_warn_return(ret, "Error writing PMT_CTL\n");
|
2012-09-28 00:57:53 +00:00
|
|
|
} else {
|
2012-11-24 01:27:49 +00:00
|
|
|
netdev_info(dev->net, "resuming from SUSPEND2\n");
|
2012-09-28 00:57:53 +00:00
|
|
|
|
2012-11-06 04:53:05 +00:00
|
|
|
ret = smsc75xx_read_reg_nopm(dev, PMT_CTL, &val);
|
2012-11-24 01:27:49 +00:00
|
|
|
check_warn_return(ret, "Error reading PMT_CTL\n");
|
2012-09-28 00:57:53 +00:00
|
|
|
|
|
|
|
val |= PMT_CTL_PHY_PWRUP;
|
|
|
|
|
2012-11-06 04:53:05 +00:00
|
|
|
ret = smsc75xx_write_reg_nopm(dev, PMT_CTL, val);
|
2012-11-24 01:27:49 +00:00
|
|
|
check_warn_return(ret, "Error writing PMT_CTL\n");
|
2012-09-28 00:57:53 +00:00
|
|
|
}
|
2012-09-28 00:57:52 +00:00
|
|
|
|
2012-11-06 04:53:05 +00:00
|
|
|
ret = smsc75xx_wait_ready(dev, 1);
|
2012-11-24 01:27:49 +00:00
|
|
|
check_warn_return(ret, "device not ready in smsc75xx_resume\n");
|
2012-09-28 00:57:52 +00:00
|
|
|
|
|
|
|
return usbnet_resume(intf);
|
|
|
|
}
|
|
|
|
|
2011-04-02 03:56:23 +00:00
|
|
|
static void smsc75xx_rx_csum_offload(struct usbnet *dev, struct sk_buff *skb,
|
|
|
|
u32 rx_cmd_a, u32 rx_cmd_b)
|
2010-03-16 08:46:46 +00:00
|
|
|
{
|
2011-04-02 03:56:23 +00:00
|
|
|
if (!(dev->net->features & NETIF_F_RXCSUM) ||
|
|
|
|
unlikely(rx_cmd_a & RX_CMD_A_LCSM)) {
|
2010-03-16 08:46:46 +00:00
|
|
|
skb->ip_summed = CHECKSUM_NONE;
|
|
|
|
} else {
|
|
|
|
skb->csum = ntohs((u16)(rx_cmd_b >> RX_CMD_B_CSUM_SHIFT));
|
|
|
|
skb->ip_summed = CHECKSUM_COMPLETE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static int smsc75xx_rx_fixup(struct usbnet *dev, struct sk_buff *skb)
|
|
|
|
{
|
|
|
|
while (skb->len > 0) {
|
|
|
|
u32 rx_cmd_a, rx_cmd_b, align_count, size;
|
|
|
|
struct sk_buff *ax_skb;
|
|
|
|
unsigned char *packet;
|
|
|
|
|
|
|
|
memcpy(&rx_cmd_a, skb->data, sizeof(rx_cmd_a));
|
|
|
|
le32_to_cpus(&rx_cmd_a);
|
|
|
|
skb_pull(skb, 4);
|
|
|
|
|
|
|
|
memcpy(&rx_cmd_b, skb->data, sizeof(rx_cmd_b));
|
|
|
|
le32_to_cpus(&rx_cmd_b);
|
2011-11-08 07:30:40 +00:00
|
|
|
skb_pull(skb, 4 + RXW_PADDING);
|
2010-03-16 08:46:46 +00:00
|
|
|
|
|
|
|
packet = skb->data;
|
|
|
|
|
|
|
|
/* get the packet length */
|
2011-11-08 07:30:40 +00:00
|
|
|
size = (rx_cmd_a & RX_CMD_A_LEN) - RXW_PADDING;
|
|
|
|
align_count = (4 - ((size + RXW_PADDING) % 4)) % 4;
|
2010-03-16 08:46:46 +00:00
|
|
|
|
|
|
|
if (unlikely(rx_cmd_a & RX_CMD_A_RED)) {
|
|
|
|
netif_dbg(dev, rx_err, dev->net,
|
2012-11-24 01:27:49 +00:00
|
|
|
"Error rx_cmd_a=0x%08x\n", rx_cmd_a);
|
2010-03-16 08:46:46 +00:00
|
|
|
dev->net->stats.rx_errors++;
|
|
|
|
dev->net->stats.rx_dropped++;
|
|
|
|
|
|
|
|
if (rx_cmd_a & RX_CMD_A_FCS)
|
|
|
|
dev->net->stats.rx_crc_errors++;
|
|
|
|
else if (rx_cmd_a & (RX_CMD_A_LONG | RX_CMD_A_RUNT))
|
|
|
|
dev->net->stats.rx_frame_errors++;
|
|
|
|
} else {
|
|
|
|
/* ETH_FRAME_LEN + 4(CRC) + 2(COE) + 4(Vlan) */
|
|
|
|
if (unlikely(size > (ETH_FRAME_LEN + 12))) {
|
|
|
|
netif_dbg(dev, rx_err, dev->net,
|
2012-11-24 01:27:49 +00:00
|
|
|
"size err rx_cmd_a=0x%08x\n",
|
|
|
|
rx_cmd_a);
|
2010-03-16 08:46:46 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* last frame in this batch */
|
|
|
|
if (skb->len == size) {
|
2011-04-02 03:56:23 +00:00
|
|
|
smsc75xx_rx_csum_offload(dev, skb, rx_cmd_a,
|
|
|
|
rx_cmd_b);
|
2010-03-16 08:46:46 +00:00
|
|
|
|
|
|
|
skb_trim(skb, skb->len - 4); /* remove fcs */
|
|
|
|
skb->truesize = size + sizeof(struct sk_buff);
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
ax_skb = skb_clone(skb, GFP_ATOMIC);
|
|
|
|
if (unlikely(!ax_skb)) {
|
2012-11-24 01:27:49 +00:00
|
|
|
netdev_warn(dev->net, "Error allocating skb\n");
|
2010-03-16 08:46:46 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
ax_skb->len = size;
|
|
|
|
ax_skb->data = packet;
|
|
|
|
skb_set_tail_pointer(ax_skb, size);
|
|
|
|
|
2011-04-02 03:56:23 +00:00
|
|
|
smsc75xx_rx_csum_offload(dev, ax_skb, rx_cmd_a,
|
|
|
|
rx_cmd_b);
|
2010-03-16 08:46:46 +00:00
|
|
|
|
|
|
|
skb_trim(ax_skb, ax_skb->len - 4); /* remove fcs */
|
|
|
|
ax_skb->truesize = size + sizeof(struct sk_buff);
|
|
|
|
|
|
|
|
usbnet_skb_return(dev, ax_skb);
|
|
|
|
}
|
|
|
|
|
|
|
|
skb_pull(skb, size);
|
|
|
|
|
|
|
|
/* padding bytes before the next frame starts */
|
|
|
|
if (skb->len)
|
|
|
|
skb_pull(skb, align_count);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (unlikely(skb->len < 0)) {
|
2012-11-24 01:27:49 +00:00
|
|
|
netdev_warn(dev->net, "invalid rx length<0 %d\n", skb->len);
|
2010-03-16 08:46:46 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct sk_buff *smsc75xx_tx_fixup(struct usbnet *dev,
|
|
|
|
struct sk_buff *skb, gfp_t flags)
|
|
|
|
{
|
|
|
|
u32 tx_cmd_a, tx_cmd_b;
|
|
|
|
|
|
|
|
skb_linearize(skb);
|
|
|
|
|
|
|
|
if (skb_headroom(skb) < SMSC75XX_TX_OVERHEAD) {
|
|
|
|
struct sk_buff *skb2 =
|
|
|
|
skb_copy_expand(skb, SMSC75XX_TX_OVERHEAD, 0, flags);
|
|
|
|
dev_kfree_skb_any(skb);
|
|
|
|
skb = skb2;
|
|
|
|
if (!skb)
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
tx_cmd_a = (u32)(skb->len & TX_CMD_A_LEN) | TX_CMD_A_FCS;
|
|
|
|
|
|
|
|
if (skb->ip_summed == CHECKSUM_PARTIAL)
|
|
|
|
tx_cmd_a |= TX_CMD_A_IPE | TX_CMD_A_TPE;
|
|
|
|
|
|
|
|
if (skb_is_gso(skb)) {
|
|
|
|
u16 mss = max(skb_shinfo(skb)->gso_size, TX_MSS_MIN);
|
|
|
|
tx_cmd_b = (mss << TX_CMD_B_MSS_SHIFT) & TX_CMD_B_MSS;
|
|
|
|
|
|
|
|
tx_cmd_a |= TX_CMD_A_LSO;
|
|
|
|
} else {
|
|
|
|
tx_cmd_b = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
skb_push(skb, 4);
|
|
|
|
cpu_to_le32s(&tx_cmd_b);
|
|
|
|
memcpy(skb->data, &tx_cmd_b, 4);
|
|
|
|
|
|
|
|
skb_push(skb, 4);
|
|
|
|
cpu_to_le32s(&tx_cmd_a);
|
|
|
|
memcpy(skb->data, &tx_cmd_a, 4);
|
|
|
|
|
|
|
|
return skb;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const struct driver_info smsc75xx_info = {
|
|
|
|
.description = "smsc75xx USB 2.0 Gigabit Ethernet",
|
|
|
|
.bind = smsc75xx_bind,
|
|
|
|
.unbind = smsc75xx_unbind,
|
|
|
|
.link_reset = smsc75xx_link_reset,
|
|
|
|
.reset = smsc75xx_reset,
|
|
|
|
.rx_fixup = smsc75xx_rx_fixup,
|
|
|
|
.tx_fixup = smsc75xx_tx_fixup,
|
|
|
|
.status = smsc75xx_status,
|
2012-04-30 07:56:50 +00:00
|
|
|
.flags = FLAG_ETHER | FLAG_SEND_ZLP | FLAG_LINK_INTR,
|
2010-03-16 08:46:46 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static const struct usb_device_id products[] = {
|
|
|
|
{
|
|
|
|
/* SMSC7500 USB Gigabit Ethernet Device */
|
|
|
|
USB_DEVICE(USB_VENDOR_ID_SMSC, USB_PRODUCT_ID_LAN7500),
|
|
|
|
.driver_info = (unsigned long) &smsc75xx_info,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
/* SMSC7500 USB Gigabit Ethernet Device */
|
|
|
|
USB_DEVICE(USB_VENDOR_ID_SMSC, USB_PRODUCT_ID_LAN7505),
|
|
|
|
.driver_info = (unsigned long) &smsc75xx_info,
|
|
|
|
},
|
|
|
|
{ }, /* END */
|
|
|
|
};
|
|
|
|
MODULE_DEVICE_TABLE(usb, products);
|
|
|
|
|
|
|
|
static struct usb_driver smsc75xx_driver = {
|
|
|
|
.name = SMSC_CHIPNAME,
|
|
|
|
.id_table = products,
|
|
|
|
.probe = usbnet_probe,
|
2012-09-28 00:57:52 +00:00
|
|
|
.suspend = smsc75xx_suspend,
|
|
|
|
.resume = smsc75xx_resume,
|
|
|
|
.reset_resume = smsc75xx_resume,
|
2010-03-16 08:46:46 +00:00
|
|
|
.disconnect = usbnet_disconnect,
|
2012-04-23 17:08:51 +00:00
|
|
|
.disable_hub_initiated_lpm = 1,
|
2010-03-16 08:46:46 +00:00
|
|
|
};
|
|
|
|
|
2011-11-18 17:44:20 +00:00
|
|
|
module_usb_driver(smsc75xx_driver);
|
2010-03-16 08:46:46 +00:00
|
|
|
|
|
|
|
MODULE_AUTHOR("Nancy Lin");
|
2012-04-16 11:13:29 +00:00
|
|
|
MODULE_AUTHOR("Steve Glendinning <steve.glendinning@shawell.net>");
|
2010-03-16 08:46:46 +00:00
|
|
|
MODULE_DESCRIPTION("SMSC75XX USB 2.0 Gigabit Ethernet Devices");
|
|
|
|
MODULE_LICENSE("GPL");
|