From: Florian Fainelli <florian.fainelli@broadcom.com>
To: netdev@vger.kernel.org
Cc: Florian Fainelli <florian.fainelli@broadcom.com>,
Doug Berger <opendmb@gmail.com>,
Broadcom internal kernel review list
<bcm-kernel-feedback-list@broadcom.com>,
"David S. Miller" <davem@davemloft.net>,
Eric Dumazet <edumazet@google.com>,
Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
Andrew Lunn <andrew@lunn.ch>,
Heiner Kallweit <hkallweit1@gmail.com>,
Russell King <linux@armlinux.org.uk>,
Vladimir Oltean <vladimir.oltean@nxp.com>,
Tariq Toukan <tariqt@nvidia.com>, Gal Pressman <gal@nvidia.com>,
Willem de Bruijn <willemb@google.com>,
Daniil Tatianin <d-tatianin@yandex-team.ru>,
Simon Horman <horms@kernel.org>,
Justin Chen <justin.chen@broadcom.com>,
Ratheesh Kannoth <rkannoth@marvell.com>,
Joe Damato <jdamato@fastly.com>,
Vincent Mailhol <mailhol.vincent@wanadoo.fr>,
Jiri Pirko <jiri@resnulli.us>,
linux-kernel@vger.kernel.org (open list)
Subject: [PATCH net-next v2 2/5] net: ethtool: Add validation for WAKE_FILTER
Date: Thu, 26 Oct 2023 15:45:06 -0700 [thread overview]
Message-ID: <20231026224509.112353-3-florian.fainelli@broadcom.com> (raw)
In-Reply-To: <20231026224509.112353-1-florian.fainelli@broadcom.com>
[-- Attachment #1: Type: text/plain, Size: 3176 bytes --]
A driver implementing WAKE_FILTER must first install at least one rule
with RX_CLS_FLOW_WAKE for WAKE_FILTER to be effective. Iterate over
RXNFC rules to validate that condition while trying to enable
WAKE_FILTER.
Signed-off-by: Florian Fainelli <florian.fainelli@broadcom.com>
---
net/ethtool/common.c | 42 ++++++++++++++++++++++++++++++++++++++++++
net/ethtool/common.h | 3 +++
net/ethtool/ioctl.c | 3 +++
net/ethtool/wol.c | 3 +++
4 files changed, 51 insertions(+)
diff --git a/net/ethtool/common.c b/net/ethtool/common.c
index 143dae872fb2..bab901b35731 100644
--- a/net/ethtool/common.c
+++ b/net/ethtool/common.c
@@ -742,3 +742,45 @@ ethtool_forced_speed_maps_init(struct ethtool_forced_speed_map *maps, u32 size)
}
}
EXPORT_SYMBOL_GPL(ethtool_forced_speed_maps_init);
+
+static int __ethtool_check_rxnfc_wake_filter(struct ethtool_rxnfc *rule_info,
+ void *priv)
+{
+ bool *verdict = priv;
+
+ if (rule_info->fs.ring_cookie == RX_CLS_FLOW_WAKE) {
+ *verdict = true;
+ return 1;
+ }
+
+ return 0;
+}
+
+/**
+ * ethtool_dev_check_wake_filter: Tests if a network device can use the
+ * WAKE_FILTER Wake-on-LAN option.
+ * @dev: network device to test
+ * @wol: %ethtool_wolinfo structure with Wake-on-LAN configuration
+ *
+ * Returns true if there is no support for %WAKE_FILTER, no support
+ * for RXNFC ethtool operations, or if there is at least one WAKE_FILTER
+ * installed.
+ */
+bool ethtool_dev_check_wake_filter(struct net_device *dev,
+ const struct ethtool_wolinfo *wol)
+{
+ bool verdict = false;
+ int ret;
+
+ if (!(wol->wolopts & WAKE_FILTER))
+ return true;
+
+ if (!dev->ethtool_ops->get_rxnfc ||
+ !dev->ethtool_ops->set_rxnfc)
+ return true;
+
+ ret = __ethtool_for_each_rxnfc(dev, __ethtool_check_rxnfc_wake_filter,
+ &verdict);
+
+ return ret < 0 ? false : verdict;
+}
diff --git a/net/ethtool/common.h b/net/ethtool/common.h
index 28b8aaaf9bcb..6cd3286d5038 100644
--- a/net/ethtool/common.h
+++ b/net/ethtool/common.h
@@ -56,4 +56,7 @@ int ethtool_get_module_eeprom_call(struct net_device *dev,
bool __ethtool_dev_mm_supported(struct net_device *dev);
+bool ethtool_dev_check_wake_filter(struct net_device *dev,
+ const struct ethtool_wolinfo *wol);
+
#endif /* _ETHTOOL_COMMON_H */
diff --git a/net/ethtool/ioctl.c b/net/ethtool/ioctl.c
index 0b0ce4f81c01..954446185158 100644
--- a/net/ethtool/ioctl.c
+++ b/net/ethtool/ioctl.c
@@ -1457,6 +1457,9 @@ static int ethtool_set_wol(struct net_device *dev, char __user *useraddr)
!memcmp(wol.sopass, cur_wol.sopass, sizeof(wol.sopass)))
return 0;
+ if (!ethtool_dev_check_wake_filter(dev, &wol))
+ return -EOPNOTSUPP;
+
ret = dev->ethtool_ops->set_wol(dev, &wol);
if (ret)
return ret;
diff --git a/net/ethtool/wol.c b/net/ethtool/wol.c
index 0ed56c9ac1bc..65fbe743a070 100644
--- a/net/ethtool/wol.c
+++ b/net/ethtool/wol.c
@@ -132,6 +132,9 @@ ethnl_set_wol(struct ethnl_req_info *req_info, struct genl_info *info)
tb[ETHTOOL_A_WOL_SOPASS], &mod);
}
+ if (!ethtool_dev_check_wake_filter(dev, &wol))
+ return -EOPNOTSUPP;
+
if (!mod)
return 0;
ret = dev->ethtool_ops->set_wol(dev, &wol);
--
2.34.1
[-- Attachment #2: S/MIME Cryptographic Signature --]
[-- Type: application/pkcs7-signature, Size: 4221 bytes --]
next prev parent reply other threads:[~2023-10-26 22:55 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-10-26 22:45 [PATCH net-next v2 0/5] WAKE_FILTER for Broadcom PHY (v2) Florian Fainelli
2023-10-26 22:45 ` [PATCH net-next v2 1/5] net: ethtool: Make RXNFC walking code accept a callback Florian Fainelli
2023-10-26 23:18 ` Jacob Keller
2023-10-26 22:45 ` Florian Fainelli [this message]
2023-10-26 23:19 ` [PATCH net-next v2 2/5] net: ethtool: Add validation for WAKE_FILTER Jacob Keller
2023-10-26 22:45 ` [PATCH net-next v2 3/5] net: phy: Add pluming for ethtool_{get,set}_rxnfc Florian Fainelli
2023-10-26 23:20 ` Jacob Keller
2023-10-26 23:32 ` Florian Fainelli
2023-10-27 2:53 ` Jakub Kicinski
2023-10-26 22:45 ` [PATCH net-next v2 4/5] net: phy: broadcom: Add support for WAKE_FILTER Florian Fainelli
2023-10-26 23:22 ` Jacob Keller
2023-10-26 22:45 ` [PATCH net-next v2 5/5] net: bcmgenet: Interrogate PHY for WAKE_FILTER programming Florian Fainelli
2023-10-26 23:23 ` Jacob Keller
2023-10-26 23:52 ` Florian Fainelli
[not found] ` <6456509b-9df7-47e3-b941-c307594a80d2@intel.com>
2023-10-27 17:15 ` Florian Fainelli
2023-10-27 17:36 ` Jacob Keller
2023-10-27 18:31 ` Andrew Lunn
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=20231026224509.112353-3-florian.fainelli@broadcom.com \
--to=florian.fainelli@broadcom.com \
--cc=andrew@lunn.ch \
--cc=bcm-kernel-feedback-list@broadcom.com \
--cc=d-tatianin@yandex-team.ru \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=gal@nvidia.com \
--cc=hkallweit1@gmail.com \
--cc=horms@kernel.org \
--cc=jdamato@fastly.com \
--cc=jiri@resnulli.us \
--cc=justin.chen@broadcom.com \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux@armlinux.org.uk \
--cc=mailhol.vincent@wanadoo.fr \
--cc=netdev@vger.kernel.org \
--cc=opendmb@gmail.com \
--cc=pabeni@redhat.com \
--cc=rkannoth@marvell.com \
--cc=tariqt@nvidia.com \
--cc=vladimir.oltean@nxp.com \
--cc=willemb@google.com \
/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
all inboxes | Powered by JetHome®