From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <dev-bounces@dpdk.org>
Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124])
	by inbox.dpdk.org (Postfix) with ESMTP id 7F19DA0560;
	Tue, 18 Oct 2022 08:24:21 +0200 (CEST)
Received: from [217.70.189.124] (localhost [127.0.0.1])
	by mails.dpdk.org (Postfix) with ESMTP id 0BD5D427FF;
	Tue, 18 Oct 2022 08:23:55 +0200 (CEST)
Received: from mga12.intel.com (mga12.intel.com [192.55.52.136])
 by mails.dpdk.org (Postfix) with ESMTP id 34EFC4281E
 for <dev@dpdk.org>; Tue, 18 Oct 2022 08:23:53 +0200 (CEST)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple;
 d=intel.com; i=@intel.com; q=dns/txt; s=Intel;
 t=1666074233; x=1697610233;
 h=from:to:cc:subject:date:message-id:in-reply-to: references;
 bh=o8f1sWoMenWEr9E6VK1GnKrRShbXo+TYIdd8C7jFeK0=;
 b=ED/9Xr32pIDC4rmbgq9DEwa01IWqmktUE+ziObataBEZe5/57dyW5JzI
 9SJWw78oAo+bcGa/pm10Of479GC+SPi+Iy7yXqeZxyAU7NHeAYOWejVtd
 pffVJz6/0tWQ+cKGyie0zwNEWIuV251dhuESsJOwGPS4gE8kvoPe+5ugb
 WxPYybm/JpiwjaftrAg7OPWZohVshfnieTQ+nw2SLdaVFriqyD4cuJtf5
 aTwtbTdXppB7aTXEDqTf3WA55cMplTEK9z2nhaWwyvSKx2UbDRxBOfpnm
 BQH2xLf0HjodfnOMEsmTp1ghsgwGxU3GFQ7CV9ztBnFCMml6tw6mvcOS6 Q==;
X-IronPort-AV: E=McAfee;i="6500,9779,10503"; a="285732794"
X-IronPort-AV: E=Sophos;i="5.95,193,1661842800"; d="scan'208";a="285732794"
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:52 -0700
X-ExtLoop1: 1
X-IronPort-AV: E=McAfee;i="6500,9779,10503"; a="659655889"
X-IronPort-AV: E=Sophos;i="5.95,193,1661842800"; d="scan'208";a="659655889"
Received: from dpdk-dipei.sh.intel.com ([10.67.110.251])
 by orsmga008.jf.intel.com with ESMTP; 17 Oct 2022 23:23:50 -0700
From: Andy Pei <andy.pei@intel.com>
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 09/12] vdpa/ifc: change some driver logic
Date: Tue, 18 Oct 2022 14:19:34 +0800
Message-Id: <1666073977-175484-10-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 <dev.dpdk.org>
List-Unsubscribe: <https://mails.dpdk.org/options/dev>,
 <mailto:dev-request@dpdk.org?subject=unsubscribe>
List-Archive: <http://mails.dpdk.org/archives/dev/>
List-Post: <mailto:dev@dpdk.org>
List-Help: <mailto:dev-request@dpdk.org?subject=help>
List-Subscribe: <https://mails.dpdk.org/listinfo/dev>,
 <mailto:dev-request@dpdk.org?subject=subscribe>
Errors-To: dev-bounces@dpdk.org

Insert internal list element to internal list before
register vdpa device, in order to call vdpa ops during
vdpa device registration.

Signed-off-by: Andy Pei <andy.pei@intel.com>
---
 drivers/vdpa/ifc/ifcvf_vdpa.c | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)

diff --git a/drivers/vdpa/ifc/ifcvf_vdpa.c b/drivers/vdpa/ifc/ifcvf_vdpa.c
index c16e263..8dfd493 100644
--- a/drivers/vdpa/ifc/ifcvf_vdpa.c
+++ b/drivers/vdpa/ifc/ifcvf_vdpa.c
@@ -1737,17 +1737,20 @@ struct rte_vdpa_dev_info dev_info[] = {
 	}
 	internal->sw_lm = sw_fallback_lm;
 
+	pthread_mutex_lock(&internal_list_lock);
+	TAILQ_INSERT_TAIL(&internal_list, list, next);
+	pthread_mutex_unlock(&internal_list_lock);
+
 	internal->vdev = rte_vdpa_register_device(&pci_dev->device,
 				dev_info[internal->hw.device_type].ops);
 	if (internal->vdev == NULL) {
 		DRV_LOG(ERR, "failed to register device %s", pci_dev->name);
+		pthread_mutex_lock(&internal_list_lock);
+		TAILQ_REMOVE(&internal_list, list, next);
+		pthread_mutex_unlock(&internal_list_lock);
 		goto error;
 	}
 
-	pthread_mutex_lock(&internal_list_lock);
-	TAILQ_INSERT_TAIL(&internal_list, list, next);
-	pthread_mutex_unlock(&internal_list_lock);
-
 	rte_atomic32_set(&internal->started, 1);
 	update_datapath(internal);
 
-- 
1.8.3.1