net/mlx5e: TC, Move flow hashtable to be per rep
authorPaul Blakey <paulb@nvidia.com>
Mon, 24 Jan 2022 13:03:27 +0000 (15:03 +0200)
committerSaeed Mahameed <saeedm@nvidia.com>
Thu, 17 Feb 2022 07:55:15 +0000 (23:55 -0800)
To allow shared tc block offload between two or more reps of the
same eswitch, move the tc flow hashtable to be per rep, instead
of per eswitch.

Signed-off-by: Paul Blakey <paulb@nvidia.com>
Reviewed-by: Roi Dayan <roid@nvidia.com>
Signed-off-by: Saeed Mahameed <saeedm@nvidia.com>
drivers/net/ethernet/mellanox/mlx5/core/en/rep/tc.c
drivers/net/ethernet/mellanox/mlx5/core/en_rep.c
drivers/net/ethernet/mellanox/mlx5/core/en_rep.h
drivers/net/ethernet/mellanox/mlx5/core/en_tc.c
drivers/net/ethernet/mellanox/mlx5/core/en_tc.h

index 0991345c4ae5cd18e00ac3d8189d58c16dd57ece..86fa0bdbee36f3ca4a231049369ea1e97f69cf96 100644 (file)
@@ -263,14 +263,14 @@ int mlx5e_rep_tc_init(struct mlx5e_rep_priv *rpriv)
        INIT_LIST_HEAD(&uplink_priv->unready_flows);
 
        /* init shared tc flow table */
-       err = mlx5e_tc_esw_init(&uplink_priv->tc_ht);
+       err = mlx5e_tc_esw_init(uplink_priv);
        return err;
 }
 
 void mlx5e_rep_tc_cleanup(struct mlx5e_rep_priv *rpriv)
 {
        /* delete shared tc flow table */
-       mlx5e_tc_esw_cleanup(&rpriv->uplink_priv.tc_ht);
+       mlx5e_tc_esw_cleanup(&rpriv->uplink_priv);
        mutex_destroy(&rpriv->uplink_priv.unready_flows_lock);
 }
 
index 6070b8a1381871fdf0650237cfb132f0651127de..6b7e7ea6ded2327be94d48dfe1b1ef249185ff68 100644 (file)
@@ -942,15 +942,21 @@ static int mlx5e_init_rep_tx(struct mlx5e_priv *priv)
                return err;
        }
 
+       err = mlx5e_tc_ht_init(&rpriv->tc_ht);
+       if (err)
+               goto err_ht_init;
+
        if (rpriv->rep->vport == MLX5_VPORT_UPLINK) {
                err = mlx5e_init_uplink_rep_tx(rpriv);
                if (err)
-                       goto destroy_tises;
+                       goto err_init_tx;
        }
 
        return 0;
 
-destroy_tises:
+err_init_tx:
+       mlx5e_tc_ht_cleanup(&rpriv->tc_ht);
+err_ht_init:
        mlx5e_destroy_tises(priv);
        return err;
 }
@@ -970,6 +976,8 @@ static void mlx5e_cleanup_rep_tx(struct mlx5e_priv *priv)
 
        if (rpriv->rep->vport == MLX5_VPORT_UPLINK)
                mlx5e_cleanup_uplink_rep_tx(rpriv);
+
+       mlx5e_tc_ht_cleanup(&rpriv->tc_ht);
 }
 
 static void mlx5e_rep_enable(struct mlx5e_priv *priv)
index b01dacb6f527c81f27688dd0c14763ceeb210a17..0b619c7846d09733deffc5c55f4e11e3b31c6393 100644 (file)
@@ -64,11 +64,6 @@ struct mlx5e_tc_tun_encap;
 struct mlx5e_post_act;
 
 struct mlx5_rep_uplink_priv {
-       /* Filters DB - instantiated by the uplink representor and shared by
-        * the uplink's VFs
-        */
-       struct rhashtable  tc_ht;
-
        /* indirect block callbacks are invoked on bind/unbind events
         * on registered higher level devices (e.g. tunnel devices)
         *
@@ -113,6 +108,7 @@ struct mlx5e_rep_priv {
        struct list_head       vport_sqs_list;
        struct mlx5_rep_uplink_priv uplink_priv; /* valid for uplink rep */
        struct rtnl_link_stats64 prev_vf_vport_stats;
+       struct rhashtable tc_ht;
 };
 
 static inline
index 099d4ce160495442e5d32d80b0703b7e59ea4de7..342ab0688f13738d0a3d60dcb36499fbe54bad6f 100644 (file)
@@ -3609,12 +3609,11 @@ static const struct rhashtable_params tc_ht_params = {
 static struct rhashtable *get_tc_ht(struct mlx5e_priv *priv,
                                    unsigned long flags)
 {
-       struct mlx5_eswitch *esw = priv->mdev->priv.eswitch;
-       struct mlx5e_rep_priv *uplink_rpriv;
+       struct mlx5e_rep_priv *rpriv;
 
        if (flags & MLX5_TC_FLAG(ESW_OFFLOAD)) {
-               uplink_rpriv = mlx5_eswitch_get_uplink_priv(esw, REP_ETH);
-               return &uplink_rpriv->uplink_priv.tc_ht;
+               rpriv = priv->ppriv;
+               return &rpriv->tc_ht;
        } else /* NIC offload */
                return &priv->fs.tc.ht;
 }
@@ -4447,10 +4446,27 @@ void mlx5e_tc_nic_cleanup(struct mlx5e_priv *priv)
        mlx5_chains_destroy(tc->chains);
 }
 
-int mlx5e_tc_esw_init(struct rhashtable *tc_ht)
+int mlx5e_tc_ht_init(struct rhashtable *tc_ht)
+{
+       int err;
+
+       err = rhashtable_init(tc_ht, &tc_ht_params);
+       if (err)
+               return err;
+
+       lockdep_set_class(&tc_ht->mutex, &tc_ht_lock_key);
+
+       return 0;
+}
+
+void mlx5e_tc_ht_cleanup(struct rhashtable *tc_ht)
+{
+       rhashtable_free_and_destroy(tc_ht, _mlx5e_tc_del_flow, NULL);
+}
+
+int mlx5e_tc_esw_init(struct mlx5_rep_uplink_priv *uplink_priv)
 {
        const size_t sz_enc_opts = sizeof(struct tunnel_match_enc_opts);
-       struct mlx5_rep_uplink_priv *uplink_priv;
        struct mlx5e_rep_priv *rpriv;
        struct mapping_ctx *mapping;
        struct mlx5_eswitch *esw;
@@ -4458,7 +4474,6 @@ int mlx5e_tc_esw_init(struct rhashtable *tc_ht)
        u64 mapping_id;
        int err = 0;
 
-       uplink_priv = container_of(tc_ht, struct mlx5_rep_uplink_priv, tc_ht);
        rpriv = container_of(uplink_priv, struct mlx5e_rep_priv, uplink_priv);
        priv = netdev_priv(rpriv->netdev);
        esw = priv->mdev->priv.eswitch;
@@ -4498,12 +4513,6 @@ int mlx5e_tc_esw_init(struct rhashtable *tc_ht)
        }
        uplink_priv->tunnel_enc_opts_mapping = mapping;
 
-       err = rhashtable_init(tc_ht, &tc_ht_params);
-       if (err)
-               goto err_ht_init;
-
-       lockdep_set_class(&tc_ht->mutex, &tc_ht_lock_key);
-
        uplink_priv->encap = mlx5e_tc_tun_init(priv);
        if (IS_ERR(uplink_priv->encap)) {
                err = PTR_ERR(uplink_priv->encap);
@@ -4513,8 +4522,6 @@ int mlx5e_tc_esw_init(struct rhashtable *tc_ht)
        return 0;
 
 err_register_fib_notifier:
-       rhashtable_destroy(tc_ht);
-err_ht_init:
        mapping_destroy(uplink_priv->tunnel_enc_opts_mapping);
 err_enc_opts_mapping:
        mapping_destroy(uplink_priv->tunnel_mapping);
@@ -4528,13 +4535,8 @@ err_tun_mapping:
        return err;
 }
 
-void mlx5e_tc_esw_cleanup(struct rhashtable *tc_ht)
+void mlx5e_tc_esw_cleanup(struct mlx5_rep_uplink_priv *uplink_priv)
 {
-       struct mlx5_rep_uplink_priv *uplink_priv;
-
-       uplink_priv = container_of(tc_ht, struct mlx5_rep_uplink_priv, tc_ht);
-
-       rhashtable_free_and_destroy(tc_ht, _mlx5e_tc_del_flow, NULL);
        mlx5e_tc_tun_cleanup(uplink_priv->encap);
 
        mapping_destroy(uplink_priv->tunnel_enc_opts_mapping);
index c6221728b7673e2597813511e727e304ae1472e8..533c897bd517836860eb27f896268fd198de5d53 100644 (file)
@@ -167,8 +167,11 @@ enum {
 
 #define MLX5_TC_FLAG(flag) BIT(MLX5E_TC_FLAG_##flag##_BIT)
 
-int mlx5e_tc_esw_init(struct rhashtable *tc_ht);
-void mlx5e_tc_esw_cleanup(struct rhashtable *tc_ht);
+int mlx5e_tc_esw_init(struct mlx5_rep_uplink_priv *uplink_priv);
+void mlx5e_tc_esw_cleanup(struct mlx5_rep_uplink_priv *uplink_priv);
+
+int mlx5e_tc_ht_init(struct rhashtable *tc_ht);
+void mlx5e_tc_ht_cleanup(struct rhashtable *tc_ht);
 
 int mlx5e_configure_flower(struct net_device *dev, struct mlx5e_priv *priv,
                           struct flow_cls_offload *f, unsigned long flags);
@@ -304,6 +307,8 @@ int mlx5e_set_fwd_to_int_port_actions(struct mlx5e_priv *priv,
 #else /* CONFIG_MLX5_CLS_ACT */
 static inline int  mlx5e_tc_nic_init(struct mlx5e_priv *priv) { return 0; }
 static inline void mlx5e_tc_nic_cleanup(struct mlx5e_priv *priv) {}
+static inline int mlx5e_tc_ht_init(struct rhashtable *tc_ht) { return 0; }
+static inline void mlx5e_tc_ht_cleanup(struct rhashtable *tc_ht) {}
 static inline int
 mlx5e_setup_tc_block_cb(enum tc_setup_type type, void *type_data, void *cb_priv)
 { return -EOPNOTSUPP; }