From: Michal Kubecek <mkubecek@suse.cz>
To: David Miller <davem@davemloft.net>, netdev@vger.kernel.org
Cc: Jakub Kicinski <jakub.kicinski@netronome.com>,
Jiri Pirko <jiri@resnulli.us>, Andrew Lunn <andrew@lunn.ch>,
Florian Fainelli <f.fainelli@gmail.com>,
John Linville <linville@tuxdriver.com>,
Stephen Hemminger <stephen@networkplumber.org>,
linux-kernel@vger.kernel.org
Subject: [PATCH net-next v5 20/22] ethtool: set WoL settings with SET_SETTINGS request
Date: Mon, 25 Mar 2019 18:08:55 +0100 (CET) [thread overview]
Message-ID: <19b3da19441d0c8884c2cd07cb31acf83de89163.1553532199.git.mkubecek@suse.cz> (raw)
In-Reply-To: <cover.1553532199.git.mkubecek@suse.cz>
Allow enabling and disabling wake on LAN modes using SET_SETTINGS
request.
ETHA_SETTINGS_WOL nested attribute is used to set or modify enabled WoL
modes and SecureOn(tm) password.
Signed-off-by: Michal Kubecek <mkubecek@suse.cz>
---
Documentation/networking/ethtool-netlink.txt | 12 +++-
net/ethtool/settings.c | 60 +++++++++++++++++++-
2 files changed, 70 insertions(+), 2 deletions(-)
diff --git a/Documentation/networking/ethtool-netlink.txt b/Documentation/networking/ethtool-netlink.txt
index bc7f28f0182f..3568d35ad7ec 100644
--- a/Documentation/networking/ethtool-netlink.txt
+++ b/Documentation/networking/ethtool-netlink.txt
@@ -335,6 +335,9 @@ to be passed with SET_SETTINGS request:
ETHA_LINKMODES_OURS (bitset) advertised link modes
ETHA_LINKMODES_SPEED (u32) link speed (Mb/s)
ETHA_LINKMODES_DUPLEX (u8) duplex mode
+ ETHA_SETTINGS_WOL (nested) wake on LAN settings
+ ETHA_WOL_MODES (bitfield32) wake on LAN modes
+ ETHA_WOL_SOPASS (binary) SecureOn(tm) password
ETHA_LINKMODES_OURS bit set allows setting advertised link modes. If
autonegotiation is on (either set now or kept from before), advertised modes
@@ -345,6 +348,13 @@ autoselection is done on ethtool side with ioctl interface, netlink interface
is supposed to allow requesting changes without knowing what exactly kernel
supports.
+ETHA_WOL_MODES bitfield is interpreted in the usual way, i.e. bits set in the
+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).
+
Request translation
-------------------
@@ -360,7 +370,7 @@ ETHTOOL_SSET ETHNL_CMD_SET_SETTINGS
ETHTOOL_GDRVINFO ETHNL_CMD_GET_INFO
ETHTOOL_GREGS n/a
ETHTOOL_GWOL ETHNL_CMD_GET_SETTINGS
-ETHTOOL_SWOL n/a
+ETHTOOL_SWOL ETHNL_CMD_SET_SETTINGS
ETHTOOL_GMSGLVL n/a
ETHTOOL_SMSGLVL n/a
ETHTOOL_NWAY_RST n/a
diff --git a/net/ethtool/settings.c b/net/ethtool/settings.c
index 56a045e5e916..ea5279dad826 100644
--- a/net/ethtool/settings.c
+++ b/net/ethtool/settings.c
@@ -108,6 +108,12 @@ static const struct link_mode_info link_mode_params[] = {
__DEFINE_LINK_MODE_PARAMS(200000, CR4, Full),
};
+/* We want to allow ~0 as selector for backward compatibility (to just set
+ * given set of modes, whatever kernel supports) so that we allow all bits
+ * on validation and do our own sanity check later.
+ */
+static u32 all_bits = ~(u32)0;
+
static const struct nla_policy get_settings_policy[ETHA_SETTINGS_MAX + 1] = {
[ETHA_SETTINGS_UNSPEC] = { .type = NLA_REJECT },
[ETHA_SETTINGS_DEV] = { .type = NLA_NESTED },
@@ -485,6 +491,14 @@ static const struct nla_policy set_linkmodes_policy[ETHA_LINKMODES_MAX + 1] = {
[ETHA_LINKMODES_DUPLEX] = { .type = NLA_U8 },
};
+static const struct nla_policy set_wol_policy[ETHA_LINKINFO_MAX + 1] = {
+ [ETHA_WOL_UNSPEC] = { .type = NLA_REJECT },
+ [ETHA_WOL_MODES] = { .type = NLA_BITFIELD32,
+ .validation_data = &all_bits },
+ [ETHA_WOL_SOPASS] = { .type = NLA_BINARY,
+ .len = SOPASS_MAX },
+};
+
static const struct nla_policy set_settings_policy[ETHA_SETTINGS_MAX + 1] = {
[ETHA_SETTINGS_UNSPEC] = { .type = NLA_REJECT },
[ETHA_SETTINGS_DEV] = { .type = NLA_NESTED },
@@ -493,7 +507,7 @@ static const struct nla_policy set_settings_policy[ETHA_SETTINGS_MAX + 1] = {
[ETHA_SETTINGS_LINK_INFO] = { .type = NLA_NESTED },
[ETHA_SETTINGS_LINK_MODES] = { .type = NLA_NESTED },
[ETHA_SETTINGS_LINK_STATE] = { .type = NLA_REJECT },
- [ETHA_SETTINGS_WOL] = { .type = NLA_REJECT },
+ [ETHA_SETTINGS_WOL] = { .type = NLA_NESTED },
};
static int ethnl_set_link_ksettings(struct genl_info *info,
@@ -641,6 +655,43 @@ static int ethnl_update_ksettings(struct genl_info *info, struct nlattr **tb,
return 0;
}
+static int update_wol(struct genl_info *info, struct nlattr *nest,
+ struct net_device *dev)
+{
+ struct nlattr *tb[ETHA_WOL_MAX + 1];
+ struct ethtool_wolinfo wolinfo = {};
+ int ret;
+
+ if (!nest)
+ return 0;
+ ret = nla_parse_nested_strict(tb, ETHA_WOL_MAX, nest, set_wol_policy,
+ info->extack);
+ if (ret < 0)
+ return ret;
+
+ ret = ethnl_get_wol(info, dev, &wolinfo);
+ if (ret < 0) {
+ ETHNL_SET_ERRMSG(info, "failed to get wol settings");
+ return ret;
+ }
+
+ ret = 0;
+ if (ethnl_update_bitfield32(&wolinfo.wolopts, tb[ETHA_WOL_MODES]))
+ ret = 1;
+ if (ethnl_update_binary(wolinfo.sopass, SOPASS_MAX,
+ tb[ETHA_WOL_SOPASS]))
+ ret = 1;
+ if (ret) {
+ int ret2 = dev->ethtool_ops->set_wol(dev, &wolinfo);
+ if (ret2 < 0) {
+ ETHNL_SET_ERRMSG(info, "wol info update failed");
+ ret = ret2;
+ }
+ }
+
+ return ret;
+}
+
int ethnl_set_settings(struct sk_buff *skb, struct genl_info *info)
{
struct nlattr *tb[ETHA_SETTINGS_MAX + 1];
@@ -668,6 +719,13 @@ int ethnl_set_settings(struct sk_buff *skb, struct genl_info *info)
if (ret < 0)
goto out_ops;
}
+ if (tb[ETHA_SETTINGS_WOL]) {
+ ret = update_wol(info, tb[ETHA_SETTINGS_WOL], dev);
+ if (ret < 0)
+ goto out_ops;
+ if (ret)
+ req_mask |= ETH_SETTINGS_IM_WOL;
+ }
ret = 0;
out_ops:
--
2.21.0
next prev parent reply other threads:[~2019-03-25 17:09 UTC|newest]
Thread overview: 109+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-03-25 17:07 [PATCH net-next v5 00/22] ethtool netlink interface, part 1 Michal Kubecek
2019-03-25 17:07 ` [PATCH net-next v5 01/22] rtnetlink: provide permanent hardware address in RTM_NEWLINK Michal Kubecek
2019-03-26 10:08 ` Jiri Pirko
2019-03-26 10:31 ` Michal Kubecek
2019-03-26 11:38 ` Jiri Pirko
2019-03-26 19:46 ` David Miller
2019-03-25 17:08 ` [PATCH net-next v5 02/22] netlink: introduce nla_put_bitfield32() Michal Kubecek
2019-03-26 10:09 ` Jiri Pirko
2019-03-28 1:56 ` Florian Fainelli
2019-03-25 17:08 ` [PATCH net-next v5 03/22] netlink: add strict version of nla_parse_nested() Michal Kubecek
2019-03-26 10:11 ` Jiri Pirko
2019-03-28 1:57 ` Florian Fainelli
2019-03-25 17:08 ` [PATCH net-next v5 04/22] ethtool: move to its own directory Michal Kubecek
2019-03-26 10:14 ` Jiri Pirko
2019-03-28 1:57 ` Florian Fainelli
2019-03-25 17:08 ` [PATCH net-next v5 05/22] ethtool: introduce ethtool netlink interface Michal Kubecek
2019-03-26 12:09 ` Jiri Pirko
2019-03-26 13:24 ` Michal Kubecek
2019-03-26 13:42 ` Jiri Pirko
2019-03-27 9:26 ` Michal Kubecek
2019-03-27 9:50 ` Jiri Pirko
2019-03-28 2:05 ` Florian Fainelli
2019-03-28 8:10 ` Jiri Pirko
2019-03-28 9:37 ` Michal Kubecek
2019-03-28 13:23 ` Jiri Pirko
2019-03-28 17:00 ` Florian Fainelli
2019-03-28 17:28 ` Jiri Pirko
2019-03-26 16:36 ` Jiri Pirko
2019-03-26 17:32 ` Michal Kubecek
2019-03-27 9:26 ` Jiri Pirko
2019-03-25 17:08 ` [PATCH net-next v5 06/22] ethtool: helper functions for " Michal Kubecek
2019-03-26 12:38 ` Jiri Pirko
2019-03-26 14:19 ` Michal Kubecek
2019-03-26 16:22 ` Jiri Pirko
2019-03-25 17:08 ` [PATCH net-next v5 07/22] ethtool: netlink bitset handling Michal Kubecek
2019-03-26 15:59 ` Jiri Pirko
2019-03-26 17:59 ` Michal Kubecek
2019-03-27 9:57 ` Jiri Pirko
2019-03-27 10:19 ` Michal Kubecek
2019-03-25 17:08 ` [PATCH net-next v5 08/22] ethtool: support for netlink notifications Michal Kubecek
2019-03-26 16:34 ` Jiri Pirko
2019-03-26 18:17 ` Michal Kubecek
2019-03-27 9:38 ` Jiri Pirko
2019-03-27 9:51 ` Andrew Lunn
2019-03-27 10:04 ` Jiri Pirko
2019-03-27 10:16 ` Andrew Lunn
2019-03-27 10:41 ` Jiri Pirko
2019-03-27 9:59 ` Michal Kubecek
2019-03-27 10:43 ` Jiri Pirko
2019-03-25 17:08 ` [PATCH net-next v5 09/22] ethtool: implement EVENT notifications Michal Kubecek
2019-03-27 13:04 ` Jiri Pirko
2019-03-27 14:14 ` Michal Kubecek
2019-03-28 2:14 ` Florian Fainelli
2019-03-28 6:41 ` Michal Kubecek
2019-03-28 9:16 ` Jiri Pirko
2019-03-25 17:08 ` [PATCH net-next v5 10/22] ethtool: generic handlers for GET requests Michal Kubecek
2019-03-27 16:35 ` Jiri Pirko
2019-03-27 21:53 ` Michal Kubecek
2019-03-28 13:32 ` Jiri Pirko
2019-03-25 17:08 ` [PATCH net-next v5 11/22] ethtool: move string arrays into common file Michal Kubecek
2019-03-28 2:17 ` Florian Fainelli
2019-03-25 17:08 ` [PATCH net-next v5 12/22] ethtool: provide string sets with GET_STRSET request Michal Kubecek
2019-03-27 20:12 ` Jiri Pirko
2019-03-27 22:56 ` Michal Kubecek
2019-03-29 8:43 ` Jiri Pirko
2019-03-28 2:25 ` Florian Fainelli
2019-03-28 7:18 ` Michal Kubecek
2019-03-28 13:43 ` Jiri Pirko
2019-03-28 14:04 ` Michal Kubecek
2019-03-28 17:35 ` Jiri Pirko
2019-03-28 18:52 ` Jakub Kicinski
2019-03-28 20:43 ` Michal Kubecek
2019-03-28 21:06 ` Jakub Kicinski
2019-03-29 6:52 ` Jiri Pirko
2019-03-28 22:28 ` Michal Kubecek
2019-03-25 17:08 ` [PATCH net-next v5 13/22] ethtool: provide driver/device information in GET_INFO request Michal Kubecek
2019-03-27 20:14 ` Jiri Pirko
2019-03-27 22:25 ` Michal Kubecek
2019-03-28 2:30 ` Florian Fainelli
2019-03-28 9:21 ` Jiri Pirko
2019-03-28 9:53 ` Michal Kubecek
2019-03-28 16:34 ` Jiri Pirko
2019-03-28 20:09 ` Jakub Kicinski
2019-03-28 22:46 ` Michal Kubecek
2019-03-29 18:48 ` Jakub Kicinski
2019-03-29 18:53 ` Florian Fainelli
2019-03-25 17:08 ` [PATCH net-next v5 14/22] ethtool: provide timestamping " Michal Kubecek
2019-03-28 3:36 ` Florian Fainelli
2019-03-28 10:03 ` Michal Kubecek
2019-03-25 17:08 ` [PATCH net-next v5 15/22] ethtool: provide link mode names as a string set Michal Kubecek
2019-03-28 3:52 ` Florian Fainelli
2019-03-25 17:08 ` [PATCH net-next v5 16/22] ethtool: provide link settings and link modes in GET_SETTINGS request Michal Kubecek
2019-03-28 3:44 ` Florian Fainelli
2019-03-28 10:04 ` Michal Kubecek
2019-03-25 17:08 ` [PATCH net-next v5 17/22] ethtool: set link settings and link modes with SET_SETTINGS request Michal Kubecek
2019-03-25 17:08 ` [PATCH net-next v5 18/22] ethtool: provide link state in GET_SETTINGS request Michal Kubecek
2019-03-25 17:08 ` [PATCH net-next v5 19/22] ethtool: provide WoL information " Michal Kubecek
2019-03-28 3:42 ` Florian Fainelli
2019-03-28 10:10 ` Michal Kubecek
2019-03-25 17:08 ` Michal Kubecek [this message]
2019-03-28 3:49 ` [PATCH net-next v5 20/22] ethtool: set WoL settings with SET_SETTINGS request Florian Fainelli
2019-03-25 17:08 ` [PATCH net-next v5 21/22] ethtool: provide message level in GET_SETTINGS request Michal Kubecek
2019-03-28 3:46 ` Florian Fainelli
2019-03-25 17:09 ` [PATCH net-next v5 22/22] ethtool: set message level with SET_SETTINGS request Michal Kubecek
2019-03-28 3:48 ` Florian Fainelli
2019-03-27 13:09 ` [PATCH net-next v5 00/22] ethtool netlink interface, part 1 Jiri Pirko
2019-03-27 14:28 ` Michal Kubecek
2019-03-27 15:19 ` Jiri Pirko
2019-03-27 19:12 ` David Miller
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=19b3da19441d0c8884c2cd07cb31acf83de89163.1553532199.git.mkubecek@suse.cz \
--to=mkubecek@suse.cz \
--cc=andrew@lunn.ch \
--cc=davem@davemloft.net \
--cc=f.fainelli@gmail.com \
--cc=jakub.kicinski@netronome.com \
--cc=jiri@resnulli.us \
--cc=linux-kernel@vger.kernel.org \
--cc=linville@tuxdriver.com \
--cc=netdev@vger.kernel.org \
--cc=stephen@networkplumber.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).