xref: /linux/drivers/net/usb/smsc95xx.c (revision a7021af707a3637c963ce41802b650db6793eb8a)
11ccea77eSThomas Gleixner // SPDX-License-Identifier: GPL-2.0-or-later
22f7ca802SSteve Glendinning  /***************************************************************************
32f7ca802SSteve Glendinning  *
42f7ca802SSteve Glendinning  * Copyright (C) 2007-2008 SMSC
52f7ca802SSteve Glendinning  *
62f7ca802SSteve Glendinning  *****************************************************************************/
72f7ca802SSteve Glendinning 
82f7ca802SSteve Glendinning #include <linux/module.h>
92f7ca802SSteve Glendinning #include <linux/kmod.h>
102f7ca802SSteve Glendinning #include <linux/netdevice.h>
112f7ca802SSteve Glendinning #include <linux/etherdevice.h>
122f7ca802SSteve Glendinning #include <linux/ethtool.h>
132f7ca802SSteve Glendinning #include <linux/mii.h>
142f7ca802SSteve Glendinning #include <linux/usb.h>
15bbd9f9eeSSteve Glendinning #include <linux/bitrev.h>
16bbd9f9eeSSteve Glendinning #include <linux/crc16.h>
172f7ca802SSteve Glendinning #include <linux/crc32.h>
182f7ca802SSteve Glendinning #include <linux/usb/usbnet.h>
195a0e3ad6STejun Heo #include <linux/slab.h>
20c489565bSArnd Bergmann #include <linux/of_net.h>
2105b35e7eSAndre Edich #include <linux/mdio.h>
2205b35e7eSAndre Edich #include <linux/phy.h>
232f7ca802SSteve Glendinning #include "smsc95xx.h"
242f7ca802SSteve Glendinning 
252f7ca802SSteve Glendinning #define SMSC_CHIPNAME			"smsc95xx"
2605b35e7eSAndre Edich #define SMSC_DRIVER_VERSION		"2.0.0"
272f7ca802SSteve Glendinning #define HS_USB_PKT_SIZE			(512)
282f7ca802SSteve Glendinning #define FS_USB_PKT_SIZE			(64)
292f7ca802SSteve Glendinning #define DEFAULT_HS_BURST_CAP_SIZE	(16 * 1024 + 5 * HS_USB_PKT_SIZE)
302f7ca802SSteve Glendinning #define DEFAULT_FS_BURST_CAP_SIZE	(6 * 1024 + 33 * FS_USB_PKT_SIZE)
312f7ca802SSteve Glendinning #define DEFAULT_BULK_IN_DELAY		(0x00002000)
322f7ca802SSteve Glendinning #define MAX_SINGLE_PACKET_SIZE		(2048)
332f7ca802SSteve Glendinning #define LAN95XX_EEPROM_MAGIC		(0x9500)
342f7ca802SSteve Glendinning #define EEPROM_MAC_OFFSET		(0x01)
35f7b29271SSteve Glendinning #define DEFAULT_TX_CSUM_ENABLE		(true)
362f7ca802SSteve Glendinning #define DEFAULT_RX_CSUM_ENABLE		(true)
372f7ca802SSteve Glendinning #define SMSC95XX_INTERNAL_PHY_ID	(1)
382f7ca802SSteve Glendinning #define SMSC95XX_TX_OVERHEAD		(8)
39f7b29271SSteve Glendinning #define SMSC95XX_TX_OVERHEAD_CSUM	(12)
40e5e3af83SSteve Glendinning #define SUPPORTED_WAKE			(WAKE_PHY | WAKE_UCAST | WAKE_BCAST | \
41bbd9f9eeSSteve Glendinning 					 WAKE_MCAST | WAKE_ARP | WAKE_MAGIC)
422f7ca802SSteve Glendinning 
439ebca507SSteve Glendinning #define FEATURE_8_WAKEUP_FILTERS	(0x01)
449ebca507SSteve Glendinning #define FEATURE_PHY_NLP_CROSSOVER	(0x02)
45eb970ff0SMing Lei #define FEATURE_REMOTE_WAKEUP		(0x04)
469ebca507SSteve Glendinning 
47b2d4b150SSteve Glendinning #define SUSPEND_SUSPEND0		(0x01)
48b2d4b150SSteve Glendinning #define SUSPEND_SUSPEND1		(0x02)
49b2d4b150SSteve Glendinning #define SUSPEND_SUSPEND2		(0x04)
50b2d4b150SSteve Glendinning #define SUSPEND_SUSPEND3		(0x08)
51b2d4b150SSteve Glendinning #define SUSPEND_ALLMODES		(SUSPEND_SUSPEND0 | SUSPEND_SUSPEND1 | \
52b2d4b150SSteve Glendinning 					 SUSPEND_SUSPEND2 | SUSPEND_SUSPEND3)
53b2d4b150SSteve Glendinning 
542f7ca802SSteve Glendinning struct smsc95xx_priv {
552f7ca802SSteve Glendinning 	u32 mac_cr;
563c0f3c60SMarc Zyngier 	u32 hash_hi;
573c0f3c60SMarc Zyngier 	u32 hash_lo;
58e0e474a8SSteve Glendinning 	u32 wolopts;
592f7ca802SSteve Glendinning 	spinlock_t mac_cr_lock;
609ebca507SSteve Glendinning 	u8 features;
61b2d4b150SSteve Glendinning 	u8 suspend_flags;
6205b35e7eSAndre Edich 	struct mii_bus *mdiobus;
6305b35e7eSAndre Edich 	struct phy_device *phydev;
642f7ca802SSteve Glendinning };
652f7ca802SSteve Glendinning 
66eb939922SRusty Russell static bool turbo_mode = true;
672f7ca802SSteve Glendinning module_param(turbo_mode, bool, 0644);
682f7ca802SSteve Glendinning MODULE_PARM_DESC(turbo_mode, "Enable multiple frames per Rx transaction");
692f7ca802SSteve Glendinning 
70ec32115dSMing Lei static int __must_check __smsc95xx_read_reg(struct usbnet *dev, u32 index,
71ec32115dSMing Lei 					    u32 *data, int in_pm)
722f7ca802SSteve Glendinning {
7372108fd2SMing Lei 	u32 buf;
742f7ca802SSteve Glendinning 	int ret;
75ec32115dSMing Lei 	int (*fn)(struct usbnet *, u8, u8, u16, u16, void *, u16);
762f7ca802SSteve Glendinning 
772f7ca802SSteve Glendinning 	BUG_ON(!dev);
782f7ca802SSteve Glendinning 
79ec32115dSMing Lei 	if (!in_pm)
80ec32115dSMing Lei 		fn = usbnet_read_cmd;
81ec32115dSMing Lei 	else
82ec32115dSMing Lei 		fn = usbnet_read_cmd_nopm;
83ec32115dSMing Lei 
84ec32115dSMing Lei 	ret = fn(dev, USB_VENDOR_REQUEST_READ_REGISTER, USB_DIR_IN
85ec32115dSMing Lei 		 | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
8672108fd2SMing Lei 		 0, index, &buf, 4);
875a36b68bSDan Carpenter 	if (unlikely(ret < 0)) {
881e1d7412SJoe Perches 		netdev_warn(dev->net, "Failed to read reg index 0x%08x: %d\n",
891e1d7412SJoe Perches 			    index, ret);
905a36b68bSDan Carpenter 		return ret;
915a36b68bSDan Carpenter 	}
922f7ca802SSteve Glendinning 
9372108fd2SMing Lei 	le32_to_cpus(&buf);
9472108fd2SMing Lei 	*data = buf;
952f7ca802SSteve Glendinning 
962f7ca802SSteve Glendinning 	return ret;
972f7ca802SSteve Glendinning }
982f7ca802SSteve Glendinning 
99ec32115dSMing Lei static int __must_check __smsc95xx_write_reg(struct usbnet *dev, u32 index,
100ec32115dSMing Lei 					     u32 data, int in_pm)
1012f7ca802SSteve Glendinning {
10272108fd2SMing Lei 	u32 buf;
1032f7ca802SSteve Glendinning 	int ret;
104ec32115dSMing Lei 	int (*fn)(struct usbnet *, u8, u8, u16, u16, const void *, u16);
1052f7ca802SSteve Glendinning 
1062f7ca802SSteve Glendinning 	BUG_ON(!dev);
1072f7ca802SSteve Glendinning 
108ec32115dSMing Lei 	if (!in_pm)
109ec32115dSMing Lei 		fn = usbnet_write_cmd;
110ec32115dSMing Lei 	else
111ec32115dSMing Lei 		fn = usbnet_write_cmd_nopm;
112ec32115dSMing Lei 
11372108fd2SMing Lei 	buf = data;
11472108fd2SMing Lei 	cpu_to_le32s(&buf);
1152f7ca802SSteve Glendinning 
116ec32115dSMing Lei 	ret = fn(dev, USB_VENDOR_REQUEST_WRITE_REGISTER, USB_DIR_OUT
117ec32115dSMing Lei 		 | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
11872108fd2SMing Lei 		 0, index, &buf, 4);
1192f7ca802SSteve Glendinning 	if (unlikely(ret < 0))
1201e1d7412SJoe Perches 		netdev_warn(dev->net, "Failed to write reg index 0x%08x: %d\n",
1211e1d7412SJoe Perches 			    index, ret);
1222f7ca802SSteve Glendinning 
1232f7ca802SSteve Glendinning 	return ret;
1242f7ca802SSteve Glendinning }
1252f7ca802SSteve Glendinning 
126ec32115dSMing Lei static int __must_check smsc95xx_read_reg_nopm(struct usbnet *dev, u32 index,
127ec32115dSMing Lei 					       u32 *data)
128ec32115dSMing Lei {
129ec32115dSMing Lei 	return __smsc95xx_read_reg(dev, index, data, 1);
130ec32115dSMing Lei }
131ec32115dSMing Lei 
132ec32115dSMing Lei static int __must_check smsc95xx_write_reg_nopm(struct usbnet *dev, u32 index,
133ec32115dSMing Lei 						u32 data)
134ec32115dSMing Lei {
135ec32115dSMing Lei 	return __smsc95xx_write_reg(dev, index, data, 1);
136ec32115dSMing Lei }
137ec32115dSMing Lei 
138ec32115dSMing Lei static int __must_check smsc95xx_read_reg(struct usbnet *dev, u32 index,
139ec32115dSMing Lei 					  u32 *data)
140ec32115dSMing Lei {
141ec32115dSMing Lei 	return __smsc95xx_read_reg(dev, index, data, 0);
142ec32115dSMing Lei }
143ec32115dSMing Lei 
144ec32115dSMing Lei static int __must_check smsc95xx_write_reg(struct usbnet *dev, u32 index,
145ec32115dSMing Lei 					   u32 data)
146ec32115dSMing Lei {
147ec32115dSMing Lei 	return __smsc95xx_write_reg(dev, index, data, 0);
148ec32115dSMing Lei }
149e0e474a8SSteve Glendinning 
1502f7ca802SSteve Glendinning /* Loop until the read is completed with timeout
1512f7ca802SSteve Glendinning  * called with phy_mutex held */
152e5e3af83SSteve Glendinning static int __must_check __smsc95xx_phy_wait_not_busy(struct usbnet *dev,
153e5e3af83SSteve Glendinning 						     int in_pm)
1542f7ca802SSteve Glendinning {
1552f7ca802SSteve Glendinning 	unsigned long start_time = jiffies;
1562f7ca802SSteve Glendinning 	u32 val;
157769ea6d8SSteve Glendinning 	int ret;
1582f7ca802SSteve Glendinning 
1592f7ca802SSteve Glendinning 	do {
160e5e3af83SSteve Glendinning 		ret = __smsc95xx_read_reg(dev, MII_ADDR, &val, in_pm);
161b052e073SSteve Glendinning 		if (ret < 0) {
162b052e073SSteve Glendinning 			netdev_warn(dev->net, "Error reading MII_ACCESS\n");
163b052e073SSteve Glendinning 			return ret;
164b052e073SSteve Glendinning 		}
165b052e073SSteve Glendinning 
1662f7ca802SSteve Glendinning 		if (!(val & MII_BUSY_))
1672f7ca802SSteve Glendinning 			return 0;
1682f7ca802SSteve Glendinning 	} while (!time_after(jiffies, start_time + HZ));
1692f7ca802SSteve Glendinning 
1702f7ca802SSteve Glendinning 	return -EIO;
1712f7ca802SSteve Glendinning }
1722f7ca802SSteve Glendinning 
17305b35e7eSAndre Edich static u32 mii_address_cmd(int phy_id, int idx, u16 op)
17405b35e7eSAndre Edich {
17505b35e7eSAndre Edich 	return (phy_id & 0x1f) << 11 | (idx & 0x1f) << 6 | op;
17605b35e7eSAndre Edich }
17705b35e7eSAndre Edich 
17805b35e7eSAndre Edich static int __smsc95xx_mdio_read(struct usbnet *dev, int phy_id, int idx,
179e5e3af83SSteve Glendinning 				int in_pm)
1802f7ca802SSteve Glendinning {
1812f7ca802SSteve Glendinning 	u32 val, addr;
182769ea6d8SSteve Glendinning 	int ret;
1832f7ca802SSteve Glendinning 
1842f7ca802SSteve Glendinning 	mutex_lock(&dev->phy_mutex);
1852f7ca802SSteve Glendinning 
1862f7ca802SSteve Glendinning 	/* confirm MII not busy */
187e5e3af83SSteve Glendinning 	ret = __smsc95xx_phy_wait_not_busy(dev, in_pm);
188b052e073SSteve Glendinning 	if (ret < 0) {
18905b35e7eSAndre Edich 		netdev_warn(dev->net, "%s: MII is busy\n", __func__);
190b052e073SSteve Glendinning 		goto done;
191b052e073SSteve Glendinning 	}
1922f7ca802SSteve Glendinning 
1932f7ca802SSteve Glendinning 	/* set the address, index & direction (read from PHY) */
19405b35e7eSAndre Edich 	addr = mii_address_cmd(phy_id, idx, MII_READ_ | MII_BUSY_);
195e5e3af83SSteve Glendinning 	ret = __smsc95xx_write_reg(dev, MII_ADDR, addr, in_pm);
196b052e073SSteve Glendinning 	if (ret < 0) {
197b052e073SSteve Glendinning 		netdev_warn(dev->net, "Error writing MII_ADDR\n");
198b052e073SSteve Glendinning 		goto done;
199b052e073SSteve Glendinning 	}
2002f7ca802SSteve Glendinning 
201e5e3af83SSteve Glendinning 	ret = __smsc95xx_phy_wait_not_busy(dev, in_pm);
202b052e073SSteve Glendinning 	if (ret < 0) {
203b052e073SSteve Glendinning 		netdev_warn(dev->net, "Timed out reading MII reg %02X\n", idx);
204b052e073SSteve Glendinning 		goto done;
205b052e073SSteve Glendinning 	}
206769ea6d8SSteve Glendinning 
207e5e3af83SSteve Glendinning 	ret = __smsc95xx_read_reg(dev, MII_DATA, &val, in_pm);
208b052e073SSteve Glendinning 	if (ret < 0) {
209b052e073SSteve Glendinning 		netdev_warn(dev->net, "Error reading MII_DATA\n");
210b052e073SSteve Glendinning 		goto done;
211b052e073SSteve Glendinning 	}
212769ea6d8SSteve Glendinning 
213769ea6d8SSteve Glendinning 	ret = (u16)(val & 0xFFFF);
214769ea6d8SSteve Glendinning 
215769ea6d8SSteve Glendinning done:
2162f7ca802SSteve Glendinning 	mutex_unlock(&dev->phy_mutex);
217769ea6d8SSteve Glendinning 	return ret;
2182f7ca802SSteve Glendinning }
2192f7ca802SSteve Glendinning 
22005b35e7eSAndre Edich static void __smsc95xx_mdio_write(struct usbnet *dev, int phy_id,
221e5e3af83SSteve Glendinning 				  int idx, int regval, int in_pm)
2222f7ca802SSteve Glendinning {
2232f7ca802SSteve Glendinning 	u32 val, addr;
224769ea6d8SSteve Glendinning 	int ret;
2252f7ca802SSteve Glendinning 
2262f7ca802SSteve Glendinning 	mutex_lock(&dev->phy_mutex);
2272f7ca802SSteve Glendinning 
2282f7ca802SSteve Glendinning 	/* confirm MII not busy */
229e5e3af83SSteve Glendinning 	ret = __smsc95xx_phy_wait_not_busy(dev, in_pm);
230b052e073SSteve Glendinning 	if (ret < 0) {
23105b35e7eSAndre Edich 		netdev_warn(dev->net, "%s: MII is busy\n", __func__);
232b052e073SSteve Glendinning 		goto done;
233b052e073SSteve Glendinning 	}
2342f7ca802SSteve Glendinning 
2352f7ca802SSteve Glendinning 	val = regval;
236e5e3af83SSteve Glendinning 	ret = __smsc95xx_write_reg(dev, MII_DATA, val, in_pm);
237b052e073SSteve Glendinning 	if (ret < 0) {
238b052e073SSteve Glendinning 		netdev_warn(dev->net, "Error writing MII_DATA\n");
239b052e073SSteve Glendinning 		goto done;
240b052e073SSteve Glendinning 	}
2412f7ca802SSteve Glendinning 
2422f7ca802SSteve Glendinning 	/* set the address, index & direction (write to PHY) */
24305b35e7eSAndre Edich 	addr = mii_address_cmd(phy_id, idx, MII_WRITE_ | MII_BUSY_);
244e5e3af83SSteve Glendinning 	ret = __smsc95xx_write_reg(dev, MII_ADDR, addr, in_pm);
245b052e073SSteve Glendinning 	if (ret < 0) {
246b052e073SSteve Glendinning 		netdev_warn(dev->net, "Error writing MII_ADDR\n");
247b052e073SSteve Glendinning 		goto done;
248b052e073SSteve Glendinning 	}
2492f7ca802SSteve Glendinning 
250e5e3af83SSteve Glendinning 	ret = __smsc95xx_phy_wait_not_busy(dev, in_pm);
251b052e073SSteve Glendinning 	if (ret < 0) {
252b052e073SSteve Glendinning 		netdev_warn(dev->net, "Timed out writing MII reg %02X\n", idx);
253b052e073SSteve Glendinning 		goto done;
254b052e073SSteve Glendinning 	}
2552f7ca802SSteve Glendinning 
256769ea6d8SSteve Glendinning done:
2572f7ca802SSteve Glendinning 	mutex_unlock(&dev->phy_mutex);
2582f7ca802SSteve Glendinning }
2592f7ca802SSteve Glendinning 
260368be1caSAndre Edich static int smsc95xx_mdio_read_nopm(struct usbnet *dev, int idx)
261e5e3af83SSteve Glendinning {
26205b35e7eSAndre Edich 	struct smsc95xx_priv *pdata = dev->driver_priv;
263368be1caSAndre Edich 
26405b35e7eSAndre Edich 	return __smsc95xx_mdio_read(dev, pdata->phydev->mdio.addr, idx, 1);
265e5e3af83SSteve Glendinning }
266e5e3af83SSteve Glendinning 
267368be1caSAndre Edich static void smsc95xx_mdio_write_nopm(struct usbnet *dev, int idx, int regval)
268e5e3af83SSteve Glendinning {
26905b35e7eSAndre Edich 	struct smsc95xx_priv *pdata = dev->driver_priv;
270368be1caSAndre Edich 
27105b35e7eSAndre Edich 	__smsc95xx_mdio_write(dev, pdata->phydev->mdio.addr, idx, regval, 1);
272e5e3af83SSteve Glendinning }
273e5e3af83SSteve Glendinning 
27405b35e7eSAndre Edich static int smsc95xx_mdiobus_read(struct mii_bus *bus, int phy_id, int idx)
275e5e3af83SSteve Glendinning {
27605b35e7eSAndre Edich 	struct usbnet *dev = bus->priv;
27705b35e7eSAndre Edich 
27805b35e7eSAndre Edich 	return __smsc95xx_mdio_read(dev, phy_id, idx, 0);
279e5e3af83SSteve Glendinning }
280e5e3af83SSteve Glendinning 
28105b35e7eSAndre Edich static int smsc95xx_mdiobus_write(struct mii_bus *bus, int phy_id, int idx,
28205b35e7eSAndre Edich 				  u16 regval)
283e5e3af83SSteve Glendinning {
28405b35e7eSAndre Edich 	struct usbnet *dev = bus->priv;
28505b35e7eSAndre Edich 
28605b35e7eSAndre Edich 	__smsc95xx_mdio_write(dev, phy_id, idx, regval, 0);
28705b35e7eSAndre Edich 	return 0;
288e5e3af83SSteve Glendinning }
289e5e3af83SSteve Glendinning 
290769ea6d8SSteve Glendinning static int __must_check smsc95xx_wait_eeprom(struct usbnet *dev)
2912f7ca802SSteve Glendinning {
2922f7ca802SSteve Glendinning 	unsigned long start_time = jiffies;
2932f7ca802SSteve Glendinning 	u32 val;
294769ea6d8SSteve Glendinning 	int ret;
2952f7ca802SSteve Glendinning 
2962f7ca802SSteve Glendinning 	do {
297769ea6d8SSteve Glendinning 		ret = smsc95xx_read_reg(dev, E2P_CMD, &val);
298b052e073SSteve Glendinning 		if (ret < 0) {
299b052e073SSteve Glendinning 			netdev_warn(dev->net, "Error reading E2P_CMD\n");
300b052e073SSteve Glendinning 			return ret;
301b052e073SSteve Glendinning 		}
302b052e073SSteve Glendinning 
3032f7ca802SSteve Glendinning 		if (!(val & E2P_CMD_BUSY_) || (val & E2P_CMD_TIMEOUT_))
3042f7ca802SSteve Glendinning 			break;
3052f7ca802SSteve Glendinning 		udelay(40);
3062f7ca802SSteve Glendinning 	} while (!time_after(jiffies, start_time + HZ));
3072f7ca802SSteve Glendinning 
3082f7ca802SSteve Glendinning 	if (val & (E2P_CMD_TIMEOUT_ | E2P_CMD_BUSY_)) {
30960b86755SJoe Perches 		netdev_warn(dev->net, "EEPROM read operation timeout\n");
3102f7ca802SSteve Glendinning 		return -EIO;
3112f7ca802SSteve Glendinning 	}
3122f7ca802SSteve Glendinning 
3132f7ca802SSteve Glendinning 	return 0;
3142f7ca802SSteve Glendinning }
3152f7ca802SSteve Glendinning 
316769ea6d8SSteve Glendinning static int __must_check smsc95xx_eeprom_confirm_not_busy(struct usbnet *dev)
3172f7ca802SSteve Glendinning {
3182f7ca802SSteve Glendinning 	unsigned long start_time = jiffies;
3192f7ca802SSteve Glendinning 	u32 val;
320769ea6d8SSteve Glendinning 	int ret;
3212f7ca802SSteve Glendinning 
3222f7ca802SSteve Glendinning 	do {
323769ea6d8SSteve Glendinning 		ret = smsc95xx_read_reg(dev, E2P_CMD, &val);
324b052e073SSteve Glendinning 		if (ret < 0) {
325b052e073SSteve Glendinning 			netdev_warn(dev->net, "Error reading E2P_CMD\n");
326b052e073SSteve Glendinning 			return ret;
327b052e073SSteve Glendinning 		}
3282f7ca802SSteve Glendinning 
3292f7ca802SSteve Glendinning 		if (!(val & E2P_CMD_BUSY_))
3302f7ca802SSteve Glendinning 			return 0;
3312f7ca802SSteve Glendinning 
3322f7ca802SSteve Glendinning 		udelay(40);
3332f7ca802SSteve Glendinning 	} while (!time_after(jiffies, start_time + HZ));
3342f7ca802SSteve Glendinning 
33560b86755SJoe Perches 	netdev_warn(dev->net, "EEPROM is busy\n");
3362f7ca802SSteve Glendinning 	return -EIO;
3372f7ca802SSteve Glendinning }
3382f7ca802SSteve Glendinning 
3392f7ca802SSteve Glendinning static int smsc95xx_read_eeprom(struct usbnet *dev, u32 offset, u32 length,
3402f7ca802SSteve Glendinning 				u8 *data)
3412f7ca802SSteve Glendinning {
3422f7ca802SSteve Glendinning 	u32 val;
3432f7ca802SSteve Glendinning 	int i, ret;
3442f7ca802SSteve Glendinning 
3452f7ca802SSteve Glendinning 	BUG_ON(!dev);
3462f7ca802SSteve Glendinning 	BUG_ON(!data);
3472f7ca802SSteve Glendinning 
3482f7ca802SSteve Glendinning 	ret = smsc95xx_eeprom_confirm_not_busy(dev);
3492f7ca802SSteve Glendinning 	if (ret)
3502f7ca802SSteve Glendinning 		return ret;
3512f7ca802SSteve Glendinning 
3522f7ca802SSteve Glendinning 	for (i = 0; i < length; i++) {
3532f7ca802SSteve Glendinning 		val = E2P_CMD_BUSY_ | E2P_CMD_READ_ | (offset & E2P_CMD_ADDR_);
354769ea6d8SSteve Glendinning 		ret = smsc95xx_write_reg(dev, E2P_CMD, val);
355b052e073SSteve Glendinning 		if (ret < 0) {
356b052e073SSteve Glendinning 			netdev_warn(dev->net, "Error writing E2P_CMD\n");
357b052e073SSteve Glendinning 			return ret;
358b052e073SSteve Glendinning 		}
3592f7ca802SSteve Glendinning 
3602f7ca802SSteve Glendinning 		ret = smsc95xx_wait_eeprom(dev);
3612f7ca802SSteve Glendinning 		if (ret < 0)
3622f7ca802SSteve Glendinning 			return ret;
3632f7ca802SSteve Glendinning 
364769ea6d8SSteve Glendinning 		ret = smsc95xx_read_reg(dev, E2P_DATA, &val);
365b052e073SSteve Glendinning 		if (ret < 0) {
366b052e073SSteve Glendinning 			netdev_warn(dev->net, "Error reading E2P_DATA\n");
367b052e073SSteve Glendinning 			return ret;
368b052e073SSteve Glendinning 		}
3692f7ca802SSteve Glendinning 
3702f7ca802SSteve Glendinning 		data[i] = val & 0xFF;
3712f7ca802SSteve Glendinning 		offset++;
3722f7ca802SSteve Glendinning 	}
3732f7ca802SSteve Glendinning 
3742f7ca802SSteve Glendinning 	return 0;
3752f7ca802SSteve Glendinning }
3762f7ca802SSteve Glendinning 
3772f7ca802SSteve Glendinning static int smsc95xx_write_eeprom(struct usbnet *dev, u32 offset, u32 length,
3782f7ca802SSteve Glendinning 				 u8 *data)
3792f7ca802SSteve Glendinning {
3802f7ca802SSteve Glendinning 	u32 val;
3812f7ca802SSteve Glendinning 	int i, ret;
3822f7ca802SSteve Glendinning 
3832f7ca802SSteve Glendinning 	BUG_ON(!dev);
3842f7ca802SSteve Glendinning 	BUG_ON(!data);
3852f7ca802SSteve Glendinning 
3862f7ca802SSteve Glendinning 	ret = smsc95xx_eeprom_confirm_not_busy(dev);
3872f7ca802SSteve Glendinning 	if (ret)
3882f7ca802SSteve Glendinning 		return ret;
3892f7ca802SSteve Glendinning 
3902f7ca802SSteve Glendinning 	/* Issue write/erase enable command */
3912f7ca802SSteve Glendinning 	val = E2P_CMD_BUSY_ | E2P_CMD_EWEN_;
392769ea6d8SSteve Glendinning 	ret = smsc95xx_write_reg(dev, E2P_CMD, val);
393b052e073SSteve Glendinning 	if (ret < 0) {
394b052e073SSteve Glendinning 		netdev_warn(dev->net, "Error writing E2P_DATA\n");
395b052e073SSteve Glendinning 		return ret;
396b052e073SSteve Glendinning 	}
3972f7ca802SSteve Glendinning 
3982f7ca802SSteve Glendinning 	ret = smsc95xx_wait_eeprom(dev);
3992f7ca802SSteve Glendinning 	if (ret < 0)
4002f7ca802SSteve Glendinning 		return ret;
4012f7ca802SSteve Glendinning 
4022f7ca802SSteve Glendinning 	for (i = 0; i < length; i++) {
4032f7ca802SSteve Glendinning 
4042f7ca802SSteve Glendinning 		/* Fill data register */
4052f7ca802SSteve Glendinning 		val = data[i];
406769ea6d8SSteve Glendinning 		ret = smsc95xx_write_reg(dev, E2P_DATA, val);
407b052e073SSteve Glendinning 		if (ret < 0) {
408b052e073SSteve Glendinning 			netdev_warn(dev->net, "Error writing E2P_DATA\n");
409b052e073SSteve Glendinning 			return ret;
410b052e073SSteve Glendinning 		}
4112f7ca802SSteve Glendinning 
4122f7ca802SSteve Glendinning 		/* Send "write" command */
4132f7ca802SSteve Glendinning 		val = E2P_CMD_BUSY_ | E2P_CMD_WRITE_ | (offset & E2P_CMD_ADDR_);
414769ea6d8SSteve Glendinning 		ret = smsc95xx_write_reg(dev, E2P_CMD, val);
415b052e073SSteve Glendinning 		if (ret < 0) {
416b052e073SSteve Glendinning 			netdev_warn(dev->net, "Error writing E2P_CMD\n");
417b052e073SSteve Glendinning 			return ret;
418b052e073SSteve Glendinning 		}
4192f7ca802SSteve Glendinning 
4202f7ca802SSteve Glendinning 		ret = smsc95xx_wait_eeprom(dev);
4212f7ca802SSteve Glendinning 		if (ret < 0)
4222f7ca802SSteve Glendinning 			return ret;
4232f7ca802SSteve Glendinning 
4242f7ca802SSteve Glendinning 		offset++;
4252f7ca802SSteve Glendinning 	}
4262f7ca802SSteve Glendinning 
4272f7ca802SSteve Glendinning 	return 0;
4282f7ca802SSteve Glendinning }
4292f7ca802SSteve Glendinning 
430769ea6d8SSteve Glendinning static int __must_check smsc95xx_write_reg_async(struct usbnet *dev, u16 index,
4317b9e7580SSteve Glendinning 						 u32 data)
4322f7ca802SSteve Glendinning {
4331d74a6bdSSteve Glendinning 	const u16 size = 4;
4347b9e7580SSteve Glendinning 	u32 buf;
43572108fd2SMing Lei 	int ret;
4362f7ca802SSteve Glendinning 
4377b9e7580SSteve Glendinning 	buf = data;
4387b9e7580SSteve Glendinning 	cpu_to_le32s(&buf);
4397b9e7580SSteve Glendinning 
44072108fd2SMing Lei 	ret = usbnet_write_cmd_async(dev, USB_VENDOR_REQUEST_WRITE_REGISTER,
44172108fd2SMing Lei 				     USB_DIR_OUT | USB_TYPE_VENDOR |
44272108fd2SMing Lei 				     USB_RECIP_DEVICE,
4437b9e7580SSteve Glendinning 				     0, index, &buf, size);
44472108fd2SMing Lei 	if (ret < 0)
44572108fd2SMing Lei 		netdev_warn(dev->net, "Error write async cmd, sts=%d\n",
44672108fd2SMing Lei 			    ret);
44772108fd2SMing Lei 	return ret;
4482f7ca802SSteve Glendinning }
4492f7ca802SSteve Glendinning 
4502f7ca802SSteve Glendinning /* returns hash bit number for given MAC address
4512f7ca802SSteve Glendinning  * example:
4522f7ca802SSteve Glendinning  * 01 00 5E 00 00 01 -> returns bit number 31 */
4532f7ca802SSteve Glendinning static unsigned int smsc95xx_hash(char addr[ETH_ALEN])
4542f7ca802SSteve Glendinning {
4552f7ca802SSteve Glendinning 	return (ether_crc(ETH_ALEN, addr) >> 26) & 0x3f;
4562f7ca802SSteve Glendinning }
4572f7ca802SSteve Glendinning 
4582f7ca802SSteve Glendinning static void smsc95xx_set_multicast(struct net_device *netdev)
4592f7ca802SSteve Glendinning {
4602f7ca802SSteve Glendinning 	struct usbnet *dev = netdev_priv(netdev);
461ad90a73fSAndre Edich 	struct smsc95xx_priv *pdata = dev->driver_priv;
4622f7ca802SSteve Glendinning 	unsigned long flags;
463769ea6d8SSteve Glendinning 	int ret;
4642f7ca802SSteve Glendinning 
4653c0f3c60SMarc Zyngier 	pdata->hash_hi = 0;
4663c0f3c60SMarc Zyngier 	pdata->hash_lo = 0;
4673c0f3c60SMarc Zyngier 
4682f7ca802SSteve Glendinning 	spin_lock_irqsave(&pdata->mac_cr_lock, flags);
4692f7ca802SSteve Glendinning 
4702f7ca802SSteve Glendinning 	if (dev->net->flags & IFF_PROMISC) {
471a475f603SJoe Perches 		netif_dbg(dev, drv, dev->net, "promiscuous mode enabled\n");
4722f7ca802SSteve Glendinning 		pdata->mac_cr |= MAC_CR_PRMS_;
4732f7ca802SSteve Glendinning 		pdata->mac_cr &= ~(MAC_CR_MCPAS_ | MAC_CR_HPFILT_);
4742f7ca802SSteve Glendinning 	} else if (dev->net->flags & IFF_ALLMULTI) {
475a475f603SJoe Perches 		netif_dbg(dev, drv, dev->net, "receive all multicast enabled\n");
4762f7ca802SSteve Glendinning 		pdata->mac_cr |= MAC_CR_MCPAS_;
4772f7ca802SSteve Glendinning 		pdata->mac_cr &= ~(MAC_CR_PRMS_ | MAC_CR_HPFILT_);
4784cd24eafSJiri Pirko 	} else if (!netdev_mc_empty(dev->net)) {
47922bedad3SJiri Pirko 		struct netdev_hw_addr *ha;
4802f7ca802SSteve Glendinning 
4812f7ca802SSteve Glendinning 		pdata->mac_cr |= MAC_CR_HPFILT_;
4822f7ca802SSteve Glendinning 		pdata->mac_cr &= ~(MAC_CR_PRMS_ | MAC_CR_MCPAS_);
4832f7ca802SSteve Glendinning 
48422bedad3SJiri Pirko 		netdev_for_each_mc_addr(ha, netdev) {
48522bedad3SJiri Pirko 			u32 bitnum = smsc95xx_hash(ha->addr);
4862f7ca802SSteve Glendinning 			u32 mask = 0x01 << (bitnum & 0x1F);
4872f7ca802SSteve Glendinning 			if (bitnum & 0x20)
4883c0f3c60SMarc Zyngier 				pdata->hash_hi |= mask;
4892f7ca802SSteve Glendinning 			else
4903c0f3c60SMarc Zyngier 				pdata->hash_lo |= mask;
4912f7ca802SSteve Glendinning 		}
4922f7ca802SSteve Glendinning 
493a475f603SJoe Perches 		netif_dbg(dev, drv, dev->net, "HASHH=0x%08X, HASHL=0x%08X\n",
4943c0f3c60SMarc Zyngier 				   pdata->hash_hi, pdata->hash_lo);
4952f7ca802SSteve Glendinning 	} else {
496a475f603SJoe Perches 		netif_dbg(dev, drv, dev->net, "receive own packets only\n");
4972f7ca802SSteve Glendinning 		pdata->mac_cr &=
4982f7ca802SSteve Glendinning 			~(MAC_CR_PRMS_ | MAC_CR_MCPAS_ | MAC_CR_HPFILT_);
4992f7ca802SSteve Glendinning 	}
5002f7ca802SSteve Glendinning 
5012f7ca802SSteve Glendinning 	spin_unlock_irqrestore(&pdata->mac_cr_lock, flags);
5022f7ca802SSteve Glendinning 
5032f7ca802SSteve Glendinning 	/* Initiate async writes, as we can't wait for completion here */
5047b9e7580SSteve Glendinning 	ret = smsc95xx_write_reg_async(dev, HASHH, pdata->hash_hi);
505b052e073SSteve Glendinning 	if (ret < 0)
506b052e073SSteve Glendinning 		netdev_warn(dev->net, "failed to initiate async write to HASHH\n");
507769ea6d8SSteve Glendinning 
5087b9e7580SSteve Glendinning 	ret = smsc95xx_write_reg_async(dev, HASHL, pdata->hash_lo);
509b052e073SSteve Glendinning 	if (ret < 0)
510b052e073SSteve Glendinning 		netdev_warn(dev->net, "failed to initiate async write to HASHL\n");
511769ea6d8SSteve Glendinning 
5127b9e7580SSteve Glendinning 	ret = smsc95xx_write_reg_async(dev, MAC_CR, pdata->mac_cr);
513b052e073SSteve Glendinning 	if (ret < 0)
514b052e073SSteve Glendinning 		netdev_warn(dev->net, "failed to initiate async write to MAC_CR\n");
5152f7ca802SSteve Glendinning }
5162f7ca802SSteve Glendinning 
51705b35e7eSAndre Edich static int smsc95xx_phy_update_flowcontrol(struct usbnet *dev)
5182f7ca802SSteve Glendinning {
5199c082731SNisar Sayed 	u32 flow = 0, afc_cfg;
52005b35e7eSAndre Edich 	struct smsc95xx_priv *pdata = dev->driver_priv;
52105b35e7eSAndre Edich 	bool tx_pause, rx_pause;
5222f7ca802SSteve Glendinning 
5232f7ca802SSteve Glendinning 	int ret = smsc95xx_read_reg(dev, AFC_CFG, &afc_cfg);
524e360a8b4SSteve Glendinning 	if (ret < 0)
525b052e073SSteve Glendinning 		return ret;
5262f7ca802SSteve Glendinning 
52705b35e7eSAndre Edich 	if (pdata->phydev->duplex == DUPLEX_FULL) {
52805b35e7eSAndre Edich 		phy_get_pause(pdata->phydev, &tx_pause, &rx_pause);
5292f7ca802SSteve Glendinning 
53005b35e7eSAndre Edich 		if (rx_pause)
5312f7ca802SSteve Glendinning 			flow = 0xFFFF0002;
5322f7ca802SSteve Glendinning 
53305b35e7eSAndre Edich 		if (tx_pause) {
5342f7ca802SSteve Glendinning 			afc_cfg |= 0xF;
5359c082731SNisar Sayed 			flow |= 0xFFFF0000;
5369c082731SNisar Sayed 		} else {
5372f7ca802SSteve Glendinning 			afc_cfg &= ~0xF;
5389c082731SNisar Sayed 		}
5392f7ca802SSteve Glendinning 
540a475f603SJoe Perches 		netif_dbg(dev, link, dev->net, "rx pause %s, tx pause %s\n",
54105b35e7eSAndre Edich 			  rx_pause ? "enabled" : "disabled",
54205b35e7eSAndre Edich 			  tx_pause ? "enabled" : "disabled");
5432f7ca802SSteve Glendinning 	} else {
544a475f603SJoe Perches 		netif_dbg(dev, link, dev->net, "half duplex\n");
5452f7ca802SSteve Glendinning 		afc_cfg |= 0xF;
5462f7ca802SSteve Glendinning 	}
5472f7ca802SSteve Glendinning 
548769ea6d8SSteve Glendinning 	ret = smsc95xx_write_reg(dev, FLOW, flow);
549b052e073SSteve Glendinning 	if (ret < 0)
550b052e073SSteve Glendinning 		return ret;
551e360a8b4SSteve Glendinning 
552e360a8b4SSteve Glendinning 	return smsc95xx_write_reg(dev, AFC_CFG, afc_cfg);
5532f7ca802SSteve Glendinning }
5542f7ca802SSteve Glendinning 
5552f7ca802SSteve Glendinning static int smsc95xx_link_reset(struct usbnet *dev)
5562f7ca802SSteve Glendinning {
557ad90a73fSAndre Edich 	struct smsc95xx_priv *pdata = dev->driver_priv;
5582f7ca802SSteve Glendinning 	unsigned long flags;
559769ea6d8SSteve Glendinning 	int ret;
5602f7ca802SSteve Glendinning 
561769ea6d8SSteve Glendinning 	ret = smsc95xx_write_reg(dev, INT_STS, INT_STS_CLEAR_ALL_);
562e360a8b4SSteve Glendinning 	if (ret < 0)
563b052e073SSteve Glendinning 		return ret;
5642f7ca802SSteve Glendinning 
5652f7ca802SSteve Glendinning 	spin_lock_irqsave(&pdata->mac_cr_lock, flags);
56605b35e7eSAndre Edich 	if (pdata->phydev->duplex != DUPLEX_FULL) {
5672f7ca802SSteve Glendinning 		pdata->mac_cr &= ~MAC_CR_FDPX_;
5682f7ca802SSteve Glendinning 		pdata->mac_cr |= MAC_CR_RCVOWN_;
5692f7ca802SSteve Glendinning 	} else {
5702f7ca802SSteve Glendinning 		pdata->mac_cr &= ~MAC_CR_RCVOWN_;
5712f7ca802SSteve Glendinning 		pdata->mac_cr |= MAC_CR_FDPX_;
5722f7ca802SSteve Glendinning 	}
5732f7ca802SSteve Glendinning 	spin_unlock_irqrestore(&pdata->mac_cr_lock, flags);
5742f7ca802SSteve Glendinning 
575769ea6d8SSteve Glendinning 	ret = smsc95xx_write_reg(dev, MAC_CR, pdata->mac_cr);
576e360a8b4SSteve Glendinning 	if (ret < 0)
577b052e073SSteve Glendinning 		return ret;
5782f7ca802SSteve Glendinning 
57905b35e7eSAndre Edich 	ret = smsc95xx_phy_update_flowcontrol(dev);
580b052e073SSteve Glendinning 	if (ret < 0)
581b052e073SSteve Glendinning 		netdev_warn(dev->net, "Error updating PHY flow control\n");
5822f7ca802SSteve Glendinning 
583b052e073SSteve Glendinning 	return ret;
5842f7ca802SSteve Glendinning }
5852f7ca802SSteve Glendinning 
5862f7ca802SSteve Glendinning static void smsc95xx_status(struct usbnet *dev, struct urb *urb)
5872f7ca802SSteve Glendinning {
5882f7ca802SSteve Glendinning 	u32 intdata;
5892f7ca802SSteve Glendinning 
5902f7ca802SSteve Glendinning 	if (urb->actual_length != 4) {
59160b86755SJoe Perches 		netdev_warn(dev->net, "unexpected urb length %d\n",
59260b86755SJoe Perches 			    urb->actual_length);
5932f7ca802SSteve Glendinning 		return;
5942f7ca802SSteve Glendinning 	}
5952f7ca802SSteve Glendinning 
5966809d216SBen Dooks 	intdata = get_unaligned_le32(urb->transfer_buffer);
597a475f603SJoe Perches 	netif_dbg(dev, link, dev->net, "intdata: 0x%08X\n", intdata);
5982f7ca802SSteve Glendinning 
5992f7ca802SSteve Glendinning 	if (intdata & INT_ENP_PHY_INT_)
6002f7ca802SSteve Glendinning 		usbnet_defer_kevent(dev, EVENT_LINK_RESET);
6012f7ca802SSteve Glendinning 	else
60260b86755SJoe Perches 		netdev_warn(dev->net, "unexpected interrupt, intdata=0x%08X\n",
60360b86755SJoe Perches 			    intdata);
6042f7ca802SSteve Glendinning }
6052f7ca802SSteve Glendinning 
606f7b29271SSteve Glendinning /* Enable or disable Tx & Rx checksum offload engines */
607c8f44affSMichał Mirosław static int smsc95xx_set_features(struct net_device *netdev,
608c8f44affSMichał Mirosław 	netdev_features_t features)
6092f7ca802SSteve Glendinning {
61078e47fe4SMichał Mirosław 	struct usbnet *dev = netdev_priv(netdev);
6112f7ca802SSteve Glendinning 	u32 read_buf;
61278e47fe4SMichał Mirosław 	int ret;
61378e47fe4SMichał Mirosław 
61478e47fe4SMichał Mirosław 	ret = smsc95xx_read_reg(dev, COE_CR, &read_buf);
615e360a8b4SSteve Glendinning 	if (ret < 0)
616b052e073SSteve Glendinning 		return ret;
6172f7ca802SSteve Glendinning 
618fe0cd8caSNisar Sayed 	if (features & NETIF_F_IP_CSUM)
619f7b29271SSteve Glendinning 		read_buf |= Tx_COE_EN_;
620f7b29271SSteve Glendinning 	else
621f7b29271SSteve Glendinning 		read_buf &= ~Tx_COE_EN_;
622f7b29271SSteve Glendinning 
62378e47fe4SMichał Mirosław 	if (features & NETIF_F_RXCSUM)
6242f7ca802SSteve Glendinning 		read_buf |= Rx_COE_EN_;
6252f7ca802SSteve Glendinning 	else
6262f7ca802SSteve Glendinning 		read_buf &= ~Rx_COE_EN_;
6272f7ca802SSteve Glendinning 
6282f7ca802SSteve Glendinning 	ret = smsc95xx_write_reg(dev, COE_CR, read_buf);
629e360a8b4SSteve Glendinning 	if (ret < 0)
630b052e073SSteve Glendinning 		return ret;
6312f7ca802SSteve Glendinning 
632a475f603SJoe Perches 	netif_dbg(dev, hw, dev->net, "COE_CR = 0x%08x\n", read_buf);
6332f7ca802SSteve Glendinning 	return 0;
6342f7ca802SSteve Glendinning }
6352f7ca802SSteve Glendinning 
6362f7ca802SSteve Glendinning static int smsc95xx_ethtool_get_eeprom_len(struct net_device *net)
6372f7ca802SSteve Glendinning {
6382f7ca802SSteve Glendinning 	return MAX_EEPROM_SIZE;
6392f7ca802SSteve Glendinning }
6402f7ca802SSteve Glendinning 
6412f7ca802SSteve Glendinning static int smsc95xx_ethtool_get_eeprom(struct net_device *netdev,
6422f7ca802SSteve Glendinning 				       struct ethtool_eeprom *ee, u8 *data)
6432f7ca802SSteve Glendinning {
6442f7ca802SSteve Glendinning 	struct usbnet *dev = netdev_priv(netdev);
6452f7ca802SSteve Glendinning 
6462f7ca802SSteve Glendinning 	ee->magic = LAN95XX_EEPROM_MAGIC;
6472f7ca802SSteve Glendinning 
6482f7ca802SSteve Glendinning 	return smsc95xx_read_eeprom(dev, ee->offset, ee->len, data);
6492f7ca802SSteve Glendinning }
6502f7ca802SSteve Glendinning 
6512f7ca802SSteve Glendinning static int smsc95xx_ethtool_set_eeprom(struct net_device *netdev,
6522f7ca802SSteve Glendinning 				       struct ethtool_eeprom *ee, u8 *data)
6532f7ca802SSteve Glendinning {
6542f7ca802SSteve Glendinning 	struct usbnet *dev = netdev_priv(netdev);
6552f7ca802SSteve Glendinning 
6562f7ca802SSteve Glendinning 	if (ee->magic != LAN95XX_EEPROM_MAGIC) {
65760b86755SJoe Perches 		netdev_warn(dev->net, "EEPROM: magic value mismatch, magic = 0x%x\n",
6582f7ca802SSteve Glendinning 			    ee->magic);
6592f7ca802SSteve Glendinning 		return -EINVAL;
6602f7ca802SSteve Glendinning 	}
6612f7ca802SSteve Glendinning 
6622f7ca802SSteve Glendinning 	return smsc95xx_write_eeprom(dev, ee->offset, ee->len, data);
6632f7ca802SSteve Glendinning }
6642f7ca802SSteve Glendinning 
6659fa32e94SEmeric Vigier static int smsc95xx_ethtool_getregslen(struct net_device *netdev)
6669fa32e94SEmeric Vigier {
6679fa32e94SEmeric Vigier 	/* all smsc95xx registers */
66896245317SSteve Glendinning 	return COE_CR - ID_REV + sizeof(u32);
6699fa32e94SEmeric Vigier }
6709fa32e94SEmeric Vigier 
6719fa32e94SEmeric Vigier static void
6729fa32e94SEmeric Vigier smsc95xx_ethtool_getregs(struct net_device *netdev, struct ethtool_regs *regs,
6739fa32e94SEmeric Vigier 			 void *buf)
6749fa32e94SEmeric Vigier {
6759fa32e94SEmeric Vigier 	struct usbnet *dev = netdev_priv(netdev);
676d348446bSDan Carpenter 	unsigned int i, j;
677d348446bSDan Carpenter 	int retval;
6789fa32e94SEmeric Vigier 	u32 *data = buf;
6799fa32e94SEmeric Vigier 
6809fa32e94SEmeric Vigier 	retval = smsc95xx_read_reg(dev, ID_REV, &regs->version);
6819fa32e94SEmeric Vigier 	if (retval < 0) {
6829fa32e94SEmeric Vigier 		netdev_warn(netdev, "REGS: cannot read ID_REV\n");
6839fa32e94SEmeric Vigier 		return;
6849fa32e94SEmeric Vigier 	}
6859fa32e94SEmeric Vigier 
6869fa32e94SEmeric Vigier 	for (i = ID_REV, j = 0; i <= COE_CR; i += (sizeof(u32)), j++) {
6879fa32e94SEmeric Vigier 		retval = smsc95xx_read_reg(dev, i, &data[j]);
6889fa32e94SEmeric Vigier 		if (retval < 0) {
6899fa32e94SEmeric Vigier 			netdev_warn(netdev, "REGS: cannot read reg[%x]\n", i);
6909fa32e94SEmeric Vigier 			return;
6919fa32e94SEmeric Vigier 		}
6929fa32e94SEmeric Vigier 	}
6939fa32e94SEmeric Vigier }
6949fa32e94SEmeric Vigier 
695e0e474a8SSteve Glendinning static void smsc95xx_ethtool_get_wol(struct net_device *net,
696e0e474a8SSteve Glendinning 				     struct ethtool_wolinfo *wolinfo)
697e0e474a8SSteve Glendinning {
698e0e474a8SSteve Glendinning 	struct usbnet *dev = netdev_priv(net);
699ad90a73fSAndre Edich 	struct smsc95xx_priv *pdata = dev->driver_priv;
700e0e474a8SSteve Glendinning 
701e0e474a8SSteve Glendinning 	wolinfo->supported = SUPPORTED_WAKE;
702e0e474a8SSteve Glendinning 	wolinfo->wolopts = pdata->wolopts;
703e0e474a8SSteve Glendinning }
704e0e474a8SSteve Glendinning 
705e0e474a8SSteve Glendinning static int smsc95xx_ethtool_set_wol(struct net_device *net,
706e0e474a8SSteve Glendinning 				    struct ethtool_wolinfo *wolinfo)
707e0e474a8SSteve Glendinning {
708e0e474a8SSteve Glendinning 	struct usbnet *dev = netdev_priv(net);
709ad90a73fSAndre Edich 	struct smsc95xx_priv *pdata = dev->driver_priv;
7103b14692cSSteve Glendinning 	int ret;
711e0e474a8SSteve Glendinning 
712c530c471SFlorian Fainelli 	if (wolinfo->wolopts & ~SUPPORTED_WAKE)
713c530c471SFlorian Fainelli 		return -EINVAL;
714c530c471SFlorian Fainelli 
715e0e474a8SSteve Glendinning 	pdata->wolopts = wolinfo->wolopts & SUPPORTED_WAKE;
7163b14692cSSteve Glendinning 
7173b14692cSSteve Glendinning 	ret = device_set_wakeup_enable(&dev->udev->dev, pdata->wolopts);
718b052e073SSteve Glendinning 	if (ret < 0)
719b052e073SSteve Glendinning 		netdev_warn(dev->net, "device_set_wakeup_enable error %d\n", ret);
7203b14692cSSteve Glendinning 
721b052e073SSteve Glendinning 	return ret;
722e0e474a8SSteve Glendinning }
723e0e474a8SSteve Glendinning 
72405b35e7eSAndre Edich static u32 smsc95xx_get_link(struct net_device *net)
72513722bbeSWoojung Huh {
72605b35e7eSAndre Edich 	phy_read_status(net->phydev);
72705b35e7eSAndre Edich 	return net->phydev->link;
72813722bbeSWoojung Huh }
72913722bbeSWoojung Huh 
7300fc0b732SStephen Hemminger static const struct ethtool_ops smsc95xx_ethtool_ops = {
73105b35e7eSAndre Edich 	.get_link	= smsc95xx_get_link,
73205b35e7eSAndre Edich 	.nway_reset	= phy_ethtool_nway_reset,
7332f7ca802SSteve Glendinning 	.get_drvinfo	= usbnet_get_drvinfo,
7342f7ca802SSteve Glendinning 	.get_msglevel	= usbnet_get_msglevel,
7352f7ca802SSteve Glendinning 	.set_msglevel	= usbnet_set_msglevel,
7362f7ca802SSteve Glendinning 	.get_eeprom_len	= smsc95xx_ethtool_get_eeprom_len,
7372f7ca802SSteve Glendinning 	.get_eeprom	= smsc95xx_ethtool_get_eeprom,
7382f7ca802SSteve Glendinning 	.set_eeprom	= smsc95xx_ethtool_set_eeprom,
7399fa32e94SEmeric Vigier 	.get_regs_len	= smsc95xx_ethtool_getregslen,
7409fa32e94SEmeric Vigier 	.get_regs	= smsc95xx_ethtool_getregs,
741e0e474a8SSteve Glendinning 	.get_wol	= smsc95xx_ethtool_get_wol,
742e0e474a8SSteve Glendinning 	.set_wol	= smsc95xx_ethtool_set_wol,
74305b35e7eSAndre Edich 	.get_link_ksettings	= phy_ethtool_get_link_ksettings,
74405b35e7eSAndre Edich 	.set_link_ksettings	= phy_ethtool_set_link_ksettings,
745a8f5cb9eSPetr Kulhavy 	.get_ts_info	= ethtool_op_get_ts_info,
7462f7ca802SSteve Glendinning };
7472f7ca802SSteve Glendinning 
7482f7ca802SSteve Glendinning static int smsc95xx_ioctl(struct net_device *netdev, struct ifreq *rq, int cmd)
7492f7ca802SSteve Glendinning {
7502f7ca802SSteve Glendinning 	if (!netif_running(netdev))
7512f7ca802SSteve Glendinning 		return -EINVAL;
7522f7ca802SSteve Glendinning 
75305b35e7eSAndre Edich 	return phy_mii_ioctl(netdev->phydev, rq, cmd);
7542f7ca802SSteve Glendinning }
7552f7ca802SSteve Glendinning 
7562f7ca802SSteve Glendinning static void smsc95xx_init_mac_address(struct usbnet *dev)
7572f7ca802SSteve Glendinning {
758*a7021af7SJakub Kicinski 	u8 addr[ETH_ALEN];
759*a7021af7SJakub Kicinski 
760c489565bSArnd Bergmann 	/* maybe the boot loader passed the MAC address in devicetree */
7614d04cdc5SJakub Kicinski 	if (!platform_get_ethdev_address(&dev->udev->dev, dev->net)) {
7624f359b65SŁukasz Stelmach 		if (is_valid_ether_addr(dev->net->dev_addr)) {
7634f359b65SŁukasz Stelmach 			/* device tree values are valid so use them */
7644f359b65SŁukasz Stelmach 			netif_dbg(dev, ifup, dev->net, "MAC address read from the device tree\n");
765c489565bSArnd Bergmann 			return;
766c489565bSArnd Bergmann 		}
7674f359b65SŁukasz Stelmach 	}
768c489565bSArnd Bergmann 
7692f7ca802SSteve Glendinning 	/* try reading mac address from EEPROM */
770*a7021af7SJakub Kicinski 	if (smsc95xx_read_eeprom(dev, EEPROM_MAC_OFFSET, ETH_ALEN, addr) == 0) {
771*a7021af7SJakub Kicinski 		eth_hw_addr_set(dev->net, addr);
7722f7ca802SSteve Glendinning 		if (is_valid_ether_addr(dev->net->dev_addr)) {
7732f7ca802SSteve Glendinning 			/* eeprom values are valid so use them */
774a475f603SJoe Perches 			netif_dbg(dev, ifup, dev->net, "MAC address read from EEPROM\n");
7752f7ca802SSteve Glendinning 			return;
7762f7ca802SSteve Glendinning 		}
7772f7ca802SSteve Glendinning 	}
7782f7ca802SSteve Glendinning 
779c489565bSArnd Bergmann 	/* no useful static MAC address found. generate a random one */
780f2cedb63SDanny Kukawka 	eth_hw_addr_random(dev->net);
781c7e12eadSJoe Perches 	netif_dbg(dev, ifup, dev->net, "MAC address set to eth_random_addr\n");
7822f7ca802SSteve Glendinning }
7832f7ca802SSteve Glendinning 
7842f7ca802SSteve Glendinning static int smsc95xx_set_mac_address(struct usbnet *dev)
7852f7ca802SSteve Glendinning {
7862f7ca802SSteve Glendinning 	u32 addr_lo = dev->net->dev_addr[0] | dev->net->dev_addr[1] << 8 |
7872f7ca802SSteve Glendinning 		dev->net->dev_addr[2] << 16 | dev->net->dev_addr[3] << 24;
7882f7ca802SSteve Glendinning 	u32 addr_hi = dev->net->dev_addr[4] | dev->net->dev_addr[5] << 8;
7892f7ca802SSteve Glendinning 	int ret;
7902f7ca802SSteve Glendinning 
7912f7ca802SSteve Glendinning 	ret = smsc95xx_write_reg(dev, ADDRL, addr_lo);
792b052e073SSteve Glendinning 	if (ret < 0)
793b052e073SSteve Glendinning 		return ret;
794e360a8b4SSteve Glendinning 
795e360a8b4SSteve Glendinning 	return smsc95xx_write_reg(dev, ADDRH, addr_hi);
7962f7ca802SSteve Glendinning }
7972f7ca802SSteve Glendinning 
7982f7ca802SSteve Glendinning /* starts the TX path */
799769ea6d8SSteve Glendinning static int smsc95xx_start_tx_path(struct usbnet *dev)
8002f7ca802SSteve Glendinning {
801ad90a73fSAndre Edich 	struct smsc95xx_priv *pdata = dev->driver_priv;
8022f7ca802SSteve Glendinning 	unsigned long flags;
803769ea6d8SSteve Glendinning 	int ret;
8042f7ca802SSteve Glendinning 
8052f7ca802SSteve Glendinning 	/* Enable Tx at MAC */
8062f7ca802SSteve Glendinning 	spin_lock_irqsave(&pdata->mac_cr_lock, flags);
8072f7ca802SSteve Glendinning 	pdata->mac_cr |= MAC_CR_TXEN_;
8082f7ca802SSteve Glendinning 	spin_unlock_irqrestore(&pdata->mac_cr_lock, flags);
8092f7ca802SSteve Glendinning 
810769ea6d8SSteve Glendinning 	ret = smsc95xx_write_reg(dev, MAC_CR, pdata->mac_cr);
811e360a8b4SSteve Glendinning 	if (ret < 0)
812b052e073SSteve Glendinning 		return ret;
8132f7ca802SSteve Glendinning 
8142f7ca802SSteve Glendinning 	/* Enable Tx at SCSRs */
815e360a8b4SSteve Glendinning 	return smsc95xx_write_reg(dev, TX_CFG, TX_CFG_ON_);
8162f7ca802SSteve Glendinning }
8172f7ca802SSteve Glendinning 
8182f7ca802SSteve Glendinning /* Starts the Receive path */
819ec32115dSMing Lei static int smsc95xx_start_rx_path(struct usbnet *dev, int in_pm)
8202f7ca802SSteve Glendinning {
821ad90a73fSAndre Edich 	struct smsc95xx_priv *pdata = dev->driver_priv;
8222f7ca802SSteve Glendinning 	unsigned long flags;
8232f7ca802SSteve Glendinning 
8242f7ca802SSteve Glendinning 	spin_lock_irqsave(&pdata->mac_cr_lock, flags);
8252f7ca802SSteve Glendinning 	pdata->mac_cr |= MAC_CR_RXEN_;
8262f7ca802SSteve Glendinning 	spin_unlock_irqrestore(&pdata->mac_cr_lock, flags);
8272f7ca802SSteve Glendinning 
828e360a8b4SSteve Glendinning 	return __smsc95xx_write_reg(dev, MAC_CR, pdata->mac_cr, in_pm);
8292f7ca802SSteve Glendinning }
8302f7ca802SSteve Glendinning 
8312f7ca802SSteve Glendinning static int smsc95xx_reset(struct usbnet *dev)
8322f7ca802SSteve Glendinning {
833ad90a73fSAndre Edich 	struct smsc95xx_priv *pdata = dev->driver_priv;
8342f7ca802SSteve Glendinning 	u32 read_buf, write_buf, burst_cap;
8352f7ca802SSteve Glendinning 	int ret = 0, timeout;
8362f7ca802SSteve Glendinning 
837a475f603SJoe Perches 	netif_dbg(dev, ifup, dev->net, "entering smsc95xx_reset\n");
8382f7ca802SSteve Glendinning 
8394436761bSSteve Glendinning 	ret = smsc95xx_write_reg(dev, HW_CFG, HW_CFG_LRST_);
840e360a8b4SSteve Glendinning 	if (ret < 0)
841b052e073SSteve Glendinning 		return ret;
8422f7ca802SSteve Glendinning 
8432f7ca802SSteve Glendinning 	timeout = 0;
8442f7ca802SSteve Glendinning 	do {
845cf2acec2SSteve Glendinning 		msleep(10);
8462f7ca802SSteve Glendinning 		ret = smsc95xx_read_reg(dev, HW_CFG, &read_buf);
847e360a8b4SSteve Glendinning 		if (ret < 0)
848b052e073SSteve Glendinning 			return ret;
8492f7ca802SSteve Glendinning 		timeout++;
8502f7ca802SSteve Glendinning 	} while ((read_buf & HW_CFG_LRST_) && (timeout < 100));
8512f7ca802SSteve Glendinning 
8522f7ca802SSteve Glendinning 	if (timeout >= 100) {
85360b86755SJoe Perches 		netdev_warn(dev->net, "timeout waiting for completion of Lite Reset\n");
8542f7ca802SSteve Glendinning 		return ret;
8552f7ca802SSteve Glendinning 	}
8562f7ca802SSteve Glendinning 
8574436761bSSteve Glendinning 	ret = smsc95xx_write_reg(dev, PM_CTRL, PM_CTL_PHY_RST_);
858e360a8b4SSteve Glendinning 	if (ret < 0)
859b052e073SSteve Glendinning 		return ret;
8602f7ca802SSteve Glendinning 
8612f7ca802SSteve Glendinning 	timeout = 0;
8622f7ca802SSteve Glendinning 	do {
863cf2acec2SSteve Glendinning 		msleep(10);
8642f7ca802SSteve Glendinning 		ret = smsc95xx_read_reg(dev, PM_CTRL, &read_buf);
865e360a8b4SSteve Glendinning 		if (ret < 0)
866b052e073SSteve Glendinning 			return ret;
8672f7ca802SSteve Glendinning 		timeout++;
8682f7ca802SSteve Glendinning 	} while ((read_buf & PM_CTL_PHY_RST_) && (timeout < 100));
8692f7ca802SSteve Glendinning 
8702f7ca802SSteve Glendinning 	if (timeout >= 100) {
87160b86755SJoe Perches 		netdev_warn(dev->net, "timeout waiting for PHY Reset\n");
8722f7ca802SSteve Glendinning 		return ret;
8732f7ca802SSteve Glendinning 	}
8742f7ca802SSteve Glendinning 
8752f7ca802SSteve Glendinning 	ret = smsc95xx_set_mac_address(dev);
8762f7ca802SSteve Glendinning 	if (ret < 0)
8772f7ca802SSteve Glendinning 		return ret;
8782f7ca802SSteve Glendinning 
8791e1d7412SJoe Perches 	netif_dbg(dev, ifup, dev->net, "MAC Address: %pM\n",
8801e1d7412SJoe Perches 		  dev->net->dev_addr);
8812f7ca802SSteve Glendinning 
8822f7ca802SSteve Glendinning 	ret = smsc95xx_read_reg(dev, HW_CFG, &read_buf);
883e360a8b4SSteve Glendinning 	if (ret < 0)
884b052e073SSteve Glendinning 		return ret;
8852f7ca802SSteve Glendinning 
8861e1d7412SJoe Perches 	netif_dbg(dev, ifup, dev->net, "Read Value from HW_CFG : 0x%08x\n",
8871e1d7412SJoe Perches 		  read_buf);
8882f7ca802SSteve Glendinning 
8892f7ca802SSteve Glendinning 	read_buf |= HW_CFG_BIR_;
8902f7ca802SSteve Glendinning 
8912f7ca802SSteve Glendinning 	ret = smsc95xx_write_reg(dev, HW_CFG, read_buf);
892e360a8b4SSteve Glendinning 	if (ret < 0)
893b052e073SSteve Glendinning 		return ret;
8942f7ca802SSteve Glendinning 
8952f7ca802SSteve Glendinning 	ret = smsc95xx_read_reg(dev, HW_CFG, &read_buf);
896e360a8b4SSteve Glendinning 	if (ret < 0)
897b052e073SSteve Glendinning 		return ret;
898b052e073SSteve Glendinning 
899a475f603SJoe Perches 	netif_dbg(dev, ifup, dev->net,
900a475f603SJoe Perches 		  "Read Value from HW_CFG after writing HW_CFG_BIR_: 0x%08x\n",
90160b86755SJoe Perches 		  read_buf);
9022f7ca802SSteve Glendinning 
9032f7ca802SSteve Glendinning 	if (!turbo_mode) {
9042f7ca802SSteve Glendinning 		burst_cap = 0;
9052f7ca802SSteve Glendinning 		dev->rx_urb_size = MAX_SINGLE_PACKET_SIZE;
9062f7ca802SSteve Glendinning 	} else if (dev->udev->speed == USB_SPEED_HIGH) {
9072f7ca802SSteve Glendinning 		burst_cap = DEFAULT_HS_BURST_CAP_SIZE / HS_USB_PKT_SIZE;
9082f7ca802SSteve Glendinning 		dev->rx_urb_size = DEFAULT_HS_BURST_CAP_SIZE;
9092f7ca802SSteve Glendinning 	} else {
9102f7ca802SSteve Glendinning 		burst_cap = DEFAULT_FS_BURST_CAP_SIZE / FS_USB_PKT_SIZE;
9112f7ca802SSteve Glendinning 		dev->rx_urb_size = DEFAULT_FS_BURST_CAP_SIZE;
9122f7ca802SSteve Glendinning 	}
9132f7ca802SSteve Glendinning 
9141e1d7412SJoe Perches 	netif_dbg(dev, ifup, dev->net, "rx_urb_size=%ld\n",
9151e1d7412SJoe Perches 		  (ulong)dev->rx_urb_size);
9162f7ca802SSteve Glendinning 
9172f7ca802SSteve Glendinning 	ret = smsc95xx_write_reg(dev, BURST_CAP, burst_cap);
918e360a8b4SSteve Glendinning 	if (ret < 0)
919b052e073SSteve Glendinning 		return ret;
9202f7ca802SSteve Glendinning 
9212f7ca802SSteve Glendinning 	ret = smsc95xx_read_reg(dev, BURST_CAP, &read_buf);
922e360a8b4SSteve Glendinning 	if (ret < 0)
923b052e073SSteve Glendinning 		return ret;
924769ea6d8SSteve Glendinning 
925a475f603SJoe Perches 	netif_dbg(dev, ifup, dev->net,
926a475f603SJoe Perches 		  "Read Value from BURST_CAP after writing: 0x%08x\n",
9272f7ca802SSteve Glendinning 		  read_buf);
9282f7ca802SSteve Glendinning 
9294436761bSSteve Glendinning 	ret = smsc95xx_write_reg(dev, BULK_IN_DLY, DEFAULT_BULK_IN_DELAY);
930e360a8b4SSteve Glendinning 	if (ret < 0)
931b052e073SSteve Glendinning 		return ret;
9322f7ca802SSteve Glendinning 
9332f7ca802SSteve Glendinning 	ret = smsc95xx_read_reg(dev, BULK_IN_DLY, &read_buf);
934e360a8b4SSteve Glendinning 	if (ret < 0)
935b052e073SSteve Glendinning 		return ret;
936769ea6d8SSteve Glendinning 
937a475f603SJoe Perches 	netif_dbg(dev, ifup, dev->net,
938a475f603SJoe Perches 		  "Read Value from BULK_IN_DLY after writing: 0x%08x\n",
93960b86755SJoe Perches 		  read_buf);
9402f7ca802SSteve Glendinning 
9412f7ca802SSteve Glendinning 	ret = smsc95xx_read_reg(dev, HW_CFG, &read_buf);
942e360a8b4SSteve Glendinning 	if (ret < 0)
943b052e073SSteve Glendinning 		return ret;
944769ea6d8SSteve Glendinning 
9451e1d7412SJoe Perches 	netif_dbg(dev, ifup, dev->net, "Read Value from HW_CFG: 0x%08x\n",
9461e1d7412SJoe Perches 		  read_buf);
9472f7ca802SSteve Glendinning 
9482f7ca802SSteve Glendinning 	if (turbo_mode)
9492f7ca802SSteve Glendinning 		read_buf |= (HW_CFG_MEF_ | HW_CFG_BCE_);
9502f7ca802SSteve Glendinning 
9512f7ca802SSteve Glendinning 	read_buf &= ~HW_CFG_RXDOFF_;
9522f7ca802SSteve Glendinning 
9532f7ca802SSteve Glendinning 	/* set Rx data offset=2, Make IP header aligns on word boundary. */
9542f7ca802SSteve Glendinning 	read_buf |= NET_IP_ALIGN << 9;
9552f7ca802SSteve Glendinning 
9562f7ca802SSteve Glendinning 	ret = smsc95xx_write_reg(dev, HW_CFG, read_buf);
957e360a8b4SSteve Glendinning 	if (ret < 0)
958b052e073SSteve Glendinning 		return ret;
9592f7ca802SSteve Glendinning 
9602f7ca802SSteve Glendinning 	ret = smsc95xx_read_reg(dev, HW_CFG, &read_buf);
961e360a8b4SSteve Glendinning 	if (ret < 0)
962b052e073SSteve Glendinning 		return ret;
963769ea6d8SSteve Glendinning 
964a475f603SJoe Perches 	netif_dbg(dev, ifup, dev->net,
965a475f603SJoe Perches 		  "Read Value from HW_CFG after writing: 0x%08x\n", read_buf);
9662f7ca802SSteve Glendinning 
9674436761bSSteve Glendinning 	ret = smsc95xx_write_reg(dev, INT_STS, INT_STS_CLEAR_ALL_);
968e360a8b4SSteve Glendinning 	if (ret < 0)
969b052e073SSteve Glendinning 		return ret;
9702f7ca802SSteve Glendinning 
9712f7ca802SSteve Glendinning 	ret = smsc95xx_read_reg(dev, ID_REV, &read_buf);
972e360a8b4SSteve Glendinning 	if (ret < 0)
973b052e073SSteve Glendinning 		return ret;
974a475f603SJoe Perches 	netif_dbg(dev, ifup, dev->net, "ID_REV = 0x%08x\n", read_buf);
9752f7ca802SSteve Glendinning 
976f293501cSSteve Glendinning 	/* Configure GPIO pins as LED outputs */
977f293501cSSteve Glendinning 	write_buf = LED_GPIO_CFG_SPD_LED | LED_GPIO_CFG_LNK_LED |
978f293501cSSteve Glendinning 		LED_GPIO_CFG_FDX_LED;
979f293501cSSteve Glendinning 	ret = smsc95xx_write_reg(dev, LED_GPIO_CFG, write_buf);
980e360a8b4SSteve Glendinning 	if (ret < 0)
981b052e073SSteve Glendinning 		return ret;
982f293501cSSteve Glendinning 
9832f7ca802SSteve Glendinning 	/* Init Tx */
9844436761bSSteve Glendinning 	ret = smsc95xx_write_reg(dev, FLOW, 0);
985e360a8b4SSteve Glendinning 	if (ret < 0)
986b052e073SSteve Glendinning 		return ret;
9872f7ca802SSteve Glendinning 
9884436761bSSteve Glendinning 	ret = smsc95xx_write_reg(dev, AFC_CFG, AFC_CFG_DEFAULT);
989e360a8b4SSteve Glendinning 	if (ret < 0)
990b052e073SSteve Glendinning 		return ret;
9912f7ca802SSteve Glendinning 
9922f7ca802SSteve Glendinning 	/* Don't need mac_cr_lock during initialisation */
9932f7ca802SSteve Glendinning 	ret = smsc95xx_read_reg(dev, MAC_CR, &pdata->mac_cr);
994e360a8b4SSteve Glendinning 	if (ret < 0)
995b052e073SSteve Glendinning 		return ret;
9962f7ca802SSteve Glendinning 
9972f7ca802SSteve Glendinning 	/* Init Rx */
9982f7ca802SSteve Glendinning 	/* Set Vlan */
9994436761bSSteve Glendinning 	ret = smsc95xx_write_reg(dev, VLAN1, (u32)ETH_P_8021Q);
1000e360a8b4SSteve Glendinning 	if (ret < 0)
1001b052e073SSteve Glendinning 		return ret;
10022f7ca802SSteve Glendinning 
1003f7b29271SSteve Glendinning 	/* Enable or disable checksum offload engines */
1004769ea6d8SSteve Glendinning 	ret = smsc95xx_set_features(dev->net, dev->net->features);
1005b052e073SSteve Glendinning 	if (ret < 0) {
1006b052e073SSteve Glendinning 		netdev_warn(dev->net, "Failed to set checksum offload features\n");
1007b052e073SSteve Glendinning 		return ret;
1008b052e073SSteve Glendinning 	}
10092f7ca802SSteve Glendinning 
10102f7ca802SSteve Glendinning 	smsc95xx_set_multicast(dev->net);
10112f7ca802SSteve Glendinning 
10122f7ca802SSteve Glendinning 	ret = smsc95xx_read_reg(dev, INT_EP_CTL, &read_buf);
1013e360a8b4SSteve Glendinning 	if (ret < 0)
1014b052e073SSteve Glendinning 		return ret;
10152f7ca802SSteve Glendinning 
10162f7ca802SSteve Glendinning 	/* enable PHY interrupts */
10172f7ca802SSteve Glendinning 	read_buf |= INT_EP_CTL_PHY_INT_;
10182f7ca802SSteve Glendinning 
10192f7ca802SSteve Glendinning 	ret = smsc95xx_write_reg(dev, INT_EP_CTL, read_buf);
1020e360a8b4SSteve Glendinning 	if (ret < 0)
1021b052e073SSteve Glendinning 		return ret;
10222f7ca802SSteve Glendinning 
1023769ea6d8SSteve Glendinning 	ret = smsc95xx_start_tx_path(dev);
1024b052e073SSteve Glendinning 	if (ret < 0) {
1025b052e073SSteve Glendinning 		netdev_warn(dev->net, "Failed to start TX path\n");
1026b052e073SSteve Glendinning 		return ret;
1027b052e073SSteve Glendinning 	}
1028769ea6d8SSteve Glendinning 
1029ec32115dSMing Lei 	ret = smsc95xx_start_rx_path(dev, 0);
1030b052e073SSteve Glendinning 	if (ret < 0) {
1031b052e073SSteve Glendinning 		netdev_warn(dev->net, "Failed to start RX path\n");
1032b052e073SSteve Glendinning 		return ret;
1033b052e073SSteve Glendinning 	}
10342f7ca802SSteve Glendinning 
1035a475f603SJoe Perches 	netif_dbg(dev, ifup, dev->net, "smsc95xx_reset, return 0\n");
10362f7ca802SSteve Glendinning 	return 0;
10372f7ca802SSteve Glendinning }
10382f7ca802SSteve Glendinning 
103963e77b39SStephen Hemminger static const struct net_device_ops smsc95xx_netdev_ops = {
104063e77b39SStephen Hemminger 	.ndo_open		= usbnet_open,
104163e77b39SStephen Hemminger 	.ndo_stop		= usbnet_stop,
104263e77b39SStephen Hemminger 	.ndo_start_xmit		= usbnet_start_xmit,
104363e77b39SStephen Hemminger 	.ndo_tx_timeout		= usbnet_tx_timeout,
104463e77b39SStephen Hemminger 	.ndo_change_mtu		= usbnet_change_mtu,
1045323955a0SHeiner Kallweit 	.ndo_get_stats64	= dev_get_tstats64,
104663e77b39SStephen Hemminger 	.ndo_set_mac_address 	= eth_mac_addr,
104763e77b39SStephen Hemminger 	.ndo_validate_addr	= eth_validate_addr,
1048a7605370SArnd Bergmann 	.ndo_eth_ioctl		= smsc95xx_ioctl,
1049afc4b13dSJiri Pirko 	.ndo_set_rx_mode	= smsc95xx_set_multicast,
105078e47fe4SMichał Mirosław 	.ndo_set_features	= smsc95xx_set_features,
105163e77b39SStephen Hemminger };
105263e77b39SStephen Hemminger 
10532f7ca802SSteve Glendinning static int smsc95xx_bind(struct usbnet *dev, struct usb_interface *intf)
10542f7ca802SSteve Glendinning {
1055ad90a73fSAndre Edich 	struct smsc95xx_priv *pdata;
105605b35e7eSAndre Edich 	bool is_internal_phy;
1057bbd9f9eeSSteve Glendinning 	u32 val;
10582f7ca802SSteve Glendinning 	int ret;
10592f7ca802SSteve Glendinning 
10602f7ca802SSteve Glendinning 	printk(KERN_INFO SMSC_CHIPNAME " v" SMSC_DRIVER_VERSION "\n");
10612f7ca802SSteve Glendinning 
10622f7ca802SSteve Glendinning 	ret = usbnet_get_endpoints(dev, intf);
1063b052e073SSteve Glendinning 	if (ret < 0) {
1064b052e073SSteve Glendinning 		netdev_warn(dev->net, "usbnet_get_endpoints failed: %d\n", ret);
1065b052e073SSteve Glendinning 		return ret;
1066b052e073SSteve Glendinning 	}
10672f7ca802SSteve Glendinning 
1068ad90a73fSAndre Edich 	pdata = kzalloc(sizeof(*pdata), GFP_KERNEL);
106938673c82SJoe Perches 	if (!pdata)
10702f7ca802SSteve Glendinning 		return -ENOMEM;
10712f7ca802SSteve Glendinning 
1072ad90a73fSAndre Edich 	dev->driver_priv = pdata;
1073ad90a73fSAndre Edich 
10742f7ca802SSteve Glendinning 	spin_lock_init(&pdata->mac_cr_lock);
10752f7ca802SSteve Glendinning 
1076fe0cd8caSNisar Sayed 	/* LAN95xx devices do not alter the computed checksum of 0 to 0xffff.
1077fe0cd8caSNisar Sayed 	 * RFC 2460, ipv6 UDP calculated checksum yields a result of zero must
1078fe0cd8caSNisar Sayed 	 * be changed to 0xffff. RFC 768, ipv4 UDP computed checksum is zero,
1079fe0cd8caSNisar Sayed 	 * it is transmitted as all ones. The zero transmitted checksum means
1080fe0cd8caSNisar Sayed 	 * transmitter generated no checksum. Hence, enable csum offload only
1081fe0cd8caSNisar Sayed 	 * for ipv4 packets.
1082fe0cd8caSNisar Sayed 	 */
108378e47fe4SMichał Mirosław 	if (DEFAULT_TX_CSUM_ENABLE)
1084fe0cd8caSNisar Sayed 		dev->net->features |= NETIF_F_IP_CSUM;
108578e47fe4SMichał Mirosław 	if (DEFAULT_RX_CSUM_ENABLE)
108678e47fe4SMichał Mirosław 		dev->net->features |= NETIF_F_RXCSUM;
108778e47fe4SMichał Mirosław 
1088fe0cd8caSNisar Sayed 	dev->net->hw_features = NETIF_F_IP_CSUM | NETIF_F_RXCSUM;
1089810eeb1fSBen Dooks 	set_bit(EVENT_NO_IP_ALIGN, &dev->flags);
10902f7ca802SSteve Glendinning 
1091f4e8ab7cSBernard Blackham 	smsc95xx_init_mac_address(dev);
1092f4e8ab7cSBernard Blackham 
10932f7ca802SSteve Glendinning 	/* Init all registers */
10942f7ca802SSteve Glendinning 	ret = smsc95xx_reset(dev);
10957c8b1e85SAndre Edich 	if (ret)
10967c8b1e85SAndre Edich 		goto free_pdata;
10972f7ca802SSteve Glendinning 
109805b35e7eSAndre Edich 	pdata->mdiobus = mdiobus_alloc();
109905b35e7eSAndre Edich 	if (!pdata->mdiobus) {
110005b35e7eSAndre Edich 		ret = -ENOMEM;
110105b35e7eSAndre Edich 		goto free_pdata;
110205b35e7eSAndre Edich 	}
110305b35e7eSAndre Edich 
110405b35e7eSAndre Edich 	ret = smsc95xx_read_reg(dev, HW_CFG, &val);
110505b35e7eSAndre Edich 	if (ret < 0)
110605b35e7eSAndre Edich 		goto free_mdio;
110705b35e7eSAndre Edich 
110805b35e7eSAndre Edich 	is_internal_phy = !(val & HW_CFG_PSEL_);
110905b35e7eSAndre Edich 	if (is_internal_phy)
111005b35e7eSAndre Edich 		pdata->mdiobus->phy_mask = ~(1u << SMSC95XX_INTERNAL_PHY_ID);
111105b35e7eSAndre Edich 
111205b35e7eSAndre Edich 	pdata->mdiobus->priv = dev;
111305b35e7eSAndre Edich 	pdata->mdiobus->read = smsc95xx_mdiobus_read;
111405b35e7eSAndre Edich 	pdata->mdiobus->write = smsc95xx_mdiobus_write;
111505b35e7eSAndre Edich 	pdata->mdiobus->name = "smsc95xx-mdiobus";
111605b35e7eSAndre Edich 	pdata->mdiobus->parent = &dev->udev->dev;
111705b35e7eSAndre Edich 
111805b35e7eSAndre Edich 	snprintf(pdata->mdiobus->id, ARRAY_SIZE(pdata->mdiobus->id),
111905b35e7eSAndre Edich 		 "usb-%03d:%03d", dev->udev->bus->busnum, dev->udev->devnum);
112005b35e7eSAndre Edich 
112105b35e7eSAndre Edich 	ret = mdiobus_register(pdata->mdiobus);
112205b35e7eSAndre Edich 	if (ret) {
112305b35e7eSAndre Edich 		netdev_err(dev->net, "Could not register MDIO bus\n");
112405b35e7eSAndre Edich 		goto free_mdio;
112505b35e7eSAndre Edich 	}
112605b35e7eSAndre Edich 
112705b35e7eSAndre Edich 	pdata->phydev = phy_find_first(pdata->mdiobus);
112805b35e7eSAndre Edich 	if (!pdata->phydev) {
112905b35e7eSAndre Edich 		netdev_err(dev->net, "no PHY found\n");
113005b35e7eSAndre Edich 		ret = -ENODEV;
113105b35e7eSAndre Edich 		goto unregister_mdio;
113205b35e7eSAndre Edich 	}
113305b35e7eSAndre Edich 
113405b35e7eSAndre Edich 	pdata->phydev->is_internal = is_internal_phy;
113505b35e7eSAndre Edich 
1136bbd9f9eeSSteve Glendinning 	/* detect device revision as different features may be available */
1137bbd9f9eeSSteve Glendinning 	ret = smsc95xx_read_reg(dev, ID_REV, &val);
1138e360a8b4SSteve Glendinning 	if (ret < 0)
113905b35e7eSAndre Edich 		goto unregister_mdio;
11403ed58f96SAndre Edich 
1141bbd9f9eeSSteve Glendinning 	val >>= 16;
11429ebca507SSteve Glendinning 	if ((val == ID_REV_CHIP_ID_9500A_) || (val == ID_REV_CHIP_ID_9530_) ||
11439ebca507SSteve Glendinning 	    (val == ID_REV_CHIP_ID_89530_) || (val == ID_REV_CHIP_ID_9730_))
11449ebca507SSteve Glendinning 		pdata->features = (FEATURE_8_WAKEUP_FILTERS |
11459ebca507SSteve Glendinning 			FEATURE_PHY_NLP_CROSSOVER |
1146eb970ff0SMing Lei 			FEATURE_REMOTE_WAKEUP);
11479ebca507SSteve Glendinning 	else if (val == ID_REV_CHIP_ID_9512_)
11489ebca507SSteve Glendinning 		pdata->features = FEATURE_8_WAKEUP_FILTERS;
1149bbd9f9eeSSteve Glendinning 
115063e77b39SStephen Hemminger 	dev->net->netdev_ops = &smsc95xx_netdev_ops;
11512f7ca802SSteve Glendinning 	dev->net->ethtool_ops = &smsc95xx_ethtool_ops;
11522f7ca802SSteve Glendinning 	dev->net->flags |= IFF_MULTICAST;
115378e47fe4SMichał Mirosław 	dev->net->hard_header_len += SMSC95XX_TX_OVERHEAD_CSUM;
115485b18b02SStefan Wahren 	dev->net->min_mtu = ETH_MIN_MTU;
115585b18b02SStefan Wahren 	dev->net->max_mtu = ETH_DATA_LEN;
11569bbf5660SStephane Fillod 	dev->hard_mtu = dev->net->mtu + dev->net->hard_header_len;
11572f7ca802SSteve Glendinning 	return 0;
11587c8b1e85SAndre Edich 
115905b35e7eSAndre Edich unregister_mdio:
116005b35e7eSAndre Edich 	mdiobus_unregister(pdata->mdiobus);
116105b35e7eSAndre Edich 
116205b35e7eSAndre Edich free_mdio:
116305b35e7eSAndre Edich 	mdiobus_free(pdata->mdiobus);
116405b35e7eSAndre Edich 
11657c8b1e85SAndre Edich free_pdata:
11667c8b1e85SAndre Edich 	kfree(pdata);
11677c8b1e85SAndre Edich 	return ret;
11682f7ca802SSteve Glendinning }
11692f7ca802SSteve Glendinning 
11702f7ca802SSteve Glendinning static void smsc95xx_unbind(struct usbnet *dev, struct usb_interface *intf)
11712f7ca802SSteve Glendinning {
1172ad90a73fSAndre Edich 	struct smsc95xx_priv *pdata = dev->driver_priv;
1173d69d1694SChristoph Fritz 
117405b35e7eSAndre Edich 	mdiobus_unregister(pdata->mdiobus);
117505b35e7eSAndre Edich 	mdiobus_free(pdata->mdiobus);
1176a475f603SJoe Perches 	netif_dbg(dev, ifdown, dev->net, "free pdata\n");
11772f7ca802SSteve Glendinning 	kfree(pdata);
11782f7ca802SSteve Glendinning }
11792f7ca802SSteve Glendinning 
118005b35e7eSAndre Edich static void smsc95xx_handle_link_change(struct net_device *net)
118105b35e7eSAndre Edich {
11825ab8a447SAaro Koskinen 	struct usbnet *dev = netdev_priv(net);
11835ab8a447SAaro Koskinen 
118405b35e7eSAndre Edich 	phy_print_status(net->phydev);
11855ab8a447SAaro Koskinen 	usbnet_defer_kevent(dev, EVENT_LINK_CHANGE);
118605b35e7eSAndre Edich }
118705b35e7eSAndre Edich 
118805b35e7eSAndre Edich static int smsc95xx_start_phy(struct usbnet *dev)
118905b35e7eSAndre Edich {
119005b35e7eSAndre Edich 	struct smsc95xx_priv *pdata = dev->driver_priv;
119105b35e7eSAndre Edich 	struct net_device *net = dev->net;
119205b35e7eSAndre Edich 	int ret;
119305b35e7eSAndre Edich 
119405b35e7eSAndre Edich 	ret = smsc95xx_reset(dev);
119505b35e7eSAndre Edich 	if (ret < 0)
119605b35e7eSAndre Edich 		return ret;
119705b35e7eSAndre Edich 
119805b35e7eSAndre Edich 	ret = phy_connect_direct(net, pdata->phydev,
119905b35e7eSAndre Edich 				 &smsc95xx_handle_link_change,
120005b35e7eSAndre Edich 				 PHY_INTERFACE_MODE_MII);
120105b35e7eSAndre Edich 	if (ret) {
120205b35e7eSAndre Edich 		netdev_err(net, "can't attach PHY to %s\n", pdata->mdiobus->id);
120305b35e7eSAndre Edich 		return ret;
120405b35e7eSAndre Edich 	}
120505b35e7eSAndre Edich 
120605b35e7eSAndre Edich 	phy_attached_info(net->phydev);
120705b35e7eSAndre Edich 	phy_start(net->phydev);
120805b35e7eSAndre Edich 	return 0;
120905b35e7eSAndre Edich }
121005b35e7eSAndre Edich 
121105b35e7eSAndre Edich static int smsc95xx_disconnect_phy(struct usbnet *dev)
121205b35e7eSAndre Edich {
121305b35e7eSAndre Edich 	phy_stop(dev->net->phydev);
121405b35e7eSAndre Edich 	phy_disconnect(dev->net->phydev);
121505b35e7eSAndre Edich 	return 0;
121605b35e7eSAndre Edich }
121705b35e7eSAndre Edich 
1218068bb1a7SSteve Glendinning static u32 smsc_crc(const u8 *buffer, size_t len, int filter)
1219bbd9f9eeSSteve Glendinning {
1220068bb1a7SSteve Glendinning 	u32 crc = bitrev16(crc16(0xFFFF, buffer, len));
1221068bb1a7SSteve Glendinning 	return crc << ((filter % 2) * 16);
1222bbd9f9eeSSteve Glendinning }
1223bbd9f9eeSSteve Glendinning 
1224e5e3af83SSteve Glendinning static int smsc95xx_enable_phy_wakeup_interrupts(struct usbnet *dev, u16 mask)
1225e5e3af83SSteve Glendinning {
1226e5e3af83SSteve Glendinning 	int ret;
1227e5e3af83SSteve Glendinning 
12281e1d7412SJoe Perches 	netdev_dbg(dev->net, "enabling PHY wakeup interrupts\n");
1229e5e3af83SSteve Glendinning 
1230e5e3af83SSteve Glendinning 	/* read to clear */
1231368be1caSAndre Edich 	ret = smsc95xx_mdio_read_nopm(dev, PHY_INT_SRC);
1232e360a8b4SSteve Glendinning 	if (ret < 0)
1233b052e073SSteve Glendinning 		return ret;
1234e5e3af83SSteve Glendinning 
1235e5e3af83SSteve Glendinning 	/* enable interrupt source */
1236368be1caSAndre Edich 	ret = smsc95xx_mdio_read_nopm(dev, PHY_INT_MASK);
1237e360a8b4SSteve Glendinning 	if (ret < 0)
1238b052e073SSteve Glendinning 		return ret;
1239e5e3af83SSteve Glendinning 
1240e5e3af83SSteve Glendinning 	ret |= mask;
1241e5e3af83SSteve Glendinning 
1242368be1caSAndre Edich 	smsc95xx_mdio_write_nopm(dev, PHY_INT_MASK, ret);
1243e5e3af83SSteve Glendinning 
1244e5e3af83SSteve Glendinning 	return 0;
1245e5e3af83SSteve Glendinning }
1246e5e3af83SSteve Glendinning 
1247e5e3af83SSteve Glendinning static int smsc95xx_link_ok_nopm(struct usbnet *dev)
1248e5e3af83SSteve Glendinning {
1249e5e3af83SSteve Glendinning 	int ret;
1250e5e3af83SSteve Glendinning 
1251e5e3af83SSteve Glendinning 	/* first, a dummy read, needed to latch some MII phys */
1252368be1caSAndre Edich 	ret = smsc95xx_mdio_read_nopm(dev, MII_BMSR);
1253e360a8b4SSteve Glendinning 	if (ret < 0)
1254b052e073SSteve Glendinning 		return ret;
1255e5e3af83SSteve Glendinning 
1256368be1caSAndre Edich 	ret = smsc95xx_mdio_read_nopm(dev, MII_BMSR);
1257e360a8b4SSteve Glendinning 	if (ret < 0)
1258b052e073SSteve Glendinning 		return ret;
1259e5e3af83SSteve Glendinning 
1260e5e3af83SSteve Glendinning 	return !!(ret & BMSR_LSTATUS);
1261e5e3af83SSteve Glendinning }
1262e5e3af83SSteve Glendinning 
1263319b95b5SSteve Glendinning static int smsc95xx_enter_suspend0(struct usbnet *dev)
1264319b95b5SSteve Glendinning {
1265ad90a73fSAndre Edich 	struct smsc95xx_priv *pdata = dev->driver_priv;
1266319b95b5SSteve Glendinning 	u32 val;
1267319b95b5SSteve Glendinning 	int ret;
1268319b95b5SSteve Glendinning 
1269319b95b5SSteve Glendinning 	ret = smsc95xx_read_reg_nopm(dev, PM_CTRL, &val);
1270e360a8b4SSteve Glendinning 	if (ret < 0)
1271b052e073SSteve Glendinning 		return ret;
1272319b95b5SSteve Glendinning 
1273319b95b5SSteve Glendinning 	val &= (~(PM_CTL_SUS_MODE_ | PM_CTL_WUPS_ | PM_CTL_PHY_RST_));
1274319b95b5SSteve Glendinning 	val |= PM_CTL_SUS_MODE_0;
1275319b95b5SSteve Glendinning 
1276319b95b5SSteve Glendinning 	ret = smsc95xx_write_reg_nopm(dev, PM_CTRL, val);
1277e360a8b4SSteve Glendinning 	if (ret < 0)
1278b052e073SSteve Glendinning 		return ret;
1279319b95b5SSteve Glendinning 
1280319b95b5SSteve Glendinning 	/* clear wol status */
1281319b95b5SSteve Glendinning 	val &= ~PM_CTL_WUPS_;
1282319b95b5SSteve Glendinning 	val |= PM_CTL_WUPS_WOL_;
1283319b95b5SSteve Glendinning 
1284319b95b5SSteve Glendinning 	/* enable energy detection */
1285319b95b5SSteve Glendinning 	if (pdata->wolopts & WAKE_PHY)
1286319b95b5SSteve Glendinning 		val |= PM_CTL_WUPS_ED_;
1287319b95b5SSteve Glendinning 
1288319b95b5SSteve Glendinning 	ret = smsc95xx_write_reg_nopm(dev, PM_CTRL, val);
1289e360a8b4SSteve Glendinning 	if (ret < 0)
1290b052e073SSteve Glendinning 		return ret;
1291319b95b5SSteve Glendinning 
1292319b95b5SSteve Glendinning 	/* read back PM_CTRL */
1293319b95b5SSteve Glendinning 	ret = smsc95xx_read_reg_nopm(dev, PM_CTRL, &val);
129476437214SMing Lei 	if (ret < 0)
129576437214SMing Lei 		return ret;
1296319b95b5SSteve Glendinning 
1297b2d4b150SSteve Glendinning 	pdata->suspend_flags |= SUSPEND_SUSPEND0;
1298b2d4b150SSteve Glendinning 
129976437214SMing Lei 	return 0;
1300319b95b5SSteve Glendinning }
1301319b95b5SSteve Glendinning 
1302319b95b5SSteve Glendinning static int smsc95xx_enter_suspend1(struct usbnet *dev)
1303319b95b5SSteve Glendinning {
1304ad90a73fSAndre Edich 	struct smsc95xx_priv *pdata = dev->driver_priv;
1305319b95b5SSteve Glendinning 	u32 val;
1306319b95b5SSteve Glendinning 	int ret;
1307319b95b5SSteve Glendinning 
1308319b95b5SSteve Glendinning 	/* reconfigure link pulse detection timing for
1309319b95b5SSteve Glendinning 	 * compatibility with non-standard link partners
1310319b95b5SSteve Glendinning 	 */
1311319b95b5SSteve Glendinning 	if (pdata->features & FEATURE_PHY_NLP_CROSSOVER)
1312368be1caSAndre Edich 		smsc95xx_mdio_write_nopm(dev, PHY_EDPD_CONFIG,
1313319b95b5SSteve Glendinning 					 PHY_EDPD_CONFIG_DEFAULT);
1314319b95b5SSteve Glendinning 
1315319b95b5SSteve Glendinning 	/* enable energy detect power-down mode */
1316368be1caSAndre Edich 	ret = smsc95xx_mdio_read_nopm(dev, PHY_MODE_CTRL_STS);
1317e360a8b4SSteve Glendinning 	if (ret < 0)
1318b052e073SSteve Glendinning 		return ret;
1319319b95b5SSteve Glendinning 
1320319b95b5SSteve Glendinning 	ret |= MODE_CTRL_STS_EDPWRDOWN_;
1321319b95b5SSteve Glendinning 
1322368be1caSAndre Edich 	smsc95xx_mdio_write_nopm(dev, PHY_MODE_CTRL_STS, ret);
1323319b95b5SSteve Glendinning 
1324319b95b5SSteve Glendinning 	/* enter SUSPEND1 mode */
1325319b95b5SSteve Glendinning 	ret = smsc95xx_read_reg_nopm(dev, PM_CTRL, &val);
1326e360a8b4SSteve Glendinning 	if (ret < 0)
1327b052e073SSteve Glendinning 		return ret;
1328319b95b5SSteve Glendinning 
1329319b95b5SSteve Glendinning 	val &= ~(PM_CTL_SUS_MODE_ | PM_CTL_WUPS_ | PM_CTL_PHY_RST_);
1330319b95b5SSteve Glendinning 	val |= PM_CTL_SUS_MODE_1;
1331319b95b5SSteve Glendinning 
1332319b95b5SSteve Glendinning 	ret = smsc95xx_write_reg_nopm(dev, PM_CTRL, val);
1333e360a8b4SSteve Glendinning 	if (ret < 0)
1334b052e073SSteve Glendinning 		return ret;
1335319b95b5SSteve Glendinning 
1336319b95b5SSteve Glendinning 	/* clear wol status, enable energy detection */
1337319b95b5SSteve Glendinning 	val &= ~PM_CTL_WUPS_;
1338319b95b5SSteve Glendinning 	val |= (PM_CTL_WUPS_ED_ | PM_CTL_ED_EN_);
1339319b95b5SSteve Glendinning 
1340319b95b5SSteve Glendinning 	ret = smsc95xx_write_reg_nopm(dev, PM_CTRL, val);
134176437214SMing Lei 	if (ret < 0)
134276437214SMing Lei 		return ret;
1343319b95b5SSteve Glendinning 
1344b2d4b150SSteve Glendinning 	pdata->suspend_flags |= SUSPEND_SUSPEND1;
1345b2d4b150SSteve Glendinning 
134676437214SMing Lei 	return 0;
1347319b95b5SSteve Glendinning }
1348319b95b5SSteve Glendinning 
1349319b95b5SSteve Glendinning static int smsc95xx_enter_suspend2(struct usbnet *dev)
1350319b95b5SSteve Glendinning {
1351ad90a73fSAndre Edich 	struct smsc95xx_priv *pdata = dev->driver_priv;
1352319b95b5SSteve Glendinning 	u32 val;
1353319b95b5SSteve Glendinning 	int ret;
1354319b95b5SSteve Glendinning 
1355319b95b5SSteve Glendinning 	ret = smsc95xx_read_reg_nopm(dev, PM_CTRL, &val);
1356e360a8b4SSteve Glendinning 	if (ret < 0)
1357b052e073SSteve Glendinning 		return ret;
1358319b95b5SSteve Glendinning 
1359319b95b5SSteve Glendinning 	val &= ~(PM_CTL_SUS_MODE_ | PM_CTL_WUPS_ | PM_CTL_PHY_RST_);
1360319b95b5SSteve Glendinning 	val |= PM_CTL_SUS_MODE_2;
1361319b95b5SSteve Glendinning 
1362319b95b5SSteve Glendinning 	ret = smsc95xx_write_reg_nopm(dev, PM_CTRL, val);
136376437214SMing Lei 	if (ret < 0)
136476437214SMing Lei 		return ret;
1365319b95b5SSteve Glendinning 
1366b2d4b150SSteve Glendinning 	pdata->suspend_flags |= SUSPEND_SUSPEND2;
1367b2d4b150SSteve Glendinning 
136876437214SMing Lei 	return 0;
1369319b95b5SSteve Glendinning }
1370319b95b5SSteve Glendinning 
1371b2d4b150SSteve Glendinning static int smsc95xx_enter_suspend3(struct usbnet *dev)
1372b2d4b150SSteve Glendinning {
1373ad90a73fSAndre Edich 	struct smsc95xx_priv *pdata = dev->driver_priv;
1374b2d4b150SSteve Glendinning 	u32 val;
1375b2d4b150SSteve Glendinning 	int ret;
1376b2d4b150SSteve Glendinning 
1377b2d4b150SSteve Glendinning 	ret = smsc95xx_read_reg_nopm(dev, RX_FIFO_INF, &val);
1378b2d4b150SSteve Glendinning 	if (ret < 0)
1379b2d4b150SSteve Glendinning 		return ret;
1380b2d4b150SSteve Glendinning 
138153a759c8SMartin Wetterwald 	if (val & RX_FIFO_INF_USED_) {
1382b2d4b150SSteve Glendinning 		netdev_info(dev->net, "rx fifo not empty in autosuspend\n");
1383b2d4b150SSteve Glendinning 		return -EBUSY;
1384b2d4b150SSteve Glendinning 	}
1385b2d4b150SSteve Glendinning 
1386b2d4b150SSteve Glendinning 	ret = smsc95xx_read_reg_nopm(dev, PM_CTRL, &val);
1387b2d4b150SSteve Glendinning 	if (ret < 0)
1388b2d4b150SSteve Glendinning 		return ret;
1389b2d4b150SSteve Glendinning 
1390b2d4b150SSteve Glendinning 	val &= ~(PM_CTL_SUS_MODE_ | PM_CTL_WUPS_ | PM_CTL_PHY_RST_);
1391b2d4b150SSteve Glendinning 	val |= PM_CTL_SUS_MODE_3 | PM_CTL_RES_CLR_WKP_STS;
1392b2d4b150SSteve Glendinning 
1393b2d4b150SSteve Glendinning 	ret = smsc95xx_write_reg_nopm(dev, PM_CTRL, val);
1394b2d4b150SSteve Glendinning 	if (ret < 0)
1395b2d4b150SSteve Glendinning 		return ret;
1396b2d4b150SSteve Glendinning 
1397b2d4b150SSteve Glendinning 	/* clear wol status */
1398b2d4b150SSteve Glendinning 	val &= ~PM_CTL_WUPS_;
1399b2d4b150SSteve Glendinning 	val |= PM_CTL_WUPS_WOL_;
1400b2d4b150SSteve Glendinning 
1401b2d4b150SSteve Glendinning 	ret = smsc95xx_write_reg_nopm(dev, PM_CTRL, val);
1402b2d4b150SSteve Glendinning 	if (ret < 0)
1403b2d4b150SSteve Glendinning 		return ret;
1404b2d4b150SSteve Glendinning 
1405b2d4b150SSteve Glendinning 	pdata->suspend_flags |= SUSPEND_SUSPEND3;
1406b2d4b150SSteve Glendinning 
1407b2d4b150SSteve Glendinning 	return 0;
1408b2d4b150SSteve Glendinning }
1409b2d4b150SSteve Glendinning 
1410b2d4b150SSteve Glendinning static int smsc95xx_autosuspend(struct usbnet *dev, u32 link_up)
1411b2d4b150SSteve Glendinning {
1412ad90a73fSAndre Edich 	struct smsc95xx_priv *pdata = dev->driver_priv;
1413b2d4b150SSteve Glendinning 	int ret;
1414b2d4b150SSteve Glendinning 
1415b2d4b150SSteve Glendinning 	if (!netif_running(dev->net)) {
1416b2d4b150SSteve Glendinning 		/* interface is ifconfig down so fully power down hw */
1417b2d4b150SSteve Glendinning 		netdev_dbg(dev->net, "autosuspend entering SUSPEND2\n");
1418b2d4b150SSteve Glendinning 		return smsc95xx_enter_suspend2(dev);
1419b2d4b150SSteve Glendinning 	}
1420b2d4b150SSteve Glendinning 
1421b2d4b150SSteve Glendinning 	if (!link_up) {
1422b2d4b150SSteve Glendinning 		/* link is down so enter EDPD mode, but only if device can
1423b2d4b150SSteve Glendinning 		 * reliably resume from it.  This check should be redundant
1424eb970ff0SMing Lei 		 * as current FEATURE_REMOTE_WAKEUP parts also support
1425b2d4b150SSteve Glendinning 		 * FEATURE_PHY_NLP_CROSSOVER but it's included for clarity */
1426b2d4b150SSteve Glendinning 		if (!(pdata->features & FEATURE_PHY_NLP_CROSSOVER)) {
1427b2d4b150SSteve Glendinning 			netdev_warn(dev->net, "EDPD not supported\n");
1428b2d4b150SSteve Glendinning 			return -EBUSY;
1429b2d4b150SSteve Glendinning 		}
1430b2d4b150SSteve Glendinning 
1431b2d4b150SSteve Glendinning 		netdev_dbg(dev->net, "autosuspend entering SUSPEND1\n");
1432b2d4b150SSteve Glendinning 
1433b2d4b150SSteve Glendinning 		/* enable PHY wakeup events for if cable is attached */
1434b2d4b150SSteve Glendinning 		ret = smsc95xx_enable_phy_wakeup_interrupts(dev,
1435b2d4b150SSteve Glendinning 			PHY_INT_MASK_ANEG_COMP_);
1436b2d4b150SSteve Glendinning 		if (ret < 0) {
1437b2d4b150SSteve Glendinning 			netdev_warn(dev->net, "error enabling PHY wakeup ints\n");
1438b2d4b150SSteve Glendinning 			return ret;
1439b2d4b150SSteve Glendinning 		}
1440b2d4b150SSteve Glendinning 
1441b2d4b150SSteve Glendinning 		netdev_info(dev->net, "entering SUSPEND1 mode\n");
1442b2d4b150SSteve Glendinning 		return smsc95xx_enter_suspend1(dev);
1443b2d4b150SSteve Glendinning 	}
1444b2d4b150SSteve Glendinning 
1445b2d4b150SSteve Glendinning 	/* enable PHY wakeup events so we remote wakeup if cable is pulled */
1446b2d4b150SSteve Glendinning 	ret = smsc95xx_enable_phy_wakeup_interrupts(dev,
1447b2d4b150SSteve Glendinning 		PHY_INT_MASK_LINK_DOWN_);
1448b2d4b150SSteve Glendinning 	if (ret < 0) {
1449b2d4b150SSteve Glendinning 		netdev_warn(dev->net, "error enabling PHY wakeup ints\n");
1450b2d4b150SSteve Glendinning 		return ret;
1451b2d4b150SSteve Glendinning 	}
1452b2d4b150SSteve Glendinning 
1453b2d4b150SSteve Glendinning 	netdev_dbg(dev->net, "autosuspend entering SUSPEND3\n");
1454b2d4b150SSteve Glendinning 	return smsc95xx_enter_suspend3(dev);
1455b2d4b150SSteve Glendinning }
1456b2d4b150SSteve Glendinning 
1457b5a04475SSteve Glendinning static int smsc95xx_suspend(struct usb_interface *intf, pm_message_t message)
1458b5a04475SSteve Glendinning {
1459b5a04475SSteve Glendinning 	struct usbnet *dev = usb_get_intfdata(intf);
1460ad90a73fSAndre Edich 	struct smsc95xx_priv *pdata = dev->driver_priv;
1461e5e3af83SSteve Glendinning 	u32 val, link_up;
1462b5a04475SSteve Glendinning 	int ret;
1463b5a04475SSteve Glendinning 
1464b5a04475SSteve Glendinning 	ret = usbnet_suspend(intf, message);
1465b052e073SSteve Glendinning 	if (ret < 0) {
1466b052e073SSteve Glendinning 		netdev_warn(dev->net, "usbnet_suspend error\n");
1467b052e073SSteve Glendinning 		return ret;
1468b052e073SSteve Glendinning 	}
1469b5a04475SSteve Glendinning 
1470b2d4b150SSteve Glendinning 	if (pdata->suspend_flags) {
1471b2d4b150SSteve Glendinning 		netdev_warn(dev->net, "error during last resume\n");
1472b2d4b150SSteve Glendinning 		pdata->suspend_flags = 0;
1473b2d4b150SSteve Glendinning 	}
1474b2d4b150SSteve Glendinning 
1475e5e3af83SSteve Glendinning 	/* determine if link is up using only _nopm functions */
1476e5e3af83SSteve Glendinning 	link_up = smsc95xx_link_ok_nopm(dev);
1477e5e3af83SSteve Glendinning 
147842e21c01SMing Lei 	if (message.event == PM_EVENT_AUTO_SUSPEND &&
1479eb970ff0SMing Lei 	    (pdata->features & FEATURE_REMOTE_WAKEUP)) {
1480b2d4b150SSteve Glendinning 		ret = smsc95xx_autosuspend(dev, link_up);
1481b2d4b150SSteve Glendinning 		goto done;
1482b2d4b150SSteve Glendinning 	}
1483b2d4b150SSteve Glendinning 
1484b2d4b150SSteve Glendinning 	/* if we get this far we're not autosuspending */
1485e5e3af83SSteve Glendinning 	/* if no wol options set, or if link is down and we're not waking on
1486e5e3af83SSteve Glendinning 	 * PHY activity, enter lowest power SUSPEND2 mode
1487e5e3af83SSteve Glendinning 	 */
1488e5e3af83SSteve Glendinning 	if (!(pdata->wolopts & SUPPORTED_WAKE) ||
1489e5e3af83SSteve Glendinning 		!(link_up || (pdata->wolopts & WAKE_PHY))) {
14901e1d7412SJoe Perches 		netdev_info(dev->net, "entering SUSPEND2 mode\n");
1491b5a04475SSteve Glendinning 
1492e0e474a8SSteve Glendinning 		/* disable energy detect (link up) & wake up events */
1493ec32115dSMing Lei 		ret = smsc95xx_read_reg_nopm(dev, WUCSR, &val);
1494e360a8b4SSteve Glendinning 		if (ret < 0)
1495b052e073SSteve Glendinning 			goto done;
1496e0e474a8SSteve Glendinning 
1497e0e474a8SSteve Glendinning 		val &= ~(WUCSR_MPEN_ | WUCSR_WAKE_EN_);
1498e0e474a8SSteve Glendinning 
1499ec32115dSMing Lei 		ret = smsc95xx_write_reg_nopm(dev, WUCSR, val);
1500e360a8b4SSteve Glendinning 		if (ret < 0)
1501b052e073SSteve Glendinning 			goto done;
1502e0e474a8SSteve Glendinning 
1503ec32115dSMing Lei 		ret = smsc95xx_read_reg_nopm(dev, PM_CTRL, &val);
1504e360a8b4SSteve Glendinning 		if (ret < 0)
1505b052e073SSteve Glendinning 			goto done;
1506e0e474a8SSteve Glendinning 
1507e0e474a8SSteve Glendinning 		val &= ~(PM_CTL_ED_EN_ | PM_CTL_WOL_EN_);
1508e0e474a8SSteve Glendinning 
1509ec32115dSMing Lei 		ret = smsc95xx_write_reg_nopm(dev, PM_CTRL, val);
1510e360a8b4SSteve Glendinning 		if (ret < 0)
1511b052e073SSteve Glendinning 			goto done;
1512e0e474a8SSteve Glendinning 
15133b9f7d8cSSteve Glendinning 		ret = smsc95xx_enter_suspend2(dev);
15143b9f7d8cSSteve Glendinning 		goto done;
1515b5a04475SSteve Glendinning 	}
1516b5a04475SSteve Glendinning 
1517e5e3af83SSteve Glendinning 	if (pdata->wolopts & WAKE_PHY) {
1518e5e3af83SSteve Glendinning 		ret = smsc95xx_enable_phy_wakeup_interrupts(dev,
1519e5e3af83SSteve Glendinning 			(PHY_INT_MASK_ANEG_COMP_ | PHY_INT_MASK_LINK_DOWN_));
1520b052e073SSteve Glendinning 		if (ret < 0) {
1521b052e073SSteve Glendinning 			netdev_warn(dev->net, "error enabling PHY wakeup ints\n");
1522b052e073SSteve Glendinning 			goto done;
1523b052e073SSteve Glendinning 		}
1524e5e3af83SSteve Glendinning 
1525e5e3af83SSteve Glendinning 		/* if link is down then configure EDPD and enter SUSPEND1,
1526e5e3af83SSteve Glendinning 		 * otherwise enter SUSPEND0 below
1527e5e3af83SSteve Glendinning 		 */
1528e5e3af83SSteve Glendinning 		if (!link_up) {
15291e1d7412SJoe Perches 			netdev_info(dev->net, "entering SUSPEND1 mode\n");
15303b9f7d8cSSteve Glendinning 			ret = smsc95xx_enter_suspend1(dev);
15313b9f7d8cSSteve Glendinning 			goto done;
1532e5e3af83SSteve Glendinning 		}
1533e5e3af83SSteve Glendinning 	}
1534e5e3af83SSteve Glendinning 
1535bbd9f9eeSSteve Glendinning 	if (pdata->wolopts & (WAKE_BCAST | WAKE_MCAST | WAKE_ARP | WAKE_UCAST)) {
15366396bb22SKees Cook 		u32 *filter_mask = kcalloc(32, sizeof(u32), GFP_KERNEL);
153706a221beSMing Lei 		u32 command[2];
153806a221beSMing Lei 		u32 offset[2];
153906a221beSMing Lei 		u32 crc[4];
15409ebca507SSteve Glendinning 		int wuff_filter_count =
15419ebca507SSteve Glendinning 			(pdata->features & FEATURE_8_WAKEUP_FILTERS) ?
15429ebca507SSteve Glendinning 			LAN9500A_WUFF_NUM : LAN9500_WUFF_NUM;
1543bbd9f9eeSSteve Glendinning 		int i, filter = 0;
1544bbd9f9eeSSteve Glendinning 
1545eed9a729SSteve Glendinning 		if (!filter_mask) {
1546eed9a729SSteve Glendinning 			netdev_warn(dev->net, "Unable to allocate filter_mask\n");
15473b9f7d8cSSteve Glendinning 			ret = -ENOMEM;
15483b9f7d8cSSteve Glendinning 			goto done;
1549eed9a729SSteve Glendinning 		}
1550eed9a729SSteve Glendinning 
155106a221beSMing Lei 		memset(command, 0, sizeof(command));
155206a221beSMing Lei 		memset(offset, 0, sizeof(offset));
155306a221beSMing Lei 		memset(crc, 0, sizeof(crc));
155406a221beSMing Lei 
1555bbd9f9eeSSteve Glendinning 		if (pdata->wolopts & WAKE_BCAST) {
1556bbd9f9eeSSteve Glendinning 			const u8 bcast[] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF};
15571e1d7412SJoe Perches 			netdev_info(dev->net, "enabling broadcast detection\n");
1558bbd9f9eeSSteve Glendinning 			filter_mask[filter * 4] = 0x003F;
1559bbd9f9eeSSteve Glendinning 			filter_mask[filter * 4 + 1] = 0x00;
1560bbd9f9eeSSteve Glendinning 			filter_mask[filter * 4 + 2] = 0x00;
1561bbd9f9eeSSteve Glendinning 			filter_mask[filter * 4 + 3] = 0x00;
1562bbd9f9eeSSteve Glendinning 			command[filter/4] |= 0x05UL << ((filter % 4) * 8);
1563bbd9f9eeSSteve Glendinning 			offset[filter/4] |= 0x00 << ((filter % 4) * 8);
1564bbd9f9eeSSteve Glendinning 			crc[filter/2] |= smsc_crc(bcast, 6, filter);
1565bbd9f9eeSSteve Glendinning 			filter++;
1566bbd9f9eeSSteve Glendinning 		}
1567bbd9f9eeSSteve Glendinning 
1568bbd9f9eeSSteve Glendinning 		if (pdata->wolopts & WAKE_MCAST) {
1569bbd9f9eeSSteve Glendinning 			const u8 mcast[] = {0x01, 0x00, 0x5E};
15701e1d7412SJoe Perches 			netdev_info(dev->net, "enabling multicast detection\n");
1571bbd9f9eeSSteve Glendinning 			filter_mask[filter * 4] = 0x0007;
1572bbd9f9eeSSteve Glendinning 			filter_mask[filter * 4 + 1] = 0x00;
1573bbd9f9eeSSteve Glendinning 			filter_mask[filter * 4 + 2] = 0x00;
1574bbd9f9eeSSteve Glendinning 			filter_mask[filter * 4 + 3] = 0x00;
1575bbd9f9eeSSteve Glendinning 			command[filter/4] |= 0x09UL << ((filter % 4) * 8);
1576bbd9f9eeSSteve Glendinning 			offset[filter/4] |= 0x00  << ((filter % 4) * 8);
1577bbd9f9eeSSteve Glendinning 			crc[filter/2] |= smsc_crc(mcast, 3, filter);
1578bbd9f9eeSSteve Glendinning 			filter++;
1579bbd9f9eeSSteve Glendinning 		}
1580bbd9f9eeSSteve Glendinning 
1581bbd9f9eeSSteve Glendinning 		if (pdata->wolopts & WAKE_ARP) {
1582bbd9f9eeSSteve Glendinning 			const u8 arp[] = {0x08, 0x06};
15831e1d7412SJoe Perches 			netdev_info(dev->net, "enabling ARP detection\n");
1584bbd9f9eeSSteve Glendinning 			filter_mask[filter * 4] = 0x0003;
1585bbd9f9eeSSteve Glendinning 			filter_mask[filter * 4 + 1] = 0x00;
1586bbd9f9eeSSteve Glendinning 			filter_mask[filter * 4 + 2] = 0x00;
1587bbd9f9eeSSteve Glendinning 			filter_mask[filter * 4 + 3] = 0x00;
1588bbd9f9eeSSteve Glendinning 			command[filter/4] |= 0x05UL << ((filter % 4) * 8);
1589bbd9f9eeSSteve Glendinning 			offset[filter/4] |= 0x0C << ((filter % 4) * 8);
1590bbd9f9eeSSteve Glendinning 			crc[filter/2] |= smsc_crc(arp, 2, filter);
1591bbd9f9eeSSteve Glendinning 			filter++;
1592bbd9f9eeSSteve Glendinning 		}
1593bbd9f9eeSSteve Glendinning 
1594bbd9f9eeSSteve Glendinning 		if (pdata->wolopts & WAKE_UCAST) {
15951e1d7412SJoe Perches 			netdev_info(dev->net, "enabling unicast detection\n");
1596bbd9f9eeSSteve Glendinning 			filter_mask[filter * 4] = 0x003F;
1597bbd9f9eeSSteve Glendinning 			filter_mask[filter * 4 + 1] = 0x00;
1598bbd9f9eeSSteve Glendinning 			filter_mask[filter * 4 + 2] = 0x00;
1599bbd9f9eeSSteve Glendinning 			filter_mask[filter * 4 + 3] = 0x00;
1600bbd9f9eeSSteve Glendinning 			command[filter/4] |= 0x01UL << ((filter % 4) * 8);
1601bbd9f9eeSSteve Glendinning 			offset[filter/4] |= 0x00 << ((filter % 4) * 8);
1602bbd9f9eeSSteve Glendinning 			crc[filter/2] |= smsc_crc(dev->net->dev_addr, ETH_ALEN, filter);
1603bbd9f9eeSSteve Glendinning 			filter++;
1604bbd9f9eeSSteve Glendinning 		}
1605bbd9f9eeSSteve Glendinning 
16069ebca507SSteve Glendinning 		for (i = 0; i < (wuff_filter_count * 4); i++) {
1607ec32115dSMing Lei 			ret = smsc95xx_write_reg_nopm(dev, WUFF, filter_mask[i]);
1608b052e073SSteve Glendinning 			if (ret < 0) {
160906a221beSMing Lei 				kfree(filter_mask);
1610b052e073SSteve Glendinning 				goto done;
1611b052e073SSteve Glendinning 			}
1612bbd9f9eeSSteve Glendinning 		}
161306a221beSMing Lei 		kfree(filter_mask);
1614bbd9f9eeSSteve Glendinning 
16159ebca507SSteve Glendinning 		for (i = 0; i < (wuff_filter_count / 4); i++) {
1616ec32115dSMing Lei 			ret = smsc95xx_write_reg_nopm(dev, WUFF, command[i]);
1617e360a8b4SSteve Glendinning 			if (ret < 0)
1618b052e073SSteve Glendinning 				goto done;
1619b052e073SSteve Glendinning 		}
1620bbd9f9eeSSteve Glendinning 
16219ebca507SSteve Glendinning 		for (i = 0; i < (wuff_filter_count / 4); i++) {
1622ec32115dSMing Lei 			ret = smsc95xx_write_reg_nopm(dev, WUFF, offset[i]);
1623e360a8b4SSteve Glendinning 			if (ret < 0)
1624b052e073SSteve Glendinning 				goto done;
1625b052e073SSteve Glendinning 		}
1626bbd9f9eeSSteve Glendinning 
16279ebca507SSteve Glendinning 		for (i = 0; i < (wuff_filter_count / 2); i++) {
1628ec32115dSMing Lei 			ret = smsc95xx_write_reg_nopm(dev, WUFF, crc[i]);
1629e360a8b4SSteve Glendinning 			if (ret < 0)
1630b052e073SSteve Glendinning 				goto done;
1631b052e073SSteve Glendinning 		}
1632bbd9f9eeSSteve Glendinning 
1633bbd9f9eeSSteve Glendinning 		/* clear any pending pattern match packet status */
1634ec32115dSMing Lei 		ret = smsc95xx_read_reg_nopm(dev, WUCSR, &val);
1635e360a8b4SSteve Glendinning 		if (ret < 0)
1636b052e073SSteve Glendinning 			goto done;
1637bbd9f9eeSSteve Glendinning 
1638bbd9f9eeSSteve Glendinning 		val |= WUCSR_WUFR_;
1639bbd9f9eeSSteve Glendinning 
1640ec32115dSMing Lei 		ret = smsc95xx_write_reg_nopm(dev, WUCSR, val);
1641e360a8b4SSteve Glendinning 		if (ret < 0)
1642b052e073SSteve Glendinning 			goto done;
1643b052e073SSteve Glendinning 	}
1644bbd9f9eeSSteve Glendinning 
1645e0e474a8SSteve Glendinning 	if (pdata->wolopts & WAKE_MAGIC) {
1646e0e474a8SSteve Glendinning 		/* clear any pending magic packet status */
1647ec32115dSMing Lei 		ret = smsc95xx_read_reg_nopm(dev, WUCSR, &val);
1648e360a8b4SSteve Glendinning 		if (ret < 0)
1649b052e073SSteve Glendinning 			goto done;
1650e0e474a8SSteve Glendinning 
1651e0e474a8SSteve Glendinning 		val |= WUCSR_MPR_;
1652e0e474a8SSteve Glendinning 
1653ec32115dSMing Lei 		ret = smsc95xx_write_reg_nopm(dev, WUCSR, val);
1654e360a8b4SSteve Glendinning 		if (ret < 0)
1655b052e073SSteve Glendinning 			goto done;
1656b052e073SSteve Glendinning 	}
1657e0e474a8SSteve Glendinning 
1658bbd9f9eeSSteve Glendinning 	/* enable/disable wakeup sources */
1659ec32115dSMing Lei 	ret = smsc95xx_read_reg_nopm(dev, WUCSR, &val);
1660e360a8b4SSteve Glendinning 	if (ret < 0)
1661b052e073SSteve Glendinning 		goto done;
1662e0e474a8SSteve Glendinning 
1663bbd9f9eeSSteve Glendinning 	if (pdata->wolopts & (WAKE_BCAST | WAKE_MCAST | WAKE_ARP | WAKE_UCAST)) {
16641e1d7412SJoe Perches 		netdev_info(dev->net, "enabling pattern match wakeup\n");
1665bbd9f9eeSSteve Glendinning 		val |= WUCSR_WAKE_EN_;
1666bbd9f9eeSSteve Glendinning 	} else {
16671e1d7412SJoe Perches 		netdev_info(dev->net, "disabling pattern match wakeup\n");
1668bbd9f9eeSSteve Glendinning 		val &= ~WUCSR_WAKE_EN_;
1669bbd9f9eeSSteve Glendinning 	}
1670bbd9f9eeSSteve Glendinning 
1671e0e474a8SSteve Glendinning 	if (pdata->wolopts & WAKE_MAGIC) {
16721e1d7412SJoe Perches 		netdev_info(dev->net, "enabling magic packet wakeup\n");
1673e0e474a8SSteve Glendinning 		val |= WUCSR_MPEN_;
1674e0e474a8SSteve Glendinning 	} else {
16751e1d7412SJoe Perches 		netdev_info(dev->net, "disabling magic packet wakeup\n");
1676e0e474a8SSteve Glendinning 		val &= ~WUCSR_MPEN_;
1677e0e474a8SSteve Glendinning 	}
1678e0e474a8SSteve Glendinning 
1679ec32115dSMing Lei 	ret = smsc95xx_write_reg_nopm(dev, WUCSR, val);
1680e360a8b4SSteve Glendinning 	if (ret < 0)
1681b052e073SSteve Glendinning 		goto done;
1682e0e474a8SSteve Glendinning 
1683e0e474a8SSteve Glendinning 	/* enable wol wakeup source */
1684ec32115dSMing Lei 	ret = smsc95xx_read_reg_nopm(dev, PM_CTRL, &val);
1685e360a8b4SSteve Glendinning 	if (ret < 0)
1686b052e073SSteve Glendinning 		goto done;
1687e0e474a8SSteve Glendinning 
1688e0e474a8SSteve Glendinning 	val |= PM_CTL_WOL_EN_;
1689e0e474a8SSteve Glendinning 
1690e5e3af83SSteve Glendinning 	/* phy energy detect wakeup source */
1691e5e3af83SSteve Glendinning 	if (pdata->wolopts & WAKE_PHY)
1692e5e3af83SSteve Glendinning 		val |= PM_CTL_ED_EN_;
1693e5e3af83SSteve Glendinning 
1694ec32115dSMing Lei 	ret = smsc95xx_write_reg_nopm(dev, PM_CTRL, val);
1695e360a8b4SSteve Glendinning 	if (ret < 0)
1696b052e073SSteve Glendinning 		goto done;
1697e0e474a8SSteve Glendinning 
1698bbd9f9eeSSteve Glendinning 	/* enable receiver to enable frame reception */
1699ec32115dSMing Lei 	smsc95xx_start_rx_path(dev, 1);
1700e0e474a8SSteve Glendinning 
1701e0e474a8SSteve Glendinning 	/* some wol options are enabled, so enter SUSPEND0 */
17021e1d7412SJoe Perches 	netdev_info(dev->net, "entering SUSPEND0 mode\n");
17033b9f7d8cSSteve Glendinning 	ret = smsc95xx_enter_suspend0(dev);
17043b9f7d8cSSteve Glendinning 
17053b9f7d8cSSteve Glendinning done:
17060d41be53SMing Lei 	/*
17070d41be53SMing Lei 	 * TODO: resume() might need to handle the suspend failure
17080d41be53SMing Lei 	 * in system sleep
17090d41be53SMing Lei 	 */
17100d41be53SMing Lei 	if (ret && PMSG_IS_AUTO(message))
17113b9f7d8cSSteve Glendinning 		usbnet_resume(intf);
17127b900eadSFrieder Schrempf 
17133b9f7d8cSSteve Glendinning 	return ret;
1714e0e474a8SSteve Glendinning }
1715e0e474a8SSteve Glendinning 
1716e0e474a8SSteve Glendinning static int smsc95xx_resume(struct usb_interface *intf)
1717e0e474a8SSteve Glendinning {
1718e0e474a8SSteve Glendinning 	struct usbnet *dev = usb_get_intfdata(intf);
17198bca81d9SSudip Mukherjee 	struct smsc95xx_priv *pdata;
17208bca81d9SSudip Mukherjee 	u8 suspend_flags;
1721e0e474a8SSteve Glendinning 	int ret;
1722e0e474a8SSteve Glendinning 	u32 val;
1723e0e474a8SSteve Glendinning 
1724e0e474a8SSteve Glendinning 	BUG_ON(!dev);
1725ad90a73fSAndre Edich 	pdata = dev->driver_priv;
17268bca81d9SSudip Mukherjee 	suspend_flags = pdata->suspend_flags;
1727e0e474a8SSteve Glendinning 
1728b2d4b150SSteve Glendinning 	netdev_dbg(dev->net, "resume suspend_flags=0x%02x\n", suspend_flags);
1729b2d4b150SSteve Glendinning 
1730b2d4b150SSteve Glendinning 	/* do this first to ensure it's cleared even in error case */
1731b2d4b150SSteve Glendinning 	pdata->suspend_flags = 0;
1732b2d4b150SSteve Glendinning 
1733b2d4b150SSteve Glendinning 	if (suspend_flags & SUSPEND_ALLMODES) {
1734bbd9f9eeSSteve Glendinning 		/* clear wake-up sources */
1735ec32115dSMing Lei 		ret = smsc95xx_read_reg_nopm(dev, WUCSR, &val);
1736e360a8b4SSteve Glendinning 		if (ret < 0)
1737b052e073SSteve Glendinning 			return ret;
1738e0e474a8SSteve Glendinning 
1739bbd9f9eeSSteve Glendinning 		val &= ~(WUCSR_WAKE_EN_ | WUCSR_MPEN_);
1740e0e474a8SSteve Glendinning 
1741ec32115dSMing Lei 		ret = smsc95xx_write_reg_nopm(dev, WUCSR, val);
1742e360a8b4SSteve Glendinning 		if (ret < 0)
1743b052e073SSteve Glendinning 			return ret;
1744e0e474a8SSteve Glendinning 
1745e0e474a8SSteve Glendinning 		/* clear wake-up status */
1746ec32115dSMing Lei 		ret = smsc95xx_read_reg_nopm(dev, PM_CTRL, &val);
1747e360a8b4SSteve Glendinning 		if (ret < 0)
1748b052e073SSteve Glendinning 			return ret;
1749e0e474a8SSteve Glendinning 
1750e0e474a8SSteve Glendinning 		val &= ~PM_CTL_WOL_EN_;
1751e0e474a8SSteve Glendinning 		val |= PM_CTL_WUPS_;
1752e0e474a8SSteve Glendinning 
1753ec32115dSMing Lei 		ret = smsc95xx_write_reg_nopm(dev, PM_CTRL, val);
1754e360a8b4SSteve Glendinning 		if (ret < 0)
1755b052e073SSteve Glendinning 			return ret;
1756b052e073SSteve Glendinning 	}
1757e0e474a8SSteve Glendinning 
1758af3d7c1eSSteve Glendinning 	ret = usbnet_resume(intf);
1759b052e073SSteve Glendinning 	if (ret < 0)
1760b052e073SSteve Glendinning 		netdev_warn(dev->net, "usbnet_resume error\n");
1761e0e474a8SSteve Glendinning 
176205b35e7eSAndre Edich 	phy_init_hw(pdata->phydev);
1763b052e073SSteve Glendinning 	return ret;
1764e0e474a8SSteve Glendinning }
1765e0e474a8SSteve Glendinning 
1766b4df480fSJoonyoung Shim static int smsc95xx_reset_resume(struct usb_interface *intf)
1767b4df480fSJoonyoung Shim {
1768b4df480fSJoonyoung Shim 	struct usbnet *dev = usb_get_intfdata(intf);
1769b4df480fSJoonyoung Shim 	int ret;
1770b4df480fSJoonyoung Shim 
1771b4df480fSJoonyoung Shim 	ret = smsc95xx_reset(dev);
1772b4df480fSJoonyoung Shim 	if (ret < 0)
1773b4df480fSJoonyoung Shim 		return ret;
1774b4df480fSJoonyoung Shim 
1775b4df480fSJoonyoung Shim 	return smsc95xx_resume(intf);
1776b4df480fSJoonyoung Shim }
1777b4df480fSJoonyoung Shim 
17782f7ca802SSteve Glendinning static void smsc95xx_rx_csum_offload(struct sk_buff *skb)
17792f7ca802SSteve Glendinning {
17802f7ca802SSteve Glendinning 	skb->csum = *(u16 *)(skb_tail_pointer(skb) - 2);
17812f7ca802SSteve Glendinning 	skb->ip_summed = CHECKSUM_COMPLETE;
17822f7ca802SSteve Glendinning 	skb_trim(skb, skb->len - 2);
17832f7ca802SSteve Glendinning }
17842f7ca802SSteve Glendinning 
17852f7ca802SSteve Glendinning static int smsc95xx_rx_fixup(struct usbnet *dev, struct sk_buff *skb)
17862f7ca802SSteve Glendinning {
1787eb85569fSEmil Goode 	/* This check is no longer done by usbnet */
1788eb85569fSEmil Goode 	if (skb->len < dev->net->hard_header_len)
1789eb85569fSEmil Goode 		return 0;
1790eb85569fSEmil Goode 
17912f7ca802SSteve Glendinning 	while (skb->len > 0) {
17922f7ca802SSteve Glendinning 		u32 header, align_count;
17932f7ca802SSteve Glendinning 		struct sk_buff *ax_skb;
17942f7ca802SSteve Glendinning 		unsigned char *packet;
17952f7ca802SSteve Glendinning 		u16 size;
17962f7ca802SSteve Glendinning 
17976809d216SBen Dooks 		header = get_unaligned_le32(skb->data);
17982f7ca802SSteve Glendinning 		skb_pull(skb, 4 + NET_IP_ALIGN);
17992f7ca802SSteve Glendinning 		packet = skb->data;
18002f7ca802SSteve Glendinning 
18012f7ca802SSteve Glendinning 		/* get the packet length */
18022f7ca802SSteve Glendinning 		size = (u16)((header & RX_STS_FL_) >> 16);
18032f7ca802SSteve Glendinning 		align_count = (4 - ((size + NET_IP_ALIGN) % 4)) % 4;
18042f7ca802SSteve Glendinning 
18052f7ca802SSteve Glendinning 		if (unlikely(header & RX_STS_ES_)) {
1806a475f603SJoe Perches 			netif_dbg(dev, rx_err, dev->net,
1807a475f603SJoe Perches 				  "Error header=0x%08x\n", header);
180880667ac1SHerbert Xu 			dev->net->stats.rx_errors++;
180980667ac1SHerbert Xu 			dev->net->stats.rx_dropped++;
18102f7ca802SSteve Glendinning 
18112f7ca802SSteve Glendinning 			if (header & RX_STS_CRC_) {
181280667ac1SHerbert Xu 				dev->net->stats.rx_crc_errors++;
18132f7ca802SSteve Glendinning 			} else {
18142f7ca802SSteve Glendinning 				if (header & (RX_STS_TL_ | RX_STS_RF_))
181580667ac1SHerbert Xu 					dev->net->stats.rx_frame_errors++;
18162f7ca802SSteve Glendinning 
18172f7ca802SSteve Glendinning 				if ((header & RX_STS_LE_) &&
18182f7ca802SSteve Glendinning 					(!(header & RX_STS_FT_)))
181980667ac1SHerbert Xu 					dev->net->stats.rx_length_errors++;
18202f7ca802SSteve Glendinning 			}
18212f7ca802SSteve Glendinning 		} else {
18222f7ca802SSteve Glendinning 			/* ETH_FRAME_LEN + 4(CRC) + 2(COE) + 4(Vlan) */
18232f7ca802SSteve Glendinning 			if (unlikely(size > (ETH_FRAME_LEN + 12))) {
1824a475f603SJoe Perches 				netif_dbg(dev, rx_err, dev->net,
1825a475f603SJoe Perches 					  "size err header=0x%08x\n", header);
18262f7ca802SSteve Glendinning 				return 0;
18272f7ca802SSteve Glendinning 			}
18282f7ca802SSteve Glendinning 
18292f7ca802SSteve Glendinning 			/* last frame in this batch */
18302f7ca802SSteve Glendinning 			if (skb->len == size) {
183178e47fe4SMichał Mirosław 				if (dev->net->features & NETIF_F_RXCSUM)
18322f7ca802SSteve Glendinning 					smsc95xx_rx_csum_offload(skb);
1833df18accaSPeter Korsgaard 				skb_trim(skb, skb->len - 4); /* remove fcs */
18342f7ca802SSteve Glendinning 				skb->truesize = size + sizeof(struct sk_buff);
18352f7ca802SSteve Glendinning 
18362f7ca802SSteve Glendinning 				return 1;
18372f7ca802SSteve Glendinning 			}
18382f7ca802SSteve Glendinning 
18392f7ca802SSteve Glendinning 			ax_skb = skb_clone(skb, GFP_ATOMIC);
18402f7ca802SSteve Glendinning 			if (unlikely(!ax_skb)) {
184160b86755SJoe Perches 				netdev_warn(dev->net, "Error allocating skb\n");
18422f7ca802SSteve Glendinning 				return 0;
18432f7ca802SSteve Glendinning 			}
18442f7ca802SSteve Glendinning 
18452f7ca802SSteve Glendinning 			ax_skb->len = size;
18462f7ca802SSteve Glendinning 			ax_skb->data = packet;
18472f7ca802SSteve Glendinning 			skb_set_tail_pointer(ax_skb, size);
18482f7ca802SSteve Glendinning 
184978e47fe4SMichał Mirosław 			if (dev->net->features & NETIF_F_RXCSUM)
18502f7ca802SSteve Glendinning 				smsc95xx_rx_csum_offload(ax_skb);
1851df18accaSPeter Korsgaard 			skb_trim(ax_skb, ax_skb->len - 4); /* remove fcs */
18522f7ca802SSteve Glendinning 			ax_skb->truesize = size + sizeof(struct sk_buff);
18532f7ca802SSteve Glendinning 
18542f7ca802SSteve Glendinning 			usbnet_skb_return(dev, ax_skb);
18552f7ca802SSteve Glendinning 		}
18562f7ca802SSteve Glendinning 
18572f7ca802SSteve Glendinning 		skb_pull(skb, size);
18582f7ca802SSteve Glendinning 
18592f7ca802SSteve Glendinning 		/* padding bytes before the next frame starts */
18602f7ca802SSteve Glendinning 		if (skb->len)
18612f7ca802SSteve Glendinning 			skb_pull(skb, align_count);
18622f7ca802SSteve Glendinning 	}
18632f7ca802SSteve Glendinning 
18642f7ca802SSteve Glendinning 	return 1;
18652f7ca802SSteve Glendinning }
18662f7ca802SSteve Glendinning 
1867f7b29271SSteve Glendinning static u32 smsc95xx_calc_csum_preamble(struct sk_buff *skb)
1868f7b29271SSteve Glendinning {
186955508d60SMichał Mirosław 	u16 low_16 = (u16)skb_checksum_start_offset(skb);
187055508d60SMichał Mirosław 	u16 high_16 = low_16 + skb->csum_offset;
1871f7b29271SSteve Glendinning 	return (high_16 << 16) | low_16;
1872f7b29271SSteve Glendinning }
1873f7b29271SSteve Glendinning 
187475938f77SBen Dooks /* The TX CSUM won't work if the checksum lies in the last 4 bytes of the
187575938f77SBen Dooks  * transmission. This is fairly unlikely, only seems to trigger with some
187675938f77SBen Dooks  * short TCP ACK packets sent.
187775938f77SBen Dooks  *
187875938f77SBen Dooks  * Note, this calculation should probably check for the alignment of the
187975938f77SBen Dooks  * data as well, but a straight check for csum being in the last four bytes
188075938f77SBen Dooks  * of the packet should be ok for now.
188175938f77SBen Dooks  */
188275938f77SBen Dooks static bool smsc95xx_can_tx_checksum(struct sk_buff *skb)
188375938f77SBen Dooks {
188475938f77SBen Dooks        unsigned int len = skb->len - skb_checksum_start_offset(skb);
188575938f77SBen Dooks 
188675938f77SBen Dooks        if (skb->len <= 45)
188775938f77SBen Dooks 	       return false;
188875938f77SBen Dooks        return skb->csum_offset < (len - (4 + 1));
188975938f77SBen Dooks }
189075938f77SBen Dooks 
18912f7ca802SSteve Glendinning static struct sk_buff *smsc95xx_tx_fixup(struct usbnet *dev,
18922f7ca802SSteve Glendinning 					 struct sk_buff *skb, gfp_t flags)
18932f7ca802SSteve Glendinning {
189478e47fe4SMichał Mirosław 	bool csum = skb->ip_summed == CHECKSUM_PARTIAL;
1895f7b29271SSteve Glendinning 	int overhead = csum ? SMSC95XX_TX_OVERHEAD_CSUM : SMSC95XX_TX_OVERHEAD;
18962f7ca802SSteve Glendinning 	u32 tx_cmd_a, tx_cmd_b;
18970c8b2655SBen Dooks 	void *ptr;
18982f7ca802SSteve Glendinning 
1899f7b29271SSteve Glendinning 	/* We do not advertise SG, so skbs should be already linearized */
1900f7b29271SSteve Glendinning 	BUG_ON(skb_shinfo(skb)->nr_frags);
1901f7b29271SSteve Glendinning 
1902e9156cd2SJames Hughes 	/* Make writable and expand header space by overhead if required */
1903e9156cd2SJames Hughes 	if (skb_cow_head(skb, overhead)) {
1904e9156cd2SJames Hughes 		/* Must deallocate here as returning NULL to indicate error
1905e9156cd2SJames Hughes 		 * means the skb won't be deallocated in the caller.
1906e9156cd2SJames Hughes 		 */
19072f7ca802SSteve Glendinning 		dev_kfree_skb_any(skb);
19082f7ca802SSteve Glendinning 		return NULL;
19092f7ca802SSteve Glendinning 	}
19102f7ca802SSteve Glendinning 
19110c8b2655SBen Dooks 	tx_cmd_b = (u32)skb->len;
19120c8b2655SBen Dooks 	tx_cmd_a = tx_cmd_b | TX_CMD_A_FIRST_SEG_ | TX_CMD_A_LAST_SEG_;
19130c8b2655SBen Dooks 
1914f7b29271SSteve Glendinning 	if (csum) {
191575938f77SBen Dooks 		if (!smsc95xx_can_tx_checksum(skb)) {
191611bc3088SSteve Glendinning 			/* workaround - hardware tx checksum does not work
191711bc3088SSteve Glendinning 			 * properly with extremely small packets */
191855508d60SMichał Mirosław 			long csstart = skb_checksum_start_offset(skb);
191911bc3088SSteve Glendinning 			__wsum calc = csum_partial(skb->data + csstart,
192011bc3088SSteve Glendinning 				skb->len - csstart, 0);
192111bc3088SSteve Glendinning 			*((__sum16 *)(skb->data + csstart
192211bc3088SSteve Glendinning 				+ skb->csum_offset)) = csum_fold(calc);
192311bc3088SSteve Glendinning 
192411bc3088SSteve Glendinning 			csum = false;
192511bc3088SSteve Glendinning 		} else {
1926f7b29271SSteve Glendinning 			u32 csum_preamble = smsc95xx_calc_csum_preamble(skb);
19270c8b2655SBen Dooks 			ptr = skb_push(skb, 4);
19280c8b2655SBen Dooks 			put_unaligned_le32(csum_preamble, ptr);
1929f7b29271SSteve Glendinning 
19300c8b2655SBen Dooks 			tx_cmd_a += 4;
19310c8b2655SBen Dooks 			tx_cmd_b += 4;
1932f7b29271SSteve Glendinning 			tx_cmd_b |= TX_CMD_B_CSUM_ENABLE;
19330c8b2655SBen Dooks 		}
19340c8b2655SBen Dooks 	}
19352f7ca802SSteve Glendinning 
19360c8b2655SBen Dooks 	ptr = skb_push(skb, 8);
19370c8b2655SBen Dooks 	put_unaligned_le32(tx_cmd_a, ptr);
19380c8b2655SBen Dooks 	put_unaligned_le32(tx_cmd_b, ptr+4);
19392f7ca802SSteve Glendinning 
19402f7ca802SSteve Glendinning 	return skb;
19412f7ca802SSteve Glendinning }
19422f7ca802SSteve Glendinning 
1943b2d4b150SSteve Glendinning static int smsc95xx_manage_power(struct usbnet *dev, int on)
1944b2d4b150SSteve Glendinning {
1945ad90a73fSAndre Edich 	struct smsc95xx_priv *pdata = dev->driver_priv;
1946b2d4b150SSteve Glendinning 
1947b2d4b150SSteve Glendinning 	dev->intf->needs_remote_wakeup = on;
1948b2d4b150SSteve Glendinning 
1949eb970ff0SMing Lei 	if (pdata->features & FEATURE_REMOTE_WAKEUP)
1950b2d4b150SSteve Glendinning 		return 0;
1951b2d4b150SSteve Glendinning 
1952eb970ff0SMing Lei 	/* this chip revision isn't capable of remote wakeup */
1953eb970ff0SMing Lei 	netdev_info(dev->net, "hardware isn't capable of remote wakeup\n");
1954b2d4b150SSteve Glendinning 
1955b2d4b150SSteve Glendinning 	if (on)
1956b2d4b150SSteve Glendinning 		usb_autopm_get_interface_no_resume(dev->intf);
1957b2d4b150SSteve Glendinning 	else
1958b2d4b150SSteve Glendinning 		usb_autopm_put_interface(dev->intf);
1959b2d4b150SSteve Glendinning 
1960b2d4b150SSteve Glendinning 	return 0;
1961b2d4b150SSteve Glendinning }
1962b2d4b150SSteve Glendinning 
19632f7ca802SSteve Glendinning static const struct driver_info smsc95xx_info = {
19642f7ca802SSteve Glendinning 	.description	= "smsc95xx USB 2.0 Ethernet",
19652f7ca802SSteve Glendinning 	.bind		= smsc95xx_bind,
19662f7ca802SSteve Glendinning 	.unbind		= smsc95xx_unbind,
19672f7ca802SSteve Glendinning 	.link_reset	= smsc95xx_link_reset,
196805b35e7eSAndre Edich 	.reset		= smsc95xx_start_phy,
196905b35e7eSAndre Edich 	.stop		= smsc95xx_disconnect_phy,
19702f7ca802SSteve Glendinning 	.rx_fixup	= smsc95xx_rx_fixup,
19712f7ca802SSteve Glendinning 	.tx_fixup	= smsc95xx_tx_fixup,
19722f7ca802SSteve Glendinning 	.status		= smsc95xx_status,
1973b2d4b150SSteve Glendinning 	.manage_power	= smsc95xx_manage_power,
197407d69d42SPaolo Pisati 	.flags		= FLAG_ETHER | FLAG_SEND_ZLP | FLAG_LINK_INTR,
19752f7ca802SSteve Glendinning };
19762f7ca802SSteve Glendinning 
19772f7ca802SSteve Glendinning static const struct usb_device_id products[] = {
19782f7ca802SSteve Glendinning 	{
19792f7ca802SSteve Glendinning 		/* SMSC9500 USB Ethernet Device */
19802f7ca802SSteve Glendinning 		USB_DEVICE(0x0424, 0x9500),
19812f7ca802SSteve Glendinning 		.driver_info = (unsigned long) &smsc95xx_info,
19822f7ca802SSteve Glendinning 	},
1983726474b8SSteve Glendinning 	{
19846f41d12bSSteve Glendinning 		/* SMSC9505 USB Ethernet Device */
19856f41d12bSSteve Glendinning 		USB_DEVICE(0x0424, 0x9505),
19866f41d12bSSteve Glendinning 		.driver_info = (unsigned long) &smsc95xx_info,
19876f41d12bSSteve Glendinning 	},
19886f41d12bSSteve Glendinning 	{
19896f41d12bSSteve Glendinning 		/* SMSC9500A USB Ethernet Device */
19906f41d12bSSteve Glendinning 		USB_DEVICE(0x0424, 0x9E00),
19916f41d12bSSteve Glendinning 		.driver_info = (unsigned long) &smsc95xx_info,
19926f41d12bSSteve Glendinning 	},
19936f41d12bSSteve Glendinning 	{
19946f41d12bSSteve Glendinning 		/* SMSC9505A USB Ethernet Device */
19956f41d12bSSteve Glendinning 		USB_DEVICE(0x0424, 0x9E01),
19966f41d12bSSteve Glendinning 		.driver_info = (unsigned long) &smsc95xx_info,
19976f41d12bSSteve Glendinning 	},
19986f41d12bSSteve Glendinning 	{
1999726474b8SSteve Glendinning 		/* SMSC9512/9514 USB Hub & Ethernet Device */
2000726474b8SSteve Glendinning 		USB_DEVICE(0x0424, 0xec00),
2001726474b8SSteve Glendinning 		.driver_info = (unsigned long) &smsc95xx_info,
2002726474b8SSteve Glendinning 	},
20036f41d12bSSteve Glendinning 	{
20046f41d12bSSteve Glendinning 		/* SMSC9500 USB Ethernet Device (SAL10) */
20056f41d12bSSteve Glendinning 		USB_DEVICE(0x0424, 0x9900),
20066f41d12bSSteve Glendinning 		.driver_info = (unsigned long) &smsc95xx_info,
20076f41d12bSSteve Glendinning 	},
20086f41d12bSSteve Glendinning 	{
20096f41d12bSSteve Glendinning 		/* SMSC9505 USB Ethernet Device (SAL10) */
20106f41d12bSSteve Glendinning 		USB_DEVICE(0x0424, 0x9901),
20116f41d12bSSteve Glendinning 		.driver_info = (unsigned long) &smsc95xx_info,
20126f41d12bSSteve Glendinning 	},
20136f41d12bSSteve Glendinning 	{
20146f41d12bSSteve Glendinning 		/* SMSC9500A USB Ethernet Device (SAL10) */
20156f41d12bSSteve Glendinning 		USB_DEVICE(0x0424, 0x9902),
20166f41d12bSSteve Glendinning 		.driver_info = (unsigned long) &smsc95xx_info,
20176f41d12bSSteve Glendinning 	},
20186f41d12bSSteve Glendinning 	{
20196f41d12bSSteve Glendinning 		/* SMSC9505A USB Ethernet Device (SAL10) */
20206f41d12bSSteve Glendinning 		USB_DEVICE(0x0424, 0x9903),
20216f41d12bSSteve Glendinning 		.driver_info = (unsigned long) &smsc95xx_info,
20226f41d12bSSteve Glendinning 	},
20236f41d12bSSteve Glendinning 	{
20246f41d12bSSteve Glendinning 		/* SMSC9512/9514 USB Hub & Ethernet Device (SAL10) */
20256f41d12bSSteve Glendinning 		USB_DEVICE(0x0424, 0x9904),
20266f41d12bSSteve Glendinning 		.driver_info = (unsigned long) &smsc95xx_info,
20276f41d12bSSteve Glendinning 	},
20286f41d12bSSteve Glendinning 	{
20296f41d12bSSteve Glendinning 		/* SMSC9500A USB Ethernet Device (HAL) */
20306f41d12bSSteve Glendinning 		USB_DEVICE(0x0424, 0x9905),
20316f41d12bSSteve Glendinning 		.driver_info = (unsigned long) &smsc95xx_info,
20326f41d12bSSteve Glendinning 	},
20336f41d12bSSteve Glendinning 	{
20346f41d12bSSteve Glendinning 		/* SMSC9505A USB Ethernet Device (HAL) */
20356f41d12bSSteve Glendinning 		USB_DEVICE(0x0424, 0x9906),
20366f41d12bSSteve Glendinning 		.driver_info = (unsigned long) &smsc95xx_info,
20376f41d12bSSteve Glendinning 	},
20386f41d12bSSteve Glendinning 	{
20396f41d12bSSteve Glendinning 		/* SMSC9500 USB Ethernet Device (Alternate ID) */
20406f41d12bSSteve Glendinning 		USB_DEVICE(0x0424, 0x9907),
20416f41d12bSSteve Glendinning 		.driver_info = (unsigned long) &smsc95xx_info,
20426f41d12bSSteve Glendinning 	},
20436f41d12bSSteve Glendinning 	{
20446f41d12bSSteve Glendinning 		/* SMSC9500A USB Ethernet Device (Alternate ID) */
20456f41d12bSSteve Glendinning 		USB_DEVICE(0x0424, 0x9908),
20466f41d12bSSteve Glendinning 		.driver_info = (unsigned long) &smsc95xx_info,
20476f41d12bSSteve Glendinning 	},
20486f41d12bSSteve Glendinning 	{
20496f41d12bSSteve Glendinning 		/* SMSC9512/9514 USB Hub & Ethernet Device (Alternate ID) */
20506f41d12bSSteve Glendinning 		USB_DEVICE(0x0424, 0x9909),
20516f41d12bSSteve Glendinning 		.driver_info = (unsigned long) &smsc95xx_info,
20526f41d12bSSteve Glendinning 	},
205388edaa41SSteve Glendinning 	{
205488edaa41SSteve Glendinning 		/* SMSC LAN9530 USB Ethernet Device */
205588edaa41SSteve Glendinning 		USB_DEVICE(0x0424, 0x9530),
205688edaa41SSteve Glendinning 		.driver_info = (unsigned long) &smsc95xx_info,
205788edaa41SSteve Glendinning 	},
205888edaa41SSteve Glendinning 	{
205988edaa41SSteve Glendinning 		/* SMSC LAN9730 USB Ethernet Device */
206088edaa41SSteve Glendinning 		USB_DEVICE(0x0424, 0x9730),
206188edaa41SSteve Glendinning 		.driver_info = (unsigned long) &smsc95xx_info,
206288edaa41SSteve Glendinning 	},
206388edaa41SSteve Glendinning 	{
206488edaa41SSteve Glendinning 		/* SMSC LAN89530 USB Ethernet Device */
206588edaa41SSteve Glendinning 		USB_DEVICE(0x0424, 0x9E08),
206688edaa41SSteve Glendinning 		.driver_info = (unsigned long) &smsc95xx_info,
206788edaa41SSteve Glendinning 	},
20682f7ca802SSteve Glendinning 	{ },		/* END */
20692f7ca802SSteve Glendinning };
20702f7ca802SSteve Glendinning MODULE_DEVICE_TABLE(usb, products);
20712f7ca802SSteve Glendinning 
20722f7ca802SSteve Glendinning static struct usb_driver smsc95xx_driver = {
20732f7ca802SSteve Glendinning 	.name		= "smsc95xx",
20742f7ca802SSteve Glendinning 	.id_table	= products,
20752f7ca802SSteve Glendinning 	.probe		= usbnet_probe,
2076b5a04475SSteve Glendinning 	.suspend	= smsc95xx_suspend,
2077e0e474a8SSteve Glendinning 	.resume		= smsc95xx_resume,
2078b4df480fSJoonyoung Shim 	.reset_resume	= smsc95xx_reset_resume,
20792f7ca802SSteve Glendinning 	.disconnect	= usbnet_disconnect,
2080e1f12eb6SSarah Sharp 	.disable_hub_initiated_lpm = 1,
2081b2d4b150SSteve Glendinning 	.supports_autosuspend = 1,
20822f7ca802SSteve Glendinning };
20832f7ca802SSteve Glendinning 
2084d632eb1bSGreg Kroah-Hartman module_usb_driver(smsc95xx_driver);
20852f7ca802SSteve Glendinning 
20862f7ca802SSteve Glendinning MODULE_AUTHOR("Nancy Lin");
208790b24cfbSSteve Glendinning MODULE_AUTHOR("Steve Glendinning <steve.glendinning@shawell.net>");
20882f7ca802SSteve Glendinning MODULE_DESCRIPTION("SMSC95XX USB 2.0 Ethernet Devices");
20892f7ca802SSteve Glendinning MODULE_LICENSE("GPL");
2090