xref: /dpdk/lib/bpf/bpf_impl.h (revision 0f1dc8cb671203d52488fd66936f2fe6dcca03cc)
199a2dd95SBruce Richardson /* SPDX-License-Identifier: BSD-3-Clause
299a2dd95SBruce Richardson  * Copyright(c) 2018 Intel Corporation
399a2dd95SBruce Richardson  */
499a2dd95SBruce Richardson 
563f39a43SDavid Marchand #ifndef BPF_IMPL_H
663f39a43SDavid Marchand #define BPF_IMPL_H
799a2dd95SBruce Richardson 
899a2dd95SBruce Richardson #include <rte_bpf.h>
999a2dd95SBruce Richardson #include <sys/mman.h>
1099a2dd95SBruce Richardson 
1199a2dd95SBruce Richardson #define MAX_BPF_STACK_SIZE	0x200
1299a2dd95SBruce Richardson 
1399a2dd95SBruce Richardson struct rte_bpf {
1499a2dd95SBruce Richardson 	struct rte_bpf_prm prm;
1599a2dd95SBruce Richardson 	struct rte_bpf_jit jit;
1699a2dd95SBruce Richardson 	size_t sz;
1799a2dd95SBruce Richardson 	uint32_t stack_sz;
1899a2dd95SBruce Richardson };
1999a2dd95SBruce Richardson 
20cf095b1eSJ.J. Martzki /*
21cf095b1eSJ.J. Martzki  * Use '__rte' prefix for non-static internal functions
22cf095b1eSJ.J. Martzki  * to avoid potential name conflict with other libraries.
23cf095b1eSJ.J. Martzki  */
2416bd1c62SThomas Monjalon int __rte_bpf_validate(struct rte_bpf *bpf);
2516bd1c62SThomas Monjalon int __rte_bpf_jit(struct rte_bpf *bpf);
2616bd1c62SThomas Monjalon int __rte_bpf_jit_x86(struct rte_bpf *bpf);
2716bd1c62SThomas Monjalon int __rte_bpf_jit_arm64(struct rte_bpf *bpf);
2899a2dd95SBruce Richardson 
2999a2dd95SBruce Richardson extern int rte_bpf_logtype;
300e21c7c0SDavid Marchand #define RTE_LOGTYPE_BPF rte_bpf_logtype
3199a2dd95SBruce Richardson 
32*0f1dc8cbSTyler Retzlaff #define RTE_BPF_LOG_LINE(lvl, ...) \
33*0f1dc8cbSTyler Retzlaff 	RTE_LOG_LINE(lvl, BPF, __VA_ARGS__)
3499a2dd95SBruce Richardson 
3599a2dd95SBruce Richardson static inline size_t
bpf_size(uint32_t bpf_op_sz)3699a2dd95SBruce Richardson bpf_size(uint32_t bpf_op_sz)
3799a2dd95SBruce Richardson {
3899a2dd95SBruce Richardson 	if (bpf_op_sz == BPF_B)
3999a2dd95SBruce Richardson 		return sizeof(uint8_t);
4099a2dd95SBruce Richardson 	else if (bpf_op_sz == BPF_H)
4199a2dd95SBruce Richardson 		return sizeof(uint16_t);
4299a2dd95SBruce Richardson 	else if (bpf_op_sz == BPF_W)
4399a2dd95SBruce Richardson 		return sizeof(uint32_t);
4499a2dd95SBruce Richardson 	else if (bpf_op_sz == EBPF_DW)
4599a2dd95SBruce Richardson 		return sizeof(uint64_t);
4699a2dd95SBruce Richardson 	return 0;
4799a2dd95SBruce Richardson }
4899a2dd95SBruce Richardson 
4963f39a43SDavid Marchand #endif /* BPF_IMPL_H */
50