From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from NAM01-BY2-obe.outbound.protection.outlook.com (mail-by2nam01on0045.outbound.protection.outlook.com [104.47.34.45]) by dpdk.org (Postfix) with ESMTP id 3F310558D for ; Tue, 12 Jul 2016 08:01:31 +0200 (CEST) Received: from BN3PR0301CA0007.namprd03.prod.outlook.com (10.160.180.145) by BN1PR0301MB0769.namprd03.prod.outlook.com (10.160.78.151) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P384) id 15.1.534.8; Tue, 12 Jul 2016 06:01:30 +0000 Received: from BL2FFO11OLC003.protection.gbl (2a01:111:f400:7c09::124) by BN3PR0301CA0007.outlook.office365.com (2a01:111:e400:4000::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P384) id 15.1.534.14 via Frontend Transport; Tue, 12 Jul 2016 06:01:30 +0000 Authentication-Results: spf=fail (sender IP is 192.88.168.50) smtp.mailfrom=nxp.com; 6wind.com; dkim=none (message not signed) header.d=none;6wind.com; dmarc=fail action=none header.from=nxp.com; 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 BL2FFO11OLC003.mail.protection.outlook.com (10.173.161.187) with Microsoft SMTP Server (TLS) id 15.1.534.7 via Frontend Transport; Tue, 12 Jul 2016 06:01:29 +0000 Received: from Tophie.ap.freescale.net (Tophie.ap.freescale.net [10.232.14.199]) by tx30smr01.am.freescale.net (8.14.3/8.14.0) with ESMTP id u6C60qWk006202; Mon, 11 Jul 2016 23:01:27 -0700 From: Shreyansh Jain To: CC: , , Date: Tue, 12 Jul 2016 11:31:17 +0530 Message-ID: <1468303282-2806-13-git-send-email-shreyansh.jain@nxp.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1468303282-2806-1-git-send-email-shreyansh.jain@nxp.com> References: <1466510566-9240-1-git-send-email-shreyansh.jain@nxp.com> <1468303282-2806-1-git-send-email-shreyansh.jain@nxp.com> X-EOPAttributedMessage: 0 X-Matching-Connectors: 131127768896586558; (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)(1110001)(1109001)(339900001)(199003)(189002)(586003)(305945005)(33646002)(86362001)(7846002)(11100500001)(6806005)(68736007)(50226002)(36756003)(356003)(85426001)(229853001)(104016004)(81156014)(47776003)(2351001)(2950100001)(4326007)(76176999)(50466002)(48376002)(189998001)(106466001)(97736004)(8936002)(105606002)(110136002)(77096005)(8676002)(87936001)(2906002)(81166006)(19580395003)(5003940100001)(50986999)(92566002)(19580405001); DIR:OUT; SFP:1101; SCL:1; SRVR:BN1PR0301MB0769; H:tx30smr01.am.freescale.net; FPR:; SPF:Fail; PTR:InfoDomainNonexistent; A:1; MX:1; LANG:en; X-Microsoft-Exchange-Diagnostics: 1; BL2FFO11OLC003; 1:9pvYEZgf+Hiqiiyr1mFiQqolbfHs2lsexby0jXZH4cd+a0pq0YeKj+Pq4zPE51gXYa1UWviXnPR1/kxeRzJPw4kGip6kRIDOrPvrUbSulI+q/XtL9fv5uppk3JUqR3uDa02hzPqfLpoF4R5VkuxXRGpI/h69InopNMV8CkOmVZhfWKeUl5TfA0swL7WCu51l9q92oJGmmg6wOsbmf0iUCOiEilbL7gLrnY/tmhH1gwWKeVZzQyjsxGgP9yHEJdbCAWb6Lz+mHf/CwQCN/4zM4k4At0dhZtkVubA75wG/Nxlr+nrjSx1apufAA6B/emYw+yF2HGEv0LXSL/OVewfG48JjWdB9dfGblK25cMFvnWfYoPD00G3HXsGjhUe5hnmNsLDo2GElPjz09V5WAwudDLzSbuqllyRJ5j025iFsDw6NdaFk0t1VGHTipVjsJ37EFTr07BekBPX82xtSs1d1ENG+afT1qZuA/wFkkwqLWYaIa4R0Adr4BJAgR3lF1pKz/UJfLpNOYy2CSkpx3qeCOsrk02KPWf1RjRlamHCj7for7v47plDH8VWYbmk0almVW+DzlHlCpiO2RweYwy3z7Y9HKQ4URoy6Csi7qKGjrs5HsSQmkvfqQQQFEu59fL+Z MIME-Version: 1.0 Content-Type: text/plain X-MS-Office365-Filtering-Correlation-Id: ee4a680d-cff9-4387-433e-08d3aa19f7bc X-Microsoft-Exchange-Diagnostics: 1; BN1PR0301MB0769; 2:jQb9L3ZbGyeIOFKi93XHfHKXyi22eEEpuDITk/fk+wYgxchJhAj0m/cKbZwX9/JQk+dqtTuMBqVGzXhhtcP/eHm4nNcuH1UMNomuskhJnuxzjrd8A4k9GA25aklPUCxX6QoXuT0PHPBc2HP5V8OTlOBmpIkwIXu+ZQ6TdWMB0nZZNshL/2H4c0f8yz/8kXhU; 3:t/TLImuz4KdgsufwaX9WpBaNoJW1WN+/lBJFbcEdCPd82IWlBjYkF/IGKnDL+ALSy10AGa9i+XCNsDg/f0nlX+7r/UtHzREdTTNbAUeFZYn7c3tTLkzy0/9ksHh5sdd/73y8jl0XZ5bhUPInZxFl2oIRD9vONtn2KzREBFzazeEPjP1ESjtetHMSzj73zA0wNBdKaGOQJROu5mm4G1vSM5Etquqx0tD8K3IjmcLVlkY=; 25:o5S7YeOBniO+ep3RID9aRFC81RCiZAp745V7QTrnV7lCp/mdAD+Au+Zq/ZF8Fu4ozGFgBJaZNZtESVgyjByKrfAfH+f6sLcWh4tcGDMevxc0p1bGVIpDsLh/apa5MOoXUEzYCqyJzd69XZ00NOCNjz9IZwBvpQUcWe59NTznSO/0fkiyx15BX4n5a/VhVV9puSuh1TFLMhJi0BN/7GoB8z0hPUoQRJjzysGsiO3AzPGvXVtolJPHKLFw3i+Gr6a6oKFfMNwmawWfC3jWmzjwfHCH08Fu+WtzffaXuZof+rvE/99I8ZBzYZXPRSBEY7Dr8i6Q5FW73ZWiiJwULmZBdoT5VYfR+KPAbCyIJ5l+bcF5RBgOa1p4VcNCdkCtePBLzwopukIiNJEHCiu7I91EcBHexTaxbalPc0ucvGq+x+E= X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:;SRVR:BN1PR0301MB0769; X-Microsoft-Exchange-Diagnostics: 1; BN1PR0301MB0769; 31:3fdQFTjd4xTcvPyxG43VAtbXFXM5a6ORo30VAAXwocuX9DEeRMD+N7xH5QWBj3DLFp2g/dEEmXwplp2sXloFYWt6CSqy8lOwoUGxDdYEC0JjuXExmgA8TfuEVMSGnss0O2XqpOTyaDZV0DxUOaXCSBoMEq5Pfy8CSBaoEAcGw0w1YJHWELsuXNTwlXqPJmBE+zwLMsQpxOXRFeqgUjpvlQ==; 4:jG8di+a2YrpD3RiYzVc+0c3qUKZFge5XfpZOfEr93Is5lweQntjrzEr41moG99ID+Oh7v2BNp+mr4y0Skw7Dr6lqMhY/0yKsMv/LlkYQLuNWgmIUgDb32UDf6JpeDEHxpZZy46ewdlHwXPmKSPYDT9LlHHSvKTfUWbfGU7zvkiF7fJ87Q0nIsomgDHZphZ+xkttgu67P+Ath3uOLMixv4MKgz4pllfGNqgtbjQIDOh9jbIy6T1kwhUEI2/DxccIzBBkfOwBAzZEIj4TDkFHqeCYue7lKSwXIgqOxh8zpRIK/fCwfXjuSIxrWdDRAMyi8tHhVPlWLAmatWNdGRSeir2aTYDWYTINuV/g+UgSxD5zeS1oHw7mOAIzvS/se0a7CNG7TrIAH7ZVtNbY2Io56E3jO3UmEQ1792wpT2yISfGwVwO3yJumKhFJAiq5KogL9OjA+k9JEbhvPvf7nAE9vqmr09nCQshM1JK10dx8VD62CDIQ+vRF/A8Pvy5Sqogtgbf8lidAd9Dz37XJG3GBWzg== X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(185117386973197); X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(601004)(2401047)(13023025)(8121501046)(5005006)(13017025)(13015025)(13018025)(13024025)(10201501046)(3002001)(6055026); SRVR:BN1PR0301MB0769; BCL:0; PCL:0; RULEID:(400006); SRVR:BN1PR0301MB0769; X-Forefront-PRVS: 0001227049 X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; BN1PR0301MB0769; 23:XmyMROHoNrBuNcaJ+gWPpshTClxaVYLVpewDR+v?= =?us-ascii?Q?L5zA2hD5BCciEZum9DsEuSAOUI0jA/nziSqINdPnoV0SadJR2j5RN9ejxeOA?= =?us-ascii?Q?YD1y3hTlPyW9+O0eTqFBtQn+B+2DmEwDsp/36LRx0V44rspag47Wstk61r3h?= =?us-ascii?Q?uyEi5cxy4hAGpSCwlDpeSyjPgI8zG0LhCxfqSV02g8PsCV3EtUrsR0u0XIm5?= =?us-ascii?Q?Va7gBseARtdIegZsi6g6DC+N54xNJaCuWGZloIQMxzT8asp8EvlE62zCLJly?= =?us-ascii?Q?ash2/7gVs8FO8Yb59otb3JUkUbKW8cmjZfjaS4NkFYxd1XxYkwlfrGWJiQwb?= =?us-ascii?Q?kv5MsYXrEbw41n/TpLD8axombfgHzZz2Umq4/PoQTeyTcyOzMC/SvQcHDWZa?= =?us-ascii?Q?y6sHrJ6kBKmNuiyPtHOiBVx7V8AabD768EXujJT4Z+kHdkCQBwVi545VDVLl?= =?us-ascii?Q?OIRsHTWMGlPoVsckEXhGraehSS5tPyc7uY1eqK0axIZmvhU8xF+sA1q+PCcV?= =?us-ascii?Q?VaimPfRLCot0aCnNUvYT9DaePOASQo6XvZ6V+lwTGdHlSjvxI2am56HzaVR+?= =?us-ascii?Q?2ZdN68WRd50pUz4NLkll015dwZuMBRLKHT1waKYbXik0wtOMc557P7PJMfCx?= =?us-ascii?Q?WQir7wmPb6yWgRSBb0D1DMI7EYcG3h9D2i7z3H0J59qPE7sFI5iEJ6f1wvNG?= =?us-ascii?Q?GeC+bE88D7syPcqbfsPxyw8rwyM1Dp9Ux8JzzQF/QwAZxVCIxU4eZkYhB3GV?= =?us-ascii?Q?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ur80yaJVRcgxq2LAMt4OVAExZEpkq6II=; 7:Yt0aZ6S158bT7pjl65/pn7ADFJnBymRpEPUgzzbu9jyxuexAxDig0fYBNriD5Eno58rp3sys6aFGkMeg3dFnHi869U3K/7JqGX0ajLFznFdF/VNU/92dA0/G8LpHX9VCThjismGPXKCMJ0IJZ1HgmDxblP7dnQg2+CsQCwVssmixQ/lMtgBmJGKqCIwo1cNuEcf7Jq4Sbs+sNNh5zbEXY7A9eJtNArOWXHtoTV+oj+9JSNC0eXpUlFgsr64MjyyN SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-MS-Exchange-CrossTenant-OriginalArrivalTime: 12 Jul 2016 06:01:29.4558 (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: BN1PR0301MB0769 Subject: [dpdk-dev] [PATCH v6 12/17] pci: add a helper for device name 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, 12 Jul 2016 06:01:31 -0000 eal is a better place than crypto / ethdev for naming resources. Add a helper in eal and make use of it in crypto / ethdev. Signed-off-by: David Marchand Signed-off-by: Shreyansh Jain --- lib/librte_cryptodev/rte_cryptodev.c | 27 ++++----------------------- lib/librte_eal/common/include/rte_pci.h | 25 +++++++++++++++++++++++++ lib/librte_ether/rte_ethdev.c | 24 ++++-------------------- 3 files changed, 33 insertions(+), 43 deletions(-) diff --git a/lib/librte_cryptodev/rte_cryptodev.c b/lib/librte_cryptodev/rte_cryptodev.c index d7be111..60c6384 100644 --- a/lib/librte_cryptodev/rte_cryptodev.c +++ b/lib/librte_cryptodev/rte_cryptodev.c @@ -367,23 +367,6 @@ rte_cryptodev_pmd_allocate(const char *name, int socket_id) return cryptodev; } -static inline int -rte_cryptodev_create_unique_device_name(char *name, size_t size, - struct rte_pci_device *pci_dev) -{ - int ret; - - if ((name == NULL) || (pci_dev == NULL)) - return -EINVAL; - - ret = snprintf(name, size, "%d:%d.%d", - pci_dev->addr.bus, pci_dev->addr.devid, - pci_dev->addr.function); - if (ret < 0) - return ret; - return 0; -} - int rte_cryptodev_pmd_release_device(struct rte_cryptodev *cryptodev) { @@ -446,9 +429,8 @@ rte_cryptodev_pci_probe(struct rte_pci_driver *pci_drv, if (cryptodrv == NULL) return -ENODEV; - /* Create unique Crypto device name using PCI address */ - rte_cryptodev_create_unique_device_name(cryptodev_name, - sizeof(cryptodev_name), pci_dev); + rte_eal_pci_device_name(&pci_dev->addr, cryptodev_name, + sizeof(cryptodev_name)); cryptodev = rte_cryptodev_pmd_allocate(cryptodev_name, rte_socket_id()); if (cryptodev == NULL) @@ -503,9 +485,8 @@ rte_cryptodev_pci_remove(struct rte_pci_device *pci_dev) if (pci_dev == NULL) return -EINVAL; - /* Create unique device name using PCI address */ - rte_cryptodev_create_unique_device_name(cryptodev_name, - sizeof(cryptodev_name), pci_dev); + rte_eal_pci_device_name(&pci_dev->addr, cryptodev_name, + sizeof(cryptodev_name)); cryptodev = rte_cryptodev_pmd_get_named_dev(cryptodev_name); if (cryptodev == NULL) diff --git a/lib/librte_eal/common/include/rte_pci.h b/lib/librte_eal/common/include/rte_pci.h index 3027adf..06508fa 100644 --- a/lib/librte_eal/common/include/rte_pci.h +++ b/lib/librte_eal/common/include/rte_pci.h @@ -82,6 +82,7 @@ extern "C" { #include #include +#include #include TAILQ_HEAD(pci_device_list, rte_pci_device); /**< PCI devices in D-linked Q. */ @@ -95,6 +96,7 @@ const char *pci_get_sysfs_path(void); /** Formatting string for PCI device identifier: Ex: 0000:00:01.0 */ #define PCI_PRI_FMT "%.4" PRIx16 ":%.2" PRIx8 ":%.2" PRIx8 ".%" PRIx8 +#define PCI_PRI_STR_SIZE sizeof("XXXX:XX:XX.X") /** Short formatting string, without domain, for PCI device: Ex: 00:01.0 */ #define PCI_SHORT_PRI_FMT "%.2" PRIx8 ":%.2" PRIx8 ".%" PRIx8 @@ -308,6 +310,29 @@ eal_parse_pci_DomBDF(const char *input, struct rte_pci_addr *dev_addr) } #undef GET_PCIADDR_FIELD +/** + * Utility function to write a pci device name, this device name can later be + * used to retrieve the corresponding rte_pci_addr using above functions. + * + * @param addr + * The PCI Bus-Device-Function address + * @param output + * The output buffer string + * @param size + * The output buffer size + * @return + * 0 on success, negative on error. + */ +static inline void +rte_eal_pci_device_name(const struct rte_pci_addr *addr, + char *output, size_t size) +{ + RTE_VERIFY(size >= PCI_PRI_STR_SIZE); + RTE_VERIFY(snprintf(output, size, PCI_PRI_FMT, + addr->domain, addr->bus, + addr->devid, addr->function) >= 0); +} + /* Compare two PCI device addresses. */ /** * Utility function to compare two PCI device addresses. diff --git a/lib/librte_ether/rte_ethdev.c b/lib/librte_ether/rte_ethdev.c index 89c7b31..147b26f 100644 --- a/lib/librte_ether/rte_ethdev.c +++ b/lib/librte_ether/rte_ethdev.c @@ -220,20 +220,6 @@ rte_eth_dev_allocate(const char *name, enum rte_eth_dev_type type) return eth_dev; } -static int -rte_eth_dev_create_unique_device_name(char *name, size_t size, - struct rte_pci_device *pci_dev) -{ - int ret; - - ret = snprintf(name, size, "%d:%d.%d", - pci_dev->addr.bus, pci_dev->addr.devid, - pci_dev->addr.function); - if (ret < 0) - return ret; - return 0; -} - int rte_eth_dev_release_port(struct rte_eth_dev *eth_dev) { @@ -257,9 +243,8 @@ rte_eth_dev_pci_probe(struct rte_pci_driver *pci_drv, eth_drv = (struct eth_driver *)pci_drv; - /* Create unique Ethernet device name using PCI address */ - rte_eth_dev_create_unique_device_name(ethdev_name, - sizeof(ethdev_name), pci_dev); + rte_eal_pci_device_name(&pci_dev->addr, ethdev_name, + sizeof(ethdev_name)); eth_dev = rte_eth_dev_allocate(ethdev_name, RTE_ETH_DEV_PCI); if (eth_dev == NULL) @@ -310,9 +295,8 @@ rte_eth_dev_pci_remove(struct rte_pci_device *pci_dev) if (pci_dev == NULL) return -EINVAL; - /* Create unique Ethernet device name using PCI address */ - rte_eth_dev_create_unique_device_name(ethdev_name, - sizeof(ethdev_name), pci_dev); + rte_eal_pci_device_name(&pci_dev->addr, ethdev_name, + sizeof(ethdev_name)); eth_dev = rte_eth_dev_allocated(ethdev_name); if (eth_dev == NULL) -- 2.7.4