DPDK logo

Elixir Cross Referencer

   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
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
/* SPDX-License-Identifier: BSD-3-Clause
 * Copyright(c) 2014-2020 Broadcom
 * All rights reserved.
 */

#include "bnxt.h"
#include "ulp_template_db.h"
#include "ulp_template_struct.h"
#include "bnxt_tf_common.h"
#include "ulp_rte_parser.h"
#include "ulp_utils.h"
#include "tfp.h"
#include "ulp_port_db.h"

/* 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 update the field_bitmap */
static void
ulp_rte_parser_field_bitmap_update(struct ulp_rte_parser_params *params,
				   uint32_t idx)
{
	struct ulp_rte_hdr_field *field;

	field = &params->hdr_field[idx];
	if (ulp_bitmap_notzero(field->mask, field->size)) {
		ULP_INDEX_BITMAP_SET(params->fld_bitmap.bits, idx);
		/* Not exact match */
		if (!ulp_bitmap_is_ones(field->mask, field->size))
			ULP_BITMAP_SET(params->fld_bitmap.bits,
				       BNXT_ULP_MATCH_TYPE_BITMASK_WM);
	} else {
		ULP_INDEX_BITMAP_RESET(params->fld_bitmap.bits, idx);
	}
}

/* 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 copy field masks items */
static void
ulp_rte_prsr_mask_copy(struct ulp_rte_parser_params *params,
		       uint32_t *idx,
		       const void *buffer,
		       uint32_t size)
{
	struct ulp_rte_hdr_field *field = &params->hdr_field[*idx];

	memcpy(field->mask, buffer, size);
	ulp_rte_parser_field_bitmap_update(params, *idx);
	*idx = *idx + 1;
}

/*
 * 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;
	if (params->dir == ULP_DIR_EGRESS)
		ULP_BITMAP_SET(params->hdr_bitmap.bits,
			       BNXT_ULP_FLOW_DIR_BITMASK_EGR);

	/* Parse all the items in the pattern */
	while (item && item->type != RTE_FLOW_ITEM_TYPE_END) {
		/* get the header information from the flow_hdr_info table */
		hdr_info = &ulp_hdr_info[item->type];
		if (hdr_info->hdr_type == BNXT_ULP_HDR_TYPE_NOT_SUPPORTED) {
			BNXT_TF_DBG(ERR,
				    "Truflow parser does not support type %d\n",
				    item->type);
			return BNXT_TF_RC_PARSE_ERR;
		} 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 */
	(void)ulp_rte_parser_svif_process(params);
	return BNXT_TF_RC_SUCCESS;
}

/*
 * 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) {
		/* get the header information from the flow_hdr_info table */
		hdr_info = &ulp_act_info[action_item->type];
		if (hdr_info->act_type ==
		    BNXT_ULP_ACT_TYPE_NOT_SUPPORTED) {
			BNXT_TF_DBG(ERR,
				    "Truflow parser does not support act %u\n",
				    action_item->type);
			return BNXT_TF_RC_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 VNIC */
	ulp_rte_parser_vnic_process(params);
	return BNXT_TF_RC_SUCCESS;
}

/* 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,
			enum rte_flow_item_type proto,
			uint16_t svif,
			uint16_t mask)
{
	uint16_t port_id = svif;
	uint32_t dir = 0;
	struct ulp_rte_hdr_field *hdr_field;
	uint32_t ifindex;
	int32_t rc;

	if (ULP_BITMAP_ISSET(params->hdr_bitmap.bits, BNXT_ULP_HDR_BIT_SVIF)) {
		BNXT_TF_DBG(ERR,
			    "SVIF already set,multiple source not support'd\n");
		return BNXT_TF_RC_ERROR;
	}

	/*update the hdr_bitmap with BNXT_ULP_HDR_PROTO_SVIF */
	ULP_BITMAP_SET(params->hdr_bitmap.bits, BNXT_ULP_HDR_BIT_SVIF);

	if (proto == RTE_FLOW_ITEM_TYPE_PORT_ID) {
		dir = ULP_UTIL_CHF_IDX_RD(params,
					  BNXT_ULP_CHF_IDX_DIRECTION);
		/* perform the conversion from dpdk port to bnxt svif */
		rc = ulp_port_db_dev_port_to_ulp_index(params->ulp_ctx, port_id,
						       &ifindex);
		if (rc) {
			BNXT_TF_DBG(ERR,
				    "Invalid port id\n");
			return BNXT_TF_RC_ERROR;
		}
		ulp_port_db_svif_get(params->ulp_ctx, ifindex, dir, &svif);
		svif = rte_cpu_to_be_16(svif);
	}
	hdr_field = &params->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);
	return BNXT_TF_RC_SUCCESS;
}

/* Function to handle the parsing of the RTE port id */
int32_t
ulp_rte_parser_svif_process(struct ulp_rte_parser_params *params)
{
	uint16_t port_id = 0;
	uint16_t svif_mask = 0xFFFF;

	if (ULP_BITMAP_ISSET(params->hdr_bitmap.bits, BNXT_ULP_HDR_BIT_SVIF))
		return BNXT_TF_RC_SUCCESS;

	/* SVIF not set. So get the port id */
	port_id = ULP_UTIL_CHF_IDX_RD(params, BNXT_ULP_CHF_IDX_INCOMING_IF);

	/* Update the SVIF details */
	return ulp_rte_parser_svif_set(params, RTE_FLOW_ITEM_TYPE_PORT_ID,
				       port_id, svif_mask);
}

/* Function to handle the implicit VNIC RTE port id */
int32_t
ulp_rte_parser_vnic_process(struct ulp_rte_parser_params *params)
{
	struct ulp_rte_act_bitmap *act = &params->act_bitmap;

	if (ULP_BITMAP_ISSET(act->bits, BNXT_ULP_ACTION_BIT_VNIC) ||
	    ULP_BITMAP_ISSET(act->bits, BNXT_ULP_ACTION_BIT_VPORT))
		return BNXT_TF_RC_SUCCESS;

	/* Update the vnic details */
	ulp_rte_pf_act_handler(NULL, params);
	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,
		       struct ulp_rte_parser_params *params)
{
	uint16_t port_id = 0;
	uint16_t svif_mask = 0xFFFF;

	/* Get the port id */
	port_id = ULP_UTIL_CHF_IDX_RD(params, BNXT_ULP_CHF_IDX_INCOMING_IF);

	/* Update the SVIF details */
	return ulp_rte_parser_svif_set(params,
				       item->type,
				       port_id, svif_mask);
}

/* 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 svif = 0, mask = 0;

	/* Get VF rte_flow_item for Port details */
	if (vf_spec)
		svif = (uint16_t)vf_spec->id;
	if (vf_mask)
		mask = (uint16_t)vf_mask->id;

	return ulp_rte_parser_svif_set(params, item->type, svif, mask);
}

/* Function to handle the parsing of RTE Flow item port id  Header. */
int32_t
ulp_rte_port_id_hdr_handler(const struct rte_flow_item *item,
			    struct ulp_rte_parser_params *params)
{
	const struct rte_flow_item_port_id *port_spec = item->spec;
	const struct rte_flow_item_port_id *port_mask = item->mask;
	uint16_t svif = 0, mask = 0;

	/*
	 * Copy the rte_flow_item for Port into hdr_field using port id
	 * header fields.
	 */
	if (port_spec)
		svif = (uint16_t)port_spec->id;
	if (port_mask)
		mask = (uint16_t)port_mask->id;

	/* Update the SVIF details */
	return ulp_rte_parser_svif_set(params, item->type, svif, mask);
}

/* 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;
	uint32_t svif = 0, mask = 0;

	/* Copy the rte_flow_item for phy port into hdr_field */
	if (port_spec)
		svif = port_spec->index;
	if (port_mask)
		mask = port_mask->index;

	/* Update the SVIF details */
	return ulp_rte_parser_svif_set(params, item->type, svif, mask);
}

/* 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;
	struct ulp_rte_hdr_field *field;
	uint32_t idx = params->field_idx;
	uint64_t set_flag = 0;
	uint32_t size;

	/*
	 * Copy the rte_flow_item for eth into hdr_field using ethernet
	 * header fields
	 */
	if (eth_spec) {
		size = sizeof(eth_spec->dst.addr_bytes);
		field = ulp_rte_parser_fld_copy(&params->hdr_field[idx],
						eth_spec->dst.addr_bytes,
						size);
		size = sizeof(eth_spec->src.addr_bytes);
		field = ulp_rte_parser_fld_copy(field,
						eth_spec->src.addr_bytes,
						size);
		field = ulp_rte_parser_fld_copy(field,
						&eth_spec->type,
						sizeof(eth_spec->type));
	}
	if (eth_mask) {
		ulp_rte_prsr_mask_copy(params, &idx, eth_mask->dst.addr_bytes,
				       sizeof(eth_mask->dst.addr_bytes));
		ulp_rte_prsr_mask_copy(params, &idx, eth_mask->src.addr_bytes,
				       sizeof(eth_mask->src.addr_bytes));
		ulp_rte_prsr_mask_copy(params, &idx, &eth_mask->type,
				       sizeof(eth_mask->type));
	}
	/* Add number of vlan header elements */
	params->field_idx += BNXT_ULP_PROTO_HDR_ETH_NUM;
	params->vlan_idx = params->field_idx;
	params->field_idx += BNXT_ULP_PROTO_HDR_VLAN_NUM;

	/* Update the hdr_bitmap with BNXT_ULP_HDR_PROTO_I_ETH */
	set_flag = ULP_BITMAP_ISSET(params->hdr_bitmap.bits,
				    BNXT_ULP_HDR_BIT_O_ETH);
	if (set_flag)
		ULP_BITMAP_SET(params->hdr_bitmap.bits, BNXT_ULP_HDR_BIT_I_ETH);
	else
		ULP_BITMAP_RESET(params->hdr_bitmap.bits,
				 BNXT_ULP_HDR_BIT_I_ETH);

	/* update the hdr_bitmap with BNXT_ULP_HDR_PROTO_O_ETH */
	ULP_BITMAP_SET(params->hdr_bitmap.bits, BNXT_ULP_HDR_BIT_O_ETH);

	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_field *field;
	struct ulp_rte_hdr_bitmap	*hdr_bit;
	uint32_t idx = params->vlan_idx;
	uint16_t vlan_tag, priority;
	uint32_t outer_vtag_num;
	uint32_t inner_vtag_num;

	/*
	 * Copy the rte_flow_item for vlan into hdr_field using Vlan
	 * header fields
	 */
	if (vlan_spec) {
		vlan_tag = ntohs(vlan_spec->tci);
		priority = htons(vlan_tag >> 13);
		vlan_tag &= 0xfff;
		vlan_tag = htons(vlan_tag);

		field = ulp_rte_parser_fld_copy(&params->hdr_field[idx],
						&priority,
						sizeof(priority));
		field = ulp_rte_parser_fld_copy(field,
						&vlan_tag,
						sizeof(vlan_tag));
		field = ulp_rte_parser_fld_copy(field,
						&vlan_spec->inner_type,
						sizeof(vlan_spec->inner_type));
	}

	if (vlan_mask) {
		vlan_tag = ntohs(vlan_mask->tci);
		priority = htons(vlan_tag >> 13);
		vlan_tag &= 0xfff;
		vlan_tag = htons(vlan_tag);

		field = &params->hdr_field[idx];
		memcpy(field->mask, &priority, field->size);
		field++;
		memcpy(field->mask, &vlan_tag, field->size);
		field++;
		memcpy(field->mask, &vlan_mask->inner_type, field->size);
	}
	/* Set the vlan index to new incremented value */
	params->vlan_idx += BNXT_ULP_PROTO_HDR_S_VLAN_NUM;

	/* Get the outer tag and inner tag counts */
	outer_vtag_num = ULP_UTIL_CHF_IDX_RD(params,
					     BNXT_ULP_CHF_IDX_O_VTAG_NUM);
	inner_vtag_num = ULP_UTIL_CHF_IDX_RD(params,
					     BNXT_ULP_CHF_IDX_I_VTAG_NUM);

	/* Update the hdr_bitmap of the vlans */
	hdr_bit = &params->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_OO_VLAN)) {
		/* Set the outer vlan bit and update the vlan tag num */
		ULP_BITMAP_SET(hdr_bit->bits, BNXT_ULP_HDR_BIT_OO_VLAN);
		outer_vtag_num++;
		ULP_UTIL_CHF_IDX_WR(params, BNXT_ULP_CHF_IDX_O_VTAG_NUM,
				    outer_vtag_num);
		ULP_UTIL_CHF_IDX_WR(params, BNXT_ULP_CHF_IDX_O_VTAG_PRESENT, 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_OO_VLAN) &&
		   !ULP_BITMAP_ISSET(hdr_bit->bits, BNXT_ULP_HDR_BIT_OI_VLAN)) {
		/* Set the outer vlan bit and update the vlan tag num */
		ULP_BITMAP_SET(hdr_bit->bits, BNXT_ULP_HDR_BIT_OI_VLAN);
		outer_vtag_num++;
		ULP_UTIL_CHF_IDX_WR(params, BNXT_ULP_CHF_IDX_O_VTAG_NUM,
				    outer_vtag_num);
		ULP_UTIL_CHF_IDX_WR(params, BNXT_ULP_CHF_IDX_O_TWO_VTAGS, 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_OO_VLAN) &&
		   ULP_BITMAP_ISSET(hdr_bit->bits, BNXT_ULP_HDR_BIT_OI_VLAN) &&
		   ULP_BITMAP_ISSET(hdr_bit->bits, BNXT_ULP_HDR_BIT_I_ETH) &&
		   !ULP_BITMAP_ISSET(hdr_bit->bits, BNXT_ULP_HDR_BIT_IO_VLAN)) {
		/* Set the inner vlan bit and update the vlan tag num */
		ULP_BITMAP_SET(hdr_bit->bits, BNXT_ULP_HDR_BIT_IO_VLAN);
		inner_vtag_num++;
		ULP_UTIL_CHF_IDX_WR(params, BNXT_ULP_CHF_IDX_I_VTAG_NUM,
				    inner_vtag_num);
		ULP_UTIL_CHF_IDX_WR(params, BNXT_ULP_CHF_IDX_I_VTAG_PRESENT, 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_OO_VLAN) &&
		   ULP_BITMAP_ISSET(hdr_bit->bits, BNXT_ULP_HDR_BIT_OI_VLAN) &&
		   ULP_BITMAP_ISSET(hdr_bit->bits, BNXT_ULP_HDR_BIT_I_ETH) &&
		   ULP_BITMAP_ISSET(hdr_bit->bits, BNXT_ULP_HDR_BIT_IO_VLAN) &&
		   !ULP_BITMAP_ISSET(hdr_bit->bits, BNXT_ULP_HDR_BIT_II_VLAN)) {
		/* Set the inner vlan bit and update the vlan tag num */
		ULP_BITMAP_SET(hdr_bit->bits, BNXT_ULP_HDR_BIT_II_VLAN);
		inner_vtag_num++;
		ULP_UTIL_CHF_IDX_WR(params, BNXT_ULP_CHF_IDX_I_VTAG_NUM,
				    inner_vtag_num);
		ULP_UTIL_CHF_IDX_WR(params, BNXT_ULP_CHF_IDX_I_TWO_VTAGS, 1);
	} else {
		BNXT_TF_DBG(ERR, "Error Parsing:Vlan hdr found withtout eth\n");
		return BNXT_TF_RC_ERROR;
	}
	return BNXT_TF_RC_SUCCESS;
}

/* Function to handle the parsing of RTE Flow item IPV4 Header. */
int32_t
ulp_rte_ipv4_hdr_handler(const struct rte_flow_item *item,
			 struct ulp_rte_parser_params *params)
{
	const struct rte_flow_item_ipv4 *ipv4_spec = item->spec;
	const struct rte_flow_item_ipv4 *ipv4_mask = item->mask;
	struct ulp_rte_hdr_field *field;
	struct ulp_rte_hdr_bitmap *hdr_bitmap = &params->hdr_bitmap;
	uint32_t idx = params->field_idx;
	uint32_t size;
	uint32_t inner_l3, outer_l3;

	inner_l3 = ULP_UTIL_CHF_IDX_RD(params, BNXT_ULP_CHF_IDX_I_L3);
	if (inner_l3) {
		BNXT_TF_DBG(ERR, "Parse Error:Third L3 header not supported\n");
		return BNXT_TF_RC_ERROR;
	}

	/*
	 * Copy the rte_flow_item for ipv4 into hdr_field using ipv4
	 * header fields
	 */
	if (ipv4_spec) {
		size = sizeof(ipv4_spec->hdr.version_ihl);
		field = ulp_rte_parser_fld_copy(&params->hdr_field[idx],
						&ipv4_spec->hdr.version_ihl,
						size);
		size = sizeof(ipv4_spec->hdr.type_of_service);
		field = ulp_rte_parser_fld_copy(field,
						&ipv4_spec->hdr.type_of_service,
						size);
		size = sizeof(ipv4_spec->hdr.total_length);
		field = ulp_rte_parser_fld_copy(field,
						&ipv4_spec->hdr.total_length,
						size);
		size = sizeof(ipv4_spec->hdr.packet_id);
		field = ulp_rte_parser_fld_copy(field,
						&ipv4_spec->hdr.packet_id,
						size);
		size = sizeof(ipv4_spec->hdr.fragment_offset);
		field = ulp_rte_parser_fld_copy(field,
						&ipv4_spec->hdr.fragment_offset,
						size);
		size = sizeof(ipv4_spec->hdr.time_to_live);
		field = ulp_rte_parser_fld_copy(field,
						&ipv4_spec->hdr.time_to_live,
						size);
		size = sizeof(ipv4_spec->hdr.next_proto_id);
		field = ulp_rte_parser_fld_copy(field,
						&ipv4_spec->hdr.next_proto_id,
						size);
		size = sizeof(ipv4_spec->hdr.hdr_checksum);
		field = ulp_rte_parser_fld_copy(field,
						&ipv4_spec->hdr.hdr_checksum,
						size);
		size = sizeof(ipv4_spec->hdr.src_addr);
		field = ulp_rte_parser_fld_copy(field,
						&ipv4_spec->hdr.src_addr,
						size);
		size = sizeof(ipv4_spec->hdr.dst_addr);
		field = ulp_rte_parser_fld_copy(field,
						&ipv4_spec->hdr.dst_addr,
						size);
	}
	if (ipv4_mask) {
		ulp_rte_prsr_mask_copy(params, &idx,
				       &ipv4_mask->hdr.version_ihl,
				       sizeof(ipv4_mask->hdr.version_ihl));
		ulp_rte_prsr_mask_copy(params, &idx,
				       &ipv4_mask->hdr.type_of_service,
				       sizeof(ipv4_mask->hdr.type_of_service));
		ulp_rte_prsr_mask_copy(params, &idx,
				       &ipv4_mask->hdr.total_length,
				       sizeof(ipv4_mask->hdr.total_length));
		ulp_rte_prsr_mask_copy(params, &idx,
				       &ipv4_mask->hdr.packet_id,
				       sizeof(ipv4_mask->hdr.packet_id));
		ulp_rte_prsr_mask_copy(params, &idx,
				       &ipv4_mask->hdr.fragment_offset,
				       sizeof(ipv4_mask->hdr.fragment_offset));
		ulp_rte_prsr_mask_copy(params, &idx,
				       &ipv4_mask->hdr.time_to_live,
				       sizeof(ipv4_mask->hdr.time_to_live));
		ulp_rte_prsr_mask_copy(params, &idx,
				       &ipv4_mask->hdr.next_proto_id,
				       sizeof(ipv4_mask->hdr.next_proto_id));
		ulp_rte_prsr_mask_copy(params, &idx,
				       &ipv4_mask->hdr.hdr_checksum,
				       sizeof(ipv4_mask->hdr.hdr_checksum));
		ulp_rte_prsr_mask_copy(params, &idx,
				       &ipv4_mask->hdr.src_addr,
				       sizeof(ipv4_mask->hdr.src_addr));
		ulp_rte_prsr_mask_copy(params, &idx,
				       &ipv4_mask->hdr.dst_addr,
				       sizeof(ipv4_mask->hdr.dst_addr));
	}
	/* Add the number of ipv4 header elements */
	params->field_idx += BNXT_ULP_PROTO_HDR_IPV4_NUM;

	/* Set the ipv4 header bitmap and computed l3 header bitmaps */
	outer_l3 = ULP_UTIL_CHF_IDX_RD(params, BNXT_ULP_CHF_IDX_O_L3);
	if (outer_l3 ||
	    ULP_BITMAP_ISSET(hdr_bitmap->bits, BNXT_ULP_HDR_BIT_O_IPV4) ||
	    ULP_BITMAP_ISSET(hdr_bitmap->bits, BNXT_ULP_HDR_BIT_O_IPV6)) {
		ULP_BITMAP_SET(hdr_bitmap->bits, BNXT_ULP_HDR_BIT_I_IPV4);
		inner_l3++;
		ULP_UTIL_CHF_IDX_WR(params, BNXT_ULP_CHF_IDX_I_L3, inner_l3);
	} else {
		ULP_BITMAP_SET(hdr_bitmap->bits, BNXT_ULP_HDR_BIT_O_IPV4);
		outer_l3++;
		ULP_UTIL_CHF_IDX_WR(params, BNXT_ULP_CHF_IDX_O_L3, outer_l3);
	}
	return BNXT_TF_RC_SUCCESS;
}

/* Function to handle the parsing of RTE Flow item IPV6 Header */
int32_t
ulp_rte_ipv6_hdr_handler(const struct rte_flow_item *item,
			 struct ulp_rte_parser_params *params)
{
	const struct rte_flow_item_ipv6	*ipv6_spec = item->spec;
	const struct rte_flow_item_ipv6	*ipv6_mask = item->mask;
	struct ulp_rte_hdr_field *field;
	struct ulp_rte_hdr_bitmap *hdr_bitmap = &params->hdr_bitmap;
	uint32_t idx = params->field_idx;
	uint32_t size;
	uint32_t inner_l3, outer_l3;

	inner_l3 = ULP_UTIL_CHF_IDX_RD(params, BNXT_ULP_CHF_IDX_I_L3);
	if (inner_l3) {
		BNXT_TF_DBG(ERR, "Parse Error: 3'rd L3 header not supported\n");
		return BNXT_TF_RC_ERROR;
	}

	/*
	 * Copy the rte_flow_item for ipv4 into hdr_field using ipv4
	 * header fields
	 */
	if (ipv6_spec) {
		size = sizeof(ipv6_spec->hdr.vtc_flow);
		field = ulp_rte_parser_fld_copy(&params->hdr_field[idx],
						&ipv6_spec->hdr.vtc_flow,
						size);
		size = sizeof(ipv6_spec->hdr.payload_len);
		field = ulp_rte_parser_fld_copy(field,
						&ipv6_spec->hdr.payload_len,
						size);
		size = sizeof(ipv6_spec->hdr.proto);
		field = ulp_rte_parser_fld_copy(field,
						&ipv6_spec->hdr.proto,
						size);
		size = sizeof(ipv6_spec->hdr.hop_limits);
		field = ulp_rte_parser_fld_copy(field,
						&ipv6_spec->hdr.hop_limits,
						size);
		size = sizeof(ipv6_spec->hdr.src_addr);
		field = ulp_rte_parser_fld_copy(field,
						&ipv6_spec->hdr.src_addr,
						size);
		size = sizeof(ipv6_spec->hdr.dst_addr);
		field = ulp_rte_parser_fld_copy(field,
						&ipv6_spec->hdr.dst_addr,
						size);
	}
	if (ipv6_mask) {
		ulp_rte_prsr_mask_copy(params, &idx,
				       &ipv6_mask->hdr.vtc_flow,
				       sizeof(ipv6_mask->hdr.vtc_flow));
		ulp_rte_prsr_mask_copy(params, &idx,
				       &ipv6_mask->hdr.payload_len,
				       sizeof(ipv6_mask->hdr.payload_len));
		ulp_rte_prsr_mask_copy(params, &idx,
				       &ipv6_mask->hdr.proto,
				       sizeof(ipv6_mask->hdr.proto));
		ulp_rte_prsr_mask_copy(params, &idx,
				       &ipv6_mask->hdr.hop_limits,
				       sizeof(ipv6_mask->hdr.hop_limits));
		ulp_rte_prsr_mask_copy(params, &idx,
				       &ipv6_mask->hdr.src_addr,
				       sizeof(ipv6_mask->hdr.src_addr));
		ulp_rte_prsr_mask_copy(params, &idx,
				       &ipv6_mask->hdr.dst_addr,
				       sizeof(ipv6_mask->hdr.dst_addr));
	}
	/* add number of ipv6 header elements */
	params->field_idx += BNXT_ULP_PROTO_HDR_IPV6_NUM;

	/* Set the ipv6 header bitmap and computed l3 header bitmaps */
	outer_l3 = ULP_UTIL_CHF_IDX_RD(params, BNXT_ULP_CHF_IDX_O_L3);
	if (outer_l3 ||
	    ULP_BITMAP_ISSET(hdr_bitmap->bits, BNXT_ULP_HDR_BIT_O_IPV4) ||
	    ULP_BITMAP_ISSET(hdr_bitmap->bits, BNXT_ULP_HDR_BIT_O_IPV6)) {
		ULP_BITMAP_SET(hdr_bitmap->bits, BNXT_ULP_HDR_BIT_I_IPV6);
		ULP_UTIL_CHF_IDX_WR(params, BNXT_ULP_CHF_IDX_I_L3, 1);
	} else {
		ULP_BITMAP_SET(hdr_bitmap->bits, BNXT_ULP_HDR_BIT_O_IPV6);
		ULP_UTIL_CHF_IDX_WR(params, BNXT_ULP_CHF_IDX_O_L3, 1);
	}
	return BNXT_TF_RC_SUCCESS;
}

/* Function to handle the parsing of RTE Flow item UDP Header. */
int32_t
ulp_rte_udp_hdr_handler(const struct rte_flow_item *item,
			struct ulp_rte_parser_params *params)
{
	const struct rte_flow_item_udp *udp_spec = item->spec;
	const struct rte_flow_item_udp *udp_mask = item->mask;
	struct ulp_rte_hdr_field *field;
	struct ulp_rte_hdr_bitmap *hdr_bitmap = &params->hdr_bitmap;
	uint32_t idx = params->field_idx;
	uint32_t size;
	uint32_t inner_l4, outer_l4;

	inner_l4 = ULP_UTIL_CHF_IDX_RD(params, BNXT_ULP_CHF_IDX_I_L4);
	if (inner_l4) {
		BNXT_TF_DBG(ERR, "Parse Err:Third L4 header not supported\n");
		return BNXT_TF_RC_ERROR;
	}

	/*
	 * Copy the rte_flow_item for ipv4 into hdr_field using ipv4
	 * header fields
	 */
	if (udp_spec) {
		size = sizeof(udp_spec->hdr.src_port);
		field = ulp_rte_parser_fld_copy(&params->hdr_field[idx],
						&udp_spec->hdr.src_port,
						size);
		size = sizeof(udp_spec->hdr.dst_port);
		field = ulp_rte_parser_fld_copy(field,
						&udp_spec->hdr.dst_port,
						size);
		size = sizeof(udp_spec->hdr.dgram_len);
		field = ulp_rte_parser_fld_copy(field,
						&udp_spec->hdr.dgram_len,
						size);
		size = sizeof(udp_spec->hdr.dgram_cksum);
		field = ulp_rte_parser_fld_copy(field,
						&udp_spec->hdr.dgram_cksum,
						size);
	}
	if (udp_mask) {
		ulp_rte_prsr_mask_copy(params, &idx,
				       &udp_mask->hdr.src_port,
				       sizeof(udp_mask->hdr.src_port));
		ulp_rte_prsr_mask_copy(params, &idx,
				       &udp_mask->hdr.dst_port,
				       sizeof(udp_mask->hdr.dst_port));
		ulp_rte_prsr_mask_copy(params, &idx,
				       &udp_mask->hdr.dgram_len,
				       sizeof(udp_mask->hdr.dgram_len));
		ulp_rte_prsr_mask_copy(params, &idx,
				       &udp_mask->hdr.dgram_cksum,
				       sizeof(udp_mask->hdr.dgram_cksum));
	}

	/* Add number of UDP header elements */
	params->field_idx += BNXT_ULP_PROTO_HDR_UDP_NUM;

	/* Set the udp header bitmap and computed l4 header bitmaps */
	outer_l4 = ULP_UTIL_CHF_IDX_RD(params, BNXT_ULP_CHF_IDX_O_L4);
	if (outer_l4 ||
	    ULP_BITMAP_ISSET(hdr_bitmap->bits, BNXT_ULP_HDR_BIT_O_UDP) ||
	    ULP_BITMAP_ISSET(hdr_bitmap->bits, BNXT_ULP_HDR_BIT_O_TCP)) {
		ULP_BITMAP_SET(hdr_bitmap->bits, BNXT_ULP_HDR_BIT_I_UDP);
		ULP_UTIL_CHF_IDX_WR(params, BNXT_ULP_CHF_IDX_I_L4, 1);
	} else {
		ULP_BITMAP_SET(hdr_bitmap->bits, BNXT_ULP_HDR_BIT_O_UDP);
		ULP_UTIL_CHF_IDX_WR(params, BNXT_ULP_CHF_IDX_O_L4, 1);
	}
	return BNXT_TF_RC_SUCCESS;
}

/* Function to handle the parsing of RTE Flow item TCP Header. */
int32_t
ulp_rte_tcp_hdr_handler(const struct rte_flow_item *item,
			struct ulp_rte_parser_params *params)
{
	const struct rte_flow_item_tcp *tcp_spec = item->spec;
	const struct rte_flow_item_tcp *tcp_mask = item->mask;
	struct ulp_rte_hdr_field *field;
	struct ulp_rte_hdr_bitmap *hdr_bitmap = &params->hdr_bitmap;
	uint32_t idx = params->field_idx;
	uint32_t size;
	uint32_t inner_l4, outer_l4;

	inner_l4 = ULP_UTIL_CHF_IDX_RD(params, BNXT_ULP_CHF_IDX_I_L4);
	if (inner_l4) {
		BNXT_TF_DBG(ERR, "Parse Error:Third L4 header not supported\n");
		return BNXT_TF_RC_ERROR;
	}

	/*
	 * Copy the rte_flow_item for ipv4 into hdr_field using ipv4
	 * header fields
	 */
	if (tcp_spec) {
		size = sizeof(tcp_spec->hdr.src_port);
		field = ulp_rte_parser_fld_copy(&params->hdr_field[idx],
						&tcp_spec->hdr.src_port,
						size);
		size = sizeof(tcp_spec->hdr.dst_port);
		field = ulp_rte_parser_fld_copy(field,
						&tcp_spec->hdr.dst_port,
						size);
		size = sizeof(tcp_spec->hdr.sent_seq);
		field = ulp_rte_parser_fld_copy(field,
						&tcp_spec->hdr.sent_seq,
						size);
		size = sizeof(tcp_spec->hdr.recv_ack);
		field = ulp_rte_parser_fld_copy(field,
						&tcp_spec->hdr.recv_ack,
						size);
		size = sizeof(tcp_spec->hdr.data_off);
		field = ulp_rte_parser_fld_copy(field,
						&tcp_spec->hdr.data_off,
						size);
		size = sizeof(tcp_spec->hdr.tcp_flags);
		field = ulp_rte_parser_fld_copy(field,
						&tcp_spec->hdr.tcp_flags,
						size);
		size = sizeof(tcp_spec->hdr.rx_win);
		field = ulp_rte_parser_fld_copy(field,
						&tcp_spec->hdr.rx_win,
						size);
		size = sizeof(tcp_spec->hdr.cksum);
		field = ulp_rte_parser_fld_copy(field,
						&tcp_spec->hdr.cksum,
						size);
		size = sizeof(tcp_spec->hdr.tcp_urp);
		field = ulp_rte_parser_fld_copy(field,
						&tcp_spec->hdr.tcp_urp,
						size);
	} else {
		idx += BNXT_ULP_PROTO_HDR_TCP_NUM;
	}

	if (tcp_mask) {
		ulp_rte_prsr_mask_copy(params, &idx,
				       &tcp_mask->hdr.src_port,
				       sizeof(tcp_mask->hdr.src_port));
		ulp_rte_prsr_mask_copy(params, &idx,
				       &tcp_mask->hdr.dst_port,
				       sizeof(tcp_mask->hdr.dst_port));
		ulp_rte_prsr_mask_copy(params, &idx,
				       &tcp_mask->hdr.sent_seq,
				       sizeof(tcp_mask->hdr.sent_seq));
		ulp_rte_prsr_mask_copy(params, &idx,
				       &tcp_mask->hdr.recv_ack,
				       sizeof(tcp_mask->hdr.recv_ack));
		ulp_rte_prsr_mask_copy(params, &idx,
				       &tcp_mask->hdr.data_off,
				       sizeof(tcp_mask->hdr.data_off));
		ulp_rte_prsr_mask_copy(params, &idx,
				       &tcp_mask->hdr.tcp_flags,
				       sizeof(tcp_mask->hdr.tcp_flags));
		ulp_rte_prsr_mask_copy(params, &idx,
				       &tcp_mask->hdr.rx_win,
				       sizeof(tcp_mask->hdr.rx_win));
		ulp_rte_prsr_mask_copy(params, &idx,
				       &tcp_mask->hdr.cksum,
				       sizeof(tcp_mask->hdr.cksum));
		ulp_rte_prsr_mask_copy(params, &idx,
				       &tcp_mask->hdr.tcp_urp,
				       sizeof(tcp_mask->hdr.tcp_urp));
	}
	/* add number of TCP header elements */
	params->field_idx += BNXT_ULP_PROTO_HDR_TCP_NUM;

	/* Set the udp header bitmap and computed l4 header bitmaps */
	outer_l4 = ULP_UTIL_CHF_IDX_RD(params, BNXT_ULP_CHF_IDX_O_L4);
	if (outer_l4 ||
	    ULP_BITMAP_ISSET(hdr_bitmap->bits, BNXT_ULP_HDR_BIT_O_UDP) ||
	    ULP_BITMAP_ISSET(hdr_bitmap->bits, BNXT_ULP_HDR_BIT_O_TCP)) {
		ULP_BITMAP_SET(hdr_bitmap->bits, BNXT_ULP_HDR_BIT_I_TCP);
		ULP_UTIL_CHF_IDX_WR(params, BNXT_ULP_CHF_IDX_I_L4, 1);
	} else {
		ULP_BITMAP_SET(hdr_bitmap->bits, BNXT_ULP_HDR_BIT_O_TCP);
		ULP_UTIL_CHF_IDX_WR(params, BNXT_ULP_CHF_IDX_O_L4, 1);
	}
	return BNXT_TF_RC_SUCCESS;
}

/* Function to handle the parsing of RTE Flow item Vxlan Header. */
int32_t
ulp_rte_vxlan_hdr_handler(const struct rte_flow_item *item,
			  struct ulp_rte_parser_params *params)
{
	const struct rte_flow_item_vxlan *vxlan_spec = item->spec;
	const struct rte_flow_item_vxlan *vxlan_mask = item->mask;
	struct ulp_rte_hdr_field *field;
	struct ulp_rte_hdr_bitmap *hdr_bitmap = &params->hdr_bitmap;
	uint32_t idx = params->field_idx;
	uint32_t size;

	/*
	 * Copy the rte_flow_item for vxlan into hdr_field using vxlan
	 * header fields
	 */
	if (vxlan_spec) {
		size = sizeof(vxlan_spec->flags);
		field = ulp_rte_parser_fld_copy(&params->hdr_field[idx],
						&vxlan_spec->flags,
						size);
		size = sizeof(vxlan_spec->rsvd0);
		field = ulp_rte_parser_fld_copy(field,
						&vxlan_spec->rsvd0,
						size);
		size = sizeof(vxlan_spec->vni);
		field = ulp_rte_parser_fld_copy(field,
						&vxlan_spec->vni,
						size);
		size = sizeof(vxlan_spec->rsvd1);
		field = ulp_rte_parser_fld_copy(field,
						&vxlan_spec->rsvd1,
						size);
	}
	if (vxlan_mask) {
		ulp_rte_prsr_mask_copy(params, &idx,
				       &vxlan_mask->flags,
				       sizeof(vxlan_mask->flags));
		ulp_rte_prsr_mask_copy(params, &idx,
				       &vxlan_mask->rsvd0,
				       sizeof(vxlan_mask->rsvd0));
		ulp_rte_prsr_mask_copy(params, &idx,
				       &vxlan_mask->vni,
				       sizeof(vxlan_mask->vni));
		ulp_rte_prsr_mask_copy(params, &idx,
				       &vxlan_mask->rsvd1,
				       sizeof(vxlan_mask->rsvd1));
	}
	/* Add number of vxlan header elements */
	params->field_idx += BNXT_ULP_PROTO_HDR_VXLAN_NUM;

	/* Update the hdr_bitmap with vxlan */
	ULP_BITMAP_SET(hdr_bitmap->bits, BNXT_ULP_HDR_BIT_T_VXLAN);
	return BNXT_TF_RC_SUCCESS;
}

/* Function to handle the parsing of RTE Flow item void Header */
int32_t
ulp_rte_void_hdr_handler(const struct rte_flow_item *item __rte_unused,
			 struct ulp_rte_parser_params *params __rte_unused)
{
	return BNXT_TF_RC_SUCCESS;
}

/* Function to handle the parsing of RTE Flow action void Header. */
int32_t
ulp_rte_void_act_handler(const struct rte_flow_action *action_item __rte_unused,
			 struct ulp_rte_parser_params *params __rte_unused)
{
	return BNXT_TF_RC_SUCCESS;
}

/* Function to handle the parsing of RTE Flow action Mark Header. */
int32_t
ulp_rte_mark_act_handler(const struct rte_flow_action *action_item,
			 struct ulp_rte_parser_params *param)
{
	const struct rte_flow_action_mark *mark;
	struct ulp_rte_act_bitmap *act = &param->act_bitmap;
	uint32_t mark_id;

	mark = action_item->conf;
	if (mark) {
		mark_id = tfp_cpu_to_be_32(mark->id);
		memcpy(&param->act_prop.act_details[BNXT_ULP_ACT_PROP_IDX_MARK],
		       &mark_id, BNXT_ULP_ACT_PROP_SZ_MARK);

		/* Update the hdr_bitmap with vxlan */
		ULP_BITMAP_SET(act->bits, BNXT_ULP_ACTION_BIT_MARK);
		return BNXT_TF_RC_SUCCESS;
	}
	BNXT_TF_DBG(ERR, "Parse Error: Mark arg is invalid\n");
	return BNXT_TF_RC_ERROR;
}

/* Function to handle the parsing of RTE Flow action RSS Header. */
int32_t
ulp_rte_rss_act_handler(const struct rte_flow_action *action_item,
			struct ulp_rte_parser_params *param)
{
	const struct rte_flow_action_rss *rss = action_item->conf;

	if (rss) {
		/* Update the hdr_bitmap with vxlan */
		ULP_BITMAP_SET(param->act_bitmap.bits, BNXT_ULP_ACTION_BIT_RSS);
		return BNXT_TF_RC_SUCCESS;
	}
	BNXT_TF_DBG(ERR, "Parse Error: RSS arg is invalid\n");
	return BNXT_TF_RC_ERROR;
}

/* Function to handle the parsing of RTE Flow action vxlan_encap Header. */
int32_t
ulp_rte_vxlan_encap_act_handler(const struct rte_flow_action *action_item,
				struct ulp_rte_parser_params *params)
{
	const struct rte_flow_action_vxlan_encap *vxlan_encap;
	const struct rte_flow_item *item;
	const struct rte_flow_item_eth *eth_spec;
	const struct rte_flow_item_ipv4 *ipv4_spec;
	const struct rte_flow_item_ipv6 *ipv6_spec;
	struct rte_flow_item_vxlan vxlan_spec;
	uint32_t vlan_num = 0, vlan_size = 0;
	uint32_t ip_size = 0, ip_type = 0;
	uint32_t vxlan_size = 0;
	uint8_t *buff;
	/* IP header per byte - ver/hlen, TOS, ID, ID, FRAG, FRAG, TTL, PROTO */
	const uint8_t def_ipv4_hdr[] = {0x45, 0x00, 0x00, 0x01, 0x00,
				    0x00, 0x40, 0x11};
	struct ulp_rte_act_bitmap *act = &params->act_bitmap;
	struct ulp_rte_act_prop *ap = &params->act_prop;

	vxlan_encap = action_item->conf;
	if (!vxlan_encap) {
		BNXT_TF_DBG(ERR, "Parse Error: Vxlan_encap arg is invalid\n");
		return BNXT_TF_RC_ERROR;
	}

	item = vxlan_encap->definition;
	if (!item) {
		BNXT_TF_DBG(ERR, "Parse Error: definition arg is invalid\n");
		return BNXT_TF_RC_ERROR;
	}

	if (!ulp_rte_item_skip_void(&item, 0))
		return BNXT_TF_RC_ERROR;

	/* must have ethernet header */
	if (item->type != RTE_FLOW_ITEM_TYPE_ETH) {
		BNXT_TF_DBG(ERR, "Parse Error:vxlan encap does not have eth\n");
		return BNXT_TF_RC_ERROR;
	}
	eth_spec = item->spec;
	buff = &ap->act_details[BNXT_ULP_ACT_PROP_IDX_ENCAP_L2_DMAC];
	ulp_encap_buffer_copy(buff,
			      eth_spec->dst.addr_bytes,
			      BNXT_ULP_ACT_PROP_SZ_ENCAP_L2_DMAC);

	/* Goto the next item */
	if (!ulp_rte_item_skip_void(&item, 1))
		return BNXT_TF_RC_ERROR;

	/* May have vlan header */
	if (item->type == RTE_FLOW_ITEM_TYPE_VLAN) {
		vlan_num++;
		buff = &ap->act_details[BNXT_ULP_ACT_PROP_IDX_ENCAP_VTAG];
		ulp_encap_buffer_copy(buff,
				      item->spec,
				      sizeof(struct rte_flow_item_vlan));

		if (!ulp_rte_item_skip_void(&item, 1))
			return BNXT_TF_RC_ERROR;
	}

	/* may have two vlan headers */
	if (item->type == RTE_FLOW_ITEM_TYPE_VLAN) {
		vlan_num++;
		memcpy(&ap->act_details[BNXT_ULP_ACT_PROP_IDX_ENCAP_VTAG +
		       sizeof(struct rte_flow_item_vlan)],
		       item->spec,
		       sizeof(struct rte_flow_item_vlan));
		if (!ulp_rte_item_skip_void(&item, 1))
			return BNXT_TF_RC_ERROR;
	}
	/* Update the vlan count and size of more than one */
	if (vlan_num) {
		vlan_size = vlan_num * sizeof(struct rte_flow_item_vlan);
		vlan_num = tfp_cpu_to_be_32(vlan_num);
		memcpy(&ap->act_details[BNXT_ULP_ACT_PROP_IDX_ENCAP_VTAG_NUM],
		       &vlan_num,
		       sizeof(uint32_t));
		vlan_size = tfp_cpu_to_be_32(vlan_size);
		memcpy(&ap->act_details[BNXT_ULP_ACT_PROP_IDX_ENCAP_VTAG_SZ],
		       &vlan_size,
		       sizeof(uint32_t));
	}

	/* L3 must be IPv4, IPv6 */
	if (item->type == RTE_FLOW_ITEM_TYPE_IPV4) {
		ipv4_spec = item->spec;
		ip_size = BNXT_ULP_ENCAP_IPV4_SIZE;

		/* copy the ipv4 details */
		if (ulp_buffer_is_empty(&ipv4_spec->hdr.version_ihl,
					BNXT_ULP_ENCAP_IPV4_VER_HLEN_TOS)) {
			buff = &ap->act_details[BNXT_ULP_ACT_PROP_IDX_ENCAP_IP];
			ulp_encap_buffer_copy(buff,
					      def_ipv4_hdr,
					      BNXT_ULP_ENCAP_IPV4_VER_HLEN_TOS +
					      BNXT_ULP_ENCAP_IPV4_ID_PROTO);
		} else {
			const uint8_t *tmp_buff;

			buff = &ap->act_details[BNXT_ULP_ACT_PROP_IDX_ENCAP_IP];
			ulp_encap_buffer_copy(buff,
					      &ipv4_spec->hdr.version_ihl,
					      BNXT_ULP_ENCAP_IPV4_VER_HLEN_TOS);
			buff = &ap->act_details[BNXT_ULP_ACT_PROP_IDX_ENCAP_IP +
			     BNXT_ULP_ENCAP_IPV4_VER_HLEN_TOS];
			tmp_buff = (const uint8_t *)&ipv4_spec->hdr.packet_id;
			ulp_encap_buffer_copy(buff,
					      tmp_buff,
					      BNXT_ULP_ENCAP_IPV4_ID_PROTO);
		}
		buff = &ap->act_details[BNXT_ULP_ACT_PROP_IDX_ENCAP_IP +
		    BNXT_ULP_ENCAP_IPV4_VER_HLEN_TOS +
		    BNXT_ULP_ENCAP_IPV4_ID_PROTO];
		ulp_encap_buffer_copy(buff,
				      (const uint8_t *)&ipv4_spec->hdr.dst_addr,
				      BNXT_ULP_ENCAP_IPV4_DEST_IP);

		/* Update the ip size details */
		ip_size = tfp_cpu_to_be_32(ip_size);
		memcpy(&ap->act_details[BNXT_ULP_ACT_PROP_IDX_ENCAP_IP_SZ],
		       &ip_size, sizeof(uint32_t));

		/* update the ip type */
		ip_type = rte_cpu_to_be_32(BNXT_ULP_ETH_IPV4);
		memcpy(&ap->act_details[BNXT_ULP_ACT_PROP_IDX_ENCAP_L3_TYPE],
		       &ip_type, sizeof(uint32_t));

		if (!ulp_rte_item_skip_void(&item, 1))
			return BNXT_TF_RC_ERROR;
	} else if (item->type == RTE_FLOW_ITEM_TYPE_IPV6) {
		ipv6_spec = item->spec;
		ip_size = BNXT_ULP_ENCAP_IPV6_SIZE;

		/* copy the ipv4 details */
		memcpy(&ap->act_details[BNXT_ULP_ACT_PROP_IDX_ENCAP_IP],
		       ipv6_spec, BNXT_ULP_ENCAP_IPV6_SIZE);

		/* Update the ip size details */
		ip_size = tfp_cpu_to_be_32(ip_size);
		memcpy(&ap->act_details[BNXT_ULP_ACT_PROP_IDX_ENCAP_IP_SZ],
		       &ip_size, sizeof(uint32_t));

		 /* update the ip type */
		ip_type = rte_cpu_to_be_32(BNXT_ULP_ETH_IPV6);
		memcpy(&ap->act_details[BNXT_ULP_ACT_PROP_IDX_ENCAP_L3_TYPE],
		       &ip_type, sizeof(uint32_t));

		if (!ulp_rte_item_skip_void(&item, 1))
			return BNXT_TF_RC_ERROR;
	} else {
		BNXT_TF_DBG(ERR, "Parse Error: Vxlan Encap expects L3 hdr\n");
		return BNXT_TF_RC_ERROR;
	}

	/* L4 is UDP */
	if (item->type != RTE_FLOW_ITEM_TYPE_UDP) {
		BNXT_TF_DBG(ERR, "vxlan encap does not have udp\n");
		return BNXT_TF_RC_ERROR;
	}
	/* copy the udp details */
	ulp_encap_buffer_copy(&ap->act_details[BNXT_ULP_ACT_PROP_IDX_ENCAP_UDP],
			      item->spec, BNXT_ULP_ENCAP_UDP_SIZE);

	if (!ulp_rte_item_skip_void(&item, 1))
		return BNXT_TF_RC_ERROR;

	/* Finally VXLAN */
	if (item->type != RTE_FLOW_ITEM_TYPE_VXLAN) {
		BNXT_TF_DBG(ERR, "vxlan encap does not have vni\n");
		return BNXT_TF_RC_ERROR;
	}
	vxlan_size = sizeof(struct rte_flow_item_vxlan);
	/* copy the vxlan details */
	memcpy(&vxlan_spec, item->spec, vxlan_size);
	vxlan_spec.flags = 0x08;
	ulp_encap_buffer_copy(&ap->act_details[BNXT_ULP_ACT_PROP_IDX_ENCAP_TUN],
			      (const uint8_t *)&vxlan_spec,
			      vxlan_size);
	vxlan_size = tfp_cpu_to_be_32(vxlan_size);
	memcpy(&ap->act_details[BNXT_ULP_ACT_PROP_IDX_ENCAP_TUN_SZ],
	       &vxlan_size, sizeof(uint32_t));

	/*update the hdr_bitmap with vxlan */
	ULP_BITMAP_SET(act->bits, BNXT_ULP_ACTION_BIT_VXLAN_ENCAP);
	return BNXT_TF_RC_SUCCESS;
}

/* Function to handle the parsing of RTE Flow action vxlan_encap Header */
int32_t
ulp_rte_vxlan_decap_act_handler(const struct rte_flow_action *action_item
				__rte_unused,
				struct ulp_rte_parser_params *params)
{
	/* update the hdr_bitmap with vxlan */
	ULP_BITMAP_SET(params->act_bitmap.bits,
		       BNXT_ULP_ACTION_BIT_VXLAN_DECAP);
	return BNXT_TF_RC_SUCCESS;
}

/* Function to handle the parsing of RTE Flow action drop Header. */
int32_t
ulp_rte_drop_act_handler(const struct rte_flow_action *action_item __rte_unused,
			 struct ulp_rte_parser_params *params)
{
	/* Update the hdr_bitmap with drop */
	ULP_BITMAP_SET(params->act_bitmap.bits, BNXT_ULP_ACTION_BIT_DROP);
	return BNXT_TF_RC_SUCCESS;
}

/* Function to handle the parsing of RTE Flow action count. */
int32_t
ulp_rte_count_act_handler(const struct rte_flow_action *action_item,
			  struct ulp_rte_parser_params *params)

{
	const struct rte_flow_action_count *act_count;
	struct ulp_rte_act_prop *act_prop = &params->act_prop;

	act_count = action_item->conf;
	if (act_count) {
		if (act_count->shared) {
			BNXT_TF_DBG(ERR,
				    "Parse Error:Shared count not supported\n");
			return BNXT_TF_RC_PARSE_ERR;
		}
		memcpy(&act_prop->act_details[BNXT_ULP_ACT_PROP_IDX_COUNT],
		       &act_count->id,
		       BNXT_ULP_ACT_PROP_SZ_COUNT);
	}

	/* Update the hdr_bitmap with count */
	ULP_BITMAP_SET(params->act_bitmap.bits, BNXT_ULP_ACTION_BIT_COUNT);
	return BNXT_TF_RC_SUCCESS;
}

/* Function to handle the parsing of RTE Flow action PF. */
int32_t
ulp_rte_pf_act_handler(const struct rte_flow_action *action_item __rte_unused,
		       struct ulp_rte_parser_params *params)
{
	uint32_t svif;

	/* Update the hdr_bitmap with vnic bit */
	ULP_BITMAP_SET(params->act_bitmap.bits, BNXT_ULP_ACTION_BIT_VNIC);

	/* copy the PF of the current device into VNIC Property */
	svif = ULP_UTIL_CHF_IDX_RD(params, BNXT_ULP_CHF_IDX_INCOMING_IF);
	svif = bnxt_get_vnic_id(svif);
	svif = rte_cpu_to_be_32(svif);
	memcpy(&params->act_prop.act_details[BNXT_ULP_ACT_PROP_IDX_VNIC],
	       &svif, BNXT_ULP_ACT_PROP_SZ_VNIC);

	return BNXT_TF_RC_SUCCESS;
}

/* Function to handle the parsing of RTE Flow action VF. */
int32_t
ulp_rte_vf_act_handler(const struct rte_flow_action *action_item,
		       struct ulp_rte_parser_params *param)
{
	const struct rte_flow_action_vf *vf_action;
	uint32_t pid;

	vf_action = action_item->conf;
	if (vf_action) {
		if (vf_action->original) {
			BNXT_TF_DBG(ERR,
				    "Parse Error:VF Original not supported\n");
			return BNXT_TF_RC_PARSE_ERR;
		}
		/* TBD: Update the computed VNIC using VF conversion */
		pid = bnxt_get_vnic_id(vf_action->id);
		pid = rte_cpu_to_be_32(pid);
		memcpy(&param->act_prop.act_details[BNXT_ULP_ACT_PROP_IDX_VNIC],
		       &pid, BNXT_ULP_ACT_PROP_SZ_VNIC);
	}

	/* Update the hdr_bitmap with count */
	ULP_BITMAP_SET(param->act_bitmap.bits, BNXT_ULP_ACTION_BIT_VNIC);
	return BNXT_TF_RC_SUCCESS;
}

/* Function to handle the parsing of RTE Flow action port_id. */
int32_t
ulp_rte_port_id_act_handler(const struct rte_flow_action *act_item,
			    struct ulp_rte_parser_params *param)
{
	const struct rte_flow_action_port_id *port_id;
	uint32_t pid;

	port_id = act_item->conf;
	if (port_id) {
		if (port_id->original) {
			BNXT_TF_DBG(ERR,
				    "ParseErr:Portid Original not supported\n");
			return BNXT_TF_RC_PARSE_ERR;
		}
		/* TBD: Update the computed VNIC using port conversion */
		pid = bnxt_get_vnic_id(port_id->id);
		pid = rte_cpu_to_be_32(pid);
		memcpy(&param->act_prop.act_details[BNXT_ULP_ACT_PROP_IDX_VNIC],
		       &pid, BNXT_ULP_ACT_PROP_SZ_VNIC);
	}

	/* Update the hdr_bitmap with count */
	ULP_BITMAP_SET(param->act_bitmap.bits, BNXT_ULP_ACTION_BIT_VNIC);
	return BNXT_TF_RC_SUCCESS;
}

/* Function to handle the parsing of RTE Flow action phy_port. */
int32_t
ulp_rte_phy_port_act_handler(const struct rte_flow_action *action_item,
			     struct ulp_rte_parser_params *prm)
{
	const struct rte_flow_action_phy_port *phy_port;
	uint32_t pid;

	phy_port = action_item->conf;
	if (phy_port) {
		if (phy_port->original) {
			BNXT_TF_DBG(ERR,
				    "Parse Err:Port Original not supported\n");
			return BNXT_TF_RC_PARSE_ERR;
		}
		pid = bnxt_get_vnic_id(phy_port->index);
		pid = rte_cpu_to_be_32(pid);
		memcpy(&prm->act_prop.act_details[BNXT_ULP_ACT_PROP_IDX_VPORT],
		       &pid, BNXT_ULP_ACT_PROP_SZ_VPORT);
	}

	/* Update the hdr_bitmap with count */
	ULP_BITMAP_SET(prm->act_bitmap.bits, BNXT_ULP_ACTION_BIT_VPORT);
	return BNXT_TF_RC_SUCCESS;
}