Björn Töpel | dac0914 | 2018-05-18 14:00:21 +0200 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0 */ |
| 2 | /* XDP user-space packet buffer |
Björn Töpel | c0c77d8 | 2018-05-02 13:01:23 +0200 | [diff] [blame] | 3 | * Copyright(c) 2018 Intel Corporation. |
Björn Töpel | c0c77d8 | 2018-05-02 13:01:23 +0200 | [diff] [blame] | 4 | */ |
| 5 | |
| 6 | #ifndef XDP_UMEM_H_ |
| 7 | #define XDP_UMEM_H_ |
| 8 | |
| 9 | #include <linux/mm.h> |
| 10 | #include <linux/if_xdp.h> |
| 11 | #include <linux/workqueue.h> |
| 12 | |
Magnus Karlsson | 423f383 | 2018-05-02 13:01:24 +0200 | [diff] [blame] | 13 | #include "xsk_queue.h" |
Björn Töpel | c0c77d8 | 2018-05-02 13:01:23 +0200 | [diff] [blame] | 14 | #include "xdp_umem_props.h" |
| 15 | |
| 16 | struct xdp_umem { |
Magnus Karlsson | 423f383 | 2018-05-02 13:01:24 +0200 | [diff] [blame] | 17 | struct xsk_queue *fq; |
Magnus Karlsson | fe23083 | 2018-05-02 13:01:31 +0200 | [diff] [blame] | 18 | struct xsk_queue *cq; |
Björn Töpel | c0c77d8 | 2018-05-02 13:01:23 +0200 | [diff] [blame] | 19 | struct page **pgs; |
| 20 | struct xdp_umem_props props; |
| 21 | u32 npgs; |
| 22 | u32 frame_headroom; |
| 23 | u32 nfpp_mask; |
| 24 | u32 nfpplog2; |
| 25 | u32 frame_size_log2; |
| 26 | struct user_struct *user; |
| 27 | struct pid *pid; |
| 28 | unsigned long address; |
| 29 | size_t size; |
| 30 | atomic_t users; |
| 31 | struct work_struct work; |
| 32 | }; |
| 33 | |
Björn Töpel | c497176 | 2018-05-02 13:01:27 +0200 | [diff] [blame] | 34 | static inline char *xdp_umem_get_data(struct xdp_umem *umem, u32 idx) |
| 35 | { |
| 36 | u64 pg, off; |
| 37 | char *data; |
| 38 | |
| 39 | pg = idx >> umem->nfpplog2; |
| 40 | off = (idx & umem->nfpp_mask) << umem->frame_size_log2; |
| 41 | |
| 42 | data = page_address(umem->pgs[pg]); |
| 43 | return data + off; |
| 44 | } |
| 45 | |
| 46 | static inline char *xdp_umem_get_data_with_headroom(struct xdp_umem *umem, |
| 47 | u32 idx) |
| 48 | { |
| 49 | return xdp_umem_get_data(umem, idx) + umem->frame_headroom; |
| 50 | } |
| 51 | |
Magnus Karlsson | 965a990 | 2018-05-02 13:01:26 +0200 | [diff] [blame] | 52 | bool xdp_umem_validate_queues(struct xdp_umem *umem); |
Björn Töpel | c0c77d8 | 2018-05-02 13:01:23 +0200 | [diff] [blame] | 53 | int xdp_umem_reg(struct xdp_umem *umem, struct xdp_umem_reg *mr); |
| 54 | void xdp_get_umem(struct xdp_umem *umem); |
| 55 | void xdp_put_umem(struct xdp_umem *umem); |
| 56 | int xdp_umem_create(struct xdp_umem **umem); |
| 57 | |
| 58 | #endif /* XDP_UMEM_H_ */ |