From patchwork Thu Oct 25 14:17:40 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Stokes, Ian" X-Patchwork-Id: 989104 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 42gq3026wdz9sPB for ; Fri, 26 Oct 2018 01:17:48 +1100 (AEDT) Received: from mail.linux-foundation.org (localhost [127.0.0.1]) by mail.linuxfoundation.org (Postfix) with ESMTP id ADB941CDF; Thu, 25 Oct 2018 14:17:45 +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 DA9E81CD8 for ; Thu, 25 Oct 2018 14:17:44 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from mga11.intel.com (mga11.intel.com [192.55.52.93]) by smtp1.linuxfoundation.org (Postfix) with ESMTPS id 3F2307CB for ; Thu, 25 Oct 2018 14:17:44 +0000 (UTC) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga006.jf.intel.com ([10.7.209.51]) by fmsmga102.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 25 Oct 2018 07:17:43 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.54,424,1534834800"; d="scan'208";a="85530873" Received: from sivswdev01.ir.intel.com (HELO localhost.localdomain) ([10.237.217.45]) by orsmga006.jf.intel.com with ESMTP; 25 Oct 2018 07:17:42 -0700 From: Ian Stokes To: dev@openvswitch.org Date: Thu, 25 Oct 2018 15:17:40 +0100 Message-Id: <1540477060-8039-1-git-send-email-ian.stokes@intel.com> X-Mailer: git-send-email 1.7.0.7 X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_HI 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 1/2] netdev-dpdk: Fix netdev_dpdk_get_features(). 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 This commit fixes netdev_dpdk_get_features() by initializing a bitmap that represents current features to zero and accounting for non defined link speed values in the OpenFlow spec. The current approach for retrieving netdev dpdk features uses a pointer allocated in the stack without being initialized. As such there is no guarantee that the bitmap will be accurate. Fix this by declaring and initializing local variable 'feature' to be used when building the bitmap, with its value then assigned to the pointer. Also account for link speeds not defined in the OpenFlow spec by defaulting to NETDEV_F_OTHER for undefined link speeds. Fixes: 8a9562d21a40 ("dpif-netdev: Add DPDK netdev.") Signed-off-by: Ian Stokes --- Flavio, this patch is based on suggestions from you https://mail.openvswitch.org/pipermail/ovs-dev/2018-September/351809.html I'd like to add Co-authored-by: Flavio Leitner Signed-off-by: Flavio Leitner if you agree to sign off on this. --- lib/netdev-dpdk.c | 65 ++++++++++++++++++++++++++++++++++--------------------- 1 file changed, 40 insertions(+), 25 deletions(-) diff --git a/lib/netdev-dpdk.c b/lib/netdev-dpdk.c index f91aa27cd..35eb30f8d 100644 --- a/lib/netdev-dpdk.c +++ b/lib/netdev-dpdk.c @@ -2707,43 +2707,58 @@ netdev_dpdk_get_features(const struct netdev *netdev, { struct netdev_dpdk *dev = netdev_dpdk_cast(netdev); struct rte_eth_link link; + uint32_t feature = 0; ovs_mutex_lock(&dev->mutex); link = dev->link; ovs_mutex_unlock(&dev->mutex); - if (link.link_duplex == ETH_LINK_HALF_DUPLEX) { - if (link.link_speed == ETH_SPEED_NUM_10M) { - *current = NETDEV_F_10MB_HD; - } - if (link.link_speed == ETH_SPEED_NUM_100M) { - *current = NETDEV_F_100MB_HD; - } - if (link.link_speed == ETH_SPEED_NUM_1G) { - *current = NETDEV_F_1GB_HD; - } - } else if (link.link_duplex == ETH_LINK_FULL_DUPLEX) { - if (link.link_speed == ETH_SPEED_NUM_10M) { - *current = NETDEV_F_10MB_FD; - } - if (link.link_speed == ETH_SPEED_NUM_100M) { - *current = NETDEV_F_100MB_FD; - } - if (link.link_speed == ETH_SPEED_NUM_1G) { - *current = NETDEV_F_1GB_FD; - } - if (link.link_speed == ETH_SPEED_NUM_10G) { - *current = NETDEV_F_10GB_FD; + if (link.link_duplex == ETH_LINK_FULL_DUPLEX) { + switch (link.link_speed) { + /* OpenFlow defined values: see enum ofp_port_features */ + case ETH_SPEED_NUM_10M: + feature |= NETDEV_F_10MB_FD; + break; + case ETH_SPEED_NUM_100M: + feature |= NETDEV_F_100MB_FD; + break; + case ETH_SPEED_NUM_1G: + feature |= NETDEV_F_1GB_FD; + break; + case ETH_SPEED_NUM_10G: + feature |= NETDEV_F_10GB_FD; + break; + case ETH_SPEED_NUM_40G: + feature |= NETDEV_F_40GB_FD; + break; + case ETH_SPEED_NUM_100G: + feature |= NETDEV_F_100GB_FD; + break; + default: + feature |= NETDEV_F_OTHER; } - if (link.link_speed == ETH_SPEED_NUM_40G) { - *current = NETDEV_F_40GB_FD; + } + else if (link.link_duplex == ETH_LINK_HALF_DUPLEX) { + switch (link.link_speed) { + case ETH_SPEED_NUM_10M: + feature |= NETDEV_F_10MB_HD; + break; + case ETH_SPEED_NUM_100M: + feature |= NETDEV_F_100MB_HD; + break; + case ETH_SPEED_NUM_1G: + feature |= NETDEV_F_1GB_HD; + break; + default: + feature |= NETDEV_F_OTHER; } } if (link.link_autoneg) { - *current |= NETDEV_F_AUTONEG; + feature |= NETDEV_F_AUTONEG; } + *current = feature; *advertised = *supported = *peer = 0; return 0; 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; }