-
Notifications
You must be signed in to change notification settings - Fork 2
/
ulp_rte_parser.c
2688 lines (2366 loc) · 85.7 KB
/
ulp_rte_parser.c
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
/* SPDX-License-Identifier: BSD-3-Clause
* Copyright(c) 2014-2021 Broadcom
* All rights reserved.
*/
#include "bnxt.h"
#include "ulp_template_db_enum.h"
#include "ulp_template_struct.h"
#include "bnxt_ulp.h"
#include "bnxt_tf_common.h"
#include "bnxt_tf_pmd_shim.h"
#include "ulp_rte_parser.h"
#include "ulp_matcher.h"
#include "ulp_utils.h"
#include "tfp.h"
#include "ulp_port_db.h"
#include "ulp_flow_db.h"
#include "ulp_mapper.h"
#include "ulp_tun.h"
#include "ulp_template_db_tbl.h"
/* Local defines for the parsing functions */
#define ULP_VLAN_PRIORITY_SHIFT 13 /* First 3 bits */
#define ULP_VLAN_PRIORITY_MASK 0x700
#define ULP_VLAN_TAG_MASK 0xFFF /* Last 12 bits*/
#define ULP_UDP_PORT_VXLAN 4789
/* Utility function to skip the void items. */
static inline int32_t
ulp_rte_item_skip_void(const struct rte_flow_item **item, uint32_t increment)
{
if (!*item)
return 0;
if (increment)
(*item)++;
while ((*item) && (*item)->type == RTE_FLOW_ITEM_TYPE_VOID)
(*item)++;
if (*item)
return 1;
return 0;
}
/* Utility function to copy field spec items */
static struct ulp_rte_hdr_field *
ulp_rte_parser_fld_copy(struct ulp_rte_hdr_field *field,
const void *buffer,
uint32_t size)
{
field->size = size;
memcpy(field->spec, buffer, field->size);
field++;
return field;
}
/* Utility function to update the field_bitmap */
static void
ulp_rte_parser_field_bitmap_update(struct ulp_rte_parser_params *params,
uint32_t idx,
enum bnxt_ulp_prsr_action prsr_act)
{
struct ulp_rte_hdr_field *field;
field = ¶ms->hdr_field[idx];
if (ulp_bitmap_notzero(field->mask, field->size)) {
ULP_INDEX_BITMAP_SET(params->fld_bitmap.bits, idx);
if (!(prsr_act & ULP_PRSR_ACT_MATCH_IGNORE))
ULP_INDEX_BITMAP_SET(params->fld_s_bitmap.bits, idx);
/* Not exact match */
if (!ulp_bitmap_is_ones(field->mask, field->size))
ULP_COMP_FLD_IDX_WR(params,
BNXT_ULP_CF_IDX_WC_MATCH, 1);
} else {
ULP_INDEX_BITMAP_RESET(params->fld_bitmap.bits, idx);
}
}
#define ulp_deference_struct(x, y) ((x) ? &((x)->y) : NULL)
/* Utility function to copy field spec and masks items */
static void
ulp_rte_prsr_fld_mask(struct ulp_rte_parser_params *params,
uint32_t *idx,
uint32_t size,
const void *spec_buff,
const void *mask_buff,
enum bnxt_ulp_prsr_action prsr_act)
{
struct ulp_rte_hdr_field *field = ¶ms->hdr_field[*idx];
/* update the field size */
field->size = size;
/* copy the mask specifications only if mask is not null */
if (!(prsr_act & ULP_PRSR_ACT_MASK_IGNORE) && mask_buff) {
memcpy(field->mask, mask_buff, size);
ulp_rte_parser_field_bitmap_update(params, *idx, prsr_act);
}
/* copy the protocol specifications only if mask is not null*/
if (spec_buff && mask_buff && ulp_bitmap_notzero(mask_buff, size))
memcpy(field->spec, spec_buff, size);
/* Increment the index */
*idx = *idx + 1;
}
/* Utility function to copy field spec and masks items */
static int32_t
ulp_rte_prsr_fld_size_validate(struct ulp_rte_parser_params *params,
uint32_t *idx,
uint32_t size)
{
if (params->field_idx + size >= BNXT_ULP_PROTO_HDR_MAX) {
BNXT_TF_DBG(ERR, "OOB for field processing %u\n", *idx);
return -EINVAL;
}
*idx = params->field_idx;
params->field_idx += size;
return 0;
}
/*
* Function to handle the parsing of RTE Flows and placing
* the RTE flow items into the ulp structures.
*/
int32_t
bnxt_ulp_rte_parser_hdr_parse(const struct rte_flow_item pattern[],
struct ulp_rte_parser_params *params)
{
const struct rte_flow_item *item = pattern;
struct bnxt_ulp_rte_hdr_info *hdr_info;
params->field_idx = BNXT_ULP_PROTO_HDR_SVIF_NUM;
/* Set the computed flags for no vlan tags before parsing */
ULP_COMP_FLD_IDX_WR(params, BNXT_ULP_CF_IDX_O_NO_VTAG, 1);
ULP_COMP_FLD_IDX_WR(params, BNXT_ULP_CF_IDX_I_NO_VTAG, 1);
/* Parse all the items in the pattern */
while (item && item->type != RTE_FLOW_ITEM_TYPE_END) {
if (item->type >= (typeof(item->type))
BNXT_RTE_FLOW_ITEM_TYPE_END) {
if (item->type >=
(typeof(item->type))BNXT_RTE_FLOW_ITEM_TYPE_LAST)
goto hdr_parser_error;
/* get the header information */
hdr_info = &ulp_vendor_hdr_info[item->type -
BNXT_RTE_FLOW_ITEM_TYPE_END];
} else {
if (item->type > RTE_FLOW_ITEM_TYPE_HIGIG2)
goto hdr_parser_error;
hdr_info = &ulp_hdr_info[item->type];
}
if (hdr_info->hdr_type == BNXT_ULP_HDR_TYPE_NOT_SUPPORTED) {
goto hdr_parser_error;
} else if (hdr_info->hdr_type == BNXT_ULP_HDR_TYPE_SUPPORTED) {
/* call the registered callback handler */
if (hdr_info->proto_hdr_func) {
if (hdr_info->proto_hdr_func(item, params) !=
BNXT_TF_RC_SUCCESS) {
return BNXT_TF_RC_ERROR;
}
}
}
item++;
}
/* update the implied SVIF */
return ulp_rte_parser_implicit_match_port_process(params);
hdr_parser_error:
BNXT_TF_DBG(ERR, "Truflow parser does not support type %d\n",
item->type);
return BNXT_TF_RC_PARSE_ERR;
}
/*
* Function to handle the parsing of RTE Flows and placing
* the RTE flow actions into the ulp structures.
*/
int32_t
bnxt_ulp_rte_parser_act_parse(const struct rte_flow_action actions[],
struct ulp_rte_parser_params *params)
{
const struct rte_flow_action *action_item = actions;
struct bnxt_ulp_rte_act_info *hdr_info;
/* Parse all the items in the pattern */
while (action_item && action_item->type != RTE_FLOW_ACTION_TYPE_END) {
if (action_item->type >=
(typeof(action_item->type))BNXT_RTE_FLOW_ACTION_TYPE_END) {
if (action_item->type >=
(typeof(action_item->type))BNXT_RTE_FLOW_ACTION_TYPE_LAST)
goto act_parser_error;
/* get the header information from bnxt actinfo table */
hdr_info = &ulp_vendor_act_info[action_item->type -
BNXT_RTE_FLOW_ACTION_TYPE_END];
} else {
if (action_item->type > RTE_FLOW_ACTION_TYPE_SHARED)
goto act_parser_error;
/* get the header information from the act info table */
hdr_info = &ulp_act_info[action_item->type];
}
if (hdr_info->act_type == BNXT_ULP_ACT_TYPE_NOT_SUPPORTED) {
goto act_parser_error;
} else if (hdr_info->act_type == BNXT_ULP_ACT_TYPE_SUPPORTED) {
/* call the registered callback handler */
if (hdr_info->proto_act_func) {
if (hdr_info->proto_act_func(action_item,
params) !=
BNXT_TF_RC_SUCCESS) {
return BNXT_TF_RC_ERROR;
}
}
}
action_item++;
}
/* update the implied port details */
ulp_rte_parser_implicit_act_port_process(params);
return BNXT_TF_RC_SUCCESS;
act_parser_error:
BNXT_TF_DBG(ERR, "Truflow parser does not support act %u\n",
action_item->type);
return BNXT_TF_RC_ERROR;
}
/*
* Function to handle the post processing of the computed
* fields for the interface.
*/
static void
bnxt_ulp_comp_fld_intf_update(struct ulp_rte_parser_params *params)
{
uint32_t ifindex;
uint16_t port_id, parif;
uint32_t mtype;
enum bnxt_ulp_direction_type dir;
/* get the direction details */
dir = ULP_COMP_FLD_IDX_RD(params, BNXT_ULP_CF_IDX_DIRECTION);
/* read the port id details */
port_id = ULP_COMP_FLD_IDX_RD(params, BNXT_ULP_CF_IDX_INCOMING_IF);
if (ulp_port_db_dev_port_to_ulp_index(params->ulp_ctx,
port_id,
&ifindex)) {
BNXT_TF_DBG(ERR, "ParseErr:Portid is not valid\n");
return;
}
if (dir == BNXT_ULP_DIR_INGRESS) {
/* Set port PARIF */
if (ulp_port_db_parif_get(params->ulp_ctx, ifindex,
BNXT_ULP_PHY_PORT_PARIF, &parif)) {
BNXT_TF_DBG(ERR, "ParseErr:ifindex is not valid\n");
return;
}
ULP_COMP_FLD_IDX_WR(params, BNXT_ULP_CF_IDX_PHY_PORT_PARIF,
parif);
} else {
/* Get the match port type */
mtype = ULP_COMP_FLD_IDX_RD(params,
BNXT_ULP_CF_IDX_MATCH_PORT_TYPE);
if (mtype == BNXT_ULP_INTF_TYPE_VF_REP) {
ULP_COMP_FLD_IDX_WR(params,
BNXT_ULP_CF_IDX_MATCH_PORT_IS_VFREP,
1);
/* Set VF func PARIF */
if (ulp_port_db_parif_get(params->ulp_ctx, ifindex,
BNXT_ULP_VF_FUNC_PARIF,
&parif)) {
BNXT_TF_DBG(ERR,
"ParseErr:ifindex is not valid\n");
return;
}
ULP_COMP_FLD_IDX_WR(params,
BNXT_ULP_CF_IDX_VF_FUNC_PARIF,
parif);
} else {
/* Set DRV func PARIF */
if (ulp_port_db_parif_get(params->ulp_ctx, ifindex,
BNXT_ULP_DRV_FUNC_PARIF,
&parif)) {
BNXT_TF_DBG(ERR,
"ParseErr:ifindex is not valid\n");
return;
}
ULP_COMP_FLD_IDX_WR(params,
BNXT_ULP_CF_IDX_DRV_FUNC_PARIF,
parif);
}
if (mtype == BNXT_ULP_INTF_TYPE_PF) {
ULP_COMP_FLD_IDX_WR(params,
BNXT_ULP_CF_IDX_MATCH_PORT_IS_PF,
1);
}
}
}
static int32_t
ulp_post_process_normal_flow(struct ulp_rte_parser_params *params)
{
enum bnxt_ulp_intf_type match_port_type, act_port_type;
enum bnxt_ulp_direction_type dir;
uint32_t act_port_set;
/* Get the computed details */
dir = ULP_COMP_FLD_IDX_RD(params, BNXT_ULP_CF_IDX_DIRECTION);
match_port_type = ULP_COMP_FLD_IDX_RD(params,
BNXT_ULP_CF_IDX_MATCH_PORT_TYPE);
act_port_type = ULP_COMP_FLD_IDX_RD(params,
BNXT_ULP_CF_IDX_ACT_PORT_TYPE);
act_port_set = ULP_COMP_FLD_IDX_RD(params,
BNXT_ULP_CF_IDX_ACT_PORT_IS_SET);
/* set the flow direction in the proto and action header */
if (dir == BNXT_ULP_DIR_EGRESS) {
ULP_BITMAP_SET(params->hdr_bitmap.bits,
BNXT_ULP_FLOW_DIR_BITMASK_EGR);
ULP_BITMAP_SET(params->act_bitmap.bits,
BNXT_ULP_FLOW_DIR_BITMASK_EGR);
}
/* calculate the VF to VF flag */
if (act_port_set && act_port_type == BNXT_ULP_INTF_TYPE_VF_REP &&
match_port_type == BNXT_ULP_INTF_TYPE_VF_REP)
ULP_COMP_FLD_IDX_WR(params, BNXT_ULP_CF_IDX_VF_TO_VF, 1);
/* Update the decrement ttl computational fields */
if (ULP_BITMAP_ISSET(params->act_bitmap.bits,
BNXT_ULP_ACT_BIT_DEC_TTL)) {
/*
* Check that vxlan proto is included and vxlan decap
* action is not set then decrement tunnel ttl.
* Similarly add GRE and NVGRE in future.
*/
if ((ULP_BITMAP_ISSET(params->hdr_bitmap.bits,
BNXT_ULP_HDR_BIT_T_VXLAN) &&
!ULP_BITMAP_ISSET(params->act_bitmap.bits,
BNXT_ULP_ACT_BIT_VXLAN_DECAP))) {
ULP_COMP_FLD_IDX_WR(params,
BNXT_ULP_CF_IDX_ACT_T_DEC_TTL, 1);
} else {
ULP_COMP_FLD_IDX_WR(params,
BNXT_ULP_CF_IDX_ACT_DEC_TTL, 1);
}
}
/* Merge the hdr_fp_bit into the proto header bit */
params->hdr_bitmap.bits |= params->hdr_fp_bit.bits;
/* Update the comp fld fid */
ULP_COMP_FLD_IDX_WR(params, BNXT_ULP_CF_IDX_FID, params->fid);
/* Update the computed interface parameters */
bnxt_ulp_comp_fld_intf_update(params);
/* TBD: Handle the flow rejection scenarios */
return 0;
}
/*
* Function to handle the post processing of the parsing details
*/
void
bnxt_ulp_rte_parser_post_process(struct ulp_rte_parser_params *params)
{
ulp_post_process_normal_flow(params);
}
/*
* Function to compute the flow direction based on the match port details
*/
static void
bnxt_ulp_rte_parser_direction_compute(struct ulp_rte_parser_params *params)
{
enum bnxt_ulp_intf_type match_port_type;
/* Get the match port type */
match_port_type = ULP_COMP_FLD_IDX_RD(params,
BNXT_ULP_CF_IDX_MATCH_PORT_TYPE);
/* If ingress flow and matchport is vf rep then dir is egress*/
if ((params->dir_attr & BNXT_ULP_FLOW_ATTR_INGRESS) &&
match_port_type == BNXT_ULP_INTF_TYPE_VF_REP) {
ULP_COMP_FLD_IDX_WR(params, BNXT_ULP_CF_IDX_DIRECTION,
BNXT_ULP_DIR_EGRESS);
} else {
/* Assign the input direction */
if (params->dir_attr & BNXT_ULP_FLOW_ATTR_INGRESS)
ULP_COMP_FLD_IDX_WR(params, BNXT_ULP_CF_IDX_DIRECTION,
BNXT_ULP_DIR_INGRESS);
else
ULP_COMP_FLD_IDX_WR(params, BNXT_ULP_CF_IDX_DIRECTION,
BNXT_ULP_DIR_EGRESS);
}
}
/* Function to handle the parsing of RTE Flow item PF Header. */
static int32_t
ulp_rte_parser_svif_set(struct ulp_rte_parser_params *params,
uint32_t ifindex,
uint16_t mask,
enum bnxt_ulp_direction_type item_dir)
{
uint16_t svif;
enum bnxt_ulp_direction_type dir;
struct ulp_rte_hdr_field *hdr_field;
enum bnxt_ulp_svif_type svif_type;
enum bnxt_ulp_intf_type port_type;
if (ULP_COMP_FLD_IDX_RD(params, BNXT_ULP_CF_IDX_SVIF_FLAG) !=
BNXT_ULP_INVALID_SVIF_VAL) {
BNXT_TF_DBG(ERR,
"SVIF already set,multiple source not support'd\n");
return BNXT_TF_RC_ERROR;
}
/* Get port type details */
port_type = ulp_port_db_port_type_get(params->ulp_ctx, ifindex);
if (port_type == BNXT_ULP_INTF_TYPE_INVALID) {
BNXT_TF_DBG(ERR, "Invalid port type\n");
return BNXT_TF_RC_ERROR;
}
/* Update the match port type */
ULP_COMP_FLD_IDX_WR(params, BNXT_ULP_CF_IDX_MATCH_PORT_TYPE, port_type);
/* compute the direction */
bnxt_ulp_rte_parser_direction_compute(params);
/* Get the computed direction */
dir = (item_dir != BNXT_ULP_DIR_INVALID) ? item_dir :
ULP_COMP_FLD_IDX_RD(params, BNXT_ULP_CF_IDX_DIRECTION);
if (dir == BNXT_ULP_DIR_INGRESS &&
port_type != BNXT_ULP_INTF_TYPE_VF_REP) {
svif_type = BNXT_ULP_PHY_PORT_SVIF;
} else {
if (port_type == BNXT_ULP_INTF_TYPE_VF_REP &&
item_dir != BNXT_ULP_DIR_EGRESS)
svif_type = BNXT_ULP_VF_FUNC_SVIF;
else
svif_type = BNXT_ULP_DRV_FUNC_SVIF;
}
ulp_port_db_svif_get(params->ulp_ctx, ifindex, svif_type,
&svif);
svif = rte_cpu_to_be_16(svif);
hdr_field = ¶ms->hdr_field[BNXT_ULP_PROTO_HDR_FIELD_SVIF_IDX];
memcpy(hdr_field->spec, &svif, sizeof(svif));
memcpy(hdr_field->mask, &mask, sizeof(mask));
hdr_field->size = sizeof(svif);
ULP_COMP_FLD_IDX_WR(params, BNXT_ULP_CF_IDX_SVIF_FLAG,
rte_be_to_cpu_16(svif));
return BNXT_TF_RC_SUCCESS;
}
/* Function to handle the parsing of the RTE port id */
int32_t
ulp_rte_parser_implicit_match_port_process(struct ulp_rte_parser_params *params)
{
uint16_t port_id = 0;
uint16_t svif_mask = 0xFFFF;
uint32_t ifindex;
int32_t rc = BNXT_TF_RC_ERROR;
if (ULP_COMP_FLD_IDX_RD(params, BNXT_ULP_CF_IDX_SVIF_FLAG) !=
BNXT_ULP_INVALID_SVIF_VAL)
return BNXT_TF_RC_SUCCESS;
/* SVIF not set. So get the port id */
port_id = ULP_COMP_FLD_IDX_RD(params, BNXT_ULP_CF_IDX_INCOMING_IF);
if (ulp_port_db_dev_port_to_ulp_index(params->ulp_ctx,
port_id,
&ifindex)) {
BNXT_TF_DBG(ERR, "ParseErr:Portid is not valid\n");
return rc;
}
/* Update the SVIF details */
rc = ulp_rte_parser_svif_set(params, ifindex, svif_mask,
BNXT_ULP_DIR_INVALID);
return rc;
}
/* Function to handle the implicit action port id */
int32_t
ulp_rte_parser_implicit_act_port_process(struct ulp_rte_parser_params *params)
{
struct rte_flow_action action_item = {0};
struct rte_flow_action_port_id port_id = {0};
/* Read the action port set bit */
if (ULP_COMP_FLD_IDX_RD(params, BNXT_ULP_CF_IDX_ACT_PORT_IS_SET)) {
/* Already set, so just exit */
return BNXT_TF_RC_SUCCESS;
}
port_id.id = ULP_COMP_FLD_IDX_RD(params, BNXT_ULP_CF_IDX_INCOMING_IF);
action_item.type = RTE_FLOW_ACTION_TYPE_PORT_ID;
action_item.conf = &port_id;
/* Update the action port based on incoming port */
ulp_rte_port_act_handler(&action_item, params);
/* Reset the action port set bit */
ULP_COMP_FLD_IDX_WR(params, BNXT_ULP_CF_IDX_ACT_PORT_IS_SET, 0);
return BNXT_TF_RC_SUCCESS;
}
/* Function to handle the parsing of RTE Flow item PF Header. */
int32_t
ulp_rte_pf_hdr_handler(const struct rte_flow_item *item __rte_unused,
struct ulp_rte_parser_params *params)
{
uint16_t port_id = 0;
uint16_t svif_mask = 0xFFFF;
uint32_t ifindex;
/* Get the implicit port id */
port_id = ULP_COMP_FLD_IDX_RD(params, BNXT_ULP_CF_IDX_INCOMING_IF);
/* perform the conversion from dpdk port to bnxt ifindex */
if (ulp_port_db_dev_port_to_ulp_index(params->ulp_ctx,
port_id,
&ifindex)) {
BNXT_TF_DBG(ERR, "ParseErr:Portid is not valid\n");
return BNXT_TF_RC_ERROR;
}
/* Update the SVIF details */
return ulp_rte_parser_svif_set(params, ifindex, svif_mask,
BNXT_ULP_DIR_INVALID);
}
/* Function to handle the parsing of RTE Flow item VF Header. */
int32_t
ulp_rte_vf_hdr_handler(const struct rte_flow_item *item,
struct ulp_rte_parser_params *params)
{
const struct rte_flow_item_vf *vf_spec = item->spec;
const struct rte_flow_item_vf *vf_mask = item->mask;
uint16_t mask = 0;
uint32_t ifindex;
int32_t rc = BNXT_TF_RC_PARSE_ERR;
/* Get VF rte_flow_item for Port details */
if (!vf_spec) {
BNXT_TF_DBG(ERR, "ParseErr:VF id is not valid\n");
return rc;
}
if (!vf_mask) {
BNXT_TF_DBG(ERR, "ParseErr:VF mask is not valid\n");
return rc;
}
mask = vf_mask->id;
/* perform the conversion from VF Func id to bnxt ifindex */
if (ulp_port_db_dev_func_id_to_ulp_index(params->ulp_ctx,
vf_spec->id,
&ifindex)) {
BNXT_TF_DBG(ERR, "ParseErr:Portid is not valid\n");
return rc;
}
/* Update the SVIF details */
return ulp_rte_parser_svif_set(params, ifindex, mask,
BNXT_ULP_DIR_INVALID);
}
/* Parse items PORT_ID, PORT_REPRESENTOR and REPRESENTED_PORT. */
int32_t
ulp_rte_port_hdr_handler(const struct rte_flow_item *item,
struct ulp_rte_parser_params *params)
{
enum bnxt_ulp_direction_type item_dir;
uint16_t ethdev_id;
uint16_t mask = 0;
int32_t rc = BNXT_TF_RC_PARSE_ERR;
uint32_t ifindex;
if (!item->spec) {
BNXT_TF_DBG(ERR, "ParseErr:Port spec is not valid\n");
return rc;
}
if (!item->mask) {
BNXT_TF_DBG(ERR, "ParseErr:Port mask is not valid\n");
return rc;
}
switch (item->type) {
case RTE_FLOW_ITEM_TYPE_PORT_ID: {
const struct rte_flow_item_port_id *port_spec = item->spec;
const struct rte_flow_item_port_id *port_mask = item->mask;
item_dir = BNXT_ULP_DIR_INVALID;
ethdev_id = port_spec->id;
mask = port_mask->id;
break;
}
case RTE_FLOW_ITEM_TYPE_PORT_REPRESENTOR: {
const struct rte_flow_item_ethdev *ethdev_spec = item->spec;
const struct rte_flow_item_ethdev *ethdev_mask = item->mask;
item_dir = BNXT_ULP_DIR_INGRESS;
ethdev_id = ethdev_spec->port_id;
mask = ethdev_mask->port_id;
break;
}
case RTE_FLOW_ITEM_TYPE_REPRESENTED_PORT: {
const struct rte_flow_item_ethdev *ethdev_spec = item->spec;
const struct rte_flow_item_ethdev *ethdev_mask = item->mask;
item_dir = BNXT_ULP_DIR_EGRESS;
ethdev_id = ethdev_spec->port_id;
mask = ethdev_mask->port_id;
break;
}
default:
BNXT_TF_DBG(ERR, "ParseErr:Unexpected item\n");
return rc;
}
/* perform the conversion from dpdk port to bnxt ifindex */
if (ulp_port_db_dev_port_to_ulp_index(params->ulp_ctx,
ethdev_id,
&ifindex)) {
BNXT_TF_DBG(ERR, "ParseErr:Portid is not valid\n");
return rc;
}
/* Update the SVIF details */
return ulp_rte_parser_svif_set(params, ifindex, mask, item_dir);
}
/* Function to handle the parsing of RTE Flow item phy port Header. */
int32_t
ulp_rte_phy_port_hdr_handler(const struct rte_flow_item *item,
struct ulp_rte_parser_params *params)
{
const struct rte_flow_item_phy_port *port_spec = item->spec;
const struct rte_flow_item_phy_port *port_mask = item->mask;
uint16_t mask = 0;
int32_t rc = BNXT_TF_RC_ERROR;
uint16_t svif;
enum bnxt_ulp_direction_type dir;
struct ulp_rte_hdr_field *hdr_field;
/* Copy the rte_flow_item for phy port into hdr_field */
if (!port_spec) {
BNXT_TF_DBG(ERR, "ParseErr:Phy Port id is not valid\n");
return rc;
}
if (!port_mask) {
BNXT_TF_DBG(ERR, "ParseErr:Phy Port mask is not valid\n");
return rc;
}
mask = port_mask->index;
/* Update the match port type */
ULP_COMP_FLD_IDX_WR(params, BNXT_ULP_CF_IDX_MATCH_PORT_TYPE,
BNXT_ULP_INTF_TYPE_PHY_PORT);
/* Compute the Hw direction */
bnxt_ulp_rte_parser_direction_compute(params);
/* Direction validation */
dir = ULP_COMP_FLD_IDX_RD(params, BNXT_ULP_CF_IDX_DIRECTION);
if (dir == BNXT_ULP_DIR_EGRESS) {
BNXT_TF_DBG(ERR,
"Parse Err:Phy ports are valid only for ingress\n");
return BNXT_TF_RC_PARSE_ERR;
}
/* Get the physical port details from port db */
rc = ulp_port_db_phy_port_svif_get(params->ulp_ctx, port_spec->index,
&svif);
if (rc) {
BNXT_TF_DBG(ERR, "Failed to get port details\n");
return BNXT_TF_RC_PARSE_ERR;
}
/* Update the SVIF details */
svif = rte_cpu_to_be_16(svif);
hdr_field = ¶ms->hdr_field[BNXT_ULP_PROTO_HDR_FIELD_SVIF_IDX];
memcpy(hdr_field->spec, &svif, sizeof(svif));
memcpy(hdr_field->mask, &mask, sizeof(mask));
hdr_field->size = sizeof(svif);
ULP_COMP_FLD_IDX_WR(params, BNXT_ULP_CF_IDX_SVIF_FLAG,
rte_be_to_cpu_16(svif));
if (!mask) {
uint32_t port_id = 0;
uint16_t phy_port = 0;
/* Validate the control port */
port_id = ULP_COMP_FLD_IDX_RD(params,
BNXT_ULP_CF_IDX_DEV_PORT_ID);
if (ulp_port_db_phy_port_get(params->ulp_ctx,
port_id, &phy_port) ||
(uint16_t)port_spec->index != phy_port) {
BNXT_TF_DBG(ERR, "Mismatch of control and phy_port\n");
return BNXT_TF_RC_PARSE_ERR;
}
ULP_BITMAP_SET(params->hdr_bitmap.bits,
BNXT_ULP_HDR_BIT_SVIF_IGNORE);
memset(hdr_field->mask, 0xFF, sizeof(mask));
}
return BNXT_TF_RC_SUCCESS;
}
/* Function to handle the update of proto header based on field values */
static void
ulp_rte_l2_proto_type_update(struct ulp_rte_parser_params *param,
uint16_t type, uint32_t in_flag)
{
if (type == tfp_cpu_to_be_16(RTE_ETHER_TYPE_IPV4)) {
if (in_flag) {
ULP_BITMAP_SET(param->hdr_fp_bit.bits,
BNXT_ULP_HDR_BIT_I_IPV4);
ULP_COMP_FLD_IDX_WR(param, BNXT_ULP_CF_IDX_I_L3, 1);
} else {
ULP_BITMAP_SET(param->hdr_fp_bit.bits,
BNXT_ULP_HDR_BIT_O_IPV4);
ULP_COMP_FLD_IDX_WR(param, BNXT_ULP_CF_IDX_O_L3, 1);
}
} else if (type == tfp_cpu_to_be_16(RTE_ETHER_TYPE_IPV6)) {
if (in_flag) {
ULP_BITMAP_SET(param->hdr_fp_bit.bits,
BNXT_ULP_HDR_BIT_I_IPV6);
ULP_COMP_FLD_IDX_WR(param, BNXT_ULP_CF_IDX_I_L3, 1);
} else {
ULP_BITMAP_SET(param->hdr_fp_bit.bits,
BNXT_ULP_HDR_BIT_O_IPV6);
ULP_COMP_FLD_IDX_WR(param, BNXT_ULP_CF_IDX_O_L3, 1);
}
}
}
/* Internal Function to identify broadcast or multicast packets */
static int32_t
ulp_rte_parser_is_bcmc_addr(const struct rte_ether_addr *eth_addr)
{
if (rte_is_multicast_ether_addr(eth_addr) ||
rte_is_broadcast_ether_addr(eth_addr)) {
BNXT_TF_DBG(DEBUG,
"No support for bcast or mcast addr offload\n");
return 1;
}
return 0;
}
/* Function to handle the parsing of RTE Flow item Ethernet Header. */
int32_t
ulp_rte_eth_hdr_handler(const struct rte_flow_item *item,
struct ulp_rte_parser_params *params)
{
const struct rte_flow_item_eth *eth_spec = item->spec;
const struct rte_flow_item_eth *eth_mask = item->mask;
uint32_t idx = 0, dmac_idx = 0;
uint32_t size;
uint16_t eth_type = 0;
uint32_t inner_flag = 0;
/* Perform validations */
if (eth_spec) {
/* Todo: work around to avoid multicast and broadcast addr */
if (ulp_rte_parser_is_bcmc_addr(ð_spec->dst))
return BNXT_TF_RC_PARSE_ERR;
if (ulp_rte_parser_is_bcmc_addr(ð_spec->src))
return BNXT_TF_RC_PARSE_ERR;
eth_type = eth_spec->type;
}
if (ulp_rte_prsr_fld_size_validate(params, &idx,
BNXT_ULP_PROTO_HDR_ETH_NUM)) {
BNXT_TF_DBG(ERR, "Error parsing protocol header\n");
return BNXT_TF_RC_ERROR;
}
/*
* Copy the rte_flow_item for eth into hdr_field using ethernet
* header fields
*/
dmac_idx = idx;
size = sizeof(((struct rte_flow_item_eth *)NULL)->dst.addr_bytes);
ulp_rte_prsr_fld_mask(params, &idx, size,
ulp_deference_struct(eth_spec, dst.addr_bytes),
ulp_deference_struct(eth_mask, dst.addr_bytes),
ULP_PRSR_ACT_DEFAULT);
size = sizeof(((struct rte_flow_item_eth *)NULL)->src.addr_bytes);
ulp_rte_prsr_fld_mask(params, &idx, size,
ulp_deference_struct(eth_spec, src.addr_bytes),
ulp_deference_struct(eth_mask, src.addr_bytes),
ULP_PRSR_ACT_DEFAULT);
size = sizeof(((struct rte_flow_item_eth *)NULL)->type);
ulp_rte_prsr_fld_mask(params, &idx, size,
ulp_deference_struct(eth_spec, type),
ulp_deference_struct(eth_mask, type),
ULP_PRSR_ACT_MATCH_IGNORE);
/* Update the protocol hdr bitmap */
if (ULP_BITMAP_ISSET(params->hdr_bitmap.bits,
BNXT_ULP_HDR_BIT_O_ETH) ||
ULP_BITMAP_ISSET(params->hdr_bitmap.bits,
BNXT_ULP_HDR_BIT_O_IPV4) ||
ULP_BITMAP_ISSET(params->hdr_bitmap.bits,
BNXT_ULP_HDR_BIT_O_IPV6) ||
ULP_BITMAP_ISSET(params->hdr_bitmap.bits,
BNXT_ULP_HDR_BIT_O_UDP) ||
ULP_BITMAP_ISSET(params->hdr_bitmap.bits,
BNXT_ULP_HDR_BIT_O_TCP)) {
ULP_BITMAP_SET(params->hdr_bitmap.bits, BNXT_ULP_HDR_BIT_I_ETH);
inner_flag = 1;
} else {
ULP_BITMAP_SET(params->hdr_bitmap.bits, BNXT_ULP_HDR_BIT_O_ETH);
ULP_COMP_FLD_IDX_WR(params, BNXT_ULP_CF_IDX_TUN_OFF_DMAC_ID,
dmac_idx);
}
/* Update the field protocol hdr bitmap */
ulp_rte_l2_proto_type_update(params, eth_type, inner_flag);
return BNXT_TF_RC_SUCCESS;
}
/* Function to handle the parsing of RTE Flow item Vlan Header. */
int32_t
ulp_rte_vlan_hdr_handler(const struct rte_flow_item *item,
struct ulp_rte_parser_params *params)
{
const struct rte_flow_item_vlan *vlan_spec = item->spec;
const struct rte_flow_item_vlan *vlan_mask = item->mask;
struct ulp_rte_hdr_bitmap *hdr_bit;
uint32_t idx = 0;
uint16_t vlan_tag = 0, priority = 0;
uint16_t vlan_tag_mask = 0, priority_mask = 0;
uint32_t outer_vtag_num;
uint32_t inner_vtag_num;
uint16_t eth_type = 0;
uint32_t inner_flag = 0;
uint32_t size;
if (vlan_spec) {
vlan_tag = ntohs(vlan_spec->tci);
priority = htons(vlan_tag >> ULP_VLAN_PRIORITY_SHIFT);
vlan_tag &= ULP_VLAN_TAG_MASK;
vlan_tag = htons(vlan_tag);
eth_type = vlan_spec->inner_type;
}
if (vlan_mask) {
vlan_tag_mask = ntohs(vlan_mask->tci);
priority_mask = htons(vlan_tag_mask >> ULP_VLAN_PRIORITY_SHIFT);
vlan_tag_mask &= 0xfff;
/*
* the storage for priority and vlan tag is 2 bytes
* The mask of priority which is 3 bits if it is all 1's
* then make the rest bits 13 bits as 1's
* so that it is matched as exact match.
*/
if (priority_mask == ULP_VLAN_PRIORITY_MASK)
priority_mask |= ~ULP_VLAN_PRIORITY_MASK;
if (vlan_tag_mask == ULP_VLAN_TAG_MASK)
vlan_tag_mask |= ~ULP_VLAN_TAG_MASK;
vlan_tag_mask = htons(vlan_tag_mask);
}
if (ulp_rte_prsr_fld_size_validate(params, &idx,
BNXT_ULP_PROTO_HDR_S_VLAN_NUM)) {
BNXT_TF_DBG(ERR, "Error parsing protocol header\n");
return BNXT_TF_RC_ERROR;
}
/*
* Copy the rte_flow_item for vlan into hdr_field using Vlan
* header fields
*/
size = sizeof(((struct rte_flow_item_vlan *)NULL)->tci);
/*
* The priority field is ignored since OVS is setting it as
* wild card match and it is not supported. This is a work
* around and shall be addressed in the future.
*/
ulp_rte_prsr_fld_mask(params, &idx, size,
&priority,
(vlan_mask) ? &priority_mask : NULL,
ULP_PRSR_ACT_MASK_IGNORE);
ulp_rte_prsr_fld_mask(params, &idx, size,
&vlan_tag,
(vlan_mask) ? &vlan_tag_mask : NULL,
ULP_PRSR_ACT_DEFAULT);
size = sizeof(((struct rte_flow_item_vlan *)NULL)->inner_type);
ulp_rte_prsr_fld_mask(params, &idx, size,
ulp_deference_struct(vlan_spec, inner_type),
ulp_deference_struct(vlan_mask, inner_type),
ULP_PRSR_ACT_MATCH_IGNORE);
/* Get the outer tag and inner tag counts */
outer_vtag_num = ULP_COMP_FLD_IDX_RD(params,
BNXT_ULP_CF_IDX_O_VTAG_NUM);
inner_vtag_num = ULP_COMP_FLD_IDX_RD(params,
BNXT_ULP_CF_IDX_I_VTAG_NUM);
/* Update the hdr_bitmap of the vlans */
hdr_bit = ¶ms->hdr_bitmap;
if (ULP_BITMAP_ISSET(hdr_bit->bits, BNXT_ULP_HDR_BIT_O_ETH) &&
!ULP_BITMAP_ISSET(hdr_bit->bits, BNXT_ULP_HDR_BIT_I_ETH) &&
!outer_vtag_num) {
/* Update the vlan tag num */
outer_vtag_num++;
ULP_COMP_FLD_IDX_WR(params, BNXT_ULP_CF_IDX_O_VTAG_NUM,
outer_vtag_num);
ULP_COMP_FLD_IDX_WR(params, BNXT_ULP_CF_IDX_O_NO_VTAG, 0);
ULP_COMP_FLD_IDX_WR(params, BNXT_ULP_CF_IDX_O_ONE_VTAG, 1);
ULP_BITMAP_SET(params->hdr_bitmap.bits,
BNXT_ULP_HDR_BIT_OO_VLAN);
if (vlan_mask && vlan_tag_mask)
ULP_COMP_FLD_IDX_WR(params,
BNXT_ULP_CF_IDX_OO_VLAN_FB_VID, 1);
} else if (ULP_BITMAP_ISSET(hdr_bit->bits, BNXT_ULP_HDR_BIT_O_ETH) &&
!ULP_BITMAP_ISSET(hdr_bit->bits, BNXT_ULP_HDR_BIT_I_ETH) &&
outer_vtag_num == 1) {
/* update the vlan tag num */
outer_vtag_num++;
ULP_COMP_FLD_IDX_WR(params, BNXT_ULP_CF_IDX_O_VTAG_NUM,
outer_vtag_num);
ULP_COMP_FLD_IDX_WR(params, BNXT_ULP_CF_IDX_O_TWO_VTAGS, 1);
ULP_COMP_FLD_IDX_WR(params, BNXT_ULP_CF_IDX_O_ONE_VTAG, 0);
ULP_BITMAP_SET(params->hdr_bitmap.bits,
BNXT_ULP_HDR_BIT_OI_VLAN);
if (vlan_mask && vlan_tag_mask)
ULP_COMP_FLD_IDX_WR(params,
BNXT_ULP_CF_IDX_OI_VLAN_FB_VID, 1);
} else if (ULP_BITMAP_ISSET(hdr_bit->bits, BNXT_ULP_HDR_BIT_O_ETH) &&
ULP_BITMAP_ISSET(hdr_bit->bits, BNXT_ULP_HDR_BIT_I_ETH) &&
!inner_vtag_num) {
/* update the vlan tag num */
inner_vtag_num++;
ULP_COMP_FLD_IDX_WR(params, BNXT_ULP_CF_IDX_I_VTAG_NUM,
inner_vtag_num);
ULP_COMP_FLD_IDX_WR(params, BNXT_ULP_CF_IDX_I_NO_VTAG, 0);
ULP_COMP_FLD_IDX_WR(params, BNXT_ULP_CF_IDX_I_ONE_VTAG, 1);
ULP_BITMAP_SET(params->hdr_bitmap.bits,
BNXT_ULP_HDR_BIT_IO_VLAN);
if (vlan_mask && vlan_tag_mask)
ULP_COMP_FLD_IDX_WR(params,
BNXT_ULP_CF_IDX_IO_VLAN_FB_VID, 1);
inner_flag = 1;
} else if (ULP_BITMAP_ISSET(hdr_bit->bits, BNXT_ULP_HDR_BIT_O_ETH) &&
ULP_BITMAP_ISSET(hdr_bit->bits, BNXT_ULP_HDR_BIT_I_ETH) &&
inner_vtag_num == 1) {
/* update the vlan tag num */
inner_vtag_num++;
ULP_COMP_FLD_IDX_WR(params, BNXT_ULP_CF_IDX_I_VTAG_NUM,
inner_vtag_num);
ULP_COMP_FLD_IDX_WR(params, BNXT_ULP_CF_IDX_I_TWO_VTAGS, 1);
ULP_COMP_FLD_IDX_WR(params, BNXT_ULP_CF_IDX_I_ONE_VTAG, 0);
ULP_BITMAP_SET(params->hdr_bitmap.bits,
BNXT_ULP_HDR_BIT_II_VLAN);
if (vlan_mask && vlan_tag_mask)
ULP_COMP_FLD_IDX_WR(params,
BNXT_ULP_CF_IDX_II_VLAN_FB_VID, 1);
inner_flag = 1;
} else {
BNXT_TF_DBG(ERR, "Error Parsing:Vlan hdr found without eth\n");
return BNXT_TF_RC_ERROR;
}
/* Update the field protocol hdr bitmap */
ulp_rte_l2_proto_type_update(params, eth_type, inner_flag);
return BNXT_TF_RC_SUCCESS;
}
/* Function to handle the update of proto header based on field values */
static void
ulp_rte_l3_proto_type_update(struct ulp_rte_parser_params *param,
uint8_t proto, uint32_t in_flag)
{
if (proto == IPPROTO_UDP) {
if (in_flag) {
ULP_BITMAP_SET(param->hdr_fp_bit.bits,
BNXT_ULP_HDR_BIT_I_UDP);
ULP_COMP_FLD_IDX_WR(param, BNXT_ULP_CF_IDX_I_L4, 1);
} else {
ULP_BITMAP_SET(param->hdr_fp_bit.bits,
BNXT_ULP_HDR_BIT_O_UDP);
ULP_COMP_FLD_IDX_WR(param, BNXT_ULP_CF_IDX_O_L4, 1);
}
} else if (proto == IPPROTO_TCP) {
if (in_flag) {
ULP_BITMAP_SET(param->hdr_fp_bit.bits,
BNXT_ULP_HDR_BIT_I_TCP);
ULP_COMP_FLD_IDX_WR(param, BNXT_ULP_CF_IDX_I_L4, 1);
} else {
ULP_BITMAP_SET(param->hdr_fp_bit.bits,
BNXT_ULP_HDR_BIT_O_TCP);
ULP_COMP_FLD_IDX_WR(param, BNXT_ULP_CF_IDX_O_L4, 1);