All of lore.kernel.org
 help / color / mirror / Atom feed
From: David Marchand <david.marchand@6wind.com>
To: dev@dpdk.org
Cc: viktorin@rehivetech.com
Subject: [PATCH 4/9] pci: rework sysfs parsing for driver
Date: Fri, 22 Jan 2016 16:27:39 +0100	[thread overview]
Message-ID: <1453476464-31767-5-git-send-email-david.marchand@6wind.com> (raw)
In-Reply-To: <1453476464-31767-1-git-send-email-david.marchand@6wind.com>

There is no use for pci_get_kernel_driver_by_path() apart recognising
kernel driver and fill kdrv field.
If driver parsing fails, report "none" driver rather than "unknown".

Signed-off-by: David Marchand <david.marchand@6wind.com>
---
 lib/librte_eal/linuxapp/eal/eal_pci.c | 48 ++++++++++++++---------------------
 1 file changed, 19 insertions(+), 29 deletions(-)

diff --git a/lib/librte_eal/linuxapp/eal/eal_pci.c b/lib/librte_eal/linuxapp/eal/eal_pci.c
index 7bec30f..00fdee7 100644
--- a/lib/librte_eal/linuxapp/eal/eal_pci.c
+++ b/lib/librte_eal/linuxapp/eal/eal_pci.c
@@ -94,32 +94,37 @@ error:
 }
 
 static int
-pci_get_kernel_driver_by_path(const char *filename, char *dri_name)
+pci_parse_sysfs_driver(const char *filename, struct rte_pci_device *dev)
 {
 	int count;
 	char path[PATH_MAX];
 	char *name;
 
-	if (!filename || !dri_name)
-		return -1;
-
 	count = readlink(filename, path, PATH_MAX);
 	if (count >= PATH_MAX)
 		return -1;
 
-	/* For device does not have a driver */
-	if (count < 0)
-		return 1;
+	dev->kdrv = RTE_KDRV_NONE;
 
-	path[count] = '\0';
+	if (count > 0) {
+		dev->kdrv = RTE_KDRV_UNKNOWN;
 
-	name = strrchr(path, '/');
-	if (name) {
-		strncpy(dri_name, name + 1, strlen(name + 1) + 1);
-		return 0;
+		path[count] = '\0';
+		name = strrchr(path, '/');
+		if (name) {
+			name[0] = '\0';
+			name++;
+		}
+
+		if (!strcmp(name, "vfio-pci"))
+			dev->kdrv = RTE_KDRV_VFIO;
+		else if (!strcmp(name, "igb_uio"))
+			dev->kdrv = RTE_KDRV_IGB_UIO;
+		else if (!strcmp(name, "uio_pci_generic"))
+			dev->kdrv = RTE_KDRV_UIO_GENERIC;
 	}
 
-	return -1;
+	return 0;
 }
 
 /* Map pci device */
@@ -260,8 +265,6 @@ pci_scan_one(const char *dirname, uint16_t domain, uint8_t bus,
 	unsigned long tmp;
 	struct rte_pci_device *dev;
 	struct rte_pci_device *dev2;
-	char driver[PATH_MAX];
-	int ret;
 
 	dev = malloc(sizeof(*dev));
 	if (dev == NULL)
@@ -341,25 +344,12 @@ pci_scan_one(const char *dirname, uint16_t domain, uint8_t bus,
 
 	/* parse driver */
 	snprintf(filename, sizeof(filename), "%s/driver", dirname);
-	ret = pci_get_kernel_driver_by_path(filename, driver);
-	if (ret < 0) {
+	if (pci_parse_sysfs_driver(filename, dev) < 0) {
 		RTE_LOG(ERR, EAL, "Fail to get kernel driver\n");
 		free(dev);
 		return -1;
 	}
 
-	if (!ret) {
-		if (!strcmp(driver, "vfio-pci"))
-			dev->kdrv = RTE_KDRV_VFIO;
-		else if (!strcmp(driver, "igb_uio"))
-			dev->kdrv = RTE_KDRV_IGB_UIO;
-		else if (!strcmp(driver, "uio_pci_generic"))
-			dev->kdrv = RTE_KDRV_UIO_GENERIC;
-		else
-			dev->kdrv = RTE_KDRV_UNKNOWN;
-	} else
-		dev->kdrv = RTE_KDRV_UNKNOWN;
-
 	dev2 = pci_find_device(&dev->addr);
 	if (!dev2)
 		pci_add_device(dev);
-- 
1.9.1

  parent reply	other threads:[~2016-01-22 15:27 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-01-22 15:27 [PATCH 0/9] pci cleanup and blacklist rework David Marchand
2016-01-22 15:27 ` [PATCH 1/9] pci: no need for dynamic tailq init David Marchand
2016-01-22 15:27 ` [PATCH 2/9] pci: add internal device list helpers David Marchand
2016-01-22 15:27 ` [PATCH 3/9] pci: minor cleanup David Marchand
2016-01-22 15:27 ` David Marchand [this message]
2016-01-22 15:27 ` [PATCH 5/9] pci: factorize probe/detach code David Marchand
2016-01-22 15:27 ` [PATCH 6/9] pci: cosmetic change David Marchand
2016-01-22 15:27 ` [PATCH 7/9] pci: factorize driver search David Marchand
2016-01-22 15:27 ` [PATCH 8/9] pci: remove driver lookup from detach David Marchand
2016-01-22 15:27 ` [PATCH 9/9] pci: blacklist only in global probe function David Marchand
2016-01-27 13:07 ` [PATCH 0/9] pci cleanup and blacklist rework David Marchand
2016-01-29 14:49 ` [PATCH v2 " David Marchand
2016-01-29 14:49   ` [PATCH v2 1/9] pci: add internal device list helpers David Marchand
2016-01-29 14:49   ` [PATCH v2 2/9] pci/linux: minor cleanup David Marchand
2016-01-29 14:49   ` [PATCH v2 3/9] pci/linux: rework sysfs parsing for driver David Marchand
2016-01-29 14:49   ` [PATCH v2 4/9] pci: factorize probe/detach code David Marchand
2016-01-29 14:49   ` [PATCH v2 5/9] pci: cosmetic change David Marchand
2016-01-29 14:49   ` [PATCH v2 6/9] pci: factorize driver search David Marchand
2016-01-29 14:49   ` [PATCH v2 7/9] pci: remove driver lookup from detach David Marchand
2016-01-29 14:49   ` [PATCH v2 8/9] pci: implement blacklist using a hook David Marchand
2016-01-29 14:49   ` [PATCH v2 9/9] pci: implement automatic bind/unbind David Marchand
2016-02-03  9:26     ` Ivan Boule
2016-02-08 13:31   ` [PATCH v2 0/9] pci cleanup and blacklist rework Jan Viktorin
2016-02-09  8:39     ` David Marchand
2016-03-16 16:07   ` Jan Viktorin
2016-03-22 10:24     ` David Marchand

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1453476464-31767-5-git-send-email-david.marchand@6wind.com \
    --to=david.marchand@6wind.com \
    --cc=dev@dpdk.org \
    --cc=viktorin@rehivetech.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.