[net] octeon_ep: update BQL sent bytes before ringing doorbell

Message ID 20231010115015.2279977-1-srasheed@marvell.com
State New
Headers
Series [net] octeon_ep: update BQL sent bytes before ringing doorbell |

Commit Message

Shinas Rasheed Oct. 10, 2023, 11:50 a.m. UTC
  Sometimes Tx is completed immediately after doorbell is updated, which
causes Tx completion routing to update completion bytes before the
same packet bytes are updated in sent bytes in transmit function, hence
hitting BUG_ON() in dql_completed(). To avoid this, update BQL
sent bytes before ringing doorbell.

Fixes: 37d79d059606 ("octeon_ep: add Tx/Rx processing and interrupt support")
Signed-off-by: Shinas Rasheed <srasheed@marvell.com>
---
 drivers/net/ethernet/marvell/octeon_ep/octep_main.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
  

Comments

Paolo Abeni Oct. 12, 2023, 8:31 a.m. UTC | #1
On Tue, 2023-10-10 at 04:50 -0700, Shinas Rasheed wrote:
> Sometimes Tx is completed immediately after doorbell is updated, which
> causes Tx completion routing to update completion bytes before the
> same packet bytes are updated in sent bytes in transmit function, hence
> hitting BUG_ON() in dql_completed(). To avoid this, update BQL
> sent bytes before ringing doorbell.
> 
> Fixes: 37d79d059606 ("octeon_ep: add Tx/Rx processing and interrupt support")
> Signed-off-by: Shinas Rasheed <srasheed@marvell.com>
> ---
>  drivers/net/ethernet/marvell/octeon_ep/octep_main.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/net/ethernet/marvell/octeon_ep/octep_main.c b/drivers/net/ethernet/marvell/octeon_ep/octep_main.c
> index dbc518ff8276..314f9c661f93 100644
> --- a/drivers/net/ethernet/marvell/octeon_ep/octep_main.c
> +++ b/drivers/net/ethernet/marvell/octeon_ep/octep_main.c
> @@ -718,6 +718,7 @@ static netdev_tx_t octep_start_xmit(struct sk_buff *skb,
>  	/* Flush the hw descriptor before writing to doorbell */
>  	wmb();
>  
> +	netdev_tx_sent_queue(iq->netdev_q, skb->len);

If tx completion and start_xmit happen on 2 different CPUs, how do you
ensure that xmit_completion will observe the values written here?

Specifically, don't you need to move netdev_tx_sent_queue() before the
above memory barrier?

Thanks,

Paolo
  
Shinas Rasheed Oct. 12, 2023, 10 a.m. UTC | #2
Hi,

If tx completion and start_xmit happen on 2 different CPUs, how do you
ensure that xmit_completion will observe the values written here?

Specifically, don't you need to move netdev_tx_sent_queue() before the
above memory barrier?

>>> Yes, you are correct. I'll update the changeset. Thank you.
  

Patch

diff --git a/drivers/net/ethernet/marvell/octeon_ep/octep_main.c b/drivers/net/ethernet/marvell/octeon_ep/octep_main.c
index dbc518ff8276..314f9c661f93 100644
--- a/drivers/net/ethernet/marvell/octeon_ep/octep_main.c
+++ b/drivers/net/ethernet/marvell/octeon_ep/octep_main.c
@@ -718,6 +718,7 @@  static netdev_tx_t octep_start_xmit(struct sk_buff *skb,
 	/* Flush the hw descriptor before writing to doorbell */
 	wmb();
 
+	netdev_tx_sent_queue(iq->netdev_q, skb->len);
 	/* Ring Doorbell to notify the NIC there is a new packet */
 	writel(1, iq->doorbell_reg);
 	atomic_inc(&iq->instr_pending);
@@ -726,7 +727,6 @@  static netdev_tx_t octep_start_xmit(struct sk_buff *skb,
 		wi = 0;
 	iq->host_write_index = wi;
 
-	netdev_tx_sent_queue(iq->netdev_q, skb->len);
 	iq->stats.instr_posted++;
 	skb_tx_timestamp(skb);
 	return NETDEV_TX_OK;