+/* Get a pointer to an existing UMEM which overlays the rxq's mb_pool */
+static inline int
+get_shared_umem(struct pkt_rx_queue *rxq, const char *ifname,
+ struct xsk_umem_info **umem)
+{
+ struct internal_list *list;
+ struct pmd_internals *internals;
+ int i = 0, ret = 0;
+ struct rte_mempool *mb_pool = rxq->mb_pool;
+
+ if (mb_pool == NULL)
+ return ret;
+
+ pthread_mutex_lock(&internal_list_lock);
+
+ TAILQ_FOREACH(list, &internal_list, next) {
+ internals = list->eth_dev->data->dev_private;
+ for (i = 0; i < internals->queue_cnt; i++) {
+ struct pkt_rx_queue *list_rxq =
+ &internals->rx_queues[i];
+ if (rxq == list_rxq)
+ continue;
+ if (mb_pool == internals->rx_queues[i].mb_pool) {
+ if (ctx_exists(rxq, ifname, list_rxq,
+ internals->if_name)) {
+ ret = -1;
+ goto out;
+ }
+ if (__atomic_load_n(&internals->rx_queues[i].umem->refcnt,
+ __ATOMIC_ACQUIRE)) {
+ *umem = internals->rx_queues[i].umem;
+ goto out;
+ }
+ }
+ }
+ }
+
+out:
+ pthread_mutex_unlock(&internal_list_lock);
+
+ return ret;
+}
+
+static struct
+xsk_umem_info *xdp_umem_configure(struct pmd_internals *internals,
+ struct pkt_rx_queue *rxq)
+{
+ struct xsk_umem_info *umem = NULL;
+ int ret;
+ struct xsk_umem_config usr_config = {
+ .fill_size = ETH_AF_XDP_DFLT_NUM_DESCS * 2,
+ .comp_size = ETH_AF_XDP_DFLT_NUM_DESCS,
+ .flags = XDP_UMEM_UNALIGNED_CHUNK_FLAG};
+ void *base_addr = NULL;
+ struct rte_mempool *mb_pool = rxq->mb_pool;
+ uint64_t umem_size, align = 0;
+
+ if (internals->shared_umem) {
+ if (get_shared_umem(rxq, internals->if_name, &umem) < 0)
+ return NULL;
+
+ if (umem != NULL &&
+ __atomic_load_n(&umem->refcnt, __ATOMIC_ACQUIRE) <
+ umem->max_xsks) {
+ AF_XDP_LOG(INFO, "%s,qid%i sharing UMEM\n",
+ internals->if_name, rxq->xsk_queue_idx);
+ __atomic_fetch_add(&umem->refcnt, 1, __ATOMIC_ACQUIRE);
+ }
+ }
+
+ if (umem == NULL) {
+ usr_config.frame_size =
+ rte_mempool_calc_obj_size(mb_pool->elt_size,
+ mb_pool->flags, NULL);
+ usr_config.frame_headroom = mb_pool->header_size +
+ sizeof(struct rte_mbuf) +
+ rte_pktmbuf_priv_size(mb_pool) +
+ RTE_PKTMBUF_HEADROOM;
+
+ umem = rte_zmalloc_socket("umem", sizeof(*umem), 0,
+ rte_socket_id());
+ if (umem == NULL) {
+ AF_XDP_LOG(ERR, "Failed to allocate umem info");
+ return NULL;
+ }
+
+ umem->mb_pool = mb_pool;
+ base_addr = (void *)get_base_addr(mb_pool, &align);
+ umem_size = (uint64_t)mb_pool->populated_size *
+ (uint64_t)usr_config.frame_size +
+ align;
+
+ 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");
+ goto err;
+ }
+ umem->buffer = base_addr;
+
+ if (internals->shared_umem) {
+ umem->max_xsks = mb_pool->populated_size /
+ ETH_AF_XDP_NUM_BUFFERS;
+ AF_XDP_LOG(INFO, "Max xsks for UMEM %s: %u\n",
+ mb_pool->name, umem->max_xsks);
+ }
+
+ __atomic_store_n(&umem->refcnt, 1, __ATOMIC_RELEASE);
+ }
+
+ return umem;
+
+err:
+ xdp_umem_destroy(umem);
+ return NULL;
+}
+#else