From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from dpdk.org (dpdk.org [92.243.14.124]) by inbox.dpdk.org (Postfix) with ESMTP id 4DACFA04A4; Tue, 26 May 2020 21:11:09 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id B65D51D6F6; Tue, 26 May 2020 21:10:54 +0200 (CEST) Received: from mailout1.w1.samsung.com (mailout1.w1.samsung.com [210.118.77.11]) by dpdk.org (Postfix) with ESMTP id 0D4611D6F3 for ; Tue, 26 May 2020 21:10:53 +0200 (CEST) Received: from eucas1p2.samsung.com (unknown [182.198.249.207]) by mailout1.w1.samsung.com (KnoxPortal) with ESMTP id 20200526191052euoutp01e3695ccd1a71c5a131970845ba5c2d20~Sqb4RmA1O3216332163euoutp01d for ; Tue, 26 May 2020 19:10:52 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout1.w1.samsung.com 20200526191052euoutp01e3695ccd1a71c5a131970845ba5c2d20~Sqb4RmA1O3216332163euoutp01d DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1590520252; bh=r/Zgdgw3cI5ClABDcivjVEPBf0kVTXTPMgQM9bIHrGk=; h=From:To:Subject:Date:In-Reply-To:Reply-To:References:From; b=APDHQ8QAzK3x6KRsuk6GrgjZUkN2oqGphSKZz29oXHgWWuvfEW3I7cvsqIbaU2ihY Nq1StWVmjF6kxanHhQVlElJrbozJJN+agBzo5JhiHgUHb2OBs3WbIcswmEnshiq7KU 9kiGNizxYY9bkIz+skCMzjdEtJK+xJBO7D6qjXMw= Received: from eusmges3new.samsung.com (unknown [203.254.199.245]) by eucas1p1.samsung.com (KnoxPortal) with ESMTP id 20200526191051eucas1p17bfca30df0ee8b93d7b6d2391e726f53~Sqb3nJkOA2430024300eucas1p1I; Tue, 26 May 2020 19:10:51 +0000 (GMT) Received: from eucas1p2.samsung.com ( [182.198.249.207]) by eusmges3new.samsung.com (EUCPMTA) with SMTP id DD.A7.60698.BB96DCE5; Tue, 26 May 2020 20:10:51 +0100 (BST) Received: from eusmtrp2.samsung.com (unknown [182.198.249.139]) by eucas1p1.samsung.com (KnoxPortal) with ESMTPA id 20200526191050eucas1p16311d491af2d7640553aced2e55ac83a~Sqb2wdJtR2416724167eucas1p1G; Tue, 26 May 2020 19:10:50 +0000 (GMT) Received: from eusmgms1.samsung.com (unknown [182.198.249.179]) by eusmtrp2.samsung.com (KnoxPortal) with ESMTP id 20200526191050eusmtrp2299cec4ea77ba851cb39d7c94e5ae1f1~Sqb2v8txz0898208982eusmtrp2_; Tue, 26 May 2020 19:10:50 +0000 (GMT) X-AuditID: cbfec7f5-a29ff7000001ed1a-dd-5ecd69bbc34b Received: from eusmtip1.samsung.com ( [203.254.199.221]) by eusmgms1.samsung.com (EUCPMTA) with SMTP id F0.F4.08375.AB96DCE5; Tue, 26 May 2020 20:10:50 +0100 (BST) Received: from idyukov.rnd.samsung.ru (unknown [106.109.129.29]) by eusmtip1.samsung.com (KnoxPortal) with ESMTPA id 20200526191049eusmtip1e91038a56c93867429e81a599fd0f120~Sqb2B2I8b1119611196eusmtip1-; Tue, 26 May 2020 19:10:49 +0000 (GMT) From: Ivan Dyukov To: dev@dpdk.org, i.dyukov@samsung.com, v.kuramshin@samsung.com, thomas@monjalon.net, david.marchand@redhat.com, ferruh.yigit@intel.com, arybchenko@solarflare.com, wei.zhao1@intel.com, jia.guo@intel.com, beilei.xing@intel.com, qiming.yang@intel.com, wenzhuo.lu@intel.com Date: Tue, 26 May 2020 22:10:05 +0300 Message-Id: <20200526191033.16459-3-i.dyukov@samsung.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200526191033.16459-1-i.dyukov@samsung.com> X-Brightmail-Tracker: H4sIAAAAAAAAA0WSe0hTYRjG/Xa2c47DyXEavlkoDCSL0kyDo1lZGIyE7B8hitSVBxWdyo5a GoR3dEZqzHt5xQual9TmXURDjTktw8xLIVnIvBXmLG+Z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sfvKDLYAtSs+mKL+0JFUhI7+4xFYp2tDC SM/Q0kLPyMRSz9DYPNbKyFRJ384mJTUnsyy1SN8uQS/j5aLH7AXT5Sr2dU9lbGCcKNnFyMkh IWAisX7ODuYuRi4OIYGljBK3Fm9h6WLkAEpISLx+wgxRIyzx51oXG0TNZ0aJnxMPsIEk2AQ0 JE53zGMCSYgILGGS2LvqHCNIQljAVaLl1lVWEJtFQFWi5+YEdhCbV8BS4vzvN2wQU+UlVm84 ALaBU8BK4s2X5SwgtpBApsT6O/PZIGw5ievzvzBNYORbwMiwilEktbQ4Nz232FCvODG3uDQv XS85P3cTIzDktx37uXkH46WNwYcYBTgYlXh4E36fiRNiTSwrrsw9xCjBwawkwut09nScEG9K YmVValF+fFFpTmrxIUZToAMnMkuJJucD4zGvJN7Q1NDcwtLQ3Njc2MxCSZy3Q+BgjJBAemJJ anZqakFqEUwfEwenVAOjVe25U2pSXSf0lrfXvHxzWrv+/tM3+Y/uOF4RZDDfMoF1WW6X+UVj 0cctDXd61fKmKnA+C2SQlwqNdltyO9v+5a+LHWV+Htt3i4jb35j0ooxtmnVjv9cduRZJ4T63 D+pNO72U/miHlUWFiTt8tZweNN1hV0Efq9P2Obpf17yfd/bM35fLTrkosRRnJBpqMRcVJwIA 1LKsko8CAAA= X-CMS-MailID: 20200526191050eucas1p16311d491af2d7640553aced2e55ac83a X-Msg-Generator: CA Content-Type: text/plain; charset="utf-8" X-RootMTR: 20200526191050eucas1p16311d491af2d7640553aced2e55ac83a X-EPHeader: CA CMS-TYPE: 201P X-CMS-RootMailID: 20200526191050eucas1p16311d491af2d7640553aced2e55ac83a References: <20200427095737.11082-1-i.dyukov@samsung.com> <20200526191033.16459-1-i.dyukov@samsung.com> Subject: [dpdk-dev] [PATCH v2 2/7] ethdev: add a link status text representation X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list Reply-To: i.dyukov@samsung.com List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" This commit add function which treat link status structure and format it to text representation. Signed-off-by: Ivan Dyukov --- lib/librte_ethdev/rte_ethdev.c | 39 ++++++++++++++++++++++++++++++++++ lib/librte_ethdev/rte_ethdev.h | 31 +++++++++++++++++++++++++++ 2 files changed, 70 insertions(+) diff --git a/lib/librte_ethdev/rte_ethdev.c b/lib/librte_ethdev/rte_ethdev.c index 8e10a6fc3..8d75c2440 100644 --- a/lib/librte_ethdev/rte_ethdev.c +++ b/lib/librte_ethdev/rte_ethdev.c @@ -2385,6 +2385,45 @@ rte_eth_link_get_nowait(uint16_t port_id, struct rte_eth_link *eth_link) return 0; } +void +rte_eth_link_prepare_text(struct rte_eth_link *eth_link, uint32_t speed_unit, + struct rte_eth_link_text *link_text) +{ + uint32_t link_speed = 0; + /* prepare link speed */ + if (eth_link->link_speed == ETH_SPEED_NUM_UNKNOWN) + memcpy(link_text->link_speed, "unknown", sizeof("unknown")); + else { + if (speed_unit == ETH_SPEED_UNIT_GBPS) + link_speed = eth_link->link_speed / 1000; + else + link_speed = eth_link->link_speed; + snprintf(link_text->link_speed, sizeof(link_text->link_speed), + "%u", link_speed); + } + /* prepare link duplex */ + if (eth_link->link_duplex == ETH_LINK_FULL_DUPLEX) + memcpy(link_text->link_duplex, "full-duplex", + sizeof("full-duplex")); + else + memcpy(link_text->link_duplex, "half-duplex", + sizeof("half-duplex")); + /* prepare autoneg */ + if (eth_link->link_autoneg == ETH_LINK_AUTONEG) + memcpy(link_text->link_autoneg, "autoneg", + sizeof("autoneg")); + else + memcpy(link_text->link_autoneg, "fixed", + sizeof("fixed")); + /* prepare status */ + if (eth_link->link_status == ETH_LINK_DOWN) + memcpy(link_text->link_status, "down", + sizeof("down")); + else + memcpy(link_text->link_status, "up", + sizeof("up")); +} + int rte_eth_stats_get(uint16_t port_id, struct rte_eth_stats *stats) { diff --git a/lib/librte_ethdev/rte_ethdev.h b/lib/librte_ethdev/rte_ethdev.h index 2090af501..53d2f0c78 100644 --- a/lib/librte_ethdev/rte_ethdev.h +++ b/lib/librte_ethdev/rte_ethdev.h @@ -316,6 +316,19 @@ struct rte_eth_link { uint16_t link_status : 1; /**< ETH_LINK_[DOWN/UP] */ } __rte_aligned(8); /**< aligned for atomic64 read/write */ +/** + * Link speed units + */ +#define ETH_SPEED_UNIT_GBPS 0 +#define ETH_SPEED_UNIT_MBPS 1 + + +struct rte_eth_link_text { + char link_speed[14]; /** link speed */ + char link_duplex[12]; /** full-duplex or half-duplex */ + char link_autoneg[8]; /** autoneg or fixed */ + char link_status[5]; /** down or up */ +}; /* Utility constants */ #define ETH_LINK_HALF_DUPLEX 0 /**< Half-duplex connection (see link_duplex). */ #define ETH_LINK_FULL_DUPLEX 1 /**< Full-duplex connection (see link_duplex). */ @@ -2295,6 +2308,24 @@ int rte_eth_link_get(uint16_t port_id, struct rte_eth_link *link); */ int rte_eth_link_get_nowait(uint16_t port_id, struct rte_eth_link *link); +/** + * Format link status to textual representation. speed_unit is used to convert + * link_speed to specified unit. Also this function threats a special + * ETH_SPEED_NUM_UNKNOWN value of link_speed and return 'UNKNOWN' speed + * in this case. + * + * @param link + * Link status provided by rte_eth_link_get function + * @param speed_unit + * Target units for the speed. Following values are available: + * - ETH_SPEED_UNIT_GBPS + * - ETH_SPEED_UNIT_MBPS + * @param link_text + * A pointer to an *rte_eth_link_text* structure to be filled with + * textual representation of device status + */ +void rte_eth_link_prepare_text(struct rte_eth_link *link, uint32_t speed_unit, + struct rte_eth_link_text *link_text); /** * Retrieve the general I/O statistics of an Ethernet device. * -- 2.17.1