18c2ecf20Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0-or-later
28c2ecf20Sopenharmony_ci/*
38c2ecf20Sopenharmony_ci * ASIX AX88179/178A USB 3.0/2.0 to Gigabit Ethernet Devices
48c2ecf20Sopenharmony_ci *
58c2ecf20Sopenharmony_ci * Copyright (C) 2011-2013 ASIX
68c2ecf20Sopenharmony_ci */
78c2ecf20Sopenharmony_ci
88c2ecf20Sopenharmony_ci#include <linux/module.h>
98c2ecf20Sopenharmony_ci#include <linux/etherdevice.h>
108c2ecf20Sopenharmony_ci#include <linux/mii.h>
118c2ecf20Sopenharmony_ci#include <linux/usb.h>
128c2ecf20Sopenharmony_ci#include <linux/crc32.h>
138c2ecf20Sopenharmony_ci#include <linux/usb/usbnet.h>
148c2ecf20Sopenharmony_ci#include <uapi/linux/mdio.h>
158c2ecf20Sopenharmony_ci#include <linux/mdio.h>
168c2ecf20Sopenharmony_ci
178c2ecf20Sopenharmony_ci#define AX88179_PHY_ID				0x03
188c2ecf20Sopenharmony_ci#define AX_EEPROM_LEN				0x100
198c2ecf20Sopenharmony_ci#define AX88179_EEPROM_MAGIC			0x17900b95
208c2ecf20Sopenharmony_ci#define AX_MCAST_FLTSIZE			8
218c2ecf20Sopenharmony_ci#define AX_MAX_MCAST				64
228c2ecf20Sopenharmony_ci#define AX_INT_PPLS_LINK			((u32)BIT(16))
238c2ecf20Sopenharmony_ci#define AX_RXHDR_L4_TYPE_MASK			0x1c
248c2ecf20Sopenharmony_ci#define AX_RXHDR_L4_TYPE_UDP			4
258c2ecf20Sopenharmony_ci#define AX_RXHDR_L4_TYPE_TCP			16
268c2ecf20Sopenharmony_ci#define AX_RXHDR_L3CSUM_ERR			2
278c2ecf20Sopenharmony_ci#define AX_RXHDR_L4CSUM_ERR			1
288c2ecf20Sopenharmony_ci#define AX_RXHDR_CRC_ERR			((u32)BIT(29))
298c2ecf20Sopenharmony_ci#define AX_RXHDR_DROP_ERR			((u32)BIT(31))
308c2ecf20Sopenharmony_ci#define AX_ACCESS_MAC				0x01
318c2ecf20Sopenharmony_ci#define AX_ACCESS_PHY				0x02
328c2ecf20Sopenharmony_ci#define AX_ACCESS_EEPROM			0x04
338c2ecf20Sopenharmony_ci#define AX_ACCESS_EFUS				0x05
348c2ecf20Sopenharmony_ci#define AX_RELOAD_EEPROM_EFUSE			0x06
358c2ecf20Sopenharmony_ci#define AX_PAUSE_WATERLVL_HIGH			0x54
368c2ecf20Sopenharmony_ci#define AX_PAUSE_WATERLVL_LOW			0x55
378c2ecf20Sopenharmony_ci
388c2ecf20Sopenharmony_ci#define PHYSICAL_LINK_STATUS			0x02
398c2ecf20Sopenharmony_ci	#define	AX_USB_SS		0x04
408c2ecf20Sopenharmony_ci	#define	AX_USB_HS		0x02
418c2ecf20Sopenharmony_ci
428c2ecf20Sopenharmony_ci#define GENERAL_STATUS				0x03
438c2ecf20Sopenharmony_ci/* Check AX88179 version. UA1:Bit2 = 0,  UA2:Bit2 = 1 */
448c2ecf20Sopenharmony_ci	#define	AX_SECLD		0x04
458c2ecf20Sopenharmony_ci
468c2ecf20Sopenharmony_ci#define AX_SROM_ADDR				0x07
478c2ecf20Sopenharmony_ci#define AX_SROM_CMD				0x0a
488c2ecf20Sopenharmony_ci	#define EEP_RD			0x04
498c2ecf20Sopenharmony_ci	#define EEP_BUSY		0x10
508c2ecf20Sopenharmony_ci
518c2ecf20Sopenharmony_ci#define AX_SROM_DATA_LOW			0x08
528c2ecf20Sopenharmony_ci#define AX_SROM_DATA_HIGH			0x09
538c2ecf20Sopenharmony_ci
548c2ecf20Sopenharmony_ci#define AX_RX_CTL				0x0b
558c2ecf20Sopenharmony_ci	#define AX_RX_CTL_DROPCRCERR	0x0100
568c2ecf20Sopenharmony_ci	#define AX_RX_CTL_IPE		0x0200
578c2ecf20Sopenharmony_ci	#define AX_RX_CTL_START		0x0080
588c2ecf20Sopenharmony_ci	#define AX_RX_CTL_AP		0x0020
598c2ecf20Sopenharmony_ci	#define AX_RX_CTL_AM		0x0010
608c2ecf20Sopenharmony_ci	#define AX_RX_CTL_AB		0x0008
618c2ecf20Sopenharmony_ci	#define AX_RX_CTL_AMALL		0x0002
628c2ecf20Sopenharmony_ci	#define AX_RX_CTL_PRO		0x0001
638c2ecf20Sopenharmony_ci	#define AX_RX_CTL_STOP		0x0000
648c2ecf20Sopenharmony_ci
658c2ecf20Sopenharmony_ci#define AX_NODE_ID				0x10
668c2ecf20Sopenharmony_ci#define AX_MULFLTARY				0x16
678c2ecf20Sopenharmony_ci
688c2ecf20Sopenharmony_ci#define AX_MEDIUM_STATUS_MODE			0x22
698c2ecf20Sopenharmony_ci	#define AX_MEDIUM_GIGAMODE	0x01
708c2ecf20Sopenharmony_ci	#define AX_MEDIUM_FULL_DUPLEX	0x02
718c2ecf20Sopenharmony_ci	#define AX_MEDIUM_EN_125MHZ	0x08
728c2ecf20Sopenharmony_ci	#define AX_MEDIUM_RXFLOW_CTRLEN	0x10
738c2ecf20Sopenharmony_ci	#define AX_MEDIUM_TXFLOW_CTRLEN	0x20
748c2ecf20Sopenharmony_ci	#define AX_MEDIUM_RECEIVE_EN	0x100
758c2ecf20Sopenharmony_ci	#define AX_MEDIUM_PS		0x200
768c2ecf20Sopenharmony_ci	#define AX_MEDIUM_JUMBO_EN	0x8040
778c2ecf20Sopenharmony_ci
788c2ecf20Sopenharmony_ci#define AX_MONITOR_MOD				0x24
798c2ecf20Sopenharmony_ci	#define AX_MONITOR_MODE_RWLC	0x02
808c2ecf20Sopenharmony_ci	#define AX_MONITOR_MODE_RWMP	0x04
818c2ecf20Sopenharmony_ci	#define AX_MONITOR_MODE_PMEPOL	0x20
828c2ecf20Sopenharmony_ci	#define AX_MONITOR_MODE_PMETYPE	0x40
838c2ecf20Sopenharmony_ci
848c2ecf20Sopenharmony_ci#define AX_GPIO_CTRL				0x25
858c2ecf20Sopenharmony_ci	#define AX_GPIO_CTRL_GPIO3EN	0x80
868c2ecf20Sopenharmony_ci	#define AX_GPIO_CTRL_GPIO2EN	0x40
878c2ecf20Sopenharmony_ci	#define AX_GPIO_CTRL_GPIO1EN	0x20
888c2ecf20Sopenharmony_ci
898c2ecf20Sopenharmony_ci#define AX_PHYPWR_RSTCTL			0x26
908c2ecf20Sopenharmony_ci	#define AX_PHYPWR_RSTCTL_BZ	0x0010
918c2ecf20Sopenharmony_ci	#define AX_PHYPWR_RSTCTL_IPRL	0x0020
928c2ecf20Sopenharmony_ci	#define AX_PHYPWR_RSTCTL_AT	0x1000
938c2ecf20Sopenharmony_ci
948c2ecf20Sopenharmony_ci#define AX_RX_BULKIN_QCTRL			0x2e
958c2ecf20Sopenharmony_ci#define AX_CLK_SELECT				0x33
968c2ecf20Sopenharmony_ci	#define AX_CLK_SELECT_BCS	0x01
978c2ecf20Sopenharmony_ci	#define AX_CLK_SELECT_ACS	0x02
988c2ecf20Sopenharmony_ci	#define AX_CLK_SELECT_ULR	0x08
998c2ecf20Sopenharmony_ci
1008c2ecf20Sopenharmony_ci#define AX_RXCOE_CTL				0x34
1018c2ecf20Sopenharmony_ci	#define AX_RXCOE_IP		0x01
1028c2ecf20Sopenharmony_ci	#define AX_RXCOE_TCP		0x02
1038c2ecf20Sopenharmony_ci	#define AX_RXCOE_UDP		0x04
1048c2ecf20Sopenharmony_ci	#define AX_RXCOE_TCPV6		0x20
1058c2ecf20Sopenharmony_ci	#define AX_RXCOE_UDPV6		0x40
1068c2ecf20Sopenharmony_ci
1078c2ecf20Sopenharmony_ci#define AX_TXCOE_CTL				0x35
1088c2ecf20Sopenharmony_ci	#define AX_TXCOE_IP		0x01
1098c2ecf20Sopenharmony_ci	#define AX_TXCOE_TCP		0x02
1108c2ecf20Sopenharmony_ci	#define AX_TXCOE_UDP		0x04
1118c2ecf20Sopenharmony_ci	#define AX_TXCOE_TCPV6		0x20
1128c2ecf20Sopenharmony_ci	#define AX_TXCOE_UDPV6		0x40
1138c2ecf20Sopenharmony_ci
1148c2ecf20Sopenharmony_ci#define AX_LEDCTRL				0x73
1158c2ecf20Sopenharmony_ci
1168c2ecf20Sopenharmony_ci#define GMII_PHY_PHYSR				0x11
1178c2ecf20Sopenharmony_ci	#define GMII_PHY_PHYSR_SMASK	0xc000
1188c2ecf20Sopenharmony_ci	#define GMII_PHY_PHYSR_GIGA	0x8000
1198c2ecf20Sopenharmony_ci	#define GMII_PHY_PHYSR_100	0x4000
1208c2ecf20Sopenharmony_ci	#define GMII_PHY_PHYSR_FULL	0x2000
1218c2ecf20Sopenharmony_ci	#define GMII_PHY_PHYSR_LINK	0x400
1228c2ecf20Sopenharmony_ci
1238c2ecf20Sopenharmony_ci#define GMII_LED_ACT				0x1a
1248c2ecf20Sopenharmony_ci	#define	GMII_LED_ACTIVE_MASK	0xff8f
1258c2ecf20Sopenharmony_ci	#define	GMII_LED0_ACTIVE	BIT(4)
1268c2ecf20Sopenharmony_ci	#define	GMII_LED1_ACTIVE	BIT(5)
1278c2ecf20Sopenharmony_ci	#define	GMII_LED2_ACTIVE	BIT(6)
1288c2ecf20Sopenharmony_ci
1298c2ecf20Sopenharmony_ci#define GMII_LED_LINK				0x1c
1308c2ecf20Sopenharmony_ci	#define	GMII_LED_LINK_MASK	0xf888
1318c2ecf20Sopenharmony_ci	#define	GMII_LED0_LINK_10	BIT(0)
1328c2ecf20Sopenharmony_ci	#define	GMII_LED0_LINK_100	BIT(1)
1338c2ecf20Sopenharmony_ci	#define	GMII_LED0_LINK_1000	BIT(2)
1348c2ecf20Sopenharmony_ci	#define	GMII_LED1_LINK_10	BIT(4)
1358c2ecf20Sopenharmony_ci	#define	GMII_LED1_LINK_100	BIT(5)
1368c2ecf20Sopenharmony_ci	#define	GMII_LED1_LINK_1000	BIT(6)
1378c2ecf20Sopenharmony_ci	#define	GMII_LED2_LINK_10	BIT(8)
1388c2ecf20Sopenharmony_ci	#define	GMII_LED2_LINK_100	BIT(9)
1398c2ecf20Sopenharmony_ci	#define	GMII_LED2_LINK_1000	BIT(10)
1408c2ecf20Sopenharmony_ci	#define	LED0_ACTIVE		BIT(0)
1418c2ecf20Sopenharmony_ci	#define	LED0_LINK_10		BIT(1)
1428c2ecf20Sopenharmony_ci	#define	LED0_LINK_100		BIT(2)
1438c2ecf20Sopenharmony_ci	#define	LED0_LINK_1000		BIT(3)
1448c2ecf20Sopenharmony_ci	#define	LED0_FD			BIT(4)
1458c2ecf20Sopenharmony_ci	#define	LED0_USB3_MASK		0x001f
1468c2ecf20Sopenharmony_ci	#define	LED1_ACTIVE		BIT(5)
1478c2ecf20Sopenharmony_ci	#define	LED1_LINK_10		BIT(6)
1488c2ecf20Sopenharmony_ci	#define	LED1_LINK_100		BIT(7)
1498c2ecf20Sopenharmony_ci	#define	LED1_LINK_1000		BIT(8)
1508c2ecf20Sopenharmony_ci	#define	LED1_FD			BIT(9)
1518c2ecf20Sopenharmony_ci	#define	LED1_USB3_MASK		0x03e0
1528c2ecf20Sopenharmony_ci	#define	LED2_ACTIVE		BIT(10)
1538c2ecf20Sopenharmony_ci	#define	LED2_LINK_1000		BIT(13)
1548c2ecf20Sopenharmony_ci	#define	LED2_LINK_100		BIT(12)
1558c2ecf20Sopenharmony_ci	#define	LED2_LINK_10		BIT(11)
1568c2ecf20Sopenharmony_ci	#define	LED2_FD			BIT(14)
1578c2ecf20Sopenharmony_ci	#define	LED_VALID		BIT(15)
1588c2ecf20Sopenharmony_ci	#define	LED2_USB3_MASK		0x7c00
1598c2ecf20Sopenharmony_ci
1608c2ecf20Sopenharmony_ci#define GMII_PHYPAGE				0x1e
1618c2ecf20Sopenharmony_ci#define GMII_PHY_PAGE_SELECT			0x1f
1628c2ecf20Sopenharmony_ci	#define GMII_PHY_PGSEL_EXT	0x0007
1638c2ecf20Sopenharmony_ci	#define GMII_PHY_PGSEL_PAGE0	0x0000
1648c2ecf20Sopenharmony_ci	#define GMII_PHY_PGSEL_PAGE3	0x0003
1658c2ecf20Sopenharmony_ci	#define GMII_PHY_PGSEL_PAGE5	0x0005
1668c2ecf20Sopenharmony_ci
1678c2ecf20Sopenharmony_cistruct ax88179_data {
1688c2ecf20Sopenharmony_ci	u8  eee_enabled;
1698c2ecf20Sopenharmony_ci	u8  eee_active;
1708c2ecf20Sopenharmony_ci	u16 rxctl;
1718c2ecf20Sopenharmony_ci	u16 reserved;
1728c2ecf20Sopenharmony_ci};
1738c2ecf20Sopenharmony_ci
1748c2ecf20Sopenharmony_cistruct ax88179_int_data {
1758c2ecf20Sopenharmony_ci	__le32 intdata1;
1768c2ecf20Sopenharmony_ci	__le32 intdata2;
1778c2ecf20Sopenharmony_ci};
1788c2ecf20Sopenharmony_ci
1798c2ecf20Sopenharmony_cistatic const struct {
1808c2ecf20Sopenharmony_ci	unsigned char ctrl, timer_l, timer_h, size, ifg;
1818c2ecf20Sopenharmony_ci} AX88179_BULKIN_SIZE[] =	{
1828c2ecf20Sopenharmony_ci	{7, 0x4f, 0,	0x12, 0xff},
1838c2ecf20Sopenharmony_ci	{7, 0x20, 3,	0x16, 0xff},
1848c2ecf20Sopenharmony_ci	{7, 0xae, 7,	0x18, 0xff},
1858c2ecf20Sopenharmony_ci	{7, 0xcc, 0x4c, 0x18, 8},
1868c2ecf20Sopenharmony_ci};
1878c2ecf20Sopenharmony_ci
1888c2ecf20Sopenharmony_cistatic int __ax88179_read_cmd(struct usbnet *dev, u8 cmd, u16 value, u16 index,
1898c2ecf20Sopenharmony_ci			      u16 size, void *data, int in_pm)
1908c2ecf20Sopenharmony_ci{
1918c2ecf20Sopenharmony_ci	int ret;
1928c2ecf20Sopenharmony_ci	int (*fn)(struct usbnet *, u8, u8, u16, u16, void *, u16);
1938c2ecf20Sopenharmony_ci
1948c2ecf20Sopenharmony_ci	BUG_ON(!dev);
1958c2ecf20Sopenharmony_ci
1968c2ecf20Sopenharmony_ci	if (!in_pm)
1978c2ecf20Sopenharmony_ci		fn = usbnet_read_cmd;
1988c2ecf20Sopenharmony_ci	else
1998c2ecf20Sopenharmony_ci		fn = usbnet_read_cmd_nopm;
2008c2ecf20Sopenharmony_ci
2018c2ecf20Sopenharmony_ci	ret = fn(dev, cmd, USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
2028c2ecf20Sopenharmony_ci		 value, index, data, size);
2038c2ecf20Sopenharmony_ci
2048c2ecf20Sopenharmony_ci	if (unlikely(ret < 0))
2058c2ecf20Sopenharmony_ci		netdev_warn(dev->net, "Failed to read reg index 0x%04x: %d\n",
2068c2ecf20Sopenharmony_ci			    index, ret);
2078c2ecf20Sopenharmony_ci
2088c2ecf20Sopenharmony_ci	return ret;
2098c2ecf20Sopenharmony_ci}
2108c2ecf20Sopenharmony_ci
2118c2ecf20Sopenharmony_cistatic int __ax88179_write_cmd(struct usbnet *dev, u8 cmd, u16 value, u16 index,
2128c2ecf20Sopenharmony_ci			       u16 size, void *data, int in_pm)
2138c2ecf20Sopenharmony_ci{
2148c2ecf20Sopenharmony_ci	int ret;
2158c2ecf20Sopenharmony_ci	int (*fn)(struct usbnet *, u8, u8, u16, u16, const void *, u16);
2168c2ecf20Sopenharmony_ci
2178c2ecf20Sopenharmony_ci	BUG_ON(!dev);
2188c2ecf20Sopenharmony_ci
2198c2ecf20Sopenharmony_ci	if (!in_pm)
2208c2ecf20Sopenharmony_ci		fn = usbnet_write_cmd;
2218c2ecf20Sopenharmony_ci	else
2228c2ecf20Sopenharmony_ci		fn = usbnet_write_cmd_nopm;
2238c2ecf20Sopenharmony_ci
2248c2ecf20Sopenharmony_ci	ret = fn(dev, cmd, USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
2258c2ecf20Sopenharmony_ci		 value, index, data, size);
2268c2ecf20Sopenharmony_ci
2278c2ecf20Sopenharmony_ci	if (unlikely(ret < 0))
2288c2ecf20Sopenharmony_ci		netdev_warn(dev->net, "Failed to write reg index 0x%04x: %d\n",
2298c2ecf20Sopenharmony_ci			    index, ret);
2308c2ecf20Sopenharmony_ci
2318c2ecf20Sopenharmony_ci	return ret;
2328c2ecf20Sopenharmony_ci}
2338c2ecf20Sopenharmony_ci
2348c2ecf20Sopenharmony_cistatic void ax88179_write_cmd_async(struct usbnet *dev, u8 cmd, u16 value,
2358c2ecf20Sopenharmony_ci				    u16 index, u16 size, void *data)
2368c2ecf20Sopenharmony_ci{
2378c2ecf20Sopenharmony_ci	u16 buf;
2388c2ecf20Sopenharmony_ci
2398c2ecf20Sopenharmony_ci	if (2 == size) {
2408c2ecf20Sopenharmony_ci		buf = *((u16 *)data);
2418c2ecf20Sopenharmony_ci		cpu_to_le16s(&buf);
2428c2ecf20Sopenharmony_ci		usbnet_write_cmd_async(dev, cmd, USB_DIR_OUT | USB_TYPE_VENDOR |
2438c2ecf20Sopenharmony_ci				       USB_RECIP_DEVICE, value, index, &buf,
2448c2ecf20Sopenharmony_ci				       size);
2458c2ecf20Sopenharmony_ci	} else {
2468c2ecf20Sopenharmony_ci		usbnet_write_cmd_async(dev, cmd, USB_DIR_OUT | USB_TYPE_VENDOR |
2478c2ecf20Sopenharmony_ci				       USB_RECIP_DEVICE, value, index, data,
2488c2ecf20Sopenharmony_ci				       size);
2498c2ecf20Sopenharmony_ci	}
2508c2ecf20Sopenharmony_ci}
2518c2ecf20Sopenharmony_ci
2528c2ecf20Sopenharmony_cistatic int ax88179_read_cmd_nopm(struct usbnet *dev, u8 cmd, u16 value,
2538c2ecf20Sopenharmony_ci				 u16 index, u16 size, void *data)
2548c2ecf20Sopenharmony_ci{
2558c2ecf20Sopenharmony_ci	int ret;
2568c2ecf20Sopenharmony_ci
2578c2ecf20Sopenharmony_ci	if (2 == size) {
2588c2ecf20Sopenharmony_ci		u16 buf;
2598c2ecf20Sopenharmony_ci		ret = __ax88179_read_cmd(dev, cmd, value, index, size, &buf, 1);
2608c2ecf20Sopenharmony_ci		le16_to_cpus(&buf);
2618c2ecf20Sopenharmony_ci		*((u16 *)data) = buf;
2628c2ecf20Sopenharmony_ci	} else if (4 == size) {
2638c2ecf20Sopenharmony_ci		u32 buf;
2648c2ecf20Sopenharmony_ci		ret = __ax88179_read_cmd(dev, cmd, value, index, size, &buf, 1);
2658c2ecf20Sopenharmony_ci		le32_to_cpus(&buf);
2668c2ecf20Sopenharmony_ci		*((u32 *)data) = buf;
2678c2ecf20Sopenharmony_ci	} else {
2688c2ecf20Sopenharmony_ci		ret = __ax88179_read_cmd(dev, cmd, value, index, size, data, 1);
2698c2ecf20Sopenharmony_ci	}
2708c2ecf20Sopenharmony_ci
2718c2ecf20Sopenharmony_ci	return ret;
2728c2ecf20Sopenharmony_ci}
2738c2ecf20Sopenharmony_ci
2748c2ecf20Sopenharmony_cistatic int ax88179_write_cmd_nopm(struct usbnet *dev, u8 cmd, u16 value,
2758c2ecf20Sopenharmony_ci				  u16 index, u16 size, void *data)
2768c2ecf20Sopenharmony_ci{
2778c2ecf20Sopenharmony_ci	int ret;
2788c2ecf20Sopenharmony_ci
2798c2ecf20Sopenharmony_ci	if (2 == size) {
2808c2ecf20Sopenharmony_ci		u16 buf;
2818c2ecf20Sopenharmony_ci		buf = *((u16 *)data);
2828c2ecf20Sopenharmony_ci		cpu_to_le16s(&buf);
2838c2ecf20Sopenharmony_ci		ret = __ax88179_write_cmd(dev, cmd, value, index,
2848c2ecf20Sopenharmony_ci					  size, &buf, 1);
2858c2ecf20Sopenharmony_ci	} else {
2868c2ecf20Sopenharmony_ci		ret = __ax88179_write_cmd(dev, cmd, value, index,
2878c2ecf20Sopenharmony_ci					  size, data, 1);
2888c2ecf20Sopenharmony_ci	}
2898c2ecf20Sopenharmony_ci
2908c2ecf20Sopenharmony_ci	return ret;
2918c2ecf20Sopenharmony_ci}
2928c2ecf20Sopenharmony_ci
2938c2ecf20Sopenharmony_cistatic int ax88179_read_cmd(struct usbnet *dev, u8 cmd, u16 value, u16 index,
2948c2ecf20Sopenharmony_ci			    u16 size, void *data)
2958c2ecf20Sopenharmony_ci{
2968c2ecf20Sopenharmony_ci	int ret;
2978c2ecf20Sopenharmony_ci
2988c2ecf20Sopenharmony_ci	if (2 == size) {
2998c2ecf20Sopenharmony_ci		u16 buf = 0;
3008c2ecf20Sopenharmony_ci		ret = __ax88179_read_cmd(dev, cmd, value, index, size, &buf, 0);
3018c2ecf20Sopenharmony_ci		le16_to_cpus(&buf);
3028c2ecf20Sopenharmony_ci		*((u16 *)data) = buf;
3038c2ecf20Sopenharmony_ci	} else if (4 == size) {
3048c2ecf20Sopenharmony_ci		u32 buf = 0;
3058c2ecf20Sopenharmony_ci		ret = __ax88179_read_cmd(dev, cmd, value, index, size, &buf, 0);
3068c2ecf20Sopenharmony_ci		le32_to_cpus(&buf);
3078c2ecf20Sopenharmony_ci		*((u32 *)data) = buf;
3088c2ecf20Sopenharmony_ci	} else {
3098c2ecf20Sopenharmony_ci		ret = __ax88179_read_cmd(dev, cmd, value, index, size, data, 0);
3108c2ecf20Sopenharmony_ci	}
3118c2ecf20Sopenharmony_ci
3128c2ecf20Sopenharmony_ci	return ret;
3138c2ecf20Sopenharmony_ci}
3148c2ecf20Sopenharmony_ci
3158c2ecf20Sopenharmony_cistatic int ax88179_write_cmd(struct usbnet *dev, u8 cmd, u16 value, u16 index,
3168c2ecf20Sopenharmony_ci			     u16 size, void *data)
3178c2ecf20Sopenharmony_ci{
3188c2ecf20Sopenharmony_ci	int ret;
3198c2ecf20Sopenharmony_ci
3208c2ecf20Sopenharmony_ci	if (2 == size) {
3218c2ecf20Sopenharmony_ci		u16 buf;
3228c2ecf20Sopenharmony_ci		buf = *((u16 *)data);
3238c2ecf20Sopenharmony_ci		cpu_to_le16s(&buf);
3248c2ecf20Sopenharmony_ci		ret = __ax88179_write_cmd(dev, cmd, value, index,
3258c2ecf20Sopenharmony_ci					  size, &buf, 0);
3268c2ecf20Sopenharmony_ci	} else {
3278c2ecf20Sopenharmony_ci		ret = __ax88179_write_cmd(dev, cmd, value, index,
3288c2ecf20Sopenharmony_ci					  size, data, 0);
3298c2ecf20Sopenharmony_ci	}
3308c2ecf20Sopenharmony_ci
3318c2ecf20Sopenharmony_ci	return ret;
3328c2ecf20Sopenharmony_ci}
3338c2ecf20Sopenharmony_ci
3348c2ecf20Sopenharmony_cistatic void ax88179_status(struct usbnet *dev, struct urb *urb)
3358c2ecf20Sopenharmony_ci{
3368c2ecf20Sopenharmony_ci	struct ax88179_int_data *event;
3378c2ecf20Sopenharmony_ci	u32 link;
3388c2ecf20Sopenharmony_ci
3398c2ecf20Sopenharmony_ci	if (urb->actual_length < 8)
3408c2ecf20Sopenharmony_ci		return;
3418c2ecf20Sopenharmony_ci
3428c2ecf20Sopenharmony_ci	event = urb->transfer_buffer;
3438c2ecf20Sopenharmony_ci	le32_to_cpus((void *)&event->intdata1);
3448c2ecf20Sopenharmony_ci
3458c2ecf20Sopenharmony_ci	link = (((__force u32)event->intdata1) & AX_INT_PPLS_LINK) >> 16;
3468c2ecf20Sopenharmony_ci
3478c2ecf20Sopenharmony_ci	if (netif_carrier_ok(dev->net) != link) {
3488c2ecf20Sopenharmony_ci		usbnet_link_change(dev, link, 1);
3498c2ecf20Sopenharmony_ci		netdev_info(dev->net, "ax88179 - Link status is: %d\n", link);
3508c2ecf20Sopenharmony_ci	}
3518c2ecf20Sopenharmony_ci}
3528c2ecf20Sopenharmony_ci
3538c2ecf20Sopenharmony_cistatic int ax88179_mdio_read(struct net_device *netdev, int phy_id, int loc)
3548c2ecf20Sopenharmony_ci{
3558c2ecf20Sopenharmony_ci	struct usbnet *dev = netdev_priv(netdev);
3568c2ecf20Sopenharmony_ci	u16 res;
3578c2ecf20Sopenharmony_ci
3588c2ecf20Sopenharmony_ci	ax88179_read_cmd(dev, AX_ACCESS_PHY, phy_id, (__u16)loc, 2, &res);
3598c2ecf20Sopenharmony_ci	return res;
3608c2ecf20Sopenharmony_ci}
3618c2ecf20Sopenharmony_ci
3628c2ecf20Sopenharmony_cistatic void ax88179_mdio_write(struct net_device *netdev, int phy_id, int loc,
3638c2ecf20Sopenharmony_ci			       int val)
3648c2ecf20Sopenharmony_ci{
3658c2ecf20Sopenharmony_ci	struct usbnet *dev = netdev_priv(netdev);
3668c2ecf20Sopenharmony_ci	u16 res = (u16) val;
3678c2ecf20Sopenharmony_ci
3688c2ecf20Sopenharmony_ci	ax88179_write_cmd(dev, AX_ACCESS_PHY, phy_id, (__u16)loc, 2, &res);
3698c2ecf20Sopenharmony_ci}
3708c2ecf20Sopenharmony_ci
3718c2ecf20Sopenharmony_cistatic inline int ax88179_phy_mmd_indirect(struct usbnet *dev, u16 prtad,
3728c2ecf20Sopenharmony_ci					   u16 devad)
3738c2ecf20Sopenharmony_ci{
3748c2ecf20Sopenharmony_ci	u16 tmp16;
3758c2ecf20Sopenharmony_ci	int ret;
3768c2ecf20Sopenharmony_ci
3778c2ecf20Sopenharmony_ci	tmp16 = devad;
3788c2ecf20Sopenharmony_ci	ret = ax88179_write_cmd(dev, AX_ACCESS_PHY, AX88179_PHY_ID,
3798c2ecf20Sopenharmony_ci				MII_MMD_CTRL, 2, &tmp16);
3808c2ecf20Sopenharmony_ci
3818c2ecf20Sopenharmony_ci	tmp16 = prtad;
3828c2ecf20Sopenharmony_ci	ret = ax88179_write_cmd(dev, AX_ACCESS_PHY, AX88179_PHY_ID,
3838c2ecf20Sopenharmony_ci				MII_MMD_DATA, 2, &tmp16);
3848c2ecf20Sopenharmony_ci
3858c2ecf20Sopenharmony_ci	tmp16 = devad | MII_MMD_CTRL_NOINCR;
3868c2ecf20Sopenharmony_ci	ret = ax88179_write_cmd(dev, AX_ACCESS_PHY, AX88179_PHY_ID,
3878c2ecf20Sopenharmony_ci				MII_MMD_CTRL, 2, &tmp16);
3888c2ecf20Sopenharmony_ci
3898c2ecf20Sopenharmony_ci	return ret;
3908c2ecf20Sopenharmony_ci}
3918c2ecf20Sopenharmony_ci
3928c2ecf20Sopenharmony_cistatic int
3938c2ecf20Sopenharmony_ciax88179_phy_read_mmd_indirect(struct usbnet *dev, u16 prtad, u16 devad)
3948c2ecf20Sopenharmony_ci{
3958c2ecf20Sopenharmony_ci	int ret;
3968c2ecf20Sopenharmony_ci	u16 tmp16;
3978c2ecf20Sopenharmony_ci
3988c2ecf20Sopenharmony_ci	ax88179_phy_mmd_indirect(dev, prtad, devad);
3998c2ecf20Sopenharmony_ci
4008c2ecf20Sopenharmony_ci	ret = ax88179_read_cmd(dev, AX_ACCESS_PHY, AX88179_PHY_ID,
4018c2ecf20Sopenharmony_ci			       MII_MMD_DATA, 2, &tmp16);
4028c2ecf20Sopenharmony_ci	if (ret < 0)
4038c2ecf20Sopenharmony_ci		return ret;
4048c2ecf20Sopenharmony_ci
4058c2ecf20Sopenharmony_ci	return tmp16;
4068c2ecf20Sopenharmony_ci}
4078c2ecf20Sopenharmony_ci
4088c2ecf20Sopenharmony_cistatic int
4098c2ecf20Sopenharmony_ciax88179_phy_write_mmd_indirect(struct usbnet *dev, u16 prtad, u16 devad,
4108c2ecf20Sopenharmony_ci			       u16 data)
4118c2ecf20Sopenharmony_ci{
4128c2ecf20Sopenharmony_ci	int ret;
4138c2ecf20Sopenharmony_ci
4148c2ecf20Sopenharmony_ci	ax88179_phy_mmd_indirect(dev, prtad, devad);
4158c2ecf20Sopenharmony_ci
4168c2ecf20Sopenharmony_ci	ret = ax88179_write_cmd(dev, AX_ACCESS_PHY, AX88179_PHY_ID,
4178c2ecf20Sopenharmony_ci				MII_MMD_DATA, 2, &data);
4188c2ecf20Sopenharmony_ci
4198c2ecf20Sopenharmony_ci	if (ret < 0)
4208c2ecf20Sopenharmony_ci		return ret;
4218c2ecf20Sopenharmony_ci
4228c2ecf20Sopenharmony_ci	return 0;
4238c2ecf20Sopenharmony_ci}
4248c2ecf20Sopenharmony_ci
4258c2ecf20Sopenharmony_cistatic int ax88179_suspend(struct usb_interface *intf, pm_message_t message)
4268c2ecf20Sopenharmony_ci{
4278c2ecf20Sopenharmony_ci	struct usbnet *dev = usb_get_intfdata(intf);
4288c2ecf20Sopenharmony_ci	u16 tmp16;
4298c2ecf20Sopenharmony_ci	u8 tmp8;
4308c2ecf20Sopenharmony_ci
4318c2ecf20Sopenharmony_ci	usbnet_suspend(intf, message);
4328c2ecf20Sopenharmony_ci
4338c2ecf20Sopenharmony_ci	/* Disable RX path */
4348c2ecf20Sopenharmony_ci	ax88179_read_cmd_nopm(dev, AX_ACCESS_MAC, AX_MEDIUM_STATUS_MODE,
4358c2ecf20Sopenharmony_ci			      2, 2, &tmp16);
4368c2ecf20Sopenharmony_ci	tmp16 &= ~AX_MEDIUM_RECEIVE_EN;
4378c2ecf20Sopenharmony_ci	ax88179_write_cmd_nopm(dev, AX_ACCESS_MAC, AX_MEDIUM_STATUS_MODE,
4388c2ecf20Sopenharmony_ci			       2, 2, &tmp16);
4398c2ecf20Sopenharmony_ci
4408c2ecf20Sopenharmony_ci	/* Force bulk-in zero length */
4418c2ecf20Sopenharmony_ci	ax88179_read_cmd_nopm(dev, AX_ACCESS_MAC, AX_PHYPWR_RSTCTL,
4428c2ecf20Sopenharmony_ci			      2, 2, &tmp16);
4438c2ecf20Sopenharmony_ci
4448c2ecf20Sopenharmony_ci	tmp16 |= AX_PHYPWR_RSTCTL_BZ | AX_PHYPWR_RSTCTL_IPRL;
4458c2ecf20Sopenharmony_ci	ax88179_write_cmd_nopm(dev, AX_ACCESS_MAC, AX_PHYPWR_RSTCTL,
4468c2ecf20Sopenharmony_ci			       2, 2, &tmp16);
4478c2ecf20Sopenharmony_ci
4488c2ecf20Sopenharmony_ci	/* change clock */
4498c2ecf20Sopenharmony_ci	tmp8 = 0;
4508c2ecf20Sopenharmony_ci	ax88179_write_cmd_nopm(dev, AX_ACCESS_MAC, AX_CLK_SELECT, 1, 1, &tmp8);
4518c2ecf20Sopenharmony_ci
4528c2ecf20Sopenharmony_ci	/* Configure RX control register => stop operation */
4538c2ecf20Sopenharmony_ci	tmp16 = AX_RX_CTL_STOP;
4548c2ecf20Sopenharmony_ci	ax88179_write_cmd_nopm(dev, AX_ACCESS_MAC, AX_RX_CTL, 2, 2, &tmp16);
4558c2ecf20Sopenharmony_ci
4568c2ecf20Sopenharmony_ci	return 0;
4578c2ecf20Sopenharmony_ci}
4588c2ecf20Sopenharmony_ci
4598c2ecf20Sopenharmony_ci/* This function is used to enable the autodetach function. */
4608c2ecf20Sopenharmony_ci/* This function is determined by offset 0x43 of EEPROM */
4618c2ecf20Sopenharmony_cistatic int ax88179_auto_detach(struct usbnet *dev, int in_pm)
4628c2ecf20Sopenharmony_ci{
4638c2ecf20Sopenharmony_ci	u16 tmp16;
4648c2ecf20Sopenharmony_ci	u8 tmp8;
4658c2ecf20Sopenharmony_ci	int (*fnr)(struct usbnet *, u8, u16, u16, u16, void *);
4668c2ecf20Sopenharmony_ci	int (*fnw)(struct usbnet *, u8, u16, u16, u16, void *);
4678c2ecf20Sopenharmony_ci
4688c2ecf20Sopenharmony_ci	if (!in_pm) {
4698c2ecf20Sopenharmony_ci		fnr = ax88179_read_cmd;
4708c2ecf20Sopenharmony_ci		fnw = ax88179_write_cmd;
4718c2ecf20Sopenharmony_ci	} else {
4728c2ecf20Sopenharmony_ci		fnr = ax88179_read_cmd_nopm;
4738c2ecf20Sopenharmony_ci		fnw = ax88179_write_cmd_nopm;
4748c2ecf20Sopenharmony_ci	}
4758c2ecf20Sopenharmony_ci
4768c2ecf20Sopenharmony_ci	if (fnr(dev, AX_ACCESS_EEPROM, 0x43, 1, 2, &tmp16) < 0)
4778c2ecf20Sopenharmony_ci		return 0;
4788c2ecf20Sopenharmony_ci
4798c2ecf20Sopenharmony_ci	if ((tmp16 == 0xFFFF) || (!(tmp16 & 0x0100)))
4808c2ecf20Sopenharmony_ci		return 0;
4818c2ecf20Sopenharmony_ci
4828c2ecf20Sopenharmony_ci	/* Enable Auto Detach bit */
4838c2ecf20Sopenharmony_ci	tmp8 = 0;
4848c2ecf20Sopenharmony_ci	fnr(dev, AX_ACCESS_MAC, AX_CLK_SELECT, 1, 1, &tmp8);
4858c2ecf20Sopenharmony_ci	tmp8 |= AX_CLK_SELECT_ULR;
4868c2ecf20Sopenharmony_ci	fnw(dev, AX_ACCESS_MAC, AX_CLK_SELECT, 1, 1, &tmp8);
4878c2ecf20Sopenharmony_ci
4888c2ecf20Sopenharmony_ci	fnr(dev, AX_ACCESS_MAC, AX_PHYPWR_RSTCTL, 2, 2, &tmp16);
4898c2ecf20Sopenharmony_ci	tmp16 |= AX_PHYPWR_RSTCTL_AT;
4908c2ecf20Sopenharmony_ci	fnw(dev, AX_ACCESS_MAC, AX_PHYPWR_RSTCTL, 2, 2, &tmp16);
4918c2ecf20Sopenharmony_ci
4928c2ecf20Sopenharmony_ci	return 0;
4938c2ecf20Sopenharmony_ci}
4948c2ecf20Sopenharmony_ci
4958c2ecf20Sopenharmony_cistatic int ax88179_resume(struct usb_interface *intf)
4968c2ecf20Sopenharmony_ci{
4978c2ecf20Sopenharmony_ci	struct usbnet *dev = usb_get_intfdata(intf);
4988c2ecf20Sopenharmony_ci	u16 tmp16;
4998c2ecf20Sopenharmony_ci	u8 tmp8;
5008c2ecf20Sopenharmony_ci
5018c2ecf20Sopenharmony_ci	usbnet_link_change(dev, 0, 0);
5028c2ecf20Sopenharmony_ci
5038c2ecf20Sopenharmony_ci	/* Power up ethernet PHY */
5048c2ecf20Sopenharmony_ci	tmp16 = 0;
5058c2ecf20Sopenharmony_ci	ax88179_write_cmd_nopm(dev, AX_ACCESS_MAC, AX_PHYPWR_RSTCTL,
5068c2ecf20Sopenharmony_ci			       2, 2, &tmp16);
5078c2ecf20Sopenharmony_ci	udelay(1000);
5088c2ecf20Sopenharmony_ci
5098c2ecf20Sopenharmony_ci	tmp16 = AX_PHYPWR_RSTCTL_IPRL;
5108c2ecf20Sopenharmony_ci	ax88179_write_cmd_nopm(dev, AX_ACCESS_MAC, AX_PHYPWR_RSTCTL,
5118c2ecf20Sopenharmony_ci			       2, 2, &tmp16);
5128c2ecf20Sopenharmony_ci	msleep(200);
5138c2ecf20Sopenharmony_ci
5148c2ecf20Sopenharmony_ci	/* Ethernet PHY Auto Detach*/
5158c2ecf20Sopenharmony_ci	ax88179_auto_detach(dev, 1);
5168c2ecf20Sopenharmony_ci
5178c2ecf20Sopenharmony_ci	/* Enable clock */
5188c2ecf20Sopenharmony_ci	ax88179_read_cmd_nopm(dev, AX_ACCESS_MAC,  AX_CLK_SELECT, 1, 1, &tmp8);
5198c2ecf20Sopenharmony_ci	tmp8 |= AX_CLK_SELECT_ACS | AX_CLK_SELECT_BCS;
5208c2ecf20Sopenharmony_ci	ax88179_write_cmd_nopm(dev, AX_ACCESS_MAC, AX_CLK_SELECT, 1, 1, &tmp8);
5218c2ecf20Sopenharmony_ci	msleep(100);
5228c2ecf20Sopenharmony_ci
5238c2ecf20Sopenharmony_ci	/* Configure RX control register => start operation */
5248c2ecf20Sopenharmony_ci	tmp16 = AX_RX_CTL_DROPCRCERR | AX_RX_CTL_IPE | AX_RX_CTL_START |
5258c2ecf20Sopenharmony_ci		AX_RX_CTL_AP | AX_RX_CTL_AMALL | AX_RX_CTL_AB;
5268c2ecf20Sopenharmony_ci	ax88179_write_cmd_nopm(dev, AX_ACCESS_MAC, AX_RX_CTL, 2, 2, &tmp16);
5278c2ecf20Sopenharmony_ci
5288c2ecf20Sopenharmony_ci	return usbnet_resume(intf);
5298c2ecf20Sopenharmony_ci}
5308c2ecf20Sopenharmony_ci
5318c2ecf20Sopenharmony_cistatic void
5328c2ecf20Sopenharmony_ciax88179_get_wol(struct net_device *net, struct ethtool_wolinfo *wolinfo)
5338c2ecf20Sopenharmony_ci{
5348c2ecf20Sopenharmony_ci	struct usbnet *dev = netdev_priv(net);
5358c2ecf20Sopenharmony_ci	u8 opt;
5368c2ecf20Sopenharmony_ci
5378c2ecf20Sopenharmony_ci	if (ax88179_read_cmd(dev, AX_ACCESS_MAC, AX_MONITOR_MOD,
5388c2ecf20Sopenharmony_ci			     1, 1, &opt) < 0) {
5398c2ecf20Sopenharmony_ci		wolinfo->supported = 0;
5408c2ecf20Sopenharmony_ci		wolinfo->wolopts = 0;
5418c2ecf20Sopenharmony_ci		return;
5428c2ecf20Sopenharmony_ci	}
5438c2ecf20Sopenharmony_ci
5448c2ecf20Sopenharmony_ci	wolinfo->supported = WAKE_PHY | WAKE_MAGIC;
5458c2ecf20Sopenharmony_ci	wolinfo->wolopts = 0;
5468c2ecf20Sopenharmony_ci	if (opt & AX_MONITOR_MODE_RWLC)
5478c2ecf20Sopenharmony_ci		wolinfo->wolopts |= WAKE_PHY;
5488c2ecf20Sopenharmony_ci	if (opt & AX_MONITOR_MODE_RWMP)
5498c2ecf20Sopenharmony_ci		wolinfo->wolopts |= WAKE_MAGIC;
5508c2ecf20Sopenharmony_ci}
5518c2ecf20Sopenharmony_ci
5528c2ecf20Sopenharmony_cistatic int
5538c2ecf20Sopenharmony_ciax88179_set_wol(struct net_device *net, struct ethtool_wolinfo *wolinfo)
5548c2ecf20Sopenharmony_ci{
5558c2ecf20Sopenharmony_ci	struct usbnet *dev = netdev_priv(net);
5568c2ecf20Sopenharmony_ci	u8 opt = 0;
5578c2ecf20Sopenharmony_ci
5588c2ecf20Sopenharmony_ci	if (wolinfo->wolopts & ~(WAKE_PHY | WAKE_MAGIC))
5598c2ecf20Sopenharmony_ci		return -EINVAL;
5608c2ecf20Sopenharmony_ci
5618c2ecf20Sopenharmony_ci	if (wolinfo->wolopts & WAKE_PHY)
5628c2ecf20Sopenharmony_ci		opt |= AX_MONITOR_MODE_RWLC;
5638c2ecf20Sopenharmony_ci	if (wolinfo->wolopts & WAKE_MAGIC)
5648c2ecf20Sopenharmony_ci		opt |= AX_MONITOR_MODE_RWMP;
5658c2ecf20Sopenharmony_ci
5668c2ecf20Sopenharmony_ci	if (ax88179_write_cmd(dev, AX_ACCESS_MAC, AX_MONITOR_MOD,
5678c2ecf20Sopenharmony_ci			      1, 1, &opt) < 0)
5688c2ecf20Sopenharmony_ci		return -EINVAL;
5698c2ecf20Sopenharmony_ci
5708c2ecf20Sopenharmony_ci	return 0;
5718c2ecf20Sopenharmony_ci}
5728c2ecf20Sopenharmony_ci
5738c2ecf20Sopenharmony_cistatic int ax88179_get_eeprom_len(struct net_device *net)
5748c2ecf20Sopenharmony_ci{
5758c2ecf20Sopenharmony_ci	return AX_EEPROM_LEN;
5768c2ecf20Sopenharmony_ci}
5778c2ecf20Sopenharmony_ci
5788c2ecf20Sopenharmony_cistatic int
5798c2ecf20Sopenharmony_ciax88179_get_eeprom(struct net_device *net, struct ethtool_eeprom *eeprom,
5808c2ecf20Sopenharmony_ci		   u8 *data)
5818c2ecf20Sopenharmony_ci{
5828c2ecf20Sopenharmony_ci	struct usbnet *dev = netdev_priv(net);
5838c2ecf20Sopenharmony_ci	u16 *eeprom_buff;
5848c2ecf20Sopenharmony_ci	int first_word, last_word;
5858c2ecf20Sopenharmony_ci	int i, ret;
5868c2ecf20Sopenharmony_ci
5878c2ecf20Sopenharmony_ci	if (eeprom->len == 0)
5888c2ecf20Sopenharmony_ci		return -EINVAL;
5898c2ecf20Sopenharmony_ci
5908c2ecf20Sopenharmony_ci	eeprom->magic = AX88179_EEPROM_MAGIC;
5918c2ecf20Sopenharmony_ci
5928c2ecf20Sopenharmony_ci	first_word = eeprom->offset >> 1;
5938c2ecf20Sopenharmony_ci	last_word = (eeprom->offset + eeprom->len - 1) >> 1;
5948c2ecf20Sopenharmony_ci	eeprom_buff = kmalloc_array(last_word - first_word + 1, sizeof(u16),
5958c2ecf20Sopenharmony_ci				    GFP_KERNEL);
5968c2ecf20Sopenharmony_ci	if (!eeprom_buff)
5978c2ecf20Sopenharmony_ci		return -ENOMEM;
5988c2ecf20Sopenharmony_ci
5998c2ecf20Sopenharmony_ci	/* ax88179/178A returns 2 bytes from eeprom on read */
6008c2ecf20Sopenharmony_ci	for (i = first_word; i <= last_word; i++) {
6018c2ecf20Sopenharmony_ci		ret = __ax88179_read_cmd(dev, AX_ACCESS_EEPROM, i, 1, 2,
6028c2ecf20Sopenharmony_ci					 &eeprom_buff[i - first_word],
6038c2ecf20Sopenharmony_ci					 0);
6048c2ecf20Sopenharmony_ci		if (ret < 0) {
6058c2ecf20Sopenharmony_ci			kfree(eeprom_buff);
6068c2ecf20Sopenharmony_ci			return -EIO;
6078c2ecf20Sopenharmony_ci		}
6088c2ecf20Sopenharmony_ci	}
6098c2ecf20Sopenharmony_ci
6108c2ecf20Sopenharmony_ci	memcpy(data, (u8 *)eeprom_buff + (eeprom->offset & 1), eeprom->len);
6118c2ecf20Sopenharmony_ci	kfree(eeprom_buff);
6128c2ecf20Sopenharmony_ci	return 0;
6138c2ecf20Sopenharmony_ci}
6148c2ecf20Sopenharmony_ci
6158c2ecf20Sopenharmony_cistatic int
6168c2ecf20Sopenharmony_ciax88179_set_eeprom(struct net_device *net, struct ethtool_eeprom *eeprom,
6178c2ecf20Sopenharmony_ci		   u8 *data)
6188c2ecf20Sopenharmony_ci{
6198c2ecf20Sopenharmony_ci	struct usbnet *dev = netdev_priv(net);
6208c2ecf20Sopenharmony_ci	u16 *eeprom_buff;
6218c2ecf20Sopenharmony_ci	int first_word;
6228c2ecf20Sopenharmony_ci	int last_word;
6238c2ecf20Sopenharmony_ci	int ret;
6248c2ecf20Sopenharmony_ci	int i;
6258c2ecf20Sopenharmony_ci
6268c2ecf20Sopenharmony_ci	netdev_dbg(net, "write EEPROM len %d, offset %d, magic 0x%x\n",
6278c2ecf20Sopenharmony_ci		   eeprom->len, eeprom->offset, eeprom->magic);
6288c2ecf20Sopenharmony_ci
6298c2ecf20Sopenharmony_ci	if (eeprom->len == 0)
6308c2ecf20Sopenharmony_ci		return -EINVAL;
6318c2ecf20Sopenharmony_ci
6328c2ecf20Sopenharmony_ci	if (eeprom->magic != AX88179_EEPROM_MAGIC)
6338c2ecf20Sopenharmony_ci		return -EINVAL;
6348c2ecf20Sopenharmony_ci
6358c2ecf20Sopenharmony_ci	first_word = eeprom->offset >> 1;
6368c2ecf20Sopenharmony_ci	last_word = (eeprom->offset + eeprom->len - 1) >> 1;
6378c2ecf20Sopenharmony_ci
6388c2ecf20Sopenharmony_ci	eeprom_buff = kmalloc_array(last_word - first_word + 1, sizeof(u16),
6398c2ecf20Sopenharmony_ci				    GFP_KERNEL);
6408c2ecf20Sopenharmony_ci	if (!eeprom_buff)
6418c2ecf20Sopenharmony_ci		return -ENOMEM;
6428c2ecf20Sopenharmony_ci
6438c2ecf20Sopenharmony_ci	/* align data to 16 bit boundaries, read the missing data from
6448c2ecf20Sopenharmony_ci	   the EEPROM */
6458c2ecf20Sopenharmony_ci	if (eeprom->offset & 1) {
6468c2ecf20Sopenharmony_ci		ret = ax88179_read_cmd(dev, AX_ACCESS_EEPROM, first_word, 1, 2,
6478c2ecf20Sopenharmony_ci				       &eeprom_buff[0]);
6488c2ecf20Sopenharmony_ci		if (ret < 0) {
6498c2ecf20Sopenharmony_ci			netdev_err(net, "Failed to read EEPROM at offset 0x%02x.\n", first_word);
6508c2ecf20Sopenharmony_ci			goto free;
6518c2ecf20Sopenharmony_ci		}
6528c2ecf20Sopenharmony_ci	}
6538c2ecf20Sopenharmony_ci
6548c2ecf20Sopenharmony_ci	if ((eeprom->offset + eeprom->len) & 1) {
6558c2ecf20Sopenharmony_ci		ret = ax88179_read_cmd(dev, AX_ACCESS_EEPROM, last_word, 1, 2,
6568c2ecf20Sopenharmony_ci				       &eeprom_buff[last_word - first_word]);
6578c2ecf20Sopenharmony_ci		if (ret < 0) {
6588c2ecf20Sopenharmony_ci			netdev_err(net, "Failed to read EEPROM at offset 0x%02x.\n", last_word);
6598c2ecf20Sopenharmony_ci			goto free;
6608c2ecf20Sopenharmony_ci		}
6618c2ecf20Sopenharmony_ci	}
6628c2ecf20Sopenharmony_ci
6638c2ecf20Sopenharmony_ci	memcpy((u8 *)eeprom_buff + (eeprom->offset & 1), data, eeprom->len);
6648c2ecf20Sopenharmony_ci
6658c2ecf20Sopenharmony_ci	for (i = first_word; i <= last_word; i++) {
6668c2ecf20Sopenharmony_ci		netdev_dbg(net, "write to EEPROM at offset 0x%02x, data 0x%04x\n",
6678c2ecf20Sopenharmony_ci			   i, eeprom_buff[i - first_word]);
6688c2ecf20Sopenharmony_ci		ret = ax88179_write_cmd(dev, AX_ACCESS_EEPROM, i, 1, 2,
6698c2ecf20Sopenharmony_ci					&eeprom_buff[i - first_word]);
6708c2ecf20Sopenharmony_ci		if (ret < 0) {
6718c2ecf20Sopenharmony_ci			netdev_err(net, "Failed to write EEPROM at offset 0x%02x.\n", i);
6728c2ecf20Sopenharmony_ci			goto free;
6738c2ecf20Sopenharmony_ci		}
6748c2ecf20Sopenharmony_ci		msleep(20);
6758c2ecf20Sopenharmony_ci	}
6768c2ecf20Sopenharmony_ci
6778c2ecf20Sopenharmony_ci	/* reload EEPROM data */
6788c2ecf20Sopenharmony_ci	ret = ax88179_write_cmd(dev, AX_RELOAD_EEPROM_EFUSE, 0x0000, 0, 0, NULL);
6798c2ecf20Sopenharmony_ci	if (ret < 0) {
6808c2ecf20Sopenharmony_ci		netdev_err(net, "Failed to reload EEPROM data\n");
6818c2ecf20Sopenharmony_ci		goto free;
6828c2ecf20Sopenharmony_ci	}
6838c2ecf20Sopenharmony_ci
6848c2ecf20Sopenharmony_ci	ret = 0;
6858c2ecf20Sopenharmony_cifree:
6868c2ecf20Sopenharmony_ci	kfree(eeprom_buff);
6878c2ecf20Sopenharmony_ci	return ret;
6888c2ecf20Sopenharmony_ci}
6898c2ecf20Sopenharmony_ci
6908c2ecf20Sopenharmony_cistatic int ax88179_get_link_ksettings(struct net_device *net,
6918c2ecf20Sopenharmony_ci				      struct ethtool_link_ksettings *cmd)
6928c2ecf20Sopenharmony_ci{
6938c2ecf20Sopenharmony_ci	struct usbnet *dev = netdev_priv(net);
6948c2ecf20Sopenharmony_ci
6958c2ecf20Sopenharmony_ci	mii_ethtool_get_link_ksettings(&dev->mii, cmd);
6968c2ecf20Sopenharmony_ci
6978c2ecf20Sopenharmony_ci	return 0;
6988c2ecf20Sopenharmony_ci}
6998c2ecf20Sopenharmony_ci
7008c2ecf20Sopenharmony_cistatic int ax88179_set_link_ksettings(struct net_device *net,
7018c2ecf20Sopenharmony_ci				      const struct ethtool_link_ksettings *cmd)
7028c2ecf20Sopenharmony_ci{
7038c2ecf20Sopenharmony_ci	struct usbnet *dev = netdev_priv(net);
7048c2ecf20Sopenharmony_ci	return mii_ethtool_set_link_ksettings(&dev->mii, cmd);
7058c2ecf20Sopenharmony_ci}
7068c2ecf20Sopenharmony_ci
7078c2ecf20Sopenharmony_cistatic int
7088c2ecf20Sopenharmony_ciax88179_ethtool_get_eee(struct usbnet *dev, struct ethtool_eee *data)
7098c2ecf20Sopenharmony_ci{
7108c2ecf20Sopenharmony_ci	int val;
7118c2ecf20Sopenharmony_ci
7128c2ecf20Sopenharmony_ci	/* Get Supported EEE */
7138c2ecf20Sopenharmony_ci	val = ax88179_phy_read_mmd_indirect(dev, MDIO_PCS_EEE_ABLE,
7148c2ecf20Sopenharmony_ci					    MDIO_MMD_PCS);
7158c2ecf20Sopenharmony_ci	if (val < 0)
7168c2ecf20Sopenharmony_ci		return val;
7178c2ecf20Sopenharmony_ci	data->supported = mmd_eee_cap_to_ethtool_sup_t(val);
7188c2ecf20Sopenharmony_ci
7198c2ecf20Sopenharmony_ci	/* Get advertisement EEE */
7208c2ecf20Sopenharmony_ci	val = ax88179_phy_read_mmd_indirect(dev, MDIO_AN_EEE_ADV,
7218c2ecf20Sopenharmony_ci					    MDIO_MMD_AN);
7228c2ecf20Sopenharmony_ci	if (val < 0)
7238c2ecf20Sopenharmony_ci		return val;
7248c2ecf20Sopenharmony_ci	data->advertised = mmd_eee_adv_to_ethtool_adv_t(val);
7258c2ecf20Sopenharmony_ci
7268c2ecf20Sopenharmony_ci	/* Get LP advertisement EEE */
7278c2ecf20Sopenharmony_ci	val = ax88179_phy_read_mmd_indirect(dev, MDIO_AN_EEE_LPABLE,
7288c2ecf20Sopenharmony_ci					    MDIO_MMD_AN);
7298c2ecf20Sopenharmony_ci	if (val < 0)
7308c2ecf20Sopenharmony_ci		return val;
7318c2ecf20Sopenharmony_ci	data->lp_advertised = mmd_eee_adv_to_ethtool_adv_t(val);
7328c2ecf20Sopenharmony_ci
7338c2ecf20Sopenharmony_ci	return 0;
7348c2ecf20Sopenharmony_ci}
7358c2ecf20Sopenharmony_ci
7368c2ecf20Sopenharmony_cistatic int
7378c2ecf20Sopenharmony_ciax88179_ethtool_set_eee(struct usbnet *dev, struct ethtool_eee *data)
7388c2ecf20Sopenharmony_ci{
7398c2ecf20Sopenharmony_ci	u16 tmp16 = ethtool_adv_to_mmd_eee_adv_t(data->advertised);
7408c2ecf20Sopenharmony_ci
7418c2ecf20Sopenharmony_ci	return ax88179_phy_write_mmd_indirect(dev, MDIO_AN_EEE_ADV,
7428c2ecf20Sopenharmony_ci					      MDIO_MMD_AN, tmp16);
7438c2ecf20Sopenharmony_ci}
7448c2ecf20Sopenharmony_ci
7458c2ecf20Sopenharmony_cistatic int ax88179_chk_eee(struct usbnet *dev)
7468c2ecf20Sopenharmony_ci{
7478c2ecf20Sopenharmony_ci	struct ethtool_cmd ecmd = { .cmd = ETHTOOL_GSET };
7488c2ecf20Sopenharmony_ci	struct ax88179_data *priv = (struct ax88179_data *)dev->data;
7498c2ecf20Sopenharmony_ci
7508c2ecf20Sopenharmony_ci	mii_ethtool_gset(&dev->mii, &ecmd);
7518c2ecf20Sopenharmony_ci
7528c2ecf20Sopenharmony_ci	if (ecmd.duplex & DUPLEX_FULL) {
7538c2ecf20Sopenharmony_ci		int eee_lp, eee_cap, eee_adv;
7548c2ecf20Sopenharmony_ci		u32 lp, cap, adv, supported = 0;
7558c2ecf20Sopenharmony_ci
7568c2ecf20Sopenharmony_ci		eee_cap = ax88179_phy_read_mmd_indirect(dev,
7578c2ecf20Sopenharmony_ci							MDIO_PCS_EEE_ABLE,
7588c2ecf20Sopenharmony_ci							MDIO_MMD_PCS);
7598c2ecf20Sopenharmony_ci		if (eee_cap < 0) {
7608c2ecf20Sopenharmony_ci			priv->eee_active = 0;
7618c2ecf20Sopenharmony_ci			return false;
7628c2ecf20Sopenharmony_ci		}
7638c2ecf20Sopenharmony_ci
7648c2ecf20Sopenharmony_ci		cap = mmd_eee_cap_to_ethtool_sup_t(eee_cap);
7658c2ecf20Sopenharmony_ci		if (!cap) {
7668c2ecf20Sopenharmony_ci			priv->eee_active = 0;
7678c2ecf20Sopenharmony_ci			return false;
7688c2ecf20Sopenharmony_ci		}
7698c2ecf20Sopenharmony_ci
7708c2ecf20Sopenharmony_ci		eee_lp = ax88179_phy_read_mmd_indirect(dev,
7718c2ecf20Sopenharmony_ci						       MDIO_AN_EEE_LPABLE,
7728c2ecf20Sopenharmony_ci						       MDIO_MMD_AN);
7738c2ecf20Sopenharmony_ci		if (eee_lp < 0) {
7748c2ecf20Sopenharmony_ci			priv->eee_active = 0;
7758c2ecf20Sopenharmony_ci			return false;
7768c2ecf20Sopenharmony_ci		}
7778c2ecf20Sopenharmony_ci
7788c2ecf20Sopenharmony_ci		eee_adv = ax88179_phy_read_mmd_indirect(dev,
7798c2ecf20Sopenharmony_ci							MDIO_AN_EEE_ADV,
7808c2ecf20Sopenharmony_ci							MDIO_MMD_AN);
7818c2ecf20Sopenharmony_ci
7828c2ecf20Sopenharmony_ci		if (eee_adv < 0) {
7838c2ecf20Sopenharmony_ci			priv->eee_active = 0;
7848c2ecf20Sopenharmony_ci			return false;
7858c2ecf20Sopenharmony_ci		}
7868c2ecf20Sopenharmony_ci
7878c2ecf20Sopenharmony_ci		adv = mmd_eee_adv_to_ethtool_adv_t(eee_adv);
7888c2ecf20Sopenharmony_ci		lp = mmd_eee_adv_to_ethtool_adv_t(eee_lp);
7898c2ecf20Sopenharmony_ci		supported = (ecmd.speed == SPEED_1000) ?
7908c2ecf20Sopenharmony_ci			     SUPPORTED_1000baseT_Full :
7918c2ecf20Sopenharmony_ci			     SUPPORTED_100baseT_Full;
7928c2ecf20Sopenharmony_ci
7938c2ecf20Sopenharmony_ci		if (!(lp & adv & supported)) {
7948c2ecf20Sopenharmony_ci			priv->eee_active = 0;
7958c2ecf20Sopenharmony_ci			return false;
7968c2ecf20Sopenharmony_ci		}
7978c2ecf20Sopenharmony_ci
7988c2ecf20Sopenharmony_ci		priv->eee_active = 1;
7998c2ecf20Sopenharmony_ci		return true;
8008c2ecf20Sopenharmony_ci	}
8018c2ecf20Sopenharmony_ci
8028c2ecf20Sopenharmony_ci	priv->eee_active = 0;
8038c2ecf20Sopenharmony_ci	return false;
8048c2ecf20Sopenharmony_ci}
8058c2ecf20Sopenharmony_ci
8068c2ecf20Sopenharmony_cistatic void ax88179_disable_eee(struct usbnet *dev)
8078c2ecf20Sopenharmony_ci{
8088c2ecf20Sopenharmony_ci	u16 tmp16;
8098c2ecf20Sopenharmony_ci
8108c2ecf20Sopenharmony_ci	tmp16 = GMII_PHY_PGSEL_PAGE3;
8118c2ecf20Sopenharmony_ci	ax88179_write_cmd(dev, AX_ACCESS_PHY, AX88179_PHY_ID,
8128c2ecf20Sopenharmony_ci			  GMII_PHY_PAGE_SELECT, 2, &tmp16);
8138c2ecf20Sopenharmony_ci
8148c2ecf20Sopenharmony_ci	tmp16 = 0x3246;
8158c2ecf20Sopenharmony_ci	ax88179_write_cmd(dev, AX_ACCESS_PHY, AX88179_PHY_ID,
8168c2ecf20Sopenharmony_ci			  MII_PHYADDR, 2, &tmp16);
8178c2ecf20Sopenharmony_ci
8188c2ecf20Sopenharmony_ci	tmp16 = GMII_PHY_PGSEL_PAGE0;
8198c2ecf20Sopenharmony_ci	ax88179_write_cmd(dev, AX_ACCESS_PHY, AX88179_PHY_ID,
8208c2ecf20Sopenharmony_ci			  GMII_PHY_PAGE_SELECT, 2, &tmp16);
8218c2ecf20Sopenharmony_ci}
8228c2ecf20Sopenharmony_ci
8238c2ecf20Sopenharmony_cistatic void ax88179_enable_eee(struct usbnet *dev)
8248c2ecf20Sopenharmony_ci{
8258c2ecf20Sopenharmony_ci	u16 tmp16;
8268c2ecf20Sopenharmony_ci
8278c2ecf20Sopenharmony_ci	tmp16 = GMII_PHY_PGSEL_PAGE3;
8288c2ecf20Sopenharmony_ci	ax88179_write_cmd(dev, AX_ACCESS_PHY, AX88179_PHY_ID,
8298c2ecf20Sopenharmony_ci			  GMII_PHY_PAGE_SELECT, 2, &tmp16);
8308c2ecf20Sopenharmony_ci
8318c2ecf20Sopenharmony_ci	tmp16 = 0x3247;
8328c2ecf20Sopenharmony_ci	ax88179_write_cmd(dev, AX_ACCESS_PHY, AX88179_PHY_ID,
8338c2ecf20Sopenharmony_ci			  MII_PHYADDR, 2, &tmp16);
8348c2ecf20Sopenharmony_ci
8358c2ecf20Sopenharmony_ci	tmp16 = GMII_PHY_PGSEL_PAGE5;
8368c2ecf20Sopenharmony_ci	ax88179_write_cmd(dev, AX_ACCESS_PHY, AX88179_PHY_ID,
8378c2ecf20Sopenharmony_ci			  GMII_PHY_PAGE_SELECT, 2, &tmp16);
8388c2ecf20Sopenharmony_ci
8398c2ecf20Sopenharmony_ci	tmp16 = 0x0680;
8408c2ecf20Sopenharmony_ci	ax88179_write_cmd(dev, AX_ACCESS_PHY, AX88179_PHY_ID,
8418c2ecf20Sopenharmony_ci			  MII_BMSR, 2, &tmp16);
8428c2ecf20Sopenharmony_ci
8438c2ecf20Sopenharmony_ci	tmp16 = GMII_PHY_PGSEL_PAGE0;
8448c2ecf20Sopenharmony_ci	ax88179_write_cmd(dev, AX_ACCESS_PHY, AX88179_PHY_ID,
8458c2ecf20Sopenharmony_ci			  GMII_PHY_PAGE_SELECT, 2, &tmp16);
8468c2ecf20Sopenharmony_ci}
8478c2ecf20Sopenharmony_ci
8488c2ecf20Sopenharmony_cistatic int ax88179_get_eee(struct net_device *net, struct ethtool_eee *edata)
8498c2ecf20Sopenharmony_ci{
8508c2ecf20Sopenharmony_ci	struct usbnet *dev = netdev_priv(net);
8518c2ecf20Sopenharmony_ci	struct ax88179_data *priv = (struct ax88179_data *)dev->data;
8528c2ecf20Sopenharmony_ci
8538c2ecf20Sopenharmony_ci	edata->eee_enabled = priv->eee_enabled;
8548c2ecf20Sopenharmony_ci	edata->eee_active = priv->eee_active;
8558c2ecf20Sopenharmony_ci
8568c2ecf20Sopenharmony_ci	return ax88179_ethtool_get_eee(dev, edata);
8578c2ecf20Sopenharmony_ci}
8588c2ecf20Sopenharmony_ci
8598c2ecf20Sopenharmony_cistatic int ax88179_set_eee(struct net_device *net, struct ethtool_eee *edata)
8608c2ecf20Sopenharmony_ci{
8618c2ecf20Sopenharmony_ci	struct usbnet *dev = netdev_priv(net);
8628c2ecf20Sopenharmony_ci	struct ax88179_data *priv = (struct ax88179_data *)dev->data;
8638c2ecf20Sopenharmony_ci	int ret;
8648c2ecf20Sopenharmony_ci
8658c2ecf20Sopenharmony_ci	priv->eee_enabled = edata->eee_enabled;
8668c2ecf20Sopenharmony_ci	if (!priv->eee_enabled) {
8678c2ecf20Sopenharmony_ci		ax88179_disable_eee(dev);
8688c2ecf20Sopenharmony_ci	} else {
8698c2ecf20Sopenharmony_ci		priv->eee_enabled = ax88179_chk_eee(dev);
8708c2ecf20Sopenharmony_ci		if (!priv->eee_enabled)
8718c2ecf20Sopenharmony_ci			return -EOPNOTSUPP;
8728c2ecf20Sopenharmony_ci
8738c2ecf20Sopenharmony_ci		ax88179_enable_eee(dev);
8748c2ecf20Sopenharmony_ci	}
8758c2ecf20Sopenharmony_ci
8768c2ecf20Sopenharmony_ci	ret = ax88179_ethtool_set_eee(dev, edata);
8778c2ecf20Sopenharmony_ci	if (ret)
8788c2ecf20Sopenharmony_ci		return ret;
8798c2ecf20Sopenharmony_ci
8808c2ecf20Sopenharmony_ci	mii_nway_restart(&dev->mii);
8818c2ecf20Sopenharmony_ci
8828c2ecf20Sopenharmony_ci	usbnet_link_change(dev, 0, 0);
8838c2ecf20Sopenharmony_ci
8848c2ecf20Sopenharmony_ci	return ret;
8858c2ecf20Sopenharmony_ci}
8868c2ecf20Sopenharmony_ci
8878c2ecf20Sopenharmony_cistatic int ax88179_ioctl(struct net_device *net, struct ifreq *rq, int cmd)
8888c2ecf20Sopenharmony_ci{
8898c2ecf20Sopenharmony_ci	struct usbnet *dev = netdev_priv(net);
8908c2ecf20Sopenharmony_ci	return generic_mii_ioctl(&dev->mii, if_mii(rq), cmd, NULL);
8918c2ecf20Sopenharmony_ci}
8928c2ecf20Sopenharmony_ci
8938c2ecf20Sopenharmony_cistatic const struct ethtool_ops ax88179_ethtool_ops = {
8948c2ecf20Sopenharmony_ci	.get_link		= ethtool_op_get_link,
8958c2ecf20Sopenharmony_ci	.get_msglevel		= usbnet_get_msglevel,
8968c2ecf20Sopenharmony_ci	.set_msglevel		= usbnet_set_msglevel,
8978c2ecf20Sopenharmony_ci	.get_wol		= ax88179_get_wol,
8988c2ecf20Sopenharmony_ci	.set_wol		= ax88179_set_wol,
8998c2ecf20Sopenharmony_ci	.get_eeprom_len		= ax88179_get_eeprom_len,
9008c2ecf20Sopenharmony_ci	.get_eeprom		= ax88179_get_eeprom,
9018c2ecf20Sopenharmony_ci	.set_eeprom		= ax88179_set_eeprom,
9028c2ecf20Sopenharmony_ci	.get_eee		= ax88179_get_eee,
9038c2ecf20Sopenharmony_ci	.set_eee		= ax88179_set_eee,
9048c2ecf20Sopenharmony_ci	.nway_reset		= usbnet_nway_reset,
9058c2ecf20Sopenharmony_ci	.get_link_ksettings	= ax88179_get_link_ksettings,
9068c2ecf20Sopenharmony_ci	.set_link_ksettings	= ax88179_set_link_ksettings,
9078c2ecf20Sopenharmony_ci	.get_ts_info		= ethtool_op_get_ts_info,
9088c2ecf20Sopenharmony_ci};
9098c2ecf20Sopenharmony_ci
9108c2ecf20Sopenharmony_cistatic void ax88179_set_multicast(struct net_device *net)
9118c2ecf20Sopenharmony_ci{
9128c2ecf20Sopenharmony_ci	struct usbnet *dev = netdev_priv(net);
9138c2ecf20Sopenharmony_ci	struct ax88179_data *data = (struct ax88179_data *)dev->data;
9148c2ecf20Sopenharmony_ci	u8 *m_filter = ((u8 *)dev->data) + 12;
9158c2ecf20Sopenharmony_ci
9168c2ecf20Sopenharmony_ci	data->rxctl = (AX_RX_CTL_START | AX_RX_CTL_AB | AX_RX_CTL_IPE);
9178c2ecf20Sopenharmony_ci
9188c2ecf20Sopenharmony_ci	if (net->flags & IFF_PROMISC) {
9198c2ecf20Sopenharmony_ci		data->rxctl |= AX_RX_CTL_PRO;
9208c2ecf20Sopenharmony_ci	} else if (net->flags & IFF_ALLMULTI ||
9218c2ecf20Sopenharmony_ci		   netdev_mc_count(net) > AX_MAX_MCAST) {
9228c2ecf20Sopenharmony_ci		data->rxctl |= AX_RX_CTL_AMALL;
9238c2ecf20Sopenharmony_ci	} else if (netdev_mc_empty(net)) {
9248c2ecf20Sopenharmony_ci		/* just broadcast and directed */
9258c2ecf20Sopenharmony_ci	} else {
9268c2ecf20Sopenharmony_ci		/* We use the 20 byte dev->data for our 8 byte filter buffer
9278c2ecf20Sopenharmony_ci		 * to avoid allocating memory that is tricky to free later
9288c2ecf20Sopenharmony_ci		 */
9298c2ecf20Sopenharmony_ci		u32 crc_bits;
9308c2ecf20Sopenharmony_ci		struct netdev_hw_addr *ha;
9318c2ecf20Sopenharmony_ci
9328c2ecf20Sopenharmony_ci		memset(m_filter, 0, AX_MCAST_FLTSIZE);
9338c2ecf20Sopenharmony_ci
9348c2ecf20Sopenharmony_ci		netdev_for_each_mc_addr(ha, net) {
9358c2ecf20Sopenharmony_ci			crc_bits = ether_crc(ETH_ALEN, ha->addr) >> 26;
9368c2ecf20Sopenharmony_ci			*(m_filter + (crc_bits >> 3)) |= (1 << (crc_bits & 7));
9378c2ecf20Sopenharmony_ci		}
9388c2ecf20Sopenharmony_ci
9398c2ecf20Sopenharmony_ci		ax88179_write_cmd_async(dev, AX_ACCESS_MAC, AX_MULFLTARY,
9408c2ecf20Sopenharmony_ci					AX_MCAST_FLTSIZE, AX_MCAST_FLTSIZE,
9418c2ecf20Sopenharmony_ci					m_filter);
9428c2ecf20Sopenharmony_ci
9438c2ecf20Sopenharmony_ci		data->rxctl |= AX_RX_CTL_AM;
9448c2ecf20Sopenharmony_ci	}
9458c2ecf20Sopenharmony_ci
9468c2ecf20Sopenharmony_ci	ax88179_write_cmd_async(dev, AX_ACCESS_MAC, AX_RX_CTL,
9478c2ecf20Sopenharmony_ci				2, 2, &data->rxctl);
9488c2ecf20Sopenharmony_ci}
9498c2ecf20Sopenharmony_ci
9508c2ecf20Sopenharmony_cistatic int
9518c2ecf20Sopenharmony_ciax88179_set_features(struct net_device *net, netdev_features_t features)
9528c2ecf20Sopenharmony_ci{
9538c2ecf20Sopenharmony_ci	u8 tmp;
9548c2ecf20Sopenharmony_ci	struct usbnet *dev = netdev_priv(net);
9558c2ecf20Sopenharmony_ci	netdev_features_t changed = net->features ^ features;
9568c2ecf20Sopenharmony_ci
9578c2ecf20Sopenharmony_ci	if (changed & NETIF_F_IP_CSUM) {
9588c2ecf20Sopenharmony_ci		ax88179_read_cmd(dev, AX_ACCESS_MAC, AX_TXCOE_CTL, 1, 1, &tmp);
9598c2ecf20Sopenharmony_ci		tmp ^= AX_TXCOE_TCP | AX_TXCOE_UDP;
9608c2ecf20Sopenharmony_ci		ax88179_write_cmd(dev, AX_ACCESS_MAC, AX_TXCOE_CTL, 1, 1, &tmp);
9618c2ecf20Sopenharmony_ci	}
9628c2ecf20Sopenharmony_ci
9638c2ecf20Sopenharmony_ci	if (changed & NETIF_F_IPV6_CSUM) {
9648c2ecf20Sopenharmony_ci		ax88179_read_cmd(dev, AX_ACCESS_MAC, AX_TXCOE_CTL, 1, 1, &tmp);
9658c2ecf20Sopenharmony_ci		tmp ^= AX_TXCOE_TCPV6 | AX_TXCOE_UDPV6;
9668c2ecf20Sopenharmony_ci		ax88179_write_cmd(dev, AX_ACCESS_MAC, AX_TXCOE_CTL, 1, 1, &tmp);
9678c2ecf20Sopenharmony_ci	}
9688c2ecf20Sopenharmony_ci
9698c2ecf20Sopenharmony_ci	if (changed & NETIF_F_RXCSUM) {
9708c2ecf20Sopenharmony_ci		ax88179_read_cmd(dev, AX_ACCESS_MAC, AX_RXCOE_CTL, 1, 1, &tmp);
9718c2ecf20Sopenharmony_ci		tmp ^= AX_RXCOE_IP | AX_RXCOE_TCP | AX_RXCOE_UDP |
9728c2ecf20Sopenharmony_ci		       AX_RXCOE_TCPV6 | AX_RXCOE_UDPV6;
9738c2ecf20Sopenharmony_ci		ax88179_write_cmd(dev, AX_ACCESS_MAC, AX_RXCOE_CTL, 1, 1, &tmp);
9748c2ecf20Sopenharmony_ci	}
9758c2ecf20Sopenharmony_ci
9768c2ecf20Sopenharmony_ci	return 0;
9778c2ecf20Sopenharmony_ci}
9788c2ecf20Sopenharmony_ci
9798c2ecf20Sopenharmony_cistatic int ax88179_change_mtu(struct net_device *net, int new_mtu)
9808c2ecf20Sopenharmony_ci{
9818c2ecf20Sopenharmony_ci	struct usbnet *dev = netdev_priv(net);
9828c2ecf20Sopenharmony_ci	u16 tmp16;
9838c2ecf20Sopenharmony_ci
9848c2ecf20Sopenharmony_ci	net->mtu = new_mtu;
9858c2ecf20Sopenharmony_ci	dev->hard_mtu = net->mtu + net->hard_header_len;
9868c2ecf20Sopenharmony_ci
9878c2ecf20Sopenharmony_ci	if (net->mtu > 1500) {
9888c2ecf20Sopenharmony_ci		ax88179_read_cmd(dev, AX_ACCESS_MAC, AX_MEDIUM_STATUS_MODE,
9898c2ecf20Sopenharmony_ci				 2, 2, &tmp16);
9908c2ecf20Sopenharmony_ci		tmp16 |= AX_MEDIUM_JUMBO_EN;
9918c2ecf20Sopenharmony_ci		ax88179_write_cmd(dev, AX_ACCESS_MAC, AX_MEDIUM_STATUS_MODE,
9928c2ecf20Sopenharmony_ci				  2, 2, &tmp16);
9938c2ecf20Sopenharmony_ci	} else {
9948c2ecf20Sopenharmony_ci		ax88179_read_cmd(dev, AX_ACCESS_MAC, AX_MEDIUM_STATUS_MODE,
9958c2ecf20Sopenharmony_ci				 2, 2, &tmp16);
9968c2ecf20Sopenharmony_ci		tmp16 &= ~AX_MEDIUM_JUMBO_EN;
9978c2ecf20Sopenharmony_ci		ax88179_write_cmd(dev, AX_ACCESS_MAC, AX_MEDIUM_STATUS_MODE,
9988c2ecf20Sopenharmony_ci				  2, 2, &tmp16);
9998c2ecf20Sopenharmony_ci	}
10008c2ecf20Sopenharmony_ci
10018c2ecf20Sopenharmony_ci	/* max qlen depend on hard_mtu and rx_urb_size */
10028c2ecf20Sopenharmony_ci	usbnet_update_max_qlen(dev);
10038c2ecf20Sopenharmony_ci
10048c2ecf20Sopenharmony_ci	return 0;
10058c2ecf20Sopenharmony_ci}
10068c2ecf20Sopenharmony_ci
10078c2ecf20Sopenharmony_cistatic int ax88179_set_mac_addr(struct net_device *net, void *p)
10088c2ecf20Sopenharmony_ci{
10098c2ecf20Sopenharmony_ci	struct usbnet *dev = netdev_priv(net);
10108c2ecf20Sopenharmony_ci	struct sockaddr *addr = p;
10118c2ecf20Sopenharmony_ci	int ret;
10128c2ecf20Sopenharmony_ci
10138c2ecf20Sopenharmony_ci	if (netif_running(net))
10148c2ecf20Sopenharmony_ci		return -EBUSY;
10158c2ecf20Sopenharmony_ci	if (!is_valid_ether_addr(addr->sa_data))
10168c2ecf20Sopenharmony_ci		return -EADDRNOTAVAIL;
10178c2ecf20Sopenharmony_ci
10188c2ecf20Sopenharmony_ci	memcpy(net->dev_addr, addr->sa_data, ETH_ALEN);
10198c2ecf20Sopenharmony_ci
10208c2ecf20Sopenharmony_ci	/* Set the MAC address */
10218c2ecf20Sopenharmony_ci	ret = ax88179_write_cmd(dev, AX_ACCESS_MAC, AX_NODE_ID, ETH_ALEN,
10228c2ecf20Sopenharmony_ci				 ETH_ALEN, net->dev_addr);
10238c2ecf20Sopenharmony_ci	if (ret < 0)
10248c2ecf20Sopenharmony_ci		return ret;
10258c2ecf20Sopenharmony_ci
10268c2ecf20Sopenharmony_ci	return 0;
10278c2ecf20Sopenharmony_ci}
10288c2ecf20Sopenharmony_ci
10298c2ecf20Sopenharmony_cistatic const struct net_device_ops ax88179_netdev_ops = {
10308c2ecf20Sopenharmony_ci	.ndo_open		= usbnet_open,
10318c2ecf20Sopenharmony_ci	.ndo_stop		= usbnet_stop,
10328c2ecf20Sopenharmony_ci	.ndo_start_xmit		= usbnet_start_xmit,
10338c2ecf20Sopenharmony_ci	.ndo_tx_timeout		= usbnet_tx_timeout,
10348c2ecf20Sopenharmony_ci	.ndo_get_stats64	= usbnet_get_stats64,
10358c2ecf20Sopenharmony_ci	.ndo_change_mtu		= ax88179_change_mtu,
10368c2ecf20Sopenharmony_ci	.ndo_set_mac_address	= ax88179_set_mac_addr,
10378c2ecf20Sopenharmony_ci	.ndo_validate_addr	= eth_validate_addr,
10388c2ecf20Sopenharmony_ci	.ndo_do_ioctl		= ax88179_ioctl,
10398c2ecf20Sopenharmony_ci	.ndo_set_rx_mode	= ax88179_set_multicast,
10408c2ecf20Sopenharmony_ci	.ndo_set_features	= ax88179_set_features,
10418c2ecf20Sopenharmony_ci};
10428c2ecf20Sopenharmony_ci
10438c2ecf20Sopenharmony_cistatic int ax88179_check_eeprom(struct usbnet *dev)
10448c2ecf20Sopenharmony_ci{
10458c2ecf20Sopenharmony_ci	u8 i, buf, eeprom[20];
10468c2ecf20Sopenharmony_ci	u16 csum, delay = HZ / 10;
10478c2ecf20Sopenharmony_ci	unsigned long jtimeout;
10488c2ecf20Sopenharmony_ci
10498c2ecf20Sopenharmony_ci	/* Read EEPROM content */
10508c2ecf20Sopenharmony_ci	for (i = 0; i < 6; i++) {
10518c2ecf20Sopenharmony_ci		buf = i;
10528c2ecf20Sopenharmony_ci		if (ax88179_write_cmd(dev, AX_ACCESS_MAC, AX_SROM_ADDR,
10538c2ecf20Sopenharmony_ci				      1, 1, &buf) < 0)
10548c2ecf20Sopenharmony_ci			return -EINVAL;
10558c2ecf20Sopenharmony_ci
10568c2ecf20Sopenharmony_ci		buf = EEP_RD;
10578c2ecf20Sopenharmony_ci		if (ax88179_write_cmd(dev, AX_ACCESS_MAC, AX_SROM_CMD,
10588c2ecf20Sopenharmony_ci				      1, 1, &buf) < 0)
10598c2ecf20Sopenharmony_ci			return -EINVAL;
10608c2ecf20Sopenharmony_ci
10618c2ecf20Sopenharmony_ci		jtimeout = jiffies + delay;
10628c2ecf20Sopenharmony_ci		do {
10638c2ecf20Sopenharmony_ci			ax88179_read_cmd(dev, AX_ACCESS_MAC, AX_SROM_CMD,
10648c2ecf20Sopenharmony_ci					 1, 1, &buf);
10658c2ecf20Sopenharmony_ci
10668c2ecf20Sopenharmony_ci			if (time_after(jiffies, jtimeout))
10678c2ecf20Sopenharmony_ci				return -EINVAL;
10688c2ecf20Sopenharmony_ci
10698c2ecf20Sopenharmony_ci		} while (buf & EEP_BUSY);
10708c2ecf20Sopenharmony_ci
10718c2ecf20Sopenharmony_ci		__ax88179_read_cmd(dev, AX_ACCESS_MAC, AX_SROM_DATA_LOW,
10728c2ecf20Sopenharmony_ci				   2, 2, &eeprom[i * 2], 0);
10738c2ecf20Sopenharmony_ci
10748c2ecf20Sopenharmony_ci		if ((i == 0) && (eeprom[0] == 0xFF))
10758c2ecf20Sopenharmony_ci			return -EINVAL;
10768c2ecf20Sopenharmony_ci	}
10778c2ecf20Sopenharmony_ci
10788c2ecf20Sopenharmony_ci	csum = eeprom[6] + eeprom[7] + eeprom[8] + eeprom[9];
10798c2ecf20Sopenharmony_ci	csum = (csum >> 8) + (csum & 0xff);
10808c2ecf20Sopenharmony_ci	if ((csum + eeprom[10]) != 0xff)
10818c2ecf20Sopenharmony_ci		return -EINVAL;
10828c2ecf20Sopenharmony_ci
10838c2ecf20Sopenharmony_ci	return 0;
10848c2ecf20Sopenharmony_ci}
10858c2ecf20Sopenharmony_ci
10868c2ecf20Sopenharmony_cistatic int ax88179_check_efuse(struct usbnet *dev, u16 *ledmode)
10878c2ecf20Sopenharmony_ci{
10888c2ecf20Sopenharmony_ci	u8	i;
10898c2ecf20Sopenharmony_ci	u8	efuse[64];
10908c2ecf20Sopenharmony_ci	u16	csum = 0;
10918c2ecf20Sopenharmony_ci
10928c2ecf20Sopenharmony_ci	if (ax88179_read_cmd(dev, AX_ACCESS_EFUS, 0, 64, 64, efuse) < 0)
10938c2ecf20Sopenharmony_ci		return -EINVAL;
10948c2ecf20Sopenharmony_ci
10958c2ecf20Sopenharmony_ci	if (*efuse == 0xFF)
10968c2ecf20Sopenharmony_ci		return -EINVAL;
10978c2ecf20Sopenharmony_ci
10988c2ecf20Sopenharmony_ci	for (i = 0; i < 64; i++)
10998c2ecf20Sopenharmony_ci		csum = csum + efuse[i];
11008c2ecf20Sopenharmony_ci
11018c2ecf20Sopenharmony_ci	while (csum > 255)
11028c2ecf20Sopenharmony_ci		csum = (csum & 0x00FF) + ((csum >> 8) & 0x00FF);
11038c2ecf20Sopenharmony_ci
11048c2ecf20Sopenharmony_ci	if (csum != 0xFF)
11058c2ecf20Sopenharmony_ci		return -EINVAL;
11068c2ecf20Sopenharmony_ci
11078c2ecf20Sopenharmony_ci	*ledmode = (efuse[51] << 8) | efuse[52];
11088c2ecf20Sopenharmony_ci
11098c2ecf20Sopenharmony_ci	return 0;
11108c2ecf20Sopenharmony_ci}
11118c2ecf20Sopenharmony_ci
11128c2ecf20Sopenharmony_cistatic int ax88179_convert_old_led(struct usbnet *dev, u16 *ledvalue)
11138c2ecf20Sopenharmony_ci{
11148c2ecf20Sopenharmony_ci	u16 led;
11158c2ecf20Sopenharmony_ci
11168c2ecf20Sopenharmony_ci	/* Loaded the old eFuse LED Mode */
11178c2ecf20Sopenharmony_ci	if (ax88179_read_cmd(dev, AX_ACCESS_EEPROM, 0x3C, 1, 2, &led) < 0)
11188c2ecf20Sopenharmony_ci		return -EINVAL;
11198c2ecf20Sopenharmony_ci
11208c2ecf20Sopenharmony_ci	led >>= 8;
11218c2ecf20Sopenharmony_ci	switch (led) {
11228c2ecf20Sopenharmony_ci	case 0xFF:
11238c2ecf20Sopenharmony_ci		led = LED0_ACTIVE | LED1_LINK_10 | LED1_LINK_100 |
11248c2ecf20Sopenharmony_ci		      LED1_LINK_1000 | LED2_ACTIVE | LED2_LINK_10 |
11258c2ecf20Sopenharmony_ci		      LED2_LINK_100 | LED2_LINK_1000 | LED_VALID;
11268c2ecf20Sopenharmony_ci		break;
11278c2ecf20Sopenharmony_ci	case 0xFE:
11288c2ecf20Sopenharmony_ci		led = LED0_ACTIVE | LED1_LINK_1000 | LED2_LINK_100 | LED_VALID;
11298c2ecf20Sopenharmony_ci		break;
11308c2ecf20Sopenharmony_ci	case 0xFD:
11318c2ecf20Sopenharmony_ci		led = LED0_ACTIVE | LED1_LINK_1000 | LED2_LINK_100 |
11328c2ecf20Sopenharmony_ci		      LED2_LINK_10 | LED_VALID;
11338c2ecf20Sopenharmony_ci		break;
11348c2ecf20Sopenharmony_ci	case 0xFC:
11358c2ecf20Sopenharmony_ci		led = LED0_ACTIVE | LED1_ACTIVE | LED1_LINK_1000 | LED2_ACTIVE |
11368c2ecf20Sopenharmony_ci		      LED2_LINK_100 | LED2_LINK_10 | LED_VALID;
11378c2ecf20Sopenharmony_ci		break;
11388c2ecf20Sopenharmony_ci	default:
11398c2ecf20Sopenharmony_ci		led = LED0_ACTIVE | LED1_LINK_10 | LED1_LINK_100 |
11408c2ecf20Sopenharmony_ci		      LED1_LINK_1000 | LED2_ACTIVE | LED2_LINK_10 |
11418c2ecf20Sopenharmony_ci		      LED2_LINK_100 | LED2_LINK_1000 | LED_VALID;
11428c2ecf20Sopenharmony_ci		break;
11438c2ecf20Sopenharmony_ci	}
11448c2ecf20Sopenharmony_ci
11458c2ecf20Sopenharmony_ci	*ledvalue = led;
11468c2ecf20Sopenharmony_ci
11478c2ecf20Sopenharmony_ci	return 0;
11488c2ecf20Sopenharmony_ci}
11498c2ecf20Sopenharmony_ci
11508c2ecf20Sopenharmony_cistatic int ax88179_led_setting(struct usbnet *dev)
11518c2ecf20Sopenharmony_ci{
11528c2ecf20Sopenharmony_ci	u8 ledfd, value = 0;
11538c2ecf20Sopenharmony_ci	u16 tmp, ledact, ledlink, ledvalue = 0, delay = HZ / 10;
11548c2ecf20Sopenharmony_ci	unsigned long jtimeout;
11558c2ecf20Sopenharmony_ci
11568c2ecf20Sopenharmony_ci	/* Check AX88179 version. UA1 or UA2*/
11578c2ecf20Sopenharmony_ci	ax88179_read_cmd(dev, AX_ACCESS_MAC, GENERAL_STATUS, 1, 1, &value);
11588c2ecf20Sopenharmony_ci
11598c2ecf20Sopenharmony_ci	if (!(value & AX_SECLD)) {	/* UA1 */
11608c2ecf20Sopenharmony_ci		value = AX_GPIO_CTRL_GPIO3EN | AX_GPIO_CTRL_GPIO2EN |
11618c2ecf20Sopenharmony_ci			AX_GPIO_CTRL_GPIO1EN;
11628c2ecf20Sopenharmony_ci		if (ax88179_write_cmd(dev, AX_ACCESS_MAC, AX_GPIO_CTRL,
11638c2ecf20Sopenharmony_ci				      1, 1, &value) < 0)
11648c2ecf20Sopenharmony_ci			return -EINVAL;
11658c2ecf20Sopenharmony_ci	}
11668c2ecf20Sopenharmony_ci
11678c2ecf20Sopenharmony_ci	/* Check EEPROM */
11688c2ecf20Sopenharmony_ci	if (!ax88179_check_eeprom(dev)) {
11698c2ecf20Sopenharmony_ci		value = 0x42;
11708c2ecf20Sopenharmony_ci		if (ax88179_write_cmd(dev, AX_ACCESS_MAC, AX_SROM_ADDR,
11718c2ecf20Sopenharmony_ci				      1, 1, &value) < 0)
11728c2ecf20Sopenharmony_ci			return -EINVAL;
11738c2ecf20Sopenharmony_ci
11748c2ecf20Sopenharmony_ci		value = EEP_RD;
11758c2ecf20Sopenharmony_ci		if (ax88179_write_cmd(dev, AX_ACCESS_MAC, AX_SROM_CMD,
11768c2ecf20Sopenharmony_ci				      1, 1, &value) < 0)
11778c2ecf20Sopenharmony_ci			return -EINVAL;
11788c2ecf20Sopenharmony_ci
11798c2ecf20Sopenharmony_ci		jtimeout = jiffies + delay;
11808c2ecf20Sopenharmony_ci		do {
11818c2ecf20Sopenharmony_ci			ax88179_read_cmd(dev, AX_ACCESS_MAC, AX_SROM_CMD,
11828c2ecf20Sopenharmony_ci					 1, 1, &value);
11838c2ecf20Sopenharmony_ci
11848c2ecf20Sopenharmony_ci			if (time_after(jiffies, jtimeout))
11858c2ecf20Sopenharmony_ci				return -EINVAL;
11868c2ecf20Sopenharmony_ci
11878c2ecf20Sopenharmony_ci		} while (value & EEP_BUSY);
11888c2ecf20Sopenharmony_ci
11898c2ecf20Sopenharmony_ci		ax88179_read_cmd(dev, AX_ACCESS_MAC, AX_SROM_DATA_HIGH,
11908c2ecf20Sopenharmony_ci				 1, 1, &value);
11918c2ecf20Sopenharmony_ci		ledvalue = (value << 8);
11928c2ecf20Sopenharmony_ci
11938c2ecf20Sopenharmony_ci		ax88179_read_cmd(dev, AX_ACCESS_MAC, AX_SROM_DATA_LOW,
11948c2ecf20Sopenharmony_ci				 1, 1, &value);
11958c2ecf20Sopenharmony_ci		ledvalue |= value;
11968c2ecf20Sopenharmony_ci
11978c2ecf20Sopenharmony_ci		/* load internal ROM for defaule setting */
11988c2ecf20Sopenharmony_ci		if ((ledvalue == 0xFFFF) || ((ledvalue & LED_VALID) == 0))
11998c2ecf20Sopenharmony_ci			ax88179_convert_old_led(dev, &ledvalue);
12008c2ecf20Sopenharmony_ci
12018c2ecf20Sopenharmony_ci	} else if (!ax88179_check_efuse(dev, &ledvalue)) {
12028c2ecf20Sopenharmony_ci		if ((ledvalue == 0xFFFF) || ((ledvalue & LED_VALID) == 0))
12038c2ecf20Sopenharmony_ci			ax88179_convert_old_led(dev, &ledvalue);
12048c2ecf20Sopenharmony_ci	} else {
12058c2ecf20Sopenharmony_ci		ax88179_convert_old_led(dev, &ledvalue);
12068c2ecf20Sopenharmony_ci	}
12078c2ecf20Sopenharmony_ci
12088c2ecf20Sopenharmony_ci	tmp = GMII_PHY_PGSEL_EXT;
12098c2ecf20Sopenharmony_ci	ax88179_write_cmd(dev, AX_ACCESS_PHY, AX88179_PHY_ID,
12108c2ecf20Sopenharmony_ci			  GMII_PHY_PAGE_SELECT, 2, &tmp);
12118c2ecf20Sopenharmony_ci
12128c2ecf20Sopenharmony_ci	tmp = 0x2c;
12138c2ecf20Sopenharmony_ci	ax88179_write_cmd(dev, AX_ACCESS_PHY, AX88179_PHY_ID,
12148c2ecf20Sopenharmony_ci			  GMII_PHYPAGE, 2, &tmp);
12158c2ecf20Sopenharmony_ci
12168c2ecf20Sopenharmony_ci	ax88179_read_cmd(dev, AX_ACCESS_PHY, AX88179_PHY_ID,
12178c2ecf20Sopenharmony_ci			 GMII_LED_ACT, 2, &ledact);
12188c2ecf20Sopenharmony_ci
12198c2ecf20Sopenharmony_ci	ax88179_read_cmd(dev, AX_ACCESS_PHY, AX88179_PHY_ID,
12208c2ecf20Sopenharmony_ci			 GMII_LED_LINK, 2, &ledlink);
12218c2ecf20Sopenharmony_ci
12228c2ecf20Sopenharmony_ci	ledact &= GMII_LED_ACTIVE_MASK;
12238c2ecf20Sopenharmony_ci	ledlink &= GMII_LED_LINK_MASK;
12248c2ecf20Sopenharmony_ci
12258c2ecf20Sopenharmony_ci	if (ledvalue & LED0_ACTIVE)
12268c2ecf20Sopenharmony_ci		ledact |= GMII_LED0_ACTIVE;
12278c2ecf20Sopenharmony_ci
12288c2ecf20Sopenharmony_ci	if (ledvalue & LED1_ACTIVE)
12298c2ecf20Sopenharmony_ci		ledact |= GMII_LED1_ACTIVE;
12308c2ecf20Sopenharmony_ci
12318c2ecf20Sopenharmony_ci	if (ledvalue & LED2_ACTIVE)
12328c2ecf20Sopenharmony_ci		ledact |= GMII_LED2_ACTIVE;
12338c2ecf20Sopenharmony_ci
12348c2ecf20Sopenharmony_ci	if (ledvalue & LED0_LINK_10)
12358c2ecf20Sopenharmony_ci		ledlink |= GMII_LED0_LINK_10;
12368c2ecf20Sopenharmony_ci
12378c2ecf20Sopenharmony_ci	if (ledvalue & LED1_LINK_10)
12388c2ecf20Sopenharmony_ci		ledlink |= GMII_LED1_LINK_10;
12398c2ecf20Sopenharmony_ci
12408c2ecf20Sopenharmony_ci	if (ledvalue & LED2_LINK_10)
12418c2ecf20Sopenharmony_ci		ledlink |= GMII_LED2_LINK_10;
12428c2ecf20Sopenharmony_ci
12438c2ecf20Sopenharmony_ci	if (ledvalue & LED0_LINK_100)
12448c2ecf20Sopenharmony_ci		ledlink |= GMII_LED0_LINK_100;
12458c2ecf20Sopenharmony_ci
12468c2ecf20Sopenharmony_ci	if (ledvalue & LED1_LINK_100)
12478c2ecf20Sopenharmony_ci		ledlink |= GMII_LED1_LINK_100;
12488c2ecf20Sopenharmony_ci
12498c2ecf20Sopenharmony_ci	if (ledvalue & LED2_LINK_100)
12508c2ecf20Sopenharmony_ci		ledlink |= GMII_LED2_LINK_100;
12518c2ecf20Sopenharmony_ci
12528c2ecf20Sopenharmony_ci	if (ledvalue & LED0_LINK_1000)
12538c2ecf20Sopenharmony_ci		ledlink |= GMII_LED0_LINK_1000;
12548c2ecf20Sopenharmony_ci
12558c2ecf20Sopenharmony_ci	if (ledvalue & LED1_LINK_1000)
12568c2ecf20Sopenharmony_ci		ledlink |= GMII_LED1_LINK_1000;
12578c2ecf20Sopenharmony_ci
12588c2ecf20Sopenharmony_ci	if (ledvalue & LED2_LINK_1000)
12598c2ecf20Sopenharmony_ci		ledlink |= GMII_LED2_LINK_1000;
12608c2ecf20Sopenharmony_ci
12618c2ecf20Sopenharmony_ci	tmp = ledact;
12628c2ecf20Sopenharmony_ci	ax88179_write_cmd(dev, AX_ACCESS_PHY, AX88179_PHY_ID,
12638c2ecf20Sopenharmony_ci			  GMII_LED_ACT, 2, &tmp);
12648c2ecf20Sopenharmony_ci
12658c2ecf20Sopenharmony_ci	tmp = ledlink;
12668c2ecf20Sopenharmony_ci	ax88179_write_cmd(dev, AX_ACCESS_PHY, AX88179_PHY_ID,
12678c2ecf20Sopenharmony_ci			  GMII_LED_LINK, 2, &tmp);
12688c2ecf20Sopenharmony_ci
12698c2ecf20Sopenharmony_ci	tmp = GMII_PHY_PGSEL_PAGE0;
12708c2ecf20Sopenharmony_ci	ax88179_write_cmd(dev, AX_ACCESS_PHY, AX88179_PHY_ID,
12718c2ecf20Sopenharmony_ci			  GMII_PHY_PAGE_SELECT, 2, &tmp);
12728c2ecf20Sopenharmony_ci
12738c2ecf20Sopenharmony_ci	/* LED full duplex setting */
12748c2ecf20Sopenharmony_ci	ledfd = 0;
12758c2ecf20Sopenharmony_ci	if (ledvalue & LED0_FD)
12768c2ecf20Sopenharmony_ci		ledfd |= 0x01;
12778c2ecf20Sopenharmony_ci	else if ((ledvalue & LED0_USB3_MASK) == 0)
12788c2ecf20Sopenharmony_ci		ledfd |= 0x02;
12798c2ecf20Sopenharmony_ci
12808c2ecf20Sopenharmony_ci	if (ledvalue & LED1_FD)
12818c2ecf20Sopenharmony_ci		ledfd |= 0x04;
12828c2ecf20Sopenharmony_ci	else if ((ledvalue & LED1_USB3_MASK) == 0)
12838c2ecf20Sopenharmony_ci		ledfd |= 0x08;
12848c2ecf20Sopenharmony_ci
12858c2ecf20Sopenharmony_ci	if (ledvalue & LED2_FD)
12868c2ecf20Sopenharmony_ci		ledfd |= 0x10;
12878c2ecf20Sopenharmony_ci	else if ((ledvalue & LED2_USB3_MASK) == 0)
12888c2ecf20Sopenharmony_ci		ledfd |= 0x20;
12898c2ecf20Sopenharmony_ci
12908c2ecf20Sopenharmony_ci	ax88179_write_cmd(dev, AX_ACCESS_MAC, AX_LEDCTRL, 1, 1, &ledfd);
12918c2ecf20Sopenharmony_ci
12928c2ecf20Sopenharmony_ci	return 0;
12938c2ecf20Sopenharmony_ci}
12948c2ecf20Sopenharmony_ci
12958c2ecf20Sopenharmony_cistatic void ax88179_get_mac_addr(struct usbnet *dev)
12968c2ecf20Sopenharmony_ci{
12978c2ecf20Sopenharmony_ci	u8 mac[ETH_ALEN];
12988c2ecf20Sopenharmony_ci
12998c2ecf20Sopenharmony_ci	memset(mac, 0, sizeof(mac));
13008c2ecf20Sopenharmony_ci
13018c2ecf20Sopenharmony_ci	/* Maybe the boot loader passed the MAC address via device tree */
13028c2ecf20Sopenharmony_ci	if (!eth_platform_get_mac_address(&dev->udev->dev, mac)) {
13038c2ecf20Sopenharmony_ci		netif_dbg(dev, ifup, dev->net,
13048c2ecf20Sopenharmony_ci			  "MAC address read from device tree");
13058c2ecf20Sopenharmony_ci	} else {
13068c2ecf20Sopenharmony_ci		ax88179_read_cmd(dev, AX_ACCESS_MAC, AX_NODE_ID, ETH_ALEN,
13078c2ecf20Sopenharmony_ci				 ETH_ALEN, mac);
13088c2ecf20Sopenharmony_ci		netif_dbg(dev, ifup, dev->net,
13098c2ecf20Sopenharmony_ci			  "MAC address read from ASIX chip");
13108c2ecf20Sopenharmony_ci	}
13118c2ecf20Sopenharmony_ci
13128c2ecf20Sopenharmony_ci	if (is_valid_ether_addr(mac)) {
13138c2ecf20Sopenharmony_ci		memcpy(dev->net->dev_addr, mac, ETH_ALEN);
13148c2ecf20Sopenharmony_ci	} else {
13158c2ecf20Sopenharmony_ci		netdev_info(dev->net, "invalid MAC address, using random\n");
13168c2ecf20Sopenharmony_ci		eth_hw_addr_random(dev->net);
13178c2ecf20Sopenharmony_ci	}
13188c2ecf20Sopenharmony_ci
13198c2ecf20Sopenharmony_ci	ax88179_write_cmd(dev, AX_ACCESS_MAC, AX_NODE_ID, ETH_ALEN, ETH_ALEN,
13208c2ecf20Sopenharmony_ci			  dev->net->dev_addr);
13218c2ecf20Sopenharmony_ci}
13228c2ecf20Sopenharmony_ci
13238c2ecf20Sopenharmony_cistatic int ax88179_bind(struct usbnet *dev, struct usb_interface *intf)
13248c2ecf20Sopenharmony_ci{
13258c2ecf20Sopenharmony_ci	u8 buf[5];
13268c2ecf20Sopenharmony_ci	u16 *tmp16;
13278c2ecf20Sopenharmony_ci	u8 *tmp;
13288c2ecf20Sopenharmony_ci	struct ax88179_data *ax179_data = (struct ax88179_data *)dev->data;
13298c2ecf20Sopenharmony_ci	struct ethtool_eee eee_data;
13308c2ecf20Sopenharmony_ci
13318c2ecf20Sopenharmony_ci	usbnet_get_endpoints(dev, intf);
13328c2ecf20Sopenharmony_ci
13338c2ecf20Sopenharmony_ci	tmp16 = (u16 *)buf;
13348c2ecf20Sopenharmony_ci	tmp = (u8 *)buf;
13358c2ecf20Sopenharmony_ci
13368c2ecf20Sopenharmony_ci	memset(ax179_data, 0, sizeof(*ax179_data));
13378c2ecf20Sopenharmony_ci
13388c2ecf20Sopenharmony_ci	/* Power up ethernet PHY */
13398c2ecf20Sopenharmony_ci	*tmp16 = 0;
13408c2ecf20Sopenharmony_ci	ax88179_write_cmd(dev, AX_ACCESS_MAC, AX_PHYPWR_RSTCTL, 2, 2, tmp16);
13418c2ecf20Sopenharmony_ci	*tmp16 = AX_PHYPWR_RSTCTL_IPRL;
13428c2ecf20Sopenharmony_ci	ax88179_write_cmd(dev, AX_ACCESS_MAC, AX_PHYPWR_RSTCTL, 2, 2, tmp16);
13438c2ecf20Sopenharmony_ci	msleep(200);
13448c2ecf20Sopenharmony_ci
13458c2ecf20Sopenharmony_ci	*tmp = AX_CLK_SELECT_ACS | AX_CLK_SELECT_BCS;
13468c2ecf20Sopenharmony_ci	ax88179_write_cmd(dev, AX_ACCESS_MAC, AX_CLK_SELECT, 1, 1, tmp);
13478c2ecf20Sopenharmony_ci	msleep(100);
13488c2ecf20Sopenharmony_ci
13498c2ecf20Sopenharmony_ci	/* Read MAC address from DTB or asix chip */
13508c2ecf20Sopenharmony_ci	ax88179_get_mac_addr(dev);
13518c2ecf20Sopenharmony_ci	memcpy(dev->net->perm_addr, dev->net->dev_addr, ETH_ALEN);
13528c2ecf20Sopenharmony_ci
13538c2ecf20Sopenharmony_ci	/* RX bulk configuration */
13548c2ecf20Sopenharmony_ci	memcpy(tmp, &AX88179_BULKIN_SIZE[0], 5);
13558c2ecf20Sopenharmony_ci	ax88179_write_cmd(dev, AX_ACCESS_MAC, AX_RX_BULKIN_QCTRL, 5, 5, tmp);
13568c2ecf20Sopenharmony_ci
13578c2ecf20Sopenharmony_ci	dev->rx_urb_size = 1024 * 20;
13588c2ecf20Sopenharmony_ci
13598c2ecf20Sopenharmony_ci	*tmp = 0x34;
13608c2ecf20Sopenharmony_ci	ax88179_write_cmd(dev, AX_ACCESS_MAC, AX_PAUSE_WATERLVL_LOW, 1, 1, tmp);
13618c2ecf20Sopenharmony_ci
13628c2ecf20Sopenharmony_ci	*tmp = 0x52;
13638c2ecf20Sopenharmony_ci	ax88179_write_cmd(dev, AX_ACCESS_MAC, AX_PAUSE_WATERLVL_HIGH,
13648c2ecf20Sopenharmony_ci			  1, 1, tmp);
13658c2ecf20Sopenharmony_ci
13668c2ecf20Sopenharmony_ci	dev->net->netdev_ops = &ax88179_netdev_ops;
13678c2ecf20Sopenharmony_ci	dev->net->ethtool_ops = &ax88179_ethtool_ops;
13688c2ecf20Sopenharmony_ci	dev->net->needed_headroom = 8;
13698c2ecf20Sopenharmony_ci	dev->net->max_mtu = 4088;
13708c2ecf20Sopenharmony_ci
13718c2ecf20Sopenharmony_ci	/* Initialize MII structure */
13728c2ecf20Sopenharmony_ci	dev->mii.dev = dev->net;
13738c2ecf20Sopenharmony_ci	dev->mii.mdio_read = ax88179_mdio_read;
13748c2ecf20Sopenharmony_ci	dev->mii.mdio_write = ax88179_mdio_write;
13758c2ecf20Sopenharmony_ci	dev->mii.phy_id_mask = 0xff;
13768c2ecf20Sopenharmony_ci	dev->mii.reg_num_mask = 0xff;
13778c2ecf20Sopenharmony_ci	dev->mii.phy_id = 0x03;
13788c2ecf20Sopenharmony_ci	dev->mii.supports_gmii = 1;
13798c2ecf20Sopenharmony_ci
13808c2ecf20Sopenharmony_ci	dev->net->features |= NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM |
13818c2ecf20Sopenharmony_ci			      NETIF_F_RXCSUM;
13828c2ecf20Sopenharmony_ci
13838c2ecf20Sopenharmony_ci	dev->net->hw_features |= NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM |
13848c2ecf20Sopenharmony_ci				 NETIF_F_RXCSUM;
13858c2ecf20Sopenharmony_ci
13868c2ecf20Sopenharmony_ci	/* Enable checksum offload */
13878c2ecf20Sopenharmony_ci	*tmp = AX_RXCOE_IP | AX_RXCOE_TCP | AX_RXCOE_UDP |
13888c2ecf20Sopenharmony_ci	       AX_RXCOE_TCPV6 | AX_RXCOE_UDPV6;
13898c2ecf20Sopenharmony_ci	ax88179_write_cmd(dev, AX_ACCESS_MAC, AX_RXCOE_CTL, 1, 1, tmp);
13908c2ecf20Sopenharmony_ci
13918c2ecf20Sopenharmony_ci	*tmp = AX_TXCOE_IP | AX_TXCOE_TCP | AX_TXCOE_UDP |
13928c2ecf20Sopenharmony_ci	       AX_TXCOE_TCPV6 | AX_TXCOE_UDPV6;
13938c2ecf20Sopenharmony_ci	ax88179_write_cmd(dev, AX_ACCESS_MAC, AX_TXCOE_CTL, 1, 1, tmp);
13948c2ecf20Sopenharmony_ci
13958c2ecf20Sopenharmony_ci	/* Configure RX control register => start operation */
13968c2ecf20Sopenharmony_ci	*tmp16 = AX_RX_CTL_DROPCRCERR | AX_RX_CTL_IPE | AX_RX_CTL_START |
13978c2ecf20Sopenharmony_ci		 AX_RX_CTL_AP | AX_RX_CTL_AMALL | AX_RX_CTL_AB;
13988c2ecf20Sopenharmony_ci	ax88179_write_cmd(dev, AX_ACCESS_MAC, AX_RX_CTL, 2, 2, tmp16);
13998c2ecf20Sopenharmony_ci
14008c2ecf20Sopenharmony_ci	*tmp = AX_MONITOR_MODE_PMETYPE | AX_MONITOR_MODE_PMEPOL |
14018c2ecf20Sopenharmony_ci	       AX_MONITOR_MODE_RWMP;
14028c2ecf20Sopenharmony_ci	ax88179_write_cmd(dev, AX_ACCESS_MAC, AX_MONITOR_MOD, 1, 1, tmp);
14038c2ecf20Sopenharmony_ci
14048c2ecf20Sopenharmony_ci	/* Configure default medium type => giga */
14058c2ecf20Sopenharmony_ci	*tmp16 = AX_MEDIUM_RECEIVE_EN | AX_MEDIUM_TXFLOW_CTRLEN |
14068c2ecf20Sopenharmony_ci		 AX_MEDIUM_RXFLOW_CTRLEN | AX_MEDIUM_FULL_DUPLEX |
14078c2ecf20Sopenharmony_ci		 AX_MEDIUM_GIGAMODE;
14088c2ecf20Sopenharmony_ci	ax88179_write_cmd(dev, AX_ACCESS_MAC, AX_MEDIUM_STATUS_MODE,
14098c2ecf20Sopenharmony_ci			  2, 2, tmp16);
14108c2ecf20Sopenharmony_ci
14118c2ecf20Sopenharmony_ci	ax88179_led_setting(dev);
14128c2ecf20Sopenharmony_ci
14138c2ecf20Sopenharmony_ci	ax179_data->eee_enabled = 0;
14148c2ecf20Sopenharmony_ci	ax179_data->eee_active = 0;
14158c2ecf20Sopenharmony_ci
14168c2ecf20Sopenharmony_ci	ax88179_disable_eee(dev);
14178c2ecf20Sopenharmony_ci
14188c2ecf20Sopenharmony_ci	ax88179_ethtool_get_eee(dev, &eee_data);
14198c2ecf20Sopenharmony_ci	eee_data.advertised = 0;
14208c2ecf20Sopenharmony_ci	ax88179_ethtool_set_eee(dev, &eee_data);
14218c2ecf20Sopenharmony_ci
14228c2ecf20Sopenharmony_ci	/* Restart autoneg */
14238c2ecf20Sopenharmony_ci	mii_nway_restart(&dev->mii);
14248c2ecf20Sopenharmony_ci
14258c2ecf20Sopenharmony_ci	usbnet_link_change(dev, 0, 0);
14268c2ecf20Sopenharmony_ci
14278c2ecf20Sopenharmony_ci	return 0;
14288c2ecf20Sopenharmony_ci}
14298c2ecf20Sopenharmony_ci
14308c2ecf20Sopenharmony_cistatic void ax88179_unbind(struct usbnet *dev, struct usb_interface *intf)
14318c2ecf20Sopenharmony_ci{
14328c2ecf20Sopenharmony_ci	u16 tmp16;
14338c2ecf20Sopenharmony_ci
14348c2ecf20Sopenharmony_ci	/* Configure RX control register => stop operation */
14358c2ecf20Sopenharmony_ci	tmp16 = AX_RX_CTL_STOP;
14368c2ecf20Sopenharmony_ci	ax88179_write_cmd(dev, AX_ACCESS_MAC, AX_RX_CTL, 2, 2, &tmp16);
14378c2ecf20Sopenharmony_ci
14388c2ecf20Sopenharmony_ci	tmp16 = 0;
14398c2ecf20Sopenharmony_ci	ax88179_write_cmd(dev, AX_ACCESS_MAC, AX_CLK_SELECT, 1, 1, &tmp16);
14408c2ecf20Sopenharmony_ci
14418c2ecf20Sopenharmony_ci	/* Power down ethernet PHY */
14428c2ecf20Sopenharmony_ci	tmp16 = 0;
14438c2ecf20Sopenharmony_ci	ax88179_write_cmd(dev, AX_ACCESS_MAC, AX_PHYPWR_RSTCTL, 2, 2, &tmp16);
14448c2ecf20Sopenharmony_ci}
14458c2ecf20Sopenharmony_ci
14468c2ecf20Sopenharmony_cistatic void
14478c2ecf20Sopenharmony_ciax88179_rx_checksum(struct sk_buff *skb, u32 *pkt_hdr)
14488c2ecf20Sopenharmony_ci{
14498c2ecf20Sopenharmony_ci	skb->ip_summed = CHECKSUM_NONE;
14508c2ecf20Sopenharmony_ci
14518c2ecf20Sopenharmony_ci	/* checksum error bit is set */
14528c2ecf20Sopenharmony_ci	if ((*pkt_hdr & AX_RXHDR_L3CSUM_ERR) ||
14538c2ecf20Sopenharmony_ci	    (*pkt_hdr & AX_RXHDR_L4CSUM_ERR))
14548c2ecf20Sopenharmony_ci		return;
14558c2ecf20Sopenharmony_ci
14568c2ecf20Sopenharmony_ci	/* It must be a TCP or UDP packet with a valid checksum */
14578c2ecf20Sopenharmony_ci	if (((*pkt_hdr & AX_RXHDR_L4_TYPE_MASK) == AX_RXHDR_L4_TYPE_TCP) ||
14588c2ecf20Sopenharmony_ci	    ((*pkt_hdr & AX_RXHDR_L4_TYPE_MASK) == AX_RXHDR_L4_TYPE_UDP))
14598c2ecf20Sopenharmony_ci		skb->ip_summed = CHECKSUM_UNNECESSARY;
14608c2ecf20Sopenharmony_ci}
14618c2ecf20Sopenharmony_ci
14628c2ecf20Sopenharmony_cistatic int ax88179_rx_fixup(struct usbnet *dev, struct sk_buff *skb)
14638c2ecf20Sopenharmony_ci{
14648c2ecf20Sopenharmony_ci	struct sk_buff *ax_skb;
14658c2ecf20Sopenharmony_ci	int pkt_cnt;
14668c2ecf20Sopenharmony_ci	u32 rx_hdr;
14678c2ecf20Sopenharmony_ci	u16 hdr_off;
14688c2ecf20Sopenharmony_ci	u32 *pkt_hdr;
14698c2ecf20Sopenharmony_ci
14708c2ecf20Sopenharmony_ci	/* At the end of the SKB, there's a header telling us how many packets
14718c2ecf20Sopenharmony_ci	 * are bundled into this buffer and where we can find an array of
14728c2ecf20Sopenharmony_ci	 * per-packet metadata (which contains elements encoded into u16).
14738c2ecf20Sopenharmony_ci	 */
14748c2ecf20Sopenharmony_ci
14758c2ecf20Sopenharmony_ci	/* SKB contents for current firmware:
14768c2ecf20Sopenharmony_ci	 *   <packet 1> <padding>
14778c2ecf20Sopenharmony_ci	 *   ...
14788c2ecf20Sopenharmony_ci	 *   <packet N> <padding>
14798c2ecf20Sopenharmony_ci	 *   <per-packet metadata entry 1> <dummy header>
14808c2ecf20Sopenharmony_ci	 *   ...
14818c2ecf20Sopenharmony_ci	 *   <per-packet metadata entry N> <dummy header>
14828c2ecf20Sopenharmony_ci	 *   <padding2> <rx_hdr>
14838c2ecf20Sopenharmony_ci	 *
14848c2ecf20Sopenharmony_ci	 * where:
14858c2ecf20Sopenharmony_ci	 *   <packet N> contains pkt_len bytes:
14868c2ecf20Sopenharmony_ci	 *		2 bytes of IP alignment pseudo header
14878c2ecf20Sopenharmony_ci	 *		packet received
14888c2ecf20Sopenharmony_ci	 *   <per-packet metadata entry N> contains 4 bytes:
14898c2ecf20Sopenharmony_ci	 *		pkt_len and fields AX_RXHDR_*
14908c2ecf20Sopenharmony_ci	 *   <padding>	0-7 bytes to terminate at
14918c2ecf20Sopenharmony_ci	 *		8 bytes boundary (64-bit).
14928c2ecf20Sopenharmony_ci	 *   <padding2> 4 bytes to make rx_hdr terminate at
14938c2ecf20Sopenharmony_ci	 *		8 bytes boundary (64-bit)
14948c2ecf20Sopenharmony_ci	 *   <dummy-header> contains 4 bytes:
14958c2ecf20Sopenharmony_ci	 *		pkt_len=0 and AX_RXHDR_DROP_ERR
14968c2ecf20Sopenharmony_ci	 *   <rx-hdr>	contains 4 bytes:
14978c2ecf20Sopenharmony_ci	 *		pkt_cnt and hdr_off (offset of
14988c2ecf20Sopenharmony_ci	 *		  <per-packet metadata entry 1>)
14998c2ecf20Sopenharmony_ci	 *
15008c2ecf20Sopenharmony_ci	 * pkt_cnt is number of entrys in the per-packet metadata.
15018c2ecf20Sopenharmony_ci	 * In current firmware there is 2 entrys per packet.
15028c2ecf20Sopenharmony_ci	 * The first points to the packet and the
15038c2ecf20Sopenharmony_ci	 *  second is a dummy header.
15048c2ecf20Sopenharmony_ci	 * This was done probably to align fields in 64-bit and
15058c2ecf20Sopenharmony_ci	 *  maintain compatibility with old firmware.
15068c2ecf20Sopenharmony_ci	 * This code assumes that <dummy header> and <padding2> are
15078c2ecf20Sopenharmony_ci	 *  optional.
15088c2ecf20Sopenharmony_ci	 */
15098c2ecf20Sopenharmony_ci
15108c2ecf20Sopenharmony_ci	if (skb->len < 4)
15118c2ecf20Sopenharmony_ci		return 0;
15128c2ecf20Sopenharmony_ci	skb_trim(skb, skb->len - 4);
15138c2ecf20Sopenharmony_ci	rx_hdr = get_unaligned_le32(skb_tail_pointer(skb));
15148c2ecf20Sopenharmony_ci	pkt_cnt = (u16)rx_hdr;
15158c2ecf20Sopenharmony_ci	hdr_off = (u16)(rx_hdr >> 16);
15168c2ecf20Sopenharmony_ci
15178c2ecf20Sopenharmony_ci	if (pkt_cnt == 0)
15188c2ecf20Sopenharmony_ci		return 0;
15198c2ecf20Sopenharmony_ci
15208c2ecf20Sopenharmony_ci	/* Make sure that the bounds of the metadata array are inside the SKB
15218c2ecf20Sopenharmony_ci	 * (and in front of the counter at the end).
15228c2ecf20Sopenharmony_ci	 */
15238c2ecf20Sopenharmony_ci	if (pkt_cnt * 4 + hdr_off > skb->len)
15248c2ecf20Sopenharmony_ci		return 0;
15258c2ecf20Sopenharmony_ci	pkt_hdr = (u32 *)(skb->data + hdr_off);
15268c2ecf20Sopenharmony_ci
15278c2ecf20Sopenharmony_ci	/* Packets must not overlap the metadata array */
15288c2ecf20Sopenharmony_ci	skb_trim(skb, hdr_off);
15298c2ecf20Sopenharmony_ci
15308c2ecf20Sopenharmony_ci	for (; pkt_cnt > 0; pkt_cnt--, pkt_hdr++) {
15318c2ecf20Sopenharmony_ci		u16 pkt_len_plus_padd;
15328c2ecf20Sopenharmony_ci		u16 pkt_len;
15338c2ecf20Sopenharmony_ci
15348c2ecf20Sopenharmony_ci		le32_to_cpus(pkt_hdr);
15358c2ecf20Sopenharmony_ci		pkt_len = (*pkt_hdr >> 16) & 0x1fff;
15368c2ecf20Sopenharmony_ci		pkt_len_plus_padd = (pkt_len + 7) & 0xfff8;
15378c2ecf20Sopenharmony_ci
15388c2ecf20Sopenharmony_ci		/* Skip dummy header used for alignment
15398c2ecf20Sopenharmony_ci		 */
15408c2ecf20Sopenharmony_ci		if (pkt_len == 0)
15418c2ecf20Sopenharmony_ci			continue;
15428c2ecf20Sopenharmony_ci
15438c2ecf20Sopenharmony_ci		if (pkt_len_plus_padd > skb->len)
15448c2ecf20Sopenharmony_ci			return 0;
15458c2ecf20Sopenharmony_ci
15468c2ecf20Sopenharmony_ci		/* Check CRC or runt packet */
15478c2ecf20Sopenharmony_ci		if ((*pkt_hdr & (AX_RXHDR_CRC_ERR | AX_RXHDR_DROP_ERR)) ||
15488c2ecf20Sopenharmony_ci		    pkt_len < 2 + ETH_HLEN) {
15498c2ecf20Sopenharmony_ci			dev->net->stats.rx_errors++;
15508c2ecf20Sopenharmony_ci			skb_pull(skb, pkt_len_plus_padd);
15518c2ecf20Sopenharmony_ci			continue;
15528c2ecf20Sopenharmony_ci		}
15538c2ecf20Sopenharmony_ci
15548c2ecf20Sopenharmony_ci		/* last packet */
15558c2ecf20Sopenharmony_ci		if (pkt_len_plus_padd == skb->len) {
15568c2ecf20Sopenharmony_ci			skb_trim(skb, pkt_len);
15578c2ecf20Sopenharmony_ci
15588c2ecf20Sopenharmony_ci			/* Skip IP alignment pseudo header */
15598c2ecf20Sopenharmony_ci			skb_pull(skb, 2);
15608c2ecf20Sopenharmony_ci
15618c2ecf20Sopenharmony_ci			skb->truesize = SKB_TRUESIZE(pkt_len_plus_padd);
15628c2ecf20Sopenharmony_ci			ax88179_rx_checksum(skb, pkt_hdr);
15638c2ecf20Sopenharmony_ci			return 1;
15648c2ecf20Sopenharmony_ci		}
15658c2ecf20Sopenharmony_ci
15668c2ecf20Sopenharmony_ci		ax_skb = skb_clone(skb, GFP_ATOMIC);
15678c2ecf20Sopenharmony_ci		if (!ax_skb)
15688c2ecf20Sopenharmony_ci			return 0;
15698c2ecf20Sopenharmony_ci		skb_trim(ax_skb, pkt_len);
15708c2ecf20Sopenharmony_ci
15718c2ecf20Sopenharmony_ci		/* Skip IP alignment pseudo header */
15728c2ecf20Sopenharmony_ci		skb_pull(ax_skb, 2);
15738c2ecf20Sopenharmony_ci
15748c2ecf20Sopenharmony_ci		skb->truesize = pkt_len_plus_padd +
15758c2ecf20Sopenharmony_ci				SKB_DATA_ALIGN(sizeof(struct sk_buff));
15768c2ecf20Sopenharmony_ci		ax88179_rx_checksum(ax_skb, pkt_hdr);
15778c2ecf20Sopenharmony_ci		usbnet_skb_return(dev, ax_skb);
15788c2ecf20Sopenharmony_ci
15798c2ecf20Sopenharmony_ci		skb_pull(skb, pkt_len_plus_padd);
15808c2ecf20Sopenharmony_ci	}
15818c2ecf20Sopenharmony_ci
15828c2ecf20Sopenharmony_ci	return 0;
15838c2ecf20Sopenharmony_ci}
15848c2ecf20Sopenharmony_ci
15858c2ecf20Sopenharmony_cistatic struct sk_buff *
15868c2ecf20Sopenharmony_ciax88179_tx_fixup(struct usbnet *dev, struct sk_buff *skb, gfp_t flags)
15878c2ecf20Sopenharmony_ci{
15888c2ecf20Sopenharmony_ci	u32 tx_hdr1, tx_hdr2;
15898c2ecf20Sopenharmony_ci	int frame_size = dev->maxpacket;
15908c2ecf20Sopenharmony_ci	int mss = skb_shinfo(skb)->gso_size;
15918c2ecf20Sopenharmony_ci	int headroom;
15928c2ecf20Sopenharmony_ci	void *ptr;
15938c2ecf20Sopenharmony_ci
15948c2ecf20Sopenharmony_ci	tx_hdr1 = skb->len;
15958c2ecf20Sopenharmony_ci	tx_hdr2 = mss;
15968c2ecf20Sopenharmony_ci	if (((skb->len + 8) % frame_size) == 0)
15978c2ecf20Sopenharmony_ci		tx_hdr2 |= 0x80008000;	/* Enable padding */
15988c2ecf20Sopenharmony_ci
15998c2ecf20Sopenharmony_ci	headroom = skb_headroom(skb) - 8;
16008c2ecf20Sopenharmony_ci
16018c2ecf20Sopenharmony_ci	if ((skb_header_cloned(skb) || headroom < 0) &&
16028c2ecf20Sopenharmony_ci	    pskb_expand_head(skb, headroom < 0 ? 8 : 0, 0, GFP_ATOMIC)) {
16038c2ecf20Sopenharmony_ci		dev_kfree_skb_any(skb);
16048c2ecf20Sopenharmony_ci		return NULL;
16058c2ecf20Sopenharmony_ci	}
16068c2ecf20Sopenharmony_ci
16078c2ecf20Sopenharmony_ci	ptr = skb_push(skb, 8);
16088c2ecf20Sopenharmony_ci	put_unaligned_le32(tx_hdr1, ptr);
16098c2ecf20Sopenharmony_ci	put_unaligned_le32(tx_hdr2, ptr + 4);
16108c2ecf20Sopenharmony_ci
16118c2ecf20Sopenharmony_ci	return skb;
16128c2ecf20Sopenharmony_ci}
16138c2ecf20Sopenharmony_ci
16148c2ecf20Sopenharmony_cistatic int ax88179_link_reset(struct usbnet *dev)
16158c2ecf20Sopenharmony_ci{
16168c2ecf20Sopenharmony_ci	struct ax88179_data *ax179_data = (struct ax88179_data *)dev->data;
16178c2ecf20Sopenharmony_ci	u8 tmp[5], link_sts;
16188c2ecf20Sopenharmony_ci	u16 mode, tmp16, delay = HZ / 10;
16198c2ecf20Sopenharmony_ci	u32 tmp32 = 0x40000000;
16208c2ecf20Sopenharmony_ci	unsigned long jtimeout;
16218c2ecf20Sopenharmony_ci
16228c2ecf20Sopenharmony_ci	jtimeout = jiffies + delay;
16238c2ecf20Sopenharmony_ci	while (tmp32 & 0x40000000) {
16248c2ecf20Sopenharmony_ci		mode = 0;
16258c2ecf20Sopenharmony_ci		ax88179_write_cmd(dev, AX_ACCESS_MAC, AX_RX_CTL, 2, 2, &mode);
16268c2ecf20Sopenharmony_ci		ax88179_write_cmd(dev, AX_ACCESS_MAC, AX_RX_CTL, 2, 2,
16278c2ecf20Sopenharmony_ci				  &ax179_data->rxctl);
16288c2ecf20Sopenharmony_ci
16298c2ecf20Sopenharmony_ci		/*link up, check the usb device control TX FIFO full or empty*/
16308c2ecf20Sopenharmony_ci		ax88179_read_cmd(dev, 0x81, 0x8c, 0, 4, &tmp32);
16318c2ecf20Sopenharmony_ci
16328c2ecf20Sopenharmony_ci		if (time_after(jiffies, jtimeout))
16338c2ecf20Sopenharmony_ci			return 0;
16348c2ecf20Sopenharmony_ci	}
16358c2ecf20Sopenharmony_ci
16368c2ecf20Sopenharmony_ci	mode = AX_MEDIUM_RECEIVE_EN | AX_MEDIUM_TXFLOW_CTRLEN |
16378c2ecf20Sopenharmony_ci	       AX_MEDIUM_RXFLOW_CTRLEN;
16388c2ecf20Sopenharmony_ci
16398c2ecf20Sopenharmony_ci	ax88179_read_cmd(dev, AX_ACCESS_MAC, PHYSICAL_LINK_STATUS,
16408c2ecf20Sopenharmony_ci			 1, 1, &link_sts);
16418c2ecf20Sopenharmony_ci
16428c2ecf20Sopenharmony_ci	ax88179_read_cmd(dev, AX_ACCESS_PHY, AX88179_PHY_ID,
16438c2ecf20Sopenharmony_ci			 GMII_PHY_PHYSR, 2, &tmp16);
16448c2ecf20Sopenharmony_ci
16458c2ecf20Sopenharmony_ci	if (!(tmp16 & GMII_PHY_PHYSR_LINK)) {
16468c2ecf20Sopenharmony_ci		return 0;
16478c2ecf20Sopenharmony_ci	} else if (GMII_PHY_PHYSR_GIGA == (tmp16 & GMII_PHY_PHYSR_SMASK)) {
16488c2ecf20Sopenharmony_ci		mode |= AX_MEDIUM_GIGAMODE | AX_MEDIUM_EN_125MHZ;
16498c2ecf20Sopenharmony_ci		if (dev->net->mtu > 1500)
16508c2ecf20Sopenharmony_ci			mode |= AX_MEDIUM_JUMBO_EN;
16518c2ecf20Sopenharmony_ci
16528c2ecf20Sopenharmony_ci		if (link_sts & AX_USB_SS)
16538c2ecf20Sopenharmony_ci			memcpy(tmp, &AX88179_BULKIN_SIZE[0], 5);
16548c2ecf20Sopenharmony_ci		else if (link_sts & AX_USB_HS)
16558c2ecf20Sopenharmony_ci			memcpy(tmp, &AX88179_BULKIN_SIZE[1], 5);
16568c2ecf20Sopenharmony_ci		else
16578c2ecf20Sopenharmony_ci			memcpy(tmp, &AX88179_BULKIN_SIZE[3], 5);
16588c2ecf20Sopenharmony_ci	} else if (GMII_PHY_PHYSR_100 == (tmp16 & GMII_PHY_PHYSR_SMASK)) {
16598c2ecf20Sopenharmony_ci		mode |= AX_MEDIUM_PS;
16608c2ecf20Sopenharmony_ci
16618c2ecf20Sopenharmony_ci		if (link_sts & (AX_USB_SS | AX_USB_HS))
16628c2ecf20Sopenharmony_ci			memcpy(tmp, &AX88179_BULKIN_SIZE[2], 5);
16638c2ecf20Sopenharmony_ci		else
16648c2ecf20Sopenharmony_ci			memcpy(tmp, &AX88179_BULKIN_SIZE[3], 5);
16658c2ecf20Sopenharmony_ci	} else {
16668c2ecf20Sopenharmony_ci		memcpy(tmp, &AX88179_BULKIN_SIZE[3], 5);
16678c2ecf20Sopenharmony_ci	}
16688c2ecf20Sopenharmony_ci
16698c2ecf20Sopenharmony_ci	/* RX bulk configuration */
16708c2ecf20Sopenharmony_ci	ax88179_write_cmd(dev, AX_ACCESS_MAC, AX_RX_BULKIN_QCTRL, 5, 5, tmp);
16718c2ecf20Sopenharmony_ci
16728c2ecf20Sopenharmony_ci	dev->rx_urb_size = (1024 * (tmp[3] + 2));
16738c2ecf20Sopenharmony_ci
16748c2ecf20Sopenharmony_ci	if (tmp16 & GMII_PHY_PHYSR_FULL)
16758c2ecf20Sopenharmony_ci		mode |= AX_MEDIUM_FULL_DUPLEX;
16768c2ecf20Sopenharmony_ci	ax88179_write_cmd(dev, AX_ACCESS_MAC, AX_MEDIUM_STATUS_MODE,
16778c2ecf20Sopenharmony_ci			  2, 2, &mode);
16788c2ecf20Sopenharmony_ci
16798c2ecf20Sopenharmony_ci	ax179_data->eee_enabled = ax88179_chk_eee(dev);
16808c2ecf20Sopenharmony_ci
16818c2ecf20Sopenharmony_ci	netif_carrier_on(dev->net);
16828c2ecf20Sopenharmony_ci
16838c2ecf20Sopenharmony_ci	return 0;
16848c2ecf20Sopenharmony_ci}
16858c2ecf20Sopenharmony_ci
16868c2ecf20Sopenharmony_cistatic int ax88179_reset(struct usbnet *dev)
16878c2ecf20Sopenharmony_ci{
16888c2ecf20Sopenharmony_ci	u8 buf[5];
16898c2ecf20Sopenharmony_ci	u16 *tmp16;
16908c2ecf20Sopenharmony_ci	u8 *tmp;
16918c2ecf20Sopenharmony_ci	struct ax88179_data *ax179_data = (struct ax88179_data *)dev->data;
16928c2ecf20Sopenharmony_ci	struct ethtool_eee eee_data;
16938c2ecf20Sopenharmony_ci
16948c2ecf20Sopenharmony_ci	tmp16 = (u16 *)buf;
16958c2ecf20Sopenharmony_ci	tmp = (u8 *)buf;
16968c2ecf20Sopenharmony_ci
16978c2ecf20Sopenharmony_ci	/* Power up ethernet PHY */
16988c2ecf20Sopenharmony_ci	*tmp16 = 0;
16998c2ecf20Sopenharmony_ci	ax88179_write_cmd(dev, AX_ACCESS_MAC, AX_PHYPWR_RSTCTL, 2, 2, tmp16);
17008c2ecf20Sopenharmony_ci
17018c2ecf20Sopenharmony_ci	*tmp16 = AX_PHYPWR_RSTCTL_IPRL;
17028c2ecf20Sopenharmony_ci	ax88179_write_cmd(dev, AX_ACCESS_MAC, AX_PHYPWR_RSTCTL, 2, 2, tmp16);
17038c2ecf20Sopenharmony_ci	msleep(500);
17048c2ecf20Sopenharmony_ci
17058c2ecf20Sopenharmony_ci	*tmp = AX_CLK_SELECT_ACS | AX_CLK_SELECT_BCS;
17068c2ecf20Sopenharmony_ci	ax88179_write_cmd(dev, AX_ACCESS_MAC, AX_CLK_SELECT, 1, 1, tmp);
17078c2ecf20Sopenharmony_ci	msleep(200);
17088c2ecf20Sopenharmony_ci
17098c2ecf20Sopenharmony_ci	/* Ethernet PHY Auto Detach*/
17108c2ecf20Sopenharmony_ci	ax88179_auto_detach(dev, 0);
17118c2ecf20Sopenharmony_ci
17128c2ecf20Sopenharmony_ci	/* Read MAC address from DTB or asix chip */
17138c2ecf20Sopenharmony_ci	ax88179_get_mac_addr(dev);
17148c2ecf20Sopenharmony_ci
17158c2ecf20Sopenharmony_ci	/* RX bulk configuration */
17168c2ecf20Sopenharmony_ci	memcpy(tmp, &AX88179_BULKIN_SIZE[0], 5);
17178c2ecf20Sopenharmony_ci	ax88179_write_cmd(dev, AX_ACCESS_MAC, AX_RX_BULKIN_QCTRL, 5, 5, tmp);
17188c2ecf20Sopenharmony_ci
17198c2ecf20Sopenharmony_ci	dev->rx_urb_size = 1024 * 20;
17208c2ecf20Sopenharmony_ci
17218c2ecf20Sopenharmony_ci	*tmp = 0x34;
17228c2ecf20Sopenharmony_ci	ax88179_write_cmd(dev, AX_ACCESS_MAC, AX_PAUSE_WATERLVL_LOW, 1, 1, tmp);
17238c2ecf20Sopenharmony_ci
17248c2ecf20Sopenharmony_ci	*tmp = 0x52;
17258c2ecf20Sopenharmony_ci	ax88179_write_cmd(dev, AX_ACCESS_MAC, AX_PAUSE_WATERLVL_HIGH,
17268c2ecf20Sopenharmony_ci			  1, 1, tmp);
17278c2ecf20Sopenharmony_ci
17288c2ecf20Sopenharmony_ci	dev->net->features |= NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM |
17298c2ecf20Sopenharmony_ci			      NETIF_F_RXCSUM;
17308c2ecf20Sopenharmony_ci
17318c2ecf20Sopenharmony_ci	dev->net->hw_features |= NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM |
17328c2ecf20Sopenharmony_ci				 NETIF_F_RXCSUM;
17338c2ecf20Sopenharmony_ci
17348c2ecf20Sopenharmony_ci	/* Enable checksum offload */
17358c2ecf20Sopenharmony_ci	*tmp = AX_RXCOE_IP | AX_RXCOE_TCP | AX_RXCOE_UDP |
17368c2ecf20Sopenharmony_ci	       AX_RXCOE_TCPV6 | AX_RXCOE_UDPV6;
17378c2ecf20Sopenharmony_ci	ax88179_write_cmd(dev, AX_ACCESS_MAC, AX_RXCOE_CTL, 1, 1, tmp);
17388c2ecf20Sopenharmony_ci
17398c2ecf20Sopenharmony_ci	*tmp = AX_TXCOE_IP | AX_TXCOE_TCP | AX_TXCOE_UDP |
17408c2ecf20Sopenharmony_ci	       AX_TXCOE_TCPV6 | AX_TXCOE_UDPV6;
17418c2ecf20Sopenharmony_ci	ax88179_write_cmd(dev, AX_ACCESS_MAC, AX_TXCOE_CTL, 1, 1, tmp);
17428c2ecf20Sopenharmony_ci
17438c2ecf20Sopenharmony_ci	/* Configure RX control register => start operation */
17448c2ecf20Sopenharmony_ci	*tmp16 = AX_RX_CTL_DROPCRCERR | AX_RX_CTL_IPE | AX_RX_CTL_START |
17458c2ecf20Sopenharmony_ci		 AX_RX_CTL_AP | AX_RX_CTL_AMALL | AX_RX_CTL_AB;
17468c2ecf20Sopenharmony_ci	ax88179_write_cmd(dev, AX_ACCESS_MAC, AX_RX_CTL, 2, 2, tmp16);
17478c2ecf20Sopenharmony_ci
17488c2ecf20Sopenharmony_ci	*tmp = AX_MONITOR_MODE_PMETYPE | AX_MONITOR_MODE_PMEPOL |
17498c2ecf20Sopenharmony_ci	       AX_MONITOR_MODE_RWMP;
17508c2ecf20Sopenharmony_ci	ax88179_write_cmd(dev, AX_ACCESS_MAC, AX_MONITOR_MOD, 1, 1, tmp);
17518c2ecf20Sopenharmony_ci
17528c2ecf20Sopenharmony_ci	/* Configure default medium type => giga */
17538c2ecf20Sopenharmony_ci	*tmp16 = AX_MEDIUM_RECEIVE_EN | AX_MEDIUM_TXFLOW_CTRLEN |
17548c2ecf20Sopenharmony_ci		 AX_MEDIUM_RXFLOW_CTRLEN | AX_MEDIUM_FULL_DUPLEX |
17558c2ecf20Sopenharmony_ci		 AX_MEDIUM_GIGAMODE;
17568c2ecf20Sopenharmony_ci	ax88179_write_cmd(dev, AX_ACCESS_MAC, AX_MEDIUM_STATUS_MODE,
17578c2ecf20Sopenharmony_ci			  2, 2, tmp16);
17588c2ecf20Sopenharmony_ci
17598c2ecf20Sopenharmony_ci	ax88179_led_setting(dev);
17608c2ecf20Sopenharmony_ci
17618c2ecf20Sopenharmony_ci	ax179_data->eee_enabled = 0;
17628c2ecf20Sopenharmony_ci	ax179_data->eee_active = 0;
17638c2ecf20Sopenharmony_ci
17648c2ecf20Sopenharmony_ci	ax88179_disable_eee(dev);
17658c2ecf20Sopenharmony_ci
17668c2ecf20Sopenharmony_ci	ax88179_ethtool_get_eee(dev, &eee_data);
17678c2ecf20Sopenharmony_ci	eee_data.advertised = 0;
17688c2ecf20Sopenharmony_ci	ax88179_ethtool_set_eee(dev, &eee_data);
17698c2ecf20Sopenharmony_ci
17708c2ecf20Sopenharmony_ci	/* Restart autoneg */
17718c2ecf20Sopenharmony_ci	mii_nway_restart(&dev->mii);
17728c2ecf20Sopenharmony_ci
17738c2ecf20Sopenharmony_ci	usbnet_link_change(dev, 0, 0);
17748c2ecf20Sopenharmony_ci
17758c2ecf20Sopenharmony_ci	return 0;
17768c2ecf20Sopenharmony_ci}
17778c2ecf20Sopenharmony_ci
17788c2ecf20Sopenharmony_cistatic int ax88179_stop(struct usbnet *dev)
17798c2ecf20Sopenharmony_ci{
17808c2ecf20Sopenharmony_ci	u16 tmp16;
17818c2ecf20Sopenharmony_ci
17828c2ecf20Sopenharmony_ci	ax88179_read_cmd(dev, AX_ACCESS_MAC, AX_MEDIUM_STATUS_MODE,
17838c2ecf20Sopenharmony_ci			 2, 2, &tmp16);
17848c2ecf20Sopenharmony_ci	tmp16 &= ~AX_MEDIUM_RECEIVE_EN;
17858c2ecf20Sopenharmony_ci	ax88179_write_cmd(dev, AX_ACCESS_MAC, AX_MEDIUM_STATUS_MODE,
17868c2ecf20Sopenharmony_ci			  2, 2, &tmp16);
17878c2ecf20Sopenharmony_ci
17888c2ecf20Sopenharmony_ci	return 0;
17898c2ecf20Sopenharmony_ci}
17908c2ecf20Sopenharmony_ci
17918c2ecf20Sopenharmony_cistatic const struct driver_info ax88179_info = {
17928c2ecf20Sopenharmony_ci	.description = "ASIX AX88179 USB 3.0 Gigabit Ethernet",
17938c2ecf20Sopenharmony_ci	.bind = ax88179_bind,
17948c2ecf20Sopenharmony_ci	.unbind = ax88179_unbind,
17958c2ecf20Sopenharmony_ci	.status = ax88179_status,
17968c2ecf20Sopenharmony_ci	.link_reset = ax88179_link_reset,
17978c2ecf20Sopenharmony_ci	.reset = ax88179_reset,
17988c2ecf20Sopenharmony_ci	.stop = ax88179_stop,
17998c2ecf20Sopenharmony_ci	.flags = FLAG_ETHER | FLAG_FRAMING_AX,
18008c2ecf20Sopenharmony_ci	.rx_fixup = ax88179_rx_fixup,
18018c2ecf20Sopenharmony_ci	.tx_fixup = ax88179_tx_fixup,
18028c2ecf20Sopenharmony_ci};
18038c2ecf20Sopenharmony_ci
18048c2ecf20Sopenharmony_cistatic const struct driver_info ax88178a_info = {
18058c2ecf20Sopenharmony_ci	.description = "ASIX AX88178A USB 2.0 Gigabit Ethernet",
18068c2ecf20Sopenharmony_ci	.bind = ax88179_bind,
18078c2ecf20Sopenharmony_ci	.unbind = ax88179_unbind,
18088c2ecf20Sopenharmony_ci	.status = ax88179_status,
18098c2ecf20Sopenharmony_ci	.link_reset = ax88179_link_reset,
18108c2ecf20Sopenharmony_ci	.reset = ax88179_reset,
18118c2ecf20Sopenharmony_ci	.stop = ax88179_stop,
18128c2ecf20Sopenharmony_ci	.flags = FLAG_ETHER | FLAG_FRAMING_AX,
18138c2ecf20Sopenharmony_ci	.rx_fixup = ax88179_rx_fixup,
18148c2ecf20Sopenharmony_ci	.tx_fixup = ax88179_tx_fixup,
18158c2ecf20Sopenharmony_ci};
18168c2ecf20Sopenharmony_ci
18178c2ecf20Sopenharmony_cistatic const struct driver_info cypress_GX3_info = {
18188c2ecf20Sopenharmony_ci	.description = "Cypress GX3 SuperSpeed to Gigabit Ethernet Controller",
18198c2ecf20Sopenharmony_ci	.bind = ax88179_bind,
18208c2ecf20Sopenharmony_ci	.unbind = ax88179_unbind,
18218c2ecf20Sopenharmony_ci	.status = ax88179_status,
18228c2ecf20Sopenharmony_ci	.link_reset = ax88179_link_reset,
18238c2ecf20Sopenharmony_ci	.reset = ax88179_reset,
18248c2ecf20Sopenharmony_ci	.stop = ax88179_stop,
18258c2ecf20Sopenharmony_ci	.flags = FLAG_ETHER | FLAG_FRAMING_AX,
18268c2ecf20Sopenharmony_ci	.rx_fixup = ax88179_rx_fixup,
18278c2ecf20Sopenharmony_ci	.tx_fixup = ax88179_tx_fixup,
18288c2ecf20Sopenharmony_ci};
18298c2ecf20Sopenharmony_ci
18308c2ecf20Sopenharmony_cistatic const struct driver_info dlink_dub1312_info = {
18318c2ecf20Sopenharmony_ci	.description = "D-Link DUB-1312 USB 3.0 to Gigabit Ethernet Adapter",
18328c2ecf20Sopenharmony_ci	.bind = ax88179_bind,
18338c2ecf20Sopenharmony_ci	.unbind = ax88179_unbind,
18348c2ecf20Sopenharmony_ci	.status = ax88179_status,
18358c2ecf20Sopenharmony_ci	.link_reset = ax88179_link_reset,
18368c2ecf20Sopenharmony_ci	.reset = ax88179_reset,
18378c2ecf20Sopenharmony_ci	.stop = ax88179_stop,
18388c2ecf20Sopenharmony_ci	.flags = FLAG_ETHER | FLAG_FRAMING_AX,
18398c2ecf20Sopenharmony_ci	.rx_fixup = ax88179_rx_fixup,
18408c2ecf20Sopenharmony_ci	.tx_fixup = ax88179_tx_fixup,
18418c2ecf20Sopenharmony_ci};
18428c2ecf20Sopenharmony_ci
18438c2ecf20Sopenharmony_cistatic const struct driver_info sitecom_info = {
18448c2ecf20Sopenharmony_ci	.description = "Sitecom USB 3.0 to Gigabit Adapter",
18458c2ecf20Sopenharmony_ci	.bind = ax88179_bind,
18468c2ecf20Sopenharmony_ci	.unbind = ax88179_unbind,
18478c2ecf20Sopenharmony_ci	.status = ax88179_status,
18488c2ecf20Sopenharmony_ci	.link_reset = ax88179_link_reset,
18498c2ecf20Sopenharmony_ci	.reset = ax88179_reset,
18508c2ecf20Sopenharmony_ci	.stop = ax88179_stop,
18518c2ecf20Sopenharmony_ci	.flags = FLAG_ETHER | FLAG_FRAMING_AX,
18528c2ecf20Sopenharmony_ci	.rx_fixup = ax88179_rx_fixup,
18538c2ecf20Sopenharmony_ci	.tx_fixup = ax88179_tx_fixup,
18548c2ecf20Sopenharmony_ci};
18558c2ecf20Sopenharmony_ci
18568c2ecf20Sopenharmony_cistatic const struct driver_info samsung_info = {
18578c2ecf20Sopenharmony_ci	.description = "Samsung USB Ethernet Adapter",
18588c2ecf20Sopenharmony_ci	.bind = ax88179_bind,
18598c2ecf20Sopenharmony_ci	.unbind = ax88179_unbind,
18608c2ecf20Sopenharmony_ci	.status = ax88179_status,
18618c2ecf20Sopenharmony_ci	.link_reset = ax88179_link_reset,
18628c2ecf20Sopenharmony_ci	.reset = ax88179_reset,
18638c2ecf20Sopenharmony_ci	.stop = ax88179_stop,
18648c2ecf20Sopenharmony_ci	.flags = FLAG_ETHER | FLAG_FRAMING_AX,
18658c2ecf20Sopenharmony_ci	.rx_fixup = ax88179_rx_fixup,
18668c2ecf20Sopenharmony_ci	.tx_fixup = ax88179_tx_fixup,
18678c2ecf20Sopenharmony_ci};
18688c2ecf20Sopenharmony_ci
18698c2ecf20Sopenharmony_cistatic const struct driver_info lenovo_info = {
18708c2ecf20Sopenharmony_ci	.description = "Lenovo OneLinkDock Gigabit LAN",
18718c2ecf20Sopenharmony_ci	.bind = ax88179_bind,
18728c2ecf20Sopenharmony_ci	.unbind = ax88179_unbind,
18738c2ecf20Sopenharmony_ci	.status = ax88179_status,
18748c2ecf20Sopenharmony_ci	.link_reset = ax88179_link_reset,
18758c2ecf20Sopenharmony_ci	.reset = ax88179_reset,
18768c2ecf20Sopenharmony_ci	.stop = ax88179_stop,
18778c2ecf20Sopenharmony_ci	.flags = FLAG_ETHER | FLAG_FRAMING_AX,
18788c2ecf20Sopenharmony_ci	.rx_fixup = ax88179_rx_fixup,
18798c2ecf20Sopenharmony_ci	.tx_fixup = ax88179_tx_fixup,
18808c2ecf20Sopenharmony_ci};
18818c2ecf20Sopenharmony_ci
18828c2ecf20Sopenharmony_cistatic const struct driver_info belkin_info = {
18838c2ecf20Sopenharmony_ci	.description = "Belkin USB Ethernet Adapter",
18848c2ecf20Sopenharmony_ci	.bind	= ax88179_bind,
18858c2ecf20Sopenharmony_ci	.unbind = ax88179_unbind,
18868c2ecf20Sopenharmony_ci	.status = ax88179_status,
18878c2ecf20Sopenharmony_ci	.link_reset = ax88179_link_reset,
18888c2ecf20Sopenharmony_ci	.reset	= ax88179_reset,
18898c2ecf20Sopenharmony_ci	.stop	= ax88179_stop,
18908c2ecf20Sopenharmony_ci	.flags	= FLAG_ETHER | FLAG_FRAMING_AX,
18918c2ecf20Sopenharmony_ci	.rx_fixup = ax88179_rx_fixup,
18928c2ecf20Sopenharmony_ci	.tx_fixup = ax88179_tx_fixup,
18938c2ecf20Sopenharmony_ci};
18948c2ecf20Sopenharmony_ci
18958c2ecf20Sopenharmony_cistatic const struct driver_info toshiba_info = {
18968c2ecf20Sopenharmony_ci	.description = "Toshiba USB Ethernet Adapter",
18978c2ecf20Sopenharmony_ci	.bind	= ax88179_bind,
18988c2ecf20Sopenharmony_ci	.unbind = ax88179_unbind,
18998c2ecf20Sopenharmony_ci	.status = ax88179_status,
19008c2ecf20Sopenharmony_ci	.link_reset = ax88179_link_reset,
19018c2ecf20Sopenharmony_ci	.reset	= ax88179_reset,
19028c2ecf20Sopenharmony_ci	.stop = ax88179_stop,
19038c2ecf20Sopenharmony_ci	.flags	= FLAG_ETHER | FLAG_FRAMING_AX,
19048c2ecf20Sopenharmony_ci	.rx_fixup = ax88179_rx_fixup,
19058c2ecf20Sopenharmony_ci	.tx_fixup = ax88179_tx_fixup,
19068c2ecf20Sopenharmony_ci};
19078c2ecf20Sopenharmony_ci
19088c2ecf20Sopenharmony_cistatic const struct driver_info mct_info = {
19098c2ecf20Sopenharmony_ci	.description = "MCT USB 3.0 Gigabit Ethernet Adapter",
19108c2ecf20Sopenharmony_ci	.bind	= ax88179_bind,
19118c2ecf20Sopenharmony_ci	.unbind	= ax88179_unbind,
19128c2ecf20Sopenharmony_ci	.status	= ax88179_status,
19138c2ecf20Sopenharmony_ci	.link_reset = ax88179_link_reset,
19148c2ecf20Sopenharmony_ci	.reset	= ax88179_reset,
19158c2ecf20Sopenharmony_ci	.stop	= ax88179_stop,
19168c2ecf20Sopenharmony_ci	.flags	= FLAG_ETHER | FLAG_FRAMING_AX,
19178c2ecf20Sopenharmony_ci	.rx_fixup = ax88179_rx_fixup,
19188c2ecf20Sopenharmony_ci	.tx_fixup = ax88179_tx_fixup,
19198c2ecf20Sopenharmony_ci};
19208c2ecf20Sopenharmony_ci
19218c2ecf20Sopenharmony_cistatic const struct usb_device_id products[] = {
19228c2ecf20Sopenharmony_ci{
19238c2ecf20Sopenharmony_ci	/* ASIX AX88179 10/100/1000 */
19248c2ecf20Sopenharmony_ci	USB_DEVICE(0x0b95, 0x1790),
19258c2ecf20Sopenharmony_ci	.driver_info = (unsigned long)&ax88179_info,
19268c2ecf20Sopenharmony_ci}, {
19278c2ecf20Sopenharmony_ci	/* ASIX AX88178A 10/100/1000 */
19288c2ecf20Sopenharmony_ci	USB_DEVICE(0x0b95, 0x178a),
19298c2ecf20Sopenharmony_ci	.driver_info = (unsigned long)&ax88178a_info,
19308c2ecf20Sopenharmony_ci}, {
19318c2ecf20Sopenharmony_ci	/* Cypress GX3 SuperSpeed to Gigabit Ethernet Bridge Controller */
19328c2ecf20Sopenharmony_ci	USB_DEVICE(0x04b4, 0x3610),
19338c2ecf20Sopenharmony_ci	.driver_info = (unsigned long)&cypress_GX3_info,
19348c2ecf20Sopenharmony_ci}, {
19358c2ecf20Sopenharmony_ci	/* D-Link DUB-1312 USB 3.0 to Gigabit Ethernet Adapter */
19368c2ecf20Sopenharmony_ci	USB_DEVICE(0x2001, 0x4a00),
19378c2ecf20Sopenharmony_ci	.driver_info = (unsigned long)&dlink_dub1312_info,
19388c2ecf20Sopenharmony_ci}, {
19398c2ecf20Sopenharmony_ci	/* Sitecom USB 3.0 to Gigabit Adapter */
19408c2ecf20Sopenharmony_ci	USB_DEVICE(0x0df6, 0x0072),
19418c2ecf20Sopenharmony_ci	.driver_info = (unsigned long)&sitecom_info,
19428c2ecf20Sopenharmony_ci}, {
19438c2ecf20Sopenharmony_ci	/* Samsung USB Ethernet Adapter */
19448c2ecf20Sopenharmony_ci	USB_DEVICE(0x04e8, 0xa100),
19458c2ecf20Sopenharmony_ci	.driver_info = (unsigned long)&samsung_info,
19468c2ecf20Sopenharmony_ci}, {
19478c2ecf20Sopenharmony_ci	/* Lenovo OneLinkDock Gigabit LAN */
19488c2ecf20Sopenharmony_ci	USB_DEVICE(0x17ef, 0x304b),
19498c2ecf20Sopenharmony_ci	.driver_info = (unsigned long)&lenovo_info,
19508c2ecf20Sopenharmony_ci}, {
19518c2ecf20Sopenharmony_ci	/* Belkin B2B128 USB 3.0 Hub + Gigabit Ethernet Adapter */
19528c2ecf20Sopenharmony_ci	USB_DEVICE(0x050d, 0x0128),
19538c2ecf20Sopenharmony_ci	.driver_info = (unsigned long)&belkin_info,
19548c2ecf20Sopenharmony_ci}, {
19558c2ecf20Sopenharmony_ci	/* Toshiba USB 3.0 GBit Ethernet Adapter */
19568c2ecf20Sopenharmony_ci	USB_DEVICE(0x0930, 0x0a13),
19578c2ecf20Sopenharmony_ci	.driver_info = (unsigned long)&toshiba_info,
19588c2ecf20Sopenharmony_ci}, {
19598c2ecf20Sopenharmony_ci	/* Magic Control Technology U3-A9003 USB 3.0 Gigabit Ethernet Adapter */
19608c2ecf20Sopenharmony_ci	USB_DEVICE(0x0711, 0x0179),
19618c2ecf20Sopenharmony_ci	.driver_info = (unsigned long)&mct_info,
19628c2ecf20Sopenharmony_ci},
19638c2ecf20Sopenharmony_ci	{ },
19648c2ecf20Sopenharmony_ci};
19658c2ecf20Sopenharmony_ciMODULE_DEVICE_TABLE(usb, products);
19668c2ecf20Sopenharmony_ci
19678c2ecf20Sopenharmony_cistatic struct usb_driver ax88179_178a_driver = {
19688c2ecf20Sopenharmony_ci	.name =		"ax88179_178a",
19698c2ecf20Sopenharmony_ci	.id_table =	products,
19708c2ecf20Sopenharmony_ci	.probe =	usbnet_probe,
19718c2ecf20Sopenharmony_ci	.suspend =	ax88179_suspend,
19728c2ecf20Sopenharmony_ci	.resume =	ax88179_resume,
19738c2ecf20Sopenharmony_ci	.reset_resume =	ax88179_resume,
19748c2ecf20Sopenharmony_ci	.disconnect =	usbnet_disconnect,
19758c2ecf20Sopenharmony_ci	.supports_autosuspend = 1,
19768c2ecf20Sopenharmony_ci	.disable_hub_initiated_lpm = 1,
19778c2ecf20Sopenharmony_ci};
19788c2ecf20Sopenharmony_ci
19798c2ecf20Sopenharmony_cimodule_usb_driver(ax88179_178a_driver);
19808c2ecf20Sopenharmony_ci
19818c2ecf20Sopenharmony_ciMODULE_DESCRIPTION("ASIX AX88179/178A based USB 3.0/2.0 Gigabit Ethernet Devices");
19828c2ecf20Sopenharmony_ciMODULE_LICENSE("GPL");
1983