staging: rtl8188eu: Add ASUS USB-N10 Nano B1 to device table
[linux/fpc-iii.git] / net / xdp / xsk_queue.c
blob6c32e92e98fcbff550ffc0d7f336e0510ac181b6
1 // SPDX-License-Identifier: GPL-2.0
2 /* XDP user-space ring structure
3 * Copyright(c) 2018 Intel Corporation.
4 */
6 #include <linux/slab.h>
8 #include "xsk_queue.h"
10 void xskq_set_umem(struct xsk_queue *q, struct xdp_umem_props *umem_props)
12 if (!q)
13 return;
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)
30 struct xsk_queue *q;
31 gfp_t gfp_flags;
32 size_t size;
34 q = kzalloc(sizeof(*q), GFP_KERNEL);
35 if (!q)
36 return NULL;
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,
47 get_order(size));
48 if (!q->ring) {
49 kfree(q);
50 return NULL;
53 return q;
56 void xskq_destroy(struct xsk_queue *q)
58 if (!q)
59 return;
61 page_frag_free(q->ring);
62 kfree(q);