net/bnxt: support tunnel offload
[dpdk.git] / drivers / net / bnxt / tf_ulp / ulp_mapper.c
index acd9f99..6d804c7 100644 (file)
 #include "ulp_ha_mgr.h"
 #include "bnxt_tf_pmd_shim.h"
 
+#ifdef RTE_LIBRTE_BNXT_TRUFLOW_DEBUG
+#include "ulp_template_debug_proto.h"
+#include "ulp_tf_debug.h"
+#endif
+
 static uint8_t mapper_fld_zeros[16] = { 0 };
 
 static uint8_t mapper_fld_ones[16] = {
@@ -156,6 +161,13 @@ ulp_mapper_resource_ident_allocate(struct bnxt_ulp_context *ulp_ctx,
                tf_free_identifier(tfp, &fparms);
                return rc;
        }
+#ifdef RTE_LIBRTE_BNXT_TRUFLOW_DEBUG
+#ifdef RTE_LIBRTE_BNXT_TRUFLOW_DEBUG_MAPPER
+       BNXT_TF_DBG(DEBUG, "Allocated Glb Res Ident [%s][%d][%d] = 0x%04x\n",
+                   tf_dir_2_str(iparms.dir),
+                   glb_res->glb_regfile_index, iparms.ident_type, iparms.id);
+#endif
+#endif
        return rc;
 }
 
@@ -189,13 +201,12 @@ ulp_mapper_resource_index_tbl_alloc(struct bnxt_ulp_context *ulp_ctx,
 
        aparms.type = glb_res->resource_type;
        aparms.dir = glb_res->direction;
-       aparms.search_enable = 0;
        aparms.tbl_scope_id = tbl_scope_id;
 
        /* Allocate the index tbl using tf api */
        rc = tf_alloc_tbl_entry(tfp, &aparms);
        if (rc) {
-               BNXT_TF_DBG(ERR, "Failed to alloc identifier [%s][%d]\n",
+               BNXT_TF_DBG(ERR, "Failed to alloc index table [%s][%d]\n",
                            tf_dir_2_str(aparms.dir), aparms.type);
                return rc;
        }
@@ -217,6 +228,13 @@ ulp_mapper_resource_index_tbl_alloc(struct bnxt_ulp_context *ulp_ctx,
                tf_free_tbl_entry(tfp, &free_parms);
                return rc;
        }
+#ifdef RTE_LIBRTE_BNXT_TRUFLOW_DEBUG
+#ifdef RTE_LIBRTE_BNXT_TRUFLOW_DEBUG_MAPPER
+       BNXT_TF_DBG(DEBUG, "Allocated Glb Res Index [%s][%d][%d] = 0x%04x\n",
+                   tf_dir_2_str(aparms.dir),
+                   glb_res->glb_regfile_index, aparms.type, aparms.idx);
+#endif
+#endif
        return rc;
 }
 
@@ -526,34 +544,14 @@ ulp_mapper_parent_flow_free(struct bnxt_ulp_context *ulp,
                            uint32_t parent_fid,
                            struct ulp_flow_db_res_params *res)
 {
-       uint32_t idx, child_fid = 0, parent_idx;
-       struct bnxt_ulp_flow_db *flow_db;
-
-       parent_idx = (uint32_t)res->resource_hndl;
-
-       /* check the validity of the parent fid */
-       if (ulp_flow_db_parent_flow_idx_get(ulp, parent_fid, &idx) ||
-           idx != parent_idx) {
-               BNXT_TF_DBG(ERR, "invalid parent flow id %x\n", parent_fid);
-               return -EINVAL;
-       }
+       uint32_t pc_idx;
 
-       /* Clear all the child flows parent index */
-       flow_db = bnxt_ulp_cntxt_ptr2_flow_db_get(ulp);
-       while (!ulp_flow_db_parent_child_flow_next_entry_get(flow_db, idx,
-                                                            &child_fid)) {
-               /* update the child flows resource handle */
-               if (ulp_flow_db_child_flow_reset(ulp, BNXT_ULP_FDB_TYPE_REGULAR,
-                                                child_fid)) {
-                       BNXT_TF_DBG(ERR, "failed to reset child flow %x\n",
-                                   child_fid);
-                       return -EINVAL;
-               }
-       }
+       pc_idx = (uint32_t)res->resource_hndl;
 
-       /* free the parent entry in the parent table flow */
-       if (ulp_flow_db_parent_flow_free(ulp, parent_fid)) {
-               BNXT_TF_DBG(ERR, "failed to free parent flow %x\n", parent_fid);
+       /* reset the child flow bitset*/
+       if (ulp_flow_db_pc_db_parent_flow_set(ulp, pc_idx, parent_fid, 0)) {
+               BNXT_TF_DBG(ERR, "error in reset parent flow bitset %x:%x\n",
+                           pc_idx, parent_fid);
                return -EINVAL;
        }
        return 0;
@@ -564,16 +562,14 @@ ulp_mapper_child_flow_free(struct bnxt_ulp_context *ulp,
                           uint32_t child_fid,
                           struct ulp_flow_db_res_params *res)
 {
-       uint32_t parent_fid;
+       uint32_t pc_idx;
 
-       parent_fid = (uint32_t)res->resource_hndl;
-       if (!parent_fid)
-               return 0; /* Already freed - orphan child*/
+       pc_idx = (uint32_t)res->resource_hndl;
 
        /* reset the child flow bitset*/
-       if (ulp_flow_db_parent_child_flow_set(ulp, parent_fid, child_fid, 0)) {
+       if (ulp_flow_db_pc_db_child_flow_set(ulp, pc_idx, child_fid, 0)) {
                BNXT_TF_DBG(ERR, "error in resetting child flow bitset %x:%x\n",
-                           parent_fid, child_fid);
+                           pc_idx, child_fid);
                return -EINVAL;
        }
        return 0;
@@ -785,6 +781,9 @@ ulp_mapper_ident_process(struct bnxt_ulp_mapper_parms *parms,
                            tf_ident_2_str(iparms.ident_type));
                return rc;
        }
+       BNXT_TF_INF("Alloc ident %s:%s.success.\n",
+                   tf_dir_2_str(iparms.dir),
+                   tf_ident_2_str(iparms.ident_type));
 
        id = (uint64_t)tfp_cpu_to_be_64(iparms.id);
        if (ulp_regfile_write(parms->regfile, idx, id)) {
@@ -814,6 +813,11 @@ ulp_mapper_ident_process(struct bnxt_ulp_mapper_parms *parms,
        } else {
                *val = iparms.id;
        }
+#ifdef RTE_LIBRTE_BNXT_TRUFLOW_DEBUG
+#ifdef RTE_LIBRTE_BNXT_TRUFLOW_DEBUG_MAPPER
+       ulp_mapper_ident_field_dump("Ident", ident, tbl, iparms.id);
+#endif
+#endif
        return 0;
 
 error:
@@ -878,6 +882,10 @@ ulp_mapper_ident_extract(struct bnxt_ulp_mapper_parms *parms,
                            sparms.search_id);
                return rc;
        }
+       BNXT_TF_INF("Search ident %s:%s:%x.success.\n",
+                   tf_dir_2_str(sparms.dir),
+                   tf_tbl_type_2_str(sparms.ident_type),
+                   sparms.search_id);
 
        /* Write it to the regfile */
        id = (uint64_t)tfp_cpu_to_be_64(sparms.search_id);
@@ -905,6 +913,11 @@ ulp_mapper_ident_extract(struct bnxt_ulp_mapper_parms *parms,
                goto error;
        }
 
+#ifdef RTE_LIBRTE_BNXT_TRUFLOW_DEBUG
+#ifdef RTE_LIBRTE_BNXT_TRUFLOW_DEBUG_MAPPER
+       ulp_mapper_ident_field_dump("Ident", ident, tbl, sparms.search_id);
+#endif
+#endif
        return 0;
 
 error:
@@ -997,7 +1010,7 @@ ulp_mapper_field_src_process(struct bnxt_ulp_mapper_parms *parms,
                        return -EINVAL;
                }
                idx = tfp_be_to_cpu_16(idx);
-               if (idx >= BNXT_ULP_CF_IDX_LAST || bytelen > sizeof(uint64_t)) {
+               if (idx >= BNXT_ULP_CF_IDX_LAST || bytelen > sizeof(uint32_t)) {
                        BNXT_TF_DBG(ERR, "comp field [%d] read oob %d\n", idx,
                                    bytelen);
                        return -EINVAL;
@@ -1449,7 +1462,16 @@ ulp_mapper_field_opc_process(struct bnxt_ulp_mapper_parms *parms,
                break;
        }
 
-       return rc;
+       if (!rc) {
+#ifdef RTE_LIBRTE_BNXT_TRUFLOW_DEBUG
+#ifdef RTE_LIBRTE_BNXT_TRUFLOW_DEBUG_MAPPER
+               if (fld->field_src1 != BNXT_ULP_FIELD_SRC_ZERO)
+                       ulp_mapper_field_dump(name, fld, blob, write_idx, val,
+                                             val_len);
+#endif
+#endif
+               return rc;
+       }
 error:
        BNXT_TF_DBG(ERR, "Error in %s:%s process %u:%u\n", name,
                    fld->description, (val) ? write_idx : 0, val_len);
@@ -1501,8 +1523,15 @@ ulp_mapper_tbl_result_build(struct bnxt_ulp_mapper_parms *parms,
        }
 
        /* if encap bit swap is enabled perform the bit swap */
-       if (parms->device_params->encap_byte_swap && encap_flds)
+       if (parms->device_params->encap_byte_swap && encap_flds) {
                ulp_blob_perform_encap_swap(data);
+#ifdef RTE_LIBRTE_BNXT_TRUFLOW_DEBUG
+#ifdef RTE_LIBRTE_BNXT_TRUFLOW_DEBUG_MAPPER
+               BNXT_TF_DBG(INFO, "Dump after encap swap\n");
+               ulp_mapper_blob_dump(data);
+#endif
+#endif
+       }
 
        return rc;
 }
@@ -1726,6 +1755,9 @@ ulp_mapper_tcam_tbl_entry_write(struct bnxt_ulp_mapper_parms *parms,
                            tf_dir_2_str(sparms.dir), sparms.idx);
                return -EIO;
        }
+       BNXT_TF_INF("tcam[%s][%s][%x] write success.\n",
+                   tf_tcam_tbl_2_str(sparms.tcam_tbl_type),
+                   tf_dir_2_str(sparms.dir), sparms.idx);
 
        /* Mark action */
        rc = ulp_mapper_mark_act_ptr_process(parms, tbl);
@@ -1734,6 +1766,11 @@ ulp_mapper_tcam_tbl_entry_write(struct bnxt_ulp_mapper_parms *parms,
                return rc;
        }
 
+#ifdef RTE_LIBRTE_BNXT_TRUFLOW_DEBUG
+#ifdef RTE_LIBRTE_BNXT_TRUFLOW_DEBUG_MAPPER
+       ulp_mapper_tcam_entry_dump("TCAM", idx, tbl, key, mask, data);
+#endif
+#endif
        return rc;
 }
 
@@ -1839,6 +1876,12 @@ static void ulp_mapper_wc_tcam_tbl_post_process(struct ulp_blob *blob)
 {
        ulp_blob_perform_64B_word_swap(blob);
        ulp_blob_perform_64B_byte_swap(blob);
+#ifdef RTE_LIBRTE_BNXT_TRUFLOW_DEBUG
+#ifdef RTE_LIBRTE_BNXT_TRUFLOW_DEBUG_MAPPER
+       BNXT_TF_DBG(INFO, "Dump after wc tcam post process\n");
+       ulp_mapper_blob_dump(blob);
+#endif
+#endif
 }
 
 static int32_t
@@ -1879,6 +1922,12 @@ ulp_mapper_tcam_tbl_process(struct bnxt_ulp_mapper_parms *parms,
                return -EINVAL;
        }
 
+       /* If only allocation of identifier then perform and exit */
+       if (tbl->tbl_opcode == BNXT_ULP_TCAM_TBL_OPC_ALLOC_IDENT) {
+               rc = ulp_mapper_tcam_tbl_scan_ident_alloc(parms, tbl);
+               return rc;
+       }
+
        kflds = ulp_mapper_key_fields_get(parms, tbl, &num_kflds);
        if (!kflds || !num_kflds) {
                BNXT_TF_DBG(ERR, "Failed to get key fields\n");
@@ -2135,6 +2184,11 @@ ulp_mapper_em_tbl_process(struct bnxt_ulp_mapper_parms *parms,
                BNXT_TF_DBG(ERR, "Failed to build the result blob\n");
                return rc;
        }
+#ifdef RTE_LIBRTE_BNXT_TRUFLOW_DEBUG
+#ifdef RTE_LIBRTE_BNXT_TRUFLOW_DEBUG_MAPPER
+       ulp_mapper_result_dump("EM Result", tbl, &data);
+#endif
+#endif
        if (dparms->dynamic_pad_en) {
                uint32_t abits = dparms->em_blk_align_bits;
 
@@ -2149,6 +2203,11 @@ ulp_mapper_em_tbl_process(struct bnxt_ulp_mapper_parms *parms,
                ulp_blob_pad_align(&data, abits);
 
                ulp_blob_perform_byte_reverse(&data, ULP_BITS_2_BYTE(abits));
+#ifdef RTE_LIBRTE_BNXT_TRUFLOW_DEBUG
+#ifdef RTE_LIBRTE_BNXT_TRUFLOW_DEBUG_MAPPER
+       ulp_mapper_result_dump("EM Merged Result", tbl, &data);
+#endif
+#endif
        }
 
        /* do the transpose for the internal EM keys */
@@ -2161,6 +2220,11 @@ ulp_mapper_em_tbl_process(struct bnxt_ulp_mapper_parms *parms,
                }
                tmplen = ulp_blob_data_len_get(&key);
                ulp_blob_perform_byte_reverse(&key, ULP_BITS_2_BYTE(tmplen));
+#ifdef RTE_LIBRTE_BNXT_TRUFLOW_DEBUG
+#ifdef RTE_LIBRTE_BNXT_TRUFLOW_DEBUG_MAPPER
+       ulp_mapper_result_dump("EM Key Transpose", tbl, &key);
+#endif
+#endif
        }
 
        rc = bnxt_ulp_cntxt_tbl_scope_id_get(parms->ulp_ctx,
@@ -2191,6 +2255,12 @@ ulp_mapper_em_tbl_process(struct bnxt_ulp_mapper_parms *parms,
                return rc;
        }
 
+#ifdef RTE_LIBRTE_BNXT_TRUFLOW_DEBUG
+#ifdef RTE_LIBRTE_BNXT_TRUFLOW_DEBUG_MAPPER
+       ulp_mapper_em_dump("EM", &key, &data, &iparms);
+       /* tf_dump_tables(tfp, iparms.tbl_scope_id); */
+#endif
+#endif
        /* Mark action process */
        if (mtype == BNXT_ULP_FLOW_MEM_TYPE_EXT &&
            tbl->resource_type == TF_MEM_EXTERNAL)
@@ -2249,7 +2319,7 @@ ulp_mapper_index_tbl_process(struct bnxt_ulp_mapper_parms *parms,
        struct tf_free_tbl_entry_parms free_parms = { 0 };
        uint32_t tbl_scope_id;
        struct tf *tfp;
-       struct bnxt_ulp_glb_resource_info glb_res;
+       struct bnxt_ulp_glb_resource_info glb_res = { 0 };
        uint16_t bit_size;
        bool alloc = false;
        bool write = false;
@@ -2480,6 +2550,9 @@ ulp_mapper_index_tbl_process(struct bnxt_ulp_mapper_parms *parms,
                                    sparms.idx, rc);
                        goto error;
                }
+               BNXT_TF_INF("Index table[%s][%s][%x] write successful.\n",
+                           tf_tbl_type_2_str(sparms.type),
+                           tf_dir_2_str(sparms.dir), sparms.idx);
 
                /* Calculate action record size */
                if (tbl->resource_type == TF_TBL_TYPE_EXT) {
@@ -2636,6 +2709,10 @@ ulp_mapper_if_tbl_process(struct bnxt_ulp_mapper_parms *parms,
                            iftbl_params.idx, rc);
                return rc;
        }
+       BNXT_TF_INF("Set table[%s][%s][%x] success.\n",
+                   tf_if_tbl_2_str(iftbl_params.type),
+                   tf_dir_2_str(iftbl_params.dir),
+                   iftbl_params.idx);
 
        /*
         * TBD: Need to look at the need to store idx in flow db for restore
@@ -2698,6 +2775,12 @@ ulp_mapper_gen_tbl_process(struct bnxt_ulp_mapper_parms *parms,
 
        /* The_key is a byte array convert it to a search index */
        cache_key = ulp_blob_data_get(&key, &tmplen);
+#ifdef RTE_LIBRTE_BNXT_TRUFLOW_DEBUG
+#ifdef RTE_LIBRTE_BNXT_TRUFLOW_DEBUG_MAPPER
+       BNXT_TF_DBG(DEBUG, "The gen_tbl[%u] key\n", tbl_idx);
+       ulp_mapper_blob_dump(&key);
+#endif
+#endif
        /* get the generic table  */
        gen_tbl_list = &parms->mapper_data->gen_tbl_list[tbl_idx];
 
@@ -3496,6 +3579,11 @@ ulp_mapper_tbls_process(struct bnxt_ulp_mapper_parms *parms, uint32_t tid)
        for (tbl_idx = 0; tbl_idx < num_tbls && cond_goto;) {
                tbl = &tbls[tbl_idx];
                cond_goto = tbl->execute_info.cond_true_goto;
+#ifdef RTE_LIBRTE_BNXT_TRUFLOW_DEBUG
+#ifdef RTE_LIBRTE_BNXT_TRUFLOW_DEBUG_MAPPER
+               ulp_mapper_table_dump(tbl, tbl_idx);
+#endif
+#endif
                /* Process the conditional func code opcodes */
                if (ulp_mapper_func_info_process(parms, tbl)) {
                        BNXT_TF_DBG(ERR, "Failed to process cond update\n");
@@ -3785,7 +3873,7 @@ ulp_mapper_flow_create(struct bnxt_ulp_context *ulp_ctx,
        parms.class_tid = cparms->class_tid;
        parms.flow_type = cparms->flow_type;
        parms.parent_flow = cparms->parent_flow;
-       parms.parent_fid = cparms->parent_fid;
+       parms.child_flow = cparms->child_flow;
        parms.fid = cparms->flow_id;
        parms.tun_idx = cparms->tun_idx;
        parms.app_priority = cparms->app_priority;
@@ -3850,7 +3938,7 @@ ulp_mapper_flow_create(struct bnxt_ulp_context *ulp_ctx,
                rc = ulp_flow_db_parent_flow_create(&parms);
                if (rc)
                        goto flow_error;
-       } else if (parms.parent_fid) {
+       } else if (parms.child_flow) {
                /* create a child flow details */
                rc = ulp_flow_db_child_flow_create(&parms);
                if (rc)