diff mbox series

[RFCv2,net-next,036/167] macsec: use netdev feature helpers

Message ID 20210929155334.12454-37-shenjian15@huawei.com (mailing list archive)
State RFC
Delegated to: Netdev Maintainers
Headers show
Series net: extend the netdev_features_t | expand

Commit Message

shenjian (K) Sept. 29, 2021, 3:51 p.m. UTC
Use netdev_feature_xxx helpers to replace the logical operation
for netdev features.

Signed-off-by: Jian Shen <shenjian15@huawei.com>
---
 drivers/net/macsec.c | 39 ++++++++++++++++++++++++---------------
 1 file changed, 24 insertions(+), 15 deletions(-)
diff mbox series

Patch

diff --git a/drivers/net/macsec.c b/drivers/net/macsec.c
index 601b833a40bd..5526d54c0a14 100644
--- a/drivers/net/macsec.c
+++ b/drivers/net/macsec.c
@@ -347,7 +347,8 @@  static bool macsec_check_offload(enum macsec_offload offload,
 		return macsec->real_dev->phydev &&
 		       macsec->real_dev->phydev->macsec_ops;
 	else if (offload == MACSEC_OFFLOAD_MAC)
-		return macsec->real_dev->features & NETIF_F_HW_MACSEC &&
+		return netdev_feature_test_bit(NETIF_F_HW_MACSEC_BIT,
+					       macsec->real_dev->features) &&
 		       macsec->real_dev->macsec_ops;
 
 	return false;
@@ -3419,13 +3420,6 @@  static netdev_tx_t macsec_start_xmit(struct sk_buff *skb,
 #define SW_MACSEC_FEATURES \
 	(NETIF_F_SG | NETIF_F_HIGHDMA | NETIF_F_FRAGLIST)
 
-/* If h/w offloading is enabled, use real device features save for
- *   VLAN_FEATURES - they require additional ops
- *   HW_MACSEC - no reason to report it
- */
-#define REAL_DEV_FEATURES(dev) \
-	((dev)->features & ~(NETIF_F_VLAN_FEATURES | NETIF_F_HW_MACSEC))
-
 static int macsec_dev_init(struct net_device *dev)
 {
 	struct macsec_dev *macsec = macsec_priv(dev);
@@ -3443,10 +3437,19 @@  static int macsec_dev_init(struct net_device *dev)
 	}
 
 	if (macsec_is_offloaded(macsec)) {
-		dev->features = REAL_DEV_FEATURES(real_dev);
+		/* If h/w offloading is enabled, use real device features save for
+		 *   VLAN_FEATURES - they require additional ops
+		 *   HW_MACSEC - no reason to report it
+		 */
+		netdev_feature_copy(&dev->features, real_dev->features);
+		netdev_feature_clear_bits(NETIF_F_VLAN_FEATURES |
+					  NETIF_F_HW_MACSEC,
+					  &dev->features);
 	} else {
-		dev->features = real_dev->features & SW_MACSEC_FEATURES;
-		dev->features |= NETIF_F_LLTX | NETIF_F_GSO_SOFTWARE;
+		netdev_feature_copy(&dev->features, real_dev->features);
+		netdev_feature_and_bits(SW_MACSEC_FEATURES, &dev->features);
+		netdev_feature_set_bits(NETIF_F_LLTX | NETIF_F_GSO_SOFTWARE,
+					&dev->features);
 	}
 
 	dev->needed_headroom = real_dev->needed_headroom +
@@ -3475,15 +3478,21 @@  static void macsec_fix_features(struct net_device *dev,
 {
 	struct macsec_dev *macsec = macsec_priv(dev);
 	struct net_device *real_dev = macsec->real_dev;
+	netdev_features_t tmp;
 
 	if (macsec_is_offloaded(macsec)) {
-		*features = REAL_DEV_FEATURES(real_dev);
+		netdev_feature_copy(features, real_dev->features);
+		netdev_feature_clear_bits(NETIF_F_VLAN_FEATURES |
+					  NETIF_F_HW_MACSEC, features);
 		return;
 	}
 
-	*features &= (real_dev->features & SW_MACSEC_FEATURES) |
-		    NETIF_F_GSO_SOFTWARE | NETIF_F_SOFT_FEATURES;
-	*features |= NETIF_F_LLTX;
+	netdev_feature_copy(&tmp, real_dev->features);
+	netdev_feature_and_bits(SW_MACSEC_FEATURES, &tmp);
+	netdev_feature_set_bits(NETIF_F_GSO_SOFTWARE | NETIF_F_SOFT_FEATURES,
+				&tmp);
+	netdev_feature_and(features, *features, tmp);
+	netdev_feature_set_bit(NETIF_F_LLTX_BIT, features);
 }
 
 static int macsec_dev_open(struct net_device *dev)