[dpdk-dev,4/9] pci: rework sysfs parsing for driver
Commit Message
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(-)
@@ -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);