From nobody Fri Apr 17 06:17:28 2026 Received: from relmlie6.idc.renesas.com (relmlor2.renesas.com [210.160.252.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 9B5E2362137; Mon, 23 Feb 2026 12:41:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=210.160.252.172 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1771850487; cv=none; b=Tmf0S6Z2Hs4Rt94CVkznu+GweRsgKjysSWnmPGRFtnrGZ6EeIaN7vmgNPaJSQfOJr2dHBJuaUIQKWBaSKWrui4XdAHaXYovsmW7RRd6pBDyu7CWE7uJRn/qVqGfQ2IlcKiTThCBKJc/2quP99WGxW/AxxeuKL/7th9BaDVtV05M= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1771850487; c=relaxed/simple; bh=ssm1ej6wHLtmi4HUkE/Q7GizkzFxTHV98lFTX/xFLyk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=nQmkWay/rmT7UTWe8nI5NGkeUUUhYnUYP4Y8NXITSi345U/X/Z4blPBHLUprqKdroLed6K3IWYvTbT6o/IBym4q0Vit5R1JEQutyquq1AG+vv79NwEEF6Am5fIEUFiQfEJoXORC9WeKbCV3pXBQKspDsT7F3W3WveCESC9XNkNQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=renesas.com; spf=pass smtp.mailfrom=renesas.com; arc=none smtp.client-ip=210.160.252.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=renesas.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=renesas.com X-CSE-ConnectionGUID: bMcOu8vCSmmFV+qHGkpgjg== X-CSE-MsgGUID: 6OlLtoNfQCiGn3FFGYi9xw== Received: from unknown (HELO relmlir6.idc.renesas.com) ([10.200.68.152]) by relmlie6.idc.renesas.com with ESMTP; 23 Feb 2026 21:41:18 +0900 Received: from vm01.adwin.renesas.com (unknown [10.226.92.12]) by relmlir6.idc.renesas.com (Postfix) with ESMTP id A777C41AAEBA; Mon, 23 Feb 2026 21:41:11 +0900 (JST) From: Ovidiu Panait To: andrew+netdev@lunn.ch, davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, mcoquelin.stm32@gmail.com, alexandre.torgue@foss.st.com, linux@armlinux.org.uk, rmk+kernel@armlinux.org.uk, maxime.chevallier@bootlin.com, boon.khai.ng@altera.com, rohan.g.thomas@altera.com, vladimir.oltean@nxp.com, hayashi.kunihiko@socionext.com, matthew.gerlach@altera.com, vee.khee.wong@intel.com, boon.leong.ong@intel.com, kim.tatt.chuah@intel.com Cc: netdev@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-stm32@st-md-mailman.stormreply.com, linux-kernel@vger.kernel.org Subject: [PATCH net-next 1/4] net: stmmac: Fix error handling in VLAN add and delete paths Date: Mon, 23 Feb 2026 12:40:59 +0000 Message-ID: <20260223124102.120432-2-ovidiu.panait.rb@renesas.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260223124102.120432-1-ovidiu.panait.rb@renesas.com> References: <20260223124102.120432-1-ovidiu.panait.rb@renesas.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" stmmac_vlan_rx_add_vid() updates active_vlans and the VLAN hash register before writing the HW filter entry. If the filter write fails, it leaves a stale VID in active_vlans and the hash register. stmmac_vlan_rx_kill_vid() has the reverse problem: it clears active_vlans before removing the HW filter. On failure, the VID is gone from active_vlans but still present in the HW filter table. To fix this, reorder the operations to update the hash table first, then attempt the HW filter operation. If the HW filter fails, roll back both the active_vlans bitmap and the hash table by calling stmmac_vlan_update() again. Fixes: ed64639bc1e0 ("net: stmmac: Add support for VLAN Rx filtering") Signed-off-by: Ovidiu Panait --- .../net/ethernet/stmicro/stmmac/stmmac_main.c | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c b/drivers/ne= t/ethernet/stmicro/stmmac/stmmac_main.c index 82375d34ad57..f2f120ddba46 100644 --- a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c +++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c @@ -6798,9 +6798,13 @@ static int stmmac_vlan_rx_add_vid(struct net_device = *ndev, __be16 proto, u16 vid =20 if (priv->hw->num_vlan) { ret =3D stmmac_add_hw_vlan_rx_fltr(priv, ndev, priv->hw, proto, vid); - if (ret) + if (ret) { + clear_bit(vid, priv->active_vlans); + stmmac_vlan_update(priv, is_double); goto err_pm_put; + } } + err_pm_put: pm_runtime_put(priv->device); =20 @@ -6824,15 +6828,21 @@ static int stmmac_vlan_rx_kill_vid(struct net_devic= e *ndev, __be16 proto, u16 vi is_double =3D true; =20 clear_bit(vid, priv->active_vlans); + ret =3D stmmac_vlan_update(priv, is_double); + if (ret) { + set_bit(vid, priv->active_vlans); + goto del_vlan_error; + } =20 if (priv->hw->num_vlan) { ret =3D stmmac_del_hw_vlan_rx_fltr(priv, ndev, priv->hw, proto, vid); - if (ret) + if (ret) { + set_bit(vid, priv->active_vlans); + stmmac_vlan_update(priv, is_double); goto del_vlan_error; + } } =20 - ret =3D stmmac_vlan_update(priv, is_double); - del_vlan_error: pm_runtime_put(priv->device); =20 --=20 2.34.1 From nobody Fri Apr 17 06:17:28 2026 Received: from relmlie5.idc.renesas.com (relmlor1.renesas.com [210.160.252.171]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 2AE213659E0; Mon, 23 Feb 2026 12:41:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=210.160.252.171 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1771850488; cv=none; b=a1Vt2uhXr6UrUzCeCBzDjbrpzfJYZu2YZ4JhGvUknqbctpORXpUyt3Svy9mYRy8PopO3uyIrra8FXhD8RbdCDot5nX2JPG+swcj5KPVNWqsyDR5euB503PAY/1QLSloUr9YoOA2us6Kd9MRDOPjLE/nEwEfOlNZS7rDmjUUmqxI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1771850488; c=relaxed/simple; bh=V9qSZ1YOacGlIYDV7EenF11qDRp/oAc/mQ1Jr8b558o=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=kyZ7dswzh9lK4X44CWm1RzTFNT9MFeO13ACg0Q0lOps905F0b8ZtmShDJsS+Xru+HWpmdQjcnrSiCVBewok/3y5/CxZM6SuhoWLziDl6I1VtvLdHfwHgLR3KNmf2RsmC/Xb5VIMsFxV2+T1gNKmhxFcVR8bNHRqLnVu7hV89Tbs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=renesas.com; spf=pass smtp.mailfrom=renesas.com; arc=none smtp.client-ip=210.160.252.171 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=renesas.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=renesas.com X-CSE-ConnectionGUID: 73CCg/46RoWhw5x0yhoOvw== X-CSE-MsgGUID: Wv1cVRZARwmnx9IONG74hA== Received: from unknown (HELO relmlir6.idc.renesas.com) ([10.200.68.152]) by relmlie5.idc.renesas.com with ESMTP; 23 Feb 2026 21:41:25 +0900 Received: from vm01.adwin.renesas.com (unknown [10.226.92.12]) by relmlir6.idc.renesas.com (Postfix) with ESMTP id 1AB1F41AB637; Mon, 23 Feb 2026 21:41:18 +0900 (JST) From: Ovidiu Panait To: andrew+netdev@lunn.ch, davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, mcoquelin.stm32@gmail.com, alexandre.torgue@foss.st.com, linux@armlinux.org.uk, rmk+kernel@armlinux.org.uk, maxime.chevallier@bootlin.com, boon.khai.ng@altera.com, rohan.g.thomas@altera.com, vladimir.oltean@nxp.com, hayashi.kunihiko@socionext.com, matthew.gerlach@altera.com, vee.khee.wong@intel.com, boon.leong.ong@intel.com, kim.tatt.chuah@intel.com Cc: netdev@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-stm32@st-md-mailman.stormreply.com, linux-kernel@vger.kernel.org Subject: [PATCH net-next 2/4] net: stmmac: Improve double VLAN handling Date: Mon, 23 Feb 2026 12:41:00 +0000 Message-ID: <20260223124102.120432-3-ovidiu.panait.rb@renesas.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260223124102.120432-1-ovidiu.panait.rb@renesas.com> References: <20260223124102.120432-1-ovidiu.panait.rb@renesas.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" The double VLAN bits (EDVLP, ESVL, DOVLTC) are handled inconsistently between the two vlan_update_hash() implementations: - dwxgmac2_update_vlan_hash() explicitly clears the double VLAN bits when is_double is false, meaning that adding a 802.1Q VLAN will disable double VLAN mode: $ ip link add link eth0 name eth0.200 type vlan id 200 protocol 802.1ad $ ip link add link eth0 name eth0.100 type vlan id 100 # Double VLAN bits no longer set - vlan_update_hash() sets these bits and only clears them when the last VLAN has been removed, so double VLAN mode remains enabled even after all 802.1AD VLANs are removed. Address both issues by tracking the number of active 802.1AD VLANs in priv->num_double_vlans. Pass this count to stmmac_vlan_update() so both implementations correctly set the double VLAN bits when any 802.1AD VLAN is active, and clear them only when none remain. Also update vlan_update_hash() to explicitly clear the double VLAN bits when is_double is false, matching the dwxgmac2 behavior. Signed-off-by: Ovidiu Panait --- drivers/net/ethernet/stmicro/stmmac/stmmac.h | 1 + .../net/ethernet/stmicro/stmmac/stmmac_main.c | 16 ++++++++++++---- .../net/ethernet/stmicro/stmmac/stmmac_vlan.c | 8 ++++++++ 3 files changed, 21 insertions(+), 4 deletions(-) diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac.h b/drivers/net/eth= ernet/stmicro/stmmac/stmmac.h index 51c96a738151..33667a26708c 100644 --- a/drivers/net/ethernet/stmicro/stmmac/stmmac.h +++ b/drivers/net/ethernet/stmicro/stmmac/stmmac.h @@ -323,6 +323,7 @@ struct stmmac_priv { void __iomem *ptpaddr; void __iomem *estaddr; unsigned long active_vlans[BITS_TO_LONGS(VLAN_N_VID)]; + unsigned int num_double_vlans; int sfty_irq; int sfty_ce_irq; int sfty_ue_irq; diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c b/drivers/ne= t/ethernet/stmicro/stmmac/stmmac_main.c index f2f120ddba46..45f2f3492dbd 100644 --- a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c +++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c @@ -6779,6 +6779,7 @@ static int stmmac_vlan_update(struct stmmac_priv *pri= v, bool is_double) static int stmmac_vlan_rx_add_vid(struct net_device *ndev, __be16 proto, u= 16 vid) { struct stmmac_priv *priv =3D netdev_priv(ndev); + unsigned int num_double_vlans; bool is_double =3D false; int ret; =20 @@ -6790,7 +6791,8 @@ static int stmmac_vlan_rx_add_vid(struct net_device *= ndev, __be16 proto, u16 vid is_double =3D true; =20 set_bit(vid, priv->active_vlans); - ret =3D stmmac_vlan_update(priv, is_double); + num_double_vlans =3D priv->num_double_vlans + is_double; + ret =3D stmmac_vlan_update(priv, num_double_vlans); if (ret) { clear_bit(vid, priv->active_vlans); goto err_pm_put; @@ -6800,11 +6802,13 @@ static int stmmac_vlan_rx_add_vid(struct net_device= *ndev, __be16 proto, u16 vid ret =3D stmmac_add_hw_vlan_rx_fltr(priv, ndev, priv->hw, proto, vid); if (ret) { clear_bit(vid, priv->active_vlans); - stmmac_vlan_update(priv, is_double); + stmmac_vlan_update(priv, priv->num_double_vlans); goto err_pm_put; } } =20 + priv->num_double_vlans =3D num_double_vlans; + err_pm_put: pm_runtime_put(priv->device); =20 @@ -6817,6 +6821,7 @@ static int stmmac_vlan_rx_add_vid(struct net_device *= ndev, __be16 proto, u16 vid static int stmmac_vlan_rx_kill_vid(struct net_device *ndev, __be16 proto, = u16 vid) { struct stmmac_priv *priv =3D netdev_priv(ndev); + unsigned int num_double_vlans; bool is_double =3D false; int ret; =20 @@ -6828,7 +6833,8 @@ static int stmmac_vlan_rx_kill_vid(struct net_device = *ndev, __be16 proto, u16 vi is_double =3D true; =20 clear_bit(vid, priv->active_vlans); - ret =3D stmmac_vlan_update(priv, is_double); + num_double_vlans =3D priv->num_double_vlans - is_double; + ret =3D stmmac_vlan_update(priv, num_double_vlans); if (ret) { set_bit(vid, priv->active_vlans); goto del_vlan_error; @@ -6838,11 +6844,13 @@ static int stmmac_vlan_rx_kill_vid(struct net_devic= e *ndev, __be16 proto, u16 vi ret =3D stmmac_del_hw_vlan_rx_fltr(priv, ndev, priv->hw, proto, vid); if (ret) { set_bit(vid, priv->active_vlans); - stmmac_vlan_update(priv, is_double); + stmmac_vlan_update(priv, priv->num_double_vlans); goto del_vlan_error; } } =20 + priv->num_double_vlans =3D num_double_vlans; + del_vlan_error: pm_runtime_put(priv->device); =20 diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_vlan.c b/drivers/ne= t/ethernet/stmicro/stmmac/stmmac_vlan.c index b18404dd5a8b..de1a70e1c86e 100644 --- a/drivers/net/ethernet/stmicro/stmmac/stmmac_vlan.c +++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_vlan.c @@ -183,6 +183,10 @@ static void vlan_update_hash(struct mac_device_info *h= w, u32 hash, value |=3D VLAN_EDVLP; value |=3D VLAN_ESVL; value |=3D VLAN_DOVLTC; + } else { + value &=3D ~VLAN_EDVLP; + value &=3D ~VLAN_ESVL; + value &=3D ~VLAN_DOVLTC; } =20 writel(value, ioaddr + VLAN_TAG); @@ -193,6 +197,10 @@ static void vlan_update_hash(struct mac_device_info *h= w, u32 hash, value |=3D VLAN_EDVLP; value |=3D VLAN_ESVL; value |=3D VLAN_DOVLTC; + } else { + value &=3D ~VLAN_EDVLP; + value &=3D ~VLAN_ESVL; + value &=3D ~VLAN_DOVLTC; } =20 writel(value | perfect_match, ioaddr + VLAN_TAG); --=20 2.34.1 From nobody Fri Apr 17 06:17:28 2026 Received: from relmlie6.idc.renesas.com (relmlor2.renesas.com [210.160.252.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 7A3793659F1; Mon, 23 Feb 2026 12:41:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=210.160.252.172 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1771850496; cv=none; b=bttQY8yfqZwc0wpJoCRpOY+5uUg+rDZX8XFL8Dx7k/qotHsVVgvKfWwdG/6os+Sq2sCp5jK1x24GH34K4QszMkbMEuHxb21oFqj6vCde5LmzPYrpF92gzy3/u2eBBckMzPUBP1g9bIVcfgz97RDevUTGzBat/5LMto02TTMdPRA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1771850496; c=relaxed/simple; bh=j4cL1P2Gxxi3TVnLIn9XYljLZhtaG+Egr2MCURCuAr0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=g0iB2O8YjpObuevNjuKcDJe1567Jv0yLxFvwzeC8UCyBSz3X1pAtKH6ax3Xo4wyABQmCx29sXZ+83JgZOCUFKbJ9qs4uRcFUI22WzALEupS9L+3OcnCKvddrbSGs4g30m34zbwTkUf4e8GZ7RI3SFoT50agQVZ2A/N+kmTAmwKI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=renesas.com; spf=pass smtp.mailfrom=renesas.com; arc=none smtp.client-ip=210.160.252.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=renesas.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=renesas.com X-CSE-ConnectionGUID: ek5THAtjQOeU0ucxkRYSnw== X-CSE-MsgGUID: jXeiQHxYQZ+5ur3JJSJJIg== Received: from unknown (HELO relmlir6.idc.renesas.com) ([10.200.68.152]) by relmlie6.idc.renesas.com with ESMTP; 23 Feb 2026 21:41:33 +0900 Received: from vm01.adwin.renesas.com (unknown [10.226.92.12]) by relmlir6.idc.renesas.com (Postfix) with ESMTP id 7933A41AB637; Mon, 23 Feb 2026 21:41:26 +0900 (JST) From: Ovidiu Panait To: andrew+netdev@lunn.ch, davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, mcoquelin.stm32@gmail.com, alexandre.torgue@foss.st.com, linux@armlinux.org.uk, rmk+kernel@armlinux.org.uk, maxime.chevallier@bootlin.com, boon.khai.ng@altera.com, rohan.g.thomas@altera.com, vladimir.oltean@nxp.com, hayashi.kunihiko@socionext.com, matthew.gerlach@altera.com, vee.khee.wong@intel.com, boon.leong.ong@intel.com, kim.tatt.chuah@intel.com Cc: netdev@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-stm32@st-md-mailman.stormreply.com, linux-kernel@vger.kernel.org Subject: [PATCH net-next 3/4] net: stmmac: Add write_hw parameter to VLAN filter operations Date: Mon, 23 Feb 2026 12:41:01 +0000 Message-ID: <20260223124102.120432-4-ovidiu.panait.rb@renesas.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260223124102.120432-1-ovidiu.panait.rb@renesas.com> References: <20260223124102.120432-1-ovidiu.panait.rb@renesas.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Add a write_hw parameter to the VLAN add/delete HW filter functions and to stmmac_vlan_update(). This flag controls whether the actual hardware register accesses are performed. When set to false, only the software state is updated. The next commit will use this to defer hardware writes when the interface is down. No functional change. Signed-off-by: Ovidiu Panait --- drivers/net/ethernet/stmicro/stmmac/hwif.h | 6 ++-- .../net/ethernet/stmicro/stmmac/stmmac_main.c | 23 ++++++++----- .../net/ethernet/stmicro/stmmac/stmmac_vlan.c | 34 ++++++++++++------- 3 files changed, 40 insertions(+), 23 deletions(-) diff --git a/drivers/net/ethernet/stmicro/stmmac/hwif.h b/drivers/net/ether= net/stmicro/stmmac/hwif.h index 0db96a387259..d7598c76251f 100644 --- a/drivers/net/ethernet/stmicro/stmmac/hwif.h +++ b/drivers/net/ethernet/stmicro/stmmac/hwif.h @@ -647,10 +647,12 @@ struct stmmac_vlan_ops { void (*set_hw_vlan_mode)(struct mac_device_info *hw); int (*add_hw_vlan_rx_fltr)(struct net_device *dev, struct mac_device_info *hw, - __be16 proto, u16 vid); + __be16 proto, u16 vid, + bool write_hw); int (*del_hw_vlan_rx_fltr)(struct net_device *dev, struct mac_device_info *hw, - __be16 proto, u16 vid); + __be16 proto, u16 vid, + bool write_hw); void (*restore_hw_vlan_rx_fltr)(struct net_device *dev, struct mac_device_info *hw); }; diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c b/drivers/ne= t/ethernet/stmicro/stmmac/stmmac_main.c index 45f2f3492dbd..536668a0d6dd 100644 --- a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c +++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c @@ -6748,7 +6748,8 @@ static u32 stmmac_vid_crc32_le(__le16 vid_le) return crc; } =20 -static int stmmac_vlan_update(struct stmmac_priv *priv, bool is_double) +static int stmmac_vlan_update(struct stmmac_priv *priv, bool is_double, + bool write_hw) { u32 crc, hash =3D 0; u16 pmatch =3D 0; @@ -6770,7 +6771,11 @@ static int stmmac_vlan_update(struct stmmac_priv *pr= iv, bool is_double) hash =3D 0; } =20 - return stmmac_update_vlan_hash(priv, priv->hw, hash, pmatch, is_double); + if (write_hw) + return stmmac_update_vlan_hash(priv, priv->hw, hash, pmatch, + is_double); + + return 0; } =20 /* FIXME: This may need RXC to be running, but it may be called with BH @@ -6792,17 +6797,18 @@ static int stmmac_vlan_rx_add_vid(struct net_device= *ndev, __be16 proto, u16 vid =20 set_bit(vid, priv->active_vlans); num_double_vlans =3D priv->num_double_vlans + is_double; - ret =3D stmmac_vlan_update(priv, num_double_vlans); + ret =3D stmmac_vlan_update(priv, num_double_vlans, true); if (ret) { clear_bit(vid, priv->active_vlans); goto err_pm_put; } =20 if (priv->hw->num_vlan) { - ret =3D stmmac_add_hw_vlan_rx_fltr(priv, ndev, priv->hw, proto, vid); + ret =3D stmmac_add_hw_vlan_rx_fltr(priv, ndev, priv->hw, proto, + vid, true); if (ret) { clear_bit(vid, priv->active_vlans); - stmmac_vlan_update(priv, priv->num_double_vlans); + stmmac_vlan_update(priv, priv->num_double_vlans, true); goto err_pm_put; } } @@ -6834,17 +6840,18 @@ static int stmmac_vlan_rx_kill_vid(struct net_devic= e *ndev, __be16 proto, u16 vi =20 clear_bit(vid, priv->active_vlans); num_double_vlans =3D priv->num_double_vlans - is_double; - ret =3D stmmac_vlan_update(priv, num_double_vlans); + ret =3D stmmac_vlan_update(priv, num_double_vlans, true); if (ret) { set_bit(vid, priv->active_vlans); goto del_vlan_error; } =20 if (priv->hw->num_vlan) { - ret =3D stmmac_del_hw_vlan_rx_fltr(priv, ndev, priv->hw, proto, vid); + ret =3D stmmac_del_hw_vlan_rx_fltr(priv, ndev, priv->hw, proto, + vid, true); if (ret) { set_bit(vid, priv->active_vlans); - stmmac_vlan_update(priv, priv->num_double_vlans); + stmmac_vlan_update(priv, priv->num_double_vlans, true); goto del_vlan_error; } } diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_vlan.c b/drivers/ne= t/ethernet/stmicro/stmmac/stmmac_vlan.c index de1a70e1c86e..b74c173da1b5 100644 --- a/drivers/net/ethernet/stmicro/stmmac/stmmac_vlan.c +++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_vlan.c @@ -53,7 +53,8 @@ static int vlan_write_filter(struct net_device *dev, =20 static int vlan_add_hw_rx_fltr(struct net_device *dev, struct mac_device_info *hw, - __be16 proto, u16 vid) + __be16 proto, u16 vid, + bool write_hw) { int index =3D -1; u32 val =3D 0; @@ -76,7 +77,8 @@ static int vlan_add_hw_rx_fltr(struct net_device *dev, } =20 hw->vlan_filter[0] =3D vid; - vlan_write_single(dev, vid); + if (write_hw) + vlan_write_single(dev, vid); =20 return 0; } @@ -97,17 +99,21 @@ static int vlan_add_hw_rx_fltr(struct net_device *dev, return -EPERM; } =20 - ret =3D vlan_write_filter(dev, hw, index, val); + if (write_hw) { + ret =3D vlan_write_filter(dev, hw, index, val); + if (ret) + return ret; + } =20 - if (!ret) - hw->vlan_filter[index] =3D val; + hw->vlan_filter[index] =3D val; =20 - return ret; + return 0; } =20 static int vlan_del_hw_rx_fltr(struct net_device *dev, struct mac_device_info *hw, - __be16 proto, u16 vid) + __be16 proto, u16 vid, + bool write_hw) { int i, ret =3D 0; =20 @@ -115,7 +121,8 @@ static int vlan_del_hw_rx_fltr(struct net_device *dev, if (hw->num_vlan =3D=3D 1) { if ((hw->vlan_filter[0] & VLAN_TAG_VID) =3D=3D vid) { hw->vlan_filter[0] =3D 0; - vlan_write_single(dev, 0); + if (write_hw) + vlan_write_single(dev, 0); } return 0; } @@ -124,12 +131,13 @@ static int vlan_del_hw_rx_fltr(struct net_device *dev, for (i =3D 0; i < hw->num_vlan; i++) { if ((hw->vlan_filter[i] & VLAN_TAG_DATA_VEN) && ((hw->vlan_filter[i] & VLAN_TAG_DATA_VID) =3D=3D vid)) { - ret =3D vlan_write_filter(dev, hw, i, 0); + if (write_hw) { + ret =3D vlan_write_filter(dev, hw, i, 0); + if (ret) + return ret; + } =20 - if (!ret) - hw->vlan_filter[i] =3D 0; - else - return ret; + hw->vlan_filter[i] =3D 0; } } =20 --=20 2.34.1 From nobody Fri Apr 17 06:17:28 2026 Received: from relmlie6.idc.renesas.com (relmlor2.renesas.com [210.160.252.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id F1B9C366044; Mon, 23 Feb 2026 12:41:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=210.160.252.172 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1771850502; cv=none; b=eC6AspBmMsMB/lWsyoAvY3E71LYNHY62dRvVrUEbqNP4Y+KfHXY56fh8T+PD4U9RDu19fxTE5bkIRmBNqTSNYUUZ5fu7tHokMij9oFi4OdkLsDZDGduiwi0ofv/hsBHzmoaarrVznD5zGcK+0VWymeTyY+3DznvlEOTFPLEEaaA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1771850502; c=relaxed/simple; bh=my3ie864iTaDCoQbedVs3qsRAL84M9L7UnzCUL3bZ9s=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=hPvE0w8zNOtLAqvVptXaQrr5hXS74ys0LSZEeYqBGpeWM4viCdqPjFfYhnAeULGwr/N+U6XRnTYWBMQ0MHqC1JLgHbEejwcuJmqjFATBn4iXszGYsXOmkpeypDpmPHxLUsDoq5LfFQTNNhapw24adhVW9VdQDQYDNopFSLOaaDc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=renesas.com; spf=pass smtp.mailfrom=renesas.com; arc=none smtp.client-ip=210.160.252.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=renesas.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=renesas.com X-CSE-ConnectionGUID: RATekyJ1R5yKNNf7lStgUQ== X-CSE-MsgGUID: y0YMchb9Q8eDUObnCEjfig== Received: from unknown (HELO relmlir6.idc.renesas.com) ([10.200.68.152]) by relmlie6.idc.renesas.com with ESMTP; 23 Feb 2026 21:41:40 +0900 Received: from vm01.adwin.renesas.com (unknown [10.226.92.12]) by relmlir6.idc.renesas.com (Postfix) with ESMTP id DEB7641AB637; Mon, 23 Feb 2026 21:41:33 +0900 (JST) From: Ovidiu Panait To: andrew+netdev@lunn.ch, davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, mcoquelin.stm32@gmail.com, alexandre.torgue@foss.st.com, linux@armlinux.org.uk, rmk+kernel@armlinux.org.uk, maxime.chevallier@bootlin.com, boon.khai.ng@altera.com, rohan.g.thomas@altera.com, vladimir.oltean@nxp.com, hayashi.kunihiko@socionext.com, matthew.gerlach@altera.com, vee.khee.wong@intel.com, boon.leong.ong@intel.com, kim.tatt.chuah@intel.com Cc: netdev@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-stm32@st-md-mailman.stormreply.com, linux-kernel@vger.kernel.org Subject: [PATCH net-next 4/4] net: stmmac: Defer VLAN HW configuration when interface is down Date: Mon, 23 Feb 2026 12:41:02 +0000 Message-ID: <20260223124102.120432-5-ovidiu.panait.rb@renesas.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260223124102.120432-1-ovidiu.panait.rb@renesas.com> References: <20260223124102.120432-1-ovidiu.panait.rb@renesas.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" VLAN register accesses on the MAC side require the PHY RX clock to be active. When the network interface is down, the PHY is suspended and the RX clock is unavailable, causing VLAN operations to fail with timeouts. The VLAN core automatically removes VID 0 after the interface goes down and re-adds it when it comes back up, so these timeouts happen during normal interface down/up: # ip link set end1 down renesas-gbeth 15c40000.ethernet end1: Timeout accessing MAC_VLAN_Tag_Fi= lter renesas-gbeth 15c40000.ethernet end1: failed to kill vid 0081/0 Adding VLANs while the interface is down also fails: # ip link add link end1 name end1.10 type vlan id 10 renesas-gbeth 15c40000.ethernet end1: Timeout accessing MAC_VLAN_Tag_Fi= lter RTNETLINK answers: Device or resource busy Use the write_hw parameter introduced in the previous commit to skip hardware register writes when the interface is down. The software state is always kept up to date regardless of interface state. When the interface is brought up, stmmac_vlan_configure() is called to write the VLAN state to hardware. Signed-off-by: Ovidiu Panait --- .../net/ethernet/stmicro/stmmac/stmmac_main.c | 33 +++++++++++++++---- .../net/ethernet/stmicro/stmmac/stmmac_vlan.c | 9 ++--- 2 files changed, 29 insertions(+), 13 deletions(-) diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c b/drivers/ne= t/ethernet/stmicro/stmmac/stmmac_main.c index 536668a0d6dd..d0aede23ae0d 100644 --- a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c +++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c @@ -156,6 +156,7 @@ static void stmmac_tx_timer_arm(struct stmmac_priv *pri= v, u32 queue); static void stmmac_flush_tx_descriptors(struct stmmac_priv *priv, int queu= e); static void stmmac_set_dma_operation_mode(struct stmmac_priv *priv, u32 tx= mode, u32 rxmode, u32 chan); +static int stmmac_vlan_configure(struct stmmac_priv *priv); =20 #ifdef CONFIG_DEBUG_FS static const struct net_device_ops stmmac_netdev_ops; @@ -4111,6 +4112,14 @@ static int __stmmac_open(struct net_device *dev, =20 phylink_start(priv->phylink); =20 + if (dev->features & NETIF_F_VLAN_FEATURES) { + phylink_rx_clk_stop_block(priv->phylink); + ret =3D stmmac_vlan_configure(priv); + phylink_rx_clk_stop_unblock(priv->phylink); + if (ret) + netdev_err(dev, "Failed to configure VLANs\n"); + } + ret =3D stmmac_request_irq(dev); if (ret) goto irq_error; @@ -6784,6 +6793,7 @@ static int stmmac_vlan_update(struct stmmac_priv *pri= v, bool is_double, static int stmmac_vlan_rx_add_vid(struct net_device *ndev, __be16 proto, u= 16 vid) { struct stmmac_priv *priv =3D netdev_priv(ndev); + bool write_hw =3D netif_running(ndev); unsigned int num_double_vlans; bool is_double =3D false; int ret; @@ -6797,7 +6807,7 @@ static int stmmac_vlan_rx_add_vid(struct net_device *= ndev, __be16 proto, u16 vid =20 set_bit(vid, priv->active_vlans); num_double_vlans =3D priv->num_double_vlans + is_double; - ret =3D stmmac_vlan_update(priv, num_double_vlans, true); + ret =3D stmmac_vlan_update(priv, num_double_vlans, write_hw); if (ret) { clear_bit(vid, priv->active_vlans); goto err_pm_put; @@ -6805,10 +6815,11 @@ static int stmmac_vlan_rx_add_vid(struct net_device= *ndev, __be16 proto, u16 vid =20 if (priv->hw->num_vlan) { ret =3D stmmac_add_hw_vlan_rx_fltr(priv, ndev, priv->hw, proto, - vid, true); + vid, write_hw); if (ret) { clear_bit(vid, priv->active_vlans); - stmmac_vlan_update(priv, priv->num_double_vlans, true); + stmmac_vlan_update(priv, priv->num_double_vlans, + write_hw); goto err_pm_put; } } @@ -6827,6 +6838,7 @@ static int stmmac_vlan_rx_add_vid(struct net_device *= ndev, __be16 proto, u16 vid static int stmmac_vlan_rx_kill_vid(struct net_device *ndev, __be16 proto, = u16 vid) { struct stmmac_priv *priv =3D netdev_priv(ndev); + bool write_hw =3D netif_running(ndev); unsigned int num_double_vlans; bool is_double =3D false; int ret; @@ -6840,7 +6852,7 @@ static int stmmac_vlan_rx_kill_vid(struct net_device = *ndev, __be16 proto, u16 vi =20 clear_bit(vid, priv->active_vlans); num_double_vlans =3D priv->num_double_vlans - is_double; - ret =3D stmmac_vlan_update(priv, num_double_vlans, true); + ret =3D stmmac_vlan_update(priv, num_double_vlans, write_hw); if (ret) { set_bit(vid, priv->active_vlans); goto del_vlan_error; @@ -6848,10 +6860,11 @@ static int stmmac_vlan_rx_kill_vid(struct net_devic= e *ndev, __be16 proto, u16 vi =20 if (priv->hw->num_vlan) { ret =3D stmmac_del_hw_vlan_rx_fltr(priv, ndev, priv->hw, proto, - vid, true); + vid, write_hw); if (ret) { set_bit(vid, priv->active_vlans); - stmmac_vlan_update(priv, priv->num_double_vlans, true); + stmmac_vlan_update(priv, priv->num_double_vlans, + write_hw); goto del_vlan_error; } } @@ -6864,6 +6877,14 @@ static int stmmac_vlan_rx_kill_vid(struct net_device= *ndev, __be16 proto, u16 vi return ret; } =20 +static int stmmac_vlan_configure(struct stmmac_priv *priv) +{ + if (priv->hw->num_vlan) + stmmac_restore_hw_vlan_rx_fltr(priv, priv->dev, priv->hw); + + return stmmac_vlan_update(priv, priv->num_double_vlans, true); +} + static int stmmac_bpf(struct net_device *dev, struct netdev_bpf *bpf) { struct stmmac_priv *priv =3D netdev_priv(dev); diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_vlan.c b/drivers/ne= t/ethernet/stmicro/stmmac/stmmac_vlan.c index b74c173da1b5..070c11870c02 100644 --- a/drivers/net/ethernet/stmicro/stmmac/stmmac_vlan.c +++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_vlan.c @@ -150,7 +150,6 @@ static void vlan_restore_hw_rx_fltr(struct net_device *= dev, void __iomem *ioaddr =3D hw->pcsr; u32 value; u32 hash; - u32 val; int i; =20 /* Single Rx VLAN Filter */ @@ -160,12 +159,8 @@ static void vlan_restore_hw_rx_fltr(struct net_device = *dev, } =20 /* Extended Rx VLAN Filter Enable */ - for (i =3D 0; i < hw->num_vlan; i++) { - if (hw->vlan_filter[i] & VLAN_TAG_DATA_VEN) { - val =3D hw->vlan_filter[i]; - vlan_write_filter(dev, hw, i, val); - } - } + for (i =3D 0; i < hw->num_vlan; i++) + vlan_write_filter(dev, hw, i, hw->vlan_filter[i]); =20 hash =3D readl(ioaddr + VLAN_HASH_TABLE); if (hash & VLAN_VLHT) { --=20 2.34.1