b4d4d3b16d7d287d3a8f4fc0d76563de7b9fb9fe
[dpdk.git] / lib / librte_bpf / rte_bpf_ethdev.h
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2018 Intel Corporation
3  */
4
5 #ifndef _RTE_BPF_ETHDEV_H_
6 #define _RTE_BPF_ETHDEV_H_
7
8 /**
9  * @file
10  *
11  * API to install BPF filter as RX/TX callbacks for eth devices.
12  * Note that right now:
13  * - it is not MT safe, i.e. it is not allowed to do load/unload for the
14  *   same port/queue from different threads in parallel.
15  * - though it allows to do load/unload at runtime
16  *   (while RX/TX is ongoing on given port/queue).
17  * - allows only one BPF program per port/queue,
18  * i.e. new load will replace previously loaded for that port/queue BPF program.
19  * Filter behaviour - if BPF program returns zero value for a given packet,
20  * then it will be dropped inside callback and no further processing
21  *   on RX - it will be dropped inside callback and no further processing
22  *   for that packet will happen.
23  *   on TX - packet will remain unsent, and it is responsibility of the user
24  *   to handle such situation (drop, try to send again, etc.).
25  */
26
27 #include <rte_bpf.h>
28
29 #ifdef __cplusplus
30 extern "C" {
31 #endif
32
33 enum {
34         RTE_BPF_ETH_F_NONE = 0,
35         RTE_BPF_ETH_F_JIT  = 0x1, /*< use compiled into native ISA code */
36 };
37
38 /**
39  * Unload previously loaded BPF program (if any) from given RX port/queue
40  * and remove appropriate RX port/queue callback.
41  *
42  * @param port
43  *   The identifier of the ethernet port
44  * @param queue
45  *   The identifier of the RX queue on the given port
46  */
47 void rte_bpf_eth_rx_unload(uint16_t port, uint16_t queue);
48
49 /**
50  * Unload previously loaded BPF program (if any) from given TX port/queue
51  * and remove appropriate TX port/queue callback.
52  *
53  * @param port
54  *   The identifier of the ethernet port
55  * @param queue
56  *   The identifier of the TX queue on the given port
57  */
58 void rte_bpf_eth_tx_unload(uint16_t port, uint16_t queue);
59
60 /**
61  * Load BPF program from the ELF file and install callback to execute it
62  * on given RX port/queue.
63  *
64  * @param port
65  *   The identifier of the ethernet port
66  * @param queue
67  *   The identifier of the RX queue on the given port
68  * @param fname
69  *  Pathname for a ELF file.
70  * @param sname
71  *  Name of the executable section within the file to load.
72  * @param prm
73  *  Parameters used to create and initialise the BPF exeution context.
74  * @param flags
75  *  Flags that define expected expected behavior of the loaded filter
76  *  (i.e. jited/non-jited version to use).
77  * @return
78  *   Zero on successful completion or negative error code otherwise.
79  */
80 int rte_bpf_eth_rx_elf_load(uint16_t port, uint16_t queue,
81         const struct rte_bpf_prm *prm, const char *fname, const char *sname,
82         uint32_t flags);
83
84 /**
85  * Load BPF program from the ELF file and install callback to execute it
86  * on given TX port/queue.
87  *
88  * @param port
89  *   The identifier of the ethernet port
90  * @param queue
91  *   The identifier of the TX queue on the given port
92  * @param fname
93  *  Pathname for a ELF file.
94  * @param sname
95  *  Name of the executable section within the file to load.
96  * @param prm
97  *  Parameters used to create and initialise the BPF exeution context.
98  * @param flags
99  *  Flags that define expected expected behavior of the loaded filter
100  *  (i.e. jited/non-jited version to use).
101  * @return
102  *   Zero on successful completion or negative error code otherwise.
103  */
104 int rte_bpf_eth_tx_elf_load(uint16_t port, uint16_t queue,
105         const struct rte_bpf_prm *prm, const char *fname, const char *sname,
106         uint32_t flags);
107
108 #ifdef __cplusplus
109 }
110 #endif
111
112 #endif /* _RTE_BPF_ETHDEV_H_ */