在 2021/8/11 22:44, Jian Shen 写道:
Use netdev_feature_xxx helpers to replace the logical operation for netdev features.
Signed-off-by: Jian Shen shenjian15@huawei.com
include/linux/if_vlan.h | 16 ++++++++++------ net/8021q/vlan.c | 11 +++++++---- net/8021q/vlan.h | 22 ++++++++++++---------- net/8021q/vlan_core.c | 6 ++++-- net/8021q/vlan_dev.c | 47 ++++++++++++++++++++++++++++------------------- 5 files changed, 61 insertions(+), 41 deletions(-)
diff --git a/include/linux/if_vlan.h b/include/linux/if_vlan.h index 2337538..9696e7a 100644 --- a/include/linux/if_vlan.h +++ b/include/linux/if_vlan.h @@ -313,9 +313,11 @@ static inline bool eth_type_vlan(__be16 ethertype) static inline bool vlan_hw_offload_capable(netdev_features_t features, __be16 proto) {
- if (proto == htons(ETH_P_8021Q) && features & NETIF_F_HW_VLAN_CTAG_TX)
- if (proto == htons(ETH_P_8021Q) &&
return true;netdev_feature_test_bit(NETIF_F_HW_VLAN_CTAG_TX_BIT, features))
- if (proto == htons(ETH_P_8021AD) && features & NETIF_F_HW_VLAN_STAG_TX)
- if (proto == htons(ETH_P_8021AD) &&
return true; return false; }netdev_feature_test_bit(NETIF_F_HW_VLAN_STAG_TX_BIT, features))
@@ -563,7 +565,8 @@ static inline int __vlan_hwaccel_get_tag(const struct sk_buff *skb, */ static inline int vlan_get_tag(const struct sk_buff *skb, u16 *vlan_tci) {
- if (skb->dev->features & NETIF_F_HW_VLAN_CTAG_TX) {
- if (netdev_feature_test_bit(NETIF_F_HW_VLAN_CTAG_TX_BIT,
return __vlan_hwaccel_get_tag(skb, vlan_tci); } else { return __vlan_get_tag(skb, vlan_tci);skb->dev->features)) {
@@ -736,9 +739,10 @@ static inline void vlan_features_check(struct sk_buff *skb, * sure that only devices supporting NETIF_F_HW_CSUM will * have checksum offloading support. */
*features &= NETIF_F_SG | NETIF_F_HIGHDMA | NETIF_F_HW_CSUM |
NETIF_F_FRAGLIST | NETIF_F_HW_VLAN_CTAG_TX |
NETIF_F_HW_VLAN_STAG_TX;
netdev_feature_clear_bits(NETIF_F_SG | NETIF_F_HIGHDMA |
NETIF_F_HW_CSUM | NETIF_F_FRAGLIST |
NETIF_F_HW_VLAN_CTAG_TX |
} }NETIF_F_HW_VLAN_STAG_TX, features);
diff --git a/net/8021q/vlan.c b/net/8021q/vlan.c index 55275ef..8a50def 100644 --- a/net/8021q/vlan.c +++ b/net/8021q/vlan.c @@ -134,7 +134,8 @@ int vlan_check_real_dev(struct net_device *real_dev, { const char *name = real_dev->name;
- if (real_dev->features & NETIF_F_VLAN_CHALLENGED) {
- if (netdev_feature_test_bit(NETIF_F_VLAN_CHALLENGED_BIT,
pr_info("VLANs not supported on %s\n", name); NL_SET_ERR_MSG_MOD(extack, "VLANs not supported on device"); return -EOPNOTSUPP;real_dev->features)) {
@@ -339,7 +340,7 @@ static void vlan_transfer_features(struct net_device *dev,
vlandev->priv_flags &= ~IFF_XMIT_DST_RELEASE; vlandev->priv_flags |= (vlan->real_dev->priv_flags & IFF_XMIT_DST_RELEASE);
- vlandev->hw_enc_features = vlan_tnl_features(vlan->real_dev);
vlan_tnl_features(vlan->real_dev, &vlandev->hw_enc_features);
netdev_update_features(vlandev); }
@@ -386,13 +387,15 @@ static int vlan_device_event(struct notifier_block *unused, unsigned long event, }
if ((event == NETDEV_UP) &&
(dev->features & NETIF_F_HW_VLAN_CTAG_FILTER)) {
netdev_feature_test_bit(NETIF_F_HW_VLAN_CTAG_FILTER_BIT,
pr_info("adding VLAN 0 to HW filter on device %s\n", dev->name); vlan_vid_add(dev, htons(ETH_P_8021Q), 0); } if (event == NETDEV_DOWN &&dev->features)) {
(dev->features & NETIF_F_HW_VLAN_CTAG_FILTER))
netdev_feature_test_bit(NETIF_F_HW_VLAN_CTAG_FILTER_BIT,
dev->features))
vlan_vid_del(dev, htons(ETH_P_8021Q), 0);
vlan_info = rtnl_dereference(dev->vlan_info);
diff --git a/net/8021q/vlan.h b/net/8021q/vlan.h index 1a705a4..10b792e 100644 --- a/net/8021q/vlan.h +++ b/net/8021q/vlan.h @@ -103,17 +103,19 @@ static inline struct net_device *vlan_find_dev(struct net_device *real_dev, return NULL; }
-static inline netdev_features_t vlan_tnl_features(struct net_device *real_dev) +static inline void vlan_tnl_features(struct net_device *real_dev,
{netdev_features_t *tnl)
- netdev_features_t ret;
- ret = real_dev->hw_enc_features &
(NETIF_F_CSUM_MASK | NETIF_F_GSO_SOFTWARE |
NETIF_F_GSO_ENCAP_ALL);
- if ((ret & NETIF_F_GSO_ENCAP_ALL) && (ret & NETIF_F_CSUM_MASK))
return (ret & ~NETIF_F_CSUM_MASK) | NETIF_F_HW_CSUM;
- return 0;
- netdev_feature_zero(tnl);
- netdev_feature_set_bits(NETIF_F_CSUM_MASK | NETIF_F_GSO_SOFTWARE |
NETIF_F_GSO_ENCAP_ALL, tnl);
- netdev_feature_and(tnl, *tnl, real_dev->hw_enc_features);
- if (netdev_feature_test_bits(NETIF_F_GSO_ENCAP_ALL, *tnl) &&
netdev_feature_test_bits(NETIF_F_CSUM_MASK, *tnl)) {
netdev_feature_clear_bits(NETIF_F_CSUM_MASK, tnl);
netdev_feature_set_bit(NETIF_F_HW_CSUM_BIT, tnl);
- }
it missing "netdev_feature_zero(tnl);" here, will fix it next version.
}
#define vlan_group_for_each_dev(grp, i, dev) \ diff --git a/net/8021q/vlan_core.c b/net/8021q/vlan_core.c index 59bc13b..757b2f1 100644 --- a/net/8021q/vlan_core.c +++ b/net/8021q/vlan_core.c @@ -169,10 +169,12 @@ struct vlan_vid_info { static bool vlan_hw_filter_capable(const struct net_device *dev, __be16 proto) { if (proto == htons(ETH_P_8021Q) &&
dev->features & NETIF_F_HW_VLAN_CTAG_FILTER)
netdev_feature_test_bit(NETIF_F_HW_VLAN_CTAG_FILTER_BIT,
return true; if (proto == htons(ETH_P_8021AD) &&dev->features))
dev->features & NETIF_F_HW_VLAN_STAG_FILTER)
netdev_feature_test_bit(NETIF_F_HW_VLAN_STAG_FILTER_BIT,
return true; return false; }dev->features))
diff --git a/net/8021q/vlan_dev.c b/net/8021q/vlan_dev.c index 9f90a58..a010612 100644 --- a/net/8021q/vlan_dev.c +++ b/net/8021q/vlan_dev.c @@ -566,21 +566,24 @@ static int vlan_dev_init(struct net_device *dev) if (vlan->flags & VLAN_FLAG_BRIDGE_BINDING) dev->state |= (1 << __LINK_STATE_NOCARRIER);
- dev->hw_features = NETIF_F_HW_CSUM | NETIF_F_SG |
NETIF_F_FRAGLIST | NETIF_F_GSO_SOFTWARE |
NETIF_F_GSO_ENCAP_ALL |
NETIF_F_HIGHDMA | NETIF_F_SCTP_CRC |
NETIF_F_ALL_FCOE;
- dev->features |= dev->hw_features | NETIF_F_LLTX;
- netdev_feature_zero(&dev->hw_features);
- netdev_feature_set_bits(NETIF_F_HW_CSUM | NETIF_F_SG |
NETIF_F_FRAGLIST | NETIF_F_GSO_SOFTWARE |
NETIF_F_GSO_ENCAP_ALL |
NETIF_F_HIGHDMA | NETIF_F_SCTP_CRC |
NETIF_F_ALL_FCOE, &dev->hw_features);
- netdev_feature_or(&dev->features, dev->features, dev->hw_features);
- netdev_feature_set_bit(NETIF_F_LLTX_BIT, &dev->features); dev->gso_max_size = real_dev->gso_max_size; dev->gso_max_segs = real_dev->gso_max_segs;
- if (dev->features & NETIF_F_VLAN_FEATURES)
- if (netdev_feature_test_bits(NETIF_F_VLAN_FEATURES, dev->features)) netdev_warn(real_dev, "VLAN features are set incorrectly. Q-in-Q configurations may not work correctly.\n");
- dev->vlan_features = real_dev->vlan_features & ~NETIF_F_ALL_FCOE;
- dev->hw_enc_features = vlan_tnl_features(real_dev);
- dev->mpls_features = real_dev->mpls_features;
netdev_feature_copy(&dev->vlan_features, real_dev->vlan_features);
netdev_feature_clear_bits(NETIF_F_ALL_FCOE, &dev->vlan_features);
vlan_tnl_features(real_dev, &dev->hw_enc_features);
netdev_feature_copy(&dev->mpls_features, real_dev->mpls_features);
/* ipv6 shared card related stuff */ dev->dev_id = real_dev->dev_id;
@@ -637,21 +640,27 @@ static void vlan_dev_fix_features(struct net_device *dev, netdev_features_t *features) { struct net_device *real_dev = vlan_dev_priv(dev)->real_dev;
- netdev_features_t old_features = *features; netdev_features_t lower_features;
- netdev_features_t old_features;
- netdev_features_t tmp;
- netdev_intersect_features(&lower_features,
(real_dev->vlan_features | NETIF_F_RXCSUM),
real_dev->features);
netdev_feature_copy(&tmp, real_dev->vlan_features);
netdev_feature_set_bit(NETIF_F_RXCSUM_BIT, &tmp);
netdev_feature_copy(&old_features, *features);
netdev_intersect_features(&lower_features, tmp, real_dev->features);
/* Add HW_CSUM setting to preserve user ability to control
- checksum offload on the vlan device.
*/
- if (lower_features & (NETIF_F_IP_CSUM|NETIF_F_IPV6_CSUM))
lower_features |= NETIF_F_HW_CSUM;
- if (netdev_feature_test_bits(NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM,
lower_features))
netdev_intersect_features(features, *features, lower_features);netdev_feature_set_bit(NETIF_F_HW_CSUM_BIT, &lower_features);
- *features |= old_features & (NETIF_F_SOFT_FEATURES | NETIF_F_GSO_SOFTWARE);
- *features |= NETIF_F_LLTX;
netdev_feature_and_bits(NETIF_F_SOFT_FEATURES | NETIF_F_GSO_SOFTWARE,
&old_features);
netdev_feature_or(features, *features, old_features);
netdev_feature_set_bit(NETIF_F_LLTX_BIT, features); }
static int vlan_ethtool_get_link_ksettings(struct net_device *dev,