r8169: add workaround for RTL8168evl TSO hw issues
authorHeiner Kallweit <hkallweit1@gmail.com>
Sat, 18 Apr 2020 21:11:32 +0000 (23:11 +0200)
committerDavid S. Miller <davem@davemloft.net>
Sun, 19 Apr 2020 03:20:11 +0000 (20:20 -0700)
Add workaround for hw issues with TSO on RTL8168evl. This workaround is
based on information I got from Realtek, and *should* allow to safely
enable TSO on this chip version.

Signed-off-by: Heiner Kallweit <hkallweit1@gmail.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
drivers/net/ethernet/realtek/r8169_main.c

index 2cd2b038e4ebfc33b729a60e29d19a89268e2ae7..a8696d958cd1e16fa839ea903a30d0b30821833e 100644 (file)
@@ -4306,6 +4306,37 @@ err_stop_0:
        return NETDEV_TX_BUSY;
 }
 
+static unsigned int rtl_last_frag_len(struct sk_buff *skb)
+{
+       struct skb_shared_info *info = skb_shinfo(skb);
+       unsigned int nr_frags = info->nr_frags;
+
+       if (!nr_frags)
+               return UINT_MAX;
+
+       return skb_frag_size(info->frags + nr_frags - 1);
+}
+
+/* Workaround for hw issues with TSO on RTL8168evl */
+static netdev_features_t rtl8168evl_fix_tso(struct sk_buff *skb,
+                                           netdev_features_t features)
+{
+       /* IPv4 header has options field */
+       if (vlan_get_protocol(skb) == htons(ETH_P_IP) &&
+           ip_hdrlen(skb) > sizeof(struct iphdr))
+               features &= ~NETIF_F_ALL_TSO;
+
+       /* IPv4 TCP header has options field */
+       else if (skb_shinfo(skb)->gso_type & SKB_GSO_TCPV4 &&
+                tcp_hdrlen(skb) > sizeof(struct tcphdr))
+               features &= ~NETIF_F_ALL_TSO;
+
+       else if (rtl_last_frag_len(skb) <= 6)
+               features &= ~NETIF_F_ALL_TSO;
+
+       return features;
+}
+
 static netdev_features_t rtl8169_features_check(struct sk_buff *skb,
                                                struct net_device *dev,
                                                netdev_features_t features)
@@ -4314,6 +4345,9 @@ static netdev_features_t rtl8169_features_check(struct sk_buff *skb,
        struct rtl8169_private *tp = netdev_priv(dev);
 
        if (skb_is_gso(skb)) {
+               if (tp->mac_version == RTL_GIGA_MAC_VER_34)
+                       features = rtl8168evl_fix_tso(skb, features);
+
                if (transport_offset > GTTCPHO_MAX &&
                    rtl_chip_supports_csum_v2(tp))
                        features &= ~NETIF_F_ALL_TSO;