net/mlx5_core: Connect flow tables
authorMaor Gottlieb <maorg@mellanox.com>
Mon, 11 Jan 2016 08:26:01 +0000 (10:26 +0200)
committerDavid S. Miller <davem@davemloft.net>
Mon, 11 Jan 2016 22:48:53 +0000 (17:48 -0500)
Flow tables from different priorities should be chained together.
When a packet arrives we search for a match in the
by-pass flow tables (first we search for a match in priority 0
and if we don't find a match we move to the next priority).
If we can't find a match in any of the bypass flow-tables, we continue
searching in the flow-tables of the next priority, which are the
kernel's flow tables.

Setting the miss flow table in a new flow table to be the next one in
the list is performed via create flow table API. If we want to change an
existing flow table, for example in order to point from an
existing flow table to the new next-in-list flow table, we use the
modify flow table API.

Signed-off-by: Maor Gottlieb <maorg@mellanox.com>
Signed-off-by: Moni Shoua <monis@mellanox.com>
Signed-off-by: Matan Barak <matanb@mellanox.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
drivers/net/ethernet/mellanox/mlx5/core/fs_cmd.c
drivers/net/ethernet/mellanox/mlx5/core/fs_cmd.h
drivers/net/ethernet/mellanox/mlx5/core/fs_core.c

index 2b5562553f2d4d6a780fdc19c618f1991b0d7560..a9894d2e8e26b01b6e77dc83c5b8df8d5ebd3a7c 100644 (file)
@@ -58,7 +58,8 @@ int mlx5_cmd_update_root_ft(struct mlx5_core_dev *dev,
 
 int mlx5_cmd_create_flow_table(struct mlx5_core_dev *dev,
                               enum fs_flow_table_type type, unsigned int level,
-                              unsigned int log_size, unsigned int *table_id)
+                              unsigned int log_size, struct mlx5_flow_table
+                              *next_ft, unsigned int *table_id)
 {
        u32 out[MLX5_ST_SZ_DW(create_flow_table_out)];
        u32 in[MLX5_ST_SZ_DW(create_flow_table_in)];
@@ -69,6 +70,10 @@ int mlx5_cmd_create_flow_table(struct mlx5_core_dev *dev,
        MLX5_SET(create_flow_table_in, in, opcode,
                 MLX5_CMD_OP_CREATE_FLOW_TABLE);
 
+       if (next_ft) {
+               MLX5_SET(create_flow_table_in, in, table_miss_mode, 1);
+               MLX5_SET(create_flow_table_in, in, table_miss_id, next_ft->id);
+       }
        MLX5_SET(create_flow_table_in, in, table_type, type);
        MLX5_SET(create_flow_table_in, in, level, level);
        MLX5_SET(create_flow_table_in, in, log_size, log_size);
index 1ae9b685c78322a103ad1034ff92d085d4d3dc89..9814d478480392de94b6ad50e16ad558e3cf6da9 100644 (file)
@@ -35,7 +35,8 @@
 
 int mlx5_cmd_create_flow_table(struct mlx5_core_dev *dev,
                               enum fs_flow_table_type type, unsigned int level,
-                              unsigned int log_size, unsigned int *table_id);
+                              unsigned int log_size, struct mlx5_flow_table
+                              *next_ft, unsigned int *table_id);
 
 int mlx5_cmd_destroy_flow_table(struct mlx5_core_dev *dev,
                                struct mlx5_flow_table *ft);
index 64bdb54041d183cd27b0d6b05b8fff5d7e66dd82..c6f864d1ad1aa0d70d2903b628fe5fe6fe656253 100644 (file)
@@ -510,6 +510,48 @@ static struct mlx5_flow_table *find_prev_chained_ft(struct fs_prio *prio)
        return find_closest_ft(prio, true);
 }
 
+static int connect_fts_in_prio(struct mlx5_core_dev *dev,
+                              struct fs_prio *prio,
+                              struct mlx5_flow_table *ft)
+{
+       struct mlx5_flow_table *iter;
+       int i = 0;
+       int err;
+
+       fs_for_each_ft(iter, prio) {
+               i++;
+               err = mlx5_cmd_modify_flow_table(dev,
+                                                iter,
+                                                ft);
+               if (err) {
+                       mlx5_core_warn(dev, "Failed to modify flow table %d\n",
+                                      iter->id);
+                       /* The driver is out of sync with the FW */
+                       if (i > 1)
+                               WARN_ON(true);
+                       return err;
+               }
+       }
+       return 0;
+}
+
+/* Connect flow tables from previous priority of prio to ft */
+static int connect_prev_fts(struct mlx5_core_dev *dev,
+                           struct mlx5_flow_table *ft,
+                           struct fs_prio *prio)
+{
+       struct mlx5_flow_table *prev_ft;
+
+       prev_ft = find_prev_chained_ft(prio);
+       if (prev_ft) {
+               struct fs_prio *prev_prio;
+
+               fs_get_obj(prev_prio, prev_ft->node.parent);
+               return connect_fts_in_prio(dev, prev_prio, ft);
+       }
+       return 0;
+}
+
 static int update_root_ft_create(struct mlx5_flow_table *ft, struct fs_prio
                                 *prio)
 {
@@ -533,10 +575,30 @@ static int update_root_ft_create(struct mlx5_flow_table *ft, struct fs_prio
        return err;
 }
 
+static int connect_flow_table(struct mlx5_core_dev *dev, struct mlx5_flow_table *ft,
+                             struct fs_prio *prio)
+{
+       int err = 0;
+
+       /* Connect_prev_fts and update_root_ft_create are mutually exclusive */
+
+       if (list_empty(&prio->node.children)) {
+               err = connect_prev_fts(dev, ft, prio);
+               if (err)
+                       return err;
+       }
+
+       if (MLX5_CAP_FLOWTABLE(dev,
+                              flow_table_properties_nic_receive.modify_root))
+               err = update_root_ft_create(ft, prio);
+       return err;
+}
+
 struct mlx5_flow_table *mlx5_create_flow_table(struct mlx5_flow_namespace *ns,
                                               int prio,
                                               int max_fte)
 {
+       struct mlx5_flow_table *next_ft = NULL;
        struct mlx5_flow_table *ft;
        int err;
        int log_table_sz;
@@ -570,17 +632,15 @@ struct mlx5_flow_table *mlx5_create_flow_table(struct mlx5_flow_namespace *ns,
 
        tree_init_node(&ft->node, 1, del_flow_table);
        log_table_sz = ilog2(ft->max_fte);
+       next_ft = find_next_chained_ft(fs_prio);
        err = mlx5_cmd_create_flow_table(root->dev, ft->type, ft->level,
-                                        log_table_sz, &ft->id);
+                                        log_table_sz, next_ft, &ft->id);
        if (err)
                goto free_ft;
 
-       if (MLX5_CAP_FLOWTABLE(root->dev,
-                              flow_table_properties_nic_receive.modify_root)) {
-               err = update_root_ft_create(ft, fs_prio);
-               if (err)
-                       goto destroy_ft;
-       }
+       err = connect_flow_table(root->dev, ft, fs_prio);
+       if (err)
+               goto destroy_ft;
        lock_ref_node(&fs_prio->node);
        tree_add_node(&ft->node, &fs_prio->node);
        list_add_tail(&ft->node.list, &fs_prio->node.children);
@@ -967,13 +1027,41 @@ static int update_root_ft_destroy(struct mlx5_flow_table *ft)
        return 0;
 }
 
+/* Connect flow table from previous priority to
+ * the next flow table.
+ */
+static int disconnect_flow_table(struct mlx5_flow_table *ft)
+{
+       struct mlx5_core_dev *dev = get_dev(&ft->node);
+       struct mlx5_flow_table *next_ft;
+       struct fs_prio *prio;
+       int err = 0;
+
+       err = update_root_ft_destroy(ft);
+       if (err)
+               return err;
+
+       fs_get_obj(prio, ft->node.parent);
+       if  (!(list_first_entry(&prio->node.children,
+                               struct mlx5_flow_table,
+                               node.list) == ft))
+               return 0;
+
+       next_ft = find_next_chained_ft(prio);
+       err = connect_prev_fts(dev, next_ft, prio);
+       if (err)
+               mlx5_core_warn(dev, "Failed to disconnect flow table %d\n",
+                              ft->id);
+       return err;
+}
+
 int mlx5_destroy_flow_table(struct mlx5_flow_table *ft)
 {
        struct mlx5_flow_root_namespace *root = find_root(&ft->node);
        int err = 0;
 
        mutex_lock(&root->chain_lock);
-       err = update_root_ft_destroy(ft);
+       err = disconnect_flow_table(ft);
        if (err) {
                mutex_unlock(&root->chain_lock);
                return err;