From: Michael Baum Date: Tue, 19 Oct 2021 20:55:56 +0000 (+0300) Subject: net/mlx5: remove redundancy in MR file X-Git-Url: http://git.droids-corp.org/?a=commitdiff_plain;h=05fa53d6a09aaef846d520f7c972e8d6ae44ae92;p=dpdk.git net/mlx5: remove redundancy in MR file This patch remove two redundant things from MR file: 1. mr_find_contig_memsegs_data structure which is moved to common file before. 2. External memory mechanism - mlx5_tx_update_ext_mp function. Since commit [1] which added support for DMA map and unmap, external mem must be configured by the user using rte_mem_map function and no need to handle this in pmd. [1] commit 989e999d9305 ("net/mlx5: support PCI device DMA map and unmap") Signed-off-by: Michael Baum Acked-by: Matan Azrad --- diff --git a/drivers/net/mlx5/mlx5_mr.c b/drivers/net/mlx5/mlx5_mr.c index b53f905cf3..74bdecf36a 100644 --- a/drivers/net/mlx5/mlx5_mr.c +++ b/drivers/net/mlx5/mlx5_mr.c @@ -17,19 +17,6 @@ #include "mlx5_rx.h" #include "mlx5_tx.h" -struct mr_find_contig_memsegs_data { - uintptr_t addr; - uintptr_t start; - uintptr_t end; - const struct rte_memseg_list *msl; -}; - -struct mr_update_mp_data { - struct rte_eth_dev *dev; - struct mlx5_mr_ctrl *mr_ctrl; - int ret; -}; - /** * Callback for memory event. This can be called from both primary and secondary * process. @@ -134,70 +121,7 @@ mlx5_tx_mb2mr_bh(struct mlx5_txq_data *txq, struct rte_mbuf *mb) } /* Fallback for generic mechanism in corner cases. */ } - lkey = mlx5_tx_addr2mr_bh(txq, addr); - if (lkey == UINT32_MAX && rte_errno == ENXIO) { - /* Mempool may have externally allocated memory. */ - return mlx5_tx_update_ext_mp(txq, addr, mlx5_mb2mp(mb)); - } - return lkey; -} - -/** - * Called during rte_mempool_mem_iter() by mlx5_mr_update_ext_mp(). - * - * Externally allocated chunk is registered and a MR is created for the chunk. - * The MR object is added to the global list. If memseg list of a MR object - * (mr->msl) is null, the MR object can be regarded as externally allocated - * memory. - * - * Once external memory is registered, it should be static. If the memory is - * freed and the virtual address range has different physical memory mapped - * again, it may cause crash on device due to the wrong translation entry. PMD - * can't track the free event of the external memory for now. - */ -static void -mlx5_mr_update_ext_mp_cb(struct rte_mempool *mp, void *opaque, - struct rte_mempool_memhdr *memhdr, - unsigned mem_idx __rte_unused) -{ - struct mr_update_mp_data *data = opaque; - struct rte_eth_dev *dev = data->dev; - struct mlx5_priv *priv = dev->data->dev_private; - struct mlx5_dev_ctx_shared *sh = priv->sh; - struct mlx5_mr_ctrl *mr_ctrl = data->mr_ctrl; - struct mlx5_mr *mr = NULL; - uintptr_t addr = (uintptr_t)memhdr->addr; - size_t len = memhdr->len; - struct mr_cache_entry entry; - uint32_t lkey; - - MLX5_ASSERT(rte_eal_process_type() == RTE_PROC_PRIMARY); - /* If already registered, it should return. */ - rte_rwlock_read_lock(&sh->share_cache.rwlock); - lkey = mlx5_mr_lookup_cache(&sh->share_cache, &entry, addr); - rte_rwlock_read_unlock(&sh->share_cache.rwlock); - if (lkey != UINT32_MAX) - return; - DRV_LOG(DEBUG, "port %u register MR for chunk #%d of mempool (%s)", - dev->data->port_id, mem_idx, mp->name); - mr = mlx5_create_mr_ext(sh->cdev->pd, addr, len, mp->socket_id, - sh->share_cache.reg_mr_cb); - if (!mr) { - DRV_LOG(WARNING, - "port %u unable to allocate a new MR of" - " mempool (%s).", - dev->data->port_id, mp->name); - data->ret = -1; - return; - } - rte_rwlock_write_lock(&sh->share_cache.rwlock); - LIST_INSERT_HEAD(&sh->share_cache.mr_list, mr, mr); - /* Insert to the global cache table. */ - mlx5_mr_insert_cache(&sh->share_cache, mr); - rte_rwlock_write_unlock(&sh->share_cache.rwlock); - /* Insert to the local cache table */ - mlx5_mr_addr2mr_bh(sh->cdev->pd, &priv->mp_id, &sh->share_cache, - mr_ctrl, addr, sh->cdev->config.mr_ext_memseg_en); + return mlx5_tx_addr2mr_bh(txq, addr); } /** @@ -331,67 +255,3 @@ mlx5_net_dma_unmap(struct rte_device *rte_dev, void *addr, rte_rwlock_write_unlock(&sh->share_cache.rwlock); return 0; } - -/** - * Register MR for entire memory chunks in a Mempool having externally allocated - * memory and fill in local cache. - * - * @param dev - * Pointer to Ethernet device. - * @param mr_ctrl - * Pointer to per-queue MR control structure. - * @param mp - * Pointer to registering Mempool. - * - * @return - * 0 on success, -1 on failure. - */ -static uint32_t -mlx5_mr_update_ext_mp(struct rte_eth_dev *dev, struct mlx5_mr_ctrl *mr_ctrl, - struct rte_mempool *mp) -{ - struct mr_update_mp_data data = { - .dev = dev, - .mr_ctrl = mr_ctrl, - .ret = 0, - }; - - rte_mempool_mem_iter(mp, mlx5_mr_update_ext_mp_cb, &data); - return data.ret; -} - -/** - * Register MR entire memory chunks in a Mempool having externally allocated - * memory and search LKey of the address to return. - * - * @param dev - * Pointer to Ethernet device. - * @param addr - * Search key. - * @param mp - * Pointer to registering Mempool where addr belongs. - * - * @return - * LKey for address on success, UINT32_MAX on failure. - */ -uint32_t -mlx5_tx_update_ext_mp(struct mlx5_txq_data *txq, uintptr_t addr, - struct rte_mempool *mp) -{ - struct mlx5_txq_ctrl *txq_ctrl = - container_of(txq, struct mlx5_txq_ctrl, txq); - struct mlx5_mr_ctrl *mr_ctrl = &txq->mr_ctrl; - struct mlx5_priv *priv = txq_ctrl->priv; - - if (rte_eal_process_type() != RTE_PROC_PRIMARY) { - DRV_LOG(WARNING, - "port %u using address (%p) from unregistered mempool" - " having externally allocated memory" - " in secondary process, please create mempool" - " prior to rte_eth_dev_start()", - PORT_ID(priv), (void *)addr); - return UINT32_MAX; - } - mlx5_mr_update_ext_mp(ETH_DEV(priv), mr_ctrl, mp); - return mlx5_tx_addr2mr_bh(txq, addr); -} diff --git a/drivers/net/mlx5/mlx5_tx.h b/drivers/net/mlx5/mlx5_tx.h index e722738682..cdbcf659df 100644 --- a/drivers/net/mlx5/mlx5_tx.h +++ b/drivers/net/mlx5/mlx5_tx.h @@ -239,8 +239,6 @@ int mlx5_tx_burst_mode_get(struct rte_eth_dev *dev, uint16_t tx_queue_id, /* mlx5_mr.c */ uint32_t mlx5_tx_mb2mr_bh(struct mlx5_txq_data *txq, struct rte_mbuf *mb); -uint32_t mlx5_tx_update_ext_mp(struct mlx5_txq_data *txq, uintptr_t addr, - struct rte_mempool *mp); /* mlx5_tx_empw.c */