From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from out1-smtp.messagingengine.com (out1-smtp.messagingengine.com [66.111.4.25]) by dpdk.org (Postfix) with ESMTP id 474371BBBC for ; Fri, 11 May 2018 01:58:51 +0200 (CEST) Received: from compute1.internal (compute1.nyi.internal [10.202.2.41]) by mailout.nyi.internal (Postfix) with ESMTP id DC7AB2272A; Thu, 10 May 2018 19:58:49 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute1.internal (MEProxy); Thu, 10 May 2018 19:58:49 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=monjalon.net; h= cc:date:from:in-reply-to:message-id:references:subject:to :x-me-sender:x-me-sender:x-sasl-enc; s=mesmtp; bh=TAbhejFP425XdS /KuuACHm6A9fAX2uTOMD9tt6ZzAvQ=; b=Au08/zbtJhSPw8VZMVLUcqBacWzOFD rBWdJCr9a0EH/85KfRN0v4PHfq1z0MmHyAJabbexsybE4VzKUG8scM7pe0Y872gf 31rduXxm5N1tCNri1NbBQAAZOUnrUkRoOi/9aE5ZyJOxY7arFAwg4iHOgp35R2Ko 2/RVNImqOkOH4= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:date:from:in-reply-to:message-id :references:subject:to:x-me-sender:x-me-sender:x-sasl-enc; s= fm2; bh=TAbhejFP425XdS/KuuACHm6A9fAX2uTOMD9tt6ZzAvQ=; b=XJ+t4vx4 zo01iy/UtAARjaDxJSEjfdcvJiw3zvNzxb6ySu9/zTE36B5Y3dci/o6Kh9h8SRgj hokcWmxXujYPatGWo8u8NbtgQw6P1cTgjoIDNB2XEWA65Z9bdUOTYPSU2aiw63Su QPhGRgSA2XD0n2zULQN4NWFYMQUzNdRHVgzRbXQ7jj3lnLJbbGSCTg1FdAK1movh i/eeoSgrY88BQnpUhU2rdrVve6fRZxLiV5yP9AkVCLPQ0PpmIXC/bMUmXAF4nFly rZYTHjotf+ijLoOpWjBMw9PgVkmyCItQkah9EHVZWuQRPlOCv3tn0ZQ1TRISha9T o5UugXUIY3zn0w== X-ME-Sender: Received: from xps.monjalon.net (184.203.134.77.rev.sfr.net [77.134.203.184]) by mail.messagingengine.com (Postfix) with ESMTPA id F1110E43E8; Thu, 10 May 2018 19:58:48 -0400 (EDT) From: Thomas Monjalon To: dev@dpdk.org Cc: matan@mellanox.com, arybchenko@solarflare.com, stephen@networkplumber.org, ferruh.yigit@intel.com Date: Fri, 11 May 2018 01:58:31 +0200 Message-Id: <20180510235836.1099-7-thomas@monjalon.net> X-Mailer: git-send-email 2.16.2 In-Reply-To: <20180510235836.1099-1-thomas@monjalon.net> References: <20180509094337.26112-1-thomas@monjalon.net> <20180510235836.1099-1-thomas@monjalon.net> Subject: [dpdk-dev] [PATCH v3 06/11] ethdev: allow ownership operations on unused port X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 10 May 2018 23:58:51 -0000 From: Matan Azrad When the state will be updated later than in allocation, we may need to update the ownership of a port which is still in state unused. It will be used to take ownership of a port before it is declared as available for other entities. Cc: stable@dpdk.org Signed-off-by: Matan Azrad Acked-by: Thomas Monjalon Reviewed-by: Andrew Rybchenko Reviewed-by: Stephen Hemminger --- lib/librte_ethdev/rte_ethdev.c | 28 ++++++++++++++++++++-------- 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/lib/librte_ethdev/rte_ethdev.c b/lib/librte_ethdev/rte_ethdev.c index 575ae48c0..9bd397b66 100644 --- a/lib/librte_ethdev/rte_ethdev.c +++ b/lib/librte_ethdev/rte_ethdev.c @@ -10,6 +10,7 @@ #include #include #include +#include #include #include #include @@ -227,6 +228,12 @@ rte_eth_dev_shared_data_prepare(void) rte_spinlock_unlock(&rte_eth_shared_data_lock); } +static bool +is_allocated(const struct rte_eth_dev *ethdev) +{ + return ethdev->data->name[0] != '\0'; +} + struct rte_eth_dev * rte_eth_dev_allocated(const char *name) { @@ -414,10 +421,14 @@ static int _rte_eth_dev_owner_set(const uint16_t port_id, const uint64_t old_owner_id, const struct rte_eth_dev_owner *new_owner) { + struct rte_eth_dev *ethdev = &rte_eth_devices[port_id]; struct rte_eth_dev_owner *port_owner; int sret; - RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV); + if (port_id >= RTE_MAX_ETHPORTS || !is_allocated(ethdev)) { + RTE_PMD_DEBUG_TRACE("Port id %"PRIu16" is not allocated.\n", port_id); + return -ENODEV; + } if (!rte_eth_is_valid_owner_id(new_owner->id) && !rte_eth_is_valid_owner_id(old_owner_id)) @@ -488,9 +499,10 @@ rte_eth_dev_owner_delete(const uint64_t owner_id) rte_spinlock_lock(&rte_eth_dev_shared_data->ownership_lock); if (rte_eth_is_valid_owner_id(owner_id)) { - RTE_ETH_FOREACH_DEV_OWNED_BY(port_id, owner_id) - memset(&rte_eth_devices[port_id].data->owner, 0, - sizeof(struct rte_eth_dev_owner)); + for (port_id = 0; port_id < RTE_MAX_ETHPORTS; port_id++) + if (rte_eth_devices[port_id].data->owner.id == owner_id) + memset(&rte_eth_devices[port_id].data->owner, 0, + sizeof(struct rte_eth_dev_owner)); RTE_PMD_DEBUG_TRACE("All port owners owned by %016"PRIX64 " identifier have removed.\n", owner_id); } @@ -502,17 +514,17 @@ int __rte_experimental rte_eth_dev_owner_get(const uint16_t port_id, struct rte_eth_dev_owner *owner) { int ret = 0; + struct rte_eth_dev *ethdev = &rte_eth_devices[port_id]; rte_eth_dev_shared_data_prepare(); rte_spinlock_lock(&rte_eth_dev_shared_data->ownership_lock); - if (!rte_eth_dev_is_valid_port(port_id)) { - RTE_PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id); + if (port_id >= RTE_MAX_ETHPORTS || !is_allocated(ethdev)) { + RTE_PMD_DEBUG_TRACE("Port id %"PRIu16" is not allocated.\n", port_id); ret = -ENODEV; } else { - rte_memcpy(owner, &rte_eth_devices[port_id].data->owner, - sizeof(*owner)); + rte_memcpy(owner, ðdev->data->owner, sizeof(*owner)); } rte_spinlock_unlock(&rte_eth_dev_shared_data->ownership_lock); -- 2.16.2