ethtool netlink interface (WiP)
Subsystems (4)
cover ethtool netlink interface (WiP)
This is still work in progress and only a very small part of the ioctl interface is reimplemented but I would like to get some comments before the patchset becomes too big and changing things becomes too tedious.
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 or systemd-networkd).
The interface is documented in Documentation/networking/ethtool-netlink.txt
I'll post RFC patch series for ethtool in a few days, it still needs some more polishing.
Basic concepts:
- the interface is based on generic netlink (family name "ethtool")
- provide everything ioctl can do 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, userspace can simply say what it wants to change and how
- be less dependent on ethtool and kernel being in sync; allow e.g. saying "ethtool -s eth0 advertise xyz off" without knowing what "xyz" means; it's kernel's job to know what mode "xyz" is and if it exists and is supported
Unresolved questions/tasks:
- allow dumps for "get" type requests, e.g. listing EEE settings for all interfaces in current netns
- find reasonable format for data transfers (e.g. eeprom dump or flash)
- 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
Michal Kubecek (9):
netlink: introduce nla_put_bitfield32()
ethtool: introduce ethtool netlink interface
ethtool: helper functions for netlink interface
ethtool: netlink bitset handling
ethtool: implement GET_DRVINFO message
ethtool: implement GET_SETTINGS message
ethtool: implement SET_SETTINGS message
ethtool: implement GET_PARAMS message
ethtool: implement SET_PARAMS message
Documentation/networking/ethtool-netlink.txt | 466 ++++++ include/linux/ethtool_netlink.h | 12 + include/linux/netdevice.h | 2 + include/net/netlink.h | 15 + include/uapi/linux/ethtool.h | 3 + include/uapi/linux/ethtool_netlink.h | 239 +++ net/Kconfig | 7 + net/core/Makefile | 3 +- net/core/ethtool.c | 150 +- net/core/ethtool_common.c | 158 ++ net/core/ethtool_common.h | 19 + net/core/ethtool_netlink.c | 2323 ++++++++++++++++++++++++++ 12 files changed, 3260 insertions(+), 137 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/core/ethtool_common.c create mode 100644 net/core/ethtool_common.h create mode 100644 net/core/ethtool_netlink.c
Signature · 1 line
2.15.1
RFC PATCH 1/9 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
@@ -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.15.1
RFC PATCH 2/9 ethtool: introduce ethtool netlink interface
In reply to Michal KubecekNo 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 | 155 +++++++++++++++++++++++++++ include/linux/ethtool_netlink.h | 9 ++ include/uapi/linux/ethtool_netlink.h | 33 ++++++ net/Kconfig | 7 ++ net/core/Makefile | 1 + net/core/ethtool_netlink.c | 46 ++++++++ 6 files changed, 251 insertions(+) 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/core/ethtool_netlink.c
Documentation/networking/ethtool-netlink.txt new file +155 -0
@@ -0,0 +1,155 @@ + 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 uses a message +header of 24 bytes: + +struct ethnlmsghdr { + __u32 ifindex; + __u16 flags; + union { + __u16 info_mask; + __u16 index; + } + char ifname[IFNAMSIZ]; +}; + +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. + + +List of message types +--------------------- + +All constants use ETHTOOL_CMD_ prefix 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 corresopinding "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. + +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
@@ -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 +33 -0
@@ -0,0 +1,33 @@ +/* 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> + +/* identifies the device to query/set +* - use either ifindex or ifname, not both +* - for dumps and messages not related to a particular devices, fill neither +* - info_mask is a bitfield, interpretation depends on the command +*/ +struct ethnlmsghdr { +__u32 ifindex;/* device ifindex */ +__u16 flags;/* request/response flags */ +__u16 info_mask;/* request/response info mask */ +char ifname[IFNAMSIZ ];/* device name */ +}; + +#define ETHNL_HDRLEN NLMSG_ALIGN(sizeof(struct ethnlmsghdr)) + +enum { +ETHTOOL_CMD_NOOP , + + __ETHTOOL_CMD_MAX, +ETHTOOL_CMD_MAX = (__ETHTOOL_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
@@ -440,6 +440,13 @@ config MAY_USE_DEVLINK on MAY_USE_DEVLINK to ensure they do not cause link errors when devlink is a loadable module and the driver using it is built-in. +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/core/Makefile +1 -0
@@ -30,3 +30,4 @@ obj-$(CONFIG_DST_CACHE) += dst_cache.o obj-$(CONFIG_HWBM) += hwbm.o obj-$(CONFIG_NET_DEVLINK) += devlink.o obj-$(CONFIG_GRO_CELLS) += gro_cells.o +obj-$(CONFIG_ETHTOOL_NETLINK) += ethtool_netlink.o
net/core/ethtool_netlink.c new file +46 -0
46 lines not on this page · raw message
Signature · 1 line
2.15.1
RFC PATCH 3/9 ethtool: helper functions for netlink interface
In reply to Michal KubecekMisc helpers used by ethtool netlink code.
--- net/core/ethtool_netlink.c | 177 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 177 insertions(+)
net/core/ethtool_netlink.c +177 -0
@@ -8,6 +8,183 @@static struct genl_family ethtool_genl_family; +/* misc helper functions */ + +static int ethnl_str_size (const char *s) +{ +return nla_total_size (strlen (s) +1 ); +} + +static int ethnl_str_ifne_size (const char *s) +{ +return s[0 ] ?ethnl_str_size (s) :0 ; +} + +static int ethnl_put_str_ifne (struct sk_buff *skb,int attrtype,const char *s) +{ +if (!s[0 ]) +return 0 ; +return nla_put_string (skb, attrtype, s); +} + +static struct nlattr *ethnl_nest_start (struct sk_buff *skb,int attrtype) +{ +return nla_nest_start (skb, attrtype |NLA_F_NESTED ); +} + +/* ethnl_update_* return true if the value is changed */ +static bool ethnl_update_u32 (u32 *dst,struct nlattr *attr) +{ +u32 val; + +if (!attr) +return false; + val =nla_get_u32 (attr); +if (*dst == val) +return false; + + *dst = val; +return true; +} + +static bool ethnl_update_u8 (u8 *dst,struct nlattr *attr) +{ +u8 val; + +if (!attr) +return false; + val =nla_get_u8 (attr); +if (*dst == val) +return false; + + *dst = val; +return true; +} + +/* update u32 value used as bool from NLA_U8 */ +static bool ethnl_update_bool32 (u32 *dst,struct nlattr *attr) +{ +u8 val; + +if (!attr) +return false; + val = !!nla_get_u8 (attr); +if (!!*dst == val) +return false; + + *dst = val; +return true; +} + +static bool ethnl_update_binary (u8 *dst,unsigned int len,struct nlattr *attr) +{ +if (!attr) +return false; +if (nla_len (attr) < len) + len =nla_len (attr); +if (!memcmp (dst,nla_data (attr), len)) +return false; + +memcpy (dst,nla_data (attr), len); +return true; +} + +static bool ethnl_update_bitfield32 (u32 *dst,struct nlattr *attr) +{ +struct nla_bitfield32 change; +u32 newval; + +if (!attr) +return false; + change =nla_get_bitfield32 (attr); + newval = (*dst & ~change.selector) | (change.value & change.selector); +if (*dst == newval) +return false; + + *dst = newval; +return true; +} + +static struct net_device *ethnl_dev_get (struct genl_info *info) +{ +const struct ethnlmsghdr *hdr = info->userhdr; +struct net *net =genl_info_net (info); +struct net_device *dev; + +if (hdr->ifindex) { + dev =dev_get_by_index (net, hdr->ifindex); +if (!dev) +return ERR_PTR (-ENODEV ); +/* if both ifindex and ifname are passed, both must match */ +if (hdr->ifname &&strncmp (dev->name, hdr->ifname,IFNAMSIZ )) { +GENL_SET_ERR_MSG (info, +"ifindex and ifname do not match" ); +return ERR_PTR (-ENODEV ); + } +return dev; + }else if (hdr->ifname[0 ]) { + dev =dev_get_by_name (net, hdr->ifname); +return dev ?:ERR_PTR (-ENODEV ); + } + +return ERR_PTR (-EINVAL ); +} + +static void warn_partial_info (struct genl_info *info) +{ +GENL_SET_ERR_MSG (info,"not all requested data could be retrieved" ); +} + +/* Check user privileges explicitly to allow finer access control based on +* context of the request or hiding part of the information from unprivileged +* users +*/ +static bool ethnl_is_privileged (struct sk_buff *skb,struct genl_info *info) +{ +struct net *net =genl_info_net (info); + +return netlink_ns_capable (skb, net->user_ns,CAP_NET_ADMIN ); +} + +/* create skb for a reply +* payload: payload length (without netlink, genetlink and ethnl headers) +* dev: device the reply is about +* cmd: ETHTOOL_CMD_* command for reply +* info: info for the received packet we respond to +* ehdrp: place to store pointer to ethtool specific header (may be null) +* returns: skb or null on error +*/ +static struct sk_buff *ethnl_reply_init (size_t payload,struct net_device *dev, +u8 cmd,struct genl_info *info, +struct ethnlmsghdr **ehdrp) +{ +struct ethnlmsghdr *ehdr; +struct sk_buff *rskb; + + rskb =genlmsg_new (ETHNL_HDRLEN + payload,GFP_KERNEL ); +if (!rskb) { +GENL_SET_ERR_MSG (info, +"failed to allocate reply message" ); +return NULL ; + } + + ehdr =genlmsg_put_reply (rskb, info, ðtool_genl_family,0 , cmd); +if (!ehdr) { +nlmsg_free (rskb); +return NULL ; + } +if (ehdrp) + *ehdrp = ehdr; + + ehdr->ifindex = dev->ifindex; + ehdr->flags =0 ; + ehdr->info_mask =0 ; +strncpy (ehdr->ifname, dev->name,sizeof (ehdr->ifname)); + ehdr->ifname[sizeof (ehdr->ifname) -1 ] ='\0' ; + +return rskb; +} +/* genetlink paperwork */ static const struct genl_ops ethtool_genl_ops[] = {
Signature · 1 line
2.15.1
RFC PATCH 4/9 ethtool: netlink bitset handling
In reply to Michal KubecekDeclare 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/core/ethtool_netlink.c | 346 +++++++++++++++++++++++++++ 3 files changed, 433 insertions(+)
Documentation/networking/ethtool-netlink.txt +56 -0
@@ -48,6 +48,62 @@ 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. +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
@@ -26,6 +26,37 @@ enum { ETHTOOL_CMD_MAX = (__ETHTOOL_CMD_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/core/ethtool_netlink.c +346 -0
358 lines not on this page · raw message
Signature · 1 line
2.15.1
RFC PATCH 5/9 ethtool: implement GET_DRVINFO message
In reply to Michal KubecekRequest the same information as ETHTOOL_GDRVINFO. This is read-only so that corresponding SET_DRVINFO exists but is only used in kernel replies. Rip the code to query the driver out of the legacy interface and move it to a new file ethtool_common.c so that both interfaces can use it.
--- Documentation/networking/ethtool-netlink.txt | 30 ++++++++++- include/uapi/linux/ethtool_netlink.h | 21 ++++++++ net/core/Makefile | 2 +- net/core/ethtool.c | 42 +++------------- net/core/ethtool_common.c | 46 +++++++++++++++++ net/core/ethtool_common.h | 11 ++++ net/core/ethtool_netlink.c | 75 ++++++++++++++++++++++++++++ 7 files changed, 189 insertions(+), 38 deletions(-) create mode 100644 net/core/ethtool_common.c create mode 100644 net/core/ethtool_common.h
Documentation/networking/ethtool-netlink.txt +29 -1
@@ -107,6 +107,9 @@ which the request applies. List of message types --------------------- + ETHTOOL_CMD_GET_DRVINFO + ETHTOOL_CMD_SET_DRVINFO response only + All constants use ETHTOOL_CMD_ prefix followed by "GET", "SET" or "ACT" to indicate the type.
@@ -119,6 +122,31 @@ messages marked as "response only" in the table above. Later sections describe the format and semantics of these request messages. +GET_DRVINFO +----------- + +GET_DRVINFO request corresponds to ETHTOOL_GDRVINFO ioctl command and provides +basic driver information. The request doesn't use any attributes and flags, +info_mask and index field in request header are ignored. Kernel response +contents: + + 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. + + Request translation -------------------
@@ -130,7 +158,7 @@ ioctl command netlink command --------------------------------------------------------------------- ETHTOOL_GSET n/a ETHTOOL_SSET n/a -ETHTOOL_GDRVINFO n/a +ETHTOOL_GDRVINFO ETHTOOL_CMD_GET_DRVINFO ETHTOOL_GREGS n/a ETHTOOL_GWOL n/a ETHTOOL_SWOL n/a
include/uapi/linux/ethtool_netlink.h +21 -0
@@ -21,6 +21,8 @@ struct ethnlmsghdr {enum {ETHTOOL_CMD_NOOP , +ETHTOOL_CMD_GET_DRVINFO , +ETHTOOL_CMD_SET_DRVINFO ,/* only for reply */ __ETHTOOL_CMD_MAX,ETHTOOL_CMD_MAX = (__ETHTOOL_CMD_MAX -1 ),
@@ -57,6 +59,25 @@ enum { ETHA_BITSET_MAX = (__ETHA_BITSET_MAX - 1), }; +/* GET_DRVINFO / SET_DRVINFO */ + +enum { +ETHA_DRVINFO_UNSPEC , +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/core/Makefile +1 -1
@@ -11,7 +11,7 @@ obj-$(CONFIG_SYSCTL) += sysctl_net_core.o obj-y += dev.o ethtool.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 + fib_notifier.o ethtool_common.o obj-y += net-sysfs.o obj-$(CONFIG_PROC_FS) += net-procfs.o
net/core/ethtool.c +6 -36
57 lines not on this page · raw message
net/core/ethtool_common.c new file +46 -0
46 lines not on this page · raw message
net/core/ethtool_common.h new file +11 -0
@@ -0,0 +1,11 @@ +/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ + +#ifndef _ETHTOOL_COMMON_H +#define _ETHTOOL_COMMON_H + +#include <linux/netdevice.h> +#include <linux/ethtool.h> + +int __ethtool_get_drvinfo (struct net_device *dev,struct ethtool_drvinfo *info); + +#endif /* _ETHTOOL_COMMON_H */
net/core/ethtool_netlink.c +75 -0
84 lines not on this page · raw message
Signature · 1 line
2.15.1
RFC PATCH 6/9 ethtool: implement GET_SETTINGS message
In reply to Michal KubecekRequests 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 | 62 +++++- include/linux/ethtool_netlink.h | 3 + include/linux/netdevice.h | 2 + include/uapi/linux/ethtool.h | 3 + include/uapi/linux/ethtool_netlink.h | 36 ++++ net/core/ethtool.c | 108 +--------- net/core/ethtool_common.c | 112 ++++++++++ net/core/ethtool_common.h | 8 + net/core/ethtool_netlink.c | 299 +++++++++++++++++++++++++++ 9 files changed, 528 insertions(+), 105 deletions(-)
Documentation/networking/ethtool-netlink.txt +57 -5
@@ -109,6 +109,8 @@ List of message types ETHTOOL_CMD_GET_DRVINFO ETHTOOL_CMD_SET_DRVINFO response only + ETHTOOL_CMD_GET_SETTINGS + ETHTOOL_CMD_SET_SETTINGS response only (for now) All constants use ETHTOOL_CMD_ prefix followed by "GET", "SET" or "ACT" to indicate the type.
@@ -147,6 +149,56 @@ response. All information is read only, SET_DRVINFO request is not implemented. +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. + +Header flags: + ETH_SETTINGS_RF_COMPACT_BITSETS bitset form in response (1 is compact) + +Header info_mask bits: + 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 + +Zero info_mask + +Response contents: + + 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. + + Request translation -------------------
@@ -156,16 +208,16 @@ have their netlink replacement yet. ioctl command netlink command --------------------------------------------------------------------- -ETHTOOL_GSET n/a +ETHTOOL_GSET ETHTOOL_CMD_GET_SETTINGS ETHTOOL_SSET n/a ETHTOOL_GDRVINFO ETHTOOL_CMD_GET_DRVINFO ETHTOOL_GREGS n/a -ETHTOOL_GWOL n/a +ETHTOOL_GWOL ETHTOOL_CMD_GET_SETTINGS ETHTOOL_SWOL n/a -ETHTOOL_GMSGLVL n/a +ETHTOOL_GMSGLVL ETHTOOL_CMD_GET_SETTINGS ETHTOOL_SMSGLVL n/a ETHTOOL_NWAY_RST n/a -ETHTOOL_GLINK n/a +ETHTOOL_GLINK ETHTOOL_CMD_GET_SETTINGS ETHTOOL_GEEPROM n/a ETHTOOL_SEEPROM n/a ETHTOOL_GCOALESCE n/a
@@ -230,7 +282,7 @@ ETHTOOL_GTUNABLE n/a ETHTOOL_STUNABLE n/a ETHTOOL_GPHYSTATS n/a ETHTOOL_PERQUEUE n/a -ETHTOOL_GLINKSETTINGS n/a +ETHTOOL_GLINKSETTINGS ETHTOOL_CMD_GET_SETTINGS ETHTOOL_SLINKSETTINGS n/a ETHTOOL_PHY_GTUNABLE n/a ETHTOOL_PHY_STUNABLE n/a
include/linux/ethtool_netlink.h +3 -0
@@ -6,4 +6,7 @@#include <uapi/linux/ethtool_netlink.h> #include <linux/ethtool.h> +#define __ETHTOOL_LINK_MODE_MASK_NWORDS \ + ((__ETHTOOL_LINK_MODE_MASK_NBITS + 31) / 32) +#endif /* _LINUX_ETHTOOL_NETLINK_H_ */
include/linux/netdevice.h +2 -0
@@ -3506,6 +3506,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
@@ -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 +36 -0
@@ -23,6 +23,8 @@ enum {ETHTOOL_CMD_NOOP ,ETHTOOL_CMD_GET_DRVINFO ,ETHTOOL_CMD_SET_DRVINFO ,/* only for reply */ +ETHTOOL_CMD_GET_SETTINGS , +ETHTOOL_CMD_SET_SETTINGS , __ETHTOOL_CMD_MAX, ETHTOOL_CMD_MAX = (__ETHTOOL_CMD_MAX - 1),
@@ -78,6 +80,40 @@ enum { ETHA_DRVINFO_MAX = (__ETHA_DRVINFO_MAX - 1), }; +/* GET_SETTINGS / SET_SETTINGS */ + +enum { +ETHA_SETTINGS_UNSPEC , +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_RF_COMPACT_BITSETS 0x1 + +#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/core/ethtool.c +8 -100
135 lines not on this page · raw message
net/core/ethtool_common.c +112 -0
115 lines not on this page · raw message
net/core/ethtool_common.h +8 -0
@@ -7,5 +7,13 @@#include <linux/ethtool.h> 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/core/ethtool_netlink.c +299 -0
322 lines not on this page · raw message
Signature · 1 line
2.15.1
RFC PATCH 7/9 ethtool: implement SET_SETTINGS message
In reply to Michal KubecekSets 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 | 42 +- net/core/ethtool_netlink.c | 547 +++++++++++++++++++++++++++ 2 files changed, 584 insertions(+), 5 deletions(-)
Documentation/networking/ethtool-netlink.txt +37 -5
@@ -110,7 +110,7 @@ List of message types ETHTOOL_CMD_GET_DRVINFO ETHTOOL_CMD_SET_DRVINFO response only ETHTOOL_CMD_GET_SETTINGS - ETHTOOL_CMD_SET_SETTINGS response only (for now) + ETHTOOL_CMD_SET_SETTINGS All constants use ETHTOOL_CMD_ prefix followed by "GET", "SET" or "ACT" to indicate the type.
@@ -199,6 +199,38 @@ is only provided by kernel in response to privileged (netns CAP_NET_ADMIN) requests. +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_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 -------------------
@@ -209,13 +241,13 @@ have their netlink replacement yet. ioctl command netlink command --------------------------------------------------------------------- ETHTOOL_GSET ETHTOOL_CMD_GET_SETTINGS -ETHTOOL_SSET n/a +ETHTOOL_SSET ETHTOOL_CMD_SET_SETTINGS ETHTOOL_GDRVINFO ETHTOOL_CMD_GET_DRVINFO ETHTOOL_GREGS n/a ETHTOOL_GWOL ETHTOOL_CMD_GET_SETTINGS -ETHTOOL_SWOL n/a +ETHTOOL_SWOL ETHTOOL_CMD_SET_SETTINGS ETHTOOL_GMSGLVL ETHTOOL_CMD_GET_SETTINGS -ETHTOOL_SMSGLVL n/a +ETHTOOL_SMSGLVL ETHTOOL_CMD_SET_SETTINGS ETHTOOL_NWAY_RST n/a ETHTOOL_GLINK ETHTOOL_CMD_GET_SETTINGS ETHTOOL_GEEPROM n/a
@@ -283,7 +315,7 @@ ETHTOOL_STUNABLE n/a ETHTOOL_GPHYSTATS n/a ETHTOOL_PERQUEUE n/a ETHTOOL_GLINKSETTINGS ETHTOOL_CMD_GET_SETTINGS -ETHTOOL_SLINKSETTINGS n/a +ETHTOOL_SLINKSETTINGS ETHTOOL_CMD_SET_SETTINGS ETHTOOL_PHY_GTUNABLE n/a ETHTOOL_PHY_STUNABLE n/a ETHTOOL_GFECPARAM n/a
net/core/ethtool_netlink.c +547 -0
583 lines not on this page · raw message
Signature · 1 line
2.15.1
RFC PATCH 8/9 ethtool: implement GET_PARAMS message
In reply to Michal KubecekRequests 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 | 98 ++++++- include/uapi/linux/ethtool_netlink.h | 118 ++++++++ net/core/ethtool_netlink.c | 411 +++++++++++++++++++++++++++ 3 files changed, 621 insertions(+), 6 deletions(-)
Documentation/networking/ethtool-netlink.txt +92 -6
@@ -111,6 +111,8 @@ List of message types ETHTOOL_CMD_SET_DRVINFO response only ETHTOOL_CMD_GET_SETTINGS ETHTOOL_CMD_SET_SETTINGS + ETHTOOL_CMD_GET_PARAMS + ETHTOOL_CMD_SET_PARAMS response only (for now) All constants use ETHTOOL_CMD_ prefix followed by "GET", "SET" or "ACT" to indicate the type.
@@ -231,6 +233,90 @@ is supposed to allow requesting changes without knowing what exactly kernel supports. +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. + +Header flags: + ETH_PARAMS_RF_COMPACT_BITSETS bitset form in response (1 is compact) + +Header 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 + +On top level, there is one attribute for each of the information categories, +the information is nested in it. + + 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_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 (nest) pause parameters + ETHA_PAUSE_AUTONEG (bool) + ETHA_PAUSE_RX (bool) + ETHA_PAUSE_TX (bool) + ETHA_PARAMS_CHANNELS (nest) 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 (nest) 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 (nest) FEC parameters + ETHA_FEC_MODES (bitfield32) + - active (value) and configured (selector) FEC encodings + + + Request translation -------------------
@@ -252,11 +338,11 @@ ETHTOOL_NWAY_RST n/a ETHTOOL_GLINK ETHTOOL_CMD_GET_SETTINGS ETHTOOL_GEEPROM n/a ETHTOOL_SEEPROM n/a -ETHTOOL_GCOALESCE n/a +ETHTOOL_GCOALESCE ETHTOOL_CMD_GET_PARAMS ETHTOOL_SCOALESCE n/a -ETHTOOL_GRINGPARAM n/a +ETHTOOL_GRINGPARAM ETHTOOL_CMD_GET_PARAMS ETHTOOL_SRINGPARAM n/a -ETHTOOL_GPAUSEPARAM n/a +ETHTOOL_GPAUSEPARAM ETHTOOL_CMD_GET_PARAMS ETHTOOL_SPAUSEPARAM n/a ETHTOOL_GRXCSUM n/a ETHTOOL_SRXCSUM n/a
@@ -298,7 +384,7 @@ ETHTOOL_GRXFHINDIR n/a ETHTOOL_SRXFHINDIR n/a ETHTOOL_GFEATURES n/a ETHTOOL_SFEATURES n/a -ETHTOOL_GCHANNELS n/a +ETHTOOL_GCHANNELS ETHTOOL_CMD_GET_PARAMS ETHTOOL_SCHANNELS n/a ETHTOOL_SET_DUMP n/a ETHTOOL_GET_DUMP_FLAG n/a
@@ -306,7 +392,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 ETHTOOL_CMD_GET_PARAMS ETHTOOL_SEEE n/a ETHTOOL_GRSSH n/a ETHTOOL_SRSSH n/a
@@ -318,6 +404,6 @@ ETHTOOL_GLINKSETTINGS ETHTOOL_CMD_GET_SETTINGS ETHTOOL_SLINKSETTINGS ETHTOOL_CMD_SET_SETTINGS ETHTOOL_PHY_GTUNABLE n/a ETHTOOL_PHY_STUNABLE n/a -ETHTOOL_GFECPARAM n/a +ETHTOOL_GFECPARAM ETHTOOL_CMD_GET_PARAMS ETHTOOL_SFECPARAM n/a
include/uapi/linux/ethtool_netlink.h +118 -0
130 lines not on this page · raw message
net/core/ethtool_netlink.c +411 -0
423 lines not on this page · raw message
Signature · 1 line
2.15.1
RFC PATCH 9/9 ethtool: implement SET_PARAMS message
In reply to Michal KubecekSets 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/core/ethtool_netlink.c | 422 +++++++++++++++++++++++++++ 2 files changed, 486 insertions(+), 7 deletions(-)
Documentation/networking/ethtool-netlink.txt +64 -7
@@ -112,7 +112,7 @@ List of message types ETHTOOL_CMD_GET_SETTINGS ETHTOOL_CMD_SET_SETTINGS ETHTOOL_CMD_GET_PARAMS - ETHTOOL_CMD_SET_PARAMS response only (for now) + ETHTOOL_CMD_SET_PARAMS All constants use ETHTOOL_CMD_ prefix followed by "GET", "SET" or "ACT" to indicate the type.
@@ -316,6 +316,63 @@ the information is nested in it. - active (value) and configured (selector) FEC encodings +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 -------------------
@@ -339,11 +396,11 @@ ETHTOOL_GLINK ETHTOOL_CMD_GET_SETTINGS ETHTOOL_GEEPROM n/a ETHTOOL_SEEPROM n/a ETHTOOL_GCOALESCE ETHTOOL_CMD_GET_PARAMS -ETHTOOL_SCOALESCE n/a +ETHTOOL_SCOALESCE ETHTOOL_CMD_SET_PARAMS ETHTOOL_GRINGPARAM ETHTOOL_CMD_GET_PARAMS -ETHTOOL_SRINGPARAM n/a +ETHTOOL_SRINGPARAM ETHTOOL_CMD_SET_PARAMS ETHTOOL_GPAUSEPARAM ETHTOOL_CMD_GET_PARAMS -ETHTOOL_SPAUSEPARAM n/a +ETHTOOL_SPAUSEPARAM ETHTOOL_CMD_SET_PARAMS ETHTOOL_GRXCSUM n/a ETHTOOL_SRXCSUM n/a ETHTOOL_GTXCSUM n/a
@@ -385,7 +442,7 @@ ETHTOOL_SRXFHINDIR n/a ETHTOOL_GFEATURES n/a ETHTOOL_SFEATURES n/a ETHTOOL_GCHANNELS ETHTOOL_CMD_GET_PARAMS -ETHTOOL_SCHANNELS n/a +ETHTOOL_SCHANNELS ETHTOOL_CMD_SET_PARAMS ETHTOOL_SET_DUMP n/a ETHTOOL_GET_DUMP_FLAG n/a ETHTOOL_GET_DUMP_DATA n/a
@@ -393,7 +450,7 @@ ETHTOOL_GET_TS_INFO n/a ETHTOOL_GMODULEINFO n/a ETHTOOL_GMODULEEEPROM n/a ETHTOOL_GEEE ETHTOOL_CMD_GET_PARAMS -ETHTOOL_SEEE n/a +ETHTOOL_SEEE ETHTOOL_CMD_SET_PARAMS ETHTOOL_GRSSH n/a ETHTOOL_SRSSH n/a ETHTOOL_GTUNABLE n/a
@@ -405,5 +462,5 @@ ETHTOOL_SLINKSETTINGS ETHTOOL_CMD_SET_SETTINGS ETHTOOL_PHY_GTUNABLE n/a ETHTOOL_PHY_STUNABLE n/a ETHTOOL_GFECPARAM ETHTOOL_CMD_GET_PARAMS -ETHTOOL_SFECPARAM n/a +ETHTOOL_SFECPARAM ETHTOOL_CMD_SET_PARAMS
net/core/ethtool_netlink.c +422 -0
434 lines not on this page · raw message
Signature · 1 line
2.15.1
Re: [RFC PATCH 2/9] ethtool: introduce ethtool netlink interface
In reply to Michal KubecekQuoted 6 lines · Mon, Dec 11, 2017 at 02:53:31PM CET, [email protected] wrote:
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").
Signed-off-by Michal Kubecek <[email protected]>
[...]
include/uapi/linux/ethtool_netlink.h line 17
Quoted 11 lines
include/uapi/linux/ethtool_netlink.h new file +11
-0+ +/* identifies the device to query/set +* - use either ifindex or ifname, not both +* - for dumps and messages not related to a particular devices, fill neither +* - info_mask is a bitfield, interpretation depends on the command +*/ +struct ethnlmsghdr { +__u32 ifindex;/* device ifindex */ +__u16 flags;/* request/response flags */ +__u16 info_mask;/* request/response info mask */ +char ifname[IFNAMSIZ ];/* device name */
Why do you need this header? You can have 2 attrs:ETHTOOL_ATTR_IFINDEX and ETHTOOL_ATTR_IFNAME
Why do you need per-command flags and info_mask? Could be bitfield attr if needed by specific command.
Quoted 50 lines
include/uapi/linux/ethtool_netlink.h new file +16
-0+}; + +#define ETHNL_HDRLEN NLMSG_ALIGN(sizeof(struct ethnlmsghdr)) + +enum { +ETHTOOL_CMD_NOOP , + + __ETHTOOL_CMD_MAX, +ETHTOOL_CMD_MAX = (__ETHTOOL_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@@ -440,6 +440,13 @@ config MAY_USE_DEVLINK on MAY_USE_DEVLINK to ensure they do not cause link errors when devlink is a loadable module and the driver using it is built-in. +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/core/Makefile +0
-0@@ -30,3 +30,4 @@ obj-$(CONFIG_DST_CACHE) += dst_cache.oobj-$(CONFIG_HWBM) += hwbm.o
obj-$(CONFIG_NET_DEVLINK) += devlink.o
obj-$(CONFIG_GRO_CELLS) += gro_cells.onet/core/Makefile +1
-0+obj-$(CONFIG_ETHTOOL_NETLINK) += ethtool_netlink.onet/core/ethtool_netlink.c new file +1
-0@@ -0,0 +1,46 @@ +/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
net/core/ethtool_netlink.c line 11
Quoted 10 lines
net/core/ethtool_netlink.c new file +10
-0+ +#include <linux/module.h> +#include <linux/ethtool_netlink.h> +#include <linux/netdevice.h> +#include <net/genetlink.h> +#include "ethtool_common.h" + +static struct genl_family ethtool_genl_family; + +/* genetlink paperwork */
What "paperwork"? :)
Quoted 22 lines
net/core/ethtool_netlink.c new file +22
-0+ +static const struct genl_ops ethtool_genl_ops[] = { +}; + +static struct genl_family ethtool_genl_family = { + .hdrsize =ETHNL_HDRLEN , + .name =ETHTOOL_GENL_NAME , + .version =ETHTOOL_GENL_VERSION , + .netnsok = true, + .ops = ethtool_genl_ops, + .n_ops =ARRAY_SIZE (ethtool_genl_ops), +}; + +/* module paperwork */ + +static int __init ethtool_nl_init (void ) +{ +return genl_register_family (ðtool_genl_family); +} + +static void __exit ethtool_nl_exit(void) +{
net/core/ethtool_netlink.c line 43
Quoted 10 lines
net/core/ethtool_netlink.c new file +10
-0+genl_unregister_family (ðtool_genl_family); +} + +module_init (ethtool_nl_init); +module_exit (ethtool_nl_exit); + +/* this alias is for autoload */ +MODULE_ALIAS("net-pf-" __stringify(PF_NETLINK) + "-proto-" __stringify(NETLINK_GENERIC) + "-family-" ETHTOOL_GENL_NAME);
You can use MODULE_ALIAS_GENL_FAMILY instead.
net/core/ethtool_netlink.c line 46
Quoted 3 lines
net/core/ethtool_netlink.c new file +3
-0+MODULE_AUTHOR ("Michal Kubecek <[email protected]>" ); +MODULE_DESCRIPTION ("Netlink interface for ethtool" ); +MODULE_LICENSE ("GPL" );
"GPL v2"?
Quoted 3 lines
Signature · 1 line
2.15.1
Re: [RFC PATCH 5/9] ethtool: implement GET_DRVINFO message
In reply to Michal KubecekQuoted 36 lines · Mon, Dec 11, 2017 at 02:54:01PM CET, [email protected] wrote:
Request the same information as
ETHTOOL_GDRVINFO. This is read-only so that correspondingSET_DRVINFOexists but is only used in kernel replies. Rip the code to query the driver out of the legacy interface and move it to a new fileethtool_common.cso that both interfaces can use it.Signed-off-by Michal Kubecek <[email protected]>---
Documentation/networking/ethtool-netlink.txt | 30 ++++++++++- include/uapi/linux/ethtool_netlink.h | 21 ++++++++ net/core/Makefile | 2 +- net/core/ethtool.c | 42 +++------------- net/core/ethtool_common.c | 46 +++++++++++++++++ net/core/ethtool_common.h | 11 ++++ net/core/ethtool_netlink.c | 75 ++++++++++++++++++++++++++++ 7 files changed, 189 insertions(+), 38 deletions(-)create mode 100644
net/core/ethtool_common.c
create mode 100644net/core/ethtool_common.hDocumentation/networking/ethtool-netlink.txt +0
-0@@ -107,6 +107,9 @@ which the request applies.List of message types
---------------------Documentation/networking/ethtool-netlink.txt +3
-0+ ETHTOOL_CMD_GET_DRVINFO + ETHTOOL_CMD_SET_DRVINFO response only +All constants use
ETHTOOL_CMD_prefix followed by "GET", "SET" or "ACT" to indicate the type.Documentation/networking/ethtool-netlink.txt +0
-0@@ -119,6 +122,31 @@ messages marked as "response only" in the table above.Later sections describe the format and semantics of these request messages.
Documentation/networking/ethtool-netlink.txt messages marked as "response only" in the table above. · line 134
Quoted 10 lines
Documentation/networking/ethtool-netlink.txt +10
-0+GET_DRVINFO +----------- + +GET_DRVINFO request corresponds to ETHTOOL_GDRVINFO ioctl command and provides +basic driver information. The request doesn't use any attributes and flags, +info_mask and index field in request header are ignored. Kernel response +contents: + + ETHA_DRVINFO_DRIVER (string) driver name + ETHA_DRVINFO_VERSION (string) driver version
You use 3 prefixes:ETHTOOL_ for cmdETHA_ for attrsethnl_ for function
I suggest to sync this, perhaps to:
ETHNL_CMD_*
ETHNL_ATTR_*
ethnl_*
?
Documentation/networking/ethtool-netlink.txt messages marked as "response only" in the table above. · line 142
Quoted 8 lines
Documentation/networking/ethtool-netlink.txt +8
-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 + 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
We are now working on providing various fw memory regions dump in devlink. It makes sense to have it in devlink for couple of reasons:
1) per-asic, not netdev specific, therefore does not really make sense to have netdev as handle, but rather devlink handle.
2) snapshot support - we need to provide support for getting snapshot (for example on failure), transferring to user and deleting it (remove from driver memory).
Also, driver name, version, fwversion, etc is per-asic. Would make sense to have it in devlink as well.
I think this is great opprotunity to move things where they should be to be alligned with the current world and kernel infrastructure.
Quoted 18 lines · Mon, Dec 11, 2017 at 02:53:11PM CET, [email protected] wrote:
This is still work in progress and only a very small part of the ioctl interface is reimplemented but I would like to get some comments before the patchset becomes too big and changing things becomes too tedious.
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 or systemd-networkd).
Quoted 4 lines
The interface is documented in
Documentation/networking/ethtool-netlink.txtI'll post RFC patch series for ethtool in a few days, it still needs some more polishing.
First of all, thank you Michale for taking a stab at this!
I think that it does not make sense to convert ethtool->netlink_ethtool 1:1 feature wise. Now we have devlink, ritch switch representation model, tc offload and many others. Lot of things that are in ethtool, should be done in devlink. Also, there are couple of things that should just die - nice example is ethtool --config-ntuple - we should use tc for that.
So I believe that it would be better to introduce new iterface called differently, to avoid confusion, like "ethlink" and start to migrate things there, without existing baggage. In kernel the existing ethtool would just call compat layer inside ethlink code. Similarly with devlink. ethtool api would freeze. Similar scenario to rtnetlink and legacy ioctl.
Also, this new netlink iface should have userspace notification support from day 1.
David Miller
maintainerRe: [RFC PATCH 2/9] ethtool: introduce ethtool netlink interface
In reply to Jiri PirkoFrom: Jiri Pirko <[email protected]>
Date: Mon, 11 Dec 2017 17:02:21 +0100
Quoted 27 lines
Quoted 6 lines · Mon, Dec 11, 2017 at 02:53:31PM CET, [email protected] wrote:
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").
Signed-off-by Michal Kubecek <[email protected]>[...]
include/uapi/linux/ethtool_netlink.h line 17
Quoted 11 lines
include/uapi/linux/ethtool_netlink.h new file +11
-0+ +/* identifies the device to query/set +* - use either ifindex or ifname, not both +* - for dumps and messages not related to a particular devices, fill neither +* - info_mask is a bitfield, interpretation depends on the command +*/ +struct ethnlmsghdr { +__u32 ifindex;/* device ifindex */ +__u16 flags;/* request/response flags */ +__u16 info_mask;/* request/response info mask */ +char ifname[IFNAMSIZ ];/* device name */ Why do you need this header? You can have 2 attrs:
ETHTOOL_ATTR_IFINDEXandETHTOOL_ATTR_IFNAME
Quoted 2 lines
Why do you need per-command flags and
info_mask? Could be bitfield attr if needed by specific command.
Jiri, we've had this discussion before :-)
For elements which are common to most, if not all, requests it makes sense to define a base netlink message.
My opinion on this matter has not changed at all since the last time we discussed this.
So unless you have new information to provide to me on this issue which might change my mind, please accept the result of the previous discussion which is that a base netlink message is not only appropriate but desirable.
Thank you.
David Miller
maintainerFrom: Jiri Pirko <[email protected]>
Date: Mon, 11 Dec 2017 17:32:46 +0100
Quoted 6 lines
I think that it does not make sense to convert
ethtool->netlink_ethtool1:1 feature wise. Now we have devlink, ritch switch representation model, tc offload and many others. Lot of things that are in ethtool, should be done in devlink. Also, there are couple of things that should just die - nice example is ethtool --config-ntuple - we should use tc for that.
Whilst I do agree that devlink is probably a good place for this stuff (we want to be able to do ethetool things on objects that lack a netdev) I do not agree with the tc angle.
It is entirely appropriate to set the ntuple settings of a driver without being required to use TC or similar.
All you are going to do with your suggestion is make people keep using the existing ethtool ioctl, because they'll say "screw this, I'm not using TC I have something which works just fine already". And that's not the goal of putting this stuff into netlink, we want people to use the new facilities and move off of the ioctl.
Quoted 14 lines · Mon, Dec 11, 2017 at 06:01:44PM CET, [email protected] wrote:
From: Jiri Pirko <[email protected]>
Date: Mon, 11 Dec 2017 17:32:46 +0100Quoted 6 lines
I think that it does not make sense to convert
ethtool->netlink_ethtool1:1 feature wise. Now we have devlink, ritch switch representation model, tc offload and many others. Lot of things that are in ethtool, should be done in devlink. Also, there are couple of things that should just die - nice example is ethtool --config-ntuple - we should use tc for that.Whilst I do agree that devlink is probably a good place for this stuff (we want to be able to do ethetool things on objects that lack a netdev) I do not agree with the tc angle.
Quoted 8 lines
It is entirely appropriate to set the ntuple settings of a driver without being required to use TC or similar.
All you are going to do with your suggestion is make people keep using the existing ethtool ioctl, because they'll say "screw this, I'm not using TC I have something which works just fine already". And that's not the goal of putting this stuff into netlink, we want people to use the new facilities and move off of the ioctl.
Sure, but this is a great opportunity to avoid copying old mistakes. That is why I suggested to do it not 1:1 but rather introduce brand new netlink-based interface that would not carry old baggage.
Re: [RFC PATCH 2/9] ethtool: introduce ethtool netlink interface
In reply to David MillerQuoted 33 lines · Mon, Dec 11, 2017 at 05:56:51PM CET, [email protected] wrote:
From: Jiri Pirko <[email protected]>
Date: Mon, 11 Dec 2017 17:02:21 +0100Quoted 27 lines
Quoted 6 lines · Mon, Dec 11, 2017 at 02:53:31PM CET, [email protected] wrote:
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").
Signed-off-by Michal Kubecek <[email protected]>[...]
include/uapi/linux/ethtool_netlink.h line 17
Quoted 11 lines
include/uapi/linux/ethtool_netlink.h new file +11
-0+ +/* identifies the device to query/set +* - use either ifindex or ifname, not both +* - for dumps and messages not related to a particular devices, fill neither +* - info_mask is a bitfield, interpretation depends on the command +*/ +struct ethnlmsghdr { +__u32 ifindex;/* device ifindex */ +__u16 flags;/* request/response flags */ +__u16 info_mask;/* request/response info mask */ +char ifname[IFNAMSIZ ];/* device name */ Why do you need this header? You can have 2 attrs:
ETHTOOL_ATTR_IFINDEXandETHTOOL_ATTR_IFNAMEQuoted 2 lines
Why do you need per-command flags and
info_mask? Could be bitfield attr if needed by specific command.
Quoted 7 lines
Jiri, we've had this discussion before :-)
For elements which are common to most, if not all, requests it makes sense to define a base netlink message.
My opinion on this matter has not changed at all since the last time we discussed this.
The discussion we had before was about flag bitfield that was there *always*. In this case, that is not true. It is either ifindex or ifname. Even rtnetlink has ifname as attribute.
The flags and info_mask is just big mystery. If it is per-command, seems natural to have it as attributes.
Quoted 7 lines
So unless you have new information to provide to me on this issue which might change my mind, please accept the result of the previous discussion which is that a base netlink message is not only appropriate but desirable.
Thank you.
David Miller
maintainerRe: [RFC PATCH 2/9] ethtool: introduce ethtool netlink interface
From: Jiri Pirko <[email protected]>
Date: Mon, 11 Dec 2017 19:02:19 +0100
Quoted 6 lines
The discussion we had before was about flag bitfield that was there *always*. In this case, that is not true. It is either ifindex or ifname. Even rtnetlink has ifname as attribute.
The flags and
info_maskis just big mystery. If it is per-command, seems natural to have it as attributes.
I think flags and info_mask indeed can be moved out of this struct.
I guess, in this case, I can see your point of view especially if we allow ethtool operations on non-netdev entities.
So, ok, let's move forward without a base command struct and just use attributes.
Thanks :)
Quoted 14 lines · David Miller
From: Jiri Pirko <[email protected]>
Date: Mon, 11 Dec 2017 17:32:46 +0100Quoted 6 lines
I think that it does not make sense to convert
ethtool->netlink_ethtool1:1 feature wise. Now we have devlink, ritch switch representation model, tc offload and many others. Lot of things that are in ethtool, should be done in devlink. Also, there are couple of things that should just die - nice example is ethtool --config-ntuple - we should use tc for that.Whilst I do agree that devlink is probably a good place for this stuff (we want to be able to do ethetool things on objects that lack a netdev) I do not agree with the tc angle.
Quoted 8 lines
It is entirely appropriate to set the ntuple settings of a driver without being required to use TC or similar.
All you are going to do with your suggestion is make people keep using the existing ethtool ioctl, because they'll say "screw this, I'm not using TC I have something which works just fine already". And that's not the goal of putting this stuff into netlink, we want people to use the new facilities and move off of the ioctl.
I agree, we can't walk away from that feature today, there are many more drivers implementing ethtool::ntuple (counting 22) than there are implementing cls_flower (counting 6), also they are not strictly equivalent feature wise, one thing critically missing in cls_flower (last I looked) is the ability to either auto-place (RX_CLS_LOC_ANY) a matching rule, or select a particular location. For specifying what to match in a packet and how, cls_flower is superior.
We can probably advise people not to use that feature and request their driver provider to switch over to cls_flower, but considering how many more LOCs are needed in the driver to implement that (as opposed to ethtool ntuple), I just don't see it being something people will be thrilled to do.
Writing a shim that converts from ethtool ntuple to the equivalent in kernel space representation of the same call through cls_flower would be reasonably easy, but same thing, that still requires migrating your kernel driver over to the cls_flower interface, which is the harder part.
That being said, we should probably discourage implementing both for new drivers, since they are likely to use the same centralized HW resources towards the same goals: match + actions, with no visibility into one another (can't see rules set-up in ethtool via cls_flower and vice versa) and that just sucks.
Signature · 1 line
Florian
Quoted 60 lines · Michal Kubecek
This is still work in progress and only a very small part of the ioctl interface is reimplemented but I would like to get some comments before the patchset becomes too big and changing things becomes too tedious.
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 or systemd-networkd).
The interface is documented in
Documentation/networking/ethtool-netlink.txtI'll post RFC patch series for ethtool in a few days, it still needs some more polishing.
Basic concepts:
- the interface is based on generic netlink (family name "ethtool")
- provide everything ioctl can do 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, userspace can simply say what it wants to change and how
- be less dependent on ethtool and kernel being in sync; allow e.g. saying "ethtool -s eth0 advertise xyz off" without knowing what "xyz" means; it's kernel's job to know what mode "xyz" is and if it exists and is supported
Unresolved questions/tasks:
- allow dumps for "get" type requests, e.g. listing EEE settings for all interfaces in current netns
- find reasonable format for data transfers (e.g. eeprom dump or flash)
- while the netlink interface allows easy future extensions,
ethtool_opsinterface 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
Quoted 11 lines
Michal Kubecek (9):
netlink: introducenla_put_bitfield32()
ethtool: introduce ethtool netlink interface
ethtool: helper functions for netlink interface
ethtool: netlink bitset handling
ethtool: implementGET_DRVINFOmessage
ethtool: implementGET_SETTINGSmessage
ethtool: implementSET_SETTINGSmessage
ethtool: implementGET_PARAMSmessage
ethtool: implementSET_PARAMSmessage
Thanks for working on this!. Agree with most comments already discussed on this thread.
I would prefer if we fold ethtool netlink into devlink since there is already an overlap.
many reasons:
- have just one driver api for device global and per port config (devlink already provides that)
- some of the devlink commands like port split/unsplit can already be applied per netdev (and since you bring up network interface managers, we are looking at getting these in network managers for switch ports)
- if we keep them separate, we will soon see that drivers will need handlers for both devlink and ethtool
- and the overlap is going to be confusing for both drivers and
user-space
Quoted 5 lines · Roopa Prabhu
Thanks for working on this!. Agree with most comments already discussed on this thread.
I would prefer if we fold ethtool netlink into devlink since there is already an overlap.
many reasons:
Quoted 8 lines
- have just one driver api for device global and per port config (devlink already provides that)
- some of the devlink commands like port split/unsplit can already be applied per netdev (and since you bring up network interface managers, we are looking at getting these in network managers for switch ports)
- if we keep them separate, we will soon see that drivers will need handlers for both devlink and ethtool
- and the overlap is going to be confusing for both drivers and user-space
+1
FWIW my gut feeling is that extending devlink-port makes more sense than creating another command. Although things like RSS tables don't feel very natural in port context.
The other issue that springs to mind is that ethtool ops take RTNL lock today, and devlink doesn't. It would be cool if we could make ethtool not require RTNL lock (and drivers didn't have to drop locks half way through the .flash_device callback, sigh...) but OTOH that would make the driver conversion more brittle and potentially block the much needed netlink conversion...
That's my $0.02 ;)
Re: [RFC PATCH 5/9] ethtool: implement GET_DRVINFO message
In reply to Jiri PirkoQuoted 10 lines · Jiri Pirko
Documentation/networking/ethtool-netlink.txt messages marked as "response only" in the table above. · line 134
Quoted 3 lines · Mon, Dec 11, 2017 at 02:54:01PM CET, [email protected] wrote:
Documentation/networking/ethtool-netlink.txt +3
-0+ + ETHA_DRVINFO_DRIVER (string) driver name + ETHA_DRVINFO_VERSION (string) driver versionYou use 3 prefixes:
ETHTOOL_for cmdETHA_for attrsethnl_for function
Quoted 5 lines
I suggest to sync this, perhaps to:
ETHNL_CMD_*
ETHNL_ATTR_*
ethnl_*
?
Switching to ETHNL_CMD_* is certainly a good idea. For attributes, I'm a bit worried that ETHNL_ATTR_ prefix might make it even harder to fit into the 80 characters per line limit. I'll try and see what it would look like.
Quoted 17 lines
Documentation/networking/ethtool-netlink.txt messages marked as "response only" in the table above. · line 142
Quoted 8 lines
Documentation/networking/ethtool-netlink.txt +8
-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 + ETHA_DRVINFO_TESTINFO_LEN (u32) number of test results + ETHA_DRVINFO_EEDUMP_LEN (u32) EEPROM dump size + ETHA_DRVINFO_REGDUMP_LEN (u32) register dump sizeWe are now working on providing various fw memory regions dump in devlink. It makes sense to have it in devlink for couple of reasons:
1) per-asic, not netdev specific, therefore does not really make sense to have netdev as handle, but rather devlink handle.
2) snapshot support - we need to provide support for getting snapshot (for example on failure), transferring to user and deleting it (remove from driver memory).
Quoted 5 lines
Also, driver name, version, fwversion, etc is per-asic. Would make sense to have it in devlink as well.
I think this is great opprotunity to move things where they should be to be alligned with the current world and kernel infrastructure.
IMHO this depends on the question whether we are going to rework also the interface between kernel and NIC drivers (currently ethtool_ops). If we are, it would make good sense to split the information in both interfaces. If not, it doesn't seem to make userspace do two queries, each getting one part of the same information provided by NIC.
Also, I must admit that one thing I dislike about the iw tool is that it pushes me to distinguish between operations on "phy" and "dev". While I understand that it makes perfect sense for someone familiar with the internals, it's quite annoying for an occasional "consumer". It would be sad if we created a set of perfectly logical and clean tools and (almost) 20 years later, people still used old ioctl based ethtool because "it's what they are used to and it works just fine for them" (like they do with ifconfig, netstat or brctl).
Michal
Re: [RFC PATCH 2/9] ethtool: introduce ethtool netlink interface
In reply to David MillerQuoted 10 lines · David Miller
From: Jiri Pirko <[email protected]>
Date: Mon, 11 Dec 2017 19:02:19 +0100Quoted 6 lines
The discussion we had before was about flag bitfield that was there *always*. In this case, that is not true. It is either ifindex or ifname. Even rtnetlink has ifname as attribute.
The flags and
info_maskis just big mystery. If it is per-command, seems natural to have it as attributes.
Quoted 7 lines
I think flags and
info_maskindeed can be moved out of this struct.I guess, in this case, I can see your point of view especially if we allow ethtool operations on non-netdev entities.
So, ok, let's move forward without a base command struct and just use attributes.
OK, I'll rework the interface to use attributes for all data.
Michal Kubecek
Re: [RFC PATCH 5/9] ethtool: implement GET_DRVINFO message
In reply to Michal KubecekQuoted 42 lines · Wed, Dec 13, 2017 at 12:54:39AM CET, [email protected] wrote:
Quoted 10 lines · Jiri Pirko
Documentation/networking/ethtool-netlink.txt messages marked as "response only" in the table above. · line 134
Quoted 3 lines · Mon, Dec 11, 2017 at 02:54:01PM CET, [email protected] wrote:
Documentation/networking/ethtool-netlink.txt +3
-0+ + ETHA_DRVINFO_DRIVER (string) driver name + ETHA_DRVINFO_VERSION (string) driver versionYou use 3 prefixes:
ETHTOOL_for cmdETHA_for attrsethnl_for functionQuoted 5 lines
I suggest to sync this, perhaps to:
ETHNL_CMD_*
ETHNL_ATTR_*
ethnl_*
?Switching to ETHNL_CMD_* is certainly a good idea. For attributes, I'm a bit worried that
ETHNL_ATTR_prefix might make it even harder to fit into the 80 characters per line limit. I'll try and see what it would look like.Quoted 20 lines
Documentation/networking/ethtool-netlink.txt messages marked as "response only" in the table above. · line 142
Quoted 8 lines
Documentation/networking/ethtool-netlink.txt +8
-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 + ETHA_DRVINFO_TESTINFO_LEN (u32) number of test results + ETHA_DRVINFO_EEDUMP_LEN (u32) EEPROM dump size + ETHA_DRVINFO_REGDUMP_LEN (u32) register dump sizeWe are now working on providing various fw memory regions dump in devlink. It makes sense to have it in devlink for couple of reasons:
1) per-asic, not netdev specific, therefore does not really make sense to have netdev as handle, but rather devlink handle.
2) snapshot support - we need to provide support for getting snapshot (for example on failure), transferring to user and deleting it (remove from driver memory).Also, driver name, version, fwversion, etc is per-asic. Would make sense to have it in devlink as well.
Quoted 8 lines
Quoted 2 lines
I think this is great opprotunity to move things where they should be to be alligned with the current world and kernel infrastructure.
IMHO this depends on the question whether we are going to rework also the interface between kernel and NIC drivers (currently
ethtool_ops). If we are, it would make good sense to split the information in both interfaces. If not, it doesn't seem to make userspace do two queries, each getting one part of the same information provided by NIC.
Yeah, agreed. I believe we should.
Quoted 9 lines
Also, I must admit that one thing I dislike about the iw tool is that it pushes me to distinguish between operations on "phy" and "dev". While I understand that it makes perfect sense for someone familiar with the internals, it's quite annoying for an occasional "consumer". It would be sad if we created a set of perfectly logical and clean tools and (almost) 20 years later, people still used old ioctl based ethtool because "it's what they are used to and it works just fine for them" (like they do with ifconfig, netstat or brctl).
Good documentation should take care of that.
Quoted 2 lines
Michal
Michal,
Thanks for looking at this issue.
While the kernel and userland bits here are at least somewhat decoupled, as the current maintainer for the userland ethtool I feel compelled to comment. FWIW I had started down a similar road, but I became dissatisfied with my own results. The main problem was that the only obvious API-conversion technique essentially amounted to re-implementing the ioctl-based API, but on top of the netlink transport. Having been burned by something similar in the pre-nl80211 days with wireless extensions, I really didn't want to repeat that.
Even without considering the ioctl problesms, the current ethtool API seems a bit crufty. It has been a catch-all, "where else would it go?" dumping ground for a long time, and it has accrued a number of not-entirely-related bits of functionality. In my mind, what needs to happen is that these various bits of functionality need to be reorganized into a handful of groupings. Then, each group needs an API designed around semantics that are natural to the functionality being addressed. I believe this is essentially the idea that others have expressed with the "move some of the ethtool bits to devlink" comments. I think that probably makes sense, although trying to shove everything into devlink probably makes no more sense than keeping the entire ethtool API intact on top of a netlink transport. Anyway, I think that with a reasonable set of groupings, the semantics would fall-out naturally and implementing them on netlink or any other suitable transport would be reasonably trivial.
Unfortunately, I have yet to formultate a useful set of abstractions for grouping the various bits of the ethtool API. I have reached-out to a few community folks seeking their wisdom, but since no one has been forthcoming with such a set of abstractions, I'll presume that either I failed to convey my message, my idea isn't too good, or none of them are any smarter than me -- I'll avoid identifying any of them here in order to save us all some embarassment! :-)
In short, what I would like to see is a true rethink of what APIs need to be provided to NICs, outside of the basic netdev abstraction. I wish I had the answer to what those APIs should be, but I don't. I do believe that with a well-conceived group of APIs, the proper semantics will fall-out naturally. Any takers? :-)
Michal, once again -- thanks for attempting to address this issue. Please do not take any of the above as discouragement. It is clear that ethtool needs replacement, and we all know that 'perfect' is the enemy of 'good'. I just would hate to miss the opportunity for a 'better' API just because ethtool's ioctly API has lived too long.
John
Quoted 95 lines · Michal Kubecek
This is still work in progress and only a very small part of the ioctl interface is reimplemented but I would like to get some comments before the patchset becomes too big and changing things becomes too tedious.
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 or systemd-networkd).
The interface is documented in
Documentation/networking/ethtool-netlink.txtI'll post RFC patch series for ethtool in a few days, it still needs some more polishing.
Basic concepts:
- the interface is based on generic netlink (family name "ethtool")
- provide everything ioctl can do 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, userspace can simply say what it wants to change and how
- be less dependent on ethtool and kernel being in sync; allow e.g. saying "ethtool -s eth0 advertise xyz off" without knowing what "xyz" means; it's kernel's job to know what mode "xyz" is and if it exists and is supported
Unresolved questions/tasks:
- allow dumps for "get" type requests, e.g. listing EEE settings for all interfaces in current netns
- find reasonable format for data transfers (e.g. eeprom dump or flash)
- while the netlink interface allows easy future extensions,
ethtool_opsinterface 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
Michal Kubecek (9):
netlink: introducenla_put_bitfield32()
ethtool: introduce ethtool netlink interface
ethtool: helper functions for netlink interface
ethtool: netlink bitset handling
ethtool: implementGET_DRVINFOmessage
ethtool: implementGET_SETTINGSmessage
ethtool: implementSET_SETTINGSmessage
ethtool: implementGET_PARAMSmessage
ethtool: implementSET_PARAMSmessageDocumentation/networking/ethtool-netlink.txt | 466 ++++++ include/linux/ethtool_netlink.h | 12 + include/linux/netdevice.h | 2 + include/net/netlink.h | 15 + include/uapi/linux/ethtool.h | 3 + include/uapi/linux/ethtool_netlink.h | 239 +++ net/Kconfig | 7 + net/core/Makefile | 3 +- net/core/ethtool.c | 150 +- net/core/ethtool_common.c | 158 ++ net/core/ethtool_common.h | 19 + net/core/ethtool_netlink.c | 2323 ++++++++++++++++++++++++++ 12 files changed, 3260 insertions(+), 137 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/core/ethtool_common.c create mode 100644 net/core/ethtool_common.h create mode 100644 net/core/ethtool_netlink.cSignature · 1 line
2.15.1
Signature · 2 lines
John W. Linville Someday the world will need a hero, and you [email protected] might be all we have. Be ready.
David Miller
maintainerFrom: "John W. Linville" <[email protected]>
Date: Thu, 14 Dec 2017 16:07:56 -0500
Quoted 7 lines
Even without considering the ioctl problesms, the current ethtool API seems a bit crufty. It has been a catch-all, "where else would it go?" dumping ground for a long time, and it has accrued a number of not-entirely-related bits of functionality. In my mind, what needs to happen is that these various bits of functionality need to be reorganized into a handful of groupings. Then, each group needs an API designed around semantics that are natural to the functionality
Quoted 8 lines
being addressed. I believe this is essentially the idea that others have expressed with the "move some of the ethtool bits to devlink" comments. I think that probably makes sense, although trying to shove everything into devlink probably makes no more sense than keeping the entire ethtool API intact on top of a netlink transport. Anyway, I think that with a reasonable set of groupings, the semantics would fall-out naturally and implementing them on netlink or any other suitable transport would be reasonably trivial.
Thanks for your valueable feedback John.
Let's keep in mind that really the core impetus to move ethtool stuff to netlink is visibility.
Someone trying to monitor network config events in the system can't see anything that happens with ethtool currently. It's completely invisible.
Even ancient ifconfig ioctls generate proper netlink events.
Ethtool is one of the few, if not the only, network config mechanism that elides netlink event visibility.
And I think fixing that core issue is what is driving the focus onto a pure 1-to-1 conversion, be it to a separate netlink/genetlink family or to devlink.