From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from na01-by2-obe.outbound.protection.outlook.com (mail-by2on0091.outbound.protection.outlook.com [207.46.100.91]) by dpdk.org (Postfix) with ESMTP id BA437C31C for ; Tue, 21 Jun 2016 14:03:10 +0200 (CEST) Received: from DM2PR03CA0048.namprd03.prod.outlook.com (10.141.96.47) by BN3PR03MB2370.namprd03.prod.outlook.com (10.166.74.153) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P384) id 15.1.523.12; Tue, 21 Jun 2016 12:03:09 +0000 Received: from BY2FFO11FD003.protection.gbl (2a01:111:f400:7c0c::113) by DM2PR03CA0048.outlook.office365.com (2a01:111:e400:2428::47) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P384) id 15.1.523.12 via Frontend Transport; Tue, 21 Jun 2016 12:03:09 +0000 Authentication-Results: spf=fail (sender IP is 192.88.158.2) smtp.mailfrom=nxp.com; 6wind.com; dkim=none (message not signed) header.d=none;6wind.com; dmarc=none action=none header.from=nxp.com; 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 BY2FFO11FD003.mail.protection.outlook.com (10.1.14.125) with Microsoft SMTP Server (TLS) id 15.1.517.7 via Frontend Transport; Tue, 21 Jun 2016 12:03:08 +0000 Received: from Tophie.ap.freescale.net (Tophie.ap.freescale.net [10.232.14.199]) by az84smr01.freescale.net (8.14.3/8.14.0) with ESMTP id u5LC2TDT004076; Tue, 21 Jun 2016 05:03:06 -0700 From: Shreyansh Jain To: CC: , Date: Tue, 21 Jun 2016 17:32:41 +0530 Message-ID: <1466510566-9240-13-git-send-email-shreyansh.jain@nxp.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1466510566-9240-1-git-send-email-shreyansh.jain@nxp.com> References: <1454076516-21591-1-git-send-email-david.marchand@6wind.com> <1466510566-9240-1-git-send-email-shreyansh.jain@nxp.com> X-EOPAttributedMessage: 0 X-Matching-Connectors: 131109841886430787; (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)(189002)(199003)(11100500001)(2906002)(92566002)(7846002)(87936001)(85426001)(8936002)(50226002)(86362001)(47776003)(19580395003)(586003)(81156014)(19580405001)(81166006)(69596002)(76176999)(50986999)(50466002)(77096005)(5003940100001)(229853001)(6806005)(36756003)(106466001)(105606002)(33646002)(4326007)(97736004)(8676002)(356003)(48376002)(2950100001)(110136002)(104016004)(68736007)(189998001)(2351001); DIR:OUT; SFP:1101; SCL:1; SRVR:BN3PR03MB2370; H:az84smr01.freescale.net; FPR:; SPF:Fail; PTR:InfoDomainNonexistent; MX:1; A:1; LANG:en; X-Microsoft-Exchange-Diagnostics: 1; BY2FFO11FD003; 1:LdtoHlOOA82ZGebK8RVfjTJD6g+PCRQdlLPPwYwnA1EvumbaDn4Y5S30jKHdqM8LaGWEOYmEssvRyorFoSBmqUwSG0DRLVqSc7EvDoeaPerwdHjdv7NVL+l9T8I+Nyf34gVI5x02w3ZD5UvancQ7aBQHe/TGeAEXsQvceNTLxDcJYRTfI46U0KuFxk6KWEQJf9kpw5NZ4gjxUCWiwEO4aP2QG3z80CBBbNX5goJEA2gcq9lixvCksXnbfq2eEOrX3BSQznuV34zUydmD70wjWCcz1dkXH/MCEFNpS62zqMlBm8CJiUJzEh361+nYKI97uqk2D4z00pWgFM7zxw4nSRWsuRHMJMWlRtsT0fdoMaC3n4RKRFucxZdayU663/JHu5YLB7nIbH+Fo5zMzbLkB7g0cCrVEH28nMcQdnsvhk1oFYTp7LBJ9oN5ggpNU9jrKQDy+diZawPQt0w6qoHX66+YfFLVfmhfRGdH68SssRX/zTmSzzOw58AocnJelpZrOiBum6S1XDOX2Yud6Q0TSPfuYhUsacsJE5oB/HmWdA5P17SeVK4bH0U8cU6bXKvXswmS6726nL3ouaYnKBoZJw== MIME-Version: 1.0 Content-Type: text/plain X-MS-Office365-Filtering-Correlation-Id: 2500fdca-913f-4aae-c643-08d399cc02a9 X-Microsoft-Exchange-Diagnostics: 1; BN3PR03MB2370; 2:wOY9YFK1P2pXLRVWnxGdesCtC7tupCCoexu6xbbko7gMi5zNp5VFXs+agK/L6QnHmTE7pG8MdRjyS/MxLBdcwelZZfEQgvI2Fb4dAqX237aNsVrJQKg7+FklJgHVpSdXnfJCvEbVD9Ixo/JRUn9Be8XdoensJJPyaDJFT2ayJhjMLlShrmoS4N4fY+eLwvCd; 3:2iDsDr2TVAIw9fPXLFYkTIVMx1XLT/SIu8YyQagTXXXPdRqnhPKuhRh0OfBHp5SpgWVb933VoJzaBD9Bjz4MMjTzmNThKsl0mwegh9Z1+CqRcFUcZcGcbI6flimL571xCHO6CzKVBvJKyLOEnyFesITIe5VdFBYv2IGPIVoe+9932p/kQR4elY8MZDHsGR5VD6gr7Lr/6G05KkzrPGNRPWZKrndzb+gpS23Eo2ZCwCc=; 25:rG5eJBTwTovsjVmxXNGeTe9V+SlUH69niBX98fTM5tqXqVkUHT3/QDm/ykmkttgwLZ+Sh6YH4I+maFGd59FiUX2ZmRwPxyYorVGZqzKpjzoVyjevihk8RGDuZbIQ/TarTPa2UZlXIhw2svjvuiT/2YctGmFVvZXh7PXncQlAyZa1Fz8/u3zNKW3UlIC1ENzjr6kaR+7oXo35vDUVlg5O/P+hrGEZkAcHwSzCYo99KIQ83XwSTbjyqm+aWrcjuqrt0KDj1ynUsDcw/PWM6sX4dng7h3e4ylfISfhnu7RL2E+Rvfmjoc7tTv+VgaQueXA2bcHC5DCJn1AdZzuMRzFZ4tyujIGj77ERB0PXY6SKd1ozXm+8fE6C/UFchw6hR6TQxU8xKAD6kDwtersIz/3808BU76QqR87NLzdHVo8RC1w= X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:;SRVR:BN3PR03MB2370; X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(185117386973197); X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(601004)(2401047)(13018025)(13017025)(13024025)(13023025)(13015025)(5005006)(8121501046)(10201501046)(3002001)(6055026); SRVR:BN3PR03MB2370; BCL:0; PCL:0; RULEID:(400006); SRVR:BN3PR03MB2370; X-Microsoft-Exchange-Diagnostics: 1; BN3PR03MB2370; 4:QAYv5ueuq0emmoOI4RL67wL1HXfF3fziHthPDZ1Jk9iGrJ+KHQVlnnnv0H5Ef6XxVBrriH6D9QchpOqQkg73sX4ubz7W85vrUgHJATUPqOR1O1YN6Mk4a1tQuY6HUR3ZS0k23aSi9+G99zC20ehxv2tu9cpP1c+DS0OvfF2IXfIUEB3uBI03n9z+mTG4dUq9+CQLW1hqXXk9oVshIiuyGEfuW69moJJ+Mc/hYpgY1rf7vPZ2MjRt/uoxe0gd22j1Re8SqE+7AQbArXmrFeoVBRsXZHJ9xk8Bxl91hJKABX+bxIjGhDxkOPc1NZjSymr0ZwGwizpQHdpfKn4J+rwn1EUci/qwUVgg0ol23aDjkzwK68qipCJmu/RxUqLZaIw2vmubKvFYQwMfb0CVexRI/8rKizonN/M8S3ZlSIwJKYXs15UyStHSF5ofqUbj9RYZSXlMfYwOtTD7S1vCC6e78ri106S/FNyBio0HXwu/PCR/56GF94Q99fQ13hiB3ZJcrlcdx8VFrSWhhNIstdtNSg== X-Forefront-PRVS: 098076C36C X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; BN3PR03MB2370; 23:jHPp0Sz4T15KKf1/4TmedLPfTcsubPAtxVNcCr6z1?= =?us-ascii?Q?A9JAYl4ZuMMv+639dK5nuV03wCRu0W8fsA7n32aqRoII5hqktsPcJv6er+xC?= =?us-ascii?Q?Xd8M+aD2ENLNCZyqd8xz3T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PM X-MS-Exchange-CrossTenant-OriginalArrivalTime: 21 Jun 2016 12:03:08.5338 (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: BN3PR03MB2370 Subject: [dpdk-dev] [PATCH v4 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, 21 Jun 2016 12:03:12 -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 a7cb33a..3b587e4 100644 --- a/lib/librte_cryptodev/rte_cryptodev.c +++ b/lib/librte_cryptodev/rte_cryptodev.c @@ -276,23 +276,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) { @@ -355,9 +338,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) @@ -412,9 +394,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 ac890fc..1666a55 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 06065fe..ace8353 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