From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from NAM03-BY2-obe.outbound.protection.outlook.com (mail-by2nam03on0070.outbound.protection.outlook.com [104.47.42.70]) by dpdk.org (Postfix) with ESMTP id EBF6658CF for ; Fri, 28 Oct 2016 14:30:33 +0200 (CEST) Received: from BN3PR0301CA0056.namprd03.prod.outlook.com (10.160.152.152) by BN3PR03MB2372.namprd03.prod.outlook.com (10.166.75.7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P384) id 15.1.693.12; Fri, 28 Oct 2016 12:30:32 +0000 Received: from BN1BFFO11OLC001.protection.gbl (2a01:111:f400:7c10::1:103) by BN3PR0301CA0056.outlook.office365.com (2a01:111:e400:401e::24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P384) id 15.1.693.12 via Frontend Transport; Fri, 28 Oct 2016 12:30:32 +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 BN1BFFO11OLC001.mail.protection.outlook.com (10.58.145.12) with Microsoft SMTP Server (version=TLS1_0, cipher=TLS_RSA_WITH_AES_256_CBC_SHA) id 15.1.679.5 via Frontend Transport; Fri, 28 Oct 2016 12:30:32 +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 u9SCPEMF019399; Fri, 28 Oct 2016 05:30:29 -0700 From: Shreyansh Jain To: Date: Fri, 28 Oct 2016 17:56:20 +0530 Message-ID: <1477657598-826-4-git-send-email-shreyansh.jain@nxp.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1477657598-826-1-git-send-email-shreyansh.jain@nxp.com> References: <1477581467-12588-1-git-send-email-shreyansh.jain@nxp.com> <1477657598-826-1-git-send-email-shreyansh.jain@nxp.com> X-EOPAttributedMessage: 0 X-Matching-Connectors: 131221314323261634; (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)(97736004)(19580395003)(19580405001)(106466001)(105606002)(626004)(7846002)(8666005)(8676002)(5660300001)(68736007)(33646002)(36756003)(189998001)(77096005)(575784001)(229853001)(86362001)(2351001)(11100500001)(110136003)(2950100002)(305945005)(356003)(6916009)(6666003)(104016004)(85426001)(50466002)(47776003)(8936002)(87936001)(586003)(92566002)(48376002)(5003940100001)(4326007)(50986999)(76176999)(50226002)(81156014)(81166006)(2906002)(7059030); DIR:OUT; SFP:1101; SCL:1; SRVR:BN3PR03MB2372; H:tx30smr01.am.freescale.net; FPR:; SPF:Fail; PTR:InfoDomainNonexistent; MX:1; A:1; LANG:en; X-Microsoft-Exchange-Diagnostics: 1; BN1BFFO11OLC001; 1:mtHOT1cIjzTR0WAmJQHZbVnIbvIVZxurxUvwx7eesTJW9n7eB7oIZqll9r9J6iJ9GbUW4UtQIYamkBZ3Saiyw1E0Y2pED5geHVu/5lIZJUgBRBFKOvCYHzhMke6SXZOZuiPGUsaQYwahD6brS6wejEJI32/c2psK2B2wBvAlCdM3zaUI6diWR3rufhS9OgxXQP3VrIYHHNh2uQMDoM8cRRuaiVHS9Xz6gbEYAqRP7sVD+TLiDYO8Wx1Y8O3QvrAHtuq3ykBcmjRty4RhOlqbWsvu6/4G7nBmImIq/EbTgkmEMrpKRHEpGpZ4iYqIlZV694+Tup5Y8d6nVTuq64A5VjqDajpTqPGN7h299NZJcgfqqi48xD9vQihq8fMowsTOkwVEKgE/UuRkXjPpORsKXix1TBPLUXzzEJMNXP7FPbuqmJYwr53P90C1Mw4FgAWEYFvcGT8eOABNZ6IiDuJurjf/vsdPxF4F9XDeyhHjYxaFmTUwEEVtJ6WtwUeTwFDAzjlyHhCUZe+u3PmFUO76EehnUEOQDUq5D5P+/eT2W1DxxUcyQRT9OC3g4YHSjIh/TbT7pbdRM9ZNPHLr9kAhKfiIjJEwVb8DpUVcKCkPBKc0GwF1NQvknqd/jOEMZvGRAVBGYffk1Ox95PpEWtWJpfHfyBzYhDCV02L6DkqbhnQ0hZQ0MqskQ8jaqJz6t2Cf4MjhPLXNHBZD8lg859FvIw46EAcOSbffiMyBQb06n/c= MIME-Version: 1.0 Content-Type: text/plain X-MS-Office365-Filtering-Correlation-Id: 56daaea9-e66a-4385-4768-08d3ff2e35a7 X-Microsoft-Exchange-Diagnostics: 1; BN3PR03MB2372; 2:G3uv4f2bGYAAnhG39P93tAl/FKxo8dkiT1Rnyh59bxrVRG1MhNkFpHgxUACLfqqd4cA0NlgunGrNSn5R/GYkFyEoKWwwEfYb2Onwjo9qB7A8UDLhZsTWQzLs+uaQH28kTObumL4iLNHec4FtBobhE6vCJjeYas1V90bfB2S2zJGyhPutQjlV7UyYOnSN588Y+BPTh0lIo8iKC4ViTPmu+A==; 3:+UaUhOwa9/O+KgvAF2FEnPW92M/uG2QfdPCmzLYqbP/PwYKmx6e4XGMkfqOgwBg+lB4Sis6QmoVYJ/jT31j6D4wRdlZh4TLOtyq8Kv/6sqnIz5aslyPAgt1rd99gbNSiHGXX5BIfelLm4edFLIIDW3qozUuPjBL6FITI5BWkMVrtFS4DV6OXuP1Rb7oBzaNYNGLbVwRvhySNQf//7P3ljK3Bd/qUINJE8v8pHkDPQk+xq8iAZnQJ+5c89pMeUL53 X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:;SRVR:BN3PR03MB2372; X-Microsoft-Exchange-Diagnostics: 1; BN3PR03MB2372; 25:3if1CCkbxtHYB4Kcv7xCFDaAk4yvaP94fDko0dlcijuYp2ZvymL12HM8br9T/WtLOK+zTlnQ8bTXLQdHjHGUFbVx/2RIfFsjdG/J0K2t5URRwDH7uI70Q1LFbNGM7Mg9gKZ6WWcyh1faOj/9wRf6OeRlXZ2DIu7Jq8KqqT2mCfk351k2SGw78Vq3rLvjZGjP/B2myAl34u9LF2n9gcZ2w+Dhh4hgxnQu4WXxvCgqSlaoo7+9z4g3iPp5u93WvtIxItwJyeItw7AmzQmdmTf1LjsC4z329IvmxtPJaKlnfp2P8SrwtVEKzs+SV00aec0I6aSip4VDv9ODobPY0AyUqakhrzhaoMt0AbgLoqnexxLeWCxD/FzwwrThfk6tDEZDr0ZvvBxYd3UNPh+6hSwx8OKFcJo36IBCfCCR1hcq4qvShGRt1gtVWg8Fn8iS8SLQchtfoHMO0uWFAFCl5M9A/w==; 31:E8WnRFi1OtOtsizAi30om4zC4yplNOZ3Gn7REXR1kH8Td/Y0aB9fUu371EEl7O6AAM5Ytr7esM+ZeCN5DL/K81QDYQ1VtX4JsE/XP0DoPSNAzVHaZRRF8ljQEfnjusSuXtHML34FCg+VHDpsr5NOXzspzMzMEag1Xf/SK1jKP2CDTMaLAKcOEEGi6mr89BSikHnkmq3Crd46QmegmlyFeZ+XW9sJQaGeU5/aKN7KQHdOv/RTYl7lc6S8EW2acXvP37BkrrSthNoZbyiwr+pRt26XQTxlx1m1iEJ0DSnf3Pk= 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)(13024025)(13023025)(13015025)(13018025)(13017025)(3002001)(10201501046)(6055026); SRVR:BN3PR03MB2372; BCL:0; PCL:0; RULEID:(400006); SRVR:BN3PR03MB2372; X-Microsoft-Exchange-Diagnostics: 1; BN3PR03MB2372; 4:buDd98EqtJ+U1ytfVRPKaQkwm9TZUFbIaJOPr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ascii?Q?=3D?= X-Microsoft-Exchange-Diagnostics: 1; BN3PR03MB2372; 6:sMtPPxzNPVLq1p9AH9mRFkYUYBx/qPBuxjPMQG//WfNCsexurPI5dMYqlRi97w0+IsTJLfBwZFAaZIJYT3ErIwdeLwAq8RTaA3Do0clmh+lvagY9KOqZ6KEKKt4yH6m1KvIk86hmtOBP95LFNj/jVlV9tmfGKNXYOJDBPyywU7GShwhB5foXnz5yHGE547FE1Tro76p9rWaW81hjy1GvwcioxjbjOzZ+ycJYOyy+CJAkMVpT55sj2ZMSY9JFE75pPm+sDv4DC2cUdiX28lQhi6BciXIT5K/C3EAr/Poo5Q/RtwBlpQm+PjcVdTKS5WA3; 5:r4VevtQErDRxx9hKj/tQjKnHE2kzvFW0xSKUUs/DwnUQHf1GfrtpblYemUmP5O/0SLow3gYR9cGuwZvkL203dLS0suM6Rh274GQySJqYWxeGhARC32x1K1txN5JuAl8uaAY4WflJpwWU2pgu6/kFOSxCgjRr1T9M1XwiJMYmq/ENGMyvNv/J8yZlrpZeHbx4; 24:fdlx1nZhgve4mUvARV50v4fyeZFVzQIN6HbyATEjjX44aVpjHuPgcWqQHR+V3wZMIUSoolasoVAIEN0jluCbbtE/wAyawUY3V6fhf5DJaio= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; BN3PR03MB2372; 7:fLCCUTOwdYnT1bpjKOwUSukTC2l09OJf0sgv8PX8oUe2axiU6n0klO2zoIqZy4FesfevfRXfKh3LnHcv+4efbFL/7+w5aUXwFzZckBckVn7yRWGqIc38hZV+ra4Wg0qBoh/A7qahSq5e12q1XvEfbujUDSR8IOW/UkHzv09Y7o0gFOeaL+SLSwZsL/R1+AlMcSTs81HnQoQZd5zpGoRH4I3OQK4/tGQQpCwZ6XcHJhEoGvzZZI3Ecgx4TljhOlk/1YTlr4FzqkQ2dMT36QSrOK6X6NDNRYzGM664Fs6T/+72r4l33gDtTNlse7l8yw62y+g5tscEyc+Ba19xcPpTkfOZMxuW46PR1oYMXzBSz40= X-MS-Exchange-CrossTenant-OriginalArrivalTime: 28 Oct 2016 12:30:32.1233 (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: BN3PR03MB2372 Cc: Shreyansh Jain , thomas.monjalon@6wind.com, viktorin@rehivetech.com Subject: [dpdk-dev] [PATCH v7 03/21] 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: Fri, 28 Oct 2016 12:30: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. BSD implementation updated as ENOTSUP Signed-off-by: Jan Viktorin Signed-off-by: Shreyansh Jain -- Changes since v2: - update BSD support for unbind kernel driver --- lib/librte_eal/bsdapp/eal/eal.c | 7 +++++++ lib/librte_eal/bsdapp/eal/eal_pci.c | 4 ++-- 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 +++++++++------------------------ 5 files changed, 57 insertions(+), 26 deletions(-) diff --git a/lib/librte_eal/bsdapp/eal/eal.c b/lib/librte_eal/bsdapp/eal/eal.c index 35e3117..5271fc2 100644 --- a/lib/librte_eal/bsdapp/eal/eal.c +++ b/lib/librte_eal/bsdapp/eal/eal.c @@ -633,3 +633,10 @@ rte_eal_process_type(void) { return rte_config.process_type; } + +int +rte_eal_unbind_kernel_driver(const char *devpath __rte_unused, + const char *devid __rte_unused) +{ + return -ENOTSUP; +} diff --git a/lib/librte_eal/bsdapp/eal/eal_pci.c b/lib/librte_eal/bsdapp/eal/eal_pci.c index 7ed0115..703f034 100644 --- a/lib/librte_eal/bsdapp/eal/eal_pci.c +++ b/lib/librte_eal/bsdapp/eal/eal_pci.c @@ -89,11 +89,11 @@ /* unbind kernel driver for this device */ int -pci_unbind_kernel_driver(struct rte_pci_device *dev __rte_unused) +pci_unbind_kernel_driver(struct rte_pci_device *dev) { RTE_LOG(ERR, EAL, "RTE_PCI_DRV_FORCE_UNBIND flag is not implemented " "for BSD\n"); - return -ENOTSUP; + return rte_eal_unbind_kernel_driver(dev); } /* Map pci device */ diff --git a/lib/librte_eal/common/eal_private.h b/lib/librte_eal/common/eal_private.h index 9e7d8f6..b0c208a 100644 --- a/lib/librte_eal/common/eal_private.h +++ b/lib/librte_eal/common/eal_private.h @@ -256,6 +256,19 @@ int rte_eal_alarm_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 2075282..5f6676d 100644 --- a/lib/librte_eal/linuxapp/eal/eal.c +++ b/lib/librte_eal/linuxapp/eal/eal.c @@ -943,3 +943,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 876ba38..a03553f 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