Skip to content

Commit f3fef2b

Browse files
JanJSokolowskiJeff Kirsher
authored andcommitted
i40e: Remove umem from VSI
As current implementation of netdev already contains and provides umems for us, we no longer have the need to contain these structures in i40e_vsi. Refactor the code to operate on netdev-provided umems. Signed-off-by: Jan Sokolowski <[email protected]> Acked-by: Björn Töpel <[email protected]> Tested-by: Andrew Bowers <[email protected]> Signed-off-by: Jeff Kirsher <[email protected]>
1 parent 5f4f3b2 commit f3fef2b

File tree

2 files changed

+21
-99
lines changed

2 files changed

+21
-99
lines changed

drivers/net/ethernet/intel/i40e/i40e.h

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
#include <net/pkt_cls.h>
3535
#include <net/tc_act/tc_gact.h>
3636
#include <net/tc_act/tc_mirred.h>
37+
#include <net/xdp_sock.h>
3738
#include "i40e_type.h"
3839
#include "i40e_prototype.h"
3940
#include "i40e_client.h"
@@ -787,11 +788,6 @@ struct i40e_vsi {
787788

788789
/* VSI specific handlers */
789790
irqreturn_t (*irq_handler)(int irq, void *data);
790-
791-
/* AF_XDP zero-copy */
792-
struct xdp_umem **xsk_umems;
793-
u16 num_xsk_umems_used;
794-
u16 num_xsk_umems;
795791
} ____cacheline_internodealigned_in_smp;
796792

797793
struct i40e_netdev_priv {
@@ -1104,10 +1100,10 @@ static inline struct xdp_umem *i40e_xsk_umem(struct i40e_ring *ring)
11041100
if (ring_is_xdp(ring))
11051101
qid -= ring->vsi->alloc_queue_pairs;
11061102

1107-
if (!ring->vsi->xsk_umems || !ring->vsi->xsk_umems[qid] || !xdp_on)
1103+
if (!xdp_on)
11081104
return NULL;
11091105

1110-
return ring->vsi->xsk_umems[qid];
1106+
return xdp_get_umem_from_qid(ring->vsi->netdev, qid);
11111107
}
11121108

11131109
int i40e_create_queue_channel(struct i40e_vsi *vsi, struct i40e_channel *ch);

drivers/net/ethernet/intel/i40e/i40e_xsk.c

Lines changed: 18 additions & 92 deletions
Original file line numberDiff line numberDiff line change
@@ -9,69 +9,6 @@
99
#include "i40e_txrx_common.h"
1010
#include "i40e_xsk.h"
1111

12-
/**
13-
* i40e_alloc_xsk_umems - Allocate an array to store per ring UMEMs
14-
* @vsi: Current VSI
15-
*
16-
* Returns 0 on success, <0 on failure
17-
**/
18-
static int i40e_alloc_xsk_umems(struct i40e_vsi *vsi)
19-
{
20-
if (vsi->xsk_umems)
21-
return 0;
22-
23-
vsi->num_xsk_umems_used = 0;
24-
vsi->num_xsk_umems = vsi->alloc_queue_pairs;
25-
vsi->xsk_umems = kcalloc(vsi->num_xsk_umems, sizeof(*vsi->xsk_umems),
26-
GFP_KERNEL);
27-
if (!vsi->xsk_umems) {
28-
vsi->num_xsk_umems = 0;
29-
return -ENOMEM;
30-
}
31-
32-
return 0;
33-
}
34-
35-
/**
36-
* i40e_add_xsk_umem - Store a UMEM for a certain ring/qid
37-
* @vsi: Current VSI
38-
* @umem: UMEM to store
39-
* @qid: Ring/qid to associate with the UMEM
40-
*
41-
* Returns 0 on success, <0 on failure
42-
**/
43-
static int i40e_add_xsk_umem(struct i40e_vsi *vsi, struct xdp_umem *umem,
44-
u16 qid)
45-
{
46-
int err;
47-
48-
err = i40e_alloc_xsk_umems(vsi);
49-
if (err)
50-
return err;
51-
52-
vsi->xsk_umems[qid] = umem;
53-
vsi->num_xsk_umems_used++;
54-
55-
return 0;
56-
}
57-
58-
/**
59-
* i40e_remove_xsk_umem - Remove a UMEM for a certain ring/qid
60-
* @vsi: Current VSI
61-
* @qid: Ring/qid associated with the UMEM
62-
**/
63-
static void i40e_remove_xsk_umem(struct i40e_vsi *vsi, u16 qid)
64-
{
65-
vsi->xsk_umems[qid] = NULL;
66-
vsi->num_xsk_umems_used--;
67-
68-
if (vsi->num_xsk_umems == 0) {
69-
kfree(vsi->xsk_umems);
70-
vsi->xsk_umems = NULL;
71-
vsi->num_xsk_umems = 0;
72-
}
73-
}
74-
7512
/**
7613
* i40e_xsk_umem_dma_map - DMA maps all UMEM memory for the netdev
7714
* @vsi: Current VSI
@@ -140,6 +77,7 @@ static void i40e_xsk_umem_dma_unmap(struct i40e_vsi *vsi, struct xdp_umem *umem)
14077
static int i40e_xsk_umem_enable(struct i40e_vsi *vsi, struct xdp_umem *umem,
14178
u16 qid)
14279
{
80+
struct net_device *netdev = vsi->netdev;
14381
struct xdp_umem_fq_reuse *reuseq;
14482
bool if_running;
14583
int err;
@@ -150,12 +88,9 @@ static int i40e_xsk_umem_enable(struct i40e_vsi *vsi, struct xdp_umem *umem,
15088
if (qid >= vsi->num_queue_pairs)
15189
return -EINVAL;
15290

153-
if (vsi->xsk_umems) {
154-
if (qid >= vsi->num_xsk_umems)
155-
return -EINVAL;
156-
if (vsi->xsk_umems[qid])
157-
return -EBUSY;
158-
}
91+
if (qid >= netdev->real_num_rx_queues ||
92+
qid >= netdev->real_num_tx_queues)
93+
return -EINVAL;
15994

16095
reuseq = xsk_reuseq_prepare(vsi->rx_rings[0]->count);
16196
if (!reuseq)
@@ -173,13 +108,7 @@ static int i40e_xsk_umem_enable(struct i40e_vsi *vsi, struct xdp_umem *umem,
173108
err = i40e_queue_pair_disable(vsi, qid);
174109
if (err)
175110
return err;
176-
}
177-
178-
err = i40e_add_xsk_umem(vsi, umem, qid);
179-
if (err)
180-
return err;
181111

182-
if (if_running) {
183112
err = i40e_queue_pair_enable(vsi, qid);
184113
if (err)
185114
return err;
@@ -197,11 +126,13 @@ static int i40e_xsk_umem_enable(struct i40e_vsi *vsi, struct xdp_umem *umem,
197126
**/
198127
static int i40e_xsk_umem_disable(struct i40e_vsi *vsi, u16 qid)
199128
{
129+
struct net_device *netdev = vsi->netdev;
130+
struct xdp_umem *umem;
200131
bool if_running;
201132
int err;
202133

203-
if (!vsi->xsk_umems || qid >= vsi->num_xsk_umems ||
204-
!vsi->xsk_umems[qid])
134+
umem = xdp_get_umem_from_qid(netdev, qid);
135+
if (!umem)
205136
return -EINVAL;
206137

207138
if_running = netif_running(vsi->netdev) && i40e_enabled_xdp_vsi(vsi);
@@ -212,8 +143,7 @@ static int i40e_xsk_umem_disable(struct i40e_vsi *vsi, u16 qid)
212143
return err;
213144
}
214145

215-
i40e_xsk_umem_dma_unmap(vsi, vsi->xsk_umems[qid]);
216-
i40e_remove_xsk_umem(vsi, qid);
146+
i40e_xsk_umem_dma_unmap(vsi, umem);
217147

218148
if (if_running) {
219149
err = i40e_queue_pair_enable(vsi, qid);
@@ -237,20 +167,18 @@ static int i40e_xsk_umem_disable(struct i40e_vsi *vsi, u16 qid)
237167
int i40e_xsk_umem_query(struct i40e_vsi *vsi, struct xdp_umem **umem,
238168
u16 qid)
239169
{
170+
struct net_device *netdev = vsi->netdev;
171+
struct xdp_umem *queried_umem;
172+
240173
if (vsi->type != I40E_VSI_MAIN)
241174
return -EINVAL;
242175

243-
if (qid >= vsi->num_queue_pairs)
244-
return -EINVAL;
176+
queried_umem = xdp_get_umem_from_qid(netdev, qid);
245177

246-
if (vsi->xsk_umems) {
247-
if (qid >= vsi->num_xsk_umems)
248-
return -EINVAL;
249-
*umem = vsi->xsk_umems[qid];
250-
return 0;
251-
}
178+
if (!queried_umem)
179+
return -EINVAL;
252180

253-
*umem = NULL;
181+
*umem = queried_umem;
254182
return 0;
255183
}
256184

@@ -945,13 +873,11 @@ void i40e_xsk_clean_tx_ring(struct i40e_ring *tx_ring)
945873
**/
946874
bool i40e_xsk_any_rx_ring_enabled(struct i40e_vsi *vsi)
947875
{
876+
struct net_device *netdev = vsi->netdev;
948877
int i;
949878

950-
if (!vsi->xsk_umems)
951-
return false;
952-
953879
for (i = 0; i < vsi->num_queue_pairs; i++) {
954-
if (vsi->xsk_umems[i])
880+
if (xdp_get_umem_from_qid(netdev, i))
955881
return true;
956882
}
957883

0 commit comments

Comments
 (0)