From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <dwdohert@ecsmtp.ir.intel.com>
Received: from mga09.intel.com (mga09.intel.com [134.134.136.24])
 by dpdk.org (Postfix) with ESMTP id 78EC5B0A4
 for <dev@dpdk.org>; Mon, 16 Jun 2014 13:18:24 +0200 (CEST)
Received: from orsmga001.jf.intel.com ([10.7.209.18])
 by orsmga102.jf.intel.com with ESMTP; 16 Jun 2014 04:13:20 -0700
X-ExtLoop1: 1
X-IronPort-AV: E=Sophos;i="5.01,486,1400050800"; d="scan'208";a="529159923"
Received: from irvmail001.ir.intel.com ([163.33.26.43])
 by orsmga001.jf.intel.com with ESMTP; 16 Jun 2014 04:18:38 -0700
Received: from sivswdev02.ir.intel.com (sivswdev02.ir.intel.com
 [10.237.217.46])
 by irvmail001.ir.intel.com (8.14.3/8.13.6/MailSET/Hub) with ESMTP id
 s5GBIcxm023096; Mon, 16 Jun 2014 12:18:38 +0100
Received: from sivswdev02.ir.intel.com (localhost [127.0.0.1])
 by sivswdev02.ir.intel.com with ESMTP id s5GBIbaf019716;
 Mon, 16 Jun 2014 12:18:37 +0100
Received: (from dwdohert@localhost)
 by sivswdev02.ir.intel.com with  id s5GBIbLT019712;
 Mon, 16 Jun 2014 12:18:37 +0100
From: Declan Doherty <declan.doherty@intel.com>
To: dev@dpdk.org
Date: Mon, 16 Jun 2014 12:18:30 +0100
Message-Id: <1402917513-19495-4-git-send-email-declan.doherty@intel.com>
X-Mailer: git-send-email 1.7.0.7
In-Reply-To: <cover.1402662300.git.declan.doherty@intel.com>
References: <cover.1402662300.git.declan.doherty@intel.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Subject: [dpdk-dev] [PATCH v4 3/6] EAL support for link bonding device
	initialization
X-BeenThere: dev@dpdk.org
X-Mailman-Version: 2.1.15
Precedence: list
List-Id: patches and discussions about DPDK <dev.dpdk.org>
List-Unsubscribe: <http://dpdk.org/ml/options/dev>,
 <mailto:dev-request@dpdk.org?subject=unsubscribe>
List-Archive: <http://dpdk.org/ml/archives/dev/>
List-Post: <mailto:dev@dpdk.org>
List-Help: <mailto:dev-request@dpdk.org?subject=help>
List-Subscribe: <http://dpdk.org/ml/listinfo/dev>,
 <mailto:dev-request@dpdk.org?subject=subscribe>
X-List-Received-Date: Mon, 16 Jun 2014 11:18:25 -0000

Updating functionality in EAL to support adding link bonding
devices via –vdev option. Link bonding devices will be
initialized after all physical devices have been probed and
initialized.

Signed-off-by: Declan Doherty <declan.doherty@intel.com>
---
 lib/librte_eal/common/eal_common_dev.c      |   66 +++++++++++++++++++++++++--
 lib/librte_eal/common/eal_common_pci.c      |    6 +++
 lib/librte_eal/common/include/eal_private.h |    7 +++
 lib/librte_eal/common/include/rte_dev.h     |    1 +
 4 files changed, 76 insertions(+), 4 deletions(-)

diff --git a/lib/librte_eal/common/eal_common_dev.c b/lib/librte_eal/common/eal_common_dev.c
index eae5656..b50c908 100644
--- a/lib/librte_eal/common/eal_common_dev.c
+++ b/lib/librte_eal/common/eal_common_dev.c
@@ -75,14 +75,28 @@ rte_eal_dev_init(void)
 
 	/* call the init function for each virtual device */
 	TAILQ_FOREACH(devargs, &devargs_list, next) {
+		uint8_t bdev = 0;
 
 		if (devargs->type != RTE_DEVTYPE_VIRTUAL)
 			continue;
 
 		TAILQ_FOREACH(driver, &dev_driver_list, next) {
-			if (driver->type != PMD_VDEV)
+			/* RTE_DEVTYPE_VIRTUAL can only be a virtual or bonded device*/
+			if (driver->type != PMD_VDEV && driver->type != PMD_BDEV)
 				continue;
 
+			/*
+			 * Bonded devices are not initialize here, we do it later in
+			 * rte_eal_bonded_dev_init() after all physical devices have been
+			 * probed and initialized
+			 */
+			if (driver->type == PMD_BDEV &&
+					!strncmp(driver->name, devargs->virtual.drv_name,
+							strlen(driver->name))) {
+				bdev = 1;
+				break;
+			}
+
 			/* search a driver prefix in virtual device name */
 			if (!strncmp(driver->name, devargs->virtual.drv_name,
 					strlen(driver->name))) {
@@ -92,9 +106,9 @@ rte_eal_dev_init(void)
 			}
 		}
 
-		if (driver == NULL) {
-			rte_panic("no driver found for %s\n",
-				  devargs->virtual.drv_name);
+		if (driver == NULL && !bdev) {
+			rte_panic("no driver found for %s and is not a bonded vdev %d\n",
+				  devargs->virtual.drv_name, bdev);
 		}
 	}
 
@@ -107,3 +121,47 @@ rte_eal_dev_init(void)
 	}
 	return 0;
 }
+
+#ifdef RTE_LIBRTE_PMD_BOND
+int
+rte_eal_bonded_dev_init(void)
+{
+	struct rte_devargs *devargs;
+	struct rte_driver *driver;
+
+	TAILQ_FOREACH(devargs, &devargs_list, next) {
+		int vdev = 0;
+
+		if (devargs->type != RTE_DEVTYPE_VIRTUAL)
+			continue;
+
+		TAILQ_FOREACH(driver, &dev_driver_list, next) {
+			if (driver->type != PMD_VDEV && driver->type != PMD_BDEV)
+				continue;
+
+			/* Virtual devices have already been initialized so we skip them
+			 * here*/
+			if (driver->type == PMD_VDEV &&
+					!strncmp(driver->name, devargs->virtual.drv_name,
+							strlen(driver->name))) {
+				vdev = 1;
+				break;
+			}
+
+			/* search a driver prefix in bonded device name */
+			if (!strncmp(driver->name, devargs->virtual.drv_name,
+					strlen(driver->name))) {
+				driver->init(devargs->virtual.drv_name, devargs->args);
+				break;
+			}
+		}
+
+		if (driver == NULL && !vdev) {
+			rte_panic("no driver found for %s\n",
+					devargs->virtual.drv_name);
+		}
+	}
+	return 0;
+}
+#endif
+
diff --git a/lib/librte_eal/common/eal_common_pci.c b/lib/librte_eal/common/eal_common_pci.c
index 4d877ea..9b584f5 100644
--- a/lib/librte_eal/common/eal_common_pci.c
+++ b/lib/librte_eal/common/eal_common_pci.c
@@ -166,7 +166,13 @@ rte_eal_pci_probe(void)
 				 dev->addr.devid, dev->addr.function);
 	}
 
+#ifdef RTE_LIBRTE_PMD_BOND
+	/* After all physical PCI devices have been probed and initialized then we
+	 * initialize the bonded devices */
+	return rte_eal_bonded_dev_init();
+#else
 	return 0;
+#endif
 }
 
 /* dump one device */
diff --git a/lib/librte_eal/common/include/eal_private.h b/lib/librte_eal/common/include/eal_private.h
index 232fcec..f6081bb 100644
--- a/lib/librte_eal/common/include/eal_private.h
+++ b/lib/librte_eal/common/include/eal_private.h
@@ -203,4 +203,11 @@ int rte_eal_alarm_init(void);
  */
 int rte_eal_dev_init(void);
 
+#ifdef RTE_LIBRTE_PMD_BOND
+/**
+ * Initialize the bonded devices
+ */
+int rte_eal_bonded_dev_init(void);
+#endif
+
 #endif /* _EAL_PRIVATE_H_ */
diff --git a/lib/librte_eal/common/include/rte_dev.h b/lib/librte_eal/common/include/rte_dev.h
index f7e3a10..f0a780a 100644
--- a/lib/librte_eal/common/include/rte_dev.h
+++ b/lib/librte_eal/common/include/rte_dev.h
@@ -62,6 +62,7 @@ typedef int (rte_dev_init_t)(const char *name, const char *args);
 enum pmd_type {
 	PMD_VDEV = 0,
 	PMD_PDEV = 1,
+	PMD_BDEV = 2,	/**< Poll Mode Driver Bonded Device*/
 };
 
 /**
-- 
1.7.0.7