forked from ~ljy/RK356X_SDK_RELEASE

hc
2024-05-10 9999e48639b3cecb08ffb37358bcba3b48161b29
kernel/drivers/net/ethernet/mellanox/mlx5/core/fs_cmd.c
....@@ -39,7 +39,7 @@
3939 #include "mlx5_core.h"
4040 #include "eswitch.h"
4141
42
-static int mlx5_cmd_stub_update_root_ft(struct mlx5_core_dev *dev,
42
+static int mlx5_cmd_stub_update_root_ft(struct mlx5_flow_root_namespace *ns,
4343 struct mlx5_flow_table *ft,
4444 u32 underlay_qpn,
4545 bool disconnect)
....@@ -47,47 +47,43 @@
4747 return 0;
4848 }
4949
50
-static int mlx5_cmd_stub_create_flow_table(struct mlx5_core_dev *dev,
51
- u16 vport,
52
- enum fs_flow_table_op_mod op_mod,
53
- enum fs_flow_table_type type,
54
- unsigned int level,
50
+static int mlx5_cmd_stub_create_flow_table(struct mlx5_flow_root_namespace *ns,
51
+ struct mlx5_flow_table *ft,
5552 unsigned int log_size,
56
- struct mlx5_flow_table *next_ft,
57
- unsigned int *table_id, u32 flags)
53
+ struct mlx5_flow_table *next_ft)
5854 {
5955 return 0;
6056 }
6157
62
-static int mlx5_cmd_stub_destroy_flow_table(struct mlx5_core_dev *dev,
58
+static int mlx5_cmd_stub_destroy_flow_table(struct mlx5_flow_root_namespace *ns,
6359 struct mlx5_flow_table *ft)
6460 {
6561 return 0;
6662 }
6763
68
-static int mlx5_cmd_stub_modify_flow_table(struct mlx5_core_dev *dev,
64
+static int mlx5_cmd_stub_modify_flow_table(struct mlx5_flow_root_namespace *ns,
6965 struct mlx5_flow_table *ft,
7066 struct mlx5_flow_table *next_ft)
7167 {
7268 return 0;
7369 }
7470
75
-static int mlx5_cmd_stub_create_flow_group(struct mlx5_core_dev *dev,
71
+static int mlx5_cmd_stub_create_flow_group(struct mlx5_flow_root_namespace *ns,
7672 struct mlx5_flow_table *ft,
7773 u32 *in,
78
- unsigned int *group_id)
74
+ struct mlx5_flow_group *fg)
7975 {
8076 return 0;
8177 }
8278
83
-static int mlx5_cmd_stub_destroy_flow_group(struct mlx5_core_dev *dev,
79
+static int mlx5_cmd_stub_destroy_flow_group(struct mlx5_flow_root_namespace *ns,
8480 struct mlx5_flow_table *ft,
85
- unsigned int group_id)
81
+ struct mlx5_flow_group *fg)
8682 {
8783 return 0;
8884 }
8985
90
-static int mlx5_cmd_stub_create_fte(struct mlx5_core_dev *dev,
86
+static int mlx5_cmd_stub_create_fte(struct mlx5_flow_root_namespace *ns,
9187 struct mlx5_flow_table *ft,
9288 struct mlx5_flow_group *group,
9389 struct fs_fte *fte)
....@@ -95,28 +91,72 @@
9591 return 0;
9692 }
9793
98
-static int mlx5_cmd_stub_update_fte(struct mlx5_core_dev *dev,
94
+static int mlx5_cmd_stub_update_fte(struct mlx5_flow_root_namespace *ns,
9995 struct mlx5_flow_table *ft,
100
- unsigned int group_id,
96
+ struct mlx5_flow_group *group,
10197 int modify_mask,
10298 struct fs_fte *fte)
10399 {
104100 return -EOPNOTSUPP;
105101 }
106102
107
-static int mlx5_cmd_stub_delete_fte(struct mlx5_core_dev *dev,
103
+static int mlx5_cmd_stub_delete_fte(struct mlx5_flow_root_namespace *ns,
108104 struct mlx5_flow_table *ft,
109105 struct fs_fte *fte)
110106 {
111107 return 0;
112108 }
113109
114
-static int mlx5_cmd_update_root_ft(struct mlx5_core_dev *dev,
110
+static int mlx5_cmd_stub_packet_reformat_alloc(struct mlx5_flow_root_namespace *ns,
111
+ int reformat_type,
112
+ size_t size,
113
+ void *reformat_data,
114
+ enum mlx5_flow_namespace_type namespace,
115
+ struct mlx5_pkt_reformat *pkt_reformat)
116
+{
117
+ return 0;
118
+}
119
+
120
+static void mlx5_cmd_stub_packet_reformat_dealloc(struct mlx5_flow_root_namespace *ns,
121
+ struct mlx5_pkt_reformat *pkt_reformat)
122
+{
123
+}
124
+
125
+static int mlx5_cmd_stub_modify_header_alloc(struct mlx5_flow_root_namespace *ns,
126
+ u8 namespace, u8 num_actions,
127
+ void *modify_actions,
128
+ struct mlx5_modify_hdr *modify_hdr)
129
+{
130
+ return 0;
131
+}
132
+
133
+static void mlx5_cmd_stub_modify_header_dealloc(struct mlx5_flow_root_namespace *ns,
134
+ struct mlx5_modify_hdr *modify_hdr)
135
+{
136
+}
137
+
138
+static int mlx5_cmd_stub_set_peer(struct mlx5_flow_root_namespace *ns,
139
+ struct mlx5_flow_root_namespace *peer_ns)
140
+{
141
+ return 0;
142
+}
143
+
144
+static int mlx5_cmd_stub_create_ns(struct mlx5_flow_root_namespace *ns)
145
+{
146
+ return 0;
147
+}
148
+
149
+static int mlx5_cmd_stub_destroy_ns(struct mlx5_flow_root_namespace *ns)
150
+{
151
+ return 0;
152
+}
153
+
154
+static int mlx5_cmd_update_root_ft(struct mlx5_flow_root_namespace *ns,
115155 struct mlx5_flow_table *ft, u32 underlay_qpn,
116156 bool disconnect)
117157 {
118
- u32 in[MLX5_ST_SZ_DW(set_flow_table_root_in)] = {0};
119
- u32 out[MLX5_ST_SZ_DW(set_flow_table_root_out)] = {0};
158
+ u32 in[MLX5_ST_SZ_DW(set_flow_table_root_in)] = {};
159
+ struct mlx5_core_dev *dev = ns->dev;
120160
121161 if ((MLX5_CAP_GEN(dev, port_type) == MLX5_CAP_PORT_TYPE_IB) &&
122162 underlay_qpn == 0)
....@@ -126,13 +166,10 @@
126166 MLX5_CMD_OP_SET_FLOW_TABLE_ROOT);
127167 MLX5_SET(set_flow_table_root_in, in, table_type, ft->type);
128168
129
- if (disconnect) {
169
+ if (disconnect)
130170 MLX5_SET(set_flow_table_root_in, in, op_mod, 1);
131
- MLX5_SET(set_flow_table_root_in, in, table_id, 0);
132
- } else {
133
- MLX5_SET(set_flow_table_root_in, in, op_mod, 0);
171
+ else
134172 MLX5_SET(set_flow_table_root_in, in, table_id, ft->id);
135
- }
136173
137174 MLX5_SET(set_flow_table_root_in, in, underlay_qpn, underlay_qpn);
138175 if (ft->vport) {
....@@ -140,46 +177,52 @@
140177 MLX5_SET(set_flow_table_root_in, in, other_vport, 1);
141178 }
142179
143
- return mlx5_cmd_exec(dev, in, sizeof(in), out, sizeof(out));
180
+ return mlx5_cmd_exec_in(dev, set_flow_table_root, in);
144181 }
145182
146
-static int mlx5_cmd_create_flow_table(struct mlx5_core_dev *dev,
147
- u16 vport,
148
- enum fs_flow_table_op_mod op_mod,
149
- enum fs_flow_table_type type,
150
- unsigned int level,
183
+static int mlx5_cmd_create_flow_table(struct mlx5_flow_root_namespace *ns,
184
+ struct mlx5_flow_table *ft,
151185 unsigned int log_size,
152
- struct mlx5_flow_table *next_ft,
153
- unsigned int *table_id, u32 flags)
186
+ struct mlx5_flow_table *next_ft)
154187 {
155
- int en_encap_decap = !!(flags & MLX5_FLOW_TABLE_TUNNEL_EN);
156
- u32 out[MLX5_ST_SZ_DW(create_flow_table_out)] = {0};
157
- u32 in[MLX5_ST_SZ_DW(create_flow_table_in)] = {0};
188
+ int en_encap = !!(ft->flags & MLX5_FLOW_TABLE_TUNNEL_EN_REFORMAT);
189
+ int en_decap = !!(ft->flags & MLX5_FLOW_TABLE_TUNNEL_EN_DECAP);
190
+ int term = !!(ft->flags & MLX5_FLOW_TABLE_TERMINATION);
191
+ u32 out[MLX5_ST_SZ_DW(create_flow_table_out)] = {};
192
+ u32 in[MLX5_ST_SZ_DW(create_flow_table_in)] = {};
193
+ struct mlx5_core_dev *dev = ns->dev;
158194 int err;
159195
160196 MLX5_SET(create_flow_table_in, in, opcode,
161197 MLX5_CMD_OP_CREATE_FLOW_TABLE);
162198
163
- MLX5_SET(create_flow_table_in, in, table_type, type);
164
- MLX5_SET(create_flow_table_in, in, flow_table_context.level, level);
199
+ MLX5_SET(create_flow_table_in, in, table_type, ft->type);
200
+ MLX5_SET(create_flow_table_in, in, flow_table_context.level, ft->level);
165201 MLX5_SET(create_flow_table_in, in, flow_table_context.log_size, log_size);
166
- if (vport) {
167
- MLX5_SET(create_flow_table_in, in, vport_number, vport);
202
+ if (ft->vport) {
203
+ MLX5_SET(create_flow_table_in, in, vport_number, ft->vport);
168204 MLX5_SET(create_flow_table_in, in, other_vport, 1);
169205 }
170206
171207 MLX5_SET(create_flow_table_in, in, flow_table_context.decap_en,
172
- en_encap_decap);
173
- MLX5_SET(create_flow_table_in, in, flow_table_context.encap_en,
174
- en_encap_decap);
208
+ en_decap);
209
+ MLX5_SET(create_flow_table_in, in, flow_table_context.reformat_en,
210
+ en_encap);
211
+ MLX5_SET(create_flow_table_in, in, flow_table_context.termination_table,
212
+ term);
175213
176
- switch (op_mod) {
214
+ switch (ft->op_mod) {
177215 case FS_FT_OP_MOD_NORMAL:
178216 if (next_ft) {
179217 MLX5_SET(create_flow_table_in, in,
180
- flow_table_context.table_miss_action, 1);
218
+ flow_table_context.table_miss_action,
219
+ MLX5_FLOW_TABLE_MISS_ACTION_FWD);
181220 MLX5_SET(create_flow_table_in, in,
182221 flow_table_context.table_miss_id, next_ft->id);
222
+ } else {
223
+ MLX5_SET(create_flow_table_in, in,
224
+ flow_table_context.table_miss_action,
225
+ ft->def_miss_action);
183226 }
184227 break;
185228
....@@ -192,18 +235,18 @@
192235 break;
193236 }
194237
195
- err = mlx5_cmd_exec(dev, in, sizeof(in), out, sizeof(out));
238
+ err = mlx5_cmd_exec_inout(dev, create_flow_table, in, out);
196239 if (!err)
197
- *table_id = MLX5_GET(create_flow_table_out, out,
198
- table_id);
240
+ ft->id = MLX5_GET(create_flow_table_out, out,
241
+ table_id);
199242 return err;
200243 }
201244
202
-static int mlx5_cmd_destroy_flow_table(struct mlx5_core_dev *dev,
245
+static int mlx5_cmd_destroy_flow_table(struct mlx5_flow_root_namespace *ns,
203246 struct mlx5_flow_table *ft)
204247 {
205
- u32 in[MLX5_ST_SZ_DW(destroy_flow_table_in)] = {0};
206
- u32 out[MLX5_ST_SZ_DW(destroy_flow_table_out)] = {0};
248
+ u32 in[MLX5_ST_SZ_DW(destroy_flow_table_in)] = {};
249
+ struct mlx5_core_dev *dev = ns->dev;
207250
208251 MLX5_SET(destroy_flow_table_in, in, opcode,
209252 MLX5_CMD_OP_DESTROY_FLOW_TABLE);
....@@ -214,15 +257,15 @@
214257 MLX5_SET(destroy_flow_table_in, in, other_vport, 1);
215258 }
216259
217
- return mlx5_cmd_exec(dev, in, sizeof(in), out, sizeof(out));
260
+ return mlx5_cmd_exec_in(dev, destroy_flow_table, in);
218261 }
219262
220
-static int mlx5_cmd_modify_flow_table(struct mlx5_core_dev *dev,
263
+static int mlx5_cmd_modify_flow_table(struct mlx5_flow_root_namespace *ns,
221264 struct mlx5_flow_table *ft,
222265 struct mlx5_flow_table *next_ft)
223266 {
224
- u32 in[MLX5_ST_SZ_DW(modify_flow_table_in)] = {0};
225
- u32 out[MLX5_ST_SZ_DW(modify_flow_table_out)] = {0};
267
+ u32 in[MLX5_ST_SZ_DW(modify_flow_table_in)] = {};
268
+ struct mlx5_core_dev *dev = ns->dev;
226269
227270 MLX5_SET(modify_flow_table_in, in, opcode,
228271 MLX5_CMD_OP_MODIFY_FLOW_TABLE);
....@@ -249,26 +292,28 @@
249292 MLX5_MODIFY_FLOW_TABLE_MISS_TABLE_ID);
250293 if (next_ft) {
251294 MLX5_SET(modify_flow_table_in, in,
252
- flow_table_context.table_miss_action, 1);
295
+ flow_table_context.table_miss_action,
296
+ MLX5_FLOW_TABLE_MISS_ACTION_FWD);
253297 MLX5_SET(modify_flow_table_in, in,
254298 flow_table_context.table_miss_id,
255299 next_ft->id);
256300 } else {
257301 MLX5_SET(modify_flow_table_in, in,
258
- flow_table_context.table_miss_action, 0);
302
+ flow_table_context.table_miss_action,
303
+ ft->def_miss_action);
259304 }
260305 }
261306
262
- return mlx5_cmd_exec(dev, in, sizeof(in), out, sizeof(out));
307
+ return mlx5_cmd_exec_in(dev, modify_flow_table, in);
263308 }
264309
265
-static int mlx5_cmd_create_flow_group(struct mlx5_core_dev *dev,
310
+static int mlx5_cmd_create_flow_group(struct mlx5_flow_root_namespace *ns,
266311 struct mlx5_flow_table *ft,
267312 u32 *in,
268
- unsigned int *group_id)
313
+ struct mlx5_flow_group *fg)
269314 {
270
- u32 out[MLX5_ST_SZ_DW(create_flow_group_out)] = {0};
271
- int inlen = MLX5_ST_SZ_BYTES(create_flow_group_in);
315
+ u32 out[MLX5_ST_SZ_DW(create_flow_group_out)] = {};
316
+ struct mlx5_core_dev *dev = ns->dev;
272317 int err;
273318
274319 MLX5_SET(create_flow_group_in, in, opcode,
....@@ -280,49 +325,95 @@
280325 MLX5_SET(create_flow_group_in, in, other_vport, 1);
281326 }
282327
283
- err = mlx5_cmd_exec(dev, in, inlen, out, sizeof(out));
328
+ err = mlx5_cmd_exec_inout(dev, create_flow_group, in, out);
284329 if (!err)
285
- *group_id = MLX5_GET(create_flow_group_out, out,
286
- group_id);
330
+ fg->id = MLX5_GET(create_flow_group_out, out,
331
+ group_id);
287332 return err;
288333 }
289334
290
-static int mlx5_cmd_destroy_flow_group(struct mlx5_core_dev *dev,
335
+static int mlx5_cmd_destroy_flow_group(struct mlx5_flow_root_namespace *ns,
291336 struct mlx5_flow_table *ft,
292
- unsigned int group_id)
337
+ struct mlx5_flow_group *fg)
293338 {
294
- u32 out[MLX5_ST_SZ_DW(destroy_flow_group_out)] = {0};
295
- u32 in[MLX5_ST_SZ_DW(destroy_flow_group_in)] = {0};
339
+ u32 in[MLX5_ST_SZ_DW(destroy_flow_group_in)] = {};
340
+ struct mlx5_core_dev *dev = ns->dev;
296341
297342 MLX5_SET(destroy_flow_group_in, in, opcode,
298343 MLX5_CMD_OP_DESTROY_FLOW_GROUP);
299344 MLX5_SET(destroy_flow_group_in, in, table_type, ft->type);
300345 MLX5_SET(destroy_flow_group_in, in, table_id, ft->id);
301
- MLX5_SET(destroy_flow_group_in, in, group_id, group_id);
346
+ MLX5_SET(destroy_flow_group_in, in, group_id, fg->id);
302347 if (ft->vport) {
303348 MLX5_SET(destroy_flow_group_in, in, vport_number, ft->vport);
304349 MLX5_SET(destroy_flow_group_in, in, other_vport, 1);
305350 }
306351
307
- return mlx5_cmd_exec(dev, in, sizeof(in), out, sizeof(out));
352
+ return mlx5_cmd_exec_in(dev, destroy_flow_group, in);
308353 }
309354
355
+static int mlx5_set_extended_dest(struct mlx5_core_dev *dev,
356
+ struct fs_fte *fte, bool *extended_dest)
357
+{
358
+ int fw_log_max_fdb_encap_uplink =
359
+ MLX5_CAP_ESW(dev, log_max_fdb_encap_uplink);
360
+ int num_fwd_destinations = 0;
361
+ struct mlx5_flow_rule *dst;
362
+ int num_encap = 0;
363
+
364
+ *extended_dest = false;
365
+ if (!(fte->action.action & MLX5_FLOW_CONTEXT_ACTION_FWD_DEST))
366
+ return 0;
367
+
368
+ list_for_each_entry(dst, &fte->node.children, node.list) {
369
+ if (dst->dest_attr.type == MLX5_FLOW_DESTINATION_TYPE_COUNTER)
370
+ continue;
371
+ if (dst->dest_attr.type == MLX5_FLOW_DESTINATION_TYPE_VPORT &&
372
+ dst->dest_attr.vport.flags & MLX5_FLOW_DEST_VPORT_REFORMAT_ID)
373
+ num_encap++;
374
+ num_fwd_destinations++;
375
+ }
376
+ if (num_fwd_destinations > 1 && num_encap > 0)
377
+ *extended_dest = true;
378
+
379
+ if (*extended_dest && !fw_log_max_fdb_encap_uplink) {
380
+ mlx5_core_warn(dev, "FW does not support extended destination");
381
+ return -EOPNOTSUPP;
382
+ }
383
+ if (num_encap > (1 << fw_log_max_fdb_encap_uplink)) {
384
+ mlx5_core_warn(dev, "FW does not support more than %d encaps",
385
+ 1 << fw_log_max_fdb_encap_uplink);
386
+ return -EOPNOTSUPP;
387
+ }
388
+
389
+ return 0;
390
+}
310391 static int mlx5_cmd_set_fte(struct mlx5_core_dev *dev,
311392 int opmod, int modify_mask,
312393 struct mlx5_flow_table *ft,
313394 unsigned group_id,
314395 struct fs_fte *fte)
315396 {
316
- unsigned int inlen = MLX5_ST_SZ_BYTES(set_fte_in) +
317
- fte->dests_size * MLX5_ST_SZ_BYTES(dest_format_struct);
318397 u32 out[MLX5_ST_SZ_DW(set_fte_out)] = {0};
398
+ bool extended_dest = false;
319399 struct mlx5_flow_rule *dst;
320400 void *in_flow_context, *vlan;
321401 void *in_match_value;
402
+ unsigned int inlen;
403
+ int dst_cnt_size;
322404 void *in_dests;
323405 u32 *in;
324406 int err;
325407
408
+ if (mlx5_set_extended_dest(dev, fte, &extended_dest))
409
+ return -EOPNOTSUPP;
410
+
411
+ if (!extended_dest)
412
+ dst_cnt_size = MLX5_ST_SZ_BYTES(dest_format_struct);
413
+ else
414
+ dst_cnt_size = MLX5_ST_SZ_BYTES(extended_dest_format);
415
+
416
+ inlen = MLX5_ST_SZ_BYTES(set_fte_in) + fte->dests_size * dst_cnt_size;
326417 in = kvzalloc(inlen, GFP_KERNEL);
327418 if (!in)
328419 return -ENOMEM;
....@@ -333,6 +424,9 @@
333424 MLX5_SET(set_fte_in, in, table_type, ft->type);
334425 MLX5_SET(set_fte_in, in, table_id, ft->id);
335426 MLX5_SET(set_fte_in, in, flow_index, fte->index);
427
+ MLX5_SET(set_fte_in, in, ignore_flow_level,
428
+ !!(fte->action.flags & FLOW_ACT_IGNORE_FLOW_LEVEL));
429
+
336430 if (ft->vport) {
337431 MLX5_SET(set_fte_in, in, vport_number, ft->vport);
338432 MLX5_SET(set_fte_in, in, other_vport, 1);
....@@ -341,11 +435,31 @@
341435 in_flow_context = MLX5_ADDR_OF(set_fte_in, in, flow_context);
342436 MLX5_SET(flow_context, in_flow_context, group_id, group_id);
343437
344
- MLX5_SET(flow_context, in_flow_context, flow_tag, fte->action.flow_tag);
345
- MLX5_SET(flow_context, in_flow_context, action, fte->action.action);
346
- MLX5_SET(flow_context, in_flow_context, encap_id, fte->action.encap_id);
347
- MLX5_SET(flow_context, in_flow_context, modify_header_id,
348
- fte->action.modify_id);
438
+ MLX5_SET(flow_context, in_flow_context, flow_tag,
439
+ fte->flow_context.flow_tag);
440
+ MLX5_SET(flow_context, in_flow_context, flow_source,
441
+ fte->flow_context.flow_source);
442
+
443
+ MLX5_SET(flow_context, in_flow_context, extended_destination,
444
+ extended_dest);
445
+ if (extended_dest) {
446
+ u32 action;
447
+
448
+ action = fte->action.action &
449
+ ~MLX5_FLOW_CONTEXT_ACTION_PACKET_REFORMAT;
450
+ MLX5_SET(flow_context, in_flow_context, action, action);
451
+ } else {
452
+ MLX5_SET(flow_context, in_flow_context, action,
453
+ fte->action.action);
454
+ if (fte->action.pkt_reformat)
455
+ MLX5_SET(flow_context, in_flow_context, packet_reformat_id,
456
+ fte->action.pkt_reformat->id);
457
+ }
458
+ if (fte->action.modify_hdr)
459
+ MLX5_SET(flow_context, in_flow_context, modify_header_id,
460
+ fte->action.modify_hdr->id);
461
+
462
+ MLX5_SET(flow_context, in_flow_context, ipsec_obj_id, fte->action.ipsec_obj_id);
349463
350464 vlan = MLX5_ADDR_OF(flow_context, in_flow_context, push_vlan);
351465
....@@ -385,10 +499,21 @@
385499 id = dst->dest_attr.vport.num;
386500 MLX5_SET(dest_format_struct, in_dests,
387501 destination_eswitch_owner_vhca_id_valid,
388
- dst->dest_attr.vport.vhca_id_valid);
502
+ !!(dst->dest_attr.vport.flags &
503
+ MLX5_FLOW_DEST_VPORT_VHCA_ID));
389504 MLX5_SET(dest_format_struct, in_dests,
390505 destination_eswitch_owner_vhca_id,
391506 dst->dest_attr.vport.vhca_id);
507
+ if (extended_dest &&
508
+ dst->dest_attr.vport.pkt_reformat) {
509
+ MLX5_SET(dest_format_struct, in_dests,
510
+ packet_reformat,
511
+ !!(dst->dest_attr.vport.flags &
512
+ MLX5_FLOW_DEST_VPORT_REFORMAT_ID));
513
+ MLX5_SET(extended_dest_format, in_dests,
514
+ packet_reformat_id,
515
+ dst->dest_attr.vport.pkt_reformat->id);
516
+ }
392517 break;
393518 default:
394519 id = dst->dest_attr.tir_num;
....@@ -397,7 +522,7 @@
397522 MLX5_SET(dest_format_struct, in_dests, destination_type,
398523 type);
399524 MLX5_SET(dest_format_struct, in_dests, destination_id, id);
400
- in_dests += MLX5_ST_SZ_BYTES(dest_format_struct);
525
+ in_dests += dst_cnt_size;
401526 list_size++;
402527 }
403528
....@@ -417,8 +542,8 @@
417542 continue;
418543
419544 MLX5_SET(flow_counter_list, in_dests, flow_counter_id,
420
- dst->dest_attr.counter->id);
421
- in_dests += MLX5_ST_SZ_BYTES(dest_format_struct);
545
+ dst->dest_attr.counter_id);
546
+ in_dests += dst_cnt_size;
422547 list_size++;
423548 }
424549 if (list_size > max_list_size) {
....@@ -436,23 +561,25 @@
436561 return err;
437562 }
438563
439
-static int mlx5_cmd_create_fte(struct mlx5_core_dev *dev,
564
+static int mlx5_cmd_create_fte(struct mlx5_flow_root_namespace *ns,
440565 struct mlx5_flow_table *ft,
441566 struct mlx5_flow_group *group,
442567 struct fs_fte *fte)
443568 {
569
+ struct mlx5_core_dev *dev = ns->dev;
444570 unsigned int group_id = group->id;
445571
446572 return mlx5_cmd_set_fte(dev, 0, 0, ft, group_id, fte);
447573 }
448574
449
-static int mlx5_cmd_update_fte(struct mlx5_core_dev *dev,
575
+static int mlx5_cmd_update_fte(struct mlx5_flow_root_namespace *ns,
450576 struct mlx5_flow_table *ft,
451
- unsigned int group_id,
577
+ struct mlx5_flow_group *fg,
452578 int modify_mask,
453579 struct fs_fte *fte)
454580 {
455581 int opmod;
582
+ struct mlx5_core_dev *dev = ns->dev;
456583 int atomic_mod_cap = MLX5_CAP_FLOWTABLE(dev,
457584 flow_table_properties_nic_receive.
458585 flow_modify_en);
....@@ -460,15 +587,15 @@
460587 return -EOPNOTSUPP;
461588 opmod = 1;
462589
463
- return mlx5_cmd_set_fte(dev, opmod, modify_mask, ft, group_id, fte);
590
+ return mlx5_cmd_set_fte(dev, opmod, modify_mask, ft, fg->id, fte);
464591 }
465592
466
-static int mlx5_cmd_delete_fte(struct mlx5_core_dev *dev,
593
+static int mlx5_cmd_delete_fte(struct mlx5_flow_root_namespace *ns,
467594 struct mlx5_flow_table *ft,
468595 struct fs_fte *fte)
469596 {
470
- u32 out[MLX5_ST_SZ_DW(delete_fte_out)] = {0};
471
- u32 in[MLX5_ST_SZ_DW(delete_fte_in)] = {0};
597
+ u32 in[MLX5_ST_SZ_DW(delete_fte_in)] = {};
598
+ struct mlx5_core_dev *dev = ns->dev;
472599
473600 MLX5_SET(delete_fte_in, in, opcode, MLX5_CMD_OP_DELETE_FLOW_TABLE_ENTRY);
474601 MLX5_SET(delete_fte_in, in, table_type, ft->type);
....@@ -479,41 +606,48 @@
479606 MLX5_SET(delete_fte_in, in, other_vport, 1);
480607 }
481608
482
- return mlx5_cmd_exec(dev, in, sizeof(in), out, sizeof(out));
609
+ return mlx5_cmd_exec_in(dev, delete_fte, in);
483610 }
484611
485
-int mlx5_cmd_fc_alloc(struct mlx5_core_dev *dev, u32 *id)
612
+int mlx5_cmd_fc_bulk_alloc(struct mlx5_core_dev *dev,
613
+ enum mlx5_fc_bulk_alloc_bitmask alloc_bitmask,
614
+ u32 *id)
486615 {
487
- u32 in[MLX5_ST_SZ_DW(alloc_flow_counter_in)] = {0};
488
- u32 out[MLX5_ST_SZ_DW(alloc_flow_counter_out)] = {0};
616
+ u32 out[MLX5_ST_SZ_DW(alloc_flow_counter_out)] = {};
617
+ u32 in[MLX5_ST_SZ_DW(alloc_flow_counter_in)] = {};
489618 int err;
490619
491620 MLX5_SET(alloc_flow_counter_in, in, opcode,
492621 MLX5_CMD_OP_ALLOC_FLOW_COUNTER);
622
+ MLX5_SET(alloc_flow_counter_in, in, flow_counter_bulk, alloc_bitmask);
493623
494
- err = mlx5_cmd_exec(dev, in, sizeof(in), out, sizeof(out));
624
+ err = mlx5_cmd_exec_inout(dev, alloc_flow_counter, in, out);
495625 if (!err)
496626 *id = MLX5_GET(alloc_flow_counter_out, out, flow_counter_id);
497627 return err;
498628 }
499629
630
+int mlx5_cmd_fc_alloc(struct mlx5_core_dev *dev, u32 *id)
631
+{
632
+ return mlx5_cmd_fc_bulk_alloc(dev, 0, id);
633
+}
634
+
500635 int mlx5_cmd_fc_free(struct mlx5_core_dev *dev, u32 id)
501636 {
502
- u32 in[MLX5_ST_SZ_DW(dealloc_flow_counter_in)] = {0};
503
- u32 out[MLX5_ST_SZ_DW(dealloc_flow_counter_out)] = {0};
637
+ u32 in[MLX5_ST_SZ_DW(dealloc_flow_counter_in)] = {};
504638
505639 MLX5_SET(dealloc_flow_counter_in, in, opcode,
506640 MLX5_CMD_OP_DEALLOC_FLOW_COUNTER);
507641 MLX5_SET(dealloc_flow_counter_in, in, flow_counter_id, id);
508
- return mlx5_cmd_exec(dev, in, sizeof(in), out, sizeof(out));
642
+ return mlx5_cmd_exec_in(dev, dealloc_flow_counter, in);
509643 }
510644
511645 int mlx5_cmd_fc_query(struct mlx5_core_dev *dev, u32 id,
512646 u64 *packets, u64 *bytes)
513647 {
514648 u32 out[MLX5_ST_SZ_BYTES(query_flow_counter_out) +
515
- MLX5_ST_SZ_BYTES(traffic_counter)] = {0};
516
- u32 in[MLX5_ST_SZ_DW(query_flow_counter_in)] = {0};
649
+ MLX5_ST_SZ_BYTES(traffic_counter)] = {};
650
+ u32 in[MLX5_ST_SZ_DW(query_flow_counter_in)] = {};
517651 void *stats;
518652 int err = 0;
519653
....@@ -531,82 +665,45 @@
531665 return 0;
532666 }
533667
534
-struct mlx5_cmd_fc_bulk {
535
- u32 id;
536
- int num;
537
- int outlen;
538
- u32 out[0];
539
-};
540
-
541
-struct mlx5_cmd_fc_bulk *
542
-mlx5_cmd_fc_bulk_alloc(struct mlx5_core_dev *dev, u32 id, int num)
668
+int mlx5_cmd_fc_get_bulk_query_out_len(int bulk_len)
543669 {
544
- struct mlx5_cmd_fc_bulk *b;
545
- int outlen =
546
- MLX5_ST_SZ_BYTES(query_flow_counter_out) +
547
- MLX5_ST_SZ_BYTES(traffic_counter) * num;
548
-
549
- b = kzalloc(sizeof(*b) + outlen, GFP_KERNEL);
550
- if (!b)
551
- return NULL;
552
-
553
- b->id = id;
554
- b->num = num;
555
- b->outlen = outlen;
556
-
557
- return b;
670
+ return MLX5_ST_SZ_BYTES(query_flow_counter_out) +
671
+ MLX5_ST_SZ_BYTES(traffic_counter) * bulk_len;
558672 }
559673
560
-void mlx5_cmd_fc_bulk_free(struct mlx5_cmd_fc_bulk *b)
674
+int mlx5_cmd_fc_bulk_query(struct mlx5_core_dev *dev, u32 base_id, int bulk_len,
675
+ u32 *out)
561676 {
562
- kfree(b);
563
-}
564
-
565
-int
566
-mlx5_cmd_fc_bulk_query(struct mlx5_core_dev *dev, struct mlx5_cmd_fc_bulk *b)
567
-{
568
- u32 in[MLX5_ST_SZ_DW(query_flow_counter_in)] = {0};
677
+ int outlen = mlx5_cmd_fc_get_bulk_query_out_len(bulk_len);
678
+ u32 in[MLX5_ST_SZ_DW(query_flow_counter_in)] = {};
569679
570680 MLX5_SET(query_flow_counter_in, in, opcode,
571681 MLX5_CMD_OP_QUERY_FLOW_COUNTER);
572
- MLX5_SET(query_flow_counter_in, in, op_mod, 0);
573
- MLX5_SET(query_flow_counter_in, in, flow_counter_id, b->id);
574
- MLX5_SET(query_flow_counter_in, in, num_of_counters, b->num);
575
- return mlx5_cmd_exec(dev, in, sizeof(in), b->out, b->outlen);
682
+ MLX5_SET(query_flow_counter_in, in, flow_counter_id, base_id);
683
+ MLX5_SET(query_flow_counter_in, in, num_of_counters, bulk_len);
684
+ return mlx5_cmd_exec(dev, in, sizeof(in), out, outlen);
576685 }
577686
578
-void mlx5_cmd_fc_bulk_get(struct mlx5_core_dev *dev,
579
- struct mlx5_cmd_fc_bulk *b, u32 id,
580
- u64 *packets, u64 *bytes)
687
+static int mlx5_cmd_packet_reformat_alloc(struct mlx5_flow_root_namespace *ns,
688
+ int reformat_type,
689
+ size_t size,
690
+ void *reformat_data,
691
+ enum mlx5_flow_namespace_type namespace,
692
+ struct mlx5_pkt_reformat *pkt_reformat)
581693 {
582
- int index = id - b->id;
583
- void *stats;
584
-
585
- if (index < 0 || index >= b->num) {
586
- mlx5_core_warn(dev, "Flow counter id (0x%x) out of range (0x%x..0x%x). Counter ignored.\n",
587
- id, b->id, b->id + b->num - 1);
588
- return;
589
- }
590
-
591
- stats = MLX5_ADDR_OF(query_flow_counter_out, b->out,
592
- flow_statistics[index]);
593
- *packets = MLX5_GET64(traffic_counter, stats, packets);
594
- *bytes = MLX5_GET64(traffic_counter, stats, octets);
595
-}
596
-
597
-int mlx5_encap_alloc(struct mlx5_core_dev *dev,
598
- int header_type,
599
- size_t size,
600
- void *encap_header,
601
- u32 *encap_id)
602
-{
603
- int max_encap_size = MLX5_CAP_ESW(dev, max_encap_header_size);
604
- u32 out[MLX5_ST_SZ_DW(alloc_encap_header_out)];
605
- void *encap_header_in;
606
- void *header;
694
+ u32 out[MLX5_ST_SZ_DW(alloc_packet_reformat_context_out)] = {};
695
+ struct mlx5_core_dev *dev = ns->dev;
696
+ void *packet_reformat_context_in;
697
+ int max_encap_size;
698
+ void *reformat;
607699 int inlen;
608700 int err;
609701 u32 *in;
702
+
703
+ if (namespace == MLX5_FLOW_NAMESPACE_FDB)
704
+ max_encap_size = MLX5_CAP_ESW(dev, max_encap_header_size);
705
+ else
706
+ max_encap_size = MLX5_CAP_FLOWTABLE(dev, max_encap_header_size);
610707
611708 if (size > max_encap_size) {
612709 mlx5_core_warn(dev, "encap size %zd too big, max supported is %d\n",
....@@ -614,49 +711,56 @@
614711 return -EINVAL;
615712 }
616713
617
- in = kzalloc(MLX5_ST_SZ_BYTES(alloc_encap_header_in) + size,
714
+ in = kzalloc(MLX5_ST_SZ_BYTES(alloc_packet_reformat_context_in) + size,
618715 GFP_KERNEL);
619716 if (!in)
620717 return -ENOMEM;
621718
622
- encap_header_in = MLX5_ADDR_OF(alloc_encap_header_in, in, encap_header);
623
- header = MLX5_ADDR_OF(encap_header_in, encap_header_in, encap_header);
624
- inlen = header - (void *)in + size;
719
+ packet_reformat_context_in = MLX5_ADDR_OF(alloc_packet_reformat_context_in,
720
+ in, packet_reformat_context);
721
+ reformat = MLX5_ADDR_OF(packet_reformat_context_in,
722
+ packet_reformat_context_in,
723
+ reformat_data);
724
+ inlen = reformat - (void *)in + size;
625725
626
- memset(in, 0, inlen);
627
- MLX5_SET(alloc_encap_header_in, in, opcode,
628
- MLX5_CMD_OP_ALLOC_ENCAP_HEADER);
629
- MLX5_SET(encap_header_in, encap_header_in, encap_header_size, size);
630
- MLX5_SET(encap_header_in, encap_header_in, header_type, header_type);
631
- memcpy(header, encap_header, size);
726
+ MLX5_SET(alloc_packet_reformat_context_in, in, opcode,
727
+ MLX5_CMD_OP_ALLOC_PACKET_REFORMAT_CONTEXT);
728
+ MLX5_SET(packet_reformat_context_in, packet_reformat_context_in,
729
+ reformat_data_size, size);
730
+ MLX5_SET(packet_reformat_context_in, packet_reformat_context_in,
731
+ reformat_type, reformat_type);
732
+ memcpy(reformat, reformat_data, size);
632733
633
- memset(out, 0, sizeof(out));
634734 err = mlx5_cmd_exec(dev, in, inlen, out, sizeof(out));
635735
636
- *encap_id = MLX5_GET(alloc_encap_header_out, out, encap_id);
736
+ pkt_reformat->id = MLX5_GET(alloc_packet_reformat_context_out,
737
+ out, packet_reformat_id);
637738 kfree(in);
638739 return err;
639740 }
640741
641
-void mlx5_encap_dealloc(struct mlx5_core_dev *dev, u32 encap_id)
742
+static void mlx5_cmd_packet_reformat_dealloc(struct mlx5_flow_root_namespace *ns,
743
+ struct mlx5_pkt_reformat *pkt_reformat)
642744 {
643
- u32 in[MLX5_ST_SZ_DW(dealloc_encap_header_in)];
644
- u32 out[MLX5_ST_SZ_DW(dealloc_encap_header_out)];
745
+ u32 in[MLX5_ST_SZ_DW(dealloc_packet_reformat_context_in)] = {};
746
+ struct mlx5_core_dev *dev = ns->dev;
645747
646
- memset(in, 0, sizeof(in));
647
- MLX5_SET(dealloc_encap_header_in, in, opcode,
648
- MLX5_CMD_OP_DEALLOC_ENCAP_HEADER);
649
- MLX5_SET(dealloc_encap_header_in, in, encap_id, encap_id);
748
+ MLX5_SET(dealloc_packet_reformat_context_in, in, opcode,
749
+ MLX5_CMD_OP_DEALLOC_PACKET_REFORMAT_CONTEXT);
750
+ MLX5_SET(dealloc_packet_reformat_context_in, in, packet_reformat_id,
751
+ pkt_reformat->id);
650752
651
- mlx5_cmd_exec(dev, in, sizeof(in), out, sizeof(out));
753
+ mlx5_cmd_exec_in(dev, dealloc_packet_reformat_context, in);
652754 }
653755
654
-int mlx5_modify_header_alloc(struct mlx5_core_dev *dev,
655
- u8 namespace, u8 num_actions,
656
- void *modify_actions, u32 *modify_header_id)
756
+static int mlx5_cmd_modify_header_alloc(struct mlx5_flow_root_namespace *ns,
757
+ u8 namespace, u8 num_actions,
758
+ void *modify_actions,
759
+ struct mlx5_modify_hdr *modify_hdr)
657760 {
658
- u32 out[MLX5_ST_SZ_DW(alloc_modify_header_context_out)];
761
+ u32 out[MLX5_ST_SZ_DW(alloc_modify_header_context_out)] = {};
659762 int max_actions, actions_size, inlen, err;
763
+ struct mlx5_core_dev *dev = ns->dev;
660764 void *actions_in;
661765 u8 table_type;
662766 u32 *in;
....@@ -667,8 +771,24 @@
667771 table_type = FS_FT_FDB;
668772 break;
669773 case MLX5_FLOW_NAMESPACE_KERNEL:
774
+ case MLX5_FLOW_NAMESPACE_BYPASS:
670775 max_actions = MLX5_CAP_FLOWTABLE_NIC_RX(dev, max_modify_header_actions);
671776 table_type = FS_FT_NIC_RX;
777
+ break;
778
+ case MLX5_FLOW_NAMESPACE_EGRESS:
779
+#ifdef CONFIG_MLX5_IPSEC
780
+ case MLX5_FLOW_NAMESPACE_EGRESS_KERNEL:
781
+#endif
782
+ max_actions = MLX5_CAP_FLOWTABLE_NIC_TX(dev, max_modify_header_actions);
783
+ table_type = FS_FT_NIC_TX;
784
+ break;
785
+ case MLX5_FLOW_NAMESPACE_ESW_INGRESS:
786
+ max_actions = MLX5_CAP_ESW_INGRESS_ACL(dev, max_modify_header_actions);
787
+ table_type = FS_FT_ESW_INGRESS_ACL;
788
+ break;
789
+ case MLX5_FLOW_NAMESPACE_RDMA_TX:
790
+ max_actions = MLX5_CAP_FLOWTABLE_RDMA_TX(dev, max_modify_header_actions);
791
+ table_type = FS_FT_RDMA_TX;
672792 break;
673793 default:
674794 return -EOPNOTSUPP;
....@@ -680,7 +800,7 @@
680800 return -EOPNOTSUPP;
681801 }
682802
683
- actions_size = MLX5_UN_SZ_BYTES(set_action_in_add_action_in_auto) * num_actions;
803
+ actions_size = MLX5_UN_SZ_BYTES(set_add_copy_action_in_auto) * num_actions;
684804 inlen = MLX5_ST_SZ_BYTES(alloc_modify_header_context_in) + actions_size;
685805
686806 in = kzalloc(inlen, GFP_KERNEL);
....@@ -695,26 +815,25 @@
695815 actions_in = MLX5_ADDR_OF(alloc_modify_header_context_in, in, actions);
696816 memcpy(actions_in, modify_actions, actions_size);
697817
698
- memset(out, 0, sizeof(out));
699818 err = mlx5_cmd_exec(dev, in, inlen, out, sizeof(out));
700819
701
- *modify_header_id = MLX5_GET(alloc_modify_header_context_out, out, modify_header_id);
820
+ modify_hdr->id = MLX5_GET(alloc_modify_header_context_out, out, modify_header_id);
702821 kfree(in);
703822 return err;
704823 }
705824
706
-void mlx5_modify_header_dealloc(struct mlx5_core_dev *dev, u32 modify_header_id)
825
+static void mlx5_cmd_modify_header_dealloc(struct mlx5_flow_root_namespace *ns,
826
+ struct mlx5_modify_hdr *modify_hdr)
707827 {
708
- u32 in[MLX5_ST_SZ_DW(dealloc_modify_header_context_in)];
709
- u32 out[MLX5_ST_SZ_DW(dealloc_modify_header_context_out)];
828
+ u32 in[MLX5_ST_SZ_DW(dealloc_modify_header_context_in)] = {};
829
+ struct mlx5_core_dev *dev = ns->dev;
710830
711
- memset(in, 0, sizeof(in));
712831 MLX5_SET(dealloc_modify_header_context_in, in, opcode,
713832 MLX5_CMD_OP_DEALLOC_MODIFY_HEADER_CONTEXT);
714833 MLX5_SET(dealloc_modify_header_context_in, in, modify_header_id,
715
- modify_header_id);
834
+ modify_hdr->id);
716835
717
- mlx5_cmd_exec(dev, in, sizeof(in), out, sizeof(out));
836
+ mlx5_cmd_exec_in(dev, dealloc_modify_header_context, in);
718837 }
719838
720839 static const struct mlx5_flow_cmds mlx5_flow_cmds = {
....@@ -727,6 +846,13 @@
727846 .update_fte = mlx5_cmd_update_fte,
728847 .delete_fte = mlx5_cmd_delete_fte,
729848 .update_root_ft = mlx5_cmd_update_root_ft,
849
+ .packet_reformat_alloc = mlx5_cmd_packet_reformat_alloc,
850
+ .packet_reformat_dealloc = mlx5_cmd_packet_reformat_dealloc,
851
+ .modify_header_alloc = mlx5_cmd_modify_header_alloc,
852
+ .modify_header_dealloc = mlx5_cmd_modify_header_dealloc,
853
+ .set_peer = mlx5_cmd_stub_set_peer,
854
+ .create_ns = mlx5_cmd_stub_create_ns,
855
+ .destroy_ns = mlx5_cmd_stub_destroy_ns,
730856 };
731857
732858 static const struct mlx5_flow_cmds mlx5_flow_cmd_stubs = {
....@@ -739,9 +865,16 @@
739865 .update_fte = mlx5_cmd_stub_update_fte,
740866 .delete_fte = mlx5_cmd_stub_delete_fte,
741867 .update_root_ft = mlx5_cmd_stub_update_root_ft,
868
+ .packet_reformat_alloc = mlx5_cmd_stub_packet_reformat_alloc,
869
+ .packet_reformat_dealloc = mlx5_cmd_stub_packet_reformat_dealloc,
870
+ .modify_header_alloc = mlx5_cmd_stub_modify_header_alloc,
871
+ .modify_header_dealloc = mlx5_cmd_stub_modify_header_dealloc,
872
+ .set_peer = mlx5_cmd_stub_set_peer,
873
+ .create_ns = mlx5_cmd_stub_create_ns,
874
+ .destroy_ns = mlx5_cmd_stub_destroy_ns,
742875 };
743876
744
-static const struct mlx5_flow_cmds *mlx5_fs_cmd_get_fw_cmds(void)
877
+const struct mlx5_flow_cmds *mlx5_fs_cmd_get_fw_cmds(void)
745878 {
746879 return &mlx5_flow_cmds;
747880 }
....@@ -760,8 +893,10 @@
760893 case FS_FT_FDB:
761894 case FS_FT_SNIFFER_RX:
762895 case FS_FT_SNIFFER_TX:
763
- return mlx5_fs_cmd_get_fw_cmds();
764896 case FS_FT_NIC_TX:
897
+ case FS_FT_RDMA_RX:
898
+ case FS_FT_RDMA_TX:
899
+ return mlx5_fs_cmd_get_fw_cmds();
765900 default:
766901 return mlx5_fs_cmd_get_stub_cmds();
767902 }