diff mbox series

[net-next,2/3] net/mlx5e: Introduce mlx5e_eswitch_rep_uplink_priv helper

Message ID 1588051455-42828-2-git-send-email-xiangxia.m.yue@gmail.com
State Awaiting Upstream
Delegated to: David Miller
Headers show
Series [net-next,1/3] net/mlx5e: Implicitly decap the tunnel packet when necessary | expand

Commit Message

Tonghao Zhang April 28, 2020, 5:24 a.m. UTC
From: Tonghao Zhang <xiangxia.m.yue@gmail.com>

Introduce the mlx5e_eswitch_rep_uplink_priv helper
to make the codes readable.

Signed-off-by: Tonghao Zhang <xiangxia.m.yue@gmail.com>
---
 drivers/net/ethernet/mellanox/mlx5/core/en/tc_ct.c |  4 +--
 drivers/net/ethernet/mellanox/mlx5/core/en_rep.h   |  9 +++++++
 drivers/net/ethernet/mellanox/mlx5/core/en_tc.c    | 30 +++++-----------------
 3 files changed, 17 insertions(+), 26 deletions(-)

Comments

Roi Dayan April 30, 2020, 11:17 a.m. UTC | #1
On 2020-04-28 8:24 AM, xiangxia.m.yue@gmail.com wrote:
> From: Tonghao Zhang <xiangxia.m.yue@gmail.com>
> 
> Introduce the mlx5e_eswitch_rep_uplink_priv helper
> to make the codes readable.
> 
> Signed-off-by: Tonghao Zhang <xiangxia.m.yue@gmail.com>
> ---
>  drivers/net/ethernet/mellanox/mlx5/core/en/tc_ct.c |  4 +--
>  drivers/net/ethernet/mellanox/mlx5/core/en_rep.h   |  9 +++++++
>  drivers/net/ethernet/mellanox/mlx5/core/en_tc.c    | 30 +++++-----------------
>  3 files changed, 17 insertions(+), 26 deletions(-)
> 
> diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en/tc_ct.c b/drivers/net/ethernet/mellanox/mlx5/core/en/tc_ct.c
> index 16416eaac39e..c5d5e69ff147 100644
> --- a/drivers/net/ethernet/mellanox/mlx5/core/en/tc_ct.c
> +++ b/drivers/net/ethernet/mellanox/mlx5/core/en/tc_ct.c
> @@ -100,10 +100,8 @@ struct mlx5_ct_entry {
>  {
>  	struct mlx5_eswitch *esw = priv->mdev->priv.eswitch;
>  	struct mlx5_rep_uplink_priv *uplink_priv;
> -	struct mlx5e_rep_priv *uplink_rpriv;
>  
> -	uplink_rpriv = mlx5_eswitch_get_uplink_priv(esw, REP_ETH);
> -	uplink_priv = &uplink_rpriv->uplink_priv;
> +	uplink_priv = mlx5e_eswitch_rep_uplink_priv(esw);
>  	return uplink_priv->ct_priv;
>  }
>  
> diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en_rep.h b/drivers/net/ethernet/mellanox/mlx5/core/en_rep.h
> index 6a2337900420..899ffa0872b7 100644
> --- a/drivers/net/ethernet/mellanox/mlx5/core/en_rep.h
> +++ b/drivers/net/ethernet/mellanox/mlx5/core/en_rep.h
> @@ -109,6 +109,15 @@ struct mlx5e_rep_priv *mlx5e_rep_to_rep_priv(struct mlx5_eswitch_rep *rep)
>  	return rep->rep_data[REP_ETH].priv;
>  }
>  
> +static inline struct mlx5_rep_uplink_priv *
> +mlx5e_eswitch_rep_uplink_priv(struct mlx5_eswitch *esw)
> +{
> +	struct mlx5e_rep_priv *priv;
> +
> +	priv = mlx5_eswitch_get_uplink_priv(esw, REP_ETH);
> +	return &priv->uplink_priv;
> +}
> +

since its in en_rep.h, please use "mlx5e_rep_" prefix.
thanks

>  struct mlx5e_neigh {
>  	struct net_device *dev;
>  	union {
> diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en_tc.c b/drivers/net/ethernet/mellanox/mlx5/core/en_tc.c
> index 64f5c3f3dbb3..696544e2a25b 100644
> --- a/drivers/net/ethernet/mellanox/mlx5/core/en_tc.c
> +++ b/drivers/net/ethernet/mellanox/mlx5/core/en_tc.c
> @@ -1250,12 +1250,10 @@ static void unready_flow_del(struct mlx5e_tc_flow *flow)
>  static void add_unready_flow(struct mlx5e_tc_flow *flow)
>  {
>  	struct mlx5_rep_uplink_priv *uplink_priv;
> -	struct mlx5e_rep_priv *rpriv;
>  	struct mlx5_eswitch *esw;
>  
>  	esw = flow->priv->mdev->priv.eswitch;
> -	rpriv = mlx5_eswitch_get_uplink_priv(esw, REP_ETH);
> -	uplink_priv = &rpriv->uplink_priv;
> +	uplink_priv = mlx5e_eswitch_rep_uplink_priv(esw);
>  
>  	mutex_lock(&uplink_priv->unready_flows_lock);
>  	unready_flow_add(flow, &uplink_priv->unready_flows);
> @@ -1265,12 +1263,10 @@ static void add_unready_flow(struct mlx5e_tc_flow *flow)
>  static void remove_unready_flow(struct mlx5e_tc_flow *flow)
>  {
>  	struct mlx5_rep_uplink_priv *uplink_priv;
> -	struct mlx5e_rep_priv *rpriv;
>  	struct mlx5_eswitch *esw;
>  
>  	esw = flow->priv->mdev->priv.eswitch;
> -	rpriv = mlx5_eswitch_get_uplink_priv(esw, REP_ETH);
> -	uplink_priv = &rpriv->uplink_priv;
> +	uplink_priv = mlx5e_eswitch_rep_uplink_priv(esw);
>  
>  	mutex_lock(&uplink_priv->unready_flows_lock);
>  	unready_flow_del(flow);
> @@ -1888,7 +1884,6 @@ static int mlx5e_get_flow_tunnel_id(struct mlx5e_priv *priv,
>  	struct mlx5e_tc_mod_hdr_acts *mod_hdr_acts;
>  	struct flow_match_enc_opts enc_opts_match;
>  	struct mlx5_rep_uplink_priv *uplink_priv;
> -	struct mlx5e_rep_priv *uplink_rpriv;
>  	struct tunnel_match_key tunnel_key;
>  	bool enc_opts_is_dont_care = true;
>  	u32 tun_id, enc_opts_id = 0;
> @@ -1897,8 +1892,7 @@ static int mlx5e_get_flow_tunnel_id(struct mlx5e_priv *priv,
>  	int err;
>  
>  	esw = priv->mdev->priv.eswitch;
> -	uplink_rpriv = mlx5_eswitch_get_uplink_priv(esw, REP_ETH);
> -	uplink_priv = &uplink_rpriv->uplink_priv;
> +	uplink_priv = mlx5e_eswitch_rep_uplink_priv(esw);
>  
>  	mlx5e_make_tunnel_match_key(f, filter_dev, &tunnel_key);
>  	err = mapping_add(uplink_priv->tunnel_mapping, &tunnel_key, &tun_id);
> @@ -1957,13 +1951,11 @@ static int mlx5e_lookup_flow_tunnel_id(struct mlx5e_priv *priv,
>  				       u32 *tun_id)
>  {
>  	struct mlx5_rep_uplink_priv *uplink_priv;
> -	struct mlx5e_rep_priv *uplink_rpriv;
>  	struct tunnel_match_key tunnel_key;
>  	struct mlx5_eswitch *esw;
>  
>  	esw = priv->mdev->priv.eswitch;
> -	uplink_rpriv = mlx5_eswitch_get_uplink_priv(esw, REP_ETH);
> -	uplink_priv = &uplink_rpriv->uplink_priv;
> +	uplink_priv = mlx5e_eswitch_rep_uplink_priv(esw);
>  
>  	mlx5e_make_tunnel_match_key(f, filter_dev, &tunnel_key);
>  	return mapping_find_by_data(uplink_priv->tunnel_mapping, &tunnel_key, tun_id);
> @@ -1974,12 +1966,10 @@ static void mlx5e_put_flow_tunnel_id(struct mlx5e_tc_flow *flow)
>  	u32 enc_opts_id = flow->tunnel_id & ENC_OPTS_BITS_MASK;
>  	u32 tun_id = flow->tunnel_id >> ENC_OPTS_BITS;
>  	struct mlx5_rep_uplink_priv *uplink_priv;
> -	struct mlx5e_rep_priv *uplink_rpriv;
>  	struct mlx5_eswitch *esw;
>  
>  	esw = flow->priv->mdev->priv.eswitch;
> -	uplink_rpriv = mlx5_eswitch_get_uplink_priv(esw, REP_ETH);
> -	uplink_priv = &uplink_rpriv->uplink_priv;
> +	uplink_priv = mlx5e_eswitch_rep_uplink_priv(esw);
>  
>  	if (tun_id)
>  		mapping_remove(uplink_priv->tunnel_mapping, tun_id);
> @@ -4841,7 +4831,6 @@ static bool mlx5e_restore_tunnel(struct mlx5e_priv *priv, struct sk_buff *skb,
>  	struct mlx5_eswitch *esw = priv->mdev->priv.eswitch;
>  	struct flow_dissector_key_enc_opts enc_opts = {};
>  	struct mlx5_rep_uplink_priv *uplink_priv;
> -	struct mlx5e_rep_priv *uplink_rpriv;
>  	struct metadata_dst *tun_dst;
>  	struct tunnel_match_key key;
>  	u32 tun_id, enc_opts_id;
> @@ -4854,9 +4843,7 @@ static bool mlx5e_restore_tunnel(struct mlx5e_priv *priv, struct sk_buff *skb,
>  	if (!tun_id)
>  		return true;
>  
> -	uplink_rpriv = mlx5_eswitch_get_uplink_priv(esw, REP_ETH);
> -	uplink_priv = &uplink_rpriv->uplink_priv;
> -
> +	uplink_priv = mlx5e_eswitch_rep_uplink_priv(esw);
>  	err = mapping_find(uplink_priv->tunnel_mapping, tun_id, &key);
>  	if (err) {
>  		WARN_ON_ONCE(true);
> @@ -4920,7 +4907,6 @@ bool mlx5e_tc_rep_update_skb(struct mlx5_cqe64 *cqe,
>  #if IS_ENABLED(CONFIG_NET_TC_SKB_EXT)
>  	u32 chain = 0, reg_c0, reg_c1, tunnel_id, tuple_id;
>  	struct mlx5_rep_uplink_priv *uplink_priv;
> -	struct mlx5e_rep_priv *uplink_rpriv;
>  	struct tc_skb_ext *tc_skb_ext;
>  	struct mlx5_eswitch *esw;
>  	struct mlx5e_priv *priv;
> @@ -4956,9 +4942,7 @@ bool mlx5e_tc_rep_update_skb(struct mlx5_cqe64 *cqe,
>  		tc_skb_ext->chain = chain;
>  
>  		tuple_id = reg_c1 & TUPLE_ID_MAX;
> -
> -		uplink_rpriv = mlx5_eswitch_get_uplink_priv(esw, REP_ETH);
> -		uplink_priv = &uplink_rpriv->uplink_priv;
> +		uplink_priv = mlx5e_eswitch_rep_uplink_priv(esw);
>  		if (!mlx5e_tc_ct_restore_flow(uplink_priv, skb, tuple_id))
>  			return false;
>  	}
>
diff mbox series

Patch

diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en/tc_ct.c b/drivers/net/ethernet/mellanox/mlx5/core/en/tc_ct.c
index 16416eaac39e..c5d5e69ff147 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/en/tc_ct.c
+++ b/drivers/net/ethernet/mellanox/mlx5/core/en/tc_ct.c
@@ -100,10 +100,8 @@  struct mlx5_ct_entry {
 {
 	struct mlx5_eswitch *esw = priv->mdev->priv.eswitch;
 	struct mlx5_rep_uplink_priv *uplink_priv;
-	struct mlx5e_rep_priv *uplink_rpriv;
 
-	uplink_rpriv = mlx5_eswitch_get_uplink_priv(esw, REP_ETH);
-	uplink_priv = &uplink_rpriv->uplink_priv;
+	uplink_priv = mlx5e_eswitch_rep_uplink_priv(esw);
 	return uplink_priv->ct_priv;
 }
 
diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en_rep.h b/drivers/net/ethernet/mellanox/mlx5/core/en_rep.h
index 6a2337900420..899ffa0872b7 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/en_rep.h
+++ b/drivers/net/ethernet/mellanox/mlx5/core/en_rep.h
@@ -109,6 +109,15 @@  struct mlx5e_rep_priv *mlx5e_rep_to_rep_priv(struct mlx5_eswitch_rep *rep)
 	return rep->rep_data[REP_ETH].priv;
 }
 
+static inline struct mlx5_rep_uplink_priv *
+mlx5e_eswitch_rep_uplink_priv(struct mlx5_eswitch *esw)
+{
+	struct mlx5e_rep_priv *priv;
+
+	priv = mlx5_eswitch_get_uplink_priv(esw, REP_ETH);
+	return &priv->uplink_priv;
+}
+
 struct mlx5e_neigh {
 	struct net_device *dev;
 	union {
diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en_tc.c b/drivers/net/ethernet/mellanox/mlx5/core/en_tc.c
index 64f5c3f3dbb3..696544e2a25b 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/en_tc.c
+++ b/drivers/net/ethernet/mellanox/mlx5/core/en_tc.c
@@ -1250,12 +1250,10 @@  static void unready_flow_del(struct mlx5e_tc_flow *flow)
 static void add_unready_flow(struct mlx5e_tc_flow *flow)
 {
 	struct mlx5_rep_uplink_priv *uplink_priv;
-	struct mlx5e_rep_priv *rpriv;
 	struct mlx5_eswitch *esw;
 
 	esw = flow->priv->mdev->priv.eswitch;
-	rpriv = mlx5_eswitch_get_uplink_priv(esw, REP_ETH);
-	uplink_priv = &rpriv->uplink_priv;
+	uplink_priv = mlx5e_eswitch_rep_uplink_priv(esw);
 
 	mutex_lock(&uplink_priv->unready_flows_lock);
 	unready_flow_add(flow, &uplink_priv->unready_flows);
@@ -1265,12 +1263,10 @@  static void add_unready_flow(struct mlx5e_tc_flow *flow)
 static void remove_unready_flow(struct mlx5e_tc_flow *flow)
 {
 	struct mlx5_rep_uplink_priv *uplink_priv;
-	struct mlx5e_rep_priv *rpriv;
 	struct mlx5_eswitch *esw;
 
 	esw = flow->priv->mdev->priv.eswitch;
-	rpriv = mlx5_eswitch_get_uplink_priv(esw, REP_ETH);
-	uplink_priv = &rpriv->uplink_priv;
+	uplink_priv = mlx5e_eswitch_rep_uplink_priv(esw);
 
 	mutex_lock(&uplink_priv->unready_flows_lock);
 	unready_flow_del(flow);
@@ -1888,7 +1884,6 @@  static int mlx5e_get_flow_tunnel_id(struct mlx5e_priv *priv,
 	struct mlx5e_tc_mod_hdr_acts *mod_hdr_acts;
 	struct flow_match_enc_opts enc_opts_match;
 	struct mlx5_rep_uplink_priv *uplink_priv;
-	struct mlx5e_rep_priv *uplink_rpriv;
 	struct tunnel_match_key tunnel_key;
 	bool enc_opts_is_dont_care = true;
 	u32 tun_id, enc_opts_id = 0;
@@ -1897,8 +1892,7 @@  static int mlx5e_get_flow_tunnel_id(struct mlx5e_priv *priv,
 	int err;
 
 	esw = priv->mdev->priv.eswitch;
-	uplink_rpriv = mlx5_eswitch_get_uplink_priv(esw, REP_ETH);
-	uplink_priv = &uplink_rpriv->uplink_priv;
+	uplink_priv = mlx5e_eswitch_rep_uplink_priv(esw);
 
 	mlx5e_make_tunnel_match_key(f, filter_dev, &tunnel_key);
 	err = mapping_add(uplink_priv->tunnel_mapping, &tunnel_key, &tun_id);
@@ -1957,13 +1951,11 @@  static int mlx5e_lookup_flow_tunnel_id(struct mlx5e_priv *priv,
 				       u32 *tun_id)
 {
 	struct mlx5_rep_uplink_priv *uplink_priv;
-	struct mlx5e_rep_priv *uplink_rpriv;
 	struct tunnel_match_key tunnel_key;
 	struct mlx5_eswitch *esw;
 
 	esw = priv->mdev->priv.eswitch;
-	uplink_rpriv = mlx5_eswitch_get_uplink_priv(esw, REP_ETH);
-	uplink_priv = &uplink_rpriv->uplink_priv;
+	uplink_priv = mlx5e_eswitch_rep_uplink_priv(esw);
 
 	mlx5e_make_tunnel_match_key(f, filter_dev, &tunnel_key);
 	return mapping_find_by_data(uplink_priv->tunnel_mapping, &tunnel_key, tun_id);
@@ -1974,12 +1966,10 @@  static void mlx5e_put_flow_tunnel_id(struct mlx5e_tc_flow *flow)
 	u32 enc_opts_id = flow->tunnel_id & ENC_OPTS_BITS_MASK;
 	u32 tun_id = flow->tunnel_id >> ENC_OPTS_BITS;
 	struct mlx5_rep_uplink_priv *uplink_priv;
-	struct mlx5e_rep_priv *uplink_rpriv;
 	struct mlx5_eswitch *esw;
 
 	esw = flow->priv->mdev->priv.eswitch;
-	uplink_rpriv = mlx5_eswitch_get_uplink_priv(esw, REP_ETH);
-	uplink_priv = &uplink_rpriv->uplink_priv;
+	uplink_priv = mlx5e_eswitch_rep_uplink_priv(esw);
 
 	if (tun_id)
 		mapping_remove(uplink_priv->tunnel_mapping, tun_id);
@@ -4841,7 +4831,6 @@  static bool mlx5e_restore_tunnel(struct mlx5e_priv *priv, struct sk_buff *skb,
 	struct mlx5_eswitch *esw = priv->mdev->priv.eswitch;
 	struct flow_dissector_key_enc_opts enc_opts = {};
 	struct mlx5_rep_uplink_priv *uplink_priv;
-	struct mlx5e_rep_priv *uplink_rpriv;
 	struct metadata_dst *tun_dst;
 	struct tunnel_match_key key;
 	u32 tun_id, enc_opts_id;
@@ -4854,9 +4843,7 @@  static bool mlx5e_restore_tunnel(struct mlx5e_priv *priv, struct sk_buff *skb,
 	if (!tun_id)
 		return true;
 
-	uplink_rpriv = mlx5_eswitch_get_uplink_priv(esw, REP_ETH);
-	uplink_priv = &uplink_rpriv->uplink_priv;
-
+	uplink_priv = mlx5e_eswitch_rep_uplink_priv(esw);
 	err = mapping_find(uplink_priv->tunnel_mapping, tun_id, &key);
 	if (err) {
 		WARN_ON_ONCE(true);
@@ -4920,7 +4907,6 @@  bool mlx5e_tc_rep_update_skb(struct mlx5_cqe64 *cqe,
 #if IS_ENABLED(CONFIG_NET_TC_SKB_EXT)
 	u32 chain = 0, reg_c0, reg_c1, tunnel_id, tuple_id;
 	struct mlx5_rep_uplink_priv *uplink_priv;
-	struct mlx5e_rep_priv *uplink_rpriv;
 	struct tc_skb_ext *tc_skb_ext;
 	struct mlx5_eswitch *esw;
 	struct mlx5e_priv *priv;
@@ -4956,9 +4942,7 @@  bool mlx5e_tc_rep_update_skb(struct mlx5_cqe64 *cqe,
 		tc_skb_ext->chain = chain;
 
 		tuple_id = reg_c1 & TUPLE_ID_MAX;
-
-		uplink_rpriv = mlx5_eswitch_get_uplink_priv(esw, REP_ETH);
-		uplink_priv = &uplink_rpriv->uplink_priv;
+		uplink_priv = mlx5e_eswitch_rep_uplink_priv(esw);
 		if (!mlx5e_tc_ct_restore_flow(uplink_priv, skb, tuple_id))
 			return false;
 	}