From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from NAM01-SN1-obe.outbound.protection.outlook.com (mail-sn1nam01on0075.outbound.protection.outlook.com [104.47.32.75]) by dpdk.org (Postfix) with ESMTP id 231625589 for ; Thu, 1 Sep 2016 06:42:29 +0200 (CEST) Received: from DM2PR03CA0041.namprd03.prod.outlook.com (10.141.96.40) by BN6PR03MB2436.namprd03.prod.outlook.com (10.168.223.14) with Microsoft SMTP Server (version=TLS1_0, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA_P384) id 15.1.599.9; Thu, 1 Sep 2016 04:42:26 +0000 Received: from BY2FFO11FD002.protection.gbl (2a01:111:f400:7c0c::185) by DM2PR03CA0041.outlook.office365.com (2a01:111:e400:2428::40) with Microsoft SMTP Server (version=TLS1_0, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA_P384) id 15.1.599.9 via Frontend Transport; Thu, 1 Sep 2016 04:42:26 +0000 Authentication-Results: spf=fail (sender IP is 192.88.158.2) smtp.mailfrom=nxp.com; nxp.com; dkim=none (message not signed) header.d=none;nxp.com; dmarc=fail action=none header.from=nxp.com;nxp.com; dkim=none (message not signed) header.d=none; Received-SPF: Fail (protection.outlook.com: domain of nxp.com does not designate 192.88.158.2 as permitted sender) receiver=protection.outlook.com; client-ip=192.88.158.2; helo=az84smr01.freescale.net; Received: from az84smr01.freescale.net (192.88.158.2) by BY2FFO11FD002.mail.protection.outlook.com (10.1.14.124) with Microsoft SMTP Server (version=TLS1_0, cipher=TLS_RSA_WITH_AES_256_CBC_SHA) id 15.1.587.6 via Frontend Transport; Thu, 1 Sep 2016 04:42:24 +0000 Received: from Tophie.ap.freescale.net ([10.232.14.87]) by az84smr01.freescale.net (8.14.3/8.14.0) with ESMTP id u814g8R2029498; Wed, 31 Aug 2016 21:42:21 -0700 From: Shreyansh Jain To: , CC: , Shreyansh Jain Date: Thu, 1 Sep 2016 10:11:54 +0530 Message-ID: <1472704915-13112-5-git-send-email-shreyansh.jain@nxp.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1472704915-13112-1-git-send-email-shreyansh.jain@nxp.com> References: <1472704915-13112-1-git-send-email-shreyansh.jain@nxp.com> X-EOPAttributedMessage: 0 X-Matching-Connectors: 131171785459832565; (91ab9b29-cfa4-454e-5278-08d120cd25b8); () X-Forefront-Antispam-Report: CIP:192.88.158.2; IPV:NLI; CTRY:US; EFV:NLI; SFV:NSPM; SFS:(10009020)(6009001)(7916002)(2980300002)(1110001)(1109001)(339900001)(189002)(199003)(229853001)(36756003)(586003)(8676002)(50986999)(50226002)(5001770100001)(97736004)(77096005)(76176999)(33646002)(2906002)(189998001)(8936002)(5660300001)(8666005)(305945005)(68736007)(48376002)(81156014)(106466001)(69596002)(81166006)(50466002)(7846002)(86362001)(19580395003)(92566002)(575784001)(104016004)(47776003)(356003)(19580405001)(87936001)(5003940100001)(85426001)(4326007)(626004)(11100500001)(105606002)(2950100001)(7059030); DIR:OUT; SFP:1101; SCL:1; SRVR:BN6PR03MB2436; H:az84smr01.freescale.net; FPR:; SPF:Fail; PTR:InfoDomainNonexistent; MX:1; A:1; LANG:en; X-Microsoft-Exchange-Diagnostics: 1; BY2FFO11FD002; 1:RxRx/FVyXboXbhc1OJkNHT2vrjiyfQR15L523++IK7GY+XKo21t9xLeGsoA9f1JlmEC6wnCvYlKOdvqVmjvbpZCcO68CBWhf5Ggbg8boUN5HOZ38sWXJGmX3Lw7qC3GaYm0VgYf4qnWMLCF9MPK403/3g9bk6JLHrMgcvMv9eV8jcoHA/FSLhV1fh8Lo+xq+Nh3XGTdgBRzwVyW1mtexnUv97QpBB8pzP///YDXb4DlZhbxEkBG4f7JelAeI19BbBrI55aEpjb1J0ML51GLAos+5xhVrK123xDaUT6oZWKXymT0YoAgqVxFO+EqpkdVBFgaY/xVNY9IUZszo9ghg3WyvVpi9oEvR/lyW9f/QtbvpzrtJPTcUZHl2+KXLosV7bruX6MTOwcHi9GX57MjOI0B+ajMJADEiSYf0MAe3B0Sm9Dhj+LBRhR2NMlDYunovti+7Y5XdsdhRKzVxJmDRrhaLrW+TlQg4G1iuOu6ZC0Es3BWHHhQlGU5xfk5PIkCPQj2YzjBwoAd1Dod5rSZYuPl+PImKPxCn8YelTD5+Vr7hhzD3Mf03DBjA6OuQ1WIlYdN1Hfynmgr0Jh0T3C25MetmdVKie8w7obFanINUuF0UxNwlyy4Y0XMu5MCgI4145GUsLwOT24bsktUZOk/FiVuM/irFeDn68tJNAbIRlFXt0SFOnY1NQESFY0pkO2RnRGW9Az9hMj+WXbhc8w2rvwLDqibq772K5D8CY37F47A= MIME-Version: 1.0 Content-Type: text/plain X-MS-Office365-Filtering-Correlation-Id: 9c48b649-70ea-48ec-b594-08d3d2225f57 X-Microsoft-Exchange-Diagnostics: 1; BN6PR03MB2436; 2:fcjI1NQY0XdCaVjvYibkZi7mndGP+Qy7ANUIR5m7coKlsL5PYpYTZv3CoaH0+rBet3c48sypaTdcd8HUtaNJU2a5ud2uYbzH6aZMIKCO0jC62MG/7vQymO2BENnCrF6fnwoZwAk35tKSKkk13htx2es4iLwxB6qoRm+aRriYwzBuNMAHm2ngEXBVtXNANqA6; 3:1Nt14y+1B6olmUZerwP78L90r9AL2fIvEHJVxBbf7Qi3+4US61K5ixdWVi/JqomoHoBJe9hO4QpxgG8m/Zcls1wKiCxt0CqllhAJAE9BlZSfKk0b6NBGb4+H0/t2O/CSzM6BeLXlhLoiZ9Q83xW8Ja7GlxMP59Oc/0IsBjQbJwqgdALpddUaJEVllI7keP4Chp8xJEWqNOYydB1LKOOpBKfJtELwB40+a9VxtVtqH1Q=; 25:L8KI1HY9h/5WWvzOQ0Azjdh2W01P26pUJSe0IWK6YqV/y/rjwP3QrGXGBSfDdPxr2twpS2i2tOEHyS2SRmCfJAZbmQL+OXuiaShfBO/BxIeMt10NgSFivqrzpRlP09egV/WtsUopn4+HG6hEoyIDKj7foZzTjpUW7J0xZSVrF9mGch0d3OoWoPTjUv//XKI1n7iKXuoaFfsD83hmF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zFOaJ4nVm66ggnwU1AkVaaOZZuU4K0p4Xs3ss= X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(185117386973197); X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(6040176)(601004)(2401047)(13017025)(8121501046)(5005006)(13015025)(13024025)(13023025)(13018025)(3002001)(10201501046)(6055026); SRVR:BN6PR03MB2436; BCL:0; PCL:0; RULEID:(400006); SRVR:BN6PR03MB2436; X-Forefront-PRVS: 0052308DC6 X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; BN6PR03MB2436; 23:AXQIEQHOnLGmtKkzRcJn3ryH1AlFHD/KwWXXIKpvn?= =?us-ascii?Q?NQvUdQ7I/ZSjtgdWdbnyqKlx1D2erNzPmP8FrZTWv8l3armNJ/tZ0v+mkfPD?= =?us-ascii?Q?xBffJ1booIsi7Z1OaAciJHpzfBWrtQEm4bOaqLIUJHmtzL/JttLBNB9K31Ly?= =?us-ascii?Q?Y9F/+dYRMs8jLmDJrinyRBNExHIEa0jX4eP4NiUl2JuGohHPAmRjs6hdjCNx?= =?us-ascii?Q?ZEGKHP7A+OxLN5ZjFDD/oPl1ozxL332HCbTg0t2YdGmf+JFVJ4Zy10M0x1L4?= =?us-ascii?Q?HxPd2/FropXjLcRhJEuh4/fmD6s4/Jp6AOY8xkefHVh9urC4Z1futAozdGil?= =?us-ascii?Q?0t0K0kpcdhx1YLKrE76lgc9OW6aQZzzw7Dn/juyHkSaZI3v5khUOTivBBnM0?= =?us-ascii?Q?jclqAwHYHk9l92BhPiEppgqsO40kM7h5Xy55Kpzffikqwwaz2IZMwR2uCQJ4?= =?us-ascii?Q?acUwy5KOJcaUYOu1lsDbTJq2iuX6P51+UReIfbzuFxI+Kwok+E0/Dg8jsnPI?= =?us-ascii?Q?pXWl5KZ7730VyPMNJywBjRbUG2e7/oz8Ctuq/2Y6vEVvC4WpQQCDtPlKVKkf?= =?us-ascii?Q?+/8hOOH+7TZsLRbnAJ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XjL9rrP+Yew=; 5:WAW3xa+/b3cZv4oCzhbGO4S/eq+aflAqFS3ZGsQAvK7sEr3KP+yJpwrZi6ck1JwCqspm8rSf04OIvhNMNSnUXw+KcsxYAkkYkQpL3K6x+ZsMJg6u/urCVrjNCc2asOf0Yp8+wEfxb74Z4bD4E4oRLYjKodyLtutnENYOigoo4nw=; 24:nQjWdvH8qsnYOv+jytKhriaRS0ROTbTfqhsV86dGz/xUSTa1rYKu5i/8Q/fv7DuG3ab8NqvybqM02z521NQZ/6kjh40oQf9txwhvfLOegYg=; 7:DbTqI6Oyg/FvMxeA4RrHs2HK3g6L4zvG/IPHpqUNuxnZi3L7OTl/fULRD7NcsYSc13024Ixp04owT2SlIWeYi67M5zD+hSQu0LH9OwopRF/oS8ux+sWpHAItKVkZzjl2JSRGrrCAJDohFWRKgMY6lPgqfdpp4hNt7gkpsz6BKfNkhQPZRVRo819QfdodfG/lhhShnA9P/+ybbYr9L45mozM6pfNeRF8Sm3U29Lwg7vegOWndJ1ebQZmZhSu5c74E SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-MS-Exchange-CrossTenant-OriginalArrivalTime: 01 Sep 2016 04:42:24.4544 (UTC) X-MS-Exchange-CrossTenant-Id: 5afe0b00-7697-4969-b663-5eab37d5f47e X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=5afe0b00-7697-4969-b663-5eab37d5f47e; Ip=[192.88.158.2]; Helo=[az84smr01.freescale.net] X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BN6PR03MB2436 Subject: [dpdk-dev] [PATCH 4/5] eal/linux: extract function rte_eal_unbind_kernel_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: Thu, 01 Sep 2016 04:42:29 -0000 From: Jan Viktorin From: Jan Viktorin Generalize the PCI-specific pci_unbind_kernel_driver. It is now divided into two parts. First, determination of the path and string identification of the device to be unbound. Second, the actual unbind operation which is generic. Signed-off-by: Jan Viktorin Signed-off-by: Shreyansh Jain --- lib/librte_eal/common/eal_private.h | 13 +++++++++++++ lib/librte_eal/linuxapp/eal/eal.c | 26 ++++++++++++++++++++++++++ lib/librte_eal/linuxapp/eal/eal_pci.c | 33 +++++++++------------------------ 3 files changed, 48 insertions(+), 24 deletions(-) diff --git a/lib/librte_eal/common/eal_private.h b/lib/librte_eal/common/eal_private.h index 19f7535..0740c0c 100644 --- a/lib/librte_eal/common/eal_private.h +++ b/lib/librte_eal/common/eal_private.h @@ -258,6 +258,19 @@ int rte_eal_dev_init(void); int rte_eal_check_module(const char *module_name); /** + * Unbind kernel driver bound to the device specified by the given devpath, + * and its string identification. + * + * @param devpath path to the device directory ("/sys/.../devices/") + * @param devid identification of the device () + * + * @return + * -1 unbind has failed + * 0 module has been unbound + */ +int rte_eal_unbind_kernel_driver(const char *devpath, const char *devid); + +/** * 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 f912e4e..8711d9a 100644 --- a/lib/librte_eal/linuxapp/eal/eal.c +++ b/lib/librte_eal/linuxapp/eal/eal.c @@ -947,3 +947,29 @@ rte_eal_check_module(const char *module_name) /* Module has been found */ return 1; } + +int +rte_eal_unbind_kernel_driver(const char *devpath, const char *devid) +{ + char filename[PATH_MAX]; + FILE *f; + + snprintf(filename, sizeof(filename), + "%s/driver/unbind", devpath); + + f = fopen(filename, "w"); + if (f == NULL) /* device was not bound */ + return 0; + + if (fwrite(devid, strlen(devid), 1, f) == 0) { + RTE_LOG(ERR, EAL, "%s(): could not write to %s\n", __func__, + filename); + goto error; + } + + fclose(f); + return 0; +error: + fclose(f); + return -1; +} diff --git a/lib/librte_eal/linuxapp/eal/eal_pci.c b/lib/librte_eal/linuxapp/eal/eal_pci.c index cd9de7c..4792d05 100644 --- a/lib/librte_eal/linuxapp/eal/eal_pci.c +++ b/lib/librte_eal/linuxapp/eal/eal_pci.c @@ -59,38 +59,23 @@ int pci_unbind_kernel_driver(struct rte_pci_device *dev) { int n; - FILE *f; - char filename[PATH_MAX]; - char buf[BUFSIZ]; + char devpath[PATH_MAX]; + char devid[BUFSIZ]; struct rte_pci_addr *loc = &dev->addr; - /* open /sys/bus/pci/devices/AAAA:BB:CC.D/driver */ - snprintf(filename, sizeof(filename), - "%s/" PCI_PRI_FMT "/driver/unbind", pci_get_sysfs_path(), + /* devpath /sys/bus/pci/devices/AAAA:BB:CC.D */ + snprintf(devpath, sizeof(devpath), + "%s/" PCI_PRI_FMT, pci_get_sysfs_path(), loc->domain, loc->bus, loc->devid, loc->function); - f = fopen(filename, "w"); - if (f == NULL) /* device was not bound */ - return 0; - - n = snprintf(buf, sizeof(buf), PCI_PRI_FMT "\n", + n = snprintf(devid, sizeof(devid), PCI_PRI_FMT "\n", loc->domain, loc->bus, loc->devid, loc->function); - if ((n < 0) || (n >= (int)sizeof(buf))) { + if ((n < 0) || (n >= (int)sizeof(devid))) { RTE_LOG(ERR, EAL, "%s(): snprintf failed\n", __func__); - goto error; - } - if (fwrite(buf, n, 1, f) == 0) { - RTE_LOG(ERR, EAL, "%s(): could not write to %s\n", __func__, - filename); - goto error; + return -1; } - fclose(f); - return 0; - -error: - fclose(f); - return -1; + return rte_eal_unbind_kernel_driver(devpath, devid); } static int -- 2.7.4