1 // SPDX-License-Identifier: GPL-2.0
2 /* XDP user-space ring structure
3 * Copyright(c) 2018 Intel Corporation.
6 #include <linux/log2.h>
7 #include <linux/slab.h>
8 #include <linux/overflow.h>
9 #include <net/xdp_sock_drv.h>
11 #include "xsk_queue.h"
13 static size_t xskq_get_ring_size(struct xsk_queue *q, bool umem_queue)
15 struct xdp_umem_ring *umem_ring;
16 struct xdp_rxtx_ring *rxtx_ring;
19 return struct_size(umem_ring, desc, q->nentries);
20 return struct_size(rxtx_ring, desc, q->nentries);
23 struct xsk_queue *xskq_create(u32 nentries, bool umem_queue)
29 q = kzalloc(sizeof(*q), GFP_KERNEL);
33 q->nentries = nentries;
34 q->ring_mask = nentries - 1;
36 gfp_flags = GFP_KERNEL | __GFP_ZERO | __GFP_NOWARN |
37 __GFP_COMP | __GFP_NORETRY;
38 size = xskq_get_ring_size(q, umem_queue);
40 q->ring = (struct xdp_ring *)__get_free_pages(gfp_flags,
50 void xskq_destroy(struct xsk_queue *q)
55 page_frag_free(q->ring);