From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-pa0-f48.google.com (mail-pa0-f48.google.com [209.85.220.48]) by dpdk.org (Postfix) with ESMTP id 736297FD5 for ; Thu, 20 Nov 2014 09:57:09 +0100 (CET) Received: by mail-pa0-f48.google.com with SMTP id rd3so2180228pab.7 for ; Thu, 20 Nov 2014 01:07:38 -0800 (PST) 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=0lwY6SYSmKJIhKTLbcvinwuVrlGI8yrDsZqzCQRnBB4=; b=kWT5Q7rBMJqMzRlRifpCBHMK2+XpSzyjYDYxxVtKXE+wJyB3tW4DsFe6xO8GvOHNng 7H+X06Oq/SvbEgw2gCKwk20Oj5tilkwU+xCL/wjel1SKR1NwbX5otLVxEZqMiKkxnWuS aRYrNQNvmFbTSyhBSkTrdY5lGeZtgPaUXS/DcRNj2Rnrr69hhUcylWTHtApl+GsAVnp0 y2s/KPMH29O4Lo4N1PQusQ01RDhdYbPmgE443c1AslcdLicr7PgIBbq/lQFVBYTUPqAS EjfoPvY+OmABPMfV8K53mtGyHedgM2AZpJgT22vL8ayHclFOjrwk0y412Nxx4L8jJfSd UQ7g== X-Gm-Message-State: ALoCoQlTGDVvucQT4+WWCsGfI4rVwNTq7KwMBikQUJO6lm+WaGcXql9/+WctMTaopgPeHrDDyki2 X-Received: by 10.68.201.72 with SMTP id jy8mr34103535pbc.55.1416474458124; Thu, 20 Nov 2014 01:07:38 -0800 (PST) Received: from localhost.localdomain (napt.igel.co.jp. [219.106.231.132]) by mx.google.com with ESMTPSA id a6sm1432407pbu.64.2014.11.20.01.07.35 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 20 Nov 2014 01:07:37 -0800 (PST) From: Tetsuya Mukawa To: dev@dpdk.org Date: Thu, 20 Nov 2014 18:06:23 +0900 Message-Id: <1416474399-16851-10-git-send-email-mukawa@igel.co.jp> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1416474399-16851-1-git-send-email-mukawa@igel.co.jp> References: <1414572576-21371-1-git-send-email-mukawa@igel.co.jp> <1416474399-16851-1-git-send-email-mukawa@igel.co.jp> Cc: nakajima.yoshihiro@lab.ntt.co.jp, menrigh@brocade.com, masutani.hitoshi@lab.ntt.co.jp Subject: [dpdk-dev] [PATCH 09/25] ethdev: Add rte_eth_dev_get_port_by_addr 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, 20 Nov 2014 08:57:10 -0000 The function returns a port identifier of a ethdev specified by pci address. v3: - Fix if-condition bug while comparing pci addresses. - Add error checking codes. Reported-by: Mark Enright Signed-off-by: Tetsuya Mukawa --- lib/librte_ether/rte_ethdev.c | 17 +++++++++++++++++ lib/librte_ether/rte_ethdev.h | 13 +++++++++++++ 2 files changed, 30 insertions(+) diff --git a/lib/librte_ether/rte_ethdev.c b/lib/librte_ether/rte_ethdev.c index fa75ea9..fa5b928 100644 --- a/lib/librte_ether/rte_ethdev.c +++ b/lib/librte_ether/rte_ethdev.c @@ -432,6 +432,23 @@ rte_eth_dev_get_addr_by_port(uint8_t port_id, struct rte_pci_addr *addr) return 0; } +int +rte_eth_dev_get_port_by_addr(struct rte_pci_addr *addr, uint8_t *port_id) +{ + struct rte_pci_addr *tmp; + + for (*port_id = 0; *port_id < RTE_MAX_ETHPORTS; (*port_id)++) { + if (!rte_eth_devices[*port_id].attached) + continue; + if (!rte_eth_devices[*port_id].pci_dev) + continue; + tmp = &rte_eth_devices[*port_id].pci_dev->addr; + if (eal_compare_pci_addr(tmp, addr) == 0) + return 0; + } + return -1; +} + static int rte_eth_dev_rx_queue_config(struct rte_eth_dev *dev, uint16_t nb_queues) { diff --git a/lib/librte_ether/rte_ethdev.h b/lib/librte_ether/rte_ethdev.h index fd4aa5a..8bdc8ae 100644 --- a/lib/librte_ether/rte_ethdev.h +++ b/lib/librte_ether/rte_ethdev.h @@ -1672,6 +1672,19 @@ extern int rte_eth_dev_get_addr_by_port( uint8_t port_id, struct rte_pci_addr *addr); /** + * Function for internal use by port hotplug functions. + * Returns a port identifier of a ethdev specified by pci address. + * @param addr + * The pointer to the pci address of the Ethernet device. + * @param port_id + * The pointer to the port identifier + * @return + * - 0 on success, negative on error + */ +extern int rte_eth_dev_get_port_by_addr( + struct rte_pci_addr *addr, uint8_t *port_id); + +/** * Function for internal use by dummy drivers primarily, e.g. ring-based * driver. * Allocates a new ethdev slot for an ethernet device and returns the pointer -- 1.9.1