From nobody Tue Apr 7 12:23:28 2026 Received: from relmlie6.idc.renesas.com (relmlor2.renesas.com [210.160.252.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 46ED03B3BF2; Tue, 3 Mar 2026 14:58:43 +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=1772549928; cv=none; b=dWlnv+Rm2VQoBxIasJZsUQ14GXl3WP3ADtiwN8KUUrkbau1Cpd0wMqJpq+cRnRndnb5bq0bn5jQxa7DRpASKhUntY/aw0Aq97iASV1OSVj4cPhjvc/grESqCfKrKS7OIvUf8+NpOjpU/nX9+bT+UKRGy/eCMXtu5lWCl1jkKsHQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772549928; c=relaxed/simple; bh=1iv+LorVKkgiobfh7MC1Ga6YvyOF4Yj+HscIHMmZiCY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=sFHslVrzMUApbMrzHgMJfg1IwZJb4X6LvvSKhP3hsuS8yGg0jdS8OsHlITPk7w+TE5IAuQHhjJ5GCPtuS25bwZk30QqaAl+pUBa64804agW/dyWA9Eg+wiERrBtciASTAd2t7eo4cThaKrd4G33xykByc1U0MCUDDxfp6OgwOj4= 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: xtyau20DRIG2bqUR8fVI7w== X-CSE-MsgGUID: gLHH6HTlSNiuLaCyurF4XA== Received: from unknown (HELO relmlir5.idc.renesas.com) ([10.200.68.151]) by relmlie6.idc.renesas.com with ESMTP; 03 Mar 2026 23:58:42 +0900 Received: from vm01.adwin.renesas.com (unknown [10.226.92.15]) by relmlir5.idc.renesas.com (Postfix) with ESMTP id A6298400D0EA; Tue, 3 Mar 2026 23:58:36 +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, 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 v3 1/4] net: stmmac: Fix error handling in VLAN add and delete paths Date: Tue, 3 Mar 2026 14:58:25 +0000 Message-ID: <20260303145828.7845-2-ovidiu.panait.rb@renesas.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260303145828.7845-1-ovidiu.panait.rb@renesas.com> References: <20260303145828.7845-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 --- v3 changes: none. v2 changes: none. .../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 8772d735c577..d979a3ebd28e 100644 --- a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c +++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c @@ -6799,9 +6799,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 @@ -6825,15 +6829,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.51.0 From nobody Tue Apr 7 12:23:28 2026 Received: from relmlie6.idc.renesas.com (relmlor2.renesas.com [210.160.252.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id B99B147F2EF; Tue, 3 Mar 2026 14:58:49 +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=1772549931; cv=none; b=YPWT2wpZ7fR+HqhfQ2uzVMLAzwf9cOtcZ/c99gHJGWfQQWRDNKzyGRFSwVZbJQE8KZmuiPzfgoxpGFv/dl8qneDmQSM19sXGiOhX0XBvZog9NDo9X5zuwG1W0Kd/JiphLSMgZyJ6uDjOchQmcuMPRwmoRHgRB5TpeOV3J5aPYKE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772549931; c=relaxed/simple; bh=FLv0YOxZuBU+xNlmH9S5SZOiBrCIe/USODwl8gAaZGI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ZKjL+nR6EQVr8YC75+pyfHQhY5Lx1T/UNq4qFqByNbNxPOczusf7iM/1m1N8B1cTRLaKhexpGfbogXGUFDfaNOdOOeS9Bl5ctdbCPluecZDIdxRbhC3cE6zbr4s8I8Z89aLnCcPh8qyqfzVZwQSdTBmmwAD0q7EocbqKTlamZGw= 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: FKUiEAa7QWySMLK+hu3+Ag== X-CSE-MsgGUID: 4ltcrwNwQbiL1ECACIVy2w== Received: from unknown (HELO relmlir5.idc.renesas.com) ([10.200.68.151]) by relmlie6.idc.renesas.com with ESMTP; 03 Mar 2026 23:58:49 +0900 Received: from vm01.adwin.renesas.com (unknown [10.226.92.15]) by relmlir5.idc.renesas.com (Postfix) with ESMTP id 52014400D0EA; Tue, 3 Mar 2026 23:58:43 +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, 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 v3 2/4] net: stmmac: Improve double VLAN handling Date: Tue, 3 Mar 2026 14:58:26 +0000 Message-ID: <20260303145828.7845-3-ovidiu.panait.rb@renesas.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260303145828.7845-1-ovidiu.panait.rb@renesas.com> References: <20260303145828.7845-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 --- v3 changes: none. v2 changes: none. 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 d979a3ebd28e..2365b12fbe05 100644 --- a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c +++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c @@ -6780,6 +6780,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 @@ -6791,7 +6792,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; @@ -6801,11 +6803,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 @@ -6818,6 +6822,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 @@ -6829,7 +6834,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; @@ -6839,11 +6845,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.51.0 From nobody Tue Apr 7 12:23:28 2026 Received: from relmlie5.idc.renesas.com (relmlor1.renesas.com [210.160.252.171]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 22F813D5651; Tue, 3 Mar 2026 14:58:56 +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=1772549939; cv=none; b=HxHLC6k4ftfkzPa1VxV1L/hCHbfQ0PXQrOn5AqzP9AjGGUMwspQbP4Dw6UqbEHanBA4iIx1B4PJoITnD487IOD9iNGDP6lxB8ov3YrH92jPv0ojqlheCEcWCGXteWalfopEoh8vnlJGXeMW/9jA6sxraWaQ3R/wzeBBLfaUoF3E= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772549939; c=relaxed/simple; bh=C4356gas4yxYUHodweEZbzXX2g6jB6SVAnqNCI976ac=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Gjtw7vWivGjlspjQrIBkbMc3mGTbGH+/ap7nxwA88AgXpkcSybszNwgGE45qTOcmT39rfx09syh1uCx4nI7UCdwjBf3oEf2ZWole4/XIKZhXQonRhX0IOwAAMZPFePzQTyh48J4fhcpm9WG8a7JraatcSPkAmudQs5KZ06Wrhaw= 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: KDc5Hfc0Sse6lgeiaEJN8w== X-CSE-MsgGUID: XJTvLmIRTNek0bFMqTUZOQ== Received: from unknown (HELO relmlir5.idc.renesas.com) ([10.200.68.151]) by relmlie5.idc.renesas.com with ESMTP; 03 Mar 2026 23:58:56 +0900 Received: from vm01.adwin.renesas.com (unknown [10.226.92.15]) by relmlir5.idc.renesas.com (Postfix) with ESMTP id 00848400D0EA; Tue, 3 Mar 2026 23:58:49 +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, 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 v3 3/4] net: stmmac: Fix VLAN HW state restore Date: Tue, 3 Mar 2026 14:58:27 +0000 Message-ID: <20260303145828.7845-4-ovidiu.panait.rb@renesas.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260303145828.7845-1-ovidiu.panait.rb@renesas.com> References: <20260303145828.7845-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" When the network interface is opened or resumed, a DMA reset is performed, which resets all hardware state, including VLAN state. Currently, only the resume path is restoring the VLAN state via stmmac_restore_hw_vlan_rx_fltr(), but that is incomplete: the VLAN hash table and the VLAN_TAG control bits are not restored. Therefore, add stmmac_vlan_restore(), which restores the full VLAN state by updating both the HW filter entries and the hash table, and call it from both the open and resume paths. The VLAN restore is moved outside of phylink_rx_clk_stop_block/unblock in the resume path because receive clock stop is already disabled when stmmac supports VLAN. Also, remove the hash readback code in vlan_restore_hw_rx_fltr() that attempts to restore VTHM by reading VLAN_HASH_TABLE, as it always reads zero after DMA reset, making it dead code. Fixes: 3cd1cfcba26e ("net: stmmac: Implement VLAN Hash Filtering in XGMAC") Fixes: ed64639bc1e0 ("net: stmmac: Add support for VLAN Rx filtering") Signed-off-by: Ovidiu Panait --- v3 changes: none. v2 changes: new patch. .../net/ethernet/stmicro/stmmac/stmmac_main.c | 24 +++++++++++++++++-- .../net/ethernet/stmicro/stmmac/stmmac_vlan.c | 10 -------- 2 files changed, 22 insertions(+), 12 deletions(-) diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c b/drivers/ne= t/ethernet/stmicro/stmmac/stmmac_main.c index 2365b12fbe05..a8fb091d7b5d 100644 --- a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c +++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c @@ -157,6 +157,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_restore(struct stmmac_priv *priv); =20 #ifdef CONFIG_DEBUG_FS static const struct net_device_ops stmmac_netdev_ops; @@ -4111,6 +4112,8 @@ static int __stmmac_open(struct net_device *dev, =20 phylink_start(priv->phylink); =20 + stmmac_vlan_restore(priv); + ret =3D stmmac_request_irq(dev); if (ret) goto irq_error; @@ -6858,6 +6861,23 @@ static int stmmac_vlan_rx_kill_vid(struct net_device= *ndev, __be16 proto, u16 vi return ret; } =20 +static int stmmac_vlan_restore(struct stmmac_priv *priv) +{ + int ret; + + if (!(priv->dev->features & NETIF_F_VLAN_FEATURES)) + return 0; + + if (priv->hw->num_vlan) + stmmac_restore_hw_vlan_rx_fltr(priv, priv->dev, priv->hw); + + ret =3D stmmac_vlan_update(priv, priv->num_double_vlans); + if (ret) + netdev_err(priv->dev, "Failed to restore VLANs\n"); + + return ret; +} + static int stmmac_bpf(struct net_device *dev, struct netdev_bpf *bpf) { struct stmmac_priv *priv =3D netdev_priv(dev); @@ -8282,10 +8302,10 @@ int stmmac_resume(struct device *dev) stmmac_init_coalesce(priv); phylink_rx_clk_stop_block(priv->phylink); stmmac_set_rx_mode(ndev); - - stmmac_restore_hw_vlan_rx_fltr(priv, ndev, priv->hw); phylink_rx_clk_stop_unblock(priv->phylink); =20 + stmmac_vlan_restore(priv); + stmmac_enable_all_queues(priv); stmmac_enable_all_dma_irq(priv); =20 diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_vlan.c b/drivers/ne= t/ethernet/stmicro/stmmac/stmmac_vlan.c index de1a70e1c86e..fcc34867405e 100644 --- a/drivers/net/ethernet/stmicro/stmmac/stmmac_vlan.c +++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_vlan.c @@ -139,9 +139,6 @@ static int vlan_del_hw_rx_fltr(struct net_device *dev, static void vlan_restore_hw_rx_fltr(struct net_device *dev, struct mac_device_info *hw) { - void __iomem *ioaddr =3D hw->pcsr; - u32 value; - u32 hash; u32 val; int i; =20 @@ -158,13 +155,6 @@ static void vlan_restore_hw_rx_fltr(struct net_device = *dev, vlan_write_filter(dev, hw, i, val); } } - - hash =3D readl(ioaddr + VLAN_HASH_TABLE); - if (hash & VLAN_VLHT) { - value =3D readl(ioaddr + VLAN_TAG); - value |=3D VLAN_VTHM; - writel(value, ioaddr + VLAN_TAG); - } } =20 static void vlan_update_hash(struct mac_device_info *hw, u32 hash, --=20 2.51.0 From nobody Tue Apr 7 12:23:28 2026 Received: from relmlie6.idc.renesas.com (relmlor2.renesas.com [210.160.252.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 1D55D3B5822; Tue, 3 Mar 2026 14:59:03 +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=1772549945; cv=none; b=pDWqQgpaRqw7+gcgj24vPETJrUj0VkD1d3M2da+EGAs7xXMwsHTVYWrxU3nK7jCaJJdJ8fSBkz55clYYtZqGPWceejyxF6KZp0mQT+g+ct7XY9QDXlzcjIT7FIbYfiq5o0ZLc2gzRdnQ2CZGHIotU1Us3+XQBJHTdzt7Q+cT+0w= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772549945; c=relaxed/simple; bh=jsHmcRTwSYXWV0NQ7akNiCpmZSEUere/Vg3ckiSm75M=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=NgAHGfvhAbXJFbQIUnk7We5ZJuWjoPIddVDyN4RPedudZtTjokm8P2bW7TN3E70IDHlnvAcyd1AF86uocFRim3miY3Gx1eeOJp6iwRMBtpx4f7RAzUc3SwN+agSKiYwRolWZ3+fAr5h+rW8QYp2vHnrSqgTvbwD0iQJ3v+51lHQ= 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: u7EqF9WKTXKRYtkXA6aSNg== X-CSE-MsgGUID: PBIVzJ5sQzuJRrMv6FCszg== Received: from unknown (HELO relmlir5.idc.renesas.com) ([10.200.68.151]) by relmlie6.idc.renesas.com with ESMTP; 03 Mar 2026 23:59:02 +0900 Received: from vm01.adwin.renesas.com (unknown [10.226.92.15]) by relmlir5.idc.renesas.com (Postfix) with ESMTP id ABA92401006A; Tue, 3 Mar 2026 23:58:56 +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, 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 v3 4/4] net: stmmac: Defer VLAN HW configuration when interface is down Date: Tue, 3 Mar 2026 14:58:28 +0000 Message-ID: <20260303145828.7845-5-ovidiu.panait.rb@renesas.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260303145828.7845-1-ovidiu.panait.rb@renesas.com> References: <20260303145828.7845-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 To fix this, check if the interface is up before accessing VLAN registers. The software state is always kept up to date regardless of interface state. When the interface is brought up, stmmac_vlan_restore() is called to write the VLAN state to hardware. Fixes: ed64639bc1e0 ("net: stmmac: Add support for VLAN Rx filtering") Signed-off-by: Ovidiu Panait --- v3 changes: - Dropped the 'write_hw' approach to avoid passing attributes around. Instead, netif_running() checks were added directly on the VLAN paths. v2 changes: - Split this commit - added a new commit (3/5) which fixes VLAN restore on resume and open paths. - Dropped phylink_rx_clk_stop_block()/unblock() calls around VLAN restore. .../net/ethernet/stmicro/stmmac/stmmac_main.c | 3 ++ .../net/ethernet/stmicro/stmmac/stmmac_vlan.c | 42 ++++++++++--------- 2 files changed, 26 insertions(+), 19 deletions(-) diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c b/drivers/ne= t/ethernet/stmicro/stmmac/stmmac_main.c index a8fb091d7b5d..536d513bdad5 100644 --- a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c +++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c @@ -6774,6 +6774,9 @@ static int stmmac_vlan_update(struct stmmac_priv *pri= v, bool is_double) hash =3D 0; } =20 + if (!netif_running(priv->dev)) + return 0; + return stmmac_update_vlan_hash(priv, priv->hw, hash, pmatch, is_double); } =20 diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_vlan.c b/drivers/ne= t/ethernet/stmicro/stmmac/stmmac_vlan.c index fcc34867405e..e24efe3bfedb 100644 --- a/drivers/net/ethernet/stmicro/stmmac/stmmac_vlan.c +++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_vlan.c @@ -76,7 +76,9 @@ static int vlan_add_hw_rx_fltr(struct net_device *dev, } =20 hw->vlan_filter[0] =3D vid; - vlan_write_single(dev, vid); + + if (netif_running(dev)) + vlan_write_single(dev, vid); =20 return 0; } @@ -97,12 +99,15 @@ static int vlan_add_hw_rx_fltr(struct net_device *dev, return -EPERM; } =20 - ret =3D vlan_write_filter(dev, hw, index, val); + if (netif_running(dev)) { + 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, @@ -115,7 +120,9 @@ 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 (netif_running(dev)) + vlan_write_single(dev, 0); } return 0; } @@ -124,22 +131,23 @@ 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); =20 - if (!ret) - hw->vlan_filter[i] =3D 0; - else - return ret; + if (netif_running(dev)) { + ret =3D vlan_write_filter(dev, hw, i, 0); + if (ret) + return ret; + } + + hw->vlan_filter[i] =3D 0; } } =20 - return ret; + return 0; } =20 static void vlan_restore_hw_rx_fltr(struct net_device *dev, struct mac_device_info *hw) { - u32 val; int i; =20 /* Single Rx VLAN Filter */ @@ -149,12 +157,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 static void vlan_update_hash(struct mac_device_info *hw, u32 hash, --=20 2.51.0