X-Git-Url: http://git.droids-corp.org/?a=blobdiff_plain;f=drivers%2Fnet%2Fbnxt%2Ftf_ulp%2Fulp_mapper.c;h=734db7c6ce350e4a7c46594186b164ce4d095595;hb=eee264adc95ed049642a9c7d0e4b897d51ccaccf;hp=c3c96d8be50d4b2225e4a8fa326a819d381a1e6b;hpb=642feef813241a813c219ccbd8e815825bb174b1;p=dpdk.git diff --git a/drivers/net/bnxt/tf_ulp/ulp_mapper.c b/drivers/net/bnxt/tf_ulp/ulp_mapper.c index c3c96d8be5..734db7c6ce 100644 --- a/drivers/net/bnxt/tf_ulp/ulp_mapper.c +++ b/drivers/net/bnxt/tf_ulp/ulp_mapper.c @@ -6,7 +6,7 @@ #include #include #include "bnxt.h" -#include "ulp_template_db.h" +#include "ulp_template_db_enum.h" #include "ulp_template_struct.h" #include "bnxt_tf_common.h" #include "ulp_utils.h" @@ -159,7 +159,7 @@ ulp_mapper_act_prop_size_get(uint32_t idx) * * Returns An array of action tables to implement the flow, or NULL on error. */ -static struct bnxt_ulp_mapper_act_tbl_info * +static struct bnxt_ulp_mapper_tbl_info * ulp_mapper_action_tbl_list_get(uint32_t dev_id, uint32_t tid, uint32_t *num_tbls) @@ -196,7 +196,7 @@ ulp_mapper_action_tbl_list_get(uint32_t dev_id, * returns An array of classifier tables to implement the flow, or NULL on * error */ -static struct bnxt_ulp_mapper_class_tbl_info * +static struct bnxt_ulp_mapper_tbl_info * ulp_mapper_class_tbl_list_get(uint32_t dev_id, uint32_t tid, uint32_t *num_tbls) @@ -228,7 +228,7 @@ ulp_mapper_class_tbl_list_get(uint32_t dev_id, * Returns array of Key fields, or NULL on error. */ static struct bnxt_ulp_mapper_class_key_field_info * -ulp_mapper_key_fields_get(struct bnxt_ulp_mapper_class_tbl_info *tbl, +ulp_mapper_key_fields_get(struct bnxt_ulp_mapper_tbl_info *tbl, uint32_t *num_flds) { uint32_t idx; @@ -255,7 +255,7 @@ ulp_mapper_key_fields_get(struct bnxt_ulp_mapper_class_tbl_info *tbl, * Returns array of data fields, or NULL on error. */ static struct bnxt_ulp_mapper_result_field_info * -ulp_mapper_result_fields_get(struct bnxt_ulp_mapper_class_tbl_info *tbl, +ulp_mapper_result_fields_get(struct bnxt_ulp_mapper_tbl_info *tbl, uint32_t *num_flds) { uint32_t idx; @@ -280,7 +280,7 @@ ulp_mapper_result_fields_get(struct bnxt_ulp_mapper_class_tbl_info *tbl, * Returns array of data fields, or NULL on error. */ static struct bnxt_ulp_mapper_result_field_info * -ulp_mapper_act_result_fields_get(struct bnxt_ulp_mapper_act_tbl_info *tbl, +ulp_mapper_act_result_fields_get(struct bnxt_ulp_mapper_tbl_info *tbl, uint32_t *num_rslt_flds, uint32_t *num_encap_flds) { @@ -307,7 +307,7 @@ ulp_mapper_act_result_fields_get(struct bnxt_ulp_mapper_act_tbl_info *tbl, * returns array of ident fields, or NULL on error */ static struct bnxt_ulp_mapper_ident_info * -ulp_mapper_ident_fields_get(struct bnxt_ulp_mapper_class_tbl_info *tbl, +ulp_mapper_ident_fields_get(struct bnxt_ulp_mapper_tbl_info *tbl, uint32_t *num_flds) { uint32_t idx; @@ -324,13 +324,14 @@ ulp_mapper_ident_fields_get(struct bnxt_ulp_mapper_class_tbl_info *tbl, static struct bnxt_ulp_mapper_cache_entry * ulp_mapper_cache_entry_get(struct bnxt_ulp_context *ulp, - enum bnxt_ulp_cache_tbl_id id, + uint32_t id, uint16_t key) { struct bnxt_ulp_mapper_data *mapper_data; mapper_data = bnxt_ulp_cntxt_ptr2_mapper_data_get(ulp); - if (!mapper_data || !mapper_data->cache_tbl[id]) { + if (!mapper_data || id >= BNXT_ULP_CACHE_TBL_MAX_SZ || + !mapper_data->cache_tbl[id]) { BNXT_TF_DBG(ERR, "Unable to acquire the cache tbl (%d)\n", id); return NULL; } @@ -364,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; @@ -521,7 +522,7 @@ ulp_mapper_mark_free(struct bnxt_ulp_context *ulp, */ static int32_t ulp_mapper_ident_process(struct bnxt_ulp_mapper_parms *parms, - struct bnxt_ulp_mapper_class_tbl_info *tbl, + struct bnxt_ulp_mapper_tbl_info *tbl, struct bnxt_ulp_mapper_ident_info *ident, uint16_t *val) { @@ -539,7 +540,7 @@ ulp_mapper_ident_process(struct bnxt_ulp_mapper_parms *parms, return -EINVAL; } - idx = ident->regfile_wr_idx; + idx = ident->regfile_idx; iparms.ident_type = ident->ident_type; iparms.dir = tbl->direction; @@ -567,7 +568,7 @@ ulp_mapper_ident_process(struct bnxt_ulp_mapper_parms *parms, fid_parms.resource_func = ident->resource_func; fid_parms.resource_type = ident->ident_type; fid_parms.resource_hndl = iparms.id; - fid_parms.critical_resource = 0; + fid_parms.critical_resource = BNXT_ULP_CRITICAL_RESOURCE_NO; rc = ulp_flow_db_resource_add(parms->ulp_ctx, parms->tbl_idx, @@ -610,16 +611,18 @@ ulp_mapper_result_field_process(struct bnxt_ulp_mapper_parms *parms, uint8_t *val = NULL; uint64_t regval; uint32_t val_size = 0, field_size = 0; + uint64_t act_bit; + uint8_t act_val; switch (fld->result_opcode) { - case BNXT_ULP_RESULT_OPC_SET_TO_CONSTANT: + case BNXT_ULP_MAPPER_OPC_SET_TO_CONSTANT: val = fld->result_operand; if (!ulp_blob_push(blob, val, fld->field_bit_size)) { BNXT_TF_DBG(ERR, "%s failed to add field\n", name); return -EINVAL; } break; - case BNXT_ULP_RESULT_OPC_SET_TO_ACT_PROP: + case BNXT_ULP_MAPPER_OPC_SET_TO_ACT_PROP: if (!ulp_operand_read(fld->result_operand, (uint8_t *)&idx, sizeof(uint16_t))) { BNXT_TF_DBG(ERR, "%s operand read failed\n", name); @@ -643,7 +646,25 @@ ulp_mapper_result_field_process(struct bnxt_ulp_mapper_parms *parms, return -EINVAL; } break; - case BNXT_ULP_RESULT_OPC_SET_TO_ENCAP_ACT_PROP_SZ: + case BNXT_ULP_MAPPER_OPC_SET_TO_ACT_BIT: + if (!ulp_operand_read(fld->result_operand, + (uint8_t *)&act_bit, sizeof(uint64_t))) { + BNXT_TF_DBG(ERR, "%s operand read failed\n", name); + return -EINVAL; + } + act_bit = tfp_be_to_cpu_64(act_bit); + act_val = ULP_BITMAP_ISSET(parms->act_bitmap->bits, act_bit); + if (fld->field_bit_size > ULP_BYTE_2_BITS(sizeof(act_val))) { + BNXT_TF_DBG(ERR, "%s field size is incorrect\n", name); + return -EINVAL; + } + if (!ulp_blob_push(blob, &act_val, fld->field_bit_size)) { + BNXT_TF_DBG(ERR, "%s push field failed\n", name); + return -EINVAL; + } + val = &act_val; + break; + case BNXT_ULP_MAPPER_OPC_SET_TO_ENCAP_ACT_PROP_SZ: if (!ulp_operand_read(fld->result_operand, (uint8_t *)&idx, sizeof(uint16_t))) { BNXT_TF_DBG(ERR, "%s operand read failed\n", name); @@ -675,7 +696,7 @@ ulp_mapper_result_field_process(struct bnxt_ulp_mapper_parms *parms, val_size = ULP_BYTE_2_BITS(val_size); ulp_blob_push_encap(blob, val, val_size); break; - case BNXT_ULP_RESULT_OPC_SET_TO_REGFILE: + case BNXT_ULP_MAPPER_OPC_SET_TO_REGFILE: if (!ulp_operand_read(fld->result_operand, (uint8_t *)&idx, sizeof(uint16_t))) { BNXT_TF_DBG(ERR, "%s operand read failed\n", name); @@ -696,7 +717,7 @@ ulp_mapper_result_field_process(struct bnxt_ulp_mapper_parms *parms, return -EINVAL; } break; - case BNXT_ULP_RESULT_OPC_SET_TO_GLB_REGFILE: + case BNXT_ULP_MAPPER_OPC_SET_TO_GLB_REGFILE: if (!ulp_operand_read(fld->result_operand, (uint8_t *)&idx, sizeof(uint16_t))) { @@ -717,7 +738,7 @@ ulp_mapper_result_field_process(struct bnxt_ulp_mapper_parms *parms, return -EINVAL; } break; - case BNXT_ULP_RESULT_OPC_SET_TO_COMP_FIELD: + case BNXT_ULP_MAPPER_OPC_SET_TO_COMP_FIELD: if (!ulp_operand_read(fld->result_operand, (uint8_t *)&idx, sizeof(uint16_t))) { @@ -732,6 +753,13 @@ ulp_mapper_result_field_process(struct bnxt_ulp_mapper_parms *parms, BNXT_TF_DBG(ERR, "%s push to key blob failed\n", name); return -EINVAL; } + break; + case BNXT_ULP_MAPPER_OPC_SET_TO_ZERO: + if (ulp_blob_pad_push(blob, fld->field_bit_size) < 0) { + BNXT_TF_DBG(ERR, "%s too large for blob\n", name); + return -EINVAL; + } + break; default: return -EINVAL; @@ -768,21 +796,21 @@ ulp_mapper_keymask_field_process(struct bnxt_ulp_mapper_parms *parms, bitlen = fld->field_bit_size; switch (opcode) { - case BNXT_ULP_SPEC_OPC_SET_TO_CONSTANT: + case BNXT_ULP_MAPPER_OPC_SET_TO_CONSTANT: val = operand; if (!ulp_blob_push(blob, val, bitlen)) { BNXT_TF_DBG(ERR, "%s push to key blob failed\n", name); return -EINVAL; } break; - case BNXT_ULP_SPEC_OPC_ADD_PAD: - if (!ulp_blob_pad_push(blob, bitlen)) { + case BNXT_ULP_MAPPER_OPC_SET_TO_ZERO: + if (ulp_blob_pad_push(blob, bitlen) < 0) { BNXT_TF_DBG(ERR, "%s pad too large for blob\n", name); return -EINVAL; } break; - case BNXT_ULP_SPEC_OPC_SET_TO_HDR_FIELD: + case BNXT_ULP_MAPPER_OPC_SET_TO_HDR_FIELD: if (!ulp_operand_read(operand, (uint8_t *)&idx, sizeof(uint16_t))) { BNXT_TF_DBG(ERR, "%s key operand read failed.\n", name); @@ -809,7 +837,7 @@ ulp_mapper_keymask_field_process(struct bnxt_ulp_mapper_parms *parms, return -EINVAL; } break; - case BNXT_ULP_SPEC_OPC_SET_TO_COMP_FIELD: + case BNXT_ULP_MAPPER_OPC_SET_TO_COMP_FIELD: if (!ulp_operand_read(operand, (uint8_t *)&idx, sizeof(uint16_t))) { BNXT_TF_DBG(ERR, "%s key operand read failed.\n", name); @@ -824,7 +852,7 @@ ulp_mapper_keymask_field_process(struct bnxt_ulp_mapper_parms *parms, return -EINVAL; } break; - case BNXT_ULP_SPEC_OPC_SET_TO_REGFILE: + case BNXT_ULP_MAPPER_OPC_SET_TO_REGFILE: if (!ulp_operand_read(operand, (uint8_t *)&idx, sizeof(uint16_t))) { BNXT_TF_DBG(ERR, "%s key operand read failed.\n", name); @@ -844,7 +872,7 @@ ulp_mapper_keymask_field_process(struct bnxt_ulp_mapper_parms *parms, return -EINVAL; } break; - case BNXT_ULP_SPEC_OPC_SET_TO_GLB_REGFILE: + case BNXT_ULP_MAPPER_OPC_SET_TO_GLB_REGFILE: if (!ulp_operand_read(operand, (uint8_t *)&idx, sizeof(uint16_t))) { BNXT_TF_DBG(ERR, "%s key operand read failed.\n", name); @@ -871,185 +899,150 @@ ulp_mapper_keymask_field_process(struct bnxt_ulp_mapper_parms *parms, return 0; } -/* Function to alloc action record and set the table. */ static int32_t -ulp_mapper_action_alloc_and_set(struct bnxt_ulp_mapper_parms *parms, - struct ulp_blob *blob) +ulp_mapper_mark_gfid_process(struct bnxt_ulp_mapper_parms *parms, + struct bnxt_ulp_mapper_tbl_info *tbl, + uint64_t flow_id) { - struct ulp_flow_db_res_params fid_parms; - struct tf_alloc_tbl_entry_parms alloc_parms = { 0 }; - struct tf_free_tbl_entry_parms free_parms = { 0 }; - struct bnxt_ulp_mapper_act_tbl_info *atbls = parms->atbls; - int32_t rc = 0; - int32_t trc; - uint64_t idx; - uint32_t tbl_scope_id; - - bnxt_ulp_cntxt_tbl_scope_id_get(parms->ulp_ctx, &tbl_scope_id); - - /* Set the allocation parameters for the table*/ - alloc_parms.dir = atbls->direction; - alloc_parms.type = atbls->resource_type; - alloc_parms.search_enable = atbls->srch_b4_alloc; - alloc_parms.result = ulp_blob_data_get(blob, - &alloc_parms.result_sz_in_bytes); - alloc_parms.tbl_scope_id = tbl_scope_id; - if (!alloc_parms.result) { - BNXT_TF_DBG(ERR, "blob is not populated\n"); - return -EINVAL; - } + 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; - rc = tf_alloc_tbl_entry(parms->tfp, &alloc_parms); + 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))) + return rc; /* no need to perform gfid process */ + + /* Get the mark id details from action property */ + memcpy(&mark, &parms->act_prop->act_details[BNXT_ULP_ACT_PROP_IDX_MARK], + sizeof(mark)); + mark = tfp_be_to_cpu_32(mark); + + TF_GET_GFID_FROM_FLOW_ID(flow_id, gfid); + mark_flag = BNXT_ULP_MARK_GLOBAL_HW_FID; + rc = ulp_mark_db_mark_add(parms->ulp_ctx, mark_flag, + gfid, mark); if (rc) { - BNXT_TF_DBG(ERR, "table type= [%d] dir = [%s] alloc failed\n", - alloc_parms.type, - (alloc_parms.dir == TF_DIR_RX) ? "RX" : "TX"); + 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 = gfid; + 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; +} - /* Need to calculate the idx for the result record */ - uint64_t tmpidx = alloc_parms.idx; - - if (atbls->resource_type == TF_TBL_TYPE_EXT) - tmpidx = TF_ACT_REC_OFFSET_2_PTR(alloc_parms.idx); - else - tmpidx = alloc_parms.idx; - - idx = tfp_cpu_to_be_64(tmpidx); +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; - /* Store the allocated index for future use in the regfile */ - rc = ulp_regfile_write(parms->regfile, atbls->regfile_wr_idx, idx); - if (!rc) { - BNXT_TF_DBG(ERR, "regfile[%d] write failed\n", - atbls->regfile_wr_idx); - rc = -EINVAL; - goto error; + 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))) + return rc; /* no need to perform mark action process */ + + /* Get the mark id details from action property */ + memcpy(&mark, &parms->act_prop->act_details[BNXT_ULP_ACT_PROP_IDX_MARK], + sizeof(mark)); + mark = tfp_be_to_cpu_32(mark); + + 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; } - - /* - * The set_tbl_entry API if search is not enabled or searched entry - * is not found. - */ - if (!atbls->srch_b4_alloc || !alloc_parms.hit) { - struct tf_set_tbl_entry_parms set_parm = { 0 }; - uint16_t length; - - set_parm.dir = atbls->direction; - set_parm.type = atbls->resource_type; - set_parm.idx = alloc_parms.idx; - set_parm.data = ulp_blob_data_get(blob, &length); - set_parm.data_sz_in_bytes = length / 8; - - if (set_parm.type == TF_TBL_TYPE_EXT) - set_parm.tbl_scope_id = tbl_scope_id; - - /* set the table entry */ - rc = tf_set_tbl_entry(parms->tfp, &set_parm); - if (rc) { - BNXT_TF_DBG(ERR, "table[%d][%s][%d] set failed\n", - set_parm.type, - (set_parm.dir == TF_DIR_RX) ? "RX" : "TX", - set_parm.idx); - goto error; - } + act_idx = tfp_be_to_cpu_64(val64); + mark_flag = BNXT_ULP_MARK_LOCAL_HW_FID; + 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; } - - /* Link the resource to the flow in the flow db */ - memset(&fid_parms, 0, sizeof(fid_parms)); - fid_parms.direction = atbls->direction; - fid_parms.resource_func = atbls->resource_func; - fid_parms.resource_type = atbls->resource_type; - fid_parms.resource_hndl = alloc_parms.idx; - fid_parms.critical_resource = 0; - + 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, "Failed to link resource to flow rc = %d\n", - rc); - rc = -EINVAL; - goto error; - } - - return 0; -error: - - free_parms.dir = alloc_parms.dir; - free_parms.type = alloc_parms.type; - free_parms.idx = alloc_parms.idx; - - trc = tf_free_tbl_entry(parms->tfp, &free_parms); - if (trc) - BNXT_TF_DBG(ERR, "Failed to free table entry on failure\n"); - + if (rc) + BNXT_TF_DBG(ERR, "Fail to link res to flow rc = %d\n", rc); return rc; } -/* - * Function to process the action Info. Iterate through the list - * action info templates and process it. - */ static int32_t -ulp_mapper_action_info_process(struct bnxt_ulp_mapper_parms *parms, - struct bnxt_ulp_mapper_act_tbl_info *tbl) +ulp_mapper_mark_vfr_idx_process(struct bnxt_ulp_mapper_parms *parms, + struct bnxt_ulp_mapper_tbl_info *tbl) { - struct ulp_blob blob; - struct bnxt_ulp_mapper_result_field_info *flds, *fld; - uint32_t num_flds = 0; - uint32_t encap_flds = 0; - uint32_t i; - int32_t rc; - uint16_t bit_size; - - if (!tbl || !parms->act_prop || !parms->act_bitmap || !parms->regfile) - return -EINVAL; + 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; - /* use the max size if encap is enabled */ - if (tbl->encap_num_fields) - bit_size = BNXT_ULP_FLMP_BLOB_SIZE_IN_BITS; - else - bit_size = tbl->result_bit_size; - if (!ulp_blob_init(&blob, bit_size, parms->order)) { - BNXT_TF_DBG(ERR, "action blob init failed\n"); - return -EINVAL; - } + 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 */ - flds = ulp_mapper_act_result_fields_get(tbl, &num_flds, &encap_flds); - if (!flds || !num_flds) { - BNXT_TF_DBG(ERR, "Template undefined for action\n"); + /* 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); - for (i = 0; i < (num_flds + encap_flds); i++) { - fld = &flds[i]; - rc = ulp_mapper_result_field_process(parms, - tbl->direction, - fld, - &blob, - "Action"); - if (rc) { - BNXT_TF_DBG(ERR, "Action field failed\n"); - return rc; - } - /* set the swap index if 64 bit swap is enabled */ - if (parms->encap_byte_swap && encap_flds) { - if ((i + 1) == num_flds) - ulp_blob_encap_swap_idx_set(&blob); - /* if 64 bit swap is enabled perform the 64bit swap */ - if ((i + 1) == (num_flds + encap_flds)) - ulp_blob_perform_encap_swap(&blob); - } - } + /* 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_mapper_action_alloc_and_set(parms, &blob); + 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_class_tbl_info *tbl) + struct bnxt_ulp_mapper_tbl_info *tbl) { struct bnxt_ulp_mapper_class_key_field_info *kflds; struct ulp_blob key, mask, data; @@ -1081,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; } @@ -1226,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; @@ -1278,7 +1279,7 @@ error: static int32_t ulp_mapper_em_tbl_process(struct bnxt_ulp_mapper_parms *parms, - struct bnxt_ulp_mapper_class_tbl_info *tbl) + struct bnxt_ulp_mapper_tbl_info *tbl) { struct bnxt_ulp_mapper_class_key_field_info *kflds; struct bnxt_ulp_mapper_result_field_info *dflds; @@ -1290,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); @@ -1299,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; } @@ -1344,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); @@ -1370,6 +1381,18 @@ ulp_mapper_em_tbl_process(struct bnxt_ulp_mapper_parms *parms, return rc; } + /* Mark action process */ + 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 (mtype == BNXT_ULP_FLOW_MEM_TYPE_INT && + tbl->resource_type == TF_MEM_INTERNAL) + rc = ulp_mapper_mark_act_ptr_process(parms, tbl); + if (rc) { + BNXT_TF_DBG(ERR, "Failed to add mark to flow\n"); + goto error; + } + /* Link the EM resource to the flow in the flow db */ memset(&fid_parms, 0, sizeof(fid_parms)); fid_parms.direction = tbl->direction; @@ -1405,7 +1428,8 @@ error: static int32_t ulp_mapper_index_tbl_process(struct bnxt_ulp_mapper_parms *parms, - struct bnxt_ulp_mapper_class_tbl_info *tbl) + struct bnxt_ulp_mapper_tbl_info *tbl, + bool is_class_tbl) { struct bnxt_ulp_mapper_result_field_info *flds; struct ulp_flow_db_res_params fid_parms; @@ -1419,21 +1443,49 @@ 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 = bnxt_ulp_cntxt_tfp_get(parms->ulp_ctx); + uint16_t bit_size; + uint32_t encap_flds = 0; + + /* Get the scope id first */ + rc = bnxt_ulp_cntxt_tbl_scope_id_get(parms->ulp_ctx, &tbl_scope_id); + if (rc) { + BNXT_TF_DBG(ERR, "Failed to get table scope rc=%d\n", rc); + return rc; + } - bnxt_ulp_cntxt_tbl_scope_id_get(parms->ulp_ctx, &tbl_scope_id); + /* use the max size if encap is enabled */ + if (tbl->encap_num_fields) + bit_size = BNXT_ULP_FLMP_BLOB_SIZE_IN_BITS; + else + bit_size = tbl->result_bit_size; - if (!ulp_blob_init(&data, tbl->result_bit_size, parms->order)) { + /* Initialize the blob data */ + if (!ulp_blob_init(&data, bit_size, + parms->device_params->byte_order)) { BNXT_TF_DBG(ERR, "Failed initial index table blob\n"); return -EINVAL; } - flds = ulp_mapper_result_fields_get(tbl, &num_flds); + /* Get the result fields list */ + if (is_class_tbl) + flds = ulp_mapper_result_fields_get(tbl, &num_flds); + else + flds = ulp_mapper_act_result_fields_get(tbl, &num_flds, + &encap_flds); + if (!flds || !num_flds) { - BNXT_TF_DBG(ERR, "Template undefined for action\n"); + BNXT_TF_DBG(ERR, "template undefined for the index table\n"); return -EINVAL; } - for (i = 0; i < num_flds; i++) { + /* process the result fields, loop through them */ + 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)) + ulp_blob_encap_swap_idx_set(&data); + + /* Process the result fields */ rc = ulp_mapper_result_field_process(parms, tbl->direction, &flds[i], @@ -1443,51 +1495,73 @@ 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); +#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); + } +#endif + } } + /* 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_SZ_BITS2BYTES(tbl->result_bit_size); + 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", - tbl->resource_type, - (tbl->direction == TF_DIR_RX) ? "RX" : "TX", + aparms.type, + (aparms.dir == TF_DIR_RX) ? "RX" : "TX", rc); return rc; } + /* + * 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); + else + idx = aparms.idx; + /* Always storing values in Regfile in BE */ - idx = tfp_cpu_to_be_64(aparms.idx); - rc = ulp_regfile_write(parms->regfile, tbl->regfile_wr_idx, idx); + idx = tfp_cpu_to_be_64(idx); + rc = ulp_regfile_write(parms->regfile, tbl->regfile_idx, idx); if (!rc) { BNXT_TF_DBG(ERR, "Write regfile[%d] failed\n", - tbl->regfile_wr_idx); + tbl->regfile_idx); goto error; } - if (!tbl->srch_b4_alloc) { + /* Perform the tf table set by filling the set params */ + if (!tbl->srch_b4_alloc || !aparms.hit) { sparms.dir = tbl->direction; sparms.type = tbl->resource_type; sparms.data = ulp_blob_data_get(&data, &tmplen); - sparms.data_sz_in_bytes = - ULP_SZ_BITS2BYTES(tbl->result_bit_size); + sparms.data_sz_in_bytes = ULP_BITS_2_BYTE(tmplen); sparms.idx = aparms.idx; sparms.tbl_scope_id = tbl_scope_id; rc = tf_set_tbl_entry(tfp, &sparms); if (rc) { BNXT_TF_DBG(ERR, "Set table[%d][%s][%d] failed rc=%d\n", - tbl->resource_type, - (tbl->direction == TF_DIR_RX) ? "RX" : "TX", + sparms.type, + (sparms.dir == TF_DIR_RX) ? "RX" : "TX", sparms.idx, rc); - goto error; } } @@ -1498,7 +1572,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_hndl = aparms.idx; - fid_parms.critical_resource = 0; + fid_parms.critical_resource = BNXT_ULP_CRITICAL_RESOURCE_NO; rc = ulp_flow_db_resource_add(parms->ulp_ctx, parms->tbl_idx, @@ -1510,6 +1584,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: /* @@ -1530,7 +1610,7 @@ error: static int32_t ulp_mapper_cache_tbl_process(struct bnxt_ulp_mapper_parms *parms, - struct bnxt_ulp_mapper_class_tbl_info *tbl) + struct bnxt_ulp_mapper_tbl_info *tbl) { struct bnxt_ulp_mapper_class_key_field_info *kflds; struct bnxt_ulp_mapper_cache_entry *cache_entry; @@ -1551,7 +1631,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; } @@ -1575,8 +1656,15 @@ ulp_mapper_cache_tbl_process(struct bnxt_ulp_mapper_parms *parms, */ cache_key = ulp_blob_data_get(&key, &tmplen); ckey = (uint16_t *)cache_key; + + /* + * The id computed based on resource sub type and direction where + * dir is the bit0 and rest of the bits come from resource + * sub type. + */ cache_entry = ulp_mapper_cache_entry_get(parms->ulp_ctx, - tbl->cache_tbl_id, + (tbl->resource_sub_type << 1 | + (tbl->direction & 0x1)), *ckey); /* @@ -1617,7 +1705,7 @@ ulp_mapper_cache_tbl_process(struct bnxt_ulp_mapper_parms *parms, for (i = 0; i < num_idents; i++) { regval = (uint64_t)cache_entry->idents[i]; if (!ulp_regfile_write(parms->regfile, - idents[i].regfile_wr_idx, + idents[i].regfile_idx, tfp_cpu_to_be_64(regval))) { BNXT_TF_DBG(ERR, "Failed to write to regfile\n"); @@ -1640,12 +1728,13 @@ ulp_mapper_cache_tbl_process(struct bnxt_ulp_mapper_parms *parms, fid_parms.resource_func = tbl->resource_func; /* - * Cache resource type is composed of both table_type and cache_tbl_id - * need to set it appropriately via setter. + * Cache resource type is composed of table_type, resource + * sub type and direction, it needs to set appropriately via setter. */ ulp_mapper_cache_res_type_set(&fid_parms, tbl->resource_type, - tbl->cache_tbl_id); + (tbl->resource_sub_type << 1 | + (tbl->direction & 0x1))); fid_parms.resource_hndl = (uint64_t)*ckey; fid_parms.critical_resource = tbl->critical_resource; rc = ulp_flow_db_resource_add(parms->ulp_ctx, @@ -1715,6 +1804,7 @@ ulp_mapper_action_tbls_process(struct bnxt_ulp_mapper_parms *parms) { uint32_t i; int32_t rc = 0; + struct bnxt_ulp_mapper_tbl_info *tbl; if (!parms->atbls || !parms->num_atbls) { BNXT_TF_DBG(ERR, "No action tables for template[%d][%d].\n", @@ -1723,9 +1813,21 @@ ulp_mapper_action_tbls_process(struct bnxt_ulp_mapper_parms *parms) } for (i = 0; i < parms->num_atbls; i++) { - rc = ulp_mapper_action_info_process(parms, &parms->atbls[i]); - if (rc) - return rc; + tbl = &parms->atbls[i]; + switch (tbl->resource_func) { + case BNXT_ULP_RESOURCE_FUNC_INDEX_TABLE: + rc = ulp_mapper_index_tbl_process(parms, tbl, false); + break; + default: + BNXT_TF_DBG(ERR, "Unexpected action resource %d\n", + tbl->resource_func); + return -EINVAL; + } + } + if (rc) { + BNXT_TF_DBG(ERR, "Resource type %d failed\n", + tbl->resource_func); + return rc; } return rc; @@ -1748,7 +1850,7 @@ ulp_mapper_class_tbls_process(struct bnxt_ulp_mapper_parms *parms) } for (i = 0; i < parms->num_ctbls; i++) { - struct bnxt_ulp_mapper_class_tbl_info *tbl = &parms->ctbls[i]; + struct bnxt_ulp_mapper_tbl_info *tbl = &parms->ctbls[i]; switch (tbl->resource_func) { case BNXT_ULP_RESOURCE_FUNC_TCAM_TABLE: @@ -1758,7 +1860,7 @@ ulp_mapper_class_tbls_process(struct bnxt_ulp_mapper_parms *parms) rc = ulp_mapper_em_tbl_process(parms, tbl); break; case BNXT_ULP_RESOURCE_FUNC_INDEX_TABLE: - rc = ulp_mapper_index_tbl_process(parms, tbl); + rc = ulp_mapper_index_tbl_process(parms, tbl, true); break; case BNXT_ULP_RESOURCE_FUNC_CACHE_TABLE: rc = ulp_mapper_cache_tbl_process(parms, tbl); @@ -1840,7 +1942,7 @@ ulp_mapper_resources_free(struct bnxt_ulp_context *ulp_ctx, * Set the critical resource on the first resource del, then iterate * while status is good */ - res_parms.critical_resource = 1; + res_parms.critical_resource = BNXT_ULP_CRITICAL_RESOURCE_YES; rc = ulp_flow_db_resource_del(ulp_ctx, tbl_type, fid, &res_parms); if (rc) { @@ -1866,8 +1968,8 @@ ulp_mapper_resources_free(struct bnxt_ulp_context *ulp_ctx, tbl_type, fid, res_parms.resource_func, res_parms.resource_hndl, trc); - /* All subsequent call require the critical_resource be zero */ - res_parms.critical_resource = 0; + /* 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, @@ -1928,7 +2030,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; @@ -1986,15 +2087,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)) {