net: Abstract features usage.
Subsystems (2)
PATCH 1/1 net: Abstract features usage.
Define macros to set/clear/test bits for feature set usage. This will eliminate the direct use of these fields and enable future ease in managing these fields.
--- include/linux/netdev_features.h | 137 +++++++++++++++++++++++++++++++++++++++ include/linux/netdevice.h | 35 ++--------- 2 files changed, 142 insertions(+), 30 deletions(-) create mode 100644 include/linux/netdev_features.h
include/linux/netdev_features.h new file +137 -0
@@ -0,0 +1,137 @@ +#ifndef _NETDEV_FEATURES_H +#define _NETDEV_FEATURES_H + +/* Forward declarations */ +struct net_device ; + +typedef unsigned long *nd_feature_t ; + +/* Net device feature bits; if you change something, +* also update netdev_features_strings[] in ethtool.c */ +enum netdev_features { +SG_BIT ,/* Scatter/gather IO. */ +IP_CSUM_BIT ,/* Can checksum TCP/UDP over IPv4. */ +NO_CSUM_BIT ,/* Does not require checksum. F.e. loopack. */ +HW_CSUM_BIT ,/* Can checksum all the packets. */ +IPV6_CSUM_BIT ,/* Can checksum TCP/UDP over IPV6 */ +HIGHDMA_BIT ,/* Can DMA to high memory. */ +FRAGLIST_BIT ,/* Scatter/gather IO. */ +HW_VLAN_TX_BIT ,/* Transmit VLAN hw acceleration */ +HW_VLAN_RX_BIT ,/* Receive VLAN hw acceleration */ +HW_VLAN_FILTER_BIT ,/* Receive filtering on VLAN */ +VLAN_CHALLENGED_BIT ,/* Device cannot handle VLAN packets */ +GSO_BIT ,/* Enable software GSO. */ +LLTX_BIT ,/* LockLess TX - deprecated. Please */ +/* do not use LLTX in new drivers */ +NETNS_LOCAL_BIT ,/* Does not change network namespaces */ +GRO_BIT ,/* Generic receive offload */ +LRO_BIT ,/* large receive offload */ +RESERVED16_BIT ,/* the GSO_MASK reserved bit 16 */ +RESERVED17_BIT ,/* the GSO_MASK reserved bit 17 */ +RESERVED18_BIT ,/* the GSO_MASK reserved bit 18 */ +RESERVED19_BIT ,/* the GSO_MASK reserved bit 19 */ +RESERVED20_BIT ,/* the GSO_MASK reserved bit 20 */ +RESERVED21_BIT ,/* the GSO_MASK reserved bit 21 */ +RESERVED22_BIT ,/* the GSO_MASK reserved bit 22 */ +RESERVED23_BIT ,/* the GSO_MASK reserved bit 23 */ +FCOE_CRC_BIT ,/* FCoE CRC32 */ +SCTP_CSUM_BIT ,/* SCTP checksum offload */ +FCOE_MTU_BIT ,/* Supports max FCoE MTU, 2158 bytes*/ +NTUPLE_BIT ,/* N-tuple filters supported */ +RXHASH_BIT ,/* Receive hashing offload */ +RXCSUM_BIT ,/* Receive checksumming offload */ +NOCACHE_COPY_BIT ,/* Use no-cache copyfromuser */ +LOOPBACK_BIT ,/* Enable loopback */ + +/* Add you bit above this */ +ND_FEATURE_NUM_BITS /* (LAST VALUE) Total bits in use */ +}; + +#define BIT2FLAG (bit) (1 << (bit)) + +#define NETIF_F_SG BIT2FLAG(SG_BIT) +#define NETIF_F_IP_CSUM BIT2FLAG(IP_CSUM_BIT) +#define NETIF_F_NO_CSUM BIT2FLAG(NO_CSUM_BIT) +#define NETIF_F_HW_CSUM BIT2FLAG(HW_CSUM_BIT) +#define NETIF_F_IPV6_CSUM BIT2FLAG(IPV6_CSUM_BIT) +#define NETIF_F_HIGHDMA BIT2FLAG(HIGHDMA_BIT) +#define NETIF_F_FRAGLIST BIT2FLAG(FRAGLIST_BIT) +#define NETIF_F_HW_VLAN_TX BIT2FLAG(HW_VLAN_TX_BIT) +#define NETIF_F_HW_VLAN_RX BIT2FLAG(HW_VLAN_RX_BIT) +#define NETIF_F_HW_VLAN_FILTER BIT2FLAG(HW_VLAN_FILTER_BIT) +#define NETIF_F_VLAN_CHALLENGED BIT2FLAG(VLAN_CHALLENGED_BIT) +#define NETIF_F_GSO BIT2FLAG(GSO_BIT) +#define NETIF_F_LLTX BIT2FLAG(LLTX_BIT) +#define NETIF_F_NETNS_LOCAL BIT2FLAG(NETNS_LOCAL_BIT) +#define NETIF_F_GRO BIT2FLAG(GRO_BIT) +#define NETIF_F_LRO BIT2FLAG(LRO_BIT) +#define NETIF_F_FCOE_CRC BIT2FLAG(FCOE_CRC_BIT) +#define NETIF_F_SCTP_CSUM BIT2FLAG(SCTP_CSUM_BIT) +#define NETIF_F_FCOE_MTU BIT2FLAG(FCOE_MTU_BIT) +#define NETIF_F_NTUPLE BIT2FLAG(NTUPLE_BIT) +#define NETIF_F_RXHASH BIT2FLAG(RXHASH_BIT) +#define NETIF_F_RXCSUM BIT2FLAG(RXCSUM_BIT) +#define NETIF_F_NOCACHE_COPY BIT2FLAG(NOCACHE_COPY_BIT) +#define NETIF_F_LOOPBACK BIT2FLAG(LOOPBACK_BIT) + +#define DEV_FEATURE_WORDS BITS_TO_LONGS(ND_FEATURE_NUM_BITS) +#define DEV_FEATURE_BITS (DEV_FEATURE_WORDS * BITS_PER_LONG) + +static inline void _nd_set_feature (u32 *old_field, +unsigned long *new_field,int bit) +{ +if (bit <32 ) + *old_field |= (1 << bit); +set_bit (bit, new_field); +} + +static inline void _nd_clear_feature (u32 *old_field, +unsigned long *new_field,int bit) +{ +if (bit <32 ) + *old_field &= ~(1 << bit); + +clear_bit (bit, new_field); +} + +static inline bool _nd_test_feature (u32 old_field, +unsigned long *new_field,int bit) +{ +if (bit <32 ) +return (old_field & (1 << bit)) ==1 ; + +return test_bit (bit, new_field) ==1 ; +} + +#define netdev_set_feature netdev_set_active_feature +#define netdev_set_active_feature (dev, bit) \ + _nd_set_feature(&(dev)->features, (dev)->active_feature, (bit)) +#define netdev_clear_active_feature (dev, bit) \ + _nd_clear_feature(&(dev)->features, (dev)->active_feature, (bit)) +#define netdev_test_active_feature (dev, bit) \ + _nd_test_feature((dev)->features, (dev)->active_feature, (bit)) + +#define netdev_set_hw_feature netdev_set_offered_feature +#define netdev_set_offered_feature (dev, bit) \ + _nd_set_feature(&(dev)->hw_features, (dev)->offered_feature, (bit)) +#define netdev_clear_offered_feature (dev, bit) \ + _nd_clear_feature(&(dev)->hw_features, (dev)->offered_feature, (bit)) +#define netdev_test_offered_feature (dev, bit) \ + _nd_test_feature((dev)->hw_features, (dev)->offered_feature, (bit)) + +#define netdev_set_vlan_feature (dev, bit) \ + _nd_set_feature(&(dev)->vlan_features, (dev)->vlan_feature, (bit)) +#define netdev_clear_vlan_feature (dev, bit) \ + _nd_clear_feature(&(dev)->vlan_features, (dev)->vlan_feature, (bit)) +#define netdev_test_vlan_feature (dev, bit) \ + _nd_test_feature((dev)->vlan_features, (dev)->vlan_feature, (bit)) + +#define netdev_set_wanted_feature (dev, bit) \ + _nd_set_feature(&(dev)->wanted_features, (dev)->wanted_feature, (bit)) +#define netdev_clear_wanted_feature (dev, bit) \ + _nd_clear_feature(&(dev)->wanted_features, (dev)->wanted_feature, (bit)) +#define netdev_test_wanted_feature (dev, bit) \ + _nd_test_feature((dev)->wanted_features, (dev)->wanted_feature, (bit)) + + +#endif /* __NETDEV_FEATURES_H */
include/linux/netdevice.h +5 -30
@@ -51,6 +51,7 @@#ifdef CONFIG_DCB #include <net/dcbnl.h> #endif +#include <linux/netdev_features.h> struct vlan_group ;struct netpoll_info ;
@@ -1035,36 +1036,10 @@ struct net_device {/* mask of features inheritable by VLAN devices */ u32 vlan_features; -/* Net device feature bits; if you change something, -* also update netdev_features_strings[] in ethtool.c */ - -#define NETIF_F_SG 1/* Scatter/gather IO. */ -#define NETIF_F_IP_CSUM 2/* Can checksum TCP/UDP over IPv4. */ -#define NETIF_F_NO_CSUM 4/* Does not require checksum. F.e. loopack. */ -#define NETIF_F_HW_CSUM 8/* Can checksum all the packets. */ -#define NETIF_F_IPV6_CSUM 16/* Can checksum TCP/UDP over IPV6 */ -#define NETIF_F_HIGHDMA 32/* Can DMA to high memory. */ -#define NETIF_F_FRAGLIST 64/* Scatter/gather IO. */ -#define NETIF_F_HW_VLAN_TX 128/* Transmit VLAN hw acceleration */ -#define NETIF_F_HW_VLAN_RX 256/* Receive VLAN hw acceleration */ -#define NETIF_F_HW_VLAN_FILTER 512/* Receive filtering on VLAN */ -#define NETIF_F_VLAN_CHALLENGED 1024/* Device cannot handle VLAN packets */ -#define NETIF_F_GSO 2048/* Enable software GSO. */ -#define NETIF_F_LLTX 4096/* LockLess TX - deprecated. Please */ -/* do not use LLTX in new drivers */ -#define NETIF_F_NETNS_LOCAL 8192/* Does not change network namespaces */ -#define NETIF_F_GRO 16384/* Generic receive offload */ -#define NETIF_F_LRO 32768/* large receive offload */ - -/* the GSO_MASK reserves bits 16 through 23 */ -#define NETIF_F_FCOE_CRC (1 << 24)/* FCoE CRC32 */ -#define NETIF_F_SCTP_CSUM (1 << 25)/* SCTP checksum offload */ -#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 */ -#define NETIF_F_NOCACHE_COPY (1 << 30)/* Use no-cache copyfromuser */ -#define NETIF_F_LOOPBACK (1 << 31)/* Enable loopback */ +DECLARE_BITMAP (active_feature,DEV_FEATURE_BITS ); +DECLARE_BITMAP (offered_feature,DEV_FEATURE_BITS ); +DECLARE_BITMAP (wanted_feature,DEV_FEATURE_BITS ); +DECLARE_BITMAP (vlan_feature,DEV_FEATURE_BITS );/* Segmentation offload features */ #define NETIF_F_GSO_SHIFT 16
Signature · 1 line
1.7.3.1
2011/5/24 Mahesh Bandewar <[email protected]>:
Quoted 18 lines
Define macros to set/clear/test bits for feature set usage. This will eliminate the direct use of these fields and enable future ease in managing these fields.
Signed-off-by Mahesh Bandewar <[email protected]>---
include/linux/netdev_features.h | 137 +++++++++++++++++++++++++++++++++++++++include/linux/netdevice.h| 35 ++---------2 files changed, 142 insertions(+), 30 deletions(-)create mode 100644
include/linux/netdev_features.hinclude/linux/netdev_features.h new file +2
-0@@ -0,0 +1,137 @@ +#ifndef _NETDEV_FEATURES_H +#define _NETDEV_FEATURES_H
include/linux/netdev_features.h line 12
Quoted 10 lines
include/linux/netdev_features.h new file +10
-0+ +/* Forward declarations */ +struct net_device ; + +typedef unsigned long *nd_feature_t; + +/* Net device feature bits; if you change something, +* also update netdev_features_strings[] in ethtool.c */ +enum netdev_features { + SG_BIT, /* Scatter/gather IO. */
[...]
Please split this change (introducing enum + converting NETIF_F_* defines to use it). This part is a nice cleanup, but I think the bitmap idea is still not worth the trouble until u64 runs out.
Best Regards,
Michał Mirosław
Quoted 32 lines · Michał Mirosław
2011/5/24 Mahesh Bandewar <[email protected]>:
Quoted 28 lines
Define macros to set/clear/test bits for feature set usage. This will eliminate the direct use of these fields and enable future ease in managing these fields.
Signed-off-by Mahesh Bandewar <[email protected]>---
include/linux/netdev_features.h | 137 +++++++++++++++++++++++++++++++++++++++include/linux/netdevice.h| 35 ++---------2 files changed, 142 insertions(+), 30 deletions(-)create mode 100644
include/linux/netdev_features.hinclude/linux/netdev_features.h new file +12
-0@@ -0,0 +1,137 @@ +#ifndef _NETDEV_FEATURES_H +#define _NETDEV_FEATURES_H + +/* Forward declarations */ +struct net_device ; + +typedef unsigned long *nd_feature_t; + +/* Net device feature bits; if you change something, +* also update netdev_features_strings[] in ethtool.c */ +enum netdev_features { + SG_BIT, /* Scatter/gather IO. */[...]
Quoted 4 lines
Please split this change (introducing enum + converting NETIF_F_* defines to use it). This part is a nice cleanup, but I think the bitmap idea is still not worth the trouble until u64 runs out.
What will we achieve by this split? May be I'm not getting your point about split. Do you want to see the cleanup part as a separate patch? These enums and NETIF_F_* values have to be in sync. The macros that I have defined are expecting this bit numbers rather than the flag value.
Whether it is u64 or bitmap, the changes should be limited to this file. Going forward that can be achieved by
simply changing few lines in these macros / inlines.
Thanks,
--mahesh..
Quoted 2 lines
Best Regards,
Michał Mirosław
W dniu 24 maja 2011 22:29 użytkownik Mahesh Bandewar
Quoted 33 lines · <[email protected]> napisał:
Quoted 32 lines · Michał Mirosław
2011/5/24 Mahesh Bandewar <[email protected]>:
Quoted 28 lines
Define macros to set/clear/test bits for feature set usage. This will eliminate the direct use of these fields and enable future ease in managing these fields.
Signed-off-by Mahesh Bandewar <[email protected]>---
include/linux/netdev_features.h | 137 +++++++++++++++++++++++++++++++++++++++include/linux/netdevice.h| 35 ++---------2 files changed, 142 insertions(+), 30 deletions(-)create mode 100644
include/linux/netdev_features.hinclude/linux/netdev_features.h new file +12
-0@@ -0,0 +1,137 @@ +#ifndef _NETDEV_FEATURES_H +#define _NETDEV_FEATURES_H + +/* Forward declarations */ +struct net_device ; + +typedef unsigned long *nd_feature_t; + +/* Net device feature bits; if you change something, +* also update netdev_features_strings[] in ethtool.c */ +enum netdev_features { + SG_BIT, /* Scatter/gather IO. */[...]
Quoted 6 lines
Quoted 3 lines
Please split this change (introducing enum + converting NETIF_F_* defines to use it). This part is a nice cleanup, but I think the bitmap idea is still not worth the trouble until u64 runs out.
What will we achieve by this split? May be I'm not getting your point about split. Do you want to see the cleanup part as a separate patch? These enums and NETIF_F_* values have to be in sync.
Exactly. You already did the cleanup (defining enum and NETIF_F_* #defines), so just split it into separate patch. This is a prerequisite to any change to the type holding features from u32 to either u64 or bitmap. And this will separate the cleanup from your proposed idea.
Quoted 5 lines
The macros that I have defined are expecting this bit numbers rather than the flag value.
Whether it is u64 or bitmap, the changes should be limited to this file. Going forward that can be achieved by
simply changing few lines in these macros / inlines.
One thing I don't like in this implementation is that it leaves old fields around - so you'll have two code templates in the kernel doing the same thing (unless you fix all users, but then you won't need old fields anyway).
Best Regards,
Michał Mirosław
Quoted 42 lines · Michał Mirosław
W dniu 24 maja 2011 22:29 użytkownik Mahesh Bandewar
Quoted 33 lines · <[email protected]> napisał:
Quoted 32 lines · Michał Mirosław
2011/5/24 Mahesh Bandewar <[email protected]>:
Quoted 28 lines
Define macros to set/clear/test bits for feature set usage. This will eliminate the direct use of these fields and enable future ease in managing these fields.
Signed-off-by Mahesh Bandewar <[email protected]>---
include/linux/netdev_features.h | 137 +++++++++++++++++++++++++++++++++++++++include/linux/netdevice.h| 35 ++---------2 files changed, 142 insertions(+), 30 deletions(-)create mode 100644
include/linux/netdev_features.hinclude/linux/netdev_features.h new file +12
-0@@ -0,0 +1,137 @@ +#ifndef _NETDEV_FEATURES_H +#define _NETDEV_FEATURES_H + +/* Forward declarations */ +struct net_device ; + +typedef unsigned long *nd_feature_t; + +/* Net device feature bits; if you change something, +* also update netdev_features_strings[] in ethtool.c */ +enum netdev_features { + SG_BIT, /* Scatter/gather IO. */[...]
Quoted 6 lines
Quoted 3 lines
Please split this change (introducing enum + converting NETIF_F_* defines to use it). This part is a nice cleanup, but I think the bitmap idea is still not worth the trouble until u64 runs out.
What will we achieve by this split? May be I'm not getting your point about split. Do you want to see the cleanup part as a separate patch? These enums and NETIF_F_* values have to be in sync.
Quoted 6 lines
Exactly. You already did the cleanup (defining enum and NETIF_F_* #defines), so just split it into separate patch. This is a prerequisite to any change to the type holding features from u32 to either u64 or bitmap. And this will separate the cleanup from your proposed idea.
Alright, will split the change into two pieces.
Quoted 11 lines
Quoted 5 lines
The macros that I have defined are expecting this bit numbers rather than the flag value.
Whether it is u64 or bitmap, the changes should be limited to this file. Going forward that can be achieved by
simply changing few lines in these macros / inlines.One thing I don't like in this implementation is that it leaves old fields around - so you'll have two code templates in the kernel doing the same thing (unless you fix all users, but then you won't need old fields anyway).
The older fields give us longer time frame to make these changes where ever necessary. Also enable us to make these changes in stages. Once all the changes are in place, the older-fields along with the code instrumentation will be removed. So yes, this file / macros / inlines will be touched at the end of the completion of the last phase.
Thanks,
--mahesh..
Quoted 3 lines
Best Regards,
Michał Mirosław
Quoted 16 lines · On Tue, 24 May 2011 11:52:42 -0700 Mahesh Bandewar <[email protected]> wrote:
Define macros to set/clear/test bits for feature set usage. This will eliminate the direct use of these fields and enable future ease in managing these fields.
Signed-off-by Mahesh Bandewar <[email protected]>--- include/linux/netdev_features.h | 137 +++++++++++++++++++++++++++++++++++++++ include/linux/netdevice.h | 35 ++--------- 2 files changed, 142 insertions(+), 30 deletions(-) create mode 100644 include/linux/netdev_features.hinclude/linux/netdev_features.h new file +0
-0
include/linux/netdev_features.h line 7
Quoted 7 lines
include/linux/netdev_features.h new file +7
-0@@ -0,0 +1,137 @@ +#ifndef _NETDEV_FEATURES_H +#define _NETDEV_FEATURES_H + +/* Forward declarations */ +struct net_device ; + +typedef unsigned long *nd_feature_t
typedef'ing a pointer is strongly discouraged by kernel coding style. You need to use another way such as open coding it.
Quoted 13 lines · Stephen Hemminger
Quoted 10 lines · On Tue, 24 May 2011 11:52:42 -0700 Mahesh Bandewar <[email protected]> wrote:
Define macros to set/clear/test bits for feature set usage. This will eliminate the direct use of these fields and enable future ease in managing these fields.
Signed-off-by Mahesh Bandewar <[email protected]>---
include/linux/netdev_features.h | 137 +++++++++++++++++++++++++++++++++++++++include/linux/netdevice.h| 35 ++---------2 files changed, 142 insertions(+), 30 deletions(-)create mode 100644
include/linux/netdev_features.h
Quoted 17 lines
include/linux/netdev_features.h line 7
Quoted 13 lines
include/linux/netdev_features.h new file +7
-0@@ -0,0 +1,137 @@ +#ifndef _NETDEV_FEATURES_H +#define _NETDEV_FEATURES_H + +/* Forward declarations */ +struct net_device ; + +typedef unsigned long *nd_feature_ttypedef'ing a pointer is strongly discouraged by kernel coding style. You need to use another way such as open coding it.
The idea here is to have a typedef that we can use to avoid future changes all over the code if we decide to change the way feature bits are stored. So if this is bitmap it will be defined as "unsigned long *" and if it were to be u64 then it's typedef-ed as "u64". So in one case it's a pointer and in other case it's not! Now how do we handle both these cases?
Thanks,
--mahesh..
Quoted 2 lines
--
Quoted 32 lines · On Tue, 24 May 2011 16:04:20 -0700 Mahesh Bandewar <[email protected]> wrote:
Quoted 13 lines · Stephen Hemminger
Quoted 10 lines · On Tue, 24 May 2011 11:52:42 -0700 Mahesh Bandewar <[email protected]> wrote:
Define macros to set/clear/test bits for feature set usage. This will eliminate the direct use of these fields and enable future ease in managing these fields.
Signed-off-by Mahesh Bandewar <[email protected]>---
include/linux/netdev_features.h | 137 +++++++++++++++++++++++++++++++++++++++include/linux/netdevice.h| 35 ++---------2 files changed, 142 insertions(+), 30 deletions(-)create mode 100644
include/linux/netdev_features.hQuoted 17 lines
include/linux/netdev_features.h line 7
Quoted 13 lines
include/linux/netdev_features.h new file +7
-0@@ -0,0 +1,137 @@ +#ifndef _NETDEV_FEATURES_H +#define _NETDEV_FEATURES_H + +/* Forward declarations */ +struct net_device ; + +typedef unsigned long *nd_feature_ttypedef'ing a pointer is strongly discouraged by kernel coding style. You need to use another way such as open coding it.
Quoted 6 lines
The idea here is to have a typedef that we can use to avoid future changes all over the code if we decide to change the way feature bits are stored. So if this is bitmap it will be defined as "unsigned long *" and if it were to be u64 then it's typedef-ed as "u64". So in one case it's a pointer and in other case it's not! Now how do we handle both these cases?
It is okay to add a typedef for a fixed width type. Just not adding the indirection
because it leads to confusion.
Read "Chapter 5: Typedefs" in Documentation/CodingStyle
Quoted 42 lines · Stephen Hemminger
Quoted 32 lines · On Tue, 24 May 2011 16:04:20 -0700 Mahesh Bandewar <[email protected]> wrote:
Quoted 13 lines · Stephen Hemminger
Quoted 10 lines · On Tue, 24 May 2011 11:52:42 -0700 Mahesh Bandewar <[email protected]> wrote:
Define macros to set/clear/test bits for feature set usage. This will eliminate the direct use of these fields and enable future ease in managing these fields.
Signed-off-by Mahesh Bandewar <[email protected]>---
include/linux/netdev_features.h | 137 +++++++++++++++++++++++++++++++++++++++include/linux/netdevice.h| 35 ++---------2 files changed, 142 insertions(+), 30 deletions(-)create mode 100644
include/linux/netdev_features.hQuoted 17 lines
include/linux/netdev_features.h line 7
Quoted 13 lines
include/linux/netdev_features.h new file +7
-0@@ -0,0 +1,137 @@ +#ifndef _NETDEV_FEATURES_H +#define _NETDEV_FEATURES_H + +/* Forward declarations */ +struct net_device ; + +typedef unsigned long *nd_feature_ttypedef'ing a pointer is strongly discouraged by kernel coding style. You need to use another way such as open coding it.
Quoted 6 lines
The idea here is to have a typedef that we can use to avoid future changes all over the code if we decide to change the way feature bits are stored. So if this is bitmap it will be defined as "unsigned long *" and if it were to be u64 then it's typedef-ed as "u64". So in one case it's a pointer and in other case it's not! Now how do we handle both these cases?
Quoted 6 lines
It is okay to add a typedef for a fixed width type. Just not adding the indirection
because it leads to confusion.Read "Chapter 5: Typedefs" in
Documentation/CodingStyle
Yes, this usage matches the (a) case in the documentation. This typedef is to hide the object but enable APIs to pass it around for reference and it _should_ only be altered by using the helper APIs from this file. If we find a certain API is missing, it should be added here instead of doing some local magic.
Thanks,
--mahesh..
Quoted 4 lines
--
PATCH v2 1/1 net: Abstract features usage.
In reply to Mahesh BandewarDefine macros to set/clear/test bits for feature set usage. This will eliminate the direct use of these fields and enable future ease in managing these fields.
---
Changes since v1:
Split the patch into two pieces.
include/linux/netdev_features.h | 64 +++++++++++++++++++++++++++++++++++++++ include/linux/netdevice.h | 8 +++++ 2 files changed, 72 insertions(+), 0 deletions(-) create mode 100644 include/linux/netdev_features.h
include/linux/netdev_features.h new file +64 -0
@@ -0,0 +1,64 @@ +#ifndef _NETDEV_FEATURES_H +#define _NETDEV_FEATURES_H + +/* Forward declarations */ +struct net_device ; + +typedef unsigned long *nd_feature_t ; + +static inline void _nd_set_feature (u32 *old_field, +unsigned long *new_field,int bit) +{ +if (bit <32 ) + *old_field |= (1 << bit); +set_bit (bit, new_field); +} + +static inline void _nd_clear_feature (u32 *old_field, +unsigned long *new_field,int bit) +{ +if (bit <32 ) + *old_field &= ~(1 << bit); + +clear_bit (bit, new_field); +} + +static inline bool _nd_test_feature (u32 old_field, +unsigned long *new_field,int bit) +{ +if (bit <32 ) +return (old_field & (1 << bit)) ==1 ; + +return test_bit (bit, new_field) ==1 ; +} + +#define netdev_set_active_feature (dev, bit) \ + _nd_set_feature(&(dev)->features, (dev)->active_feature, (bit)) +#define netdev_clear_active_feature (dev, bit) \ + _nd_clear_feature(&(dev)->features, (dev)->active_feature, (bit)) +#define netdev_test_active_feature (dev, bit) \ + _nd_test_feature((dev)->features, (dev)->active_feature, (bit)) + +#define netdev_set_offered_feature (dev, bit) \ + _nd_set_feature(&(dev)->hw_features, (dev)->offered_feature, (bit)) +#define netdev_clear_offered_feature (dev, bit) \ + _nd_clear_feature(&(dev)->hw_features, (dev)->offered_feature, (bit)) +#define netdev_test_offered_feature (dev, bit) \ + _nd_test_feature((dev)->hw_features, (dev)->offered_feature, (bit)) + +#define netdev_set_vlan_feature (dev, bit) \ + _nd_set_feature(&(dev)->vlan_features, (dev)->vlan_feature, (bit)) +#define netdev_clear_vlan_feature (dev, bit) \ + _nd_clear_feature(&(dev)->vlan_features, (dev)->vlan_feature, (bit)) +#define netdev_test_vlan_feature (dev, bit) \ + _nd_test_feature((dev)->vlan_features, (dev)->vlan_feature, (bit)) + +#define netdev_set_wanted_feature (dev, bit) \ + _nd_set_feature(&(dev)->wanted_features, (dev)->wanted_feature, (bit)) +#define netdev_clear_wanted_feature (dev, bit) \ + _nd_clear_feature(&(dev)->wanted_features, (dev)->wanted_feature, (bit)) +#define netdev_test_wanted_feature (dev, bit) \ + _nd_test_feature((dev)->wanted_features, (dev)->wanted_feature, (bit)) + + +#endif /* __NETDEV_FEATURES_H */
include/linux/netdevice.h +8 -0
@@ -1079,6 +1079,14 @@ struct net_device {/* mask of features inheritable by VLAN devices */ u32 vlan_features; +#define DEV_FEATURE_WORDS BITS_TO_LONGS(ND_FEATURE_NUM_BITS) +#define DEV_FEATURE_BITS (DEV_FEATURE_WORDS * BITS_PER_LONG) + +DECLARE_BITMAP (active_feature,DEV_FEATURE_BITS ); +DECLARE_BITMAP (offered_feature,DEV_FEATURE_BITS ); +DECLARE_BITMAP (wanted_feature,DEV_FEATURE_BITS ); +DECLARE_BITMAP (vlan_feature,DEV_FEATURE_BITS ); +#define BIT2FLAG (bit) (1 << (bit))#define NETIF_F_SG BIT2FLAG(SG_BIT)
Signature · 1 line
1.7.3.1
PATCH v3 1/1 net: Abstract features usage.
Define macros to set/clear/test bits for feature set usage. This will eliminate the direct use of these fields and enable future ease in managing these fields.
---
Changes since v2:
Added the include which accidently went into the other patch.
Changes since v1:
Split the patch into two pieces.
include/linux/netdev_features.h | 64 +++++++++++++++++++++++++++++++++++++++ include/linux/netdevice.h | 9 +++++ 2 files changed, 73 insertions(+), 0 deletions(-) create mode 100644 include/linux/netdev_features.h
include/linux/netdev_features.h new file +64 -0
@@ -0,0 +1,64 @@ +#ifndef _NETDEV_FEATURES_H +#define _NETDEV_FEATURES_H + +/* Forward declarations */ +struct net_device ; + +typedef unsigned long *nd_feature_t ; + +static inline void _nd_set_feature (u32 *old_field, +unsigned long *new_field,int bit) +{ +if (bit <32 ) + *old_field |= (1 << bit); +set_bit (bit, new_field); +} + +static inline void _nd_clear_feature (u32 *old_field, +unsigned long *new_field,int bit) +{ +if (bit <32 ) + *old_field &= ~(1 << bit); + +clear_bit (bit, new_field); +} + +static inline bool _nd_test_feature (u32 old_field, +unsigned long *new_field,int bit) +{ +if (bit <32 ) +return (old_field & (1 << bit)) ==1 ; + +return test_bit (bit, new_field) ==1 ; +} + +#define netdev_set_active_feature (dev, bit) \ + _nd_set_feature(&(dev)->features, (dev)->active_feature, (bit)) +#define netdev_clear_active_feature (dev, bit) \ + _nd_clear_feature(&(dev)->features, (dev)->active_feature, (bit)) +#define netdev_test_active_feature (dev, bit) \ + _nd_test_feature((dev)->features, (dev)->active_feature, (bit)) + +#define netdev_set_offered_feature (dev, bit) \ + _nd_set_feature(&(dev)->hw_features, (dev)->offered_feature, (bit)) +#define netdev_clear_offered_feature (dev, bit) \ + _nd_clear_feature(&(dev)->hw_features, (dev)->offered_feature, (bit)) +#define netdev_test_offered_feature (dev, bit) \ + _nd_test_feature((dev)->hw_features, (dev)->offered_feature, (bit)) + +#define netdev_set_vlan_feature (dev, bit) \ + _nd_set_feature(&(dev)->vlan_features, (dev)->vlan_feature, (bit)) +#define netdev_clear_vlan_feature (dev, bit) \ + _nd_clear_feature(&(dev)->vlan_features, (dev)->vlan_feature, (bit)) +#define netdev_test_vlan_feature (dev, bit) \ + _nd_test_feature((dev)->vlan_features, (dev)->vlan_feature, (bit)) + +#define netdev_set_wanted_feature (dev, bit) \ + _nd_set_feature(&(dev)->wanted_features, (dev)->wanted_feature, (bit)) +#define netdev_clear_wanted_feature (dev, bit) \ + _nd_clear_feature(&(dev)->wanted_features, (dev)->wanted_feature, (bit)) +#define netdev_test_wanted_feature (dev, bit) \ + _nd_test_feature((dev)->wanted_features, (dev)->wanted_feature, (bit)) + + +#endif /* __NETDEV_FEATURES_H */
include/linux/netdevice.h +9 -0
@@ -51,6 +51,7 @@#ifdef CONFIG_DCB #include <net/dcbnl.h> #endif +#include <linux/netdev_features.h> struct vlan_group ;struct netpoll_info ;
@@ -1078,6 +1079,14 @@ struct net_device {/* mask of features inheritable by VLAN devices */ u32 vlan_features; +#define DEV_FEATURE_WORDS BITS_TO_LONGS(ND_FEATURE_NUM_BITS) +#define DEV_FEATURE_BITS (DEV_FEATURE_WORDS * BITS_PER_LONG) + +DECLARE_BITMAP (active_feature,DEV_FEATURE_BITS ); +DECLARE_BITMAP (offered_feature,DEV_FEATURE_BITS ); +DECLARE_BITMAP (wanted_feature,DEV_FEATURE_BITS ); +DECLARE_BITMAP (vlan_feature,DEV_FEATURE_BITS ); +#define BIT2FLAG (bit) (1 << (bit))#define NETIF_F_SG BIT2FLAG(NETIF_F_SG_BIT)
Signature · 1 line
1.7.3.1
PATCH v2 1/1 net: Define enum for the bits used in features.
In reply to Mahesh BandewarLittle bit cleanup by defining enum for all bits used. Also use those enum values to redefine flags.
---
Changes since v1:
Split the patch into two pieces.
include/linux/netdevice.h | 100 +++++++++++++++++++++++++++++++------------- 1 files changed, 70 insertions(+), 30 deletions(-)
include/linux/netdevice.h +70 -30
@@ -51,6 +51,7 @@#ifdef CONFIG_DCB #include <net/dcbnl.h> #endif +#include <linux/netdev_features.h> struct vlan_group ;struct netpoll_info ;
@@ -981,6 +982,49 @@ struct net_device_ops { };/* +* Net device feature bits; if you change something, +* also update netdev_features_strings[] in ethtool.c +*/ +enum netdev_features { +SG_BIT ,/* Scatter/gather IO. */ +IP_CSUM_BIT ,/* Can checksum TCP/UDP over IPv4. */ +NO_CSUM_BIT ,/* Does not require checksum. F.e. loopack. */ +HW_CSUM_BIT ,/* Can checksum all the packets. */ +IPV6_CSUM_BIT ,/* Can checksum TCP/UDP over IPV6 */ +HIGHDMA_BIT ,/* Can DMA to high memory. */ +FRAGLIST_BIT ,/* Scatter/gather IO. */ +HW_VLAN_TX_BIT ,/* Transmit VLAN hw acceleration */ +HW_VLAN_RX_BIT ,/* Receive VLAN hw acceleration */ +HW_VLAN_FILTER_BIT ,/* Receive filtering on VLAN */ +VLAN_CHALLENGED_BIT ,/* Device cannot handle VLAN packets */ +GSO_BIT ,/* Enable software GSO. */ +LLTX_BIT ,/* LockLess TX - deprecated. Please */ +/* do not use LLTX in new drivers */ +NETNS_LOCAL_BIT ,/* Does not change network namespaces */ +GRO_BIT ,/* Generic receive offload */ +LRO_BIT ,/* large receive offload */ +RESERVED16_BIT ,/* the GSO_MASK reserved bit 16 */ +RESERVED17_BIT ,/* the GSO_MASK reserved bit 17 */ +RESERVED18_BIT ,/* the GSO_MASK reserved bit 18 */ +RESERVED19_BIT ,/* the GSO_MASK reserved bit 19 */ +RESERVED20_BIT ,/* the GSO_MASK reserved bit 20 */ +RESERVED21_BIT ,/* the GSO_MASK reserved bit 21 */ +RESERVED22_BIT ,/* the GSO_MASK reserved bit 22 */ +RESERVED23_BIT ,/* the GSO_MASK reserved bit 23 */ +FCOE_CRC_BIT ,/* FCoE CRC32 */ +SCTP_CSUM_BIT ,/* SCTP checksum offload */ +FCOE_MTU_BIT ,/* Supports max FCoE MTU, 2158 bytes*/ +NTUPLE_BIT ,/* N-tuple filters supported */ +RXHASH_BIT ,/* Receive hashing offload */ +RXCSUM_BIT ,/* Receive checksumming offload */ +NOCACHE_COPY_BIT ,/* Use no-cache copyfromuser */ +LOOPBACK_BIT ,/* Enable loopback */ + +/* Add you bit above this */ +ND_FEATURE_NUM_BITS /* (LAST VALUE) Total bits in use */ +}; + +/* * The DEVICE structure. * Actually, this whole structure is a big mistake. It mixes I/O * data with strictly "high-level" data, and it has to know about
@@ -1035,36 +1079,32 @@ struct net_device {/* mask of features inheritable by VLAN devices */ u32 vlan_features; -/* Net device feature bits; if you change something, -* also update netdev_features_strings[] in ethtool.c */ - -#define NETIF_F_SG 1/* Scatter/gather IO. */ -#define NETIF_F_IP_CSUM 2/* Can checksum TCP/UDP over IPv4. */ -#define NETIF_F_NO_CSUM 4/* Does not require checksum. F.e. loopack. */ -#define NETIF_F_HW_CSUM 8/* Can checksum all the packets. */ -#define NETIF_F_IPV6_CSUM 16/* Can checksum TCP/UDP over IPV6 */ -#define NETIF_F_HIGHDMA 32/* Can DMA to high memory. */ -#define NETIF_F_FRAGLIST 64/* Scatter/gather IO. */ -#define NETIF_F_HW_VLAN_TX 128/* Transmit VLAN hw acceleration */ -#define NETIF_F_HW_VLAN_RX 256/* Receive VLAN hw acceleration */ -#define NETIF_F_HW_VLAN_FILTER 512/* Receive filtering on VLAN */ -#define NETIF_F_VLAN_CHALLENGED 1024/* Device cannot handle VLAN packets */ -#define NETIF_F_GSO 2048/* Enable software GSO. */ -#define NETIF_F_LLTX 4096/* LockLess TX - deprecated. Please */ -/* do not use LLTX in new drivers */ -#define NETIF_F_NETNS_LOCAL 8192/* Does not change network namespaces */ -#define NETIF_F_GRO 16384/* Generic receive offload */ -#define NETIF_F_LRO 32768/* large receive offload */ - -/* the GSO_MASK reserves bits 16 through 23 */ -#define NETIF_F_FCOE_CRC (1 << 24)/* FCoE CRC32 */ -#define NETIF_F_SCTP_CSUM (1 << 25)/* SCTP checksum offload */ -#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 */ -#define NETIF_F_NOCACHE_COPY (1 << 30)/* Use no-cache copyfromuser */ -#define NETIF_F_LOOPBACK (1 << 31)/* Enable loopback */ +#define BIT2FLAG (bit) (1 << (bit)) + +#define NETIF_F_SG BIT2FLAG(SG_BIT) +#define NETIF_F_IP_CSUM BIT2FLAG(IP_CSUM_BIT) +#define NETIF_F_NO_CSUM BIT2FLAG(NO_CSUM_BIT) +#define NETIF_F_HW_CSUM BIT2FLAG(HW_CSUM_BIT) +#define NETIF_F_IPV6_CSUM BIT2FLAG(IPV6_CSUM_BIT) +#define NETIF_F_HIGHDMA BIT2FLAG(HIGHDMA_BIT) +#define NETIF_F_FRAGLIST BIT2FLAG(FRAGLIST_BIT) +#define NETIF_F_HW_VLAN_TX BIT2FLAG(HW_VLAN_TX_BIT) +#define NETIF_F_HW_VLAN_RX BIT2FLAG(HW_VLAN_RX_BIT) +#define NETIF_F_HW_VLAN_FILTER BIT2FLAG(HW_VLAN_FILTER_BIT) +#define NETIF_F_VLAN_CHALLENGED BIT2FLAG(VLAN_CHALLENGED_BIT) +#define NETIF_F_GSO BIT2FLAG(GSO_BIT) +#define NETIF_F_LLTX BIT2FLAG(LLTX_BIT) +#define NETIF_F_NETNS_LOCAL BIT2FLAG(NETNS_LOCAL_BIT) +#define NETIF_F_GRO BIT2FLAG(GRO_BIT) +#define NETIF_F_LRO BIT2FLAG(LRO_BIT) +#define NETIF_F_FCOE_CRC BIT2FLAG(FCOE_CRC_BIT) +#define NETIF_F_SCTP_CSUM BIT2FLAG(SCTP_CSUM_BIT) +#define NETIF_F_FCOE_MTU BIT2FLAG(FCOE_MTU_BIT) +#define NETIF_F_NTUPLE BIT2FLAG(NTUPLE_BIT) +#define NETIF_F_RXHASH BIT2FLAG(RXHASH_BIT) +#define NETIF_F_RXCSUM BIT2FLAG(RXCSUM_BIT) +#define NETIF_F_NOCACHE_COPY BIT2FLAG(NOCACHE_COPY_BIT) +#define NETIF_F_LOOPBACK BIT2FLAG(LOOPBACK_BIT)/* Segmentation offload features */ #define NETIF_F_GSO_SHIFT 16
Signature · 1 line
1.7.3.1
Re: [PATCHv2] net: Define enum for the bits used in features.
Quoted 1 line · Mahesh Bandewar
Little bit cleanup by defining enum for all bits used. Also use those
enum
Quoted 1 line
values to redefine flags.
Where is the advantage? Now I need to add 2 lines at two different places.
#define NETIF_F_IP_CSUM BIT2FLAG(IP_CSUM_BIT)
Confuses me more compared to a simple
#define NETIF_F_IP_CSUM (1 << 2)
The enum netdev_features namespace is not really unique (e.g.
RESERVED16_BIT).
For me the modifications are harder to understand, my tools are confused
and I see no real advantage, only more indirection introduced.
Hagen
Re: [PATCHv2] net: Define enum for the bits used in features.
In reply to Mahesh Bandewar2011/5/25 Mahesh Bandewar <[email protected]>:
Quoted 16 lines
Little bit cleanup by defining enum for all bits used. Also use those enum values to redefine flags.
Signed-off-by Mahesh Bandewar <[email protected]>---
Changes since v1:
Split the patch into two pieces.include/linux/netdevice.h | 100 +++++++++++++++++++++++++++++++-------------
1 files changed, 70 insertions(+), 30 deletions(-)include/linux/netdevice.h +0
-0
include/linux/netdevice.h line 54
Quoted 4 lines
include/linux/netdevice.h +1
-0@@ -51,6 +51,7 @@ #ifdef CONFIG_DCB #include <net/dcbnl.h> #endif +#include <linux/netdev_features.h>
This should go to other part.
Quoted 10 lines
include/linux/netdevice.h +4
-0struct vlan_group; struct netpoll_info;@@ -981,6 +982,49 @@ struct net_device_ops { }; /* +* Net device feature bits; if you change something, +* also update netdev_features_strings[] in ethtool.c +*/ +enum netdev_features {
[...]
Quoted 8 lines
+
RESERVED16_BIT, /* theGSO_MASKreserved bit 16 */
+RESERVED17_BIT, /* theGSO_MASKreserved bit 17 */
+RESERVED18_BIT, /* theGSO_MASKreserved bit 18 */
+RESERVED19_BIT, /* theGSO_MASKreserved bit 19 */
+RESERVED20_BIT, /* theGSO_MASKreserved bit 20 */
+RESERVED21_BIT, /* theGSO_MASKreserved bit 21 */
+RESERVED22_BIT, /* theGSO_MASKreserved bit 22 */
+RESERVED23_BIT, /* theGSO_MASKreserved bit 23 */
This could also define NETIF_F_GSO_SHIFT and name TSO and others. Maybe like this:
NETIF_F_GSO_SHIFT, /* must == 16, for now */GSO_RESERVED0_BIT = NETIF_F_GSO_SHIFT,GSO_RESERVED1_BIT,
...GSO_RESERVED7_BIT,
... (other bits)
Quoted 1 line
+ /* Add you bit above this */
your.
Quoted 1 line
+
ND_FEATURE_NUM_BITS, /* (LAST VALUE) Total bits in use */
And here GSO aliases:
TSO_BIT = NETIF_F_GSO_SHIFT + SKB_GSO_TCPV4,UFO_BIT = NETIF_F_GSO_SHIFT + SKB_GSO_UDP,
...
Afther this is done, I can convert the feature-names table in ethtool.c to use C99 array assignments, so that no one else will trip on a missing comma or wrong entries order there.
About the bit names: NETIF_F_xxx_BIT?
Best Regards,
Michał Mirosław
Re: [PATCHv2] net: Define enum for the bits used in features.
W dniu 25 maja 2011 11:43 użytkownik Michał Mirosław <[email protected]> napisał:
[...]
Quoted 4 lines
And here GSO aliases:
TSO_BIT=NETIF_F_GSO_SHIFT+SKB_GSO_TCPV4,UFO_BIT=NETIF_F_GSO_SHIFT+SKB_GSO_UDP,
Ah, this is wrong as SKB_GSO_* are bitmasks. Can be fixed though.
Best Regards,
Michał Mirosław
Re: [PATCHv2] net: Define enum for the bits used in features.
In reply to Michał MirosławQuoted 12 lines · Michał Mirosław
2011/5/25 Mahesh Bandewar <[email protected]>:
Quoted 11 lines
Little bit cleanup by defining enum for all bits used. Also use those enum values to redefine flags.
Signed-off-by Mahesh Bandewar <[email protected]>---
Changes since v1:
Split the patch into two pieces.include/linux/netdevice.h | 100 +++++++++++++++++++++++++++++++-------------
1 files changed, 70 insertions(+), 30 deletions(-)
Quoted 12 lines
include/linux/netdevice.h line 54
Quoted 9 lines
include/linux/netdevice.h +1
-0@@ -51,6 +51,7 @@ #ifdef CONFIG_DCB #include <net/dcbnl.h> #endif +#include <linux/netdev_features.h> This should go to other part.
Ahh! split mishap!
Quoted 25 lines
Quoted 10 lines
include/linux/netdevice.h +4
-0struct vlan_group; struct netpoll_info;@@ -981,6 +982,49 @@ struct net_device_ops { }; /* +* Net device feature bits; if you change something, +* also update netdev_features_strings[] in ethtool.c +*/ +enum netdev_features {[...]
Quoted 8 lines
+
RESERVED16_BIT, /* theGSO_MASKreserved bit 16 */
+RESERVED17_BIT, /* theGSO_MASKreserved bit 17 */
+RESERVED18_BIT, /* theGSO_MASKreserved bit 18 */
+RESERVED19_BIT, /* theGSO_MASKreserved bit 19 */
+RESERVED20_BIT, /* theGSO_MASKreserved bit 20 */
+RESERVED21_BIT, /* theGSO_MASKreserved bit 21 */
+RESERVED22_BIT, /* theGSO_MASKreserved bit 22 */
+RESERVED23_BIT, /* theGSO_MASKreserved bit 23 */This could also define
NETIF_F_GSO_SHIFTand name TSO and others. Maybe like this:
Quoted 7 lines
NETIF_F_GSO_SHIFT, /* must == 16, for now */GSO_RESERVED0_BIT=NETIF_F_GSO_SHIFT,GSO_RESERVED1_BIT,
...GSO_RESERVED7_BIT,
... (other bits)
Yes, I was thinking about that but then thought that itself will deserve a separate patch.
Quoted 12 lines
Quoted 1 line
+ /* Add you bit above this */
your.
Quoted 1 line
+
ND_FEATURE_NUM_BITS, /* (LAST VALUE) Total bits in use */And here GSO aliases:
TSO_BIT=NETIF_F_GSO_SHIFT+SKB_GSO_TCPV4,UFO_BIT=NETIF_F_GSO_SHIFT+SKB_GSO_UDP,
...
Quoted 6 lines
Afther this is done, I can convert the feature-names table in
ethtool.cto use C99 array assignments, so that no one else will trip on a missing comma or wrong entries order there.About the bit names:
NETIF_F_xxx_BIT?
I thought it was getting longer so tried to trim it, but don't have reservations against it.
--mahesh..
Quoted 3 lines
Best Regards,
Michał Mirosław
PATCH v3 1/1 net: Define enum for the bits used in features.
In reply to Mahesh BandewarLittle bit cleanup by defining enum for all bits used. Also use those enum values to redefine flags.
---
Changes since v2:
(1) Removed the include which was part of the other patch (split mishap).
(2) Changed the enums to add NETIF_F_ prefix.
Changes since v1:
Split the patch into two pieces.
include/linux/netdevice.h | 99 +++++++++++++++++++++++++++++++-------------- 1 files changed, 69 insertions(+), 30 deletions(-)
include/linux/netdevice.h +69 -30
@@ -981,6 +981,49 @@ struct net_device_ops { };/* +* Net device feature bits; if you change something, +* also update netdev_features_strings[] in ethtool.c +*/ +enum netdev_features { +NETIF_F_SG_BIT ,/* Scatter/gather IO. */ +NETIF_F_IP_CSUM_BIT ,/* Can checksum TCP/UDP over IPv4. */ +NETIF_F_NO_CSUM_BIT ,/* Does not require checksum. F.e. loopack. */ +NETIF_F_HW_CSUM_BIT ,/* Can checksum all the packets. */ +NETIF_F_IPV6_CSUM_BIT ,/* Can checksum TCP/UDP over IPV6 */ +NETIF_F_HIGHDMA_BIT ,/* Can DMA to high memory. */ +NETIF_F_FRAGLIST_BIT ,/* Scatter/gather IO. */ +NETIF_F_HW_VLAN_TX_BIT ,/* Transmit VLAN hw acceleration */ +NETIF_F_HW_VLAN_RX_BIT ,/* Receive VLAN hw acceleration */ +NETIF_F_HW_VLAN_FILTER_BIT ,/* Receive filtering on VLAN */ +NETIF_F_VLAN_CHALLENGED_BIT ,/* Device cannot handle VLAN packets */ +NETIF_F_GSO_BIT ,/* Enable software GSO. */ +NETIF_F_LLTX_BIT ,/* LockLess TX - deprecated. Please */ +/* do not use LLTX in new drivers */ +NETIF_F_NETNS_LOCAL_BIT ,/* Does not change network namespaces */ +NETIF_F_GRO_BIT ,/* Generic receive offload */ +NETIF_F_LRO_BIT ,/* large receive offload */ +RESERVED16_BIT ,/* the GSO_MASK reserved bit 16 */ +RESERVED17_BIT ,/* the GSO_MASK reserved bit 17 */ +RESERVED18_BIT ,/* the GSO_MASK reserved bit 18 */ +RESERVED19_BIT ,/* the GSO_MASK reserved bit 19 */ +RESERVED20_BIT ,/* the GSO_MASK reserved bit 20 */ +RESERVED21_BIT ,/* the GSO_MASK reserved bit 21 */ +RESERVED22_BIT ,/* the GSO_MASK reserved bit 22 */ +RESERVED23_BIT ,/* the GSO_MASK reserved bit 23 */ +NETIF_F_FCOE_CRC_BIT ,/* FCoE CRC32 */ +NETIF_F_SCTP_CSUM_BIT ,/* SCTP checksum offload */ +NETIF_F_FCOE_MTU_BIT ,/* Supports max FCoE MTU, 2158 bytes*/ +NETIF_F_NTUPLE_BIT ,/* N-tuple filters supported */ +NETIF_F_RXHASH_BIT ,/* Receive hashing offload */ +NETIF_F_RXCSUM_BIT ,/* Receive checksumming offload */ +NETIF_F_NOCACHE_COPY_BIT ,/* Use no-cache copyfromuser */ +NETIF_F_LOOPBACK_BIT ,/* Enable loopback */ + +/* Add you bit above this */ +ND_FEATURE_NUM_BITS /* (LAST VALUE) Total bits in use */ +}; + +/* * The DEVICE structure. * Actually, this whole structure is a big mistake. It mixes I/O * data with strictly "high-level" data, and it has to know about
@@ -1035,36 +1078,32 @@ struct net_device {/* mask of features inheritable by VLAN devices */ u32 vlan_features; -/* Net device feature bits; if you change something, -* also update netdev_features_strings[] in ethtool.c */ - -#define NETIF_F_SG 1/* Scatter/gather IO. */ -#define NETIF_F_IP_CSUM 2/* Can checksum TCP/UDP over IPv4. */ -#define NETIF_F_NO_CSUM 4/* Does not require checksum. F.e. loopack. */ -#define NETIF_F_HW_CSUM 8/* Can checksum all the packets. */ -#define NETIF_F_IPV6_CSUM 16/* Can checksum TCP/UDP over IPV6 */ -#define NETIF_F_HIGHDMA 32/* Can DMA to high memory. */ -#define NETIF_F_FRAGLIST 64/* Scatter/gather IO. */ -#define NETIF_F_HW_VLAN_TX 128/* Transmit VLAN hw acceleration */ -#define NETIF_F_HW_VLAN_RX 256/* Receive VLAN hw acceleration */ -#define NETIF_F_HW_VLAN_FILTER 512/* Receive filtering on VLAN */ -#define NETIF_F_VLAN_CHALLENGED 1024/* Device cannot handle VLAN packets */ -#define NETIF_F_GSO 2048/* Enable software GSO. */ -#define NETIF_F_LLTX 4096/* LockLess TX - deprecated. Please */ -/* do not use LLTX in new drivers */ -#define NETIF_F_NETNS_LOCAL 8192/* Does not change network namespaces */ -#define NETIF_F_GRO 16384/* Generic receive offload */ -#define NETIF_F_LRO 32768/* large receive offload */ - -/* the GSO_MASK reserves bits 16 through 23 */ -#define NETIF_F_FCOE_CRC (1 << 24)/* FCoE CRC32 */ -#define NETIF_F_SCTP_CSUM (1 << 25)/* SCTP checksum offload */ -#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 */ -#define NETIF_F_NOCACHE_COPY (1 << 30)/* Use no-cache copyfromuser */ -#define NETIF_F_LOOPBACK (1 << 31)/* Enable loopback */ +#define BIT2FLAG (bit) (1 << (bit)) + +#define NETIF_F_SG BIT2FLAG(NETIF_F_SG_BIT) +#define NETIF_F_IP_CSUM BIT2FLAG(NETIF_F_IP_CSUM_BIT) +#define NETIF_F_NO_CSUM BIT2FLAG(NETIF_F_NO_CSUM_BIT) +#define NETIF_F_HW_CSUM BIT2FLAG(NETIF_F_HW_CSUM_BIT) +#define NETIF_F_IPV6_CSUM BIT2FLAG(NETIF_F_IPV6_CSUM_BIT) +#define NETIF_F_HIGHDMA BIT2FLAG(NETIF_F_HIGHDMA_BIT) +#define NETIF_F_FRAGLIST BIT2FLAG(NETIF_F_FRAGLIST_BIT) +#define NETIF_F_HW_VLAN_TX BIT2FLAG(NETIF_F_HW_VLAN_TX_BIT) +#define NETIF_F_HW_VLAN_RX BIT2FLAG(NETIF_F_HW_VLAN_RX_BIT) +#define NETIF_F_HW_VLAN_FILTER BIT2FLAG(NETIF_F_HW_VLAN_FILTER_BIT) +#define NETIF_F_VLAN_CHALLENGED BIT2FLAG(NETIF_F_VLAN_CHALLENGED_BIT) +#define NETIF_F_GSO BIT2FLAG(NETIF_F_GSO_BIT) +#define NETIF_F_LLTX BIT2FLAG(NETIF_F_LLTX_BIT) +#define NETIF_F_NETNS_LOCAL BIT2FLAG(NETIF_F_NETNS_LOCAL_BIT) +#define NETIF_F_GRO BIT2FLAG(NETIF_F_GRO_BIT) +#define NETIF_F_LRO BIT2FLAG(NETIF_F_LRO_BIT) +#define NETIF_F_FCOE_CRC BIT2FLAG(NETIF_F_FCOE_CRC_BIT) +#define NETIF_F_SCTP_CSUM BIT2FLAG(NETIF_F_SCTP_CSUM_BIT) +#define NETIF_F_FCOE_MTU BIT2FLAG(NETIF_F_FCOE_MTU_BIT) +#define NETIF_F_NTUPLE BIT2FLAG(NETIF_F_NTUPLE_BIT) +#define NETIF_F_RXHASH BIT2FLAG(NETIF_F_RXHASH_BIT) +#define NETIF_F_RXCSUM BIT2FLAG(NETIF_F_RXCSUM_BIT) +#define NETIF_F_NOCACHE_COPY BIT2FLAG(NETIF_F_NOCACHE_COPY_BIT) +#define NETIF_F_LOOPBACK BIT2FLAG(NETIF_F_LOOPBACK_BIT)/* Segmentation offload features */ #define NETIF_F_GSO_SHIFT 16
Signature · 1 line
1.7.3.1
Re: [PATCHv3] net: Define enum for the bits used in features.
2011/5/26 Mahesh Bandewar <[email protected]>:
Quoted 2 lines
Little bit cleanup by defining enum for all bits used. Also use those enum values to redefine flags.
[...]
This BIT2FLAG macro just obfuscates the code (and gives you more characters to read).
I'd also prefer this patch included the GSO/TSO bits and they are logically part of this cleanup. But if you think it's easier to review split, then that's fine by me.
Best Regards,
Michał Mirosław
RFC PATCH 1/1 net: ethtool: use C99 array initialization for feature-names table
This depends on Mahesh Bandewar's cleanup of feature bits.
Note: This is why I'd like that patch to include TSO bits as well, so I can get rid of this ugly NETIF_F_GSO_SHIFT+n.
--- net/core/ethtool.c | 65 +++++++++++++++++++++++++-------------------------- 1 files changed, 32 insertions(+), 33 deletions(-)
net/core/ethtool.c +32 -33
@@ -350,42 +350,41 @@ static int ethtool_set_features(struct net_device *dev, void __user *useraddr)return ret; } -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" , -/* NETIF_F_NO_CSUM */ "tx-checksum-unneeded" , -/* NETIF_F_HW_CSUM */ "tx-checksum-ip-generic" , -/* NETIF_F_IPV6_CSUM */ "tx-checksum-ipv6" , -/* NETIF_F_HIGHDMA */ "highdma" , -/* NETIF_F_FRAGLIST */ "tx-scatter-gather-fraglist" , -/* NETIF_F_HW_VLAN_TX */ "tx-vlan-hw-insert" , +static const char netdev_features_strings[ND_FEATURE_NUM_BITS ][ETH_GSTRING_LEN ] = { + [NETIF_F_SG_BIT ] ="tx-scatter-gather" , + [NETIF_F_IP_CSUM_BIT ] ="tx-checksum-ipv4" , + [NETIF_F_NO_CSUM_BIT ] ="tx-checksum-unneeded" , + [NETIF_F_HW_CSUM_BIT ] ="tx-checksum-ip-generic" , + [NETIF_F_IPV6_CSUM_BIT ] ="tx-checksum-ipv6" , + [NETIF_F_HIGHDMA_BIT ] ="highdma" , + [NETIF_F_FRAGLIST_BIT ] ="tx-scatter-gather-fraglist" , + [NETIF_F_HW_VLAN_TX_BIT ] ="tx-vlan-hw-insert" , -/* NETIF_F_HW_VLAN_RX */ "rx-vlan-hw-parse" , -/* NETIF_F_HW_VLAN_FILTER */ "rx-vlan-filter" , -/* NETIF_F_VLAN_CHALLENGED */ "vlan-challenged" , -/* NETIF_F_GSO */ "tx-generic-segmentation" , -/* NETIF_F_LLTX */ "tx-lockless" , -/* NETIF_F_NETNS_LOCAL */ "netns-local" , -/* NETIF_F_GRO */ "rx-gro" , -/* NETIF_F_LRO */ "rx-lro" , + [NETIF_F_HW_VLAN_RX_BIT ] ="rx-vlan-hw-parse" , + [NETIF_F_HW_VLAN_FILTER_BIT ] ="rx-vlan-filter" , + [NETIF_F_VLAN_CHALLENGED_BIT ] ="vlan-challenged" , + [NETIF_F_GSO_BIT ] ="tx-generic-segmentation" , + [NETIF_F_LLTX_BIT ] ="tx-lockless" , + [NETIF_F_NETNS_LOCAL_BIT ] ="netns-local" , + [NETIF_F_GRO_BIT ] ="rx-gro" , + [NETIF_F_LRO_BIT ] ="rx-lro" , -/* NETIF_F_TSO */ "tx-tcp-segmentation" , -/* NETIF_F_UFO */ "tx-udp-fragmentation" , -/* NETIF_F_GSO_ROBUST */ "tx-gso-robust" , -/* NETIF_F_TSO_ECN */ "tx-tcp-ecn-segmentation" , -/* NETIF_F_TSO6 */ "tx-tcp6-segmentation" , -/* NETIF_F_FSO */ "tx-fcoe-segmentation" , -"" , -"" , +/* must match SKB_GSO_* order */ + [NETIF_F_GSO_SHIFT +0 ] ="tx-tcp-segmentation" , + [NETIF_F_GSO_SHIFT +1 ] ="tx-udp-fragmentation" , + [NETIF_F_GSO_SHIFT +2 ] ="tx-gso-robust" , + [NETIF_F_GSO_SHIFT +3 ] ="tx-tcp-ecn-segmentation" , + [NETIF_F_GSO_SHIFT +4 ] ="tx-tcp6-segmentation" , + [NETIF_F_GSO_SHIFT +5 ] ="tx-fcoe-segmentation" , -/* NETIF_F_FCOE_CRC */ "tx-checksum-fcoe-crc" , -/* NETIF_F_SCTP_CSUM */ "tx-checksum-sctp" , -/* NETIF_F_FCOE_MTU */ "fcoe-mtu" , -/* NETIF_F_NTUPLE */ "rx-ntuple-filter" , -/* NETIF_F_RXHASH */ "rx-hashing" , -/* NETIF_F_RXCSUM */ "rx-checksum" , -/* NETIF_F_NOCACHE_COPY */ "tx-nocache-copy" , -/* NETIF_F_LOOPBACK */ "loopback" , + [NETIF_F_FCOE_CRC_BIT ] ="tx-checksum-fcoe-crc" , + [NETIF_F_SCTP_CSUM_BIT ] ="tx-checksum-sctp" , + [NETIF_F_FCOE_MTU_BIT ] ="fcoe-mtu" , + [NETIF_F_NTUPLE_BIT ] ="rx-ntuple-filter" , + [NETIF_F_RXHASH_BIT ] ="rx-hashing" , + [NETIF_F_RXCSUM_BIT ] ="rx-checksum" , + [NETIF_F_NOCACHE_COPY_BIT ] ="tx-nocache-copy" , + [NETIF_F_LOOPBACK_BIT ] ="loopback" , };static int __ethtool_get_sset_count (struct net_device *dev,int sset)
Signature · 1 line
1.7.2.5
David Miller
maintainerRe: [PATCHv3] net: Define enum for the bits used in features.
In reply to Mahesh BandewarFrom: Mahesh Bandewar <[email protected]>
Date: Wed, 25 May 2011 15:42:16 -0700
Quoted 8 lines
Little bit cleanup by defining enum for all bits used. Also use those enum values to redefine flags.
Signed-off-by Mahesh Bandewar <[email protected]>---
Changes since v2:
(1) Removed the include which was part of the other patch (split mishap).
(2) Changed the enums to addNETIF_F_prefix.
I hate to be a pain after you've put so much work into these patches, but I simply don't like this approach.
I think the abstracted interfaces should come first. You don't need to change any of the NETIF_F_* defines in order to do that. You should only need to add the netdev_{set,clear,test}_*() macros.
If you want you can make the "bit" argument be the flag name after the NETIF_F_ prefix, so "netdev_test_active_feature(dev, SG)"
Then you convert every single access.
Then you make the flags type opaque, which should at that point be a 6 line change at best.
And then you can implement the flags however you want.
Re: [PATCHv3] net: Define enum for the bits used in features.
Quoted 22 lines · David Miller
From: Mahesh Bandewar <[email protected]>
Date: Wed, 25 May 2011 15:42:16 -0700Quoted 8 lines
Little bit cleanup by defining enum for all bits used. Also use those enum values to redefine flags.
Signed-off-by Mahesh Bandewar <[email protected]>---
Changes since v2:
(1) Removed the include which was part of the other patch (split mishap).
(2) Changed the enums to addNETIF_F_prefix.I hate to be a pain after you've put so much work into these patches, but I simply don't like this approach.
I think the abstracted interfaces should come first. You don't need to change any of the NETIF_F_* defines in order to do that. You should only need to add the netdev_{set,clear,test}_*() macros.
If you want you can make the "bit" argument be the flag name after the
NETIF_F_prefix, so "netdev_test_active_feature(dev, SG)"
Quoted 6 lines
Then you convert every single access.
Then you make the flags type opaque, which should at that point be a 6 line change at best.
And then you can implement the flags however you want.
I've been thinking about this as well. It turns out most things above can be done with the spatch (aka coccinelle) tool. But I think the largest problem is what to do with multiple-feature macros such as NETIF_F_GSO_SOFTWARE.
If we keep them an 'or' of bits, we more or less commit to an implementation that can represent them all in a single constant.
I played with variadic macros but could not come up with something that does not generate a lot of code.
Ideas?
Signature · 1 line
MST
David Miller
maintainerRe: [PATCHv3] net: Define enum for the bits used in features.
From: "Michael S. Tsirkin" <[email protected]>
Date: Mon, 6 Jun 2011 06:58:08 +0300
Quoted 11 lines
I've been thinking about this as well. It turns out most things above can be done with the spatch (aka coccinelle) tool. But I think the largest problem is what to do with multiple-feature macros such as
NETIF_F_GSO_SOFTWARE.If we keep them an 'or' of bits, we more or less commit to an implementation that can represent them all in a single constant.
I played with variadic macros but could not come up with something that does not generate a lot of code.
Since the GSO accessors deal with mutliple bits, you can create special GSO specific interfaces to manipulate them.
Re: [PATCHv3] net: Define enum for the bits used in features.
Quoted 12 lines · David Miller
From: "Michael S. Tsirkin" <[email protected]>
Date: Mon, 6 Jun 2011 06:58:08 +0300Quoted 9 lines
I've been thinking about this as well. It turns out most things above can be done with the spatch (aka coccinelle) tool. But I think the largest problem is what to do with multiple-feature macros such as
NETIF_F_GSO_SOFTWARE.If we keep them an 'or' of bits, we more or less commit to an implementation that can represent them all in a single constant.
Quoted 5 lines
Quoted 2 lines
I played with variadic macros but could not come up with something that does not generate a lot of code.
Since the GSO accessors deal with mutliple bits, you can create special GSO specific interfaces to manipulate them.
Yes but it's not just GSO.
It's anything that includes more than 1 feature.
Examples:NETIF_F_ALL_CSUMNETIF_F_ALL_TX_OFFLOADSNETIF_F_V6_CSUMNETIF_F_SOFT_FEATURES
etc
Creating many accessors for each will need a lot
of code duplication ...
Signature · 1 line
MST
David Miller
maintainerRe: [PATCHv3] net: Define enum for the bits used in features.
From: "Michael S. Tsirkin" <[email protected]>
Date: Mon, 6 Jun 2011 18:32:53 +0300
Quoted 12 lines · David Miller
Quoted 2 lines
Since the GSO accessors deal with mutliple bits, you can create special GSO specific interfaces to manipulate them.
Yes but it's not just GSO.
It's anything that includes more than 1 feature.
Examples:NETIF_F_ALL_CSUMNETIF_F_ALL_TX_OFFLOADSNETIF_F_V6_CSUMNETIF_F_SOFT_FEATURES
Quoted 4 lines
etc
Creating many accessors for each will need a lot
of code duplication ...
Yet this is something you must resolve in order to change the feature bit implementation.
Whether this issue is difficult or not to address, it has to be done either way.
Re: [PATCHv3] net: Define enum for the bits used in features.
Quoted 17 lines · David Miller
From: "Michael S. Tsirkin" <[email protected]>
Date: Mon, 6 Jun 2011 18:32:53 +0300Quoted 14 lines · David Miller
Quoted 2 lines
Since the GSO accessors deal with mutliple bits, you can create special GSO specific interfaces to manipulate them.
Yes but it's not just GSO.
It's anything that includes more than 1 feature.
Examples:NETIF_F_ALL_CSUMNETIF_F_ALL_TX_OFFLOADSNETIF_F_V6_CSUMNETIF_F_SOFT_FEATURESetc
Quoted 8 lines
Quoted 2 lines
Creating many accessors for each will need a lot
of code duplication ...Yet this is something you must resolve in order to change the feature bit implementation.
Whether this issue is difficult or not to address, it has to be done either way.
I think I found a truly elegant solution to this problem which this margin is too narrow to contain ...
Signature · 1 line
MST
Re: [PATCHv3] net: Define enum for the bits used in features.
Quoted 21 lines · Michael S. Tsirkin
Quoted 20 lines · David Miller
From: "Michael S. Tsirkin" <[email protected]>
Date: Mon, 6 Jun 2011 18:32:53 +0300Quoted 16 lines · David Miller
Quoted 2 lines
Since the GSO accessors deal with mutliple bits, you can create special GSO specific interfaces to manipulate them.
Yes but it's not just GSO.
It's anything that includes more than 1 feature.
Examples:NETIF_F_ALL_CSUMNETIF_F_ALL_TX_OFFLOADSNETIF_F_V6_CSUMNETIF_F_SOFT_FEATURESetc
Creating many accessors for each will need a lot
of code duplication ...
Quoted 8 lines
Quoted 5 lines
Yet this is something you must resolve in order to change the feature bit implementation.
Whether this issue is difficult or not to address, it has to be done either way.
I think I found a truly elegant solution to this problem which this margin is too narrow to contain ...
OK, it looks like using variadic macros from C99 makes this possible, even though use of ungarded comma in macros below makes me cringe:
/* Set all bits in the first 64 arguments, ignore the rest */
#define NETIF_F_OR_64( \ _000, _001 , _002 , _003 , _004 , _005 , _006 , _007, \ _010, _011 , _012 , _013 , _014 , _015 , _016 , _017, \ _020, _021 , _022 , _023 , _024 , _025 , _026 , _027, \ _030, _031 , _032 , _033 , _034 , _035 , _036 , _037, \ _040, _041 , _042 , _043 , _044 , _045 , _046 , _047, \ _050, _051 , _052 , _053 , _054 , _055 , _056 , _057, \ _060, _061 , _062 , _063 , _064 , _065 , _066 , _067, \ _070, _071 , _072 , _073 , _074 , _075 , _076 , _077, \ ... ) \ ((_000) | (_001) | (_002) | (_003) | (_004) | (_005) | (_006) | (_007) | \ (_010) | (_011) | (_012) | (_013) | (_014) | (_015) | (_016) | (_017) | \ (_020) | (_021) | (_022) | (_023) | (_024) | (_025) | (_026) | (_027) | \ (_030) | (_031) | (_032) | (_033) | (_034) | (_035) | (_036) | (_037) | \ (_040) | (_041) | (_042) | (_043) | (_044) | (_045) | (_046) | (_047) | \ (_050) | (_051) | (_052) | (_053) | (_054) | (_055) | (_056) | (_057) | \ (_060) | (_061) | (_062) | (_063) | (_064) | (_065) | (_066) | (_067) | \ (_070) | (_071) | (_072) | (_073) | (_074) | (_075) | (_076) | (_077) )
/* Verify that argument #65 is zero */
#define NETIF_F_BUG_ON_64( \ _000, _001 , _002 , _003 , _004 , _005 , _006 , _007, \ _010, _011 , _012 , _013 , _014 , _015 , _016 , _017, \ _020, _021 , _022 , _023 , _024 , _025 , _026 , _027, \ _030, _031 , _032 , _033 , _034 , _035 , _036 , _037, \ _040, _041 , _042 , _043 , _044 , _045 , _046 , _047, \ _050, _051 , _052 , _053 , _054 , _055 , _056 , _057, \ _060, _061 , _062 , _063 , _064 , _065 , _066 , _067, \ _070, _071 , _072 , _073 , _074 , _075 , _076 , _077, \ _100, ... ) \ BUG_ON((_100))
/* Set multiple bits in f. At most 64 bits can be
* set in this way.
* Nested calls are padded with 0 arguments
* to ensure there are at least 64 of them */
#define NETIF_F_INIT(f, ...) do { \
f |= NETIF_F_OR_64(__VA_ARGS__, \
0, 0, 0, 0, 0, 0, 0, 0,\
0, 0, 0, 0, 0, 0, 0, 0,\
0, 0, 0, 0, 0, 0, 0, 0,\
0, 0, 0, 0, 0, 0, 0, 0,\
0, 0, 0, 0, 0, 0, 0, 0,\
0, 0, 0, 0, 0, 0, 0, 0,\
0, 0, 0, 0, 0, 0, 0, 0,\
0, 0, 0, 0, 0, 0, 0, 0 \
); \
NETIF_F_BUG_ON_64(__VA_ARGS__, \
0, 0, 0, 0, 0, 0, 0, 0,\
0, 0, 0, 0, 0, 0, 0, 0,\
0, 0, 0, 0, 0, 0, 0, 0,\
0, 0, 0, 0, 0, 0, 0, 0,\
0, 0, 0, 0, 0, 0, 0, 0,\
0, 0, 0, 0, 0, 0, 0, 0,\
0, 0, 0, 0, 0, 0, 0, 0,\
0, 0, 0, 0, 0, 0, 0, 0 \
); \
} while (0)And now:
#define NETIF_F_GSO_SOFTWARE NETIF_F_TSO , NETIF_F_TSO_ECN , \
NETIF_F_TSO6 , NETIF_F_UFO
which makes
NETIF_F_INIT(z, NETIF_F_GSO_SOFTWARE);
work as expected, and set all necessary bits,
so all we need to do is replace
z = NETIF_F_GSO_SOFTWARE;
with call to macro above.
At most 64 different bits can be passed in this way but NETIF_F_BUG_ON_64 above checks that.
If we want more than 64 bits, we just update these macro definitions.
It seems that behaviour above is guaranteed by the language spec, specifically the argument prescan rule.
Any C99 experts want to comment on this?
I have my doubts about whether the above is way too clever even if it works. What do others think?
Quoted 2 lines
Signature · 1 line
MST
Re: [PATCHv3] net: Define enum for the bits used in features.
Quoted 86 lines · Michael S. Tsirkin
Quoted 21 lines · Michael S. Tsirkin
Quoted 20 lines · David Miller
From: "Michael S. Tsirkin" <[email protected]>
Date: Mon, 6 Jun 2011 18:32:53 +0300Quoted 16 lines · David Miller
Quoted 2 lines
Since the GSO accessors deal with mutliple bits, you can create special GSO specific interfaces to manipulate them.
Yes but it's not just GSO.
It's anything that includes more than 1 feature.
Examples:NETIF_F_ALL_CSUMNETIF_F_ALL_TX_OFFLOADSNETIF_F_V6_CSUMNETIF_F_SOFT_FEATURESetc
Creating many accessors for each will need a lot
of code duplication ...Quoted 8 lines
Quoted 5 lines
Yet this is something you must resolve in order to change the feature bit implementation.
Whether this issue is difficult or not to address, it has to be done either way.
I think I found a truly elegant solution to this problem which this margin is too narrow to contain ...
OK, it looks like using variadic macros from C99 makes this possible, even though use of ungarded comma in macros below makes me cringe:
/* Set all bits in the first 64 arguments, ignore the rest */
#define NETIF_F_OR_64( \ _000, _001 , _002 , _003 , _004 , _005 , _006 , _007, \ _010, _011 , _012 , _013 , _014 , _015 , _016 , _017, \ _020, _021 , _022 , _023 , _024 , _025 , _026 , _027, \ _030, _031 , _032 , _033 , _034 , _035 , _036 , _037, \ _040, _041 , _042 , _043 , _044 , _045 , _046 , _047, \ _050, _051 , _052 , _053 , _054 , _055 , _056 , _057, \ _060, _061 , _062 , _063 , _064 , _065 , _066 , _067, \ _070, _071 , _072 , _073 , _074 , _075 , _076 , _077, \ ... ) \ ((_000) | (_001) | (_002) | (_003) | (_004) | (_005) | (_006) | (_007) | \ (_010) | (_011) | (_012) | (_013) | (_014) | (_015) | (_016) | (_017) | \ (_020) | (_021) | (_022) | (_023) | (_024) | (_025) | (_026) | (_027) | \ (_030) | (_031) | (_032) | (_033) | (_034) | (_035) | (_036) | (_037) | \ (_040) | (_041) | (_042) | (_043) | (_044) | (_045) | (_046) | (_047) | \ (_050) | (_051) | (_052) | (_053) | (_054) | (_055) | (_056) | (_057) | \ (_060) | (_061) | (_062) | (_063) | (_064) | (_065) | (_066) | (_067) | \ (_070) | (_071) | (_072) | (_073) | (_074) | (_075) | (_076) | (_077) )/* Verify that argument #65 is zero */
#define NETIF_F_BUG_ON_64( \ _000, _001 , _002 , _003 , _004 , _005 , _006 , _007, \ _010, _011 , _012 , _013 , _014 , _015 , _016 , _017, \ _020, _021 , _022 , _023 , _024 , _025 , _026 , _027, \ _030, _031 , _032 , _033 , _034 , _035 , _036 , _037, \ _040, _041 , _042 , _043 , _044 , _045 , _046 , _047, \ _050, _051 , _052 , _053 , _054 , _055 , _056 , _057, \ _060, _061 , _062 , _063 , _064 , _065 , _066 , _067, \ _070, _071 , _072 , _073 , _074 , _075 , _076 , _077, \ _100, ... ) \ BUG_ON((_100))/* Set multiple bits in f. At most 64 bits can be
* set in this way.
* Nested calls are padded with 0 arguments
* to ensure there are at least 64 of them */#define NETIF_F_INIT(f, ...) do { \ f |= NETIF_F_OR_64(__VA_ARGS__, \ 0, 0, 0, 0, 0, 0, 0, 0,\ 0, 0, 0, 0, 0, 0, 0, 0,\ 0, 0, 0, 0, 0, 0, 0, 0,\ 0, 0, 0, 0, 0, 0, 0, 0,\ 0, 0, 0, 0, 0, 0, 0, 0,\ 0, 0, 0, 0, 0, 0, 0, 0,\ 0, 0, 0, 0, 0, 0, 0, 0,\ 0, 0, 0, 0, 0, 0, 0, 0 \ ); \ NETIF_F_BUG_ON_64(__VA_ARGS__, \ 0, 0, 0, 0, 0, 0, 0, 0,\ 0, 0, 0, 0, 0, 0, 0, 0,\
Quoted 8 lines
0, 0, 0, 0, 0, 0, 0, 0,\ 0, 0, 0, 0, 0, 0, 0, 0,\ 0, 0, 0, 0, 0, 0, 0, 0,\ 0, 0, 0, 0, 0, 0, 0, 0,\ 0, 0, 0, 0, 0, 0, 0, 0,\ 0, 0, 0, 0, 0, 0, 0, 0 \ ); \ } while (0)
One thing I realized is there's no reason for NETIF_F_INIT to get the ellipsis ... as we don't want users to pass arbitrary lists of features, just the predefined sets. So this can be a simpler:
#define NETIF_F_INIT(f, bits) do { \
f |= NETIF_F_OR_64(bits, \
0, 0, 0, 0, 0, 0, 0, 0,\
0, 0, 0, 0, 0, 0, 0, 0,\
0, 0, 0, 0, 0, 0, 0, 0,\
0, 0, 0, 0, 0, 0, 0, 0,\
0, 0, 0, 0, 0, 0, 0, 0,\
0, 0, 0, 0, 0, 0, 0, 0,\
0, 0, 0, 0, 0, 0, 0, 0,\
0, 0, 0, 0, 0, 0, 0, 0 \
);
Quoted 14 lines
And now:
#defineNETIF_F_GSO_SOFTWARENETIF_F_TSO,NETIF_F_TSO_ECN, \
NETIF_F_TSO6,NETIF_F_UFOwhich makes
NETIF_F_INIT(z, NETIF_F_GSO_SOFTWARE);work as expected, and set all necessary bits,
so all we need to do is replacez = NETIF_F_GSO_SOFTWARE;with call to macro above.
Quoted 8 lines
At most 64 different bits can be passed in this way but
NETIF_F_BUG_ON_64above checks that.
If we want more than 64 bits, we just update these macro definitions.It seems that behaviour above is guaranteed by the language spec, specifically the argument prescan rule.
Any C99 experts want to comment on this?
OK, the confirmation was located in C99 standard, chapter 6.10.3.1 Argument substitution.
Quoted 6 lines
I have my doubts about whether the above is way too clever even if it works. What do others think?
Quoted 2 lines
Signature · 1 line
MST
Re: [PATCHv3] net: Define enum for the bits used in features.
In reply to David MillerQuoted 17 lines · David Miller
From: "Michael S. Tsirkin" <[email protected]>
Date: Mon, 6 Jun 2011 18:32:53 +0300Quoted 14 lines · David Miller
Quoted 2 lines
Since the GSO accessors deal with mutliple bits, you can create special GSO specific interfaces to manipulate them.
Yes but it's not just GSO.
It's anything that includes more than 1 feature.
Examples:NETIF_F_ALL_CSUMNETIF_F_ALL_TX_OFFLOADSNETIF_F_V6_CSUMNETIF_F_SOFT_FEATURESetc
Quoted 9 lines
Quoted 2 lines
Creating many accessors for each will need a lot
of code duplication ...Yet this is something you must resolve in order to change the feature bit implementation.
Whether this issue is difficult or not to address, it has to be done either way.
I agree that the cleanup is not really necessary to the feature extension as such but this along with the other patch that I have posted is the beginning of that work. It's definitely not complete and also not as simple as it sounds / feels because of these constants defined which are "or-ed" flag values (listed above). I think it will be nice to get this done in as little code as possible, but I think that should be the constraint.
In these two patches I have created separate header file "netdev_features.h" where everything related to "features" should reside including all these accessor macros / functions.
--mahesh..
Re: [PATCHv3] net: Define enum for the bits used in features.
In reply to David Miller2011/6/4 David Miller <[email protected]>:
Quoted 11 lines
From: Mahesh Bandewar <[email protected]>
Date: Wed, 25 May 2011 15:42:16 -0700Quoted 8 lines
Little bit cleanup by defining enum for all bits used. Also use those enum values to redefine flags.
Signed-off-by Mahesh Bandewar <[email protected]>---
Changes since v2:
(1) Removed the include which was part of the other patch (split mishap).
(2) Changed the enums to addNETIF_F_prefix.
Quoted 6 lines
I hate to be a pain after you've put so much work into these patches, but I simply don't like this approach.
I think the abstracted interfaces should come first. You don't need to change any of the NETIF_F_* defines in order to do that. You should only need to add the netdev_{set,clear,test}_*() macros.
I suggested that it's better to first introduce the enum because it can be used right away (e.g. in ethtool.c feature name table). Whatever the new access scheme will be, it will also use that enum.
Best Regards,
Michał Mirosław