net/bnxt: enable NAT action with tagged traffic
authorKishore Padmanabha <kishore.padmanabha@broadcom.com>
Fri, 11 Sep 2020 01:55:57 +0000 (18:55 -0700)
committerFerruh Yigit <ferruh.yigit@intel.com>
Fri, 18 Sep 2020 16:55:12 +0000 (18:55 +0200)
Added support for performing L3 or L4 rewrite for VLAN tagged
flows. The outer most DMAC, SMAC and VLAN are used to overwrite
when NAT operations are performed.

Signed-off-by: Kishore Padmanabha <kishore.padmanabha@broadcom.com>
Reviewed-by: Mike Baucom <michael.baucom@broadcom.com>
Reviewed-by: Ajit Khaparde <ajit.khaparde@broadcom.com>
drivers/net/bnxt/tf_ulp/bnxt_ulp.c
drivers/net/bnxt/tf_ulp/bnxt_ulp.h
drivers/net/bnxt/tf_ulp/ulp_mapper.c
drivers/net/bnxt/tf_ulp/ulp_template_db_act.c
drivers/net/bnxt/tf_ulp/ulp_template_db_enum.h

index eae8884..364853a 100644 (file)
@@ -721,15 +721,11 @@ bnxt_ulp_deinit(struct bnxt *bp,
        /* Disable NAT feature */
        (void)bnxt_ulp_global_cfg_update(bp, TF_DIR_RX, TF_TUNNEL_ENCAP,
                                         TF_TUNNEL_ENCAP_NAT,
-                                        (BNXT_ULP_NAT_INNER_L2_HEADER_SMAC |
-                                         BNXT_ULP_NAT_INNER_L2_HEADER_DMAC),
-                                        0);
+                                        BNXT_ULP_NAT_OUTER_MOST_FLAGS, 0);
 
        (void)bnxt_ulp_global_cfg_update(bp, TF_DIR_TX, TF_TUNNEL_ENCAP,
                                         TF_TUNNEL_ENCAP_NAT,
-                                        (BNXT_ULP_NAT_INNER_L2_HEADER_SMAC |
-                                         BNXT_ULP_NAT_INNER_L2_HEADER_DMAC),
-                                        0);
+                                        BNXT_ULP_NAT_OUTER_MOST_FLAGS, 0);
 
        /* Delete the ulp context and tf session and free the ulp context */
        ulp_ctx_deinit(bp, session);
@@ -808,8 +804,7 @@ bnxt_ulp_init(struct bnxt *bp,
         */
        rc = bnxt_ulp_global_cfg_update(bp, TF_DIR_RX, TF_TUNNEL_ENCAP,
                                        TF_TUNNEL_ENCAP_NAT,
-                                       (BNXT_ULP_NAT_INNER_L2_HEADER_SMAC |
-                                       BNXT_ULP_NAT_INNER_L2_HEADER_DMAC), 1);
+                                       BNXT_ULP_NAT_OUTER_MOST_FLAGS, 1);
        if (rc) {
                BNXT_TF_DBG(ERR, "Failed to set rx global configuration\n");
                goto jump_to_error;
@@ -817,8 +812,7 @@ bnxt_ulp_init(struct bnxt *bp,
 
        rc = bnxt_ulp_global_cfg_update(bp, TF_DIR_TX, TF_TUNNEL_ENCAP,
                                        TF_TUNNEL_ENCAP_NAT,
-                                       (BNXT_ULP_NAT_INNER_L2_HEADER_SMAC |
-                                       BNXT_ULP_NAT_INNER_L2_HEADER_DMAC), 1);
+                                       BNXT_ULP_NAT_OUTER_MOST_FLAGS, 1);
        if (rc) {
                BNXT_TF_DBG(ERR, "Failed to set tx global configuration\n");
                goto jump_to_error;
index 5882c54..ed97873 100644 (file)
 
 /* NAT defines to reuse existing inner L2 SMAC and DMAC */
 #define BNXT_ULP_NAT_INNER_L2_HEADER_SMAC      0x2000
+#define BNXT_ULP_NAT_OUTER_MOST_L2_HDR_SMAC    0x6000
+#define BNXT_ULP_NAT_OUTER_MOST_L2_VLAN_TAGS   0xc00
 #define BNXT_ULP_NAT_INNER_L2_HEADER_DMAC      0x100
+#define BNXT_ULP_NAT_OUTER_MOST_L2_HDR_DMAC    0x300
+#define BNXT_ULP_NAT_OUTER_MOST_FLAGS (BNXT_ULP_NAT_OUTER_MOST_L2_HDR_SMAC |\
+                                       BNXT_ULP_NAT_OUTER_MOST_L2_VLAN_TAGS |\
+                                       BNXT_ULP_NAT_OUTER_MOST_L2_HDR_DMAC)
 
 /* defines for the ulp_flags */
 #define BNXT_ULP_VF_REP_ENABLED                0x1
index 6ac4b0f..1568267 100644 (file)
@@ -783,6 +783,7 @@ ulp_mapper_result_field_process(struct bnxt_ulp_mapper_parms *parms,
        uint32_t val_size = 0, field_size = 0;
        uint64_t act_bit;
        uint8_t act_val;
+       uint64_t hdr_bit;
 
        switch (fld->result_opcode) {
        case BNXT_ULP_MAPPER_OPC_SET_TO_CONSTANT:
@@ -1033,6 +1034,26 @@ ulp_mapper_result_field_process(struct bnxt_ulp_mapper_parms *parms,
                        return -EINVAL;
                }
                break;
+       case BNXT_ULP_MAPPER_OPC_IF_HDR_BIT_THEN_CONST_ELSE_CONST:
+               if (!ulp_operand_read(fld->result_operand,
+                                     (uint8_t *)&hdr_bit, sizeof(uint64_t))) {
+                       BNXT_TF_DBG(ERR, "%s operand read failed\n", name);
+                       return -EINVAL;
+               }
+               hdr_bit = tfp_be_to_cpu_64(hdr_bit);
+               if (ULP_BITMAP_ISSET(parms->hdr_bitmap->bits, hdr_bit)) {
+                       /* Header bit is set so consider operand_true */
+                       val = fld->result_operand_true;
+               } else {
+                       /* Header bit is not set, use the operand false */
+                       val = fld->result_operand_false;
+               }
+               if (!ulp_blob_push(blob, val, fld->field_bit_size)) {
+                       BNXT_TF_DBG(ERR, "%s failed to add field\n",
+                                   name);
+                       return -EINVAL;
+               }
+               break;
        default:
                BNXT_TF_DBG(ERR, "invalid result mapper opcode 0x%x\n",
                            fld->result_opcode);
index cab3445..22142c1 100644 (file)
@@ -1434,11 +1434,21 @@ struct bnxt_ulp_mapper_result_field_info ulp_act_result_field_list[] = {
        },
        {
        .field_bit_size = 4,
-       .result_opcode = BNXT_ULP_MAPPER_OPC_SET_TO_CONSTANT,
-       .result_operand = {
-               BNXT_ULP_SYM_DECAP_FUNC_THRU_L2,
-               0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-               0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}
+       .result_opcode = BNXT_ULP_MAPPER_OPC_IF_HDR_BIT_THEN_CONST_ELSE_CONST,
+       .result_operand = {
+               ((uint64_t)BNXT_ULP_HDR_BIT_T_VXLAN >> 56) & 0xff,
+               ((uint64_t)BNXT_ULP_HDR_BIT_T_VXLAN >> 48) & 0xff,
+               ((uint64_t)BNXT_ULP_HDR_BIT_T_VXLAN >> 40) & 0xff,
+               ((uint64_t)BNXT_ULP_HDR_BIT_T_VXLAN >> 32) & 0xff,
+               ((uint64_t)BNXT_ULP_HDR_BIT_T_VXLAN >> 24) & 0xff,
+               ((uint64_t)BNXT_ULP_HDR_BIT_T_VXLAN >> 16) & 0xff,
+               ((uint64_t)BNXT_ULP_HDR_BIT_T_VXLAN >> 8) & 0xff,
+               (uint64_t)BNXT_ULP_HDR_BIT_T_VXLAN & 0xff,
+               0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
+       .result_operand_true = {0x03, 0x00, 0x00, 0x00, 0x00, 0x00,
+               0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
+       .result_operand_false = {0x0b, 0x00, 0x00, 0x00, 0x00, 0x00,
+               0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}
        },
        {
        .field_bit_size = 12,
@@ -2336,11 +2346,21 @@ struct bnxt_ulp_mapper_result_field_info ulp_act_result_field_list[] = {
        },
        {
        .field_bit_size = 4,
-       .result_opcode = BNXT_ULP_MAPPER_OPC_SET_TO_CONSTANT,
-       .result_operand = {
-               BNXT_ULP_SYM_DECAP_FUNC_THRU_L2,
-               0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-               0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}
+       .result_opcode = BNXT_ULP_MAPPER_OPC_IF_HDR_BIT_THEN_CONST_ELSE_CONST,
+       .result_operand = {
+               ((uint64_t)BNXT_ULP_HDR_BIT_T_VXLAN >> 56) & 0xff,
+               ((uint64_t)BNXT_ULP_HDR_BIT_T_VXLAN >> 48) & 0xff,
+               ((uint64_t)BNXT_ULP_HDR_BIT_T_VXLAN >> 40) & 0xff,
+               ((uint64_t)BNXT_ULP_HDR_BIT_T_VXLAN >> 32) & 0xff,
+               ((uint64_t)BNXT_ULP_HDR_BIT_T_VXLAN >> 24) & 0xff,
+               ((uint64_t)BNXT_ULP_HDR_BIT_T_VXLAN >> 16) & 0xff,
+               ((uint64_t)BNXT_ULP_HDR_BIT_T_VXLAN >> 8) & 0xff,
+               (uint64_t)BNXT_ULP_HDR_BIT_T_VXLAN & 0xff,
+               0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
+       .result_operand_true = {0x03, 0x00, 0x00, 0x00, 0x00, 0x00,
+               0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
+       .result_operand_false = {0x0b, 0x00, 0x00, 0x00, 0x00, 0x00,
+               0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}
        },
        {
        .field_bit_size = 12,
index 4c1161a..5175886 100644 (file)
@@ -218,7 +218,8 @@ enum bnxt_ulp_mapper_opc {
        BNXT_ULP_MAPPER_OPC_IF_ACT_BIT_THEN_ACT_PROP_ELSE_CONST = 9,
        BNXT_ULP_MAPPER_OPC_IF_ACT_BIT_THEN_CONST_ELSE_CONST = 10,
        BNXT_ULP_MAPPER_OPC_IF_COMP_FIELD_THEN_CF_ELSE_CF = 11,
-       BNXT_ULP_MAPPER_OPC_LAST = 12
+       BNXT_ULP_MAPPER_OPC_IF_HDR_BIT_THEN_CONST_ELSE_CONST = 12,
+       BNXT_ULP_MAPPER_OPC_LAST = 13
 };
 
 enum bnxt_ulp_mark_db_opcode {