[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20231011221242.4180589-2-florian.fainelli@broadcom.com>
Date: Wed, 11 Oct 2023 15:12:39 -0700
From: Florian Fainelli <florian.fainelli@...adcom.com>
To: netdev@...r.kernel.org
Cc: Florian Fainelli <florian.fainelli@...adcom.com>,
"David S. Miller" <davem@...emloft.net>,
Eric Dumazet <edumazet@...gle.com>,
Jakub Kicinski <kuba@...nel.org>,
Paolo Abeni <pabeni@...hat.com>,
Jonathan Corbet <corbet@....net>,
Broadcom internal kernel review list <bcm-kernel-feedback-list@...adcom.com>,
Andrew Lunn <andrew@...n.ch>,
Heiner Kallweit <hkallweit1@...il.com>,
Russell King <linux@...linux.org.uk>,
opendmb@...il.com,
justin.chen@...adcom.com,
Michal Kubecek <mkubecek@...e.cz>
Subject: [PATCH net-next 1/2] ethtool: Introduce WAKE_MDA
Allow Ethernet PHY and MAC drivers with simplified matching logic to be
waking-up on a custom MAC destination address. This is particularly
useful for Ethernet PHYs which have limited amounts of buffering but can
still wake-up on a custom MAC destination address.
When WAKE_MDA is specified, the "sopass" field in the existing struct
ethtool_wolinfo is re-purposed to hold a custom MAC destination address
to match against.
Example:
ethtool -s eth0 wol e mac-da 01:00:5e:00:00:fb
Signed-off-by: Florian Fainelli <florian.fainelli@...adcom.com>
---
Documentation/networking/ethtool-netlink.rst | 7 ++++++-
include/uapi/linux/ethtool.h | 10 ++++++++--
include/uapi/linux/ethtool_netlink.h | 1 +
net/ethtool/common.c | 1 +
net/ethtool/netlink.h | 2 +-
net/ethtool/wol.c | 21 ++++++++++++++++++++
6 files changed, 38 insertions(+), 4 deletions(-)
diff --git a/Documentation/networking/ethtool-netlink.rst b/Documentation/networking/ethtool-netlink.rst
index 2540c70952ff..b2b1191d5cec 100644
--- a/Documentation/networking/ethtool-netlink.rst
+++ b/Documentation/networking/ethtool-netlink.rst
@@ -708,11 +708,13 @@ Kernel response contents:
``ETHTOOL_A_WOL_HEADER`` nested reply header
``ETHTOOL_A_WOL_MODES`` bitset mask of enabled WoL modes
``ETHTOOL_A_WOL_SOPASS`` binary SecureOn(tm) password
+ ``ETHTOOL_A_WOL_MAC_DA`` binary Destination matching MAC address
==================================== ====== ==========================
In reply, ``ETHTOOL_A_WOL_MODES`` mask consists of modes supported by the
device, value of modes which are enabled. ``ETHTOOL_A_WOL_SOPASS`` is only
-included in reply if ``WAKE_MAGICSECURE`` mode is supported.
+included in reply if ``WAKE_MAGICSECURE`` mode is supported. ``ETHTOOL_A_WOL_MAC_DA``
+is only included in reply if ``WAKE_MDA`` mode is supported.
WOL_SET
@@ -726,10 +728,13 @@ Request contents:
``ETHTOOL_A_WOL_HEADER`` nested request header
``ETHTOOL_A_WOL_MODES`` bitset enabled WoL modes
``ETHTOOL_A_WOL_SOPASS`` binary SecureOn(tm) password
+ ``ETHTOOL_A_WOL_MAC_DA`` binary Destination matching MAC address
==================================== ====== ==========================
``ETHTOOL_A_WOL_SOPASS`` is only allowed for devices supporting
``WAKE_MAGICSECURE`` mode.
+``ETHTOOL_A_WOL_MAC_DA`` is only allowed for devices supporting
+``WAKE_MDA`` mode.
FEATURES_GET
diff --git a/include/uapi/linux/ethtool.h b/include/uapi/linux/ethtool.h
index f7fba0dc87e5..8134ac8870bd 100644
--- a/include/uapi/linux/ethtool.h
+++ b/include/uapi/linux/ethtool.h
@@ -207,12 +207,17 @@ struct ethtool_drvinfo {
* @wolopts: Bitmask of %WAKE_* flags for enabled Wake-On-Lan modes.
* @sopass: SecureOn(tm) password; meaningful only if %WAKE_MAGICSECURE
* is set in @wolopts.
+ * @mac_da: Destination MAC address to match; meaningful only if
+ * %WAKE_MDA is set in @wolopts.
*/
struct ethtool_wolinfo {
__u32 cmd;
__u32 supported;
__u32 wolopts;
- __u8 sopass[SOPASS_MAX];
+ union {
+ __u8 sopass[SOPASS_MAX];
+ __u8 mac_da[ETH_ALEN];
+ };
};
/* for passing single values */
@@ -1989,8 +1994,9 @@ static inline int ethtool_validate_duplex(__u8 duplex)
#define WAKE_MAGIC (1 << 5)
#define WAKE_MAGICSECURE (1 << 6) /* only meaningful if WAKE_MAGIC */
#define WAKE_FILTER (1 << 7)
+#define WAKE_MDA (1 << 8)
-#define WOL_MODE_COUNT 8
+#define WOL_MODE_COUNT 9
/* L2-L4 network traffic flow types */
#define TCP_V4_FLOW 0x01 /* hash or spec (tcp_ip4_spec) */
diff --git a/include/uapi/linux/ethtool_netlink.h b/include/uapi/linux/ethtool_netlink.h
index 73e2c10dc2cc..237a0fc68997 100644
--- a/include/uapi/linux/ethtool_netlink.h
+++ b/include/uapi/linux/ethtool_netlink.h
@@ -300,6 +300,7 @@ enum {
ETHTOOL_A_WOL_HEADER, /* nest - _A_HEADER_* */
ETHTOOL_A_WOL_MODES, /* bitset */
ETHTOOL_A_WOL_SOPASS, /* binary */
+ ETHTOOL_A_WOL_MAC_DA, /* binary */
/* add new constants above here */
__ETHTOOL_A_WOL_CNT,
diff --git a/net/ethtool/common.c b/net/ethtool/common.c
index f5598c5f50de..d1c837f6094c 100644
--- a/net/ethtool/common.c
+++ b/net/ethtool/common.c
@@ -405,6 +405,7 @@ const char wol_mode_names[][ETH_GSTRING_LEN] = {
[const_ilog2(WAKE_MAGIC)] = "magic",
[const_ilog2(WAKE_MAGICSECURE)] = "magicsecure",
[const_ilog2(WAKE_FILTER)] = "filter",
+ [const_ilog2(WAKE_MDA)] = "mac-da",
};
static_assert(ARRAY_SIZE(wol_mode_names) == WOL_MODE_COUNT);
diff --git a/net/ethtool/netlink.h b/net/ethtool/netlink.h
index 9a333a8d04c1..5958e4483ced 100644
--- a/net/ethtool/netlink.h
+++ b/net/ethtool/netlink.h
@@ -407,7 +407,7 @@ extern const struct nla_policy ethnl_linkstate_get_policy[ETHTOOL_A_LINKSTATE_HE
extern const struct nla_policy ethnl_debug_get_policy[ETHTOOL_A_DEBUG_HEADER + 1];
extern const struct nla_policy ethnl_debug_set_policy[ETHTOOL_A_DEBUG_MSGMASK + 1];
extern const struct nla_policy ethnl_wol_get_policy[ETHTOOL_A_WOL_HEADER + 1];
-extern const struct nla_policy ethnl_wol_set_policy[ETHTOOL_A_WOL_SOPASS + 1];
+extern const struct nla_policy ethnl_wol_set_policy[ETHTOOL_A_WOL_MAC_DA + 1];
extern const struct nla_policy ethnl_features_get_policy[ETHTOOL_A_FEATURES_HEADER + 1];
extern const struct nla_policy ethnl_features_set_policy[ETHTOOL_A_FEATURES_WANTED + 1];
extern const struct nla_policy ethnl_privflags_get_policy[ETHTOOL_A_PRIVFLAGS_HEADER + 1];
diff --git a/net/ethtool/wol.c b/net/ethtool/wol.c
index 0ed56c9ac1bc..13dfcc9bb1e5 100644
--- a/net/ethtool/wol.c
+++ b/net/ethtool/wol.c
@@ -12,6 +12,7 @@ struct wol_reply_data {
struct ethnl_reply_data base;
struct ethtool_wolinfo wol;
bool show_sopass;
+ bool show_mac_da;
};
#define WOL_REPDATA(__reply_base) \
@@ -41,6 +42,8 @@ static int wol_prepare_data(const struct ethnl_req_info *req_base,
/* do not include password in notifications */
data->show_sopass = !genl_info_is_ntf(info) &&
(data->wol.supported & WAKE_MAGICSECURE);
+ data->show_mac_da = !genl_info_is_ntf(info) &&
+ (data->wol.supported & WAKE_MDA);
return 0;
}
@@ -58,6 +61,8 @@ static int wol_reply_size(const struct ethnl_req_info *req_base,
return len;
if (data->show_sopass)
len += nla_total_size(sizeof(data->wol.sopass));
+ if (data->show_mac_da)
+ len += nla_total_size(sizeof(data->wol.mac_da));
return len;
}
@@ -79,6 +84,10 @@ static int wol_fill_reply(struct sk_buff *skb,
nla_put(skb, ETHTOOL_A_WOL_SOPASS, sizeof(data->wol.sopass),
data->wol.sopass))
return -EMSGSIZE;
+ if (data->show_mac_da &&
+ nla_put(skb, ETHTOOL_A_WOL_MAC_DA, sizeof(data->wol.mac_da),
+ data->wol.mac_da))
+ return -EMSGSIZE;
return 0;
}
@@ -91,6 +100,8 @@ const struct nla_policy ethnl_wol_set_policy[] = {
[ETHTOOL_A_WOL_MODES] = { .type = NLA_NESTED },
[ETHTOOL_A_WOL_SOPASS] = { .type = NLA_BINARY,
.len = SOPASS_MAX },
+ [ETHTOOL_A_WOL_MAC_DA] = { .type = NLA_BINARY,
+ .len = ETH_ALEN }
};
static int
@@ -131,6 +142,16 @@ ethnl_set_wol(struct ethnl_req_info *req_info, struct genl_info *info)
ethnl_update_binary(wol.sopass, sizeof(wol.sopass),
tb[ETHTOOL_A_WOL_SOPASS], &mod);
}
+ if (tb[ETHTOOL_A_WOL_MAC_DA]) {
+ if (!(wol.supported & WAKE_MDA)) {
+ NL_SET_ERR_MSG_ATTR(info->extack,
+ tb[ETHTOOL_A_WOL_MAC_DA],
+ "mac-da not supported, cannot set MAC");
+ return -EINVAL;
+ }
+ ethnl_update_binary(wol.mac_da, sizeof(wol.mac_da),
+ tb[ETHTOOL_A_WOL_MAC_DA], &mod);
+ }
if (!mod)
return 0;
--
2.34.1
Download attachment "smime.p7s" of type "application/pkcs7-signature" (4221 bytes)
Powered by blists - more mailing lists