Skip to content

Commit c7a2190

Browse files
mswiatkoanguy11
authored andcommitted
ice: Remove xsk_buff_pool from VSI structure
Current implementation of netdev already contains xsk_buff_pools. We no longer have to contain these structures in ice_vsi. Refactor the code to operate on netdev-provided xsk_buff_pools. Move scheduling napi on each queue to a separate function to simplify setup function. Signed-off-by: Michal Swiatkowski <[email protected]> Reviewed-by: Maciej Fijalkowski <[email protected]> Tested-by: Kiran Bhandare <[email protected]> Signed-off-by: Tony Nguyen <[email protected]>
1 parent 34295a3 commit c7a2190

File tree

3 files changed

+30
-79
lines changed

3 files changed

+30
-79
lines changed

drivers/net/ethernet/intel/ice/ice.h

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
#include <net/devlink.h>
4040
#include <net/ipv6.h>
4141
#include <net/xdp_sock.h>
42+
#include <net/xdp_sock_drv.h>
4243
#include <net/geneve.h>
4344
#include <net/gre.h>
4445
#include <net/udp_tunnel.h>
@@ -326,9 +327,6 @@ struct ice_vsi {
326327
struct ice_ring **xdp_rings; /* XDP ring array */
327328
u16 num_xdp_txq; /* Used XDP queues */
328329
u8 xdp_mapping_mode; /* ICE_MAP_MODE_[CONTIG|SCATTER] */
329-
struct xsk_buff_pool **xsk_pools;
330-
u16 num_xsk_pools_used;
331-
u16 num_xsk_pools;
332330
} ____cacheline_internodealigned_in_smp;
333331

334332
/* struct that defines an interrupt vector */
@@ -517,17 +515,15 @@ static inline void ice_set_ring_xdp(struct ice_ring *ring)
517515
*/
518516
static inline struct xsk_buff_pool *ice_xsk_pool(struct ice_ring *ring)
519517
{
520-
struct xsk_buff_pool **pools = ring->vsi->xsk_pools;
521518
u16 qid = ring->q_index;
522519

523520
if (ice_ring_is_xdp(ring))
524521
qid -= ring->vsi->num_xdp_txq;
525522

526-
if (qid >= ring->vsi->num_xsk_pools || !pools || !pools[qid] ||
527-
!ice_is_xdp_ena_vsi(ring->vsi))
523+
if (!ice_is_xdp_ena_vsi(ring->vsi))
528524
return NULL;
529525

530-
return pools[qid];
526+
return xsk_get_pool_from_qid(ring->vsi->netdev, qid);
531527
}
532528

533529
/**

drivers/net/ethernet/intel/ice/ice_main.c

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2475,6 +2475,22 @@ int ice_destroy_xdp_rings(struct ice_vsi *vsi)
24752475
max_txqs);
24762476
}
24772477

2478+
/**
2479+
* ice_vsi_rx_napi_schedule - Schedule napi on RX queues from VSI
2480+
* @vsi: VSI to schedule napi on
2481+
*/
2482+
static void ice_vsi_rx_napi_schedule(struct ice_vsi *vsi)
2483+
{
2484+
int i;
2485+
2486+
ice_for_each_rxq(vsi, i) {
2487+
struct ice_ring *rx_ring = vsi->rx_rings[i];
2488+
2489+
if (rx_ring->xsk_pool)
2490+
napi_schedule(&rx_ring->q_vector->napi);
2491+
}
2492+
}
2493+
24782494
/**
24792495
* ice_xdp_setup_prog - Add or remove XDP eBPF program
24802496
* @vsi: VSI to setup XDP for
@@ -2519,16 +2535,8 @@ ice_xdp_setup_prog(struct ice_vsi *vsi, struct bpf_prog *prog,
25192535
if (if_running)
25202536
ret = ice_up(vsi);
25212537

2522-
if (!ret && prog && vsi->xsk_pools) {
2523-
int i;
2524-
2525-
ice_for_each_rxq(vsi, i) {
2526-
struct ice_ring *rx_ring = vsi->rx_rings[i];
2527-
2528-
if (rx_ring->xsk_pool)
2529-
napi_schedule(&rx_ring->q_vector->napi);
2530-
}
2531-
}
2538+
if (!ret && prog)
2539+
ice_vsi_rx_napi_schedule(vsi);
25322540

25332541
return (ret || xdp_ring_err) ? -ENOMEM : 0;
25342542
}

drivers/net/ethernet/intel/ice/ice_xsk.c

Lines changed: 9 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -259,45 +259,6 @@ static int ice_qp_ena(struct ice_vsi *vsi, u16 q_idx)
259259
return err;
260260
}
261261

262-
/**
263-
* ice_xsk_alloc_pools - allocate a buffer pool for an XDP socket
264-
* @vsi: VSI to allocate the buffer pool on
265-
*
266-
* Returns 0 on success, negative on error
267-
*/
268-
static int ice_xsk_alloc_pools(struct ice_vsi *vsi)
269-
{
270-
if (vsi->xsk_pools)
271-
return 0;
272-
273-
vsi->xsk_pools = kcalloc(vsi->num_xsk_pools, sizeof(*vsi->xsk_pools),
274-
GFP_KERNEL);
275-
276-
if (!vsi->xsk_pools) {
277-
vsi->num_xsk_pools = 0;
278-
return -ENOMEM;
279-
}
280-
281-
return 0;
282-
}
283-
284-
/**
285-
* ice_xsk_remove_pool - Remove an buffer pool for a certain ring/qid
286-
* @vsi: VSI from which the VSI will be removed
287-
* @qid: Ring/qid associated with the buffer pool
288-
*/
289-
static void ice_xsk_remove_pool(struct ice_vsi *vsi, u16 qid)
290-
{
291-
vsi->xsk_pools[qid] = NULL;
292-
vsi->num_xsk_pools_used--;
293-
294-
if (vsi->num_xsk_pools_used == 0) {
295-
kfree(vsi->xsk_pools);
296-
vsi->xsk_pools = NULL;
297-
vsi->num_xsk_pools = 0;
298-
}
299-
}
300-
301262
/**
302263
* ice_xsk_pool_disable - disable a buffer pool region
303264
* @vsi: Current VSI
@@ -307,12 +268,12 @@ static void ice_xsk_remove_pool(struct ice_vsi *vsi, u16 qid)
307268
*/
308269
static int ice_xsk_pool_disable(struct ice_vsi *vsi, u16 qid)
309270
{
310-
if (!vsi->xsk_pools || qid >= vsi->num_xsk_pools ||
311-
!vsi->xsk_pools[qid])
271+
struct xsk_buff_pool *pool = xsk_get_pool_from_qid(vsi->netdev, qid);
272+
273+
if (!pool)
312274
return -EINVAL;
313275

314-
xsk_pool_dma_unmap(vsi->xsk_pools[qid], ICE_RX_DMA_ATTR);
315-
ice_xsk_remove_pool(vsi, qid);
276+
xsk_pool_dma_unmap(pool, ICE_RX_DMA_ATTR);
316277

317278
return 0;
318279
}
@@ -333,22 +294,11 @@ ice_xsk_pool_enable(struct ice_vsi *vsi, struct xsk_buff_pool *pool, u16 qid)
333294
if (vsi->type != ICE_VSI_PF)
334295
return -EINVAL;
335296

336-
if (!vsi->num_xsk_pools)
337-
vsi->num_xsk_pools = min_t(u16, vsi->num_rxq, vsi->num_txq);
338-
if (qid >= vsi->num_xsk_pools)
297+
if (qid >= vsi->netdev->real_num_rx_queues ||
298+
qid >= vsi->netdev->real_num_tx_queues)
339299
return -EINVAL;
340300

341-
err = ice_xsk_alloc_pools(vsi);
342-
if (err)
343-
return err;
344-
345-
if (vsi->xsk_pools && vsi->xsk_pools[qid])
346-
return -EBUSY;
347-
348-
vsi->xsk_pools[qid] = pool;
349-
vsi->num_xsk_pools_used++;
350-
351-
err = xsk_pool_dma_map(vsi->xsk_pools[qid], ice_pf_to_dev(vsi->back),
301+
err = xsk_pool_dma_map(pool, ice_pf_to_dev(vsi->back),
352302
ICE_RX_DMA_ATTR);
353303
if (err)
354304
return err;
@@ -842,11 +792,8 @@ bool ice_xsk_any_rx_ring_ena(struct ice_vsi *vsi)
842792
{
843793
int i;
844794

845-
if (!vsi->xsk_pools)
846-
return false;
847-
848-
for (i = 0; i < vsi->num_xsk_pools; i++) {
849-
if (vsi->xsk_pools[i])
795+
ice_for_each_rxq(vsi, i) {
796+
if (xsk_get_pool_from_qid(vsi->netdev, i))
850797
return true;
851798
}
852799

0 commit comments

Comments
 (0)