Received: by 2002:ac0:946b:0:0:0:0:0 with SMTP id j40csp2741032imj; Mon, 18 Feb 2019 11:17:17 -0800 (PST) X-Google-Smtp-Source: AHgI3IZG4qBgp5gy5sGq2xBo5pEMwdgr5iSOIPSPLqpyuMD7kGXyJOguA4OqF7Va6kbYq2W8FFCv X-Received: by 2002:a17:902:8a91:: with SMTP id p17mr26990356plo.316.1550517437146; Mon, 18 Feb 2019 11:17:17 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1550517437; cv=none; d=google.com; s=arc-20160816; b=p1vIMcIKu++OccZmEbgZoIwxAVjzgqPq0cuj2R5S/ci4x4dvlOIpmDFkyM6jOe7TXm PMiiG9H+FFvRoSswyrpJBgu2esKY++Oc0GTK2eLIt10pxLyRNNFJ18yvzFvuGAqMDc4u pt8aAhhagyuZsNM7EUlHIqi5oa98r29o+WMo2OZJwscsA0qTNr4XkK27Z/6laGdHtBxJ TPtNghxcY8sYXcgnl66rhlCEM8526TBf5LBqJD++IHgzDakQcTXfuQ49sTzHU6Ezvkw7 V1WVfdaYsQPOldVn8eIlgPhf1naniWQHmjvnNnjEIiWf1QRmAJJOp/1VwNTMNR1KYo3M 7VCg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:date:cc:to:subject:from:references :in-reply-to:message-id; bh=Hk0wCu5jBeyf620WpDn1d+Z8VsoSuXjGT1PdLNGODI4=; b=t/Xz/Eqz+5F/8OyqaC+nkx1DAOS2Y0j82MPp3LuM3xrPiWf9nOrgX3NEI6Cwtb/v/0 FXrmVf7RGS8q8A9DOwTGilquGRYtqqgQ6VV04hf1i87FtP3nqbXe15ty6oelOQoOXLAO 9CN8zyXPOTmlQymc543iYh1fsPR+KZJp1GjQ03zZdqKtTvl+CoZXqua0mwoVYncRzdoy /+3Djlfkdjal7XzOCkzZVnzRvTO86Tml66Y74fSZ3c2RUHqC5pBmkg9QdsnH80xbbiCY pMlH8X5Wd2HNZ8Wv+ROcXpKj0DOQKg9J+G6s4WbfmeWV3RlDCK5h5xzPyF6Lx3BEmCAV 0k/Q== 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 1si4355247pgu.300.2019.02.18.11.17.01; Mon, 18 Feb 2019 11:17:17 -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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2392490AbfBRSXB (ORCPT + 99 others); Mon, 18 Feb 2019 13:23:01 -0500 Received: from mx2.suse.de ([195.135.220.15]:47008 "EHLO mx1.suse.de" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S2391008AbfBRSW5 (ORCPT ); Mon, 18 Feb 2019 13:22:57 -0500 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id 5AE97AF7A; Mon, 18 Feb 2019 18:22:55 +0000 (UTC) Received: by unicorn.suse.cz (Postfix, from userid 1000) id 077A1E0122; Mon, 18 Feb 2019 19:22:55 +0100 (CET) Message-Id: <5d1c101f83f74008b68c5ae53ab2d9e2cc87db75.1550513384.git.mkubecek@suse.cz> In-Reply-To: References: From: Michal Kubecek Subject: [RFC PATCH net-next v3 18/21] ethtool: provide link state in GET_SETTINGS request To: netdev@vger.kernel.org Cc: David Miller , Andrew Lunn , Jakub Kicinski , Jiri Pirko , linux-kernel@vger.kernel.org Date: Mon, 18 Feb 2019 19:22:55 +0100 (CET) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Add information about device link state (as provided by ETHTOOL_GLINK ioctl command) into the GET_SETTINGS reply when ETH_SETTINGS_IM_LINK flag is set in the request. Note: we cannot use NLA_FLAG for link state as we need three states: off, on and unknown. Signed-off-by: Michal Kubecek --- Documentation/networking/ethtool-netlink.txt | 4 +++- include/uapi/linux/ethtool_netlink.h | 4 +++- net/ethtool/common.c | 8 ++++++++ net/ethtool/common.h | 1 + net/ethtool/ioctl.c | 8 ++++---- net/ethtool/settings.c | 11 +++++++++++ 6 files changed, 30 insertions(+), 6 deletions(-) diff --git a/Documentation/networking/ethtool-netlink.txt b/Documentation/networking/ethtool-netlink.txt index 057eb3213cfe..538dad93009f 100644 --- a/Documentation/networking/ethtool-netlink.txt +++ b/Documentation/networking/ethtool-netlink.txt @@ -285,6 +285,7 @@ Info mask bits meaning: ETH_SETTINGS_IM_LINKMODES link modes from link_ksettings ETH_SETTINGS_IM_WOLINFO struct ethtool_wolinfo ETH_SETTINGS_IM_MSGLEVEL msglevel + ETH_SETTINGS_IM_LINK link state Response contents: @@ -304,6 +305,7 @@ Response contents: ETHA_WOL_MODES (bitfield32) wake on LAN modes ETHA_WOL_SOPASS (binary) SecureOn(tm) password ETHA_SETTINGS_MSGLEVEL (bitfield32) debug level + ETHA_SETTINGS_LINK (u8) link state Most of the attributes and their values have the same meaning as matching members of the corresponding ioctl structures. For ETHA_SETTINGS_LINK_MODES, @@ -343,7 +345,7 @@ ETHTOOL_SWOL n/a ETHTOOL_GMSGLVL ETHNL_CMD_GET_SETTINGS ETHTOOL_SMSGLVL n/a ETHTOOL_NWAY_RST n/a -ETHTOOL_GLINK n/a +ETHTOOL_GLINK ETHNL_CMD_GET_SETTINGS ETHTOOL_GEEPROM n/a ETHTOOL_SEEPROM n/a ETHTOOL_GCOALESCE n/a diff --git a/include/uapi/linux/ethtool_netlink.h b/include/uapi/linux/ethtool_netlink.h index 360e20a73f19..06e78d94cacc 100644 --- a/include/uapi/linux/ethtool_netlink.h +++ b/include/uapi/linux/ethtool_netlink.h @@ -203,6 +203,7 @@ enum { ETHA_SETTINGS_PEER_MODES, /* bitset */ ETHA_SETTINGS_WOL, /* nested */ ETHA_SETTINGS_MSGLEVEL, /* bitfield32 */ + ETHA_SETTINGS_LINK, /* u8 */ __ETHA_SETTINGS_CNT, ETHA_SETTINGS_MAX = (__ETHA_SETTINGS_CNT - 1) @@ -212,8 +213,9 @@ enum { #define ETH_SETTINGS_IM_LINKMODES 0x02 #define ETH_SETTINGS_IM_WOLINFO 0x04 #define ETH_SETTINGS_IM_MSGLEVEL 0x08 +#define ETH_SETTINGS_IM_LINK 0x10 -#define ETH_SETTINGS_IM_ALL 0x0f +#define ETH_SETTINGS_IM_ALL 0x1f enum { ETHA_LINKINFO_UNSPEC, diff --git a/net/ethtool/common.c b/net/ethtool/common.c index 9fba57f554dd..a188f07bcb4c 100644 --- a/net/ethtool/common.c +++ b/net/ethtool/common.c @@ -217,3 +217,11 @@ int __ethtool_get_wol(struct net_device *dev, struct ethtool_wolinfo *wol) return 0; } + +int __ethtool_get_link(struct net_device *dev) +{ + if (!dev->ethtool_ops->get_link) + return -EOPNOTSUPP; + + return netif_running(dev) && dev->ethtool_ops->get_link(dev); +} diff --git a/net/ethtool/common.h b/net/ethtool/common.h index ed3f1ca54660..e5b5c5c2a4b9 100644 --- a/net/ethtool/common.h +++ b/net/ethtool/common.h @@ -18,6 +18,7 @@ phy_tunable_strings[__ETHTOOL_PHY_TUNABLE_COUNT][ETH_GSTRING_LEN]; int __ethtool_get_drvinfo(struct net_device *dev, struct ethtool_drvinfo *info); int __ethtool_get_ts_info(struct net_device *dev, struct ethtool_ts_info *info); int __ethtool_get_wol(struct net_device *dev, struct ethtool_wolinfo *wol); +int __ethtool_get_link(struct net_device *dev); bool convert_legacy_settings_to_link_ksettings( struct ethtool_link_ksettings *link_ksettings, diff --git a/net/ethtool/ioctl.c b/net/ethtool/ioctl.c index 945eaf551a4c..63662a3fa2ae 100644 --- a/net/ethtool/ioctl.c +++ b/net/ethtool/ioctl.c @@ -1306,12 +1306,12 @@ static int ethtool_nway_reset(struct net_device *dev) static int ethtool_get_link(struct net_device *dev, char __user *useraddr) { struct ethtool_value edata = { .cmd = ETHTOOL_GLINK }; + int link = __ethtool_get_link(dev); - if (!dev->ethtool_ops->get_link) - return -EOPNOTSUPP; - - edata.data = netif_running(dev) && dev->ethtool_ops->get_link(dev); + if (link < 0) + return link; + edata.data = link; if (copy_to_user(useraddr, &edata, sizeof(edata))) return -EFAULT; return 0; diff --git a/net/ethtool/settings.c b/net/ethtool/settings.c index 58cd2d19a75d..099300901c12 100644 --- a/net/ethtool/settings.c +++ b/net/ethtool/settings.c @@ -14,6 +14,7 @@ struct settings_data { struct ethtool_link_settings *lsettings; struct ethtool_wolinfo wolinfo; u32 msglevel; + int link; bool lpm_empty; }; @@ -27,6 +28,7 @@ static const struct nla_policy get_settings_policy[ETHA_SETTINGS_MAX + 1] = { [ETHA_SETTINGS_PEER_MODES] = { .type = NLA_REJECT }, [ETHA_SETTINGS_WOL] = { .type = NLA_REJECT }, [ETHA_SETTINGS_MSGLEVEL] = { .type = NLA_REJECT }, + [ETHA_SETTINGS_LINK] = { .type = NLA_REJECT }, }; static int parse_settings(struct common_req_info *req_info, @@ -99,6 +101,7 @@ static int prepare_settings(struct common_req_info *req_info, data->lsettings = &data->ksettings.base; data->lpm_empty = true; + data->link = -EOPNOTSUPP; ret = ethnl_before_ops(dev); if (ret < 0) @@ -131,6 +134,8 @@ static int prepare_settings(struct common_req_info *req_info, else req_mask &= ~ETH_SETTINGS_IM_MSGLEVEL; } + if (req_mask & ETH_SETTINGS_IM_LINK) + data->link = __ethtool_get_link(dev); ethnl_after_ops(dev); data->repdata_base.info_mask = req_mask; @@ -209,6 +214,8 @@ static int settings_size(const struct common_req_info *req_info) len += wol_size(); if (info_mask & ETH_SETTINGS_IM_MSGLEVEL) len += nla_total_size(sizeof(struct nla_bitfield32)); + if (info_mask & ETH_SETTINGS_IM_LINK) + len += nla_total_size(sizeof(u32)); return len; } @@ -324,6 +331,10 @@ static int fill_settings(struct sk_buff *skb, data->msglevel, NETIF_MSG_ALL)) return -EMSGSIZE; } + if (info_mask & ETH_SETTINGS_IM_LINK && data->link >= 0) { + if (nla_put_u8(skb, ETHA_SETTINGS_LINK, data->link)) + return -EMSGSIZE; + } return 0; } -- 2.20.1