Received: by 2002:a25:1506:0:0:0:0:0 with SMTP id 6csp439329ybv; Fri, 7 Feb 2020 02:12:13 -0800 (PST) X-Google-Smtp-Source: APXvYqxubk4s2ubYyebMRlSBvk7Jd3WPXeSiqdyUwqibmxE0hjV9VNijQLSGUdTbjUwLinPe1hZ+ X-Received: by 2002:aca:1913:: with SMTP id l19mr1462168oii.47.1581070333021; Fri, 07 Feb 2020 02:12:13 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1581070333; cv=none; d=google.com; s=arc-20160816; b=Nf1huhxHnhH+NcdYGSnlkRQKA9iMWcKrjDK47P/8jY7Wk2Pp619XdCkSYhaMrfH0aK N9zEyVMe2RFFZq3J6uloIevStYFmuuIj5D7dp1SZk1E9ZKa7Iz79KdG7rEBdlA8gD8dW F5Zo2+FOyyd5GnVBKy2Q2vYyGGNLo1n+M5iYrIorsUHl1TdbEaKugZE8htWE2m+csWFx 5xyCE+xlatT7UdxnIhxcLYD0kuUQr/PuNgF3nRj652vN4kRutHVXeZL2wOgJ86mN/kv7 7bKKj3Yn1Zy4zzcUd4V7ASSz6J1fIrXUqVkrCqxtcyWtbk6PQjYAIal4IkKXnEO6chyg Zk4A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from; bh=id2UR+ALbFc0Ugss/7uvjN2Un9wNhJ6KnBSb9/KDWrM=; b=XHIUuy3EP9T11IGxEPTMm4VM1Y5f+topA9jWJ3OiFcU/xn2xJLmfQ2YpvNYbnZy3HT HN4hk7ZV1xrT2JOTnVZsoZHpbhjs3+WMUOJfK5Jq4AFec2OCK0e2UVAQVptIAAESSNT/ 28Z1R4S0I1R69OOpLGqe2Py6kmMGBTV91QKuPpNwwe+8iMHPbRYup+RGfcGaQWSAJLkN M1NcEqkDceAs1rRgKSN8IXkyGo8SfJ47NHQGU8LXtLYbDvHyYu3mwhnFB8LMkbX3Kzyf kuNvc7ID3ISYUDffydHpOzesWB9hH0HRXiCg49IxZxRWUHXmGaCFJnNix+8rT2y5qUE7 uxhw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=canonical.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id z15si1267373otm.168.2020.02.07.02.12.00; Fri, 07 Feb 2020 02:12:13 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=canonical.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726999AbgBGKLG (ORCPT + 99 others); Fri, 7 Feb 2020 05:11:06 -0500 Received: from youngberry.canonical.com ([91.189.89.112]:42246 "EHLO youngberry.canonical.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726587AbgBGKLG (ORCPT ); Fri, 7 Feb 2020 05:11:06 -0500 Received: from 61-220-137-37.hinet-ip.hinet.net ([61.220.137.37] helo=localhost) by youngberry.canonical.com with esmtpsa (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1j00ae-0007Js-42; Fri, 07 Feb 2020 10:10:24 +0000 From: Kai-Heng Feng To: davem@davemloft.net, mkubecek@suse.cz, jeffrey.t.kirsher@intel.com Cc: Kai-Heng Feng , Jakub Kicinski , Maxime Chevallier , Heiner Kallweit , Andy Shevchenko , Jouni Hogander , Eric Dumazet , Greg Kroah-Hartman , Wang Hai , YueHaibing , Kimberly Brown , Thomas Gleixner , Florian Fainelli , Jiri Pirko , Andrew Lunn , Li RongQing , linux-kernel@vger.kernel.org (open list), netdev@vger.kernel.org (open list:NETWORKING [GENERAL]) Subject: [PATCH v3 2/2] net-sysfs: Ensure begin/complete are called in speed_show() and duplex_show() Date: Fri, 7 Feb 2020 18:10:04 +0800 Message-Id: <20200207101005.4454-2-kai.heng.feng@canonical.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200207101005.4454-1-kai.heng.feng@canonical.com> References: <20200207101005.4454-1-kai.heng.feng@canonical.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Device like igb gets runtime suspended when there's no link partner. We can't get correct speed under that state: $ cat /sys/class/net/enp3s0/speed 1000 In addition to that, an error can also be spotted in dmesg: [ 385.991957] igb 0000:03:00.0 enp3s0: PCIe link lost It's because the igb device doesn't get runtime resumed before calling get_link_ksettings(). So let's use a new helper to call begin() and complete() like what dev_ethtool() does, to runtime resume/suspend or power up/down the device properly. Once this fix is in place, igb can show the speed correctly without link partner: $ cat /sys/class/net/enp3s0/speed -1 -1 here means SPEED_UNKNOWN, which is the correct value when igb is runtime suspended. Signed-off-by: Kai-Heng Feng --- v3: - Specify -1 means SPEED_UNKNOWN. v2: - Add a new helper with begin/complete and use it in net-sysfs. include/linux/ethtool.h | 4 ++++ net/core/net-sysfs.c | 4 ++-- net/ethtool/ioctl.c | 33 ++++++++++++++++++++++++++++++++- 3 files changed, 38 insertions(+), 3 deletions(-) diff --git a/include/linux/ethtool.h b/include/linux/ethtool.h index 95991e4300bf..785ec1921417 100644 --- a/include/linux/ethtool.h +++ b/include/linux/ethtool.h @@ -160,6 +160,10 @@ extern int __ethtool_get_link_ksettings(struct net_device *dev, struct ethtool_link_ksettings *link_ksettings); +extern int +__ethtool_get_link_ksettings_full(struct net_device *dev, + struct ethtool_link_ksettings *link_ksettings); + /** * ethtool_intersect_link_masks - Given two link masks, AND them together * @dst: first mask and where result is stored diff --git a/net/core/net-sysfs.c b/net/core/net-sysfs.c index 4c826b8bf9b1..a199e15a080f 100644 --- a/net/core/net-sysfs.c +++ b/net/core/net-sysfs.c @@ -201,7 +201,7 @@ static ssize_t speed_show(struct device *dev, if (netif_running(netdev)) { struct ethtool_link_ksettings cmd; - if (!__ethtool_get_link_ksettings(netdev, &cmd)) + if (!__ethtool_get_link_ksettings_full(netdev, &cmd)) ret = sprintf(buf, fmt_dec, cmd.base.speed); } rtnl_unlock(); @@ -221,7 +221,7 @@ static ssize_t duplex_show(struct device *dev, if (netif_running(netdev)) { struct ethtool_link_ksettings cmd; - if (!__ethtool_get_link_ksettings(netdev, &cmd)) { + if (!__ethtool_get_link_ksettings_full(netdev, &cmd)) { const char *duplex; switch (cmd.base.duplex) { diff --git a/net/ethtool/ioctl.c b/net/ethtool/ioctl.c index b987052d91ef..faeba247c1fb 100644 --- a/net/ethtool/ioctl.c +++ b/net/ethtool/ioctl.c @@ -420,7 +420,9 @@ struct ethtool_link_usettings { } link_modes; }; -/* Internal kernel helper to query a device ethtool_link_settings. */ +/* Internal kernel helper to query a device ethtool_link_settings. To be called + * inside begin/complete block. + */ int __ethtool_get_link_ksettings(struct net_device *dev, struct ethtool_link_ksettings *link_ksettings) { @@ -434,6 +436,35 @@ int __ethtool_get_link_ksettings(struct net_device *dev, } EXPORT_SYMBOL(__ethtool_get_link_ksettings); +/* Internal kernel helper to query a device ethtool_link_settings. To be called + * outside of begin/complete block. + */ +int __ethtool_get_link_ksettings_full(struct net_device *dev, + struct ethtool_link_ksettings *link_ksettings) +{ + int rc; + + ASSERT_RTNL(); + + if (!dev->ethtool_ops->get_link_ksettings) + return -EOPNOTSUPP; + + if (dev->ethtool_ops->begin) { + rc = dev->ethtool_ops->begin(dev); + if (rc < 0) + return rc; + } + + memset(link_ksettings, 0, sizeof(*link_ksettings)); + rc = dev->ethtool_ops->get_link_ksettings(dev, link_ksettings); + + if (dev->ethtool_ops->complete) + dev->ethtool_ops->complete(dev); + + return rc; +} +EXPORT_SYMBOL(__ethtool_get_link_ksettings_full); + /* convert ethtool_link_usettings in user space to a kernel internal * ethtool_link_ksettings. return 0 on success, errno on error. */ -- 2.17.1