All of lore.kernel.org
 help / color / mirror / Atom feed
From: Shreyansh Jain <shreyansh.jain@nxp.com>
To: <viktorin@rehivetech.com>, <dev@dpdk.org>
Cc: <thomas.monjalon@6wind.com>, Shreyansh Jain <shreyansh.jain@nxp.com>
Subject: [PATCH 5/5] eal/linux: extract function rte_eal_get_kernel_driver_by_path
Date: Thu, 1 Sep 2016 10:11:55 +0530	[thread overview]
Message-ID: <1472704915-13112-6-git-send-email-shreyansh.jain@nxp.com> (raw)
In-Reply-To: <1472704915-13112-1-git-send-email-shreyansh.jain@nxp.com>

From: Jan Viktorin <viktorin@rehivetech.com>

From: Jan Viktorin <viktorin@rehivetech.com>

Generalize the PCI-specific pci_get_kernel_driver_by_path. The function
is general enough, we have just moved it to eal.c, changed the prefix to
rte_eal and provided it privately to other parts of EAL.

Signed-off-by: Jan Viktorin <viktorin@rehivetech.com>
Signed-off-by: Shreyansh Jain <shreyansh.jain@nxp.com>
---
 lib/librte_eal/common/eal_private.h   | 14 ++++++++++++++
 lib/librte_eal/linuxapp/eal/eal.c     | 29 +++++++++++++++++++++++++++++
 lib/librte_eal/linuxapp/eal/eal_pci.c | 31 +------------------------------
 3 files changed, 44 insertions(+), 30 deletions(-)

diff --git a/lib/librte_eal/common/eal_private.h b/lib/librte_eal/common/eal_private.h
index 0740c0c..5ea30a2 100644
--- a/lib/librte_eal/common/eal_private.h
+++ b/lib/librte_eal/common/eal_private.h
@@ -271,6 +271,20 @@ int rte_eal_check_module(const char *module_name);
 int rte_eal_unbind_kernel_driver(const char *devpath, const char *devid);
 
 /**
+ * Extrat the kernel driver name from the absolute path to the driver.
+ *
+ * @param filename  path to the driver ("<path-to-device>/driver")
+ * @path  dri_name  target buffer where to place the driver name
+ *                  (should be at least PATH_MAX long)
+ *
+ * @return
+ *      -1   on failure
+ *       0   when successful
+ *       1   when there is no such driver
+ */
+int rte_eal_get_kernel_driver_by_path(const char *filename, char *dri_name);
+
+/**
  * Get cpu core_id.
  *
  * This function is private to the EAL.
diff --git a/lib/librte_eal/linuxapp/eal/eal.c b/lib/librte_eal/linuxapp/eal/eal.c
index 8711d9a..9a4c498 100644
--- a/lib/librte_eal/linuxapp/eal/eal.c
+++ b/lib/librte_eal/linuxapp/eal/eal.c
@@ -973,3 +973,32 @@ error:
 	fclose(f);
 	return -1;
 }
+
+int
+rte_eal_get_kernel_driver_by_path(const char *filename, char *dri_name)
+{
+	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;
+
+	path[count] = '\0';
+
+	name = strrchr(path, '/');
+	if (name) {
+		strncpy(dri_name, name + 1, strlen(name + 1) + 1);
+		return 0;
+	}
+
+	return -1;
+}
diff --git a/lib/librte_eal/linuxapp/eal/eal_pci.c b/lib/librte_eal/linuxapp/eal/eal_pci.c
index 4792d05..f923e42 100644
--- a/lib/librte_eal/linuxapp/eal/eal_pci.c
+++ b/lib/librte_eal/linuxapp/eal/eal_pci.c
@@ -78,35 +78,6 @@ pci_unbind_kernel_driver(struct rte_pci_device *dev)
 	return rte_eal_unbind_kernel_driver(devpath, devid);
 }
 
-static int
-pci_get_kernel_driver_by_path(const char *filename, char *dri_name)
-{
-	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;
-
-	path[count] = '\0';
-
-	name = strrchr(path, '/');
-	if (name) {
-		strncpy(dri_name, name + 1, strlen(name + 1) + 1);
-		return 0;
-	}
-
-	return -1;
-}
-
 /* Map pci device */
 int
 rte_eal_pci_map_device(struct rte_pci_device *dev)
@@ -354,7 +325,7 @@ 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);
+	ret = rte_eal_get_kernel_driver_by_path(filename, driver);
 	if (ret < 0) {
 		RTE_LOG(ERR, EAL, "Fail to get kernel driver\n");
 		free(dev);
-- 
2.7.4

  parent reply	other threads:[~2016-09-01  4:42 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-09-01  4:41 [PATCH 0/5] Generalize PCI specific EAL function/structures Shreyansh Jain
2016-09-01  4:41 ` [PATCH 1/5] eal: make enum rte_kernel_driver non-PCI specific Shreyansh Jain
2016-09-11 12:15   ` Yuanhan Liu
2016-09-12  5:10     ` Shreyansh Jain
2016-09-01  4:41 ` [PATCH 2/5] eal: extract function eal_parse_sysfs_valuef Shreyansh Jain
2016-09-01  6:30   ` Stephen Hemminger
2016-09-01  9:01     ` Shreyansh Jain
2016-09-01  4:41 ` [PATCH 3/5] eal: Convert pci_(un)map_resource to rte_eal_(un)map_resource Shreyansh Jain
2016-09-01  4:41 ` [PATCH 4/5] eal/linux: extract function rte_eal_unbind_kernel_driver Shreyansh Jain
2016-09-01  4:41 ` Shreyansh Jain [this message]
2016-09-27 14:12 ` [PATCH v1 0/4] Generalize PCI specific EAL function/structures Shreyansh Jain
2016-09-27 14:12   ` [PATCH v1 1/4] eal: generalize PCI kernel driver enum to EAL Shreyansh Jain
2016-09-27 14:12   ` [PATCH v1 2/4] eal: generalize PCI map/unmap resource " Shreyansh Jain
2016-09-27 14:12   ` [PATCH v1 3/4] eal/linux: generalize PCI kernel unbinding driver " Shreyansh Jain
2016-09-27 14:12   ` [PATCH v1 4/4] eal/linux: generalize PCI kernel driver extraction " Shreyansh Jain
2016-09-30 15:31   ` [PATCH v1 0/4] Generalize PCI specific EAL function/structures David Marchand
2016-10-03  5:37     ` Shreyansh Jain
2016-10-03 13:12       ` Jan Viktorin
2016-10-03 13:36       ` Thomas Monjalon
2016-10-06 11:43         ` Shreyansh Jain
2016-10-06 13:01           ` Thomas Monjalon
2016-10-13  6:47     ` Shreyansh Jain
2016-10-14 10:55   ` [PATCH v2 " Shreyansh Jain
2016-10-14 10:55     ` [PATCH v2 1/4] eal: generalize PCI kernel driver enum to EAL Shreyansh Jain
2016-10-14 10:55     ` [PATCH v2 2/4] eal: generalize PCI map/unmap resource " Shreyansh Jain
2016-10-14 10:55     ` [PATCH v2 3/4] eal/linux: generalize PCI kernel unbinding driver " Shreyansh Jain
2016-10-14 10:55     ` [PATCH v2 4/4] eal/linux: generalize PCI kernel driver extraction " Shreyansh Jain

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=1472704915-13112-6-git-send-email-shreyansh.jain@nxp.com \
    --to=shreyansh.jain@nxp.com \
    --cc=dev@dpdk.org \
    --cc=thomas.monjalon@6wind.com \
    --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.