From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from na01-bn1-obe.outbound.protection.outlook.com (mail-bn1bon0085.outbound.protection.outlook.com [157.56.111.85]) by dpdk.org (Postfix) with ESMTP id 1C7E6C77E for ; Thu, 16 Jun 2016 16:07:06 +0200 (CEST) Received: from BN3PR0301CA0061.namprd03.prod.outlook.com (10.160.152.157) by CY1PR03MB2380.namprd03.prod.outlook.com (10.167.8.6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P384) id 15.1.517.8; Thu, 16 Jun 2016 14:07:04 +0000 Received: from BL2FFO11FD025.protection.gbl (2a01:111:f400:7c09::123) by BN3PR0301CA0061.outlook.office365.com (2a01:111:e400:401e::29) 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; Thu, 16 Jun 2016 14:07:04 +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 BL2FFO11FD025.mail.protection.outlook.com (10.173.161.104) with Microsoft SMTP Server (TLS) id 15.1.511.7 via Frontend Transport; Thu, 16 Jun 2016 14:07:04 +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 u5GE6XoD026530; Thu, 16 Jun 2016 07:07:01 -0700 From: Shreyansh Jain To: CC: , , David Marchand Date: Thu, 16 Jun 2016 19:36:46 +0530 Message-ID: <1466086011-11920-13-git-send-email-shreyansh.jain@nxp.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1466086011-11920-1-git-send-email-shreyansh.jain@nxp.com> References: <1454076516-21591-1-git-send-email-david.marchand@6wind.com> <1466086011-11920-1-git-send-email-shreyansh.jain@nxp.com> X-EOPAttributedMessage: 0 X-Matching-Connectors: 131105596246434626; (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)(1110001)(1109001)(339900001)(199003)(189002)(50466002)(2950100001)(106466001)(77096005)(2906002)(8676002)(81166006)(8936002)(356003)(4326007)(50226002)(5008740100001)(5003940100001)(69596002)(87936001)(97736004)(81156014)(68736007)(229853001)(47776003)(19580405001)(48376002)(19580395003)(189998001)(50986999)(76176999)(11100500001)(104016004)(86362001)(85426001)(586003)(6806005)(105606002)(110136002)(92566002)(2351001)(36756003)(33646002); DIR:OUT; SFP:1101; SCL:1; SRVR:CY1PR03MB2380; H:az84smr01.freescale.net; FPR:; SPF:Fail; PTR:InfoDomainNonexistent; A:1; MX:1; CAT:NONE; LANG:en; CAT:NONE; X-Microsoft-Exchange-Diagnostics: 1; BL2FFO11FD025; 1:ycuXjPIUN4j+3TEttAuNJ/nsRf8I54WOObYy9HwI+dm6FWlrFrJAiXn99LjrCuDlokSQup1pDRcGH3FWN29LfyRDi45P0nwYgr58Mc6tfIl1CvpH0z1fhQUIWmnFZyJvyzLMbljw8EZdmhGOThmJQv86ic9BctbuNmjU93wqaMkx6t1oVTHV6X2hLLjx4SVAUoqPBD52pUGQuLggLH1Yy0u7xolDAU4x5LdtmF4pGhti2X6H0VLr9dNCEO2CaTEpDFnZ6AldRZ0dm5T/mrixGReIXui+knzDWMdSg5nyx61H2djov9l9LNQ/xeYHQ2xE6OBYh7NSdPGfBfppNsLsxAZzEe1FEq4faOaIP3wiAnaM3xY/OMh/5jCVRDnJZDHtM6SZeN6VVrWxbA8JnH2Jt+HPZy5r8Bwa0yj8b+z/Xu+loTzUKIMzEX/6kD/UURGueG1BXnlNrRzdqdjyMwY6ELew5JnskNGKX6NnmbyKz8WKp9cUSK+bLgfhfgbrL7YxrOkR8oIZGv0uooanTpUwdXZBIzQojmnVO6TrM6KHT7vRhcnOZF7cjffjoZce6ahi5JO0JX20gpWyH+lBYJPMXA== MIME-Version: 1.0 Content-Type: text/plain X-MS-Office365-Filtering-Correlation-Id: a5b526fa-e813-4a95-41e1-08d395ef7eca X-Microsoft-Exchange-Diagnostics: 1; CY1PR03MB2380; 2:fjmXr9Sf76x1kgylG4pmigqCheEGbY48ILt0maCvGQGRqICB5wCfvVZDPOOr+Pxhruu1HUWqnchFOiFiczMFuEXg/z/LXbA61bAoSEEqarzjPnKsb5RZi8i9+UzbKZgDcbEJ7Crnwzlmz5Ug5EGOsTBfphm5tLrrECPQxL8kMxT8OeWJmUg6Mq61CQOgKcUS; 3:GpEIOAUVrIJLuBlUgOQW263UImJYH+rH3A3IlDb7/9agVcikPmt36ZtXve125sTykhtwufs4dzo9azhbjDcqqLX/n+NFzP8pTY+mgxY2vLili6irAHc1/TDGKPBlifS+4xhK8bCdouP8WsS+nSUUCjHhFXXbtztHbCUZBs19pX3iXAcZU9b1g6iUA+xzQAK03+Ns7AI7melHi2E58CKXlof2QPBpUA4eRzjPtppZ9iA=; 25:3XzWs7CFEn4f//guwKuzFICh0NEFMqm+cWVZP1UslNJAXUJuXXD51gDnLVVi4YUQf2OOyFLIeNvwBbepyUGMvtq3NSsHp4vwcwkjYyYte4BL1JrmndSpVpXD/t3jDw3R4VPKNCsi+Ay16k5opsZMsbGCch+gAjbM5XxSeUPEI6lKUvNs2QbQPQLuZwDpwT41WByEAAsCK+2Dg4HNzIkaKGFC82GqeEXs+9SzXNl+wjg0T0p2+9+yiTo1klIY8cZ7NfNYfzgxN6rwZjTMFgacIjT1U71PET897lkZ1kVGaaMe1xjqBwrjMG97n+jIi+4j26VkYKW+OUfFUtCIty6/NVR2pOBJ6CTLJKrsCrCXslsnuTQw8Nx3+zsKdTVmmERQY/TkNatyG/V0ZaitGiUPHCSj6xCy7CA7szwuvw6nFzk= X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:;SRVR:CY1PR03MB2380; X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:; X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(601004)(2401047)(5005006)(8121501046)(13015025)(13017025)(13018025)(13024025)(13023025)(10201501046)(3002001)(6055026); SRVR:CY1PR03MB2380; BCL:0; PCL:0; RULEID:(400006); SRVR:CY1PR03MB2380; X-Microsoft-Exchange-Diagnostics: 1; CY1PR03MB2380; 4:FopITSk1nzEqdlHv4EzAVzG8js7x+BDZWvDEab1MdU9LIggN0u04DVsUqqjyJjv/cslalXo7elwMzmUHcYeGE2fRZLVh4E2mfnFiIQkKJ+Vmrz6ojsG1/z+bjNr00YyUqUlbn3B/uWPdaroGG/iD1srxOutDmGFhqbnVS1bp1nCjsZKMRK1OPPYlZvYib4/mDXbg5cNp8AIyGSh3HvR0BKGOyjoP4SO3PsmNs8ScDwE/I9FNN1RWiBsMnCtCK+ORm9bl18NhBzvEGWrvdf/PiWwpZrJEP/dxSr5bkSHoJfvIme2tEXgGUhCq6rfkU/TROP8TcYrHC4dW1BgipuO0mbiBX1NnmF3Ra4i0zrW/W27PgwUm2p7MsoHJ7fYGqmWIuktpXJ3gvtpRwUIHj5hVs9b6KdaXBbZNy731yGJYMGco9ZoWFu0VkskX9wABW1OCfn3ubm9DR+dpqH3HMyfd6hoxl7Ua58ff9OM/JHzyvh0= X-Forefront-PRVS: 09752BC779 X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; CY1PR03MB2380; 23:jI6KZM6UEcHLWTuEhjwNOqCIBYmIfUS2r+xAwz3ob?= =?us-ascii?Q?7Ump04JuJBPxpuVnjxoDyCp403pqGXNrkIQ66nStUASAHipsXCyuHyKK9FEL?= =?us-ascii?Q?IN36jQekw7h1lfYcjoeThkRhWy8NkwQulpNHuKA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NSPM X-MS-Exchange-CrossTenant-OriginalArrivalTime: 16 Jun 2016 14:07:04.4094 (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: CY1PR03MB2380 Subject: [dpdk-dev] [PATCH v3 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: Thu, 16 Jun 2016 14:07:06 -0000 From: David Marchand 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 --- 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 d7df1d9..5e8bd89 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 7258062..5bcf610 100644 --- a/lib/librte_ether/rte_ethdev.c +++ b/lib/librte_ether/rte_ethdev.c @@ -214,20 +214,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) { @@ -251,9 +237,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) @@ -304,9 +289,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