Björn Töpel | c0c77d8 | 2018-05-02 13:01:23 +0200 | [diff] [blame] | 1 | /* 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 Karlsson | 423f383 | 2018-05-02 13:01:24 +0200 | [diff] [blame] | 22 | #include "xsk_queue.h" |
Björn Töpel | c0c77d8 | 2018-05-02 13:01:23 +0200 | [diff] [blame] | 23 | #include "xdp_umem_props.h" |
| 24 | |
| 25 | struct xdp_umem { |
Magnus Karlsson | 423f383 | 2018-05-02 13:01:24 +0200 | [diff] [blame] | 26 | struct xsk_queue *fq; |
Björn Töpel | c0c77d8 | 2018-05-02 13:01:23 +0200 | [diff] [blame] | 27 | struct page **pgs; |
| 28 | struct xdp_umem_props props; |
| 29 | u32 npgs; |
| 30 | u32 frame_headroom; |
| 31 | u32 nfpp_mask; |
| 32 | u32 nfpplog2; |
| 33 | u32 frame_size_log2; |
| 34 | struct user_struct *user; |
| 35 | struct pid *pid; |
| 36 | unsigned long address; |
| 37 | size_t size; |
| 38 | atomic_t users; |
| 39 | struct work_struct work; |
| 40 | }; |
| 41 | |
Björn Töpel | c497176 | 2018-05-02 13:01:27 +0200 | [diff] [blame^] | 42 | static inline char *xdp_umem_get_data(struct xdp_umem *umem, u32 idx) |
| 43 | { |
| 44 | u64 pg, off; |
| 45 | char *data; |
| 46 | |
| 47 | pg = idx >> umem->nfpplog2; |
| 48 | off = (idx & umem->nfpp_mask) << umem->frame_size_log2; |
| 49 | |
| 50 | data = page_address(umem->pgs[pg]); |
| 51 | return data + off; |
| 52 | } |
| 53 | |
| 54 | static inline char *xdp_umem_get_data_with_headroom(struct xdp_umem *umem, |
| 55 | u32 idx) |
| 56 | { |
| 57 | return xdp_umem_get_data(umem, idx) + umem->frame_headroom; |
| 58 | } |
| 59 | |
Magnus Karlsson | 965a990 | 2018-05-02 13:01:26 +0200 | [diff] [blame] | 60 | bool xdp_umem_validate_queues(struct xdp_umem *umem); |
Björn Töpel | c0c77d8 | 2018-05-02 13:01:23 +0200 | [diff] [blame] | 61 | int xdp_umem_reg(struct xdp_umem *umem, struct xdp_umem_reg *mr); |
| 62 | void xdp_get_umem(struct xdp_umem *umem); |
| 63 | void xdp_put_umem(struct xdp_umem *umem); |
| 64 | int xdp_umem_create(struct xdp_umem **umem); |
| 65 | |
| 66 | #endif /* XDP_UMEM_H_ */ |