net: Unified offload configuration
Subsystems (3)
v3 cover net: Unified offload configuration
Here's a next version 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 pseudodevice 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 - I'll resend them Cc'ing their maintainters after the core interfaces get accepted.
Best Regards,
Michał Mirosław
---
v1: http://marc.info/?l=linux-netdev&m=129245188832643&w=3
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 | 87 ++++++++- include/linux/netdevice.h | 47 +++++- net/core/dev.c | 47 ++++- net/core/ethtool.c | 472 ++++++++++++++++++++++++++++----------------- 5 files changed, 469 insertions(+), 193 deletions(-)
Signature · 1 line
1.7.2.3
PATCH v3 1/5 net: Introduce new feature setting ops
This 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 | 86 +++++++++++++++++++++++++ include/linux/netdevice.h | 44 ++++++++++++- net/core/dev.c | 47 ++++++++++++-- net/core/ethtool.c | 154 +++++++++++++++++++++++++++++++++++++++++---- 4 files changed, 312 insertions(+), 19 deletions(-)
include/linux/ethtool.h +86 -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,88 @@ 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 +* @avaliable: mask of changeable features +* @requested: mask of features requested to be enabled if possible +* @active: mask of currently enabled features +* @never_changed: mask of never-changeable features +*/ +struct ethtool_get_features_block { +__u32 available;/* features togglable */ +__u32 requested;/* features requested to be enabled */ +__u32 active;/* features currently enabled */ +__u32 never_changed;/* never-changeable features */ +}; + +/** +* struct ethtool_gfeatures - command to get state of device's features +* @cmd: command number = %ETHTOOL_GFEATURES +* @size: in: array size of the features[] array +* out: count of features[] elements filled +* @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;/* bits valid in .requested */ +__u32 requested;/* features 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 ,/* .valid had unsupported bits set */ +ETHTOOL_F_WISH__BIT ,/* resulting device features state in +* .valid is not equal to .requested */ +}; + +#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 +827,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 +42 -2
92 lines not on this page · raw message
net/core/dev.c +42 -5
65 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
Re: [PATCH v3 1/5] net: Introduce new feature setting ops
Quoted 37 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)Signed-off-by Michał Mirosław <[email protected]>--- include/linux/ethtool.h | 86 +++++++++++++++++++++++++ include/linux/netdevice.h | 44 ++++++++++++- net/core/dev.c | 47 ++++++++++++-- net/core/ethtool.c | 154 +++++++++++++++++++++++++++++++++++++++++---- 4 files changed, 312 insertions(+), 19 deletions(-)include/linux/ethtool.h +1
-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 */
include/linux/ethtool.h struct ethtool_flash { · line 531
Quoted 8 lines
include/linux/ethtool.h +5
-0@@ -523,6 +524,88 @@ 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 +* @avaliable: mask of changeable features
Typo, should be @available.
include/linux/ethtool.h struct ethtool_flash { · line 534
Quoted 3 lines
include/linux/ethtool.h +3
-0+* @requested: mask of features requested to be enabled if possible +* @active: mask of currently enabled features +* @never_changed: mask of never-changeable features
I don't think the description of never_changed is clear enough. It should be described as something like:
Mask of feature flags that are not changeable for any device.
include/linux/ethtool.h struct ethtool_flash { · line 540
Quoted 6 lines
include/linux/ethtool.h +6
-0+*/ +struct ethtool_get_features_block { +__u32 available;/* features togglable */ +__u32 requested;/* features requested to be enabled */ +__u32 active;/* features currently enabled */ +__u32 never_changed;/* never-changeable features */
Don't comment the fields inline as well as in the kernel-doc.
include/linux/ethtool.h struct ethtool_flash { · line 547
Quoted 7 lines
include/linux/ethtool.h +7
-0+}; + +/** +* struct ethtool_gfeatures - command to get state of device's features +* @cmd: command number = %ETHTOOL_GFEATURES +* @size: in: array size of the features[] array +* out: count of features[] elements filled
The value on output should be the size required to read all features, so that the caller can discover it easily.
The two lines describing 'size' will be wrapped together when converted to another format (manual page, HTML...). You need to use at least a full stop (period) to separate them.
[...]
include/linux/netdevice.h struct netdev_tc_txq { · line 789
Quoted 12 lines
include/linux/netdevice.h +4
-0@@ -783,6 +783,16 @@ struct netdev_tc_txq {* Set hardware filter for RFS. rxq_index is the target queue index; * flow_id is a flow ID to be passed to rps_may_expire_flow() later. * Return the filter ID on success, or a negative error code. +* +* u32 (*ndo_fix_features)(struct net_device *dev, u32 features); +* Modifies features supported by device depending on device-specific +* constraints. Should not modify hardware state.
I don't think this wording is clear enough. How about:
Adjusts the requested feature flags according to device-specific constraints, and returns the resulting flags. Must not modify the device state.
[...]
include/linux/netdevice.h struct net_device { · line 980
Quoted 8 lines
include/linux/netdevice.h +4
-0@@ -954,6 +974,12 @@ struct net_device {#define NETIF_F_TSO6 (SKB_GSO_TCPV6 << NETIF_F_GSO_SHIFT)#define NETIF_F_FSO (SKB_GSO_FCOE << NETIF_F_GSO_SHIFT) +/* Features valid for ethtool to change */ +/* = all defined minus driver/device-class-related */ +#define NETIF_F_NEVER_CHANGE (NETIF_F_VLAN_CHALLENGED | \ + NETIF_F_LLTX | NETIF_F_NETNS_LOCAL)
Shouldn't NETIF_F_NO_CSUM and NETIF_F_HIGHDMA be included in this? (And excluded from NETIF_F_ALL_TX_OFFLOADS.)
Quoted 18 lines
include/linux/netdevice.h +8
-0+#define NETIF_F_ETHTOOL_BITS (0x1f3fffff & ~NETIF_F_NEVER_CHANGE) +/* List of features with software fallbacks. */ #define NETIF_F_GSO_SOFTWARE (NETIF_F_TSO | NETIF_F_TSO_ECN | \ NETIF_F_TSO6 | NETIF_F_UFO)@@ -964,6 +990,12 @@ struct net_device {#define NETIF_F_V6_CSUM (NETIF_F_GEN_CSUM | NETIF_F_IPV6_CSUM)#define NETIF_F_ALL_CSUM (NETIF_F_V4_CSUM | NETIF_F_V6_CSUM) +#define NETIF_F_ALL_TSO (NETIF_F_TSO | NETIF_F_TSO6 | NETIF_F_TSO_ECN) + +#define NETIF_F_ALL_TX_OFFLOADS (NETIF_F_ALL_CSUM | NETIF_F_SG | \ + NETIF_F_FRAGLIST | NETIF_F_ALL_TSO | \ + NETIF_F_SCTP_CSUM | NETIF_F_FCOE_CRC) +/* * If one device supports one of these features, then enable them * for all in netdev_increment_features.
[...]
Quoted 4 lines
net/core/dev.c +0
-0
[...]
Quoted 20 lines
net/core/dev.c +16
-0@@ -5267,6 +5273,35 @@ u32 netdev_fix_features(struct net_device *dev, u32 features) }EXPORT_SYMBOL (netdev_fix_features); +void netdev_update_features (struct net_device *dev) +{ +u32 features; +int err =0 ; + + features =netdev_get_wanted_features (dev); + +if (dev->netdev_ops->ndo_fix_features) + features = dev->netdev_ops->ndo_fix_features (dev, features); + +/* driver might be less strict about feature dependencies */ + features =netdev_fix_features (dev, features); + +if (dev->features == features) +return ; +
net/core/dev.c u32 netdev_fix_features(struct net_device *dev, u32 features) · line 5301
Quoted 10 lines
net/core/dev.c +10
-0+netdev_info (dev,"Features changed: 0x%08x -> 0x%08x\n" , + dev->features, features); + +if (dev->netdev_ops->ndo_set_features) + err = dev->netdev_ops->ndo_set_features (dev, features); + +if (!err) + dev->features = features; +else if (err <0 ) +netdev_err (dev,"set_features() failed (%d)\n" , err);
The error message should include the feature flags passed, since the previous informational message may be filtered out.
Quoted 6 lines
net/core/dev.c +3
-0+} +EXPORT_SYMBOL (netdev_update_features); +/** * netif_stacked_transfer_operstate - transfer operstate * @rootdev: the root or lower level device to transfer state from
[...]
Quoted 31 lines
net/core/ethtool.c +16
-0@@ -55,6 +55,7 @@ int ethtool_op_set_tx_csum(struct net_device *dev, u32 data)return 0 ; } +EXPORT_SYMBOL (ethtool_op_set_tx_csum);int ethtool_op_set_tx_hw_csum (struct net_device *dev,u32 data) {@@ -171,6 +172,136 @@ EXPORT_SYMBOL(ethtool_ntuple_flush);/* Handlers for each ethtool command */ +#define ETHTOOL_DEV_FEATURE_WORDS 1 + +static int ethtool_get_features (struct net_device *dev,void __user *useraddr) +{ +struct ethtool_gfeatures cmd = { + .cmd =ETHTOOL_GFEATURES , + .size =ETHTOOL_DEV_FEATURE_WORDS , + }; +struct ethtool_get_features_block features[ETHTOOL_DEV_FEATURE_WORDS ] = { + { + .available = dev->hw_features, + .requested = dev->wanted_features, + .active = dev->features, + .never_changed =NETIF_F_NEVER_CHANGE , + },
net/core/ethtool.c EXPORT_SYMBOL(ethtool_ntuple_flush); · line 199
Quoted 10 lines
net/core/ethtool.c +10
-0+ }; +u32 __user *sizeaddr; +u32 in_size; + + sizeaddr = useraddr + offsetof(struct ethtool_gfeatures , size); +if (get_user (in_size, sizeaddr)) +return -EFAULT ; + +if (in_size <ETHTOOL_DEV_FEATURE_WORDS ) +return -EINVAL ;
I don't think this should be considered invalid. Instead:
u32 copy_size; ... copy_size = min_t(u32, in_size, ETHTOOL_DEV_FEATURE_WORDS);
net/core/ethtool.c EXPORT_SYMBOL(ethtool_ntuple_flush); · line 204
Quoted 4 lines
net/core/ethtool.c +4
-0+if (copy_to_user (useraddr, &cmd,sizeof (cmd))) +return -EFAULT ; + useraddr +=sizeof (cmd); +if (copy_to_user (useraddr, features,sizeof (features)))
and:
if (copy_to_user(useraddr, features, copy_size * sizeof(features[0]))
[...]
net/core/ethtool.c EXPORT_SYMBOL(ethtool_ntuple_flush); · line 244
Quoted 2 lines
net/core/ethtool.c +2
-0+static const char netdev_features_strings[ETHTOOL_DEV_FEATURE_WORDS *32 ][ETH_GSTRING_LEN ] = { +/* NETIF_F_SG */ "scatter-gather" ,
SG really means TX DMA gather only, as the driver is responsible for allocating its own RX buffers.
net/core/ethtool.c EXPORT_SYMBOL(ethtool_ntuple_flush); · line 255
Quoted 11 lines
net/core/ethtool.c +11
-0+/* NETIF_F_IP_CSUM */ "tx-checksum-hw-ipv4" , +/* NETIF_F_NO_CSUM */ "tx-checksum-local" , +/* NETIF_F_HW_CSUM */ "tx-checksum-hw-ip-generic" , +/* NETIF_F_IPV6_CSUM */ "tx_checksum-hw-ipv6" , +/* NETIF_F_HIGHDMA */ "highdma" , +/* NETIF_F_FRAGLIST */ "scatter-gather-fraglist" , +/* NETIF_F_HW_VLAN_TX */ "tx-vlan-hw" , + +/* NETIF_F_HW_VLAN_RX */ "rx-vlan-hw" , +/* NETIF_F_HW_VLAN_FILTER */ "rx-vlan-filter" , + /* NETIF_F_VLAN_CHALLENGED */ "*vlan-challenged",
Don't mark the unchangeable features specially here; that can be done by userland. Actually, I wonder whether they really need descriptions at all.
Quoted 9 lines
net/core/ethtool.c +9
-0+/* NETIF_F_GSO */ "generic-segmentation-offload" , +/* NETIF_F_LLTX */ "*lockless-tx" , +/* NETIF_F_NETNS_LOCAL */ "*netns-local" , +/* NETIF_F_GRO */ "generic-receive-offload" , +/* NETIF_F_LRO */ "large-receive-offload" , + +/* NETIF_F_TSO */ "tcp-segmentation-offload" , +/* NETIF_F_UFO */ "udp-fragmentation-offload" , + /* NETIF_F_GSO_ROBUST */ "gso-robust",
net/core/ethtool.c EXPORT_SYMBOL(ethtool_ntuple_flush); · line 274
Quoted 10 lines
net/core/ethtool.c +10
-0+/* NETIF_F_TSO_ECN */ "tcp-ecn-segmentation-offload" , +/* NETIF_F_TSO6 */ "ipv6-tcp-segmentation-offload" , +/* NETIF_F_FSO */ "fcoe-segmentation-offload" , +"" , +"" , + +/* NETIF_F_FCOE_CRC */ "tx-checksum-fcoe-crc" , +/* NETIF_F_SCTP_CSUM */ "tx-checksum-sctp" , +/* NETIF_F_FCOE_MTU */ "fcoe-mtu" , + /* NETIF_F_NTUPLE */ "ntuple-filter",
[...]
I think this should be named 'rx-ntuple-filter'. TX filtering may be controlled for related devices (VFs) and is completely separate from this.
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 v3 1/5] net: Introduce new feature setting ops
Quoted 41 lines · Ben Hutchings
Quoted 40 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)Signed-off-by Michał Mirosław <[email protected]>--- include/linux/ethtool.h | 86 +++++++++++++++++++++++++ include/linux/netdevice.h | 44 ++++++++++++- net/core/dev.c | 47 ++++++++++++-- net/core/ethtool.c | 154 +++++++++++++++++++++++++++++++++++++++++---- 4 files changed, 312 insertions(+), 19 deletions(-)include/linux/ethtool.h +1
-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,88 @@ struct ethtool_flash {char data[ETHTOOL_FLASH_MAX_FILENAME ]; };
Quoted 6 lines
include/linux/ethtool.h struct ethtool_flash { · line 531
Quoted 5 lines
include/linux/ethtool.h +5
-0+/* for returning and changing feature sets */ + +/** +* struct ethtool_get_features_block - block with state of 32 features +* @avaliable: mask of changeable features Typo, should be @available.
Fixed.
Quoted 7 lines
include/linux/ethtool.h struct ethtool_flash { · line 534
Quoted 3 lines
include/linux/ethtool.h +3
-0+* @requested: mask of features requested to be enabled if possible +* @active: mask of currently enabled features +* @never_changed: mask of never-changeable features I don't think the description of
never_changedis clear enough. It should be described as something like:
Mask of feature flags that are not changeable for any device.
Fixed. I shortened the text a bit.
Quoted 8 lines
include/linux/ethtool.h struct ethtool_flash { · line 540
Quoted 6 lines
include/linux/ethtool.h +6
-0+*/ +struct ethtool_get_features_block { +__u32 available;/* features togglable */ +__u32 requested;/* features requested to be enabled */ +__u32 active;/* features currently enabled */ +__u32 never_changed;/* never-changeable features */ Don't comment the fields inline as well as in the kernel-doc.
Removed this and other occurrences.
Quoted 11 lines
include/linux/ethtool.h struct ethtool_flash { · line 547
Quoted 7 lines
include/linux/ethtool.h +7
-0+}; + +/** +* struct ethtool_gfeatures - command to get state of device's features +* @cmd: command number = %ETHTOOL_GFEATURES +* @size: in: array size of the features[] array +* out: count of features[] elements filled The value on output should be the size required to read all features, so that the caller can discover it easily.
Quoted 3 lines
The two lines describing 'size' will be wrapped together when converted to another format (manual page, HTML...). You need to use at least a full stop (period) to separate them.
Fixed. Anyway, userspace should use GSSET_INFO/SS_FEATURES for this.
Quoted 16 lines
[...]
include/linux/netdevice.h struct netdev_tc_txq { · line 789
Quoted 12 lines
include/linux/netdevice.h +4
-0@@ -783,6 +783,16 @@ struct netdev_tc_txq {* Set hardware filter for RFS. rxq_index is the target queue index; * flow_id is a flow ID to be passed to rps_may_expire_flow() later. * Return the filter ID on success, or a negative error code. +* +* u32 (*ndo_fix_features)(struct net_device *dev, u32 features); +* Modifies features supported by device depending on device-specific +* constraints. Should not modify hardware state. I don't think this wording is clear enough. How about:
Quoted 3 lines
Adjusts the requested feature flags according to device-specific constraints, and returns the resulting flags. Must not modify the device state.
I like your version better, too. I also updated ndo_set_features() description.
Quoted 5 lines
[...]
Quoted 4 lines
include/linux/netdevice.h +0
-0@@ -954,6 +974,12 @@ struct net_device {#define NETIF_F_TSO6 (SKB_GSO_TCPV6 << NETIF_F_GSO_SHIFT)#define NETIF_F_FSO (SKB_GSO_FCOE << NETIF_F_GSO_SHIFT)
Quoted 7 lines
include/linux/netdevice.h struct net_device { · line 980
Quoted 4 lines
include/linux/netdevice.h +4
-0+/* Features valid for ethtool to change */ +/* = all defined minus driver/device-class-related */ +#define NETIF_F_NEVER_CHANGE (NETIF_F_VLAN_CHALLENGED | \ + NETIF_F_LLTX | NETIF_F_NETNS_LOCAL)Shouldn't
NETIF_F_NO_CSUMandNETIF_F_HIGHDMAbe included in this? (And excluded fromNETIF_F_ALL_TX_OFFLOADS.)
NETIF_F_HIGHDMA added. NO_CSUM can be changed for some software devices like bridge or bond.
Quoted 49 lines
Quoted 18 lines
include/linux/netdevice.h +8
-0+#define NETIF_F_ETHTOOL_BITS (0x1f3fffff & ~NETIF_F_NEVER_CHANGE) +/* List of features with software fallbacks. */ #define NETIF_F_GSO_SOFTWARE (NETIF_F_TSO | NETIF_F_TSO_ECN | \ NETIF_F_TSO6 | NETIF_F_UFO)@@ -964,6 +990,12 @@ struct net_device {#define NETIF_F_V6_CSUM (NETIF_F_GEN_CSUM | NETIF_F_IPV6_CSUM)#define NETIF_F_ALL_CSUM (NETIF_F_V4_CSUM | NETIF_F_V6_CSUM) +#define NETIF_F_ALL_TSO (NETIF_F_TSO | NETIF_F_TSO6 | NETIF_F_TSO_ECN) + +#define NETIF_F_ALL_TX_OFFLOADS (NETIF_F_ALL_CSUM | NETIF_F_SG | \ + NETIF_F_FRAGLIST | NETIF_F_ALL_TSO | \ + NETIF_F_SCTP_CSUM | NETIF_F_FCOE_CRC) +/* * If one device supports one of these features, then enable them * for all in netdev_increment_features. [...]
Quoted 4 lines
net/core/dev.c +0
-0[...]
Quoted 25 lines
net/core/dev.c +21
-0@@ -5267,6 +5273,35 @@ u32 netdev_fix_features(struct net_device *dev, u32 features) }EXPORT_SYMBOL (netdev_fix_features); +void netdev_update_features (struct net_device *dev) +{ +u32 features; +int err =0 ; + + features =netdev_get_wanted_features (dev); + +if (dev->netdev_ops->ndo_fix_features) + features = dev->netdev_ops->ndo_fix_features (dev, features); + +/* driver might be less strict about feature dependencies */ + features =netdev_fix_features (dev, features); + +if (dev->features == features) +return ; + +netdev_info (dev,"Features changed: 0x%08x -> 0x%08x\n" , + dev->features, features); + +if (dev->netdev_ops->ndo_set_features) + err = dev->netdev_ops->ndo_set_features (dev, features);
Quoted 8 lines
net/core/dev.c u32 netdev_fix_features(struct net_device *dev, u32 features) · line 5301
Quoted 5 lines
net/core/dev.c +5
-0+ +if (!err) + dev->features = features; +else if (err <0 ) +netdev_err (dev,"set_features() failed (%d)\n" , err);The error message should include the feature flags passed, since the previous informational message may be filtered out.
Fixed. This will make checkpatch.pl complain about long line, but I don't want to split the message's text as it'd be hard to grep for it then.
Quoted 54 lines
Quoted 6 lines
net/core/dev.c +3
-0+} +EXPORT_SYMBOL (netdev_update_features); +/** * netif_stacked_transfer_operstate - transfer operstate * @rootdev: the root or lower level device to transfer state from [...]
Quoted 31 lines
net/core/ethtool.c +16
-0@@ -55,6 +55,7 @@ int ethtool_op_set_tx_csum(struct net_device *dev, u32 data)return 0 ; } +EXPORT_SYMBOL (ethtool_op_set_tx_csum);int ethtool_op_set_tx_hw_csum (struct net_device *dev,u32 data) {@@ -171,6 +172,136 @@ EXPORT_SYMBOL(ethtool_ntuple_flush);/* Handlers for each ethtool command */ +#define ETHTOOL_DEV_FEATURE_WORDS 1 + +static int ethtool_get_features (struct net_device *dev,void __user *useraddr) +{ +struct ethtool_gfeatures cmd = { + .cmd =ETHTOOL_GFEATURES , + .size =ETHTOOL_DEV_FEATURE_WORDS , + }; +struct ethtool_get_features_block features[ETHTOOL_DEV_FEATURE_WORDS ] = { + { + .available = dev->hw_features, + .requested = dev->wanted_features, + .active = dev->features, + .never_changed =NETIF_F_NEVER_CHANGE , + },net/core/ethtool.c EXPORT_SYMBOL(ethtool_ntuple_flush); · line 199
Quoted 10 lines
net/core/ethtool.c +10
-0+ }; +u32 __user *sizeaddr; +u32 in_size; + + sizeaddr = useraddr + offsetof(struct ethtool_gfeatures , size); +if (get_user (in_size, sizeaddr)) +return -EFAULT ; + +if (in_size <ETHTOOL_DEV_FEATURE_WORDS ) +return -EINVAL ;I don't think this should be considered invalid. Instead:
u32 copy_size; ... copy_size = min_t(u32, in_size, ETHTOOL_DEV_FEATURE_WORDS);
Quoted 7 lines
net/core/ethtool.c EXPORT_SYMBOL(ethtool_ntuple_flush); · line 204
Quoted 4 lines
net/core/ethtool.c +4
-0+if (copy_to_user (useraddr, &cmd,sizeof (cmd))) +return -EFAULT ; + useraddr +=sizeof (cmd); +if (copy_to_user (useraddr, features,sizeof (features)))and:
if (copy_to_user(useraddr, features, copy_size * sizeof(features[0]))
Fixed to equivalent code but without additional variable.
Quoted 5 lines
[...]
net/core/ethtool.c EXPORT_SYMBOL(ethtool_ntuple_flush); · line 244
Quoted 2 lines
net/core/ethtool.c +2
-0+static const char netdev_features_strings[ETHTOOL_DEV_FEATURE_WORDS *32 ][ETH_GSTRING_LEN ] = { +/* NETIF_F_SG */ "scatter-gather" ,SG really means TX DMA gather only, as the driver is responsible for allocating its own RX buffers.
I changed this and other feature strings to prefix them with "tx-" or "rx-" as apropriate.
Quoted 6 lines
Quoted 6 lines
net/core/ethtool.c +6
-0+/* NETIF_F_IP_CSUM */ "tx-checksum-hw-ipv4" , +/* NETIF_F_NO_CSUM */ "tx-checksum-local" , +/* NETIF_F_HW_CSUM */ "tx-checksum-hw-ip-generic" , +/* NETIF_F_IPV6_CSUM */ "tx_checksum-hw-ipv6" , +/* NETIF_F_HIGHDMA */ "highdma" , + /* NETIF_F_FRAGLIST */ "scatter-gather-fraglist",
Quoted 8 lines
net/core/ethtool.c EXPORT_SYMBOL(ethtool_ntuple_flush); · line 255
Quoted 5 lines
net/core/ethtool.c +5
-0+/* NETIF_F_HW_VLAN_TX */ "tx-vlan-hw" , + +/* NETIF_F_HW_VLAN_RX */ "rx-vlan-hw" , +/* NETIF_F_HW_VLAN_FILTER */ "rx-vlan-filter" , + /* NETIF_F_VLAN_CHALLENGED */ "*vlan-challenged",Don't mark the unchangeable features specially here; that can be done by userland. Actually, I wonder whether they really need descriptions at all.
Removed the markings. I think it's still good to have them for debugging purposes - ethtool can show them then. At least vlan-challenged state is useful information.
Quoted 21 lines
Quoted 19 lines
net/core/ethtool.c +19
-0+/* NETIF_F_GSO */ "generic-segmentation-offload" , +/* NETIF_F_LLTX */ "*lockless-tx" , +/* NETIF_F_NETNS_LOCAL */ "*netns-local" , +/* NETIF_F_GRO */ "generic-receive-offload" , +/* NETIF_F_LRO */ "large-receive-offload" , + +/* NETIF_F_TSO */ "tcp-segmentation-offload" , +/* NETIF_F_UFO */ "udp-fragmentation-offload" , +/* NETIF_F_GSO_ROBUST */ "gso-robust" , +/* NETIF_F_TSO_ECN */ "tcp-ecn-segmentation-offload" , +/* NETIF_F_TSO6 */ "ipv6-tcp-segmentation-offload" , +/* NETIF_F_FSO */ "fcoe-segmentation-offload" , +"" , +"" , + +/* NETIF_F_FCOE_CRC */ "tx-checksum-fcoe-crc" , +/* NETIF_F_SCTP_CSUM */ "tx-checksum-sctp" , +/* NETIF_F_FCOE_MTU */ "fcoe-mtu" , + /* NETIF_F_NTUPLE */ "ntuple-filter",[...]
Quoted 3 lines
I think this should be named 'rx-ntuple-filter'. TX filtering may be controlled for related devices (VFs) and is completely separate from this.
Changed, as above.
Thanks for the review!
Best Regards,
Michał Mirosław
PATCH v3 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 */ "scatter-gather" ,/* NETIF_F_IP_CSUM */ "tx-checksum-hw-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
Re: [PATCH v3 2/5] net: ethtool: use ndo_fix_features for offload setting
Quoted 1 line · Michał Mirosław
Signed-off-by Michał Mirosław <[email protected]>
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.
PATCH v3 3/5 net: use ndo_fix_features for ethtool_ops->set_flags
In reply to Michał Mirosław--- net/core/ethtool.c | 22 ++++++++++++++++++++-- 1 files changed, 20 insertions(+), 2 deletions(-)
net/core/ethtool.c +20 -2
@@ -240,6 +240,25 @@ 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) +{ +if (data & ~flags_dup_features) +return -EINVAL ; + +if (!(dev->hw_features & flags_dup_features)) { +if (!dev->ethtool_ops->set_flags) +return -EOPNOTSUPP ; +return dev->ethtool_ops->set_flags (dev, data); + } + + dev->wanted_features = + (dev->wanted_features & ~flags_dup_features) | 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 +1752,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
Re: [PATCH v3 3/5] net: use ndo_fix_features for ethtool_ops->set_flags
Quoted 20 lines · Michał Mirosław
Signed-off-by Michał Mirosław <[email protected]>--- net/core/ethtool.c | 22 ++++++++++++++++++++-- 1 files changed, 20 insertions(+), 2 deletions(-)net/core/ethtool.c +7
-0@@ -240,6 +240,25 @@ 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) +{ +if (data & ~flags_dup_features) +return -EINVAL ; + +if (!(dev->hw_features & flags_dup_features)) { +if (!dev->ethtool_ops->set_flags)
net/core/ethtool.c static int ethtool_set_features(struct net_device *dev, void __user *useraddr) · line 259
Quoted 10 lines
net/core/ethtool.c +10
-0+return -EOPNOTSUPP ; +return dev->ethtool_ops->set_flags (dev, data); + } + + dev->wanted_features = + (dev->wanted_features & ~flags_dup_features) | data; + +netdev_update_features (dev); + +return 0 ;
[...]
I think it would be clearer to write this as:
if (dev->hw_features & flags_dup_features) {
dev->wanted_features =
(dev->wanted_features & ~flags_dup_features) | data;
netdev_update_features(dev);
return 0;
}
if (dev->ethtool_ops->set_flags)
return dev->ethtool_ops->set_flags(dev, data);
return -EOPNOTSUPP;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 v3 3/5] net: use ndo_fix_features for ethtool_ops->set_flags
Quoted 33 lines · Ben Hutchings
Quoted 30 lines · Michał Mirosław
Signed-off-by Michał Mirosław <[email protected]>--- net/core/ethtool.c | 22 ++++++++++++++++++++-- 1 files changed, 20 insertions(+), 2 deletions(-)net/core/ethtool.c +17
-0@@ -240,6 +240,25 @@ 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) +{ +if (data & ~flags_dup_features) +return -EINVAL ; + +if (!(dev->hw_features & flags_dup_features)) { +if (!dev->ethtool_ops->set_flags) +return -EOPNOTSUPP ; +return dev->ethtool_ops->set_flags (dev, data); + } + + dev->wanted_features = + (dev->wanted_features & ~flags_dup_features) | data; + +netdev_update_features (dev); + +return 0 ;[...]
Quoted 1 line
I think it would be clearer to write this as:
[cut]
I changed it to check for more invalid states and to reject changing of bits not in hw_features but present in flags_dup_features.
Best Regards,
Michał Mirosław
PATCH 1/1 ethtool: implement G/SFEATURES calls
In reply to Michał Mirosław--- ethtool-copy.h | 90 +++++++++++++++++++++++- ethtool.c | 218 +++++++++++++++++++++++++++++++++++++++++++++++++++++--- 2 files changed, 298 insertions(+), 10 deletions(-)
ethtool-copy.h +89 -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,88 @@ 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 +* @avaliable: mask of changeable features +* @requested: mask of features requested to be enabled if possible +* @active: mask of currently enabled features +* @never_changed: mask of never-changeable features +*/ +struct ethtool_get_features_block { +__u32 available;/* features togglable */ +__u32 requested;/* features requested to be enabled */ +__u32 active;/* features currently enabled */ +__u32 never_changed;/* never-changeable features */ +}; + +/** +* struct ethtool_gfeatures - command to get state of device's features +* @cmd: command number = %ETHTOOL_GFEATURES +* @size: in: array size of the features[] array +* out: count of features[] elements filled +* @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;/* bits valid in .requested */ +__u32 requested;/* features 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 ,/* .valid had unsupported bits set */ +ETHTOOL_F_WISH__BIT ,/* resulting device features state in +* .valid is not equal to .requested */ +}; + +#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 +617,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 +670,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 +209 -9
294 lines not on this page · raw message
Signature · 1 line
1.7.2.3
Re: [PATCH] ethtool: implement G/SFEATURES calls
On Sat, 2011-01-29 at 19:39 +0100, Michał Mirosław wrote:
[...]
ethtool.c static struct option { · line 209
Quoted 11 lines
ethtool.c +2
-2@@ -196,8 +202,8 @@ static struct option {" [ rx-mini N ]\n" " [ rx-jumbo N ]\n" " [ tx N ]\n" }, - { "-k", "--show-offload", MODE_GOFFLOAD, "Get protocol offload information" }, - { "-K", "--offload", MODE_SOFFLOAD, "Set protocol offload", + { "-k", "--show-offload", MODE_GOFFLOAD, "Get protocol offload information (deprecated)" }, + { "-K", "--offload", MODE_SOFFLOAD, "Set protocol offload (deprecated)"," [ rx on|off ]\n" " [ tx on|off ]\n" " [ sg on|off ]\n"
[...]
I see no reason to deprecate the existing options.
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.
PATCH v3 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
@@ -626,7 +626,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
@@ -963,6 +963,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
@@ -978,7 +979,7 @@ struct net_device {/* = all defined minus driver/device-class-related */ #define NETIF_F_NEVER_CHANGE (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 | \
@@ -2500,6 +2501,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 ;
@@ -267,6 +261,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 ;
@@ -301,6 +298,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);
@@ -338,6 +336,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 :
@@ -382,7 +382,7 @@ static const char netdev_features_strings[ETHTOOL_DEV_FEATURE_WORDS * 32][ETH_GS/* NETIF_F_FCOE_MTU */ "fcoe-mtu" ,/* NETIF_F_NTUPLE */ "ntuple-filter" ,/* NETIF_F_RXHASH */ "rx-hashing-offload" , -"" , +/* NETIF_F_RXCSUM */ "rx-checksum-offload" ,"" , "", };
@@ -1360,20 +1360,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)
@@ -1721,15 +1716,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 ;
@@ -1802,6 +1788,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 :
@@ -1810,6 +1797,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
Re: [PATCH v3 4/5] net: introduce NETIF_F_RXCSUM
Quoted 6 lines · Michał Mirosław
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]>
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.
PATCH v3 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