summaryrefslogtreecommitdiffstats
path: root/net/xdp/xdp_umem.h
blob: 70fe225baa51879ce92b7d1fd3b99800a460b54a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
/* SPDX-License-Identifier: GPL-2.0 */
/* XDP user-space packet buffer
 * Copyright(c) 2018 Intel Corporation.
 */

#ifndef XDP_UMEM_H_
#define XDP_UMEM_H_

#include <linux/mm.h>
#include <linux/if_xdp.h>
#include <linux/workqueue.h>

#include "xsk_queue.h"
#include "xdp_umem_props.h"

struct xdp_umem {
	struct xsk_queue *fq;
	struct xsk_queue *cq;
	struct page **pgs;
	struct xdp_umem_props props;
	u32 npgs;
	u32 frame_headroom;
	u32 nfpp_mask;
	u32 nfpplog2;
	u32 frame_size_log2;
	struct user_struct *user;
	struct pid *pid;
	unsigned long address;
	size_t size;
	atomic_t users;
	struct work_struct work;
};

static inline char *xdp_umem_get_data(struct xdp_umem *umem, u32 idx)
{
	u64 pg, off;
	char *data;

	pg = idx >> umem->nfpplog2;
	off = (idx & umem->nfpp_mask) << umem->frame_size_log2;

	data = page_address(umem->pgs[pg]);
	return data + off;
}

static inline char *xdp_umem_get_data_with_headroom(struct xdp_umem *umem,
						    u32 idx)
{
	return xdp_umem_get_data(umem, idx) + umem->frame_headroom;
}

bool xdp_umem_validate_queues(struct xdp_umem *umem);
int xdp_umem_reg(struct xdp_umem *umem, struct xdp_umem_reg *mr);
void xdp_get_umem(struct xdp_umem *umem);
void xdp_put_umem(struct xdp_umem *umem);
int xdp_umem_create(struct xdp_umem **umem);

#endif /* XDP_UMEM_H_ */
OpenPOWER on IntegriCloud