net/bnxt: support internal encap records
[dpdk.git] / drivers / net / bnxt / tf_ulp / ulp_mapper.c
index 33461dc..a9a625f 100644 (file)
@@ -365,8 +365,8 @@ ulp_mapper_cache_res_type_get(struct ulp_flow_db_res_params *res,
 
 static int32_t
 ulp_mapper_cache_entry_free(struct bnxt_ulp_context *ulp,
-                          struct tf *tfp,
-                          struct ulp_flow_db_res_params *res)
+                           struct tf *tfp,
+                           struct ulp_flow_db_res_params *res)
 {
        struct bnxt_ulp_mapper_cache_entry *cache_entry;
        struct tf_free_identifier_parms ident_parms;
@@ -804,7 +804,7 @@ ulp_mapper_keymask_field_process(struct bnxt_ulp_mapper_parms *parms,
                }
                break;
        case BNXT_ULP_MAPPER_OPC_SET_TO_ZERO:
-               if (!ulp_blob_pad_push(blob, bitlen)) {
+               if (ulp_blob_pad_push(blob, bitlen) < 0) {
                        BNXT_TF_DBG(ERR, "%s pad too large for blob\n", name);
                        return -EINVAL;
                }
@@ -904,13 +904,15 @@ ulp_mapper_mark_gfid_process(struct bnxt_ulp_mapper_parms *parms,
                             struct bnxt_ulp_mapper_tbl_info *tbl,
                             uint64_t flow_id)
 {
+       enum bnxt_ulp_mark_db_opcode mark_op = tbl->mark_db_opcode;
        struct ulp_flow_db_res_params fid_parms;
        uint32_t mark, gfid, mark_flag;
        int32_t rc = 0;
 
-       if (!(tbl->mark_enable &&
+       if (mark_op == BNXT_ULP_MARK_DB_OPCODE_NOP ||
+           !(mark_op == BNXT_ULP_MARK_DB_OPCODE_SET_IF_MARK_ACTION &&
              ULP_BITMAP_ISSET(parms->act_bitmap->bits,
-                             BNXT_ULP_ACTION_BIT_MARK)))
+                              BNXT_ULP_ACTION_BIT_MARK)))
                return rc; /* no need to perform gfid process */
 
        /* Get the mark id details from action property */
@@ -944,14 +946,16 @@ static int32_t
 ulp_mapper_mark_act_ptr_process(struct bnxt_ulp_mapper_parms *parms,
                                struct bnxt_ulp_mapper_tbl_info *tbl)
 {
+       enum bnxt_ulp_mark_db_opcode mark_op = tbl->mark_db_opcode;
        struct ulp_flow_db_res_params fid_parms;
        uint32_t act_idx, mark, mark_flag;
        uint64_t val64;
        int32_t rc = 0;
 
-       if (!(tbl->mark_enable &&
+       if (mark_op == BNXT_ULP_MARK_DB_OPCODE_NOP ||
+           !(mark_op == BNXT_ULP_MARK_DB_OPCODE_SET_IF_MARK_ACTION &&
              ULP_BITMAP_ISSET(parms->act_bitmap->bits,
-                               BNXT_ULP_ACTION_BIT_MARK)))
+                              BNXT_ULP_ACTION_BIT_MARK)))
                return rc; /* no need to perform mark action process */
 
        /* Get the mark id details from action property */
@@ -987,6 +991,55 @@ ulp_mapper_mark_act_ptr_process(struct bnxt_ulp_mapper_parms *parms,
        return rc;
 }
 
+static int32_t
+ulp_mapper_mark_vfr_idx_process(struct bnxt_ulp_mapper_parms *parms,
+                               struct bnxt_ulp_mapper_tbl_info *tbl)
+{
+       struct ulp_flow_db_res_params fid_parms;
+       uint32_t act_idx, mark, mark_flag;
+       uint64_t val64;
+       enum bnxt_ulp_mark_db_opcode mark_op = tbl->mark_db_opcode;
+       int32_t rc = 0;
+
+       if (mark_op == BNXT_ULP_MARK_DB_OPCODE_NOP ||
+           mark_op == BNXT_ULP_MARK_DB_OPCODE_SET_IF_MARK_ACTION)
+               return rc; /* no need to perform mark action process */
+
+       /* Get the mark id details from the computed field of dev port id */
+       mark = ULP_COMP_FLD_IDX_RD(parms, BNXT_ULP_CF_IDX_DEV_PORT_ID);
+
+        /* Get the main action pointer */
+       if (!ulp_regfile_read(parms->regfile,
+                             BNXT_ULP_REGFILE_INDEX_MAIN_ACTION_PTR,
+                             &val64)) {
+               BNXT_TF_DBG(ERR, "read action ptr main failed\n");
+               return -EINVAL;
+       }
+       act_idx = tfp_be_to_cpu_64(val64);
+
+       /* Set the mark flag to local fid and vfr flag */
+       mark_flag  = BNXT_ULP_MARK_LOCAL_HW_FID | BNXT_ULP_MARK_VFR_ID;
+
+       rc = ulp_mark_db_mark_add(parms->ulp_ctx, mark_flag,
+                                 act_idx, mark);
+       if (rc) {
+               BNXT_TF_DBG(ERR, "Failed to add mark to flow\n");
+               return rc;
+       }
+       fid_parms.direction = tbl->direction;
+       fid_parms.resource_func = BNXT_ULP_RESOURCE_FUNC_HW_FID;
+       fid_parms.critical_resource = BNXT_ULP_CRITICAL_RESOURCE_NO;
+       fid_parms.resource_type = mark_flag;
+       fid_parms.resource_hndl = act_idx;
+       rc = ulp_flow_db_resource_add(parms->ulp_ctx,
+                                     parms->tbl_idx,
+                                     parms->fid,
+                                     &fid_parms);
+       if (rc)
+               BNXT_TF_DBG(ERR, "Fail to link res to flow rc = %d\n", rc);
+       return rc;
+}
+
 static int32_t
 ulp_mapper_tcam_tbl_process(struct bnxt_ulp_mapper_parms *parms,
                            struct bnxt_ulp_mapper_tbl_info *tbl)
@@ -1021,9 +1074,12 @@ ulp_mapper_tcam_tbl_process(struct bnxt_ulp_mapper_parms *parms,
                return -EINVAL;
        }
 
-       if (!ulp_blob_init(&key, tbl->key_bit_size, parms->order) ||
-           !ulp_blob_init(&mask, tbl->key_bit_size, parms->order) ||
-           !ulp_blob_init(&data, tbl->result_bit_size, parms->order)) {
+       if (!ulp_blob_init(&key, tbl->key_bit_size,
+                          parms->device_params->byte_order) ||
+           !ulp_blob_init(&mask, tbl->key_bit_size,
+                          parms->device_params->byte_order) ||
+           !ulp_blob_init(&data, tbl->result_bit_size,
+                          parms->device_params->byte_order)) {
                BNXT_TF_DBG(ERR, "blob inits failed.\n");
                return -EINVAL;
        }
@@ -1166,6 +1222,11 @@ ulp_mapper_tcam_tbl_process(struct bnxt_ulp_mapper_parms *parms,
                        parms->cache_ptr->tcam_idx = aparms.idx;
                }
 
+               /* Mark action */
+               rc = ulp_mapper_mark_act_ptr_process(parms, tbl);
+               if (rc)
+                       goto error;
+
        } else {
                BNXT_TF_DBG(ERR, "Not supporting search before alloc now\n");
                rc = -EINVAL;
@@ -1230,6 +1291,7 @@ ulp_mapper_em_tbl_process(struct bnxt_ulp_mapper_parms *parms,
        struct tf_insert_em_entry_parms iparms = { 0 };
        struct tf_delete_em_entry_parms free_parms = { 0 };
        int32_t trc;
+       enum bnxt_ulp_flow_mem_type mtype = parms->device_params->flow_mem_type;
        int32_t rc = 0;
 
        kflds = ulp_mapper_key_fields_get(tbl, &num_kflds);
@@ -1239,8 +1301,10 @@ ulp_mapper_em_tbl_process(struct bnxt_ulp_mapper_parms *parms,
        }
 
        /* Initialize the key/result blobs */
-       if (!ulp_blob_init(&key, tbl->blob_key_bit_size, parms->order) ||
-           !ulp_blob_init(&data, tbl->result_bit_size, parms->order)) {
+       if (!ulp_blob_init(&key, tbl->blob_key_bit_size,
+                          parms->device_params->byte_order) ||
+           !ulp_blob_init(&data, tbl->result_bit_size,
+                          parms->device_params->byte_order)) {
                BNXT_TF_DBG(ERR, "blob inits failed.\n");
                return -EINVAL;
        }
@@ -1284,6 +1348,13 @@ ulp_mapper_em_tbl_process(struct bnxt_ulp_mapper_parms *parms,
                        return rc;
                }
        }
+#ifdef RTE_LIBRTE_BNXT_TRUFLOW_DEBUG
+       ulp_mapper_result_dump("EEM Result", tbl, &data);
+#endif
+
+       /* do the transpose for the internal EM keys */
+       if (tbl->resource_type == TF_MEM_INTERNAL)
+               ulp_blob_perform_byte_reverse(&key);
 
        rc = bnxt_ulp_cntxt_tbl_scope_id_get(parms->ulp_ctx,
                                             &iparms.tbl_scope_id);
@@ -1311,10 +1382,10 @@ ulp_mapper_em_tbl_process(struct bnxt_ulp_mapper_parms *parms,
        }
 
        /* Mark action process */
-       if (parms->device_params->global_fid_enable &&
+       if (mtype == BNXT_ULP_FLOW_MEM_TYPE_EXT &&
            tbl->resource_type == TF_MEM_EXTERNAL)
                rc = ulp_mapper_mark_gfid_process(parms, tbl, iparms.flow_id);
-       else if (!parms->device_params->global_fid_enable &&
+       else if (mtype == BNXT_ULP_FLOW_MEM_TYPE_INT &&
                 tbl->resource_type == TF_MEM_INTERNAL)
                rc = ulp_mapper_mark_act_ptr_process(parms, tbl);
        if (rc) {
@@ -1402,7 +1473,7 @@ ulp_mapper_index_tbl_process(struct bnxt_ulp_mapper_parms *parms,
                flds = ulp_mapper_act_result_fields_get(tbl, &num_flds,
                                                        &encap_flds);
 
-       if (!flds || !num_flds) {
+       if (!flds || (!num_flds && !encap_flds)) {
                BNXT_TF_DBG(ERR, "template undefined for the index table\n");
                return -EINVAL;
        }
@@ -1411,7 +1482,7 @@ ulp_mapper_index_tbl_process(struct bnxt_ulp_mapper_parms *parms,
        for (i = 0; i < (num_flds + encap_flds); i++) {
                /* set the swap index if encap swap bit is enabled */
                if (parms->device_params->encap_byte_swap && encap_flds &&
-                   ((i + 1) == num_flds))
+                   (i == num_flds))
                        ulp_blob_encap_swap_idx_set(&data);
 
                /* Process the result fields */
@@ -1424,18 +1495,15 @@ ulp_mapper_index_tbl_process(struct bnxt_ulp_mapper_parms *parms,
                        BNXT_TF_DBG(ERR, "data field failed\n");
                        return rc;
                }
+       }
 
-               /* if encap bit swap is enabled perform the bit swap */
-               if (parms->device_params->encap_byte_swap && encap_flds) {
-                       if ((i + 1) == (num_flds + encap_flds))
-                               ulp_blob_perform_encap_swap(&data);
+       /* if encap bit swap is enabled perform the bit swap */
+       if (parms->device_params->encap_byte_swap && encap_flds) {
+               ulp_blob_perform_encap_swap(&data);
 #ifdef RTE_LIBRTE_BNXT_TRUFLOW_DEBUG
-                       if ((i + 1) == (num_flds + encap_flds)) {
-                               BNXT_TF_DBG(INFO, "Dump fter encap swap\n");
-                               ulp_mapper_blob_dump(&data);
-                       }
+               BNXT_TF_DBG(INFO, "Dump after encap swap\n");
+               ulp_mapper_blob_dump(&data);
 #endif
-               }
        }
 
        /* Perform the tf table allocation by filling the alloc params */
@@ -1513,6 +1581,12 @@ ulp_mapper_index_tbl_process(struct bnxt_ulp_mapper_parms *parms,
                goto error;
        }
 
+       /* Perform the VF rep action */
+       rc = ulp_mapper_mark_vfr_idx_process(parms, tbl);
+       if (rc) {
+               BNXT_TF_DBG(ERR, "Failed to add vfr mark rc = %d\n", rc);
+               goto error;
+       }
        return rc;
 error:
        /*
@@ -1554,7 +1628,8 @@ ulp_mapper_cache_tbl_process(struct bnxt_ulp_mapper_parms *parms,
                BNXT_TF_DBG(ERR, "Failed to get key fields\n");
                return -EINVAL;
        }
-       if (!ulp_blob_init(&key, tbl->key_bit_size, parms->order)) {
+       if (!ulp_blob_init(&key, tbl->key_bit_size,
+                          parms->device_params->byte_order)) {
                BNXT_TF_DBG(ERR, "Failed to alloc blob\n");
                return -EINVAL;
        }
@@ -1739,6 +1814,11 @@ ulp_mapper_action_tbls_process(struct bnxt_ulp_mapper_parms *parms)
                switch (tbl->resource_func) {
                case BNXT_ULP_RESOURCE_FUNC_INDEX_TABLE:
                        rc = ulp_mapper_index_tbl_process(parms, tbl, false);
+                       if (rc) {
+                               BNXT_TF_DBG(ERR, "Resource type %d failed\n",
+                                           tbl->resource_func);
+                               return rc;
+                       }
                        break;
                default:
                        BNXT_TF_DBG(ERR, "Unexpected action resource %d\n",
@@ -1746,11 +1826,6 @@ ulp_mapper_action_tbls_process(struct bnxt_ulp_mapper_parms *parms)
                        return -EINVAL;
                }
        }
-       if (rc) {
-               BNXT_TF_DBG(ERR, "Resource type %d failed\n",
-                           tbl->resource_func);
-               return rc;
-       }
 
        return rc;
 }
@@ -1952,7 +2027,6 @@ ulp_mapper_flow_create(struct bnxt_ulp_context *ulp_ctx,
                       struct bnxt_ulp_mapper_create_parms *cparms,
                       uint32_t *flowid)
 {
-       struct bnxt_ulp_device_params *device_params;
        struct bnxt_ulp_mapper_parms parms;
        struct ulp_regfile regfile;
        int32_t  rc, trc;
@@ -2010,15 +2084,13 @@ ulp_mapper_flow_create(struct bnxt_ulp_context *ulp_ctx,
                return -EINVAL;
        }
 
-       /* Get the byte order for the further processing from device params */
-       device_params = bnxt_ulp_device_params_get(parms.dev_id);
-       if (!device_params) {
+       /* Get the device params, it will be used in later processing */
+       parms.device_params = bnxt_ulp_device_params_get(parms.dev_id);
+       if (!parms.device_params) {
                BNXT_TF_DBG(ERR, "No class tables for %d:%d\n",
                            parms.dev_id, parms.class_tid);
                return -EINVAL;
        }
-       parms.order = device_params->byte_order;
-       parms.encap_byte_swap = device_params->encap_byte_swap;
 
        /* initialize the registry file for further processing */
        if (!ulp_regfile_init(parms.regfile)) {