From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 0EA1DA00C2; Fri, 1 Jul 2022 11:03:18 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 930AF4284D; Fri, 1 Jul 2022 11:03:06 +0200 (CEST) Received: from linux.microsoft.com (linux.microsoft.com [13.77.154.182]) by mails.dpdk.org (Postfix) with ESMTP id 5671042670 for ; Fri, 1 Jul 2022 11:03:04 +0200 (CEST) Received: by linux.microsoft.com (Postfix, from userid 1004) id ABB3D20D5906; Fri, 1 Jul 2022 02:03:03 -0700 (PDT) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com ABB3D20D5906 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxonhyperv.com; s=default; t=1656666183; bh=qv1V20I7DwO8wxob5/bIKItLq/37U9CyUtMkoulLG3s=; h=From:To:Cc:Subject:Date:In-Reply-To:References:Reply-To:From; b=czFooDAvWeq2xRlintr+NY81PjBJw+LS0Sm56tFSxj1FmTu/6fj2Yoq2n18DYMtQh 3879l+0SvItyWpICegP/7yrsLoR2scFa0Qr8zP0zY472UqaQ16Pq0eDdlxhg0guX8r jBDafL+jA5JK6meiWoXs9a+z9E22JP6Jvy3LIfJw= From: longli@linuxonhyperv.com To: Ferruh Yigit Cc: dev@dpdk.org, Ajay Sharma , Stephen Hemminger , Long Li Subject: [PATCH 02/17] net/mana: add device configuration and stop Date: Fri, 1 Jul 2022 02:02:32 -0700 Message-Id: <1656666167-26035-3-git-send-email-longli@linuxonhyperv.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1656666167-26035-1-git-send-email-longli@linuxonhyperv.com> References: <1656666167-26035-1-git-send-email-longli@linuxonhyperv.com> X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: longli@microsoft.com Errors-To: dev-bounces@dpdk.org From: Long Li MANA defines its memory allocation functions to override IB layer default functions to allocate device queues. This patch adds the code for device configuration and stop. Signed-off-by: Long Li --- drivers/net/mana/mana.c | 87 ++++++++++++++++++++++++++++++++++++++++- drivers/net/mana/mana.h | 3 -- 2 files changed, 85 insertions(+), 5 deletions(-) diff --git a/drivers/net/mana/mana.c b/drivers/net/mana/mana.c index 893e2b1e23..882a38d7df 100644 --- a/drivers/net/mana/mana.c +++ b/drivers/net/mana/mana.c @@ -57,7 +57,91 @@ static rte_spinlock_t mana_shared_data_lock = RTE_SPINLOCK_INITIALIZER; int mana_logtype_driver; int mana_logtype_init; +static void *mana_alloc_verbs_buf(size_t size, void *data) +{ + void *ret; + size_t alignment = rte_mem_page_size(); + int socket = (int)(uintptr_t)data; + + DRV_LOG(DEBUG, "size=%lu socket=%d", size, socket); + + if (alignment == (size_t)-1) { + DRV_LOG(ERR, "Failed to get mem page size"); + rte_errno = ENOMEM; + return NULL; + } + + ret = rte_zmalloc_socket("mana_verb_buf", size, alignment, socket); + if (!ret && size) + rte_errno = ENOMEM; + return ret; +} + +static void mana_free_verbs_buf(void *ptr, void *data __rte_unused) +{ + rte_free(ptr); +} + +static int mana_dev_configure(struct rte_eth_dev *dev) +{ + struct mana_priv *priv = dev->data->dev_private; + struct rte_eth_conf *dev_conf = &dev->data->dev_conf; + const struct rte_eth_rxmode *rxmode = &dev_conf->rxmode; + const struct rte_eth_txmode *txmode = &dev_conf->txmode; + + if (dev_conf->rxmode.mq_mode & ETH_MQ_RX_RSS_FLAG) + dev_conf->rxmode.offloads |= DEV_RX_OFFLOAD_RSS_HASH; + + if (txmode->offloads & ~BNIC_DEV_TX_OFFLOAD_SUPPORT) { + DRV_LOG(ERR, "Unsupported TX offload: %lx", txmode->offloads); + return -EINVAL; + } + + if (rxmode->offloads & ~BNIC_DEV_RX_OFFLOAD_SUPPORT) { + DRV_LOG(ERR, "Unsupported RX offload: %lx", rxmode->offloads); + return -EINVAL; + } + + if (dev->data->nb_rx_queues != dev->data->nb_tx_queues) { + DRV_LOG(ERR, "Only support equal number of rx/tx queues"); + return -EINVAL; + } + + if (!rte_is_power_of_2(dev->data->nb_rx_queues)) { + DRV_LOG(ERR, "number of TX/RX queues must be power of 2"); + return -EINVAL; + } + + priv->num_queues = dev->data->nb_rx_queues; + + manadv_set_context_attr(priv->ib_ctx, MANADV_CTX_ATTR_BUF_ALLOCATORS, + (void *)((uintptr_t)&(struct manadv_ctx_allocators){ + .alloc = &mana_alloc_verbs_buf, + .free = &mana_free_verbs_buf, + .data = 0, + })); + + return 0; +} + +static int +mana_dev_close(struct rte_eth_dev *dev) +{ + struct mana_priv *priv = dev->data->dev_private; + int ret; + + ret = ibv_close_device(priv->ib_ctx); + if (ret) { + ret = errno; + return ret; + } + + return 0; +} + const struct eth_dev_ops mana_dev_ops = { + .dev_configure = mana_dev_configure, + .dev_close = mana_dev_close, }; const struct eth_dev_ops mana_dev_sec_ops = { @@ -652,8 +736,7 @@ static int mana_pci_probe(struct rte_pci_driver *pci_drv __rte_unused, static int mana_dev_uninit(struct rte_eth_dev *dev) { - RTE_SET_USED(dev); - return 0; + return mana_dev_close(dev); } static int mana_pci_remove(struct rte_pci_device *pci_dev) diff --git a/drivers/net/mana/mana.h b/drivers/net/mana/mana.h index dbef5420ff..9609bee4de 100644 --- a/drivers/net/mana/mana.h +++ b/drivers/net/mana/mana.h @@ -177,9 +177,6 @@ uint16_t mana_rx_burst_removed(void *dpdk_rxq, struct rte_mbuf **pkts, uint16_t mana_tx_burst_removed(void *dpdk_rxq, struct rte_mbuf **pkts, uint16_t pkts_n); -void *mana_alloc_verbs_buf(size_t size, void *data); -void mana_free_verbs_buf(void *ptr, void *data); - /** Request timeout for IPC. */ #define MANA_MP_REQ_TIMEOUT_SEC 5 -- 2.17.1