net: Unified offload configuration
Subsystems (3)
v4 cover net: Unified offload configuration
Here's a v4 of the ethtool unification patch series.
What's in it?
1:
the patch - implement unified ethtool setting ops
2..3:
implement interoperation between old and new ethtool ops
4:
include RX checksum in features and plug it into new framework
5:
convert loopback device to new framework
What is it good for?
- unifies driver behaviour wrt hardware offloads
- removes a lot of boilerplate code from drivers
- allows better fine-grained control over used offloads
I'm testing this on ARM Gemini arch now. Patch to ethtool userspace tool will follow this series. I'm not fond of the GFEATURES output I implemented - please throw some suggestions on it if you can.
Driver conversions stay the same as in v2 - as for v3, I'll keep them from resending until after the core code gets accepted.
Patches 2,4,5 are unchanged from v3.
Best Regards,
Michał Mirosław
v1: http://marc.info/?l=linux-netdev&m=129245188832643&w=3
Changes from v3:
- fixed kernel-doc and other comments
- added HIGHDMA to never-changeable features
- changed GFEATURES .size interpretation
- changed feature strings
- change __ethtool_set_flags() to reject invalid changes
Changes from v2:
- rebase to net-next after merging v2 leading patches
- fix missing comma in feature name table
- force NETIF_F_SOFT_FEATURES in hw_features for simpler code (fixes a bug that disallowed changing GSO and GRO state)
Changes from v1:
- split structures for GFEATURES/SFEATURES
- naming of feature bits using GSTRINGS ETH_SS_FEATURES
- strict checking of bits used in SFEATURES call
- more comments and kernel-doc
- rebased to net-next after 2.6.37
---
Michał Mirosław (5):
net: Introduce new feature setting ops
net: ethtool: use ndo_fix_features for offload setting
net: use ndo_fix_features for ethtool_ops->set_flags
net: introduce NETIF_F_RXCSUM
loopback: convert to hw_features
drivers/net/loopback.c | 9 +- include/linux/ethtool.h | 86 ++++++++- include/linux/netdevice.h | 48 +++++- net/core/dev.c | 49 ++++- net/core/ethtool.c | 481 ++++++++++++++++++++++++++++----------------- 5 files changed, 480 insertions(+), 193 deletions(-)
Signature · 1 line
1.7.2.3
PATCH v4 3/5 net: use ndo_fix_features for ethtool_ops->set_flags
--- net/core/ethtool.c | 31 +++++++++++++++++++++++++++++-- 1 files changed, 29 insertions(+), 2 deletions(-)
net/core/ethtool.c +29 -2
@@ -240,6 +240,34 @@ static int ethtool_set_features(struct net_device *dev, void __user *useraddr)return ret; } +static int __ethtool_set_flags (struct net_device *dev,u32 data) +{ +u32 changed; + +if (data & ~flags_dup_features) +return -EINVAL ; + +/* legacy set_flags() op */ +if (dev->ethtool_ops->set_flags) { +if (unlikely (dev->hw_features & flags_dup_features)) +netdev_warn (dev, +"driver BUG: mixed hw_features and set_flags()\n" ); +return dev->ethtool_ops->set_flags (dev, data); + } + +/* allow changing only bits set in hw_features */ + changed = (data ^ dev->wanted_features) & flags_dup_features; +if (changed & ~dev->hw_features) +return -EOPNOTSUPP ; + + dev->wanted_features = + (dev->wanted_features & ~changed) | data; + +netdev_update_features (dev); + +return 0 ; +} +static u32 ethtool_get_feature_mask (u32 eth_cmd) {/* feature masks of legacy discrete ethtool ops */
@@ -1733,8 +1761,7 @@ int dev_ethtool(struct net *net, struct ifreq *ifr) ethtool_op_get_flags));break ;case ETHTOOL_SFLAGS : - rc =ethtool_set_value (dev, useraddr, - dev->ethtool_ops->set_flags); + rc =ethtool_set_value (dev, useraddr, __ethtool_set_flags);break ;case ETHTOOL_GPFLAGS : rc = ethtool_get_value(dev, useraddr, ethcmd,
Signature · 1 line
1.7.2.3
PATCH v4 4/5 net: introduce NETIF_F_RXCSUM
In reply to Michał MirosławIntroduce NETIF_F_RXCSUM to replace device-private flags for RX checksum offload. Integrate it with ndo_fix_features.
ethtool_op_get_rx_csum() is removed altogether as nothing in-tree uses it.
--- include/linux/ethtool.h | 1 - include/linux/netdevice.h | 5 ++++- net/core/ethtool.c | 36 ++++++++++++------------------------ 3 files changed, 16 insertions(+), 26 deletions(-)
include/linux/ethtool.h +0 -1
@@ -625,7 +625,6 @@ struct net_device;/* Some generic methods drivers may use in their ethtool_ops */ u32 ethtool_op_get_link (struct net_device *dev); -u32 ethtool_op_get_rx_csum (struct net_device *dev);u32 ethtool_op_get_tx_csum (struct net_device *dev);int ethtool_op_set_tx_csum (struct net_device *dev,u32 data);int ethtool_op_set_tx_hw_csum (struct net_device *dev,u32 data);
include/linux/netdevice.h +4 -1
@@ -964,6 +964,7 @@ struct net_device {#define NETIF_F_FCOE_MTU (1 << 26)/* Supports max FCoE MTU, 2158 bytes*/ #define NETIF_F_NTUPLE (1 << 27)/* N-tuple filters supported */ #define NETIF_F_RXHASH (1 << 28)/* Receive hashing offload */ +#define NETIF_F_RXCSUM (1 << 29)/* Receive checksumming offload */ /* Segmentation offload features */ #define NETIF_F_GSO_SHIFT 16
@@ -979,7 +980,7 @@ struct net_device {/* = all defined minus driver/device-class-related */ #define NETIF_F_NEVER_CHANGE (NETIF_F_HIGHDMA | NETIF_F_VLAN_CHALLENGED | \ NETIF_F_LLTX | NETIF_F_NETNS_LOCAL) -#define NETIF_F_ETHTOOL_BITS (0x1f3fffff & ~NETIF_F_NEVER_CHANGE) +#define NETIF_F_ETHTOOL_BITS (0x3f3fffff & ~NETIF_F_NEVER_CHANGE)/* List of features with software fallbacks. */ #define NETIF_F_GSO_SOFTWARE (NETIF_F_TSO | NETIF_F_TSO_ECN | \
@@ -2501,6 +2502,8 @@ static inline int dev_ethtool_get_settings(struct net_device *dev,static inline u32 dev_ethtool_get_rx_csum (struct net_device *dev) { +if (dev->hw_features &NETIF_F_RXCSUM ) +return !!(dev->features &NETIF_F_RXCSUM );if (!dev->ethtool_ops || !dev->ethtool_ops->get_rx_csum)return 0 ;return dev->ethtool_ops->get_rx_csum (dev);
net/core/ethtool.c +12 -24
@@ -34,12 +34,6 @@ u32 ethtool_op_get_link(struct net_device *dev) }EXPORT_SYMBOL (ethtool_op_get_link); -u32 ethtool_op_get_rx_csum (struct net_device *dev) -{ -return (dev->features &NETIF_F_ALL_CSUM ) !=0 ; -} -EXPORT_SYMBOL (ethtool_op_get_rx_csum); -u32 ethtool_op_get_tx_csum (struct net_device *dev) {return (dev->features &NETIF_F_ALL_CSUM ) !=0 ;
@@ -276,6 +270,9 @@ static u32 ethtool_get_feature_mask(u32 eth_cmd)case ETHTOOL_GTXCSUM :case ETHTOOL_STXCSUM :return NETIF_F_ALL_CSUM |NETIF_F_SCTP_CSUM ; +case ETHTOOL_GRXCSUM : +case ETHTOOL_SRXCSUM : +return NETIF_F_RXCSUM ;case ETHTOOL_GSG :case ETHTOOL_SSG :return NETIF_F_SG ;
@@ -310,6 +307,7 @@ static int ethtool_get_one_feature(struct net_device *dev, char __user *useraddr }static int __ethtool_set_tx_csum (struct net_device *dev,u32 data); +static int __ethtool_set_rx_csum (struct net_device *dev,u32 data);static int __ethtool_set_sg (struct net_device *dev,u32 data);static int __ethtool_set_tso (struct net_device *dev,u32 data);static int __ethtool_set_ufo (struct net_device *dev,u32 data);
@@ -347,6 +345,8 @@ static int ethtool_set_one_feature(struct net_device *dev,switch (ethcmd) {case ETHTOOL_STXCSUM :return __ethtool_set_tx_csum (dev, edata.data); +case ETHTOOL_SRXCSUM : +return __ethtool_set_rx_csum (dev, edata.data);case ETHTOOL_SSG :return __ethtool_set_sg (dev, edata.data);case ETHTOOL_STSO :
@@ -391,7 +391,7 @@ static const char netdev_features_strings[ETHTOOL_DEV_FEATURE_WORDS * 32][ETH_GS/* NETIF_F_FCOE_MTU */ "fcoe-mtu" ,/* NETIF_F_NTUPLE */ "rx-ntuple-filter" ,/* NETIF_F_RXHASH */ "rx-hashing" , -"" , +/* NETIF_F_RXCSUM */ "rx-checksum" ,"" , "", };
@@ -1369,20 +1369,15 @@ static int __ethtool_set_tx_csum(struct net_device *dev, u32 data)return dev->ethtool_ops->set_tx_csum (dev, data); } -static int ethtool_set_rx_csum (struct net_device *dev,char __user *useraddr) +static int __ethtool_set_rx_csum (struct net_device *dev,u32 data) { -struct ethtool_value edata; -if (!dev->ethtool_ops->set_rx_csum)return -EOPNOTSUPP ; -if (copy_from_user (&edata, useraddr,sizeof (edata))) -return -EFAULT ; - -if (!edata.data && dev->ethtool_ops->set_sg) +if (!data) dev->features &= ~NETIF_F_GRO ; -return dev->ethtool_ops->set_rx_csum (dev, edata.data); +return dev->ethtool_ops->set_rx_csum (dev, data); }static int __ethtool_set_tso (struct net_device *dev,u32 data)
@@ -1730,15 +1725,6 @@ int dev_ethtool(struct net *net, struct ifreq *ifr)case ETHTOOL_SPAUSEPARAM : rc =ethtool_set_pauseparam (dev, useraddr);break ; -case ETHTOOL_GRXCSUM : - rc =ethtool_get_value (dev, useraddr, ethcmd, - (dev->ethtool_ops->get_rx_csum ? - dev->ethtool_ops->get_rx_csum : - ethtool_op_get_rx_csum)); -break ; -case ETHTOOL_SRXCSUM : - rc =ethtool_set_rx_csum (dev, useraddr); -break ;case ETHTOOL_TEST : rc =ethtool_self_test (dev, useraddr);break ;
@@ -1811,6 +1797,7 @@ int dev_ethtool(struct net *net, struct ifreq *ifr) rc =ethtool_set_features (dev, useraddr);break ;case ETHTOOL_GTXCSUM : +case ETHTOOL_GRXCSUM :case ETHTOOL_GSG :case ETHTOOL_GTSO :case ETHTOOL_GUFO :
@@ -1819,6 +1806,7 @@ int dev_ethtool(struct net *net, struct ifreq *ifr) rc =ethtool_get_one_feature (dev, useraddr, ethcmd);break ;case ETHTOOL_STXCSUM : +case ETHTOOL_SRXCSUM :case ETHTOOL_SSG :case ETHTOOL_STSO :case ETHTOOL_SUFO :
Signature · 1 line
1.7.2.3
PATCH v4 1/5 net: Introduce new feature setting ops
In reply to Michał MirosławThis introduces a new framework to handle device features setting. It consists of:
- new fields in struct net_device:
+ hw_features - features that hw/driver supports toggling
+ wanted_features - features that user wants enabled, when possible
- new netdev_ops:
+ feat = ndo_fix_features(dev, feat) - API checking constraints for enabling features or their combinations
+ ndo_set_features(dev) - API updating hardware state to match changed dev->features
- new ethtool commands:
+ ETHTOOL_GFEATURES/ETHTOOL_SFEATURES: get/set dev->wanted_features and trigger device reconfiguration if resulting dev->features changed
+ ETHTOOL_GSTRINGS(ETH_SS_FEATURES): get feature bits names (meaning)
--- include/linux/ethtool.h | 85 +++++++++++++++++++++++++ include/linux/netdevice.h | 45 +++++++++++++- net/core/dev.c | 49 +++++++++++++-- net/core/ethtool.c | 154 +++++++++++++++++++++++++++++++++++++++++---- 4 files changed, 314 insertions(+), 19 deletions(-)
include/linux/ethtool.h +85 -0
@@ -251,6 +251,7 @@ enum ethtool_stringset {ETH_SS_STATS ,ETH_SS_PRIV_FLAGS ,ETH_SS_NTUPLE_FILTERS , + ETH_SS_FEATURES, };/* for passing string sets for data tagging */
@@ -523,6 +524,87 @@ struct ethtool_flash {char data[ETHTOOL_FLASH_MAX_FILENAME ]; }; +/* for returning and changing feature sets */ + +/** +* struct ethtool_get_features_block - block with state of 32 features +* @available: mask of changeable features +* @requested: mask of features requested to be enabled if possible +* @active: mask of currently enabled features +* @never_changed: mask of features not changeable for any device +*/ +struct ethtool_get_features_block { +__u32 available; +__u32 requested; +__u32 active; +__u32 never_changed; +}; + +/** +* struct ethtool_gfeatures - command to get state of device's features +* @cmd: command number = %ETHTOOL_GFEATURES +* @size: in: number of elements in the features[] array; +* out: number of elements in features[] needed to hold all features +* @features: state of features +*/ +struct ethtool_gfeatures { +__u32 cmd; +__u32 size; +struct ethtool_get_features_block features[0 ]; +}; + +/** +* struct ethtool_set_features_block - block with request for 32 features +* @valid: mask of features to be changed +* @requested: values of features to be changed +*/ +struct ethtool_set_features_block { +__u32 valid; +__u32 requested; +}; + +/** +* struct ethtool_sfeatures - command to request change in device's features +* @cmd: command number = %ETHTOOL_SFEATURES +* @size: array size of the features[] array +* @features: feature change masks +*/ +struct ethtool_sfeatures { +__u32 cmd; +__u32 size; +struct ethtool_set_features_block features[0 ]; +}; + +/* +* %ETHTOOL_SFEATURES changes features present in features[].valid to the +* values of corresponding bits in features[].requested. Bits in .requested +* not set in .valid or not changeable are ignored. +* +* Returns %EINVAL when .valid contains undefined or never-changable bits +* or size is not equal to required number of features words (32-bit blocks). +* Returns >= 0 if request was completed; bits set in the value mean: +* %ETHTOOL_F_UNSUPPORTED - there were bits set in .valid that are not +* changeable (not present in %ETHTOOL_GFEATURES' features[].available) +* those bits were ignored. +* %ETHTOOL_F_WISH - some or all changes requested were recorded but the +* resulting state of bits masked by .valid is not equal to .requested. +* Probably there are other device-specific constraints on some features +* in the set. When %ETHTOOL_F_UNSUPPORTED is set, .valid is considered +* here as though ignored bits were cleared. +* +* Meaning of bits in the masks are obtained by %ETHTOOL_GSSET_INFO (number of +* bits in the arrays - always multiple of 32) and %ETHTOOL_GSTRINGS commands +* for ETH_SS_FEATURES string set. First entry in the table corresponds to least +* significant bit in features[0] fields. Empty strings mark undefined features. +*/ +enum ethtool_sfeatures_retval_bits { +ETHTOOL_F_UNSUPPORTED__BIT , +ETHTOOL_F_WISH__BIT , +}; + +#define ETHTOOL_F_UNSUPPORTED (1 << ETHTOOL_F_UNSUPPORTED__BIT) +#define ETHTOOL_F_WISH (1 << ETHTOOL_F_WISH__BIT) +#ifdef __KERNEL__#include <linux/rculist.h>
@@ -744,6 +826,9 @@ struct ethtool_ops {#define ETHTOOL_GRXFHINDIR 0x00000038/* Get RX flow hash indir'n table */ #define ETHTOOL_SRXFHINDIR 0x00000039/* Set RX flow hash indir'n table */ +#define ETHTOOL_GFEATURES 0x0000003a/* Get device offload settings */ +#define ETHTOOL_SFEATURES 0x0000003b/* Change device offload settings */ +/* compatibility with older code */ #define SPARC_ETH_GSET ETHTOOL_GSET#define SPARC_ETH_SSET ETHTOOL_SSET
include/linux/netdevice.h +43 -2
93 lines not on this page · raw message
net/core/dev.c +44 -5
67 lines not on this page · raw message
net/core/ethtool.c +142 -12
218 lines not on this page · raw message
Signature · 1 line
1.7.2.3
PATCH v4 2/5 net: ethtool: use ndo_fix_features for offload setting
In reply to Michał Mirosław--- net/core/ethtool.c | 262 ++++++++++++++++++++++++---------------------------- 1 files changed, 119 insertions(+), 143 deletions(-)
net/core/ethtool.c +119 -143
@@ -240,6 +240,96 @@ static int ethtool_set_features(struct net_device *dev, void __user *useraddr)return ret; } +static u32 ethtool_get_feature_mask (u32 eth_cmd) +{ +/* feature masks of legacy discrete ethtool ops */ + +switch (eth_cmd) { +case ETHTOOL_GTXCSUM : +case ETHTOOL_STXCSUM : +return NETIF_F_ALL_CSUM |NETIF_F_SCTP_CSUM ; +case ETHTOOL_GSG : +case ETHTOOL_SSG : +return NETIF_F_SG ; +case ETHTOOL_GTSO : +case ETHTOOL_STSO : +return NETIF_F_ALL_TSO ; +case ETHTOOL_GUFO : +case ETHTOOL_SUFO : +return NETIF_F_UFO ; +case ETHTOOL_GGSO : +case ETHTOOL_SGSO : +return NETIF_F_GSO ; +case ETHTOOL_GGRO : +case ETHTOOL_SGRO : +return NETIF_F_GRO ; +default : +BUG (); + } +} + +static int ethtool_get_one_feature (struct net_device *dev,char __user *useraddr, +u32 ethcmd) +{ +struct ethtool_value edata = { + .cmd = ethcmd, + .data = !!(dev->features ðtool_get_feature_mask (ethcmd)), + }; + +if (copy_to_user (useraddr, &edata,sizeof (edata))) +return -EFAULT ; +return 0 ; +} + +static int __ethtool_set_tx_csum (struct net_device *dev,u32 data); +static int __ethtool_set_sg (struct net_device *dev,u32 data); +static int __ethtool_set_tso (struct net_device *dev,u32 data); +static int __ethtool_set_ufo (struct net_device *dev,u32 data); + +static int ethtool_set_one_feature (struct net_device *dev, +void __user *useraddr,u32 ethcmd) +{ +struct ethtool_value edata; +u32 mask; + +if (copy_from_user (&edata, useraddr,sizeof (edata))) +return -EFAULT ; + + mask =ethtool_get_feature_mask (ethcmd); + mask &= dev->hw_features; +if (mask) { +if (edata.data) + dev->wanted_features |= mask; +else + dev->wanted_features &= ~mask; + +netdev_update_features (dev); +return 0 ; + } + +/* Driver is not converted to ndo_fix_features or does not +* support changing this offload. In the latter case it won't +* have corresponding ethtool_ops field set. +* +* Following part is to be removed after all drivers advertise +* their changeable features in netdev->hw_features and stop +* using discrete offload setting ops. +*/ + +switch (ethcmd) { +case ETHTOOL_STXCSUM : +return __ethtool_set_tx_csum (dev, edata.data); +case ETHTOOL_SSG : +return __ethtool_set_sg (dev, edata.data); +case ETHTOOL_STSO : +return __ethtool_set_tso (dev, edata.data); +case ETHTOOL_SUFO : +return __ethtool_set_ufo (dev, edata.data); +default : +return -EOPNOTSUPP ; + } +} +static const char netdev_features_strings[ETHTOOL_DEV_FEATURE_WORDS *32 ][ETH_GSTRING_LEN ] = {/* NETIF_F_SG */ "tx-scatter-gather" ,/* NETIF_F_IP_CSUM */ "tx-checksum-ipv4" ,
@@ -1218,6 +1308,9 @@ static int __ethtool_set_sg(struct net_device *dev, u32 data) {int err; +if (data && !(dev->features &NETIF_F_ALL_CSUM )) +return -EINVAL ; +if (!data && dev->ethtool_ops->set_tso) { err = dev->ethtool_ops->set_tso (dev,0 );if (err)
@@ -1232,26 +1325,21 @@ static int __ethtool_set_sg(struct net_device *dev, u32 data)return dev->ethtool_ops->set_sg (dev, data); } -static int ethtool_set_tx_csum (struct net_device *dev,char __user *useraddr) +static int __ethtool_set_tx_csum (struct net_device *dev,u32 data) { -struct ethtool_value edata;int err;if (!dev->ethtool_ops->set_tx_csum)return -EOPNOTSUPP ; -if (copy_from_user (&edata, useraddr,sizeof (edata))) -return -EFAULT ; - -if (!edata.data && dev->ethtool_ops->set_sg) { +if (!data && dev->ethtool_ops->set_sg) { err =__ethtool_set_sg (dev,0 );if (err)return err; } -return dev->ethtool_ops->set_tx_csum (dev, edata.data); +return dev->ethtool_ops->set_tx_csum (dev, data); } -EXPORT_SYMBOL (ethtool_op_set_tx_csum);static int ethtool_set_rx_csum (struct net_device *dev,char __user *useraddr) {
@@ -1269,108 +1357,28 @@ static int ethtool_set_rx_csum(struct net_device *dev, char __user *useraddr)return dev->ethtool_ops->set_rx_csum (dev, edata.data); } -static int ethtool_set_sg (struct net_device *dev,char __user *useraddr) +static int __ethtool_set_tso (struct net_device *dev,u32 data) { -struct ethtool_value edata; - -if (!dev->ethtool_ops->set_sg) -return -EOPNOTSUPP ; - -if (copy_from_user (&edata, useraddr,sizeof (edata))) -return -EFAULT ; - -if (edata.data && - !(dev->features &NETIF_F_ALL_CSUM )) -return -EINVAL ; - -return __ethtool_set_sg (dev, edata.data); -} - -static int ethtool_set_tso (struct net_device *dev,char __user *useraddr) -{ -struct ethtool_value edata; -if (!dev->ethtool_ops->set_tso)return -EOPNOTSUPP ; -if (copy_from_user (&edata, useraddr,sizeof (edata))) -return -EFAULT ; - -if (edata.data && !(dev->features &NETIF_F_SG )) +if (data && !(dev->features &NETIF_F_SG ))return -EINVAL ; -return dev->ethtool_ops->set_tso (dev, edata.data); +return dev->ethtool_ops->set_tso (dev, data); } -static int ethtool_set_ufo (struct net_device *dev,char __user *useraddr) +static int __ethtool_set_ufo (struct net_device *dev,u32 data) { -struct ethtool_value edata; -if (!dev->ethtool_ops->set_ufo)return -EOPNOTSUPP ; -if (copy_from_user (&edata, useraddr,sizeof (edata))) -return -EFAULT ; -if (edata.data && !(dev->features &NETIF_F_SG )) +if (data && !(dev->features &NETIF_F_SG ))return -EINVAL ; -if (edata.data && !((dev->features &NETIF_F_GEN_CSUM ) || +if (data && !((dev->features &NETIF_F_GEN_CSUM ) || (dev->features & (NETIF_F_IP_CSUM |NETIF_F_IPV6_CSUM )) == (NETIF_F_IP_CSUM |NETIF_F_IPV6_CSUM )))return -EINVAL ; -return dev->ethtool_ops->set_ufo (dev, edata.data); -} - -static int ethtool_get_gso (struct net_device *dev,char __user *useraddr) -{ -struct ethtool_value edata = {ETHTOOL_GGSO }; - - edata.data = dev->features &NETIF_F_GSO ; -if (copy_to_user (useraddr, &edata,sizeof (edata))) -return -EFAULT ; -return 0 ; -} - -static int ethtool_set_gso (struct net_device *dev,char __user *useraddr) -{ -struct ethtool_value edata; - -if (copy_from_user (&edata, useraddr,sizeof (edata))) -return -EFAULT ; -if (edata.data) - dev->features |=NETIF_F_GSO ; -else - dev->features &= ~NETIF_F_GSO ; -return 0 ; -} - -static int ethtool_get_gro (struct net_device *dev,char __user *useraddr) -{ -struct ethtool_value edata = {ETHTOOL_GGRO }; - - edata.data = dev->features &NETIF_F_GRO ; -if (copy_to_user (useraddr, &edata,sizeof (edata))) -return -EFAULT ; -return 0 ; -} - -static int ethtool_set_gro (struct net_device *dev,char __user *useraddr) -{ -struct ethtool_value edata; - -if (copy_from_user (&edata, useraddr,sizeof (edata))) -return -EFAULT ; - -if (edata.data) { -u32 rxcsum = dev->ethtool_ops->get_rx_csum ? - dev->ethtool_ops->get_rx_csum (dev) : -ethtool_op_get_rx_csum (dev); - -if (!rxcsum) -return -EINVAL ; - dev->features |=NETIF_F_GRO ; - }else - dev->features &= ~NETIF_F_GRO ; - -return 0 ; +return dev->ethtool_ops->set_ufo (dev, data); }static int ethtool_self_test (struct net_device *dev,char __user *useraddr)
@@ -1703,33 +1711,6 @@ int dev_ethtool(struct net *net, struct ifreq *ifr)case ETHTOOL_SRXCSUM : rc =ethtool_set_rx_csum (dev, useraddr);break ; -case ETHTOOL_GTXCSUM : - rc =ethtool_get_value (dev, useraddr, ethcmd, - (dev->ethtool_ops->get_tx_csum ? - dev->ethtool_ops->get_tx_csum : - ethtool_op_get_tx_csum)); -break ; -case ETHTOOL_STXCSUM : - rc =ethtool_set_tx_csum (dev, useraddr); -break ; -case ETHTOOL_GSG : - rc =ethtool_get_value (dev, useraddr, ethcmd, - (dev->ethtool_ops->get_sg ? - dev->ethtool_ops->get_sg : - ethtool_op_get_sg)); -break ; -case ETHTOOL_SSG : - rc =ethtool_set_sg (dev, useraddr); -break ; -case ETHTOOL_GTSO : - rc =ethtool_get_value (dev, useraddr, ethcmd, - (dev->ethtool_ops->get_tso ? - dev->ethtool_ops->get_tso : - ethtool_op_get_tso)); -break ; -case ETHTOOL_STSO : - rc =ethtool_set_tso (dev, useraddr); -break ;case ETHTOOL_TEST : rc =ethtool_self_test (dev, useraddr);break ;
@@ -1745,21 +1726,6 @@ int dev_ethtool(struct net *net, struct ifreq *ifr)case ETHTOOL_GPERMADDR : rc =ethtool_get_perm_addr (dev, useraddr);break ; -case ETHTOOL_GUFO : - rc =ethtool_get_value (dev, useraddr, ethcmd, - (dev->ethtool_ops->get_ufo ? - dev->ethtool_ops->get_ufo : - ethtool_op_get_ufo)); -break ; -case ETHTOOL_SUFO : - rc =ethtool_set_ufo (dev, useraddr); -break ; -case ETHTOOL_GGSO : - rc =ethtool_get_gso (dev, useraddr); -break ; -case ETHTOOL_SGSO : - rc =ethtool_set_gso (dev, useraddr); -break ;case ETHTOOL_GFLAGS : rc = ethtool_get_value(dev, useraddr, ethcmd, (dev->ethtool_ops->get_flags ?
@@ -1790,12 +1756,6 @@ int dev_ethtool(struct net *net, struct ifreq *ifr)case ETHTOOL_SRXCLSRLINS : rc =ethtool_set_rxnfc (dev, ethcmd, useraddr);break ; -case ETHTOOL_GGRO : - rc =ethtool_get_gro (dev, useraddr); -break ; -case ETHTOOL_SGRO : - rc =ethtool_set_gro (dev, useraddr); -break ;case ETHTOOL_FLASHDEV : rc =ethtool_flash_device (dev, useraddr);break ;
@@ -1823,6 +1783,22 @@ int dev_ethtool(struct net *net, struct ifreq *ifr)case ETHTOOL_SFEATURES : rc =ethtool_set_features (dev, useraddr);break ; +case ETHTOOL_GTXCSUM : +case ETHTOOL_GSG : +case ETHTOOL_GTSO : +case ETHTOOL_GUFO : +case ETHTOOL_GGSO : +case ETHTOOL_GGRO : + rc =ethtool_get_one_feature (dev, useraddr, ethcmd); +break ; +case ETHTOOL_STXCSUM : +case ETHTOOL_SSG : +case ETHTOOL_STSO : +case ETHTOOL_SUFO : +case ETHTOOL_SGSO : +case ETHTOOL_SGRO : + rc =ethtool_set_one_feature (dev, useraddr, ethcmd); +break ;default : rc = -EOPNOTSUPP ; }
Signature · 1 line
1.7.2.3
PATCH v2 1/1 ethtool: implement G/SFEATURES calls
In reply to Michał Mirosław---
Changes from v1:
- removed deprecation of -k/-K
- mark never-changeable features in userspace
---
ethtool-copy.h | 89 +++++++++++++++++++++++- ethtool.c | 215 ++++++++++++++++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 296 insertions(+), 8 deletions(-)
ethtool-copy.h +88 -1
@@ -251,6 +251,7 @@ enum ethtool_stringset {ETH_SS_STATS ,ETH_SS_PRIV_FLAGS ,ETH_SS_NTUPLE_FILTERS , + ETH_SS_FEATURES, };/* for passing string sets for data tagging */
@@ -523,6 +524,87 @@ struct ethtool_flash {char data[ETHTOOL_FLASH_MAX_FILENAME ]; }; +/* for returning and changing feature sets */ + +/** +* struct ethtool_get_features_block - block with state of 32 features +* @available: mask of changeable features +* @requested: mask of features requested to be enabled if possible +* @active: mask of currently enabled features +* @never_changed: mask of features not changeable for any device +*/ +struct ethtool_get_features_block { +__u32 available; +__u32 requested; +__u32 active; +__u32 never_changed; +}; + +/** +* struct ethtool_gfeatures - command to get state of device's features +* @cmd: command number = %ETHTOOL_GFEATURES +* @size: in: number of elements in the features[] array; +* out: number of elements in features[] needed to hold all features +* @features: state of features +*/ +struct ethtool_gfeatures { +__u32 cmd; +__u32 size; +struct ethtool_get_features_block features[0 ]; +}; + +/** +* struct ethtool_set_features_block - block with request for 32 features +* @valid: mask of features to be changed +* @requested: values of features to be changed +*/ +struct ethtool_set_features_block { +__u32 valid; +__u32 requested; +}; + +/** +* struct ethtool_sfeatures - command to request change in device's features +* @cmd: command number = %ETHTOOL_SFEATURES +* @size: array size of the features[] array +* @features: feature change masks +*/ +struct ethtool_sfeatures { +__u32 cmd; +__u32 size; +struct ethtool_set_features_block features[0 ]; +}; + +/* +* %ETHTOOL_SFEATURES changes features present in features[].valid to the +* values of corresponding bits in features[].requested. Bits in .requested +* not set in .valid or not changeable are ignored. +* +* Returns %EINVAL when .valid contains undefined or never-changable bits +* or size is not equal to required number of features words (32-bit blocks). +* Returns >= 0 if request was completed; bits set in the value mean: +* %ETHTOOL_F_UNSUPPORTED - there were bits set in .valid that are not +* changeable (not present in %ETHTOOL_GFEATURES' features[].available) +* those bits were ignored. +* %ETHTOOL_F_WISH - some or all changes requested were recorded but the +* resulting state of bits masked by .valid is not equal to .requested. +* Probably there are other device-specific constraints on some features +* in the set. When %ETHTOOL_F_UNSUPPORTED is set, .valid is considered +* here as though ignored bits were cleared. +* +* Meaning of bits in the masks are obtained by %ETHTOOL_GSSET_INFO (number of +* bits in the arrays - always multiple of 32) and %ETHTOOL_GSTRINGS commands +* for ETH_SS_FEATURES string set. First entry in the table corresponds to least +* significant bit in features[0] fields. Empty strings mark undefined features. +*/ +enum ethtool_sfeatures_retval_bits { +ETHTOOL_F_UNSUPPORTED__BIT , +ETHTOOL_F_WISH__BIT , +}; + +#define ETHTOOL_F_UNSUPPORTED (1 << ETHTOOL_F_UNSUPPORTED__BIT) +#define ETHTOOL_F_WISH (1 << ETHTOOL_F_WISH__BIT) +/* CMDs currently supported */ #define ETHTOOL_GSET 0x00000001/* Get settings. */
@@ -534,7 +616,9 @@ struct ethtool_flash {#define ETHTOOL_GMSGLVL 0x00000007/* Get driver message level */ #define ETHTOOL_SMSGLVL 0x00000008/* Set driver msg level. */ #define ETHTOOL_NWAY_RST 0x00000009/* Restart autonegotiation. */ -#define ETHTOOL_GLINK 0x0000000a/* Get link status (ethtool_value) */ +/* Get link status for host, i.e. whether the interface *and* the +* physical port (if there is one) are up (ethtool_value). */ +#define ETHTOOL_GLINK 0x0000000a#define ETHTOOL_GEEPROM 0x0000000b/* Get EEPROM data */ #define ETHTOOL_SEEPROM 0x0000000c/* Set EEPROM data. */ #define ETHTOOL_GCOALESCE 0x0000000e/* Get coalesce config */
@@ -585,6 +669,9 @@ struct ethtool_flash {#define ETHTOOL_GRXFHINDIR 0x00000038/* Get RX flow hash indir'n table */ #define ETHTOOL_SRXFHINDIR 0x00000039/* Set RX flow hash indir'n table */ +#define ETHTOOL_GFEATURES 0x0000003a/* Get device offload settings */ +#define ETHTOOL_SFEATURES 0x0000003b/* Change device offload settings */ +/* compatibility with older code */ #define SPARC_ETH_GSET ETHTOOL_GSET#define SPARC_ETH_SSET ETHTOOL_SSET
ethtool.c +208 -7
285 lines not on this page · raw message
Signature · 1 line
1.7.2.3
PATCH v4 5/5 loopback: convert to hw_features
In reply to Michał MirosławThis also enables TSOv6, TSO-ECN, and UFO as loopback clearly can handle them.
--- drivers/net/loopback.c | 9 ++++----- 1 files changed, 4 insertions(+), 5 deletions(-)
drivers/net/loopback.c +4 -5
@@ -129,10 +129,6 @@ static u32 always_on(struct net_device *dev)static const struct ethtool_ops loopback_ethtool_ops = { .get_link = always_on, - .set_tso = ethtool_op_set_tso, - .get_tx_csum = always_on, - .get_sg = always_on, - .get_rx_csum = always_on, };static int loopback_dev_init (struct net_device *dev)
@@ -169,9 +165,12 @@ static void loopback_setup(struct net_device *dev) dev->type =ARPHRD_LOOPBACK ;/* 0x0001*/ dev->flags =IFF_LOOPBACK ; dev->priv_flags &= ~IFF_XMIT_DST_RELEASE ; + dev->hw_features =NETIF_F_ALL_TSO ; dev->features =NETIF_F_SG |NETIF_F_FRAGLIST - |NETIF_F_TSO + |NETIF_F_ALL_TSO + |NETIF_F_UFO |NETIF_F_NO_CSUM + |NETIF_F_RXCSUM |NETIF_F_HIGHDMA |NETIF_F_LLTX |NETIF_F_NETNS_LOCAL ;
Signature · 1 line
1.7.2.3
Re: [PATCH v4 1/5] net: Introduce new feature setting ops
In reply to Michał MirosławQuoted 16 lines · Michał Mirosław
This introduces a new framework to handle device features setting. It consists of:
- new fields in structnet_device:
+hw_features- features that hw/driver supports toggling
+wanted_features- features that user wants enabled, when possible
- newnetdev_ops:
+ feat =ndo_fix_features(dev, feat)- API checking constraints for enabling features or their combinations
+ndo_set_features(dev)- API updating hardware state to match changeddev->features
- new ethtool commands:
+ ETHTOOL_GFEATURES/ETHTOOL_SFEATURES: get/setdev->wanted_featuresand trigger device reconfiguration if resultingdev->featureschanged
+ETHTOOL_GSTRINGS(ETH_SS_FEATURES): get feature bits names (meaning)
Quoted 1 line
Signed-off-by Michał Mirosław <[email protected]>
Signature · 3 lines
Ben Hutchings, Senior Software Engineer, Solarflare Communications Not speaking for my employer; that's the marketing department's job. They asked us to note that Solarflare product names are trademarked.
Re: [PATCH v4 3/5] net: use ndo_fix_features for ethtool_ops->set_flags
In reply to Michał MirosławQuoted 22 lines · Michał Mirosław
Signed-off-by Michał Mirosław <[email protected]>--- net/core/ethtool.c | 31 +++++++++++++++++++++++++++++-- 1 files changed, 29 insertions(+), 2 deletions(-)net/core/ethtool.c +9
-0@@ -240,6 +240,34 @@ static int ethtool_set_features(struct net_device *dev, void __user *useraddr)return ret; } +static int __ethtool_set_flags (struct net_device *dev,u32 data) +{ +u32 changed; + +if (data & ~flags_dup_features) +return -EINVAL ; + +/* legacy set_flags() op */ +if (dev->ethtool_ops->set_flags) {
net/core/ethtool.c static int ethtool_set_features(struct net_device *dev, void __user *useraddr) · line 261
Quoted 10 lines
net/core/ethtool.c +10
-0+if (unlikely (dev->hw_features & flags_dup_features)) +netdev_warn (dev, +"driver BUG: mixed hw_features and set_flags()\n" ); +return dev->ethtool_ops->set_flags (dev, data); + } + +/* allow changing only bits set in hw_features */ + changed = (data ^ dev->wanted_features) & flags_dup_features; +if (changed & ~dev->hw_features) +return -EOPNOTSUPP ;
[...]
The error code should only be EOPNOTSUPP if (dev->hw_features & flags_dup_features) == 0. Otherwise it should be EINVAL.
Ben.
Signature · 3 lines
Ben Hutchings, Senior Software Engineer, Solarflare Communications Not speaking for my employer; that's the marketing department's job. They asked us to note that Solarflare product names are trademarked.
Re: [PATCH v4 1/5] net: Introduce new feature setting ops
In reply to Ben HutchingsFrom: Ben Hutchings <[email protected]>
Date: Mon, 07 Feb 2011 19:39:57 +0000
Quoted 17 lines · Michał Mirosław
Quoted 16 lines
This introduces a new framework to handle device features setting. It consists of:
- new fields in structnet_device:
+hw_features- features that hw/driver supports toggling
+wanted_features- features that user wants enabled, when possible
- newnetdev_ops:
+ feat =ndo_fix_features(dev, feat)- API checking constraints for enabling features or their combinations
+ndo_set_features(dev)- API updating hardware state to match changeddev->features
- new ethtool commands:
+ ETHTOOL_GFEATURES/ETHTOOL_SFEATURES: get/setdev->wanted_featuresand trigger device reconfiguration if resultingdev->featureschanged
+ETHTOOL_GSTRINGS(ETH_SS_FEATURES): get feature bits names (meaning)
Quoted 2 lines
Quoted 1 line
Signed-off-by Michał Mirosław <[email protected]>Reviewed-by Ben Hutchings <[email protected]>
Applied, thanks.
David Miller
maintainerRe: [PATCH v4 1/5] net: Introduce new feature setting ops
From: David Miller <[email protected]>
Date: Mon, 07 Feb 2011 12:51:20 -0800 (PST)
Quoted 20 lines
From: Ben Hutchings <[email protected]>
Date: Mon, 07 Feb 2011 19:39:57 +0000Quoted 17 lines · Michał Mirosław
Quoted 16 lines
This introduces a new framework to handle device features setting. It consists of:
- new fields in structnet_device:
+hw_features- features that hw/driver supports toggling
+wanted_features- features that user wants enabled, when possible
- newnetdev_ops:
+ feat =ndo_fix_features(dev, feat)- API checking constraints for enabling features or their combinations
+ndo_set_features(dev)- API updating hardware state to match changeddev->features
- new ethtool commands:
+ ETHTOOL_GFEATURES/ETHTOOL_SFEATURES: get/setdev->wanted_featuresand trigger device reconfiguration if resultingdev->featureschanged
+ETHTOOL_GSTRINGS(ETH_SS_FEATURES): get feature bits names (meaning)
Quoted 4 lines
Quoted 2 lines
Quoted 1 line
Signed-off-by Michał Mirosław <[email protected]>Reviewed-by Ben Hutchings <[email protected]>Applied, thanks.
I had to make a fix to this patch, there were duplicate EXPORT_SYMBOL() lines in net/core/ethtool.c for ethtool_op_set_tx_csum() after your changes.
How did this build successfully for you?
David Miller
maintainerRe: [PATCH v4 2/5] net: ethtool: use ndo_fix_features for offload setting
In reply to Michał MirosławFrom: Michał Mirosław <[email protected]>
Date: Thu, 3 Feb 2011 15:21:21 +0100 (CET)
Quoted 2 lines
Signed-off-by Michał Mirosław <[email protected]>Reviewed-by Ben Hutchings <[email protected]>
Applied, and now I see why the tree "built" successfully for you.
You remove the duplicate EXPORT_SYMBOL() in this patch.
You absolutely cannot test your patch sets like this, only build testing at the end.
Every single individual change must not introduce any functional or build regressions, therefore you must make sure the build works fine after each and every patch in your series, not just after they are all applied.
What disturbs me even more, is that really this problem was introduced because you mixed functional and cleanup changes in the first patch. Something you should also never do.
David Miller
maintainerRe: [PATCH v4 3/5] net: use ndo_fix_features for ethtool_ops->set_flags
In reply to Ben HutchingsFrom: Ben Hutchings <[email protected]>
Date: Mon, 07 Feb 2011 19:46:12 +0000
Quoted 35 lines · Michał Mirosław
Quoted 32 lines
Signed-off-by Michał Mirosław <[email protected]>--- net/core/ethtool.c | 31 +++++++++++++++++++++++++++++-- 1 files changed, 29 insertions(+), 2 deletions(-)net/core/ethtool.c +19
-0@@ -240,6 +240,34 @@ static int ethtool_set_features(struct net_device *dev, void __user *useraddr)return ret; } +static int __ethtool_set_flags (struct net_device *dev,u32 data) +{ +u32 changed; + +if (data & ~flags_dup_features) +return -EINVAL ; + +/* legacy set_flags() op */ +if (dev->ethtool_ops->set_flags) { +if (unlikely (dev->hw_features & flags_dup_features)) +netdev_warn (dev, +"driver BUG: mixed hw_features and set_flags()\n" ); +return dev->ethtool_ops->set_flags (dev, data); + } + +/* allow changing only bits set in hw_features */ + changed = (data ^ dev->wanted_features) & flags_dup_features; +if (changed & ~dev->hw_features) +return -EOPNOTSUPP ;[...]
Quoted 2 lines
The error code should only be EOPNOTSUPP if (
dev->hw_features&flags_dup_features) == 0. Otherwise it should be EINVAL.
I'll fix this up when I apply his patch, thanks Ben.
Re: [PATCH v4 4/5] net: introduce NETIF_F_RXCSUM
In reply to Michał MirosławFrom: Michał Mirosław <[email protected]>
Date: Thu, 3 Feb 2011 15:21:22 +0100 (CET)
Quoted 7 lines
Introduce
NETIF_F_RXCSUMto replace device-private flags for RX checksum offload. Integrate it withndo_fix_features.
ethtool_op_get_rx_csum()is removed altogether as nothing in-tree uses it.Signed-off-by Michał Mirosław <[email protected]>Reviewed-by Ben Hutchings <[email protected]>
Applied.
Re: [PATCH v4 5/5] loopback: convert to hw_features
In reply to Michał MirosławFrom: Michał Mirosław <[email protected]>
Date: Thu, 3 Feb 2011 15:21:22 +0100 (CET)
Quoted 3 lines
This also enables TSOv6, TSO-ECN, and UFO as loopback clearly can handle them.
Signed-off-by Michał Mirosław <[email protected]>
Applied.
David Miller
maintainerFrom: Michał Mirosław <[email protected]>
Date: Thu, 3 Feb 2011 15:21:21 +0100 (CET)
Quoted 11 lines
Here's a v4 of the ethtool unification patch series.
What's in it?
1:
the patch - implement unified ethtool setting ops
2..3:
implement interoperation between old and new ethtool ops
4:
include RX checksum in features and plug it into new framework
5:
convert loopback device to new framework
After these changes the ethtool output is now inaccurate for RX checksumming.
Before:
davem@maramba:~$ /usr/sbin/ethtool -k eth0 Offload parameters for eth0: rx-checksumming: on tx-checksumming: on scatter-gather: on tcp segmentation offload: off udp fragmentation offload: off generic segmentation offload: on large receive offload: off davem@maramba:~$
After:
davem@maramba:~$ /usr/sbin/ethtool -k eth0 Offload parameters for eth0: rx-checksumming: off tx-checksumming: on scatter-gather: on tcp segmentation offload: off udp fragmentation offload: off generic segmentation offload: on large receive offload: off
If the issue is that you require driver or ethtool utility changes in order for things to keep working properly, then that is not acceptable.
I'm reverting all of these changes, resubmit them when you have them in a state such that no regressions will be introduced.
Thanks.
Quoted 3 lines · David Miller
From: Michał Mirosław <[email protected]>
Date: Thu, 3 Feb 2011 15:21:21 +0100 (CET)Quoted 1 line
Here's a v4 of the ethtool unification patch series.
[cut list]
Quoted 9 lines
After these changes the ethtool output is now inaccurate for RX checksumming.
Before:
davem@maramba:~$ /usr/sbin/ethtool -k eth0 Offload parameters for eth0: rx-checksumming: on tx-checksumming: on
[...]
Quoted 6 lines
After:
davem@maramba:~$ /usr/sbin/ethtool -k eth0 Offload parameters for eth0: rx-checksumming: off tx-checksumming: on
[...]
Quoted 7 lines
If the issue is that you require driver or ethtool utility changes in order for things to keep working properly, then that is not acceptable.
I'm reverting all of these changes, resubmit them when you have them in a state such that no regressions will be introduced.
What driver did you get this output from? All drivers that implement set_rx_csum also implement their own get_rx_csum and so should not be affected by patch #4. For others that don't implement get_rx_csum rx-checksumming status is unreliable. Looking at random drivers:
- via-rhine: will advertise rx-checksumming when it doesn't support it (as a side effect of hardware workaround - checksum in driver)
- sunhme: has no way to disable rx- and tx-checksumming so was correctly showing rx-checksumming enabled
- 8139too: will show rx-checksumming enabled but doesn't support it (side effect of hardware workaround - checksumming in driver)
I wouldn't be suprised if there was a driver which doesn't advertise RX checksumming but use it anyway.
So yes - this patchset uncovers bugs in drivers. I'll see how can I make the RXCSUM patch retain the previous behaviour for this case.
Best Regards,
Michał Mirosław
David Miller
maintainerFrom: Michał Mirosław <[email protected]>
Date: Mon, 7 Feb 2011 23:49:37 +0100
Quoted 1 line
What driver did you get this output from?
NIU, which sets NETIF_F_HW_CSUM in netdev->features, which is absolutely correct.
Quoted 5 lines · David Miller
From: Michał Mirosław <[email protected]>
Date: Mon, 7 Feb 2011 23:49:37 +0100Quoted 1 line
What driver did you get this output from?
NIU, which sets
NETIF_F_HW_CSUMinnetdev->features, which is absolutely correct.
Quick look at niu_process_rx_pkt() reveals that if you disable TX checksumming you will also get 'rx-checksumming: off' from ethtool, but RX checksumming will still be used.
Best Regards,
Michał Mirosław
David Miller
maintainerBTW, none of your patch postings from today made it to the mailing lists because there were syntax errors in your email headers.
Therefore, you'll need to resend them.
Quoted 4 lines · David Miller
BTW, none of your patch postings from today made it to the mailing lists because there were syntax errors in your email headers.
Therefore, you'll need to resend them.
Hmm, that's weird. My mailer said:
mail.info: Feb 8 15:23:59 postfix/smtp[6076]: 7138813909: to=<[email protected]>, relay=vger.kernel.org[209.132.180.67]:25, delay=3, delays=0.09/0.08/2.2/0.7, dsn=2.7.0, status=sent (250 2.7.0 nothing apparently wrong in the message. BF:<H 0>; S1754489Ab1BHOX7) mail.info: Feb 8 15:23:59 postfix/smtp[6110]: BA99413A5F: to=<[email protected]>, relay=vger.kernel.org[209.132.180.67]:25, delay=3, delays=0.2/0.45/1.5/0.84, dsn=2.7.1, status=sent (250 2.7.1 Looks like Linux source DIFF email.. BF:<H 0>; S1754575Ab1BHOX7) [same for other patches in series]
And I got no bounces. What were the errors?
Best Regards,
Michał Mirosław
David Miller
maintainerFrom: Michał Mirosław <[email protected]>
Date: Wed, 9 Feb 2011 00:55:43 +0100
Quoted 1 line
And I got no bounces. What were the errors?
The bounces only go to me.
You had mal-formed email addresses in your TO or CC line, you forgot a comma between two of them.
Re: [PATCH v4 1/5] net: Introduce new feature setting ops
In reply to Ben HutchingsQuoted 17 lines · Ben Hutchings
Quoted 16 lines · Michał Mirosław
This introduces a new framework to handle device features setting. It consists of:
- new fields in structnet_device:
+hw_features- features that hw/driver supports toggling
+wanted_features- features that user wants enabled, when possible
- newnetdev_ops:
+ feat =ndo_fix_features(dev, feat)- API checking constraints for enabling features or their combinations
+ndo_set_features(dev)- API updating hardware state to match changeddev->features
- new ethtool commands:
+ ETHTOOL_GFEATURES/ETHTOOL_SFEATURES: get/setdev->wanted_featuresand trigger device reconfiguration if resultingdev->featureschanged
+ETHTOOL_GSTRINGS(ETH_SS_FEATURES): get feature bits names (meaning)
Quoted 3 lines
Quoted 1 line
Signed-off-by Michał Mirosław <[email protected]>Reviewed-by Ben Hutchings <[email protected]>
Hi guys
Do we have any ethtool patch to use these 'new' features ?
Thanks
Re: [PATCH v4 1/5] net: Introduce new feature setting ops
Quoted 18 lines · Eric Dumazet
Quoted 17 lines · Ben Hutchings
Quoted 16 lines · Michał Mirosław
This introduces a new framework to handle device features setting. It consists of:
- new fields in structnet_device:
+hw_features- features that hw/driver supports toggling
+wanted_features- features that user wants enabled, when possible
- newnetdev_ops:
+ feat =ndo_fix_features(dev, feat)- API checking constraints for enabling features or their combinations
+ndo_set_features(dev)- API updating hardware state to match changeddev->features
- new ethtool commands:
+ ETHTOOL_GFEATURES/ETHTOOL_SFEATURES: get/setdev->wanted_featuresand trigger device reconfiguration if resultingdev->featureschanged
+ETHTOOL_GSTRINGS(ETH_SS_FEATURES): get feature bits names (meaning)
Quoted 8 lines
Quoted 3 lines
Quoted 1 line
Signed-off-by Michał Mirosław <[email protected]>Reviewed-by Ben Hutchings <[email protected]>Hi guys
Do we have any ethtool patch to use these 'new' features ?
I have some unfinished changes to support this. What I don't want to do is to add an entirely separate set of options; I want -k/-K to work with old and new kernel versions, supporting named features as an extension where available.
Ben.
Signature · 3 lines
Ben Hutchings, Staff Engineer, Solarflare Not speaking for my employer; that's the marketing department's job. They asked us to note that Solarflare product names are trademarked.
Re: [PATCH v4 1/5] net: Introduce new feature setting ops
Quoted 10 lines · Ben Hutchings
Quoted 3 lines · Eric Dumazet
Hi guys
Do we have any ethtool patch to use these 'new' features ?
I have some unfinished changes to support this. What I don't want to do is to add an entirely separate set of options; I want -k/-K to work with old and new kernel versions, supporting named features as an extension where available.
Excellent !
Thanks
Re: [PATCH v4 1/5] net: Introduce new feature setting ops
In reply to Ben HutchingsQuoted 19 lines · Ben Hutchings
Quoted 18 lines · Eric Dumazet
Quoted 17 lines · Ben Hutchings
Quoted 16 lines · Michał Mirosław
This introduces a new framework to handle device features setting. It consists of:
- new fields in structnet_device:
+hw_features- features that hw/driver supports toggling
+wanted_features- features that user wants enabled, when possible
- newnetdev_ops:
+ feat =ndo_fix_features(dev, feat)- API checking constraints for enabling features or their combinations
+ndo_set_features(dev)- API updating hardware state to match changeddev->features
- new ethtool commands:
+ ETHTOOL_GFEATURES/ETHTOOL_SFEATURES: get/setdev->wanted_featuresand trigger device reconfiguration if resultingdev->featureschanged
+ETHTOOL_GSTRINGS(ETH_SS_FEATURES): get feature bits names (meaning)
Quoted 7 lines
Quoted 3 lines
Quoted 2 lines
Quoted 1 line
Signed-off-by Michał Mirosław <[email protected]>Reviewed-by Ben Hutchings <[email protected]>Do we have any ethtool patch to use these 'new' features ?
I have some unfinished changes to support this. What I don't want to do is to add an entirely separate set of options; I want -k/-K to work with old and new kernel versions, supporting named features as an extension where available.
Ben, what are your patches like? I mean their state? I'm asking, because I found a bit of time and rebased my earlier patch to current ethtool 3.2 this weekend. Haven't sent them yet, because I'm seeing -EOPNOTSUPP from kernel on x86_64 for GFEATURES and I'm trying to figure out where's the bug.
Best Regards,
Michał Mirosław
RFC PATCH 1/1 ethtool: implement [GS]FEATURES handling
Quoted 10 lines · Michał Mirosław
Quoted 4 lines · Ben Hutchings
I have some unfinished changes to support this. What I don't want to do is to add an entirely separate set of options; I want -k/-K to work with old and new kernel versions, supporting named features as an extension where available.
Ben, what are your patches like? I mean their state? I'm asking, because I found a bit of time and rebased my earlier patch to current ethtool 3.2 this weekend. Haven't sent them yet, because I'm seeing
-EOPNOTSUPPfrom kernel onx86_64for GFEATURES and I'm trying to figure out where's the bug.
Turned out it was a typo in userspace code. Resulting patch below.
The more I look at this the more I think that never_changed field was a mistake and it would be better to include vlan_features there instead. What do you think? Can we change it (it's not widely used, yet)? That would include changing GFEATURES command number of course.
Best Regards,
Michał Mirosław
--- ethtool.c | 613 ++++++++++++++++++++++++++++++++++++++++++++++++------------ 1 files changed, 490 insertions(+), 123 deletions(-)
ethtool.c +490 -123
@@ -1036,9 +1036,15 @@ static int dump_coalesce(const struct ethtool_coalesce *ecoal)return 0 ; } -static int dump_offload (int rx,int tx,int sg,int tso,int ufo,int gso, -int gro,int lro,int rxvlan,int txvlan,int ntuple, -int rxhash) +struct offload_state { +int rx, tx, sg, tso, ufo, gso, gro, lro, rxvlan, txvlan, ntuple, rxhash; +}; + +static const char *const old_feature_names[] = { +"rx" ,"tx" ,"sg" ,"tso" ,"ufo" ,"gso" ,"gro" ,"lro" ,"rxvlan" ,"txvlan" ,"ntuple" ,"rxhash" +}; + +static int dump_offload (const struct offload_state *offload) {fprintf (stdout, "rx-checksumming: %s\n"
@@ -1053,18 +1059,18 @@ static int dump_offload(int rx, int tx, int sg, int tso, int ufo, int gso,"tx-vlan-offload: %s\n" "ntuple-filters: %s\n" "receive-hashing: %s\n" , - rx ?"on" :"off" , - tx ?"on" :"off" , - sg ?"on" :"off" , - tso ?"on" :"off" , - ufo ?"on" :"off" , - gso ?"on" :"off" , - gro ?"on" :"off" , - lro ?"on" :"off" , - rxvlan ?"on" :"off" , - txvlan ?"on" :"off" , - ntuple ?"on" :"off" , - rxhash ? "on" : "off"); + offload->rx ?"on" :"off" , + offload->tx ?"on" :"off" , + offload->sg ?"on" :"off" , + offload->tso ?"on" :"off" , + offload->ufo ?"on" :"off" , + offload->gso ?"on" :"off" , + offload->gro ?"on" :"off" , + offload->lro ?"on" :"off" , + offload->rxvlan ?"on" :"off" , + offload->txvlan ?"on" :"off" , + offload->ntuple ?"on" :"off" , + offload->rxhash ? "on" : "off");return 0 ; }
@@ -1547,24 +1553,20 @@ static int do_scoalesce(struct cmd_context *ctx)return 0 ; } -static int do_goffload (struct cmd_context *ctx) +static int send_goffloads (struct cmd_context *ctx, +struct offload_state *offload) {struct ethtool_value eval; -int err, allfail =1 , rx =0 , tx =0 , sg =0 ; -int tso =0 , ufo =0 , gso =0 , gro =0 , lro =0 , rxvlan =0 , txvlan =0 , - ntuple =0 , rxhash =0 ; - -if (ctx->argc !=0 ) -exit_bad_args (); +int err, allfail =1 ; -fprintf (stdout,"Offload parameters for %s:\n" , ctx->devname); +memset (offload,0 ,sizeof (*offload)); eval.cmd =ETHTOOL_GRXCSUM ; err =send_ioctl (ctx, &eval);if (err)perror ("Cannot get device rx csum settings" );else { - rx = eval.data; + offload->rx = eval.data; allfail =0 ; }
@@ -1573,7 +1575,7 @@ static int do_goffload(struct cmd_context *ctx)if (err)perror ("Cannot get device tx csum settings" );else { - tx = eval.data; + offload->tx = eval.data; allfail =0 ; }
@@ -1582,7 +1584,7 @@ static int do_goffload(struct cmd_context *ctx)if (err)perror ("Cannot get device scatter-gather settings" );else { - sg = eval.data; + offload->sg = eval.data; allfail =0 ; }
@@ -1591,7 +1593,7 @@ static int do_goffload(struct cmd_context *ctx)if (err)perror ("Cannot get device tcp segmentation offload settings" );else { - tso = eval.data; + offload->tso = eval.data; allfail =0 ; }
@@ -1600,7 +1602,7 @@ static int do_goffload(struct cmd_context *ctx)if (err)perror ("Cannot get device udp large send offload settings" );else { - ufo = eval.data; + offload->ufo = eval.data; allfail =0 ; }
@@ -1609,7 +1611,7 @@ static int do_goffload(struct cmd_context *ctx)if (err)perror ("Cannot get device generic segmentation offload settings" );else { - gso = eval.data; + offload->gso = eval.data; allfail =0 ; }
@@ -1618,11 +1620,11 @@ static int do_goffload(struct cmd_context *ctx)if (err) {perror ("Cannot get device flags" ); }else { - lro = (eval.data Ð_FLAG_LRO ) !=0 ; - rxvlan = (eval.data Ð_FLAG_RXVLAN ) !=0 ; - txvlan = (eval.data Ð_FLAG_TXVLAN ) !=0 ; - ntuple = (eval.data Ð_FLAG_NTUPLE ) !=0 ; - rxhash = (eval.data Ð_FLAG_RXHASH ) !=0 ; + offload->lro = (eval.data Ð_FLAG_LRO ) !=0 ; + offload->rxvlan = (eval.data Ð_FLAG_RXVLAN ) !=0 ; + offload->txvlan = (eval.data Ð_FLAG_TXVLAN ) !=0 ; + offload->ntuple = (eval.data Ð_FLAG_NTUPLE ) !=0 ; + offload->rxhash = (eval.data Ð_FLAG_RXHASH ) !=0 ; allfail =0 ; }
@@ -1631,7 +1633,7 @@ static int do_goffload(struct cmd_context *ctx)if (err)perror ("Cannot get device GRO settings" );else { - gro = eval.data; + offload->gro = eval.data; allfail =0 ; }
@@ -1640,144 +1642,509 @@ static int do_goffload(struct cmd_context *ctx)return 83 ; } -return dump_offload (rx, tx, sg, tso, ufo, gso, gro, lro, rxvlan, txvlan, - ntuple, rxhash); +return 0 ; } -static int do_soffload (struct cmd_context *ctx) +static int send_soffloads (struct cmd_context *ctx, +const struct offload_state *wanted) { -int goffload_changed =0 ; -int off_csum_rx_wanted =-1 ; -int off_csum_tx_wanted =-1 ; -int off_sg_wanted =-1 ; -int off_tso_wanted =-1 ; -int off_ufo_wanted =-1 ; -int off_gso_wanted =-1 ; +struct ethtool_value eval; +int changed =0 , err;u32 off_flags_wanted =0 ;u32 off_flags_mask =0 ; -int off_gro_wanted =-1 ; -struct cmdline_info cmdline_offload[] = { - {"rx" ,CMDL_BOOL , &off_csum_rx_wanted,NULL }, - {"tx" ,CMDL_BOOL , &off_csum_tx_wanted,NULL }, - {"sg" ,CMDL_BOOL , &off_sg_wanted,NULL }, - {"tso" ,CMDL_BOOL , &off_tso_wanted,NULL }, - {"ufo" ,CMDL_BOOL , &off_ufo_wanted,NULL }, - {"gso" ,CMDL_BOOL , &off_gso_wanted,NULL }, - {"lro" ,CMDL_FLAG , &off_flags_wanted,NULL , -ETH_FLAG_LRO , &off_flags_mask }, - {"gro" ,CMDL_BOOL , &off_gro_wanted,NULL }, - {"rxvlan" ,CMDL_FLAG , &off_flags_wanted,NULL , -ETH_FLAG_RXVLAN , &off_flags_mask }, - {"txvlan" ,CMDL_FLAG , &off_flags_wanted,NULL , -ETH_FLAG_TXVLAN , &off_flags_mask }, - {"ntuple" ,CMDL_FLAG , &off_flags_wanted,NULL , -ETH_FLAG_NTUPLE , &off_flags_mask }, - {"rxhash" ,CMDL_FLAG , &off_flags_wanted,NULL , -ETH_FLAG_RXHASH , &off_flags_mask }, - }; -struct ethtool_value eval; -int err, changed =0 ; -parse_generic_cmdline (ctx, &goffload_changed, - cmdline_offload,ARRAY_SIZE (cmdline_offload)); +if (wanted->lro >=0 ) { + off_flags_mask |=ETH_FLAG_LRO ; +if (wanted->lro) + off_flags_wanted |=ETH_FLAG_LRO ; + } + +if (wanted->rxvlan >=0 ) { + off_flags_mask |=ETH_FLAG_RXVLAN ; +if (wanted->rxvlan) + off_flags_wanted |=ETH_FLAG_RXVLAN ; + } -if (off_csum_rx_wanted >=0 ) { - changed =1 ; +if (wanted->txvlan >=0 ) { + off_flags_mask |=ETH_FLAG_TXVLAN ; +if (wanted->txvlan) + off_flags_wanted |=ETH_FLAG_TXVLAN ; + } + +if (wanted->ntuple >=0 ) { + off_flags_mask |=ETH_FLAG_NTUPLE ; +if (wanted->ntuple) + off_flags_wanted |=ETH_FLAG_NTUPLE ; + } + +if (wanted->rxhash >=0 ) { + off_flags_mask |=ETH_FLAG_RXHASH ; +if (wanted->rxhash) + off_flags_wanted |=ETH_FLAG_RXHASH ; + } + +if (wanted->rx >=0 ) { eval.cmd =ETHTOOL_SRXCSUM ; - eval.data = (off_csum_rx_wanted ==1 ); + eval.data = !!wanted->rx; err =send_ioctl (ctx, &eval); -if (err) { +if (err)perror ("Cannot set device rx csum settings" ); -return 84 ; - } +else + changed =1 ; } -if (off_csum_tx_wanted >=0 ) { - changed =1 ; +if (wanted->tx >=0 ) { eval.cmd =ETHTOOL_STXCSUM ; - eval.data = (off_csum_tx_wanted ==1 ); + eval.data = !!wanted->tx; err =send_ioctl (ctx, &eval); -if (err) { +if (err)perror ("Cannot set device tx csum settings" ); -return 85 ; - } +else + changed =1 ; } -if (off_sg_wanted >=0 ) { - changed =1 ; +if (wanted->sg >=0 ) { eval.cmd =ETHTOOL_SSG ; - eval.data = (off_sg_wanted ==1 ); + eval.data = !!wanted->sg; err =send_ioctl (ctx, &eval); -if (err) { +if (err)perror ("Cannot set device scatter-gather settings" ); -return 86 ; - } +else + changed =1 ; } -if (off_tso_wanted >=0 ) { - changed =1 ; +if (wanted->tso >=0 ) { eval.cmd =ETHTOOL_STSO ; - eval.data = (off_tso_wanted ==1 ); + eval.data = !!wanted->tso; err =send_ioctl (ctx, &eval); -if (err) { +if (err)perror ("Cannot set device tcp segmentation offload settings" ); -return 88 ; - } +else + changed =1 ; } -if (off_ufo_wanted >=0 ) { - changed =1 ; +if (wanted->ufo >=0 ) { eval.cmd =ETHTOOL_SUFO ; - eval.data = (off_ufo_wanted ==1 ); + eval.data = !!wanted->ufo; err =send_ioctl (ctx, &eval); -if (err) { +if (err)perror ("Cannot set device udp large send offload settings" ); -return 89 ; - } +else + changed =1 ; } -if (off_gso_wanted >=0 ) { - changed =1 ; +if (wanted->gso >=0 ) { eval.cmd =ETHTOOL_SGSO ; - eval.data = (off_gso_wanted ==1 ); + eval.data = !!wanted->gso; err =send_ioctl (ctx, &eval); -if (err) { +if (err)perror ("Cannot set device generic segmentation offload settings" ); -return 90 ; - } +else + changed =1 ; }if (off_flags_mask) { - changed =1 ; eval.cmd =ETHTOOL_GFLAGS ; eval.data =0 ; err =send_ioctl (ctx, &eval); -if (err) { +if (err)perror ("Cannot get device flag settings" ); -return 91 ; - } - - eval.cmd =ETHTOOL_SFLAGS ; - eval.data = ((eval.data & ~off_flags_mask) | - off_flags_wanted); - - err =send_ioctl (ctx, &eval); -if (err) { -perror ("Cannot set device flag settings" ); -return 92 ; +else { + eval.cmd =ETHTOOL_SFLAGS ; + eval.data = ((eval.data & ~off_flags_mask) | + off_flags_wanted); + + err =send_ioctl (ctx, &eval); +if (err) +perror ("Cannot set device flag settings" ); +else + changed =1 ; } } -if (off_gro_wanted >=0 ) { - changed =1 ; +if (wanted->gro >=0 ) { eval.cmd =ETHTOOL_SGRO ; - eval.data = (off_gro_wanted ==1 ); + eval.data = !!wanted->gro; err =send_ioctl (ctx, &eval); -if (err) { +if (err)perror ("Cannot set device GRO settings" ); -return 93 ; +else + changed =1 ; + } + +return changed; +} + +static int n_feature_strings; +static const char **feature_strings; + +static int init_feature_strings (struct cmd_context *ctx) +{ +struct ethtool_gstrings *strings; +int i, n; + +if (feature_strings) +return n_feature_strings; + + strings =get_stringset (ctx,ETH_SS_FEATURES ,0 ); +if (!strings) +return -100 ; + + n = n_feature_strings = strings->len; + feature_strings =calloc (n,sizeof (*feature_strings)); +if (!feature_strings) { +fprintf (stderr,"no memory available for string table [size=%d]\n" , n); +exit (95 ); + } + +for (i =0 ; i < n; ++i) { +if (!strings->data[i*ETH_GSTRING_LEN ]) +continue ; + + feature_strings[i] =strndup ( + (const char *)&strings->data[i *ETH_GSTRING_LEN ], +ETH_GSTRING_LEN ); + +if (!feature_strings[i]) { +fprintf (stderr,"no memory available for a string\n" ); +exit (95 ); } } +free (strings); +return n; +} + +static void parse_sfeatures_args (struct cmd_context *ctx, +struct offload_state *offload, +struct ethtool_sfeatures **features_req_p) +{ +struct ethtool_sfeatures *features_req; +struct cmdline_info *cmdline_desc, *cp; +int sz_features, i; +int changed =0 ; + +struct cmdline_info cmdline_offload[] = { + {"rx" ,CMDL_BOOL , &offload->rx,NULL }, + {"tx" ,CMDL_BOOL , &offload->tx,NULL }, + {"sg" ,CMDL_BOOL , &offload->sg,NULL }, + {"tso" ,CMDL_BOOL , &offload->tso,NULL }, + {"ufo" ,CMDL_BOOL , &offload->ufo,NULL }, + {"gso" ,CMDL_BOOL , &offload->gso,NULL }, + {"lro" ,CMDL_FLAG , &offload->lro,NULL }, + {"gro" ,CMDL_FLAG , &offload->gro,NULL }, + {"rxvlan" ,CMDL_FLAG , &offload->rxvlan,NULL }, + {"txvlan" ,CMDL_FLAG , &offload->txvlan,NULL }, + {"ntuple" ,CMDL_FLAG , &offload->ntuple,NULL }, + {"rxhash" ,CMDL_FLAG , &offload->rxhash,NULL }, + }; + +for (i =0 ; i <ARRAY_SIZE (old_feature_names); ++i) + ((int *)offload)[i] =-1 ; + *features_req_p =NULL ; + +if (init_feature_strings (ctx) <0 ) { +/* ETHTOOL_GFEATURES unavailable */ +parse_generic_cmdline (ctx, &changed, + cmdline_offload,ARRAY_SIZE (cmdline_offload)); +return ; + } + + sz_features =sizeof (*features_req->features) * ((n_feature_strings +31 ) /32 ); + + cp = cmdline_desc =calloc (n_feature_strings +ARRAY_SIZE (cmdline_offload), +sizeof (*cmdline_desc)); +memcpy (cp, cmdline_offload,sizeof (cmdline_offload)); + cp +=ARRAY_SIZE (cmdline_offload); + + features_req =calloc (1 ,sizeof (*features_req) + sz_features); +if (!cmdline_desc || !features_req) { +fprintf (stderr,"no memory available\n" ); +exit (95 ); + } + + features_req->size = (n_feature_strings +31 ) /32 ; + +for (i =0 ; i < n_feature_strings; ++i) { +if (!feature_strings[i]) +continue ; + + cp->name = feature_strings[i]; + cp->type =CMDL_FLAG ; + cp->flag_val =1 << (i %32 ); + cp->wanted_val = &features_req->features[i /32 ].requested; + cp->seen_val = &features_req->features[i /32 ].valid; + ++cp; + } + +parse_generic_cmdline (ctx, &changed, cmdline_desc, cp - cmdline_desc); + +free (cmdline_desc); + +if (changed) + *features_req_p = features_req; +else +free (features_req); +} + +static int send_gfeatures (struct cmd_context *ctx, +struct ethtool_gfeatures **features_p) +{ +struct ethtool_gfeatures *features; +int err, sz_features; + + sz_features =sizeof (*features->features) * ((n_feature_strings +31 ) /32 ); + features =calloc (1 , sz_features +sizeof (*features)); +if (!features) { +fprintf (stderr,"no memory available\n" ); +return 95 ; + } + + features->cmd =ETHTOOL_GFEATURES ; + features->size = (n_feature_strings +31 ) /32 ; + err =send_ioctl (ctx, features); + +if (err <0 ) { +perror ("Cannot get feature status" ); +free (features); +return 97 ; + } + + *features_p = features; +return 0 ; +} + +static const char *get_feature_state (struct ethtool_get_features_block *gfb, +uint32_t bit) +{ +if (gfb->never_changed & bit) +return "fixed" ; +if (!(gfb->available & bit)) +return "driver-controlled" ; + +if ((gfb->active ^ gfb->requested) & bit) +return (gfb->requested & bit) ?"requested on" :"requested off" ; +else +return "changeable" ; +} + +static int do_gfeatures (struct cmd_context *ctx) +{ +struct ethtool_get_features_block *gfb; +struct ethtool_gfeatures *features; +uint32_t bit; +int err, i; + + err =init_feature_strings (ctx); +if (err <0 ) +return -err; + + err =send_gfeatures (ctx, &features); +if (err) +return err; + +fprintf (stdout,"\nExtended offload state for %s:\n" , ctx->devname); +for (i =0 ; i < n_feature_strings; i++) { +if (!feature_strings[i]) +continue ;/* empty */ + + gfb = features->features + i /32 ; + bit =1 << (i %32 ); + +fprintf (stdout,"%s: %s (%s)\n" , feature_strings[i], + (gfb->active & bit) ?"on" :"off" , +get_feature_state (gfb, bit)); + } +free (features); + +return 0 ; +} + +static void print_gfeatures_diff ( +const struct ethtool_get_features_block *expected, +const struct ethtool_get_features_block *set, +const char **strings,int n_strings) +{ +int i; + +if (n_strings >32 ) + n_strings =32 ; + +for (i =0 ; i < n_strings; ++i) { +u32 mask =1 << i; + +if (!strings[i]) +continue ; + +if (!((expected->active ^ set->active) & mask)) +continue ; + +fprintf (stdout,"feature %.*s is %s (expected: %s, saved: %s)\n" , +ETH_GSTRING_LEN , strings[i], + set->active & mask ?"enabled" :"disabled" , + expected->active & mask ?"enabled" :"disabled" , + !(set->available & mask) ?"not user-changeable" : + set->requested & mask ?"enabled" :"disabled" + ); + } +} + +static int get_offload_state (struct cmd_context *ctx, +struct ethtool_gfeatures **features, +struct offload_state *offload) +{ +int err, allfail; + +if (ctx->argc !=0 ) +exit_bad_args (); + + allfail =send_goffloads (ctx, offload); + + err =init_feature_strings (ctx); +if (err <0 ) +return allfail ? err :0 ; + + err =send_gfeatures (ctx, features); +if (err) +perror ("Cannot read features" ); + +return allfail ? -err :0 ; +} + +static int send_sfeatures (struct cmd_context *ctx, +struct ethtool_sfeatures *features) +{ +int err; + + features->cmd =ETHTOOL_SFEATURES ; + err =send_ioctl (ctx, features); +if (err <0 ) { +perror ("Cannot change features" ); +return 97 ; + } + +return 0 ; +} + +static void compare_offload_state (struct offload_state *offload0, +struct offload_state *offload_req,struct offload_state *offload1) +{ +int *old = (int *)offload0; +int *req = (int *)offload_req; +int *new = (int *)offload1; +int i; + +for (i =0 ; i <ARRAY_SIZE (old_feature_names); i++) { +if (req[i] <0 ) + req[i] = old[i]; +if (req[i] == new[i]) +continue ; + +fprintf (stdout,"feature group %s is %s (expected: %s)\n" , + old_feature_names[i], + new[i] ?"enabled" :"disabled" , + req[i] ?"enabled" :"disabled" + ); + } +} + +static void compare_features (struct ethtool_gfeatures *features0, +struct ethtool_sfeatures *features_req, +struct ethtool_gfeatures *features1) +{ +int i; + +if (features_req) { +/* make features0 .active what we expect to be set */ + i = (n_feature_strings +31 ) /32 ; +while (i--) { + features0->features[i].active &= ~features_req->features[i].valid; + features0->features[i].active |= + features_req->features[i].requested & + features_req->features[i].valid; + } + } + +for (i =0 ; i < n_feature_strings; i +=32 ) +print_gfeatures_diff (&features0->features[i /32 ], + &features1->features[i /32 ], + feature_strings + i, + n_feature_strings - i); +} + +static int do_goffload (struct cmd_context *ctx) +{ +struct offload_state offload; +int err, allfail; + + allfail =send_goffloads (ctx, &offload); + +if (!allfail) { +fprintf (stdout,"Offload parameters for %s:\n" , ctx->devname); + +dump_offload (&offload); + } + + err =do_gfeatures (ctx); +if (!err) + allfail =0 ; + +if (allfail) { +fprintf (stdout,"no offload info available\n" ); +return 83 ; + } + +return 0 ; +} + +static int do_soffload (struct cmd_context *ctx) +{ +struct ethtool_gfeatures *features_old, *features_new; +struct ethtool_sfeatures *features_req; +struct offload_state offload_old, offload_new, offload_req; +int err, changed; + +parse_sfeatures_args (ctx, &offload_req, &features_req); + + err =get_offload_state (ctx, &features_old, &offload_old); +if (err) +return -err; + + changed =send_soffloads (ctx, &offload_req); + +if (features_req) { + err =send_sfeatures (ctx, features_req); +if (!err) + changed =1 ; + } +if (!changed) {fprintf (stdout,"no offload settings changed\n" ); +return err; + } + + err =get_offload_state (ctx, &features_new, &offload_new); +if (err) { +perror ("can't verify offload setting" ); +return 101 ; + } + +if ((!features_old) ^ (!features_new)) { +fprintf (stderr,"can't compare features (one GFEATURES failed)\n" ); +if (features_old) { +free (features_old); + features_old =NULL ; + } +if (features_new) { +free (features_new); + features_new =NULL ; + } + } + +compare_offload_state (&offload_old, &offload_req, &offload_new); +if (features_old) { +compare_features (features_old, features_req, features_new); +free (features_old); +free (features_new); } +if (features_req) +free (features_req);return 0 ; }
Signature · 1 line
1.7.8.3
RFC PATCH v2 1/1 ethtool: implement [GS]FEATURES handling
v2: fix missing change CMDL_FLAG -> CMDL_BOOL for old offloads parsing
--- ethtool.c | 613 ++++++++++++++++++++++++++++++++++++++++++++++++------------ 1 files changed, 490 insertions(+), 123 deletions(-)
ethtool.c +490 -123
@@ -1036,9 +1036,15 @@ static int dump_coalesce(const struct ethtool_coalesce *ecoal)return 0 ; } -static int dump_offload (int rx,int tx,int sg,int tso,int ufo,int gso, -int gro,int lro,int rxvlan,int txvlan,int ntuple, -int rxhash) +struct offload_state { +int rx, tx, sg, tso, ufo, gso, gro, lro, rxvlan, txvlan, ntuple, rxhash; +}; + +static const char *const old_feature_names[] = { +"rx" ,"tx" ,"sg" ,"tso" ,"ufo" ,"gso" ,"gro" ,"lro" ,"rxvlan" ,"txvlan" ,"ntuple" ,"rxhash" +}; + +static int dump_offload (const struct offload_state *offload) {fprintf (stdout, "rx-checksumming: %s\n"
@@ -1053,18 +1059,18 @@ static int dump_offload(int rx, int tx, int sg, int tso, int ufo, int gso,"tx-vlan-offload: %s\n" "ntuple-filters: %s\n" "receive-hashing: %s\n" , - rx ?"on" :"off" , - tx ?"on" :"off" , - sg ?"on" :"off" , - tso ?"on" :"off" , - ufo ?"on" :"off" , - gso ?"on" :"off" , - gro ?"on" :"off" , - lro ?"on" :"off" , - rxvlan ?"on" :"off" , - txvlan ?"on" :"off" , - ntuple ?"on" :"off" , - rxhash ? "on" : "off"); + offload->rx ?"on" :"off" , + offload->tx ?"on" :"off" , + offload->sg ?"on" :"off" , + offload->tso ?"on" :"off" , + offload->ufo ?"on" :"off" , + offload->gso ?"on" :"off" , + offload->gro ?"on" :"off" , + offload->lro ?"on" :"off" , + offload->rxvlan ?"on" :"off" , + offload->txvlan ?"on" :"off" , + offload->ntuple ?"on" :"off" , + offload->rxhash ? "on" : "off");return 0 ; }
@@ -1547,24 +1553,20 @@ static int do_scoalesce(struct cmd_context *ctx)return 0 ; } -static int do_goffload (struct cmd_context *ctx) +static int send_goffloads (struct cmd_context *ctx, +struct offload_state *offload) {struct ethtool_value eval; -int err, allfail =1 , rx =0 , tx =0 , sg =0 ; -int tso =0 , ufo =0 , gso =0 , gro =0 , lro =0 , rxvlan =0 , txvlan =0 , - ntuple =0 , rxhash =0 ; - -if (ctx->argc !=0 ) -exit_bad_args (); +int err, allfail =1 ; -fprintf (stdout,"Offload parameters for %s:\n" , ctx->devname); +memset (offload,0 ,sizeof (*offload)); eval.cmd =ETHTOOL_GRXCSUM ; err =send_ioctl (ctx, &eval);if (err)perror ("Cannot get device rx csum settings" );else { - rx = eval.data; + offload->rx = eval.data; allfail =0 ; }
@@ -1573,7 +1575,7 @@ static int do_goffload(struct cmd_context *ctx)if (err)perror ("Cannot get device tx csum settings" );else { - tx = eval.data; + offload->tx = eval.data; allfail =0 ; }
@@ -1582,7 +1584,7 @@ static int do_goffload(struct cmd_context *ctx)if (err)perror ("Cannot get device scatter-gather settings" );else { - sg = eval.data; + offload->sg = eval.data; allfail =0 ; }
@@ -1591,7 +1593,7 @@ static int do_goffload(struct cmd_context *ctx)if (err)perror ("Cannot get device tcp segmentation offload settings" );else { - tso = eval.data; + offload->tso = eval.data; allfail =0 ; }
@@ -1600,7 +1602,7 @@ static int do_goffload(struct cmd_context *ctx)if (err)perror ("Cannot get device udp large send offload settings" );else { - ufo = eval.data; + offload->ufo = eval.data; allfail =0 ; }
@@ -1609,7 +1611,7 @@ static int do_goffload(struct cmd_context *ctx)if (err)perror ("Cannot get device generic segmentation offload settings" );else { - gso = eval.data; + offload->gso = eval.data; allfail =0 ; }
@@ -1618,11 +1620,11 @@ static int do_goffload(struct cmd_context *ctx)if (err) {perror ("Cannot get device flags" ); }else { - lro = (eval.data Ð_FLAG_LRO ) !=0 ; - rxvlan = (eval.data Ð_FLAG_RXVLAN ) !=0 ; - txvlan = (eval.data Ð_FLAG_TXVLAN ) !=0 ; - ntuple = (eval.data Ð_FLAG_NTUPLE ) !=0 ; - rxhash = (eval.data Ð_FLAG_RXHASH ) !=0 ; + offload->lro = (eval.data Ð_FLAG_LRO ) !=0 ; + offload->rxvlan = (eval.data Ð_FLAG_RXVLAN ) !=0 ; + offload->txvlan = (eval.data Ð_FLAG_TXVLAN ) !=0 ; + offload->ntuple = (eval.data Ð_FLAG_NTUPLE ) !=0 ; + offload->rxhash = (eval.data Ð_FLAG_RXHASH ) !=0 ; allfail =0 ; }
@@ -1631,7 +1633,7 @@ static int do_goffload(struct cmd_context *ctx)if (err)perror ("Cannot get device GRO settings" );else { - gro = eval.data; + offload->gro = eval.data; allfail =0 ; }
@@ -1640,144 +1642,509 @@ static int do_goffload(struct cmd_context *ctx)return 83 ; } -return dump_offload (rx, tx, sg, tso, ufo, gso, gro, lro, rxvlan, txvlan, - ntuple, rxhash); +return 0 ; } -static int do_soffload (struct cmd_context *ctx) +static int send_soffloads (struct cmd_context *ctx, +const struct offload_state *wanted) { -int goffload_changed =0 ; -int off_csum_rx_wanted =-1 ; -int off_csum_tx_wanted =-1 ; -int off_sg_wanted =-1 ; -int off_tso_wanted =-1 ; -int off_ufo_wanted =-1 ; -int off_gso_wanted =-1 ; +struct ethtool_value eval; +int changed =0 , err;u32 off_flags_wanted =0 ;u32 off_flags_mask =0 ; -int off_gro_wanted =-1 ; -struct cmdline_info cmdline_offload[] = { - {"rx" ,CMDL_BOOL , &off_csum_rx_wanted,NULL }, - {"tx" ,CMDL_BOOL , &off_csum_tx_wanted,NULL }, - {"sg" ,CMDL_BOOL , &off_sg_wanted,NULL }, - {"tso" ,CMDL_BOOL , &off_tso_wanted,NULL }, - {"ufo" ,CMDL_BOOL , &off_ufo_wanted,NULL }, - {"gso" ,CMDL_BOOL , &off_gso_wanted,NULL }, - {"lro" ,CMDL_FLAG , &off_flags_wanted,NULL , -ETH_FLAG_LRO , &off_flags_mask }, - {"gro" ,CMDL_BOOL , &off_gro_wanted,NULL }, - {"rxvlan" ,CMDL_FLAG , &off_flags_wanted,NULL , -ETH_FLAG_RXVLAN , &off_flags_mask }, - {"txvlan" ,CMDL_FLAG , &off_flags_wanted,NULL , -ETH_FLAG_TXVLAN , &off_flags_mask }, - {"ntuple" ,CMDL_FLAG , &off_flags_wanted,NULL , -ETH_FLAG_NTUPLE , &off_flags_mask }, - {"rxhash" ,CMDL_FLAG , &off_flags_wanted,NULL , -ETH_FLAG_RXHASH , &off_flags_mask }, - }; -struct ethtool_value eval; -int err, changed =0 ; -parse_generic_cmdline (ctx, &goffload_changed, - cmdline_offload,ARRAY_SIZE (cmdline_offload)); +if (wanted->lro >=0 ) { + off_flags_mask |=ETH_FLAG_LRO ; +if (wanted->lro) + off_flags_wanted |=ETH_FLAG_LRO ; + } + +if (wanted->rxvlan >=0 ) { + off_flags_mask |=ETH_FLAG_RXVLAN ; +if (wanted->rxvlan) + off_flags_wanted |=ETH_FLAG_RXVLAN ; + } -if (off_csum_rx_wanted >=0 ) { - changed =1 ; +if (wanted->txvlan >=0 ) { + off_flags_mask |=ETH_FLAG_TXVLAN ; +if (wanted->txvlan) + off_flags_wanted |=ETH_FLAG_TXVLAN ; + } + +if (wanted->ntuple >=0 ) { + off_flags_mask |=ETH_FLAG_NTUPLE ; +if (wanted->ntuple) + off_flags_wanted |=ETH_FLAG_NTUPLE ; + } + +if (wanted->rxhash >=0 ) { + off_flags_mask |=ETH_FLAG_RXHASH ; +if (wanted->rxhash) + off_flags_wanted |=ETH_FLAG_RXHASH ; + } + +if (wanted->rx >=0 ) { eval.cmd =ETHTOOL_SRXCSUM ; - eval.data = (off_csum_rx_wanted ==1 ); + eval.data = !!wanted->rx; err =send_ioctl (ctx, &eval); -if (err) { +if (err)perror ("Cannot set device rx csum settings" ); -return 84 ; - } +else + changed =1 ; } -if (off_csum_tx_wanted >=0 ) { - changed =1 ; +if (wanted->tx >=0 ) { eval.cmd =ETHTOOL_STXCSUM ; - eval.data = (off_csum_tx_wanted ==1 ); + eval.data = !!wanted->tx; err =send_ioctl (ctx, &eval); -if (err) { +if (err)perror ("Cannot set device tx csum settings" ); -return 85 ; - } +else + changed =1 ; } -if (off_sg_wanted >=0 ) { - changed =1 ; +if (wanted->sg >=0 ) { eval.cmd =ETHTOOL_SSG ; - eval.data = (off_sg_wanted ==1 ); + eval.data = !!wanted->sg; err =send_ioctl (ctx, &eval); -if (err) { +if (err)perror ("Cannot set device scatter-gather settings" ); -return 86 ; - } +else + changed =1 ; } -if (off_tso_wanted >=0 ) { - changed =1 ; +if (wanted->tso >=0 ) { eval.cmd =ETHTOOL_STSO ; - eval.data = (off_tso_wanted ==1 ); + eval.data = !!wanted->tso; err =send_ioctl (ctx, &eval); -if (err) { +if (err)perror ("Cannot set device tcp segmentation offload settings" ); -return 88 ; - } +else + changed =1 ; } -if (off_ufo_wanted >=0 ) { - changed =1 ; +if (wanted->ufo >=0 ) { eval.cmd =ETHTOOL_SUFO ; - eval.data = (off_ufo_wanted ==1 ); + eval.data = !!wanted->ufo; err =send_ioctl (ctx, &eval); -if (err) { +if (err)perror ("Cannot set device udp large send offload settings" ); -return 89 ; - } +else + changed =1 ; } -if (off_gso_wanted >=0 ) { - changed =1 ; +if (wanted->gso >=0 ) { eval.cmd =ETHTOOL_SGSO ; - eval.data = (off_gso_wanted ==1 ); + eval.data = !!wanted->gso; err =send_ioctl (ctx, &eval); -if (err) { +if (err)perror ("Cannot set device generic segmentation offload settings" ); -return 90 ; - } +else + changed =1 ; }if (off_flags_mask) { - changed =1 ; eval.cmd =ETHTOOL_GFLAGS ; eval.data =0 ; err =send_ioctl (ctx, &eval); -if (err) { +if (err)perror ("Cannot get device flag settings" ); -return 91 ; - } - - eval.cmd =ETHTOOL_SFLAGS ; - eval.data = ((eval.data & ~off_flags_mask) | - off_flags_wanted); - - err =send_ioctl (ctx, &eval); -if (err) { -perror ("Cannot set device flag settings" ); -return 92 ; +else { + eval.cmd =ETHTOOL_SFLAGS ; + eval.data = ((eval.data & ~off_flags_mask) | + off_flags_wanted); + + err =send_ioctl (ctx, &eval); +if (err) +perror ("Cannot set device flag settings" ); +else + changed =1 ; } } -if (off_gro_wanted >=0 ) { - changed =1 ; +if (wanted->gro >=0 ) { eval.cmd =ETHTOOL_SGRO ; - eval.data = (off_gro_wanted ==1 ); + eval.data = !!wanted->gro; err =send_ioctl (ctx, &eval); -if (err) { +if (err)perror ("Cannot set device GRO settings" ); -return 93 ; +else + changed =1 ; + } + +return changed; +} + +static int n_feature_strings; +static const char **feature_strings; + +static int init_feature_strings (struct cmd_context *ctx) +{ +struct ethtool_gstrings *strings; +int i, n; + +if (feature_strings) +return n_feature_strings; + + strings =get_stringset (ctx,ETH_SS_FEATURES ,0 ); +if (!strings) +return -100 ; + + n = n_feature_strings = strings->len; + feature_strings =calloc (n,sizeof (*feature_strings)); +if (!feature_strings) { +fprintf (stderr,"no memory available for string table [size=%d]\n" , n); +exit (95 ); + } + +for (i =0 ; i < n; ++i) { +if (!strings->data[i*ETH_GSTRING_LEN ]) +continue ; + + feature_strings[i] =strndup ( + (const char *)&strings->data[i *ETH_GSTRING_LEN ], +ETH_GSTRING_LEN ); + +if (!feature_strings[i]) { +fprintf (stderr,"no memory available for a string\n" ); +exit (95 ); } } +free (strings); +return n; +} + +static void parse_sfeatures_args (struct cmd_context *ctx, +struct offload_state *offload, +struct ethtool_sfeatures **features_req_p) +{ +struct ethtool_sfeatures *features_req; +struct cmdline_info *cmdline_desc, *cp; +int sz_features, i; +int changed =0 ; + +struct cmdline_info cmdline_offload[] = { + {"rx" ,CMDL_BOOL , &offload->rx,NULL }, + {"tx" ,CMDL_BOOL , &offload->tx,NULL }, + {"sg" ,CMDL_BOOL , &offload->sg,NULL }, + {"tso" ,CMDL_BOOL , &offload->tso,NULL }, + {"ufo" ,CMDL_BOOL , &offload->ufo,NULL }, + {"gso" ,CMDL_BOOL , &offload->gso,NULL }, + {"lro" ,CMDL_BOOL , &offload->lro,NULL }, + {"gro" ,CMDL_BOOL , &offload->gro,NULL }, + {"rxvlan" ,CMDL_BOOL , &offload->rxvlan,NULL }, + {"txvlan" ,CMDL_BOOL , &offload->txvlan,NULL }, + {"ntuple" ,CMDL_BOOL , &offload->ntuple,NULL }, + {"rxhash" ,CMDL_BOOL , &offload->rxhash,NULL }, + }; + +for (i =0 ; i <ARRAY_SIZE (old_feature_names); ++i) + ((int *)offload)[i] =-1 ; + *features_req_p =NULL ; + +if (init_feature_strings (ctx) <0 ) { +/* ETHTOOL_GFEATURES unavailable */ +parse_generic_cmdline (ctx, &changed, + cmdline_offload,ARRAY_SIZE (cmdline_offload)); +return ; + } + + sz_features =sizeof (*features_req->features) * ((n_feature_strings +31 ) /32 ); + + cp = cmdline_desc =calloc (n_feature_strings +ARRAY_SIZE (cmdline_offload), +sizeof (*cmdline_desc)); +memcpy (cp, cmdline_offload,sizeof (cmdline_offload)); + cp +=ARRAY_SIZE (cmdline_offload); + + features_req =calloc (1 ,sizeof (*features_req) + sz_features); +if (!cmdline_desc || !features_req) { +fprintf (stderr,"no memory available\n" ); +exit (95 ); + } + + features_req->size = (n_feature_strings +31 ) /32 ; + +for (i =0 ; i < n_feature_strings; ++i) { +if (!feature_strings[i]) +continue ; + + cp->name = feature_strings[i]; + cp->type =CMDL_FLAG ; + cp->flag_val =1 << (i %32 ); + cp->wanted_val = &features_req->features[i /32 ].requested; + cp->seen_val = &features_req->features[i /32 ].valid; + ++cp; + } + +parse_generic_cmdline (ctx, &changed, cmdline_desc, cp - cmdline_desc); + +free (cmdline_desc); + +if (changed) + *features_req_p = features_req; +else +free (features_req); +} + +static int send_gfeatures (struct cmd_context *ctx, +struct ethtool_gfeatures **features_p) +{ +struct ethtool_gfeatures *features; +int err, sz_features; + + sz_features =sizeof (*features->features) * ((n_feature_strings +31 ) /32 ); + features =calloc (1 , sz_features +sizeof (*features)); +if (!features) { +fprintf (stderr,"no memory available\n" ); +return 95 ; + } + + features->cmd =ETHTOOL_GFEATURES ; + features->size = (n_feature_strings +31 ) /32 ; + err =send_ioctl (ctx, features); + +if (err <0 ) { +perror ("Cannot get feature status" ); +free (features); +return 97 ; + } + + *features_p = features; +return 0 ; +} + +static const char *get_feature_state (struct ethtool_get_features_block *gfb, +uint32_t bit) +{ +if (gfb->never_changed & bit) +return "fixed" ; +if (!(gfb->available & bit)) +return "driver-controlled" ; + +if ((gfb->active ^ gfb->requested) & bit) +return (gfb->requested & bit) ?"requested on" :"requested off" ; +else +return "changeable" ; +} + +static int do_gfeatures (struct cmd_context *ctx) +{ +struct ethtool_get_features_block *gfb; +struct ethtool_gfeatures *features; +uint32_t bit; +int err, i; + + err =init_feature_strings (ctx); +if (err <0 ) +return -err; + + err =send_gfeatures (ctx, &features); +if (err) +return err; + +fprintf (stdout,"\nExtended offload state for %s:\n" , ctx->devname); +for (i =0 ; i < n_feature_strings; i++) { +if (!feature_strings[i]) +continue ;/* empty */ + + gfb = features->features + i /32 ; + bit =1 << (i %32 ); + +fprintf (stdout,"%s: %s (%s)\n" , feature_strings[i], + (gfb->active & bit) ?"on" :"off" , +get_feature_state (gfb, bit)); + } +free (features); + +return 0 ; +} + +static void print_gfeatures_diff ( +const struct ethtool_get_features_block *expected, +const struct ethtool_get_features_block *set, +const char **strings,int n_strings) +{ +int i; + +if (n_strings >32 ) + n_strings =32 ; + +for (i =0 ; i < n_strings; ++i) { +u32 mask =1 << i; + +if (!strings[i]) +continue ; + +if (!((expected->active ^ set->active) & mask)) +continue ; + +fprintf (stdout,"feature %.*s is %s (expected: %s, saved: %s)\n" , +ETH_GSTRING_LEN , strings[i], + set->active & mask ?"enabled" :"disabled" , + expected->active & mask ?"enabled" :"disabled" , + !(set->available & mask) ?"not user-changeable" : + set->requested & mask ?"enabled" :"disabled" + ); + } +} + +static int get_offload_state (struct cmd_context *ctx, +struct ethtool_gfeatures **features, +struct offload_state *offload) +{ +int err, allfail; + +if (ctx->argc !=0 ) +exit_bad_args (); + + allfail =send_goffloads (ctx, offload); + + err =init_feature_strings (ctx); +if (err <0 ) +return allfail ? err :0 ; + + err =send_gfeatures (ctx, features); +if (err) +perror ("Cannot read features" ); + +return allfail ? -err :0 ; +} + +static int send_sfeatures (struct cmd_context *ctx, +struct ethtool_sfeatures *features) +{ +int err; + + features->cmd =ETHTOOL_SFEATURES ; + err =send_ioctl (ctx, features); +if (err <0 ) { +perror ("Cannot change features" ); +return 97 ; + } + +return 0 ; +} + +static void compare_offload_state (struct offload_state *offload0, +struct offload_state *offload_req,struct offload_state *offload1) +{ +int *old = (int *)offload0; +int *req = (int *)offload_req; +int *new = (int *)offload1; +int i; + +for (i =0 ; i <ARRAY_SIZE (old_feature_names); i++) { +if (req[i] <0 ) + req[i] = old[i]; +if (req[i] == new[i]) +continue ; + +fprintf (stdout,"feature group %s is %s (expected: %s)\n" , + old_feature_names[i], + new[i] ?"enabled" :"disabled" , + req[i] ?"enabled" :"disabled" + ); + } +} + +static void compare_features (struct ethtool_gfeatures *features0, +struct ethtool_sfeatures *features_req, +struct ethtool_gfeatures *features1) +{ +int i; + +if (features_req) { +/* make features0 .active what we expect to be set */ + i = (n_feature_strings +31 ) /32 ; +while (i--) { + features0->features[i].active &= ~features_req->features[i].valid; + features0->features[i].active |= + features_req->features[i].requested & + features_req->features[i].valid; + } + } + +for (i =0 ; i < n_feature_strings; i +=32 ) +print_gfeatures_diff (&features0->features[i /32 ], + &features1->features[i /32 ], + feature_strings + i, + n_feature_strings - i); +} + +static int do_goffload (struct cmd_context *ctx) +{ +struct offload_state offload; +int err, allfail; + + allfail =send_goffloads (ctx, &offload); + +if (!allfail) { +fprintf (stdout,"Offload parameters for %s:\n" , ctx->devname); + +dump_offload (&offload); + } + + err =do_gfeatures (ctx); +if (!err) + allfail =0 ; + +if (allfail) { +fprintf (stdout,"no offload info available\n" ); +return 83 ; + } + +return 0 ; +} + +static int do_soffload (struct cmd_context *ctx) +{ +struct ethtool_gfeatures *features_old, *features_new; +struct ethtool_sfeatures *features_req; +struct offload_state offload_old, offload_new, offload_req; +int err, changed; + +parse_sfeatures_args (ctx, &offload_req, &features_req); + + err =get_offload_state (ctx, &features_old, &offload_old); +if (err) +return -err; + + changed =send_soffloads (ctx, &offload_req); + +if (features_req) { + err =send_sfeatures (ctx, features_req); +if (!err) + changed =1 ; + } +if (!changed) {fprintf (stdout,"no offload settings changed\n" ); +return err; + } + + err =get_offload_state (ctx, &features_new, &offload_new); +if (err) { +perror ("can't verify offload setting" ); +return 101 ; + } + +if ((!features_old) ^ (!features_new)) { +fprintf (stderr,"can't compare features (one GFEATURES failed)\n" ); +if (features_old) { +free (features_old); + features_old =NULL ; + } +if (features_new) { +free (features_new); + features_new =NULL ; + } + } + +compare_offload_state (&offload_old, &offload_req, &offload_new); +if (features_old) { +compare_features (features_old, features_req, features_new); +free (features_old); +free (features_new); } +if (features_req) +free (features_req);return 0 ; }
Signature · 1 line
1.7.8.3
Re: [RFC PATCH v2] ethtool: implement [GS]FEATURES handling
Quoted 6 lines · Michał Mirosław
v2: fix missing change
CMDL_FLAG->CMDL_BOOLfor old offloads parsingSigned-off-by Michał Mirosław <[email protected]>--- ethtool.c | 613 ++++++++++++++++++++++++++++++++++++++++++++++++------------ 1 files changed, 490 insertions(+), 123 deletions(-)
Seems fine to me, here is the result for the new section :
I can now 'see' my tg3 doesnt support tx-tcp6-segmentation without having to read driver source...
Extended offload state for eth3:
tx-scatter-gather: on (changeable)
tx-checksum-ipv4: on (changeable)
tx-checksum-ip-generic: off (driver-controlled)
tx-checksum-ipv6: off (driver-controlled)
highdma: on (changeable) tx-scatter-gather-fraglist: off (driver-controlled)
tx-vlan-hw-insert: on (changeable)
rx-vlan-hw-parse: on (changeable)
rx-vlan-filter: off (driver-controlled)
vlan-challenged: off (fixed)
tx-generic-segmentation: on (changeable)
tx-lockless: off (fixed)
netns-local: off (fixed)
rx-gro: on (changeable)
rx-lro: off (driver-controlled)
tx-tcp-segmentation: on (changeable)
tx-udp-fragmentation: off (driver-controlled)
tx-gso-robust: off (driver-controlled)
tx-tcp-ecn-segmentation: off (driver-controlled)
tx-tcp6-segmentation: off (driver-controlled)
tx-fcoe-segmentation: off (driver-controlled)
tx-checksum-fcoe-crc: off (driver-controlled)
tx-checksum-sctp: off (driver-controlled)
fcoe-mtu: off (driver-controlled)
rx-ntuple-filter: off (driver-controlled)
rx-hashing: off (driver-controlled)
rx-checksum: on (changeable)
tx-nocache-copy: on (changeable)
loopback: off (changeable)
Thanks !