net/mlx5: Split FDB fast path prio to multiple namespaces
[sfrench/cifs-2.6.git] / drivers / net / ethernet / mellanox / mlx5 / core / fs_core.c
index cdcbf9d0ae6cf08e76be1d45d65842d9bf3095cd..7eb6d58733accb64ffa679a3c20d68d7fa7c2bf1 100644 (file)
@@ -40,6 +40,7 @@
 #include "diag/fs_tracepoint.h"
 #include "accel/ipsec.h"
 #include "fpga/ipsec.h"
+#include "eswitch.h"
 
 #define INIT_TREE_NODE_ARRAY_SIZE(...) (sizeof((struct init_tree_node[]){__VA_ARGS__}) /\
                                         sizeof(struct init_tree_node))
@@ -713,7 +714,7 @@ static struct mlx5_flow_table *find_closest_ft_recursive(struct fs_node  *root,
        struct fs_node *iter = list_entry(start, struct fs_node, list);
        struct mlx5_flow_table *ft = NULL;
 
-       if (!root)
+       if (!root || root->type == FS_TYPE_PRIO_CHAINS)
                return NULL;
 
        list_for_each_advance_continue(iter, &root->children, reverse) {
@@ -1973,6 +1974,18 @@ void mlx5_destroy_flow_group(struct mlx5_flow_group *fg)
                               fg->id);
 }
 
+struct mlx5_flow_namespace *mlx5_get_fdb_sub_ns(struct mlx5_core_dev *dev,
+                                               int n)
+{
+       struct mlx5_flow_steering *steering = dev->priv.steering;
+
+       if (!steering || !steering->fdb_sub_ns)
+               return NULL;
+
+       return steering->fdb_sub_ns[n];
+}
+EXPORT_SYMBOL(mlx5_get_fdb_sub_ns);
+
 struct mlx5_flow_namespace *mlx5_get_flow_namespace(struct mlx5_core_dev *dev,
                                                    enum mlx5_flow_namespace_type type)
 {
@@ -2051,8 +2064,10 @@ struct mlx5_flow_namespace *mlx5_get_flow_vport_acl_namespace(struct mlx5_core_d
        }
 }
 
-static struct fs_prio *fs_create_prio(struct mlx5_flow_namespace *ns,
-                                     unsigned int prio, int num_levels)
+static struct fs_prio *_fs_create_prio(struct mlx5_flow_namespace *ns,
+                                      unsigned int prio,
+                                      int num_levels,
+                                      enum fs_node_type type)
 {
        struct fs_prio *fs_prio;
 
@@ -2060,7 +2075,7 @@ static struct fs_prio *fs_create_prio(struct mlx5_flow_namespace *ns,
        if (!fs_prio)
                return ERR_PTR(-ENOMEM);
 
-       fs_prio->node.type = FS_TYPE_PRIO;
+       fs_prio->node.type = type;
        tree_init_node(&fs_prio->node, NULL, del_sw_prio);
        tree_add_node(&fs_prio->node, &ns->node);
        fs_prio->num_levels = num_levels;
@@ -2070,6 +2085,19 @@ static struct fs_prio *fs_create_prio(struct mlx5_flow_namespace *ns,
        return fs_prio;
 }
 
+static struct fs_prio *fs_create_prio_chained(struct mlx5_flow_namespace *ns,
+                                             unsigned int prio,
+                                             int num_levels)
+{
+       return _fs_create_prio(ns, prio, num_levels, FS_TYPE_PRIO_CHAINS);
+}
+
+static struct fs_prio *fs_create_prio(struct mlx5_flow_namespace *ns,
+                                     unsigned int prio, int num_levels)
+{
+       return _fs_create_prio(ns, prio, num_levels, FS_TYPE_PRIO);
+}
+
 static struct mlx5_flow_namespace *fs_init_namespace(struct mlx5_flow_namespace
                                                     *ns)
 {
@@ -2374,6 +2402,9 @@ void mlx5_cleanup_fs(struct mlx5_core_dev *dev)
        cleanup_egress_acls_root_ns(dev);
        cleanup_ingress_acls_root_ns(dev);
        cleanup_root_ns(steering->fdb_root_ns);
+       steering->fdb_root_ns = NULL;
+       kfree(steering->fdb_sub_ns);
+       steering->fdb_sub_ns = NULL;
        cleanup_root_ns(steering->sniffer_rx_root_ns);
        cleanup_root_ns(steering->sniffer_tx_root_ns);
        cleanup_root_ns(steering->egress_root_ns);
@@ -2419,27 +2450,64 @@ static int init_sniffer_rx_root_ns(struct mlx5_flow_steering *steering)
 
 static int init_fdb_root_ns(struct mlx5_flow_steering *steering)
 {
-       struct fs_prio *prio;
+       struct mlx5_flow_namespace *ns;
+       struct fs_prio *maj_prio;
+       struct fs_prio *min_prio;
+       int levels;
+       int chain;
+       int prio;
+       int err;
 
        steering->fdb_root_ns = create_root_ns(steering, FS_FT_FDB);
        if (!steering->fdb_root_ns)
                return -ENOMEM;
 
-       prio = fs_create_prio(&steering->fdb_root_ns->ns, 0, 2);
-       if (IS_ERR(prio))
+       steering->fdb_sub_ns = kzalloc(sizeof(steering->fdb_sub_ns) *
+                                      FDB_MAX_CHAIN + 1, GFP_KERNEL);
+       if (!steering->fdb_sub_ns)
+               return -ENOMEM;
+
+       levels = 2 * FDB_MAX_PRIO * (FDB_MAX_CHAIN + 1);
+       maj_prio = fs_create_prio_chained(&steering->fdb_root_ns->ns, 0,
+                                         levels);
+       if (IS_ERR(maj_prio)) {
+               err = PTR_ERR(maj_prio);
                goto out_err;
+       }
 
-       prio = fs_create_prio(&steering->fdb_root_ns->ns, 1, 1);
-       if (IS_ERR(prio))
+       for (chain = 0; chain <= FDB_MAX_CHAIN; chain++) {
+               ns = fs_create_namespace(maj_prio);
+               if (IS_ERR(ns)) {
+                       err = PTR_ERR(ns);
+                       goto out_err;
+               }
+
+               for (prio = 0; prio < FDB_MAX_PRIO * (chain + 1); prio++) {
+                       min_prio = fs_create_prio(ns, prio, 2);
+                       if (IS_ERR(min_prio)) {
+                               err = PTR_ERR(min_prio);
+                               goto out_err;
+                       }
+               }
+
+               steering->fdb_sub_ns[chain] = ns;
+       }
+
+       maj_prio = fs_create_prio(&steering->fdb_root_ns->ns, 1, 1);
+       if (IS_ERR(maj_prio)) {
+               err = PTR_ERR(maj_prio);
                goto out_err;
+       }
 
        set_prio_attrs(steering->fdb_root_ns);
        return 0;
 
 out_err:
        cleanup_root_ns(steering->fdb_root_ns);
+       kfree(steering->fdb_sub_ns);
+       steering->fdb_sub_ns = NULL;
        steering->fdb_root_ns = NULL;
-       return PTR_ERR(prio);
+       return err;
 }
 
 static int init_egress_acl_root_ns(struct mlx5_flow_steering *steering, int vport)