diff mbox series

[v2,net-next,4/5] ionic: always use rxq_info

Message ID 20240826184422.21895-5-brett.creeley@amd.com (mailing list archive)
State Superseded
Delegated to: Netdev Maintainers
Headers show
Series ionic: convert Rx queue buffers to use page_pool | expand

Checks

Context Check Description
netdev/series_format success Posting correctly formatted
netdev/tree_selection success Clearly marked for net-next
netdev/ynl success Generated files up to date; no warnings/errors; no diff in generated;
netdev/fixes_present success Fixes tag not required for -next series
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 7 this patch: 7
netdev/build_tools success No tools touched, skip
netdev/cc_maintainers warning 5 maintainers not CCed: bpf@vger.kernel.org ast@kernel.org hawk@kernel.org daniel@iogearbox.net john.fastabend@gmail.com
netdev/build_clang success Errors and warnings before: 16 this patch: 16
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/deprecated_api success None detected
netdev/check_selftest success No net selftest shell script
netdev/verify_fixes success No Fixes tag
netdev/build_allmodconfig_warn success Errors and warnings before: 16 this patch: 16
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 124 lines checked
netdev/build_clang_rust success No Rust files in patch. Skipping build
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0
netdev/contest success net-next-2024-08-27--03-00 (tests: 713)

Commit Message

Brett Creeley Aug. 26, 2024, 6:44 p.m. UTC
From: Shannon Nelson <shannon.nelson@amd.com>

Instead of setting up and tearing down the rxq_info only when the XDP
program is loaded or unloaded, we will build the rxq_info whether or not
XDP is in use.  This is the more common use pattern and better supports
future conversion to page_pool.  Since the rxq_info wants the napi_id
we re-order things slightly to tie this into the queue init and deinit
functions where we do the add and delete of napi.

Signed-off-by: Shannon Nelson <shannon.nelson@amd.com>
Signed-off-by: Brett Creeley <brett.creeley@amd.com>
---
 .../net/ethernet/pensando/ionic/ionic_lif.c   | 55 +++++++------------
 1 file changed, 19 insertions(+), 36 deletions(-)

Comments

Larysa Zaremba Aug. 27, 2024, 12:08 p.m. UTC | #1
On Mon, Aug 26, 2024 at 11:44:21AM -0700, Brett Creeley wrote:
> From: Shannon Nelson <shannon.nelson@amd.com>
> 
> Instead of setting up and tearing down the rxq_info only when the XDP
> program is loaded or unloaded, we will build the rxq_info whether or not
> XDP is in use.  This is the more common use pattern and better supports
> future conversion to page_pool.  Since the rxq_info wants the napi_id
> we re-order things slightly to tie this into the queue init and deinit
> functions where we do the add and delete of napi.
> 
> Signed-off-by: Shannon Nelson <shannon.nelson@amd.com>
> Signed-off-by: Brett Creeley <brett.creeley@amd.com>
> ---
>  .../net/ethernet/pensando/ionic/ionic_lif.c   | 55 +++++++------------
>  1 file changed, 19 insertions(+), 36 deletions(-)
> 
> diff --git a/drivers/net/ethernet/pensando/ionic/ionic_lif.c b/drivers/net/ethernet/pensando/ionic/ionic_lif.c
> index 0fba2df33915..4a7763ec061f 100644
> --- a/drivers/net/ethernet/pensando/ionic/ionic_lif.c
> +++ b/drivers/net/ethernet/pensando/ionic/ionic_lif.c
> @@ -46,8 +46,9 @@ static int ionic_start_queues(struct ionic_lif *lif);
>  static void ionic_stop_queues(struct ionic_lif *lif);
>  static void ionic_lif_queue_identify(struct ionic_lif *lif);
>  
> -static int ionic_xdp_queues_config(struct ionic_lif *lif);
> -static void ionic_xdp_unregister_rxq_info(struct ionic_queue *q);
> +static void ionic_xdp_queues_config(struct ionic_lif *lif);
> +static int ionic_register_rxq_info(struct ionic_queue *q, unsigned int napi_id);
> +static void ionic_unregister_rxq_info(struct ionic_queue *q);
>  
>  static void ionic_dim_work(struct work_struct *work)
>  {
> @@ -380,6 +381,7 @@ static void ionic_lif_qcq_deinit(struct ionic_lif *lif, struct ionic_qcq *qcq)
>  	if (!(qcq->flags & IONIC_QCQ_F_INITED))
>  		return;
>  
> +	ionic_unregister_rxq_info(&qcq->q);
>  	if (qcq->flags & IONIC_QCQ_F_INTR) {
>  		ionic_intr_mask(idev->intr_ctrl, qcq->intr.index,
>  				IONIC_INTR_MASK_SET);
> @@ -437,9 +439,7 @@ static void ionic_qcq_free(struct ionic_lif *lif, struct ionic_qcq *qcq)
>  		qcq->sg_base_pa = 0;
>  	}
>  
> -	ionic_xdp_unregister_rxq_info(&qcq->q);
>  	ionic_qcq_intr_free(lif, qcq);
> -
>  	vfree(qcq->q.info);
>  	qcq->q.info = NULL;
>  }
> @@ -925,6 +925,11 @@ static int ionic_lif_rxq_init(struct ionic_lif *lif, struct ionic_qcq *qcq)
>  		netif_napi_add(lif->netdev, &qcq->napi, ionic_rx_napi);
>  	else
>  		netif_napi_add(lif->netdev, &qcq->napi, ionic_txrx_napi);
> +	err = ionic_register_rxq_info(q, qcq->napi.napi_id);
> +	if (err) {
> +		netif_napi_del(&qcq->napi);
> +		return err;
> +	}
>  
>  	qcq->flags |= IONIC_QCQ_F_INITED;
>  
> @@ -2143,9 +2148,7 @@ static int ionic_txrx_enable(struct ionic_lif *lif)
>  	int derr = 0;
>  	int i, err;
>  
> -	err = ionic_xdp_queues_config(lif);
> -	if (err)
> -		return err;
> +	ionic_xdp_queues_config(lif);
>  
>  	for (i = 0; i < lif->nxqs; i++) {
>  		if (!(lif->rxqcqs[i] && lif->txqcqs[i])) {
> @@ -2192,8 +2195,6 @@ static int ionic_txrx_enable(struct ionic_lif *lif)
>  		derr = ionic_qcq_disable(lif, lif->rxqcqs[i], derr);
>  	}
>  
> -	ionic_xdp_queues_config(lif);
> -
>  	return err;
>  }
>  
> @@ -2651,7 +2652,7 @@ static void ionic_vf_attr_replay(struct ionic_lif *lif)
>  	ionic_vf_start(ionic);
>  }
>  
> -static void ionic_xdp_unregister_rxq_info(struct ionic_queue *q)
> +static void ionic_unregister_rxq_info(struct ionic_queue *q)
>  {
>  	struct xdp_rxq_info *xi;
>  
> @@ -2665,7 +2666,7 @@ static void ionic_xdp_unregister_rxq_info(struct ionic_queue *q)
>  	kfree(xi);
>  }
>  
> -static int ionic_xdp_register_rxq_info(struct ionic_queue *q, unsigned int napi_id)
> +static int ionic_register_rxq_info(struct ionic_queue *q, unsigned int napi_id)
>  {
>  	struct xdp_rxq_info *rxq_info;
>  	int err;
> @@ -2698,45 +2699,27 @@ static int ionic_xdp_register_rxq_info(struct ionic_queue *q, unsigned int napi_
>  	return err;
>  }
>  
> -static int ionic_xdp_queues_config(struct ionic_lif *lif)
> +static void ionic_xdp_queues_config(struct ionic_lif *lif)

I think this function should also get a new name that would reflect the fact 
that it is just updating the XDP prog on rings. Also, ionic_xdp_queues_config 
sounds a little bit like configuring XDP_TX/xdp_xmit queues, but here we have rx 
queues only.

>  {
>  	struct bpf_prog *xdp_prog;
>  	unsigned int i;
> -	int err;
>  
>  	if (!lif->rxqcqs)
> -		return 0;
> +		return;
>  
> -	/* There's no need to rework memory if not going to/from NULL program.  */
> +	/* Nothing to do if not going to/from NULL program.  */
>  	xdp_prog = READ_ONCE(lif->xdp_prog);
>  	if (!xdp_prog == !lif->rxqcqs[0]->q.xdp_prog)
> -		return 0;
> +		return;
>  
>  	for (i = 0; i < lif->ionic->nrxqs_per_lif && lif->rxqcqs[i]; i++) {
>  		struct ionic_queue *q = &lif->rxqcqs[i]->q;
>  
> -		if (q->xdp_prog) {
> -			ionic_xdp_unregister_rxq_info(q);
> +		if (q->xdp_prog)
>  			q->xdp_prog = NULL;
> -			continue;
> -		}
> -
> -		err = ionic_xdp_register_rxq_info(q, lif->rxqcqs[i]->napi.napi_id);
> -		if (err) {
> -			dev_err(lif->ionic->dev, "failed to register RX queue %d info for XDP, err %d\n",
> -				i, err);
> -			goto err_out;
> -		}
> -		q->xdp_prog = xdp_prog;
> +		else
> +			q->xdp_prog = xdp_prog;
>  	}
> -
> -	return 0;
> -
> -err_out:
> -	for (i = 0; i < lif->ionic->nrxqs_per_lif && lif->rxqcqs[i]; i++)
> -		ionic_xdp_unregister_rxq_info(&lif->rxqcqs[i]->q);
> -
> -	return err;
>  }
>  
>  static int ionic_xdp_config(struct net_device *netdev, struct netdev_bpf *bpf)
> -- 
> 2.17.1
> 
>
Brett Creeley Aug. 27, 2024, 10:32 p.m. UTC | #2
On 8/27/2024 5:08 AM, Larysa Zaremba wrote:
> Caution: This message originated from an External Source. Use proper caution when opening attachments, clicking links, or responding.
> 
> 
> On Mon, Aug 26, 2024 at 11:44:21AM -0700, Brett Creeley wrote:
>> From: Shannon Nelson <shannon.nelson@amd.com>
>>
>> Instead of setting up and tearing down the rxq_info only when the XDP
>> program is loaded or unloaded, we will build the rxq_info whether or not
>> XDP is in use.  This is the more common use pattern and better supports
>> future conversion to page_pool.  Since the rxq_info wants the napi_id
>> we re-order things slightly to tie this into the queue init and deinit
>> functions where we do the add and delete of napi.
>>
>> Signed-off-by: Shannon Nelson <shannon.nelson@amd.com>
>> Signed-off-by: Brett Creeley <brett.creeley@amd.com>
>> ---
>>   .../net/ethernet/pensando/ionic/ionic_lif.c   | 55 +++++++------------
>>   1 file changed, 19 insertions(+), 36 deletions(-)
>>
>> diff --git a/drivers/net/ethernet/pensando/ionic/ionic_lif.c b/drivers/net/ethernet/pensando/ionic/ionic_lif.c

<snip>

>> -static int ionic_xdp_register_rxq_info(struct ionic_queue *q, unsigned int napi_id)
>> +static int ionic_register_rxq_info(struct ionic_queue *q, unsigned int napi_id)
>>   {
>>        struct xdp_rxq_info *rxq_info;
>>        int err;
>> @@ -2698,45 +2699,27 @@ static int ionic_xdp_register_rxq_info(struct ionic_queue *q, unsigned int napi_
>>        return err;
>>   }
>>
>> -static int ionic_xdp_queues_config(struct ionic_lif *lif)
>> +static void ionic_xdp_queues_config(struct ionic_lif *lif)
> 
> I think this function should also get a new name that would reflect the fact
> that it is just updating the XDP prog on rings. Also, ionic_xdp_queues_config
> sounds a little bit like configuring XDP_TX/xdp_xmit queues, but here we have rx
> queues only.

Yeah that makes sense. We can rename it to something closer to the 
function's contents/purpose.

Thanks,

Brett
> 
>>   {
>>        struct bpf_prog *xdp_prog;
>>        unsigned int i;
>> -     int err;
>>
>>        if (!lif->rxqcqs)
>> -             return 0;
>> +             return;
>>
>> -     /* There's no need to rework memory if not going to/from NULL program.  */
>> +     /* Nothing to do if not going to/from NULL program.  */
>>        xdp_prog = READ_ONCE(lif->xdp_prog);
>>        if (!xdp_prog == !lif->rxqcqs[0]->q.xdp_prog)
>> -             return 0;
>> +             return;
>>
>>        for (i = 0; i < lif->ionic->nrxqs_per_lif && lif->rxqcqs[i]; i++) {
>>                struct ionic_queue *q = &lif->rxqcqs[i]->q;
>>
>> -             if (q->xdp_prog) {
>> -                     ionic_xdp_unregister_rxq_info(q);
>> +             if (q->xdp_prog)
>>                        q->xdp_prog = NULL;
>> -                     continue;
>> -             }
>> -
>> -             err = ionic_xdp_register_rxq_info(q, lif->rxqcqs[i]->napi.napi_id);
>> -             if (err) {
>> -                     dev_err(lif->ionic->dev, "failed to register RX queue %d info for XDP, err %d\n",
>> -                             i, err);
>> -                     goto err_out;
>> -             }
>> -             q->xdp_prog = xdp_prog;
>> +             else
>> +                     q->xdp_prog = xdp_prog;
>>        }
>> -
>> -     return 0;
>> -
>> -err_out:
>> -     for (i = 0; i < lif->ionic->nrxqs_per_lif && lif->rxqcqs[i]; i++)
>> -             ionic_xdp_unregister_rxq_info(&lif->rxqcqs[i]->q);
>> -
>> -     return err;
>>   }
>>
>>   static int ionic_xdp_config(struct net_device *netdev, struct netdev_bpf *bpf)
>> --
>> 2.17.1
>>
>>
diff mbox series

Patch

diff --git a/drivers/net/ethernet/pensando/ionic/ionic_lif.c b/drivers/net/ethernet/pensando/ionic/ionic_lif.c
index 0fba2df33915..4a7763ec061f 100644
--- a/drivers/net/ethernet/pensando/ionic/ionic_lif.c
+++ b/drivers/net/ethernet/pensando/ionic/ionic_lif.c
@@ -46,8 +46,9 @@  static int ionic_start_queues(struct ionic_lif *lif);
 static void ionic_stop_queues(struct ionic_lif *lif);
 static void ionic_lif_queue_identify(struct ionic_lif *lif);
 
-static int ionic_xdp_queues_config(struct ionic_lif *lif);
-static void ionic_xdp_unregister_rxq_info(struct ionic_queue *q);
+static void ionic_xdp_queues_config(struct ionic_lif *lif);
+static int ionic_register_rxq_info(struct ionic_queue *q, unsigned int napi_id);
+static void ionic_unregister_rxq_info(struct ionic_queue *q);
 
 static void ionic_dim_work(struct work_struct *work)
 {
@@ -380,6 +381,7 @@  static void ionic_lif_qcq_deinit(struct ionic_lif *lif, struct ionic_qcq *qcq)
 	if (!(qcq->flags & IONIC_QCQ_F_INITED))
 		return;
 
+	ionic_unregister_rxq_info(&qcq->q);
 	if (qcq->flags & IONIC_QCQ_F_INTR) {
 		ionic_intr_mask(idev->intr_ctrl, qcq->intr.index,
 				IONIC_INTR_MASK_SET);
@@ -437,9 +439,7 @@  static void ionic_qcq_free(struct ionic_lif *lif, struct ionic_qcq *qcq)
 		qcq->sg_base_pa = 0;
 	}
 
-	ionic_xdp_unregister_rxq_info(&qcq->q);
 	ionic_qcq_intr_free(lif, qcq);
-
 	vfree(qcq->q.info);
 	qcq->q.info = NULL;
 }
@@ -925,6 +925,11 @@  static int ionic_lif_rxq_init(struct ionic_lif *lif, struct ionic_qcq *qcq)
 		netif_napi_add(lif->netdev, &qcq->napi, ionic_rx_napi);
 	else
 		netif_napi_add(lif->netdev, &qcq->napi, ionic_txrx_napi);
+	err = ionic_register_rxq_info(q, qcq->napi.napi_id);
+	if (err) {
+		netif_napi_del(&qcq->napi);
+		return err;
+	}
 
 	qcq->flags |= IONIC_QCQ_F_INITED;
 
@@ -2143,9 +2148,7 @@  static int ionic_txrx_enable(struct ionic_lif *lif)
 	int derr = 0;
 	int i, err;
 
-	err = ionic_xdp_queues_config(lif);
-	if (err)
-		return err;
+	ionic_xdp_queues_config(lif);
 
 	for (i = 0; i < lif->nxqs; i++) {
 		if (!(lif->rxqcqs[i] && lif->txqcqs[i])) {
@@ -2192,8 +2195,6 @@  static int ionic_txrx_enable(struct ionic_lif *lif)
 		derr = ionic_qcq_disable(lif, lif->rxqcqs[i], derr);
 	}
 
-	ionic_xdp_queues_config(lif);
-
 	return err;
 }
 
@@ -2651,7 +2652,7 @@  static void ionic_vf_attr_replay(struct ionic_lif *lif)
 	ionic_vf_start(ionic);
 }
 
-static void ionic_xdp_unregister_rxq_info(struct ionic_queue *q)
+static void ionic_unregister_rxq_info(struct ionic_queue *q)
 {
 	struct xdp_rxq_info *xi;
 
@@ -2665,7 +2666,7 @@  static void ionic_xdp_unregister_rxq_info(struct ionic_queue *q)
 	kfree(xi);
 }
 
-static int ionic_xdp_register_rxq_info(struct ionic_queue *q, unsigned int napi_id)
+static int ionic_register_rxq_info(struct ionic_queue *q, unsigned int napi_id)
 {
 	struct xdp_rxq_info *rxq_info;
 	int err;
@@ -2698,45 +2699,27 @@  static int ionic_xdp_register_rxq_info(struct ionic_queue *q, unsigned int napi_
 	return err;
 }
 
-static int ionic_xdp_queues_config(struct ionic_lif *lif)
+static void ionic_xdp_queues_config(struct ionic_lif *lif)
 {
 	struct bpf_prog *xdp_prog;
 	unsigned int i;
-	int err;
 
 	if (!lif->rxqcqs)
-		return 0;
+		return;
 
-	/* There's no need to rework memory if not going to/from NULL program.  */
+	/* Nothing to do if not going to/from NULL program.  */
 	xdp_prog = READ_ONCE(lif->xdp_prog);
 	if (!xdp_prog == !lif->rxqcqs[0]->q.xdp_prog)
-		return 0;
+		return;
 
 	for (i = 0; i < lif->ionic->nrxqs_per_lif && lif->rxqcqs[i]; i++) {
 		struct ionic_queue *q = &lif->rxqcqs[i]->q;
 
-		if (q->xdp_prog) {
-			ionic_xdp_unregister_rxq_info(q);
+		if (q->xdp_prog)
 			q->xdp_prog = NULL;
-			continue;
-		}
-
-		err = ionic_xdp_register_rxq_info(q, lif->rxqcqs[i]->napi.napi_id);
-		if (err) {
-			dev_err(lif->ionic->dev, "failed to register RX queue %d info for XDP, err %d\n",
-				i, err);
-			goto err_out;
-		}
-		q->xdp_prog = xdp_prog;
+		else
+			q->xdp_prog = xdp_prog;
 	}
-
-	return 0;
-
-err_out:
-	for (i = 0; i < lif->ionic->nrxqs_per_lif && lif->rxqcqs[i]; i++)
-		ionic_xdp_unregister_rxq_info(&lif->rxqcqs[i]->q);
-
-	return err;
 }
 
 static int ionic_xdp_config(struct net_device *netdev, struct netdev_bpf *bpf)