From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from NAM03-DM3-obe.outbound.protection.outlook.com (mail-dm3nam03on0055.outbound.protection.outlook.com [104.47.41.55]) by dpdk.org (Postfix) with ESMTP id B44F0594E for ; Mon, 1 Aug 2016 12:45:21 +0200 (CEST) Received: from BN3PR0301CA0042.namprd03.prod.outlook.com (10.160.180.180) by BY2PR0301MB0694.namprd03.prod.outlook.com (10.160.63.149) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P384) id 15.1.549.15; Mon, 1 Aug 2016 10:45:19 +0000 Received: from BY2FFO11FD028.protection.gbl (2a01:111:f400:7c0c::142) by BN3PR0301CA0042.outlook.office365.com (2a01:111:e400:4000::52) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P384) id 15.1.549.15 via Frontend Transport; Mon, 1 Aug 2016 10:45:18 +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 BY2FFO11FD028.mail.protection.outlook.com (10.1.15.217) with Microsoft SMTP Server (version=TLS1_0, cipher=TLS_RSA_WITH_AES_256_CBC_SHA) id 15.1.549.5 via Frontend Transport; Mon, 1 Aug 2016 10:45:18 +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 u71Aibjs018422; Mon, 1 Aug 2016 03:45:16 -0700 From: Shreyansh Jain To: CC: , , David Marchand Date: Mon, 1 Aug 2016 16:15:27 +0530 Message-ID: <1470048332-27318-13-git-send-email-shreyansh.jain@nxp.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1470048332-27318-1-git-send-email-shreyansh.jain@nxp.com> References: <1466510566-9240-1-git-send-email-shreyansh.jain@nxp.com> <1470048332-27318-1-git-send-email-shreyansh.jain@nxp.com> X-EOPAttributedMessage: 0 X-Matching-Connectors: 131145219190251595; (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)(189002)(199003)(86362001)(85426001)(19580405001)(48376002)(5003940100001)(2950100001)(104016004)(19580395003)(77096005)(87936001)(76176999)(33646002)(50986999)(586003)(2351001)(229853001)(106466001)(11100500001)(105606002)(36756003)(189998001)(50466002)(110136002)(68736007)(2906002)(4326007)(97736004)(47776003)(356003)(92566002)(81156014)(50226002)(81166006)(8676002)(8936002)(305945005)(7846002); DIR:OUT; SFP:1101; SCL:1; SRVR:BY2PR0301MB0694; H:tx30smr01.am.freescale.net; FPR:; SPF:Fail; PTR:InfoDomainNonexistent; MX:1; A:1; LANG:en; X-Microsoft-Exchange-Diagnostics: 1; BY2FFO11FD028; 1:DhMHcPt1tTqjTVwP4ZdFqhaWMb8pJMbelr5Zs2I5fgSZHftjfDHL6tBxrpkYZoN3Ee3Px4HsgyQQGTe01CvYFTCwaRL2b7ZNj7oH+Pz1xD93lR4rO6PuE00A3OllXtcqi1Vc+6dDuEp5h93P8efCu7KjaWuV+oYBEL/tgkN3nH13w1BUAETER6qj3gocwLqAFrx9UruW/tpzPOOnLwsTEXJCWPgXPmRzQZMHCTYbcQsQMBn1Pnoa7qPAMNUYJQxDwETiroMoZPnCGoP0btnd5zpoeMmSrk9xjHKhoOryuyuUYUQO15gIuYONXyhSWil3m2uRYGKH6HaxvLVcINxB7LB+YaaM6Ofu0IPhj8SvmRcaqMIQxnNTTjaSaka2gLJkNigy7d6w2AAhHzoy1rmWFIebvrClikhg/lcDwtXjBfxQPbW4bqk2HPw7y6d82oMjguZppUV8C0xgN38YPbbiH5DvHUBYG0kxH5ZZJR2jCHce4a3f04BFXPsbRXW3y6hAjMAzNVrSVEtFIyrGtk+7wyow32/EUD+EV/kI0+f8FiaV5CaJzNAYgNg9RM5h4TmCIlxqleE7ZhH1acvY6qfpVFpPZBO2HNmnLTp4bYF6Cz98faLDwcfNlOe3D588MrYw MIME-Version: 1.0 Content-Type: text/plain X-MS-Office365-Filtering-Correlation-Id: 9b429f76-4088-4a78-feea-08d3b9f8ee47 X-Microsoft-Exchange-Diagnostics: 1; BY2PR0301MB0694; 2:9s9lhfhjq4wWHFKGAJpK2Zsljo1y+uZ5rYj5WOeA8X+RC2UrOYksehhl68kDtOrfDSvOAtu3wChUh4K61OxLnddyRCZrjGdCLnxvs5rIIjKeQcMxdUY8xD7ktny42HHgY3tFjoAqRm4UrZkdrlSFEz45B9YL/OE72WCbeMInWPZHsE/mnq6XrtFsZ+65ncuJ; 3:TD80Z77wcJMQ2BSUXwHTycwKaBBxqJQqxN6iFJhSPk762FSC/LLy1LAXFiJSL2ijIZq/ubLE3xJzECRtvglPw9zKqRVrNB7Vy6GuO/Be3UjI5lu1w8jDKXbW/VH873BrX52krJvBizJHXe7EAXVAQfkzHZlUoKKrR4JjE4EohMgs5+XxYJBeccVMhMDSGTdIkZjnNgvkKMpHxjvIyG3phlnPf6U7mW2uN+zwhExg45I=; 25:nF/AZmu1FMdSEQXZBsuBqrQ+rZZthGZygip9E0PCEJUiNoVf0pjXetQ+J2/8Q0YI0S+vGErZTJjoQBS/auwxO4tHxWzEs0BQCg3k14lUrtgGFyXFl8a3LMJgIHQX+YH9RTbnzcCED2Sf2SPt07eBwRkaBSPPvo0B3Nw1ILE6iQ8GhNM+PhBFC1bpz9IdJj7R5++mU7FyIi0wIVD9V0joXWkKpcqw9k8NpE3q1q3p8IDV6H+AlLzHd7I75/MoYrC8G36XvQSqCDSKPvkavYE8mTvZiZCiHnWu7Bd8Ug+snMnigSCz8Fkj0oZx2Ep+on8XlVgv9fehDZmoG/42RN/qRCHGhma/AE+y9BREfrbEZ9c5FU8MqwHuFIr2H3W1IXHRnB2VfVwGunVlXw8LCT3dVJbT0AQNRiRgILVc9xSvruk= X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:;SRVR:BY2PR0301MB0694; X-Microsoft-Exchange-Diagnostics: 1; BY2PR0301MB0694; 31:a8vj9qEzJLSXpX4M6TDnmYNTV6Ul7EkmuP27RJQq3cNXgld4/k0R0ktjodjFMdnLDaotrqcKJ9yREImVkCRdM55m2w53r2Sk6QgVm83YURa3EriMJ0Zb3NUlGLJdP3Lex3Dz8/yVgHRXQekvZTVWKrKs3oSd+LNsMhW8Yv184ZV/rlXOc1hIbqYQtRVrl/neRlTYhZTEpJwLdFQZI+EjVg==; 4:OEhxj5aXLqjIb5FfbbWMkIsLtPsZU4XBTMKpNmNJGIa8X0/rUYgDEOuOv+msvmeWUu6osvnWv3GpgVUz0iP78kbcTzI2eNDCNu12OBxL/e2MblJHY0Da0CdPwf+JSbeKeToGlYLmVZB86kfEP32hoxfuoEdAt4WHSuAZoJNKi6qKMn+T008g0t6E+BOWrSvLSiFVHXNdzZJzVDir4aBE/TMcMKcGN6wsp+P1QxAPgKw7QkMRllXbKjhNnXeuzp3OXEyDYn2ZNfksRV8283i2soRkTdXsEi10L4Zvk4bz9ukFGO1UIZ0C+BOQZfKEyAmZyKpyFrlQ9C2zMGzAHk4DVNWOyxUA0d4hEbTO8zbbC3UdkrfXbVVpDZbsAAvjwgipimx1BCtISRNPQDAIn6r5yEERdEWy1ygnMoCRZ6oVJHIg2CTXQZKVJI0J+35eYyFi5pYhKbmkc8B/wmDQidyKaJpc1xCm8yAVdY9vrOlmovMH4oWKB8SwqKs/s6+xI1Wu3st9JYY3s4+wbTB6ubMgSw== 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)(13024025)(13015025)(13018025)(13017025)(8121501046)(5005006)(10201501046)(3002001)(6055026); SRVR:BY2PR0301MB0694; BCL:0; PCL:0; RULEID:(400006); SRVR:BY2PR0301MB0694; X-Forefront-PRVS: 0021920B5A X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; BY2PR0301MB0694; 23:ALzTUSWKUywx2yFN4109unVpByR8JdibUmN6sOm?= =?us-ascii?Q?r9zx5AFtkVRxCYAnD33m9Vz29nHna1joRJ+33ryFHUixiVUZWV5YYEttI83c?= =?us-ascii?Q?I5tAXqSeXf7rsrzrO+OfZL9BWgGeKj3S4QPqA9t7xzop3P/Qw5byg66ghuaA?= =?us-ascii?Q?3gyRkWT+mnRJldH/IlYF1uFpzmHmWDhh1L6beunNUwXlXYBk7/A+iD0cG69O?= =?us-ascii?Q?z/9SElBiKfdY4C0s2bLPavwmZmxt+/osyreFU86Ph1EAXBO4hAHbhpXgIeqO?= =?us-ascii?Q?QcsMehWYvL0SCdAiZpU5JRYMaYPnVKMbW9cuayXCSgavPWLAJqklb2er7cOr?= =?us-ascii?Q?ND5gHxnwE50SLNVAJw8tCWmX/aLvG6HcHFg8xIaw0idBqTZ8ab1iY+PYfqF5?= =?us-ascii?Q?0/zD0OQ3YTK5d7J+ZgpZIado5evECQ8SOYnZlrRbmPKfMAfMfSJoNhCmfaqj?= =?us-ascii?Q?4MnzE4MEzMQax4zGIaE0W+FF8sR4tyneceuf8AD0AniKJQid2Nx642YEHh4H?= =?us-ascii?Q?HWA4JtLTPq0fSQ5avhoddzY4nGD3pQqnzIZ7apWPsuXSr2liykKyfwH+fhgj?= =?us-ascii?Q?qvuEfSMmQLRkjPojbLpBNIGqey+cxrgQ+lIpfMkvmM95aJ9W/joed4utRvcd?= =?us-ascii?Q?DVlBWeWGB5dkfrfS7QsXgcQ324QqznNddNLKtiUyNVvtVOd0mMCXHBmkITAQ?= =?us-ascii?Q?j+WBORcL23IS57H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0aWBSR7BP7jPoBLN8xpHljd9jOlyFtjwWJ8ZCc8tM=; 7:gRFBbuPF+KVis0HuCzc0FiwXMCPCwgiv9Y1MAOh819mm3XQkUR+NlAeldvkgWXwPu+f1N5Tsv79JEBLkpzI4JQsH/Iy+cdQCr4czdSIogBxHx42S61kNNGNJNuC/hLaIMFuBpiWF2i1sdHsAs1uD0QmFWlfGw8PdSSZ/vidsrQV+rsjiitpD7cuXrU5XmzTJxuLwVMKCiab9HvvmOy+g5aMc98HOxco/s5rRhMHCIJw3mDXSW0nw9WOASoybX9nw SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-MS-Exchange-CrossTenant-OriginalArrivalTime: 01 Aug 2016 10:45:18.8223 (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: BY2PR0301MB0694 Subject: [dpdk-dev] [PATCH v7 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: Mon, 01 Aug 2016 10:45:22 -0000 Eal is a better place than crypto / ethdev to name devices. 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 | 26 ++++++++++++++++++++++++++ lib/librte_ether/rte_ethdev.c | 24 ++++-------------------- 3 files changed, 34 insertions(+), 43 deletions(-) diff --git a/lib/librte_cryptodev/rte_cryptodev.c b/lib/librte_cryptodev/rte_cryptodev.c index 2a3b649..c81e366 100644 --- a/lib/librte_cryptodev/rte_cryptodev.c +++ b/lib/librte_cryptodev/rte_cryptodev.c @@ -365,23 +365,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) { @@ -444,9 +427,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) @@ -501,9 +483,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 ffeb94c..9eea092 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,30 @@ 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 eal_parse_pci_* + * BDF helpers. + * + * @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 3bccf20..a1bb043 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