From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from NAM03-CO1-obe.outbound.protection.outlook.com (mail-co1nam03on0072.outbound.protection.outlook.com [104.47.40.72]) by dpdk.org (Postfix) with ESMTP id 7D0EE2B8C for ; Tue, 27 Sep 2016 16:12:33 +0200 (CEST) Received: from BN3PR0301CA0047.namprd03.prod.outlook.com (10.160.152.143) by BN1PR0301MB0705.namprd03.prod.outlook.com (10.160.78.12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P384) id 15.1.639.5; Tue, 27 Sep 2016 14:12:31 +0000 Received: from BL2FFO11OLC002.protection.gbl (2a01:111:f400:7c09::191) by BN3PR0301CA0047.outlook.office365.com (2a01:111:e400:401e::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P384) id 15.1.639.5 via Frontend Transport; Tue, 27 Sep 2016 14:12:31 +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 BL2FFO11OLC002.mail.protection.outlook.com (10.173.161.186) with Microsoft SMTP Server (version=TLS1_0, cipher=TLS_RSA_WITH_AES_256_CBC_SHA) id 15.1.629.5 via Frontend Transport; Tue, 27 Sep 2016 14:12:31 +0000 Received: from Tophie.ap.freescale.net ([10.232.14.87]) by az84smr01.freescale.net (8.14.3/8.14.0) with ESMTP id u8REBqcg027766; Tue, 27 Sep 2016 07:12:28 -0700 From: Shreyansh Jain To: CC: , , , Shreyansh Jain Date: Tue, 27 Sep 2016 19:42:30 +0530 Message-ID: <1474985551-14219-4-git-send-email-shreyansh.jain@nxp.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1474985551-14219-1-git-send-email-shreyansh.jain@nxp.com> References: <1472704915-13112-1-git-send-email-shreyansh.jain@nxp.com> <1474985551-14219-1-git-send-email-shreyansh.jain@nxp.com> X-EOPAttributedMessage: 0 X-Matching-Connectors: 131194591515153493; (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)(1109001)(1110001)(339900001)(199003)(189002)(104016004)(229853001)(2351001)(626004)(85426001)(8936002)(5660300001)(36756003)(87936001)(50466002)(5003940100001)(110136003)(19580405001)(48376002)(106466001)(92566002)(19580395003)(11100500001)(77096005)(105606002)(7846002)(50226002)(586003)(47776003)(305945005)(69596002)(50986999)(76176999)(33646002)(356003)(8666005)(6916009)(2950100002)(97736004)(68736007)(2906002)(81166006)(189998001)(4326007)(8676002)(81156014)(575784001)(86362001)(7059030); DIR:OUT; SFP:1101; SCL:1; SRVR:BN1PR0301MB0705; H:az84smr01.freescale.net; FPR:; SPF:Fail; PTR:InfoDomainNonexistent; A:1; MX:1; LANG:en; X-Microsoft-Exchange-Diagnostics: 1; BL2FFO11OLC002; 1:7AU9lSbrAEh8sUj7d0zUt4nkHFrnlAVMmqT84BFtclN9SiuhgNGxAH48lhV0G5C/Prt0uBC3zslkKmvryjDLlVU0lgtrnyJDoiu0aI6/eagTHPcLfww1NY052ryQXpkGh5PuCAMiaRuFg3iPTRJICskpqfK/Q1n8bFu8Kob8W2DGgJyZR3coxD7slVW7VtCEoReJDoQcY+9zCkRmukcJnDdW8g9laYNmGmBhckXBFF2vN0LwFAm5+uFSUzPmk3bj16KN7/LBGG2z2vQx4lQWZAZJvIXL37uTYhBPrfm4m40Wxf+EwlVTedcXD+kaTuYlMiUymYBTx1T7oGvcMnyKpjakJcWCWwzt+R2CtgeB7D/Zv9iNq3lUQWyJjkT3G+OStGCG7TUwch3p9zsNlO0EfMchNzRGn5L3NyjEpi+oO5Y3+lP9+5YuAu0wOn7o55qql6KoB0FbBZFxNHWSPwNyH93ghCk8q+76Ed6qUg6CBS9iCZtQVhtV/JYkITxxM4zhh7k32JA/7I1iNxb/9oL7ThC4U89hQabIAwrsj3OF+Z4Q99SZhZloMbvPmLtVLF/sVlhP0MOXWNUHZgKm9g8yZvZNm8x3k41JXDVFJv0MZj62HB4s6Fc+ki6rOlXlfeqoGN7ggYbiJo+On8oOk0TEnjdlXfiPCi/HpjLQaRSQuTGLrijVG55xqVfAUtZeSwdI4AISk3bsWyvX5hvl7qcTgpuSKkdRJ1NskaLQjk2/Kw4= MIME-Version: 1.0 Content-Type: text/plain X-MS-Office365-Filtering-Correlation-Id: d0c2a24b-a816-4beb-32f6-08d3e6e0522b X-Microsoft-Exchange-Diagnostics: 1; BN1PR0301MB0705; 2:5Npz4pcxev30IhuNmwqn2HdEpIKUTeYz8I7IpFIHrXjTuKONoNu9Z5OQ2b2dU91p7Al5KCHXWPrgn5pc05Ut7c0/gpNB3XAM2hpgoQz6itiuBMAgQT5YO1zdy+6CkQWkKUKvkOjm7WIFs24zu9e+CKe3Zr2+hWp7+Eag+66b0mU+bHObdZ9cDHqqllg1dJAB; 3:Y8ukfnNafyA2TwwVcbyFPn0ZqKzKC+LSFwyt9+sFRVF3SBYn0+yOnMQYfH+uFmalymnHjAUlwfDtc+gpfeCaDaPolBbzNzwcj9ouxPtw+a4H+VKZdj5c8QvzIv7pZwQMnB7nL4ZkFcXJNK04QNB/pgAcrQ0RwZeUAdiuI9TAECd5idQQlThX+83mG6Dx71vs4svoicUVNEJVvjWfGJjuSCLpLBiW3RkpECVlYjEhv4U= X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:;SRVR:BN1PR0301MB0705; X-Microsoft-Exchange-Diagnostics: 1; BN1PR0301MB0705; 25:ooyG3P6KF9A+c1NTQQhs44jK4St0oCMlfpTva2f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BM2o5E5OXuNNdjMhvr/xj2jsbcYOSs/J2C0ibCf/8WB8LUGo6f+ayZk1IltJQ7xptiJLYHDmVwvZwuWMMijuy9gYTo5T04ql4Ln4EvMJnXq0kr69rzvefWRJUV23RfLODBFjnjZThC+bDAiPe0OYrZPp5t1ojRfwc9a1wrZi5g8yuFWU2SWODmgIDfGpYYOeRX+F0iBRXSmrYfXMtobx0L+TDoE7L4KUwFfq/+Sqz99J6I6yoRL3IQ0NiV4MKNe+pvyvg3TAL7BX3m/7qix6Ooy84MzKR2h87n1tG+6H5qeYTMgyBQ5WC0KJtfgD7sc2UGCgCIEswhNQ9js2C5GbFWOLvi0Dv+AKdN3l6D3dnuKTHHyYsLKoo/KbYGlSGFauyin6WAbnyejS7W/EEYstEPG1Nur5An82Ynq1OUjGTafFjJToS7w/iRtcZExLINjszFXIcWh6fGIlijMrKSkHJVjdEDcR7vWNdHlYg7+UVRreupDxdzeGJhk= 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)(13024025)(13023025)(13015025)(13018025)(8121501046)(5005006)(10201501046)(3002001)(6055026); SRVR:BN1PR0301MB0705; BCL:0; PCL:0; RULEID:(400006); SRVR:BN1PR0301MB0705; X-Forefront-PRVS: 007814487B X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; BN1PR0301MB0705; 23:Stc5aLwISs6ar/qtbeDouFPRggcxJcUeHbrNXdI?= =?us-ascii?Q?0GV+IDsouo4k8caWkn8te3MxRUlTfAyRWRrup+zJqPmzOj4Zq0sHgky4RYaS?= =?us-ascii?Q?KEiexsDp82FpeRg2yufkppuA577ErDGJj1a07E+/isrwxNbC95GudgB5OW+E?= =?us-ascii?Q?wj2LCnqcFOTRUYAaJQRuyBOwhBig7Eubl8+WM0qtAXLZ3BYyVqbT7eviAupN?= =?us-ascii?Q?y6RUNyGDwBxpmzPOE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308FuyYrIo7Cbv2C4UP0l3j3BLvNPxJkAeTcu5E5SL4DTwRF153deOvVr SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-MS-Exchange-CrossTenant-OriginalArrivalTime: 27 Sep 2016 14:12:31.2813 (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: BN1PR0301MB0705 Subject: [dpdk-dev] [PATCH v1 3/4] eal/linux: generalize PCI kernel unbinding driver to EAL 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: Tue, 27 Sep 2016 14:12:34 -0000 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 d5b81a3..a9c974b 100644 --- a/lib/librte_eal/linuxapp/eal/eal.c +++ b/lib/librte_eal/linuxapp/eal/eal.c @@ -933,3 +933,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