Skip to content

Commit 8d520b4

Browse files
hkallweitkuba-moo
authored andcommitted
r8169: work around RTL8125 UDP hw bug
It was reported that on RTL8125 network breaks under heavy UDP load, e.g. torrent traffic ([0], from comment 27). Realtek confirmed a hw bug and provided me with a test version of the r8125 driver including a workaround. Tests confirmed that the workaround fixes the issue. I modified the original version of the workaround to meet mainline code style. [0] https://bugzilla.kernel.org/show_bug.cgi?id=209839 v2: - rebased to net v3: - make rtl_skb_is_udp() more robust and use skb_header_pointer() to access the ip(v6) header v4: - remove dependency on ptp_classify.h - replace magic number with offsetof(struct udphdr, len) Fixes: f1bce4a ("r8169: add support for RTL8125") Tested-by: xplo <xplo.bn@gmail.com> Signed-off-by: Heiner Kallweit <hkallweit1@gmail.com> Acked-by: Willem de Bruijn <willemb@google.com> Link: https://lore.kernel.org/r/6e453d49-1801-e6de-d5f7-d7e6c7526c8f@gmail.com Signed-off-by: Jakub Kicinski <kuba@kernel.org>
1 parent 0136563 commit 8d520b4

1 file changed

Lines changed: 65 additions & 6 deletions

File tree

‎drivers/net/ethernet/realtek/r8169_main.c‎

Lines changed: 65 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4046,17 +4046,72 @@ static int rtl8169_xmit_frags(struct rtl8169_private *tp, struct sk_buff *skb,
40464046
return -EIO;
40474047
}
40484048

4049-
static bool rtl_test_hw_pad_bug(struct rtl8169_private *tp)
4049+
static bool rtl_skb_is_udp(struct sk_buff *skb)
4050+
{
4051+
int no = skb_network_offset(skb);
4052+
struct ipv6hdr *i6h, _i6h;
4053+
struct iphdr *ih, _ih;
4054+
4055+
switch (vlan_get_protocol(skb)) {
4056+
case htons(ETH_P_IP):
4057+
ih = skb_header_pointer(skb, no, sizeof(_ih), &_ih);
4058+
return ih && ih->protocol == IPPROTO_UDP;
4059+
case htons(ETH_P_IPV6):
4060+
i6h = skb_header_pointer(skb, no, sizeof(_i6h), &_i6h);
4061+
return i6h && i6h->nexthdr == IPPROTO_UDP;
4062+
default:
4063+
return false;
4064+
}
4065+
}
4066+
4067+
#define RTL_MIN_PATCH_LEN 47
4068+
4069+
/* see rtl8125_get_patch_pad_len() in r8125 vendor driver */
4070+
static unsigned int rtl8125_quirk_udp_padto(struct rtl8169_private *tp,
4071+
struct sk_buff *skb)
40504072
{
4073+
unsigned int padto = 0, len = skb->len;
4074+
4075+
if (rtl_is_8125(tp) && len < 128 + RTL_MIN_PATCH_LEN &&
4076+
rtl_skb_is_udp(skb) && skb_transport_header_was_set(skb)) {
4077+
unsigned int trans_data_len = skb_tail_pointer(skb) -
4078+
skb_transport_header(skb);
4079+
4080+
if (trans_data_len >= offsetof(struct udphdr, len) &&
4081+
trans_data_len < RTL_MIN_PATCH_LEN) {
4082+
u16 dest = ntohs(udp_hdr(skb)->dest);
4083+
4084+
/* dest is a standard PTP port */
4085+
if (dest == 319 || dest == 320)
4086+
padto = len + RTL_MIN_PATCH_LEN - trans_data_len;
4087+
}
4088+
4089+
if (trans_data_len < sizeof(struct udphdr))
4090+
padto = max_t(unsigned int, padto,
4091+
len + sizeof(struct udphdr) - trans_data_len);
4092+
}
4093+
4094+
return padto;
4095+
}
4096+
4097+
static unsigned int rtl_quirk_packet_padto(struct rtl8169_private *tp,
4098+
struct sk_buff *skb)
4099+
{
4100+
unsigned int padto;
4101+
4102+
padto = rtl8125_quirk_udp_padto(tp, skb);
4103+
40514104
switch (tp->mac_version) {
40524105
case RTL_GIGA_MAC_VER_34:
40534106
case RTL_GIGA_MAC_VER_60:
40544107
case RTL_GIGA_MAC_VER_61:
40554108
case RTL_GIGA_MAC_VER_63:
4056-
return true;
4109+
padto = max_t(unsigned int, padto, ETH_ZLEN);
40574110
default:
4058-
return false;
4111+
break;
40594112
}
4113+
4114+
return padto;
40604115
}
40614116

40624117
static void rtl8169_tso_csum_v1(struct sk_buff *skb, u32 *opts)
@@ -4128,9 +4183,10 @@ static bool rtl8169_tso_csum_v2(struct rtl8169_private *tp,
41284183

41294184
opts[1] |= transport_offset << TCPHO_SHIFT;
41304185
} else {
4131-
if (unlikely(skb->len < ETH_ZLEN && rtl_test_hw_pad_bug(tp)))
4132-
/* eth_skb_pad would free the skb on error */
4133-
return !__skb_put_padto(skb, ETH_ZLEN, false);
4186+
unsigned int padto = rtl_quirk_packet_padto(tp, skb);
4187+
4188+
/* skb_padto would free the skb on error */
4189+
return !__skb_put_padto(skb, padto, false);
41344190
}
41354191

41364192
return true;
@@ -4307,6 +4363,9 @@ static netdev_features_t rtl8169_features_check(struct sk_buff *skb,
43074363
if (skb->len < ETH_ZLEN)
43084364
features &= ~NETIF_F_CSUM_MASK;
43094365

4366+
if (rtl_quirk_packet_padto(tp, skb))
4367+
features &= ~NETIF_F_CSUM_MASK;
4368+
43104369
if (transport_offset > TCPHO_MAX &&
43114370
rtl_chip_supports_csum_v2(tp))
43124371
features &= ~NETIF_F_CSUM_MASK;

0 commit comments

Comments
 (0)