From patchwork Thu Oct 25 14:17:56 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Stokes, Ian" X-Patchwork-Id: 989105 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=openvswitch.org (client-ip=140.211.169.12; helo=mail.linuxfoundation.org; envelope-from=ovs-dev-bounces@openvswitch.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=intel.com Received: from mail.linuxfoundation.org (mail.linuxfoundation.org [140.211.169.12]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 42gq3W4hR8z9sPv for ; Fri, 26 Oct 2018 01:18:15 +1100 (AEDT) Received: from mail.linux-foundation.org (localhost [127.0.0.1]) by mail.linuxfoundation.org (Postfix) with ESMTP id 8AC6B1CFD; Thu, 25 Oct 2018 14:18:04 +0000 (UTC) X-Original-To: dev@openvswitch.org Delivered-To: ovs-dev@mail.linuxfoundation.org Received: from smtp1.linuxfoundation.org (smtp1.linux-foundation.org [172.17.192.35]) by mail.linuxfoundation.org (Postfix) with ESMTPS id 610831CF9 for ; Thu, 25 Oct 2018 14:18:03 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from mga05.intel.com (mga05.intel.com [192.55.52.43]) by smtp1.linuxfoundation.org (Postfix) with ESMTPS id F01C07C3 for ; Thu, 25 Oct 2018 14:18:02 +0000 (UTC) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga008.jf.intel.com ([10.7.209.65]) by fmsmga105.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 25 Oct 2018 07:18:02 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.54,424,1534834800"; d="scan'208";a="84404160" Received: from sivswdev01.ir.intel.com (HELO localhost.localdomain) ([10.237.217.45]) by orsmga008.jf.intel.com with ESMTP; 25 Oct 2018 07:18:01 -0700 From: Ian Stokes To: dev@openvswitch.org Date: Thu, 25 Oct 2018 15:17:56 +0100 Message-Id: <1540477076-8412-1-git-send-email-ian.stokes@intel.com> X-Mailer: git-send-email 1.7.0.7 X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on smtp1.linux-foundation.org Cc: fbl@sysclose.org Subject: [ovs-dev] [PATCH v1 2/2] netdev-dpdk: Add link speed to get_status(). X-BeenThere: ovs-dev@openvswitch.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: ovs-dev-bounces@openvswitch.org Errors-To: ovs-dev-bounces@openvswitch.org Report the link speed of the device in netdev_dpdk_get_status() function. Link speed is already reported as part of the netdev_get_features() function. However only link speeds defined in the OpenFlow specs are supported so speeds such as 25 Gbps etc. are not shown. The link speed for the device is available in Mbps in rte_eth_link. This commit converts the link speed for a given dpdk device to an easy to read string and reports it in get_status(). Suggested-by: Flavio Leitner Signed-off-by: Ian Stokes --- lib/netdev-dpdk.c | 62 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) diff --git a/lib/netdev-dpdk.c b/lib/netdev-dpdk.c index 35eb30f8d..b3a2430a0 100644 --- a/lib/netdev-dpdk.c +++ b/lib/netdev-dpdk.c @@ -164,6 +164,8 @@ typedef uint16_t dpdk_port_t; #define VHOST_ENQ_RETRY_NUM 8 #define IF_NAME_SZ (PATH_MAX > IFNAMSIZ ? PATH_MAX : IFNAMSIZ) +#define MAX_LINK_SPEED_STR 12 + static const struct rte_eth_conf port_conf = { .rxmode = { .mq_mode = ETH_MQ_RX_RSS, @@ -3022,11 +3024,62 @@ netdev_dpdk_vhost_user_get_status(const struct netdev *netdev, return 0; } +/* + * Convert a given uint32_t link speed defined in DPDK to a string + * equivalent. + */ +static void +netdev_dpdk_link_speed_to_str__(uint32_t link_speed, char *speed_str) +{ + switch (link_speed) { + case ETH_SPEED_NUM_10M: + snprintf(speed_str, MAX_LINK_SPEED_STR,"%s", "10 Mbps"); + break; + case ETH_SPEED_NUM_100M: + snprintf(speed_str, MAX_LINK_SPEED_STR,"%s", "100 Mbps"); + break; + case ETH_SPEED_NUM_1G: + snprintf(speed_str, MAX_LINK_SPEED_STR,"%s", "1 Gbps"); + break; + case ETH_SPEED_NUM_2_5G: + snprintf(speed_str, MAX_LINK_SPEED_STR,"%s", "2.5 Gbps"); + break; + case ETH_SPEED_NUM_5G: + snprintf(speed_str, MAX_LINK_SPEED_STR,"%s", "5 Gbps"); + break; + case ETH_SPEED_NUM_10G: + snprintf(speed_str, MAX_LINK_SPEED_STR,"%s", "10 Gbps"); + break; + case ETH_SPEED_NUM_20G: + snprintf(speed_str, MAX_LINK_SPEED_STR,"%s", "20 Gbps"); + break; + case ETH_SPEED_NUM_25G: + snprintf(speed_str, MAX_LINK_SPEED_STR,"%s", "25 Gbps"); + break; + case ETH_SPEED_NUM_40G: + snprintf(speed_str, MAX_LINK_SPEED_STR,"%s", "40 Gbps"); + break; + case ETH_SPEED_NUM_50G: + snprintf(speed_str, MAX_LINK_SPEED_STR,"%s", "50 Gbps"); + break; + case ETH_SPEED_NUM_56G: + snprintf(speed_str, MAX_LINK_SPEED_STR,"%s", "56 Gbps"); + break; + case ETH_SPEED_NUM_100G: + snprintf(speed_str, MAX_LINK_SPEED_STR,"%s", "100 Gbps"); + break; + default: + snprintf(speed_str, MAX_LINK_SPEED_STR,"%s", "Not Defined"); + } +} + static int netdev_dpdk_get_status(const struct netdev *netdev, struct smap *args) { struct netdev_dpdk *dev = netdev_dpdk_cast(netdev); struct rte_eth_dev_info dev_info; + struct rte_eth_link link; + char link_speed_str [MAX_LINK_SPEED_STR]; if (!rte_eth_dev_is_valid_port(dev->port_id)) { return ENODEV; @@ -3034,6 +3087,7 @@ netdev_dpdk_get_status(const struct netdev *netdev, struct smap *args) ovs_mutex_lock(&dev->mutex); rte_eth_dev_info_get(dev->port_id, &dev_info); + link = dev->link; ovs_mutex_unlock(&dev->mutex); smap_add_format(args, "port_no", DPDK_PORT_ID_FMT, dev->port_id); @@ -3065,6 +3119,14 @@ netdev_dpdk_get_status(const struct netdev *netdev, struct smap *args) dev_info.pci_dev->id.device_id); } + /* Not all link speeds are defined in the OpenFlow specs e.g. 25 Gbps. + * In that case the speed will not be reported as part of the usual + * call to get_features(). Get the link speed of the device and add it + * to the device status in an easy to read string format. + */ + netdev_dpdk_link_speed_to_str__(link.link_speed, link_speed_str); + smap_add_format(args, "link_speed", "%s", link_speed_str); + return 0; }