From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wm0-f52.google.com (mail-wm0-f52.google.com [74.125.82.52]) by dpdk.org (Postfix) with ESMTP id 6FF4537A8 for ; Wed, 20 Apr 2016 13:44:35 +0200 (CEST) Received: by mail-wm0-f52.google.com with SMTP id u206so76783948wme.1 for ; Wed, 20 Apr 2016 04:44:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=6wind-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=nq3D5hc5hPqDWSIuEBX3zaXMFoAdgPzwoF3eiV8to3E=; b=X2K1T5D4O3B9fHEP9E80wHZaSVwh1bDjlFNiHZ9ztsui7+KktQed5E/exBWEkcquLc CKKhd4qIpG7DE740tPSL2mCDwkByKRifWSBOW3ymtM3s0UWxuMJn8jGuwRja9WgUMtBU mG9OHWTqWIz8kya/F0Rn/sOFPU6Uz3darxO1FNnc49VkJaKiHfmsAmtBsq9isFvSIOQz HJi3T5V+iiEPD9dHgsuSmkeDBF08O7VT0zaSq+Zi+4qFUUyynZx81b1mvr7M8ILPDRZx 05m/XgeQiviFpnFS2ijEb9dfY23VCIbK0IlPV59xll1Kib7jwkx0Ym+AXNEe9NvOlJyW q4fA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=nq3D5hc5hPqDWSIuEBX3zaXMFoAdgPzwoF3eiV8to3E=; b=k0yynCK12RflwBAzGSJ+he6VfNgXOqpKplvRGRMWl/FDkzzp9sV0FwlSdPsE6i+yn6 79JECsvthTOToJuXSHan2ep+nMwNPnoG2tJNlrQDOIYOE3VPgxXhHK2ZqIvljd1nr9Uf pfDPD5bgRjXwDXcR44KhBERdB9XzMUjF3UVPa/NH1LjpWL5SLs4Ph/7+SC2lTfc+zyZO LoGYMCT97E24TzxVCh94ccpN71QSV0t/phAM7QxA+YcpbeCwIXaRRKPEtbZoihq1aWjr OpjAcUwqY98yApBCdRvCOIzYxipWqq8Z7ybwZSwQNWLrlq4QR/hNqP6itk3Z1mJQk/U4 5fEg== X-Gm-Message-State: AOPr4FXx+7zQmJOU76naFV+usH5JBrge98xUPytXczjYlphYEQrurh/5xyqEQMgod/n9HZ/5 X-Received: by 10.194.95.198 with SMTP id dm6mr8672043wjb.136.1461152675277; Wed, 20 Apr 2016 04:44:35 -0700 (PDT) Received: from gloops.dev.6wind.com (144.77.126.78.rev.sfr.net. [78.126.77.144]) by smtp.gmail.com with ESMTPSA id m6sm5195708wje.21.2016.04.20.04.44.34 (version=TLSv1/SSLv3 cipher=OTHER); Wed, 20 Apr 2016 04:44:34 -0700 (PDT) From: David Marchand To: dev@dpdk.org Cc: thomas.monjalon@6wind.com, viktorin@rehivetech.com Date: Wed, 20 Apr 2016 13:44:12 +0200 Message-Id: <1461152657-19969-13-git-send-email-david.marchand@6wind.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1461152657-19969-1-git-send-email-david.marchand@6wind.com> References: <1454076516-21591-1-git-send-email-david.marchand@6wind.com> <1461152657-19969-1-git-send-email-david.marchand@6wind.com> Subject: [dpdk-dev] [PATCH v2 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, 20 Apr 2016 11:44:35 -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 --- 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 d9648a2..6f4d1c4 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 f99b33a..3bb1833 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 @@ extern struct pci_device_list pci_device_list; /**< Global list of PCI devices. /** 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 @@ -309,6 +311,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 7ec8cdb..9d5827b 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) -- 1.9.1