[PATCH net-next 1/2] mlxsw: pci: Process EQ in the IRQ handler instead of a tasklet

From
Petr Machata <petrm@nvidia.com>
Date
2026-11-16 10:18:20
Reply to
Petr Machata, 2026-11-16
mlxsw_pci_eq_irq_handler() schedules a tasklet, which then reads the EQ and
schedules NAPI instances for the CQs that have pending events. The actual
completion processing itself is done by NAPI.

The EQ processing is bounded by half of the EQ size (see credits in
mlxsw_pci_eq_tasklet()), and all it does is to ring two doorbells and call
napi_schedule(), both of which are safe to do from a hard IRQ context. The
EQ is only re-armed at the end, so the handler cannot be re-entered.

The tasklet therefore does not really serve a useful purpose: neither
structurally, nor with regards to permissible runtime operations, nor with
regards to amount of time spent in IRQ. It is just an extra deferral layer.

Drop the tasklet and do the work directly in the IRQ handler. Change
napi_schedule() to napi_schedule_irqoff() to leverage the fact that
interrupts are already masked.

Reviewed-by: Ido Schimmel <idosch@nvidia.com>
Signed-off-by: Petr Machata <petrm@nvidia.com>
---
 drivers/net/ethernet/mellanox/mlxsw/pci.c | 31 ++++++++---------------
 1 file changed, 11 insertions(+), 20 deletions(-)
diff --git a/drivers/net/ethernet/mellanox/mlxsw/pci.c b/drivers/net/ethernet/mellanox/mlxsw/pci.c
index dceb69945d26..b2a7f568c74a 100644
--- a/drivers/net/ethernet/mellanox/mlxsw/pci.c
+++ b/drivers/net/ethernet/mellanox/mlxsw/pci.c
@@ -88,9 +88,6 @@ struct mlxsw_pci_queue {
 			struct napi_struct napi;
 			struct page_pool *page_pool;
 		} cq;
-		struct {
-			struct tasklet_struct tasklet;
-		} eq;
 		struct {
 			struct mlxsw_pci_queue *cq;
 		} rdq;
@@ -1111,16 +1108,19 @@ static char *mlxsw_pci_eq_sw_eqe_get(struct mlxsw_pci_queue *q)
 	return elem;
 }
 
-static void mlxsw_pci_eq_tasklet(struct tasklet_struct *t)
+static irqreturn_t mlxsw_pci_eq_irq_handler(int irq, void *dev_id)
 {
 	unsigned long active_cqns[BITS_TO_LONGS(MLXSW_PCI_CQS_MAX)];
-	struct mlxsw_pci_queue *q = from_tasklet(q, t, u.eq.tasklet);
-	struct mlxsw_pci *mlxsw_pci = q->pci;
-	int credits = q->count >> 1;
+	struct mlxsw_pci *mlxsw_pci = dev_id;
+	struct mlxsw_pci_queue *q;
 	u8 cqn, cq_count;
 	int items = 0;
+	int credits;
 	char *eqe;
 
+	q = mlxsw_pci_eq_get(mlxsw_pci);
+	credits = q->count >> 1;
+
 	memset(&active_cqns, 0, sizeof(active_cqns));
 
 	while ((eqe = mlxsw_pci_eq_sw_eqe_get(q))) {
@@ -1132,7 +1132,7 @@ static void mlxsw_pci_eq_tasklet(struct tasklet_struct *t)
 	}
 
 	if (!items)
-		return;
+		return IRQ_HANDLED;
 
 	mlxsw_pci_queue_doorbell_consumer_ring(mlxsw_pci, q);
 	mlxsw_pci_queue_doorbell_arm_consumer_ring(mlxsw_pci, q);
@@ -1140,8 +1140,10 @@ static void mlxsw_pci_eq_tasklet(struct tasklet_struct *t)
 	cq_count = mlxsw_pci->num_cqs;
 	for_each_set_bit(cqn, active_cqns, cq_count) {
 		q = mlxsw_pci_cq_get(mlxsw_pci, cqn);
-		napi_schedule(&q->u.cq.napi);
+		napi_schedule_irqoff(&q->u.cq.napi);
 	}
+
+	return IRQ_HANDLED;
 }
 
 static int mlxsw_pci_eq_init(struct mlxsw_pci *mlxsw_pci, char *mbox,
@@ -1176,7 +1178,6 @@ static int mlxsw_pci_eq_init(struct mlxsw_pci *mlxsw_pci, char *mbox,
 	err = mlxsw_cmd_sw2hw_eq(mlxsw_pci->core, mbox, q->num);
 	if (err)
 		return err;
-	tasklet_setup(&q->u.eq.tasklet, mlxsw_pci_eq_tasklet);
 	mlxsw_pci_queue_doorbell_consumer_ring(mlxsw_pci, q);
 	mlxsw_pci_queue_doorbell_arm_consumer_ring(mlxsw_pci, q);
 	return 0;
@@ -1730,16 +1731,6 @@ static void mlxsw_pci_fw_area_fini(struct mlxsw_pci *mlxsw_pci)
 	kfree(mlxsw_pci->fw_area.items);
 }
 
-static irqreturn_t mlxsw_pci_eq_irq_handler(int irq, void *dev_id)
-{
-	struct mlxsw_pci *mlxsw_pci = dev_id;
-	struct mlxsw_pci_queue *q;
-
-	q = mlxsw_pci_eq_get(mlxsw_pci);
-	tasklet_schedule(&q->u.eq.tasklet);
-	return IRQ_HANDLED;
-}
-
 static int mlxsw_pci_mbox_alloc(struct mlxsw_pci *mlxsw_pci,
 				struct mlxsw_pci_mem_item *mbox)
 {
-- 
2.56.1
Thread (5 messages) 5 messages, 2 authors, last reply 2d ago
Keyboard shortcuts
hback out one level
jnext message in thread / next series-diff position
kprevious message in thread / previous series-diff position
ldrill in
Escclose help / fold thread tree
?toggle this help