Skip to contentSkip to conversation

ethtool netlink interface (WiP)

RFC PATCH Superseded Michal Kubecek 4 participants 37 messages Jul 30, 2018 – Aug 21, 2018

Subsystems (4)

v2 of 9 Superseded Latest is v9 →

lore
Share & tools
lore
#0 lore raw

v2 cover ethtool netlink interface (WiP)

A netlink based interface for ethtool is a recurring discussion theme; such discussion happens from time to time but never seems to reach any clear conclusion except that netlink interface is desperately needed. I'm sending this hoping that having a proposal (even if partial) on the table could help move the discussion further.

The interface used for communication between ethtool and kernel is based on ioctl() and suffers from many problems. The most pressing seems the be the lack of extensibility. While some of the newer commands use structures designed to allow future extensions (e.g. GFEATURES or TEST), most either allow no extension at all (GPAUSEPARAM, GCOALESCE) or only limited set of reserved fields (GDRVINFO, GEEE). Even most of those which support future extensions limit the data types that can be used.

This series aims to provide an alternative interface based on netlink which is what other network configuration utilities use. In particular, it uses generic netlink (family "ethtool"). The goal is to provide an interface which would be extensible, flexible and practical both for ethtool and for other network configuration tools (e.g. wicked, systemd-networkd or NetworkManager).

The interface is documented in Documentation/networking/ethtool-netlink.txt

A series for ethtool utility will follow shortly.

Basic concepts:

- the interface is based on generic netlink (family name "ethtool")

- the goal is to provide all features of ioctl interface but allow easier future extensions

- 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, netlink allows providing 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 defices 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 again RFC v1:

- 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:

- as some comments in discussion on v1 pointed out, some features of ethtool would rather belong to devlink; phy_tunables and phy_stats seem to be candidates, maybe part of drvinfo; are there more?

- another question is where to do the split; should ethtool use devlink API for these or can we provide them in ethtool API as well but with devlink backend (for communication with NIC)

- currently, all communication with drivers via ethtool_ops is done under RTNL as this is what ioctl interface does and I suspect many ethtool_ops rely on that; can we do without RTNL?

- 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

- find reasonable format for data transfers (e.g. eeprom dump or flash); I don't have clear idea how big these can get and if 64 KB limit on attribute size (including nested ones) is a problem; if so, dumps can be an answer for dumps, some kind of multi-message requests would be needed for flashes

- 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

- it would be nice if driver could provide useful error/warning messages to be passed to userspace via extended ACK; example: while testing, I found a driver which only allows values 0, 1, 3 and 10000 for certain parameter but the only way poor user can find out is either by trying all values or by checking driver source

- some of the functions for GET_SETTINGS and GET_PARAMS are quite similar (e.g. ethtool_get_*); it might be beneficial to introduce some "ops", leave only "parse", "prepare", "size" and "fill" handlers and make the rest generic (like ethnl_dumpit()).

- the counts and sizes in GET_DRVINFO reply seem to be a relic of the past and if userspace needs them, there are (or will be) other ways to get them; they should most likely go

Michal Kubecek (17):
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: implement GET_STRSET message
ethtool: implement GET_DRVINFO message
ethtool: implement GET_SETTINGS message
ethtool: implement GET_SETTINGS request for features
ethtool: implement SET_SETTINGS notification
ethtool: implement SET_SETTINGS message
ethtool: implement SET_SETTINGS request for features
ethtool: implement GET_PARAMS message
ethtool: implement SET_PARAMS notification
ethtool: implement SET_PARAMS message

 Documentation/networking/ethtool-netlink.txt |  558 ++++++++
 include/linux/ethtool_netlink.h              |   17 +
 include/linux/netdevice.h                    |   25 +
 include/net/netlink.h                        |   15 +
 include/uapi/linux/ethtool.h                 |    7 +
 include/uapi/linux/ethtool_netlink.h         |  325 +++++
 net/Kconfig                                  |    7 +
 net/Makefile                                 |    2 +-
 net/core/Makefile                            |    2 +-
 net/core/dev.c                               |   27 +-
 net/ethtool/Makefile                         |    7 +
 net/ethtool/common.c                         |  242 ++++
 net/ethtool/common.h                         |   26 +
 net/ethtool/drvinfo.c                        |  131 ++
 net/{core/ethtool.c => ethtool/ioctl.c}      |  310 ++---
 net/ethtool/netlink.c                        |  840 ++++++++++++
 net/ethtool/netlink.h                        |  169 +++
 net/ethtool/params.c                         | 1008 ++++++++++++++
 net/ethtool/settings.c                       | 1230 ++++++++++++++++++
 net/ethtool/strset.c                         |  552 ++++++++
 20 files changed, 5269 insertions(+), 231 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/common.c
 create mode 100644 net/ethtool/common.h
 create mode 100644 net/ethtool/drvinfo.c
 rename net/{core/ethtool.c => ethtool/ioctl.c} (88%)
 create mode 100644 net/ethtool/netlink.c
 create mode 100644 net/ethtool/netlink.h
 create mode 100644 net/ethtool/params.c
 create mode 100644 net/ethtool/settings.c
 create mode 100644 net/ethtool/strset.c
Signature · 1 line
2.18.0
#1 lore raw

RFC PATCH v2 1/17 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 you already have struct nla_bitfield32, you can use nla_put().

---
 include/net/netlink.h | 15 +++++++++++++++
 1 file changed, 15 insertions(+)
include/net/netlink.h +15 -0
index 0c154f98e987..6d4eb6bd9235 100644
@@ -1064,6 +1064,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.18.0
#2 lore raw

RFC PATCH v2 2/17 ethtool: move to its own directory

In reply to Michal Kubecek

With ethtool netlink interface, there is going to be a lot of new files so that it seem more convenient to put them into a separate directory net/ethtool. Start with moving current file with ioctl implementation there and renaming it to ioctl.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 80175e6a2eb8..55734d0a1603 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
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.18.0
#3 lore raw

RFC PATCH v2 3/17 ethtool: introduce ethtool netlink interface

In reply to Michal Kubecek

No function implemented yet, only genetlink and module infrastructure. Register/unregister genetlink family "ethtool" and allow the module to be autoloaded by genetlink code (if built as a module, distributions would probably prefer "y").

---
 Documentation/networking/ethtool-netlink.txt | 168 +++++++++++++++++++
 include/linux/ethtool_netlink.h              |   9 +
 include/uapi/linux/ethtool_netlink.h         |  19 +++
 net/Kconfig                                  |   7 +
 net/ethtool/Makefile                         |   6 +-
 net/ethtool/netlink.c                        |  41 +++++
 net/ethtool/netlink.h                        |  12 ++
 7 files changed, 261 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 +168 -0
new file mode 100644
index 000000000000..120376e0f91b
@@ -0,0 +1,168 @@
+                        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..3c0c5c70692b
@@ -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_MAX,
+	ETHNL_CMD_MAX = (__ETHNL_CMD_MAX - 1)
+};
+
+/* generic netlink info */
+#define ETHTOOL_GENL_NAME "ethtool"
+#define ETHTOOL_GENL_VERSION 1
+
+#endif /* _UAPI_LINUX_ETHTOOL_NETLINK_H_ */
net/Kconfig +7 -0
index 228dfa382eec..12e763449525 100644
@@ -445,6 +445,13 @@ config FAILOVER
 	  migration of VMs with direct attached VFs by failing over to the
 	  paravirtual datapath when the VF is unplugged.
 
+config ETHTOOL_NETLINK
+	tristate "Netlink interface for ethtool"
+	default m
+	help
+	   New netlink based interface for ethtool which is going to obsolete
+	   the old ioctl based one once it provides all features.
+
 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 +41 -0

41 lines not on this page · raw message

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.18.0
#4 lore raw

RFC PATCH v2 4/17 ethtool: helper functions for netlink interface

In reply to Michal Kubecek

Misc helpers used by ethtool netlink code.

---
 include/uapi/linux/ethtool_netlink.h |  11 ++
 net/ethtool/netlink.c                | 163 +++++++++++++++++++++++++++
 net/ethtool/netlink.h                | 124 ++++++++++++++++++++
 3 files changed, 298 insertions(+)
include/uapi/linux/ethtool_netlink.h +11 -0
index 3c0c5c70692b..1df263d9feb7 100644
@@ -12,6 +12,17 @@ enum {
 	ETHNL_CMD_MAX = (__ETHNL_CMD_MAX - 1)
 };
 
+/* device specification */
+
+enum {
+	ETHA_DEV_UNSPEC,
+	ETHA_DEV_INDEX,				/* u32 */
+	ETHA_DEV_NAME,				/* string */
+
+	__ETHA_DEV_MAX,
+	ETHA_DEV_MAX = (__ETHA_DEV_MAX - 1)
+};
+
 /* generic netlink info */
 #define ETHTOOL_GENL_NAME "ethtool"
 #define ETHTOOL_GENL_VERSION 1
net/ethtool/netlink.c +163 -0

172 lines not on this page · raw message

net/ethtool/netlink.h +124 -0

131 lines not on this page · raw message

Signature · 1 line
2.18.0
#5 lore raw

RFC PATCH v2 5/17 ethtool: netlink bitset handling

In reply to Michal Kubecek

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

---
 Documentation/networking/ethtool-netlink.txt |  56 +++
 include/uapi/linux/ethtool_netlink.h         |  31 ++
 net/ethtool/netlink.c                        | 395 +++++++++++++++++++
 net/ethtool/netlink.h                        |  26 ++
 4 files changed, 508 insertions(+)
Documentation/networking/ethtool-netlink.txt +56 -0
index 120376e0f91b..a49dfe3ef4bb 100644
@@ -59,6 +59,62 @@ 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_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 byt 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 set in value) or 0 (if not) and preserve the rest. If the mask is
+omitted, it is supposed to be "all ones", i.e. set all bits according to
+value.
+
+Kernel bit set length may differ from userspace length if older application is
+used on newer kernel or vice versa. If userspace bitmaps are longer, error is
+only issued if request actually tries to set bits not implemented in kernel.
+
+Bit-by-bit form: nested (bitset) attribute contents:
+
+    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.
+
+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 +31 -0
index 1df263d9feb7..98d6fae315f3 100644
@@ -23,6 +23,37 @@ enum {
 	ETHA_DEV_MAX = (__ETHA_DEV_MAX - 1)
 };
 
+/* bit sets */
+
+enum {
+	ETHA_BIT_UNSPEC,
+	ETHA_BIT_INDEX,				/* u32 */
+	ETHA_BIT_NAME,				/* string */
+	ETHA_BIT_VALUE,				/* flag */
+
+	__ETHA_BIT_MAX,
+	ETHA_BIT_MAX = (__ETHA_BIT_MAX - 1)
+};
+
+enum {
+	ETHA_BITS_UNSPEC,
+	ETHA_BITS_BIT,
+
+	__ETHA_BITS_MAX,
+	ETHA_BITS_MAX = (__ETHA_BITS_MAX - 1)
+};
+
+enum {
+	ETHA_BITSET_UNSPEC,
+	ETHA_BITSET_SIZE,			/* u32 */
+	ETHA_BITSET_BITS,			/* nest - ETHA_BITS_* */
+	ETHA_BITSET_VALUE,			/* binary */
+	ETHA_BITSET_MASK,			/* binary */
+
+	__ETHA_BITSET_MAX,
+	ETHA_BITSET_MAX = (__ETHA_BITSET_MAX - 1)
+};
+
 /* generic netlink info */
 #define ETHTOOL_GENL_NAME "ethtool"
 #define ETHTOOL_GENL_VERSION 1
net/ethtool/netlink.c +395 -0

407 lines not on this page · raw message

net/ethtool/netlink.h +26 -0
index acfed5ba6b54..6e9e854eec5d 100644
@@ -20,6 +20,32 @@ 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
+
+int ethnl_bitset_size(bool compact, unsigned int size, unsigned long *val,
+		      unsigned long *mask, const char *const *names);
+int ethnl_bitset32_size(bool compact, unsigned int size, u32 *val, u32 *mask,
+			const char *const *names);
+int ethnl_put_bitset(struct sk_buff *skb, int attrtype, bool compact,
+		     unsigned int size, unsigned long *val, unsigned long *mask,
+		     const char *const *names);
+int ethnl_put_bitset32(struct sk_buff *skb, int attrtype, bool compact,
+		       unsigned int size, u32 *val, u32 *mask,
+		       const char *const *names);
+bool ethnl_update_bitset(unsigned long *bitmap, unsigned long *bitmask,
+			 unsigned int nbits, struct nlattr *attr, int *err,
+			 const char *const *names, struct genl_info *info);
+bool ethnl_update_bitset32(u32 *bitmap, u32 *bitmask, unsigned int nbits,
+			   struct nlattr *attr, int *err,
+			   const char *const *names, struct genl_info *info);
+
 static inline int ethnl_str_size(const char *s)
 {
 	return nla_total_size(strlen(s) + 1);
Signature · 1 line
2.18.0
#11 lore raw

RFC PATCH v2 8/17 ethtool: implement GET_STRSET message

In reply to Michal Kubecek

Requests a contents of a string set, i.e. indexed array 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 all "global" stringsets
- no NLM_F_DUMP, with device: get all string sets related to the device
- NLM_F_DUMP, no device: get all device related string sets for all devices

It's also possible to request only specific string sets.

In addition to string sets recognized by ioctl interface, GET_STRSET request can also retrieve list of link modes.

---
 Documentation/networking/ethtool-netlink.txt |   6 +-
 include/uapi/linux/ethtool.h                 |   4 +
 include/uapi/linux/ethtool_netlink.h         |  42 ++
 net/ethtool/Makefile                         |   2 +-
 net/ethtool/common.c                         |  87 +++
 net/ethtool/common.h                         |  13 +
 net/ethtool/ioctl.c                          |  80 ---
 net/ethtool/netlink.c                        |  13 +
 net/ethtool/strset.c                         | 552 +++++++++++++++++++
 9 files changed, 716 insertions(+), 83 deletions(-)
 create mode 100644 net/ethtool/common.c
 create mode 100644 net/ethtool/common.h
 create mode 100644 net/ethtool/strset.c
Documentation/networking/ethtool-netlink.txt +4 -2
index 0e83397f2975..8b43f41a8140 100644
@@ -119,6 +119,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.
@@ -188,7 +190,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
@@ -216,7 +218,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 +4 -0
index 7363f18e65a5..2ae393963704 100644
@@ -578,6 +578,10 @@ enum ethtool_stringset {
 	ETH_SS_TUNABLES,
 	ETH_SS_PHY_STATS,
 	ETH_SS_PHY_TUNABLES,
+	ETH_SS_LINK_MODES,
+
+	__ETH_SS_MAX,
+	ETH_SS_MAX = (__ETH_SS_MAX - 1)
 };
 
 /**
include/uapi/linux/ethtool_netlink.h +42 -0

54 lines not on this page · raw message

net/ethtool/Makefile +1 -1
index f30e0da88be5..ba260d5b53b2 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 strset.o
net/ethtool/common.c new file +87 -0

87 lines not on this page · raw message

net/ethtool/common.h new file +13 -0
new file mode 100644
index 000000000000..45c6492e4aee
@@ -0,0 +1,13 @@
+/* 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 +0 -80

86 lines not on this page · raw message

net/ethtool/netlink.c +13 -0
index 543560778c80..237a2cb40be4 100644
@@ -669,7 +669,20 @@ static struct notifier_block ethnl_netdev_notifier = {
 
 /* genetlink setup */
 
+int ethnl_get_strset(struct sk_buff *skb, struct genl_info *info);
+
+int ethnl_strset_start(struct netlink_callback *cb);
+
+int ethnl_strset_done(struct netlink_callback *cb);
+
 static const struct genl_ops ethtool_genl_ops[] = {
+	{
+		.cmd	= ETHNL_CMD_GET_STRSET,
+		.doit	= ethnl_get_strset,
+		.start	= ethnl_strset_start,
+		.dumpit	= ethnl_dumpit,
+		.done	= ethnl_strset_done,
+	},
 };
 
 static const struct genl_multicast_group ethtool_nl_mcgrps[] = {
net/ethtool/strset.c new file +552 -0

552 lines not on this page · raw message

Signature · 1 line
2.18.0
#10 lore raw

RFC PATCH v2 7/17 ethtool: implement EVENT notifications

In reply to Michal Kubecek

Two types of netlink notifications are introduced: ETHA_EVENT_NEWDEV to notify about newly registered network devices and ETHA_EVENT_DELDEV to notify about unregistered network devices. These are triggered by NETDEV_REGISTER and NETDEV_UNREGISTER notifiers.

These 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 | 22 ++++++++++
 include/uapi/linux/ethtool_netlink.h         | 28 +++++++++++++
 net/ethtool/netlink.c                        | 44 ++++++++++++++++++++
 3 files changed, 94 insertions(+)
Documentation/networking/ethtool-netlink.txt +22 -0
index a49dfe3ef4bb..0e83397f2975 100644
@@ -118,6 +118,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.
 
@@ -129,9 +131,29 @@ 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
+
+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 +28 -0
index 444a668e4a08..f162cd6f80d4 100644
@@ -7,6 +7,7 @@
 
 enum {
 	ETHNL_CMD_NOOP,
+	ETHNL_CMD_EVENT,		/* only for notifications */
 
 	__ETHNL_CMD_MAX,
 	ETHNL_CMD_MAX = (__ETHNL_CMD_MAX - 1)
@@ -54,6 +55,33 @@ enum {
 	ETHA_BITSET_MAX = (__ETHA_BITSET_MAX - 1)
 };
 
+/* events */
+
+enum {
+	ETHA_NEWDEV_UNSPEC,
+	ETHA_NEWDEV_DEV,			/* nest - ETHA_DEV_* */
+
+	__ETHA_NEWDEV_MAX,
+	ETHA_NEWDEV_MAX = (__ETHA_NEWDEV_MAX - 1)
+};
+
+enum {
+	ETHA_DELDEV_UNSPEC,
+	ETHA_DELDEV_DEV,			/* nest - ETHA_DEV_* */
+
+	__ETHA_DELDEV_MAX,
+	ETHA_DELDEV_MAX = (__ETHA_DELDEV_MAX - 1)
+};
+
+enum {
+	ETHA_EVENT_UNSPEC,
+	ETHA_EVENT_NEWDEV,			/* nest - ETHA_NEWDEV_* */
+	ETHA_EVENT_DELDEV,			/* nest - ETHA_DELDEV_* */
+
+	__ETHA_EVENT_MAX,
+	ETHA_EVENT_MAX = (__ETHA_EVENT_MAX - 1)
+};
+
 /* generic netlink info */
 #define ETHTOOL_GENL_NAME "ethtool"
 #define ETHTOOL_GENL_VERSION 1
net/ethtool/netlink.c +44 -0

56 lines not on this page · raw message

Signature · 1 line
2.18.0
#20 lore raw

RFC PATCH v2 10/17 ethtool: implement GET_SETTINGS message

In reply to Michal Kubecek

Requests the information provided by ETHTOOL_GLINKSETTINGS, ETHTOOL_GWOL and ETHTOOL_GMSGLVL. The info_mask header field can be used to request only part of the information. Flag ETH_SETTINGS_RF_COMPACT_BITSETS switches between flag-by-flag list and compact bitmaps for link modes in the reply.

---
 Documentation/networking/ethtool-netlink.txt |  69 ++-
 include/linux/ethtool_netlink.h              |   3 +
 include/linux/netdevice.h                    |   2 +
 include/uapi/linux/ethtool.h                 |   3 +
 include/uapi/linux/ethtool_netlink.h         |  37 ++
 net/ethtool/Makefile                         |   2 +-
 net/ethtool/common.c                         | 112 +++++
 net/ethtool/common.h                         |   8 +
 net/ethtool/ioctl.c                          | 108 +----
 net/ethtool/netlink.c                        |  69 +++
 net/ethtool/netlink.h                        |   2 +
 net/ethtool/settings.c                       | 416 +++++++++++++++++++
 12 files changed, 725 insertions(+), 106 deletions(-)
 create mode 100644 net/ethtool/settings.c
Documentation/networking/ethtool-netlink.txt +64 -5
index 1e3d5ffc97ab..60d426cf6dad 100644
@@ -123,6 +123,8 @@ List of message types
     ETHNL_CMD_SET_STRSET		response only
     ETHNL_CMD_GET_DRVINFO
     ETHNL_CMD_SET_DRVINFO		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.
@@ -192,6 +194,63 @@ GET_DRVINFO requests).
 GET_DRVINFO 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
+    ETH_SETTINGS_IM_MSGLEVEL		msglevel
+    ETH_SETTINGS_IM_WOLINFO		struct ethtool_wolinfo
+    ETH_SETTINGS_IM_LINK		link state
+
+Response contents:
+
+    ETHA_SETTINGS_DEV		(nested)	device identification
+    ETHA_SETTINGS_SPEED		(u32)		link speed (Mb/s)
+    ETHA_SETTINGS_DUPLEX	(u8)		duplex mode
+    ETHA_SETTINGS_PORT		(u8)		physical port
+    ETHA_SETTINGS_PHYADDR	(u8)		MDIO address of phy
+    ETHA_SETTINGS_AUTONEG	(u8)		autoneotiation status
+    ETHA_SETTINGS_MDIO_SUPPORT	(bitfield32)	MDIO support flags
+    ETHA_SETTINGS_TP_MDIX	(u8)		MDI(-X) status
+    ETHA_SETTINGS_TP_MDIX_CTRL	(u8)		MDI(-X) control
+    ETHA_SETTINGS_TRANSCEIVER	(u8)		transceiver
+    ETHA_SETTINGS_WOL_MODES	(bitfield32)	wake-on-lan modes
+    ETHA_SETTINGS_SOPASS	(binary)	SecureOn(tm) password
+    ETHA_SETTINGS_MSGLVL	(bitfield32)	debug level
+    ETHA_SETTINGS_LINK_MODES	(bitset)	device link modes
+    ETHA_SETTINGS_PEER_MODES	(bitset)	link partner link modes
+    ETHA_SETTINGS_LINK		(u32)		link state
+
+Most of the attributes have the same meaning (including values) as
+corresponding members of ioctl structures. For ETHA_SETTINGS_MDIO_SUPPORT and
+ETHA_SETTINGS_MSGLVL, selector reports flags supported by kernel. For
+ETHA_SETTINGS_WOL_MODES it reports flags supported by the device. For
+ETHA_SETTINGS_LINK_MODES, value represent advertised modes and mask represents
+supported modes. For ETHA_SETTINGS_PEER_MODES, both value and mask represent
+partner advertised link 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.
+
+
 Request translation
 -------------------
 
@@ -201,16 +260,16 @@ 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_DRVINFO
 ETHTOOL_GREGS			n/a
-ETHTOOL_GWOL			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
+ETHTOOL_GLINK			ETHNL_CMD_GET_SETTINGS
 ETHTOOL_GEEPROM			n/a
 ETHTOOL_SEEPROM			n/a
 ETHTOOL_GCOALESCE		n/a
@@ -275,7 +334,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..fba8ff961887 100644
@@ -7,6 +7,9 @@
 #include <linux/ethtool.h>
 #include <linux/netdevice.h>
 
+#define __ETHTOOL_LINK_MODE_MASK_NWORDS \
+	((__ETHTOOL_LINK_MODE_MASK_NBITS + 31) / 32)
+
 enum ethtool_multicast_groups {
 	ETHNL_MCGRP_MONITOR,
 };
include/linux/netdevice.h +2 -0
index c4b0c575d57e..93071380558c 100644
@@ -3738,6 +3738,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.h +3 -0
index 2ae393963704..98f645a38168 100644
@@ -143,6 +143,9 @@ static inline __u32 ethtool_cmd_speed(const struct ethtool_cmd *ep)
  */
 #define ETH_MDIO_SUPPORTS_C45	2
 
+/* All defined ETH_MDIO_SUPPORTS_* flags */
+#define ETH_MDIO_SUPPORTS_ALL (ETH_MDIO_SUPPORTS_C22 | ETH_MDIO_SUPPORTS_C45)
+
 #define ETHTOOL_FWVERS_LEN	32
 #define ETHTOOL_BUSINFO_LEN	32
 #define ETHTOOL_EROMVERS_LEN	32
include/uapi/linux/ethtool_netlink.h +37 -0
index df4de61fac48..66df44aa7226 100644
@@ -12,6 +12,8 @@ enum {
 	ETHNL_CMD_SET_STRSET,		/* only for reply */
 	ETHNL_CMD_GET_DRVINFO,
 	ETHNL_CMD_SET_DRVINFO,		/* only for reply */
+	ETHNL_CMD_GET_SETTINGS,
+	ETHNL_CMD_SET_SETTINGS,
 
 	__ETHNL_CMD_MAX,
 	ETHNL_CMD_MAX = (__ETHNL_CMD_MAX - 1)
@@ -146,6 +148,41 @@ enum {
 	ETHA_DRVINFO_MAX = (__ETHA_DRVINFO_MAX - 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_SPEED,			/* u32 */
+	ETHA_SETTINGS_DUPLEX,			/* u8 */
+	ETHA_SETTINGS_PORT,			/* u8 */
+	ETHA_SETTINGS_PHYADDR,			/* u8 */
+	ETHA_SETTINGS_AUTONEG,			/* u8 */
+	ETHA_SETTINGS_MDIO_SUPPORT,		/* bitfield32 */
+	ETHA_SETTINGS_TP_MDIX,			/* u8 */
+	ETHA_SETTINGS_TP_MDIX_CTRL,		/* u8 */
+	ETHA_SETTINGS_TRANSCEIVER,		/* u8 */
+	ETHA_SETTINGS_WOL_MODES,		/* bitfield32 */
+	ETHA_SETTINGS_SOPASS,			/* binary */
+	ETHA_SETTINGS_MSGLVL,			/* bitfield32 */
+	ETHA_SETTINGS_LINK_MODES,		/* bitset */
+	ETHA_SETTINGS_PEER_MODES,		/* bitset */
+	ETHA_SETTINGS_LINK,			/* u32 */
+
+	__ETHA_SETTINGS_MAX,
+	ETHA_SETTINGS_MAX = (__ETHA_SETTINGS_MAX - 1)
+};
+
+#define ETH_SETTINGS_IM_LINKINFO		0x01
+#define ETH_SETTINGS_IM_LINKMODES		0x02
+#define ETH_SETTINGS_IM_MSGLEVEL		0x04
+#define ETH_SETTINGS_IM_WOLINFO			0x08
+#define ETH_SETTINGS_IM_LINK			0x10
+
+#define ETH_SETTINGS_IM_DEFAULT			0x1f
+
 /* generic netlink info */
 #define ETHTOOL_GENL_NAME "ethtool"
 #define ETHTOOL_GENL_VERSION 1
net/ethtool/Makefile +1 -1
index 2e840ae0ba1e..8dd98310ed6f 100644
@@ -4,4 +4,4 @@ obj-y				+= ioctl.o common.o
 
 obj-$(CONFIG_ETHTOOL_NETLINK)	+= ethtool_nl.o
 
-ethtool_nl-y	:= netlink.o strset.o drvinfo.o
+ethtool_nl-y	:= netlink.o strset.o drvinfo.o settings.o
net/ethtool/common.c +112 -0

115 lines not on this page · raw message

net/ethtool/common.h +8 -0
index 0f768c1be527..ec90d4ccddf7 100644
@@ -12,5 +12,13 @@ extern const char 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);
+int __ethtool_get_wol(struct net_device *dev, struct ethtool_wolinfo *wol);
+int __ethtool_get_link_ksettings(struct net_device *dev,
+				 struct ethtool_link_ksettings *link_ksettings);
+int __ethtool_get_link(struct net_device *dev);
+
+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 +8 -100

135 lines not on this page · raw message

net/ethtool/netlink.c +69 -0

104 lines not on this page · raw message

net/ethtool/netlink.h +2 -0
index 94c14ec2c3fc..789aceae9f5e 100644
@@ -15,6 +15,8 @@ extern u32 ethnl_bcast_seq;
 
 extern struct genl_family ethtool_genl_family;
 
+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/settings.c new file +416 -0

416 lines not on this page · raw message

Signature · 1 line
2.18.0
#28 lore raw

RFC PATCH v2 11/17 ethtool: implement GET_SETTINGS request for features

In reply to Michal Kubecek

With ETH_SETTINGS_IM_FEATURES info mask, ETHNL_CMD_GET_SETTINGS request gets network device feature values. This is the same information as provided via ETHTOOL_GFEATURES ioctl request.

---
 Documentation/networking/ethtool-netlink.txt |  33 ++--
 include/uapi/linux/ethtool_netlink.h         |  15 +-
 net/ethtool/common.h                         |   2 +
 net/ethtool/ioctl.c                          |   2 -
 net/ethtool/settings.c                       | 151 +++++++++++++++++++
 5 files changed, 191 insertions(+), 12 deletions(-)
Documentation/networking/ethtool-netlink.txt +24 -9
index 60d426cf6dad..82b839c03707 100644
@@ -214,6 +214,7 @@ Info mask bits meaning:
     ETH_SETTINGS_IM_MSGLEVEL		msglevel
     ETH_SETTINGS_IM_WOLINFO		struct ethtool_wolinfo
     ETH_SETTINGS_IM_LINK		link state
+    ETH_SETTINGS_IM_FEATURES		features
 
 Response contents:
 
@@ -233,6 +234,11 @@ Response contents:
     ETHA_SETTINGS_LINK_MODES	(bitset)	device link modes
     ETHA_SETTINGS_PEER_MODES	(bitset)	link partner link modes
     ETHA_SETTINGS_LINK		(u32)		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 have the same meaning (including values) as
 corresponding members of ioctl structures. For ETHA_SETTINGS_MDIO_SUPPORT and
@@ -242,6 +248,15 @@ ETHA_SETTINGS_LINK_MODES, value represent advertised modes and mask represents
 supported modes. For ETHA_SETTINGS_PEER_MODES, both value and mask represent
 partner advertised link modes.
 
+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.
@@ -278,30 +293,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		n/a
-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
@@ -316,7 +331,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 66df44aa7226..06c78b281275 100644
@@ -170,6 +170,7 @@ enum {
 	ETHA_SETTINGS_LINK_MODES,		/* bitset */
 	ETHA_SETTINGS_PEER_MODES,		/* bitset */
 	ETHA_SETTINGS_LINK,			/* u32 */
+	ETHA_SETTINGS_FEATURES,			/* nest - ETHA_FEATURES_* */
 
 	__ETHA_SETTINGS_MAX,
 	ETHA_SETTINGS_MAX = (__ETHA_SETTINGS_MAX - 1)
@@ -180,8 +181,20 @@ enum {
 #define ETH_SETTINGS_IM_MSGLEVEL		0x04
 #define ETH_SETTINGS_IM_WOLINFO			0x08
 #define ETH_SETTINGS_IM_LINK			0x10
+#define ETH_SETTINGS_IM_FEATURES		0x20
 
-#define ETH_SETTINGS_IM_DEFAULT			0x1f
+#define ETH_SETTINGS_IM_DEFAULT			0x3f
+
+enum {
+	ETHA_FEATURES_UNSPEC,
+	ETHA_FEATURES_HW,			/* bitset */
+	ETHA_FEATURES_WANTED,			/* bitset */
+	ETHA_FEATURES_ACTIVE,			/* bitset */
+	ETHA_FEATURES_NOCHANGE,			/* bitset */
+
+	__ETHA_FEATURES_MAX,
+	ETHA_FEATURES_MAX = (__ETHA_FEATURES_MAX - 1)
+};
 
 /* generic netlink info */
 #define ETHTOOL_GENL_NAME "ethtool"
net/ethtool/common.h +2 -0
index ec90d4ccddf7..3b00ed6bfe10 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 rss_hash_func_strings[ETH_RSS_HASH_FUNCS_COUNT][ETH_GSTRING_LEN];
 extern const char tunable_strings[__ETHTOOL_TUNABLE_COUNT][ETH_GSTRING_LEN];
net/ethtool/ioctl.c +0 -2
index 8613434b6fc0..39e9aea60516 100644
@@ -54,8 +54,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 +151 -0

193 lines not on this page · raw message

Signature · 1 line
2.18.0
#29 lore raw

RFC PATCH v2 12/17 ethtool: implement SET_SETTINGS notification

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.

Also trigger the notification on analogous changes performed via the legacy ioctl interface.

---
 Documentation/networking/ethtool-netlink.txt |  3 +-
 net/core/dev.c                               |  3 ++
 net/ethtool/ioctl.c                          | 36 +++++++++++++++--
 net/ethtool/netlink.c                        |  2 +
 net/ethtool/settings.c                       | 41 ++++++++++++++++++++
 5 files changed, 80 insertions(+), 5 deletions(-)
Documentation/networking/ethtool-netlink.txt +2 -1
index 82b839c03707..3993652f81a9 100644
@@ -263,7 +263,8 @@ 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
net/core/dev.c +3 -0
index 8a0773a52dd7..66932a9f133e 100644
@@ -93,6 +93,7 @@
 #include <linux/netdevice.h>
 #include <linux/etherdevice.h>
 #include <linux/ethtool.h>
+#include <linux/ethtool_netlink.h>
 #include <linux/notifier.h>
 #include <linux/skbuff.h>
 #include <linux/bpf.h>
@@ -1318,6 +1319,8 @@ int dev_get_alias(const struct net_device *dev, char *name, size_t len)
 void netdev_features_change(struct net_device *dev)
 {
 	call_netdevice_notifiers(NETDEV_FEAT_CHANGE, dev);
+	netdev_ethtool_info_change(dev, NULL, ETHNL_CMD_SET_SETTINGS,
+				   ETH_SETTINGS_IM_FEATURES);
 }
 EXPORT_SYMBOL(netdev_features_change);
 
net/ethtool/ioctl.c +32 -4
index 39e9aea60516..2754d3f6fd75 100644
@@ -27,6 +27,7 @@
 #include <linux/rtnetlink.h>
 #include <linux/sched/signal.h>
 #include <linux/net.h>
+#include <linux/ethtool_netlink.h>
 #include "common.h"
 
 /*
@@ -125,6 +126,8 @@ static int ethtool_set_features(struct net_device *dev, void __user *useraddr)
 	dev->wanted_features &= ~valid;
 	dev->wanted_features |= wanted & valid;
 	__netdev_update_features(dev);
+	netdev_ethtool_info_change(dev, NULL, ETHNL_CMD_SET_SETTINGS,
+				   ETH_SETTINGS_IM_FEATURES);
 
 	if ((dev->wanted_features ^ dev->features) & valid)
 		ret |= ETHTOOL_F_WISH;
@@ -243,6 +246,8 @@ static int ethtool_set_one_feature(struct net_device *dev,
 		dev->wanted_features &= ~mask;
 
 	__netdev_update_features(dev);
+	netdev_ethtool_info_change(dev, NULL, ETHNL_CMD_SET_SETTINGS,
+				   ETH_SETTINGS_IM_FEATURES);
 
 	return 0;
 }
@@ -298,6 +303,8 @@ static int __ethtool_set_flags(struct net_device *dev, u32 data)
 		(dev->wanted_features & ~changed) | (features & changed);
 
 	__netdev_update_features(dev);
+	netdev_ethtool_info_change(dev, NULL, ETHNL_CMD_SET_SETTINGS,
+				   ETH_SETTINGS_IM_FEATURES);
 
 	return 0;
 }
@@ -638,6 +645,7 @@ static int ethtool_get_settings(struct net_device *dev, void __user *useraddr)
 static int ethtool_set_settings(struct net_device *dev, void __user *useraddr)
 {
 	struct ethtool_cmd cmd;
+	int ret;
 
 	ASSERT_RTNL();
 
@@ -655,8 +663,14 @@ static int ethtool_set_settings(struct net_device *dev, void __user *useraddr)
 		link_ksettings.base.cmd = ETHTOOL_SLINKSETTINGS;
 		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)
+			netdev_ethtool_info_change(dev, NULL,
+						   ETHNL_CMD_SET_SETTINGS,
+						   ETH_SETTINGS_IM_LINKINFO |
+						   ETH_SETTINGS_IM_LINKMODES);
+		return ret;
 	}
 
 	/* legacy %ethtool_cmd API */
@@ -668,7 +682,12 @@ static int ethtool_set_settings(struct net_device *dev, void __user *useraddr)
 	if (!dev->ethtool_ops->set_settings)
 		return -EOPNOTSUPP;
 
-	return dev->ethtool_ops->set_settings(dev, &cmd);
+	ret = dev->ethtool_ops->set_settings(dev, &cmd);
+	if (ret >= 0)
+		netdev_ethtool_info_change(dev, NULL, ETHNL_CMD_SET_SETTINGS,
+					   ETH_SETTINGS_IM_LINKINFO |
+					   ETH_SETTINGS_IM_LINKMODES);
+	return ret;
 }
 
 static noinline_for_stack int ethtool_get_drvinfo(struct net_device *dev,
@@ -1279,6 +1298,7 @@ static int ethtool_get_wol(struct net_device *dev, char __user *useraddr)
 static int ethtool_set_wol(struct net_device *dev, char __user *useraddr)
 {
 	struct ethtool_wolinfo wol;
+	int ret;
 
 	if (!dev->ethtool_ops->set_wol)
 		return -EOPNOTSUPP;
@@ -1286,7 +1306,11 @@ static int ethtool_set_wol(struct net_device *dev, char __user *useraddr)
 	if (copy_from_user(&wol, useraddr, sizeof(wol)))
 		return -EFAULT;
 
-	return dev->ethtool_ops->set_wol(dev, &wol);
+	ret = dev->ethtool_ops->set_wol(dev, &wol);
+	if (ret >= 0)
+		netdev_ethtool_info_change(dev, NULL, ETHNL_CMD_SET_SETTINGS,
+					   ETH_SETTINGS_IM_WOLINFO);
+	return ret;
 }
 
 static int ethtool_get_eee(struct net_device *dev, char __user *useraddr)
@@ -2478,6 +2502,10 @@ 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)
+			netdev_ethtool_info_change(dev, NULL,
+						   ETHNL_CMD_SET_SETTINGS,
+						   ETH_SETTINGS_IM_MSGLEVEL);
 		break;
 	case ETHTOOL_GEEE:
 		rc = ethtool_get_eee(dev, useraddr);
net/ethtool/netlink.c +2 -0
index 6c14185a6466..0e2158092a44 100644
@@ -629,7 +629,9 @@ int ethnl_dumpit(struct sk_buff *skb, struct netlink_callback *cb)
 
 typedef void (*ethnl_notify_handler_t)(struct netdev_notifier_ethtool_info *);
 
+void ethnl_settings_notify(struct netdev_notifier_ethtool_info *);
 ethnl_notify_handler_t ethnl_notify_handlers[] = {
+	[ETHNL_CMD_SET_SETTINGS]	= ethnl_settings_notify,
 };
 
 static void __ethnl_notify(struct netdev_notifier_ethtool_info *info)
net/ethtool/settings.c +41 -0

44 lines not on this page · raw message

Signature · 1 line
2.18.0
#30 lore raw

RFC PATCH v2 13/17 ethtool: implement SET_SETTINGS message

In reply to Michal Kubecek

Sets the information provided by ETHTOOL_SLINKSETTINGS, ETHTOOL_SWOL and ETHTOOL_SMSGLVL. Unlike with ioctl(), userspace can send only some attributes so that we only need to call ethtool_ops callbacks which we really need (and the "set" callback is only called when we actually changed some setting).

---
 Documentation/networking/ethtool-netlink.txt |  43 +-
 net/ethtool/netlink.c                        |   6 +
 net/ethtool/settings.c                       | 495 +++++++++++++++++++
 3 files changed, 539 insertions(+), 5 deletions(-)
Documentation/networking/ethtool-netlink.txt +38 -5
index 3993652f81a9..c7fe4f518972 100644
@@ -124,7 +124,7 @@ List of message types
     ETHNL_CMD_GET_DRVINFO
     ETHNL_CMD_SET_DRVINFO		response only
     ETHNL_CMD_GET_SETTINGS
-    ETHNL_CMD_SET_SETTINGS		response only (for now)
+    ETHNL_CMD_SET_SETTINGS
 
 All constants use ETHNL_CMD_ prefix, usually followed by "GET", "SET" or "ACT"
 to indicate the type.
@@ -267,6 +267,39 @@ netlink or ioctl ethtool interface; feature notifications are also sent
 whenever netdev_update_features() or netdev_change_features() is called.
 
 
+SET_SETTINGS
+------------
+
+SET_SETTINGS request allows setting some of the data reported by GET_SETTINGS.
+Request flags, info_mask and index are ignored. These attributes are allowed
+to be passed with SET_SETTINGS request:
+
+    ETHA_SETTINGS_DEV		(nested)	device identification
+    ETHA_SETTINGS_SPEED         (u32)           link speed (Mb/s)
+    ETHA_SETTINGS_DUPLEX        (u8)            duplex mode
+    ETHA_SETTINGS_PORT          (u8)            physical port
+    ETHA_SETTINGS_PHYADDR       (u8)            MDIO address of phy
+    ETHA_SETTINGS_AUTONEG       (u8)            autoneotiation status
+    ETHA_SETTINGS_TP_MDIX_CTRL  (u8)            MDI(-X) control
+    ETHA_SETTINGS_WOL_MODES     (bitfield32)    wake-on-lan modes
+    ETHA_SETTINGS_SOPASS        (binary)        SecureOn(tm) password
+    ETHA_SETTINGS_MSGLVL        (bitfield32)    debug level
+    ETHA_SETTINGS_LINK_MODES    (bitset)        device link modes
+
+For both bitfield32 types, value and selector work the usual way, i.e. bits
+set in selector are set to corresponding bits from value and the rest is
+preserved. In a similar fashion, ETHA_SETTINGS_LINK_MODES allows setting
+advertised link modes.
+
+If autonegotiation is on (either set now or kept from before), advertised
+modes are not changed (no ETHA_SETTINGS_LINK_MODES attribute) and at least one
+of speed and duplex is specified, kernel adjusts advertised modes to all
+supported modes matching speed, duplex or both (whatever is specified). This
+autoselection is done on ethtool side with ioctl interface, netlink interface
+is supposed to allow requesting changes without knowing what exactly kernel
+supports.
+
+
 Request translation
 -------------------
 
@@ -277,13 +310,13 @@ have their netlink replacement yet.
 ioctl command			netlink command
 ---------------------------------------------------------------------
 ETHTOOL_GSET			ETHNL_CMD_GET_SETTINGS
-ETHTOOL_SSET			n/a
+ETHTOOL_SSET			ETHNL_CMD_SET_SETTINGS
 ETHTOOL_GDRVINFO		ETHNL_CMD_GET_DRVINFO
 ETHTOOL_GREGS			n/a
 ETHTOOL_GWOL			ETHNL_CMD_GET_SETTINGS
-ETHTOOL_SWOL			n/a
+ETHTOOL_SWOL			ETHNL_CMD_SET_SETTINGS
 ETHTOOL_GMSGLVL			ETHNL_CMD_GET_SETTINGS
-ETHTOOL_SMSGLVL			n/a
+ETHTOOL_SMSGLVL			ETHNL_CMD_SET_SETTINGS
 ETHTOOL_NWAY_RST		n/a
 ETHTOOL_GLINK			ETHNL_CMD_GET_SETTINGS
 ETHTOOL_GEEPROM			n/a
@@ -351,7 +384,7 @@ ETHTOOL_STUNABLE		n/a
 ETHTOOL_GPHYSTATS		n/a
 ETHTOOL_PERQUEUE		n/a
 ETHTOOL_GLINKSETTINGS		ETHNL_CMD_GET_SETTINGS
-ETHTOOL_SLINKSETTINGS		n/a
+ETHTOOL_SLINKSETTINGS		ETHNL_CMD_SET_SETTINGS
 ETHTOOL_PHY_GTUNABLE		n/a
 ETHTOOL_PHY_STUNABLE		n/a
 ETHTOOL_GFECPARAM		n/a
net/ethtool/netlink.c +6 -0
index 0e2158092a44..6e183caca01f 100644
@@ -730,6 +730,7 @@ static struct notifier_block ethnl_netdev_notifier = {
 int ethnl_get_strset(struct sk_buff *skb, struct genl_info *info);
 int ethnl_get_drvinfo(struct sk_buff *skb, struct genl_info *info);
 int ethnl_get_settings(struct sk_buff *skb, struct genl_info *info);
+int ethnl_set_settings(struct sk_buff *skb, struct genl_info *info);
 
 int ethnl_strset_start(struct netlink_callback *cb);
 int ethnl_drvinfo_start(struct netlink_callback *cb);
@@ -759,6 +760,11 @@ static const struct genl_ops ethtool_genl_ops[] = {
 		.dumpit	= ethnl_dumpit,
 		.done	= ethnl_settings_done,
 	},
+	{
+		.cmd	= ETHNL_CMD_SET_SETTINGS,
+		.flags	= GENL_UNS_ADMIN_PERM,
+		.doit	= ethnl_set_settings,
+	},
 };
 
 static const struct genl_multicast_group ethtool_nl_mcgrps[] = {
net/ethtool/settings.c +495 -0

504 lines not on this page · raw message

Signature · 1 line
2.18.0
#32 lore raw

RFC PATCH v2 15/17 ethtool: implement GET_PARAMS message

In reply to Michal Kubecek

Requests the information provide by ETHTOOL_GCOALESCE, ETHTOOL_GRINGPARAM, ETHTOOL_GPAUSEPARAM, ETHTOOL_GCHANNELS, ETHTOOL_GEEE and ETHTOOL_GFECPARAM. Flags in info_mask allow selecting only some (or on) of these categories.

---
 Documentation/networking/ethtool-netlink.txt | 107 +++-
 include/uapi/linux/ethtool_netlink.h         | 119 ++++
 net/ethtool/Makefile                         |   2 +-
 net/ethtool/netlink.c                        |  10 +
 net/ethtool/params.c                         | 539 +++++++++++++++++++
 5 files changed, 770 insertions(+), 7 deletions(-)
 create mode 100644 net/ethtool/params.c
Documentation/networking/ethtool-netlink.txt +101 -6
index 307d8c6c6c85..630eebd7e741 100644
@@ -125,6 +125,8 @@ List of message types
     ETHNL_CMD_SET_DRVINFO		response only
     ETHNL_CMD_GET_SETTINGS
     ETHNL_CMD_SET_SETTINGS
+    ETHNL_CMD_GET_PARAMS
+    ETHNL_CMD_SET_PARAMS		response only (for now)
 
 All constants use ETHNL_CMD_ prefix, usually followed by "GET", "SET" or "ACT"
 to indicate the type.
@@ -314,6 +316,99 @@ the operation); mask shows bits which have been changed and value their new
 values.
 
 
+GET_PARAMS
+----------
+
+GET_PARAMS request retrieves information provided by legacy comands
+ETHTOOL_GCOALESCE (coalescing setting), ETHTOOL_GRINGPARAM (ring parameters),
+ETHTOOL_GPAUSEPARAM (pause parameters), ETHTOOL_GCHANNELS (channel settings),
+ETHTOOL_GEEE (EEE settings) and ETHTOOL_GFECPARAM (FEC parameters). For each
+of these, there is a bit in header info_mask so that only one type of
+information can be requested.
+
+Request contents:
+
+    ETHA_PARAMS_DEV		(nested)	device identification
+    ETHA_PARAMS_INFOMASK	(u32)		info mask
+    ETHA_PARAMS_COMPACT		(flag)		request compact bitsets
+
+Info mask bits:
+
+    ETH_PARAMS_IM_COALESCE		coalescing settings
+    ETH_PARAMS_IM_RING			ring parameters
+    ETH_PARAMS_IM_PAUSE			pause parameters
+    ETH_PARAMS_IM_CHANNELS		channel settings
+    ETH_PARAMS_IM_EEE			EEE settings
+    ETH_PARAMS_IM_FEC			FEC parameters
+
+Response contents: On top level, there is one attribute for each of the
+information categories, the information is nested in it.
+
+    ETHA_PARAMS_DEV		(nested)	device identification
+    ETHA_PARAMS_COALESCE	(nested)	coalescing
+        ETHA_COALESCE_RX_USECS			(u32)
+        ETHA_COALESCE_RX_MAXFRM			(u32)
+        ETHA_COALESCE_RX_USECS_IRQ		(u32)
+        ETHA_COALESCE_RX_MAXFRM_IRQ		(u32)
+        ETHA_COALESCE_RX_USECS_LOW		(u32)
+        ETHA_COALESCE_RX_MAXFRM_LOW		(u32)
+        ETHA_COALESCE_RX_USECS_HIGH		(u32)
+        ETHA_COALESCE_RX_MAXFRM_HIGH		(u32)
+        ETHA_COALESCE_TX_USECS			(u32)
+        ETHA_COALESCE_TX_MAXFRM			(u32)
+        ETHA_COALESCE_TX_USECS_IRQ		(u32)
+        ETHA_COALESCE_TX_MAXFRM_IRQ		(u32)
+        ETHA_COALESCE_TX_USECS_LOW		(u32)
+        ETHA_COALESCE_TX_MAXFRM_LOW		(u32)
+        ETHA_COALESCE_TX_USECS_HIGH		(u32)
+        ETHA_COALESCE_TX_MAXFRM_HIGH		(u32)
+        ETHA_COALESCE_PKT_RATE_LOW		(u32)
+        ETHA_COALESCE_PKT_RATE_HIGH		(u32)
+        ETHA_COALESCE_RX_USE_ADAPTIVE		(bool)
+        ETHA_COALESCE_TX_USE_ADAPTIVE		(bool)
+        ETHA_COALESCE_RATE_SAMPLE_INTERVAL	(u32)
+        ETHA_COALESCE_STATS_BLOCK_USECS		(u32)
+    ETHA_PARAMS_RING		(nested)	ring parameters
+        ETHA_RING_RX_MAX_PENDING		(u32)
+        ETHA_RING_RX_MINI_MAX_PENDING		(u32)
+        ETHA_RING_RX_JUMBO_MAX_PENDING		(u32)
+        ETHA_RING_TX_MAX_PENDING		(u32)
+        ETHA_RING_RX_PENDING			(u32)
+        ETHA_RING_RX_MINI_PENDING		(u32)
+        ETHA_RING_RX_JUMBO_PENDING		(u32)
+        ETHA_RING_TX_PENDING			(u32)
+    ETHA_PARAMS_PAUSE		(nested)	pause parameters
+        ETHA_PAUSE_AUTONEG			(bool)
+        ETHA_PAUSE_RX				(bool)
+        ETHA_PAUSE_TX				(bool)
+    ETHA_PARAMS_CHANNELS	(nested)	channel settings
+        ETHA_CHANNELS_MAX_RX			(u32)
+        ETHA_CHANNELS_MAX_TX			(u32)
+        ETHA_CHANNELS_MAX_OTHER			(u32)
+        ETHA_CHANNELS_MAX_COMBINED		(u32)
+        ETHA_CHANNELS_RX_COUNT			(u32)
+        ETHA_CHANNELS_TX_COUNT			(u32)
+        ETHA_CHANNELS_OTHER_COUNT		(u32)
+        ETHA_CHANNELS_COMBINED_COUNT		(u32)
+    ETHA_PARAMS_EEE		(nested)	EEE settings
+        ETHA_EEE_LINK_MODES			(bitset)
+		- modes for which EEE is advertised (value) or supported (mask)
+        ETHA_EEE_PEER_MODES			(bitset)
+		- modes for which link partner advertises EEE
+        ETHA_EEE_ACTIVE				(bool)
+        ETHA_EEE_ENABLED			(bool)
+        ETHA_EEE_TX_LPI_ENABLED			(bool)
+        ETHA_EEE_TX_LPI_TIMER			(u32)
+    ETHA_PARAMS_FEC		(nested)	FEC parameters
+        ETHA_FEC_MODES				(bitfield32)
+		- active (value) and configured (selector) FEC encodings
+
+GET_PARAMS 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
 -------------------
 
@@ -335,11 +430,11 @@ ETHTOOL_NWAY_RST		n/a
 ETHTOOL_GLINK			ETHNL_CMD_GET_SETTINGS
 ETHTOOL_GEEPROM			n/a
 ETHTOOL_SEEPROM			n/a
-ETHTOOL_GCOALESCE		n/a
+ETHTOOL_GCOALESCE		ETHNL_CMD_GET_PARAMS
 ETHTOOL_SCOALESCE		n/a
-ETHTOOL_GRINGPARAM		n/a
+ETHTOOL_GRINGPARAM		ETHNL_CMD_GET_PARAMS
 ETHTOOL_SRINGPARAM		n/a
-ETHTOOL_GPAUSEPARAM		n/a
+ETHTOOL_GPAUSEPARAM		ETHNL_CMD_GET_PARAMS
 ETHTOOL_SPAUSEPARAM		n/a
 ETHTOOL_GRXCSUM			ETHNL_CMD_GET_SETTINGS
 ETHTOOL_SRXCSUM			ETHNL_CMD_SET_SETTINGS
@@ -381,7 +476,7 @@ ETHTOOL_GRXFHINDIR		n/a
 ETHTOOL_SRXFHINDIR		n/a
 ETHTOOL_GFEATURES		ETHNL_CMD_GET_SETTINGS
 ETHTOOL_SFEATURES		n/a
-ETHTOOL_GCHANNELS		n/a
+ETHTOOL_GCHANNELS		ETHNL_CMD_GET_PARAMS
 ETHTOOL_SCHANNELS		n/a
 ETHTOOL_SET_DUMP		n/a
 ETHTOOL_GET_DUMP_FLAG		n/a
@@ -389,7 +484,7 @@ 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_GEEE			ETHNL_CMD_GET_PARAMS
 ETHTOOL_SEEE			n/a
 ETHTOOL_GRSSH			n/a
 ETHTOOL_SRSSH			n/a
@@ -401,6 +496,6 @@ ETHTOOL_GLINKSETTINGS		ETHNL_CMD_GET_SETTINGS
 ETHTOOL_SLINKSETTINGS		ETHNL_CMD_SET_SETTINGS
 ETHTOOL_PHY_GTUNABLE		n/a
 ETHTOOL_PHY_STUNABLE		n/a
-ETHTOOL_GFECPARAM		n/a
+ETHTOOL_GFECPARAM		ETHNL_CMD_GET_PARAMS
 ETHTOOL_SFECPARAM		n/a
 
include/uapi/linux/ethtool_netlink.h +119 -0

131 lines not on this page · raw message

net/ethtool/Makefile +1 -1
index 8dd98310ed6f..10aeedcee336 100644
@@ -4,4 +4,4 @@ obj-y				+= ioctl.o common.o
 
 obj-$(CONFIG_ETHTOOL_NETLINK)	+= ethtool_nl.o
 
-ethtool_nl-y	:= netlink.o strset.o drvinfo.o settings.o
+ethtool_nl-y	:= netlink.o strset.o drvinfo.o settings.o params.o
net/ethtool/netlink.c +10 -0
index 6e183caca01f..721101ed2ab6 100644
@@ -731,13 +731,16 @@ int ethnl_get_strset(struct sk_buff *skb, struct genl_info *info);
 int ethnl_get_drvinfo(struct sk_buff *skb, struct genl_info *info);
 int ethnl_get_settings(struct sk_buff *skb, struct genl_info *info);
 int ethnl_set_settings(struct sk_buff *skb, struct genl_info *info);
+int ethnl_get_params(struct sk_buff *skb, struct genl_info *info);
 
 int ethnl_strset_start(struct netlink_callback *cb);
 int ethnl_drvinfo_start(struct netlink_callback *cb);
 int ethnl_settings_start(struct netlink_callback *cb);
+int ethnl_params_start(struct netlink_callback *cb);
 
 int ethnl_strset_done(struct netlink_callback *cb);
 int ethnl_settings_done(struct netlink_callback *cb);
+int ethnl_params_done(struct netlink_callback *cb);
 
 static const struct genl_ops ethtool_genl_ops[] = {
 	{
@@ -765,6 +768,13 @@ static const struct genl_ops ethtool_genl_ops[] = {
 		.flags	= GENL_UNS_ADMIN_PERM,
 		.doit	= ethnl_set_settings,
 	},
+	{
+		.cmd	= ETHNL_CMD_GET_PARAMS,
+		.doit	= ethnl_get_params,
+		.start	= ethnl_params_start,
+		.dumpit	= ethnl_dumpit,
+		.done	= ethnl_params_done,
+	},
 };
 
 static const struct genl_multicast_group ethtool_nl_mcgrps[] = {
net/ethtool/params.c new file +539 -0

539 lines not on this page · raw message

Signature · 1 line
2.18.0
#31 lore raw

RFC PATCH v2 14/17 ethtool: implement SET_SETTINGS request for features

In reply to Michal Kubecek

Using ETHNL_SETTINGS_FEATURES attribute, userspace can modify device features. Actual change is subject to netdev_change_features() sanity checks so that it can differ from what was requested. Unlike with most other requests, kernel can reply (if ETHA_FEATURES_WANT_DIFF flag is used) with a message in the same format but with different semantics: information about difference between user request and actual result and difference between old and new state of dev->features.

---
 Documentation/networking/ethtool-netlink.txt |  30 +++--
 include/uapi/linux/ethtool_netlink.h         |   1 +
 net/ethtool/settings.c                       | 127 +++++++++++++++++++
 3 files changed, 150 insertions(+), 8 deletions(-)
Documentation/networking/ethtool-netlink.txt +22 -8
index c7fe4f518972..307d8c6c6c85 100644
@@ -285,6 +285,9 @@ to be passed with SET_SETTINGS request:
     ETHA_SETTINGS_SOPASS        (binary)        SecureOn(tm) password
     ETHA_SETTINGS_MSGLVL        (bitfield32)    debug level
     ETHA_SETTINGS_LINK_MODES    (bitset)        device link modes
+    ETHA_SETTINGS_FEATURES	(nested)	device features
+        ETHA_FEATURES_WANTED		(bitset)	wanted features
+        ETHA_FEATURES_WANT_DIFF		(flag)		actual diff
 
 For both bitfield32 types, value and selector work the usual way, i.e. bits
 set in selector are set to corresponding bits from value and the rest is
@@ -299,6 +302,17 @@ autoselection is done on ethtool side with ioctl interface, netlink interface
 is supposed to allow requesting changes without knowing what exactly kernel
 supports.
 
+When changing device features, only ETHA_FEATURES_WANTED is passed. As usual,
+mask defines which bits are to be set and value their values. If the request
+has ETHA_FEATURES_WANT_DIFF flag set, reply will contain a message in the same
+format as response to GET request, except only two bitsets are provided.
+ETHA_FEATURES_WANTED shows difference between requested features and actual
+result (dev->features after the operation); mask shows bits which differ and
+value their values from the original request (new values are negated). Value
+shows changes between old dev->features (before the operation) and new (after
+the operation); mask shows bits which have been changed and value their new
+values.
+
 
 Request translation
 -------------------
@@ -328,30 +342,30 @@ ETHTOOL_SRINGPARAM		n/a
 ETHTOOL_GPAUSEPARAM		n/a
 ETHTOOL_SPAUSEPARAM		n/a
 ETHTOOL_GRXCSUM			ETHNL_CMD_GET_SETTINGS
-ETHTOOL_SRXCSUM			n/a
+ETHTOOL_SRXCSUM			ETHNL_CMD_SET_SETTINGS
 ETHTOOL_GTXCSUM			ETHNL_CMD_GET_SETTINGS
-ETHTOOL_STXCSUM			n/a
+ETHTOOL_STXCSUM			ETHNL_CMD_SET_SETTINGS
 ETHTOOL_GSG			ETHNL_CMD_GET_SETTINGS
-ETHTOOL_SSG			n/a
+ETHTOOL_SSG			ETHNL_CMD_SET_SETTINGS
 ETHTOOL_TEST			n/a
 ETHTOOL_GSTRINGS		ETHNL_CMD_GET_STRSET
 ETHTOOL_PHYS_ID			n/a
 ETHTOOL_GSTATS			n/a
 ETHTOOL_GTSO			ETHNL_CMD_GET_SETTINGS
-ETHTOOL_STSO			n/a
+ETHTOOL_STSO			ETHNL_CMD_SET_SETTINGS
 ETHTOOL_GPERMADDR		n/a
 ETHTOOL_GUFO			ETHNL_CMD_GET_SETTINGS
-ETHTOOL_SUFO			n/a
+ETHTOOL_SUFO			ETHNL_CMD_SET_SETTINGS
 ETHTOOL_GGSO			ETHNL_CMD_GET_SETTINGS
-ETHTOOL_SGSO			n/a
+ETHTOOL_SGSO			ETHNL_CMD_SET_SETTINGS
 ETHTOOL_GFLAGS			ETHNL_CMD_GET_SETTINGS
-ETHTOOL_SFLAGS			n/a
+ETHTOOL_SFLAGS			ETHNL_CMD_SET_SETTINGS
 ETHTOOL_GPFLAGS			n/a
 ETHTOOL_SPFLAGS			n/a
 ETHTOOL_GRXFH			n/a
 ETHTOOL_SRXFH			n/a
 ETHTOOL_GGRO			ETHNL_CMD_GET_SETTINGS
-ETHTOOL_SGRO			n/a
+ETHTOOL_SGRO			ETHNL_CMD_SET_SETTINGS
 ETHTOOL_GRXRINGS		n/a
 ETHTOOL_GRXCLSRLCNT		n/a
 ETHTOOL_GRXCLSRULE		n/a
include/uapi/linux/ethtool_netlink.h +1 -0
index 06c78b281275..8dfcb9ef4009 100644
@@ -191,6 +191,7 @@ enum {
 	ETHA_FEATURES_WANTED,			/* bitset */
 	ETHA_FEATURES_ACTIVE,			/* bitset */
 	ETHA_FEATURES_NOCHANGE,			/* bitset */
+	ETHA_FEATURES_WANT_DIFF,		/* flag */
 
 	__ETHA_FEATURES_MAX,
 	ETHA_FEATURES_MAX = (__ETHA_FEATURES_MAX - 1)
net/ethtool/settings.c +127 -0

139 lines not on this page · raw message

Signature · 1 line
2.18.0
#34 lore raw

RFC PATCH v2 17/17 ethtool: implement SET_PARAMS message

In reply to Michal Kubecek

Sets the information provided by ETHTOOL_SCOALESCE, ETHTOOL_SRINGPARAM, ETHTOOL_SPAUSEPARAM, ETHTOOL_SCHANNELS, ETHTOOL_SEEE and ETHTOOL_SFECPARAM. Each of these has corresponding nesting attribute containing attributes for its settings. This way, userspace can request changes equivalent to one or more of the legacy requests (and provide only part of the data to update).

---
 Documentation/networking/ethtool-netlink.txt |  71 ++-
 net/ethtool/netlink.c                        |   6 +
 net/ethtool/params.c                         | 429 +++++++++++++++++++
 3 files changed, 499 insertions(+), 7 deletions(-)
Documentation/networking/ethtool-netlink.txt +64 -7
index 630eebd7e741..2b70736110fe 100644
@@ -126,7 +126,7 @@ List of message types
     ETHNL_CMD_GET_SETTINGS
     ETHNL_CMD_SET_SETTINGS
     ETHNL_CMD_GET_PARAMS
-    ETHNL_CMD_SET_PARAMS		response only (for now)
+    ETHNL_CMD_SET_PARAMS
 
 All constants use ETHNL_CMD_ prefix, usually followed by "GET", "SET" or "ACT"
 to indicate the type.
@@ -408,6 +408,63 @@ to them are broadcasted as notifications on change of these settings using
 netlink or ioctl ethtool interface.
 
 
+SET_PARAMS
+----------
+
+SET_PARAMS request modifies the settings retrieved by GET_PARAMS, i.e. it
+replaces ETHTOOL_SCOALESCE, ETHTOOL_SRINGPARAM, ETHTOOL_SPAUSEPARAM,
+ETHTOOL_SCHANNELS, ETHTOOL_SEEE and ETHTOOL_SFECPARAM legacy commands. For
+each of these, relevant data attributes are contained in a corresponding nest
+attribute. Some of the attributes provided by GET_SETPARAMS are read only and
+cannot be set by SET_PARAMS request.
+
+    ETHA_PARAMS_COALESCE	(nest)		coalescing
+        ETHA_COALESCE_RX_USECS			(u32)
+        ETHA_COALESCE_RX_MAXFRM			(u32)
+        ETHA_COALESCE_RX_USECS_IRQ		(u32)
+        ETHA_COALESCE_RX_MAXFRM_IRQ		(u32)
+        ETHA_COALESCE_RX_USECS_LOW		(u32)
+        ETHA_COALESCE_RX_MAXFRM_LOW		(u32)
+        ETHA_COALESCE_RX_USECS_HIGH		(u32)
+        ETHA_COALESCE_RX_MAXFRM_HIGH		(u32)
+        ETHA_COALESCE_TX_USECS			(u32)
+        ETHA_COALESCE_TX_MAXFRM			(u32)
+        ETHA_COALESCE_TX_USECS_IRQ		(u32)
+        ETHA_COALESCE_TX_MAXFRM_IRQ		(u32)
+        ETHA_COALESCE_TX_USECS_LOW		(u32)
+        ETHA_COALESCE_TX_MAXFRM_LOW		(u32)
+        ETHA_COALESCE_TX_USECS_HIGH		(u32)
+        ETHA_COALESCE_TX_MAXFRM_HIGH		(u32)
+        ETHA_COALESCE_PKT_RATE_LOW		(u32)
+        ETHA_COALESCE_PKT_RATE_HIGH		(u32)
+        ETHA_COALESCE_RX_USE_ADAPTIVE		(bool)
+        ETHA_COALESCE_TX_USE_ADAPTIVE		(bool)
+        ETHA_COALESCE_RATE_SAMPLE_INTERVAL	(u32)
+        ETHA_COALESCE_STATS_BLOCK_USECS		(u32)
+    ETHA_PARAMS_RING		(nest)		ring parameters
+        ETHA_RING_RX_PENDING			(u32)
+        ETHA_RING_RX_MINI_PENDING		(u32)
+        ETHA_RING_RX_JUMBO_PENDING		(u32)
+        ETHA_RING_TX_PENDING			(u32)
+    ETHA_PARAMS_PAUSE		(nest)		pause parameters
+        ETHA_PAUSE_AUTONEG			(bool)
+        ETHA_PAUSE_RX				(bool)
+        ETHA_PAUSE_TX				(bool)
+    ETHA_PARAMS_CHANNELS	(nest)		channel settings
+        ETHA_CHANNELS_RX_COUNT			(u32)
+        ETHA_CHANNELS_TX_COUNT			(u32)
+        ETHA_CHANNELS_OTHER_COUNT		(u32)
+        ETHA_CHANNELS_COMBINED_COUNT		(u32)
+    ETHA_PARAMS_EEE		(nest)		EEE settings
+        ETHA_EEE_LINK_MODES			(bitset)
+		- change modes for which EEE is advertised
+        ETHA_EEE_ENABLED			(bool)
+        ETHA_EEE_TX_LPI_ENABLED			(bool)
+        ETHA_EEE_TX_LPI_TIMER			(u32)
+    ETHA_PARAMS_FEC		(nest)		FEC parameters
+        ETHA_FEC_MODES				(bitfield32)
+		- change configured FEC encodings
+
 
 Request translation
 -------------------
@@ -431,11 +488,11 @@ ETHTOOL_GLINK			ETHNL_CMD_GET_SETTINGS
 ETHTOOL_GEEPROM			n/a
 ETHTOOL_SEEPROM			n/a
 ETHTOOL_GCOALESCE		ETHNL_CMD_GET_PARAMS
-ETHTOOL_SCOALESCE		n/a
+ETHTOOL_SCOALESCE		ETHNL_CMD_SET_PARAMS
 ETHTOOL_GRINGPARAM		ETHNL_CMD_GET_PARAMS
-ETHTOOL_SRINGPARAM		n/a
+ETHTOOL_SRINGPARAM		ETHNL_CMD_SET_PARAMS
 ETHTOOL_GPAUSEPARAM		ETHNL_CMD_GET_PARAMS
-ETHTOOL_SPAUSEPARAM		n/a
+ETHTOOL_SPAUSEPARAM		ETHNL_CMD_SET_PARAMS
 ETHTOOL_GRXCSUM			ETHNL_CMD_GET_SETTINGS
 ETHTOOL_SRXCSUM			ETHNL_CMD_SET_SETTINGS
 ETHTOOL_GTXCSUM			ETHNL_CMD_GET_SETTINGS
@@ -477,7 +534,7 @@ ETHTOOL_SRXFHINDIR		n/a
 ETHTOOL_GFEATURES		ETHNL_CMD_GET_SETTINGS
 ETHTOOL_SFEATURES		n/a
 ETHTOOL_GCHANNELS		ETHNL_CMD_GET_PARAMS
-ETHTOOL_SCHANNELS		n/a
+ETHTOOL_SCHANNELS		ETHNL_CMD_SET_PARAMS
 ETHTOOL_SET_DUMP		n/a
 ETHTOOL_GET_DUMP_FLAG		n/a
 ETHTOOL_GET_DUMP_DATA		n/a
@@ -485,7 +542,7 @@ ETHTOOL_GET_TS_INFO		n/a
 ETHTOOL_GMODULEINFO		n/a
 ETHTOOL_GMODULEEEPROM		n/a
 ETHTOOL_GEEE			ETHNL_CMD_GET_PARAMS
-ETHTOOL_SEEE			n/a
+ETHTOOL_SEEE			ETHNL_CMD_SET_PARAMS
 ETHTOOL_GRSSH			n/a
 ETHTOOL_SRSSH			n/a
 ETHTOOL_GTUNABLE		n/a
@@ -497,5 +554,5 @@ ETHTOOL_SLINKSETTINGS		ETHNL_CMD_SET_SETTINGS
 ETHTOOL_PHY_GTUNABLE		n/a
 ETHTOOL_PHY_STUNABLE		n/a
 ETHTOOL_GFECPARAM		ETHNL_CMD_GET_PARAMS
-ETHTOOL_SFECPARAM		n/a
+ETHTOOL_SFECPARAM		ETHNL_CMD_SET_PARAMS
 
net/ethtool/netlink.c +6 -0
index b24a0e045ec0..17fee1ce077b 100644
@@ -735,6 +735,7 @@ int ethnl_get_drvinfo(struct sk_buff *skb, struct genl_info *info);
 int ethnl_get_settings(struct sk_buff *skb, struct genl_info *info);
 int ethnl_set_settings(struct sk_buff *skb, struct genl_info *info);
 int ethnl_get_params(struct sk_buff *skb, struct genl_info *info);
+int ethnl_set_params(struct sk_buff *skb, struct genl_info *info);
 
 int ethnl_strset_start(struct netlink_callback *cb);
 int ethnl_drvinfo_start(struct netlink_callback *cb);
@@ -778,6 +779,11 @@ static const struct genl_ops ethtool_genl_ops[] = {
 		.dumpit	= ethnl_dumpit,
 		.done	= ethnl_params_done,
 	},
+	{
+		.cmd	= ETHNL_CMD_SET_PARAMS,
+		.flags	= GENL_UNS_ADMIN_PERM,
+		.doit	= ethnl_set_params,
+	},
 };
 
 static const struct genl_multicast_group ethtool_nl_mcgrps[] = {
net/ethtool/params.c +429 -0

432 lines not on this page · raw message

Signature · 1 line
2.18.0
#33 lore raw

RFC PATCH v2 16/17 ethtool: implement SET_PARAMS notification

In reply to Michal Kubecek

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

Also trigger the notification on analogous changes performed via the legacy ioctl interface.

---
 net/ethtool/ioctl.c   | 42 ++++++++++++++++++++++++++++++++++++------
 net/ethtool/netlink.c |  3 +++
 net/ethtool/params.c  | 40 ++++++++++++++++++++++++++++++++++++++++
 3 files changed, 79 insertions(+), 6 deletions(-)
net/ethtool/ioctl.c +36 -6
index 2754d3f6fd75..1dc1459dff6e 100644
@@ -1337,6 +1337,7 @@ static int ethtool_get_eee(struct net_device *dev, char __user *useraddr)
 static int ethtool_set_eee(struct net_device *dev, char __user *useraddr)
 {
 	struct ethtool_eee edata;
+	int ret;
 
 	if (!dev->ethtool_ops->set_eee)
 		return -EOPNOTSUPP;
@@ -1344,7 +1345,11 @@ static int ethtool_set_eee(struct net_device *dev, char __user *useraddr)
 	if (copy_from_user(&edata, useraddr, sizeof(edata)))
 		return -EFAULT;
 
-	return dev->ethtool_ops->set_eee(dev, &edata);
+	ret = dev->ethtool_ops->set_eee(dev, &edata);
+	if (ret >= 0)
+		netdev_ethtool_info_change(dev, NULL, ETHNL_CMD_SET_PARAMS,
+					   ETH_PARAMS_IM_EEE);
+	return ret;
 }
 
 static int ethtool_nway_reset(struct net_device *dev)
@@ -1499,6 +1504,7 @@ static noinline_for_stack int ethtool_set_coalesce(struct net_device *dev,
 						   void __user *useraddr)
 {
 	struct ethtool_coalesce coalesce;
+	int ret;
 
 	if (!dev->ethtool_ops->set_coalesce)
 		return -EOPNOTSUPP;
@@ -1506,7 +1512,11 @@ static noinline_for_stack int ethtool_set_coalesce(struct net_device *dev,
 	if (copy_from_user(&coalesce, useraddr, sizeof(coalesce)))
 		return -EFAULT;
 
-	return dev->ethtool_ops->set_coalesce(dev, &coalesce);
+	ret = dev->ethtool_ops->set_coalesce(dev, &coalesce);
+	if (ret >= 0)
+		netdev_ethtool_info_change(dev, NULL, ETHNL_CMD_SET_PARAMS,
+					   ETH_PARAMS_IM_COALESCE);
+	return ret;
 }
 
 static int ethtool_get_ringparam(struct net_device *dev, void __user *useraddr)
@@ -1526,6 +1536,7 @@ static int ethtool_get_ringparam(struct net_device *dev, void __user *useraddr)
 static int ethtool_set_ringparam(struct net_device *dev, void __user *useraddr)
 {
 	struct ethtool_ringparam ringparam, max = { .cmd = ETHTOOL_GRINGPARAM };
+	int ret;
 
 	if (!dev->ethtool_ops->set_ringparam || !dev->ethtool_ops->get_ringparam)
 		return -EOPNOTSUPP;
@@ -1542,7 +1553,11 @@ static int ethtool_set_ringparam(struct net_device *dev, void __user *useraddr)
 	    ringparam.tx_pending > max.tx_max_pending)
 		return -EINVAL;
 
-	return dev->ethtool_ops->set_ringparam(dev, &ringparam);
+	ret = dev->ethtool_ops->set_ringparam(dev, &ringparam);
+	if (ret >= 0)
+		netdev_ethtool_info_change(dev, NULL, ETHNL_CMD_SET_PARAMS,
+					   ETH_PARAMS_IM_RING);
+	return ret;
 }
 
 static noinline_for_stack int ethtool_get_channels(struct net_device *dev,
@@ -1565,6 +1580,7 @@ static noinline_for_stack int ethtool_set_channels(struct net_device *dev,
 {
 	struct ethtool_channels channels, max = { .cmd = ETHTOOL_GCHANNELS };
 	u32 max_rx_in_use = 0;
+	int ret;
 
 	if (!dev->ethtool_ops->set_channels || !dev->ethtool_ops->get_channels)
 		return -EOPNOTSUPP;
@@ -1588,7 +1604,11 @@ static noinline_for_stack int ethtool_set_channels(struct net_device *dev,
 	    (channels.combined_count + channels.rx_count) <= max_rx_in_use)
 	    return -EINVAL;
 
-	return dev->ethtool_ops->set_channels(dev, &channels);
+	ret = dev->ethtool_ops->set_channels(dev, &channels);
+	if (ret >= 0)
+		netdev_ethtool_info_change(dev, NULL, ETHNL_CMD_SET_PARAMS,
+					   ETH_PARAMS_IM_CHANNELS);
+	return ret;
 }
 
 static int ethtool_get_pauseparam(struct net_device *dev, void __user *useraddr)
@@ -1608,6 +1628,7 @@ static int ethtool_get_pauseparam(struct net_device *dev, void __user *useraddr)
 static int ethtool_set_pauseparam(struct net_device *dev, void __user *useraddr)
 {
 	struct ethtool_pauseparam pauseparam;
+	int ret;
 
 	if (!dev->ethtool_ops->set_pauseparam)
 		return -EOPNOTSUPP;
@@ -1615,7 +1636,11 @@ static int ethtool_set_pauseparam(struct net_device *dev, void __user *useraddr)
 	if (copy_from_user(&pauseparam, useraddr, sizeof(pauseparam)))
 		return -EFAULT;
 
-	return dev->ethtool_ops->set_pauseparam(dev, &pauseparam);
+	ret = dev->ethtool_ops->set_pauseparam(dev, &pauseparam);
+	if (ret >= 0)
+		netdev_ethtool_info_change(dev, NULL, ETHNL_CMD_SET_PARAMS,
+					   ETH_PARAMS_IM_PAUSE);
+	return ret;
 }
 
 static int ethtool_self_test(struct net_device *dev, char __user *useraddr)
@@ -2394,6 +2419,7 @@ static int ethtool_get_fecparam(struct net_device *dev, void __user *useraddr)
 static int ethtool_set_fecparam(struct net_device *dev, void __user *useraddr)
 {
 	struct ethtool_fecparam fecparam;
+	int ret;
 
 	if (!dev->ethtool_ops->set_fecparam)
 		return -EOPNOTSUPP;
@@ -2401,7 +2427,11 @@ static int ethtool_set_fecparam(struct net_device *dev, void __user *useraddr)
 	if (copy_from_user(&fecparam, useraddr, sizeof(fecparam)))
 		return -EFAULT;
 
-	return dev->ethtool_ops->set_fecparam(dev, &fecparam);
+	ret = dev->ethtool_ops->set_fecparam(dev, &fecparam);
+	if (ret >= 0)
+		netdev_ethtool_info_change(dev, NULL, ETHNL_CMD_SET_PARAMS,
+					   ETH_PARAMS_IM_FEC);
+	return ret;
 }
 
 /* The main entry point in this file.  Called from net/core/dev_ioctl.c */
net/ethtool/netlink.c +3 -0
index 721101ed2ab6..b24a0e045ec0 100644
@@ -630,8 +630,11 @@ int ethnl_dumpit(struct sk_buff *skb, struct netlink_callback *cb)
 typedef void (*ethnl_notify_handler_t)(struct netdev_notifier_ethtool_info *);
 
 void ethnl_settings_notify(struct netdev_notifier_ethtool_info *);
+void ethnl_params_notify(struct netdev_notifier_ethtool_info *);
+
 ethnl_notify_handler_t ethnl_notify_handlers[] = {
 	[ETHNL_CMD_SET_SETTINGS]	= ethnl_settings_notify,
+	[ETHNL_CMD_SET_PARAMS]		= ethnl_params_notify,
 };
 
 static void __ethnl_notify(struct netdev_notifier_ethtool_info *info)
net/ethtool/params.c +40 -0
index 07d4c527abf2..773e13fc1ae6 100644
@@ -537,3 +537,43 @@ int ethnl_params_done(struct netlink_callback *cb)
 
 	return 0;
 }
+
+void ethnl_params_notify(struct netdev_notifier_ethtool_info *info)
+{
+	struct params_reqinfo req_info = {
+		.dev		= info->info.dev,
+		.req_mask	= info->ethtool_info.req_mask,
+		.compact	= true,
+		.have_rtnl	= true,
+	};
+	struct params_data data;
+	struct sk_buff *skb;
+	int reply_len;
+	void *ehdr;
+	int ret;
+
+	ret = prepare_params(&data, &req_info, NULL, req_info.dev);
+	if (ret < 0)
+		return;
+	reply_len = params_size(&data, &req_info);
+	if (ret < 0)
+		return;
+	skb = genlmsg_new(reply_len, GFP_KERNEL);
+	if (!skb)
+		return;
+	ehdr = genlmsg_put(skb, 0, ++ethnl_bcast_seq, &ethtool_genl_family, 0,
+			   ETHNL_CMD_SET_PARAMS);
+	ret = ethnl_fill_dev(skb, req_info.dev, ETHA_PARAMS_DEV);
+	if (ret < 0)
+		goto err_skb;
+	ret = fill_params(skb, &data, &req_info);
+	if (ret < 0)
+		goto err_skb;
+	genlmsg_end(skb, ehdr);
+
+	genlmsg_multicast(&ethtool_genl_family, skb, 0, ETHNL_MCGRP_MONITOR,
+			  GFP_KERNEL);
+	return;
+err_skb:
+	nlmsg_free(skb);
+}
Signature · 1 line
2.18.0
#12 lore raw

RFC PATCH v2 9/17 ethtool: implement GET_DRVINFO message

In reply to Michal Kubecek

Requests the same information as ETHTOOL_GDRVINFO command in ioct interface. This is read-only so that corresponding SET_DRVINFO exists but is only used in kernel replies.

---
 Documentation/networking/ethtool-netlink.txt |  38 +++++-
 include/uapi/linux/ethtool_netlink.h         |  22 ++++
 net/ethtool/Makefile                         |   4 +-
 net/ethtool/common.c                         |  43 ++++++
 net/ethtool/common.h                         |   3 +
 net/ethtool/drvinfo.c                        | 131 +++++++++++++++++++
 net/ethtool/ioctl.c                          |  42 +-----
 net/ethtool/netlink.c                        |   8 ++
 8 files changed, 252 insertions(+), 39 deletions(-)
 create mode 100644 net/ethtool/drvinfo.c
Documentation/networking/ethtool-netlink.txt +37 -1
index 8b43f41a8140..1e3d5ffc97ab 100644
@@ -121,6 +121,8 @@ List of message types
     ETHNL_CMD_EVENT			notification only
     ETHNL_CMD_GET_STRSET
     ETHNL_CMD_SET_STRSET		response only
+    ETHNL_CMD_GET_DRVINFO
+    ETHNL_CMD_SET_DRVINFO		response only
 
 All constants use ETHNL_CMD_ prefix, usually followed by "GET", "SET" or "ACT"
 to indicate the type.
@@ -156,6 +158,40 @@ and also multiple events of the same type (e.g. two or more newly registered
 devices).
 
 
+GET_DRVINFO
+-----------
+
+GET_DRVINFO request corresponds to ETHTOOL_GDRVINFO ioctl command and provides
+basic driver information.
+
+Request contents:
+
+    ETHA_DRVINFO_DEV		(nested)	device identification
+
+Kernel response contents:
+
+    ETHA_DRVINFO_DEV		(nested)	device identification
+    ETHA_DRVINFO_DRIVER		(string)	driver name
+    ETHA_DRVINFO_VERSION	(string)	driver version
+    ETHA_DRVINFO_FWVERSION	(string)	firmware version
+    ETHA_DRVINFO_BUSINFO	(string)	device bus address
+    ETHA_DRVINFO_EROM_VER	(string)	expansion ROM version
+    ETHA_DRVINFO_N_PRIV_FLAGS	(u32)		number of private flags
+    ETHA_DRVINFO_N_STATS	(u32)		number of device stats
+    ETHA_DRVINFO_TESTINFO_LEN	(u32)		number of test results
+    ETHA_DRVINFO_EEDUMP_LEN	(u32)		EEPROM dump size
+    ETHA_DRVINFO_REGDUMP_LEN	(u32)		register dump size
+
+The meaning of these follows the corresponding fields of ETHTOOL_GDRVINFO
+response.
+
+All information is read only, SET_DRVINFO request is not implemented
+(ETHNL_CMD_SET_DRVINFO messages are sent only by kernel in response to
+GET_DRVINFO requests).
+
+GET_DRVINFO requests allow dumps.
+
+
 Request translation
 -------------------
 
@@ -167,7 +203,7 @@ ioctl command			netlink command
 ---------------------------------------------------------------------
 ETHTOOL_GSET			n/a
 ETHTOOL_SSET			n/a
-ETHTOOL_GDRVINFO		n/a
+ETHTOOL_GDRVINFO		ETHNL_CMD_GET_DRVINFO
 ETHTOOL_GREGS			n/a
 ETHTOOL_GWOL			n/a
 ETHTOOL_SWOL			n/a
include/uapi/linux/ethtool_netlink.h +22 -0
index 5177c1940c2b..df4de61fac48 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_DRVINFO,
+	ETHNL_CMD_SET_DRVINFO,		/* only for reply */
 
 	__ETHNL_CMD_MAX,
 	ETHNL_CMD_MAX = (__ETHNL_CMD_MAX - 1)
@@ -124,6 +126,26 @@ enum {
 	ETHA_STRSET_MAX = (__ETHA_STRSET_MAX - 1)
 };
 
+/* GET_DRVINFO / SET_DRVINFO */
+
+enum {
+	ETHA_DRVINFO_UNSPEC,
+	ETHA_DRVINFO_DEV,			/* nest - ETHA_DEV_* */
+	ETHA_DRVINFO_DRIVER,			/* string */
+	ETHA_DRVINFO_VERSION,			/* string */
+	ETHA_DRVINFO_FWVERSION,			/* string */
+	ETHA_DRVINFO_BUSINFO,			/* string */
+	ETHA_DRVINFO_EROM_VER,			/* string */
+	ETHA_DRVINFO_N_PRIV_FLAGS,		/* u32 */
+	ETHA_DRVINFO_N_STATS,			/* u32 */
+	ETHA_DRVINFO_TESTINFO_LEN,		/* u32 */
+	ETHA_DRVINFO_EEDUMP_LEN,		/* u32 */
+	ETHA_DRVINFO_REGDUMP_LEN,		/* u32 */
+
+	__ETHA_DRVINFO_MAX,
+	ETHA_DRVINFO_MAX = (__ETHA_DRVINFO_MAX - 1)
+};
+
 /* generic netlink info */
 #define ETHTOOL_GENL_NAME "ethtool"
 #define ETHTOOL_GENL_VERSION 1
net/ethtool/Makefile +2 -2
index ba260d5b53b2..2e840ae0ba1e 100644
@@ -1,7 +1,7 @@
 # SPDX-License-Identifier: GPL-2.0
 
-obj-y				+= ioctl.o
+obj-y				+= ioctl.o common.o
 
 obj-$(CONFIG_ETHTOOL_NETLINK)	+= ethtool_nl.o
 
-ethtool_nl-y	:= netlink.o strset.o
+ethtool_nl-y	:= netlink.o strset.o drvinfo.o
net/ethtool/common.c +43 -0

51 lines not on this page · raw message

net/ethtool/common.h +3 -0
index 45c6492e4aee..0f768c1be527 100644
@@ -3,6 +3,7 @@
 #ifndef _ETHTOOL_COMMON_H
 #define _ETHTOOL_COMMON_H
 
+#include <linux/netdevice.h>
 #include <linux/ethtool.h>
 
 extern const char netdev_features_strings[NETDEV_FEATURE_COUNT][ETH_GSTRING_LEN];
@@ -10,4 +11,6 @@ extern const char rss_hash_func_strings[ETH_RSS_HASH_FUNCS_COUNT][ETH_GSTRING_LE
 extern const char 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/drvinfo.c new file +131 -0

131 lines not on this page · raw message

net/ethtool/ioctl.c +6 -36

57 lines not on this page · raw message

net/ethtool/netlink.c +8 -0
index 237a2cb40be4..305baa02ff70 100644
@@ -670,8 +670,10 @@ static struct notifier_block ethnl_netdev_notifier = {
 /* genetlink setup */
 
 int ethnl_get_strset(struct sk_buff *skb, struct genl_info *info);
+int ethnl_get_drvinfo(struct sk_buff *skb, struct genl_info *info);
 
 int ethnl_strset_start(struct netlink_callback *cb);
+int ethnl_drvinfo_start(struct netlink_callback *cb);
 
 int ethnl_strset_done(struct netlink_callback *cb);
 
@@ -683,6 +685,12 @@ static const struct genl_ops ethtool_genl_ops[] = {
 		.dumpit	= ethnl_dumpit,
 		.done	= ethnl_strset_done,
 	},
+	{
+		.cmd	= ETHNL_CMD_GET_DRVINFO,
+		.doit	= ethnl_get_drvinfo,
+		.start	= ethnl_drvinfo_start,
+		.dumpit	= ethnl_dumpit,
+	},
 };
 
 static const struct genl_multicast_group ethtool_nl_mcgrps[] = {
Signature · 1 line
2.18.0
#6 lore raw

RFC PATCH v2 6/17 ethtool: support for netlink notifications

In reply to Michal Kubecek

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

To trigger a notification, netlink code calls ethtool_notify(), external code (ioctl interface) uses NETDEV_ETHTOOL event, preferrably by the means of netdev_ethtool_info_change() helper. For both, the caller must hold RTNL (and, obviously, allow sleeping).

---
 include/linux/ethtool_netlink.h      |  5 ++
 include/linux/netdevice.h            | 23 ++++++++
 include/uapi/linux/ethtool_netlink.h |  2 +
 net/core/dev.c                       | 24 +++++++-
 net/ethtool/netlink.c                | 82 +++++++++++++++++++++++++++-
 net/ethtool/netlink.h                |  5 ++
 6 files changed, 139 insertions(+), 2 deletions(-)
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 +23 -0
index c1295c7a452e..c4b0c575d57e 100644
@@ -2444,6 +2444,7 @@ enum netdev_cmd {
 	NETDEV_CVLAN_FILTER_DROP_INFO,
 	NETDEV_SVLAN_FILTER_PUSH_INFO,
 	NETDEV_SVLAN_FILTER_DROP_INFO,
+	NETDEV_ETHTOOL,
 };
 const char *netdev_cmd_to_name(enum netdev_cmd cmd);
 
@@ -4221,6 +4222,28 @@ struct netdev_notifier_bonding_info {
 void netdev_bonding_info_change(struct net_device *dev,
 				struct netdev_bonding_info *bonding_info);
 
+struct netdev_ethtool_info {
+	unsigned int cmd;
+	u32 req_mask;
+};
+
+struct netdev_notifier_ethtool_info {
+	struct netdev_notifier_info info; /* must be first */
+	struct netdev_ethtool_info ethtool_info;
+};
+
+#if IS_ENABLED(CONFIG_ETHTOOL_NETLINK)
+int netdev_ethtool_info_change(struct net_device *dev,
+			       struct netlink_ext_ack *extack,
+			       unsigned int cmd, u32 req_mask);
+#else
+static inline void netdev_ethtool_info_change(struct net_device *dev,
+					      struct netlink_ext_ack *extack,
+					      unsigned int cmd, u32 req_mask)
+{
+}
+#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 98d6fae315f3..444a668e4a08 100644
@@ -58,4 +58,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/core/dev.c +23 -1
index 87c42c8249ae..8a0773a52dd7 100644
@@ -1585,7 +1585,7 @@ const char *netdev_cmd_to_name(enum netdev_cmd cmd)
 	N(PRECHANGEUPPER) N(CHANGELOWERSTATE) N(UDP_TUNNEL_PUSH_INFO)
 	N(UDP_TUNNEL_DROP_INFO) N(CHANGE_TX_QUEUE_LEN)
 	N(CVLAN_FILTER_PUSH_INFO) N(CVLAN_FILTER_DROP_INFO)
-	N(SVLAN_FILTER_PUSH_INFO) N(SVLAN_FILTER_DROP_INFO)
+	N(SVLAN_FILTER_PUSH_INFO) N(SVLAN_FILTER_DROP_INFO) N(ETHTOOL)
 	}
 #undef N
 	return "UNKNOWN_NETDEV_EVENT";
@@ -7058,6 +7058,28 @@ void netdev_bonding_info_change(struct net_device *dev,
 }
 EXPORT_SYMBOL(netdev_bonding_info_change);
 
+#if IS_ENABLED(CONFIG_ETHTOOL_NETLINK)
+int netdev_ethtool_info_change(struct net_device *dev,
+			       struct netlink_ext_ack *extack,
+			       unsigned int cmd, u32 req_mask)
+{
+	struct netdev_notifier_ethtool_info ethtool_info = {
+		.info = {
+			.dev = dev,
+			.extack = extack,
+		},
+		.ethtool_info = {
+			.cmd = cmd,
+			.req_mask = req_mask,
+		},
+	};
+
+	return call_netdevice_notifiers_info(NETDEV_ETHTOOL,
+					     &ethtool_info.info);
+}
+EXPORT_SYMBOL(netdev_ethtool_info_change);
+#endif
+
 static void netdev_adjacent_add_links(struct net_device *dev)
 {
 	struct netdev_adjacent *iter;
net/ethtool/netlink.c +81 -1

121 lines not on this page · raw message

net/ethtool/netlink.h +5 -0
index 6e9e854eec5d..94c14ec2c3fc 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);
@@ -159,4 +161,7 @@ static inline bool ethnl_is_privileged(struct sk_buff *skb)
 	return netlink_ns_capable(skb, net->user_ns, CAP_NET_ADMIN);
 }
 
+void ethnl_notify(struct net_device *dev, struct netlink_ext_ack *extack,
+		  unsigned int cmd, u32 req_mask);
+
 #endif /* _NET_ETHTOOL_NETLINK_H */
Signature · 1 line
2.18.0
#35 lore raw
In reply to Michal Kubecek
Quoted 62 lines · Mon, Jul 30, 2018 at 02:52:42PM CEST, [email protected] wrote:

A netlink based interface for ethtool is a recurring discussion theme; such discussion happens from time to time but never seems to reach any clear conclusion except that netlink interface is desperately needed. I'm sending this hoping that having a proposal (even if partial) on the table could help move the discussion further.

The interface used for communication between ethtool and kernel is based on ioctl() and suffers from many problems. The most pressing seems the be the lack of extensibility. While some of the newer commands use structures designed to allow future extensions (e.g. GFEATURES or TEST), most either allow no extension at all (GPAUSEPARAM, GCOALESCE) or only limited set of reserved fields (GDRVINFO, GEEE). Even most of those which support future extensions limit the data types that can be used.

This series aims to provide an alternative interface based on netlink which is what other network configuration utilities use. In particular, it uses generic netlink (family "ethtool"). The goal is to provide an interface which would be extensible, flexible and practical both for ethtool and for other network configuration tools (e.g. wicked, systemd-networkd or NetworkManager).

The interface is documented in Documentation/networking/ethtool-netlink.txt

A series for ethtool utility will follow shortly.

Basic concepts:

- the interface is based on generic netlink (family name "ethtool")

- the goal is to provide all features of ioctl interface but allow easier future extensions

- 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, netlink allows providing 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 defices 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 again RFC v1:

- 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:

Quoted 7 lines

- as some comments in discussion on v1 pointed out, some features of ethtool would rather belong to devlink; phy_tunables and phy_stats seem to be candidates, maybe part of drvinfo; are there more?

- another question is where to do the split; should ethtool use devlink API for these or can we provide them in ethtool API as well but with devlink backend (for communication with NIC)

My idea was to provide a compat layer for it. But I also wanted to change the implementation of driver callbacks and provide compat layer for it too. Current ethtool callbacks are very tightly wrapped around the uapi structs.

Please see the last slide:
http://vger.kernel.org/netconf2018_files/JiriPirko_netconf2018.pdf

I started to work on POC implementation but got distracted. Perhaps we can sync over a beer :)

Quoted 11 lines

- currently, all communication with drivers via ethtool_ops is done under RTNL as this is what ioctl interface does and I suspect many ethtool_ops rely on that; can we do without RTNL?

- 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

Quoted 5 lines

- find reasonable format for data transfers (e.g. eeprom dump or flash); I don't have clear idea how big these can get and if 64 KB limit on attribute size (including nested ones) is a problem; if so, dumps can be an answer for dumps, some kind of multi-message requests would be needed for flashes

This is another thing that should go into devlink as it is not netdev-handled. We have now a "region" facility there which can be re-used.

Quoted 79 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

- it would be nice if driver could provide useful error/warning messages to be passed to userspace via extended ACK; example: while testing, I found a driver which only allows values 0, 1, 3 and 10000 for certain parameter but the only way poor user can find out is either by trying all values or by checking driver source

- some of the functions for GET_SETTINGS and GET_PARAMS are quite similar (e.g. ethtool_get_*); it might be beneficial to introduce some "ops", leave only "parse", "prepare", "size" and "fill" handlers and make the rest generic (like ethnl_dumpit()).

- the counts and sizes in GET_DRVINFO reply seem to be a relic of the past and if userspace needs them, there are (or will be) other ways to get them; they should most likely go

Michal Kubecek (17):
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: implement GET_STRSET message
ethtool: implement GET_DRVINFO message
ethtool: implement GET_SETTINGS message
ethtool: implement GET_SETTINGS request for features
ethtool: implement SET_SETTINGS notification
ethtool: implement SET_SETTINGS message
ethtool: implement SET_SETTINGS request for features
ethtool: implement GET_PARAMS message
ethtool: implement SET_PARAMS notification
ethtool: implement SET_PARAMS message

Documentation/networking/ethtool-netlink.txt |  558 ++++++++
include/linux/ethtool_netlink.h              |   17 +
include/linux/netdevice.h                    |   25 +
include/net/netlink.h                        |   15 +
include/uapi/linux/ethtool.h                 |    7 +
include/uapi/linux/ethtool_netlink.h         |  325 +++++
net/Kconfig                                  |    7 +
net/Makefile                                 |    2 +-
net/core/Makefile                            |    2 +-
net/core/dev.c                               |   27 +-
net/ethtool/Makefile                         |    7 +
net/ethtool/common.c                         |  242 ++++
net/ethtool/common.h                         |   26 +
net/ethtool/drvinfo.c                        |  131 ++
net/{core/ethtool.c => ethtool/ioctl.c}      |  310 ++---
net/ethtool/netlink.c                        |  840 ++++++++++++
net/ethtool/netlink.h                        |  169 +++
net/ethtool/params.c                         | 1008 ++++++++++++++
net/ethtool/settings.c                       | 1230 ++++++++++++++++++
net/ethtool/strset.c                         |  552 ++++++++
20 files changed, 5269 insertions(+), 231 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/common.c
create mode 100644 net/ethtool/common.h
create mode 100644 net/ethtool/drvinfo.c
rename net/{core/ethtool.c => ethtool/ioctl.c} (88%) create mode 100644 net/ethtool/netlink.c
create mode 100644 net/ethtool/netlink.h
create mode 100644 net/ethtool/params.c
create mode 100644 net/ethtool/settings.c
create mode 100644 net/ethtool/strset.c

Signature · 1 line
2.18.0
#7 lore raw

Re: [RFC PATCH net-next v2 06/17] ethtool: support for netlink notifications

In reply to Michal Kubecek

Mon, Jul 30, 2018 at 02:53:12PM CEST, [email protected] wrote:

[...]

include/linux/netdevice.h enum netdev_cmd { · line 2447

Quoted 9 lines
include/linux/netdevice.h +1 -0
index c1295c7a452e..c4b0c575d57e 100644
@@ -2444,6 +2444,7 @@ enum netdev_cmd {
 	NETDEV_CVLAN_FILTER_DROP_INFO,
 	NETDEV_SVLAN_FILTER_PUSH_INFO,
 	NETDEV_SVLAN_FILTER_DROP_INFO,
+	NETDEV_ETHTOOL,

I don't understand why this goes through netdev notifier. What's the reason?

#13 lore raw

Re: [RFC PATCH net-next v2 09/17] ethtool: implement GET_DRVINFO message

In reply to Michal Kubecek

Mon, Jul 30, 2018 at 02:53:27PM CEST, [email protected] wrote:

[...]

Quoted 5 lines
include/uapi/linux/ethtool_netlink.h +5 -0
+/* GET_DRVINFO / SET_DRVINFO */
+
+enum {
+	ETHA_DRVINFO_UNSPEC,
+	ETHA_DRVINFO_DEV,			/* nest - ETHA_DEV_* */

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

Quoted 10 lines
include/uapi/linux/ethtool_netlink.h +10 -0
+	ETHA_DRVINFO_DRIVER,			/* string */
+	ETHA_DRVINFO_VERSION,			/* string */
+	ETHA_DRVINFO_FWVERSION,			/* string */
+	ETHA_DRVINFO_BUSINFO,			/* string */
+	ETHA_DRVINFO_EROM_VER,			/* string */
+	ETHA_DRVINFO_N_PRIV_FLAGS,		/* u32 */
+	ETHA_DRVINFO_N_STATS,			/* u32 */
+	ETHA_DRVINFO_TESTINFO_LEN,		/* u32 */
+	ETHA_DRVINFO_EEDUMP_LEN,		/* u32 */
+	ETHA_DRVINFO_REGDUMP_LEN,		/* u32 */

This is a nice example of why 1:1 ioctl->netlink conversion would be a big mistake.

I understand that for ioclt, getting lengths of various things is important. Userspace can prepare buffer for next ioctl which would actually do dump transfer. However in netlink, this is totally pointless as the dump goes into userspace in multiple netlink messages.

We need to figure out the netlink uapi from scratch.

[...]

maintainer
#15 lore raw

Re: [RFC PATCH net-next v2 09/17] ethtool: implement GET_DRVINFO message

In reply to Michal Kubecek
Quoted 39 lines · Michal Kubecek

Requests the same information as ETHTOOL_GDRVINFO command in ioct interface. This is read-only so that corresponding SET_DRVINFO exists but is only used in kernel replies.

---
 Documentation/networking/ethtool-netlink.txt |  38 +++++-
 include/uapi/linux/ethtool_netlink.h         |  22 ++++
 net/ethtool/Makefile                         |   4 +-
 net/ethtool/common.c                         |  43 ++++++
 net/ethtool/common.h                         |   3 +
 net/ethtool/drvinfo.c                        | 131 +++++++++++++++++++
 net/ethtool/ioctl.c                          |  42 +-----
 net/ethtool/netlink.c                        |   8 ++
 8 files changed, 252 insertions(+), 39 deletions(-)
 create mode 100644 net/ethtool/drvinfo.c
Documentation/networking/ethtool-netlink.txt +7 -0
index 8b43f41a8140..1e3d5ffc97ab 100644
@@ -121,6 +121,8 @@ List of message types
     ETHNL_CMD_EVENT			notification only
     ETHNL_CMD_GET_STRSET
     ETHNL_CMD_SET_STRSET		response only
+    ETHNL_CMD_GET_DRVINFO
+    ETHNL_CMD_SET_DRVINFO		response only
 
 All constants use ETHNL_CMD_ prefix, usually followed by "GET", "SET" or "ACT"
 to indicate the type.
@@ -156,6 +158,40 @@ and also multiple events of the same type (e.g. two or more newly registered
 devices).
 
 
+GET_DRVINFO
+-----------
+
+GET_DRVINFO request corresponds to ETHTOOL_GDRVINFO ioctl command and provides
+basic driver information.

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

Quoted 10 lines
Documentation/networking/ethtool-netlink.txt +10 -0
+
+Request contents:
+
+    ETHA_DRVINFO_DEV		(nested)	device identification
+
+Kernel response contents:
+
+    ETHA_DRVINFO_DEV		(nested)	device identification
+    ETHA_DRVINFO_DRIVER		(string)	driver name
+    ETHA_DRVINFO_VERSION	(string)	driver version

Driver version is generally useless. Is version X.Y.Z of a driver the same when backported to some ancient enterprise kernel with 1000s of patches? Now seems like a good opportunity to drop it.

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

Quoted 5 lines
Documentation/networking/ethtool-netlink.txt +5 -0
+    ETHA_DRVINFO_FWVERSION	(string)	firmware version
+    ETHA_DRVINFO_BUSINFO	(string)	device bus address
+    ETHA_DRVINFO_EROM_VER	(string)	expansion ROM version
+    ETHA_DRVINFO_N_PRIV_FLAGS	(u32)		number of private flags
+    ETHA_DRVINFO_N_STATS	(u32)		number of device stats

I know there is at least one driver that has somewhat dynamic number of statistics. It would be better to have the strings and the values in the same message, so there is no need to first get the number of strings, allocate the memory, get the strings, then get the values.

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

Quoted 1 line
Documentation/networking/ethtool-netlink.txt +1 -0
+    ETHA_DRVINFO_TESTINFO_LEN	(u32)		number of test results

In theory, this also does not need to be fixed.

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

Quoted 2 lines
Documentation/networking/ethtool-netlink.txt +2 -0
+    ETHA_DRVINFO_EEDUMP_LEN	(u32)		EEPROM dump size
+    ETHA_DRVINFO_REGDUMP_LEN	(u32)		register dump size

I would suggest removing all these _LEN properties, and let netlink return what it needs to return.

Andrew

#14 lore raw

Re: [RFC PATCH net-next v2 09/17] ethtool: implement GET_DRVINFO message

In reply to Jiri Pirko
Quoted 23 lines · Jiri Pirko

Mon, Jul 30, 2018 at 02:53:27PM CEST, [email protected] wrote:

[...]

Quoted 5 lines
include/uapi/linux/ethtool_netlink.h +5 -0
+/* GET_DRVINFO / SET_DRVINFO */
+
+enum {
+	ETHA_DRVINFO_UNSPEC,
+	ETHA_DRVINFO_DEV,			/* nest - ETHA_DEV_* */

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

Quoted 10 lines
include/uapi/linux/ethtool_netlink.h +10 -0
+	ETHA_DRVINFO_DRIVER,			/* string */
+	ETHA_DRVINFO_VERSION,			/* string */
+	ETHA_DRVINFO_FWVERSION,			/* string */
+	ETHA_DRVINFO_BUSINFO,			/* string */
+	ETHA_DRVINFO_EROM_VER,			/* string */
+	ETHA_DRVINFO_N_PRIV_FLAGS,		/* u32 */
+	ETHA_DRVINFO_N_STATS,			/* u32 */
+	ETHA_DRVINFO_TESTINFO_LEN,		/* u32 */
+	ETHA_DRVINFO_EEDUMP_LEN,		/* u32 */
+	ETHA_DRVINFO_REGDUMP_LEN,		/* u32 */

This is a nice example of why 1:1 ioctl->netlink conversion would be a big mistake.

Quoted 4 lines

I understand that for ioclt, getting lengths of various things is important. Userspace can prepare buffer for next ioctl which would actually do dump transfer. However in netlink, this is totally pointless as the dump goes into userspace in multiple netlink messages.

Right, I already mentioned this in the ToDo part of cover letter. It makes indeed little sense to put this information here - and even less to put only dome of the counts and lengths.

Michal Kubecek

#16 lore raw

Re: [RFC PATCH net-next v2 09/17] ethtool: implement GET_DRVINFO message

In reply to Andrew Lunn
Quoted 8 lines · Andrew Lunn

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

Quoted 5 lines · Michal Kubecek
Documentation/networking/ethtool-netlink.txt +5 -0
+    ETHA_DRVINFO_FWVERSION	(string)	firmware version
+    ETHA_DRVINFO_BUSINFO	(string)	device bus address
+    ETHA_DRVINFO_EROM_VER	(string)	expansion ROM version
+    ETHA_DRVINFO_N_PRIV_FLAGS	(u32)		number of private flags
+    ETHA_DRVINFO_N_STATS	(u32)		number of device stats
Quoted 8 lines

I know there is at least one driver that has somewhat dynamic number of statistics. It would be better to have the strings and the values in the same message, so there is no need to first get the number of strings, allocate the memory, get the strings, then get the values.

Quoted 1 line

+ ETHA_DRVINFO_TESTINFO_LEN (u32) number of test results

In theory, this also does not need to be fixed.

This is interesting. It would mean current (ioctl) ethtool approach with string set may not work correctly either. On the other hand, this should not be a problem for netlink interface. Statistics are unlikely to appear in notifications and daemons collecting them periodically will have to learn with it. Adding test name to notification "test started" or "test finished" seems quite natural.

Quoted 5 lines

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

Quoted 2 lines
Documentation/networking/ethtool-netlink.txt +2 -0
+    ETHA_DRVINFO_EEDUMP_LEN	(u32)		EEPROM dump size
+    ETHA_DRVINFO_REGDUMP_LEN	(u32)		register dump size

I would suggest removing all these _LEN properties, and let netlink return what it needs to return.

Agreed.

Michal Kubecek

maintainer
#17 lore raw

Re: [RFC PATCH net-next v2 09/17] ethtool: implement GET_DRVINFO message

Quoted 2 lines

This is interesting. It would mean current (ioctl) ethtool approach with string set may not work correctly either.

Hi Michal

For the statistics, it is a bit of a corner case. One of the Ethernet switches in DSA can have two different PHYs linked to one MAC. One PHY is built in, the second is connected via a SERDES interface. Which every gets link first is used. However, the SERDES interface has additional statistics counters. So if the SERDES is in use, we return more statistics. If somebody was to plug in the cable at just the wrong/right time, the count of statistics could be different to the number of statistics.

Another corner case i can think of. Some drivers return statistics per queue. And there is an ioctl to change the number of queues....

I could also imaging tests being similar. There are more loopback tests you can do with a SERDES which you cannot do with a built in PHY. But so far, i've not seen anything like that.

Andrew

#18 lore raw

Re: [RFC PATCH net-next v2 09/17] ethtool: implement GET_DRVINFO message

Quoted 10 lines · Andrew Lunn

For the statistics, it is a bit of a corner case. One of the Ethernet switches in DSA can have two different PHYs linked to one MAC. One PHY is built in, the second is connected via a SERDES interface. Which every gets link first is used. However, the SERDES interface has additional statistics counters. So if the SERDES is in use, we return more statistics. If somebody was to plug in the cable at just the wrong/right time, the count of statistics could be different to the number of statistics.

Quoted 6 lines

Another corner case i can think of. Some drivers return statistics per queue. And there is an ioctl to change the number of queues....

I could also imaging tests being similar. There are more loopback tests you can do with a SERDES which you cannot do with a built in PHY. But so far, i've not seen anything like that.

Thank you for the explanation. What I have in mind is that there are two different types of userspace applications: one shot and running long term. It can be seen in my series in the way e.g. link modes are handled. There are two formats in which a bitset can be passed: verbose (list of bits with names) or compact (just bitmaps). For one shot queries (e.g. "ethtool eth0") it's easier to use verbose format so that you get names with bit values in one package. But for long running applications processing many messages ("ethtool --monitor" or config management daemons), it's more practical to load the names once and pass only data with each notification or response.

I suppose in the scenarios you mentioned the driver would be able to trigger a notification whenever the list changes so that userspace application could reload the string set.

Michal Kubecek

#8 lore raw

Re: [RFC PATCH net-next v2 06/17] ethtool: support for netlink notifications

In reply to Jiri Pirko
Quoted 4 lines · Jiri Pirko

Mon, Jul 30, 2018 at 02:53:12PM CEST, [email protected] wrote:

[...]

Quoted 12 lines

include/linux/netdevice.h enum netdev_cmd { · line 2447

Quoted 9 lines
include/linux/netdevice.h +1 -0
index c1295c7a452e..c4b0c575d57e 100644
@@ -2444,6 +2444,7 @@ enum netdev_cmd {
 	NETDEV_CVLAN_FILTER_DROP_INFO,
 	NETDEV_SVLAN_FILTER_PUSH_INFO,
 	NETDEV_SVLAN_FILTER_DROP_INFO,
+	NETDEV_ETHTOOL,

I don't understand why this goes through netdev notifier. What's the reason?

To allow triggering a notification from other code (ethtool ioctl or e.g. netdev_features_change()) when netlink interface is built as a module. If it's a (performance?) problem, an alternative could be having a global pointer which would be either null or point to ethtool_notify() depending on whether the module is loaded (and ready).

(Which made me realize I forgot to handle a race between module unloading and processing a notification.)

Another question is if we really need the option to build the netlink interface as a module. I must admit my main motivation to have it as a module is that it makes testing and debugging easier.

Michal

maintainer
#21 lore raw

Re: [RFC PATCH net-next v2 10/17] ethtool: implement GET_SETTINGS message

In reply to Michal Kubecek
Quoted 9 lines

+/* Internal kernel helper to query a device ethtool_link_settings.
+ *
+ * Backward compatibility note: for compatibility with legacy drivers
+ * that implement only the ethtool_cmd API, this has to work with both
+ * drivers implementing get_link_ksettings API and drivers
+ * implementing get_settings API. When drivers implement get_settings
+ * and report ethtool_cmd deprecated fields
+ * (transceiver/maxrxpkt/maxtxpkt), these fields are silently ignored
+ * because the resulting struct ethtool_link_settings does not report them.

~/linux/drivers$ grep -r [.]get_settings *
net/ethernet/8390/etherh.c: .get_settings = etherh_get_settings,

I don't think it is worth adding support for .get_settings for just one driver. It is better to just convert that driver to the new API.

Andrew

maintainer
#25 lore raw

Re: [RFC PATCH net-next v2 10/17] ethtool: implement GET_SETTINGS message

In reply to Michal Kubecek
Quoted 1 line

+ ETHA_SETTINGS_MDIO_SUPPORT (bitfield32) MDIO support flags

Now might be a good time to drop this. The mdio drivers don't have this information. There is no API between the MAC driver and the MDIO driver to ask for it. Only a couple of drivers which ignore the kernel MDIO code set this.

Andrew

maintainer
#26 lore raw

Re: [RFC PATCH net-next v2 10/17] ethtool: implement GET_SETTINGS message

In reply to Michal Kubecek

Documentation/networking/ethtool-netlink.txt GET_DRVINFO requests).

Quoted 5 lines
Documentation/networking/ethtool-netlink.txt +4 -0
+Response contents:
+
+    ETHA_SETTINGS_LINK		(u32)		link state
 
+	[ETHA_SETTINGS_LINK]		= { .type = NLA_FLAG },

Is this correct?

The link is either up or down. So a u32 seems a bit big.

Andrew

#27 lore raw

Re: [RFC PATCH net-next v2 10/17] ethtool: implement GET_SETTINGS message

Quoted 7 lines · Andrew Lunn

Documentation/networking/ethtool-netlink.txt GET_DRVINFO requests).

Quoted 5 lines
Documentation/networking/ethtool-netlink.txt +4 -0
+Response contents:
+
+    ETHA_SETTINGS_LINK		(u32)		link state
 
+	[ETHA_SETTINGS_LINK]		= { .type = NLA_FLAG },

Is this correct?

NLA_FLAG is wrong, we need three states: on/off/unknown for "get" replies and on/off/keep for "set" requests.

Quoted 1 line

The link is either up or down. So a u32 seems a bit big.

I tend to use u32 everywhere with some obvious exceptions. The reason is that netlink attributes are padded to 32 bits so that no matter if you use u8, u16 or u32, the attribute still ends up taking 8 bytes. But yes, this looks like an obvious exception where u8 wouldn't mean any risk of running out of values one day.

Michal Kubecek

#36 lore raw
In reply to Jiri Pirko
Quoted 9 lines · Jiri Pirko
Quoted 5 lines

- find reasonable format for data transfers (e.g. eeprom dump or flash); I don't have clear idea how big these can get and if 64 KB limit on attribute size (including nested ones) is a problem; if so, dumps can be an answer for dumps, some kind of multi-message requests would be needed for flashes

This is another thing that should go into devlink as it is not netdev-handled. We have now a "region" facility there which can be re-used.

+1 regions should cover the current use cases and are a better API IMHO.

#19 lore raw

Re: [RFC PATCH net-next v2 09/17] ethtool: implement GET_DRVINFO message

In reply to Michal Kubecek
Quoted 6 lines · Michal Kubecek
Documentation/networking/ethtool-netlink.txt +6 -0
+GET_DRVINFO
+-----------
+
+GET_DRVINFO request corresponds to ETHTOOL_GDRVINFO ioctl command and provides
+basic driver information.
+

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

Quoted 10 lines
Documentation/networking/ethtool-netlink.txt +10 -0
+Request contents:
+
+    ETHA_DRVINFO_DEV		(nested)	device identification
+
+Kernel response contents:
+
+    ETHA_DRVINFO_DEV		(nested)	device identification
+    ETHA_DRVINFO_DRIVER		(string)	driver name
+    ETHA_DRVINFO_VERSION	(string)	driver version
+    ETHA_DRVINFO_FWVERSION	(string)	firmware version

FWIW I think fwinfo belongs to devlink, and should be split. Most modern drivers provide versions of multiple FW components smooshed into a single string. Perhaps it's time to allow this facility to carry multiple key: value entries?

Quoted 1 line

+ ETHA_DRVINFO_BUSINFO (string) device bus address

I wonder if some of this information is also not duplicated with sysfs. There should be a link from the netdev to a sysfs device. Same for driver name.

I'm probably missing some uses (in embedded world?) and will be corrected.. :)

Quoted 6 lines
Documentation/networking/ethtool-netlink.txt +6 -0
+    ETHA_DRVINFO_EROM_VER	(string)	expansion ROM version
+    ETHA_DRVINFO_N_PRIV_FLAGS	(u32)		number of private flags
+    ETHA_DRVINFO_N_STATS	(u32)		number of device stats
+    ETHA_DRVINFO_TESTINFO_LEN	(u32)		number of test results
+    ETHA_DRVINFO_EEDUMP_LEN	(u32)		EEPROM dump size
+    ETHA_DRVINFO_REGDUMP_LEN	(u32)		register dump size
#9 lore raw

Re: [RFC PATCH net-next v2 06/17] ethtool: support for netlink notifications

In reply to Michal Kubecek
Quoted 24 lines · Mon, Jul 30, 2018 at 07:01:21PM CEST, [email protected] wrote:
Quoted 4 lines · Jiri Pirko

Mon, Jul 30, 2018 at 02:53:12PM CEST, [email protected] wrote:

[...]

Quoted 12 lines

include/linux/netdevice.h enum netdev_cmd { · line 2447

Quoted 9 lines
include/linux/netdevice.h +1 -0
index c1295c7a452e..c4b0c575d57e 100644
@@ -2444,6 +2444,7 @@ enum netdev_cmd {
 	NETDEV_CVLAN_FILTER_DROP_INFO,
 	NETDEV_SVLAN_FILTER_PUSH_INFO,
 	NETDEV_SVLAN_FILTER_DROP_INFO,
+	NETDEV_ETHTOOL,

I don't understand why this goes through netdev notifier. What's the reason?

To allow triggering a notification from other code (ethtool ioctl or e.g. netdev_features_change()) when netlink interface is built as a module. If it's a (performance?) problem, an alternative could be having a global pointer which would be either null or point to ethtool_notify() depending on whether the module is loaded (and ready).

Quoted 6 lines

(Which made me realize I forgot to handle a race between module unloading and processing a notification.)

Another question is if we really need the option to build the netlink interface as a module. I must admit my main motivation to have it as a module is that it makes testing and debugging easier.

Yeah. It is very core thing. I think it does not have to be a module.

#22 lore raw

Re: [RFC PATCH net-next v2 10/17] ethtool: implement GET_SETTINGS message

In reply to Andrew Lunn
Quoted 10 lines · Andrew Lunn
Quoted 9 lines

+/* Internal kernel helper to query a device ethtool_link_settings.
+ *
+ * Backward compatibility note: for compatibility with legacy drivers
+ * that implement only the ethtool_cmd API, this has to work with both
+ * drivers implementing get_link_ksettings API and drivers
+ * implementing get_settings API. When drivers implement get_settings
+ * and report ethtool_cmd deprecated fields
+ * (transceiver/maxrxpkt/maxtxpkt), these fields are silently ignored
+ * because the resulting struct ethtool_link_settings does not report them.

Quoted 5 lines

~/linux/drivers$ grep -r [.]get_settings *
net/ethernet/8390/etherh.c: .get_settings = etherh_get_settings,

I don't think it is worth adding support for .get_settings for just one driver. It is better to just convert that driver to the new API.

I have prepared a patch converting 8390/etherh driver to use {g,s}et_link_ksettings and I'm going to submit it when net-next opens. Do you think we can then drop {g,s}et_settings callbacks completely (i.e. also from ioctl() code and ethtool_ops)? Do we care about unconverted out of tree drivers?

Michal Kubecek

maintainer
#23 lore raw

Re: [RFC PATCH net-next v2 10/17] ethtool: implement GET_SETTINGS message

Quoted 14 lines · Michal Kubecek
Quoted 13 lines · Andrew Lunn
Quoted 9 lines

+/* Internal kernel helper to query a device ethtool_link_settings.
+ *
+ * Backward compatibility note: for compatibility with legacy drivers
+ * that implement only the ethtool_cmd API, this has to work with both
+ * drivers implementing get_link_ksettings API and drivers
+ * implementing get_settings API. When drivers implement get_settings
+ * and report ethtool_cmd deprecated fields
+ * (transceiver/maxrxpkt/maxtxpkt), these fields are silently ignored
+ * because the resulting struct ethtool_link_settings does not report them.

~/linux/drivers$ grep -r [.]get_settings *
net/ethernet/8390/etherh.c: .get_settings = etherh_get_settings,

Quoted 8 lines
Quoted 2 lines

I don't think it is worth adding support for .get_settings for just one driver. It is better to just convert that driver to the new API.

I have prepared a patch converting 8390/etherh driver to use {g,s}et_link_ksettings and I'm going to submit it when net-next opens. Do you think we can then drop {g,s}et_settings callbacks completely (i.e. also from ioctl() code and ethtool_ops)? Do we care about unconverted out of tree drivers?

Hi Michal

We cannot break ethtool, the ABI it uses. But there is already code to use get_link_ksettings() and only fall back to get_settings if it does not exist. So we can clean up all the fallback code, remove the ethtool_ops, etc.

I personally don't care about out of tree drivers. They have had over 2 years to change to the new API.

Andrew

#24 lore raw

Re: [RFC PATCH net-next v2 10/17] ethtool: implement GET_SETTINGS message

Quoted 11 lines · Andrew Lunn
Quoted 5 lines · Michal Kubecek

I have prepared a patch converting 8390/etherh driver to use {g,s}et_link_ksettings and I'm going to submit it when net-next opens. Do you think we can then drop {g,s}et_settings callbacks completely (i.e. also from ioctl() code and ethtool_ops)? Do we care about unconverted out of tree drivers?

We cannot break ethtool, the ABI it uses. But there is already code to use get_link_ksettings() and only fall back to get_settings if it does not exist. So we can clean up all the fallback code, remove the ethtool_ops, etc.

Yes, that's what I have in mind: keep the ethtool interface as is (both ETHTOOL_{G,S}SET and ETHTOOL_{G,S}LINKSETTINGS) but drop get_settings and set_settings from ethtool_ops and the code that falls back to them. This way both old and new versions of ethtool would still work and the only problem would be with out of tree drivers not converted to {s,g}et_link_ksettings (which won't build so that it won't be silent breakage).

Michal Kubecek