11ccea77eSThomas Gleixner // SPDX-License-Identifier: GPL-2.0-or-later 2e2ca90c2SFreddy Xin /* 3e2ca90c2SFreddy Xin * ASIX AX88179/178A USB 3.0/2.0 to Gigabit Ethernet Devices 4e2ca90c2SFreddy Xin * 5e2ca90c2SFreddy Xin * Copyright (C) 2011-2013 ASIX 6e2ca90c2SFreddy Xin */ 7e2ca90c2SFreddy Xin 8e2ca90c2SFreddy Xin #include <linux/module.h> 9e2ca90c2SFreddy Xin #include <linux/etherdevice.h> 10e2ca90c2SFreddy Xin #include <linux/mii.h> 11e2ca90c2SFreddy Xin #include <linux/usb.h> 12e2ca90c2SFreddy Xin #include <linux/crc32.h> 13e2ca90c2SFreddy Xin #include <linux/usb/usbnet.h> 14e98d69baSFreddy Xin #include <uapi/linux/mdio.h> 15e98d69baSFreddy Xin #include <linux/mdio.h> 16e2ca90c2SFreddy Xin 17e2ca90c2SFreddy Xin #define AX88179_PHY_ID 0x03 18e2ca90c2SFreddy Xin #define AX_EEPROM_LEN 0x100 19e2ca90c2SFreddy Xin #define AX88179_EEPROM_MAGIC 0x17900b95 20e2ca90c2SFreddy Xin #define AX_MCAST_FLTSIZE 8 21e2ca90c2SFreddy Xin #define AX_MAX_MCAST 64 22e2ca90c2SFreddy Xin #define AX_INT_PPLS_LINK ((u32)BIT(16)) 23e2ca90c2SFreddy Xin #define AX_RXHDR_L4_TYPE_MASK 0x1c 24e2ca90c2SFreddy Xin #define AX_RXHDR_L4_TYPE_UDP 4 25e2ca90c2SFreddy Xin #define AX_RXHDR_L4_TYPE_TCP 16 26e2ca90c2SFreddy Xin #define AX_RXHDR_L3CSUM_ERR 2 27e2ca90c2SFreddy Xin #define AX_RXHDR_L4CSUM_ERR 1 287e78b83cSFreddy Xin #define AX_RXHDR_CRC_ERR ((u32)BIT(29)) 297e78b83cSFreddy Xin #define AX_RXHDR_DROP_ERR ((u32)BIT(31)) 30e2ca90c2SFreddy Xin #define AX_ACCESS_MAC 0x01 31e2ca90c2SFreddy Xin #define AX_ACCESS_PHY 0x02 32e2ca90c2SFreddy Xin #define AX_ACCESS_EEPROM 0x04 33e2ca90c2SFreddy Xin #define AX_ACCESS_EFUS 0x05 3478734404SBjorn Andersson #define AX_RELOAD_EEPROM_EFUSE 0x06 35e2ca90c2SFreddy Xin #define AX_PAUSE_WATERLVL_HIGH 0x54 36e2ca90c2SFreddy Xin #define AX_PAUSE_WATERLVL_LOW 0x55 37e2ca90c2SFreddy Xin 38e2ca90c2SFreddy Xin #define PHYSICAL_LINK_STATUS 0x02 39e2ca90c2SFreddy Xin #define AX_USB_SS 0x04 40e2ca90c2SFreddy Xin #define AX_USB_HS 0x02 41e2ca90c2SFreddy Xin 42e2ca90c2SFreddy Xin #define GENERAL_STATUS 0x03 43e2ca90c2SFreddy Xin /* Check AX88179 version. UA1:Bit2 = 0, UA2:Bit2 = 1 */ 44e2ca90c2SFreddy Xin #define AX_SECLD 0x04 45e2ca90c2SFreddy Xin 46e2ca90c2SFreddy Xin #define AX_SROM_ADDR 0x07 47e2ca90c2SFreddy Xin #define AX_SROM_CMD 0x0a 48e2ca90c2SFreddy Xin #define EEP_RD 0x04 49e2ca90c2SFreddy Xin #define EEP_BUSY 0x10 50e2ca90c2SFreddy Xin 51e2ca90c2SFreddy Xin #define AX_SROM_DATA_LOW 0x08 52e2ca90c2SFreddy Xin #define AX_SROM_DATA_HIGH 0x09 53e2ca90c2SFreddy Xin 54e2ca90c2SFreddy Xin #define AX_RX_CTL 0x0b 55e2ca90c2SFreddy Xin #define AX_RX_CTL_DROPCRCERR 0x0100 56e2ca90c2SFreddy Xin #define AX_RX_CTL_IPE 0x0200 57e2ca90c2SFreddy Xin #define AX_RX_CTL_START 0x0080 58e2ca90c2SFreddy Xin #define AX_RX_CTL_AP 0x0020 59e2ca90c2SFreddy Xin #define AX_RX_CTL_AM 0x0010 60e2ca90c2SFreddy Xin #define AX_RX_CTL_AB 0x0008 61e2ca90c2SFreddy Xin #define AX_RX_CTL_AMALL 0x0002 62e2ca90c2SFreddy Xin #define AX_RX_CTL_PRO 0x0001 63e2ca90c2SFreddy Xin #define AX_RX_CTL_STOP 0x0000 64e2ca90c2SFreddy Xin 65e2ca90c2SFreddy Xin #define AX_NODE_ID 0x10 66e2ca90c2SFreddy Xin #define AX_MULFLTARY 0x16 67e2ca90c2SFreddy Xin 68e2ca90c2SFreddy Xin #define AX_MEDIUM_STATUS_MODE 0x22 69e2ca90c2SFreddy Xin #define AX_MEDIUM_GIGAMODE 0x01 70e2ca90c2SFreddy Xin #define AX_MEDIUM_FULL_DUPLEX 0x02 71e2ca90c2SFreddy Xin #define AX_MEDIUM_EN_125MHZ 0x08 72e2ca90c2SFreddy Xin #define AX_MEDIUM_RXFLOW_CTRLEN 0x10 73e2ca90c2SFreddy Xin #define AX_MEDIUM_TXFLOW_CTRLEN 0x20 74e2ca90c2SFreddy Xin #define AX_MEDIUM_RECEIVE_EN 0x100 75e2ca90c2SFreddy Xin #define AX_MEDIUM_PS 0x200 76e2ca90c2SFreddy Xin #define AX_MEDIUM_JUMBO_EN 0x8040 77e2ca90c2SFreddy Xin 78e2ca90c2SFreddy Xin #define AX_MONITOR_MOD 0x24 79e2ca90c2SFreddy Xin #define AX_MONITOR_MODE_RWLC 0x02 80e2ca90c2SFreddy Xin #define AX_MONITOR_MODE_RWMP 0x04 81e2ca90c2SFreddy Xin #define AX_MONITOR_MODE_PMEPOL 0x20 82e2ca90c2SFreddy Xin #define AX_MONITOR_MODE_PMETYPE 0x40 83e2ca90c2SFreddy Xin 84e2ca90c2SFreddy Xin #define AX_GPIO_CTRL 0x25 85e2ca90c2SFreddy Xin #define AX_GPIO_CTRL_GPIO3EN 0x80 86e2ca90c2SFreddy Xin #define AX_GPIO_CTRL_GPIO2EN 0x40 87e2ca90c2SFreddy Xin #define AX_GPIO_CTRL_GPIO1EN 0x20 88e2ca90c2SFreddy Xin 89e2ca90c2SFreddy Xin #define AX_PHYPWR_RSTCTL 0x26 90e2ca90c2SFreddy Xin #define AX_PHYPWR_RSTCTL_BZ 0x0010 91e2ca90c2SFreddy Xin #define AX_PHYPWR_RSTCTL_IPRL 0x0020 92e2ca90c2SFreddy Xin #define AX_PHYPWR_RSTCTL_AT 0x1000 93e2ca90c2SFreddy Xin 94e2ca90c2SFreddy Xin #define AX_RX_BULKIN_QCTRL 0x2e 95e2ca90c2SFreddy Xin #define AX_CLK_SELECT 0x33 96e2ca90c2SFreddy Xin #define AX_CLK_SELECT_BCS 0x01 97e2ca90c2SFreddy Xin #define AX_CLK_SELECT_ACS 0x02 98e2ca90c2SFreddy Xin #define AX_CLK_SELECT_ULR 0x08 99e2ca90c2SFreddy Xin 100e2ca90c2SFreddy Xin #define AX_RXCOE_CTL 0x34 101e2ca90c2SFreddy Xin #define AX_RXCOE_IP 0x01 102e2ca90c2SFreddy Xin #define AX_RXCOE_TCP 0x02 103e2ca90c2SFreddy Xin #define AX_RXCOE_UDP 0x04 104e2ca90c2SFreddy Xin #define AX_RXCOE_TCPV6 0x20 105e2ca90c2SFreddy Xin #define AX_RXCOE_UDPV6 0x40 106e2ca90c2SFreddy Xin 107e2ca90c2SFreddy Xin #define AX_TXCOE_CTL 0x35 108e2ca90c2SFreddy Xin #define AX_TXCOE_IP 0x01 109e2ca90c2SFreddy Xin #define AX_TXCOE_TCP 0x02 110e2ca90c2SFreddy Xin #define AX_TXCOE_UDP 0x04 111e2ca90c2SFreddy Xin #define AX_TXCOE_TCPV6 0x20 112e2ca90c2SFreddy Xin #define AX_TXCOE_UDPV6 0x40 113e2ca90c2SFreddy Xin 114e2ca90c2SFreddy Xin #define AX_LEDCTRL 0x73 115e2ca90c2SFreddy Xin 116e2ca90c2SFreddy Xin #define GMII_PHY_PHYSR 0x11 117e2ca90c2SFreddy Xin #define GMII_PHY_PHYSR_SMASK 0xc000 118e2ca90c2SFreddy Xin #define GMII_PHY_PHYSR_GIGA 0x8000 119e2ca90c2SFreddy Xin #define GMII_PHY_PHYSR_100 0x4000 120e2ca90c2SFreddy Xin #define GMII_PHY_PHYSR_FULL 0x2000 121e2ca90c2SFreddy Xin #define GMII_PHY_PHYSR_LINK 0x400 122e2ca90c2SFreddy Xin 123e2ca90c2SFreddy Xin #define GMII_LED_ACT 0x1a 124e2ca90c2SFreddy Xin #define GMII_LED_ACTIVE_MASK 0xff8f 125e2ca90c2SFreddy Xin #define GMII_LED0_ACTIVE BIT(4) 126e2ca90c2SFreddy Xin #define GMII_LED1_ACTIVE BIT(5) 127e2ca90c2SFreddy Xin #define GMII_LED2_ACTIVE BIT(6) 128e2ca90c2SFreddy Xin 129e2ca90c2SFreddy Xin #define GMII_LED_LINK 0x1c 130e2ca90c2SFreddy Xin #define GMII_LED_LINK_MASK 0xf888 131e2ca90c2SFreddy Xin #define GMII_LED0_LINK_10 BIT(0) 132e2ca90c2SFreddy Xin #define GMII_LED0_LINK_100 BIT(1) 133e2ca90c2SFreddy Xin #define GMII_LED0_LINK_1000 BIT(2) 134e2ca90c2SFreddy Xin #define GMII_LED1_LINK_10 BIT(4) 135e2ca90c2SFreddy Xin #define GMII_LED1_LINK_100 BIT(5) 136e2ca90c2SFreddy Xin #define GMII_LED1_LINK_1000 BIT(6) 137e2ca90c2SFreddy Xin #define GMII_LED2_LINK_10 BIT(8) 138e2ca90c2SFreddy Xin #define GMII_LED2_LINK_100 BIT(9) 139e2ca90c2SFreddy Xin #define GMII_LED2_LINK_1000 BIT(10) 140e2ca90c2SFreddy Xin #define LED0_ACTIVE BIT(0) 141e2ca90c2SFreddy Xin #define LED0_LINK_10 BIT(1) 142e2ca90c2SFreddy Xin #define LED0_LINK_100 BIT(2) 143e2ca90c2SFreddy Xin #define LED0_LINK_1000 BIT(3) 144e2ca90c2SFreddy Xin #define LED0_FD BIT(4) 145e2ca90c2SFreddy Xin #define LED0_USB3_MASK 0x001f 146e2ca90c2SFreddy Xin #define LED1_ACTIVE BIT(5) 147e2ca90c2SFreddy Xin #define LED1_LINK_10 BIT(6) 148e2ca90c2SFreddy Xin #define LED1_LINK_100 BIT(7) 149e2ca90c2SFreddy Xin #define LED1_LINK_1000 BIT(8) 150e2ca90c2SFreddy Xin #define LED1_FD BIT(9) 151e2ca90c2SFreddy Xin #define LED1_USB3_MASK 0x03e0 152e2ca90c2SFreddy Xin #define LED2_ACTIVE BIT(10) 153e2ca90c2SFreddy Xin #define LED2_LINK_1000 BIT(13) 154e2ca90c2SFreddy Xin #define LED2_LINK_100 BIT(12) 155e2ca90c2SFreddy Xin #define LED2_LINK_10 BIT(11) 156e2ca90c2SFreddy Xin #define LED2_FD BIT(14) 157e2ca90c2SFreddy Xin #define LED_VALID BIT(15) 158e2ca90c2SFreddy Xin #define LED2_USB3_MASK 0x7c00 159e2ca90c2SFreddy Xin 160e2ca90c2SFreddy Xin #define GMII_PHYPAGE 0x1e 161e2ca90c2SFreddy Xin #define GMII_PHY_PAGE_SELECT 0x1f 162e2ca90c2SFreddy Xin #define GMII_PHY_PGSEL_EXT 0x0007 163e2ca90c2SFreddy Xin #define GMII_PHY_PGSEL_PAGE0 0x0000 164e98d69baSFreddy Xin #define GMII_PHY_PGSEL_PAGE3 0x0003 165e98d69baSFreddy Xin #define GMII_PHY_PGSEL_PAGE5 0x0005 166e2ca90c2SFreddy Xin 1679718f9ceSJustin Chen static int ax88179_reset(struct usbnet *dev); 1689718f9ceSJustin Chen 169e2ca90c2SFreddy Xin struct ax88179_data { 170e98d69baSFreddy Xin u8 eee_enabled; 171e98d69baSFreddy Xin u8 eee_active; 172e2ca90c2SFreddy Xin u16 rxctl; 173e2ca90c2SFreddy Xin u16 reserved; 174843f9205SJustin Chen u8 in_pm; 175e2ca90c2SFreddy Xin }; 176e2ca90c2SFreddy Xin 177e2ca90c2SFreddy Xin struct ax88179_int_data { 178e2ca90c2SFreddy Xin __le32 intdata1; 179e2ca90c2SFreddy Xin __le32 intdata2; 180e2ca90c2SFreddy Xin }; 181e2ca90c2SFreddy Xin 182e2ca90c2SFreddy Xin static const struct { 183e2ca90c2SFreddy Xin unsigned char ctrl, timer_l, timer_h, size, ifg; 184e2ca90c2SFreddy Xin } AX88179_BULKIN_SIZE[] = { 185e2ca90c2SFreddy Xin {7, 0x4f, 0, 0x12, 0xff}, 186e2ca90c2SFreddy Xin {7, 0x20, 3, 0x16, 0xff}, 187e2ca90c2SFreddy Xin {7, 0xae, 7, 0x18, 0xff}, 188e2ca90c2SFreddy Xin {7, 0xcc, 0x4c, 0x18, 8}, 189e2ca90c2SFreddy Xin }; 190e2ca90c2SFreddy Xin 191843f9205SJustin Chen static void ax88179_set_pm_mode(struct usbnet *dev, bool pm_mode) 192843f9205SJustin Chen { 193843f9205SJustin Chen struct ax88179_data *ax179_data = (struct ax88179_data *)dev->data; 194843f9205SJustin Chen 195843f9205SJustin Chen ax179_data->in_pm = pm_mode; 196843f9205SJustin Chen } 197843f9205SJustin Chen 198843f9205SJustin Chen static int ax88179_in_pm(struct usbnet *dev) 199843f9205SJustin Chen { 200843f9205SJustin Chen struct ax88179_data *ax179_data = (struct ax88179_data *)dev->data; 201843f9205SJustin Chen 202843f9205SJustin Chen return ax179_data->in_pm; 203843f9205SJustin Chen } 204843f9205SJustin Chen 205e2ca90c2SFreddy Xin static int __ax88179_read_cmd(struct usbnet *dev, u8 cmd, u16 value, u16 index, 206843f9205SJustin Chen u16 size, void *data) 207e2ca90c2SFreddy Xin { 208e2ca90c2SFreddy Xin int ret; 209e2ca90c2SFreddy Xin int (*fn)(struct usbnet *, u8, u8, u16, u16, void *, u16); 210e2ca90c2SFreddy Xin 211e2ca90c2SFreddy Xin BUG_ON(!dev); 212e2ca90c2SFreddy Xin 213843f9205SJustin Chen if (!ax88179_in_pm(dev)) 214e2ca90c2SFreddy Xin fn = usbnet_read_cmd; 215e2ca90c2SFreddy Xin else 216e2ca90c2SFreddy Xin fn = usbnet_read_cmd_nopm; 217e2ca90c2SFreddy Xin 218e2ca90c2SFreddy Xin ret = fn(dev, cmd, USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE, 219e2ca90c2SFreddy Xin value, index, data, size); 220e2ca90c2SFreddy Xin 221e2ca90c2SFreddy Xin if (unlikely(ret < 0)) 222e2ca90c2SFreddy Xin netdev_warn(dev->net, "Failed to read reg index 0x%04x: %d\n", 223e2ca90c2SFreddy Xin index, ret); 224e2ca90c2SFreddy Xin 225e2ca90c2SFreddy Xin return ret; 226e2ca90c2SFreddy Xin } 227e2ca90c2SFreddy Xin 228e2ca90c2SFreddy Xin static int __ax88179_write_cmd(struct usbnet *dev, u8 cmd, u16 value, u16 index, 229843f9205SJustin Chen u16 size, const void *data) 230e2ca90c2SFreddy Xin { 231e2ca90c2SFreddy Xin int ret; 232e2ca90c2SFreddy Xin int (*fn)(struct usbnet *, u8, u8, u16, u16, const void *, u16); 233e2ca90c2SFreddy Xin 234e2ca90c2SFreddy Xin BUG_ON(!dev); 235e2ca90c2SFreddy Xin 236843f9205SJustin Chen if (!ax88179_in_pm(dev)) 237e2ca90c2SFreddy Xin fn = usbnet_write_cmd; 238e2ca90c2SFreddy Xin else 239e2ca90c2SFreddy Xin fn = usbnet_write_cmd_nopm; 240e2ca90c2SFreddy Xin 241e2ca90c2SFreddy Xin ret = fn(dev, cmd, USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE, 242e2ca90c2SFreddy Xin value, index, data, size); 243e2ca90c2SFreddy Xin 244e2ca90c2SFreddy Xin if (unlikely(ret < 0)) 245e2ca90c2SFreddy Xin netdev_warn(dev->net, "Failed to write reg index 0x%04x: %d\n", 246e2ca90c2SFreddy Xin index, ret); 247e2ca90c2SFreddy Xin 248e2ca90c2SFreddy Xin return ret; 249e2ca90c2SFreddy Xin } 250e2ca90c2SFreddy Xin 251e2ca90c2SFreddy Xin static void ax88179_write_cmd_async(struct usbnet *dev, u8 cmd, u16 value, 252e2ca90c2SFreddy Xin u16 index, u16 size, void *data) 253e2ca90c2SFreddy Xin { 254e2ca90c2SFreddy Xin u16 buf; 255e2ca90c2SFreddy Xin 256e2ca90c2SFreddy Xin if (2 == size) { 257e2ca90c2SFreddy Xin buf = *((u16 *)data); 258e2ca90c2SFreddy Xin cpu_to_le16s(&buf); 259e2ca90c2SFreddy Xin usbnet_write_cmd_async(dev, cmd, USB_DIR_OUT | USB_TYPE_VENDOR | 260e2ca90c2SFreddy Xin USB_RECIP_DEVICE, value, index, &buf, 261e2ca90c2SFreddy Xin size); 262e2ca90c2SFreddy Xin } else { 263e2ca90c2SFreddy Xin usbnet_write_cmd_async(dev, cmd, USB_DIR_OUT | USB_TYPE_VENDOR | 264e2ca90c2SFreddy Xin USB_RECIP_DEVICE, value, index, data, 265e2ca90c2SFreddy Xin size); 266e2ca90c2SFreddy Xin } 267e2ca90c2SFreddy Xin } 268e2ca90c2SFreddy Xin 269e2ca90c2SFreddy Xin static int ax88179_read_cmd(struct usbnet *dev, u8 cmd, u16 value, u16 index, 270e2ca90c2SFreddy Xin u16 size, void *data) 271e2ca90c2SFreddy Xin { 272e2ca90c2SFreddy Xin int ret; 273e2ca90c2SFreddy Xin 274e2ca90c2SFreddy Xin if (2 == size) { 275bd78980bSPhillip Potter u16 buf = 0; 276843f9205SJustin Chen ret = __ax88179_read_cmd(dev, cmd, value, index, size, &buf); 277e2ca90c2SFreddy Xin le16_to_cpus(&buf); 278e2ca90c2SFreddy Xin *((u16 *)data) = buf; 279e2ca90c2SFreddy Xin } else if (4 == size) { 280bd78980bSPhillip Potter u32 buf = 0; 281843f9205SJustin Chen ret = __ax88179_read_cmd(dev, cmd, value, index, size, &buf); 282e2ca90c2SFreddy Xin le32_to_cpus(&buf); 283e2ca90c2SFreddy Xin *((u32 *)data) = buf; 284e2ca90c2SFreddy Xin } else { 285843f9205SJustin Chen ret = __ax88179_read_cmd(dev, cmd, value, index, size, data); 286e2ca90c2SFreddy Xin } 287e2ca90c2SFreddy Xin 288e2ca90c2SFreddy Xin return ret; 289e2ca90c2SFreddy Xin } 290e2ca90c2SFreddy Xin 291e2ca90c2SFreddy Xin static int ax88179_write_cmd(struct usbnet *dev, u8 cmd, u16 value, u16 index, 29276660757SJakub Kicinski u16 size, const void *data) 293e2ca90c2SFreddy Xin { 294e2ca90c2SFreddy Xin int ret; 295e2ca90c2SFreddy Xin 296e2ca90c2SFreddy Xin if (2 == size) { 297e2ca90c2SFreddy Xin u16 buf; 298e2ca90c2SFreddy Xin buf = *((u16 *)data); 299e2ca90c2SFreddy Xin cpu_to_le16s(&buf); 300e2ca90c2SFreddy Xin ret = __ax88179_write_cmd(dev, cmd, value, index, 301843f9205SJustin Chen size, &buf); 302e2ca90c2SFreddy Xin } else { 303e2ca90c2SFreddy Xin ret = __ax88179_write_cmd(dev, cmd, value, index, 304843f9205SJustin Chen size, data); 305e2ca90c2SFreddy Xin } 306e2ca90c2SFreddy Xin 307e2ca90c2SFreddy Xin return ret; 308e2ca90c2SFreddy Xin } 309e2ca90c2SFreddy Xin 310e2ca90c2SFreddy Xin static void ax88179_status(struct usbnet *dev, struct urb *urb) 311e2ca90c2SFreddy Xin { 312e2ca90c2SFreddy Xin struct ax88179_int_data *event; 313e2ca90c2SFreddy Xin u32 link; 314e2ca90c2SFreddy Xin 315e2ca90c2SFreddy Xin if (urb->actual_length < 8) 316e2ca90c2SFreddy Xin return; 317e2ca90c2SFreddy Xin 318e2ca90c2SFreddy Xin event = urb->transfer_buffer; 319e2ca90c2SFreddy Xin le32_to_cpus((void *)&event->intdata1); 320e2ca90c2SFreddy Xin 321e2ca90c2SFreddy Xin link = (((__force u32)event->intdata1) & AX_INT_PPLS_LINK) >> 16; 322e2ca90c2SFreddy Xin 323e2ca90c2SFreddy Xin if (netif_carrier_ok(dev->net) != link) { 3247a97856eSMing Lei usbnet_link_change(dev, link, 1); 325e2ca90c2SFreddy Xin netdev_info(dev->net, "ax88179 - Link status is: %d\n", link); 326e2ca90c2SFreddy Xin } 327e2ca90c2SFreddy Xin } 328e2ca90c2SFreddy Xin 329e2ca90c2SFreddy Xin static int ax88179_mdio_read(struct net_device *netdev, int phy_id, int loc) 330e2ca90c2SFreddy Xin { 331e2ca90c2SFreddy Xin struct usbnet *dev = netdev_priv(netdev); 332e2ca90c2SFreddy Xin u16 res; 333e2ca90c2SFreddy Xin 334e2ca90c2SFreddy Xin ax88179_read_cmd(dev, AX_ACCESS_PHY, phy_id, (__u16)loc, 2, &res); 335e2ca90c2SFreddy Xin return res; 336e2ca90c2SFreddy Xin } 337e2ca90c2SFreddy Xin 338e2ca90c2SFreddy Xin static void ax88179_mdio_write(struct net_device *netdev, int phy_id, int loc, 339e2ca90c2SFreddy Xin int val) 340e2ca90c2SFreddy Xin { 341e2ca90c2SFreddy Xin struct usbnet *dev = netdev_priv(netdev); 342e2ca90c2SFreddy Xin u16 res = (u16) val; 343e2ca90c2SFreddy Xin 344e2ca90c2SFreddy Xin ax88179_write_cmd(dev, AX_ACCESS_PHY, phy_id, (__u16)loc, 2, &res); 345e2ca90c2SFreddy Xin } 346e2ca90c2SFreddy Xin 347e98d69baSFreddy Xin static inline int ax88179_phy_mmd_indirect(struct usbnet *dev, u16 prtad, 348e98d69baSFreddy Xin u16 devad) 349e98d69baSFreddy Xin { 350e98d69baSFreddy Xin u16 tmp16; 351e98d69baSFreddy Xin int ret; 352e98d69baSFreddy Xin 353e98d69baSFreddy Xin tmp16 = devad; 354e98d69baSFreddy Xin ret = ax88179_write_cmd(dev, AX_ACCESS_PHY, AX88179_PHY_ID, 355e98d69baSFreddy Xin MII_MMD_CTRL, 2, &tmp16); 356e98d69baSFreddy Xin 357e98d69baSFreddy Xin tmp16 = prtad; 358e98d69baSFreddy Xin ret = ax88179_write_cmd(dev, AX_ACCESS_PHY, AX88179_PHY_ID, 359e98d69baSFreddy Xin MII_MMD_DATA, 2, &tmp16); 360e98d69baSFreddy Xin 361e98d69baSFreddy Xin tmp16 = devad | MII_MMD_CTRL_NOINCR; 362e98d69baSFreddy Xin ret = ax88179_write_cmd(dev, AX_ACCESS_PHY, AX88179_PHY_ID, 363e98d69baSFreddy Xin MII_MMD_CTRL, 2, &tmp16); 364e98d69baSFreddy Xin 365e98d69baSFreddy Xin return ret; 366e98d69baSFreddy Xin } 367e98d69baSFreddy Xin 368e98d69baSFreddy Xin static int 369e98d69baSFreddy Xin ax88179_phy_read_mmd_indirect(struct usbnet *dev, u16 prtad, u16 devad) 370e98d69baSFreddy Xin { 371e98d69baSFreddy Xin int ret; 372e98d69baSFreddy Xin u16 tmp16; 373e98d69baSFreddy Xin 374e98d69baSFreddy Xin ax88179_phy_mmd_indirect(dev, prtad, devad); 375e98d69baSFreddy Xin 376e98d69baSFreddy Xin ret = ax88179_read_cmd(dev, AX_ACCESS_PHY, AX88179_PHY_ID, 377e98d69baSFreddy Xin MII_MMD_DATA, 2, &tmp16); 378e98d69baSFreddy Xin if (ret < 0) 379e98d69baSFreddy Xin return ret; 380e98d69baSFreddy Xin 381e98d69baSFreddy Xin return tmp16; 382e98d69baSFreddy Xin } 383e98d69baSFreddy Xin 384e98d69baSFreddy Xin static int 385e98d69baSFreddy Xin ax88179_phy_write_mmd_indirect(struct usbnet *dev, u16 prtad, u16 devad, 386e98d69baSFreddy Xin u16 data) 387e98d69baSFreddy Xin { 388e98d69baSFreddy Xin int ret; 389e98d69baSFreddy Xin 390e98d69baSFreddy Xin ax88179_phy_mmd_indirect(dev, prtad, devad); 391e98d69baSFreddy Xin 392e98d69baSFreddy Xin ret = ax88179_write_cmd(dev, AX_ACCESS_PHY, AX88179_PHY_ID, 393e98d69baSFreddy Xin MII_MMD_DATA, 2, &data); 394e98d69baSFreddy Xin 395e98d69baSFreddy Xin if (ret < 0) 396e98d69baSFreddy Xin return ret; 397e98d69baSFreddy Xin 398e98d69baSFreddy Xin return 0; 399e98d69baSFreddy Xin } 400e98d69baSFreddy Xin 401e2ca90c2SFreddy Xin static int ax88179_suspend(struct usb_interface *intf, pm_message_t message) 402e2ca90c2SFreddy Xin { 403e2ca90c2SFreddy Xin struct usbnet *dev = usb_get_intfdata(intf); 404e2ca90c2SFreddy Xin u16 tmp16; 405e2ca90c2SFreddy Xin u8 tmp8; 406e2ca90c2SFreddy Xin 407843f9205SJustin Chen ax88179_set_pm_mode(dev, true); 408843f9205SJustin Chen 409e2ca90c2SFreddy Xin usbnet_suspend(intf, message); 410e2ca90c2SFreddy Xin 411e2ca90c2SFreddy Xin /* Disable RX path */ 412843f9205SJustin Chen ax88179_read_cmd(dev, AX_ACCESS_MAC, AX_MEDIUM_STATUS_MODE, 413e2ca90c2SFreddy Xin 2, 2, &tmp16); 414e2ca90c2SFreddy Xin tmp16 &= ~AX_MEDIUM_RECEIVE_EN; 415843f9205SJustin Chen ax88179_write_cmd(dev, AX_ACCESS_MAC, AX_MEDIUM_STATUS_MODE, 416e2ca90c2SFreddy Xin 2, 2, &tmp16); 417e2ca90c2SFreddy Xin 418e2ca90c2SFreddy Xin /* Force bulk-in zero length */ 419843f9205SJustin Chen ax88179_read_cmd(dev, AX_ACCESS_MAC, AX_PHYPWR_RSTCTL, 420e2ca90c2SFreddy Xin 2, 2, &tmp16); 421e2ca90c2SFreddy Xin 422e2ca90c2SFreddy Xin tmp16 |= AX_PHYPWR_RSTCTL_BZ | AX_PHYPWR_RSTCTL_IPRL; 423843f9205SJustin Chen ax88179_write_cmd(dev, AX_ACCESS_MAC, AX_PHYPWR_RSTCTL, 424e2ca90c2SFreddy Xin 2, 2, &tmp16); 425e2ca90c2SFreddy Xin 426e2ca90c2SFreddy Xin /* change clock */ 427e2ca90c2SFreddy Xin tmp8 = 0; 428843f9205SJustin Chen ax88179_write_cmd(dev, AX_ACCESS_MAC, AX_CLK_SELECT, 1, 1, &tmp8); 429e2ca90c2SFreddy Xin 430e2ca90c2SFreddy Xin /* Configure RX control register => stop operation */ 431e2ca90c2SFreddy Xin tmp16 = AX_RX_CTL_STOP; 432843f9205SJustin Chen ax88179_write_cmd(dev, AX_ACCESS_MAC, AX_RX_CTL, 2, 2, &tmp16); 433843f9205SJustin Chen 434843f9205SJustin Chen ax88179_set_pm_mode(dev, false); 435e2ca90c2SFreddy Xin 436e2ca90c2SFreddy Xin return 0; 437e2ca90c2SFreddy Xin } 438e2ca90c2SFreddy Xin 439e2ca90c2SFreddy Xin /* This function is used to enable the autodetach function. */ 440e2ca90c2SFreddy Xin /* This function is determined by offset 0x43 of EEPROM */ 441843f9205SJustin Chen static int ax88179_auto_detach(struct usbnet *dev) 442e2ca90c2SFreddy Xin { 443e2ca90c2SFreddy Xin u16 tmp16; 444e2ca90c2SFreddy Xin u8 tmp8; 445e2ca90c2SFreddy Xin 446843f9205SJustin Chen if (ax88179_read_cmd(dev, AX_ACCESS_EEPROM, 0x43, 1, 2, &tmp16) < 0) 447e2ca90c2SFreddy Xin return 0; 448e2ca90c2SFreddy Xin 449e2ca90c2SFreddy Xin if ((tmp16 == 0xFFFF) || (!(tmp16 & 0x0100))) 450e2ca90c2SFreddy Xin return 0; 451e2ca90c2SFreddy Xin 452e2ca90c2SFreddy Xin /* Enable Auto Detach bit */ 453e2ca90c2SFreddy Xin tmp8 = 0; 454843f9205SJustin Chen ax88179_read_cmd(dev, AX_ACCESS_MAC, AX_CLK_SELECT, 1, 1, &tmp8); 455e2ca90c2SFreddy Xin tmp8 |= AX_CLK_SELECT_ULR; 456843f9205SJustin Chen ax88179_write_cmd(dev, AX_ACCESS_MAC, AX_CLK_SELECT, 1, 1, &tmp8); 457e2ca90c2SFreddy Xin 458843f9205SJustin Chen ax88179_read_cmd(dev, AX_ACCESS_MAC, AX_PHYPWR_RSTCTL, 2, 2, &tmp16); 459e2ca90c2SFreddy Xin tmp16 |= AX_PHYPWR_RSTCTL_AT; 460843f9205SJustin Chen ax88179_write_cmd(dev, AX_ACCESS_MAC, AX_PHYPWR_RSTCTL, 2, 2, &tmp16); 461e2ca90c2SFreddy Xin 462e2ca90c2SFreddy Xin return 0; 463e2ca90c2SFreddy Xin } 464e2ca90c2SFreddy Xin 465e2ca90c2SFreddy Xin static int ax88179_resume(struct usb_interface *intf) 466e2ca90c2SFreddy Xin { 467e2ca90c2SFreddy Xin struct usbnet *dev = usb_get_intfdata(intf); 468e2ca90c2SFreddy Xin 469843f9205SJustin Chen ax88179_set_pm_mode(dev, true); 470843f9205SJustin Chen 4717a97856eSMing Lei usbnet_link_change(dev, 0, 0); 472e2ca90c2SFreddy Xin 473*c4bf747cSJustin Chen ax88179_reset(dev); 474843f9205SJustin Chen 475843f9205SJustin Chen ax88179_set_pm_mode(dev, false); 476e2ca90c2SFreddy Xin 477e2ca90c2SFreddy Xin return usbnet_resume(intf); 478e2ca90c2SFreddy Xin } 479e2ca90c2SFreddy Xin 480e2ca90c2SFreddy Xin static void 481e2ca90c2SFreddy Xin ax88179_get_wol(struct net_device *net, struct ethtool_wolinfo *wolinfo) 482e2ca90c2SFreddy Xin { 483e2ca90c2SFreddy Xin struct usbnet *dev = netdev_priv(net); 484e2ca90c2SFreddy Xin u8 opt; 485e2ca90c2SFreddy Xin 486e2ca90c2SFreddy Xin if (ax88179_read_cmd(dev, AX_ACCESS_MAC, AX_MONITOR_MOD, 487e2ca90c2SFreddy Xin 1, 1, &opt) < 0) { 488e2ca90c2SFreddy Xin wolinfo->supported = 0; 489e2ca90c2SFreddy Xin wolinfo->wolopts = 0; 490e2ca90c2SFreddy Xin return; 491e2ca90c2SFreddy Xin } 492e2ca90c2SFreddy Xin 493e2ca90c2SFreddy Xin wolinfo->supported = WAKE_PHY | WAKE_MAGIC; 494e2ca90c2SFreddy Xin wolinfo->wolopts = 0; 495e2ca90c2SFreddy Xin if (opt & AX_MONITOR_MODE_RWLC) 496e2ca90c2SFreddy Xin wolinfo->wolopts |= WAKE_PHY; 497e2ca90c2SFreddy Xin if (opt & AX_MONITOR_MODE_RWMP) 498e2ca90c2SFreddy Xin wolinfo->wolopts |= WAKE_MAGIC; 499e2ca90c2SFreddy Xin } 500e2ca90c2SFreddy Xin 501e2ca90c2SFreddy Xin static int 502e2ca90c2SFreddy Xin ax88179_set_wol(struct net_device *net, struct ethtool_wolinfo *wolinfo) 503e2ca90c2SFreddy Xin { 504e2ca90c2SFreddy Xin struct usbnet *dev = netdev_priv(net); 505e2ca90c2SFreddy Xin u8 opt = 0; 506e2ca90c2SFreddy Xin 5075ba6b4aaSFlorian Fainelli if (wolinfo->wolopts & ~(WAKE_PHY | WAKE_MAGIC)) 5085ba6b4aaSFlorian Fainelli return -EINVAL; 5095ba6b4aaSFlorian Fainelli 510e2ca90c2SFreddy Xin if (wolinfo->wolopts & WAKE_PHY) 511e2ca90c2SFreddy Xin opt |= AX_MONITOR_MODE_RWLC; 512e2ca90c2SFreddy Xin if (wolinfo->wolopts & WAKE_MAGIC) 513e2ca90c2SFreddy Xin opt |= AX_MONITOR_MODE_RWMP; 514e2ca90c2SFreddy Xin 515e2ca90c2SFreddy Xin if (ax88179_write_cmd(dev, AX_ACCESS_MAC, AX_MONITOR_MOD, 516e2ca90c2SFreddy Xin 1, 1, &opt) < 0) 517e2ca90c2SFreddy Xin return -EINVAL; 518e2ca90c2SFreddy Xin 519e2ca90c2SFreddy Xin return 0; 520e2ca90c2SFreddy Xin } 521e2ca90c2SFreddy Xin 522e2ca90c2SFreddy Xin static int ax88179_get_eeprom_len(struct net_device *net) 523e2ca90c2SFreddy Xin { 524e2ca90c2SFreddy Xin return AX_EEPROM_LEN; 525e2ca90c2SFreddy Xin } 526e2ca90c2SFreddy Xin 527e2ca90c2SFreddy Xin static int 528e2ca90c2SFreddy Xin ax88179_get_eeprom(struct net_device *net, struct ethtool_eeprom *eeprom, 529e2ca90c2SFreddy Xin u8 *data) 530e2ca90c2SFreddy Xin { 531e2ca90c2SFreddy Xin struct usbnet *dev = netdev_priv(net); 532e2ca90c2SFreddy Xin u16 *eeprom_buff; 533e2ca90c2SFreddy Xin int first_word, last_word; 534e2ca90c2SFreddy Xin int i, ret; 535e2ca90c2SFreddy Xin 536e2ca90c2SFreddy Xin if (eeprom->len == 0) 537e2ca90c2SFreddy Xin return -EINVAL; 538e2ca90c2SFreddy Xin 539e2ca90c2SFreddy Xin eeprom->magic = AX88179_EEPROM_MAGIC; 540e2ca90c2SFreddy Xin 541e2ca90c2SFreddy Xin first_word = eeprom->offset >> 1; 542e2ca90c2SFreddy Xin last_word = (eeprom->offset + eeprom->len - 1) >> 1; 5436da2ec56SKees Cook eeprom_buff = kmalloc_array(last_word - first_word + 1, sizeof(u16), 544e2ca90c2SFreddy Xin GFP_KERNEL); 545e2ca90c2SFreddy Xin if (!eeprom_buff) 546e2ca90c2SFreddy Xin return -ENOMEM; 547e2ca90c2SFreddy Xin 548e2ca90c2SFreddy Xin /* ax88179/178A returns 2 bytes from eeprom on read */ 549e2ca90c2SFreddy Xin for (i = first_word; i <= last_word; i++) { 550e2ca90c2SFreddy Xin ret = __ax88179_read_cmd(dev, AX_ACCESS_EEPROM, i, 1, 2, 551843f9205SJustin Chen &eeprom_buff[i - first_word]); 552e2ca90c2SFreddy Xin if (ret < 0) { 553e2ca90c2SFreddy Xin kfree(eeprom_buff); 554e2ca90c2SFreddy Xin return -EIO; 555e2ca90c2SFreddy Xin } 556e2ca90c2SFreddy Xin } 557e2ca90c2SFreddy Xin 558e2ca90c2SFreddy Xin memcpy(data, (u8 *)eeprom_buff + (eeprom->offset & 1), eeprom->len); 559e2ca90c2SFreddy Xin kfree(eeprom_buff); 560e2ca90c2SFreddy Xin return 0; 561e2ca90c2SFreddy Xin } 562e2ca90c2SFreddy Xin 56378734404SBjorn Andersson static int 56478734404SBjorn Andersson ax88179_set_eeprom(struct net_device *net, struct ethtool_eeprom *eeprom, 56578734404SBjorn Andersson u8 *data) 56678734404SBjorn Andersson { 56778734404SBjorn Andersson struct usbnet *dev = netdev_priv(net); 56878734404SBjorn Andersson u16 *eeprom_buff; 56978734404SBjorn Andersson int first_word; 57078734404SBjorn Andersson int last_word; 57178734404SBjorn Andersson int ret; 57278734404SBjorn Andersson int i; 57378734404SBjorn Andersson 57478734404SBjorn Andersson netdev_dbg(net, "write EEPROM len %d, offset %d, magic 0x%x\n", 57578734404SBjorn Andersson eeprom->len, eeprom->offset, eeprom->magic); 57678734404SBjorn Andersson 57778734404SBjorn Andersson if (eeprom->len == 0) 57878734404SBjorn Andersson return -EINVAL; 57978734404SBjorn Andersson 58078734404SBjorn Andersson if (eeprom->magic != AX88179_EEPROM_MAGIC) 58178734404SBjorn Andersson return -EINVAL; 58278734404SBjorn Andersson 58378734404SBjorn Andersson first_word = eeprom->offset >> 1; 58478734404SBjorn Andersson last_word = (eeprom->offset + eeprom->len - 1) >> 1; 58578734404SBjorn Andersson 58678734404SBjorn Andersson eeprom_buff = kmalloc_array(last_word - first_word + 1, sizeof(u16), 58778734404SBjorn Andersson GFP_KERNEL); 58878734404SBjorn Andersson if (!eeprom_buff) 58978734404SBjorn Andersson return -ENOMEM; 59078734404SBjorn Andersson 59178734404SBjorn Andersson /* align data to 16 bit boundaries, read the missing data from 59278734404SBjorn Andersson the EEPROM */ 59378734404SBjorn Andersson if (eeprom->offset & 1) { 59478734404SBjorn Andersson ret = ax88179_read_cmd(dev, AX_ACCESS_EEPROM, first_word, 1, 2, 59578734404SBjorn Andersson &eeprom_buff[0]); 59678734404SBjorn Andersson if (ret < 0) { 59778734404SBjorn Andersson netdev_err(net, "Failed to read EEPROM at offset 0x%02x.\n", first_word); 59878734404SBjorn Andersson goto free; 59978734404SBjorn Andersson } 60078734404SBjorn Andersson } 60178734404SBjorn Andersson 60278734404SBjorn Andersson if ((eeprom->offset + eeprom->len) & 1) { 60378734404SBjorn Andersson ret = ax88179_read_cmd(dev, AX_ACCESS_EEPROM, last_word, 1, 2, 60478734404SBjorn Andersson &eeprom_buff[last_word - first_word]); 60578734404SBjorn Andersson if (ret < 0) { 60678734404SBjorn Andersson netdev_err(net, "Failed to read EEPROM at offset 0x%02x.\n", last_word); 60778734404SBjorn Andersson goto free; 60878734404SBjorn Andersson } 60978734404SBjorn Andersson } 61078734404SBjorn Andersson 61178734404SBjorn Andersson memcpy((u8 *)eeprom_buff + (eeprom->offset & 1), data, eeprom->len); 61278734404SBjorn Andersson 61378734404SBjorn Andersson for (i = first_word; i <= last_word; i++) { 61478734404SBjorn Andersson netdev_dbg(net, "write to EEPROM at offset 0x%02x, data 0x%04x\n", 61578734404SBjorn Andersson i, eeprom_buff[i - first_word]); 61678734404SBjorn Andersson ret = ax88179_write_cmd(dev, AX_ACCESS_EEPROM, i, 1, 2, 61778734404SBjorn Andersson &eeprom_buff[i - first_word]); 61878734404SBjorn Andersson if (ret < 0) { 61978734404SBjorn Andersson netdev_err(net, "Failed to write EEPROM at offset 0x%02x.\n", i); 62078734404SBjorn Andersson goto free; 62178734404SBjorn Andersson } 62278734404SBjorn Andersson msleep(20); 62378734404SBjorn Andersson } 62478734404SBjorn Andersson 62578734404SBjorn Andersson /* reload EEPROM data */ 62678734404SBjorn Andersson ret = ax88179_write_cmd(dev, AX_RELOAD_EEPROM_EFUSE, 0x0000, 0, 0, NULL); 62778734404SBjorn Andersson if (ret < 0) { 62878734404SBjorn Andersson netdev_err(net, "Failed to reload EEPROM data\n"); 62978734404SBjorn Andersson goto free; 63078734404SBjorn Andersson } 63178734404SBjorn Andersson 63278734404SBjorn Andersson ret = 0; 63378734404SBjorn Andersson free: 63478734404SBjorn Andersson kfree(eeprom_buff); 63578734404SBjorn Andersson return ret; 63678734404SBjorn Andersson } 63778734404SBjorn Andersson 6383c9b803bSPhilippe Reynes static int ax88179_get_link_ksettings(struct net_device *net, 6393c9b803bSPhilippe Reynes struct ethtool_link_ksettings *cmd) 640e2ca90c2SFreddy Xin { 641e2ca90c2SFreddy Xin struct usbnet *dev = netdev_priv(net); 64282c01a84Syuval.shaia@oracle.com 64382c01a84Syuval.shaia@oracle.com mii_ethtool_get_link_ksettings(&dev->mii, cmd); 64482c01a84Syuval.shaia@oracle.com 64582c01a84Syuval.shaia@oracle.com return 0; 646e2ca90c2SFreddy Xin } 647e2ca90c2SFreddy Xin 6483c9b803bSPhilippe Reynes static int ax88179_set_link_ksettings(struct net_device *net, 6493c9b803bSPhilippe Reynes const struct ethtool_link_ksettings *cmd) 650e2ca90c2SFreddy Xin { 651e2ca90c2SFreddy Xin struct usbnet *dev = netdev_priv(net); 6523c9b803bSPhilippe Reynes return mii_ethtool_set_link_ksettings(&dev->mii, cmd); 653e2ca90c2SFreddy Xin } 654e2ca90c2SFreddy Xin 655e98d69baSFreddy Xin static int 656e98d69baSFreddy Xin ax88179_ethtool_get_eee(struct usbnet *dev, struct ethtool_eee *data) 657e98d69baSFreddy Xin { 658e98d69baSFreddy Xin int val; 659e98d69baSFreddy Xin 660e98d69baSFreddy Xin /* Get Supported EEE */ 661e98d69baSFreddy Xin val = ax88179_phy_read_mmd_indirect(dev, MDIO_PCS_EEE_ABLE, 662e98d69baSFreddy Xin MDIO_MMD_PCS); 663e98d69baSFreddy Xin if (val < 0) 664e98d69baSFreddy Xin return val; 665e98d69baSFreddy Xin data->supported = mmd_eee_cap_to_ethtool_sup_t(val); 666e98d69baSFreddy Xin 667e98d69baSFreddy Xin /* Get advertisement EEE */ 668e98d69baSFreddy Xin val = ax88179_phy_read_mmd_indirect(dev, MDIO_AN_EEE_ADV, 669e98d69baSFreddy Xin MDIO_MMD_AN); 670e98d69baSFreddy Xin if (val < 0) 671e98d69baSFreddy Xin return val; 672e98d69baSFreddy Xin data->advertised = mmd_eee_adv_to_ethtool_adv_t(val); 673e98d69baSFreddy Xin 674e98d69baSFreddy Xin /* Get LP advertisement EEE */ 675e98d69baSFreddy Xin val = ax88179_phy_read_mmd_indirect(dev, MDIO_AN_EEE_LPABLE, 676e98d69baSFreddy Xin MDIO_MMD_AN); 677e98d69baSFreddy Xin if (val < 0) 678e98d69baSFreddy Xin return val; 679e98d69baSFreddy Xin data->lp_advertised = mmd_eee_adv_to_ethtool_adv_t(val); 680e98d69baSFreddy Xin 681e98d69baSFreddy Xin return 0; 682e98d69baSFreddy Xin } 683e98d69baSFreddy Xin 684e98d69baSFreddy Xin static int 685e98d69baSFreddy Xin ax88179_ethtool_set_eee(struct usbnet *dev, struct ethtool_eee *data) 686e98d69baSFreddy Xin { 687e98d69baSFreddy Xin u16 tmp16 = ethtool_adv_to_mmd_eee_adv_t(data->advertised); 688e98d69baSFreddy Xin 689e98d69baSFreddy Xin return ax88179_phy_write_mmd_indirect(dev, MDIO_AN_EEE_ADV, 690e98d69baSFreddy Xin MDIO_MMD_AN, tmp16); 691e98d69baSFreddy Xin } 692e98d69baSFreddy Xin 693e98d69baSFreddy Xin static int ax88179_chk_eee(struct usbnet *dev) 694e98d69baSFreddy Xin { 695e98d69baSFreddy Xin struct ethtool_cmd ecmd = { .cmd = ETHTOOL_GSET }; 696e98d69baSFreddy Xin struct ax88179_data *priv = (struct ax88179_data *)dev->data; 697e98d69baSFreddy Xin 698e98d69baSFreddy Xin mii_ethtool_gset(&dev->mii, &ecmd); 699e98d69baSFreddy Xin 700e98d69baSFreddy Xin if (ecmd.duplex & DUPLEX_FULL) { 701e98d69baSFreddy Xin int eee_lp, eee_cap, eee_adv; 702e98d69baSFreddy Xin u32 lp, cap, adv, supported = 0; 703e98d69baSFreddy Xin 704e98d69baSFreddy Xin eee_cap = ax88179_phy_read_mmd_indirect(dev, 705e98d69baSFreddy Xin MDIO_PCS_EEE_ABLE, 706e98d69baSFreddy Xin MDIO_MMD_PCS); 707e98d69baSFreddy Xin if (eee_cap < 0) { 708e98d69baSFreddy Xin priv->eee_active = 0; 709e98d69baSFreddy Xin return false; 710e98d69baSFreddy Xin } 711e98d69baSFreddy Xin 712e98d69baSFreddy Xin cap = mmd_eee_cap_to_ethtool_sup_t(eee_cap); 713e98d69baSFreddy Xin if (!cap) { 714e98d69baSFreddy Xin priv->eee_active = 0; 715e98d69baSFreddy Xin return false; 716e98d69baSFreddy Xin } 717e98d69baSFreddy Xin 718e98d69baSFreddy Xin eee_lp = ax88179_phy_read_mmd_indirect(dev, 719e98d69baSFreddy Xin MDIO_AN_EEE_LPABLE, 720e98d69baSFreddy Xin MDIO_MMD_AN); 721e98d69baSFreddy Xin if (eee_lp < 0) { 722e98d69baSFreddy Xin priv->eee_active = 0; 723e98d69baSFreddy Xin return false; 724e98d69baSFreddy Xin } 725e98d69baSFreddy Xin 726e98d69baSFreddy Xin eee_adv = ax88179_phy_read_mmd_indirect(dev, 727e98d69baSFreddy Xin MDIO_AN_EEE_ADV, 728e98d69baSFreddy Xin MDIO_MMD_AN); 729e98d69baSFreddy Xin 730e98d69baSFreddy Xin if (eee_adv < 0) { 731e98d69baSFreddy Xin priv->eee_active = 0; 732e98d69baSFreddy Xin return false; 733e98d69baSFreddy Xin } 734e98d69baSFreddy Xin 735e98d69baSFreddy Xin adv = mmd_eee_adv_to_ethtool_adv_t(eee_adv); 736e98d69baSFreddy Xin lp = mmd_eee_adv_to_ethtool_adv_t(eee_lp); 737e98d69baSFreddy Xin supported = (ecmd.speed == SPEED_1000) ? 738e98d69baSFreddy Xin SUPPORTED_1000baseT_Full : 739e98d69baSFreddy Xin SUPPORTED_100baseT_Full; 740e98d69baSFreddy Xin 741e98d69baSFreddy Xin if (!(lp & adv & supported)) { 742e98d69baSFreddy Xin priv->eee_active = 0; 743e98d69baSFreddy Xin return false; 744e98d69baSFreddy Xin } 745e98d69baSFreddy Xin 746e98d69baSFreddy Xin priv->eee_active = 1; 747e98d69baSFreddy Xin return true; 748e98d69baSFreddy Xin } 749e98d69baSFreddy Xin 750e98d69baSFreddy Xin priv->eee_active = 0; 751e98d69baSFreddy Xin return false; 752e98d69baSFreddy Xin } 753e98d69baSFreddy Xin 754e98d69baSFreddy Xin static void ax88179_disable_eee(struct usbnet *dev) 755e98d69baSFreddy Xin { 756e98d69baSFreddy Xin u16 tmp16; 757e98d69baSFreddy Xin 758e98d69baSFreddy Xin tmp16 = GMII_PHY_PGSEL_PAGE3; 759e98d69baSFreddy Xin ax88179_write_cmd(dev, AX_ACCESS_PHY, AX88179_PHY_ID, 760e98d69baSFreddy Xin GMII_PHY_PAGE_SELECT, 2, &tmp16); 761e98d69baSFreddy Xin 762e98d69baSFreddy Xin tmp16 = 0x3246; 763e98d69baSFreddy Xin ax88179_write_cmd(dev, AX_ACCESS_PHY, AX88179_PHY_ID, 764e98d69baSFreddy Xin MII_PHYADDR, 2, &tmp16); 765e98d69baSFreddy Xin 766e98d69baSFreddy Xin tmp16 = GMII_PHY_PGSEL_PAGE0; 767e98d69baSFreddy Xin ax88179_write_cmd(dev, AX_ACCESS_PHY, AX88179_PHY_ID, 768e98d69baSFreddy Xin GMII_PHY_PAGE_SELECT, 2, &tmp16); 769e98d69baSFreddy Xin } 770e98d69baSFreddy Xin 771e98d69baSFreddy Xin static void ax88179_enable_eee(struct usbnet *dev) 772e98d69baSFreddy Xin { 773e98d69baSFreddy Xin u16 tmp16; 774e98d69baSFreddy Xin 775e98d69baSFreddy Xin tmp16 = GMII_PHY_PGSEL_PAGE3; 776e98d69baSFreddy Xin ax88179_write_cmd(dev, AX_ACCESS_PHY, AX88179_PHY_ID, 777e98d69baSFreddy Xin GMII_PHY_PAGE_SELECT, 2, &tmp16); 778e98d69baSFreddy Xin 779e98d69baSFreddy Xin tmp16 = 0x3247; 780e98d69baSFreddy Xin ax88179_write_cmd(dev, AX_ACCESS_PHY, AX88179_PHY_ID, 781e98d69baSFreddy Xin MII_PHYADDR, 2, &tmp16); 782e98d69baSFreddy Xin 783e98d69baSFreddy Xin tmp16 = GMII_PHY_PGSEL_PAGE5; 784e98d69baSFreddy Xin ax88179_write_cmd(dev, AX_ACCESS_PHY, AX88179_PHY_ID, 785e98d69baSFreddy Xin GMII_PHY_PAGE_SELECT, 2, &tmp16); 786e98d69baSFreddy Xin 787e98d69baSFreddy Xin tmp16 = 0x0680; 788e98d69baSFreddy Xin ax88179_write_cmd(dev, AX_ACCESS_PHY, AX88179_PHY_ID, 789e98d69baSFreddy Xin MII_BMSR, 2, &tmp16); 790e98d69baSFreddy Xin 791e98d69baSFreddy Xin tmp16 = GMII_PHY_PGSEL_PAGE0; 792e98d69baSFreddy Xin ax88179_write_cmd(dev, AX_ACCESS_PHY, AX88179_PHY_ID, 793e98d69baSFreddy Xin GMII_PHY_PAGE_SELECT, 2, &tmp16); 794e98d69baSFreddy Xin } 795e98d69baSFreddy Xin 796e98d69baSFreddy Xin static int ax88179_get_eee(struct net_device *net, struct ethtool_eee *edata) 797e98d69baSFreddy Xin { 798e98d69baSFreddy Xin struct usbnet *dev = netdev_priv(net); 799e98d69baSFreddy Xin struct ax88179_data *priv = (struct ax88179_data *)dev->data; 800e98d69baSFreddy Xin 801e98d69baSFreddy Xin edata->eee_enabled = priv->eee_enabled; 802e98d69baSFreddy Xin edata->eee_active = priv->eee_active; 803e98d69baSFreddy Xin 804e98d69baSFreddy Xin return ax88179_ethtool_get_eee(dev, edata); 805e98d69baSFreddy Xin } 806e98d69baSFreddy Xin 807e98d69baSFreddy Xin static int ax88179_set_eee(struct net_device *net, struct ethtool_eee *edata) 808e98d69baSFreddy Xin { 809e98d69baSFreddy Xin struct usbnet *dev = netdev_priv(net); 810e98d69baSFreddy Xin struct ax88179_data *priv = (struct ax88179_data *)dev->data; 811d728e640SColin Ian King int ret; 812e98d69baSFreddy Xin 813e98d69baSFreddy Xin priv->eee_enabled = edata->eee_enabled; 814e98d69baSFreddy Xin if (!priv->eee_enabled) { 815e98d69baSFreddy Xin ax88179_disable_eee(dev); 816e98d69baSFreddy Xin } else { 817e98d69baSFreddy Xin priv->eee_enabled = ax88179_chk_eee(dev); 818e98d69baSFreddy Xin if (!priv->eee_enabled) 819e98d69baSFreddy Xin return -EOPNOTSUPP; 820e98d69baSFreddy Xin 821e98d69baSFreddy Xin ax88179_enable_eee(dev); 822e98d69baSFreddy Xin } 823e98d69baSFreddy Xin 824e98d69baSFreddy Xin ret = ax88179_ethtool_set_eee(dev, edata); 825e98d69baSFreddy Xin if (ret) 826e98d69baSFreddy Xin return ret; 827e98d69baSFreddy Xin 828e98d69baSFreddy Xin mii_nway_restart(&dev->mii); 829e98d69baSFreddy Xin 830e98d69baSFreddy Xin usbnet_link_change(dev, 0, 0); 831e98d69baSFreddy Xin 832e98d69baSFreddy Xin return ret; 833e98d69baSFreddy Xin } 834e2ca90c2SFreddy Xin 835e2ca90c2SFreddy Xin static int ax88179_ioctl(struct net_device *net, struct ifreq *rq, int cmd) 836e2ca90c2SFreddy Xin { 837e2ca90c2SFreddy Xin struct usbnet *dev = netdev_priv(net); 838e2ca90c2SFreddy Xin return generic_mii_ioctl(&dev->mii, if_mii(rq), cmd, NULL); 839e2ca90c2SFreddy Xin } 840e2ca90c2SFreddy Xin 841e2ca90c2SFreddy Xin static const struct ethtool_ops ax88179_ethtool_ops = { 842e2ca90c2SFreddy Xin .get_link = ethtool_op_get_link, 843e2ca90c2SFreddy Xin .get_msglevel = usbnet_get_msglevel, 844e2ca90c2SFreddy Xin .set_msglevel = usbnet_set_msglevel, 845e2ca90c2SFreddy Xin .get_wol = ax88179_get_wol, 846e2ca90c2SFreddy Xin .set_wol = ax88179_set_wol, 847e2ca90c2SFreddy Xin .get_eeprom_len = ax88179_get_eeprom_len, 848e2ca90c2SFreddy Xin .get_eeprom = ax88179_get_eeprom, 84978734404SBjorn Andersson .set_eeprom = ax88179_set_eeprom, 850e98d69baSFreddy Xin .get_eee = ax88179_get_eee, 851e98d69baSFreddy Xin .set_eee = ax88179_set_eee, 852e2ca90c2SFreddy Xin .nway_reset = usbnet_nway_reset, 8533c9b803bSPhilippe Reynes .get_link_ksettings = ax88179_get_link_ksettings, 8543c9b803bSPhilippe Reynes .set_link_ksettings = ax88179_set_link_ksettings, 855dc83ef22SAndreas K. Besslein .get_ts_info = ethtool_op_get_ts_info, 856e2ca90c2SFreddy Xin }; 857e2ca90c2SFreddy Xin 858e2ca90c2SFreddy Xin static void ax88179_set_multicast(struct net_device *net) 859e2ca90c2SFreddy Xin { 860e2ca90c2SFreddy Xin struct usbnet *dev = netdev_priv(net); 861e2ca90c2SFreddy Xin struct ax88179_data *data = (struct ax88179_data *)dev->data; 862e2ca90c2SFreddy Xin u8 *m_filter = ((u8 *)dev->data) + 12; 863e2ca90c2SFreddy Xin 864e2ca90c2SFreddy Xin data->rxctl = (AX_RX_CTL_START | AX_RX_CTL_AB | AX_RX_CTL_IPE); 865e2ca90c2SFreddy Xin 866e2ca90c2SFreddy Xin if (net->flags & IFF_PROMISC) { 867e2ca90c2SFreddy Xin data->rxctl |= AX_RX_CTL_PRO; 868e2ca90c2SFreddy Xin } else if (net->flags & IFF_ALLMULTI || 869e2ca90c2SFreddy Xin netdev_mc_count(net) > AX_MAX_MCAST) { 870e2ca90c2SFreddy Xin data->rxctl |= AX_RX_CTL_AMALL; 871e2ca90c2SFreddy Xin } else if (netdev_mc_empty(net)) { 872e2ca90c2SFreddy Xin /* just broadcast and directed */ 873e2ca90c2SFreddy Xin } else { 874e2ca90c2SFreddy Xin /* We use the 20 byte dev->data for our 8 byte filter buffer 875e2ca90c2SFreddy Xin * to avoid allocating memory that is tricky to free later 876e2ca90c2SFreddy Xin */ 877e2ca90c2SFreddy Xin u32 crc_bits; 878e2ca90c2SFreddy Xin struct netdev_hw_addr *ha; 879e2ca90c2SFreddy Xin 880e2ca90c2SFreddy Xin memset(m_filter, 0, AX_MCAST_FLTSIZE); 881e2ca90c2SFreddy Xin 882e2ca90c2SFreddy Xin netdev_for_each_mc_addr(ha, net) { 883e2ca90c2SFreddy Xin crc_bits = ether_crc(ETH_ALEN, ha->addr) >> 26; 884e2ca90c2SFreddy Xin *(m_filter + (crc_bits >> 3)) |= (1 << (crc_bits & 7)); 885e2ca90c2SFreddy Xin } 886e2ca90c2SFreddy Xin 887e2ca90c2SFreddy Xin ax88179_write_cmd_async(dev, AX_ACCESS_MAC, AX_MULFLTARY, 888e2ca90c2SFreddy Xin AX_MCAST_FLTSIZE, AX_MCAST_FLTSIZE, 889e2ca90c2SFreddy Xin m_filter); 890e2ca90c2SFreddy Xin 891e2ca90c2SFreddy Xin data->rxctl |= AX_RX_CTL_AM; 892e2ca90c2SFreddy Xin } 893e2ca90c2SFreddy Xin 894e2ca90c2SFreddy Xin ax88179_write_cmd_async(dev, AX_ACCESS_MAC, AX_RX_CTL, 895e2ca90c2SFreddy Xin 2, 2, &data->rxctl); 896e2ca90c2SFreddy Xin } 897e2ca90c2SFreddy Xin 898e2ca90c2SFreddy Xin static int 899e2ca90c2SFreddy Xin ax88179_set_features(struct net_device *net, netdev_features_t features) 900e2ca90c2SFreddy Xin { 901e2ca90c2SFreddy Xin u8 tmp; 902e2ca90c2SFreddy Xin struct usbnet *dev = netdev_priv(net); 903e2ca90c2SFreddy Xin netdev_features_t changed = net->features ^ features; 904e2ca90c2SFreddy Xin 905e2ca90c2SFreddy Xin if (changed & NETIF_F_IP_CSUM) { 906e2ca90c2SFreddy Xin ax88179_read_cmd(dev, AX_ACCESS_MAC, AX_TXCOE_CTL, 1, 1, &tmp); 907e2ca90c2SFreddy Xin tmp ^= AX_TXCOE_TCP | AX_TXCOE_UDP; 908e2ca90c2SFreddy Xin ax88179_write_cmd(dev, AX_ACCESS_MAC, AX_TXCOE_CTL, 1, 1, &tmp); 909e2ca90c2SFreddy Xin } 910e2ca90c2SFreddy Xin 911e2ca90c2SFreddy Xin if (changed & NETIF_F_IPV6_CSUM) { 912e2ca90c2SFreddy Xin ax88179_read_cmd(dev, AX_ACCESS_MAC, AX_TXCOE_CTL, 1, 1, &tmp); 913e2ca90c2SFreddy Xin tmp ^= AX_TXCOE_TCPV6 | AX_TXCOE_UDPV6; 914e2ca90c2SFreddy Xin ax88179_write_cmd(dev, AX_ACCESS_MAC, AX_TXCOE_CTL, 1, 1, &tmp); 915e2ca90c2SFreddy Xin } 916e2ca90c2SFreddy Xin 917e2ca90c2SFreddy Xin if (changed & NETIF_F_RXCSUM) { 918e2ca90c2SFreddy Xin ax88179_read_cmd(dev, AX_ACCESS_MAC, AX_RXCOE_CTL, 1, 1, &tmp); 919e2ca90c2SFreddy Xin tmp ^= AX_RXCOE_IP | AX_RXCOE_TCP | AX_RXCOE_UDP | 920e2ca90c2SFreddy Xin AX_RXCOE_TCPV6 | AX_RXCOE_UDPV6; 921e2ca90c2SFreddy Xin ax88179_write_cmd(dev, AX_ACCESS_MAC, AX_RXCOE_CTL, 1, 1, &tmp); 922e2ca90c2SFreddy Xin } 923e2ca90c2SFreddy Xin 924e2ca90c2SFreddy Xin return 0; 925e2ca90c2SFreddy Xin } 926e2ca90c2SFreddy Xin 927e2ca90c2SFreddy Xin static int ax88179_change_mtu(struct net_device *net, int new_mtu) 928e2ca90c2SFreddy Xin { 929e2ca90c2SFreddy Xin struct usbnet *dev = netdev_priv(net); 930e2ca90c2SFreddy Xin u16 tmp16; 931e2ca90c2SFreddy Xin 932e2ca90c2SFreddy Xin net->mtu = new_mtu; 933e2ca90c2SFreddy Xin dev->hard_mtu = net->mtu + net->hard_header_len; 934e2ca90c2SFreddy Xin 935e2ca90c2SFreddy Xin if (net->mtu > 1500) { 936e2ca90c2SFreddy Xin ax88179_read_cmd(dev, AX_ACCESS_MAC, AX_MEDIUM_STATUS_MODE, 937e2ca90c2SFreddy Xin 2, 2, &tmp16); 938e2ca90c2SFreddy Xin tmp16 |= AX_MEDIUM_JUMBO_EN; 939e2ca90c2SFreddy Xin ax88179_write_cmd(dev, AX_ACCESS_MAC, AX_MEDIUM_STATUS_MODE, 940e2ca90c2SFreddy Xin 2, 2, &tmp16); 941e2ca90c2SFreddy Xin } else { 942e2ca90c2SFreddy Xin ax88179_read_cmd(dev, AX_ACCESS_MAC, AX_MEDIUM_STATUS_MODE, 943e2ca90c2SFreddy Xin 2, 2, &tmp16); 944e2ca90c2SFreddy Xin tmp16 &= ~AX_MEDIUM_JUMBO_EN; 945e2ca90c2SFreddy Xin ax88179_write_cmd(dev, AX_ACCESS_MAC, AX_MEDIUM_STATUS_MODE, 946e2ca90c2SFreddy Xin 2, 2, &tmp16); 947e2ca90c2SFreddy Xin } 948e2ca90c2SFreddy Xin 949a88c32aeSMing Lei /* max qlen depend on hard_mtu and rx_urb_size */ 950a88c32aeSMing Lei usbnet_update_max_qlen(dev); 951a88c32aeSMing Lei 952e2ca90c2SFreddy Xin return 0; 953e2ca90c2SFreddy Xin } 954e2ca90c2SFreddy Xin 955e2ca90c2SFreddy Xin static int ax88179_set_mac_addr(struct net_device *net, void *p) 956e2ca90c2SFreddy Xin { 957e2ca90c2SFreddy Xin struct usbnet *dev = netdev_priv(net); 958e2ca90c2SFreddy Xin struct sockaddr *addr = p; 95995ff8868SIan Morgan int ret; 960e2ca90c2SFreddy Xin 961e2ca90c2SFreddy Xin if (netif_running(net)) 962e2ca90c2SFreddy Xin return -EBUSY; 963e2ca90c2SFreddy Xin if (!is_valid_ether_addr(addr->sa_data)) 964e2ca90c2SFreddy Xin return -EADDRNOTAVAIL; 965e2ca90c2SFreddy Xin 96616813717SJakub Kicinski eth_hw_addr_set(net, addr->sa_data); 967e2ca90c2SFreddy Xin 968e2ca90c2SFreddy Xin /* Set the MAC address */ 96995ff8868SIan Morgan ret = ax88179_write_cmd(dev, AX_ACCESS_MAC, AX_NODE_ID, ETH_ALEN, 970e2ca90c2SFreddy Xin ETH_ALEN, net->dev_addr); 97195ff8868SIan Morgan if (ret < 0) 97295ff8868SIan Morgan return ret; 97395ff8868SIan Morgan 97495ff8868SIan Morgan return 0; 975e2ca90c2SFreddy Xin } 976e2ca90c2SFreddy Xin 977e2ca90c2SFreddy Xin static const struct net_device_ops ax88179_netdev_ops = { 978e2ca90c2SFreddy Xin .ndo_open = usbnet_open, 979e2ca90c2SFreddy Xin .ndo_stop = usbnet_stop, 980e2ca90c2SFreddy Xin .ndo_start_xmit = usbnet_start_xmit, 981e2ca90c2SFreddy Xin .ndo_tx_timeout = usbnet_tx_timeout, 982323955a0SHeiner Kallweit .ndo_get_stats64 = dev_get_tstats64, 983e2ca90c2SFreddy Xin .ndo_change_mtu = ax88179_change_mtu, 984e2ca90c2SFreddy Xin .ndo_set_mac_address = ax88179_set_mac_addr, 985e2ca90c2SFreddy Xin .ndo_validate_addr = eth_validate_addr, 986a7605370SArnd Bergmann .ndo_eth_ioctl = ax88179_ioctl, 987e2ca90c2SFreddy Xin .ndo_set_rx_mode = ax88179_set_multicast, 988e2ca90c2SFreddy Xin .ndo_set_features = ax88179_set_features, 989e2ca90c2SFreddy Xin }; 990e2ca90c2SFreddy Xin 991e2ca90c2SFreddy Xin static int ax88179_check_eeprom(struct usbnet *dev) 992e2ca90c2SFreddy Xin { 993e2ca90c2SFreddy Xin u8 i, buf, eeprom[20]; 994e2ca90c2SFreddy Xin u16 csum, delay = HZ / 10; 995e2ca90c2SFreddy Xin unsigned long jtimeout; 996e2ca90c2SFreddy Xin 997e2ca90c2SFreddy Xin /* Read EEPROM content */ 998e2ca90c2SFreddy Xin for (i = 0; i < 6; i++) { 999e2ca90c2SFreddy Xin buf = i; 1000e2ca90c2SFreddy Xin if (ax88179_write_cmd(dev, AX_ACCESS_MAC, AX_SROM_ADDR, 1001e2ca90c2SFreddy Xin 1, 1, &buf) < 0) 1002e2ca90c2SFreddy Xin return -EINVAL; 1003e2ca90c2SFreddy Xin 1004e2ca90c2SFreddy Xin buf = EEP_RD; 1005e2ca90c2SFreddy Xin if (ax88179_write_cmd(dev, AX_ACCESS_MAC, AX_SROM_CMD, 1006e2ca90c2SFreddy Xin 1, 1, &buf) < 0) 1007e2ca90c2SFreddy Xin return -EINVAL; 1008e2ca90c2SFreddy Xin 1009e2ca90c2SFreddy Xin jtimeout = jiffies + delay; 1010e2ca90c2SFreddy Xin do { 1011e2ca90c2SFreddy Xin ax88179_read_cmd(dev, AX_ACCESS_MAC, AX_SROM_CMD, 1012e2ca90c2SFreddy Xin 1, 1, &buf); 1013e2ca90c2SFreddy Xin 1014e2ca90c2SFreddy Xin if (time_after(jiffies, jtimeout)) 1015e2ca90c2SFreddy Xin return -EINVAL; 1016e2ca90c2SFreddy Xin 1017e2ca90c2SFreddy Xin } while (buf & EEP_BUSY); 1018e2ca90c2SFreddy Xin 1019e2ca90c2SFreddy Xin __ax88179_read_cmd(dev, AX_ACCESS_MAC, AX_SROM_DATA_LOW, 1020843f9205SJustin Chen 2, 2, &eeprom[i * 2]); 1021e2ca90c2SFreddy Xin 1022e2ca90c2SFreddy Xin if ((i == 0) && (eeprom[0] == 0xFF)) 1023e2ca90c2SFreddy Xin return -EINVAL; 1024e2ca90c2SFreddy Xin } 1025e2ca90c2SFreddy Xin 1026e2ca90c2SFreddy Xin csum = eeprom[6] + eeprom[7] + eeprom[8] + eeprom[9]; 1027e2ca90c2SFreddy Xin csum = (csum >> 8) + (csum & 0xff); 1028e2ca90c2SFreddy Xin if ((csum + eeprom[10]) != 0xff) 1029e2ca90c2SFreddy Xin return -EINVAL; 1030e2ca90c2SFreddy Xin 1031e2ca90c2SFreddy Xin return 0; 1032e2ca90c2SFreddy Xin } 1033e2ca90c2SFreddy Xin 1034e2ca90c2SFreddy Xin static int ax88179_check_efuse(struct usbnet *dev, u16 *ledmode) 1035e2ca90c2SFreddy Xin { 1036e2ca90c2SFreddy Xin u8 i; 1037e2ca90c2SFreddy Xin u8 efuse[64]; 1038e2ca90c2SFreddy Xin u16 csum = 0; 1039e2ca90c2SFreddy Xin 1040e2ca90c2SFreddy Xin if (ax88179_read_cmd(dev, AX_ACCESS_EFUS, 0, 64, 64, efuse) < 0) 1041e2ca90c2SFreddy Xin return -EINVAL; 1042e2ca90c2SFreddy Xin 1043e2ca90c2SFreddy Xin if (*efuse == 0xFF) 1044e2ca90c2SFreddy Xin return -EINVAL; 1045e2ca90c2SFreddy Xin 1046e2ca90c2SFreddy Xin for (i = 0; i < 64; i++) 1047e2ca90c2SFreddy Xin csum = csum + efuse[i]; 1048e2ca90c2SFreddy Xin 1049e2ca90c2SFreddy Xin while (csum > 255) 1050e2ca90c2SFreddy Xin csum = (csum & 0x00FF) + ((csum >> 8) & 0x00FF); 1051e2ca90c2SFreddy Xin 1052e2ca90c2SFreddy Xin if (csum != 0xFF) 1053e2ca90c2SFreddy Xin return -EINVAL; 1054e2ca90c2SFreddy Xin 1055e2ca90c2SFreddy Xin *ledmode = (efuse[51] << 8) | efuse[52]; 1056e2ca90c2SFreddy Xin 1057e2ca90c2SFreddy Xin return 0; 1058e2ca90c2SFreddy Xin } 1059e2ca90c2SFreddy Xin 1060e2ca90c2SFreddy Xin static int ax88179_convert_old_led(struct usbnet *dev, u16 *ledvalue) 1061e2ca90c2SFreddy Xin { 1062e2ca90c2SFreddy Xin u16 led; 1063e2ca90c2SFreddy Xin 1064e2ca90c2SFreddy Xin /* Loaded the old eFuse LED Mode */ 1065e2ca90c2SFreddy Xin if (ax88179_read_cmd(dev, AX_ACCESS_EEPROM, 0x3C, 1, 2, &led) < 0) 1066e2ca90c2SFreddy Xin return -EINVAL; 1067e2ca90c2SFreddy Xin 1068e2ca90c2SFreddy Xin led >>= 8; 1069e2ca90c2SFreddy Xin switch (led) { 1070e2ca90c2SFreddy Xin case 0xFF: 1071e2ca90c2SFreddy Xin led = LED0_ACTIVE | LED1_LINK_10 | LED1_LINK_100 | 1072e2ca90c2SFreddy Xin LED1_LINK_1000 | LED2_ACTIVE | LED2_LINK_10 | 1073e2ca90c2SFreddy Xin LED2_LINK_100 | LED2_LINK_1000 | LED_VALID; 1074e2ca90c2SFreddy Xin break; 1075e2ca90c2SFreddy Xin case 0xFE: 1076e2ca90c2SFreddy Xin led = LED0_ACTIVE | LED1_LINK_1000 | LED2_LINK_100 | LED_VALID; 1077e2ca90c2SFreddy Xin break; 1078e2ca90c2SFreddy Xin case 0xFD: 1079e2ca90c2SFreddy Xin led = LED0_ACTIVE | LED1_LINK_1000 | LED2_LINK_100 | 1080e2ca90c2SFreddy Xin LED2_LINK_10 | LED_VALID; 1081e2ca90c2SFreddy Xin break; 1082e2ca90c2SFreddy Xin case 0xFC: 1083e2ca90c2SFreddy Xin led = LED0_ACTIVE | LED1_ACTIVE | LED1_LINK_1000 | LED2_ACTIVE | 1084e2ca90c2SFreddy Xin LED2_LINK_100 | LED2_LINK_10 | LED_VALID; 1085e2ca90c2SFreddy Xin break; 1086e2ca90c2SFreddy Xin default: 1087e2ca90c2SFreddy Xin led = LED0_ACTIVE | LED1_LINK_10 | LED1_LINK_100 | 1088e2ca90c2SFreddy Xin LED1_LINK_1000 | LED2_ACTIVE | LED2_LINK_10 | 1089e2ca90c2SFreddy Xin LED2_LINK_100 | LED2_LINK_1000 | LED_VALID; 1090e2ca90c2SFreddy Xin break; 1091e2ca90c2SFreddy Xin } 1092e2ca90c2SFreddy Xin 1093e2ca90c2SFreddy Xin *ledvalue = led; 1094e2ca90c2SFreddy Xin 1095e2ca90c2SFreddy Xin return 0; 1096e2ca90c2SFreddy Xin } 1097e2ca90c2SFreddy Xin 1098e2ca90c2SFreddy Xin static int ax88179_led_setting(struct usbnet *dev) 1099e2ca90c2SFreddy Xin { 1100e2ca90c2SFreddy Xin u8 ledfd, value = 0; 1101e2ca90c2SFreddy Xin u16 tmp, ledact, ledlink, ledvalue = 0, delay = HZ / 10; 1102e2ca90c2SFreddy Xin unsigned long jtimeout; 1103e2ca90c2SFreddy Xin 1104e2ca90c2SFreddy Xin /* Check AX88179 version. UA1 or UA2*/ 1105e2ca90c2SFreddy Xin ax88179_read_cmd(dev, AX_ACCESS_MAC, GENERAL_STATUS, 1, 1, &value); 1106e2ca90c2SFreddy Xin 1107e2ca90c2SFreddy Xin if (!(value & AX_SECLD)) { /* UA1 */ 1108e2ca90c2SFreddy Xin value = AX_GPIO_CTRL_GPIO3EN | AX_GPIO_CTRL_GPIO2EN | 1109e2ca90c2SFreddy Xin AX_GPIO_CTRL_GPIO1EN; 1110e2ca90c2SFreddy Xin if (ax88179_write_cmd(dev, AX_ACCESS_MAC, AX_GPIO_CTRL, 1111e2ca90c2SFreddy Xin 1, 1, &value) < 0) 1112e2ca90c2SFreddy Xin return -EINVAL; 1113e2ca90c2SFreddy Xin } 1114e2ca90c2SFreddy Xin 1115e2ca90c2SFreddy Xin /* Check EEPROM */ 1116e2ca90c2SFreddy Xin if (!ax88179_check_eeprom(dev)) { 1117e2ca90c2SFreddy Xin value = 0x42; 1118e2ca90c2SFreddy Xin if (ax88179_write_cmd(dev, AX_ACCESS_MAC, AX_SROM_ADDR, 1119e2ca90c2SFreddy Xin 1, 1, &value) < 0) 1120e2ca90c2SFreddy Xin return -EINVAL; 1121e2ca90c2SFreddy Xin 1122e2ca90c2SFreddy Xin value = EEP_RD; 1123e2ca90c2SFreddy Xin if (ax88179_write_cmd(dev, AX_ACCESS_MAC, AX_SROM_CMD, 1124e2ca90c2SFreddy Xin 1, 1, &value) < 0) 1125e2ca90c2SFreddy Xin return -EINVAL; 1126e2ca90c2SFreddy Xin 1127e2ca90c2SFreddy Xin jtimeout = jiffies + delay; 1128e2ca90c2SFreddy Xin do { 1129e2ca90c2SFreddy Xin ax88179_read_cmd(dev, AX_ACCESS_MAC, AX_SROM_CMD, 1130e2ca90c2SFreddy Xin 1, 1, &value); 1131e2ca90c2SFreddy Xin 1132e2ca90c2SFreddy Xin if (time_after(jiffies, jtimeout)) 1133e2ca90c2SFreddy Xin return -EINVAL; 1134e2ca90c2SFreddy Xin 1135e2ca90c2SFreddy Xin } while (value & EEP_BUSY); 1136e2ca90c2SFreddy Xin 1137e2ca90c2SFreddy Xin ax88179_read_cmd(dev, AX_ACCESS_MAC, AX_SROM_DATA_HIGH, 1138e2ca90c2SFreddy Xin 1, 1, &value); 1139e2ca90c2SFreddy Xin ledvalue = (value << 8); 1140e2ca90c2SFreddy Xin 1141e2ca90c2SFreddy Xin ax88179_read_cmd(dev, AX_ACCESS_MAC, AX_SROM_DATA_LOW, 1142e2ca90c2SFreddy Xin 1, 1, &value); 1143e2ca90c2SFreddy Xin ledvalue |= value; 1144e2ca90c2SFreddy Xin 1145e2ca90c2SFreddy Xin /* load internal ROM for defaule setting */ 1146e2ca90c2SFreddy Xin if ((ledvalue == 0xFFFF) || ((ledvalue & LED_VALID) == 0)) 1147e2ca90c2SFreddy Xin ax88179_convert_old_led(dev, &ledvalue); 1148e2ca90c2SFreddy Xin 1149e2ca90c2SFreddy Xin } else if (!ax88179_check_efuse(dev, &ledvalue)) { 1150e2ca90c2SFreddy Xin if ((ledvalue == 0xFFFF) || ((ledvalue & LED_VALID) == 0)) 1151e2ca90c2SFreddy Xin ax88179_convert_old_led(dev, &ledvalue); 1152e2ca90c2SFreddy Xin } else { 1153e2ca90c2SFreddy Xin ax88179_convert_old_led(dev, &ledvalue); 1154e2ca90c2SFreddy Xin } 1155e2ca90c2SFreddy Xin 1156e2ca90c2SFreddy Xin tmp = GMII_PHY_PGSEL_EXT; 1157e2ca90c2SFreddy Xin ax88179_write_cmd(dev, AX_ACCESS_PHY, AX88179_PHY_ID, 1158e2ca90c2SFreddy Xin GMII_PHY_PAGE_SELECT, 2, &tmp); 1159e2ca90c2SFreddy Xin 1160e2ca90c2SFreddy Xin tmp = 0x2c; 1161e2ca90c2SFreddy Xin ax88179_write_cmd(dev, AX_ACCESS_PHY, AX88179_PHY_ID, 1162e2ca90c2SFreddy Xin GMII_PHYPAGE, 2, &tmp); 1163e2ca90c2SFreddy Xin 1164e2ca90c2SFreddy Xin ax88179_read_cmd(dev, AX_ACCESS_PHY, AX88179_PHY_ID, 1165e2ca90c2SFreddy Xin GMII_LED_ACT, 2, &ledact); 1166e2ca90c2SFreddy Xin 1167e2ca90c2SFreddy Xin ax88179_read_cmd(dev, AX_ACCESS_PHY, AX88179_PHY_ID, 1168e2ca90c2SFreddy Xin GMII_LED_LINK, 2, &ledlink); 1169e2ca90c2SFreddy Xin 1170e2ca90c2SFreddy Xin ledact &= GMII_LED_ACTIVE_MASK; 1171e2ca90c2SFreddy Xin ledlink &= GMII_LED_LINK_MASK; 1172e2ca90c2SFreddy Xin 1173e2ca90c2SFreddy Xin if (ledvalue & LED0_ACTIVE) 1174e2ca90c2SFreddy Xin ledact |= GMII_LED0_ACTIVE; 1175e2ca90c2SFreddy Xin 1176e2ca90c2SFreddy Xin if (ledvalue & LED1_ACTIVE) 1177e2ca90c2SFreddy Xin ledact |= GMII_LED1_ACTIVE; 1178e2ca90c2SFreddy Xin 1179e2ca90c2SFreddy Xin if (ledvalue & LED2_ACTIVE) 1180e2ca90c2SFreddy Xin ledact |= GMII_LED2_ACTIVE; 1181e2ca90c2SFreddy Xin 1182e2ca90c2SFreddy Xin if (ledvalue & LED0_LINK_10) 1183e2ca90c2SFreddy Xin ledlink |= GMII_LED0_LINK_10; 1184e2ca90c2SFreddy Xin 1185e2ca90c2SFreddy Xin if (ledvalue & LED1_LINK_10) 1186e2ca90c2SFreddy Xin ledlink |= GMII_LED1_LINK_10; 1187e2ca90c2SFreddy Xin 1188e2ca90c2SFreddy Xin if (ledvalue & LED2_LINK_10) 1189e2ca90c2SFreddy Xin ledlink |= GMII_LED2_LINK_10; 1190e2ca90c2SFreddy Xin 1191e2ca90c2SFreddy Xin if (ledvalue & LED0_LINK_100) 1192e2ca90c2SFreddy Xin ledlink |= GMII_LED0_LINK_100; 1193e2ca90c2SFreddy Xin 1194e2ca90c2SFreddy Xin if (ledvalue & LED1_LINK_100) 1195e2ca90c2SFreddy Xin ledlink |= GMII_LED1_LINK_100; 1196e2ca90c2SFreddy Xin 1197e2ca90c2SFreddy Xin if (ledvalue & LED2_LINK_100) 1198e2ca90c2SFreddy Xin ledlink |= GMII_LED2_LINK_100; 1199e2ca90c2SFreddy Xin 1200e2ca90c2SFreddy Xin if (ledvalue & LED0_LINK_1000) 1201e2ca90c2SFreddy Xin ledlink |= GMII_LED0_LINK_1000; 1202e2ca90c2SFreddy Xin 1203e2ca90c2SFreddy Xin if (ledvalue & LED1_LINK_1000) 1204e2ca90c2SFreddy Xin ledlink |= GMII_LED1_LINK_1000; 1205e2ca90c2SFreddy Xin 1206e2ca90c2SFreddy Xin if (ledvalue & LED2_LINK_1000) 1207e2ca90c2SFreddy Xin ledlink |= GMII_LED2_LINK_1000; 1208e2ca90c2SFreddy Xin 1209e2ca90c2SFreddy Xin tmp = ledact; 1210e2ca90c2SFreddy Xin ax88179_write_cmd(dev, AX_ACCESS_PHY, AX88179_PHY_ID, 1211e2ca90c2SFreddy Xin GMII_LED_ACT, 2, &tmp); 1212e2ca90c2SFreddy Xin 1213e2ca90c2SFreddy Xin tmp = ledlink; 1214e2ca90c2SFreddy Xin ax88179_write_cmd(dev, AX_ACCESS_PHY, AX88179_PHY_ID, 1215e2ca90c2SFreddy Xin GMII_LED_LINK, 2, &tmp); 1216e2ca90c2SFreddy Xin 1217e2ca90c2SFreddy Xin tmp = GMII_PHY_PGSEL_PAGE0; 1218e2ca90c2SFreddy Xin ax88179_write_cmd(dev, AX_ACCESS_PHY, AX88179_PHY_ID, 1219e2ca90c2SFreddy Xin GMII_PHY_PAGE_SELECT, 2, &tmp); 1220e2ca90c2SFreddy Xin 1221e2ca90c2SFreddy Xin /* LED full duplex setting */ 1222e2ca90c2SFreddy Xin ledfd = 0; 1223e2ca90c2SFreddy Xin if (ledvalue & LED0_FD) 1224e2ca90c2SFreddy Xin ledfd |= 0x01; 1225e2ca90c2SFreddy Xin else if ((ledvalue & LED0_USB3_MASK) == 0) 1226e2ca90c2SFreddy Xin ledfd |= 0x02; 1227e2ca90c2SFreddy Xin 1228e2ca90c2SFreddy Xin if (ledvalue & LED1_FD) 1229e2ca90c2SFreddy Xin ledfd |= 0x04; 1230e2ca90c2SFreddy Xin else if ((ledvalue & LED1_USB3_MASK) == 0) 1231e2ca90c2SFreddy Xin ledfd |= 0x08; 1232e2ca90c2SFreddy Xin 1233e2ca90c2SFreddy Xin if (ledvalue & LED2_FD) 1234e2ca90c2SFreddy Xin ledfd |= 0x10; 1235e2ca90c2SFreddy Xin else if ((ledvalue & LED2_USB3_MASK) == 0) 1236e2ca90c2SFreddy Xin ledfd |= 0x20; 1237e2ca90c2SFreddy Xin 1238e2ca90c2SFreddy Xin ax88179_write_cmd(dev, AX_ACCESS_MAC, AX_LEDCTRL, 1, 1, &ledfd); 1239e2ca90c2SFreddy Xin 1240e2ca90c2SFreddy Xin return 0; 1241e2ca90c2SFreddy Xin } 1242e2ca90c2SFreddy Xin 12439fb137aeSPeter Fink static void ax88179_get_mac_addr(struct usbnet *dev) 12449fb137aeSPeter Fink { 12459fb137aeSPeter Fink u8 mac[ETH_ALEN]; 12469fb137aeSPeter Fink 1247bd78980bSPhillip Potter memset(mac, 0, sizeof(mac)); 1248bd78980bSPhillip Potter 12499fb137aeSPeter Fink /* Maybe the boot loader passed the MAC address via device tree */ 12509fb137aeSPeter Fink if (!eth_platform_get_mac_address(&dev->udev->dev, mac)) { 12519fb137aeSPeter Fink netif_dbg(dev, ifup, dev->net, 12529fb137aeSPeter Fink "MAC address read from device tree"); 12539fb137aeSPeter Fink } else { 12549fb137aeSPeter Fink ax88179_read_cmd(dev, AX_ACCESS_MAC, AX_NODE_ID, ETH_ALEN, 12559fb137aeSPeter Fink ETH_ALEN, mac); 12569fb137aeSPeter Fink netif_dbg(dev, ifup, dev->net, 12579fb137aeSPeter Fink "MAC address read from ASIX chip"); 12589fb137aeSPeter Fink } 12599fb137aeSPeter Fink 12609fb137aeSPeter Fink if (is_valid_ether_addr(mac)) { 126116813717SJakub Kicinski eth_hw_addr_set(dev->net, mac); 12629fb137aeSPeter Fink } else { 12639fb137aeSPeter Fink netdev_info(dev->net, "invalid MAC address, using random\n"); 12649fb137aeSPeter Fink eth_hw_addr_random(dev->net); 12659fb137aeSPeter Fink } 12661635520aSPeter Fink 12671635520aSPeter Fink ax88179_write_cmd(dev, AX_ACCESS_MAC, AX_NODE_ID, ETH_ALEN, ETH_ALEN, 12681635520aSPeter Fink dev->net->dev_addr); 12699fb137aeSPeter Fink } 12709fb137aeSPeter Fink 1271c0725502SDavid S. Miller static int ax88179_bind(struct usbnet *dev, struct usb_interface *intf) 1272e2ca90c2SFreddy Xin { 1273e2ca90c2SFreddy Xin struct ax88179_data *ax179_data = (struct ax88179_data *)dev->data; 1274e2ca90c2SFreddy Xin 1275c0725502SDavid S. Miller usbnet_get_endpoints(dev, intf); 1276c0725502SDavid S. Miller 1277e2ca90c2SFreddy Xin memset(ax179_data, 0, sizeof(*ax179_data)); 1278e2ca90c2SFreddy Xin 1279e2ca90c2SFreddy Xin dev->net->netdev_ops = &ax88179_netdev_ops; 1280e2ca90c2SFreddy Xin dev->net->ethtool_ops = &ax88179_ethtool_ops; 1281e2ca90c2SFreddy Xin dev->net->needed_headroom = 8; 1282f77f0aeeSJarod Wilson dev->net->max_mtu = 4088; 1283e2ca90c2SFreddy Xin 1284e2ca90c2SFreddy Xin /* Initialize MII structure */ 1285e2ca90c2SFreddy Xin dev->mii.dev = dev->net; 1286e2ca90c2SFreddy Xin dev->mii.mdio_read = ax88179_mdio_read; 1287e2ca90c2SFreddy Xin dev->mii.mdio_write = ax88179_mdio_write; 1288e2ca90c2SFreddy Xin dev->mii.phy_id_mask = 0xff; 1289e2ca90c2SFreddy Xin dev->mii.reg_num_mask = 0xff; 1290e2ca90c2SFreddy Xin dev->mii.phy_id = 0x03; 1291e2ca90c2SFreddy Xin dev->mii.supports_gmii = 1; 1292e2ca90c2SFreddy Xin 129316b1c4e0SJacky Chou dev->net->features |= NETIF_F_SG | NETIF_F_IP_CSUM | 129416b1c4e0SJacky Chou NETIF_F_IPV6_CSUM | NETIF_F_RXCSUM | NETIF_F_TSO; 1295e2ca90c2SFreddy Xin 129616b1c4e0SJacky Chou dev->net->hw_features |= dev->net->features; 129716b1c4e0SJacky Chou 1298ee8b7a11SJakub Kicinski netif_set_tso_max_size(dev->net, 16384); 1299e2ca90c2SFreddy Xin 13009718f9ceSJustin Chen ax88179_reset(dev); 1301e2ca90c2SFreddy Xin 1302e2ca90c2SFreddy Xin return 0; 1303e2ca90c2SFreddy Xin } 1304e2ca90c2SFreddy Xin 1305e2ca90c2SFreddy Xin static void ax88179_unbind(struct usbnet *dev, struct usb_interface *intf) 1306e2ca90c2SFreddy Xin { 1307e2ca90c2SFreddy Xin u16 tmp16; 1308e2ca90c2SFreddy Xin 1309e2ca90c2SFreddy Xin /* Configure RX control register => stop operation */ 1310e2ca90c2SFreddy Xin tmp16 = AX_RX_CTL_STOP; 1311e2ca90c2SFreddy Xin ax88179_write_cmd(dev, AX_ACCESS_MAC, AX_RX_CTL, 2, 2, &tmp16); 1312e2ca90c2SFreddy Xin 1313e2ca90c2SFreddy Xin tmp16 = 0; 1314e2ca90c2SFreddy Xin ax88179_write_cmd(dev, AX_ACCESS_MAC, AX_CLK_SELECT, 1, 1, &tmp16); 1315e2ca90c2SFreddy Xin 1316e2ca90c2SFreddy Xin /* Power down ethernet PHY */ 1317e2ca90c2SFreddy Xin tmp16 = 0; 1318e2ca90c2SFreddy Xin ax88179_write_cmd(dev, AX_ACCESS_MAC, AX_PHYPWR_RSTCTL, 2, 2, &tmp16); 1319e2ca90c2SFreddy Xin } 1320e2ca90c2SFreddy Xin 1321e2ca90c2SFreddy Xin static void 1322e2ca90c2SFreddy Xin ax88179_rx_checksum(struct sk_buff *skb, u32 *pkt_hdr) 1323e2ca90c2SFreddy Xin { 1324e2ca90c2SFreddy Xin skb->ip_summed = CHECKSUM_NONE; 1325e2ca90c2SFreddy Xin 1326e2ca90c2SFreddy Xin /* checksum error bit is set */ 1327e2ca90c2SFreddy Xin if ((*pkt_hdr & AX_RXHDR_L3CSUM_ERR) || 1328e2ca90c2SFreddy Xin (*pkt_hdr & AX_RXHDR_L4CSUM_ERR)) 1329e2ca90c2SFreddy Xin return; 1330e2ca90c2SFreddy Xin 1331e2ca90c2SFreddy Xin /* It must be a TCP or UDP packet with a valid checksum */ 1332e2ca90c2SFreddy Xin if (((*pkt_hdr & AX_RXHDR_L4_TYPE_MASK) == AX_RXHDR_L4_TYPE_TCP) || 1333e2ca90c2SFreddy Xin ((*pkt_hdr & AX_RXHDR_L4_TYPE_MASK) == AX_RXHDR_L4_TYPE_UDP)) 1334e2ca90c2SFreddy Xin skb->ip_summed = CHECKSUM_UNNECESSARY; 1335e2ca90c2SFreddy Xin } 1336e2ca90c2SFreddy Xin 1337e2ca90c2SFreddy Xin static int ax88179_rx_fixup(struct usbnet *dev, struct sk_buff *skb) 1338e2ca90c2SFreddy Xin { 1339e2ca90c2SFreddy Xin struct sk_buff *ax_skb; 1340e2ca90c2SFreddy Xin int pkt_cnt; 1341e2ca90c2SFreddy Xin u32 rx_hdr; 1342e2ca90c2SFreddy Xin u16 hdr_off; 1343e2ca90c2SFreddy Xin u32 *pkt_hdr; 1344e2ca90c2SFreddy Xin 134557bc3d3aSJann Horn /* At the end of the SKB, there's a header telling us how many packets 134657bc3d3aSJann Horn * are bundled into this buffer and where we can find an array of 134757bc3d3aSJann Horn * per-packet metadata (which contains elements encoded into u16). 134857bc3d3aSJann Horn */ 1349f8ebb3acSJose Alonso 1350f8ebb3acSJose Alonso /* SKB contents for current firmware: 1351f8ebb3acSJose Alonso * <packet 1> <padding> 1352f8ebb3acSJose Alonso * ... 1353f8ebb3acSJose Alonso * <packet N> <padding> 1354f8ebb3acSJose Alonso * <per-packet metadata entry 1> <dummy header> 1355f8ebb3acSJose Alonso * ... 1356f8ebb3acSJose Alonso * <per-packet metadata entry N> <dummy header> 1357f8ebb3acSJose Alonso * <padding2> <rx_hdr> 1358f8ebb3acSJose Alonso * 1359f8ebb3acSJose Alonso * where: 1360f8ebb3acSJose Alonso * <packet N> contains pkt_len bytes: 1361f8ebb3acSJose Alonso * 2 bytes of IP alignment pseudo header 1362f8ebb3acSJose Alonso * packet received 1363f8ebb3acSJose Alonso * <per-packet metadata entry N> contains 4 bytes: 1364f8ebb3acSJose Alonso * pkt_len and fields AX_RXHDR_* 1365f8ebb3acSJose Alonso * <padding> 0-7 bytes to terminate at 1366f8ebb3acSJose Alonso * 8 bytes boundary (64-bit). 1367f8ebb3acSJose Alonso * <padding2> 4 bytes to make rx_hdr terminate at 1368f8ebb3acSJose Alonso * 8 bytes boundary (64-bit) 1369f8ebb3acSJose Alonso * <dummy-header> contains 4 bytes: 1370f8ebb3acSJose Alonso * pkt_len=0 and AX_RXHDR_DROP_ERR 1371f8ebb3acSJose Alonso * <rx-hdr> contains 4 bytes: 1372f8ebb3acSJose Alonso * pkt_cnt and hdr_off (offset of 1373f8ebb3acSJose Alonso * <per-packet metadata entry 1>) 1374f8ebb3acSJose Alonso * 1375f8ebb3acSJose Alonso * pkt_cnt is number of entrys in the per-packet metadata. 1376f8ebb3acSJose Alonso * In current firmware there is 2 entrys per packet. 1377f8ebb3acSJose Alonso * The first points to the packet and the 1378f8ebb3acSJose Alonso * second is a dummy header. 1379f8ebb3acSJose Alonso * This was done probably to align fields in 64-bit and 1380f8ebb3acSJose Alonso * maintain compatibility with old firmware. 1381f8ebb3acSJose Alonso * This code assumes that <dummy header> and <padding2> are 1382f8ebb3acSJose Alonso * optional. 1383f8ebb3acSJose Alonso */ 1384f8ebb3acSJose Alonso 138557bc3d3aSJann Horn if (skb->len < 4) 1386eb85569fSEmil Goode return 0; 1387e2ca90c2SFreddy Xin skb_trim(skb, skb->len - 4); 1388d1854d50SChuhong Yuan rx_hdr = get_unaligned_le32(skb_tail_pointer(skb)); 1389e2ca90c2SFreddy Xin pkt_cnt = (u16)rx_hdr; 1390e2ca90c2SFreddy Xin hdr_off = (u16)(rx_hdr >> 16); 139157bc3d3aSJann Horn 139257bc3d3aSJann Horn if (pkt_cnt == 0) 139357bc3d3aSJann Horn return 0; 139457bc3d3aSJann Horn 139557bc3d3aSJann Horn /* Make sure that the bounds of the metadata array are inside the SKB 139657bc3d3aSJann Horn * (and in front of the counter at the end). 139757bc3d3aSJann Horn */ 1398f8ebb3acSJose Alonso if (pkt_cnt * 4 + hdr_off > skb->len) 139957bc3d3aSJann Horn return 0; 1400e2ca90c2SFreddy Xin pkt_hdr = (u32 *)(skb->data + hdr_off); 1401e2ca90c2SFreddy Xin 140257bc3d3aSJann Horn /* Packets must not overlap the metadata array */ 140357bc3d3aSJann Horn skb_trim(skb, hdr_off); 140457bc3d3aSJann Horn 1405f8ebb3acSJose Alonso for (; pkt_cnt > 0; pkt_cnt--, pkt_hdr++) { 1406f8ebb3acSJose Alonso u16 pkt_len_plus_padd; 1407e2ca90c2SFreddy Xin u16 pkt_len; 1408e2ca90c2SFreddy Xin 1409e2ca90c2SFreddy Xin le32_to_cpus(pkt_hdr); 1410e2ca90c2SFreddy Xin pkt_len = (*pkt_hdr >> 16) & 0x1fff; 1411f8ebb3acSJose Alonso pkt_len_plus_padd = (pkt_len + 7) & 0xfff8; 1412e2ca90c2SFreddy Xin 1413f8ebb3acSJose Alonso /* Skip dummy header used for alignment 1414f8ebb3acSJose Alonso */ 1415f8ebb3acSJose Alonso if (pkt_len == 0) 1416f8ebb3acSJose Alonso continue; 1417f8ebb3acSJose Alonso 1418f8ebb3acSJose Alonso if (pkt_len_plus_padd > skb->len) 141957bc3d3aSJann Horn return 0; 142057bc3d3aSJann Horn 1421e2ca90c2SFreddy Xin /* Check CRC or runt packet */ 1422f8ebb3acSJose Alonso if ((*pkt_hdr & (AX_RXHDR_CRC_ERR | AX_RXHDR_DROP_ERR)) || 1423f8ebb3acSJose Alonso pkt_len < 2 + ETH_HLEN) { 1424f8ebb3acSJose Alonso dev->net->stats.rx_errors++; 1425f8ebb3acSJose Alonso skb_pull(skb, pkt_len_plus_padd); 1426f8ebb3acSJose Alonso continue; 1427f8ebb3acSJose Alonso } 1428e2ca90c2SFreddy Xin 1429f8ebb3acSJose Alonso /* last packet */ 1430f8ebb3acSJose Alonso if (pkt_len_plus_padd == skb->len) { 1431f8ebb3acSJose Alonso skb_trim(skb, pkt_len); 1432f8ebb3acSJose Alonso 1433f8ebb3acSJose Alonso /* Skip IP alignment pseudo header */ 1434f8ebb3acSJose Alonso skb_pull(skb, 2); 1435f8ebb3acSJose Alonso 1436f8ebb3acSJose Alonso skb->truesize = SKB_TRUESIZE(pkt_len_plus_padd); 1437f8ebb3acSJose Alonso ax88179_rx_checksum(skb, pkt_hdr); 1438f8ebb3acSJose Alonso return 1; 1439f8ebb3acSJose Alonso } 1440f8ebb3acSJose Alonso 1441e2ca90c2SFreddy Xin ax_skb = skb_clone(skb, GFP_ATOMIC); 144257bc3d3aSJann Horn if (!ax_skb) 144357bc3d3aSJann Horn return 0; 1444f8ebb3acSJose Alonso skb_trim(ax_skb, pkt_len); 1445f8ebb3acSJose Alonso 1446e869e7a1SJeremy Kerr /* Skip IP alignment pseudo header */ 1447e869e7a1SJeremy Kerr skb_pull(ax_skb, 2); 1448f8ebb3acSJose Alonso 1449f8ebb3acSJose Alonso skb->truesize = pkt_len_plus_padd + 1450f8ebb3acSJose Alonso SKB_DATA_ALIGN(sizeof(struct sk_buff)); 1451e2ca90c2SFreddy Xin ax88179_rx_checksum(ax_skb, pkt_hdr); 1452e2ca90c2SFreddy Xin usbnet_skb_return(dev, ax_skb); 1453f8ebb3acSJose Alonso 1454f8ebb3acSJose Alonso skb_pull(skb, pkt_len_plus_padd); 1455e2ca90c2SFreddy Xin } 1456e2ca90c2SFreddy Xin 145757bc3d3aSJann Horn return 0; 1458e2ca90c2SFreddy Xin } 1459e2ca90c2SFreddy Xin 1460e2ca90c2SFreddy Xin static struct sk_buff * 1461e2ca90c2SFreddy Xin ax88179_tx_fixup(struct usbnet *dev, struct sk_buff *skb, gfp_t flags) 1462e2ca90c2SFreddy Xin { 1463e2ca90c2SFreddy Xin u32 tx_hdr1, tx_hdr2; 1464e2ca90c2SFreddy Xin int frame_size = dev->maxpacket; 1465e2ca90c2SFreddy Xin int headroom; 14667e24b4edSChuhong Yuan void *ptr; 1467e2ca90c2SFreddy Xin 1468e2ca90c2SFreddy Xin tx_hdr1 = skb->len; 146916b1c4e0SJacky Chou tx_hdr2 = skb_shinfo(skb)->gso_size; /* Set TSO mss */ 1470e2ca90c2SFreddy Xin if (((skb->len + 8) % frame_size) == 0) 1471e2ca90c2SFreddy Xin tx_hdr2 |= 0x80008000; /* Enable padding */ 1472e2ca90c2SFreddy Xin 1473f2707015SEric Dumazet headroom = skb_headroom(skb) - 8; 1474e2ca90c2SFreddy Xin 147516b1c4e0SJacky Chou if ((dev->net->features & NETIF_F_SG) && skb_linearize(skb)) 147616b1c4e0SJacky Chou return NULL; 147716b1c4e0SJacky Chou 1478f2707015SEric Dumazet if ((skb_header_cloned(skb) || headroom < 0) && 1479f2707015SEric Dumazet pskb_expand_head(skb, headroom < 0 ? 8 : 0, 0, GFP_ATOMIC)) { 1480e2ca90c2SFreddy Xin dev_kfree_skb_any(skb); 1481e2ca90c2SFreddy Xin return NULL; 1482e2ca90c2SFreddy Xin } 1483e2ca90c2SFreddy Xin 14847e24b4edSChuhong Yuan ptr = skb_push(skb, 8); 14857e24b4edSChuhong Yuan put_unaligned_le32(tx_hdr1, ptr); 14867e24b4edSChuhong Yuan put_unaligned_le32(tx_hdr2, ptr + 4); 1487e2ca90c2SFreddy Xin 148816b1c4e0SJacky Chou usbnet_set_skb_tx_stats(skb, (skb_shinfo(skb)->gso_segs ?: 1), 0); 148916b1c4e0SJacky Chou 1490e2ca90c2SFreddy Xin return skb; 1491e2ca90c2SFreddy Xin } 1492e2ca90c2SFreddy Xin 1493e2ca90c2SFreddy Xin static int ax88179_link_reset(struct usbnet *dev) 1494e2ca90c2SFreddy Xin { 1495c0725502SDavid S. Miller struct ax88179_data *ax179_data = (struct ax88179_data *)dev->data; 1496c0725502SDavid S. Miller u8 tmp[5], link_sts; 1497c0725502SDavid S. Miller u16 mode, tmp16, delay = HZ / 10; 1498c0725502SDavid S. Miller u32 tmp32 = 0x40000000; 1499c0725502SDavid S. Miller unsigned long jtimeout; 1500c0725502SDavid S. Miller 1501c0725502SDavid S. Miller jtimeout = jiffies + delay; 1502c0725502SDavid S. Miller while (tmp32 & 0x40000000) { 1503c0725502SDavid S. Miller mode = 0; 1504c0725502SDavid S. Miller ax88179_write_cmd(dev, AX_ACCESS_MAC, AX_RX_CTL, 2, 2, &mode); 1505c0725502SDavid S. Miller ax88179_write_cmd(dev, AX_ACCESS_MAC, AX_RX_CTL, 2, 2, 1506c0725502SDavid S. Miller &ax179_data->rxctl); 1507c0725502SDavid S. Miller 1508c0725502SDavid S. Miller /*link up, check the usb device control TX FIFO full or empty*/ 1509c0725502SDavid S. Miller ax88179_read_cmd(dev, 0x81, 0x8c, 0, 4, &tmp32); 1510c0725502SDavid S. Miller 1511c0725502SDavid S. Miller if (time_after(jiffies, jtimeout)) 1512c0725502SDavid S. Miller return 0; 1513c0725502SDavid S. Miller } 1514c0725502SDavid S. Miller 1515c0725502SDavid S. Miller mode = AX_MEDIUM_RECEIVE_EN | AX_MEDIUM_TXFLOW_CTRLEN | 1516c0725502SDavid S. Miller AX_MEDIUM_RXFLOW_CTRLEN; 1517c0725502SDavid S. Miller 1518c0725502SDavid S. Miller ax88179_read_cmd(dev, AX_ACCESS_MAC, PHYSICAL_LINK_STATUS, 1519c0725502SDavid S. Miller 1, 1, &link_sts); 1520c0725502SDavid S. Miller 1521c0725502SDavid S. Miller ax88179_read_cmd(dev, AX_ACCESS_PHY, AX88179_PHY_ID, 1522c0725502SDavid S. Miller GMII_PHY_PHYSR, 2, &tmp16); 1523c0725502SDavid S. Miller 1524c0725502SDavid S. Miller if (!(tmp16 & GMII_PHY_PHYSR_LINK)) { 1525c0725502SDavid S. Miller return 0; 1526c0725502SDavid S. Miller } else if (GMII_PHY_PHYSR_GIGA == (tmp16 & GMII_PHY_PHYSR_SMASK)) { 1527c0725502SDavid S. Miller mode |= AX_MEDIUM_GIGAMODE | AX_MEDIUM_EN_125MHZ; 1528c0725502SDavid S. Miller if (dev->net->mtu > 1500) 1529c0725502SDavid S. Miller mode |= AX_MEDIUM_JUMBO_EN; 1530c0725502SDavid S. Miller 1531c0725502SDavid S. Miller if (link_sts & AX_USB_SS) 1532c0725502SDavid S. Miller memcpy(tmp, &AX88179_BULKIN_SIZE[0], 5); 1533c0725502SDavid S. Miller else if (link_sts & AX_USB_HS) 1534c0725502SDavid S. Miller memcpy(tmp, &AX88179_BULKIN_SIZE[1], 5); 1535c0725502SDavid S. Miller else 1536c0725502SDavid S. Miller memcpy(tmp, &AX88179_BULKIN_SIZE[3], 5); 1537c0725502SDavid S. Miller } else if (GMII_PHY_PHYSR_100 == (tmp16 & GMII_PHY_PHYSR_SMASK)) { 1538c0725502SDavid S. Miller mode |= AX_MEDIUM_PS; 1539c0725502SDavid S. Miller 1540c0725502SDavid S. Miller if (link_sts & (AX_USB_SS | AX_USB_HS)) 1541c0725502SDavid S. Miller memcpy(tmp, &AX88179_BULKIN_SIZE[2], 5); 1542c0725502SDavid S. Miller else 1543c0725502SDavid S. Miller memcpy(tmp, &AX88179_BULKIN_SIZE[3], 5); 1544c0725502SDavid S. Miller } else { 1545c0725502SDavid S. Miller memcpy(tmp, &AX88179_BULKIN_SIZE[3], 5); 1546c0725502SDavid S. Miller } 1547c0725502SDavid S. Miller 1548c0725502SDavid S. Miller /* RX bulk configuration */ 1549c0725502SDavid S. Miller ax88179_write_cmd(dev, AX_ACCESS_MAC, AX_RX_BULKIN_QCTRL, 5, 5, tmp); 1550c0725502SDavid S. Miller 1551c0725502SDavid S. Miller dev->rx_urb_size = (1024 * (tmp[3] + 2)); 1552c0725502SDavid S. Miller 1553c0725502SDavid S. Miller if (tmp16 & GMII_PHY_PHYSR_FULL) 1554c0725502SDavid S. Miller mode |= AX_MEDIUM_FULL_DUPLEX; 1555c0725502SDavid S. Miller ax88179_write_cmd(dev, AX_ACCESS_MAC, AX_MEDIUM_STATUS_MODE, 1556c0725502SDavid S. Miller 2, 2, &mode); 1557c0725502SDavid S. Miller 1558c0725502SDavid S. Miller ax179_data->eee_enabled = ax88179_chk_eee(dev); 1559c0725502SDavid S. Miller 1560c0725502SDavid S. Miller netif_carrier_on(dev->net); 1561c0725502SDavid S. Miller 1562c0725502SDavid S. Miller return 0; 1563e2ca90c2SFreddy Xin } 1564e2ca90c2SFreddy Xin 1565e2ca90c2SFreddy Xin static int ax88179_reset(struct usbnet *dev) 1566e2ca90c2SFreddy Xin { 1567e2ca90c2SFreddy Xin u8 buf[5]; 1568e2ca90c2SFreddy Xin u16 *tmp16; 1569e2ca90c2SFreddy Xin u8 *tmp; 1570e98d69baSFreddy Xin struct ax88179_data *ax179_data = (struct ax88179_data *)dev->data; 1571e98d69baSFreddy Xin struct ethtool_eee eee_data; 1572e2ca90c2SFreddy Xin 1573e2ca90c2SFreddy Xin tmp16 = (u16 *)buf; 1574e2ca90c2SFreddy Xin tmp = (u8 *)buf; 1575e2ca90c2SFreddy Xin 1576e2ca90c2SFreddy Xin /* Power up ethernet PHY */ 1577e2ca90c2SFreddy Xin *tmp16 = 0; 1578e2ca90c2SFreddy Xin ax88179_write_cmd(dev, AX_ACCESS_MAC, AX_PHYPWR_RSTCTL, 2, 2, tmp16); 1579e2ca90c2SFreddy Xin 1580e2ca90c2SFreddy Xin *tmp16 = AX_PHYPWR_RSTCTL_IPRL; 1581e2ca90c2SFreddy Xin ax88179_write_cmd(dev, AX_ACCESS_MAC, AX_PHYPWR_RSTCTL, 2, 2, tmp16); 1582e2ca90c2SFreddy Xin msleep(200); 1583e2ca90c2SFreddy Xin 1584e2ca90c2SFreddy Xin *tmp = AX_CLK_SELECT_ACS | AX_CLK_SELECT_BCS; 1585e2ca90c2SFreddy Xin ax88179_write_cmd(dev, AX_ACCESS_MAC, AX_CLK_SELECT, 1, 1, tmp); 1586e2ca90c2SFreddy Xin msleep(100); 1587e2ca90c2SFreddy Xin 1588e2ca90c2SFreddy Xin /* Ethernet PHY Auto Detach*/ 1589843f9205SJustin Chen ax88179_auto_detach(dev); 1590e2ca90c2SFreddy Xin 15919fb137aeSPeter Fink /* Read MAC address from DTB or asix chip */ 15929fb137aeSPeter Fink ax88179_get_mac_addr(dev); 15939718f9ceSJustin Chen memcpy(dev->net->perm_addr, dev->net->dev_addr, ETH_ALEN); 1594e2ca90c2SFreddy Xin 1595e2ca90c2SFreddy Xin /* RX bulk configuration */ 1596e2ca90c2SFreddy Xin memcpy(tmp, &AX88179_BULKIN_SIZE[0], 5); 1597e2ca90c2SFreddy Xin ax88179_write_cmd(dev, AX_ACCESS_MAC, AX_RX_BULKIN_QCTRL, 5, 5, tmp); 1598e2ca90c2SFreddy Xin 1599e2ca90c2SFreddy Xin dev->rx_urb_size = 1024 * 20; 1600e2ca90c2SFreddy Xin 1601e2ca90c2SFreddy Xin *tmp = 0x34; 1602e2ca90c2SFreddy Xin ax88179_write_cmd(dev, AX_ACCESS_MAC, AX_PAUSE_WATERLVL_LOW, 1, 1, tmp); 1603e2ca90c2SFreddy Xin 1604e2ca90c2SFreddy Xin *tmp = 0x52; 1605e2ca90c2SFreddy Xin ax88179_write_cmd(dev, AX_ACCESS_MAC, AX_PAUSE_WATERLVL_HIGH, 1606e2ca90c2SFreddy Xin 1, 1, tmp); 1607e2ca90c2SFreddy Xin 1608e2ca90c2SFreddy Xin /* Enable checksum offload */ 1609e2ca90c2SFreddy Xin *tmp = AX_RXCOE_IP | AX_RXCOE_TCP | AX_RXCOE_UDP | 1610e2ca90c2SFreddy Xin AX_RXCOE_TCPV6 | AX_RXCOE_UDPV6; 1611e2ca90c2SFreddy Xin ax88179_write_cmd(dev, AX_ACCESS_MAC, AX_RXCOE_CTL, 1, 1, tmp); 1612e2ca90c2SFreddy Xin 1613e2ca90c2SFreddy Xin *tmp = AX_TXCOE_IP | AX_TXCOE_TCP | AX_TXCOE_UDP | 1614e2ca90c2SFreddy Xin AX_TXCOE_TCPV6 | AX_TXCOE_UDPV6; 1615e2ca90c2SFreddy Xin ax88179_write_cmd(dev, AX_ACCESS_MAC, AX_TXCOE_CTL, 1, 1, tmp); 1616e2ca90c2SFreddy Xin 1617e2ca90c2SFreddy Xin /* Configure RX control register => start operation */ 1618e2ca90c2SFreddy Xin *tmp16 = AX_RX_CTL_DROPCRCERR | AX_RX_CTL_IPE | AX_RX_CTL_START | 1619e2ca90c2SFreddy Xin AX_RX_CTL_AP | AX_RX_CTL_AMALL | AX_RX_CTL_AB; 1620e2ca90c2SFreddy Xin ax88179_write_cmd(dev, AX_ACCESS_MAC, AX_RX_CTL, 2, 2, tmp16); 1621e2ca90c2SFreddy Xin 1622e2ca90c2SFreddy Xin *tmp = AX_MONITOR_MODE_PMETYPE | AX_MONITOR_MODE_PMEPOL | 1623e2ca90c2SFreddy Xin AX_MONITOR_MODE_RWMP; 1624e2ca90c2SFreddy Xin ax88179_write_cmd(dev, AX_ACCESS_MAC, AX_MONITOR_MOD, 1, 1, tmp); 1625e2ca90c2SFreddy Xin 1626e2ca90c2SFreddy Xin /* Configure default medium type => giga */ 1627e2ca90c2SFreddy Xin *tmp16 = AX_MEDIUM_RECEIVE_EN | AX_MEDIUM_TXFLOW_CTRLEN | 16284c8e84b2SFreddy Xin AX_MEDIUM_RXFLOW_CTRLEN | AX_MEDIUM_FULL_DUPLEX | 16294c8e84b2SFreddy Xin AX_MEDIUM_GIGAMODE; 1630e2ca90c2SFreddy Xin ax88179_write_cmd(dev, AX_ACCESS_MAC, AX_MEDIUM_STATUS_MODE, 1631e2ca90c2SFreddy Xin 2, 2, tmp16); 1632e2ca90c2SFreddy Xin 1633e2ca90c2SFreddy Xin ax88179_led_setting(dev); 1634e2ca90c2SFreddy Xin 1635e98d69baSFreddy Xin ax179_data->eee_enabled = 0; 1636e98d69baSFreddy Xin ax179_data->eee_active = 0; 1637e98d69baSFreddy Xin 1638e98d69baSFreddy Xin ax88179_disable_eee(dev); 1639e98d69baSFreddy Xin 1640e98d69baSFreddy Xin ax88179_ethtool_get_eee(dev, &eee_data); 1641e98d69baSFreddy Xin eee_data.advertised = 0; 1642e98d69baSFreddy Xin ax88179_ethtool_set_eee(dev, &eee_data); 1643e98d69baSFreddy Xin 1644e2ca90c2SFreddy Xin /* Restart autoneg */ 1645e2ca90c2SFreddy Xin mii_nway_restart(&dev->mii); 1646e2ca90c2SFreddy Xin 16477a97856eSMing Lei usbnet_link_change(dev, 0, 0); 1648e2ca90c2SFreddy Xin 1649e2ca90c2SFreddy Xin return 0; 1650e2ca90c2SFreddy Xin } 1651e2ca90c2SFreddy Xin 1652e2ca90c2SFreddy Xin static int ax88179_stop(struct usbnet *dev) 1653e2ca90c2SFreddy Xin { 1654e2ca90c2SFreddy Xin u16 tmp16; 1655e2ca90c2SFreddy Xin 1656e2ca90c2SFreddy Xin ax88179_read_cmd(dev, AX_ACCESS_MAC, AX_MEDIUM_STATUS_MODE, 1657e2ca90c2SFreddy Xin 2, 2, &tmp16); 1658e2ca90c2SFreddy Xin tmp16 &= ~AX_MEDIUM_RECEIVE_EN; 1659e2ca90c2SFreddy Xin ax88179_write_cmd(dev, AX_ACCESS_MAC, AX_MEDIUM_STATUS_MODE, 1660e2ca90c2SFreddy Xin 2, 2, &tmp16); 1661e2ca90c2SFreddy Xin 1662e2ca90c2SFreddy Xin return 0; 1663e2ca90c2SFreddy Xin } 1664e2ca90c2SFreddy Xin 1665e2ca90c2SFreddy Xin static const struct driver_info ax88179_info = { 1666803dee95SDavid Chang .description = "ASIX AX88179 USB 3.0 Gigabit Ethernet", 1667e2ca90c2SFreddy Xin .bind = ax88179_bind, 1668e2ca90c2SFreddy Xin .unbind = ax88179_unbind, 1669e2ca90c2SFreddy Xin .status = ax88179_status, 1670e2ca90c2SFreddy Xin .link_reset = ax88179_link_reset, 1671e2ca90c2SFreddy Xin .reset = ax88179_reset, 1672e2ca90c2SFreddy Xin .stop = ax88179_stop, 167336a15e1cSJose Alonso .flags = FLAG_ETHER | FLAG_FRAMING_AX | FLAG_SEND_ZLP, 1674e2ca90c2SFreddy Xin .rx_fixup = ax88179_rx_fixup, 1675e2ca90c2SFreddy Xin .tx_fixup = ax88179_tx_fixup, 1676e2ca90c2SFreddy Xin }; 1677e2ca90c2SFreddy Xin 1678e2ca90c2SFreddy Xin static const struct driver_info ax88178a_info = { 1679803dee95SDavid Chang .description = "ASIX AX88178A USB 2.0 Gigabit Ethernet", 1680e2ca90c2SFreddy Xin .bind = ax88179_bind, 1681e2ca90c2SFreddy Xin .unbind = ax88179_unbind, 1682e2ca90c2SFreddy Xin .status = ax88179_status, 1683e2ca90c2SFreddy Xin .link_reset = ax88179_link_reset, 1684e2ca90c2SFreddy Xin .reset = ax88179_reset, 1685e2ca90c2SFreddy Xin .stop = ax88179_stop, 168636a15e1cSJose Alonso .flags = FLAG_ETHER | FLAG_FRAMING_AX | FLAG_SEND_ZLP, 1687e2ca90c2SFreddy Xin .rx_fixup = ax88179_rx_fixup, 1688e2ca90c2SFreddy Xin .tx_fixup = ax88179_tx_fixup, 1689e2ca90c2SFreddy Xin }; 1690e2ca90c2SFreddy Xin 16918da3cf2aSAllan Chou static const struct driver_info cypress_GX3_info = { 16928da3cf2aSAllan Chou .description = "Cypress GX3 SuperSpeed to Gigabit Ethernet Controller", 16938da3cf2aSAllan Chou .bind = ax88179_bind, 16948da3cf2aSAllan Chou .unbind = ax88179_unbind, 16958da3cf2aSAllan Chou .status = ax88179_status, 16968da3cf2aSAllan Chou .link_reset = ax88179_link_reset, 16978da3cf2aSAllan Chou .reset = ax88179_reset, 16988da3cf2aSAllan Chou .stop = ax88179_stop, 169936a15e1cSJose Alonso .flags = FLAG_ETHER | FLAG_FRAMING_AX | FLAG_SEND_ZLP, 17008da3cf2aSAllan Chou .rx_fixup = ax88179_rx_fixup, 17018da3cf2aSAllan Chou .tx_fixup = ax88179_tx_fixup, 17028da3cf2aSAllan Chou }; 17038da3cf2aSAllan Chou 1704635d61a3SGerry Demaret static const struct driver_info dlink_dub1312_info = { 1705635d61a3SGerry Demaret .description = "D-Link DUB-1312 USB 3.0 to Gigabit Ethernet Adapter", 1706635d61a3SGerry Demaret .bind = ax88179_bind, 1707635d61a3SGerry Demaret .unbind = ax88179_unbind, 1708635d61a3SGerry Demaret .status = ax88179_status, 1709635d61a3SGerry Demaret .link_reset = ax88179_link_reset, 1710635d61a3SGerry Demaret .reset = ax88179_reset, 1711635d61a3SGerry Demaret .stop = ax88179_stop, 171236a15e1cSJose Alonso .flags = FLAG_ETHER | FLAG_FRAMING_AX | FLAG_SEND_ZLP, 1713635d61a3SGerry Demaret .rx_fixup = ax88179_rx_fixup, 1714635d61a3SGerry Demaret .tx_fixup = ax88179_tx_fixup, 1715635d61a3SGerry Demaret }; 1716635d61a3SGerry Demaret 1717e2ca90c2SFreddy Xin static const struct driver_info sitecom_info = { 1718e2ca90c2SFreddy Xin .description = "Sitecom USB 3.0 to Gigabit Adapter", 1719e2ca90c2SFreddy Xin .bind = ax88179_bind, 1720e2ca90c2SFreddy Xin .unbind = ax88179_unbind, 1721e2ca90c2SFreddy Xin .status = ax88179_status, 1722e2ca90c2SFreddy Xin .link_reset = ax88179_link_reset, 1723e2ca90c2SFreddy Xin .reset = ax88179_reset, 1724e2ca90c2SFreddy Xin .stop = ax88179_stop, 172536a15e1cSJose Alonso .flags = FLAG_ETHER | FLAG_FRAMING_AX | FLAG_SEND_ZLP, 1726e2ca90c2SFreddy Xin .rx_fixup = ax88179_rx_fixup, 1727e2ca90c2SFreddy Xin .tx_fixup = ax88179_tx_fixup, 1728e2ca90c2SFreddy Xin }; 1729e2ca90c2SFreddy Xin 1730f11a5bc1SFreddy Xin static const struct driver_info samsung_info = { 1731f11a5bc1SFreddy Xin .description = "Samsung USB Ethernet Adapter", 1732f11a5bc1SFreddy Xin .bind = ax88179_bind, 1733f11a5bc1SFreddy Xin .unbind = ax88179_unbind, 1734f11a5bc1SFreddy Xin .status = ax88179_status, 1735f11a5bc1SFreddy Xin .link_reset = ax88179_link_reset, 1736f11a5bc1SFreddy Xin .reset = ax88179_reset, 1737f11a5bc1SFreddy Xin .stop = ax88179_stop, 173836a15e1cSJose Alonso .flags = FLAG_ETHER | FLAG_FRAMING_AX | FLAG_SEND_ZLP, 1739f11a5bc1SFreddy Xin .rx_fixup = ax88179_rx_fixup, 1740f11a5bc1SFreddy Xin .tx_fixup = ax88179_tx_fixup, 1741f11a5bc1SFreddy Xin }; 1742f11a5bc1SFreddy Xin 1743e5fe0cd4SFreddy Xin static const struct driver_info lenovo_info = { 1744e5fe0cd4SFreddy Xin .description = "Lenovo OneLinkDock Gigabit LAN", 1745e5fe0cd4SFreddy Xin .bind = ax88179_bind, 1746e5fe0cd4SFreddy Xin .unbind = ax88179_unbind, 1747e5fe0cd4SFreddy Xin .status = ax88179_status, 1748e5fe0cd4SFreddy Xin .link_reset = ax88179_link_reset, 1749e5fe0cd4SFreddy Xin .reset = ax88179_reset, 1750e5fe0cd4SFreddy Xin .stop = ax88179_stop, 175136a15e1cSJose Alonso .flags = FLAG_ETHER | FLAG_FRAMING_AX | FLAG_SEND_ZLP, 1752e5fe0cd4SFreddy Xin .rx_fixup = ax88179_rx_fixup, 1753e5fe0cd4SFreddy Xin .tx_fixup = ax88179_tx_fixup, 1754e5fe0cd4SFreddy Xin }; 1755e5fe0cd4SFreddy Xin 1756e20bd60bSAndrew F. Davis static const struct driver_info belkin_info = { 1757e20bd60bSAndrew F. Davis .description = "Belkin USB Ethernet Adapter", 1758e20bd60bSAndrew F. Davis .bind = ax88179_bind, 1759e20bd60bSAndrew F. Davis .unbind = ax88179_unbind, 1760e20bd60bSAndrew F. Davis .status = ax88179_status, 1761e20bd60bSAndrew F. Davis .link_reset = ax88179_link_reset, 1762e20bd60bSAndrew F. Davis .reset = ax88179_reset, 17639666ea66SWilken Gottwalt .stop = ax88179_stop, 176436a15e1cSJose Alonso .flags = FLAG_ETHER | FLAG_FRAMING_AX | FLAG_SEND_ZLP, 1765e20bd60bSAndrew F. Davis .rx_fixup = ax88179_rx_fixup, 1766e20bd60bSAndrew F. Davis .tx_fixup = ax88179_tx_fixup, 1767e20bd60bSAndrew F. Davis }; 1768e20bd60bSAndrew F. Davis 1769e42d72feSWilken Gottwalt static const struct driver_info toshiba_info = { 1770e42d72feSWilken Gottwalt .description = "Toshiba USB Ethernet Adapter", 1771e42d72feSWilken Gottwalt .bind = ax88179_bind, 1772e42d72feSWilken Gottwalt .unbind = ax88179_unbind, 1773e42d72feSWilken Gottwalt .status = ax88179_status, 1774e42d72feSWilken Gottwalt .link_reset = ax88179_link_reset, 1775e42d72feSWilken Gottwalt .reset = ax88179_reset, 1776e42d72feSWilken Gottwalt .stop = ax88179_stop, 177736a15e1cSJose Alonso .flags = FLAG_ETHER | FLAG_FRAMING_AX | FLAG_SEND_ZLP, 1778e42d72feSWilken Gottwalt .rx_fixup = ax88179_rx_fixup, 1779e42d72feSWilken Gottwalt .tx_fixup = ax88179_tx_fixup, 1780e42d72feSWilken Gottwalt }; 1781e42d72feSWilken Gottwalt 1782c92a7982SWilken Gottwalt static const struct driver_info mct_info = { 1783c92a7982SWilken Gottwalt .description = "MCT USB 3.0 Gigabit Ethernet Adapter", 1784c92a7982SWilken Gottwalt .bind = ax88179_bind, 1785c92a7982SWilken Gottwalt .unbind = ax88179_unbind, 1786c92a7982SWilken Gottwalt .status = ax88179_status, 1787c92a7982SWilken Gottwalt .link_reset = ax88179_link_reset, 1788c92a7982SWilken Gottwalt .reset = ax88179_reset, 1789c92a7982SWilken Gottwalt .stop = ax88179_stop, 179036a15e1cSJose Alonso .flags = FLAG_ETHER | FLAG_FRAMING_AX | FLAG_SEND_ZLP, 1791c92a7982SWilken Gottwalt .rx_fixup = ax88179_rx_fixup, 1792c92a7982SWilken Gottwalt .tx_fixup = ax88179_tx_fixup, 1793c92a7982SWilken Gottwalt }; 1794c92a7982SWilken Gottwalt 17959fe087ddSGreg Jesionowski static const struct driver_info at_umc2000_info = { 17969fe087ddSGreg Jesionowski .description = "AT-UMC2000 USB 3.0/USB 3.1 Gen 1 to Gigabit Ethernet Adapter", 17979fe087ddSGreg Jesionowski .bind = ax88179_bind, 17989fe087ddSGreg Jesionowski .unbind = ax88179_unbind, 17999fe087ddSGreg Jesionowski .status = ax88179_status, 18009fe087ddSGreg Jesionowski .link_reset = ax88179_link_reset, 18019fe087ddSGreg Jesionowski .reset = ax88179_reset, 18029fe087ddSGreg Jesionowski .stop = ax88179_stop, 180336a15e1cSJose Alonso .flags = FLAG_ETHER | FLAG_FRAMING_AX | FLAG_SEND_ZLP, 18049fe087ddSGreg Jesionowski .rx_fixup = ax88179_rx_fixup, 18059fe087ddSGreg Jesionowski .tx_fixup = ax88179_tx_fixup, 18069fe087ddSGreg Jesionowski }; 18079fe087ddSGreg Jesionowski 18089fe087ddSGreg Jesionowski static const struct driver_info at_umc200_info = { 18099fe087ddSGreg Jesionowski .description = "AT-UMC200 USB 3.0/USB 3.1 Gen 1 to Fast Ethernet Adapter", 18109fe087ddSGreg Jesionowski .bind = ax88179_bind, 18119fe087ddSGreg Jesionowski .unbind = ax88179_unbind, 18129fe087ddSGreg Jesionowski .status = ax88179_status, 18139fe087ddSGreg Jesionowski .link_reset = ax88179_link_reset, 18149fe087ddSGreg Jesionowski .reset = ax88179_reset, 18159fe087ddSGreg Jesionowski .stop = ax88179_stop, 181636a15e1cSJose Alonso .flags = FLAG_ETHER | FLAG_FRAMING_AX | FLAG_SEND_ZLP, 18179fe087ddSGreg Jesionowski .rx_fixup = ax88179_rx_fixup, 18189fe087ddSGreg Jesionowski .tx_fixup = ax88179_tx_fixup, 18199fe087ddSGreg Jesionowski }; 18209fe087ddSGreg Jesionowski 18219fe087ddSGreg Jesionowski static const struct driver_info at_umc2000sp_info = { 18229fe087ddSGreg Jesionowski .description = "AT-UMC2000/SP USB 3.0/USB 3.1 Gen 1 to Gigabit Ethernet Adapter", 18239fe087ddSGreg Jesionowski .bind = ax88179_bind, 18249fe087ddSGreg Jesionowski .unbind = ax88179_unbind, 18259fe087ddSGreg Jesionowski .status = ax88179_status, 18269fe087ddSGreg Jesionowski .link_reset = ax88179_link_reset, 18279fe087ddSGreg Jesionowski .reset = ax88179_reset, 18289fe087ddSGreg Jesionowski .stop = ax88179_stop, 182936a15e1cSJose Alonso .flags = FLAG_ETHER | FLAG_FRAMING_AX | FLAG_SEND_ZLP, 18309fe087ddSGreg Jesionowski .rx_fixup = ax88179_rx_fixup, 18319fe087ddSGreg Jesionowski .tx_fixup = ax88179_tx_fixup, 18329fe087ddSGreg Jesionowski }; 18339fe087ddSGreg Jesionowski 1834e2ca90c2SFreddy Xin static const struct usb_device_id products[] = { 1835e2ca90c2SFreddy Xin { 1836e2ca90c2SFreddy Xin /* ASIX AX88179 10/100/1000 */ 1837e2ca90c2SFreddy Xin USB_DEVICE(0x0b95, 0x1790), 1838e2ca90c2SFreddy Xin .driver_info = (unsigned long)&ax88179_info, 1839e2ca90c2SFreddy Xin }, { 1840e2ca90c2SFreddy Xin /* ASIX AX88178A 10/100/1000 */ 1841e2ca90c2SFreddy Xin USB_DEVICE(0x0b95, 0x178a), 1842e2ca90c2SFreddy Xin .driver_info = (unsigned long)&ax88178a_info, 1843e2ca90c2SFreddy Xin }, { 18448da3cf2aSAllan Chou /* Cypress GX3 SuperSpeed to Gigabit Ethernet Bridge Controller */ 18458da3cf2aSAllan Chou USB_DEVICE(0x04b4, 0x3610), 18468da3cf2aSAllan Chou .driver_info = (unsigned long)&cypress_GX3_info, 18478da3cf2aSAllan Chou }, { 1848635d61a3SGerry Demaret /* D-Link DUB-1312 USB 3.0 to Gigabit Ethernet Adapter */ 1849635d61a3SGerry Demaret USB_DEVICE(0x2001, 0x4a00), 1850635d61a3SGerry Demaret .driver_info = (unsigned long)&dlink_dub1312_info, 1851635d61a3SGerry Demaret }, { 1852e2ca90c2SFreddy Xin /* Sitecom USB 3.0 to Gigabit Adapter */ 1853e2ca90c2SFreddy Xin USB_DEVICE(0x0df6, 0x0072), 1854e2ca90c2SFreddy Xin .driver_info = (unsigned long)&sitecom_info, 1855f11a5bc1SFreddy Xin }, { 1856f11a5bc1SFreddy Xin /* Samsung USB Ethernet Adapter */ 1857f11a5bc1SFreddy Xin USB_DEVICE(0x04e8, 0xa100), 1858f11a5bc1SFreddy Xin .driver_info = (unsigned long)&samsung_info, 1859e5fe0cd4SFreddy Xin }, { 1860e5fe0cd4SFreddy Xin /* Lenovo OneLinkDock Gigabit LAN */ 1861e5fe0cd4SFreddy Xin USB_DEVICE(0x17ef, 0x304b), 1862e5fe0cd4SFreddy Xin .driver_info = (unsigned long)&lenovo_info, 1863e20bd60bSAndrew F. Davis }, { 1864e20bd60bSAndrew F. Davis /* Belkin B2B128 USB 3.0 Hub + Gigabit Ethernet Adapter */ 1865e20bd60bSAndrew F. Davis USB_DEVICE(0x050d, 0x0128), 1866e20bd60bSAndrew F. Davis .driver_info = (unsigned long)&belkin_info, 1867e42d72feSWilken Gottwalt }, { 1868e42d72feSWilken Gottwalt /* Toshiba USB 3.0 GBit Ethernet Adapter */ 1869e42d72feSWilken Gottwalt USB_DEVICE(0x0930, 0x0a13), 1870e42d72feSWilken Gottwalt .driver_info = (unsigned long)&toshiba_info, 1871c92a7982SWilken Gottwalt }, { 1872c92a7982SWilken Gottwalt /* Magic Control Technology U3-A9003 USB 3.0 Gigabit Ethernet Adapter */ 1873c92a7982SWilken Gottwalt USB_DEVICE(0x0711, 0x0179), 1874c92a7982SWilken Gottwalt .driver_info = (unsigned long)&mct_info, 18759fe087ddSGreg Jesionowski }, { 18769fe087ddSGreg Jesionowski /* Allied Telesis AT-UMC2000 USB 3.0/USB 3.1 Gen 1 to Gigabit Ethernet Adapter */ 18779fe087ddSGreg Jesionowski USB_DEVICE(0x07c9, 0x000e), 18789fe087ddSGreg Jesionowski .driver_info = (unsigned long)&at_umc2000_info, 18799fe087ddSGreg Jesionowski }, { 18809fe087ddSGreg Jesionowski /* Allied Telesis AT-UMC200 USB 3.0/USB 3.1 Gen 1 to Fast Ethernet Adapter */ 18819fe087ddSGreg Jesionowski USB_DEVICE(0x07c9, 0x000f), 18829fe087ddSGreg Jesionowski .driver_info = (unsigned long)&at_umc200_info, 18839fe087ddSGreg Jesionowski }, { 18849fe087ddSGreg Jesionowski /* Allied Telesis AT-UMC2000/SP USB 3.0/USB 3.1 Gen 1 to Gigabit Ethernet Adapter */ 18859fe087ddSGreg Jesionowski USB_DEVICE(0x07c9, 0x0010), 18869fe087ddSGreg Jesionowski .driver_info = (unsigned long)&at_umc2000sp_info, 1887e2ca90c2SFreddy Xin }, 1888e2ca90c2SFreddy Xin { }, 1889e2ca90c2SFreddy Xin }; 1890e2ca90c2SFreddy Xin MODULE_DEVICE_TABLE(usb, products); 1891e2ca90c2SFreddy Xin 1892e2ca90c2SFreddy Xin static struct usb_driver ax88179_178a_driver = { 1893e2ca90c2SFreddy Xin .name = "ax88179_178a", 1894e2ca90c2SFreddy Xin .id_table = products, 1895e2ca90c2SFreddy Xin .probe = usbnet_probe, 1896e2ca90c2SFreddy Xin .suspend = ax88179_suspend, 1897e2ca90c2SFreddy Xin .resume = ax88179_resume, 1898b8553b89SDavid Chang .reset_resume = ax88179_resume, 1899e2ca90c2SFreddy Xin .disconnect = usbnet_disconnect, 1900e2ca90c2SFreddy Xin .supports_autosuspend = 1, 1901e2ca90c2SFreddy Xin .disable_hub_initiated_lpm = 1, 1902e2ca90c2SFreddy Xin }; 1903e2ca90c2SFreddy Xin 1904e2ca90c2SFreddy Xin module_usb_driver(ax88179_178a_driver); 1905e2ca90c2SFreddy Xin 1906e2ca90c2SFreddy Xin MODULE_DESCRIPTION("ASIX AX88179/178A based USB 3.0/2.0 Gigabit Ethernet Devices"); 1907e2ca90c2SFreddy Xin MODULE_LICENSE("GPL"); 1908