[PATCH net] net: ethernet: sunplus: check budget before calling napi_complete_done()
From: Janis Edvarts Lacis
Date: Sat Nov 14 2026 - 17:28:05 EST
Sunplus drivers currently do napi_complete() after each rx/tx poll is
done without checking whether budget was exhausted or not. Interrupts
are also unmasked before the call to napi_complete().
Replace napi_complete() with napi_complete_done() and add a check for
budget_left. Call napi_complete_done() only when the budget has been
not exhausted fully, e.g. budget_left > 0 and unmask interrupts only when
napi_complete_done() returns true.
I do not have the hardware necessary, this patch is not tested on real
hardware.
Fixes: fd3040b9394c ("net: ethernet: Add driver for Sunplus SP7021")
Signed-off-by: Janis Edvarts Lacis <janislacis06@xxxxxxxxx>
---
drivers/net/ethernet/sunplus/spl2sw_int.c | 26 ++++++++++++-----------
1 file changed, 14 insertions(+), 12 deletions(-)
diff --git a/drivers/net/ethernet/sunplus/spl2sw_int.c b/drivers/net/ethernet/sunplus/spl2sw_int.c
index a37c9a4c281f..1aada11429d4 100644
--- a/drivers/net/ethernet/sunplus/spl2sw_int.c
+++ b/drivers/net/ethernet/sunplus/spl2sw_int.c
@@ -125,13 +125,14 @@ int spl2sw_rx_poll(struct napi_struct *napi, int budget)
h_desc = comm->rx_desc[queue] + rx_pos;
}
- spin_lock_irqsave(&comm->int_mask_lock, flags);
- mask = readl(comm->l2sw_reg_base + L2SW_SW_INT_MASK_0);
- mask &= ~MAC_INT_RX;
- writel(mask, comm->l2sw_reg_base + L2SW_SW_INT_MASK_0);
- spin_unlock_irqrestore(&comm->int_mask_lock, flags);
+ if (budget_left > 0 && napi_complete_done(napi, budget - budget_left)) {
+ spin_lock_irqsave(&comm->int_mask_lock, flags);
+ mask = readl(comm->l2sw_reg_base + L2SW_SW_INT_MASK_0);
+ mask &= ~MAC_INT_RX;
+ writel(mask, comm->l2sw_reg_base + L2SW_SW_INT_MASK_0);
+ spin_unlock_irqrestore(&comm->int_mask_lock, flags);
+ }
- napi_complete(napi);
return budget - budget_left;
}
@@ -198,13 +199,14 @@ int spl2sw_tx_poll(struct napi_struct *napi, int budget)
spin_unlock(&comm->tx_lock);
- spin_lock_irqsave(&comm->int_mask_lock, flags);
- mask = readl(comm->l2sw_reg_base + L2SW_SW_INT_MASK_0);
- mask &= ~MAC_INT_TX;
- writel(mask, comm->l2sw_reg_base + L2SW_SW_INT_MASK_0);
- spin_unlock_irqrestore(&comm->int_mask_lock, flags);
+ if (budget_left > 0 && napi_complete_done(napi, budget - budget_left)) {
+ spin_lock_irqsave(&comm->int_mask_lock, flags);
+ mask = readl(comm->l2sw_reg_base + L2SW_SW_INT_MASK_0);
+ mask &= ~MAC_INT_TX;
+ writel(mask, comm->l2sw_reg_base + L2SW_SW_INT_MASK_0);
+ spin_unlock_irqrestore(&comm->int_mask_lock, flags);
+ }
- napi_complete(napi);
return budget - budget_left;
}
--
2.43.0