r8169: implement callback ndo_features_check
authorHeiner Kallweit <hkallweit1@gmail.com>
Fri, 26 Jul 2019 19:49:22 +0000 (21:49 +0200)
committerDavid S. Miller <davem@davemloft.net>
Sat, 27 Jul 2019 21:25:07 +0000 (14:25 -0700)
Implement callback ndo_features_check and move all feature checks there.
This will allow us to get rid of r8169_csum_workaround() completely in
a subsequent step. Like in the vendor driver disable HW csum for short
packets on RTL8168b.

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 52a9e2d2fc73de32a71f0cf1cef38bb05697830f..7e1b68b19d6028599a1ff48e26f5bc9551acb2c6 100644 (file)
@@ -539,11 +539,11 @@ enum rtl_tx_desc_bit_1 {
        TD1_GTSENV4     = (1 << 26),            /* Giant Send for IPv4 */
        TD1_GTSENV6     = (1 << 25),            /* Giant Send for IPv6 */
 #define GTTCPHO_SHIFT                  18
-#define GTTCPHO_MAX                    0x7fU
+#define GTTCPHO_MAX                    0x7f
 
        /* Second doubleword. */
 #define TCPHO_SHIFT                    18
-#define TCPHO_MAX                      0x3ffU
+#define TCPHO_MAX                      0x3ff
 #define TD1_MSS_SHIFT                  18      /* MSS position (11 bits) */
        TD1_IPv6_CS     = (1 << 28),            /* Calculate IPv6 checksum */
        TD1_IPv4_CS     = (1 << 29),            /* Calculate IPv4 checksum */
@@ -5534,11 +5534,6 @@ static void r8169_csum_workaround(struct rtl8169_private *tp,
                } while (segs);
 
                dev_consume_skb_any(skb);
-       } else if (skb->ip_summed == CHECKSUM_PARTIAL) {
-               if (skb_checksum_help(skb) < 0)
-                       goto drop;
-
-               rtl8169_start_xmit(skb, tp->dev);
        } else {
 drop:
                tp->dev->stats.tx_dropped++;
@@ -5595,13 +5590,6 @@ static bool rtl8169_tso_csum_v2(struct rtl8169_private *tp,
        u32 mss = skb_shinfo(skb)->gso_size;
 
        if (mss) {
-               if (transport_offset > GTTCPHO_MAX) {
-                       netif_warn(tp, tx_err, tp->dev,
-                                  "Invalid transport offset 0x%x for TSO\n",
-                                  transport_offset);
-                       return false;
-               }
-
                switch (vlan_get_protocol(skb)) {
                case htons(ETH_P_IP):
                        opts[0] |= TD1_GTSENV4;
@@ -5624,16 +5612,6 @@ static bool rtl8169_tso_csum_v2(struct rtl8169_private *tp,
        } else if (skb->ip_summed == CHECKSUM_PARTIAL) {
                u8 ip_protocol;
 
-               if (unlikely(rtl_test_hw_pad_bug(tp, skb)))
-                       return !(skb_checksum_help(skb) || eth_skb_pad(skb));
-
-               if (transport_offset > TCPHO_MAX) {
-                       netif_warn(tp, tx_err, tp->dev,
-                                  "Invalid transport offset 0x%x\n",
-                                  transport_offset);
-                       return false;
-               }
-
                switch (vlan_get_protocol(skb)) {
                case htons(ETH_P_IP):
                        opts[1] |= TD1_IPv4_CS;
@@ -5790,6 +5768,39 @@ err_stop_0:
        return NETDEV_TX_BUSY;
 }
 
+static netdev_features_t rtl8169_features_check(struct sk_buff *skb,
+                                               struct net_device *dev,
+                                               netdev_features_t features)
+{
+       int transport_offset = skb_transport_offset(skb);
+       struct rtl8169_private *tp = netdev_priv(dev);
+
+       if (skb_is_gso(skb)) {
+               if (transport_offset > GTTCPHO_MAX &&
+                   rtl_chip_supports_csum_v2(tp))
+                       features &= ~NETIF_F_ALL_TSO;
+       } else if (skb->ip_summed == CHECKSUM_PARTIAL) {
+               if (skb->len < ETH_ZLEN) {
+                       switch (tp->mac_version) {
+                       case RTL_GIGA_MAC_VER_11:
+                       case RTL_GIGA_MAC_VER_12:
+                       case RTL_GIGA_MAC_VER_17:
+                       case RTL_GIGA_MAC_VER_34:
+                               features &= ~NETIF_F_CSUM_MASK;
+                               break;
+                       default:
+                               break;
+                       }
+               }
+
+               if (transport_offset > TCPHO_MAX &&
+                   rtl_chip_supports_csum_v2(tp))
+                       features &= ~NETIF_F_CSUM_MASK;
+       }
+
+       return vlan_features_check(skb, features);
+}
+
 static void rtl8169_pcierr_interrupt(struct net_device *dev)
 {
        struct rtl8169_private *tp = netdev_priv(dev);
@@ -6546,6 +6557,7 @@ static const struct net_device_ops rtl_netdev_ops = {
        .ndo_stop               = rtl8169_close,
        .ndo_get_stats64        = rtl8169_get_stats64,
        .ndo_start_xmit         = rtl8169_start_xmit,
+       .ndo_features_check     = rtl8169_features_check,
        .ndo_tx_timeout         = rtl8169_tx_timeout,
        .ndo_validate_addr      = eth_validate_addr,
        .ndo_change_mtu         = rtl8169_change_mtu,