From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wm0-f50.google.com (mail-wm0-f50.google.com [74.125.82.50]) by dpdk.org (Postfix) with ESMTP id 00F11C6AC for ; Fri, 29 Jan 2016 15:49:22 +0100 (CET) Received: by mail-wm0-f50.google.com with SMTP id l66so57665800wml.0 for ; Fri, 29 Jan 2016 06:49:21 -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=377yMuTlsT4JWAxLxpl/PkCU6Ha9W/SOlvWYjuET/oQ=; b=eoR91rohjlF8HLBP94yEnSIxxrlLDl64Xo3IzLMJgL6N0Y5UKKmTRZwQa4r1V5lxnw 7KNd3CiKLJ7V0xMC3rx+jjqgUKii4pj52PokEIvIEc2cMYvxQIsuQp147erqoB+oiG4d XIcEj76kTvEwlEBLZONzbW789rwxZK0kB49WtuHrlGzyxRiuE79DgsLmTMz0FjBKjsTg 0YONMgYHnWn+5DX6qqocc/nB6x88e+DmPQHnq0aJMvvS+1S9tAEvi8CQ/zziyvhK7Y/F bI2HMNB0BQh9zJY9AAIzinGbmeNBLbqt5TPycrqdY+OYbEN+Zr63S1L6WWQwqsv7AdvL g7KA== 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=377yMuTlsT4JWAxLxpl/PkCU6Ha9W/SOlvWYjuET/oQ=; b=Wk/yjINqHSgexOBGB95OwOQwWviiBKH1+cExZEirMJS+wAWGys8McP5RTHfrRaYZse eGkPlSAEJO5OQH30w+NsVTiU1eJ9FxG41DUf2utXSVRblWJJ0ozR49xzq6oWND6wxI78 9qNWY9N7ISfvARVG7MqW1pVOA6etfMXglUxGivCxYn+syd2CwCszrhwrBi/9BpLJwqdp FFSp+uiEcaG4ORpO5pLwgpobiiyBl9jpw/Qey4r4PSSH7HWFGk+yMg61l798zz8KhKEf nFArUpgs3xoYC9hx6YCYPj3ZSW+hUs8OiwY1Jcm9o35yOKuED790WoduHwsyuyPDg5C1 L0UA== X-Gm-Message-State: AG10YORhqCVmF4Oiyu8uK3V1oPpGsIOkoNl5d6KIvXsxzPKFjEEVVB3oXGizoLc7LHEIXjvl X-Received: by 10.28.229.20 with SMTP id c20mr8871132wmh.79.1454078961870; Fri, 29 Jan 2016 06:49:21 -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 y188sm7811294wmy.11.2016.01.29.06.49.20 (version=TLSv1/SSLv3 cipher=OTHER); Fri, 29 Jan 2016 06:49:21 -0800 (PST) From: David Marchand To: dev@dpdk.org Date: Fri, 29 Jan 2016 15:49:07 +0100 Message-Id: <1454078953-23744-4-git-send-email-david.marchand@6wind.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1454078953-23744-1-git-send-email-david.marchand@6wind.com> References: <1453476464-31767-1-git-send-email-david.marchand@6wind.com> <1454078953-23744-1-git-send-email-david.marchand@6wind.com> Cc: viktorin@rehivetech.com Subject: [dpdk-dev] [PATCH v2 3/9] pci/linux: 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, 29 Jan 2016 14:49:22 -0000 There is no use for pci_get_kernel_driver_by_path() apart recognising kernel driver and fill kdrv field. Signed-off-by: David Marchand --- Changes since v1: - updated the commitlog, Huawei already did the "unknown" -> "none" change, so this patch ends up just refactoring code --- 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 6751b48..c3118fc 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