Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752173AbeAQHIB (ORCPT + 1 other); Wed, 17 Jan 2018 02:08:01 -0500 Received: from mx07-00178001.pphosted.com ([62.209.51.94]:51615 "EHLO mx07-00178001.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751080AbeAQHH7 (ORCPT ); Wed, 17 Jan 2018 02:07:59 -0500 Subject: Re: [PATCH net-next] net: stmmac: Fix reception of Broadcom switches tags To: Florian Fainelli , References: <20180116232545.22054-1-f.fainelli@gmail.com> CC: , , Alexandre Torgue , Maxime Ripard , Chen-Yu Tsai , open list , "moderated list:ARM/Allwinner sunXi SoC support" From: Giuseppe CAVALLARO Message-ID: <4fb40e11-a160-b9c7-aa02-f30a9de172bd@st.com> Date: Wed, 17 Jan 2018 08:06:58 +0100 User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:45.0) Gecko/20100101 Thunderbird/45.1.0 MIME-Version: 1.0 In-Reply-To: <20180116232545.22054-1-f.fainelli@gmail.com> Content-Type: text/plain; charset="windows-1252"; format=flowed Content-Transfer-Encoding: 7bit X-Originating-IP: [10.75.127.48] X-ClientProxiedBy: SFHDAG2NODE1.st.com (10.75.127.4) To SFHDAG4NODE1.st.com (10.75.127.10) X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:,, definitions=2018-01-17_02:,, signatures=0 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Return-Path: Hi Florian for gmac4.x and gmac3.x series the ACS bit is the Automatic Pad or CRC Stripping, so the core strips the Pad or FCS on frames if the value of the length field is < 1536 bytes. For MAC10-100 there is the Bit 8 (ASTP) of the reg0 that does the same if len is < 46bytes. In your patch I can just suggest to add a new field to strip the PAD/FCS w/o passing the whole netdev struct to the core_init. In the main driver, we could manage the pad-strip feature (also by using dt) or disable it in case of netdev_uses_dsa; then propagating this setting to the core_init or calling a new callback. What do you think? Regards Peppe On 1/17/2018 12:25 AM, Florian Fainelli wrote: > 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 > --- > drivers/net/ethernet/stmicro/stmmac/common.h | 2 +- > drivers/net/ethernet/stmicro/stmmac/dwmac-sun8i.c | 3 ++- > drivers/net/ethernet/stmicro/stmmac/dwmac1000_core.c | 12 +++++++++++- > drivers/net/ethernet/stmicro/stmmac/dwmac100_core.c | 3 ++- > drivers/net/ethernet/stmicro/stmmac/dwmac4_core.c | 11 ++++++++++- > drivers/net/ethernet/stmicro/stmmac/stmmac_main.c | 2 +- > 6 files changed, 27 insertions(+), 6 deletions(-) > > diff --git a/drivers/net/ethernet/stmicro/stmmac/common.h b/drivers/net/ethernet/stmicro/stmmac/common.h > index ce2ea2d491ac..2ffe76c0ff74 100644 > --- a/drivers/net/ethernet/stmicro/stmmac/common.h > +++ b/drivers/net/ethernet/stmicro/stmmac/common.h > @@ -474,7 +474,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 */ > diff --git a/drivers/net/ethernet/stmicro/stmmac/dwmac-sun8i.c b/drivers/net/ethernet/stmicro/stmmac/dwmac-sun8i.c > index 9eb7f65d8000..a3fa65b1ca8e 100644 > --- a/drivers/net/ethernet/stmicro/stmmac/dwmac-sun8i.c > +++ b/drivers/net/ethernet/stmicro/stmmac/dwmac-sun8i.c > @@ -483,7 +483,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; > diff --git a/drivers/net/ethernet/stmicro/stmmac/dwmac1000_core.c b/drivers/net/ethernet/stmicro/stmmac/dwmac1000_core.c > index 8a86340ff2d3..540d21786a43 100644 > --- a/drivers/net/ethernet/stmicro/stmmac/dwmac1000_core.c > +++ b/drivers/net/ethernet/stmicro/stmmac/dwmac1000_core.c > @@ -25,18 +25,28 @@ > #include > #include > #include > +#include > #include > #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) > diff --git a/drivers/net/ethernet/stmicro/stmmac/dwmac100_core.c b/drivers/net/ethernet/stmicro/stmmac/dwmac100_core.c > index 8ef517356313..c1ee427c42cb 100644 > --- a/drivers/net/ethernet/stmicro/stmmac/dwmac100_core.c > +++ b/drivers/net/ethernet/stmicro/stmmac/dwmac100_core.c > @@ -28,7 +28,8 @@ > #include > #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); > diff --git a/drivers/net/ethernet/stmicro/stmmac/dwmac4_core.c b/drivers/net/ethernet/stmicro/stmmac/dwmac4_core.c > index f3ed8f7853eb..6af5100d3cb2 100644 > --- a/drivers/net/ethernet/stmicro/stmmac/dwmac4_core.c > +++ b/drivers/net/ethernet/stmicro/stmmac/dwmac4_core.c > @@ -20,13 +20,22 @@ > #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_CONTROL_ACS; > + > if (mtu > 1500) > value |= GMAC_CONFIG_2K; > if (mtu > 2000) > diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c > index f99f14c35063..7ad841434ec8 100644 > --- a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c > +++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c > @@ -2527,7 +2527,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)