Received: by 2002:a89:d88:0:b0:1fa:5c73:8e2d with SMTP id eb8csp2640243lqb; Tue, 28 May 2024 06:22:57 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUI+vzyO6nJ+6OrRXoDBJKspryTZ+BzrTJ/XCh/4pWi3kHYkO+LNGrw10daIVbjvExUYlfZW+Ox+Sq9GJf6g3bK5TRmwrlj8i5GN/xKWg== X-Google-Smtp-Source: AGHT+IEnuphk/1mla5Vm7I5uZiynySaB+f6M14NrQLfL6Az7VbXAJuSFCX4dfSrPFd2mnhBNEF70 X-Received: by 2002:a17:907:6d22:b0:a62:94ef:1f50 with SMTP id a640c23a62f3a-a6294ef2091mr980235966b.0.1716902576884; Tue, 28 May 2024 06:22:56 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1716902576; cv=pass; d=google.com; s=arc-20160816; b=dnyWtEzaBt71IGYDfe4VRDwtLFAR7RzHWdY+Tt51NB3i7GnThk8rtg/PCZ6vd7EHfm id0jQuUKxJjAKLKDls9HwUrOhw5Y8g8/CoPYHZGmc2U8+noSQNt6AXibn8h1n2Ecr+ay B9Pj1r4h4PMThLKf+8im2MVnP06Asp/5NJW4VOurLXK7F8JJW0ZwokDhMshtOAmqm7d7 zVi2wTsW35H8k7AR/p6GPESlH/WfBtH/0nD8OqhYgAZCBVjUq+MWF+TlSwHspVIPVn9I QHVBqRNNf1UpkF2DgtyPNKWb0Kq41TxEu7jL36tYEI+6WSNP0f88yCF+YyhpQiLAP2Xs pAJw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-disposition:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:message-id:subject:cc :to:from:date:dkim-signature; bh=+woYX1uxkRDOXtBX1F1Aj3xr5QPBx2mr8y8wsI+bzIE=; fh=C6X+v+glNz868xeaScoR6d5y+IN5vOKl5jfWg28yXAY=; b=N0eBWh3Nmf9nq3UztVxSJX94Yuf2Veh7rzPcnot7uuPhf3+SEvS7vuKnphZh+8wRxa K1fDP90onAsEbXJdyAkKbvdO75h13cpgqtMdL6NM4t5heucaHoVbkKQPnyeURIs38ag5 +S9v5D6RU67wOCZ0uaxrvJB3rz0w6OwBDNSCMJl7M3WY8KSjVMSst9nOicX0FJdo5atT zc743rG9xQwrekkdmRsF8HZmRl1kl+QRK6jSE3mb5ltel9ruxkMZSfnXLOeCn9JhGNJR 2JiLl/6PUYJoOkY86C5Zr81xS9nAFLvVcqapQpK/ef+Uo0f/vtD9wAEvlTc74JywUVXI 2JYA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@lunn.ch header.s=20171124 header.b=6V1EhJmy; arc=pass (i=1 spf=pass spfdomain=lunn.ch dkim=pass dkdomain=lunn.ch dmarc=pass fromdomain=lunn.ch); spf=pass (google.com: domain of linux-kernel+bounces-192360-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-192360-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=lunn.ch Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id a640c23a62f3a-a626cc3745csi514393566b.370.2024.05.28.06.22.56 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 28 May 2024 06:22:56 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-192360-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@lunn.ch header.s=20171124 header.b=6V1EhJmy; arc=pass (i=1 spf=pass spfdomain=lunn.ch dkim=pass dkdomain=lunn.ch dmarc=pass fromdomain=lunn.ch); spf=pass (google.com: domain of linux-kernel+bounces-192360-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-192360-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=lunn.ch Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 945641F24100 for ; Tue, 28 May 2024 13:05:07 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 23A5F16F822; Tue, 28 May 2024 13:02:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=lunn.ch header.i=@lunn.ch header.b="6V1EhJmy" Received: from vps0.lunn.ch (vps0.lunn.ch [156.67.10.101]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 881F316DEA0; Tue, 28 May 2024 13:02:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=156.67.10.101 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716901370; cv=none; b=KoE7mCatbBJXN9RHBHOcKXMf7nw+Kh07cbPm/OyLRE0vDpT9BXR5shT7y4Upqhnt/XCJQbQZwryBHYia1pdPRcoOapZvBu3Ho7xXQ3ajBEXckUiiapcN3mSpKz8Kp4FONWWLY+xMC71KP2JZhoX2HGQxR0EKYWgx7S5UmJsjyG4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716901370; c=relaxed/simple; bh=BlS+RNoJZf7uRqH8yZdZgXZub+cVsj79b4zET2aARhg=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=L63zuDOHKdshXj0GrTi93p+DJIcyUQQK+PC3BmTgZkLrPyZzDNK/Hn1TqmtEeNlngCAdCT8QwsB9ol95GKyI3D540CdoX0Ytphv7dYHxI+W/gRJZ2swiwq2NQrbEVzobBfZIZjTywPx6UBcwGgM0ZuGFSRUey4YGYiM6Nodc2bE= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=lunn.ch; spf=pass smtp.mailfrom=lunn.ch; dkim=pass (1024-bit key) header.d=lunn.ch header.i=@lunn.ch header.b=6V1EhJmy; arc=none smtp.client-ip=156.67.10.101 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=lunn.ch Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=lunn.ch DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lunn.ch; s=20171124; h=In-Reply-To:Content-Disposition:Content-Type:MIME-Version: References:Message-ID:Subject:Cc:To:From:Date:From:Sender:Reply-To:Subject: Date:Message-ID:To:Cc:MIME-Version:Content-Type:Content-Transfer-Encoding: Content-ID:Content-Description:Content-Disposition:In-Reply-To:References; bh=+woYX1uxkRDOXtBX1F1Aj3xr5QPBx2mr8y8wsI+bzIE=; b=6V1EhJmyF5HfLnX+zuf7uLpRue nlyqWF2L8F2B3o2iUCjLTwVrj9Gr6/QiCMSZmIJpMa/0oaAZQ2K96tk7ylb+MYbuE+XJjAzlezgkF dSa55z+3D/HDINRKUK0OZS/AsebKBWHMMOlEm+MINfSyPY+d/VuH9uqfbJJu+5xWLlNU=; Received: from andrew by vps0.lunn.ch with local (Exim 4.94.2) (envelope-from ) id 1sBwT3-00G9k6-EI; Tue, 28 May 2024 15:02:17 +0200 Date: Tue, 28 May 2024 15:02:17 +0200 From: Andrew Lunn To: "Ng, Boon Khai" Cc: Alexandre Torgue , Jose Abreu , "David S . Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Maxime Coquelin , "netdev@vger.kernel.org" , "linux-stm32@st-md-mailman.stormreply.com" , "linux-arm-kernel@lists.infradead.org" , "linux-kernel@vger.kernel.org" , "Ang, Tien Sung" , "G Thomas, Rohan" , "Looi, Hong Aun" , Andy Shevchenko , Ilpo Jarvinen Subject: Re: [Enable Designware XGMAC VLAN Stripping Feature v2 1/1] net: stmmac: dwxgmac2: Add support for HW-accelerated VLAN Stripping Message-ID: <48673551-cada-4194-865f-bc04c1e19c29@lunn.ch> References: <20240527093339.30883-1-boon.khai.ng@intel.com> <20240527093339.30883-2-boon.khai.ng@intel.com> <48176576-e1d2-4c45-967a-91cabb982a21@lunn.ch> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: > So, for this XGMAC VLAN patch, the idea of getting the VLAN id from the descriptor is the same, but > The register bit filed of getting the VLAN packet VALID is different. Thus, it need to be implemented separately. Please wrap your emails to around 78 characters. It is well know this driver is a mess. I just wanted to check you are not adding to be mess by simply cut/pasting rather than refactoring code. Lets look at the code. From your patch: +static void dwxgmac2_rx_hw_vlan(struct mac_device_info *hw, + struct dma_desc *rx_desc, struct sk_buff *skb) +{ + if (hw->desc->get_rx_vlan_valid(rx_desc)) { + u16 vid = hw->desc->get_rx_vlan_tci(rx_desc); + + __vlan_hwaccel_put_tag(skb, htons(ETH_P_8021Q), vid); + } +} + and static void dwmac4_rx_hw_vlan(struct mac_device_info *hw, struct dma_desc *rx_desc, struct sk_buff *skb) { if (hw->desc->get_rx_vlan_valid(rx_desc)) { u16 vid = hw->desc->get_rx_vlan_tci(rx_desc); __vlan_hwaccel_put_tag(skb, htons(ETH_P_8021Q), vid); } } Looks identical to me. From your patch: static void dwxgmac2_set_hw_vlan_mode(struct mac_device_info *hw) +{ + void __iomem *ioaddr = hw->pcsr; + u32 val = readl(ioaddr + XGMAC_VLAN_TAG); + + val &= ~XGMAC_VLAN_TAG_CTRL_EVLS_MASK; + + if (hw->hw_vlan_en) + /* Always strip VLAN on Receive */ + val |= XGMAC_VLAN_TAG_STRIP_ALL; + else + /* Do not strip VLAN on Receive */ + val |= XGMAC_VLAN_TAG_STRIP_NONE; + + /* Enable outer VLAN Tag in Rx DMA descriptro */ + val |= XGMAC_VLAN_TAG_CTRL_EVLRXS; + writel(val, ioaddr + XGMAC_VLAN_TAG); +} static void dwmac4_set_hw_vlan_mode(struct mac_device_info *hw) { void __iomem *ioaddr = hw->pcsr; u32 value = readl(ioaddr + GMAC_VLAN_TAG); value &= ~GMAC_VLAN_TAG_CTRL_EVLS_MASK; if (hw->hw_vlan_en) /* Always strip VLAN on Receive */ value |= GMAC_VLAN_TAG_STRIP_ALL; else /* Do not strip VLAN on Receive */ value |= GMAC_VLAN_TAG_STRIP_NONE; /* Enable outer VLAN Tag in Rx DMA descriptor */ value |= GMAC_VLAN_TAG_CTRL_EVLRXS; writel(value, ioaddr + GMAC_VLAN_TAG); } The basic flow is the same. Lets look at the #defines: #define XGMAC_VLAN_TAG 0x00000050 #define GMAC_VLAN_TAG 0x00000050 #define GMAC_VLAN_TAG_CTRL_EVLS_MASK GENMASK(22, 21) #define GMAC_VLAN_TAG_CTRL_EVLS_SHIFT 21 +#define XGMAC_VLAN_TAG_CTRL_EVLS_MASK GENMASK(22, 21) +#define XGMAC_VLAN_TAG_CTRL_EVLS_SHIFT 21 +#define XGMAC_VLAN_TAG_STRIP_NONE FIELD_PREP(XGMAC_VLAN_TAG_CTRL_EVLS_MASK, 0x0) +#define XGMAC_VLAN_TAG_STRIP_PASS FIELD_PREP(XGMAC_VLAN_TAG_CTRL_EVLS_MASK, 0x1) +#define XGMAC_VLAN_TAG_STRIP_FAIL FIELD_PREP(XGMAC_VLAN_TAG_CTRL_EVLS_MASK, 0x2) +#define XGMAC_VLAN_TAG_STRIP_ALL FIELD_PREP(XGMAC_VLAN_TAG_CTRL_EVLS_MASK, 0x3) #define GMAC_VLAN_TAG_STRIP_NONE (0x0 << GMAC_VLAN_TAG_CTRL_EVLS_SHIFT) #define GMAC_VLAN_TAG_STRIP_PASS (0x1 << GMAC_VLAN_TAG_CTRL_EVLS_SHIFT) #define GMAC_VLAN_TAG_STRIP_FAIL (0x2 << GMAC_VLAN_TAG_CTRL_EVLS_SHIFT) #define GMAC_VLAN_TAG_STRIP_ALL (0x3 << GMAC_VLAN_TAG_CTRL_EVLS_SHIFT) This is less obvious a straight cut/paste, but they are in fact identical. #define GMAC_VLAN_TAG_CTRL_EVLRXS BIT(24) #define XGMAC_VLAN_TAG_CTRL_EVLRXS BIT(24) So this also looks identical to me, but maybe i'm missing something subtle. +static inline u16 dwxgmac2_wrback_get_rx_vlan_tci(struct dma_desc *p) +{ + return le32_to_cpu(p->des0) & XGMAC_RDES0_VLAN_TAG_MASK; +} + static u16 dwmac4_wrback_get_rx_vlan_tci(struct dma_desc *p) { return (le32_to_cpu(p->des0) & RDES0_VLAN_TAG_MASK); } #define RDES0_VLAN_TAG_MASK GENMASK(15, 0) #define XGMAC_RDES0_VLAN_TAG_MASK GENMASK(15, 0) More identical code. +static inline bool dwxgmac2_wrback_get_rx_vlan_valid(struct dma_desc *p) +{ + u32 et_lt; + + et_lt = FIELD_GET(XGMAC_RDES3_ET_LT, le32_to_cpu(p->des3)); + + return et_lt >= XGMAC_ET_LT_VLAN_STAG && + et_lt <= XGMAC_ET_LT_DVLAN_STAG_CTAG; +} static bool dwmac4_wrback_get_rx_vlan_valid(struct dma_desc *p) { return ((le32_to_cpu(p->des3) & RDES3_LAST_DESCRIPTOR) && (le32_to_cpu(p->des3) & RDES3_RDES0_VALID)); } #define RDES3_RDES0_VALID BIT(25) #define RDES3_LAST_DESCRIPTOR BIT(28) #define XGMAC_RDES3_ET_LT GENMASK(19, 16) +#define XGMAC_ET_LT_VLAN_STAG 8 +#define XGMAC_ET_LT_VLAN_CTAG 9 +#define XGMAC_ET_LT_DVLAN_CTAG_CTAG 10 This does actually look different. Please take a step back and see if you can help clean up some of the mess in this driver by refactoring bits of identical code, rather than copy/pasting it. Andrew