From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from na01-by2-obe.outbound.protection.outlook.com (mail-eopbgr690047.outbound.protection.outlook.com [40.107.69.47]) by dpdk.org (Postfix) with ESMTP id 4968FC498 for ; Wed, 22 Jun 2016 11:06:47 +0200 (CEST) Received: from BY2PR03CA061.namprd03.prod.outlook.com (10.141.249.34) by BY2PR0301MB1624.namprd03.prod.outlook.com (10.163.28.30) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P384) id 15.1.523.12; Wed, 22 Jun 2016 09:06:44 +0000 Received: from BL2FFO11OLC012.protection.gbl (2a01:111:f400:7c09::197) by BY2PR03CA061.outlook.office365.com (2a01:111:e400:2c5d::34) 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; Wed, 22 Jun 2016 09:06:45 +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 BL2FFO11OLC012.mail.protection.outlook.com (10.173.160.159) with Microsoft SMTP Server (TLS) id 15.1.517.7 via Frontend Transport; Wed, 22 Jun 2016 09:06:44 +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 u5M9663l022009; Wed, 22 Jun 2016 02:06:42 -0700 From: Shreyansh Jain To: CC: , Date: Wed, 22 Jun 2016 14:36:31 +0530 Message-ID: <1466586396-22618-13-git-send-email-shreyansh.jain@nxp.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1466586396-22618-1-git-send-email-shreyansh.jain@nxp.com> References: <1466510566-9240-1-git-send-email-shreyansh.jain@nxp.com> <1466586396-22618-1-git-send-email-shreyansh.jain@nxp.com> X-EOPAttributedMessage: 0 X-Matching-Connectors: 131110600044439349; (91ab9b29-cfa4-454e-5278-08d120cd25b8); () X-Forefront-Antispam-Report: CIP:192.88.158.2; IPV:NLI; CTRY:US; EFV:NLI; SFV:NSPM; SFS:(10009020)(979002)(6009001)(7916002)(2980300002)(1110001)(1109001)(339900001)(189002)(199003)(4326007)(2950100001)(189998001)(5003940100001)(104016004)(68736007)(6806005)(19580395003)(19580405001)(33646002)(2906002)(110136002)(77096005)(50226002)(586003)(8936002)(69596002)(97736004)(85426001)(86362001)(81166006)(47776003)(8676002)(2351001)(229853001)(105606002)(48376002)(7846002)(106466001)(50466002)(81156014)(356003)(36756003)(76176999)(92566002)(50986999)(87936001)(969003)(989001)(999001)(1009001)(1019001); DIR:OUT; SFP:1101; SCL:1; SRVR:BY2PR0301MB1624; H:az84smr01.freescale.net; FPR:; SPF:Fail; PTR:InfoDomainNonexistent; MX:1; A:1; LANG:en; X-Microsoft-Exchange-Diagnostics: 1; BL2FFO11OLC012; 1:MsU3x0eEJg5nJVxeH/RV8Bs5I4RATgd9P/MFWwCNT4OVBUvIx7BZAdfhs7YKpPP5bj5eCoQcY4fkKWJUjU4AsV585+3R9E/0JNWF25ldJQHYrOU2+n8gNUl0h2MBDQczqO1viQD7Q8SV0LObpP2XTldaIjNXDsFrVV3XJuNTs7+cYzUxo1Ef+CAh2IeMmayOlOOCdny0aoCbRDvl3Hc94vk1peRDB+9IPGm7DCxfBYc0W2DBJD+jSh4l+XpRdxyerVknGhE+8z+03x7zvsrKtDj5SMfaJJiw2debHynorJmBgKVEbLaAaqIOH4oCvQNTmBLn+fApHko9qjKOf9dq7KmgRsZcxnBr8Z5m27W4TVRlLCJGBmqHxGgJhEQIlndouSsU2Rq5ZLOo4UeVw48Ge7pSDOlp1s3zwQFF3dxQzE/fOsMg/Dg09phwtTOt4QTwqYDJ9dopmG7TI51yy2R4dcDuxy2DhIjWvMHxKC7FmNRmZvVS9D6v7hwStudFo9aRA3Vi2Be92m7lzrv+7dx7OEJ2Arh1AxL96tTOH2ypKPCS+PJb9XvE9E0yVPWqOLPga86nhQWH31msoiRxdEh4DQ== MIME-Version: 1.0 Content-Type: text/plain X-MS-Office365-Filtering-Correlation-Id: b69ba211-54a6-4a4c-7af0-08d39a7c8851 X-Microsoft-Exchange-Diagnostics: 1; BY2PR0301MB1624; 2:Vh7i5a3Tj6kigRhFpIz5j8bRSEkO67KTpGgTU9Za38Tr+biDLu9IzyEMEem61yInyUhW+stuPNgLVBPvoSFPsZ3fiWHVeV1fOq4rKqjmiGo/IU9yXCYj6M6J006uY2SYql+c/2oGi+uAVa5/5GnZhNttOe5G7BORM20gAkFTz3S3aOV7UkWYAamaCHLTHkoY; 3:nwYXdkuc9JT+ez5iRA2Ke8j6r2FZNDqDpVjOnOnaiJ/VijodLnO7ATL7GRDxP3jLF/zsG2YttR+ORcx5VOSoKvLP7FHfAQppPMxRseyQgu9COF6YPM+rnagqXM6ATG/Vn6d7AQAEaU6LmRSSPhiLcBv/YhdizDVfcqNLYaEP53uReDhpGsdFUUvhR0m29lx5zHvyf5vE1uB85eSC2cHCARR8pkz4DGeckfaicuheoHA=; 25:CFVoRd1Qm1vpE3dtVdNnme/YH+wWPWJrApqwR0nGtDUbRXE3d1tVWTX7UcjCstdzYeZnfd2Kn7D4jAEKqbOduq4Ryi9uIhAjs8q5nGZ9rGOVClLIpStO6Ngqhg/RQPZ3o+6YFzksYlKRM4OPBOzUN51UfYIQeQXkh6K9MW9kJp8yvhCkJsI9ZfvyQJ4hNaf4rc8+L3Hfd5DUgDpDstLfOU0Z4ryDDeHjhVB5C2WNJ5Sjl+QA588ucsHS357eto4/ryWbinOnGbk9oZOno1eOCZPRJgn3au1EAucxY36XD/shwvPiVYgTJ1Xvl96zm1XyuCqxGAHToA5p0K3bLMYGohDbrXv0gKMZLOcgB+Oi7iVFroNfIpDoApO+NQcJYnVQ738D0xF0Q2JTO8wBbJlIWJDV6jUhQhs+WSz2kuLW6fk= X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:;SRVR:BY2PR0301MB1624; X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(185117386973197); X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(601004)(2401047)(5005006)(8121501046)(13024025)(13018025)(13017025)(13023025)(13015025)(3002001)(10201501046)(6055026); SRVR:BY2PR0301MB1624; BCL:0; PCL:0; RULEID:(400006); SRVR:BY2PR0301MB1624; X-Microsoft-Exchange-Diagnostics: 1; BY2PR0301MB1624; 4:Qnj/K7ac6/UIrCNWjr7aJJQSDNtUYpatiHs5W23UYrJhEdClkNed94lhkuCjNdvJqjHTZN23xyx3XH0L2mUR73NsaTYLbN5zkDn69Egm6ysWfL3Qr6/jgNpuftbylr3uM+I67itXziuIaSyQwnfzDsIbipymeMQZKfohdMn5DdCNVpQp74EZntc6eJJzEOyWvesKC2b6BbBqo20zJP0G82LRHbyGtUd7YGZnfpdP52kZg11wPyBoC4arHxELnLc6EiFV+Wm/1/4xd2zGV6r7kFG9Bub2ZS25OJrzcBD4am+WSQQOQtce0vG0cWpUFw7MGDb4rrNvBlSAjrP/2exC0VN19v1N6hbyP9mS6Pe0shLt/CKkv4xhNVMVRD2PZNOPyfFRzETE/8MWNNJjEpMD/eoSi1vzgOwIY4lNAiCyYuhpuyzflYRBjkEbiAL7vC708Wfh8GL/fpZIidaAed98nQix7dDnuzOwQRHdBjI0kHlZR5+yOqYPXTafRXnlK77+sTaBnHjyCE/FG83hbuqsEw== X-Forefront-PRVS: 0981815F2F X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; BY2PR0301MB1624; 23:oNaUltBxksyStv5rBhZd4cIQmnNwmw8cWuw2/og?= =?us-ascii?Q?dacGp/woeCZ7EJmRJE1zvbYW0iXVl1evglfKlx9TIi8tKE6Zl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NodP/vb6OxGfaQ9/tBp5zpLMY5z8PkmvUKJ65SMWUnVOyk/XQ85HRc34QF0JkJ0ccbO/+2z71Ba4GeR36IcRo+Q7u4HzMvjWwz/rDL8FXC0CySoOis1dFihLJ6VdBfsFT0Fucgbs+ksTGbtifZrlaCLxA== SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-MS-Exchange-CrossTenant-OriginalArrivalTime: 22 Jun 2016 09:06:44.1007 (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: BY2PR0301MB1624 Subject: [dpdk-dev] [PATCH v5 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: Wed, 22 Jun 2016 09:06:48 -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