net/mlx5: support queue/RSS actions for external Rx queue
[dpdk.git] / drivers / net / af_xdp / compat.h
index bf40c65..28ea64a 100644 (file)
@@ -7,6 +7,7 @@
 #else
 #include <bpf/xsk.h>
 #endif
+#include <bpf/bpf.h>
 #include <linux/version.h>
 #include <poll.h>
 
@@ -58,3 +59,41 @@ tx_syscall_needed(struct xsk_ring_prod *q __rte_unused)
        return 1;
 }
 #endif
+
+#ifdef RTE_NET_AF_XDP_LIBBPF_OBJ_OPEN
+static int load_program(const char *prog_path, struct bpf_object **obj)
+{
+       struct bpf_program *prog;
+       int err;
+
+       *obj = bpf_object__open_file(prog_path, NULL);
+       err = libbpf_get_error(*obj);
+       if (err)
+               return -1;
+
+       err = bpf_object__load(*obj);
+       if (err)
+               goto out;
+
+       prog = bpf_object__next_program(*obj, NULL);
+       if (!prog)
+               goto out;
+
+       return bpf_program__fd(prog);
+
+out:
+       bpf_object__close(*obj);
+       return -1;
+}
+#else
+static int load_program(const char *prog_path, struct bpf_object **obj)
+{
+       int ret, prog_fd;
+
+       ret = bpf_prog_load(prog_path, BPF_PROG_TYPE_XDP, obj, &prog_fd);
+       if (ret)
+               return -1;
+
+       return prog_fd;
+}
+#endif