1 // SPDX-License-Identifier: GPL-2.0
2 /* XDP user-space ring structure
3 * Copyright(c) 2018 Intel Corporation.
6 #include <linux/slab.h>
10 void xskq_set_umem(struct xsk_queue
*q
, struct xdp_umem_props
*umem_props
)
15 q
->umem_props
= *umem_props
;
18 static u32
xskq_umem_get_ring_size(struct xsk_queue
*q
)
20 return sizeof(struct xdp_umem_ring
) + q
->nentries
* sizeof(u64
);
23 static u32
xskq_rxtx_get_ring_size(struct xsk_queue
*q
)
25 return sizeof(struct xdp_ring
) + q
->nentries
* sizeof(struct xdp_desc
);
28 struct xsk_queue
*xskq_create(u32 nentries
, bool umem_queue
)
34 q
= kzalloc(sizeof(*q
), GFP_KERNEL
);
38 q
->nentries
= nentries
;
39 q
->ring_mask
= nentries
- 1;
41 gfp_flags
= GFP_KERNEL
| __GFP_ZERO
| __GFP_NOWARN
|
42 __GFP_COMP
| __GFP_NORETRY
;
43 size
= umem_queue
? xskq_umem_get_ring_size(q
) :
44 xskq_rxtx_get_ring_size(q
);
46 q
->ring
= (struct xdp_ring
*)__get_free_pages(gfp_flags
,
56 void xskq_destroy(struct xsk_queue
*q
)
61 page_frag_free(q
->ring
);