From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wm0-f41.google.com (mail-wm0-f41.google.com [74.125.82.41]) by dpdk.org (Postfix) with ESMTP id 92631C6C8 for ; Fri, 29 Jan 2016 15:08:49 +0100 (CET) Received: by mail-wm0-f41.google.com with SMTP id p63so69730942wmp.1 for ; Fri, 29 Jan 2016 06:08:49 -0800 (PST) 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=/Ahbvjzq4Q9QCaxeWk8xm0/691M9Vdrd5/XYhDF9ic8=; b=qZd/yvqto6ZZP3EjaXfdoS3ci2wSJ5e6SOWiYQOKFHJ9eGgrx0OEczUy5bmKNgoR/T qnlf2OJ1SNn1VFzQviKuw3jXs3Eima492+BXHa+P68ZzfnBih2B4fFEUrvy8nuAyJA21 YaTs5O1pbQep+aXrCXFw1XzRo6pLq9CMPu1D0HpKNpedtmEMII+JgTvaN5cxMWbKSxZk MOx0tJG419KaoswqxA4nfv1TJYvrPnaD8XfdRcakRYfF6Bwc4D44Ojs58L/1Y6bjclyP y2okTfezCCndqVbDKcz6aH/BGCmHqn7OB0UctvACQeehK68nlvluLI5mbxAupqThZ9Ey ptvg== 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=/Ahbvjzq4Q9QCaxeWk8xm0/691M9Vdrd5/XYhDF9ic8=; b=FspzJG85WWhwglzk0wGvclj7LF7ZKACBGPhlSV48dzp/jMc3qMa1SBcjl2sBcmmcde ya305uv74PYZgWys3k4HyiOGFRKw8DwllJHVAyrX3x5V9TEhfcDmbkL52WViGRHkinY2 +7Cq5IBNqS5QnMD2SsC+nQDQKKive/QLT24QSuzJTAY2S33CuvuhsZs3Gui3mWn0tWit U7GjyfO5Lt84Qhl0d3Z26e5GgYZ7oNkv3UK91WVFQZnfLsnN4t51jB0L61PT9bu5HrFw Ke47Q89hESJ+v6sin1ACQE8mGXtC0b070695bEA91a3c6rIRsGz+5E1D6b8WzYlhmnT1 WFmQ== X-Gm-Message-State: AG10YORfIQHAeDp05lirLOSsqHc+MffbNleRVbp1bA06JFaYUIuIHKwA2c0/dtYsGXdjzfzA X-Received: by 10.194.173.233 with SMTP id bn9mr8876257wjc.1.1454076529430; Fri, 29 Jan 2016 06:08:49 -0800 (PST) Received: from gloops.dev.6wind.com (144.77.126.78.rev.sfr.net. [78.126.77.144]) by smtp.gmail.com with ESMTPSA id 67sm7669944wmp.20.2016.01.29.06.08.48 (version=TLSv1/SSLv3 cipher=OTHER); Fri, 29 Jan 2016 06:08:48 -0800 (PST) From: David Marchand To: dev@dpdk.org Date: Fri, 29 Jan 2016 15:08:34 +0100 Message-Id: <1454076516-21591-8-git-send-email-david.marchand@6wind.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1454076516-21591-1-git-send-email-david.marchand@6wind.com> References: <1454076516-21591-1-git-send-email-david.marchand@6wind.com> Cc: viktorin@rehivetech.com Subject: [dpdk-dev] [PATCH 7/9] 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: Fri, 29 Jan 2016 14:08:49 -0000 eal is a better place than ethdev for naming resources. Add a helper here, and make use of it in ethdev hotplug code. Signed-off-by: David Marchand --- lib/librte_eal/common/include/rte_pci.h | 28 ++++++++++++++++++++++++++++ lib/librte_ether/rte_ethdev.c | 22 ++-------------------- 2 files changed, 30 insertions(+), 20 deletions(-) diff --git a/lib/librte_eal/common/include/rte_pci.h b/lib/librte_eal/common/include/rte_pci.h index 334c12e..9edd5f5 100644 --- a/lib/librte_eal/common/include/rte_pci.h +++ b/lib/librte_eal/common/include/rte_pci.h @@ -309,6 +309,34 @@ 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 int +eal_pci_device_name(const struct rte_pci_addr *addr, + char *output, int size) +{ + int ret; + + ret = snprintf(output, size, PCI_PRI_FMT, + addr->domain, addr->bus, + addr->devid, addr->function); + if (ret < 0 || ret >= size) + return -1; + + return 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 17e4f4d..5ba7479 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,7 @@ 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); + 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 +288,7 @@ 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); + 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