eth: fbnic: support queue API and zero-copy Rx
Subsystems (6)
Jakub Kicinski
maintainerv3 cover eth: fbnic: support queue API and zero-copy Rx
Add support for queue API to fbnic, enable zero-copy Rx.
Patch 10 is likely of most interest as it adds a new core helper (and touches mlx5). The rest of the patches are fbnic-specific (and relatively boring).
Patches 1-3 reshuffle the Rx init/allocation path to better align structures and functions which operate on them. Notably patch 1 moves the page pool pointer to the queue struct (from NAPI).
Patch 4 converts the driver to use netmem_ref. The driver has separate and explicit buffer queue for scatter / payloads, so only references to those are converted.
Next 5 patches are more boring code shifts.
Patch 11 adds unreadable memory support to page pool allocation.
Patch 14 finally adds the support for queue API.
v3:
- rebase (fix from net added something to the context)
v2: https://lore.kernel.org/[email protected]
- rework patch 10
- update commit message in patch 11
v1: https://lore.kernel.org/[email protected]
Jakub Kicinski (14):
eth: fbnic: move page pool pointer from NAPI to the ring struct
eth: fbnic: move xdp_rxq_info_reg() to resource alloc
eth: fbnic: move page pool alloc to fbnic_alloc_rx_qt_resources()
eth: fbnic: use netmem_ref where applicable
eth: fbnic: request ops lock
eth: fbnic: split fbnic_disable()
eth: fbnic: split fbnic_flush()
eth: fbnic: split fbnic_enable()
eth: fbnic: split fbnic_fill()
net: add helper to pre-check if PP for an Rx queue will be unreadable
eth: fbnic: allocate unreadable page pool for the payloads
eth: fbnic: defer page pool recycling activation to queue start
eth: fbnic: don't pass NAPI into pp alloc
eth: fbnic: support queue ops / zero-copy Rx
drivers/net/ethernet/meta/fbnic/fbnic_txrx.h | 20 +- include/net/netdev_queues.h | 2 + include/net/page_pool/helpers.h | 12 + .../net/ethernet/mellanox/mlx5/core/en_main.c | 9 +- .../net/ethernet/meta/fbnic/fbnic_netdev.c | 1 + drivers/net/ethernet/meta/fbnic/fbnic_pci.c | 9 +- drivers/net/ethernet/meta/fbnic/fbnic_txrx.c | 621 ++++++++++++------ net/core/netdev_rx_queue.c | 9 + 8 files changed, 454 insertions(+), 229 deletions(-)
Signature · 1 line
2.51.0
Jakub Kicinski
maintainerPATCH v3 1/14 eth: fbnic: move page pool pointer from NAPI to the ring struct
In preparation for memory providers we need a closer association between queues and page pools. We used to have a page pool at the NAPI level to serve all associated queues but with MP the queues under a NAPI may no longer be created equal.
The "ring" structure in fbnic is a descriptor ring. We have separate "rings" for payload and header pages ("to device"), as well as a ring for completions ("from device"). Technically we only need the page pool pointers in the "to device" rings, so adding the pointer to the ring struct is a bit wasteful. But it makes passing the structures around much easier.
For now both "to device" rings store a pointer to the same page pool. Using more than one queue per NAPI is extremely rare so don't bother trying to share a single page pool between queues.
--- drivers/net/ethernet/meta/fbnic/fbnic_txrx.h | 16 ++-- drivers/net/ethernet/meta/fbnic/fbnic_txrx.c | 83 +++++++++++--------- 2 files changed, 55 insertions(+), 44 deletions(-)
drivers/net/ethernet/meta/fbnic/fbnic_txrx.h +10 -6
@@ -121,11 +121,16 @@ struct fbnic_ring {u32 head, tail;/* Head/Tail of ring */ -/* Deferred_head is used to cache the head for TWQ1 if an attempt -* is made to clean TWQ1 with zero napi_budget. We do not use it for -* any other ring. -*/ -s32 deferred_head; +union { +/* Rx BDQs only */ +struct page_pool *page_pool; + +/* Deferred_head is used to cache the head for TWQ1 if +* an attempt is made to clean TWQ1 with zero napi_budget. +* We do not use it for any other ring. +*/ +s32 deferred_head; + };struct fbnic_queue_stats stats;
@@ -142,7 +147,6 @@ struct fbnic_q_triad {struct fbnic_napi_vector {struct napi_struct napi;struct device *dev;/* Device for DMA unmapping */ -struct page_pool *page_pool;struct fbnic_dev *fbd;u16 v_idx;
drivers/net/ethernet/meta/fbnic/fbnic_txrx.c +45 -38
237 lines not on this page · raw message
Signature · 1 line
2.51.0
Jakub Kicinski
maintainerPATCH v3 2/14 eth: fbnic: move xdp_rxq_info_reg() to resource alloc
In reply to Jakub KicinskiMove 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..
--- drivers/net/ethernet/meta/fbnic/fbnic_txrx.c | 58 +++++++++----------- 1 file changed, 26 insertions(+), 32 deletions(-)
drivers/net/ethernet/meta/fbnic/fbnic_txrx.c +26 -32
@@ -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 @@ static int fbnic_alloc_tx_qt_resources(struct fbnic_net *fbn, }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 @@ static int fbnic_alloc_rx_qt_resources(struct fbnic_net *fbn,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; +int i; -/* Free Tx Resources */ -for (i =0 ; i < nv->txt_count; i++) +for (i =0 ; i < nv->txt_count + nv->rxt_count; i++)fbnic_free_qt_resources (fbn, &nv->qt[i]); - -for (j =0 ; j < nv->rxt_count; j++, 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); + err =fbnic_alloc_rx_qt_resources (fbn, nv, &nv->qt[i]);if (err) - goto xdp_unreg_mem_model; - - err =fbnic_alloc_rx_qt_resources (fbn, &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]);
Signature · 1 line
2.51.0
Jakub Kicinski
maintainerPATCH v3 3/14 eth: fbnic: move page pool alloc to fbnic_alloc_rx_qt_resources()
In reply to Jakub Kicinskipage pools are now at the ring level, move page pool alloc to fbnic_alloc_rx_qt_resources(), and freeing to fbnic_free_qt_resources().
This significantly simplifies fbnic_alloc_napi_vector() error handling, by removing a late failure point.
--- drivers/net/ethernet/meta/fbnic/fbnic_txrx.c | 37 +++++--------------- 1 file changed, 9 insertions(+), 28 deletions(-)
drivers/net/ethernet/meta/fbnic/fbnic_txrx.c +9 -28
@@ -1485,7 +1485,6 @@ static void fbnic_free_napi_vector(struct fbnic_net *fbn,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); -fbnic_free_qt_page_pools (&nv->qt[i]); }fbnic_napi_free_irq (fbd, nv);
@@ -1681,10 +1680,6 @@ static int fbnic_alloc_napi_vector(struct fbnic_dev *fbd, struct fbnic_net *fbn,fbnic_ring_init (&qt->cmpl, db, rxq_idx,FBNIC_RING_F_STATS ); fbn->rx[rxq_idx] = &qt->cmpl; - err =fbnic_alloc_qt_page_pools (fbn, nv, qt); -if (err) - goto free_ring_cur_qt; -/* Update Rx queue index */ rxt_count--; rxq_idx += v_count;
@@ -1695,26 +1690,6 @@ static int fbnic_alloc_napi_vector(struct fbnic_dev *fbd, struct fbnic_net *fbn,return 0 ; -while (rxt_count < nv->rxt_count) { - qt--; - -fbnic_free_qt_page_pools (qt); -free_ring_cur_qt: -fbnic_remove_rx_ring (fbn, &qt->sub0); -fbnic_remove_rx_ring (fbn, &qt->sub1); -fbnic_remove_rx_ring (fbn, &qt->cmpl); - rxt_count++; - } -while (txt_count < nv->txt_count) { - qt--; - -fbnic_remove_tx_ring (fbn, &qt->sub0); -fbnic_remove_xdp_ring (fbn, &qt->sub1); -fbnic_remove_tx_ring (fbn, &qt->cmpl); - - txt_count++; - } -fbnic_napi_free_irq (fbd, nv); napi_del:netif_napi_del (&nv->napi); fbn->napi[fbnic_napi_idx (nv)] =NULL ;
@@ -1934,6 +1909,7 @@ static void fbnic_free_qt_resources(struct fbnic_net *fbn,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); +fbnic_free_qt_page_pools (qt); } }
@@ -1971,12 +1947,15 @@ static int fbnic_alloc_rx_qt_resources(struct fbnic_net *fbn,struct device *dev = fbn->netdev->dev.parent;int err; - err =xdp_rxq_info_reg (&qt->xdp_rxq, fbn->netdev, qt->sub0.q_idx, - nv->napi.napi_id); + err =fbnic_alloc_qt_page_pools (fbn, nv, qt);if (err)return err; -/* Register XDP memory model for completion queue */ + err =xdp_rxq_info_reg (&qt->xdp_rxq, fbn->netdev, qt->sub0.q_idx, + nv->napi.napi_id); +if (err) + goto free_page_pools; + err =xdp_rxq_info_reg_mem_model (&qt->xdp_rxq,MEM_TYPE_PAGE_POOL , qt->sub0.page_pool);if (err)
@@ -2004,6 +1983,8 @@ static int fbnic_alloc_rx_qt_resources(struct fbnic_net *fbn,xdp_rxq_info_unreg_mem_model (&qt->xdp_rxq); unreg_rxq:xdp_rxq_info_unreg (&qt->xdp_rxq); +free_page_pools: +fbnic_free_qt_page_pools (qt);return err; }
Signature · 1 line
2.51.0
Jakub Kicinski
maintainerPATCH v3 4/14 eth: fbnic: use netmem_ref where applicable
In reply to Jakub KicinskiUse netmem_ref instead of struct page pointer in prep for unreadable memory. fbnic has separate free buffer submission queues for headers and for data. Refactor the helper which returns page pointer for a submission buffer to take the high level queue container, create a separate handler for header and payload rings. This ties the "upcast" from netmem to system page to use of sub0 which we know has system pages.
--- drivers/net/ethernet/meta/fbnic/fbnic_txrx.h | 2 +- drivers/net/ethernet/meta/fbnic/fbnic_txrx.c | 65 ++++++++++++-------- 2 files changed, 40 insertions(+), 27 deletions(-)
drivers/net/ethernet/meta/fbnic/fbnic_txrx.h +1 -1
@@ -100,7 +100,7 @@ struct fbnic_queue_stats {#define FBNIC_PAGECNT_BIAS_MAX PAGE_SIZEstruct fbnic_rx_buf { -struct page *page; +netmem_ref netmem;long pagecnt_bias; };
drivers/net/ethernet/meta/fbnic/fbnic_txrx.c +39 -26
142 lines not on this page · raw message
Signature · 1 line
2.51.0
Jakub Kicinski
maintainerPATCH v3 5/14 eth: fbnic: request ops lock
In reply to Jakub KicinskiWe'll add queue ops soon so. queue ops will opt the driver into extra locking. Request this locking explicitly already to make future patches smaller and easier to review.
--- drivers/net/ethernet/meta/fbnic/fbnic_netdev.c | 2 ++ drivers/net/ethernet/meta/fbnic/fbnic_pci.c | 9 ++++++++- drivers/net/ethernet/meta/fbnic/fbnic_txrx.c | 15 ++++++++------- 3 files changed, 18 insertions(+), 8 deletions(-)
drivers/net/ethernet/meta/fbnic/fbnic_netdev.c +2 -0
@@ -714,6 +714,8 @@ struct net_device *fbnic_netdev_alloc(struct fbnic_dev *fbd)fbnic_set_ethtool_ops (netdev); + netdev->request_ops_lock = true; + fbn =netdev_priv (netdev); fbn->netdev = netdev;
drivers/net/ethernet/meta/fbnic/fbnic_pci.c +8 -1
@@ -206,8 +206,11 @@ static void fbnic_service_task(struct work_struct *work)fbnic_bmc_rpc_check (fbd); -if (netif_carrier_ok (fbd->netdev)) +if (netif_carrier_ok (fbd->netdev)) { +netdev_lock (fbd->netdev);fbnic_napi_depletion_check (fbd->netdev); +netdev_unlock (fbd->netdev); + }if (netif_running (fbd->netdev))schedule_delayed_work (&fbd->service_task,HZ );
@@ -391,12 +394,14 @@ static int fbnic_pm_suspend(struct device *dev) goto null_uc_addr;rtnl_lock (); +netdev_lock (netdev);netif_device_detach (netdev);if (netif_running (netdev)) netdev->netdev_ops->ndo_stop (netdev); +netdev_unlock (netdev);rtnl_unlock (); null_uc_addr:
@@ -461,10 +466,12 @@ static int __fbnic_pm_resume(struct device *dev)fbnic_reset_queues (fbn, fbn->num_tx_queues, fbn->num_rx_queues);rtnl_lock (); +netdev_lock (netdev);if (netif_running (netdev)) err =__fbnic_open (fbn); +netdev_unlock (netdev);rtnl_unlock ();if (err) goto err_free_mbx;
drivers/net/ethernet/meta/fbnic/fbnic_txrx.c +8 -7
@@ -1501,7 +1501,7 @@ static void fbnic_free_napi_vector(struct fbnic_net *fbn, }fbnic_napi_free_irq (fbd, nv); -netif_napi_del (&nv->napi); +netif_napi_del_locked (&nv->napi); fbn->napi[fbnic_napi_idx (nv)] =NULL ;kfree (nv); }
@@ -1611,11 +1611,12 @@ static int fbnic_alloc_napi_vector(struct fbnic_dev *fbd, struct fbnic_net *fbn,/* Tie napi to netdev */ fbn->napi[fbnic_napi_idx (nv)] = nv; -netif_napi_add (fbn->netdev, &nv->napi, fbnic_poll); +netif_napi_add_locked (fbn->netdev, &nv->napi, fbnic_poll);/* Record IRQ to NAPI struct */ -netif_napi_set_irq (&nv->napi, -pci_irq_vector (to_pci_dev (fbd->dev), nv->v_idx)); +netif_napi_set_irq_locked (&nv->napi, +pci_irq_vector (to_pci_dev (fbd->dev), + nv->v_idx));/* Tie nv back to PCIe dev */ nv->dev = fbd->dev;
@@ -1704,7 +1705,7 @@ static int fbnic_alloc_napi_vector(struct fbnic_dev *fbd, struct fbnic_net *fbn,return 0 ; napi_del: -netif_napi_del (&nv->napi); +netif_napi_del_locked (&nv->napi); fbn->napi[fbnic_napi_idx (nv)] =NULL ;kfree (nv);return err;
@@ -2173,7 +2174,7 @@ void fbnic_napi_disable(struct fbnic_net *fbn)int i;for (i =0 ; i < fbn->num_napi; i++) { -napi_disable (&fbn->napi[i]->napi); +napi_disable_locked (&fbn->napi[i]->napi);fbnic_nv_irq_disable (fbn->napi[i]); }
@@ -2621,7 +2622,7 @@ void fbnic_napi_enable(struct fbnic_net *fbn)for (i =0 ; i < fbn->num_napi; i++) {struct fbnic_napi_vector *nv = fbn->napi[i]; -napi_enable (&nv->napi); +napi_enable_locked (&nv->napi);fbnic_nv_irq_enable (nv);
Signature · 1 line
2.51.0
Jakub Kicinski
maintainerPATCH v3 6/14 eth: fbnic: split fbnic_disable()
In reply to Jakub KicinskiFactor out handling a single nv from fbnic_disable() to make it reusable for queue ops. Use a __ prefix for the factored out code. The real fbnic_nv_disable() which will include fbnic_wrfl() will be added with the qops, to avoid unused function warnings.
--- drivers/net/ethernet/meta/fbnic/fbnic_txrx.c | 46 +++++++++++--------- 1 file changed, 25 insertions(+), 21 deletions(-)
drivers/net/ethernet/meta/fbnic/fbnic_txrx.c +25 -21
@@ -2180,31 +2180,35 @@ void fbnic_napi_disable(struct fbnic_net *fbn) } } +static void __fbnic_nv_disable (struct fbnic_napi_vector *nv) +{ +int i, t; + +/* Disable Tx queue triads */ +for (t =0 ; t < nv->txt_count; t++) { +struct fbnic_q_triad *qt = &nv->qt[t]; + +fbnic_disable_twq0 (&qt->sub0); +fbnic_disable_twq1 (&qt->sub1); +fbnic_disable_tcq (&qt->cmpl); + } + +/* Disable Rx queue triads */ +for (i =0 ; i < nv->rxt_count; i++, t++) { +struct fbnic_q_triad *qt = &nv->qt[t]; + +fbnic_disable_bdq (&qt->sub0, &qt->sub1); +fbnic_disable_rcq (&qt->cmpl); + } +} +void fbnic_disable (struct fbnic_net *fbn) {struct fbnic_dev *fbd = fbn->fbd; -int i, j, t; +int i; -for (i =0 ; i < fbn->num_napi; i++) { -struct fbnic_napi_vector *nv = fbn->napi[i]; - -/* Disable Tx queue triads */ -for (t =0 ; t < nv->txt_count; t++) { -struct fbnic_q_triad *qt = &nv->qt[t]; - -fbnic_disable_twq0 (&qt->sub0); -fbnic_disable_twq1 (&qt->sub1); -fbnic_disable_tcq (&qt->cmpl); - } - -/* Disable Rx queue triads */ -for (j =0 ; j < nv->rxt_count; j++, t++) { -struct fbnic_q_triad *qt = &nv->qt[t]; - -fbnic_disable_bdq (&qt->sub0, &qt->sub1); -fbnic_disable_rcq (&qt->cmpl); - } - } +for (i =0 ; i < fbn->num_napi; i++) +__fbnic_nv_disable (fbn->napi[i]);fbnic_wrfl (fbd); }
Signature · 1 line
2.51.0
Jakub Kicinski
maintainerPATCH v3 7/14 eth: fbnic: split fbnic_flush()
In reply to Jakub KicinskiFactor out handling a single nv from fbnic_flush() to make it reusable for queue ops.
--- drivers/net/ethernet/meta/fbnic/fbnic_txrx.c | 87 ++++++++++---------- 1 file changed, 45 insertions(+), 42 deletions(-)
drivers/net/ethernet/meta/fbnic/fbnic_txrx.c +45 -42
@@ -2297,52 +2297,55 @@ int fbnic_wait_all_queues_idle(struct fbnic_dev *fbd, bool may_fail)return err; } +static void fbnic_nv_flush (struct fbnic_napi_vector *nv) +{ +int j, t; + +/* Flush any processed Tx Queue Triads and drop the rest */ +for (t =0 ; t < nv->txt_count; t++) { +struct fbnic_q_triad *qt = &nv->qt[t]; +struct netdev_queue *tx_queue; + +/* Clean the work queues of unprocessed work */ +fbnic_clean_twq0 (nv,0 , &qt->sub0, true, qt->sub0.tail); +fbnic_clean_twq1 (nv, false, &qt->sub1, true, + qt->sub1.tail); + +/* Reset completion queue descriptor ring */ +memset (qt->cmpl.desc,0 , qt->cmpl.size); + +/* Nothing else to do if Tx queue is disabled */ +if (qt->sub0.flags &FBNIC_RING_F_DISABLED ) +continue ; + +/* Reset BQL associated with Tx queue */ + tx_queue =netdev_get_tx_queue (nv->napi.dev, + qt->sub0.q_idx); +netdev_tx_reset_queue (tx_queue); + } + +/* Flush any processed Rx Queue Triads and drop the rest */ +for (j =0 ; j < nv->rxt_count; j++, t++) { +struct fbnic_q_triad *qt = &nv->qt[t]; + +/* Clean the work queues of unprocessed work */ +fbnic_clean_bdq (&qt->sub0, qt->sub0.tail,0 ); +fbnic_clean_bdq (&qt->sub1, qt->sub1.tail,0 ); + +/* Reset completion queue descriptor ring */ +memset (qt->cmpl.desc,0 , qt->cmpl.size); + +fbnic_put_pkt_buff (qt, qt->cmpl.pkt,0 ); +memset (qt->cmpl.pkt,0 ,sizeof (struct fbnic_pkt_buff )); + } +} +void fbnic_flush (struct fbnic_net *fbn) {int i; -for (i =0 ; i < fbn->num_napi; i++) { -struct fbnic_napi_vector *nv = fbn->napi[i]; -int j, t; - -/* Flush any processed Tx Queue Triads and drop the rest */ -for (t =0 ; t < nv->txt_count; t++) { -struct fbnic_q_triad *qt = &nv->qt[t]; -struct netdev_queue *tx_queue; - -/* Clean the work queues of unprocessed work */ -fbnic_clean_twq0 (nv,0 , &qt->sub0, true, qt->sub0.tail); -fbnic_clean_twq1 (nv, false, &qt->sub1, true, - qt->sub1.tail); - -/* Reset completion queue descriptor ring */ -memset (qt->cmpl.desc,0 , qt->cmpl.size); - -/* Nothing else to do if Tx queue is disabled */ -if (qt->sub0.flags &FBNIC_RING_F_DISABLED ) -continue ; - -/* Reset BQL associated with Tx queue */ - tx_queue =netdev_get_tx_queue (nv->napi.dev, - qt->sub0.q_idx); -netdev_tx_reset_queue (tx_queue); - } - -/* Flush any processed Rx Queue Triads and drop the rest */ -for (j =0 ; j < nv->rxt_count; j++, t++) { -struct fbnic_q_triad *qt = &nv->qt[t]; - -/* Clean the work queues of unprocessed work */ -fbnic_clean_bdq (&qt->sub0, qt->sub0.tail,0 ); -fbnic_clean_bdq (&qt->sub1, qt->sub1.tail,0 ); - -/* Reset completion queue descriptor ring */ -memset (qt->cmpl.desc,0 , qt->cmpl.size); - -fbnic_put_pkt_buff (qt, qt->cmpl.pkt,0 ); -memset (qt->cmpl.pkt,0 ,sizeof (struct fbnic_pkt_buff )); - } - } +for (i =0 ; i < fbn->num_napi; i++) +fbnic_nv_flush (fbn->napi[i]); }void fbnic_fill (struct fbnic_net *fbn)
Signature · 1 line
2.51.0
Jakub Kicinski
maintainerPATCH v3 8/14 eth: fbnic: split fbnic_enable()
In reply to Jakub KicinskiFactor out handling a single nv from fbnic_enable() to make it reusable for queue ops. Use a __ prefix for the factored out code. The real fbnic_nv_enable() which will include fbnic_wrfl() will be added with the qops, to avoid unused function warnings.
--- drivers/net/ethernet/meta/fbnic/fbnic_txrx.c | 47 +++++++++++--------- 1 file changed, 25 insertions(+), 22 deletions(-)
drivers/net/ethernet/meta/fbnic/fbnic_txrx.c +25 -22
@@ -2584,33 +2584,36 @@ static void fbnic_enable_rcq(struct fbnic_napi_vector *nv,fbnic_ring_wr32 (rcq,FBNIC_QUEUE_RCQ_CTL ,FBNIC_QUEUE_RCQ_CTL_ENABLE ); } +static void __fbnic_nv_enable (struct fbnic_napi_vector *nv) +{ +int j, t; + +/* Setup Tx Queue Triads */ +for (t =0 ; t < nv->txt_count; t++) { +struct fbnic_q_triad *qt = &nv->qt[t]; + +fbnic_enable_twq0 (&qt->sub0); +fbnic_enable_twq1 (&qt->sub1); +fbnic_enable_tcq (nv, &qt->cmpl); + } + +/* Setup Rx Queue Triads */ +for (j =0 ; j < nv->rxt_count; j++, t++) { +struct fbnic_q_triad *qt = &nv->qt[t]; + +fbnic_enable_bdq (&qt->sub0, &qt->sub1); +fbnic_config_drop_mode_rcq (nv, &qt->cmpl); +fbnic_enable_rcq (nv, &qt->cmpl); + } +} +void fbnic_enable (struct fbnic_net *fbn) {struct fbnic_dev *fbd = fbn->fbd;int i; -for (i =0 ; i < fbn->num_napi; i++) { -struct fbnic_napi_vector *nv = fbn->napi[i]; -int j, t; - -/* Setup Tx Queue Triads */ -for (t =0 ; t < nv->txt_count; t++) { -struct fbnic_q_triad *qt = &nv->qt[t]; - -fbnic_enable_twq0 (&qt->sub0); -fbnic_enable_twq1 (&qt->sub1); -fbnic_enable_tcq (nv, &qt->cmpl); - } - -/* Setup Rx Queue Triads */ -for (j =0 ; j < nv->rxt_count; j++, t++) { -struct fbnic_q_triad *qt = &nv->qt[t]; - -fbnic_enable_bdq (&qt->sub0, &qt->sub1); -fbnic_config_drop_mode_rcq (nv, &qt->cmpl); -fbnic_enable_rcq (nv, &qt->cmpl); - } - } +for (i =0 ; i < fbn->num_napi; i++) +__fbnic_nv_enable (fbn->napi[i]);fbnic_wrfl (fbd); }
Signature · 1 line
2.51.0
Jakub Kicinski
maintainerPATCH v3 9/14 eth: fbnic: split fbnic_fill()
In reply to Jakub KicinskiFactor out handling a single nv from fbnic_fill() to make it reusable for queue ops.
--- drivers/net/ethernet/meta/fbnic/fbnic_txrx.c | 33 +++++++++++--------- 1 file changed, 18 insertions(+), 15 deletions(-)
drivers/net/ethernet/meta/fbnic/fbnic_txrx.c +18 -15
@@ -2348,25 +2348,28 @@ void fbnic_flush(struct fbnic_net *fbn)fbnic_nv_flush (fbn->napi[i]); } +static void fbnic_nv_fill (struct fbnic_napi_vector *nv) +{ +int j, t; + +/* Configure NAPI mapping and populate pages +* in the BDQ rings to use for Rx +*/ +for (j =0 , t = nv->txt_count; j < nv->rxt_count; j++, t++) { +struct fbnic_q_triad *qt = &nv->qt[t]; + +/* Populate the header and payload BDQs */ +fbnic_fill_bdq (&qt->sub0); +fbnic_fill_bdq (&qt->sub1); + } +} +void fbnic_fill (struct fbnic_net *fbn) {int i; -for (i =0 ; i < fbn->num_napi; i++) { -struct fbnic_napi_vector *nv = fbn->napi[i]; -int j, t; - -/* Configure NAPI mapping and populate pages -* in the BDQ rings to use for Rx -*/ -for (j =0 , t = nv->txt_count; j < nv->rxt_count; j++, t++) { -struct fbnic_q_triad *qt = &nv->qt[t]; - -/* Populate the header and payload BDQs */ -fbnic_fill_bdq (&qt->sub0); -fbnic_fill_bdq (&qt->sub1); - } - } +for (i =0 ; i < fbn->num_napi; i++) +fbnic_nv_fill (fbn->napi[i]); }static void fbnic_enable_twq0 (struct fbnic_ring *twq)
Signature · 1 line
2.51.0
Jakub Kicinski
maintainerPATCH v3 10/14 net: add helper to pre-check if PP for an Rx queue will be unreadable
In reply to Jakub Kicinskimlx5 pokes into the rxq state to check if the queue has a memory provider, and therefore whether it may produce unreadable mem. Add a helper for doing this in the page pool API. fbnic will want a similar thing (tho, for a slightly different reason).
---
v2:
- make the helper an rxq helper rather than PP helper
v1: https://lore.kernel.org/[email protected]
--- include/net/netdev_queues.h | 2 ++ include/net/page_pool/helpers.h | 12 ++++++++++++ drivers/net/ethernet/mellanox/mlx5/core/en_main.c | 9 +-------- net/core/netdev_rx_queue.c | 9 +++++++++ 4 files changed, 24 insertions(+), 8 deletions(-)
include/net/netdev_queues.h +2 -0
@@ -151,6 +151,8 @@ struct netdev_queue_mgmt_ops { int idx); }; +bool netif_rxq_has_unreadable_mp (struct net_device *dev,int idx); +/** * DOC: Lockless queue stopping / waking helpers. *
include/net/page_pool/helpers.h +12 -0
@@ -505,6 +505,18 @@ static inline void page_pool_nid_changed(struct page_pool *pool, int new_nid)page_pool_update_nid (pool, new_nid); } +/** +* page_pool_is_unreadable() - will allocated buffers be unreadable for the CPU +* @pool: queried page pool +* +* Check if page pool will return buffers which are unreadable to the CPU / +* kernel. This will only be the case if user space bound a memory provider (mp) +* which returns unreadable memory to the queue served by the page pool. +* If %PP_FLAG_ALLOW_UNREADABLE_NETMEM was set but there is no mp bound +* this helper will return false. See also netif_rxq_has_unreadable_mp(). +* +* Return: true if memory allocated by the page pool may be unreadable +*/ static inline bool page_pool_is_unreadable (struct page_pool *pool) {return !!pool->mp_ops;
drivers/net/ethernet/mellanox/mlx5/core/en_main.c +1 -8
@@ -780,13 +780,6 @@ static void mlx5e_rq_shampo_hd_info_free(struct mlx5e_rq *rq)bitmap_free (rq->mpwqe.shampo->bitmap); } -static bool mlx5_rq_needs_separate_hd_pool (struct mlx5e_rq *rq) -{ -struct netdev_rx_queue *rxq =__netif_get_rx_queue (rq->netdev, rq->ix); - -return !!rxq->mp_params.mp_ops; -} - static int mlx5_rq_shampo_alloc(struct mlx5_core_dev *mdev, struct mlx5e_params *params, struct mlx5e_rq_param *rqp,
@@ -825,7 +818,7 @@ static int mlx5_rq_shampo_alloc(struct mlx5_core_dev *mdev, hd_pool_size = (rq->mpwqe.shampo->hd_per_wqe * wq_size) /MLX5E_SHAMPO_WQ_HEADER_PER_PAGE ; -if (mlx5_rq_needs_separate_hd_pool (rq)) { +if (netif_rxq_has_unreadable_mp (rq->netdev, rq->ix)) {/* Separate page pool for shampo headers */ struct page_pool_params pp_params = { };
net/core/netdev_rx_queue.c +9 -0
@@ -9,6 +9,15 @@#include "page_pool_priv.h" +/* See also page_pool_is_unreadable() */ +bool netif_rxq_has_unreadable_mp (struct net_device *dev,int idx) +{ +struct netdev_rx_queue *rxq =__netif_get_rx_queue (dev, idx); + +return !!rxq->mp_params.mp_ops; +} +EXPORT_SYMBOL (netif_rxq_has_unreadable_mp); +int netdev_rx_queue_restart (struct net_device *dev,unsigned int rxq_idx) {struct netdev_rx_queue *rxq =__netif_get_rx_queue (dev, rxq_idx);
Signature · 1 line
2.51.0
Jakub Kicinski
maintainerPATCH v3 11/14 eth: fbnic: allocate unreadable page pool for the payloads
In reply to Jakub KicinskiAllow allocating a page pool with unreadable memory for the payload ring (sub1). We need to provide the queue ID so that the memory provider can match the PP. Use the appropriate page pool DMA sync helper. For unreadable mem the direction has to be FROM_DEVICE. The default is BIDIR for XDP, but obviously unreadable mem is not compatible with XDP in the first place, so that's fine. While at it remove the define for page pool flags.
The rxq_idx is passed to fbnic_alloc_rx_qt_resources() explicitly to make it easy to allocate page pools without NAPI (see the patch after the next).
---
v2:
- update commit msg
v1: https://lore.kernel.org/[email protected]
--- drivers/net/ethernet/meta/fbnic/fbnic_txrx.c | 31 +++++++++++++------- 1 file changed, 21 insertions(+), 10 deletions(-)
drivers/net/ethernet/meta/fbnic/fbnic_txrx.c +21 -10
@@ -997,9 +997,8 @@ static void fbnic_add_rx_frag(struct fbnic_napi_vector *nv, u64 rcd,FBNIC_BD_FRAG_SIZE ;/* Sync DMA buffer */ -dma_sync_single_range_for_cpu (nv->dev, -page_pool_get_dma_addr_netmem (netmem), - pg_off, truesize,DMA_BIDIRECTIONAL ); +page_pool_dma_sync_netmem_for_cpu (qt->sub1.page_pool, netmem, + pg_off, truesize); added =xdp_buff_add_frag (&pkt->buff, netmem, pg_off, len, truesize);if (unlikely (!added)) {
@@ -1515,16 +1514,14 @@ void fbnic_free_napi_vectors(struct fbnic_net *fbn)fbnic_free_napi_vector (fbn, fbn->napi[i]); } -#define FBNIC_PAGE_POOL_FLAGS \ - (PP_FLAG_DMA_MAP | PP_FLAG_DMA_SYNC_DEV) -static int fbnic_alloc_qt_page_pools (struct fbnic_net *fbn,struct fbnic_napi_vector *nv, -struct fbnic_q_triad *qt) +struct fbnic_q_triad *qt,unsigned int rxq_idx) {struct page_pool_params pp_params = { .order =0 , - .flags =FBNIC_PAGE_POOL_FLAGS , + .flags =PP_FLAG_DMA_MAP | +PP_FLAG_DMA_SYNC_DEV , .pool_size = fbn->hpq_size + fbn->ppq_size, .nid =NUMA_NO_NODE , .dev = nv->dev,
@@ -1533,6 +1530,7 @@ fbnic_alloc_qt_page_pools(struct fbnic_net *fbn, struct fbnic_napi_vector *nv, .max_len = PAGE_SIZE, .napi = &nv->napi, .netdev = fbn->netdev, + .queue_idx = rxq_idx, };struct page_pool *pp;
@@ -1553,10 +1551,23 @@ fbnic_alloc_qt_page_pools(struct fbnic_net *fbn, struct fbnic_napi_vector *nv,return PTR_ERR (pp); qt->sub0.page_pool = pp; -page_pool_get (pp); +if (netif_rxq_has_unreadable_mp (fbn->netdev, rxq_idx)) { + pp_params.flags |=PP_FLAG_ALLOW_UNREADABLE_NETMEM ; + pp_params.dma_dir =DMA_FROM_DEVICE ; + + pp =page_pool_create (&pp_params); +if (IS_ERR (pp)) + goto err_destroy_sub0; + }else { +page_pool_get (pp); + } qt->sub1.page_pool = pp;return 0 ; + +err_destroy_sub0: +page_pool_destroy (pp); +return PTR_ERR (pp); } static void fbnic_ring_init(struct fbnic_ring *ring, u32 __iomem *doorbell,
@@ -1961,7 +1972,7 @@ static int fbnic_alloc_rx_qt_resources(struct fbnic_net *fbn,struct device *dev = fbn->netdev->dev.parent;int err; - err =fbnic_alloc_qt_page_pools (fbn, nv, qt); + err =fbnic_alloc_qt_page_pools (fbn, nv, qt, qt->cmpl.q_idx);if (err)return err;
Signature · 1 line
2.51.0
Jakub Kicinski
maintainerPATCH v3 12/14 eth: fbnic: defer page pool recycling activation to queue start
In reply to Jakub KicinskiWe need to be more careful about when direct page pool recycling is enabled in preparation for queue ops support. Don't set the NAPI pointer, call page_pool_enable_direct_recycling() from the function that activates the queue (once the config can no longer fail).
--- drivers/net/ethernet/meta/fbnic/fbnic_txrx.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
drivers/net/ethernet/meta/fbnic/fbnic_txrx.c +5 -1
@@ -1528,7 +1528,6 @@ fbnic_alloc_qt_page_pools(struct fbnic_net *fbn, struct fbnic_napi_vector *nv, .dma_dir = DMA_BIDIRECTIONAL, .offset = 0, .max_len = PAGE_SIZE, - .napi = &nv->napi, .netdev = fbn->netdev, .queue_idx = rxq_idx, };
@@ -2615,6 +2614,11 @@ static void __fbnic_nv_enable(struct fbnic_napi_vector *nv)for (j =0 ; j < nv->rxt_count; j++, t++) {struct fbnic_q_triad *qt = &nv->qt[t]; +page_pool_enable_direct_recycling (qt->sub0.page_pool, + &nv->napi); +page_pool_enable_direct_recycling (qt->sub1.page_pool, + &nv->napi); +fbnic_enable_bdq (&qt->sub0, &qt->sub1);fbnic_config_drop_mode_rcq (nv, &qt->cmpl);fbnic_enable_rcq (nv, &qt->cmpl);
Signature · 1 line
2.51.0
Jakub Kicinski
maintainerPATCH v3 13/14 eth: fbnic: don't pass NAPI into pp alloc
In reply to Jakub KicinskiQueue API may ask us to allocate page pools when the device is down, to validate that we ingested a memory provider binding. Don't require NAPI to be passed to fbnic_alloc_qt_page_pools(), to make calling fbnic_alloc_qt_page_pools() without NAPI possible.
--- drivers/net/ethernet/meta/fbnic/fbnic_txrx.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/net/ethernet/meta/fbnic/fbnic_txrx.c +4 -4
@@ -1515,8 +1515,8 @@ void fbnic_free_napi_vectors(struct fbnic_net *fbn) }static int -fbnic_alloc_qt_page_pools (struct fbnic_net *fbn,struct fbnic_napi_vector *nv, -struct fbnic_q_triad *qt,unsigned int rxq_idx) +fbnic_alloc_qt_page_pools (struct fbnic_net *fbn,struct fbnic_q_triad *qt, +unsigned int rxq_idx) {struct page_pool_params pp_params = { .order =0 ,
@@ -1524,7 +1524,7 @@ fbnic_alloc_qt_page_pools(struct fbnic_net *fbn, struct fbnic_napi_vector *nv, PP_FLAG_DMA_SYNC_DEV, .pool_size = fbn->hpq_size + fbn->ppq_size, .nid = NUMA_NO_NODE, - .dev = nv->dev, + .dev = fbn->netdev->dev.parent, .dma_dir = DMA_BIDIRECTIONAL, .offset = 0, .max_len = PAGE_SIZE,
@@ -1971,7 +1971,7 @@ static int fbnic_alloc_rx_qt_resources(struct fbnic_net *fbn,struct device *dev = fbn->netdev->dev.parent;int err; - err =fbnic_alloc_qt_page_pools (fbn, nv, qt, qt->cmpl.q_idx); + err =fbnic_alloc_qt_page_pools (fbn, qt, qt->cmpl.q_idx);if (err)return err;
Signature · 1 line
2.51.0
Jakub Kicinski
maintainerPATCH v3 14/14 eth: fbnic: support queue ops / zero-copy Rx
In reply to Jakub KicinskiSupport queue ops. fbnic doesn't shut down the entire device just to restart a single queue.
./tools/testing/selftests/drivers/net/hw/iou-zcrx.py TAP version 13
1..3
ok 1 iou-zcrx.test_zcrx
ok 2 iou-zcrx.test_zcrx_oneshot
ok 3 iou-zcrx.test_zcrx_rss
# Totals: pass:3 fail:0 xfail:0 xpass:0 skip:0 error:0
--- drivers/net/ethernet/meta/fbnic/fbnic_txrx.h | 2 + .../net/ethernet/meta/fbnic/fbnic_netdev.c | 3 +- drivers/net/ethernet/meta/fbnic/fbnic_txrx.c | 171 ++++++++++++++++++ 3 files changed, 174 insertions(+), 2 deletions(-)
drivers/net/ethernet/meta/fbnic/fbnic_txrx.h +2 -0
@@ -156,6 +156,8 @@ struct fbnic_napi_vector {struct fbnic_q_triad qt[]; }; +extern const struct netdev_queue_mgmt_ops fbnic_queue_mgmt_ops; +netdev_tx_t fbnic_xmit_frame (struct sk_buff *skb,struct net_device *dev); netdev_features_t fbnic_features_check(struct sk_buff *skb, struct net_device *dev,
drivers/net/ethernet/meta/fbnic/fbnic_netdev.c +1 -2
@@ -711,11 +711,10 @@ struct net_device *fbnic_netdev_alloc(struct fbnic_dev *fbd) netdev->netdev_ops = &fbnic_netdev_ops; netdev->stat_ops = &fbnic_stat_ops; + netdev->queue_mgmt_ops = &fbnic_queue_mgmt_ops;fbnic_set_ethtool_ops (netdev); - netdev->request_ops_lock = true; - fbn =netdev_priv (netdev); fbn->netdev = netdev;
drivers/net/ethernet/meta/fbnic/fbnic_txrx.c +171 -0
192 lines not on this page · raw message
Signature · 1 line
2.51.0
This series was applied to netdev/net-next.git (main) by Paolo Abeni <[email protected]>:
Hello:
This series was applied to netdev/net-next.git (main) by Paolo Abeni <[email protected]>:
Quoted 11 lines · On Mon, 1 Sep 2025 14:12:00 -0700 you wrote:
Add support for queue API to fbnic, enable zero-copy Rx.
Patch 10 is likely of most interest as it adds a new core helper (and touches mlx5). The rest of the patches are fbnic-specific (and relatively boring).
Patches 1-3 reshuffle the Rx init/allocation path to better align structures and functions which operate on them. Notably patch 1 moves the page pool pointer to the queue struct (from NAPI).
[...]
Here is the summary with links:
- [net-next,v3,01/14] eth: fbnic: move page pool pointer from NAPI to the ring struct
https://git.kernel.org/netdev/net-next/c/33478dca2b23 - [net-next,v3,02/14] eth: fbnic: move xdp_rxq_info_reg() to resource alloc https://git.kernel.org/netdev/net-next/c/894d4a4ea6cb - [net-next,v3,03/14] eth: fbnic: move page pool alloc to fbnic_alloc_rx_qt_resources() https://git.kernel.org/netdev/net-next/c/b6396b71d196 - [net-next,v3,04/14] eth: fbnic: use netmem_ref where applicable https://git.kernel.org/netdev/net-next/c/426e13db369c - [net-next,v3,05/14] eth: fbnic: request ops lock https://git.kernel.org/netdev/net-next/c/4ddb17c1a2c2 - [net-next,v3,06/14] eth: fbnic: split fbnic_disable() https://git.kernel.org/netdev/net-next/c/cbfc047429ee - [net-next,v3,07/14] eth: fbnic: split fbnic_flush() https://git.kernel.org/netdev/net-next/c/be2be74af889 - [net-next,v3,08/14] eth: fbnic: split fbnic_enable() https://git.kernel.org/netdev/net-next/c/8a47d940cf81 - [net-next,v3,09/14] eth: fbnic: split fbnic_fill() https://git.kernel.org/netdev/net-next/c/709da681f4de - [net-next,v3,10/14] net: add helper to pre-check if PP for an Rx queue will be unreadable https://git.kernel.org/netdev/net-next/c/3ceb08838b57 - [net-next,v3,11/14] eth: fbnic: allocate unreadable page pool for the payloads https://git.kernel.org/netdev/net-next/c/8a11010fdd96 - [net-next,v3,12/14] eth: fbnic: defer page pool recycling activation to queue start https://git.kernel.org/netdev/net-next/c/49c429ec6b62 - [net-next,v3,13/14] eth: fbnic: don't pass NAPI into pp alloc https://git.kernel.org/netdev/net-next/c/3812339b6cc9 - [net-next,v3,14/14] eth: fbnic: support queue ops / zero-copy Rx https://git.kernel.org/netdev/net-next/c/da43127a8edc
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html