1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
|
// SPDX-License-Identifier: GPL-2.0 OR Linux-OpenIB
/* Copyright (c) 2024 NVIDIA Corporation & Affiliates */
#include "internal.h"
enum mlx5hws_matcher_rtc_type {
HWS_MATCHER_RTC_TYPE_MATCH,
HWS_MATCHER_RTC_TYPE_STE_ARRAY,
HWS_MATCHER_RTC_TYPE_MAX,
};
static const char * const mlx5hws_matcher_rtc_type_str[] = {
[HWS_MATCHER_RTC_TYPE_MATCH] = "MATCH",
[HWS_MATCHER_RTC_TYPE_STE_ARRAY] = "STE_ARRAY",
[HWS_MATCHER_RTC_TYPE_MAX] = "UNKNOWN",
};
static const char *hws_matcher_rtc_type_to_str(enum mlx5hws_matcher_rtc_type rtc_type)
{
if (rtc_type > HWS_MATCHER_RTC_TYPE_MAX)
rtc_type = HWS_MATCHER_RTC_TYPE_MAX;
return mlx5hws_matcher_rtc_type_str[rtc_type];
}
static bool hws_matcher_requires_col_tbl(u8 log_num_of_rules)
{
/* Collision table concatenation is done only for large rule tables */
return log_num_of_rules > MLX5HWS_MATCHER_ASSURED_RULES_TH;
}
static u8 hws_matcher_rules_to_tbl_depth(u8 log_num_of_rules)
{
if (hws_matcher_requires_col_tbl(log_num_of_rules))
return MLX5HWS_MATCHER_ASSURED_MAIN_TBL_DEPTH;
/* For small rule tables we use a single deep table to assure insertion */
return min(log_num_of_rules, MLX5HWS_MATCHER_ASSURED_COL_TBL_DEPTH);
}
static void hws_matcher_destroy_end_ft(struct mlx5hws_matcher *matcher)
{
mlx5hws_table_destroy_default_ft(matcher->tbl, matcher->end_ft_id);
}
static int hws_matcher_create_end_ft(struct mlx5hws_matcher *matcher)
{
struct mlx5hws_table *tbl = matcher->tbl;
int ret;
ret = mlx5hws_table_create_default_ft(tbl->ctx->mdev, tbl, &matcher->end_ft_id);
if (ret) {
mlx5hws_err(tbl->ctx, "Failed to create matcher end flow table\n");
return ret;
}
return 0;
}
static int hws_matcher_connect(struct mlx5hws_matcher *matcher)
{
struct mlx5hws_table *tbl = matcher->tbl;
struct mlx5hws_context *ctx = tbl->ctx;
struct mlx5hws_matcher *prev = NULL;
struct mlx5hws_matcher *next = NULL;
struct mlx5hws_matcher *tmp_matcher;
int ret;
/* Find location in matcher list */
if (list_empty(&tbl->matchers_list)) {
list_add(&matcher->list_node, &tbl->matchers_list);
goto connect;
}
list_for_each_entry(tmp_matcher, &tbl->matchers_list, list_node) {
if (tmp_matcher->attr.priority > matcher->attr.priority) {
next = tmp_matcher;
break;
}
prev = tmp_matcher;
}
if (next)
/* insert before next */
list_add_tail(&matcher->list_node, &next->list_node);
else
/* insert after prev */
list_add(&matcher->list_node, &prev->list_node);
connect:
if (next) {
/* Connect to next RTC */
ret = mlx5hws_table_ft_set_next_rtc(ctx,
matcher->end_ft_id,
tbl->fw_ft_type,
next->match_ste.rtc_0_id,
next->match_ste.rtc_1_id);
if (ret) {
mlx5hws_err(ctx, "Failed to connect new matcher to next RTC\n");
goto remove_from_list;
}
} else {
/* Connect last matcher to next miss_tbl if exists */
ret = mlx5hws_table_connect_to_miss_table(tbl, tbl->default_miss.miss_tbl);
if (ret) {
mlx5hws_err(ctx, "Failed connect new matcher to miss_tbl\n");
goto remove_from_list;
}
}
/* Connect to previous FT */
ret = mlx5hws_table_ft_set_next_rtc(ctx,
prev ? prev->end_ft_id : tbl->ft_id,
tbl->fw_ft_type,
matcher->match_ste.rtc_0_id,
matcher->match_ste.rtc_1_id);
if (ret) {
mlx5hws_err(ctx, "Failed to connect new matcher to previous FT\n");
goto remove_from_list;
}
/* Reset prev matcher FT default miss (drop refcount) */
ret = mlx5hws_table_ft_set_default_next_ft(tbl, prev ? prev->end_ft_id : tbl->ft_id);
if (ret) {
mlx5hws_err(ctx, "Failed to reset matcher ft default miss\n");
goto remove_from_list;
}
if (!prev) {
/* Update tables missing to current matcher in the table */
ret = mlx5hws_table_update_connected_miss_tables(tbl);
if (ret) {
mlx5hws_err(ctx, "Fatal error, failed to update connected miss table\n");
goto remove_from_list;
}
}
return 0;
remove_from_list:
list_del_init(&matcher->list_node);
return ret;
}
static int hws_matcher_disconnect(struct mlx5hws_matcher *matcher)
{
struct mlx5hws_matcher *next = NULL, *prev = NULL;
struct mlx5hws_table *tbl = matcher->tbl;
u32 prev_ft_id = tbl->ft_id;
int ret;
if (!list_is_first(&matcher->list_node, &tbl->matchers_list)) {
prev = list_prev_entry(matcher, list_node);
prev_ft_id = prev->end_ft_id;
}
if (!list_is_last(&matcher->list_node, &tbl->matchers_list))
next = list_next_entry(matcher, list_node);
list_del_init(&matcher->list_node);
if (next) {
/* Connect previous end FT to next RTC */
ret = mlx5hws_table_ft_set_next_rtc(tbl->ctx,
prev_ft_id,
tbl->fw_ft_type,
next->match_ste.rtc_0_id,
next->match_ste.rtc_1_id);
if (ret) {
mlx5hws_err(tbl->ctx, "Failed to disconnect matcher\n");
goto matcher_reconnect;
}
} else {
ret = mlx5hws_table_connect_to_miss_table(tbl, tbl->default_miss.miss_tbl);
if (ret) {
mlx5hws_err(tbl->ctx, "Failed to disconnect last matcher\n");
goto matcher_reconnect;
}
}
/* Removing first matcher, update connected miss tables if exists */
if (prev_ft_id == tbl->ft_id) {
ret = mlx5hws_table_update_connected_miss_tables(tbl);
if (ret) {
mlx5hws_err(tbl->ctx, "Fatal error, failed to update connected miss table\n");
goto matcher_reconnect;
}
}
ret = mlx5hws_table_ft_set_default_next_ft(tbl, prev_ft_id);
if (ret) {
mlx5hws_err(tbl->ctx, "Fatal error, failed to restore matcher ft default miss\n");
goto matcher_reconnect;
}
return 0;
matcher_reconnect:
if (list_empty(&tbl->matchers_list) || !prev)
list_add(&matcher->list_node, &tbl->matchers_list);
else
/* insert after prev matcher */
list_add(&matcher->list_node, &prev->list_node);
return ret;
}
static void hws_matcher_set_rtc_attr_sz(struct mlx5hws_matcher *matcher,
struct mlx5hws_cmd_rtc_create_attr *rtc_attr,
enum mlx5hws_matcher_rtc_type rtc_type,
bool is_mirror)
{
struct mlx5hws_pool_chunk *ste = &matcher->action_ste[MLX5HWS_ACTION_STE_IDX_ANY].ste;
enum mlx5hws_matcher_flow_src flow_src = matcher->attr.optimize_flow_src;
bool is_match_rtc = rtc_type == HWS_MATCHER_RTC_TYPE_MATCH;
if ((flow_src == MLX5HWS_MATCHER_FLOW_SRC_VPORT && !is_mirror) ||
(flow_src == MLX5HWS_MATCHER_FLOW_SRC_WIRE && is_mirror)) {
/* Optimize FDB RTC */
rtc_attr->log_size = 0;
rtc_attr->log_depth = 0;
} else {
/* Keep original values */
rtc_attr->log_size = is_match_rtc ? matcher->attr.table.sz_row_log : ste->order;
rtc_attr->log_depth = is_match_rtc ? matcher->attr.table.sz_col_log : 0;
}
}
static int hws_matcher_create_rtc(struct mlx5hws_matcher *matcher,
enum mlx5hws_matcher_rtc_type rtc_type,
u8 action_ste_selector)
{
struct mlx5hws_matcher_attr *attr = &matcher->attr;
struct mlx5hws_cmd_rtc_create_attr rtc_attr = {0};
struct mlx5hws_match_template *mt = matcher->mt;
struct mlx5hws_context *ctx = matcher->tbl->ctx;
struct mlx5hws_action_default_stc *default_stc;
struct mlx5hws_matcher_action_ste *action_ste;
struct mlx5hws_table *tbl = matcher->tbl;
struct mlx5hws_pool *ste_pool, *stc_pool;
struct mlx5hws_pool_chunk *ste;
u32 *rtc_0_id, *rtc_1_id;
u32 obj_id;
int ret;
switch (rtc_type) {
case HWS_MATCHER_RTC_TYPE_MATCH:
rtc_0_id = &matcher->match_ste.rtc_0_id;
rtc_1_id = &matcher->match_ste.rtc_1_id;
ste_pool = matcher->match_ste.pool;
ste = &matcher->match_ste.ste;
ste->order = attr->table.sz_col_log + attr->table.sz_row_log;
rtc_attr.log_size = attr->table.sz_row_log;
rtc_attr.log_depth = attr->table.sz_col_log;
rtc_attr.is_frst_jumbo = mlx5hws_matcher_mt_is_jumbo(mt);
rtc_attr.is_scnd_range = 0;
rtc_attr.miss_ft_id = matcher->end_ft_id;
if (attr->insert_mode == MLX5HWS_MATCHER_INSERT_BY_HASH) {
/* The usual Hash Table */
rtc_attr.update_index_mode = MLX5_IFC_RTC_STE_UPDATE_MODE_BY_HASH;
/* The first mt is used since all share the same definer */
rtc_attr.match_definer_0 = mlx5hws_definer_get_id(mt->definer);
} else if (attr->insert_mode == MLX5HWS_MATCHER_INSERT_BY_INDEX) {
rtc_attr.update_index_mode = MLX5_IFC_RTC_STE_UPDATE_MODE_BY_OFFSET;
rtc_attr.num_hash_definer = 1;
if (attr->distribute_mode == MLX5HWS_MATCHER_DISTRIBUTE_BY_HASH) {
/* Hash Split Table */
rtc_attr.access_index_mode = MLX5_IFC_RTC_STE_ACCESS_MODE_BY_HASH;
rtc_attr.match_definer_0 = mlx5hws_definer_get_id(mt->definer);
} else if (attr->distribute_mode == MLX5HWS_MATCHER_DISTRIBUTE_BY_LINEAR) {
/* Linear Lookup Table */
rtc_attr.access_index_mode = MLX5_IFC_RTC_STE_ACCESS_MODE_LINEAR;
rtc_attr.match_definer_0 = ctx->caps->linear_match_definer;
}
}
/* Match pool requires implicit allocation */
ret = mlx5hws_pool_chunk_alloc(ste_pool, ste);
if (ret) {
mlx5hws_err(ctx, "Failed to allocate STE for %s RTC",
hws_matcher_rtc_type_to_str(rtc_type));
return ret;
}
break;
case HWS_MATCHER_RTC_TYPE_STE_ARRAY:
action_ste = &matcher->action_ste[action_ste_selector];
rtc_0_id = &action_ste->rtc_0_id;
rtc_1_id = &action_ste->rtc_1_id;
ste_pool = action_ste->pool;
ste = &action_ste->ste;
ste->order = ilog2(roundup_pow_of_two(action_ste->max_stes)) +
attr->table.sz_row_log;
rtc_attr.log_size = ste->order;
rtc_attr.log_depth = 0;
rtc_attr.update_index_mode = MLX5_IFC_RTC_STE_UPDATE_MODE_BY_OFFSET;
/* The action STEs use the default always hit definer */
rtc_attr.match_definer_0 = ctx->caps->trivial_match_definer;
rtc_attr.is_frst_jumbo = false;
rtc_attr.miss_ft_id = 0;
break;
default:
mlx5hws_err(ctx, "HWS Invalid RTC type\n");
return -EINVAL;
}
obj_id = mlx5hws_pool_chunk_get_base_id(ste_pool, ste);
rtc_attr.pd = ctx->pd_num;
rtc_attr.ste_base = obj_id;
rtc_attr.ste_offset = ste->offset;
rtc_attr.reparse_mode = mlx5hws_context_get_reparse_mode(ctx);
rtc_attr.table_type = mlx5hws_table_get_res_fw_ft_type(tbl->type, false);
hws_matcher_set_rtc_attr_sz(matcher, &rtc_attr, rtc_type, false);
/* STC is a single resource (obj_id), use any STC for the ID */
stc_pool = ctx->stc_pool[tbl->type];
default_stc = ctx->common_res[tbl->type].default_stc;
obj_id = mlx5hws_pool_chunk_get_base_id(stc_pool, &default_stc->default_hit);
rtc_attr.stc_base = obj_id;
ret = mlx5hws_cmd_rtc_create(ctx->mdev, &rtc_attr, rtc_0_id);
if (ret) {
mlx5hws_err(ctx, "Failed to create matcher RTC of type %s",
hws_matcher_rtc_type_to_str(rtc_type));
goto free_ste;
}
if (tbl->type == MLX5HWS_TABLE_TYPE_FDB) {
obj_id = mlx5hws_pool_chunk_get_base_mirror_id(ste_pool, ste);
rtc_attr.ste_base = obj_id;
rtc_attr.table_type = mlx5hws_table_get_res_fw_ft_type(tbl->type, true);
obj_id = mlx5hws_pool_chunk_get_base_mirror_id(stc_pool, &default_stc->default_hit);
rtc_attr.stc_base = obj_id;
hws_matcher_set_rtc_attr_sz(matcher, &rtc_attr, rtc_type, true);
ret = mlx5hws_cmd_rtc_create(ctx->mdev, &rtc_attr, rtc_1_id);
if (ret) {
mlx5hws_err(ctx, "Failed to create peer matcher RTC of type %s",
hws_matcher_rtc_type_to_str(rtc_type));
goto destroy_rtc_0;
}
}
return 0;
destroy_rtc_0:
mlx5hws_cmd_rtc_destroy(ctx->mdev, *rtc_0_id);
free_ste:
if (rtc_type == HWS_MATCHER_RTC_TYPE_MATCH)
mlx5hws_pool_chunk_free(ste_pool, ste);
return ret;
}
static void hws_matcher_destroy_rtc(struct mlx5hws_matcher *matcher,
enum mlx5hws_matcher_rtc_type rtc_type,
u8 action_ste_selector)
{
struct mlx5hws_matcher_action_ste *action_ste;
struct mlx5hws_table *tbl = matcher->tbl;
struct mlx5hws_pool_chunk *ste;
struct mlx5hws_pool *ste_pool;
u32 rtc_0_id, rtc_1_id;
switch (rtc_type) {
case HWS_MATCHER_RTC_TYPE_MATCH:
rtc_0_id = matcher->match_ste.rtc_0_id;
rtc_1_id = matcher->match_ste.rtc_1_id;
ste_pool = matcher->match_ste.pool;
ste = &matcher->match_ste.ste;
break;
case HWS_MATCHER_RTC_TYPE_STE_ARRAY:
action_ste = &matcher->action_ste[action_ste_selector];
rtc_0_id = action_ste->rtc_0_id;
rtc_1_id = action_ste->rtc_1_id;
ste_pool = action_ste->pool;
ste = &action_ste->ste;
break;
default:
return;
}
if (tbl->type == MLX5HWS_TABLE_TYPE_FDB)
mlx5hws_cmd_rtc_destroy(matcher->tbl->ctx->mdev, rtc_1_id);
mlx5hws_cmd_rtc_destroy(matcher->tbl->ctx->mdev, rtc_0_id);
if (rtc_type == HWS_MATCHER_RTC_TYPE_MATCH)
mlx5hws_pool_chunk_free(ste_pool, ste);
}
static int
hws_matcher_check_attr_sz(struct mlx5hws_cmd_query_caps *caps,
struct mlx5hws_matcher *matcher)
{
struct mlx5hws_matcher_attr *attr = &matcher->attr;
if (attr->table.sz_col_log > caps->rtc_log_depth_max) {
mlx5hws_err(matcher->tbl->ctx, "Matcher depth exceeds limit %d\n",
caps->rtc_log_depth_max);
return -EOPNOTSUPP;
}
if (attr->table.sz_col_log + attr->table.sz_row_log > caps->ste_alloc_log_max) {
mlx5hws_err(matcher->tbl->ctx, "Total matcher size exceeds limit %d\n",
caps->ste_alloc_log_max);
return -EOPNOTSUPP;
}
if (attr->table.sz_col_log + attr->table.sz_row_log < caps->ste_alloc_log_gran) {
mlx5hws_err(matcher->tbl->ctx, "Total matcher size below limit %d\n",
caps->ste_alloc_log_gran);
return -EOPNOTSUPP;
}
return 0;
}
static void hws_matcher_set_pool_attr(struct mlx5hws_pool_attr *attr,
struct mlx5hws_matcher *matcher)
{
switch (matcher->attr.optimize_flow_src) {
case MLX5HWS_MATCHER_FLOW_SRC_VPORT:
attr->opt_type = MLX5HWS_POOL_OPTIMIZE_ORIG;
break;
case MLX5HWS_MATCHER_FLOW_SRC_WIRE:
attr->opt_type = MLX5HWS_POOL_OPTIMIZE_MIRROR;
break;
default:
break;
}
}
static int hws_matcher_check_and_process_at(struct mlx5hws_matcher *matcher,
struct mlx5hws_action_template *at)
{
struct mlx5hws_context *ctx = matcher->tbl->ctx;
bool valid;
int ret;
valid = mlx5hws_action_check_combo(ctx, at->action_type_arr, matcher->tbl->type);
if (!valid) {
mlx5hws_err(ctx, "Invalid combination in action template\n");
return -EINVAL;
}
/* Process action template to setters */
ret = mlx5hws_action_template_process(at);
if (ret) {
mlx5hws_err(ctx, "Failed to process action template\n");
return ret;
}
return 0;
}
static int hws_matcher_resize_init(struct mlx5hws_matcher *src_matcher)
{
struct mlx5hws_matcher_resize_data *resize_data;
resize_data = kzalloc(sizeof(*resize_data), GFP_KERNEL);
if (!resize_data)
return -ENOMEM;
resize_data->max_stes = src_matcher->action_ste[MLX5HWS_ACTION_STE_IDX_ANY].max_stes;
resize_data->action_ste[0].stc = src_matcher->action_ste[0].stc;
resize_data->action_ste[0].rtc_0_id = src_matcher->action_ste[0].rtc_0_id;
resize_data->action_ste[0].rtc_1_id = src_matcher->action_ste[0].rtc_1_id;
resize_data->action_ste[0].pool = src_matcher->action_ste[0].max_stes ?
src_matcher->action_ste[0].pool :
NULL;
resize_data->action_ste[1].stc = src_matcher->action_ste[1].stc;
resize_data->action_ste[1].rtc_0_id = src_matcher->action_ste[1].rtc_0_id;
resize_data->action_ste[1].rtc_1_id = src_matcher->action_ste[1].rtc_1_id;
resize_data->action_ste[1].pool = src_matcher->action_ste[1].max_stes ?
src_matcher->action_ste[1].pool :
NULL;
/* Place the new resized matcher on the dst matcher's list */
list_add(&resize_data->list_node, &src_matcher->resize_dst->resize_data);
/* Move all the previous resized matchers to the dst matcher's list */
while (!list_empty(&src_matcher->resize_data)) {
resize_data = list_first_entry(&src_matcher->resize_data,
struct mlx5hws_matcher_resize_data,
list_node);
list_del_init(&resize_data->list_node);
list_add(&resize_data->list_node, &src_matcher->resize_dst->resize_data);
}
return 0;
}
static void hws_matcher_resize_uninit(struct mlx5hws_matcher *matcher)
{
struct mlx5hws_matcher_resize_data *resize_data;
if (!mlx5hws_matcher_is_resizable(matcher))
return;
while (!list_empty(&matcher->resize_data)) {
resize_data = list_first_entry(&matcher->resize_data,
struct mlx5hws_matcher_resize_data,
list_node);
list_del_init(&resize_data->list_node);
if (resize_data->max_stes) {
mlx5hws_action_free_single_stc(matcher->tbl->ctx,
matcher->tbl->type,
&resize_data->action_ste[1].stc);
mlx5hws_action_free_single_stc(matcher->tbl->ctx,
matcher->tbl->type,
&resize_data->action_ste[0].stc);
if (matcher->tbl->type == MLX5HWS_TABLE_TYPE_FDB) {
mlx5hws_cmd_rtc_destroy(matcher->tbl->ctx->mdev,
resize_data->action_ste[1].rtc_1_id);
mlx5hws_cmd_rtc_destroy(matcher->tbl->ctx->mdev,
resize_data->action_ste[0].rtc_1_id);
}
mlx5hws_cmd_rtc_destroy(matcher->tbl->ctx->mdev,
resize_data->action_ste[1].rtc_0_id);
mlx5hws_cmd_rtc_destroy(matcher->tbl->ctx->mdev,
resize_data->action_ste[0].rtc_0_id);
if (resize_data->action_ste[MLX5HWS_ACTION_STE_IDX_ANY].pool) {
mlx5hws_pool_destroy(resize_data->action_ste[1].pool);
mlx5hws_pool_destroy(resize_data->action_ste[0].pool);
}
}
kfree(resize_data);
}
}
static int
hws_matcher_bind_at_idx(struct mlx5hws_matcher *matcher, u8 action_ste_selector)
{
struct mlx5hws_cmd_stc_modify_attr stc_attr = {0};
struct mlx5hws_matcher_action_ste *action_ste;
struct mlx5hws_table *tbl = matcher->tbl;
struct mlx5hws_pool_attr pool_attr = {0};
struct mlx5hws_context *ctx = tbl->ctx;
int ret;
action_ste = &matcher->action_ste[action_ste_selector];
/* Allocate action STE mempool */
pool_attr.table_type = tbl->type;
pool_attr.pool_type = MLX5HWS_POOL_TYPE_STE;
pool_attr.flags = MLX5HWS_POOL_FLAGS_FOR_STE_ACTION_POOL;
pool_attr.alloc_log_sz = ilog2(roundup_pow_of_two(action_ste->max_stes)) +
matcher->attr.table.sz_row_log;
hws_matcher_set_pool_attr(&pool_attr, matcher);
action_ste->pool = mlx5hws_pool_create(ctx, &pool_attr);
if (!action_ste->pool) {
mlx5hws_err(ctx, "Failed to create action ste pool\n");
return -EINVAL;
}
/* Allocate action RTC */
ret = hws_matcher_create_rtc(matcher, HWS_MATCHER_RTC_TYPE_STE_ARRAY, action_ste_selector);
if (ret) {
mlx5hws_err(ctx, "Failed to create action RTC\n");
goto free_ste_pool;
}
/* Allocate STC for jumps to STE */
stc_attr.action_offset = MLX5HWS_ACTION_OFFSET_HIT;
stc_attr.action_type = MLX5_IFC_STC_ACTION_TYPE_JUMP_TO_STE_TABLE;
stc_attr.reparse_mode = MLX5_IFC_STC_REPARSE_IGNORE;
stc_attr.ste_table.ste = action_ste->ste;
stc_attr.ste_table.ste_pool = action_ste->pool;
stc_attr.ste_table.match_definer_id = ctx->caps->trivial_match_definer;
ret = mlx5hws_action_alloc_single_stc(ctx, &stc_attr, tbl->type,
&action_ste->stc);
if (ret) {
mlx5hws_err(ctx, "Failed to create action jump to table STC\n");
goto free_rtc;
}
return 0;
free_rtc:
hws_matcher_destroy_rtc(matcher, HWS_MATCHER_RTC_TYPE_STE_ARRAY, action_ste_selector);
free_ste_pool:
mlx5hws_pool_destroy(action_ste->pool);
return ret;
}
static void hws_matcher_unbind_at_idx(struct mlx5hws_matcher *matcher, u8 action_ste_selector)
{
struct mlx5hws_matcher_action_ste *action_ste;
struct mlx5hws_table *tbl = matcher->tbl;
action_ste = &matcher->action_ste[action_ste_selector];
if (!action_ste->max_stes ||
matcher->flags & MLX5HWS_MATCHER_FLAGS_COLLISION ||
mlx5hws_matcher_is_in_resize(matcher))
return;
mlx5hws_action_free_single_stc(tbl->ctx, tbl->type, &action_ste->stc);
hws_matcher_destroy_rtc(matcher, HWS_MATCHER_RTC_TYPE_STE_ARRAY, action_ste_selector);
mlx5hws_pool_destroy(action_ste->pool);
}
static int hws_matcher_bind_at(struct mlx5hws_matcher *matcher)
{
bool is_jumbo = mlx5hws_matcher_mt_is_jumbo(matcher->mt);
struct mlx5hws_table *tbl = matcher->tbl;
struct mlx5hws_context *ctx = tbl->ctx;
u32 required_stes;
u8 max_stes = 0;
int i, ret;
if (matcher->flags & MLX5HWS_MATCHER_FLAGS_COLLISION)
return 0;
for (i = 0; i < matcher->num_of_at; i++) {
struct mlx5hws_action_template *at = &matcher->at[i];
ret = hws_matcher_check_and_process_at(matcher, at);
if (ret) {
mlx5hws_err(ctx, "Invalid at %d", i);
return ret;
}
required_stes = at->num_of_action_stes - (!is_jumbo || at->only_term);
max_stes = max(max_stes, required_stes);
/* Future: Optimize reparse */
}
/* There are no additional STEs required for matcher */
if (!max_stes)
return 0;
matcher->action_ste[0].max_stes = max_stes;
matcher->action_ste[1].max_stes = max_stes;
ret = hws_matcher_bind_at_idx(matcher, 0);
if (ret)
return ret;
ret = hws_matcher_bind_at_idx(matcher, 1);
if (ret)
goto free_at_0;
return 0;
free_at_0:
hws_matcher_unbind_at_idx(matcher, 0);
return ret;
}
static void hws_matcher_unbind_at(struct mlx5hws_matcher *matcher)
{
hws_matcher_unbind_at_idx(matcher, 1);
hws_matcher_unbind_at_idx(matcher, 0);
}
static int hws_matcher_bind_mt(struct mlx5hws_matcher *matcher)
{
struct mlx5hws_context *ctx = matcher->tbl->ctx;
struct mlx5hws_pool_attr pool_attr = {0};
int ret;
/* Calculate match, range and hash definers */
if (!(matcher->flags & MLX5HWS_MATCHER_FLAGS_COLLISION)) {
ret = mlx5hws_definer_mt_init(ctx, matcher->mt);
if (ret) {
if (ret == -E2BIG)
mlx5hws_err(ctx, "Failed to set matcher templates with match definers\n");
return ret;
}
}
/* Create an STE pool per matcher*/
pool_attr.table_type = matcher->tbl->type;
pool_attr.pool_type = MLX5HWS_POOL_TYPE_STE;
pool_attr.flags = MLX5HWS_POOL_FLAGS_FOR_MATCHER_STE_POOL;
pool_attr.alloc_log_sz = matcher->attr.table.sz_col_log +
matcher->attr.table.sz_row_log;
hws_matcher_set_pool_attr(&pool_attr, matcher);
matcher->match_ste.pool = mlx5hws_pool_create(ctx, &pool_attr);
if (!matcher->match_ste.pool) {
mlx5hws_err(ctx, "Failed to allocate matcher STE pool\n");
ret = -EOPNOTSUPP;
goto uninit_match_definer;
}
return 0;
uninit_match_definer:
if (!(matcher->flags & MLX5HWS_MATCHER_FLAGS_COLLISION))
mlx5hws_definer_mt_uninit(ctx, matcher->mt);
return ret;
}
static void hws_matcher_unbind_mt(struct mlx5hws_matcher *matcher)
{
mlx5hws_pool_destroy(matcher->match_ste.pool);
if (!(matcher->flags & MLX5HWS_MATCHER_FLAGS_COLLISION))
mlx5hws_definer_mt_uninit(matcher->tbl->ctx, matcher->mt);
}
static int
hws_matcher_validate_insert_mode(struct mlx5hws_cmd_query_caps *caps,
struct mlx5hws_matcher *matcher)
{
struct mlx5hws_matcher_attr *attr = &matcher->attr;
struct mlx5hws_context *ctx = matcher->tbl->ctx;
switch (attr->insert_mode) {
case MLX5HWS_MATCHER_INSERT_BY_HASH:
if (matcher->attr.distribute_mode != MLX5HWS_MATCHER_DISTRIBUTE_BY_HASH) {
mlx5hws_err(ctx, "Invalid matcher distribute mode\n");
return -EOPNOTSUPP;
}
break;
case MLX5HWS_MATCHER_INSERT_BY_INDEX:
if (attr->table.sz_col_log) {
mlx5hws_err(ctx, "Matcher with INSERT_BY_INDEX supports only Nx1 table size\n");
return -EOPNOTSUPP;
}
if (attr->distribute_mode == MLX5HWS_MATCHER_DISTRIBUTE_BY_HASH) {
/* Hash Split Table */
if (!caps->rtc_hash_split_table) {
mlx5hws_err(ctx, "FW doesn't support insert by index and hash distribute\n");
return -EOPNOTSUPP;
}
} else if (attr->distribute_mode == MLX5HWS_MATCHER_DISTRIBUTE_BY_LINEAR) {
/* Linear Lookup Table */
if (!caps->rtc_linear_lookup_table ||
!IS_BIT_SET(caps->access_index_mode,
MLX5_IFC_RTC_STE_ACCESS_MODE_LINEAR)) {
mlx5hws_err(ctx, "FW doesn't support insert by index and linear distribute\n");
return -EOPNOTSUPP;
}
if (attr->table.sz_row_log > MLX5_IFC_RTC_LINEAR_LOOKUP_TBL_LOG_MAX) {
mlx5hws_err(ctx, "Matcher with linear distribute: rows exceed limit %d",
MLX5_IFC_RTC_LINEAR_LOOKUP_TBL_LOG_MAX);
return -EOPNOTSUPP;
}
} else {
mlx5hws_err(ctx, "Matcher has unsupported distribute mode\n");
return -EOPNOTSUPP;
}
break;
default:
mlx5hws_err(ctx, "Matcher has unsupported insert mode\n");
return -EOPNOTSUPP;
}
return 0;
}
static int
hws_matcher_process_attr(struct mlx5hws_cmd_query_caps *caps,
struct mlx5hws_matcher *matcher)
{
struct mlx5hws_matcher_attr *attr = &matcher->attr;
if (hws_matcher_validate_insert_mode(caps, matcher))
return -EOPNOTSUPP;
if (matcher->tbl->type != MLX5HWS_TABLE_TYPE_FDB && attr->optimize_flow_src) {
mlx5hws_err(matcher->tbl->ctx, "NIC domain doesn't support flow_src\n");
return -EOPNOTSUPP;
}
/* Convert number of rules to the required depth */
if (attr->mode == MLX5HWS_MATCHER_RESOURCE_MODE_RULE &&
attr->insert_mode == MLX5HWS_MATCHER_INSERT_BY_HASH)
attr->table.sz_col_log = hws_matcher_rules_to_tbl_depth(attr->rule.num_log);
matcher->flags |= attr->resizable ? MLX5HWS_MATCHER_FLAGS_RESIZABLE : 0;
return hws_matcher_check_attr_sz(caps, matcher);
}
static int hws_matcher_create_and_connect(struct mlx5hws_matcher *matcher)
{
int ret;
/* Select and create the definers for current matcher */
ret = hws_matcher_bind_mt(matcher);
if (ret)
return ret;
/* Calculate and verify action combination */
ret = hws_matcher_bind_at(matcher);
if (ret)
goto unbind_mt;
/* Create matcher end flow table anchor */
ret = hws_matcher_create_end_ft(matcher);
if (ret)
goto unbind_at;
/* Allocate the RTC for the new matcher */
ret = hws_matcher_create_rtc(matcher, HWS_MATCHER_RTC_TYPE_MATCH, 0);
if (ret)
goto destroy_end_ft;
/* Connect the matcher to the matcher list */
ret = hws_matcher_connect(matcher);
if (ret)
goto destroy_rtc;
return 0;
destroy_rtc:
hws_matcher_destroy_rtc(matcher, HWS_MATCHER_RTC_TYPE_MATCH, 0);
destroy_end_ft:
hws_matcher_destroy_end_ft(matcher);
unbind_at:
hws_matcher_unbind_at(matcher);
unbind_mt:
hws_matcher_unbind_mt(matcher);
return ret;
}
static void hws_matcher_destroy_and_disconnect(struct mlx5hws_matcher *matcher)
{
hws_matcher_resize_uninit(matcher);
hws_matcher_disconnect(matcher);
hws_matcher_destroy_rtc(matcher, HWS_MATCHER_RTC_TYPE_MATCH, 0);
hws_matcher_destroy_end_ft(matcher);
hws_matcher_unbind_at(matcher);
hws_matcher_unbind_mt(matcher);
}
static int
hws_matcher_create_col_matcher(struct mlx5hws_matcher *matcher)
{
struct mlx5hws_context *ctx = matcher->tbl->ctx;
struct mlx5hws_matcher *col_matcher;
int ret;
if (matcher->attr.mode != MLX5HWS_MATCHER_RESOURCE_MODE_RULE ||
matcher->attr.insert_mode == MLX5HWS_MATCHER_INSERT_BY_INDEX)
return 0;
if (!hws_matcher_requires_col_tbl(matcher->attr.rule.num_log))
return 0;
col_matcher = kzalloc(sizeof(*matcher), GFP_KERNEL);
if (!col_matcher)
return -ENOMEM;
INIT_LIST_HEAD(&col_matcher->resize_data);
col_matcher->tbl = matcher->tbl;
col_matcher->mt = matcher->mt;
col_matcher->at = matcher->at;
col_matcher->num_of_at = matcher->num_of_at;
col_matcher->num_of_mt = matcher->num_of_mt;
col_matcher->attr.priority = matcher->attr.priority;
col_matcher->flags = matcher->flags;
col_matcher->flags |= MLX5HWS_MATCHER_FLAGS_COLLISION;
col_matcher->attr.mode = MLX5HWS_MATCHER_RESOURCE_MODE_HTABLE;
col_matcher->attr.optimize_flow_src = matcher->attr.optimize_flow_src;
col_matcher->attr.table.sz_row_log = matcher->attr.rule.num_log;
col_matcher->attr.table.sz_col_log = MLX5HWS_MATCHER_ASSURED_COL_TBL_DEPTH;
if (col_matcher->attr.table.sz_row_log > MLX5HWS_MATCHER_ASSURED_ROW_RATIO)
col_matcher->attr.table.sz_row_log -= MLX5HWS_MATCHER_ASSURED_ROW_RATIO;
col_matcher->attr.max_num_of_at_attach = matcher->attr.max_num_of_at_attach;
ret = hws_matcher_process_attr(ctx->caps, col_matcher);
if (ret)
goto free_col_matcher;
ret = hws_matcher_create_and_connect(col_matcher);
if (ret)
goto free_col_matcher;
matcher->col_matcher = col_matcher;
return 0;
free_col_matcher:
kfree(col_matcher);
mlx5hws_err(ctx, "Failed to create assured collision matcher\n");
return ret;
}
static void
hws_matcher_destroy_col_matcher(struct mlx5hws_matcher *matcher)
{
if (matcher->attr.mode != MLX5HWS_MATCHER_RESOURCE_MODE_RULE ||
matcher->attr.insert_mode == MLX5HWS_MATCHER_INSERT_BY_INDEX)
return;
if (matcher->col_matcher) {
hws_matcher_destroy_and_disconnect(matcher->col_matcher);
kfree(matcher->col_matcher);
}
}
static int hws_matcher_init(struct mlx5hws_matcher *matcher)
{
struct mlx5hws_context *ctx = matcher->tbl->ctx;
int ret;
INIT_LIST_HEAD(&matcher->resize_data);
mutex_lock(&ctx->ctrl_lock);
/* Allocate matcher resource and connect to the packet pipe */
ret = hws_matcher_create_and_connect(matcher);
if (ret)
goto unlock_err;
/* Create additional matcher for collision handling */
ret = hws_matcher_create_col_matcher(matcher);
if (ret)
goto destory_and_disconnect;
mutex_unlock(&ctx->ctrl_lock);
return 0;
destory_and_disconnect:
hws_matcher_destroy_and_disconnect(matcher);
unlock_err:
mutex_unlock(&ctx->ctrl_lock);
return ret;
}
static int hws_matcher_uninit(struct mlx5hws_matcher *matcher)
{
struct mlx5hws_context *ctx = matcher->tbl->ctx;
mutex_lock(&ctx->ctrl_lock);
hws_matcher_destroy_col_matcher(matcher);
hws_matcher_destroy_and_disconnect(matcher);
mutex_unlock(&ctx->ctrl_lock);
return 0;
}
int mlx5hws_matcher_attach_at(struct mlx5hws_matcher *matcher,
struct mlx5hws_action_template *at)
{
bool is_jumbo = mlx5hws_matcher_mt_is_jumbo(matcher->mt);
struct mlx5hws_context *ctx = matcher->tbl->ctx;
u32 required_stes;
int ret;
if (!matcher->attr.max_num_of_at_attach) {
mlx5hws_dbg(ctx, "Num of current at (%d) exceed allowed value\n",
matcher->num_of_at);
return -EOPNOTSUPP;
}
ret = hws_matcher_check_and_process_at(matcher, at);
if (ret)
return ret;
required_stes = at->num_of_action_stes - (!is_jumbo || at->only_term);
if (matcher->action_ste[MLX5HWS_ACTION_STE_IDX_ANY].max_stes < required_stes) {
mlx5hws_dbg(ctx, "Required STEs [%d] exceeds initial action template STE [%d]\n",
required_stes,
matcher->action_ste[MLX5HWS_ACTION_STE_IDX_ANY].max_stes);
return -ENOMEM;
}
matcher->at[matcher->num_of_at] = *at;
matcher->num_of_at += 1;
matcher->attr.max_num_of_at_attach -= 1;
if (matcher->col_matcher)
matcher->col_matcher->num_of_at = matcher->num_of_at;
return 0;
}
static int
hws_matcher_set_templates(struct mlx5hws_matcher *matcher,
struct mlx5hws_match_template *mt[],
u8 num_of_mt,
struct mlx5hws_action_template *at[],
u8 num_of_at)
{
struct mlx5hws_context *ctx = matcher->tbl->ctx;
int ret = 0;
int i;
if (!num_of_mt || !num_of_at) {
mlx5hws_err(ctx, "Number of action/match template cannot be zero\n");
return -EOPNOTSUPP;
}
matcher->mt = kcalloc(num_of_mt, sizeof(*matcher->mt), GFP_KERNEL);
if (!matcher->mt)
return -ENOMEM;
matcher->at = kcalloc(num_of_at + matcher->attr.max_num_of_at_attach,
sizeof(*matcher->at),
GFP_KERNEL);
if (!matcher->at) {
mlx5hws_err(ctx, "Failed to allocate action template array\n");
ret = -ENOMEM;
goto free_mt;
}
for (i = 0; i < num_of_mt; i++)
matcher->mt[i] = *mt[i];
for (i = 0; i < num_of_at; i++)
matcher->at[i] = *at[i];
matcher->num_of_mt = num_of_mt;
matcher->num_of_at = num_of_at;
return 0;
free_mt:
kfree(matcher->mt);
return ret;
}
static void
hws_matcher_unset_templates(struct mlx5hws_matcher *matcher)
{
kfree(matcher->at);
kfree(matcher->mt);
}
struct mlx5hws_matcher *
mlx5hws_matcher_create(struct mlx5hws_table *tbl,
struct mlx5hws_match_template *mt[],
u8 num_of_mt,
struct mlx5hws_action_template *at[],
u8 num_of_at,
struct mlx5hws_matcher_attr *attr)
{
struct mlx5hws_context *ctx = tbl->ctx;
struct mlx5hws_matcher *matcher;
int ret;
matcher = kzalloc(sizeof(*matcher), GFP_KERNEL);
if (!matcher)
return NULL;
matcher->tbl = tbl;
matcher->attr = *attr;
ret = hws_matcher_process_attr(tbl->ctx->caps, matcher);
if (ret)
goto free_matcher;
ret = hws_matcher_set_templates(matcher, mt, num_of_mt, at, num_of_at);
if (ret)
goto free_matcher;
ret = hws_matcher_init(matcher);
if (ret) {
mlx5hws_err(ctx, "Failed to initialise matcher: %d\n", ret);
goto unset_templates;
}
return matcher;
unset_templates:
hws_matcher_unset_templates(matcher);
free_matcher:
kfree(matcher);
return NULL;
}
int mlx5hws_matcher_destroy(struct mlx5hws_matcher *matcher)
{
hws_matcher_uninit(matcher);
hws_matcher_unset_templates(matcher);
kfree(matcher);
return 0;
}
struct mlx5hws_match_template *
mlx5hws_match_template_create(struct mlx5hws_context *ctx,
u32 *match_param,
u32 match_param_sz,
u8 match_criteria_enable)
{
struct mlx5hws_match_template *mt;
mt = kzalloc(sizeof(*mt), GFP_KERNEL);
if (!mt)
return NULL;
mt->match_param = kzalloc(MLX5_ST_SZ_BYTES(fte_match_param), GFP_KERNEL);
if (!mt->match_param)
goto free_template;
memcpy(mt->match_param, match_param, match_param_sz);
mt->match_criteria_enable = match_criteria_enable;
return mt;
free_template:
kfree(mt);
return NULL;
}
int mlx5hws_match_template_destroy(struct mlx5hws_match_template *mt)
{
kfree(mt->match_param);
kfree(mt);
return 0;
}
static int hws_matcher_resize_precheck(struct mlx5hws_matcher *src_matcher,
struct mlx5hws_matcher *dst_matcher)
{
struct mlx5hws_context *ctx = src_matcher->tbl->ctx;
int i;
if (src_matcher->tbl->type != dst_matcher->tbl->type) {
mlx5hws_err(ctx, "Table type mismatch for src/dst matchers\n");
return -EINVAL;
}
if (!mlx5hws_matcher_is_resizable(src_matcher) ||
!mlx5hws_matcher_is_resizable(dst_matcher)) {
mlx5hws_err(ctx, "Src/dst matcher is not resizable\n");
return -EINVAL;
}
if (mlx5hws_matcher_is_insert_by_idx(src_matcher) !=
mlx5hws_matcher_is_insert_by_idx(dst_matcher)) {
mlx5hws_err(ctx, "Src/dst matchers insert mode mismatch\n");
return -EINVAL;
}
if (mlx5hws_matcher_is_in_resize(src_matcher) ||
mlx5hws_matcher_is_in_resize(dst_matcher)) {
mlx5hws_err(ctx, "Src/dst matcher is already in resize\n");
return -EINVAL;
}
/* Compare match templates - make sure the definers are equivalent */
if (src_matcher->num_of_mt != dst_matcher->num_of_mt) {
mlx5hws_err(ctx, "Src/dst matcher match templates mismatch\n");
return -EINVAL;
}
if (src_matcher->action_ste[MLX5HWS_ACTION_STE_IDX_ANY].max_stes >
dst_matcher->action_ste[0].max_stes) {
mlx5hws_err(ctx, "Src/dst matcher max STEs mismatch\n");
return -EINVAL;
}
for (i = 0; i < src_matcher->num_of_mt; i++) {
if (mlx5hws_definer_compare(src_matcher->mt[i].definer,
dst_matcher->mt[i].definer)) {
mlx5hws_err(ctx, "Src/dst matcher definers mismatch\n");
return -EINVAL;
}
}
return 0;
}
int mlx5hws_matcher_resize_set_target(struct mlx5hws_matcher *src_matcher,
struct mlx5hws_matcher *dst_matcher)
{
int ret = 0;
mutex_lock(&src_matcher->tbl->ctx->ctrl_lock);
ret = hws_matcher_resize_precheck(src_matcher, dst_matcher);
if (ret)
goto out;
src_matcher->resize_dst = dst_matcher;
ret = hws_matcher_resize_init(src_matcher);
if (ret)
src_matcher->resize_dst = NULL;
out:
mutex_unlock(&src_matcher->tbl->ctx->ctrl_lock);
return ret;
}
int mlx5hws_matcher_resize_rule_move(struct mlx5hws_matcher *src_matcher,
struct mlx5hws_rule *rule,
struct mlx5hws_rule_attr *attr)
{
struct mlx5hws_context *ctx = src_matcher->tbl->ctx;
if (unlikely(!mlx5hws_matcher_is_in_resize(src_matcher))) {
mlx5hws_err(ctx, "Matcher is not resizable or not in resize\n");
return -EINVAL;
}
if (unlikely(src_matcher != rule->matcher)) {
mlx5hws_err(ctx, "Rule doesn't belong to src matcher\n");
return -EINVAL;
}
return mlx5hws_rule_move_hws_add(rule, attr);
}
|