From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wm0-f44.google.com (mail-wm0-f44.google.com [74.125.82.44]) by dpdk.org (Postfix) with ESMTP id EDA3691C2 for ; Fri, 22 Jan 2016 16:27:55 +0100 (CET) Received: by mail-wm0-f44.google.com with SMTP id l65so265467981wmf.1 for ; Fri, 22 Jan 2016 07:27:55 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=6wind-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=Q/CHoeU3Sn3dKwYDSnt6FZkisQDyzL1ADXYkEnzrPf4=; b=qd6rv6qqXui7OJ1Qs+UeQBWsdIgF46RhvyA1Fymbdfal4bv0C82j5OH0xPxsH454xL RfiQ0tWr27szaBBn8DyKwIYaqZmywf8LMjvDZWd7UKE1RnhmaREkCdZhG8VE5SgGP6Jy zScXCoHCJ22h5xcDXOwCgLL4qKMJ+vGfmfBrCyfxkZHHLtCXx500TNbGGsEob/t2RG/w 8fGwsn89197H9U/sCaCJjiG73dKZxgZYVYIxF/TQ3jANxxT3YgZl4crZE2NaUHva/33A S8NShnEZoC1O8tlnPAkq6aYOiTP3d6u0tOT93IFuSDhAeuo8bI84E+XMj/8/oMnfOUX2 QbAA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=Q/CHoeU3Sn3dKwYDSnt6FZkisQDyzL1ADXYkEnzrPf4=; b=Tm6f7JxGBn9rlgEfFGtOINzW/w5CMOB2hO72/hlAQmIFg6W7/bBuh26kCEuk35bhET NDIzQee8OQGb/EHyI2oAso7dlF660CFN9duSVDqh3urnonkiqJpRxdWkc8v0A8/WY+2g RXS7QROYxd7W0QDI/Ak8XZ56VMjqXTiAz5qbx3v62gYIm7t/gdMZQS0nzVhJ/rytGR4j pZcnOvVVEra1BL8NsBrosJzAYyo8uTFiWousGKURFqTZ8kJz+zMe/+FOG1CmZ6m60JJl nW8yvqi6pGW2MQKG+YVh67kqnuF7UxwwLl+3r5wuGp56FrPpsyLVSRv+hWgGl74mhPxs Ggcw== X-Gm-Message-State: AG10YOQ+Mcj9e6RO+9W6OrGpB9vcNCUX01K7azU2BPImIzPl+xFO/VbL/2Sm8EIp0GelnJ1K X-Received: by 10.28.17.8 with SMTP id 8mr3916015wmr.65.1453476475732; Fri, 22 Jan 2016 07:27:55 -0800 (PST) Received: from gloops.dev.6wind.com (144.77.126.78.rev.sfr.net. [78.126.77.144]) by smtp.gmail.com with ESMTPSA id w73sm3359464wmw.21.2016.01.22.07.27.54 (version=TLSv1/SSLv3 cipher=OTHER); Fri, 22 Jan 2016 07:27:55 -0800 (PST) From: David Marchand To: dev@dpdk.org Date: Fri, 22 Jan 2016 16:27:39 +0100 Message-Id: <1453476464-31767-5-git-send-email-david.marchand@6wind.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1453476464-31767-1-git-send-email-david.marchand@6wind.com> References: <1453476464-31767-1-git-send-email-david.marchand@6wind.com> Cc: viktorin@rehivetech.com Subject: [dpdk-dev] [PATCH 4/9] pci: rework sysfs parsing for driver X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: patches and discussions about DPDK List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 22 Jan 2016 15:27:56 -0000 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 --- 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