Skip to content

Commit ac8813c

Browse files
emuslnkuba-moo
authored andcommitted
ionic: convert Rx queue buffers to use page_pool
Our home-grown buffer management needs to go away and we need to be playing nicely with the page_pool infrastructure. This converts the Rx traffic queues to use page_pool. Also, since ionic_rx_buf_size() was removed, redefine IONIC_PAGE_SIZE to account for IONIC_MAX_BUF_LEN being the largest allowed buffer to prevent overflowing u16 variables, which could happen when PAGE_SIZE is defined as >= 64KB. include/linux/minmax.h:93:37: warning: conversion from 'long unsigned int' to 'u16' {aka 'short unsigned int'} changes value from '65536' to '0' [-Woverflow] Signed-off-by: Shannon Nelson <[email protected]> Signed-off-by: Brett Creeley <[email protected]> Link: https://patch.msgid.link/[email protected] Signed-off-by: Jakub Kicinski <[email protected]>
1 parent a7f3f63 commit ac8813c

File tree

4 files changed

+233
-208
lines changed

4 files changed

+233
-208
lines changed

drivers/net/ethernet/pensando/Kconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ config IONIC
2323
depends on PTP_1588_CLOCK_OPTIONAL
2424
select NET_DEVLINK
2525
select DIMLIB
26+
select PAGE_POOL
2627
help
2728
This enables the support for the Pensando family of Ethernet
2829
adapters. More specific information on this driver can be

drivers/net/ethernet/pensando/ionic/ionic_dev.h

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -181,10 +181,7 @@ struct ionic_queue;
181181
struct ionic_qcq;
182182

183183
#define IONIC_MAX_BUF_LEN ((u16)-1)
184-
#define IONIC_PAGE_SIZE PAGE_SIZE
185-
#define IONIC_PAGE_SPLIT_SZ (PAGE_SIZE / 2)
186-
#define IONIC_PAGE_GFP_MASK (GFP_ATOMIC | __GFP_NOWARN |\
187-
__GFP_COMP | __GFP_MEMALLOC)
184+
#define IONIC_PAGE_SIZE MIN(PAGE_SIZE, IONIC_MAX_BUF_LEN)
188185

189186
#define IONIC_XDP_MAX_LINEAR_MTU (IONIC_PAGE_SIZE - \
190187
(VLAN_ETH_HLEN + \
@@ -248,11 +245,6 @@ struct ionic_queue {
248245
struct ionic_rxq_desc *rxq;
249246
struct ionic_admin_cmd *adminq;
250247
};
251-
union {
252-
void __iomem *cmb_base;
253-
struct ionic_txq_desc __iomem *cmb_txq;
254-
struct ionic_rxq_desc __iomem *cmb_rxq;
255-
};
256248
union {
257249
void *sg_base;
258250
struct ionic_txq_sg_desc *txq_sgl;
@@ -261,8 +253,14 @@ struct ionic_queue {
261253
};
262254
struct xdp_rxq_info *xdp_rxq_info;
263255
struct bpf_prog *xdp_prog;
256+
struct page_pool *page_pool;
264257
struct ionic_queue *partner;
265258

259+
union {
260+
void __iomem *cmb_base;
261+
struct ionic_txq_desc __iomem *cmb_txq;
262+
struct ionic_rxq_desc __iomem *cmb_rxq;
263+
};
266264
unsigned int type;
267265
unsigned int hw_index;
268266
dma_addr_t base_pa;

drivers/net/ethernet/pensando/ionic/ionic_lif.c

Lines changed: 61 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#include <linux/cpumask.h>
1414
#include <linux/crash_dump.h>
1515
#include <linux/vmalloc.h>
16+
#include <net/page_pool/helpers.h>
1617

1718
#include "ionic.h"
1819
#include "ionic_bus.h"
@@ -439,6 +440,9 @@ static void ionic_qcq_free(struct ionic_lif *lif, struct ionic_qcq *qcq)
439440
qcq->sg_base_pa = 0;
440441
}
441442

443+
page_pool_destroy(qcq->q.page_pool);
444+
qcq->q.page_pool = NULL;
445+
442446
ionic_qcq_intr_free(lif, qcq);
443447
vfree(qcq->q.info);
444448
qcq->q.info = NULL;
@@ -553,7 +557,8 @@ static int ionic_qcq_alloc(struct ionic_lif *lif, unsigned int type,
553557
unsigned int cq_desc_size,
554558
unsigned int sg_desc_size,
555559
unsigned int desc_info_size,
556-
unsigned int pid, struct ionic_qcq **qcq)
560+
unsigned int pid, struct bpf_prog *xdp_prog,
561+
struct ionic_qcq **qcq)
557562
{
558563
struct ionic_dev *idev = &lif->ionic->idev;
559564
struct device *dev = lif->ionic->dev;
@@ -579,19 +584,44 @@ static int ionic_qcq_alloc(struct ionic_lif *lif, unsigned int type,
579584
goto err_out_free_qcq;
580585
}
581586

587+
if (type == IONIC_QTYPE_RXQ) {
588+
struct page_pool_params pp_params = {
589+
.flags = PP_FLAG_DMA_MAP | PP_FLAG_DMA_SYNC_DEV,
590+
.order = 0,
591+
.pool_size = num_descs,
592+
.nid = NUMA_NO_NODE,
593+
.dev = lif->ionic->dev,
594+
.napi = &new->napi,
595+
.dma_dir = DMA_FROM_DEVICE,
596+
.max_len = PAGE_SIZE,
597+
.netdev = lif->netdev,
598+
};
599+
600+
if (xdp_prog)
601+
pp_params.dma_dir = DMA_BIDIRECTIONAL;
602+
603+
new->q.page_pool = page_pool_create(&pp_params);
604+
if (IS_ERR(new->q.page_pool)) {
605+
netdev_err(lif->netdev, "Cannot create page_pool\n");
606+
err = PTR_ERR(new->q.page_pool);
607+
new->q.page_pool = NULL;
608+
goto err_out_free_q_info;
609+
}
610+
}
611+
582612
new->q.type = type;
583613
new->q.max_sg_elems = lif->qtype_info[type].max_sg_elems;
584614

585615
err = ionic_q_init(lif, idev, &new->q, index, name, num_descs,
586616
desc_size, sg_desc_size, pid);
587617
if (err) {
588618
netdev_err(lif->netdev, "Cannot initialize queue\n");
589-
goto err_out_free_q_info;
619+
goto err_out_free_page_pool;
590620
}
591621

592622
err = ionic_alloc_qcq_interrupt(lif, new);
593623
if (err)
594-
goto err_out_free_q_info;
624+
goto err_out_free_page_pool;
595625

596626
err = ionic_cq_init(lif, &new->cq, &new->intr, num_descs, cq_desc_size);
597627
if (err) {
@@ -712,6 +742,8 @@ static int ionic_qcq_alloc(struct ionic_lif *lif, unsigned int type,
712742
devm_free_irq(dev, new->intr.vector, &new->napi);
713743
ionic_intr_free(lif->ionic, new->intr.index);
714744
}
745+
err_out_free_page_pool:
746+
page_pool_destroy(new->q.page_pool);
715747
err_out_free_q_info:
716748
vfree(new->q.info);
717749
err_out_free_qcq:
@@ -734,7 +766,7 @@ static int ionic_qcqs_alloc(struct ionic_lif *lif)
734766
sizeof(struct ionic_admin_comp),
735767
0,
736768
sizeof(struct ionic_admin_desc_info),
737-
lif->kern_pid, &lif->adminqcq);
769+
lif->kern_pid, NULL, &lif->adminqcq);
738770
if (err)
739771
return err;
740772
ionic_debugfs_add_qcq(lif, lif->adminqcq);
@@ -747,7 +779,7 @@ static int ionic_qcqs_alloc(struct ionic_lif *lif)
747779
sizeof(union ionic_notifyq_comp),
748780
0,
749781
sizeof(struct ionic_admin_desc_info),
750-
lif->kern_pid, &lif->notifyqcq);
782+
lif->kern_pid, NULL, &lif->notifyqcq);
751783
if (err)
752784
goto err_out;
753785
ionic_debugfs_add_qcq(lif, lif->notifyqcq);
@@ -965,7 +997,7 @@ int ionic_lif_create_hwstamp_txq(struct ionic_lif *lif)
965997
err = ionic_qcq_alloc(lif, IONIC_QTYPE_TXQ, txq_i, "hwstamp_tx", flags,
966998
num_desc, desc_sz, comp_sz, sg_desc_sz,
967999
sizeof(struct ionic_tx_desc_info),
968-
lif->kern_pid, &txq);
1000+
lif->kern_pid, NULL, &txq);
9691001
if (err)
9701002
goto err_qcq_alloc;
9711003

@@ -1025,7 +1057,7 @@ int ionic_lif_create_hwstamp_rxq(struct ionic_lif *lif)
10251057
err = ionic_qcq_alloc(lif, IONIC_QTYPE_RXQ, rxq_i, "hwstamp_rx", flags,
10261058
num_desc, desc_sz, comp_sz, sg_desc_sz,
10271059
sizeof(struct ionic_rx_desc_info),
1028-
lif->kern_pid, &rxq);
1060+
lif->kern_pid, NULL, &rxq);
10291061
if (err)
10301062
goto err_qcq_alloc;
10311063

@@ -2051,7 +2083,7 @@ static int ionic_txrx_alloc(struct ionic_lif *lif)
20512083
err = ionic_qcq_alloc(lif, IONIC_QTYPE_TXQ, i, "tx", flags,
20522084
num_desc, desc_sz, comp_sz, sg_desc_sz,
20532085
sizeof(struct ionic_tx_desc_info),
2054-
lif->kern_pid, &lif->txqcqs[i]);
2086+
lif->kern_pid, NULL, &lif->txqcqs[i]);
20552087
if (err)
20562088
goto err_out;
20572089

@@ -2083,7 +2115,8 @@ static int ionic_txrx_alloc(struct ionic_lif *lif)
20832115
err = ionic_qcq_alloc(lif, IONIC_QTYPE_RXQ, i, "rx", flags,
20842116
num_desc, desc_sz, comp_sz, sg_desc_sz,
20852117
sizeof(struct ionic_rx_desc_info),
2086-
lif->kern_pid, &lif->rxqcqs[i]);
2118+
lif->kern_pid, lif->xdp_prog,
2119+
&lif->rxqcqs[i]);
20872120
if (err)
20882121
goto err_out;
20892122

@@ -2679,15 +2712,15 @@ static int ionic_register_rxq_info(struct ionic_queue *q, unsigned int napi_id)
26792712

26802713
err = xdp_rxq_info_reg(rxq_info, q->lif->netdev, q->index, napi_id);
26812714
if (err) {
2682-
dev_err(q->dev, "Queue %d xdp_rxq_info_reg failed, err %d\n",
2683-
q->index, err);
2715+
netdev_err(q->lif->netdev, "q%d xdp_rxq_info_reg failed, err %d\n",
2716+
q->index, err);
26842717
goto err_out;
26852718
}
26862719

2687-
err = xdp_rxq_info_reg_mem_model(rxq_info, MEM_TYPE_PAGE_ORDER0, NULL);
2720+
err = xdp_rxq_info_reg_mem_model(rxq_info, MEM_TYPE_PAGE_POOL, q->page_pool);
26882721
if (err) {
2689-
dev_err(q->dev, "Queue %d xdp_rxq_info_reg_mem_model failed, err %d\n",
2690-
q->index, err);
2722+
netdev_err(q->lif->netdev, "q%d xdp_rxq_info_reg_mem_model failed, err %d\n",
2723+
q->index, err);
26912724
xdp_rxq_info_unreg(rxq_info);
26922725
goto err_out;
26932726
}
@@ -2853,7 +2886,16 @@ static int ionic_cmb_reconfig(struct ionic_lif *lif,
28532886

28542887
static void ionic_swap_queues(struct ionic_qcq *a, struct ionic_qcq *b)
28552888
{
2856-
/* only swapping the queues, not the napi, flags, or other stuff */
2889+
/* only swapping the queues and napi, not flags or other stuff */
2890+
swap(a->napi, b->napi);
2891+
2892+
if (a->q.type == IONIC_QTYPE_RXQ) {
2893+
swap(a->q.page_pool, b->q.page_pool);
2894+
a->q.page_pool->p.napi = &a->napi;
2895+
if (b->q.page_pool) /* is NULL when increasing queue count */
2896+
b->q.page_pool->p.napi = &b->napi;
2897+
}
2898+
28572899
swap(a->q.features, b->q.features);
28582900
swap(a->q.num_descs, b->q.num_descs);
28592901
swap(a->q.desc_size, b->q.desc_size);
@@ -2943,7 +2985,7 @@ int ionic_reconfigure_queues(struct ionic_lif *lif,
29432985
err = ionic_qcq_alloc(lif, IONIC_QTYPE_TXQ, i, "tx", flags,
29442986
4, desc_sz, comp_sz, sg_desc_sz,
29452987
sizeof(struct ionic_tx_desc_info),
2946-
lif->kern_pid, &lif->txqcqs[i]);
2988+
lif->kern_pid, NULL, &lif->txqcqs[i]);
29472989
if (err)
29482990
goto err_out;
29492991
}
@@ -2952,7 +2994,7 @@ int ionic_reconfigure_queues(struct ionic_lif *lif,
29522994
err = ionic_qcq_alloc(lif, IONIC_QTYPE_TXQ, i, "tx", flags,
29532995
num_desc, desc_sz, comp_sz, sg_desc_sz,
29542996
sizeof(struct ionic_tx_desc_info),
2955-
lif->kern_pid, &tx_qcqs[i]);
2997+
lif->kern_pid, NULL, &tx_qcqs[i]);
29562998
if (err)
29572999
goto err_out;
29583000
}
@@ -2974,7 +3016,7 @@ int ionic_reconfigure_queues(struct ionic_lif *lif,
29743016
err = ionic_qcq_alloc(lif, IONIC_QTYPE_RXQ, i, "rx", flags,
29753017
4, desc_sz, comp_sz, sg_desc_sz,
29763018
sizeof(struct ionic_rx_desc_info),
2977-
lif->kern_pid, &lif->rxqcqs[i]);
3019+
lif->kern_pid, NULL, &lif->rxqcqs[i]);
29783020
if (err)
29793021
goto err_out;
29803022
}
@@ -2983,7 +3025,7 @@ int ionic_reconfigure_queues(struct ionic_lif *lif,
29833025
err = ionic_qcq_alloc(lif, IONIC_QTYPE_RXQ, i, "rx", flags,
29843026
num_desc, desc_sz, comp_sz, sg_desc_sz,
29853027
sizeof(struct ionic_rx_desc_info),
2986-
lif->kern_pid, &rx_qcqs[i]);
3028+
lif->kern_pid, qparam->xdp_prog, &rx_qcqs[i]);
29873029
if (err)
29883030
goto err_out;
29893031

0 commit comments

Comments
 (0)