]> asedeno.scripts.mit.edu Git - linux.git/commitdiff
{IB,net}/mlx5: Constify rep ops functions pointers
authorParav Pandit <parav@mellanox.com>
Wed, 29 May 2019 22:50:41 +0000 (22:50 +0000)
committerSaeed Mahameed <saeedm@mellanox.com>
Fri, 31 May 2019 19:28:14 +0000 (12:28 -0700)
Currently for every representor type and for every single vport,
representer function pointers copy is stored even though they don't
change from one to other vport.

Additionally priv data entry for the rep is not passed during
registration, but its copied. It is used (set and cleared) by the user
of the reps.

As we want to scale vports, to simplify and also to split constants
from data,

1. Rename mlx5_eswitch_rep_if to mlx5_eswitch_rep_ops as to match _ops
prefix with other standard netdev, ibdev ops.
2. Constify the IB and Ethernet rep ops structure.
3. Instead of storing copy of all rep function pointers, store copy
per eswitch rep type.
4. Split data and function pointers to mlx5_eswitch_rep_ops and
mlx5_eswitch_rep_data.

Signed-off-by: Parav Pandit <parav@mellanox.com>
Reviewed-by: Mark Bloch <markb@mellanox.com>
Signed-off-by: Saeed Mahameed <saeedm@mellanox.com>
drivers/infiniband/hw/mlx5/ib_rep.c
drivers/infiniband/hw/mlx5/ib_rep.h
drivers/net/ethernet/mellanox/mlx5/core/en_rep.c
drivers/net/ethernet/mellanox/mlx5/core/en_rep.h
drivers/net/ethernet/mellanox/mlx5/core/eswitch.h
drivers/net/ethernet/mellanox/mlx5/core/eswitch_offloads.c
include/linux/mlx5/eswitch.h

index cbcc40d776b97355e6617909328c8b1afb27c439..22e651cb553466266bd18a3e1281bdb5f27aac9f 100644 (file)
@@ -60,7 +60,7 @@ mlx5_ib_vport_rep_load(struct mlx5_core_dev *dev, struct mlx5_eswitch_rep *rep)
        if (!__mlx5_ib_add(ibdev, profile))
                return -EINVAL;
 
-       rep->rep_if[REP_IB].priv = ibdev;
+       rep->rep_data[REP_IB].priv = ibdev;
 
        return 0;
 }
@@ -70,13 +70,13 @@ mlx5_ib_vport_rep_unload(struct mlx5_eswitch_rep *rep)
 {
        struct mlx5_ib_dev *dev;
 
-       if (!rep->rep_if[REP_IB].priv ||
+       if (!rep->rep_data[REP_IB].priv ||
            rep->vport != MLX5_VPORT_UPLINK)
                return;
 
        dev = mlx5_ib_rep_to_dev(rep);
        __mlx5_ib_remove(dev, dev->profile, MLX5_IB_STAGE_MAX);
-       rep->rep_if[REP_IB].priv = NULL;
+       rep->rep_data[REP_IB].priv = NULL;
 }
 
 static void *mlx5_ib_vport_get_proto_dev(struct mlx5_eswitch_rep *rep)
@@ -84,16 +84,17 @@ static void *mlx5_ib_vport_get_proto_dev(struct mlx5_eswitch_rep *rep)
        return mlx5_ib_rep_to_dev(rep);
 }
 
+static const struct mlx5_eswitch_rep_ops rep_ops = {
+       .load = mlx5_ib_vport_rep_load,
+       .unload = mlx5_ib_vport_rep_unload,
+       .get_proto_dev = mlx5_ib_vport_get_proto_dev,
+};
+
 void mlx5_ib_register_vport_reps(struct mlx5_core_dev *mdev)
 {
        struct mlx5_eswitch *esw = mdev->priv.eswitch;
-       struct mlx5_eswitch_rep_if rep_if = {};
-
-       rep_if.load = mlx5_ib_vport_rep_load;
-       rep_if.unload = mlx5_ib_vport_rep_unload;
-       rep_if.get_proto_dev = mlx5_ib_vport_get_proto_dev;
 
-       mlx5_eswitch_register_vport_reps(esw, &rep_if, REP_IB);
+       mlx5_eswitch_register_vport_reps(esw, &rep_ops, REP_IB);
 }
 
 void mlx5_ib_unregister_vport_reps(struct mlx5_core_dev *mdev)
index c995102b02766a19d62dc3222aed8bcd3aa333c2..22adce2d6795aa48c4beb5ad347050fc2b17a5ab 100644 (file)
@@ -72,6 +72,6 @@ struct net_device *mlx5_ib_get_rep_netdev(struct mlx5_eswitch *esw,
 static inline
 struct mlx5_ib_dev *mlx5_ib_rep_to_dev(struct mlx5_eswitch_rep *rep)
 {
-       return rep->rep_if[REP_IB].priv;
+       return rep->rep_data[REP_IB].priv;
 }
 #endif /* __MLX5_IB_REP_H__ */
index 91e24f1cead885e73e5b1cfbd31fda7ebf809205..33f8f99681a541fe48e82d9405a4f15b17f98d44 100644 (file)
@@ -1752,7 +1752,7 @@ mlx5e_vport_rep_load(struct mlx5_core_dev *dev, struct mlx5_eswitch_rep *rep)
        }
 
        rpriv->netdev = netdev;
-       rep->rep_if[REP_ETH].priv = rpriv;
+       rep->rep_data[REP_ETH].priv = rpriv;
        INIT_LIST_HEAD(&rpriv->vport_sqs_list);
 
        if (rep->vport == MLX5_VPORT_UPLINK) {
@@ -1826,16 +1826,17 @@ static void *mlx5e_vport_rep_get_proto_dev(struct mlx5_eswitch_rep *rep)
        return rpriv->netdev;
 }
 
+static const struct mlx5_eswitch_rep_ops rep_ops = {
+       .load = mlx5e_vport_rep_load,
+       .unload = mlx5e_vport_rep_unload,
+       .get_proto_dev = mlx5e_vport_rep_get_proto_dev
+};
+
 void mlx5e_rep_register_vport_reps(struct mlx5_core_dev *mdev)
 {
        struct mlx5_eswitch *esw = mdev->priv.eswitch;
-       struct mlx5_eswitch_rep_if rep_if = {};
-
-       rep_if.load = mlx5e_vport_rep_load;
-       rep_if.unload = mlx5e_vport_rep_unload;
-       rep_if.get_proto_dev = mlx5e_vport_rep_get_proto_dev;
 
-       mlx5_eswitch_register_vport_reps(esw, &rep_if, REP_ETH);
+       mlx5_eswitch_register_vport_reps(esw, &rep_ops, REP_ETH);
 }
 
 void mlx5e_rep_unregister_vport_reps(struct mlx5_core_dev *mdev)
index c40c025afd998eac8afceef78db697bdf366d832..e34573fd88c15c337b9dc56e38fc4da77af47948 100644 (file)
@@ -91,7 +91,7 @@ struct mlx5e_rep_priv {
 static inline
 struct mlx5e_rep_priv *mlx5e_rep_to_rep_priv(struct mlx5_eswitch_rep *rep)
 {
-       return rep->rep_if[REP_ETH].priv;
+       return rep->rep_data[REP_ETH].priv;
 }
 
 struct mlx5e_neigh {
index b524813cccacbca1f0a59a3a7b2dc3f6a70827df..135d9a29bbdf1cd955a45073267de453a334b504 100644 (file)
@@ -173,6 +173,7 @@ struct mlx5_esw_offload {
        struct mutex peer_mutex;
        DECLARE_HASHTABLE(encap_tbl, 8);
        DECLARE_HASHTABLE(mod_hdr_tbl, 8);
+       const struct mlx5_eswitch_rep_ops *rep_ops[NUM_REP_TYPES];
        u8 inline_mode;
        u64 num_flows;
        u8 encap;
index 05cb2fffd887fe1b0698f6738f219b524fa65e3b..d6246ee042facf39c4475e4a15ee10969baabb70 100644 (file)
@@ -332,7 +332,7 @@ static int esw_set_global_vlan_pop(struct mlx5_eswitch *esw, u8 val)
        esw_debug(esw->dev, "%s applying global %s policy\n", __func__, val ? "pop" : "none");
        for (vf_vport = 1; vf_vport < esw->enabled_vports; vf_vport++) {
                rep = &esw->offloads.vport_reps[vf_vport];
-               if (atomic_read(&rep->rep_if[REP_ETH].state) != REP_LOADED)
+               if (atomic_read(&rep->rep_data[REP_ETH].state) != REP_LOADED)
                        continue;
 
                err = __mlx5_eswitch_set_vport_vlan(esw, rep->vport, 0, 0, val);
@@ -1276,7 +1276,7 @@ int esw_offloads_init_reps(struct mlx5_eswitch *esw)
                ether_addr_copy(rep->hw_id, hw_id);
 
                for (rep_type = 0; rep_type < NUM_REP_TYPES; rep_type++)
-                       atomic_set(&rep->rep_if[rep_type].state,
+                       atomic_set(&rep->rep_data[rep_type].state,
                                   REP_UNREGISTERED);
        }
 
@@ -1286,9 +1286,9 @@ int esw_offloads_init_reps(struct mlx5_eswitch *esw)
 static void __esw_offloads_unload_rep(struct mlx5_eswitch *esw,
                                      struct mlx5_eswitch_rep *rep, u8 rep_type)
 {
-       if (atomic_cmpxchg(&rep->rep_if[rep_type].state,
+       if (atomic_cmpxchg(&rep->rep_data[rep_type].state,
                           REP_LOADED, REP_REGISTERED) == REP_LOADED)
-               rep->rep_if[rep_type].unload(rep);
+               esw->offloads.rep_ops[rep_type]->unload(rep);
 }
 
 static void __unload_reps_special_vport(struct mlx5_eswitch *esw, u8 rep_type)
@@ -1349,11 +1349,11 @@ static int __esw_offloads_load_rep(struct mlx5_eswitch *esw,
 {
        int err = 0;
 
-       if (atomic_cmpxchg(&rep->rep_if[rep_type].state,
+       if (atomic_cmpxchg(&rep->rep_data[rep_type].state,
                           REP_REGISTERED, REP_LOADED) == REP_REGISTERED) {
-               err = rep->rep_if[rep_type].load(esw->dev, rep);
+               err = esw->offloads.rep_ops[rep_type]->load(esw->dev, rep);
                if (err)
-                       atomic_set(&rep->rep_if[rep_type].state,
+                       atomic_set(&rep->rep_data[rep_type].state,
                                   REP_REGISTERED);
        }
 
@@ -2216,21 +2216,17 @@ int mlx5_devlink_eswitch_encap_mode_get(struct devlink *devlink, u8 *encap)
 }
 
 void mlx5_eswitch_register_vport_reps(struct mlx5_eswitch *esw,
-                                     struct mlx5_eswitch_rep_if *__rep_if,
+                                     const struct mlx5_eswitch_rep_ops *ops,
                                      u8 rep_type)
 {
-       struct mlx5_eswitch_rep_if *rep_if;
+       struct mlx5_eswitch_rep_data *rep_data;
        struct mlx5_eswitch_rep *rep;
        int i;
 
+       esw->offloads.rep_ops[rep_type] = ops;
        mlx5_esw_for_all_reps(esw, i, rep) {
-               rep_if = &rep->rep_if[rep_type];
-               rep_if->load   = __rep_if->load;
-               rep_if->unload = __rep_if->unload;
-               rep_if->get_proto_dev = __rep_if->get_proto_dev;
-               rep_if->priv = __rep_if->priv;
-
-               atomic_set(&rep_if->state, REP_REGISTERED);
+               rep_data = &rep->rep_data[rep_type];
+               atomic_set(&rep_data->state, REP_REGISTERED);
        }
 }
 EXPORT_SYMBOL(mlx5_eswitch_register_vport_reps);
@@ -2245,7 +2241,7 @@ void mlx5_eswitch_unregister_vport_reps(struct mlx5_eswitch *esw, u8 rep_type)
                __unload_reps_all_vport(esw, max_vf, rep_type);
 
        mlx5_esw_for_all_reps(esw, i, rep)
-               atomic_set(&rep->rep_if[rep_type].state, REP_UNREGISTERED);
+               atomic_set(&rep->rep_data[rep_type].state, REP_UNREGISTERED);
 }
 EXPORT_SYMBOL(mlx5_eswitch_unregister_vport_reps);
 
@@ -2254,7 +2250,7 @@ void *mlx5_eswitch_get_uplink_priv(struct mlx5_eswitch *esw, u8 rep_type)
        struct mlx5_eswitch_rep *rep;
 
        rep = mlx5_eswitch_get_rep(esw, MLX5_VPORT_UPLINK);
-       return rep->rep_if[rep_type].priv;
+       return rep->rep_data[rep_type].priv;
 }
 
 void *mlx5_eswitch_get_proto_dev(struct mlx5_eswitch *esw,
@@ -2265,9 +2261,9 @@ void *mlx5_eswitch_get_proto_dev(struct mlx5_eswitch *esw,
 
        rep = mlx5_eswitch_get_rep(esw, vport);
 
-       if (atomic_read(&rep->rep_if[rep_type].state) == REP_LOADED &&
-           rep->rep_if[rep_type].get_proto_dev)
-               return rep->rep_if[rep_type].get_proto_dev(rep);
+       if (atomic_read(&rep->rep_data[rep_type].state) == REP_LOADED &&
+           esw->offloads.rep_ops[rep_type]->get_proto_dev)
+               return esw->offloads.rep_ops[rep_type]->get_proto_dev(rep);
        return NULL;
 }
 EXPORT_SYMBOL(mlx5_eswitch_get_proto_dev);
index 0ca77dd1429c07efb12e17d5a0e2311065ec82c9..d81ee4df181c07b16ac54a16543859d9738aba45 100644 (file)
@@ -29,17 +29,19 @@ enum {
 };
 
 struct mlx5_eswitch_rep;
-struct mlx5_eswitch_rep_if {
-       int                    (*load)(struct mlx5_core_dev *dev,
-                                      struct mlx5_eswitch_rep *rep);
-       void                   (*unload)(struct mlx5_eswitch_rep *rep);
-       void                   *(*get_proto_dev)(struct mlx5_eswitch_rep *rep);
-       void                    *priv;
-       atomic_t                state;
+struct mlx5_eswitch_rep_ops {
+       int (*load)(struct mlx5_core_dev *dev, struct mlx5_eswitch_rep *rep);
+       void (*unload)(struct mlx5_eswitch_rep *rep);
+       void *(*get_proto_dev)(struct mlx5_eswitch_rep *rep);
+};
+
+struct mlx5_eswitch_rep_data {
+       void *priv;
+       atomic_t state;
 };
 
 struct mlx5_eswitch_rep {
-       struct mlx5_eswitch_rep_if rep_if[NUM_REP_TYPES];
+       struct mlx5_eswitch_rep_data rep_data[NUM_REP_TYPES];
        u16                    vport;
        u8                     hw_id[ETH_ALEN];
        u16                    vlan;
@@ -47,7 +49,7 @@ struct mlx5_eswitch_rep {
 };
 
 void mlx5_eswitch_register_vport_reps(struct mlx5_eswitch *esw,
-                                     struct mlx5_eswitch_rep_if *rep_if,
+                                     const struct mlx5_eswitch_rep_ops *ops,
                                      u8 rep_type);
 void mlx5_eswitch_unregister_vport_reps(struct mlx5_eswitch *esw, u8 rep_type);
 void *mlx5_eswitch_get_proto_dev(struct mlx5_eswitch *esw,