diff mbox series

[RFCv2,net-next,032/167] net: tap: use netdev feature helpers

Message ID 20210929155334.12454-33-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/tap.c | 36 ++++++++++++++++++++++--------------
 1 file changed, 22 insertions(+), 14 deletions(-)
diff mbox series

Patch

diff --git a/drivers/net/tap.c b/drivers/net/tap.c
index 8e3a28ba6b28..03158fa9476c 100644
--- a/drivers/net/tap.c
+++ b/drivers/net/tap.c
@@ -321,7 +321,10 @@  rx_handler_result_t tap_handle_frame(struct sk_buff **pskb)
 	struct net_device *dev = skb->dev;
 	struct tap_dev *tap;
 	struct tap_queue *q;
-	netdev_features_t features = TAP_FEATURES;
+	netdev_features_t features;
+
+	netdev_feature_zero(&features);
+	netdev_feature_set_bits(TAP_FEATURES, &features);
 
 	tap = tap_dev_get_rcu(dev);
 	if (!tap)
@@ -338,7 +341,7 @@  rx_handler_result_t tap_handle_frame(struct sk_buff **pskb)
 	 * enabled.
 	 */
 	if (q->flags & IFF_VNET_HDR)
-		features |= tap->tap_features;
+		netdev_feature_or(&features, features, tap->tap_features);
 	if (netif_needs_gso(skb, features)) {
 		struct sk_buff *segs = __skb_gso_segment(skb, features, false);
 		struct sk_buff *next;
@@ -368,7 +371,7 @@  rx_handler_result_t tap_handle_frame(struct sk_buff **pskb)
 		 *	  check, we either support them all or none.
 		 */
 		if (skb->ip_summed == CHECKSUM_PARTIAL &&
-		    !(features & NETIF_F_CSUM_MASK) &&
+		    !netdev_feature_test_bits(NETIF_F_CSUM_MASK, features) &&
 		    skb_checksum_help(skb))
 			goto drop;
 		if (ptr_ring_produce(&q->ring, skb))
@@ -536,7 +539,8 @@  static int tap_open(struct inode *inode, struct file *file)
 	 * The macvlan supports zerocopy iff the lower device supports zero
 	 * copy so we don't have to look at the lower device directly.
 	 */
-	if ((tap->dev->features & NETIF_F_HIGHDMA) && (tap->dev->features & NETIF_F_SG))
+	if (netdev_feature_test_bit(NETIF_F_HIGHDMA_BIT, tap->dev->features) &&
+	    netdev_feature_test_bit(NETIF_F_SG_BIT, tap->dev->features))
 		sock_set_flag(&q->sk, SOCK_ZEROCOPY);
 
 	err = tap_set_queue(tap, file, q);
@@ -921,24 +925,28 @@  static int set_offload(struct tap_queue *q, unsigned long arg)
 {
 	struct tap_dev *tap;
 	netdev_features_t features;
-	netdev_features_t feature_mask = 0;
+	netdev_features_t feature_mask;
 
 	tap = rtnl_dereference(q->tap);
 	if (!tap)
 		return -ENOLINK;
 
-	features = tap->dev->features;
+	netdev_feature_zero(&feature_mask);
+	netdev_feature_copy(&features, tap->dev->features);
 
 	if (arg & TUN_F_CSUM) {
-		feature_mask = NETIF_F_HW_CSUM;
+		netdev_feature_set_bit(NETIF_F_HW_CSUM_BIT, &feature_mask);
 
 		if (arg & (TUN_F_TSO4 | TUN_F_TSO6)) {
 			if (arg & TUN_F_TSO_ECN)
-				feature_mask |= NETIF_F_TSO_ECN;
+				netdev_feature_set_bit(NETIF_F_TSO_ECN_BIT,
+						       &feature_mask);
 			if (arg & TUN_F_TSO4)
-				feature_mask |= NETIF_F_TSO;
+				netdev_feature_set_bit(NETIF_F_TSO_BIT,
+						       &feature_mask);
 			if (arg & TUN_F_TSO6)
-				feature_mask |= NETIF_F_TSO6;
+				netdev_feature_set_bit(NETIF_F_TSO6_BIT,
+						       &feature_mask);
 		}
 	}
 
@@ -950,15 +958,15 @@  static int set_offload(struct tap_queue *q, unsigned long arg)
 	 * When user space turns off TSO, we turn off GSO/LRO so that
 	 * user-space will not receive TSO frames.
 	 */
-	if (feature_mask & (NETIF_F_TSO | NETIF_F_TSO6))
-		features |= RX_OFFLOADS;
+	if (netdev_feature_test_bits(NETIF_F_TSO | NETIF_F_TSO6, feature_mask))
+		netdev_feature_set_bits(RX_OFFLOADS, &features);
 	else
-		features &= ~RX_OFFLOADS;
+		netdev_feature_clear_bits(RX_OFFLOADS, &features);
 
 	/* tap_features are the same as features on tun/tap and
 	 * reflect user expectations.
 	 */
-	tap->tap_features = feature_mask;
+	netdev_feature_copy(&tap->tap_features, feature_mask);
 	if (tap->update_features)
 		tap->update_features(tap, features);