From patchwork Fri Jul 5 06:28:08 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Furong Xu <0x1207@gmail.com> X-Patchwork-Id: 13724450 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id CFEC8C30658 for ; Fri, 5 Jul 2024 06:31:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: MIME-Version:Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-Type: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References:List-Owner; bh=znD+DHZ03Xc1hLW5FfmfP3AjgTz3IHInSXaFKd4zqU4=; b=I3EIpapef2Q0C3Qrmtl5E/+/I2 F2nrhWYrA5wF007SCe+77doZp/xncyP9xKEB2HI3cL+LvEQC1FpFOXUKTUdhPV0exBaqEer7qAe2f pwSJg+Vgmd5EcV36vyYnFBoz+p7xVKZ/stRdEk82Ht86Lstz6M/4QxxZ8EAqHsiZBO74787xA9Frh 8PfC7jNZ8HRxMxXPPPQgEL5FmGRQaM3iRaCtZEsCwsNrUBSR0JL6wpEgzf+ss5tcKzcwjTi6nRENy v0OE6ZZhmh48OgSKY+Ef46Cxj1zVHrVio9k1bRvRfMgKNPZe45ApTGAK02wyZbEfXA0Narv8HMbQy /nwj/GOA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sPcTC-0000000F3RZ-3QbO; Fri, 05 Jul 2024 06:30:58 +0000 Received: from mail-pl1-x62f.google.com ([2607:f8b0:4864:20::62f]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sPcSu-0000000F3Kb-312g for linux-arm-kernel@lists.infradead.org; Fri, 05 Jul 2024 06:30:42 +0000 Received: by mail-pl1-x62f.google.com with SMTP id d9443c01a7336-1fb222a8eaeso9819395ad.3 for ; Thu, 04 Jul 2024 23:30:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1720161039; x=1720765839; darn=lists.infradead.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=znD+DHZ03Xc1hLW5FfmfP3AjgTz3IHInSXaFKd4zqU4=; b=jYQSxfS2V95+ZQixD9kfEzDELM29ZUmOdYXfPkAsdfYPBPXOBOh8tWgqTovl1GpBiH KWxY+hgaXQeoNDqCxpYhlUXL6HPaykOAZoD5U0mmKHWhgmgvJUGznSNwah8isuU5F2sH FEergjSn6ST0tnWaFJ4Z8il3lE9qjn7UafLePWqruGHqfcoT7ZjCOs3vw6rNBj+MkeEX zax9VqtfJY9YgyogpAiRt5zd3xcgk29plBzGpBD+sAyuISkMBRzzO1ErQuYybl6v0tDa NBKjP8IoHQZtMLCfxyGK6Xlo7L7b/vEgrujW0stOn8cG9OZNRo4tsbMgYtgS9v9vyyoL r4bw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1720161039; x=1720765839; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=znD+DHZ03Xc1hLW5FfmfP3AjgTz3IHInSXaFKd4zqU4=; b=XKXDGZw8RStMdWviGLoyLNdD7ISd5rijf8kA5SL9ktmPPRiZIy9Y7tg0Wfkz4EUpNz PysHdMbE7WWD7CwsNQPVjpwaNt/chLVgalHusTGu9+GICn8JCJ7oeoG6EcJ//gxkNlIE eUM0KG4JD/+krtEsRlFz4AE3gRoy7nLo5e7WQA5/lORBOUsswl/Rjwa+YSrGcWYPpDfN gecoVsYWptuGD276wUPFLdrqw54lltf9vISC0hRC8J8ApwiNedJO4q09pWp+A84eWUG1 ati+i3jDkwdg3j2clGHIVz5XCJ9ahS1We3xAZ2aFELea8y8havIeAWV97SCs80xxkK97 6n9A== X-Forwarded-Encrypted: i=1; AJvYcCWzTojB+GReaSJzHrkUmW1DEbiFrFxpC/2qVSKma1sPhxnd2Ujvv4qHmOP7+ix/DVJiDAanQGfv6xLuF6kKB/PF7QDZRgD5RjgFhJhykHiAkLsBITE= X-Gm-Message-State: AOJu0Yy0y0e37cMSJ/Um5xhOlJUqtt0WvL5zJAORLgmevzvu67chEbT2 +5rvPHch9vhEwOmLGGlDdvtEej/EjfgsWdYskRKBDTVn4hUziNBuAHhSjg== X-Google-Smtp-Source: AGHT+IGiekAtzI6KVFfNnBe7S/cylZJ4g2TdGcaP75Xl91oUKJ+AwWvYJL5v9f+jbUZu4wDMKFueRQ== X-Received: by 2002:a17:902:e751:b0:1fa:ac73:ca28 with SMTP id d9443c01a7336-1fb33e62d7fmr30255415ad.32.1720161039026; Thu, 04 Jul 2024 23:30:39 -0700 (PDT) Received: from localhost.localdomain ([129.146.253.192]) by smtp.googlemail.com with ESMTPSA id d9443c01a7336-1fb44752cf2sm9976255ad.268.2024.07.04.23.30.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 04 Jul 2024 23:30:38 -0700 (PDT) From: Furong Xu <0x1207@gmail.com> To: "David S. Miller" , Alexandre Torgue , Jose Abreu , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Maxime Coquelin , Joao Pinto Cc: netdev@vger.kernel.org, linux-stm32@st-md-mailman.stormreply.com, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, xfr@outlook.com, rock.xu@nio.com, Furong Xu <0x1207@gmail.com> Subject: [PATCH net-next v1] net: stmmac: xgmac: add support for HW-accelerated VLAN stripping Date: Fri, 5 Jul 2024 14:28:08 +0800 Message-Id: <20240705062808.805071-1-0x1207@gmail.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240704_233040_786433_C462156F X-CRM114-Status: GOOD ( 18.27 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Commit 750011e239a5 ("net: stmmac: Add support for HW-accelerated VLAN stripping") introduced MAC level VLAN tag stripping for gmac4 core. This patch extend the support to xgmac core. Signed-off-by: Furong Xu <0x1207@gmail.com> --- .../net/ethernet/stmicro/stmmac/dwxgmac2.h | 7 ++++ .../ethernet/stmicro/stmmac/dwxgmac2_core.c | 39 +++++++++++++++++++ .../ethernet/stmicro/stmmac/dwxgmac2_descs.c | 19 +++++++++ .../net/ethernet/stmicro/stmmac/stmmac_main.c | 2 +- 4 files changed, 66 insertions(+), 1 deletion(-) diff --git a/drivers/net/ethernet/stmicro/stmmac/dwxgmac2.h b/drivers/net/ethernet/stmicro/stmmac/dwxgmac2.h index 6a2c7d22df1e..db3217784cb0 100644 --- a/drivers/net/ethernet/stmicro/stmmac/dwxgmac2.h +++ b/drivers/net/ethernet/stmicro/stmmac/dwxgmac2.h @@ -60,6 +60,10 @@ #define XGMAC_VLAN_TAG 0x00000050 #define XGMAC_VLAN_EDVLP BIT(26) #define XGMAC_VLAN_VTHM BIT(25) +#define XGMAC_VLAN_TAG_CTRL_EVLRXS BIT(24) +#define XGMAC_VLAN_TAG_CTRL_EVLS GENMASK(22, 21) +#define XGMAC_VLAN_TAG_STRIP_NONE 0x0 +#define XGMAC_VLAN_TAG_STRIP_ALL 0x3 #define XGMAC_VLAN_DOVLTC BIT(20) #define XGMAC_VLAN_ESVL BIT(18) #define XGMAC_VLAN_ETV BIT(16) @@ -477,6 +481,7 @@ #define XGMAC_TDES3_VLTV BIT(16) #define XGMAC_TDES3_VT GENMASK(15, 0) #define XGMAC_TDES3_FL GENMASK(14, 0) +#define XGMAC_RDES0_VLAN_TAG GENMASK(15, 0) #define XGMAC_RDES2_HL GENMASK(9, 0) #define XGMAC_RDES3_OWN BIT(31) #define XGMAC_RDES3_CTXT BIT(30) @@ -490,6 +495,8 @@ #define XGMAC_L34T_IP4UDP 0x2 #define XGMAC_L34T_IP6TCP 0x9 #define XGMAC_L34T_IP6UDP 0xA +#define XGMAC_RDES3_L2T GENMASK(19, 16) +#define XGMAC_L2T_SINGLE_C_VLAN 0x9 #define XGMAC_RDES3_ES BIT(15) #define XGMAC_RDES3_PL GENMASK(13, 0) #define XGMAC_RDES3_TSD BIT(6) diff --git a/drivers/net/ethernet/stmicro/stmmac/dwxgmac2_core.c b/drivers/net/ethernet/stmicro/stmmac/dwxgmac2_core.c index 6a987cf598e4..89ac9ad6164a 100644 --- a/drivers/net/ethernet/stmicro/stmmac/dwxgmac2_core.c +++ b/drivers/net/ethernet/stmicro/stmmac/dwxgmac2_core.c @@ -1530,6 +1530,41 @@ static void dwxgmac3_fpe_configure(void __iomem *ioaddr, struct stmmac_fpe_cfg * writel(value, ioaddr + XGMAC_FPE_CTRL_STS); } +static void dwxgmac2_rx_hw_vlan(struct mac_device_info *hw, + struct dma_desc *rx_desc, struct sk_buff *skb) +{ + u16 vid; + + if (!hw->desc->get_rx_vlan_valid(rx_desc)) + return; + + vid = hw->desc->get_rx_vlan_tci(rx_desc); + + __vlan_hwaccel_put_tag(skb, htons(ETH_P_8021Q), vid); +} + +static void dwxgmac2_set_hw_vlan_mode(struct mac_device_info *hw) +{ + void __iomem *ioaddr = hw->pcsr; + u32 value = readl(ioaddr + XGMAC_VLAN_TAG); + + value &= ~XGMAC_VLAN_TAG_CTRL_EVLS; + + if (hw->hw_vlan_en) + /* Always strip VLAN on Receive */ + value |= FIELD_PREP(XGMAC_VLAN_TAG_CTRL_EVLS, + XGMAC_VLAN_TAG_STRIP_ALL); + else + /* Do not strip VLAN on Receive */ + value |= FIELD_PREP(XGMAC_VLAN_TAG_CTRL_EVLS, + XGMAC_VLAN_TAG_STRIP_NONE); + + /* Enable outer VLAN Tag in Rx DMA descriptor */ + value |= XGMAC_VLAN_TAG_CTRL_EVLRXS; + + writel(value, ioaddr + XGMAC_VLAN_TAG); +} + const struct stmmac_ops dwxgmac210_ops = { .core_init = dwxgmac2_core_init, .set_mac = dwxgmac2_set_mac, @@ -1571,6 +1606,8 @@ const struct stmmac_ops dwxgmac210_ops = { .config_l4_filter = dwxgmac2_config_l4_filter, .set_arp_offload = dwxgmac2_set_arp_offload, .fpe_configure = dwxgmac3_fpe_configure, + .rx_hw_vlan = dwxgmac2_rx_hw_vlan, + .set_hw_vlan_mode = dwxgmac2_set_hw_vlan_mode, }; static void dwxlgmac2_rx_queue_enable(struct mac_device_info *hw, u8 mode, @@ -1628,6 +1665,8 @@ const struct stmmac_ops dwxlgmac2_ops = { .config_l4_filter = dwxgmac2_config_l4_filter, .set_arp_offload = dwxgmac2_set_arp_offload, .fpe_configure = dwxgmac3_fpe_configure, + .rx_hw_vlan = dwxgmac2_rx_hw_vlan, + .set_hw_vlan_mode = dwxgmac2_set_hw_vlan_mode, }; int dwxgmac2_setup(struct stmmac_priv *priv) diff --git a/drivers/net/ethernet/stmicro/stmmac/dwxgmac2_descs.c b/drivers/net/ethernet/stmicro/stmmac/dwxgmac2_descs.c index fc82862a612c..f5293f75fbb4 100644 --- a/drivers/net/ethernet/stmicro/stmmac/dwxgmac2_descs.c +++ b/drivers/net/ethernet/stmicro/stmmac/dwxgmac2_descs.c @@ -67,6 +67,23 @@ static int dwxgmac2_get_tx_ls(struct dma_desc *p) return (le32_to_cpu(p->des3) & XGMAC_RDES3_LD) > 0; } +static u16 dwxgmac2_wrback_get_rx_vlan_tci(struct dma_desc *p) +{ + return (le32_to_cpu(p->des0) & XGMAC_RDES0_VLAN_TAG); +} + +static bool dwxgmac2_wrback_get_rx_vlan_valid(struct dma_desc *p) +{ + u32 l2_type; + + if (!(le32_to_cpu(p->des3) & XGMAC_RDES3_LD)) + return false; + + l2_type = FIELD_GET(XGMAC_RDES3_L2T, le32_to_cpu(p->des3)); + + return (l2_type == XGMAC_L2T_SINGLE_C_VLAN); +} + static int dwxgmac2_get_rx_frame_len(struct dma_desc *p, int rx_coe) { return (le32_to_cpu(p->des3) & XGMAC_RDES3_PL); @@ -349,6 +366,8 @@ const struct stmmac_desc_ops dwxgmac210_desc_ops = { .set_tx_owner = dwxgmac2_set_tx_owner, .set_rx_owner = dwxgmac2_set_rx_owner, .get_tx_ls = dwxgmac2_get_tx_ls, + .get_rx_vlan_tci = dwxgmac2_wrback_get_rx_vlan_tci, + .get_rx_vlan_valid = dwxgmac2_wrback_get_rx_vlan_valid, .get_rx_frame_len = dwxgmac2_get_rx_frame_len, .enable_tx_timestamp = dwxgmac2_enable_tx_timestamp, .get_tx_timestamp_status = dwxgmac2_get_tx_timestamp_status, diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c index 4b6a359e5a94..6f594c455d0f 100644 --- a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c +++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c @@ -7663,7 +7663,7 @@ int stmmac_dvr_probe(struct device *device, #ifdef STMMAC_VLAN_TAG_USED /* Both mac100 and gmac support receive VLAN tag detection */ ndev->features |= NETIF_F_HW_VLAN_CTAG_RX | NETIF_F_HW_VLAN_STAG_RX; - if (priv->plat->has_gmac4) { + if (priv->plat->has_gmac4 || priv->plat->has_xgmac) { ndev->hw_features |= NETIF_F_HW_VLAN_CTAG_RX; priv->hw->hw_vlan_en = true; }