net: stmmac: Fix reception of Broadcom switches tags
authorFlorian Fainelli <f.fainelli@gmail.com>
Thu, 18 Jan 2018 23:12:21 +0000 (15:12 -0800)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Tue, 5 Mar 2019 16:57:58 +0000 (17:57 +0100)
commit 8cad443eacf661796a740903a75cb8944c675b4e upstream.

Broadcom tags inserted by Broadcom switches put a 4 byte header after
the MAC SA and before the EtherType, which may look like some sort of 0
length LLC/SNAP packet (tcpdump and wireshark do think that way). With
ACS enabled in stmmac the packets were truncated to 8 bytes on
reception, whereas clearing this bit allowed normal reception to occur.

In order to make that possible, we need to pass a net_device argument to
the different core_init() functions and we are dependent on the Broadcom
tagger padding packets correctly (which it now does). To be as little
invasive as possible, this is only done for gmac1000 when the network
device is DSA-enabled (netdev_uses_dsa() returns true).

Signed-off-by: Florian Fainelli <f.fainelli@gmail.com>
Acked-by: Giuseppe Cavallaro <peppe.cavallaro@st.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
Cc: Niklas Cassel <niklas.cassel@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/net/ethernet/stmicro/stmmac/common.h
drivers/net/ethernet/stmicro/stmmac/dwmac-sun8i.c
drivers/net/ethernet/stmicro/stmmac/dwmac1000_core.c
drivers/net/ethernet/stmicro/stmmac/dwmac100_core.c
drivers/net/ethernet/stmicro/stmmac/dwmac4_core.c
drivers/net/ethernet/stmicro/stmmac/stmmac_main.c

index c87bc0a5efa3a4c814d8784c5b0bfb132dc13c6b..d824bf942a8fb370f5813accf292b19b27d01597 100644 (file)
@@ -475,7 +475,7 @@ struct mac_device_info;
 /* Helpers to program the MAC core */
 struct stmmac_ops {
        /* MAC core initialization */
-       void (*core_init)(struct mac_device_info *hw, int mtu);
+       void (*core_init)(struct mac_device_info *hw, struct net_device *dev);
        /* Enable the MAC RX/TX */
        void (*set_mac)(void __iomem *ioaddr, bool enable);
        /* Enable and verify that the IPC module is supported */
index 39c2122a4f26947ff564b773df454ce8fa05ec75..14866331eced602259e5e55bef65539097d61976 100644 (file)
@@ -477,7 +477,8 @@ static int sun8i_dwmac_init(struct platform_device *pdev, void *priv)
        return 0;
 }
 
-static void sun8i_dwmac_core_init(struct mac_device_info *hw, int mtu)
+static void sun8i_dwmac_core_init(struct mac_device_info *hw,
+                                 struct net_device *dev)
 {
        void __iomem *ioaddr = hw->pcsr;
        u32 v;
index 8a86340ff2d348ebbaabe29f73b51a67060542fe..540d21786a43b885fc98f2d5282538bf20792bfe 100644 (file)
 #include <linux/crc32.h>
 #include <linux/slab.h>
 #include <linux/ethtool.h>
+#include <net/dsa.h>
 #include <asm/io.h>
 #include "stmmac_pcs.h"
 #include "dwmac1000.h"
 
-static void dwmac1000_core_init(struct mac_device_info *hw, int mtu)
+static void dwmac1000_core_init(struct mac_device_info *hw,
+                               struct net_device *dev)
 {
        void __iomem *ioaddr = hw->pcsr;
        u32 value = readl(ioaddr + GMAC_CONTROL);
+       int mtu = dev->mtu;
 
        /* Configure GMAC core */
        value |= GMAC_CORE_INIT;
 
+       /* Clear ACS bit because Ethernet switch tagging formats such as
+        * Broadcom tags can look like invalid LLC/SNAP packets and cause the
+        * hardware to truncate packets on reception.
+        */
+       if (netdev_uses_dsa(dev))
+               value &= ~GMAC_CONTROL_ACS;
+
        if (mtu > 1500)
                value |= GMAC_CONTROL_2K;
        if (mtu > 2000)
index 8ef5173563134235903350167ca9d16b366881af..91b23f9db31ade76c05a6a7a638d41506ed9c93d 100644 (file)
 *******************************************************************************/
 
 #include <linux/crc32.h>
+#include <net/dsa.h>
 #include <asm/io.h>
 #include "dwmac100.h"
 
-static void dwmac100_core_init(struct mac_device_info *hw, int mtu)
+static void dwmac100_core_init(struct mac_device_info *hw,
+                              struct net_device *dev)
 {
        void __iomem *ioaddr = hw->pcsr;
        u32 value = readl(ioaddr + MAC_CONTROL);
 
-       writel((value | MAC_CORE_INIT), ioaddr + MAC_CONTROL);
+       value |= MAC_CORE_INIT;
+
+       /* Clear ASTP bit because Ethernet switch tagging formats such as
+        * Broadcom tags can look like invalid LLC/SNAP packets and cause the
+        * hardware to truncate packets on reception.
+        */
+       if (netdev_uses_dsa(dev))
+               value &= ~MAC_CONTROL_ASTP;
+
+       writel(value, ioaddr + MAC_CONTROL);
 
 #ifdef STMMAC_VLAN_TAG_USED
        writel(ETH_P_8021Q, ioaddr + MAC_VLAN1);
index e1d03489ae63f1a1d4f580f7f950589b80317f41..f2283feb03da65ace7f3ccb01d65618726788718 100644 (file)
 #include <linux/slab.h>
 #include <linux/ethtool.h>
 #include <linux/io.h>
+#include <net/dsa.h>
 #include "stmmac_pcs.h"
 #include "dwmac4.h"
 
-static void dwmac4_core_init(struct mac_device_info *hw, int mtu)
+static void dwmac4_core_init(struct mac_device_info *hw,
+                            struct net_device *dev)
 {
        void __iomem *ioaddr = hw->pcsr;
        u32 value = readl(ioaddr + GMAC_CONFIG);
+       int mtu = dev->mtu;
 
        value |= GMAC_CORE_INIT;
 
+       /* Clear ACS bit because Ethernet switch tagging formats such as
+        * Broadcom tags can look like invalid LLC/SNAP packets and cause the
+        * hardware to truncate packets on reception.
+        */
+       if (netdev_uses_dsa(dev))
+               value &= ~GMAC_CONFIG_ACS;
+
        if (mtu > 1500)
                value |= GMAC_CONFIG_2K;
        if (mtu > 2000)
index a901feaad4e154459e66f19202f64b9da59ffcd3..11e301670b2e8d118bd7c612ae008eabcd150728 100644 (file)
@@ -2497,7 +2497,7 @@ static int stmmac_hw_setup(struct net_device *dev, bool init_ptp)
        }
 
        /* Initialize the MAC Core */
-       priv->hw->mac->core_init(priv->hw, dev->mtu);
+       priv->hw->mac->core_init(priv->hw, dev);
 
        /* Initialize MTL*/
        if (priv->synopsys_id >= DWMAC_CORE_4_00)