xref: /dpdk/lib/bpf/rte_bpf_ethdev.h (revision 23f3dac43237d5de18f9544c6e3f932c70c39e27)
199a2dd95SBruce Richardson /* SPDX-License-Identifier: BSD-3-Clause
299a2dd95SBruce Richardson  * Copyright(c) 2018 Intel Corporation
399a2dd95SBruce Richardson  */
499a2dd95SBruce Richardson 
599a2dd95SBruce Richardson #ifndef _RTE_BPF_ETHDEV_H_
699a2dd95SBruce Richardson #define _RTE_BPF_ETHDEV_H_
799a2dd95SBruce Richardson 
899a2dd95SBruce Richardson /**
999a2dd95SBruce Richardson  * @file rte_bpf_ethdev.h
1099a2dd95SBruce Richardson  *
1199a2dd95SBruce Richardson  * API to install BPF filter as RX/TX callbacks for eth devices.
1299a2dd95SBruce Richardson  * Note that right now:
1399a2dd95SBruce Richardson  * - it is not MT safe, i.e. it is not allowed to do load/unload for the
1499a2dd95SBruce Richardson  *   same port/queue from different threads in parallel.
1599a2dd95SBruce Richardson  * - though it allows to do load/unload at runtime
1699a2dd95SBruce Richardson  *   (while RX/TX is ongoing on given port/queue).
1799a2dd95SBruce Richardson  * - allows only one BPF program per port/queue,
1899a2dd95SBruce Richardson  * i.e. new load will replace previously loaded for that port/queue BPF program.
1999a2dd95SBruce Richardson  * Filter behaviour - if BPF program returns zero value for a given packet,
2099a2dd95SBruce Richardson  * then it will be dropped inside callback and no further processing
2199a2dd95SBruce Richardson  *   on RX - it will be dropped inside callback and no further processing
2299a2dd95SBruce Richardson  *   for that packet will happen.
2399a2dd95SBruce Richardson  *   on TX - packet will remain unsent, and it is responsibility of the user
2499a2dd95SBruce Richardson  *   to handle such situation (drop, try to send again, etc.).
2599a2dd95SBruce Richardson  */
2699a2dd95SBruce Richardson 
2799a2dd95SBruce Richardson #include <rte_bpf.h>
2899a2dd95SBruce Richardson 
2999a2dd95SBruce Richardson #ifdef __cplusplus
3099a2dd95SBruce Richardson extern "C" {
3199a2dd95SBruce Richardson #endif
3299a2dd95SBruce Richardson 
3399a2dd95SBruce Richardson enum {
3499a2dd95SBruce Richardson 	RTE_BPF_ETH_F_NONE = 0,
3599a2dd95SBruce Richardson 	RTE_BPF_ETH_F_JIT  = 0x1, /*< use compiled into native ISA code */
3699a2dd95SBruce Richardson };
3799a2dd95SBruce Richardson 
3899a2dd95SBruce Richardson /**
3999a2dd95SBruce Richardson  * Unload previously loaded BPF program (if any) from given RX port/queue
4099a2dd95SBruce Richardson  * and remove appropriate RX port/queue callback.
4199a2dd95SBruce Richardson  *
4299a2dd95SBruce Richardson  * @param port
4399a2dd95SBruce Richardson  *   The identifier of the ethernet port
4499a2dd95SBruce Richardson  * @param queue
4599a2dd95SBruce Richardson  *   The identifier of the RX queue on the given port
4699a2dd95SBruce Richardson  */
4799a2dd95SBruce Richardson void
4899a2dd95SBruce Richardson rte_bpf_eth_rx_unload(uint16_t port, uint16_t queue);
4999a2dd95SBruce Richardson 
5099a2dd95SBruce Richardson /**
5199a2dd95SBruce Richardson  * Unload previously loaded BPF program (if any) from given TX port/queue
5299a2dd95SBruce Richardson  * and remove appropriate TX port/queue callback.
5399a2dd95SBruce Richardson  *
5499a2dd95SBruce Richardson  * @param port
5599a2dd95SBruce Richardson  *   The identifier of the ethernet port
5699a2dd95SBruce Richardson  * @param queue
5799a2dd95SBruce Richardson  *   The identifier of the TX queue on the given port
5899a2dd95SBruce Richardson  */
5999a2dd95SBruce Richardson void
6099a2dd95SBruce Richardson rte_bpf_eth_tx_unload(uint16_t port, uint16_t queue);
6199a2dd95SBruce Richardson 
6299a2dd95SBruce Richardson /**
6399a2dd95SBruce Richardson  * Load BPF program from the ELF file and install callback to execute it
6499a2dd95SBruce Richardson  * on given RX port/queue.
6599a2dd95SBruce Richardson  *
6699a2dd95SBruce Richardson  * @param port
6799a2dd95SBruce Richardson  *   The identifier of the ethernet port
6899a2dd95SBruce Richardson  * @param queue
6999a2dd95SBruce Richardson  *   The identifier of the RX queue on the given port
7099a2dd95SBruce Richardson  * @param fname
7199a2dd95SBruce Richardson  *  Pathname for a ELF file.
7299a2dd95SBruce Richardson  * @param sname
7399a2dd95SBruce Richardson  *  Name of the executable section within the file to load.
7499a2dd95SBruce Richardson  * @param prm
7599a2dd95SBruce Richardson  *  Parameters used to create and initialise the BPF execution context.
7699a2dd95SBruce Richardson  * @param flags
7799a2dd95SBruce Richardson  *  Flags that define expected behavior of the loaded filter
7899a2dd95SBruce Richardson  *  (i.e. jited/non-jited version to use).
7999a2dd95SBruce Richardson  * @return
8099a2dd95SBruce Richardson  *   Zero on successful completion or negative error code otherwise.
8199a2dd95SBruce Richardson  */
8299a2dd95SBruce Richardson int
8399a2dd95SBruce Richardson rte_bpf_eth_rx_elf_load(uint16_t port, uint16_t queue,
8499a2dd95SBruce Richardson 	const struct rte_bpf_prm *prm, const char *fname, const char *sname,
8599a2dd95SBruce Richardson 	uint32_t flags);
8699a2dd95SBruce Richardson 
8799a2dd95SBruce Richardson /**
8899a2dd95SBruce Richardson  * Load BPF program from the ELF file and install callback to execute it
8999a2dd95SBruce Richardson  * on given TX port/queue.
9099a2dd95SBruce Richardson  *
9199a2dd95SBruce Richardson  * @param port
9299a2dd95SBruce Richardson  *   The identifier of the ethernet port
9399a2dd95SBruce Richardson  * @param queue
9499a2dd95SBruce Richardson  *   The identifier of the TX queue on the given port
9599a2dd95SBruce Richardson  * @param fname
9699a2dd95SBruce Richardson  *  Pathname for a ELF file.
9799a2dd95SBruce Richardson  * @param sname
9899a2dd95SBruce Richardson  *  Name of the executable section within the file to load.
9999a2dd95SBruce Richardson  * @param prm
10099a2dd95SBruce Richardson  *  Parameters used to create and initialise the BPF execution context.
10199a2dd95SBruce Richardson  * @param flags
102*23f3dac4SStephen Hemminger  *  Flags that define expected behavior of the loaded filter
10399a2dd95SBruce Richardson  *  (i.e. jited/non-jited version to use).
10499a2dd95SBruce Richardson  * @return
10599a2dd95SBruce Richardson  *   Zero on successful completion or negative error code otherwise.
10699a2dd95SBruce Richardson  */
10799a2dd95SBruce Richardson int
10899a2dd95SBruce Richardson rte_bpf_eth_tx_elf_load(uint16_t port, uint16_t queue,
10999a2dd95SBruce Richardson 	const struct rte_bpf_prm *prm, const char *fname, const char *sname,
11099a2dd95SBruce Richardson 	uint32_t flags);
11199a2dd95SBruce Richardson 
11299a2dd95SBruce Richardson #ifdef __cplusplus
11399a2dd95SBruce Richardson }
11499a2dd95SBruce Richardson #endif
11599a2dd95SBruce Richardson 
11699a2dd95SBruce Richardson #endif /* _RTE_BPF_ETHDEV_H_ */
117