From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-pg0-f68.google.com (mail-pg0-f68.google.com [74.125.83.68]) by dpdk.org (Postfix) with ESMTP id 599891B161 for ; Sat, 6 Jan 2018 02:07:01 +0100 (CET) Received: by mail-pg0-f68.google.com with SMTP id m17so270365pgd.8 for ; Fri, 05 Jan 2018 17:07:01 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=wiM1o9mpbBe/c8w2WqZ0l9RfqYrzumaRRv6R7Bc+xH0=; b=xKsfjwO+jdG0ZH3GZ8sbVBFsrNJk0J6MfaKEa0ue627ZbteSCF2dH8NU1kpIdUGAC8 DPx9PSGtOJw9DX6scwsEYIWjZRpc3fKNnMRjtVArOUMoq7gNJs0mvSV0xlfT6EVB6uXS rYDJawWKKH99KnDSXUttjFebRVncKps03Po3nKUUiD+ti7Lqx0ymX7tn4DHE7lBuRCkU +yWuPKIEBl7oVdjkHGP1ds5WztMAJOagv6K1cD9TvuSFLjakLiy299YAlPch00LKe4wL z/DmRDXBvRPhUq8K4C+Nb1YDo+tzhdQGfDfXFO3oUVn2zuhbckAVUl40XBiT3tji1OPv xbkw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=wiM1o9mpbBe/c8w2WqZ0l9RfqYrzumaRRv6R7Bc+xH0=; b=aKldGrlJ73ZBQOSIQDNfU+EHBIE8/Yh7jNPSrhli2eI6NqwsmPGqcuqB7TX+4iNABg dxgtcqI3BH+YkAaIE7KOFhJE2pEECbspQJFU8laBwYyuwmGxuSadKISu5xMD+x0sAbu+ zruPKql9+X0b0lNQ7GFNeBResKMkh8ApIUoRbLamIho0pI2yeZqilP3nMs1IiVlYwiHx xTEUppXMq0vTAv3UEHKbWrVRsJipJkrI5if56vj92sl40FKT149Q1VI2PIkCE0OUQmsQ GDj0oWTlGZDQzz67spzGfT8LVyJxFEbWdtIptEy818QYBqpRE/AKnpJfwGEXkCiaodWo eFLQ== X-Gm-Message-State: AKGB3mIdMwUm14bRhTVfVT1X9mB2WtN0TmHm625kkj9mAr0KD1eZV/TF Qhizb5MKZkX8qfx4XmymzDYcn6Q4tDM= X-Google-Smtp-Source: ACJfBovZXBceGuFwyf7WWsWB4Nzy75hwjJ9aJ+pHJ7JZtszMzi+APHo7hOniDqx5P7wHKTkGAS25eg== X-Received: by 10.101.80.74 with SMTP id k10mr3867340pgo.418.1515200819959; Fri, 05 Jan 2018 17:06:59 -0800 (PST) Received: from xeon-e3.lan (204-195-18-133.wavecable.com. [204.195.18.133]) by smtp.gmail.com with ESMTPSA id p14sm12385018pgn.37.2018.01.05.17.06.59 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 05 Jan 2018 17:06:59 -0800 (PST) From: Stephen Hemminger To: dev@dpdk.org Cc: Stephen Hemminger Date: Fri, 5 Jan 2018 17:06:43 -0800 Message-Id: <20180106010656.9167-3-stephen@networkplumber.org> X-Mailer: git-send-email 2.15.1 In-Reply-To: <20180106010656.9167-1-stephen@networkplumber.org> References: <20180106010656.9167-1-stephen@networkplumber.org> Subject: [dpdk-dev] [PATCH v2 02/15] ethdev: add linkstatus get/set helper functions 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: Sat, 06 Jan 2018 01:07:01 -0000 Many drivers are all doing copy/paste of the same code to atomically update the link status. Reduce duplication, and allow for future changes by having common function for this. Signed-off-by: Stephen Hemminger --- lib/librte_ether/rte_ethdev.c | 35 +++++++++++++++++++++++++++++++++++ lib/librte_ether/rte_ethdev.h | 28 ++++++++++++++++++++++++++++ 2 files changed, 63 insertions(+) diff --git a/lib/librte_ether/rte_ethdev.c b/lib/librte_ether/rte_ethdev.c index 27b52131ef01..4897e1dcda14 100644 --- a/lib/librte_ether/rte_ethdev.c +++ b/lib/librte_ether/rte_ethdev.c @@ -1495,6 +1495,41 @@ rte_eth_link_get_nowait(uint16_t port_id, struct rte_eth_link *eth_link) } } +int +_rte_eth_linkstatus_set(struct rte_eth_dev *dev, + const struct rte_eth_link *new_link) +{ + volatile uint64_t *dev_link + = (volatile uint64_t *)&(dev->data->dev_link); + union { + uint64_t val64; + struct rte_eth_link link; + } orig; + + RTE_BUILD_BUG_ON(sizeof(*new_link) != sizeof(uint64_t)); + + orig.val64 = rte_atomic64_exchange(dev_link, + *(const uint64_t *)new_link); + + return (orig.link.link_status == new_link->link_status) ? -1 : 0; +} + +void +_rte_eth_linkstatus_get(const struct rte_eth_dev *dev, + struct rte_eth_link *link) +{ + const uint64_t *src = (const uint64_t *)&(dev->data->dev_link); + volatile uint64_t *dst = (uint64_t *)link; + + RTE_BUILD_BUG_ON(sizeof(*link) != sizeof(uint64_t)); + + /* + * Note: this should never fail since both destination and expected + * values are the same and are a pointer from caller. + */ + rte_atomic64_cmpset(dst, *dst, *src); +} + int rte_eth_stats_get(uint16_t port_id, struct rte_eth_stats *stats) { diff --git a/lib/librte_ether/rte_ethdev.h b/lib/librte_ether/rte_ethdev.h index b10e2a92da71..b47402b797c3 100644 --- a/lib/librte_ether/rte_ethdev.h +++ b/lib/librte_ether/rte_ethdev.h @@ -2218,6 +2218,34 @@ int rte_eth_dev_set_link_down(uint16_t port_id); */ void rte_eth_dev_close(uint16_t port_id); + +/** + * @internal + * Atomically set the link status for the specific device. + * It is for use by DPDK device driver use only. + * User applications should not call it + * + * @param dev + * Pointer to struct rte_eth_dev. + * @param link + * New link status value. + * @return + * -1 if link state has changed, 0 if the same. + */ +int _rte_eth_linkstatus_set(struct rte_eth_dev *dev, + const struct rte_eth_link *link); + +/** + * @internal + * Atomically get the link speed and status. + * @param dev + * Pointer to struct rte_eth_dev. + * @param link + * link status value. + */ +void _rte_eth_linkstatus_get(const struct rte_eth_dev *dev, + struct rte_eth_link *link); + /** * Reset a Ethernet device and keep its port id. * -- 2.15.1