Received: by 2002:ac0:bc90:0:0:0:0:0 with SMTP id a16csp3434312img; Mon, 25 Mar 2019 10:11:45 -0700 (PDT) X-Google-Smtp-Source: APXvYqxvYMhKv3533BS07b1DbSgYq8uqFb/Uh/PLl8l2CoI4V2uWqCX9CPLk+o1oUoyaj/EmSH6s X-Received: by 2002:a62:6e05:: with SMTP id j5mr25905072pfc.158.1553533905731; Mon, 25 Mar 2019 10:11:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1553533905; cv=none; d=google.com; s=arc-20160816; b=OFTwc79mXymQQMgOZsdRw7KaIQIUZ+Y2z6fgnHOGDs/ztmJmuCrRxwm9yayS1zfzIa xlzziFvOAPtIvIlIT521g0GG0B/sXWza80BJ46bcsyp1fjn3GhMEa8YyvgmwYnB6SVIU C6MXRmy6dY6UZUXfvrUCcXDoqZ+IX+N/BGQ0jYNAnqgLGrEgorKjXtHDuR0VYzXyS3Ob svIZwpWiJa4RqUWvO2KcQc7fF1H0mYqjUUdwnU4xQ/0E6uPT9Yt98HXQEQVxjQXBvyD6 866zHzVV06E8osVLoovV5LPXPIO+9atue7RES0oaNKcuX3Mr79VF5SUwkP4jl/HlnyiC q6JQ== 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=075jo29hapyPn8MtaRy5EO4Gu+UtDzpA2cF9PQ/cFnQ=; b=J+UV6jJYZTfNv0RBAPPW6X5MamL0iS/ymdHBKXEQAbhbR9+V4xzyigueE2gjw9Pc6U SwHtb8AUsOJBd8i3XPi+DtOh/v8kDr/LIz9fzPewUom74FMdJGURfow64DIowkWVz85m POBDEm+09vrse2PtNmIdj1nAMOQVm93I9ik0hWBrhr6wArhAgJGq2Ya+Zv1qWOHN61lc 3N80CMGiYJKNCSNF21W/To62p4Ld9iR21aSGI4l8zSlbVFhqaLPM8YQ+GWF/22lkE5xR 2pD6aSde+dVU7sZPmBcB65mroW+mzfFIAzOFK9KV2WyvGHVtzdSrW6ecJ/sYgL6XLXv7 j1lw== 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 u3si13794495pgi.275.2019.03.25.10.11.30; Mon, 25 Mar 2019 10:11:45 -0700 (PDT) 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 S1730527AbfCYRJJ (ORCPT + 99 others); Mon, 25 Mar 2019 13:09:09 -0400 Received: from mx2.suse.de ([195.135.220.15]:51496 "EHLO mx1.suse.de" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1730441AbfCYRJD (ORCPT ); Mon, 25 Mar 2019 13:09:03 -0400 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 776F5B023; Mon, 25 Mar 2019 17:09:01 +0000 (UTC) Received: by unicorn.suse.cz (Postfix, from userid 1000) id 23985E1404; Mon, 25 Mar 2019 18:09:01 +0100 (CET) Message-Id: <901fe605465ab8be78026ce2da21c45ea52ca3a3.1553532199.git.mkubecek@suse.cz> In-Reply-To: References: From: Michal Kubecek Subject: [PATCH net-next v5 22/22] ethtool: set message level with SET_SETTINGS request To: David Miller , netdev@vger.kernel.org Cc: Jakub Kicinski , Jiri Pirko , Andrew Lunn , Florian Fainelli , John Linville , Stephen Hemminger , linux-kernel@vger.kernel.org Date: Mon, 25 Mar 2019 18:09:01 +0100 (CET) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Allow setting device message level using ETHA_SETTINGS_DEBUG nested attribute. Unlike in ioctl interface "message level" is called "message mask" (as it is in fact used as a bit mask) and put inside a nested attribute to allow future extensions. Signed-off-by: Michal Kubecek --- Documentation/networking/ethtool-netlink.txt | 8 +++- net/ethtool/settings.c | 45 +++++++++++++++++++- 2 files changed, 50 insertions(+), 3 deletions(-) diff --git a/Documentation/networking/ethtool-netlink.txt b/Documentation/networking/ethtool-netlink.txt index 603acfbefe29..20e43d42afdd 100644 --- a/Documentation/networking/ethtool-netlink.txt +++ b/Documentation/networking/ethtool-netlink.txt @@ -345,6 +345,8 @@ to be passed with SET_SETTINGS request: ETHA_SETTINGS_WOL (nested) wake on LAN settings ETHA_WOL_MODES (bitfield32) wake on LAN modes ETHA_WOL_SOPASS (binary) SecureOn(tm) password + ETHA_SETTINGS_DEBUG (nested) debugging + ETHA_DEBUG_MSG_MASK (bitfield32) message mask ETHA_LINKMODES_OURS bit set allows setting advertised link modes. If autonegotiation is on (either set now or kept from before), advertised modes @@ -360,7 +362,9 @@ selector are set to 0 or 1 according to value. To allow the semantics of the ioctl interface where the whole bitmap is set rather than only modified, selectors may have also bits not supported by device set and an error is only issued if any of them is also set in the value (i.e. if userspace tries to -enable mode not supported by device). +enable mode not supported by device). ETHA_SETTINGS_MSGLEVEL bitfield also +allows bits not recognized by kernel in selector as long as the request does +not attempt to enable them. Request translation @@ -379,7 +383,7 @@ ETHTOOL_GREGS n/a ETHTOOL_GWOL ETHNL_CMD_GET_SETTINGS ETHTOOL_SWOL ETHNL_CMD_SET_SETTINGS ETHTOOL_GMSGLVL ETHNL_CMD_GET_SETTINGS -ETHTOOL_SMSGLVL n/a +ETHTOOL_SMSGLVL ETHNL_CMD_SET_SETTINGS ETHTOOL_NWAY_RST n/a ETHTOOL_GLINK ETHNL_CMD_GET_SETTINGS ETHTOOL_GEEPROM n/a diff --git a/net/ethtool/settings.c b/net/ethtool/settings.c index 53409dd8af34..bc7ca03aa205 100644 --- a/net/ethtool/settings.c +++ b/net/ethtool/settings.c @@ -538,6 +538,12 @@ static const struct nla_policy set_wol_policy[ETHA_LINKINFO_MAX + 1] = { .len = SOPASS_MAX }, }; +static const struct nla_policy set_debug_policy[ETHA_DEBUG_MAX + 1] = { + [ETHA_DEBUG_UNSPEC] = { .type = NLA_REJECT }, + [ETHA_DEBUG_MSG_MASK] = { .type = NLA_BITFIELD32, + .validation_data = &all_bits }, +}; + static const struct nla_policy set_settings_policy[ETHA_SETTINGS_MAX + 1] = { [ETHA_SETTINGS_UNSPEC] = { .type = NLA_REJECT }, [ETHA_SETTINGS_DEV] = { .type = NLA_NESTED }, @@ -547,7 +553,7 @@ static const struct nla_policy set_settings_policy[ETHA_SETTINGS_MAX + 1] = { [ETHA_SETTINGS_LINK_MODES] = { .type = NLA_NESTED }, [ETHA_SETTINGS_LINK_STATE] = { .type = NLA_REJECT }, [ETHA_SETTINGS_WOL] = { .type = NLA_NESTED }, - [ETHA_SETTINGS_DEBUG] = { .type = NLA_REJECT }, + [ETHA_SETTINGS_DEBUG] = { .type = NLA_NESTED }, }; static int ethnl_set_link_ksettings(struct genl_info *info, @@ -732,6 +738,36 @@ static int update_wol(struct genl_info *info, struct nlattr *nest, return ret; } +static int update_debug(struct genl_info *info, struct nlattr *nest, + struct net_device *dev) +{ + struct nlattr *tb[ETHA_DEBUG_MAX + 1]; + u32 msglevel; + int ret; + + if (!nest) + return 0; + ret = nla_parse_nested_strict(tb, ETHA_DEBUG_MAX, nest, + set_debug_policy, info->extack); + if (ret < 0) + return ret; + + if (!dev->ethtool_ops->get_msglevel || + !dev->ethtool_ops->set_msglevel) { + ETHNL_SET_ERRMSG(info, + "device does not provide msglvl access"); + return -EOPNOTSUPP; + } + ret = 0; + msglevel = dev->ethtool_ops->get_msglevel(dev); + if (ethnl_update_bitfield32(&msglevel, tb[ETHA_DEBUG_MSG_MASK])) { + dev->ethtool_ops->set_msglevel(dev, msglevel); + ret = 1; + } + + return ret; +} + int ethnl_set_settings(struct sk_buff *skb, struct genl_info *info) { struct nlattr *tb[ETHA_SETTINGS_MAX + 1]; @@ -766,6 +802,13 @@ int ethnl_set_settings(struct sk_buff *skb, struct genl_info *info) if (ret) req_mask |= ETH_SETTINGS_IM_WOL; } + if (tb[ETHA_SETTINGS_DEBUG]) { + ret = update_debug(info, tb[ETHA_SETTINGS_DEBUG], dev); + if (ret < 0) + goto out_ops; + if (ret) + req_mask |= ETH_SETTINGS_IM_DEBUG; + } ret = 0; out_ops: -- 2.21.0