From patchwork Tue Dec 9 03:42:32 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tetsuya Mukawa X-Patchwork-Id: 1835 Return-Path: X-Original-To: patchwork@dpdk.org Delivered-To: patchwork@dpdk.org Received: from [92.243.14.124] (localhost [IPv6:::1]) by dpdk.org (Postfix) with ESMTP id 539AF8065; Tue, 9 Dec 2014 04:43:36 +0100 (CET) Received: from mail-pd0-f175.google.com (mail-pd0-f175.google.com [209.85.192.175]) by dpdk.org (Postfix) with ESMTP id 752747F61 for ; Tue, 9 Dec 2014 04:43:32 +0100 (CET) Received: by mail-pd0-f175.google.com with SMTP id y10so6444312pdj.34 for ; Mon, 08 Dec 2014 19:43:31 -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=2Da2bjxhrIVffa8UxZYBLwIfVpS+NXNnCAhpcEQdD+A=; b=TH/cre4H5MRSVIE2aupd//6MLUVvB1D8EseawW2l9DI44AtLzDirjBiTciMdsCuU9k z7bc/du9ZX4RLtD3YKn4bTy61dwSswTCDfctRZZXGU2fQZ8HA2o/KdgXN4N/xdG1YYLt U4MVXMl+KUCPDQZrqgy3vxWZxnL79bB//ulhsYgsgMCmShHe+9CAbHBiVxvlvdngUFmm VkuJKQ5u5pq0HkkPHBiS9PGdQ0ja2iRn1ityhl8lT1SGh5GAL86UT8FXP/q7GXc8rjoH hHYs6lfzJHdcvh6J+VCXDCJUqEHmu/z0lUNyXFUTWG4uwgeP4thGd1IhHt5u1wNRtD5t P8wA== X-Gm-Message-State: ALoCoQlcgWkB3doBaoQjL2YbFLtjtf3bTG1e37UgBXegJW6WU+lXflnSfKNGqp5dGDOzUdGCdZZU X-Received: by 10.66.217.228 with SMTP id pb4mr1416402pac.116.1418096611840; Mon, 08 Dec 2014 19:43:31 -0800 (PST) Received: from eris.hq.igel.co.jp (napt.igel.co.jp. [219.106.231.132]) by mx.google.com with ESMTPSA id xx2sm2185pab.17.2014.12.08.19.43.29 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 08 Dec 2014 19:43:31 -0800 (PST) From: Tetsuya Mukawa To: dev@dpdk.org Date: Tue, 9 Dec 2014 12:42:32 +0900 Message-Id: <1418096571-27531-10-git-send-email-mukawa@igel.co.jp> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1418096571-27531-1-git-send-email-mukawa@igel.co.jp> References: <1416474399-16851-1-git-send-email-mukawa@igel.co.jp> <1418096571-27531-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 v2 09/28] 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: , Errors-To: dev-bounces@dpdk.org Sender: "dev" 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 | 22 ++++++++++++++++++++++ lib/librte_ether/rte_ethdev.h | 13 +++++++++++++ 2 files changed, 35 insertions(+) diff --git a/lib/librte_ether/rte_ethdev.c b/lib/librte_ether/rte_ethdev.c index ddaf14a..4e9f0f7 100644 --- a/lib/librte_ether/rte_ethdev.c +++ b/lib/librte_ether/rte_ethdev.c @@ -454,6 +454,28 @@ 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; + + if ((addr == NULL) || (port_id == NULL)) { + PMD_DEBUG_TRACE("Null pointer is specified\n"); + return -1; + } + + 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 30277a2..8c55c56 100644 --- a/lib/librte_ether/rte_ethdev.h +++ b/lib/librte_ether/rte_ethdev.h @@ -1676,6 +1676,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