]>
Commit | Line | Data |
---|---|---|
423f3832 MK |
1 | // SPDX-License-Identifier: GPL-2.0 |
2 | /* XDP user-space ring structure | |
3 | * Copyright(c) 2018 Intel Corporation. | |
4 | * | |
5 | * This program is free software; you can redistribute it and/or modify it | |
6 | * under the terms and conditions of the GNU General Public License, | |
7 | * version 2, as published by the Free Software Foundation. | |
8 | * | |
9 | * This program is distributed in the hope it will be useful, but WITHOUT | |
10 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
11 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for | |
12 | * more details. | |
13 | */ | |
14 | ||
15 | #include <linux/slab.h> | |
16 | ||
17 | #include "xsk_queue.h" | |
18 | ||
19 | static u32 xskq_umem_get_ring_size(struct xsk_queue *q) | |
20 | { | |
21 | return sizeof(struct xdp_umem_ring) + q->nentries * sizeof(u32); | |
22 | } | |
23 | ||
24 | struct xsk_queue *xskq_create(u32 nentries) | |
25 | { | |
26 | struct xsk_queue *q; | |
27 | gfp_t gfp_flags; | |
28 | size_t size; | |
29 | ||
30 | q = kzalloc(sizeof(*q), GFP_KERNEL); | |
31 | if (!q) | |
32 | return NULL; | |
33 | ||
34 | q->nentries = nentries; | |
35 | q->ring_mask = nentries - 1; | |
36 | ||
37 | gfp_flags = GFP_KERNEL | __GFP_ZERO | __GFP_NOWARN | | |
38 | __GFP_COMP | __GFP_NORETRY; | |
39 | size = xskq_umem_get_ring_size(q); | |
40 | ||
41 | q->ring = (struct xdp_ring *)__get_free_pages(gfp_flags, | |
42 | get_order(size)); | |
43 | if (!q->ring) { | |
44 | kfree(q); | |
45 | return NULL; | |
46 | } | |
47 | ||
48 | return q; | |
49 | } | |
50 | ||
51 | void xskq_destroy(struct xsk_queue *q) | |
52 | { | |
53 | if (!q) | |
54 | return; | |
55 | ||
56 | page_frag_free(q->ring); | |
57 | kfree(q); | |
58 | } |