Maor Gottlieb | de8575e | 2015-12-10 17:12:40 +0200 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2015, Mellanox Technologies. All rights reserved. |
| 3 | * |
| 4 | * This software is available to you under a choice of one of two |
| 5 | * licenses. You may choose to be licensed under the terms of the GNU |
| 6 | * General Public License (GPL) Version 2, available from the file |
| 7 | * COPYING in the main directory of this source tree, or the |
| 8 | * OpenIB.org BSD license below: |
| 9 | * |
| 10 | * Redistribution and use in source and binary forms, with or |
| 11 | * without modification, are permitted provided that the following |
| 12 | * conditions are met: |
| 13 | * |
| 14 | * - Redistributions of source code must retain the above |
| 15 | * copyright notice, this list of conditions and the following |
| 16 | * disclaimer. |
| 17 | * |
| 18 | * - Redistributions in binary form must reproduce the above |
| 19 | * copyright notice, this list of conditions and the following |
| 20 | * disclaimer in the documentation and/or other materials |
| 21 | * provided with the distribution. |
| 22 | * |
| 23 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, |
| 24 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
| 25 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
| 26 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS |
| 27 | * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN |
| 28 | * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN |
| 29 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
| 30 | * SOFTWARE. |
| 31 | */ |
| 32 | |
| 33 | #include <linux/mutex.h> |
| 34 | #include <linux/mlx5/driver.h> |
| 35 | |
| 36 | #include "mlx5_core.h" |
| 37 | #include "fs_core.h" |
Maor Gottlieb | 0c56b97 | 2015-12-10 17:12:42 +0200 | [diff] [blame] | 38 | #include "fs_cmd.h" |
| 39 | |
Maor Gottlieb | 2530236 | 2015-12-10 17:12:43 +0200 | [diff] [blame] | 40 | #define INIT_TREE_NODE_ARRAY_SIZE(...) (sizeof((struct init_tree_node[]){__VA_ARGS__}) /\ |
| 41 | sizeof(struct init_tree_node)) |
| 42 | |
Maor Gottlieb | a257b94 | 2016-04-29 01:36:34 +0300 | [diff] [blame] | 43 | #define ADD_PRIO(num_prios_val, min_level_val, num_levels_val, caps_val,\ |
Maor Gottlieb | 8d40d16 | 2016-01-11 10:26:03 +0200 | [diff] [blame] | 44 | ...) {.type = FS_TYPE_PRIO,\ |
Maor Gottlieb | 2530236 | 2015-12-10 17:12:43 +0200 | [diff] [blame] | 45 | .min_ft_level = min_level_val,\ |
Maor Gottlieb | a257b94 | 2016-04-29 01:36:34 +0300 | [diff] [blame] | 46 | .num_levels = num_levels_val,\ |
Maor Gottlieb | 4cbdd30 | 2016-01-11 10:26:04 +0200 | [diff] [blame] | 47 | .num_leaf_prios = num_prios_val,\ |
Maor Gottlieb | 8d40d16 | 2016-01-11 10:26:03 +0200 | [diff] [blame] | 48 | .caps = caps_val,\ |
Maor Gottlieb | 2530236 | 2015-12-10 17:12:43 +0200 | [diff] [blame] | 49 | .children = (struct init_tree_node[]) {__VA_ARGS__},\ |
| 50 | .ar_size = INIT_TREE_NODE_ARRAY_SIZE(__VA_ARGS__) \ |
| 51 | } |
| 52 | |
Maor Gottlieb | a257b94 | 2016-04-29 01:36:34 +0300 | [diff] [blame] | 53 | #define ADD_MULTIPLE_PRIO(num_prios_val, num_levels_val, ...)\ |
| 54 | ADD_PRIO(num_prios_val, 0, num_levels_val, {},\ |
Maor Gottlieb | 4cbdd30 | 2016-01-11 10:26:04 +0200 | [diff] [blame] | 55 | __VA_ARGS__)\ |
Maor Gottlieb | 2530236 | 2015-12-10 17:12:43 +0200 | [diff] [blame] | 56 | |
| 57 | #define ADD_NS(...) {.type = FS_TYPE_NAMESPACE,\ |
| 58 | .children = (struct init_tree_node[]) {__VA_ARGS__},\ |
| 59 | .ar_size = INIT_TREE_NODE_ARRAY_SIZE(__VA_ARGS__) \ |
| 60 | } |
| 61 | |
Maor Gottlieb | 8d40d16 | 2016-01-11 10:26:03 +0200 | [diff] [blame] | 62 | #define INIT_CAPS_ARRAY_SIZE(...) (sizeof((long[]){__VA_ARGS__}) /\ |
| 63 | sizeof(long)) |
| 64 | |
| 65 | #define FS_CAP(cap) (__mlx5_bit_off(flow_table_nic_cap, cap)) |
| 66 | |
| 67 | #define FS_REQUIRED_CAPS(...) {.arr_sz = INIT_CAPS_ARRAY_SIZE(__VA_ARGS__), \ |
| 68 | .caps = (long[]) {__VA_ARGS__} } |
| 69 | |
Maor Gottlieb | 6dc6071 | 2016-07-04 17:23:08 +0300 | [diff] [blame] | 70 | #define FS_CHAINING_CAPS FS_REQUIRED_CAPS(FS_CAP(flow_table_properties_nic_receive.flow_modify_en), \ |
| 71 | FS_CAP(flow_table_properties_nic_receive.modify_root), \ |
| 72 | FS_CAP(flow_table_properties_nic_receive.identified_miss_table_mode), \ |
| 73 | FS_CAP(flow_table_properties_nic_receive.flow_table_modify)) |
| 74 | |
Maor Gottlieb | a257b94 | 2016-04-29 01:36:34 +0300 | [diff] [blame] | 75 | #define LEFTOVERS_NUM_LEVELS 1 |
Maor Gottlieb | 4cbdd30 | 2016-01-11 10:26:04 +0200 | [diff] [blame] | 76 | #define LEFTOVERS_NUM_PRIOS 1 |
Maor Gottlieb | 4cbdd30 | 2016-01-11 10:26:04 +0200 | [diff] [blame] | 77 | |
Maor Gottlieb | a257b94 | 2016-04-29 01:36:34 +0300 | [diff] [blame] | 78 | #define BY_PASS_PRIO_NUM_LEVELS 1 |
Maor Gottlieb | 6dc6071 | 2016-07-04 17:23:08 +0300 | [diff] [blame] | 79 | #define BY_PASS_MIN_LEVEL (ETHTOOL_MIN_LEVEL + MLX5_BY_PASS_NUM_PRIOS +\ |
Maor Gottlieb | a257b94 | 2016-04-29 01:36:34 +0300 | [diff] [blame] | 80 | LEFTOVERS_NUM_PRIOS) |
| 81 | |
Maor Gottlieb | 6dc6071 | 2016-07-04 17:23:08 +0300 | [diff] [blame] | 82 | #define ETHTOOL_PRIO_NUM_LEVELS 1 |
Maor Gottlieb | e5835f2 | 2016-08-29 01:13:50 +0300 | [diff] [blame] | 83 | #define ETHTOOL_NUM_PRIOS 11 |
Maor Gottlieb | 6dc6071 | 2016-07-04 17:23:08 +0300 | [diff] [blame] | 84 | #define ETHTOOL_MIN_LEVEL (KERNEL_MIN_LEVEL + ETHTOOL_NUM_PRIOS) |
Maor Gottlieb | 1cabe6b | 2016-04-29 01:36:40 +0300 | [diff] [blame] | 85 | /* Vlan, mac, ttc, aRFS */ |
| 86 | #define KERNEL_NIC_PRIO_NUM_LEVELS 4 |
Maor Gottlieb | 13de6c1 | 2016-04-29 01:36:36 +0300 | [diff] [blame] | 87 | #define KERNEL_NIC_NUM_PRIOS 1 |
| 88 | /* One more level for tc */ |
| 89 | #define KERNEL_MIN_LEVEL (KERNEL_NIC_PRIO_NUM_LEVELS + 1) |
Maor Gottlieb | 8d40d16 | 2016-01-11 10:26:03 +0200 | [diff] [blame] | 90 | |
Maor Gottlieb | a257b94 | 2016-04-29 01:36:34 +0300 | [diff] [blame] | 91 | #define ANCHOR_NUM_LEVELS 1 |
Maor Gottlieb | 153fefb | 2016-03-07 18:51:45 +0200 | [diff] [blame] | 92 | #define ANCHOR_NUM_PRIOS 1 |
| 93 | #define ANCHOR_MIN_LEVEL (BY_PASS_MIN_LEVEL + 1) |
Or Gerlitz | acbc200 | 2016-07-01 14:50:58 +0300 | [diff] [blame] | 94 | |
| 95 | #define OFFLOADS_MAX_FT 1 |
| 96 | #define OFFLOADS_NUM_PRIOS 1 |
| 97 | #define OFFLOADS_MIN_LEVEL (ANCHOR_MIN_LEVEL + 1) |
| 98 | |
Maor Gottlieb | 8d40d16 | 2016-01-11 10:26:03 +0200 | [diff] [blame] | 99 | struct node_caps { |
| 100 | size_t arr_sz; |
| 101 | long *caps; |
| 102 | }; |
Maor Gottlieb | 2530236 | 2015-12-10 17:12:43 +0200 | [diff] [blame] | 103 | static struct init_tree_node { |
| 104 | enum fs_node_type type; |
| 105 | struct init_tree_node *children; |
| 106 | int ar_size; |
Maor Gottlieb | 8d40d16 | 2016-01-11 10:26:03 +0200 | [diff] [blame] | 107 | struct node_caps caps; |
Maor Gottlieb | 2530236 | 2015-12-10 17:12:43 +0200 | [diff] [blame] | 108 | int min_ft_level; |
Maor Gottlieb | 4cbdd30 | 2016-01-11 10:26:04 +0200 | [diff] [blame] | 109 | int num_leaf_prios; |
Maor Gottlieb | 2530236 | 2015-12-10 17:12:43 +0200 | [diff] [blame] | 110 | int prio; |
Maor Gottlieb | a257b94 | 2016-04-29 01:36:34 +0300 | [diff] [blame] | 111 | int num_levels; |
Maor Gottlieb | 2530236 | 2015-12-10 17:12:43 +0200 | [diff] [blame] | 112 | } root_fs = { |
| 113 | .type = FS_TYPE_NAMESPACE, |
Maor Gottlieb | 6dc6071 | 2016-07-04 17:23:08 +0300 | [diff] [blame] | 114 | .ar_size = 6, |
Maor Gottlieb | 2530236 | 2015-12-10 17:12:43 +0200 | [diff] [blame] | 115 | .children = (struct init_tree_node[]) { |
Maor Gottlieb | 4cbdd30 | 2016-01-11 10:26:04 +0200 | [diff] [blame] | 116 | ADD_PRIO(0, BY_PASS_MIN_LEVEL, 0, |
Maor Gottlieb | 6dc6071 | 2016-07-04 17:23:08 +0300 | [diff] [blame] | 117 | FS_CHAINING_CAPS, |
Maor Gottlieb | a257b94 | 2016-04-29 01:36:34 +0300 | [diff] [blame] | 118 | ADD_NS(ADD_MULTIPLE_PRIO(MLX5_BY_PASS_NUM_PRIOS, |
| 119 | BY_PASS_PRIO_NUM_LEVELS))), |
Or Gerlitz | acbc200 | 2016-07-01 14:50:58 +0300 | [diff] [blame] | 120 | ADD_PRIO(0, OFFLOADS_MIN_LEVEL, 0, {}, |
| 121 | ADD_NS(ADD_MULTIPLE_PRIO(OFFLOADS_NUM_PRIOS, OFFLOADS_MAX_FT))), |
Maor Gottlieb | 6dc6071 | 2016-07-04 17:23:08 +0300 | [diff] [blame] | 122 | ADD_PRIO(0, ETHTOOL_MIN_LEVEL, 0, |
| 123 | FS_CHAINING_CAPS, |
| 124 | ADD_NS(ADD_MULTIPLE_PRIO(ETHTOOL_NUM_PRIOS, |
| 125 | ETHTOOL_PRIO_NUM_LEVELS))), |
Maor Gottlieb | a257b94 | 2016-04-29 01:36:34 +0300 | [diff] [blame] | 126 | ADD_PRIO(0, KERNEL_MIN_LEVEL, 0, {}, |
Maor Gottlieb | 13de6c1 | 2016-04-29 01:36:36 +0300 | [diff] [blame] | 127 | ADD_NS(ADD_MULTIPLE_PRIO(1, 1), |
| 128 | ADD_MULTIPLE_PRIO(KERNEL_NIC_NUM_PRIOS, |
| 129 | KERNEL_NIC_PRIO_NUM_LEVELS))), |
Maor Gottlieb | 4cbdd30 | 2016-01-11 10:26:04 +0200 | [diff] [blame] | 130 | ADD_PRIO(0, BY_PASS_MIN_LEVEL, 0, |
Maor Gottlieb | 6dc6071 | 2016-07-04 17:23:08 +0300 | [diff] [blame] | 131 | FS_CHAINING_CAPS, |
Maor Gottlieb | a257b94 | 2016-04-29 01:36:34 +0300 | [diff] [blame] | 132 | ADD_NS(ADD_MULTIPLE_PRIO(LEFTOVERS_NUM_PRIOS, LEFTOVERS_NUM_LEVELS))), |
Maor Gottlieb | 153fefb | 2016-03-07 18:51:45 +0200 | [diff] [blame] | 133 | ADD_PRIO(0, ANCHOR_MIN_LEVEL, 0, {}, |
Maor Gottlieb | a257b94 | 2016-04-29 01:36:34 +0300 | [diff] [blame] | 134 | ADD_NS(ADD_MULTIPLE_PRIO(ANCHOR_NUM_PRIOS, ANCHOR_NUM_LEVELS))), |
Maor Gottlieb | 2530236 | 2015-12-10 17:12:43 +0200 | [diff] [blame] | 135 | } |
| 136 | }; |
| 137 | |
Maor Gottlieb | f0d22d1 | 2016-01-11 10:25:57 +0200 | [diff] [blame] | 138 | enum fs_i_mutex_lock_class { |
| 139 | FS_MUTEX_GRANDPARENT, |
| 140 | FS_MUTEX_PARENT, |
| 141 | FS_MUTEX_CHILD |
| 142 | }; |
| 143 | |
Maor Gottlieb | 0c56b97 | 2015-12-10 17:12:42 +0200 | [diff] [blame] | 144 | static void del_rule(struct fs_node *node); |
| 145 | static void del_flow_table(struct fs_node *node); |
| 146 | static void del_flow_group(struct fs_node *node); |
| 147 | static void del_fte(struct fs_node *node); |
Maor Gottlieb | de8575e | 2015-12-10 17:12:40 +0200 | [diff] [blame] | 148 | |
| 149 | static void tree_init_node(struct fs_node *node, |
| 150 | unsigned int refcount, |
| 151 | void (*remove_func)(struct fs_node *)) |
| 152 | { |
| 153 | atomic_set(&node->refcount, refcount); |
| 154 | INIT_LIST_HEAD(&node->list); |
| 155 | INIT_LIST_HEAD(&node->children); |
| 156 | mutex_init(&node->lock); |
| 157 | node->remove_func = remove_func; |
| 158 | } |
| 159 | |
| 160 | static void tree_add_node(struct fs_node *node, struct fs_node *parent) |
| 161 | { |
| 162 | if (parent) |
| 163 | atomic_inc(&parent->refcount); |
| 164 | node->parent = parent; |
| 165 | |
| 166 | /* Parent is the root */ |
| 167 | if (!parent) |
| 168 | node->root = node; |
| 169 | else |
| 170 | node->root = parent->root; |
| 171 | } |
| 172 | |
| 173 | static void tree_get_node(struct fs_node *node) |
| 174 | { |
| 175 | atomic_inc(&node->refcount); |
| 176 | } |
| 177 | |
Maor Gottlieb | f0d22d1 | 2016-01-11 10:25:57 +0200 | [diff] [blame] | 178 | static void nested_lock_ref_node(struct fs_node *node, |
| 179 | enum fs_i_mutex_lock_class class) |
Maor Gottlieb | de8575e | 2015-12-10 17:12:40 +0200 | [diff] [blame] | 180 | { |
| 181 | if (node) { |
Maor Gottlieb | f0d22d1 | 2016-01-11 10:25:57 +0200 | [diff] [blame] | 182 | mutex_lock_nested(&node->lock, class); |
Maor Gottlieb | de8575e | 2015-12-10 17:12:40 +0200 | [diff] [blame] | 183 | atomic_inc(&node->refcount); |
| 184 | } |
| 185 | } |
| 186 | |
| 187 | static void lock_ref_node(struct fs_node *node) |
| 188 | { |
| 189 | if (node) { |
| 190 | mutex_lock(&node->lock); |
| 191 | atomic_inc(&node->refcount); |
| 192 | } |
| 193 | } |
| 194 | |
| 195 | static void unlock_ref_node(struct fs_node *node) |
| 196 | { |
| 197 | if (node) { |
| 198 | atomic_dec(&node->refcount); |
| 199 | mutex_unlock(&node->lock); |
| 200 | } |
| 201 | } |
| 202 | |
| 203 | static void tree_put_node(struct fs_node *node) |
| 204 | { |
| 205 | struct fs_node *parent_node = node->parent; |
| 206 | |
| 207 | lock_ref_node(parent_node); |
| 208 | if (atomic_dec_and_test(&node->refcount)) { |
| 209 | if (parent_node) |
| 210 | list_del_init(&node->list); |
| 211 | if (node->remove_func) |
| 212 | node->remove_func(node); |
| 213 | kfree(node); |
| 214 | node = NULL; |
| 215 | } |
| 216 | unlock_ref_node(parent_node); |
| 217 | if (!node && parent_node) |
| 218 | tree_put_node(parent_node); |
| 219 | } |
| 220 | |
| 221 | static int tree_remove_node(struct fs_node *node) |
| 222 | { |
Maor Gottlieb | b3638e1 | 2016-03-07 18:51:46 +0200 | [diff] [blame] | 223 | if (atomic_read(&node->refcount) > 1) { |
| 224 | atomic_dec(&node->refcount); |
| 225 | return -EEXIST; |
| 226 | } |
Maor Gottlieb | de8575e | 2015-12-10 17:12:40 +0200 | [diff] [blame] | 227 | tree_put_node(node); |
| 228 | return 0; |
| 229 | } |
Maor Gottlieb | 5e1626c | 2015-12-10 17:12:41 +0200 | [diff] [blame] | 230 | |
| 231 | static struct fs_prio *find_prio(struct mlx5_flow_namespace *ns, |
| 232 | unsigned int prio) |
| 233 | { |
| 234 | struct fs_prio *iter_prio; |
| 235 | |
| 236 | fs_for_each_prio(iter_prio, ns) { |
| 237 | if (iter_prio->prio == prio) |
| 238 | return iter_prio; |
| 239 | } |
| 240 | |
| 241 | return NULL; |
| 242 | } |
| 243 | |
Maor Gottlieb | 5e1626c | 2015-12-10 17:12:41 +0200 | [diff] [blame] | 244 | static bool masked_memcmp(void *mask, void *val1, void *val2, size_t size) |
| 245 | { |
| 246 | unsigned int i; |
| 247 | |
| 248 | for (i = 0; i < size; i++, mask++, val1++, val2++) |
| 249 | if ((*((u8 *)val1) & (*(u8 *)mask)) != |
| 250 | ((*(u8 *)val2) & (*(u8 *)mask))) |
| 251 | return false; |
| 252 | |
| 253 | return true; |
| 254 | } |
| 255 | |
| 256 | static bool compare_match_value(struct mlx5_flow_group_mask *mask, |
| 257 | void *fte_param1, void *fte_param2) |
| 258 | { |
| 259 | if (mask->match_criteria_enable & |
| 260 | 1 << MLX5_CREATE_FLOW_GROUP_IN_MATCH_CRITERIA_ENABLE_OUTER_HEADERS) { |
| 261 | void *fte_match1 = MLX5_ADDR_OF(fte_match_param, |
| 262 | fte_param1, outer_headers); |
| 263 | void *fte_match2 = MLX5_ADDR_OF(fte_match_param, |
| 264 | fte_param2, outer_headers); |
| 265 | void *fte_mask = MLX5_ADDR_OF(fte_match_param, |
| 266 | mask->match_criteria, outer_headers); |
| 267 | |
| 268 | if (!masked_memcmp(fte_mask, fte_match1, fte_match2, |
| 269 | MLX5_ST_SZ_BYTES(fte_match_set_lyr_2_4))) |
| 270 | return false; |
| 271 | } |
| 272 | |
| 273 | if (mask->match_criteria_enable & |
| 274 | 1 << MLX5_CREATE_FLOW_GROUP_IN_MATCH_CRITERIA_ENABLE_MISC_PARAMETERS) { |
| 275 | void *fte_match1 = MLX5_ADDR_OF(fte_match_param, |
| 276 | fte_param1, misc_parameters); |
| 277 | void *fte_match2 = MLX5_ADDR_OF(fte_match_param, |
| 278 | fte_param2, misc_parameters); |
| 279 | void *fte_mask = MLX5_ADDR_OF(fte_match_param, |
| 280 | mask->match_criteria, misc_parameters); |
| 281 | |
| 282 | if (!masked_memcmp(fte_mask, fte_match1, fte_match2, |
| 283 | MLX5_ST_SZ_BYTES(fte_match_set_misc))) |
| 284 | return false; |
| 285 | } |
| 286 | |
| 287 | if (mask->match_criteria_enable & |
| 288 | 1 << MLX5_CREATE_FLOW_GROUP_IN_MATCH_CRITERIA_ENABLE_INNER_HEADERS) { |
| 289 | void *fte_match1 = MLX5_ADDR_OF(fte_match_param, |
| 290 | fte_param1, inner_headers); |
| 291 | void *fte_match2 = MLX5_ADDR_OF(fte_match_param, |
| 292 | fte_param2, inner_headers); |
| 293 | void *fte_mask = MLX5_ADDR_OF(fte_match_param, |
| 294 | mask->match_criteria, inner_headers); |
| 295 | |
| 296 | if (!masked_memcmp(fte_mask, fte_match1, fte_match2, |
| 297 | MLX5_ST_SZ_BYTES(fte_match_set_lyr_2_4))) |
| 298 | return false; |
| 299 | } |
| 300 | return true; |
| 301 | } |
| 302 | |
| 303 | static bool compare_match_criteria(u8 match_criteria_enable1, |
| 304 | u8 match_criteria_enable2, |
| 305 | void *mask1, void *mask2) |
| 306 | { |
| 307 | return match_criteria_enable1 == match_criteria_enable2 && |
| 308 | !memcmp(mask1, mask2, MLX5_ST_SZ_BYTES(fte_match_param)); |
| 309 | } |
Maor Gottlieb | 0c56b97 | 2015-12-10 17:12:42 +0200 | [diff] [blame] | 310 | |
| 311 | static struct mlx5_flow_root_namespace *find_root(struct fs_node *node) |
| 312 | { |
| 313 | struct fs_node *root; |
| 314 | struct mlx5_flow_namespace *ns; |
| 315 | |
| 316 | root = node->root; |
| 317 | |
| 318 | if (WARN_ON(root->type != FS_TYPE_NAMESPACE)) { |
| 319 | pr_warn("mlx5: flow steering node is not in tree or garbaged\n"); |
| 320 | return NULL; |
| 321 | } |
| 322 | |
| 323 | ns = container_of(root, struct mlx5_flow_namespace, node); |
| 324 | return container_of(ns, struct mlx5_flow_root_namespace, ns); |
| 325 | } |
| 326 | |
| 327 | static inline struct mlx5_core_dev *get_dev(struct fs_node *node) |
| 328 | { |
| 329 | struct mlx5_flow_root_namespace *root = find_root(node); |
| 330 | |
| 331 | if (root) |
| 332 | return root->dev; |
| 333 | return NULL; |
| 334 | } |
| 335 | |
| 336 | static void del_flow_table(struct fs_node *node) |
| 337 | { |
| 338 | struct mlx5_flow_table *ft; |
| 339 | struct mlx5_core_dev *dev; |
| 340 | struct fs_prio *prio; |
| 341 | int err; |
| 342 | |
| 343 | fs_get_obj(ft, node); |
| 344 | dev = get_dev(&ft->node); |
| 345 | |
| 346 | err = mlx5_cmd_destroy_flow_table(dev, ft); |
| 347 | if (err) |
| 348 | pr_warn("flow steering can't destroy ft\n"); |
| 349 | fs_get_obj(prio, ft->node.parent); |
| 350 | prio->num_ft--; |
| 351 | } |
| 352 | |
| 353 | static void del_rule(struct fs_node *node) |
| 354 | { |
| 355 | struct mlx5_flow_rule *rule; |
| 356 | struct mlx5_flow_table *ft; |
| 357 | struct mlx5_flow_group *fg; |
| 358 | struct fs_fte *fte; |
| 359 | u32 *match_value; |
Amir Vadai | bd5251db | 2016-05-13 12:55:40 +0000 | [diff] [blame] | 360 | int modify_mask; |
Maor Gottlieb | 0c56b97 | 2015-12-10 17:12:42 +0200 | [diff] [blame] | 361 | struct mlx5_core_dev *dev = get_dev(node); |
| 362 | int match_len = MLX5_ST_SZ_BYTES(fte_match_param); |
| 363 | int err; |
| 364 | |
| 365 | match_value = mlx5_vzalloc(match_len); |
| 366 | if (!match_value) { |
| 367 | pr_warn("failed to allocate inbox\n"); |
| 368 | return; |
| 369 | } |
| 370 | |
| 371 | fs_get_obj(rule, node); |
| 372 | fs_get_obj(fte, rule->node.parent); |
| 373 | fs_get_obj(fg, fte->node.parent); |
| 374 | memcpy(match_value, fte->val, sizeof(fte->val)); |
| 375 | fs_get_obj(ft, fg->node.parent); |
| 376 | list_del(&rule->node.list); |
Maor Gottlieb | b3638e1 | 2016-03-07 18:51:46 +0200 | [diff] [blame] | 377 | if (rule->sw_action == MLX5_FLOW_CONTEXT_ACTION_FWD_NEXT_PRIO) { |
| 378 | mutex_lock(&rule->dest_attr.ft->lock); |
| 379 | list_del(&rule->next_ft); |
| 380 | mutex_unlock(&rule->dest_attr.ft->lock); |
| 381 | } |
Amir Vadai | 60ab458 | 2016-03-08 12:42:33 +0200 | [diff] [blame] | 382 | if ((fte->action & MLX5_FLOW_CONTEXT_ACTION_FWD_DEST) && |
| 383 | --fte->dests_size) { |
Amir Vadai | bd5251db | 2016-05-13 12:55:40 +0000 | [diff] [blame] | 384 | modify_mask = BIT(MLX5_SET_FTE_MODIFY_ENABLE_MASK_DESTINATION_LIST), |
Maor Gottlieb | 0c56b97 | 2015-12-10 17:12:42 +0200 | [diff] [blame] | 385 | err = mlx5_cmd_update_fte(dev, ft, |
Amir Vadai | bd5251db | 2016-05-13 12:55:40 +0000 | [diff] [blame] | 386 | fg->id, |
| 387 | modify_mask, |
| 388 | fte); |
Maor Gottlieb | 0c56b97 | 2015-12-10 17:12:42 +0200 | [diff] [blame] | 389 | if (err) |
| 390 | pr_warn("%s can't del rule fg id=%d fte_index=%d\n", |
| 391 | __func__, fg->id, fte->index); |
| 392 | } |
| 393 | kvfree(match_value); |
| 394 | } |
| 395 | |
| 396 | static void del_fte(struct fs_node *node) |
| 397 | { |
| 398 | struct mlx5_flow_table *ft; |
| 399 | struct mlx5_flow_group *fg; |
| 400 | struct mlx5_core_dev *dev; |
| 401 | struct fs_fte *fte; |
| 402 | int err; |
| 403 | |
| 404 | fs_get_obj(fte, node); |
| 405 | fs_get_obj(fg, fte->node.parent); |
| 406 | fs_get_obj(ft, fg->node.parent); |
| 407 | |
| 408 | dev = get_dev(&ft->node); |
| 409 | err = mlx5_cmd_delete_fte(dev, ft, |
| 410 | fte->index); |
| 411 | if (err) |
| 412 | pr_warn("flow steering can't delete fte in index %d of flow group id %d\n", |
| 413 | fte->index, fg->id); |
| 414 | |
| 415 | fte->status = 0; |
| 416 | fg->num_ftes--; |
| 417 | } |
| 418 | |
| 419 | static void del_flow_group(struct fs_node *node) |
| 420 | { |
| 421 | struct mlx5_flow_group *fg; |
| 422 | struct mlx5_flow_table *ft; |
| 423 | struct mlx5_core_dev *dev; |
| 424 | |
| 425 | fs_get_obj(fg, node); |
| 426 | fs_get_obj(ft, fg->node.parent); |
| 427 | dev = get_dev(&ft->node); |
| 428 | |
| 429 | if (mlx5_cmd_destroy_flow_group(dev, ft, fg->id)) |
| 430 | pr_warn("flow steering can't destroy fg %d of ft %d\n", |
| 431 | fg->id, ft->id); |
| 432 | } |
| 433 | |
| 434 | static struct fs_fte *alloc_fte(u8 action, |
| 435 | u32 flow_tag, |
| 436 | u32 *match_value, |
| 437 | unsigned int index) |
| 438 | { |
| 439 | struct fs_fte *fte; |
| 440 | |
| 441 | fte = kzalloc(sizeof(*fte), GFP_KERNEL); |
| 442 | if (!fte) |
| 443 | return ERR_PTR(-ENOMEM); |
| 444 | |
| 445 | memcpy(fte->val, match_value, sizeof(fte->val)); |
| 446 | fte->node.type = FS_TYPE_FLOW_ENTRY; |
| 447 | fte->flow_tag = flow_tag; |
| 448 | fte->index = index; |
| 449 | fte->action = action; |
| 450 | |
| 451 | return fte; |
| 452 | } |
| 453 | |
| 454 | static struct mlx5_flow_group *alloc_flow_group(u32 *create_fg_in) |
| 455 | { |
| 456 | struct mlx5_flow_group *fg; |
| 457 | void *match_criteria = MLX5_ADDR_OF(create_flow_group_in, |
| 458 | create_fg_in, match_criteria); |
| 459 | u8 match_criteria_enable = MLX5_GET(create_flow_group_in, |
| 460 | create_fg_in, |
| 461 | match_criteria_enable); |
| 462 | fg = kzalloc(sizeof(*fg), GFP_KERNEL); |
| 463 | if (!fg) |
| 464 | return ERR_PTR(-ENOMEM); |
| 465 | |
| 466 | fg->mask.match_criteria_enable = match_criteria_enable; |
| 467 | memcpy(&fg->mask.match_criteria, match_criteria, |
| 468 | sizeof(fg->mask.match_criteria)); |
| 469 | fg->node.type = FS_TYPE_FLOW_GROUP; |
| 470 | fg->start_index = MLX5_GET(create_flow_group_in, create_fg_in, |
| 471 | start_flow_index); |
| 472 | fg->max_ftes = MLX5_GET(create_flow_group_in, create_fg_in, |
| 473 | end_flow_index) - fg->start_index + 1; |
| 474 | return fg; |
| 475 | } |
| 476 | |
Mohamad Haj Yahia | efdc810 | 2016-05-03 17:13:54 +0300 | [diff] [blame] | 477 | static struct mlx5_flow_table *alloc_flow_table(int level, u16 vport, int max_fte, |
Maor Gottlieb | 0c56b97 | 2015-12-10 17:12:42 +0200 | [diff] [blame] | 478 | enum fs_flow_table_type table_type) |
| 479 | { |
| 480 | struct mlx5_flow_table *ft; |
| 481 | |
| 482 | ft = kzalloc(sizeof(*ft), GFP_KERNEL); |
| 483 | if (!ft) |
| 484 | return NULL; |
| 485 | |
| 486 | ft->level = level; |
| 487 | ft->node.type = FS_TYPE_FLOW_TABLE; |
| 488 | ft->type = table_type; |
Mohamad Haj Yahia | efdc810 | 2016-05-03 17:13:54 +0300 | [diff] [blame] | 489 | ft->vport = vport; |
Maor Gottlieb | 0c56b97 | 2015-12-10 17:12:42 +0200 | [diff] [blame] | 490 | ft->max_fte = max_fte; |
Maor Gottlieb | b3638e1 | 2016-03-07 18:51:46 +0200 | [diff] [blame] | 491 | INIT_LIST_HEAD(&ft->fwd_rules); |
| 492 | mutex_init(&ft->lock); |
Maor Gottlieb | 0c56b97 | 2015-12-10 17:12:42 +0200 | [diff] [blame] | 493 | |
| 494 | return ft; |
| 495 | } |
| 496 | |
Maor Gottlieb | fdb6896 | 2016-01-11 10:25:58 +0200 | [diff] [blame] | 497 | /* If reverse is false, then we search for the first flow table in the |
| 498 | * root sub-tree from start(closest from right), else we search for the |
| 499 | * last flow table in the root sub-tree till start(closest from left). |
| 500 | */ |
| 501 | static struct mlx5_flow_table *find_closest_ft_recursive(struct fs_node *root, |
| 502 | struct list_head *start, |
| 503 | bool reverse) |
| 504 | { |
| 505 | #define list_advance_entry(pos, reverse) \ |
| 506 | ((reverse) ? list_prev_entry(pos, list) : list_next_entry(pos, list)) |
| 507 | |
| 508 | #define list_for_each_advance_continue(pos, head, reverse) \ |
| 509 | for (pos = list_advance_entry(pos, reverse); \ |
| 510 | &pos->list != (head); \ |
| 511 | pos = list_advance_entry(pos, reverse)) |
| 512 | |
| 513 | struct fs_node *iter = list_entry(start, struct fs_node, list); |
| 514 | struct mlx5_flow_table *ft = NULL; |
| 515 | |
| 516 | if (!root) |
| 517 | return NULL; |
| 518 | |
| 519 | list_for_each_advance_continue(iter, &root->children, reverse) { |
| 520 | if (iter->type == FS_TYPE_FLOW_TABLE) { |
| 521 | fs_get_obj(ft, iter); |
| 522 | return ft; |
| 523 | } |
| 524 | ft = find_closest_ft_recursive(iter, &iter->children, reverse); |
| 525 | if (ft) |
| 526 | return ft; |
| 527 | } |
| 528 | |
| 529 | return ft; |
| 530 | } |
| 531 | |
| 532 | /* If reverse if false then return the first flow table in next priority of |
| 533 | * prio in the tree, else return the last flow table in the previous priority |
| 534 | * of prio in the tree. |
| 535 | */ |
| 536 | static struct mlx5_flow_table *find_closest_ft(struct fs_prio *prio, bool reverse) |
| 537 | { |
| 538 | struct mlx5_flow_table *ft = NULL; |
| 539 | struct fs_node *curr_node; |
| 540 | struct fs_node *parent; |
| 541 | |
| 542 | parent = prio->node.parent; |
| 543 | curr_node = &prio->node; |
| 544 | while (!ft && parent) { |
| 545 | ft = find_closest_ft_recursive(parent, &curr_node->list, reverse); |
| 546 | curr_node = parent; |
| 547 | parent = curr_node->parent; |
| 548 | } |
| 549 | return ft; |
| 550 | } |
| 551 | |
| 552 | /* Assuming all the tree is locked by mutex chain lock */ |
| 553 | static struct mlx5_flow_table *find_next_chained_ft(struct fs_prio *prio) |
| 554 | { |
| 555 | return find_closest_ft(prio, false); |
| 556 | } |
| 557 | |
| 558 | /* Assuming all the tree is locked by mutex chain lock */ |
| 559 | static struct mlx5_flow_table *find_prev_chained_ft(struct fs_prio *prio) |
| 560 | { |
| 561 | return find_closest_ft(prio, true); |
| 562 | } |
| 563 | |
Maor Gottlieb | f90edfd | 2016-01-11 10:26:01 +0200 | [diff] [blame] | 564 | static int connect_fts_in_prio(struct mlx5_core_dev *dev, |
| 565 | struct fs_prio *prio, |
| 566 | struct mlx5_flow_table *ft) |
| 567 | { |
| 568 | struct mlx5_flow_table *iter; |
| 569 | int i = 0; |
| 570 | int err; |
| 571 | |
| 572 | fs_for_each_ft(iter, prio) { |
| 573 | i++; |
| 574 | err = mlx5_cmd_modify_flow_table(dev, |
| 575 | iter, |
| 576 | ft); |
| 577 | if (err) { |
| 578 | mlx5_core_warn(dev, "Failed to modify flow table %d\n", |
| 579 | iter->id); |
| 580 | /* The driver is out of sync with the FW */ |
| 581 | if (i > 1) |
| 582 | WARN_ON(true); |
| 583 | return err; |
| 584 | } |
| 585 | } |
| 586 | return 0; |
| 587 | } |
| 588 | |
| 589 | /* Connect flow tables from previous priority of prio to ft */ |
| 590 | static int connect_prev_fts(struct mlx5_core_dev *dev, |
| 591 | struct mlx5_flow_table *ft, |
| 592 | struct fs_prio *prio) |
| 593 | { |
| 594 | struct mlx5_flow_table *prev_ft; |
| 595 | |
| 596 | prev_ft = find_prev_chained_ft(prio); |
| 597 | if (prev_ft) { |
| 598 | struct fs_prio *prev_prio; |
| 599 | |
| 600 | fs_get_obj(prev_prio, prev_ft->node.parent); |
| 601 | return connect_fts_in_prio(dev, prev_prio, ft); |
| 602 | } |
| 603 | return 0; |
| 604 | } |
| 605 | |
Maor Gottlieb | 2cc43b4 | 2016-01-11 10:25:59 +0200 | [diff] [blame] | 606 | static int update_root_ft_create(struct mlx5_flow_table *ft, struct fs_prio |
| 607 | *prio) |
| 608 | { |
| 609 | struct mlx5_flow_root_namespace *root = find_root(&prio->node); |
| 610 | int min_level = INT_MAX; |
| 611 | int err; |
| 612 | |
| 613 | if (root->root_ft) |
| 614 | min_level = root->root_ft->level; |
| 615 | |
| 616 | if (ft->level >= min_level) |
| 617 | return 0; |
| 618 | |
| 619 | err = mlx5_cmd_update_root_ft(root->dev, ft); |
| 620 | if (err) |
| 621 | mlx5_core_warn(root->dev, "Update root flow table of id=%u failed\n", |
| 622 | ft->id); |
| 623 | else |
| 624 | root->root_ft = ft; |
| 625 | |
| 626 | return err; |
| 627 | } |
| 628 | |
Maor Gottlieb | d745098 | 2016-04-29 01:36:33 +0300 | [diff] [blame] | 629 | int mlx5_modify_rule_destination(struct mlx5_flow_rule *rule, |
| 630 | struct mlx5_flow_destination *dest) |
Maor Gottlieb | b3638e1 | 2016-03-07 18:51:46 +0200 | [diff] [blame] | 631 | { |
| 632 | struct mlx5_flow_table *ft; |
| 633 | struct mlx5_flow_group *fg; |
| 634 | struct fs_fte *fte; |
Amir Vadai | bd5251db | 2016-05-13 12:55:40 +0000 | [diff] [blame] | 635 | int modify_mask = BIT(MLX5_SET_FTE_MODIFY_ENABLE_MASK_DESTINATION_LIST); |
Maor Gottlieb | b3638e1 | 2016-03-07 18:51:46 +0200 | [diff] [blame] | 636 | int err = 0; |
| 637 | |
| 638 | fs_get_obj(fte, rule->node.parent); |
| 639 | if (!(fte->action & MLX5_FLOW_CONTEXT_ACTION_FWD_DEST)) |
| 640 | return -EINVAL; |
| 641 | lock_ref_node(&fte->node); |
| 642 | fs_get_obj(fg, fte->node.parent); |
| 643 | fs_get_obj(ft, fg->node.parent); |
| 644 | |
| 645 | memcpy(&rule->dest_attr, dest, sizeof(*dest)); |
| 646 | err = mlx5_cmd_update_fte(get_dev(&ft->node), |
Amir Vadai | bd5251db | 2016-05-13 12:55:40 +0000 | [diff] [blame] | 647 | ft, fg->id, |
| 648 | modify_mask, |
| 649 | fte); |
Maor Gottlieb | b3638e1 | 2016-03-07 18:51:46 +0200 | [diff] [blame] | 650 | unlock_ref_node(&fte->node); |
| 651 | |
| 652 | return err; |
| 653 | } |
| 654 | |
| 655 | /* Modify/set FWD rules that point on old_next_ft to point on new_next_ft */ |
| 656 | static int connect_fwd_rules(struct mlx5_core_dev *dev, |
| 657 | struct mlx5_flow_table *new_next_ft, |
| 658 | struct mlx5_flow_table *old_next_ft) |
| 659 | { |
| 660 | struct mlx5_flow_destination dest; |
| 661 | struct mlx5_flow_rule *iter; |
| 662 | int err = 0; |
| 663 | |
| 664 | /* new_next_ft and old_next_ft could be NULL only |
| 665 | * when we create/destroy the anchor flow table. |
| 666 | */ |
| 667 | if (!new_next_ft || !old_next_ft) |
| 668 | return 0; |
| 669 | |
| 670 | dest.type = MLX5_FLOW_DESTINATION_TYPE_FLOW_TABLE; |
| 671 | dest.ft = new_next_ft; |
| 672 | |
| 673 | mutex_lock(&old_next_ft->lock); |
| 674 | list_splice_init(&old_next_ft->fwd_rules, &new_next_ft->fwd_rules); |
| 675 | mutex_unlock(&old_next_ft->lock); |
| 676 | list_for_each_entry(iter, &new_next_ft->fwd_rules, next_ft) { |
| 677 | err = mlx5_modify_rule_destination(iter, &dest); |
| 678 | if (err) |
| 679 | pr_err("mlx5_core: failed to modify rule to point on flow table %d\n", |
| 680 | new_next_ft->id); |
| 681 | } |
| 682 | return 0; |
| 683 | } |
| 684 | |
Maor Gottlieb | f90edfd | 2016-01-11 10:26:01 +0200 | [diff] [blame] | 685 | static int connect_flow_table(struct mlx5_core_dev *dev, struct mlx5_flow_table *ft, |
| 686 | struct fs_prio *prio) |
| 687 | { |
Maor Gottlieb | b3638e1 | 2016-03-07 18:51:46 +0200 | [diff] [blame] | 688 | struct mlx5_flow_table *next_ft; |
Maor Gottlieb | f90edfd | 2016-01-11 10:26:01 +0200 | [diff] [blame] | 689 | int err = 0; |
| 690 | |
| 691 | /* Connect_prev_fts and update_root_ft_create are mutually exclusive */ |
| 692 | |
| 693 | if (list_empty(&prio->node.children)) { |
| 694 | err = connect_prev_fts(dev, ft, prio); |
| 695 | if (err) |
| 696 | return err; |
Maor Gottlieb | b3638e1 | 2016-03-07 18:51:46 +0200 | [diff] [blame] | 697 | |
| 698 | next_ft = find_next_chained_ft(prio); |
| 699 | err = connect_fwd_rules(dev, ft, next_ft); |
| 700 | if (err) |
| 701 | return err; |
Maor Gottlieb | f90edfd | 2016-01-11 10:26:01 +0200 | [diff] [blame] | 702 | } |
| 703 | |
| 704 | if (MLX5_CAP_FLOWTABLE(dev, |
| 705 | flow_table_properties_nic_receive.modify_root)) |
| 706 | err = update_root_ft_create(ft, prio); |
| 707 | return err; |
| 708 | } |
| 709 | |
Maor Gottlieb | d63cd28 | 2016-04-29 01:36:35 +0300 | [diff] [blame] | 710 | static void list_add_flow_table(struct mlx5_flow_table *ft, |
| 711 | struct fs_prio *prio) |
| 712 | { |
| 713 | struct list_head *prev = &prio->node.children; |
| 714 | struct mlx5_flow_table *iter; |
| 715 | |
| 716 | fs_for_each_ft(iter, prio) { |
| 717 | if (iter->level > ft->level) |
| 718 | break; |
| 719 | prev = &iter->node.list; |
| 720 | } |
| 721 | list_add(&ft->node.list, prev); |
| 722 | } |
| 723 | |
Mohamad Haj Yahia | efdc810 | 2016-05-03 17:13:54 +0300 | [diff] [blame] | 724 | static struct mlx5_flow_table *__mlx5_create_flow_table(struct mlx5_flow_namespace *ns, |
| 725 | u16 vport, int prio, |
| 726 | int max_fte, u32 level) |
Maor Gottlieb | 0c56b97 | 2015-12-10 17:12:42 +0200 | [diff] [blame] | 727 | { |
Maor Gottlieb | f90edfd | 2016-01-11 10:26:01 +0200 | [diff] [blame] | 728 | struct mlx5_flow_table *next_ft = NULL; |
Maor Gottlieb | 0c56b97 | 2015-12-10 17:12:42 +0200 | [diff] [blame] | 729 | struct mlx5_flow_table *ft; |
| 730 | int err; |
| 731 | int log_table_sz; |
| 732 | struct mlx5_flow_root_namespace *root = |
| 733 | find_root(&ns->node); |
| 734 | struct fs_prio *fs_prio = NULL; |
| 735 | |
| 736 | if (!root) { |
| 737 | pr_err("mlx5: flow steering failed to find root of namespace\n"); |
| 738 | return ERR_PTR(-ENODEV); |
| 739 | } |
| 740 | |
Maor Gottlieb | 2cc43b4 | 2016-01-11 10:25:59 +0200 | [diff] [blame] | 741 | mutex_lock(&root->chain_lock); |
Maor Gottlieb | 0c56b97 | 2015-12-10 17:12:42 +0200 | [diff] [blame] | 742 | fs_prio = find_prio(ns, prio); |
Maor Gottlieb | 2cc43b4 | 2016-01-11 10:25:59 +0200 | [diff] [blame] | 743 | if (!fs_prio) { |
| 744 | err = -EINVAL; |
| 745 | goto unlock_root; |
| 746 | } |
Maor Gottlieb | d63cd28 | 2016-04-29 01:36:35 +0300 | [diff] [blame] | 747 | if (level >= fs_prio->num_levels) { |
Maor Gottlieb | 0c56b97 | 2015-12-10 17:12:42 +0200 | [diff] [blame] | 748 | err = -ENOSPC; |
Maor Gottlieb | 2cc43b4 | 2016-01-11 10:25:59 +0200 | [diff] [blame] | 749 | goto unlock_root; |
Maor Gottlieb | 0c56b97 | 2015-12-10 17:12:42 +0200 | [diff] [blame] | 750 | } |
Maor Gottlieb | d63cd28 | 2016-04-29 01:36:35 +0300 | [diff] [blame] | 751 | /* The level is related to the |
| 752 | * priority level range. |
| 753 | */ |
| 754 | level += fs_prio->start_level; |
| 755 | ft = alloc_flow_table(level, |
Mohamad Haj Yahia | efdc810 | 2016-05-03 17:13:54 +0300 | [diff] [blame] | 756 | vport, |
Maor Gottlieb | 0c56b97 | 2015-12-10 17:12:42 +0200 | [diff] [blame] | 757 | roundup_pow_of_two(max_fte), |
| 758 | root->table_type); |
| 759 | if (!ft) { |
| 760 | err = -ENOMEM; |
Maor Gottlieb | 2cc43b4 | 2016-01-11 10:25:59 +0200 | [diff] [blame] | 761 | goto unlock_root; |
Maor Gottlieb | 0c56b97 | 2015-12-10 17:12:42 +0200 | [diff] [blame] | 762 | } |
| 763 | |
| 764 | tree_init_node(&ft->node, 1, del_flow_table); |
| 765 | log_table_sz = ilog2(ft->max_fte); |
Maor Gottlieb | f90edfd | 2016-01-11 10:26:01 +0200 | [diff] [blame] | 766 | next_ft = find_next_chained_ft(fs_prio); |
Mohamad Haj Yahia | efdc810 | 2016-05-03 17:13:54 +0300 | [diff] [blame] | 767 | err = mlx5_cmd_create_flow_table(root->dev, ft->vport, ft->type, ft->level, |
Maor Gottlieb | f90edfd | 2016-01-11 10:26:01 +0200 | [diff] [blame] | 768 | log_table_sz, next_ft, &ft->id); |
Maor Gottlieb | 0c56b97 | 2015-12-10 17:12:42 +0200 | [diff] [blame] | 769 | if (err) |
| 770 | goto free_ft; |
| 771 | |
Maor Gottlieb | f90edfd | 2016-01-11 10:26:01 +0200 | [diff] [blame] | 772 | err = connect_flow_table(root->dev, ft, fs_prio); |
| 773 | if (err) |
| 774 | goto destroy_ft; |
Maor Gottlieb | 2cc43b4 | 2016-01-11 10:25:59 +0200 | [diff] [blame] | 775 | lock_ref_node(&fs_prio->node); |
Maor Gottlieb | 0c56b97 | 2015-12-10 17:12:42 +0200 | [diff] [blame] | 776 | tree_add_node(&ft->node, &fs_prio->node); |
Maor Gottlieb | d63cd28 | 2016-04-29 01:36:35 +0300 | [diff] [blame] | 777 | list_add_flow_table(ft, fs_prio); |
Maor Gottlieb | 0c56b97 | 2015-12-10 17:12:42 +0200 | [diff] [blame] | 778 | fs_prio->num_ft++; |
| 779 | unlock_ref_node(&fs_prio->node); |
Maor Gottlieb | 2cc43b4 | 2016-01-11 10:25:59 +0200 | [diff] [blame] | 780 | mutex_unlock(&root->chain_lock); |
Maor Gottlieb | 0c56b97 | 2015-12-10 17:12:42 +0200 | [diff] [blame] | 781 | return ft; |
Maor Gottlieb | 2cc43b4 | 2016-01-11 10:25:59 +0200 | [diff] [blame] | 782 | destroy_ft: |
| 783 | mlx5_cmd_destroy_flow_table(root->dev, ft); |
Maor Gottlieb | 0c56b97 | 2015-12-10 17:12:42 +0200 | [diff] [blame] | 784 | free_ft: |
| 785 | kfree(ft); |
Maor Gottlieb | 2cc43b4 | 2016-01-11 10:25:59 +0200 | [diff] [blame] | 786 | unlock_root: |
| 787 | mutex_unlock(&root->chain_lock); |
Maor Gottlieb | 0c56b97 | 2015-12-10 17:12:42 +0200 | [diff] [blame] | 788 | return ERR_PTR(err); |
| 789 | } |
| 790 | |
Mohamad Haj Yahia | efdc810 | 2016-05-03 17:13:54 +0300 | [diff] [blame] | 791 | struct mlx5_flow_table *mlx5_create_flow_table(struct mlx5_flow_namespace *ns, |
| 792 | int prio, int max_fte, |
| 793 | u32 level) |
| 794 | { |
| 795 | return __mlx5_create_flow_table(ns, 0, prio, max_fte, level); |
| 796 | } |
| 797 | |
| 798 | struct mlx5_flow_table *mlx5_create_vport_flow_table(struct mlx5_flow_namespace *ns, |
| 799 | int prio, int max_fte, |
| 800 | u32 level, u16 vport) |
| 801 | { |
| 802 | return __mlx5_create_flow_table(ns, vport, prio, max_fte, level); |
| 803 | } |
| 804 | |
Maor Gottlieb | f0d22d1 | 2016-01-11 10:25:57 +0200 | [diff] [blame] | 805 | struct mlx5_flow_table *mlx5_create_auto_grouped_flow_table(struct mlx5_flow_namespace *ns, |
| 806 | int prio, |
| 807 | int num_flow_table_entries, |
Maor Gottlieb | d63cd28 | 2016-04-29 01:36:35 +0300 | [diff] [blame] | 808 | int max_num_groups, |
| 809 | u32 level) |
Maor Gottlieb | f0d22d1 | 2016-01-11 10:25:57 +0200 | [diff] [blame] | 810 | { |
| 811 | struct mlx5_flow_table *ft; |
| 812 | |
| 813 | if (max_num_groups > num_flow_table_entries) |
| 814 | return ERR_PTR(-EINVAL); |
| 815 | |
Maor Gottlieb | d63cd28 | 2016-04-29 01:36:35 +0300 | [diff] [blame] | 816 | ft = mlx5_create_flow_table(ns, prio, num_flow_table_entries, level); |
Maor Gottlieb | f0d22d1 | 2016-01-11 10:25:57 +0200 | [diff] [blame] | 817 | if (IS_ERR(ft)) |
| 818 | return ft; |
| 819 | |
| 820 | ft->autogroup.active = true; |
| 821 | ft->autogroup.required_groups = max_num_groups; |
| 822 | |
| 823 | return ft; |
| 824 | } |
Maor Gottlieb | b217ea2 | 2016-01-11 10:26:06 +0200 | [diff] [blame] | 825 | EXPORT_SYMBOL(mlx5_create_auto_grouped_flow_table); |
Maor Gottlieb | f0d22d1 | 2016-01-11 10:25:57 +0200 | [diff] [blame] | 826 | |
| 827 | /* Flow table should be locked */ |
| 828 | static struct mlx5_flow_group *create_flow_group_common(struct mlx5_flow_table *ft, |
| 829 | u32 *fg_in, |
| 830 | struct list_head |
| 831 | *prev_fg, |
| 832 | bool is_auto_fg) |
Maor Gottlieb | 0c56b97 | 2015-12-10 17:12:42 +0200 | [diff] [blame] | 833 | { |
| 834 | struct mlx5_flow_group *fg; |
| 835 | struct mlx5_core_dev *dev = get_dev(&ft->node); |
| 836 | int err; |
| 837 | |
| 838 | if (!dev) |
| 839 | return ERR_PTR(-ENODEV); |
| 840 | |
| 841 | fg = alloc_flow_group(fg_in); |
| 842 | if (IS_ERR(fg)) |
| 843 | return fg; |
| 844 | |
Maor Gottlieb | 0c56b97 | 2015-12-10 17:12:42 +0200 | [diff] [blame] | 845 | err = mlx5_cmd_create_flow_group(dev, ft, fg_in, &fg->id); |
| 846 | if (err) { |
| 847 | kfree(fg); |
Maor Gottlieb | 0c56b97 | 2015-12-10 17:12:42 +0200 | [diff] [blame] | 848 | return ERR_PTR(err); |
| 849 | } |
Maor Gottlieb | f0d22d1 | 2016-01-11 10:25:57 +0200 | [diff] [blame] | 850 | |
| 851 | if (ft->autogroup.active) |
| 852 | ft->autogroup.num_groups++; |
Maor Gottlieb | 0c56b97 | 2015-12-10 17:12:42 +0200 | [diff] [blame] | 853 | /* Add node to tree */ |
Maor Gottlieb | f0d22d1 | 2016-01-11 10:25:57 +0200 | [diff] [blame] | 854 | tree_init_node(&fg->node, !is_auto_fg, del_flow_group); |
Maor Gottlieb | 0c56b97 | 2015-12-10 17:12:42 +0200 | [diff] [blame] | 855 | tree_add_node(&fg->node, &ft->node); |
| 856 | /* Add node to group list */ |
| 857 | list_add(&fg->node.list, ft->node.children.prev); |
Maor Gottlieb | f0d22d1 | 2016-01-11 10:25:57 +0200 | [diff] [blame] | 858 | |
| 859 | return fg; |
| 860 | } |
| 861 | |
| 862 | struct mlx5_flow_group *mlx5_create_flow_group(struct mlx5_flow_table *ft, |
| 863 | u32 *fg_in) |
| 864 | { |
| 865 | struct mlx5_flow_group *fg; |
| 866 | |
| 867 | if (ft->autogroup.active) |
| 868 | return ERR_PTR(-EPERM); |
| 869 | |
| 870 | lock_ref_node(&ft->node); |
| 871 | fg = create_flow_group_common(ft, fg_in, &ft->node.children, false); |
Maor Gottlieb | 0c56b97 | 2015-12-10 17:12:42 +0200 | [diff] [blame] | 872 | unlock_ref_node(&ft->node); |
| 873 | |
| 874 | return fg; |
| 875 | } |
| 876 | |
| 877 | static struct mlx5_flow_rule *alloc_rule(struct mlx5_flow_destination *dest) |
| 878 | { |
| 879 | struct mlx5_flow_rule *rule; |
| 880 | |
| 881 | rule = kzalloc(sizeof(*rule), GFP_KERNEL); |
| 882 | if (!rule) |
| 883 | return NULL; |
| 884 | |
Maor Gottlieb | b3638e1 | 2016-03-07 18:51:46 +0200 | [diff] [blame] | 885 | INIT_LIST_HEAD(&rule->next_ft); |
Maor Gottlieb | 0c56b97 | 2015-12-10 17:12:42 +0200 | [diff] [blame] | 886 | rule->node.type = FS_TYPE_FLOW_DEST; |
Amir Vadai | 60ab458 | 2016-03-08 12:42:33 +0200 | [diff] [blame] | 887 | if (dest) |
| 888 | memcpy(&rule->dest_attr, dest, sizeof(*dest)); |
Maor Gottlieb | 0c56b97 | 2015-12-10 17:12:42 +0200 | [diff] [blame] | 889 | |
| 890 | return rule; |
| 891 | } |
| 892 | |
| 893 | /* fte should not be deleted while calling this function */ |
| 894 | static struct mlx5_flow_rule *add_rule_fte(struct fs_fte *fte, |
| 895 | struct mlx5_flow_group *fg, |
| 896 | struct mlx5_flow_destination *dest) |
| 897 | { |
| 898 | struct mlx5_flow_table *ft; |
| 899 | struct mlx5_flow_rule *rule; |
Amir Vadai | bd5251db | 2016-05-13 12:55:40 +0000 | [diff] [blame] | 900 | int modify_mask = 0; |
Maor Gottlieb | 0c56b97 | 2015-12-10 17:12:42 +0200 | [diff] [blame] | 901 | int err; |
| 902 | |
| 903 | rule = alloc_rule(dest); |
| 904 | if (!rule) |
| 905 | return ERR_PTR(-ENOMEM); |
| 906 | |
| 907 | fs_get_obj(ft, fg->node.parent); |
Maor Gottlieb | b3638e1 | 2016-03-07 18:51:46 +0200 | [diff] [blame] | 908 | /* Add dest to dests list- we need flow tables to be in the |
| 909 | * end of the list for forward to next prio rules. |
| 910 | */ |
Maor Gottlieb | 0c56b97 | 2015-12-10 17:12:42 +0200 | [diff] [blame] | 911 | tree_init_node(&rule->node, 1, del_rule); |
Maor Gottlieb | b3638e1 | 2016-03-07 18:51:46 +0200 | [diff] [blame] | 912 | if (dest && dest->type != MLX5_FLOW_DESTINATION_TYPE_FLOW_TABLE) |
| 913 | list_add(&rule->node.list, &fte->node.children); |
| 914 | else |
| 915 | list_add_tail(&rule->node.list, &fte->node.children); |
Amir Vadai | bd5251db | 2016-05-13 12:55:40 +0000 | [diff] [blame] | 916 | if (dest) { |
Amir Vadai | 60ab458 | 2016-03-08 12:42:33 +0200 | [diff] [blame] | 917 | fte->dests_size++; |
Amir Vadai | bd5251db | 2016-05-13 12:55:40 +0000 | [diff] [blame] | 918 | |
| 919 | modify_mask |= dest->type == MLX5_FLOW_DESTINATION_TYPE_COUNTER ? |
| 920 | BIT(MLX5_SET_FTE_MODIFY_ENABLE_MASK_FLOW_COUNTERS) : |
| 921 | BIT(MLX5_SET_FTE_MODIFY_ENABLE_MASK_DESTINATION_LIST); |
| 922 | } |
| 923 | |
Amir Vadai | 60ab458 | 2016-03-08 12:42:33 +0200 | [diff] [blame] | 924 | if (fte->dests_size == 1 || !dest) |
Maor Gottlieb | 0c56b97 | 2015-12-10 17:12:42 +0200 | [diff] [blame] | 925 | err = mlx5_cmd_create_fte(get_dev(&ft->node), |
| 926 | ft, fg->id, fte); |
| 927 | else |
| 928 | err = mlx5_cmd_update_fte(get_dev(&ft->node), |
Amir Vadai | bd5251db | 2016-05-13 12:55:40 +0000 | [diff] [blame] | 929 | ft, fg->id, modify_mask, fte); |
Maor Gottlieb | 0c56b97 | 2015-12-10 17:12:42 +0200 | [diff] [blame] | 930 | if (err) |
| 931 | goto free_rule; |
| 932 | |
| 933 | fte->status |= FS_FTE_STATUS_EXISTING; |
| 934 | |
| 935 | return rule; |
| 936 | |
| 937 | free_rule: |
| 938 | list_del(&rule->node.list); |
| 939 | kfree(rule); |
Amir Vadai | 60ab458 | 2016-03-08 12:42:33 +0200 | [diff] [blame] | 940 | if (dest) |
| 941 | fte->dests_size--; |
Maor Gottlieb | 0c56b97 | 2015-12-10 17:12:42 +0200 | [diff] [blame] | 942 | return ERR_PTR(err); |
| 943 | } |
| 944 | |
| 945 | /* Assumed fg is locked */ |
| 946 | static unsigned int get_free_fte_index(struct mlx5_flow_group *fg, |
| 947 | struct list_head **prev) |
| 948 | { |
| 949 | struct fs_fte *fte; |
| 950 | unsigned int start = fg->start_index; |
| 951 | |
| 952 | if (prev) |
| 953 | *prev = &fg->node.children; |
| 954 | |
| 955 | /* assumed list is sorted by index */ |
| 956 | fs_for_each_fte(fte, fg) { |
| 957 | if (fte->index != start) |
| 958 | return start; |
| 959 | start++; |
| 960 | if (prev) |
| 961 | *prev = &fte->node.list; |
| 962 | } |
| 963 | |
| 964 | return start; |
| 965 | } |
| 966 | |
| 967 | /* prev is output, prev->next = new_fte */ |
| 968 | static struct fs_fte *create_fte(struct mlx5_flow_group *fg, |
| 969 | u32 *match_value, |
| 970 | u8 action, |
| 971 | u32 flow_tag, |
| 972 | struct list_head **prev) |
| 973 | { |
| 974 | struct fs_fte *fte; |
| 975 | int index; |
| 976 | |
| 977 | index = get_free_fte_index(fg, prev); |
| 978 | fte = alloc_fte(action, flow_tag, match_value, index); |
| 979 | if (IS_ERR(fte)) |
| 980 | return fte; |
| 981 | |
| 982 | return fte; |
| 983 | } |
| 984 | |
Maor Gottlieb | f0d22d1 | 2016-01-11 10:25:57 +0200 | [diff] [blame] | 985 | static struct mlx5_flow_group *create_autogroup(struct mlx5_flow_table *ft, |
| 986 | u8 match_criteria_enable, |
| 987 | u32 *match_criteria) |
| 988 | { |
| 989 | int inlen = MLX5_ST_SZ_BYTES(create_flow_group_in); |
| 990 | struct list_head *prev = &ft->node.children; |
| 991 | unsigned int candidate_index = 0; |
| 992 | struct mlx5_flow_group *fg; |
| 993 | void *match_criteria_addr; |
| 994 | unsigned int group_size = 0; |
| 995 | u32 *in; |
| 996 | |
| 997 | if (!ft->autogroup.active) |
| 998 | return ERR_PTR(-ENOENT); |
| 999 | |
| 1000 | in = mlx5_vzalloc(inlen); |
| 1001 | if (!in) |
| 1002 | return ERR_PTR(-ENOMEM); |
| 1003 | |
| 1004 | if (ft->autogroup.num_groups < ft->autogroup.required_groups) |
| 1005 | /* We save place for flow groups in addition to max types */ |
| 1006 | group_size = ft->max_fte / (ft->autogroup.required_groups + 1); |
| 1007 | |
| 1008 | /* ft->max_fte == ft->autogroup.max_types */ |
| 1009 | if (group_size == 0) |
| 1010 | group_size = 1; |
| 1011 | |
| 1012 | /* sorted by start_index */ |
| 1013 | fs_for_each_fg(fg, ft) { |
| 1014 | if (candidate_index + group_size > fg->start_index) |
| 1015 | candidate_index = fg->start_index + fg->max_ftes; |
| 1016 | else |
| 1017 | break; |
| 1018 | prev = &fg->node.list; |
| 1019 | } |
| 1020 | |
| 1021 | if (candidate_index + group_size > ft->max_fte) { |
| 1022 | fg = ERR_PTR(-ENOSPC); |
| 1023 | goto out; |
| 1024 | } |
| 1025 | |
| 1026 | MLX5_SET(create_flow_group_in, in, match_criteria_enable, |
| 1027 | match_criteria_enable); |
| 1028 | MLX5_SET(create_flow_group_in, in, start_flow_index, candidate_index); |
| 1029 | MLX5_SET(create_flow_group_in, in, end_flow_index, candidate_index + |
| 1030 | group_size - 1); |
| 1031 | match_criteria_addr = MLX5_ADDR_OF(create_flow_group_in, |
| 1032 | in, match_criteria); |
| 1033 | memcpy(match_criteria_addr, match_criteria, |
| 1034 | MLX5_ST_SZ_BYTES(fte_match_param)); |
| 1035 | |
| 1036 | fg = create_flow_group_common(ft, in, prev, true); |
| 1037 | out: |
| 1038 | kvfree(in); |
| 1039 | return fg; |
| 1040 | } |
| 1041 | |
Maor Gottlieb | b3638e1 | 2016-03-07 18:51:46 +0200 | [diff] [blame] | 1042 | static struct mlx5_flow_rule *find_flow_rule(struct fs_fte *fte, |
| 1043 | struct mlx5_flow_destination *dest) |
| 1044 | { |
| 1045 | struct mlx5_flow_rule *rule; |
| 1046 | |
| 1047 | list_for_each_entry(rule, &fte->node.children, node.list) { |
| 1048 | if (rule->dest_attr.type == dest->type) { |
| 1049 | if ((dest->type == MLX5_FLOW_DESTINATION_TYPE_VPORT && |
| 1050 | dest->vport_num == rule->dest_attr.vport_num) || |
| 1051 | (dest->type == MLX5_FLOW_DESTINATION_TYPE_FLOW_TABLE && |
| 1052 | dest->ft == rule->dest_attr.ft) || |
| 1053 | (dest->type == MLX5_FLOW_DESTINATION_TYPE_TIR && |
| 1054 | dest->tir_num == rule->dest_attr.tir_num)) |
| 1055 | return rule; |
| 1056 | } |
| 1057 | } |
| 1058 | return NULL; |
| 1059 | } |
| 1060 | |
Maor Gottlieb | 0c56b97 | 2015-12-10 17:12:42 +0200 | [diff] [blame] | 1061 | static struct mlx5_flow_rule *add_rule_fg(struct mlx5_flow_group *fg, |
| 1062 | u32 *match_value, |
| 1063 | u8 action, |
| 1064 | u32 flow_tag, |
| 1065 | struct mlx5_flow_destination *dest) |
| 1066 | { |
| 1067 | struct fs_fte *fte; |
| 1068 | struct mlx5_flow_rule *rule; |
| 1069 | struct mlx5_flow_table *ft; |
| 1070 | struct list_head *prev; |
| 1071 | |
Maor Gottlieb | f0d22d1 | 2016-01-11 10:25:57 +0200 | [diff] [blame] | 1072 | nested_lock_ref_node(&fg->node, FS_MUTEX_PARENT); |
Maor Gottlieb | 0c56b97 | 2015-12-10 17:12:42 +0200 | [diff] [blame] | 1073 | fs_for_each_fte(fte, fg) { |
Maor Gottlieb | f0d22d1 | 2016-01-11 10:25:57 +0200 | [diff] [blame] | 1074 | nested_lock_ref_node(&fte->node, FS_MUTEX_CHILD); |
Maor Gottlieb | 0c56b97 | 2015-12-10 17:12:42 +0200 | [diff] [blame] | 1075 | if (compare_match_value(&fg->mask, match_value, &fte->val) && |
| 1076 | action == fte->action && flow_tag == fte->flow_tag) { |
Maor Gottlieb | b3638e1 | 2016-03-07 18:51:46 +0200 | [diff] [blame] | 1077 | rule = find_flow_rule(fte, dest); |
| 1078 | if (rule) { |
| 1079 | atomic_inc(&rule->node.refcount); |
| 1080 | unlock_ref_node(&fte->node); |
| 1081 | unlock_ref_node(&fg->node); |
| 1082 | return rule; |
| 1083 | } |
Maor Gottlieb | 0c56b97 | 2015-12-10 17:12:42 +0200 | [diff] [blame] | 1084 | rule = add_rule_fte(fte, fg, dest); |
| 1085 | unlock_ref_node(&fte->node); |
| 1086 | if (IS_ERR(rule)) |
| 1087 | goto unlock_fg; |
| 1088 | else |
| 1089 | goto add_rule; |
| 1090 | } |
| 1091 | unlock_ref_node(&fte->node); |
| 1092 | } |
| 1093 | fs_get_obj(ft, fg->node.parent); |
| 1094 | if (fg->num_ftes >= fg->max_ftes) { |
| 1095 | rule = ERR_PTR(-ENOSPC); |
| 1096 | goto unlock_fg; |
| 1097 | } |
| 1098 | |
| 1099 | fte = create_fte(fg, match_value, action, flow_tag, &prev); |
| 1100 | if (IS_ERR(fte)) { |
| 1101 | rule = (void *)fte; |
| 1102 | goto unlock_fg; |
| 1103 | } |
| 1104 | tree_init_node(&fte->node, 0, del_fte); |
| 1105 | rule = add_rule_fte(fte, fg, dest); |
| 1106 | if (IS_ERR(rule)) { |
| 1107 | kfree(fte); |
| 1108 | goto unlock_fg; |
| 1109 | } |
| 1110 | |
| 1111 | fg->num_ftes++; |
| 1112 | |
| 1113 | tree_add_node(&fte->node, &fg->node); |
| 1114 | list_add(&fte->node.list, prev); |
| 1115 | add_rule: |
| 1116 | tree_add_node(&rule->node, &fte->node); |
| 1117 | unlock_fg: |
| 1118 | unlock_ref_node(&fg->node); |
| 1119 | return rule; |
| 1120 | } |
| 1121 | |
Amir Vadai | bd5251db | 2016-05-13 12:55:40 +0000 | [diff] [blame] | 1122 | struct mlx5_fc *mlx5_flow_rule_counter(struct mlx5_flow_rule *rule) |
| 1123 | { |
| 1124 | struct mlx5_flow_rule *dst; |
| 1125 | struct fs_fte *fte; |
| 1126 | |
| 1127 | fs_get_obj(fte, rule->node.parent); |
| 1128 | |
| 1129 | fs_for_each_dst(dst, fte) { |
| 1130 | if (dst->dest_attr.type == MLX5_FLOW_DESTINATION_TYPE_COUNTER) |
| 1131 | return dst->dest_attr.counter; |
| 1132 | } |
| 1133 | |
| 1134 | return NULL; |
| 1135 | } |
| 1136 | |
| 1137 | static bool counter_is_valid(struct mlx5_fc *counter, u32 action) |
| 1138 | { |
| 1139 | if (!(action & MLX5_FLOW_CONTEXT_ACTION_COUNT)) |
| 1140 | return !counter; |
| 1141 | |
| 1142 | if (!counter) |
| 1143 | return false; |
| 1144 | |
| 1145 | /* Hardware support counter for a drop action only */ |
| 1146 | return action == (MLX5_FLOW_CONTEXT_ACTION_DROP | MLX5_FLOW_CONTEXT_ACTION_COUNT); |
| 1147 | } |
| 1148 | |
Maor Gottlieb | d63cd28 | 2016-04-29 01:36:35 +0300 | [diff] [blame] | 1149 | static bool dest_is_valid(struct mlx5_flow_destination *dest, |
| 1150 | u32 action, |
| 1151 | struct mlx5_flow_table *ft) |
| 1152 | { |
Amir Vadai | bd5251db | 2016-05-13 12:55:40 +0000 | [diff] [blame] | 1153 | if (dest && (dest->type == MLX5_FLOW_DESTINATION_TYPE_COUNTER)) |
| 1154 | return counter_is_valid(dest->counter, action); |
| 1155 | |
Maor Gottlieb | d63cd28 | 2016-04-29 01:36:35 +0300 | [diff] [blame] | 1156 | if (!(action & MLX5_FLOW_CONTEXT_ACTION_FWD_DEST)) |
| 1157 | return true; |
| 1158 | |
| 1159 | if (!dest || ((dest->type == |
| 1160 | MLX5_FLOW_DESTINATION_TYPE_FLOW_TABLE) && |
| 1161 | (dest->ft->level <= ft->level))) |
| 1162 | return false; |
| 1163 | return true; |
| 1164 | } |
| 1165 | |
Maor Gottlieb | b3638e1 | 2016-03-07 18:51:46 +0200 | [diff] [blame] | 1166 | static struct mlx5_flow_rule * |
| 1167 | _mlx5_add_flow_rule(struct mlx5_flow_table *ft, |
Maor Gottlieb | c5bb173 | 2016-07-04 17:23:05 +0300 | [diff] [blame] | 1168 | struct mlx5_flow_spec *spec, |
Maor Gottlieb | b3638e1 | 2016-03-07 18:51:46 +0200 | [diff] [blame] | 1169 | u32 action, |
| 1170 | u32 flow_tag, |
| 1171 | struct mlx5_flow_destination *dest) |
Maor Gottlieb | 0c56b97 | 2015-12-10 17:12:42 +0200 | [diff] [blame] | 1172 | { |
| 1173 | struct mlx5_flow_group *g; |
Maor Gottlieb | f0d22d1 | 2016-01-11 10:25:57 +0200 | [diff] [blame] | 1174 | struct mlx5_flow_rule *rule; |
Maor Gottlieb | 0c56b97 | 2015-12-10 17:12:42 +0200 | [diff] [blame] | 1175 | |
Maor Gottlieb | d63cd28 | 2016-04-29 01:36:35 +0300 | [diff] [blame] | 1176 | if (!dest_is_valid(dest, action, ft)) |
Amir Vadai | 60ab458 | 2016-03-08 12:42:33 +0200 | [diff] [blame] | 1177 | return ERR_PTR(-EINVAL); |
| 1178 | |
Maor Gottlieb | f0d22d1 | 2016-01-11 10:25:57 +0200 | [diff] [blame] | 1179 | nested_lock_ref_node(&ft->node, FS_MUTEX_GRANDPARENT); |
Maor Gottlieb | 0c56b97 | 2015-12-10 17:12:42 +0200 | [diff] [blame] | 1180 | fs_for_each_fg(g, ft) |
| 1181 | if (compare_match_criteria(g->mask.match_criteria_enable, |
Maor Gottlieb | c5bb173 | 2016-07-04 17:23:05 +0300 | [diff] [blame] | 1182 | spec->match_criteria_enable, |
Maor Gottlieb | 0c56b97 | 2015-12-10 17:12:42 +0200 | [diff] [blame] | 1183 | g->mask.match_criteria, |
Maor Gottlieb | c5bb173 | 2016-07-04 17:23:05 +0300 | [diff] [blame] | 1184 | spec->match_criteria)) { |
| 1185 | rule = add_rule_fg(g, spec->match_value, |
Maor Gottlieb | 0c56b97 | 2015-12-10 17:12:42 +0200 | [diff] [blame] | 1186 | action, flow_tag, dest); |
Maor Gottlieb | f0d22d1 | 2016-01-11 10:25:57 +0200 | [diff] [blame] | 1187 | if (!IS_ERR(rule) || PTR_ERR(rule) != -ENOSPC) |
| 1188 | goto unlock; |
Maor Gottlieb | 0c56b97 | 2015-12-10 17:12:42 +0200 | [diff] [blame] | 1189 | } |
Maor Gottlieb | f0d22d1 | 2016-01-11 10:25:57 +0200 | [diff] [blame] | 1190 | |
Maor Gottlieb | c5bb173 | 2016-07-04 17:23:05 +0300 | [diff] [blame] | 1191 | g = create_autogroup(ft, spec->match_criteria_enable, |
| 1192 | spec->match_criteria); |
Maor Gottlieb | c3f9bf6 | 2016-04-22 00:33:00 +0300 | [diff] [blame] | 1193 | if (IS_ERR(g)) { |
| 1194 | rule = (void *)g; |
| 1195 | goto unlock; |
| 1196 | } |
| 1197 | |
Maor Gottlieb | c5bb173 | 2016-07-04 17:23:05 +0300 | [diff] [blame] | 1198 | rule = add_rule_fg(g, spec->match_value, |
Maor Gottlieb | c3f9bf6 | 2016-04-22 00:33:00 +0300 | [diff] [blame] | 1199 | action, flow_tag, dest); |
| 1200 | if (IS_ERR(rule)) { |
| 1201 | /* Remove assumes refcount > 0 and autogroup creates a group |
| 1202 | * with a refcount = 0. |
| 1203 | */ |
| 1204 | unlock_ref_node(&ft->node); |
| 1205 | tree_get_node(&g->node); |
| 1206 | tree_remove_node(&g->node); |
| 1207 | return rule; |
| 1208 | } |
Maor Gottlieb | f0d22d1 | 2016-01-11 10:25:57 +0200 | [diff] [blame] | 1209 | unlock: |
Maor Gottlieb | 0c56b97 | 2015-12-10 17:12:42 +0200 | [diff] [blame] | 1210 | unlock_ref_node(&ft->node); |
Maor Gottlieb | 0c56b97 | 2015-12-10 17:12:42 +0200 | [diff] [blame] | 1211 | return rule; |
| 1212 | } |
Maor Gottlieb | b3638e1 | 2016-03-07 18:51:46 +0200 | [diff] [blame] | 1213 | |
| 1214 | static bool fwd_next_prio_supported(struct mlx5_flow_table *ft) |
| 1215 | { |
| 1216 | return ((ft->type == FS_FT_NIC_RX) && |
| 1217 | (MLX5_CAP_FLOWTABLE(get_dev(&ft->node), nic_rx_multi_path_tirs))); |
| 1218 | } |
| 1219 | |
| 1220 | struct mlx5_flow_rule * |
| 1221 | mlx5_add_flow_rule(struct mlx5_flow_table *ft, |
Maor Gottlieb | c5bb173 | 2016-07-04 17:23:05 +0300 | [diff] [blame] | 1222 | struct mlx5_flow_spec *spec, |
Maor Gottlieb | b3638e1 | 2016-03-07 18:51:46 +0200 | [diff] [blame] | 1223 | u32 action, |
| 1224 | u32 flow_tag, |
| 1225 | struct mlx5_flow_destination *dest) |
| 1226 | { |
| 1227 | struct mlx5_flow_root_namespace *root = find_root(&ft->node); |
| 1228 | struct mlx5_flow_destination gen_dest; |
| 1229 | struct mlx5_flow_table *next_ft = NULL; |
| 1230 | struct mlx5_flow_rule *rule = NULL; |
| 1231 | u32 sw_action = action; |
| 1232 | struct fs_prio *prio; |
| 1233 | |
| 1234 | fs_get_obj(prio, ft->node.parent); |
| 1235 | if (action == MLX5_FLOW_CONTEXT_ACTION_FWD_NEXT_PRIO) { |
| 1236 | if (!fwd_next_prio_supported(ft)) |
| 1237 | return ERR_PTR(-EOPNOTSUPP); |
| 1238 | if (dest) |
| 1239 | return ERR_PTR(-EINVAL); |
| 1240 | mutex_lock(&root->chain_lock); |
| 1241 | next_ft = find_next_chained_ft(prio); |
| 1242 | if (next_ft) { |
| 1243 | gen_dest.type = MLX5_FLOW_DESTINATION_TYPE_FLOW_TABLE; |
| 1244 | gen_dest.ft = next_ft; |
| 1245 | dest = &gen_dest; |
| 1246 | action = MLX5_FLOW_CONTEXT_ACTION_FWD_DEST; |
| 1247 | } else { |
| 1248 | mutex_unlock(&root->chain_lock); |
| 1249 | return ERR_PTR(-EOPNOTSUPP); |
| 1250 | } |
| 1251 | } |
| 1252 | |
Maor Gottlieb | c5bb173 | 2016-07-04 17:23:05 +0300 | [diff] [blame] | 1253 | rule = _mlx5_add_flow_rule(ft, spec, action, flow_tag, dest); |
Maor Gottlieb | b3638e1 | 2016-03-07 18:51:46 +0200 | [diff] [blame] | 1254 | |
| 1255 | if (sw_action == MLX5_FLOW_CONTEXT_ACTION_FWD_NEXT_PRIO) { |
| 1256 | if (!IS_ERR_OR_NULL(rule) && |
| 1257 | (list_empty(&rule->next_ft))) { |
| 1258 | mutex_lock(&next_ft->lock); |
| 1259 | list_add(&rule->next_ft, &next_ft->fwd_rules); |
| 1260 | mutex_unlock(&next_ft->lock); |
| 1261 | rule->sw_action = MLX5_FLOW_CONTEXT_ACTION_FWD_NEXT_PRIO; |
| 1262 | } |
| 1263 | mutex_unlock(&root->chain_lock); |
| 1264 | } |
| 1265 | return rule; |
| 1266 | } |
Maor Gottlieb | b217ea2 | 2016-01-11 10:26:06 +0200 | [diff] [blame] | 1267 | EXPORT_SYMBOL(mlx5_add_flow_rule); |
Maor Gottlieb | 0c56b97 | 2015-12-10 17:12:42 +0200 | [diff] [blame] | 1268 | |
Maor Gottlieb | 86d722a | 2015-12-10 17:12:44 +0200 | [diff] [blame] | 1269 | void mlx5_del_flow_rule(struct mlx5_flow_rule *rule) |
Maor Gottlieb | 0c56b97 | 2015-12-10 17:12:42 +0200 | [diff] [blame] | 1270 | { |
| 1271 | tree_remove_node(&rule->node); |
| 1272 | } |
Maor Gottlieb | b217ea2 | 2016-01-11 10:26:06 +0200 | [diff] [blame] | 1273 | EXPORT_SYMBOL(mlx5_del_flow_rule); |
Maor Gottlieb | 0c56b97 | 2015-12-10 17:12:42 +0200 | [diff] [blame] | 1274 | |
Maor Gottlieb | 2cc43b4 | 2016-01-11 10:25:59 +0200 | [diff] [blame] | 1275 | /* Assuming prio->node.children(flow tables) is sorted by level */ |
| 1276 | static struct mlx5_flow_table *find_next_ft(struct mlx5_flow_table *ft) |
| 1277 | { |
| 1278 | struct fs_prio *prio; |
| 1279 | |
| 1280 | fs_get_obj(prio, ft->node.parent); |
| 1281 | |
| 1282 | if (!list_is_last(&ft->node.list, &prio->node.children)) |
| 1283 | return list_next_entry(ft, node.list); |
| 1284 | return find_next_chained_ft(prio); |
| 1285 | } |
| 1286 | |
| 1287 | static int update_root_ft_destroy(struct mlx5_flow_table *ft) |
| 1288 | { |
| 1289 | struct mlx5_flow_root_namespace *root = find_root(&ft->node); |
| 1290 | struct mlx5_flow_table *new_root_ft = NULL; |
| 1291 | |
| 1292 | if (root->root_ft != ft) |
| 1293 | return 0; |
| 1294 | |
| 1295 | new_root_ft = find_next_ft(ft); |
| 1296 | if (new_root_ft) { |
| 1297 | int err = mlx5_cmd_update_root_ft(root->dev, new_root_ft); |
| 1298 | |
| 1299 | if (err) { |
| 1300 | mlx5_core_warn(root->dev, "Update root flow table of id=%u failed\n", |
| 1301 | ft->id); |
| 1302 | return err; |
| 1303 | } |
Maor Gottlieb | 2cc43b4 | 2016-01-11 10:25:59 +0200 | [diff] [blame] | 1304 | } |
Maor Gottlieb | 2fee37a | 2016-06-10 00:07:31 +0300 | [diff] [blame] | 1305 | root->root_ft = new_root_ft; |
Maor Gottlieb | 2cc43b4 | 2016-01-11 10:25:59 +0200 | [diff] [blame] | 1306 | return 0; |
| 1307 | } |
| 1308 | |
Maor Gottlieb | f90edfd | 2016-01-11 10:26:01 +0200 | [diff] [blame] | 1309 | /* Connect flow table from previous priority to |
| 1310 | * the next flow table. |
| 1311 | */ |
| 1312 | static int disconnect_flow_table(struct mlx5_flow_table *ft) |
| 1313 | { |
| 1314 | struct mlx5_core_dev *dev = get_dev(&ft->node); |
| 1315 | struct mlx5_flow_table *next_ft; |
| 1316 | struct fs_prio *prio; |
| 1317 | int err = 0; |
| 1318 | |
| 1319 | err = update_root_ft_destroy(ft); |
| 1320 | if (err) |
| 1321 | return err; |
| 1322 | |
| 1323 | fs_get_obj(prio, ft->node.parent); |
| 1324 | if (!(list_first_entry(&prio->node.children, |
| 1325 | struct mlx5_flow_table, |
| 1326 | node.list) == ft)) |
| 1327 | return 0; |
| 1328 | |
| 1329 | next_ft = find_next_chained_ft(prio); |
Maor Gottlieb | b3638e1 | 2016-03-07 18:51:46 +0200 | [diff] [blame] | 1330 | err = connect_fwd_rules(dev, next_ft, ft); |
| 1331 | if (err) |
| 1332 | return err; |
| 1333 | |
Maor Gottlieb | f90edfd | 2016-01-11 10:26:01 +0200 | [diff] [blame] | 1334 | err = connect_prev_fts(dev, next_ft, prio); |
| 1335 | if (err) |
| 1336 | mlx5_core_warn(dev, "Failed to disconnect flow table %d\n", |
| 1337 | ft->id); |
| 1338 | return err; |
| 1339 | } |
| 1340 | |
Maor Gottlieb | 86d722a | 2015-12-10 17:12:44 +0200 | [diff] [blame] | 1341 | int mlx5_destroy_flow_table(struct mlx5_flow_table *ft) |
Maor Gottlieb | 0c56b97 | 2015-12-10 17:12:42 +0200 | [diff] [blame] | 1342 | { |
Maor Gottlieb | 2cc43b4 | 2016-01-11 10:25:59 +0200 | [diff] [blame] | 1343 | struct mlx5_flow_root_namespace *root = find_root(&ft->node); |
| 1344 | int err = 0; |
| 1345 | |
| 1346 | mutex_lock(&root->chain_lock); |
Maor Gottlieb | f90edfd | 2016-01-11 10:26:01 +0200 | [diff] [blame] | 1347 | err = disconnect_flow_table(ft); |
Maor Gottlieb | 2cc43b4 | 2016-01-11 10:25:59 +0200 | [diff] [blame] | 1348 | if (err) { |
| 1349 | mutex_unlock(&root->chain_lock); |
| 1350 | return err; |
| 1351 | } |
Maor Gottlieb | 0c56b97 | 2015-12-10 17:12:42 +0200 | [diff] [blame] | 1352 | if (tree_remove_node(&ft->node)) |
| 1353 | mlx5_core_warn(get_dev(&ft->node), "Flow table %d wasn't destroyed, refcount > 1\n", |
| 1354 | ft->id); |
Maor Gottlieb | 2cc43b4 | 2016-01-11 10:25:59 +0200 | [diff] [blame] | 1355 | mutex_unlock(&root->chain_lock); |
Maor Gottlieb | 0c56b97 | 2015-12-10 17:12:42 +0200 | [diff] [blame] | 1356 | |
Maor Gottlieb | 2cc43b4 | 2016-01-11 10:25:59 +0200 | [diff] [blame] | 1357 | return err; |
Maor Gottlieb | 0c56b97 | 2015-12-10 17:12:42 +0200 | [diff] [blame] | 1358 | } |
Maor Gottlieb | b217ea2 | 2016-01-11 10:26:06 +0200 | [diff] [blame] | 1359 | EXPORT_SYMBOL(mlx5_destroy_flow_table); |
Maor Gottlieb | 0c56b97 | 2015-12-10 17:12:42 +0200 | [diff] [blame] | 1360 | |
Maor Gottlieb | 86d722a | 2015-12-10 17:12:44 +0200 | [diff] [blame] | 1361 | void mlx5_destroy_flow_group(struct mlx5_flow_group *fg) |
Maor Gottlieb | 0c56b97 | 2015-12-10 17:12:42 +0200 | [diff] [blame] | 1362 | { |
| 1363 | if (tree_remove_node(&fg->node)) |
| 1364 | mlx5_core_warn(get_dev(&fg->node), "Flow group %d wasn't destroyed, refcount > 1\n", |
| 1365 | fg->id); |
| 1366 | } |
Maor Gottlieb | 2530236 | 2015-12-10 17:12:43 +0200 | [diff] [blame] | 1367 | |
Maor Gottlieb | 86d722a | 2015-12-10 17:12:44 +0200 | [diff] [blame] | 1368 | struct mlx5_flow_namespace *mlx5_get_flow_namespace(struct mlx5_core_dev *dev, |
| 1369 | enum mlx5_flow_namespace_type type) |
Maor Gottlieb | 2530236 | 2015-12-10 17:12:43 +0200 | [diff] [blame] | 1370 | { |
Maor Gottlieb | fba53f7 | 2016-07-04 17:23:06 +0300 | [diff] [blame] | 1371 | struct mlx5_flow_steering *steering = dev->priv.steering; |
| 1372 | struct mlx5_flow_root_namespace *root_ns; |
Maor Gottlieb | 2530236 | 2015-12-10 17:12:43 +0200 | [diff] [blame] | 1373 | int prio; |
Eli Cohen | 78228cb | 2016-04-22 00:33:06 +0300 | [diff] [blame] | 1374 | struct fs_prio *fs_prio; |
Maor Gottlieb | 2530236 | 2015-12-10 17:12:43 +0200 | [diff] [blame] | 1375 | struct mlx5_flow_namespace *ns; |
| 1376 | |
Maor Gottlieb | fba53f7 | 2016-07-04 17:23:06 +0300 | [diff] [blame] | 1377 | if (!steering) |
Maor Gottlieb | 2530236 | 2015-12-10 17:12:43 +0200 | [diff] [blame] | 1378 | return NULL; |
| 1379 | |
| 1380 | switch (type) { |
Maor Gottlieb | 4cbdd30 | 2016-01-11 10:26:04 +0200 | [diff] [blame] | 1381 | case MLX5_FLOW_NAMESPACE_BYPASS: |
Or Gerlitz | acbc200 | 2016-07-01 14:50:58 +0300 | [diff] [blame] | 1382 | case MLX5_FLOW_NAMESPACE_OFFLOADS: |
Maor Gottlieb | 6dc6071 | 2016-07-04 17:23:08 +0300 | [diff] [blame] | 1383 | case MLX5_FLOW_NAMESPACE_ETHTOOL: |
Maor Gottlieb | 2530236 | 2015-12-10 17:12:43 +0200 | [diff] [blame] | 1384 | case MLX5_FLOW_NAMESPACE_KERNEL: |
Maor Gottlieb | 4cbdd30 | 2016-01-11 10:26:04 +0200 | [diff] [blame] | 1385 | case MLX5_FLOW_NAMESPACE_LEFTOVERS: |
Maor Gottlieb | 153fefb | 2016-03-07 18:51:45 +0200 | [diff] [blame] | 1386 | case MLX5_FLOW_NAMESPACE_ANCHOR: |
Maor Gottlieb | 4cbdd30 | 2016-01-11 10:26:04 +0200 | [diff] [blame] | 1387 | prio = type; |
Maor Gottlieb | 2530236 | 2015-12-10 17:12:43 +0200 | [diff] [blame] | 1388 | break; |
| 1389 | case MLX5_FLOW_NAMESPACE_FDB: |
Maor Gottlieb | fba53f7 | 2016-07-04 17:23:06 +0300 | [diff] [blame] | 1390 | if (steering->fdb_root_ns) |
| 1391 | return &steering->fdb_root_ns->ns; |
Maor Gottlieb | 2530236 | 2015-12-10 17:12:43 +0200 | [diff] [blame] | 1392 | else |
| 1393 | return NULL; |
Mohamad Haj Yahia | efdc810 | 2016-05-03 17:13:54 +0300 | [diff] [blame] | 1394 | case MLX5_FLOW_NAMESPACE_ESW_EGRESS: |
Maor Gottlieb | fba53f7 | 2016-07-04 17:23:06 +0300 | [diff] [blame] | 1395 | if (steering->esw_egress_root_ns) |
| 1396 | return &steering->esw_egress_root_ns->ns; |
Mohamad Haj Yahia | efdc810 | 2016-05-03 17:13:54 +0300 | [diff] [blame] | 1397 | else |
| 1398 | return NULL; |
| 1399 | case MLX5_FLOW_NAMESPACE_ESW_INGRESS: |
Maor Gottlieb | fba53f7 | 2016-07-04 17:23:06 +0300 | [diff] [blame] | 1400 | if (steering->esw_ingress_root_ns) |
| 1401 | return &steering->esw_ingress_root_ns->ns; |
Mohamad Haj Yahia | efdc810 | 2016-05-03 17:13:54 +0300 | [diff] [blame] | 1402 | else |
| 1403 | return NULL; |
Maor Gottlieb | 2530236 | 2015-12-10 17:12:43 +0200 | [diff] [blame] | 1404 | default: |
| 1405 | return NULL; |
| 1406 | } |
| 1407 | |
Maor Gottlieb | fba53f7 | 2016-07-04 17:23:06 +0300 | [diff] [blame] | 1408 | root_ns = steering->root_ns; |
| 1409 | if (!root_ns) |
| 1410 | return NULL; |
| 1411 | |
Maor Gottlieb | 2530236 | 2015-12-10 17:12:43 +0200 | [diff] [blame] | 1412 | fs_prio = find_prio(&root_ns->ns, prio); |
| 1413 | if (!fs_prio) |
| 1414 | return NULL; |
| 1415 | |
| 1416 | ns = list_first_entry(&fs_prio->node.children, |
| 1417 | typeof(*ns), |
| 1418 | node.list); |
| 1419 | |
| 1420 | return ns; |
| 1421 | } |
Maor Gottlieb | b217ea2 | 2016-01-11 10:26:06 +0200 | [diff] [blame] | 1422 | EXPORT_SYMBOL(mlx5_get_flow_namespace); |
Maor Gottlieb | 2530236 | 2015-12-10 17:12:43 +0200 | [diff] [blame] | 1423 | |
| 1424 | static struct fs_prio *fs_create_prio(struct mlx5_flow_namespace *ns, |
Maor Gottlieb | a257b94 | 2016-04-29 01:36:34 +0300 | [diff] [blame] | 1425 | unsigned int prio, int num_levels) |
Maor Gottlieb | 2530236 | 2015-12-10 17:12:43 +0200 | [diff] [blame] | 1426 | { |
| 1427 | struct fs_prio *fs_prio; |
| 1428 | |
| 1429 | fs_prio = kzalloc(sizeof(*fs_prio), GFP_KERNEL); |
| 1430 | if (!fs_prio) |
| 1431 | return ERR_PTR(-ENOMEM); |
| 1432 | |
| 1433 | fs_prio->node.type = FS_TYPE_PRIO; |
| 1434 | tree_init_node(&fs_prio->node, 1, NULL); |
| 1435 | tree_add_node(&fs_prio->node, &ns->node); |
Maor Gottlieb | a257b94 | 2016-04-29 01:36:34 +0300 | [diff] [blame] | 1436 | fs_prio->num_levels = num_levels; |
Maor Gottlieb | 2530236 | 2015-12-10 17:12:43 +0200 | [diff] [blame] | 1437 | fs_prio->prio = prio; |
Maor Gottlieb | 2530236 | 2015-12-10 17:12:43 +0200 | [diff] [blame] | 1438 | list_add_tail(&fs_prio->node.list, &ns->node.children); |
| 1439 | |
| 1440 | return fs_prio; |
| 1441 | } |
| 1442 | |
| 1443 | static struct mlx5_flow_namespace *fs_init_namespace(struct mlx5_flow_namespace |
| 1444 | *ns) |
| 1445 | { |
| 1446 | ns->node.type = FS_TYPE_NAMESPACE; |
| 1447 | |
| 1448 | return ns; |
| 1449 | } |
| 1450 | |
| 1451 | static struct mlx5_flow_namespace *fs_create_namespace(struct fs_prio *prio) |
| 1452 | { |
| 1453 | struct mlx5_flow_namespace *ns; |
| 1454 | |
| 1455 | ns = kzalloc(sizeof(*ns), GFP_KERNEL); |
| 1456 | if (!ns) |
| 1457 | return ERR_PTR(-ENOMEM); |
| 1458 | |
| 1459 | fs_init_namespace(ns); |
| 1460 | tree_init_node(&ns->node, 1, NULL); |
| 1461 | tree_add_node(&ns->node, &prio->node); |
| 1462 | list_add_tail(&ns->node.list, &prio->node.children); |
| 1463 | |
| 1464 | return ns; |
| 1465 | } |
| 1466 | |
Maor Gottlieb | 13de6c1 | 2016-04-29 01:36:36 +0300 | [diff] [blame] | 1467 | static int create_leaf_prios(struct mlx5_flow_namespace *ns, int prio, |
| 1468 | struct init_tree_node *prio_metadata) |
Maor Gottlieb | 4cbdd30 | 2016-01-11 10:26:04 +0200 | [diff] [blame] | 1469 | { |
| 1470 | struct fs_prio *fs_prio; |
| 1471 | int i; |
| 1472 | |
| 1473 | for (i = 0; i < prio_metadata->num_leaf_prios; i++) { |
Maor Gottlieb | 13de6c1 | 2016-04-29 01:36:36 +0300 | [diff] [blame] | 1474 | fs_prio = fs_create_prio(ns, prio++, prio_metadata->num_levels); |
Maor Gottlieb | 4cbdd30 | 2016-01-11 10:26:04 +0200 | [diff] [blame] | 1475 | if (IS_ERR(fs_prio)) |
| 1476 | return PTR_ERR(fs_prio); |
| 1477 | } |
| 1478 | return 0; |
| 1479 | } |
| 1480 | |
Maor Gottlieb | 8d40d16 | 2016-01-11 10:26:03 +0200 | [diff] [blame] | 1481 | #define FLOW_TABLE_BIT_SZ 1 |
| 1482 | #define GET_FLOW_TABLE_CAP(dev, offset) \ |
| 1483 | ((be32_to_cpu(*((__be32 *)(dev->hca_caps_cur[MLX5_CAP_FLOW_TABLE]) + \ |
| 1484 | offset / 32)) >> \ |
| 1485 | (32 - FLOW_TABLE_BIT_SZ - (offset & 0x1f))) & FLOW_TABLE_BIT_SZ) |
| 1486 | static bool has_required_caps(struct mlx5_core_dev *dev, struct node_caps *caps) |
| 1487 | { |
| 1488 | int i; |
| 1489 | |
| 1490 | for (i = 0; i < caps->arr_sz; i++) { |
| 1491 | if (!GET_FLOW_TABLE_CAP(dev, caps->caps[i])) |
| 1492 | return false; |
| 1493 | } |
| 1494 | return true; |
| 1495 | } |
| 1496 | |
Maor Gottlieb | fba53f7 | 2016-07-04 17:23:06 +0300 | [diff] [blame] | 1497 | static int init_root_tree_recursive(struct mlx5_flow_steering *steering, |
Maor Gottlieb | 8d40d16 | 2016-01-11 10:26:03 +0200 | [diff] [blame] | 1498 | struct init_tree_node *init_node, |
Maor Gottlieb | 2530236 | 2015-12-10 17:12:43 +0200 | [diff] [blame] | 1499 | struct fs_node *fs_parent_node, |
| 1500 | struct init_tree_node *init_parent_node, |
Maor Gottlieb | 13de6c1 | 2016-04-29 01:36:36 +0300 | [diff] [blame] | 1501 | int prio) |
Maor Gottlieb | 2530236 | 2015-12-10 17:12:43 +0200 | [diff] [blame] | 1502 | { |
Maor Gottlieb | fba53f7 | 2016-07-04 17:23:06 +0300 | [diff] [blame] | 1503 | int max_ft_level = MLX5_CAP_FLOWTABLE(steering->dev, |
Maor Gottlieb | 8d40d16 | 2016-01-11 10:26:03 +0200 | [diff] [blame] | 1504 | flow_table_properties_nic_receive. |
| 1505 | max_ft_level); |
Maor Gottlieb | 2530236 | 2015-12-10 17:12:43 +0200 | [diff] [blame] | 1506 | struct mlx5_flow_namespace *fs_ns; |
| 1507 | struct fs_prio *fs_prio; |
| 1508 | struct fs_node *base; |
| 1509 | int i; |
| 1510 | int err; |
| 1511 | |
| 1512 | if (init_node->type == FS_TYPE_PRIO) { |
Maor Gottlieb | 8d40d16 | 2016-01-11 10:26:03 +0200 | [diff] [blame] | 1513 | if ((init_node->min_ft_level > max_ft_level) || |
Maor Gottlieb | fba53f7 | 2016-07-04 17:23:06 +0300 | [diff] [blame] | 1514 | !has_required_caps(steering->dev, &init_node->caps)) |
Maor Gottlieb | 8d40d16 | 2016-01-11 10:26:03 +0200 | [diff] [blame] | 1515 | return 0; |
Maor Gottlieb | 2530236 | 2015-12-10 17:12:43 +0200 | [diff] [blame] | 1516 | |
| 1517 | fs_get_obj(fs_ns, fs_parent_node); |
Maor Gottlieb | 4cbdd30 | 2016-01-11 10:26:04 +0200 | [diff] [blame] | 1518 | if (init_node->num_leaf_prios) |
Maor Gottlieb | 13de6c1 | 2016-04-29 01:36:36 +0300 | [diff] [blame] | 1519 | return create_leaf_prios(fs_ns, prio, init_node); |
| 1520 | fs_prio = fs_create_prio(fs_ns, prio, init_node->num_levels); |
Maor Gottlieb | 2530236 | 2015-12-10 17:12:43 +0200 | [diff] [blame] | 1521 | if (IS_ERR(fs_prio)) |
| 1522 | return PTR_ERR(fs_prio); |
| 1523 | base = &fs_prio->node; |
| 1524 | } else if (init_node->type == FS_TYPE_NAMESPACE) { |
| 1525 | fs_get_obj(fs_prio, fs_parent_node); |
| 1526 | fs_ns = fs_create_namespace(fs_prio); |
| 1527 | if (IS_ERR(fs_ns)) |
| 1528 | return PTR_ERR(fs_ns); |
| 1529 | base = &fs_ns->node; |
| 1530 | } else { |
| 1531 | return -EINVAL; |
| 1532 | } |
Maor Gottlieb | 13de6c1 | 2016-04-29 01:36:36 +0300 | [diff] [blame] | 1533 | prio = 0; |
Maor Gottlieb | 2530236 | 2015-12-10 17:12:43 +0200 | [diff] [blame] | 1534 | for (i = 0; i < init_node->ar_size; i++) { |
Maor Gottlieb | fba53f7 | 2016-07-04 17:23:06 +0300 | [diff] [blame] | 1535 | err = init_root_tree_recursive(steering, &init_node->children[i], |
Maor Gottlieb | 13de6c1 | 2016-04-29 01:36:36 +0300 | [diff] [blame] | 1536 | base, init_node, prio); |
Maor Gottlieb | 2530236 | 2015-12-10 17:12:43 +0200 | [diff] [blame] | 1537 | if (err) |
| 1538 | return err; |
Maor Gottlieb | 13de6c1 | 2016-04-29 01:36:36 +0300 | [diff] [blame] | 1539 | if (init_node->children[i].type == FS_TYPE_PRIO && |
| 1540 | init_node->children[i].num_leaf_prios) { |
| 1541 | prio += init_node->children[i].num_leaf_prios; |
| 1542 | } |
Maor Gottlieb | 2530236 | 2015-12-10 17:12:43 +0200 | [diff] [blame] | 1543 | } |
| 1544 | |
| 1545 | return 0; |
| 1546 | } |
| 1547 | |
Maor Gottlieb | fba53f7 | 2016-07-04 17:23:06 +0300 | [diff] [blame] | 1548 | static int init_root_tree(struct mlx5_flow_steering *steering, |
Maor Gottlieb | 8d40d16 | 2016-01-11 10:26:03 +0200 | [diff] [blame] | 1549 | struct init_tree_node *init_node, |
Maor Gottlieb | 2530236 | 2015-12-10 17:12:43 +0200 | [diff] [blame] | 1550 | struct fs_node *fs_parent_node) |
| 1551 | { |
| 1552 | int i; |
| 1553 | struct mlx5_flow_namespace *fs_ns; |
| 1554 | int err; |
| 1555 | |
| 1556 | fs_get_obj(fs_ns, fs_parent_node); |
| 1557 | for (i = 0; i < init_node->ar_size; i++) { |
Maor Gottlieb | fba53f7 | 2016-07-04 17:23:06 +0300 | [diff] [blame] | 1558 | err = init_root_tree_recursive(steering, &init_node->children[i], |
Maor Gottlieb | 2530236 | 2015-12-10 17:12:43 +0200 | [diff] [blame] | 1559 | &fs_ns->node, |
| 1560 | init_node, i); |
| 1561 | if (err) |
| 1562 | return err; |
| 1563 | } |
| 1564 | return 0; |
| 1565 | } |
| 1566 | |
Maor Gottlieb | fba53f7 | 2016-07-04 17:23:06 +0300 | [diff] [blame] | 1567 | static struct mlx5_flow_root_namespace *create_root_ns(struct mlx5_flow_steering *steering, |
Maor Gottlieb | 2530236 | 2015-12-10 17:12:43 +0200 | [diff] [blame] | 1568 | enum fs_flow_table_type |
| 1569 | table_type) |
| 1570 | { |
| 1571 | struct mlx5_flow_root_namespace *root_ns; |
| 1572 | struct mlx5_flow_namespace *ns; |
| 1573 | |
Maor Gottlieb | 86d722a | 2015-12-10 17:12:44 +0200 | [diff] [blame] | 1574 | /* Create the root namespace */ |
Maor Gottlieb | 2530236 | 2015-12-10 17:12:43 +0200 | [diff] [blame] | 1575 | root_ns = mlx5_vzalloc(sizeof(*root_ns)); |
| 1576 | if (!root_ns) |
| 1577 | return NULL; |
| 1578 | |
Maor Gottlieb | fba53f7 | 2016-07-04 17:23:06 +0300 | [diff] [blame] | 1579 | root_ns->dev = steering->dev; |
Maor Gottlieb | 2530236 | 2015-12-10 17:12:43 +0200 | [diff] [blame] | 1580 | root_ns->table_type = table_type; |
| 1581 | |
| 1582 | ns = &root_ns->ns; |
| 1583 | fs_init_namespace(ns); |
Maor Gottlieb | 2cc43b4 | 2016-01-11 10:25:59 +0200 | [diff] [blame] | 1584 | mutex_init(&root_ns->chain_lock); |
Maor Gottlieb | 2530236 | 2015-12-10 17:12:43 +0200 | [diff] [blame] | 1585 | tree_init_node(&ns->node, 1, NULL); |
| 1586 | tree_add_node(&ns->node, NULL); |
| 1587 | |
| 1588 | return root_ns; |
| 1589 | } |
| 1590 | |
Maor Gottlieb | 655227e | 2016-01-11 10:26:02 +0200 | [diff] [blame] | 1591 | static void set_prio_attrs_in_prio(struct fs_prio *prio, int acc_level); |
| 1592 | |
| 1593 | static int set_prio_attrs_in_ns(struct mlx5_flow_namespace *ns, int acc_level) |
| 1594 | { |
| 1595 | struct fs_prio *prio; |
| 1596 | |
| 1597 | fs_for_each_prio(prio, ns) { |
Maor Gottlieb | a257b94 | 2016-04-29 01:36:34 +0300 | [diff] [blame] | 1598 | /* This updates prio start_level and num_levels */ |
Maor Gottlieb | 655227e | 2016-01-11 10:26:02 +0200 | [diff] [blame] | 1599 | set_prio_attrs_in_prio(prio, acc_level); |
Maor Gottlieb | a257b94 | 2016-04-29 01:36:34 +0300 | [diff] [blame] | 1600 | acc_level += prio->num_levels; |
Maor Gottlieb | 655227e | 2016-01-11 10:26:02 +0200 | [diff] [blame] | 1601 | } |
| 1602 | return acc_level; |
| 1603 | } |
| 1604 | |
| 1605 | static void set_prio_attrs_in_prio(struct fs_prio *prio, int acc_level) |
| 1606 | { |
| 1607 | struct mlx5_flow_namespace *ns; |
| 1608 | int acc_level_ns = acc_level; |
| 1609 | |
| 1610 | prio->start_level = acc_level; |
| 1611 | fs_for_each_ns(ns, prio) |
Maor Gottlieb | a257b94 | 2016-04-29 01:36:34 +0300 | [diff] [blame] | 1612 | /* This updates start_level and num_levels of ns's priority descendants */ |
Maor Gottlieb | 655227e | 2016-01-11 10:26:02 +0200 | [diff] [blame] | 1613 | acc_level_ns = set_prio_attrs_in_ns(ns, acc_level); |
Maor Gottlieb | a257b94 | 2016-04-29 01:36:34 +0300 | [diff] [blame] | 1614 | if (!prio->num_levels) |
| 1615 | prio->num_levels = acc_level_ns - prio->start_level; |
| 1616 | WARN_ON(prio->num_levels < acc_level_ns - prio->start_level); |
Maor Gottlieb | 655227e | 2016-01-11 10:26:02 +0200 | [diff] [blame] | 1617 | } |
| 1618 | |
| 1619 | static void set_prio_attrs(struct mlx5_flow_root_namespace *root_ns) |
| 1620 | { |
| 1621 | struct mlx5_flow_namespace *ns = &root_ns->ns; |
| 1622 | struct fs_prio *prio; |
| 1623 | int start_level = 0; |
| 1624 | |
| 1625 | fs_for_each_prio(prio, ns) { |
| 1626 | set_prio_attrs_in_prio(prio, start_level); |
Maor Gottlieb | a257b94 | 2016-04-29 01:36:34 +0300 | [diff] [blame] | 1627 | start_level += prio->num_levels; |
Maor Gottlieb | 655227e | 2016-01-11 10:26:02 +0200 | [diff] [blame] | 1628 | } |
| 1629 | } |
| 1630 | |
Maor Gottlieb | 153fefb | 2016-03-07 18:51:45 +0200 | [diff] [blame] | 1631 | #define ANCHOR_PRIO 0 |
| 1632 | #define ANCHOR_SIZE 1 |
Maor Gottlieb | d63cd28 | 2016-04-29 01:36:35 +0300 | [diff] [blame] | 1633 | #define ANCHOR_LEVEL 0 |
Maor Gottlieb | fba53f7 | 2016-07-04 17:23:06 +0300 | [diff] [blame] | 1634 | static int create_anchor_flow_table(struct mlx5_flow_steering *steering) |
Maor Gottlieb | 153fefb | 2016-03-07 18:51:45 +0200 | [diff] [blame] | 1635 | { |
| 1636 | struct mlx5_flow_namespace *ns = NULL; |
| 1637 | struct mlx5_flow_table *ft; |
| 1638 | |
Maor Gottlieb | fba53f7 | 2016-07-04 17:23:06 +0300 | [diff] [blame] | 1639 | ns = mlx5_get_flow_namespace(steering->dev, MLX5_FLOW_NAMESPACE_ANCHOR); |
Maor Gottlieb | 153fefb | 2016-03-07 18:51:45 +0200 | [diff] [blame] | 1640 | if (!ns) |
| 1641 | return -EINVAL; |
Maor Gottlieb | d63cd28 | 2016-04-29 01:36:35 +0300 | [diff] [blame] | 1642 | ft = mlx5_create_flow_table(ns, ANCHOR_PRIO, ANCHOR_SIZE, ANCHOR_LEVEL); |
Maor Gottlieb | 153fefb | 2016-03-07 18:51:45 +0200 | [diff] [blame] | 1643 | if (IS_ERR(ft)) { |
Maor Gottlieb | fba53f7 | 2016-07-04 17:23:06 +0300 | [diff] [blame] | 1644 | mlx5_core_err(steering->dev, "Failed to create last anchor flow table"); |
Maor Gottlieb | 153fefb | 2016-03-07 18:51:45 +0200 | [diff] [blame] | 1645 | return PTR_ERR(ft); |
| 1646 | } |
| 1647 | return 0; |
| 1648 | } |
| 1649 | |
Maor Gottlieb | fba53f7 | 2016-07-04 17:23:06 +0300 | [diff] [blame] | 1650 | static int init_root_ns(struct mlx5_flow_steering *steering) |
Maor Gottlieb | 2530236 | 2015-12-10 17:12:43 +0200 | [diff] [blame] | 1651 | { |
Maor Gottlieb | 2530236 | 2015-12-10 17:12:43 +0200 | [diff] [blame] | 1652 | |
Maor Gottlieb | fba53f7 | 2016-07-04 17:23:06 +0300 | [diff] [blame] | 1653 | steering->root_ns = create_root_ns(steering, FS_FT_NIC_RX); |
| 1654 | if (IS_ERR_OR_NULL(steering->root_ns)) |
Maor Gottlieb | 2530236 | 2015-12-10 17:12:43 +0200 | [diff] [blame] | 1655 | goto cleanup; |
| 1656 | |
Maor Gottlieb | fba53f7 | 2016-07-04 17:23:06 +0300 | [diff] [blame] | 1657 | if (init_root_tree(steering, &root_fs, &steering->root_ns->ns.node)) |
Maor Gottlieb | 2530236 | 2015-12-10 17:12:43 +0200 | [diff] [blame] | 1658 | goto cleanup; |
| 1659 | |
Maor Gottlieb | fba53f7 | 2016-07-04 17:23:06 +0300 | [diff] [blame] | 1660 | set_prio_attrs(steering->root_ns); |
Maor Gottlieb | 655227e | 2016-01-11 10:26:02 +0200 | [diff] [blame] | 1661 | |
Maor Gottlieb | fba53f7 | 2016-07-04 17:23:06 +0300 | [diff] [blame] | 1662 | if (create_anchor_flow_table(steering)) |
Maor Gottlieb | 153fefb | 2016-03-07 18:51:45 +0200 | [diff] [blame] | 1663 | goto cleanup; |
| 1664 | |
Maor Gottlieb | 2530236 | 2015-12-10 17:12:43 +0200 | [diff] [blame] | 1665 | return 0; |
| 1666 | |
| 1667 | cleanup: |
Maor Gottlieb | fba53f7 | 2016-07-04 17:23:06 +0300 | [diff] [blame] | 1668 | mlx5_cleanup_fs(steering->dev); |
Maor Gottlieb | 2530236 | 2015-12-10 17:12:43 +0200 | [diff] [blame] | 1669 | return -ENOMEM; |
| 1670 | } |
| 1671 | |
Maor Gottlieb | 0da2d66 | 2016-07-04 17:23:07 +0300 | [diff] [blame] | 1672 | static void clean_tree(struct fs_node *node) |
Maor Gottlieb | 2530236 | 2015-12-10 17:12:43 +0200 | [diff] [blame] | 1673 | { |
Maor Gottlieb | 0da2d66 | 2016-07-04 17:23:07 +0300 | [diff] [blame] | 1674 | if (node) { |
| 1675 | struct fs_node *iter; |
| 1676 | struct fs_node *temp; |
Maor Gottlieb | 2530236 | 2015-12-10 17:12:43 +0200 | [diff] [blame] | 1677 | |
Maor Gottlieb | 0da2d66 | 2016-07-04 17:23:07 +0300 | [diff] [blame] | 1678 | list_for_each_entry_safe(iter, temp, &node->children, list) |
| 1679 | clean_tree(iter); |
| 1680 | tree_remove_node(node); |
| 1681 | } |
| 1682 | } |
| 1683 | |
| 1684 | static void cleanup_root_ns(struct mlx5_flow_root_namespace *root_ns) |
| 1685 | { |
Maor Gottlieb | 2530236 | 2015-12-10 17:12:43 +0200 | [diff] [blame] | 1686 | if (!root_ns) |
| 1687 | return; |
| 1688 | |
Maor Gottlieb | 0da2d66 | 2016-07-04 17:23:07 +0300 | [diff] [blame] | 1689 | clean_tree(&root_ns->ns.node); |
Maor Gottlieb | 2530236 | 2015-12-10 17:12:43 +0200 | [diff] [blame] | 1690 | } |
| 1691 | |
| 1692 | void mlx5_cleanup_fs(struct mlx5_core_dev *dev) |
| 1693 | { |
Maor Gottlieb | fba53f7 | 2016-07-04 17:23:06 +0300 | [diff] [blame] | 1694 | struct mlx5_flow_steering *steering = dev->priv.steering; |
| 1695 | |
Maor Gottlieb | 876d634 | 2016-06-10 00:07:32 +0300 | [diff] [blame] | 1696 | if (MLX5_CAP_GEN(dev, port_type) != MLX5_CAP_PORT_TYPE_ETH) |
| 1697 | return; |
| 1698 | |
Maor Gottlieb | 0da2d66 | 2016-07-04 17:23:07 +0300 | [diff] [blame] | 1699 | cleanup_root_ns(steering->root_ns); |
| 1700 | cleanup_root_ns(steering->esw_egress_root_ns); |
| 1701 | cleanup_root_ns(steering->esw_ingress_root_ns); |
| 1702 | cleanup_root_ns(steering->fdb_root_ns); |
Amir Vadai | 43a335e | 2016-05-13 12:55:41 +0000 | [diff] [blame] | 1703 | mlx5_cleanup_fc_stats(dev); |
Maor Gottlieb | fba53f7 | 2016-07-04 17:23:06 +0300 | [diff] [blame] | 1704 | kfree(steering); |
Maor Gottlieb | 2530236 | 2015-12-10 17:12:43 +0200 | [diff] [blame] | 1705 | } |
| 1706 | |
Maor Gottlieb | fba53f7 | 2016-07-04 17:23:06 +0300 | [diff] [blame] | 1707 | static int init_fdb_root_ns(struct mlx5_flow_steering *steering) |
Maor Gottlieb | 2530236 | 2015-12-10 17:12:43 +0200 | [diff] [blame] | 1708 | { |
| 1709 | struct fs_prio *prio; |
| 1710 | |
Maor Gottlieb | fba53f7 | 2016-07-04 17:23:06 +0300 | [diff] [blame] | 1711 | steering->fdb_root_ns = create_root_ns(steering, FS_FT_FDB); |
| 1712 | if (!steering->fdb_root_ns) |
Maor Gottlieb | 2530236 | 2015-12-10 17:12:43 +0200 | [diff] [blame] | 1713 | return -ENOMEM; |
| 1714 | |
Maor Gottlieb | fba53f7 | 2016-07-04 17:23:06 +0300 | [diff] [blame] | 1715 | prio = fs_create_prio(&steering->fdb_root_ns->ns, 0, 1); |
Or Gerlitz | 1033665 | 2016-07-14 10:32:40 +0300 | [diff] [blame] | 1716 | if (IS_ERR(prio)) |
| 1717 | goto out_err; |
| 1718 | |
| 1719 | prio = fs_create_prio(&steering->fdb_root_ns->ns, 1, 1); |
| 1720 | if (IS_ERR(prio)) |
| 1721 | goto out_err; |
| 1722 | |
| 1723 | set_prio_attrs(steering->fdb_root_ns); |
| 1724 | return 0; |
| 1725 | |
| 1726 | out_err: |
| 1727 | cleanup_root_ns(steering->fdb_root_ns); |
| 1728 | steering->fdb_root_ns = NULL; |
| 1729 | return PTR_ERR(prio); |
Maor Gottlieb | 2530236 | 2015-12-10 17:12:43 +0200 | [diff] [blame] | 1730 | } |
| 1731 | |
Maor Gottlieb | fba53f7 | 2016-07-04 17:23:06 +0300 | [diff] [blame] | 1732 | static int init_ingress_acl_root_ns(struct mlx5_flow_steering *steering) |
Mohamad Haj Yahia | efdc810 | 2016-05-03 17:13:54 +0300 | [diff] [blame] | 1733 | { |
| 1734 | struct fs_prio *prio; |
| 1735 | |
Maor Gottlieb | fba53f7 | 2016-07-04 17:23:06 +0300 | [diff] [blame] | 1736 | steering->esw_egress_root_ns = create_root_ns(steering, FS_FT_ESW_EGRESS_ACL); |
| 1737 | if (!steering->esw_egress_root_ns) |
Mohamad Haj Yahia | efdc810 | 2016-05-03 17:13:54 +0300 | [diff] [blame] | 1738 | return -ENOMEM; |
| 1739 | |
| 1740 | /* create 1 prio*/ |
Maor Gottlieb | fba53f7 | 2016-07-04 17:23:06 +0300 | [diff] [blame] | 1741 | prio = fs_create_prio(&steering->esw_egress_root_ns->ns, 0, |
| 1742 | MLX5_TOTAL_VPORTS(steering->dev)); |
Wei Yongjun | 44fafda | 2016-07-19 11:35:46 +0000 | [diff] [blame] | 1743 | return PTR_ERR_OR_ZERO(prio); |
Mohamad Haj Yahia | efdc810 | 2016-05-03 17:13:54 +0300 | [diff] [blame] | 1744 | } |
| 1745 | |
Maor Gottlieb | fba53f7 | 2016-07-04 17:23:06 +0300 | [diff] [blame] | 1746 | static int init_egress_acl_root_ns(struct mlx5_flow_steering *steering) |
Mohamad Haj Yahia | efdc810 | 2016-05-03 17:13:54 +0300 | [diff] [blame] | 1747 | { |
| 1748 | struct fs_prio *prio; |
| 1749 | |
Maor Gottlieb | fba53f7 | 2016-07-04 17:23:06 +0300 | [diff] [blame] | 1750 | steering->esw_ingress_root_ns = create_root_ns(steering, FS_FT_ESW_INGRESS_ACL); |
| 1751 | if (!steering->esw_ingress_root_ns) |
Mohamad Haj Yahia | efdc810 | 2016-05-03 17:13:54 +0300 | [diff] [blame] | 1752 | return -ENOMEM; |
| 1753 | |
| 1754 | /* create 1 prio*/ |
Maor Gottlieb | fba53f7 | 2016-07-04 17:23:06 +0300 | [diff] [blame] | 1755 | prio = fs_create_prio(&steering->esw_ingress_root_ns->ns, 0, |
| 1756 | MLX5_TOTAL_VPORTS(steering->dev)); |
Wei Yongjun | 44fafda | 2016-07-19 11:35:46 +0000 | [diff] [blame] | 1757 | return PTR_ERR_OR_ZERO(prio); |
Mohamad Haj Yahia | efdc810 | 2016-05-03 17:13:54 +0300 | [diff] [blame] | 1758 | } |
| 1759 | |
Maor Gottlieb | 2530236 | 2015-12-10 17:12:43 +0200 | [diff] [blame] | 1760 | int mlx5_init_fs(struct mlx5_core_dev *dev) |
| 1761 | { |
Maor Gottlieb | fba53f7 | 2016-07-04 17:23:06 +0300 | [diff] [blame] | 1762 | struct mlx5_flow_steering *steering; |
Maor Gottlieb | 2530236 | 2015-12-10 17:12:43 +0200 | [diff] [blame] | 1763 | int err = 0; |
| 1764 | |
Maor Gottlieb | 876d634 | 2016-06-10 00:07:32 +0300 | [diff] [blame] | 1765 | if (MLX5_CAP_GEN(dev, port_type) != MLX5_CAP_PORT_TYPE_ETH) |
| 1766 | return 0; |
| 1767 | |
Amir Vadai | 43a335e | 2016-05-13 12:55:41 +0000 | [diff] [blame] | 1768 | err = mlx5_init_fc_stats(dev); |
| 1769 | if (err) |
| 1770 | return err; |
| 1771 | |
Maor Gottlieb | fba53f7 | 2016-07-04 17:23:06 +0300 | [diff] [blame] | 1772 | steering = kzalloc(sizeof(*steering), GFP_KERNEL); |
| 1773 | if (!steering) |
| 1774 | return -ENOMEM; |
| 1775 | steering->dev = dev; |
| 1776 | dev->priv.steering = steering; |
| 1777 | |
Maor Gottlieb | 876d634 | 2016-06-10 00:07:32 +0300 | [diff] [blame] | 1778 | if (MLX5_CAP_GEN(dev, nic_flow_table) && |
| 1779 | MLX5_CAP_FLOWTABLE_NIC_RX(dev, ft_support)) { |
Maor Gottlieb | fba53f7 | 2016-07-04 17:23:06 +0300 | [diff] [blame] | 1780 | err = init_root_ns(steering); |
Maor Gottlieb | 2530236 | 2015-12-10 17:12:43 +0200 | [diff] [blame] | 1781 | if (err) |
Amir Vadai | 43a335e | 2016-05-13 12:55:41 +0000 | [diff] [blame] | 1782 | goto err; |
Maor Gottlieb | 2530236 | 2015-12-10 17:12:43 +0200 | [diff] [blame] | 1783 | } |
Maor Gottlieb | 876d634 | 2016-06-10 00:07:32 +0300 | [diff] [blame] | 1784 | |
Maor Gottlieb | 2530236 | 2015-12-10 17:12:43 +0200 | [diff] [blame] | 1785 | if (MLX5_CAP_GEN(dev, eswitch_flow_table)) { |
Maor Gottlieb | bd02ef8 | 2016-06-10 00:07:33 +0300 | [diff] [blame] | 1786 | if (MLX5_CAP_ESW_FLOWTABLE_FDB(dev, ft_support)) { |
Maor Gottlieb | fba53f7 | 2016-07-04 17:23:06 +0300 | [diff] [blame] | 1787 | err = init_fdb_root_ns(steering); |
Maor Gottlieb | bd02ef8 | 2016-06-10 00:07:33 +0300 | [diff] [blame] | 1788 | if (err) |
| 1789 | goto err; |
| 1790 | } |
| 1791 | if (MLX5_CAP_ESW_EGRESS_ACL(dev, ft_support)) { |
Maor Gottlieb | fba53f7 | 2016-07-04 17:23:06 +0300 | [diff] [blame] | 1792 | err = init_egress_acl_root_ns(steering); |
Maor Gottlieb | bd02ef8 | 2016-06-10 00:07:33 +0300 | [diff] [blame] | 1793 | if (err) |
| 1794 | goto err; |
| 1795 | } |
| 1796 | if (MLX5_CAP_ESW_INGRESS_ACL(dev, ft_support)) { |
Maor Gottlieb | fba53f7 | 2016-07-04 17:23:06 +0300 | [diff] [blame] | 1797 | err = init_ingress_acl_root_ns(steering); |
Maor Gottlieb | bd02ef8 | 2016-06-10 00:07:33 +0300 | [diff] [blame] | 1798 | if (err) |
| 1799 | goto err; |
| 1800 | } |
Maor Gottlieb | 2530236 | 2015-12-10 17:12:43 +0200 | [diff] [blame] | 1801 | } |
| 1802 | |
Mohamad Haj Yahia | efdc810 | 2016-05-03 17:13:54 +0300 | [diff] [blame] | 1803 | return 0; |
| 1804 | err: |
| 1805 | mlx5_cleanup_fs(dev); |
Maor Gottlieb | 2530236 | 2015-12-10 17:12:43 +0200 | [diff] [blame] | 1806 | return err; |
| 1807 | } |