1 /* SPDX-License-Identifier: GPL-2.0 */ 2 /* XDP user-space packet buffer 3 * Copyright(c) 2018 Intel Corporation. 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 13 #include "xsk_queue.h" 14 #include "xdp_umem_props.h" 15 16 struct xdp_umem { 17 struct xsk_queue *fq; 18 struct xsk_queue *cq; 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 refcount_t users; 31 struct work_struct work; 32 }; 33 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 52 bool xdp_umem_validate_queues(struct xdp_umem *umem); 53 void xdp_get_umem(struct xdp_umem *umem); 54 void xdp_put_umem(struct xdp_umem *umem); 55 struct xdp_umem *xdp_umem_create(struct xdp_umem_reg *mr); 56 57 #endif /* XDP_UMEM_H_ */ 58