#include <linux/ethtool.h>
#include <linux/sockios.h>
#include "af_xdp_deps.h"
-#include <bpf/bpf.h>
#include <rte_ethdev.h>
#include <ethdev_driver.h>
umem = rte_zmalloc_socket("umem", sizeof(*umem), 0,
rte_socket_id());
if (umem == NULL) {
- AF_XDP_LOG(ERR, "Failed to allocate umem info");
+ AF_XDP_LOG(ERR, "Failed to allocate umem info\n");
return NULL;
}
ret = xsk_umem__create(&umem->umem, base_addr, umem_size,
&rxq->fq, &rxq->cq, &usr_config);
if (ret) {
- AF_XDP_LOG(ERR, "Failed to create umem");
+ AF_XDP_LOG(ERR, "Failed to create umem\n");
goto err;
}
umem->buffer = base_addr;
umem = rte_zmalloc_socket("umem", sizeof(*umem), 0, rte_socket_id());
if (umem == NULL) {
- AF_XDP_LOG(ERR, "Failed to allocate umem info");
+ AF_XDP_LOG(ERR, "Failed to allocate umem info\n");
return NULL;
}
&usr_config);
if (ret) {
- AF_XDP_LOG(ERR, "Failed to create umem");
+ AF_XDP_LOG(ERR, "Failed to create umem\n");
goto err;
}
umem->mz = mz;
static int
load_custom_xdp_prog(const char *prog_path, int if_index, struct bpf_map **map)
{
- int ret, prog_fd = -1;
+ int ret, prog_fd;
struct bpf_object *obj;
- ret = bpf_prog_load(prog_path, BPF_PROG_TYPE_XDP, &obj, &prog_fd);
- if (ret) {
+ prog_fd = load_program(prog_path, &obj);
+ if (prog_fd < 0) {
AF_XDP_LOG(ERR, "Failed to load program %s\n", prog_path);
- return ret;
+ return -1;
}
/*
return -ENOMEM;
txq->umem = rxq->umem;
+#if defined(XDP_UMEM_UNALIGNED_CHUNK_FLAG)
+ ret = rte_pktmbuf_alloc_bulk(rxq->umem->mb_pool, fq_bufs, reserve_size);
+ if (ret) {
+ AF_XDP_LOG(DEBUG, "Failed to get enough buffers for fq.\n");
+ goto out_umem;
+ }
+#endif
+
+ ret = reserve_fill_queue(rxq->umem, reserve_size, fq_bufs, &rxq->fq);
+ if (ret) {
+ AF_XDP_LOG(ERR, "Failed to reserve fill queue.\n");
+ goto out_umem;
+ }
+
cfg.rx_size = ring_size;
cfg.tx_size = ring_size;
cfg.libbpf_flags = 0;
if (ret) {
AF_XDP_LOG(ERR, "Failed to load custom XDP program %s\n",
internals->prog_path);
- goto err;
+ goto out_umem;
}
internals->custom_prog_configured = 1;
cfg.libbpf_flags = XSK_LIBBPF_FLAGS__INHIBIT_PROG_LOAD;
if (ret) {
AF_XDP_LOG(ERR, "Failed to create xsk socket.\n");
- goto err;
+ goto out_umem;
}
/* insert the xsk into the xsks_map */
&rxq->xsk_queue_idx, &fd, 0);
if (err) {
AF_XDP_LOG(ERR, "Failed to insert xsk in map.\n");
- goto err;
+ goto out_xsk;
}
}
-#if defined(XDP_UMEM_UNALIGNED_CHUNK_FLAG)
- ret = rte_pktmbuf_alloc_bulk(rxq->umem->mb_pool, fq_bufs, reserve_size);
- if (ret) {
- AF_XDP_LOG(DEBUG, "Failed to get enough buffers for fq.\n");
- goto err;
- }
-#endif
-
if (rxq->busy_budget) {
ret = configure_preferred_busy_poll(rxq);
if (ret) {
AF_XDP_LOG(ERR, "Failed configure busy polling.\n");
- goto err;
+ goto out_xsk;
}
}
- ret = reserve_fill_queue(rxq->umem, reserve_size, fq_bufs, &rxq->fq);
- if (ret) {
- xsk_socket__delete(rxq->xsk);
- AF_XDP_LOG(ERR, "Failed to reserve fill queue.\n");
- goto err;
- }
-
return 0;
-err:
+out_xsk:
+ xsk_socket__delete(rxq->xsk);
+out_umem:
if (__atomic_sub_fetch(&rxq->umem->refcnt, 1, __ATOMIC_ACQUIRE) == 0)
xdp_umem_destroy(rxq->umem);
AF_XDP_LOG(DEBUG, "Sending multi-process IPC request for %s\n", name);
ret = rte_mp_request_sync(&request, &replies, &timeout);
if (ret < 0 || replies.nb_received != 1) {
- AF_XDP_LOG(ERR, "Failed to request fds from primary: %d",
+ AF_XDP_LOG(ERR, "Failed to request fds from primary: %d\n",
rte_errno);
return -1;
}
return 0;
}
-/* Secondary process rx function. RX is disabled because memory mapping of the
- * rings being assigned by the kernel in the primary process only.
- */
-static uint16_t
-eth_af_xdp_rx_noop(void *queue __rte_unused,
- struct rte_mbuf **bufs __rte_unused,
- uint16_t nb_pkts __rte_unused)
-{
- return 0;
-}
-
-/* Secondary process tx function. TX is disabled because memory mapping of the
- * rings being assigned by the kernel in the primary process only.
- */
-static uint16_t
-eth_af_xdp_tx_noop(void *queue __rte_unused,
- struct rte_mbuf **bufs __rte_unused,
- uint16_t nb_pkts __rte_unused)
-{
- return 0;
-}
-
static int
rte_pmd_af_xdp_probe(struct rte_vdev_device *dev)
{
}
eth_dev->dev_ops = &ops;
eth_dev->device = &dev->device;
- eth_dev->rx_pkt_burst = eth_af_xdp_rx_noop;
- eth_dev->tx_pkt_burst = eth_af_xdp_tx_noop;
+ eth_dev->rx_pkt_burst = rte_eth_pkt_burst_dummy;
+ eth_dev->tx_pkt_burst = rte_eth_pkt_burst_dummy;
eth_dev->process_private = (struct pmd_process_private *)
rte_zmalloc_socket(name,
sizeof(struct pmd_process_private),
/* Register IPC callback which shares xsk fds from primary to secondary */
if (!afxdp_dev_count) {
ret = rte_mp_action_register(ETH_AF_XDP_MP_KEY, afxdp_mp_send_fds);
- if (ret < 0) {
- AF_XDP_LOG(ERR, "%s: Failed to register multi-process IPC callback: %s",
+ if (ret < 0 && rte_errno != ENOTSUP) {
+ AF_XDP_LOG(ERR, "%s: Failed to register multi-process IPC callback: %s\n",
name, strerror(rte_errno));
return -1;
}