Skip to contentSkip to conversation

ethtool netlink interface, part 1

RFC PATCH Superseded Michal Kubecek 5 participants 47 messages Feb 18, 2019 – Feb 21, 2019

Subsystems (5)

v3 of 9 Superseded Latest is v9 →

lore
Share & tools
lore
#0 lore raw

v3 cover ethtool netlink interface, part 1

Note: this is marked as RFC because it's rather late in the cycle; the plan is to make a regular submission (with changes based on review) once net-next reopens after the 5.1 merge window. The full (work in progress) series, together with the (userspace) ethtool counterpart can be found at
https://github.com/mkubecek/ethnl

This is first part of alternative userspace interface for ethtool. The aim is to address some long known issues with the ioctl interface, mainly lack of extensibility, raciness, limited error reporting and absence of notifications.

The interface uses generic netlink family "ethtool"; it provides multicast group "monitor" which is used for notifications. Documentation for the interface is in Documentation/networking/ethtool-netlink.txt

Basic concepts:

- the goal is to provide all features of ioctl interface but allow easier future extensions; at some point, it should be possible to have full ethtool functionality without using the ioctl interface
- inextensibility of ioctl interface resulted in way too many commands, many of them obsoleted by newer ones; reduce the number by ignoring the obsolete commands and grouping some together
- for "set" type commands, allows passing only the attributes to be changed; therefore we don't need a get-modify-set cycle (which is inherently racy), userspace can simply say what it wants to change
- provide notifications to multicast group "monitor" like rtnetlink does, i.e. in the form of messages close to replies to "get" requests
- allow dump requests to get some information about all network devices providing it
- be less dependent on ethtool and kernel being in sync; allow e.g. saying "ethtool -s eth0 advertise foo off" without ethtool knowing what "foo" means; it's kernel's job to know what mode "xyz" is and if it exists and is supported

Main changes between RFC v2 and RFC v3:

- do not allow building as a module (no netdev notifiers needed)
- drop some obsolete fields
- add permanent hw address, timestamping and private flags support
- rework bitset handling to get rid of variable length arrays
- notify monitor on device renames
- restructure GET_SETTINGS/SET_SETTINGS messages
- split too long patches and submit only first part of the series

Main changes between RFC v1 and RFC v2:

- support dumps for all "get" requests
- provide notifications for changes related to supported request types
- support getting string sets (both global and per device)
- support getting/setting device features
- get rid of family specific header, everything passed as attributes
- split netlink code into multiple files in net/ethtool/ directory

ToDo / open questions:

- some features provided by ethtool would rather belong to devlink (and some are already superseded by devlink); however, only few drivers provide devlink interface at the moment and as recent discussion on flashing revealed, we cannot rely on devlink's presence

- while the netlink interface allows easy future extensions, ethtool_ops interface does not; some settings could be implemented using tunables and accessed via relevant netlink messages (as well as tunables) from userspace but in the long term, something better will be needed

- currently, all communication with drivers via ethtool_ops is done under RTNL as this is what ioctl interface does and likely many ethtool_ops handlers rely on that; if we are going to rework ethtool_ops in the future ("phase two"), it would be nice to get rid of it

- ethtool_ops should pass extack pointer to allow drivers more meaningful error reporting; it's not clear, however, how to pass information about offending attribute

- notifications are sent whenever a change is done via netlink API or ioctl API and for netdev features also whenever they are updated using netdev_change_features(); it would be desirable to notify also about link state and negotiation result (speed/duplex and partner link modes) but it would be more tricky

Michal Kubecek (21):
netlink: introduce nla_put_bitfield32()
ethtool: move to its own directory
ethtool: introduce ethtool netlink interface
ethtool: helper functions for netlink interface
ethtool: netlink bitset handling
ethtool: support for netlink notifications
ethtool: implement EVENT notifications
ethtool: generic handlers for GET requests
ethtool: move string arrays into common file
ethtool: provide string sets with GET_STRSET request
ethtool: provide driver/device information in GET_INFO request
ethtool: provide permanent hardware address in GET_INFO request
ethtool: provide timestamping information in GET_INFO request
ethtool: provide link mode names as a string set
ethtool: provide link settings and link modes in GET_SETTINGS request
ethtool: provide WoL information in GET_SETTINGS request
ethtool: provide message level in GET_SETTINGS request
ethtool: provide link state in GET_SETTINGS request
ethtool: provide device features in GET_SETTINGS request
ethtool: provide private flags in GET_SETTINGS request
ethtool: send netlink notifications about setting changes

 Documentation/networking/ethtool-netlink.txt | 441 +++++++++++++
 include/linux/ethtool_netlink.h              |  17 +
 include/linux/netdevice.h                    |  14 +
 include/net/netlink.h                        |  15 +
 include/uapi/linux/ethtool.h                 |  10 +
 include/uapi/linux/ethtool_netlink.h         | 265 ++++++++
 include/uapi/linux/net_tstamp.h              |  13 +
 net/Kconfig                                  |   8 +
 net/Makefile                                 |   2 +-
 net/core/Makefile                            |   2 +-
 net/ethtool/Makefile                         |   7 +
 net/ethtool/bitset.c                         | 572 +++++++++++++++++
 net/ethtool/bitset.h                         |  40 ++
 net/ethtool/common.c                         | 227 +++++++
 net/ethtool/common.h                         |  29 +
 net/ethtool/info.c                           | 332 ++++++++++
 net/{core/ethtool.c => ethtool/ioctl.c}      | 244 ++-----
 net/ethtool/netlink.c                        | 634 +++++++++++++++++++
 net/ethtool/netlink.h                        | 252 ++++++++
 net/ethtool/settings.c                       | 559 ++++++++++++++++
 net/ethtool/strset.c                         | 461 ++++++++++++++
 21 files changed, 3937 insertions(+), 207 deletions(-)
 create mode 100644 Documentation/networking/ethtool-netlink.txt
 create mode 100644 include/linux/ethtool_netlink.h
 create mode 100644 include/uapi/linux/ethtool_netlink.h
 create mode 100644 net/ethtool/Makefile
 create mode 100644 net/ethtool/bitset.c
 create mode 100644 net/ethtool/bitset.h
 create mode 100644 net/ethtool/common.c
 create mode 100644 net/ethtool/common.h
 create mode 100644 net/ethtool/info.c
 rename net/{core/ethtool.c => ethtool/ioctl.c} (91%)
 create mode 100644 net/ethtool/netlink.c
 create mode 100644 net/ethtool/netlink.h
 create mode 100644 net/ethtool/settings.c
 create mode 100644 net/ethtool/strset.c
Signature · 1 line
2.20.1
#1 lore raw

RFC PATCH v3 1/21 netlink: introduce nla_put_bitfield32()

Similar to other data types, this helper puts NLA_BITFIELD32 attribute into a netlink message. It takes separate value and selector arguments, if there is a struct nla_bitfield32 already, one can use nla_put().

---
 include/net/netlink.h | 15 +++++++++++++++
 1 file changed, 15 insertions(+)
include/net/netlink.h +15 -0
index 23f27b0b3cef..bc0497076bec 100644
@@ -1211,6 +1211,21 @@ static inline int nla_put_in6_addr(struct sk_buff *skb, int attrtype,
 	return nla_put(skb, attrtype, sizeof(*addr), addr);
 }
 
+/**
+ * nla_put_bitfield32 - Add a bitfield32 value/selector attribute to
+ * a socket buffer
+ * @skb: socket buffer to add attribute to
+ * @value: 32-bit value bitmap
+ * @selector: 32-bit selector bitmap
+ */
+static inline int nla_put_bitfield32(struct sk_buff *skb, int attrtype,
+				     u32 value, u32 selector)
+{
+	struct nla_bitfield32 tmp = { .value = value, .selector = selector };
+
+	return nla_put(skb, attrtype, sizeof(tmp), &tmp);
+}
+
 /**
  * nla_get_u32 - return payload of u32 attribute
  * @nla: u32 netlink attribute
Signature · 1 line
2.20.1
#2 lore raw

RFC PATCH v3 2/21 ethtool: move to its own directory

In reply to Michal Kubecek

The ethtool netlink interface is going to be split into multiple files so that it will be more convenient to put all of them in a separate directory net/ethtool. Start by moving current ethtool.c with ioctl interface into this directory and renaming it to ioct.c.

---
 net/Makefile                            | 2 +-
 net/core/Makefile                       | 2 +-
 net/ethtool/Makefile                    | 3 +++
 net/{core/ethtool.c => ethtool/ioctl.c} | 0
 4 files changed, 5 insertions(+), 2 deletions(-)
 create mode 100644 net/ethtool/Makefile
 rename net/{core/ethtool.c => ethtool/ioctl.c} (100%)
net/Makefile +1 -1
index bdaf53925acd..6c68520e5eb9 100644
@@ -13,7 +13,7 @@ obj-$(CONFIG_NET)		+= $(tmp-y)
 
 # LLC has to be linked before the files in net/802/
 obj-$(CONFIG_LLC)		+= llc/
-obj-$(CONFIG_NET)		+= ethernet/ 802/ sched/ netlink/ bpf/
+obj-$(CONFIG_NET)		+= ethernet/ 802/ sched/ netlink/ bpf/ ethtool/
 obj-$(CONFIG_NETFILTER)		+= netfilter/
 obj-$(CONFIG_INET)		+= ipv4/
 obj-$(CONFIG_TLS)		+= tls/
net/core/Makefile +1 -1
index f97d6254e564..9ddc2f3ecd97 100644
@@ -8,7 +8,7 @@ obj-y := sock.o request_sock.o skbuff.o datagram.o stream.o scm.o \
 
 obj-$(CONFIG_SYSCTL) += sysctl_net_core.o
 
-obj-y		     += dev.o ethtool.o dev_addr_lists.o dst.o netevent.o \
+obj-y		     += dev.o dev_addr_lists.o dst.o netevent.o \
 			neighbour.o rtnetlink.o utils.o link_watch.o filter.o \
 			sock_diag.o dev_ioctl.o tso.o sock_reuseport.o \
 			fib_notifier.o xdp.o flow_offload.o
net/ethtool/Makefile new file +3 -0
new file mode 100644
index 000000000000..3ebfab2bca66
@@ -0,0 +1,3 @@
+# SPDX-License-Identifier: GPL-2.0
+
+obj-y		+= ioctl.o
net/ethtool/ioctl.c renamed from net/core/ethtool.c +0 -0
similarity index 100%
rename from net/core/ethtool.c
rename to net/ethtool/ioctl.c
Signature · 1 line
2.20.1
#3 lore raw

Re: [RFC PATCH net-next v3 02/21] ethtool: move to its own directory

Quoted 4 lines · Michal Kubecek

The ethtool netlink interface is going to be split into multiple files so that it will be more convenient to put all of them in a separate directory net/ethtool. Start by moving current ethtool.c with ioctl interface into this directory and renaming it to ioct.c.

nit: s/ioct.c/ioctl.c/

#4 lore raw

RFC PATCH v3 3/21 ethtool: introduce ethtool netlink interface

In reply to Michal Kubecek

Basic genetlink and init infrastructure for the netlink interface, register genetlink family "ethtool". Introduce CONFIG_ETHTOOL_NETLINK Kconfig option. Add interface description into Documentation/networking.

---
 Documentation/networking/ethtool-netlink.txt | 167 +++++++++++++++++++
 include/linux/ethtool_netlink.h              |   9 +
 include/uapi/linux/ethtool_netlink.h         |  19 +++
 net/Kconfig                                  |   8 +
 net/ethtool/Makefile                         |   6 +-
 net/ethtool/netlink.c                        |  34 ++++
 net/ethtool/netlink.h                        |  12 ++
 7 files changed, 254 insertions(+), 1 deletion(-)
 create mode 100644 Documentation/networking/ethtool-netlink.txt
 create mode 100644 include/linux/ethtool_netlink.h
 create mode 100644 include/uapi/linux/ethtool_netlink.h
 create mode 100644 net/ethtool/netlink.c
 create mode 100644 net/ethtool/netlink.h
Documentation/networking/ethtool-netlink.txt new file +167 -0
new file mode 100644
index 000000000000..09c36e0392a8
@@ -0,0 +1,167 @@
+                        Netlink interface for ethtool
+                        =============================
+
+
+Basic information
+-----------------
+
+Netlink interface for ethtool uses generic netlink family "ethtool" (userspace
+application should use macros ETHTOOL_GENL_NAME and ETHTOOL_GENL_VERSION
+defined in <linux/ethtool_netlink.h> uapi header). This family does not use
+a specific header, all information in requests and replies is passed using
+netlink attributes.
+
+In requests, device can be identified by ifindex or by name; if both are used,
+they must match. In replies, kernel fills both. The meaning of flags,
+info_mask and index fields depends on request type.
+
+The ethtool netlink interface uses extended ACK for error and warning
+reporting, userspace application developers are encouraged to make these
+messages available to user in a suitable way.
+
+Requests can be divided into three categories: "get" (retrieving information),
+"set" (setting parameters) and "action" (invoking an action).
+
+All "set" and "action" type requests require admin privileges (CAP_NET_ADMIN
+in the namespace). Most "get" type request are allowed for anyone but there
+are exceptions (where the response contains sensitive information). In some
+cases, the request as such is allowed for anyone but unprivileged users have
+attributes with sensitive information (e.g. wake-on-lan password) omitted.
+
+
+Conventions
+-----------
+
+Attributes which represent a boolean value usually use u8 type so that we can
+distinguish three states: "on", "off" and "not present" (meaning the
+information is not available in "get" requests or value is not to be changed
+in "set" requests). For these attributes, the "true" value should be passed as
+number 1 but any non-zero value should be understood as "true" by recipient.
+
+Some request types allow passing an attribute named ETHA_*_INFOMASK with
+a bitmask telling kernel that we are only interested in some parts of the
+information. If info mask is omitted, all available information is returned.
+Meaning of info mask bits depends on request type and is listed below.
+
+
+Device identification
+---------------------
+
+When appropriate, network device is identified by a nested attribute named
+ETHA_*_DEV. This attribute can contain
+
+    ETHA_DEV_INDEX	(u32)		device ifindex
+    ETHA_DEV_NAME	(string)	device name
+
+In device related requests, one of these is sufficient; if both are used, they
+must match (i.e. identify the same device). In device related replies both are
+provided by kernel. In dump requests, device is not specified and kernel
+replies with one message per network device (only those for which the request
+is supported).
+
+List of message types
+---------------------
+
+All constants use ETHNL_CMD_ prefix, usually followed by "GET", "SET" or "ACT"
+to indicate the type.
+
+Messages of type "get" are used by userspace to request information and
+usually do not contain any attributes (that may be added later for dump
+filtering). Kernel response is in the form of corresponding "set" message;
+the same message can be also used to set (some of) the parameters, except for
+messages marked as "response only" in the table above. "Get" messages with
+NLM_F_DUMP flags and no device identification dump the information for all
+devices supporting the request.
+
+Later sections describe the format and semantics of these request messages.
+
+
+Request translation
+-------------------
+
+The following table maps iosctl commands to netlink commands providing their
+functionality. Entries with "n/a" in right column are commands which do not
+have their netlink replacement yet.
+
+ioctl command			netlink command
+---------------------------------------------------------------------
+ETHTOOL_GSET			n/a
+ETHTOOL_SSET			n/a
+ETHTOOL_GDRVINFO		n/a
+ETHTOOL_GREGS			n/a
+ETHTOOL_GWOL			n/a
+ETHTOOL_SWOL			n/a
+ETHTOOL_GMSGLVL			n/a
+ETHTOOL_SMSGLVL			n/a
+ETHTOOL_NWAY_RST		n/a
+ETHTOOL_GLINK			n/a
+ETHTOOL_GEEPROM			n/a
+ETHTOOL_SEEPROM			n/a
+ETHTOOL_GCOALESCE		n/a
+ETHTOOL_SCOALESCE		n/a
+ETHTOOL_GRINGPARAM		n/a
+ETHTOOL_SRINGPARAM		n/a
+ETHTOOL_GPAUSEPARAM		n/a
+ETHTOOL_SPAUSEPARAM		n/a
+ETHTOOL_GRXCSUM			n/a
+ETHTOOL_SRXCSUM			n/a
+ETHTOOL_GTXCSUM			n/a
+ETHTOOL_STXCSUM			n/a
+ETHTOOL_GSG			n/a
+ETHTOOL_SSG			n/a
+ETHTOOL_TEST			n/a
+ETHTOOL_GSTRINGS		n/a
+ETHTOOL_PHYS_ID			n/a
+ETHTOOL_GSTATS			n/a
+ETHTOOL_GTSO			n/a
+ETHTOOL_STSO			n/a
+ETHTOOL_GPERMADDR		n/a
+ETHTOOL_GUFO			n/a
+ETHTOOL_SUFO			n/a
+ETHTOOL_GGSO			n/a
+ETHTOOL_SGSO			n/a
+ETHTOOL_GFLAGS			n/a
+ETHTOOL_SFLAGS			n/a
+ETHTOOL_GPFLAGS			n/a
+ETHTOOL_SPFLAGS			n/a
+ETHTOOL_GRXFH			n/a
+ETHTOOL_SRXFH			n/a
+ETHTOOL_GGRO			n/a
+ETHTOOL_SGRO			n/a
+ETHTOOL_GRXRINGS		n/a
+ETHTOOL_GRXCLSRLCNT		n/a
+ETHTOOL_GRXCLSRULE		n/a
+ETHTOOL_GRXCLSRLALL		n/a
+ETHTOOL_SRXCLSRLDEL		n/a
+ETHTOOL_SRXCLSRLINS		n/a
+ETHTOOL_FLASHDEV		n/a
+ETHTOOL_RESET			n/a
+ETHTOOL_SRXNTUPLE		n/a
+ETHTOOL_GRXNTUPLE		n/a
+ETHTOOL_GSSET_INFO		n/a
+ETHTOOL_GRXFHINDIR		n/a
+ETHTOOL_SRXFHINDIR		n/a
+ETHTOOL_GFEATURES		n/a
+ETHTOOL_SFEATURES		n/a
+ETHTOOL_GCHANNELS		n/a
+ETHTOOL_SCHANNELS		n/a
+ETHTOOL_SET_DUMP		n/a
+ETHTOOL_GET_DUMP_FLAG		n/a
+ETHTOOL_GET_DUMP_DATA		n/a
+ETHTOOL_GET_TS_INFO		n/a
+ETHTOOL_GMODULEINFO		n/a
+ETHTOOL_GMODULEEEPROM		n/a
+ETHTOOL_GEEE			n/a
+ETHTOOL_SEEE			n/a
+ETHTOOL_GRSSH			n/a
+ETHTOOL_SRSSH			n/a
+ETHTOOL_GTUNABLE		n/a
+ETHTOOL_STUNABLE		n/a
+ETHTOOL_GPHYSTATS		n/a
+ETHTOOL_PERQUEUE		n/a
+ETHTOOL_GLINKSETTINGS		n/a
+ETHTOOL_SLINKSETTINGS		n/a
+ETHTOOL_PHY_GTUNABLE		n/a
+ETHTOOL_PHY_STUNABLE		n/a
+ETHTOOL_GFECPARAM		n/a
+ETHTOOL_SFECPARAM		n/a
include/linux/ethtool_netlink.h new file +9 -0
new file mode 100644
index 000000000000..0412adb4f42f
@@ -0,0 +1,9 @@
+/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
+
+#ifndef _LINUX_ETHTOOL_NETLINK_H_
+#define _LINUX_ETHTOOL_NETLINK_H_
+
+#include <uapi/linux/ethtool_netlink.h>
+#include <linux/ethtool.h>
+
+#endif /* _LINUX_ETHTOOL_NETLINK_H_ */
include/uapi/linux/ethtool_netlink.h new file +19 -0
new file mode 100644
index 000000000000..d8a8d3c72c2f
@@ -0,0 +1,19 @@
+/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
+
+#ifndef _UAPI_LINUX_ETHTOOL_NETLINK_H_
+#define _UAPI_LINUX_ETHTOOL_NETLINK_H_
+
+#include <linux/ethtool.h>
+
+enum {
+	ETHNL_CMD_NOOP,
+
+	__ETHNL_CMD_CNT,
+	ETHNL_CMD_MAX = (__ETHNL_CMD_CNT - 1)
+};
+
+/* generic netlink info */
+#define ETHTOOL_GENL_NAME "ethtool"
+#define ETHTOOL_GENL_VERSION 1
+
+#endif /* _UAPI_LINUX_ETHTOOL_NETLINK_H_ */
net/Kconfig +8 -0
index 62da6148e9f8..383fe04ddf07 100644
@@ -460,6 +460,14 @@ config FAILOVER
 	  migration of VMs with direct attached VFs by failing over to the
 	  paravirtual datapath when the VF is unplugged.
 
+config ETHTOOL_NETLINK
+	bool "Netlink interface for ethtool"
+	default y
+	help
+	  An alternative userspace interface for ethtool based on generic
+	  netlink. It provides better extensibility and some new features,
+	  e.g. notification messages.
+
 endif   # if NET
 
 # Used by archs to tell that they support BPF JIT compiler plus which flavour.
net/ethtool/Makefile +5 -1
index 3ebfab2bca66..f30e0da88be5 100644
@@ -1,3 +1,7 @@
 # SPDX-License-Identifier: GPL-2.0
 
-obj-y		+= ioctl.o
+obj-y				+= ioctl.o
+
+obj-$(CONFIG_ETHTOOL_NETLINK)	+= ethtool_nl.o
+
+ethtool_nl-y	:= netlink.o
net/ethtool/netlink.c new file +34 -0
new file mode 100644
index 000000000000..5fe3e5b68e81
@@ -0,0 +1,34 @@
+// SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note
+
+#include <linux/ethtool_netlink.h>
+#include "netlink.h"
+
+/* genetlink setup */
+
+static const struct genl_ops ethtool_genl_ops[] = {
+};
+
+struct genl_family ethtool_genl_family = {
+	.hdrsize	= 0,
+	.name		= ETHTOOL_GENL_NAME,
+	.version	= ETHTOOL_GENL_VERSION,
+	.netnsok	= true,
+	.parallel_ops	= true,
+	.ops		= ethtool_genl_ops,
+	.n_ops		= ARRAY_SIZE(ethtool_genl_ops),
+};
+
+/* module setup */
+
+static int __init ethnl_init(void)
+{
+	int ret;
+
+	ret = genl_register_family(&ethtool_genl_family);
+	if (ret < 0)
+		panic("ethtool: could not register genetlink family\n");
+
+	return 0;
+}
+
+subsys_initcall(ethnl_init);
net/ethtool/netlink.h new file +12 -0
new file mode 100644
index 000000000000..63063b582ca2
@@ -0,0 +1,12 @@
+/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
+
+#ifndef _NET_ETHTOOL_NETLINK_H
+#define _NET_ETHTOOL_NETLINK_H
+
+#include <linux/ethtool_netlink.h>
+#include <linux/netdevice.h>
+#include <net/genetlink.h>
+
+extern struct genl_family ethtool_genl_family;
+
+#endif /* _NET_ETHTOOL_NETLINK_H */
Signature · 1 line
2.20.1
#5 lore raw

RFC PATCH v3 4/21 ethtool: helper functions for netlink interface

In reply to Michal Kubecek

Various helpers used by ethtool netlink code.

---
 include/uapi/linux/ethtool_netlink.h |  11 +++
 net/ethtool/netlink.c                | 119 +++++++++++++++++++++++
 net/ethtool/netlink.h                | 135 +++++++++++++++++++++++++++
 3 files changed, 265 insertions(+)
include/uapi/linux/ethtool_netlink.h +11 -0
index d8a8d3c72c2f..01896a1ee21a 100644
@@ -12,6 +12,17 @@ enum {
 	ETHNL_CMD_MAX = (__ETHNL_CMD_CNT - 1)
 };
 
+/* device specification */
+
+enum {
+	ETHA_DEV_UNSPEC,
+	ETHA_DEV_INDEX,				/* u32 */
+	ETHA_DEV_NAME,				/* string */
+
+	__ETHA_DEV_CNT,
+	ETHA_DEV_MAX = (__ETHA_DEV_CNT - 1)
+};
+
 /* generic netlink info */
 #define ETHTOOL_GENL_NAME "ethtool"
 #define ETHTOOL_GENL_VERSION 1
net/ethtool/netlink.c +119 -0

127 lines not on this page · raw message

net/ethtool/netlink.h +135 -0

142 lines not on this page · raw message

Signature · 1 line
2.20.1
#6 lore raw

Re: [RFC PATCH net-next v3 04/21] ethtool: helper functions for netlink interface

Quoted 8 lines · Michal Kubecek

+/* create skb for a reply and fill device identification
+ * payload: payload length (without netlink and genetlink header)

+ * dev:     device the reply is about (may be null)
+ * cmd:     ETHNL_CMD_* command for reply
+ * info:    info for the received packet we respond to
+ * ehdrp:   place to store payload pointer returned by genlmsg_new()

+ * returns: skb or null on error
+ */

nit: why not correct kdoc?

net/ethtool/netlink.c line 98

Quoted 6 lines
net/ethtool/netlink.c +6 -0
+struct sk_buff *ethnl_reply_init(size_t payload, struct net_device *dev, u8 cmd,
+				 u16 dev_attrtype, struct genl_info *info,
+				 void **ehdrp)
+{
+	void *ehdr;
+	struct sk_buff *rskb;

nit: reverse xmas tree

#7 lore raw

Re: [RFC PATCH net-next v3 04/21] ethtool: helper functions for netlink interface

Quoted 11 lines · Jakub Kicinski
Quoted 8 lines · Michal Kubecek

+/* create skb for a reply and fill device identification
+ * payload: payload length (without netlink and genetlink header)

+ * dev:     device the reply is about (may be null)
+ * cmd:     ETHNL_CMD_* command for reply
+ * info:    info for the received packet we respond to
+ * ehdrp:   place to store payload pointer returned by genlmsg_new()

+ * returns: skb or null on error
+ */

nit: why not correct kdoc?

Good point. I'll fix that, together with the other things.

Michal

Quoted 9 lines

net/ethtool/netlink.c line 98

Quoted 7 lines
net/ethtool/netlink.c +6 -0
+struct sk_buff *ethnl_reply_init(size_t payload, struct net_device *dev, u8 cmd,
+				 u16 dev_attrtype, struct genl_info *info,
+				 void **ehdrp)
+{
+	void *ehdr;
+	struct sk_buff *rskb;

nit: reverse xmas tree

#8 lore raw

RFC PATCH v3 5/21 ethtool: netlink bitset handling

In reply to Michal Kubecek

Declare attribute type constants and add helper functions to generate and parse arbitrary length bit sets.

---
 Documentation/networking/ethtool-netlink.txt |  63 ++
 include/uapi/linux/ethtool_netlink.h         |  32 ++
 net/ethtool/Makefile                         |   2 +-
 net/ethtool/bitset.c                         | 572 +++++++++++++++++++
 net/ethtool/bitset.h                         |  40 ++
 net/ethtool/netlink.h                        |   9 +
 6 files changed, 717 insertions(+), 1 deletion(-)
 create mode 100644 net/ethtool/bitset.c
 create mode 100644 net/ethtool/bitset.h
Documentation/networking/ethtool-netlink.txt +63 -0
index 09c36e0392a8..205ae4462e9e 100644
@@ -59,6 +59,69 @@ provided by kernel. In dump requests, device is not specified and kernel
 replies with one message per network device (only those for which the request
 is supported).
 
+Bit sets
+--------
+
+For short bitmaps of (reasonably) fixed length, standard NLA_BITFIELD32 type
+is used. For arbitrary length bitmaps, ethtool netlink uses a nested attribute
+with contents of one of two forms: compact (two binary bitmaps representing
+bit values and mask of affected bits) and bit-by-bit (list of bits identified
+by either index or name).
+
+Compact form: nested (bitset) atrribute contents:
+
+    ETHA_BITSET_LIST	(flag)		no mask, only a list
+    ETHA_BITSET_SIZE	(u32)		number of significant bits
+    ETHA_BITSET_VALUE	(binary)	bitmap of bit values
+    ETHA_BITSET_MASK	(binary)	bitmap of valid bits
+
+Value and mask must have length at least ETHA_BITSET_SIZE bits rounded up to
+a multiple of 32 bits. They consist of 32-bit words in host byte order, words
+ordered from least significant to most significant (i.e. the same way as
+bitmaps are passed with ioctl interface).
+
+For compact form, ETHA_BITSET_SIZE and ETHA_BITSET_VALUE are mandatory.
+Similar to BITFIELD32, a compact form bit set requests to set bits in the mask
+to 1 (if the bit is set in value) or 0 (if not) and preserve the rest. If
+ETHA_BITSET_LIST is present, there is no mask and bitset represents a simple
+list of bits.
+
+Kernel bit set length may differ from userspace length if older application is
+used on newer kernel or vice versa. If userspace bitmap is longer, an error is
+issued only if the request actually tries to set values of some bits not
+recognized by kernel.
+
+Bit-by-bit form: nested (bitset) attribute contents:
+
+    ETHA_BITSET_LIST	(flag)		no mask, only a list
+    ETHA_BITSET_SIZE	(u32)		number of significant bits (optional)
+    ETHA_BITSET_BITS	(nested)	array of bits
+	ETHA_BITSET_BIT
+	    ETHA_BIT_INDEX	(u32)		bit index (0 for LSB)
+            ETHA_BIT_NAME	(string)	bit name
+	    ETHA_BIT_VALUE	(flag)		present if bit is set
+        ETHA_BITSET_BIT
+	...
+
+Bit size is optional for bit-by-bit form. ETHA_BITSET_BITS nest can only
+contain ETHA_BITS_BIT attributes but there can be an arbitrary number of them.
+A bit may be identified by its index or by its name. When used in requests,
+listed bits are set to 0 or 1 according to ETHA_BIT_VALUE, the rest is
+preserved. A request fails if index exceeds kernel bit length or if name is
+not recognized.
+
+When ETHA_BITSET_LIST flag is present, bitset is interpreted as a simple bit
+list. ETHA_BIT_VALUE attributes are not used in such case. Bit list represents
+a bitmap with listed bits set and the rest zero.
+
+In requests, application can use either form. Form used by kernel in reply is
+determined by a flag in flags field of request header. Semantics of value and
+mask depends on the attribute. General idea is that flags control request
+processing, info_mask control which parts of the information are returned in
+"get" request and index identifies a particular subcommand or an object to
+which the request applies.
+
+
 List of message types
 ---------------------
 
include/uapi/linux/ethtool_netlink.h +32 -0
index 01896a1ee21a..7f3d401977b4 100644
@@ -23,6 +23,38 @@ enum {
 	ETHA_DEV_MAX = (__ETHA_DEV_CNT - 1)
 };
 
+/* bit sets */
+
+enum {
+	ETHA_BIT_UNSPEC,
+	ETHA_BIT_INDEX,				/* u32 */
+	ETHA_BIT_NAME,				/* string */
+	ETHA_BIT_VALUE,				/* flag */
+
+	__ETHA_BIT_CNT,
+	ETHA_BIT_MAX = (__ETHA_BIT_CNT - 1)
+};
+
+enum {
+	ETHA_BITS_UNSPEC,
+	ETHA_BITS_BIT,
+
+	__ETHA_BITS_CNT,
+	ETHA_BITS_MAX = (__ETHA_BITS_CNT - 1)
+};
+
+enum {
+	ETHA_BITSET_UNSPEC,
+	ETHA_BITSET_LIST,			/* flag */
+	ETHA_BITSET_SIZE,			/* u32 */
+	ETHA_BITSET_BITS,			/* nest - ETHA_BITS_* */
+	ETHA_BITSET_VALUE,			/* binary */
+	ETHA_BITSET_MASK,			/* binary */
+
+	__ETHA_BITSET_CNT,
+	ETHA_BITSET_MAX = (__ETHA_BITSET_CNT - 1)
+};
+
 /* generic netlink info */
 #define ETHTOOL_GENL_NAME "ethtool"
 #define ETHTOOL_GENL_VERSION 1
net/ethtool/Makefile +1 -1
index f30e0da88be5..482fdb9380fa 100644
@@ -4,4 +4,4 @@ obj-y				+= ioctl.o
 
 obj-$(CONFIG_ETHTOOL_NETLINK)	+= ethtool_nl.o
 
-ethtool_nl-y	:= netlink.o
+ethtool_nl-y	:= netlink.o bitset.o
net/ethtool/bitset.c new file +572 -0

572 lines not on this page · raw message

net/ethtool/bitset.h new file +40 -0
new file mode 100644
index 000000000000..761d0c47fe23
@@ -0,0 +1,40 @@
+/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
+
+#ifndef _NET_ETHTOOL_BITSET_H
+#define _NET_ETHTOOL_BITSET_H
+
+/* when set, value and mask bitmaps are arrays of u32, when not, arrays of
+ * unsigned long
+ */
+#define ETHNL_BITSET_U32		BIT(0)
+/* generate a compact format bitset */
+#define ETHNL_BITSET_COMPACT		BIT(1)
+/* generate a bit list */
+#define ETHNL_BITSET_LIST		BIT(2)
+/* when set, names are interpreted as legacy string set (an array of
+ * char[ETH_GSTRING_LEN]), when not, as a simple array of char *
+ */
+#define ETHNL_BITSET_LEGACY_NAMES	BIT(3)
+
+int ethnl_bitset_is_compact(const struct nlattr *bitset, bool *compact);
+int ethnl_bitset_size(unsigned int size, const unsigned long *val,
+		      const unsigned long *mask, const void *names,
+		      unsigned int flags);
+int ethnl_bitset32_size(unsigned int size, const u32 *val, const u32 *mask,
+			const void *names, unsigned int flags);
+int ethnl_put_bitset(struct sk_buff *skb, int attrtype, unsigned int size,
+		     const unsigned long *val, const unsigned long *mask,
+		     const void *names, unsigned int flags);
+int ethnl_put_bitset32(struct sk_buff *skb, int attrtype, unsigned int size,
+		       const u32 *val, const u32 *mask, const void *names,
+		       unsigned int flags);
+bool ethnl_update_bitset(unsigned long *bitmap, unsigned long *bitmask,
+			 unsigned int nbits, const struct nlattr *attr,
+			 int *err, const void *names, bool legacy,
+			 struct genl_info *info);
+bool ethnl_update_bitset32(u32 *bitmap, u32 *bitmask, unsigned int nbits,
+			   const struct nlattr *attr, int *err,
+			   const void *names, bool legacy,
+			   struct genl_info *info);
+
+#endif /* _NET_ETHTOOL_BITSET_H */
net/ethtool/netlink.h +9 -0
index 36a397656127..ba638eb5a99a 100644
@@ -20,6 +20,15 @@ struct sk_buff *ethnl_reply_init(size_t payload, struct net_device *dev, u8 cmd,
 				 u16 dev_attrtype, struct genl_info *info,
 				 void **ehdrp);
 
+#if BITS_PER_LONG == 64 && defined(__BIG_ENDIAN)
+void ethnl_bitmap_to_u32(unsigned long *bitmap, unsigned int nwords);
+#else
+static inline void ethnl_bitmap_to_u32(unsigned long *bitmap,
+				       unsigned int nwords)
+{
+}
+#endif
+
 static inline int ethnl_str_size(const char *s)
 {
 	return nla_total_size(strlen(s) + 1);
Signature · 1 line
2.20.1
#9 lore raw

Re: [RFC PATCH net-next v3 05/21] ethtool: netlink bitset handling

Quoted 11 lines · Michal Kubecek
net/ethtool/bitset.c new file +11 -0
+		else if (is_u32)
+			bitmap_from_arr32(val, bitmap, nbits);
+		else
+			bitmap_copy(val, bitmap, nbits);
+		nla_for_each_nested(bit_attr, tb[ETHA_BITSET_BITS], rem) {
+			*err = ethnl_update_bit(val, mask, nbits, bit_attr,
+						is_list, names, legacy, info);
+			if (*err < 0)
+				goto out_free;
+		}
+		if (bitmask)

net/ethtool/bitset.c line 509

Quoted 10 lines
net/ethtool/bitset.c new file +10 -0
+			__bitmap_to_any(bitmask, mask, nbits, is_u32);
+	} else {
+		unsigned int change_words = DIV_ROUND_UP(change_bits, 32);
+
+		*err = 0;
+		if (change_bits == 0 && tb[ETHA_BITSET_MASK])
+			goto out_free;
+		*err = -EINVAL;
+		if (!tb[ETHA_BITSET_VALUE])
+			goto out_free;

!tb[ETHA_BITSET_BITS] && !tb[ETHA_BITSET_VALUE] is already rejected above.

Quoted 21 lines
net/ethtool/bitset.c new file +21 -0
+		if (nla_len(tb[ETHA_BITSET_VALUE]) < change_words * sizeof(u32))
+			goto out_free;
+		if (tb[ETHA_BITSET_MASK] &&
+		    nla_len(tb[ETHA_BITSET_MASK]) < change_words * sizeof(u32))
+			goto out_free;
+
+		bitmap_from_arr32(val, nla_data(tb[ETHA_BITSET_VALUE]),
+				  change_bits);
+		if (tb[ETHA_BITSET_MASK])
+			bitmap_from_arr32(mask, nla_data(tb[ETHA_BITSET_MASK]),
+					  change_bits);
+		else
+			bitmap_fill(mask, nbits);
+
+		if (nbits < change_bits) {
+			unsigned int idx = find_next_bit(mask, max_bits, nbits);
+
+			*err = -EINVAL;
+			if (idx < max_bits)
+				goto out_free;
+		}
#10 lore raw

Re: [RFC PATCH net-next v3 05/21] ethtool: netlink bitset handling

Quoted 17 lines · Jakub Kicinski
Quoted 16 lines · Michal Kubecek
net/ethtool/bitset.c new file +16 -0
+		else if (is_u32)
+			bitmap_from_arr32(val, bitmap, nbits);
+		else
+			bitmap_copy(val, bitmap, nbits);
+		nla_for_each_nested(bit_attr, tb[ETHA_BITSET_BITS], rem) {
+			*err = ethnl_update_bit(val, mask, nbits, bit_attr,
+						is_list, names, legacy, info);
+			if (*err < 0)
+				goto out_free;
+		}
+		if (bitmask)
+			__bitmap_to_any(bitmask, mask, nbits, is_u32);
+	} else {
+		unsigned int change_words = DIV_ROUND_UP(change_bits, 32);
+
+		*err = 0;
Quoted 8 lines

net/ethtool/bitset.c line 509

Quoted 5 lines
net/ethtool/bitset.c new file +5 -0
+		if (change_bits == 0 && tb[ETHA_BITSET_MASK])
+			goto out_free;
+		*err = -EINVAL;
+		if (!tb[ETHA_BITSET_VALUE])
+			goto out_free;

!tb[ETHA_BITSET_BITS] && !tb[ETHA_BITSET_VALUE] is already rejected above.

Thank you. I'll drop this test.

Michal

#11 lore raw

RFC PATCH v3 6/21 ethtool: support for netlink notifications

In reply to Michal Kubecek

Add infrastructure for ethtool netlink notifications. There is only one multicast group "monitor" which is used to notify userspace about changes. Notifications are supposed to be broadcasted on every configuration change, whether it is done using the netlink interface or legacy ioctl one.

To trigger an ethtool notification, both ethtool netlink and external code use ethtool_notify() helper. This helper requires RTNL to be held and may sleep.

---
 include/linux/ethtool_netlink.h      |  5 +++++
 include/linux/netdevice.h            | 12 +++++++++++
 include/uapi/linux/ethtool_netlink.h |  2 ++
 net/ethtool/netlink.c                | 32 ++++++++++++++++++++++++++++
 net/ethtool/netlink.h                |  2 ++
 5 files changed, 53 insertions(+)
include/linux/ethtool_netlink.h +5 -0
index 0412adb4f42f..2a15e64a16f3 100644
@@ -5,5 +5,10 @@
 
 #include <uapi/linux/ethtool_netlink.h>
 #include <linux/ethtool.h>
+#include <linux/netdevice.h>
+
+enum ethtool_multicast_groups {
+	ETHNL_MCGRP_MONITOR,
+};
 
 #endif /* _LINUX_ETHTOOL_NETLINK_H_ */
include/linux/netdevice.h +12 -0
index aab4d9f6613d..9a50a67f328f 100644
@@ -4340,6 +4340,18 @@ struct netdev_notifier_bonding_info {
 void netdev_bonding_info_change(struct net_device *dev,
 				struct netdev_bonding_info *bonding_info);
 
+#if IS_ENABLED(CONFIG_ETHTOOL_NETLINK)
+void ethtool_notify(struct net_device *dev, struct netlink_ext_ack *extack,
+		    unsigned int cmd, u32 req_mask, const void *data);
+#else
+static inline void ethtool_notify(struct net_device *dev,
+				  struct netlink_ext_ack *extack,
+				  unsigned int cmd, u32 req_mask,
+				  const void *data)
+{
+}
+#endif
+
 static inline
 struct sk_buff *skb_gso_segment(struct sk_buff *skb, netdev_features_t features)
 {
include/uapi/linux/ethtool_netlink.h +2 -0
index 7f3d401977b4..b662d75a0636 100644
@@ -59,4 +59,6 @@ enum {
 #define ETHTOOL_GENL_NAME "ethtool"
 #define ETHTOOL_GENL_VERSION 1
 
+#define ETHTOOL_MCGRP_MONITOR_NAME "monitor"
+
 #endif /* _UAPI_LINUX_ETHTOOL_NETLINK_H_ */
net/ethtool/netlink.c +32 -0
index ffdcc7c9d4bc..a5fa54c2b743 100644
@@ -4,6 +4,8 @@
 #include <linux/ethtool_netlink.h>
 #include "netlink.h"
 
+u32 ethnl_bcast_seq;
+
 static const struct nla_policy dev_policy[ETHA_DEV_MAX + 1] = {
 	[ETHA_DEV_UNSPEC]	= { .type = NLA_REJECT },
 	[ETHA_DEV_INDEX]	= { .type = NLA_U32 },
@@ -122,11 +124,39 @@ struct sk_buff *ethnl_reply_init(size_t payload, struct net_device *dev, u8 cmd,
 	return NULL;
 }
 
+/* notifications */
+
+typedef void (*ethnl_notify_handler_t)(struct net_device *dev,
+				       struct netlink_ext_ack *extack,
+				       unsigned int cmd, u32 req_mask,
+				       const void *data);
+
+ethnl_notify_handler_t ethnl_notify_handlers[] = {
+};
+
+void ethtool_notify(struct net_device *dev, struct netlink_ext_ack *extack,
+		    unsigned int cmd, u32 req_mask, const void *data)
+{
+	ASSERT_RTNL();
+
+	if (likely(cmd < ARRAY_SIZE(ethnl_notify_handlers) &&
+		   ethnl_notify_handlers[cmd]))
+		ethnl_notify_handlers[cmd](dev, extack, cmd, req_mask, data);
+	else
+		WARN_ONCE(1, "notification %u not implemented (dev=%s, req_mask=0x%x)\n",
+			  cmd, netdev_name(dev), req_mask);
+}
+EXPORT_SYMBOL(ethtool_notify);
+
 /* genetlink setup */
 
 static const struct genl_ops ethtool_genl_ops[] = {
 };
 
+static const struct genl_multicast_group ethtool_nl_mcgrps[] = {
+	[ETHNL_MCGRP_MONITOR] = { .name = ETHTOOL_MCGRP_MONITOR_NAME },
+};
+
 struct genl_family ethtool_genl_family = {
 	.hdrsize	= 0,
 	.name		= ETHTOOL_GENL_NAME,
@@ -135,6 +165,8 @@ struct genl_family ethtool_genl_family = {
 	.parallel_ops	= true,
 	.ops		= ethtool_genl_ops,
 	.n_ops		= ARRAY_SIZE(ethtool_genl_ops),
+	.mcgrps		= ethtool_nl_mcgrps,
+	.n_mcgrps	= ARRAY_SIZE(ethtool_nl_mcgrps),
 };
 
 /* module setup */
net/ethtool/netlink.h +2 -0
index ba638eb5a99a..78385baeaec0 100644
@@ -11,6 +11,8 @@
 #define ETHNL_SET_ERRMSG(info, msg) \
 	do { if (info) GENL_SET_ERR_MSG(info, msg); } while (0)
 
+extern u32 ethnl_bcast_seq;
+
 extern struct genl_family ethtool_genl_family;
 
 struct net_device *ethnl_dev_get(struct genl_info *info, struct nlattr *nest);
Signature · 1 line
2.20.1
#12 lore raw

RFC PATCH v3 7/21 ethtool: implement EVENT notifications

In reply to Michal Kubecek

Three types of netlink notifications are introduced:

- ETHA_EVENT_NEWDEV to notify about newly registered network devices
- ETHA_EVENT_DELDEV to notify about unregistered network devices
- ETHA_EVENT_RENAMEDEV to notify about renamed network device

The notifications are triggered by NETDEV_REGISTER, NETDEV_UNREGISTER and NETDEV_CHANGENAME notifiers.

These notifications are intended for applications and daemons monitoring ethtool events to allow updating the list of existing devices without having to open another socket for rtnetlink.

---
 Documentation/networking/ethtool-netlink.txt | 27 ++++++++
 include/uapi/linux/ethtool_netlink.h         | 37 +++++++++++
 net/ethtool/netlink.c                        | 65 ++++++++++++++++++++
 3 files changed, 129 insertions(+)
Documentation/networking/ethtool-netlink.txt +27 -0
index 205ae4462e9e..b79c26b5e92b 100644
@@ -125,6 +125,8 @@ which the request applies.
 List of message types
 ---------------------
 
+    ETHNL_CMD_EVENT			notification only
+
 All constants use ETHNL_CMD_ prefix, usually followed by "GET", "SET" or "ACT"
 to indicate the type.
 
@@ -136,9 +138,34 @@ messages marked as "response only" in the table above. "Get" messages with
 NLM_F_DUMP flags and no device identification dump the information for all
 devices supporting the request.
 
+Type ETHNL_CMD_EVENT is special, these messages are never used in userspace
+requests or kernel replies. They are only sent by kernel to sockets listening
+to "monitor" multicast group to inform userspace about certain events.
+
 Later sections describe the format and semantics of these request messages.
 
 
+EVENT
+-----
+
+EVENT messages are only used in kernel multicast notifications. Atributes
+correspond to specific event types, the same type can appear multiple times.
+
+    ETHA_EVENT_NEWDEV		(nested)	new device was registered
+       ETHA_NEWDEV_DEV			(nested)	new device
+    ETHA_EVENT_DELDEV		(nested)	device was unregistered
+       ETHA_DELDEV_DEV			(nested)	removed device
+    ETHA_EVENT_RENAMEDEV	(nested)	device was renamed
+       ETHA_RENAMEDEV_DEV		(nested)	renamed device
+
+For ETHA_EVENT_RENAMEDEV, the name ETHA_RENAME_DEV/ETHA_DEV_NAME is the new
+name after the rename.
+
+Userspace application must expect multiple events to be present in one message
+and also multiple events of the same type (e.g. two or more newly registered
+devices).
+
+
 Request translation
 -------------------
 
include/uapi/linux/ethtool_netlink.h +37 -0
index b662d75a0636..7e192ad8ce3a 100644
@@ -7,6 +7,7 @@
 
 enum {
 	ETHNL_CMD_NOOP,
+	ETHNL_CMD_EVENT,		/* only for notifications */
 
 	__ETHNL_CMD_CNT,
 	ETHNL_CMD_MAX = (__ETHNL_CMD_CNT - 1)
@@ -55,6 +56,42 @@ enum {
 	ETHA_BITSET_MAX = (__ETHA_BITSET_CNT - 1)
 };
 
+/* events */
+
+enum {
+	ETHA_NEWDEV_UNSPEC,
+	ETHA_NEWDEV_DEV,			/* nest - ETHA_DEV_* */
+
+	__ETHA_NEWDEV_CNT,
+	ETHA_NEWDEV_MAX = (__ETHA_NEWDEV_CNT - 1)
+};
+
+enum {
+	ETHA_DELDEV_UNSPEC,
+	ETHA_DELDEV_DEV,			/* nest - ETHA_DEV_* */
+
+	__ETHA_DELDEV_CNT,
+	ETHA_DELDEV_MAX = (__ETHA_DELDEV_CNT - 1)
+};
+
+enum {
+	ETHA_RENAMEDEV_UNSPEC,
+	ETHA_RENAMEDEV_DEV,			/* nest - ETHA_DEV_* */
+
+	__ETHA_RENAMEDEV_CNT,
+	ETHA_RENAMEDEV_MAX = (__ETHA_RENAMEDEV_CNT - 1)
+};
+
+enum {
+	ETHA_EVENT_UNSPEC,
+	ETHA_EVENT_NEWDEV,			/* nest - ETHA_NEWDEV_* */
+	ETHA_EVENT_DELDEV,			/* nest - ETHA_DELDEV_* */
+	ETHA_EVENT_RENAMEDEV,			/* nest - ETHA_RENAMEDEV_* */
+
+	__ETHA_EVENT_CNT,
+	ETHA_EVENT_MAX = (__ETHA_EVENT_CNT - 1)
+};
+
 /* generic netlink info */
 #define ETHTOOL_GENL_NAME "ethtool"
 #define ETHTOOL_GENL_VERSION 1
net/ethtool/netlink.c +65 -0

77 lines not on this page · raw message

Signature · 1 line
2.20.1
maintainer
#13 lore raw

Re: [RFC PATCH net-next v3 07/21] ethtool: implement EVENT notifications

Quoted 6 lines · Michal Kubecek

Three types of netlink notifications are introduced:

- ETHA_EVENT_NEWDEV to notify about newly registered network devices
- ETHA_EVENT_DELDEV to notify about unregistered network devices
- ETHA_EVENT_RENAMEDEV to notify about renamed network device

Quoted 6 lines

The notifications are triggered by NETDEV_REGISTER, NETDEV_UNREGISTER and NETDEV_CHANGENAME notifiers.

These notifications are intended for applications and daemons monitoring ethtool events to allow updating the list of existing devices without having to open another socket for rtnetlink.

Hi Michal

Does ETHA_EVENT_RENAMEDEV actually contain enough information to avoid needing a rtnetlink lookup? If i understand the code correctly, all you have is the new name. You don't know the old name?

Having said that, i don't see an easy way to get access to the old name when handling the NETDEV_CHANGENAME.

Andrew

#14 lore raw

Re: [RFC PATCH net-next v3 07/21] ethtool: implement EVENT notifications

Quoted 14 lines · Andrew Lunn
Quoted 6 lines · Michal Kubecek

Three types of netlink notifications are introduced:

- ETHA_EVENT_NEWDEV to notify about newly registered network devices
- ETHA_EVENT_DELDEV to notify about unregistered network devices
- ETHA_EVENT_RENAMEDEV to notify about renamed network device

Quoted 6 lines

The notifications are triggered by NETDEV_REGISTER, NETDEV_UNREGISTER and NETDEV_CHANGENAME notifiers.

These notifications are intended for applications and daemons monitoring ethtool events to allow updating the list of existing devices without having to open another socket for rtnetlink.

Quoted 8 lines

Hi Michal

Does ETHA_EVENT_RENAMEDEV actually contain enough information to avoid needing a rtnetlink lookup? If i understand the code correctly, all you have is the new name. You don't know the old name?

Having said that, i don't see an easy way to get access to the old name when handling the NETDEV_CHANGENAME.

We don't have the old name and without modifying the NETDEV_CHANGENAME notifier to pass it, there is probably no way to get it. But the ethtool notification also contains ifindex so that userspace applications which want to track the configuration can remember both and identify the renamed device by ifindex.

Michal

#15 lore raw

RFC PATCH v3 8/21 ethtool: generic handlers for GET requests

In reply to Michal Kubecek

Some parts of processing GET type requests and related notifications are independent of a command. Provide universal functions so that only four callbacks need to be defined for each command type:

parse_request() - parse incoming message

  prepare_data()  - retrieve data from driver or NIC
  reply_size()    - estimate reply message size
  fill_reply()    - compose reply message

These callback are defined in an instance of struct get_request_ops.

---
 net/ethtool/netlink.c | 286 ++++++++++++++++++++++++++++++++++++++++++
 net/ethtool/netlink.h |  84 +++++++++++++
 2 files changed, 370 insertions(+)
net/ethtool/netlink.c +286 -0
index ee3424cd1f90..8cdb6f52cb4a 100644
@@ -84,6 +84,41 @@ int ethnl_fill_dev(struct sk_buff *msg, struct net_device *dev, u16 attrtype)
 	return ret;
 }
 
+/* GET request helpers */
+
+const struct get_request_ops *get_requests[__ETHNL_CMD_CNT] = {
+};
+
+static struct common_req_info *alloc_get_data(const struct get_request_ops *ops)
+{
+	struct common_req_info *req_info = kmalloc(ops->data_size, GFP_KERNEL);
+
+	if (!req_info)
+		return NULL;
+	memset(req_info, '\0', ops->repdata_offset);
+	req_info->reply_data =
+		(struct common_reply_data *)((char *)req_info +
+					     ops->repdata_offset);
+	return req_info;
+}
+
+static void free_get_data(const struct get_request_ops *ops,
+			  struct common_req_info *req_info)
+{
+	if (ops->cleanup)
+		ops->cleanup(req_info);
+	kfree(req_info);
+}
+
+static void init_reply_data(const struct common_req_info *req_info,
+			    const struct get_request_ops *ops,
+			    struct net_device *dev)
+{
+	memset(req_info->reply_data, '\0',
+	       ops->data_size - ops->repdata_offset);
+	req_info->reply_data->dev = dev;
+}
+
 /* create skb for a reply and fill device identification
  * payload: payload length (without netlink and genetlink header)
  * dev:     device the reply is about (may be null)
@@ -124,6 +159,257 @@ struct sk_buff *ethnl_reply_init(size_t payload, struct net_device *dev, u8 cmd,
 	return NULL;
 }
 
+int ethnl_get_doit(struct sk_buff *skb, struct genl_info *info)
+{
+	const u8 cmd = info->genlhdr->cmd;
+	struct common_req_info *req_info;
+	const struct get_request_ops *ops;
+	struct sk_buff *rskb;
+	void *reply_payload;
+	int reply_len;
+	int ret;
+
+	ops = get_requests[cmd];
+	if (WARN_ONCE(!ops, "cmd %u has no get_request_ops\n", cmd))
+		return -EOPNOTSUPP;
+	req_info = alloc_get_data(ops);
+	if (!req_info)
+		return -ENOMEM;
+	ret = ops->parse_request(req_info, skb, info, info->nlhdr);
+	if (!ops->allow_nodev_do && !req_info->dev) {
+		ETHNL_SET_ERRMSG(info, "device not specified in do request");
+		ret = -EINVAL;
+	}
+	if (ret < 0)
+		goto err_dev;
+	init_reply_data(req_info, ops, req_info->dev);
+
+	rtnl_lock();
+	ret = ops->prepare_data(req_info, info);
+	if (ret < 0)
+		goto err_rtnl;
+	reply_len = ops->reply_size(req_info);
+	if (ret < 0)
+		goto err_rtnl;
+	ret = -ENOMEM;
+	rskb = ethnl_reply_init(reply_len, req_info->dev, ops->reply_cmd,
+				ops->dev_attrtype, info, &reply_payload);
+	if (!rskb)
+		goto err_rtnl;
+	ret = ops->fill_reply(rskb, req_info);
+	if (ret < 0)
+		goto err;
+	rtnl_unlock();
+
+	genlmsg_end(rskb, reply_payload);
+	if (req_info->dev)
+		dev_put(req_info->dev);
+	free_get_data(ops, req_info);
+	return genlmsg_reply(rskb, info);
+
+err:
+	WARN_ONCE(ret == -EMSGSIZE,
+		  "calculated message payload length (%d) not sufficient\n",
+		  reply_len);
+	nlmsg_free(rskb);
+	free_get_data(ops, req_info);
+err_rtnl:
+	rtnl_unlock();
+err_dev:
+	if (req_info->dev)
+		dev_put(req_info->dev);
+	return ret;
+}
+
+static int ethnl_get_dump_one(struct sk_buff *skb,
+			      struct net_device *dev,
+			      const struct get_request_ops *ops,
+			      struct common_req_info *req_info)
+{
+	int ret;
+
+	init_reply_data(req_info, ops, dev);
+	rtnl_lock();
+	ret = ops->prepare_data(req_info, NULL);
+	if (ret < 0)
+		return ret;
+	ret = ethnl_fill_dev(skb, dev, ops->dev_attrtype);
+	if (ret < 0)
+		return ret;
+	ret = ops->fill_reply(skb, req_info);
+	rtnl_unlock();
+
+	req_info->reply_data->dev = NULL;
+	return ret;
+}
+
+/* generic ->dumpit() handler; device iteration copied from rtnl_dump_ifinfo()
+ * cb->args[0]: pointer to struct get_request_ops
+ * cb->args[1]: pointer to request data
+ * cb->args[2]: iteration position - hashbucket
+ * cb->args[3]: iteration position - ifindex
+ */
+int ethnl_get_dumpit(struct sk_buff *skb, struct netlink_callback *cb)
+{
+	struct net *net = sock_net(skb->sk);
+	struct common_req_info *req_info;
+	const struct get_request_ops *ops;
+	int h, s_h, idx = 0, s_idx;
+	struct hlist_head *head;
+	struct net_device *dev;
+	int ret = 0;
+	void *ehdr;
+
+	ops = (const struct get_request_ops *)cb->args[0];
+	req_info = (struct common_req_info *)cb->args[1];
+	s_h = cb->args[2];
+	s_idx = cb->args[3];
+
+	for (h = s_h; h < NETDEV_HASHENTRIES; h++, s_idx = 0) {
+		idx = 0;
+		head = &net->dev_index_head[h];
+		hlist_for_each_entry(dev, head, index_hlist) {
+			if (idx < s_idx)
+				goto cont;
+			ehdr = genlmsg_put(skb, NETLINK_CB(cb->skb).portid,
+					   cb->nlh->nlmsg_seq,
+					   &ethtool_genl_family, 0,
+					   ops->reply_cmd);
+			ret = ethnl_get_dump_one(skb, dev, ops, req_info);
+			if (ret < 0) {
+				genlmsg_cancel(skb, ehdr);
+				if (ret == -EOPNOTSUPP)
+					goto cont;
+				if (likely(skb->len))
+					goto out;
+				goto out_err;
+			}
+			genlmsg_end(skb, ehdr);
+cont:
+			idx++;
+		}
+	}
+out:
+	ret = skb->len;
+out_err:
+	cb->args[2] = h;
+	cb->args[3] = idx;
+	cb->seq = net->dev_base_seq;
+	nl_dump_check_consistent(cb, nlmsg_hdr(skb));
+
+	return ret;
+}
+
+/* generic ->start() handler for GET requests */
+static int ethnl_get_start(struct netlink_callback *cb)
+{
+	struct common_req_info *req_info;
+	const struct get_request_ops *ops;
+	struct genlmsghdr *ghdr;
+	int ret;
+
+	ghdr = nlmsg_data(cb->nlh);
+	ops = get_requests[ghdr->cmd];
+	if (WARN_ONCE(!ops, "cmd %u has no get_request_ops\n", ghdr->cmd))
+		return -EOPNOTSUPP;
+	req_info = alloc_get_data(ops);
+	if (!req_info)
+		return -ENOMEM;
+
+	ret = ops->parse_request(req_info, cb->skb, NULL, cb->nlh);
+	if (req_info->dev) {
+		/* We ignore device specification in dump requests but as the
+		 * same parser as for non-dump (doit) requests is used, it
+		 * would take reference to the device if it finds one
+		 */
+		dev_put(req_info->dev);
+		req_info->dev = NULL;
+	}
+	if (ret < 0)
+		return ret;
+
+	cb->args[0] = (long)ops;
+	cb->args[1] = (long)req_info;
+	cb->args[2] = 0;
+	cb->args[3] = 0;
+
+	return 0;
+}
+
+/* generic ->done() handler for GET requests */
+static int ethnl_get_done(struct netlink_callback *cb)
+{
+	free_get_data((const struct get_request_ops *)cb->args[0],
+		      (struct common_req_info *)cb->args[1]);
+
+	return 0;
+}
+
+/* generic notification handler */
+static void ethnl_std_notify(struct net_device *dev,
+			     struct netlink_ext_ack *extack, unsigned int cmd,
+			     u32 req_mask, const void *data)
+{
+	struct common_req_info *req_info;
+	const struct get_request_ops *ops;
+	struct sk_buff *skb;
+	void *reply_payload;
+	int reply_len;
+	int ret;
+
+	ops = get_requests[cmd - 1];
+	if (WARN_ONCE(!ops, "cmd %u has no get_request_ops\n", cmd - 1))
+		return;
+	/* when ethnl_std_notify() is used as notify handler, command id of
+	 * corresponding GET request must be one less than cmd argument passed
+	 * to ethnl_std_notify()
+	 */
+	if (WARN_ONCE(ops->reply_cmd != cmd,
+		      "reply_cmd for %u is %u, expected %u\n", cmd - 1,
+		      ops->reply_cmd, cmd))
+		return;
+
+	req_info = alloc_get_data(ops);
+	if (!req_info)
+		return;
+	req_info->dev = dev;
+	req_info->req_mask = req_mask;
+	req_info->compact = true;
+
+	init_reply_data(req_info, ops, dev);
+	ret = ops->prepare_data(req_info, NULL);
+	if (ret < 0)
+		goto err_data;
+	reply_len = ops->reply_size(req_info);
+	if (reply_len < 0)
+		goto err_data;
+	skb = genlmsg_new(reply_len, GFP_KERNEL);
+	if (!skb)
+		goto err_data;
+	reply_payload = genlmsg_put(skb, 0, ++ethnl_bcast_seq,
+				    &ethtool_genl_family, 0, ops->reply_cmd);
+	if (!reply_payload)
+		goto err_skb;
+
+	ret = ethnl_fill_dev(skb, dev, ops->dev_attrtype);
+	if (ret < 0)
+		goto err_skb;
+	ret = ops->fill_reply(skb, req_info);
+	if (ret < 0)
+		goto err_skb;
+	free_get_data(ops, req_info);
+	genlmsg_end(skb, reply_payload);
+
+	genlmsg_multicast(&ethtool_genl_family, skb, 0, ETHNL_MCGRP_MONITOR,
+			  GFP_KERNEL);
+	return;
+
+err_skb:
+	nlmsg_free(skb);
+err_data:
+	free_get_data(ops, req_info);
+}
+
 /* notifications */
 
 typedef void (*ethnl_notify_handler_t)(struct net_device *dev,
net/ethtool/netlink.h +84 -0

88 lines not on this page · raw message

Signature · 1 line
2.20.1
#16 lore raw

Re: [RFC PATCH net-next v3 08/21] ethtool: generic handlers for GET requests

Quoted 1 line · Michal Kubecek

+static struct common_req_info *alloc_get_data(const struct get_request_ops *ops)

nit: IMHO prefixing all structures and functions with a common phrase
(ethnl) makes the code easier to navigate.

net/ethtool/netlink.c int ethnl_fill_dev(struct sk_buff *msg, struct net_device *dev, u16 attrtype) · line 97

Quoted 5 lines
net/ethtool/netlink.c +5 -0
+{
+	struct common_req_info *req_info = kmalloc(ops->data_size, GFP_KERNEL);
+
+	if (!req_info)
+		return NULL;

nit: please avoid calling complex functions inline, especially if the
result has to be error checked

#17 lore raw

RFC PATCH v3 9/21 ethtool: move string arrays into common file

In reply to Michal Kubecek

Introduce file net/ethtool/common.c for code shared by ioctl and netlink ethtool interface. Move name tables of features, RSS hash functions, tunables and PHY tunables into this file.

---
 net/ethtool/Makefile |  2 +-
 net/ethtool/common.c | 83 ++++++++++++++++++++++++++++++++++++++++++++
 net/ethtool/common.h | 17 +++++++++
 net/ethtool/ioctl.c  | 82 ++-----------------------------------------
 4 files changed, 103 insertions(+), 81 deletions(-)
 create mode 100644 net/ethtool/common.c
 create mode 100644 net/ethtool/common.h
net/ethtool/Makefile +1 -1
index 482fdb9380fa..11782306593b 100644
@@ -1,6 +1,6 @@
 # SPDX-License-Identifier: GPL-2.0
 
-obj-y				+= ioctl.o
+obj-y				+= ioctl.o common.o
 
 obj-$(CONFIG_ETHTOOL_NETLINK)	+= ethtool_nl.o
 
net/ethtool/common.c new file +83 -0

83 lines not on this page · raw message

net/ethtool/common.h new file +17 -0
new file mode 100644
index 000000000000..41b2efc1e4e1
@@ -0,0 +1,17 @@
+/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
+
+#ifndef _ETHTOOL_COMMON_H
+#define _ETHTOOL_COMMON_H
+
+#include <linux/ethtool.h>
+
+extern const char
+netdev_features_strings[NETDEV_FEATURE_COUNT][ETH_GSTRING_LEN];
+extern const char
+rss_hash_func_strings[ETH_RSS_HASH_FUNCS_COUNT][ETH_GSTRING_LEN];
+extern const char
+tunable_strings[__ETHTOOL_TUNABLE_COUNT][ETH_GSTRING_LEN];
+extern const char
+phy_tunable_strings[__ETHTOOL_PHY_TUNABLE_COUNT][ETH_GSTRING_LEN];
+
+#endif /* _ETHTOOL_COMMON_H */
net/ethtool/ioctl.c +2 -80

94 lines not on this page · raw message

Signature · 1 line
2.20.1
#18 lore raw

RFC PATCH v3 10/21 ethtool: provide string sets with GET_STRSET request

In reply to Michal Kubecek

Requests a contents of one or more string sets, i.e. indexed arrays of strings; this information is provided by ETHTOOL_GSSET_INFO and ETHTOOL_GSTRINGS commands of ioctl interface. There are three types of requests:

- no NLM_F_DUMP, no device: get "global" stringsets
- no NLM_F_DUMP, with device: get string sets related to the device
- NLM_F_DUMP, no device: get device related string sets for all devices

It's possible to request all string sets of given type or only specific sets. With ETHA_STRSET_COUNTS flag, only set sizes (number of strings) are returned.

---
 Documentation/networking/ethtool-netlink.txt |  46 +-
 include/uapi/linux/ethtool.h                 |   2 +
 include/uapi/linux/ethtool_netlink.h         |  43 ++
 net/ethtool/Makefile                         |   2 +-
 net/ethtool/netlink.c                        |  10 +
 net/ethtool/strset.c                         | 437 +++++++++++++++++++
 6 files changed, 537 insertions(+), 3 deletions(-)
 create mode 100644 net/ethtool/strset.c
Documentation/networking/ethtool-netlink.txt +44 -2
index b79c26b5e92b..f0fe4f50db9f 100644
@@ -126,6 +126,8 @@ List of message types
 ---------------------
 
     ETHNL_CMD_EVENT			notification only
+    ETHNL_CMD_GET_STRSET
+    ETHNL_CMD_SET_STRSET		response only
 
 All constants use ETHNL_CMD_ prefix, usually followed by "GET", "SET" or "ACT"
 to indicate the type.
@@ -166,6 +168,46 @@ and also multiple events of the same type (e.g. two or more newly registered
 devices).
 
 
+GET_STRSET
+----------
+
+Requests contents of a string set as provided by ioctl commands
+ETHTOOL_GSSET_INFO and ETHTOOL_GSTRINGS. String sets are not user writeable so
+that the corresponding SET_STRSET message is only used in kernel replies.
+There are two types of string sets: global (independent of a device, e.g.
+device feature names) and device specific (e.g. device private flags).
+
+Request contents:
+
+    ETHA_STRSET_DEV		(nested)	device identification
+    ETHA_STRSET_COUNTS		(flag)		request only string counts
+    ETHA_STRSET_STRINGSET	(nested)	string set to request
+        ETHA_STRINGSET_ID		(u32)		set id
+
+Kernel response contents:
+
+    ETHA_STRSET_DEV		(nested)	device identification
+    ETHA_STRSET_STRINGSET	(nested)	string set to request
+        ETHA_STRINGSET_ID		(u32)		set id
+        ETHA_STRINGSET_COUNT		(u32)		number of strings
+        ETHA_STRINGSET_STRINGS		(nested)	array of strings
+            ETHA_STRING_INDEX			(u32)		string index
+            ETHA_STRING_VALUE			(string)	string value
+
+ETHA_STRSET_DEV, if present, identifies the device to request device specific
+string sets for. Depending on its presence a and NLM_F_DUMP flag, there are
+three type of GET_STRSET requests:
+
+ - no NLM_F_DUMP, no device: get "global" stringsets
+ - no NLM_F_DUMP, with device: get string sets related to the device
+ - NLM_F_DUMP, no device: get device related string sets for all devices
+
+If there is no ETHA_STRSET_STRINGSET attribute, all string sets of requested
+type are returned, otherwise only those specified in the request. Flag
+ETHA_STRSET_COUNTS tells kernel to only return string counts of the sets, not
+the actual strings.
+
+
 Request translation
 -------------------
 
@@ -200,7 +242,7 @@ ETHTOOL_STXCSUM			n/a
 ETHTOOL_GSG			n/a
 ETHTOOL_SSG			n/a
 ETHTOOL_TEST			n/a
-ETHTOOL_GSTRINGS		n/a
+ETHTOOL_GSTRINGS		ETHNL_CMD_GET_STRSET
 ETHTOOL_PHYS_ID			n/a
 ETHTOOL_GSTATS			n/a
 ETHTOOL_GTSO			n/a
@@ -228,7 +270,7 @@ ETHTOOL_FLASHDEV		n/a
 ETHTOOL_RESET			n/a
 ETHTOOL_SRXNTUPLE		n/a
 ETHTOOL_GRXNTUPLE		n/a
-ETHTOOL_GSSET_INFO		n/a
+ETHTOOL_GSSET_INFO		ETHNL_CMD_GET_STRSET
 ETHTOOL_GRXFHINDIR		n/a
 ETHTOOL_SRXFHINDIR		n/a
 ETHTOOL_GFEATURES		n/a
include/uapi/linux/ethtool.h +2 -0
index 17be76aeb468..9ea278961d80 100644
@@ -574,6 +574,8 @@ enum ethtool_stringset {
 	ETH_SS_TUNABLES,
 	ETH_SS_PHY_STATS,
 	ETH_SS_PHY_TUNABLES,
+
+	ETH_SS_COUNT
 };
 
 /**
include/uapi/linux/ethtool_netlink.h +43 -0

55 lines not on this page · raw message

net/ethtool/Makefile +1 -1
index 11782306593b..11ceb00821b3 100644
@@ -4,4 +4,4 @@ obj-y				+= ioctl.o common.o
 
 obj-$(CONFIG_ETHTOOL_NETLINK)	+= ethtool_nl.o
 
-ethtool_nl-y	:= netlink.o bitset.o
+ethtool_nl-y	:= netlink.o bitset.o strset.o
net/ethtool/netlink.c +10 -0
index 8cdb6f52cb4a..082a9f2aa0a7 100644
@@ -86,7 +86,10 @@ int ethnl_fill_dev(struct sk_buff *msg, struct net_device *dev, u16 attrtype)
 
 /* GET request helpers */
 
+extern const struct get_request_ops strset_request_ops;
+
 const struct get_request_ops *get_requests[__ETHNL_CMD_CNT] = {
+	[ETHNL_CMD_GET_STRSET]		= &strset_request_ops,
 };
 
 static struct common_req_info *alloc_get_data(const struct get_request_ops *ops)
@@ -498,6 +501,13 @@ static struct notifier_block ethnl_netdev_notifier = {
 /* genetlink setup */
 
 static const struct genl_ops ethtool_genl_ops[] = {
+	{
+		.cmd	= ETHNL_CMD_GET_STRSET,
+		.doit	= ethnl_get_doit,
+		.start	= ethnl_get_start,
+		.dumpit	= ethnl_get_dumpit,
+		.done	= ethnl_get_done,
+	},
 };
 
 static const struct genl_multicast_group ethtool_nl_mcgrps[] = {
net/ethtool/strset.c new file +437 -0

437 lines not on this page · raw message

Signature · 1 line
2.20.1
#19 lore raw

Re: [RFC PATCH net-next v3 10/21] ethtool: provide string sets with GET_STRSET request

Quoted 23 lines · Michal Kubecek

Requests a contents of one or more string sets, i.e. indexed arrays of strings; this information is provided by ETHTOOL_GSSET_INFO and ETHTOOL_GSTRINGS commands of ioctl interface. There are three types of requests:

- no NLM_F_DUMP, no device: get "global" stringsets
- no NLM_F_DUMP, with device: get string sets related to the device
- NLM_F_DUMP, no device: get device related string sets for all devices

It's possible to request all string sets of given type or only specific sets. With ETHA_STRSET_COUNTS flag, only set sizes (number of strings) are returned.

Documentation/networking/ethtool-netlink.txt +10 -0
+GET_STRSET
+----------
+
+Requests contents of a string set as provided by ioctl commands
+ETHTOOL_GSSET_INFO and ETHTOOL_GSTRINGS. String sets are not user writeable so
+that the corresponding SET_STRSET message is only used in kernel replies.
+There are two types of string sets: global (independent of a device, e.g.
+device feature names) and device specific (e.g. device private flags).
+
+Request contents:

Documentation/networking/ethtool-netlink.txt and also multiple events of the same type (e.g. two or more newly registered · line 190

Quoted 10 lines
Documentation/networking/ethtool-netlink.txt +10 -0
+
+    ETHA_STRSET_DEV		(nested)	device identification
+    ETHA_STRSET_COUNTS		(flag)		request only string counts
+    ETHA_STRSET_STRINGSET	(nested)	string set to request
+        ETHA_STRINGSET_ID		(u32)		set id
+
+Kernel response contents:
+
+    ETHA_STRSET_DEV		(nested)	device identification
+    ETHA_STRSET_STRINGSET	(nested)	string set to request

Is it common to put the device information outside of the main attribute nest?

Quoted 19 lines
Documentation/networking/ethtool-netlink.txt +19 -0
+        ETHA_STRINGSET_ID		(u32)		set id
+        ETHA_STRINGSET_COUNT		(u32)		number of strings
+        ETHA_STRINGSET_STRINGS		(nested)	array of strings
+            ETHA_STRING_INDEX			(u32)		string index
+            ETHA_STRING_VALUE			(string)	string value
+
+ETHA_STRSET_DEV, if present, identifies the device to request device specific
+string sets for. Depending on its presence a and NLM_F_DUMP flag, there are
+three type of GET_STRSET requests:
+
+ - no NLM_F_DUMP, no device: get "global" stringsets
+ - no NLM_F_DUMP, with device: get string sets related to the device
+ - NLM_F_DUMP, no device: get device related string sets for all devices
+
+If there is no ETHA_STRSET_STRINGSET attribute, all string sets of requested
+type are returned, otherwise only those specified in the request. Flag
+ETHA_STRSET_COUNTS tells kernel to only return string counts of the sets, not
+the actual strings.
+

Documentation/networking/ethtool-netlink.txt and also multiple events of the same type (e.g. two or more newly registered

Quoted 10 lines
Documentation/networking/ethtool-netlink.txt +9 -0
+
 
+static int get_strset_id(const struct nlattr *nest, u32 *val,
+			 struct genl_info *info)
+{
+	struct nlattr *tb[ETHA_STRINGSET_MAX + 1];
+	int ret;
+
+	ret = nla_parse_nested(tb, ETHA_STRINGSET_MAX, nest, stringset_policy,
+			       info ? info->extack : NULL);

Would it make sense to use strict parsing everywhere from the start? You seem to add REJECTS, but won't attributes > max get ignored?

Quoted 21 lines
net/ethtool/strset.c new file +21 -0
+	if (ret < 0)
+		return ret;
+	if (!tb[ETHA_STRINGSET_ID])
+		return -EINVAL;
+
+	*val = nla_get_u32(tb[ETHA_STRINGSET_ID]);
+	return 0;
+}
+
+static int parse_strset(struct common_req_info *req_info, struct sk_buff *skb,
+			struct genl_info *info, const struct nlmsghdr *nlhdr)
+{
+	struct strset_data *data =
+		container_of(req_info, struct strset_data, reqinfo_base);
+	struct nlattr *attr;
+	int rem, ret;
+
+	ret = nlmsg_validate(nlhdr, GENL_HDRLEN, ETHA_STRSET_MAX,
+			     get_strset_policy, info ? info->extack : NULL);
+	if (ret < 0)
+		return ret;
#20 lore raw

Re: [RFC PATCH net-next v3 10/21] ethtool: provide string sets with GET_STRSET request

Quoted 29 lines · Jakub Kicinski
Quoted 28 lines · Michal Kubecek

Requests a contents of one or more string sets, i.e. indexed arrays of strings; this information is provided by ETHTOOL_GSSET_INFO and ETHTOOL_GSTRINGS commands of ioctl interface. There are three types of requests:

- no NLM_F_DUMP, no device: get "global" stringsets
- no NLM_F_DUMP, with device: get string sets related to the device
- NLM_F_DUMP, no device: get device related string sets for all devices

It's possible to request all string sets of given type or only specific sets. With ETHA_STRSET_COUNTS flag, only set sizes (number of strings) are returned.

Documentation/networking/ethtool-netlink.txt +15 -0
+GET_STRSET
+----------
+
+Requests contents of a string set as provided by ioctl commands
+ETHTOOL_GSSET_INFO and ETHTOOL_GSTRINGS. String sets are not user writeable so
+that the corresponding SET_STRSET message is only used in kernel replies.
+There are two types of string sets: global (independent of a device, e.g.
+device feature names) and device specific (e.g. device private flags).
+
+Request contents:
+
+    ETHA_STRSET_DEV		(nested)	device identification
+    ETHA_STRSET_COUNTS		(flag)		request only string counts
+    ETHA_STRSET_STRINGSET	(nested)	string set to request
+        ETHA_STRINGSET_ID		(u32)		set id
Quoted 8 lines

Documentation/networking/ethtool-netlink.txt and also multiple events of the same type (e.g. two or more newly registered · line 190

Quoted 5 lines
Documentation/networking/ethtool-netlink.txt +5 -0
+
+Kernel response contents:
+
+    ETHA_STRSET_DEV		(nested)	device identification
+    ETHA_STRSET_STRINGSET	(nested)	string set to request

Is it common to put the device information outside of the main attribute nest?

There may be multiple string sets (ETHA_STRSET_STIRNGSET nests) in one message but they would be either all global or all related to the same device. If string sets for multiple devices are sent, it would be in response to a dump request and there would be one message per device.

Quoted 22 lines
Quoted 21 lines
Documentation/networking/ethtool-netlink.txt +20 -0
+        ETHA_STRINGSET_ID		(u32)		set id
+        ETHA_STRINGSET_COUNT		(u32)		number of strings
+        ETHA_STRINGSET_STRINGS		(nested)	array of strings
+            ETHA_STRING_INDEX			(u32)		string index
+            ETHA_STRING_VALUE			(string)	string value
+
+ETHA_STRSET_DEV, if present, identifies the device to request device specific
+string sets for. Depending on its presence a and NLM_F_DUMP flag, there are
+three type of GET_STRSET requests:
+
+ - no NLM_F_DUMP, no device: get "global" stringsets
+ - no NLM_F_DUMP, with device: get string sets related to the device
+ - NLM_F_DUMP, no device: get device related string sets for all devices
+
+If there is no ETHA_STRSET_STRINGSET attribute, all string sets of requested
+type are returned, otherwise only those specified in the request. Flag
+ETHA_STRSET_COUNTS tells kernel to only return string counts of the sets, not
+the actual strings.
+
+
Quoted 11 lines

net/ethtool/strset.c line 136

Quoted 8 lines
net/ethtool/strset.c new file +8 -0
+static int get_strset_id(const struct nlattr *nest, u32 *val,
+			 struct genl_info *info)
+{
+	struct nlattr *tb[ETHA_STRINGSET_MAX + 1];
+	int ret;
+
+	ret = nla_parse_nested(tb, ETHA_STRINGSET_MAX, nest, stringset_policy,
+			       info ? info->extack : NULL);

Would it make sense to use strict parsing everywhere from the start? You seem to add REJECTS, but won't attributes > max get ignored?

Good point, I forgot about this when the strict checking helpers were added. I'll change the uses of nlmsg_parse() and nla_parse_nested() to their strict variants (and add nla_parse_nested_strict()).

Michal

#21 lore raw

RFC PATCH v3 11/21 ethtool: provide driver/device information in GET_INFO request

In reply to Michal Kubecek

Implement GET_INFO request to get basic driver and device information as provided by ETHTOOL_GDRVINFO ioct command. The information is read only so that the corresponding SET_INFO message is only used in kernel replies.

Move most of ethtool_get_drvinfo() int common.c so that the code can be shared by both ioctl and netlink interface.

---
 Documentation/networking/ethtool-netlink.txt |  43 ++++-
 include/uapi/linux/ethtool_netlink.h         |  32 ++++
 net/ethtool/Makefile                         |   2 +-
 net/ethtool/common.c                         |  54 +++++++
 net/ethtool/common.h                         |   2 +
 net/ethtool/info.c                           | 155 +++++++++++++++++++
 net/ethtool/ioctl.c                          |  52 +------
 net/ethtool/netlink.c                        |   9 ++
 8 files changed, 300 insertions(+), 49 deletions(-)
 create mode 100644 net/ethtool/info.c
Documentation/networking/ethtool-netlink.txt +42 -1
index f0fe4f50db9f..b6999a2167e8 100644
@@ -128,6 +128,8 @@ List of message types
     ETHNL_CMD_EVENT			notification only
     ETHNL_CMD_GET_STRSET
     ETHNL_CMD_SET_STRSET		response only
+    ETHNL_CMD_GET_INFO
+    ETHNL_CMD_SET_INFO			response only
 
 All constants use ETHNL_CMD_ prefix, usually followed by "GET", "SET" or "ACT"
 to indicate the type.
@@ -208,6 +210,45 @@ ETHA_STRSET_COUNTS tells kernel to only return string counts of the sets, not
 the actual strings.
 
 
+GET_INFO
+--------
+
+GET_INFO requests information provided by ioctl commands ETHTOOL_GDRVINFO,
+ETHTOOL_GPERMADDR and ETHTOOL_GET_TS_INFO to provide basic device information.
+Common pattern is that all information is read only so that SET_INFO message
+exists but is only used by kernel for replies to GET_INFO requests. There is
+also no corresponding notification.
+
+Request contents:
+
+    ETHA_INFO_DEV		(nested)	device identification
+    ETHA_INFO_INFOMASK		(u32)		info mask
+    ETHA_INFO_COMPACT		(flag)		request compact bitsets
+
+Info mask bits meaning:
+
+    ETH_INFO_IM_DRVINFO			driver info (GDRVINFO)
+    ETH_INFO_IM_PERMADDR		permanent HW address (GPERMADDR)
+    ETH_INFO_IM_TSINFO			timestamping info (GET_TS_INFO)
+
+Kernel response contents:
+
+    ETHA_INFO_DEV		(nested)	device identification
+    ETHA_INFO_DRVINFO		(nested)	driver information
+        ETHA_DRVINFO_DRIVER		(string)	driver name
+        ETHA_DRVINFO_FWVERSION		(string)	firmware version
+        ETHA_DRVINFO_BUSINFO		(string)	device bus address
+        ETHA_DRVINFO_EROM_VER		(string)	expansion ROM version
+
+The meaning of DRVINFO attributes follows the corresponding fields of
+ETHTOOL_GDRVINFO response. Second part with various counts and sizes is
+omitted as these are not really needed (and if they are, they can be easily
+found by different means). Driver version is also omitted as it is rather
+misleading in most cases.
+
+GET_INFO requests allow dumps.
+
+
 Request translation
 -------------------
 
@@ -219,7 +260,7 @@ ioctl command			netlink command
 ---------------------------------------------------------------------
 ETHTOOL_GSET			n/a
 ETHTOOL_SSET			n/a
-ETHTOOL_GDRVINFO		n/a
+ETHTOOL_GDRVINFO		ETHNL_CMD_GET_INFO
 ETHTOOL_GREGS			n/a
 ETHTOOL_GWOL			n/a
 ETHTOOL_SWOL			n/a
include/uapi/linux/ethtool_netlink.h +32 -0
index 630b66732dc9..fdae12b6c6b6 100644
@@ -10,6 +10,8 @@ enum {
 	ETHNL_CMD_EVENT,		/* only for notifications */
 	ETHNL_CMD_GET_STRSET,
 	ETHNL_CMD_SET_STRSET,		/* only for reply */
+	ETHNL_CMD_GET_INFO,
+	ETHNL_CMD_SET_INFO,		/* only for reply */
 
 	__ETHNL_CMD_CNT,
 	ETHNL_CMD_MAX = (__ETHNL_CMD_CNT - 1)
@@ -135,6 +137,36 @@ enum {
 	ETHA_STRSET_MAX = (__ETHA_STRSET_CNT - 1)
 };
 
+/* GET_INFO / SET_INFO */
+
+enum {
+	ETHA_INFO_UNSPEC,
+	ETHA_INFO_DEV,				/* nest - ETHA_DEV_* */
+	ETHA_INFO_INFOMASK,			/* u32 */
+	ETHA_INFO_COMPACT,			/* flag */
+	ETHA_INFO_DRVINFO,			/* nest - ETHA_DRVINFO_* */
+	ETHA_INFO_PERMADDR,			/* nest - ETHA_PERMADDR_* */
+	ETHA_INFO_TSINFO,			/* nest - ETHA_TSINFO_* */
+
+	__ETHA_INFO_CNT,
+	ETHA_INFO_MAX = (__ETHA_INFO_CNT - 1)
+};
+
+#define ETH_INFO_IM_DRVINFO			0x01
+
+#define ETH_INFO_IM_ALL				0x01
+
+enum {
+	ETHA_DRVINFO_UNSPEC,
+	ETHA_DRVINFO_DRIVER,			/* string */
+	ETHA_DRVINFO_FWVERSION,			/* string */
+	ETHA_DRVINFO_BUSINFO,			/* string */
+	ETHA_DRVINFO_EROM_VER,			/* string */
+
+	__ETHA_DRVINFO_CNT,
+	ETHA_DRVINFO_MAX = (__ETHA_DRVINFO_CNT - 1)
+};
+
 /* generic netlink info */
 #define ETHTOOL_GENL_NAME "ethtool"
 #define ETHTOOL_GENL_VERSION 1
net/ethtool/Makefile +1 -1
index 11ceb00821b3..96d41dc45d4f 100644
@@ -4,4 +4,4 @@ obj-y				+= ioctl.o common.o
 
 obj-$(CONFIG_ETHTOOL_NETLINK)	+= ethtool_nl.o
 
-ethtool_nl-y	:= netlink.o bitset.o strset.o
+ethtool_nl-y	:= netlink.o bitset.o strset.o info.o
net/ethtool/common.c +54 -0

62 lines not on this page · raw message

net/ethtool/common.h +2 -0
index 41b2efc1e4e1..e87e58b3a274 100644
@@ -3,6 +3,7 @@
 #ifndef _ETHTOOL_COMMON_H
 #define _ETHTOOL_COMMON_H
 
+#include <linux/netdevice.h>
 #include <linux/ethtool.h>
 
 extern const char
@@ -14,4 +15,5 @@ tunable_strings[__ETHTOOL_TUNABLE_COUNT][ETH_GSTRING_LEN];
 extern const char
 phy_tunable_strings[__ETHTOOL_PHY_TUNABLE_COUNT][ETH_GSTRING_LEN];
 
+int __ethtool_get_drvinfo(struct net_device *dev, struct ethtool_drvinfo *info);
 #endif /* _ETHTOOL_COMMON_H */
net/ethtool/info.c new file +155 -0

155 lines not on this page · raw message

net/ethtool/ioctl.c +5 -47

61 lines not on this page · raw message

net/ethtool/netlink.c +9 -0
index 082a9f2aa0a7..e27dec427414 100644
@@ -87,9 +87,11 @@ int ethnl_fill_dev(struct sk_buff *msg, struct net_device *dev, u16 attrtype)
 /* GET request helpers */
 
 extern const struct get_request_ops strset_request_ops;
+extern const struct get_request_ops info_request_ops;
 
 const struct get_request_ops *get_requests[__ETHNL_CMD_CNT] = {
 	[ETHNL_CMD_GET_STRSET]		= &strset_request_ops,
+	[ETHNL_CMD_GET_INFO]		= &info_request_ops,
 };
 
 static struct common_req_info *alloc_get_data(const struct get_request_ops *ops)
@@ -508,6 +510,13 @@ static const struct genl_ops ethtool_genl_ops[] = {
 		.dumpit	= ethnl_get_dumpit,
 		.done	= ethnl_get_done,
 	},
+	{
+		.cmd	= ETHNL_CMD_GET_INFO,
+		.doit	= ethnl_get_doit,
+		.start	= ethnl_get_start,
+		.dumpit	= ethnl_get_dumpit,
+		.done	= ethnl_get_done,
+	},
 };
 
 static const struct genl_multicast_group ethtool_nl_mcgrps[] = {
Signature · 1 line
2.20.1
#22 lore raw

RFC PATCH v3 12/21 ethtool: provide permanent hardware address in GET_INFO request

In reply to Michal Kubecek

Add information about permanent hadware address of a device (as provided by ETHTOOL_GPERMADDR ioctl command) in GET_INFO reply if ETH_INFO_IM_PERMADDR flag is set in the request.

There is no separate attribute for hardware address length as nla_len gives this information. The reply also provides address type (net_device::type).

---
 Documentation/networking/ethtool-netlink.txt |  9 ++++-
 include/uapi/linux/ethtool_netlink.h         | 12 +++++-
 net/ethtool/info.c                           | 39 ++++++++++++++++++++
 3 files changed, 58 insertions(+), 2 deletions(-)
Documentation/networking/ethtool-netlink.txt +8 -1
index b6999a2167e8..1e615e111262 100644
@@ -239,6 +239,9 @@ Kernel response contents:
         ETHA_DRVINFO_FWVERSION		(string)	firmware version
         ETHA_DRVINFO_BUSINFO		(string)	device bus address
         ETHA_DRVINFO_EROM_VER		(string)	expansion ROM version
+    ETHA_INFO_PERMADDR		(nested)
+        ETHA_PERMADDR_ADDRESS		(binary)	permanent HW address
+        ETHA_PERMADDR_TYPE		(u16)		dev->type
 
 The meaning of DRVINFO attributes follows the corresponding fields of
 ETHTOOL_GDRVINFO response. Second part with various counts and sizes is
@@ -246,6 +249,10 @@ omitted as these are not really needed (and if they are, they can be easily
 found by different means). Driver version is also omitted as it is rather
 misleading in most cases.
 
+There is no separate attribute for permanent address length as the length can
+be determined from attribute length (nla_len()). ETHA_PERMADDR_TYPE provides
+net_device::type value to give a hint about what kind of address device has.
+
 GET_INFO requests allow dumps.
 
 
@@ -288,7 +295,7 @@ ETHTOOL_PHYS_ID			n/a
 ETHTOOL_GSTATS			n/a
 ETHTOOL_GTSO			n/a
 ETHTOOL_STSO			n/a
-ETHTOOL_GPERMADDR		n/a
+ETHTOOL_GPERMADDR		ETHNL_CMD_GET_INFO
 ETHTOOL_GUFO			n/a
 ETHTOOL_SUFO			n/a
 ETHTOOL_GGSO			n/a
include/uapi/linux/ethtool_netlink.h +11 -1
index fdae12b6c6b6..fb756b6a8592 100644
@@ -153,8 +153,9 @@ enum {
 };
 
 #define ETH_INFO_IM_DRVINFO			0x01
+#define ETH_INFO_IM_PERMADDR			0x02
 
-#define ETH_INFO_IM_ALL				0x01
+#define ETH_INFO_IM_ALL				0x03
 
 enum {
 	ETHA_DRVINFO_UNSPEC,
@@ -167,6 +168,15 @@ enum {
 	ETHA_DRVINFO_MAX = (__ETHA_DRVINFO_CNT - 1)
 };
 
+enum {
+	ETHA_PERMADDR_UNSPEC,
+	ETHA_PERMADDR_ADDRESS,			/* binary */
+	ETHA_PERMADDR_TYPE,			/* u16 */
+
+	__ETHA_PERMADDR_CNT,
+	ETHA_PERMADDR_MAX = (__ETHA_PERMADDR_CNT - 1)
+};
+
 /* generic netlink info */
 #define ETHTOOL_GENL_NAME "ethtool"
 #define ETHTOOL_GENL_VERSION 1
net/ethtool/info.c +39 -0
index 1a2e78d238e3..05dbd87ebc41 100644
@@ -18,6 +18,7 @@ static const struct nla_policy get_info_policy[ETHA_INFO_MAX + 1] = {
 	[ETHA_INFO_INFOMASK]		= { .type = NLA_U32 },
 	[ETHA_INFO_COMPACT]		= { .type = NLA_FLAG },
 	[ETHA_INFO_DRVINFO]		= { .type = NLA_REJECT },
+	[ETHA_INFO_PERMADDR]		= { .type = NLA_REJECT },
 };
 
 static int parse_info(struct common_req_info *req_info, struct sk_buff *skb,
@@ -86,16 +87,29 @@ static int drvinfo_size(const struct ethtool_drvinfo *drvinfo)
 	return nla_total_size(len);
 }
 
+static int permaddr_size(const struct net_device *dev)
+{
+	int len = 0;
+
+	len += nla_total_size(dev->addr_len);
+	len += nla_total_size(sizeof(u16));
+
+	return nla_total_size(len);
+}
+
 static int info_size(const struct common_req_info *req_info)
 {
 	const struct info_data *data =
 		container_of(req_info, struct info_data, reqinfo_base);
+	const struct net_device *dev = data->repdata_base.dev;
 	u32 info_mask = data->repdata_base.info_mask;
 	int len = 0;
 
 	len += dev_ident_size();
 	if (info_mask & ETH_INFO_IM_DRVINFO)
 		len += drvinfo_size(&data->drvinfo);
+	if (info_mask & ETH_INFO_IM_PERMADDR)
+		len += permaddr_size(dev);
 
 	return len;
 }
@@ -124,6 +138,26 @@ static int fill_drvinfo(struct sk_buff *skb,
 	return ret;
 }
 
+static int fill_permaddr(struct sk_buff *skb, const struct net_device *dev)
+{
+	struct nlattr *nest = ethnl_nest_start(skb, ETHA_INFO_PERMADDR);
+	int ret;
+
+	if (!nest)
+		return -EMSGSIZE;
+	ret = -EMSGSIZE;
+	if (nla_put(skb, ETHA_PERMADDR_ADDRESS, dev->addr_len, dev->perm_addr))
+		goto err;
+	if (nla_put_u16(skb, ETHA_PERMADDR_TYPE, dev->type))
+		goto err;
+
+	nla_nest_end(skb, nest);
+	return 0;
+err:
+	nla_nest_cancel(skb, nest);
+	return ret;
+}
+
 static int fill_info(struct sk_buff *skb,
 		     const struct common_req_info *req_info)
 {
@@ -137,6 +171,11 @@ static int fill_info(struct sk_buff *skb,
 		if (ret < 0)
 			return ret;
 	}
+	if (info_mask & ETH_INFO_IM_PERMADDR) {
+		ret = fill_permaddr(skb, data->repdata_base.dev);
+		if (ret < 0)
+			return ret;
+	}
 
 	return 0;
 }
Signature · 1 line
2.20.1
#23 lore raw

Re: [RFC PATCH net-next v3 12/21] ethtool: provide permanent hardware address in GET_INFO request

Quoted 19 lines · Mon, Feb 18, 2019 at 07:22:24PM CET, [email protected] wrote:

Add information about permanent hadware address of a device (as provided by ETHTOOL_GPERMADDR ioctl command) in GET_INFO reply if ETH_INFO_IM_PERMADDR flag is set in the request.

There is no separate attribute for hardware address length as nla_len gives this information. The reply also provides address type (net_device::type).

---

Documentation/networking/ethtool-netlink.txt |  9 ++++-
include/uapi/linux/ethtool_netlink.h         | 12 +++++-
net/ethtool/info.c                           | 39 ++++++++++++++++++++
3 files changed, 58 insertions(+), 2 deletions(-)
Documentation/networking/ethtool-netlink.txt +0 -0
index b6999a2167e8..1e615e111262 100644

Documentation/networking/ethtool-netlink.txt Kernel response contents: · line 243

Quoted 5 lines
Documentation/networking/ethtool-netlink.txt +2 -0
@@ -239,6 +239,9 @@ Kernel response contents:
        ETHA_DRVINFO_FWVERSION		(string)	firmware version
        ETHA_DRVINFO_BUSINFO		(string)	device bus address
        ETHA_DRVINFO_EROM_VER		(string)	expansion ROM version
+    ETHA_INFO_PERMADDR		(nested)
+        ETHA_PERMADDR_ADDRESS		(binary)	permanent HW address

I think this is a nice example of thing that should not be exposed with ethtool but rather via rtnetlink, alongside with the actual hw address.

[...]

#24 lore raw

Re: [RFC PATCH net-next v3 12/21] ethtool: provide permanent hardware address in GET_INFO request

Quoted 29 lines · Jiri Pirko
Quoted 19 lines · Mon, Feb 18, 2019 at 07:22:24PM CET, [email protected] wrote:

Add information about permanent hadware address of a device (as provided by ETHTOOL_GPERMADDR ioctl command) in GET_INFO reply if ETH_INFO_IM_PERMADDR flag is set in the request.

There is no separate attribute for hardware address length as nla_len gives this information. The reply also provides address type (net_device::type).

---

Documentation/networking/ethtool-netlink.txt |  9 ++++-
include/uapi/linux/ethtool_netlink.h         | 12 +++++-
net/ethtool/info.c                           | 39 ++++++++++++++++++++
3 files changed, 58 insertions(+), 2 deletions(-)
Documentation/networking/ethtool-netlink.txt +0 -0
index b6999a2167e8..1e615e111262 100644

Documentation/networking/ethtool-netlink.txt Kernel response contents: · line 243

Quoted 5 lines
Documentation/networking/ethtool-netlink.txt +2 -0
@@ -239,6 +239,9 @@ Kernel response contents:
        ETHA_DRVINFO_FWVERSION		(string)	firmware version
        ETHA_DRVINFO_BUSINFO		(string)	device bus address
        ETHA_DRVINFO_EROM_VER		(string)	expansion ROM version
+    ETHA_INFO_PERMADDR		(nested)
+        ETHA_PERMADDR_ADDRESS		(binary)	permanent HW address

I think this is a nice example of thing that should not be exposed with ethtool but rather via rtnetlink, alongside with the actual hw address.

Quoted 1 line

[...]

I guess you are right. As we don't have to query the driver and just read the information from struct net_device, rtnetlink does indeed seem more appropriate.

Michal

#25 lore raw

RFC PATCH v3 13/21 ethtool: provide timestamping information in GET_INFO request

In reply to Michal Kubecek

Add timestamping information as provided by ETHTOOL_GET_TS_INFO ioctl command in GET_INFO reply if ETH_INFO_IM_TSINFO flag is set in the request.

Add constants for counts of HWTSTAMP_TX_* and HWTSTAM_FILTER_* constants and provide symbolic names for timestamping related values so that they can be retrieved in GET_STRSET and GET_INFO requests.

---
 Documentation/networking/ethtool-netlink.txt |  10 +-
 include/uapi/linux/ethtool.h                 |   6 +
 include/uapi/linux/ethtool_netlink.h         |  14 +-
 include/uapi/linux/net_tstamp.h              |  13 ++
 net/ethtool/common.c                         |  24 ++++
 net/ethtool/common.h                         |   2 +
 net/ethtool/info.c                           | 138 +++++++++++++++++++
 net/ethtool/ioctl.c                          |  20 +--
 net/ethtool/netlink.h                        |   9 ++
 net/ethtool/strset.c                         |  18 +++
 10 files changed, 234 insertions(+), 20 deletions(-)
Documentation/networking/ethtool-netlink.txt +9 -1
index 1e615e111262..c6c7475340e2 100644
@@ -242,6 +242,11 @@ Kernel response contents:
     ETHA_INFO_PERMADDR		(nested)
         ETHA_PERMADDR_ADDRESS		(binary)	permanent HW address
         ETHA_PERMADDR_TYPE		(u16)		dev->type
+    ETHA_INFO_TSINFO		(nested)	timestamping information
+        ETHA_TSINFO_TIMESTAMPING	(bitset)	supported flags
+        ETHA_TSINFO_PHC_INDEX		(u32)		associated PHC
+        ETHA_TSINFO_TX_TYPES		(bitset)	Tx types
+        ETHA_TSINFO_RX_FILTERS		(bitset)	Rx filters
 
 The meaning of DRVINFO attributes follows the corresponding fields of
 ETHTOOL_GDRVINFO response. Second part with various counts and sizes is
@@ -253,6 +258,9 @@ There is no separate attribute for permanent address length as the length can
 be determined from attribute length (nla_len()). ETHA_PERMADDR_TYPE provides
 net_device::type value to give a hint about what kind of address device has.
 
+ETHA_TSINFO_PHC_INDEX can be unsigned as there is no need for special value;
+if no PHC is associated, the attribute is not present.
+
 GET_INFO requests allow dumps.
 
 
@@ -328,7 +336,7 @@ ETHTOOL_SCHANNELS		n/a
 ETHTOOL_SET_DUMP		n/a
 ETHTOOL_GET_DUMP_FLAG		n/a
 ETHTOOL_GET_DUMP_DATA		n/a
-ETHTOOL_GET_TS_INFO		n/a
+ETHTOOL_GET_TS_INFO		ETHNL_CMD_GET_INFO
 ETHTOOL_GMODULEINFO		n/a
 ETHTOOL_GMODULEEEPROM		n/a
 ETHTOOL_GEEE			n/a
include/uapi/linux/ethtool.h +6 -0
index 9ea278961d80..1b58637d3a4d 100644
@@ -563,6 +563,9 @@ struct ethtool_pauseparam {
  * @ETH_SS_RSS_HASH_FUNCS: RSS hush function names
  * @ETH_SS_PHY_STATS: Statistic names, for use with %ETHTOOL_GPHYSTATS
  * @ETH_SS_PHY_TUNABLES: PHY tunable names
+ * @ETH_SS_TSTAMP_SOF: timestamping flag names
+ * @ETH_SS_TSTAMP_TX_TYPE: timestamping Tx type names
+ * @ETH_SS_TSTAMP_RX_FILTER: timestamping Rx filter names
  */
 enum ethtool_stringset {
 	ETH_SS_TEST		= 0,
@@ -574,6 +577,9 @@ enum ethtool_stringset {
 	ETH_SS_TUNABLES,
 	ETH_SS_PHY_STATS,
 	ETH_SS_PHY_TUNABLES,
+	ETH_SS_TSTAMP_SOF,
+	ETH_SS_TSTAMP_TX_TYPE,
+	ETH_SS_TSTAMP_RX_FILTER,
 
 	ETH_SS_COUNT
 };
include/uapi/linux/ethtool_netlink.h +13 -1
index fb756b6a8592..8ab2b7454e81 100644
@@ -154,8 +154,9 @@ enum {
 
 #define ETH_INFO_IM_DRVINFO			0x01
 #define ETH_INFO_IM_PERMADDR			0x02
+#define ETH_INFO_IM_TSINFO			0x04
 
-#define ETH_INFO_IM_ALL				0x03
+#define ETH_INFO_IM_ALL				0x07
 
 enum {
 	ETHA_DRVINFO_UNSPEC,
@@ -177,6 +178,17 @@ enum {
 	ETHA_PERMADDR_MAX = (__ETHA_PERMADDR_CNT - 1)
 };
 
+enum {
+	ETHA_TSINFO_UNSPEC,
+	ETHA_TSINFO_TIMESTAMPING,		/* bitset */
+	ETHA_TSINFO_PHC_INDEX,			/* u32 */
+	ETHA_TSINFO_TX_TYPES,			/* bitset */
+	ETHA_TSINFO_RX_FILTERS,			/* bitset */
+
+	__ETHA_TSINFO_CNT,
+	ETHA_TSINFO_MAX = (__ETHA_TSINFO_CNT - 1)
+};
+
 /* generic netlink info */
 #define ETHTOOL_GENL_NAME "ethtool"
 #define ETHTOOL_GENL_VERSION 1
include/uapi/linux/net_tstamp.h +13 -0
index e5b39721c6e4..e5b0472c4416 100644
@@ -30,6 +30,9 @@ enum {
 	SOF_TIMESTAMPING_OPT_STATS = (1<<12),
 	SOF_TIMESTAMPING_OPT_PKTINFO = (1<<13),
 	SOF_TIMESTAMPING_OPT_TX_SWHW = (1<<14),
+	/* when adding a flag, please update so_timestamping_labels array
+	 * in net/ethtool/info.c
+	 */
 
 	SOF_TIMESTAMPING_LAST = SOF_TIMESTAMPING_OPT_TX_SWHW,
 	SOF_TIMESTAMPING_MASK = (SOF_TIMESTAMPING_LAST - 1) |
@@ -90,6 +93,11 @@ enum hwtstamp_tx_types {
 	 * queue.
 	 */
 	HWTSTAMP_TX_ONESTEP_SYNC,
+	/* when adding a value, please update tstamp_tx_type_labels array
+	 * in net/ethtool/info.c
+	 */
+
+	HWTSTAMP_TX_LAST = HWTSTAMP_TX_ONESTEP_SYNC
 };
 
 /* possible values for hwtstamp_config->rx_filter */
@@ -132,6 +140,11 @@ enum hwtstamp_rx_filters {
 
 	/* NTP, UDP, all versions and packet modes */
 	HWTSTAMP_FILTER_NTP_ALL,
+	/* when adding a value, please update tstamp_rx_filter_labels array
+	 * in net/ethtool/info.c
+	 */
+
+	HWTSTAMP_FILTER_LAST = HWTSTAMP_FILTER_NTP_ALL
 };
 
 /* SCM_TIMESTAMPING_PKTINFO control message */
net/ethtool/common.c +24 -0
index e0bd7c6c5874..4616816861cc 100644
@@ -1,6 +1,8 @@
 // SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note
 
 #include <linux/rtnetlink.h>
+#include <linux/phy.h>
+#include <linux/net_tstamp.h>
 #include <net/devlink.h>
 #include "common.h"
 
@@ -135,3 +137,25 @@ int __ethtool_get_drvinfo(struct net_device *dev, struct ethtool_drvinfo *info)
 
 	return 0;
 }
+
+int __ethtool_get_ts_info(struct net_device *dev, struct ethtool_ts_info *info)
+{
+	const struct ethtool_ops *ops = dev->ethtool_ops;
+	struct phy_device *phydev = dev->phydev;
+	int err = 0;
+
+	memset(info, 0, sizeof(*info));
+	info->cmd = ETHTOOL_GET_TS_INFO;
+
+	if (phydev && phydev->drv && phydev->drv->ts_info) {
+		err = phydev->drv->ts_info(phydev, info);
+	} else if (ops->get_ts_info) {
+		err = ops->get_ts_info(dev, info);
+	} else {
+		info->so_timestamping = SOF_TIMESTAMPING_RX_SOFTWARE |
+					SOF_TIMESTAMPING_SOFTWARE;
+		info->phc_index = -1;
+	}
+
+	return err;
+}
net/ethtool/common.h +2 -0
index e87e58b3a274..02cbee79da35 100644
@@ -16,4 +16,6 @@ extern const char
 phy_tunable_strings[__ETHTOOL_PHY_TUNABLE_COUNT][ETH_GSTRING_LEN];
 
 int __ethtool_get_drvinfo(struct net_device *dev, struct ethtool_drvinfo *info);
+int __ethtool_get_ts_info(struct net_device *dev, struct ethtool_ts_info *info);
+
 #endif /* _ETHTOOL_COMMON_H */
net/ethtool/info.c +138 -0

189 lines not on this page · raw message

net/ethtool/ioctl.c +2 -18
index c883239001a4..0837849156d3 100644
@@ -2034,28 +2034,12 @@ static int ethtool_get_dump_data(struct net_device *dev,
 
 static int ethtool_get_ts_info(struct net_device *dev, void __user *useraddr)
 {
-	int err = 0;
+	int err;
 	struct ethtool_ts_info info;
-	const struct ethtool_ops *ops = dev->ethtool_ops;
-	struct phy_device *phydev = dev->phydev;
-
-	memset(&info, 0, sizeof(info));
-	info.cmd = ETHTOOL_GET_TS_INFO;
-
-	if (phydev && phydev->drv && phydev->drv->ts_info) {
-		err = phydev->drv->ts_info(phydev, &info);
-	} else if (ops->get_ts_info) {
-		err = ops->get_ts_info(dev, &info);
-	} else {
-		info.so_timestamping =
-			SOF_TIMESTAMPING_RX_SOFTWARE |
-			SOF_TIMESTAMPING_SOFTWARE;
-		info.phc_index = -1;
-	}
 
+	err = __ethtool_get_ts_info(dev, &info);
 	if (err)
 		return err;
-
 	if (copy_to_user(useraddr, &info, sizeof(info)))
 		err = -EFAULT;
 
net/ethtool/netlink.h +9 -0
index 7141ec71a6d3..82a4c1f398d8 100644
@@ -7,14 +7,23 @@
 #include <linux/netdevice.h>
 #include <net/genetlink.h>
 #include <net/sock.h>
+#include <linux/net_tstamp.h>
 
 #define ETHNL_SET_ERRMSG(info, msg) \
 	do { if (info) GENL_SET_ERR_MSG(info, msg); } while (0)
 
+#define __SOF_TIMESTAMPING_COUNT (const_ilog2(SOF_TIMESTAMPING_LAST) + 1)
+#define __HWTSTAMP_TX_COUNT (HWTSTAMP_TX_LAST + 1)
+#define __HWTSTAMP_FILTER_COUNT (HWTSTAMP_FILTER_LAST + 1)
+
 extern u32 ethnl_bcast_seq;
 
 extern struct genl_family ethtool_genl_family;
 
+extern const char *const so_timestamping_labels[];
+extern const char *const tstamp_tx_type_labels[];
+extern const char *const tstamp_rx_filter_labels[];
+
 struct net_device *ethnl_dev_get(struct genl_info *info, struct nlattr *nest);
 int ethnl_fill_dev(struct sk_buff *msg, struct net_device *dev, u16 attrtype);
 
net/ethtool/strset.c +18 -0
index a7d0ec2865fb..5c74498d9c72 100644
@@ -67,6 +67,24 @@ static const struct strset_info info_template[] = {
 		.count		= ARRAY_SIZE(phy_tunable_strings),
 		.data		= { .legacy = phy_tunable_strings },
 	},
+	[ETH_SS_TSTAMP_SOF] = {
+		.type		= ETH_SS_TYPE_SIMPLE,
+		.per_dev	= false,
+		.count		= __SOF_TIMESTAMPING_COUNT,
+		.data		= { .simple = so_timestamping_labels },
+	},
+	[ETH_SS_TSTAMP_TX_TYPE] = {
+		.type		= ETH_SS_TYPE_SIMPLE,
+		.per_dev	= false,
+		.count		= __HWTSTAMP_TX_COUNT,
+		.data		= { .simple = tstamp_tx_type_labels },
+	},
+	[ETH_SS_TSTAMP_RX_FILTER] = {
+		.type		= ETH_SS_TYPE_SIMPLE,
+		.per_dev	= false,
+		.count		= __HWTSTAMP_FILTER_COUNT,
+		.data		= { .simple = tstamp_rx_filter_labels },
+	},
 };
 
 struct strset_data {
Signature · 1 line
2.20.1
#26 lore raw

Re: [RFC PATCH net-next v3 13/21] ethtool: provide timestamping information in GET_INFO request

Quoted 6 lines · Michal Kubecek

Add timestamping information as provided by ETHTOOL_GET_TS_INFO ioctl command in GET_INFO reply if ETH_INFO_IM_TSINFO flag is set in the request.

Add constants for counts of HWTSTAMP_TX_* and HWTSTAM_FILTER_* constants and provide symbolic names for timestamping related values so that they can be retrieved in GET_STRSET and GET_INFO requests.

What's the reason for providing the symbolic names?

Quoted 1 line
#27 lore raw

Re: [RFC PATCH net-next v3 13/21] ethtool: provide timestamping information in GET_INFO request

Quoted 9 lines · Jakub Kicinski
Quoted 6 lines · Michal Kubecek

Add timestamping information as provided by ETHTOOL_GET_TS_INFO ioctl command in GET_INFO reply if ETH_INFO_IM_TSINFO flag is set in the request.

Add constants for counts of HWTSTAMP_TX_* and HWTSTAM_FILTER_* constants and provide symbolic names for timestamping related values so that they can be retrieved in GET_STRSET and GET_INFO requests.

What's the reason for providing the symbolic names?

One of the the goals I had was to reduce the need to keep the lists of possible values in sync between kernel and userspace ethtool and other users of the interface so that when a new value is added, we don't have to update all userspace tools to be able to use or present it.

This already works in ethtool for some newer commands (e.g. features) and obviously for those where the list of available options depends on the device (e.g. private flags or statistics). I would like to extend the principle also to older commands and new ones which do not work like this (e.g. device reset).

Michal

#28 lore raw

Re: [RFC PATCH net-next v3 13/21] ethtool: provide timestamping information in GET_INFO request

Quoted 16 lines · Michal Kubecek
Quoted 9 lines · Jakub Kicinski
Quoted 6 lines · Michal Kubecek

Add timestamping information as provided by ETHTOOL_GET_TS_INFO ioctl command in GET_INFO reply if ETH_INFO_IM_TSINFO flag is set in the request.

Add constants for counts of HWTSTAMP_TX_* and HWTSTAM_FILTER_* constants and provide symbolic names for timestamping related values so that they can be retrieved in GET_STRSET and GET_INFO requests.

What's the reason for providing the symbolic names?

One of the the goals I had was to reduce the need to keep the lists of possible values in sync between kernel and userspace ethtool and other users of the interface so that when a new value is added, we don't have to update all userspace tools to be able to use or present it.

Quoted 5 lines

This already works in ethtool for some newer commands (e.g. features) and obviously for those where the list of available options depends on the device (e.g. private flags or statistics). I would like to extend the principle also to older commands and new ones which do not work like this (e.g. device reset).

Let me try to argue that's the wrong direction. People should learn to update their user space tooling if they want access to new features. In my (limited) experience trying to solve forward compatibility leads to short term gains, and long term warts in the APIs and increased maintenance burden in the kernel.

#29 lore raw

RFC PATCH v3 14/21 ethtool: provide link mode names as a string set

In reply to Michal Kubecek

Add table of ethernet link mode names and make it available as a string set to userspace GET_STRSET requests.

---
 include/uapi/linux/ethtool.h |  2 ++
 net/ethtool/netlink.c        | 58 ++++++++++++++++++++++++++++++++++++
 net/ethtool/netlink.h        |  1 +
 net/ethtool/strset.c         |  6 ++++
 4 files changed, 67 insertions(+)
include/uapi/linux/ethtool.h +2 -0
index 1b58637d3a4d..ba96a691bfd4 100644
@@ -566,6 +566,7 @@ struct ethtool_pauseparam {
  * @ETH_SS_TSTAMP_SOF: timestamping flag names
  * @ETH_SS_TSTAMP_TX_TYPE: timestamping Tx type names
  * @ETH_SS_TSTAMP_RX_FILTER: timestamping Rx filter names
+ * @ETH_SS_LINK_MODES: link mode names
  */
 enum ethtool_stringset {
 	ETH_SS_TEST		= 0,
@@ -580,6 +581,7 @@ enum ethtool_stringset {
 	ETH_SS_TSTAMP_SOF,
 	ETH_SS_TSTAMP_TX_TYPE,
 	ETH_SS_TSTAMP_RX_FILTER,
+	ETH_SS_LINK_MODES,
 
 	ETH_SS_COUNT
 };
net/ethtool/netlink.c +58 -0

70 lines not on this page · raw message

net/ethtool/netlink.h +1 -0
index 82a4c1f398d8..800ea57ab0de 100644
@@ -23,6 +23,7 @@ extern struct genl_family ethtool_genl_family;
 extern const char *const so_timestamping_labels[];
 extern const char *const tstamp_tx_type_labels[];
 extern const char *const tstamp_rx_filter_labels[];
+extern const char *const link_mode_names[];
 
 struct net_device *ethnl_dev_get(struct genl_info *info, struct nlattr *nest);
 int ethnl_fill_dev(struct sk_buff *msg, struct net_device *dev, u16 attrtype);
net/ethtool/strset.c +6 -0
index 5c74498d9c72..dd87d7db8b61 100644
@@ -85,6 +85,12 @@ static const struct strset_info info_template[] = {
 		.count		= __HWTSTAMP_FILTER_COUNT,
 		.data		= { .simple = tstamp_rx_filter_labels },
 	},
+	[ETH_SS_LINK_MODES] = {
+		.type		= ETH_SS_TYPE_SIMPLE,
+		.per_dev	= false,
+		.count		= __ETHTOOL_LINK_MODE_MASK_NBITS,
+		.data		= { .simple = link_mode_names },
+	},
 };
 
 struct strset_data {
Signature · 1 line
2.20.1
#30 lore raw

Re: [RFC PATCH net-next v3 14/21] ethtool: provide link mode names as a string set

Quoted 5 lines · Michal Kubecek

Add table of ethernet link mode names and make it available as a string set to userspace GET_STRSET requests.

---

[snip]

Quoted 2 lines

+const char *const link_mode_names[] = {

Maybe you can define a macro (totally untested) to build the table an avoid some of the repetition, something like:

#define ETHTOOL_LINK_NAME(speed, duplex) \
	[ETHTOOL_LINK_MODE_##speed_##duplex_BIT]	= stringify(speed ## "/" ##

duplex)

Signature · 1 line
Florian
#31 lore raw

Re: [RFC PATCH net-next v3 14/21] ethtool: provide link mode names as a string set

Quoted 8 lines · Florian Fainelli
Quoted 1 line

+const char *const link_mode_names[] = {

Maybe you can define a macro (totally untested) to build the table an avoid some of the repetition, something like:

#define ETHTOOL_LINK_NAME(speed, duplex) \
	[ETHTOOL_LINK_MODE_##speed_##duplex_BIT]	= stringify(speed ## "/" ##

duplex)

Thanks for the tip, that should work for most of the modes.

Michal

#32 lore raw

RFC PATCH v3 15/21 ethtool: provide link settings and link modes in GET_SETTINGS request

In reply to Michal Kubecek

Implement GET_SETTINGS netlink request to get link settings and link mode information provided by ETHTOOL_GLINKSETTINGS ioctl command.

The information is divided into two parts: supported, advertised and peer advertised link modes when ETH_SETTINGS_IM_LINKMODES flag is set in the request and other settings when ETH_SETTINGS_IM_LINKINFO is set.

---
 Documentation/networking/ethtool-netlink.txt |  49 +++-
 include/linux/ethtool_netlink.h              |   3 +
 include/uapi/linux/ethtool_netlink.h         |  37 +++
 net/ethtool/Makefile                         |   2 +-
 net/ethtool/common.c                         |  48 ++++
 net/ethtool/common.h                         |   4 +
 net/ethtool/ioctl.c                          |  48 ----
 net/ethtool/netlink.c                        |   9 +
 net/ethtool/settings.c                       | 265 +++++++++++++++++++
 9 files changed, 414 insertions(+), 51 deletions(-)
 create mode 100644 net/ethtool/settings.c
Documentation/networking/ethtool-netlink.txt +47 -2
index c6c7475340e2..0ea7d89c6052 100644
@@ -130,6 +130,8 @@ List of message types
     ETHNL_CMD_SET_STRSET		response only
     ETHNL_CMD_GET_INFO
     ETHNL_CMD_SET_INFO			response only
+    ETHNL_CMD_GET_SETTINGS
+    ETHNL_CMD_SET_SETTINGS		response only (for now)
 
 All constants use ETHNL_CMD_ prefix, usually followed by "GET", "SET" or "ACT"
 to indicate the type.
@@ -264,6 +266,49 @@ if no PHC is associated, the attribute is not present.
 GET_INFO requests allow dumps.
 
 
+GET_SETTINGS
+------------
+
+GET_SETTINGS request retrieves information provided by ETHTOOL_GLINKSETTINGS,
+ETHTOOL_GWOL, ETHTOOL_GMSGLVL and ETHTOOL_GLINK ioctl requests. The request
+doesn't use any attributes.
+
+Request attributes:
+
+    ETHA_SETTINGS_DEV		(nested)	device identification
+    ETHA_SETTINGS_INFOMASK	(u32)		info mask
+    ETHA_SETTINGS_COMPACT	(flag)		request compact bitsets
+
+Info mask bits meaning:
+
+    ETH_SETTINGS_IM_LINKINFO		link_ksettings except link modes
+    ETH_SETTINGS_IM_LINKMODES		link modes from link_ksettings
+
+Response contents:
+
+    ETHA_SETTINGS_DEV		(nested)	device identification
+    ETHA_SETTINGS_LINK_INFO	(nested)	link settings
+        ETHA_LINKINFO_SPEED		(u32)		link speed (Mb/s)
+        ETHA_LINKINFO_DUPLEX		(u8)		duplex mode
+        ETHA_LINKINFO_PORT		(u8)		physical port
+        ETHA_LINKINFO_PHYADDR		(u8)		MDIO address of phy
+        ETHA_LINKINFO_AUTONEG		(u8)		autoneotiation status
+        ETHA_LINKINFO_TP_MDIX		(u8)		MDI(-X) status
+        ETHA_LINKINFO_TP_MDIX_CTRL	(u8)		MDI(-X) control
+        ETHA_LINKINFO_TRANSCEIVER	(u8)		transceiver
+    ETHA_SETTINGS_LINK_MODES	(bitset)	device link modes
+    ETHA_SETTINGS_PEER_MODES	(bitset)	link partner link modes
+
+Most of the attributes and their values have the same meaning as matching
+members of the corresponding ioctl structures. For ETHA_SETTINGS_LINK_MODES,
+value represents advertised modes and mask represents supported modes.
+ETHA_SETTINGS_PEER_MODES in the reply is a bit list.
+
+GET_SETTINGS requests allow dumps and messages in the same format as response
+to them are broadcasted as notifications on change of these settings using
+netlink or ioctl ethtool interface.
+
+
 Request translation
 -------------------
 
@@ -273,7 +318,7 @@ have their netlink replacement yet.
 
 ioctl command			netlink command
 ---------------------------------------------------------------------
-ETHTOOL_GSET			n/a
+ETHTOOL_GSET			ETHNL_CMD_GET_SETTINGS
 ETHTOOL_SSET			n/a
 ETHTOOL_GDRVINFO		ETHNL_CMD_GET_INFO
 ETHTOOL_GREGS			n/a
@@ -347,7 +392,7 @@ ETHTOOL_GTUNABLE		n/a
 ETHTOOL_STUNABLE		n/a
 ETHTOOL_GPHYSTATS		n/a
 ETHTOOL_PERQUEUE		n/a
-ETHTOOL_GLINKSETTINGS		n/a
+ETHTOOL_GLINKSETTINGS		ETHNL_CMD_GET_SETTINGS
 ETHTOOL_SLINKSETTINGS		n/a
 ETHTOOL_PHY_GTUNABLE		n/a
 ETHTOOL_PHY_STUNABLE		n/a
include/linux/ethtool_netlink.h +3 -0
index 2a15e64a16f3..e770e6e9acca 100644
@@ -7,6 +7,9 @@
 #include <linux/ethtool.h>
 #include <linux/netdevice.h>
 
+#define __ETHTOOL_LINK_MODE_MASK_NWORDS \
+	DIV_ROUND_UP(__ETHTOOL_LINK_MODE_MASK_NBITS, 32)
+
 enum ethtool_multicast_groups {
 	ETHNL_MCGRP_MONITOR,
 };
include/uapi/linux/ethtool_netlink.h +37 -0
index 8ab2b7454e81..4e1fa4a06aac 100644
@@ -12,6 +12,8 @@ enum {
 	ETHNL_CMD_SET_STRSET,		/* only for reply */
 	ETHNL_CMD_GET_INFO,
 	ETHNL_CMD_SET_INFO,		/* only for reply */
+	ETHNL_CMD_GET_SETTINGS,
+	ETHNL_CMD_SET_SETTINGS,
 
 	__ETHNL_CMD_CNT,
 	ETHNL_CMD_MAX = (__ETHNL_CMD_CNT - 1)
@@ -189,6 +191,41 @@ enum {
 	ETHA_TSINFO_MAX = (__ETHA_TSINFO_CNT - 1)
 };
 
+/* GET_SETTINGS / SET_SETTINGS */
+
+enum {
+	ETHA_SETTINGS_UNSPEC,
+	ETHA_SETTINGS_DEV,			/* nest - ETHA_DEV_* */
+	ETHA_SETTINGS_INFOMASK,			/* u32 */
+	ETHA_SETTINGS_COMPACT,			/* flag */
+	ETHA_SETTINGS_LINK_INFO,		/* nested */
+	ETHA_SETTINGS_LINK_MODES,		/* bitset */
+	ETHA_SETTINGS_PEER_MODES,		/* bitset */
+
+	__ETHA_SETTINGS_CNT,
+	ETHA_SETTINGS_MAX = (__ETHA_SETTINGS_CNT - 1)
+};
+
+#define ETH_SETTINGS_IM_LINKINFO		0x01
+#define ETH_SETTINGS_IM_LINKMODES		0x02
+
+#define ETH_SETTINGS_IM_ALL			0x03
+
+enum {
+	ETHA_LINKINFO_UNSPEC,
+	ETHA_LINKINFO_SPEED,			/* u32 */
+	ETHA_LINKINFO_DUPLEX,			/* u8 */
+	ETHA_LINKINFO_PORT,			/* u8 */
+	ETHA_LINKINFO_PHYADDR,			/* u8 */
+	ETHA_LINKINFO_AUTONEG,			/* u8 */
+	ETHA_LINKINFO_TP_MDIX,			/* u8 */
+	ETHA_LINKINFO_TP_MDIX_CTRL,		/* u8 */
+	ETHA_LINKINFO_TRANSCEIVER,		/* u8 */
+
+	__ETHA_LINKINFO_CNT,
+	ETHA_LINKINFO_MAX = (__ETHA_LINKINFO_CNT - 1)
+};
+
 /* generic netlink info */
 #define ETHTOOL_GENL_NAME "ethtool"
 #define ETHTOOL_GENL_VERSION 1
net/ethtool/Makefile +1 -1
index 96d41dc45d4f..6a7a182e1568 100644
@@ -4,4 +4,4 @@ obj-y				+= ioctl.o common.o
 
 obj-$(CONFIG_ETHTOOL_NETLINK)	+= ethtool_nl.o
 
-ethtool_nl-y	:= netlink.o bitset.o strset.o info.o
+ethtool_nl-y	:= netlink.o bitset.o strset.o info.o settings.o
net/ethtool/common.c +48 -0

51 lines not on this page · raw message

net/ethtool/common.h +4 -0
index 02cbee79da35..7a3e0b10e69a 100644
@@ -18,4 +18,8 @@ phy_tunable_strings[__ETHTOOL_PHY_TUNABLE_COUNT][ETH_GSTRING_LEN];
 int __ethtool_get_drvinfo(struct net_device *dev, struct ethtool_drvinfo *info);
 int __ethtool_get_ts_info(struct net_device *dev, struct ethtool_ts_info *info);
 
+bool convert_legacy_settings_to_link_ksettings(
+	struct ethtool_link_ksettings *link_ksettings,
+	const struct ethtool_cmd *legacy_settings);
+
 #endif /* _ETHTOOL_COMMON_H */
net/ethtool/ioctl.c +0 -48

54 lines not on this page · raw message

net/ethtool/netlink.c +9 -0
index 1ff6696ad716..5166b0c28288 100644
@@ -143,10 +143,12 @@ int ethnl_fill_dev(struct sk_buff *msg, struct net_device *dev, u16 attrtype)
 
 extern const struct get_request_ops strset_request_ops;
 extern const struct get_request_ops info_request_ops;
+extern const struct get_request_ops settings_request_ops;
 
 const struct get_request_ops *get_requests[__ETHNL_CMD_CNT] = {
 	[ETHNL_CMD_GET_STRSET]		= &strset_request_ops,
 	[ETHNL_CMD_GET_INFO]		= &info_request_ops,
+	[ETHNL_CMD_GET_SETTINGS]	= &settings_request_ops,
 };
 
 static struct common_req_info *alloc_get_data(const struct get_request_ops *ops)
@@ -572,6 +574,13 @@ static const struct genl_ops ethtool_genl_ops[] = {
 		.dumpit	= ethnl_get_dumpit,
 		.done	= ethnl_get_done,
 	},
+	{
+		.cmd	= ETHNL_CMD_GET_SETTINGS,
+		.doit	= ethnl_get_doit,
+		.start	= ethnl_get_start,
+		.dumpit	= ethnl_get_dumpit,
+		.done	= ethnl_get_done,
+	},
 };
 
 static const struct genl_multicast_group ethtool_nl_mcgrps[] = {
net/ethtool/settings.c new file +265 -0

265 lines not on this page · raw message

Signature · 1 line
2.20.1
#33 lore raw

Re: [RFC PATCH net-next v3 15/21] ethtool: provide link settings and link modes in GET_SETTINGS request

Quoted 9 lines · Michal Kubecek

Implement GET_SETTINGS netlink request to get link settings and link mode information provided by ETHTOOL_GLINKSETTINGS ioctl command.

The information is divided into two parts: supported, advertised and peer advertised link modes when ETH_SETTINGS_IM_LINKMODES flag is set in the request and other settings when ETH_SETTINGS_IM_LINKINFO is set.

---

[snip]

include/uapi/linux/ethtool_netlink.h enum { · line 212

Quoted 4 lines
include/uapi/linux/ethtool_netlink.h +4 -0
+#define ETH_SETTINGS_IM_LINKINFO		0x01
+#define ETH_SETTINGS_IM_LINKMODES		0x02
+
+#define ETH_SETTINGS_IM_ALL			0x03

You could define ETH_SETTINGS_IM_ALL as:

#define ETH_SETTING_IM_ALL \
(ETH_SETTINGS_IM_LINKINFO |
ETH_SETTINGS_IM_LINMODES)

that would scale better IMHO, especially given that you have to keep bumping that mask with new bits in subsequent patches.

[snip]

net/ethtool/settings.c line 53

Quoted 6 lines
net/ethtool/settings.c new file +6 -0
+	if (tb[ETHA_SETTINGS_INFOMASK])
+		req_info->req_mask = nla_get_u32(tb[ETHA_SETTINGS_INFOMASK]);
+	if (tb[ETHA_SETTINGS_COMPACT])
+		req_info->compact = true;
+	if (req_info->req_mask == 0)
+		req_info->req_mask = ETH_SETTINGS_IM_ALL;

What if userland is newer than the kernel and specifies a req_mask with bits set that you don't support? Should not you always do an & ETH_SETTINGS_IM_ALL here?

[snip]

Signature · 1 line
Florian
#34 lore raw

Re: [RFC PATCH net-next v3 15/21] ethtool: provide link settings and link modes in GET_SETTINGS request

Quoted 8 lines · Florian Fainelli

include/uapi/linux/ethtool_netlink.h enum { · line 212

Quoted 4 lines · Michal Kubecek
include/uapi/linux/ethtool_netlink.h +4 -0
+#define ETH_SETTINGS_IM_LINKINFO		0x01
+#define ETH_SETTINGS_IM_LINKMODES		0x02
+
+#define ETH_SETTINGS_IM_ALL			0x03

You could define ETH_SETTINGS_IM_ALL as:

Quoted 6 lines

#define ETH_SETTING_IM_ALL \
(ETH_SETTINGS_IM_LINKINFO |
ETH_SETTINGS_IM_LINMODES)

that would scale better IMHO, especially given that you have to keep bumping that mask with new bits in subsequent patches.

I'm considering going even further and using something similar to what is used for NETIF_F_* constants so that the *_ALL value would be calculated automatically. But I'm not sure if it's not too fancy for a uapi header file.

Quoted 10 lines

net/ethtool/settings.c line 53

Quoted 6 lines
net/ethtool/settings.c new file +6 -0
+	if (tb[ETHA_SETTINGS_INFOMASK])
+		req_info->req_mask = nla_get_u32(tb[ETHA_SETTINGS_INFOMASK]);
+	if (tb[ETHA_SETTINGS_COMPACT])
+		req_info->compact = true;
+	if (req_info->req_mask == 0)
+		req_info->req_mask = ETH_SETTINGS_IM_ALL;

What if userland is newer than the kernel and specifies a req_mask with bits set that you don't support? Should not you always do an & ETH_SETTINGS_IM_ALL here?

In that case only known bits would be handled and the check at the end of prepare_info() would add a warning to extack that part of the information couldn't be provided (same as if some of the recognized parts didn't have necessary ethtool_ops handlers or if they failed).

Michal

#35 lore raw

Re: [RFC PATCH net-next v3 15/21] ethtool: provide link settings and link modes in GET_SETTINGS request

Quoted 13 lines · Michal Kubecek
Quoted 12 lines · Florian Fainelli

include/uapi/linux/ethtool_netlink.h enum { · line 212

Quoted 4 lines · Michal Kubecek
include/uapi/linux/ethtool_netlink.h +4 -0
+#define ETH_SETTINGS_IM_LINKINFO		0x01
+#define ETH_SETTINGS_IM_LINKMODES		0x02
+
+#define ETH_SETTINGS_IM_ALL			0x03

You could define ETH_SETTINGS_IM_ALL as:

#define ETH_SETTING_IM_ALL \
(ETH_SETTINGS_IM_LINKINFO |
ETH_SETTINGS_IM_LINMODES)

Quoted 7 lines
Quoted 2 lines

that would scale better IMHO, especially given that you have to keep bumping that mask with new bits in subsequent patches.

I'm considering going even further and using something similar to what is used for NETIF_F_* constants so that the *_ALL value would be calculated automatically. But I'm not sure if it's not too fancy for a uapi header file.

Adding new netdev features still requires defining two constants: one in the enumeration, and one that resolves the bit to bitmask constant, so this would amount to the same possible mistakes/errors being made here by changing two lines.

Quoted 12 lines
Quoted 11 lines

net/ethtool/settings.c line 53

Quoted 7 lines
net/ethtool/settings.c new file +6 -0
+	if (tb[ETHA_SETTINGS_INFOMASK])
+		req_info->req_mask = nla_get_u32(tb[ETHA_SETTINGS_INFOMASK]);
+	if (tb[ETHA_SETTINGS_COMPACT])
+		req_info->compact = true;
+	if (req_info->req_mask == 0)
+		req_info->req_mask = ETH_SETTINGS_IM_ALL;

What if userland is newer than the kernel and specifies a req_mask with bits set that you don't support? Should not you always do an & ETH_SETTINGS_IM_ALL here?

Quoted 4 lines

In that case only known bits would be handled and the check at the end of prepare_info() would add a warning to extack that part of the information couldn't be provided (same as if some of the recognized parts didn't have necessary ethtool_ops handlers or if they failed).

I guess that is fair, I was just wondering if it made sense for the kernel to report that there is one particular bitmask of settings that it does not support at all and report that through netlink extended ack, as opposed to silently not processing the bits it does not know.

Signature · 1 line
Florian
#36 lore raw

RFC PATCH v3 16/21 ethtool: provide WoL information in GET_SETTINGS request

In reply to Michal Kubecek

Add information about supported and enabled wake on LAN modes into the GET_SETTINGS reply when ETH_SETTINGS_IM_WOLINFO flag is set in the request.

The GET_SETTINGS request can be still sent by unprivileged users but in such case the SecureOn password (if any) is not included in the reply.

---
 Documentation/networking/ethtool-netlink.txt | 13 ++++-
 include/uapi/linux/ethtool_netlink.h         | 13 ++++-
 net/ethtool/common.c                         | 10 ++++
 net/ethtool/common.h                         |  1 +
 net/ethtool/ioctl.c                          |  8 +--
 net/ethtool/settings.c                       | 61 ++++++++++++++++++++
 6 files changed, 100 insertions(+), 6 deletions(-)
Documentation/networking/ethtool-netlink.txt +12 -1
index 0ea7d89c6052..913df35cb762 100644
@@ -283,6 +283,7 @@ Info mask bits meaning:
 
     ETH_SETTINGS_IM_LINKINFO		link_ksettings except link modes
     ETH_SETTINGS_IM_LINKMODES		link modes from link_ksettings
+    ETH_SETTINGS_IM_WOLINFO		struct ethtool_wolinfo
 
 Response contents:
 
@@ -298,12 +299,22 @@ Response contents:
         ETHA_LINKINFO_TRANSCEIVER	(u8)		transceiver
     ETHA_SETTINGS_LINK_MODES	(bitset)	device link modes
     ETHA_SETTINGS_PEER_MODES	(bitset)	link partner link modes
+    ETHA_SETTINGS_WOL		(nested)	wake on LAN settings
+        ETHA_WOL_MODES			(bitfield32)	wake on LAN modes
+        ETHA_WOL_SOPASS			(binary)	SecureOn(tm) password
 
 Most of the attributes and their values have the same meaning as matching
 members of the corresponding ioctl structures. For ETHA_SETTINGS_LINK_MODES,
 value represents advertised modes and mask represents supported modes.
 ETHA_SETTINGS_PEER_MODES in the reply is a bit list.
 
+For ETHA_WOL_MODES, selector reports wake on LAN modes supported by the
+device and value enabled modes.
+
+GET_SETTINGS request is allowed for unprivileged user but ETHA_SETTINGS_SOPASS
+is only provided by kernel in response to privileged (netns CAP_NET_ADMIN)
+requests.
+
 GET_SETTINGS requests allow dumps and messages in the same format as response
 to them are broadcasted as notifications on change of these settings using
 netlink or ioctl ethtool interface.
@@ -322,7 +333,7 @@ ETHTOOL_GSET			ETHNL_CMD_GET_SETTINGS
 ETHTOOL_SSET			n/a
 ETHTOOL_GDRVINFO		ETHNL_CMD_GET_INFO
 ETHTOOL_GREGS			n/a
-ETHTOOL_GWOL			n/a
+ETHTOOL_GWOL			ETHNL_CMD_GET_SETTINGS
 ETHTOOL_SWOL			n/a
 ETHTOOL_GMSGLVL			n/a
 ETHTOOL_SMSGLVL			n/a
include/uapi/linux/ethtool_netlink.h +12 -1
index 4e1fa4a06aac..ce9d6b48f814 100644
@@ -201,6 +201,7 @@ enum {
 	ETHA_SETTINGS_LINK_INFO,		/* nested */
 	ETHA_SETTINGS_LINK_MODES,		/* bitset */
 	ETHA_SETTINGS_PEER_MODES,		/* bitset */
+	ETHA_SETTINGS_WOL,			/* nested */
 
 	__ETHA_SETTINGS_CNT,
 	ETHA_SETTINGS_MAX = (__ETHA_SETTINGS_CNT - 1)
@@ -208,8 +209,9 @@ enum {
 
 #define ETH_SETTINGS_IM_LINKINFO		0x01
 #define ETH_SETTINGS_IM_LINKMODES		0x02
+#define ETH_SETTINGS_IM_WOLINFO			0x04
 
-#define ETH_SETTINGS_IM_ALL			0x03
+#define ETH_SETTINGS_IM_ALL			0x07
 
 enum {
 	ETHA_LINKINFO_UNSPEC,
@@ -226,6 +228,15 @@ enum {
 	ETHA_LINKINFO_MAX = (__ETHA_LINKINFO_CNT - 1)
 };
 
+enum {
+	ETHA_WOL_UNSPEC,
+	ETHA_WOL_MODES,				/* bitfield32 */
+	ETHA_WOL_SOPASS,			/* binary */
+
+	__ETHA_WOL_CNT,
+	ETHA_WOL_MAX = (__ETHA_WOL_CNT - 1)
+};
+
 /* generic netlink info */
 #define ETHTOOL_GENL_NAME "ethtool"
 #define ETHTOOL_GENL_VERSION 1
net/ethtool/common.c +10 -0
index 3316e9e403c9..9fba57f554dd 100644
@@ -207,3 +207,13 @@ convert_legacy_settings_to_link_ksettings(
 		= legacy_settings->eth_tp_mdix_ctrl;
 	return retval;
 }
+
+int __ethtool_get_wol(struct net_device *dev, struct ethtool_wolinfo *wol)
+{
+	if (!dev->ethtool_ops->get_wol)
+		return -EOPNOTSUPP;
+
+	dev->ethtool_ops->get_wol(dev, wol);
+
+	return 0;
+}
net/ethtool/common.h +1 -0
index 7a3e0b10e69a..ed3f1ca54660 100644
@@ -17,6 +17,7 @@ phy_tunable_strings[__ETHTOOL_PHY_TUNABLE_COUNT][ETH_GSTRING_LEN];
 
 int __ethtool_get_drvinfo(struct net_device *dev, struct ethtool_drvinfo *info);
 int __ethtool_get_ts_info(struct net_device *dev, struct ethtool_ts_info *info);
+int __ethtool_get_wol(struct net_device *dev, struct ethtool_wolinfo *wol);
 
 bool convert_legacy_settings_to_link_ksettings(
 	struct ethtool_link_ksettings *link_ksettings,
net/ethtool/ioctl.c +4 -4
index 5e878cf6f418..945eaf551a4c 100644
@@ -1230,11 +1230,11 @@ static int ethtool_reset(struct net_device *dev, char __user *useraddr)
 static int ethtool_get_wol(struct net_device *dev, char __user *useraddr)
 {
 	struct ethtool_wolinfo wol = { .cmd = ETHTOOL_GWOL };
+	int rc;
 
-	if (!dev->ethtool_ops->get_wol)
-		return -EOPNOTSUPP;
-
-	dev->ethtool_ops->get_wol(dev, &wol);
+	rc = __ethtool_get_wol(dev, &wol);
+	if (rc < 0)
+		return rc;
 
 	if (copy_to_user(useraddr, &wol, sizeof(wol)))
 		return -EFAULT;
net/ethtool/settings.c +61 -0

123 lines not on this page · raw message

Signature · 1 line
2.20.1
#37 lore raw

RFC PATCH v3 17/21 ethtool: provide message level in GET_SETTINGS request

In reply to Michal Kubecek

Add information about supported and enabled message levels to the GET_SETTINGS reply when ETH_SETTINGS_IM_MSGLEVEL flag is set in the request.

---
 Documentation/networking/ethtool-netlink.txt |  7 ++++++-
 include/linux/netdevice.h                    |  2 ++
 include/uapi/linux/ethtool_netlink.h         |  4 +++-
 net/ethtool/settings.c                       | 16 ++++++++++++++++
 4 files changed, 27 insertions(+), 2 deletions(-)
Documentation/networking/ethtool-netlink.txt +6 -1
index 913df35cb762..057eb3213cfe 100644
@@ -284,6 +284,7 @@ Info mask bits meaning:
     ETH_SETTINGS_IM_LINKINFO		link_ksettings except link modes
     ETH_SETTINGS_IM_LINKMODES		link modes from link_ksettings
     ETH_SETTINGS_IM_WOLINFO		struct ethtool_wolinfo
+    ETH_SETTINGS_IM_MSGLEVEL		msglevel
 
 Response contents:
 
@@ -302,6 +303,7 @@ Response contents:
     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_MSGLEVEL	(bitfield32)	debug level
 
 Most of the attributes and their values have the same meaning as matching
 members of the corresponding ioctl structures. For ETHA_SETTINGS_LINK_MODES,
@@ -311,6 +313,9 @@ ETHA_SETTINGS_PEER_MODES in the reply is a bit list.
 For ETHA_WOL_MODES, selector reports wake on LAN modes supported by the
 device and value enabled modes.
 
+For ETHA_SETTINGS_MSGLEVEL, selector reports all flags supported by kernel and
+value flags enabled for the device.
+
 GET_SETTINGS request is allowed for unprivileged user but ETHA_SETTINGS_SOPASS
 is only provided by kernel in response to privileged (netns CAP_NET_ADMIN)
 requests.
@@ -335,7 +340,7 @@ ETHTOOL_GDRVINFO		ETHNL_CMD_GET_INFO
 ETHTOOL_GREGS			n/a
 ETHTOOL_GWOL			ETHNL_CMD_GET_SETTINGS
 ETHTOOL_SWOL			n/a
-ETHTOOL_GMSGLVL			n/a
+ETHTOOL_GMSGLVL			ETHNL_CMD_GET_SETTINGS
 ETHTOOL_SMSGLVL			n/a
 ETHTOOL_NWAY_RST		n/a
 ETHTOOL_GLINK			n/a
include/linux/netdevice.h +2 -0
index 9a50a67f328f..a2ddfeb381bb 100644
@@ -3846,6 +3846,8 @@ enum {
 	NETIF_MSG_PKTDATA	= 0x1000,
 	NETIF_MSG_HW		= 0x2000,
 	NETIF_MSG_WOL		= 0x4000,
+
+	NETIF_MSG_ALL		= 0x7fff,
 };
 
 #define netif_msg_drv(p)	((p)->msg_enable & NETIF_MSG_DRV)
include/uapi/linux/ethtool_netlink.h +3 -1
index ce9d6b48f814..360e20a73f19 100644
@@ -202,6 +202,7 @@ enum {
 	ETHA_SETTINGS_LINK_MODES,		/* bitset */
 	ETHA_SETTINGS_PEER_MODES,		/* bitset */
 	ETHA_SETTINGS_WOL,			/* nested */
+	ETHA_SETTINGS_MSGLEVEL,			/* bitfield32 */
 
 	__ETHA_SETTINGS_CNT,
 	ETHA_SETTINGS_MAX = (__ETHA_SETTINGS_CNT - 1)
@@ -210,8 +211,9 @@ enum {
 #define ETH_SETTINGS_IM_LINKINFO		0x01
 #define ETH_SETTINGS_IM_LINKMODES		0x02
 #define ETH_SETTINGS_IM_WOLINFO			0x04
+#define ETH_SETTINGS_IM_MSGLEVEL		0x08
 
-#define ETH_SETTINGS_IM_ALL			0x07
+#define ETH_SETTINGS_IM_ALL			0x0f
 
 enum {
 	ETHA_LINKINFO_UNSPEC,
net/ethtool/settings.c +16 -0
index d296625edb2b..58cd2d19a75d 100644
@@ -13,6 +13,7 @@ struct settings_data {
 	struct ethtool_link_ksettings	ksettings;
 	struct ethtool_link_settings	*lsettings;
 	struct ethtool_wolinfo		wolinfo;
+	u32				msglevel;
 	bool				lpm_empty;
 };
 
@@ -25,6 +26,7 @@ static const struct nla_policy get_settings_policy[ETHA_SETTINGS_MAX + 1] = {
 	[ETHA_SETTINGS_LINK_MODES]	= { .type = NLA_REJECT },
 	[ETHA_SETTINGS_PEER_MODES]	= { .type = NLA_REJECT },
 	[ETHA_SETTINGS_WOL]		= { .type = NLA_REJECT },
+	[ETHA_SETTINGS_MSGLEVEL]	= { .type = NLA_REJECT },
 };
 
 static int parse_settings(struct common_req_info *req_info,
@@ -91,6 +93,7 @@ static int prepare_settings(struct common_req_info *req_info,
 	struct settings_data *data =
 		container_of(req_info, struct settings_data, reqinfo_base);
 	struct net_device *dev = data->repdata_base.dev;
+	const struct ethtool_ops *eops = dev->ethtool_ops;
 	u32 req_mask = req_info->req_mask;
 	int ret;
 
@@ -122,6 +125,12 @@ static int prepare_settings(struct common_req_info *req_info,
 		if (ret < 0)
 			req_mask &= ~ETH_SETTINGS_IM_WOLINFO;
 	}
+	if (req_mask & ETH_SETTINGS_IM_MSGLEVEL) {
+		if (eops->get_msglevel)
+			data->msglevel = eops->get_msglevel(dev);
+		else
+			req_mask &= ~ETH_SETTINGS_IM_MSGLEVEL;
+	}
 	ethnl_after_ops(dev);
 
 	data->repdata_base.info_mask = req_mask;
@@ -198,6 +207,8 @@ static int settings_size(const struct common_req_info *req_info)
 	}
 	if (info_mask & ETH_SETTINGS_IM_WOLINFO)
 		len += wol_size();
+	if (info_mask & ETH_SETTINGS_IM_MSGLEVEL)
+		len += nla_total_size(sizeof(struct nla_bitfield32));
 
 	return len;
 }
@@ -308,6 +319,11 @@ static int fill_settings(struct sk_buff *skb,
 		if (ret < 0)
 			return ret;
 	}
+	if (info_mask & ETH_SETTINGS_IM_MSGLEVEL) {
+		if (nla_put_bitfield32(skb, ETHA_SETTINGS_MSGLEVEL,
+				       data->msglevel, NETIF_MSG_ALL))
+			return -EMSGSIZE;
+	}
 
 	return 0;
 }
Signature · 1 line
2.20.1
#38 lore raw

RFC PATCH v3 18/21 ethtool: provide link state in GET_SETTINGS request

In reply to Michal Kubecek

Add information about device link state (as provided by ETHTOOL_GLINK ioctl command) into the GET_SETTINGS reply when ETH_SETTINGS_IM_LINK flag is set in the request.

Note: we cannot use NLA_FLAG for link state as we need three states: off, on and unknown.

---
 Documentation/networking/ethtool-netlink.txt |  4 +++-
 include/uapi/linux/ethtool_netlink.h         |  4 +++-
 net/ethtool/common.c                         |  8 ++++++++
 net/ethtool/common.h                         |  1 +
 net/ethtool/ioctl.c                          |  8 ++++----
 net/ethtool/settings.c                       | 11 +++++++++++
 6 files changed, 30 insertions(+), 6 deletions(-)
Documentation/networking/ethtool-netlink.txt +3 -1
index 057eb3213cfe..538dad93009f 100644
@@ -285,6 +285,7 @@ Info mask bits meaning:
     ETH_SETTINGS_IM_LINKMODES		link modes from link_ksettings
     ETH_SETTINGS_IM_WOLINFO		struct ethtool_wolinfo
     ETH_SETTINGS_IM_MSGLEVEL		msglevel
+    ETH_SETTINGS_IM_LINK		link state
 
 Response contents:
 
@@ -304,6 +305,7 @@ Response contents:
         ETHA_WOL_MODES			(bitfield32)	wake on LAN modes
         ETHA_WOL_SOPASS			(binary)	SecureOn(tm) password
     ETHA_SETTINGS_MSGLEVEL	(bitfield32)	debug level
+    ETHA_SETTINGS_LINK		(u8)		link state
 
 Most of the attributes and their values have the same meaning as matching
 members of the corresponding ioctl structures. For ETHA_SETTINGS_LINK_MODES,
@@ -343,7 +345,7 @@ ETHTOOL_SWOL			n/a
 ETHTOOL_GMSGLVL			ETHNL_CMD_GET_SETTINGS
 ETHTOOL_SMSGLVL			n/a
 ETHTOOL_NWAY_RST		n/a
-ETHTOOL_GLINK			n/a
+ETHTOOL_GLINK			ETHNL_CMD_GET_SETTINGS
 ETHTOOL_GEEPROM			n/a
 ETHTOOL_SEEPROM			n/a
 ETHTOOL_GCOALESCE		n/a
include/uapi/linux/ethtool_netlink.h +3 -1
index 360e20a73f19..06e78d94cacc 100644
@@ -203,6 +203,7 @@ enum {
 	ETHA_SETTINGS_PEER_MODES,		/* bitset */
 	ETHA_SETTINGS_WOL,			/* nested */
 	ETHA_SETTINGS_MSGLEVEL,			/* bitfield32 */
+	ETHA_SETTINGS_LINK,			/* u8 */
 
 	__ETHA_SETTINGS_CNT,
 	ETHA_SETTINGS_MAX = (__ETHA_SETTINGS_CNT - 1)
@@ -212,8 +213,9 @@ enum {
 #define ETH_SETTINGS_IM_LINKMODES		0x02
 #define ETH_SETTINGS_IM_WOLINFO			0x04
 #define ETH_SETTINGS_IM_MSGLEVEL		0x08
+#define ETH_SETTINGS_IM_LINK			0x10
 
-#define ETH_SETTINGS_IM_ALL			0x0f
+#define ETH_SETTINGS_IM_ALL			0x1f
 
 enum {
 	ETHA_LINKINFO_UNSPEC,
net/ethtool/common.c +8 -0
index 9fba57f554dd..a188f07bcb4c 100644
@@ -217,3 +217,11 @@ int __ethtool_get_wol(struct net_device *dev, struct ethtool_wolinfo *wol)
 
 	return 0;
 }
+
+int __ethtool_get_link(struct net_device *dev)
+{
+	if (!dev->ethtool_ops->get_link)
+		return -EOPNOTSUPP;
+
+	return netif_running(dev) && dev->ethtool_ops->get_link(dev);
+}
net/ethtool/common.h +1 -0
index ed3f1ca54660..e5b5c5c2a4b9 100644
@@ -18,6 +18,7 @@ phy_tunable_strings[__ETHTOOL_PHY_TUNABLE_COUNT][ETH_GSTRING_LEN];
 int __ethtool_get_drvinfo(struct net_device *dev, struct ethtool_drvinfo *info);
 int __ethtool_get_ts_info(struct net_device *dev, struct ethtool_ts_info *info);
 int __ethtool_get_wol(struct net_device *dev, struct ethtool_wolinfo *wol);
+int __ethtool_get_link(struct net_device *dev);
 
 bool convert_legacy_settings_to_link_ksettings(
 	struct ethtool_link_ksettings *link_ksettings,
net/ethtool/ioctl.c +4 -4
index 945eaf551a4c..63662a3fa2ae 100644
@@ -1306,12 +1306,12 @@ static int ethtool_nway_reset(struct net_device *dev)
 static int ethtool_get_link(struct net_device *dev, char __user *useraddr)
 {
 	struct ethtool_value edata = { .cmd = ETHTOOL_GLINK };
+	int link = __ethtool_get_link(dev);
 
-	if (!dev->ethtool_ops->get_link)
-		return -EOPNOTSUPP;
-
-	edata.data = netif_running(dev) && dev->ethtool_ops->get_link(dev);
+	if (link < 0)
+		return link;
 
+	edata.data = link;
 	if (copy_to_user(useraddr, &edata, sizeof(edata)))
 		return -EFAULT;
 	return 0;
net/ethtool/settings.c +11 -0
index 58cd2d19a75d..099300901c12 100644
@@ -14,6 +14,7 @@ struct settings_data {
 	struct ethtool_link_settings	*lsettings;
 	struct ethtool_wolinfo		wolinfo;
 	u32				msglevel;
+	int				link;
 	bool				lpm_empty;
 };
 
@@ -27,6 +28,7 @@ static const struct nla_policy get_settings_policy[ETHA_SETTINGS_MAX + 1] = {
 	[ETHA_SETTINGS_PEER_MODES]	= { .type = NLA_REJECT },
 	[ETHA_SETTINGS_WOL]		= { .type = NLA_REJECT },
 	[ETHA_SETTINGS_MSGLEVEL]	= { .type = NLA_REJECT },
+	[ETHA_SETTINGS_LINK]		= { .type = NLA_REJECT },
 };
 
 static int parse_settings(struct common_req_info *req_info,
@@ -99,6 +101,7 @@ static int prepare_settings(struct common_req_info *req_info,
 
 	data->lsettings = &data->ksettings.base;
 	data->lpm_empty = true;
+	data->link = -EOPNOTSUPP;
 
 	ret = ethnl_before_ops(dev);
 	if (ret < 0)
@@ -131,6 +134,8 @@ static int prepare_settings(struct common_req_info *req_info,
 		else
 			req_mask &= ~ETH_SETTINGS_IM_MSGLEVEL;
 	}
+	if (req_mask & ETH_SETTINGS_IM_LINK)
+		data->link = __ethtool_get_link(dev);
 	ethnl_after_ops(dev);
 
 	data->repdata_base.info_mask = req_mask;
@@ -209,6 +214,8 @@ static int settings_size(const struct common_req_info *req_info)
 		len += wol_size();
 	if (info_mask & ETH_SETTINGS_IM_MSGLEVEL)
 		len += nla_total_size(sizeof(struct nla_bitfield32));
+	if (info_mask & ETH_SETTINGS_IM_LINK)
+		len += nla_total_size(sizeof(u32));
 
 	return len;
 }
@@ -324,6 +331,10 @@ static int fill_settings(struct sk_buff *skb,
 				       data->msglevel, NETIF_MSG_ALL))
 			return -EMSGSIZE;
 	}
+	if (info_mask & ETH_SETTINGS_IM_LINK && data->link >= 0) {
+		if (nla_put_u8(skb, ETHA_SETTINGS_LINK, data->link))
+			return -EMSGSIZE;
+	}
 
 	return 0;
 }
Signature · 1 line
2.20.1
#39 lore raw

RFC PATCH v3 19/21 ethtool: provide device features in GET_SETTINGS request

In reply to Michal Kubecek

Add information about network device features (as provided by ETHTOOL_GFEATURES ioctl command) in GET_SETTINGS reply when ETH_SETTINGS_IM_FEATURES flag is set in the request.

This request also provides information provided by ETHTOOL_GRXCSUM, ETHTOOL_GTXCSUM, ETHTOOL_GSG, ETHTOOL_GTSO, ETHTOOL_GUFO, ETHTOOL_GGSO, ETHTOOL_GFLAGS and ETHTOOL_GGRO ioctl commands.

---
 Documentation/networking/ethtool-netlink.txt |  36 +++++--
 include/uapi/linux/ethtool_netlink.h         |  15 ++-
 net/ethtool/common.h                         |   2 +
 net/ethtool/ioctl.c                          |   2 -
 net/ethtool/settings.c                       | 108 +++++++++++++++++++
 5 files changed, 150 insertions(+), 13 deletions(-)
Documentation/networking/ethtool-netlink.txt +26 -10
index 538dad93009f..664c922a05eb 100644
@@ -286,6 +286,7 @@ Info mask bits meaning:
     ETH_SETTINGS_IM_WOLINFO		struct ethtool_wolinfo
     ETH_SETTINGS_IM_MSGLEVEL		msglevel
     ETH_SETTINGS_IM_LINK		link state
+    ETH_SETTINGS_IM_FEATURES		features
 
 Response contents:
 
@@ -306,6 +307,11 @@ Response contents:
         ETHA_WOL_SOPASS			(binary)	SecureOn(tm) password
     ETHA_SETTINGS_MSGLEVEL	(bitfield32)	debug level
     ETHA_SETTINGS_LINK		(u8)		link state
+    ETHA_SETTINGS_FEATURES	(nested)	device features
+        ETHA_FEATURES_HW		(bitset)	dev->hw_features
+        ETHA_FEATURES_WANTED		(bitset)	dev->wanted_features
+        ETHA_FEATURES_ACTIVE		(bitset)	dev->features
+        ETHA_FEATURES_NOCHANGE		(bitset)	NETIF_F_NEVER_CHANGE
 
 Most of the attributes and their values have the same meaning as matching
 members of the corresponding ioctl structures. For ETHA_SETTINGS_LINK_MODES,
@@ -318,13 +324,23 @@ device and value enabled modes.
 For ETHA_SETTINGS_MSGLEVEL, selector reports all flags supported by kernel and
 value flags enabled for the device.
 
+Bitmaps contained in ETHA_SETTINGS_FEATURES have the same meaning as bitmaps
+used in ioctl interference but attribute names are different (they are based
+on corresponding members of struct net_device). Legacy "flags" are not
+provided, if userspace needs them (most likely only ethtool for backward
+compatibility), it can calculate their values from related feature bits
+itself. ETHA_FEATURES_HW uses mask consisting of all features recognized by
+kernel (to provide all names when using verbose bitmap format), remaining
+three use mask equal to value (to save space).
+
 GET_SETTINGS request is allowed for unprivileged user but ETHA_SETTINGS_SOPASS
 is only provided by kernel in response to privileged (netns CAP_NET_ADMIN)
 requests.
 
 GET_SETTINGS requests allow dumps and messages in the same format as response
 to them are broadcasted as notifications on change of these settings using
-netlink or ioctl ethtool interface.
+netlink or ioctl ethtool interface; feature notifications are also sent
+whenever netdev_update_features() or netdev_change_features() is called.
 
 
 Request translation
@@ -354,30 +370,30 @@ ETHTOOL_GRINGPARAM		n/a
 ETHTOOL_SRINGPARAM		n/a
 ETHTOOL_GPAUSEPARAM		n/a
 ETHTOOL_SPAUSEPARAM		n/a
-ETHTOOL_GRXCSUM			n/a
+ETHTOOL_GRXCSUM			ETHNL_CMD_GET_SETTINGS
 ETHTOOL_SRXCSUM			n/a
-ETHTOOL_GTXCSUM			n/a
+ETHTOOL_GTXCSUM			ETHNL_CMD_GET_SETTINGS
 ETHTOOL_STXCSUM			n/a
-ETHTOOL_GSG			n/a
+ETHTOOL_GSG			ETHNL_CMD_GET_SETTINGS
 ETHTOOL_SSG			n/a
 ETHTOOL_TEST			n/a
 ETHTOOL_GSTRINGS		ETHNL_CMD_GET_STRSET
 ETHTOOL_PHYS_ID			n/a
 ETHTOOL_GSTATS			n/a
-ETHTOOL_GTSO			n/a
+ETHTOOL_GTSO			ETHNL_CMD_GET_SETTINGS
 ETHTOOL_STSO			n/a
 ETHTOOL_GPERMADDR		ETHNL_CMD_GET_INFO
-ETHTOOL_GUFO			n/a
+ETHTOOL_GUFO			ETHNL_CMD_GET_SETTINGS
 ETHTOOL_SUFO			n/a
-ETHTOOL_GGSO			n/a
+ETHTOOL_GGSO			ETHNL_CMD_GET_SETTINGS
 ETHTOOL_SGSO			n/a
-ETHTOOL_GFLAGS			n/a
+ETHTOOL_GFLAGS			ETHNL_CMD_GET_SETTINGS
 ETHTOOL_SFLAGS			n/a
 ETHTOOL_GPFLAGS			n/a
 ETHTOOL_SPFLAGS			n/a
 ETHTOOL_GRXFH			n/a
 ETHTOOL_SRXFH			n/a
-ETHTOOL_GGRO			n/a
+ETHTOOL_GGRO			ETHNL_CMD_GET_SETTINGS
 ETHTOOL_SGRO			n/a
 ETHTOOL_GRXRINGS		n/a
 ETHTOOL_GRXCLSRLCNT		n/a
@@ -392,7 +408,7 @@ ETHTOOL_GRXNTUPLE		n/a
 ETHTOOL_GSSET_INFO		ETHNL_CMD_GET_STRSET
 ETHTOOL_GRXFHINDIR		n/a
 ETHTOOL_SRXFHINDIR		n/a
-ETHTOOL_GFEATURES		n/a
+ETHTOOL_GFEATURES		ETHNL_CMD_GET_SETTINGS
 ETHTOOL_SFEATURES		n/a
 ETHTOOL_GCHANNELS		n/a
 ETHTOOL_SCHANNELS		n/a
include/uapi/linux/ethtool_netlink.h +14 -1
index 06e78d94cacc..154d7e6a59dd 100644
@@ -204,6 +204,7 @@ enum {
 	ETHA_SETTINGS_WOL,			/* nested */
 	ETHA_SETTINGS_MSGLEVEL,			/* bitfield32 */
 	ETHA_SETTINGS_LINK,			/* u8 */
+	ETHA_SETTINGS_FEATURES,			/* nest - ETHA_FEATURES_* */
 
 	__ETHA_SETTINGS_CNT,
 	ETHA_SETTINGS_MAX = (__ETHA_SETTINGS_CNT - 1)
@@ -214,8 +215,20 @@ enum {
 #define ETH_SETTINGS_IM_WOLINFO			0x04
 #define ETH_SETTINGS_IM_MSGLEVEL		0x08
 #define ETH_SETTINGS_IM_LINK			0x10
+#define ETH_SETTINGS_IM_FEATURES		0x20
 
-#define ETH_SETTINGS_IM_ALL			0x1f
+#define ETH_SETTINGS_IM_ALL			0x3f
+
+enum {
+	ETHA_FEATURES_UNSPEC,
+	ETHA_FEATURES_HW,			/* bitset */
+	ETHA_FEATURES_WANTED,			/* bitset */
+	ETHA_FEATURES_ACTIVE,			/* bitset */
+	ETHA_FEATURES_NOCHANGE,			/* bitset */
+
+	__ETHA_FEATURES_CNT,
+	ETHA_FEATURES_MAX = (__ETHA_FEATURES_CNT - 1)
+};
 
 enum {
 	ETHA_LINKINFO_UNSPEC,
net/ethtool/common.h +2 -0
index e5b5c5c2a4b9..cf0b81af2d9f 100644
@@ -6,6 +6,8 @@
 #include <linux/netdevice.h>
 #include <linux/ethtool.h>
 
+#define ETHTOOL_DEV_FEATURE_WORDS	((NETDEV_FEATURE_COUNT + 31) / 32)
+
 extern const char
 netdev_features_strings[NETDEV_FEATURE_COUNT][ETH_GSTRING_LEN];
 extern const char
net/ethtool/ioctl.c +0 -2
index 63662a3fa2ae..6c3b492a88fe 100644
@@ -58,8 +58,6 @@ EXPORT_SYMBOL(ethtool_op_get_ts_info);
 
 /* Handlers for each ethtool command */
 
-#define ETHTOOL_DEV_FEATURE_WORDS	((NETDEV_FEATURE_COUNT + 31) / 32)
-
 static int ethtool_get_features(struct net_device *dev, void __user *useraddr)
 {
 	struct ethtool_gfeatures cmd = {
net/ethtool/settings.c +108 -0

156 lines not on this page · raw message

Signature · 1 line
2.20.1
#40 lore raw

RFC PATCH v3 20/21 ethtool: provide private flags in GET_SETTINGS request

In reply to Michal Kubecek

Add information about device private flags (as provided by ETHTOOL_GPFLAGS ioctl command) in GET_SETTINGS reply when ETH_SETTINGS_IM_PRIVFLAGS flag is set in the request.

---
 Documentation/networking/ethtool-netlink.txt |  9 +-
 include/uapi/linux/ethtool_netlink.h         |  4 +-
 net/ethtool/settings.c                       | 98 ++++++++++++++++++++
 3 files changed, 109 insertions(+), 2 deletions(-)
Documentation/networking/ethtool-netlink.txt +8 -1
index 664c922a05eb..290008aaed0a 100644
@@ -287,6 +287,7 @@ Info mask bits meaning:
     ETH_SETTINGS_IM_MSGLEVEL		msglevel
     ETH_SETTINGS_IM_LINK		link state
     ETH_SETTINGS_IM_FEATURES		features
+    ETH_SETTINGS_IM_PRIVFLAGS		device private flags
 
 Response contents:
 
@@ -312,6 +313,7 @@ Response contents:
         ETHA_FEATURES_WANTED		(bitset)	dev->wanted_features
         ETHA_FEATURES_ACTIVE		(bitset)	dev->features
         ETHA_FEATURES_NOCHANGE		(bitset)	NETIF_F_NEVER_CHANGE
+    ETHA_SETTINGS_PRIV_FLAGS	(bitset)	device private flags
 
 Most of the attributes and their values have the same meaning as matching
 members of the corresponding ioctl structures. For ETHA_SETTINGS_LINK_MODES,
@@ -333,6 +335,11 @@ itself. ETHA_FEATURES_HW uses mask consisting of all features recognized by
 kernel (to provide all names when using verbose bitmap format), remaining
 three use mask equal to value (to save space).
 
+ETHA_SETTINGS_PRIV_FLAGS is a bitset with values of device private flags.
+These flags are defined by driver, their number and names (as well as meaning)
+are device dependent. For compact bitset format, names can be retrieved as
+ETH_SS_PRIV_FLAGS string set.
+
 GET_SETTINGS request is allowed for unprivileged user but ETHA_SETTINGS_SOPASS
 is only provided by kernel in response to privileged (netns CAP_NET_ADMIN)
 requests.
@@ -389,7 +396,7 @@ ETHTOOL_GGSO			ETHNL_CMD_GET_SETTINGS
 ETHTOOL_SGSO			n/a
 ETHTOOL_GFLAGS			ETHNL_CMD_GET_SETTINGS
 ETHTOOL_SFLAGS			n/a
-ETHTOOL_GPFLAGS			n/a
+ETHTOOL_GPFLAGS			ETHNL_CMD_GET_SETTINGS
 ETHTOOL_SPFLAGS			n/a
 ETHTOOL_GRXFH			n/a
 ETHTOOL_SRXFH			n/a
include/uapi/linux/ethtool_netlink.h +3 -1
index 154d7e6a59dd..afd61d36bcf8 100644
@@ -205,6 +205,7 @@ enum {
 	ETHA_SETTINGS_MSGLEVEL,			/* bitfield32 */
 	ETHA_SETTINGS_LINK,			/* u8 */
 	ETHA_SETTINGS_FEATURES,			/* nest - ETHA_FEATURES_* */
+	ETHA_SETTINGS_PRIV_FLAGS,		/* nest - ETHA_BITSET_* */
 
 	__ETHA_SETTINGS_CNT,
 	ETHA_SETTINGS_MAX = (__ETHA_SETTINGS_CNT - 1)
@@ -216,8 +217,9 @@ enum {
 #define ETH_SETTINGS_IM_MSGLEVEL		0x08
 #define ETH_SETTINGS_IM_LINK			0x10
 #define ETH_SETTINGS_IM_FEATURES		0x20
+#define ETH_SETTINGS_IM_PRIVFLAGS		0x40
 
-#define ETH_SETTINGS_IM_ALL			0x3f
+#define ETH_SETTINGS_IM_ALL			0x7f
 
 enum {
 	ETHA_FEATURES_UNSPEC,
net/ethtool/settings.c +98 -0

148 lines not on this page · raw message

Signature · 1 line
2.20.1
#41 lore raw

RFC PATCH v3 21/21 ethtool: send netlink notifications about setting changes

In reply to Michal Kubecek

SET_SETTINGS notification message has the same format as response to GET_SETTINGS request and is broadcasted on change of relevant fields. Info mask can be used to limit the information passed to userspace.

Send the notification on changes performed via the legacy ioctl interface; feature notifications are also sent whenever netdev_update_features() or netdev_change_features() is called, even if the change was not performed using the ethtool interface.

---
 net/ethtool/ioctl.c   | 24 ++++++++++++++++++++++--
 net/ethtool/netlink.c | 12 ++++++++++++
 2 files changed, 34 insertions(+), 2 deletions(-)
net/ethtool/ioctl.c +22 -2
index 6c3b492a88fe..17ccca14f5c3 100644
@@ -30,6 +30,7 @@
 #include <net/devlink.h>
 #include <net/xdp_sock.h>
 #include <net/flow_offload.h>
+#include <linux/ethtool_netlink.h>
 
 #include "common.h"
 
@@ -567,7 +568,12 @@ static int ethtool_set_link_ksettings(struct net_device *dev,
 	    != link_ksettings.base.link_mode_masks_nwords)
 		return -EINVAL;
 
-	return dev->ethtool_ops->set_link_ksettings(dev, &link_ksettings);
+	err = dev->ethtool_ops->set_link_ksettings(dev, &link_ksettings);
+	if (err >= 0)
+		ethtool_notify(dev, NULL, ETHNL_CMD_SET_SETTINGS,
+			       ETH_SETTINGS_IM_LINKINFO |
+			       ETH_SETTINGS_IM_LINKMODES, NULL);
+	return err;
 }
 
 /* Query device for its ethtool_cmd settings.
@@ -616,6 +622,7 @@ static int ethtool_set_settings(struct net_device *dev, void __user *useraddr)
 {
 	struct ethtool_link_ksettings link_ksettings;
 	struct ethtool_cmd cmd;
+	int ret;
 
 	ASSERT_RTNL();
 
@@ -628,7 +635,12 @@ static int ethtool_set_settings(struct net_device *dev, void __user *useraddr)
 		return -EINVAL;
 	link_ksettings.base.link_mode_masks_nwords =
 		__ETHTOOL_LINK_MODE_MASK_NU32;
-	return dev->ethtool_ops->set_link_ksettings(dev, &link_ksettings);
+	ret = dev->ethtool_ops->set_link_ksettings(dev, &link_ksettings);
+	if (ret >= 0)
+		ethtool_notify(dev, NULL, ETHNL_CMD_SET_SETTINGS,
+			       ETH_SETTINGS_IM_LINKINFO |
+			       ETH_SETTINGS_IM_LINKMODES, NULL);
+	return ret;
 }
 
 static noinline_for_stack int ethtool_get_drvinfo(struct net_device *dev,
@@ -1255,6 +1267,8 @@ static int ethtool_set_wol(struct net_device *dev, char __user *useraddr)
 		return ret;
 
 	dev->wol_enabled = !!wol.wolopts;
+	ethtool_notify(dev, NULL, ETHNL_CMD_SET_SETTINGS,
+		       ETH_SETTINGS_IM_WOLINFO, NULL);
 
 	return 0;
 }
@@ -2453,6 +2467,9 @@ int dev_ethtool(struct net *net, struct ifreq *ifr)
 	case ETHTOOL_SMSGLVL:
 		rc = ethtool_set_value_void(dev, useraddr,
 				       dev->ethtool_ops->set_msglevel);
+		if (rc >= 0)
+			ethtool_notify(dev, NULL, ETHNL_CMD_SET_SETTINGS,
+				       ETH_SETTINGS_IM_MSGLEVEL, NULL);
 		break;
 	case ETHTOOL_GEEE:
 		rc = ethtool_get_eee(dev, useraddr);
@@ -2519,6 +2536,9 @@ int dev_ethtool(struct net *net, struct ifreq *ifr)
 	case ETHTOOL_SPFLAGS:
 		rc = ethtool_set_value(dev, useraddr,
 				       dev->ethtool_ops->set_priv_flags);
+		if (rc == 0)
+			ethtool_notify(dev, NULL, ETHNL_CMD_SET_SETTINGS,
+				       ETH_SETTINGS_IM_PRIVFLAGS, NULL);
 		break;
 	case ETHTOOL_GRXFH:
 	case ETHTOOL_GRXRINGS:
net/ethtool/netlink.c +12 -0
index 5166b0c28288..6f94aec6fa69 100644
@@ -480,6 +480,7 @@ typedef void (*ethnl_notify_handler_t)(struct net_device *dev,
 				       const void *data);
 
 ethnl_notify_handler_t ethnl_notify_handlers[] = {
+	[ETHNL_CMD_SET_SETTINGS]	= ethnl_std_notify,
 };
 
 void ethtool_notify(struct net_device *dev, struct netlink_ext_ack *extack,
@@ -534,6 +535,14 @@ static void ethnl_notify_devlist(struct netdev_notifier_info *info,
 	nlmsg_free(skb);
 }
 
+static void ethnl_notify_features(struct netdev_notifier_info *info)
+{
+	struct net_device *dev = netdev_notifier_info_to_dev(info);
+
+	ethtool_notify(dev, NULL, ETHNL_CMD_SET_SETTINGS,
+		       ETH_SETTINGS_IM_FEATURES, NULL);
+}
+
 static int ethnl_netdev_event(struct notifier_block *this, unsigned long event,
 			      void *ptr)
 {
@@ -548,6 +557,9 @@ static int ethnl_netdev_event(struct notifier_block *this, unsigned long event,
 		ethnl_notify_devlist(ptr, ETHA_EVENT_RENAMEDEV,
 				     ETHA_RENAMEDEV_DEV);
 		break;
+	case NETDEV_FEAT_CHANGE:
+		ethnl_notify_features(ptr);
+		break;
 	}
 
 	return NOTIFY_DONE;
Signature · 1 line
2.20.1
#42 lore raw
In reply to Michal Kubecek
Quoted 15 lines · Mon, Feb 18, 2019 at 07:21:24PM CET, [email protected] wrote:

Note: this is marked as RFC because it's rather late in the cycle; the plan is to make a regular submission (with changes based on review) once net-next reopens after the 5.1 merge window. The full (work in progress) series, together with the (userspace) ethtool counterpart can be found at
https://github.com/mkubecek/ethnl

This is first part of alternative userspace interface for ethtool. The aim is to address some long known issues with the ioctl interface, mainly lack of extensibility, raciness, limited error reporting and absence of notifications.

The interface uses generic netlink family "ethtool"; it provides multicast group "monitor" which is used for notifications. Documentation for the interface is in Documentation/networking/ethtool-netlink.txt

Quoted 5 lines

Basic concepts:

- the goal is to provide all features of ioctl interface but allow easier future extensions; at some point, it should be possible to have full ethtool functionality without using the ioctl interface

I'm not sure it is a good idea to map the existing iface to netlink fully. There are things in ethtool which are not really unique for Ethernet. Those things should be put somewhere else.

Quoted 34 lines

- inextensibility of ioctl interface resulted in way too many commands, many of them obsoleted by newer ones; reduce the number by ignoring the obsolete commands and grouping some together
- for "set" type commands, allows passing only the attributes to be changed; therefore we don't need a get-modify-set cycle (which is inherently racy), userspace can simply say what it wants to change
- provide notifications to multicast group "monitor" like rtnetlink does, i.e. in the form of messages close to replies to "get" requests
- allow dump requests to get some information about all network devices providing it
- be less dependent on ethtool and kernel being in sync; allow e.g. saying "ethtool -s eth0 advertise foo off" without ethtool knowing what "foo" means; it's kernel's job to know what mode "xyz" is and if it exists and is supported

Main changes between RFC v2 and RFC v3:

- do not allow building as a module (no netdev notifiers needed)
- drop some obsolete fields
- add permanent hw address, timestamping and private flags support
- rework bitset handling to get rid of variable length arrays
- notify monitor on device renames
- restructure GET_SETTINGS/SET_SETTINGS messages
- split too long patches and submit only first part of the series

Main changes between RFC v1 and RFC v2:

- support dumps for all "get" requests
- provide notifications for changes related to supported request types
- support getting string sets (both global and per device)
- support getting/setting device features
- get rid of family specific header, everything passed as attributes
- split netlink code into multiple files in net/ethtool/ directory

Quoted 6 lines

ToDo / open questions:

- some features provided by ethtool would rather belong to devlink (and some are already superseded by devlink); however, only few drivers provide devlink interface at the moment and as recent discussion on flashing revealed, we cannot rely on devlink's presence

Could you explain why please?

Quoted 84 lines

- while the netlink interface allows easy future extensions, ethtool_ops interface does not; some settings could be implemented using tunables and accessed via relevant netlink messages (as well as tunables) from userspace but in the long term, something better will be needed

- currently, all communication with drivers via ethtool_ops is done under RTNL as this is what ioctl interface does and likely many ethtool_ops handlers rely on that; if we are going to rework ethtool_ops in the future ("phase two"), it would be nice to get rid of it

- ethtool_ops should pass extack pointer to allow drivers more meaningful error reporting; it's not clear, however, how to pass information about offending attribute

- notifications are sent whenever a change is done via netlink API or ioctl API and for netdev features also whenever they are updated using netdev_change_features(); it would be desirable to notify also about link state and negotiation result (speed/duplex and partner link modes) but it would be more tricky

Michal Kubecek (21):
netlink: introduce nla_put_bitfield32()
ethtool: move to its own directory
ethtool: introduce ethtool netlink interface
ethtool: helper functions for netlink interface
ethtool: netlink bitset handling
ethtool: support for netlink notifications
ethtool: implement EVENT notifications
ethtool: generic handlers for GET requests
ethtool: move string arrays into common file
ethtool: provide string sets with GET_STRSET request
ethtool: provide driver/device information in GET_INFO request
ethtool: provide permanent hardware address in GET_INFO request
ethtool: provide timestamping information in GET_INFO request
ethtool: provide link mode names as a string set
ethtool: provide link settings and link modes in GET_SETTINGS request
ethtool: provide WoL information in GET_SETTINGS request
ethtool: provide message level in GET_SETTINGS request
ethtool: provide link state in GET_SETTINGS request
ethtool: provide device features in GET_SETTINGS request
ethtool: provide private flags in GET_SETTINGS request
ethtool: send netlink notifications about setting changes

Documentation/networking/ethtool-netlink.txt | 441 +++++++++++++
include/linux/ethtool_netlink.h              |  17 +
include/linux/netdevice.h                    |  14 +
include/net/netlink.h                        |  15 +
include/uapi/linux/ethtool.h                 |  10 +
include/uapi/linux/ethtool_netlink.h         | 265 ++++++++
include/uapi/linux/net_tstamp.h              |  13 +
net/Kconfig                                  |   8 +
net/Makefile                                 |   2 +-
net/core/Makefile                            |   2 +-
net/ethtool/Makefile                         |   7 +
net/ethtool/bitset.c                         | 572 +++++++++++++++++
net/ethtool/bitset.h                         |  40 ++
net/ethtool/common.c                         | 227 +++++++
net/ethtool/common.h                         |  29 +
net/ethtool/info.c                           | 332 ++++++++++
net/{core/ethtool.c => ethtool/ioctl.c}      | 244 ++-----
net/ethtool/netlink.c                        | 634 +++++++++++++++++++
net/ethtool/netlink.h                        | 252 ++++++++
net/ethtool/settings.c                       | 559 ++++++++++++++++
net/ethtool/strset.c                         | 461 ++++++++++++++
21 files changed, 3937 insertions(+), 207 deletions(-)

create mode 100644 Documentation/networking/ethtool-netlink.txt create mode 100644 include/linux/ethtool_netlink.h create mode 100644 include/uapi/linux/ethtool_netlink.h create mode 100644 net/ethtool/Makefile
create mode 100644 net/ethtool/bitset.c
create mode 100644 net/ethtool/bitset.h
create mode 100644 net/ethtool/common.c
create mode 100644 net/ethtool/common.h
create mode 100644 net/ethtool/info.c
rename net/{core/ethtool.c => ethtool/ioctl.c} (91%) create mode 100644 net/ethtool/netlink.c
create mode 100644 net/ethtool/netlink.h
create mode 100644 net/ethtool/settings.c
create mode 100644 net/ethtool/strset.c

Signature · 1 line
2.20.1
#43 lore raw
Quoted 6 lines · Jiri Pirko
Quoted 4 lines

- some features provided by ethtool would rather belong to devlink (and some are already superseded by devlink); however, only few drivers provide devlink interface at the moment and as recent discussion on flashing revealed, we cannot rely on devlink's presence

Could you explain why please?

What I mean is the problem discussed under Jakub's devlink flash
patchset: that he couldn't implement only the devlink callback in nfp and rely on the generic fallback to devlink because it wouldn't work if devlink is built as a module.

But I think this should be addressed. If we agree that flashing (and other features provided by ethtool at the moment) rather belongs to devlink (which nobody seems to oppose), we should rather try to make it possible for drivers to provide only the devlink callback and gradually move all in-tree drivers to doing so. (And one day, remove it from ethtool_ops.) It doesn't seem to make much sense to have devlink as a module in such scenario.

Michal

#44 lore raw
Quoted 6 lines · Tue, Feb 19, 2019 at 12:57:27PM CET, [email protected] wrote:
Quoted 5 lines · Jiri Pirko
Quoted 4 lines

- some features provided by ethtool would rather belong to devlink (and some are already superseded by devlink); however, only few drivers provide devlink interface at the moment and as recent discussion on flashing revealed, we cannot rely on devlink's presence

Quoted 6 lines
Quoted 1 line

Could you explain why please?

What I mean is the problem discussed under Jakub's devlink flash
patchset: that he couldn't implement only the devlink callback in nfp and rely on the generic fallback to devlink because it wouldn't work if devlink is built as a module.

So let's fix that.

Quoted 8 lines

But I think this should be addressed. If we agree that flashing (and other features provided by ethtool at the moment) rather belongs to devlink (which nobody seems to oppose), we should rather try to make it possible for drivers to provide only the devlink callback and gradually move all in-tree drivers to doing so. (And one day, remove it from ethtool_ops.) It doesn't seem to make much sense to have devlink as a module in such scenario.

Agreed.

Quoted 2 lines

Michal

#45 lore raw
In reply to Michal Kubecek

Hi Michal,

Let me start with a big thank you for tackling this humongous amount of work!

Quoted 15 lines · Michal Kubecek

Note: this is marked as RFC because it's rather late in the cycle; the plan is to make a regular submission (with changes based on review) once net-next reopens after the 5.1 merge window. The full (work in progress) series, together with the (userspace) ethtool counterpart can be found at
https://github.com/mkubecek/ethnl

This is first part of alternative userspace interface for ethtool. The aim is to address some long known issues with the ioctl interface, mainly lack of extensibility, raciness, limited error reporting and absence of notifications.

The interface uses generic netlink family "ethtool"; it provides multicast group "monitor" which is used for notifications. Documentation for the interface is in Documentation/networking/ethtool-netlink.txt

Quoted 5 lines

Basic concepts:

- the goal is to provide all features of ioctl interface but allow easier future extensions; at some point, it should be possible to have full ethtool functionality without using the ioctl interface

+1

Quoted 8 lines

- inextensibility of ioctl interface resulted in way too many commands, many of them obsoleted by newer ones; reduce the number by ignoring the obsolete commands and grouping some together
- for "set" type commands, allows passing only the attributes to be changed; therefore we don't need a get-modify-set cycle (which is inherently racy), userspace can simply say what it wants to change
- provide notifications to multicast group "monitor" like rtnetlink does, i.e. in the form of messages close to replies to "get" requests

+1

Quoted 2 lines

- allow dump requests to get some information about all network devices providing it

And it seems like you have also added some filtering capability with at least the settings dump, right? That is also highly welcome.

Quoted 8 lines

- be less dependent on ethtool and kernel being in sync; allow e.g. saying "ethtool -s eth0 advertise foo off" without ethtool knowing what "foo" means; it's kernel's job to know what mode "xyz" is and if it exists and is supported

Main changes between RFC v2 and RFC v3:

- do not allow building as a module (no netdev notifiers needed)

I would very much prefer that we could build this as a module. Some systems might be memory constrained or opt to disable ethtool entirely (security?). If this is not too much trouble, can we try to maintain that?

Quoted 16 lines

- drop some obsolete fields
- add permanent hw address, timestamping and private flags support
- rework bitset handling to get rid of variable length arrays
- notify monitor on device renames
- restructure GET_SETTINGS/SET_SETTINGS messages
- split too long patches and submit only first part of the series

Main changes between RFC v1 and RFC v2:

- support dumps for all "get" requests
- provide notifications for changes related to supported request types
- support getting string sets (both global and per device)
- support getting/setting device features
- get rid of family specific header, everything passed as attributes
- split netlink code into multiple files in net/ethtool/ directory

Quoted 6 lines

ToDo / open questions:

- some features provided by ethtool would rather belong to devlink (and some are already superseded by devlink); however, only few drivers provide devlink interface at the moment and as recent discussion on flashing revealed, we cannot rely on devlink's presence

Should we just move everything under devlink given that ethtool over netlink or devlink are essentially manipulating the same (or close to) objects? It seems to me that at least now is the right time to make decisions about what should stay in ethtool and be offered via netlink, what should be migrated to something else (e.g.: Jiri mentioned rtnetlink), and what is a devlink candidate.

How do we proceed to easily triage which of these netlink facilities should things be routed to/from?

Quoted 5 lines

- while the netlink interface allows easy future extensions, ethtool_ops interface does not; some settings could be implemented using tunables and accessed via relevant netlink messages (as well as tunables) from userspace but in the long term, something better will be needed

Right, so as a driver writer, one thing I kind of hate is having to fill a netlink skb myself because that's a lot of work, and it makes it fairly hard to do mass conversion of internal APIs due to the increased complexity in auditing what drivers do.

Quoted 10 lines

- currently, all communication with drivers via ethtool_ops is done under RTNL as this is what ioctl interface does and likely many ethtool_ops handlers rely on that; if we are going to rework ethtool_ops in the future ("phase two"), it would be nice to get rid of it

- ethtool_ops should pass extack pointer to allow drivers more meaningful error reporting; it's not clear, however, how to pass information about offending attribute

Quoted 5 lines

- notifications are sent whenever a change is done via netlink API or ioctl API and for netdev features also whenever they are updated using netdev_change_features(); it would be desirable to notify also about link state and negotiation result (speed/duplex and partner link modes) but it would be more tricky

Historically you listen for a link event and you determine the link parameters from there, I don't know if there is much value in giving the full link parameter list, especially given those could theoretically change depending on your medium (e.g.: wireless), or there could be a lot to query at that time...

Quoted 61 lines

Michal Kubecek (21):
netlink: introduce nla_put_bitfield32()
ethtool: move to its own directory
ethtool: introduce ethtool netlink interface
ethtool: helper functions for netlink interface
ethtool: netlink bitset handling
ethtool: support for netlink notifications
ethtool: implement EVENT notifications
ethtool: generic handlers for GET requests
ethtool: move string arrays into common file
ethtool: provide string sets with GET_STRSET request
ethtool: provide driver/device information in GET_INFO request
ethtool: provide permanent hardware address in GET_INFO request
ethtool: provide timestamping information in GET_INFO request
ethtool: provide link mode names as a string set
ethtool: provide link settings and link modes in GET_SETTINGS request
ethtool: provide WoL information in GET_SETTINGS request
ethtool: provide message level in GET_SETTINGS request
ethtool: provide link state in GET_SETTINGS request
ethtool: provide device features in GET_SETTINGS request
ethtool: provide private flags in GET_SETTINGS request
ethtool: send netlink notifications about setting changes

 Documentation/networking/ethtool-netlink.txt | 441 +++++++++++++
 include/linux/ethtool_netlink.h              |  17 +
 include/linux/netdevice.h                    |  14 +
 include/net/netlink.h                        |  15 +
 include/uapi/linux/ethtool.h                 |  10 +
 include/uapi/linux/ethtool_netlink.h         | 265 ++++++++
 include/uapi/linux/net_tstamp.h              |  13 +
 net/Kconfig                                  |   8 +
 net/Makefile                                 |   2 +-
 net/core/Makefile                            |   2 +-
 net/ethtool/Makefile                         |   7 +
 net/ethtool/bitset.c                         | 572 +++++++++++++++++
 net/ethtool/bitset.h                         |  40 ++
 net/ethtool/common.c                         | 227 +++++++
 net/ethtool/common.h                         |  29 +
 net/ethtool/info.c                           | 332 ++++++++++
 net/{core/ethtool.c => ethtool/ioctl.c}      | 244 ++-----
 net/ethtool/netlink.c                        | 634 +++++++++++++++++++
 net/ethtool/netlink.h                        | 252 ++++++++
 net/ethtool/settings.c                       | 559 ++++++++++++++++
 net/ethtool/strset.c                         | 461 ++++++++++++++
 21 files changed, 3937 insertions(+), 207 deletions(-)
 create mode 100644 Documentation/networking/ethtool-netlink.txt
 create mode 100644 include/linux/ethtool_netlink.h
 create mode 100644 include/uapi/linux/ethtool_netlink.h
 create mode 100644 net/ethtool/Makefile
 create mode 100644 net/ethtool/bitset.c
 create mode 100644 net/ethtool/bitset.h
 create mode 100644 net/ethtool/common.c
 create mode 100644 net/ethtool/common.h
 create mode 100644 net/ethtool/info.c
 rename net/{core/ethtool.c => ethtool/ioctl.c} (91%)
 create mode 100644 net/ethtool/netlink.c
 create mode 100644 net/ethtool/netlink.h
 create mode 100644 net/ethtool/settings.c
 create mode 100644 net/ethtool/strset.c
Signature · 1 line
Florian
#46 lore raw
Quoted 7 lines · Florian Fainelli
Quoted 3 lines

Main changes between RFC v2 and RFC v3:

- do not allow building as a module (no netdev notifiers needed)

I would very much prefer that we could build this as a module. Some systems might be memory constrained or opt to disable ethtool entirely (security?). If this is not too much trouble, can we try to maintain that?

There were two reasons why I agreed so quickly to the suggestion to make CONFIG_ETHTOOL a bool:

1. I didn't really think there would be anyone who would benefit from having the interface as a loadable module and the only reason why I made it possible originally was that it was easier to test changes that way. That was rather poor reason for keeping it once submitted but if there is an actual demand from real life users, it's something different.

2. Using of ethtool netdev notifiers for triggering netlink notifications from other code (mostly ioctl interface) was rather clumsy. However, it could be worked around using an RCU pointer and some simple helpers (as discussed in the devlink thread) so this not not a serious problem either.

Quoted 12 lines
Quoted 4 lines

- some features provided by ethtool would rather belong to devlink (and some are already superseded by devlink); however, only few drivers provide devlink interface at the moment and as recent discussion on flashing revealed, we cannot rely on devlink's presence

Should we just move everything under devlink given that ethtool over netlink or devlink are essentially manipulating the same (or close to) objects? It seems to me that at least now is the right time to make decisions about what should stay in ethtool and be offered via netlink, what should be migrated to something else (e.g.: Jiri mentioned rtnetlink), and what is a devlink candidate.

Quoted 2 lines

How do we proceed to easily triage which of these netlink facilities should things be routed to/from?

At the moment I would say the likely candidates for rtnetlink are permanent hw address (ethtool -P), netdev features (-k / -K) and link state (part of "ethtool <dev>"). (I'm not very happy about the prospect of moving netdev features to rtnetlink but it seems hard to argue why they shouldn't belong there.) As for devlink, I would see eeprom dump (-e) and write (-E), register dump (-d), firmware dump (-w / -W) and flash (-f), and module eeprom dump (-m) as candidates. Maybe also device reset (--reset) (which was put into ethtool_ops, though, even if added only recently).

There is also another question: at which level to do the split.

I would like to avoid doint it between user and ethtool utility, i.e. dropping some functions from ethtool and pointing people to iproute2 tools (or even replacing ethtool with some new tool). There is the "ifconfig memento": 20 years after it became obsolete, I still keep hearing people say "I don't want to learn some new tool with unfamiliar syntax". (Some of them learning to use ifconfig few years ago doesn't really help. Neither them saying the same about ss which copied the most of netstat's basic options.) I'm afraid the result would be exactly the same with ethtool.

Then there is an option of providing the functions in ethtool but using both ethtool netlink and devlink (and probably also rtnetlink) to talk to kernel. This means a bit more complicated userspace code but nothing serious. The bigger problem I see with this approach is that so far only few NIC drivers have any devlink support. Unless we would want to add ethtool_ops fallback for devlink, we would have to wait until the relevant features are available via devlink in all in-tree NIC drivers which provide them via ethtool_ops now.

Providing the features via ethtool netlink interface but having them backed up by devlink would mean we would have two userspace interfaces for the same (or almost the same) function. It's something I could live with but I understand that not everyone would like this. The advantage is that it would allow migrating the features from ethtool_ops to devlink gradually.

Quoted 9 lines
Quoted 4 lines

- while the netlink interface allows easy future extensions, ethtool_ops interface does not; some settings could be implemented using tunables and accessed via relevant netlink messages (as well as tunables) from userspace but in the long term, something better will be needed

Right, so as a driver writer, one thing I kind of hate is having to fill a netlink skb myself because that's a lot of work, and it makes it fairly hard to do mass conversion of internal APIs due to the increased complexity in auditing what drivers do.

I would also prefer to avoid parsing and generating netlink messages in drivers for regular operations.

Michal