diff mbox series

[net-next,3/4] net: hns3: replace magic numbers with macro for IPv4/v6

Message ID 20220927111205.18060-4-huangguangbin2@huawei.com (mailing list archive)
State Changes Requested
Delegated to: Netdev Maintainers
Headers show
Series net: hns3: cleanup and optimization | expand

Checks

Context Check Description
netdev/tree_selection success Clearly marked for net-next
netdev/fixes_present success Fixes tag not required for -next series
netdev/subject_prefix success Link
netdev/cover_letter success Series has a cover letter
netdev/patch_count success Link
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 0 this patch: 0
netdev/cc_maintainers success CCed 5 of 5 maintainers
netdev/build_clang success Errors and warnings before: 0 this patch: 0
netdev/module_param success Was 0 now: 0
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/check_selftest success No net selftest shell script
netdev/verify_fixes success No Fixes tag
netdev/build_allmodconfig_warn success Errors and warnings before: 0 this patch: 0
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 56 lines checked
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0

Commit Message

Guangbin Huang Sept. 27, 2022, 11:12 a.m. UTC
From: Hao Chen <chenhao418@huawei.com>

Replace 4/6 with IP_VERSION_V4/6 to improve code readability.

Signed-off-by: Hao Chen <chenhao418@huawei.com>
Signed-off-by: Guangbin Huang <huangguangbin2@huawei.com>
---
 drivers/net/ethernet/hisilicon/hns3/hns3_enet.c | 12 ++++++------
 drivers/net/ethernet/hisilicon/hns3/hns3_enet.h |  3 +++
 2 files changed, 9 insertions(+), 6 deletions(-)

Comments

Leon Romanovsky Sept. 28, 2022, 10:34 a.m. UTC | #1
On Tue, Sep 27, 2022 at 07:12:04PM +0800, Guangbin Huang wrote:
> From: Hao Chen <chenhao418@huawei.com>
> 
> Replace 4/6 with IP_VERSION_V4/6 to improve code readability.
> 
> Signed-off-by: Hao Chen <chenhao418@huawei.com>
> Signed-off-by: Guangbin Huang <huangguangbin2@huawei.com>
> ---
>  drivers/net/ethernet/hisilicon/hns3/hns3_enet.c | 12 ++++++------
>  drivers/net/ethernet/hisilicon/hns3/hns3_enet.h |  3 +++
>  2 files changed, 9 insertions(+), 6 deletions(-)
> 
> diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3_enet.c b/drivers/net/ethernet/hisilicon/hns3/hns3_enet.c
> index 39b75b68474c..bf573e0c0670 100644
> --- a/drivers/net/ethernet/hisilicon/hns3/hns3_enet.c
> +++ b/drivers/net/ethernet/hisilicon/hns3/hns3_enet.c
> @@ -1180,7 +1180,7 @@ static int hns3_set_tso(struct sk_buff *skb, u32 *paylen_fdop_ol4cs,
>  	/* Software should clear the IPv4's checksum field when tso is
>  	 * needed.
>  	 */
> -	if (l3.v4->version == 4)
> +	if (l3.v4->version == IP_VERSION_IPV4)
>  		l3.v4->check = 0;
>  
>  	/* tunnel packet */
> @@ -1195,7 +1195,7 @@ static int hns3_set_tso(struct sk_buff *skb, u32 *paylen_fdop_ol4cs,
>  		/* Software should clear the IPv4's checksum field when
>  		 * tso is needed.
>  		 */
> -		if (l3.v4->version == 4)
> +		if (l3.v4->version == IP_VERSION_IPV4)
>  			l3.v4->check = 0;
>  	}
>  
> @@ -1270,13 +1270,13 @@ static int hns3_get_l4_protocol(struct sk_buff *skb, u8 *ol4_proto,
>  	l3.hdr = skb_inner_network_header(skb);
>  	l4_hdr = skb_inner_transport_header(skb);
>  
> -	if (l3.v6->version == 6) {
> +	if (l3.v6->version == IP_VERSION_IPV6) {
>  		exthdr = l3.hdr + sizeof(*l3.v6);
>  		l4_proto_tmp = l3.v6->nexthdr;
>  		if (l4_hdr != exthdr)
>  			ipv6_skip_exthdr(skb, exthdr - skb->data,
>  					 &l4_proto_tmp, &frag_off);
> -	} else if (l3.v4->version == 4) {
> +	} else if (l3.v4->version == IP_VERSION_IPV4) {
>  		l4_proto_tmp = l3.v4->protocol;
>  	}
>  
> @@ -1364,7 +1364,7 @@ static void hns3_set_outer_l2l3l4(struct sk_buff *skb, u8 ol4_proto,
>  static void hns3_set_l3_type(struct sk_buff *skb, union l3_hdr_info l3,
>  			     u32 *type_cs_vlan_tso)
>  {
> -	if (l3.v4->version == 4) {
> +	if (l3.v4->version == IP_VERSION_IPV4) {
>  		hns3_set_field(*type_cs_vlan_tso, HNS3_TXD_L3T_S,
>  			       HNS3_L3T_IPV4);
>  
> @@ -1373,7 +1373,7 @@ static void hns3_set_l3_type(struct sk_buff *skb, union l3_hdr_info l3,
>  		 */
>  		if (skb_is_gso(skb))
>  			hns3_set_field(*type_cs_vlan_tso, HNS3_TXD_L3CS_B, 1);
> -	} else if (l3.v6->version == 6) {
> +	} else if (l3.v6->version == IP_VERSION_IPV6) {
>  		hns3_set_field(*type_cs_vlan_tso, HNS3_TXD_L3T_S,
>  			       HNS3_L3T_IPV6);
>  	}
> diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3_enet.h b/drivers/net/ethernet/hisilicon/hns3/hns3_enet.h
> index 557a5fa70d0a..93041352ef19 100644
> --- a/drivers/net/ethernet/hisilicon/hns3/hns3_enet.h
> +++ b/drivers/net/ethernet/hisilicon/hns3/hns3_enet.h
> @@ -217,6 +217,9 @@ enum hns3_nic_state {
>  #define HNS3_CQ_MODE_EQE			1U
>  #define HNS3_CQ_MODE_CQE			0U
>  
> +#define IP_VERSION_IPV4				0x4
> +#define IP_VERSION_IPV6				0x6

The more traditional way is to use sa_family_t sa_family and AF_XXX instead
of your .version variable.

Thanks

> +
>  enum hns3_pkt_l2t_type {
>  	HNS3_L2_TYPE_UNICAST,
>  	HNS3_L2_TYPE_MULTICAST,
> -- 
> 2.33.0
>
diff mbox series

Patch

diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3_enet.c b/drivers/net/ethernet/hisilicon/hns3/hns3_enet.c
index 39b75b68474c..bf573e0c0670 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3_enet.c
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3_enet.c
@@ -1180,7 +1180,7 @@  static int hns3_set_tso(struct sk_buff *skb, u32 *paylen_fdop_ol4cs,
 	/* Software should clear the IPv4's checksum field when tso is
 	 * needed.
 	 */
-	if (l3.v4->version == 4)
+	if (l3.v4->version == IP_VERSION_IPV4)
 		l3.v4->check = 0;
 
 	/* tunnel packet */
@@ -1195,7 +1195,7 @@  static int hns3_set_tso(struct sk_buff *skb, u32 *paylen_fdop_ol4cs,
 		/* Software should clear the IPv4's checksum field when
 		 * tso is needed.
 		 */
-		if (l3.v4->version == 4)
+		if (l3.v4->version == IP_VERSION_IPV4)
 			l3.v4->check = 0;
 	}
 
@@ -1270,13 +1270,13 @@  static int hns3_get_l4_protocol(struct sk_buff *skb, u8 *ol4_proto,
 	l3.hdr = skb_inner_network_header(skb);
 	l4_hdr = skb_inner_transport_header(skb);
 
-	if (l3.v6->version == 6) {
+	if (l3.v6->version == IP_VERSION_IPV6) {
 		exthdr = l3.hdr + sizeof(*l3.v6);
 		l4_proto_tmp = l3.v6->nexthdr;
 		if (l4_hdr != exthdr)
 			ipv6_skip_exthdr(skb, exthdr - skb->data,
 					 &l4_proto_tmp, &frag_off);
-	} else if (l3.v4->version == 4) {
+	} else if (l3.v4->version == IP_VERSION_IPV4) {
 		l4_proto_tmp = l3.v4->protocol;
 	}
 
@@ -1364,7 +1364,7 @@  static void hns3_set_outer_l2l3l4(struct sk_buff *skb, u8 ol4_proto,
 static void hns3_set_l3_type(struct sk_buff *skb, union l3_hdr_info l3,
 			     u32 *type_cs_vlan_tso)
 {
-	if (l3.v4->version == 4) {
+	if (l3.v4->version == IP_VERSION_IPV4) {
 		hns3_set_field(*type_cs_vlan_tso, HNS3_TXD_L3T_S,
 			       HNS3_L3T_IPV4);
 
@@ -1373,7 +1373,7 @@  static void hns3_set_l3_type(struct sk_buff *skb, union l3_hdr_info l3,
 		 */
 		if (skb_is_gso(skb))
 			hns3_set_field(*type_cs_vlan_tso, HNS3_TXD_L3CS_B, 1);
-	} else if (l3.v6->version == 6) {
+	} else if (l3.v6->version == IP_VERSION_IPV6) {
 		hns3_set_field(*type_cs_vlan_tso, HNS3_TXD_L3T_S,
 			       HNS3_L3T_IPV6);
 	}
diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3_enet.h b/drivers/net/ethernet/hisilicon/hns3/hns3_enet.h
index 557a5fa70d0a..93041352ef19 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3_enet.h
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3_enet.h
@@ -217,6 +217,9 @@  enum hns3_nic_state {
 #define HNS3_CQ_MODE_EQE			1U
 #define HNS3_CQ_MODE_CQE			0U
 
+#define IP_VERSION_IPV4				0x4
+#define IP_VERSION_IPV6				0x6
+
 enum hns3_pkt_l2t_type {
 	HNS3_L2_TYPE_UNICAST,
 	HNS3_L2_TYPE_MULTICAST,