xref: /openbmc/linux/drivers/net/usb/smsc95xx.c (revision 4066bf4ce3ae3e322fa0c3c6418e45d99ff086b8)
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>
211ce8b372SLukas Wunner #include <linux/irq.h>
221ce8b372SLukas Wunner #include <linux/irqdomain.h>
2305b35e7eSAndre Edich #include <linux/mdio.h>
2405b35e7eSAndre Edich #include <linux/phy.h>
251710b52dSOleksij Rempel #include <net/selftests.h>
261710b52dSOleksij Rempel 
272f7ca802SSteve Glendinning #include "smsc95xx.h"
282f7ca802SSteve Glendinning 
292f7ca802SSteve Glendinning #define SMSC_CHIPNAME			"smsc95xx"
3005b35e7eSAndre Edich #define SMSC_DRIVER_VERSION		"2.0.0"
312f7ca802SSteve Glendinning #define HS_USB_PKT_SIZE			(512)
322f7ca802SSteve Glendinning #define FS_USB_PKT_SIZE			(64)
332f7ca802SSteve Glendinning #define DEFAULT_HS_BURST_CAP_SIZE	(16 * 1024 + 5 * HS_USB_PKT_SIZE)
342f7ca802SSteve Glendinning #define DEFAULT_FS_BURST_CAP_SIZE	(6 * 1024 + 33 * FS_USB_PKT_SIZE)
352f7ca802SSteve Glendinning #define DEFAULT_BULK_IN_DELAY		(0x00002000)
362f7ca802SSteve Glendinning #define MAX_SINGLE_PACKET_SIZE		(2048)
372f7ca802SSteve Glendinning #define LAN95XX_EEPROM_MAGIC		(0x9500)
382f7ca802SSteve Glendinning #define EEPROM_MAC_OFFSET		(0x01)
39f7b29271SSteve Glendinning #define DEFAULT_TX_CSUM_ENABLE		(true)
402f7ca802SSteve Glendinning #define DEFAULT_RX_CSUM_ENABLE		(true)
412f7ca802SSteve Glendinning #define SMSC95XX_INTERNAL_PHY_ID	(1)
422f7ca802SSteve Glendinning #define SMSC95XX_TX_OVERHEAD		(8)
43f7b29271SSteve Glendinning #define SMSC95XX_TX_OVERHEAD_CSUM	(12)
44e5e3af83SSteve Glendinning #define SUPPORTED_WAKE			(WAKE_PHY | WAKE_UCAST | WAKE_BCAST | \
45bbd9f9eeSSteve Glendinning 					 WAKE_MCAST | WAKE_ARP | WAKE_MAGIC)
462f7ca802SSteve Glendinning 
479ebca507SSteve Glendinning #define FEATURE_8_WAKEUP_FILTERS	(0x01)
489ebca507SSteve Glendinning #define FEATURE_PHY_NLP_CROSSOVER	(0x02)
49eb970ff0SMing Lei #define FEATURE_REMOTE_WAKEUP		(0x04)
509ebca507SSteve Glendinning 
51b2d4b150SSteve Glendinning #define SUSPEND_SUSPEND0		(0x01)
52b2d4b150SSteve Glendinning #define SUSPEND_SUSPEND1		(0x02)
53b2d4b150SSteve Glendinning #define SUSPEND_SUSPEND2		(0x04)
54b2d4b150SSteve Glendinning #define SUSPEND_SUSPEND3		(0x08)
55b2d4b150SSteve Glendinning #define SUSPEND_ALLMODES		(SUSPEND_SUSPEND0 | SUSPEND_SUSPEND1 | \
56b2d4b150SSteve Glendinning 					 SUSPEND_SUSPEND2 | SUSPEND_SUSPEND3)
57b2d4b150SSteve Glendinning 
581ce8b372SLukas Wunner #define SMSC95XX_NR_IRQS		(1) /* raise to 12 for GPIOs */
591ce8b372SLukas Wunner #define PHY_HWIRQ			(SMSC95XX_NR_IRQS - 1)
601ce8b372SLukas Wunner 
612f7ca802SSteve Glendinning struct smsc95xx_priv {
622f7ca802SSteve Glendinning 	u32 mac_cr;
633c0f3c60SMarc Zyngier 	u32 hash_hi;
643c0f3c60SMarc Zyngier 	u32 hash_lo;
65e0e474a8SSteve Glendinning 	u32 wolopts;
662f7ca802SSteve Glendinning 	spinlock_t mac_cr_lock;
679ebca507SSteve Glendinning 	u8 features;
68b2d4b150SSteve Glendinning 	u8 suspend_flags;
691ce8b372SLukas Wunner 	struct irq_chip irqchip;
701ce8b372SLukas Wunner 	struct irq_domain *irqdomain;
711ce8b372SLukas Wunner 	struct fwnode_handle *irqfwnode;
7205b35e7eSAndre Edich 	struct mii_bus *mdiobus;
7305b35e7eSAndre Edich 	struct phy_device *phydev;
742f7ca802SSteve Glendinning };
752f7ca802SSteve Glendinning 
76eb939922SRusty Russell static bool turbo_mode = true;
772f7ca802SSteve Glendinning module_param(turbo_mode, bool, 0644);
782f7ca802SSteve Glendinning MODULE_PARM_DESC(turbo_mode, "Enable multiple frames per Rx transaction");
792f7ca802SSteve Glendinning 
80ec32115dSMing Lei static int __must_check __smsc95xx_read_reg(struct usbnet *dev, u32 index,
81ec32115dSMing Lei 					    u32 *data, int in_pm)
822f7ca802SSteve Glendinning {
8372108fd2SMing Lei 	u32 buf;
842f7ca802SSteve Glendinning 	int ret;
85ec32115dSMing Lei 	int (*fn)(struct usbnet *, u8, u8, u16, u16, void *, u16);
862f7ca802SSteve Glendinning 
872f7ca802SSteve Glendinning 	BUG_ON(!dev);
882f7ca802SSteve Glendinning 
89ec32115dSMing Lei 	if (!in_pm)
90ec32115dSMing Lei 		fn = usbnet_read_cmd;
91ec32115dSMing Lei 	else
92ec32115dSMing Lei 		fn = usbnet_read_cmd_nopm;
93ec32115dSMing Lei 
94ec32115dSMing Lei 	ret = fn(dev, USB_VENDOR_REQUEST_READ_REGISTER, USB_DIR_IN
95ec32115dSMing Lei 		 | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
9672108fd2SMing Lei 		 0, index, &buf, 4);
97c70c453aSFabio Estevam 	if (ret < 0) {
98c70c453aSFabio Estevam 		if (ret != -ENODEV)
991e1d7412SJoe Perches 			netdev_warn(dev->net, "Failed to read reg index 0x%08x: %d\n",
1001e1d7412SJoe Perches 				    index, ret);
1015a36b68bSDan Carpenter 		return ret;
1025a36b68bSDan Carpenter 	}
1032f7ca802SSteve Glendinning 
10472108fd2SMing Lei 	le32_to_cpus(&buf);
10572108fd2SMing Lei 	*data = buf;
1062f7ca802SSteve Glendinning 
1072f7ca802SSteve Glendinning 	return ret;
1082f7ca802SSteve Glendinning }
1092f7ca802SSteve Glendinning 
110ec32115dSMing Lei static int __must_check __smsc95xx_write_reg(struct usbnet *dev, u32 index,
111ec32115dSMing Lei 					     u32 data, int in_pm)
1122f7ca802SSteve Glendinning {
11372108fd2SMing Lei 	u32 buf;
1142f7ca802SSteve Glendinning 	int ret;
115ec32115dSMing Lei 	int (*fn)(struct usbnet *, u8, u8, u16, u16, const void *, u16);
1162f7ca802SSteve Glendinning 
1172f7ca802SSteve Glendinning 	BUG_ON(!dev);
1182f7ca802SSteve Glendinning 
119ec32115dSMing Lei 	if (!in_pm)
120ec32115dSMing Lei 		fn = usbnet_write_cmd;
121ec32115dSMing Lei 	else
122ec32115dSMing Lei 		fn = usbnet_write_cmd_nopm;
123ec32115dSMing Lei 
12472108fd2SMing Lei 	buf = data;
12572108fd2SMing Lei 	cpu_to_le32s(&buf);
1262f7ca802SSteve Glendinning 
127ec32115dSMing Lei 	ret = fn(dev, USB_VENDOR_REQUEST_WRITE_REGISTER, USB_DIR_OUT
128ec32115dSMing Lei 		 | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
12972108fd2SMing Lei 		 0, index, &buf, 4);
130c70c453aSFabio Estevam 	if (ret < 0 && ret != -ENODEV)
1311e1d7412SJoe Perches 		netdev_warn(dev->net, "Failed to write reg index 0x%08x: %d\n",
1321e1d7412SJoe Perches 			    index, ret);
1332f7ca802SSteve Glendinning 
1342f7ca802SSteve Glendinning 	return ret;
1352f7ca802SSteve Glendinning }
1362f7ca802SSteve Glendinning 
137ec32115dSMing Lei static int __must_check smsc95xx_read_reg_nopm(struct usbnet *dev, u32 index,
138ec32115dSMing Lei 					       u32 *data)
139ec32115dSMing Lei {
140ec32115dSMing Lei 	return __smsc95xx_read_reg(dev, index, data, 1);
141ec32115dSMing Lei }
142ec32115dSMing Lei 
143ec32115dSMing Lei static int __must_check smsc95xx_write_reg_nopm(struct usbnet *dev, u32 index,
144ec32115dSMing Lei 						u32 data)
145ec32115dSMing Lei {
146ec32115dSMing Lei 	return __smsc95xx_write_reg(dev, index, data, 1);
147ec32115dSMing Lei }
148ec32115dSMing Lei 
149ec32115dSMing Lei static int __must_check smsc95xx_read_reg(struct usbnet *dev, u32 index,
150ec32115dSMing Lei 					  u32 *data)
151ec32115dSMing Lei {
152ec32115dSMing Lei 	return __smsc95xx_read_reg(dev, index, data, 0);
153ec32115dSMing Lei }
154ec32115dSMing Lei 
155ec32115dSMing Lei static int __must_check smsc95xx_write_reg(struct usbnet *dev, u32 index,
156ec32115dSMing Lei 					   u32 data)
157ec32115dSMing Lei {
158ec32115dSMing Lei 	return __smsc95xx_write_reg(dev, index, data, 0);
159ec32115dSMing Lei }
160e0e474a8SSteve Glendinning 
1612f7ca802SSteve Glendinning /* Loop until the read is completed with timeout
1622f7ca802SSteve Glendinning  * called with phy_mutex held */
163e5e3af83SSteve Glendinning static int __must_check __smsc95xx_phy_wait_not_busy(struct usbnet *dev,
164e5e3af83SSteve Glendinning 						     int in_pm)
1652f7ca802SSteve Glendinning {
1662f7ca802SSteve Glendinning 	unsigned long start_time = jiffies;
1672f7ca802SSteve Glendinning 	u32 val;
168769ea6d8SSteve Glendinning 	int ret;
1692f7ca802SSteve Glendinning 
1702f7ca802SSteve Glendinning 	do {
171e5e3af83SSteve Glendinning 		ret = __smsc95xx_read_reg(dev, MII_ADDR, &val, in_pm);
172b052e073SSteve Glendinning 		if (ret < 0) {
173c70c453aSFabio Estevam 			/* Ignore -ENODEV error during disconnect() */
174c70c453aSFabio Estevam 			if (ret == -ENODEV)
175c70c453aSFabio Estevam 				return 0;
176b052e073SSteve Glendinning 			netdev_warn(dev->net, "Error reading MII_ACCESS\n");
177b052e073SSteve Glendinning 			return ret;
178b052e073SSteve Glendinning 		}
179b052e073SSteve Glendinning 
1802f7ca802SSteve Glendinning 		if (!(val & MII_BUSY_))
1812f7ca802SSteve Glendinning 			return 0;
1822f7ca802SSteve Glendinning 	} while (!time_after(jiffies, start_time + HZ));
1832f7ca802SSteve Glendinning 
1842f7ca802SSteve Glendinning 	return -EIO;
1852f7ca802SSteve Glendinning }
1862f7ca802SSteve Glendinning 
18705b35e7eSAndre Edich static u32 mii_address_cmd(int phy_id, int idx, u16 op)
18805b35e7eSAndre Edich {
18905b35e7eSAndre Edich 	return (phy_id & 0x1f) << 11 | (idx & 0x1f) << 6 | op;
19005b35e7eSAndre Edich }
19105b35e7eSAndre Edich 
19205b35e7eSAndre Edich static int __smsc95xx_mdio_read(struct usbnet *dev, int phy_id, int idx,
193e5e3af83SSteve Glendinning 				int in_pm)
1942f7ca802SSteve Glendinning {
1952f7ca802SSteve Glendinning 	u32 val, addr;
196769ea6d8SSteve Glendinning 	int ret;
1972f7ca802SSteve Glendinning 
1982f7ca802SSteve Glendinning 	mutex_lock(&dev->phy_mutex);
1992f7ca802SSteve Glendinning 
2002f7ca802SSteve Glendinning 	/* confirm MII not busy */
201e5e3af83SSteve Glendinning 	ret = __smsc95xx_phy_wait_not_busy(dev, in_pm);
202b052e073SSteve Glendinning 	if (ret < 0) {
20305b35e7eSAndre Edich 		netdev_warn(dev->net, "%s: MII is busy\n", __func__);
204b052e073SSteve Glendinning 		goto done;
205b052e073SSteve Glendinning 	}
2062f7ca802SSteve Glendinning 
2072f7ca802SSteve Glendinning 	/* set the address, index & direction (read from PHY) */
20805b35e7eSAndre Edich 	addr = mii_address_cmd(phy_id, idx, MII_READ_ | MII_BUSY_);
209e5e3af83SSteve Glendinning 	ret = __smsc95xx_write_reg(dev, MII_ADDR, addr, in_pm);
210b052e073SSteve Glendinning 	if (ret < 0) {
211c70c453aSFabio Estevam 		if (ret != -ENODEV)
212b052e073SSteve Glendinning 			netdev_warn(dev->net, "Error writing MII_ADDR\n");
213b052e073SSteve Glendinning 		goto done;
214b052e073SSteve Glendinning 	}
2152f7ca802SSteve Glendinning 
216e5e3af83SSteve Glendinning 	ret = __smsc95xx_phy_wait_not_busy(dev, in_pm);
217b052e073SSteve Glendinning 	if (ret < 0) {
218b052e073SSteve Glendinning 		netdev_warn(dev->net, "Timed out reading MII reg %02X\n", idx);
219b052e073SSteve Glendinning 		goto done;
220b052e073SSteve Glendinning 	}
221769ea6d8SSteve Glendinning 
222e5e3af83SSteve Glendinning 	ret = __smsc95xx_read_reg(dev, MII_DATA, &val, in_pm);
223b052e073SSteve Glendinning 	if (ret < 0) {
224c70c453aSFabio Estevam 		if (ret != -ENODEV)
225b052e073SSteve Glendinning 			netdev_warn(dev->net, "Error reading MII_DATA\n");
226b052e073SSteve Glendinning 		goto done;
227b052e073SSteve Glendinning 	}
228769ea6d8SSteve Glendinning 
229769ea6d8SSteve Glendinning 	ret = (u16)(val & 0xFFFF);
230769ea6d8SSteve Glendinning 
231769ea6d8SSteve Glendinning done:
2322f7ca802SSteve Glendinning 	mutex_unlock(&dev->phy_mutex);
233c70c453aSFabio Estevam 
234c70c453aSFabio Estevam 	/* Ignore -ENODEV error during disconnect() */
235c70c453aSFabio Estevam 	if (ret == -ENODEV)
236c70c453aSFabio Estevam 		return 0;
237769ea6d8SSteve Glendinning 	return ret;
2382f7ca802SSteve Glendinning }
2392f7ca802SSteve Glendinning 
24005b35e7eSAndre Edich static void __smsc95xx_mdio_write(struct usbnet *dev, int phy_id,
241e5e3af83SSteve Glendinning 				  int idx, int regval, int in_pm)
2422f7ca802SSteve Glendinning {
2432f7ca802SSteve Glendinning 	u32 val, addr;
244769ea6d8SSteve Glendinning 	int ret;
2452f7ca802SSteve Glendinning 
2462f7ca802SSteve Glendinning 	mutex_lock(&dev->phy_mutex);
2472f7ca802SSteve Glendinning 
2482f7ca802SSteve Glendinning 	/* confirm MII not busy */
249e5e3af83SSteve Glendinning 	ret = __smsc95xx_phy_wait_not_busy(dev, in_pm);
250b052e073SSteve Glendinning 	if (ret < 0) {
25105b35e7eSAndre Edich 		netdev_warn(dev->net, "%s: MII is busy\n", __func__);
252b052e073SSteve Glendinning 		goto done;
253b052e073SSteve Glendinning 	}
2542f7ca802SSteve Glendinning 
2552f7ca802SSteve Glendinning 	val = regval;
256e5e3af83SSteve Glendinning 	ret = __smsc95xx_write_reg(dev, MII_DATA, val, in_pm);
257b052e073SSteve Glendinning 	if (ret < 0) {
258c70c453aSFabio Estevam 		if (ret != -ENODEV)
259b052e073SSteve Glendinning 			netdev_warn(dev->net, "Error writing MII_DATA\n");
260b052e073SSteve Glendinning 		goto done;
261b052e073SSteve Glendinning 	}
2622f7ca802SSteve Glendinning 
2632f7ca802SSteve Glendinning 	/* set the address, index & direction (write to PHY) */
26405b35e7eSAndre Edich 	addr = mii_address_cmd(phy_id, idx, MII_WRITE_ | MII_BUSY_);
265e5e3af83SSteve Glendinning 	ret = __smsc95xx_write_reg(dev, MII_ADDR, addr, in_pm);
266b052e073SSteve Glendinning 	if (ret < 0) {
267c70c453aSFabio Estevam 		if (ret != -ENODEV)
268b052e073SSteve Glendinning 			netdev_warn(dev->net, "Error writing MII_ADDR\n");
269b052e073SSteve Glendinning 		goto done;
270b052e073SSteve Glendinning 	}
2712f7ca802SSteve Glendinning 
272e5e3af83SSteve Glendinning 	ret = __smsc95xx_phy_wait_not_busy(dev, in_pm);
273b052e073SSteve Glendinning 	if (ret < 0) {
274b052e073SSteve Glendinning 		netdev_warn(dev->net, "Timed out writing MII reg %02X\n", idx);
275b052e073SSteve Glendinning 		goto done;
276b052e073SSteve Glendinning 	}
2772f7ca802SSteve Glendinning 
278769ea6d8SSteve Glendinning done:
2792f7ca802SSteve Glendinning 	mutex_unlock(&dev->phy_mutex);
2802f7ca802SSteve Glendinning }
2812f7ca802SSteve Glendinning 
282368be1caSAndre Edich static int smsc95xx_mdio_read_nopm(struct usbnet *dev, int idx)
283e5e3af83SSteve Glendinning {
28405b35e7eSAndre Edich 	struct smsc95xx_priv *pdata = dev->driver_priv;
285368be1caSAndre Edich 
28605b35e7eSAndre Edich 	return __smsc95xx_mdio_read(dev, pdata->phydev->mdio.addr, idx, 1);
287e5e3af83SSteve Glendinning }
288e5e3af83SSteve Glendinning 
289368be1caSAndre Edich static void smsc95xx_mdio_write_nopm(struct usbnet *dev, int idx, int regval)
290e5e3af83SSteve Glendinning {
29105b35e7eSAndre Edich 	struct smsc95xx_priv *pdata = dev->driver_priv;
292368be1caSAndre Edich 
29305b35e7eSAndre Edich 	__smsc95xx_mdio_write(dev, pdata->phydev->mdio.addr, idx, regval, 1);
294e5e3af83SSteve Glendinning }
295e5e3af83SSteve Glendinning 
29605b35e7eSAndre Edich static int smsc95xx_mdiobus_read(struct mii_bus *bus, int phy_id, int idx)
297e5e3af83SSteve Glendinning {
29805b35e7eSAndre Edich 	struct usbnet *dev = bus->priv;
29905b35e7eSAndre Edich 
30005b35e7eSAndre Edich 	return __smsc95xx_mdio_read(dev, phy_id, idx, 0);
301e5e3af83SSteve Glendinning }
302e5e3af83SSteve Glendinning 
30305b35e7eSAndre Edich static int smsc95xx_mdiobus_write(struct mii_bus *bus, int phy_id, int idx,
30405b35e7eSAndre Edich 				  u16 regval)
305e5e3af83SSteve Glendinning {
30605b35e7eSAndre Edich 	struct usbnet *dev = bus->priv;
30705b35e7eSAndre Edich 
30805b35e7eSAndre Edich 	__smsc95xx_mdio_write(dev, phy_id, idx, regval, 0);
30905b35e7eSAndre Edich 	return 0;
310e5e3af83SSteve Glendinning }
311e5e3af83SSteve Glendinning 
312769ea6d8SSteve Glendinning static int __must_check smsc95xx_wait_eeprom(struct usbnet *dev)
3132f7ca802SSteve Glendinning {
3142f7ca802SSteve Glendinning 	unsigned long start_time = jiffies;
3152f7ca802SSteve Glendinning 	u32 val;
316769ea6d8SSteve Glendinning 	int ret;
3172f7ca802SSteve Glendinning 
3182f7ca802SSteve Glendinning 	do {
319769ea6d8SSteve Glendinning 		ret = smsc95xx_read_reg(dev, E2P_CMD, &val);
320b052e073SSteve Glendinning 		if (ret < 0) {
321b052e073SSteve Glendinning 			netdev_warn(dev->net, "Error reading E2P_CMD\n");
322b052e073SSteve Glendinning 			return ret;
323b052e073SSteve Glendinning 		}
324b052e073SSteve Glendinning 
3252f7ca802SSteve Glendinning 		if (!(val & E2P_CMD_BUSY_) || (val & E2P_CMD_TIMEOUT_))
3262f7ca802SSteve Glendinning 			break;
3272f7ca802SSteve Glendinning 		udelay(40);
3282f7ca802SSteve Glendinning 	} while (!time_after(jiffies, start_time + HZ));
3292f7ca802SSteve Glendinning 
3302f7ca802SSteve Glendinning 	if (val & (E2P_CMD_TIMEOUT_ | E2P_CMD_BUSY_)) {
33160b86755SJoe Perches 		netdev_warn(dev->net, "EEPROM read operation timeout\n");
3322f7ca802SSteve Glendinning 		return -EIO;
3332f7ca802SSteve Glendinning 	}
3342f7ca802SSteve Glendinning 
3352f7ca802SSteve Glendinning 	return 0;
3362f7ca802SSteve Glendinning }
3372f7ca802SSteve Glendinning 
338769ea6d8SSteve Glendinning static int __must_check smsc95xx_eeprom_confirm_not_busy(struct usbnet *dev)
3392f7ca802SSteve Glendinning {
3402f7ca802SSteve Glendinning 	unsigned long start_time = jiffies;
3412f7ca802SSteve Glendinning 	u32 val;
342769ea6d8SSteve Glendinning 	int ret;
3432f7ca802SSteve Glendinning 
3442f7ca802SSteve Glendinning 	do {
345769ea6d8SSteve Glendinning 		ret = smsc95xx_read_reg(dev, E2P_CMD, &val);
346b052e073SSteve Glendinning 		if (ret < 0) {
347b052e073SSteve Glendinning 			netdev_warn(dev->net, "Error reading E2P_CMD\n");
348b052e073SSteve Glendinning 			return ret;
349b052e073SSteve Glendinning 		}
3502f7ca802SSteve Glendinning 
3512f7ca802SSteve Glendinning 		if (!(val & E2P_CMD_BUSY_))
3522f7ca802SSteve Glendinning 			return 0;
3532f7ca802SSteve Glendinning 
3542f7ca802SSteve Glendinning 		udelay(40);
3552f7ca802SSteve Glendinning 	} while (!time_after(jiffies, start_time + HZ));
3562f7ca802SSteve Glendinning 
35760b86755SJoe Perches 	netdev_warn(dev->net, "EEPROM is busy\n");
3582f7ca802SSteve Glendinning 	return -EIO;
3592f7ca802SSteve Glendinning }
3602f7ca802SSteve Glendinning 
3612f7ca802SSteve Glendinning static int smsc95xx_read_eeprom(struct usbnet *dev, u32 offset, u32 length,
3622f7ca802SSteve Glendinning 				u8 *data)
3632f7ca802SSteve Glendinning {
3642f7ca802SSteve Glendinning 	u32 val;
3652f7ca802SSteve Glendinning 	int i, ret;
3662f7ca802SSteve Glendinning 
3672f7ca802SSteve Glendinning 	BUG_ON(!dev);
3682f7ca802SSteve Glendinning 	BUG_ON(!data);
3692f7ca802SSteve Glendinning 
3702f7ca802SSteve Glendinning 	ret = smsc95xx_eeprom_confirm_not_busy(dev);
3712f7ca802SSteve Glendinning 	if (ret)
3722f7ca802SSteve Glendinning 		return ret;
3732f7ca802SSteve Glendinning 
3742f7ca802SSteve Glendinning 	for (i = 0; i < length; i++) {
3752f7ca802SSteve Glendinning 		val = E2P_CMD_BUSY_ | E2P_CMD_READ_ | (offset & E2P_CMD_ADDR_);
376769ea6d8SSteve Glendinning 		ret = smsc95xx_write_reg(dev, E2P_CMD, val);
377b052e073SSteve Glendinning 		if (ret < 0) {
378b052e073SSteve Glendinning 			netdev_warn(dev->net, "Error writing E2P_CMD\n");
379b052e073SSteve Glendinning 			return ret;
380b052e073SSteve Glendinning 		}
3812f7ca802SSteve Glendinning 
3822f7ca802SSteve Glendinning 		ret = smsc95xx_wait_eeprom(dev);
3832f7ca802SSteve Glendinning 		if (ret < 0)
3842f7ca802SSteve Glendinning 			return ret;
3852f7ca802SSteve Glendinning 
386769ea6d8SSteve Glendinning 		ret = smsc95xx_read_reg(dev, E2P_DATA, &val);
387b052e073SSteve Glendinning 		if (ret < 0) {
388b052e073SSteve Glendinning 			netdev_warn(dev->net, "Error reading E2P_DATA\n");
389b052e073SSteve Glendinning 			return ret;
390b052e073SSteve Glendinning 		}
3912f7ca802SSteve Glendinning 
3922f7ca802SSteve Glendinning 		data[i] = val & 0xFF;
3932f7ca802SSteve Glendinning 		offset++;
3942f7ca802SSteve Glendinning 	}
3952f7ca802SSteve Glendinning 
3962f7ca802SSteve Glendinning 	return 0;
3972f7ca802SSteve Glendinning }
3982f7ca802SSteve Glendinning 
3992f7ca802SSteve Glendinning static int smsc95xx_write_eeprom(struct usbnet *dev, u32 offset, u32 length,
4002f7ca802SSteve Glendinning 				 u8 *data)
4012f7ca802SSteve Glendinning {
4022f7ca802SSteve Glendinning 	u32 val;
4032f7ca802SSteve Glendinning 	int i, ret;
4042f7ca802SSteve Glendinning 
4052f7ca802SSteve Glendinning 	BUG_ON(!dev);
4062f7ca802SSteve Glendinning 	BUG_ON(!data);
4072f7ca802SSteve Glendinning 
4082f7ca802SSteve Glendinning 	ret = smsc95xx_eeprom_confirm_not_busy(dev);
4092f7ca802SSteve Glendinning 	if (ret)
4102f7ca802SSteve Glendinning 		return ret;
4112f7ca802SSteve Glendinning 
4122f7ca802SSteve Glendinning 	/* Issue write/erase enable command */
4132f7ca802SSteve Glendinning 	val = E2P_CMD_BUSY_ | E2P_CMD_EWEN_;
414769ea6d8SSteve Glendinning 	ret = smsc95xx_write_reg(dev, E2P_CMD, val);
415b052e073SSteve Glendinning 	if (ret < 0) {
416b052e073SSteve Glendinning 		netdev_warn(dev->net, "Error writing E2P_DATA\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 	for (i = 0; i < length; i++) {
4252f7ca802SSteve Glendinning 
4262f7ca802SSteve Glendinning 		/* Fill data register */
4272f7ca802SSteve Glendinning 		val = data[i];
428769ea6d8SSteve Glendinning 		ret = smsc95xx_write_reg(dev, E2P_DATA, val);
429b052e073SSteve Glendinning 		if (ret < 0) {
430b052e073SSteve Glendinning 			netdev_warn(dev->net, "Error writing E2P_DATA\n");
431b052e073SSteve Glendinning 			return ret;
432b052e073SSteve Glendinning 		}
4332f7ca802SSteve Glendinning 
4342f7ca802SSteve Glendinning 		/* Send "write" command */
4352f7ca802SSteve Glendinning 		val = E2P_CMD_BUSY_ | E2P_CMD_WRITE_ | (offset & E2P_CMD_ADDR_);
436769ea6d8SSteve Glendinning 		ret = smsc95xx_write_reg(dev, E2P_CMD, val);
437b052e073SSteve Glendinning 		if (ret < 0) {
438b052e073SSteve Glendinning 			netdev_warn(dev->net, "Error writing E2P_CMD\n");
439b052e073SSteve Glendinning 			return ret;
440b052e073SSteve Glendinning 		}
4412f7ca802SSteve Glendinning 
4422f7ca802SSteve Glendinning 		ret = smsc95xx_wait_eeprom(dev);
4432f7ca802SSteve Glendinning 		if (ret < 0)
4442f7ca802SSteve Glendinning 			return ret;
4452f7ca802SSteve Glendinning 
4462f7ca802SSteve Glendinning 		offset++;
4472f7ca802SSteve Glendinning 	}
4482f7ca802SSteve Glendinning 
4492f7ca802SSteve Glendinning 	return 0;
4502f7ca802SSteve Glendinning }
4512f7ca802SSteve Glendinning 
452769ea6d8SSteve Glendinning static int __must_check smsc95xx_write_reg_async(struct usbnet *dev, u16 index,
4537b9e7580SSteve Glendinning 						 u32 data)
4542f7ca802SSteve Glendinning {
4551d74a6bdSSteve Glendinning 	const u16 size = 4;
4567b9e7580SSteve Glendinning 	u32 buf;
45772108fd2SMing Lei 	int ret;
4582f7ca802SSteve Glendinning 
4597b9e7580SSteve Glendinning 	buf = data;
4607b9e7580SSteve Glendinning 	cpu_to_le32s(&buf);
4617b9e7580SSteve Glendinning 
46272108fd2SMing Lei 	ret = usbnet_write_cmd_async(dev, USB_VENDOR_REQUEST_WRITE_REGISTER,
46372108fd2SMing Lei 				     USB_DIR_OUT | USB_TYPE_VENDOR |
46472108fd2SMing Lei 				     USB_RECIP_DEVICE,
4657b9e7580SSteve Glendinning 				     0, index, &buf, size);
46672108fd2SMing Lei 	if (ret < 0)
46772108fd2SMing Lei 		netdev_warn(dev->net, "Error write async cmd, sts=%d\n",
46872108fd2SMing Lei 			    ret);
46972108fd2SMing Lei 	return ret;
4702f7ca802SSteve Glendinning }
4712f7ca802SSteve Glendinning 
4722f7ca802SSteve Glendinning /* returns hash bit number for given MAC address
4732f7ca802SSteve Glendinning  * example:
4742f7ca802SSteve Glendinning  * 01 00 5E 00 00 01 -> returns bit number 31 */
4752f7ca802SSteve Glendinning static unsigned int smsc95xx_hash(char addr[ETH_ALEN])
4762f7ca802SSteve Glendinning {
4772f7ca802SSteve Glendinning 	return (ether_crc(ETH_ALEN, addr) >> 26) & 0x3f;
4782f7ca802SSteve Glendinning }
4792f7ca802SSteve Glendinning 
4802f7ca802SSteve Glendinning static void smsc95xx_set_multicast(struct net_device *netdev)
4812f7ca802SSteve Glendinning {
4822f7ca802SSteve Glendinning 	struct usbnet *dev = netdev_priv(netdev);
483ad90a73fSAndre Edich 	struct smsc95xx_priv *pdata = dev->driver_priv;
4842f7ca802SSteve Glendinning 	unsigned long flags;
485769ea6d8SSteve Glendinning 	int ret;
4862f7ca802SSteve Glendinning 
4873c0f3c60SMarc Zyngier 	pdata->hash_hi = 0;
4883c0f3c60SMarc Zyngier 	pdata->hash_lo = 0;
4893c0f3c60SMarc Zyngier 
4902f7ca802SSteve Glendinning 	spin_lock_irqsave(&pdata->mac_cr_lock, flags);
4912f7ca802SSteve Glendinning 
4922f7ca802SSteve Glendinning 	if (dev->net->flags & IFF_PROMISC) {
493a475f603SJoe Perches 		netif_dbg(dev, drv, dev->net, "promiscuous mode enabled\n");
4942f7ca802SSteve Glendinning 		pdata->mac_cr |= MAC_CR_PRMS_;
4952f7ca802SSteve Glendinning 		pdata->mac_cr &= ~(MAC_CR_MCPAS_ | MAC_CR_HPFILT_);
4962f7ca802SSteve Glendinning 	} else if (dev->net->flags & IFF_ALLMULTI) {
497a475f603SJoe Perches 		netif_dbg(dev, drv, dev->net, "receive all multicast enabled\n");
4982f7ca802SSteve Glendinning 		pdata->mac_cr |= MAC_CR_MCPAS_;
4992f7ca802SSteve Glendinning 		pdata->mac_cr &= ~(MAC_CR_PRMS_ | MAC_CR_HPFILT_);
5004cd24eafSJiri Pirko 	} else if (!netdev_mc_empty(dev->net)) {
50122bedad3SJiri Pirko 		struct netdev_hw_addr *ha;
5022f7ca802SSteve Glendinning 
5032f7ca802SSteve Glendinning 		pdata->mac_cr |= MAC_CR_HPFILT_;
5042f7ca802SSteve Glendinning 		pdata->mac_cr &= ~(MAC_CR_PRMS_ | MAC_CR_MCPAS_);
5052f7ca802SSteve Glendinning 
50622bedad3SJiri Pirko 		netdev_for_each_mc_addr(ha, netdev) {
50722bedad3SJiri Pirko 			u32 bitnum = smsc95xx_hash(ha->addr);
5082f7ca802SSteve Glendinning 			u32 mask = 0x01 << (bitnum & 0x1F);
5092f7ca802SSteve Glendinning 			if (bitnum & 0x20)
5103c0f3c60SMarc Zyngier 				pdata->hash_hi |= mask;
5112f7ca802SSteve Glendinning 			else
5123c0f3c60SMarc Zyngier 				pdata->hash_lo |= mask;
5132f7ca802SSteve Glendinning 		}
5142f7ca802SSteve Glendinning 
515a475f603SJoe Perches 		netif_dbg(dev, drv, dev->net, "HASHH=0x%08X, HASHL=0x%08X\n",
5163c0f3c60SMarc Zyngier 				   pdata->hash_hi, pdata->hash_lo);
5172f7ca802SSteve Glendinning 	} else {
518a475f603SJoe Perches 		netif_dbg(dev, drv, dev->net, "receive own packets only\n");
5192f7ca802SSteve Glendinning 		pdata->mac_cr &=
5202f7ca802SSteve Glendinning 			~(MAC_CR_PRMS_ | MAC_CR_MCPAS_ | MAC_CR_HPFILT_);
5212f7ca802SSteve Glendinning 	}
5222f7ca802SSteve Glendinning 
5232f7ca802SSteve Glendinning 	spin_unlock_irqrestore(&pdata->mac_cr_lock, flags);
5242f7ca802SSteve Glendinning 
5252f7ca802SSteve Glendinning 	/* Initiate async writes, as we can't wait for completion here */
5267b9e7580SSteve Glendinning 	ret = smsc95xx_write_reg_async(dev, HASHH, pdata->hash_hi);
527b052e073SSteve Glendinning 	if (ret < 0)
528b052e073SSteve Glendinning 		netdev_warn(dev->net, "failed to initiate async write to HASHH\n");
529769ea6d8SSteve Glendinning 
5307b9e7580SSteve Glendinning 	ret = smsc95xx_write_reg_async(dev, HASHL, pdata->hash_lo);
531b052e073SSteve Glendinning 	if (ret < 0)
532b052e073SSteve Glendinning 		netdev_warn(dev->net, "failed to initiate async write to HASHL\n");
533769ea6d8SSteve Glendinning 
5347b9e7580SSteve Glendinning 	ret = smsc95xx_write_reg_async(dev, MAC_CR, pdata->mac_cr);
535b052e073SSteve Glendinning 	if (ret < 0)
536b052e073SSteve Glendinning 		netdev_warn(dev->net, "failed to initiate async write to MAC_CR\n");
5372f7ca802SSteve Glendinning }
5382f7ca802SSteve Glendinning 
53905b35e7eSAndre Edich static int smsc95xx_phy_update_flowcontrol(struct usbnet *dev)
5402f7ca802SSteve Glendinning {
5419c082731SNisar Sayed 	u32 flow = 0, afc_cfg;
54205b35e7eSAndre Edich 	struct smsc95xx_priv *pdata = dev->driver_priv;
54305b35e7eSAndre Edich 	bool tx_pause, rx_pause;
5442f7ca802SSteve Glendinning 
5452f7ca802SSteve Glendinning 	int ret = smsc95xx_read_reg(dev, AFC_CFG, &afc_cfg);
546e360a8b4SSteve Glendinning 	if (ret < 0)
547b052e073SSteve Glendinning 		return ret;
5482f7ca802SSteve Glendinning 
54905b35e7eSAndre Edich 	if (pdata->phydev->duplex == DUPLEX_FULL) {
55005b35e7eSAndre Edich 		phy_get_pause(pdata->phydev, &tx_pause, &rx_pause);
5512f7ca802SSteve Glendinning 
55205b35e7eSAndre Edich 		if (rx_pause)
5532f7ca802SSteve Glendinning 			flow = 0xFFFF0002;
5542f7ca802SSteve Glendinning 
55505b35e7eSAndre Edich 		if (tx_pause) {
5562f7ca802SSteve Glendinning 			afc_cfg |= 0xF;
5579c082731SNisar Sayed 			flow |= 0xFFFF0000;
5589c082731SNisar Sayed 		} else {
5592f7ca802SSteve Glendinning 			afc_cfg &= ~0xF;
5609c082731SNisar Sayed 		}
5612f7ca802SSteve Glendinning 
562a475f603SJoe Perches 		netif_dbg(dev, link, dev->net, "rx pause %s, tx pause %s\n",
56305b35e7eSAndre Edich 			  rx_pause ? "enabled" : "disabled",
56405b35e7eSAndre Edich 			  tx_pause ? "enabled" : "disabled");
5652f7ca802SSteve Glendinning 	} else {
566a475f603SJoe Perches 		netif_dbg(dev, link, dev->net, "half duplex\n");
5672f7ca802SSteve Glendinning 		afc_cfg |= 0xF;
5682f7ca802SSteve Glendinning 	}
5692f7ca802SSteve Glendinning 
570769ea6d8SSteve Glendinning 	ret = smsc95xx_write_reg(dev, FLOW, flow);
571b052e073SSteve Glendinning 	if (ret < 0)
572b052e073SSteve Glendinning 		return ret;
573e360a8b4SSteve Glendinning 
574e360a8b4SSteve Glendinning 	return smsc95xx_write_reg(dev, AFC_CFG, afc_cfg);
5752f7ca802SSteve Glendinning }
5762f7ca802SSteve Glendinning 
5778960f878SLukas Wunner static void smsc95xx_mac_update_fullduplex(struct usbnet *dev)
5782f7ca802SSteve Glendinning {
579ad90a73fSAndre Edich 	struct smsc95xx_priv *pdata = dev->driver_priv;
5802f7ca802SSteve Glendinning 	unsigned long flags;
581769ea6d8SSteve Glendinning 	int ret;
5822f7ca802SSteve Glendinning 
5832f7ca802SSteve Glendinning 	spin_lock_irqsave(&pdata->mac_cr_lock, flags);
58405b35e7eSAndre Edich 	if (pdata->phydev->duplex != DUPLEX_FULL) {
5852f7ca802SSteve Glendinning 		pdata->mac_cr &= ~MAC_CR_FDPX_;
5862f7ca802SSteve Glendinning 		pdata->mac_cr |= MAC_CR_RCVOWN_;
5872f7ca802SSteve Glendinning 	} else {
5882f7ca802SSteve Glendinning 		pdata->mac_cr &= ~MAC_CR_RCVOWN_;
5892f7ca802SSteve Glendinning 		pdata->mac_cr |= MAC_CR_FDPX_;
5902f7ca802SSteve Glendinning 	}
5912f7ca802SSteve Glendinning 	spin_unlock_irqrestore(&pdata->mac_cr_lock, flags);
5922f7ca802SSteve Glendinning 
593769ea6d8SSteve Glendinning 	ret = smsc95xx_write_reg(dev, MAC_CR, pdata->mac_cr);
5948960f878SLukas Wunner 	if (ret < 0) {
5958960f878SLukas Wunner 		if (ret != -ENODEV)
5968960f878SLukas Wunner 			netdev_warn(dev->net,
5978960f878SLukas Wunner 				    "Error updating MAC full duplex mode\n");
5988960f878SLukas Wunner 		return;
5998960f878SLukas Wunner 	}
6002f7ca802SSteve Glendinning 
60105b35e7eSAndre Edich 	ret = smsc95xx_phy_update_flowcontrol(dev);
602b052e073SSteve Glendinning 	if (ret < 0)
603b052e073SSteve Glendinning 		netdev_warn(dev->net, "Error updating PHY flow control\n");
6042f7ca802SSteve Glendinning }
6052f7ca802SSteve Glendinning 
6062f7ca802SSteve Glendinning static void smsc95xx_status(struct usbnet *dev, struct urb *urb)
6072f7ca802SSteve Glendinning {
6081ce8b372SLukas Wunner 	struct smsc95xx_priv *pdata = dev->driver_priv;
6091ce8b372SLukas Wunner 	unsigned long flags;
6102f7ca802SSteve Glendinning 	u32 intdata;
6112f7ca802SSteve Glendinning 
6122f7ca802SSteve Glendinning 	if (urb->actual_length != 4) {
61360b86755SJoe Perches 		netdev_warn(dev->net, "unexpected urb length %d\n",
61460b86755SJoe Perches 			    urb->actual_length);
6152f7ca802SSteve Glendinning 		return;
6162f7ca802SSteve Glendinning 	}
6172f7ca802SSteve Glendinning 
6186809d216SBen Dooks 	intdata = get_unaligned_le32(urb->transfer_buffer);
619a475f603SJoe Perches 	netif_dbg(dev, link, dev->net, "intdata: 0x%08X\n", intdata);
6202f7ca802SSteve Glendinning 
6211ce8b372SLukas Wunner 	local_irq_save(flags);
6221ce8b372SLukas Wunner 
6232f7ca802SSteve Glendinning 	if (intdata & INT_ENP_PHY_INT_)
6241ce8b372SLukas Wunner 		generic_handle_domain_irq(pdata->irqdomain, PHY_HWIRQ);
6252f7ca802SSteve Glendinning 	else
62660b86755SJoe Perches 		netdev_warn(dev->net, "unexpected interrupt, intdata=0x%08X\n",
62760b86755SJoe Perches 			    intdata);
6281ce8b372SLukas Wunner 
6291ce8b372SLukas Wunner 	local_irq_restore(flags);
6302f7ca802SSteve Glendinning }
6312f7ca802SSteve Glendinning 
632f7b29271SSteve Glendinning /* Enable or disable Tx & Rx checksum offload engines */
633c8f44affSMichał Mirosław static int smsc95xx_set_features(struct net_device *netdev,
634c8f44affSMichał Mirosław 	netdev_features_t features)
6352f7ca802SSteve Glendinning {
63678e47fe4SMichał Mirosław 	struct usbnet *dev = netdev_priv(netdev);
6372f7ca802SSteve Glendinning 	u32 read_buf;
63878e47fe4SMichał Mirosław 	int ret;
63978e47fe4SMichał Mirosław 
64078e47fe4SMichał Mirosław 	ret = smsc95xx_read_reg(dev, COE_CR, &read_buf);
641e360a8b4SSteve Glendinning 	if (ret < 0)
642b052e073SSteve Glendinning 		return ret;
6432f7ca802SSteve Glendinning 
644fe0cd8caSNisar Sayed 	if (features & NETIF_F_IP_CSUM)
645f7b29271SSteve Glendinning 		read_buf |= Tx_COE_EN_;
646f7b29271SSteve Glendinning 	else
647f7b29271SSteve Glendinning 		read_buf &= ~Tx_COE_EN_;
648f7b29271SSteve Glendinning 
64978e47fe4SMichał Mirosław 	if (features & NETIF_F_RXCSUM)
6502f7ca802SSteve Glendinning 		read_buf |= Rx_COE_EN_;
6512f7ca802SSteve Glendinning 	else
6522f7ca802SSteve Glendinning 		read_buf &= ~Rx_COE_EN_;
6532f7ca802SSteve Glendinning 
6542f7ca802SSteve Glendinning 	ret = smsc95xx_write_reg(dev, COE_CR, read_buf);
655e360a8b4SSteve Glendinning 	if (ret < 0)
656b052e073SSteve Glendinning 		return ret;
6572f7ca802SSteve Glendinning 
658a475f603SJoe Perches 	netif_dbg(dev, hw, dev->net, "COE_CR = 0x%08x\n", read_buf);
6592f7ca802SSteve Glendinning 	return 0;
6602f7ca802SSteve Glendinning }
6612f7ca802SSteve Glendinning 
6622f7ca802SSteve Glendinning static int smsc95xx_ethtool_get_eeprom_len(struct net_device *net)
6632f7ca802SSteve Glendinning {
6642f7ca802SSteve Glendinning 	return MAX_EEPROM_SIZE;
6652f7ca802SSteve Glendinning }
6662f7ca802SSteve Glendinning 
6672f7ca802SSteve Glendinning static int smsc95xx_ethtool_get_eeprom(struct net_device *netdev,
6682f7ca802SSteve Glendinning 				       struct ethtool_eeprom *ee, u8 *data)
6692f7ca802SSteve Glendinning {
6702f7ca802SSteve Glendinning 	struct usbnet *dev = netdev_priv(netdev);
6712f7ca802SSteve Glendinning 
6722f7ca802SSteve Glendinning 	ee->magic = LAN95XX_EEPROM_MAGIC;
6732f7ca802SSteve Glendinning 
6742f7ca802SSteve Glendinning 	return smsc95xx_read_eeprom(dev, ee->offset, ee->len, data);
6752f7ca802SSteve Glendinning }
6762f7ca802SSteve Glendinning 
6772f7ca802SSteve Glendinning static int smsc95xx_ethtool_set_eeprom(struct net_device *netdev,
6782f7ca802SSteve Glendinning 				       struct ethtool_eeprom *ee, u8 *data)
6792f7ca802SSteve Glendinning {
6802f7ca802SSteve Glendinning 	struct usbnet *dev = netdev_priv(netdev);
6812f7ca802SSteve Glendinning 
6822f7ca802SSteve Glendinning 	if (ee->magic != LAN95XX_EEPROM_MAGIC) {
68360b86755SJoe Perches 		netdev_warn(dev->net, "EEPROM: magic value mismatch, magic = 0x%x\n",
6842f7ca802SSteve Glendinning 			    ee->magic);
6852f7ca802SSteve Glendinning 		return -EINVAL;
6862f7ca802SSteve Glendinning 	}
6872f7ca802SSteve Glendinning 
6882f7ca802SSteve Glendinning 	return smsc95xx_write_eeprom(dev, ee->offset, ee->len, data);
6892f7ca802SSteve Glendinning }
6902f7ca802SSteve Glendinning 
6919fa32e94SEmeric Vigier static int smsc95xx_ethtool_getregslen(struct net_device *netdev)
6929fa32e94SEmeric Vigier {
6939fa32e94SEmeric Vigier 	/* all smsc95xx registers */
69496245317SSteve Glendinning 	return COE_CR - ID_REV + sizeof(u32);
6959fa32e94SEmeric Vigier }
6969fa32e94SEmeric Vigier 
6979fa32e94SEmeric Vigier static void
6989fa32e94SEmeric Vigier smsc95xx_ethtool_getregs(struct net_device *netdev, struct ethtool_regs *regs,
6999fa32e94SEmeric Vigier 			 void *buf)
7009fa32e94SEmeric Vigier {
7019fa32e94SEmeric Vigier 	struct usbnet *dev = netdev_priv(netdev);
702d348446bSDan Carpenter 	unsigned int i, j;
703d348446bSDan Carpenter 	int retval;
7049fa32e94SEmeric Vigier 	u32 *data = buf;
7059fa32e94SEmeric Vigier 
7069fa32e94SEmeric Vigier 	retval = smsc95xx_read_reg(dev, ID_REV, &regs->version);
7079fa32e94SEmeric Vigier 	if (retval < 0) {
7089fa32e94SEmeric Vigier 		netdev_warn(netdev, "REGS: cannot read ID_REV\n");
7099fa32e94SEmeric Vigier 		return;
7109fa32e94SEmeric Vigier 	}
7119fa32e94SEmeric Vigier 
7129fa32e94SEmeric Vigier 	for (i = ID_REV, j = 0; i <= COE_CR; i += (sizeof(u32)), j++) {
7139fa32e94SEmeric Vigier 		retval = smsc95xx_read_reg(dev, i, &data[j]);
7149fa32e94SEmeric Vigier 		if (retval < 0) {
7159fa32e94SEmeric Vigier 			netdev_warn(netdev, "REGS: cannot read reg[%x]\n", i);
7169fa32e94SEmeric Vigier 			return;
7179fa32e94SEmeric Vigier 		}
7189fa32e94SEmeric Vigier 	}
7199fa32e94SEmeric Vigier }
7209fa32e94SEmeric Vigier 
721e0e474a8SSteve Glendinning static void smsc95xx_ethtool_get_wol(struct net_device *net,
722e0e474a8SSteve Glendinning 				     struct ethtool_wolinfo *wolinfo)
723e0e474a8SSteve Glendinning {
724e0e474a8SSteve Glendinning 	struct usbnet *dev = netdev_priv(net);
725ad90a73fSAndre Edich 	struct smsc95xx_priv *pdata = dev->driver_priv;
726e0e474a8SSteve Glendinning 
727e0e474a8SSteve Glendinning 	wolinfo->supported = SUPPORTED_WAKE;
728e0e474a8SSteve Glendinning 	wolinfo->wolopts = pdata->wolopts;
729e0e474a8SSteve Glendinning }
730e0e474a8SSteve Glendinning 
731e0e474a8SSteve Glendinning static int smsc95xx_ethtool_set_wol(struct net_device *net,
732e0e474a8SSteve Glendinning 				    struct ethtool_wolinfo *wolinfo)
733e0e474a8SSteve Glendinning {
734e0e474a8SSteve Glendinning 	struct usbnet *dev = netdev_priv(net);
735ad90a73fSAndre Edich 	struct smsc95xx_priv *pdata = dev->driver_priv;
7363b14692cSSteve Glendinning 	int ret;
737e0e474a8SSteve Glendinning 
738c530c471SFlorian Fainelli 	if (wolinfo->wolopts & ~SUPPORTED_WAKE)
739c530c471SFlorian Fainelli 		return -EINVAL;
740c530c471SFlorian Fainelli 
741e0e474a8SSteve Glendinning 	pdata->wolopts = wolinfo->wolopts & SUPPORTED_WAKE;
7423b14692cSSteve Glendinning 
7433b14692cSSteve Glendinning 	ret = device_set_wakeup_enable(&dev->udev->dev, pdata->wolopts);
744b052e073SSteve Glendinning 	if (ret < 0)
745b052e073SSteve Glendinning 		netdev_warn(dev->net, "device_set_wakeup_enable error %d\n", ret);
7463b14692cSSteve Glendinning 
747b052e073SSteve Glendinning 	return ret;
748e0e474a8SSteve Glendinning }
749e0e474a8SSteve Glendinning 
75005b35e7eSAndre Edich static u32 smsc95xx_get_link(struct net_device *net)
75113722bbeSWoojung Huh {
75205b35e7eSAndre Edich 	phy_read_status(net->phydev);
75305b35e7eSAndre Edich 	return net->phydev->link;
75413722bbeSWoojung Huh }
75513722bbeSWoojung Huh 
7561710b52dSOleksij Rempel static void smsc95xx_ethtool_get_strings(struct net_device *netdev, u32 sset,
7571710b52dSOleksij Rempel 					u8 *data)
7581710b52dSOleksij Rempel {
7591710b52dSOleksij Rempel 	switch (sset) {
7601710b52dSOleksij Rempel 	case ETH_SS_TEST:
7611710b52dSOleksij Rempel 		net_selftest_get_strings(data);
7621710b52dSOleksij Rempel 		break;
7631710b52dSOleksij Rempel 	}
7641710b52dSOleksij Rempel }
7651710b52dSOleksij Rempel 
7661710b52dSOleksij Rempel static int smsc95xx_ethtool_get_sset_count(struct net_device *ndev, int sset)
7671710b52dSOleksij Rempel {
7681710b52dSOleksij Rempel 	switch (sset) {
7691710b52dSOleksij Rempel 	case ETH_SS_TEST:
7701710b52dSOleksij Rempel 		return net_selftest_get_count();
7711710b52dSOleksij Rempel 	default:
7721710b52dSOleksij Rempel 		return -EOPNOTSUPP;
7731710b52dSOleksij Rempel 	}
7741710b52dSOleksij Rempel }
7751710b52dSOleksij Rempel 
7760fc0b732SStephen Hemminger static const struct ethtool_ops smsc95xx_ethtool_ops = {
77705b35e7eSAndre Edich 	.get_link	= smsc95xx_get_link,
77805b35e7eSAndre Edich 	.nway_reset	= phy_ethtool_nway_reset,
7792f7ca802SSteve Glendinning 	.get_drvinfo	= usbnet_get_drvinfo,
7802f7ca802SSteve Glendinning 	.get_msglevel	= usbnet_get_msglevel,
7812f7ca802SSteve Glendinning 	.set_msglevel	= usbnet_set_msglevel,
7822f7ca802SSteve Glendinning 	.get_eeprom_len	= smsc95xx_ethtool_get_eeprom_len,
7832f7ca802SSteve Glendinning 	.get_eeprom	= smsc95xx_ethtool_get_eeprom,
7842f7ca802SSteve Glendinning 	.set_eeprom	= smsc95xx_ethtool_set_eeprom,
7859fa32e94SEmeric Vigier 	.get_regs_len	= smsc95xx_ethtool_getregslen,
7869fa32e94SEmeric Vigier 	.get_regs	= smsc95xx_ethtool_getregs,
787e0e474a8SSteve Glendinning 	.get_wol	= smsc95xx_ethtool_get_wol,
788e0e474a8SSteve Glendinning 	.set_wol	= smsc95xx_ethtool_set_wol,
78905b35e7eSAndre Edich 	.get_link_ksettings	= phy_ethtool_get_link_ksettings,
79005b35e7eSAndre Edich 	.set_link_ksettings	= phy_ethtool_set_link_ksettings,
791a8f5cb9eSPetr Kulhavy 	.get_ts_info	= ethtool_op_get_ts_info,
7921710b52dSOleksij Rempel 	.self_test	= net_selftest,
7931710b52dSOleksij Rempel 	.get_strings	= smsc95xx_ethtool_get_strings,
7941710b52dSOleksij Rempel 	.get_sset_count	= smsc95xx_ethtool_get_sset_count,
7952f7ca802SSteve Glendinning };
7962f7ca802SSteve Glendinning 
7972f7ca802SSteve Glendinning static int smsc95xx_ioctl(struct net_device *netdev, struct ifreq *rq, int cmd)
7982f7ca802SSteve Glendinning {
7992f7ca802SSteve Glendinning 	if (!netif_running(netdev))
8002f7ca802SSteve Glendinning 		return -EINVAL;
8012f7ca802SSteve Glendinning 
80205b35e7eSAndre Edich 	return phy_mii_ioctl(netdev->phydev, rq, cmd);
8032f7ca802SSteve Glendinning }
8042f7ca802SSteve Glendinning 
8052f7ca802SSteve Glendinning static void smsc95xx_init_mac_address(struct usbnet *dev)
8062f7ca802SSteve Glendinning {
807a7021af7SJakub Kicinski 	u8 addr[ETH_ALEN];
808a7021af7SJakub Kicinski 
809c489565bSArnd Bergmann 	/* maybe the boot loader passed the MAC address in devicetree */
8104d04cdc5SJakub Kicinski 	if (!platform_get_ethdev_address(&dev->udev->dev, dev->net)) {
8114f359b65SŁukasz Stelmach 		if (is_valid_ether_addr(dev->net->dev_addr)) {
8124f359b65SŁukasz Stelmach 			/* device tree values are valid so use them */
8134f359b65SŁukasz Stelmach 			netif_dbg(dev, ifup, dev->net, "MAC address read from the device tree\n");
814c489565bSArnd Bergmann 			return;
815c489565bSArnd Bergmann 		}
8164f359b65SŁukasz Stelmach 	}
817c489565bSArnd Bergmann 
8182f7ca802SSteve Glendinning 	/* try reading mac address from EEPROM */
819a7021af7SJakub Kicinski 	if (smsc95xx_read_eeprom(dev, EEPROM_MAC_OFFSET, ETH_ALEN, addr) == 0) {
820a7021af7SJakub Kicinski 		eth_hw_addr_set(dev->net, addr);
8212f7ca802SSteve Glendinning 		if (is_valid_ether_addr(dev->net->dev_addr)) {
8222f7ca802SSteve Glendinning 			/* eeprom values are valid so use them */
823a475f603SJoe Perches 			netif_dbg(dev, ifup, dev->net, "MAC address read from EEPROM\n");
8242f7ca802SSteve Glendinning 			return;
8252f7ca802SSteve Glendinning 		}
8262f7ca802SSteve Glendinning 	}
8272f7ca802SSteve Glendinning 
828c489565bSArnd Bergmann 	/* no useful static MAC address found. generate a random one */
829f2cedb63SDanny Kukawka 	eth_hw_addr_random(dev->net);
830c7e12eadSJoe Perches 	netif_dbg(dev, ifup, dev->net, "MAC address set to eth_random_addr\n");
8312f7ca802SSteve Glendinning }
8322f7ca802SSteve Glendinning 
8332f7ca802SSteve Glendinning static int smsc95xx_set_mac_address(struct usbnet *dev)
8342f7ca802SSteve Glendinning {
8352f7ca802SSteve Glendinning 	u32 addr_lo = dev->net->dev_addr[0] | dev->net->dev_addr[1] << 8 |
8362f7ca802SSteve Glendinning 		dev->net->dev_addr[2] << 16 | dev->net->dev_addr[3] << 24;
8372f7ca802SSteve Glendinning 	u32 addr_hi = dev->net->dev_addr[4] | dev->net->dev_addr[5] << 8;
8382f7ca802SSteve Glendinning 	int ret;
8392f7ca802SSteve Glendinning 
8402f7ca802SSteve Glendinning 	ret = smsc95xx_write_reg(dev, ADDRL, addr_lo);
841b052e073SSteve Glendinning 	if (ret < 0)
842b052e073SSteve Glendinning 		return ret;
843e360a8b4SSteve Glendinning 
844e360a8b4SSteve Glendinning 	return smsc95xx_write_reg(dev, ADDRH, addr_hi);
8452f7ca802SSteve Glendinning }
8462f7ca802SSteve Glendinning 
8472f7ca802SSteve Glendinning /* starts the TX path */
848769ea6d8SSteve Glendinning static int smsc95xx_start_tx_path(struct usbnet *dev)
8492f7ca802SSteve Glendinning {
850ad90a73fSAndre Edich 	struct smsc95xx_priv *pdata = dev->driver_priv;
8512f7ca802SSteve Glendinning 	unsigned long flags;
852769ea6d8SSteve Glendinning 	int ret;
8532f7ca802SSteve Glendinning 
8542f7ca802SSteve Glendinning 	/* Enable Tx at MAC */
8552f7ca802SSteve Glendinning 	spin_lock_irqsave(&pdata->mac_cr_lock, flags);
8562f7ca802SSteve Glendinning 	pdata->mac_cr |= MAC_CR_TXEN_;
8572f7ca802SSteve Glendinning 	spin_unlock_irqrestore(&pdata->mac_cr_lock, flags);
8582f7ca802SSteve Glendinning 
859769ea6d8SSteve Glendinning 	ret = smsc95xx_write_reg(dev, MAC_CR, pdata->mac_cr);
860e360a8b4SSteve Glendinning 	if (ret < 0)
861b052e073SSteve Glendinning 		return ret;
8622f7ca802SSteve Glendinning 
8632f7ca802SSteve Glendinning 	/* Enable Tx at SCSRs */
864e360a8b4SSteve Glendinning 	return smsc95xx_write_reg(dev, TX_CFG, TX_CFG_ON_);
8652f7ca802SSteve Glendinning }
8662f7ca802SSteve Glendinning 
8672f7ca802SSteve Glendinning /* Starts the Receive path */
868ec32115dSMing Lei static int smsc95xx_start_rx_path(struct usbnet *dev, int in_pm)
8692f7ca802SSteve Glendinning {
870ad90a73fSAndre Edich 	struct smsc95xx_priv *pdata = dev->driver_priv;
8712f7ca802SSteve Glendinning 	unsigned long flags;
8722f7ca802SSteve Glendinning 
8732f7ca802SSteve Glendinning 	spin_lock_irqsave(&pdata->mac_cr_lock, flags);
8742f7ca802SSteve Glendinning 	pdata->mac_cr |= MAC_CR_RXEN_;
8752f7ca802SSteve Glendinning 	spin_unlock_irqrestore(&pdata->mac_cr_lock, flags);
8762f7ca802SSteve Glendinning 
877e360a8b4SSteve Glendinning 	return __smsc95xx_write_reg(dev, MAC_CR, pdata->mac_cr, in_pm);
8782f7ca802SSteve Glendinning }
8792f7ca802SSteve Glendinning 
8802f7ca802SSteve Glendinning static int smsc95xx_reset(struct usbnet *dev)
8812f7ca802SSteve Glendinning {
882ad90a73fSAndre Edich 	struct smsc95xx_priv *pdata = dev->driver_priv;
8832f7ca802SSteve Glendinning 	u32 read_buf, write_buf, burst_cap;
8842f7ca802SSteve Glendinning 	int ret = 0, timeout;
8852f7ca802SSteve Glendinning 
886a475f603SJoe Perches 	netif_dbg(dev, ifup, dev->net, "entering smsc95xx_reset\n");
8872f7ca802SSteve Glendinning 
8884436761bSSteve Glendinning 	ret = smsc95xx_write_reg(dev, HW_CFG, HW_CFG_LRST_);
889e360a8b4SSteve Glendinning 	if (ret < 0)
890b052e073SSteve Glendinning 		return ret;
8912f7ca802SSteve Glendinning 
8922f7ca802SSteve Glendinning 	timeout = 0;
8932f7ca802SSteve Glendinning 	do {
894cf2acec2SSteve Glendinning 		msleep(10);
8952f7ca802SSteve Glendinning 		ret = smsc95xx_read_reg(dev, HW_CFG, &read_buf);
896e360a8b4SSteve Glendinning 		if (ret < 0)
897b052e073SSteve Glendinning 			return ret;
8982f7ca802SSteve Glendinning 		timeout++;
8992f7ca802SSteve Glendinning 	} while ((read_buf & HW_CFG_LRST_) && (timeout < 100));
9002f7ca802SSteve Glendinning 
9012f7ca802SSteve Glendinning 	if (timeout >= 100) {
90260b86755SJoe Perches 		netdev_warn(dev->net, "timeout waiting for completion of Lite Reset\n");
9032f7ca802SSteve Glendinning 		return ret;
9042f7ca802SSteve Glendinning 	}
9052f7ca802SSteve Glendinning 
9062f7ca802SSteve Glendinning 	ret = smsc95xx_set_mac_address(dev);
9072f7ca802SSteve Glendinning 	if (ret < 0)
9082f7ca802SSteve Glendinning 		return ret;
9092f7ca802SSteve Glendinning 
9101e1d7412SJoe Perches 	netif_dbg(dev, ifup, dev->net, "MAC Address: %pM\n",
9111e1d7412SJoe Perches 		  dev->net->dev_addr);
9122f7ca802SSteve Glendinning 
9132f7ca802SSteve Glendinning 	ret = smsc95xx_read_reg(dev, HW_CFG, &read_buf);
914e360a8b4SSteve Glendinning 	if (ret < 0)
915b052e073SSteve Glendinning 		return ret;
9162f7ca802SSteve Glendinning 
9171e1d7412SJoe Perches 	netif_dbg(dev, ifup, dev->net, "Read Value from HW_CFG : 0x%08x\n",
9181e1d7412SJoe Perches 		  read_buf);
9192f7ca802SSteve Glendinning 
9202f7ca802SSteve Glendinning 	read_buf |= HW_CFG_BIR_;
9212f7ca802SSteve Glendinning 
9222f7ca802SSteve Glendinning 	ret = smsc95xx_write_reg(dev, HW_CFG, read_buf);
923e360a8b4SSteve Glendinning 	if (ret < 0)
924b052e073SSteve Glendinning 		return ret;
9252f7ca802SSteve Glendinning 
9262f7ca802SSteve Glendinning 	ret = smsc95xx_read_reg(dev, HW_CFG, &read_buf);
927e360a8b4SSteve Glendinning 	if (ret < 0)
928b052e073SSteve Glendinning 		return ret;
929b052e073SSteve Glendinning 
930a475f603SJoe Perches 	netif_dbg(dev, ifup, dev->net,
931a475f603SJoe Perches 		  "Read Value from HW_CFG after writing HW_CFG_BIR_: 0x%08x\n",
93260b86755SJoe Perches 		  read_buf);
9332f7ca802SSteve Glendinning 
9342f7ca802SSteve Glendinning 	if (!turbo_mode) {
9352f7ca802SSteve Glendinning 		burst_cap = 0;
9362f7ca802SSteve Glendinning 		dev->rx_urb_size = MAX_SINGLE_PACKET_SIZE;
9372f7ca802SSteve Glendinning 	} else if (dev->udev->speed == USB_SPEED_HIGH) {
9382f7ca802SSteve Glendinning 		burst_cap = DEFAULT_HS_BURST_CAP_SIZE / HS_USB_PKT_SIZE;
9392f7ca802SSteve Glendinning 		dev->rx_urb_size = DEFAULT_HS_BURST_CAP_SIZE;
9402f7ca802SSteve Glendinning 	} else {
9412f7ca802SSteve Glendinning 		burst_cap = DEFAULT_FS_BURST_CAP_SIZE / FS_USB_PKT_SIZE;
9422f7ca802SSteve Glendinning 		dev->rx_urb_size = DEFAULT_FS_BURST_CAP_SIZE;
9432f7ca802SSteve Glendinning 	}
9442f7ca802SSteve Glendinning 
9451e1d7412SJoe Perches 	netif_dbg(dev, ifup, dev->net, "rx_urb_size=%ld\n",
9461e1d7412SJoe Perches 		  (ulong)dev->rx_urb_size);
9472f7ca802SSteve Glendinning 
9482f7ca802SSteve Glendinning 	ret = smsc95xx_write_reg(dev, BURST_CAP, burst_cap);
949e360a8b4SSteve Glendinning 	if (ret < 0)
950b052e073SSteve Glendinning 		return ret;
9512f7ca802SSteve Glendinning 
9522f7ca802SSteve Glendinning 	ret = smsc95xx_read_reg(dev, BURST_CAP, &read_buf);
953e360a8b4SSteve Glendinning 	if (ret < 0)
954b052e073SSteve Glendinning 		return ret;
955769ea6d8SSteve Glendinning 
956a475f603SJoe Perches 	netif_dbg(dev, ifup, dev->net,
957a475f603SJoe Perches 		  "Read Value from BURST_CAP after writing: 0x%08x\n",
9582f7ca802SSteve Glendinning 		  read_buf);
9592f7ca802SSteve Glendinning 
9604436761bSSteve Glendinning 	ret = smsc95xx_write_reg(dev, BULK_IN_DLY, DEFAULT_BULK_IN_DELAY);
961e360a8b4SSteve Glendinning 	if (ret < 0)
962b052e073SSteve Glendinning 		return ret;
9632f7ca802SSteve Glendinning 
9642f7ca802SSteve Glendinning 	ret = smsc95xx_read_reg(dev, BULK_IN_DLY, &read_buf);
965e360a8b4SSteve Glendinning 	if (ret < 0)
966b052e073SSteve Glendinning 		return ret;
967769ea6d8SSteve Glendinning 
968a475f603SJoe Perches 	netif_dbg(dev, ifup, dev->net,
969a475f603SJoe Perches 		  "Read Value from BULK_IN_DLY after writing: 0x%08x\n",
97060b86755SJoe Perches 		  read_buf);
9712f7ca802SSteve Glendinning 
9722f7ca802SSteve Glendinning 	ret = smsc95xx_read_reg(dev, HW_CFG, &read_buf);
973e360a8b4SSteve Glendinning 	if (ret < 0)
974b052e073SSteve Glendinning 		return ret;
975769ea6d8SSteve Glendinning 
9761e1d7412SJoe Perches 	netif_dbg(dev, ifup, dev->net, "Read Value from HW_CFG: 0x%08x\n",
9771e1d7412SJoe Perches 		  read_buf);
9782f7ca802SSteve Glendinning 
9792f7ca802SSteve Glendinning 	if (turbo_mode)
9802f7ca802SSteve Glendinning 		read_buf |= (HW_CFG_MEF_ | HW_CFG_BCE_);
9812f7ca802SSteve Glendinning 
9822f7ca802SSteve Glendinning 	read_buf &= ~HW_CFG_RXDOFF_;
9832f7ca802SSteve Glendinning 
9842f7ca802SSteve Glendinning 	/* set Rx data offset=2, Make IP header aligns on word boundary. */
9852f7ca802SSteve Glendinning 	read_buf |= NET_IP_ALIGN << 9;
9862f7ca802SSteve Glendinning 
9872f7ca802SSteve Glendinning 	ret = smsc95xx_write_reg(dev, HW_CFG, read_buf);
988e360a8b4SSteve Glendinning 	if (ret < 0)
989b052e073SSteve Glendinning 		return ret;
9902f7ca802SSteve Glendinning 
9912f7ca802SSteve Glendinning 	ret = smsc95xx_read_reg(dev, HW_CFG, &read_buf);
992e360a8b4SSteve Glendinning 	if (ret < 0)
993b052e073SSteve Glendinning 		return ret;
994769ea6d8SSteve Glendinning 
995a475f603SJoe Perches 	netif_dbg(dev, ifup, dev->net,
996a475f603SJoe Perches 		  "Read Value from HW_CFG after writing: 0x%08x\n", read_buf);
9972f7ca802SSteve Glendinning 
9984436761bSSteve Glendinning 	ret = smsc95xx_write_reg(dev, INT_STS, INT_STS_CLEAR_ALL_);
999e360a8b4SSteve Glendinning 	if (ret < 0)
1000b052e073SSteve Glendinning 		return ret;
10012f7ca802SSteve Glendinning 
10022f7ca802SSteve Glendinning 	ret = smsc95xx_read_reg(dev, ID_REV, &read_buf);
1003e360a8b4SSteve Glendinning 	if (ret < 0)
1004b052e073SSteve Glendinning 		return ret;
1005a475f603SJoe Perches 	netif_dbg(dev, ifup, dev->net, "ID_REV = 0x%08x\n", read_buf);
10062f7ca802SSteve Glendinning 
1007f293501cSSteve Glendinning 	/* Configure GPIO pins as LED outputs */
1008f293501cSSteve Glendinning 	write_buf = LED_GPIO_CFG_SPD_LED | LED_GPIO_CFG_LNK_LED |
1009f293501cSSteve Glendinning 		LED_GPIO_CFG_FDX_LED;
1010f293501cSSteve Glendinning 	ret = smsc95xx_write_reg(dev, LED_GPIO_CFG, write_buf);
1011e360a8b4SSteve Glendinning 	if (ret < 0)
1012b052e073SSteve Glendinning 		return ret;
1013f293501cSSteve Glendinning 
10142f7ca802SSteve Glendinning 	/* Init Tx */
10154436761bSSteve Glendinning 	ret = smsc95xx_write_reg(dev, FLOW, 0);
1016e360a8b4SSteve Glendinning 	if (ret < 0)
1017b052e073SSteve Glendinning 		return ret;
10182f7ca802SSteve Glendinning 
10194436761bSSteve Glendinning 	ret = smsc95xx_write_reg(dev, AFC_CFG, AFC_CFG_DEFAULT);
1020e360a8b4SSteve Glendinning 	if (ret < 0)
1021b052e073SSteve Glendinning 		return ret;
10222f7ca802SSteve Glendinning 
10232f7ca802SSteve Glendinning 	/* Don't need mac_cr_lock during initialisation */
10242f7ca802SSteve Glendinning 	ret = smsc95xx_read_reg(dev, MAC_CR, &pdata->mac_cr);
1025e360a8b4SSteve Glendinning 	if (ret < 0)
1026b052e073SSteve Glendinning 		return ret;
10272f7ca802SSteve Glendinning 
10282f7ca802SSteve Glendinning 	/* Init Rx */
10292f7ca802SSteve Glendinning 	/* Set Vlan */
10304436761bSSteve Glendinning 	ret = smsc95xx_write_reg(dev, VLAN1, (u32)ETH_P_8021Q);
1031e360a8b4SSteve Glendinning 	if (ret < 0)
1032b052e073SSteve Glendinning 		return ret;
10332f7ca802SSteve Glendinning 
1034f7b29271SSteve Glendinning 	/* Enable or disable checksum offload engines */
1035769ea6d8SSteve Glendinning 	ret = smsc95xx_set_features(dev->net, dev->net->features);
1036b052e073SSteve Glendinning 	if (ret < 0) {
1037b052e073SSteve Glendinning 		netdev_warn(dev->net, "Failed to set checksum offload features\n");
1038b052e073SSteve Glendinning 		return ret;
1039b052e073SSteve Glendinning 	}
10402f7ca802SSteve Glendinning 
10412f7ca802SSteve Glendinning 	smsc95xx_set_multicast(dev->net);
10422f7ca802SSteve Glendinning 
10432f7ca802SSteve Glendinning 	ret = smsc95xx_read_reg(dev, INT_EP_CTL, &read_buf);
1044e360a8b4SSteve Glendinning 	if (ret < 0)
1045b052e073SSteve Glendinning 		return ret;
10462f7ca802SSteve Glendinning 
10472f7ca802SSteve Glendinning 	/* enable PHY interrupts */
10482f7ca802SSteve Glendinning 	read_buf |= INT_EP_CTL_PHY_INT_;
10492f7ca802SSteve Glendinning 
10502f7ca802SSteve Glendinning 	ret = smsc95xx_write_reg(dev, INT_EP_CTL, read_buf);
1051e360a8b4SSteve Glendinning 	if (ret < 0)
1052b052e073SSteve Glendinning 		return ret;
10532f7ca802SSteve Glendinning 
1054769ea6d8SSteve Glendinning 	ret = smsc95xx_start_tx_path(dev);
1055b052e073SSteve Glendinning 	if (ret < 0) {
1056b052e073SSteve Glendinning 		netdev_warn(dev->net, "Failed to start TX path\n");
1057b052e073SSteve Glendinning 		return ret;
1058b052e073SSteve Glendinning 	}
1059769ea6d8SSteve Glendinning 
1060ec32115dSMing Lei 	ret = smsc95xx_start_rx_path(dev, 0);
1061b052e073SSteve Glendinning 	if (ret < 0) {
1062b052e073SSteve Glendinning 		netdev_warn(dev->net, "Failed to start RX path\n");
1063b052e073SSteve Glendinning 		return ret;
1064b052e073SSteve Glendinning 	}
10652f7ca802SSteve Glendinning 
1066a475f603SJoe Perches 	netif_dbg(dev, ifup, dev->net, "smsc95xx_reset, return 0\n");
10672f7ca802SSteve Glendinning 	return 0;
10682f7ca802SSteve Glendinning }
10692f7ca802SSteve Glendinning 
107063e77b39SStephen Hemminger static const struct net_device_ops smsc95xx_netdev_ops = {
107163e77b39SStephen Hemminger 	.ndo_open		= usbnet_open,
107263e77b39SStephen Hemminger 	.ndo_stop		= usbnet_stop,
107363e77b39SStephen Hemminger 	.ndo_start_xmit		= usbnet_start_xmit,
107463e77b39SStephen Hemminger 	.ndo_tx_timeout		= usbnet_tx_timeout,
107563e77b39SStephen Hemminger 	.ndo_change_mtu		= usbnet_change_mtu,
1076323955a0SHeiner Kallweit 	.ndo_get_stats64	= dev_get_tstats64,
107763e77b39SStephen Hemminger 	.ndo_set_mac_address 	= eth_mac_addr,
107863e77b39SStephen Hemminger 	.ndo_validate_addr	= eth_validate_addr,
1079a7605370SArnd Bergmann 	.ndo_eth_ioctl		= smsc95xx_ioctl,
1080afc4b13dSJiri Pirko 	.ndo_set_rx_mode	= smsc95xx_set_multicast,
108178e47fe4SMichał Mirosław 	.ndo_set_features	= smsc95xx_set_features,
108263e77b39SStephen Hemminger };
108363e77b39SStephen Hemminger 
1084a049a30fSMartyn Welch static void smsc95xx_handle_link_change(struct net_device *net)
1085a049a30fSMartyn Welch {
1086a049a30fSMartyn Welch 	struct usbnet *dev = netdev_priv(net);
1087a049a30fSMartyn Welch 
1088a049a30fSMartyn Welch 	phy_print_status(net->phydev);
10898960f878SLukas Wunner 	smsc95xx_mac_update_fullduplex(dev);
1090a049a30fSMartyn Welch 	usbnet_defer_kevent(dev, EVENT_LINK_CHANGE);
1091a049a30fSMartyn Welch }
1092a049a30fSMartyn Welch 
10932f7ca802SSteve Glendinning static int smsc95xx_bind(struct usbnet *dev, struct usb_interface *intf)
10942f7ca802SSteve Glendinning {
1095ad90a73fSAndre Edich 	struct smsc95xx_priv *pdata;
109605b35e7eSAndre Edich 	bool is_internal_phy;
10971ce8b372SLukas Wunner 	char usb_path[64];
10981ce8b372SLukas Wunner 	int ret, phy_irq;
1099bbd9f9eeSSteve Glendinning 	u32 val;
11002f7ca802SSteve Glendinning 
11012f7ca802SSteve Glendinning 	printk(KERN_INFO SMSC_CHIPNAME " v" SMSC_DRIVER_VERSION "\n");
11022f7ca802SSteve Glendinning 
11032f7ca802SSteve Glendinning 	ret = usbnet_get_endpoints(dev, intf);
1104b052e073SSteve Glendinning 	if (ret < 0) {
1105b052e073SSteve Glendinning 		netdev_warn(dev->net, "usbnet_get_endpoints failed: %d\n", ret);
1106b052e073SSteve Glendinning 		return ret;
1107b052e073SSteve Glendinning 	}
11082f7ca802SSteve Glendinning 
1109ad90a73fSAndre Edich 	pdata = kzalloc(sizeof(*pdata), GFP_KERNEL);
111038673c82SJoe Perches 	if (!pdata)
11112f7ca802SSteve Glendinning 		return -ENOMEM;
11122f7ca802SSteve Glendinning 
1113ad90a73fSAndre Edich 	dev->driver_priv = pdata;
1114ad90a73fSAndre Edich 
11152f7ca802SSteve Glendinning 	spin_lock_init(&pdata->mac_cr_lock);
11162f7ca802SSteve Glendinning 
1117fe0cd8caSNisar Sayed 	/* LAN95xx devices do not alter the computed checksum of 0 to 0xffff.
1118fe0cd8caSNisar Sayed 	 * RFC 2460, ipv6 UDP calculated checksum yields a result of zero must
1119fe0cd8caSNisar Sayed 	 * be changed to 0xffff. RFC 768, ipv4 UDP computed checksum is zero,
1120fe0cd8caSNisar Sayed 	 * it is transmitted as all ones. The zero transmitted checksum means
1121fe0cd8caSNisar Sayed 	 * transmitter generated no checksum. Hence, enable csum offload only
1122fe0cd8caSNisar Sayed 	 * for ipv4 packets.
1123fe0cd8caSNisar Sayed 	 */
112478e47fe4SMichał Mirosław 	if (DEFAULT_TX_CSUM_ENABLE)
1125fe0cd8caSNisar Sayed 		dev->net->features |= NETIF_F_IP_CSUM;
112678e47fe4SMichał Mirosław 	if (DEFAULT_RX_CSUM_ENABLE)
112778e47fe4SMichał Mirosław 		dev->net->features |= NETIF_F_RXCSUM;
112878e47fe4SMichał Mirosław 
1129fe0cd8caSNisar Sayed 	dev->net->hw_features = NETIF_F_IP_CSUM | NETIF_F_RXCSUM;
1130810eeb1fSBen Dooks 	set_bit(EVENT_NO_IP_ALIGN, &dev->flags);
11312f7ca802SSteve Glendinning 
1132f4e8ab7cSBernard Blackham 	smsc95xx_init_mac_address(dev);
1133f4e8ab7cSBernard Blackham 
11342f7ca802SSteve Glendinning 	/* Init all registers */
11352f7ca802SSteve Glendinning 	ret = smsc95xx_reset(dev);
11367c8b1e85SAndre Edich 	if (ret)
11377c8b1e85SAndre Edich 		goto free_pdata;
11382f7ca802SSteve Glendinning 
11391ce8b372SLukas Wunner 	/* create irq domain for use by PHY driver and GPIO consumers */
11401ce8b372SLukas Wunner 	usb_make_path(dev->udev, usb_path, sizeof(usb_path));
11411ce8b372SLukas Wunner 	pdata->irqfwnode = irq_domain_alloc_named_fwnode(usb_path);
11421ce8b372SLukas Wunner 	if (!pdata->irqfwnode) {
11431ce8b372SLukas Wunner 		ret = -ENOMEM;
11441ce8b372SLukas Wunner 		goto free_pdata;
11451ce8b372SLukas Wunner 	}
11461ce8b372SLukas Wunner 
11471ce8b372SLukas Wunner 	pdata->irqdomain = irq_domain_create_linear(pdata->irqfwnode,
11481ce8b372SLukas Wunner 						    SMSC95XX_NR_IRQS,
11491ce8b372SLukas Wunner 						    &irq_domain_simple_ops,
11501ce8b372SLukas Wunner 						    pdata);
11511ce8b372SLukas Wunner 	if (!pdata->irqdomain) {
11521ce8b372SLukas Wunner 		ret = -ENOMEM;
11531ce8b372SLukas Wunner 		goto free_irqfwnode;
11541ce8b372SLukas Wunner 	}
11551ce8b372SLukas Wunner 
11561ce8b372SLukas Wunner 	phy_irq = irq_create_mapping(pdata->irqdomain, PHY_HWIRQ);
11571ce8b372SLukas Wunner 	if (!phy_irq) {
11581ce8b372SLukas Wunner 		ret = -ENOENT;
11591ce8b372SLukas Wunner 		goto remove_irqdomain;
11601ce8b372SLukas Wunner 	}
11611ce8b372SLukas Wunner 
11621ce8b372SLukas Wunner 	pdata->irqchip = dummy_irq_chip;
11631ce8b372SLukas Wunner 	pdata->irqchip.name = SMSC_CHIPNAME;
11641ce8b372SLukas Wunner 	irq_set_chip_and_handler_name(phy_irq, &pdata->irqchip,
11651ce8b372SLukas Wunner 				      handle_simple_irq, "phy");
11661ce8b372SLukas Wunner 
116705b35e7eSAndre Edich 	pdata->mdiobus = mdiobus_alloc();
116805b35e7eSAndre Edich 	if (!pdata->mdiobus) {
116905b35e7eSAndre Edich 		ret = -ENOMEM;
11701ce8b372SLukas Wunner 		goto dispose_irq;
117105b35e7eSAndre Edich 	}
117205b35e7eSAndre Edich 
117305b35e7eSAndre Edich 	ret = smsc95xx_read_reg(dev, HW_CFG, &val);
117405b35e7eSAndre Edich 	if (ret < 0)
117505b35e7eSAndre Edich 		goto free_mdio;
117605b35e7eSAndre Edich 
117705b35e7eSAndre Edich 	is_internal_phy = !(val & HW_CFG_PSEL_);
117805b35e7eSAndre Edich 	if (is_internal_phy)
117905b35e7eSAndre Edich 		pdata->mdiobus->phy_mask = ~(1u << SMSC95XX_INTERNAL_PHY_ID);
118005b35e7eSAndre Edich 
118105b35e7eSAndre Edich 	pdata->mdiobus->priv = dev;
118205b35e7eSAndre Edich 	pdata->mdiobus->read = smsc95xx_mdiobus_read;
118305b35e7eSAndre Edich 	pdata->mdiobus->write = smsc95xx_mdiobus_write;
118405b35e7eSAndre Edich 	pdata->mdiobus->name = "smsc95xx-mdiobus";
118505b35e7eSAndre Edich 	pdata->mdiobus->parent = &dev->udev->dev;
118605b35e7eSAndre Edich 
118705b35e7eSAndre Edich 	snprintf(pdata->mdiobus->id, ARRAY_SIZE(pdata->mdiobus->id),
118805b35e7eSAndre Edich 		 "usb-%03d:%03d", dev->udev->bus->busnum, dev->udev->devnum);
118905b35e7eSAndre Edich 
119005b35e7eSAndre Edich 	ret = mdiobus_register(pdata->mdiobus);
119105b35e7eSAndre Edich 	if (ret) {
119205b35e7eSAndre Edich 		netdev_err(dev->net, "Could not register MDIO bus\n");
119305b35e7eSAndre Edich 		goto free_mdio;
119405b35e7eSAndre Edich 	}
119505b35e7eSAndre Edich 
119605b35e7eSAndre Edich 	pdata->phydev = phy_find_first(pdata->mdiobus);
119705b35e7eSAndre Edich 	if (!pdata->phydev) {
119805b35e7eSAndre Edich 		netdev_err(dev->net, "no PHY found\n");
119905b35e7eSAndre Edich 		ret = -ENODEV;
120005b35e7eSAndre Edich 		goto unregister_mdio;
120105b35e7eSAndre Edich 	}
120205b35e7eSAndre Edich 
12031ce8b372SLukas Wunner 	pdata->phydev->irq = phy_irq;
120405b35e7eSAndre Edich 	pdata->phydev->is_internal = is_internal_phy;
120505b35e7eSAndre Edich 
1206bbd9f9eeSSteve Glendinning 	/* detect device revision as different features may be available */
1207bbd9f9eeSSteve Glendinning 	ret = smsc95xx_read_reg(dev, ID_REV, &val);
1208e360a8b4SSteve Glendinning 	if (ret < 0)
120905b35e7eSAndre Edich 		goto unregister_mdio;
12103ed58f96SAndre Edich 
1211bbd9f9eeSSteve Glendinning 	val >>= 16;
12129ebca507SSteve Glendinning 	if ((val == ID_REV_CHIP_ID_9500A_) || (val == ID_REV_CHIP_ID_9530_) ||
12139ebca507SSteve Glendinning 	    (val == ID_REV_CHIP_ID_89530_) || (val == ID_REV_CHIP_ID_9730_))
12149ebca507SSteve Glendinning 		pdata->features = (FEATURE_8_WAKEUP_FILTERS |
12159ebca507SSteve Glendinning 			FEATURE_PHY_NLP_CROSSOVER |
1216eb970ff0SMing Lei 			FEATURE_REMOTE_WAKEUP);
12179ebca507SSteve Glendinning 	else if (val == ID_REV_CHIP_ID_9512_)
12189ebca507SSteve Glendinning 		pdata->features = FEATURE_8_WAKEUP_FILTERS;
1219bbd9f9eeSSteve Glendinning 
122063e77b39SStephen Hemminger 	dev->net->netdev_ops = &smsc95xx_netdev_ops;
12212f7ca802SSteve Glendinning 	dev->net->ethtool_ops = &smsc95xx_ethtool_ops;
12222f7ca802SSteve Glendinning 	dev->net->flags |= IFF_MULTICAST;
122378e47fe4SMichał Mirosław 	dev->net->hard_header_len += SMSC95XX_TX_OVERHEAD_CSUM;
122485b18b02SStefan Wahren 	dev->net->min_mtu = ETH_MIN_MTU;
122585b18b02SStefan Wahren 	dev->net->max_mtu = ETH_DATA_LEN;
12269bbf5660SStephane Fillod 	dev->hard_mtu = dev->net->mtu + dev->net->hard_header_len;
1227a049a30fSMartyn Welch 
1228a049a30fSMartyn Welch 	ret = phy_connect_direct(dev->net, pdata->phydev,
1229a049a30fSMartyn Welch 				 &smsc95xx_handle_link_change,
1230a049a30fSMartyn Welch 				 PHY_INTERFACE_MODE_MII);
1231a049a30fSMartyn Welch 	if (ret) {
1232a049a30fSMartyn Welch 		netdev_err(dev->net, "can't attach PHY to %s\n", pdata->mdiobus->id);
1233a049a30fSMartyn Welch 		goto unregister_mdio;
1234a049a30fSMartyn Welch 	}
1235a049a30fSMartyn Welch 
1236a049a30fSMartyn Welch 	phy_attached_info(dev->net->phydev);
1237a049a30fSMartyn Welch 
12382f7ca802SSteve Glendinning 	return 0;
12397c8b1e85SAndre Edich 
124005b35e7eSAndre Edich unregister_mdio:
124105b35e7eSAndre Edich 	mdiobus_unregister(pdata->mdiobus);
124205b35e7eSAndre Edich 
124305b35e7eSAndre Edich free_mdio:
124405b35e7eSAndre Edich 	mdiobus_free(pdata->mdiobus);
124505b35e7eSAndre Edich 
12461ce8b372SLukas Wunner dispose_irq:
12471ce8b372SLukas Wunner 	irq_dispose_mapping(phy_irq);
12481ce8b372SLukas Wunner 
12491ce8b372SLukas Wunner remove_irqdomain:
12501ce8b372SLukas Wunner 	irq_domain_remove(pdata->irqdomain);
12511ce8b372SLukas Wunner 
12521ce8b372SLukas Wunner free_irqfwnode:
12531ce8b372SLukas Wunner 	irq_domain_free_fwnode(pdata->irqfwnode);
12541ce8b372SLukas Wunner 
12557c8b1e85SAndre Edich free_pdata:
12567c8b1e85SAndre Edich 	kfree(pdata);
12577c8b1e85SAndre Edich 	return ret;
12582f7ca802SSteve Glendinning }
12592f7ca802SSteve Glendinning 
12602f7ca802SSteve Glendinning static void smsc95xx_unbind(struct usbnet *dev, struct usb_interface *intf)
12612f7ca802SSteve Glendinning {
1262ad90a73fSAndre Edich 	struct smsc95xx_priv *pdata = dev->driver_priv;
1263d69d1694SChristoph Fritz 
1264a049a30fSMartyn Welch 	phy_disconnect(dev->net->phydev);
126505b35e7eSAndre Edich 	mdiobus_unregister(pdata->mdiobus);
126605b35e7eSAndre Edich 	mdiobus_free(pdata->mdiobus);
12671ce8b372SLukas Wunner 	irq_dispose_mapping(irq_find_mapping(pdata->irqdomain, PHY_HWIRQ));
12681ce8b372SLukas Wunner 	irq_domain_remove(pdata->irqdomain);
12691ce8b372SLukas Wunner 	irq_domain_free_fwnode(pdata->irqfwnode);
1270a475f603SJoe Perches 	netif_dbg(dev, ifdown, dev->net, "free pdata\n");
12712f7ca802SSteve Glendinning 	kfree(pdata);
12722f7ca802SSteve Glendinning }
12732f7ca802SSteve Glendinning 
127405b35e7eSAndre Edich static int smsc95xx_start_phy(struct usbnet *dev)
127505b35e7eSAndre Edich {
1276a049a30fSMartyn Welch 	phy_start(dev->net->phydev);
127705b35e7eSAndre Edich 
127805b35e7eSAndre Edich 	return 0;
127905b35e7eSAndre Edich }
128005b35e7eSAndre Edich 
1281a049a30fSMartyn Welch static int smsc95xx_stop(struct usbnet *dev)
128205b35e7eSAndre Edich {
128305b35e7eSAndre Edich 	phy_stop(dev->net->phydev);
1284a049a30fSMartyn Welch 
128505b35e7eSAndre Edich 	return 0;
128605b35e7eSAndre Edich }
128705b35e7eSAndre Edich 
1288068bb1a7SSteve Glendinning static u32 smsc_crc(const u8 *buffer, size_t len, int filter)
1289bbd9f9eeSSteve Glendinning {
1290068bb1a7SSteve Glendinning 	u32 crc = bitrev16(crc16(0xFFFF, buffer, len));
1291068bb1a7SSteve Glendinning 	return crc << ((filter % 2) * 16);
1292bbd9f9eeSSteve Glendinning }
1293bbd9f9eeSSteve Glendinning 
1294e5e3af83SSteve Glendinning static int smsc95xx_link_ok_nopm(struct usbnet *dev)
1295e5e3af83SSteve Glendinning {
1296e5e3af83SSteve Glendinning 	int ret;
1297e5e3af83SSteve Glendinning 
1298e5e3af83SSteve Glendinning 	/* first, a dummy read, needed to latch some MII phys */
1299368be1caSAndre Edich 	ret = smsc95xx_mdio_read_nopm(dev, MII_BMSR);
1300e360a8b4SSteve Glendinning 	if (ret < 0)
1301b052e073SSteve Glendinning 		return ret;
1302e5e3af83SSteve Glendinning 
1303368be1caSAndre Edich 	ret = smsc95xx_mdio_read_nopm(dev, MII_BMSR);
1304e360a8b4SSteve Glendinning 	if (ret < 0)
1305b052e073SSteve Glendinning 		return ret;
1306e5e3af83SSteve Glendinning 
1307e5e3af83SSteve Glendinning 	return !!(ret & BMSR_LSTATUS);
1308e5e3af83SSteve Glendinning }
1309e5e3af83SSteve Glendinning 
1310319b95b5SSteve Glendinning static int smsc95xx_enter_suspend0(struct usbnet *dev)
1311319b95b5SSteve Glendinning {
1312ad90a73fSAndre Edich 	struct smsc95xx_priv *pdata = dev->driver_priv;
1313319b95b5SSteve Glendinning 	u32 val;
1314319b95b5SSteve Glendinning 	int ret;
1315319b95b5SSteve Glendinning 
1316319b95b5SSteve Glendinning 	ret = smsc95xx_read_reg_nopm(dev, PM_CTRL, &val);
1317e360a8b4SSteve Glendinning 	if (ret < 0)
1318b052e073SSteve Glendinning 		return ret;
1319319b95b5SSteve Glendinning 
1320319b95b5SSteve Glendinning 	val &= (~(PM_CTL_SUS_MODE_ | PM_CTL_WUPS_ | PM_CTL_PHY_RST_));
1321319b95b5SSteve Glendinning 	val |= PM_CTL_SUS_MODE_0;
1322319b95b5SSteve Glendinning 
1323319b95b5SSteve Glendinning 	ret = smsc95xx_write_reg_nopm(dev, PM_CTRL, val);
1324e360a8b4SSteve Glendinning 	if (ret < 0)
1325b052e073SSteve Glendinning 		return ret;
1326319b95b5SSteve Glendinning 
1327319b95b5SSteve Glendinning 	/* clear wol status */
1328319b95b5SSteve Glendinning 	val &= ~PM_CTL_WUPS_;
1329319b95b5SSteve Glendinning 	val |= PM_CTL_WUPS_WOL_;
1330319b95b5SSteve Glendinning 
1331319b95b5SSteve Glendinning 	/* enable energy detection */
1332319b95b5SSteve Glendinning 	if (pdata->wolopts & WAKE_PHY)
1333319b95b5SSteve Glendinning 		val |= PM_CTL_WUPS_ED_;
1334319b95b5SSteve Glendinning 
1335319b95b5SSteve Glendinning 	ret = smsc95xx_write_reg_nopm(dev, PM_CTRL, val);
1336e360a8b4SSteve Glendinning 	if (ret < 0)
1337b052e073SSteve Glendinning 		return ret;
1338319b95b5SSteve Glendinning 
1339319b95b5SSteve Glendinning 	/* read back PM_CTRL */
1340319b95b5SSteve Glendinning 	ret = smsc95xx_read_reg_nopm(dev, PM_CTRL, &val);
134176437214SMing Lei 	if (ret < 0)
134276437214SMing Lei 		return ret;
1343319b95b5SSteve Glendinning 
1344b2d4b150SSteve Glendinning 	pdata->suspend_flags |= SUSPEND_SUSPEND0;
1345b2d4b150SSteve Glendinning 
134676437214SMing Lei 	return 0;
1347319b95b5SSteve Glendinning }
1348319b95b5SSteve Glendinning 
1349319b95b5SSteve Glendinning static int smsc95xx_enter_suspend1(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 	/* reconfigure link pulse detection timing for
1356319b95b5SSteve Glendinning 	 * compatibility with non-standard link partners
1357319b95b5SSteve Glendinning 	 */
1358319b95b5SSteve Glendinning 	if (pdata->features & FEATURE_PHY_NLP_CROSSOVER)
1359368be1caSAndre Edich 		smsc95xx_mdio_write_nopm(dev, PHY_EDPD_CONFIG,
1360319b95b5SSteve Glendinning 					 PHY_EDPD_CONFIG_DEFAULT);
1361319b95b5SSteve Glendinning 
1362319b95b5SSteve Glendinning 	/* enable energy detect power-down mode */
1363368be1caSAndre Edich 	ret = smsc95xx_mdio_read_nopm(dev, PHY_MODE_CTRL_STS);
1364e360a8b4SSteve Glendinning 	if (ret < 0)
1365b052e073SSteve Glendinning 		return ret;
1366319b95b5SSteve Glendinning 
1367319b95b5SSteve Glendinning 	ret |= MODE_CTRL_STS_EDPWRDOWN_;
1368319b95b5SSteve Glendinning 
1369368be1caSAndre Edich 	smsc95xx_mdio_write_nopm(dev, PHY_MODE_CTRL_STS, ret);
1370319b95b5SSteve Glendinning 
1371319b95b5SSteve Glendinning 	/* enter SUSPEND1 mode */
1372319b95b5SSteve Glendinning 	ret = smsc95xx_read_reg_nopm(dev, PM_CTRL, &val);
1373e360a8b4SSteve Glendinning 	if (ret < 0)
1374b052e073SSteve Glendinning 		return ret;
1375319b95b5SSteve Glendinning 
1376319b95b5SSteve Glendinning 	val &= ~(PM_CTL_SUS_MODE_ | PM_CTL_WUPS_ | PM_CTL_PHY_RST_);
1377319b95b5SSteve Glendinning 	val |= PM_CTL_SUS_MODE_1;
1378319b95b5SSteve Glendinning 
1379319b95b5SSteve Glendinning 	ret = smsc95xx_write_reg_nopm(dev, PM_CTRL, val);
1380e360a8b4SSteve Glendinning 	if (ret < 0)
1381b052e073SSteve Glendinning 		return ret;
1382319b95b5SSteve Glendinning 
1383319b95b5SSteve Glendinning 	/* clear wol status, enable energy detection */
1384319b95b5SSteve Glendinning 	val &= ~PM_CTL_WUPS_;
1385319b95b5SSteve Glendinning 	val |= (PM_CTL_WUPS_ED_ | PM_CTL_ED_EN_);
1386319b95b5SSteve Glendinning 
1387319b95b5SSteve Glendinning 	ret = smsc95xx_write_reg_nopm(dev, PM_CTRL, val);
138876437214SMing Lei 	if (ret < 0)
138976437214SMing Lei 		return ret;
1390319b95b5SSteve Glendinning 
1391b2d4b150SSteve Glendinning 	pdata->suspend_flags |= SUSPEND_SUSPEND1;
1392b2d4b150SSteve Glendinning 
139376437214SMing Lei 	return 0;
1394319b95b5SSteve Glendinning }
1395319b95b5SSteve Glendinning 
1396319b95b5SSteve Glendinning static int smsc95xx_enter_suspend2(struct usbnet *dev)
1397319b95b5SSteve Glendinning {
1398ad90a73fSAndre Edich 	struct smsc95xx_priv *pdata = dev->driver_priv;
1399319b95b5SSteve Glendinning 	u32 val;
1400319b95b5SSteve Glendinning 	int ret;
1401319b95b5SSteve Glendinning 
1402319b95b5SSteve Glendinning 	ret = smsc95xx_read_reg_nopm(dev, PM_CTRL, &val);
1403e360a8b4SSteve Glendinning 	if (ret < 0)
1404b052e073SSteve Glendinning 		return ret;
1405319b95b5SSteve Glendinning 
1406319b95b5SSteve Glendinning 	val &= ~(PM_CTL_SUS_MODE_ | PM_CTL_WUPS_ | PM_CTL_PHY_RST_);
1407319b95b5SSteve Glendinning 	val |= PM_CTL_SUS_MODE_2;
1408319b95b5SSteve Glendinning 
1409319b95b5SSteve Glendinning 	ret = smsc95xx_write_reg_nopm(dev, PM_CTRL, val);
141076437214SMing Lei 	if (ret < 0)
141176437214SMing Lei 		return ret;
1412319b95b5SSteve Glendinning 
1413b2d4b150SSteve Glendinning 	pdata->suspend_flags |= SUSPEND_SUSPEND2;
1414b2d4b150SSteve Glendinning 
141576437214SMing Lei 	return 0;
1416319b95b5SSteve Glendinning }
1417319b95b5SSteve Glendinning 
1418b2d4b150SSteve Glendinning static int smsc95xx_enter_suspend3(struct usbnet *dev)
1419b2d4b150SSteve Glendinning {
1420ad90a73fSAndre Edich 	struct smsc95xx_priv *pdata = dev->driver_priv;
1421b2d4b150SSteve Glendinning 	u32 val;
1422b2d4b150SSteve Glendinning 	int ret;
1423b2d4b150SSteve Glendinning 
1424b2d4b150SSteve Glendinning 	ret = smsc95xx_read_reg_nopm(dev, RX_FIFO_INF, &val);
1425b2d4b150SSteve Glendinning 	if (ret < 0)
1426b2d4b150SSteve Glendinning 		return ret;
1427b2d4b150SSteve Glendinning 
142853a759c8SMartin Wetterwald 	if (val & RX_FIFO_INF_USED_) {
1429b2d4b150SSteve Glendinning 		netdev_info(dev->net, "rx fifo not empty in autosuspend\n");
1430b2d4b150SSteve Glendinning 		return -EBUSY;
1431b2d4b150SSteve Glendinning 	}
1432b2d4b150SSteve Glendinning 
1433b2d4b150SSteve Glendinning 	ret = smsc95xx_read_reg_nopm(dev, PM_CTRL, &val);
1434b2d4b150SSteve Glendinning 	if (ret < 0)
1435b2d4b150SSteve Glendinning 		return ret;
1436b2d4b150SSteve Glendinning 
1437b2d4b150SSteve Glendinning 	val &= ~(PM_CTL_SUS_MODE_ | PM_CTL_WUPS_ | PM_CTL_PHY_RST_);
1438b2d4b150SSteve Glendinning 	val |= PM_CTL_SUS_MODE_3 | PM_CTL_RES_CLR_WKP_STS;
1439b2d4b150SSteve Glendinning 
1440b2d4b150SSteve Glendinning 	ret = smsc95xx_write_reg_nopm(dev, PM_CTRL, val);
1441b2d4b150SSteve Glendinning 	if (ret < 0)
1442b2d4b150SSteve Glendinning 		return ret;
1443b2d4b150SSteve Glendinning 
1444b2d4b150SSteve Glendinning 	/* clear wol status */
1445b2d4b150SSteve Glendinning 	val &= ~PM_CTL_WUPS_;
1446b2d4b150SSteve Glendinning 	val |= PM_CTL_WUPS_WOL_;
1447b2d4b150SSteve Glendinning 
1448b2d4b150SSteve Glendinning 	ret = smsc95xx_write_reg_nopm(dev, PM_CTRL, val);
1449b2d4b150SSteve Glendinning 	if (ret < 0)
1450b2d4b150SSteve Glendinning 		return ret;
1451b2d4b150SSteve Glendinning 
1452b2d4b150SSteve Glendinning 	pdata->suspend_flags |= SUSPEND_SUSPEND3;
1453b2d4b150SSteve Glendinning 
1454b2d4b150SSteve Glendinning 	return 0;
1455b2d4b150SSteve Glendinning }
1456b2d4b150SSteve Glendinning 
1457b2d4b150SSteve Glendinning static int smsc95xx_autosuspend(struct usbnet *dev, u32 link_up)
1458b2d4b150SSteve Glendinning {
1459ad90a73fSAndre Edich 	struct smsc95xx_priv *pdata = dev->driver_priv;
1460b2d4b150SSteve Glendinning 
1461b2d4b150SSteve Glendinning 	if (!netif_running(dev->net)) {
1462b2d4b150SSteve Glendinning 		/* interface is ifconfig down so fully power down hw */
1463b2d4b150SSteve Glendinning 		netdev_dbg(dev->net, "autosuspend entering SUSPEND2\n");
1464b2d4b150SSteve Glendinning 		return smsc95xx_enter_suspend2(dev);
1465b2d4b150SSteve Glendinning 	}
1466b2d4b150SSteve Glendinning 
1467b2d4b150SSteve Glendinning 	if (!link_up) {
1468b2d4b150SSteve Glendinning 		/* link is down so enter EDPD mode, but only if device can
1469b2d4b150SSteve Glendinning 		 * reliably resume from it.  This check should be redundant
1470eb970ff0SMing Lei 		 * as current FEATURE_REMOTE_WAKEUP parts also support
1471b2d4b150SSteve Glendinning 		 * FEATURE_PHY_NLP_CROSSOVER but it's included for clarity */
1472b2d4b150SSteve Glendinning 		if (!(pdata->features & FEATURE_PHY_NLP_CROSSOVER)) {
1473b2d4b150SSteve Glendinning 			netdev_warn(dev->net, "EDPD not supported\n");
1474b2d4b150SSteve Glendinning 			return -EBUSY;
1475b2d4b150SSteve Glendinning 		}
1476b2d4b150SSteve Glendinning 
1477b2d4b150SSteve Glendinning 		netdev_dbg(dev->net, "autosuspend entering SUSPEND1\n");
1478b2d4b150SSteve Glendinning 		netdev_info(dev->net, "entering SUSPEND1 mode\n");
1479b2d4b150SSteve Glendinning 		return smsc95xx_enter_suspend1(dev);
1480b2d4b150SSteve Glendinning 	}
1481b2d4b150SSteve Glendinning 
1482b2d4b150SSteve Glendinning 	netdev_dbg(dev->net, "autosuspend entering SUSPEND3\n");
1483b2d4b150SSteve Glendinning 	return smsc95xx_enter_suspend3(dev);
1484b2d4b150SSteve Glendinning }
1485b2d4b150SSteve Glendinning 
1486b5a04475SSteve Glendinning static int smsc95xx_suspend(struct usb_interface *intf, pm_message_t message)
1487b5a04475SSteve Glendinning {
1488b5a04475SSteve Glendinning 	struct usbnet *dev = usb_get_intfdata(intf);
1489ad90a73fSAndre Edich 	struct smsc95xx_priv *pdata = dev->driver_priv;
1490e5e3af83SSteve Glendinning 	u32 val, link_up;
1491b5a04475SSteve Glendinning 	int ret;
1492b5a04475SSteve Glendinning 
1493b5a04475SSteve Glendinning 	ret = usbnet_suspend(intf, message);
1494b052e073SSteve Glendinning 	if (ret < 0) {
1495b052e073SSteve Glendinning 		netdev_warn(dev->net, "usbnet_suspend error\n");
1496b052e073SSteve Glendinning 		return ret;
1497b052e073SSteve Glendinning 	}
1498b5a04475SSteve Glendinning 
1499b2d4b150SSteve Glendinning 	if (pdata->suspend_flags) {
1500b2d4b150SSteve Glendinning 		netdev_warn(dev->net, "error during last resume\n");
1501b2d4b150SSteve Glendinning 		pdata->suspend_flags = 0;
1502b2d4b150SSteve Glendinning 	}
1503b2d4b150SSteve Glendinning 
1504e5e3af83SSteve Glendinning 	/* determine if link is up using only _nopm functions */
1505e5e3af83SSteve Glendinning 	link_up = smsc95xx_link_ok_nopm(dev);
1506e5e3af83SSteve Glendinning 
150742e21c01SMing Lei 	if (message.event == PM_EVENT_AUTO_SUSPEND &&
1508eb970ff0SMing Lei 	    (pdata->features & FEATURE_REMOTE_WAKEUP)) {
1509b2d4b150SSteve Glendinning 		ret = smsc95xx_autosuspend(dev, link_up);
1510b2d4b150SSteve Glendinning 		goto done;
1511b2d4b150SSteve Glendinning 	}
1512b2d4b150SSteve Glendinning 
1513b2d4b150SSteve Glendinning 	/* if we get this far we're not autosuspending */
1514e5e3af83SSteve Glendinning 	/* if no wol options set, or if link is down and we're not waking on
1515e5e3af83SSteve Glendinning 	 * PHY activity, enter lowest power SUSPEND2 mode
1516e5e3af83SSteve Glendinning 	 */
1517e5e3af83SSteve Glendinning 	if (!(pdata->wolopts & SUPPORTED_WAKE) ||
1518e5e3af83SSteve Glendinning 		!(link_up || (pdata->wolopts & WAKE_PHY))) {
15191e1d7412SJoe Perches 		netdev_info(dev->net, "entering SUSPEND2 mode\n");
1520b5a04475SSteve Glendinning 
1521e0e474a8SSteve Glendinning 		/* disable energy detect (link up) & wake up events */
1522ec32115dSMing Lei 		ret = smsc95xx_read_reg_nopm(dev, WUCSR, &val);
1523e360a8b4SSteve Glendinning 		if (ret < 0)
1524b052e073SSteve Glendinning 			goto done;
1525e0e474a8SSteve Glendinning 
1526e0e474a8SSteve Glendinning 		val &= ~(WUCSR_MPEN_ | WUCSR_WAKE_EN_);
1527e0e474a8SSteve Glendinning 
1528ec32115dSMing Lei 		ret = smsc95xx_write_reg_nopm(dev, WUCSR, val);
1529e360a8b4SSteve Glendinning 		if (ret < 0)
1530b052e073SSteve Glendinning 			goto done;
1531e0e474a8SSteve Glendinning 
1532ec32115dSMing Lei 		ret = smsc95xx_read_reg_nopm(dev, PM_CTRL, &val);
1533e360a8b4SSteve Glendinning 		if (ret < 0)
1534b052e073SSteve Glendinning 			goto done;
1535e0e474a8SSteve Glendinning 
1536e0e474a8SSteve Glendinning 		val &= ~(PM_CTL_ED_EN_ | PM_CTL_WOL_EN_);
1537e0e474a8SSteve Glendinning 
1538ec32115dSMing Lei 		ret = smsc95xx_write_reg_nopm(dev, PM_CTRL, val);
1539e360a8b4SSteve Glendinning 		if (ret < 0)
1540b052e073SSteve Glendinning 			goto done;
1541e0e474a8SSteve Glendinning 
15423b9f7d8cSSteve Glendinning 		ret = smsc95xx_enter_suspend2(dev);
15433b9f7d8cSSteve Glendinning 		goto done;
1544b5a04475SSteve Glendinning 	}
1545b5a04475SSteve Glendinning 
1546e5e3af83SSteve Glendinning 	if (pdata->wolopts & WAKE_PHY) {
1547e5e3af83SSteve Glendinning 		/* if link is down then configure EDPD and enter SUSPEND1,
1548e5e3af83SSteve Glendinning 		 * otherwise enter SUSPEND0 below
1549e5e3af83SSteve Glendinning 		 */
1550e5e3af83SSteve Glendinning 		if (!link_up) {
15511e1d7412SJoe Perches 			netdev_info(dev->net, "entering SUSPEND1 mode\n");
15523b9f7d8cSSteve Glendinning 			ret = smsc95xx_enter_suspend1(dev);
15533b9f7d8cSSteve Glendinning 			goto done;
1554e5e3af83SSteve Glendinning 		}
1555e5e3af83SSteve Glendinning 	}
1556e5e3af83SSteve Glendinning 
1557bbd9f9eeSSteve Glendinning 	if (pdata->wolopts & (WAKE_BCAST | WAKE_MCAST | WAKE_ARP | WAKE_UCAST)) {
15586396bb22SKees Cook 		u32 *filter_mask = kcalloc(32, sizeof(u32), GFP_KERNEL);
155906a221beSMing Lei 		u32 command[2];
156006a221beSMing Lei 		u32 offset[2];
156106a221beSMing Lei 		u32 crc[4];
15629ebca507SSteve Glendinning 		int wuff_filter_count =
15639ebca507SSteve Glendinning 			(pdata->features & FEATURE_8_WAKEUP_FILTERS) ?
15649ebca507SSteve Glendinning 			LAN9500A_WUFF_NUM : LAN9500_WUFF_NUM;
1565bbd9f9eeSSteve Glendinning 		int i, filter = 0;
1566bbd9f9eeSSteve Glendinning 
1567eed9a729SSteve Glendinning 		if (!filter_mask) {
1568eed9a729SSteve Glendinning 			netdev_warn(dev->net, "Unable to allocate filter_mask\n");
15693b9f7d8cSSteve Glendinning 			ret = -ENOMEM;
15703b9f7d8cSSteve Glendinning 			goto done;
1571eed9a729SSteve Glendinning 		}
1572eed9a729SSteve Glendinning 
157306a221beSMing Lei 		memset(command, 0, sizeof(command));
157406a221beSMing Lei 		memset(offset, 0, sizeof(offset));
157506a221beSMing Lei 		memset(crc, 0, sizeof(crc));
157606a221beSMing Lei 
1577bbd9f9eeSSteve Glendinning 		if (pdata->wolopts & WAKE_BCAST) {
1578bbd9f9eeSSteve Glendinning 			const u8 bcast[] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF};
15791e1d7412SJoe Perches 			netdev_info(dev->net, "enabling broadcast detection\n");
1580bbd9f9eeSSteve Glendinning 			filter_mask[filter * 4] = 0x003F;
1581bbd9f9eeSSteve Glendinning 			filter_mask[filter * 4 + 1] = 0x00;
1582bbd9f9eeSSteve Glendinning 			filter_mask[filter * 4 + 2] = 0x00;
1583bbd9f9eeSSteve Glendinning 			filter_mask[filter * 4 + 3] = 0x00;
1584bbd9f9eeSSteve Glendinning 			command[filter/4] |= 0x05UL << ((filter % 4) * 8);
1585bbd9f9eeSSteve Glendinning 			offset[filter/4] |= 0x00 << ((filter % 4) * 8);
1586bbd9f9eeSSteve Glendinning 			crc[filter/2] |= smsc_crc(bcast, 6, filter);
1587bbd9f9eeSSteve Glendinning 			filter++;
1588bbd9f9eeSSteve Glendinning 		}
1589bbd9f9eeSSteve Glendinning 
1590bbd9f9eeSSteve Glendinning 		if (pdata->wolopts & WAKE_MCAST) {
1591bbd9f9eeSSteve Glendinning 			const u8 mcast[] = {0x01, 0x00, 0x5E};
15921e1d7412SJoe Perches 			netdev_info(dev->net, "enabling multicast detection\n");
1593bbd9f9eeSSteve Glendinning 			filter_mask[filter * 4] = 0x0007;
1594bbd9f9eeSSteve Glendinning 			filter_mask[filter * 4 + 1] = 0x00;
1595bbd9f9eeSSteve Glendinning 			filter_mask[filter * 4 + 2] = 0x00;
1596bbd9f9eeSSteve Glendinning 			filter_mask[filter * 4 + 3] = 0x00;
1597bbd9f9eeSSteve Glendinning 			command[filter/4] |= 0x09UL << ((filter % 4) * 8);
1598bbd9f9eeSSteve Glendinning 			offset[filter/4] |= 0x00  << ((filter % 4) * 8);
1599bbd9f9eeSSteve Glendinning 			crc[filter/2] |= smsc_crc(mcast, 3, filter);
1600bbd9f9eeSSteve Glendinning 			filter++;
1601bbd9f9eeSSteve Glendinning 		}
1602bbd9f9eeSSteve Glendinning 
1603bbd9f9eeSSteve Glendinning 		if (pdata->wolopts & WAKE_ARP) {
1604bbd9f9eeSSteve Glendinning 			const u8 arp[] = {0x08, 0x06};
16051e1d7412SJoe Perches 			netdev_info(dev->net, "enabling ARP detection\n");
1606bbd9f9eeSSteve Glendinning 			filter_mask[filter * 4] = 0x0003;
1607bbd9f9eeSSteve Glendinning 			filter_mask[filter * 4 + 1] = 0x00;
1608bbd9f9eeSSteve Glendinning 			filter_mask[filter * 4 + 2] = 0x00;
1609bbd9f9eeSSteve Glendinning 			filter_mask[filter * 4 + 3] = 0x00;
1610bbd9f9eeSSteve Glendinning 			command[filter/4] |= 0x05UL << ((filter % 4) * 8);
1611bbd9f9eeSSteve Glendinning 			offset[filter/4] |= 0x0C << ((filter % 4) * 8);
1612bbd9f9eeSSteve Glendinning 			crc[filter/2] |= smsc_crc(arp, 2, filter);
1613bbd9f9eeSSteve Glendinning 			filter++;
1614bbd9f9eeSSteve Glendinning 		}
1615bbd9f9eeSSteve Glendinning 
1616bbd9f9eeSSteve Glendinning 		if (pdata->wolopts & WAKE_UCAST) {
16171e1d7412SJoe Perches 			netdev_info(dev->net, "enabling unicast detection\n");
1618bbd9f9eeSSteve Glendinning 			filter_mask[filter * 4] = 0x003F;
1619bbd9f9eeSSteve Glendinning 			filter_mask[filter * 4 + 1] = 0x00;
1620bbd9f9eeSSteve Glendinning 			filter_mask[filter * 4 + 2] = 0x00;
1621bbd9f9eeSSteve Glendinning 			filter_mask[filter * 4 + 3] = 0x00;
1622bbd9f9eeSSteve Glendinning 			command[filter/4] |= 0x01UL << ((filter % 4) * 8);
1623bbd9f9eeSSteve Glendinning 			offset[filter/4] |= 0x00 << ((filter % 4) * 8);
1624bbd9f9eeSSteve Glendinning 			crc[filter/2] |= smsc_crc(dev->net->dev_addr, ETH_ALEN, filter);
1625bbd9f9eeSSteve Glendinning 			filter++;
1626bbd9f9eeSSteve Glendinning 		}
1627bbd9f9eeSSteve Glendinning 
16289ebca507SSteve Glendinning 		for (i = 0; i < (wuff_filter_count * 4); i++) {
1629ec32115dSMing Lei 			ret = smsc95xx_write_reg_nopm(dev, WUFF, filter_mask[i]);
1630b052e073SSteve Glendinning 			if (ret < 0) {
163106a221beSMing Lei 				kfree(filter_mask);
1632b052e073SSteve Glendinning 				goto done;
1633b052e073SSteve Glendinning 			}
1634bbd9f9eeSSteve Glendinning 		}
163506a221beSMing Lei 		kfree(filter_mask);
1636bbd9f9eeSSteve Glendinning 
16379ebca507SSteve Glendinning 		for (i = 0; i < (wuff_filter_count / 4); i++) {
1638ec32115dSMing Lei 			ret = smsc95xx_write_reg_nopm(dev, WUFF, command[i]);
1639e360a8b4SSteve Glendinning 			if (ret < 0)
1640b052e073SSteve Glendinning 				goto done;
1641b052e073SSteve Glendinning 		}
1642bbd9f9eeSSteve Glendinning 
16439ebca507SSteve Glendinning 		for (i = 0; i < (wuff_filter_count / 4); i++) {
1644ec32115dSMing Lei 			ret = smsc95xx_write_reg_nopm(dev, WUFF, offset[i]);
1645e360a8b4SSteve Glendinning 			if (ret < 0)
1646b052e073SSteve Glendinning 				goto done;
1647b052e073SSteve Glendinning 		}
1648bbd9f9eeSSteve Glendinning 
16499ebca507SSteve Glendinning 		for (i = 0; i < (wuff_filter_count / 2); i++) {
1650ec32115dSMing Lei 			ret = smsc95xx_write_reg_nopm(dev, WUFF, crc[i]);
1651e360a8b4SSteve Glendinning 			if (ret < 0)
1652b052e073SSteve Glendinning 				goto done;
1653b052e073SSteve Glendinning 		}
1654bbd9f9eeSSteve Glendinning 
1655bbd9f9eeSSteve Glendinning 		/* clear any pending pattern match packet status */
1656ec32115dSMing Lei 		ret = smsc95xx_read_reg_nopm(dev, WUCSR, &val);
1657e360a8b4SSteve Glendinning 		if (ret < 0)
1658b052e073SSteve Glendinning 			goto done;
1659bbd9f9eeSSteve Glendinning 
1660bbd9f9eeSSteve Glendinning 		val |= WUCSR_WUFR_;
1661bbd9f9eeSSteve Glendinning 
1662ec32115dSMing Lei 		ret = smsc95xx_write_reg_nopm(dev, WUCSR, val);
1663e360a8b4SSteve Glendinning 		if (ret < 0)
1664b052e073SSteve Glendinning 			goto done;
1665b052e073SSteve Glendinning 	}
1666bbd9f9eeSSteve Glendinning 
1667e0e474a8SSteve Glendinning 	if (pdata->wolopts & WAKE_MAGIC) {
1668e0e474a8SSteve Glendinning 		/* clear any pending magic packet status */
1669ec32115dSMing Lei 		ret = smsc95xx_read_reg_nopm(dev, WUCSR, &val);
1670e360a8b4SSteve Glendinning 		if (ret < 0)
1671b052e073SSteve Glendinning 			goto done;
1672e0e474a8SSteve Glendinning 
1673e0e474a8SSteve Glendinning 		val |= WUCSR_MPR_;
1674e0e474a8SSteve Glendinning 
1675ec32115dSMing Lei 		ret = smsc95xx_write_reg_nopm(dev, WUCSR, val);
1676e360a8b4SSteve Glendinning 		if (ret < 0)
1677b052e073SSteve Glendinning 			goto done;
1678b052e073SSteve Glendinning 	}
1679e0e474a8SSteve Glendinning 
1680bbd9f9eeSSteve Glendinning 	/* enable/disable wakeup sources */
1681ec32115dSMing Lei 	ret = smsc95xx_read_reg_nopm(dev, WUCSR, &val);
1682e360a8b4SSteve Glendinning 	if (ret < 0)
1683b052e073SSteve Glendinning 		goto done;
1684e0e474a8SSteve Glendinning 
1685bbd9f9eeSSteve Glendinning 	if (pdata->wolopts & (WAKE_BCAST | WAKE_MCAST | WAKE_ARP | WAKE_UCAST)) {
16861e1d7412SJoe Perches 		netdev_info(dev->net, "enabling pattern match wakeup\n");
1687bbd9f9eeSSteve Glendinning 		val |= WUCSR_WAKE_EN_;
1688bbd9f9eeSSteve Glendinning 	} else {
16891e1d7412SJoe Perches 		netdev_info(dev->net, "disabling pattern match wakeup\n");
1690bbd9f9eeSSteve Glendinning 		val &= ~WUCSR_WAKE_EN_;
1691bbd9f9eeSSteve Glendinning 	}
1692bbd9f9eeSSteve Glendinning 
1693e0e474a8SSteve Glendinning 	if (pdata->wolopts & WAKE_MAGIC) {
16941e1d7412SJoe Perches 		netdev_info(dev->net, "enabling magic packet wakeup\n");
1695e0e474a8SSteve Glendinning 		val |= WUCSR_MPEN_;
1696e0e474a8SSteve Glendinning 	} else {
16971e1d7412SJoe Perches 		netdev_info(dev->net, "disabling magic packet wakeup\n");
1698e0e474a8SSteve Glendinning 		val &= ~WUCSR_MPEN_;
1699e0e474a8SSteve Glendinning 	}
1700e0e474a8SSteve Glendinning 
1701ec32115dSMing Lei 	ret = smsc95xx_write_reg_nopm(dev, WUCSR, val);
1702e360a8b4SSteve Glendinning 	if (ret < 0)
1703b052e073SSteve Glendinning 		goto done;
1704e0e474a8SSteve Glendinning 
1705e0e474a8SSteve Glendinning 	/* enable wol wakeup source */
1706ec32115dSMing Lei 	ret = smsc95xx_read_reg_nopm(dev, PM_CTRL, &val);
1707e360a8b4SSteve Glendinning 	if (ret < 0)
1708b052e073SSteve Glendinning 		goto done;
1709e0e474a8SSteve Glendinning 
1710e0e474a8SSteve Glendinning 	val |= PM_CTL_WOL_EN_;
1711e0e474a8SSteve Glendinning 
1712e5e3af83SSteve Glendinning 	/* phy energy detect wakeup source */
1713e5e3af83SSteve Glendinning 	if (pdata->wolopts & WAKE_PHY)
1714e5e3af83SSteve Glendinning 		val |= PM_CTL_ED_EN_;
1715e5e3af83SSteve Glendinning 
1716ec32115dSMing Lei 	ret = smsc95xx_write_reg_nopm(dev, PM_CTRL, val);
1717e360a8b4SSteve Glendinning 	if (ret < 0)
1718b052e073SSteve Glendinning 		goto done;
1719e0e474a8SSteve Glendinning 
1720bbd9f9eeSSteve Glendinning 	/* enable receiver to enable frame reception */
1721ec32115dSMing Lei 	smsc95xx_start_rx_path(dev, 1);
1722e0e474a8SSteve Glendinning 
1723e0e474a8SSteve Glendinning 	/* some wol options are enabled, so enter SUSPEND0 */
17241e1d7412SJoe Perches 	netdev_info(dev->net, "entering SUSPEND0 mode\n");
17253b9f7d8cSSteve Glendinning 	ret = smsc95xx_enter_suspend0(dev);
17263b9f7d8cSSteve Glendinning 
17273b9f7d8cSSteve Glendinning done:
17280d41be53SMing Lei 	/*
17290d41be53SMing Lei 	 * TODO: resume() might need to handle the suspend failure
17300d41be53SMing Lei 	 * in system sleep
17310d41be53SMing Lei 	 */
17320d41be53SMing Lei 	if (ret && PMSG_IS_AUTO(message))
17333b9f7d8cSSteve Glendinning 		usbnet_resume(intf);
17347b900eadSFrieder Schrempf 
17353b9f7d8cSSteve Glendinning 	return ret;
1736e0e474a8SSteve Glendinning }
1737e0e474a8SSteve Glendinning 
1738e0e474a8SSteve Glendinning static int smsc95xx_resume(struct usb_interface *intf)
1739e0e474a8SSteve Glendinning {
1740e0e474a8SSteve Glendinning 	struct usbnet *dev = usb_get_intfdata(intf);
17418bca81d9SSudip Mukherjee 	struct smsc95xx_priv *pdata;
17428bca81d9SSudip Mukherjee 	u8 suspend_flags;
1743e0e474a8SSteve Glendinning 	int ret;
1744e0e474a8SSteve Glendinning 	u32 val;
1745e0e474a8SSteve Glendinning 
1746e0e474a8SSteve Glendinning 	BUG_ON(!dev);
1747ad90a73fSAndre Edich 	pdata = dev->driver_priv;
17488bca81d9SSudip Mukherjee 	suspend_flags = pdata->suspend_flags;
1749e0e474a8SSteve Glendinning 
1750b2d4b150SSteve Glendinning 	netdev_dbg(dev->net, "resume suspend_flags=0x%02x\n", suspend_flags);
1751b2d4b150SSteve Glendinning 
1752b2d4b150SSteve Glendinning 	/* do this first to ensure it's cleared even in error case */
1753b2d4b150SSteve Glendinning 	pdata->suspend_flags = 0;
1754b2d4b150SSteve Glendinning 
1755b2d4b150SSteve Glendinning 	if (suspend_flags & SUSPEND_ALLMODES) {
1756bbd9f9eeSSteve Glendinning 		/* clear wake-up sources */
1757ec32115dSMing Lei 		ret = smsc95xx_read_reg_nopm(dev, WUCSR, &val);
1758e360a8b4SSteve Glendinning 		if (ret < 0)
1759b052e073SSteve Glendinning 			return ret;
1760e0e474a8SSteve Glendinning 
1761bbd9f9eeSSteve Glendinning 		val &= ~(WUCSR_WAKE_EN_ | WUCSR_MPEN_);
1762e0e474a8SSteve Glendinning 
1763ec32115dSMing Lei 		ret = smsc95xx_write_reg_nopm(dev, WUCSR, val);
1764e360a8b4SSteve Glendinning 		if (ret < 0)
1765b052e073SSteve Glendinning 			return ret;
1766e0e474a8SSteve Glendinning 
1767e0e474a8SSteve Glendinning 		/* clear wake-up status */
1768ec32115dSMing Lei 		ret = smsc95xx_read_reg_nopm(dev, PM_CTRL, &val);
1769e360a8b4SSteve Glendinning 		if (ret < 0)
1770b052e073SSteve Glendinning 			return ret;
1771e0e474a8SSteve Glendinning 
1772e0e474a8SSteve Glendinning 		val &= ~PM_CTL_WOL_EN_;
1773e0e474a8SSteve Glendinning 		val |= PM_CTL_WUPS_;
1774e0e474a8SSteve Glendinning 
1775ec32115dSMing Lei 		ret = smsc95xx_write_reg_nopm(dev, PM_CTRL, val);
1776e360a8b4SSteve Glendinning 		if (ret < 0)
1777b052e073SSteve Glendinning 			return ret;
1778b052e073SSteve Glendinning 	}
1779e0e474a8SSteve Glendinning 
17801ce8b372SLukas Wunner 	phy_init_hw(pdata->phydev);
17811ce8b372SLukas Wunner 
1782af3d7c1eSSteve Glendinning 	ret = usbnet_resume(intf);
1783b052e073SSteve Glendinning 	if (ret < 0)
1784b052e073SSteve Glendinning 		netdev_warn(dev->net, "usbnet_resume error\n");
1785e0e474a8SSteve Glendinning 
1786b052e073SSteve Glendinning 	return ret;
1787e0e474a8SSteve Glendinning }
1788e0e474a8SSteve Glendinning 
1789b4df480fSJoonyoung Shim static int smsc95xx_reset_resume(struct usb_interface *intf)
1790b4df480fSJoonyoung Shim {
1791b4df480fSJoonyoung Shim 	struct usbnet *dev = usb_get_intfdata(intf);
1792b4df480fSJoonyoung Shim 	int ret;
1793b4df480fSJoonyoung Shim 
1794b4df480fSJoonyoung Shim 	ret = smsc95xx_reset(dev);
1795b4df480fSJoonyoung Shim 	if (ret < 0)
1796b4df480fSJoonyoung Shim 		return ret;
1797b4df480fSJoonyoung Shim 
1798b4df480fSJoonyoung Shim 	return smsc95xx_resume(intf);
1799b4df480fSJoonyoung Shim }
1800b4df480fSJoonyoung Shim 
18012f7ca802SSteve Glendinning static void smsc95xx_rx_csum_offload(struct sk_buff *skb)
18022f7ca802SSteve Glendinning {
18032f7ca802SSteve Glendinning 	skb->csum = *(u16 *)(skb_tail_pointer(skb) - 2);
18042f7ca802SSteve Glendinning 	skb->ip_summed = CHECKSUM_COMPLETE;
18052f7ca802SSteve Glendinning 	skb_trim(skb, skb->len - 2);
18062f7ca802SSteve Glendinning }
18072f7ca802SSteve Glendinning 
18082f7ca802SSteve Glendinning static int smsc95xx_rx_fixup(struct usbnet *dev, struct sk_buff *skb)
18092f7ca802SSteve Glendinning {
1810eb85569fSEmil Goode 	/* This check is no longer done by usbnet */
1811eb85569fSEmil Goode 	if (skb->len < dev->net->hard_header_len)
1812eb85569fSEmil Goode 		return 0;
1813eb85569fSEmil Goode 
18142f7ca802SSteve Glendinning 	while (skb->len > 0) {
18152f7ca802SSteve Glendinning 		u32 header, align_count;
18162f7ca802SSteve Glendinning 		struct sk_buff *ax_skb;
18172f7ca802SSteve Glendinning 		unsigned char *packet;
18182f7ca802SSteve Glendinning 		u16 size;
18192f7ca802SSteve Glendinning 
18206809d216SBen Dooks 		header = get_unaligned_le32(skb->data);
18212f7ca802SSteve Glendinning 		skb_pull(skb, 4 + NET_IP_ALIGN);
18222f7ca802SSteve Glendinning 		packet = skb->data;
18232f7ca802SSteve Glendinning 
18242f7ca802SSteve Glendinning 		/* get the packet length */
18252f7ca802SSteve Glendinning 		size = (u16)((header & RX_STS_FL_) >> 16);
18262f7ca802SSteve Glendinning 		align_count = (4 - ((size + NET_IP_ALIGN) % 4)) % 4;
18272f7ca802SSteve Glendinning 
18282f7ca802SSteve Glendinning 		if (unlikely(header & RX_STS_ES_)) {
1829a475f603SJoe Perches 			netif_dbg(dev, rx_err, dev->net,
1830a475f603SJoe Perches 				  "Error header=0x%08x\n", header);
183180667ac1SHerbert Xu 			dev->net->stats.rx_errors++;
183280667ac1SHerbert Xu 			dev->net->stats.rx_dropped++;
18332f7ca802SSteve Glendinning 
18342f7ca802SSteve Glendinning 			if (header & RX_STS_CRC_) {
183580667ac1SHerbert Xu 				dev->net->stats.rx_crc_errors++;
18362f7ca802SSteve Glendinning 			} else {
18372f7ca802SSteve Glendinning 				if (header & (RX_STS_TL_ | RX_STS_RF_))
183880667ac1SHerbert Xu 					dev->net->stats.rx_frame_errors++;
18392f7ca802SSteve Glendinning 
18402f7ca802SSteve Glendinning 				if ((header & RX_STS_LE_) &&
18412f7ca802SSteve Glendinning 					(!(header & RX_STS_FT_)))
184280667ac1SHerbert Xu 					dev->net->stats.rx_length_errors++;
18432f7ca802SSteve Glendinning 			}
18442f7ca802SSteve Glendinning 		} else {
18452f7ca802SSteve Glendinning 			/* ETH_FRAME_LEN + 4(CRC) + 2(COE) + 4(Vlan) */
18462f7ca802SSteve Glendinning 			if (unlikely(size > (ETH_FRAME_LEN + 12))) {
1847a475f603SJoe Perches 				netif_dbg(dev, rx_err, dev->net,
1848a475f603SJoe Perches 					  "size err header=0x%08x\n", header);
18492f7ca802SSteve Glendinning 				return 0;
18502f7ca802SSteve Glendinning 			}
18512f7ca802SSteve Glendinning 
18522f7ca802SSteve Glendinning 			/* last frame in this batch */
18532f7ca802SSteve Glendinning 			if (skb->len == size) {
185478e47fe4SMichał Mirosław 				if (dev->net->features & NETIF_F_RXCSUM)
18552f7ca802SSteve Glendinning 					smsc95xx_rx_csum_offload(skb);
1856df18accaSPeter Korsgaard 				skb_trim(skb, skb->len - 4); /* remove fcs */
18572f7ca802SSteve Glendinning 				skb->truesize = size + sizeof(struct sk_buff);
18582f7ca802SSteve Glendinning 
18592f7ca802SSteve Glendinning 				return 1;
18602f7ca802SSteve Glendinning 			}
18612f7ca802SSteve Glendinning 
18622f7ca802SSteve Glendinning 			ax_skb = skb_clone(skb, GFP_ATOMIC);
18632f7ca802SSteve Glendinning 			if (unlikely(!ax_skb)) {
186460b86755SJoe Perches 				netdev_warn(dev->net, "Error allocating skb\n");
18652f7ca802SSteve Glendinning 				return 0;
18662f7ca802SSteve Glendinning 			}
18672f7ca802SSteve Glendinning 
18682f7ca802SSteve Glendinning 			ax_skb->len = size;
18692f7ca802SSteve Glendinning 			ax_skb->data = packet;
18702f7ca802SSteve Glendinning 			skb_set_tail_pointer(ax_skb, size);
18712f7ca802SSteve Glendinning 
187278e47fe4SMichał Mirosław 			if (dev->net->features & NETIF_F_RXCSUM)
18732f7ca802SSteve Glendinning 				smsc95xx_rx_csum_offload(ax_skb);
1874df18accaSPeter Korsgaard 			skb_trim(ax_skb, ax_skb->len - 4); /* remove fcs */
18752f7ca802SSteve Glendinning 			ax_skb->truesize = size + sizeof(struct sk_buff);
18762f7ca802SSteve Glendinning 
18772f7ca802SSteve Glendinning 			usbnet_skb_return(dev, ax_skb);
18782f7ca802SSteve Glendinning 		}
18792f7ca802SSteve Glendinning 
18802f7ca802SSteve Glendinning 		skb_pull(skb, size);
18812f7ca802SSteve Glendinning 
18822f7ca802SSteve Glendinning 		/* padding bytes before the next frame starts */
18832f7ca802SSteve Glendinning 		if (skb->len)
18842f7ca802SSteve Glendinning 			skb_pull(skb, align_count);
18852f7ca802SSteve Glendinning 	}
18862f7ca802SSteve Glendinning 
18872f7ca802SSteve Glendinning 	return 1;
18882f7ca802SSteve Glendinning }
18892f7ca802SSteve Glendinning 
1890f7b29271SSteve Glendinning static u32 smsc95xx_calc_csum_preamble(struct sk_buff *skb)
1891f7b29271SSteve Glendinning {
189255508d60SMichał Mirosław 	u16 low_16 = (u16)skb_checksum_start_offset(skb);
189355508d60SMichał Mirosław 	u16 high_16 = low_16 + skb->csum_offset;
1894f7b29271SSteve Glendinning 	return (high_16 << 16) | low_16;
1895f7b29271SSteve Glendinning }
1896f7b29271SSteve Glendinning 
189775938f77SBen Dooks /* The TX CSUM won't work if the checksum lies in the last 4 bytes of the
189875938f77SBen Dooks  * transmission. This is fairly unlikely, only seems to trigger with some
189975938f77SBen Dooks  * short TCP ACK packets sent.
190075938f77SBen Dooks  *
190175938f77SBen Dooks  * Note, this calculation should probably check for the alignment of the
190275938f77SBen Dooks  * data as well, but a straight check for csum being in the last four bytes
190375938f77SBen Dooks  * of the packet should be ok for now.
190475938f77SBen Dooks  */
190575938f77SBen Dooks static bool smsc95xx_can_tx_checksum(struct sk_buff *skb)
190675938f77SBen Dooks {
190775938f77SBen Dooks        unsigned int len = skb->len - skb_checksum_start_offset(skb);
190875938f77SBen Dooks 
190975938f77SBen Dooks        if (skb->len <= 45)
191075938f77SBen Dooks 	       return false;
191175938f77SBen Dooks        return skb->csum_offset < (len - (4 + 1));
191275938f77SBen Dooks }
191375938f77SBen Dooks 
19142f7ca802SSteve Glendinning static struct sk_buff *smsc95xx_tx_fixup(struct usbnet *dev,
19152f7ca802SSteve Glendinning 					 struct sk_buff *skb, gfp_t flags)
19162f7ca802SSteve Glendinning {
191778e47fe4SMichał Mirosław 	bool csum = skb->ip_summed == CHECKSUM_PARTIAL;
1918f7b29271SSteve Glendinning 	int overhead = csum ? SMSC95XX_TX_OVERHEAD_CSUM : SMSC95XX_TX_OVERHEAD;
19192f7ca802SSteve Glendinning 	u32 tx_cmd_a, tx_cmd_b;
19200c8b2655SBen Dooks 	void *ptr;
19212f7ca802SSteve Glendinning 
1922f7b29271SSteve Glendinning 	/* We do not advertise SG, so skbs should be already linearized */
1923f7b29271SSteve Glendinning 	BUG_ON(skb_shinfo(skb)->nr_frags);
1924f7b29271SSteve Glendinning 
1925e9156cd2SJames Hughes 	/* Make writable and expand header space by overhead if required */
1926e9156cd2SJames Hughes 	if (skb_cow_head(skb, overhead)) {
1927e9156cd2SJames Hughes 		/* Must deallocate here as returning NULL to indicate error
1928e9156cd2SJames Hughes 		 * means the skb won't be deallocated in the caller.
1929e9156cd2SJames Hughes 		 */
19302f7ca802SSteve Glendinning 		dev_kfree_skb_any(skb);
19312f7ca802SSteve Glendinning 		return NULL;
19322f7ca802SSteve Glendinning 	}
19332f7ca802SSteve Glendinning 
19340c8b2655SBen Dooks 	tx_cmd_b = (u32)skb->len;
19350c8b2655SBen Dooks 	tx_cmd_a = tx_cmd_b | TX_CMD_A_FIRST_SEG_ | TX_CMD_A_LAST_SEG_;
19360c8b2655SBen Dooks 
1937f7b29271SSteve Glendinning 	if (csum) {
193875938f77SBen Dooks 		if (!smsc95xx_can_tx_checksum(skb)) {
193911bc3088SSteve Glendinning 			/* workaround - hardware tx checksum does not work
194011bc3088SSteve Glendinning 			 * properly with extremely small packets */
194155508d60SMichał Mirosław 			long csstart = skb_checksum_start_offset(skb);
194211bc3088SSteve Glendinning 			__wsum calc = csum_partial(skb->data + csstart,
194311bc3088SSteve Glendinning 				skb->len - csstart, 0);
194411bc3088SSteve Glendinning 			*((__sum16 *)(skb->data + csstart
194511bc3088SSteve Glendinning 				+ skb->csum_offset)) = csum_fold(calc);
194611bc3088SSteve Glendinning 
194711bc3088SSteve Glendinning 			csum = false;
194811bc3088SSteve Glendinning 		} else {
1949f7b29271SSteve Glendinning 			u32 csum_preamble = smsc95xx_calc_csum_preamble(skb);
19500c8b2655SBen Dooks 			ptr = skb_push(skb, 4);
19510c8b2655SBen Dooks 			put_unaligned_le32(csum_preamble, ptr);
1952f7b29271SSteve Glendinning 
19530c8b2655SBen Dooks 			tx_cmd_a += 4;
19540c8b2655SBen Dooks 			tx_cmd_b += 4;
1955f7b29271SSteve Glendinning 			tx_cmd_b |= TX_CMD_B_CSUM_ENABLE;
19560c8b2655SBen Dooks 		}
19570c8b2655SBen Dooks 	}
19582f7ca802SSteve Glendinning 
19590c8b2655SBen Dooks 	ptr = skb_push(skb, 8);
19600c8b2655SBen Dooks 	put_unaligned_le32(tx_cmd_a, ptr);
19610c8b2655SBen Dooks 	put_unaligned_le32(tx_cmd_b, ptr+4);
19622f7ca802SSteve Glendinning 
19632f7ca802SSteve Glendinning 	return skb;
19642f7ca802SSteve Glendinning }
19652f7ca802SSteve Glendinning 
1966b2d4b150SSteve Glendinning static int smsc95xx_manage_power(struct usbnet *dev, int on)
1967b2d4b150SSteve Glendinning {
1968ad90a73fSAndre Edich 	struct smsc95xx_priv *pdata = dev->driver_priv;
1969b2d4b150SSteve Glendinning 
1970b2d4b150SSteve Glendinning 	dev->intf->needs_remote_wakeup = on;
1971b2d4b150SSteve Glendinning 
1972eb970ff0SMing Lei 	if (pdata->features & FEATURE_REMOTE_WAKEUP)
1973b2d4b150SSteve Glendinning 		return 0;
1974b2d4b150SSteve Glendinning 
1975eb970ff0SMing Lei 	/* this chip revision isn't capable of remote wakeup */
1976eb970ff0SMing Lei 	netdev_info(dev->net, "hardware isn't capable of remote wakeup\n");
1977b2d4b150SSteve Glendinning 
1978b2d4b150SSteve Glendinning 	if (on)
1979b2d4b150SSteve Glendinning 		usb_autopm_get_interface_no_resume(dev->intf);
1980b2d4b150SSteve Glendinning 	else
1981b2d4b150SSteve Glendinning 		usb_autopm_put_interface(dev->intf);
1982b2d4b150SSteve Glendinning 
1983b2d4b150SSteve Glendinning 	return 0;
1984b2d4b150SSteve Glendinning }
1985b2d4b150SSteve Glendinning 
19862f7ca802SSteve Glendinning static const struct driver_info smsc95xx_info = {
19872f7ca802SSteve Glendinning 	.description	= "smsc95xx USB 2.0 Ethernet",
19882f7ca802SSteve Glendinning 	.bind		= smsc95xx_bind,
19892f7ca802SSteve Glendinning 	.unbind		= smsc95xx_unbind,
19900bf38853SMarkus Reichl 	.reset		= smsc95xx_reset,
19910bf38853SMarkus Reichl 	.check_connect	= smsc95xx_start_phy,
1992a049a30fSMartyn Welch 	.stop		= smsc95xx_stop,
19932f7ca802SSteve Glendinning 	.rx_fixup	= smsc95xx_rx_fixup,
19942f7ca802SSteve Glendinning 	.tx_fixup	= smsc95xx_tx_fixup,
19952f7ca802SSteve Glendinning 	.status		= smsc95xx_status,
1996b2d4b150SSteve Glendinning 	.manage_power	= smsc95xx_manage_power,
199707d69d42SPaolo Pisati 	.flags		= FLAG_ETHER | FLAG_SEND_ZLP | FLAG_LINK_INTR,
19982f7ca802SSteve Glendinning };
19992f7ca802SSteve Glendinning 
20002f7ca802SSteve Glendinning static const struct usb_device_id products[] = {
20012f7ca802SSteve Glendinning 	{
20022f7ca802SSteve Glendinning 		/* SMSC9500 USB Ethernet Device */
20032f7ca802SSteve Glendinning 		USB_DEVICE(0x0424, 0x9500),
20042f7ca802SSteve Glendinning 		.driver_info = (unsigned long) &smsc95xx_info,
20052f7ca802SSteve Glendinning 	},
2006726474b8SSteve Glendinning 	{
20076f41d12bSSteve Glendinning 		/* SMSC9505 USB Ethernet Device */
20086f41d12bSSteve Glendinning 		USB_DEVICE(0x0424, 0x9505),
20096f41d12bSSteve Glendinning 		.driver_info = (unsigned long) &smsc95xx_info,
20106f41d12bSSteve Glendinning 	},
20116f41d12bSSteve Glendinning 	{
20126f41d12bSSteve Glendinning 		/* SMSC9500A USB Ethernet Device */
20136f41d12bSSteve Glendinning 		USB_DEVICE(0x0424, 0x9E00),
20146f41d12bSSteve Glendinning 		.driver_info = (unsigned long) &smsc95xx_info,
20156f41d12bSSteve Glendinning 	},
20166f41d12bSSteve Glendinning 	{
20176f41d12bSSteve Glendinning 		/* SMSC9505A USB Ethernet Device */
20186f41d12bSSteve Glendinning 		USB_DEVICE(0x0424, 0x9E01),
20196f41d12bSSteve Glendinning 		.driver_info = (unsigned long) &smsc95xx_info,
20206f41d12bSSteve Glendinning 	},
20216f41d12bSSteve Glendinning 	{
2022726474b8SSteve Glendinning 		/* SMSC9512/9514 USB Hub & Ethernet Device */
2023726474b8SSteve Glendinning 		USB_DEVICE(0x0424, 0xec00),
2024726474b8SSteve Glendinning 		.driver_info = (unsigned long) &smsc95xx_info,
2025726474b8SSteve Glendinning 	},
20266f41d12bSSteve Glendinning 	{
20276f41d12bSSteve Glendinning 		/* SMSC9500 USB Ethernet Device (SAL10) */
20286f41d12bSSteve Glendinning 		USB_DEVICE(0x0424, 0x9900),
20296f41d12bSSteve Glendinning 		.driver_info = (unsigned long) &smsc95xx_info,
20306f41d12bSSteve Glendinning 	},
20316f41d12bSSteve Glendinning 	{
20326f41d12bSSteve Glendinning 		/* SMSC9505 USB Ethernet Device (SAL10) */
20336f41d12bSSteve Glendinning 		USB_DEVICE(0x0424, 0x9901),
20346f41d12bSSteve Glendinning 		.driver_info = (unsigned long) &smsc95xx_info,
20356f41d12bSSteve Glendinning 	},
20366f41d12bSSteve Glendinning 	{
20376f41d12bSSteve Glendinning 		/* SMSC9500A USB Ethernet Device (SAL10) */
20386f41d12bSSteve Glendinning 		USB_DEVICE(0x0424, 0x9902),
20396f41d12bSSteve Glendinning 		.driver_info = (unsigned long) &smsc95xx_info,
20406f41d12bSSteve Glendinning 	},
20416f41d12bSSteve Glendinning 	{
20426f41d12bSSteve Glendinning 		/* SMSC9505A USB Ethernet Device (SAL10) */
20436f41d12bSSteve Glendinning 		USB_DEVICE(0x0424, 0x9903),
20446f41d12bSSteve Glendinning 		.driver_info = (unsigned long) &smsc95xx_info,
20456f41d12bSSteve Glendinning 	},
20466f41d12bSSteve Glendinning 	{
20476f41d12bSSteve Glendinning 		/* SMSC9512/9514 USB Hub & Ethernet Device (SAL10) */
20486f41d12bSSteve Glendinning 		USB_DEVICE(0x0424, 0x9904),
20496f41d12bSSteve Glendinning 		.driver_info = (unsigned long) &smsc95xx_info,
20506f41d12bSSteve Glendinning 	},
20516f41d12bSSteve Glendinning 	{
20526f41d12bSSteve Glendinning 		/* SMSC9500A USB Ethernet Device (HAL) */
20536f41d12bSSteve Glendinning 		USB_DEVICE(0x0424, 0x9905),
20546f41d12bSSteve Glendinning 		.driver_info = (unsigned long) &smsc95xx_info,
20556f41d12bSSteve Glendinning 	},
20566f41d12bSSteve Glendinning 	{
20576f41d12bSSteve Glendinning 		/* SMSC9505A USB Ethernet Device (HAL) */
20586f41d12bSSteve Glendinning 		USB_DEVICE(0x0424, 0x9906),
20596f41d12bSSteve Glendinning 		.driver_info = (unsigned long) &smsc95xx_info,
20606f41d12bSSteve Glendinning 	},
20616f41d12bSSteve Glendinning 	{
20626f41d12bSSteve Glendinning 		/* SMSC9500 USB Ethernet Device (Alternate ID) */
20636f41d12bSSteve Glendinning 		USB_DEVICE(0x0424, 0x9907),
20646f41d12bSSteve Glendinning 		.driver_info = (unsigned long) &smsc95xx_info,
20656f41d12bSSteve Glendinning 	},
20666f41d12bSSteve Glendinning 	{
20676f41d12bSSteve Glendinning 		/* SMSC9500A USB Ethernet Device (Alternate ID) */
20686f41d12bSSteve Glendinning 		USB_DEVICE(0x0424, 0x9908),
20696f41d12bSSteve Glendinning 		.driver_info = (unsigned long) &smsc95xx_info,
20706f41d12bSSteve Glendinning 	},
20716f41d12bSSteve Glendinning 	{
20726f41d12bSSteve Glendinning 		/* SMSC9512/9514 USB Hub & Ethernet Device (Alternate ID) */
20736f41d12bSSteve Glendinning 		USB_DEVICE(0x0424, 0x9909),
20746f41d12bSSteve Glendinning 		.driver_info = (unsigned long) &smsc95xx_info,
20756f41d12bSSteve Glendinning 	},
207688edaa41SSteve Glendinning 	{
207788edaa41SSteve Glendinning 		/* SMSC LAN9530 USB Ethernet Device */
207888edaa41SSteve Glendinning 		USB_DEVICE(0x0424, 0x9530),
207988edaa41SSteve Glendinning 		.driver_info = (unsigned long) &smsc95xx_info,
208088edaa41SSteve Glendinning 	},
208188edaa41SSteve Glendinning 	{
208288edaa41SSteve Glendinning 		/* SMSC LAN9730 USB Ethernet Device */
208388edaa41SSteve Glendinning 		USB_DEVICE(0x0424, 0x9730),
208488edaa41SSteve Glendinning 		.driver_info = (unsigned long) &smsc95xx_info,
208588edaa41SSteve Glendinning 	},
208688edaa41SSteve Glendinning 	{
208788edaa41SSteve Glendinning 		/* SMSC LAN89530 USB Ethernet Device */
208888edaa41SSteve Glendinning 		USB_DEVICE(0x0424, 0x9E08),
208988edaa41SSteve Glendinning 		.driver_info = (unsigned long) &smsc95xx_info,
209088edaa41SSteve Glendinning 	},
2091*4066bf4cSParthiban Veerasooran 	{
2092*4066bf4cSParthiban Veerasooran 		/* Microchip's EVB-LAN8670-USB 10BASE-T1S Ethernet Device */
2093*4066bf4cSParthiban Veerasooran 		USB_DEVICE(0x184F, 0x0051),
2094*4066bf4cSParthiban Veerasooran 		.driver_info = (unsigned long)&smsc95xx_info,
2095*4066bf4cSParthiban Veerasooran 	},
20962f7ca802SSteve Glendinning 	{ },		/* END */
20972f7ca802SSteve Glendinning };
20982f7ca802SSteve Glendinning MODULE_DEVICE_TABLE(usb, products);
20992f7ca802SSteve Glendinning 
21002f7ca802SSteve Glendinning static struct usb_driver smsc95xx_driver = {
21012f7ca802SSteve Glendinning 	.name		= "smsc95xx",
21022f7ca802SSteve Glendinning 	.id_table	= products,
21032f7ca802SSteve Glendinning 	.probe		= usbnet_probe,
2104b5a04475SSteve Glendinning 	.suspend	= smsc95xx_suspend,
2105e0e474a8SSteve Glendinning 	.resume		= smsc95xx_resume,
2106b4df480fSJoonyoung Shim 	.reset_resume	= smsc95xx_reset_resume,
21072f7ca802SSteve Glendinning 	.disconnect	= usbnet_disconnect,
2108e1f12eb6SSarah Sharp 	.disable_hub_initiated_lpm = 1,
2109b2d4b150SSteve Glendinning 	.supports_autosuspend = 1,
21102f7ca802SSteve Glendinning };
21112f7ca802SSteve Glendinning 
2112d632eb1bSGreg Kroah-Hartman module_usb_driver(smsc95xx_driver);
21132f7ca802SSteve Glendinning 
21142f7ca802SSteve Glendinning MODULE_AUTHOR("Nancy Lin");
211590b24cfbSSteve Glendinning MODULE_AUTHOR("Steve Glendinning <steve.glendinning@shawell.net>");
21162f7ca802SSteve Glendinning MODULE_DESCRIPTION("SMSC95XX USB 2.0 Ethernet Devices");
21172f7ca802SSteve Glendinning MODULE_LICENSE("GPL");
2118