From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from NAM03-CO1-obe.outbound.protection.outlook.com (mail-co1nam03on0087.outbound.protection.outlook.com [104.47.40.87]) by dpdk.org (Postfix) with ESMTP id 4E40B7DEC for ; Fri, 14 Oct 2016 12:54:25 +0200 (CEST) Received: from DM2PR03CA0001.namprd03.prod.outlook.com (10.141.96.11) by BY2PR03MB331.namprd03.prod.outlook.com (10.141.139.20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P384) id 15.1.587.9; Fri, 14 Oct 2016 10:54:22 +0000 Received: from BL2FFO11FD018.protection.gbl (2a01:111:f400:7c09::171) by DM2PR03CA0001.outlook.office365.com (2a01:111:e400:2428::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P384) id 15.1.669.12 via Frontend Transport; Fri, 14 Oct 2016 10:54:22 +0000 Authentication-Results: spf=fail (sender IP is 192.88.168.50) 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.168.50 as permitted sender) receiver=protection.outlook.com; client-ip=192.88.168.50; helo=tx30smr01.am.freescale.net; Received: from tx30smr01.am.freescale.net (192.88.168.50) by BL2FFO11FD018.mail.protection.outlook.com (10.173.161.36) with Microsoft SMTP Server (version=TLS1_0, cipher=TLS_RSA_WITH_AES_256_CBC_SHA) id 15.1.629.5 via Frontend Transport; Fri, 14 Oct 2016 10:54:22 +0000 Received: from Tophie.ap.freescale.net ([10.232.14.87]) by tx30smr01.am.freescale.net (8.14.3/8.14.0) with ESMTP id u9EAs938011436; Fri, 14 Oct 2016 03:54:19 -0700 From: Shreyansh Jain To: CC: , , , Shreyansh Jain Date: Fri, 14 Oct 2016 16:25:27 +0530 Message-ID: <1476442527-30726-5-git-send-email-shreyansh.jain@nxp.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1476442527-30726-1-git-send-email-shreyansh.jain@nxp.com> References: <1474985551-14219-1-git-send-email-shreyansh.jain@nxp.com> <1476442527-30726-1-git-send-email-shreyansh.jain@nxp.com> X-EOPAttributedMessage: 0 X-Matching-Connectors: 131209160622987484; (91ab9b29-cfa4-454e-5278-08d120cd25b8); () X-Forefront-Antispam-Report: CIP:192.88.168.50; IPV:NLI; CTRY:US; EFV:NLI; SFV:NSPM; SFS:(10009020)(6009001)(7916002)(2980300002)(1109001)(1110001)(339900001)(189002)(199003)(81156014)(2906002)(92566002)(6916009)(2950100002)(356003)(86362001)(575784001)(8666005)(36756003)(7846002)(586003)(11100500001)(4326007)(2351001)(189998001)(105606002)(106466001)(305945005)(33646002)(47776003)(50466002)(19580405001)(97736004)(48376002)(8676002)(6666003)(81166006)(229853001)(104016004)(19580395003)(68736007)(50986999)(87936001)(85426001)(110136003)(50226002)(77096005)(626004)(5003940100001)(76176999)(5660300001)(8936002)(7059030); DIR:OUT; SFP:1101; SCL:1; SRVR:BY2PR03MB331; H:tx30smr01.am.freescale.net; FPR:; SPF:Fail; PTR:InfoDomainNonexistent; MX:1; A:1; LANG:en; X-Microsoft-Exchange-Diagnostics: 1; BL2FFO11FD018; 1:wuV7F7cn8d6lqFwaKR/VbWXue90p7EEHpvC6KDaU63DWEGaHME6aZJqfUvwY7gARxVhMeQSHDqf/7mGxiNtVocujemyRIz6shzPf6gpV+HyXlQcTOZTHOGP85G/mf+LuITHPva0uJCmQs0aj1EdUVAwZf0Osrqq9w7/vD/48QynXULzCAyn6ExFBNo26d43hUdTVVKz1RxgWwLmxsaRryqK5z7TfyNvNneQdyrC6tb7olhoSSYb3yMcsxv0WcvVq3Z4FjMKj0YEVuhVfant60gBgmc+uavKBRzD777eA4odZDU55KYjWf9bCoEoxg310psC9d4nGtZM4jBP7OltTZ3mOx2sYxcR2mlOhCUEVeiNIXIH/rrNdqdpwF5ZdH970MBN7Nn4gP8/Xb0jUiK5usuvLoOxFernbnC2TGKLZbyaHdyA4AkEifTPIyQXLm19ctIXPuiJHBexwh5TcQ0sAXhfzKhPYCa6PMXd4Yjmzyf1j7P3o5hKSSdlPIOkPgFSMYY9esjAS+vcrPP4KMSy2HKFgNk0S40q3zR6V2d4tiyVd/c+hUy9CKtfGFcIbtxDI9SeNTaJavOTusVRipRl929YrD5m+clveYpilr1E1FSYjMueb/HDzJvfiYjskjp2vBHkQSbYe74qiv/SkROApp59jEfa5M9pA6/DJNQbjY3FIYGJlyVJBjLzD9fcA/HaH5Kjnv+/vVxOba1O69UVZR48qrfrrGU+2OxlBPWwCxpY= MIME-Version: 1.0 Content-Type: text/plain X-MS-Office365-Filtering-Correlation-Id: 68d7f7a8-82d8-4713-777b-08d3f42074aa X-Microsoft-Exchange-Diagnostics: 1; BY2PR03MB331; 2:XV3ymK95aAJF6frc8p/uibJI1zkVnS/GVwGudPrx1062oygt0YiRq67qVcg/1BZzRL0P3bfnBU6Um0dmzVMMp60hL2pStwGOKT943GKfi3A+lFG2Arc1SC/g4OeYzBQv16O41hvl2QIcsA3C9rKvLZPLbe+E6QzBFXPwRvpVZr29QnJxxxmVcxqFsKbivw49; 3:kD7xtGkriXhDFaOVPmcPY5hhndtNducISEuAtZeOedON3FgaVMyve2qplzx4bVn7VFvGd/jK76J9zmvIyveGkvKRa9AXVL+rVBP8piPPQ2IMlUhF3+kTIW98Ae/iEYIobiXpNRdyN5vhP21R5a3NsP7tjtDgGmLw2bsSENd7vNo6PjS+UQzoxjmcsh9oKtqk42U9E1GAZDSOzLdiV4b2TXR1oTDMxioN+2vDJ0Ds0sY=; 25:Zpa4cmzS58UlxmRzEtVqrm7QHu+VBl11+3MYw0cmVhE1U9t5tQaWraxXix1J/ccuDrKbSj9eboSyZMGlcaoWpMiWn4XwTZG5Q3hvbiTfAYicSGf19KgK46A9e7GO0vQx+zXdS7LFBii+uRujXW/g30AjvshtX7ET9nhtWfLY+SCfhwzUbgCvApX7X0gLpotndDEXU7tgrMxMowfD9+DGOybW5IH4891E+fMHu/abO2NYIurl3yVatMZaQ68WXQpxTi1/syTVphCYIRVS+O1bvK6ttL7GHeUyacx/PsDQpCEOvg6mk+wVoXpJ3WXCCW/fagaxDmiLWopfdc28K4tiTryY2y9ar5LgQ5TAYHjpKYVqTlHAwl0adiRmyURsEr+I3y1S8mkzXBgSiGwjMquoGJ0SEe50zGs2sxR+aZx77ukZhZIkQ69ZkbWm7CBVX6fJ X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:;SRVR:BY2PR03MB331; X-Microsoft-Exchange-Diagnostics: 1; BY2PR03MB331; 31:jWCmeUC01grW132jmXY4PMQtF5dCA4a21vHHiMS1W83iBYKMbesmLLVBnzQWblz2ULxAdmysnSWBbkKaRJdacIWmezOTYi27PTk2tfRbhls4xJJxATUMuGrMTjtONpAFpzP/RVu9TPEhA+Jp5XkP3Y57aAzSHpv5R3QFbcrV04CSRAcvZfq+4TbHU4QP7ka+7wctfr6QiFIHyPJqtMouAa38JjPtqNU5rWcs9fMAyPBKXvnoxEcJ1AoWuRMaL2635urowYISp8w5gB2Oa/BUtg==; 4:2rgs8wAr4Xf3VHF93s7fasfY9ishJaES3k3PkkOy1/JhaNQic2jjn9276+5/KdJzEjD5ZaNrSKOE+5mwBZsUYen/zItYlJs4SN5NqppoffSR3luIa8sNP+I61jJqTL7YehIBRROU3chjla6mkV7CktnTysklaiWCkxUFmxhZVj9HkscXuLKC+3EOKY3k4GnruFJunYDoCnnasVs5mp63o+o2RdzwPqrbMwaloj6MzC5rcfneEdN8Q1sQeDO+5gOOsxdLZ3pBM398G3UDfmIK/mBa4mfG8g4PHhOXolaGnIah4c8EbA2XAUp5QFm+Tqca4BVQ4r5mZ8kpRpjxV/5qlrWst/RujUVdS+0bIuns5qkL2Xo749AV4Vy4l2m1mUA0ReAXUbr93nJ8nHz258QUXZx6QvYSZzoK8nj3llXpjuFBFhbVKQUZoMifKXAf8ESgPGPt6dOWzbnwu0obLycQ1VizybaIfNKm/v9BGUBIvNoLvbPm2DSVkkSq9pq+VGAI+rX7IyMkCLzN2Pd1+GDNHody/8w0UVwz0MHLtc7m0qk= 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)(5005006)(8121501046)(13023025)(13017025)(13015025)(13018025)(13024025)(3002001)(10201501046)(6055026); SRVR:BY2PR03MB331; BCL:0; PCL:0; RULEID:(400006); SRVR:BY2PR03MB331; X-Forefront-PRVS: 0095BCF226 X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; BY2PR03MB331; 23:bdZ+cRyVqJ1wOV4knpbjZj1IN/xkvKUy3SjnFfqkpP?= =?us-ascii?Q?0vnbXvvaZXRolDrEoviESlq5jS3iPivYsDgcPssAYAU0pKejZf/LYMDldsKU?= =?us-ascii?Q?3oFH8UJzRKLs6Ml9IBjOQpUla/QHHyPezIuiL1zR61my0bb8fZH1FQ87Y87l?= =?us-ascii?Q?/7U+fO6zdhHe4wgEBl2U66P2IPsmOpWQbmJh3RnlLE9vAmK6Z4r+p8I3Nm/T?= =?us-ascii?Q?IfdcNo/v9W4gu7vrK3osQ+SC44LgnMp4FZneHlgXVDkn9fxpcFTFWqx/Bjbp?= =?us-ascii?Q?gsIIO9KrH37/2bmPc76VIwGDl8pcm7hBPb1SmFd/m4+HYR5h6pWJBHrtsMBt?= =?us-ascii?Q?TI+62yhHtCUGZm5MpIudf8OrC45e8wuP4Whw08FUzx6QN49cL83TjTSf67Xg?= =?us-ascii?Q?zbX+9js/9X4I23IPDNfohZO5XQAOMVYgeYBk6yGUCN09ut4+wZnquT0Iot/p?= =?us-ascii?Q?igRaNiM6ODdIWwwUDGNT6VptsIhXpogWKiIwSc2MjAxVeX4aY+XNFoEe+Jfk?= =?us-ascii?Q?2GwPE9XAjI6A6NKOHocbq8jqnB+V9Thn2Rp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9/IeZCSV/O00fzefZyAteSjJYjEQkJ/1r1jOshNuQUgpDhmXKcuBzb+f+nIBgqZo+oEzsjqKsr3mRgn74f5Ip/g9/uCJSIOy2BZq0QoA4CPFR4oYDk8KWltA/K/KmLI=; 5:RUHtm0BBQEqsfwsNVSEX/ViugV2iuLu/BlubH8jSEJu9qbuwZKVYetHSjuyt4I/5S8A2SBxTyusjtLyQfzLvc6Yyw2KX3V4e8WzHioREv1Ru3zzO4+wj6T4lI5ZEB9vMg7Lq2oqvxtVV2X3/g85NmXVBwXlgQphLjuYqxvplqeo=; 24:u41Z2stymjgOQlGVEadta0hpuCxNTghqM6hcM8ciqan+KQgh5CfNVMUWeHbjfcOXYDHFoh+GH59JVnmWR1FWzJJwK/EEOMbb91QDbn9wUDU=; 7:TXj96NZdHhhc9M8tJGTz0x/LTZKT4BdiLUdZcWz98hSlZyeq63EcDYiMpo6QKooMo/Y0sJqdIhyloHdyRN7azHJFNKRlvA1IDcXdH8VDE4H5bOEd53J5cC9AM7+FxU7fTjZDP3eMZqNBb/ftD91JYoxv+EWfwhv0/YVy5c9jrd/J+rVtLZrx1uvqtQFt9my3ZZ5VE2cYO3X0iGkwCF35Vg2zuIDxW/4u6D49BHu6qd68TXjdZijiyz0zv9Fvj+Smz7Tv6KInmRmXLloJrTBhpkW9EdB/6bviCKfpNsDnMLw8LbFoXmKBPfKOLGVWmShSabjWydRU/6PByk+KVq80iQ== SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-MS-Exchange-CrossTenant-OriginalArrivalTime: 14 Oct 2016 10:54:22.0491 (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.168.50]; Helo=[tx30smr01.am.freescale.net] X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BY2PR03MB331 Subject: [dpdk-dev] [PATCH v2 4/4] eal/linux: generalize PCI kernel driver extraction 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: Fri, 14 Oct 2016 10:54:26 -0000 From: Jan Viktorin Generalize the PCI-specific pci_get_kernel_driver_by_path. The function is general enough, we have just moved it to eal.c, changed the prefix to rte_eal and provided it privately to other parts of EAL. Signed-off-by: Jan Viktorin Signed-off-by: Shreyansh Jain -- Changes since v1: - update BSD support for unbind kernel driver --- lib/librte_eal/bsdapp/eal/eal.c | 7 +++++++ lib/librte_eal/common/eal_private.h | 14 ++++++++++++++ lib/librte_eal/linuxapp/eal/eal.c | 29 +++++++++++++++++++++++++++++ lib/librte_eal/linuxapp/eal/eal_pci.c | 31 +------------------------------ 4 files changed, 51 insertions(+), 30 deletions(-) diff --git a/lib/librte_eal/bsdapp/eal/eal.c b/lib/librte_eal/bsdapp/eal/eal.c index 5271fc2..9b93da3 100644 --- a/lib/librte_eal/bsdapp/eal/eal.c +++ b/lib/librte_eal/bsdapp/eal/eal.c @@ -640,3 +640,10 @@ rte_eal_unbind_kernel_driver(const char *devpath __rte_unused, { return -ENOTSUP; } + +int +rte_eal_get_kernel_driver_by_path(const char *filename __rte_unused, + char *dri_name __rte_unused) +{ + return -ENOTSUP; +} diff --git a/lib/librte_eal/common/eal_private.h b/lib/librte_eal/common/eal_private.h index b0c208a..c8c2131 100644 --- a/lib/librte_eal/common/eal_private.h +++ b/lib/librte_eal/common/eal_private.h @@ -269,6 +269,20 @@ int rte_eal_check_module(const char *module_name); int rte_eal_unbind_kernel_driver(const char *devpath, const char *devid); /** + * Extract the kernel driver name from the absolute path to the driver. + * + * @param filename path to the driver ("/driver") + * @path dri_name target buffer where to place the driver name + * (should be at least PATH_MAX long) + * + * @return + * -1 on failure + * 0 when successful + * 1 when there is no such driver + */ +int rte_eal_get_kernel_driver_by_path(const char *filename, char *dri_name); + +/** * 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 5f6676d..00af21c 100644 --- a/lib/librte_eal/linuxapp/eal/eal.c +++ b/lib/librte_eal/linuxapp/eal/eal.c @@ -969,3 +969,32 @@ error: fclose(f); return -1; } + +int +rte_eal_get_kernel_driver_by_path(const char *filename, char *dri_name) +{ + 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; + + path[count] = '\0'; + + name = strrchr(path, '/'); + if (name) { + strncpy(dri_name, name + 1, strlen(name + 1) + 1); + return 0; + } + + return -1; +} diff --git a/lib/librte_eal/linuxapp/eal/eal_pci.c b/lib/librte_eal/linuxapp/eal/eal_pci.c index a03553f..e1cf9e8 100644 --- a/lib/librte_eal/linuxapp/eal/eal_pci.c +++ b/lib/librte_eal/linuxapp/eal/eal_pci.c @@ -78,35 +78,6 @@ pci_unbind_kernel_driver(struct rte_pci_device *dev) return rte_eal_unbind_kernel_driver(devpath, devid); } -static int -pci_get_kernel_driver_by_path(const char *filename, char *dri_name) -{ - 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; - - path[count] = '\0'; - - name = strrchr(path, '/'); - if (name) { - strncpy(dri_name, name + 1, strlen(name + 1) + 1); - return 0; - } - - return -1; -} - /* Map pci device */ int rte_eal_pci_map_device(struct rte_pci_device *dev) @@ -354,7 +325,7 @@ 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); + ret = rte_eal_get_kernel_driver_by_path(filename, driver); if (ret < 0) { RTE_LOG(ERR, EAL, "Fail to get kernel driver\n"); free(dev); -- 2.7.4