doc: announce API change for mempool IOVA populate
[dpdk.git] / lib / librte_bpf / bpf.c
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2018 Intel Corporation
3  */
4
5 #include <stdarg.h>
6 #include <stdio.h>
7 #include <string.h>
8 #include <errno.h>
9 #include <stdint.h>
10 #include <inttypes.h>
11
12 #include <rte_common.h>
13 #include <rte_eal.h>
14
15 #include "bpf_impl.h"
16
17 int rte_bpf_logtype;
18
19 void
20 rte_bpf_destroy(struct rte_bpf *bpf)
21 {
22         if (bpf != NULL) {
23                 if (bpf->jit.func != NULL)
24                         munmap(bpf->jit.func, bpf->jit.sz);
25                 munmap(bpf, bpf->sz);
26         }
27 }
28
29 int
30 rte_bpf_get_jit(const struct rte_bpf *bpf, struct rte_bpf_jit *jit)
31 {
32         if (bpf == NULL || jit == NULL)
33                 return -EINVAL;
34
35         jit[0] = bpf->jit;
36         return 0;
37 }
38
39 int
40 bpf_jit(struct rte_bpf *bpf)
41 {
42         int32_t rc;
43
44 #if defined(RTE_ARCH_X86_64)
45         rc = bpf_jit_x86(bpf);
46 #elif defined(RTE_ARCH_ARM64)
47         rc = bpf_jit_arm64(bpf);
48 #else
49         rc = -ENOTSUP;
50 #endif
51
52         if (rc != 0)
53                 RTE_BPF_LOG(WARNING, "%s(%p) failed, error code: %d;\n",
54                         __func__, bpf, rc);
55         return rc;
56 }
57
58 RTE_INIT(rte_bpf_init_log)
59 {
60         rte_bpf_logtype = rte_log_register("lib.bpf");
61         if (rte_bpf_logtype >= 0)
62                 rte_log_set_level(rte_bpf_logtype, RTE_LOG_INFO);
63 }