* [PATCH net-next v2 1/5] net: stmmac: Fix error handling in VLAN add and delete paths
2026-02-25 14:24 [PATCH net-next v2 0/5] net: stmmac: Fix VLAN handling when interface is down Ovidiu Panait
@ 2026-02-25 14:24 ` Ovidiu Panait
2026-02-25 14:24 ` [PATCH net-next v2 2/5] net: stmmac: Improve double VLAN handling Ovidiu Panait
` (3 subsequent siblings)
4 siblings, 0 replies; 9+ messages in thread
From: Ovidiu Panait @ 2026-02-25 14:24 UTC (permalink / raw)
To: andrew+netdev, davem, edumazet, kuba, pabeni, mcoquelin.stm32,
alexandre.torgue, linux, rmk+kernel, maxime.chevallier,
boon.khai.ng, rohan.g.thomas, vladimir.oltean, hayashi.kunihiko,
boon.leong.ong, kim.tatt.chuah
Cc: netdev, linux-arm-kernel, linux-stm32, linux-kernel
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 <ovidiu.panait.rb@renesas.com>
---
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/net/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
if (priv->hw->num_vlan) {
ret = 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);
@@ -6824,15 +6828,21 @@ static int stmmac_vlan_rx_kill_vid(struct net_device *ndev, __be16 proto, u16 vi
is_double = true;
clear_bit(vid, priv->active_vlans);
+ ret = stmmac_vlan_update(priv, is_double);
+ if (ret) {
+ set_bit(vid, priv->active_vlans);
+ goto del_vlan_error;
+ }
if (priv->hw->num_vlan) {
ret = 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;
+ }
}
- ret = stmmac_vlan_update(priv, is_double);
-
del_vlan_error:
pm_runtime_put(priv->device);
--
2.51.0
^ permalink raw reply related [flat|nested] 9+ messages in thread* [PATCH net-next v2 2/5] net: stmmac: Improve double VLAN handling
2026-02-25 14:24 [PATCH net-next v2 0/5] net: stmmac: Fix VLAN handling when interface is down Ovidiu Panait
2026-02-25 14:24 ` [PATCH net-next v2 1/5] net: stmmac: Fix error handling in VLAN add and delete paths Ovidiu Panait
@ 2026-02-25 14:24 ` Ovidiu Panait
2026-02-25 14:24 ` [PATCH net-next v2 3/5] net: stmmac: Fix VLAN HW state restore Ovidiu Panait
` (2 subsequent siblings)
4 siblings, 0 replies; 9+ messages in thread
From: Ovidiu Panait @ 2026-02-25 14:24 UTC (permalink / raw)
To: andrew+netdev, davem, edumazet, kuba, pabeni, mcoquelin.stm32,
alexandre.torgue, linux, rmk+kernel, maxime.chevallier,
boon.khai.ng, rohan.g.thomas, vladimir.oltean, hayashi.kunihiko,
boon.leong.ong, kim.tatt.chuah
Cc: netdev, linux-arm-kernel, linux-stm32, linux-kernel
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 <ovidiu.panait.rb@renesas.com>
---
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/ethernet/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/net/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 *priv, bool is_double)
static int stmmac_vlan_rx_add_vid(struct net_device *ndev, __be16 proto, u16 vid)
{
struct stmmac_priv *priv = netdev_priv(ndev);
+ unsigned int num_double_vlans;
bool is_double = false;
int ret;
@@ -6790,7 +6791,8 @@ static int stmmac_vlan_rx_add_vid(struct net_device *ndev, __be16 proto, u16 vid
is_double = true;
set_bit(vid, priv->active_vlans);
- ret = stmmac_vlan_update(priv, is_double);
+ num_double_vlans = priv->num_double_vlans + is_double;
+ ret = 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 = 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;
}
}
+ priv->num_double_vlans = num_double_vlans;
+
err_pm_put:
pm_runtime_put(priv->device);
@@ -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 = netdev_priv(ndev);
+ unsigned int num_double_vlans;
bool is_double = false;
int ret;
@@ -6828,7 +6833,8 @@ static int stmmac_vlan_rx_kill_vid(struct net_device *ndev, __be16 proto, u16 vi
is_double = true;
clear_bit(vid, priv->active_vlans);
- ret = stmmac_vlan_update(priv, is_double);
+ num_double_vlans = priv->num_double_vlans - is_double;
+ ret = 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_device *ndev, __be16 proto, u16 vi
ret = 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;
}
}
+ priv->num_double_vlans = num_double_vlans;
+
del_vlan_error:
pm_runtime_put(priv->device);
diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_vlan.c b/drivers/net/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 *hw, u32 hash,
value |= VLAN_EDVLP;
value |= VLAN_ESVL;
value |= VLAN_DOVLTC;
+ } else {
+ value &= ~VLAN_EDVLP;
+ value &= ~VLAN_ESVL;
+ value &= ~VLAN_DOVLTC;
}
writel(value, ioaddr + VLAN_TAG);
@@ -193,6 +197,10 @@ static void vlan_update_hash(struct mac_device_info *hw, u32 hash,
value |= VLAN_EDVLP;
value |= VLAN_ESVL;
value |= VLAN_DOVLTC;
+ } else {
+ value &= ~VLAN_EDVLP;
+ value &= ~VLAN_ESVL;
+ value &= ~VLAN_DOVLTC;
}
writel(value | perfect_match, ioaddr + VLAN_TAG);
--
2.51.0
^ permalink raw reply related [flat|nested] 9+ messages in thread* [PATCH net-next v2 3/5] net: stmmac: Fix VLAN HW state restore
2026-02-25 14:24 [PATCH net-next v2 0/5] net: stmmac: Fix VLAN handling when interface is down Ovidiu Panait
2026-02-25 14:24 ` [PATCH net-next v2 1/5] net: stmmac: Fix error handling in VLAN add and delete paths Ovidiu Panait
2026-02-25 14:24 ` [PATCH net-next v2 2/5] net: stmmac: Improve double VLAN handling Ovidiu Panait
@ 2026-02-25 14:24 ` Ovidiu Panait
2026-02-25 14:24 ` [PATCH net-next v2 4/5] net: stmmac: Add write_hw parameter to VLAN filter operations Ovidiu Panait
2026-02-25 14:24 ` [PATCH net-next v2 5/5] net: stmmac: Defer VLAN HW configuration when interface is down Ovidiu Panait
4 siblings, 0 replies; 9+ messages in thread
From: Ovidiu Panait @ 2026-02-25 14:24 UTC (permalink / raw)
To: andrew+netdev, davem, edumazet, kuba, pabeni, mcoquelin.stm32,
alexandre.torgue, linux, rmk+kernel, maxime.chevallier,
boon.khai.ng, rohan.g.thomas, vladimir.oltean, hayashi.kunihiko,
boon.leong.ong, kim.tatt.chuah
Cc: netdev, linux-arm-kernel, linux-stm32, linux-kernel
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 <ovidiu.panait.rb@renesas.com>
---
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/net/ethernet/stmicro/stmmac/stmmac_main.c
index 45f2f3492dbd..a02575f67057 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 *priv, u32 queue);
static void stmmac_flush_tx_descriptors(struct stmmac_priv *priv, int queue);
static void stmmac_set_dma_operation_mode(struct stmmac_priv *priv, u32 txmode,
u32 rxmode, u32 chan);
+static int stmmac_vlan_restore(struct stmmac_priv *priv);
#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,
phylink_start(priv->phylink);
+ stmmac_vlan_restore(priv);
+
ret = stmmac_request_irq(dev);
if (ret)
goto irq_error;
@@ -6857,6 +6860,23 @@ static int stmmac_vlan_rx_kill_vid(struct net_device *ndev, __be16 proto, u16 vi
return ret;
}
+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 = 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 = netdev_priv(dev);
@@ -8281,10 +8301,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);
+ stmmac_vlan_restore(priv);
+
stmmac_enable_all_queues(priv);
stmmac_enable_all_dma_irq(priv);
diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_vlan.c b/drivers/net/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 = hw->pcsr;
- u32 value;
- u32 hash;
u32 val;
int i;
@@ -158,13 +155,6 @@ static void vlan_restore_hw_rx_fltr(struct net_device *dev,
vlan_write_filter(dev, hw, i, val);
}
}
-
- hash = readl(ioaddr + VLAN_HASH_TABLE);
- if (hash & VLAN_VLHT) {
- value = readl(ioaddr + VLAN_TAG);
- value |= VLAN_VTHM;
- writel(value, ioaddr + VLAN_TAG);
- }
}
static void vlan_update_hash(struct mac_device_info *hw, u32 hash,
--
2.51.0
^ permalink raw reply related [flat|nested] 9+ messages in thread* [PATCH net-next v2 4/5] net: stmmac: Add write_hw parameter to VLAN filter operations
2026-02-25 14:24 [PATCH net-next v2 0/5] net: stmmac: Fix VLAN handling when interface is down Ovidiu Panait
` (2 preceding siblings ...)
2026-02-25 14:24 ` [PATCH net-next v2 3/5] net: stmmac: Fix VLAN HW state restore Ovidiu Panait
@ 2026-02-25 14:24 ` Ovidiu Panait
2026-02-28 19:04 ` Jakub Kicinski
2026-02-25 14:24 ` [PATCH net-next v2 5/5] net: stmmac: Defer VLAN HW configuration when interface is down Ovidiu Panait
4 siblings, 1 reply; 9+ messages in thread
From: Ovidiu Panait @ 2026-02-25 14:24 UTC (permalink / raw)
To: andrew+netdev, davem, edumazet, kuba, pabeni, mcoquelin.stm32,
alexandre.torgue, linux, rmk+kernel, maxime.chevallier,
boon.khai.ng, rohan.g.thomas, vladimir.oltean, hayashi.kunihiko,
boon.leong.ong, kim.tatt.chuah
Cc: netdev, linux-arm-kernel, linux-stm32, linux-kernel
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 <ovidiu.panait.rb@renesas.com>
---
v2 changes: none.
drivers/net/ethernet/stmicro/stmmac/hwif.h | 6 ++--
.../net/ethernet/stmicro/stmmac/stmmac_main.c | 25 +++++++++-----
.../net/ethernet/stmicro/stmmac/stmmac_vlan.c | 34 ++++++++++++-------
3 files changed, 41 insertions(+), 24 deletions(-)
diff --git a/drivers/net/ethernet/stmicro/stmmac/hwif.h b/drivers/net/ethernet/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/net/ethernet/stmicro/stmmac/stmmac_main.c
index a02575f67057..19c86e3b42cc 100644
--- a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
+++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
@@ -6751,7 +6751,8 @@ static u32 stmmac_vid_crc32_le(__le16 vid_le)
return crc;
}
-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 = 0;
u16 pmatch = 0;
@@ -6773,7 +6774,11 @@ static int stmmac_vlan_update(struct stmmac_priv *priv, bool is_double)
hash = 0;
}
- 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;
}
/* FIXME: This may need RXC to be running, but it may be called with BH
@@ -6795,17 +6800,18 @@ static int stmmac_vlan_rx_add_vid(struct net_device *ndev, __be16 proto, u16 vid
set_bit(vid, priv->active_vlans);
num_double_vlans = priv->num_double_vlans + is_double;
- ret = stmmac_vlan_update(priv, num_double_vlans);
+ ret = stmmac_vlan_update(priv, num_double_vlans, true);
if (ret) {
clear_bit(vid, priv->active_vlans);
goto err_pm_put;
}
if (priv->hw->num_vlan) {
- ret = stmmac_add_hw_vlan_rx_fltr(priv, ndev, priv->hw, proto, vid);
+ ret = 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;
}
}
@@ -6837,17 +6843,18 @@ static int stmmac_vlan_rx_kill_vid(struct net_device *ndev, __be16 proto, u16 vi
clear_bit(vid, priv->active_vlans);
num_double_vlans = priv->num_double_vlans - is_double;
- ret = stmmac_vlan_update(priv, num_double_vlans);
+ ret = stmmac_vlan_update(priv, num_double_vlans, true);
if (ret) {
set_bit(vid, priv->active_vlans);
goto del_vlan_error;
}
if (priv->hw->num_vlan) {
- ret = stmmac_del_hw_vlan_rx_fltr(priv, ndev, priv->hw, proto, vid);
+ ret = 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;
}
}
@@ -6870,7 +6877,7 @@ static int stmmac_vlan_restore(struct stmmac_priv *priv)
if (priv->hw->num_vlan)
stmmac_restore_hw_vlan_rx_fltr(priv, priv->dev, priv->hw);
- ret = stmmac_vlan_update(priv, priv->num_double_vlans);
+ ret = stmmac_vlan_update(priv, priv->num_double_vlans, true);
if (ret)
netdev_err(priv->dev, "Failed to restore VLANs\n");
diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_vlan.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_vlan.c
index fcc34867405e..f81015179d04 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,
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 = -1;
u32 val = 0;
@@ -76,7 +77,8 @@ static int vlan_add_hw_rx_fltr(struct net_device *dev,
}
hw->vlan_filter[0] = vid;
- vlan_write_single(dev, vid);
+ if (write_hw)
+ vlan_write_single(dev, vid);
return 0;
}
@@ -97,17 +99,21 @@ static int vlan_add_hw_rx_fltr(struct net_device *dev,
return -EPERM;
}
- ret = vlan_write_filter(dev, hw, index, val);
+ if (write_hw) {
+ ret = vlan_write_filter(dev, hw, index, val);
+ if (ret)
+ return ret;
+ }
- if (!ret)
- hw->vlan_filter[index] = val;
+ hw->vlan_filter[index] = val;
- return ret;
+ return 0;
}
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 = 0;
@@ -115,7 +121,8 @@ static int vlan_del_hw_rx_fltr(struct net_device *dev,
if (hw->num_vlan == 1) {
if ((hw->vlan_filter[0] & VLAN_TAG_VID) == vid) {
hw->vlan_filter[0] = 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 = 0; i < hw->num_vlan; i++) {
if ((hw->vlan_filter[i] & VLAN_TAG_DATA_VEN) &&
((hw->vlan_filter[i] & VLAN_TAG_DATA_VID) == vid)) {
- ret = vlan_write_filter(dev, hw, i, 0);
+ if (write_hw) {
+ ret = vlan_write_filter(dev, hw, i, 0);
+ if (ret)
+ return ret;
+ }
- if (!ret)
- hw->vlan_filter[i] = 0;
- else
- return ret;
+ hw->vlan_filter[i] = 0;
}
}
--
2.51.0
^ permalink raw reply related [flat|nested] 9+ messages in thread* Re: [PATCH net-next v2 4/5] net: stmmac: Add write_hw parameter to VLAN filter operations
2026-02-25 14:24 ` [PATCH net-next v2 4/5] net: stmmac: Add write_hw parameter to VLAN filter operations Ovidiu Panait
@ 2026-02-28 19:04 ` Jakub Kicinski
2026-03-02 21:59 ` Ovidiu Panait
0 siblings, 1 reply; 9+ messages in thread
From: Jakub Kicinski @ 2026-02-28 19:04 UTC (permalink / raw)
To: Ovidiu Panait
Cc: andrew+netdev, davem, edumazet, pabeni, mcoquelin.stm32,
alexandre.torgue, linux, rmk+kernel, maxime.chevallier,
boon.khai.ng, rohan.g.thomas, vladimir.oltean, hayashi.kunihiko,
boon.leong.ong, kim.tatt.chuah, netdev, linux-arm-kernel,
linux-stm32, linux-kernel
On Wed, 25 Feb 2026 14:24:13 +0000 Ovidiu Panait wrote:
> 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.
I wonder if instead of passing attributes like this around the driver
shouldn't simply maintain a flag (or have other way to test) whether
the clock to block X is currently enabled? It feels more like a global
state / property than trickiness directly related to VLAN config.
Also any strong reason to post this for net-next? We take fixes via
the net tree, so when you repost please use "PATCH net". And an
appropriate Fixes tag on the last patch would be great to have
(presumably just ed64639bc1e0 again?)
--
pw-bot: cr
^ permalink raw reply [flat|nested] 9+ messages in thread
* RE: [PATCH net-next v2 4/5] net: stmmac: Add write_hw parameter to VLAN filter operations
2026-02-28 19:04 ` Jakub Kicinski
@ 2026-03-02 21:59 ` Ovidiu Panait
2026-03-03 0:08 ` Jakub Kicinski
0 siblings, 1 reply; 9+ messages in thread
From: Ovidiu Panait @ 2026-03-02 21:59 UTC (permalink / raw)
To: Jakub Kicinski
Cc: andrew+netdev@lunn.ch, davem@davemloft.net, edumazet@google.com,
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,
netdev@vger.kernel.org, linux-arm-kernel@lists.infradead.org,
linux-stm32@st-md-mailman.stormreply.com,
linux-kernel@vger.kernel.org
Hi Jakub,
>
>> On Wed, 25 Feb 2026 14:24:13 +0000 Ovidiu Panait wrote:
> > 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.
>
> I wonder if instead of passing attributes like this around the driver
> shouldn't simply maintain a flag (or have other way to test) whether
> the clock to block X is currently enabled? It feels more like a global
> state / property than trickiness directly related to VLAN config.
>
I'll drop the write_hw logic and instead just check netif_running()
directly, to avoid passing attributes around.
In this case, the PHY RX clock needs to be on for the VLAN accesses to
succeed. When stmmac supports VLAN, the PHY RX clock is always kept on
via phylink when the interface is up, so I think there is no need for a
new flag, just checking if the interface is up should be enough.
> Also any strong reason to post this for net-next? We take fixes via
> the net tree, so when you repost please use "PATCH net". And an
> appropriate Fixes tag on the last patch would be great to have
> (presumably just ed64639bc1e0 again?)
Will do.
Thanks,
Ovidiu
> --
> pw-bot: cr
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH net-next v2 4/5] net: stmmac: Add write_hw parameter to VLAN filter operations
2026-03-02 21:59 ` Ovidiu Panait
@ 2026-03-03 0:08 ` Jakub Kicinski
0 siblings, 0 replies; 9+ messages in thread
From: Jakub Kicinski @ 2026-03-03 0:08 UTC (permalink / raw)
To: Ovidiu Panait
Cc: andrew+netdev@lunn.ch, davem@davemloft.net, edumazet@google.com,
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,
netdev@vger.kernel.org, linux-arm-kernel@lists.infradead.org,
linux-stm32@st-md-mailman.stormreply.com,
linux-kernel@vger.kernel.org
On Mon, 2 Mar 2026 21:59:00 +0000 Ovidiu Panait wrote:
> > I wonder if instead of passing attributes like this around the driver
> > shouldn't simply maintain a flag (or have other way to test) whether
> > the clock to block X is currently enabled? It feels more like a global
> > state / property than trickiness directly related to VLAN config.
>
> I'll drop the write_hw logic and instead just check netif_running()
> directly, to avoid passing attributes around.
SG, tho - be careful with netif_running() in context of open / close
code paths.
^ permalink raw reply [flat|nested] 9+ messages in thread
* [PATCH net-next v2 5/5] net: stmmac: Defer VLAN HW configuration when interface is down
2026-02-25 14:24 [PATCH net-next v2 0/5] net: stmmac: Fix VLAN handling when interface is down Ovidiu Panait
` (3 preceding siblings ...)
2026-02-25 14:24 ` [PATCH net-next v2 4/5] net: stmmac: Add write_hw parameter to VLAN filter operations Ovidiu Panait
@ 2026-02-25 14:24 ` Ovidiu Panait
4 siblings, 0 replies; 9+ messages in thread
From: Ovidiu Panait @ 2026-02-25 14:24 UTC (permalink / raw)
To: andrew+netdev, davem, edumazet, kuba, pabeni, mcoquelin.stm32,
alexandre.torgue, linux, rmk+kernel, maxime.chevallier,
boon.khai.ng, rohan.g.thomas, vladimir.oltean, hayashi.kunihiko,
boon.leong.ong, kim.tatt.chuah
Cc: netdev, linux-arm-kernel, linux-stm32, linux-kernel
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_Filter
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_Filter
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_restore() is called
to write the VLAN state to hardware.
Signed-off-by: Ovidiu Panait <ovidiu.panait.rb@renesas.com>
---
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 | 16 ++++++++++------
.../net/ethernet/stmicro/stmmac/stmmac_vlan.c | 9 ++-------
2 files changed, 12 insertions(+), 13 deletions(-)
diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
index 19c86e3b42cc..1098227272ed 100644
--- a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
+++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
@@ -6787,6 +6787,7 @@ static int stmmac_vlan_update(struct stmmac_priv *priv, bool is_double,
static int stmmac_vlan_rx_add_vid(struct net_device *ndev, __be16 proto, u16 vid)
{
struct stmmac_priv *priv = netdev_priv(ndev);
+ bool write_hw = netif_running(ndev);
unsigned int num_double_vlans;
bool is_double = false;
int ret;
@@ -6800,7 +6801,7 @@ static int stmmac_vlan_rx_add_vid(struct net_device *ndev, __be16 proto, u16 vid
set_bit(vid, priv->active_vlans);
num_double_vlans = priv->num_double_vlans + is_double;
- ret = stmmac_vlan_update(priv, num_double_vlans, true);
+ ret = stmmac_vlan_update(priv, num_double_vlans, write_hw);
if (ret) {
clear_bit(vid, priv->active_vlans);
goto err_pm_put;
@@ -6808,10 +6809,11 @@ static int stmmac_vlan_rx_add_vid(struct net_device *ndev, __be16 proto, u16 vid
if (priv->hw->num_vlan) {
ret = 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;
}
}
@@ -6830,6 +6832,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 = netdev_priv(ndev);
+ bool write_hw = netif_running(ndev);
unsigned int num_double_vlans;
bool is_double = false;
int ret;
@@ -6843,7 +6846,7 @@ static int stmmac_vlan_rx_kill_vid(struct net_device *ndev, __be16 proto, u16 vi
clear_bit(vid, priv->active_vlans);
num_double_vlans = priv->num_double_vlans - is_double;
- ret = stmmac_vlan_update(priv, num_double_vlans, true);
+ ret = stmmac_vlan_update(priv, num_double_vlans, write_hw);
if (ret) {
set_bit(vid, priv->active_vlans);
goto del_vlan_error;
@@ -6851,10 +6854,11 @@ static int stmmac_vlan_rx_kill_vid(struct net_device *ndev, __be16 proto, u16 vi
if (priv->hw->num_vlan) {
ret = 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;
}
}
diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_vlan.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_vlan.c
index f81015179d04..261bc751ade2 100644
--- a/drivers/net/ethernet/stmicro/stmmac/stmmac_vlan.c
+++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_vlan.c
@@ -147,7 +147,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)
{
- u32 val;
int i;
/* Single Rx VLAN Filter */
@@ -157,12 +156,8 @@ static void vlan_restore_hw_rx_fltr(struct net_device *dev,
}
/* Extended Rx VLAN Filter Enable */
- for (i = 0; i < hw->num_vlan; i++) {
- if (hw->vlan_filter[i] & VLAN_TAG_DATA_VEN) {
- val = hw->vlan_filter[i];
- vlan_write_filter(dev, hw, i, val);
- }
- }
+ for (i = 0; i < hw->num_vlan; i++)
+ vlan_write_filter(dev, hw, i, hw->vlan_filter[i]);
}
static void vlan_update_hash(struct mac_device_info *hw, u32 hash,
--
2.51.0
^ permalink raw reply related [flat|nested] 9+ messages in thread