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
|
/* SPDX-License-Identifier: BSD-3-Clause
* Copyright(c) 2019-2023 Broadcom
* All rights reserved.
*/
#include "bnxt_tf_common.h"
#include "bnxt_ulp_utils.h"
#include "ulp_template_struct.h"
#include "ulp_template_db_enum.h"
#include "ulp_template_db_field.h"
#include "ulp_utils.h"
#include "ulp_port_db.h"
#include "ulp_flow_db.h"
#include "ulp_mapper.h"
#include "ulp_rte_parser.h"
static void
ulp_l2_custom_tunnel_id_update(struct bnxt *bp,
struct bnxt_ulp_mapper_parms *params);
struct bnxt_ulp_def_param_handler {
int32_t (*vfr_func)(struct bnxt_ulp_context *ulp_ctx,
struct ulp_tlv_param *param,
struct bnxt_ulp_mapper_parms *mapper_params);
};
static int32_t
ulp_set_svif_in_comp_fld(struct bnxt_ulp_context *ulp_ctx,
uint32_t ifindex, uint8_t svif_type,
struct bnxt_ulp_mapper_parms *mapper_params)
{
uint16_t svif;
uint8_t idx;
int rc;
rc = ulp_port_db_svif_get(ulp_ctx, ifindex, svif_type, &svif);
if (rc)
return rc;
if (svif_type == BNXT_ULP_PHY_PORT_SVIF)
idx = BNXT_ULP_CF_IDX_PHY_PORT_SVIF;
else if (svif_type == BNXT_ULP_DRV_FUNC_SVIF)
idx = BNXT_ULP_CF_IDX_DRV_FUNC_SVIF;
else
idx = BNXT_ULP_CF_IDX_VF_FUNC_SVIF;
ULP_COMP_FLD_IDX_WR(mapper_params, idx, svif);
return 0;
}
static int32_t
ulp_set_spif_in_comp_fld(struct bnxt_ulp_context *ulp_ctx,
uint32_t ifindex, uint8_t spif_type,
struct bnxt_ulp_mapper_parms *mapper_params)
{
uint16_t spif;
uint8_t idx;
int rc;
rc = ulp_port_db_spif_get(ulp_ctx, ifindex, spif_type, &spif);
if (rc)
return rc;
if (spif_type == BNXT_ULP_PHY_PORT_SPIF)
idx = BNXT_ULP_CF_IDX_PHY_PORT_SPIF;
else if (spif_type == BNXT_ULP_DRV_FUNC_SPIF)
idx = BNXT_ULP_CF_IDX_DRV_FUNC_SPIF;
else
idx = BNXT_ULP_CF_IDX_VF_FUNC_SPIF;
ULP_COMP_FLD_IDX_WR(mapper_params, idx, spif);
return 0;
}
static int32_t
ulp_set_parif_in_comp_fld(struct bnxt_ulp_context *ulp_ctx,
uint32_t ifindex, uint8_t parif_type,
struct bnxt_ulp_mapper_parms *mapper_params)
{
uint16_t parif;
uint8_t idx;
int rc;
rc = ulp_port_db_parif_get(ulp_ctx, ifindex, parif_type, &parif);
if (rc)
return rc;
if (parif_type == BNXT_ULP_PHY_PORT_PARIF)
idx = BNXT_ULP_CF_IDX_PHY_PORT_PARIF;
else if (parif_type == BNXT_ULP_DRV_FUNC_PARIF)
idx = BNXT_ULP_CF_IDX_DRV_FUNC_PARIF;
else
idx = BNXT_ULP_CF_IDX_VF_FUNC_PARIF;
ULP_COMP_FLD_IDX_WR(mapper_params, idx, parif);
return 0;
}
static int32_t
ulp_set_vport_in_comp_fld(struct bnxt_ulp_context *ulp_ctx, uint32_t ifindex,
struct bnxt_ulp_mapper_parms *mapper_params)
{
uint16_t vport;
int rc;
rc = ulp_port_db_vport_get(ulp_ctx, ifindex, &vport);
if (rc)
return rc;
ULP_COMP_FLD_IDX_WR(mapper_params, BNXT_ULP_CF_IDX_PHY_PORT_VPORT,
vport);
return 0;
}
static int32_t
ulp_set_vnic_in_comp_fld(struct bnxt_ulp_context *ulp_ctx,
uint32_t ifindex, uint8_t vnic_type,
struct bnxt_ulp_mapper_parms *mapper_params)
{
uint16_t vnic;
uint8_t idx;
int rc;
rc = ulp_port_db_default_vnic_get(ulp_ctx, ifindex, vnic_type, &vnic);
if (rc)
return rc;
if (vnic_type == BNXT_ULP_DRV_FUNC_VNIC)
idx = BNXT_ULP_CF_IDX_DRV_FUNC_VNIC;
else
idx = BNXT_ULP_CF_IDX_VF_FUNC_VNIC;
ULP_COMP_FLD_IDX_WR(mapper_params, idx, vnic);
return 0;
}
static int32_t
ulp_set_vlan_in_act_prop(uint16_t port_id,
struct bnxt_ulp_mapper_parms *mapper_params)
{
struct ulp_rte_act_prop *act_prop = mapper_params->act_prop;
if (ULP_BITMAP_ISSET(mapper_params->act_bitmap->bits,
BNXT_ULP_ACT_BIT_SET_VLAN_VID)) {
BNXT_DRV_DBG(ERR,
"VLAN already set, multiple VLANs unsupported\n");
return BNXT_TF_RC_ERROR;
}
port_id = rte_cpu_to_be_16(port_id);
ULP_BITMAP_SET(mapper_params->act_bitmap->bits,
BNXT_ULP_ACT_BIT_SET_VLAN_VID);
memcpy(&act_prop->act_details[BNXT_ULP_ACT_PROP_IDX_ENCAP_VTAG],
&port_id, sizeof(port_id));
return 0;
}
static int32_t
ulp_set_mark_in_act_prop(uint16_t port_id,
struct bnxt_ulp_mapper_parms *mapper_params)
{
if (ULP_BITMAP_ISSET(mapper_params->act_bitmap->bits,
BNXT_ULP_ACT_BIT_MARK)) {
BNXT_DRV_DBG(ERR,
"MARK already set, multiple MARKs unsupported\n");
return BNXT_TF_RC_ERROR;
}
ULP_COMP_FLD_IDX_WR(mapper_params, BNXT_ULP_CF_IDX_DEV_PORT_ID,
port_id);
return 0;
}
static int32_t
ulp_df_dev_port_handler(struct bnxt_ulp_context *ulp_ctx,
struct ulp_tlv_param *param,
struct bnxt_ulp_mapper_parms *mapper_params)
{
uint16_t port_id;
uint16_t parif;
uint32_t ifindex;
int rc;
port_id = param->value[0] | param->value[1];
rc = ulp_port_db_dev_port_to_ulp_index(ulp_ctx, port_id, &ifindex);
if (rc) {
BNXT_DRV_DBG(ERR, "Invalid port id\n");
return BNXT_TF_RC_ERROR;
}
/* Set port SVIF */
rc = ulp_set_svif_in_comp_fld(ulp_ctx, ifindex, BNXT_ULP_PHY_PORT_SVIF,
mapper_params);
if (rc)
return rc;
/* Set DRV Func SVIF */
rc = ulp_set_svif_in_comp_fld(ulp_ctx, ifindex, BNXT_ULP_DRV_FUNC_SVIF,
mapper_params);
if (rc)
return rc;
/* Set VF Func SVIF */
rc = ulp_set_svif_in_comp_fld(ulp_ctx, ifindex, BNXT_ULP_VF_FUNC_SVIF,
mapper_params);
if (rc)
return rc;
/* Set port SPIF */
rc = ulp_set_spif_in_comp_fld(ulp_ctx, ifindex, BNXT_ULP_PHY_PORT_SPIF,
mapper_params);
if (rc)
return rc;
/* Set DRV Func SPIF */
rc = ulp_set_spif_in_comp_fld(ulp_ctx, ifindex, BNXT_ULP_DRV_FUNC_SPIF,
mapper_params);
if (rc)
return rc;
/* Set VF Func SPIF */
rc = ulp_set_spif_in_comp_fld(ulp_ctx, ifindex, BNXT_ULP_DRV_FUNC_SPIF,
mapper_params);
if (rc)
return rc;
/* Set port PARIF */
rc = ulp_set_parif_in_comp_fld(ulp_ctx, ifindex,
BNXT_ULP_PHY_PORT_PARIF, mapper_params);
if (rc)
return rc;
/* Set DRV Func PARIF */
rc = ulp_set_parif_in_comp_fld(ulp_ctx, ifindex,
BNXT_ULP_DRV_FUNC_PARIF, mapper_params);
if (rc)
return rc;
/* Note:
* We save the drv_func_parif into CF_IDX of phy_port_parif,
* since that index is currently referenced by ingress templates
* for datapath flows. If in the future we change the parser to
* save it in the CF_IDX of drv_func_parif we also need to update
* the template.
* WARNING: Two VFs on same parent PF will not work, as the parif is
* based on fw fid of the parent PF.
*/
parif = ULP_COMP_FLD_IDX_RD(mapper_params, BNXT_ULP_CF_IDX_DRV_FUNC_PARIF);
ULP_COMP_FLD_IDX_WR(mapper_params, BNXT_ULP_CF_IDX_PHY_PORT_PARIF, parif);
/* Set VF Func PARIF */
rc = ulp_set_parif_in_comp_fld(ulp_ctx, ifindex, BNXT_ULP_VF_FUNC_PARIF,
mapper_params);
if (rc)
return rc;
/* Set uplink VNIC */
rc = ulp_set_vnic_in_comp_fld(ulp_ctx, ifindex, true, mapper_params);
if (rc)
return rc;
/* Set VF VNIC */
rc = ulp_set_vnic_in_comp_fld(ulp_ctx, ifindex, false, mapper_params);
if (rc)
return rc;
/* Set VPORT */
rc = ulp_set_vport_in_comp_fld(ulp_ctx, ifindex, mapper_params);
if (rc)
return rc;
/* Set VLAN */
rc = ulp_set_vlan_in_act_prop(port_id, mapper_params);
if (rc)
return rc;
/* Set MARK */
rc = ulp_set_mark_in_act_prop(port_id, mapper_params);
if (rc)
return rc;
return 0;
}
struct bnxt_ulp_def_param_handler ulp_def_handler_tbl[] = {
[BNXT_ULP_DF_PARAM_TYPE_DEV_PORT_ID] = {
.vfr_func = ulp_df_dev_port_handler }
};
/*
* Function to create default rules for the following paths
* 1) Device PORT to DPDK App
* 2) DPDK App to Device PORT
* 3) VF Representor to VF
* 4) VF to VF Representor
*
* eth_dev [in] Ptr to rte eth device.
* param_list [in] Ptr to a list of parameters (Currently, only DPDK port_id).
* ulp_class_tid [in] Class template ID number.
* flow_id [out] Ptr to flow identifier.
*
* Returns 0 on success or negative number on failure.
*/
int32_t
ulp_default_flow_create(struct rte_eth_dev *eth_dev,
struct ulp_tlv_param *param_list,
uint32_t ulp_class_tid,
uint16_t port_id,
uint32_t *flow_id)
{
struct ulp_rte_hdr_field hdr_field[BNXT_ULP_PROTO_HDR_MAX];
uint64_t comp_fld[BNXT_ULP_CF_IDX_LAST];
struct bnxt_ulp_mapper_parms mapper_params = { 0 };
struct ulp_rte_act_prop act_prop;
struct ulp_rte_act_bitmap act = { 0 };
struct bnxt_ulp_context *ulp_ctx;
uint32_t type, ulp_flags = 0, fid;
struct bnxt *bp = eth_dev->data->dev_private;
uint16_t static_port = 0;
int rc = 0;
memset(&mapper_params, 0, sizeof(mapper_params));
memset(hdr_field, 0, sizeof(hdr_field));
memset(comp_fld, 0, sizeof(comp_fld));
memset(&act_prop, 0, sizeof(act_prop));
mapper_params.hdr_field = hdr_field;
mapper_params.act_bitmap = &act;
mapper_params.act_prop = &act_prop;
mapper_params.comp_fld = comp_fld;
mapper_params.class_tid = ulp_class_tid;
mapper_params.flow_type = BNXT_ULP_FDB_TYPE_DEFAULT;
mapper_params.port_id = eth_dev->data->port_id;
ulp_ctx = bnxt_ulp_eth_dev_ptr2_cntxt_get(eth_dev);
if (!ulp_ctx) {
BNXT_DRV_DBG(ERR,
"ULP is not init'ed. Fail to create dflt flow.\n");
return -EINVAL;
}
/* update the vf rep flag */
if (bnxt_ulp_cntxt_ptr2_ulp_flags_get(ulp_ctx, &ulp_flags)) {
BNXT_DRV_DBG(ERR, "Error in getting ULP context flags\n");
return -EINVAL;
}
if (ULP_VF_REP_IS_ENABLED(ulp_flags))
ULP_COMP_FLD_IDX_WR(&mapper_params,
BNXT_ULP_CF_IDX_VFR_MODE, 1);
type = param_list->type;
while (type != BNXT_ULP_DF_PARAM_TYPE_LAST) {
if (ulp_def_handler_tbl[type].vfr_func) {
rc = ulp_def_handler_tbl[type].vfr_func(ulp_ctx,
param_list,
&mapper_params);
if (rc) {
BNXT_DRV_DBG(ERR,
"Failed to create default flow.\n");
return rc;
}
}
param_list++;
type = param_list->type;
}
/* Get the function id */
if (ulp_port_db_port_func_id_get(ulp_ctx,
port_id,
&mapper_params.func_id)) {
BNXT_DRV_DBG(ERR, "conversion of port to func id failed\n");
goto err1;
}
/* update the VF meta function id */
ULP_COMP_FLD_IDX_WR(&mapper_params, BNXT_ULP_CF_IDX_VF_META_FID,
BNXT_ULP_META_VF_FLAG | mapper_params.func_id);
/* update the upar id */
ulp_l2_custom_tunnel_id_update(bp, &mapper_params);
/* update the vxlan port */
if (ULP_APP_STATIC_VXLAN_PORT_EN(ulp_ctx)) {
static_port = bnxt_ulp_cntxt_vxlan_port_get(ulp_ctx);
if (static_port) {
ULP_COMP_FLD_IDX_WR(&mapper_params,
BNXT_ULP_CF_IDX_TUNNEL_PORT,
static_port);
ULP_BITMAP_SET(mapper_params.cf_bitmap,
BNXT_ULP_CF_BIT_STATIC_VXLAN_PORT);
} else {
static_port = bnxt_ulp_cntxt_vxlan_ip_port_get(ulp_ctx);
ULP_COMP_FLD_IDX_WR(&mapper_params,
BNXT_ULP_CF_IDX_TUNNEL_PORT,
static_port);
ULP_BITMAP_SET(mapper_params.cf_bitmap,
BNXT_ULP_CF_BIT_STATIC_VXLAN_IP_PORT);
}
}
BNXT_DRV_DBG(DEBUG, "Creating default flow with template id: %u\n",
ulp_class_tid);
/* Protect flow creation */
if (bnxt_ulp_cntxt_acquire_fdb_lock(ulp_ctx)) {
BNXT_DRV_DBG(ERR, "Flow db lock acquire failed\n");
goto err1;
}
rc = ulp_flow_db_fid_alloc(ulp_ctx, mapper_params.flow_type,
mapper_params.func_id, &fid);
if (rc) {
BNXT_DRV_DBG(ERR, "Unable to allocate flow table entry\n");
goto err2;
}
mapper_params.flow_id = fid;
rc = ulp_mapper_flow_create(ulp_ctx, &mapper_params,
NULL);
if (rc)
goto err3;
bnxt_ulp_cntxt_release_fdb_lock(ulp_ctx);
*flow_id = fid;
return 0;
err3:
ulp_flow_db_fid_free(ulp_ctx, mapper_params.flow_type, fid);
err2:
bnxt_ulp_cntxt_release_fdb_lock(ulp_ctx);
err1:
BNXT_DRV_DBG(ERR, "Failed to create default flow.\n");
return rc;
}
/*
* Function to destroy default rules for the following paths
* 1) Device PORT to DPDK App
* 2) DPDK App to Device PORT
* 3) VF Representor to VF
* 4) VF to VF Representor
*
* eth_dev [in] Ptr to rte eth device.
* flow_id [in] Flow identifier.
*
* Returns 0 on success or negative number on failure.
*/
int32_t
ulp_default_flow_destroy(struct rte_eth_dev *eth_dev, uint32_t flow_id)
{
struct bnxt_ulp_context *ulp_ctx;
int rc = 0;
ulp_ctx = bnxt_ulp_eth_dev_ptr2_cntxt_get(eth_dev);
if (!ulp_ctx) {
BNXT_DRV_DBG(ERR, "ULP context is not initialized\n");
return -EINVAL;
}
if (!flow_id) {
BNXT_DRV_DBG(DEBUG, "invalid flow id zero\n");
return rc;
}
if (bnxt_ulp_cntxt_acquire_fdb_lock(ulp_ctx)) {
BNXT_DRV_DBG(ERR, "Flow db lock acquire failed\n");
return -EINVAL;
}
rc = ulp_mapper_flow_destroy(ulp_ctx, BNXT_ULP_FDB_TYPE_DEFAULT,
flow_id,
NULL);
if (rc)
BNXT_DRV_DBG(ERR, "Failed to destroy flow.\n");
bnxt_ulp_cntxt_release_fdb_lock(ulp_ctx);
return rc;
}
static void
bnxt_ulp_destroy_group_rules(struct bnxt *bp, uint16_t port_id)
{
struct bnxt_ulp_grp_rule_info *info;
struct bnxt_ulp_grp_rule_info *grp_rules;
uint16_t idx;
grp_rules = bp->ulp_ctx->cfg_data->df_rule_info[port_id].grp_df_rule;
for (idx = 0; idx < BNXT_ULP_MAX_GROUP_CNT; idx++) {
info = &grp_rules[idx];
if (!info->valid)
continue;
ulp_default_flow_destroy(bp->eth_dev, info->flow_id);
memset(info, 0, sizeof(struct bnxt_ulp_grp_rule_info));
}
}
void
bnxt_ulp_destroy_df_rules(struct bnxt *bp, bool global)
{
struct bnxt_ulp_df_rule_info *info;
uint16_t port_id;
if (!BNXT_TRUFLOW_EN(bp) ||
rte_eth_dev_is_repr(bp->eth_dev))
return;
if (!bp->ulp_ctx || !bp->ulp_ctx->cfg_data)
return;
/* Delete default rules per port */
if (!global) {
port_id = bp->eth_dev->data->port_id;
info = &bp->ulp_ctx->cfg_data->df_rule_info[port_id];
if (!info->valid)
return;
/* Delete the group default rules */
bnxt_ulp_destroy_group_rules(bp, port_id);
ulp_default_flow_destroy(bp->eth_dev,
info->def_port_flow_id);
if (info->promisc_flow_id)
ulp_default_flow_destroy(bp->eth_dev,
info->promisc_flow_id);
memset(info, 0, sizeof(struct bnxt_ulp_df_rule_info));
return;
}
/* Delete default rules for all ports */
for (port_id = 0; port_id < RTE_MAX_ETHPORTS; port_id++) {
info = &bp->ulp_ctx->cfg_data->df_rule_info[port_id];
if (!info->valid)
continue;
/* Delete the group default rules */
bnxt_ulp_destroy_group_rules(bp, port_id);
ulp_default_flow_destroy(bp->eth_dev,
info->def_port_flow_id);
if (info->promisc_flow_id)
ulp_default_flow_destroy(bp->eth_dev,
info->promisc_flow_id);
memset(info, 0, sizeof(struct bnxt_ulp_df_rule_info));
}
}
static int32_t
bnxt_create_port_app_df_rule(struct bnxt *bp, uint8_t flow_type,
uint32_t *flow_id)
{
uint16_t port_id = bp->eth_dev->data->port_id;
struct ulp_tlv_param param_list[] = {
{
.type = BNXT_ULP_DF_PARAM_TYPE_DEV_PORT_ID,
.length = 2,
.value = {(port_id >> 8) & 0xff, port_id & 0xff}
},
{
.type = BNXT_ULP_DF_PARAM_TYPE_LAST,
.length = 0,
.value = {0}
}
};
if (!flow_type) {
*flow_id = 0;
return 0;
}
return ulp_default_flow_create(bp->eth_dev, param_list, flow_type,
port_id, flow_id);
}
int32_t
bnxt_ulp_create_df_rules(struct bnxt *bp)
{
struct rte_eth_dev *dev = bp->eth_dev;
struct bnxt_ulp_df_rule_info *info;
uint16_t port_id;
int rc = 0;
if (!BNXT_TRUFLOW_EN(bp) ||
rte_eth_dev_is_repr(bp->eth_dev) || !bp->ulp_ctx)
return 0;
port_id = bp->eth_dev->data->port_id;
info = &bp->ulp_ctx->cfg_data->df_rule_info[port_id];
rc = bnxt_create_port_app_df_rule(bp,
BNXT_ULP_DF_TPL_DEFAULT_UPLINK_PORT,
&info->def_port_flow_id);
if (rc) {
BNXT_DRV_DBG(ERR,
"Failed to create port to app default rule\n");
return rc;
}
/* If the template already set the bd_action, skip this */
if (!bp->tx_cfa_action) {
rc = ulp_default_flow_db_cfa_action_get(bp->ulp_ctx,
info->def_port_flow_id,
&bp->tx_cfa_action);
}
if (rc || BNXT_TESTPMD_EN(bp))
bp->tx_cfa_action = 0;
/* set or reset the promiscuous rule */
bnxt_ulp_promisc_mode_set(bp, dev->data->promiscuous);
info->valid = true;
return 0;
}
static int32_t
bnxt_create_port_vfr_default_rule(struct bnxt *bp,
uint8_t flow_type,
uint16_t vfr_port_id,
uint32_t *flow_id)
{
struct ulp_tlv_param param_list[] = {
{
.type = BNXT_ULP_DF_PARAM_TYPE_DEV_PORT_ID,
.length = 2,
.value = {(vfr_port_id >> 8) & 0xff, vfr_port_id & 0xff}
},
{
.type = BNXT_ULP_DF_PARAM_TYPE_LAST,
.length = 0,
.value = {0}
}
};
return ulp_default_flow_create(bp->eth_dev, param_list, flow_type,
vfr_port_id,
flow_id);
}
int32_t
bnxt_ulp_create_vfr_default_rules(struct rte_eth_dev *vfr_ethdev)
{
struct bnxt_ulp_vfr_rule_info *info;
struct bnxt_representor *vfr = vfr_ethdev->data->dev_private;
struct rte_eth_dev *parent_dev = vfr->parent_dev;
struct bnxt *bp = parent_dev->data->dev_private;
uint16_t vfr_port_id = vfr_ethdev->data->port_id;
uint16_t port_id;
int rc;
if (!bp || !BNXT_TRUFLOW_EN(bp))
return 0;
port_id = vfr_ethdev->data->port_id;
info = bnxt_ulp_cntxt_ptr2_ulp_vfr_info_get(bp->ulp_ctx, port_id);
if (!info) {
BNXT_DRV_DBG(ERR, "Failed to get vfr ulp context\n");
return -EINVAL;
}
if (info->valid) {
BNXT_DRV_DBG(ERR, "VFR already allocated\n");
return -EINVAL;
}
memset(info, 0, sizeof(struct bnxt_ulp_vfr_rule_info));
rc = bnxt_create_port_vfr_default_rule(bp, BNXT_ULP_DF_TPL_DEFAULT_VFR,
vfr_port_id,
&info->vfr_flow_id);
if (rc) {
BNXT_DRV_DBG(ERR, "Failed to create VFR default rule\n");
goto error;
}
/* If the template already set the bd action, skip this */
if (!vfr->vfr_tx_cfa_action) {
rc = ulp_default_flow_db_cfa_action_get(bp->ulp_ctx,
info->vfr_flow_id,
&vfr->vfr_tx_cfa_action);
if (rc) {
BNXT_DRV_DBG(ERR, "Failed to get the tx cfa action\n");
goto error;
}
}
/* Update the other details */
info->valid = true;
info->parent_port_id = bp->eth_dev->data->port_id;
return 0;
error:
if (info->vfr_flow_id)
ulp_default_flow_destroy(bp->eth_dev, info->vfr_flow_id);
return rc;
}
int32_t
bnxt_ulp_delete_vfr_default_rules(struct bnxt_representor *vfr)
{
struct bnxt_ulp_vfr_rule_info *info;
struct rte_eth_dev *parent_dev = vfr->parent_dev;
struct bnxt *bp = parent_dev->data->dev_private;
if (!bp || !BNXT_TRUFLOW_EN(bp))
return 0;
info = bnxt_ulp_cntxt_ptr2_ulp_vfr_info_get(bp->ulp_ctx,
vfr->dpdk_port_id);
if (!info) {
BNXT_DRV_DBG(ERR, "Failed to get vfr ulp context\n");
return -EINVAL;
}
if (!info->valid) {
BNXT_DRV_DBG(ERR, "VFR already freed\n");
return -EINVAL;
}
ulp_default_flow_destroy(bp->eth_dev, info->vfr_flow_id);
vfr->vfr_tx_cfa_action = 0;
memset(info, 0, sizeof(struct bnxt_ulp_vfr_rule_info));
return 0;
}
static void
ulp_l2_custom_tunnel_id_update(struct bnxt *bp,
struct bnxt_ulp_mapper_parms *params)
{
if (!bp->l2_etype_tunnel_cnt)
return;
if (bp->l2_etype_upar_in_use &
HWRM_TUNNEL_DST_PORT_QUERY_OUTPUT_UPAR_IN_USE_UPAR0) {
ULP_COMP_FLD_IDX_WR(params, BNXT_ULP_CF_IDX_L2_CUSTOM_UPAR_ID,
ULP_WP_SYM_TUN_HDR_TYPE_UPAR1);
} else if (bp->l2_etype_upar_in_use &
HWRM_TUNNEL_DST_PORT_QUERY_OUTPUT_UPAR_IN_USE_UPAR1) {
ULP_COMP_FLD_IDX_WR(params, BNXT_ULP_CF_IDX_L2_CUSTOM_UPAR_ID,
ULP_WP_SYM_TUN_HDR_TYPE_UPAR2);
}
}
/*
* Function to execute a specific template, this does not create flow id
*
* bp [in] Ptr to bnxt
* param_list [in] Ptr to a list of parameters (Currently, only DPDK port_id).
* ulp_class_tid [in] Class template ID number.
*
* Returns 0 on success or negative number on failure.
*/
static int32_t
ulp_flow_template_process(struct bnxt *bp,
struct ulp_tlv_param *param_list,
uint32_t ulp_class_tid,
uint16_t port_id,
uint32_t flow_id)
{
struct ulp_rte_hdr_field hdr_field[BNXT_ULP_PROTO_HDR_MAX];
uint64_t comp_fld[BNXT_ULP_CF_IDX_LAST];
struct bnxt_ulp_mapper_parms mapper_params = { 0 };
struct ulp_rte_act_prop act_prop;
struct ulp_rte_act_bitmap act = { 0 };
struct bnxt_ulp_context *ulp_ctx;
uint32_t type;
int rc = 0;
memset(&mapper_params, 0, sizeof(mapper_params));
memset(hdr_field, 0, sizeof(hdr_field));
memset(comp_fld, 0, sizeof(comp_fld));
memset(&act_prop, 0, sizeof(act_prop));
mapper_params.hdr_field = hdr_field;
mapper_params.act_bitmap = &act;
mapper_params.act_prop = &act_prop;
mapper_params.comp_fld = comp_fld;
mapper_params.class_tid = ulp_class_tid;
mapper_params.port_id = port_id;
ulp_ctx = bp->ulp_ctx;
if (!ulp_ctx) {
BNXT_DRV_DBG(ERR,
"ULP is not init'ed. Fail to create dflt flow.\n");
return -EINVAL;
}
type = param_list->type;
while (type != BNXT_ULP_DF_PARAM_TYPE_LAST) {
if (ulp_def_handler_tbl[type].vfr_func) {
rc = ulp_def_handler_tbl[type].vfr_func(ulp_ctx,
param_list,
&mapper_params);
if (rc) {
BNXT_DRV_DBG(ERR,
"Failed to create default flow\n");
return rc;
}
}
param_list++;
type = param_list->type;
}
/* Protect flow creation */
if (bnxt_ulp_cntxt_acquire_fdb_lock(ulp_ctx)) {
BNXT_DRV_DBG(ERR, "Flow db lock acquire failed\n");
return -EINVAL;
}
mapper_params.flow_id = flow_id;
rc = ulp_mapper_flow_create(ulp_ctx, &mapper_params,
NULL);
bnxt_ulp_cntxt_release_fdb_lock(ulp_ctx);
return rc;
}
int32_t
bnxt_ulp_promisc_mode_set(struct bnxt *bp, uint8_t enable)
{
uint32_t flow_type;
struct bnxt_ulp_df_rule_info *info;
uint16_t port_id;
int rc = 0;
if (!BNXT_TRUFLOW_EN(bp) || BNXT_ETH_DEV_IS_REPRESENTOR(bp->eth_dev) ||
!bp->ulp_ctx)
return rc;
port_id = bp->eth_dev->data->port_id;
info = &bp->ulp_ctx->cfg_data->df_rule_info[port_id];
/* create the promiscuous rule */
if (enable && !info->promisc_flow_id) {
flow_type = BNXT_ULP_TEMPLATE_PROMISCUOUS_ENABLE;
rc = bnxt_create_port_app_df_rule(bp, flow_type,
&info->promisc_flow_id);
BNXT_DRV_DBG(DEBUG, "enable ulp promisc mode on port %u:%u\n",
port_id, info->promisc_flow_id);
} else if (!enable && info->promisc_flow_id) {
struct ulp_tlv_param param_list[] = {
{
.type = BNXT_ULP_DF_PARAM_TYPE_DEV_PORT_ID,
.length = 2,
.value = {(port_id >> 8) & 0xff, port_id & 0xff}
},
{
.type = BNXT_ULP_DF_PARAM_TYPE_LAST,
.length = 0,
.value = {0}
}
};
flow_type = BNXT_ULP_TEMPLATE_PROMISCUOUS_DISABLE;
if (ulp_flow_template_process(bp, param_list, flow_type,
port_id, 0))
return -EIO;
rc = ulp_default_flow_destroy(bp->eth_dev,
info->promisc_flow_id);
BNXT_DRV_DBG(DEBUG, "disable ulp promisc mode on port %u:%u\n",
port_id, info->promisc_flow_id);
info->promisc_flow_id = 0;
}
return rc;
}
/* Function to create the rte flow for miss action. */
int32_t
bnxt_ulp_grp_miss_act_set(struct rte_eth_dev *dev,
const struct rte_flow_attr *attr,
const struct rte_flow_action actions[],
uint32_t *flow_id)
{
struct bnxt_ulp_mapper_parms mparms = { 0 };
struct ulp_rte_parser_params params;
struct bnxt_ulp_context *ulp_ctx;
int ret = BNXT_TF_RC_ERROR;
uint16_t func_id;
uint32_t fid;
uint32_t group_id;
ulp_ctx = bnxt_ulp_eth_dev_ptr2_cntxt_get(dev);
if (unlikely(!ulp_ctx)) {
BNXT_DRV_DBG(ERR, "ULP context is not initialized\n");
goto flow_error;
}
/* Initialize the parser params */
memset(¶ms, 0, sizeof(struct ulp_rte_parser_params));
params.ulp_ctx = ulp_ctx;
params.port_id = dev->data->port_id;
/* classid is the group action template*/
params.class_id = BNXT_ULP_TEMPLATE_GROUP_MISS_ACTION;
if (unlikely(bnxt_ulp_cntxt_app_id_get(params.ulp_ctx, ¶ms.app_id))) {
BNXT_DRV_DBG(ERR, "failed to get the app id\n");
goto flow_error;
}
/* Set the flow attributes */
bnxt_ulp_set_dir_attributes(¶ms, attr);
if (unlikely(bnxt_ulp_set_prio_attribute(¶ms, attr)))
goto flow_error;
bnxt_ulp_init_parser_cf_defaults(¶ms, params.port_id);
/* Get the function id */
if (unlikely(ulp_port_db_port_func_id_get(ulp_ctx,
params.port_id,
&func_id))) {
BNXT_DRV_DBG(ERR, "conversion of port to func id failed\n");
goto flow_error;
}
/* Protect flow creation */
if (unlikely(bnxt_ulp_cntxt_acquire_fdb_lock(ulp_ctx))) {
BNXT_DRV_DBG(ERR, "Flow db lock acquire failed\n");
goto flow_error;
}
/* Allocate a Flow ID for attaching all resources for the flow to.
* Once allocated, all errors have to walk the list of resources and
* free each of them.
*/
ret = ulp_flow_db_fid_alloc(ulp_ctx, BNXT_ULP_FDB_TYPE_DEFAULT,
func_id, &fid);
if (unlikely(ret)) {
BNXT_DRV_DBG(ERR, "Unable to allocate flow table entry\n");
goto release_lock;
}
/* Update the implied SVIF */
ulp_rte_parser_implicit_match_port_process(¶ms);
/* Parse the rte flow action */
ret = bnxt_ulp_rte_parser_act_parse(actions, ¶ms);
if (unlikely(ret != BNXT_TF_RC_SUCCESS))
goto free_fid;
/* Verify the jump target group id */
if (ULP_BITMAP_ISSET(params.act_bitmap.bits, BNXT_ULP_ACT_BIT_JUMP)) {
memcpy(&group_id,
¶ms.act_prop.act_details[BNXT_ULP_ACT_PROP_IDX_JUMP],
BNXT_ULP_ACT_PROP_SZ_JUMP);
if (rte_cpu_to_be_32(group_id) == attr->group) {
BNXT_DRV_DBG(ERR, "Jump action cannot jump to its own group.\n");
ret = BNXT_TF_RC_ERROR;
goto free_fid;
}
}
mparms.flow_id = fid;
mparms.func_id = func_id;
mparms.port_id = params.port_id;
/* Perform the rte flow post process */
bnxt_ulp_rte_parser_post_process(¶ms);
ret = ulp_matcher_action_match(¶ms, ¶ms.act_tmpl);
if (unlikely(ret != BNXT_TF_RC_SUCCESS))
goto free_fid;
bnxt_ulp_init_mapper_params(&mparms, ¶ms,
BNXT_ULP_FDB_TYPE_DEFAULT);
/* Call the ulp mapper to create the flow in the hardware. */
ret = ulp_mapper_flow_create(ulp_ctx, &mparms, NULL);
if (unlikely(ret))
goto free_fid;
bnxt_ulp_cntxt_release_fdb_lock(ulp_ctx);
*flow_id = fid;
return 0;
free_fid:
ulp_flow_db_fid_free(ulp_ctx, BNXT_ULP_FDB_TYPE_DEFAULT, fid);
release_lock:
bnxt_ulp_cntxt_release_fdb_lock(ulp_ctx);
flow_error:
return ret;
}
int32_t
bnxt_ulp_hot_upgrade_process(struct bnxt *bp)
{
uint32_t flow_type = BNXT_ULP_TEMPLATE_HOT_UPGRADE;
uint16_t port_id = bp->eth_dev->data->port_id;
struct ulp_tlv_param param_list[] = {
{
.type = BNXT_ULP_DF_PARAM_TYPE_DEV_PORT_ID,
.length = 2,
.value = {(port_id >> 8) & 0xff, port_id & 0xff}
},
{
.type = BNXT_ULP_DF_PARAM_TYPE_LAST,
.length = 0,
.value = {0}
}
};
if (!BNXT_CHIP_P7(bp))
return -EPERM;
if (ulp_flow_template_process(bp, param_list, flow_type,
port_id, 0))
return -EIO;
BNXT_DRV_DBG(DEBUG, "Hot upgrade operation performed\n");
return 0;
}
|