]> www.infradead.org Git - users/hch/misc.git/commitdiff
eth: fbnic: move xdp_rxq_info_reg() to resource alloc
authorJakub Kicinski <kuba@kernel.org>
Mon, 1 Sep 2025 21:12:02 +0000 (14:12 -0700)
committerPaolo Abeni <pabeni@redhat.com>
Thu, 4 Sep 2025 08:19:16 +0000 (10:19 +0200)
Move rxq_info and mem model registration from fbnic_alloc_napi_vector()
and fbnic_alloc_nv_resources() to fbnic_alloc_rx_qt_resources().
The rxq_info is now registered later in the process, but that
should not cause any issues.

rxq_info lives in the fbnic_q_triad (qt) struct so qt init is a more
natural place. Encapsulating the logic in the qt functions will also
allow simplifying the cleanup in the NAPI related alloc functions
in the next commit.

Rx does not have a dedicated fbnic_free_rx_qt_resources(),
but we can use xdp_rxq_info_is_reg() to tell whether given
rxq_info was in use (effectively - if it's a qt for an Rx queue).

Having to pass nv into fbnic_alloc_rx_qt_resources() is not
great in terms of layering, but that's temporary, pp will
move soon..

Signed-off-by: Jakub Kicinski <kuba@kernel.org>
Link: https://patch.msgid.link/20250901211214.1027927-3-kuba@kernel.org
Signed-off-by: Paolo Abeni <pabeni@redhat.com>
drivers/net/ethernet/meta/fbnic/fbnic_txrx.c

index 7f8bdb08db9f60e8d3b2826b31816a5d3d5dac2f..29a780f72c14b266e55f87a900c959eb26eacb26 100644 (file)
@@ -1482,7 +1482,6 @@ static void fbnic_free_napi_vector(struct fbnic_net *fbn,
        }
 
        for (j = 0; j < nv->rxt_count; j++, i++) {
-               xdp_rxq_info_unreg(&nv->qt[i].xdp_rxq);
                fbnic_remove_rx_ring(fbn, &nv->qt[i].sub0);
                fbnic_remove_rx_ring(fbn, &nv->qt[i].sub1);
                fbnic_remove_rx_ring(fbn, &nv->qt[i].cmpl);
@@ -1686,11 +1685,6 @@ static int fbnic_alloc_napi_vector(struct fbnic_dev *fbd, struct fbnic_net *fbn,
                if (err)
                        goto free_ring_cur_qt;
 
-               err = xdp_rxq_info_reg(&qt->xdp_rxq, fbn->netdev, rxq_idx,
-                                      nv->napi.napi_id);
-               if (err)
-                       goto free_qt_pp;
-
                /* Update Rx queue index */
                rxt_count--;
                rxq_idx += v_count;
@@ -1704,8 +1698,6 @@ static int fbnic_alloc_napi_vector(struct fbnic_dev *fbd, struct fbnic_net *fbn,
        while (rxt_count < nv->rxt_count) {
                qt--;
 
-               xdp_rxq_info_unreg(&qt->xdp_rxq);
-free_qt_pp:
                fbnic_free_qt_page_pools(qt);
 free_ring_cur_qt:
                fbnic_remove_rx_ring(fbn, &qt->sub0);
@@ -1938,6 +1930,11 @@ static void fbnic_free_qt_resources(struct fbnic_net *fbn,
        fbnic_free_ring_resources(dev, &qt->cmpl);
        fbnic_free_ring_resources(dev, &qt->sub1);
        fbnic_free_ring_resources(dev, &qt->sub0);
+
+       if (xdp_rxq_info_is_reg(&qt->xdp_rxq)) {
+               xdp_rxq_info_unreg_mem_model(&qt->xdp_rxq);
+               xdp_rxq_info_unreg(&qt->xdp_rxq);
+       }
 }
 
 static int fbnic_alloc_tx_qt_resources(struct fbnic_net *fbn,
@@ -1968,15 +1965,27 @@ free_sub0:
 }
 
 static int fbnic_alloc_rx_qt_resources(struct fbnic_net *fbn,
+                                      struct fbnic_napi_vector *nv,
                                       struct fbnic_q_triad *qt)
 {
        struct device *dev = fbn->netdev->dev.parent;
        int err;
 
-       err = fbnic_alloc_rx_ring_resources(fbn, &qt->sub0);
+       err = xdp_rxq_info_reg(&qt->xdp_rxq, fbn->netdev, qt->sub0.q_idx,
+                              nv->napi.napi_id);
        if (err)
                return err;
 
+       /* Register XDP memory model for completion queue */
+       err = xdp_rxq_info_reg_mem_model(&qt->xdp_rxq, MEM_TYPE_PAGE_POOL,
+                                        qt->sub0.page_pool);
+       if (err)
+               goto unreg_rxq;
+
+       err = fbnic_alloc_rx_ring_resources(fbn, &qt->sub0);
+       if (err)
+               goto unreg_mm;
+
        err = fbnic_alloc_rx_ring_resources(fbn, &qt->sub1);
        if (err)
                goto free_sub0;
@@ -1991,22 +2000,20 @@ free_sub1:
        fbnic_free_ring_resources(dev, &qt->sub1);
 free_sub0:
        fbnic_free_ring_resources(dev, &qt->sub0);
+unreg_mm:
+       xdp_rxq_info_unreg_mem_model(&qt->xdp_rxq);
+unreg_rxq:
+       xdp_rxq_info_unreg(&qt->xdp_rxq);
        return err;
 }
 
 static void fbnic_free_nv_resources(struct fbnic_net *fbn,
                                    struct fbnic_napi_vector *nv)
 {
-       int i, j;
-
-       /* Free Tx Resources  */
-       for (i = 0; i < nv->txt_count; i++)
-               fbnic_free_qt_resources(fbn, &nv->qt[i]);
+       int i;
 
-       for (j = 0; j < nv->rxt_count; j++, i++) {
+       for (i = 0; i < nv->txt_count + nv->rxt_count; i++)
                fbnic_free_qt_resources(fbn, &nv->qt[i]);
-               xdp_rxq_info_unreg_mem_model(&nv->qt[i].xdp_rxq);
-       }
 }
 
 static int fbnic_alloc_nv_resources(struct fbnic_net *fbn,
@@ -2023,26 +2030,13 @@ static int fbnic_alloc_nv_resources(struct fbnic_net *fbn,
 
        /* Allocate Rx Resources */
        for (j = 0; j < nv->rxt_count; j++, i++) {
-               /* Register XDP memory model for completion queue */
-               err = xdp_reg_mem_model(&nv->qt[i].xdp_rxq.mem,
-                                       MEM_TYPE_PAGE_POOL,
-                                       nv->qt[i].sub0.page_pool);
-               if (err)
-                       goto xdp_unreg_mem_model;
-
-               err = fbnic_alloc_rx_qt_resources(fbn, &nv->qt[i]);
+               err = fbnic_alloc_rx_qt_resources(fbn, nv, &nv->qt[i]);
                if (err)
-                       goto xdp_unreg_cur_model;
+                       goto free_qt_resources;
        }
 
        return 0;
 
-xdp_unreg_mem_model:
-       while (j-- && i--) {
-               fbnic_free_qt_resources(fbn, &nv->qt[i]);
-xdp_unreg_cur_model:
-               xdp_rxq_info_unreg_mem_model(&nv->qt[i].xdp_rxq);
-       }
 free_qt_resources:
        while (i--)
                fbnic_free_qt_resources(fbn, &nv->qt[i]);