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 BBCD22BAC for ; Sun, 20 May 2018 13:00:50 +0200 (CEST) Received: from compute1.internal (compute1.nyi.internal [10.202.2.41]) by mailout.nyi.internal (Postfix) with ESMTP id 0C55122184; Sun, 20 May 2018 07:00:50 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute1.internal (MEProxy); Sun, 20 May 2018 07:00:50 -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=uKbaAFLNSvH6Ky YiFClV6OFIFrKy7PVaVEjSBZ57s2k=; b=M/9kWBjPHmzQhf5mhh81S6TU9hCNml EL9oiTHoOD9I7h2WSpnfsLjo6P2/ZRPX9JNtwY3mv8SXmHjXL2mDQ6J0c6H9rrOc ok81LuF5v0HKmtzdPcED4LJ2MYsJjU3Y5kcStjx1L01U3eg9QPziZ0VVV4mMdf67 wKxDfYSO/R7do= 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=uKbaAFLNSvH6KyYiFClV6OFIFrKy7PVaVEjSBZ57s2k=; b=QsFPPmyx m7HZ03HKVyUnAap44DWFHoKU/EyHnax0LqUJu12v2gXGznp1W2Zv7oYAnn6RxWFe CwOdES1jv5xk5Q4RJp4e1y1wtnNbNbBCWN0YjlbEMHmjQgvPrq8kX+q8oUOa3mvQ BSZo0GeTXhWmtIOM2IaQJ3JdLEtFOZotm1EuNlPIrCI2N72fT03NmEuIdm7rIR6r zs53GnWwjt3k+/LlKxNZVbzuDVLTrZ9cypZ6omKt0QvQZhoQ3axv9SlLP5Wp0wHU ka+vl64Y/Q/zAuJlP4NWfZOz4kVSsprJtsBAtBUAIYo2Fx9SD0rWtuCjRMuum8ci LiX9H5Cz8dfc/g== X-ME-Proxy: X-ME-Proxy: X-ME-Proxy: X-ME-Proxy: X-ME-Proxy: X-ME-Proxy: X-ME-Sender: Received: from xps.monjalon.net (114.149.6.93.rev.sfr.net [93.6.149.114]) by mail.messagingengine.com (Postfix) with ESMTPA id 345EA10266; Sun, 20 May 2018 07:00:49 -0400 (EDT) From: Thomas Monjalon To: stable@dpdk.org Cc: Matan Azrad Date: Sun, 20 May 2018 13:00:04 +0200 Message-Id: <20180520110006.9026-3-thomas@monjalon.net> X-Mailer: git-send-email 2.16.2 In-Reply-To: <20180520110006.9026-1-thomas@monjalon.net> References: <20180520110006.9026-1-thomas@monjalon.net> Subject: [dpdk-stable] [PATCH 18.02 2/4] ethdev: allow ownership operations on unused port X-BeenThere: stable@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: patches for DPDK stable branches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 20 May 2018 11:00: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. Signed-off-by: Matan Azrad Acked-by: Thomas Monjalon Reviewed-by: Andrew Rybchenko Reviewed-by: Stephen Hemminger --- lib/librte_ether/rte_ethdev.c | 28 ++++++++++++++++++++-------- 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/lib/librte_ether/rte_ethdev.c b/lib/librte_ether/rte_ethdev.c index 365540d3f..4ce990776 100644 --- a/lib/librte_ether/rte_ethdev.c +++ b/lib/librte_ether/rte_ethdev.c @@ -10,6 +10,7 @@ #include #include #include +#include #include #include #include @@ -222,6 +223,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'; +} + static struct rte_eth_dev * _rte_eth_dev_allocated(const char *name) { @@ -424,10 +431,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)) @@ -498,9 +509,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); } @@ -512,17 +524,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