Received: by 10.223.176.46 with SMTP id f43csp147994wra; Thu, 18 Jan 2018 15:14:11 -0800 (PST) X-Google-Smtp-Source: ACJfBosZ3CIIdPnM0SX3O6XylUQ6ZR/qoolj++JR/Log77j01htHYOBipHd8fSta5TMbCGHSrl7X X-Received: by 10.98.249.69 with SMTP id g5mr681530pfm.229.1516317251714; Thu, 18 Jan 2018 15:14:11 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1516317251; cv=none; d=google.com; s=arc-20160816; b=0/MlLZJMdS9h9Q0O50Km5OgMGVAKNEG679vbxSpSUG+zK16CJMQqk/tXw7UR9Jwtlg ZpqjqfAqhUxl80ryhQwyxtAanBNtXAEyfi7nbV+5/XuzrKMHtlXe9wUXjWfsCpKnRGgz G7B4LLJQBfVywlnMx7qaAKtmKoMp6HTE5Hdc7KWS/vEUFAPtZ84U3eudkG42q//HXZy5 3AgliekiU5PfqIzNRpOAsMZYvEdjaRu5jawrRPCyuOpwbBoxUhzLFt7qRyN0Wfei0sJ9 e1WyqCTUfwtX4tSTN+7Y54e2u5zGIzcCOLEbeMyb10FdsDLK8FlSFNu6X0VH6OliDcNJ yJ4g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :dkim-signature:arc-authentication-results; bh=VshVI/vcfGsPKgFm7V69mJPpSbpUh4bFqh1kXREjNFM=; b=R/Le57df8aEcqFbLCi+5rsXTCQNKMFHVCG3LFzzPh0kqbHBAWy5wg8ozc4mO/miPJ/ ZWVBdmrH8VeAPbteAOJvdsS7ANf+VqmapZcbp5913WZvLpIY2XWFa1W4PrpOb9AzNM2l yJqHA4FFUPc44Fi/pst8eQla49wpYTDyOOdimnfha2ZEEnUqP+NGPcAQDY/yksqnY86d pzGUluy+zcQwQ//9Yk2GKhkKugzoNyZHfDQK6pegMcIxMnyptIXvg7rWpAffohocqBvy uBgOU+5Df54XWx+SVTHGkMPD83WTMn6zQc1p/rRQ58q88MfBEVnvoPS66OEn7KODzdbN ZUCw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=NYN4EAgp; 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 r15si8060017pfb.86.2018.01.18.15.13.57; Thu, 18 Jan 2018 15:14:11 -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=NYN4EAgp; 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 S932702AbeARXMj (ORCPT + 99 others); Thu, 18 Jan 2018 18:12:39 -0500 Received: from mail-qt0-f194.google.com ([209.85.216.194]:40984 "EHLO mail-qt0-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932468AbeARXMb (ORCPT ); Thu, 18 Jan 2018 18:12:31 -0500 Received: by mail-qt0-f194.google.com with SMTP id i1so17697422qtj.8; Thu, 18 Jan 2018 15:12:31 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=VshVI/vcfGsPKgFm7V69mJPpSbpUh4bFqh1kXREjNFM=; b=NYN4EAgpknBSHjvlACoAPjlUsOO6h56HqwRywq/+UWTih/53GgzCQJj6zgQW8LpO28 g1oqpfcIlYtFwOR89Zvah7gNx6Zofe1t8wCPMNuJS4RdMj+PrCC+uQvvsxJctZNPHzCo 75LDWT8z+HmNsjehULqeCir7mKey0lyiQ4sitY9yKfAfxUEf9LJivKBKEfQYYbpbJnC0 encPratTSvD0c/3iRzkXpGUlOkFvKTdO1EKSlvJLZhRFksyRWQjKbUOnNCGakODPNZNZ mXD+r4nVNFpgvSmJSjEDjusltW0ib1m6b2YVaOdGhzOjIyT5SZlGFU7wTkqLWi/MDfvT X3Sg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=VshVI/vcfGsPKgFm7V69mJPpSbpUh4bFqh1kXREjNFM=; b=NUuAF7sYYjxcC5N21QRUcSD3PVOXNUIQa/X5mUNdE5Nae32GV02OOm5/Z7bZ6/tlE+ /pCoMOowrL23gz69NZRRSjrTbEPQ/2iXGBh8Tzid39rVXNSd1BTpApAfxBVHA0mDBWvq +ltHrPijFPX5f32CSud46ccx5fyr/5q3AJrmKGfQHyMhwwFQVVLYExsUeRWkTg/2SQ1K l9h0K4wFojwtG3aG2Bh9hMYsFkSAjEba8QxJahYI+jKDZMcva1UUSPystyDRSvynTDAn Rkc+nzQ8rnbq0UYeJUacfXK3OXLeUJZXiPT9dDy8KJ+gheJ8cz0aLbutXRrH8GBsop/l X4ig== X-Gm-Message-State: AKwxytcFmFwWZvwfsPWI4l3QQ++8ab1tV177tQydc66UysBnaBmFxa/S A3IuOYzY0Lc5asluxBTuP7Y3Shlx X-Received: by 10.55.51.18 with SMTP id z18mr19752507qkz.103.1516317150240; Thu, 18 Jan 2018 15:12:30 -0800 (PST) Received: from fainelli-desktop.igp.broadcom.net ([192.19.223.250]) by smtp.gmail.com with ESMTPSA id g8sm5747875qta.92.2018.01.18.15.12.26 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 18 Jan 2018 15:12:29 -0800 (PST) From: Florian Fainelli To: netdev@vger.kernel.org Cc: andrew@lunn.ch, vivien.didelot@savoirfairelinux.com, Florian Fainelli , Giuseppe Cavallaro , Alexandre Torgue , Maxime Ripard , Chen-Yu Tsai , linux-kernel@vger.kernel.org (open list), linux-arm-kernel@lists.infradead.org (moderated list:ARM/Allwinner sunXi SoC support) Subject: [PATCH net-next v2] net: stmmac: Fix reception of Broadcom switches tags Date: Thu, 18 Jan 2018 15:12:21 -0800 Message-Id: <20180118231222.19394-1-f.fainelli@gmail.com> X-Mailer: git-send-email 2.14.1 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 --- Changes in v2: - fixed build failure in dwmac4_core.c - updated dwmac100_core.c to also clear the ASTP bit 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 | 15 +++++++++++++-- drivers/net/ethernet/stmicro/stmmac/dwmac4_core.c | 12 +++++++++++- drivers/net/ethernet/stmicro/stmmac/stmmac_main.c | 2 +- 6 files changed, 39 insertions(+), 7 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..91b23f9db31a 100644 --- a/drivers/net/ethernet/stmicro/stmmac/dwmac100_core.c +++ b/drivers/net/ethernet/stmicro/stmmac/dwmac100_core.c @@ -25,15 +25,26 @@ *******************************************************************************/ #include +#include #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); - 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); diff --git a/drivers/net/ethernet/stmicro/stmmac/dwmac4_core.c b/drivers/net/ethernet/stmicro/stmmac/dwmac4_core.c index f3ed8f7853eb..ed222b20fcf1 100644 --- a/drivers/net/ethernet/stmicro/stmmac/dwmac4_core.c +++ b/drivers/net/ethernet/stmicro/stmmac/dwmac4_core.c @@ -17,16 +17,26 @@ #include #include #include +#include #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) 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) -- 2.14.1