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 18BD7A0560; Tue, 18 Oct 2022 08:24:27 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 03EFB4281A; Tue, 18 Oct 2022 08:23:57 +0200 (CEST) Received: from mga12.intel.com (mga12.intel.com [192.55.52.136]) by mails.dpdk.org (Postfix) with ESMTP id 0436D42829 for ; Tue, 18 Oct 2022 08:23:55 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1666074236; x=1697610236; h=from:to:cc:subject:date:message-id:in-reply-to: references; bh=EplPYg5E2hIF1Ik9d2EcKDbUIWmqgpggRmu0+icUppI=; b=J70gfl/mphsEG9dYpq8qh+RdT7u0HD3XwXFPavyoo+r38nGPxqQA+/pq NYqWTZLwfPLlPqbEkTa0GJ+FoPjqtb9ykwf+IWRd63l7NzAXv2AairpGZ Oi8U4CH77OSEAHeBtpDvLWY8sSIqOHDo/K+tVfkBpEW3gMpqnVhrrHExE vxOZ2XLdr3iyzzcYajwSWZch5ycfeOpLf8dEMMcfgzl73wpjAxVOFuSoc mRasMqgAGUxoROlzhE4wzurhw9IzovKdLO2Ad08dJSYNWqwkjW8cVLC7Z Pn0MvV2VSino+fn7VaQiX66a4Ut+v6qG8CISmO86XaT7VgKWgohXCyzrn A==; X-IronPort-AV: E=McAfee;i="6500,9779,10503"; a="285732800" X-IronPort-AV: E=Sophos;i="5.95,193,1661842800"; d="scan'208";a="285732800" Received: from orsmga008.jf.intel.com ([10.7.209.65]) by fmsmga106.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 17 Oct 2022 23:23:55 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6500,9779,10503"; a="659655904" X-IronPort-AV: E=Sophos;i="5.95,193,1661842800"; d="scan'208";a="659655904" Received: from dpdk-dipei.sh.intel.com ([10.67.110.251]) by orsmga008.jf.intel.com with ESMTP; 17 Oct 2022 23:23:53 -0700 From: Andy Pei To: dev@dpdk.org Cc: chenbo.xia@intel.com, rosen.xu@intel.com, wei.huang@intel.com, gang.cao@intel.com, maxime.coquelin@redhat.com Subject: [PATCH v7 10/12] vhost: add vdpa device type to rte vdpa device Date: Tue, 18 Oct 2022 14:19:35 +0800 Message-Id: <1666073977-175484-11-git-send-email-andy.pei@intel.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1666073977-175484-1-git-send-email-andy.pei@intel.com> References: <1661229305-240952-2-git-send-email-andy.pei@intel.com> <1666073977-175484-1-git-send-email-andy.pei@intel.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: , Errors-To: dev-bounces@dpdk.org Add vdpa_device_type to rte_vdpa_device to store device type. Call vdpa ops get_dev_type to fill vdpa_device_type when register vdpa device. Signed-off-by: Andy Pei --- lib/vhost/socket.c | 15 +-------------- lib/vhost/vdpa.c | 17 +++++++++++++++++ lib/vhost/vdpa_driver.h | 2 ++ 3 files changed, 20 insertions(+), 14 deletions(-) diff --git a/lib/vhost/socket.c b/lib/vhost/socket.c index 608ae57..f768114 100644 --- a/lib/vhost/socket.c +++ b/lib/vhost/socket.c @@ -627,7 +627,6 @@ struct rte_vdpa_device * { struct vhost_user_socket *vsocket; struct rte_vdpa_device *vdpa_dev; - uint32_t vdpa_type = 0; int ret = 0; pthread_mutex_lock(&vhost_user.mutex); @@ -644,19 +643,7 @@ struct rte_vdpa_device * goto unlock_exit; } - if (vdpa_dev->ops->get_dev_type) { - ret = vdpa_dev->ops->get_dev_type(vdpa_dev, &vdpa_type); - if (ret) { - VHOST_LOG_CONFIG(path, ERR, - "failed to get vdpa dev type for socket file.\n"); - ret = -1; - goto unlock_exit; - } - } else { - vdpa_type = RTE_VHOST_VDPA_DEVICE_TYPE_NET; - } - - *type = vdpa_type; + *type = vdpa_dev->vdpa_device_type; unlock_exit: pthread_mutex_unlock(&vhost_user.mutex); diff --git a/lib/vhost/vdpa.c b/lib/vhost/vdpa.c index bb82857..b487f4d 100644 --- a/lib/vhost/vdpa.c +++ b/lib/vhost/vdpa.c @@ -73,6 +73,8 @@ struct rte_vdpa_device * struct rte_vdpa_dev_ops *ops) { struct rte_vdpa_device *dev; + uint32_t vdpa_type = -1; + int ret = 0; if (ops == NULL) return NULL; @@ -101,6 +103,21 @@ struct rte_vdpa_device * dev->device = rte_dev; dev->ops = ops; + + if (ops->get_dev_type) { + ret = ops->get_dev_type(dev, &vdpa_type); + if (ret) { + VHOST_LOG_CONFIG(rte_dev->name, ERR, + "Failed to get vdpa dev type.\n"); + ret = -1; + goto out_unlock; + } + } else { + /** by default, we assume vdpa device is a net device */ + vdpa_type = RTE_VHOST_VDPA_DEVICE_TYPE_NET; + } + dev->vdpa_device_type = vdpa_type; + TAILQ_INSERT_TAIL(&vdpa_device_list, dev, next); out_unlock: rte_spinlock_unlock(&vdpa_device_list_lock); diff --git a/lib/vhost/vdpa_driver.h b/lib/vhost/vdpa_driver.h index 8b88a53..c4ec222 100644 --- a/lib/vhost/vdpa_driver.h +++ b/lib/vhost/vdpa_driver.h @@ -92,6 +92,8 @@ struct rte_vdpa_device { struct rte_device *device; /** vdpa device operations */ struct rte_vdpa_dev_ops *ops; + /** vdpa device type: net, blk... */ + uint32_t vdpa_device_type; }; /** -- 1.8.3.1