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 89543A0548;
	Thu,  8 Sep 2022 07:53:36 +0200 (CEST)
Received: from [217.70.189.124] (localhost [127.0.0.1])
	by mails.dpdk.org (Postfix) with ESMTP id EFE5D40DDC;
	Thu,  8 Sep 2022 07:53:26 +0200 (CEST)
Received: from mga17.intel.com (mga17.intel.com [192.55.52.151])
 by mails.dpdk.org (Postfix) with ESMTP id 45ED741155
 for <dev@dpdk.org>; Thu,  8 Sep 2022 07:53:24 +0200 (CEST)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple;
 d=intel.com; i=@intel.com; q=dns/txt; s=Intel;
 t=1662616404; x=1694152404;
 h=from:to:cc:subject:date:message-id:in-reply-to: references;
 bh=Ms+q2ncWfd04w0caB0rPcGsZvIaJNY+UXnRqq/lupSs=;
 b=IkDTvAlFhhHySZUPvRxrpcLK/u6TVWfOmSrBBK4IqnOFBJDJ//FtlZFW
 MunrtPzyHAbPf1RwdagExSzamqGgZgrBu8Dg4WEigd0Ld3Lrkypi23RhL
 xKAHjoAJ0cuuGJ4BY81jPDHR9cSGhOVAZzdXo9usdA5UisBi7OJ7K3DC2
 zkx1kQm6BQshJIWEg1h0EZZ3lsmPlbfYG/1w4KOtu3dDpFaORBmIAxSbH
 K0vZVX9BnxY4q7IEvnjICmgLJfo+1OI1Py9cBw5EWdOFY5SBD5JooQgsz
 15hpXP/55CFjCNHwkI9/ird9VboBoq5t5LKunzYLxgm58rC5hG5Il2k9P A==;
X-IronPort-AV: E=McAfee;i="6500,9779,10463"; a="277464162"
X-IronPort-AV: E=Sophos;i="5.93,299,1654585200"; d="scan'208";a="277464162"
Received: from fmsmga008.fm.intel.com ([10.253.24.58])
 by fmsmga107.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384;
 07 Sep 2022 22:53:23 -0700
X-ExtLoop1: 1
X-IronPort-AV: E=Sophos;i="5.93,299,1654585200"; d="scan'208";a="676531807"
Received: from dpdk-dipei.sh.intel.com ([10.67.110.251])
 by fmsmga008.fm.intel.com with ESMTP; 07 Sep 2022 22:53:22 -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,
 Huang Wei <wei_huang@intel.com>
Subject: [PATCH v2 3/8] vdpa/ifc: set max queues according to HW spec
Date: Thu,  8 Sep 2022 13:54:13 +0800
Message-Id: <1662616458-164613-4-git-send-email-andy.pei@intel.com>
X-Mailer: git-send-email 1.8.3.1
In-Reply-To: <1662616458-164613-1-git-send-email-andy.pei@intel.com>
References: <1661229305-240952-2-git-send-email-andy.pei@intel.com>
 <1662616458-164613-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

Set max_queues according to virtio HW spec.
For virtio BLK device, set max_queues to the value of "num_queues".
"num_queues" is element of struct virtio_blk_config.

Signed-off-by: Andy Pei <andy.pei@intel.com>
Signed-off-by: Huang Wei <wei_huang@intel.com>
---
 drivers/vdpa/ifc/base/ifcvf.h |  2 +-
 drivers/vdpa/ifc/ifcvf_vdpa.c | 21 ++++++++++++++++++++-
 2 files changed, 21 insertions(+), 2 deletions(-)

diff --git a/drivers/vdpa/ifc/base/ifcvf.h b/drivers/vdpa/ifc/base/ifcvf.h
index ad505f1..c17bf2a 100644
--- a/drivers/vdpa/ifc/base/ifcvf.h
+++ b/drivers/vdpa/ifc/base/ifcvf.h
@@ -21,7 +21,7 @@
 #define IFCVF_NET_DEVICE_ID                 0x0001
 #define IFCVF_BLK_DEVICE_ID                 0x0002
 
-#define IFCVF_MAX_QUEUES		1
+#define IFCVF_MAX_QUEUES		32
 
 #ifndef VIRTIO_F_IOMMU_PLATFORM
 #define VIRTIO_F_IOMMU_PLATFORM		33
diff --git a/drivers/vdpa/ifc/ifcvf_vdpa.c b/drivers/vdpa/ifc/ifcvf_vdpa.c
index 2d165c0..2b42850 100644
--- a/drivers/vdpa/ifc/ifcvf_vdpa.c
+++ b/drivers/vdpa/ifc/ifcvf_vdpa.c
@@ -26,6 +26,18 @@
 
 #include "base/ifcvf.h"
 
+/*
+ * RTE_MAX() and RTE_MIN() cannot be used since braced-group within
+ * expression allowed only inside a function, but MAX() is used as
+ * a number of elements in array.
+ */
+#ifndef MAX
+#define MAX(v1, v2)	((v1) > (v2) ? (v1) : (v2))
+#endif
+#ifndef MIN
+#define MIN(v1, v2)	((v1) < (v2) ? (v1) : (v2))
+#endif
+
 RTE_LOG_REGISTER(ifcvf_vdpa_logtype, pmd.vdpa.ifcvf, NOTICE);
 #define DRV_LOG(level, fmt, args...) \
 	rte_log(RTE_LOG_ ## level, ifcvf_vdpa_logtype, \
@@ -1512,6 +1524,7 @@ struct rte_vdpa_dev_info dev_info[] = {
 	uint64_t capacity = 0;
 	uint8_t *byte;
 	uint32_t i;
+	uint16_t queue_pairs;
 
 	if (rte_eal_process_type() != RTE_PROC_PRIMARY)
 		return 0;
@@ -1559,7 +1572,6 @@ struct rte_vdpa_dev_info dev_info[] = {
 	}
 
 	internal->configured = 0;
-	internal->max_queues = IFCVF_MAX_QUEUES;
 	features = ifcvf_get_features(&internal->hw);
 
 	device_id = ifcvf_pci_get_device_type(pci_dev);
@@ -1570,6 +1582,10 @@ struct rte_vdpa_dev_info dev_info[] = {
 
 	if (device_id == VIRTIO_ID_NET) {
 		internal->hw.device_type = IFCVF_NET;
+		queue_pairs = (internal->hw.common_cfg->num_queues - 1) / 2;
+		DRV_LOG(INFO, "%s support %u queue pairs", pci_dev->name,
+			queue_pairs);
+		internal->max_queues = MIN(IFCVF_MAX_QUEUES, queue_pairs);
 		internal->features = features &
 					~(1ULL << VIRTIO_F_IOMMU_PLATFORM);
 		internal->features |= dev_info[IFCVF_NET].features;
@@ -1609,6 +1625,9 @@ struct rte_vdpa_dev_info dev_info[] = {
 			internal->hw.blk_cfg->geometry.sectors);
 		DRV_LOG(DEBUG, "num_queues: 0x%08x",
 			internal->hw.blk_cfg->num_queues);
+
+		internal->max_queues = MIN(IFCVF_MAX_QUEUES,
+			internal->hw.blk_cfg->num_queues);
 	}
 
 	list->internal = internal;
-- 
1.8.3.1