Received: by 10.223.148.5 with SMTP id 5csp6544105wrq; Wed, 17 Jan 2018 15:17:22 -0800 (PST) X-Google-Smtp-Source: ACJfBoupMhkLYWODgiDDedtUY5pePrZxMywiVZFB+hSaDeQPwIdvdl0lyBPwl7X3nvmwnXe5oqi9 X-Received: by 10.84.132.14 with SMTP id 14mr12571557ple.64.1516231042068; Wed, 17 Jan 2018 15:17:22 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1516231042; cv=none; d=google.com; s=arc-20160816; b=KNrX2Sa8v6sAa0UxeiAV6b69hI2hRYhLTfRQU14A9RP1VXvUC/HgAsImyeKcUnyE4A BqxqBhzw+Wv13bI/EMWHR+tmXqGjBYcpe9puUHyxpqixyElvT+O53WYsHySwZycciMei Z4/lhVG7niSa3qRFu2i/I4FNSShsq9f15KyffsqZ1Cn7sdWrMvasfgsYTS+Kex+i4mGj 03wzn1GZVsWauBgBZz0KK2zGzbpVsYUk+3dpO2x1OwAs2Ir1ulA1QmMhQn2G9l8Awxxa FkkjrC8bHPu1Bq1HQG9/+cucoVJqeUEdUHPi3n2LucWwrHFsu1VUle2tQ3x1/4v5TQoS Xrqw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject:dkim-signature :arc-authentication-results; bh=AhUl0URuY7J0uGfHvBhRC1rzxN20KJugeFzRvjyxf1U=; b=efkQSY1RHqo+KkroYio0Z3yQBe42G9RAC6XxZ3yecQFgROIjYeR2+pTNBDqJEsUrU/ BhryDmKw0VVPZQCTQPtzHuDyFvgNxPXn5gutl+duJsZ6FOkTanrf9pe1pmiRBDUJLo// GoPW+vDVHgpe1oirvh5iEFixalEkUvEsEirgh+vgHSWhcxlomXqAuvupGmrcFxnb9WiI my/ymXU1UdEGfC/j2DAjfHG1J4vAHRc/nAExJGoOkeDGXk+K1ChidObuRmisnsF6gjfv ScgI+5uYn8h6goVfeNfu0mtBPO4dZhKK2HXl7X/B2bnH9WsV3xnHjt3Klb2U0oPDfWZj vUnA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=jhgZr4NX; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id f12si4576045pgo.493.2018.01.17.15.17.07; Wed, 17 Jan 2018 15:17:22 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=jhgZr4NX; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753815AbeAQXQj (ORCPT + 99 others); Wed, 17 Jan 2018 18:16:39 -0500 Received: from mail-qt0-f196.google.com ([209.85.216.196]:37882 "EHLO mail-qt0-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752554AbeAQXQh (ORCPT ); Wed, 17 Jan 2018 18:16:37 -0500 Received: by mail-qt0-f196.google.com with SMTP id d54so13839207qtd.4; Wed, 17 Jan 2018 15:16:37 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=subject:to:cc:references:from:message-id:date:user-agent :mime-version:in-reply-to:content-language:content-transfer-encoding; bh=AhUl0URuY7J0uGfHvBhRC1rzxN20KJugeFzRvjyxf1U=; b=jhgZr4NXDi4yOB2LieY8vnNBVOrzxx45PEsUEgD0Q2UJPMcnl35DQwh4Mo6i7BL1j4 wYhl+Qg8uX0uo0nbn1RQW7S6nw5iAjRVd8zWDM241Vw3U/OT2e8rtmuTs/PXewtzdte8 gK8RjO3zDfUEQbsLMBZY5UTtjOYGA2zFngcZQBy4xe8TdLd4LTgcWX+84yAqLjykoCU6 9cbWZx+DfMitWUbfr+9bvTLNMugp0wDFVOj35XhrU9rzPsjCWQMtm21Ir9CU5ing++hs COuhS40jXLA0qJXGvw5kFNd4ZnebjApt9kgHit3Qp/+xGSK87tegZTQTZhkLDIJvxvRd pkdw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=AhUl0URuY7J0uGfHvBhRC1rzxN20KJugeFzRvjyxf1U=; b=uBq3szcuhcO54ecR6jSoO48d6PndSHeR0H8ahT6L5bfADBXP3EY5zwIApgAyywoGmF DFesejpxSK//6DNuD7KxYl79f/etjUouKAQp6c9dW4g9liQlIdj9ABro5cN29E19gbYb 4SbwcMIqEjDKIS2EHxmeGaknhJjQF+tANAwbl6qXbcNEbBzIxY4RCOKVFd1E+ab8SJ2B S8bMn0V5KHpvqpPNBqjX/eq2gAUDlAC57dXmeNwGUp06thelBvbBY577t6edc6W12ZFC naotYAGFnAJaTsOnEM7rNXzgsQwOEvUl/uyWXzaugjaMbhgjQhZKwt0DTixbUm+WII07 kkdg== X-Gm-Message-State: AKwxytepIqUwX9RA0jry8TzjBiGU5VgP8TLWrNQHqo7w9aeWo4hE974P 4S2t1Iu9PhpU8Cgb5eJlsSI= X-Received: by 10.237.38.229 with SMTP id q92mr22077546qtd.160.1516230996443; Wed, 17 Jan 2018 15:16:36 -0800 (PST) Received: from [10.69.41.93] ([192.19.223.250]) by smtp.googlemail.com with ESMTPSA id 41sm3904987qks.34.2018.01.17.15.16.34 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 17 Jan 2018 15:16:35 -0800 (PST) Subject: Re: [PATCH net-next] net: stmmac: Fix reception of Broadcom switches tags To: Giuseppe CAVALLARO , netdev@vger.kernel.org Cc: andrew@lunn.ch, vivien.didelot@savoirfairelinux.com, Alexandre Torgue , Maxime Ripard , Chen-Yu Tsai , open list , "moderated list:ARM/Allwinner sunXi SoC support" References: <20180116232545.22054-1-f.fainelli@gmail.com> <4fb40e11-a160-b9c7-aa02-f30a9de172bd@st.com> From: Florian Fainelli Message-ID: Date: Wed, 17 Jan 2018 15:16:33 -0800 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.5.0 MIME-Version: 1.0 In-Reply-To: <4fb40e11-a160-b9c7-aa02-f30a9de172bd@st.com> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Peppe, On 01/16/2018 11:06 PM, Giuseppe CAVALLARO wrote: > 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. OK, thanks for the detail on the older core, I will update my v2 to take that into account. > 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? I don't think adding a DT property is a good idea, because we can determine whether ACS is necessary or not at runtime when DSA with proprietary Ethernet switch tags is used or not using netdev_uses_dsa(). Having the DT property to configure whether ACS is turned on or off means that the Device Tree now describes a policy, rather than a capability, which is counter to the Device Tree spirit. Besides, this leaves room for making mistake, and this creates a support burden. When interfaced with a switch, the switch is guaranteed to egress 64 bytes (including FCS) packets towards stmmac, and the only thing we need to do is ensure that stmmac does the same thing. This is a small penalty to pay for small packets, and this is done only when DSA is used. Regarding passing a net_device to the core_init functions, this was done because dev->mtu was already accessed, and we might need to access additional net_device members in the future, 2 means we need to find a solution that scales, so passing the net_device around was a natural choice. Function pointers described in common.h are not exactly consistent in what type of arguments they take, so I did not see this as being a big problem. Thank you. > > 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) > > -- Florian