hayeswang | ac718b6 | 2013-05-02 16:01:25 +0000 | [diff] [blame] | 1 | /* |
hayeswang | c7de7de | 2014-01-15 10:42:16 +0800 | [diff] [blame] | 2 | * Copyright (c) 2014 Realtek Semiconductor Corp. All rights reserved. |
hayeswang | ac718b6 | 2013-05-02 16:01:25 +0000 | [diff] [blame] | 3 | * |
| 4 | * This program is free software; you can redistribute it and/or |
| 5 | * modify it under the terms of the GNU General Public License |
| 6 | * version 2 as published by the Free Software Foundation. |
| 7 | * |
| 8 | */ |
| 9 | |
hayeswang | ac718b6 | 2013-05-02 16:01:25 +0000 | [diff] [blame] | 10 | #include <linux/signal.h> |
| 11 | #include <linux/slab.h> |
| 12 | #include <linux/module.h> |
hayeswang | ac718b6 | 2013-05-02 16:01:25 +0000 | [diff] [blame] | 13 | #include <linux/netdevice.h> |
| 14 | #include <linux/etherdevice.h> |
| 15 | #include <linux/mii.h> |
| 16 | #include <linux/ethtool.h> |
| 17 | #include <linux/usb.h> |
| 18 | #include <linux/crc32.h> |
| 19 | #include <linux/if_vlan.h> |
| 20 | #include <linux/uaccess.h> |
hayeswang | ebc2ec48 | 2013-08-14 20:54:38 +0800 | [diff] [blame] | 21 | #include <linux/list.h> |
hayeswang | 5bd2388 | 2013-08-14 20:54:39 +0800 | [diff] [blame] | 22 | #include <linux/ip.h> |
| 23 | #include <linux/ipv6.h> |
hayeswang | 6128d1bb | 2014-03-07 11:04:40 +0800 | [diff] [blame] | 24 | #include <net/ip6_checksum.h> |
hayeswang | ac718b6 | 2013-05-02 16:01:25 +0000 | [diff] [blame] | 25 | |
| 26 | /* Version Information */ |
hayeswang | 60c8907 | 2014-03-07 11:04:39 +0800 | [diff] [blame] | 27 | #define DRIVER_VERSION "v1.06.0 (2014/03/03)" |
hayeswang | ac718b6 | 2013-05-02 16:01:25 +0000 | [diff] [blame] | 28 | #define DRIVER_AUTHOR "Realtek linux nic maintainers <nic_swsd@realtek.com>" |
hayeswang | 44d942a | 2014-01-15 10:42:14 +0800 | [diff] [blame] | 29 | #define DRIVER_DESC "Realtek RTL8152/RTL8153 Based USB Ethernet Adapters" |
hayeswang | ac718b6 | 2013-05-02 16:01:25 +0000 | [diff] [blame] | 30 | #define MODULENAME "r8152" |
| 31 | |
| 32 | #define R8152_PHY_ID 32 |
| 33 | |
| 34 | #define PLA_IDR 0xc000 |
| 35 | #define PLA_RCR 0xc010 |
| 36 | #define PLA_RMS 0xc016 |
| 37 | #define PLA_RXFIFO_CTRL0 0xc0a0 |
| 38 | #define PLA_RXFIFO_CTRL1 0xc0a4 |
| 39 | #define PLA_RXFIFO_CTRL2 0xc0a8 |
| 40 | #define PLA_FMC 0xc0b4 |
| 41 | #define PLA_CFG_WOL 0xc0b6 |
hayeswang | 43779f8 | 2014-01-02 11:25:10 +0800 | [diff] [blame] | 42 | #define PLA_TEREDO_CFG 0xc0bc |
hayeswang | ac718b6 | 2013-05-02 16:01:25 +0000 | [diff] [blame] | 43 | #define PLA_MAR 0xcd00 |
hayeswang | 43779f8 | 2014-01-02 11:25:10 +0800 | [diff] [blame] | 44 | #define PLA_BACKUP 0xd000 |
hayeswang | ac718b6 | 2013-05-02 16:01:25 +0000 | [diff] [blame] | 45 | #define PAL_BDC_CR 0xd1a0 |
hayeswang | 43779f8 | 2014-01-02 11:25:10 +0800 | [diff] [blame] | 46 | #define PLA_TEREDO_TIMER 0xd2cc |
| 47 | #define PLA_REALWOW_TIMER 0xd2e8 |
hayeswang | ac718b6 | 2013-05-02 16:01:25 +0000 | [diff] [blame] | 48 | #define PLA_LEDSEL 0xdd90 |
| 49 | #define PLA_LED_FEATURE 0xdd92 |
| 50 | #define PLA_PHYAR 0xde00 |
hayeswang | 43779f8 | 2014-01-02 11:25:10 +0800 | [diff] [blame] | 51 | #define PLA_BOOT_CTRL 0xe004 |
hayeswang | ac718b6 | 2013-05-02 16:01:25 +0000 | [diff] [blame] | 52 | #define PLA_GPHY_INTR_IMR 0xe022 |
| 53 | #define PLA_EEE_CR 0xe040 |
| 54 | #define PLA_EEEP_CR 0xe080 |
| 55 | #define PLA_MAC_PWR_CTRL 0xe0c0 |
hayeswang | 43779f8 | 2014-01-02 11:25:10 +0800 | [diff] [blame] | 56 | #define PLA_MAC_PWR_CTRL2 0xe0ca |
| 57 | #define PLA_MAC_PWR_CTRL3 0xe0cc |
| 58 | #define PLA_MAC_PWR_CTRL4 0xe0ce |
| 59 | #define PLA_WDT6_CTRL 0xe428 |
hayeswang | ac718b6 | 2013-05-02 16:01:25 +0000 | [diff] [blame] | 60 | #define PLA_TCR0 0xe610 |
| 61 | #define PLA_TCR1 0xe612 |
| 62 | #define PLA_TXFIFO_CTRL 0xe618 |
| 63 | #define PLA_RSTTELLY 0xe800 |
| 64 | #define PLA_CR 0xe813 |
| 65 | #define PLA_CRWECR 0xe81c |
hayeswang | 21ff2e8 | 2014-02-18 21:49:06 +0800 | [diff] [blame] | 66 | #define PLA_CONFIG12 0xe81e /* CONFIG1, CONFIG2 */ |
| 67 | #define PLA_CONFIG34 0xe820 /* CONFIG3, CONFIG4 */ |
hayeswang | ac718b6 | 2013-05-02 16:01:25 +0000 | [diff] [blame] | 68 | #define PLA_CONFIG5 0xe822 |
| 69 | #define PLA_PHY_PWR 0xe84c |
| 70 | #define PLA_OOB_CTRL 0xe84f |
| 71 | #define PLA_CPCR 0xe854 |
| 72 | #define PLA_MISC_0 0xe858 |
| 73 | #define PLA_MISC_1 0xe85a |
| 74 | #define PLA_OCP_GPHY_BASE 0xe86c |
| 75 | #define PLA_TELLYCNT 0xe890 |
| 76 | #define PLA_SFF_STS_7 0xe8de |
| 77 | #define PLA_PHYSTATUS 0xe908 |
| 78 | #define PLA_BP_BA 0xfc26 |
| 79 | #define PLA_BP_0 0xfc28 |
| 80 | #define PLA_BP_1 0xfc2a |
| 81 | #define PLA_BP_2 0xfc2c |
| 82 | #define PLA_BP_3 0xfc2e |
| 83 | #define PLA_BP_4 0xfc30 |
| 84 | #define PLA_BP_5 0xfc32 |
| 85 | #define PLA_BP_6 0xfc34 |
| 86 | #define PLA_BP_7 0xfc36 |
hayeswang | 43779f8 | 2014-01-02 11:25:10 +0800 | [diff] [blame] | 87 | #define PLA_BP_EN 0xfc38 |
hayeswang | ac718b6 | 2013-05-02 16:01:25 +0000 | [diff] [blame] | 88 | |
hayeswang | 43779f8 | 2014-01-02 11:25:10 +0800 | [diff] [blame] | 89 | #define USB_U2P3_CTRL 0xb460 |
hayeswang | ac718b6 | 2013-05-02 16:01:25 +0000 | [diff] [blame] | 90 | #define USB_DEV_STAT 0xb808 |
| 91 | #define USB_USB_CTRL 0xd406 |
| 92 | #define USB_PHY_CTRL 0xd408 |
| 93 | #define USB_TX_AGG 0xd40a |
| 94 | #define USB_RX_BUF_TH 0xd40c |
| 95 | #define USB_USB_TIMER 0xd428 |
hayeswang | 43779f8 | 2014-01-02 11:25:10 +0800 | [diff] [blame] | 96 | #define USB_RX_EARLY_AGG 0xd42c |
hayeswang | ac718b6 | 2013-05-02 16:01:25 +0000 | [diff] [blame] | 97 | #define USB_PM_CTRL_STATUS 0xd432 |
| 98 | #define USB_TX_DMA 0xd434 |
hayeswang | 43779f8 | 2014-01-02 11:25:10 +0800 | [diff] [blame] | 99 | #define USB_TOLERANCE 0xd490 |
| 100 | #define USB_LPM_CTRL 0xd41a |
hayeswang | ac718b6 | 2013-05-02 16:01:25 +0000 | [diff] [blame] | 101 | #define USB_UPS_CTRL 0xd800 |
hayeswang | 43779f8 | 2014-01-02 11:25:10 +0800 | [diff] [blame] | 102 | #define USB_MISC_0 0xd81a |
| 103 | #define USB_POWER_CUT 0xd80a |
| 104 | #define USB_AFE_CTRL2 0xd824 |
| 105 | #define USB_WDT11_CTRL 0xe43c |
hayeswang | ac718b6 | 2013-05-02 16:01:25 +0000 | [diff] [blame] | 106 | #define USB_BP_BA 0xfc26 |
| 107 | #define USB_BP_0 0xfc28 |
| 108 | #define USB_BP_1 0xfc2a |
| 109 | #define USB_BP_2 0xfc2c |
| 110 | #define USB_BP_3 0xfc2e |
| 111 | #define USB_BP_4 0xfc30 |
| 112 | #define USB_BP_5 0xfc32 |
| 113 | #define USB_BP_6 0xfc34 |
| 114 | #define USB_BP_7 0xfc36 |
hayeswang | 43779f8 | 2014-01-02 11:25:10 +0800 | [diff] [blame] | 115 | #define USB_BP_EN 0xfc38 |
hayeswang | ac718b6 | 2013-05-02 16:01:25 +0000 | [diff] [blame] | 116 | |
| 117 | /* OCP Registers */ |
| 118 | #define OCP_ALDPS_CONFIG 0x2010 |
| 119 | #define OCP_EEE_CONFIG1 0x2080 |
| 120 | #define OCP_EEE_CONFIG2 0x2092 |
| 121 | #define OCP_EEE_CONFIG3 0x2094 |
hayeswang | ac244d3 | 2014-01-02 11:22:40 +0800 | [diff] [blame] | 122 | #define OCP_BASE_MII 0xa400 |
hayeswang | ac718b6 | 2013-05-02 16:01:25 +0000 | [diff] [blame] | 123 | #define OCP_EEE_AR 0xa41a |
| 124 | #define OCP_EEE_DATA 0xa41c |
hayeswang | 43779f8 | 2014-01-02 11:25:10 +0800 | [diff] [blame] | 125 | #define OCP_PHY_STATUS 0xa420 |
| 126 | #define OCP_POWER_CFG 0xa430 |
| 127 | #define OCP_EEE_CFG 0xa432 |
| 128 | #define OCP_SRAM_ADDR 0xa436 |
| 129 | #define OCP_SRAM_DATA 0xa438 |
| 130 | #define OCP_DOWN_SPEED 0xa442 |
| 131 | #define OCP_EEE_CFG2 0xa5d0 |
| 132 | #define OCP_ADC_CFG 0xbc06 |
| 133 | |
| 134 | /* SRAM Register */ |
| 135 | #define SRAM_LPF_CFG 0x8012 |
| 136 | #define SRAM_10M_AMP1 0x8080 |
| 137 | #define SRAM_10M_AMP2 0x8082 |
| 138 | #define SRAM_IMPEDANCE 0x8084 |
hayeswang | ac718b6 | 2013-05-02 16:01:25 +0000 | [diff] [blame] | 139 | |
| 140 | /* PLA_RCR */ |
| 141 | #define RCR_AAP 0x00000001 |
| 142 | #define RCR_APM 0x00000002 |
| 143 | #define RCR_AM 0x00000004 |
| 144 | #define RCR_AB 0x00000008 |
| 145 | #define RCR_ACPT_ALL (RCR_AAP | RCR_APM | RCR_AM | RCR_AB) |
| 146 | |
| 147 | /* PLA_RXFIFO_CTRL0 */ |
| 148 | #define RXFIFO_THR1_NORMAL 0x00080002 |
| 149 | #define RXFIFO_THR1_OOB 0x01800003 |
| 150 | |
| 151 | /* PLA_RXFIFO_CTRL1 */ |
| 152 | #define RXFIFO_THR2_FULL 0x00000060 |
| 153 | #define RXFIFO_THR2_HIGH 0x00000038 |
| 154 | #define RXFIFO_THR2_OOB 0x0000004a |
hayeswang | 43779f8 | 2014-01-02 11:25:10 +0800 | [diff] [blame] | 155 | #define RXFIFO_THR2_NORMAL 0x00a0 |
hayeswang | ac718b6 | 2013-05-02 16:01:25 +0000 | [diff] [blame] | 156 | |
| 157 | /* PLA_RXFIFO_CTRL2 */ |
| 158 | #define RXFIFO_THR3_FULL 0x00000078 |
| 159 | #define RXFIFO_THR3_HIGH 0x00000048 |
| 160 | #define RXFIFO_THR3_OOB 0x0000005a |
hayeswang | 43779f8 | 2014-01-02 11:25:10 +0800 | [diff] [blame] | 161 | #define RXFIFO_THR3_NORMAL 0x0110 |
hayeswang | ac718b6 | 2013-05-02 16:01:25 +0000 | [diff] [blame] | 162 | |
| 163 | /* PLA_TXFIFO_CTRL */ |
| 164 | #define TXFIFO_THR_NORMAL 0x00400008 |
hayeswang | 43779f8 | 2014-01-02 11:25:10 +0800 | [diff] [blame] | 165 | #define TXFIFO_THR_NORMAL2 0x01000008 |
hayeswang | ac718b6 | 2013-05-02 16:01:25 +0000 | [diff] [blame] | 166 | |
| 167 | /* PLA_FMC */ |
| 168 | #define FMC_FCR_MCU_EN 0x0001 |
| 169 | |
| 170 | /* PLA_EEEP_CR */ |
| 171 | #define EEEP_CR_EEEP_TX 0x0002 |
| 172 | |
hayeswang | 43779f8 | 2014-01-02 11:25:10 +0800 | [diff] [blame] | 173 | /* PLA_WDT6_CTRL */ |
| 174 | #define WDT6_SET_MODE 0x0010 |
| 175 | |
hayeswang | ac718b6 | 2013-05-02 16:01:25 +0000 | [diff] [blame] | 176 | /* PLA_TCR0 */ |
| 177 | #define TCR0_TX_EMPTY 0x0800 |
| 178 | #define TCR0_AUTO_FIFO 0x0080 |
| 179 | |
| 180 | /* PLA_TCR1 */ |
| 181 | #define VERSION_MASK 0x7cf0 |
| 182 | |
| 183 | /* PLA_CR */ |
| 184 | #define CR_RST 0x10 |
| 185 | #define CR_RE 0x08 |
| 186 | #define CR_TE 0x04 |
| 187 | |
| 188 | /* PLA_CRWECR */ |
| 189 | #define CRWECR_NORAML 0x00 |
| 190 | #define CRWECR_CONFIG 0xc0 |
| 191 | |
| 192 | /* PLA_OOB_CTRL */ |
| 193 | #define NOW_IS_OOB 0x80 |
| 194 | #define TXFIFO_EMPTY 0x20 |
| 195 | #define RXFIFO_EMPTY 0x10 |
| 196 | #define LINK_LIST_READY 0x02 |
| 197 | #define DIS_MCU_CLROOB 0x01 |
| 198 | #define FIFO_EMPTY (TXFIFO_EMPTY | RXFIFO_EMPTY) |
| 199 | |
| 200 | /* PLA_MISC_1 */ |
| 201 | #define RXDY_GATED_EN 0x0008 |
| 202 | |
| 203 | /* PLA_SFF_STS_7 */ |
| 204 | #define RE_INIT_LL 0x8000 |
| 205 | #define MCU_BORW_EN 0x4000 |
| 206 | |
| 207 | /* PLA_CPCR */ |
| 208 | #define CPCR_RX_VLAN 0x0040 |
| 209 | |
| 210 | /* PLA_CFG_WOL */ |
| 211 | #define MAGIC_EN 0x0001 |
| 212 | |
hayeswang | 43779f8 | 2014-01-02 11:25:10 +0800 | [diff] [blame] | 213 | /* PLA_TEREDO_CFG */ |
| 214 | #define TEREDO_SEL 0x8000 |
| 215 | #define TEREDO_WAKE_MASK 0x7f00 |
| 216 | #define TEREDO_RS_EVENT_MASK 0x00fe |
| 217 | #define OOB_TEREDO_EN 0x0001 |
| 218 | |
hayeswang | ac718b6 | 2013-05-02 16:01:25 +0000 | [diff] [blame] | 219 | /* PAL_BDC_CR */ |
| 220 | #define ALDPS_PROXY_MODE 0x0001 |
| 221 | |
hayeswang | 21ff2e8 | 2014-02-18 21:49:06 +0800 | [diff] [blame] | 222 | /* PLA_CONFIG34 */ |
| 223 | #define LINK_ON_WAKE_EN 0x0010 |
| 224 | #define LINK_OFF_WAKE_EN 0x0008 |
| 225 | |
hayeswang | ac718b6 | 2013-05-02 16:01:25 +0000 | [diff] [blame] | 226 | /* PLA_CONFIG5 */ |
hayeswang | 21ff2e8 | 2014-02-18 21:49:06 +0800 | [diff] [blame] | 227 | #define BWF_EN 0x0040 |
| 228 | #define MWF_EN 0x0020 |
| 229 | #define UWF_EN 0x0010 |
hayeswang | ac718b6 | 2013-05-02 16:01:25 +0000 | [diff] [blame] | 230 | #define LAN_WAKE_EN 0x0002 |
| 231 | |
| 232 | /* PLA_LED_FEATURE */ |
| 233 | #define LED_MODE_MASK 0x0700 |
| 234 | |
| 235 | /* PLA_PHY_PWR */ |
| 236 | #define TX_10M_IDLE_EN 0x0080 |
| 237 | #define PFM_PWM_SWITCH 0x0040 |
| 238 | |
| 239 | /* PLA_MAC_PWR_CTRL */ |
| 240 | #define D3_CLK_GATED_EN 0x00004000 |
| 241 | #define MCU_CLK_RATIO 0x07010f07 |
| 242 | #define MCU_CLK_RATIO_MASK 0x0f0f0f0f |
hayeswang | 43779f8 | 2014-01-02 11:25:10 +0800 | [diff] [blame] | 243 | #define ALDPS_SPDWN_RATIO 0x0f87 |
| 244 | |
| 245 | /* PLA_MAC_PWR_CTRL2 */ |
| 246 | #define EEE_SPDWN_RATIO 0x8007 |
| 247 | |
| 248 | /* PLA_MAC_PWR_CTRL3 */ |
| 249 | #define PKT_AVAIL_SPDWN_EN 0x0100 |
| 250 | #define SUSPEND_SPDWN_EN 0x0004 |
| 251 | #define U1U2_SPDWN_EN 0x0002 |
| 252 | #define L1_SPDWN_EN 0x0001 |
| 253 | |
| 254 | /* PLA_MAC_PWR_CTRL4 */ |
| 255 | #define PWRSAVE_SPDWN_EN 0x1000 |
| 256 | #define RXDV_SPDWN_EN 0x0800 |
| 257 | #define TX10MIDLE_EN 0x0100 |
| 258 | #define TP100_SPDWN_EN 0x0020 |
| 259 | #define TP500_SPDWN_EN 0x0010 |
| 260 | #define TP1000_SPDWN_EN 0x0008 |
| 261 | #define EEE_SPDWN_EN 0x0001 |
hayeswang | ac718b6 | 2013-05-02 16:01:25 +0000 | [diff] [blame] | 262 | |
| 263 | /* PLA_GPHY_INTR_IMR */ |
| 264 | #define GPHY_STS_MSK 0x0001 |
| 265 | #define SPEED_DOWN_MSK 0x0002 |
| 266 | #define SPDWN_RXDV_MSK 0x0004 |
| 267 | #define SPDWN_LINKCHG_MSK 0x0008 |
| 268 | |
| 269 | /* PLA_PHYAR */ |
| 270 | #define PHYAR_FLAG 0x80000000 |
| 271 | |
| 272 | /* PLA_EEE_CR */ |
| 273 | #define EEE_RX_EN 0x0001 |
| 274 | #define EEE_TX_EN 0x0002 |
| 275 | |
hayeswang | 43779f8 | 2014-01-02 11:25:10 +0800 | [diff] [blame] | 276 | /* PLA_BOOT_CTRL */ |
| 277 | #define AUTOLOAD_DONE 0x0002 |
| 278 | |
hayeswang | ac718b6 | 2013-05-02 16:01:25 +0000 | [diff] [blame] | 279 | /* USB_DEV_STAT */ |
| 280 | #define STAT_SPEED_MASK 0x0006 |
| 281 | #define STAT_SPEED_HIGH 0x0000 |
| 282 | #define STAT_SPEED_FULL 0x0001 |
| 283 | |
| 284 | /* USB_TX_AGG */ |
| 285 | #define TX_AGG_MAX_THRESHOLD 0x03 |
| 286 | |
| 287 | /* USB_RX_BUF_TH */ |
hayeswang | 43779f8 | 2014-01-02 11:25:10 +0800 | [diff] [blame] | 288 | #define RX_THR_SUPPER 0x0c350180 |
hayeswang | 8e1f51b | 2014-01-02 11:22:41 +0800 | [diff] [blame] | 289 | #define RX_THR_HIGH 0x7a120180 |
hayeswang | 43779f8 | 2014-01-02 11:25:10 +0800 | [diff] [blame] | 290 | #define RX_THR_SLOW 0xffff0180 |
hayeswang | ac718b6 | 2013-05-02 16:01:25 +0000 | [diff] [blame] | 291 | |
| 292 | /* USB_TX_DMA */ |
| 293 | #define TEST_MODE_DISABLE 0x00000001 |
| 294 | #define TX_SIZE_ADJUST1 0x00000100 |
| 295 | |
| 296 | /* USB_UPS_CTRL */ |
| 297 | #define POWER_CUT 0x0100 |
| 298 | |
| 299 | /* USB_PM_CTRL_STATUS */ |
hayeswang | 8e1f51b | 2014-01-02 11:22:41 +0800 | [diff] [blame] | 300 | #define RESUME_INDICATE 0x0001 |
hayeswang | ac718b6 | 2013-05-02 16:01:25 +0000 | [diff] [blame] | 301 | |
| 302 | /* USB_USB_CTRL */ |
| 303 | #define RX_AGG_DISABLE 0x0010 |
| 304 | |
hayeswang | 43779f8 | 2014-01-02 11:25:10 +0800 | [diff] [blame] | 305 | /* USB_U2P3_CTRL */ |
| 306 | #define U2P3_ENABLE 0x0001 |
| 307 | |
| 308 | /* USB_POWER_CUT */ |
| 309 | #define PWR_EN 0x0001 |
| 310 | #define PHASE2_EN 0x0008 |
| 311 | |
| 312 | /* USB_MISC_0 */ |
| 313 | #define PCUT_STATUS 0x0001 |
| 314 | |
| 315 | /* USB_RX_EARLY_AGG */ |
| 316 | #define EARLY_AGG_SUPPER 0x0e832981 |
| 317 | #define EARLY_AGG_HIGH 0x0e837a12 |
| 318 | #define EARLY_AGG_SLOW 0x0e83ffff |
| 319 | |
| 320 | /* USB_WDT11_CTRL */ |
| 321 | #define TIMER11_EN 0x0001 |
| 322 | |
| 323 | /* USB_LPM_CTRL */ |
| 324 | #define LPM_TIMER_MASK 0x0c |
| 325 | #define LPM_TIMER_500MS 0x04 /* 500 ms */ |
| 326 | #define LPM_TIMER_500US 0x0c /* 500 us */ |
| 327 | |
| 328 | /* USB_AFE_CTRL2 */ |
| 329 | #define SEN_VAL_MASK 0xf800 |
| 330 | #define SEN_VAL_NORMAL 0xa000 |
| 331 | #define SEL_RXIDLE 0x0100 |
| 332 | |
hayeswang | ac718b6 | 2013-05-02 16:01:25 +0000 | [diff] [blame] | 333 | /* OCP_ALDPS_CONFIG */ |
| 334 | #define ENPWRSAVE 0x8000 |
| 335 | #define ENPDNPS 0x0200 |
| 336 | #define LINKENA 0x0100 |
| 337 | #define DIS_SDSAVE 0x0010 |
| 338 | |
hayeswang | 43779f8 | 2014-01-02 11:25:10 +0800 | [diff] [blame] | 339 | /* OCP_PHY_STATUS */ |
| 340 | #define PHY_STAT_MASK 0x0007 |
| 341 | #define PHY_STAT_LAN_ON 3 |
| 342 | #define PHY_STAT_PWRDN 5 |
| 343 | |
| 344 | /* OCP_POWER_CFG */ |
| 345 | #define EEE_CLKDIV_EN 0x8000 |
| 346 | #define EN_ALDPS 0x0004 |
| 347 | #define EN_10M_PLLOFF 0x0001 |
| 348 | |
hayeswang | ac718b6 | 2013-05-02 16:01:25 +0000 | [diff] [blame] | 349 | /* OCP_EEE_CONFIG1 */ |
| 350 | #define RG_TXLPI_MSK_HFDUP 0x8000 |
| 351 | #define RG_MATCLR_EN 0x4000 |
| 352 | #define EEE_10_CAP 0x2000 |
| 353 | #define EEE_NWAY_EN 0x1000 |
| 354 | #define TX_QUIET_EN 0x0200 |
| 355 | #define RX_QUIET_EN 0x0100 |
| 356 | #define SDRISETIME 0x0010 /* bit 4 ~ 6 */ |
| 357 | #define RG_RXLPI_MSK_HFDUP 0x0008 |
| 358 | #define SDFALLTIME 0x0007 /* bit 0 ~ 2 */ |
| 359 | |
| 360 | /* OCP_EEE_CONFIG2 */ |
| 361 | #define RG_LPIHYS_NUM 0x7000 /* bit 12 ~ 15 */ |
| 362 | #define RG_DACQUIET_EN 0x0400 |
| 363 | #define RG_LDVQUIET_EN 0x0200 |
| 364 | #define RG_CKRSEL 0x0020 |
| 365 | #define RG_EEEPRG_EN 0x0010 |
| 366 | |
| 367 | /* OCP_EEE_CONFIG3 */ |
| 368 | #define FST_SNR_EYE_R 0x1500 /* bit 7 ~ 15 */ |
| 369 | #define RG_LFS_SEL 0x0060 /* bit 6 ~ 5 */ |
| 370 | #define MSK_PH 0x0006 /* bit 0 ~ 3 */ |
| 371 | |
| 372 | /* OCP_EEE_AR */ |
| 373 | /* bit[15:14] function */ |
| 374 | #define FUN_ADDR 0x0000 |
| 375 | #define FUN_DATA 0x4000 |
| 376 | /* bit[4:0] device addr */ |
| 377 | #define DEVICE_ADDR 0x0007 |
| 378 | |
| 379 | /* OCP_EEE_DATA */ |
| 380 | #define EEE_ADDR 0x003C |
| 381 | #define EEE_DATA 0x0002 |
| 382 | |
hayeswang | 43779f8 | 2014-01-02 11:25:10 +0800 | [diff] [blame] | 383 | /* OCP_EEE_CFG */ |
| 384 | #define CTAP_SHORT_EN 0x0040 |
| 385 | #define EEE10_EN 0x0010 |
| 386 | |
| 387 | /* OCP_DOWN_SPEED */ |
| 388 | #define EN_10M_BGOFF 0x0080 |
| 389 | |
| 390 | /* OCP_EEE_CFG2 */ |
| 391 | #define MY1000_EEE 0x0004 |
| 392 | #define MY100_EEE 0x0002 |
| 393 | |
| 394 | /* OCP_ADC_CFG */ |
| 395 | #define CKADSEL_L 0x0100 |
| 396 | #define ADC_EN 0x0080 |
| 397 | #define EN_EMI_L 0x0040 |
| 398 | |
| 399 | /* SRAM_LPF_CFG */ |
| 400 | #define LPF_AUTO_TUNE 0x8000 |
| 401 | |
| 402 | /* SRAM_10M_AMP1 */ |
| 403 | #define GDAC_IB_UPALL 0x0008 |
| 404 | |
| 405 | /* SRAM_10M_AMP2 */ |
| 406 | #define AMP_DN 0x0200 |
| 407 | |
| 408 | /* SRAM_IMPEDANCE */ |
| 409 | #define RX_DRIVING_MASK 0x6000 |
| 410 | |
hayeswang | ac718b6 | 2013-05-02 16:01:25 +0000 | [diff] [blame] | 411 | enum rtl_register_content { |
hayeswang | 43779f8 | 2014-01-02 11:25:10 +0800 | [diff] [blame] | 412 | _1000bps = 0x10, |
hayeswang | ac718b6 | 2013-05-02 16:01:25 +0000 | [diff] [blame] | 413 | _100bps = 0x08, |
| 414 | _10bps = 0x04, |
| 415 | LINK_STATUS = 0x02, |
| 416 | FULL_DUP = 0x01, |
| 417 | }; |
| 418 | |
hayeswang | ebc2ec48 | 2013-08-14 20:54:38 +0800 | [diff] [blame] | 419 | #define RTL8152_MAX_TX 10 |
| 420 | #define RTL8152_MAX_RX 10 |
hayeswang | 40a8291 | 2013-08-14 20:54:40 +0800 | [diff] [blame] | 421 | #define INTBUFSIZE 2 |
hayeswang | 8e1f51b | 2014-01-02 11:22:41 +0800 | [diff] [blame] | 422 | #define CRC_SIZE 4 |
| 423 | #define TX_ALIGN 4 |
| 424 | #define RX_ALIGN 8 |
hayeswang | 40a8291 | 2013-08-14 20:54:40 +0800 | [diff] [blame] | 425 | |
| 426 | #define INTR_LINK 0x0004 |
hayeswang | ebc2ec48 | 2013-08-14 20:54:38 +0800 | [diff] [blame] | 427 | |
hayeswang | ac718b6 | 2013-05-02 16:01:25 +0000 | [diff] [blame] | 428 | #define RTL8152_REQT_READ 0xc0 |
| 429 | #define RTL8152_REQT_WRITE 0x40 |
| 430 | #define RTL8152_REQ_GET_REGS 0x05 |
| 431 | #define RTL8152_REQ_SET_REGS 0x05 |
| 432 | |
| 433 | #define BYTE_EN_DWORD 0xff |
| 434 | #define BYTE_EN_WORD 0x33 |
| 435 | #define BYTE_EN_BYTE 0x11 |
| 436 | #define BYTE_EN_SIX_BYTES 0x3f |
| 437 | #define BYTE_EN_START_MASK 0x0f |
| 438 | #define BYTE_EN_END_MASK 0xf0 |
| 439 | |
| 440 | #define RTL8152_RMS (VLAN_ETH_FRAME_LEN + VLAN_HLEN) |
| 441 | #define RTL8152_TX_TIMEOUT (HZ) |
| 442 | |
| 443 | /* rtl8152 flags */ |
| 444 | enum rtl8152_flags { |
| 445 | RTL8152_UNPLUG = 0, |
hayeswang | ac718b6 | 2013-05-02 16:01:25 +0000 | [diff] [blame] | 446 | RTL8152_SET_RX_MODE, |
hayeswang | 40a8291 | 2013-08-14 20:54:40 +0800 | [diff] [blame] | 447 | WORK_ENABLE, |
| 448 | RTL8152_LINK_CHG, |
hayeswang | 9a4be1b | 2014-02-18 21:49:07 +0800 | [diff] [blame] | 449 | SELECTIVE_SUSPEND, |
hayeswang | aa66a5f | 2014-02-18 21:49:04 +0800 | [diff] [blame] | 450 | PHY_RESET, |
hayeswang | 0c3121f | 2014-03-07 11:04:36 +0800 | [diff] [blame] | 451 | SCHEDULE_TASKLET, |
hayeswang | ac718b6 | 2013-05-02 16:01:25 +0000 | [diff] [blame] | 452 | }; |
| 453 | |
| 454 | /* Define these values to match your device */ |
| 455 | #define VENDOR_ID_REALTEK 0x0bda |
| 456 | #define PRODUCT_ID_RTL8152 0x8152 |
hayeswang | 43779f8 | 2014-01-02 11:25:10 +0800 | [diff] [blame] | 457 | #define PRODUCT_ID_RTL8153 0x8153 |
| 458 | |
| 459 | #define VENDOR_ID_SAMSUNG 0x04e8 |
| 460 | #define PRODUCT_ID_SAMSUNG 0xa101 |
hayeswang | ac718b6 | 2013-05-02 16:01:25 +0000 | [diff] [blame] | 461 | |
| 462 | #define MCU_TYPE_PLA 0x0100 |
| 463 | #define MCU_TYPE_USB 0x0000 |
| 464 | |
hayeswang | c7de7de | 2014-01-15 10:42:16 +0800 | [diff] [blame] | 465 | #define REALTEK_USB_DEVICE(vend, prod) \ |
| 466 | USB_DEVICE_INTERFACE_CLASS(vend, prod, USB_CLASS_VENDOR_SPEC) |
| 467 | |
hayeswang | ac718b6 | 2013-05-02 16:01:25 +0000 | [diff] [blame] | 468 | struct rx_desc { |
hayeswang | 500b6d7 | 2013-11-20 17:30:57 +0800 | [diff] [blame] | 469 | __le32 opts1; |
hayeswang | ac718b6 | 2013-05-02 16:01:25 +0000 | [diff] [blame] | 470 | #define RX_LEN_MASK 0x7fff |
hayeswang | 565cab0 | 2014-03-07 11:04:38 +0800 | [diff] [blame] | 471 | |
hayeswang | 500b6d7 | 2013-11-20 17:30:57 +0800 | [diff] [blame] | 472 | __le32 opts2; |
hayeswang | 565cab0 | 2014-03-07 11:04:38 +0800 | [diff] [blame] | 473 | #define RD_UDP_CS (1 << 23) |
| 474 | #define RD_TCP_CS (1 << 22) |
hayeswang | 6128d1bb | 2014-03-07 11:04:40 +0800 | [diff] [blame] | 475 | #define RD_IPV6_CS (1 << 20) |
hayeswang | 565cab0 | 2014-03-07 11:04:38 +0800 | [diff] [blame] | 476 | #define RD_IPV4_CS (1 << 19) |
| 477 | |
hayeswang | 500b6d7 | 2013-11-20 17:30:57 +0800 | [diff] [blame] | 478 | __le32 opts3; |
hayeswang | 565cab0 | 2014-03-07 11:04:38 +0800 | [diff] [blame] | 479 | #define IPF (1 << 23) /* IP checksum fail */ |
| 480 | #define UDPF (1 << 22) /* UDP checksum fail */ |
| 481 | #define TCPF (1 << 21) /* TCP checksum fail */ |
| 482 | |
hayeswang | 500b6d7 | 2013-11-20 17:30:57 +0800 | [diff] [blame] | 483 | __le32 opts4; |
| 484 | __le32 opts5; |
| 485 | __le32 opts6; |
hayeswang | ac718b6 | 2013-05-02 16:01:25 +0000 | [diff] [blame] | 486 | }; |
| 487 | |
| 488 | struct tx_desc { |
hayeswang | 500b6d7 | 2013-11-20 17:30:57 +0800 | [diff] [blame] | 489 | __le32 opts1; |
hayeswang | ac718b6 | 2013-05-02 16:01:25 +0000 | [diff] [blame] | 490 | #define TX_FS (1 << 31) /* First segment of a packet */ |
| 491 | #define TX_LS (1 << 30) /* Final segment of a packet */ |
hayeswang | 60c8907 | 2014-03-07 11:04:39 +0800 | [diff] [blame] | 492 | #define GTSENDV4 (1 << 28) |
hayeswang | 6128d1bb | 2014-03-07 11:04:40 +0800 | [diff] [blame] | 493 | #define GTSENDV6 (1 << 27) |
hayeswang | 60c8907 | 2014-03-07 11:04:39 +0800 | [diff] [blame] | 494 | #define GTTCPHO_SHIFT 18 |
hayeswang | 6128d1bb | 2014-03-07 11:04:40 +0800 | [diff] [blame] | 495 | #define GTTCPHO_MAX 0x7fU |
hayeswang | 60c8907 | 2014-03-07 11:04:39 +0800 | [diff] [blame] | 496 | #define TX_LEN_MAX 0x3ffffU |
hayeswang | 5bd2388 | 2013-08-14 20:54:39 +0800 | [diff] [blame] | 497 | |
hayeswang | 500b6d7 | 2013-11-20 17:30:57 +0800 | [diff] [blame] | 498 | __le32 opts2; |
hayeswang | 5bd2388 | 2013-08-14 20:54:39 +0800 | [diff] [blame] | 499 | #define UDP_CS (1 << 31) /* Calculate UDP/IP checksum */ |
| 500 | #define TCP_CS (1 << 30) /* Calculate TCP/IP checksum */ |
| 501 | #define IPV4_CS (1 << 29) /* Calculate IPv4 checksum */ |
| 502 | #define IPV6_CS (1 << 28) /* Calculate IPv6 checksum */ |
hayeswang | 60c8907 | 2014-03-07 11:04:39 +0800 | [diff] [blame] | 503 | #define MSS_SHIFT 17 |
| 504 | #define MSS_MAX 0x7ffU |
| 505 | #define TCPHO_SHIFT 17 |
hayeswang | 6128d1bb | 2014-03-07 11:04:40 +0800 | [diff] [blame] | 506 | #define TCPHO_MAX 0x7ffU |
hayeswang | ac718b6 | 2013-05-02 16:01:25 +0000 | [diff] [blame] | 507 | }; |
| 508 | |
hayeswang | dff4e8a | 2013-08-16 16:09:33 +0800 | [diff] [blame] | 509 | struct r8152; |
| 510 | |
hayeswang | ebc2ec48 | 2013-08-14 20:54:38 +0800 | [diff] [blame] | 511 | struct rx_agg { |
| 512 | struct list_head list; |
| 513 | struct urb *urb; |
hayeswang | dff4e8a | 2013-08-16 16:09:33 +0800 | [diff] [blame] | 514 | struct r8152 *context; |
hayeswang | ebc2ec48 | 2013-08-14 20:54:38 +0800 | [diff] [blame] | 515 | void *buffer; |
| 516 | void *head; |
| 517 | }; |
| 518 | |
| 519 | struct tx_agg { |
| 520 | struct list_head list; |
| 521 | struct urb *urb; |
hayeswang | dff4e8a | 2013-08-16 16:09:33 +0800 | [diff] [blame] | 522 | struct r8152 *context; |
hayeswang | ebc2ec48 | 2013-08-14 20:54:38 +0800 | [diff] [blame] | 523 | void *buffer; |
| 524 | void *head; |
| 525 | u32 skb_num; |
| 526 | u32 skb_len; |
| 527 | }; |
| 528 | |
hayeswang | ac718b6 | 2013-05-02 16:01:25 +0000 | [diff] [blame] | 529 | struct r8152 { |
| 530 | unsigned long flags; |
| 531 | struct usb_device *udev; |
| 532 | struct tasklet_struct tl; |
hayeswang | 40a8291 | 2013-08-14 20:54:40 +0800 | [diff] [blame] | 533 | struct usb_interface *intf; |
hayeswang | ac718b6 | 2013-05-02 16:01:25 +0000 | [diff] [blame] | 534 | struct net_device *netdev; |
hayeswang | 40a8291 | 2013-08-14 20:54:40 +0800 | [diff] [blame] | 535 | struct urb *intr_urb; |
hayeswang | ebc2ec48 | 2013-08-14 20:54:38 +0800 | [diff] [blame] | 536 | struct tx_agg tx_info[RTL8152_MAX_TX]; |
| 537 | struct rx_agg rx_info[RTL8152_MAX_RX]; |
| 538 | struct list_head rx_done, tx_free; |
| 539 | struct sk_buff_head tx_queue; |
| 540 | spinlock_t rx_lock, tx_lock; |
hayeswang | ac718b6 | 2013-05-02 16:01:25 +0000 | [diff] [blame] | 541 | struct delayed_work schedule; |
| 542 | struct mii_if_info mii; |
hayeswang | c81229c | 2014-01-02 11:22:42 +0800 | [diff] [blame] | 543 | |
| 544 | struct rtl_ops { |
| 545 | void (*init)(struct r8152 *); |
| 546 | int (*enable)(struct r8152 *); |
| 547 | void (*disable)(struct r8152 *); |
hayeswang | 7e9da48 | 2014-02-18 21:49:05 +0800 | [diff] [blame] | 548 | void (*up)(struct r8152 *); |
hayeswang | c81229c | 2014-01-02 11:22:42 +0800 | [diff] [blame] | 549 | void (*down)(struct r8152 *); |
| 550 | void (*unload)(struct r8152 *); |
| 551 | } rtl_ops; |
| 552 | |
hayeswang | 40a8291 | 2013-08-14 20:54:40 +0800 | [diff] [blame] | 553 | int intr_interval; |
hayeswang | 21ff2e8 | 2014-02-18 21:49:06 +0800 | [diff] [blame] | 554 | u32 saved_wolopts; |
hayeswang | ac718b6 | 2013-05-02 16:01:25 +0000 | [diff] [blame] | 555 | u32 msg_enable; |
hayeswang | dd1b119 | 2013-11-20 17:30:56 +0800 | [diff] [blame] | 556 | u32 tx_qlen; |
hayeswang | ac718b6 | 2013-05-02 16:01:25 +0000 | [diff] [blame] | 557 | u16 ocp_base; |
hayeswang | 40a8291 | 2013-08-14 20:54:40 +0800 | [diff] [blame] | 558 | u8 *intr_buff; |
hayeswang | ac718b6 | 2013-05-02 16:01:25 +0000 | [diff] [blame] | 559 | u8 version; |
| 560 | u8 speed; |
| 561 | }; |
| 562 | |
| 563 | enum rtl_version { |
| 564 | RTL_VER_UNKNOWN = 0, |
| 565 | RTL_VER_01, |
hayeswang | 43779f8 | 2014-01-02 11:25:10 +0800 | [diff] [blame] | 566 | RTL_VER_02, |
| 567 | RTL_VER_03, |
| 568 | RTL_VER_04, |
| 569 | RTL_VER_05, |
| 570 | RTL_VER_MAX |
hayeswang | ac718b6 | 2013-05-02 16:01:25 +0000 | [diff] [blame] | 571 | }; |
| 572 | |
hayeswang | 60c8907 | 2014-03-07 11:04:39 +0800 | [diff] [blame] | 573 | enum tx_csum_stat { |
| 574 | TX_CSUM_SUCCESS = 0, |
| 575 | TX_CSUM_TSO, |
| 576 | TX_CSUM_NONE |
| 577 | }; |
| 578 | |
hayeswang | ac718b6 | 2013-05-02 16:01:25 +0000 | [diff] [blame] | 579 | /* Maximum number of multicast addresses to filter (vs. Rx-all-multicast). |
| 580 | * The RTL chips use a 64 element hash table based on the Ethernet CRC. |
| 581 | */ |
| 582 | static const int multicast_filter_limit = 32; |
hayeswang | ebc2ec48 | 2013-08-14 20:54:38 +0800 | [diff] [blame] | 583 | static unsigned int rx_buf_sz = 16384; |
hayeswang | ac718b6 | 2013-05-02 16:01:25 +0000 | [diff] [blame] | 584 | |
hayeswang | 60c8907 | 2014-03-07 11:04:39 +0800 | [diff] [blame] | 585 | #define RTL_LIMITED_TSO_SIZE (rx_buf_sz - sizeof(struct tx_desc) - \ |
| 586 | VLAN_ETH_HLEN - VLAN_HLEN) |
| 587 | |
hayeswang | ac718b6 | 2013-05-02 16:01:25 +0000 | [diff] [blame] | 588 | static |
| 589 | int get_registers(struct r8152 *tp, u16 value, u16 index, u16 size, void *data) |
| 590 | { |
hayeswang | 31787f5 | 2013-07-31 17:21:25 +0800 | [diff] [blame] | 591 | int ret; |
| 592 | void *tmp; |
| 593 | |
| 594 | tmp = kmalloc(size, GFP_KERNEL); |
| 595 | if (!tmp) |
| 596 | return -ENOMEM; |
| 597 | |
| 598 | ret = usb_control_msg(tp->udev, usb_rcvctrlpipe(tp->udev, 0), |
hayeswang | ac718b6 | 2013-05-02 16:01:25 +0000 | [diff] [blame] | 599 | RTL8152_REQ_GET_REGS, RTL8152_REQT_READ, |
hayeswang | 31787f5 | 2013-07-31 17:21:25 +0800 | [diff] [blame] | 600 | value, index, tmp, size, 500); |
| 601 | |
| 602 | memcpy(data, tmp, size); |
| 603 | kfree(tmp); |
| 604 | |
| 605 | return ret; |
hayeswang | ac718b6 | 2013-05-02 16:01:25 +0000 | [diff] [blame] | 606 | } |
| 607 | |
| 608 | static |
| 609 | int set_registers(struct r8152 *tp, u16 value, u16 index, u16 size, void *data) |
| 610 | { |
hayeswang | 31787f5 | 2013-07-31 17:21:25 +0800 | [diff] [blame] | 611 | int ret; |
| 612 | void *tmp; |
| 613 | |
| 614 | tmp = kmalloc(size, GFP_KERNEL); |
| 615 | if (!tmp) |
| 616 | return -ENOMEM; |
| 617 | |
| 618 | memcpy(tmp, data, size); |
| 619 | |
| 620 | ret = usb_control_msg(tp->udev, usb_sndctrlpipe(tp->udev, 0), |
hayeswang | ac718b6 | 2013-05-02 16:01:25 +0000 | [diff] [blame] | 621 | RTL8152_REQ_SET_REGS, RTL8152_REQT_WRITE, |
hayeswang | 31787f5 | 2013-07-31 17:21:25 +0800 | [diff] [blame] | 622 | value, index, tmp, size, 500); |
| 623 | |
| 624 | kfree(tmp); |
hayeswang | db8515e | 2014-03-06 15:07:16 +0800 | [diff] [blame] | 625 | |
hayeswang | 31787f5 | 2013-07-31 17:21:25 +0800 | [diff] [blame] | 626 | return ret; |
hayeswang | ac718b6 | 2013-05-02 16:01:25 +0000 | [diff] [blame] | 627 | } |
| 628 | |
| 629 | static int generic_ocp_read(struct r8152 *tp, u16 index, u16 size, |
| 630 | void *data, u16 type) |
| 631 | { |
hayeswang | 45f4a19 | 2014-01-06 17:08:41 +0800 | [diff] [blame] | 632 | u16 limit = 64; |
| 633 | int ret = 0; |
hayeswang | ac718b6 | 2013-05-02 16:01:25 +0000 | [diff] [blame] | 634 | |
| 635 | if (test_bit(RTL8152_UNPLUG, &tp->flags)) |
| 636 | return -ENODEV; |
| 637 | |
| 638 | /* both size and indix must be 4 bytes align */ |
| 639 | if ((size & 3) || !size || (index & 3) || !data) |
| 640 | return -EPERM; |
| 641 | |
| 642 | if ((u32)index + (u32)size > 0xffff) |
| 643 | return -EPERM; |
| 644 | |
| 645 | while (size) { |
| 646 | if (size > limit) { |
| 647 | ret = get_registers(tp, index, type, limit, data); |
| 648 | if (ret < 0) |
| 649 | break; |
| 650 | |
| 651 | index += limit; |
| 652 | data += limit; |
| 653 | size -= limit; |
| 654 | } else { |
| 655 | ret = get_registers(tp, index, type, size, data); |
| 656 | if (ret < 0) |
| 657 | break; |
| 658 | |
| 659 | index += size; |
| 660 | data += size; |
| 661 | size = 0; |
| 662 | break; |
| 663 | } |
| 664 | } |
| 665 | |
| 666 | return ret; |
| 667 | } |
| 668 | |
| 669 | static int generic_ocp_write(struct r8152 *tp, u16 index, u16 byteen, |
| 670 | u16 size, void *data, u16 type) |
| 671 | { |
hayeswang | 45f4a19 | 2014-01-06 17:08:41 +0800 | [diff] [blame] | 672 | int ret; |
| 673 | u16 byteen_start, byteen_end, byen; |
| 674 | u16 limit = 512; |
hayeswang | ac718b6 | 2013-05-02 16:01:25 +0000 | [diff] [blame] | 675 | |
| 676 | if (test_bit(RTL8152_UNPLUG, &tp->flags)) |
| 677 | return -ENODEV; |
| 678 | |
| 679 | /* both size and indix must be 4 bytes align */ |
| 680 | if ((size & 3) || !size || (index & 3) || !data) |
| 681 | return -EPERM; |
| 682 | |
| 683 | if ((u32)index + (u32)size > 0xffff) |
| 684 | return -EPERM; |
| 685 | |
| 686 | byteen_start = byteen & BYTE_EN_START_MASK; |
| 687 | byteen_end = byteen & BYTE_EN_END_MASK; |
| 688 | |
| 689 | byen = byteen_start | (byteen_start << 4); |
| 690 | ret = set_registers(tp, index, type | byen, 4, data); |
| 691 | if (ret < 0) |
| 692 | goto error1; |
| 693 | |
| 694 | index += 4; |
| 695 | data += 4; |
| 696 | size -= 4; |
| 697 | |
| 698 | if (size) { |
| 699 | size -= 4; |
| 700 | |
| 701 | while (size) { |
| 702 | if (size > limit) { |
| 703 | ret = set_registers(tp, index, |
| 704 | type | BYTE_EN_DWORD, |
| 705 | limit, data); |
| 706 | if (ret < 0) |
| 707 | goto error1; |
| 708 | |
| 709 | index += limit; |
| 710 | data += limit; |
| 711 | size -= limit; |
| 712 | } else { |
| 713 | ret = set_registers(tp, index, |
| 714 | type | BYTE_EN_DWORD, |
| 715 | size, data); |
| 716 | if (ret < 0) |
| 717 | goto error1; |
| 718 | |
| 719 | index += size; |
| 720 | data += size; |
| 721 | size = 0; |
| 722 | break; |
| 723 | } |
| 724 | } |
| 725 | |
| 726 | byen = byteen_end | (byteen_end >> 4); |
| 727 | ret = set_registers(tp, index, type | byen, 4, data); |
| 728 | if (ret < 0) |
| 729 | goto error1; |
| 730 | } |
| 731 | |
| 732 | error1: |
| 733 | return ret; |
| 734 | } |
| 735 | |
| 736 | static inline |
| 737 | int pla_ocp_read(struct r8152 *tp, u16 index, u16 size, void *data) |
| 738 | { |
| 739 | return generic_ocp_read(tp, index, size, data, MCU_TYPE_PLA); |
| 740 | } |
| 741 | |
| 742 | static inline |
| 743 | int pla_ocp_write(struct r8152 *tp, u16 index, u16 byteen, u16 size, void *data) |
| 744 | { |
| 745 | return generic_ocp_write(tp, index, byteen, size, data, MCU_TYPE_PLA); |
| 746 | } |
| 747 | |
| 748 | static inline |
| 749 | int usb_ocp_read(struct r8152 *tp, u16 index, u16 size, void *data) |
| 750 | { |
| 751 | return generic_ocp_read(tp, index, size, data, MCU_TYPE_USB); |
| 752 | } |
| 753 | |
| 754 | static inline |
| 755 | int usb_ocp_write(struct r8152 *tp, u16 index, u16 byteen, u16 size, void *data) |
| 756 | { |
| 757 | return generic_ocp_write(tp, index, byteen, size, data, MCU_TYPE_USB); |
| 758 | } |
| 759 | |
| 760 | static u32 ocp_read_dword(struct r8152 *tp, u16 type, u16 index) |
| 761 | { |
hayeswang | c8826de | 2013-07-31 17:21:26 +0800 | [diff] [blame] | 762 | __le32 data; |
hayeswang | ac718b6 | 2013-05-02 16:01:25 +0000 | [diff] [blame] | 763 | |
hayeswang | c8826de | 2013-07-31 17:21:26 +0800 | [diff] [blame] | 764 | generic_ocp_read(tp, index, sizeof(data), &data, type); |
hayeswang | ac718b6 | 2013-05-02 16:01:25 +0000 | [diff] [blame] | 765 | |
| 766 | return __le32_to_cpu(data); |
| 767 | } |
| 768 | |
| 769 | static void ocp_write_dword(struct r8152 *tp, u16 type, u16 index, u32 data) |
| 770 | { |
hayeswang | c8826de | 2013-07-31 17:21:26 +0800 | [diff] [blame] | 771 | __le32 tmp = __cpu_to_le32(data); |
| 772 | |
| 773 | generic_ocp_write(tp, index, BYTE_EN_DWORD, sizeof(tmp), &tmp, type); |
hayeswang | ac718b6 | 2013-05-02 16:01:25 +0000 | [diff] [blame] | 774 | } |
| 775 | |
| 776 | static u16 ocp_read_word(struct r8152 *tp, u16 type, u16 index) |
| 777 | { |
| 778 | u32 data; |
hayeswang | c8826de | 2013-07-31 17:21:26 +0800 | [diff] [blame] | 779 | __le32 tmp; |
hayeswang | ac718b6 | 2013-05-02 16:01:25 +0000 | [diff] [blame] | 780 | u8 shift = index & 2; |
| 781 | |
| 782 | index &= ~3; |
| 783 | |
hayeswang | c8826de | 2013-07-31 17:21:26 +0800 | [diff] [blame] | 784 | generic_ocp_read(tp, index, sizeof(tmp), &tmp, type); |
hayeswang | ac718b6 | 2013-05-02 16:01:25 +0000 | [diff] [blame] | 785 | |
hayeswang | c8826de | 2013-07-31 17:21:26 +0800 | [diff] [blame] | 786 | data = __le32_to_cpu(tmp); |
hayeswang | ac718b6 | 2013-05-02 16:01:25 +0000 | [diff] [blame] | 787 | data >>= (shift * 8); |
| 788 | data &= 0xffff; |
| 789 | |
| 790 | return (u16)data; |
| 791 | } |
| 792 | |
| 793 | static void ocp_write_word(struct r8152 *tp, u16 type, u16 index, u32 data) |
| 794 | { |
hayeswang | c8826de | 2013-07-31 17:21:26 +0800 | [diff] [blame] | 795 | u32 mask = 0xffff; |
| 796 | __le32 tmp; |
hayeswang | ac718b6 | 2013-05-02 16:01:25 +0000 | [diff] [blame] | 797 | u16 byen = BYTE_EN_WORD; |
| 798 | u8 shift = index & 2; |
| 799 | |
| 800 | data &= mask; |
| 801 | |
| 802 | if (index & 2) { |
| 803 | byen <<= shift; |
| 804 | mask <<= (shift * 8); |
| 805 | data <<= (shift * 8); |
| 806 | index &= ~3; |
| 807 | } |
| 808 | |
hayeswang | c8826de | 2013-07-31 17:21:26 +0800 | [diff] [blame] | 809 | generic_ocp_read(tp, index, sizeof(tmp), &tmp, type); |
hayeswang | ac718b6 | 2013-05-02 16:01:25 +0000 | [diff] [blame] | 810 | |
hayeswang | c8826de | 2013-07-31 17:21:26 +0800 | [diff] [blame] | 811 | data |= __le32_to_cpu(tmp) & ~mask; |
| 812 | tmp = __cpu_to_le32(data); |
hayeswang | ac718b6 | 2013-05-02 16:01:25 +0000 | [diff] [blame] | 813 | |
hayeswang | c8826de | 2013-07-31 17:21:26 +0800 | [diff] [blame] | 814 | generic_ocp_write(tp, index, byen, sizeof(tmp), &tmp, type); |
hayeswang | ac718b6 | 2013-05-02 16:01:25 +0000 | [diff] [blame] | 815 | } |
| 816 | |
| 817 | static u8 ocp_read_byte(struct r8152 *tp, u16 type, u16 index) |
| 818 | { |
| 819 | u32 data; |
hayeswang | c8826de | 2013-07-31 17:21:26 +0800 | [diff] [blame] | 820 | __le32 tmp; |
hayeswang | ac718b6 | 2013-05-02 16:01:25 +0000 | [diff] [blame] | 821 | u8 shift = index & 3; |
| 822 | |
| 823 | index &= ~3; |
| 824 | |
hayeswang | c8826de | 2013-07-31 17:21:26 +0800 | [diff] [blame] | 825 | generic_ocp_read(tp, index, sizeof(tmp), &tmp, type); |
hayeswang | ac718b6 | 2013-05-02 16:01:25 +0000 | [diff] [blame] | 826 | |
hayeswang | c8826de | 2013-07-31 17:21:26 +0800 | [diff] [blame] | 827 | data = __le32_to_cpu(tmp); |
hayeswang | ac718b6 | 2013-05-02 16:01:25 +0000 | [diff] [blame] | 828 | data >>= (shift * 8); |
| 829 | data &= 0xff; |
| 830 | |
| 831 | return (u8)data; |
| 832 | } |
| 833 | |
| 834 | static void ocp_write_byte(struct r8152 *tp, u16 type, u16 index, u32 data) |
| 835 | { |
hayeswang | c8826de | 2013-07-31 17:21:26 +0800 | [diff] [blame] | 836 | u32 mask = 0xff; |
| 837 | __le32 tmp; |
hayeswang | ac718b6 | 2013-05-02 16:01:25 +0000 | [diff] [blame] | 838 | u16 byen = BYTE_EN_BYTE; |
| 839 | u8 shift = index & 3; |
| 840 | |
| 841 | data &= mask; |
| 842 | |
| 843 | if (index & 3) { |
| 844 | byen <<= shift; |
| 845 | mask <<= (shift * 8); |
| 846 | data <<= (shift * 8); |
| 847 | index &= ~3; |
| 848 | } |
| 849 | |
hayeswang | c8826de | 2013-07-31 17:21:26 +0800 | [diff] [blame] | 850 | generic_ocp_read(tp, index, sizeof(tmp), &tmp, type); |
hayeswang | ac718b6 | 2013-05-02 16:01:25 +0000 | [diff] [blame] | 851 | |
hayeswang | c8826de | 2013-07-31 17:21:26 +0800 | [diff] [blame] | 852 | data |= __le32_to_cpu(tmp) & ~mask; |
| 853 | tmp = __cpu_to_le32(data); |
hayeswang | ac718b6 | 2013-05-02 16:01:25 +0000 | [diff] [blame] | 854 | |
hayeswang | c8826de | 2013-07-31 17:21:26 +0800 | [diff] [blame] | 855 | generic_ocp_write(tp, index, byen, sizeof(tmp), &tmp, type); |
hayeswang | ac718b6 | 2013-05-02 16:01:25 +0000 | [diff] [blame] | 856 | } |
| 857 | |
hayeswang | ac244d3 | 2014-01-02 11:22:40 +0800 | [diff] [blame] | 858 | static u16 ocp_reg_read(struct r8152 *tp, u16 addr) |
| 859 | { |
| 860 | u16 ocp_base, ocp_index; |
| 861 | |
| 862 | ocp_base = addr & 0xf000; |
| 863 | if (ocp_base != tp->ocp_base) { |
| 864 | ocp_write_word(tp, MCU_TYPE_PLA, PLA_OCP_GPHY_BASE, ocp_base); |
| 865 | tp->ocp_base = ocp_base; |
| 866 | } |
| 867 | |
| 868 | ocp_index = (addr & 0x0fff) | 0xb000; |
| 869 | return ocp_read_word(tp, MCU_TYPE_PLA, ocp_index); |
| 870 | } |
| 871 | |
hayeswang | e3fe0b1 | 2014-01-02 11:22:39 +0800 | [diff] [blame] | 872 | static void ocp_reg_write(struct r8152 *tp, u16 addr, u16 data) |
| 873 | { |
| 874 | u16 ocp_base, ocp_index; |
| 875 | |
| 876 | ocp_base = addr & 0xf000; |
| 877 | if (ocp_base != tp->ocp_base) { |
| 878 | ocp_write_word(tp, MCU_TYPE_PLA, PLA_OCP_GPHY_BASE, ocp_base); |
| 879 | tp->ocp_base = ocp_base; |
| 880 | } |
| 881 | |
| 882 | ocp_index = (addr & 0x0fff) | 0xb000; |
| 883 | ocp_write_word(tp, MCU_TYPE_PLA, ocp_index, data); |
| 884 | } |
| 885 | |
hayeswang | ac244d3 | 2014-01-02 11:22:40 +0800 | [diff] [blame] | 886 | static inline void r8152_mdio_write(struct r8152 *tp, u32 reg_addr, u32 value) |
hayeswang | ac718b6 | 2013-05-02 16:01:25 +0000 | [diff] [blame] | 887 | { |
hayeswang | ac244d3 | 2014-01-02 11:22:40 +0800 | [diff] [blame] | 888 | ocp_reg_write(tp, OCP_BASE_MII + reg_addr * 2, value); |
hayeswang | ac718b6 | 2013-05-02 16:01:25 +0000 | [diff] [blame] | 889 | } |
| 890 | |
hayeswang | ac244d3 | 2014-01-02 11:22:40 +0800 | [diff] [blame] | 891 | static inline int r8152_mdio_read(struct r8152 *tp, u32 reg_addr) |
hayeswang | ac718b6 | 2013-05-02 16:01:25 +0000 | [diff] [blame] | 892 | { |
hayeswang | ac244d3 | 2014-01-02 11:22:40 +0800 | [diff] [blame] | 893 | return ocp_reg_read(tp, OCP_BASE_MII + reg_addr * 2); |
hayeswang | ac718b6 | 2013-05-02 16:01:25 +0000 | [diff] [blame] | 894 | } |
| 895 | |
hayeswang | 43779f8 | 2014-01-02 11:25:10 +0800 | [diff] [blame] | 896 | static void sram_write(struct r8152 *tp, u16 addr, u16 data) |
| 897 | { |
| 898 | ocp_reg_write(tp, OCP_SRAM_ADDR, addr); |
| 899 | ocp_reg_write(tp, OCP_SRAM_DATA, data); |
| 900 | } |
| 901 | |
| 902 | static u16 sram_read(struct r8152 *tp, u16 addr) |
| 903 | { |
| 904 | ocp_reg_write(tp, OCP_SRAM_ADDR, addr); |
| 905 | return ocp_reg_read(tp, OCP_SRAM_DATA); |
| 906 | } |
| 907 | |
hayeswang | ac718b6 | 2013-05-02 16:01:25 +0000 | [diff] [blame] | 908 | static int read_mii_word(struct net_device *netdev, int phy_id, int reg) |
| 909 | { |
| 910 | struct r8152 *tp = netdev_priv(netdev); |
hayeswang | 9a4be1b | 2014-02-18 21:49:07 +0800 | [diff] [blame] | 911 | int ret; |
hayeswang | ac718b6 | 2013-05-02 16:01:25 +0000 | [diff] [blame] | 912 | |
| 913 | if (phy_id != R8152_PHY_ID) |
| 914 | return -EINVAL; |
| 915 | |
hayeswang | 9a4be1b | 2014-02-18 21:49:07 +0800 | [diff] [blame] | 916 | ret = usb_autopm_get_interface(tp->intf); |
| 917 | if (ret < 0) |
| 918 | goto out; |
| 919 | |
| 920 | ret = r8152_mdio_read(tp, reg); |
| 921 | |
| 922 | usb_autopm_put_interface(tp->intf); |
| 923 | |
| 924 | out: |
| 925 | return ret; |
hayeswang | ac718b6 | 2013-05-02 16:01:25 +0000 | [diff] [blame] | 926 | } |
| 927 | |
| 928 | static |
| 929 | void write_mii_word(struct net_device *netdev, int phy_id, int reg, int val) |
| 930 | { |
| 931 | struct r8152 *tp = netdev_priv(netdev); |
| 932 | |
| 933 | if (phy_id != R8152_PHY_ID) |
| 934 | return; |
| 935 | |
hayeswang | 9a4be1b | 2014-02-18 21:49:07 +0800 | [diff] [blame] | 936 | if (usb_autopm_get_interface(tp->intf) < 0) |
| 937 | return; |
| 938 | |
hayeswang | ac718b6 | 2013-05-02 16:01:25 +0000 | [diff] [blame] | 939 | r8152_mdio_write(tp, reg, val); |
hayeswang | 9a4be1b | 2014-02-18 21:49:07 +0800 | [diff] [blame] | 940 | |
| 941 | usb_autopm_put_interface(tp->intf); |
hayeswang | ac718b6 | 2013-05-02 16:01:25 +0000 | [diff] [blame] | 942 | } |
| 943 | |
hayeswang | ebc2ec48 | 2013-08-14 20:54:38 +0800 | [diff] [blame] | 944 | static |
| 945 | int r8152_submit_rx(struct r8152 *tp, struct rx_agg *agg, gfp_t mem_flags); |
| 946 | |
hayeswang | ac718b6 | 2013-05-02 16:01:25 +0000 | [diff] [blame] | 947 | static inline void set_ethernet_addr(struct r8152 *tp) |
| 948 | { |
| 949 | struct net_device *dev = tp->netdev; |
hayeswang | 8a91c82 | 2014-02-18 21:49:01 +0800 | [diff] [blame] | 950 | int ret; |
hayeswang | 31787f5 | 2013-07-31 17:21:25 +0800 | [diff] [blame] | 951 | u8 node_id[8] = {0}; |
hayeswang | ac718b6 | 2013-05-02 16:01:25 +0000 | [diff] [blame] | 952 | |
hayeswang | 8a91c82 | 2014-02-18 21:49:01 +0800 | [diff] [blame] | 953 | if (tp->version == RTL_VER_01) |
| 954 | ret = pla_ocp_read(tp, PLA_IDR, sizeof(node_id), node_id); |
| 955 | else |
| 956 | ret = pla_ocp_read(tp, PLA_BACKUP, sizeof(node_id), node_id); |
| 957 | |
| 958 | if (ret < 0) { |
hayeswang | ac718b6 | 2013-05-02 16:01:25 +0000 | [diff] [blame] | 959 | netif_notice(tp, probe, dev, "inet addr fail\n"); |
hayeswang | 8a91c82 | 2014-02-18 21:49:01 +0800 | [diff] [blame] | 960 | } else { |
| 961 | if (tp->version != RTL_VER_01) { |
| 962 | ocp_write_byte(tp, MCU_TYPE_PLA, PLA_CRWECR, |
| 963 | CRWECR_CONFIG); |
| 964 | pla_ocp_write(tp, PLA_IDR, BYTE_EN_SIX_BYTES, |
| 965 | sizeof(node_id), node_id); |
| 966 | ocp_write_byte(tp, MCU_TYPE_PLA, PLA_CRWECR, |
| 967 | CRWECR_NORAML); |
| 968 | } |
| 969 | |
hayeswang | ac718b6 | 2013-05-02 16:01:25 +0000 | [diff] [blame] | 970 | memcpy(dev->dev_addr, node_id, dev->addr_len); |
| 971 | memcpy(dev->perm_addr, dev->dev_addr, dev->addr_len); |
| 972 | } |
hayeswang | ac718b6 | 2013-05-02 16:01:25 +0000 | [diff] [blame] | 973 | } |
| 974 | |
| 975 | static int rtl8152_set_mac_address(struct net_device *netdev, void *p) |
| 976 | { |
| 977 | struct r8152 *tp = netdev_priv(netdev); |
| 978 | struct sockaddr *addr = p; |
| 979 | |
| 980 | if (!is_valid_ether_addr(addr->sa_data)) |
| 981 | return -EADDRNOTAVAIL; |
| 982 | |
| 983 | memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len); |
| 984 | |
| 985 | ocp_write_byte(tp, MCU_TYPE_PLA, PLA_CRWECR, CRWECR_CONFIG); |
| 986 | pla_ocp_write(tp, PLA_IDR, BYTE_EN_SIX_BYTES, 8, addr->sa_data); |
| 987 | ocp_write_byte(tp, MCU_TYPE_PLA, PLA_CRWECR, CRWECR_NORAML); |
| 988 | |
| 989 | return 0; |
| 990 | } |
| 991 | |
hayeswang | ac718b6 | 2013-05-02 16:01:25 +0000 | [diff] [blame] | 992 | static void read_bulk_callback(struct urb *urb) |
| 993 | { |
hayeswang | ac718b6 | 2013-05-02 16:01:25 +0000 | [diff] [blame] | 994 | struct net_device *netdev; |
hayeswang | ac718b6 | 2013-05-02 16:01:25 +0000 | [diff] [blame] | 995 | int status = urb->status; |
hayeswang | ebc2ec48 | 2013-08-14 20:54:38 +0800 | [diff] [blame] | 996 | struct rx_agg *agg; |
| 997 | struct r8152 *tp; |
hayeswang | ac718b6 | 2013-05-02 16:01:25 +0000 | [diff] [blame] | 998 | int result; |
hayeswang | ac718b6 | 2013-05-02 16:01:25 +0000 | [diff] [blame] | 999 | |
hayeswang | ebc2ec48 | 2013-08-14 20:54:38 +0800 | [diff] [blame] | 1000 | agg = urb->context; |
| 1001 | if (!agg) |
| 1002 | return; |
| 1003 | |
| 1004 | tp = agg->context; |
hayeswang | ac718b6 | 2013-05-02 16:01:25 +0000 | [diff] [blame] | 1005 | if (!tp) |
| 1006 | return; |
hayeswang | ebc2ec48 | 2013-08-14 20:54:38 +0800 | [diff] [blame] | 1007 | |
hayeswang | ac718b6 | 2013-05-02 16:01:25 +0000 | [diff] [blame] | 1008 | if (test_bit(RTL8152_UNPLUG, &tp->flags)) |
| 1009 | return; |
hayeswang | ebc2ec48 | 2013-08-14 20:54:38 +0800 | [diff] [blame] | 1010 | |
| 1011 | if (!test_bit(WORK_ENABLE, &tp->flags)) |
hayeswang | ac718b6 | 2013-05-02 16:01:25 +0000 | [diff] [blame] | 1012 | return; |
| 1013 | |
hayeswang | ebc2ec48 | 2013-08-14 20:54:38 +0800 | [diff] [blame] | 1014 | netdev = tp->netdev; |
hayeswang | 7559fb2f | 2013-08-16 16:09:38 +0800 | [diff] [blame] | 1015 | |
| 1016 | /* When link down, the driver would cancel all bulks. */ |
| 1017 | /* This avoid the re-submitting bulk */ |
hayeswang | ebc2ec48 | 2013-08-14 20:54:38 +0800 | [diff] [blame] | 1018 | if (!netif_carrier_ok(netdev)) |
| 1019 | return; |
| 1020 | |
hayeswang | 9a4be1b | 2014-02-18 21:49:07 +0800 | [diff] [blame] | 1021 | usb_mark_last_busy(tp->udev); |
| 1022 | |
hayeswang | ac718b6 | 2013-05-02 16:01:25 +0000 | [diff] [blame] | 1023 | switch (status) { |
| 1024 | case 0: |
hayeswang | ebc2ec48 | 2013-08-14 20:54:38 +0800 | [diff] [blame] | 1025 | if (urb->actual_length < ETH_ZLEN) |
| 1026 | break; |
| 1027 | |
hayeswang | 2685d41 | 2014-03-07 11:04:34 +0800 | [diff] [blame] | 1028 | spin_lock(&tp->rx_lock); |
hayeswang | ebc2ec48 | 2013-08-14 20:54:38 +0800 | [diff] [blame] | 1029 | list_add_tail(&agg->list, &tp->rx_done); |
hayeswang | 2685d41 | 2014-03-07 11:04:34 +0800 | [diff] [blame] | 1030 | spin_unlock(&tp->rx_lock); |
hayeswang | ebc2ec48 | 2013-08-14 20:54:38 +0800 | [diff] [blame] | 1031 | tasklet_schedule(&tp->tl); |
| 1032 | return; |
hayeswang | ac718b6 | 2013-05-02 16:01:25 +0000 | [diff] [blame] | 1033 | case -ESHUTDOWN: |
| 1034 | set_bit(RTL8152_UNPLUG, &tp->flags); |
| 1035 | netif_device_detach(tp->netdev); |
hayeswang | ebc2ec48 | 2013-08-14 20:54:38 +0800 | [diff] [blame] | 1036 | return; |
hayeswang | ac718b6 | 2013-05-02 16:01:25 +0000 | [diff] [blame] | 1037 | case -ENOENT: |
| 1038 | return; /* the urb is in unlink state */ |
| 1039 | case -ETIME: |
Hayes Wang | 4a8deae | 2014-01-07 11:18:22 +0800 | [diff] [blame] | 1040 | if (net_ratelimit()) |
| 1041 | netdev_warn(netdev, "maybe reset is needed?\n"); |
hayeswang | ebc2ec48 | 2013-08-14 20:54:38 +0800 | [diff] [blame] | 1042 | break; |
hayeswang | ac718b6 | 2013-05-02 16:01:25 +0000 | [diff] [blame] | 1043 | default: |
Hayes Wang | 4a8deae | 2014-01-07 11:18:22 +0800 | [diff] [blame] | 1044 | if (net_ratelimit()) |
| 1045 | netdev_warn(netdev, "Rx status %d\n", status); |
hayeswang | ebc2ec48 | 2013-08-14 20:54:38 +0800 | [diff] [blame] | 1046 | break; |
hayeswang | ac718b6 | 2013-05-02 16:01:25 +0000 | [diff] [blame] | 1047 | } |
| 1048 | |
hayeswang | ebc2ec48 | 2013-08-14 20:54:38 +0800 | [diff] [blame] | 1049 | result = r8152_submit_rx(tp, agg, GFP_ATOMIC); |
hayeswang | ac718b6 | 2013-05-02 16:01:25 +0000 | [diff] [blame] | 1050 | if (result == -ENODEV) { |
| 1051 | netif_device_detach(tp->netdev); |
| 1052 | } else if (result) { |
hayeswang | 2685d41 | 2014-03-07 11:04:34 +0800 | [diff] [blame] | 1053 | spin_lock(&tp->rx_lock); |
hayeswang | ebc2ec48 | 2013-08-14 20:54:38 +0800 | [diff] [blame] | 1054 | list_add_tail(&agg->list, &tp->rx_done); |
hayeswang | 2685d41 | 2014-03-07 11:04:34 +0800 | [diff] [blame] | 1055 | spin_unlock(&tp->rx_lock); |
hayeswang | ebc2ec48 | 2013-08-14 20:54:38 +0800 | [diff] [blame] | 1056 | tasklet_schedule(&tp->tl); |
hayeswang | ac718b6 | 2013-05-02 16:01:25 +0000 | [diff] [blame] | 1057 | } |
hayeswang | ac718b6 | 2013-05-02 16:01:25 +0000 | [diff] [blame] | 1058 | } |
| 1059 | |
| 1060 | static void write_bulk_callback(struct urb *urb) |
| 1061 | { |
hayeswang | ebc2ec48 | 2013-08-14 20:54:38 +0800 | [diff] [blame] | 1062 | struct net_device_stats *stats; |
hayeswang | d104eaf | 2014-03-06 15:07:17 +0800 | [diff] [blame] | 1063 | struct net_device *netdev; |
hayeswang | ebc2ec48 | 2013-08-14 20:54:38 +0800 | [diff] [blame] | 1064 | struct tx_agg *agg; |
hayeswang | ac718b6 | 2013-05-02 16:01:25 +0000 | [diff] [blame] | 1065 | struct r8152 *tp; |
| 1066 | int status = urb->status; |
| 1067 | |
hayeswang | ebc2ec48 | 2013-08-14 20:54:38 +0800 | [diff] [blame] | 1068 | agg = urb->context; |
| 1069 | if (!agg) |
| 1070 | return; |
| 1071 | |
| 1072 | tp = agg->context; |
hayeswang | ac718b6 | 2013-05-02 16:01:25 +0000 | [diff] [blame] | 1073 | if (!tp) |
| 1074 | return; |
hayeswang | ebc2ec48 | 2013-08-14 20:54:38 +0800 | [diff] [blame] | 1075 | |
hayeswang | d104eaf | 2014-03-06 15:07:17 +0800 | [diff] [blame] | 1076 | netdev = tp->netdev; |
hayeswang | 05e0f1a | 2014-03-06 15:07:18 +0800 | [diff] [blame] | 1077 | stats = &netdev->stats; |
hayeswang | ebc2ec48 | 2013-08-14 20:54:38 +0800 | [diff] [blame] | 1078 | if (status) { |
Hayes Wang | 4a8deae | 2014-01-07 11:18:22 +0800 | [diff] [blame] | 1079 | if (net_ratelimit()) |
hayeswang | d104eaf | 2014-03-06 15:07:17 +0800 | [diff] [blame] | 1080 | netdev_warn(netdev, "Tx status %d\n", status); |
hayeswang | ebc2ec48 | 2013-08-14 20:54:38 +0800 | [diff] [blame] | 1081 | stats->tx_errors += agg->skb_num; |
| 1082 | } else { |
| 1083 | stats->tx_packets += agg->skb_num; |
| 1084 | stats->tx_bytes += agg->skb_len; |
| 1085 | } |
| 1086 | |
hayeswang | 2685d41 | 2014-03-07 11:04:34 +0800 | [diff] [blame] | 1087 | spin_lock(&tp->tx_lock); |
hayeswang | ebc2ec48 | 2013-08-14 20:54:38 +0800 | [diff] [blame] | 1088 | list_add_tail(&agg->list, &tp->tx_free); |
hayeswang | 2685d41 | 2014-03-07 11:04:34 +0800 | [diff] [blame] | 1089 | spin_unlock(&tp->tx_lock); |
hayeswang | ebc2ec48 | 2013-08-14 20:54:38 +0800 | [diff] [blame] | 1090 | |
hayeswang | 9a4be1b | 2014-02-18 21:49:07 +0800 | [diff] [blame] | 1091 | usb_autopm_put_interface_async(tp->intf); |
| 1092 | |
hayeswang | d104eaf | 2014-03-06 15:07:17 +0800 | [diff] [blame] | 1093 | if (!netif_carrier_ok(netdev)) |
hayeswang | ac718b6 | 2013-05-02 16:01:25 +0000 | [diff] [blame] | 1094 | return; |
hayeswang | ebc2ec48 | 2013-08-14 20:54:38 +0800 | [diff] [blame] | 1095 | |
| 1096 | if (!test_bit(WORK_ENABLE, &tp->flags)) |
| 1097 | return; |
| 1098 | |
| 1099 | if (test_bit(RTL8152_UNPLUG, &tp->flags)) |
| 1100 | return; |
| 1101 | |
| 1102 | if (!skb_queue_empty(&tp->tx_queue)) |
hayeswang | 0c3121f | 2014-03-07 11:04:36 +0800 | [diff] [blame] | 1103 | tasklet_schedule(&tp->tl); |
hayeswang | ebc2ec48 | 2013-08-14 20:54:38 +0800 | [diff] [blame] | 1104 | } |
| 1105 | |
hayeswang | 40a8291 | 2013-08-14 20:54:40 +0800 | [diff] [blame] | 1106 | static void intr_callback(struct urb *urb) |
| 1107 | { |
| 1108 | struct r8152 *tp; |
hayeswang | 500b6d7 | 2013-11-20 17:30:57 +0800 | [diff] [blame] | 1109 | __le16 *d; |
hayeswang | 40a8291 | 2013-08-14 20:54:40 +0800 | [diff] [blame] | 1110 | int status = urb->status; |
| 1111 | int res; |
| 1112 | |
| 1113 | tp = urb->context; |
| 1114 | if (!tp) |
| 1115 | return; |
| 1116 | |
| 1117 | if (!test_bit(WORK_ENABLE, &tp->flags)) |
| 1118 | return; |
| 1119 | |
| 1120 | if (test_bit(RTL8152_UNPLUG, &tp->flags)) |
| 1121 | return; |
| 1122 | |
| 1123 | switch (status) { |
| 1124 | case 0: /* success */ |
| 1125 | break; |
| 1126 | case -ECONNRESET: /* unlink */ |
| 1127 | case -ESHUTDOWN: |
| 1128 | netif_device_detach(tp->netdev); |
| 1129 | case -ENOENT: |
| 1130 | return; |
| 1131 | case -EOVERFLOW: |
| 1132 | netif_info(tp, intr, tp->netdev, "intr status -EOVERFLOW\n"); |
| 1133 | goto resubmit; |
| 1134 | /* -EPIPE: should clear the halt */ |
| 1135 | default: |
| 1136 | netif_info(tp, intr, tp->netdev, "intr status %d\n", status); |
| 1137 | goto resubmit; |
| 1138 | } |
| 1139 | |
| 1140 | d = urb->transfer_buffer; |
| 1141 | if (INTR_LINK & __le16_to_cpu(d[0])) { |
| 1142 | if (!(tp->speed & LINK_STATUS)) { |
| 1143 | set_bit(RTL8152_LINK_CHG, &tp->flags); |
| 1144 | schedule_delayed_work(&tp->schedule, 0); |
| 1145 | } |
| 1146 | } else { |
| 1147 | if (tp->speed & LINK_STATUS) { |
| 1148 | set_bit(RTL8152_LINK_CHG, &tp->flags); |
| 1149 | schedule_delayed_work(&tp->schedule, 0); |
| 1150 | } |
| 1151 | } |
| 1152 | |
| 1153 | resubmit: |
| 1154 | res = usb_submit_urb(urb, GFP_ATOMIC); |
| 1155 | if (res == -ENODEV) |
| 1156 | netif_device_detach(tp->netdev); |
| 1157 | else if (res) |
| 1158 | netif_err(tp, intr, tp->netdev, |
Hayes Wang | 4a8deae | 2014-01-07 11:18:22 +0800 | [diff] [blame] | 1159 | "can't resubmit intr, status %d\n", res); |
hayeswang | 40a8291 | 2013-08-14 20:54:40 +0800 | [diff] [blame] | 1160 | } |
| 1161 | |
hayeswang | ebc2ec48 | 2013-08-14 20:54:38 +0800 | [diff] [blame] | 1162 | static inline void *rx_agg_align(void *data) |
| 1163 | { |
hayeswang | 8e1f51b | 2014-01-02 11:22:41 +0800 | [diff] [blame] | 1164 | return (void *)ALIGN((uintptr_t)data, RX_ALIGN); |
hayeswang | ebc2ec48 | 2013-08-14 20:54:38 +0800 | [diff] [blame] | 1165 | } |
| 1166 | |
| 1167 | static inline void *tx_agg_align(void *data) |
| 1168 | { |
hayeswang | 8e1f51b | 2014-01-02 11:22:41 +0800 | [diff] [blame] | 1169 | return (void *)ALIGN((uintptr_t)data, TX_ALIGN); |
hayeswang | ebc2ec48 | 2013-08-14 20:54:38 +0800 | [diff] [blame] | 1170 | } |
| 1171 | |
| 1172 | static void free_all_mem(struct r8152 *tp) |
| 1173 | { |
| 1174 | int i; |
| 1175 | |
| 1176 | for (i = 0; i < RTL8152_MAX_RX; i++) { |
hayeswang | 9629e3c | 2014-01-15 10:42:15 +0800 | [diff] [blame] | 1177 | usb_free_urb(tp->rx_info[i].urb); |
| 1178 | tp->rx_info[i].urb = NULL; |
hayeswang | ebc2ec48 | 2013-08-14 20:54:38 +0800 | [diff] [blame] | 1179 | |
hayeswang | 9629e3c | 2014-01-15 10:42:15 +0800 | [diff] [blame] | 1180 | kfree(tp->rx_info[i].buffer); |
| 1181 | tp->rx_info[i].buffer = NULL; |
| 1182 | tp->rx_info[i].head = NULL; |
hayeswang | ebc2ec48 | 2013-08-14 20:54:38 +0800 | [diff] [blame] | 1183 | } |
| 1184 | |
| 1185 | for (i = 0; i < RTL8152_MAX_TX; i++) { |
hayeswang | 9629e3c | 2014-01-15 10:42:15 +0800 | [diff] [blame] | 1186 | usb_free_urb(tp->tx_info[i].urb); |
| 1187 | tp->tx_info[i].urb = NULL; |
hayeswang | ebc2ec48 | 2013-08-14 20:54:38 +0800 | [diff] [blame] | 1188 | |
hayeswang | 9629e3c | 2014-01-15 10:42:15 +0800 | [diff] [blame] | 1189 | kfree(tp->tx_info[i].buffer); |
| 1190 | tp->tx_info[i].buffer = NULL; |
| 1191 | tp->tx_info[i].head = NULL; |
hayeswang | ebc2ec48 | 2013-08-14 20:54:38 +0800 | [diff] [blame] | 1192 | } |
hayeswang | 40a8291 | 2013-08-14 20:54:40 +0800 | [diff] [blame] | 1193 | |
hayeswang | 9629e3c | 2014-01-15 10:42:15 +0800 | [diff] [blame] | 1194 | usb_free_urb(tp->intr_urb); |
| 1195 | tp->intr_urb = NULL; |
hayeswang | 40a8291 | 2013-08-14 20:54:40 +0800 | [diff] [blame] | 1196 | |
hayeswang | 9629e3c | 2014-01-15 10:42:15 +0800 | [diff] [blame] | 1197 | kfree(tp->intr_buff); |
| 1198 | tp->intr_buff = NULL; |
hayeswang | ebc2ec48 | 2013-08-14 20:54:38 +0800 | [diff] [blame] | 1199 | } |
| 1200 | |
| 1201 | static int alloc_all_mem(struct r8152 *tp) |
| 1202 | { |
| 1203 | struct net_device *netdev = tp->netdev; |
hayeswang | 40a8291 | 2013-08-14 20:54:40 +0800 | [diff] [blame] | 1204 | struct usb_interface *intf = tp->intf; |
| 1205 | struct usb_host_interface *alt = intf->cur_altsetting; |
| 1206 | struct usb_host_endpoint *ep_intr = alt->endpoint + 2; |
hayeswang | ebc2ec48 | 2013-08-14 20:54:38 +0800 | [diff] [blame] | 1207 | struct urb *urb; |
| 1208 | int node, i; |
| 1209 | u8 *buf; |
| 1210 | |
| 1211 | node = netdev->dev.parent ? dev_to_node(netdev->dev.parent) : -1; |
| 1212 | |
| 1213 | spin_lock_init(&tp->rx_lock); |
| 1214 | spin_lock_init(&tp->tx_lock); |
| 1215 | INIT_LIST_HEAD(&tp->rx_done); |
| 1216 | INIT_LIST_HEAD(&tp->tx_free); |
| 1217 | skb_queue_head_init(&tp->tx_queue); |
| 1218 | |
| 1219 | for (i = 0; i < RTL8152_MAX_RX; i++) { |
| 1220 | buf = kmalloc_node(rx_buf_sz, GFP_KERNEL, node); |
| 1221 | if (!buf) |
| 1222 | goto err1; |
| 1223 | |
| 1224 | if (buf != rx_agg_align(buf)) { |
| 1225 | kfree(buf); |
hayeswang | 8e1f51b | 2014-01-02 11:22:41 +0800 | [diff] [blame] | 1226 | buf = kmalloc_node(rx_buf_sz + RX_ALIGN, GFP_KERNEL, |
| 1227 | node); |
hayeswang | ebc2ec48 | 2013-08-14 20:54:38 +0800 | [diff] [blame] | 1228 | if (!buf) |
| 1229 | goto err1; |
| 1230 | } |
| 1231 | |
| 1232 | urb = usb_alloc_urb(0, GFP_KERNEL); |
| 1233 | if (!urb) { |
| 1234 | kfree(buf); |
| 1235 | goto err1; |
| 1236 | } |
| 1237 | |
| 1238 | INIT_LIST_HEAD(&tp->rx_info[i].list); |
| 1239 | tp->rx_info[i].context = tp; |
| 1240 | tp->rx_info[i].urb = urb; |
| 1241 | tp->rx_info[i].buffer = buf; |
| 1242 | tp->rx_info[i].head = rx_agg_align(buf); |
| 1243 | } |
| 1244 | |
| 1245 | for (i = 0; i < RTL8152_MAX_TX; i++) { |
| 1246 | buf = kmalloc_node(rx_buf_sz, GFP_KERNEL, node); |
| 1247 | if (!buf) |
| 1248 | goto err1; |
| 1249 | |
| 1250 | if (buf != tx_agg_align(buf)) { |
| 1251 | kfree(buf); |
hayeswang | 8e1f51b | 2014-01-02 11:22:41 +0800 | [diff] [blame] | 1252 | buf = kmalloc_node(rx_buf_sz + TX_ALIGN, GFP_KERNEL, |
| 1253 | node); |
hayeswang | ebc2ec48 | 2013-08-14 20:54:38 +0800 | [diff] [blame] | 1254 | if (!buf) |
| 1255 | goto err1; |
| 1256 | } |
| 1257 | |
| 1258 | urb = usb_alloc_urb(0, GFP_KERNEL); |
| 1259 | if (!urb) { |
| 1260 | kfree(buf); |
| 1261 | goto err1; |
| 1262 | } |
| 1263 | |
| 1264 | INIT_LIST_HEAD(&tp->tx_info[i].list); |
| 1265 | tp->tx_info[i].context = tp; |
| 1266 | tp->tx_info[i].urb = urb; |
| 1267 | tp->tx_info[i].buffer = buf; |
| 1268 | tp->tx_info[i].head = tx_agg_align(buf); |
| 1269 | |
| 1270 | list_add_tail(&tp->tx_info[i].list, &tp->tx_free); |
| 1271 | } |
| 1272 | |
hayeswang | 40a8291 | 2013-08-14 20:54:40 +0800 | [diff] [blame] | 1273 | tp->intr_urb = usb_alloc_urb(0, GFP_KERNEL); |
| 1274 | if (!tp->intr_urb) |
| 1275 | goto err1; |
| 1276 | |
| 1277 | tp->intr_buff = kmalloc(INTBUFSIZE, GFP_KERNEL); |
| 1278 | if (!tp->intr_buff) |
| 1279 | goto err1; |
| 1280 | |
| 1281 | tp->intr_interval = (int)ep_intr->desc.bInterval; |
| 1282 | usb_fill_int_urb(tp->intr_urb, tp->udev, usb_rcvintpipe(tp->udev, 3), |
| 1283 | tp->intr_buff, INTBUFSIZE, intr_callback, |
| 1284 | tp, tp->intr_interval); |
| 1285 | |
hayeswang | ebc2ec48 | 2013-08-14 20:54:38 +0800 | [diff] [blame] | 1286 | return 0; |
| 1287 | |
| 1288 | err1: |
| 1289 | free_all_mem(tp); |
| 1290 | return -ENOMEM; |
| 1291 | } |
| 1292 | |
hayeswang | 0de98f6 | 2013-08-16 16:09:35 +0800 | [diff] [blame] | 1293 | static struct tx_agg *r8152_get_tx_agg(struct r8152 *tp) |
| 1294 | { |
| 1295 | struct tx_agg *agg = NULL; |
| 1296 | unsigned long flags; |
| 1297 | |
hayeswang | 21949ab | 2014-03-07 11:04:35 +0800 | [diff] [blame] | 1298 | if (list_empty(&tp->tx_free)) |
| 1299 | return NULL; |
| 1300 | |
hayeswang | 0de98f6 | 2013-08-16 16:09:35 +0800 | [diff] [blame] | 1301 | spin_lock_irqsave(&tp->tx_lock, flags); |
| 1302 | if (!list_empty(&tp->tx_free)) { |
| 1303 | struct list_head *cursor; |
| 1304 | |
| 1305 | cursor = tp->tx_free.next; |
| 1306 | list_del_init(cursor); |
| 1307 | agg = list_entry(cursor, struct tx_agg, list); |
| 1308 | } |
| 1309 | spin_unlock_irqrestore(&tp->tx_lock, flags); |
| 1310 | |
| 1311 | return agg; |
| 1312 | } |
| 1313 | |
hayeswang | 60c8907 | 2014-03-07 11:04:39 +0800 | [diff] [blame] | 1314 | static inline __be16 get_protocol(struct sk_buff *skb) |
hayeswang | 5bd2388 | 2013-08-14 20:54:39 +0800 | [diff] [blame] | 1315 | { |
hayeswang | 60c8907 | 2014-03-07 11:04:39 +0800 | [diff] [blame] | 1316 | __be16 protocol; |
hayeswang | 5bd2388 | 2013-08-14 20:54:39 +0800 | [diff] [blame] | 1317 | |
hayeswang | 60c8907 | 2014-03-07 11:04:39 +0800 | [diff] [blame] | 1318 | if (skb->protocol == htons(ETH_P_8021Q)) |
| 1319 | protocol = vlan_eth_hdr(skb)->h_vlan_encapsulated_proto; |
| 1320 | else |
| 1321 | protocol = skb->protocol; |
hayeswang | 5bd2388 | 2013-08-14 20:54:39 +0800 | [diff] [blame] | 1322 | |
hayeswang | 60c8907 | 2014-03-07 11:04:39 +0800 | [diff] [blame] | 1323 | return protocol; |
| 1324 | } |
| 1325 | |
hayeswang | 6128d1bb | 2014-03-07 11:04:40 +0800 | [diff] [blame] | 1326 | /* |
| 1327 | * r8152_csum_workaround() |
| 1328 | * The hw limites the value the transport offset. When the offset is out of the |
| 1329 | * range, calculate the checksum by sw. |
| 1330 | */ |
| 1331 | static void r8152_csum_workaround(struct r8152 *tp, struct sk_buff *skb, |
| 1332 | struct sk_buff_head *list) |
| 1333 | { |
| 1334 | if (skb_shinfo(skb)->gso_size) { |
| 1335 | netdev_features_t features = tp->netdev->features; |
| 1336 | struct sk_buff_head seg_list; |
| 1337 | struct sk_buff *segs, *nskb; |
| 1338 | |
| 1339 | features &= ~(NETIF_F_IP_CSUM | NETIF_F_SG | NETIF_F_TSO); |
| 1340 | segs = skb_gso_segment(skb, features); |
| 1341 | if (IS_ERR(segs) || !segs) |
| 1342 | goto drop; |
| 1343 | |
| 1344 | __skb_queue_head_init(&seg_list); |
| 1345 | |
| 1346 | do { |
| 1347 | nskb = segs; |
| 1348 | segs = segs->next; |
| 1349 | nskb->next = NULL; |
| 1350 | __skb_queue_tail(&seg_list, nskb); |
| 1351 | } while (segs); |
| 1352 | |
| 1353 | skb_queue_splice(&seg_list, list); |
| 1354 | dev_kfree_skb(skb); |
| 1355 | } else if (skb->ip_summed == CHECKSUM_PARTIAL) { |
| 1356 | if (skb_checksum_help(skb) < 0) |
| 1357 | goto drop; |
| 1358 | |
| 1359 | __skb_queue_head(list, skb); |
| 1360 | } else { |
| 1361 | struct net_device_stats *stats; |
| 1362 | |
| 1363 | drop: |
| 1364 | stats = &tp->netdev->stats; |
| 1365 | stats->tx_dropped++; |
| 1366 | dev_kfree_skb(skb); |
| 1367 | } |
| 1368 | } |
| 1369 | |
| 1370 | /* |
| 1371 | * msdn_giant_send_check() |
| 1372 | * According to the document of microsoft, the TCP Pseudo Header excludes the |
| 1373 | * packet length for IPv6 TCP large packets. |
| 1374 | */ |
| 1375 | static int msdn_giant_send_check(struct sk_buff *skb) |
| 1376 | { |
| 1377 | const struct ipv6hdr *ipv6h; |
| 1378 | struct tcphdr *th; |
hayeswang | fcb308d | 2014-03-11 10:20:32 +0800 | [diff] [blame^] | 1379 | int ret; |
| 1380 | |
| 1381 | ret = skb_cow_head(skb, 0); |
| 1382 | if (ret) |
| 1383 | return ret; |
hayeswang | 6128d1bb | 2014-03-07 11:04:40 +0800 | [diff] [blame] | 1384 | |
| 1385 | ipv6h = ipv6_hdr(skb); |
| 1386 | th = tcp_hdr(skb); |
| 1387 | |
| 1388 | th->check = 0; |
| 1389 | th->check = ~tcp_v6_check(0, &ipv6h->saddr, &ipv6h->daddr, 0); |
| 1390 | |
hayeswang | fcb308d | 2014-03-11 10:20:32 +0800 | [diff] [blame^] | 1391 | return ret; |
hayeswang | 6128d1bb | 2014-03-07 11:04:40 +0800 | [diff] [blame] | 1392 | } |
| 1393 | |
hayeswang | 60c8907 | 2014-03-07 11:04:39 +0800 | [diff] [blame] | 1394 | static int r8152_tx_csum(struct r8152 *tp, struct tx_desc *desc, |
| 1395 | struct sk_buff *skb, u32 len, u32 transport_offset) |
| 1396 | { |
| 1397 | u32 mss = skb_shinfo(skb)->gso_size; |
| 1398 | u32 opts1, opts2 = 0; |
| 1399 | int ret = TX_CSUM_SUCCESS; |
| 1400 | |
| 1401 | WARN_ON_ONCE(len > TX_LEN_MAX); |
| 1402 | |
| 1403 | opts1 = len | TX_FS | TX_LS; |
| 1404 | |
| 1405 | if (mss) { |
hayeswang | 6128d1bb | 2014-03-07 11:04:40 +0800 | [diff] [blame] | 1406 | if (transport_offset > GTTCPHO_MAX) { |
| 1407 | netif_warn(tp, tx_err, tp->netdev, |
| 1408 | "Invalid transport offset 0x%x for TSO\n", |
| 1409 | transport_offset); |
| 1410 | ret = TX_CSUM_TSO; |
| 1411 | goto unavailable; |
| 1412 | } |
| 1413 | |
hayeswang | 60c8907 | 2014-03-07 11:04:39 +0800 | [diff] [blame] | 1414 | switch (get_protocol(skb)) { |
| 1415 | case htons(ETH_P_IP): |
| 1416 | opts1 |= GTSENDV4; |
| 1417 | break; |
| 1418 | |
hayeswang | 6128d1bb | 2014-03-07 11:04:40 +0800 | [diff] [blame] | 1419 | case htons(ETH_P_IPV6): |
hayeswang | fcb308d | 2014-03-11 10:20:32 +0800 | [diff] [blame^] | 1420 | if (msdn_giant_send_check(skb)) { |
| 1421 | ret = TX_CSUM_TSO; |
| 1422 | goto unavailable; |
| 1423 | } |
hayeswang | 6128d1bb | 2014-03-07 11:04:40 +0800 | [diff] [blame] | 1424 | opts1 |= GTSENDV6; |
hayeswang | 6128d1bb | 2014-03-07 11:04:40 +0800 | [diff] [blame] | 1425 | break; |
| 1426 | |
hayeswang | 60c8907 | 2014-03-07 11:04:39 +0800 | [diff] [blame] | 1427 | default: |
| 1428 | WARN_ON_ONCE(1); |
| 1429 | break; |
| 1430 | } |
| 1431 | |
| 1432 | opts1 |= transport_offset << GTTCPHO_SHIFT; |
| 1433 | opts2 |= min(mss, MSS_MAX) << MSS_SHIFT; |
| 1434 | } else if (skb->ip_summed == CHECKSUM_PARTIAL) { |
hayeswang | 5bd2388 | 2013-08-14 20:54:39 +0800 | [diff] [blame] | 1435 | u8 ip_protocol; |
hayeswang | 5bd2388 | 2013-08-14 20:54:39 +0800 | [diff] [blame] | 1436 | |
hayeswang | 6128d1bb | 2014-03-07 11:04:40 +0800 | [diff] [blame] | 1437 | if (transport_offset > TCPHO_MAX) { |
| 1438 | netif_warn(tp, tx_err, tp->netdev, |
| 1439 | "Invalid transport offset 0x%x\n", |
| 1440 | transport_offset); |
| 1441 | ret = TX_CSUM_NONE; |
| 1442 | goto unavailable; |
| 1443 | } |
| 1444 | |
hayeswang | 60c8907 | 2014-03-07 11:04:39 +0800 | [diff] [blame] | 1445 | switch (get_protocol(skb)) { |
hayeswang | 5bd2388 | 2013-08-14 20:54:39 +0800 | [diff] [blame] | 1446 | case htons(ETH_P_IP): |
| 1447 | opts2 |= IPV4_CS; |
| 1448 | ip_protocol = ip_hdr(skb)->protocol; |
| 1449 | break; |
| 1450 | |
| 1451 | case htons(ETH_P_IPV6): |
| 1452 | opts2 |= IPV6_CS; |
| 1453 | ip_protocol = ipv6_hdr(skb)->nexthdr; |
| 1454 | break; |
| 1455 | |
| 1456 | default: |
| 1457 | ip_protocol = IPPROTO_RAW; |
| 1458 | break; |
| 1459 | } |
| 1460 | |
hayeswang | 60c8907 | 2014-03-07 11:04:39 +0800 | [diff] [blame] | 1461 | if (ip_protocol == IPPROTO_TCP) |
hayeswang | 5bd2388 | 2013-08-14 20:54:39 +0800 | [diff] [blame] | 1462 | opts2 |= TCP_CS; |
hayeswang | 60c8907 | 2014-03-07 11:04:39 +0800 | [diff] [blame] | 1463 | else if (ip_protocol == IPPROTO_UDP) |
hayeswang | 5bd2388 | 2013-08-14 20:54:39 +0800 | [diff] [blame] | 1464 | opts2 |= UDP_CS; |
hayeswang | 60c8907 | 2014-03-07 11:04:39 +0800 | [diff] [blame] | 1465 | else |
hayeswang | 5bd2388 | 2013-08-14 20:54:39 +0800 | [diff] [blame] | 1466 | WARN_ON_ONCE(1); |
hayeswang | 5bd2388 | 2013-08-14 20:54:39 +0800 | [diff] [blame] | 1467 | |
hayeswang | 60c8907 | 2014-03-07 11:04:39 +0800 | [diff] [blame] | 1468 | opts2 |= transport_offset << TCPHO_SHIFT; |
hayeswang | 5bd2388 | 2013-08-14 20:54:39 +0800 | [diff] [blame] | 1469 | } |
hayeswang | 60c8907 | 2014-03-07 11:04:39 +0800 | [diff] [blame] | 1470 | |
| 1471 | desc->opts2 = cpu_to_le32(opts2); |
| 1472 | desc->opts1 = cpu_to_le32(opts1); |
| 1473 | |
hayeswang | 6128d1bb | 2014-03-07 11:04:40 +0800 | [diff] [blame] | 1474 | unavailable: |
hayeswang | 60c8907 | 2014-03-07 11:04:39 +0800 | [diff] [blame] | 1475 | return ret; |
hayeswang | 5bd2388 | 2013-08-14 20:54:39 +0800 | [diff] [blame] | 1476 | } |
| 1477 | |
hayeswang | b1379d9 | 2013-08-16 16:09:37 +0800 | [diff] [blame] | 1478 | static int r8152_tx_agg_fill(struct r8152 *tp, struct tx_agg *agg) |
| 1479 | { |
hayeswang | d84130a | 2014-02-18 21:49:02 +0800 | [diff] [blame] | 1480 | struct sk_buff_head skb_head, *tx_queue = &tp->tx_queue; |
hayeswang | 9a4be1b | 2014-02-18 21:49:07 +0800 | [diff] [blame] | 1481 | int remain, ret; |
hayeswang | b1379d9 | 2013-08-16 16:09:37 +0800 | [diff] [blame] | 1482 | u8 *tx_data; |
| 1483 | |
hayeswang | d84130a | 2014-02-18 21:49:02 +0800 | [diff] [blame] | 1484 | __skb_queue_head_init(&skb_head); |
hayeswang | 0c3121f | 2014-03-07 11:04:36 +0800 | [diff] [blame] | 1485 | spin_lock(&tx_queue->lock); |
hayeswang | d84130a | 2014-02-18 21:49:02 +0800 | [diff] [blame] | 1486 | skb_queue_splice_init(tx_queue, &skb_head); |
hayeswang | 0c3121f | 2014-03-07 11:04:36 +0800 | [diff] [blame] | 1487 | spin_unlock(&tx_queue->lock); |
hayeswang | d84130a | 2014-02-18 21:49:02 +0800 | [diff] [blame] | 1488 | |
hayeswang | b1379d9 | 2013-08-16 16:09:37 +0800 | [diff] [blame] | 1489 | tx_data = agg->head; |
| 1490 | agg->skb_num = agg->skb_len = 0; |
hayeswang | 7937f9e | 2013-11-20 17:30:54 +0800 | [diff] [blame] | 1491 | remain = rx_buf_sz; |
hayeswang | b1379d9 | 2013-08-16 16:09:37 +0800 | [diff] [blame] | 1492 | |
hayeswang | 7937f9e | 2013-11-20 17:30:54 +0800 | [diff] [blame] | 1493 | while (remain >= ETH_ZLEN + sizeof(struct tx_desc)) { |
hayeswang | b1379d9 | 2013-08-16 16:09:37 +0800 | [diff] [blame] | 1494 | struct tx_desc *tx_desc; |
| 1495 | struct sk_buff *skb; |
| 1496 | unsigned int len; |
hayeswang | 60c8907 | 2014-03-07 11:04:39 +0800 | [diff] [blame] | 1497 | u32 offset; |
hayeswang | b1379d9 | 2013-08-16 16:09:37 +0800 | [diff] [blame] | 1498 | |
hayeswang | d84130a | 2014-02-18 21:49:02 +0800 | [diff] [blame] | 1499 | skb = __skb_dequeue(&skb_head); |
hayeswang | b1379d9 | 2013-08-16 16:09:37 +0800 | [diff] [blame] | 1500 | if (!skb) |
| 1501 | break; |
| 1502 | |
hayeswang | 60c8907 | 2014-03-07 11:04:39 +0800 | [diff] [blame] | 1503 | len = skb->len + sizeof(*tx_desc); |
| 1504 | |
| 1505 | if (len > remain) { |
hayeswang | d84130a | 2014-02-18 21:49:02 +0800 | [diff] [blame] | 1506 | __skb_queue_head(&skb_head, skb); |
hayeswang | b1379d9 | 2013-08-16 16:09:37 +0800 | [diff] [blame] | 1507 | break; |
| 1508 | } |
| 1509 | |
hayeswang | 7937f9e | 2013-11-20 17:30:54 +0800 | [diff] [blame] | 1510 | tx_data = tx_agg_align(tx_data); |
hayeswang | b1379d9 | 2013-08-16 16:09:37 +0800 | [diff] [blame] | 1511 | tx_desc = (struct tx_desc *)tx_data; |
hayeswang | 60c8907 | 2014-03-07 11:04:39 +0800 | [diff] [blame] | 1512 | |
| 1513 | offset = (u32)skb_transport_offset(skb); |
| 1514 | |
hayeswang | 6128d1bb | 2014-03-07 11:04:40 +0800 | [diff] [blame] | 1515 | if (r8152_tx_csum(tp, tx_desc, skb, skb->len, offset)) { |
| 1516 | r8152_csum_workaround(tp, skb, &skb_head); |
| 1517 | continue; |
| 1518 | } |
hayeswang | 60c8907 | 2014-03-07 11:04:39 +0800 | [diff] [blame] | 1519 | |
hayeswang | b1379d9 | 2013-08-16 16:09:37 +0800 | [diff] [blame] | 1520 | tx_data += sizeof(*tx_desc); |
| 1521 | |
hayeswang | 60c8907 | 2014-03-07 11:04:39 +0800 | [diff] [blame] | 1522 | len = skb->len; |
| 1523 | if (skb_copy_bits(skb, 0, tx_data, len) < 0) { |
| 1524 | struct net_device_stats *stats = &tp->netdev->stats; |
| 1525 | |
| 1526 | stats->tx_dropped++; |
| 1527 | dev_kfree_skb_any(skb); |
| 1528 | tx_data -= sizeof(*tx_desc); |
| 1529 | continue; |
| 1530 | } |
hayeswang | b1379d9 | 2013-08-16 16:09:37 +0800 | [diff] [blame] | 1531 | |
hayeswang | 7937f9e | 2013-11-20 17:30:54 +0800 | [diff] [blame] | 1532 | tx_data += len; |
hayeswang | 60c8907 | 2014-03-07 11:04:39 +0800 | [diff] [blame] | 1533 | agg->skb_len += len; |
| 1534 | agg->skb_num++; |
| 1535 | |
| 1536 | dev_kfree_skb_any(skb); |
| 1537 | |
hayeswang | 7937f9e | 2013-11-20 17:30:54 +0800 | [diff] [blame] | 1538 | remain = rx_buf_sz - (int)(tx_agg_align(tx_data) - agg->head); |
hayeswang | b1379d9 | 2013-08-16 16:09:37 +0800 | [diff] [blame] | 1539 | } |
| 1540 | |
hayeswang | d84130a | 2014-02-18 21:49:02 +0800 | [diff] [blame] | 1541 | if (!skb_queue_empty(&skb_head)) { |
hayeswang | 0c3121f | 2014-03-07 11:04:36 +0800 | [diff] [blame] | 1542 | spin_lock(&tx_queue->lock); |
hayeswang | d84130a | 2014-02-18 21:49:02 +0800 | [diff] [blame] | 1543 | skb_queue_splice(&skb_head, tx_queue); |
hayeswang | 0c3121f | 2014-03-07 11:04:36 +0800 | [diff] [blame] | 1544 | spin_unlock(&tx_queue->lock); |
hayeswang | d84130a | 2014-02-18 21:49:02 +0800 | [diff] [blame] | 1545 | } |
| 1546 | |
hayeswang | 0c3121f | 2014-03-07 11:04:36 +0800 | [diff] [blame] | 1547 | netif_tx_lock(tp->netdev); |
hayeswang | dd1b119 | 2013-11-20 17:30:56 +0800 | [diff] [blame] | 1548 | |
| 1549 | if (netif_queue_stopped(tp->netdev) && |
| 1550 | skb_queue_len(&tp->tx_queue) < tp->tx_qlen) |
| 1551 | netif_wake_queue(tp->netdev); |
| 1552 | |
hayeswang | 0c3121f | 2014-03-07 11:04:36 +0800 | [diff] [blame] | 1553 | netif_tx_unlock(tp->netdev); |
hayeswang | 9a4be1b | 2014-02-18 21:49:07 +0800 | [diff] [blame] | 1554 | |
hayeswang | 0c3121f | 2014-03-07 11:04:36 +0800 | [diff] [blame] | 1555 | ret = usb_autopm_get_interface_async(tp->intf); |
hayeswang | 9a4be1b | 2014-02-18 21:49:07 +0800 | [diff] [blame] | 1556 | if (ret < 0) |
| 1557 | goto out_tx_fill; |
hayeswang | dd1b119 | 2013-11-20 17:30:56 +0800 | [diff] [blame] | 1558 | |
hayeswang | b1379d9 | 2013-08-16 16:09:37 +0800 | [diff] [blame] | 1559 | usb_fill_bulk_urb(agg->urb, tp->udev, usb_sndbulkpipe(tp->udev, 2), |
| 1560 | agg->head, (int)(tx_data - (u8 *)agg->head), |
| 1561 | (usb_complete_t)write_bulk_callback, agg); |
| 1562 | |
hayeswang | 0c3121f | 2014-03-07 11:04:36 +0800 | [diff] [blame] | 1563 | ret = usb_submit_urb(agg->urb, GFP_ATOMIC); |
hayeswang | 9a4be1b | 2014-02-18 21:49:07 +0800 | [diff] [blame] | 1564 | if (ret < 0) |
hayeswang | 0c3121f | 2014-03-07 11:04:36 +0800 | [diff] [blame] | 1565 | usb_autopm_put_interface_async(tp->intf); |
hayeswang | 9a4be1b | 2014-02-18 21:49:07 +0800 | [diff] [blame] | 1566 | |
| 1567 | out_tx_fill: |
| 1568 | return ret; |
hayeswang | b1379d9 | 2013-08-16 16:09:37 +0800 | [diff] [blame] | 1569 | } |
| 1570 | |
hayeswang | 565cab0 | 2014-03-07 11:04:38 +0800 | [diff] [blame] | 1571 | static u8 r8152_rx_csum(struct r8152 *tp, struct rx_desc *rx_desc) |
| 1572 | { |
| 1573 | u8 checksum = CHECKSUM_NONE; |
| 1574 | u32 opts2, opts3; |
| 1575 | |
| 1576 | if (tp->version == RTL_VER_01) |
| 1577 | goto return_result; |
| 1578 | |
| 1579 | opts2 = le32_to_cpu(rx_desc->opts2); |
| 1580 | opts3 = le32_to_cpu(rx_desc->opts3); |
| 1581 | |
| 1582 | if (opts2 & RD_IPV4_CS) { |
| 1583 | if (opts3 & IPF) |
| 1584 | checksum = CHECKSUM_NONE; |
| 1585 | else if ((opts2 & RD_UDP_CS) && (opts3 & UDPF)) |
| 1586 | checksum = CHECKSUM_NONE; |
| 1587 | else if ((opts2 & RD_TCP_CS) && (opts3 & TCPF)) |
| 1588 | checksum = CHECKSUM_NONE; |
| 1589 | else |
| 1590 | checksum = CHECKSUM_UNNECESSARY; |
hayeswang | 6128d1bb | 2014-03-07 11:04:40 +0800 | [diff] [blame] | 1591 | } else if (RD_IPV6_CS) { |
| 1592 | if ((opts2 & RD_UDP_CS) && !(opts3 & UDPF)) |
| 1593 | checksum = CHECKSUM_UNNECESSARY; |
| 1594 | else if ((opts2 & RD_TCP_CS) && !(opts3 & TCPF)) |
| 1595 | checksum = CHECKSUM_UNNECESSARY; |
hayeswang | 565cab0 | 2014-03-07 11:04:38 +0800 | [diff] [blame] | 1596 | } |
| 1597 | |
| 1598 | return_result: |
| 1599 | return checksum; |
| 1600 | } |
| 1601 | |
hayeswang | ebc2ec48 | 2013-08-14 20:54:38 +0800 | [diff] [blame] | 1602 | static void rx_bottom(struct r8152 *tp) |
| 1603 | { |
hayeswang | a5a4f46 | 2013-08-16 16:09:34 +0800 | [diff] [blame] | 1604 | unsigned long flags; |
hayeswang | d84130a | 2014-02-18 21:49:02 +0800 | [diff] [blame] | 1605 | struct list_head *cursor, *next, rx_queue; |
hayeswang | ebc2ec48 | 2013-08-14 20:54:38 +0800 | [diff] [blame] | 1606 | |
hayeswang | d84130a | 2014-02-18 21:49:02 +0800 | [diff] [blame] | 1607 | if (list_empty(&tp->rx_done)) |
| 1608 | return; |
| 1609 | |
| 1610 | INIT_LIST_HEAD(&rx_queue); |
hayeswang | a5a4f46 | 2013-08-16 16:09:34 +0800 | [diff] [blame] | 1611 | spin_lock_irqsave(&tp->rx_lock, flags); |
hayeswang | d84130a | 2014-02-18 21:49:02 +0800 | [diff] [blame] | 1612 | list_splice_init(&tp->rx_done, &rx_queue); |
| 1613 | spin_unlock_irqrestore(&tp->rx_lock, flags); |
| 1614 | |
| 1615 | list_for_each_safe(cursor, next, &rx_queue) { |
hayeswang | 43a4478 | 2013-08-16 16:09:36 +0800 | [diff] [blame] | 1616 | struct rx_desc *rx_desc; |
| 1617 | struct rx_agg *agg; |
hayeswang | 43a4478 | 2013-08-16 16:09:36 +0800 | [diff] [blame] | 1618 | int len_used = 0; |
| 1619 | struct urb *urb; |
| 1620 | u8 *rx_data; |
| 1621 | int ret; |
| 1622 | |
hayeswang | ebc2ec48 | 2013-08-14 20:54:38 +0800 | [diff] [blame] | 1623 | list_del_init(cursor); |
hayeswang | ebc2ec48 | 2013-08-14 20:54:38 +0800 | [diff] [blame] | 1624 | |
| 1625 | agg = list_entry(cursor, struct rx_agg, list); |
| 1626 | urb = agg->urb; |
hayeswang | 0de98f6 | 2013-08-16 16:09:35 +0800 | [diff] [blame] | 1627 | if (urb->actual_length < ETH_ZLEN) |
| 1628 | goto submit; |
hayeswang | ebc2ec48 | 2013-08-14 20:54:38 +0800 | [diff] [blame] | 1629 | |
hayeswang | ebc2ec48 | 2013-08-14 20:54:38 +0800 | [diff] [blame] | 1630 | rx_desc = agg->head; |
| 1631 | rx_data = agg->head; |
hayeswang | 7937f9e | 2013-11-20 17:30:54 +0800 | [diff] [blame] | 1632 | len_used += sizeof(struct rx_desc); |
hayeswang | ebc2ec48 | 2013-08-14 20:54:38 +0800 | [diff] [blame] | 1633 | |
hayeswang | 7937f9e | 2013-11-20 17:30:54 +0800 | [diff] [blame] | 1634 | while (urb->actual_length > len_used) { |
hayeswang | 43a4478 | 2013-08-16 16:09:36 +0800 | [diff] [blame] | 1635 | struct net_device *netdev = tp->netdev; |
hayeswang | 05e0f1a | 2014-03-06 15:07:18 +0800 | [diff] [blame] | 1636 | struct net_device_stats *stats = &netdev->stats; |
hayeswang | 7937f9e | 2013-11-20 17:30:54 +0800 | [diff] [blame] | 1637 | unsigned int pkt_len; |
hayeswang | 43a4478 | 2013-08-16 16:09:36 +0800 | [diff] [blame] | 1638 | struct sk_buff *skb; |
| 1639 | |
hayeswang | 7937f9e | 2013-11-20 17:30:54 +0800 | [diff] [blame] | 1640 | pkt_len = le32_to_cpu(rx_desc->opts1) & RX_LEN_MASK; |
hayeswang | ebc2ec48 | 2013-08-14 20:54:38 +0800 | [diff] [blame] | 1641 | if (pkt_len < ETH_ZLEN) |
| 1642 | break; |
| 1643 | |
hayeswang | 7937f9e | 2013-11-20 17:30:54 +0800 | [diff] [blame] | 1644 | len_used += pkt_len; |
| 1645 | if (urb->actual_length < len_used) |
| 1646 | break; |
| 1647 | |
hayeswang | 8e1f51b | 2014-01-02 11:22:41 +0800 | [diff] [blame] | 1648 | pkt_len -= CRC_SIZE; |
hayeswang | ebc2ec48 | 2013-08-14 20:54:38 +0800 | [diff] [blame] | 1649 | rx_data += sizeof(struct rx_desc); |
| 1650 | |
| 1651 | skb = netdev_alloc_skb_ip_align(netdev, pkt_len); |
| 1652 | if (!skb) { |
| 1653 | stats->rx_dropped++; |
hayeswang | 5e2f748 | 2014-03-07 11:04:37 +0800 | [diff] [blame] | 1654 | goto find_next_rx; |
hayeswang | ebc2ec48 | 2013-08-14 20:54:38 +0800 | [diff] [blame] | 1655 | } |
hayeswang | 565cab0 | 2014-03-07 11:04:38 +0800 | [diff] [blame] | 1656 | |
| 1657 | skb->ip_summed = r8152_rx_csum(tp, rx_desc); |
hayeswang | ebc2ec48 | 2013-08-14 20:54:38 +0800 | [diff] [blame] | 1658 | memcpy(skb->data, rx_data, pkt_len); |
| 1659 | skb_put(skb, pkt_len); |
| 1660 | skb->protocol = eth_type_trans(skb, netdev); |
hayeswang | 9d9aafa | 2014-02-18 21:49:09 +0800 | [diff] [blame] | 1661 | netif_receive_skb(skb); |
hayeswang | ebc2ec48 | 2013-08-14 20:54:38 +0800 | [diff] [blame] | 1662 | stats->rx_packets++; |
| 1663 | stats->rx_bytes += pkt_len; |
| 1664 | |
hayeswang | 5e2f748 | 2014-03-07 11:04:37 +0800 | [diff] [blame] | 1665 | find_next_rx: |
hayeswang | 8e1f51b | 2014-01-02 11:22:41 +0800 | [diff] [blame] | 1666 | rx_data = rx_agg_align(rx_data + pkt_len + CRC_SIZE); |
hayeswang | ebc2ec48 | 2013-08-14 20:54:38 +0800 | [diff] [blame] | 1667 | rx_desc = (struct rx_desc *)rx_data; |
hayeswang | ebc2ec48 | 2013-08-14 20:54:38 +0800 | [diff] [blame] | 1668 | len_used = (int)(rx_data - (u8 *)agg->head); |
hayeswang | 7937f9e | 2013-11-20 17:30:54 +0800 | [diff] [blame] | 1669 | len_used += sizeof(struct rx_desc); |
hayeswang | ebc2ec48 | 2013-08-14 20:54:38 +0800 | [diff] [blame] | 1670 | } |
| 1671 | |
hayeswang | 0de98f6 | 2013-08-16 16:09:35 +0800 | [diff] [blame] | 1672 | submit: |
hayeswang | ebc2ec48 | 2013-08-14 20:54:38 +0800 | [diff] [blame] | 1673 | ret = r8152_submit_rx(tp, agg, GFP_ATOMIC); |
hayeswang | ebc2ec48 | 2013-08-14 20:54:38 +0800 | [diff] [blame] | 1674 | if (ret && ret != -ENODEV) { |
hayeswang | d84130a | 2014-02-18 21:49:02 +0800 | [diff] [blame] | 1675 | spin_lock_irqsave(&tp->rx_lock, flags); |
| 1676 | list_add_tail(&agg->list, &tp->rx_done); |
| 1677 | spin_unlock_irqrestore(&tp->rx_lock, flags); |
hayeswang | ebc2ec48 | 2013-08-14 20:54:38 +0800 | [diff] [blame] | 1678 | tasklet_schedule(&tp->tl); |
| 1679 | } |
| 1680 | } |
hayeswang | ebc2ec48 | 2013-08-14 20:54:38 +0800 | [diff] [blame] | 1681 | } |
| 1682 | |
| 1683 | static void tx_bottom(struct r8152 *tp) |
| 1684 | { |
hayeswang | ebc2ec48 | 2013-08-14 20:54:38 +0800 | [diff] [blame] | 1685 | int res; |
| 1686 | |
hayeswang | b1379d9 | 2013-08-16 16:09:37 +0800 | [diff] [blame] | 1687 | do { |
| 1688 | struct tx_agg *agg; |
hayeswang | ebc2ec48 | 2013-08-14 20:54:38 +0800 | [diff] [blame] | 1689 | |
hayeswang | b1379d9 | 2013-08-16 16:09:37 +0800 | [diff] [blame] | 1690 | if (skb_queue_empty(&tp->tx_queue)) |
hayeswang | ebc2ec48 | 2013-08-14 20:54:38 +0800 | [diff] [blame] | 1691 | break; |
| 1692 | |
hayeswang | b1379d9 | 2013-08-16 16:09:37 +0800 | [diff] [blame] | 1693 | agg = r8152_get_tx_agg(tp); |
| 1694 | if (!agg) |
hayeswang | ebc2ec48 | 2013-08-14 20:54:38 +0800 | [diff] [blame] | 1695 | break; |
hayeswang | b1379d9 | 2013-08-16 16:09:37 +0800 | [diff] [blame] | 1696 | |
| 1697 | res = r8152_tx_agg_fill(tp, agg); |
| 1698 | if (res) { |
hayeswang | 05e0f1a | 2014-03-06 15:07:18 +0800 | [diff] [blame] | 1699 | struct net_device *netdev = tp->netdev; |
hayeswang | b1379d9 | 2013-08-16 16:09:37 +0800 | [diff] [blame] | 1700 | |
| 1701 | if (res == -ENODEV) { |
| 1702 | netif_device_detach(netdev); |
| 1703 | } else { |
hayeswang | 05e0f1a | 2014-03-06 15:07:18 +0800 | [diff] [blame] | 1704 | struct net_device_stats *stats = &netdev->stats; |
| 1705 | unsigned long flags; |
| 1706 | |
hayeswang | b1379d9 | 2013-08-16 16:09:37 +0800 | [diff] [blame] | 1707 | netif_warn(tp, tx_err, netdev, |
| 1708 | "failed tx_urb %d\n", res); |
| 1709 | stats->tx_dropped += agg->skb_num; |
hayeswang | db8515e | 2014-03-06 15:07:16 +0800 | [diff] [blame] | 1710 | |
hayeswang | b1379d9 | 2013-08-16 16:09:37 +0800 | [diff] [blame] | 1711 | spin_lock_irqsave(&tp->tx_lock, flags); |
| 1712 | list_add_tail(&agg->list, &tp->tx_free); |
| 1713 | spin_unlock_irqrestore(&tp->tx_lock, flags); |
| 1714 | } |
hayeswang | ebc2ec48 | 2013-08-14 20:54:38 +0800 | [diff] [blame] | 1715 | } |
hayeswang | b1379d9 | 2013-08-16 16:09:37 +0800 | [diff] [blame] | 1716 | } while (res == 0); |
hayeswang | ebc2ec48 | 2013-08-14 20:54:38 +0800 | [diff] [blame] | 1717 | } |
| 1718 | |
| 1719 | static void bottom_half(unsigned long data) |
| 1720 | { |
| 1721 | struct r8152 *tp; |
| 1722 | |
| 1723 | tp = (struct r8152 *)data; |
| 1724 | |
| 1725 | if (test_bit(RTL8152_UNPLUG, &tp->flags)) |
| 1726 | return; |
| 1727 | |
| 1728 | if (!test_bit(WORK_ENABLE, &tp->flags)) |
| 1729 | return; |
| 1730 | |
hayeswang | 7559fb2f | 2013-08-16 16:09:38 +0800 | [diff] [blame] | 1731 | /* When link down, the driver would cancel all bulks. */ |
| 1732 | /* This avoid the re-submitting bulk */ |
hayeswang | ebc2ec48 | 2013-08-14 20:54:38 +0800 | [diff] [blame] | 1733 | if (!netif_carrier_ok(tp->netdev)) |
| 1734 | return; |
| 1735 | |
| 1736 | rx_bottom(tp); |
hayeswang | 0c3121f | 2014-03-07 11:04:36 +0800 | [diff] [blame] | 1737 | tx_bottom(tp); |
hayeswang | ebc2ec48 | 2013-08-14 20:54:38 +0800 | [diff] [blame] | 1738 | } |
| 1739 | |
| 1740 | static |
| 1741 | int r8152_submit_rx(struct r8152 *tp, struct rx_agg *agg, gfp_t mem_flags) |
| 1742 | { |
| 1743 | usb_fill_bulk_urb(agg->urb, tp->udev, usb_rcvbulkpipe(tp->udev, 1), |
| 1744 | agg->head, rx_buf_sz, |
| 1745 | (usb_complete_t)read_bulk_callback, agg); |
| 1746 | |
| 1747 | return usb_submit_urb(agg->urb, mem_flags); |
hayeswang | ac718b6 | 2013-05-02 16:01:25 +0000 | [diff] [blame] | 1748 | } |
| 1749 | |
hayeswang | 00a5e36 | 2014-02-18 21:48:59 +0800 | [diff] [blame] | 1750 | static void rtl_drop_queued_tx(struct r8152 *tp) |
| 1751 | { |
| 1752 | struct net_device_stats *stats = &tp->netdev->stats; |
hayeswang | d84130a | 2014-02-18 21:49:02 +0800 | [diff] [blame] | 1753 | struct sk_buff_head skb_head, *tx_queue = &tp->tx_queue; |
hayeswang | 00a5e36 | 2014-02-18 21:48:59 +0800 | [diff] [blame] | 1754 | struct sk_buff *skb; |
| 1755 | |
hayeswang | d84130a | 2014-02-18 21:49:02 +0800 | [diff] [blame] | 1756 | if (skb_queue_empty(tx_queue)) |
| 1757 | return; |
| 1758 | |
| 1759 | __skb_queue_head_init(&skb_head); |
hayeswang | 2685d41 | 2014-03-07 11:04:34 +0800 | [diff] [blame] | 1760 | spin_lock_bh(&tx_queue->lock); |
hayeswang | d84130a | 2014-02-18 21:49:02 +0800 | [diff] [blame] | 1761 | skb_queue_splice_init(tx_queue, &skb_head); |
hayeswang | 2685d41 | 2014-03-07 11:04:34 +0800 | [diff] [blame] | 1762 | spin_unlock_bh(&tx_queue->lock); |
hayeswang | d84130a | 2014-02-18 21:49:02 +0800 | [diff] [blame] | 1763 | |
| 1764 | while ((skb = __skb_dequeue(&skb_head))) { |
hayeswang | 00a5e36 | 2014-02-18 21:48:59 +0800 | [diff] [blame] | 1765 | dev_kfree_skb(skb); |
| 1766 | stats->tx_dropped++; |
| 1767 | } |
| 1768 | } |
| 1769 | |
hayeswang | ac718b6 | 2013-05-02 16:01:25 +0000 | [diff] [blame] | 1770 | static void rtl8152_tx_timeout(struct net_device *netdev) |
| 1771 | { |
| 1772 | struct r8152 *tp = netdev_priv(netdev); |
hayeswang | ebc2ec48 | 2013-08-14 20:54:38 +0800 | [diff] [blame] | 1773 | int i; |
| 1774 | |
Hayes Wang | 4a8deae | 2014-01-07 11:18:22 +0800 | [diff] [blame] | 1775 | netif_warn(tp, tx_err, netdev, "Tx timeout\n"); |
hayeswang | ebc2ec48 | 2013-08-14 20:54:38 +0800 | [diff] [blame] | 1776 | for (i = 0; i < RTL8152_MAX_TX; i++) |
| 1777 | usb_unlink_urb(tp->tx_info[i].urb); |
hayeswang | ac718b6 | 2013-05-02 16:01:25 +0000 | [diff] [blame] | 1778 | } |
| 1779 | |
| 1780 | static void rtl8152_set_rx_mode(struct net_device *netdev) |
| 1781 | { |
| 1782 | struct r8152 *tp = netdev_priv(netdev); |
| 1783 | |
hayeswang | 40a8291 | 2013-08-14 20:54:40 +0800 | [diff] [blame] | 1784 | if (tp->speed & LINK_STATUS) { |
hayeswang | ac718b6 | 2013-05-02 16:01:25 +0000 | [diff] [blame] | 1785 | set_bit(RTL8152_SET_RX_MODE, &tp->flags); |
hayeswang | 40a8291 | 2013-08-14 20:54:40 +0800 | [diff] [blame] | 1786 | schedule_delayed_work(&tp->schedule, 0); |
| 1787 | } |
hayeswang | ac718b6 | 2013-05-02 16:01:25 +0000 | [diff] [blame] | 1788 | } |
| 1789 | |
| 1790 | static void _rtl8152_set_rx_mode(struct net_device *netdev) |
| 1791 | { |
| 1792 | struct r8152 *tp = netdev_priv(netdev); |
hayeswang | 31787f5 | 2013-07-31 17:21:25 +0800 | [diff] [blame] | 1793 | u32 mc_filter[2]; /* Multicast hash filter */ |
| 1794 | __le32 tmp[2]; |
hayeswang | ac718b6 | 2013-05-02 16:01:25 +0000 | [diff] [blame] | 1795 | u32 ocp_data; |
| 1796 | |
hayeswang | ac718b6 | 2013-05-02 16:01:25 +0000 | [diff] [blame] | 1797 | clear_bit(RTL8152_SET_RX_MODE, &tp->flags); |
| 1798 | netif_stop_queue(netdev); |
| 1799 | ocp_data = ocp_read_dword(tp, MCU_TYPE_PLA, PLA_RCR); |
| 1800 | ocp_data &= ~RCR_ACPT_ALL; |
| 1801 | ocp_data |= RCR_AB | RCR_APM; |
| 1802 | |
| 1803 | if (netdev->flags & IFF_PROMISC) { |
| 1804 | /* Unconditionally log net taps. */ |
| 1805 | netif_notice(tp, link, netdev, "Promiscuous mode enabled\n"); |
| 1806 | ocp_data |= RCR_AM | RCR_AAP; |
| 1807 | mc_filter[1] = mc_filter[0] = 0xffffffff; |
| 1808 | } else if ((netdev_mc_count(netdev) > multicast_filter_limit) || |
| 1809 | (netdev->flags & IFF_ALLMULTI)) { |
| 1810 | /* Too many to filter perfectly -- accept all multicasts. */ |
| 1811 | ocp_data |= RCR_AM; |
| 1812 | mc_filter[1] = mc_filter[0] = 0xffffffff; |
| 1813 | } else { |
| 1814 | struct netdev_hw_addr *ha; |
| 1815 | |
| 1816 | mc_filter[1] = mc_filter[0] = 0; |
| 1817 | netdev_for_each_mc_addr(ha, netdev) { |
| 1818 | int bit_nr = ether_crc(ETH_ALEN, ha->addr) >> 26; |
| 1819 | mc_filter[bit_nr >> 5] |= 1 << (bit_nr & 31); |
| 1820 | ocp_data |= RCR_AM; |
| 1821 | } |
| 1822 | } |
| 1823 | |
hayeswang | 31787f5 | 2013-07-31 17:21:25 +0800 | [diff] [blame] | 1824 | tmp[0] = __cpu_to_le32(swab32(mc_filter[1])); |
| 1825 | tmp[1] = __cpu_to_le32(swab32(mc_filter[0])); |
hayeswang | ac718b6 | 2013-05-02 16:01:25 +0000 | [diff] [blame] | 1826 | |
hayeswang | 31787f5 | 2013-07-31 17:21:25 +0800 | [diff] [blame] | 1827 | pla_ocp_write(tp, PLA_MAR, BYTE_EN_DWORD, sizeof(tmp), tmp); |
hayeswang | ac718b6 | 2013-05-02 16:01:25 +0000 | [diff] [blame] | 1828 | ocp_write_dword(tp, MCU_TYPE_PLA, PLA_RCR, ocp_data); |
| 1829 | netif_wake_queue(netdev); |
hayeswang | ac718b6 | 2013-05-02 16:01:25 +0000 | [diff] [blame] | 1830 | } |
| 1831 | |
| 1832 | static netdev_tx_t rtl8152_start_xmit(struct sk_buff *skb, |
hayeswang | 0c3121f | 2014-03-07 11:04:36 +0800 | [diff] [blame] | 1833 | struct net_device *netdev) |
hayeswang | ac718b6 | 2013-05-02 16:01:25 +0000 | [diff] [blame] | 1834 | { |
| 1835 | struct r8152 *tp = netdev_priv(netdev); |
hayeswang | ac718b6 | 2013-05-02 16:01:25 +0000 | [diff] [blame] | 1836 | |
hayeswang | ac718b6 | 2013-05-02 16:01:25 +0000 | [diff] [blame] | 1837 | skb_tx_timestamp(skb); |
hayeswang | ebc2ec48 | 2013-08-14 20:54:38 +0800 | [diff] [blame] | 1838 | |
hayeswang | 6159878 | 2013-11-20 17:30:55 +0800 | [diff] [blame] | 1839 | skb_queue_tail(&tp->tx_queue, skb); |
hayeswang | ebc2ec48 | 2013-08-14 20:54:38 +0800 | [diff] [blame] | 1840 | |
hayeswang | 0c3121f | 2014-03-07 11:04:36 +0800 | [diff] [blame] | 1841 | if (!list_empty(&tp->tx_free)) { |
| 1842 | if (test_bit(SELECTIVE_SUSPEND, &tp->flags)) { |
| 1843 | set_bit(SCHEDULE_TASKLET, &tp->flags); |
| 1844 | schedule_delayed_work(&tp->schedule, 0); |
| 1845 | } else { |
| 1846 | usb_mark_last_busy(tp->udev); |
| 1847 | tasklet_schedule(&tp->tl); |
| 1848 | } |
| 1849 | } else if (skb_queue_len(&tp->tx_queue) > tp->tx_qlen) |
hayeswang | dd1b119 | 2013-11-20 17:30:56 +0800 | [diff] [blame] | 1850 | netif_stop_queue(netdev); |
| 1851 | |
hayeswang | ac718b6 | 2013-05-02 16:01:25 +0000 | [diff] [blame] | 1852 | return NETDEV_TX_OK; |
| 1853 | } |
| 1854 | |
| 1855 | static void r8152b_reset_packet_filter(struct r8152 *tp) |
| 1856 | { |
| 1857 | u32 ocp_data; |
| 1858 | |
| 1859 | ocp_data = ocp_read_word(tp, MCU_TYPE_PLA, PLA_FMC); |
| 1860 | ocp_data &= ~FMC_FCR_MCU_EN; |
| 1861 | ocp_write_word(tp, MCU_TYPE_PLA, PLA_FMC, ocp_data); |
| 1862 | ocp_data |= FMC_FCR_MCU_EN; |
| 1863 | ocp_write_word(tp, MCU_TYPE_PLA, PLA_FMC, ocp_data); |
| 1864 | } |
| 1865 | |
| 1866 | static void rtl8152_nic_reset(struct r8152 *tp) |
| 1867 | { |
| 1868 | int i; |
| 1869 | |
| 1870 | ocp_write_byte(tp, MCU_TYPE_PLA, PLA_CR, CR_RST); |
| 1871 | |
| 1872 | for (i = 0; i < 1000; i++) { |
| 1873 | if (!(ocp_read_byte(tp, MCU_TYPE_PLA, PLA_CR) & CR_RST)) |
| 1874 | break; |
| 1875 | udelay(100); |
| 1876 | } |
| 1877 | } |
| 1878 | |
hayeswang | dd1b119 | 2013-11-20 17:30:56 +0800 | [diff] [blame] | 1879 | static void set_tx_qlen(struct r8152 *tp) |
| 1880 | { |
| 1881 | struct net_device *netdev = tp->netdev; |
| 1882 | |
| 1883 | tp->tx_qlen = rx_buf_sz / (netdev->mtu + VLAN_ETH_HLEN + VLAN_HLEN + |
| 1884 | sizeof(struct tx_desc)); |
| 1885 | } |
| 1886 | |
hayeswang | ac718b6 | 2013-05-02 16:01:25 +0000 | [diff] [blame] | 1887 | static inline u8 rtl8152_get_speed(struct r8152 *tp) |
| 1888 | { |
| 1889 | return ocp_read_byte(tp, MCU_TYPE_PLA, PLA_PHYSTATUS); |
| 1890 | } |
| 1891 | |
hayeswang | 507605a | 2014-01-02 11:22:43 +0800 | [diff] [blame] | 1892 | static void rtl_set_eee_plus(struct r8152 *tp) |
hayeswang | ac718b6 | 2013-05-02 16:01:25 +0000 | [diff] [blame] | 1893 | { |
hayeswang | ebc2ec48 | 2013-08-14 20:54:38 +0800 | [diff] [blame] | 1894 | u32 ocp_data; |
hayeswang | ac718b6 | 2013-05-02 16:01:25 +0000 | [diff] [blame] | 1895 | u8 speed; |
| 1896 | |
| 1897 | speed = rtl8152_get_speed(tp); |
hayeswang | ebc2ec48 | 2013-08-14 20:54:38 +0800 | [diff] [blame] | 1898 | if (speed & _10bps) { |
hayeswang | ac718b6 | 2013-05-02 16:01:25 +0000 | [diff] [blame] | 1899 | ocp_data = ocp_read_word(tp, MCU_TYPE_PLA, PLA_EEEP_CR); |
hayeswang | ebc2ec48 | 2013-08-14 20:54:38 +0800 | [diff] [blame] | 1900 | ocp_data |= EEEP_CR_EEEP_TX; |
hayeswang | ac718b6 | 2013-05-02 16:01:25 +0000 | [diff] [blame] | 1901 | ocp_write_word(tp, MCU_TYPE_PLA, PLA_EEEP_CR, ocp_data); |
| 1902 | } else { |
| 1903 | ocp_data = ocp_read_word(tp, MCU_TYPE_PLA, PLA_EEEP_CR); |
hayeswang | ebc2ec48 | 2013-08-14 20:54:38 +0800 | [diff] [blame] | 1904 | ocp_data &= ~EEEP_CR_EEEP_TX; |
hayeswang | ac718b6 | 2013-05-02 16:01:25 +0000 | [diff] [blame] | 1905 | ocp_write_word(tp, MCU_TYPE_PLA, PLA_EEEP_CR, ocp_data); |
| 1906 | } |
hayeswang | 507605a | 2014-01-02 11:22:43 +0800 | [diff] [blame] | 1907 | } |
| 1908 | |
hayeswang | 00a5e36 | 2014-02-18 21:48:59 +0800 | [diff] [blame] | 1909 | static void rxdy_gated_en(struct r8152 *tp, bool enable) |
| 1910 | { |
| 1911 | u32 ocp_data; |
| 1912 | |
| 1913 | ocp_data = ocp_read_word(tp, MCU_TYPE_PLA, PLA_MISC_1); |
| 1914 | if (enable) |
| 1915 | ocp_data |= RXDY_GATED_EN; |
| 1916 | else |
| 1917 | ocp_data &= ~RXDY_GATED_EN; |
| 1918 | ocp_write_word(tp, MCU_TYPE_PLA, PLA_MISC_1, ocp_data); |
| 1919 | } |
| 1920 | |
hayeswang | 507605a | 2014-01-02 11:22:43 +0800 | [diff] [blame] | 1921 | static int rtl_enable(struct r8152 *tp) |
| 1922 | { |
| 1923 | u32 ocp_data; |
| 1924 | int i, ret; |
hayeswang | ac718b6 | 2013-05-02 16:01:25 +0000 | [diff] [blame] | 1925 | |
| 1926 | r8152b_reset_packet_filter(tp); |
| 1927 | |
| 1928 | ocp_data = ocp_read_byte(tp, MCU_TYPE_PLA, PLA_CR); |
| 1929 | ocp_data |= CR_RE | CR_TE; |
| 1930 | ocp_write_byte(tp, MCU_TYPE_PLA, PLA_CR, ocp_data); |
| 1931 | |
hayeswang | 00a5e36 | 2014-02-18 21:48:59 +0800 | [diff] [blame] | 1932 | rxdy_gated_en(tp, false); |
hayeswang | ac718b6 | 2013-05-02 16:01:25 +0000 | [diff] [blame] | 1933 | |
hayeswang | ebc2ec48 | 2013-08-14 20:54:38 +0800 | [diff] [blame] | 1934 | INIT_LIST_HEAD(&tp->rx_done); |
| 1935 | ret = 0; |
| 1936 | for (i = 0; i < RTL8152_MAX_RX; i++) { |
| 1937 | INIT_LIST_HEAD(&tp->rx_info[i].list); |
| 1938 | ret |= r8152_submit_rx(tp, &tp->rx_info[i], GFP_KERNEL); |
| 1939 | } |
hayeswang | ac718b6 | 2013-05-02 16:01:25 +0000 | [diff] [blame] | 1940 | |
hayeswang | ebc2ec48 | 2013-08-14 20:54:38 +0800 | [diff] [blame] | 1941 | return ret; |
hayeswang | ac718b6 | 2013-05-02 16:01:25 +0000 | [diff] [blame] | 1942 | } |
| 1943 | |
hayeswang | 507605a | 2014-01-02 11:22:43 +0800 | [diff] [blame] | 1944 | static int rtl8152_enable(struct r8152 *tp) |
| 1945 | { |
| 1946 | set_tx_qlen(tp); |
| 1947 | rtl_set_eee_plus(tp); |
| 1948 | |
| 1949 | return rtl_enable(tp); |
| 1950 | } |
| 1951 | |
hayeswang | 43779f8 | 2014-01-02 11:25:10 +0800 | [diff] [blame] | 1952 | static void r8153_set_rx_agg(struct r8152 *tp) |
| 1953 | { |
| 1954 | u8 speed; |
| 1955 | |
| 1956 | speed = rtl8152_get_speed(tp); |
| 1957 | if (speed & _1000bps) { |
| 1958 | if (tp->udev->speed == USB_SPEED_SUPER) { |
| 1959 | ocp_write_dword(tp, MCU_TYPE_USB, USB_RX_BUF_TH, |
| 1960 | RX_THR_SUPPER); |
| 1961 | ocp_write_dword(tp, MCU_TYPE_USB, USB_RX_EARLY_AGG, |
| 1962 | EARLY_AGG_SUPPER); |
| 1963 | } else { |
| 1964 | ocp_write_dword(tp, MCU_TYPE_USB, USB_RX_BUF_TH, |
| 1965 | RX_THR_HIGH); |
| 1966 | ocp_write_dword(tp, MCU_TYPE_USB, USB_RX_EARLY_AGG, |
| 1967 | EARLY_AGG_HIGH); |
| 1968 | } |
| 1969 | } else { |
| 1970 | ocp_write_dword(tp, MCU_TYPE_USB, USB_RX_BUF_TH, RX_THR_SLOW); |
| 1971 | ocp_write_dword(tp, MCU_TYPE_USB, USB_RX_EARLY_AGG, |
| 1972 | EARLY_AGG_SLOW); |
| 1973 | } |
| 1974 | } |
| 1975 | |
| 1976 | static int rtl8153_enable(struct r8152 *tp) |
| 1977 | { |
| 1978 | set_tx_qlen(tp); |
| 1979 | rtl_set_eee_plus(tp); |
| 1980 | r8153_set_rx_agg(tp); |
| 1981 | |
| 1982 | return rtl_enable(tp); |
| 1983 | } |
| 1984 | |
hayeswang | ac718b6 | 2013-05-02 16:01:25 +0000 | [diff] [blame] | 1985 | static void rtl8152_disable(struct r8152 *tp) |
| 1986 | { |
hayeswang | ebc2ec48 | 2013-08-14 20:54:38 +0800 | [diff] [blame] | 1987 | u32 ocp_data; |
| 1988 | int i; |
hayeswang | ac718b6 | 2013-05-02 16:01:25 +0000 | [diff] [blame] | 1989 | |
| 1990 | ocp_data = ocp_read_dword(tp, MCU_TYPE_PLA, PLA_RCR); |
| 1991 | ocp_data &= ~RCR_ACPT_ALL; |
| 1992 | ocp_write_dword(tp, MCU_TYPE_PLA, PLA_RCR, ocp_data); |
| 1993 | |
hayeswang | 00a5e36 | 2014-02-18 21:48:59 +0800 | [diff] [blame] | 1994 | rtl_drop_queued_tx(tp); |
hayeswang | ebc2ec48 | 2013-08-14 20:54:38 +0800 | [diff] [blame] | 1995 | |
| 1996 | for (i = 0; i < RTL8152_MAX_TX; i++) |
| 1997 | usb_kill_urb(tp->tx_info[i].urb); |
hayeswang | ac718b6 | 2013-05-02 16:01:25 +0000 | [diff] [blame] | 1998 | |
hayeswang | 00a5e36 | 2014-02-18 21:48:59 +0800 | [diff] [blame] | 1999 | rxdy_gated_en(tp, true); |
hayeswang | ac718b6 | 2013-05-02 16:01:25 +0000 | [diff] [blame] | 2000 | |
| 2001 | for (i = 0; i < 1000; i++) { |
| 2002 | ocp_data = ocp_read_byte(tp, MCU_TYPE_PLA, PLA_OOB_CTRL); |
| 2003 | if ((ocp_data & FIFO_EMPTY) == FIFO_EMPTY) |
| 2004 | break; |
| 2005 | mdelay(1); |
| 2006 | } |
| 2007 | |
| 2008 | for (i = 0; i < 1000; i++) { |
| 2009 | if (ocp_read_word(tp, MCU_TYPE_PLA, PLA_TCR0) & TCR0_TX_EMPTY) |
| 2010 | break; |
| 2011 | mdelay(1); |
| 2012 | } |
| 2013 | |
hayeswang | ebc2ec48 | 2013-08-14 20:54:38 +0800 | [diff] [blame] | 2014 | for (i = 0; i < RTL8152_MAX_RX; i++) |
| 2015 | usb_kill_urb(tp->rx_info[i].urb); |
hayeswang | ac718b6 | 2013-05-02 16:01:25 +0000 | [diff] [blame] | 2016 | |
| 2017 | rtl8152_nic_reset(tp); |
| 2018 | } |
| 2019 | |
hayeswang | 00a5e36 | 2014-02-18 21:48:59 +0800 | [diff] [blame] | 2020 | static void r8152_power_cut_en(struct r8152 *tp, bool enable) |
| 2021 | { |
| 2022 | u32 ocp_data; |
| 2023 | |
| 2024 | ocp_data = ocp_read_word(tp, MCU_TYPE_USB, USB_UPS_CTRL); |
| 2025 | if (enable) |
| 2026 | ocp_data |= POWER_CUT; |
| 2027 | else |
| 2028 | ocp_data &= ~POWER_CUT; |
| 2029 | ocp_write_word(tp, MCU_TYPE_USB, USB_UPS_CTRL, ocp_data); |
| 2030 | |
| 2031 | ocp_data = ocp_read_word(tp, MCU_TYPE_USB, USB_PM_CTRL_STATUS); |
| 2032 | ocp_data &= ~RESUME_INDICATE; |
| 2033 | ocp_write_word(tp, MCU_TYPE_USB, USB_PM_CTRL_STATUS, ocp_data); |
hayeswang | 00a5e36 | 2014-02-18 21:48:59 +0800 | [diff] [blame] | 2034 | } |
| 2035 | |
hayeswang | 21ff2e8 | 2014-02-18 21:49:06 +0800 | [diff] [blame] | 2036 | #define WAKE_ANY (WAKE_PHY | WAKE_MAGIC | WAKE_UCAST | WAKE_BCAST | WAKE_MCAST) |
| 2037 | |
| 2038 | static u32 __rtl_get_wol(struct r8152 *tp) |
| 2039 | { |
| 2040 | u32 ocp_data; |
| 2041 | u32 wolopts = 0; |
| 2042 | |
| 2043 | ocp_data = ocp_read_byte(tp, MCU_TYPE_PLA, PLA_CONFIG5); |
| 2044 | if (!(ocp_data & LAN_WAKE_EN)) |
| 2045 | return 0; |
| 2046 | |
| 2047 | ocp_data = ocp_read_word(tp, MCU_TYPE_PLA, PLA_CONFIG34); |
| 2048 | if (ocp_data & LINK_ON_WAKE_EN) |
| 2049 | wolopts |= WAKE_PHY; |
| 2050 | |
| 2051 | ocp_data = ocp_read_word(tp, MCU_TYPE_PLA, PLA_CONFIG5); |
| 2052 | if (ocp_data & UWF_EN) |
| 2053 | wolopts |= WAKE_UCAST; |
| 2054 | if (ocp_data & BWF_EN) |
| 2055 | wolopts |= WAKE_BCAST; |
| 2056 | if (ocp_data & MWF_EN) |
| 2057 | wolopts |= WAKE_MCAST; |
| 2058 | |
| 2059 | ocp_data = ocp_read_word(tp, MCU_TYPE_PLA, PLA_CFG_WOL); |
| 2060 | if (ocp_data & MAGIC_EN) |
| 2061 | wolopts |= WAKE_MAGIC; |
| 2062 | |
| 2063 | return wolopts; |
| 2064 | } |
| 2065 | |
| 2066 | static void __rtl_set_wol(struct r8152 *tp, u32 wolopts) |
| 2067 | { |
| 2068 | u32 ocp_data; |
| 2069 | |
| 2070 | ocp_write_byte(tp, MCU_TYPE_PLA, PLA_CRWECR, CRWECR_CONFIG); |
| 2071 | |
| 2072 | ocp_data = ocp_read_word(tp, MCU_TYPE_PLA, PLA_CONFIG34); |
| 2073 | ocp_data &= ~LINK_ON_WAKE_EN; |
| 2074 | if (wolopts & WAKE_PHY) |
| 2075 | ocp_data |= LINK_ON_WAKE_EN; |
| 2076 | ocp_write_word(tp, MCU_TYPE_PLA, PLA_CONFIG34, ocp_data); |
| 2077 | |
| 2078 | ocp_data = ocp_read_word(tp, MCU_TYPE_PLA, PLA_CONFIG5); |
| 2079 | ocp_data &= ~(UWF_EN | BWF_EN | MWF_EN | LAN_WAKE_EN); |
| 2080 | if (wolopts & WAKE_UCAST) |
| 2081 | ocp_data |= UWF_EN; |
| 2082 | if (wolopts & WAKE_BCAST) |
| 2083 | ocp_data |= BWF_EN; |
| 2084 | if (wolopts & WAKE_MCAST) |
| 2085 | ocp_data |= MWF_EN; |
| 2086 | if (wolopts & WAKE_ANY) |
| 2087 | ocp_data |= LAN_WAKE_EN; |
| 2088 | ocp_write_word(tp, MCU_TYPE_PLA, PLA_CONFIG5, ocp_data); |
| 2089 | |
| 2090 | ocp_write_byte(tp, MCU_TYPE_PLA, PLA_CRWECR, CRWECR_NORAML); |
| 2091 | |
| 2092 | ocp_data = ocp_read_word(tp, MCU_TYPE_PLA, PLA_CFG_WOL); |
| 2093 | ocp_data &= ~MAGIC_EN; |
| 2094 | if (wolopts & WAKE_MAGIC) |
| 2095 | ocp_data |= MAGIC_EN; |
| 2096 | ocp_write_word(tp, MCU_TYPE_PLA, PLA_CFG_WOL, ocp_data); |
| 2097 | |
| 2098 | if (wolopts & WAKE_ANY) |
| 2099 | device_set_wakeup_enable(&tp->udev->dev, true); |
| 2100 | else |
| 2101 | device_set_wakeup_enable(&tp->udev->dev, false); |
| 2102 | } |
| 2103 | |
hayeswang | 9a4be1b | 2014-02-18 21:49:07 +0800 | [diff] [blame] | 2104 | static void rtl_runtime_suspend_enable(struct r8152 *tp, bool enable) |
| 2105 | { |
| 2106 | if (enable) { |
| 2107 | u32 ocp_data; |
| 2108 | |
| 2109 | __rtl_set_wol(tp, WAKE_ANY); |
| 2110 | |
| 2111 | ocp_write_byte(tp, MCU_TYPE_PLA, PLA_CRWECR, CRWECR_CONFIG); |
| 2112 | |
| 2113 | ocp_data = ocp_read_word(tp, MCU_TYPE_PLA, PLA_CONFIG34); |
| 2114 | ocp_data |= LINK_OFF_WAKE_EN; |
| 2115 | ocp_write_word(tp, MCU_TYPE_PLA, PLA_CONFIG34, ocp_data); |
| 2116 | |
| 2117 | ocp_write_byte(tp, MCU_TYPE_PLA, PLA_CRWECR, CRWECR_NORAML); |
| 2118 | } else { |
| 2119 | __rtl_set_wol(tp, tp->saved_wolopts); |
| 2120 | } |
| 2121 | } |
| 2122 | |
hayeswang | aa66a5f | 2014-02-18 21:49:04 +0800 | [diff] [blame] | 2123 | static void rtl_phy_reset(struct r8152 *tp) |
| 2124 | { |
| 2125 | u16 data; |
| 2126 | int i; |
| 2127 | |
| 2128 | clear_bit(PHY_RESET, &tp->flags); |
| 2129 | |
| 2130 | data = r8152_mdio_read(tp, MII_BMCR); |
| 2131 | |
| 2132 | /* don't reset again before the previous one complete */ |
| 2133 | if (data & BMCR_RESET) |
| 2134 | return; |
| 2135 | |
| 2136 | data |= BMCR_RESET; |
| 2137 | r8152_mdio_write(tp, MII_BMCR, data); |
| 2138 | |
| 2139 | for (i = 0; i < 50; i++) { |
| 2140 | msleep(20); |
| 2141 | if ((r8152_mdio_read(tp, MII_BMCR) & BMCR_RESET) == 0) |
| 2142 | break; |
| 2143 | } |
| 2144 | } |
| 2145 | |
hayeswang | 4349968 | 2014-02-18 21:48:58 +0800 | [diff] [blame] | 2146 | static void rtl_clear_bp(struct r8152 *tp) |
| 2147 | { |
| 2148 | ocp_write_dword(tp, MCU_TYPE_PLA, PLA_BP_0, 0); |
| 2149 | ocp_write_dword(tp, MCU_TYPE_PLA, PLA_BP_2, 0); |
| 2150 | ocp_write_dword(tp, MCU_TYPE_PLA, PLA_BP_4, 0); |
| 2151 | ocp_write_dword(tp, MCU_TYPE_PLA, PLA_BP_6, 0); |
| 2152 | ocp_write_dword(tp, MCU_TYPE_USB, USB_BP_0, 0); |
| 2153 | ocp_write_dword(tp, MCU_TYPE_USB, USB_BP_2, 0); |
| 2154 | ocp_write_dword(tp, MCU_TYPE_USB, USB_BP_4, 0); |
| 2155 | ocp_write_dword(tp, MCU_TYPE_USB, USB_BP_6, 0); |
| 2156 | mdelay(3); |
| 2157 | ocp_write_word(tp, MCU_TYPE_PLA, PLA_BP_BA, 0); |
| 2158 | ocp_write_word(tp, MCU_TYPE_USB, USB_BP_BA, 0); |
| 2159 | } |
| 2160 | |
| 2161 | static void r8153_clear_bp(struct r8152 *tp) |
| 2162 | { |
| 2163 | ocp_write_byte(tp, MCU_TYPE_PLA, PLA_BP_EN, 0); |
| 2164 | ocp_write_byte(tp, MCU_TYPE_USB, USB_BP_EN, 0); |
| 2165 | rtl_clear_bp(tp); |
| 2166 | } |
| 2167 | |
| 2168 | static void r8153_teredo_off(struct r8152 *tp) |
| 2169 | { |
| 2170 | u32 ocp_data; |
| 2171 | |
| 2172 | ocp_data = ocp_read_word(tp, MCU_TYPE_PLA, PLA_TEREDO_CFG); |
| 2173 | ocp_data &= ~(TEREDO_SEL | TEREDO_RS_EVENT_MASK | OOB_TEREDO_EN); |
| 2174 | ocp_write_word(tp, MCU_TYPE_PLA, PLA_TEREDO_CFG, ocp_data); |
| 2175 | |
| 2176 | ocp_write_word(tp, MCU_TYPE_PLA, PLA_WDT6_CTRL, WDT6_SET_MODE); |
| 2177 | ocp_write_word(tp, MCU_TYPE_PLA, PLA_REALWOW_TIMER, 0); |
| 2178 | ocp_write_dword(tp, MCU_TYPE_PLA, PLA_TEREDO_TIMER, 0); |
| 2179 | } |
| 2180 | |
| 2181 | static void r8152b_disable_aldps(struct r8152 *tp) |
| 2182 | { |
| 2183 | ocp_reg_write(tp, OCP_ALDPS_CONFIG, ENPDNPS | LINKENA | DIS_SDSAVE); |
| 2184 | msleep(20); |
| 2185 | } |
| 2186 | |
| 2187 | static inline void r8152b_enable_aldps(struct r8152 *tp) |
| 2188 | { |
| 2189 | ocp_reg_write(tp, OCP_ALDPS_CONFIG, ENPWRSAVE | ENPDNPS | |
| 2190 | LINKENA | DIS_SDSAVE); |
| 2191 | } |
| 2192 | |
| 2193 | static void r8152b_hw_phy_cfg(struct r8152 *tp) |
| 2194 | { |
hayeswang | f0cbe0a | 2014-02-18 21:49:03 +0800 | [diff] [blame] | 2195 | u16 data; |
| 2196 | |
| 2197 | data = r8152_mdio_read(tp, MII_BMCR); |
| 2198 | if (data & BMCR_PDOWN) { |
| 2199 | data &= ~BMCR_PDOWN; |
| 2200 | r8152_mdio_write(tp, MII_BMCR, data); |
| 2201 | } |
| 2202 | |
hayeswang | 4349968 | 2014-02-18 21:48:58 +0800 | [diff] [blame] | 2203 | r8152b_disable_aldps(tp); |
hayeswang | 7e9da48 | 2014-02-18 21:49:05 +0800 | [diff] [blame] | 2204 | |
| 2205 | rtl_clear_bp(tp); |
| 2206 | |
| 2207 | r8152b_enable_aldps(tp); |
hayeswang | aa66a5f | 2014-02-18 21:49:04 +0800 | [diff] [blame] | 2208 | set_bit(PHY_RESET, &tp->flags); |
hayeswang | 4349968 | 2014-02-18 21:48:58 +0800 | [diff] [blame] | 2209 | } |
| 2210 | |
hayeswang | ac718b6 | 2013-05-02 16:01:25 +0000 | [diff] [blame] | 2211 | static void r8152b_exit_oob(struct r8152 *tp) |
| 2212 | { |
hayeswang | db8515e | 2014-03-06 15:07:16 +0800 | [diff] [blame] | 2213 | u32 ocp_data; |
| 2214 | int i; |
hayeswang | ac718b6 | 2013-05-02 16:01:25 +0000 | [diff] [blame] | 2215 | |
| 2216 | ocp_data = ocp_read_dword(tp, MCU_TYPE_PLA, PLA_RCR); |
| 2217 | ocp_data &= ~RCR_ACPT_ALL; |
| 2218 | ocp_write_dword(tp, MCU_TYPE_PLA, PLA_RCR, ocp_data); |
| 2219 | |
hayeswang | 00a5e36 | 2014-02-18 21:48:59 +0800 | [diff] [blame] | 2220 | rxdy_gated_en(tp, true); |
hayeswang | da9bd11 | 2014-02-18 21:49:08 +0800 | [diff] [blame] | 2221 | r8153_teredo_off(tp); |
hayeswang | 7e9da48 | 2014-02-18 21:49:05 +0800 | [diff] [blame] | 2222 | r8152b_hw_phy_cfg(tp); |
hayeswang | ac718b6 | 2013-05-02 16:01:25 +0000 | [diff] [blame] | 2223 | |
| 2224 | ocp_write_byte(tp, MCU_TYPE_PLA, PLA_CRWECR, CRWECR_NORAML); |
| 2225 | ocp_write_byte(tp, MCU_TYPE_PLA, PLA_CR, 0x00); |
| 2226 | |
| 2227 | ocp_data = ocp_read_byte(tp, MCU_TYPE_PLA, PLA_OOB_CTRL); |
| 2228 | ocp_data &= ~NOW_IS_OOB; |
| 2229 | ocp_write_byte(tp, MCU_TYPE_PLA, PLA_OOB_CTRL, ocp_data); |
| 2230 | |
| 2231 | ocp_data = ocp_read_word(tp, MCU_TYPE_PLA, PLA_SFF_STS_7); |
| 2232 | ocp_data &= ~MCU_BORW_EN; |
| 2233 | ocp_write_word(tp, MCU_TYPE_PLA, PLA_SFF_STS_7, ocp_data); |
| 2234 | |
| 2235 | for (i = 0; i < 1000; i++) { |
| 2236 | ocp_data = ocp_read_byte(tp, MCU_TYPE_PLA, PLA_OOB_CTRL); |
| 2237 | if (ocp_data & LINK_LIST_READY) |
| 2238 | break; |
| 2239 | mdelay(1); |
| 2240 | } |
| 2241 | |
| 2242 | ocp_data = ocp_read_word(tp, MCU_TYPE_PLA, PLA_SFF_STS_7); |
| 2243 | ocp_data |= RE_INIT_LL; |
| 2244 | ocp_write_word(tp, MCU_TYPE_PLA, PLA_SFF_STS_7, ocp_data); |
| 2245 | |
| 2246 | for (i = 0; i < 1000; i++) { |
| 2247 | ocp_data = ocp_read_byte(tp, MCU_TYPE_PLA, PLA_OOB_CTRL); |
| 2248 | if (ocp_data & LINK_LIST_READY) |
| 2249 | break; |
| 2250 | mdelay(1); |
| 2251 | } |
| 2252 | |
| 2253 | rtl8152_nic_reset(tp); |
| 2254 | |
| 2255 | /* rx share fifo credit full threshold */ |
| 2256 | ocp_write_dword(tp, MCU_TYPE_PLA, PLA_RXFIFO_CTRL0, RXFIFO_THR1_NORMAL); |
| 2257 | |
| 2258 | ocp_data = ocp_read_word(tp, MCU_TYPE_USB, USB_DEV_STAT); |
| 2259 | ocp_data &= STAT_SPEED_MASK; |
| 2260 | if (ocp_data == STAT_SPEED_FULL) { |
| 2261 | /* rx share fifo credit near full threshold */ |
| 2262 | ocp_write_dword(tp, MCU_TYPE_PLA, PLA_RXFIFO_CTRL1, |
| 2263 | RXFIFO_THR2_FULL); |
| 2264 | ocp_write_dword(tp, MCU_TYPE_PLA, PLA_RXFIFO_CTRL2, |
| 2265 | RXFIFO_THR3_FULL); |
| 2266 | } else { |
| 2267 | /* rx share fifo credit near full threshold */ |
| 2268 | ocp_write_dword(tp, MCU_TYPE_PLA, PLA_RXFIFO_CTRL1, |
| 2269 | RXFIFO_THR2_HIGH); |
| 2270 | ocp_write_dword(tp, MCU_TYPE_PLA, PLA_RXFIFO_CTRL2, |
| 2271 | RXFIFO_THR3_HIGH); |
| 2272 | } |
| 2273 | |
| 2274 | /* TX share fifo free credit full threshold */ |
| 2275 | ocp_write_dword(tp, MCU_TYPE_PLA, PLA_TXFIFO_CTRL, TXFIFO_THR_NORMAL); |
| 2276 | |
| 2277 | ocp_write_byte(tp, MCU_TYPE_USB, USB_TX_AGG, TX_AGG_MAX_THRESHOLD); |
hayeswang | 8e1f51b | 2014-01-02 11:22:41 +0800 | [diff] [blame] | 2278 | ocp_write_dword(tp, MCU_TYPE_USB, USB_RX_BUF_TH, RX_THR_HIGH); |
hayeswang | ac718b6 | 2013-05-02 16:01:25 +0000 | [diff] [blame] | 2279 | ocp_write_dword(tp, MCU_TYPE_USB, USB_TX_DMA, |
| 2280 | TEST_MODE_DISABLE | TX_SIZE_ADJUST1); |
| 2281 | |
| 2282 | ocp_data = ocp_read_word(tp, MCU_TYPE_PLA, PLA_CPCR); |
| 2283 | ocp_data &= ~CPCR_RX_VLAN; |
| 2284 | ocp_write_word(tp, MCU_TYPE_PLA, PLA_CPCR, ocp_data); |
| 2285 | |
| 2286 | ocp_write_word(tp, MCU_TYPE_PLA, PLA_RMS, RTL8152_RMS); |
| 2287 | |
| 2288 | ocp_data = ocp_read_word(tp, MCU_TYPE_PLA, PLA_TCR0); |
| 2289 | ocp_data |= TCR0_AUTO_FIFO; |
| 2290 | ocp_write_word(tp, MCU_TYPE_PLA, PLA_TCR0, ocp_data); |
| 2291 | } |
| 2292 | |
| 2293 | static void r8152b_enter_oob(struct r8152 *tp) |
| 2294 | { |
hayeswang | 45f4a19 | 2014-01-06 17:08:41 +0800 | [diff] [blame] | 2295 | u32 ocp_data; |
| 2296 | int i; |
hayeswang | ac718b6 | 2013-05-02 16:01:25 +0000 | [diff] [blame] | 2297 | |
| 2298 | ocp_data = ocp_read_byte(tp, MCU_TYPE_PLA, PLA_OOB_CTRL); |
| 2299 | ocp_data &= ~NOW_IS_OOB; |
| 2300 | ocp_write_byte(tp, MCU_TYPE_PLA, PLA_OOB_CTRL, ocp_data); |
| 2301 | |
| 2302 | ocp_write_dword(tp, MCU_TYPE_PLA, PLA_RXFIFO_CTRL0, RXFIFO_THR1_OOB); |
| 2303 | ocp_write_dword(tp, MCU_TYPE_PLA, PLA_RXFIFO_CTRL1, RXFIFO_THR2_OOB); |
| 2304 | ocp_write_dword(tp, MCU_TYPE_PLA, PLA_RXFIFO_CTRL2, RXFIFO_THR3_OOB); |
| 2305 | |
| 2306 | rtl8152_disable(tp); |
| 2307 | |
| 2308 | for (i = 0; i < 1000; i++) { |
| 2309 | ocp_data = ocp_read_byte(tp, MCU_TYPE_PLA, PLA_OOB_CTRL); |
| 2310 | if (ocp_data & LINK_LIST_READY) |
| 2311 | break; |
| 2312 | mdelay(1); |
| 2313 | } |
| 2314 | |
| 2315 | ocp_data = ocp_read_word(tp, MCU_TYPE_PLA, PLA_SFF_STS_7); |
| 2316 | ocp_data |= RE_INIT_LL; |
| 2317 | ocp_write_word(tp, MCU_TYPE_PLA, PLA_SFF_STS_7, ocp_data); |
| 2318 | |
| 2319 | for (i = 0; i < 1000; i++) { |
| 2320 | ocp_data = ocp_read_byte(tp, MCU_TYPE_PLA, PLA_OOB_CTRL); |
| 2321 | if (ocp_data & LINK_LIST_READY) |
| 2322 | break; |
| 2323 | mdelay(1); |
| 2324 | } |
| 2325 | |
| 2326 | ocp_write_word(tp, MCU_TYPE_PLA, PLA_RMS, RTL8152_RMS); |
| 2327 | |
hayeswang | ac718b6 | 2013-05-02 16:01:25 +0000 | [diff] [blame] | 2328 | ocp_data = ocp_read_word(tp, MCU_TYPE_PLA, PLA_CPCR); |
| 2329 | ocp_data |= CPCR_RX_VLAN; |
| 2330 | ocp_write_word(tp, MCU_TYPE_PLA, PLA_CPCR, ocp_data); |
| 2331 | |
| 2332 | ocp_data = ocp_read_word(tp, MCU_TYPE_PLA, PAL_BDC_CR); |
| 2333 | ocp_data |= ALDPS_PROXY_MODE; |
| 2334 | ocp_write_word(tp, MCU_TYPE_PLA, PAL_BDC_CR, ocp_data); |
| 2335 | |
| 2336 | ocp_data = ocp_read_byte(tp, MCU_TYPE_PLA, PLA_OOB_CTRL); |
| 2337 | ocp_data |= NOW_IS_OOB | DIS_MCU_CLROOB; |
| 2338 | ocp_write_byte(tp, MCU_TYPE_PLA, PLA_OOB_CTRL, ocp_data); |
| 2339 | |
hayeswang | 00a5e36 | 2014-02-18 21:48:59 +0800 | [diff] [blame] | 2340 | rxdy_gated_en(tp, false); |
hayeswang | ac718b6 | 2013-05-02 16:01:25 +0000 | [diff] [blame] | 2341 | |
| 2342 | ocp_data = ocp_read_dword(tp, MCU_TYPE_PLA, PLA_RCR); |
| 2343 | ocp_data |= RCR_APM | RCR_AM | RCR_AB; |
| 2344 | ocp_write_dword(tp, MCU_TYPE_PLA, PLA_RCR, ocp_data); |
| 2345 | } |
| 2346 | |
hayeswang | 43779f8 | 2014-01-02 11:25:10 +0800 | [diff] [blame] | 2347 | static void r8153_hw_phy_cfg(struct r8152 *tp) |
| 2348 | { |
| 2349 | u32 ocp_data; |
| 2350 | u16 data; |
| 2351 | |
| 2352 | ocp_reg_write(tp, OCP_ADC_CFG, CKADSEL_L | ADC_EN | EN_EMI_L); |
hayeswang | f0cbe0a | 2014-02-18 21:49:03 +0800 | [diff] [blame] | 2353 | data = r8152_mdio_read(tp, MII_BMCR); |
| 2354 | if (data & BMCR_PDOWN) { |
| 2355 | data &= ~BMCR_PDOWN; |
| 2356 | r8152_mdio_write(tp, MII_BMCR, data); |
| 2357 | } |
hayeswang | 43779f8 | 2014-01-02 11:25:10 +0800 | [diff] [blame] | 2358 | |
hayeswang | 7e9da48 | 2014-02-18 21:49:05 +0800 | [diff] [blame] | 2359 | r8153_clear_bp(tp); |
| 2360 | |
hayeswang | 43779f8 | 2014-01-02 11:25:10 +0800 | [diff] [blame] | 2361 | if (tp->version == RTL_VER_03) { |
| 2362 | data = ocp_reg_read(tp, OCP_EEE_CFG); |
| 2363 | data &= ~CTAP_SHORT_EN; |
| 2364 | ocp_reg_write(tp, OCP_EEE_CFG, data); |
| 2365 | } |
| 2366 | |
| 2367 | data = ocp_reg_read(tp, OCP_POWER_CFG); |
| 2368 | data |= EEE_CLKDIV_EN; |
| 2369 | ocp_reg_write(tp, OCP_POWER_CFG, data); |
| 2370 | |
| 2371 | data = ocp_reg_read(tp, OCP_DOWN_SPEED); |
| 2372 | data |= EN_10M_BGOFF; |
| 2373 | ocp_reg_write(tp, OCP_DOWN_SPEED, data); |
| 2374 | data = ocp_reg_read(tp, OCP_POWER_CFG); |
| 2375 | data |= EN_10M_PLLOFF; |
| 2376 | ocp_reg_write(tp, OCP_POWER_CFG, data); |
| 2377 | data = sram_read(tp, SRAM_IMPEDANCE); |
| 2378 | data &= ~RX_DRIVING_MASK; |
| 2379 | sram_write(tp, SRAM_IMPEDANCE, data); |
| 2380 | |
| 2381 | ocp_data = ocp_read_word(tp, MCU_TYPE_PLA, PLA_PHY_PWR); |
| 2382 | ocp_data |= PFM_PWM_SWITCH; |
| 2383 | ocp_write_word(tp, MCU_TYPE_PLA, PLA_PHY_PWR, ocp_data); |
| 2384 | |
| 2385 | data = sram_read(tp, SRAM_LPF_CFG); |
| 2386 | data |= LPF_AUTO_TUNE; |
| 2387 | sram_write(tp, SRAM_LPF_CFG, data); |
| 2388 | |
| 2389 | data = sram_read(tp, SRAM_10M_AMP1); |
| 2390 | data |= GDAC_IB_UPALL; |
| 2391 | sram_write(tp, SRAM_10M_AMP1, data); |
| 2392 | data = sram_read(tp, SRAM_10M_AMP2); |
| 2393 | data |= AMP_DN; |
| 2394 | sram_write(tp, SRAM_10M_AMP2, data); |
hayeswang | aa66a5f | 2014-02-18 21:49:04 +0800 | [diff] [blame] | 2395 | |
| 2396 | set_bit(PHY_RESET, &tp->flags); |
hayeswang | 43779f8 | 2014-01-02 11:25:10 +0800 | [diff] [blame] | 2397 | } |
| 2398 | |
hayeswang | b970272 | 2014-02-18 21:49:00 +0800 | [diff] [blame] | 2399 | static void r8153_u1u2en(struct r8152 *tp, bool enable) |
hayeswang | 43779f8 | 2014-01-02 11:25:10 +0800 | [diff] [blame] | 2400 | { |
| 2401 | u8 u1u2[8]; |
| 2402 | |
| 2403 | if (enable) |
| 2404 | memset(u1u2, 0xff, sizeof(u1u2)); |
| 2405 | else |
| 2406 | memset(u1u2, 0x00, sizeof(u1u2)); |
| 2407 | |
| 2408 | usb_ocp_write(tp, USB_TOLERANCE, BYTE_EN_SIX_BYTES, sizeof(u1u2), u1u2); |
| 2409 | } |
| 2410 | |
hayeswang | b970272 | 2014-02-18 21:49:00 +0800 | [diff] [blame] | 2411 | static void r8153_u2p3en(struct r8152 *tp, bool enable) |
hayeswang | 43779f8 | 2014-01-02 11:25:10 +0800 | [diff] [blame] | 2412 | { |
| 2413 | u32 ocp_data; |
| 2414 | |
| 2415 | ocp_data = ocp_read_word(tp, MCU_TYPE_USB, USB_U2P3_CTRL); |
| 2416 | if (enable) |
| 2417 | ocp_data |= U2P3_ENABLE; |
| 2418 | else |
| 2419 | ocp_data &= ~U2P3_ENABLE; |
| 2420 | ocp_write_word(tp, MCU_TYPE_USB, USB_U2P3_CTRL, ocp_data); |
| 2421 | } |
| 2422 | |
hayeswang | b970272 | 2014-02-18 21:49:00 +0800 | [diff] [blame] | 2423 | static void r8153_power_cut_en(struct r8152 *tp, bool enable) |
hayeswang | 43779f8 | 2014-01-02 11:25:10 +0800 | [diff] [blame] | 2424 | { |
| 2425 | u32 ocp_data; |
| 2426 | |
| 2427 | ocp_data = ocp_read_word(tp, MCU_TYPE_USB, USB_POWER_CUT); |
| 2428 | if (enable) |
| 2429 | ocp_data |= PWR_EN | PHASE2_EN; |
| 2430 | else |
| 2431 | ocp_data &= ~(PWR_EN | PHASE2_EN); |
| 2432 | ocp_write_word(tp, MCU_TYPE_USB, USB_POWER_CUT, ocp_data); |
| 2433 | |
| 2434 | ocp_data = ocp_read_word(tp, MCU_TYPE_USB, USB_MISC_0); |
| 2435 | ocp_data &= ~PCUT_STATUS; |
| 2436 | ocp_write_word(tp, MCU_TYPE_USB, USB_MISC_0, ocp_data); |
| 2437 | } |
| 2438 | |
hayeswang | 43779f8 | 2014-01-02 11:25:10 +0800 | [diff] [blame] | 2439 | static void r8153_first_init(struct r8152 *tp) |
| 2440 | { |
| 2441 | u32 ocp_data; |
| 2442 | int i; |
| 2443 | |
hayeswang | 00a5e36 | 2014-02-18 21:48:59 +0800 | [diff] [blame] | 2444 | rxdy_gated_en(tp, true); |
hayeswang | 43779f8 | 2014-01-02 11:25:10 +0800 | [diff] [blame] | 2445 | r8153_teredo_off(tp); |
| 2446 | |
| 2447 | ocp_data = ocp_read_dword(tp, MCU_TYPE_PLA, PLA_RCR); |
| 2448 | ocp_data &= ~RCR_ACPT_ALL; |
| 2449 | ocp_write_dword(tp, MCU_TYPE_PLA, PLA_RCR, ocp_data); |
| 2450 | |
| 2451 | r8153_hw_phy_cfg(tp); |
| 2452 | |
| 2453 | rtl8152_nic_reset(tp); |
| 2454 | |
| 2455 | ocp_data = ocp_read_byte(tp, MCU_TYPE_PLA, PLA_OOB_CTRL); |
| 2456 | ocp_data &= ~NOW_IS_OOB; |
| 2457 | ocp_write_byte(tp, MCU_TYPE_PLA, PLA_OOB_CTRL, ocp_data); |
| 2458 | |
| 2459 | ocp_data = ocp_read_word(tp, MCU_TYPE_PLA, PLA_SFF_STS_7); |
| 2460 | ocp_data &= ~MCU_BORW_EN; |
| 2461 | ocp_write_word(tp, MCU_TYPE_PLA, PLA_SFF_STS_7, ocp_data); |
| 2462 | |
| 2463 | for (i = 0; i < 1000; i++) { |
| 2464 | ocp_data = ocp_read_byte(tp, MCU_TYPE_PLA, PLA_OOB_CTRL); |
| 2465 | if (ocp_data & LINK_LIST_READY) |
| 2466 | break; |
| 2467 | mdelay(1); |
| 2468 | } |
| 2469 | |
| 2470 | ocp_data = ocp_read_word(tp, MCU_TYPE_PLA, PLA_SFF_STS_7); |
| 2471 | ocp_data |= RE_INIT_LL; |
| 2472 | ocp_write_word(tp, MCU_TYPE_PLA, PLA_SFF_STS_7, ocp_data); |
| 2473 | |
| 2474 | for (i = 0; i < 1000; i++) { |
| 2475 | ocp_data = ocp_read_byte(tp, MCU_TYPE_PLA, PLA_OOB_CTRL); |
| 2476 | if (ocp_data & LINK_LIST_READY) |
| 2477 | break; |
| 2478 | mdelay(1); |
| 2479 | } |
| 2480 | |
| 2481 | ocp_data = ocp_read_word(tp, MCU_TYPE_PLA, PLA_CPCR); |
| 2482 | ocp_data &= ~CPCR_RX_VLAN; |
| 2483 | ocp_write_word(tp, MCU_TYPE_PLA, PLA_CPCR, ocp_data); |
| 2484 | |
| 2485 | ocp_write_word(tp, MCU_TYPE_PLA, PLA_RMS, RTL8152_RMS); |
| 2486 | |
| 2487 | ocp_data = ocp_read_word(tp, MCU_TYPE_PLA, PLA_TCR0); |
| 2488 | ocp_data |= TCR0_AUTO_FIFO; |
| 2489 | ocp_write_word(tp, MCU_TYPE_PLA, PLA_TCR0, ocp_data); |
| 2490 | |
| 2491 | rtl8152_nic_reset(tp); |
| 2492 | |
| 2493 | /* rx share fifo credit full threshold */ |
| 2494 | ocp_write_dword(tp, MCU_TYPE_PLA, PLA_RXFIFO_CTRL0, RXFIFO_THR1_NORMAL); |
| 2495 | ocp_write_word(tp, MCU_TYPE_PLA, PLA_RXFIFO_CTRL1, RXFIFO_THR2_NORMAL); |
| 2496 | ocp_write_word(tp, MCU_TYPE_PLA, PLA_RXFIFO_CTRL2, RXFIFO_THR3_NORMAL); |
| 2497 | /* TX share fifo free credit full threshold */ |
| 2498 | ocp_write_dword(tp, MCU_TYPE_PLA, PLA_TXFIFO_CTRL, TXFIFO_THR_NORMAL2); |
| 2499 | |
hayeswang | 9629e3c | 2014-01-15 10:42:15 +0800 | [diff] [blame] | 2500 | /* rx aggregation */ |
hayeswang | 43779f8 | 2014-01-02 11:25:10 +0800 | [diff] [blame] | 2501 | ocp_data = ocp_read_word(tp, MCU_TYPE_USB, USB_USB_CTRL); |
| 2502 | ocp_data &= ~RX_AGG_DISABLE; |
| 2503 | ocp_write_word(tp, MCU_TYPE_USB, USB_USB_CTRL, ocp_data); |
| 2504 | } |
| 2505 | |
| 2506 | static void r8153_enter_oob(struct r8152 *tp) |
| 2507 | { |
| 2508 | u32 ocp_data; |
| 2509 | int i; |
| 2510 | |
| 2511 | ocp_data = ocp_read_byte(tp, MCU_TYPE_PLA, PLA_OOB_CTRL); |
| 2512 | ocp_data &= ~NOW_IS_OOB; |
| 2513 | ocp_write_byte(tp, MCU_TYPE_PLA, PLA_OOB_CTRL, ocp_data); |
| 2514 | |
| 2515 | rtl8152_disable(tp); |
| 2516 | |
| 2517 | for (i = 0; i < 1000; i++) { |
| 2518 | ocp_data = ocp_read_byte(tp, MCU_TYPE_PLA, PLA_OOB_CTRL); |
| 2519 | if (ocp_data & LINK_LIST_READY) |
| 2520 | break; |
| 2521 | mdelay(1); |
| 2522 | } |
| 2523 | |
| 2524 | ocp_data = ocp_read_word(tp, MCU_TYPE_PLA, PLA_SFF_STS_7); |
| 2525 | ocp_data |= RE_INIT_LL; |
| 2526 | ocp_write_word(tp, MCU_TYPE_PLA, PLA_SFF_STS_7, ocp_data); |
| 2527 | |
| 2528 | for (i = 0; i < 1000; i++) { |
| 2529 | ocp_data = ocp_read_byte(tp, MCU_TYPE_PLA, PLA_OOB_CTRL); |
| 2530 | if (ocp_data & LINK_LIST_READY) |
| 2531 | break; |
| 2532 | mdelay(1); |
| 2533 | } |
| 2534 | |
| 2535 | ocp_write_word(tp, MCU_TYPE_PLA, PLA_RMS, RTL8152_RMS); |
| 2536 | |
hayeswang | 43779f8 | 2014-01-02 11:25:10 +0800 | [diff] [blame] | 2537 | ocp_data = ocp_read_word(tp, MCU_TYPE_PLA, PLA_TEREDO_CFG); |
| 2538 | ocp_data &= ~TEREDO_WAKE_MASK; |
| 2539 | ocp_write_word(tp, MCU_TYPE_PLA, PLA_TEREDO_CFG, ocp_data); |
| 2540 | |
| 2541 | ocp_data = ocp_read_word(tp, MCU_TYPE_PLA, PLA_CPCR); |
| 2542 | ocp_data |= CPCR_RX_VLAN; |
| 2543 | ocp_write_word(tp, MCU_TYPE_PLA, PLA_CPCR, ocp_data); |
| 2544 | |
| 2545 | ocp_data = ocp_read_word(tp, MCU_TYPE_PLA, PAL_BDC_CR); |
| 2546 | ocp_data |= ALDPS_PROXY_MODE; |
| 2547 | ocp_write_word(tp, MCU_TYPE_PLA, PAL_BDC_CR, ocp_data); |
| 2548 | |
| 2549 | ocp_data = ocp_read_byte(tp, MCU_TYPE_PLA, PLA_OOB_CTRL); |
| 2550 | ocp_data |= NOW_IS_OOB | DIS_MCU_CLROOB; |
| 2551 | ocp_write_byte(tp, MCU_TYPE_PLA, PLA_OOB_CTRL, ocp_data); |
| 2552 | |
hayeswang | 00a5e36 | 2014-02-18 21:48:59 +0800 | [diff] [blame] | 2553 | rxdy_gated_en(tp, false); |
hayeswang | 43779f8 | 2014-01-02 11:25:10 +0800 | [diff] [blame] | 2554 | |
| 2555 | ocp_data = ocp_read_dword(tp, MCU_TYPE_PLA, PLA_RCR); |
| 2556 | ocp_data |= RCR_APM | RCR_AM | RCR_AB; |
| 2557 | ocp_write_dword(tp, MCU_TYPE_PLA, PLA_RCR, ocp_data); |
| 2558 | } |
| 2559 | |
| 2560 | static void r8153_disable_aldps(struct r8152 *tp) |
| 2561 | { |
| 2562 | u16 data; |
| 2563 | |
| 2564 | data = ocp_reg_read(tp, OCP_POWER_CFG); |
| 2565 | data &= ~EN_ALDPS; |
| 2566 | ocp_reg_write(tp, OCP_POWER_CFG, data); |
| 2567 | msleep(20); |
| 2568 | } |
| 2569 | |
| 2570 | static void r8153_enable_aldps(struct r8152 *tp) |
| 2571 | { |
| 2572 | u16 data; |
| 2573 | |
| 2574 | data = ocp_reg_read(tp, OCP_POWER_CFG); |
| 2575 | data |= EN_ALDPS; |
| 2576 | ocp_reg_write(tp, OCP_POWER_CFG, data); |
| 2577 | } |
| 2578 | |
hayeswang | ac718b6 | 2013-05-02 16:01:25 +0000 | [diff] [blame] | 2579 | static int rtl8152_set_speed(struct r8152 *tp, u8 autoneg, u16 speed, u8 duplex) |
| 2580 | { |
hayeswang | 43779f8 | 2014-01-02 11:25:10 +0800 | [diff] [blame] | 2581 | u16 bmcr, anar, gbcr; |
hayeswang | ac718b6 | 2013-05-02 16:01:25 +0000 | [diff] [blame] | 2582 | int ret = 0; |
| 2583 | |
| 2584 | cancel_delayed_work_sync(&tp->schedule); |
| 2585 | anar = r8152_mdio_read(tp, MII_ADVERTISE); |
| 2586 | anar &= ~(ADVERTISE_10HALF | ADVERTISE_10FULL | |
| 2587 | ADVERTISE_100HALF | ADVERTISE_100FULL); |
hayeswang | 43779f8 | 2014-01-02 11:25:10 +0800 | [diff] [blame] | 2588 | if (tp->mii.supports_gmii) { |
| 2589 | gbcr = r8152_mdio_read(tp, MII_CTRL1000); |
| 2590 | gbcr &= ~(ADVERTISE_1000FULL | ADVERTISE_1000HALF); |
| 2591 | } else { |
| 2592 | gbcr = 0; |
| 2593 | } |
hayeswang | ac718b6 | 2013-05-02 16:01:25 +0000 | [diff] [blame] | 2594 | |
| 2595 | if (autoneg == AUTONEG_DISABLE) { |
| 2596 | if (speed == SPEED_10) { |
| 2597 | bmcr = 0; |
| 2598 | anar |= ADVERTISE_10HALF | ADVERTISE_10FULL; |
| 2599 | } else if (speed == SPEED_100) { |
| 2600 | bmcr = BMCR_SPEED100; |
| 2601 | anar |= ADVERTISE_100HALF | ADVERTISE_100FULL; |
hayeswang | 43779f8 | 2014-01-02 11:25:10 +0800 | [diff] [blame] | 2602 | } else if (speed == SPEED_1000 && tp->mii.supports_gmii) { |
| 2603 | bmcr = BMCR_SPEED1000; |
| 2604 | gbcr |= ADVERTISE_1000FULL | ADVERTISE_1000HALF; |
hayeswang | ac718b6 | 2013-05-02 16:01:25 +0000 | [diff] [blame] | 2605 | } else { |
| 2606 | ret = -EINVAL; |
| 2607 | goto out; |
| 2608 | } |
| 2609 | |
| 2610 | if (duplex == DUPLEX_FULL) |
| 2611 | bmcr |= BMCR_FULLDPLX; |
| 2612 | } else { |
| 2613 | if (speed == SPEED_10) { |
| 2614 | if (duplex == DUPLEX_FULL) |
| 2615 | anar |= ADVERTISE_10HALF | ADVERTISE_10FULL; |
| 2616 | else |
| 2617 | anar |= ADVERTISE_10HALF; |
| 2618 | } else if (speed == SPEED_100) { |
| 2619 | if (duplex == DUPLEX_FULL) { |
| 2620 | anar |= ADVERTISE_10HALF | ADVERTISE_10FULL; |
| 2621 | anar |= ADVERTISE_100HALF | ADVERTISE_100FULL; |
| 2622 | } else { |
| 2623 | anar |= ADVERTISE_10HALF; |
| 2624 | anar |= ADVERTISE_100HALF; |
| 2625 | } |
hayeswang | 43779f8 | 2014-01-02 11:25:10 +0800 | [diff] [blame] | 2626 | } else if (speed == SPEED_1000 && tp->mii.supports_gmii) { |
| 2627 | if (duplex == DUPLEX_FULL) { |
| 2628 | anar |= ADVERTISE_10HALF | ADVERTISE_10FULL; |
| 2629 | anar |= ADVERTISE_100HALF | ADVERTISE_100FULL; |
| 2630 | gbcr |= ADVERTISE_1000FULL | ADVERTISE_1000HALF; |
| 2631 | } else { |
| 2632 | anar |= ADVERTISE_10HALF; |
| 2633 | anar |= ADVERTISE_100HALF; |
| 2634 | gbcr |= ADVERTISE_1000HALF; |
| 2635 | } |
hayeswang | ac718b6 | 2013-05-02 16:01:25 +0000 | [diff] [blame] | 2636 | } else { |
| 2637 | ret = -EINVAL; |
| 2638 | goto out; |
| 2639 | } |
| 2640 | |
| 2641 | bmcr = BMCR_ANENABLE | BMCR_ANRESTART; |
| 2642 | } |
| 2643 | |
hayeswang | aa66a5f | 2014-02-18 21:49:04 +0800 | [diff] [blame] | 2644 | if (test_bit(PHY_RESET, &tp->flags)) |
| 2645 | bmcr |= BMCR_RESET; |
| 2646 | |
hayeswang | 43779f8 | 2014-01-02 11:25:10 +0800 | [diff] [blame] | 2647 | if (tp->mii.supports_gmii) |
| 2648 | r8152_mdio_write(tp, MII_CTRL1000, gbcr); |
| 2649 | |
hayeswang | ac718b6 | 2013-05-02 16:01:25 +0000 | [diff] [blame] | 2650 | r8152_mdio_write(tp, MII_ADVERTISE, anar); |
| 2651 | r8152_mdio_write(tp, MII_BMCR, bmcr); |
| 2652 | |
hayeswang | aa66a5f | 2014-02-18 21:49:04 +0800 | [diff] [blame] | 2653 | if (test_bit(PHY_RESET, &tp->flags)) { |
| 2654 | int i; |
| 2655 | |
| 2656 | clear_bit(PHY_RESET, &tp->flags); |
| 2657 | for (i = 0; i < 50; i++) { |
| 2658 | msleep(20); |
| 2659 | if ((r8152_mdio_read(tp, MII_BMCR) & BMCR_RESET) == 0) |
| 2660 | break; |
| 2661 | } |
| 2662 | } |
| 2663 | |
hayeswang | ac718b6 | 2013-05-02 16:01:25 +0000 | [diff] [blame] | 2664 | out: |
hayeswang | ac718b6 | 2013-05-02 16:01:25 +0000 | [diff] [blame] | 2665 | |
| 2666 | return ret; |
| 2667 | } |
| 2668 | |
| 2669 | static void rtl8152_down(struct r8152 *tp) |
| 2670 | { |
hayeswang | 00a5e36 | 2014-02-18 21:48:59 +0800 | [diff] [blame] | 2671 | r8152_power_cut_en(tp, false); |
hayeswang | ac718b6 | 2013-05-02 16:01:25 +0000 | [diff] [blame] | 2672 | r8152b_disable_aldps(tp); |
| 2673 | r8152b_enter_oob(tp); |
| 2674 | r8152b_enable_aldps(tp); |
| 2675 | } |
| 2676 | |
hayeswang | 43779f8 | 2014-01-02 11:25:10 +0800 | [diff] [blame] | 2677 | static void rtl8153_down(struct r8152 *tp) |
| 2678 | { |
hayeswang | b970272 | 2014-02-18 21:49:00 +0800 | [diff] [blame] | 2679 | r8153_u1u2en(tp, false); |
| 2680 | r8153_power_cut_en(tp, false); |
hayeswang | 43779f8 | 2014-01-02 11:25:10 +0800 | [diff] [blame] | 2681 | r8153_disable_aldps(tp); |
| 2682 | r8153_enter_oob(tp); |
| 2683 | r8153_enable_aldps(tp); |
| 2684 | } |
| 2685 | |
hayeswang | ac718b6 | 2013-05-02 16:01:25 +0000 | [diff] [blame] | 2686 | static void set_carrier(struct r8152 *tp) |
| 2687 | { |
| 2688 | struct net_device *netdev = tp->netdev; |
| 2689 | u8 speed; |
| 2690 | |
hayeswang | 40a8291 | 2013-08-14 20:54:40 +0800 | [diff] [blame] | 2691 | clear_bit(RTL8152_LINK_CHG, &tp->flags); |
hayeswang | ac718b6 | 2013-05-02 16:01:25 +0000 | [diff] [blame] | 2692 | speed = rtl8152_get_speed(tp); |
| 2693 | |
| 2694 | if (speed & LINK_STATUS) { |
| 2695 | if (!(tp->speed & LINK_STATUS)) { |
hayeswang | c81229c | 2014-01-02 11:22:42 +0800 | [diff] [blame] | 2696 | tp->rtl_ops.enable(tp); |
hayeswang | ac718b6 | 2013-05-02 16:01:25 +0000 | [diff] [blame] | 2697 | set_bit(RTL8152_SET_RX_MODE, &tp->flags); |
| 2698 | netif_carrier_on(netdev); |
| 2699 | } |
| 2700 | } else { |
| 2701 | if (tp->speed & LINK_STATUS) { |
| 2702 | netif_carrier_off(netdev); |
hayeswang | ebc2ec48 | 2013-08-14 20:54:38 +0800 | [diff] [blame] | 2703 | tasklet_disable(&tp->tl); |
hayeswang | c81229c | 2014-01-02 11:22:42 +0800 | [diff] [blame] | 2704 | tp->rtl_ops.disable(tp); |
hayeswang | ebc2ec48 | 2013-08-14 20:54:38 +0800 | [diff] [blame] | 2705 | tasklet_enable(&tp->tl); |
hayeswang | ac718b6 | 2013-05-02 16:01:25 +0000 | [diff] [blame] | 2706 | } |
| 2707 | } |
| 2708 | tp->speed = speed; |
| 2709 | } |
| 2710 | |
| 2711 | static void rtl_work_func_t(struct work_struct *work) |
| 2712 | { |
| 2713 | struct r8152 *tp = container_of(work, struct r8152, schedule.work); |
| 2714 | |
hayeswang | 9a4be1b | 2014-02-18 21:49:07 +0800 | [diff] [blame] | 2715 | if (usb_autopm_get_interface(tp->intf) < 0) |
| 2716 | return; |
| 2717 | |
hayeswang | ac718b6 | 2013-05-02 16:01:25 +0000 | [diff] [blame] | 2718 | if (!test_bit(WORK_ENABLE, &tp->flags)) |
| 2719 | goto out1; |
| 2720 | |
| 2721 | if (test_bit(RTL8152_UNPLUG, &tp->flags)) |
| 2722 | goto out1; |
| 2723 | |
hayeswang | 40a8291 | 2013-08-14 20:54:40 +0800 | [diff] [blame] | 2724 | if (test_bit(RTL8152_LINK_CHG, &tp->flags)) |
| 2725 | set_carrier(tp); |
hayeswang | ac718b6 | 2013-05-02 16:01:25 +0000 | [diff] [blame] | 2726 | |
| 2727 | if (test_bit(RTL8152_SET_RX_MODE, &tp->flags)) |
| 2728 | _rtl8152_set_rx_mode(tp->netdev); |
| 2729 | |
hayeswang | 0c3121f | 2014-03-07 11:04:36 +0800 | [diff] [blame] | 2730 | if (test_bit(SCHEDULE_TASKLET, &tp->flags) && |
| 2731 | (tp->speed & LINK_STATUS)) { |
| 2732 | clear_bit(SCHEDULE_TASKLET, &tp->flags); |
| 2733 | tasklet_schedule(&tp->tl); |
| 2734 | } |
hayeswang | aa66a5f | 2014-02-18 21:49:04 +0800 | [diff] [blame] | 2735 | |
| 2736 | if (test_bit(PHY_RESET, &tp->flags)) |
| 2737 | rtl_phy_reset(tp); |
| 2738 | |
hayeswang | ac718b6 | 2013-05-02 16:01:25 +0000 | [diff] [blame] | 2739 | out1: |
hayeswang | 9a4be1b | 2014-02-18 21:49:07 +0800 | [diff] [blame] | 2740 | usb_autopm_put_interface(tp->intf); |
hayeswang | ac718b6 | 2013-05-02 16:01:25 +0000 | [diff] [blame] | 2741 | } |
| 2742 | |
| 2743 | static int rtl8152_open(struct net_device *netdev) |
| 2744 | { |
| 2745 | struct r8152 *tp = netdev_priv(netdev); |
| 2746 | int res = 0; |
| 2747 | |
hayeswang | 7e9da48 | 2014-02-18 21:49:05 +0800 | [diff] [blame] | 2748 | res = alloc_all_mem(tp); |
| 2749 | if (res) |
| 2750 | goto out; |
| 2751 | |
hayeswang | 9a4be1b | 2014-02-18 21:49:07 +0800 | [diff] [blame] | 2752 | res = usb_autopm_get_interface(tp->intf); |
| 2753 | if (res < 0) { |
| 2754 | free_all_mem(tp); |
| 2755 | goto out; |
| 2756 | } |
| 2757 | |
| 2758 | /* The WORK_ENABLE may be set when autoresume occurs */ |
| 2759 | if (test_bit(WORK_ENABLE, &tp->flags)) { |
| 2760 | clear_bit(WORK_ENABLE, &tp->flags); |
| 2761 | usb_kill_urb(tp->intr_urb); |
| 2762 | cancel_delayed_work_sync(&tp->schedule); |
| 2763 | if (tp->speed & LINK_STATUS) |
| 2764 | tp->rtl_ops.disable(tp); |
| 2765 | } |
| 2766 | |
hayeswang | 7e9da48 | 2014-02-18 21:49:05 +0800 | [diff] [blame] | 2767 | tp->rtl_ops.up(tp); |
| 2768 | |
hayeswang | 43779f8 | 2014-01-02 11:25:10 +0800 | [diff] [blame] | 2769 | rtl8152_set_speed(tp, AUTONEG_ENABLE, |
| 2770 | tp->mii.supports_gmii ? SPEED_1000 : SPEED_100, |
| 2771 | DUPLEX_FULL); |
hayeswang | 40a8291 | 2013-08-14 20:54:40 +0800 | [diff] [blame] | 2772 | tp->speed = 0; |
| 2773 | netif_carrier_off(netdev); |
hayeswang | ac718b6 | 2013-05-02 16:01:25 +0000 | [diff] [blame] | 2774 | netif_start_queue(netdev); |
| 2775 | set_bit(WORK_ENABLE, &tp->flags); |
hayeswang | db8515e | 2014-03-06 15:07:16 +0800 | [diff] [blame] | 2776 | |
hayeswang | 3d55f44 | 2014-02-06 11:55:48 +0800 | [diff] [blame] | 2777 | res = usb_submit_urb(tp->intr_urb, GFP_KERNEL); |
| 2778 | if (res) { |
| 2779 | if (res == -ENODEV) |
| 2780 | netif_device_detach(tp->netdev); |
| 2781 | netif_warn(tp, ifup, netdev, "intr_urb submit failed: %d\n", |
| 2782 | res); |
hayeswang | 7e9da48 | 2014-02-18 21:49:05 +0800 | [diff] [blame] | 2783 | free_all_mem(tp); |
hayeswang | 3d55f44 | 2014-02-06 11:55:48 +0800 | [diff] [blame] | 2784 | } |
| 2785 | |
hayeswang | 9a4be1b | 2014-02-18 21:49:07 +0800 | [diff] [blame] | 2786 | usb_autopm_put_interface(tp->intf); |
hayeswang | ac718b6 | 2013-05-02 16:01:25 +0000 | [diff] [blame] | 2787 | |
hayeswang | 7e9da48 | 2014-02-18 21:49:05 +0800 | [diff] [blame] | 2788 | out: |
hayeswang | ac718b6 | 2013-05-02 16:01:25 +0000 | [diff] [blame] | 2789 | return res; |
| 2790 | } |
| 2791 | |
| 2792 | static int rtl8152_close(struct net_device *netdev) |
| 2793 | { |
| 2794 | struct r8152 *tp = netdev_priv(netdev); |
| 2795 | int res = 0; |
| 2796 | |
| 2797 | clear_bit(WORK_ENABLE, &tp->flags); |
hayeswang | 3d55f44 | 2014-02-06 11:55:48 +0800 | [diff] [blame] | 2798 | usb_kill_urb(tp->intr_urb); |
hayeswang | ac718b6 | 2013-05-02 16:01:25 +0000 | [diff] [blame] | 2799 | cancel_delayed_work_sync(&tp->schedule); |
| 2800 | netif_stop_queue(netdev); |
hayeswang | 9a4be1b | 2014-02-18 21:49:07 +0800 | [diff] [blame] | 2801 | |
| 2802 | res = usb_autopm_get_interface(tp->intf); |
| 2803 | if (res < 0) { |
| 2804 | rtl_drop_queued_tx(tp); |
| 2805 | } else { |
| 2806 | /* |
| 2807 | * The autosuspend may have been enabled and wouldn't |
| 2808 | * be disable when autoresume occurs, because the |
| 2809 | * netif_running() would be false. |
| 2810 | */ |
| 2811 | if (test_bit(SELECTIVE_SUSPEND, &tp->flags)) { |
| 2812 | rtl_runtime_suspend_enable(tp, false); |
| 2813 | clear_bit(SELECTIVE_SUSPEND, &tp->flags); |
| 2814 | } |
| 2815 | |
| 2816 | tasklet_disable(&tp->tl); |
| 2817 | tp->rtl_ops.down(tp); |
| 2818 | tasklet_enable(&tp->tl); |
| 2819 | usb_autopm_put_interface(tp->intf); |
| 2820 | } |
hayeswang | ac718b6 | 2013-05-02 16:01:25 +0000 | [diff] [blame] | 2821 | |
hayeswang | 7e9da48 | 2014-02-18 21:49:05 +0800 | [diff] [blame] | 2822 | free_all_mem(tp); |
| 2823 | |
hayeswang | ac718b6 | 2013-05-02 16:01:25 +0000 | [diff] [blame] | 2824 | return res; |
| 2825 | } |
| 2826 | |
hayeswang | ac718b6 | 2013-05-02 16:01:25 +0000 | [diff] [blame] | 2827 | static void r8152b_enable_eee(struct r8152 *tp) |
| 2828 | { |
hayeswang | 45f4a19 | 2014-01-06 17:08:41 +0800 | [diff] [blame] | 2829 | u32 ocp_data; |
hayeswang | ac718b6 | 2013-05-02 16:01:25 +0000 | [diff] [blame] | 2830 | |
| 2831 | ocp_data = ocp_read_word(tp, MCU_TYPE_PLA, PLA_EEE_CR); |
| 2832 | ocp_data |= EEE_RX_EN | EEE_TX_EN; |
| 2833 | ocp_write_word(tp, MCU_TYPE_PLA, PLA_EEE_CR, ocp_data); |
| 2834 | ocp_reg_write(tp, OCP_EEE_CONFIG1, RG_TXLPI_MSK_HFDUP | RG_MATCLR_EN | |
| 2835 | EEE_10_CAP | EEE_NWAY_EN | |
| 2836 | TX_QUIET_EN | RX_QUIET_EN | |
| 2837 | SDRISETIME | RG_RXLPI_MSK_HFDUP | |
| 2838 | SDFALLTIME); |
| 2839 | ocp_reg_write(tp, OCP_EEE_CONFIG2, RG_LPIHYS_NUM | RG_DACQUIET_EN | |
| 2840 | RG_LDVQUIET_EN | RG_CKRSEL | |
| 2841 | RG_EEEPRG_EN); |
| 2842 | ocp_reg_write(tp, OCP_EEE_CONFIG3, FST_SNR_EYE_R | RG_LFS_SEL | MSK_PH); |
| 2843 | ocp_reg_write(tp, OCP_EEE_AR, FUN_ADDR | DEVICE_ADDR); |
| 2844 | ocp_reg_write(tp, OCP_EEE_DATA, EEE_ADDR); |
| 2845 | ocp_reg_write(tp, OCP_EEE_AR, FUN_DATA | DEVICE_ADDR); |
| 2846 | ocp_reg_write(tp, OCP_EEE_DATA, EEE_DATA); |
| 2847 | ocp_reg_write(tp, OCP_EEE_AR, 0x0000); |
| 2848 | } |
| 2849 | |
hayeswang | 43779f8 | 2014-01-02 11:25:10 +0800 | [diff] [blame] | 2850 | static void r8153_enable_eee(struct r8152 *tp) |
| 2851 | { |
| 2852 | u32 ocp_data; |
| 2853 | u16 data; |
| 2854 | |
| 2855 | ocp_data = ocp_read_word(tp, MCU_TYPE_PLA, PLA_EEE_CR); |
| 2856 | ocp_data |= EEE_RX_EN | EEE_TX_EN; |
| 2857 | ocp_write_word(tp, MCU_TYPE_PLA, PLA_EEE_CR, ocp_data); |
| 2858 | data = ocp_reg_read(tp, OCP_EEE_CFG); |
| 2859 | data |= EEE10_EN; |
| 2860 | ocp_reg_write(tp, OCP_EEE_CFG, data); |
| 2861 | data = ocp_reg_read(tp, OCP_EEE_CFG2); |
| 2862 | data |= MY1000_EEE | MY100_EEE; |
| 2863 | ocp_reg_write(tp, OCP_EEE_CFG2, data); |
| 2864 | } |
| 2865 | |
hayeswang | ac718b6 | 2013-05-02 16:01:25 +0000 | [diff] [blame] | 2866 | static void r8152b_enable_fc(struct r8152 *tp) |
| 2867 | { |
| 2868 | u16 anar; |
| 2869 | |
| 2870 | anar = r8152_mdio_read(tp, MII_ADVERTISE); |
| 2871 | anar |= ADVERTISE_PAUSE_CAP | ADVERTISE_PAUSE_ASYM; |
| 2872 | r8152_mdio_write(tp, MII_ADVERTISE, anar); |
| 2873 | } |
| 2874 | |
hayeswang | ac718b6 | 2013-05-02 16:01:25 +0000 | [diff] [blame] | 2875 | static void r8152b_init(struct r8152 *tp) |
| 2876 | { |
hayeswang | ebc2ec48 | 2013-08-14 20:54:38 +0800 | [diff] [blame] | 2877 | u32 ocp_data; |
hayeswang | ac718b6 | 2013-05-02 16:01:25 +0000 | [diff] [blame] | 2878 | |
hayeswang | ac718b6 | 2013-05-02 16:01:25 +0000 | [diff] [blame] | 2879 | if (tp->version == RTL_VER_01) { |
| 2880 | ocp_data = ocp_read_word(tp, MCU_TYPE_PLA, PLA_LED_FEATURE); |
| 2881 | ocp_data &= ~LED_MODE_MASK; |
| 2882 | ocp_write_word(tp, MCU_TYPE_PLA, PLA_LED_FEATURE, ocp_data); |
| 2883 | } |
| 2884 | |
hayeswang | 00a5e36 | 2014-02-18 21:48:59 +0800 | [diff] [blame] | 2885 | r8152_power_cut_en(tp, false); |
hayeswang | ac718b6 | 2013-05-02 16:01:25 +0000 | [diff] [blame] | 2886 | |
hayeswang | ac718b6 | 2013-05-02 16:01:25 +0000 | [diff] [blame] | 2887 | ocp_data = ocp_read_word(tp, MCU_TYPE_PLA, PLA_PHY_PWR); |
| 2888 | ocp_data |= TX_10M_IDLE_EN | PFM_PWM_SWITCH; |
| 2889 | ocp_write_word(tp, MCU_TYPE_PLA, PLA_PHY_PWR, ocp_data); |
| 2890 | ocp_data = ocp_read_dword(tp, MCU_TYPE_PLA, PLA_MAC_PWR_CTRL); |
| 2891 | ocp_data &= ~MCU_CLK_RATIO_MASK; |
| 2892 | ocp_data |= MCU_CLK_RATIO | D3_CLK_GATED_EN; |
| 2893 | ocp_write_dword(tp, MCU_TYPE_PLA, PLA_MAC_PWR_CTRL, ocp_data); |
| 2894 | ocp_data = GPHY_STS_MSK | SPEED_DOWN_MSK | |
| 2895 | SPDWN_RXDV_MSK | SPDWN_LINKCHG_MSK; |
| 2896 | ocp_write_word(tp, MCU_TYPE_PLA, PLA_GPHY_INTR_IMR, ocp_data); |
| 2897 | |
| 2898 | r8152b_enable_eee(tp); |
| 2899 | r8152b_enable_aldps(tp); |
| 2900 | r8152b_enable_fc(tp); |
| 2901 | |
hayeswang | ebc2ec48 | 2013-08-14 20:54:38 +0800 | [diff] [blame] | 2902 | /* enable rx aggregation */ |
hayeswang | ac718b6 | 2013-05-02 16:01:25 +0000 | [diff] [blame] | 2903 | ocp_data = ocp_read_word(tp, MCU_TYPE_USB, USB_USB_CTRL); |
hayeswang | ebc2ec48 | 2013-08-14 20:54:38 +0800 | [diff] [blame] | 2904 | ocp_data &= ~RX_AGG_DISABLE; |
hayeswang | ac718b6 | 2013-05-02 16:01:25 +0000 | [diff] [blame] | 2905 | ocp_write_word(tp, MCU_TYPE_USB, USB_USB_CTRL, ocp_data); |
| 2906 | } |
| 2907 | |
hayeswang | 43779f8 | 2014-01-02 11:25:10 +0800 | [diff] [blame] | 2908 | static void r8153_init(struct r8152 *tp) |
| 2909 | { |
| 2910 | u32 ocp_data; |
| 2911 | int i; |
| 2912 | |
hayeswang | b970272 | 2014-02-18 21:49:00 +0800 | [diff] [blame] | 2913 | r8153_u1u2en(tp, false); |
hayeswang | 43779f8 | 2014-01-02 11:25:10 +0800 | [diff] [blame] | 2914 | |
| 2915 | for (i = 0; i < 500; i++) { |
| 2916 | if (ocp_read_word(tp, MCU_TYPE_PLA, PLA_BOOT_CTRL) & |
| 2917 | AUTOLOAD_DONE) |
| 2918 | break; |
| 2919 | msleep(20); |
| 2920 | } |
| 2921 | |
| 2922 | for (i = 0; i < 500; i++) { |
| 2923 | ocp_data = ocp_reg_read(tp, OCP_PHY_STATUS) & PHY_STAT_MASK; |
| 2924 | if (ocp_data == PHY_STAT_LAN_ON || ocp_data == PHY_STAT_PWRDN) |
| 2925 | break; |
| 2926 | msleep(20); |
| 2927 | } |
| 2928 | |
hayeswang | b970272 | 2014-02-18 21:49:00 +0800 | [diff] [blame] | 2929 | r8153_u2p3en(tp, false); |
hayeswang | 43779f8 | 2014-01-02 11:25:10 +0800 | [diff] [blame] | 2930 | |
| 2931 | ocp_data = ocp_read_word(tp, MCU_TYPE_USB, USB_WDT11_CTRL); |
| 2932 | ocp_data &= ~TIMER11_EN; |
| 2933 | ocp_write_word(tp, MCU_TYPE_USB, USB_WDT11_CTRL, ocp_data); |
| 2934 | |
hayeswang | 43779f8 | 2014-01-02 11:25:10 +0800 | [diff] [blame] | 2935 | ocp_data = ocp_read_word(tp, MCU_TYPE_PLA, PLA_LED_FEATURE); |
| 2936 | ocp_data &= ~LED_MODE_MASK; |
| 2937 | ocp_write_word(tp, MCU_TYPE_PLA, PLA_LED_FEATURE, ocp_data); |
| 2938 | |
| 2939 | ocp_data = ocp_read_byte(tp, MCU_TYPE_USB, USB_LPM_CTRL); |
| 2940 | ocp_data &= ~LPM_TIMER_MASK; |
| 2941 | if (tp->udev->speed == USB_SPEED_SUPER) |
| 2942 | ocp_data |= LPM_TIMER_500US; |
| 2943 | else |
| 2944 | ocp_data |= LPM_TIMER_500MS; |
| 2945 | ocp_write_byte(tp, MCU_TYPE_USB, USB_LPM_CTRL, ocp_data); |
| 2946 | |
| 2947 | ocp_data = ocp_read_word(tp, MCU_TYPE_USB, USB_AFE_CTRL2); |
| 2948 | ocp_data &= ~SEN_VAL_MASK; |
| 2949 | ocp_data |= SEN_VAL_NORMAL | SEL_RXIDLE; |
| 2950 | ocp_write_word(tp, MCU_TYPE_USB, USB_AFE_CTRL2, ocp_data); |
| 2951 | |
hayeswang | b970272 | 2014-02-18 21:49:00 +0800 | [diff] [blame] | 2952 | r8153_power_cut_en(tp, false); |
| 2953 | r8153_u1u2en(tp, true); |
hayeswang | 43779f8 | 2014-01-02 11:25:10 +0800 | [diff] [blame] | 2954 | |
hayeswang | 43779f8 | 2014-01-02 11:25:10 +0800 | [diff] [blame] | 2955 | ocp_write_word(tp, MCU_TYPE_PLA, PLA_MAC_PWR_CTRL, ALDPS_SPDWN_RATIO); |
| 2956 | ocp_write_word(tp, MCU_TYPE_PLA, PLA_MAC_PWR_CTRL2, EEE_SPDWN_RATIO); |
| 2957 | ocp_write_word(tp, MCU_TYPE_PLA, PLA_MAC_PWR_CTRL3, |
| 2958 | PKT_AVAIL_SPDWN_EN | SUSPEND_SPDWN_EN | |
| 2959 | U1U2_SPDWN_EN | L1_SPDWN_EN); |
| 2960 | ocp_write_word(tp, MCU_TYPE_PLA, PLA_MAC_PWR_CTRL4, |
| 2961 | PWRSAVE_SPDWN_EN | RXDV_SPDWN_EN | TX10MIDLE_EN | |
| 2962 | TP100_SPDWN_EN | TP500_SPDWN_EN | TP1000_SPDWN_EN | |
| 2963 | EEE_SPDWN_EN); |
| 2964 | |
| 2965 | r8153_enable_eee(tp); |
| 2966 | r8153_enable_aldps(tp); |
| 2967 | r8152b_enable_fc(tp); |
hayeswang | 43779f8 | 2014-01-02 11:25:10 +0800 | [diff] [blame] | 2968 | } |
| 2969 | |
hayeswang | ac718b6 | 2013-05-02 16:01:25 +0000 | [diff] [blame] | 2970 | static int rtl8152_suspend(struct usb_interface *intf, pm_message_t message) |
| 2971 | { |
| 2972 | struct r8152 *tp = usb_get_intfdata(intf); |
| 2973 | |
hayeswang | 9a4be1b | 2014-02-18 21:49:07 +0800 | [diff] [blame] | 2974 | if (PMSG_IS_AUTO(message)) |
| 2975 | set_bit(SELECTIVE_SUSPEND, &tp->flags); |
| 2976 | else |
| 2977 | netif_device_detach(tp->netdev); |
hayeswang | ac718b6 | 2013-05-02 16:01:25 +0000 | [diff] [blame] | 2978 | |
| 2979 | if (netif_running(tp->netdev)) { |
| 2980 | clear_bit(WORK_ENABLE, &tp->flags); |
hayeswang | 40a8291 | 2013-08-14 20:54:40 +0800 | [diff] [blame] | 2981 | usb_kill_urb(tp->intr_urb); |
hayeswang | ac718b6 | 2013-05-02 16:01:25 +0000 | [diff] [blame] | 2982 | cancel_delayed_work_sync(&tp->schedule); |
hayeswang | 9a4be1b | 2014-02-18 21:49:07 +0800 | [diff] [blame] | 2983 | if (test_bit(SELECTIVE_SUSPEND, &tp->flags)) { |
| 2984 | rtl_runtime_suspend_enable(tp, true); |
| 2985 | } else { |
| 2986 | tasklet_disable(&tp->tl); |
| 2987 | tp->rtl_ops.down(tp); |
| 2988 | tasklet_enable(&tp->tl); |
| 2989 | } |
hayeswang | ac718b6 | 2013-05-02 16:01:25 +0000 | [diff] [blame] | 2990 | } |
| 2991 | |
hayeswang | ac718b6 | 2013-05-02 16:01:25 +0000 | [diff] [blame] | 2992 | return 0; |
| 2993 | } |
| 2994 | |
| 2995 | static int rtl8152_resume(struct usb_interface *intf) |
| 2996 | { |
| 2997 | struct r8152 *tp = usb_get_intfdata(intf); |
| 2998 | |
hayeswang | 9a4be1b | 2014-02-18 21:49:07 +0800 | [diff] [blame] | 2999 | if (!test_bit(SELECTIVE_SUSPEND, &tp->flags)) { |
| 3000 | tp->rtl_ops.init(tp); |
| 3001 | netif_device_attach(tp->netdev); |
| 3002 | } |
| 3003 | |
hayeswang | ac718b6 | 2013-05-02 16:01:25 +0000 | [diff] [blame] | 3004 | if (netif_running(tp->netdev)) { |
hayeswang | 9a4be1b | 2014-02-18 21:49:07 +0800 | [diff] [blame] | 3005 | if (test_bit(SELECTIVE_SUSPEND, &tp->flags)) { |
| 3006 | rtl_runtime_suspend_enable(tp, false); |
| 3007 | clear_bit(SELECTIVE_SUSPEND, &tp->flags); |
| 3008 | if (tp->speed & LINK_STATUS) |
| 3009 | tp->rtl_ops.disable(tp); |
| 3010 | } else { |
| 3011 | tp->rtl_ops.up(tp); |
| 3012 | rtl8152_set_speed(tp, AUTONEG_ENABLE, |
hayeswang | 43779f8 | 2014-01-02 11:25:10 +0800 | [diff] [blame] | 3013 | tp->mii.supports_gmii ? SPEED_1000 : SPEED_100, |
| 3014 | DUPLEX_FULL); |
hayeswang | 9a4be1b | 2014-02-18 21:49:07 +0800 | [diff] [blame] | 3015 | } |
hayeswang | 40a8291 | 2013-08-14 20:54:40 +0800 | [diff] [blame] | 3016 | tp->speed = 0; |
| 3017 | netif_carrier_off(tp->netdev); |
hayeswang | ac718b6 | 2013-05-02 16:01:25 +0000 | [diff] [blame] | 3018 | set_bit(WORK_ENABLE, &tp->flags); |
hayeswang | 40a8291 | 2013-08-14 20:54:40 +0800 | [diff] [blame] | 3019 | usb_submit_urb(tp->intr_urb, GFP_KERNEL); |
hayeswang | ac718b6 | 2013-05-02 16:01:25 +0000 | [diff] [blame] | 3020 | } |
| 3021 | |
| 3022 | return 0; |
| 3023 | } |
| 3024 | |
hayeswang | 21ff2e8 | 2014-02-18 21:49:06 +0800 | [diff] [blame] | 3025 | static void rtl8152_get_wol(struct net_device *dev, struct ethtool_wolinfo *wol) |
| 3026 | { |
| 3027 | struct r8152 *tp = netdev_priv(dev); |
| 3028 | |
hayeswang | 9a4be1b | 2014-02-18 21:49:07 +0800 | [diff] [blame] | 3029 | if (usb_autopm_get_interface(tp->intf) < 0) |
| 3030 | return; |
| 3031 | |
hayeswang | 21ff2e8 | 2014-02-18 21:49:06 +0800 | [diff] [blame] | 3032 | wol->supported = WAKE_ANY; |
| 3033 | wol->wolopts = __rtl_get_wol(tp); |
hayeswang | 9a4be1b | 2014-02-18 21:49:07 +0800 | [diff] [blame] | 3034 | |
| 3035 | usb_autopm_put_interface(tp->intf); |
hayeswang | 21ff2e8 | 2014-02-18 21:49:06 +0800 | [diff] [blame] | 3036 | } |
| 3037 | |
| 3038 | static int rtl8152_set_wol(struct net_device *dev, struct ethtool_wolinfo *wol) |
| 3039 | { |
| 3040 | struct r8152 *tp = netdev_priv(dev); |
hayeswang | 9a4be1b | 2014-02-18 21:49:07 +0800 | [diff] [blame] | 3041 | int ret; |
| 3042 | |
| 3043 | ret = usb_autopm_get_interface(tp->intf); |
| 3044 | if (ret < 0) |
| 3045 | goto out_set_wol; |
hayeswang | 21ff2e8 | 2014-02-18 21:49:06 +0800 | [diff] [blame] | 3046 | |
| 3047 | __rtl_set_wol(tp, wol->wolopts); |
| 3048 | tp->saved_wolopts = wol->wolopts & WAKE_ANY; |
| 3049 | |
hayeswang | 9a4be1b | 2014-02-18 21:49:07 +0800 | [diff] [blame] | 3050 | usb_autopm_put_interface(tp->intf); |
| 3051 | |
| 3052 | out_set_wol: |
| 3053 | return ret; |
hayeswang | 21ff2e8 | 2014-02-18 21:49:06 +0800 | [diff] [blame] | 3054 | } |
| 3055 | |
hayeswang | a5ec27c | 2014-02-18 21:49:11 +0800 | [diff] [blame] | 3056 | static u32 rtl8152_get_msglevel(struct net_device *dev) |
| 3057 | { |
| 3058 | struct r8152 *tp = netdev_priv(dev); |
| 3059 | |
| 3060 | return tp->msg_enable; |
| 3061 | } |
| 3062 | |
| 3063 | static void rtl8152_set_msglevel(struct net_device *dev, u32 value) |
| 3064 | { |
| 3065 | struct r8152 *tp = netdev_priv(dev); |
| 3066 | |
| 3067 | tp->msg_enable = value; |
| 3068 | } |
| 3069 | |
hayeswang | ac718b6 | 2013-05-02 16:01:25 +0000 | [diff] [blame] | 3070 | static void rtl8152_get_drvinfo(struct net_device *netdev, |
| 3071 | struct ethtool_drvinfo *info) |
| 3072 | { |
| 3073 | struct r8152 *tp = netdev_priv(netdev); |
| 3074 | |
| 3075 | strncpy(info->driver, MODULENAME, ETHTOOL_BUSINFO_LEN); |
| 3076 | strncpy(info->version, DRIVER_VERSION, ETHTOOL_BUSINFO_LEN); |
| 3077 | usb_make_path(tp->udev, info->bus_info, sizeof(info->bus_info)); |
| 3078 | } |
| 3079 | |
| 3080 | static |
| 3081 | int rtl8152_get_settings(struct net_device *netdev, struct ethtool_cmd *cmd) |
| 3082 | { |
| 3083 | struct r8152 *tp = netdev_priv(netdev); |
| 3084 | |
| 3085 | if (!tp->mii.mdio_read) |
| 3086 | return -EOPNOTSUPP; |
| 3087 | |
| 3088 | return mii_ethtool_gset(&tp->mii, cmd); |
| 3089 | } |
| 3090 | |
| 3091 | static int rtl8152_set_settings(struct net_device *dev, struct ethtool_cmd *cmd) |
| 3092 | { |
| 3093 | struct r8152 *tp = netdev_priv(dev); |
hayeswang | 9a4be1b | 2014-02-18 21:49:07 +0800 | [diff] [blame] | 3094 | int ret; |
hayeswang | ac718b6 | 2013-05-02 16:01:25 +0000 | [diff] [blame] | 3095 | |
hayeswang | 9a4be1b | 2014-02-18 21:49:07 +0800 | [diff] [blame] | 3096 | ret = usb_autopm_get_interface(tp->intf); |
| 3097 | if (ret < 0) |
| 3098 | goto out; |
| 3099 | |
| 3100 | ret = rtl8152_set_speed(tp, cmd->autoneg, cmd->speed, cmd->duplex); |
| 3101 | |
| 3102 | usb_autopm_put_interface(tp->intf); |
| 3103 | |
| 3104 | out: |
| 3105 | return ret; |
hayeswang | ac718b6 | 2013-05-02 16:01:25 +0000 | [diff] [blame] | 3106 | } |
| 3107 | |
| 3108 | static struct ethtool_ops ops = { |
| 3109 | .get_drvinfo = rtl8152_get_drvinfo, |
| 3110 | .get_settings = rtl8152_get_settings, |
| 3111 | .set_settings = rtl8152_set_settings, |
| 3112 | .get_link = ethtool_op_get_link, |
hayeswang | a5ec27c | 2014-02-18 21:49:11 +0800 | [diff] [blame] | 3113 | .get_msglevel = rtl8152_get_msglevel, |
| 3114 | .set_msglevel = rtl8152_set_msglevel, |
hayeswang | 21ff2e8 | 2014-02-18 21:49:06 +0800 | [diff] [blame] | 3115 | .get_wol = rtl8152_get_wol, |
| 3116 | .set_wol = rtl8152_set_wol, |
hayeswang | ac718b6 | 2013-05-02 16:01:25 +0000 | [diff] [blame] | 3117 | }; |
| 3118 | |
| 3119 | static int rtl8152_ioctl(struct net_device *netdev, struct ifreq *rq, int cmd) |
| 3120 | { |
| 3121 | struct r8152 *tp = netdev_priv(netdev); |
| 3122 | struct mii_ioctl_data *data = if_mii(rq); |
hayeswang | 9a4be1b | 2014-02-18 21:49:07 +0800 | [diff] [blame] | 3123 | int res; |
| 3124 | |
| 3125 | res = usb_autopm_get_interface(tp->intf); |
| 3126 | if (res < 0) |
| 3127 | goto out; |
hayeswang | ac718b6 | 2013-05-02 16:01:25 +0000 | [diff] [blame] | 3128 | |
| 3129 | switch (cmd) { |
| 3130 | case SIOCGMIIPHY: |
| 3131 | data->phy_id = R8152_PHY_ID; /* Internal PHY */ |
| 3132 | break; |
| 3133 | |
| 3134 | case SIOCGMIIREG: |
| 3135 | data->val_out = r8152_mdio_read(tp, data->reg_num); |
| 3136 | break; |
| 3137 | |
| 3138 | case SIOCSMIIREG: |
| 3139 | if (!capable(CAP_NET_ADMIN)) { |
| 3140 | res = -EPERM; |
| 3141 | break; |
| 3142 | } |
| 3143 | r8152_mdio_write(tp, data->reg_num, data->val_in); |
| 3144 | break; |
| 3145 | |
| 3146 | default: |
| 3147 | res = -EOPNOTSUPP; |
| 3148 | } |
| 3149 | |
hayeswang | 9a4be1b | 2014-02-18 21:49:07 +0800 | [diff] [blame] | 3150 | usb_autopm_put_interface(tp->intf); |
| 3151 | |
| 3152 | out: |
hayeswang | ac718b6 | 2013-05-02 16:01:25 +0000 | [diff] [blame] | 3153 | return res; |
| 3154 | } |
| 3155 | |
| 3156 | static const struct net_device_ops rtl8152_netdev_ops = { |
| 3157 | .ndo_open = rtl8152_open, |
| 3158 | .ndo_stop = rtl8152_close, |
| 3159 | .ndo_do_ioctl = rtl8152_ioctl, |
| 3160 | .ndo_start_xmit = rtl8152_start_xmit, |
| 3161 | .ndo_tx_timeout = rtl8152_tx_timeout, |
| 3162 | .ndo_set_rx_mode = rtl8152_set_rx_mode, |
| 3163 | .ndo_set_mac_address = rtl8152_set_mac_address, |
| 3164 | |
| 3165 | .ndo_change_mtu = eth_change_mtu, |
| 3166 | .ndo_validate_addr = eth_validate_addr, |
| 3167 | }; |
| 3168 | |
| 3169 | static void r8152b_get_version(struct r8152 *tp) |
| 3170 | { |
| 3171 | u32 ocp_data; |
| 3172 | u16 version; |
| 3173 | |
| 3174 | ocp_data = ocp_read_word(tp, MCU_TYPE_PLA, PLA_TCR1); |
| 3175 | version = (u16)(ocp_data & VERSION_MASK); |
| 3176 | |
| 3177 | switch (version) { |
| 3178 | case 0x4c00: |
| 3179 | tp->version = RTL_VER_01; |
| 3180 | break; |
| 3181 | case 0x4c10: |
| 3182 | tp->version = RTL_VER_02; |
| 3183 | break; |
hayeswang | 43779f8 | 2014-01-02 11:25:10 +0800 | [diff] [blame] | 3184 | case 0x5c00: |
| 3185 | tp->version = RTL_VER_03; |
| 3186 | tp->mii.supports_gmii = 1; |
| 3187 | break; |
| 3188 | case 0x5c10: |
| 3189 | tp->version = RTL_VER_04; |
| 3190 | tp->mii.supports_gmii = 1; |
| 3191 | break; |
| 3192 | case 0x5c20: |
| 3193 | tp->version = RTL_VER_05; |
| 3194 | tp->mii.supports_gmii = 1; |
| 3195 | break; |
hayeswang | ac718b6 | 2013-05-02 16:01:25 +0000 | [diff] [blame] | 3196 | default: |
| 3197 | netif_info(tp, probe, tp->netdev, |
| 3198 | "Unknown version 0x%04x\n", version); |
| 3199 | break; |
| 3200 | } |
| 3201 | } |
| 3202 | |
hayeswang | e3fe0b1 | 2014-01-02 11:22:39 +0800 | [diff] [blame] | 3203 | static void rtl8152_unload(struct r8152 *tp) |
| 3204 | { |
hayeswang | 00a5e36 | 2014-02-18 21:48:59 +0800 | [diff] [blame] | 3205 | if (tp->version != RTL_VER_01) |
| 3206 | r8152_power_cut_en(tp, true); |
hayeswang | e3fe0b1 | 2014-01-02 11:22:39 +0800 | [diff] [blame] | 3207 | } |
| 3208 | |
hayeswang | 43779f8 | 2014-01-02 11:25:10 +0800 | [diff] [blame] | 3209 | static void rtl8153_unload(struct r8152 *tp) |
| 3210 | { |
hayeswang | b970272 | 2014-02-18 21:49:00 +0800 | [diff] [blame] | 3211 | r8153_power_cut_en(tp, true); |
hayeswang | 43779f8 | 2014-01-02 11:25:10 +0800 | [diff] [blame] | 3212 | } |
| 3213 | |
hayeswang | 31ca1de | 2014-01-06 17:08:43 +0800 | [diff] [blame] | 3214 | static int rtl_ops_init(struct r8152 *tp, const struct usb_device_id *id) |
hayeswang | c81229c | 2014-01-02 11:22:42 +0800 | [diff] [blame] | 3215 | { |
| 3216 | struct rtl_ops *ops = &tp->rtl_ops; |
hayeswang | 31ca1de | 2014-01-06 17:08:43 +0800 | [diff] [blame] | 3217 | int ret = -ENODEV; |
hayeswang | c81229c | 2014-01-02 11:22:42 +0800 | [diff] [blame] | 3218 | |
| 3219 | switch (id->idVendor) { |
| 3220 | case VENDOR_ID_REALTEK: |
| 3221 | switch (id->idProduct) { |
| 3222 | case PRODUCT_ID_RTL8152: |
| 3223 | ops->init = r8152b_init; |
| 3224 | ops->enable = rtl8152_enable; |
| 3225 | ops->disable = rtl8152_disable; |
hayeswang | 7e9da48 | 2014-02-18 21:49:05 +0800 | [diff] [blame] | 3226 | ops->up = r8152b_exit_oob; |
hayeswang | c81229c | 2014-01-02 11:22:42 +0800 | [diff] [blame] | 3227 | ops->down = rtl8152_down; |
| 3228 | ops->unload = rtl8152_unload; |
hayeswang | 31ca1de | 2014-01-06 17:08:43 +0800 | [diff] [blame] | 3229 | ret = 0; |
hayeswang | c81229c | 2014-01-02 11:22:42 +0800 | [diff] [blame] | 3230 | break; |
hayeswang | 43779f8 | 2014-01-02 11:25:10 +0800 | [diff] [blame] | 3231 | case PRODUCT_ID_RTL8153: |
| 3232 | ops->init = r8153_init; |
| 3233 | ops->enable = rtl8153_enable; |
| 3234 | ops->disable = rtl8152_disable; |
hayeswang | 7e9da48 | 2014-02-18 21:49:05 +0800 | [diff] [blame] | 3235 | ops->up = r8153_first_init; |
hayeswang | 43779f8 | 2014-01-02 11:25:10 +0800 | [diff] [blame] | 3236 | ops->down = rtl8153_down; |
| 3237 | ops->unload = rtl8153_unload; |
hayeswang | 31ca1de | 2014-01-06 17:08:43 +0800 | [diff] [blame] | 3238 | ret = 0; |
hayeswang | 43779f8 | 2014-01-02 11:25:10 +0800 | [diff] [blame] | 3239 | break; |
| 3240 | default: |
hayeswang | 43779f8 | 2014-01-02 11:25:10 +0800 | [diff] [blame] | 3241 | break; |
| 3242 | } |
| 3243 | break; |
| 3244 | |
| 3245 | case VENDOR_ID_SAMSUNG: |
| 3246 | switch (id->idProduct) { |
| 3247 | case PRODUCT_ID_SAMSUNG: |
| 3248 | ops->init = r8153_init; |
| 3249 | ops->enable = rtl8153_enable; |
| 3250 | ops->disable = rtl8152_disable; |
hayeswang | 7e9da48 | 2014-02-18 21:49:05 +0800 | [diff] [blame] | 3251 | ops->up = r8153_first_init; |
hayeswang | 43779f8 | 2014-01-02 11:25:10 +0800 | [diff] [blame] | 3252 | ops->down = rtl8153_down; |
| 3253 | ops->unload = rtl8153_unload; |
hayeswang | 31ca1de | 2014-01-06 17:08:43 +0800 | [diff] [blame] | 3254 | ret = 0; |
hayeswang | 43779f8 | 2014-01-02 11:25:10 +0800 | [diff] [blame] | 3255 | break; |
hayeswang | c81229c | 2014-01-02 11:22:42 +0800 | [diff] [blame] | 3256 | default: |
hayeswang | c81229c | 2014-01-02 11:22:42 +0800 | [diff] [blame] | 3257 | break; |
| 3258 | } |
| 3259 | break; |
| 3260 | |
| 3261 | default: |
hayeswang | c81229c | 2014-01-02 11:22:42 +0800 | [diff] [blame] | 3262 | break; |
| 3263 | } |
| 3264 | |
hayeswang | 31ca1de | 2014-01-06 17:08:43 +0800 | [diff] [blame] | 3265 | if (ret) |
| 3266 | netif_err(tp, probe, tp->netdev, "Unknown Device\n"); |
| 3267 | |
hayeswang | c81229c | 2014-01-02 11:22:42 +0800 | [diff] [blame] | 3268 | return ret; |
| 3269 | } |
| 3270 | |
hayeswang | ac718b6 | 2013-05-02 16:01:25 +0000 | [diff] [blame] | 3271 | static int rtl8152_probe(struct usb_interface *intf, |
| 3272 | const struct usb_device_id *id) |
| 3273 | { |
| 3274 | struct usb_device *udev = interface_to_usbdev(intf); |
| 3275 | struct r8152 *tp; |
| 3276 | struct net_device *netdev; |
hayeswang | ebc2ec48 | 2013-08-14 20:54:38 +0800 | [diff] [blame] | 3277 | int ret; |
hayeswang | ac718b6 | 2013-05-02 16:01:25 +0000 | [diff] [blame] | 3278 | |
hayeswang | ac718b6 | 2013-05-02 16:01:25 +0000 | [diff] [blame] | 3279 | netdev = alloc_etherdev(sizeof(struct r8152)); |
| 3280 | if (!netdev) { |
Hayes Wang | 4a8deae | 2014-01-07 11:18:22 +0800 | [diff] [blame] | 3281 | dev_err(&intf->dev, "Out of memory\n"); |
hayeswang | ac718b6 | 2013-05-02 16:01:25 +0000 | [diff] [blame] | 3282 | return -ENOMEM; |
| 3283 | } |
| 3284 | |
hayeswang | ebc2ec48 | 2013-08-14 20:54:38 +0800 | [diff] [blame] | 3285 | SET_NETDEV_DEV(netdev, &intf->dev); |
hayeswang | ac718b6 | 2013-05-02 16:01:25 +0000 | [diff] [blame] | 3286 | tp = netdev_priv(netdev); |
| 3287 | tp->msg_enable = 0x7FFF; |
| 3288 | |
hayeswang | e3ad412 | 2014-01-06 17:08:42 +0800 | [diff] [blame] | 3289 | tp->udev = udev; |
| 3290 | tp->netdev = netdev; |
| 3291 | tp->intf = intf; |
| 3292 | |
hayeswang | 31ca1de | 2014-01-06 17:08:43 +0800 | [diff] [blame] | 3293 | ret = rtl_ops_init(tp, id); |
| 3294 | if (ret) |
| 3295 | goto out; |
hayeswang | c81229c | 2014-01-02 11:22:42 +0800 | [diff] [blame] | 3296 | |
hayeswang | ebc2ec48 | 2013-08-14 20:54:38 +0800 | [diff] [blame] | 3297 | tasklet_init(&tp->tl, bottom_half, (unsigned long)tp); |
hayeswang | ac718b6 | 2013-05-02 16:01:25 +0000 | [diff] [blame] | 3298 | INIT_DELAYED_WORK(&tp->schedule, rtl_work_func_t); |
| 3299 | |
hayeswang | ac718b6 | 2013-05-02 16:01:25 +0000 | [diff] [blame] | 3300 | netdev->netdev_ops = &rtl8152_netdev_ops; |
| 3301 | netdev->watchdog_timeo = RTL8152_TX_TIMEOUT; |
hayeswang | 5bd2388 | 2013-08-14 20:54:39 +0800 | [diff] [blame] | 3302 | |
hayeswang | 60c8907 | 2014-03-07 11:04:39 +0800 | [diff] [blame] | 3303 | netdev->features |= NETIF_F_RXCSUM | NETIF_F_IP_CSUM | NETIF_F_SG | |
hayeswang | 6128d1bb | 2014-03-07 11:04:40 +0800 | [diff] [blame] | 3304 | NETIF_F_TSO | NETIF_F_FRAGLIST | NETIF_F_IPV6_CSUM | |
| 3305 | NETIF_F_TSO6; |
hayeswang | 60c8907 | 2014-03-07 11:04:39 +0800 | [diff] [blame] | 3306 | netdev->hw_features = NETIF_F_RXCSUM | NETIF_F_IP_CSUM | NETIF_F_SG | |
hayeswang | 6128d1bb | 2014-03-07 11:04:40 +0800 | [diff] [blame] | 3307 | NETIF_F_TSO | NETIF_F_FRAGLIST | |
| 3308 | NETIF_F_IPV6_CSUM | NETIF_F_TSO6; |
hayeswang | db8515e | 2014-03-06 15:07:16 +0800 | [diff] [blame] | 3309 | |
hayeswang | ac718b6 | 2013-05-02 16:01:25 +0000 | [diff] [blame] | 3310 | SET_ETHTOOL_OPS(netdev, &ops); |
hayeswang | 60c8907 | 2014-03-07 11:04:39 +0800 | [diff] [blame] | 3311 | netif_set_gso_max_size(netdev, RTL_LIMITED_TSO_SIZE); |
hayeswang | ac718b6 | 2013-05-02 16:01:25 +0000 | [diff] [blame] | 3312 | |
| 3313 | tp->mii.dev = netdev; |
| 3314 | tp->mii.mdio_read = read_mii_word; |
| 3315 | tp->mii.mdio_write = write_mii_word; |
| 3316 | tp->mii.phy_id_mask = 0x3f; |
| 3317 | tp->mii.reg_num_mask = 0x1f; |
| 3318 | tp->mii.phy_id = R8152_PHY_ID; |
| 3319 | tp->mii.supports_gmii = 0; |
| 3320 | |
hayeswang | 9a4be1b | 2014-02-18 21:49:07 +0800 | [diff] [blame] | 3321 | intf->needs_remote_wakeup = 1; |
| 3322 | |
hayeswang | ac718b6 | 2013-05-02 16:01:25 +0000 | [diff] [blame] | 3323 | r8152b_get_version(tp); |
hayeswang | c81229c | 2014-01-02 11:22:42 +0800 | [diff] [blame] | 3324 | tp->rtl_ops.init(tp); |
hayeswang | ac718b6 | 2013-05-02 16:01:25 +0000 | [diff] [blame] | 3325 | set_ethernet_addr(tp); |
| 3326 | |
hayeswang | ac718b6 | 2013-05-02 16:01:25 +0000 | [diff] [blame] | 3327 | usb_set_intfdata(intf, tp); |
hayeswang | ac718b6 | 2013-05-02 16:01:25 +0000 | [diff] [blame] | 3328 | |
hayeswang | ebc2ec48 | 2013-08-14 20:54:38 +0800 | [diff] [blame] | 3329 | ret = register_netdev(netdev); |
| 3330 | if (ret != 0) { |
Hayes Wang | 4a8deae | 2014-01-07 11:18:22 +0800 | [diff] [blame] | 3331 | netif_err(tp, probe, netdev, "couldn't register the device\n"); |
hayeswang | ebc2ec48 | 2013-08-14 20:54:38 +0800 | [diff] [blame] | 3332 | goto out1; |
hayeswang | ac718b6 | 2013-05-02 16:01:25 +0000 | [diff] [blame] | 3333 | } |
| 3334 | |
hayeswang | 21ff2e8 | 2014-02-18 21:49:06 +0800 | [diff] [blame] | 3335 | tp->saved_wolopts = __rtl_get_wol(tp); |
| 3336 | if (tp->saved_wolopts) |
| 3337 | device_set_wakeup_enable(&udev->dev, true); |
| 3338 | else |
| 3339 | device_set_wakeup_enable(&udev->dev, false); |
| 3340 | |
Hayes Wang | 4a8deae | 2014-01-07 11:18:22 +0800 | [diff] [blame] | 3341 | netif_info(tp, probe, netdev, "%s\n", DRIVER_VERSION); |
hayeswang | ac718b6 | 2013-05-02 16:01:25 +0000 | [diff] [blame] | 3342 | |
| 3343 | return 0; |
| 3344 | |
hayeswang | ac718b6 | 2013-05-02 16:01:25 +0000 | [diff] [blame] | 3345 | out1: |
hayeswang | ebc2ec48 | 2013-08-14 20:54:38 +0800 | [diff] [blame] | 3346 | usb_set_intfdata(intf, NULL); |
hayeswang | ac718b6 | 2013-05-02 16:01:25 +0000 | [diff] [blame] | 3347 | out: |
| 3348 | free_netdev(netdev); |
hayeswang | ebc2ec48 | 2013-08-14 20:54:38 +0800 | [diff] [blame] | 3349 | return ret; |
hayeswang | ac718b6 | 2013-05-02 16:01:25 +0000 | [diff] [blame] | 3350 | } |
| 3351 | |
hayeswang | ac718b6 | 2013-05-02 16:01:25 +0000 | [diff] [blame] | 3352 | static void rtl8152_disconnect(struct usb_interface *intf) |
| 3353 | { |
| 3354 | struct r8152 *tp = usb_get_intfdata(intf); |
| 3355 | |
| 3356 | usb_set_intfdata(intf, NULL); |
| 3357 | if (tp) { |
| 3358 | set_bit(RTL8152_UNPLUG, &tp->flags); |
| 3359 | tasklet_kill(&tp->tl); |
| 3360 | unregister_netdev(tp->netdev); |
hayeswang | c81229c | 2014-01-02 11:22:42 +0800 | [diff] [blame] | 3361 | tp->rtl_ops.unload(tp); |
hayeswang | ac718b6 | 2013-05-02 16:01:25 +0000 | [diff] [blame] | 3362 | free_netdev(tp->netdev); |
| 3363 | } |
| 3364 | } |
| 3365 | |
| 3366 | /* table of devices that work with this driver */ |
| 3367 | static struct usb_device_id rtl8152_table[] = { |
hayeswang | c7de7de | 2014-01-15 10:42:16 +0800 | [diff] [blame] | 3368 | {REALTEK_USB_DEVICE(VENDOR_ID_REALTEK, PRODUCT_ID_RTL8152)}, |
| 3369 | {REALTEK_USB_DEVICE(VENDOR_ID_REALTEK, PRODUCT_ID_RTL8153)}, |
| 3370 | {REALTEK_USB_DEVICE(VENDOR_ID_SAMSUNG, PRODUCT_ID_SAMSUNG)}, |
hayeswang | ac718b6 | 2013-05-02 16:01:25 +0000 | [diff] [blame] | 3371 | {} |
| 3372 | }; |
| 3373 | |
| 3374 | MODULE_DEVICE_TABLE(usb, rtl8152_table); |
| 3375 | |
| 3376 | static struct usb_driver rtl8152_driver = { |
| 3377 | .name = MODULENAME, |
hayeswang | ebc2ec48 | 2013-08-14 20:54:38 +0800 | [diff] [blame] | 3378 | .id_table = rtl8152_table, |
hayeswang | ac718b6 | 2013-05-02 16:01:25 +0000 | [diff] [blame] | 3379 | .probe = rtl8152_probe, |
| 3380 | .disconnect = rtl8152_disconnect, |
hayeswang | ac718b6 | 2013-05-02 16:01:25 +0000 | [diff] [blame] | 3381 | .suspend = rtl8152_suspend, |
hayeswang | ebc2ec48 | 2013-08-14 20:54:38 +0800 | [diff] [blame] | 3382 | .resume = rtl8152_resume, |
| 3383 | .reset_resume = rtl8152_resume, |
hayeswang | 9a4be1b | 2014-02-18 21:49:07 +0800 | [diff] [blame] | 3384 | .supports_autosuspend = 1, |
hayeswang | a634782 | 2014-02-18 21:49:10 +0800 | [diff] [blame] | 3385 | .disable_hub_initiated_lpm = 1, |
hayeswang | ac718b6 | 2013-05-02 16:01:25 +0000 | [diff] [blame] | 3386 | }; |
| 3387 | |
Sachin Kamat | b4236daa | 2013-05-16 17:48:08 +0000 | [diff] [blame] | 3388 | module_usb_driver(rtl8152_driver); |
hayeswang | ac718b6 | 2013-05-02 16:01:25 +0000 | [diff] [blame] | 3389 | |
| 3390 | MODULE_AUTHOR(DRIVER_AUTHOR); |
| 3391 | MODULE_DESCRIPTION(DRIVER_DESC); |
| 3392 | MODULE_LICENSE("GPL"); |