* [PATCH net-next 2/3] net: stmmac: add an opt-in MSI vector mask for NAPI
2026-12-04 20:31 [PATCH net-next 0/3] net: stmmac: reduce DMA interrupt latency on YT6801 Johan Alvarado
2026-12-04 20:31 ` [PATCH net-next 1/3] net: stmmac: dwmac4: do not treat TBU as a TX event Johan Alvarado
@ 2026-12-04 20:31 ` Johan Alvarado
2026-12-04 20:31 ` [PATCH net-next 3/3] net: stmmac: motorcomm: mask the MSI vector during NAPI Johan Alvarado
2 siblings, 0 replies; 4+ messages in thread
From: Johan Alvarado @ 2026-12-04 20:31 UTC (permalink / raw)
To: Jakub Kicinski, Paolo Abeni, Eric Dumazet, David S . Miller,
Andrew Lunn, Maxime Chevallier, Yao Zi
Cc: Maxime Coquelin, Alexandre Torgue, netdev, linux-stm32,
linux-arm-kernel, Johan Alvarado, Pengfei Zhang
With one MSI per DMA channel, stmmac masks the channel interrupt in
DMA_CHAN_INTR_ENA during NAPI. On the YT6801, an RI or TI set while
masked raises no interrupt on unmask. The event waits for an unrelated
interrupt or the TX coalesce timer.
Add STMMAC_FLAG_NAPI_MASK_MSI_VEC. When it and STMMAC_FLAG_MULTI_MSI_EN
are set, the RX and TX MSI handlers disable their vector with
disable_irq_nosync() and the poll enables it again. The DMA channel
interrupt stays enabled, so the irq core resends events raised during
the poll on enable_irq(). The vendor driver does the same.
The channel records which vector it disabled, and a completing poll
undoes only its own mask. The TX timer and the shared interrupt keep
the DMA mask. stmmac_enable_all_dma_irq() and
stmmac_enable_rx/tx_queue() re-enable a vector left disabled by
napi_disable(). Freeing the interrupts clears the record.
The resend uses irq_retrigger() or CONFIG_HARDIRQS_SW_RESEND, which
arm64 and x86 select. Setting IRQ_DISABLE_UNLAZY instead would add two
PCIe writes per NAPI cycle.
The default is unchanged. The vector mask is untested on dwmac-intel
and dwmac-loongson.
Signed-off-by: Johan Alvarado <contact@c127.dev>
---
drivers/net/ethernet/stmicro/stmmac/stmmac.h | 3 +
.../net/ethernet/stmicro/stmmac/stmmac_main.c | 105 ++++++++++++++++--
include/linux/stmmac.h | 1 +
3 files changed, 101 insertions(+), 8 deletions(-)
diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac.h b/drivers/net/ethernet/stmicro/stmmac/stmmac.h
index fcc395321816..b3eb4b0d8491 100644
--- a/drivers/net/ethernet/stmicro/stmmac/stmmac.h
+++ b/drivers/net/ethernet/stmicro/stmmac/stmmac.h
@@ -146,6 +146,9 @@ struct stmmac_channel {
struct stmmac_priv *priv_data;
spinlock_t lock;
u32 index;
+ /* RX/TX MSI vector disabled for NAPI, STMMAC_FLAG_NAPI_MASK_MSI_VEC */
+ bool rx_vec_masked;
+ bool tx_vec_masked;
};
struct stmmac_fpe_cfg {
diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
index b3524d46863d..b34942ad08ba 100644
--- a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
+++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
@@ -2592,6 +2592,78 @@ static void stmmac_stop_tx_dma(struct stmmac_priv *priv, u32 chan)
stmmac_stop_tx(priv, priv->ioaddr, chan);
}
+/* Mask a channel interrupt for NAPI. With STMMAC_FLAG_NAPI_MASK_MSI_VEC
+ * and per-channel MSIs, the MSI vector is disabled instead of the DMA
+ * channel interrupt, so an event raised meanwhile is resent by the irq
+ * core (lazy disable) when the vector is enabled again. Called with
+ * ch->lock held.
+ */
+static void stmmac_napi_mask_irq(struct stmmac_priv *priv, u32 chan,
+ u32 dir)
+{
+ struct stmmac_channel *ch = &priv->channel[chan];
+
+ if ((priv->plat->flags & STMMAC_FLAG_NAPI_MASK_MSI_VEC) &&
+ (priv->plat->flags & STMMAC_FLAG_MULTI_MSI_EN)) {
+ if (dir == DMA_DIR_RX && !ch->rx_vec_masked) {
+ ch->rx_vec_masked = true;
+ disable_irq_nosync(priv->msi->rx_irq[chan]);
+ return;
+ }
+ if (dir == DMA_DIR_TX && !ch->tx_vec_masked) {
+ ch->tx_vec_masked = true;
+ disable_irq_nosync(priv->msi->tx_irq[chan]);
+ return;
+ }
+ }
+
+ stmmac_disable_dma_irq(priv, priv->ioaddr, chan, dir != DMA_DIR_TX,
+ dir != DMA_DIR_RX);
+}
+
+/* Enable the MSI vectors stmmac_napi_mask_irq() disabled for @rx/@tx and
+ * clear @rx/@tx for them. Called with ch->lock held.
+ */
+static void stmmac_napi_unmask_vec(struct stmmac_priv *priv, u32 chan,
+ bool *rx, bool *tx)
+{
+ struct stmmac_channel *ch = &priv->channel[chan];
+
+ if (*rx && ch->rx_vec_masked) {
+ ch->rx_vec_masked = false;
+ enable_irq(priv->msi->rx_irq[chan]);
+ *rx = false;
+ }
+ if (*tx && ch->tx_vec_masked) {
+ ch->tx_vec_masked = false;
+ enable_irq(priv->msi->tx_irq[chan]);
+ *tx = false;
+ }
+}
+
+/* Undo stmmac_napi_mask_irq() or a DMA mask from the other NAPI
+ * schedulers when a poll completes. Called with ch->lock held.
+ */
+static void stmmac_napi_unmask_irq(struct stmmac_priv *priv, u32 chan,
+ bool rx, bool tx)
+{
+ stmmac_napi_unmask_vec(priv, chan, &rx, &tx);
+ if (rx || tx)
+ stmmac_enable_dma_irq(priv, priv->ioaddr, chan, rx, tx);
+}
+
+/* Enable the channel interrupts when a queue (re)starts. A NAPI stopped
+ * by napi_disable() may have left its vector disabled.
+ */
+static void stmmac_start_chan_irq(struct stmmac_priv *priv, u32 chan,
+ bool rx, bool tx)
+{
+ bool vrx = rx, vtx = tx;
+
+ stmmac_napi_unmask_vec(priv, chan, &vrx, &vtx);
+ stmmac_enable_dma_irq(priv, priv->ioaddr, chan, rx, tx);
+}
+
static void stmmac_enable_all_dma_irq(struct stmmac_priv *priv)
{
u8 rx_channels_count = priv->plat->rx_queues_to_use;
@@ -2604,7 +2676,7 @@ static void stmmac_enable_all_dma_irq(struct stmmac_priv *priv)
unsigned long flags;
spin_lock_irqsave(&ch->lock, flags);
- stmmac_enable_dma_irq(priv, priv->ioaddr, chan, 1, 1);
+ stmmac_start_chan_irq(priv, chan, true, true);
spin_unlock_irqrestore(&ch->lock, flags);
}
}
@@ -3179,7 +3251,11 @@ static int stmmac_napi_check(struct stmmac_priv *priv, u32 chan, u32 dir)
if ((status & handle_rx) && (chan < priv->plat->rx_queues_to_use)) {
if (napi_schedule_prep(rx_napi)) {
spin_lock_irqsave(&ch->lock, flags);
- stmmac_disable_dma_irq(priv, priv->ioaddr, chan, 1, 0);
+ if (dir == DMA_DIR_RX)
+ stmmac_napi_mask_irq(priv, chan, dir);
+ else
+ stmmac_disable_dma_irq(priv, priv->ioaddr, chan,
+ 1, 0);
spin_unlock_irqrestore(&ch->lock, flags);
__napi_schedule(rx_napi);
}
@@ -3188,7 +3264,11 @@ static int stmmac_napi_check(struct stmmac_priv *priv, u32 chan, u32 dir)
if ((status & handle_tx) && (chan < priv->plat->tx_queues_to_use)) {
if (napi_schedule_prep(tx_napi)) {
spin_lock_irqsave(&ch->lock, flags);
- stmmac_disable_dma_irq(priv, priv->ioaddr, chan, 0, 1);
+ if (dir == DMA_DIR_TX)
+ stmmac_napi_mask_irq(priv, chan, dir);
+ else
+ stmmac_disable_dma_irq(priv, priv->ioaddr, chan,
+ 0, 1);
spin_unlock_irqrestore(&ch->lock, flags);
__napi_schedule(tx_napi);
}
@@ -3875,6 +3955,15 @@ static void stmmac_free_irq(struct net_device *dev,
struct stmmac_msi *msi = priv->msi;
int j;
+ /* NAPI and the TX timers are stopped here, so no lock is needed.
+ * With MULTI_MSI_EN the vectors are not shared, so request_irq()
+ * sets their disable depth back to 0.
+ */
+ for (j = 0; j < ARRAY_SIZE(priv->channel); j++) {
+ priv->channel[j].rx_vec_masked = false;
+ priv->channel[j].tx_vec_masked = false;
+ }
+
switch (irq_err) {
case REQ_IRQ_ERR_ALL:
irq_idx = priv->plat->tx_queues_to_use;
@@ -6217,7 +6306,7 @@ static int stmmac_napi_poll_rx(struct napi_struct *napi, int budget)
unsigned long flags;
spin_lock_irqsave(&ch->lock, flags);
- stmmac_enable_dma_irq(priv, priv->ioaddr, chan, 1, 0);
+ stmmac_napi_unmask_irq(priv, chan, true, false);
spin_unlock_irqrestore(&ch->lock, flags);
}
@@ -6246,7 +6335,7 @@ static int stmmac_napi_poll_tx(struct napi_struct *napi, int budget)
unsigned long flags;
spin_lock_irqsave(&ch->lock, flags);
- stmmac_enable_dma_irq(priv, priv->ioaddr, chan, 0, 1);
+ stmmac_napi_unmask_irq(priv, chan, false, true);
spin_unlock_irqrestore(&ch->lock, flags);
}
@@ -6299,7 +6388,7 @@ static int stmmac_napi_poll_rxtx(struct napi_struct *napi, int budget)
/* Both RX and TX work done are complete,
* so enable both RX & TX IRQs.
*/
- stmmac_enable_dma_irq(priv, priv->ioaddr, chan, 1, 1);
+ stmmac_napi_unmask_irq(priv, chan, true, true);
spin_unlock_irqrestore(&ch->lock, flags);
}
@@ -7303,7 +7392,7 @@ void stmmac_enable_rx_queue(struct stmmac_priv *priv, u32 queue)
stmmac_start_rx_dma(priv, queue);
spin_lock_irqsave(&ch->lock, flags);
- stmmac_enable_dma_irq(priv, priv->ioaddr, queue, 1, 0);
+ stmmac_start_chan_irq(priv, queue, true, false);
spin_unlock_irqrestore(&ch->lock, flags);
}
@@ -7354,7 +7443,7 @@ void stmmac_enable_tx_queue(struct stmmac_priv *priv, u32 queue)
stmmac_start_tx_dma(priv, queue);
spin_lock_irqsave(&ch->lock, flags);
- stmmac_enable_dma_irq(priv, priv->ioaddr, queue, 0, 1);
+ stmmac_start_chan_irq(priv, queue, false, true);
spin_unlock_irqrestore(&ch->lock, flags);
}
diff --git a/include/linux/stmmac.h b/include/linux/stmmac.h
index 00be2df63d22..37e3f5c001b0 100644
--- a/include/linux/stmmac.h
+++ b/include/linux/stmmac.h
@@ -211,6 +211,7 @@ enum dwmac_core_type {
#define STMMAC_FLAG_HWTSTAMP_CORRECT_LATENCY BIT(14)
#define STMMAC_FLAG_KEEP_PREAMBLE_BEFORE_SFD BIT(15)
#define STMMAC_FLAG_SERDES_SUPPORTS_2500M BIT(16)
+#define STMMAC_FLAG_NAPI_MASK_MSI_VEC BIT(17)
struct mac_device_info;
--
2.56.1
^ permalink raw reply related [flat|nested] 4+ messages in thread* [PATCH net-next 3/3] net: stmmac: motorcomm: mask the MSI vector during NAPI
2026-12-04 20:31 [PATCH net-next 0/3] net: stmmac: reduce DMA interrupt latency on YT6801 Johan Alvarado
2026-12-04 20:31 ` [PATCH net-next 1/3] net: stmmac: dwmac4: do not treat TBU as a TX event Johan Alvarado
2026-12-04 20:31 ` [PATCH net-next 2/3] net: stmmac: add an opt-in MSI vector mask for NAPI Johan Alvarado
@ 2026-12-04 20:31 ` Johan Alvarado
2 siblings, 0 replies; 4+ messages in thread
From: Johan Alvarado @ 2026-12-04 20:31 UTC (permalink / raw)
To: Jakub Kicinski, Paolo Abeni, Eric Dumazet, David S . Miller,
Andrew Lunn, Maxime Chevallier, Yao Zi
Cc: Maxime Coquelin, Alexandre Torgue, netdev, linux-stm32,
linux-arm-kernel, Johan Alvarado, Pengfei Zhang
On the YT6801, an RI or TI set while the DMA channel interrupt is
masked for NAPI raises no MSI on unmask. During a 64-byte UDP TX flood,
bpftrace shows over 1300 gaps longer than 2 ms between
stmmac_napi_poll_tx() calls per 10 s run.
The glue INT_MODERATION register, set to 200 us by motorcomm_init(),
adds up to 200 us of RX latency on top of RIWT (ethtool -C rx-usecs).
With rx-usecs 33, the median ping RTT is 0.32-0.36 ms with
INT_MODERATION at 0 and 0.53-0.54 ms at 200.
Set STMMAC_FLAG_NAPI_MASK_MSI_VEC under MSI-X and INT_MODERATION to 0.
The vector mask alone keeps ping RTT at 0.80-0.87 ms, and moderation 0
alone drops 64-byte UDP TX to 50.2-50.8 kpps.
Orange Pi 5 Pro (RK3588S, YT6801 on PCIe 2.0 x1), 7.3.6 backport,
default coalescing (rx-usecs 328, tx-usecs 5000, tx-frames 25), iperf3
to a peer one routed hop away, 10 s per test, 5 interleaved runs,
min-max. TX poll gaps are gaps over 2 ms traced with bpftrace.
before after
ping RTT (ms) 0.82-0.86 0.60-0.66
TCP RX (Mb/s) 917-923 931-935
TCP TX (Mb/s) 826-866 839-867
UDP 64B TX (kpps) 67.3-68.1 76.9-78.7
TX poll gaps per run 1381-1587 14-298
UDP 64B RX loss (%) 0.65-1.60 0.01-0.06
CPU, TCP RX (%) 10.1-12.4 11.6-13.9
RX interrupts/s, TCP RX 1751-1776 2999-3007
TX interrupts/s, UDP TX 884-928 7684-8492
RIWT alone now times RX interrupts, which accounts for the extra CPU.
motorcomm_resume() calls motorcomm_init(), so the setting survives
resume. Link down/up during a UDP flood left no unbalanced enable_irq()
warning.
With a single MSI only the moderation change applies:
before after
ping RTT (ms) 0.62-0.74 0.63-0.66
UDP 64B RX loss (%) 0.68-2.20 0.01-0.03
CPU, TCP RX (%) 9.2-13.2 13.6-14.1
TCP throughput did not change.
Signed-off-by: Johan Alvarado <contact@c127.dev>
---
drivers/net/ethernet/stmicro/stmmac/dwmac-motorcomm.c | 8 +++++---
1 file changed, 5 insertions(+), 3 deletions(-)
diff --git a/drivers/net/ethernet/stmicro/stmmac/dwmac-motorcomm.c b/drivers/net/ethernet/stmicro/stmmac/dwmac-motorcomm.c
index 42f0b11a7b60..627cf4000dea 100644
--- a/drivers/net/ethernet/stmicro/stmmac/dwmac-motorcomm.c
+++ b/drivers/net/ethernet/stmicro/stmmac/dwmac-motorcomm.c
@@ -174,8 +174,9 @@ static void motorcomm_init(struct dwmac_motorcomm_priv *priv)
{
writel(0x0, priv->base + MGMT_INT_CTRL0);
- writel(FIELD_PREP(INT_MODERATION_RX, 200) |
- FIELD_PREP(INT_MODERATION_TX, 200),
+ /* Interrupt coalescing is left to the stmmac core */
+ writel(FIELD_PREP(INT_MODERATION_RX, 0) |
+ FIELD_PREP(INT_MODERATION_TX, 0),
priv->base + INT_MODERATION);
/*
@@ -272,7 +273,8 @@ static int motorcomm_setup_irq(struct pci_dev *pdev,
res->tx_irq[0] = pci_irq_vector(pdev, 4);
res->irq = pci_irq_vector(pdev, 5);
- plat->flags |= STMMAC_FLAG_MULTI_MSI_EN;
+ plat->flags |= STMMAC_FLAG_MULTI_MSI_EN |
+ STMMAC_FLAG_NAPI_MASK_MSI_VEC;
} else {
dev_info(&pdev->dev, "failed to allocate MSI-X vector: %d\n",
ret);
--
2.56.1
^ permalink raw reply related [flat|nested] 4+ messages in thread