blob: 7e0b2fab852291d968532e6c7d28a1f53b74d73a [file] [log] [blame]
Björn Töpelc0c77d82018-05-02 13:01:23 +02001/* SPDX-License-Identifier: GPL-2.0
2 * XDP user-space packet buffer
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#ifndef XDP_UMEM_H_
16#define XDP_UMEM_H_
17
18#include <linux/mm.h>
19#include <linux/if_xdp.h>
20#include <linux/workqueue.h>
21
Magnus Karlsson423f3832018-05-02 13:01:24 +020022#include "xsk_queue.h"
Björn Töpelc0c77d82018-05-02 13:01:23 +020023#include "xdp_umem_props.h"
24
25struct xdp_umem {
Magnus Karlsson423f3832018-05-02 13:01:24 +020026 struct xsk_queue *fq;
Magnus Karlssonfe230832018-05-02 13:01:31 +020027 struct xsk_queue *cq;
Björn Töpelc0c77d82018-05-02 13:01:23 +020028 struct page **pgs;
29 struct xdp_umem_props props;
30 u32 npgs;
31 u32 frame_headroom;
32 u32 nfpp_mask;
33 u32 nfpplog2;
34 u32 frame_size_log2;
35 struct user_struct *user;
36 struct pid *pid;
37 unsigned long address;
38 size_t size;
39 atomic_t users;
40 struct work_struct work;
41};
42
Björn Töpelc4971762018-05-02 13:01:27 +020043static inline char *xdp_umem_get_data(struct xdp_umem *umem, u32 idx)
44{
45 u64 pg, off;
46 char *data;
47
48 pg = idx >> umem->nfpplog2;
49 off = (idx & umem->nfpp_mask) << umem->frame_size_log2;
50
51 data = page_address(umem->pgs[pg]);
52 return data + off;
53}
54
55static inline char *xdp_umem_get_data_with_headroom(struct xdp_umem *umem,
56 u32 idx)
57{
58 return xdp_umem_get_data(umem, idx) + umem->frame_headroom;
59}
60
Magnus Karlsson965a9902018-05-02 13:01:26 +020061bool xdp_umem_validate_queues(struct xdp_umem *umem);
Björn Töpelc0c77d82018-05-02 13:01:23 +020062int xdp_umem_reg(struct xdp_umem *umem, struct xdp_umem_reg *mr);
63void xdp_get_umem(struct xdp_umem *umem);
64void xdp_put_umem(struct xdp_umem *umem);
65int xdp_umem_create(struct xdp_umem **umem);
66
67#endif /* XDP_UMEM_H_ */