X-Git-Url: http://git.droids-corp.org/?a=blobdiff_plain;f=drivers%2Fnet%2Fbnxt%2Ftf_ulp%2Fulp_mapper.c;h=6ac4b0f83bdd21ac09e18bffd8b4157c35c30beb;hb=ce836c07e5322bb7967c6de204568a1c143b1391;hp=86858b856f677f9990b7f6d04ba4ecd52d58d7a2;hpb=7936f260953782374d43b46373a04087ac9a5ec1;p=dpdk.git diff --git a/drivers/net/bnxt/tf_ulp/ulp_mapper.c b/drivers/net/bnxt/tf_ulp/ulp_mapper.c index 86858b856f..6ac4b0f83b 100644 --- a/drivers/net/bnxt/tf_ulp/ulp_mapper.c +++ b/drivers/net/bnxt/tf_ulp/ulp_mapper.c @@ -16,6 +16,7 @@ #include "ulp_mark_mgr.h" #include "ulp_flow_db.h" #include "ulp_mapper.h" +#include "tf_util.h" static struct bnxt_ulp_glb_resource_info * ulp_mapper_glb_resource_info_list_get(uint32_t *num_entries) @@ -677,6 +678,98 @@ error: return rc; } +/* + * Process the identifier instruction and extract it from result blob. + * Increment the identifier reference count and store it in the flow database. + */ +static int32_t +ulp_mapper_ident_extract(struct bnxt_ulp_mapper_parms *parms, + struct bnxt_ulp_mapper_tbl_info *tbl, + struct bnxt_ulp_mapper_ident_info *ident, + struct ulp_blob *res_blob) +{ + struct ulp_flow_db_res_params fid_parms; + uint64_t id = 0; + uint32_t idx = 0; + struct tf_search_identifier_parms sparms = { 0 }; + struct tf_free_identifier_parms free_parms = { 0 }; + struct tf *tfp; + int rc; + + /* Get the tfp from ulp context */ + tfp = bnxt_ulp_cntxt_tfp_get(parms->ulp_ctx); + if (!tfp) { + BNXT_TF_DBG(ERR, "Failed to get tf pointer\n"); + return -EINVAL; + } + + /* Extract the index from the result blob */ + rc = ulp_blob_pull(res_blob, (uint8_t *)&idx, sizeof(idx), + ident->ident_bit_pos, ident->ident_bit_size); + if (rc) { + BNXT_TF_DBG(ERR, "Failed to extract identifier from blob\n"); + return -EIO; + } + + /* populate the search params and search identifier shadow table */ + sparms.ident_type = ident->ident_type; + sparms.dir = tbl->direction; + /* convert the idx into cpu format */ + sparms.search_id = tfp_be_to_cpu_32(idx); + + /* Search identifier also increase the reference count */ + rc = tf_search_identifier(tfp, &sparms); + if (rc) { + BNXT_TF_DBG(ERR, "Search ident %s:%x failed.\n", + tf_dir_2_str(sparms.dir), + sparms.search_id); + return rc; + } + BNXT_TF_DBG(INFO, "Search ident %s:%x.success.\n", + tf_dir_2_str(sparms.dir), + sparms.search_id); + + /* Write it to the regfile */ + id = (uint64_t)tfp_cpu_to_be_64(sparms.search_id); + if (!ulp_regfile_write(parms->regfile, ident->regfile_idx, id)) { + BNXT_TF_DBG(ERR, "Regfile[%d] write failed.\n", idx); + rc = -EINVAL; + /* Need to free the identifier, so goto error */ + goto error; + } + + /* Link the resource to the flow in the flow db */ + memset(&fid_parms, 0, sizeof(fid_parms)); + fid_parms.direction = tbl->direction; + fid_parms.resource_func = ident->resource_func; + fid_parms.resource_type = ident->ident_type; + fid_parms.resource_hndl = sparms.search_id; + fid_parms.critical_resource = BNXT_ULP_CRITICAL_RESOURCE_NO; + rc = ulp_flow_db_resource_add(parms->ulp_ctx, + parms->tbl_idx, + parms->fid, + &fid_parms); + if (rc) { + BNXT_TF_DBG(ERR, "Failed to link res to flow rc = %d\n", + rc); + /* Need to free the identifier, so goto error */ + goto error; + } + + return 0; + +error: + /* Need to free the identifier */ + free_parms.dir = tbl->direction; + free_parms.ident_type = ident->ident_type; + free_parms.id = sparms.search_id; + (void)tf_free_identifier(tfp, &free_parms); + BNXT_TF_DBG(ERR, "Ident extract failed for %s:%s:%x\n", + ident->description, + tf_dir_2_str(tbl->direction), sparms.search_id); + return rc; +} + static int32_t ulp_mapper_result_field_process(struct bnxt_ulp_mapper_parms *parms, enum tf_dir dir, @@ -905,6 +998,41 @@ ulp_mapper_result_field_process(struct bnxt_ulp_mapper_parms *parms, return -EINVAL; } break; + case BNXT_ULP_MAPPER_OPC_IF_COMP_FIELD_THEN_CF_ELSE_CF: + if (!ulp_operand_read(fld->result_operand, + (uint8_t *)&idx, + sizeof(uint16_t))) { + BNXT_TF_DBG(ERR, "%s key operand read failed.\n", name); + return -EINVAL; + } + idx = tfp_be_to_cpu_16(idx); + if (idx >= BNXT_ULP_CF_IDX_LAST) { + BNXT_TF_DBG(ERR, "%s invalid index %u\n", name, idx); + return -EINVAL; + } + /* check if the computed field is set */ + if (ULP_COMP_FLD_IDX_RD(parms, idx)) + val = fld->result_operand_true; + else + val = fld->result_operand_false; + + /* read the appropriate computed field */ + if (!ulp_operand_read(val, (uint8_t *)&idx, sizeof(uint16_t))) { + BNXT_TF_DBG(ERR, "%s val operand read failed\n", name); + return -EINVAL; + } + idx = tfp_be_to_cpu_16(idx); + if (idx >= BNXT_ULP_CF_IDX_LAST) { + BNXT_TF_DBG(ERR, "%s invalid index %u\n", name, idx); + return -EINVAL; + } + val = ulp_blob_push_32(blob, &parms->comp_fld[idx], + fld->field_bit_size); + if (!val) { + BNXT_TF_DBG(ERR, "%s push to key blob failed\n", name); + return -EINVAL; + } + break; default: BNXT_TF_DBG(ERR, "invalid result mapper opcode 0x%x\n", fld->result_opcode); @@ -1189,21 +1317,180 @@ ulp_mapper_mark_vfr_idx_process(struct bnxt_ulp_mapper_parms *parms, return rc; } +/* + * Tcam table - create the result blob. + * data [out] - the result blob data + */ +static int32_t +ulp_mapper_tcam_tbl_result_create(struct bnxt_ulp_mapper_parms *parms, + struct bnxt_ulp_mapper_tbl_info *tbl, + struct ulp_blob *data) +{ + struct bnxt_ulp_mapper_result_field_info *dflds; + uint32_t num_dflds; + uint32_t encap_flds = 0; + uint32_t i; + int32_t rc = 0; + + /* Create the result data blob */ + dflds = ulp_mapper_result_fields_get(tbl, &num_dflds, + &encap_flds); + if (!dflds || !num_dflds || encap_flds) { + BNXT_TF_DBG(ERR, "Failed to get data fields.\n"); + return -EINVAL; + } + + for (i = 0; i < num_dflds; i++) { + rc = ulp_mapper_result_field_process(parms, + tbl->direction, + &dflds[i], + data, + "TCAM Result"); + if (rc) { + BNXT_TF_DBG(ERR, "Failed to set data fields\n"); + return -EINVAL; + } + } + return rc; +} + +/* Tcam table scan the identifier list and allocate each identifier */ +static int32_t +ulp_mapper_tcam_tbl_scan_ident_alloc(struct bnxt_ulp_mapper_parms *parms, + struct bnxt_ulp_mapper_tbl_info *tbl) +{ + struct bnxt_ulp_mapper_ident_info *idents; + uint32_t num_idents; + uint32_t i; + + /* + * Since the cache entry is responsible for allocating + * identifiers when in use, allocate the identifiers only + * during normal processing. + */ + if (parms->tcam_tbl_opc == + BNXT_ULP_MAPPER_TCAM_TBL_OPC_NORMAL) { + idents = ulp_mapper_ident_fields_get(tbl, &num_idents); + + for (i = 0; i < num_idents; i++) { + if (ulp_mapper_ident_process(parms, tbl, + &idents[i], NULL)) + return -EINVAL; + } + } + return 0; +} + +/* + * Tcam table scan the identifier list and extract the identifier from + * the result blob. + */ +static int32_t +ulp_mapper_tcam_tbl_scan_ident_extract(struct bnxt_ulp_mapper_parms *parms, + struct bnxt_ulp_mapper_tbl_info *tbl, + struct ulp_blob *data) +{ + struct bnxt_ulp_mapper_ident_info *idents; + uint32_t num_idents = 0, i; + int32_t rc = 0; + + /* + * Extract the listed identifiers from the result field, + * no need to allocate them. + */ + idents = ulp_mapper_ident_fields_get(tbl, &num_idents); + for (i = 0; i < num_idents; i++) { + rc = ulp_mapper_ident_extract(parms, tbl, &idents[i], data); + if (rc) { + BNXT_TF_DBG(ERR, "Error in identifier extraction\n"); + return rc; + } + } + return rc; +} + +/* Internal function to write the tcam entry */ +static int32_t +ulp_mapper_tcam_tbl_entry_write(struct bnxt_ulp_mapper_parms *parms, + struct bnxt_ulp_mapper_tbl_info *tbl, + struct ulp_blob *key, + struct ulp_blob *mask, + struct ulp_blob *data, + uint16_t idx) +{ + struct tf_set_tcam_entry_parms sparms = { 0 }; + struct tf *tfp; + uint16_t tmplen; + int32_t rc; + + tfp = bnxt_ulp_cntxt_tfp_get(parms->ulp_ctx); + if (!tfp) { + BNXT_TF_DBG(ERR, "Failed to get truflow pointer\n"); + return -EINVAL; + } + + sparms.dir = tbl->direction; + sparms.tcam_tbl_type = tbl->resource_type; + sparms.idx = idx; + /* Already verified the key/mask lengths */ + sparms.key = ulp_blob_data_get(key, &tmplen); + sparms.mask = ulp_blob_data_get(mask, &tmplen); + sparms.key_sz_in_bits = tbl->key_bit_size; + sparms.result = ulp_blob_data_get(data, &tmplen); + + if (tbl->result_bit_size != tmplen) { + BNXT_TF_DBG(ERR, "Result len (%d) != Expected (%d)\n", + tmplen, tbl->result_bit_size); + return -EINVAL; + } + sparms.result_sz_in_bits = tbl->result_bit_size; + if (tf_set_tcam_entry(tfp, &sparms)) { + BNXT_TF_DBG(ERR, "tcam[%s][%s][%x] write failed.\n", + tf_tcam_tbl_2_str(sparms.tcam_tbl_type), + tf_dir_2_str(sparms.dir), sparms.idx); + return -EIO; + } + BNXT_TF_DBG(INFO, "tcam[%s][%s][%x] write success.\n", + tf_tcam_tbl_2_str(sparms.tcam_tbl_type), + tf_dir_2_str(sparms.dir), sparms.idx); + + /* Update cache with TCAM index if the was cache allocated. */ + if (parms->tcam_tbl_opc == + BNXT_ULP_MAPPER_TCAM_TBL_OPC_CACHE_ALLOC) { + if (!parms->cache_ptr) { + BNXT_TF_DBG(ERR, "Unable to update cache"); + return -EINVAL; + } + parms->cache_ptr->tcam_idx = idx; + } + + /* Mark action */ + rc = ulp_mapper_mark_act_ptr_process(parms, tbl); + if (rc) { + BNXT_TF_DBG(ERR, "failed mark action processing\n"); + return rc; + } + + return rc; +} + 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 ulp_blob key, mask, data; + struct ulp_blob key, mask, data, update_data; uint32_t i, num_kflds; struct tf *tfp; int32_t rc, trc; struct tf_alloc_tcam_entry_parms aparms = { 0 }; - struct tf_set_tcam_entry_parms sparms = { 0 }; + struct tf_search_tcam_entry_parms searchparms = { 0 }; struct ulp_flow_db_res_params fid_parms = { 0 }; struct tf_free_tcam_entry_parms free_parms = { 0 }; + enum bnxt_ulp_search_before_alloc search_flag; uint32_t hit = 0; uint16_t tmplen = 0; + uint16_t idx; /* Skip this if was handled by the cache. */ if (parms->tcam_tbl_opc == BNXT_ULP_MAPPER_TCAM_TBL_OPC_CACHE_SKIP) { @@ -1228,6 +1515,8 @@ ulp_mapper_tcam_tbl_process(struct bnxt_ulp_mapper_parms *parms, !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) || + !ulp_blob_init(&update_data, tbl->result_bit_size, parms->device_params->byte_order)) { BNXT_TF_DBG(ERR, "blob inits failed.\n"); return -EINVAL; @@ -1258,131 +1547,116 @@ 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) { - BNXT_TF_DBG(ERR, "Key len (%d) != Expected (%d)\n", - tmplen, tbl->key_bit_size); - return -EINVAL; - } - - aparms.mask = ulp_blob_data_get(&mask, &tmplen); - if (tbl->key_bit_size != tmplen) { - BNXT_TF_DBG(ERR, "Mask len (%d) != Expected (%d)\n", - tmplen, tbl->key_bit_size); - return -EINVAL; - } - - aparms.priority = tbl->priority; - - /* - * All failures after this succeeds require the entry to be freed. - * cannot return directly on failure, but needs to goto error - */ - rc = tf_alloc_tcam_entry(tfp, &aparms); - if (rc) { - BNXT_TF_DBG(ERR, "tcam alloc failed rc=%d.\n", rc); - return rc; - } - - hit = aparms.hit; - - /* Build the result */ - if (!tbl->srch_b4_alloc || !hit) { - struct bnxt_ulp_mapper_result_field_info *dflds; - struct bnxt_ulp_mapper_ident_info *idents; - uint32_t num_dflds, num_idents; - uint32_t encap_flds = 0; - + if (tbl->srch_b4_alloc == BNXT_ULP_SEARCH_BEFORE_ALLOC_NO) { /* - * Since the cache entry is responsible for allocating - * identifiers when in use, allocate the identifiers only - * during normal processing. + * No search for re-use is requested, so simply allocate the + * tcam index. */ - if (parms->tcam_tbl_opc == - BNXT_ULP_MAPPER_TCAM_TBL_OPC_NORMAL) { - idents = ulp_mapper_ident_fields_get(tbl, &num_idents); - - for (i = 0; i < num_idents; i++) { - rc = ulp_mapper_ident_process(parms, tbl, - &idents[i], NULL); - /* Already logged the error, just return */ - if (rc) - goto error; - } - } - - /* Create the result data blob */ - dflds = ulp_mapper_result_fields_get(tbl, &num_dflds, - &encap_flds); - if (!dflds || !num_dflds || encap_flds) { - BNXT_TF_DBG(ERR, "Failed to get data fields.\n"); - rc = -EINVAL; - goto error; + 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) { + BNXT_TF_DBG(ERR, "Key len (%d) != Expected (%d)\n", + tmplen, tbl->key_bit_size); + return -EINVAL; } - for (i = 0; i < num_dflds; i++) { - rc = ulp_mapper_result_field_process(parms, - tbl->direction, - &dflds[i], - &data, - "TCAM Result"); - if (rc) { - BNXT_TF_DBG(ERR, "Failed to set data fields\n"); - goto error; - } + aparms.mask = ulp_blob_data_get(&mask, &tmplen); + if (tbl->key_bit_size != tmplen) { + BNXT_TF_DBG(ERR, "Mask len (%d) != Expected (%d)\n", + tmplen, tbl->key_bit_size); + return -EINVAL; } - sparms.dir = aparms.dir; - sparms.tcam_tbl_type = aparms.tcam_tbl_type; - sparms.idx = aparms.idx; - /* Already verified the key/mask lengths */ - sparms.key = ulp_blob_data_get(&key, &tmplen); - sparms.mask = ulp_blob_data_get(&mask, &tmplen); - sparms.key_sz_in_bits = tbl->key_bit_size; - sparms.result = ulp_blob_data_get(&data, &tmplen); + aparms.priority = tbl->priority; - if (tbl->result_bit_size != tmplen) { - BNXT_TF_DBG(ERR, "Result len (%d) != Expected (%d)\n", - tmplen, tbl->result_bit_size); - rc = -EINVAL; - goto error; + /* + * All failures after this succeeds require the entry to be + * freed. cannot return directly on failure, but needs to goto + * error. + */ + rc = tf_alloc_tcam_entry(tfp, &aparms); + if (rc) { + BNXT_TF_DBG(ERR, "tcam alloc failed rc=%d.\n", rc); + return rc; } - sparms.result_sz_in_bits = tbl->result_bit_size; - - rc = tf_set_tcam_entry(tfp, &sparms); + idx = aparms.idx; + hit = aparms.hit; + } else { + /* + * Searching before allocation to see if we already have an + * entry. This allows re-use of a constrained resource. + */ + searchparms.dir = tbl->direction; + searchparms.tcam_tbl_type = tbl->resource_type; + searchparms.key = ulp_blob_data_get(&key, &tmplen); + searchparms.key_sz_in_bits = tbl->key_bit_size; + searchparms.mask = ulp_blob_data_get(&mask, &tmplen); + searchparms.priority = tbl->priority; + searchparms.alloc = 1; + searchparms.result = ulp_blob_data_get(&data, &tmplen); + searchparms.result_sz_in_bits = tbl->result_bit_size; + + rc = tf_search_tcam_entry(tfp, &searchparms); if (rc) { - BNXT_TF_DBG(ERR, "tcam[%d][%s][%d] write failed.\n", - sparms.tcam_tbl_type, - (sparms.dir == TF_DIR_RX) ? "RX" : "TX", - sparms.idx); - goto error; + BNXT_TF_DBG(ERR, "tcam search failed rc=%d\n", rc); + return rc; } - /* Update cache with TCAM index if the was cache allocated. */ - if (parms->tcam_tbl_opc == - BNXT_ULP_MAPPER_TCAM_TBL_OPC_CACHE_ALLOC) { - if (!parms->cache_ptr) { - BNXT_TF_DBG(ERR, "Unable to update cache"); - rc = -EINVAL; - goto error; - } - parms->cache_ptr->tcam_idx = aparms.idx; + /* Successful search, check the result */ + if (searchparms.search_status == REJECT) { + BNXT_TF_DBG(ERR, "tcam alloc rejected\n"); + return -ENOMEM; } + idx = searchparms.idx; + hit = searchparms.hit; + } - /* 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; - goto error; + /* if it is miss then it is same as no search before alloc */ + if (!hit) + search_flag = BNXT_ULP_SEARCH_BEFORE_ALLOC_NO; + else + search_flag = tbl->srch_b4_alloc; + + switch (search_flag) { + case BNXT_ULP_SEARCH_BEFORE_ALLOC_NO: + /*Scan identifier list, allocate identifier and update regfile*/ + rc = ulp_mapper_tcam_tbl_scan_ident_alloc(parms, tbl); + /* Create the result blob */ + if (!rc) + rc = ulp_mapper_tcam_tbl_result_create(parms, tbl, + &data); + /* write the tcam entry */ + if (!rc) + rc = ulp_mapper_tcam_tbl_entry_write(parms, tbl, &key, + &mask, &data, idx); + break; + case BNXT_ULP_SEARCH_BEFORE_ALLOC_SEARCH_IF_HIT_SKIP: + /*Scan identifier list, extract identifier and update regfile*/ + rc = ulp_mapper_tcam_tbl_scan_ident_extract(parms, tbl, &data); + break; + case BNXT_ULP_SEARCH_BEFORE_ALLOC_SEARCH_IF_HIT_UPDATE: + /*Scan identifier list, extract identifier and update regfile*/ + rc = ulp_mapper_tcam_tbl_scan_ident_extract(parms, tbl, &data); + /* Create the result blob */ + if (!rc) + rc = ulp_mapper_tcam_tbl_result_create(parms, tbl, + &update_data); + /* Update/overwrite the tcam entry */ + if (!rc) + rc = ulp_mapper_tcam_tbl_entry_write(parms, tbl, &key, + &mask, + &update_data, idx); + break; + default: + BNXT_TF_DBG(ERR, "invalid search opcode\n"); + rc = -EINVAL; + break; } + if (rc) + goto error; /* * Only link the entry to the flow db in the event that cache was not @@ -1393,7 +1667,7 @@ ulp_mapper_tcam_tbl_process(struct bnxt_ulp_mapper_parms *parms, fid_parms.resource_func = tbl->resource_func; fid_parms.resource_type = tbl->resource_type; fid_parms.critical_resource = tbl->critical_resource; - fid_parms.resource_hndl = aparms.idx; + fid_parms.resource_hndl = idx; rc = ulp_flow_db_resource_add(parms->ulp_ctx, parms->tbl_idx, parms->fid, @@ -1419,11 +1693,11 @@ error: parms->tcam_tbl_opc = BNXT_ULP_MAPPER_TCAM_TBL_OPC_NORMAL; free_parms.dir = tbl->direction; free_parms.tcam_tbl_type = tbl->resource_type; - free_parms.idx = aparms.idx; + free_parms.idx = idx; trc = tf_free_tcam_entry(tfp, &free_parms); if (trc) BNXT_TF_DBG(ERR, "Failed to free tcam[%d][%d][%d] on failure\n", - tbl->resource_type, tbl->direction, aparms.idx); + tbl->resource_type, tbl->direction, idx); return rc; } @@ -1585,9 +1859,10 @@ ulp_mapper_index_tbl_process(struct bnxt_ulp_mapper_parms *parms, struct ulp_blob data; uint64_t idx = 0; uint16_t tmplen; - uint32_t i, num_flds; + uint32_t i, num_flds, index, hit; int32_t rc = 0, trc = 0; struct tf_alloc_tbl_entry_parms aparms = { 0 }; + struct tf_search_tbl_entry_parms srchparms = { 0 }; struct tf_set_tbl_entry_parms sparms = { 0 }; struct tf_free_tbl_entry_parms free_parms = { 0 }; uint32_t tbl_scope_id; @@ -1689,33 +1964,59 @@ ulp_mapper_index_tbl_process(struct bnxt_ulp_mapper_parms *parms, return 0; /* success */ } + index = 0; + hit = 0; /* Perform the tf table allocation by filling the alloc params */ - aparms.dir = tbl->direction; - aparms.type = tbl->resource_type; - aparms.search_enable = tbl->srch_b4_alloc; - aparms.result = ulp_blob_data_get(&data, &tmplen); - aparms.result_sz_in_bytes = ULP_BITS_2_BYTE(tmplen); - aparms.tbl_scope_id = tbl_scope_id; - - /* All failures after the alloc succeeds require a free */ - rc = tf_alloc_tbl_entry(tfp, &aparms); - if (rc) { - BNXT_TF_DBG(ERR, "Alloc table[%d][%s] failed rc=%d\n", - aparms.type, - (aparms.dir == TF_DIR_RX) ? "RX" : "TX", - rc); - return rc; + if (tbl->srch_b4_alloc) { + memset(&srchparms, 0, sizeof(srchparms)); + srchparms.dir = tbl->direction; + srchparms.type = tbl->resource_type; + srchparms.alloc = 1; + srchparms.result = ulp_blob_data_get(&data, &tmplen); + srchparms.result_sz_in_bytes = ULP_BITS_2_BYTE(tmplen); + srchparms.tbl_scope_id = tbl_scope_id; + rc = tf_search_tbl_entry(tfp, &srchparms); + if (rc) { + BNXT_TF_DBG(ERR, "Alloc table[%s][%s] failed rc=%d\n", + tf_tbl_type_2_str(tbl->resource_type), + tf_dir_2_str(tbl->direction), rc); + return rc; + } + if (srchparms.search_status == REJECT) { + BNXT_TF_DBG(ERR, "Alloc table[%s][%s] rejected.\n", + tf_tbl_type_2_str(tbl->resource_type), + tf_dir_2_str(tbl->direction)); + return -ENOMEM; + } + index = srchparms.idx; + hit = srchparms.hit; + } else { + aparms.dir = tbl->direction; + aparms.type = tbl->resource_type; + aparms.search_enable = tbl->srch_b4_alloc; + aparms.result = ulp_blob_data_get(&data, &tmplen); + aparms.result_sz_in_bytes = ULP_BITS_2_BYTE(tmplen); + aparms.tbl_scope_id = tbl_scope_id; + + /* All failures after the alloc succeeds require a free */ + rc = tf_alloc_tbl_entry(tfp, &aparms); + if (rc) { + BNXT_TF_DBG(ERR, "Alloc table[%s][%s] failed rc=%d\n", + tf_tbl_type_2_str(tbl->resource_type), + tf_dir_2_str(tbl->direction), rc); + return rc; + } + index = aparms.idx; } - /* * calculate the idx for the result record, for external EM the offset * needs to be shifted accordingly. If external non-inline table types * are used then need to revisit this logic. */ - if (aparms.type == TF_TBL_TYPE_EXT) - idx = TF_ACT_REC_OFFSET_2_PTR(aparms.idx); + if (tbl->resource_type == TF_TBL_TYPE_EXT) + idx = TF_ACT_REC_OFFSET_2_PTR(index); else - idx = aparms.idx; + idx = index; /* Always storing values in Regfile in BE */ idx = tfp_cpu_to_be_64(idx); @@ -1729,12 +2030,12 @@ ulp_mapper_index_tbl_process(struct bnxt_ulp_mapper_parms *parms, } /* Perform the tf table set by filling the set params */ - if (!tbl->srch_b4_alloc || !aparms.hit) { + if (!tbl->srch_b4_alloc || !hit) { sparms.dir = tbl->direction; sparms.type = tbl->resource_type; sparms.data = ulp_blob_data_get(&data, &tmplen); sparms.data_sz_in_bytes = ULP_BITS_2_BYTE(tmplen); - sparms.idx = aparms.idx; + sparms.idx = index; sparms.tbl_scope_id = tbl_scope_id; rc = tf_set_tbl_entry(tfp, &sparms); @@ -1754,7 +2055,7 @@ ulp_mapper_index_tbl_process(struct bnxt_ulp_mapper_parms *parms, fid_parms.resource_func = tbl->resource_func; fid_parms.resource_type = tbl->resource_type; fid_parms.resource_sub_type = tbl->resource_sub_type; - fid_parms.resource_hndl = aparms.idx; + fid_parms.resource_hndl = index; fid_parms.critical_resource = BNXT_ULP_CRITICAL_RESOURCE_NO; rc = ulp_flow_db_resource_add(parms->ulp_ctx, @@ -1781,7 +2082,7 @@ error: */ free_parms.dir = tbl->direction; free_parms.type = tbl->resource_type; - free_parms.idx = aparms.idx; + free_parms.idx = index; free_parms.tbl_scope_id = tbl_scope_id; trc = tf_free_tbl_entry(tfp, &free_parms);