X-Git-Url: http://git.droids-corp.org/?a=blobdiff_plain;f=drivers%2Fnet%2Fbnxt%2Ftf_ulp%2Fulp_mapper.c;h=d5c129b3a64eeec0a5e41bcb0d09075bb9dc3bc3;hb=188bf91d6e24bd91a403fefdbb3663bdd336cc12;hp=5ed481ab367ecc78ea442cae4c7ed8956d608815;hpb=0c9fe336d5a84acbdb911a04289c429f59b3f8e9;p=dpdk.git diff --git a/drivers/net/bnxt/tf_ulp/ulp_mapper.c b/drivers/net/bnxt/tf_ulp/ulp_mapper.c index 5ed481ab36..d5c129b3a6 100644 --- a/drivers/net/bnxt/tf_ulp/ulp_mapper.c +++ b/drivers/net/bnxt/tf_ulp/ulp_mapper.c @@ -14,8 +14,8 @@ #include "tfp.h" #include "tf_ext_flow_handle.h" #include "ulp_mark_mgr.h" -#include "ulp_flow_db.h" #include "ulp_mapper.h" +#include "ulp_flow_db.h" #include "tf_util.h" static struct bnxt_ulp_glb_resource_info * @@ -256,7 +256,7 @@ ulp_mapper_tbl_list_get(struct bnxt_ulp_mapper_parms *mparms, * * Returns array of Key fields, or NULL on error. */ -static struct bnxt_ulp_mapper_class_key_field_info * +static struct bnxt_ulp_mapper_key_field_info * ulp_mapper_key_fields_get(struct bnxt_ulp_mapper_parms *mparms, struct bnxt_ulp_mapper_tbl_info *tbl, uint32_t *num_flds) @@ -537,6 +537,65 @@ ulp_mapper_mark_free(struct bnxt_ulp_context *ulp, res->resource_hndl); } + +static inline int32_t +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; + } + + /* 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; + } + } + + /* 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); + return -EINVAL; + } + return 0; +} + +static inline int32_t +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; + + parent_fid = (uint32_t)res->resource_hndl; + if (!parent_fid) + return 0; /* Already freed - orphan child*/ + + /* reset the child flow bitset*/ + if (ulp_flow_db_parent_child_flow_set(ulp, parent_fid, child_fid, 0)) { + BNXT_TF_DBG(ERR, "error in resetting child flow bitset %x:%x\n", + parent_fid, child_fid); + return -EINVAL; + } + return 0; +} + /* * Process the identifier instruction and either store it in the flow database * or return it in the val (if not NULL) on success. If val is NULL, the @@ -1009,7 +1068,7 @@ ulp_mapper_result_field_process(struct bnxt_ulp_mapper_parms *parms, static int32_t ulp_mapper_keymask_field_process(struct bnxt_ulp_mapper_parms *parms, enum tf_dir dir, - struct bnxt_ulp_mapper_class_key_field_info *f, + struct bnxt_ulp_mapper_key_field_info *f, struct ulp_blob *blob, uint8_t is_key, const char *name) @@ -1020,7 +1079,7 @@ ulp_mapper_keymask_field_process(struct bnxt_ulp_mapper_parms *parms, uint8_t *operand; struct ulp_regfile *regfile = parms->regfile; uint8_t *val = NULL; - struct bnxt_ulp_mapper_class_key_field_info *fld = f; + struct bnxt_ulp_mapper_key_field_info *fld = f; uint32_t field_size; if (is_key) { @@ -1438,11 +1497,34 @@ ulp_mapper_tcam_tbl_entry_write(struct bnxt_ulp_mapper_parms *parms, return rc; } +#define BNXT_ULP_WC_TCAM_SLICE_SIZE 80 +/* internal function to post process the key/mask blobs for wildcard tcam tbl */ +static void ulp_mapper_wc_tcam_tbl_post_process(struct ulp_blob *blob, + uint32_t len) +{ + uint8_t mode[2] = {0x0, 0x0}; + uint32_t mode_len = len / BNXT_ULP_WC_TCAM_SLICE_SIZE; + uint32_t size, idx; + + /* Add the mode bits to the key and mask*/ + if (mode_len == 2) + mode[1] = 2; + else if (mode_len > 2) + mode[1] = 3; + + size = BNXT_ULP_WC_TCAM_SLICE_SIZE + ULP_BYTE_2_BITS(sizeof(mode)); + for (idx = 0; idx < mode_len; idx++) + ulp_blob_insert(blob, (size * idx), mode, + ULP_BYTE_2_BITS(sizeof(mode))); + ulp_blob_perform_64B_word_swap(blob); + ulp_blob_perform_64B_byte_swap(blob); +} + static int32_t ulp_mapper_tcam_tbl_process(struct bnxt_ulp_mapper_parms *parms, struct bnxt_ulp_mapper_tbl_info *tbl) { - struct bnxt_ulp_mapper_class_key_field_info *kflds; + struct bnxt_ulp_mapper_key_field_info *kflds; struct ulp_blob key, mask, data, update_data; uint32_t i, num_kflds; struct tf *tfp; @@ -1474,9 +1556,9 @@ ulp_mapper_tcam_tbl_process(struct bnxt_ulp_mapper_parms *parms, return -EINVAL; } - if (!ulp_blob_init(&key, tbl->key_bit_size, + if (!ulp_blob_init(&key, tbl->blob_key_bit_size, parms->device_params->byte_order) || - !ulp_blob_init(&mask, tbl->key_bit_size, + !ulp_blob_init(&mask, tbl->blob_key_bit_size, parms->device_params->byte_order) || !ulp_blob_init(&data, tbl->result_bit_size, parms->device_params->byte_order) || @@ -1486,6 +1568,11 @@ ulp_mapper_tcam_tbl_process(struct bnxt_ulp_mapper_parms *parms, return -EINVAL; } + if (tbl->resource_type == TF_TCAM_TBL_TYPE_WC_TCAM) { + key.byte_order = BNXT_ULP_BYTE_ORDER_BE; + mask.byte_order = BNXT_ULP_BYTE_ORDER_BE; + } + /* create the key/mask */ /* * NOTE: The WC table will require some kind of flag to handle the @@ -1511,6 +1598,11 @@ ulp_mapper_tcam_tbl_process(struct bnxt_ulp_mapper_parms *parms, } } + if (tbl->resource_type == TF_TCAM_TBL_TYPE_WC_TCAM) { + ulp_mapper_wc_tcam_tbl_post_process(&key, tbl->key_bit_size); + ulp_mapper_wc_tcam_tbl_post_process(&mask, tbl->key_bit_size); + } + if (tbl->srch_b4_alloc == BNXT_ULP_SEARCH_BEFORE_ALLOC_NO) { /* * No search for re-use is requested, so simply allocate the @@ -1519,18 +1611,18 @@ ulp_mapper_tcam_tbl_process(struct bnxt_ulp_mapper_parms *parms, aparms.dir = tbl->direction; aparms.tcam_tbl_type = tbl->resource_type; aparms.search_enable = tbl->srch_b4_alloc; - aparms.key_sz_in_bits = tbl->key_bit_size; aparms.key = ulp_blob_data_get(&key, &tmplen); - if (tbl->key_bit_size != tmplen) { + aparms.key_sz_in_bits = tmplen; + if (tbl->blob_key_bit_size != tmplen) { BNXT_TF_DBG(ERR, "Key len (%d) != Expected (%d)\n", - tmplen, tbl->key_bit_size); + tmplen, tbl->blob_key_bit_size); return -EINVAL; } aparms.mask = ulp_blob_data_get(&mask, &tmplen); - if (tbl->key_bit_size != tmplen) { + if (tbl->blob_key_bit_size != tmplen) { BNXT_TF_DBG(ERR, "Mask len (%d) != Expected (%d)\n", - tmplen, tbl->key_bit_size); + tmplen, tbl->blob_key_bit_size); return -EINVAL; } @@ -1670,7 +1762,7 @@ static int32_t ulp_mapper_em_tbl_process(struct bnxt_ulp_mapper_parms *parms, struct bnxt_ulp_mapper_tbl_info *tbl) { - struct bnxt_ulp_mapper_class_key_field_info *kflds; + struct bnxt_ulp_mapper_key_field_info *kflds; struct bnxt_ulp_mapper_result_field_info *dflds; struct ulp_blob key, data; uint32_t i, num_kflds, num_dflds; @@ -1679,11 +1771,17 @@ ulp_mapper_em_tbl_process(struct bnxt_ulp_mapper_parms *parms, struct ulp_flow_db_res_params fid_parms = { 0 }; struct tf_insert_em_entry_parms iparms = { 0 }; struct tf_delete_em_entry_parms free_parms = { 0 }; + enum bnxt_ulp_flow_mem_type mtype; int32_t trc; - enum bnxt_ulp_flow_mem_type mtype = parms->device_params->flow_mem_type; int32_t rc = 0; uint32_t encap_flds = 0; + rc = bnxt_ulp_cntxt_mem_type_get(parms->ulp_ctx, &mtype); + if (rc) { + BNXT_TF_DBG(ERR, "Failed to get the mem type for EM\n"); + return -EINVAL; + } + kflds = ulp_mapper_key_fields_get(parms, tbl, &num_kflds); if (!kflds || !num_kflds) { BNXT_TF_DBG(ERR, "Failed to get key fields\n"); @@ -2055,7 +2153,7 @@ static int32_t ulp_mapper_cache_tbl_process(struct bnxt_ulp_mapper_parms *parms, struct bnxt_ulp_mapper_tbl_info *tbl) { - struct bnxt_ulp_mapper_class_key_field_info *kflds; + struct bnxt_ulp_mapper_key_field_info *kflds; struct bnxt_ulp_mapper_cache_entry *cache_entry; struct bnxt_ulp_mapper_ident_info *idents; uint32_t i, num_kflds = 0, num_idents = 0; @@ -2327,6 +2425,8 @@ ulp_mapper_glb_resource_info_init(struct bnxt_ulp_context *ulp_ctx, * Function to process the conditional opcode of the mapper table. * returns 1 to skip the table. * return 0 to continue processing the table. + * + * defaults to skip */ static int32_t ulp_mapper_tbl_cond_opcode_process(struct bnxt_ulp_mapper_parms *parms, @@ -2376,6 +2476,42 @@ ulp_mapper_tbl_cond_opcode_process(struct bnxt_ulp_mapper_parms *parms, return rc; } +/* + * Function to process the memtype opcode of the mapper table. + * returns 1 to skip the table. + * return 0 to continue processing the table. + * + * defaults to skip + */ +static int32_t +ulp_mapper_tbl_memtype_opcode_process(struct bnxt_ulp_mapper_parms *parms, + struct bnxt_ulp_mapper_tbl_info *tbl) +{ + enum bnxt_ulp_flow_mem_type mtype = BNXT_ULP_FLOW_MEM_TYPE_INT; + int32_t rc = 1; + + bnxt_ulp_cntxt_mem_type_get(parms->ulp_ctx, &mtype); + + switch (tbl->mem_type_opcode) { + case BNXT_ULP_MEM_TYPE_OPCODE_EXECUTE_IF_INT: + if (mtype == BNXT_ULP_FLOW_MEM_TYPE_INT) + rc = 0; + break; + case BNXT_ULP_MEM_TYPE_OPCODE_EXECUTE_IF_EXT: + if (mtype == BNXT_ULP_FLOW_MEM_TYPE_EXT) + rc = 0; + break; + case BNXT_ULP_MEM_TYPE_OPCODE_NOP: + rc = 0; + break; + default: + BNXT_TF_DBG(ERR, + "Invalid arg in mapper in memtype opcode\n"); + break; + } + return rc; +} + static int32_t ulp_mapper_tbls_process(struct bnxt_ulp_mapper_parms *parms, uint32_t tid) { @@ -2394,6 +2530,8 @@ ulp_mapper_tbls_process(struct bnxt_ulp_mapper_parms *parms, uint32_t tid) for (i = 0; i < num_tbls; i++) { struct bnxt_ulp_mapper_tbl_info *tbl = &tbls[i]; + if (ulp_mapper_tbl_memtype_opcode_process(parms, tbl)) + continue; if (ulp_mapper_tbl_cond_opcode_process(parms, tbl)) continue; @@ -2438,6 +2576,7 @@ error: static int32_t ulp_mapper_resource_free(struct bnxt_ulp_context *ulp, + uint32_t fid, struct ulp_flow_db_res_params *res) { struct tf *tfp; @@ -2474,6 +2613,12 @@ ulp_mapper_resource_free(struct bnxt_ulp_context *ulp, case BNXT_ULP_RESOURCE_FUNC_HW_FID: rc = ulp_mapper_mark_free(ulp, res); break; + case BNXT_ULP_RESOURCE_FUNC_PARENT_FLOW: + rc = ulp_mapper_parent_flow_free(ulp, fid, res); + break; + case BNXT_ULP_RESOURCE_FUNC_CHILD_FLOW: + rc = ulp_mapper_child_flow_free(ulp, fid, res); + break; default: break; } @@ -2482,12 +2627,12 @@ ulp_mapper_resource_free(struct bnxt_ulp_context *ulp, } int32_t -ulp_mapper_resources_free(struct bnxt_ulp_context *ulp_ctx, - uint32_t fid, - enum bnxt_ulp_flow_db_tables tbl_type) +ulp_mapper_resources_free(struct bnxt_ulp_context *ulp_ctx, + enum bnxt_ulp_fdb_type flow_type, + uint32_t fid) { - struct ulp_flow_db_res_params res_parms = { 0 }; - int32_t rc, trc; + struct ulp_flow_db_res_params res_parms = { 0 }; + int32_t rc, trc; if (!ulp_ctx) { BNXT_TF_DBG(ERR, "Invalid parms, unable to free flow\n"); @@ -2499,7 +2644,7 @@ ulp_mapper_resources_free(struct bnxt_ulp_context *ulp_ctx, * while status is good */ res_parms.critical_resource = BNXT_ULP_CRITICAL_RESOURCE_YES; - rc = ulp_flow_db_resource_del(ulp_ctx, tbl_type, fid, &res_parms); + rc = ulp_flow_db_resource_del(ulp_ctx, flow_type, fid, &res_parms); if (rc) { /* @@ -2507,12 +2652,12 @@ ulp_mapper_resources_free(struct bnxt_ulp_context *ulp_ctx, * It likely means that the flow did not exist in the flow db. */ BNXT_TF_DBG(ERR, "Flow[%d][0x%08x] failed to free (rc=%d)\n", - tbl_type, fid, rc); + flow_type, fid, rc); return rc; } while (!rc) { - trc = ulp_mapper_resource_free(ulp_ctx, &res_parms); + trc = ulp_mapper_resource_free(ulp_ctx, fid, &res_parms); if (trc) /* * On fail, we still need to attempt to free the @@ -2521,20 +2666,20 @@ ulp_mapper_resources_free(struct bnxt_ulp_context *ulp_ctx, BNXT_TF_DBG(ERR, "Flow[%d][0x%x] Res[%d][0x%016" PRIx64 "] failed rc=%d.\n", - tbl_type, fid, res_parms.resource_func, + flow_type, fid, res_parms.resource_func, res_parms.resource_hndl, trc); /* All subsequent call require the non-critical_resource */ res_parms.critical_resource = BNXT_ULP_CRITICAL_RESOURCE_NO; rc = ulp_flow_db_resource_del(ulp_ctx, - tbl_type, + flow_type, fid, &res_parms); } /* Free the Flow ID since we've removed all resources */ - rc = ulp_flow_db_fid_free(ulp_ctx, tbl_type, fid); + rc = ulp_flow_db_fid_free(ulp_ctx, flow_type, fid); return rc; } @@ -2562,14 +2707,15 @@ ulp_mapper_glb_resource_info_deinit(struct bnxt_ulp_context *ulp_ctx, /*convert it from BE to cpu */ res.resource_hndl = tfp_be_to_cpu_64(ent->resource_hndl); - ulp_mapper_resource_free(ulp_ctx, &res); + ulp_mapper_resource_free(ulp_ctx, 0, &res); } } } int32_t -ulp_mapper_flow_destroy(struct bnxt_ulp_context *ulp_ctx, uint32_t fid, - enum bnxt_ulp_flow_db_tables flow_tbl_type) +ulp_mapper_flow_destroy(struct bnxt_ulp_context *ulp_ctx, + enum bnxt_ulp_fdb_type flow_type, + uint32_t fid) { int32_t rc; @@ -2577,15 +2723,9 @@ ulp_mapper_flow_destroy(struct bnxt_ulp_context *ulp_ctx, uint32_t fid, BNXT_TF_DBG(ERR, "Invalid parms, unable to free flow\n"); return -EINVAL; } - if (bnxt_ulp_cntxt_acquire_fdb_lock(ulp_ctx)) { - BNXT_TF_DBG(ERR, "Flow db lock acquire failed\n"); - return -EINVAL; - } - rc = ulp_mapper_resources_free(ulp_ctx, fid, flow_tbl_type); - bnxt_ulp_cntxt_release_fdb_lock(ulp_ctx); + rc = ulp_mapper_resources_free(ulp_ctx, flow_type, fid); return rc; - } /* Function to handle the default global templates that are allocated during @@ -2624,7 +2764,7 @@ ulp_mapper_glb_template_table_init(struct bnxt_ulp_context *ulp_ctx) parms.ulp_ctx = ulp_ctx; parms.dev_id = dev_id; parms.mapper_data = mapper_data; - parms.flow_type = BNXT_ULP_DEFAULT_FLOW_TABLE; + parms.flow_type = BNXT_ULP_FDB_TYPE_DEFAULT; parms.tmpl_type = BNXT_ULP_TEMPLATE_TYPE_CLASS; /* Get the class table entry from dev id and class id */ @@ -2649,8 +2789,7 @@ ulp_mapper_glb_template_table_init(struct bnxt_ulp_context *ulp_ctx) */ int32_t ulp_mapper_flow_create(struct bnxt_ulp_context *ulp_ctx, - struct bnxt_ulp_mapper_create_parms *cparms, - uint32_t *flowid) + struct bnxt_ulp_mapper_create_parms *cparms) { struct bnxt_ulp_mapper_parms parms; struct ulp_regfile regfile; @@ -2673,6 +2812,9 @@ ulp_mapper_flow_create(struct bnxt_ulp_context *ulp_ctx, parms.act_tid = cparms->act_tid; 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.fid = cparms->flow_id; /* Get the device id from the ulp context */ if (bnxt_ulp_cntxt_dev_id_get(ulp_ctx, &parms.dev_id)) { @@ -2713,26 +2855,7 @@ ulp_mapper_flow_create(struct bnxt_ulp_context *ulp_ctx, return -EINVAL; } - /* Protect flow creation */ - if (bnxt_ulp_cntxt_acquire_fdb_lock(ulp_ctx)) { - BNXT_TF_DBG(ERR, "Flow db lock acquire failed\n"); - return -EINVAL; - } - - /* 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. - */ - rc = ulp_flow_db_fid_alloc(ulp_ctx, - parms.flow_type, - cparms->func_id, - &parms.fid); - if (rc) { - BNXT_TF_DBG(ERR, "Unable to allocate flow table entry\n"); - bnxt_ulp_cntxt_release_fdb_lock(ulp_ctx); - return rc; - } - + /* Process the action template list from the selected action table*/ if (parms.act_tid) { parms.tmpl_type = BNXT_ULP_TEMPLATE_TYPE_ACTION; /* Process the action template tables */ @@ -2750,16 +2873,25 @@ ulp_mapper_flow_create(struct bnxt_ulp_context *ulp_ctx, goto flow_error; } - *flowid = parms.fid; - bnxt_ulp_cntxt_release_fdb_lock(ulp_ctx); + /* setup the parent-child details */ + if (parms.parent_flow) { + /* create a parent flow details */ + rc = ulp_flow_db_parent_flow_create(&parms); + if (rc) + goto flow_error; + } else if (parms.parent_fid) { + /* create a child flow details */ + rc = ulp_flow_db_child_flow_create(&parms); + if (rc) + goto flow_error; + } return rc; flow_error: - bnxt_ulp_cntxt_release_fdb_lock(ulp_ctx); /* Free all resources that were allocated during flow creation */ - trc = ulp_mapper_flow_destroy(ulp_ctx, parms.fid, - BNXT_ULP_REGULAR_FLOW_TABLE); + trc = ulp_mapper_flow_destroy(ulp_ctx, BNXT_ULP_FDB_TYPE_REGULAR, + parms.fid); if (trc) BNXT_TF_DBG(ERR, "Failed to free all resources rc=%d\n", trc);