Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

Merge branch 'r8152'

Hayes Wang says:

====================
r8152: adjust the code

V2:
Correct the subject of patch #5. Replace "link feed" with "line feed".

v1:
Code adjustment.
====================

Signed-off-by: David S. Miller <davem@davemloft.net>

+46 -53
+46 -53
drivers/net/usb/r8152.c
··· 489 489 #define RX_LEN_MASK 0x7fff 490 490 491 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) 492 + #define RD_UDP_CS BIT(23) 493 + #define RD_TCP_CS BIT(22) 494 + #define RD_IPV6_CS BIT(20) 495 + #define RD_IPV4_CS BIT(19) 496 496 497 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 - #define RX_VLAN_TAG (1 << 16) 498 + #define IPF BIT(23) /* IP checksum fail */ 499 + #define UDPF BIT(22) /* UDP checksum fail */ 500 + #define TCPF BIT(21) /* TCP checksum fail */ 501 + #define RX_VLAN_TAG BIT(16) 502 502 503 503 __le32 opts4; 504 504 __le32 opts5; ··· 507 507 508 508 struct tx_desc { 509 509 __le32 opts1; 510 - #define TX_FS (1 << 31) /* First segment of a packet */ 511 - #define TX_LS (1 << 30) /* Final segment of a packet */ 512 - #define GTSENDV4 (1 << 28) 513 - #define GTSENDV6 (1 << 27) 510 + #define TX_FS BIT(31) /* First segment of a packet */ 511 + #define TX_LS BIT(30) /* Final segment of a packet */ 512 + #define GTSENDV4 BIT(28) 513 + #define GTSENDV6 BIT(27) 514 514 #define GTTCPHO_SHIFT 18 515 515 #define GTTCPHO_MAX 0x7fU 516 516 #define TX_LEN_MAX 0x3ffffU 517 517 518 518 __le32 opts2; 519 - #define UDP_CS (1 << 31) /* Calculate UDP/IP checksum */ 520 - #define TCP_CS (1 << 30) /* Calculate TCP/IP checksum */ 521 - #define IPV4_CS (1 << 29) /* Calculate IPv4 checksum */ 522 - #define IPV6_CS (1 << 28) /* Calculate IPv6 checksum */ 519 + #define UDP_CS BIT(31) /* Calculate UDP/IP checksum */ 520 + #define TCP_CS BIT(30) /* Calculate TCP/IP checksum */ 521 + #define IPV4_CS BIT(29) /* Calculate IPv4 checksum */ 522 + #define IPV6_CS BIT(28) /* Calculate IPv6 checksum */ 523 523 #define MSS_SHIFT 17 524 524 #define MSS_MAX 0x7ffU 525 525 #define TCPHO_SHIFT 17 526 526 #define TCPHO_MAX 0x7ffU 527 - #define TX_VLAN_TAG (1 << 16) 527 + #define TX_VLAN_TAG BIT(16) 528 528 }; 529 529 530 530 struct r8152; ··· 581 581 u16 ocp_base; 582 582 u8 *intr_buff; 583 583 u8 version; 584 - u8 speed; 585 584 }; 586 585 587 586 enum rtl_version { ··· 1156 1157 1157 1158 d = urb->transfer_buffer; 1158 1159 if (INTR_LINK & __le16_to_cpu(d[0])) { 1159 - if (!(tp->speed & LINK_STATUS)) { 1160 + if (!netif_carrier_ok(tp->netdev)) { 1160 1161 set_bit(RTL8152_LINK_CHG, &tp->flags); 1161 1162 schedule_delayed_work(&tp->schedule, 0); 1162 1163 } 1163 1164 } else { 1164 - if (tp->speed & LINK_STATUS) { 1165 + if (netif_carrier_ok(tp->netdev)) { 1165 1166 set_bit(RTL8152_LINK_CHG, &tp->flags); 1166 1167 schedule_delayed_work(&tp->schedule, 0); 1167 1168 } ··· 1330 1331 return agg; 1331 1332 } 1332 1333 1333 - static inline __be16 get_protocol(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 1334 /* r8152_csum_workaround() 1346 1335 * The hw limites the value the transport offset. When the offset is out of the 1347 1336 * range, calculate the checksum by sw. ··· 1435 1448 goto unavailable; 1436 1449 } 1437 1450 1438 - switch (get_protocol(skb)) { 1451 + switch (vlan_get_protocol(skb)) { 1439 1452 case htons(ETH_P_IP): 1440 1453 opts1 |= GTSENDV4; 1441 1454 break; ··· 1466 1479 goto unavailable; 1467 1480 } 1468 1481 1469 - switch (get_protocol(skb)) { 1482 + switch (vlan_get_protocol(skb)) { 1470 1483 case htons(ETH_P_IP): 1471 1484 opts2 |= IPV4_CS; 1472 1485 ip_protocol = ip_hdr(skb)->protocol; ··· 1630 1643 { 1631 1644 unsigned long flags; 1632 1645 struct list_head *cursor, *next, rx_queue; 1633 - int work_done = 0; 1646 + int ret = 0, work_done = 0; 1634 1647 1635 1648 if (!skb_queue_empty(&tp->rx_queue)) { 1636 1649 while (work_done < budget) { ··· 1721 1734 } 1722 1735 1723 1736 submit: 1724 - r8152_submit_rx(tp, agg, GFP_ATOMIC); 1737 + if (!ret) { 1738 + ret = r8152_submit_rx(tp, agg, GFP_ATOMIC); 1739 + } else { 1740 + urb->actual_length = 0; 1741 + list_add_tail(&agg->list, next); 1742 + } 1743 + } 1744 + 1745 + if (!list_empty(&rx_queue)) { 1746 + spin_lock_irqsave(&tp->rx_lock, flags); 1747 + list_splice_tail(&rx_queue, &tp->rx_done); 1748 + spin_unlock_irqrestore(&tp->rx_lock, flags); 1725 1749 } 1726 1750 1727 1751 out1: ··· 1881 1883 { 1882 1884 struct r8152 *tp = netdev_priv(netdev); 1883 1885 1884 - if (tp->speed & LINK_STATUS) { 1886 + if (netif_carrier_ok(netdev)) { 1885 1887 set_bit(RTL8152_SET_RX_MODE, &tp->flags); 1886 1888 schedule_delayed_work(&tp->schedule, 0); 1887 1889 } ··· 2905 2907 speed = rtl8152_get_speed(tp); 2906 2908 2907 2909 if (speed & LINK_STATUS) { 2908 - if (!(tp->speed & LINK_STATUS)) { 2910 + if (!netif_carrier_ok(netdev)) { 2909 2911 tp->rtl_ops.enable(tp); 2910 2912 set_bit(RTL8152_SET_RX_MODE, &tp->flags); 2911 2913 netif_carrier_on(netdev); 2912 2914 rtl_start_rx(tp); 2913 2915 } 2914 2916 } else { 2915 - if (tp->speed & LINK_STATUS) { 2917 + if (netif_carrier_ok(netdev)) { 2916 2918 netif_carrier_off(netdev); 2917 2919 napi_disable(&tp->napi); 2918 2920 tp->rtl_ops.disable(tp); 2919 2921 napi_enable(&tp->napi); 2920 2922 } 2921 2923 } 2922 - tp->speed = speed; 2923 2924 } 2924 2925 2925 2926 static void rtl_work_func_t(struct work_struct *work) ··· 2950 2953 2951 2954 /* don't schedule napi before linking */ 2952 2955 if (test_bit(SCHEDULE_NAPI, &tp->flags) && 2953 - (tp->speed & LINK_STATUS)) { 2956 + netif_carrier_ok(tp->netdev)) { 2954 2957 clear_bit(SCHEDULE_NAPI, &tp->flags); 2955 2958 napi_schedule(&tp->napi); 2956 2959 } ··· 2973 2976 if (res) 2974 2977 goto out; 2975 2978 2976 - /* set speed to 0 to avoid autoresume try to submit rx */ 2977 - tp->speed = 0; 2979 + netif_carrier_off(netdev); 2978 2980 2979 2981 res = usb_autopm_get_interface(tp->intf); 2980 2982 if (res < 0) { ··· 2990 2994 cancel_delayed_work_sync(&tp->schedule); 2991 2995 2992 2996 /* disable the tx/rx, if the workqueue has enabled them. */ 2993 - if (tp->speed & LINK_STATUS) 2997 + if (netif_carrier_ok(netdev)) 2994 2998 tp->rtl_ops.disable(tp); 2995 2999 } 2996 3000 ··· 2999 3003 rtl8152_set_speed(tp, AUTONEG_ENABLE, 3000 3004 tp->mii.supports_gmii ? SPEED_1000 : SPEED_100, 3001 3005 DUPLEX_FULL); 3002 - tp->speed = 0; 3003 3006 netif_carrier_off(netdev); 3004 3007 netif_start_queue(netdev); 3005 3008 set_bit(WORK_ENABLE, &tp->flags); ··· 3034 3039 netif_stop_queue(netdev); 3035 3040 3036 3041 res = usb_autopm_get_interface(tp->intf); 3037 - if (res < 0) { 3042 + if (res < 0 || test_bit(RTL8152_UNPLUG, &tp->flags)) { 3038 3043 rtl_drop_queued_tx(tp); 3039 3044 rtl_stop_rx(tp); 3040 3045 } else { ··· 3240 3245 3241 3246 ocp_data = ocp_read_byte(tp, MCU_TYPE_USB, USB_LPM_CTRL); 3242 3247 ocp_data &= ~LPM_TIMER_MASK; 3243 - if (tp->udev->speed == USB_SPEED_SUPER) 3244 - ocp_data |= LPM_TIMER_500US; 3245 - else 3248 + if (tp->version == RTL_VER_04 && tp->udev->speed != USB_SPEED_SUPER) 3246 3249 ocp_data |= LPM_TIMER_500MS; 3250 + else 3251 + ocp_data |= LPM_TIMER_500US; 3247 3252 ocp_write_byte(tp, MCU_TYPE_USB, USB_LPM_CTRL, ocp_data); 3248 3253 3249 3254 ocp_data = ocp_read_word(tp, MCU_TYPE_USB, USB_AFE_CTRL2); ··· 3324 3329 rtl_runtime_suspend_enable(tp, false); 3325 3330 clear_bit(SELECTIVE_SUSPEND, &tp->flags); 3326 3331 set_bit(WORK_ENABLE, &tp->flags); 3327 - if (tp->speed & LINK_STATUS) 3332 + if (netif_carrier_ok(tp->netdev)) 3328 3333 rtl_start_rx(tp); 3329 3334 } else { 3330 3335 tp->rtl_ops.up(tp); ··· 3332 3337 tp->mii.supports_gmii ? 3333 3338 SPEED_1000 : SPEED_100, 3334 3339 DUPLEX_FULL); 3335 - tp->speed = 0; 3336 3340 netif_carrier_off(tp->netdev); 3337 3341 set_bit(WORK_ENABLE, &tp->flags); 3338 3342 } ··· 3896 3902 netdev->hw_features = NETIF_F_RXCSUM | NETIF_F_IP_CSUM | NETIF_F_SG | 3897 3903 NETIF_F_TSO | NETIF_F_FRAGLIST | 3898 3904 NETIF_F_IPV6_CSUM | NETIF_F_TSO6 | 3899 - NETIF_F_HW_VLAN_CTAG_RX | 3900 - NETIF_F_HW_VLAN_CTAG_TX; 3905 + NETIF_F_HW_VLAN_CTAG_RX | NETIF_F_HW_VLAN_CTAG_TX; 3901 3906 netdev->vlan_features = NETIF_F_SG | NETIF_F_IP_CSUM | NETIF_F_TSO | 3902 3907 NETIF_F_HIGHDMA | NETIF_F_FRAGLIST | 3903 3908 NETIF_F_IPV6_CSUM | NETIF_F_TSO6;