Skip to content

Commit 57ee062

Browse files
committed
Merge branch 'r8152'
Hayes Wang says: ==================== r8152: adjust the code V2: Correct the subject of patch raspberrypi#5. Replace "link feed" with "line feed". v1: Code adjustment. ==================== Signed-off-by: David S. Miller <davem@davemloft.net>
2 parents d0a47d3 + f5aaaa6 commit 57ee062

1 file changed

Lines changed: 46 additions & 53 deletions

File tree

‎drivers/net/usb/r8152.c‎

Lines changed: 46 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -489,16 +489,16 @@ struct rx_desc {
489489
#define RX_LEN_MASK 0x7fff
490490

491491
__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)
496496

497497
__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)
502502

503503
__le32 opts4;
504504
__le32 opts5;
@@ -507,24 +507,24 @@ struct rx_desc {
507507

508508
struct tx_desc {
509509
__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)
514514
#define GTTCPHO_SHIFT 18
515515
#define GTTCPHO_MAX 0x7fU
516516
#define TX_LEN_MAX 0x3ffffU
517517

518518
__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 */
523523
#define MSS_SHIFT 17
524524
#define MSS_MAX 0x7ffU
525525
#define TCPHO_SHIFT 17
526526
#define TCPHO_MAX 0x7ffU
527-
#define TX_VLAN_TAG (1 << 16)
527+
#define TX_VLAN_TAG BIT(16)
528528
};
529529

530530
struct r8152;
@@ -581,7 +581,6 @@ struct r8152 {
581581
u16 ocp_base;
582582
u8 *intr_buff;
583583
u8 version;
584-
u8 speed;
585584
};
586585

587586
enum rtl_version {
@@ -1157,12 +1156,12 @@ static void intr_callback(struct urb *urb)
11571156

11581157
d = urb->transfer_buffer;
11591158
if (INTR_LINK & __le16_to_cpu(d[0])) {
1160-
if (!(tp->speed & LINK_STATUS)) {
1159+
if (!netif_carrier_ok(tp->netdev)) {
11611160
set_bit(RTL8152_LINK_CHG, &tp->flags);
11621161
schedule_delayed_work(&tp->schedule, 0);
11631162
}
11641163
} else {
1165-
if (tp->speed & LINK_STATUS) {
1164+
if (netif_carrier_ok(tp->netdev)) {
11661165
set_bit(RTL8152_LINK_CHG, &tp->flags);
11671166
schedule_delayed_work(&tp->schedule, 0);
11681167
}
@@ -1331,18 +1330,6 @@ static struct tx_agg *r8152_get_tx_agg(struct r8152 *tp)
13311330
return agg;
13321331
}
13331332

1334-
static inline __be16 get_protocol(struct sk_buff *skb)
1335-
{
1336-
__be16 protocol;
1337-
1338-
if (skb->protocol == htons(ETH_P_8021Q))
1339-
protocol = vlan_eth_hdr(skb)->h_vlan_encapsulated_proto;
1340-
else
1341-
protocol = skb->protocol;
1342-
1343-
return protocol;
1344-
}
1345-
13461333
/* r8152_csum_workaround()
13471334
* The hw limites the value the transport offset. When the offset is out of the
13481335
* range, calculate the checksum by sw.
@@ -1448,7 +1435,7 @@ static int r8152_tx_csum(struct r8152 *tp, struct tx_desc *desc,
14481435
goto unavailable;
14491436
}
14501437

1451-
switch (get_protocol(skb)) {
1438+
switch (vlan_get_protocol(skb)) {
14521439
case htons(ETH_P_IP):
14531440
opts1 |= GTSENDV4;
14541441
break;
@@ -1479,7 +1466,7 @@ static int r8152_tx_csum(struct r8152 *tp, struct tx_desc *desc,
14791466
goto unavailable;
14801467
}
14811468

1482-
switch (get_protocol(skb)) {
1469+
switch (vlan_get_protocol(skb)) {
14831470
case htons(ETH_P_IP):
14841471
opts2 |= IPV4_CS;
14851472
ip_protocol = ip_hdr(skb)->protocol;
@@ -1643,7 +1630,7 @@ static int rx_bottom(struct r8152 *tp, int budget)
16431630
{
16441631
unsigned long flags;
16451632
struct list_head *cursor, *next, rx_queue;
1646-
int work_done = 0;
1633+
int ret = 0, work_done = 0;
16471634

16481635
if (!skb_queue_empty(&tp->rx_queue)) {
16491636
while (work_done < budget) {
@@ -1734,7 +1721,18 @@ static int rx_bottom(struct r8152 *tp, int budget)
17341721
}
17351722

17361723
submit:
1737-
r8152_submit_rx(tp, agg, GFP_ATOMIC);
1724+
if (!ret) {
1725+
ret = r8152_submit_rx(tp, agg, GFP_ATOMIC);
1726+
} else {
1727+
urb->actual_length = 0;
1728+
list_add_tail(&agg->list, next);
1729+
}
1730+
}
1731+
1732+
if (!list_empty(&rx_queue)) {
1733+
spin_lock_irqsave(&tp->rx_lock, flags);
1734+
list_splice_tail(&rx_queue, &tp->rx_done);
1735+
spin_unlock_irqrestore(&tp->rx_lock, flags);
17381736
}
17391737

17401738
out1:
@@ -1883,7 +1881,7 @@ static void rtl8152_set_rx_mode(struct net_device *netdev)
18831881
{
18841882
struct r8152 *tp = netdev_priv(netdev);
18851883

1886-
if (tp->speed & LINK_STATUS) {
1884+
if (netif_carrier_ok(netdev)) {
18871885
set_bit(RTL8152_SET_RX_MODE, &tp->flags);
18881886
schedule_delayed_work(&tp->schedule, 0);
18891887
}
@@ -2907,21 +2905,20 @@ static void set_carrier(struct r8152 *tp)
29072905
speed = rtl8152_get_speed(tp);
29082906

29092907
if (speed & LINK_STATUS) {
2910-
if (!(tp->speed & LINK_STATUS)) {
2908+
if (!netif_carrier_ok(netdev)) {
29112909
tp->rtl_ops.enable(tp);
29122910
set_bit(RTL8152_SET_RX_MODE, &tp->flags);
29132911
netif_carrier_on(netdev);
29142912
rtl_start_rx(tp);
29152913
}
29162914
} else {
2917-
if (tp->speed & LINK_STATUS) {
2915+
if (netif_carrier_ok(netdev)) {
29182916
netif_carrier_off(netdev);
29192917
napi_disable(&tp->napi);
29202918
tp->rtl_ops.disable(tp);
29212919
napi_enable(&tp->napi);
29222920
}
29232921
}
2924-
tp->speed = speed;
29252922
}
29262923

29272924
static void rtl_work_func_t(struct work_struct *work)
@@ -2953,7 +2950,7 @@ static void rtl_work_func_t(struct work_struct *work)
29532950

29542951
/* don't schedule napi before linking */
29552952
if (test_bit(SCHEDULE_NAPI, &tp->flags) &&
2956-
(tp->speed & LINK_STATUS)) {
2953+
netif_carrier_ok(tp->netdev)) {
29572954
clear_bit(SCHEDULE_NAPI, &tp->flags);
29582955
napi_schedule(&tp->napi);
29592956
}
@@ -2976,8 +2973,7 @@ static int rtl8152_open(struct net_device *netdev)
29762973
if (res)
29772974
goto out;
29782975

2979-
/* set speed to 0 to avoid autoresume try to submit rx */
2980-
tp->speed = 0;
2976+
netif_carrier_off(netdev);
29812977

29822978
res = usb_autopm_get_interface(tp->intf);
29832979
if (res < 0) {
@@ -2994,7 +2990,7 @@ static int rtl8152_open(struct net_device *netdev)
29942990
cancel_delayed_work_sync(&tp->schedule);
29952991

29962992
/* disable the tx/rx, if the workqueue has enabled them. */
2997-
if (tp->speed & LINK_STATUS)
2993+
if (netif_carrier_ok(netdev))
29982994
tp->rtl_ops.disable(tp);
29992995
}
30002996

@@ -3003,7 +2999,6 @@ static int rtl8152_open(struct net_device *netdev)
30032999
rtl8152_set_speed(tp, AUTONEG_ENABLE,
30043000
tp->mii.supports_gmii ? SPEED_1000 : SPEED_100,
30053001
DUPLEX_FULL);
3006-
tp->speed = 0;
30073002
netif_carrier_off(netdev);
30083003
netif_start_queue(netdev);
30093004
set_bit(WORK_ENABLE, &tp->flags);
@@ -3039,7 +3034,7 @@ static int rtl8152_close(struct net_device *netdev)
30393034
netif_stop_queue(netdev);
30403035

30413036
res = usb_autopm_get_interface(tp->intf);
3042-
if (res < 0) {
3037+
if (res < 0 || test_bit(RTL8152_UNPLUG, &tp->flags)) {
30433038
rtl_drop_queued_tx(tp);
30443039
rtl_stop_rx(tp);
30453040
} else {
@@ -3245,10 +3240,10 @@ static void r8153_init(struct r8152 *tp)
32453240

32463241
ocp_data = ocp_read_byte(tp, MCU_TYPE_USB, USB_LPM_CTRL);
32473242
ocp_data &= ~LPM_TIMER_MASK;
3248-
if (tp->udev->speed == USB_SPEED_SUPER)
3249-
ocp_data |= LPM_TIMER_500US;
3250-
else
3243+
if (tp->version == RTL_VER_04 && tp->udev->speed != USB_SPEED_SUPER)
32513244
ocp_data |= LPM_TIMER_500MS;
3245+
else
3246+
ocp_data |= LPM_TIMER_500US;
32523247
ocp_write_byte(tp, MCU_TYPE_USB, USB_LPM_CTRL, ocp_data);
32533248

32543249
ocp_data = ocp_read_word(tp, MCU_TYPE_USB, USB_AFE_CTRL2);
@@ -3329,15 +3324,14 @@ static int rtl8152_resume(struct usb_interface *intf)
33293324
rtl_runtime_suspend_enable(tp, false);
33303325
clear_bit(SELECTIVE_SUSPEND, &tp->flags);
33313326
set_bit(WORK_ENABLE, &tp->flags);
3332-
if (tp->speed & LINK_STATUS)
3327+
if (netif_carrier_ok(tp->netdev))
33333328
rtl_start_rx(tp);
33343329
} else {
33353330
tp->rtl_ops.up(tp);
33363331
rtl8152_set_speed(tp, AUTONEG_ENABLE,
33373332
tp->mii.supports_gmii ?
33383333
SPEED_1000 : SPEED_100,
33393334
DUPLEX_FULL);
3340-
tp->speed = 0;
33413335
netif_carrier_off(tp->netdev);
33423336
set_bit(WORK_ENABLE, &tp->flags);
33433337
}
@@ -3902,8 +3896,7 @@ static int rtl8152_probe(struct usb_interface *intf,
39023896
netdev->hw_features = NETIF_F_RXCSUM | NETIF_F_IP_CSUM | NETIF_F_SG |
39033897
NETIF_F_TSO | NETIF_F_FRAGLIST |
39043898
NETIF_F_IPV6_CSUM | NETIF_F_TSO6 |
3905-
NETIF_F_HW_VLAN_CTAG_RX |
3906-
NETIF_F_HW_VLAN_CTAG_TX;
3899+
NETIF_F_HW_VLAN_CTAG_RX | NETIF_F_HW_VLAN_CTAG_TX;
39073900
netdev->vlan_features = NETIF_F_SG | NETIF_F_IP_CSUM | NETIF_F_TSO |
39083901
NETIF_F_HIGHDMA | NETIF_F_FRAGLIST |
39093902
NETIF_F_IPV6_CSUM | NETIF_F_TSO6;

0 commit comments

Comments
 (0)