Maor Gottlieb | 26a8145 | 2015-12-10 17:12:39 +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/mlx5/driver.h> |
| 34 | #include <linux/mlx5/device.h> |
| 35 | #include <linux/mlx5/mlx5_ifc.h> |
| 36 | |
| 37 | #include "fs_core.h" |
| 38 | #include "fs_cmd.h" |
| 39 | #include "mlx5_core.h" |
| 40 | |
Maor Gottlieb | 2cc43b4 | 2016-01-11 10:25:59 +0200 | [diff] [blame] | 41 | int mlx5_cmd_update_root_ft(struct mlx5_core_dev *dev, |
| 42 | struct mlx5_flow_table *ft) |
| 43 | { |
Saeed Mahameed | c4f287c | 2016-07-19 20:17:12 +0300 | [diff] [blame] | 44 | u32 in[MLX5_ST_SZ_DW(set_flow_table_root_in)] = {0}; |
| 45 | u32 out[MLX5_ST_SZ_DW(set_flow_table_root_out)] = {0}; |
Maor Gottlieb | 2cc43b4 | 2016-01-11 10:25:59 +0200 | [diff] [blame] | 46 | |
| 47 | MLX5_SET(set_flow_table_root_in, in, opcode, |
| 48 | MLX5_CMD_OP_SET_FLOW_TABLE_ROOT); |
| 49 | MLX5_SET(set_flow_table_root_in, in, table_type, ft->type); |
| 50 | MLX5_SET(set_flow_table_root_in, in, table_id, ft->id); |
Mohamad Haj Yahia | efdc810 | 2016-05-03 17:13:54 +0300 | [diff] [blame] | 51 | if (ft->vport) { |
| 52 | MLX5_SET(set_flow_table_root_in, in, vport_number, ft->vport); |
| 53 | MLX5_SET(set_flow_table_root_in, in, other_vport, 1); |
| 54 | } |
Maor Gottlieb | 2cc43b4 | 2016-01-11 10:25:59 +0200 | [diff] [blame] | 55 | |
Saeed Mahameed | c4f287c | 2016-07-19 20:17:12 +0300 | [diff] [blame] | 56 | return mlx5_cmd_exec(dev, in, sizeof(in), out, sizeof(out)); |
Maor Gottlieb | 2cc43b4 | 2016-01-11 10:25:59 +0200 | [diff] [blame] | 57 | } |
| 58 | |
Maor Gottlieb | 26a8145 | 2015-12-10 17:12:39 +0200 | [diff] [blame] | 59 | int mlx5_cmd_create_flow_table(struct mlx5_core_dev *dev, |
Mohamad Haj Yahia | efdc810 | 2016-05-03 17:13:54 +0300 | [diff] [blame] | 60 | u16 vport, |
Maor Gottlieb | 26a8145 | 2015-12-10 17:12:39 +0200 | [diff] [blame] | 61 | enum fs_flow_table_type type, unsigned int level, |
Maor Gottlieb | f90edfd | 2016-01-11 10:26:01 +0200 | [diff] [blame] | 62 | unsigned int log_size, struct mlx5_flow_table |
| 63 | *next_ft, unsigned int *table_id) |
Maor Gottlieb | 26a8145 | 2015-12-10 17:12:39 +0200 | [diff] [blame] | 64 | { |
Saeed Mahameed | c4f287c | 2016-07-19 20:17:12 +0300 | [diff] [blame] | 65 | u32 out[MLX5_ST_SZ_DW(create_flow_table_out)] = {0}; |
| 66 | u32 in[MLX5_ST_SZ_DW(create_flow_table_in)] = {0}; |
Maor Gottlieb | 26a8145 | 2015-12-10 17:12:39 +0200 | [diff] [blame] | 67 | int err; |
| 68 | |
Maor Gottlieb | 26a8145 | 2015-12-10 17:12:39 +0200 | [diff] [blame] | 69 | MLX5_SET(create_flow_table_in, in, opcode, |
| 70 | MLX5_CMD_OP_CREATE_FLOW_TABLE); |
| 71 | |
Maor Gottlieb | f90edfd | 2016-01-11 10:26:01 +0200 | [diff] [blame] | 72 | if (next_ft) { |
| 73 | MLX5_SET(create_flow_table_in, in, table_miss_mode, 1); |
| 74 | MLX5_SET(create_flow_table_in, in, table_miss_id, next_ft->id); |
| 75 | } |
Maor Gottlieb | 26a8145 | 2015-12-10 17:12:39 +0200 | [diff] [blame] | 76 | MLX5_SET(create_flow_table_in, in, table_type, type); |
| 77 | MLX5_SET(create_flow_table_in, in, level, level); |
| 78 | MLX5_SET(create_flow_table_in, in, log_size, log_size); |
Mohamad Haj Yahia | efdc810 | 2016-05-03 17:13:54 +0300 | [diff] [blame] | 79 | if (vport) { |
| 80 | MLX5_SET(create_flow_table_in, in, vport_number, vport); |
| 81 | MLX5_SET(create_flow_table_in, in, other_vport, 1); |
| 82 | } |
Maor Gottlieb | 26a8145 | 2015-12-10 17:12:39 +0200 | [diff] [blame] | 83 | |
Saeed Mahameed | c4f287c | 2016-07-19 20:17:12 +0300 | [diff] [blame] | 84 | err = mlx5_cmd_exec(dev, in, sizeof(in), out, sizeof(out)); |
Maor Gottlieb | 26a8145 | 2015-12-10 17:12:39 +0200 | [diff] [blame] | 85 | if (!err) |
| 86 | *table_id = MLX5_GET(create_flow_table_out, out, |
| 87 | table_id); |
| 88 | return err; |
| 89 | } |
| 90 | |
| 91 | int mlx5_cmd_destroy_flow_table(struct mlx5_core_dev *dev, |
| 92 | struct mlx5_flow_table *ft) |
| 93 | { |
Saeed Mahameed | c4f287c | 2016-07-19 20:17:12 +0300 | [diff] [blame] | 94 | u32 in[MLX5_ST_SZ_DW(destroy_flow_table_in)] = {0}; |
| 95 | u32 out[MLX5_ST_SZ_DW(destroy_flow_table_out)] = {0}; |
Maor Gottlieb | 26a8145 | 2015-12-10 17:12:39 +0200 | [diff] [blame] | 96 | |
| 97 | MLX5_SET(destroy_flow_table_in, in, opcode, |
| 98 | MLX5_CMD_OP_DESTROY_FLOW_TABLE); |
| 99 | MLX5_SET(destroy_flow_table_in, in, table_type, ft->type); |
| 100 | MLX5_SET(destroy_flow_table_in, in, table_id, ft->id); |
Mohamad Haj Yahia | efdc810 | 2016-05-03 17:13:54 +0300 | [diff] [blame] | 101 | if (ft->vport) { |
| 102 | MLX5_SET(destroy_flow_table_in, in, vport_number, ft->vport); |
| 103 | MLX5_SET(destroy_flow_table_in, in, other_vport, 1); |
| 104 | } |
Maor Gottlieb | 26a8145 | 2015-12-10 17:12:39 +0200 | [diff] [blame] | 105 | |
Saeed Mahameed | c4f287c | 2016-07-19 20:17:12 +0300 | [diff] [blame] | 106 | return mlx5_cmd_exec(dev, in, sizeof(in), out, sizeof(out)); |
Maor Gottlieb | 26a8145 | 2015-12-10 17:12:39 +0200 | [diff] [blame] | 107 | } |
| 108 | |
Maor Gottlieb | 34a40e6 | 2016-01-11 10:26:00 +0200 | [diff] [blame] | 109 | int mlx5_cmd_modify_flow_table(struct mlx5_core_dev *dev, |
| 110 | struct mlx5_flow_table *ft, |
| 111 | struct mlx5_flow_table *next_ft) |
| 112 | { |
Saeed Mahameed | c4f287c | 2016-07-19 20:17:12 +0300 | [diff] [blame] | 113 | u32 in[MLX5_ST_SZ_DW(modify_flow_table_in)] = {0}; |
| 114 | u32 out[MLX5_ST_SZ_DW(modify_flow_table_out)] = {0}; |
Maor Gottlieb | 34a40e6 | 2016-01-11 10:26:00 +0200 | [diff] [blame] | 115 | |
| 116 | MLX5_SET(modify_flow_table_in, in, opcode, |
| 117 | MLX5_CMD_OP_MODIFY_FLOW_TABLE); |
| 118 | MLX5_SET(modify_flow_table_in, in, table_type, ft->type); |
| 119 | MLX5_SET(modify_flow_table_in, in, table_id, ft->id); |
Mohamad Haj Yahia | efdc810 | 2016-05-03 17:13:54 +0300 | [diff] [blame] | 120 | if (ft->vport) { |
| 121 | MLX5_SET(modify_flow_table_in, in, vport_number, ft->vport); |
| 122 | MLX5_SET(modify_flow_table_in, in, other_vport, 1); |
| 123 | } |
Maor Gottlieb | 34a40e6 | 2016-01-11 10:26:00 +0200 | [diff] [blame] | 124 | MLX5_SET(modify_flow_table_in, in, modify_field_select, |
| 125 | MLX5_MODIFY_FLOW_TABLE_MISS_TABLE_ID); |
| 126 | if (next_ft) { |
| 127 | MLX5_SET(modify_flow_table_in, in, table_miss_mode, 1); |
| 128 | MLX5_SET(modify_flow_table_in, in, table_miss_id, next_ft->id); |
| 129 | } else { |
| 130 | MLX5_SET(modify_flow_table_in, in, table_miss_mode, 0); |
| 131 | } |
| 132 | |
Saeed Mahameed | c4f287c | 2016-07-19 20:17:12 +0300 | [diff] [blame] | 133 | return mlx5_cmd_exec(dev, in, sizeof(in), out, sizeof(out)); |
Maor Gottlieb | 34a40e6 | 2016-01-11 10:26:00 +0200 | [diff] [blame] | 134 | } |
| 135 | |
Maor Gottlieb | 26a8145 | 2015-12-10 17:12:39 +0200 | [diff] [blame] | 136 | int mlx5_cmd_create_flow_group(struct mlx5_core_dev *dev, |
| 137 | struct mlx5_flow_table *ft, |
| 138 | u32 *in, |
| 139 | unsigned int *group_id) |
| 140 | { |
Saeed Mahameed | c4f287c | 2016-07-19 20:17:12 +0300 | [diff] [blame] | 141 | u32 out[MLX5_ST_SZ_DW(create_flow_group_out)] = {0}; |
Maor Gottlieb | 26a8145 | 2015-12-10 17:12:39 +0200 | [diff] [blame] | 142 | int inlen = MLX5_ST_SZ_BYTES(create_flow_group_in); |
Maor Gottlieb | 26a8145 | 2015-12-10 17:12:39 +0200 | [diff] [blame] | 143 | int err; |
| 144 | |
Maor Gottlieb | 26a8145 | 2015-12-10 17:12:39 +0200 | [diff] [blame] | 145 | MLX5_SET(create_flow_group_in, in, opcode, |
| 146 | MLX5_CMD_OP_CREATE_FLOW_GROUP); |
| 147 | MLX5_SET(create_flow_group_in, in, table_type, ft->type); |
| 148 | MLX5_SET(create_flow_group_in, in, table_id, ft->id); |
Mohamad Haj Yahia | efdc810 | 2016-05-03 17:13:54 +0300 | [diff] [blame] | 149 | if (ft->vport) { |
| 150 | MLX5_SET(create_flow_group_in, in, vport_number, ft->vport); |
| 151 | MLX5_SET(create_flow_group_in, in, other_vport, 1); |
| 152 | } |
Maor Gottlieb | 26a8145 | 2015-12-10 17:12:39 +0200 | [diff] [blame] | 153 | |
Saeed Mahameed | c4f287c | 2016-07-19 20:17:12 +0300 | [diff] [blame] | 154 | err = mlx5_cmd_exec(dev, in, inlen, out, sizeof(out)); |
Maor Gottlieb | 26a8145 | 2015-12-10 17:12:39 +0200 | [diff] [blame] | 155 | if (!err) |
| 156 | *group_id = MLX5_GET(create_flow_group_out, out, |
| 157 | group_id); |
Maor Gottlieb | 26a8145 | 2015-12-10 17:12:39 +0200 | [diff] [blame] | 158 | return err; |
| 159 | } |
| 160 | |
| 161 | int mlx5_cmd_destroy_flow_group(struct mlx5_core_dev *dev, |
| 162 | struct mlx5_flow_table *ft, |
| 163 | unsigned int group_id) |
| 164 | { |
Saeed Mahameed | c4f287c | 2016-07-19 20:17:12 +0300 | [diff] [blame] | 165 | u32 out[MLX5_ST_SZ_DW(destroy_flow_group_out)] = {0}; |
| 166 | u32 in[MLX5_ST_SZ_DW(destroy_flow_group_in)] = {0}; |
Maor Gottlieb | 26a8145 | 2015-12-10 17:12:39 +0200 | [diff] [blame] | 167 | |
| 168 | MLX5_SET(destroy_flow_group_in, in, opcode, |
| 169 | MLX5_CMD_OP_DESTROY_FLOW_GROUP); |
| 170 | MLX5_SET(destroy_flow_group_in, in, table_type, ft->type); |
| 171 | MLX5_SET(destroy_flow_group_in, in, table_id, ft->id); |
| 172 | MLX5_SET(destroy_flow_group_in, in, group_id, group_id); |
Mohamad Haj Yahia | efdc810 | 2016-05-03 17:13:54 +0300 | [diff] [blame] | 173 | if (ft->vport) { |
| 174 | MLX5_SET(destroy_flow_group_in, in, vport_number, ft->vport); |
| 175 | MLX5_SET(destroy_flow_group_in, in, other_vport, 1); |
| 176 | } |
Maor Gottlieb | 26a8145 | 2015-12-10 17:12:39 +0200 | [diff] [blame] | 177 | |
Saeed Mahameed | c4f287c | 2016-07-19 20:17:12 +0300 | [diff] [blame] | 178 | return mlx5_cmd_exec(dev, in, sizeof(in), out, sizeof(out)); |
Maor Gottlieb | 26a8145 | 2015-12-10 17:12:39 +0200 | [diff] [blame] | 179 | } |
| 180 | |
| 181 | static int mlx5_cmd_set_fte(struct mlx5_core_dev *dev, |
| 182 | int opmod, int modify_mask, |
| 183 | struct mlx5_flow_table *ft, |
| 184 | unsigned group_id, |
| 185 | struct fs_fte *fte) |
| 186 | { |
| 187 | unsigned int inlen = MLX5_ST_SZ_BYTES(set_fte_in) + |
| 188 | fte->dests_size * MLX5_ST_SZ_BYTES(dest_format_struct); |
Saeed Mahameed | c4f287c | 2016-07-19 20:17:12 +0300 | [diff] [blame] | 189 | u32 out[MLX5_ST_SZ_DW(set_fte_out)] = {0}; |
Maor Gottlieb | 26a8145 | 2015-12-10 17:12:39 +0200 | [diff] [blame] | 190 | struct mlx5_flow_rule *dst; |
| 191 | void *in_flow_context; |
| 192 | void *in_match_value; |
| 193 | void *in_dests; |
| 194 | u32 *in; |
| 195 | int err; |
| 196 | |
| 197 | in = mlx5_vzalloc(inlen); |
| 198 | if (!in) { |
| 199 | mlx5_core_warn(dev, "failed to allocate inbox\n"); |
| 200 | return -ENOMEM; |
| 201 | } |
| 202 | |
| 203 | MLX5_SET(set_fte_in, in, opcode, MLX5_CMD_OP_SET_FLOW_TABLE_ENTRY); |
| 204 | MLX5_SET(set_fte_in, in, op_mod, opmod); |
| 205 | MLX5_SET(set_fte_in, in, modify_enable_mask, modify_mask); |
| 206 | MLX5_SET(set_fte_in, in, table_type, ft->type); |
| 207 | MLX5_SET(set_fte_in, in, table_id, ft->id); |
| 208 | MLX5_SET(set_fte_in, in, flow_index, fte->index); |
Mohamad Haj Yahia | efdc810 | 2016-05-03 17:13:54 +0300 | [diff] [blame] | 209 | if (ft->vport) { |
| 210 | MLX5_SET(set_fte_in, in, vport_number, ft->vport); |
| 211 | MLX5_SET(set_fte_in, in, other_vport, 1); |
| 212 | } |
Maor Gottlieb | 26a8145 | 2015-12-10 17:12:39 +0200 | [diff] [blame] | 213 | |
| 214 | in_flow_context = MLX5_ADDR_OF(set_fte_in, in, flow_context); |
| 215 | MLX5_SET(flow_context, in_flow_context, group_id, group_id); |
| 216 | MLX5_SET(flow_context, in_flow_context, flow_tag, fte->flow_tag); |
| 217 | MLX5_SET(flow_context, in_flow_context, action, fte->action); |
Maor Gottlieb | 26a8145 | 2015-12-10 17:12:39 +0200 | [diff] [blame] | 218 | in_match_value = MLX5_ADDR_OF(flow_context, in_flow_context, |
| 219 | match_value); |
| 220 | memcpy(in_match_value, &fte->val, MLX5_ST_SZ_BYTES(fte_match_param)); |
| 221 | |
Amir Vadai | bd5251db | 2016-05-13 12:55:40 +0000 | [diff] [blame] | 222 | in_dests = MLX5_ADDR_OF(flow_context, in_flow_context, destination); |
Amir Vadai | 60ab458 | 2016-03-08 12:42:33 +0200 | [diff] [blame] | 223 | if (fte->action & MLX5_FLOW_CONTEXT_ACTION_FWD_DEST) { |
Amir Vadai | bd5251db | 2016-05-13 12:55:40 +0000 | [diff] [blame] | 224 | int list_size = 0; |
| 225 | |
Amir Vadai | 60ab458 | 2016-03-08 12:42:33 +0200 | [diff] [blame] | 226 | list_for_each_entry(dst, &fte->node.children, node.list) { |
| 227 | unsigned int id; |
Maor Gottlieb | 26a8145 | 2015-12-10 17:12:39 +0200 | [diff] [blame] | 228 | |
Amir Vadai | bd5251db | 2016-05-13 12:55:40 +0000 | [diff] [blame] | 229 | if (dst->dest_attr.type == MLX5_FLOW_DESTINATION_TYPE_COUNTER) |
| 230 | continue; |
| 231 | |
Amir Vadai | 60ab458 | 2016-03-08 12:42:33 +0200 | [diff] [blame] | 232 | MLX5_SET(dest_format_struct, in_dests, destination_type, |
| 233 | dst->dest_attr.type); |
| 234 | if (dst->dest_attr.type == |
| 235 | MLX5_FLOW_DESTINATION_TYPE_FLOW_TABLE) { |
| 236 | id = dst->dest_attr.ft->id; |
| 237 | } else { |
| 238 | id = dst->dest_attr.tir_num; |
| 239 | } |
| 240 | MLX5_SET(dest_format_struct, in_dests, destination_id, id); |
| 241 | in_dests += MLX5_ST_SZ_BYTES(dest_format_struct); |
Amir Vadai | bd5251db | 2016-05-13 12:55:40 +0000 | [diff] [blame] | 242 | list_size++; |
Amir Vadai | 60ab458 | 2016-03-08 12:42:33 +0200 | [diff] [blame] | 243 | } |
Amir Vadai | bd5251db | 2016-05-13 12:55:40 +0000 | [diff] [blame] | 244 | |
| 245 | MLX5_SET(flow_context, in_flow_context, destination_list_size, |
| 246 | list_size); |
Maor Gottlieb | 26a8145 | 2015-12-10 17:12:39 +0200 | [diff] [blame] | 247 | } |
Amir Vadai | bd5251db | 2016-05-13 12:55:40 +0000 | [diff] [blame] | 248 | |
| 249 | if (fte->action & MLX5_FLOW_CONTEXT_ACTION_COUNT) { |
| 250 | int list_size = 0; |
| 251 | |
| 252 | list_for_each_entry(dst, &fte->node.children, node.list) { |
| 253 | if (dst->dest_attr.type != |
| 254 | MLX5_FLOW_DESTINATION_TYPE_COUNTER) |
| 255 | continue; |
| 256 | |
| 257 | MLX5_SET(flow_counter_list, in_dests, flow_counter_id, |
| 258 | dst->dest_attr.counter->id); |
| 259 | in_dests += MLX5_ST_SZ_BYTES(dest_format_struct); |
| 260 | list_size++; |
| 261 | } |
| 262 | |
| 263 | MLX5_SET(flow_context, in_flow_context, flow_counter_list_size, |
| 264 | list_size); |
| 265 | } |
| 266 | |
Saeed Mahameed | c4f287c | 2016-07-19 20:17:12 +0300 | [diff] [blame] | 267 | err = mlx5_cmd_exec(dev, in, inlen, out, sizeof(out)); |
Maor Gottlieb | 26a8145 | 2015-12-10 17:12:39 +0200 | [diff] [blame] | 268 | kvfree(in); |
Maor Gottlieb | 26a8145 | 2015-12-10 17:12:39 +0200 | [diff] [blame] | 269 | return err; |
| 270 | } |
| 271 | |
| 272 | int mlx5_cmd_create_fte(struct mlx5_core_dev *dev, |
| 273 | struct mlx5_flow_table *ft, |
| 274 | unsigned group_id, |
| 275 | struct fs_fte *fte) |
| 276 | { |
Saeed Mahameed | c4f287c | 2016-07-19 20:17:12 +0300 | [diff] [blame] | 277 | return mlx5_cmd_set_fte(dev, 0, 0, ft, group_id, fte); |
Maor Gottlieb | 26a8145 | 2015-12-10 17:12:39 +0200 | [diff] [blame] | 278 | } |
| 279 | |
| 280 | int mlx5_cmd_update_fte(struct mlx5_core_dev *dev, |
| 281 | struct mlx5_flow_table *ft, |
| 282 | unsigned group_id, |
Amir Vadai | bd5251db | 2016-05-13 12:55:40 +0000 | [diff] [blame] | 283 | int modify_mask, |
Maor Gottlieb | 26a8145 | 2015-12-10 17:12:39 +0200 | [diff] [blame] | 284 | struct fs_fte *fte) |
| 285 | { |
| 286 | int opmod; |
Maor Gottlieb | 26a8145 | 2015-12-10 17:12:39 +0200 | [diff] [blame] | 287 | int atomic_mod_cap = MLX5_CAP_FLOWTABLE(dev, |
| 288 | flow_table_properties_nic_receive. |
| 289 | flow_modify_en); |
| 290 | if (!atomic_mod_cap) |
| 291 | return -ENOTSUPP; |
| 292 | opmod = 1; |
Maor Gottlieb | 26a8145 | 2015-12-10 17:12:39 +0200 | [diff] [blame] | 293 | |
| 294 | return mlx5_cmd_set_fte(dev, opmod, modify_mask, ft, group_id, fte); |
| 295 | } |
| 296 | |
| 297 | int mlx5_cmd_delete_fte(struct mlx5_core_dev *dev, |
| 298 | struct mlx5_flow_table *ft, |
| 299 | unsigned int index) |
| 300 | { |
Saeed Mahameed | c4f287c | 2016-07-19 20:17:12 +0300 | [diff] [blame] | 301 | u32 out[MLX5_ST_SZ_DW(delete_fte_out)] = {0}; |
| 302 | u32 in[MLX5_ST_SZ_DW(delete_fte_in)] = {0}; |
Maor Gottlieb | 26a8145 | 2015-12-10 17:12:39 +0200 | [diff] [blame] | 303 | |
| 304 | MLX5_SET(delete_fte_in, in, opcode, MLX5_CMD_OP_DELETE_FLOW_TABLE_ENTRY); |
| 305 | MLX5_SET(delete_fte_in, in, table_type, ft->type); |
| 306 | MLX5_SET(delete_fte_in, in, table_id, ft->id); |
| 307 | MLX5_SET(delete_fte_in, in, flow_index, index); |
Mohamad Haj Yahia | efdc810 | 2016-05-03 17:13:54 +0300 | [diff] [blame] | 308 | if (ft->vport) { |
| 309 | MLX5_SET(delete_fte_in, in, vport_number, ft->vport); |
| 310 | MLX5_SET(delete_fte_in, in, other_vport, 1); |
| 311 | } |
Maor Gottlieb | 26a8145 | 2015-12-10 17:12:39 +0200 | [diff] [blame] | 312 | |
Saeed Mahameed | c4f287c | 2016-07-19 20:17:12 +0300 | [diff] [blame] | 313 | return mlx5_cmd_exec(dev, in, sizeof(in), out, sizeof(out)); |
Maor Gottlieb | 26a8145 | 2015-12-10 17:12:39 +0200 | [diff] [blame] | 314 | } |
Amir Vadai | 9dc0b28 | 2016-05-13 12:55:39 +0000 | [diff] [blame] | 315 | |
| 316 | int mlx5_cmd_fc_alloc(struct mlx5_core_dev *dev, u16 *id) |
| 317 | { |
Saeed Mahameed | c4f287c | 2016-07-19 20:17:12 +0300 | [diff] [blame] | 318 | u32 in[MLX5_ST_SZ_DW(alloc_flow_counter_in)] = {0}; |
| 319 | u32 out[MLX5_ST_SZ_DW(alloc_flow_counter_out)] = {0}; |
Amir Vadai | 9dc0b28 | 2016-05-13 12:55:39 +0000 | [diff] [blame] | 320 | int err; |
| 321 | |
Amir Vadai | 9dc0b28 | 2016-05-13 12:55:39 +0000 | [diff] [blame] | 322 | MLX5_SET(alloc_flow_counter_in, in, opcode, |
| 323 | MLX5_CMD_OP_ALLOC_FLOW_COUNTER); |
| 324 | |
Saeed Mahameed | c4f287c | 2016-07-19 20:17:12 +0300 | [diff] [blame] | 325 | err = mlx5_cmd_exec(dev, in, sizeof(in), out, sizeof(out)); |
| 326 | if (!err) |
| 327 | *id = MLX5_GET(alloc_flow_counter_out, out, flow_counter_id); |
| 328 | return err; |
Amir Vadai | 9dc0b28 | 2016-05-13 12:55:39 +0000 | [diff] [blame] | 329 | } |
| 330 | |
| 331 | int mlx5_cmd_fc_free(struct mlx5_core_dev *dev, u16 id) |
| 332 | { |
Saeed Mahameed | c4f287c | 2016-07-19 20:17:12 +0300 | [diff] [blame] | 333 | u32 in[MLX5_ST_SZ_DW(dealloc_flow_counter_in)] = {0}; |
| 334 | u32 out[MLX5_ST_SZ_DW(dealloc_flow_counter_out)] = {0}; |
Amir Vadai | 9dc0b28 | 2016-05-13 12:55:39 +0000 | [diff] [blame] | 335 | |
| 336 | MLX5_SET(dealloc_flow_counter_in, in, opcode, |
| 337 | MLX5_CMD_OP_DEALLOC_FLOW_COUNTER); |
| 338 | MLX5_SET(dealloc_flow_counter_in, in, flow_counter_id, id); |
Saeed Mahameed | c4f287c | 2016-07-19 20:17:12 +0300 | [diff] [blame] | 339 | return mlx5_cmd_exec(dev, in, sizeof(in), out, sizeof(out)); |
Amir Vadai | 9dc0b28 | 2016-05-13 12:55:39 +0000 | [diff] [blame] | 340 | } |
| 341 | |
| 342 | int mlx5_cmd_fc_query(struct mlx5_core_dev *dev, u16 id, |
| 343 | u64 *packets, u64 *bytes) |
| 344 | { |
| 345 | u32 out[MLX5_ST_SZ_BYTES(query_flow_counter_out) + |
Saeed Mahameed | c4f287c | 2016-07-19 20:17:12 +0300 | [diff] [blame] | 346 | MLX5_ST_SZ_BYTES(traffic_counter)] = {0}; |
| 347 | u32 in[MLX5_ST_SZ_DW(query_flow_counter_in)] = {0}; |
Amir Vadai | 9dc0b28 | 2016-05-13 12:55:39 +0000 | [diff] [blame] | 348 | void *stats; |
| 349 | int err = 0; |
| 350 | |
Amir Vadai | 9dc0b28 | 2016-05-13 12:55:39 +0000 | [diff] [blame] | 351 | MLX5_SET(query_flow_counter_in, in, opcode, |
| 352 | MLX5_CMD_OP_QUERY_FLOW_COUNTER); |
| 353 | MLX5_SET(query_flow_counter_in, in, op_mod, 0); |
| 354 | MLX5_SET(query_flow_counter_in, in, flow_counter_id, id); |
Saeed Mahameed | c4f287c | 2016-07-19 20:17:12 +0300 | [diff] [blame] | 355 | err = mlx5_cmd_exec(dev, in, sizeof(in), out, sizeof(out)); |
Amir Vadai | 9dc0b28 | 2016-05-13 12:55:39 +0000 | [diff] [blame] | 356 | if (err) |
| 357 | return err; |
| 358 | |
| 359 | stats = MLX5_ADDR_OF(query_flow_counter_out, out, flow_statistics); |
| 360 | *packets = MLX5_GET64(traffic_counter, stats, packets); |
| 361 | *bytes = MLX5_GET64(traffic_counter, stats, octets); |
Amir Vadai | 9dc0b28 | 2016-05-13 12:55:39 +0000 | [diff] [blame] | 362 | return 0; |
| 363 | } |
Amir Vadai | a351a1b0 | 2016-07-14 10:32:38 +0300 | [diff] [blame] | 364 | |
| 365 | struct mlx5_cmd_fc_bulk { |
| 366 | u16 id; |
| 367 | int num; |
| 368 | int outlen; |
| 369 | u32 out[0]; |
| 370 | }; |
| 371 | |
| 372 | struct mlx5_cmd_fc_bulk * |
| 373 | mlx5_cmd_fc_bulk_alloc(struct mlx5_core_dev *dev, u16 id, int num) |
| 374 | { |
| 375 | struct mlx5_cmd_fc_bulk *b; |
| 376 | int outlen = sizeof(*b) + |
| 377 | MLX5_ST_SZ_BYTES(query_flow_counter_out) + |
| 378 | MLX5_ST_SZ_BYTES(traffic_counter) * num; |
| 379 | |
| 380 | b = kzalloc(outlen, GFP_KERNEL); |
| 381 | if (!b) |
| 382 | return NULL; |
| 383 | |
| 384 | b->id = id; |
| 385 | b->num = num; |
| 386 | b->outlen = outlen; |
| 387 | |
| 388 | return b; |
| 389 | } |
| 390 | |
| 391 | void mlx5_cmd_fc_bulk_free(struct mlx5_cmd_fc_bulk *b) |
| 392 | { |
| 393 | kfree(b); |
| 394 | } |
| 395 | |
| 396 | int |
| 397 | mlx5_cmd_fc_bulk_query(struct mlx5_core_dev *dev, struct mlx5_cmd_fc_bulk *b) |
| 398 | { |
Saeed Mahameed | c4f287c | 2016-07-19 20:17:12 +0300 | [diff] [blame] | 399 | u32 in[MLX5_ST_SZ_DW(query_flow_counter_in)] = {0}; |
Amir Vadai | a351a1b0 | 2016-07-14 10:32:38 +0300 | [diff] [blame] | 400 | |
| 401 | MLX5_SET(query_flow_counter_in, in, opcode, |
| 402 | MLX5_CMD_OP_QUERY_FLOW_COUNTER); |
| 403 | MLX5_SET(query_flow_counter_in, in, op_mod, 0); |
| 404 | MLX5_SET(query_flow_counter_in, in, flow_counter_id, b->id); |
| 405 | MLX5_SET(query_flow_counter_in, in, num_of_counters, b->num); |
Saeed Mahameed | c4f287c | 2016-07-19 20:17:12 +0300 | [diff] [blame] | 406 | return mlx5_cmd_exec(dev, in, sizeof(in), b->out, b->outlen); |
Amir Vadai | a351a1b0 | 2016-07-14 10:32:38 +0300 | [diff] [blame] | 407 | } |
| 408 | |
| 409 | void mlx5_cmd_fc_bulk_get(struct mlx5_core_dev *dev, |
| 410 | struct mlx5_cmd_fc_bulk *b, u16 id, |
| 411 | u64 *packets, u64 *bytes) |
| 412 | { |
| 413 | int index = id - b->id; |
| 414 | void *stats; |
| 415 | |
| 416 | if (index < 0 || index >= b->num) { |
| 417 | mlx5_core_warn(dev, "Flow counter id (0x%x) out of range (0x%x..0x%x). Counter ignored.\n", |
| 418 | id, b->id, b->id + b->num - 1); |
| 419 | return; |
| 420 | } |
| 421 | |
| 422 | stats = MLX5_ADDR_OF(query_flow_counter_out, b->out, |
| 423 | flow_statistics[index]); |
| 424 | *packets = MLX5_GET64(traffic_counter, stats, packets); |
| 425 | *bytes = MLX5_GET64(traffic_counter, stats, octets); |
| 426 | } |