1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 1982, 1986, 1990, 1993
3 * The Regents of the University of California.
4 * Copyright(c) 2018 Intel Corporation.
7 #ifndef _RTE_BPF_DEF_H_
8 #define _RTE_BPF_DEF_H_
13 * classic BPF (cBPF) and extended BPF (eBPF) related defines.
14 * For more information regarding cBPF and eBPF ISA and their differences,
16 * https://www.kernel.org/doc/Documentation/networking/filter.txt.
17 * As a rule of thumb for that file:
18 * all definitions used by both cBPF and eBPF start with bpf(BPF)_ prefix,
19 * while eBPF only ones start with ebpf(EBPF)) prefix.
30 * The instruction encodings.
33 /* Instruction classes */
34 #define BPF_CLASS(code) ((code) & 0x07)
44 #define EBPF_ALU64 0x07
47 #define BPF_SIZE(code) ((code) & 0x18)
53 #define BPF_MODE(code) ((code) & 0xe0)
61 #define EBPF_XADD 0xc0
64 #define BPF_OP(code) ((code) & 0xf0)
78 #define EBPF_ARSH 0xc0
88 #define EBPF_JSGT 0x60
89 #define EBPF_JSGE 0x70
90 #define EBPF_CALL 0x80
91 #define EBPF_EXIT 0x90
94 #define EBPF_JSLT 0xc0
95 #define EBPF_JSLE 0xd0
97 #define BPF_SRC(code) ((code) & 0x08)
101 /* if BPF_OP(code) == EBPF_END */
102 #define EBPF_TO_LE 0x00 /* convert to little-endian */
103 #define EBPF_TO_BE 0x08 /* convert to big-endian */
109 EBPF_REG_0, /* return value from internal function/for eBPF program */
110 EBPF_REG_1, /* 0-th argument to internal function */
111 EBPF_REG_2, /* 1-th argument to internal function */
112 EBPF_REG_3, /* 2-th argument to internal function */
113 EBPF_REG_4, /* 3-th argument to internal function */
114 EBPF_REG_5, /* 4-th argument to internal function */
115 EBPF_REG_6, /* callee saved register */
116 EBPF_REG_7, /* callee saved register */
117 EBPF_REG_8, /* callee saved register */
118 EBPF_REG_9, /* callee saved register */
119 EBPF_REG_10, /* stack pointer (read-only) */
124 * When EBPF_CALL instruction has src_reg == EBPF_PSEUDO_CALL,
125 * it should be treated as pseudo-call instruction, where
126 * imm value contains pc-relative offset to another EBPF function.
127 * Right now DPDK EBPF library doesn't support it.
129 #define EBPF_PSEUDO_CALL EBPF_REG_1
132 * eBPF instruction format
143 * eBPF allows functions with R1-R5 as arguments.
145 #define EBPF_FUNC_MAX_ARGS (EBPF_REG_6 - EBPF_REG_1)
151 #endif /* RTE_BPF_DEF_H_ */