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 167e2ca90c2SFreddy Xin struct ax88179_data { 168e98d69baSFreddy Xin u8 eee_enabled; 169e98d69baSFreddy Xin u8 eee_active; 170e2ca90c2SFreddy Xin u16 rxctl; 171e2ca90c2SFreddy Xin u16 reserved; 172e2ca90c2SFreddy Xin }; 173e2ca90c2SFreddy Xin 174e2ca90c2SFreddy Xin struct ax88179_int_data { 175e2ca90c2SFreddy Xin __le32 intdata1; 176e2ca90c2SFreddy Xin __le32 intdata2; 177e2ca90c2SFreddy Xin }; 178e2ca90c2SFreddy Xin 179e2ca90c2SFreddy Xin static const struct { 180e2ca90c2SFreddy Xin unsigned char ctrl, timer_l, timer_h, size, ifg; 181e2ca90c2SFreddy Xin } AX88179_BULKIN_SIZE[] = { 182e2ca90c2SFreddy Xin {7, 0x4f, 0, 0x12, 0xff}, 183e2ca90c2SFreddy Xin {7, 0x20, 3, 0x16, 0xff}, 184e2ca90c2SFreddy Xin {7, 0xae, 7, 0x18, 0xff}, 185e2ca90c2SFreddy Xin {7, 0xcc, 0x4c, 0x18, 8}, 186e2ca90c2SFreddy Xin }; 187e2ca90c2SFreddy Xin 188e2ca90c2SFreddy Xin static int __ax88179_read_cmd(struct usbnet *dev, u8 cmd, u16 value, u16 index, 189e2ca90c2SFreddy Xin u16 size, void *data, int in_pm) 190e2ca90c2SFreddy Xin { 191e2ca90c2SFreddy Xin int ret; 192e2ca90c2SFreddy Xin int (*fn)(struct usbnet *, u8, u8, u16, u16, void *, u16); 193e2ca90c2SFreddy Xin 194e2ca90c2SFreddy Xin BUG_ON(!dev); 195e2ca90c2SFreddy Xin 196e2ca90c2SFreddy Xin if (!in_pm) 197e2ca90c2SFreddy Xin fn = usbnet_read_cmd; 198e2ca90c2SFreddy Xin else 199e2ca90c2SFreddy Xin fn = usbnet_read_cmd_nopm; 200e2ca90c2SFreddy Xin 201e2ca90c2SFreddy Xin ret = fn(dev, cmd, USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE, 202e2ca90c2SFreddy Xin value, index, data, size); 203e2ca90c2SFreddy Xin 204e2ca90c2SFreddy Xin if (unlikely(ret < 0)) 205e2ca90c2SFreddy Xin netdev_warn(dev->net, "Failed to read reg index 0x%04x: %d\n", 206e2ca90c2SFreddy Xin index, ret); 207e2ca90c2SFreddy Xin 208e2ca90c2SFreddy Xin return ret; 209e2ca90c2SFreddy Xin } 210e2ca90c2SFreddy Xin 211e2ca90c2SFreddy Xin static int __ax88179_write_cmd(struct usbnet *dev, u8 cmd, u16 value, u16 index, 212e2ca90c2SFreddy Xin u16 size, void *data, int in_pm) 213e2ca90c2SFreddy Xin { 214e2ca90c2SFreddy Xin int ret; 215e2ca90c2SFreddy Xin int (*fn)(struct usbnet *, u8, u8, u16, u16, const void *, u16); 216e2ca90c2SFreddy Xin 217e2ca90c2SFreddy Xin BUG_ON(!dev); 218e2ca90c2SFreddy Xin 219e2ca90c2SFreddy Xin if (!in_pm) 220e2ca90c2SFreddy Xin fn = usbnet_write_cmd; 221e2ca90c2SFreddy Xin else 222e2ca90c2SFreddy Xin fn = usbnet_write_cmd_nopm; 223e2ca90c2SFreddy Xin 224e2ca90c2SFreddy Xin ret = fn(dev, cmd, USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE, 225e2ca90c2SFreddy Xin value, index, data, size); 226e2ca90c2SFreddy Xin 227e2ca90c2SFreddy Xin if (unlikely(ret < 0)) 228e2ca90c2SFreddy Xin netdev_warn(dev->net, "Failed to write reg index 0x%04x: %d\n", 229e2ca90c2SFreddy Xin index, ret); 230e2ca90c2SFreddy Xin 231e2ca90c2SFreddy Xin return ret; 232e2ca90c2SFreddy Xin } 233e2ca90c2SFreddy Xin 234e2ca90c2SFreddy Xin static void ax88179_write_cmd_async(struct usbnet *dev, u8 cmd, u16 value, 235e2ca90c2SFreddy Xin u16 index, u16 size, void *data) 236e2ca90c2SFreddy Xin { 237e2ca90c2SFreddy Xin u16 buf; 238e2ca90c2SFreddy Xin 239e2ca90c2SFreddy Xin if (2 == size) { 240e2ca90c2SFreddy Xin buf = *((u16 *)data); 241e2ca90c2SFreddy Xin cpu_to_le16s(&buf); 242e2ca90c2SFreddy Xin usbnet_write_cmd_async(dev, cmd, USB_DIR_OUT | USB_TYPE_VENDOR | 243e2ca90c2SFreddy Xin USB_RECIP_DEVICE, value, index, &buf, 244e2ca90c2SFreddy Xin size); 245e2ca90c2SFreddy Xin } else { 246e2ca90c2SFreddy Xin usbnet_write_cmd_async(dev, cmd, USB_DIR_OUT | USB_TYPE_VENDOR | 247e2ca90c2SFreddy Xin USB_RECIP_DEVICE, value, index, data, 248e2ca90c2SFreddy Xin size); 249e2ca90c2SFreddy Xin } 250e2ca90c2SFreddy Xin } 251e2ca90c2SFreddy Xin 252e2ca90c2SFreddy Xin static int ax88179_read_cmd_nopm(struct usbnet *dev, u8 cmd, u16 value, 253e2ca90c2SFreddy Xin u16 index, u16 size, void *data) 254e2ca90c2SFreddy Xin { 255e2ca90c2SFreddy Xin int ret; 256e2ca90c2SFreddy Xin 257e2ca90c2SFreddy Xin if (2 == size) { 258e2ca90c2SFreddy Xin u16 buf; 259e2ca90c2SFreddy Xin ret = __ax88179_read_cmd(dev, cmd, value, index, size, &buf, 1); 260e2ca90c2SFreddy Xin le16_to_cpus(&buf); 261e2ca90c2SFreddy Xin *((u16 *)data) = buf; 262e2ca90c2SFreddy Xin } else if (4 == size) { 263e2ca90c2SFreddy Xin u32 buf; 264e2ca90c2SFreddy Xin ret = __ax88179_read_cmd(dev, cmd, value, index, size, &buf, 1); 265e2ca90c2SFreddy Xin le32_to_cpus(&buf); 266e2ca90c2SFreddy Xin *((u32 *)data) = buf; 267e2ca90c2SFreddy Xin } else { 268e2ca90c2SFreddy Xin ret = __ax88179_read_cmd(dev, cmd, value, index, size, data, 1); 269e2ca90c2SFreddy Xin } 270e2ca90c2SFreddy Xin 271e2ca90c2SFreddy Xin return ret; 272e2ca90c2SFreddy Xin } 273e2ca90c2SFreddy Xin 274e2ca90c2SFreddy Xin static int ax88179_write_cmd_nopm(struct usbnet *dev, u8 cmd, u16 value, 275e2ca90c2SFreddy Xin u16 index, u16 size, void *data) 276e2ca90c2SFreddy Xin { 277e2ca90c2SFreddy Xin int ret; 278e2ca90c2SFreddy Xin 279e2ca90c2SFreddy Xin if (2 == size) { 280e2ca90c2SFreddy Xin u16 buf; 281e2ca90c2SFreddy Xin buf = *((u16 *)data); 282e2ca90c2SFreddy Xin cpu_to_le16s(&buf); 283e2ca90c2SFreddy Xin ret = __ax88179_write_cmd(dev, cmd, value, index, 284e2ca90c2SFreddy Xin size, &buf, 1); 285e2ca90c2SFreddy Xin } else { 286e2ca90c2SFreddy Xin ret = __ax88179_write_cmd(dev, cmd, value, index, 287e2ca90c2SFreddy Xin size, data, 1); 288e2ca90c2SFreddy Xin } 289e2ca90c2SFreddy Xin 290e2ca90c2SFreddy Xin return ret; 291e2ca90c2SFreddy Xin } 292e2ca90c2SFreddy Xin 293e2ca90c2SFreddy Xin static int ax88179_read_cmd(struct usbnet *dev, u8 cmd, u16 value, u16 index, 294e2ca90c2SFreddy Xin u16 size, void *data) 295e2ca90c2SFreddy Xin { 296e2ca90c2SFreddy Xin int ret; 297e2ca90c2SFreddy Xin 298e2ca90c2SFreddy Xin if (2 == size) { 299e2ca90c2SFreddy Xin u16 buf; 300e2ca90c2SFreddy Xin ret = __ax88179_read_cmd(dev, cmd, value, index, size, &buf, 0); 301e2ca90c2SFreddy Xin le16_to_cpus(&buf); 302e2ca90c2SFreddy Xin *((u16 *)data) = buf; 303e2ca90c2SFreddy Xin } else if (4 == size) { 304e2ca90c2SFreddy Xin u32 buf; 305e2ca90c2SFreddy Xin ret = __ax88179_read_cmd(dev, cmd, value, index, size, &buf, 0); 306e2ca90c2SFreddy Xin le32_to_cpus(&buf); 307e2ca90c2SFreddy Xin *((u32 *)data) = buf; 308e2ca90c2SFreddy Xin } else { 309e2ca90c2SFreddy Xin ret = __ax88179_read_cmd(dev, cmd, value, index, size, data, 0); 310e2ca90c2SFreddy Xin } 311e2ca90c2SFreddy Xin 312e2ca90c2SFreddy Xin return ret; 313e2ca90c2SFreddy Xin } 314e2ca90c2SFreddy Xin 315e2ca90c2SFreddy Xin static int ax88179_write_cmd(struct usbnet *dev, u8 cmd, u16 value, u16 index, 316e2ca90c2SFreddy Xin u16 size, void *data) 317e2ca90c2SFreddy Xin { 318e2ca90c2SFreddy Xin int ret; 319e2ca90c2SFreddy Xin 320e2ca90c2SFreddy Xin if (2 == size) { 321e2ca90c2SFreddy Xin u16 buf; 322e2ca90c2SFreddy Xin buf = *((u16 *)data); 323e2ca90c2SFreddy Xin cpu_to_le16s(&buf); 324e2ca90c2SFreddy Xin ret = __ax88179_write_cmd(dev, cmd, value, index, 325e2ca90c2SFreddy Xin size, &buf, 0); 326e2ca90c2SFreddy Xin } else { 327e2ca90c2SFreddy Xin ret = __ax88179_write_cmd(dev, cmd, value, index, 328e2ca90c2SFreddy Xin size, data, 0); 329e2ca90c2SFreddy Xin } 330e2ca90c2SFreddy Xin 331e2ca90c2SFreddy Xin return ret; 332e2ca90c2SFreddy Xin } 333e2ca90c2SFreddy Xin 334e2ca90c2SFreddy Xin static void ax88179_status(struct usbnet *dev, struct urb *urb) 335e2ca90c2SFreddy Xin { 336e2ca90c2SFreddy Xin struct ax88179_int_data *event; 337e2ca90c2SFreddy Xin u32 link; 338e2ca90c2SFreddy Xin 339e2ca90c2SFreddy Xin if (urb->actual_length < 8) 340e2ca90c2SFreddy Xin return; 341e2ca90c2SFreddy Xin 342e2ca90c2SFreddy Xin event = urb->transfer_buffer; 343e2ca90c2SFreddy Xin le32_to_cpus((void *)&event->intdata1); 344e2ca90c2SFreddy Xin 345e2ca90c2SFreddy Xin link = (((__force u32)event->intdata1) & AX_INT_PPLS_LINK) >> 16; 346e2ca90c2SFreddy Xin 347e2ca90c2SFreddy Xin if (netif_carrier_ok(dev->net) != link) { 3487a97856eSMing Lei usbnet_link_change(dev, link, 1); 349e2ca90c2SFreddy Xin netdev_info(dev->net, "ax88179 - Link status is: %d\n", link); 350e2ca90c2SFreddy Xin } 351e2ca90c2SFreddy Xin } 352e2ca90c2SFreddy Xin 353e2ca90c2SFreddy Xin static int ax88179_mdio_read(struct net_device *netdev, int phy_id, int loc) 354e2ca90c2SFreddy Xin { 355e2ca90c2SFreddy Xin struct usbnet *dev = netdev_priv(netdev); 356e2ca90c2SFreddy Xin u16 res; 357e2ca90c2SFreddy Xin 358e2ca90c2SFreddy Xin ax88179_read_cmd(dev, AX_ACCESS_PHY, phy_id, (__u16)loc, 2, &res); 359e2ca90c2SFreddy Xin return res; 360e2ca90c2SFreddy Xin } 361e2ca90c2SFreddy Xin 362e2ca90c2SFreddy Xin static void ax88179_mdio_write(struct net_device *netdev, int phy_id, int loc, 363e2ca90c2SFreddy Xin int val) 364e2ca90c2SFreddy Xin { 365e2ca90c2SFreddy Xin struct usbnet *dev = netdev_priv(netdev); 366e2ca90c2SFreddy Xin u16 res = (u16) val; 367e2ca90c2SFreddy Xin 368e2ca90c2SFreddy Xin ax88179_write_cmd(dev, AX_ACCESS_PHY, phy_id, (__u16)loc, 2, &res); 369e2ca90c2SFreddy Xin } 370e2ca90c2SFreddy Xin 371e98d69baSFreddy Xin static inline int ax88179_phy_mmd_indirect(struct usbnet *dev, u16 prtad, 372e98d69baSFreddy Xin u16 devad) 373e98d69baSFreddy Xin { 374e98d69baSFreddy Xin u16 tmp16; 375e98d69baSFreddy Xin int ret; 376e98d69baSFreddy Xin 377e98d69baSFreddy Xin tmp16 = devad; 378e98d69baSFreddy Xin ret = ax88179_write_cmd(dev, AX_ACCESS_PHY, AX88179_PHY_ID, 379e98d69baSFreddy Xin MII_MMD_CTRL, 2, &tmp16); 380e98d69baSFreddy Xin 381e98d69baSFreddy Xin tmp16 = prtad; 382e98d69baSFreddy Xin ret = ax88179_write_cmd(dev, AX_ACCESS_PHY, AX88179_PHY_ID, 383e98d69baSFreddy Xin MII_MMD_DATA, 2, &tmp16); 384e98d69baSFreddy Xin 385e98d69baSFreddy Xin tmp16 = devad | MII_MMD_CTRL_NOINCR; 386e98d69baSFreddy Xin ret = ax88179_write_cmd(dev, AX_ACCESS_PHY, AX88179_PHY_ID, 387e98d69baSFreddy Xin MII_MMD_CTRL, 2, &tmp16); 388e98d69baSFreddy Xin 389e98d69baSFreddy Xin return ret; 390e98d69baSFreddy Xin } 391e98d69baSFreddy Xin 392e98d69baSFreddy Xin static int 393e98d69baSFreddy Xin ax88179_phy_read_mmd_indirect(struct usbnet *dev, u16 prtad, u16 devad) 394e98d69baSFreddy Xin { 395e98d69baSFreddy Xin int ret; 396e98d69baSFreddy Xin u16 tmp16; 397e98d69baSFreddy Xin 398e98d69baSFreddy Xin ax88179_phy_mmd_indirect(dev, prtad, devad); 399e98d69baSFreddy Xin 400e98d69baSFreddy Xin ret = ax88179_read_cmd(dev, AX_ACCESS_PHY, AX88179_PHY_ID, 401e98d69baSFreddy Xin MII_MMD_DATA, 2, &tmp16); 402e98d69baSFreddy Xin if (ret < 0) 403e98d69baSFreddy Xin return ret; 404e98d69baSFreddy Xin 405e98d69baSFreddy Xin return tmp16; 406e98d69baSFreddy Xin } 407e98d69baSFreddy Xin 408e98d69baSFreddy Xin static int 409e98d69baSFreddy Xin ax88179_phy_write_mmd_indirect(struct usbnet *dev, u16 prtad, u16 devad, 410e98d69baSFreddy Xin u16 data) 411e98d69baSFreddy Xin { 412e98d69baSFreddy Xin int ret; 413e98d69baSFreddy Xin 414e98d69baSFreddy Xin ax88179_phy_mmd_indirect(dev, prtad, devad); 415e98d69baSFreddy Xin 416e98d69baSFreddy Xin ret = ax88179_write_cmd(dev, AX_ACCESS_PHY, AX88179_PHY_ID, 417e98d69baSFreddy Xin MII_MMD_DATA, 2, &data); 418e98d69baSFreddy Xin 419e98d69baSFreddy Xin if (ret < 0) 420e98d69baSFreddy Xin return ret; 421e98d69baSFreddy Xin 422e98d69baSFreddy Xin return 0; 423e98d69baSFreddy Xin } 424e98d69baSFreddy Xin 425e2ca90c2SFreddy Xin static int ax88179_suspend(struct usb_interface *intf, pm_message_t message) 426e2ca90c2SFreddy Xin { 427e2ca90c2SFreddy Xin struct usbnet *dev = usb_get_intfdata(intf); 428e2ca90c2SFreddy Xin u16 tmp16; 429e2ca90c2SFreddy Xin u8 tmp8; 430e2ca90c2SFreddy Xin 431e2ca90c2SFreddy Xin usbnet_suspend(intf, message); 432e2ca90c2SFreddy Xin 433e2ca90c2SFreddy Xin /* Disable RX path */ 434e2ca90c2SFreddy Xin ax88179_read_cmd_nopm(dev, AX_ACCESS_MAC, AX_MEDIUM_STATUS_MODE, 435e2ca90c2SFreddy Xin 2, 2, &tmp16); 436e2ca90c2SFreddy Xin tmp16 &= ~AX_MEDIUM_RECEIVE_EN; 437e2ca90c2SFreddy Xin ax88179_write_cmd_nopm(dev, AX_ACCESS_MAC, AX_MEDIUM_STATUS_MODE, 438e2ca90c2SFreddy Xin 2, 2, &tmp16); 439e2ca90c2SFreddy Xin 440e2ca90c2SFreddy Xin /* Force bulk-in zero length */ 441e2ca90c2SFreddy Xin ax88179_read_cmd_nopm(dev, AX_ACCESS_MAC, AX_PHYPWR_RSTCTL, 442e2ca90c2SFreddy Xin 2, 2, &tmp16); 443e2ca90c2SFreddy Xin 444e2ca90c2SFreddy Xin tmp16 |= AX_PHYPWR_RSTCTL_BZ | AX_PHYPWR_RSTCTL_IPRL; 445e2ca90c2SFreddy Xin ax88179_write_cmd_nopm(dev, AX_ACCESS_MAC, AX_PHYPWR_RSTCTL, 446e2ca90c2SFreddy Xin 2, 2, &tmp16); 447e2ca90c2SFreddy Xin 448e2ca90c2SFreddy Xin /* change clock */ 449e2ca90c2SFreddy Xin tmp8 = 0; 450e2ca90c2SFreddy Xin ax88179_write_cmd_nopm(dev, AX_ACCESS_MAC, AX_CLK_SELECT, 1, 1, &tmp8); 451e2ca90c2SFreddy Xin 452e2ca90c2SFreddy Xin /* Configure RX control register => stop operation */ 453e2ca90c2SFreddy Xin tmp16 = AX_RX_CTL_STOP; 454e2ca90c2SFreddy Xin ax88179_write_cmd_nopm(dev, AX_ACCESS_MAC, AX_RX_CTL, 2, 2, &tmp16); 455e2ca90c2SFreddy Xin 456e2ca90c2SFreddy Xin return 0; 457e2ca90c2SFreddy Xin } 458e2ca90c2SFreddy Xin 459e2ca90c2SFreddy Xin /* This function is used to enable the autodetach function. */ 460e2ca90c2SFreddy Xin /* This function is determined by offset 0x43 of EEPROM */ 461e2ca90c2SFreddy Xin static int ax88179_auto_detach(struct usbnet *dev, int in_pm) 462e2ca90c2SFreddy Xin { 463e2ca90c2SFreddy Xin u16 tmp16; 464e2ca90c2SFreddy Xin u8 tmp8; 465e2ca90c2SFreddy Xin int (*fnr)(struct usbnet *, u8, u16, u16, u16, void *); 466e2ca90c2SFreddy Xin int (*fnw)(struct usbnet *, u8, u16, u16, u16, void *); 467e2ca90c2SFreddy Xin 468e2ca90c2SFreddy Xin if (!in_pm) { 469e2ca90c2SFreddy Xin fnr = ax88179_read_cmd; 470e2ca90c2SFreddy Xin fnw = ax88179_write_cmd; 471e2ca90c2SFreddy Xin } else { 472e2ca90c2SFreddy Xin fnr = ax88179_read_cmd_nopm; 473e2ca90c2SFreddy Xin fnw = ax88179_write_cmd_nopm; 474e2ca90c2SFreddy Xin } 475e2ca90c2SFreddy Xin 476e2ca90c2SFreddy Xin if (fnr(dev, AX_ACCESS_EEPROM, 0x43, 1, 2, &tmp16) < 0) 477e2ca90c2SFreddy Xin return 0; 478e2ca90c2SFreddy Xin 479e2ca90c2SFreddy Xin if ((tmp16 == 0xFFFF) || (!(tmp16 & 0x0100))) 480e2ca90c2SFreddy Xin return 0; 481e2ca90c2SFreddy Xin 482e2ca90c2SFreddy Xin /* Enable Auto Detach bit */ 483e2ca90c2SFreddy Xin tmp8 = 0; 484e2ca90c2SFreddy Xin fnr(dev, AX_ACCESS_MAC, AX_CLK_SELECT, 1, 1, &tmp8); 485e2ca90c2SFreddy Xin tmp8 |= AX_CLK_SELECT_ULR; 486e2ca90c2SFreddy Xin fnw(dev, AX_ACCESS_MAC, AX_CLK_SELECT, 1, 1, &tmp8); 487e2ca90c2SFreddy Xin 488e2ca90c2SFreddy Xin fnr(dev, AX_ACCESS_MAC, AX_PHYPWR_RSTCTL, 2, 2, &tmp16); 489e2ca90c2SFreddy Xin tmp16 |= AX_PHYPWR_RSTCTL_AT; 490e2ca90c2SFreddy Xin fnw(dev, AX_ACCESS_MAC, AX_PHYPWR_RSTCTL, 2, 2, &tmp16); 491e2ca90c2SFreddy Xin 492e2ca90c2SFreddy Xin return 0; 493e2ca90c2SFreddy Xin } 494e2ca90c2SFreddy Xin 495e2ca90c2SFreddy Xin static int ax88179_resume(struct usb_interface *intf) 496e2ca90c2SFreddy Xin { 497e2ca90c2SFreddy Xin struct usbnet *dev = usb_get_intfdata(intf); 498e2ca90c2SFreddy Xin u16 tmp16; 499e2ca90c2SFreddy Xin u8 tmp8; 500e2ca90c2SFreddy Xin 5017a97856eSMing Lei usbnet_link_change(dev, 0, 0); 502e2ca90c2SFreddy Xin 503e2ca90c2SFreddy Xin /* Power up ethernet PHY */ 504e2ca90c2SFreddy Xin tmp16 = 0; 505e2ca90c2SFreddy Xin ax88179_write_cmd_nopm(dev, AX_ACCESS_MAC, AX_PHYPWR_RSTCTL, 506e2ca90c2SFreddy Xin 2, 2, &tmp16); 507e2ca90c2SFreddy Xin udelay(1000); 508e2ca90c2SFreddy Xin 509e2ca90c2SFreddy Xin tmp16 = AX_PHYPWR_RSTCTL_IPRL; 510e2ca90c2SFreddy Xin ax88179_write_cmd_nopm(dev, AX_ACCESS_MAC, AX_PHYPWR_RSTCTL, 511e2ca90c2SFreddy Xin 2, 2, &tmp16); 512e2ca90c2SFreddy Xin msleep(200); 513e2ca90c2SFreddy Xin 514e2ca90c2SFreddy Xin /* Ethernet PHY Auto Detach*/ 515e2ca90c2SFreddy Xin ax88179_auto_detach(dev, 1); 516e2ca90c2SFreddy Xin 517e2ca90c2SFreddy Xin /* Enable clock */ 518e2ca90c2SFreddy Xin ax88179_read_cmd_nopm(dev, AX_ACCESS_MAC, AX_CLK_SELECT, 1, 1, &tmp8); 519e2ca90c2SFreddy Xin tmp8 |= AX_CLK_SELECT_ACS | AX_CLK_SELECT_BCS; 520e2ca90c2SFreddy Xin ax88179_write_cmd_nopm(dev, AX_ACCESS_MAC, AX_CLK_SELECT, 1, 1, &tmp8); 521e2ca90c2SFreddy Xin msleep(100); 522e2ca90c2SFreddy Xin 523e2ca90c2SFreddy Xin /* Configure RX control register => start operation */ 524e2ca90c2SFreddy Xin tmp16 = AX_RX_CTL_DROPCRCERR | AX_RX_CTL_IPE | AX_RX_CTL_START | 525e2ca90c2SFreddy Xin AX_RX_CTL_AP | AX_RX_CTL_AMALL | AX_RX_CTL_AB; 526e2ca90c2SFreddy Xin ax88179_write_cmd_nopm(dev, AX_ACCESS_MAC, AX_RX_CTL, 2, 2, &tmp16); 527e2ca90c2SFreddy Xin 528e2ca90c2SFreddy Xin return usbnet_resume(intf); 529e2ca90c2SFreddy Xin } 530e2ca90c2SFreddy Xin 531e2ca90c2SFreddy Xin static void 532e2ca90c2SFreddy Xin ax88179_get_wol(struct net_device *net, struct ethtool_wolinfo *wolinfo) 533e2ca90c2SFreddy Xin { 534e2ca90c2SFreddy Xin struct usbnet *dev = netdev_priv(net); 535e2ca90c2SFreddy Xin u8 opt; 536e2ca90c2SFreddy Xin 537e2ca90c2SFreddy Xin if (ax88179_read_cmd(dev, AX_ACCESS_MAC, AX_MONITOR_MOD, 538e2ca90c2SFreddy Xin 1, 1, &opt) < 0) { 539e2ca90c2SFreddy Xin wolinfo->supported = 0; 540e2ca90c2SFreddy Xin wolinfo->wolopts = 0; 541e2ca90c2SFreddy Xin return; 542e2ca90c2SFreddy Xin } 543e2ca90c2SFreddy Xin 544e2ca90c2SFreddy Xin wolinfo->supported = WAKE_PHY | WAKE_MAGIC; 545e2ca90c2SFreddy Xin wolinfo->wolopts = 0; 546e2ca90c2SFreddy Xin if (opt & AX_MONITOR_MODE_RWLC) 547e2ca90c2SFreddy Xin wolinfo->wolopts |= WAKE_PHY; 548e2ca90c2SFreddy Xin if (opt & AX_MONITOR_MODE_RWMP) 549e2ca90c2SFreddy Xin wolinfo->wolopts |= WAKE_MAGIC; 550e2ca90c2SFreddy Xin } 551e2ca90c2SFreddy Xin 552e2ca90c2SFreddy Xin static int 553e2ca90c2SFreddy Xin ax88179_set_wol(struct net_device *net, struct ethtool_wolinfo *wolinfo) 554e2ca90c2SFreddy Xin { 555e2ca90c2SFreddy Xin struct usbnet *dev = netdev_priv(net); 556e2ca90c2SFreddy Xin u8 opt = 0; 557e2ca90c2SFreddy Xin 5585ba6b4aaSFlorian Fainelli if (wolinfo->wolopts & ~(WAKE_PHY | WAKE_MAGIC)) 5595ba6b4aaSFlorian Fainelli return -EINVAL; 5605ba6b4aaSFlorian Fainelli 561e2ca90c2SFreddy Xin if (wolinfo->wolopts & WAKE_PHY) 562e2ca90c2SFreddy Xin opt |= AX_MONITOR_MODE_RWLC; 563e2ca90c2SFreddy Xin if (wolinfo->wolopts & WAKE_MAGIC) 564e2ca90c2SFreddy Xin opt |= AX_MONITOR_MODE_RWMP; 565e2ca90c2SFreddy Xin 566e2ca90c2SFreddy Xin if (ax88179_write_cmd(dev, AX_ACCESS_MAC, AX_MONITOR_MOD, 567e2ca90c2SFreddy Xin 1, 1, &opt) < 0) 568e2ca90c2SFreddy Xin return -EINVAL; 569e2ca90c2SFreddy Xin 570e2ca90c2SFreddy Xin return 0; 571e2ca90c2SFreddy Xin } 572e2ca90c2SFreddy Xin 573e2ca90c2SFreddy Xin static int ax88179_get_eeprom_len(struct net_device *net) 574e2ca90c2SFreddy Xin { 575e2ca90c2SFreddy Xin return AX_EEPROM_LEN; 576e2ca90c2SFreddy Xin } 577e2ca90c2SFreddy Xin 578e2ca90c2SFreddy Xin static int 579e2ca90c2SFreddy Xin ax88179_get_eeprom(struct net_device *net, struct ethtool_eeprom *eeprom, 580e2ca90c2SFreddy Xin u8 *data) 581e2ca90c2SFreddy Xin { 582e2ca90c2SFreddy Xin struct usbnet *dev = netdev_priv(net); 583e2ca90c2SFreddy Xin u16 *eeprom_buff; 584e2ca90c2SFreddy Xin int first_word, last_word; 585e2ca90c2SFreddy Xin int i, ret; 586e2ca90c2SFreddy Xin 587e2ca90c2SFreddy Xin if (eeprom->len == 0) 588e2ca90c2SFreddy Xin return -EINVAL; 589e2ca90c2SFreddy Xin 590e2ca90c2SFreddy Xin eeprom->magic = AX88179_EEPROM_MAGIC; 591e2ca90c2SFreddy Xin 592e2ca90c2SFreddy Xin first_word = eeprom->offset >> 1; 593e2ca90c2SFreddy Xin last_word = (eeprom->offset + eeprom->len - 1) >> 1; 5946da2ec56SKees Cook eeprom_buff = kmalloc_array(last_word - first_word + 1, sizeof(u16), 595e2ca90c2SFreddy Xin GFP_KERNEL); 596e2ca90c2SFreddy Xin if (!eeprom_buff) 597e2ca90c2SFreddy Xin return -ENOMEM; 598e2ca90c2SFreddy Xin 599e2ca90c2SFreddy Xin /* ax88179/178A returns 2 bytes from eeprom on read */ 600e2ca90c2SFreddy Xin for (i = first_word; i <= last_word; i++) { 601e2ca90c2SFreddy Xin ret = __ax88179_read_cmd(dev, AX_ACCESS_EEPROM, i, 1, 2, 602e2ca90c2SFreddy Xin &eeprom_buff[i - first_word], 603e2ca90c2SFreddy Xin 0); 604e2ca90c2SFreddy Xin if (ret < 0) { 605e2ca90c2SFreddy Xin kfree(eeprom_buff); 606e2ca90c2SFreddy Xin return -EIO; 607e2ca90c2SFreddy Xin } 608e2ca90c2SFreddy Xin } 609e2ca90c2SFreddy Xin 610e2ca90c2SFreddy Xin memcpy(data, (u8 *)eeprom_buff + (eeprom->offset & 1), eeprom->len); 611e2ca90c2SFreddy Xin kfree(eeprom_buff); 612e2ca90c2SFreddy Xin return 0; 613e2ca90c2SFreddy Xin } 614e2ca90c2SFreddy Xin 61578734404SBjorn Andersson static int 61678734404SBjorn Andersson ax88179_set_eeprom(struct net_device *net, struct ethtool_eeprom *eeprom, 61778734404SBjorn Andersson u8 *data) 61878734404SBjorn Andersson { 61978734404SBjorn Andersson struct usbnet *dev = netdev_priv(net); 62078734404SBjorn Andersson u16 *eeprom_buff; 62178734404SBjorn Andersson int first_word; 62278734404SBjorn Andersson int last_word; 62378734404SBjorn Andersson int ret; 62478734404SBjorn Andersson int i; 62578734404SBjorn Andersson 62678734404SBjorn Andersson netdev_dbg(net, "write EEPROM len %d, offset %d, magic 0x%x\n", 62778734404SBjorn Andersson eeprom->len, eeprom->offset, eeprom->magic); 62878734404SBjorn Andersson 62978734404SBjorn Andersson if (eeprom->len == 0) 63078734404SBjorn Andersson return -EINVAL; 63178734404SBjorn Andersson 63278734404SBjorn Andersson if (eeprom->magic != AX88179_EEPROM_MAGIC) 63378734404SBjorn Andersson return -EINVAL; 63478734404SBjorn Andersson 63578734404SBjorn Andersson first_word = eeprom->offset >> 1; 63678734404SBjorn Andersson last_word = (eeprom->offset + eeprom->len - 1) >> 1; 63778734404SBjorn Andersson 63878734404SBjorn Andersson eeprom_buff = kmalloc_array(last_word - first_word + 1, sizeof(u16), 63978734404SBjorn Andersson GFP_KERNEL); 64078734404SBjorn Andersson if (!eeprom_buff) 64178734404SBjorn Andersson return -ENOMEM; 64278734404SBjorn Andersson 64378734404SBjorn Andersson /* align data to 16 bit boundaries, read the missing data from 64478734404SBjorn Andersson the EEPROM */ 64578734404SBjorn Andersson if (eeprom->offset & 1) { 64678734404SBjorn Andersson ret = ax88179_read_cmd(dev, AX_ACCESS_EEPROM, first_word, 1, 2, 64778734404SBjorn Andersson &eeprom_buff[0]); 64878734404SBjorn Andersson if (ret < 0) { 64978734404SBjorn Andersson netdev_err(net, "Failed to read EEPROM at offset 0x%02x.\n", first_word); 65078734404SBjorn Andersson goto free; 65178734404SBjorn Andersson } 65278734404SBjorn Andersson } 65378734404SBjorn Andersson 65478734404SBjorn Andersson if ((eeprom->offset + eeprom->len) & 1) { 65578734404SBjorn Andersson ret = ax88179_read_cmd(dev, AX_ACCESS_EEPROM, last_word, 1, 2, 65678734404SBjorn Andersson &eeprom_buff[last_word - first_word]); 65778734404SBjorn Andersson if (ret < 0) { 65878734404SBjorn Andersson netdev_err(net, "Failed to read EEPROM at offset 0x%02x.\n", last_word); 65978734404SBjorn Andersson goto free; 66078734404SBjorn Andersson } 66178734404SBjorn Andersson } 66278734404SBjorn Andersson 66378734404SBjorn Andersson memcpy((u8 *)eeprom_buff + (eeprom->offset & 1), data, eeprom->len); 66478734404SBjorn Andersson 66578734404SBjorn Andersson for (i = first_word; i <= last_word; i++) { 66678734404SBjorn Andersson netdev_dbg(net, "write to EEPROM at offset 0x%02x, data 0x%04x\n", 66778734404SBjorn Andersson i, eeprom_buff[i - first_word]); 66878734404SBjorn Andersson ret = ax88179_write_cmd(dev, AX_ACCESS_EEPROM, i, 1, 2, 66978734404SBjorn Andersson &eeprom_buff[i - first_word]); 67078734404SBjorn Andersson if (ret < 0) { 67178734404SBjorn Andersson netdev_err(net, "Failed to write EEPROM at offset 0x%02x.\n", i); 67278734404SBjorn Andersson goto free; 67378734404SBjorn Andersson } 67478734404SBjorn Andersson msleep(20); 67578734404SBjorn Andersson } 67678734404SBjorn Andersson 67778734404SBjorn Andersson /* reload EEPROM data */ 67878734404SBjorn Andersson ret = ax88179_write_cmd(dev, AX_RELOAD_EEPROM_EFUSE, 0x0000, 0, 0, NULL); 67978734404SBjorn Andersson if (ret < 0) { 68078734404SBjorn Andersson netdev_err(net, "Failed to reload EEPROM data\n"); 68178734404SBjorn Andersson goto free; 68278734404SBjorn Andersson } 68378734404SBjorn Andersson 68478734404SBjorn Andersson ret = 0; 68578734404SBjorn Andersson free: 68678734404SBjorn Andersson kfree(eeprom_buff); 68778734404SBjorn Andersson return ret; 68878734404SBjorn Andersson } 68978734404SBjorn Andersson 6903c9b803bSPhilippe Reynes static int ax88179_get_link_ksettings(struct net_device *net, 6913c9b803bSPhilippe Reynes struct ethtool_link_ksettings *cmd) 692e2ca90c2SFreddy Xin { 693e2ca90c2SFreddy Xin struct usbnet *dev = netdev_priv(net); 69482c01a84Syuval.shaia@oracle.com 69582c01a84Syuval.shaia@oracle.com mii_ethtool_get_link_ksettings(&dev->mii, cmd); 69682c01a84Syuval.shaia@oracle.com 69782c01a84Syuval.shaia@oracle.com return 0; 698e2ca90c2SFreddy Xin } 699e2ca90c2SFreddy Xin 7003c9b803bSPhilippe Reynes static int ax88179_set_link_ksettings(struct net_device *net, 7013c9b803bSPhilippe Reynes const struct ethtool_link_ksettings *cmd) 702e2ca90c2SFreddy Xin { 703e2ca90c2SFreddy Xin struct usbnet *dev = netdev_priv(net); 7043c9b803bSPhilippe Reynes return mii_ethtool_set_link_ksettings(&dev->mii, cmd); 705e2ca90c2SFreddy Xin } 706e2ca90c2SFreddy Xin 707e98d69baSFreddy Xin static int 708e98d69baSFreddy Xin ax88179_ethtool_get_eee(struct usbnet *dev, struct ethtool_eee *data) 709e98d69baSFreddy Xin { 710e98d69baSFreddy Xin int val; 711e98d69baSFreddy Xin 712e98d69baSFreddy Xin /* Get Supported EEE */ 713e98d69baSFreddy Xin val = ax88179_phy_read_mmd_indirect(dev, MDIO_PCS_EEE_ABLE, 714e98d69baSFreddy Xin MDIO_MMD_PCS); 715e98d69baSFreddy Xin if (val < 0) 716e98d69baSFreddy Xin return val; 717e98d69baSFreddy Xin data->supported = mmd_eee_cap_to_ethtool_sup_t(val); 718e98d69baSFreddy Xin 719e98d69baSFreddy Xin /* Get advertisement EEE */ 720e98d69baSFreddy Xin val = ax88179_phy_read_mmd_indirect(dev, MDIO_AN_EEE_ADV, 721e98d69baSFreddy Xin MDIO_MMD_AN); 722e98d69baSFreddy Xin if (val < 0) 723e98d69baSFreddy Xin return val; 724e98d69baSFreddy Xin data->advertised = mmd_eee_adv_to_ethtool_adv_t(val); 725e98d69baSFreddy Xin 726e98d69baSFreddy Xin /* Get LP advertisement EEE */ 727e98d69baSFreddy Xin val = ax88179_phy_read_mmd_indirect(dev, MDIO_AN_EEE_LPABLE, 728e98d69baSFreddy Xin MDIO_MMD_AN); 729e98d69baSFreddy Xin if (val < 0) 730e98d69baSFreddy Xin return val; 731e98d69baSFreddy Xin data->lp_advertised = mmd_eee_adv_to_ethtool_adv_t(val); 732e98d69baSFreddy Xin 733e98d69baSFreddy Xin return 0; 734e98d69baSFreddy Xin } 735e98d69baSFreddy Xin 736e98d69baSFreddy Xin static int 737e98d69baSFreddy Xin ax88179_ethtool_set_eee(struct usbnet *dev, struct ethtool_eee *data) 738e98d69baSFreddy Xin { 739e98d69baSFreddy Xin u16 tmp16 = ethtool_adv_to_mmd_eee_adv_t(data->advertised); 740e98d69baSFreddy Xin 741e98d69baSFreddy Xin return ax88179_phy_write_mmd_indirect(dev, MDIO_AN_EEE_ADV, 742e98d69baSFreddy Xin MDIO_MMD_AN, tmp16); 743e98d69baSFreddy Xin } 744e98d69baSFreddy Xin 745e98d69baSFreddy Xin static int ax88179_chk_eee(struct usbnet *dev) 746e98d69baSFreddy Xin { 747e98d69baSFreddy Xin struct ethtool_cmd ecmd = { .cmd = ETHTOOL_GSET }; 748e98d69baSFreddy Xin struct ax88179_data *priv = (struct ax88179_data *)dev->data; 749e98d69baSFreddy Xin 750e98d69baSFreddy Xin mii_ethtool_gset(&dev->mii, &ecmd); 751e98d69baSFreddy Xin 752e98d69baSFreddy Xin if (ecmd.duplex & DUPLEX_FULL) { 753e98d69baSFreddy Xin int eee_lp, eee_cap, eee_adv; 754e98d69baSFreddy Xin u32 lp, cap, adv, supported = 0; 755e98d69baSFreddy Xin 756e98d69baSFreddy Xin eee_cap = ax88179_phy_read_mmd_indirect(dev, 757e98d69baSFreddy Xin MDIO_PCS_EEE_ABLE, 758e98d69baSFreddy Xin MDIO_MMD_PCS); 759e98d69baSFreddy Xin if (eee_cap < 0) { 760e98d69baSFreddy Xin priv->eee_active = 0; 761e98d69baSFreddy Xin return false; 762e98d69baSFreddy Xin } 763e98d69baSFreddy Xin 764e98d69baSFreddy Xin cap = mmd_eee_cap_to_ethtool_sup_t(eee_cap); 765e98d69baSFreddy Xin if (!cap) { 766e98d69baSFreddy Xin priv->eee_active = 0; 767e98d69baSFreddy Xin return false; 768e98d69baSFreddy Xin } 769e98d69baSFreddy Xin 770e98d69baSFreddy Xin eee_lp = ax88179_phy_read_mmd_indirect(dev, 771e98d69baSFreddy Xin MDIO_AN_EEE_LPABLE, 772e98d69baSFreddy Xin MDIO_MMD_AN); 773e98d69baSFreddy Xin if (eee_lp < 0) { 774e98d69baSFreddy Xin priv->eee_active = 0; 775e98d69baSFreddy Xin return false; 776e98d69baSFreddy Xin } 777e98d69baSFreddy Xin 778e98d69baSFreddy Xin eee_adv = ax88179_phy_read_mmd_indirect(dev, 779e98d69baSFreddy Xin MDIO_AN_EEE_ADV, 780e98d69baSFreddy Xin MDIO_MMD_AN); 781e98d69baSFreddy Xin 782e98d69baSFreddy Xin if (eee_adv < 0) { 783e98d69baSFreddy Xin priv->eee_active = 0; 784e98d69baSFreddy Xin return false; 785e98d69baSFreddy Xin } 786e98d69baSFreddy Xin 787e98d69baSFreddy Xin adv = mmd_eee_adv_to_ethtool_adv_t(eee_adv); 788e98d69baSFreddy Xin lp = mmd_eee_adv_to_ethtool_adv_t(eee_lp); 789e98d69baSFreddy Xin supported = (ecmd.speed == SPEED_1000) ? 790e98d69baSFreddy Xin SUPPORTED_1000baseT_Full : 791e98d69baSFreddy Xin SUPPORTED_100baseT_Full; 792e98d69baSFreddy Xin 793e98d69baSFreddy Xin if (!(lp & adv & supported)) { 794e98d69baSFreddy Xin priv->eee_active = 0; 795e98d69baSFreddy Xin return false; 796e98d69baSFreddy Xin } 797e98d69baSFreddy Xin 798e98d69baSFreddy Xin priv->eee_active = 1; 799e98d69baSFreddy Xin return true; 800e98d69baSFreddy Xin } 801e98d69baSFreddy Xin 802e98d69baSFreddy Xin priv->eee_active = 0; 803e98d69baSFreddy Xin return false; 804e98d69baSFreddy Xin } 805e98d69baSFreddy Xin 806e98d69baSFreddy Xin static void ax88179_disable_eee(struct usbnet *dev) 807e98d69baSFreddy Xin { 808e98d69baSFreddy Xin u16 tmp16; 809e98d69baSFreddy Xin 810e98d69baSFreddy Xin tmp16 = GMII_PHY_PGSEL_PAGE3; 811e98d69baSFreddy Xin ax88179_write_cmd(dev, AX_ACCESS_PHY, AX88179_PHY_ID, 812e98d69baSFreddy Xin GMII_PHY_PAGE_SELECT, 2, &tmp16); 813e98d69baSFreddy Xin 814e98d69baSFreddy Xin tmp16 = 0x3246; 815e98d69baSFreddy Xin ax88179_write_cmd(dev, AX_ACCESS_PHY, AX88179_PHY_ID, 816e98d69baSFreddy Xin MII_PHYADDR, 2, &tmp16); 817e98d69baSFreddy Xin 818e98d69baSFreddy Xin tmp16 = GMII_PHY_PGSEL_PAGE0; 819e98d69baSFreddy Xin ax88179_write_cmd(dev, AX_ACCESS_PHY, AX88179_PHY_ID, 820e98d69baSFreddy Xin GMII_PHY_PAGE_SELECT, 2, &tmp16); 821e98d69baSFreddy Xin } 822e98d69baSFreddy Xin 823e98d69baSFreddy Xin static void ax88179_enable_eee(struct usbnet *dev) 824e98d69baSFreddy Xin { 825e98d69baSFreddy Xin u16 tmp16; 826e98d69baSFreddy Xin 827e98d69baSFreddy Xin tmp16 = GMII_PHY_PGSEL_PAGE3; 828e98d69baSFreddy Xin ax88179_write_cmd(dev, AX_ACCESS_PHY, AX88179_PHY_ID, 829e98d69baSFreddy Xin GMII_PHY_PAGE_SELECT, 2, &tmp16); 830e98d69baSFreddy Xin 831e98d69baSFreddy Xin tmp16 = 0x3247; 832e98d69baSFreddy Xin ax88179_write_cmd(dev, AX_ACCESS_PHY, AX88179_PHY_ID, 833e98d69baSFreddy Xin MII_PHYADDR, 2, &tmp16); 834e98d69baSFreddy Xin 835e98d69baSFreddy Xin tmp16 = GMII_PHY_PGSEL_PAGE5; 836e98d69baSFreddy Xin ax88179_write_cmd(dev, AX_ACCESS_PHY, AX88179_PHY_ID, 837e98d69baSFreddy Xin GMII_PHY_PAGE_SELECT, 2, &tmp16); 838e98d69baSFreddy Xin 839e98d69baSFreddy Xin tmp16 = 0x0680; 840e98d69baSFreddy Xin ax88179_write_cmd(dev, AX_ACCESS_PHY, AX88179_PHY_ID, 841e98d69baSFreddy Xin MII_BMSR, 2, &tmp16); 842e98d69baSFreddy Xin 843e98d69baSFreddy Xin tmp16 = GMII_PHY_PGSEL_PAGE0; 844e98d69baSFreddy Xin ax88179_write_cmd(dev, AX_ACCESS_PHY, AX88179_PHY_ID, 845e98d69baSFreddy Xin GMII_PHY_PAGE_SELECT, 2, &tmp16); 846e98d69baSFreddy Xin } 847e98d69baSFreddy Xin 848e98d69baSFreddy Xin static int ax88179_get_eee(struct net_device *net, struct ethtool_eee *edata) 849e98d69baSFreddy Xin { 850e98d69baSFreddy Xin struct usbnet *dev = netdev_priv(net); 851e98d69baSFreddy Xin struct ax88179_data *priv = (struct ax88179_data *)dev->data; 852e98d69baSFreddy Xin 853e98d69baSFreddy Xin edata->eee_enabled = priv->eee_enabled; 854e98d69baSFreddy Xin edata->eee_active = priv->eee_active; 855e98d69baSFreddy Xin 856e98d69baSFreddy Xin return ax88179_ethtool_get_eee(dev, edata); 857e98d69baSFreddy Xin } 858e98d69baSFreddy Xin 859e98d69baSFreddy Xin static int ax88179_set_eee(struct net_device *net, struct ethtool_eee *edata) 860e98d69baSFreddy Xin { 861e98d69baSFreddy Xin struct usbnet *dev = netdev_priv(net); 862e98d69baSFreddy Xin struct ax88179_data *priv = (struct ax88179_data *)dev->data; 863d728e640SColin Ian King int ret; 864e98d69baSFreddy Xin 865e98d69baSFreddy Xin priv->eee_enabled = edata->eee_enabled; 866e98d69baSFreddy Xin if (!priv->eee_enabled) { 867e98d69baSFreddy Xin ax88179_disable_eee(dev); 868e98d69baSFreddy Xin } else { 869e98d69baSFreddy Xin priv->eee_enabled = ax88179_chk_eee(dev); 870e98d69baSFreddy Xin if (!priv->eee_enabled) 871e98d69baSFreddy Xin return -EOPNOTSUPP; 872e98d69baSFreddy Xin 873e98d69baSFreddy Xin ax88179_enable_eee(dev); 874e98d69baSFreddy Xin } 875e98d69baSFreddy Xin 876e98d69baSFreddy Xin ret = ax88179_ethtool_set_eee(dev, edata); 877e98d69baSFreddy Xin if (ret) 878e98d69baSFreddy Xin return ret; 879e98d69baSFreddy Xin 880e98d69baSFreddy Xin mii_nway_restart(&dev->mii); 881e98d69baSFreddy Xin 882e98d69baSFreddy Xin usbnet_link_change(dev, 0, 0); 883e98d69baSFreddy Xin 884e98d69baSFreddy Xin return ret; 885e98d69baSFreddy Xin } 886e2ca90c2SFreddy Xin 887e2ca90c2SFreddy Xin static int ax88179_ioctl(struct net_device *net, struct ifreq *rq, int cmd) 888e2ca90c2SFreddy Xin { 889e2ca90c2SFreddy Xin struct usbnet *dev = netdev_priv(net); 890e2ca90c2SFreddy Xin return generic_mii_ioctl(&dev->mii, if_mii(rq), cmd, NULL); 891e2ca90c2SFreddy Xin } 892e2ca90c2SFreddy Xin 893e2ca90c2SFreddy Xin static const struct ethtool_ops ax88179_ethtool_ops = { 894e2ca90c2SFreddy Xin .get_link = ethtool_op_get_link, 895e2ca90c2SFreddy Xin .get_msglevel = usbnet_get_msglevel, 896e2ca90c2SFreddy Xin .set_msglevel = usbnet_set_msglevel, 897e2ca90c2SFreddy Xin .get_wol = ax88179_get_wol, 898e2ca90c2SFreddy Xin .set_wol = ax88179_set_wol, 899e2ca90c2SFreddy Xin .get_eeprom_len = ax88179_get_eeprom_len, 900e2ca90c2SFreddy Xin .get_eeprom = ax88179_get_eeprom, 90178734404SBjorn Andersson .set_eeprom = ax88179_set_eeprom, 902e98d69baSFreddy Xin .get_eee = ax88179_get_eee, 903e98d69baSFreddy Xin .set_eee = ax88179_set_eee, 904e2ca90c2SFreddy Xin .nway_reset = usbnet_nway_reset, 9053c9b803bSPhilippe Reynes .get_link_ksettings = ax88179_get_link_ksettings, 9063c9b803bSPhilippe Reynes .set_link_ksettings = ax88179_set_link_ksettings, 907dc83ef22SAndreas K. Besslein .get_ts_info = ethtool_op_get_ts_info, 908e2ca90c2SFreddy Xin }; 909e2ca90c2SFreddy Xin 910e2ca90c2SFreddy Xin static void ax88179_set_multicast(struct net_device *net) 911e2ca90c2SFreddy Xin { 912e2ca90c2SFreddy Xin struct usbnet *dev = netdev_priv(net); 913e2ca90c2SFreddy Xin struct ax88179_data *data = (struct ax88179_data *)dev->data; 914e2ca90c2SFreddy Xin u8 *m_filter = ((u8 *)dev->data) + 12; 915e2ca90c2SFreddy Xin 916e2ca90c2SFreddy Xin data->rxctl = (AX_RX_CTL_START | AX_RX_CTL_AB | AX_RX_CTL_IPE); 917e2ca90c2SFreddy Xin 918e2ca90c2SFreddy Xin if (net->flags & IFF_PROMISC) { 919e2ca90c2SFreddy Xin data->rxctl |= AX_RX_CTL_PRO; 920e2ca90c2SFreddy Xin } else if (net->flags & IFF_ALLMULTI || 921e2ca90c2SFreddy Xin netdev_mc_count(net) > AX_MAX_MCAST) { 922e2ca90c2SFreddy Xin data->rxctl |= AX_RX_CTL_AMALL; 923e2ca90c2SFreddy Xin } else if (netdev_mc_empty(net)) { 924e2ca90c2SFreddy Xin /* just broadcast and directed */ 925e2ca90c2SFreddy Xin } else { 926e2ca90c2SFreddy Xin /* We use the 20 byte dev->data for our 8 byte filter buffer 927e2ca90c2SFreddy Xin * to avoid allocating memory that is tricky to free later 928e2ca90c2SFreddy Xin */ 929e2ca90c2SFreddy Xin u32 crc_bits; 930e2ca90c2SFreddy Xin struct netdev_hw_addr *ha; 931e2ca90c2SFreddy Xin 932e2ca90c2SFreddy Xin memset(m_filter, 0, AX_MCAST_FLTSIZE); 933e2ca90c2SFreddy Xin 934e2ca90c2SFreddy Xin netdev_for_each_mc_addr(ha, net) { 935e2ca90c2SFreddy Xin crc_bits = ether_crc(ETH_ALEN, ha->addr) >> 26; 936e2ca90c2SFreddy Xin *(m_filter + (crc_bits >> 3)) |= (1 << (crc_bits & 7)); 937e2ca90c2SFreddy Xin } 938e2ca90c2SFreddy Xin 939e2ca90c2SFreddy Xin ax88179_write_cmd_async(dev, AX_ACCESS_MAC, AX_MULFLTARY, 940e2ca90c2SFreddy Xin AX_MCAST_FLTSIZE, AX_MCAST_FLTSIZE, 941e2ca90c2SFreddy Xin m_filter); 942e2ca90c2SFreddy Xin 943e2ca90c2SFreddy Xin data->rxctl |= AX_RX_CTL_AM; 944e2ca90c2SFreddy Xin } 945e2ca90c2SFreddy Xin 946e2ca90c2SFreddy Xin ax88179_write_cmd_async(dev, AX_ACCESS_MAC, AX_RX_CTL, 947e2ca90c2SFreddy Xin 2, 2, &data->rxctl); 948e2ca90c2SFreddy Xin } 949e2ca90c2SFreddy Xin 950e2ca90c2SFreddy Xin static int 951e2ca90c2SFreddy Xin ax88179_set_features(struct net_device *net, netdev_features_t features) 952e2ca90c2SFreddy Xin { 953e2ca90c2SFreddy Xin u8 tmp; 954e2ca90c2SFreddy Xin struct usbnet *dev = netdev_priv(net); 955e2ca90c2SFreddy Xin netdev_features_t changed = net->features ^ features; 956e2ca90c2SFreddy Xin 957e2ca90c2SFreddy Xin if (changed & NETIF_F_IP_CSUM) { 958e2ca90c2SFreddy Xin ax88179_read_cmd(dev, AX_ACCESS_MAC, AX_TXCOE_CTL, 1, 1, &tmp); 959e2ca90c2SFreddy Xin tmp ^= AX_TXCOE_TCP | AX_TXCOE_UDP; 960e2ca90c2SFreddy Xin ax88179_write_cmd(dev, AX_ACCESS_MAC, AX_TXCOE_CTL, 1, 1, &tmp); 961e2ca90c2SFreddy Xin } 962e2ca90c2SFreddy Xin 963e2ca90c2SFreddy Xin if (changed & NETIF_F_IPV6_CSUM) { 964e2ca90c2SFreddy Xin ax88179_read_cmd(dev, AX_ACCESS_MAC, AX_TXCOE_CTL, 1, 1, &tmp); 965e2ca90c2SFreddy Xin tmp ^= AX_TXCOE_TCPV6 | AX_TXCOE_UDPV6; 966e2ca90c2SFreddy Xin ax88179_write_cmd(dev, AX_ACCESS_MAC, AX_TXCOE_CTL, 1, 1, &tmp); 967e2ca90c2SFreddy Xin } 968e2ca90c2SFreddy Xin 969e2ca90c2SFreddy Xin if (changed & NETIF_F_RXCSUM) { 970e2ca90c2SFreddy Xin ax88179_read_cmd(dev, AX_ACCESS_MAC, AX_RXCOE_CTL, 1, 1, &tmp); 971e2ca90c2SFreddy Xin tmp ^= AX_RXCOE_IP | AX_RXCOE_TCP | AX_RXCOE_UDP | 972e2ca90c2SFreddy Xin AX_RXCOE_TCPV6 | AX_RXCOE_UDPV6; 973e2ca90c2SFreddy Xin ax88179_write_cmd(dev, AX_ACCESS_MAC, AX_RXCOE_CTL, 1, 1, &tmp); 974e2ca90c2SFreddy Xin } 975e2ca90c2SFreddy Xin 976e2ca90c2SFreddy Xin return 0; 977e2ca90c2SFreddy Xin } 978e2ca90c2SFreddy Xin 979e2ca90c2SFreddy Xin static int ax88179_change_mtu(struct net_device *net, int new_mtu) 980e2ca90c2SFreddy Xin { 981e2ca90c2SFreddy Xin struct usbnet *dev = netdev_priv(net); 982e2ca90c2SFreddy Xin u16 tmp16; 983e2ca90c2SFreddy Xin 984e2ca90c2SFreddy Xin net->mtu = new_mtu; 985e2ca90c2SFreddy Xin dev->hard_mtu = net->mtu + net->hard_header_len; 986e2ca90c2SFreddy Xin 987e2ca90c2SFreddy Xin if (net->mtu > 1500) { 988e2ca90c2SFreddy Xin ax88179_read_cmd(dev, AX_ACCESS_MAC, AX_MEDIUM_STATUS_MODE, 989e2ca90c2SFreddy Xin 2, 2, &tmp16); 990e2ca90c2SFreddy Xin tmp16 |= AX_MEDIUM_JUMBO_EN; 991e2ca90c2SFreddy Xin ax88179_write_cmd(dev, AX_ACCESS_MAC, AX_MEDIUM_STATUS_MODE, 992e2ca90c2SFreddy Xin 2, 2, &tmp16); 993e2ca90c2SFreddy Xin } else { 994e2ca90c2SFreddy Xin ax88179_read_cmd(dev, AX_ACCESS_MAC, AX_MEDIUM_STATUS_MODE, 995e2ca90c2SFreddy Xin 2, 2, &tmp16); 996e2ca90c2SFreddy Xin tmp16 &= ~AX_MEDIUM_JUMBO_EN; 997e2ca90c2SFreddy Xin ax88179_write_cmd(dev, AX_ACCESS_MAC, AX_MEDIUM_STATUS_MODE, 998e2ca90c2SFreddy Xin 2, 2, &tmp16); 999e2ca90c2SFreddy Xin } 1000e2ca90c2SFreddy Xin 1001a88c32aeSMing Lei /* max qlen depend on hard_mtu and rx_urb_size */ 1002a88c32aeSMing Lei usbnet_update_max_qlen(dev); 1003a88c32aeSMing Lei 1004e2ca90c2SFreddy Xin return 0; 1005e2ca90c2SFreddy Xin } 1006e2ca90c2SFreddy Xin 1007e2ca90c2SFreddy Xin static int ax88179_set_mac_addr(struct net_device *net, void *p) 1008e2ca90c2SFreddy Xin { 1009e2ca90c2SFreddy Xin struct usbnet *dev = netdev_priv(net); 1010e2ca90c2SFreddy Xin struct sockaddr *addr = p; 101195ff8868SIan Morgan int ret; 1012e2ca90c2SFreddy Xin 1013e2ca90c2SFreddy Xin if (netif_running(net)) 1014e2ca90c2SFreddy Xin return -EBUSY; 1015e2ca90c2SFreddy Xin if (!is_valid_ether_addr(addr->sa_data)) 1016e2ca90c2SFreddy Xin return -EADDRNOTAVAIL; 1017e2ca90c2SFreddy Xin 1018e2ca90c2SFreddy Xin memcpy(net->dev_addr, addr->sa_data, ETH_ALEN); 1019e2ca90c2SFreddy Xin 1020e2ca90c2SFreddy Xin /* Set the MAC address */ 102195ff8868SIan Morgan ret = ax88179_write_cmd(dev, AX_ACCESS_MAC, AX_NODE_ID, ETH_ALEN, 1022e2ca90c2SFreddy Xin ETH_ALEN, net->dev_addr); 102395ff8868SIan Morgan if (ret < 0) 102495ff8868SIan Morgan return ret; 102595ff8868SIan Morgan 102695ff8868SIan Morgan return 0; 1027e2ca90c2SFreddy Xin } 1028e2ca90c2SFreddy Xin 1029e2ca90c2SFreddy Xin static const struct net_device_ops ax88179_netdev_ops = { 1030e2ca90c2SFreddy Xin .ndo_open = usbnet_open, 1031e2ca90c2SFreddy Xin .ndo_stop = usbnet_stop, 1032e2ca90c2SFreddy Xin .ndo_start_xmit = usbnet_start_xmit, 1033e2ca90c2SFreddy Xin .ndo_tx_timeout = usbnet_tx_timeout, 1034c8b5d129SGreg Ungerer .ndo_get_stats64 = usbnet_get_stats64, 1035e2ca90c2SFreddy Xin .ndo_change_mtu = ax88179_change_mtu, 1036e2ca90c2SFreddy Xin .ndo_set_mac_address = ax88179_set_mac_addr, 1037e2ca90c2SFreddy Xin .ndo_validate_addr = eth_validate_addr, 1038e2ca90c2SFreddy Xin .ndo_do_ioctl = ax88179_ioctl, 1039e2ca90c2SFreddy Xin .ndo_set_rx_mode = ax88179_set_multicast, 1040e2ca90c2SFreddy Xin .ndo_set_features = ax88179_set_features, 1041e2ca90c2SFreddy Xin }; 1042e2ca90c2SFreddy Xin 1043e2ca90c2SFreddy Xin static int ax88179_check_eeprom(struct usbnet *dev) 1044e2ca90c2SFreddy Xin { 1045e2ca90c2SFreddy Xin u8 i, buf, eeprom[20]; 1046e2ca90c2SFreddy Xin u16 csum, delay = HZ / 10; 1047e2ca90c2SFreddy Xin unsigned long jtimeout; 1048e2ca90c2SFreddy Xin 1049e2ca90c2SFreddy Xin /* Read EEPROM content */ 1050e2ca90c2SFreddy Xin for (i = 0; i < 6; i++) { 1051e2ca90c2SFreddy Xin buf = i; 1052e2ca90c2SFreddy Xin if (ax88179_write_cmd(dev, AX_ACCESS_MAC, AX_SROM_ADDR, 1053e2ca90c2SFreddy Xin 1, 1, &buf) < 0) 1054e2ca90c2SFreddy Xin return -EINVAL; 1055e2ca90c2SFreddy Xin 1056e2ca90c2SFreddy Xin buf = EEP_RD; 1057e2ca90c2SFreddy Xin if (ax88179_write_cmd(dev, AX_ACCESS_MAC, AX_SROM_CMD, 1058e2ca90c2SFreddy Xin 1, 1, &buf) < 0) 1059e2ca90c2SFreddy Xin return -EINVAL; 1060e2ca90c2SFreddy Xin 1061e2ca90c2SFreddy Xin jtimeout = jiffies + delay; 1062e2ca90c2SFreddy Xin do { 1063e2ca90c2SFreddy Xin ax88179_read_cmd(dev, AX_ACCESS_MAC, AX_SROM_CMD, 1064e2ca90c2SFreddy Xin 1, 1, &buf); 1065e2ca90c2SFreddy Xin 1066e2ca90c2SFreddy Xin if (time_after(jiffies, jtimeout)) 1067e2ca90c2SFreddy Xin return -EINVAL; 1068e2ca90c2SFreddy Xin 1069e2ca90c2SFreddy Xin } while (buf & EEP_BUSY); 1070e2ca90c2SFreddy Xin 1071e2ca90c2SFreddy Xin __ax88179_read_cmd(dev, AX_ACCESS_MAC, AX_SROM_DATA_LOW, 1072e2ca90c2SFreddy Xin 2, 2, &eeprom[i * 2], 0); 1073e2ca90c2SFreddy Xin 1074e2ca90c2SFreddy Xin if ((i == 0) && (eeprom[0] == 0xFF)) 1075e2ca90c2SFreddy Xin return -EINVAL; 1076e2ca90c2SFreddy Xin } 1077e2ca90c2SFreddy Xin 1078e2ca90c2SFreddy Xin csum = eeprom[6] + eeprom[7] + eeprom[8] + eeprom[9]; 1079e2ca90c2SFreddy Xin csum = (csum >> 8) + (csum & 0xff); 1080e2ca90c2SFreddy Xin if ((csum + eeprom[10]) != 0xff) 1081e2ca90c2SFreddy Xin return -EINVAL; 1082e2ca90c2SFreddy Xin 1083e2ca90c2SFreddy Xin return 0; 1084e2ca90c2SFreddy Xin } 1085e2ca90c2SFreddy Xin 1086e2ca90c2SFreddy Xin static int ax88179_check_efuse(struct usbnet *dev, u16 *ledmode) 1087e2ca90c2SFreddy Xin { 1088e2ca90c2SFreddy Xin u8 i; 1089e2ca90c2SFreddy Xin u8 efuse[64]; 1090e2ca90c2SFreddy Xin u16 csum = 0; 1091e2ca90c2SFreddy Xin 1092e2ca90c2SFreddy Xin if (ax88179_read_cmd(dev, AX_ACCESS_EFUS, 0, 64, 64, efuse) < 0) 1093e2ca90c2SFreddy Xin return -EINVAL; 1094e2ca90c2SFreddy Xin 1095e2ca90c2SFreddy Xin if (*efuse == 0xFF) 1096e2ca90c2SFreddy Xin return -EINVAL; 1097e2ca90c2SFreddy Xin 1098e2ca90c2SFreddy Xin for (i = 0; i < 64; i++) 1099e2ca90c2SFreddy Xin csum = csum + efuse[i]; 1100e2ca90c2SFreddy Xin 1101e2ca90c2SFreddy Xin while (csum > 255) 1102e2ca90c2SFreddy Xin csum = (csum & 0x00FF) + ((csum >> 8) & 0x00FF); 1103e2ca90c2SFreddy Xin 1104e2ca90c2SFreddy Xin if (csum != 0xFF) 1105e2ca90c2SFreddy Xin return -EINVAL; 1106e2ca90c2SFreddy Xin 1107e2ca90c2SFreddy Xin *ledmode = (efuse[51] << 8) | efuse[52]; 1108e2ca90c2SFreddy Xin 1109e2ca90c2SFreddy Xin return 0; 1110e2ca90c2SFreddy Xin } 1111e2ca90c2SFreddy Xin 1112e2ca90c2SFreddy Xin static int ax88179_convert_old_led(struct usbnet *dev, u16 *ledvalue) 1113e2ca90c2SFreddy Xin { 1114e2ca90c2SFreddy Xin u16 led; 1115e2ca90c2SFreddy Xin 1116e2ca90c2SFreddy Xin /* Loaded the old eFuse LED Mode */ 1117e2ca90c2SFreddy Xin if (ax88179_read_cmd(dev, AX_ACCESS_EEPROM, 0x3C, 1, 2, &led) < 0) 1118e2ca90c2SFreddy Xin return -EINVAL; 1119e2ca90c2SFreddy Xin 1120e2ca90c2SFreddy Xin led >>= 8; 1121e2ca90c2SFreddy Xin switch (led) { 1122e2ca90c2SFreddy Xin case 0xFF: 1123e2ca90c2SFreddy Xin led = LED0_ACTIVE | LED1_LINK_10 | LED1_LINK_100 | 1124e2ca90c2SFreddy Xin LED1_LINK_1000 | LED2_ACTIVE | LED2_LINK_10 | 1125e2ca90c2SFreddy Xin LED2_LINK_100 | LED2_LINK_1000 | LED_VALID; 1126e2ca90c2SFreddy Xin break; 1127e2ca90c2SFreddy Xin case 0xFE: 1128e2ca90c2SFreddy Xin led = LED0_ACTIVE | LED1_LINK_1000 | LED2_LINK_100 | LED_VALID; 1129e2ca90c2SFreddy Xin break; 1130e2ca90c2SFreddy Xin case 0xFD: 1131e2ca90c2SFreddy Xin led = LED0_ACTIVE | LED1_LINK_1000 | LED2_LINK_100 | 1132e2ca90c2SFreddy Xin LED2_LINK_10 | LED_VALID; 1133e2ca90c2SFreddy Xin break; 1134e2ca90c2SFreddy Xin case 0xFC: 1135e2ca90c2SFreddy Xin led = LED0_ACTIVE | LED1_ACTIVE | LED1_LINK_1000 | LED2_ACTIVE | 1136e2ca90c2SFreddy Xin LED2_LINK_100 | LED2_LINK_10 | LED_VALID; 1137e2ca90c2SFreddy Xin break; 1138e2ca90c2SFreddy Xin default: 1139e2ca90c2SFreddy Xin led = LED0_ACTIVE | LED1_LINK_10 | LED1_LINK_100 | 1140e2ca90c2SFreddy Xin LED1_LINK_1000 | LED2_ACTIVE | LED2_LINK_10 | 1141e2ca90c2SFreddy Xin LED2_LINK_100 | LED2_LINK_1000 | LED_VALID; 1142e2ca90c2SFreddy Xin break; 1143e2ca90c2SFreddy Xin } 1144e2ca90c2SFreddy Xin 1145e2ca90c2SFreddy Xin *ledvalue = led; 1146e2ca90c2SFreddy Xin 1147e2ca90c2SFreddy Xin return 0; 1148e2ca90c2SFreddy Xin } 1149e2ca90c2SFreddy Xin 1150e2ca90c2SFreddy Xin static int ax88179_led_setting(struct usbnet *dev) 1151e2ca90c2SFreddy Xin { 1152e2ca90c2SFreddy Xin u8 ledfd, value = 0; 1153e2ca90c2SFreddy Xin u16 tmp, ledact, ledlink, ledvalue = 0, delay = HZ / 10; 1154e2ca90c2SFreddy Xin unsigned long jtimeout; 1155e2ca90c2SFreddy Xin 1156e2ca90c2SFreddy Xin /* Check AX88179 version. UA1 or UA2*/ 1157e2ca90c2SFreddy Xin ax88179_read_cmd(dev, AX_ACCESS_MAC, GENERAL_STATUS, 1, 1, &value); 1158e2ca90c2SFreddy Xin 1159e2ca90c2SFreddy Xin if (!(value & AX_SECLD)) { /* UA1 */ 1160e2ca90c2SFreddy Xin value = AX_GPIO_CTRL_GPIO3EN | AX_GPIO_CTRL_GPIO2EN | 1161e2ca90c2SFreddy Xin AX_GPIO_CTRL_GPIO1EN; 1162e2ca90c2SFreddy Xin if (ax88179_write_cmd(dev, AX_ACCESS_MAC, AX_GPIO_CTRL, 1163e2ca90c2SFreddy Xin 1, 1, &value) < 0) 1164e2ca90c2SFreddy Xin return -EINVAL; 1165e2ca90c2SFreddy Xin } 1166e2ca90c2SFreddy Xin 1167e2ca90c2SFreddy Xin /* Check EEPROM */ 1168e2ca90c2SFreddy Xin if (!ax88179_check_eeprom(dev)) { 1169e2ca90c2SFreddy Xin value = 0x42; 1170e2ca90c2SFreddy Xin if (ax88179_write_cmd(dev, AX_ACCESS_MAC, AX_SROM_ADDR, 1171e2ca90c2SFreddy Xin 1, 1, &value) < 0) 1172e2ca90c2SFreddy Xin return -EINVAL; 1173e2ca90c2SFreddy Xin 1174e2ca90c2SFreddy Xin value = EEP_RD; 1175e2ca90c2SFreddy Xin if (ax88179_write_cmd(dev, AX_ACCESS_MAC, AX_SROM_CMD, 1176e2ca90c2SFreddy Xin 1, 1, &value) < 0) 1177e2ca90c2SFreddy Xin return -EINVAL; 1178e2ca90c2SFreddy Xin 1179e2ca90c2SFreddy Xin jtimeout = jiffies + delay; 1180e2ca90c2SFreddy Xin do { 1181e2ca90c2SFreddy Xin ax88179_read_cmd(dev, AX_ACCESS_MAC, AX_SROM_CMD, 1182e2ca90c2SFreddy Xin 1, 1, &value); 1183e2ca90c2SFreddy Xin 1184e2ca90c2SFreddy Xin if (time_after(jiffies, jtimeout)) 1185e2ca90c2SFreddy Xin return -EINVAL; 1186e2ca90c2SFreddy Xin 1187e2ca90c2SFreddy Xin } while (value & EEP_BUSY); 1188e2ca90c2SFreddy Xin 1189e2ca90c2SFreddy Xin ax88179_read_cmd(dev, AX_ACCESS_MAC, AX_SROM_DATA_HIGH, 1190e2ca90c2SFreddy Xin 1, 1, &value); 1191e2ca90c2SFreddy Xin ledvalue = (value << 8); 1192e2ca90c2SFreddy Xin 1193e2ca90c2SFreddy Xin ax88179_read_cmd(dev, AX_ACCESS_MAC, AX_SROM_DATA_LOW, 1194e2ca90c2SFreddy Xin 1, 1, &value); 1195e2ca90c2SFreddy Xin ledvalue |= value; 1196e2ca90c2SFreddy Xin 1197e2ca90c2SFreddy Xin /* load internal ROM for defaule setting */ 1198e2ca90c2SFreddy Xin if ((ledvalue == 0xFFFF) || ((ledvalue & LED_VALID) == 0)) 1199e2ca90c2SFreddy Xin ax88179_convert_old_led(dev, &ledvalue); 1200e2ca90c2SFreddy Xin 1201e2ca90c2SFreddy Xin } else if (!ax88179_check_efuse(dev, &ledvalue)) { 1202e2ca90c2SFreddy Xin if ((ledvalue == 0xFFFF) || ((ledvalue & LED_VALID) == 0)) 1203e2ca90c2SFreddy Xin ax88179_convert_old_led(dev, &ledvalue); 1204e2ca90c2SFreddy Xin } else { 1205e2ca90c2SFreddy Xin ax88179_convert_old_led(dev, &ledvalue); 1206e2ca90c2SFreddy Xin } 1207e2ca90c2SFreddy Xin 1208e2ca90c2SFreddy Xin tmp = GMII_PHY_PGSEL_EXT; 1209e2ca90c2SFreddy Xin ax88179_write_cmd(dev, AX_ACCESS_PHY, AX88179_PHY_ID, 1210e2ca90c2SFreddy Xin GMII_PHY_PAGE_SELECT, 2, &tmp); 1211e2ca90c2SFreddy Xin 1212e2ca90c2SFreddy Xin tmp = 0x2c; 1213e2ca90c2SFreddy Xin ax88179_write_cmd(dev, AX_ACCESS_PHY, AX88179_PHY_ID, 1214e2ca90c2SFreddy Xin GMII_PHYPAGE, 2, &tmp); 1215e2ca90c2SFreddy Xin 1216e2ca90c2SFreddy Xin ax88179_read_cmd(dev, AX_ACCESS_PHY, AX88179_PHY_ID, 1217e2ca90c2SFreddy Xin GMII_LED_ACT, 2, &ledact); 1218e2ca90c2SFreddy Xin 1219e2ca90c2SFreddy Xin ax88179_read_cmd(dev, AX_ACCESS_PHY, AX88179_PHY_ID, 1220e2ca90c2SFreddy Xin GMII_LED_LINK, 2, &ledlink); 1221e2ca90c2SFreddy Xin 1222e2ca90c2SFreddy Xin ledact &= GMII_LED_ACTIVE_MASK; 1223e2ca90c2SFreddy Xin ledlink &= GMII_LED_LINK_MASK; 1224e2ca90c2SFreddy Xin 1225e2ca90c2SFreddy Xin if (ledvalue & LED0_ACTIVE) 1226e2ca90c2SFreddy Xin ledact |= GMII_LED0_ACTIVE; 1227e2ca90c2SFreddy Xin 1228e2ca90c2SFreddy Xin if (ledvalue & LED1_ACTIVE) 1229e2ca90c2SFreddy Xin ledact |= GMII_LED1_ACTIVE; 1230e2ca90c2SFreddy Xin 1231e2ca90c2SFreddy Xin if (ledvalue & LED2_ACTIVE) 1232e2ca90c2SFreddy Xin ledact |= GMII_LED2_ACTIVE; 1233e2ca90c2SFreddy Xin 1234e2ca90c2SFreddy Xin if (ledvalue & LED0_LINK_10) 1235e2ca90c2SFreddy Xin ledlink |= GMII_LED0_LINK_10; 1236e2ca90c2SFreddy Xin 1237e2ca90c2SFreddy Xin if (ledvalue & LED1_LINK_10) 1238e2ca90c2SFreddy Xin ledlink |= GMII_LED1_LINK_10; 1239e2ca90c2SFreddy Xin 1240e2ca90c2SFreddy Xin if (ledvalue & LED2_LINK_10) 1241e2ca90c2SFreddy Xin ledlink |= GMII_LED2_LINK_10; 1242e2ca90c2SFreddy Xin 1243e2ca90c2SFreddy Xin if (ledvalue & LED0_LINK_100) 1244e2ca90c2SFreddy Xin ledlink |= GMII_LED0_LINK_100; 1245e2ca90c2SFreddy Xin 1246e2ca90c2SFreddy Xin if (ledvalue & LED1_LINK_100) 1247e2ca90c2SFreddy Xin ledlink |= GMII_LED1_LINK_100; 1248e2ca90c2SFreddy Xin 1249e2ca90c2SFreddy Xin if (ledvalue & LED2_LINK_100) 1250e2ca90c2SFreddy Xin ledlink |= GMII_LED2_LINK_100; 1251e2ca90c2SFreddy Xin 1252e2ca90c2SFreddy Xin if (ledvalue & LED0_LINK_1000) 1253e2ca90c2SFreddy Xin ledlink |= GMII_LED0_LINK_1000; 1254e2ca90c2SFreddy Xin 1255e2ca90c2SFreddy Xin if (ledvalue & LED1_LINK_1000) 1256e2ca90c2SFreddy Xin ledlink |= GMII_LED1_LINK_1000; 1257e2ca90c2SFreddy Xin 1258e2ca90c2SFreddy Xin if (ledvalue & LED2_LINK_1000) 1259e2ca90c2SFreddy Xin ledlink |= GMII_LED2_LINK_1000; 1260e2ca90c2SFreddy Xin 1261e2ca90c2SFreddy Xin tmp = ledact; 1262e2ca90c2SFreddy Xin ax88179_write_cmd(dev, AX_ACCESS_PHY, AX88179_PHY_ID, 1263e2ca90c2SFreddy Xin GMII_LED_ACT, 2, &tmp); 1264e2ca90c2SFreddy Xin 1265e2ca90c2SFreddy Xin tmp = ledlink; 1266e2ca90c2SFreddy Xin ax88179_write_cmd(dev, AX_ACCESS_PHY, AX88179_PHY_ID, 1267e2ca90c2SFreddy Xin GMII_LED_LINK, 2, &tmp); 1268e2ca90c2SFreddy Xin 1269e2ca90c2SFreddy Xin tmp = GMII_PHY_PGSEL_PAGE0; 1270e2ca90c2SFreddy Xin ax88179_write_cmd(dev, AX_ACCESS_PHY, AX88179_PHY_ID, 1271e2ca90c2SFreddy Xin GMII_PHY_PAGE_SELECT, 2, &tmp); 1272e2ca90c2SFreddy Xin 1273e2ca90c2SFreddy Xin /* LED full duplex setting */ 1274e2ca90c2SFreddy Xin ledfd = 0; 1275e2ca90c2SFreddy Xin if (ledvalue & LED0_FD) 1276e2ca90c2SFreddy Xin ledfd |= 0x01; 1277e2ca90c2SFreddy Xin else if ((ledvalue & LED0_USB3_MASK) == 0) 1278e2ca90c2SFreddy Xin ledfd |= 0x02; 1279e2ca90c2SFreddy Xin 1280e2ca90c2SFreddy Xin if (ledvalue & LED1_FD) 1281e2ca90c2SFreddy Xin ledfd |= 0x04; 1282e2ca90c2SFreddy Xin else if ((ledvalue & LED1_USB3_MASK) == 0) 1283e2ca90c2SFreddy Xin ledfd |= 0x08; 1284e2ca90c2SFreddy Xin 1285e2ca90c2SFreddy Xin if (ledvalue & LED2_FD) 1286e2ca90c2SFreddy Xin ledfd |= 0x10; 1287e2ca90c2SFreddy Xin else if ((ledvalue & LED2_USB3_MASK) == 0) 1288e2ca90c2SFreddy Xin ledfd |= 0x20; 1289e2ca90c2SFreddy Xin 1290e2ca90c2SFreddy Xin ax88179_write_cmd(dev, AX_ACCESS_MAC, AX_LEDCTRL, 1, 1, &ledfd); 1291e2ca90c2SFreddy Xin 1292e2ca90c2SFreddy Xin return 0; 1293e2ca90c2SFreddy Xin } 1294e2ca90c2SFreddy Xin 12959fb137aeSPeter Fink static void ax88179_get_mac_addr(struct usbnet *dev) 12969fb137aeSPeter Fink { 12979fb137aeSPeter Fink u8 mac[ETH_ALEN]; 12989fb137aeSPeter Fink 12999fb137aeSPeter Fink /* Maybe the boot loader passed the MAC address via device tree */ 13009fb137aeSPeter Fink if (!eth_platform_get_mac_address(&dev->udev->dev, mac)) { 13019fb137aeSPeter Fink netif_dbg(dev, ifup, dev->net, 13029fb137aeSPeter Fink "MAC address read from device tree"); 13039fb137aeSPeter Fink } else { 13049fb137aeSPeter Fink ax88179_read_cmd(dev, AX_ACCESS_MAC, AX_NODE_ID, ETH_ALEN, 13059fb137aeSPeter Fink ETH_ALEN, mac); 13069fb137aeSPeter Fink netif_dbg(dev, ifup, dev->net, 13079fb137aeSPeter Fink "MAC address read from ASIX chip"); 13089fb137aeSPeter Fink } 13099fb137aeSPeter Fink 13109fb137aeSPeter Fink if (is_valid_ether_addr(mac)) { 13119fb137aeSPeter Fink memcpy(dev->net->dev_addr, mac, ETH_ALEN); 13129fb137aeSPeter Fink } else { 13139fb137aeSPeter Fink netdev_info(dev->net, "invalid MAC address, using random\n"); 13149fb137aeSPeter Fink eth_hw_addr_random(dev->net); 13159fb137aeSPeter Fink } 13161635520aSPeter Fink 13171635520aSPeter Fink ax88179_write_cmd(dev, AX_ACCESS_MAC, AX_NODE_ID, ETH_ALEN, ETH_ALEN, 13181635520aSPeter Fink dev->net->dev_addr); 13199fb137aeSPeter Fink } 13209fb137aeSPeter Fink 1321c0725502SDavid S. Miller static int ax88179_bind(struct usbnet *dev, struct usb_interface *intf) 1322e2ca90c2SFreddy Xin { 1323e2ca90c2SFreddy Xin u8 buf[5]; 1324e2ca90c2SFreddy Xin u16 *tmp16; 1325e2ca90c2SFreddy Xin u8 *tmp; 1326e2ca90c2SFreddy Xin struct ax88179_data *ax179_data = (struct ax88179_data *)dev->data; 1327e98d69baSFreddy Xin struct ethtool_eee eee_data; 1328e2ca90c2SFreddy Xin 1329c0725502SDavid S. Miller usbnet_get_endpoints(dev, intf); 1330c0725502SDavid S. Miller 1331e2ca90c2SFreddy Xin tmp16 = (u16 *)buf; 1332e2ca90c2SFreddy Xin tmp = (u8 *)buf; 1333e2ca90c2SFreddy Xin 1334e2ca90c2SFreddy Xin memset(ax179_data, 0, sizeof(*ax179_data)); 1335e2ca90c2SFreddy Xin 1336e2ca90c2SFreddy Xin /* Power up ethernet PHY */ 1337e2ca90c2SFreddy Xin *tmp16 = 0; 1338e2ca90c2SFreddy Xin ax88179_write_cmd(dev, AX_ACCESS_MAC, AX_PHYPWR_RSTCTL, 2, 2, tmp16); 1339e2ca90c2SFreddy Xin *tmp16 = AX_PHYPWR_RSTCTL_IPRL; 1340e2ca90c2SFreddy Xin ax88179_write_cmd(dev, AX_ACCESS_MAC, AX_PHYPWR_RSTCTL, 2, 2, tmp16); 1341e2ca90c2SFreddy Xin msleep(200); 1342e2ca90c2SFreddy Xin 1343e2ca90c2SFreddy Xin *tmp = AX_CLK_SELECT_ACS | AX_CLK_SELECT_BCS; 1344e2ca90c2SFreddy Xin ax88179_write_cmd(dev, AX_ACCESS_MAC, AX_CLK_SELECT, 1, 1, tmp); 1345e2ca90c2SFreddy Xin msleep(100); 1346e2ca90c2SFreddy Xin 13479fb137aeSPeter Fink /* Read MAC address from DTB or asix chip */ 13489fb137aeSPeter Fink ax88179_get_mac_addr(dev); 1349e2ca90c2SFreddy Xin memcpy(dev->net->perm_addr, dev->net->dev_addr, ETH_ALEN); 1350e2ca90c2SFreddy Xin 1351e2ca90c2SFreddy Xin /* RX bulk configuration */ 1352e2ca90c2SFreddy Xin memcpy(tmp, &AX88179_BULKIN_SIZE[0], 5); 1353e2ca90c2SFreddy Xin ax88179_write_cmd(dev, AX_ACCESS_MAC, AX_RX_BULKIN_QCTRL, 5, 5, tmp); 1354e2ca90c2SFreddy Xin 1355e2ca90c2SFreddy Xin dev->rx_urb_size = 1024 * 20; 1356e2ca90c2SFreddy Xin 1357e2ca90c2SFreddy Xin *tmp = 0x34; 1358e2ca90c2SFreddy Xin ax88179_write_cmd(dev, AX_ACCESS_MAC, AX_PAUSE_WATERLVL_LOW, 1, 1, tmp); 1359e2ca90c2SFreddy Xin 1360e2ca90c2SFreddy Xin *tmp = 0x52; 1361e2ca90c2SFreddy Xin ax88179_write_cmd(dev, AX_ACCESS_MAC, AX_PAUSE_WATERLVL_HIGH, 1362e2ca90c2SFreddy Xin 1, 1, tmp); 1363e2ca90c2SFreddy Xin 1364e2ca90c2SFreddy Xin dev->net->netdev_ops = &ax88179_netdev_ops; 1365e2ca90c2SFreddy Xin dev->net->ethtool_ops = &ax88179_ethtool_ops; 1366e2ca90c2SFreddy Xin dev->net->needed_headroom = 8; 1367f77f0aeeSJarod Wilson dev->net->max_mtu = 4088; 1368e2ca90c2SFreddy Xin 1369e2ca90c2SFreddy Xin /* Initialize MII structure */ 1370e2ca90c2SFreddy Xin dev->mii.dev = dev->net; 1371e2ca90c2SFreddy Xin dev->mii.mdio_read = ax88179_mdio_read; 1372e2ca90c2SFreddy Xin dev->mii.mdio_write = ax88179_mdio_write; 1373e2ca90c2SFreddy Xin dev->mii.phy_id_mask = 0xff; 1374e2ca90c2SFreddy Xin dev->mii.reg_num_mask = 0xff; 1375e2ca90c2SFreddy Xin dev->mii.phy_id = 0x03; 1376e2ca90c2SFreddy Xin dev->mii.supports_gmii = 1; 1377e2ca90c2SFreddy Xin 1378e2ca90c2SFreddy Xin dev->net->features |= NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM | 137920f01703SEric Dumazet NETIF_F_RXCSUM; 1380e2ca90c2SFreddy Xin 1381e2ca90c2SFreddy Xin dev->net->hw_features |= NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM | 138220f01703SEric Dumazet NETIF_F_RXCSUM; 1383e2ca90c2SFreddy Xin 1384e2ca90c2SFreddy Xin /* Enable checksum offload */ 1385e2ca90c2SFreddy Xin *tmp = AX_RXCOE_IP | AX_RXCOE_TCP | AX_RXCOE_UDP | 1386e2ca90c2SFreddy Xin AX_RXCOE_TCPV6 | AX_RXCOE_UDPV6; 1387e2ca90c2SFreddy Xin ax88179_write_cmd(dev, AX_ACCESS_MAC, AX_RXCOE_CTL, 1, 1, tmp); 1388e2ca90c2SFreddy Xin 1389e2ca90c2SFreddy Xin *tmp = AX_TXCOE_IP | AX_TXCOE_TCP | AX_TXCOE_UDP | 1390e2ca90c2SFreddy Xin AX_TXCOE_TCPV6 | AX_TXCOE_UDPV6; 1391e2ca90c2SFreddy Xin ax88179_write_cmd(dev, AX_ACCESS_MAC, AX_TXCOE_CTL, 1, 1, tmp); 1392e2ca90c2SFreddy Xin 1393e2ca90c2SFreddy Xin /* Configure RX control register => start operation */ 1394e2ca90c2SFreddy Xin *tmp16 = AX_RX_CTL_DROPCRCERR | AX_RX_CTL_IPE | AX_RX_CTL_START | 1395e2ca90c2SFreddy Xin AX_RX_CTL_AP | AX_RX_CTL_AMALL | AX_RX_CTL_AB; 1396e2ca90c2SFreddy Xin ax88179_write_cmd(dev, AX_ACCESS_MAC, AX_RX_CTL, 2, 2, tmp16); 1397e2ca90c2SFreddy Xin 1398e2ca90c2SFreddy Xin *tmp = AX_MONITOR_MODE_PMETYPE | AX_MONITOR_MODE_PMEPOL | 1399e2ca90c2SFreddy Xin AX_MONITOR_MODE_RWMP; 1400e2ca90c2SFreddy Xin ax88179_write_cmd(dev, AX_ACCESS_MAC, AX_MONITOR_MOD, 1, 1, tmp); 1401e2ca90c2SFreddy Xin 1402e2ca90c2SFreddy Xin /* Configure default medium type => giga */ 1403e2ca90c2SFreddy Xin *tmp16 = AX_MEDIUM_RECEIVE_EN | AX_MEDIUM_TXFLOW_CTRLEN | 14044c8e84b2SFreddy Xin AX_MEDIUM_RXFLOW_CTRLEN | AX_MEDIUM_FULL_DUPLEX | 14054c8e84b2SFreddy Xin AX_MEDIUM_GIGAMODE; 1406e2ca90c2SFreddy Xin ax88179_write_cmd(dev, AX_ACCESS_MAC, AX_MEDIUM_STATUS_MODE, 1407e2ca90c2SFreddy Xin 2, 2, tmp16); 1408e2ca90c2SFreddy Xin 1409e2ca90c2SFreddy Xin ax88179_led_setting(dev); 1410e2ca90c2SFreddy Xin 1411e98d69baSFreddy Xin ax179_data->eee_enabled = 0; 1412e98d69baSFreddy Xin ax179_data->eee_active = 0; 1413e98d69baSFreddy Xin 1414e98d69baSFreddy Xin ax88179_disable_eee(dev); 1415e98d69baSFreddy Xin 1416e98d69baSFreddy Xin ax88179_ethtool_get_eee(dev, &eee_data); 1417e98d69baSFreddy Xin eee_data.advertised = 0; 1418e98d69baSFreddy Xin ax88179_ethtool_set_eee(dev, &eee_data); 1419e98d69baSFreddy Xin 1420e2ca90c2SFreddy Xin /* Restart autoneg */ 1421e2ca90c2SFreddy Xin mii_nway_restart(&dev->mii); 1422e2ca90c2SFreddy Xin 14237a97856eSMing Lei usbnet_link_change(dev, 0, 0); 1424e2ca90c2SFreddy Xin 1425e2ca90c2SFreddy Xin return 0; 1426e2ca90c2SFreddy Xin } 1427e2ca90c2SFreddy Xin 1428e2ca90c2SFreddy Xin static void ax88179_unbind(struct usbnet *dev, struct usb_interface *intf) 1429e2ca90c2SFreddy Xin { 1430e2ca90c2SFreddy Xin u16 tmp16; 1431e2ca90c2SFreddy Xin 1432e2ca90c2SFreddy Xin /* Configure RX control register => stop operation */ 1433e2ca90c2SFreddy Xin tmp16 = AX_RX_CTL_STOP; 1434e2ca90c2SFreddy Xin ax88179_write_cmd(dev, AX_ACCESS_MAC, AX_RX_CTL, 2, 2, &tmp16); 1435e2ca90c2SFreddy Xin 1436e2ca90c2SFreddy Xin tmp16 = 0; 1437e2ca90c2SFreddy Xin ax88179_write_cmd(dev, AX_ACCESS_MAC, AX_CLK_SELECT, 1, 1, &tmp16); 1438e2ca90c2SFreddy Xin 1439e2ca90c2SFreddy Xin /* Power down ethernet PHY */ 1440e2ca90c2SFreddy Xin tmp16 = 0; 1441e2ca90c2SFreddy Xin ax88179_write_cmd(dev, AX_ACCESS_MAC, AX_PHYPWR_RSTCTL, 2, 2, &tmp16); 1442e2ca90c2SFreddy Xin } 1443e2ca90c2SFreddy Xin 1444e2ca90c2SFreddy Xin static void 1445e2ca90c2SFreddy Xin ax88179_rx_checksum(struct sk_buff *skb, u32 *pkt_hdr) 1446e2ca90c2SFreddy Xin { 1447e2ca90c2SFreddy Xin skb->ip_summed = CHECKSUM_NONE; 1448e2ca90c2SFreddy Xin 1449e2ca90c2SFreddy Xin /* checksum error bit is set */ 1450e2ca90c2SFreddy Xin if ((*pkt_hdr & AX_RXHDR_L3CSUM_ERR) || 1451e2ca90c2SFreddy Xin (*pkt_hdr & AX_RXHDR_L4CSUM_ERR)) 1452e2ca90c2SFreddy Xin return; 1453e2ca90c2SFreddy Xin 1454e2ca90c2SFreddy Xin /* It must be a TCP or UDP packet with a valid checksum */ 1455e2ca90c2SFreddy Xin if (((*pkt_hdr & AX_RXHDR_L4_TYPE_MASK) == AX_RXHDR_L4_TYPE_TCP) || 1456e2ca90c2SFreddy Xin ((*pkt_hdr & AX_RXHDR_L4_TYPE_MASK) == AX_RXHDR_L4_TYPE_UDP)) 1457e2ca90c2SFreddy Xin skb->ip_summed = CHECKSUM_UNNECESSARY; 1458e2ca90c2SFreddy Xin } 1459e2ca90c2SFreddy Xin 1460e2ca90c2SFreddy Xin static int ax88179_rx_fixup(struct usbnet *dev, struct sk_buff *skb) 1461e2ca90c2SFreddy Xin { 1462e2ca90c2SFreddy Xin struct sk_buff *ax_skb; 1463e2ca90c2SFreddy Xin int pkt_cnt; 1464e2ca90c2SFreddy Xin u32 rx_hdr; 1465e2ca90c2SFreddy Xin u16 hdr_off; 1466e2ca90c2SFreddy Xin u32 *pkt_hdr; 1467e2ca90c2SFreddy Xin 1468eb85569fSEmil Goode /* This check is no longer done by usbnet */ 1469eb85569fSEmil Goode if (skb->len < dev->net->hard_header_len) 1470eb85569fSEmil Goode return 0; 1471eb85569fSEmil Goode 1472e2ca90c2SFreddy Xin skb_trim(skb, skb->len - 4); 1473d1854d50SChuhong Yuan rx_hdr = get_unaligned_le32(skb_tail_pointer(skb)); 1474e2ca90c2SFreddy Xin 1475e2ca90c2SFreddy Xin pkt_cnt = (u16)rx_hdr; 1476e2ca90c2SFreddy Xin hdr_off = (u16)(rx_hdr >> 16); 1477e2ca90c2SFreddy Xin pkt_hdr = (u32 *)(skb->data + hdr_off); 1478e2ca90c2SFreddy Xin 1479e2ca90c2SFreddy Xin while (pkt_cnt--) { 1480e2ca90c2SFreddy Xin u16 pkt_len; 1481e2ca90c2SFreddy Xin 1482e2ca90c2SFreddy Xin le32_to_cpus(pkt_hdr); 1483e2ca90c2SFreddy Xin pkt_len = (*pkt_hdr >> 16) & 0x1fff; 1484e2ca90c2SFreddy Xin 1485e2ca90c2SFreddy Xin /* Check CRC or runt packet */ 1486e2ca90c2SFreddy Xin if ((*pkt_hdr & AX_RXHDR_CRC_ERR) || 1487e2ca90c2SFreddy Xin (*pkt_hdr & AX_RXHDR_DROP_ERR)) { 1488e2ca90c2SFreddy Xin skb_pull(skb, (pkt_len + 7) & 0xFFF8); 1489e2ca90c2SFreddy Xin pkt_hdr++; 1490e2ca90c2SFreddy Xin continue; 1491e2ca90c2SFreddy Xin } 1492e2ca90c2SFreddy Xin 1493e2ca90c2SFreddy Xin if (pkt_cnt == 0) { 1494e2ca90c2SFreddy Xin skb->len = pkt_len; 1495e869e7a1SJeremy Kerr /* Skip IP alignment pseudo header */ 1496e869e7a1SJeremy Kerr skb_pull(skb, 2); 1497e869e7a1SJeremy Kerr skb_set_tail_pointer(skb, skb->len); 1498e2ca90c2SFreddy Xin skb->truesize = pkt_len + sizeof(struct sk_buff); 1499e2ca90c2SFreddy Xin ax88179_rx_checksum(skb, pkt_hdr); 1500e2ca90c2SFreddy Xin return 1; 1501e2ca90c2SFreddy Xin } 1502e2ca90c2SFreddy Xin 1503e2ca90c2SFreddy Xin ax_skb = skb_clone(skb, GFP_ATOMIC); 1504e2ca90c2SFreddy Xin if (ax_skb) { 1505e2ca90c2SFreddy Xin ax_skb->len = pkt_len; 1506e869e7a1SJeremy Kerr /* Skip IP alignment pseudo header */ 1507e869e7a1SJeremy Kerr skb_pull(ax_skb, 2); 1508e869e7a1SJeremy Kerr skb_set_tail_pointer(ax_skb, ax_skb->len); 1509e2ca90c2SFreddy Xin ax_skb->truesize = pkt_len + sizeof(struct sk_buff); 1510e2ca90c2SFreddy Xin ax88179_rx_checksum(ax_skb, pkt_hdr); 1511e2ca90c2SFreddy Xin usbnet_skb_return(dev, ax_skb); 1512e2ca90c2SFreddy Xin } else { 1513e2ca90c2SFreddy Xin return 0; 1514e2ca90c2SFreddy Xin } 1515e2ca90c2SFreddy Xin 1516e2ca90c2SFreddy Xin skb_pull(skb, (pkt_len + 7) & 0xFFF8); 1517e2ca90c2SFreddy Xin pkt_hdr++; 1518e2ca90c2SFreddy Xin } 1519e2ca90c2SFreddy Xin return 1; 1520e2ca90c2SFreddy Xin } 1521e2ca90c2SFreddy Xin 1522e2ca90c2SFreddy Xin static struct sk_buff * 1523e2ca90c2SFreddy Xin ax88179_tx_fixup(struct usbnet *dev, struct sk_buff *skb, gfp_t flags) 1524e2ca90c2SFreddy Xin { 1525e2ca90c2SFreddy Xin u32 tx_hdr1, tx_hdr2; 1526e2ca90c2SFreddy Xin int frame_size = dev->maxpacket; 1527e2ca90c2SFreddy Xin int mss = skb_shinfo(skb)->gso_size; 1528e2ca90c2SFreddy Xin int headroom; 15297e24b4edSChuhong Yuan void *ptr; 1530e2ca90c2SFreddy Xin 1531e2ca90c2SFreddy Xin tx_hdr1 = skb->len; 1532e2ca90c2SFreddy Xin tx_hdr2 = mss; 1533e2ca90c2SFreddy Xin if (((skb->len + 8) % frame_size) == 0) 1534e2ca90c2SFreddy Xin tx_hdr2 |= 0x80008000; /* Enable padding */ 1535e2ca90c2SFreddy Xin 1536f2707015SEric Dumazet headroom = skb_headroom(skb) - 8; 1537e2ca90c2SFreddy Xin 1538f2707015SEric Dumazet if ((skb_header_cloned(skb) || headroom < 0) && 1539f2707015SEric Dumazet pskb_expand_head(skb, headroom < 0 ? 8 : 0, 0, GFP_ATOMIC)) { 1540e2ca90c2SFreddy Xin dev_kfree_skb_any(skb); 1541e2ca90c2SFreddy Xin return NULL; 1542e2ca90c2SFreddy Xin } 1543e2ca90c2SFreddy Xin 15447e24b4edSChuhong Yuan ptr = skb_push(skb, 8); 15457e24b4edSChuhong Yuan put_unaligned_le32(tx_hdr1, ptr); 15467e24b4edSChuhong Yuan put_unaligned_le32(tx_hdr2, ptr + 4); 1547e2ca90c2SFreddy Xin 1548e2ca90c2SFreddy Xin return skb; 1549e2ca90c2SFreddy Xin } 1550e2ca90c2SFreddy Xin 1551e2ca90c2SFreddy Xin static int ax88179_link_reset(struct usbnet *dev) 1552e2ca90c2SFreddy Xin { 1553c0725502SDavid S. Miller struct ax88179_data *ax179_data = (struct ax88179_data *)dev->data; 1554c0725502SDavid S. Miller u8 tmp[5], link_sts; 1555c0725502SDavid S. Miller u16 mode, tmp16, delay = HZ / 10; 1556c0725502SDavid S. Miller u32 tmp32 = 0x40000000; 1557c0725502SDavid S. Miller unsigned long jtimeout; 1558c0725502SDavid S. Miller 1559c0725502SDavid S. Miller jtimeout = jiffies + delay; 1560c0725502SDavid S. Miller while (tmp32 & 0x40000000) { 1561c0725502SDavid S. Miller mode = 0; 1562c0725502SDavid S. Miller ax88179_write_cmd(dev, AX_ACCESS_MAC, AX_RX_CTL, 2, 2, &mode); 1563c0725502SDavid S. Miller ax88179_write_cmd(dev, AX_ACCESS_MAC, AX_RX_CTL, 2, 2, 1564c0725502SDavid S. Miller &ax179_data->rxctl); 1565c0725502SDavid S. Miller 1566c0725502SDavid S. Miller /*link up, check the usb device control TX FIFO full or empty*/ 1567c0725502SDavid S. Miller ax88179_read_cmd(dev, 0x81, 0x8c, 0, 4, &tmp32); 1568c0725502SDavid S. Miller 1569c0725502SDavid S. Miller if (time_after(jiffies, jtimeout)) 1570c0725502SDavid S. Miller return 0; 1571c0725502SDavid S. Miller } 1572c0725502SDavid S. Miller 1573c0725502SDavid S. Miller mode = AX_MEDIUM_RECEIVE_EN | AX_MEDIUM_TXFLOW_CTRLEN | 1574c0725502SDavid S. Miller AX_MEDIUM_RXFLOW_CTRLEN; 1575c0725502SDavid S. Miller 1576c0725502SDavid S. Miller ax88179_read_cmd(dev, AX_ACCESS_MAC, PHYSICAL_LINK_STATUS, 1577c0725502SDavid S. Miller 1, 1, &link_sts); 1578c0725502SDavid S. Miller 1579c0725502SDavid S. Miller ax88179_read_cmd(dev, AX_ACCESS_PHY, AX88179_PHY_ID, 1580c0725502SDavid S. Miller GMII_PHY_PHYSR, 2, &tmp16); 1581c0725502SDavid S. Miller 1582c0725502SDavid S. Miller if (!(tmp16 & GMII_PHY_PHYSR_LINK)) { 1583c0725502SDavid S. Miller return 0; 1584c0725502SDavid S. Miller } else if (GMII_PHY_PHYSR_GIGA == (tmp16 & GMII_PHY_PHYSR_SMASK)) { 1585c0725502SDavid S. Miller mode |= AX_MEDIUM_GIGAMODE | AX_MEDIUM_EN_125MHZ; 1586c0725502SDavid S. Miller if (dev->net->mtu > 1500) 1587c0725502SDavid S. Miller mode |= AX_MEDIUM_JUMBO_EN; 1588c0725502SDavid S. Miller 1589c0725502SDavid S. Miller if (link_sts & AX_USB_SS) 1590c0725502SDavid S. Miller memcpy(tmp, &AX88179_BULKIN_SIZE[0], 5); 1591c0725502SDavid S. Miller else if (link_sts & AX_USB_HS) 1592c0725502SDavid S. Miller memcpy(tmp, &AX88179_BULKIN_SIZE[1], 5); 1593c0725502SDavid S. Miller else 1594c0725502SDavid S. Miller memcpy(tmp, &AX88179_BULKIN_SIZE[3], 5); 1595c0725502SDavid S. Miller } else if (GMII_PHY_PHYSR_100 == (tmp16 & GMII_PHY_PHYSR_SMASK)) { 1596c0725502SDavid S. Miller mode |= AX_MEDIUM_PS; 1597c0725502SDavid S. Miller 1598c0725502SDavid S. Miller if (link_sts & (AX_USB_SS | AX_USB_HS)) 1599c0725502SDavid S. Miller memcpy(tmp, &AX88179_BULKIN_SIZE[2], 5); 1600c0725502SDavid S. Miller else 1601c0725502SDavid S. Miller memcpy(tmp, &AX88179_BULKIN_SIZE[3], 5); 1602c0725502SDavid S. Miller } else { 1603c0725502SDavid S. Miller memcpy(tmp, &AX88179_BULKIN_SIZE[3], 5); 1604c0725502SDavid S. Miller } 1605c0725502SDavid S. Miller 1606c0725502SDavid S. Miller /* RX bulk configuration */ 1607c0725502SDavid S. Miller ax88179_write_cmd(dev, AX_ACCESS_MAC, AX_RX_BULKIN_QCTRL, 5, 5, tmp); 1608c0725502SDavid S. Miller 1609c0725502SDavid S. Miller dev->rx_urb_size = (1024 * (tmp[3] + 2)); 1610c0725502SDavid S. Miller 1611c0725502SDavid S. Miller if (tmp16 & GMII_PHY_PHYSR_FULL) 1612c0725502SDavid S. Miller mode |= AX_MEDIUM_FULL_DUPLEX; 1613c0725502SDavid S. Miller ax88179_write_cmd(dev, AX_ACCESS_MAC, AX_MEDIUM_STATUS_MODE, 1614c0725502SDavid S. Miller 2, 2, &mode); 1615c0725502SDavid S. Miller 1616c0725502SDavid S. Miller ax179_data->eee_enabled = ax88179_chk_eee(dev); 1617c0725502SDavid S. Miller 1618c0725502SDavid S. Miller netif_carrier_on(dev->net); 1619c0725502SDavid S. Miller 1620c0725502SDavid S. Miller return 0; 1621e2ca90c2SFreddy Xin } 1622e2ca90c2SFreddy Xin 1623e2ca90c2SFreddy Xin static int ax88179_reset(struct usbnet *dev) 1624e2ca90c2SFreddy Xin { 1625e2ca90c2SFreddy Xin u8 buf[5]; 1626e2ca90c2SFreddy Xin u16 *tmp16; 1627e2ca90c2SFreddy Xin u8 *tmp; 1628e98d69baSFreddy Xin struct ax88179_data *ax179_data = (struct ax88179_data *)dev->data; 1629e98d69baSFreddy Xin struct ethtool_eee eee_data; 1630e2ca90c2SFreddy Xin 1631e2ca90c2SFreddy Xin tmp16 = (u16 *)buf; 1632e2ca90c2SFreddy Xin tmp = (u8 *)buf; 1633e2ca90c2SFreddy Xin 1634e2ca90c2SFreddy Xin /* Power up ethernet PHY */ 1635e2ca90c2SFreddy Xin *tmp16 = 0; 1636e2ca90c2SFreddy Xin ax88179_write_cmd(dev, AX_ACCESS_MAC, AX_PHYPWR_RSTCTL, 2, 2, tmp16); 1637e2ca90c2SFreddy Xin 1638e2ca90c2SFreddy Xin *tmp16 = AX_PHYPWR_RSTCTL_IPRL; 1639e2ca90c2SFreddy Xin ax88179_write_cmd(dev, AX_ACCESS_MAC, AX_PHYPWR_RSTCTL, 2, 2, tmp16); 1640e2ca90c2SFreddy Xin msleep(200); 1641e2ca90c2SFreddy Xin 1642e2ca90c2SFreddy Xin *tmp = AX_CLK_SELECT_ACS | AX_CLK_SELECT_BCS; 1643e2ca90c2SFreddy Xin ax88179_write_cmd(dev, AX_ACCESS_MAC, AX_CLK_SELECT, 1, 1, tmp); 1644e2ca90c2SFreddy Xin msleep(100); 1645e2ca90c2SFreddy Xin 1646e2ca90c2SFreddy Xin /* Ethernet PHY Auto Detach*/ 1647e2ca90c2SFreddy Xin ax88179_auto_detach(dev, 0); 1648e2ca90c2SFreddy Xin 16499fb137aeSPeter Fink /* Read MAC address from DTB or asix chip */ 16509fb137aeSPeter Fink ax88179_get_mac_addr(dev); 1651e2ca90c2SFreddy Xin 1652e2ca90c2SFreddy Xin /* RX bulk configuration */ 1653e2ca90c2SFreddy Xin memcpy(tmp, &AX88179_BULKIN_SIZE[0], 5); 1654e2ca90c2SFreddy Xin ax88179_write_cmd(dev, AX_ACCESS_MAC, AX_RX_BULKIN_QCTRL, 5, 5, tmp); 1655e2ca90c2SFreddy Xin 1656e2ca90c2SFreddy Xin dev->rx_urb_size = 1024 * 20; 1657e2ca90c2SFreddy Xin 1658e2ca90c2SFreddy Xin *tmp = 0x34; 1659e2ca90c2SFreddy Xin ax88179_write_cmd(dev, AX_ACCESS_MAC, AX_PAUSE_WATERLVL_LOW, 1, 1, tmp); 1660e2ca90c2SFreddy Xin 1661e2ca90c2SFreddy Xin *tmp = 0x52; 1662e2ca90c2SFreddy Xin ax88179_write_cmd(dev, AX_ACCESS_MAC, AX_PAUSE_WATERLVL_HIGH, 1663e2ca90c2SFreddy Xin 1, 1, tmp); 1664e2ca90c2SFreddy Xin 1665e2ca90c2SFreddy Xin dev->net->features |= NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM | 166620f01703SEric Dumazet NETIF_F_RXCSUM; 1667e2ca90c2SFreddy Xin 1668e2ca90c2SFreddy Xin dev->net->hw_features |= NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM | 166920f01703SEric Dumazet NETIF_F_RXCSUM; 1670e2ca90c2SFreddy Xin 1671e2ca90c2SFreddy Xin /* Enable checksum offload */ 1672e2ca90c2SFreddy Xin *tmp = AX_RXCOE_IP | AX_RXCOE_TCP | AX_RXCOE_UDP | 1673e2ca90c2SFreddy Xin AX_RXCOE_TCPV6 | AX_RXCOE_UDPV6; 1674e2ca90c2SFreddy Xin ax88179_write_cmd(dev, AX_ACCESS_MAC, AX_RXCOE_CTL, 1, 1, tmp); 1675e2ca90c2SFreddy Xin 1676e2ca90c2SFreddy Xin *tmp = AX_TXCOE_IP | AX_TXCOE_TCP | AX_TXCOE_UDP | 1677e2ca90c2SFreddy Xin AX_TXCOE_TCPV6 | AX_TXCOE_UDPV6; 1678e2ca90c2SFreddy Xin ax88179_write_cmd(dev, AX_ACCESS_MAC, AX_TXCOE_CTL, 1, 1, tmp); 1679e2ca90c2SFreddy Xin 1680e2ca90c2SFreddy Xin /* Configure RX control register => start operation */ 1681e2ca90c2SFreddy Xin *tmp16 = AX_RX_CTL_DROPCRCERR | AX_RX_CTL_IPE | AX_RX_CTL_START | 1682e2ca90c2SFreddy Xin AX_RX_CTL_AP | AX_RX_CTL_AMALL | AX_RX_CTL_AB; 1683e2ca90c2SFreddy Xin ax88179_write_cmd(dev, AX_ACCESS_MAC, AX_RX_CTL, 2, 2, tmp16); 1684e2ca90c2SFreddy Xin 1685e2ca90c2SFreddy Xin *tmp = AX_MONITOR_MODE_PMETYPE | AX_MONITOR_MODE_PMEPOL | 1686e2ca90c2SFreddy Xin AX_MONITOR_MODE_RWMP; 1687e2ca90c2SFreddy Xin ax88179_write_cmd(dev, AX_ACCESS_MAC, AX_MONITOR_MOD, 1, 1, tmp); 1688e2ca90c2SFreddy Xin 1689e2ca90c2SFreddy Xin /* Configure default medium type => giga */ 1690e2ca90c2SFreddy Xin *tmp16 = AX_MEDIUM_RECEIVE_EN | AX_MEDIUM_TXFLOW_CTRLEN | 16914c8e84b2SFreddy Xin AX_MEDIUM_RXFLOW_CTRLEN | AX_MEDIUM_FULL_DUPLEX | 16924c8e84b2SFreddy Xin AX_MEDIUM_GIGAMODE; 1693e2ca90c2SFreddy Xin ax88179_write_cmd(dev, AX_ACCESS_MAC, AX_MEDIUM_STATUS_MODE, 1694e2ca90c2SFreddy Xin 2, 2, tmp16); 1695e2ca90c2SFreddy Xin 1696e2ca90c2SFreddy Xin ax88179_led_setting(dev); 1697e2ca90c2SFreddy Xin 1698e98d69baSFreddy Xin ax179_data->eee_enabled = 0; 1699e98d69baSFreddy Xin ax179_data->eee_active = 0; 1700e98d69baSFreddy Xin 1701e98d69baSFreddy Xin ax88179_disable_eee(dev); 1702e98d69baSFreddy Xin 1703e98d69baSFreddy Xin ax88179_ethtool_get_eee(dev, &eee_data); 1704e98d69baSFreddy Xin eee_data.advertised = 0; 1705e98d69baSFreddy Xin ax88179_ethtool_set_eee(dev, &eee_data); 1706e98d69baSFreddy Xin 1707e2ca90c2SFreddy Xin /* Restart autoneg */ 1708e2ca90c2SFreddy Xin mii_nway_restart(&dev->mii); 1709e2ca90c2SFreddy Xin 17107a97856eSMing Lei usbnet_link_change(dev, 0, 0); 1711e2ca90c2SFreddy Xin 1712e2ca90c2SFreddy Xin return 0; 1713e2ca90c2SFreddy Xin } 1714e2ca90c2SFreddy Xin 1715e2ca90c2SFreddy Xin static int ax88179_stop(struct usbnet *dev) 1716e2ca90c2SFreddy Xin { 1717e2ca90c2SFreddy Xin u16 tmp16; 1718e2ca90c2SFreddy Xin 1719e2ca90c2SFreddy Xin ax88179_read_cmd(dev, AX_ACCESS_MAC, AX_MEDIUM_STATUS_MODE, 1720e2ca90c2SFreddy Xin 2, 2, &tmp16); 1721e2ca90c2SFreddy Xin tmp16 &= ~AX_MEDIUM_RECEIVE_EN; 1722e2ca90c2SFreddy Xin ax88179_write_cmd(dev, AX_ACCESS_MAC, AX_MEDIUM_STATUS_MODE, 1723e2ca90c2SFreddy Xin 2, 2, &tmp16); 1724e2ca90c2SFreddy Xin 1725e2ca90c2SFreddy Xin return 0; 1726e2ca90c2SFreddy Xin } 1727e2ca90c2SFreddy Xin 1728e2ca90c2SFreddy Xin static const struct driver_info ax88179_info = { 1729803dee95SDavid Chang .description = "ASIX AX88179 USB 3.0 Gigabit Ethernet", 1730e2ca90c2SFreddy Xin .bind = ax88179_bind, 1731e2ca90c2SFreddy Xin .unbind = ax88179_unbind, 1732e2ca90c2SFreddy Xin .status = ax88179_status, 1733e2ca90c2SFreddy Xin .link_reset = ax88179_link_reset, 1734e2ca90c2SFreddy Xin .reset = ax88179_reset, 1735e2ca90c2SFreddy Xin .stop = ax88179_stop, 1736e2ca90c2SFreddy Xin .flags = FLAG_ETHER | FLAG_FRAMING_AX, 1737e2ca90c2SFreddy Xin .rx_fixup = ax88179_rx_fixup, 1738e2ca90c2SFreddy Xin .tx_fixup = ax88179_tx_fixup, 1739e2ca90c2SFreddy Xin }; 1740e2ca90c2SFreddy Xin 1741e2ca90c2SFreddy Xin static const struct driver_info ax88178a_info = { 1742803dee95SDavid Chang .description = "ASIX AX88178A USB 2.0 Gigabit Ethernet", 1743e2ca90c2SFreddy Xin .bind = ax88179_bind, 1744e2ca90c2SFreddy Xin .unbind = ax88179_unbind, 1745e2ca90c2SFreddy Xin .status = ax88179_status, 1746e2ca90c2SFreddy Xin .link_reset = ax88179_link_reset, 1747e2ca90c2SFreddy Xin .reset = ax88179_reset, 1748e2ca90c2SFreddy Xin .stop = ax88179_stop, 1749e2ca90c2SFreddy Xin .flags = FLAG_ETHER | FLAG_FRAMING_AX, 1750e2ca90c2SFreddy Xin .rx_fixup = ax88179_rx_fixup, 1751e2ca90c2SFreddy Xin .tx_fixup = ax88179_tx_fixup, 1752e2ca90c2SFreddy Xin }; 1753e2ca90c2SFreddy Xin 17548da3cf2aSAllan Chou static const struct driver_info cypress_GX3_info = { 17558da3cf2aSAllan Chou .description = "Cypress GX3 SuperSpeed to Gigabit Ethernet Controller", 17568da3cf2aSAllan Chou .bind = ax88179_bind, 17578da3cf2aSAllan Chou .unbind = ax88179_unbind, 17588da3cf2aSAllan Chou .status = ax88179_status, 17598da3cf2aSAllan Chou .link_reset = ax88179_link_reset, 17608da3cf2aSAllan Chou .reset = ax88179_reset, 17618da3cf2aSAllan Chou .stop = ax88179_stop, 17628da3cf2aSAllan Chou .flags = FLAG_ETHER | FLAG_FRAMING_AX, 17638da3cf2aSAllan Chou .rx_fixup = ax88179_rx_fixup, 17648da3cf2aSAllan Chou .tx_fixup = ax88179_tx_fixup, 17658da3cf2aSAllan Chou }; 17668da3cf2aSAllan Chou 1767635d61a3SGerry Demaret static const struct driver_info dlink_dub1312_info = { 1768635d61a3SGerry Demaret .description = "D-Link DUB-1312 USB 3.0 to Gigabit Ethernet Adapter", 1769635d61a3SGerry Demaret .bind = ax88179_bind, 1770635d61a3SGerry Demaret .unbind = ax88179_unbind, 1771635d61a3SGerry Demaret .status = ax88179_status, 1772635d61a3SGerry Demaret .link_reset = ax88179_link_reset, 1773635d61a3SGerry Demaret .reset = ax88179_reset, 1774635d61a3SGerry Demaret .stop = ax88179_stop, 1775635d61a3SGerry Demaret .flags = FLAG_ETHER | FLAG_FRAMING_AX, 1776635d61a3SGerry Demaret .rx_fixup = ax88179_rx_fixup, 1777635d61a3SGerry Demaret .tx_fixup = ax88179_tx_fixup, 1778635d61a3SGerry Demaret }; 1779635d61a3SGerry Demaret 1780e2ca90c2SFreddy Xin static const struct driver_info sitecom_info = { 1781e2ca90c2SFreddy Xin .description = "Sitecom USB 3.0 to Gigabit Adapter", 1782e2ca90c2SFreddy Xin .bind = ax88179_bind, 1783e2ca90c2SFreddy Xin .unbind = ax88179_unbind, 1784e2ca90c2SFreddy Xin .status = ax88179_status, 1785e2ca90c2SFreddy Xin .link_reset = ax88179_link_reset, 1786e2ca90c2SFreddy Xin .reset = ax88179_reset, 1787e2ca90c2SFreddy Xin .stop = ax88179_stop, 1788e2ca90c2SFreddy Xin .flags = FLAG_ETHER | FLAG_FRAMING_AX, 1789e2ca90c2SFreddy Xin .rx_fixup = ax88179_rx_fixup, 1790e2ca90c2SFreddy Xin .tx_fixup = ax88179_tx_fixup, 1791e2ca90c2SFreddy Xin }; 1792e2ca90c2SFreddy Xin 1793f11a5bc1SFreddy Xin static const struct driver_info samsung_info = { 1794f11a5bc1SFreddy Xin .description = "Samsung USB Ethernet Adapter", 1795f11a5bc1SFreddy Xin .bind = ax88179_bind, 1796f11a5bc1SFreddy Xin .unbind = ax88179_unbind, 1797f11a5bc1SFreddy Xin .status = ax88179_status, 1798f11a5bc1SFreddy Xin .link_reset = ax88179_link_reset, 1799f11a5bc1SFreddy Xin .reset = ax88179_reset, 1800f11a5bc1SFreddy Xin .stop = ax88179_stop, 1801f11a5bc1SFreddy Xin .flags = FLAG_ETHER | FLAG_FRAMING_AX, 1802f11a5bc1SFreddy Xin .rx_fixup = ax88179_rx_fixup, 1803f11a5bc1SFreddy Xin .tx_fixup = ax88179_tx_fixup, 1804f11a5bc1SFreddy Xin }; 1805f11a5bc1SFreddy Xin 1806e5fe0cd4SFreddy Xin static const struct driver_info lenovo_info = { 1807e5fe0cd4SFreddy Xin .description = "Lenovo OneLinkDock Gigabit LAN", 1808e5fe0cd4SFreddy Xin .bind = ax88179_bind, 1809e5fe0cd4SFreddy Xin .unbind = ax88179_unbind, 1810e5fe0cd4SFreddy Xin .status = ax88179_status, 1811e5fe0cd4SFreddy Xin .link_reset = ax88179_link_reset, 1812e5fe0cd4SFreddy Xin .reset = ax88179_reset, 1813e5fe0cd4SFreddy Xin .stop = ax88179_stop, 1814e5fe0cd4SFreddy Xin .flags = FLAG_ETHER | FLAG_FRAMING_AX, 1815e5fe0cd4SFreddy Xin .rx_fixup = ax88179_rx_fixup, 1816e5fe0cd4SFreddy Xin .tx_fixup = ax88179_tx_fixup, 1817e5fe0cd4SFreddy Xin }; 1818e5fe0cd4SFreddy Xin 1819e20bd60bSAndrew F. Davis static const struct driver_info belkin_info = { 1820e20bd60bSAndrew F. Davis .description = "Belkin USB Ethernet Adapter", 1821e20bd60bSAndrew F. Davis .bind = ax88179_bind, 1822e20bd60bSAndrew F. Davis .unbind = ax88179_unbind, 1823e20bd60bSAndrew F. Davis .status = ax88179_status, 1824e20bd60bSAndrew F. Davis .link_reset = ax88179_link_reset, 1825e20bd60bSAndrew F. Davis .reset = ax88179_reset, 1826*9666ea66SWilken Gottwalt .stop = ax88179_stop, 1827e20bd60bSAndrew F. Davis .flags = FLAG_ETHER | FLAG_FRAMING_AX, 1828e20bd60bSAndrew F. Davis .rx_fixup = ax88179_rx_fixup, 1829e20bd60bSAndrew F. Davis .tx_fixup = ax88179_tx_fixup, 1830e20bd60bSAndrew F. Davis }; 1831e20bd60bSAndrew F. Davis 1832e42d72feSWilken Gottwalt static const struct driver_info toshiba_info = { 1833e42d72feSWilken Gottwalt .description = "Toshiba USB Ethernet Adapter", 1834e42d72feSWilken Gottwalt .bind = ax88179_bind, 1835e42d72feSWilken Gottwalt .unbind = ax88179_unbind, 1836e42d72feSWilken Gottwalt .status = ax88179_status, 1837e42d72feSWilken Gottwalt .link_reset = ax88179_link_reset, 1838e42d72feSWilken Gottwalt .reset = ax88179_reset, 1839e42d72feSWilken Gottwalt .stop = ax88179_stop, 1840e42d72feSWilken Gottwalt .flags = FLAG_ETHER | FLAG_FRAMING_AX, 1841e42d72feSWilken Gottwalt .rx_fixup = ax88179_rx_fixup, 1842e42d72feSWilken Gottwalt .tx_fixup = ax88179_tx_fixup, 1843e42d72feSWilken Gottwalt }; 1844e42d72feSWilken Gottwalt 1845e2ca90c2SFreddy Xin static const struct usb_device_id products[] = { 1846e2ca90c2SFreddy Xin { 1847e2ca90c2SFreddy Xin /* ASIX AX88179 10/100/1000 */ 1848e2ca90c2SFreddy Xin USB_DEVICE(0x0b95, 0x1790), 1849e2ca90c2SFreddy Xin .driver_info = (unsigned long)&ax88179_info, 1850e2ca90c2SFreddy Xin }, { 1851e2ca90c2SFreddy Xin /* ASIX AX88178A 10/100/1000 */ 1852e2ca90c2SFreddy Xin USB_DEVICE(0x0b95, 0x178a), 1853e2ca90c2SFreddy Xin .driver_info = (unsigned long)&ax88178a_info, 1854e2ca90c2SFreddy Xin }, { 18558da3cf2aSAllan Chou /* Cypress GX3 SuperSpeed to Gigabit Ethernet Bridge Controller */ 18568da3cf2aSAllan Chou USB_DEVICE(0x04b4, 0x3610), 18578da3cf2aSAllan Chou .driver_info = (unsigned long)&cypress_GX3_info, 18588da3cf2aSAllan Chou }, { 1859635d61a3SGerry Demaret /* D-Link DUB-1312 USB 3.0 to Gigabit Ethernet Adapter */ 1860635d61a3SGerry Demaret USB_DEVICE(0x2001, 0x4a00), 1861635d61a3SGerry Demaret .driver_info = (unsigned long)&dlink_dub1312_info, 1862635d61a3SGerry Demaret }, { 1863e2ca90c2SFreddy Xin /* Sitecom USB 3.0 to Gigabit Adapter */ 1864e2ca90c2SFreddy Xin USB_DEVICE(0x0df6, 0x0072), 1865e2ca90c2SFreddy Xin .driver_info = (unsigned long)&sitecom_info, 1866f11a5bc1SFreddy Xin }, { 1867f11a5bc1SFreddy Xin /* Samsung USB Ethernet Adapter */ 1868f11a5bc1SFreddy Xin USB_DEVICE(0x04e8, 0xa100), 1869f11a5bc1SFreddy Xin .driver_info = (unsigned long)&samsung_info, 1870e5fe0cd4SFreddy Xin }, { 1871e5fe0cd4SFreddy Xin /* Lenovo OneLinkDock Gigabit LAN */ 1872e5fe0cd4SFreddy Xin USB_DEVICE(0x17ef, 0x304b), 1873e5fe0cd4SFreddy Xin .driver_info = (unsigned long)&lenovo_info, 1874e20bd60bSAndrew F. Davis }, { 1875e20bd60bSAndrew F. Davis /* Belkin B2B128 USB 3.0 Hub + Gigabit Ethernet Adapter */ 1876e20bd60bSAndrew F. Davis USB_DEVICE(0x050d, 0x0128), 1877e20bd60bSAndrew F. Davis .driver_info = (unsigned long)&belkin_info, 1878e42d72feSWilken Gottwalt }, { 1879e42d72feSWilken Gottwalt /* Toshiba USB 3.0 GBit Ethernet Adapter */ 1880e42d72feSWilken Gottwalt USB_DEVICE(0x0930, 0x0a13), 1881e42d72feSWilken Gottwalt .driver_info = (unsigned long)&toshiba_info, 1882e2ca90c2SFreddy Xin }, 1883e2ca90c2SFreddy Xin { }, 1884e2ca90c2SFreddy Xin }; 1885e2ca90c2SFreddy Xin MODULE_DEVICE_TABLE(usb, products); 1886e2ca90c2SFreddy Xin 1887e2ca90c2SFreddy Xin static struct usb_driver ax88179_178a_driver = { 1888e2ca90c2SFreddy Xin .name = "ax88179_178a", 1889e2ca90c2SFreddy Xin .id_table = products, 1890e2ca90c2SFreddy Xin .probe = usbnet_probe, 1891e2ca90c2SFreddy Xin .suspend = ax88179_suspend, 1892e2ca90c2SFreddy Xin .resume = ax88179_resume, 1893b8553b89SDavid Chang .reset_resume = ax88179_resume, 1894e2ca90c2SFreddy Xin .disconnect = usbnet_disconnect, 1895e2ca90c2SFreddy Xin .supports_autosuspend = 1, 1896e2ca90c2SFreddy Xin .disable_hub_initiated_lpm = 1, 1897e2ca90c2SFreddy Xin }; 1898e2ca90c2SFreddy Xin 1899e2ca90c2SFreddy Xin module_usb_driver(ax88179_178a_driver); 1900e2ca90c2SFreddy Xin 1901e2ca90c2SFreddy Xin MODULE_DESCRIPTION("ASIX AX88179/178A based USB 3.0/2.0 Gigabit Ethernet Devices"); 1902e2ca90c2SFreddy Xin MODULE_LICENSE("GPL"); 1903