1e2ca90c2SFreddy Xin /* 2e2ca90c2SFreddy Xin * ASIX AX88179/178A USB 3.0/2.0 to Gigabit Ethernet Devices 3e2ca90c2SFreddy Xin * 4e2ca90c2SFreddy Xin * Copyright (C) 2011-2013 ASIX 5e2ca90c2SFreddy Xin * 6e2ca90c2SFreddy Xin * This program is free software; you can redistribute it and/or modify 7e2ca90c2SFreddy Xin * it under the terms of the GNU General Public License 8e2ca90c2SFreddy Xin * as published by the Free Software Foundation; either version 2 9e2ca90c2SFreddy Xin * of the License, or (at your option) any later version. 10e2ca90c2SFreddy Xin * 11e2ca90c2SFreddy Xin * This program is distributed in the hope that it will be useful, 12e2ca90c2SFreddy Xin * but WITHOUT ANY WARRANTY; without even the implied warranty of 13e2ca90c2SFreddy Xin * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14e2ca90c2SFreddy Xin * GNU General Public License for more details. 15e2ca90c2SFreddy Xin * 16e2ca90c2SFreddy Xin * You should have received a copy of the GNU General Public License 17e2ca90c2SFreddy Xin * along with this program; if not, write to the Free Software 18e2ca90c2SFreddy Xin * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 19e2ca90c2SFreddy Xin */ 20e2ca90c2SFreddy Xin 21e2ca90c2SFreddy Xin #include <linux/module.h> 22e2ca90c2SFreddy Xin #include <linux/etherdevice.h> 23e2ca90c2SFreddy Xin #include <linux/mii.h> 24e2ca90c2SFreddy Xin #include <linux/usb.h> 25e2ca90c2SFreddy Xin #include <linux/crc32.h> 26e2ca90c2SFreddy Xin #include <linux/usb/usbnet.h> 27e2ca90c2SFreddy Xin 28e2ca90c2SFreddy Xin #define AX88179_PHY_ID 0x03 29e2ca90c2SFreddy Xin #define AX_EEPROM_LEN 0x100 30e2ca90c2SFreddy Xin #define AX88179_EEPROM_MAGIC 0x17900b95 31e2ca90c2SFreddy Xin #define AX_MCAST_FLTSIZE 8 32e2ca90c2SFreddy Xin #define AX_MAX_MCAST 64 33e2ca90c2SFreddy Xin #define AX_INT_PPLS_LINK ((u32)BIT(16)) 34e2ca90c2SFreddy Xin #define AX_RXHDR_L4_TYPE_MASK 0x1c 35e2ca90c2SFreddy Xin #define AX_RXHDR_L4_TYPE_UDP 4 36e2ca90c2SFreddy Xin #define AX_RXHDR_L4_TYPE_TCP 16 37e2ca90c2SFreddy Xin #define AX_RXHDR_L3CSUM_ERR 2 38e2ca90c2SFreddy Xin #define AX_RXHDR_L4CSUM_ERR 1 39*7e78b83cSFreddy Xin #define AX_RXHDR_CRC_ERR ((u32)BIT(29)) 40*7e78b83cSFreddy Xin #define AX_RXHDR_DROP_ERR ((u32)BIT(31)) 41e2ca90c2SFreddy Xin #define AX_ACCESS_MAC 0x01 42e2ca90c2SFreddy Xin #define AX_ACCESS_PHY 0x02 43e2ca90c2SFreddy Xin #define AX_ACCESS_EEPROM 0x04 44e2ca90c2SFreddy Xin #define AX_ACCESS_EFUS 0x05 45e2ca90c2SFreddy Xin #define AX_PAUSE_WATERLVL_HIGH 0x54 46e2ca90c2SFreddy Xin #define AX_PAUSE_WATERLVL_LOW 0x55 47e2ca90c2SFreddy Xin 48e2ca90c2SFreddy Xin #define PHYSICAL_LINK_STATUS 0x02 49e2ca90c2SFreddy Xin #define AX_USB_SS 0x04 50e2ca90c2SFreddy Xin #define AX_USB_HS 0x02 51e2ca90c2SFreddy Xin 52e2ca90c2SFreddy Xin #define GENERAL_STATUS 0x03 53e2ca90c2SFreddy Xin /* Check AX88179 version. UA1:Bit2 = 0, UA2:Bit2 = 1 */ 54e2ca90c2SFreddy Xin #define AX_SECLD 0x04 55e2ca90c2SFreddy Xin 56e2ca90c2SFreddy Xin #define AX_SROM_ADDR 0x07 57e2ca90c2SFreddy Xin #define AX_SROM_CMD 0x0a 58e2ca90c2SFreddy Xin #define EEP_RD 0x04 59e2ca90c2SFreddy Xin #define EEP_BUSY 0x10 60e2ca90c2SFreddy Xin 61e2ca90c2SFreddy Xin #define AX_SROM_DATA_LOW 0x08 62e2ca90c2SFreddy Xin #define AX_SROM_DATA_HIGH 0x09 63e2ca90c2SFreddy Xin 64e2ca90c2SFreddy Xin #define AX_RX_CTL 0x0b 65e2ca90c2SFreddy Xin #define AX_RX_CTL_DROPCRCERR 0x0100 66e2ca90c2SFreddy Xin #define AX_RX_CTL_IPE 0x0200 67e2ca90c2SFreddy Xin #define AX_RX_CTL_START 0x0080 68e2ca90c2SFreddy Xin #define AX_RX_CTL_AP 0x0020 69e2ca90c2SFreddy Xin #define AX_RX_CTL_AM 0x0010 70e2ca90c2SFreddy Xin #define AX_RX_CTL_AB 0x0008 71e2ca90c2SFreddy Xin #define AX_RX_CTL_AMALL 0x0002 72e2ca90c2SFreddy Xin #define AX_RX_CTL_PRO 0x0001 73e2ca90c2SFreddy Xin #define AX_RX_CTL_STOP 0x0000 74e2ca90c2SFreddy Xin 75e2ca90c2SFreddy Xin #define AX_NODE_ID 0x10 76e2ca90c2SFreddy Xin #define AX_MULFLTARY 0x16 77e2ca90c2SFreddy Xin 78e2ca90c2SFreddy Xin #define AX_MEDIUM_STATUS_MODE 0x22 79e2ca90c2SFreddy Xin #define AX_MEDIUM_GIGAMODE 0x01 80e2ca90c2SFreddy Xin #define AX_MEDIUM_FULL_DUPLEX 0x02 81e2ca90c2SFreddy Xin #define AX_MEDIUM_ALWAYS_ONE 0x04 82e2ca90c2SFreddy Xin #define AX_MEDIUM_EN_125MHZ 0x08 83e2ca90c2SFreddy Xin #define AX_MEDIUM_RXFLOW_CTRLEN 0x10 84e2ca90c2SFreddy Xin #define AX_MEDIUM_TXFLOW_CTRLEN 0x20 85e2ca90c2SFreddy Xin #define AX_MEDIUM_RECEIVE_EN 0x100 86e2ca90c2SFreddy Xin #define AX_MEDIUM_PS 0x200 87e2ca90c2SFreddy Xin #define AX_MEDIUM_JUMBO_EN 0x8040 88e2ca90c2SFreddy Xin 89e2ca90c2SFreddy Xin #define AX_MONITOR_MOD 0x24 90e2ca90c2SFreddy Xin #define AX_MONITOR_MODE_RWLC 0x02 91e2ca90c2SFreddy Xin #define AX_MONITOR_MODE_RWMP 0x04 92e2ca90c2SFreddy Xin #define AX_MONITOR_MODE_PMEPOL 0x20 93e2ca90c2SFreddy Xin #define AX_MONITOR_MODE_PMETYPE 0x40 94e2ca90c2SFreddy Xin 95e2ca90c2SFreddy Xin #define AX_GPIO_CTRL 0x25 96e2ca90c2SFreddy Xin #define AX_GPIO_CTRL_GPIO3EN 0x80 97e2ca90c2SFreddy Xin #define AX_GPIO_CTRL_GPIO2EN 0x40 98e2ca90c2SFreddy Xin #define AX_GPIO_CTRL_GPIO1EN 0x20 99e2ca90c2SFreddy Xin 100e2ca90c2SFreddy Xin #define AX_PHYPWR_RSTCTL 0x26 101e2ca90c2SFreddy Xin #define AX_PHYPWR_RSTCTL_BZ 0x0010 102e2ca90c2SFreddy Xin #define AX_PHYPWR_RSTCTL_IPRL 0x0020 103e2ca90c2SFreddy Xin #define AX_PHYPWR_RSTCTL_AT 0x1000 104e2ca90c2SFreddy Xin 105e2ca90c2SFreddy Xin #define AX_RX_BULKIN_QCTRL 0x2e 106e2ca90c2SFreddy Xin #define AX_CLK_SELECT 0x33 107e2ca90c2SFreddy Xin #define AX_CLK_SELECT_BCS 0x01 108e2ca90c2SFreddy Xin #define AX_CLK_SELECT_ACS 0x02 109e2ca90c2SFreddy Xin #define AX_CLK_SELECT_ULR 0x08 110e2ca90c2SFreddy Xin 111e2ca90c2SFreddy Xin #define AX_RXCOE_CTL 0x34 112e2ca90c2SFreddy Xin #define AX_RXCOE_IP 0x01 113e2ca90c2SFreddy Xin #define AX_RXCOE_TCP 0x02 114e2ca90c2SFreddy Xin #define AX_RXCOE_UDP 0x04 115e2ca90c2SFreddy Xin #define AX_RXCOE_TCPV6 0x20 116e2ca90c2SFreddy Xin #define AX_RXCOE_UDPV6 0x40 117e2ca90c2SFreddy Xin 118e2ca90c2SFreddy Xin #define AX_TXCOE_CTL 0x35 119e2ca90c2SFreddy Xin #define AX_TXCOE_IP 0x01 120e2ca90c2SFreddy Xin #define AX_TXCOE_TCP 0x02 121e2ca90c2SFreddy Xin #define AX_TXCOE_UDP 0x04 122e2ca90c2SFreddy Xin #define AX_TXCOE_TCPV6 0x20 123e2ca90c2SFreddy Xin #define AX_TXCOE_UDPV6 0x40 124e2ca90c2SFreddy Xin 125e2ca90c2SFreddy Xin #define AX_LEDCTRL 0x73 126e2ca90c2SFreddy Xin 127e2ca90c2SFreddy Xin #define GMII_PHY_PHYSR 0x11 128e2ca90c2SFreddy Xin #define GMII_PHY_PHYSR_SMASK 0xc000 129e2ca90c2SFreddy Xin #define GMII_PHY_PHYSR_GIGA 0x8000 130e2ca90c2SFreddy Xin #define GMII_PHY_PHYSR_100 0x4000 131e2ca90c2SFreddy Xin #define GMII_PHY_PHYSR_FULL 0x2000 132e2ca90c2SFreddy Xin #define GMII_PHY_PHYSR_LINK 0x400 133e2ca90c2SFreddy Xin 134e2ca90c2SFreddy Xin #define GMII_LED_ACT 0x1a 135e2ca90c2SFreddy Xin #define GMII_LED_ACTIVE_MASK 0xff8f 136e2ca90c2SFreddy Xin #define GMII_LED0_ACTIVE BIT(4) 137e2ca90c2SFreddy Xin #define GMII_LED1_ACTIVE BIT(5) 138e2ca90c2SFreddy Xin #define GMII_LED2_ACTIVE BIT(6) 139e2ca90c2SFreddy Xin 140e2ca90c2SFreddy Xin #define GMII_LED_LINK 0x1c 141e2ca90c2SFreddy Xin #define GMII_LED_LINK_MASK 0xf888 142e2ca90c2SFreddy Xin #define GMII_LED0_LINK_10 BIT(0) 143e2ca90c2SFreddy Xin #define GMII_LED0_LINK_100 BIT(1) 144e2ca90c2SFreddy Xin #define GMII_LED0_LINK_1000 BIT(2) 145e2ca90c2SFreddy Xin #define GMII_LED1_LINK_10 BIT(4) 146e2ca90c2SFreddy Xin #define GMII_LED1_LINK_100 BIT(5) 147e2ca90c2SFreddy Xin #define GMII_LED1_LINK_1000 BIT(6) 148e2ca90c2SFreddy Xin #define GMII_LED2_LINK_10 BIT(8) 149e2ca90c2SFreddy Xin #define GMII_LED2_LINK_100 BIT(9) 150e2ca90c2SFreddy Xin #define GMII_LED2_LINK_1000 BIT(10) 151e2ca90c2SFreddy Xin #define LED0_ACTIVE BIT(0) 152e2ca90c2SFreddy Xin #define LED0_LINK_10 BIT(1) 153e2ca90c2SFreddy Xin #define LED0_LINK_100 BIT(2) 154e2ca90c2SFreddy Xin #define LED0_LINK_1000 BIT(3) 155e2ca90c2SFreddy Xin #define LED0_FD BIT(4) 156e2ca90c2SFreddy Xin #define LED0_USB3_MASK 0x001f 157e2ca90c2SFreddy Xin #define LED1_ACTIVE BIT(5) 158e2ca90c2SFreddy Xin #define LED1_LINK_10 BIT(6) 159e2ca90c2SFreddy Xin #define LED1_LINK_100 BIT(7) 160e2ca90c2SFreddy Xin #define LED1_LINK_1000 BIT(8) 161e2ca90c2SFreddy Xin #define LED1_FD BIT(9) 162e2ca90c2SFreddy Xin #define LED1_USB3_MASK 0x03e0 163e2ca90c2SFreddy Xin #define LED2_ACTIVE BIT(10) 164e2ca90c2SFreddy Xin #define LED2_LINK_1000 BIT(13) 165e2ca90c2SFreddy Xin #define LED2_LINK_100 BIT(12) 166e2ca90c2SFreddy Xin #define LED2_LINK_10 BIT(11) 167e2ca90c2SFreddy Xin #define LED2_FD BIT(14) 168e2ca90c2SFreddy Xin #define LED_VALID BIT(15) 169e2ca90c2SFreddy Xin #define LED2_USB3_MASK 0x7c00 170e2ca90c2SFreddy Xin 171e2ca90c2SFreddy Xin #define GMII_PHYPAGE 0x1e 172e2ca90c2SFreddy Xin #define GMII_PHY_PAGE_SELECT 0x1f 173e2ca90c2SFreddy Xin #define GMII_PHY_PGSEL_EXT 0x0007 174e2ca90c2SFreddy Xin #define GMII_PHY_PGSEL_PAGE0 0x0000 175e2ca90c2SFreddy Xin 176e2ca90c2SFreddy Xin struct ax88179_data { 177e2ca90c2SFreddy Xin u16 rxctl; 178e2ca90c2SFreddy Xin u16 reserved; 179e2ca90c2SFreddy Xin }; 180e2ca90c2SFreddy Xin 181e2ca90c2SFreddy Xin struct ax88179_int_data { 182e2ca90c2SFreddy Xin __le32 intdata1; 183e2ca90c2SFreddy Xin __le32 intdata2; 184e2ca90c2SFreddy Xin }; 185e2ca90c2SFreddy Xin 186e2ca90c2SFreddy Xin static const struct { 187e2ca90c2SFreddy Xin unsigned char ctrl, timer_l, timer_h, size, ifg; 188e2ca90c2SFreddy Xin } AX88179_BULKIN_SIZE[] = { 189e2ca90c2SFreddy Xin {7, 0x4f, 0, 0x12, 0xff}, 190e2ca90c2SFreddy Xin {7, 0x20, 3, 0x16, 0xff}, 191e2ca90c2SFreddy Xin {7, 0xae, 7, 0x18, 0xff}, 192e2ca90c2SFreddy Xin {7, 0xcc, 0x4c, 0x18, 8}, 193e2ca90c2SFreddy Xin }; 194e2ca90c2SFreddy Xin 195e2ca90c2SFreddy Xin static int __ax88179_read_cmd(struct usbnet *dev, u8 cmd, u16 value, u16 index, 196e2ca90c2SFreddy Xin u16 size, void *data, int in_pm) 197e2ca90c2SFreddy Xin { 198e2ca90c2SFreddy Xin int ret; 199e2ca90c2SFreddy Xin int (*fn)(struct usbnet *, u8, u8, u16, u16, void *, u16); 200e2ca90c2SFreddy Xin 201e2ca90c2SFreddy Xin BUG_ON(!dev); 202e2ca90c2SFreddy Xin 203e2ca90c2SFreddy Xin if (!in_pm) 204e2ca90c2SFreddy Xin fn = usbnet_read_cmd; 205e2ca90c2SFreddy Xin else 206e2ca90c2SFreddy Xin fn = usbnet_read_cmd_nopm; 207e2ca90c2SFreddy Xin 208e2ca90c2SFreddy Xin ret = fn(dev, cmd, USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE, 209e2ca90c2SFreddy Xin value, index, data, size); 210e2ca90c2SFreddy Xin 211e2ca90c2SFreddy Xin if (unlikely(ret < 0)) 212e2ca90c2SFreddy Xin netdev_warn(dev->net, "Failed to read reg index 0x%04x: %d\n", 213e2ca90c2SFreddy Xin index, ret); 214e2ca90c2SFreddy Xin 215e2ca90c2SFreddy Xin return ret; 216e2ca90c2SFreddy Xin } 217e2ca90c2SFreddy Xin 218e2ca90c2SFreddy Xin static int __ax88179_write_cmd(struct usbnet *dev, u8 cmd, u16 value, u16 index, 219e2ca90c2SFreddy Xin u16 size, void *data, int in_pm) 220e2ca90c2SFreddy Xin { 221e2ca90c2SFreddy Xin int ret; 222e2ca90c2SFreddy Xin int (*fn)(struct usbnet *, u8, u8, u16, u16, const void *, u16); 223e2ca90c2SFreddy Xin 224e2ca90c2SFreddy Xin BUG_ON(!dev); 225e2ca90c2SFreddy Xin 226e2ca90c2SFreddy Xin if (!in_pm) 227e2ca90c2SFreddy Xin fn = usbnet_write_cmd; 228e2ca90c2SFreddy Xin else 229e2ca90c2SFreddy Xin fn = usbnet_write_cmd_nopm; 230e2ca90c2SFreddy Xin 231e2ca90c2SFreddy Xin ret = fn(dev, cmd, USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE, 232e2ca90c2SFreddy Xin value, index, data, size); 233e2ca90c2SFreddy Xin 234e2ca90c2SFreddy Xin if (unlikely(ret < 0)) 235e2ca90c2SFreddy Xin netdev_warn(dev->net, "Failed to write reg index 0x%04x: %d\n", 236e2ca90c2SFreddy Xin index, ret); 237e2ca90c2SFreddy Xin 238e2ca90c2SFreddy Xin return ret; 239e2ca90c2SFreddy Xin } 240e2ca90c2SFreddy Xin 241e2ca90c2SFreddy Xin static void ax88179_write_cmd_async(struct usbnet *dev, u8 cmd, u16 value, 242e2ca90c2SFreddy Xin u16 index, u16 size, void *data) 243e2ca90c2SFreddy Xin { 244e2ca90c2SFreddy Xin u16 buf; 245e2ca90c2SFreddy Xin 246e2ca90c2SFreddy Xin if (2 == size) { 247e2ca90c2SFreddy Xin buf = *((u16 *)data); 248e2ca90c2SFreddy Xin cpu_to_le16s(&buf); 249e2ca90c2SFreddy Xin usbnet_write_cmd_async(dev, cmd, USB_DIR_OUT | USB_TYPE_VENDOR | 250e2ca90c2SFreddy Xin USB_RECIP_DEVICE, value, index, &buf, 251e2ca90c2SFreddy Xin size); 252e2ca90c2SFreddy Xin } else { 253e2ca90c2SFreddy Xin usbnet_write_cmd_async(dev, cmd, USB_DIR_OUT | USB_TYPE_VENDOR | 254e2ca90c2SFreddy Xin USB_RECIP_DEVICE, value, index, data, 255e2ca90c2SFreddy Xin size); 256e2ca90c2SFreddy Xin } 257e2ca90c2SFreddy Xin } 258e2ca90c2SFreddy Xin 259e2ca90c2SFreddy Xin static int ax88179_read_cmd_nopm(struct usbnet *dev, u8 cmd, u16 value, 260e2ca90c2SFreddy Xin u16 index, u16 size, void *data) 261e2ca90c2SFreddy Xin { 262e2ca90c2SFreddy Xin int ret; 263e2ca90c2SFreddy Xin 264e2ca90c2SFreddy Xin if (2 == size) { 265e2ca90c2SFreddy Xin u16 buf; 266e2ca90c2SFreddy Xin ret = __ax88179_read_cmd(dev, cmd, value, index, size, &buf, 1); 267e2ca90c2SFreddy Xin le16_to_cpus(&buf); 268e2ca90c2SFreddy Xin *((u16 *)data) = buf; 269e2ca90c2SFreddy Xin } else if (4 == size) { 270e2ca90c2SFreddy Xin u32 buf; 271e2ca90c2SFreddy Xin ret = __ax88179_read_cmd(dev, cmd, value, index, size, &buf, 1); 272e2ca90c2SFreddy Xin le32_to_cpus(&buf); 273e2ca90c2SFreddy Xin *((u32 *)data) = buf; 274e2ca90c2SFreddy Xin } else { 275e2ca90c2SFreddy Xin ret = __ax88179_read_cmd(dev, cmd, value, index, size, data, 1); 276e2ca90c2SFreddy Xin } 277e2ca90c2SFreddy Xin 278e2ca90c2SFreddy Xin return ret; 279e2ca90c2SFreddy Xin } 280e2ca90c2SFreddy Xin 281e2ca90c2SFreddy Xin static int ax88179_write_cmd_nopm(struct usbnet *dev, u8 cmd, u16 value, 282e2ca90c2SFreddy Xin u16 index, u16 size, void *data) 283e2ca90c2SFreddy Xin { 284e2ca90c2SFreddy Xin int ret; 285e2ca90c2SFreddy Xin 286e2ca90c2SFreddy Xin if (2 == size) { 287e2ca90c2SFreddy Xin u16 buf; 288e2ca90c2SFreddy Xin buf = *((u16 *)data); 289e2ca90c2SFreddy Xin cpu_to_le16s(&buf); 290e2ca90c2SFreddy Xin ret = __ax88179_write_cmd(dev, cmd, value, index, 291e2ca90c2SFreddy Xin size, &buf, 1); 292e2ca90c2SFreddy Xin } else { 293e2ca90c2SFreddy Xin ret = __ax88179_write_cmd(dev, cmd, value, index, 294e2ca90c2SFreddy Xin size, data, 1); 295e2ca90c2SFreddy Xin } 296e2ca90c2SFreddy Xin 297e2ca90c2SFreddy Xin return ret; 298e2ca90c2SFreddy Xin } 299e2ca90c2SFreddy Xin 300e2ca90c2SFreddy Xin static int ax88179_read_cmd(struct usbnet *dev, u8 cmd, u16 value, u16 index, 301e2ca90c2SFreddy Xin u16 size, void *data) 302e2ca90c2SFreddy Xin { 303e2ca90c2SFreddy Xin int ret; 304e2ca90c2SFreddy Xin 305e2ca90c2SFreddy Xin if (2 == size) { 306e2ca90c2SFreddy Xin u16 buf; 307e2ca90c2SFreddy Xin ret = __ax88179_read_cmd(dev, cmd, value, index, size, &buf, 0); 308e2ca90c2SFreddy Xin le16_to_cpus(&buf); 309e2ca90c2SFreddy Xin *((u16 *)data) = buf; 310e2ca90c2SFreddy Xin } else if (4 == size) { 311e2ca90c2SFreddy Xin u32 buf; 312e2ca90c2SFreddy Xin ret = __ax88179_read_cmd(dev, cmd, value, index, size, &buf, 0); 313e2ca90c2SFreddy Xin le32_to_cpus(&buf); 314e2ca90c2SFreddy Xin *((u32 *)data) = buf; 315e2ca90c2SFreddy Xin } else { 316e2ca90c2SFreddy Xin ret = __ax88179_read_cmd(dev, cmd, value, index, size, data, 0); 317e2ca90c2SFreddy Xin } 318e2ca90c2SFreddy Xin 319e2ca90c2SFreddy Xin return ret; 320e2ca90c2SFreddy Xin } 321e2ca90c2SFreddy Xin 322e2ca90c2SFreddy Xin static int ax88179_write_cmd(struct usbnet *dev, u8 cmd, u16 value, u16 index, 323e2ca90c2SFreddy Xin u16 size, void *data) 324e2ca90c2SFreddy Xin { 325e2ca90c2SFreddy Xin int ret; 326e2ca90c2SFreddy Xin 327e2ca90c2SFreddy Xin if (2 == size) { 328e2ca90c2SFreddy Xin u16 buf; 329e2ca90c2SFreddy Xin buf = *((u16 *)data); 330e2ca90c2SFreddy Xin cpu_to_le16s(&buf); 331e2ca90c2SFreddy Xin ret = __ax88179_write_cmd(dev, cmd, value, index, 332e2ca90c2SFreddy Xin size, &buf, 0); 333e2ca90c2SFreddy Xin } else { 334e2ca90c2SFreddy Xin ret = __ax88179_write_cmd(dev, cmd, value, index, 335e2ca90c2SFreddy Xin size, data, 0); 336e2ca90c2SFreddy Xin } 337e2ca90c2SFreddy Xin 338e2ca90c2SFreddy Xin return ret; 339e2ca90c2SFreddy Xin } 340e2ca90c2SFreddy Xin 341e2ca90c2SFreddy Xin static void ax88179_status(struct usbnet *dev, struct urb *urb) 342e2ca90c2SFreddy Xin { 343e2ca90c2SFreddy Xin struct ax88179_int_data *event; 344e2ca90c2SFreddy Xin u32 link; 345e2ca90c2SFreddy Xin 346e2ca90c2SFreddy Xin if (urb->actual_length < 8) 347e2ca90c2SFreddy Xin return; 348e2ca90c2SFreddy Xin 349e2ca90c2SFreddy Xin event = urb->transfer_buffer; 350e2ca90c2SFreddy Xin le32_to_cpus((void *)&event->intdata1); 351e2ca90c2SFreddy Xin 352e2ca90c2SFreddy Xin link = (((__force u32)event->intdata1) & AX_INT_PPLS_LINK) >> 16; 353e2ca90c2SFreddy Xin 354e2ca90c2SFreddy Xin if (netif_carrier_ok(dev->net) != link) { 3557a97856eSMing Lei usbnet_link_change(dev, link, 1); 356e2ca90c2SFreddy Xin netdev_info(dev->net, "ax88179 - Link status is: %d\n", link); 357e2ca90c2SFreddy Xin } 358e2ca90c2SFreddy Xin } 359e2ca90c2SFreddy Xin 360e2ca90c2SFreddy Xin static int ax88179_mdio_read(struct net_device *netdev, int phy_id, int loc) 361e2ca90c2SFreddy Xin { 362e2ca90c2SFreddy Xin struct usbnet *dev = netdev_priv(netdev); 363e2ca90c2SFreddy Xin u16 res; 364e2ca90c2SFreddy Xin 365e2ca90c2SFreddy Xin ax88179_read_cmd(dev, AX_ACCESS_PHY, phy_id, (__u16)loc, 2, &res); 366e2ca90c2SFreddy Xin return res; 367e2ca90c2SFreddy Xin } 368e2ca90c2SFreddy Xin 369e2ca90c2SFreddy Xin static void ax88179_mdio_write(struct net_device *netdev, int phy_id, int loc, 370e2ca90c2SFreddy Xin int val) 371e2ca90c2SFreddy Xin { 372e2ca90c2SFreddy Xin struct usbnet *dev = netdev_priv(netdev); 373e2ca90c2SFreddy Xin u16 res = (u16) val; 374e2ca90c2SFreddy Xin 375e2ca90c2SFreddy Xin ax88179_write_cmd(dev, AX_ACCESS_PHY, phy_id, (__u16)loc, 2, &res); 376e2ca90c2SFreddy Xin } 377e2ca90c2SFreddy Xin 378e2ca90c2SFreddy Xin static int ax88179_suspend(struct usb_interface *intf, pm_message_t message) 379e2ca90c2SFreddy Xin { 380e2ca90c2SFreddy Xin struct usbnet *dev = usb_get_intfdata(intf); 381e2ca90c2SFreddy Xin u16 tmp16; 382e2ca90c2SFreddy Xin u8 tmp8; 383e2ca90c2SFreddy Xin 384e2ca90c2SFreddy Xin usbnet_suspend(intf, message); 385e2ca90c2SFreddy Xin 386e2ca90c2SFreddy Xin /* Disable RX path */ 387e2ca90c2SFreddy Xin ax88179_read_cmd_nopm(dev, AX_ACCESS_MAC, AX_MEDIUM_STATUS_MODE, 388e2ca90c2SFreddy Xin 2, 2, &tmp16); 389e2ca90c2SFreddy Xin tmp16 &= ~AX_MEDIUM_RECEIVE_EN; 390e2ca90c2SFreddy Xin ax88179_write_cmd_nopm(dev, AX_ACCESS_MAC, AX_MEDIUM_STATUS_MODE, 391e2ca90c2SFreddy Xin 2, 2, &tmp16); 392e2ca90c2SFreddy Xin 393e2ca90c2SFreddy Xin /* Force bulk-in zero length */ 394e2ca90c2SFreddy Xin ax88179_read_cmd_nopm(dev, AX_ACCESS_MAC, AX_PHYPWR_RSTCTL, 395e2ca90c2SFreddy Xin 2, 2, &tmp16); 396e2ca90c2SFreddy Xin 397e2ca90c2SFreddy Xin tmp16 |= AX_PHYPWR_RSTCTL_BZ | AX_PHYPWR_RSTCTL_IPRL; 398e2ca90c2SFreddy Xin ax88179_write_cmd_nopm(dev, AX_ACCESS_MAC, AX_PHYPWR_RSTCTL, 399e2ca90c2SFreddy Xin 2, 2, &tmp16); 400e2ca90c2SFreddy Xin 401e2ca90c2SFreddy Xin /* change clock */ 402e2ca90c2SFreddy Xin tmp8 = 0; 403e2ca90c2SFreddy Xin ax88179_write_cmd_nopm(dev, AX_ACCESS_MAC, AX_CLK_SELECT, 1, 1, &tmp8); 404e2ca90c2SFreddy Xin 405e2ca90c2SFreddy Xin /* Configure RX control register => stop operation */ 406e2ca90c2SFreddy Xin tmp16 = AX_RX_CTL_STOP; 407e2ca90c2SFreddy Xin ax88179_write_cmd_nopm(dev, AX_ACCESS_MAC, AX_RX_CTL, 2, 2, &tmp16); 408e2ca90c2SFreddy Xin 409e2ca90c2SFreddy Xin return 0; 410e2ca90c2SFreddy Xin } 411e2ca90c2SFreddy Xin 412e2ca90c2SFreddy Xin /* This function is used to enable the autodetach function. */ 413e2ca90c2SFreddy Xin /* This function is determined by offset 0x43 of EEPROM */ 414e2ca90c2SFreddy Xin static int ax88179_auto_detach(struct usbnet *dev, int in_pm) 415e2ca90c2SFreddy Xin { 416e2ca90c2SFreddy Xin u16 tmp16; 417e2ca90c2SFreddy Xin u8 tmp8; 418e2ca90c2SFreddy Xin int (*fnr)(struct usbnet *, u8, u16, u16, u16, void *); 419e2ca90c2SFreddy Xin int (*fnw)(struct usbnet *, u8, u16, u16, u16, void *); 420e2ca90c2SFreddy Xin 421e2ca90c2SFreddy Xin if (!in_pm) { 422e2ca90c2SFreddy Xin fnr = ax88179_read_cmd; 423e2ca90c2SFreddy Xin fnw = ax88179_write_cmd; 424e2ca90c2SFreddy Xin } else { 425e2ca90c2SFreddy Xin fnr = ax88179_read_cmd_nopm; 426e2ca90c2SFreddy Xin fnw = ax88179_write_cmd_nopm; 427e2ca90c2SFreddy Xin } 428e2ca90c2SFreddy Xin 429e2ca90c2SFreddy Xin if (fnr(dev, AX_ACCESS_EEPROM, 0x43, 1, 2, &tmp16) < 0) 430e2ca90c2SFreddy Xin return 0; 431e2ca90c2SFreddy Xin 432e2ca90c2SFreddy Xin if ((tmp16 == 0xFFFF) || (!(tmp16 & 0x0100))) 433e2ca90c2SFreddy Xin return 0; 434e2ca90c2SFreddy Xin 435e2ca90c2SFreddy Xin /* Enable Auto Detach bit */ 436e2ca90c2SFreddy Xin tmp8 = 0; 437e2ca90c2SFreddy Xin fnr(dev, AX_ACCESS_MAC, AX_CLK_SELECT, 1, 1, &tmp8); 438e2ca90c2SFreddy Xin tmp8 |= AX_CLK_SELECT_ULR; 439e2ca90c2SFreddy Xin fnw(dev, AX_ACCESS_MAC, AX_CLK_SELECT, 1, 1, &tmp8); 440e2ca90c2SFreddy Xin 441e2ca90c2SFreddy Xin fnr(dev, AX_ACCESS_MAC, AX_PHYPWR_RSTCTL, 2, 2, &tmp16); 442e2ca90c2SFreddy Xin tmp16 |= AX_PHYPWR_RSTCTL_AT; 443e2ca90c2SFreddy Xin fnw(dev, AX_ACCESS_MAC, AX_PHYPWR_RSTCTL, 2, 2, &tmp16); 444e2ca90c2SFreddy Xin 445e2ca90c2SFreddy Xin return 0; 446e2ca90c2SFreddy Xin } 447e2ca90c2SFreddy Xin 448e2ca90c2SFreddy Xin static int ax88179_resume(struct usb_interface *intf) 449e2ca90c2SFreddy Xin { 450e2ca90c2SFreddy Xin struct usbnet *dev = usb_get_intfdata(intf); 451e2ca90c2SFreddy Xin u16 tmp16; 452e2ca90c2SFreddy Xin u8 tmp8; 453e2ca90c2SFreddy Xin 4547a97856eSMing Lei usbnet_link_change(dev, 0, 0); 455e2ca90c2SFreddy Xin 456e2ca90c2SFreddy Xin /* Power up ethernet PHY */ 457e2ca90c2SFreddy Xin tmp16 = 0; 458e2ca90c2SFreddy Xin ax88179_write_cmd_nopm(dev, AX_ACCESS_MAC, AX_PHYPWR_RSTCTL, 459e2ca90c2SFreddy Xin 2, 2, &tmp16); 460e2ca90c2SFreddy Xin udelay(1000); 461e2ca90c2SFreddy Xin 462e2ca90c2SFreddy Xin tmp16 = AX_PHYPWR_RSTCTL_IPRL; 463e2ca90c2SFreddy Xin ax88179_write_cmd_nopm(dev, AX_ACCESS_MAC, AX_PHYPWR_RSTCTL, 464e2ca90c2SFreddy Xin 2, 2, &tmp16); 465e2ca90c2SFreddy Xin msleep(200); 466e2ca90c2SFreddy Xin 467e2ca90c2SFreddy Xin /* Ethernet PHY Auto Detach*/ 468e2ca90c2SFreddy Xin ax88179_auto_detach(dev, 1); 469e2ca90c2SFreddy Xin 470e2ca90c2SFreddy Xin /* Enable clock */ 471e2ca90c2SFreddy Xin ax88179_read_cmd_nopm(dev, AX_ACCESS_MAC, AX_CLK_SELECT, 1, 1, &tmp8); 472e2ca90c2SFreddy Xin tmp8 |= AX_CLK_SELECT_ACS | AX_CLK_SELECT_BCS; 473e2ca90c2SFreddy Xin ax88179_write_cmd_nopm(dev, AX_ACCESS_MAC, AX_CLK_SELECT, 1, 1, &tmp8); 474e2ca90c2SFreddy Xin msleep(100); 475e2ca90c2SFreddy Xin 476e2ca90c2SFreddy Xin /* Configure RX control register => start operation */ 477e2ca90c2SFreddy Xin tmp16 = AX_RX_CTL_DROPCRCERR | AX_RX_CTL_IPE | AX_RX_CTL_START | 478e2ca90c2SFreddy Xin AX_RX_CTL_AP | AX_RX_CTL_AMALL | AX_RX_CTL_AB; 479e2ca90c2SFreddy Xin ax88179_write_cmd_nopm(dev, AX_ACCESS_MAC, AX_RX_CTL, 2, 2, &tmp16); 480e2ca90c2SFreddy Xin 481e2ca90c2SFreddy Xin return usbnet_resume(intf); 482e2ca90c2SFreddy Xin } 483e2ca90c2SFreddy Xin 484e2ca90c2SFreddy Xin static void 485e2ca90c2SFreddy Xin ax88179_get_wol(struct net_device *net, struct ethtool_wolinfo *wolinfo) 486e2ca90c2SFreddy Xin { 487e2ca90c2SFreddy Xin struct usbnet *dev = netdev_priv(net); 488e2ca90c2SFreddy Xin u8 opt; 489e2ca90c2SFreddy Xin 490e2ca90c2SFreddy Xin if (ax88179_read_cmd(dev, AX_ACCESS_MAC, AX_MONITOR_MOD, 491e2ca90c2SFreddy Xin 1, 1, &opt) < 0) { 492e2ca90c2SFreddy Xin wolinfo->supported = 0; 493e2ca90c2SFreddy Xin wolinfo->wolopts = 0; 494e2ca90c2SFreddy Xin return; 495e2ca90c2SFreddy Xin } 496e2ca90c2SFreddy Xin 497e2ca90c2SFreddy Xin wolinfo->supported = WAKE_PHY | WAKE_MAGIC; 498e2ca90c2SFreddy Xin wolinfo->wolopts = 0; 499e2ca90c2SFreddy Xin if (opt & AX_MONITOR_MODE_RWLC) 500e2ca90c2SFreddy Xin wolinfo->wolopts |= WAKE_PHY; 501e2ca90c2SFreddy Xin if (opt & AX_MONITOR_MODE_RWMP) 502e2ca90c2SFreddy Xin wolinfo->wolopts |= WAKE_MAGIC; 503e2ca90c2SFreddy Xin } 504e2ca90c2SFreddy Xin 505e2ca90c2SFreddy Xin static int 506e2ca90c2SFreddy Xin ax88179_set_wol(struct net_device *net, struct ethtool_wolinfo *wolinfo) 507e2ca90c2SFreddy Xin { 508e2ca90c2SFreddy Xin struct usbnet *dev = netdev_priv(net); 509e2ca90c2SFreddy Xin u8 opt = 0; 510e2ca90c2SFreddy Xin 511e2ca90c2SFreddy Xin if (wolinfo->wolopts & WAKE_PHY) 512e2ca90c2SFreddy Xin opt |= AX_MONITOR_MODE_RWLC; 513e2ca90c2SFreddy Xin if (wolinfo->wolopts & WAKE_MAGIC) 514e2ca90c2SFreddy Xin opt |= AX_MONITOR_MODE_RWMP; 515e2ca90c2SFreddy Xin 516e2ca90c2SFreddy Xin if (ax88179_write_cmd(dev, AX_ACCESS_MAC, AX_MONITOR_MOD, 517e2ca90c2SFreddy Xin 1, 1, &opt) < 0) 518e2ca90c2SFreddy Xin return -EINVAL; 519e2ca90c2SFreddy Xin 520e2ca90c2SFreddy Xin return 0; 521e2ca90c2SFreddy Xin } 522e2ca90c2SFreddy Xin 523e2ca90c2SFreddy Xin static int ax88179_get_eeprom_len(struct net_device *net) 524e2ca90c2SFreddy Xin { 525e2ca90c2SFreddy Xin return AX_EEPROM_LEN; 526e2ca90c2SFreddy Xin } 527e2ca90c2SFreddy Xin 528e2ca90c2SFreddy Xin static int 529e2ca90c2SFreddy Xin ax88179_get_eeprom(struct net_device *net, struct ethtool_eeprom *eeprom, 530e2ca90c2SFreddy Xin u8 *data) 531e2ca90c2SFreddy Xin { 532e2ca90c2SFreddy Xin struct usbnet *dev = netdev_priv(net); 533e2ca90c2SFreddy Xin u16 *eeprom_buff; 534e2ca90c2SFreddy Xin int first_word, last_word; 535e2ca90c2SFreddy Xin int i, ret; 536e2ca90c2SFreddy Xin 537e2ca90c2SFreddy Xin if (eeprom->len == 0) 538e2ca90c2SFreddy Xin return -EINVAL; 539e2ca90c2SFreddy Xin 540e2ca90c2SFreddy Xin eeprom->magic = AX88179_EEPROM_MAGIC; 541e2ca90c2SFreddy Xin 542e2ca90c2SFreddy Xin first_word = eeprom->offset >> 1; 543e2ca90c2SFreddy Xin last_word = (eeprom->offset + eeprom->len - 1) >> 1; 544e2ca90c2SFreddy Xin eeprom_buff = kmalloc(sizeof(u16) * (last_word - first_word + 1), 545e2ca90c2SFreddy Xin GFP_KERNEL); 546e2ca90c2SFreddy Xin if (!eeprom_buff) 547e2ca90c2SFreddy Xin return -ENOMEM; 548e2ca90c2SFreddy Xin 549e2ca90c2SFreddy Xin /* ax88179/178A returns 2 bytes from eeprom on read */ 550e2ca90c2SFreddy Xin for (i = first_word; i <= last_word; i++) { 551e2ca90c2SFreddy Xin ret = __ax88179_read_cmd(dev, AX_ACCESS_EEPROM, i, 1, 2, 552e2ca90c2SFreddy Xin &eeprom_buff[i - first_word], 553e2ca90c2SFreddy Xin 0); 554e2ca90c2SFreddy Xin if (ret < 0) { 555e2ca90c2SFreddy Xin kfree(eeprom_buff); 556e2ca90c2SFreddy Xin return -EIO; 557e2ca90c2SFreddy Xin } 558e2ca90c2SFreddy Xin } 559e2ca90c2SFreddy Xin 560e2ca90c2SFreddy Xin memcpy(data, (u8 *)eeprom_buff + (eeprom->offset & 1), eeprom->len); 561e2ca90c2SFreddy Xin kfree(eeprom_buff); 562e2ca90c2SFreddy Xin return 0; 563e2ca90c2SFreddy Xin } 564e2ca90c2SFreddy Xin 565e2ca90c2SFreddy Xin static int ax88179_get_settings(struct net_device *net, struct ethtool_cmd *cmd) 566e2ca90c2SFreddy Xin { 567e2ca90c2SFreddy Xin struct usbnet *dev = netdev_priv(net); 568e2ca90c2SFreddy Xin return mii_ethtool_gset(&dev->mii, cmd); 569e2ca90c2SFreddy Xin } 570e2ca90c2SFreddy Xin 571e2ca90c2SFreddy Xin static int ax88179_set_settings(struct net_device *net, struct ethtool_cmd *cmd) 572e2ca90c2SFreddy Xin { 573e2ca90c2SFreddy Xin struct usbnet *dev = netdev_priv(net); 574e2ca90c2SFreddy Xin return mii_ethtool_sset(&dev->mii, cmd); 575e2ca90c2SFreddy Xin } 576e2ca90c2SFreddy Xin 577e2ca90c2SFreddy Xin 578e2ca90c2SFreddy Xin static int ax88179_ioctl(struct net_device *net, struct ifreq *rq, int cmd) 579e2ca90c2SFreddy Xin { 580e2ca90c2SFreddy Xin struct usbnet *dev = netdev_priv(net); 581e2ca90c2SFreddy Xin return generic_mii_ioctl(&dev->mii, if_mii(rq), cmd, NULL); 582e2ca90c2SFreddy Xin } 583e2ca90c2SFreddy Xin 584e2ca90c2SFreddy Xin static const struct ethtool_ops ax88179_ethtool_ops = { 585e2ca90c2SFreddy Xin .get_link = ethtool_op_get_link, 586e2ca90c2SFreddy Xin .get_msglevel = usbnet_get_msglevel, 587e2ca90c2SFreddy Xin .set_msglevel = usbnet_set_msglevel, 588e2ca90c2SFreddy Xin .get_wol = ax88179_get_wol, 589e2ca90c2SFreddy Xin .set_wol = ax88179_set_wol, 590e2ca90c2SFreddy Xin .get_eeprom_len = ax88179_get_eeprom_len, 591e2ca90c2SFreddy Xin .get_eeprom = ax88179_get_eeprom, 592e2ca90c2SFreddy Xin .get_settings = ax88179_get_settings, 593e2ca90c2SFreddy Xin .set_settings = ax88179_set_settings, 594e2ca90c2SFreddy Xin .nway_reset = usbnet_nway_reset, 595e2ca90c2SFreddy Xin }; 596e2ca90c2SFreddy Xin 597e2ca90c2SFreddy Xin static void ax88179_set_multicast(struct net_device *net) 598e2ca90c2SFreddy Xin { 599e2ca90c2SFreddy Xin struct usbnet *dev = netdev_priv(net); 600e2ca90c2SFreddy Xin struct ax88179_data *data = (struct ax88179_data *)dev->data; 601e2ca90c2SFreddy Xin u8 *m_filter = ((u8 *)dev->data) + 12; 602e2ca90c2SFreddy Xin 603e2ca90c2SFreddy Xin data->rxctl = (AX_RX_CTL_START | AX_RX_CTL_AB | AX_RX_CTL_IPE); 604e2ca90c2SFreddy Xin 605e2ca90c2SFreddy Xin if (net->flags & IFF_PROMISC) { 606e2ca90c2SFreddy Xin data->rxctl |= AX_RX_CTL_PRO; 607e2ca90c2SFreddy Xin } else if (net->flags & IFF_ALLMULTI || 608e2ca90c2SFreddy Xin netdev_mc_count(net) > AX_MAX_MCAST) { 609e2ca90c2SFreddy Xin data->rxctl |= AX_RX_CTL_AMALL; 610e2ca90c2SFreddy Xin } else if (netdev_mc_empty(net)) { 611e2ca90c2SFreddy Xin /* just broadcast and directed */ 612e2ca90c2SFreddy Xin } else { 613e2ca90c2SFreddy Xin /* We use the 20 byte dev->data for our 8 byte filter buffer 614e2ca90c2SFreddy Xin * to avoid allocating memory that is tricky to free later 615e2ca90c2SFreddy Xin */ 616e2ca90c2SFreddy Xin u32 crc_bits; 617e2ca90c2SFreddy Xin struct netdev_hw_addr *ha; 618e2ca90c2SFreddy Xin 619e2ca90c2SFreddy Xin memset(m_filter, 0, AX_MCAST_FLTSIZE); 620e2ca90c2SFreddy Xin 621e2ca90c2SFreddy Xin netdev_for_each_mc_addr(ha, net) { 622e2ca90c2SFreddy Xin crc_bits = ether_crc(ETH_ALEN, ha->addr) >> 26; 623e2ca90c2SFreddy Xin *(m_filter + (crc_bits >> 3)) |= (1 << (crc_bits & 7)); 624e2ca90c2SFreddy Xin } 625e2ca90c2SFreddy Xin 626e2ca90c2SFreddy Xin ax88179_write_cmd_async(dev, AX_ACCESS_MAC, AX_MULFLTARY, 627e2ca90c2SFreddy Xin AX_MCAST_FLTSIZE, AX_MCAST_FLTSIZE, 628e2ca90c2SFreddy Xin m_filter); 629e2ca90c2SFreddy Xin 630e2ca90c2SFreddy Xin data->rxctl |= AX_RX_CTL_AM; 631e2ca90c2SFreddy Xin } 632e2ca90c2SFreddy Xin 633e2ca90c2SFreddy Xin ax88179_write_cmd_async(dev, AX_ACCESS_MAC, AX_RX_CTL, 634e2ca90c2SFreddy Xin 2, 2, &data->rxctl); 635e2ca90c2SFreddy Xin } 636e2ca90c2SFreddy Xin 637e2ca90c2SFreddy Xin static int 638e2ca90c2SFreddy Xin ax88179_set_features(struct net_device *net, netdev_features_t features) 639e2ca90c2SFreddy Xin { 640e2ca90c2SFreddy Xin u8 tmp; 641e2ca90c2SFreddy Xin struct usbnet *dev = netdev_priv(net); 642e2ca90c2SFreddy Xin netdev_features_t changed = net->features ^ features; 643e2ca90c2SFreddy Xin 644e2ca90c2SFreddy Xin if (changed & NETIF_F_IP_CSUM) { 645e2ca90c2SFreddy Xin ax88179_read_cmd(dev, AX_ACCESS_MAC, AX_TXCOE_CTL, 1, 1, &tmp); 646e2ca90c2SFreddy Xin tmp ^= AX_TXCOE_TCP | AX_TXCOE_UDP; 647e2ca90c2SFreddy Xin ax88179_write_cmd(dev, AX_ACCESS_MAC, AX_TXCOE_CTL, 1, 1, &tmp); 648e2ca90c2SFreddy Xin } 649e2ca90c2SFreddy Xin 650e2ca90c2SFreddy Xin if (changed & NETIF_F_IPV6_CSUM) { 651e2ca90c2SFreddy Xin ax88179_read_cmd(dev, AX_ACCESS_MAC, AX_TXCOE_CTL, 1, 1, &tmp); 652e2ca90c2SFreddy Xin tmp ^= AX_TXCOE_TCPV6 | AX_TXCOE_UDPV6; 653e2ca90c2SFreddy Xin ax88179_write_cmd(dev, AX_ACCESS_MAC, AX_TXCOE_CTL, 1, 1, &tmp); 654e2ca90c2SFreddy Xin } 655e2ca90c2SFreddy Xin 656e2ca90c2SFreddy Xin if (changed & NETIF_F_RXCSUM) { 657e2ca90c2SFreddy Xin ax88179_read_cmd(dev, AX_ACCESS_MAC, AX_RXCOE_CTL, 1, 1, &tmp); 658e2ca90c2SFreddy Xin tmp ^= AX_RXCOE_IP | AX_RXCOE_TCP | AX_RXCOE_UDP | 659e2ca90c2SFreddy Xin AX_RXCOE_TCPV6 | AX_RXCOE_UDPV6; 660e2ca90c2SFreddy Xin ax88179_write_cmd(dev, AX_ACCESS_MAC, AX_RXCOE_CTL, 1, 1, &tmp); 661e2ca90c2SFreddy Xin } 662e2ca90c2SFreddy Xin 663e2ca90c2SFreddy Xin return 0; 664e2ca90c2SFreddy Xin } 665e2ca90c2SFreddy Xin 666e2ca90c2SFreddy Xin static int ax88179_change_mtu(struct net_device *net, int new_mtu) 667e2ca90c2SFreddy Xin { 668e2ca90c2SFreddy Xin struct usbnet *dev = netdev_priv(net); 669e2ca90c2SFreddy Xin u16 tmp16; 670e2ca90c2SFreddy Xin 671e2ca90c2SFreddy Xin if (new_mtu <= 0 || new_mtu > 4088) 672e2ca90c2SFreddy Xin return -EINVAL; 673e2ca90c2SFreddy Xin 674e2ca90c2SFreddy Xin net->mtu = new_mtu; 675e2ca90c2SFreddy Xin dev->hard_mtu = net->mtu + net->hard_header_len; 676e2ca90c2SFreddy Xin 677e2ca90c2SFreddy Xin if (net->mtu > 1500) { 678e2ca90c2SFreddy Xin ax88179_read_cmd(dev, AX_ACCESS_MAC, AX_MEDIUM_STATUS_MODE, 679e2ca90c2SFreddy Xin 2, 2, &tmp16); 680e2ca90c2SFreddy Xin tmp16 |= AX_MEDIUM_JUMBO_EN; 681e2ca90c2SFreddy Xin ax88179_write_cmd(dev, AX_ACCESS_MAC, AX_MEDIUM_STATUS_MODE, 682e2ca90c2SFreddy Xin 2, 2, &tmp16); 683e2ca90c2SFreddy Xin } else { 684e2ca90c2SFreddy Xin ax88179_read_cmd(dev, AX_ACCESS_MAC, AX_MEDIUM_STATUS_MODE, 685e2ca90c2SFreddy Xin 2, 2, &tmp16); 686e2ca90c2SFreddy Xin tmp16 &= ~AX_MEDIUM_JUMBO_EN; 687e2ca90c2SFreddy Xin ax88179_write_cmd(dev, AX_ACCESS_MAC, AX_MEDIUM_STATUS_MODE, 688e2ca90c2SFreddy Xin 2, 2, &tmp16); 689e2ca90c2SFreddy Xin } 690e2ca90c2SFreddy Xin 691a88c32aeSMing Lei /* max qlen depend on hard_mtu and rx_urb_size */ 692a88c32aeSMing Lei usbnet_update_max_qlen(dev); 693a88c32aeSMing Lei 694e2ca90c2SFreddy Xin return 0; 695e2ca90c2SFreddy Xin } 696e2ca90c2SFreddy Xin 697e2ca90c2SFreddy Xin static int ax88179_set_mac_addr(struct net_device *net, void *p) 698e2ca90c2SFreddy Xin { 699e2ca90c2SFreddy Xin struct usbnet *dev = netdev_priv(net); 700e2ca90c2SFreddy Xin struct sockaddr *addr = p; 701e2ca90c2SFreddy Xin 702e2ca90c2SFreddy Xin if (netif_running(net)) 703e2ca90c2SFreddy Xin return -EBUSY; 704e2ca90c2SFreddy Xin if (!is_valid_ether_addr(addr->sa_data)) 705e2ca90c2SFreddy Xin return -EADDRNOTAVAIL; 706e2ca90c2SFreddy Xin 707e2ca90c2SFreddy Xin memcpy(net->dev_addr, addr->sa_data, ETH_ALEN); 708e2ca90c2SFreddy Xin 709e2ca90c2SFreddy Xin /* Set the MAC address */ 710e2ca90c2SFreddy Xin return ax88179_write_cmd(dev, AX_ACCESS_MAC, AX_NODE_ID, ETH_ALEN, 711e2ca90c2SFreddy Xin ETH_ALEN, net->dev_addr); 712e2ca90c2SFreddy Xin } 713e2ca90c2SFreddy Xin 714e2ca90c2SFreddy Xin static const struct net_device_ops ax88179_netdev_ops = { 715e2ca90c2SFreddy Xin .ndo_open = usbnet_open, 716e2ca90c2SFreddy Xin .ndo_stop = usbnet_stop, 717e2ca90c2SFreddy Xin .ndo_start_xmit = usbnet_start_xmit, 718e2ca90c2SFreddy Xin .ndo_tx_timeout = usbnet_tx_timeout, 719e2ca90c2SFreddy Xin .ndo_change_mtu = ax88179_change_mtu, 720e2ca90c2SFreddy Xin .ndo_set_mac_address = ax88179_set_mac_addr, 721e2ca90c2SFreddy Xin .ndo_validate_addr = eth_validate_addr, 722e2ca90c2SFreddy Xin .ndo_do_ioctl = ax88179_ioctl, 723e2ca90c2SFreddy Xin .ndo_set_rx_mode = ax88179_set_multicast, 724e2ca90c2SFreddy Xin .ndo_set_features = ax88179_set_features, 725e2ca90c2SFreddy Xin }; 726e2ca90c2SFreddy Xin 727e2ca90c2SFreddy Xin static int ax88179_check_eeprom(struct usbnet *dev) 728e2ca90c2SFreddy Xin { 729e2ca90c2SFreddy Xin u8 i, buf, eeprom[20]; 730e2ca90c2SFreddy Xin u16 csum, delay = HZ / 10; 731e2ca90c2SFreddy Xin unsigned long jtimeout; 732e2ca90c2SFreddy Xin 733e2ca90c2SFreddy Xin /* Read EEPROM content */ 734e2ca90c2SFreddy Xin for (i = 0; i < 6; i++) { 735e2ca90c2SFreddy Xin buf = i; 736e2ca90c2SFreddy Xin if (ax88179_write_cmd(dev, AX_ACCESS_MAC, AX_SROM_ADDR, 737e2ca90c2SFreddy Xin 1, 1, &buf) < 0) 738e2ca90c2SFreddy Xin return -EINVAL; 739e2ca90c2SFreddy Xin 740e2ca90c2SFreddy Xin buf = EEP_RD; 741e2ca90c2SFreddy Xin if (ax88179_write_cmd(dev, AX_ACCESS_MAC, AX_SROM_CMD, 742e2ca90c2SFreddy Xin 1, 1, &buf) < 0) 743e2ca90c2SFreddy Xin return -EINVAL; 744e2ca90c2SFreddy Xin 745e2ca90c2SFreddy Xin jtimeout = jiffies + delay; 746e2ca90c2SFreddy Xin do { 747e2ca90c2SFreddy Xin ax88179_read_cmd(dev, AX_ACCESS_MAC, AX_SROM_CMD, 748e2ca90c2SFreddy Xin 1, 1, &buf); 749e2ca90c2SFreddy Xin 750e2ca90c2SFreddy Xin if (time_after(jiffies, jtimeout)) 751e2ca90c2SFreddy Xin return -EINVAL; 752e2ca90c2SFreddy Xin 753e2ca90c2SFreddy Xin } while (buf & EEP_BUSY); 754e2ca90c2SFreddy Xin 755e2ca90c2SFreddy Xin __ax88179_read_cmd(dev, AX_ACCESS_MAC, AX_SROM_DATA_LOW, 756e2ca90c2SFreddy Xin 2, 2, &eeprom[i * 2], 0); 757e2ca90c2SFreddy Xin 758e2ca90c2SFreddy Xin if ((i == 0) && (eeprom[0] == 0xFF)) 759e2ca90c2SFreddy Xin return -EINVAL; 760e2ca90c2SFreddy Xin } 761e2ca90c2SFreddy Xin 762e2ca90c2SFreddy Xin csum = eeprom[6] + eeprom[7] + eeprom[8] + eeprom[9]; 763e2ca90c2SFreddy Xin csum = (csum >> 8) + (csum & 0xff); 764e2ca90c2SFreddy Xin if ((csum + eeprom[10]) != 0xff) 765e2ca90c2SFreddy Xin return -EINVAL; 766e2ca90c2SFreddy Xin 767e2ca90c2SFreddy Xin return 0; 768e2ca90c2SFreddy Xin } 769e2ca90c2SFreddy Xin 770e2ca90c2SFreddy Xin static int ax88179_check_efuse(struct usbnet *dev, u16 *ledmode) 771e2ca90c2SFreddy Xin { 772e2ca90c2SFreddy Xin u8 i; 773e2ca90c2SFreddy Xin u8 efuse[64]; 774e2ca90c2SFreddy Xin u16 csum = 0; 775e2ca90c2SFreddy Xin 776e2ca90c2SFreddy Xin if (ax88179_read_cmd(dev, AX_ACCESS_EFUS, 0, 64, 64, efuse) < 0) 777e2ca90c2SFreddy Xin return -EINVAL; 778e2ca90c2SFreddy Xin 779e2ca90c2SFreddy Xin if (*efuse == 0xFF) 780e2ca90c2SFreddy Xin return -EINVAL; 781e2ca90c2SFreddy Xin 782e2ca90c2SFreddy Xin for (i = 0; i < 64; i++) 783e2ca90c2SFreddy Xin csum = csum + efuse[i]; 784e2ca90c2SFreddy Xin 785e2ca90c2SFreddy Xin while (csum > 255) 786e2ca90c2SFreddy Xin csum = (csum & 0x00FF) + ((csum >> 8) & 0x00FF); 787e2ca90c2SFreddy Xin 788e2ca90c2SFreddy Xin if (csum != 0xFF) 789e2ca90c2SFreddy Xin return -EINVAL; 790e2ca90c2SFreddy Xin 791e2ca90c2SFreddy Xin *ledmode = (efuse[51] << 8) | efuse[52]; 792e2ca90c2SFreddy Xin 793e2ca90c2SFreddy Xin return 0; 794e2ca90c2SFreddy Xin } 795e2ca90c2SFreddy Xin 796e2ca90c2SFreddy Xin static int ax88179_convert_old_led(struct usbnet *dev, u16 *ledvalue) 797e2ca90c2SFreddy Xin { 798e2ca90c2SFreddy Xin u16 led; 799e2ca90c2SFreddy Xin 800e2ca90c2SFreddy Xin /* Loaded the old eFuse LED Mode */ 801e2ca90c2SFreddy Xin if (ax88179_read_cmd(dev, AX_ACCESS_EEPROM, 0x3C, 1, 2, &led) < 0) 802e2ca90c2SFreddy Xin return -EINVAL; 803e2ca90c2SFreddy Xin 804e2ca90c2SFreddy Xin led >>= 8; 805e2ca90c2SFreddy Xin switch (led) { 806e2ca90c2SFreddy Xin case 0xFF: 807e2ca90c2SFreddy Xin led = LED0_ACTIVE | LED1_LINK_10 | LED1_LINK_100 | 808e2ca90c2SFreddy Xin LED1_LINK_1000 | LED2_ACTIVE | LED2_LINK_10 | 809e2ca90c2SFreddy Xin LED2_LINK_100 | LED2_LINK_1000 | LED_VALID; 810e2ca90c2SFreddy Xin break; 811e2ca90c2SFreddy Xin case 0xFE: 812e2ca90c2SFreddy Xin led = LED0_ACTIVE | LED1_LINK_1000 | LED2_LINK_100 | LED_VALID; 813e2ca90c2SFreddy Xin break; 814e2ca90c2SFreddy Xin case 0xFD: 815e2ca90c2SFreddy Xin led = LED0_ACTIVE | LED1_LINK_1000 | LED2_LINK_100 | 816e2ca90c2SFreddy Xin LED2_LINK_10 | LED_VALID; 817e2ca90c2SFreddy Xin break; 818e2ca90c2SFreddy Xin case 0xFC: 819e2ca90c2SFreddy Xin led = LED0_ACTIVE | LED1_ACTIVE | LED1_LINK_1000 | LED2_ACTIVE | 820e2ca90c2SFreddy Xin LED2_LINK_100 | LED2_LINK_10 | LED_VALID; 821e2ca90c2SFreddy Xin break; 822e2ca90c2SFreddy Xin default: 823e2ca90c2SFreddy Xin led = LED0_ACTIVE | LED1_LINK_10 | LED1_LINK_100 | 824e2ca90c2SFreddy Xin LED1_LINK_1000 | LED2_ACTIVE | LED2_LINK_10 | 825e2ca90c2SFreddy Xin LED2_LINK_100 | LED2_LINK_1000 | LED_VALID; 826e2ca90c2SFreddy Xin break; 827e2ca90c2SFreddy Xin } 828e2ca90c2SFreddy Xin 829e2ca90c2SFreddy Xin *ledvalue = led; 830e2ca90c2SFreddy Xin 831e2ca90c2SFreddy Xin return 0; 832e2ca90c2SFreddy Xin } 833e2ca90c2SFreddy Xin 834e2ca90c2SFreddy Xin static int ax88179_led_setting(struct usbnet *dev) 835e2ca90c2SFreddy Xin { 836e2ca90c2SFreddy Xin u8 ledfd, value = 0; 837e2ca90c2SFreddy Xin u16 tmp, ledact, ledlink, ledvalue = 0, delay = HZ / 10; 838e2ca90c2SFreddy Xin unsigned long jtimeout; 839e2ca90c2SFreddy Xin 840e2ca90c2SFreddy Xin /* Check AX88179 version. UA1 or UA2*/ 841e2ca90c2SFreddy Xin ax88179_read_cmd(dev, AX_ACCESS_MAC, GENERAL_STATUS, 1, 1, &value); 842e2ca90c2SFreddy Xin 843e2ca90c2SFreddy Xin if (!(value & AX_SECLD)) { /* UA1 */ 844e2ca90c2SFreddy Xin value = AX_GPIO_CTRL_GPIO3EN | AX_GPIO_CTRL_GPIO2EN | 845e2ca90c2SFreddy Xin AX_GPIO_CTRL_GPIO1EN; 846e2ca90c2SFreddy Xin if (ax88179_write_cmd(dev, AX_ACCESS_MAC, AX_GPIO_CTRL, 847e2ca90c2SFreddy Xin 1, 1, &value) < 0) 848e2ca90c2SFreddy Xin return -EINVAL; 849e2ca90c2SFreddy Xin } 850e2ca90c2SFreddy Xin 851e2ca90c2SFreddy Xin /* Check EEPROM */ 852e2ca90c2SFreddy Xin if (!ax88179_check_eeprom(dev)) { 853e2ca90c2SFreddy Xin value = 0x42; 854e2ca90c2SFreddy Xin if (ax88179_write_cmd(dev, AX_ACCESS_MAC, AX_SROM_ADDR, 855e2ca90c2SFreddy Xin 1, 1, &value) < 0) 856e2ca90c2SFreddy Xin return -EINVAL; 857e2ca90c2SFreddy Xin 858e2ca90c2SFreddy Xin value = EEP_RD; 859e2ca90c2SFreddy Xin if (ax88179_write_cmd(dev, AX_ACCESS_MAC, AX_SROM_CMD, 860e2ca90c2SFreddy Xin 1, 1, &value) < 0) 861e2ca90c2SFreddy Xin return -EINVAL; 862e2ca90c2SFreddy Xin 863e2ca90c2SFreddy Xin jtimeout = jiffies + delay; 864e2ca90c2SFreddy Xin do { 865e2ca90c2SFreddy Xin ax88179_read_cmd(dev, AX_ACCESS_MAC, AX_SROM_CMD, 866e2ca90c2SFreddy Xin 1, 1, &value); 867e2ca90c2SFreddy Xin 868e2ca90c2SFreddy Xin if (time_after(jiffies, jtimeout)) 869e2ca90c2SFreddy Xin return -EINVAL; 870e2ca90c2SFreddy Xin 871e2ca90c2SFreddy Xin } while (value & EEP_BUSY); 872e2ca90c2SFreddy Xin 873e2ca90c2SFreddy Xin ax88179_read_cmd(dev, AX_ACCESS_MAC, AX_SROM_DATA_HIGH, 874e2ca90c2SFreddy Xin 1, 1, &value); 875e2ca90c2SFreddy Xin ledvalue = (value << 8); 876e2ca90c2SFreddy Xin 877e2ca90c2SFreddy Xin ax88179_read_cmd(dev, AX_ACCESS_MAC, AX_SROM_DATA_LOW, 878e2ca90c2SFreddy Xin 1, 1, &value); 879e2ca90c2SFreddy Xin ledvalue |= value; 880e2ca90c2SFreddy Xin 881e2ca90c2SFreddy Xin /* load internal ROM for defaule setting */ 882e2ca90c2SFreddy Xin if ((ledvalue == 0xFFFF) || ((ledvalue & LED_VALID) == 0)) 883e2ca90c2SFreddy Xin ax88179_convert_old_led(dev, &ledvalue); 884e2ca90c2SFreddy Xin 885e2ca90c2SFreddy Xin } else if (!ax88179_check_efuse(dev, &ledvalue)) { 886e2ca90c2SFreddy Xin if ((ledvalue == 0xFFFF) || ((ledvalue & LED_VALID) == 0)) 887e2ca90c2SFreddy Xin ax88179_convert_old_led(dev, &ledvalue); 888e2ca90c2SFreddy Xin } else { 889e2ca90c2SFreddy Xin ax88179_convert_old_led(dev, &ledvalue); 890e2ca90c2SFreddy Xin } 891e2ca90c2SFreddy Xin 892e2ca90c2SFreddy Xin tmp = GMII_PHY_PGSEL_EXT; 893e2ca90c2SFreddy Xin ax88179_write_cmd(dev, AX_ACCESS_PHY, AX88179_PHY_ID, 894e2ca90c2SFreddy Xin GMII_PHY_PAGE_SELECT, 2, &tmp); 895e2ca90c2SFreddy Xin 896e2ca90c2SFreddy Xin tmp = 0x2c; 897e2ca90c2SFreddy Xin ax88179_write_cmd(dev, AX_ACCESS_PHY, AX88179_PHY_ID, 898e2ca90c2SFreddy Xin GMII_PHYPAGE, 2, &tmp); 899e2ca90c2SFreddy Xin 900e2ca90c2SFreddy Xin ax88179_read_cmd(dev, AX_ACCESS_PHY, AX88179_PHY_ID, 901e2ca90c2SFreddy Xin GMII_LED_ACT, 2, &ledact); 902e2ca90c2SFreddy Xin 903e2ca90c2SFreddy Xin ax88179_read_cmd(dev, AX_ACCESS_PHY, AX88179_PHY_ID, 904e2ca90c2SFreddy Xin GMII_LED_LINK, 2, &ledlink); 905e2ca90c2SFreddy Xin 906e2ca90c2SFreddy Xin ledact &= GMII_LED_ACTIVE_MASK; 907e2ca90c2SFreddy Xin ledlink &= GMII_LED_LINK_MASK; 908e2ca90c2SFreddy Xin 909e2ca90c2SFreddy Xin if (ledvalue & LED0_ACTIVE) 910e2ca90c2SFreddy Xin ledact |= GMII_LED0_ACTIVE; 911e2ca90c2SFreddy Xin 912e2ca90c2SFreddy Xin if (ledvalue & LED1_ACTIVE) 913e2ca90c2SFreddy Xin ledact |= GMII_LED1_ACTIVE; 914e2ca90c2SFreddy Xin 915e2ca90c2SFreddy Xin if (ledvalue & LED2_ACTIVE) 916e2ca90c2SFreddy Xin ledact |= GMII_LED2_ACTIVE; 917e2ca90c2SFreddy Xin 918e2ca90c2SFreddy Xin if (ledvalue & LED0_LINK_10) 919e2ca90c2SFreddy Xin ledlink |= GMII_LED0_LINK_10; 920e2ca90c2SFreddy Xin 921e2ca90c2SFreddy Xin if (ledvalue & LED1_LINK_10) 922e2ca90c2SFreddy Xin ledlink |= GMII_LED1_LINK_10; 923e2ca90c2SFreddy Xin 924e2ca90c2SFreddy Xin if (ledvalue & LED2_LINK_10) 925e2ca90c2SFreddy Xin ledlink |= GMII_LED2_LINK_10; 926e2ca90c2SFreddy Xin 927e2ca90c2SFreddy Xin if (ledvalue & LED0_LINK_100) 928e2ca90c2SFreddy Xin ledlink |= GMII_LED0_LINK_100; 929e2ca90c2SFreddy Xin 930e2ca90c2SFreddy Xin if (ledvalue & LED1_LINK_100) 931e2ca90c2SFreddy Xin ledlink |= GMII_LED1_LINK_100; 932e2ca90c2SFreddy Xin 933e2ca90c2SFreddy Xin if (ledvalue & LED2_LINK_100) 934e2ca90c2SFreddy Xin ledlink |= GMII_LED2_LINK_100; 935e2ca90c2SFreddy Xin 936e2ca90c2SFreddy Xin if (ledvalue & LED0_LINK_1000) 937e2ca90c2SFreddy Xin ledlink |= GMII_LED0_LINK_1000; 938e2ca90c2SFreddy Xin 939e2ca90c2SFreddy Xin if (ledvalue & LED1_LINK_1000) 940e2ca90c2SFreddy Xin ledlink |= GMII_LED1_LINK_1000; 941e2ca90c2SFreddy Xin 942e2ca90c2SFreddy Xin if (ledvalue & LED2_LINK_1000) 943e2ca90c2SFreddy Xin ledlink |= GMII_LED2_LINK_1000; 944e2ca90c2SFreddy Xin 945e2ca90c2SFreddy Xin tmp = ledact; 946e2ca90c2SFreddy Xin ax88179_write_cmd(dev, AX_ACCESS_PHY, AX88179_PHY_ID, 947e2ca90c2SFreddy Xin GMII_LED_ACT, 2, &tmp); 948e2ca90c2SFreddy Xin 949e2ca90c2SFreddy Xin tmp = ledlink; 950e2ca90c2SFreddy Xin ax88179_write_cmd(dev, AX_ACCESS_PHY, AX88179_PHY_ID, 951e2ca90c2SFreddy Xin GMII_LED_LINK, 2, &tmp); 952e2ca90c2SFreddy Xin 953e2ca90c2SFreddy Xin tmp = GMII_PHY_PGSEL_PAGE0; 954e2ca90c2SFreddy Xin ax88179_write_cmd(dev, AX_ACCESS_PHY, AX88179_PHY_ID, 955e2ca90c2SFreddy Xin GMII_PHY_PAGE_SELECT, 2, &tmp); 956e2ca90c2SFreddy Xin 957e2ca90c2SFreddy Xin /* LED full duplex setting */ 958e2ca90c2SFreddy Xin ledfd = 0; 959e2ca90c2SFreddy Xin if (ledvalue & LED0_FD) 960e2ca90c2SFreddy Xin ledfd |= 0x01; 961e2ca90c2SFreddy Xin else if ((ledvalue & LED0_USB3_MASK) == 0) 962e2ca90c2SFreddy Xin ledfd |= 0x02; 963e2ca90c2SFreddy Xin 964e2ca90c2SFreddy Xin if (ledvalue & LED1_FD) 965e2ca90c2SFreddy Xin ledfd |= 0x04; 966e2ca90c2SFreddy Xin else if ((ledvalue & LED1_USB3_MASK) == 0) 967e2ca90c2SFreddy Xin ledfd |= 0x08; 968e2ca90c2SFreddy Xin 969e2ca90c2SFreddy Xin if (ledvalue & LED2_FD) 970e2ca90c2SFreddy Xin ledfd |= 0x10; 971e2ca90c2SFreddy Xin else if ((ledvalue & LED2_USB3_MASK) == 0) 972e2ca90c2SFreddy Xin ledfd |= 0x20; 973e2ca90c2SFreddy Xin 974e2ca90c2SFreddy Xin ax88179_write_cmd(dev, AX_ACCESS_MAC, AX_LEDCTRL, 1, 1, &ledfd); 975e2ca90c2SFreddy Xin 976e2ca90c2SFreddy Xin return 0; 977e2ca90c2SFreddy Xin } 978e2ca90c2SFreddy Xin 979e2ca90c2SFreddy Xin static int ax88179_bind(struct usbnet *dev, struct usb_interface *intf) 980e2ca90c2SFreddy Xin { 981e2ca90c2SFreddy Xin u8 buf[5]; 982e2ca90c2SFreddy Xin u16 *tmp16; 983e2ca90c2SFreddy Xin u8 *tmp; 984e2ca90c2SFreddy Xin struct ax88179_data *ax179_data = (struct ax88179_data *)dev->data; 985e2ca90c2SFreddy Xin 986e2ca90c2SFreddy Xin usbnet_get_endpoints(dev, intf); 987e2ca90c2SFreddy Xin 988e2ca90c2SFreddy Xin tmp16 = (u16 *)buf; 989e2ca90c2SFreddy Xin tmp = (u8 *)buf; 990e2ca90c2SFreddy Xin 991e2ca90c2SFreddy Xin memset(ax179_data, 0, sizeof(*ax179_data)); 992e2ca90c2SFreddy Xin 993e2ca90c2SFreddy Xin /* Power up ethernet PHY */ 994e2ca90c2SFreddy Xin *tmp16 = 0; 995e2ca90c2SFreddy Xin ax88179_write_cmd(dev, AX_ACCESS_MAC, AX_PHYPWR_RSTCTL, 2, 2, tmp16); 996e2ca90c2SFreddy Xin *tmp16 = AX_PHYPWR_RSTCTL_IPRL; 997e2ca90c2SFreddy Xin ax88179_write_cmd(dev, AX_ACCESS_MAC, AX_PHYPWR_RSTCTL, 2, 2, tmp16); 998e2ca90c2SFreddy Xin msleep(200); 999e2ca90c2SFreddy Xin 1000e2ca90c2SFreddy Xin *tmp = AX_CLK_SELECT_ACS | AX_CLK_SELECT_BCS; 1001e2ca90c2SFreddy Xin ax88179_write_cmd(dev, AX_ACCESS_MAC, AX_CLK_SELECT, 1, 1, tmp); 1002e2ca90c2SFreddy Xin msleep(100); 1003e2ca90c2SFreddy Xin 1004e2ca90c2SFreddy Xin ax88179_read_cmd(dev, AX_ACCESS_MAC, AX_NODE_ID, ETH_ALEN, 1005e2ca90c2SFreddy Xin ETH_ALEN, dev->net->dev_addr); 1006e2ca90c2SFreddy Xin memcpy(dev->net->perm_addr, dev->net->dev_addr, ETH_ALEN); 1007e2ca90c2SFreddy Xin 1008e2ca90c2SFreddy Xin /* RX bulk configuration */ 1009e2ca90c2SFreddy Xin memcpy(tmp, &AX88179_BULKIN_SIZE[0], 5); 1010e2ca90c2SFreddy Xin ax88179_write_cmd(dev, AX_ACCESS_MAC, AX_RX_BULKIN_QCTRL, 5, 5, tmp); 1011e2ca90c2SFreddy Xin 1012e2ca90c2SFreddy Xin dev->rx_urb_size = 1024 * 20; 1013e2ca90c2SFreddy Xin 1014e2ca90c2SFreddy Xin *tmp = 0x34; 1015e2ca90c2SFreddy Xin ax88179_write_cmd(dev, AX_ACCESS_MAC, AX_PAUSE_WATERLVL_LOW, 1, 1, tmp); 1016e2ca90c2SFreddy Xin 1017e2ca90c2SFreddy Xin *tmp = 0x52; 1018e2ca90c2SFreddy Xin ax88179_write_cmd(dev, AX_ACCESS_MAC, AX_PAUSE_WATERLVL_HIGH, 1019e2ca90c2SFreddy Xin 1, 1, tmp); 1020e2ca90c2SFreddy Xin 1021e2ca90c2SFreddy Xin dev->net->netdev_ops = &ax88179_netdev_ops; 1022e2ca90c2SFreddy Xin dev->net->ethtool_ops = &ax88179_ethtool_ops; 1023e2ca90c2SFreddy Xin dev->net->needed_headroom = 8; 1024e2ca90c2SFreddy Xin 1025e2ca90c2SFreddy Xin /* Initialize MII structure */ 1026e2ca90c2SFreddy Xin dev->mii.dev = dev->net; 1027e2ca90c2SFreddy Xin dev->mii.mdio_read = ax88179_mdio_read; 1028e2ca90c2SFreddy Xin dev->mii.mdio_write = ax88179_mdio_write; 1029e2ca90c2SFreddy Xin dev->mii.phy_id_mask = 0xff; 1030e2ca90c2SFreddy Xin dev->mii.reg_num_mask = 0xff; 1031e2ca90c2SFreddy Xin dev->mii.phy_id = 0x03; 1032e2ca90c2SFreddy Xin dev->mii.supports_gmii = 1; 1033e2ca90c2SFreddy Xin 10343804fad4SMing Lei if (usb_device_no_sg_constraint(dev->udev)) 10353804fad4SMing Lei dev->can_dma_sg = 1; 10363804fad4SMing Lei 1037e2ca90c2SFreddy Xin dev->net->features |= NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM | 103820f01703SEric Dumazet NETIF_F_RXCSUM; 1039e2ca90c2SFreddy Xin 1040e2ca90c2SFreddy Xin dev->net->hw_features |= NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM | 104120f01703SEric Dumazet NETIF_F_RXCSUM; 1042e2ca90c2SFreddy Xin 10433804fad4SMing Lei if (dev->can_dma_sg) { 10443804fad4SMing Lei dev->net->features |= NETIF_F_SG | NETIF_F_TSO; 10453804fad4SMing Lei dev->net->hw_features |= NETIF_F_SG | NETIF_F_TSO; 10463804fad4SMing Lei } 10473804fad4SMing Lei 1048e2ca90c2SFreddy Xin /* Enable checksum offload */ 1049e2ca90c2SFreddy Xin *tmp = AX_RXCOE_IP | AX_RXCOE_TCP | AX_RXCOE_UDP | 1050e2ca90c2SFreddy Xin AX_RXCOE_TCPV6 | AX_RXCOE_UDPV6; 1051e2ca90c2SFreddy Xin ax88179_write_cmd(dev, AX_ACCESS_MAC, AX_RXCOE_CTL, 1, 1, tmp); 1052e2ca90c2SFreddy Xin 1053e2ca90c2SFreddy Xin *tmp = AX_TXCOE_IP | AX_TXCOE_TCP | AX_TXCOE_UDP | 1054e2ca90c2SFreddy Xin AX_TXCOE_TCPV6 | AX_TXCOE_UDPV6; 1055e2ca90c2SFreddy Xin ax88179_write_cmd(dev, AX_ACCESS_MAC, AX_TXCOE_CTL, 1, 1, tmp); 1056e2ca90c2SFreddy Xin 1057e2ca90c2SFreddy Xin /* Configure RX control register => start operation */ 1058e2ca90c2SFreddy Xin *tmp16 = AX_RX_CTL_DROPCRCERR | AX_RX_CTL_IPE | AX_RX_CTL_START | 1059e2ca90c2SFreddy Xin AX_RX_CTL_AP | AX_RX_CTL_AMALL | AX_RX_CTL_AB; 1060e2ca90c2SFreddy Xin ax88179_write_cmd(dev, AX_ACCESS_MAC, AX_RX_CTL, 2, 2, tmp16); 1061e2ca90c2SFreddy Xin 1062e2ca90c2SFreddy Xin *tmp = AX_MONITOR_MODE_PMETYPE | AX_MONITOR_MODE_PMEPOL | 1063e2ca90c2SFreddy Xin AX_MONITOR_MODE_RWMP; 1064e2ca90c2SFreddy Xin ax88179_write_cmd(dev, AX_ACCESS_MAC, AX_MONITOR_MOD, 1, 1, tmp); 1065e2ca90c2SFreddy Xin 1066e2ca90c2SFreddy Xin /* Configure default medium type => giga */ 1067e2ca90c2SFreddy Xin *tmp16 = AX_MEDIUM_RECEIVE_EN | AX_MEDIUM_TXFLOW_CTRLEN | 1068e2ca90c2SFreddy Xin AX_MEDIUM_RXFLOW_CTRLEN | AX_MEDIUM_ALWAYS_ONE | 1069e2ca90c2SFreddy Xin AX_MEDIUM_FULL_DUPLEX | AX_MEDIUM_GIGAMODE; 1070e2ca90c2SFreddy Xin ax88179_write_cmd(dev, AX_ACCESS_MAC, AX_MEDIUM_STATUS_MODE, 1071e2ca90c2SFreddy Xin 2, 2, tmp16); 1072e2ca90c2SFreddy Xin 1073e2ca90c2SFreddy Xin ax88179_led_setting(dev); 1074e2ca90c2SFreddy Xin 1075e2ca90c2SFreddy Xin /* Restart autoneg */ 1076e2ca90c2SFreddy Xin mii_nway_restart(&dev->mii); 1077e2ca90c2SFreddy Xin 10787a97856eSMing Lei usbnet_link_change(dev, 0, 0); 1079e2ca90c2SFreddy Xin 1080e2ca90c2SFreddy Xin return 0; 1081e2ca90c2SFreddy Xin } 1082e2ca90c2SFreddy Xin 1083e2ca90c2SFreddy Xin static void ax88179_unbind(struct usbnet *dev, struct usb_interface *intf) 1084e2ca90c2SFreddy Xin { 1085e2ca90c2SFreddy Xin u16 tmp16; 1086e2ca90c2SFreddy Xin 1087e2ca90c2SFreddy Xin /* Configure RX control register => stop operation */ 1088e2ca90c2SFreddy Xin tmp16 = AX_RX_CTL_STOP; 1089e2ca90c2SFreddy Xin ax88179_write_cmd(dev, AX_ACCESS_MAC, AX_RX_CTL, 2, 2, &tmp16); 1090e2ca90c2SFreddy Xin 1091e2ca90c2SFreddy Xin tmp16 = 0; 1092e2ca90c2SFreddy Xin ax88179_write_cmd(dev, AX_ACCESS_MAC, AX_CLK_SELECT, 1, 1, &tmp16); 1093e2ca90c2SFreddy Xin 1094e2ca90c2SFreddy Xin /* Power down ethernet PHY */ 1095e2ca90c2SFreddy Xin tmp16 = 0; 1096e2ca90c2SFreddy Xin ax88179_write_cmd(dev, AX_ACCESS_MAC, AX_PHYPWR_RSTCTL, 2, 2, &tmp16); 1097e2ca90c2SFreddy Xin } 1098e2ca90c2SFreddy Xin 1099e2ca90c2SFreddy Xin static void 1100e2ca90c2SFreddy Xin ax88179_rx_checksum(struct sk_buff *skb, u32 *pkt_hdr) 1101e2ca90c2SFreddy Xin { 1102e2ca90c2SFreddy Xin skb->ip_summed = CHECKSUM_NONE; 1103e2ca90c2SFreddy Xin 1104e2ca90c2SFreddy Xin /* checksum error bit is set */ 1105e2ca90c2SFreddy Xin if ((*pkt_hdr & AX_RXHDR_L3CSUM_ERR) || 1106e2ca90c2SFreddy Xin (*pkt_hdr & AX_RXHDR_L4CSUM_ERR)) 1107e2ca90c2SFreddy Xin return; 1108e2ca90c2SFreddy Xin 1109e2ca90c2SFreddy Xin /* It must be a TCP or UDP packet with a valid checksum */ 1110e2ca90c2SFreddy Xin if (((*pkt_hdr & AX_RXHDR_L4_TYPE_MASK) == AX_RXHDR_L4_TYPE_TCP) || 1111e2ca90c2SFreddy Xin ((*pkt_hdr & AX_RXHDR_L4_TYPE_MASK) == AX_RXHDR_L4_TYPE_UDP)) 1112e2ca90c2SFreddy Xin skb->ip_summed = CHECKSUM_UNNECESSARY; 1113e2ca90c2SFreddy Xin } 1114e2ca90c2SFreddy Xin 1115e2ca90c2SFreddy Xin static int ax88179_rx_fixup(struct usbnet *dev, struct sk_buff *skb) 1116e2ca90c2SFreddy Xin { 1117e2ca90c2SFreddy Xin struct sk_buff *ax_skb; 1118e2ca90c2SFreddy Xin int pkt_cnt; 1119e2ca90c2SFreddy Xin u32 rx_hdr; 1120e2ca90c2SFreddy Xin u16 hdr_off; 1121e2ca90c2SFreddy Xin u32 *pkt_hdr; 1122e2ca90c2SFreddy Xin 1123e2ca90c2SFreddy Xin skb_trim(skb, skb->len - 4); 1124e2ca90c2SFreddy Xin memcpy(&rx_hdr, skb_tail_pointer(skb), 4); 1125e2ca90c2SFreddy Xin le32_to_cpus(&rx_hdr); 1126e2ca90c2SFreddy Xin 1127e2ca90c2SFreddy Xin pkt_cnt = (u16)rx_hdr; 1128e2ca90c2SFreddy Xin hdr_off = (u16)(rx_hdr >> 16); 1129e2ca90c2SFreddy Xin pkt_hdr = (u32 *)(skb->data + hdr_off); 1130e2ca90c2SFreddy Xin 1131e2ca90c2SFreddy Xin while (pkt_cnt--) { 1132e2ca90c2SFreddy Xin u16 pkt_len; 1133e2ca90c2SFreddy Xin 1134e2ca90c2SFreddy Xin le32_to_cpus(pkt_hdr); 1135e2ca90c2SFreddy Xin pkt_len = (*pkt_hdr >> 16) & 0x1fff; 1136e2ca90c2SFreddy Xin 1137e2ca90c2SFreddy Xin /* Check CRC or runt packet */ 1138e2ca90c2SFreddy Xin if ((*pkt_hdr & AX_RXHDR_CRC_ERR) || 1139e2ca90c2SFreddy Xin (*pkt_hdr & AX_RXHDR_DROP_ERR)) { 1140e2ca90c2SFreddy Xin skb_pull(skb, (pkt_len + 7) & 0xFFF8); 1141e2ca90c2SFreddy Xin pkt_hdr++; 1142e2ca90c2SFreddy Xin continue; 1143e2ca90c2SFreddy Xin } 1144e2ca90c2SFreddy Xin 1145e2ca90c2SFreddy Xin if (pkt_cnt == 0) { 1146e2ca90c2SFreddy Xin /* Skip IP alignment psudo header */ 1147e2ca90c2SFreddy Xin skb_pull(skb, 2); 1148e2ca90c2SFreddy Xin skb->len = pkt_len; 1149e2ca90c2SFreddy Xin skb_set_tail_pointer(skb, pkt_len); 1150e2ca90c2SFreddy Xin skb->truesize = pkt_len + sizeof(struct sk_buff); 1151e2ca90c2SFreddy Xin ax88179_rx_checksum(skb, pkt_hdr); 1152e2ca90c2SFreddy Xin return 1; 1153e2ca90c2SFreddy Xin } 1154e2ca90c2SFreddy Xin 1155e2ca90c2SFreddy Xin ax_skb = skb_clone(skb, GFP_ATOMIC); 1156e2ca90c2SFreddy Xin if (ax_skb) { 1157e2ca90c2SFreddy Xin ax_skb->len = pkt_len; 1158e2ca90c2SFreddy Xin ax_skb->data = skb->data + 2; 1159e2ca90c2SFreddy Xin skb_set_tail_pointer(ax_skb, pkt_len); 1160e2ca90c2SFreddy Xin ax_skb->truesize = pkt_len + sizeof(struct sk_buff); 1161e2ca90c2SFreddy Xin ax88179_rx_checksum(ax_skb, pkt_hdr); 1162e2ca90c2SFreddy Xin usbnet_skb_return(dev, ax_skb); 1163e2ca90c2SFreddy Xin } else { 1164e2ca90c2SFreddy Xin return 0; 1165e2ca90c2SFreddy Xin } 1166e2ca90c2SFreddy Xin 1167e2ca90c2SFreddy Xin skb_pull(skb, (pkt_len + 7) & 0xFFF8); 1168e2ca90c2SFreddy Xin pkt_hdr++; 1169e2ca90c2SFreddy Xin } 1170e2ca90c2SFreddy Xin return 1; 1171e2ca90c2SFreddy Xin } 1172e2ca90c2SFreddy Xin 1173e2ca90c2SFreddy Xin static struct sk_buff * 1174e2ca90c2SFreddy Xin ax88179_tx_fixup(struct usbnet *dev, struct sk_buff *skb, gfp_t flags) 1175e2ca90c2SFreddy Xin { 1176e2ca90c2SFreddy Xin u32 tx_hdr1, tx_hdr2; 1177e2ca90c2SFreddy Xin int frame_size = dev->maxpacket; 1178e2ca90c2SFreddy Xin int mss = skb_shinfo(skb)->gso_size; 1179e2ca90c2SFreddy Xin int headroom; 1180e2ca90c2SFreddy Xin 1181e2ca90c2SFreddy Xin tx_hdr1 = skb->len; 1182e2ca90c2SFreddy Xin tx_hdr2 = mss; 1183e2ca90c2SFreddy Xin if (((skb->len + 8) % frame_size) == 0) 1184e2ca90c2SFreddy Xin tx_hdr2 |= 0x80008000; /* Enable padding */ 1185e2ca90c2SFreddy Xin 1186f2707015SEric Dumazet headroom = skb_headroom(skb) - 8; 1187e2ca90c2SFreddy Xin 1188f2707015SEric Dumazet if ((skb_header_cloned(skb) || headroom < 0) && 1189f2707015SEric Dumazet pskb_expand_head(skb, headroom < 0 ? 8 : 0, 0, GFP_ATOMIC)) { 1190e2ca90c2SFreddy Xin dev_kfree_skb_any(skb); 1191e2ca90c2SFreddy Xin return NULL; 1192e2ca90c2SFreddy Xin } 1193e2ca90c2SFreddy Xin 1194e2ca90c2SFreddy Xin skb_push(skb, 4); 1195e2ca90c2SFreddy Xin cpu_to_le32s(&tx_hdr2); 1196e2ca90c2SFreddy Xin skb_copy_to_linear_data(skb, &tx_hdr2, 4); 1197e2ca90c2SFreddy Xin 1198e2ca90c2SFreddy Xin skb_push(skb, 4); 1199e2ca90c2SFreddy Xin cpu_to_le32s(&tx_hdr1); 1200e2ca90c2SFreddy Xin skb_copy_to_linear_data(skb, &tx_hdr1, 4); 1201e2ca90c2SFreddy Xin 1202e2ca90c2SFreddy Xin return skb; 1203e2ca90c2SFreddy Xin } 1204e2ca90c2SFreddy Xin 1205e2ca90c2SFreddy Xin static int ax88179_link_reset(struct usbnet *dev) 1206e2ca90c2SFreddy Xin { 1207e2ca90c2SFreddy Xin struct ax88179_data *ax179_data = (struct ax88179_data *)dev->data; 1208e2ca90c2SFreddy Xin u8 tmp[5], link_sts; 1209e2ca90c2SFreddy Xin u16 mode, tmp16, delay = HZ / 10; 1210e2ca90c2SFreddy Xin u32 tmp32 = 0x40000000; 1211e2ca90c2SFreddy Xin unsigned long jtimeout; 1212e2ca90c2SFreddy Xin 1213e2ca90c2SFreddy Xin jtimeout = jiffies + delay; 1214e2ca90c2SFreddy Xin while (tmp32 & 0x40000000) { 1215e2ca90c2SFreddy Xin mode = 0; 1216e2ca90c2SFreddy Xin ax88179_write_cmd(dev, AX_ACCESS_MAC, AX_RX_CTL, 2, 2, &mode); 1217e2ca90c2SFreddy Xin ax88179_write_cmd(dev, AX_ACCESS_MAC, AX_RX_CTL, 2, 2, 1218e2ca90c2SFreddy Xin &ax179_data->rxctl); 1219e2ca90c2SFreddy Xin 1220e2ca90c2SFreddy Xin /*link up, check the usb device control TX FIFO full or empty*/ 1221e2ca90c2SFreddy Xin ax88179_read_cmd(dev, 0x81, 0x8c, 0, 4, &tmp32); 1222e2ca90c2SFreddy Xin 1223e2ca90c2SFreddy Xin if (time_after(jiffies, jtimeout)) 1224e2ca90c2SFreddy Xin return 0; 1225e2ca90c2SFreddy Xin } 1226e2ca90c2SFreddy Xin 1227e2ca90c2SFreddy Xin mode = AX_MEDIUM_RECEIVE_EN | AX_MEDIUM_TXFLOW_CTRLEN | 1228e2ca90c2SFreddy Xin AX_MEDIUM_RXFLOW_CTRLEN | AX_MEDIUM_ALWAYS_ONE; 1229e2ca90c2SFreddy Xin 1230e2ca90c2SFreddy Xin ax88179_read_cmd(dev, AX_ACCESS_MAC, PHYSICAL_LINK_STATUS, 1231e2ca90c2SFreddy Xin 1, 1, &link_sts); 1232e2ca90c2SFreddy Xin 1233e2ca90c2SFreddy Xin ax88179_read_cmd(dev, AX_ACCESS_PHY, AX88179_PHY_ID, 1234e2ca90c2SFreddy Xin GMII_PHY_PHYSR, 2, &tmp16); 1235e2ca90c2SFreddy Xin 1236e2ca90c2SFreddy Xin if (!(tmp16 & GMII_PHY_PHYSR_LINK)) { 1237e2ca90c2SFreddy Xin return 0; 1238e2ca90c2SFreddy Xin } else if (GMII_PHY_PHYSR_GIGA == (tmp16 & GMII_PHY_PHYSR_SMASK)) { 1239e2ca90c2SFreddy Xin mode |= AX_MEDIUM_GIGAMODE | AX_MEDIUM_EN_125MHZ; 1240e2ca90c2SFreddy Xin if (dev->net->mtu > 1500) 1241e2ca90c2SFreddy Xin mode |= AX_MEDIUM_JUMBO_EN; 1242e2ca90c2SFreddy Xin 1243e2ca90c2SFreddy Xin if (link_sts & AX_USB_SS) 1244e2ca90c2SFreddy Xin memcpy(tmp, &AX88179_BULKIN_SIZE[0], 5); 1245e2ca90c2SFreddy Xin else if (link_sts & AX_USB_HS) 1246e2ca90c2SFreddy Xin memcpy(tmp, &AX88179_BULKIN_SIZE[1], 5); 1247e2ca90c2SFreddy Xin else 1248e2ca90c2SFreddy Xin memcpy(tmp, &AX88179_BULKIN_SIZE[3], 5); 1249e2ca90c2SFreddy Xin } else if (GMII_PHY_PHYSR_100 == (tmp16 & GMII_PHY_PHYSR_SMASK)) { 1250e2ca90c2SFreddy Xin mode |= AX_MEDIUM_PS; 1251e2ca90c2SFreddy Xin 1252e2ca90c2SFreddy Xin if (link_sts & (AX_USB_SS | AX_USB_HS)) 1253e2ca90c2SFreddy Xin memcpy(tmp, &AX88179_BULKIN_SIZE[2], 5); 1254e2ca90c2SFreddy Xin else 1255e2ca90c2SFreddy Xin memcpy(tmp, &AX88179_BULKIN_SIZE[3], 5); 1256e2ca90c2SFreddy Xin } else { 1257e2ca90c2SFreddy Xin memcpy(tmp, &AX88179_BULKIN_SIZE[3], 5); 1258e2ca90c2SFreddy Xin } 1259e2ca90c2SFreddy Xin 1260e2ca90c2SFreddy Xin /* RX bulk configuration */ 1261e2ca90c2SFreddy Xin ax88179_write_cmd(dev, AX_ACCESS_MAC, AX_RX_BULKIN_QCTRL, 5, 5, tmp); 1262e2ca90c2SFreddy Xin 1263e2ca90c2SFreddy Xin dev->rx_urb_size = (1024 * (tmp[3] + 2)); 1264e2ca90c2SFreddy Xin 1265e2ca90c2SFreddy Xin if (tmp16 & GMII_PHY_PHYSR_FULL) 1266e2ca90c2SFreddy Xin mode |= AX_MEDIUM_FULL_DUPLEX; 1267e2ca90c2SFreddy Xin ax88179_write_cmd(dev, AX_ACCESS_MAC, AX_MEDIUM_STATUS_MODE, 1268e2ca90c2SFreddy Xin 2, 2, &mode); 1269e2ca90c2SFreddy Xin 1270e2ca90c2SFreddy Xin netif_carrier_on(dev->net); 1271e2ca90c2SFreddy Xin 1272e2ca90c2SFreddy Xin return 0; 1273e2ca90c2SFreddy Xin } 1274e2ca90c2SFreddy Xin 1275e2ca90c2SFreddy Xin static int ax88179_reset(struct usbnet *dev) 1276e2ca90c2SFreddy Xin { 1277e2ca90c2SFreddy Xin u8 buf[5]; 1278e2ca90c2SFreddy Xin u16 *tmp16; 1279e2ca90c2SFreddy Xin u8 *tmp; 1280e2ca90c2SFreddy Xin 1281e2ca90c2SFreddy Xin tmp16 = (u16 *)buf; 1282e2ca90c2SFreddy Xin tmp = (u8 *)buf; 1283e2ca90c2SFreddy Xin 1284e2ca90c2SFreddy Xin /* Power up ethernet PHY */ 1285e2ca90c2SFreddy Xin *tmp16 = 0; 1286e2ca90c2SFreddy Xin ax88179_write_cmd(dev, AX_ACCESS_MAC, AX_PHYPWR_RSTCTL, 2, 2, tmp16); 1287e2ca90c2SFreddy Xin 1288e2ca90c2SFreddy Xin *tmp16 = AX_PHYPWR_RSTCTL_IPRL; 1289e2ca90c2SFreddy Xin ax88179_write_cmd(dev, AX_ACCESS_MAC, AX_PHYPWR_RSTCTL, 2, 2, tmp16); 1290e2ca90c2SFreddy Xin msleep(200); 1291e2ca90c2SFreddy Xin 1292e2ca90c2SFreddy Xin *tmp = AX_CLK_SELECT_ACS | AX_CLK_SELECT_BCS; 1293e2ca90c2SFreddy Xin ax88179_write_cmd(dev, AX_ACCESS_MAC, AX_CLK_SELECT, 1, 1, tmp); 1294e2ca90c2SFreddy Xin msleep(100); 1295e2ca90c2SFreddy Xin 1296e2ca90c2SFreddy Xin /* Ethernet PHY Auto Detach*/ 1297e2ca90c2SFreddy Xin ax88179_auto_detach(dev, 0); 1298e2ca90c2SFreddy Xin 1299e2ca90c2SFreddy Xin ax88179_read_cmd(dev, AX_ACCESS_MAC, AX_NODE_ID, ETH_ALEN, ETH_ALEN, 1300e2ca90c2SFreddy Xin dev->net->dev_addr); 1301e2ca90c2SFreddy Xin memcpy(dev->net->perm_addr, dev->net->dev_addr, ETH_ALEN); 1302e2ca90c2SFreddy Xin 1303e2ca90c2SFreddy Xin /* RX bulk configuration */ 1304e2ca90c2SFreddy Xin memcpy(tmp, &AX88179_BULKIN_SIZE[0], 5); 1305e2ca90c2SFreddy Xin ax88179_write_cmd(dev, AX_ACCESS_MAC, AX_RX_BULKIN_QCTRL, 5, 5, tmp); 1306e2ca90c2SFreddy Xin 1307e2ca90c2SFreddy Xin dev->rx_urb_size = 1024 * 20; 1308e2ca90c2SFreddy Xin 1309e2ca90c2SFreddy Xin *tmp = 0x34; 1310e2ca90c2SFreddy Xin ax88179_write_cmd(dev, AX_ACCESS_MAC, AX_PAUSE_WATERLVL_LOW, 1, 1, tmp); 1311e2ca90c2SFreddy Xin 1312e2ca90c2SFreddy Xin *tmp = 0x52; 1313e2ca90c2SFreddy Xin ax88179_write_cmd(dev, AX_ACCESS_MAC, AX_PAUSE_WATERLVL_HIGH, 1314e2ca90c2SFreddy Xin 1, 1, tmp); 1315e2ca90c2SFreddy Xin 1316e2ca90c2SFreddy Xin dev->net->features |= NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM | 131720f01703SEric Dumazet NETIF_F_RXCSUM; 1318e2ca90c2SFreddy Xin 1319e2ca90c2SFreddy Xin dev->net->hw_features |= NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM | 132020f01703SEric Dumazet NETIF_F_RXCSUM; 1321e2ca90c2SFreddy Xin 1322e2ca90c2SFreddy Xin /* Enable checksum offload */ 1323e2ca90c2SFreddy Xin *tmp = AX_RXCOE_IP | AX_RXCOE_TCP | AX_RXCOE_UDP | 1324e2ca90c2SFreddy Xin AX_RXCOE_TCPV6 | AX_RXCOE_UDPV6; 1325e2ca90c2SFreddy Xin ax88179_write_cmd(dev, AX_ACCESS_MAC, AX_RXCOE_CTL, 1, 1, tmp); 1326e2ca90c2SFreddy Xin 1327e2ca90c2SFreddy Xin *tmp = AX_TXCOE_IP | AX_TXCOE_TCP | AX_TXCOE_UDP | 1328e2ca90c2SFreddy Xin AX_TXCOE_TCPV6 | AX_TXCOE_UDPV6; 1329e2ca90c2SFreddy Xin ax88179_write_cmd(dev, AX_ACCESS_MAC, AX_TXCOE_CTL, 1, 1, tmp); 1330e2ca90c2SFreddy Xin 1331e2ca90c2SFreddy Xin /* Configure RX control register => start operation */ 1332e2ca90c2SFreddy Xin *tmp16 = AX_RX_CTL_DROPCRCERR | AX_RX_CTL_IPE | AX_RX_CTL_START | 1333e2ca90c2SFreddy Xin AX_RX_CTL_AP | AX_RX_CTL_AMALL | AX_RX_CTL_AB; 1334e2ca90c2SFreddy Xin ax88179_write_cmd(dev, AX_ACCESS_MAC, AX_RX_CTL, 2, 2, tmp16); 1335e2ca90c2SFreddy Xin 1336e2ca90c2SFreddy Xin *tmp = AX_MONITOR_MODE_PMETYPE | AX_MONITOR_MODE_PMEPOL | 1337e2ca90c2SFreddy Xin AX_MONITOR_MODE_RWMP; 1338e2ca90c2SFreddy Xin ax88179_write_cmd(dev, AX_ACCESS_MAC, AX_MONITOR_MOD, 1, 1, tmp); 1339e2ca90c2SFreddy Xin 1340e2ca90c2SFreddy Xin /* Configure default medium type => giga */ 1341e2ca90c2SFreddy Xin *tmp16 = AX_MEDIUM_RECEIVE_EN | AX_MEDIUM_TXFLOW_CTRLEN | 1342e2ca90c2SFreddy Xin AX_MEDIUM_RXFLOW_CTRLEN | AX_MEDIUM_ALWAYS_ONE | 1343e2ca90c2SFreddy Xin AX_MEDIUM_FULL_DUPLEX | AX_MEDIUM_GIGAMODE; 1344e2ca90c2SFreddy Xin ax88179_write_cmd(dev, AX_ACCESS_MAC, AX_MEDIUM_STATUS_MODE, 1345e2ca90c2SFreddy Xin 2, 2, tmp16); 1346e2ca90c2SFreddy Xin 1347e2ca90c2SFreddy Xin ax88179_led_setting(dev); 1348e2ca90c2SFreddy Xin 1349e2ca90c2SFreddy Xin /* Restart autoneg */ 1350e2ca90c2SFreddy Xin mii_nway_restart(&dev->mii); 1351e2ca90c2SFreddy Xin 13527a97856eSMing Lei usbnet_link_change(dev, 0, 0); 1353e2ca90c2SFreddy Xin 1354e2ca90c2SFreddy Xin return 0; 1355e2ca90c2SFreddy Xin } 1356e2ca90c2SFreddy Xin 1357e2ca90c2SFreddy Xin static int ax88179_stop(struct usbnet *dev) 1358e2ca90c2SFreddy Xin { 1359e2ca90c2SFreddy Xin u16 tmp16; 1360e2ca90c2SFreddy Xin 1361e2ca90c2SFreddy Xin ax88179_read_cmd(dev, AX_ACCESS_MAC, AX_MEDIUM_STATUS_MODE, 1362e2ca90c2SFreddy Xin 2, 2, &tmp16); 1363e2ca90c2SFreddy Xin tmp16 &= ~AX_MEDIUM_RECEIVE_EN; 1364e2ca90c2SFreddy Xin ax88179_write_cmd(dev, AX_ACCESS_MAC, AX_MEDIUM_STATUS_MODE, 1365e2ca90c2SFreddy Xin 2, 2, &tmp16); 1366e2ca90c2SFreddy Xin 1367e2ca90c2SFreddy Xin return 0; 1368e2ca90c2SFreddy Xin } 1369e2ca90c2SFreddy Xin 1370e2ca90c2SFreddy Xin static const struct driver_info ax88179_info = { 1371803dee95SDavid Chang .description = "ASIX AX88179 USB 3.0 Gigabit Ethernet", 1372e2ca90c2SFreddy Xin .bind = ax88179_bind, 1373e2ca90c2SFreddy Xin .unbind = ax88179_unbind, 1374e2ca90c2SFreddy Xin .status = ax88179_status, 1375e2ca90c2SFreddy Xin .link_reset = ax88179_link_reset, 1376e2ca90c2SFreddy Xin .reset = ax88179_reset, 1377e2ca90c2SFreddy Xin .stop = ax88179_stop, 1378e2ca90c2SFreddy Xin .flags = FLAG_ETHER | FLAG_FRAMING_AX, 1379e2ca90c2SFreddy Xin .rx_fixup = ax88179_rx_fixup, 1380e2ca90c2SFreddy Xin .tx_fixup = ax88179_tx_fixup, 1381e2ca90c2SFreddy Xin }; 1382e2ca90c2SFreddy Xin 1383e2ca90c2SFreddy Xin static const struct driver_info ax88178a_info = { 1384803dee95SDavid Chang .description = "ASIX AX88178A USB 2.0 Gigabit Ethernet", 1385e2ca90c2SFreddy Xin .bind = ax88179_bind, 1386e2ca90c2SFreddy Xin .unbind = ax88179_unbind, 1387e2ca90c2SFreddy Xin .status = ax88179_status, 1388e2ca90c2SFreddy Xin .link_reset = ax88179_link_reset, 1389e2ca90c2SFreddy Xin .reset = ax88179_reset, 1390e2ca90c2SFreddy Xin .stop = ax88179_stop, 1391e2ca90c2SFreddy Xin .flags = FLAG_ETHER | FLAG_FRAMING_AX, 1392e2ca90c2SFreddy Xin .rx_fixup = ax88179_rx_fixup, 1393e2ca90c2SFreddy Xin .tx_fixup = ax88179_tx_fixup, 1394e2ca90c2SFreddy Xin }; 1395e2ca90c2SFreddy Xin 1396e2ca90c2SFreddy Xin static const struct driver_info sitecom_info = { 1397e2ca90c2SFreddy Xin .description = "Sitecom USB 3.0 to Gigabit Adapter", 1398e2ca90c2SFreddy Xin .bind = ax88179_bind, 1399e2ca90c2SFreddy Xin .unbind = ax88179_unbind, 1400e2ca90c2SFreddy Xin .status = ax88179_status, 1401e2ca90c2SFreddy Xin .link_reset = ax88179_link_reset, 1402e2ca90c2SFreddy Xin .reset = ax88179_reset, 1403e2ca90c2SFreddy Xin .stop = ax88179_stop, 1404e2ca90c2SFreddy Xin .flags = FLAG_ETHER | FLAG_FRAMING_AX, 1405e2ca90c2SFreddy Xin .rx_fixup = ax88179_rx_fixup, 1406e2ca90c2SFreddy Xin .tx_fixup = ax88179_tx_fixup, 1407e2ca90c2SFreddy Xin }; 1408e2ca90c2SFreddy Xin 1409e2ca90c2SFreddy Xin static const struct usb_device_id products[] = { 1410e2ca90c2SFreddy Xin { 1411e2ca90c2SFreddy Xin /* ASIX AX88179 10/100/1000 */ 1412e2ca90c2SFreddy Xin USB_DEVICE(0x0b95, 0x1790), 1413e2ca90c2SFreddy Xin .driver_info = (unsigned long)&ax88179_info, 1414e2ca90c2SFreddy Xin }, { 1415e2ca90c2SFreddy Xin /* ASIX AX88178A 10/100/1000 */ 1416e2ca90c2SFreddy Xin USB_DEVICE(0x0b95, 0x178a), 1417e2ca90c2SFreddy Xin .driver_info = (unsigned long)&ax88178a_info, 1418e2ca90c2SFreddy Xin }, { 1419e2ca90c2SFreddy Xin /* Sitecom USB 3.0 to Gigabit Adapter */ 1420e2ca90c2SFreddy Xin USB_DEVICE(0x0df6, 0x0072), 1421e2ca90c2SFreddy Xin .driver_info = (unsigned long) &sitecom_info, 1422e2ca90c2SFreddy Xin }, 1423e2ca90c2SFreddy Xin { }, 1424e2ca90c2SFreddy Xin }; 1425e2ca90c2SFreddy Xin MODULE_DEVICE_TABLE(usb, products); 1426e2ca90c2SFreddy Xin 1427e2ca90c2SFreddy Xin static struct usb_driver ax88179_178a_driver = { 1428e2ca90c2SFreddy Xin .name = "ax88179_178a", 1429e2ca90c2SFreddy Xin .id_table = products, 1430e2ca90c2SFreddy Xin .probe = usbnet_probe, 1431e2ca90c2SFreddy Xin .suspend = ax88179_suspend, 1432e2ca90c2SFreddy Xin .resume = ax88179_resume, 1433b8553b89SDavid Chang .reset_resume = ax88179_resume, 1434e2ca90c2SFreddy Xin .disconnect = usbnet_disconnect, 1435e2ca90c2SFreddy Xin .supports_autosuspend = 1, 1436e2ca90c2SFreddy Xin .disable_hub_initiated_lpm = 1, 1437e2ca90c2SFreddy Xin }; 1438e2ca90c2SFreddy Xin 1439e2ca90c2SFreddy Xin module_usb_driver(ax88179_178a_driver); 1440e2ca90c2SFreddy Xin 1441e2ca90c2SFreddy Xin MODULE_DESCRIPTION("ASIX AX88179/178A based USB 3.0/2.0 Gigabit Ethernet Devices"); 1442e2ca90c2SFreddy Xin MODULE_LICENSE("GPL"); 1443