For the prototype of netdev_features_t will be changed from u64 to unsigned long *, so it's necessary to add a set of helpers to do the logic operation.
This is a temporary patch, used to compatible with the current prototype of netdev_features_t. The parameters styles are not consistent for among these helpers, in order to minimize the modification when change the netdev_features_t to bitmap.
It also introduce a new macro NETDEV_FEATURE_DWORDS, used for scenario define the features as an array, so it can be initialized when define structure.
Signed-off-by: Jian Shen shenjian15@huawei.com --- include/linux/netdev_features.h | 135 ++++++++++++++++++++++++++++++++ 1 file changed, 135 insertions(+)
diff --git a/include/linux/netdev_features.h b/include/linux/netdev_features.h index 2c6b9e416225..b3fa05c88eef 100644 --- a/include/linux/netdev_features.h +++ b/include/linux/netdev_features.h @@ -101,6 +101,8 @@ enum { /**/NETDEV_FEATURE_COUNT };
+#define NETDEV_FEATURE_DWORDS DIV_ROUND_UP(NETDEV_FEATURE_COUNT, 64) + /* copy'n'paste compression ;) */ #define __NETIF_F_BIT(bit) ((netdev_features_t)1 << (bit)) #define __NETIF_F(name) __NETIF_F_BIT(NETIF_F_##name##_BIT) @@ -261,4 +263,137 @@ static inline int find_next_netdev_feature(u64 feature, unsigned long start) NETIF_F_GSO_UDP_TUNNEL | \ NETIF_F_GSO_UDP_TUNNEL_CSUM)
+static inline void netdev_feature_zero(netdev_features_t *dst) +{ + *dst = 0; +} + +static inline void netdev_feature_fill(netdev_features_t *dst) +{ + *dst = ~0; +} + +static inline void netdev_feature_copy(netdev_features_t *dst, + const netdev_features_t src) +{ + *dst = src; +} + +static inline void netdev_feature_and(netdev_features_t *dst, + const netdev_features_t a, + const netdev_features_t b) +{ + *dst = a & b; +} + +static inline void netdev_feature_or(netdev_features_t *dst, + const netdev_features_t a, + const netdev_features_t b) +{ + *dst = a | b; +} + +static inline void netdev_feature_xor(netdev_features_t *dst, + const netdev_features_t a, + const netdev_features_t b) +{ + *dst = a ^ b; +} + +static inline bool netdev_feature_empty(netdev_features_t src) +{ + return src == 0; +} + +static inline bool netdev_feature_equal(const netdev_features_t src1, + const netdev_features_t src2) +{ + return src1 == src2; +} + +static inline int netdev_feature_andnot(netdev_features_t *dst, + const netdev_features_t src1, + const netdev_features_t src2) +{ + *dst = src1 & ~src2; + return 0; +} + +static inline void netdev_feature_set_bit(int nr, netdev_features_t *addr) +{ + *addr |= __NETIF_F_BIT(nr); +} + +static inline void netdev_feature_clear_bit(int nr, netdev_features_t *addr) +{ + *addr &= ~(__NETIF_F_BIT(nr)); +} + +static inline void netdev_feature_mod_bit(int nr, netdev_features_t *addr, + int set) +{ + if (set) + netdev_feature_set_bit(nr, addr); + else + netdev_feature_clear_bit(nr, addr); +} + +static inline void netdev_feature_change_bit(int nr, netdev_features_t *addr) +{ + *addr ^= __NETIF_F_BIT(nr); +} + +static inline int netdev_feature_test_bit(int nr, const netdev_features_t addr) +{ + return (addr & __NETIF_F_BIT(nr)) > 0; +} + +static inline void netdev_feature_set_bit_array(const int *array, + int array_size, + netdev_features_t *addr) +{ + int i; + + for (i = 0; i < array_size; i++) + netdev_feature_set_bit(array[i], addr); +} + +/* only be used for the first 64 bits features */ +static inline void netdev_feature_set_bits(u64 bits, netdev_features_t *addr) +{ + *addr |= bits; +} + +/* only be used for the first 64 bits features */ +static inline void netdev_feature_clear_bits(u64 bits, netdev_features_t *addr) +{ + *addr &= ~bits; +} + +/* only be used for the first 64 bits features */ +static inline bool netdev_feature_test_bits(u64 bits, + const netdev_features_t addr) +{ + return (addr & bits) > 0; +} + +/* only be used for the first 64 bits features */ +static inline void netdev_feature_and_bits(u64 bits, + netdev_features_t *addr) +{ + *addr &= bits; +} + +static inline int netdev_feature_intersects(const netdev_features_t src1, + const netdev_features_t src2) +{ + return (src1 & src2) > 0; +} + +static inline int netdev_feature_subset(const netdev_features_t src1, + const netdev_features_t src2) +{ + return (src1 & src2) == src2; +} + #endif /* _LINUX_NETDEV_FEATURES_H */