linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH net-next 0/4] net: hns3: cleanup and optimization
@ 2022-09-27 11:12 Guangbin Huang
  2022-09-27 11:12 ` [PATCH net-next 1/4] net: hns3: refine the tcam key convert handle Guangbin Huang
                   ` (3 more replies)
  0 siblings, 4 replies; 8+ messages in thread
From: Guangbin Huang @ 2022-09-27 11:12 UTC (permalink / raw)
  To: davem, kuba
  Cc: edumazet, pabeni, netdev, linux-kernel, huangguangbin2,
	shenjian15, lanhao

This serial includes some cleanup and one optimization patches for
HNS3 driver.

Guangbin Huang (1):
  net: hns3: delete unnecessary vf value judgement when get vport id

Hao Chen (2):
  net: hns3: fix hns3 driver header file not self-contained issue
  net: hns3: replace magic numbers with macro for IPv4/v6

Jian Shen (1):
  net: hns3: refine the tcam key convert handle

 drivers/net/ethernet/hisilicon/hns3/hclge_mbx.h      |  4 +++-
 .../hns3/hns3_common/hclge_comm_tqp_stats.h          |  2 ++
 drivers/net/ethernet/hisilicon/hns3/hns3_enet.c      | 12 ++++++------
 drivers/net/ethernet/hisilicon/hns3/hns3_enet.h      |  6 ++++++
 .../net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c  |  4 +---
 .../net/ethernet/hisilicon/hns3/hns3pf/hclge_main.h  | 11 +++--------
 .../net/ethernet/hisilicon/hns3/hns3pf/hclge_ptp.h   |  5 ++++-
 7 files changed, 25 insertions(+), 19 deletions(-)

-- 
2.33.0


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [PATCH net-next 1/4] net: hns3: refine the tcam key convert handle
  2022-09-27 11:12 [PATCH net-next 0/4] net: hns3: cleanup and optimization Guangbin Huang
@ 2022-09-27 11:12 ` Guangbin Huang
  2022-09-28 10:28   ` Leon Romanovsky
  2022-09-27 11:12 ` [PATCH net-next 2/4] net: hns3: fix hns3 driver header file not self-contained issue Guangbin Huang
                   ` (2 subsequent siblings)
  3 siblings, 1 reply; 8+ messages in thread
From: Guangbin Huang @ 2022-09-27 11:12 UTC (permalink / raw)
  To: davem, kuba
  Cc: edumazet, pabeni, netdev, linux-kernel, huangguangbin2,
	shenjian15, lanhao

From: Jian Shen <shenjian15@huawei.com>

The expression '(k ^ ~v)' is exaclty '(k & v)', and
'(k & v) & k' is exaclty 'k & v'. So simplify the
expression for tcam key convert.

It also add necessary brackets for them.

Signed-off-by: Jian Shen <shenjian15@huawei.com>
Signed-off-by: Guangbin Huang <huangguangbin2@huawei.com>
---
 .../net/ethernet/hisilicon/hns3/hns3pf/hclge_main.h   | 11 +++--------
 1 file changed, 3 insertions(+), 8 deletions(-)

diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.h b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.h
index 495b639b0dc2..59bfacc687c9 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.h
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.h
@@ -827,15 +827,10 @@ struct hclge_vf_vlan_cfg {
  * Then for input key(k) and mask(v), we can calculate the value by
  * the formulae:
  *	x = (~k) & v
- *	y = (k ^ ~v) & k
+ *	y = k & v
  */
-#define calc_x(x, k, v) (x = ~(k) & (v))
-#define calc_y(y, k, v) \
-	do { \
-		const typeof(k) _k_ = (k); \
-		const typeof(v) _v_ = (v); \
-		(y) = (_k_ ^ ~_v_) & (_k_); \
-	} while (0)
+#define calc_x(x, k, v) ((x) = ~(k) & (v))
+#define calc_y(y, k, v) ((y) = (k) & (v))
 
 #define HCLGE_MAC_STATS_FIELD_OFF(f) (offsetof(struct hclge_mac_stats, f))
 #define HCLGE_STATS_READ(p, offset) (*(u64 *)((u8 *)(p) + (offset)))
-- 
2.33.0


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH net-next 2/4] net: hns3: fix hns3 driver header file not self-contained issue
  2022-09-27 11:12 [PATCH net-next 0/4] net: hns3: cleanup and optimization Guangbin Huang
  2022-09-27 11:12 ` [PATCH net-next 1/4] net: hns3: refine the tcam key convert handle Guangbin Huang
@ 2022-09-27 11:12 ` Guangbin Huang
  2022-09-27 11:12 ` [PATCH net-next 3/4] net: hns3: replace magic numbers with macro for IPv4/v6 Guangbin Huang
  2022-09-27 11:12 ` [PATCH net-next 4/4] net: hns3: delete unnecessary vf value judgement when get vport id Guangbin Huang
  3 siblings, 0 replies; 8+ messages in thread
From: Guangbin Huang @ 2022-09-27 11:12 UTC (permalink / raw)
  To: davem, kuba
  Cc: edumazet, pabeni, netdev, linux-kernel, huangguangbin2,
	shenjian15, lanhao

From: Hao Chen <chenhao418@huawei.com>

The hns3 driver header file uses the structure of other files, but does
not include corresponding file, which causes a check warning that the
header file is not self-contained.

Therefore, the required header file is included in the header file, and
the structure declaration is added to the header file to avoid cyclic
dependency of the header file.

Signed-off-by: Hao Chen <chenhao418@huawei.com>
Signed-off-by: Guangbin Huang <huangguangbin2@huawei.com>
---
 drivers/net/ethernet/hisilicon/hns3/hclge_mbx.h              | 4 +++-
 .../hisilicon/hns3/hns3_common/hclge_comm_tqp_stats.h        | 2 ++
 drivers/net/ethernet/hisilicon/hns3/hns3_enet.h              | 3 +++
 drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_ptp.h       | 5 ++++-
 4 files changed, 12 insertions(+), 2 deletions(-)

diff --git a/drivers/net/ethernet/hisilicon/hns3/hclge_mbx.h b/drivers/net/ethernet/hisilicon/hns3/hclge_mbx.h
index abcd7877f7d2..487216aeae50 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hclge_mbx.h
+++ b/drivers/net/ethernet/hisilicon/hns3/hclge_mbx.h
@@ -7,6 +7,8 @@
 #include <linux/mutex.h>
 #include <linux/types.h>
 
+struct hclgevf_dev;
+
 enum HCLGE_MBX_OPCODE {
 	HCLGE_MBX_RESET = 0x01,		/* (VF -> PF) assert reset */
 	HCLGE_MBX_ASSERTING_RESET,	/* (PF -> VF) PF is asserting reset */
@@ -233,7 +235,7 @@ struct hclgevf_mbx_arq_ring {
 	__le16 msg_q[HCLGE_MBX_MAX_ARQ_MSG_NUM][HCLGE_MBX_MAX_ARQ_MSG_SIZE];
 };
 
-struct hclge_dev;
+struct hclge_vport;
 
 #define HCLGE_MBX_OPCODE_MAX 256
 struct hclge_mbx_ops_param {
diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3_common/hclge_comm_tqp_stats.h b/drivers/net/ethernet/hisilicon/hns3/hns3_common/hclge_comm_tqp_stats.h
index a46350162ee8..7aff1a544cf4 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3_common/hclge_comm_tqp_stats.h
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3_common/hclge_comm_tqp_stats.h
@@ -7,6 +7,8 @@
 #include <linux/etherdevice.h>
 #include "hnae3.h"
 
+struct hclge_comm_hw;
+
 /* each tqp has TX & RX two queues */
 #define HCLGE_COMM_QUEUE_PAIR_SIZE 2
 
diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3_enet.h b/drivers/net/ethernet/hisilicon/hns3/hns3_enet.h
index 133a054af6b7..557a5fa70d0a 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3_enet.h
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3_enet.h
@@ -13,6 +13,9 @@
 
 struct iphdr;
 struct ipv6hdr;
+struct gre_base_hdr;
+struct tcphdr;
+struct udphdr;
 
 enum hns3_nic_state {
 	HNS3_NIC_STATE_TESTING,
diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_ptp.h b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_ptp.h
index bbee74cd8404..bceb61c791a1 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_ptp.h
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_ptp.h
@@ -8,8 +8,11 @@
 #include <linux/net_tstamp.h>
 #include <linux/types.h>
 
-struct hclge_dev;
 struct ifreq;
+struct ethtool_ts_info;
+
+struct hnae3_handle;
+struct hclge_dev;
 
 #define HCLGE_PTP_REG_OFFSET	0x29000
 
-- 
2.33.0


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH net-next 3/4] net: hns3: replace magic numbers with macro for IPv4/v6
  2022-09-27 11:12 [PATCH net-next 0/4] net: hns3: cleanup and optimization Guangbin Huang
  2022-09-27 11:12 ` [PATCH net-next 1/4] net: hns3: refine the tcam key convert handle Guangbin Huang
  2022-09-27 11:12 ` [PATCH net-next 2/4] net: hns3: fix hns3 driver header file not self-contained issue Guangbin Huang
@ 2022-09-27 11:12 ` Guangbin Huang
  2022-09-28 10:34   ` Leon Romanovsky
  2022-09-27 11:12 ` [PATCH net-next 4/4] net: hns3: delete unnecessary vf value judgement when get vport id Guangbin Huang
  3 siblings, 1 reply; 8+ messages in thread
From: Guangbin Huang @ 2022-09-27 11:12 UTC (permalink / raw)
  To: davem, kuba
  Cc: edumazet, pabeni, netdev, linux-kernel, huangguangbin2,
	shenjian15, lanhao

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
+
 enum hns3_pkt_l2t_type {
 	HNS3_L2_TYPE_UNICAST,
 	HNS3_L2_TYPE_MULTICAST,
-- 
2.33.0


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH net-next 4/4] net: hns3: delete unnecessary vf value judgement when get vport id
  2022-09-27 11:12 [PATCH net-next 0/4] net: hns3: cleanup and optimization Guangbin Huang
                   ` (2 preceding siblings ...)
  2022-09-27 11:12 ` [PATCH net-next 3/4] net: hns3: replace magic numbers with macro for IPv4/v6 Guangbin Huang
@ 2022-09-27 11:12 ` Guangbin Huang
  3 siblings, 0 replies; 8+ messages in thread
From: Guangbin Huang @ 2022-09-27 11:12 UTC (permalink / raw)
  To: davem, kuba
  Cc: edumazet, pabeni, netdev, linux-kernel, huangguangbin2,
	shenjian15, lanhao

The hdev->vport->vport_id is equal to hdev->vport[0].vport_id, so
delete unnecessary vf value judgement.

Signed-off-by: Guangbin Huang <huangguangbin2@huawei.com>
---
 drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c
index 6962a9d69cf8..b566c0d782ad 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c
@@ -6487,8 +6487,6 @@ static bool hclge_is_cls_flower_active(struct hnae3_handle *handle)
 static int hclge_fd_parse_ring_cookie(struct hclge_dev *hdev, u64 ring_cookie,
 				      u16 *vport_id, u8 *action, u16 *queue_id)
 {
-	struct hclge_vport *vport = hdev->vport;
-
 	if (ring_cookie == RX_CLS_FLOW_DISC) {
 		*action = HCLGE_FD_ACTION_DROP_PACKET;
 	} else {
@@ -6506,7 +6504,7 @@ static int hclge_fd_parse_ring_cookie(struct hclge_dev *hdev, u64 ring_cookie,
 			return -EINVAL;
 		}
 
-		*vport_id = vf ? hdev->vport[vf].vport_id : vport->vport_id;
+		*vport_id = hdev->vport[vf].vport_id;
 		tqps = hdev->vport[vf].nic.kinfo.num_tqps;
 
 		if (ring >= tqps) {
-- 
2.33.0


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* Re: [PATCH net-next 1/4] net: hns3: refine the tcam key convert handle
  2022-09-27 11:12 ` [PATCH net-next 1/4] net: hns3: refine the tcam key convert handle Guangbin Huang
@ 2022-09-28 10:28   ` Leon Romanovsky
  2022-11-15 14:12     ` Hao Lan
  0 siblings, 1 reply; 8+ messages in thread
From: Leon Romanovsky @ 2022-09-28 10:28 UTC (permalink / raw)
  To: Guangbin Huang
  Cc: davem, kuba, edumazet, pabeni, netdev, linux-kernel, shenjian15, lanhao

On Tue, Sep 27, 2022 at 07:12:02PM +0800, Guangbin Huang wrote:
> From: Jian Shen <shenjian15@huawei.com>
> 
> The expression '(k ^ ~v)' is exaclty '(k & v)', and
> '(k & v) & k' is exaclty 'k & v'. So simplify the
> expression for tcam key convert.
> 
> It also add necessary brackets for them.
> 
> Signed-off-by: Jian Shen <shenjian15@huawei.com>
> Signed-off-by: Guangbin Huang <huangguangbin2@huawei.com>
> ---
>  .../net/ethernet/hisilicon/hns3/hns3pf/hclge_main.h   | 11 +++--------
>  1 file changed, 3 insertions(+), 8 deletions(-)
> 
> diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.h b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.h
> index 495b639b0dc2..59bfacc687c9 100644
> --- a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.h
> +++ b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.h
> @@ -827,15 +827,10 @@ struct hclge_vf_vlan_cfg {
>   * Then for input key(k) and mask(v), we can calculate the value by
>   * the formulae:
>   *	x = (~k) & v
> - *	y = (k ^ ~v) & k
> + *	y = k & v
>   */
> -#define calc_x(x, k, v) (x = ~(k) & (v))
> -#define calc_y(y, k, v) \
> -	do { \
> -		const typeof(k) _k_ = (k); \
> -		const typeof(v) _v_ = (v); \
> -		(y) = (_k_ ^ ~_v_) & (_k_); \
> -	} while (0)
> +#define calc_x(x, k, v) ((x) = ~(k) & (v))
> +#define calc_y(y, k, v) ((y) = (k) & (v))

Can you please explain why do you need special define for boolean AND?

Thanks

>  
>  #define HCLGE_MAC_STATS_FIELD_OFF(f) (offsetof(struct hclge_mac_stats, f))
>  #define HCLGE_STATS_READ(p, offset) (*(u64 *)((u8 *)(p) + (offset)))
> -- 
> 2.33.0
> 

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH net-next 3/4] net: hns3: replace magic numbers with macro for IPv4/v6
  2022-09-27 11:12 ` [PATCH net-next 3/4] net: hns3: replace magic numbers with macro for IPv4/v6 Guangbin Huang
@ 2022-09-28 10:34   ` Leon Romanovsky
  0 siblings, 0 replies; 8+ messages in thread
From: Leon Romanovsky @ 2022-09-28 10:34 UTC (permalink / raw)
  To: Guangbin Huang
  Cc: davem, kuba, edumazet, pabeni, netdev, linux-kernel, shenjian15, lanhao

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
> 

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH net-next 1/4] net: hns3: refine the tcam key convert handle
  2022-09-28 10:28   ` Leon Romanovsky
@ 2022-11-15 14:12     ` Hao Lan
  0 siblings, 0 replies; 8+ messages in thread
From: Hao Lan @ 2022-11-15 14:12 UTC (permalink / raw)
  To: Leon Romanovsky, Guangbin Huang
  Cc: davem, kuba, edumazet, pabeni, netdev, linux-kernel, shenjian15

> Can you please explain why do you need special define for boolean AND?
we use '&', just define a bitwise AND, not define boolean AND.
Thanks.

On 2022/9/28 18:28, Leon Romanovsky wrote:
> On Tue, Sep 27, 2022 at 07:12:02PM +0800, Guangbin Huang wrote:
>> From: Jian Shen <shenjian15@huawei.com>
>>
>> The expression '(k ^ ~v)' is exaclty '(k & v)', and
>> '(k & v) & k' is exaclty 'k & v'. So simplify the
>> expression for tcam key convert.
>>
>> It also add necessary brackets for them.
>>
>> Signed-off-by: Jian Shen <shenjian15@huawei.com>
>> Signed-off-by: Guangbin Huang <huangguangbin2@huawei.com>
>> ---
>>  .../net/ethernet/hisilicon/hns3/hns3pf/hclge_main.h   | 11 +++--------
>>  1 file changed, 3 insertions(+), 8 deletions(-)
>>
>> diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.h b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.h
>> index 495b639b0dc2..59bfacc687c9 100644
>> --- a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.h
>> +++ b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.h
>> @@ -827,15 +827,10 @@ struct hclge_vf_vlan_cfg {
>>   * Then for input key(k) and mask(v), we can calculate the value by
>>   * the formulae:
>>   *	x = (~k) & v
>> - *	y = (k ^ ~v) & k
>> + *	y = k & v
>>   */
>> -#define calc_x(x, k, v) (x = ~(k) & (v))
>> -#define calc_y(y, k, v) \
>> -	do { \
>> -		const typeof(k) _k_ = (k); \
>> -		const typeof(v) _v_ = (v); \
>> -		(y) = (_k_ ^ ~_v_) & (_k_); \
>> -	} while (0)
>> +#define calc_x(x, k, v) ((x) = ~(k) & (v))
>> +#define calc_y(y, k, v) ((y) = (k) & (v))
> 
> Can you please explain why do you need special define for boolean AND?
we use '&', just define a bitwise AND, not define boolean AND.
> 
> Thanks
> 
>>  
>>  #define HCLGE_MAC_STATS_FIELD_OFF(f) (offsetof(struct hclge_mac_stats, f))
>>  #define HCLGE_STATS_READ(p, offset) (*(u64 *)((u8 *)(p) + (offset)))
>> -- 
>> 2.33.0
>>
> .
> 

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2022-11-15 14:13 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-09-27 11:12 [PATCH net-next 0/4] net: hns3: cleanup and optimization Guangbin Huang
2022-09-27 11:12 ` [PATCH net-next 1/4] net: hns3: refine the tcam key convert handle Guangbin Huang
2022-09-28 10:28   ` Leon Romanovsky
2022-11-15 14:12     ` Hao Lan
2022-09-27 11:12 ` [PATCH net-next 2/4] net: hns3: fix hns3 driver header file not self-contained issue Guangbin Huang
2022-09-27 11:12 ` [PATCH net-next 3/4] net: hns3: replace magic numbers with macro for IPv4/v6 Guangbin Huang
2022-09-28 10:34   ` Leon Romanovsky
2022-09-27 11:12 ` [PATCH net-next 4/4] net: hns3: delete unnecessary vf value judgement when get vport id Guangbin Huang

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).