net: mana: Ring doorbell at 4 CQ wraparounds
Subsystems (5)
PATCH 1/1 net: mana: Ring doorbell at 4 CQ wraparounds
MANA hardware requires at least one doorbell ring every 8 wraparounds of the CQ. The driver rings the doorbell as a form of flow control to inform hardware that CQEs have been consumed.
The NAPI poll functions mana_poll_tx_cq() and mana_poll_rx_cq() can poll up to CQE_POLLING_BUFFER (512) completions per call. If the CQ has fewer than 512 entries, a single poll call can process more than 4 wraparounds without ringing the doorbell. The doorbell threshold check also uses ">" instead of ">=", delaying the ring by one extra CQE beyond 4 wraparounds. Combined, these issues can cause the driver to exceed the 8-wraparound hardware limit, leading to missed completions and stalled queues.
Fix this by capping the number of CQEs polled per call to 4 wraparounds of the CQ in both TX and RX paths. Also change the doorbell threshold from ">" to ">=" so the doorbell is rung as soon as 4 wraparounds are reached.
--- drivers/net/ethernet/microsoft/mana/mana_en.c | 23 +++++++++++++++---- 1 file changed, 18 insertions(+), 5 deletions(-)
drivers/net/ethernet/microsoft/mana/mana_en.c +18 -5
@@ -1770,8 +1770,14 @@ static void mana_poll_tx_cq(struct mana_cq *cq) ndev = txq->ndev; apc =netdev_priv (ndev); +/* Limit CQEs polled to 4 wraparounds of the CQ to ensure the +* doorbell can be rung in time for the hardware's requirement +* of at least one doorbell ring every 8 wraparounds. +*/ comp_read =mana_gd_poll_cq (cq->gdma_cq, completions, -CQE_POLLING_BUFFER ); +min_t (u32, (cq->gdma_cq->queue_size / +COMP_ENTRY_SIZE ) *4 , +CQE_POLLING_BUFFER ));if (comp_read <1 )return ;
@@ -2156,7 +2162,14 @@ static void mana_poll_rx_cq(struct mana_cq *cq)struct mana_rxq *rxq = cq->rxq;int comp_read, i; - comp_read =mana_gd_poll_cq (cq->gdma_cq, comp,CQE_POLLING_BUFFER ); +/* Limit CQEs polled to 4 wraparounds of the CQ to ensure the +* doorbell can be rung in time for the hardware's requirement +* of at least one doorbell ring every 8 wraparounds. +*/ + comp_read =mana_gd_poll_cq (cq->gdma_cq, comp, +min_t (u32, (cq->gdma_cq->queue_size / +COMP_ENTRY_SIZE ) *4 , +CQE_POLLING_BUFFER ));WARN_ON_ONCE (comp_read >CQE_POLLING_BUFFER ); rxq->xdp_flush = false;
@@ -2201,11 +2214,11 @@ static int mana_cq_handler(void *context, struct gdma_queue *gdma_queue)mana_gd_ring_cq (gdma_queue,SET_ARM_BIT ); cq->work_done_since_doorbell =0 ;napi_complete_done (&cq->napi, w); - }else if (cq->work_done_since_doorbell > - cq->gdma_cq->queue_size /COMP_ENTRY_SIZE *4 ) { + }else if (cq->work_done_since_doorbell >= + (cq->gdma_cq->queue_size /COMP_ENTRY_SIZE ) *4 ) {/* MANA hardware requires at least one doorbell ring every 8 * wraparounds of CQ even if there is no need to arm the CQ. -* This driver rings the doorbell as soon as we have exceeded +* This driver rings the doorbell as soon as it has processed * 4 wraparounds. */ mana_gd_ring_cq (gdma_queue,0 );
Signature · 1 line
2.43.0
Quoted 30 lines · Long Li
MANA hardware requires at least one doorbell ring every 8 wraparounds of the CQ. The driver rings the doorbell as a form of flow control to inform hardware that CQEs have been consumed.
The NAPI poll functions
mana_poll_tx_cq()andmana_poll_rx_cq()can poll up toCQE_POLLING_BUFFER(512) completions per call. If the CQ has fewer than 512 entries, a single poll call can process more than 4 wraparounds without ringing the doorbell. The doorbell threshold check also uses ">" instead of ">=", delaying the ring by one extra CQE beyond 4 wraparounds. Combined, these issues can cause the driver to exceed the 8-wraparound hardware limit, leading to missed completions and stalled queues.Fix this by capping the number of CQEs polled per call to 4 wraparounds of the CQ in both TX and RX paths. Also change the doorbell threshold from ">" to ">=" so the doorbell is rung as soon as 4 wraparounds are reached.
Fixes 58a63729c957 ("net: mana: Fix doorbell out of order violation and avoid unnecessary doorbell rings")Signed-off-by Long Li <[email protected]>--- drivers/net/ethernet/microsoft/mana/mana_en.c | 23 +++++++++++++++---- 1 file changed, 18 insertions(+), 5 deletions(-)drivers/net/ethernet/microsoft/mana/mana_en.c +0
-0
drivers/net/ethernet/microsoft/mana/mana_en.c static void mana_poll_tx_cq(struct mana_cq *cq) · line 1778
Quoted 10 lines
drivers/net/ethernet/microsoft/mana/mana_en.c +5
-1@@ -1770,8 +1770,14 @@ static void mana_poll_tx_cq(struct mana_cq *cq) ndev = txq->ndev; apc =netdev_priv (ndev); +/* Limit CQEs polled to 4 wraparounds of the CQ to ensure the +* doorbell can be rung in time for the hardware's requirement +* of at least one doorbell ring every 8 wraparounds. +*/ comp_read = mana_gd_poll_cq(cq->gdma_cq, completions, -CQE_POLLING_BUFFER ); + min_t(u32, (cq->gdma_cq->queue_size /
no need for min_t, simple min() can be used, queue_size is already u32
Quoted 6 lines
drivers/net/ethernet/microsoft/mana/mana_en.c +2
-0+ COMP_ENTRY_SIZE) * 4, + CQE_POLLING_BUFFER));if (comp_read <1 )return ;
drivers/net/ethernet/microsoft/mana/mana_en.c static void mana_poll_rx_cq(struct mana_cq *cq) · line 2170
Quoted 10 lines
drivers/net/ethernet/microsoft/mana/mana_en.c +6
-1@@ -2156,7 +2162,14 @@ static void mana_poll_rx_cq(struct mana_cq *cq)struct mana_rxq *rxq = cq->rxq;int comp_read, i; - comp_read =mana_gd_poll_cq (cq->gdma_cq, comp,CQE_POLLING_BUFFER ); +/* Limit CQEs polled to 4 wraparounds of the CQ to ensure the +* doorbell can be rung in time for the hardware's requirement +* of at least one doorbell ring every 8 wraparounds. +*/ + comp_read = mana_gd_poll_cq(cq->gdma_cq, comp, + min_t(u32, (cq->gdma_cq->queue_size /
same here
Quoted 5 lines
drivers/net/ethernet/microsoft/mana/mana_en.c +2
-0+ COMP_ENTRY_SIZE) * 4, + CQE_POLLING_BUFFER));WARN_ON_ONCE (comp_read >CQE_POLLING_BUFFER ); rxq->xdp_flush = false;
Quoted 39 lines
Subject: [EXTERNAL] Re: [PATCH net] net: mana: Ring doorbell at 4 CQ wraparounds
Quoted 35 lines · Long Li
MANA hardware requires at least one doorbell ring every 8 wraparounds of the CQ. The driver rings the doorbell as a form of flow control to inform hardware that CQEs have been consumed.
The NAPI poll functions
mana_poll_tx_cq()andmana_poll_rx_cq()can poll up toCQE_POLLING_BUFFER(512) completions per call. If the CQ has fewer than 512 entries, a single poll call can process more than 4 wraparounds without ringing the doorbell. The doorbell threshold check also uses ">" instead of ">=", delaying the ring by one extra CQE beyond 4 wraparounds. Combined, these issues can cause the driver to exceed the 8-wraparound hardware limit, leading to missed completions and stalled queues.Fix this by capping the number of CQEs polled per call to 4 wraparounds of the CQ in both TX and RX paths. Also change the doorbell threshold from ">" to ">=" so the doorbell is rung as soon as 4 wraparounds are reached.
Fixes 58a63729c957 ("net: mana: Fix doorbell out of order violationand avoid unnecessary doorbell rings")
Signed-off-by Long Li <[email protected]>--- drivers/net/ethernet/microsoft/mana/mana_en.c | 23 +++++++++++++++---- 1 file changed, 18 insertions(+), 5 deletions(-)drivers/net/ethernet/microsoft/mana/mana_en.c +0
-0@@ -1770,8 +1770,14 @@ static void mana_poll_tx_cq(struct mana_cq *cq) ndev = txq->ndev; apc =netdev_priv (ndev);
Quoted 9 lines
drivers/net/ethernet/microsoft/mana/mana_en.c static void mana_poll_tx_cq(struct mana_cq *cq) · line 1778
Quoted 7 lines
drivers/net/ethernet/microsoft/mana/mana_en.c +5
-1+/* Limit CQEs polled to 4 wraparounds of the CQ to ensure the +* doorbell can be rung in time for the hardware's requirement +* of at least one doorbell ring every 8 wraparounds. +*/ comp_read = mana_gd_poll_cq(cq->gdma_cq, completions, -CQE_POLLING_BUFFER ); + min_t(u32, (cq->gdma_cq->queue_size /no need for
min_t, simplemin()can be used,queue_sizeis already u32
Thank you, I'm sending v2.
Long
Quoted 26 lines
drivers/net/ethernet/microsoft/mana/mana_en.c static void mana_poll_rx_cq(struct mana_cq *cq) · line 2159
Quoted 11 lines
drivers/net/ethernet/microsoft/mana/mana_en.c +2
-1+ COMP_ENTRY_SIZE) * 4, + CQE_POLLING_BUFFER));if (comp_read <1 )return ;@@ -2156,7 +2162,14 @@ static void mana_poll_rx_cq(struct mana_cq *cq)struct mana_rxq *rxq = cq->rxq;int comp_read, i; - comp_read = mana_gd_poll_cq(cq->gdma_cq, comp,
CQE_POLLING_BUFFER);drivers/net/ethernet/microsoft/mana/mana_en.c static void mana_poll_rx_cq(struct mana_cq *cq) · line 2170
Quoted 6 lines
drivers/net/ethernet/microsoft/mana/mana_en.c +6
-0+/* Limit CQEs polled to 4 wraparounds of the CQ to ensure the +* doorbell can be rung in time for the hardware's requirement +* of at least one doorbell ring every 8 wraparounds. +*/ + comp_read = mana_gd_poll_cq(cq->gdma_cq, comp, + min_t(u32, (cq->gdma_cq->queue_size /same here
Quoted 5 lines
drivers/net/ethernet/microsoft/mana/mana_en.c +2
-0+ COMP_ENTRY_SIZE) * 4, + CQE_POLLING_BUFFER));WARN_ON_ONCE (comp_read >CQE_POLLING_BUFFER ); rxq->xdp_flush = false;