From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga09.intel.com (mga09.intel.com [134.134.136.24]) by dpdk.org (Postfix) with ESMTP id C537CC300 for ; Wed, 17 Feb 2016 15:20:34 +0100 (CET) Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by orsmga102.jf.intel.com with ESMTP; 17 Feb 2016 06:20:35 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.22,460,1449561600"; d="scan'208";a="917164960" Received: from irvmail001.ir.intel.com ([163.33.26.43]) by fmsmga002.fm.intel.com with ESMTP; 17 Feb 2016 06:20:33 -0800 Received: from sivswdev02.ir.intel.com (sivswdev02.ir.intel.com [10.237.217.46]) by irvmail001.ir.intel.com (8.14.3/8.13.6/MailSET/Hub) with ESMTP id u1HEKWIY019038; Wed, 17 Feb 2016 14:20:32 GMT Received: from sivswdev02.ir.intel.com (localhost [127.0.0.1]) by sivswdev02.ir.intel.com with ESMTP id u1HEKWi7014348; Wed, 17 Feb 2016 14:20:32 GMT Received: (from fyigit@localhost) by sivswdev02.ir.intel.com with id u1HEKW9M014344; Wed, 17 Feb 2016 14:20:32 GMT From: Ferruh Yigit To: dev@dpdk.org Date: Wed, 17 Feb 2016 14:20:15 +0000 Message-Id: <1455718817-14171-2-git-send-email-ferruh.yigit@intel.com> X-Mailer: git-send-email 1.7.4.1 In-Reply-To: <1455718817-14171-1-git-send-email-ferruh.yigit@intel.com> References: <1455718817-14171-1-git-send-email-ferruh.yigit@intel.com> Subject: [dpdk-dev] [PATCH 1/3] ethdev: add helper functions to get eth_dev and dev private data 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, 17 Feb 2016 14:20:35 -0000 This is to provide abstraction and reduce global variable access. Global variable rte_eth_devices kept exported to not break ABI. Signed-off-by: Ferruh Yigit --- lib/librte_ether/rte_ethdev.h | 44 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/lib/librte_ether/rte_ethdev.h b/lib/librte_ether/rte_ethdev.h index 6afb5a9..7209b83 100644 --- a/lib/librte_ether/rte_ethdev.h +++ b/lib/librte_ether/rte_ethdev.h @@ -3881,6 +3881,50 @@ rte_eth_dma_zone_reserve(const struct rte_eth_dev *eth_dev, const char *name, uint16_t queue_id, size_t size, unsigned align, int socket_id); +/** + * Return rte_eth_dev by port id + * + * This is to abstract device access and limit global variable access. + * + * @param port_id + * port_id of the device to return. + */ +static inline struct rte_eth_dev * +rte_eth_by_port(uint16_t port_id) +{ + return &rte_eth_devices[port_id]; +} + +/** + * Return rte_eth_dev private data structure by port id + * + * This is to abstract device private data access and + * limit global variable access. + * + * @param port_id + * port_id of the device to return. + */ +static inline void * +rte_eth_private_by_port(uint16_t port_id) +{ + return rte_eth_devices[port_id].data->dev_private; +} + +/** + * Return rte_eth_dev private data structure by rte_eth_dev + * + * This is helper function to access device private data, also + * provides some abstraction on how private data kept. + * + * @param dev + * rte_eth_dev + */ +static inline void * +rte_eth_private_by_dev(struct rte_eth_dev *dev) +{ + return dev->data->dev_private; +} + #ifdef __cplusplus } #endif -- 2.5.0