From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <jblunck@gmail.com>
Received: from mail-wm0-f68.google.com (mail-wm0-f68.google.com [74.125.82.68])
 by dpdk.org (Postfix) with ESMTP id E27FA5583
 for <dev@dpdk.org>; Wed, 15 Feb 2017 15:04:16 +0100 (CET)
Received: by mail-wm0-f68.google.com with SMTP id c85so8396224wmi.1
 for <dev@dpdk.org>; Wed, 15 Feb 2017 06:04:16 -0800 (PST)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025;
 h=sender:from:to:cc:subject:date:message-id:in-reply-to:references;
 bh=GuDVUFCx/tQJWALN8zUt88/mKysbSNFs7qYSZ6vcMqE=;
 b=QndISbjdYcAKrLcZflfD2HwQ9TQ9Q2GIm5GhKTOvvMGLjcRzaoMS0+b7G45BsGxceE
 J9I6A/EpKh7YfR1Q/ZTZIMo2+fISiJqKS1f/2v8fJudt57ArRZzKaeN4Z63ZIUuuMF7F
 jb3pVmHyrvWWWAPc5QDbEYLei9UaAY2tP+8GpdSuhbeJQYH5tMEmCWNoQBGwr/pjbUPs
 GdGQLtTyEvfhNZRvfzoz0FenKpiz1oCiv7zXbo/OKJh3Ox19ZHZ/gtTVBk49IvXx0vF3
 vhQMBbFJioRLTZJ7UaRa6721L2734YN2syB3EtfAUUpa1ylsO+EdBAemqnjldR8twcay
 iBig==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
 d=1e100.net; s=20161025;
 h=x-gm-message-state:sender:from:to:cc:subject:date:message-id
 :in-reply-to:references;
 bh=GuDVUFCx/tQJWALN8zUt88/mKysbSNFs7qYSZ6vcMqE=;
 b=Snx2s/9IZeRjCiJy6CU3YiFVvI/GboTrAcoDXSe3qz5RuVKVC8g4iRz/KUrN3C4Wpi
 5kgf2sqPF5vV8saw8gE320TngtKZtcdWWH2Q6T6dk7jqxz3KLXW7x2S0OGpzsJCK4w8V
 IIPyTuAogGZePixy5m3O+Oy0IcoSXpPKJia+XbtYQuJ73mLRhG+jx+KMALRL7oUhTCOd
 0wAihauQ6qBddzkI9i612kIkza7BQJMVRN/0g11zELqw/rnkmQlIVcn2DwPdWQtoYuV/
 fP2NkrnqnINCBeDomgtee+YiOnNzwG4Mc0uo+s6zB9eLBmsNbrZzN2UB79+ZdPx0JrRa
 0Ndg==
X-Gm-Message-State: AMke39ksh+UaMyFZgUF/H4pyaUDj/KriMb6949AQIk0KvhwPnOhECB7G+qH+K85yyxkMpA==
X-Received: by 10.28.94.2 with SMTP id s2mr7744234wmb.127.1487167456393;
 Wed, 15 Feb 2017 06:04:16 -0800 (PST)
Received: from weierstrass.local.net ([91.200.109.169])
 by smtp.gmail.com with ESMTPSA id c202sm7708554wmd.10.2017.02.15.06.04.15
 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128);
 Wed, 15 Feb 2017 06:04:15 -0800 (PST)
Sender: Jan Blunck <jblunck@gmail.com>
From: Jan Blunck <jblunck@infradead.org>
To: dev@dpdk.org
Cc: david.marchand@6wind.com,
	shreyansh.jain@nxp.com
Date: Wed, 15 Feb 2017 15:04:04 +0100
Message-Id: <1487167444-642-1-git-send-email-jblunck@infradead.org>
X-Mailer: git-send-email 2.7.4
In-Reply-To: <CALe+Z01bWvyyRF6A1FEWeU9nx-a96AH6gtg+Lezv1-LeSz9b2w@mail.gmail.com>
References: <CALe+Z01bWvyyRF6A1FEWeU9nx-a96AH6gtg+Lezv1-LeSz9b2w@mail.gmail.com>
Subject: [dpdk-dev] [RFC] eal: use busname and devargs to attach devices
X-BeenThere: dev@dpdk.org
X-Mailman-Version: 2.1.15
Precedence: list
List-Id: DPDK patches and discussions <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: Wed, 15 Feb 2017 14:04:17 -0000

Using just the device name to attach a device on the EAL level is not enough
for a unique identification of the bus it should get attached to. Therefore
lets change rte_eal_dev_attach() introduced in 16.11 to take the busname and
the raw devargs string.

Signed-off-by: Jan Blunck <jblunck@infradead.org>
---
 lib/librte_eal/common/eal_common_dev.c | 61 ++++++++++++++++++++++++++--------
 lib/librte_ether/rte_ethdev.c          | 17 +---------
 2 files changed, 49 insertions(+), 29 deletions(-)

diff --git a/lib/librte_eal/common/eal_common_dev.c b/lib/librte_eal/common/eal_common_dev.c
index 4bde430..bf41a94 100644
--- a/lib/librte_eal/common/eal_common_dev.c
+++ b/lib/librte_eal/common/eal_common_dev.c
@@ -37,6 +37,7 @@
 #include <inttypes.h>
 #include <sys/queue.h>
 
+#include <rte_bus.h>
 #include <rte_dev.h>
 #include <rte_devargs.h>
 #include <rte_debug.h>
@@ -76,29 +77,63 @@ void rte_eal_device_remove(struct rte_device *dev)
 	TAILQ_REMOVE(&dev_device_list, dev, next);
 }
 
-int rte_eal_dev_attach(const char *name, const char *devargs)
+int rte_eal_dev_attach(const char *busname, const char *devargs)
 {
-	struct rte_pci_addr addr;
+	struct rte_bus *bus;
+	rte_bus_attach_t attach;
+	int ret;
 
-	if (name == NULL || devargs == NULL) {
+	if (busname == NULL || devargs == NULL) {
 		RTE_LOG(ERR, EAL, "Invalid device or arguments provided\n");
 		return -EINVAL;
 	}
 
-	if (eal_parse_pci_DomBDF(name, &addr) == 0) {
-		if (rte_eal_pci_probe_one(&addr) < 0)
-			goto err;
+	if (!busname) {
+		char *name, *args;
+		struct rte_pci_addr addr;
 
-	} else {
-		if (rte_eal_vdev_init(name, devargs))
-			goto err;
+		/*
+		 * We default to virtual device but lets check for PCI device format for
+		 * backwards compatibility reasons.
+		 */
+		busname = "virtual";
+
+		if (rte_eal_parse_devargs_str(devargs, &name, &args))
+			return -EINVAL;
+
+		if (eal_parse_pci_DomBDF(name, &addr) == 0) {
+			RTE_LOG(ERR, EAL, "Deprectated\n");
+			busname = "pci";
+		}
+
+		free(name);
+		free(args);
 	}
 
-	return 0;
+	bus = rte_bus_find_by_name(busname);
+	if (!bus) {
+		RTE_LOG(ERR, EAL, "Can't find bus (%s)\n", busname);
+		return -EINVAL;
+	}
 
-err:
-	RTE_LOG(ERR, EAL, "Driver cannot attach the device (%s)\n", name);
-	return -EINVAL;
+	attach = bus->attach;
+	if (!attach) {
+		RTE_LOG(ERR, EAL, "Function not supported\n");
+		return -ENOTSUP;
+	}
+
+	ret = attach(devargs);
+	if (ret) {
+		RTE_LOG(ERR, EAL, "Attaching device to bus failed \n");
+		return ret;
+	}
+
+	/*
+	 * Probing might fail because some devices are not claimed by any driver
+	 * but we don't care: the device is properly attached at this point.
+	 */
+	(void)bus->probe();
+	return 0;
 }
 
 int rte_eal_dev_detach(const char *name)
diff --git a/lib/librte_ether/rte_ethdev.c b/lib/librte_ether/rte_ethdev.c
index eb0a94a..bbebc8f 100644
--- a/lib/librte_ether/rte_ethdev.c
+++ b/lib/librte_ether/rte_ethdev.c
@@ -474,29 +474,16 @@ rte_eth_dev_attach(const char *devargs, uint8_t *port_id)
 {
 	int ret = -1;
 	int current = rte_eth_dev_count();
-	char *name = NULL;
-	char *args = NULL;
 
 	if ((devargs == NULL) || (port_id == NULL)) {
 		ret = -EINVAL;
 		goto err;
 	}
 
-	/* parse devargs, then retrieve device name and args */
-	if (rte_eal_parse_devargs_str(devargs, &name, &args))
-		goto err;
-
-	ret = rte_eal_dev_attach(name, args);
+	ret = rte_eal_dev_attach(NULL, devargs);
 	if (ret < 0)
 		goto err;
 
-	/* no point looking at the port count if no port exists */
-	if (!rte_eth_dev_count()) {
-		RTE_LOG(ERR, EAL, "No port found for device (%s)\n", name);
-		ret = -1;
-		goto err;
-	}
-
 	/* if nothing happened, there is a bug here, since some driver told us
 	 * it did attach a device, but did not create a port.
 	 */
@@ -509,8 +496,6 @@ rte_eth_dev_attach(const char *devargs, uint8_t *port_id)
 	ret = 0;
 
 err:
-	free(name);
-	free(args);
 	return ret;
 }
 
-- 
2.7.4