aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/net/usb/r8152.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/net/usb/r8152.c')
-rw-r--r--drivers/net/usb/r8152.c1124
1 files changed, 883 insertions, 241 deletions
diff --git a/drivers/net/usb/r8152.c b/drivers/net/usb/r8152.c
index adb12f349a61..18e12a3f7fc3 100644
--- a/drivers/net/usb/r8152.c
+++ b/drivers/net/usb/r8152.c
@@ -21,9 +21,10 @@
21#include <linux/list.h> 21#include <linux/list.h>
22#include <linux/ip.h> 22#include <linux/ip.h>
23#include <linux/ipv6.h> 23#include <linux/ipv6.h>
24#include <net/ip6_checksum.h>
24 25
25/* Version Information */ 26/* Version Information */
26#define DRIVER_VERSION "v1.04.0 (2014/01/15)" 27#define DRIVER_VERSION "v1.06.0 (2014/03/03)"
27#define DRIVER_AUTHOR "Realtek linux nic maintainers <nic_swsd@realtek.com>" 28#define DRIVER_AUTHOR "Realtek linux nic maintainers <nic_swsd@realtek.com>"
28#define DRIVER_DESC "Realtek RTL8152/RTL8153 Based USB Ethernet Adapters" 29#define DRIVER_DESC "Realtek RTL8152/RTL8153 Based USB Ethernet Adapters"
29#define MODULENAME "r8152" 30#define MODULENAME "r8152"
@@ -59,9 +60,11 @@
59#define PLA_TCR0 0xe610 60#define PLA_TCR0 0xe610
60#define PLA_TCR1 0xe612 61#define PLA_TCR1 0xe612
61#define PLA_TXFIFO_CTRL 0xe618 62#define PLA_TXFIFO_CTRL 0xe618
62#define PLA_RSTTELLY 0xe800 63#define PLA_RSTTALLY 0xe800
63#define PLA_CR 0xe813 64#define PLA_CR 0xe813
64#define PLA_CRWECR 0xe81c 65#define PLA_CRWECR 0xe81c
66#define PLA_CONFIG12 0xe81e /* CONFIG1, CONFIG2 */
67#define PLA_CONFIG34 0xe820 /* CONFIG3, CONFIG4 */
65#define PLA_CONFIG5 0xe822 68#define PLA_CONFIG5 0xe822
66#define PLA_PHY_PWR 0xe84c 69#define PLA_PHY_PWR 0xe84c
67#define PLA_OOB_CTRL 0xe84f 70#define PLA_OOB_CTRL 0xe84f
@@ -69,7 +72,7 @@
69#define PLA_MISC_0 0xe858 72#define PLA_MISC_0 0xe858
70#define PLA_MISC_1 0xe85a 73#define PLA_MISC_1 0xe85a
71#define PLA_OCP_GPHY_BASE 0xe86c 74#define PLA_OCP_GPHY_BASE 0xe86c
72#define PLA_TELLYCNT 0xe890 75#define PLA_TALLYCNT 0xe890
73#define PLA_SFF_STS_7 0xe8de 76#define PLA_SFF_STS_7 0xe8de
74#define PLA_PHYSTATUS 0xe908 77#define PLA_PHYSTATUS 0xe908
75#define PLA_BP_BA 0xfc26 78#define PLA_BP_BA 0xfc26
@@ -177,6 +180,9 @@
177/* PLA_TCR1 */ 180/* PLA_TCR1 */
178#define VERSION_MASK 0x7cf0 181#define VERSION_MASK 0x7cf0
179 182
183/* PLA_RSTTALLY */
184#define TALLY_RESET 0x0001
185
180/* PLA_CR */ 186/* PLA_CR */
181#define CR_RST 0x10 187#define CR_RST 0x10
182#define CR_RE 0x08 188#define CR_RE 0x08
@@ -216,7 +222,14 @@
216/* PAL_BDC_CR */ 222/* PAL_BDC_CR */
217#define ALDPS_PROXY_MODE 0x0001 223#define ALDPS_PROXY_MODE 0x0001
218 224
225/* PLA_CONFIG34 */
226#define LINK_ON_WAKE_EN 0x0010
227#define LINK_OFF_WAKE_EN 0x0008
228
219/* PLA_CONFIG5 */ 229/* PLA_CONFIG5 */
230#define BWF_EN 0x0040
231#define MWF_EN 0x0020
232#define UWF_EN 0x0010
220#define LAN_WAKE_EN 0x0002 233#define LAN_WAKE_EN 0x0002
221 234
222/* PLA_LED_FEATURE */ 235/* PLA_LED_FEATURE */
@@ -436,6 +449,9 @@ enum rtl8152_flags {
436 RTL8152_SET_RX_MODE, 449 RTL8152_SET_RX_MODE,
437 WORK_ENABLE, 450 WORK_ENABLE,
438 RTL8152_LINK_CHG, 451 RTL8152_LINK_CHG,
452 SELECTIVE_SUSPEND,
453 PHY_RESET,
454 SCHEDULE_TASKLET,
439}; 455};
440 456
441/* Define these values to match your device */ 457/* Define these values to match your device */
@@ -449,11 +465,40 @@ enum rtl8152_flags {
449#define MCU_TYPE_PLA 0x0100 465#define MCU_TYPE_PLA 0x0100
450#define MCU_TYPE_USB 0x0000 466#define MCU_TYPE_USB 0x0000
451 467
468#define REALTEK_USB_DEVICE(vend, prod) \
469 USB_DEVICE_INTERFACE_CLASS(vend, prod, USB_CLASS_VENDOR_SPEC)
470
471struct tally_counter {
472 __le64 tx_packets;
473 __le64 rx_packets;
474 __le64 tx_errors;
475 __le32 rx_errors;
476 __le16 rx_missed;
477 __le16 align_errors;
478 __le32 tx_one_collision;
479 __le32 tx_multi_collision;
480 __le64 rx_unicast;
481 __le64 rx_broadcast;
482 __le32 rx_multicast;
483 __le16 tx_aborted;
484 __le16 tx_underun;
485};
486
452struct rx_desc { 487struct rx_desc {
453 __le32 opts1; 488 __le32 opts1;
454#define RX_LEN_MASK 0x7fff 489#define RX_LEN_MASK 0x7fff
490
455 __le32 opts2; 491 __le32 opts2;
492#define RD_UDP_CS (1 << 23)
493#define RD_TCP_CS (1 << 22)
494#define RD_IPV6_CS (1 << 20)
495#define RD_IPV4_CS (1 << 19)
496
456 __le32 opts3; 497 __le32 opts3;
498#define IPF (1 << 23) /* IP checksum fail */
499#define UDPF (1 << 22) /* UDP checksum fail */
500#define TCPF (1 << 21) /* TCP checksum fail */
501
457 __le32 opts4; 502 __le32 opts4;
458 __le32 opts5; 503 __le32 opts5;
459 __le32 opts6; 504 __le32 opts6;
@@ -463,13 +508,21 @@ struct tx_desc {
463 __le32 opts1; 508 __le32 opts1;
464#define TX_FS (1 << 31) /* First segment of a packet */ 509#define TX_FS (1 << 31) /* First segment of a packet */
465#define TX_LS (1 << 30) /* Final segment of a packet */ 510#define TX_LS (1 << 30) /* Final segment of a packet */
466#define TX_LEN_MASK 0x3ffff 511#define GTSENDV4 (1 << 28)
512#define GTSENDV6 (1 << 27)
513#define GTTCPHO_SHIFT 18
514#define GTTCPHO_MAX 0x7fU
515#define TX_LEN_MAX 0x3ffffU
467 516
468 __le32 opts2; 517 __le32 opts2;
469#define UDP_CS (1 << 31) /* Calculate UDP/IP checksum */ 518#define UDP_CS (1 << 31) /* Calculate UDP/IP checksum */
470#define TCP_CS (1 << 30) /* Calculate TCP/IP checksum */ 519#define TCP_CS (1 << 30) /* Calculate TCP/IP checksum */
471#define IPV4_CS (1 << 29) /* Calculate IPv4 checksum */ 520#define IPV4_CS (1 << 29) /* Calculate IPv4 checksum */
472#define IPV6_CS (1 << 28) /* Calculate IPv6 checksum */ 521#define IPV6_CS (1 << 28) /* Calculate IPv6 checksum */
522#define MSS_SHIFT 17
523#define MSS_MAX 0x7ffU
524#define TCPHO_SHIFT 17
525#define TCPHO_MAX 0x7ffU
473}; 526};
474 527
475struct r8152; 528struct r8152;
@@ -511,11 +564,13 @@ struct r8152 {
511 void (*init)(struct r8152 *); 564 void (*init)(struct r8152 *);
512 int (*enable)(struct r8152 *); 565 int (*enable)(struct r8152 *);
513 void (*disable)(struct r8152 *); 566 void (*disable)(struct r8152 *);
567 void (*up)(struct r8152 *);
514 void (*down)(struct r8152 *); 568 void (*down)(struct r8152 *);
515 void (*unload)(struct r8152 *); 569 void (*unload)(struct r8152 *);
516 } rtl_ops; 570 } rtl_ops;
517 571
518 int intr_interval; 572 int intr_interval;
573 u32 saved_wolopts;
519 u32 msg_enable; 574 u32 msg_enable;
520 u32 tx_qlen; 575 u32 tx_qlen;
521 u16 ocp_base; 576 u16 ocp_base;
@@ -534,12 +589,21 @@ enum rtl_version {
534 RTL_VER_MAX 589 RTL_VER_MAX
535}; 590};
536 591
592enum tx_csum_stat {
593 TX_CSUM_SUCCESS = 0,
594 TX_CSUM_TSO,
595 TX_CSUM_NONE
596};
597
537/* Maximum number of multicast addresses to filter (vs. Rx-all-multicast). 598/* Maximum number of multicast addresses to filter (vs. Rx-all-multicast).
538 * The RTL chips use a 64 element hash table based on the Ethernet CRC. 599 * The RTL chips use a 64 element hash table based on the Ethernet CRC.
539 */ 600 */
540static const int multicast_filter_limit = 32; 601static const int multicast_filter_limit = 32;
541static unsigned int rx_buf_sz = 16384; 602static unsigned int rx_buf_sz = 16384;
542 603
604#define RTL_LIMITED_TSO_SIZE (rx_buf_sz - sizeof(struct tx_desc) - \
605 VLAN_ETH_HLEN - VLAN_HLEN)
606
543static 607static
544int get_registers(struct r8152 *tp, u16 value, u16 index, u16 size, void *data) 608int get_registers(struct r8152 *tp, u16 value, u16 index, u16 size, void *data)
545{ 609{
@@ -577,6 +641,7 @@ int set_registers(struct r8152 *tp, u16 value, u16 index, u16 size, void *data)
577 value, index, tmp, size, 500); 641 value, index, tmp, size, 500);
578 642
579 kfree(tmp); 643 kfree(tmp);
644
580 return ret; 645 return ret;
581} 646}
582 647
@@ -862,11 +927,21 @@ static u16 sram_read(struct r8152 *tp, u16 addr)
862static int read_mii_word(struct net_device *netdev, int phy_id, int reg) 927static int read_mii_word(struct net_device *netdev, int phy_id, int reg)
863{ 928{
864 struct r8152 *tp = netdev_priv(netdev); 929 struct r8152 *tp = netdev_priv(netdev);
930 int ret;
865 931
866 if (phy_id != R8152_PHY_ID) 932 if (phy_id != R8152_PHY_ID)
867 return -EINVAL; 933 return -EINVAL;
868 934
869 return r8152_mdio_read(tp, reg); 935 ret = usb_autopm_get_interface(tp->intf);
936 if (ret < 0)
937 goto out;
938
939 ret = r8152_mdio_read(tp, reg);
940
941 usb_autopm_put_interface(tp->intf);
942
943out:
944 return ret;
870} 945}
871 946
872static 947static
@@ -877,7 +952,12 @@ void write_mii_word(struct net_device *netdev, int phy_id, int reg, int val)
877 if (phy_id != R8152_PHY_ID) 952 if (phy_id != R8152_PHY_ID)
878 return; 953 return;
879 954
955 if (usb_autopm_get_interface(tp->intf) < 0)
956 return;
957
880 r8152_mdio_write(tp, reg, val); 958 r8152_mdio_write(tp, reg, val);
959
960 usb_autopm_put_interface(tp->intf);
881} 961}
882 962
883static 963static
@@ -886,11 +966,26 @@ int r8152_submit_rx(struct r8152 *tp, struct rx_agg *agg, gfp_t mem_flags);
886static inline void set_ethernet_addr(struct r8152 *tp) 966static inline void set_ethernet_addr(struct r8152 *tp)
887{ 967{
888 struct net_device *dev = tp->netdev; 968 struct net_device *dev = tp->netdev;
969 int ret;
889 u8 node_id[8] = {0}; 970 u8 node_id[8] = {0};
890 971
891 if (pla_ocp_read(tp, PLA_IDR, sizeof(node_id), node_id) < 0) 972 if (tp->version == RTL_VER_01)
973 ret = pla_ocp_read(tp, PLA_IDR, sizeof(node_id), node_id);
974 else
975 ret = pla_ocp_read(tp, PLA_BACKUP, sizeof(node_id), node_id);
976
977 if (ret < 0) {
892 netif_notice(tp, probe, dev, "inet addr fail\n"); 978 netif_notice(tp, probe, dev, "inet addr fail\n");
893 else { 979 } else {
980 if (tp->version != RTL_VER_01) {
981 ocp_write_byte(tp, MCU_TYPE_PLA, PLA_CRWECR,
982 CRWECR_CONFIG);
983 pla_ocp_write(tp, PLA_IDR, BYTE_EN_SIX_BYTES,
984 sizeof(node_id), node_id);
985 ocp_write_byte(tp, MCU_TYPE_PLA, PLA_CRWECR,
986 CRWECR_NORAML);
987 }
988
894 memcpy(dev->dev_addr, node_id, dev->addr_len); 989 memcpy(dev->dev_addr, node_id, dev->addr_len);
895 memcpy(dev->perm_addr, dev->dev_addr, dev->addr_len); 990 memcpy(dev->perm_addr, dev->dev_addr, dev->addr_len);
896 } 991 }
@@ -913,15 +1008,9 @@ static int rtl8152_set_mac_address(struct net_device *netdev, void *p)
913 return 0; 1008 return 0;
914} 1009}
915 1010
916static struct net_device_stats *rtl8152_get_stats(struct net_device *dev)
917{
918 return &dev->stats;
919}
920
921static void read_bulk_callback(struct urb *urb) 1011static void read_bulk_callback(struct urb *urb)
922{ 1012{
923 struct net_device *netdev; 1013 struct net_device *netdev;
924 unsigned long flags;
925 int status = urb->status; 1014 int status = urb->status;
926 struct rx_agg *agg; 1015 struct rx_agg *agg;
927 struct r8152 *tp; 1016 struct r8152 *tp;
@@ -948,14 +1037,16 @@ static void read_bulk_callback(struct urb *urb)
948 if (!netif_carrier_ok(netdev)) 1037 if (!netif_carrier_ok(netdev))
949 return; 1038 return;
950 1039
1040 usb_mark_last_busy(tp->udev);
1041
951 switch (status) { 1042 switch (status) {
952 case 0: 1043 case 0:
953 if (urb->actual_length < ETH_ZLEN) 1044 if (urb->actual_length < ETH_ZLEN)
954 break; 1045 break;
955 1046
956 spin_lock_irqsave(&tp->rx_lock, flags); 1047 spin_lock(&tp->rx_lock);
957 list_add_tail(&agg->list, &tp->rx_done); 1048 list_add_tail(&agg->list, &tp->rx_done);
958 spin_unlock_irqrestore(&tp->rx_lock, flags); 1049 spin_unlock(&tp->rx_lock);
959 tasklet_schedule(&tp->tl); 1050 tasklet_schedule(&tp->tl);
960 return; 1051 return;
961 case -ESHUTDOWN: 1052 case -ESHUTDOWN:
@@ -978,9 +1069,9 @@ static void read_bulk_callback(struct urb *urb)
978 if (result == -ENODEV) { 1069 if (result == -ENODEV) {
979 netif_device_detach(tp->netdev); 1070 netif_device_detach(tp->netdev);
980 } else if (result) { 1071 } else if (result) {
981 spin_lock_irqsave(&tp->rx_lock, flags); 1072 spin_lock(&tp->rx_lock);
982 list_add_tail(&agg->list, &tp->rx_done); 1073 list_add_tail(&agg->list, &tp->rx_done);
983 spin_unlock_irqrestore(&tp->rx_lock, flags); 1074 spin_unlock(&tp->rx_lock);
984 tasklet_schedule(&tp->tl); 1075 tasklet_schedule(&tp->tl);
985 } 1076 }
986} 1077}
@@ -988,7 +1079,7 @@ static void read_bulk_callback(struct urb *urb)
988static void write_bulk_callback(struct urb *urb) 1079static void write_bulk_callback(struct urb *urb)
989{ 1080{
990 struct net_device_stats *stats; 1081 struct net_device_stats *stats;
991 unsigned long flags; 1082 struct net_device *netdev;
992 struct tx_agg *agg; 1083 struct tx_agg *agg;
993 struct r8152 *tp; 1084 struct r8152 *tp;
994 int status = urb->status; 1085 int status = urb->status;
@@ -1001,21 +1092,24 @@ static void write_bulk_callback(struct urb *urb)
1001 if (!tp) 1092 if (!tp)
1002 return; 1093 return;
1003 1094
1004 stats = rtl8152_get_stats(tp->netdev); 1095 netdev = tp->netdev;
1096 stats = &netdev->stats;
1005 if (status) { 1097 if (status) {
1006 if (net_ratelimit()) 1098 if (net_ratelimit())
1007 netdev_warn(tp->netdev, "Tx status %d\n", status); 1099 netdev_warn(netdev, "Tx status %d\n", status);
1008 stats->tx_errors += agg->skb_num; 1100 stats->tx_errors += agg->skb_num;
1009 } else { 1101 } else {
1010 stats->tx_packets += agg->skb_num; 1102 stats->tx_packets += agg->skb_num;
1011 stats->tx_bytes += agg->skb_len; 1103 stats->tx_bytes += agg->skb_len;
1012 } 1104 }
1013 1105
1014 spin_lock_irqsave(&tp->tx_lock, flags); 1106 spin_lock(&tp->tx_lock);
1015 list_add_tail(&agg->list, &tp->tx_free); 1107 list_add_tail(&agg->list, &tp->tx_free);
1016 spin_unlock_irqrestore(&tp->tx_lock, flags); 1108 spin_unlock(&tp->tx_lock);
1017 1109
1018 if (!netif_carrier_ok(tp->netdev)) 1110 usb_autopm_put_interface_async(tp->intf);
1111
1112 if (!netif_carrier_ok(netdev))
1019 return; 1113 return;
1020 1114
1021 if (!test_bit(WORK_ENABLE, &tp->flags)) 1115 if (!test_bit(WORK_ENABLE, &tp->flags))
@@ -1220,6 +1314,9 @@ static struct tx_agg *r8152_get_tx_agg(struct r8152 *tp)
1220 struct tx_agg *agg = NULL; 1314 struct tx_agg *agg = NULL;
1221 unsigned long flags; 1315 unsigned long flags;
1222 1316
1317 if (list_empty(&tp->tx_free))
1318 return NULL;
1319
1223 spin_lock_irqsave(&tp->tx_lock, flags); 1320 spin_lock_irqsave(&tp->tx_lock, flags);
1224 if (!list_empty(&tp->tx_free)) { 1321 if (!list_empty(&tp->tx_free)) {
1225 struct list_head *cursor; 1322 struct list_head *cursor;
@@ -1233,24 +1330,138 @@ static struct tx_agg *r8152_get_tx_agg(struct r8152 *tp)
1233 return agg; 1330 return agg;
1234} 1331}
1235 1332
1236static void 1333static inline __be16 get_protocol(struct sk_buff *skb)
1237r8152_tx_csum(struct r8152 *tp, struct tx_desc *desc, struct sk_buff *skb) 1334{
1335 __be16 protocol;
1336
1337 if (skb->protocol == htons(ETH_P_8021Q))
1338 protocol = vlan_eth_hdr(skb)->h_vlan_encapsulated_proto;
1339 else
1340 protocol = skb->protocol;
1341
1342 return protocol;
1343}
1344
1345/*
1346 * r8152_csum_workaround()
1347 * The hw limites the value the transport offset. When the offset is out of the
1348 * range, calculate the checksum by sw.
1349 */
1350static void r8152_csum_workaround(struct r8152 *tp, struct sk_buff *skb,
1351 struct sk_buff_head *list)
1352{
1353 if (skb_shinfo(skb)->gso_size) {
1354 netdev_features_t features = tp->netdev->features;
1355 struct sk_buff_head seg_list;
1356 struct sk_buff *segs, *nskb;
1357
1358 features &= ~(NETIF_F_IP_CSUM | NETIF_F_SG | NETIF_F_TSO);
1359 segs = skb_gso_segment(skb, features);
1360 if (IS_ERR(segs) || !segs)
1361 goto drop;
1362
1363 __skb_queue_head_init(&seg_list);
1364
1365 do {
1366 nskb = segs;
1367 segs = segs->next;
1368 nskb->next = NULL;
1369 __skb_queue_tail(&seg_list, nskb);
1370 } while (segs);
1371
1372 skb_queue_splice(&seg_list, list);
1373 dev_kfree_skb(skb);
1374 } else if (skb->ip_summed == CHECKSUM_PARTIAL) {
1375 if (skb_checksum_help(skb) < 0)
1376 goto drop;
1377
1378 __skb_queue_head(list, skb);
1379 } else {
1380 struct net_device_stats *stats;
1381
1382drop:
1383 stats = &tp->netdev->stats;
1384 stats->tx_dropped++;
1385 dev_kfree_skb(skb);
1386 }
1387}
1388
1389/*
1390 * msdn_giant_send_check()
1391 * According to the document of microsoft, the TCP Pseudo Header excludes the
1392 * packet length for IPv6 TCP large packets.
1393 */
1394static int msdn_giant_send_check(struct sk_buff *skb)
1395{
1396 const struct ipv6hdr *ipv6h;
1397 struct tcphdr *th;
1398 int ret;
1399
1400 ret = skb_cow_head(skb, 0);
1401 if (ret)
1402 return ret;
1403
1404 ipv6h = ipv6_hdr(skb);
1405 th = tcp_hdr(skb);
1406
1407 th->check = 0;
1408 th->check = ~tcp_v6_check(0, &ipv6h->saddr, &ipv6h->daddr, 0);
1409
1410 return ret;
1411}
1412
1413static int r8152_tx_csum(struct r8152 *tp, struct tx_desc *desc,
1414 struct sk_buff *skb, u32 len, u32 transport_offset)
1238{ 1415{
1239 memset(desc, 0, sizeof(*desc)); 1416 u32 mss = skb_shinfo(skb)->gso_size;
1417 u32 opts1, opts2 = 0;
1418 int ret = TX_CSUM_SUCCESS;
1419
1420 WARN_ON_ONCE(len > TX_LEN_MAX);
1421
1422 opts1 = len | TX_FS | TX_LS;
1423
1424 if (mss) {
1425 if (transport_offset > GTTCPHO_MAX) {
1426 netif_warn(tp, tx_err, tp->netdev,
1427 "Invalid transport offset 0x%x for TSO\n",
1428 transport_offset);
1429 ret = TX_CSUM_TSO;
1430 goto unavailable;
1431 }
1240 1432
1241 desc->opts1 = cpu_to_le32((skb->len & TX_LEN_MASK) | TX_FS | TX_LS); 1433 switch (get_protocol(skb)) {
1434 case htons(ETH_P_IP):
1435 opts1 |= GTSENDV4;
1436 break;
1242 1437
1243 if (skb->ip_summed == CHECKSUM_PARTIAL) { 1438 case htons(ETH_P_IPV6):
1244 __be16 protocol; 1439 if (msdn_giant_send_check(skb)) {
1440 ret = TX_CSUM_TSO;
1441 goto unavailable;
1442 }
1443 opts1 |= GTSENDV6;
1444 break;
1445
1446 default:
1447 WARN_ON_ONCE(1);
1448 break;
1449 }
1450
1451 opts1 |= transport_offset << GTTCPHO_SHIFT;
1452 opts2 |= min(mss, MSS_MAX) << MSS_SHIFT;
1453 } else if (skb->ip_summed == CHECKSUM_PARTIAL) {
1245 u8 ip_protocol; 1454 u8 ip_protocol;
1246 u32 opts2 = 0;
1247 1455
1248 if (skb->protocol == htons(ETH_P_8021Q)) 1456 if (transport_offset > TCPHO_MAX) {
1249 protocol = vlan_eth_hdr(skb)->h_vlan_encapsulated_proto; 1457 netif_warn(tp, tx_err, tp->netdev,
1250 else 1458 "Invalid transport offset 0x%x\n",
1251 protocol = skb->protocol; 1459 transport_offset);
1460 ret = TX_CSUM_NONE;
1461 goto unavailable;
1462 }
1252 1463
1253 switch (protocol) { 1464 switch (get_protocol(skb)) {
1254 case htons(ETH_P_IP): 1465 case htons(ETH_P_IP):
1255 opts2 |= IPV4_CS; 1466 opts2 |= IPV4_CS;
1256 ip_protocol = ip_hdr(skb)->protocol; 1467 ip_protocol = ip_hdr(skb)->protocol;
@@ -1266,24 +1477,34 @@ r8152_tx_csum(struct r8152 *tp, struct tx_desc *desc, struct sk_buff *skb)
1266 break; 1477 break;
1267 } 1478 }
1268 1479
1269 if (ip_protocol == IPPROTO_TCP) { 1480 if (ip_protocol == IPPROTO_TCP)
1270 opts2 |= TCP_CS; 1481 opts2 |= TCP_CS;
1271 opts2 |= (skb_transport_offset(skb) & 0x7fff) << 17; 1482 else if (ip_protocol == IPPROTO_UDP)
1272 } else if (ip_protocol == IPPROTO_UDP) {
1273 opts2 |= UDP_CS; 1483 opts2 |= UDP_CS;
1274 } else { 1484 else
1275 WARN_ON_ONCE(1); 1485 WARN_ON_ONCE(1);
1276 }
1277 1486
1278 desc->opts2 = cpu_to_le32(opts2); 1487 opts2 |= transport_offset << TCPHO_SHIFT;
1279 } 1488 }
1489
1490 desc->opts2 = cpu_to_le32(opts2);
1491 desc->opts1 = cpu_to_le32(opts1);
1492
1493unavailable:
1494 return ret;
1280} 1495}
1281 1496
1282static int r8152_tx_agg_fill(struct r8152 *tp, struct tx_agg *agg) 1497static int r8152_tx_agg_fill(struct r8152 *tp, struct tx_agg *agg)
1283{ 1498{
1284 int remain; 1499 struct sk_buff_head skb_head, *tx_queue = &tp->tx_queue;
1500 int remain, ret;
1285 u8 *tx_data; 1501 u8 *tx_data;
1286 1502
1503 __skb_queue_head_init(&skb_head);
1504 spin_lock(&tx_queue->lock);
1505 skb_queue_splice_init(tx_queue, &skb_head);
1506 spin_unlock(&tx_queue->lock);
1507
1287 tx_data = agg->head; 1508 tx_data = agg->head;
1288 agg->skb_num = agg->skb_len = 0; 1509 agg->skb_num = agg->skb_len = 0;
1289 remain = rx_buf_sz; 1510 remain = rx_buf_sz;
@@ -1292,32 +1513,56 @@ static int r8152_tx_agg_fill(struct r8152 *tp, struct tx_agg *agg)
1292 struct tx_desc *tx_desc; 1513 struct tx_desc *tx_desc;
1293 struct sk_buff *skb; 1514 struct sk_buff *skb;
1294 unsigned int len; 1515 unsigned int len;
1516 u32 offset;
1295 1517
1296 skb = skb_dequeue(&tp->tx_queue); 1518 skb = __skb_dequeue(&skb_head);
1297 if (!skb) 1519 if (!skb)
1298 break; 1520 break;
1299 1521
1300 remain -= sizeof(*tx_desc); 1522 len = skb->len + sizeof(*tx_desc);
1301 len = skb->len; 1523
1302 if (remain < len) { 1524 if (len > remain) {
1303 skb_queue_head(&tp->tx_queue, skb); 1525 __skb_queue_head(&skb_head, skb);
1304 break; 1526 break;
1305 } 1527 }
1306 1528
1307 tx_data = tx_agg_align(tx_data); 1529 tx_data = tx_agg_align(tx_data);
1308 tx_desc = (struct tx_desc *)tx_data; 1530 tx_desc = (struct tx_desc *)tx_data;
1531
1532 offset = (u32)skb_transport_offset(skb);
1533
1534 if (r8152_tx_csum(tp, tx_desc, skb, skb->len, offset)) {
1535 r8152_csum_workaround(tp, skb, &skb_head);
1536 continue;
1537 }
1538
1309 tx_data += sizeof(*tx_desc); 1539 tx_data += sizeof(*tx_desc);
1310 1540
1311 r8152_tx_csum(tp, tx_desc, skb); 1541 len = skb->len;
1312 memcpy(tx_data, skb->data, len); 1542 if (skb_copy_bits(skb, 0, tx_data, len) < 0) {
1313 agg->skb_num++; 1543 struct net_device_stats *stats = &tp->netdev->stats;
1544
1545 stats->tx_dropped++;
1546 dev_kfree_skb_any(skb);
1547 tx_data -= sizeof(*tx_desc);
1548 continue;
1549 }
1550
1551 tx_data += len;
1314 agg->skb_len += len; 1552 agg->skb_len += len;
1553 agg->skb_num++;
1554
1315 dev_kfree_skb_any(skb); 1555 dev_kfree_skb_any(skb);
1316 1556
1317 tx_data += len;
1318 remain = rx_buf_sz - (int)(tx_agg_align(tx_data) - agg->head); 1557 remain = rx_buf_sz - (int)(tx_agg_align(tx_data) - agg->head);
1319 } 1558 }
1320 1559
1560 if (!skb_queue_empty(&skb_head)) {
1561 spin_lock(&tx_queue->lock);
1562 skb_queue_splice(&skb_head, tx_queue);
1563 spin_unlock(&tx_queue->lock);
1564 }
1565
1321 netif_tx_lock(tp->netdev); 1566 netif_tx_lock(tp->netdev);
1322 1567
1323 if (netif_queue_stopped(tp->netdev) && 1568 if (netif_queue_stopped(tp->netdev) &&
@@ -1326,20 +1571,67 @@ static int r8152_tx_agg_fill(struct r8152 *tp, struct tx_agg *agg)
1326 1571
1327 netif_tx_unlock(tp->netdev); 1572 netif_tx_unlock(tp->netdev);
1328 1573
1574 ret = usb_autopm_get_interface_async(tp->intf);
1575 if (ret < 0)
1576 goto out_tx_fill;
1577
1329 usb_fill_bulk_urb(agg->urb, tp->udev, usb_sndbulkpipe(tp->udev, 2), 1578 usb_fill_bulk_urb(agg->urb, tp->udev, usb_sndbulkpipe(tp->udev, 2),
1330 agg->head, (int)(tx_data - (u8 *)agg->head), 1579 agg->head, (int)(tx_data - (u8 *)agg->head),
1331 (usb_complete_t)write_bulk_callback, agg); 1580 (usb_complete_t)write_bulk_callback, agg);
1332 1581
1333 return usb_submit_urb(agg->urb, GFP_ATOMIC); 1582 ret = usb_submit_urb(agg->urb, GFP_ATOMIC);
1583 if (ret < 0)
1584 usb_autopm_put_interface_async(tp->intf);
1585
1586out_tx_fill:
1587 return ret;
1588}
1589
1590static u8 r8152_rx_csum(struct r8152 *tp, struct rx_desc *rx_desc)
1591{
1592 u8 checksum = CHECKSUM_NONE;
1593 u32 opts2, opts3;
1594
1595 if (tp->version == RTL_VER_01)
1596 goto return_result;
1597
1598 opts2 = le32_to_cpu(rx_desc->opts2);
1599 opts3 = le32_to_cpu(rx_desc->opts3);
1600
1601 if (opts2 & RD_IPV4_CS) {
1602 if (opts3 & IPF)
1603 checksum = CHECKSUM_NONE;
1604 else if ((opts2 & RD_UDP_CS) && (opts3 & UDPF))
1605 checksum = CHECKSUM_NONE;
1606 else if ((opts2 & RD_TCP_CS) && (opts3 & TCPF))
1607 checksum = CHECKSUM_NONE;
1608 else
1609 checksum = CHECKSUM_UNNECESSARY;
1610 } else if (RD_IPV6_CS) {
1611 if ((opts2 & RD_UDP_CS) && !(opts3 & UDPF))
1612 checksum = CHECKSUM_UNNECESSARY;
1613 else if ((opts2 & RD_TCP_CS) && !(opts3 & TCPF))
1614 checksum = CHECKSUM_UNNECESSARY;
1615 }
1616
1617return_result:
1618 return checksum;
1334} 1619}
1335 1620
1336static void rx_bottom(struct r8152 *tp) 1621static void rx_bottom(struct r8152 *tp)
1337{ 1622{
1338 unsigned long flags; 1623 unsigned long flags;
1339 struct list_head *cursor, *next; 1624 struct list_head *cursor, *next, rx_queue;
1340 1625
1626 if (list_empty(&tp->rx_done))
1627 return;
1628
1629 INIT_LIST_HEAD(&rx_queue);
1341 spin_lock_irqsave(&tp->rx_lock, flags); 1630 spin_lock_irqsave(&tp->rx_lock, flags);
1342 list_for_each_safe(cursor, next, &tp->rx_done) { 1631 list_splice_init(&tp->rx_done, &rx_queue);
1632 spin_unlock_irqrestore(&tp->rx_lock, flags);
1633
1634 list_for_each_safe(cursor, next, &rx_queue) {
1343 struct rx_desc *rx_desc; 1635 struct rx_desc *rx_desc;
1344 struct rx_agg *agg; 1636 struct rx_agg *agg;
1345 int len_used = 0; 1637 int len_used = 0;
@@ -1348,7 +1640,6 @@ static void rx_bottom(struct r8152 *tp)
1348 int ret; 1640 int ret;
1349 1641
1350 list_del_init(cursor); 1642 list_del_init(cursor);
1351 spin_unlock_irqrestore(&tp->rx_lock, flags);
1352 1643
1353 agg = list_entry(cursor, struct rx_agg, list); 1644 agg = list_entry(cursor, struct rx_agg, list);
1354 urb = agg->urb; 1645 urb = agg->urb;
@@ -1361,7 +1652,7 @@ static void rx_bottom(struct r8152 *tp)
1361 1652
1362 while (urb->actual_length > len_used) { 1653 while (urb->actual_length > len_used) {
1363 struct net_device *netdev = tp->netdev; 1654 struct net_device *netdev = tp->netdev;
1364 struct net_device_stats *stats; 1655 struct net_device_stats *stats = &netdev->stats;
1365 unsigned int pkt_len; 1656 unsigned int pkt_len;
1366 struct sk_buff *skb; 1657 struct sk_buff *skb;
1367 1658
@@ -1373,23 +1664,24 @@ static void rx_bottom(struct r8152 *tp)
1373 if (urb->actual_length < len_used) 1664 if (urb->actual_length < len_used)
1374 break; 1665 break;
1375 1666
1376 stats = rtl8152_get_stats(netdev);
1377
1378 pkt_len -= CRC_SIZE; 1667 pkt_len -= CRC_SIZE;
1379 rx_data += sizeof(struct rx_desc); 1668 rx_data += sizeof(struct rx_desc);
1380 1669
1381 skb = netdev_alloc_skb_ip_align(netdev, pkt_len); 1670 skb = netdev_alloc_skb_ip_align(netdev, pkt_len);
1382 if (!skb) { 1671 if (!skb) {
1383 stats->rx_dropped++; 1672 stats->rx_dropped++;
1384 break; 1673 goto find_next_rx;
1385 } 1674 }
1675
1676 skb->ip_summed = r8152_rx_csum(tp, rx_desc);
1386 memcpy(skb->data, rx_data, pkt_len); 1677 memcpy(skb->data, rx_data, pkt_len);
1387 skb_put(skb, pkt_len); 1678 skb_put(skb, pkt_len);
1388 skb->protocol = eth_type_trans(skb, netdev); 1679 skb->protocol = eth_type_trans(skb, netdev);
1389 netif_rx(skb); 1680 netif_receive_skb(skb);
1390 stats->rx_packets++; 1681 stats->rx_packets++;
1391 stats->rx_bytes += pkt_len; 1682 stats->rx_bytes += pkt_len;
1392 1683
1684find_next_rx:
1393 rx_data = rx_agg_align(rx_data + pkt_len + CRC_SIZE); 1685 rx_data = rx_agg_align(rx_data + pkt_len + CRC_SIZE);
1394 rx_desc = (struct rx_desc *)rx_data; 1686 rx_desc = (struct rx_desc *)rx_data;
1395 len_used = (int)(rx_data - (u8 *)agg->head); 1687 len_used = (int)(rx_data - (u8 *)agg->head);
@@ -1398,13 +1690,13 @@ static void rx_bottom(struct r8152 *tp)
1398 1690
1399submit: 1691submit:
1400 ret = r8152_submit_rx(tp, agg, GFP_ATOMIC); 1692 ret = r8152_submit_rx(tp, agg, GFP_ATOMIC);
1401 spin_lock_irqsave(&tp->rx_lock, flags);
1402 if (ret && ret != -ENODEV) { 1693 if (ret && ret != -ENODEV) {
1403 list_add_tail(&agg->list, next); 1694 spin_lock_irqsave(&tp->rx_lock, flags);
1695 list_add_tail(&agg->list, &tp->rx_done);
1696 spin_unlock_irqrestore(&tp->rx_lock, flags);
1404 tasklet_schedule(&tp->tl); 1697 tasklet_schedule(&tp->tl);
1405 } 1698 }
1406 } 1699 }
1407 spin_unlock_irqrestore(&tp->rx_lock, flags);
1408} 1700}
1409 1701
1410static void tx_bottom(struct r8152 *tp) 1702static void tx_bottom(struct r8152 *tp)
@@ -1423,19 +1715,18 @@ static void tx_bottom(struct r8152 *tp)
1423 1715
1424 res = r8152_tx_agg_fill(tp, agg); 1716 res = r8152_tx_agg_fill(tp, agg);
1425 if (res) { 1717 if (res) {
1426 struct net_device_stats *stats; 1718 struct net_device *netdev = tp->netdev;
1427 struct net_device *netdev;
1428 unsigned long flags;
1429
1430 netdev = tp->netdev;
1431 stats = rtl8152_get_stats(netdev);
1432 1719
1433 if (res == -ENODEV) { 1720 if (res == -ENODEV) {
1434 netif_device_detach(netdev); 1721 netif_device_detach(netdev);
1435 } else { 1722 } else {
1723 struct net_device_stats *stats = &netdev->stats;
1724 unsigned long flags;
1725
1436 netif_warn(tp, tx_err, netdev, 1726 netif_warn(tp, tx_err, netdev,
1437 "failed tx_urb %d\n", res); 1727 "failed tx_urb %d\n", res);
1438 stats->tx_dropped += agg->skb_num; 1728 stats->tx_dropped += agg->skb_num;
1729
1439 spin_lock_irqsave(&tp->tx_lock, flags); 1730 spin_lock_irqsave(&tp->tx_lock, flags);
1440 list_add_tail(&agg->list, &tp->tx_free); 1731 list_add_tail(&agg->list, &tp->tx_free);
1441 spin_unlock_irqrestore(&tp->tx_lock, flags); 1732 spin_unlock_irqrestore(&tp->tx_lock, flags);
@@ -1475,6 +1766,26 @@ int r8152_submit_rx(struct r8152 *tp, struct rx_agg *agg, gfp_t mem_flags)
1475 return usb_submit_urb(agg->urb, mem_flags); 1766 return usb_submit_urb(agg->urb, mem_flags);
1476} 1767}
1477 1768
1769static void rtl_drop_queued_tx(struct r8152 *tp)
1770{
1771 struct net_device_stats *stats = &tp->netdev->stats;
1772 struct sk_buff_head skb_head, *tx_queue = &tp->tx_queue;
1773 struct sk_buff *skb;
1774
1775 if (skb_queue_empty(tx_queue))
1776 return;
1777
1778 __skb_queue_head_init(&skb_head);
1779 spin_lock_bh(&tx_queue->lock);
1780 skb_queue_splice_init(tx_queue, &skb_head);
1781 spin_unlock_bh(&tx_queue->lock);
1782
1783 while ((skb = __skb_dequeue(&skb_head))) {
1784 dev_kfree_skb(skb);
1785 stats->tx_dropped++;
1786 }
1787}
1788
1478static void rtl8152_tx_timeout(struct net_device *netdev) 1789static void rtl8152_tx_timeout(struct net_device *netdev)
1479{ 1790{
1480 struct r8152 *tp = netdev_priv(netdev); 1791 struct r8152 *tp = netdev_priv(netdev);
@@ -1538,7 +1849,7 @@ static void _rtl8152_set_rx_mode(struct net_device *netdev)
1538} 1849}
1539 1850
1540static netdev_tx_t rtl8152_start_xmit(struct sk_buff *skb, 1851static netdev_tx_t rtl8152_start_xmit(struct sk_buff *skb,
1541 struct net_device *netdev) 1852 struct net_device *netdev)
1542{ 1853{
1543 struct r8152 *tp = netdev_priv(netdev); 1854 struct r8152 *tp = netdev_priv(netdev);
1544 1855
@@ -1546,13 +1857,17 @@ static netdev_tx_t rtl8152_start_xmit(struct sk_buff *skb,
1546 1857
1547 skb_queue_tail(&tp->tx_queue, skb); 1858 skb_queue_tail(&tp->tx_queue, skb);
1548 1859
1549 if (list_empty(&tp->tx_free) && 1860 if (!list_empty(&tp->tx_free)) {
1550 skb_queue_len(&tp->tx_queue) > tp->tx_qlen) 1861 if (test_bit(SELECTIVE_SUSPEND, &tp->flags)) {
1862 set_bit(SCHEDULE_TASKLET, &tp->flags);
1863 schedule_delayed_work(&tp->schedule, 0);
1864 } else {
1865 usb_mark_last_busy(tp->udev);
1866 tasklet_schedule(&tp->tl);
1867 }
1868 } else if (skb_queue_len(&tp->tx_queue) > tp->tx_qlen)
1551 netif_stop_queue(netdev); 1869 netif_stop_queue(netdev);
1552 1870
1553 if (!list_empty(&tp->tx_free))
1554 tasklet_schedule(&tp->tl);
1555
1556 return NETDEV_TX_OK; 1871 return NETDEV_TX_OK;
1557} 1872}
1558 1873
@@ -1610,6 +1925,18 @@ static void rtl_set_eee_plus(struct r8152 *tp)
1610 } 1925 }
1611} 1926}
1612 1927
1928static void rxdy_gated_en(struct r8152 *tp, bool enable)
1929{
1930 u32 ocp_data;
1931
1932 ocp_data = ocp_read_word(tp, MCU_TYPE_PLA, PLA_MISC_1);
1933 if (enable)
1934 ocp_data |= RXDY_GATED_EN;
1935 else
1936 ocp_data &= ~RXDY_GATED_EN;
1937 ocp_write_word(tp, MCU_TYPE_PLA, PLA_MISC_1, ocp_data);
1938}
1939
1613static int rtl_enable(struct r8152 *tp) 1940static int rtl_enable(struct r8152 *tp)
1614{ 1941{
1615 u32 ocp_data; 1942 u32 ocp_data;
@@ -1621,9 +1948,7 @@ static int rtl_enable(struct r8152 *tp)
1621 ocp_data |= CR_RE | CR_TE; 1948 ocp_data |= CR_RE | CR_TE;
1622 ocp_write_byte(tp, MCU_TYPE_PLA, PLA_CR, ocp_data); 1949 ocp_write_byte(tp, MCU_TYPE_PLA, PLA_CR, ocp_data);
1623 1950
1624 ocp_data = ocp_read_word(tp, MCU_TYPE_PLA, PLA_MISC_1); 1951 rxdy_gated_en(tp, false);
1625 ocp_data &= ~RXDY_GATED_EN;
1626 ocp_write_word(tp, MCU_TYPE_PLA, PLA_MISC_1, ocp_data);
1627 1952
1628 INIT_LIST_HEAD(&tp->rx_done); 1953 INIT_LIST_HEAD(&tp->rx_done);
1629 ret = 0; 1954 ret = 0;
@@ -1678,8 +2003,6 @@ static int rtl8153_enable(struct r8152 *tp)
1678 2003
1679static void rtl8152_disable(struct r8152 *tp) 2004static void rtl8152_disable(struct r8152 *tp)
1680{ 2005{
1681 struct net_device_stats *stats = rtl8152_get_stats(tp->netdev);
1682 struct sk_buff *skb;
1683 u32 ocp_data; 2006 u32 ocp_data;
1684 int i; 2007 int i;
1685 2008
@@ -1687,17 +2010,12 @@ static void rtl8152_disable(struct r8152 *tp)
1687 ocp_data &= ~RCR_ACPT_ALL; 2010 ocp_data &= ~RCR_ACPT_ALL;
1688 ocp_write_dword(tp, MCU_TYPE_PLA, PLA_RCR, ocp_data); 2011 ocp_write_dword(tp, MCU_TYPE_PLA, PLA_RCR, ocp_data);
1689 2012
1690 while ((skb = skb_dequeue(&tp->tx_queue))) { 2013 rtl_drop_queued_tx(tp);
1691 dev_kfree_skb(skb);
1692 stats->tx_dropped++;
1693 }
1694 2014
1695 for (i = 0; i < RTL8152_MAX_TX; i++) 2015 for (i = 0; i < RTL8152_MAX_TX; i++)
1696 usb_kill_urb(tp->tx_info[i].urb); 2016 usb_kill_urb(tp->tx_info[i].urb);
1697 2017
1698 ocp_data = ocp_read_word(tp, MCU_TYPE_PLA, PLA_MISC_1); 2018 rxdy_gated_en(tp, true);
1699 ocp_data |= RXDY_GATED_EN;
1700 ocp_write_word(tp, MCU_TYPE_PLA, PLA_MISC_1, ocp_data);
1701 2019
1702 for (i = 0; i < 1000; i++) { 2020 for (i = 0; i < 1000; i++) {
1703 ocp_data = ocp_read_byte(tp, MCU_TYPE_PLA, PLA_OOB_CTRL); 2021 ocp_data = ocp_read_byte(tp, MCU_TYPE_PLA, PLA_OOB_CTRL);
@@ -1718,18 +2036,209 @@ static void rtl8152_disable(struct r8152 *tp)
1718 rtl8152_nic_reset(tp); 2036 rtl8152_nic_reset(tp);
1719} 2037}
1720 2038
2039static void r8152_power_cut_en(struct r8152 *tp, bool enable)
2040{
2041 u32 ocp_data;
2042
2043 ocp_data = ocp_read_word(tp, MCU_TYPE_USB, USB_UPS_CTRL);
2044 if (enable)
2045 ocp_data |= POWER_CUT;
2046 else
2047 ocp_data &= ~POWER_CUT;
2048 ocp_write_word(tp, MCU_TYPE_USB, USB_UPS_CTRL, ocp_data);
2049
2050 ocp_data = ocp_read_word(tp, MCU_TYPE_USB, USB_PM_CTRL_STATUS);
2051 ocp_data &= ~RESUME_INDICATE;
2052 ocp_write_word(tp, MCU_TYPE_USB, USB_PM_CTRL_STATUS, ocp_data);
2053}
2054
2055#define WAKE_ANY (WAKE_PHY | WAKE_MAGIC | WAKE_UCAST | WAKE_BCAST | WAKE_MCAST)
2056
2057static u32 __rtl_get_wol(struct r8152 *tp)
2058{
2059 u32 ocp_data;
2060 u32 wolopts = 0;
2061
2062 ocp_data = ocp_read_byte(tp, MCU_TYPE_PLA, PLA_CONFIG5);
2063 if (!(ocp_data & LAN_WAKE_EN))
2064 return 0;
2065
2066 ocp_data = ocp_read_word(tp, MCU_TYPE_PLA, PLA_CONFIG34);
2067 if (ocp_data & LINK_ON_WAKE_EN)
2068 wolopts |= WAKE_PHY;
2069
2070 ocp_data = ocp_read_word(tp, MCU_TYPE_PLA, PLA_CONFIG5);
2071 if (ocp_data & UWF_EN)
2072 wolopts |= WAKE_UCAST;
2073 if (ocp_data & BWF_EN)
2074 wolopts |= WAKE_BCAST;
2075 if (ocp_data & MWF_EN)
2076 wolopts |= WAKE_MCAST;
2077
2078 ocp_data = ocp_read_word(tp, MCU_TYPE_PLA, PLA_CFG_WOL);
2079 if (ocp_data & MAGIC_EN)
2080 wolopts |= WAKE_MAGIC;
2081
2082 return wolopts;
2083}
2084
2085static void __rtl_set_wol(struct r8152 *tp, u32 wolopts)
2086{
2087 u32 ocp_data;
2088
2089 ocp_write_byte(tp, MCU_TYPE_PLA, PLA_CRWECR, CRWECR_CONFIG);
2090
2091 ocp_data = ocp_read_word(tp, MCU_TYPE_PLA, PLA_CONFIG34);
2092 ocp_data &= ~LINK_ON_WAKE_EN;
2093 if (wolopts & WAKE_PHY)
2094 ocp_data |= LINK_ON_WAKE_EN;
2095 ocp_write_word(tp, MCU_TYPE_PLA, PLA_CONFIG34, ocp_data);
2096
2097 ocp_data = ocp_read_word(tp, MCU_TYPE_PLA, PLA_CONFIG5);
2098 ocp_data &= ~(UWF_EN | BWF_EN | MWF_EN | LAN_WAKE_EN);
2099 if (wolopts & WAKE_UCAST)
2100 ocp_data |= UWF_EN;
2101 if (wolopts & WAKE_BCAST)
2102 ocp_data |= BWF_EN;
2103 if (wolopts & WAKE_MCAST)
2104 ocp_data |= MWF_EN;
2105 if (wolopts & WAKE_ANY)
2106 ocp_data |= LAN_WAKE_EN;
2107 ocp_write_word(tp, MCU_TYPE_PLA, PLA_CONFIG5, ocp_data);
2108
2109 ocp_write_byte(tp, MCU_TYPE_PLA, PLA_CRWECR, CRWECR_NORAML);
2110
2111 ocp_data = ocp_read_word(tp, MCU_TYPE_PLA, PLA_CFG_WOL);
2112 ocp_data &= ~MAGIC_EN;
2113 if (wolopts & WAKE_MAGIC)
2114 ocp_data |= MAGIC_EN;
2115 ocp_write_word(tp, MCU_TYPE_PLA, PLA_CFG_WOL, ocp_data);
2116
2117 if (wolopts & WAKE_ANY)
2118 device_set_wakeup_enable(&tp->udev->dev, true);
2119 else
2120 device_set_wakeup_enable(&tp->udev->dev, false);
2121}
2122
2123static void rtl_runtime_suspend_enable(struct r8152 *tp, bool enable)
2124{
2125 if (enable) {
2126 u32 ocp_data;
2127
2128 __rtl_set_wol(tp, WAKE_ANY);
2129
2130 ocp_write_byte(tp, MCU_TYPE_PLA, PLA_CRWECR, CRWECR_CONFIG);
2131
2132 ocp_data = ocp_read_word(tp, MCU_TYPE_PLA, PLA_CONFIG34);
2133 ocp_data |= LINK_OFF_WAKE_EN;
2134 ocp_write_word(tp, MCU_TYPE_PLA, PLA_CONFIG34, ocp_data);
2135
2136 ocp_write_byte(tp, MCU_TYPE_PLA, PLA_CRWECR, CRWECR_NORAML);
2137 } else {
2138 __rtl_set_wol(tp, tp->saved_wolopts);
2139 }
2140}
2141
2142static void rtl_phy_reset(struct r8152 *tp)
2143{
2144 u16 data;
2145 int i;
2146
2147 clear_bit(PHY_RESET, &tp->flags);
2148
2149 data = r8152_mdio_read(tp, MII_BMCR);
2150
2151 /* don't reset again before the previous one complete */
2152 if (data & BMCR_RESET)
2153 return;
2154
2155 data |= BMCR_RESET;
2156 r8152_mdio_write(tp, MII_BMCR, data);
2157
2158 for (i = 0; i < 50; i++) {
2159 msleep(20);
2160 if ((r8152_mdio_read(tp, MII_BMCR) & BMCR_RESET) == 0)
2161 break;
2162 }
2163}
2164
2165static void rtl_clear_bp(struct r8152 *tp)
2166{
2167 ocp_write_dword(tp, MCU_TYPE_PLA, PLA_BP_0, 0);
2168 ocp_write_dword(tp, MCU_TYPE_PLA, PLA_BP_2, 0);
2169 ocp_write_dword(tp, MCU_TYPE_PLA, PLA_BP_4, 0);
2170 ocp_write_dword(tp, MCU_TYPE_PLA, PLA_BP_6, 0);
2171 ocp_write_dword(tp, MCU_TYPE_USB, USB_BP_0, 0);
2172 ocp_write_dword(tp, MCU_TYPE_USB, USB_BP_2, 0);
2173 ocp_write_dword(tp, MCU_TYPE_USB, USB_BP_4, 0);
2174 ocp_write_dword(tp, MCU_TYPE_USB, USB_BP_6, 0);
2175 mdelay(3);
2176 ocp_write_word(tp, MCU_TYPE_PLA, PLA_BP_BA, 0);
2177 ocp_write_word(tp, MCU_TYPE_USB, USB_BP_BA, 0);
2178}
2179
2180static void r8153_clear_bp(struct r8152 *tp)
2181{
2182 ocp_write_byte(tp, MCU_TYPE_PLA, PLA_BP_EN, 0);
2183 ocp_write_byte(tp, MCU_TYPE_USB, USB_BP_EN, 0);
2184 rtl_clear_bp(tp);
2185}
2186
2187static void r8153_teredo_off(struct r8152 *tp)
2188{
2189 u32 ocp_data;
2190
2191 ocp_data = ocp_read_word(tp, MCU_TYPE_PLA, PLA_TEREDO_CFG);
2192 ocp_data &= ~(TEREDO_SEL | TEREDO_RS_EVENT_MASK | OOB_TEREDO_EN);
2193 ocp_write_word(tp, MCU_TYPE_PLA, PLA_TEREDO_CFG, ocp_data);
2194
2195 ocp_write_word(tp, MCU_TYPE_PLA, PLA_WDT6_CTRL, WDT6_SET_MODE);
2196 ocp_write_word(tp, MCU_TYPE_PLA, PLA_REALWOW_TIMER, 0);
2197 ocp_write_dword(tp, MCU_TYPE_PLA, PLA_TEREDO_TIMER, 0);
2198}
2199
2200static void r8152b_disable_aldps(struct r8152 *tp)
2201{
2202 ocp_reg_write(tp, OCP_ALDPS_CONFIG, ENPDNPS | LINKENA | DIS_SDSAVE);
2203 msleep(20);
2204}
2205
2206static inline void r8152b_enable_aldps(struct r8152 *tp)
2207{
2208 ocp_reg_write(tp, OCP_ALDPS_CONFIG, ENPWRSAVE | ENPDNPS |
2209 LINKENA | DIS_SDSAVE);
2210}
2211
2212static void r8152b_hw_phy_cfg(struct r8152 *tp)
2213{
2214 u16 data;
2215
2216 data = r8152_mdio_read(tp, MII_BMCR);
2217 if (data & BMCR_PDOWN) {
2218 data &= ~BMCR_PDOWN;
2219 r8152_mdio_write(tp, MII_BMCR, data);
2220 }
2221
2222 r8152b_disable_aldps(tp);
2223
2224 rtl_clear_bp(tp);
2225
2226 r8152b_enable_aldps(tp);
2227 set_bit(PHY_RESET, &tp->flags);
2228}
2229
1721static void r8152b_exit_oob(struct r8152 *tp) 2230static void r8152b_exit_oob(struct r8152 *tp)
1722{ 2231{
1723 u32 ocp_data; 2232 u32 ocp_data;
1724 int i; 2233 int i;
1725 2234
1726 ocp_data = ocp_read_dword(tp, MCU_TYPE_PLA, PLA_RCR); 2235 ocp_data = ocp_read_dword(tp, MCU_TYPE_PLA, PLA_RCR);
1727 ocp_data &= ~RCR_ACPT_ALL; 2236 ocp_data &= ~RCR_ACPT_ALL;
1728 ocp_write_dword(tp, MCU_TYPE_PLA, PLA_RCR, ocp_data); 2237 ocp_write_dword(tp, MCU_TYPE_PLA, PLA_RCR, ocp_data);
1729 2238
1730 ocp_data = ocp_read_word(tp, MCU_TYPE_PLA, PLA_MISC_1); 2239 rxdy_gated_en(tp, true);
1731 ocp_data |= RXDY_GATED_EN; 2240 r8153_teredo_off(tp);
1732 ocp_write_word(tp, MCU_TYPE_PLA, PLA_MISC_1, ocp_data); 2241 r8152b_hw_phy_cfg(tp);
1733 2242
1734 ocp_write_byte(tp, MCU_TYPE_PLA, PLA_CRWECR, CRWECR_NORAML); 2243 ocp_write_byte(tp, MCU_TYPE_PLA, PLA_CRWECR, CRWECR_NORAML);
1735 ocp_write_byte(tp, MCU_TYPE_PLA, PLA_CR, 0x00); 2244 ocp_write_byte(tp, MCU_TYPE_PLA, PLA_CR, 0x00);
@@ -1835,10 +2344,6 @@ static void r8152b_enter_oob(struct r8152 *tp)
1835 2344
1836 ocp_write_word(tp, MCU_TYPE_PLA, PLA_RMS, RTL8152_RMS); 2345 ocp_write_word(tp, MCU_TYPE_PLA, PLA_RMS, RTL8152_RMS);
1837 2346
1838 ocp_data = ocp_read_word(tp, MCU_TYPE_PLA, PLA_CFG_WOL);
1839 ocp_data |= MAGIC_EN;
1840 ocp_write_word(tp, MCU_TYPE_PLA, PLA_CFG_WOL, ocp_data);
1841
1842 ocp_data = ocp_read_word(tp, MCU_TYPE_PLA, PLA_CPCR); 2347 ocp_data = ocp_read_word(tp, MCU_TYPE_PLA, PLA_CPCR);
1843 ocp_data |= CPCR_RX_VLAN; 2348 ocp_data |= CPCR_RX_VLAN;
1844 ocp_write_word(tp, MCU_TYPE_PLA, PLA_CPCR, ocp_data); 2349 ocp_write_word(tp, MCU_TYPE_PLA, PLA_CPCR, ocp_data);
@@ -1851,36 +2356,26 @@ static void r8152b_enter_oob(struct r8152 *tp)
1851 ocp_data |= NOW_IS_OOB | DIS_MCU_CLROOB; 2356 ocp_data |= NOW_IS_OOB | DIS_MCU_CLROOB;
1852 ocp_write_byte(tp, MCU_TYPE_PLA, PLA_OOB_CTRL, ocp_data); 2357 ocp_write_byte(tp, MCU_TYPE_PLA, PLA_OOB_CTRL, ocp_data);
1853 2358
1854 ocp_write_byte(tp, MCU_TYPE_PLA, PLA_CONFIG5, LAN_WAKE_EN); 2359 rxdy_gated_en(tp, false);
1855
1856 ocp_data = ocp_read_word(tp, MCU_TYPE_PLA, PLA_MISC_1);
1857 ocp_data &= ~RXDY_GATED_EN;
1858 ocp_write_word(tp, MCU_TYPE_PLA, PLA_MISC_1, ocp_data);
1859 2360
1860 ocp_data = ocp_read_dword(tp, MCU_TYPE_PLA, PLA_RCR); 2361 ocp_data = ocp_read_dword(tp, MCU_TYPE_PLA, PLA_RCR);
1861 ocp_data |= RCR_APM | RCR_AM | RCR_AB; 2362 ocp_data |= RCR_APM | RCR_AM | RCR_AB;
1862 ocp_write_dword(tp, MCU_TYPE_PLA, PLA_RCR, ocp_data); 2363 ocp_write_dword(tp, MCU_TYPE_PLA, PLA_RCR, ocp_data);
1863} 2364}
1864 2365
1865static void r8152b_disable_aldps(struct r8152 *tp)
1866{
1867 ocp_reg_write(tp, OCP_ALDPS_CONFIG, ENPDNPS | LINKENA | DIS_SDSAVE);
1868 msleep(20);
1869}
1870
1871static inline void r8152b_enable_aldps(struct r8152 *tp)
1872{
1873 ocp_reg_write(tp, OCP_ALDPS_CONFIG, ENPWRSAVE | ENPDNPS |
1874 LINKENA | DIS_SDSAVE);
1875}
1876
1877static void r8153_hw_phy_cfg(struct r8152 *tp) 2366static void r8153_hw_phy_cfg(struct r8152 *tp)
1878{ 2367{
1879 u32 ocp_data; 2368 u32 ocp_data;
1880 u16 data; 2369 u16 data;
1881 2370
1882 ocp_reg_write(tp, OCP_ADC_CFG, CKADSEL_L | ADC_EN | EN_EMI_L); 2371 ocp_reg_write(tp, OCP_ADC_CFG, CKADSEL_L | ADC_EN | EN_EMI_L);
1883 r8152_mdio_write(tp, MII_BMCR, BMCR_ANENABLE); 2372 data = r8152_mdio_read(tp, MII_BMCR);
2373 if (data & BMCR_PDOWN) {
2374 data &= ~BMCR_PDOWN;
2375 r8152_mdio_write(tp, MII_BMCR, data);
2376 }
2377
2378 r8153_clear_bp(tp);
1884 2379
1885 if (tp->version == RTL_VER_03) { 2380 if (tp->version == RTL_VER_03) {
1886 data = ocp_reg_read(tp, OCP_EEE_CFG); 2381 data = ocp_reg_read(tp, OCP_EEE_CFG);
@@ -1916,9 +2411,11 @@ static void r8153_hw_phy_cfg(struct r8152 *tp)
1916 data = sram_read(tp, SRAM_10M_AMP2); 2411 data = sram_read(tp, SRAM_10M_AMP2);
1917 data |= AMP_DN; 2412 data |= AMP_DN;
1918 sram_write(tp, SRAM_10M_AMP2, data); 2413 sram_write(tp, SRAM_10M_AMP2, data);
2414
2415 set_bit(PHY_RESET, &tp->flags);
1919} 2416}
1920 2417
1921static void r8153_u1u2en(struct r8152 *tp, int enable) 2418static void r8153_u1u2en(struct r8152 *tp, bool enable)
1922{ 2419{
1923 u8 u1u2[8]; 2420 u8 u1u2[8];
1924 2421
@@ -1930,7 +2427,7 @@ static void r8153_u1u2en(struct r8152 *tp, int enable)
1930 usb_ocp_write(tp, USB_TOLERANCE, BYTE_EN_SIX_BYTES, sizeof(u1u2), u1u2); 2427 usb_ocp_write(tp, USB_TOLERANCE, BYTE_EN_SIX_BYTES, sizeof(u1u2), u1u2);
1931} 2428}
1932 2429
1933static void r8153_u2p3en(struct r8152 *tp, int enable) 2430static void r8153_u2p3en(struct r8152 *tp, bool enable)
1934{ 2431{
1935 u32 ocp_data; 2432 u32 ocp_data;
1936 2433
@@ -1942,7 +2439,7 @@ static void r8153_u2p3en(struct r8152 *tp, int enable)
1942 ocp_write_word(tp, MCU_TYPE_USB, USB_U2P3_CTRL, ocp_data); 2439 ocp_write_word(tp, MCU_TYPE_USB, USB_U2P3_CTRL, ocp_data);
1943} 2440}
1944 2441
1945static void r8153_power_cut_en(struct r8152 *tp, int enable) 2442static void r8153_power_cut_en(struct r8152 *tp, bool enable)
1946{ 2443{
1947 u32 ocp_data; 2444 u32 ocp_data;
1948 2445
@@ -1958,28 +2455,12 @@ static void r8153_power_cut_en(struct r8152 *tp, int enable)
1958 ocp_write_word(tp, MCU_TYPE_USB, USB_MISC_0, ocp_data); 2455 ocp_write_word(tp, MCU_TYPE_USB, USB_MISC_0, ocp_data);
1959} 2456}
1960 2457
1961static void r8153_teredo_off(struct r8152 *tp)
1962{
1963 u32 ocp_data;
1964
1965 ocp_data = ocp_read_word(tp, MCU_TYPE_PLA, PLA_TEREDO_CFG);
1966 ocp_data &= ~(TEREDO_SEL | TEREDO_RS_EVENT_MASK | OOB_TEREDO_EN);
1967 ocp_write_word(tp, MCU_TYPE_PLA, PLA_TEREDO_CFG, ocp_data);
1968
1969 ocp_write_word(tp, MCU_TYPE_PLA, PLA_WDT6_CTRL, WDT6_SET_MODE);
1970 ocp_write_word(tp, MCU_TYPE_PLA, PLA_REALWOW_TIMER, 0);
1971 ocp_write_dword(tp, MCU_TYPE_PLA, PLA_TEREDO_TIMER, 0);
1972}
1973
1974static void r8153_first_init(struct r8152 *tp) 2458static void r8153_first_init(struct r8152 *tp)
1975{ 2459{
1976 u32 ocp_data; 2460 u32 ocp_data;
1977 int i; 2461 int i;
1978 2462
1979 ocp_data = ocp_read_word(tp, MCU_TYPE_PLA, PLA_MISC_1); 2463 rxdy_gated_en(tp, true);
1980 ocp_data |= RXDY_GATED_EN;
1981 ocp_write_word(tp, MCU_TYPE_PLA, PLA_MISC_1, ocp_data);
1982
1983 r8153_teredo_off(tp); 2464 r8153_teredo_off(tp);
1984 2465
1985 ocp_data = ocp_read_dword(tp, MCU_TYPE_PLA, PLA_RCR); 2466 ocp_data = ocp_read_dword(tp, MCU_TYPE_PLA, PLA_RCR);
@@ -2072,10 +2553,6 @@ static void r8153_enter_oob(struct r8152 *tp)
2072 2553
2073 ocp_write_word(tp, MCU_TYPE_PLA, PLA_RMS, RTL8152_RMS); 2554 ocp_write_word(tp, MCU_TYPE_PLA, PLA_RMS, RTL8152_RMS);
2074 2555
2075 ocp_data = ocp_read_word(tp, MCU_TYPE_PLA, PLA_CFG_WOL);
2076 ocp_data |= MAGIC_EN;
2077 ocp_write_word(tp, MCU_TYPE_PLA, PLA_CFG_WOL, ocp_data);
2078
2079 ocp_data = ocp_read_word(tp, MCU_TYPE_PLA, PLA_TEREDO_CFG); 2556 ocp_data = ocp_read_word(tp, MCU_TYPE_PLA, PLA_TEREDO_CFG);
2080 ocp_data &= ~TEREDO_WAKE_MASK; 2557 ocp_data &= ~TEREDO_WAKE_MASK;
2081 ocp_write_word(tp, MCU_TYPE_PLA, PLA_TEREDO_CFG, ocp_data); 2558 ocp_write_word(tp, MCU_TYPE_PLA, PLA_TEREDO_CFG, ocp_data);
@@ -2092,11 +2569,7 @@ static void r8153_enter_oob(struct r8152 *tp)
2092 ocp_data |= NOW_IS_OOB | DIS_MCU_CLROOB; 2569 ocp_data |= NOW_IS_OOB | DIS_MCU_CLROOB;
2093 ocp_write_byte(tp, MCU_TYPE_PLA, PLA_OOB_CTRL, ocp_data); 2570 ocp_write_byte(tp, MCU_TYPE_PLA, PLA_OOB_CTRL, ocp_data);
2094 2571
2095 ocp_write_byte(tp, MCU_TYPE_PLA, PLA_CONFIG5, LAN_WAKE_EN); 2572 rxdy_gated_en(tp, false);
2096
2097 ocp_data = ocp_read_word(tp, MCU_TYPE_PLA, PLA_MISC_1);
2098 ocp_data &= ~RXDY_GATED_EN;
2099 ocp_write_word(tp, MCU_TYPE_PLA, PLA_MISC_1, ocp_data);
2100 2573
2101 ocp_data = ocp_read_dword(tp, MCU_TYPE_PLA, PLA_RCR); 2574 ocp_data = ocp_read_dword(tp, MCU_TYPE_PLA, PLA_RCR);
2102 ocp_data |= RCR_APM | RCR_AM | RCR_AB; 2575 ocp_data |= RCR_APM | RCR_AM | RCR_AB;
@@ -2187,12 +2660,26 @@ static int rtl8152_set_speed(struct r8152 *tp, u8 autoneg, u16 speed, u8 duplex)
2187 bmcr = BMCR_ANENABLE | BMCR_ANRESTART; 2660 bmcr = BMCR_ANENABLE | BMCR_ANRESTART;
2188 } 2661 }
2189 2662
2663 if (test_bit(PHY_RESET, &tp->flags))
2664 bmcr |= BMCR_RESET;
2665
2190 if (tp->mii.supports_gmii) 2666 if (tp->mii.supports_gmii)
2191 r8152_mdio_write(tp, MII_CTRL1000, gbcr); 2667 r8152_mdio_write(tp, MII_CTRL1000, gbcr);
2192 2668
2193 r8152_mdio_write(tp, MII_ADVERTISE, anar); 2669 r8152_mdio_write(tp, MII_ADVERTISE, anar);
2194 r8152_mdio_write(tp, MII_BMCR, bmcr); 2670 r8152_mdio_write(tp, MII_BMCR, bmcr);
2195 2671
2672 if (test_bit(PHY_RESET, &tp->flags)) {
2673 int i;
2674
2675 clear_bit(PHY_RESET, &tp->flags);
2676 for (i = 0; i < 50; i++) {
2677 msleep(20);
2678 if ((r8152_mdio_read(tp, MII_BMCR) & BMCR_RESET) == 0)
2679 break;
2680 }
2681 }
2682
2196out: 2683out:
2197 2684
2198 return ret; 2685 return ret;
@@ -2200,12 +2687,7 @@ out:
2200 2687
2201static void rtl8152_down(struct r8152 *tp) 2688static void rtl8152_down(struct r8152 *tp)
2202{ 2689{
2203 u32 ocp_data; 2690 r8152_power_cut_en(tp, false);
2204
2205 ocp_data = ocp_read_word(tp, MCU_TYPE_USB, USB_UPS_CTRL);
2206 ocp_data &= ~POWER_CUT;
2207 ocp_write_word(tp, MCU_TYPE_USB, USB_UPS_CTRL, ocp_data);
2208
2209 r8152b_disable_aldps(tp); 2691 r8152b_disable_aldps(tp);
2210 r8152b_enter_oob(tp); 2692 r8152b_enter_oob(tp);
2211 r8152b_enable_aldps(tp); 2693 r8152b_enable_aldps(tp);
@@ -2213,8 +2695,8 @@ static void rtl8152_down(struct r8152 *tp)
2213 2695
2214static void rtl8153_down(struct r8152 *tp) 2696static void rtl8153_down(struct r8152 *tp)
2215{ 2697{
2216 r8153_u1u2en(tp, 0); 2698 r8153_u1u2en(tp, false);
2217 r8153_power_cut_en(tp, 0); 2699 r8153_power_cut_en(tp, false);
2218 r8153_disable_aldps(tp); 2700 r8153_disable_aldps(tp);
2219 r8153_enter_oob(tp); 2701 r8153_enter_oob(tp);
2220 r8153_enable_aldps(tp); 2702 r8153_enable_aldps(tp);
@@ -2249,6 +2731,9 @@ static void rtl_work_func_t(struct work_struct *work)
2249{ 2731{
2250 struct r8152 *tp = container_of(work, struct r8152, schedule.work); 2732 struct r8152 *tp = container_of(work, struct r8152, schedule.work);
2251 2733
2734 if (usb_autopm_get_interface(tp->intf) < 0)
2735 return;
2736
2252 if (!test_bit(WORK_ENABLE, &tp->flags)) 2737 if (!test_bit(WORK_ENABLE, &tp->flags))
2253 goto out1; 2738 goto out1;
2254 2739
@@ -2261,8 +2746,17 @@ static void rtl_work_func_t(struct work_struct *work)
2261 if (test_bit(RTL8152_SET_RX_MODE, &tp->flags)) 2746 if (test_bit(RTL8152_SET_RX_MODE, &tp->flags))
2262 _rtl8152_set_rx_mode(tp->netdev); 2747 _rtl8152_set_rx_mode(tp->netdev);
2263 2748
2749 if (test_bit(SCHEDULE_TASKLET, &tp->flags) &&
2750 (tp->speed & LINK_STATUS)) {
2751 clear_bit(SCHEDULE_TASKLET, &tp->flags);
2752 tasklet_schedule(&tp->tl);
2753 }
2754
2755 if (test_bit(PHY_RESET, &tp->flags))
2756 rtl_phy_reset(tp);
2757
2264out1: 2758out1:
2265 return; 2759 usb_autopm_put_interface(tp->intf);
2266} 2760}
2267 2761
2268static int rtl8152_open(struct net_device *netdev) 2762static int rtl8152_open(struct net_device *netdev)
@@ -2270,6 +2764,27 @@ static int rtl8152_open(struct net_device *netdev)
2270 struct r8152 *tp = netdev_priv(netdev); 2764 struct r8152 *tp = netdev_priv(netdev);
2271 int res = 0; 2765 int res = 0;
2272 2766
2767 res = alloc_all_mem(tp);
2768 if (res)
2769 goto out;
2770
2771 res = usb_autopm_get_interface(tp->intf);
2772 if (res < 0) {
2773 free_all_mem(tp);
2774 goto out;
2775 }
2776
2777 /* The WORK_ENABLE may be set when autoresume occurs */
2778 if (test_bit(WORK_ENABLE, &tp->flags)) {
2779 clear_bit(WORK_ENABLE, &tp->flags);
2780 usb_kill_urb(tp->intr_urb);
2781 cancel_delayed_work_sync(&tp->schedule);
2782 if (tp->speed & LINK_STATUS)
2783 tp->rtl_ops.disable(tp);
2784 }
2785
2786 tp->rtl_ops.up(tp);
2787
2273 rtl8152_set_speed(tp, AUTONEG_ENABLE, 2788 rtl8152_set_speed(tp, AUTONEG_ENABLE,
2274 tp->mii.supports_gmii ? SPEED_1000 : SPEED_100, 2789 tp->mii.supports_gmii ? SPEED_1000 : SPEED_100,
2275 DUPLEX_FULL); 2790 DUPLEX_FULL);
@@ -2277,15 +2792,19 @@ static int rtl8152_open(struct net_device *netdev)
2277 netif_carrier_off(netdev); 2792 netif_carrier_off(netdev);
2278 netif_start_queue(netdev); 2793 netif_start_queue(netdev);
2279 set_bit(WORK_ENABLE, &tp->flags); 2794 set_bit(WORK_ENABLE, &tp->flags);
2795
2280 res = usb_submit_urb(tp->intr_urb, GFP_KERNEL); 2796 res = usb_submit_urb(tp->intr_urb, GFP_KERNEL);
2281 if (res) { 2797 if (res) {
2282 if (res == -ENODEV) 2798 if (res == -ENODEV)
2283 netif_device_detach(tp->netdev); 2799 netif_device_detach(tp->netdev);
2284 netif_warn(tp, ifup, netdev, "intr_urb submit failed: %d\n", 2800 netif_warn(tp, ifup, netdev, "intr_urb submit failed: %d\n",
2285 res); 2801 res);
2802 free_all_mem(tp);
2286 } 2803 }
2287 2804
2805 usb_autopm_put_interface(tp->intf);
2288 2806
2807out:
2289 return res; 2808 return res;
2290} 2809}
2291 2810
@@ -2298,33 +2817,30 @@ static int rtl8152_close(struct net_device *netdev)
2298 usb_kill_urb(tp->intr_urb); 2817 usb_kill_urb(tp->intr_urb);
2299 cancel_delayed_work_sync(&tp->schedule); 2818 cancel_delayed_work_sync(&tp->schedule);
2300 netif_stop_queue(netdev); 2819 netif_stop_queue(netdev);
2301 tasklet_disable(&tp->tl);
2302 tp->rtl_ops.disable(tp);
2303 tasklet_enable(&tp->tl);
2304 2820
2305 return res; 2821 res = usb_autopm_get_interface(tp->intf);
2306} 2822 if (res < 0) {
2823 rtl_drop_queued_tx(tp);
2824 } else {
2825 /*
2826 * The autosuspend may have been enabled and wouldn't
2827 * be disable when autoresume occurs, because the
2828 * netif_running() would be false.
2829 */
2830 if (test_bit(SELECTIVE_SUSPEND, &tp->flags)) {
2831 rtl_runtime_suspend_enable(tp, false);
2832 clear_bit(SELECTIVE_SUSPEND, &tp->flags);
2833 }
2307 2834
2308static void rtl_clear_bp(struct r8152 *tp) 2835 tasklet_disable(&tp->tl);
2309{ 2836 tp->rtl_ops.down(tp);
2310 ocp_write_dword(tp, MCU_TYPE_PLA, PLA_BP_0, 0); 2837 tasklet_enable(&tp->tl);
2311 ocp_write_dword(tp, MCU_TYPE_PLA, PLA_BP_2, 0); 2838 usb_autopm_put_interface(tp->intf);
2312 ocp_write_dword(tp, MCU_TYPE_PLA, PLA_BP_4, 0); 2839 }
2313 ocp_write_dword(tp, MCU_TYPE_PLA, PLA_BP_6, 0);
2314 ocp_write_dword(tp, MCU_TYPE_USB, USB_BP_0, 0);
2315 ocp_write_dword(tp, MCU_TYPE_USB, USB_BP_2, 0);
2316 ocp_write_dword(tp, MCU_TYPE_USB, USB_BP_4, 0);
2317 ocp_write_dword(tp, MCU_TYPE_USB, USB_BP_6, 0);
2318 mdelay(3);
2319 ocp_write_word(tp, MCU_TYPE_PLA, PLA_BP_BA, 0);
2320 ocp_write_word(tp, MCU_TYPE_USB, USB_BP_BA, 0);
2321}
2322 2840
2323static void r8153_clear_bp(struct r8152 *tp) 2841 free_all_mem(tp);
2324{ 2842
2325 ocp_write_byte(tp, MCU_TYPE_PLA, PLA_BP_EN, 0); 2843 return res;
2326 ocp_write_byte(tp, MCU_TYPE_USB, USB_BP_EN, 0);
2327 rtl_clear_bp(tp);
2328} 2844}
2329 2845
2330static void r8152b_enable_eee(struct r8152 *tp) 2846static void r8152b_enable_eee(struct r8152 *tp)
@@ -2375,18 +2891,18 @@ static void r8152b_enable_fc(struct r8152 *tp)
2375 r8152_mdio_write(tp, MII_ADVERTISE, anar); 2891 r8152_mdio_write(tp, MII_ADVERTISE, anar);
2376} 2892}
2377 2893
2378static void r8152b_hw_phy_cfg(struct r8152 *tp) 2894static void rtl_tally_reset(struct r8152 *tp)
2379{ 2895{
2380 r8152_mdio_write(tp, MII_BMCR, BMCR_ANENABLE); 2896 u32 ocp_data;
2381 r8152b_disable_aldps(tp); 2897
2898 ocp_data = ocp_read_word(tp, MCU_TYPE_PLA, PLA_RSTTALLY);
2899 ocp_data |= TALLY_RESET;
2900 ocp_write_word(tp, MCU_TYPE_PLA, PLA_RSTTALLY, ocp_data);
2382} 2901}
2383 2902
2384static void r8152b_init(struct r8152 *tp) 2903static void r8152b_init(struct r8152 *tp)
2385{ 2904{
2386 u32 ocp_data; 2905 u32 ocp_data;
2387 int i;
2388
2389 rtl_clear_bp(tp);
2390 2906
2391 if (tp->version == RTL_VER_01) { 2907 if (tp->version == RTL_VER_01) {
2392 ocp_data = ocp_read_word(tp, MCU_TYPE_PLA, PLA_LED_FEATURE); 2908 ocp_data = ocp_read_word(tp, MCU_TYPE_PLA, PLA_LED_FEATURE);
@@ -2394,17 +2910,7 @@ static void r8152b_init(struct r8152 *tp)
2394 ocp_write_word(tp, MCU_TYPE_PLA, PLA_LED_FEATURE, ocp_data); 2910 ocp_write_word(tp, MCU_TYPE_PLA, PLA_LED_FEATURE, ocp_data);
2395 } 2911 }
2396 2912
2397 r8152b_hw_phy_cfg(tp); 2913 r8152_power_cut_en(tp, false);
2398
2399 ocp_data = ocp_read_word(tp, MCU_TYPE_USB, USB_UPS_CTRL);
2400 ocp_data &= ~POWER_CUT;
2401 ocp_write_word(tp, MCU_TYPE_USB, USB_UPS_CTRL, ocp_data);
2402
2403 ocp_data = ocp_read_word(tp, MCU_TYPE_USB, USB_PM_CTRL_STATUS);
2404 ocp_data &= ~RESUME_INDICATE;
2405 ocp_write_word(tp, MCU_TYPE_USB, USB_PM_CTRL_STATUS, ocp_data);
2406
2407 r8152b_exit_oob(tp);
2408 2914
2409 ocp_data = ocp_read_word(tp, MCU_TYPE_PLA, PLA_PHY_PWR); 2915 ocp_data = ocp_read_word(tp, MCU_TYPE_PLA, PLA_PHY_PWR);
2410 ocp_data |= TX_10M_IDLE_EN | PFM_PWM_SWITCH; 2916 ocp_data |= TX_10M_IDLE_EN | PFM_PWM_SWITCH;
@@ -2420,14 +2926,7 @@ static void r8152b_init(struct r8152 *tp)
2420 r8152b_enable_eee(tp); 2926 r8152b_enable_eee(tp);
2421 r8152b_enable_aldps(tp); 2927 r8152b_enable_aldps(tp);
2422 r8152b_enable_fc(tp); 2928 r8152b_enable_fc(tp);
2423 2929 rtl_tally_reset(tp);
2424 r8152_mdio_write(tp, MII_BMCR, BMCR_RESET | BMCR_ANENABLE |
2425 BMCR_ANRESTART);
2426 for (i = 0; i < 100; i++) {
2427 udelay(100);
2428 if (!(r8152_mdio_read(tp, MII_BMCR) & BMCR_RESET))
2429 break;
2430 }
2431 2930
2432 /* enable rx aggregation */ 2931 /* enable rx aggregation */
2433 ocp_data = ocp_read_word(tp, MCU_TYPE_USB, USB_USB_CTRL); 2932 ocp_data = ocp_read_word(tp, MCU_TYPE_USB, USB_USB_CTRL);
@@ -2440,7 +2939,7 @@ static void r8153_init(struct r8152 *tp)
2440 u32 ocp_data; 2939 u32 ocp_data;
2441 int i; 2940 int i;
2442 2941
2443 r8153_u1u2en(tp, 0); 2942 r8153_u1u2en(tp, false);
2444 2943
2445 for (i = 0; i < 500; i++) { 2944 for (i = 0; i < 500; i++) {
2446 if (ocp_read_word(tp, MCU_TYPE_PLA, PLA_BOOT_CTRL) & 2945 if (ocp_read_word(tp, MCU_TYPE_PLA, PLA_BOOT_CTRL) &
@@ -2456,14 +2955,12 @@ static void r8153_init(struct r8152 *tp)
2456 msleep(20); 2955 msleep(20);
2457 } 2956 }
2458 2957
2459 r8153_u2p3en(tp, 0); 2958 r8153_u2p3en(tp, false);
2460 2959
2461 ocp_data = ocp_read_word(tp, MCU_TYPE_USB, USB_WDT11_CTRL); 2960 ocp_data = ocp_read_word(tp, MCU_TYPE_USB, USB_WDT11_CTRL);
2462 ocp_data &= ~TIMER11_EN; 2961 ocp_data &= ~TIMER11_EN;
2463 ocp_write_word(tp, MCU_TYPE_USB, USB_WDT11_CTRL, ocp_data); 2962 ocp_write_word(tp, MCU_TYPE_USB, USB_WDT11_CTRL, ocp_data);
2464 2963
2465 r8153_clear_bp(tp);
2466
2467 ocp_data = ocp_read_word(tp, MCU_TYPE_PLA, PLA_LED_FEATURE); 2964 ocp_data = ocp_read_word(tp, MCU_TYPE_PLA, PLA_LED_FEATURE);
2468 ocp_data &= ~LED_MODE_MASK; 2965 ocp_data &= ~LED_MODE_MASK;
2469 ocp_write_word(tp, MCU_TYPE_PLA, PLA_LED_FEATURE, ocp_data); 2966 ocp_write_word(tp, MCU_TYPE_PLA, PLA_LED_FEATURE, ocp_data);
@@ -2481,10 +2978,8 @@ static void r8153_init(struct r8152 *tp)
2481 ocp_data |= SEN_VAL_NORMAL | SEL_RXIDLE; 2978 ocp_data |= SEN_VAL_NORMAL | SEL_RXIDLE;
2482 ocp_write_word(tp, MCU_TYPE_USB, USB_AFE_CTRL2, ocp_data); 2979 ocp_write_word(tp, MCU_TYPE_USB, USB_AFE_CTRL2, ocp_data);
2483 2980
2484 r8153_power_cut_en(tp, 0); 2981 r8153_power_cut_en(tp, false);
2485 r8153_u1u2en(tp, 1); 2982 r8153_u1u2en(tp, true);
2486
2487 r8153_first_init(tp);
2488 2983
2489 ocp_write_word(tp, MCU_TYPE_PLA, PLA_MAC_PWR_CTRL, ALDPS_SPDWN_RATIO); 2984 ocp_write_word(tp, MCU_TYPE_PLA, PLA_MAC_PWR_CTRL, ALDPS_SPDWN_RATIO);
2490 ocp_write_word(tp, MCU_TYPE_PLA, PLA_MAC_PWR_CTRL2, EEE_SPDWN_RATIO); 2985 ocp_write_word(tp, MCU_TYPE_PLA, PLA_MAC_PWR_CTRL2, EEE_SPDWN_RATIO);
@@ -2499,26 +2994,31 @@ static void r8153_init(struct r8152 *tp)
2499 r8153_enable_eee(tp); 2994 r8153_enable_eee(tp);
2500 r8153_enable_aldps(tp); 2995 r8153_enable_aldps(tp);
2501 r8152b_enable_fc(tp); 2996 r8152b_enable_fc(tp);
2502 2997 rtl_tally_reset(tp);
2503 r8152_mdio_write(tp, MII_BMCR, BMCR_RESET | BMCR_ANENABLE |
2504 BMCR_ANRESTART);
2505} 2998}
2506 2999
2507static int rtl8152_suspend(struct usb_interface *intf, pm_message_t message) 3000static int rtl8152_suspend(struct usb_interface *intf, pm_message_t message)
2508{ 3001{
2509 struct r8152 *tp = usb_get_intfdata(intf); 3002 struct r8152 *tp = usb_get_intfdata(intf);
2510 3003
2511 netif_device_detach(tp->netdev); 3004 if (PMSG_IS_AUTO(message))
3005 set_bit(SELECTIVE_SUSPEND, &tp->flags);
3006 else
3007 netif_device_detach(tp->netdev);
2512 3008
2513 if (netif_running(tp->netdev)) { 3009 if (netif_running(tp->netdev)) {
2514 clear_bit(WORK_ENABLE, &tp->flags); 3010 clear_bit(WORK_ENABLE, &tp->flags);
2515 usb_kill_urb(tp->intr_urb); 3011 usb_kill_urb(tp->intr_urb);
2516 cancel_delayed_work_sync(&tp->schedule); 3012 cancel_delayed_work_sync(&tp->schedule);
2517 tasklet_disable(&tp->tl); 3013 if (test_bit(SELECTIVE_SUSPEND, &tp->flags)) {
3014 rtl_runtime_suspend_enable(tp, true);
3015 } else {
3016 tasklet_disable(&tp->tl);
3017 tp->rtl_ops.down(tp);
3018 tasklet_enable(&tp->tl);
3019 }
2518 } 3020 }
2519 3021
2520 tp->rtl_ops.down(tp);
2521
2522 return 0; 3022 return 0;
2523} 3023}
2524 3024
@@ -2526,22 +3026,77 @@ static int rtl8152_resume(struct usb_interface *intf)
2526{ 3026{
2527 struct r8152 *tp = usb_get_intfdata(intf); 3027 struct r8152 *tp = usb_get_intfdata(intf);
2528 3028
2529 tp->rtl_ops.init(tp); 3029 if (!test_bit(SELECTIVE_SUSPEND, &tp->flags)) {
2530 netif_device_attach(tp->netdev); 3030 tp->rtl_ops.init(tp);
3031 netif_device_attach(tp->netdev);
3032 }
3033
2531 if (netif_running(tp->netdev)) { 3034 if (netif_running(tp->netdev)) {
2532 rtl8152_set_speed(tp, AUTONEG_ENABLE, 3035 if (test_bit(SELECTIVE_SUSPEND, &tp->flags)) {
3036 rtl_runtime_suspend_enable(tp, false);
3037 clear_bit(SELECTIVE_SUSPEND, &tp->flags);
3038 if (tp->speed & LINK_STATUS)
3039 tp->rtl_ops.disable(tp);
3040 } else {
3041 tp->rtl_ops.up(tp);
3042 rtl8152_set_speed(tp, AUTONEG_ENABLE,
2533 tp->mii.supports_gmii ? SPEED_1000 : SPEED_100, 3043 tp->mii.supports_gmii ? SPEED_1000 : SPEED_100,
2534 DUPLEX_FULL); 3044 DUPLEX_FULL);
3045 }
2535 tp->speed = 0; 3046 tp->speed = 0;
2536 netif_carrier_off(tp->netdev); 3047 netif_carrier_off(tp->netdev);
2537 set_bit(WORK_ENABLE, &tp->flags); 3048 set_bit(WORK_ENABLE, &tp->flags);
2538 usb_submit_urb(tp->intr_urb, GFP_KERNEL); 3049 usb_submit_urb(tp->intr_urb, GFP_KERNEL);
2539 tasklet_enable(&tp->tl);
2540 } 3050 }
2541 3051
2542 return 0; 3052 return 0;
2543} 3053}
2544 3054
3055static void rtl8152_get_wol(struct net_device *dev, struct ethtool_wolinfo *wol)
3056{
3057 struct r8152 *tp = netdev_priv(dev);
3058
3059 if (usb_autopm_get_interface(tp->intf) < 0)
3060 return;
3061
3062 wol->supported = WAKE_ANY;
3063 wol->wolopts = __rtl_get_wol(tp);
3064
3065 usb_autopm_put_interface(tp->intf);
3066}
3067
3068static int rtl8152_set_wol(struct net_device *dev, struct ethtool_wolinfo *wol)
3069{
3070 struct r8152 *tp = netdev_priv(dev);
3071 int ret;
3072
3073 ret = usb_autopm_get_interface(tp->intf);
3074 if (ret < 0)
3075 goto out_set_wol;
3076
3077 __rtl_set_wol(tp, wol->wolopts);
3078 tp->saved_wolopts = wol->wolopts & WAKE_ANY;
3079
3080 usb_autopm_put_interface(tp->intf);
3081
3082out_set_wol:
3083 return ret;
3084}
3085
3086static u32 rtl8152_get_msglevel(struct net_device *dev)
3087{
3088 struct r8152 *tp = netdev_priv(dev);
3089
3090 return tp->msg_enable;
3091}
3092
3093static void rtl8152_set_msglevel(struct net_device *dev, u32 value)
3094{
3095 struct r8152 *tp = netdev_priv(dev);
3096
3097 tp->msg_enable = value;
3098}
3099
2545static void rtl8152_get_drvinfo(struct net_device *netdev, 3100static void rtl8152_get_drvinfo(struct net_device *netdev,
2546 struct ethtool_drvinfo *info) 3101 struct ethtool_drvinfo *info)
2547{ 3102{
@@ -2566,8 +3121,76 @@ int rtl8152_get_settings(struct net_device *netdev, struct ethtool_cmd *cmd)
2566static int rtl8152_set_settings(struct net_device *dev, struct ethtool_cmd *cmd) 3121static int rtl8152_set_settings(struct net_device *dev, struct ethtool_cmd *cmd)
2567{ 3122{
2568 struct r8152 *tp = netdev_priv(dev); 3123 struct r8152 *tp = netdev_priv(dev);
3124 int ret;
3125
3126 ret = usb_autopm_get_interface(tp->intf);
3127 if (ret < 0)
3128 goto out;
2569 3129
2570 return rtl8152_set_speed(tp, cmd->autoneg, cmd->speed, cmd->duplex); 3130 ret = rtl8152_set_speed(tp, cmd->autoneg, cmd->speed, cmd->duplex);
3131
3132 usb_autopm_put_interface(tp->intf);
3133
3134out:
3135 return ret;
3136}
3137
3138static const char rtl8152_gstrings[][ETH_GSTRING_LEN] = {
3139 "tx_packets",
3140 "rx_packets",
3141 "tx_errors",
3142 "rx_errors",
3143 "rx_missed",
3144 "align_errors",
3145 "tx_single_collisions",
3146 "tx_multi_collisions",
3147 "rx_unicast",
3148 "rx_broadcast",
3149 "rx_multicast",
3150 "tx_aborted",
3151 "tx_underrun",
3152};
3153
3154static int rtl8152_get_sset_count(struct net_device *dev, int sset)
3155{
3156 switch (sset) {
3157 case ETH_SS_STATS:
3158 return ARRAY_SIZE(rtl8152_gstrings);
3159 default:
3160 return -EOPNOTSUPP;
3161 }
3162}
3163
3164static void rtl8152_get_ethtool_stats(struct net_device *dev,
3165 struct ethtool_stats *stats, u64 *data)
3166{
3167 struct r8152 *tp = netdev_priv(dev);
3168 struct tally_counter tally;
3169
3170 generic_ocp_read(tp, PLA_TALLYCNT, sizeof(tally), &tally, MCU_TYPE_PLA);
3171
3172 data[0] = le64_to_cpu(tally.tx_packets);
3173 data[1] = le64_to_cpu(tally.rx_packets);
3174 data[2] = le64_to_cpu(tally.tx_errors);
3175 data[3] = le32_to_cpu(tally.rx_errors);
3176 data[4] = le16_to_cpu(tally.rx_missed);
3177 data[5] = le16_to_cpu(tally.align_errors);
3178 data[6] = le32_to_cpu(tally.tx_one_collision);
3179 data[7] = le32_to_cpu(tally.tx_multi_collision);
3180 data[8] = le64_to_cpu(tally.rx_unicast);
3181 data[9] = le64_to_cpu(tally.rx_broadcast);
3182 data[10] = le32_to_cpu(tally.rx_multicast);
3183 data[11] = le16_to_cpu(tally.tx_aborted);
3184 data[12] = le16_to_cpu(tally.tx_underun);
3185}
3186
3187static void rtl8152_get_strings(struct net_device *dev, u32 stringset, u8 *data)
3188{
3189 switch (stringset) {
3190 case ETH_SS_STATS:
3191 memcpy(data, *rtl8152_gstrings, sizeof(rtl8152_gstrings));
3192 break;
3193 }
2571} 3194}
2572 3195
2573static struct ethtool_ops ops = { 3196static struct ethtool_ops ops = {
@@ -2575,13 +3198,24 @@ static struct ethtool_ops ops = {
2575 .get_settings = rtl8152_get_settings, 3198 .get_settings = rtl8152_get_settings,
2576 .set_settings = rtl8152_set_settings, 3199 .set_settings = rtl8152_set_settings,
2577 .get_link = ethtool_op_get_link, 3200 .get_link = ethtool_op_get_link,
3201 .get_msglevel = rtl8152_get_msglevel,
3202 .set_msglevel = rtl8152_set_msglevel,
3203 .get_wol = rtl8152_get_wol,
3204 .set_wol = rtl8152_set_wol,
3205 .get_strings = rtl8152_get_strings,
3206 .get_sset_count = rtl8152_get_sset_count,
3207 .get_ethtool_stats = rtl8152_get_ethtool_stats,
2578}; 3208};
2579 3209
2580static int rtl8152_ioctl(struct net_device *netdev, struct ifreq *rq, int cmd) 3210static int rtl8152_ioctl(struct net_device *netdev, struct ifreq *rq, int cmd)
2581{ 3211{
2582 struct r8152 *tp = netdev_priv(netdev); 3212 struct r8152 *tp = netdev_priv(netdev);
2583 struct mii_ioctl_data *data = if_mii(rq); 3213 struct mii_ioctl_data *data = if_mii(rq);
2584 int res = 0; 3214 int res;
3215
3216 res = usb_autopm_get_interface(tp->intf);
3217 if (res < 0)
3218 goto out;
2585 3219
2586 switch (cmd) { 3220 switch (cmd) {
2587 case SIOCGMIIPHY: 3221 case SIOCGMIIPHY:
@@ -2604,6 +3238,9 @@ static int rtl8152_ioctl(struct net_device *netdev, struct ifreq *rq, int cmd)
2604 res = -EOPNOTSUPP; 3238 res = -EOPNOTSUPP;
2605 } 3239 }
2606 3240
3241 usb_autopm_put_interface(tp->intf);
3242
3243out:
2607 return res; 3244 return res;
2608} 3245}
2609 3246
@@ -2656,22 +3293,13 @@ static void r8152b_get_version(struct r8152 *tp)
2656 3293
2657static void rtl8152_unload(struct r8152 *tp) 3294static void rtl8152_unload(struct r8152 *tp)
2658{ 3295{
2659 u32 ocp_data; 3296 if (tp->version != RTL_VER_01)
2660 3297 r8152_power_cut_en(tp, true);
2661 if (tp->version != RTL_VER_01) {
2662 ocp_data = ocp_read_word(tp, MCU_TYPE_USB, USB_UPS_CTRL);
2663 ocp_data |= POWER_CUT;
2664 ocp_write_word(tp, MCU_TYPE_USB, USB_UPS_CTRL, ocp_data);
2665 }
2666
2667 ocp_data = ocp_read_word(tp, MCU_TYPE_USB, USB_PM_CTRL_STATUS);
2668 ocp_data &= ~RESUME_INDICATE;
2669 ocp_write_word(tp, MCU_TYPE_USB, USB_PM_CTRL_STATUS, ocp_data);
2670} 3298}
2671 3299
2672static void rtl8153_unload(struct r8152 *tp) 3300static void rtl8153_unload(struct r8152 *tp)
2673{ 3301{
2674 r8153_power_cut_en(tp, 1); 3302 r8153_power_cut_en(tp, true);
2675} 3303}
2676 3304
2677static int rtl_ops_init(struct r8152 *tp, const struct usb_device_id *id) 3305static int rtl_ops_init(struct r8152 *tp, const struct usb_device_id *id)
@@ -2686,6 +3314,7 @@ static int rtl_ops_init(struct r8152 *tp, const struct usb_device_id *id)
2686 ops->init = r8152b_init; 3314 ops->init = r8152b_init;
2687 ops->enable = rtl8152_enable; 3315 ops->enable = rtl8152_enable;
2688 ops->disable = rtl8152_disable; 3316 ops->disable = rtl8152_disable;
3317 ops->up = r8152b_exit_oob;
2689 ops->down = rtl8152_down; 3318 ops->down = rtl8152_down;
2690 ops->unload = rtl8152_unload; 3319 ops->unload = rtl8152_unload;
2691 ret = 0; 3320 ret = 0;
@@ -2694,6 +3323,7 @@ static int rtl_ops_init(struct r8152 *tp, const struct usb_device_id *id)
2694 ops->init = r8153_init; 3323 ops->init = r8153_init;
2695 ops->enable = rtl8153_enable; 3324 ops->enable = rtl8153_enable;
2696 ops->disable = rtl8152_disable; 3325 ops->disable = rtl8152_disable;
3326 ops->up = r8153_first_init;
2697 ops->down = rtl8153_down; 3327 ops->down = rtl8153_down;
2698 ops->unload = rtl8153_unload; 3328 ops->unload = rtl8153_unload;
2699 ret = 0; 3329 ret = 0;
@@ -2709,6 +3339,7 @@ static int rtl_ops_init(struct r8152 *tp, const struct usb_device_id *id)
2709 ops->init = r8153_init; 3339 ops->init = r8153_init;
2710 ops->enable = rtl8153_enable; 3340 ops->enable = rtl8153_enable;
2711 ops->disable = rtl8152_disable; 3341 ops->disable = rtl8152_disable;
3342 ops->up = r8153_first_init;
2712 ops->down = rtl8153_down; 3343 ops->down = rtl8153_down;
2713 ops->unload = rtl8153_unload; 3344 ops->unload = rtl8153_unload;
2714 ret = 0; 3345 ret = 0;
@@ -2766,9 +3397,15 @@ static int rtl8152_probe(struct usb_interface *intf,
2766 netdev->netdev_ops = &rtl8152_netdev_ops; 3397 netdev->netdev_ops = &rtl8152_netdev_ops;
2767 netdev->watchdog_timeo = RTL8152_TX_TIMEOUT; 3398 netdev->watchdog_timeo = RTL8152_TX_TIMEOUT;
2768 3399
2769 netdev->features |= NETIF_F_IP_CSUM; 3400 netdev->features |= NETIF_F_RXCSUM | NETIF_F_IP_CSUM | NETIF_F_SG |
2770 netdev->hw_features = NETIF_F_IP_CSUM; 3401 NETIF_F_TSO | NETIF_F_FRAGLIST | NETIF_F_IPV6_CSUM |
3402 NETIF_F_TSO6;
3403 netdev->hw_features = NETIF_F_RXCSUM | NETIF_F_IP_CSUM | NETIF_F_SG |
3404 NETIF_F_TSO | NETIF_F_FRAGLIST |
3405 NETIF_F_IPV6_CSUM | NETIF_F_TSO6;
3406
2771 SET_ETHTOOL_OPS(netdev, &ops); 3407 SET_ETHTOOL_OPS(netdev, &ops);
3408 netif_set_gso_max_size(netdev, RTL_LIMITED_TSO_SIZE);
2772 3409
2773 tp->mii.dev = netdev; 3410 tp->mii.dev = netdev;
2774 tp->mii.mdio_read = read_mii_word; 3411 tp->mii.mdio_read = read_mii_word;
@@ -2778,14 +3415,12 @@ static int rtl8152_probe(struct usb_interface *intf,
2778 tp->mii.phy_id = R8152_PHY_ID; 3415 tp->mii.phy_id = R8152_PHY_ID;
2779 tp->mii.supports_gmii = 0; 3416 tp->mii.supports_gmii = 0;
2780 3417
3418 intf->needs_remote_wakeup = 1;
3419
2781 r8152b_get_version(tp); 3420 r8152b_get_version(tp);
2782 tp->rtl_ops.init(tp); 3421 tp->rtl_ops.init(tp);
2783 set_ethernet_addr(tp); 3422 set_ethernet_addr(tp);
2784 3423
2785 ret = alloc_all_mem(tp);
2786 if (ret)
2787 goto out;
2788
2789 usb_set_intfdata(intf, tp); 3424 usb_set_intfdata(intf, tp);
2790 3425
2791 ret = register_netdev(netdev); 3426 ret = register_netdev(netdev);
@@ -2794,6 +3429,12 @@ static int rtl8152_probe(struct usb_interface *intf,
2794 goto out1; 3429 goto out1;
2795 } 3430 }
2796 3431
3432 tp->saved_wolopts = __rtl_get_wol(tp);
3433 if (tp->saved_wolopts)
3434 device_set_wakeup_enable(&udev->dev, true);
3435 else
3436 device_set_wakeup_enable(&udev->dev, false);
3437
2797 netif_info(tp, probe, netdev, "%s\n", DRIVER_VERSION); 3438 netif_info(tp, probe, netdev, "%s\n", DRIVER_VERSION);
2798 3439
2799 return 0; 3440 return 0;
@@ -2815,7 +3456,6 @@ static void rtl8152_disconnect(struct usb_interface *intf)
2815 tasklet_kill(&tp->tl); 3456 tasklet_kill(&tp->tl);
2816 unregister_netdev(tp->netdev); 3457 unregister_netdev(tp->netdev);
2817 tp->rtl_ops.unload(tp); 3458 tp->rtl_ops.unload(tp);
2818 free_all_mem(tp);
2819 free_netdev(tp->netdev); 3459 free_netdev(tp->netdev);
2820 } 3460 }
2821} 3461}
@@ -2838,6 +3478,8 @@ static struct usb_driver rtl8152_driver = {
2838 .suspend = rtl8152_suspend, 3478 .suspend = rtl8152_suspend,
2839 .resume = rtl8152_resume, 3479 .resume = rtl8152_resume,
2840 .reset_resume = rtl8152_resume, 3480 .reset_resume = rtl8152_resume,
3481 .supports_autosuspend = 1,
3482 .disable_hub_initiated_lpm = 1,
2841}; 3483};
2842 3484
2843module_usb_driver(rtl8152_driver); 3485module_usb_driver(rtl8152_driver);