From patchwork Mon Jan 20 17:02:40 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matan Azrad X-Patchwork-Id: 64939 X-Patchwork-Delegate: maxime.coquelin@redhat.com Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from dpdk.org (dpdk.org [92.243.14.124]) by inbox.dpdk.org (Postfix) with ESMTP id E752AA0526; Mon, 20 Jan 2020 18:03:27 +0100 (CET) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 4425A1BF87; Mon, 20 Jan 2020 18:03:20 +0100 (CET) Received: from mellanox.co.il (mail-il-dmz.mellanox.com [193.47.165.129]) by dpdk.org (Postfix) with ESMTP id 0BFC71BF71 for ; Mon, 20 Jan 2020 18:03:13 +0100 (CET) Received: from Internal Mail-Server by MTLPINE1 (envelope-from asafp@mellanox.com) with ESMTPS (AES256-SHA encrypted); 20 Jan 2020 19:03:12 +0200 Received: from pegasus07.mtr.labs.mlnx (pegasus07.mtr.labs.mlnx [10.210.16.112]) by labmailer.mlnx (8.13.8/8.13.8) with ESMTP id 00KH3BGR024424; Mon, 20 Jan 2020 19:03:12 +0200 From: Matan Azrad To: dev@dpdk.org Cc: Maxime Coquelin , Thomas Monjalon Date: Mon, 20 Jan 2020 17:02:40 +0000 Message-Id: <1579539790-3882-9-git-send-email-matan@mellanox.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1579539790-3882-1-git-send-email-matan@mellanox.com> References: <1579539790-3882-1-git-send-email-matan@mellanox.com> Subject: [dpdk-dev] [PATCH v1 08/38] vdpa/mlx5: support queues number operation X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" Support get_queue_num operation to get the maximum number of queues supported by the device. This number comes from the DevX capabilities. Signed-off-by: Matan Azrad --- drivers/vdpa/mlx5/mlx5_vdpa.c | 54 ++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 53 insertions(+), 1 deletion(-) diff --git a/drivers/vdpa/mlx5/mlx5_vdpa.c b/drivers/vdpa/mlx5/mlx5_vdpa.c index cb49a32..32ca908 100644 --- a/drivers/vdpa/mlx5/mlx5_vdpa.c +++ b/drivers/vdpa/mlx5/mlx5_vdpa.c @@ -9,6 +9,7 @@ #include #include +#include #include "mlx5_vdpa_utils.h" @@ -18,6 +19,7 @@ struct mlx5_vdpa_priv { int id; /* vDPA device id. */ struct ibv_context *ctx; /* Device context. */ struct rte_vdpa_dev_addr dev_addr; + struct mlx5_hca_vdpa_attr caps; }; TAILQ_HEAD(mlx5_vdpa_privs, mlx5_vdpa_priv) priv_list = @@ -25,8 +27,43 @@ struct mlx5_vdpa_priv { static pthread_mutex_t priv_list_lock = PTHREAD_MUTEX_INITIALIZER; int mlx5_vdpa_logtype; +static struct mlx5_vdpa_priv * +mlx5_vdpa_find_priv_resource_by_did(int did) +{ + struct mlx5_vdpa_priv *priv; + int found = 0; + + pthread_mutex_lock(&priv_list_lock); + TAILQ_FOREACH(priv, &priv_list, next) { + if (did == priv->id) { + found = 1; + break; + } + } + pthread_mutex_unlock(&priv_list_lock); + if (!found) { + DRV_LOG(ERR, "Invalid device id: %d.", did); + rte_errno = EINVAL; + return NULL; + } + return priv; +} + +static int +mlx5_vdpa_get_queue_num(int did, uint32_t *queue_num) +{ + struct mlx5_vdpa_priv *priv = mlx5_vdpa_find_priv_resource_by_did(did); + + if (priv == NULL) { + DRV_LOG(ERR, "Invalid device id: %d.", did); + return -1; + } + *queue_num = priv->caps.max_num_virtio_queues; + return 0; +} + static struct rte_vdpa_dev_ops mlx5_vdpa_ops = { - .get_queue_num = NULL, + .get_queue_num = mlx5_vdpa_get_queue_num, .get_features = NULL, .get_protocol_features = NULL, .dev_conf = NULL, @@ -60,6 +97,7 @@ struct mlx5_vdpa_priv { struct ibv_device *ibv_match = NULL; struct mlx5_vdpa_priv *priv = NULL; struct ibv_context *ctx; + struct mlx5_hca_attr attr; int ret; errno = 0; @@ -107,6 +145,20 @@ struct mlx5_vdpa_priv { rte_errno = ENOMEM; goto error; } + ret = mlx5_devx_cmd_query_hca_attr(ctx, &attr); + if (ret) { + DRV_LOG(ERR, "Unable to read HCA capabilities."); + rte_errno = ENOTSUP; + goto error; + } else { + if (!attr.vdpa.valid || !attr.vdpa.max_num_virtio_queues) { + DRV_LOG(ERR, "Not enough capabilities to support vdpa," + " maybe old FW/OFED version?"); + rte_errno = ENOTSUP; + goto error; + } + priv->caps = attr.vdpa; + } priv->ctx = ctx; priv->dev_addr.pci_addr = pci_dev->addr; priv->dev_addr.type = PCI_ADDR;