From patchwork Tue Nov 4 03:45:27 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tetsuya Mukawa X-Patchwork-Id: 1093 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 2C83F7F45; Tue, 4 Nov 2014 04:37:21 +0100 (CET) Received: from mail-pd0-f169.google.com (mail-pd0-f169.google.com [209.85.192.169]) by dpdk.org (Postfix) with ESMTP id C71987EB0 for ; Tue, 4 Nov 2014 04:37:11 +0100 (CET) Received: by mail-pd0-f169.google.com with SMTP id y10so12802304pdj.14 for ; Mon, 03 Nov 2014 19:46:28 -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=kM7CHUl16uO0+vzSW32QuSXBioPJ+2TE1EZ2I5FWjZU=; b=comgAwNoBpnr90OQYJh9b1wzYRfsYFfQH+kL2u/yXVSe5slRGVsmF6aXNB5Sv6n1dK pxwnhqJIg9cD45C5rmjeDyA4QQO98zXhBav9UeaPI1nLdQWoErS4GusyK11LdFmJkEO0 XnWcKuyc8k5BgM0tJknDDLHDYDAEg53O6c5OTN+fiSbA/LjR53rN/QGLmJz1wnbyuwuK vhw1ZtrnIV5BcTMr0uOyJH4EU1000VjLRVitxFbst7BCIihAKcGeQCaGogpx3agHQGMF 6xxJf4v+YPs7+G+78zZcpZa3QOd5OUyOHusm9OO39ywkPJDnIh7AMBrbEQvOUqBWDQr5 6YJQ== X-Gm-Message-State: ALoCoQl9vTPMyuvJaC12Ler0Gw6jtntVTTCpO6VbluqnwFPKwOXRKmK+vsABrD5ok7nAmo7gsR6E X-Received: by 10.66.184.47 with SMTP id er15mr46731857pac.5.1415072787968; Mon, 03 Nov 2014 19:46:27 -0800 (PST) Received: from localhost.localdomain (napt.igel.co.jp. [219.106.231.132]) by mx.google.com with ESMTPSA id jc3sm18430580pbb.49.2014.11.03.19.46.26 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 03 Nov 2014 19:46:27 -0800 (PST) From: Tetsuya Mukawa To: dev@dpdk.org Date: Tue, 4 Nov 2014 12:45:27 +0900 Message-Id: <1415072748-31937-8-git-send-email-mukawa@igel.co.jp> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1415072748-31937-1-git-send-email-mukawa@igel.co.jp> References: <1414572576-21371-1-git-send-email-mukawa@igel.co.jp> <1415072748-31937-1-git-send-email-mukawa@igel.co.jp> Cc: nakajima.yoshihiro@lab.ntt.co.jp, masutani.hitoshi@lab.ntt.co.jp Subject: [dpdk-dev] [RFC PATCH v2 07/28] ethdev: Add functions to know which port is attached or detached 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 patch adds rte_eth_dev_save() and rte_eth_dev_get_changed_port(). rte_eth_dev_save() is used for saving current rte_eth_dev structures. rte_eth_dev_get_changed_port() receives the rte_eth_dev structures, then compare these with current values to know which port is actually attached or detached. Signed-off-by: Tetsuya Mukawa --- lib/librte_ether/rte_ethdev.c | 18 ++++++++++++++++++ lib/librte_ether/rte_ethdev.h | 21 +++++++++++++++++++++ 2 files changed, 39 insertions(+) diff --git a/lib/librte_ether/rte_ethdev.c b/lib/librte_ether/rte_ethdev.c index b623e31..939bf3b 100644 --- a/lib/librte_ether/rte_ethdev.c +++ b/lib/librte_ether/rte_ethdev.c @@ -391,6 +391,24 @@ rte_eth_dev_count(void) return (nb_ports); } +void +rte_eth_dev_save(struct rte_eth_dev *devs) +{ + /* save current rte_eth_devices */ + memcpy(devs, rte_eth_devices, + sizeof(struct rte_eth_dev) * RTE_MAX_ETHPORTS); +} + +int +rte_eth_dev_get_changed_port(struct rte_eth_dev *devs, uint8_t *port_id) +{ + /* check which port was attached or detached */ + for (*port_id = 0; *port_id < RTE_MAX_ETHPORTS; (*port_id)++, devs++) + if (rte_eth_devices[*port_id].attached ^ devs->attached) + 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 99cc8ce..106ba5c 100644 --- a/lib/librte_ether/rte_ethdev.h +++ b/lib/librte_ether/rte_ethdev.h @@ -1618,6 +1618,27 @@ extern struct rte_eth_dev rte_eth_devices[]; extern uint8_t rte_eth_dev_count(void); /** + * Function for internal use by port hotplug functions. + * Copies current ethdev structures to the specified pointer. + * + * @param devs The pointer to the ethdev structures + */ +extern void rte_eth_dev_save(struct rte_eth_dev *devs); + +/** + * Function for internal use by port hotplug functions. + * Compare the specified ethdev structures with currrents. Then + * if there is a port which status is changed, fill the specified pointer + * with the port id of that port. + * @param devs The pointer to the ethdev structures + * @param port_id The pointer to the port id + * @return + * - 0 on success, negative on error + */ +extern int rte_eth_dev_get_changed_port( + struct rte_eth_dev *devs, 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