kernel: improve skb hash on the mtk ethernet driver
authorFelix Fietkau <nbd@nbd.name>
Fri, 18 Dec 2020 16:10:04 +0000 (17:10 +0100)
committerFelix Fietkau <nbd@nbd.name>
Fri, 18 Dec 2020 17:10:52 +0000 (18:10 +0100)
The PPE only provides a 14 bit hash, however many uses of the skb hash
expect the hash to use the full 32 bit range.
Use jhash to extend the hash to the full size

Signed-off-by: Felix Fietkau <nbd@nbd.name>
target/linux/generic/pending-5.4/770-13-net-ethernet-mtk_eth_soc-fix-parsing-packets-in-GDM.patch
target/linux/generic/pending-5.4/770-14-net-ethernet-mtk_eth_soc-set-PPE-flow-hash-as-skb-ha.patch
target/linux/generic/pending-5.4/770-15-net-ethernet-mediatek-mtk_eth_soc-add-support-for-in.patch
target/linux/generic/pending-5.4/770-16-net-ethernet-mediatek-mtk_eth_soc-add-flow-offloadin.patch
target/linux/mediatek/patches-5.4/1011-net-ethernet-mtk_eth_soc-add-support-for-coherent-DM.patch

index 9ef675dcd186b6eed8f0fbd329aceabd2597715e..16993b9d80117abe5679524f1238f9676bb69b50 100644 (file)
@@ -18,15 +18,7 @@ Signed-off-by: Felix Fietkau <nbd@nbd.name>
  
  #include "mtk_eth_soc.h"
  
  
  #include "mtk_eth_soc.h"
  
-@@ -1246,6 +1247,7 @@ static int mtk_poll_rx(struct napi_struc
-               unsigned int pktlen;
-               dma_addr_t dma_addr;
-               int mac;
-+              u16 hash;
-               ring = mtk_get_rx_ring(eth);
-               if (unlikely(!ring))
-@@ -1259,13 +1261,12 @@ static int mtk_poll_rx(struct napi_struc
+@@ -1259,13 +1260,12 @@ static int mtk_poll_rx(struct napi_struc
                        break;
  
                /* find out which mac the packet come from. values start at 1 */
                        break;
  
                /* find out which mac the packet come from. values start at 1 */
@@ -45,7 +37,7 @@ Signed-off-by: Felix Fietkau <nbd@nbd.name>
  
                if (unlikely(mac < 0 || mac >= MTK_MAC_COUNT ||
                             !eth->netdev[mac]))
  
                if (unlikely(mac < 0 || mac >= MTK_MAC_COUNT ||
                             !eth->netdev[mac]))
-@@ -2247,6 +2248,9 @@ static void mtk_gdm_config(struct mtk_et
+@@ -2247,6 +2247,9 @@ static void mtk_gdm_config(struct mtk_et
  
                val |= config;
  
  
                val |= config;
  
index 60ac12c013c9fdeb30d70681cda82ccc292f52b8..68ae19ec6e557128b6a56d3f99ed70b10e987fae 100644 (file)
@@ -10,13 +10,31 @@ Signed-off-by: Felix Fietkau <nbd@nbd.name>
 
 --- a/drivers/net/ethernet/mediatek/mtk_eth_soc.c
 +++ b/drivers/net/ethernet/mediatek/mtk_eth_soc.c
 
 --- a/drivers/net/ethernet/mediatek/mtk_eth_soc.c
 +++ b/drivers/net/ethernet/mediatek/mtk_eth_soc.c
-@@ -1316,6 +1316,10 @@ static int mtk_poll_rx(struct napi_struc
+@@ -19,6 +19,7 @@
+ #include <linux/interrupt.h>
+ #include <linux/pinctrl/devinfo.h>
+ #include <linux/phylink.h>
++#include <linux/jhash.h>
+ #include <net/dsa.h>
+ #include "mtk_eth_soc.h"
+@@ -1246,6 +1247,7 @@ static int mtk_poll_rx(struct napi_struc
+               struct net_device *netdev;
+               unsigned int pktlen;
+               dma_addr_t dma_addr;
++              u32 hash;
+               int mac;
+               ring = mtk_get_rx_ring(eth);
+@@ -1315,6 +1317,12 @@ static int mtk_poll_rx(struct napi_struc
                skb->protocol = eth_type_trans(skb, netdev);
                bytes += pktlen;
  
 +              hash = trxd.rxd4 & GENMASK(13, 0);
                skb->protocol = eth_type_trans(skb, netdev);
                bytes += pktlen;
  
 +              hash = trxd.rxd4 & GENMASK(13, 0);
-+              if (hash != GENMASK(13, 0))
++              if (hash != GENMASK(13, 0)) {
++                      hash = jhash_1word(hash, 0);
 +                      skb_set_hash(skb, hash, PKT_HASH_TYPE_L4);
 +                      skb_set_hash(skb, hash, PKT_HASH_TYPE_L4);
++              }
 +
                if (netdev->features & NETIF_F_HW_VLAN_CTAG_RX &&
                    (trxd.rxd2 & RX_DMA_VTAG))
 +
                if (netdev->features & NETIF_F_HW_VLAN_CTAG_RX &&
                    (trxd.rxd2 & RX_DMA_VTAG))
index 6d729c0f08c565c72f0df44b3233325676841ed8..d679e30bea657e5c4100d49fcfb0d0e120c19af7 100644 (file)
@@ -24,7 +24,7 @@ Signed-off-by: Felix Fietkau <nbd@nbd.name>
 +mtk_eth-y := mtk_eth_soc.o mtk_sgmii.o mtk_eth_path.o mtk_ppe.o
 --- a/drivers/net/ethernet/mediatek/mtk_eth_soc.c
 +++ b/drivers/net/ethernet/mediatek/mtk_eth_soc.c
 +mtk_eth-y := mtk_eth_soc.o mtk_sgmii.o mtk_eth_path.o mtk_ppe.o
 --- a/drivers/net/ethernet/mediatek/mtk_eth_soc.c
 +++ b/drivers/net/ethernet/mediatek/mtk_eth_soc.c
-@@ -2277,12 +2277,17 @@ static int mtk_open(struct net_device *d
+@@ -2280,12 +2280,17 @@ static int mtk_open(struct net_device *d
  
        /* we run 2 netdevs on the same dma ring so we only bring it up once */
        if (!refcount_read(&eth->dma_refcnt)) {
  
        /* we run 2 netdevs on the same dma ring so we only bring it up once */
        if (!refcount_read(&eth->dma_refcnt)) {
@@ -44,7 +44,7 @@ Signed-off-by: Felix Fietkau <nbd@nbd.name>
  
                napi_enable(&eth->tx_napi);
                napi_enable(&eth->rx_napi);
  
                napi_enable(&eth->tx_napi);
                napi_enable(&eth->rx_napi);
-@@ -2352,6 +2357,9 @@ static int mtk_stop(struct net_device *d
+@@ -2355,6 +2360,9 @@ static int mtk_stop(struct net_device *d
  
        mtk_dma_free(eth);
  
  
        mtk_dma_free(eth);
  
@@ -54,7 +54,7 @@ Signed-off-by: Felix Fietkau <nbd@nbd.name>
        return 0;
  }
  
        return 0;
  }
  
-@@ -3141,6 +3149,13 @@ static int mtk_probe(struct platform_dev
+@@ -3144,6 +3152,13 @@ static int mtk_probe(struct platform_dev
                        goto err_free_dev;
        }
  
                        goto err_free_dev;
        }
  
@@ -68,7 +68,7 @@ Signed-off-by: Felix Fietkau <nbd@nbd.name>
        for (i = 0; i < MTK_MAX_DEVS; i++) {
                if (!eth->netdev[i])
                        continue;
        for (i = 0; i < MTK_MAX_DEVS; i++) {
                if (!eth->netdev[i])
                        continue;
-@@ -3215,6 +3230,7 @@ static const struct mtk_soc_data mt7621_
+@@ -3218,6 +3233,7 @@ static const struct mtk_soc_data mt7621_
        .hw_features = MTK_HW_FEATURES,
        .required_clks = MT7621_CLKS_BITMAP,
        .required_pctl = false,
        .hw_features = MTK_HW_FEATURES,
        .required_clks = MT7621_CLKS_BITMAP,
        .required_pctl = false,
@@ -76,7 +76,7 @@ Signed-off-by: Felix Fietkau <nbd@nbd.name>
  };
  
  static const struct mtk_soc_data mt7622_data = {
  };
  
  static const struct mtk_soc_data mt7622_data = {
-@@ -3223,6 +3239,7 @@ static const struct mtk_soc_data mt7622_
+@@ -3226,6 +3242,7 @@ static const struct mtk_soc_data mt7622_
        .hw_features = MTK_HW_FEATURES,
        .required_clks = MT7622_CLKS_BITMAP,
        .required_pctl = false,
        .hw_features = MTK_HW_FEATURES,
        .required_clks = MT7622_CLKS_BITMAP,
        .required_pctl = false,
index 810eeda75c0db4488e32a0d91265df87277c67a9..f63ed2899884c735e3cd007a0c54143a7713b176 100644 (file)
@@ -20,16 +20,16 @@ Signed-off-by: Felix Fietkau <nbd@nbd.name>
 +mtk_eth-y := mtk_eth_soc.o mtk_sgmii.o mtk_eth_path.o mtk_ppe.o mtk_ppe_debugfs.o mtk_offload.o
 --- a/drivers/net/ethernet/mediatek/mtk_eth_soc.c
 +++ b/drivers/net/ethernet/mediatek/mtk_eth_soc.c
 +mtk_eth-y := mtk_eth_soc.o mtk_sgmii.o mtk_eth_path.o mtk_ppe.o mtk_ppe_debugfs.o mtk_offload.o
 --- a/drivers/net/ethernet/mediatek/mtk_eth_soc.c
 +++ b/drivers/net/ethernet/mediatek/mtk_eth_soc.c
-@@ -19,6 +19,8 @@
- #include <linux/interrupt.h>
+@@ -20,6 +20,8 @@
  #include <linux/pinctrl/devinfo.h>
  #include <linux/phylink.h>
  #include <linux/pinctrl/devinfo.h>
  #include <linux/phylink.h>
+ #include <linux/jhash.h>
 +#include <linux/netfilter.h>
 +#include <net/netfilter/nf_flow_table.h>
  #include <net/dsa.h>
  
  #include "mtk_eth_soc.h"
 +#include <linux/netfilter.h>
 +#include <net/netfilter/nf_flow_table.h>
  #include <net/dsa.h>
  
  #include "mtk_eth_soc.h"
-@@ -1324,8 +1326,12 @@ static int mtk_poll_rx(struct napi_struc
+@@ -1327,8 +1329,12 @@ static int mtk_poll_rx(struct napi_struc
                    (trxd.rxd2 & RX_DMA_VTAG))
                        __vlan_hwaccel_put_tag(skb, htons(ETH_P_8021Q),
                                               RX_DMA_VID(trxd.rxd3));
                    (trxd.rxd2 & RX_DMA_VTAG))
                        __vlan_hwaccel_put_tag(skb, htons(ETH_P_8021Q),
                                               RX_DMA_VID(trxd.rxd3));
@@ -44,7 +44,7 @@ Signed-off-by: Felix Fietkau <nbd@nbd.name>
  
  skip_rx:
                ring->data[idx] = new_data;
  
  skip_rx:
                ring->data[idx] = new_data;
-@@ -2858,6 +2864,25 @@ static int mtk_set_rxnfc(struct net_devi
+@@ -2861,6 +2867,25 @@ static int mtk_set_rxnfc(struct net_devi
        return ret;
  }
  
        return ret;
  }
  
@@ -70,7 +70,7 @@ Signed-off-by: Felix Fietkau <nbd@nbd.name>
  static const struct ethtool_ops mtk_ethtool_ops = {
        .get_link_ksettings     = mtk_get_link_ksettings,
        .set_link_ksettings     = mtk_set_link_ksettings,
  static const struct ethtool_ops mtk_ethtool_ops = {
        .get_link_ksettings     = mtk_get_link_ksettings,
        .set_link_ksettings     = mtk_set_link_ksettings,
-@@ -2889,6 +2914,7 @@ static const struct net_device_ops mtk_n
+@@ -2892,6 +2917,7 @@ static const struct net_device_ops mtk_n
  #ifdef CONFIG_NET_POLL_CONTROLLER
        .ndo_poll_controller    = mtk_poll_controller,
  #endif
  #ifdef CONFIG_NET_POLL_CONTROLLER
        .ndo_poll_controller    = mtk_poll_controller,
  #endif
@@ -78,7 +78,7 @@ Signed-off-by: Felix Fietkau <nbd@nbd.name>
  };
  
  static int mtk_add_mac(struct mtk_eth *eth, struct device_node *np)
  };
  
  static int mtk_add_mac(struct mtk_eth *eth, struct device_node *np)
-@@ -3154,6 +3180,10 @@ static int mtk_probe(struct platform_dev
+@@ -3157,6 +3183,10 @@ static int mtk_probe(struct platform_dev
                                   eth->base + MTK_ETH_PPE_BASE, 2);
                if (err)
                        goto err_free_dev;
                                   eth->base + MTK_ETH_PPE_BASE, 2);
                if (err)
                        goto err_free_dev;
index 18ddd0863ef355e1b3824c1d096a405b233b3df9..efb30f2e5070aaed182012fdd103fd03491776f2 100644 (file)
@@ -37,7 +37,7 @@ Signed-off-by: Felix Fietkau <nbd@nbd.name>
  #include <linux/mfd/syscon.h>
  #include <linux/regmap.h>
  #include <linux/clk.h>
  #include <linux/mfd/syscon.h>
  #include <linux/regmap.h>
  #include <linux/clk.h>
-@@ -2482,6 +2483,13 @@ static int mtk_hw_init(struct mtk_eth *e
+@@ -2485,6 +2486,13 @@ static int mtk_hw_init(struct mtk_eth *e
        if (ret)
                goto err_disable_pm;
  
        if (ret)
                goto err_disable_pm;
  
@@ -51,7 +51,7 @@ Signed-off-by: Felix Fietkau <nbd@nbd.name>
        if (MTK_HAS_CAPS(eth->soc->caps, MTK_SOC_MT7628)) {
                ret = device_reset(eth->dev);
                if (ret) {
        if (MTK_HAS_CAPS(eth->soc->caps, MTK_SOC_MT7628)) {
                ret = device_reset(eth->dev);
                if (ret) {
-@@ -3080,6 +3088,16 @@ static int mtk_probe(struct platform_dev
+@@ -3083,6 +3091,16 @@ static int mtk_probe(struct platform_dev
                }
        }
  
                }
        }