netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH net-next] ethtool: add tunable api to disable various firmware offloads
@ 2024-08-13 22:33 Maciej Żenczykowski
  2024-08-15  0:32 ` Jakub Kicinski
  2024-08-15 16:13 ` Nelson, Shannon
  0 siblings, 2 replies; 10+ messages in thread
From: Maciej Żenczykowski @ 2024-08-13 22:33 UTC (permalink / raw)
  To: Maciej Żenczykowski
  Cc: Linux Network Development Mailing List, David S . Miller,
	Eric Dumazet, Jakub Kicinski, Paolo Abeni,
	Maciej Żenczykowski, Kory Maincent (Dent Project),
	Ahmed Zaki, Edward Cree, Yuyang Huang, Lorenzo Colitti

In order to save power (battery), most network hardware
designed for low power environments (ie. battery powered
devices) supports varying types of hardware/firmware offload
(filtering and/or generating replies) of incoming packets.

The goal being to prevent device wakeups caused by ingress 'spam'.

This is particularly true for wifi (especially phones/tablets),
but isn't actually wifi specific.  It can also be implemented
in wired nics (TV) or usb ethernet dongles.

For examples TVs require this to keep power consumption
under (the EU mandated) 2 Watts while idle (display off),
while still being discoverable on the network.

This may include things like: ARP/IPv6 ND, IGMP/MLD, ping, mdns,
but various other possibilities are also possible,
for example:
  ethertype filtering (discarding non-IP ethertypes),
  nat-t keepalive (discarding ingress, automating periodic egress),
  tcp keepalive (generation/processing/filtering),
  tethering (forwarding) offload

In many ways, in its goals, it is somewhat similar to the
relatively standard destination mac filtering most wired nics
have supported for ages: reduce the amount of traffic the host
must handle.

While working on Android we've discovered that there is
no device/driver agnostic way to disable these offloads.

This patch is an attempt to rectify this.

It does not add an API to configure these offloads, as usually
this isn't needed as the driver will just fetch the required
configuration information straight from the kernel.

What it does do is add a simple API to allow disabling (masking)
them, either for debugging or for test purposes.

Cc: "Kory Maincent (Dent Project)" <kory.maincent@bootlin.com>
Cc: Ahmed Zaki <ahmed.zaki@intel.com>
Cc: Edward Cree <ecree.xilinx@gmail.com>
Cc: "David S. Miller" <davem@davemloft.net>
Cc: Eric Dumazet <edumazet@google.com>
Cc: Jakub Kicinski <kuba@kernel.org>
Cc: Paolo Abeni <pabeni@redhat.com>
Cc: Yuyang Huang <yuyanghuang@google.com>
Cc: Lorenzo Colitti <lorenzo@google.com>
Signed-off-by: Maciej Żenczykowski <maze@google.com>
---
 include/uapi/linux/ethtool.h | 15 +++++++++++++++
 net/ethtool/common.c         |  1 +
 net/ethtool/ioctl.c          |  5 +++++
 3 files changed, 21 insertions(+)

diff --git a/include/uapi/linux/ethtool.h b/include/uapi/linux/ethtool.h
index 4a0a6e703483..7b58860c3731 100644
--- a/include/uapi/linux/ethtool.h
+++ b/include/uapi/linux/ethtool.h
@@ -224,12 +224,27 @@ struct ethtool_value {
 #define PFC_STORM_PREVENTION_AUTO	0xffff
 #define PFC_STORM_PREVENTION_DISABLE	0
 
+/* For power/wakeup (*not* performance) related offloads */
+enum tunable_fw_offload_disable {
+	ETHTOOL_TUNABLE_FW_OFFLOAD_DISABLE_ALL,
+	ETHTOOL_TUNABLE_FW_OFFLOAD_DISABLE_IPV4_ARP,
+	ETHTOOL_TUNABLE_FW_OFFLOAD_DISABLE_IPV6_ND,
+	ETHTOOL_TUNABLE_FW_OFFLOAD_DISABLE_IPV4_PING,
+	ETHTOOL_TUNABLE_FW_OFFLOAD_DISABLE_IPV6_PING,
+	ETHTOOL_TUNABLE_FW_OFFLOAD_DISABLE_IPV4_IGMP,
+	ETHTOOL_TUNABLE_FW_OFFLOAD_DISABLE_IPV6_MLD,
+	ETHTOOL_TUNABLE_FW_OFFLOAD_DISABLE_IPV4_MDNS,
+	ETHTOOL_TUNABLE_FW_OFFLOAD_DISABLE_IPV6_MDNS,
+	/* 55 bits remaining for future use */
+};
+
 enum tunable_id {
 	ETHTOOL_ID_UNSPEC,
 	ETHTOOL_RX_COPYBREAK,
 	ETHTOOL_TX_COPYBREAK,
 	ETHTOOL_PFC_PREVENTION_TOUT, /* timeout in msecs */
 	ETHTOOL_TX_COPYBREAK_BUF_SIZE,
+	ETHTOOL_FW_OFFLOAD_DISABLE, /* u64 bits numbered from LSB per tunable_fw_offload_disable */
 	/*
 	 * Add your fresh new tunable attribute above and remember to update
 	 * tunable_strings[] in net/ethtool/common.c
diff --git a/net/ethtool/common.c b/net/ethtool/common.c
index 7257ae272296..8dc0c084fce5 100644
--- a/net/ethtool/common.c
+++ b/net/ethtool/common.c
@@ -91,6 +91,7 @@ tunable_strings[__ETHTOOL_TUNABLE_COUNT][ETH_GSTRING_LEN] = {
 	[ETHTOOL_TX_COPYBREAK]	= "tx-copybreak",
 	[ETHTOOL_PFC_PREVENTION_TOUT] = "pfc-prevention-tout",
 	[ETHTOOL_TX_COPYBREAK_BUF_SIZE] = "tx-copybreak-buf-size",
+	[ETHTOOL_FW_OFFLOAD_DISABLE] = "fw-offload-disable",
 };
 
 const char
diff --git a/net/ethtool/ioctl.c b/net/ethtool/ioctl.c
index 18cf9fa32ae3..31318ded17a7 100644
--- a/net/ethtool/ioctl.c
+++ b/net/ethtool/ioctl.c
@@ -2733,6 +2733,11 @@ static int ethtool_get_module_eeprom(struct net_device *dev,
 static int ethtool_tunable_valid(const struct ethtool_tunable *tuna)
 {
 	switch (tuna->id) {
+	case ETHTOOL_FW_OFFLOAD_DISABLE:
+		if (tuna->len != sizeof(u64) ||
+		    tuna->type_id != ETHTOOL_TUNABLE_U64)
+			return -EINVAL;
+		break;
 	case ETHTOOL_RX_COPYBREAK:
 	case ETHTOOL_TX_COPYBREAK:
 	case ETHTOOL_TX_COPYBREAK_BUF_SIZE:
-- 
2.46.0.76.ge559c4bf1a-goog


^ permalink raw reply related	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2024-08-16 17:51 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-08-13 22:33 [PATCH net-next] ethtool: add tunable api to disable various firmware offloads Maciej Żenczykowski
2024-08-15  0:32 ` Jakub Kicinski
2024-08-15  3:08   ` Florian Fainelli
2024-08-15 15:45     ` Jakub Kicinski
2024-08-15 16:38       ` Florian Fainelli
2024-08-16  0:49   ` Maciej Żenczykowski
2024-08-16 17:51     ` Jakub Kicinski
2024-08-15 16:13 ` Nelson, Shannon
2024-08-16  0:55   ` Maciej Żenczykowski
2024-08-16  1:03     ` Nelson, Shannon

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).