#include "tf_util.h"
#include "ulp_template_db_tbl.h"
#include "ulp_port_db.h"
+#include "ulp_ha_mgr.h"
+#include "bnxt_tf_pmd_shim.h"
+
+static uint8_t mapper_fld_zeros[16] = { 0 };
static uint8_t mapper_fld_ones[16] = {
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF
};
+static uint8_t mapper_fld_one[16] = {
+ 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
+ 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01
+};
+
static const char *
ulp_mapper_tmpl_name_str(enum bnxt_ulp_template_type tmpl_type)
{
ulp_mapper_glb_resource_read(struct bnxt_ulp_mapper_data *mapper_data,
enum tf_dir dir,
uint16_t idx,
- uint64_t *regval)
+ uint64_t *regval,
+ bool *shared)
{
- if (!mapper_data || !regval ||
+ if (!mapper_data || !regval || !shared ||
dir >= TF_DIR_MAX || idx >= BNXT_ULP_GLB_RF_IDX_LAST)
return -EINVAL;
*regval = mapper_data->glb_res_tbl[dir][idx].resource_hndl;
+ *shared = mapper_data->glb_res_tbl[dir][idx].shared;
return 0;
}
static int32_t
ulp_mapper_glb_resource_write(struct bnxt_ulp_mapper_data *data,
struct bnxt_ulp_glb_resource_info *res,
- uint64_t regval)
+ uint64_t regval, bool shared)
{
struct bnxt_ulp_mapper_glb_resource_entry *ent;
ent->resource_func = res->resource_func;
ent->resource_type = res->resource_type;
ent->resource_hndl = regval;
+ ent->shared = shared;
return 0;
}
struct tf *tfp;
int32_t rc = 0;
- tfp = bnxt_ulp_cntxt_tfp_get(ulp_ctx);
+ tfp = bnxt_ulp_cntxt_tfp_get(ulp_ctx, BNXT_ULP_SHARED_SESSION_NO);
if (!tfp)
return -EINVAL;
/* entries are stored as big-endian format */
regval = tfp_cpu_to_be_64((uint64_t)iparms.id);
- /* write to the mapper global resource */
- rc = ulp_mapper_glb_resource_write(mapper_data, glb_res, regval);
+ /*
+ * write to the mapper global resource
+ * Shared resources are never allocated through this method, so the
+ * shared flag is always false.
+ */
+ rc = ulp_mapper_glb_resource_write(mapper_data, glb_res, regval, false);
if (rc) {
BNXT_TF_DBG(ERR, "Failed to write to global resource id\n");
/* Free the identifier when update failed */
uint32_t tbl_scope_id;
int32_t rc = 0;
- tfp = bnxt_ulp_cntxt_tfp_get(ulp_ctx);
+ tfp = bnxt_ulp_cntxt_tfp_get(ulp_ctx, BNXT_ULP_SHARED_SESSION_NO);
if (!tfp)
return -EINVAL;
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;
}
/* entries are stored as big-endian format */
regval = tfp_cpu_to_be_64((uint64_t)aparms.idx);
- /* write to the mapper global resource */
- rc = ulp_mapper_glb_resource_write(mapper_data, glb_res, regval);
+ /*
+ * write to the mapper global resource
+ * Shared resources are never allocated through this method, so the
+ * shared flag is always false.
+ */
+ rc = ulp_mapper_glb_resource_write(mapper_data, glb_res, regval, false);
if (rc) {
BNXT_TF_DBG(ERR, "Failed to write to global resource id\n");
/* Free the identifier when update failed */
{
uint32_t t_idx;
- t_idx = parms->class_tid << (BNXT_ULP_HDR_SIG_ID_SHIFT +
- BNXT_ULP_GLB_FIELD_TBL_SHIFT);
+ t_idx = parms->app_id << (BNXT_ULP_APP_ID_SHIFT +
+ BNXT_ULP_HDR_SIG_ID_SHIFT +
+ BNXT_ULP_GLB_FIELD_TBL_SHIFT);
+ t_idx += parms->class_tid << (BNXT_ULP_HDR_SIG_ID_SHIFT +
+ BNXT_ULP_GLB_FIELD_TBL_SHIFT);
t_idx += ULP_COMP_FLD_IDX_RD(parms, BNXT_ULP_CF_IDX_HDR_SIG_ID) <<
BNXT_ULP_GLB_FIELD_TBL_SHIFT;
t_idx += operand;
return &dev_tbls->ident_list[idx];
}
+static enum tf_tbl_type
+ulp_mapper_dyn_tbl_type_get(struct bnxt_ulp_mapper_parms *mparms,
+ struct bnxt_ulp_mapper_tbl_info *tbl,
+ struct ulp_blob *bdata,
+ uint16_t *out_len)
+{
+ struct bnxt_ulp_device_params *d_params = mparms->device_params;
+ uint16_t blob_len = ulp_blob_data_len_get(bdata);
+ struct bnxt_ulp_dyn_size_map *size_map;
+ uint32_t i;
+
+ if (d_params->dynamic_sram_en) {
+ switch (tbl->resource_type) {
+ case TF_TBL_TYPE_ACT_ENCAP_8B:
+ case TF_TBL_TYPE_ACT_ENCAP_16B:
+ case TF_TBL_TYPE_ACT_ENCAP_32B:
+ case TF_TBL_TYPE_ACT_ENCAP_64B:
+ size_map = d_params->dyn_encap_sizes;
+ for (i = 0; i < d_params->dyn_encap_list_size; i++) {
+ if (blob_len <= size_map[i].slab_size) {
+ *out_len = size_map[i].slab_size;
+ return size_map[i].tbl_type;
+ }
+ }
+ break;
+ case TF_TBL_TYPE_ACT_MODIFY_8B:
+ case TF_TBL_TYPE_ACT_MODIFY_16B:
+ case TF_TBL_TYPE_ACT_MODIFY_32B:
+ case TF_TBL_TYPE_ACT_MODIFY_64B:
+ size_map = d_params->dyn_modify_sizes;
+ for (i = 0; i < d_params->dyn_modify_list_size; i++) {
+ if (blob_len <= size_map[i].slab_size) {
+ *out_len = size_map[i].slab_size;
+ return size_map[i].tbl_type;
+ }
+ }
+ break;
+ default:
+ break;
+ }
+ }
+ return tbl->resource_type;
+}
+
+static uint16_t
+ulp_mapper_dyn_blob_size_get(struct bnxt_ulp_mapper_parms *mparms,
+ struct bnxt_ulp_mapper_tbl_info *tbl)
+{
+ struct bnxt_ulp_device_params *d_params = mparms->device_params;
+
+ if (d_params->dynamic_sram_en) {
+ switch (tbl->resource_type) {
+ case TF_TBL_TYPE_ACT_ENCAP_8B:
+ case TF_TBL_TYPE_ACT_ENCAP_16B:
+ case TF_TBL_TYPE_ACT_ENCAP_32B:
+ case TF_TBL_TYPE_ACT_ENCAP_64B:
+ case TF_TBL_TYPE_ACT_MODIFY_8B:
+ case TF_TBL_TYPE_ACT_MODIFY_16B:
+ case TF_TBL_TYPE_ACT_MODIFY_32B:
+ case TF_TBL_TYPE_ACT_MODIFY_64B:
+ /* return max size */
+ return BNXT_ULP_FLMP_BLOB_SIZE_IN_BITS;
+ default:
+ break;
+ }
+ } else if (tbl->encap_num_fields) {
+ return BNXT_ULP_FLMP_BLOB_SIZE_IN_BITS;
+ }
+ return tbl->result_bit_size;
+}
+
static inline int32_t
-ulp_mapper_tcam_entry_free(struct bnxt_ulp_context *ulp __rte_unused,
+ulp_mapper_tcam_entry_free(struct bnxt_ulp_context *ulp,
struct tf *tfp,
struct ulp_flow_db_res_params *res)
{
.idx = (uint16_t)res->resource_hndl
};
+ /* If HA is enabled, we may have to remap the TF Type */
+ if (bnxt_ulp_cntxt_ha_enabled(ulp)) {
+ enum ulp_ha_mgr_region region;
+ int32_t rc;
+
+ switch (res->resource_type) {
+ case TF_TCAM_TBL_TYPE_WC_TCAM_HIGH:
+ case TF_TCAM_TBL_TYPE_WC_TCAM_LOW:
+ rc = ulp_ha_mgr_region_get(ulp, ®ion);
+ if (rc)
+ /* Log this, but assume region is correct */
+ BNXT_TF_DBG(ERR,
+ "Unable to get HA region (%d)\n",
+ rc);
+ else
+ fparms.tcam_tbl_type =
+ (region == ULP_HA_REGION_LOW) ?
+ TF_TCAM_TBL_TYPE_WC_TCAM_LOW :
+ TF_TCAM_TBL_TYPE_WC_TCAM_HIGH;
+ break;
+ default:
+ break;
+ }
+ }
return tf_free_tcam_entry(tfp, &fparms);
}
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;
+ uint32_t pc_idx;
- /* 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;
- }
- }
+ 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;
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;
struct tf *tfp;
int rc;
- tfp = bnxt_ulp_cntxt_tfp_get(parms->ulp_ctx);
+ tfp = bnxt_ulp_cntxt_tfp_get(parms->ulp_ctx, tbl->shared_session);
if (!tfp) {
BNXT_TF_DBG(ERR, "Failed to get tf pointer\n");
return -EINVAL;
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)) {
fid_parms.resource_type = ident->ident_type;
fid_parms.resource_hndl = iparms.id;
fid_parms.critical_resource = tbl->critical_resource;
+ ulp_flow_db_shared_session_set(&fid_parms, tbl->shared_session);
rc = ulp_mapper_fdb_opc_process(parms, tbl, &fid_parms);
if (rc) {
int rc;
/* Get the tfp from ulp context */
- tfp = bnxt_ulp_cntxt_tfp_get(parms->ulp_ctx);
+ tfp = bnxt_ulp_cntxt_tfp_get(parms->ulp_ctx, tbl->shared_session);
if (!tfp) {
BNXT_TF_DBG(ERR, "Failed to get tf pointer\n");
return -EINVAL;
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);
fid_parms.resource_type = ident->ident_type;
fid_parms.resource_hndl = sparms.search_id;
fid_parms.critical_resource = tbl->critical_resource;
+ ulp_flow_db_shared_session_set(&fid_parms, tbl->shared_session);
+
rc = ulp_mapper_fdb_opc_process(parms, tbl, &fid_parms);
if (rc) {
BNXT_TF_DBG(ERR, "Failed to link res to flow rc = %d\n",
static int32_t
ulp_mapper_field_port_db_process(struct bnxt_ulp_mapper_parms *parms,
- struct bnxt_ulp_mapper_field_info *fld,
uint32_t port_id,
uint16_t val16,
uint8_t **val)
}
break;
default:
- BNXT_TF_DBG(ERR, "Invalid port_data %s\n", fld->description);
+ BNXT_TF_DBG(ERR, "Invalid port_data %d\n", port_data);
return -EINVAL;
}
return 0;
}
static int32_t
-ulp_mapper_field_process_inc_dec(struct bnxt_ulp_mapper_field_info *fld,
- struct ulp_blob *blob,
- uint64_t *val64,
- uint16_t const_val16,
- uint32_t bitlen,
- uint32_t *update_flag)
-{
- uint64_t l_val64 = *val64;
-
- if (fld->field_opc == BNXT_ULP_FIELD_OPC_SRC1_PLUS_CONST ||
- fld->field_opc == BNXT_ULP_FIELD_OPC_SRC1_PLUS_CONST_POST) {
- l_val64 += const_val16;
- l_val64 = tfp_be_to_cpu_64(l_val64);
- ulp_blob_push_64(blob, &l_val64, bitlen);
- } else if (fld->field_opc == BNXT_ULP_FIELD_OPC_SRC1_MINUS_CONST ||
- fld->field_opc == BNXT_ULP_FIELD_OPC_SRC1_MINUS_CONST_POST) {
- l_val64 -= const_val16;
- l_val64 = tfp_be_to_cpu_64(l_val64);
- ulp_blob_push_64(blob, &l_val64, bitlen);
- } else {
- BNXT_TF_DBG(ERR, "Invalid field opcode %u\n", fld->field_opc);
- return -EINVAL;
- }
-
- if (fld->field_opc == BNXT_ULP_FIELD_OPC_SRC1_MINUS_CONST_POST ||
- fld->field_opc == BNXT_ULP_FIELD_OPC_SRC1_PLUS_CONST_POST) {
- *val64 = l_val64;
- *update_flag = 1;
- }
- return 0;
-}
-
-static int32_t
-ulp_mapper_field_process(struct bnxt_ulp_mapper_parms *parms,
- enum tf_dir dir,
- struct bnxt_ulp_mapper_field_info *fld,
- struct ulp_blob *blob,
- uint8_t is_key,
- const char *name)
-{
- uint32_t val_size = 0, field_size = 0;
- uint64_t hdr_bit, act_bit, regval;
- uint16_t write_idx = blob->write_idx;
- uint16_t idx, size_idx, bitlen, offset;
- uint8_t *val = NULL;
- uint8_t tmpval[16];
+ulp_mapper_field_src_process(struct bnxt_ulp_mapper_parms *parms,
+ enum bnxt_ulp_field_src field_src,
+ uint8_t *field_opr,
+ enum tf_dir dir,
+ uint8_t is_key,
+ uint32_t bitlen,
+ uint8_t **val,
+ uint32_t *val_len,
+ uint64_t *value)
+{
+ struct bnxt_ulp_mapper_data *m;
uint8_t bit;
- uint32_t src1_sel = 0;
- enum bnxt_ulp_field_src fld_src;
- uint8_t *fld_src_oper;
- enum bnxt_ulp_field_cond_src field_cond_src;
- uint16_t const_val = 0;
- uint32_t update_flag = 0;
- uint64_t src1_val64;
- uint32_t port_id;
-
- /* process the field opcode */
- if (fld->field_opc != BNXT_ULP_FIELD_OPC_COND_OP) {
- field_cond_src = BNXT_ULP_FIELD_COND_SRC_TRUE;
- /* Read the constant from the second operand */
- memcpy(&const_val, fld->field_opr2, sizeof(uint16_t));
- const_val = tfp_be_to_cpu_16(const_val);
- } else {
- field_cond_src = fld->field_cond_src;
- }
-
- bitlen = fld->field_bit_size;
- /* Evaluate the condition */
- switch (field_cond_src) {
- case BNXT_ULP_FIELD_COND_SRC_TRUE:
- src1_sel = 1;
- break;
- case BNXT_ULP_FIELD_COND_SRC_CF:
- if (!ulp_operand_read(fld->field_cond_opr,
- (uint8_t *)&idx, sizeof(uint16_t))) {
- BNXT_TF_DBG(ERR, "%s 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))
- src1_sel = 1;
- break;
- case BNXT_ULP_FIELD_COND_SRC_RF:
- if (!ulp_operand_read(fld->field_cond_opr,
- (uint8_t *)&idx, sizeof(uint16_t))) {
- BNXT_TF_DBG(ERR, "%s operand read failed\n", name);
- return -EINVAL;
- }
-
- idx = tfp_be_to_cpu_16(idx);
- /* Uninitialized regfile entries return 0 */
- if (!ulp_regfile_read(parms->regfile, idx, ®val)) {
- BNXT_TF_DBG(ERR, "%s regfile[%d] read oob\n",
- name, idx);
- return -EINVAL;
- }
- if (regval)
- src1_sel = 1;
- break;
- case BNXT_ULP_FIELD_COND_SRC_ACT_BIT:
- if (!ulp_operand_read(fld->field_cond_opr,
- (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);
- if (ULP_BITMAP_ISSET(parms->act_bitmap->bits, act_bit))
- src1_sel = 1;
- break;
- case BNXT_ULP_FIELD_COND_SRC_HDR_BIT:
- if (!ulp_operand_read(fld->field_cond_opr,
- (uint8_t *)&hdr_bit, sizeof(uint64_t))) {
- BNXT_TF_DBG(ERR, "%s operand read failed\n", name);
- return -EINVAL;
- }
- hdr_bit = tfp_be_to_cpu_64(hdr_bit);
- if (ULP_BITMAP_ISSET(parms->hdr_bitmap->bits, hdr_bit))
- src1_sel = 1;
- break;
- case BNXT_ULP_FIELD_COND_SRC_FIELD_BIT:
- if (!ulp_operand_read(fld->field_cond_opr, (uint8_t *)&idx,
- sizeof(uint16_t))) {
- BNXT_TF_DBG(ERR, "%s operand read failed.\n", name);
- return -EINVAL;
- }
- idx = tfp_be_to_cpu_16(idx);
- /* get the index from the global field list */
- if (ulp_mapper_glb_field_tbl_get(parms, idx, &bit)) {
- BNXT_TF_DBG(ERR, "invalid ulp_glb_field_tbl idx %d\n",
- idx);
- return -EINVAL;
- }
- if (bit && (ULP_INDEX_BITMAP_GET(parms->fld_bitmap->bits, bit)))
- src1_sel = 1;
- break;
- default:
- BNXT_TF_DBG(ERR, "%s invalid field opcode 0x%x at %d\n",
- name, fld->field_cond_src, write_idx);
- return -EINVAL;
- }
-
- /* pick the selected source */
- if (src1_sel) {
- fld_src = fld->field_src1;
- fld_src_oper = fld->field_opr1;
- } else {
- fld_src = fld->field_src2;
- fld_src_oper = fld->field_opr2;
- }
-
+ uint32_t port_id, val_size, field_size;
+ uint16_t idx, size_idx, offset;
+ uint32_t bytelen = ULP_BITS_2_BYTE(bitlen);
+ uint8_t *buffer;
+ uint64_t lregval;
+ bool shared;
+
+ *val_len = bitlen;
+ *value = 0;
/* Perform the action */
- switch (fld_src) {
+ switch (field_src) {
case BNXT_ULP_FIELD_SRC_ZERO:
- if (ulp_blob_pad_push(blob, bitlen) < 0) {
- BNXT_TF_DBG(ERR, "%s too large for blob\n", name);
- return -EINVAL;
- }
+ *val = mapper_fld_zeros;
break;
case BNXT_ULP_FIELD_SRC_CONST:
- val = fld_src_oper;
- if (!ulp_blob_push(blob, val, bitlen)) {
- BNXT_TF_DBG(ERR, "%s push to blob failed\n", name);
- return -EINVAL;
- }
+ *val = field_opr;
break;
case BNXT_ULP_FIELD_SRC_ONES:
- val = mapper_fld_ones;
- if (!ulp_blob_push(blob, val, bitlen)) {
- BNXT_TF_DBG(ERR, "%s too large for blob\n", name);
- return -EINVAL;
- }
+ *val = mapper_fld_ones;
+ *value = 1;
break;
case BNXT_ULP_FIELD_SRC_CF:
- if (!ulp_operand_read(fld_src_oper,
+ if (!ulp_operand_read(field_opr,
(uint8_t *)&idx, sizeof(uint16_t))) {
- BNXT_TF_DBG(ERR, "%s operand read failed.\n",
- name);
+ BNXT_TF_DBG(ERR, "CF operand read failed\n");
return -EINVAL;
}
idx = tfp_be_to_cpu_16(idx);
- if (idx >= BNXT_ULP_CF_IDX_LAST) {
- BNXT_TF_DBG(ERR, "%s comp field [%d] read oob\n",
- name, idx);
+ if (idx >= BNXT_ULP_CF_IDX_LAST || bytelen > sizeof(uint64_t)) {
+ BNXT_TF_DBG(ERR, "comp field [%d] read oob %d\n", idx,
+ bytelen);
return -EINVAL;
}
- if (fld->field_opc == BNXT_ULP_FIELD_OPC_COND_OP) {
- val = ulp_blob_push_32(blob, &parms->comp_fld[idx],
- bitlen);
- if (!val) {
- BNXT_TF_DBG(ERR, "%s push to blob failed\n",
- name);
- return -EINVAL;
- }
- } else if (fld->field_opc == BNXT_ULP_FIELD_OPC_PORT_TABLE) {
- port_id = ULP_COMP_FLD_IDX_RD(parms, idx);
- if (ulp_mapper_field_port_db_process(parms, fld,
- port_id, const_val,
- &val)) {
- BNXT_TF_DBG(ERR, "%s field port table failed\n",
- name);
- return -EINVAL;
- }
- if (!ulp_blob_push(blob, val, bitlen)) {
- BNXT_TF_DBG(ERR, "%s push to blob failed\n",
- name);
- return -EINVAL;
- }
- } else {
- src1_val64 = ULP_COMP_FLD_IDX_RD(parms, idx);
- if (ulp_mapper_field_process_inc_dec(fld, blob,
- &src1_val64,
- const_val,
- bitlen,
- &update_flag)) {
- BNXT_TF_DBG(ERR, "%s field cond opc failed\n",
- name);
- return -EINVAL;
- }
- if (update_flag) {
- BNXT_TF_DBG(ERR, "%s invalid field cond opc\n",
- name);
- return -EINVAL;
- }
- }
+ buffer = (uint8_t *)&parms->comp_fld[idx];
+ *val = &buffer[sizeof(uint64_t) - bytelen];
+ *value = ULP_COMP_FLD_IDX_RD(parms, idx);
break;
case BNXT_ULP_FIELD_SRC_RF:
- if (!ulp_operand_read(fld_src_oper,
+ if (!ulp_operand_read(field_opr,
(uint8_t *)&idx, sizeof(uint16_t))) {
- BNXT_TF_DBG(ERR, "%s operand read failed\n", name);
+ BNXT_TF_DBG(ERR, "RF operand read failed\n");
return -EINVAL;
}
idx = tfp_be_to_cpu_16(idx);
/* Uninitialized regfile entries return 0 */
- if (!ulp_regfile_read(parms->regfile, idx, ®val)) {
- BNXT_TF_DBG(ERR, "%s regfile[%d] read oob\n",
- name, idx);
+ if (!ulp_regfile_read(parms->regfile, idx, &lregval) ||
+ sizeof(uint64_t) < bytelen) {
+ BNXT_TF_DBG(ERR, "regfile[%d] read oob %u\n", idx,
+ bytelen);
return -EINVAL;
}
- if (fld->field_opc == BNXT_ULP_FIELD_OPC_COND_OP) {
- val = ulp_blob_push_64(blob, ®val, bitlen);
- if (!val) {
- BNXT_TF_DBG(ERR, "%s push to blob failed\n",
- name);
- return -EINVAL;
- }
- } else {
- if (ulp_mapper_field_process_inc_dec(fld, blob,
- ®val,
- const_val,
- bitlen,
- &update_flag)) {
- BNXT_TF_DBG(ERR, "%s field cond opc failed\n",
- name);
- return -EINVAL;
- }
- if (update_flag) {
- regval = tfp_cpu_to_be_64(regval);
- if (ulp_regfile_write(parms->regfile, idx,
- regval)) {
- BNXT_TF_DBG(ERR,
- "Write regfile[%d] fail\n",
- idx);
- return -EINVAL;
- }
- }
- }
+ buffer = (uint8_t *)&parms->regfile->entry[idx].data;
+ *val = &buffer[sizeof(uint64_t) - bytelen];
+ *value = tfp_be_to_cpu_64(lregval);
break;
case BNXT_ULP_FIELD_SRC_ACT_PROP:
- if (!ulp_operand_read(fld_src_oper,
+ if (!ulp_operand_read(field_opr,
(uint8_t *)&idx, sizeof(uint16_t))) {
- BNXT_TF_DBG(ERR, "%s operand read failed\n", name);
+ BNXT_TF_DBG(ERR, "Action operand read failed\n");
return -EINVAL;
}
idx = tfp_be_to_cpu_16(idx);
-
if (idx >= BNXT_ULP_ACT_PROP_IDX_LAST) {
- BNXT_TF_DBG(ERR, "%s act_prop[%d] oob\n", name, idx);
+ BNXT_TF_DBG(ERR, "act_prop[%d] oob\n", idx);
return -EINVAL;
}
- val = &parms->act_prop->act_details[idx];
+ buffer = &parms->act_prop->act_details[idx];
field_size = ulp_mapper_act_prop_size_get(idx);
- if (bitlen < ULP_BYTE_2_BITS(field_size)) {
- field_size = field_size - ((bitlen + 7) / 8);
- val += field_size;
- }
- if (!ulp_blob_push(blob, val, bitlen)) {
- BNXT_TF_DBG(ERR, "%s push to blob failed\n", name);
+ if (bytelen > field_size) {
+ BNXT_TF_DBG(ERR, "act_prop[%d] field size small %u\n",
+ idx, field_size);
return -EINVAL;
}
+ *val = &buffer[field_size - bytelen];
break;
case BNXT_ULP_FIELD_SRC_ACT_PROP_SZ:
- if (!ulp_operand_read(fld_src_oper,
+ if (!ulp_operand_read(field_opr,
(uint8_t *)&idx, sizeof(uint16_t))) {
- BNXT_TF_DBG(ERR, "%s operand read failed\n", name);
+ BNXT_TF_DBG(ERR, "Action sz operand read failed\n");
return -EINVAL;
}
idx = tfp_be_to_cpu_16(idx);
if (idx >= BNXT_ULP_ACT_PROP_IDX_LAST) {
- BNXT_TF_DBG(ERR, "%s act_prop[%d] oob\n", name, idx);
+ BNXT_TF_DBG(ERR, "act_prop_sz[%d] oob\n", idx);
return -EINVAL;
}
- val = &parms->act_prop->act_details[idx];
+ *val = &parms->act_prop->act_details[idx];
/* get the size index next */
- if (!ulp_operand_read(&fld_src_oper[sizeof(uint16_t)],
+ if (!ulp_operand_read(&field_opr[sizeof(uint16_t)],
(uint8_t *)&size_idx, sizeof(uint16_t))) {
- BNXT_TF_DBG(ERR, "%s operand read failed\n", name);
+ BNXT_TF_DBG(ERR, "Action sz operand read failed\n");
return -EINVAL;
}
size_idx = tfp_be_to_cpu_16(size_idx);
-
if (size_idx >= BNXT_ULP_ACT_PROP_IDX_LAST) {
BNXT_TF_DBG(ERR, "act_prop[%d] oob\n", size_idx);
return -EINVAL;
memcpy(&val_size, &parms->act_prop->act_details[size_idx],
sizeof(uint32_t));
val_size = tfp_be_to_cpu_32(val_size);
- val_size = ULP_BYTE_2_BITS(val_size);
- ulp_blob_push_encap(blob, val, val_size);
+ *val_len = ULP_BYTE_2_BITS(val_size);
break;
case BNXT_ULP_FIELD_SRC_GLB_RF:
- if (!ulp_operand_read(fld_src_oper,
- (uint8_t *)&idx,
- sizeof(uint16_t))) {
- BNXT_TF_DBG(ERR, "%s operand read failed.\n", name);
+ if (!ulp_operand_read(field_opr,
+ (uint8_t *)&idx, sizeof(uint16_t))) {
+ BNXT_TF_DBG(ERR, "Global regfile read failed\n");
return -EINVAL;
}
idx = tfp_be_to_cpu_16(idx);
if (ulp_mapper_glb_resource_read(parms->mapper_data,
- dir,
- idx, ®val)) {
- BNXT_TF_DBG(ERR, "%s global regfile[%d] read failed.\n",
- name, idx);
+ dir, idx, &lregval, &shared) ||
+ sizeof(uint64_t) < bytelen) {
+ BNXT_TF_DBG(ERR, "Global regfile[%d] read failed %u\n",
+ idx, bytelen);
return -EINVAL;
}
- if (fld->field_opc == BNXT_ULP_FIELD_OPC_COND_OP) {
- val = ulp_blob_push_64(blob, ®val, bitlen);
- if (!val) {
- BNXT_TF_DBG(ERR, "%s push to blob failed\n",
- name);
- return -EINVAL;
- }
- } else {
- if (ulp_mapper_field_process_inc_dec(fld, blob,
- ®val,
- const_val,
- bitlen,
- &update_flag)) {
- BNXT_TF_DBG(ERR, "%s field cond opc failed\n",
- name);
- return -EINVAL;
- }
- if (update_flag) {
- BNXT_TF_DBG(ERR, "%s invalid field cond opc\n",
- name);
- return -EINVAL;
- }
- }
+ m = parms->mapper_data;
+ buffer = (uint8_t *)&m->glb_res_tbl[dir][idx].resource_hndl;
+ *val = &buffer[sizeof(uint64_t) - bytelen];
+ *value = tfp_be_to_cpu_64(lregval);
break;
case BNXT_ULP_FIELD_SRC_HF:
- if (!ulp_operand_read(fld_src_oper, (uint8_t *)&idx,
- sizeof(uint16_t))) {
- BNXT_TF_DBG(ERR, "%s operand read failed.\n", name);
+ case BNXT_ULP_FIELD_SRC_SUB_HF:
+ if (!ulp_operand_read(field_opr,
+ (uint8_t *)&idx, sizeof(uint16_t))) {
+ BNXT_TF_DBG(ERR, "Header field read failed\n");
return -EINVAL;
}
idx = tfp_be_to_cpu_16(idx);
return -EINVAL;
}
if (is_key)
- val = parms->hdr_field[bit].spec;
+ buffer = parms->hdr_field[bit].spec;
else
- val = parms->hdr_field[bit].mask;
+ buffer = parms->hdr_field[bit].mask;
- /*
- * Need to account for how much data was pushed to the header
- * field vs how much is to be inserted in the key/mask.
- */
field_size = parms->hdr_field[bit].size;
- if (bitlen < ULP_BYTE_2_BITS(field_size)) {
- field_size = field_size - ((bitlen + 7) / 8);
- val += field_size;
- }
-
- if (!ulp_blob_push(blob, val, bitlen)) {
- BNXT_TF_DBG(ERR, "%s push to blob failed\n", name);
+ if (bytelen > field_size) {
+ BNXT_TF_DBG(ERR, "Hdr field[%d] size small %u\n",
+ bit, field_size);
return -EINVAL;
}
+ if (field_src == BNXT_ULP_FIELD_SRC_HF) {
+ *val = &buffer[field_size - bytelen];
+ } else {
+ /* get the offset next */
+ if (!ulp_operand_read(&field_opr[sizeof(uint16_t)],
+ (uint8_t *)&offset,
+ sizeof(uint16_t))) {
+ BNXT_TF_DBG(ERR, "Hdr fld size read failed\n");
+ return -EINVAL;
+ }
+ offset = tfp_be_to_cpu_16(offset);
+ offset = ULP_BITS_2_BYTE_NR(offset);
+ if ((offset + bytelen) > field_size) {
+ BNXT_TF_DBG(ERR, "Hdr field[%d] oob\n", bit);
+ return -EINVAL;
+ }
+ *val = &buffer[offset];
+ }
break;
case BNXT_ULP_FIELD_SRC_HDR_BIT:
- if (!ulp_operand_read(fld_src_oper,
- (uint8_t *)&hdr_bit, sizeof(uint64_t))) {
- BNXT_TF_DBG(ERR, "%s operand read failed\n", name);
- return -EINVAL;
- }
- hdr_bit = tfp_be_to_cpu_64(hdr_bit);
- memset(tmpval, 0, sizeof(tmpval));
- if (ULP_BITMAP_ISSET(parms->hdr_bitmap->bits, hdr_bit))
- tmpval[0] = 1;
- if (bitlen > ULP_BYTE_2_BITS(sizeof(tmpval))) {
- BNXT_TF_DBG(ERR, "%s field size is incorrect\n", name);
+ if (!ulp_operand_read(field_opr,
+ (uint8_t *)&lregval, sizeof(uint64_t))) {
+ BNXT_TF_DBG(ERR, "Header bit read failed\n");
return -EINVAL;
}
- if (!ulp_blob_push(blob, tmpval, bitlen)) {
- BNXT_TF_DBG(ERR, "%s push to blob failed\n", name);
- return -EINVAL;
+ lregval = tfp_be_to_cpu_64(lregval);
+ if (ULP_BITMAP_ISSET(parms->hdr_bitmap->bits, lregval)) {
+ *val = mapper_fld_one;
+ *value = 1;
+ } else {
+ *val = mapper_fld_zeros;
}
- val = tmpval;
break;
case BNXT_ULP_FIELD_SRC_ACT_BIT:
- if (!ulp_operand_read(fld_src_oper,
- (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);
- memset(tmpval, 0, sizeof(tmpval));
- if (ULP_BITMAP_ISSET(parms->act_bitmap->bits, act_bit))
- tmpval[0] = 1;
- if (bitlen > ULP_BYTE_2_BITS(sizeof(tmpval))) {
- BNXT_TF_DBG(ERR, "%s field size is incorrect\n", name);
+ if (!ulp_operand_read(field_opr,
+ (uint8_t *)&lregval, sizeof(uint64_t))) {
+ BNXT_TF_DBG(ERR, "Action bit read failed\n");
return -EINVAL;
}
- if (!ulp_blob_push(blob, tmpval, bitlen)) {
- BNXT_TF_DBG(ERR, "%s push to blob failed\n", name);
- return -EINVAL;
+ lregval = tfp_be_to_cpu_64(lregval);
+ if (ULP_BITMAP_ISSET(parms->act_bitmap->bits, lregval)) {
+ *val = mapper_fld_one;
+ *value = 1;
+ } else {
+ *val = mapper_fld_zeros;
}
- val = tmpval;
break;
case BNXT_ULP_FIELD_SRC_FIELD_BIT:
- if (!ulp_operand_read(fld_src_oper, (uint8_t *)&idx,
- sizeof(uint16_t))) {
- BNXT_TF_DBG(ERR, "%s operand read failed.\n", name);
+ if (!ulp_operand_read(field_opr,
+ (uint8_t *)&idx, sizeof(uint16_t))) {
+ BNXT_TF_DBG(ERR, "Field bit read failed\n");
return -EINVAL;
}
idx = tfp_be_to_cpu_16(idx);
idx);
return -EINVAL;
}
- memset(tmpval, 0, sizeof(tmpval));
- if (ULP_INDEX_BITMAP_GET(parms->fld_bitmap->bits, bit))
- tmpval[0] = 1;
- if (bitlen > ULP_BYTE_2_BITS(sizeof(tmpval))) {
- BNXT_TF_DBG(ERR, "%s field size is incorrect\n", name);
+ if (ULP_INDEX_BITMAP_GET(parms->fld_bitmap->bits, bit)) {
+ *val = mapper_fld_one;
+ *value = 1;
+ } else {
+ *val = mapper_fld_zeros;
+ }
+ break;
+ case BNXT_ULP_FIELD_SRC_PORT_TABLE:
+ /* The port id is present in the comp field list */
+ port_id = ULP_COMP_FLD_IDX_RD(parms,
+ BNXT_ULP_CF_IDX_DEV_PORT_ID);
+ /* get the port table enum */
+ if (!ulp_operand_read(field_opr,
+ (uint8_t *)&idx, sizeof(uint16_t))) {
+ BNXT_TF_DBG(ERR, "Port table enum read failed\n");
return -EINVAL;
}
- if (!ulp_blob_push(blob, tmpval, bitlen)) {
- BNXT_TF_DBG(ERR, "%s push to blob failed\n", name);
+ idx = tfp_be_to_cpu_16(idx);
+ if (ulp_mapper_field_port_db_process(parms, port_id, idx,
+ val)) {
+ BNXT_TF_DBG(ERR, "field port table failed\n");
return -EINVAL;
}
- val = tmpval;
break;
- case BNXT_ULP_FIELD_SRC_SKIP:
- /* do nothing */
+ case BNXT_ULP_FIELD_SRC_ENC_HDR_BIT:
+ if (!ulp_operand_read(field_opr,
+ (uint8_t *)&lregval, sizeof(uint64_t))) {
+ BNXT_TF_DBG(ERR, "Header bit read failed\n");
+ return -EINVAL;
+ }
+ lregval = tfp_be_to_cpu_64(lregval);
+ if (ULP_BITMAP_ISSET(parms->enc_hdr_bitmap->bits, lregval)) {
+ *val = mapper_fld_one;
+ *value = 1;
+ } else {
+ *val = mapper_fld_zeros;
+ }
break;
- case BNXT_ULP_FIELD_SRC_REJECT:
- return -EINVAL;
- case BNXT_ULP_FIELD_SRC_SUB_HF:
- if (!ulp_operand_read(fld_src_oper,
+ case BNXT_ULP_FIELD_SRC_ENC_FIELD:
+ if (!ulp_operand_read(field_opr,
(uint8_t *)&idx, sizeof(uint16_t))) {
- BNXT_TF_DBG(ERR, "%s operand read failed\n", name);
+ BNXT_TF_DBG(ERR, "Header field read failed\n");
return -EINVAL;
}
idx = tfp_be_to_cpu_16(idx);
/* get the index from the global field list */
- if (ulp_mapper_glb_field_tbl_get(parms, idx, &bit)) {
- BNXT_TF_DBG(ERR, "invalid ulp_glb_field_tbl idx %d\n",
+ if (idx >= BNXT_ULP_ENC_FIELD_LAST) {
+ BNXT_TF_DBG(ERR, "invalid encap field tbl idx %d\n",
idx);
return -EINVAL;
}
+ buffer = parms->enc_field[idx].spec;
+ field_size = parms->enc_field[idx].size;
+ if (bytelen > field_size) {
+ BNXT_TF_DBG(ERR, "Encap field[%d] size small %u\n",
+ idx, field_size);
+ return -EINVAL;
+ }
+ *val = &buffer[field_size - bytelen];
+ break;
+ case BNXT_ULP_FIELD_SRC_SKIP:
+ /* do nothing */
+ *val = mapper_fld_zeros;
+ *val_len = 0;
+ break;
+ case BNXT_ULP_FIELD_SRC_REJECT:
+ return -EINVAL;
+ default:
+ BNXT_TF_DBG(ERR, "invalid field opcode 0x%x\n", field_src);
+ return -EINVAL;
+ }
+ return 0;
+}
+
+static int32_t ulp_mapper_field_buffer_eval(uint8_t *buffer, uint32_t bitlen,
+ uint64_t *output)
+{
+ uint16_t val_16;
+ uint32_t val_32;
+ uint64_t val_64;
+ uint32_t bytelen;
+
+ bytelen = ULP_BITS_2_BYTE(bitlen);
+ if (bytelen == sizeof(uint8_t)) {
+ *output = *((uint8_t *)buffer);
+ } else if (bytelen == sizeof(uint16_t)) {
+ val_16 = *((uint16_t *)buffer);
+ *output = tfp_be_to_cpu_16(val_16);
+ } else if (bytelen == sizeof(uint32_t)) {
+ val_32 = *((uint32_t *)buffer);
+ *output = tfp_be_to_cpu_32(val_32);
+ } else if (bytelen == sizeof(val_64)) {
+ val_64 = *((uint64_t *)buffer);
+ *output = tfp_be_to_cpu_64(val_64);
+ } else {
+ *output = 0;
+ return -EINVAL;
+ }
+ return 0;
+}
- /* get the offset next */
- if (!ulp_operand_read(&fld_src_oper[sizeof(uint16_t)],
- (uint8_t *)&offset, sizeof(uint16_t))) {
- BNXT_TF_DBG(ERR, "%s operand read failed\n", name);
+static int32_t ulp_mapper_field_blob_write(enum bnxt_ulp_field_src fld_src,
+ struct ulp_blob *blob,
+ uint8_t *val,
+ uint32_t val_len,
+ uint8_t **out_val)
+{
+ if (fld_src == BNXT_ULP_FIELD_SRC_ZERO) {
+ if (ulp_blob_pad_push(blob, val_len) < 0) {
+ BNXT_TF_DBG(ERR, "too large for blob\n");
+ return -EINVAL;
+ }
+ } else if (fld_src == BNXT_ULP_FIELD_SRC_ACT_PROP_SZ) {
+ if (ulp_blob_push_encap(blob, val, val_len) < 0) {
+ BNXT_TF_DBG(ERR, "encap blob push failed\n");
return -EINVAL;
}
- offset = tfp_be_to_cpu_16(offset);
- if ((offset + bitlen) >
- ULP_BYTE_2_BITS(parms->hdr_field[bit].size) ||
- ULP_BITS_IS_BYTE_NOT_ALIGNED(offset)) {
- BNXT_TF_DBG(ERR, "Hdr field[%s] oob\n", name);
+ } else if (fld_src == BNXT_ULP_FIELD_SRC_SKIP) {
+ /* do nothing */
+ } else {
+ if (!ulp_blob_push(blob, val, val_len)) {
+ BNXT_TF_DBG(ERR, "push of val1 failed\n");
return -EINVAL;
}
- offset = ULP_BITS_2_BYTE_NR(offset);
+ }
+ *out_val = val;
+ return 0;
+}
- /* write the value into blob */
- if (is_key)
- val = &parms->hdr_field[bit].spec[offset];
+static int32_t
+ulp_mapper_field_opc_process(struct bnxt_ulp_mapper_parms *parms,
+ enum tf_dir dir,
+ struct bnxt_ulp_mapper_field_info *fld,
+ struct ulp_blob *blob,
+ uint8_t is_key,
+ const char *name)
+{
+ uint16_t write_idx = blob->write_idx;
+ uint8_t *val = NULL, *val1, *val2, *val3;
+ uint32_t val_len = 0, val1_len = 0, val2_len = 0, val3_len = 0;
+ uint8_t process_src1 = 0, process_src2 = 0, process_src3 = 0;
+ uint8_t eval_src1 = 0, eval_src2 = 0, eval_src3 = 0;
+ uint64_t val_int = 0, val1_int = 0, val2_int = 0, val3_int = 0;
+ uint64_t value1 = 0, value2 = 0, value3 = 0;
+ int32_t rc = 0;
+
+ /* prepare the field source and values */
+ switch (fld->field_opc) {
+ case BNXT_ULP_FIELD_OPC_SRC1:
+ process_src1 = 1;
+ break;
+ case BNXT_ULP_FIELD_OPC_SRC1_THEN_SRC2_ELSE_SRC3:
+ process_src1 = 1;
+ break;
+ case BNXT_ULP_FIELD_OPC_SRC1_OR_SRC2_OR_SRC3:
+ case BNXT_ULP_FIELD_OPC_SRC1_AND_SRC2_OR_SRC3:
+ process_src3 = 1;
+ eval_src3 = 1;
+ process_src1 = 1;
+ process_src2 = 1;
+ eval_src1 = 1;
+ eval_src2 = 1;
+ break;
+ case BNXT_ULP_FIELD_OPC_SRC1_PLUS_SRC2:
+ case BNXT_ULP_FIELD_OPC_SRC1_MINUS_SRC2:
+ case BNXT_ULP_FIELD_OPC_SRC1_PLUS_SRC2_POST:
+ case BNXT_ULP_FIELD_OPC_SRC1_MINUS_SRC2_POST:
+ case BNXT_ULP_FIELD_OPC_SRC1_OR_SRC2:
+ case BNXT_ULP_FIELD_OPC_SRC1_AND_SRC2:
+ process_src1 = 1;
+ process_src2 = 1;
+ eval_src1 = 1;
+ eval_src2 = 1;
+ break;
+ default:
+ break;
+ }
+
+ /* process the src1 opcode */
+ if (process_src1) {
+ if (ulp_mapper_field_src_process(parms, fld->field_src1,
+ fld->field_opr1, dir, is_key,
+ fld->field_bit_size, &val1,
+ &val1_len, &value1)) {
+ BNXT_TF_DBG(ERR, "fld src1 process failed\n");
+ goto error;
+ }
+ if (eval_src1) {
+ if (ulp_mapper_field_buffer_eval(val1, val1_len,
+ &val1_int)) {
+ BNXT_TF_DBG(ERR, "fld src1 eval failed\n");
+ goto error;
+ }
+ }
+ }
+
+ /* for "if then clause" set the correct process */
+ if (fld->field_opc == BNXT_ULP_FIELD_OPC_SRC1_THEN_SRC2_ELSE_SRC3) {
+ if (value1)
+ process_src2 = 1;
else
- val = &parms->hdr_field[bit].mask[offset];
+ process_src3 = 1;
+ }
- if (!ulp_blob_push(blob, val, bitlen)) {
- BNXT_TF_DBG(ERR, "%s push to blob failed\n", name);
- return -EINVAL;
+ /* process src2 opcode */
+ if (process_src2) {
+ if (ulp_mapper_field_src_process(parms, fld->field_src2,
+ fld->field_opr2, dir, is_key,
+ fld->field_bit_size, &val2,
+ &val2_len, &value2)) {
+ BNXT_TF_DBG(ERR, "fld src2 process failed\n");
+ goto error;
+ }
+ if (eval_src2) {
+ if (ulp_mapper_field_buffer_eval(val2, val2_len,
+ &val2_int)) {
+ BNXT_TF_DBG(ERR, "fld src2 eval failed\n");
+ goto error;
+ }
+ }
+ }
+
+ /* process src3 opcode */
+ if (process_src3) {
+ if (ulp_mapper_field_src_process(parms, fld->field_src3,
+ fld->field_opr3, dir, is_key,
+ fld->field_bit_size, &val3,
+ &val3_len, &value3)) {
+ BNXT_TF_DBG(ERR, "fld src3 process failed\n");
+ goto error;
+ }
+ if (eval_src3) {
+ if (ulp_mapper_field_buffer_eval(val3, val3_len,
+ &val3_int)) {
+ BNXT_TF_DBG(ERR, "fld src3 eval failed\n");
+ goto error;
+ }
+ }
+ }
+
+ val_len = fld->field_bit_size;
+ /* process the field opcodes */
+ switch (fld->field_opc) {
+ case BNXT_ULP_FIELD_OPC_SRC1:
+ rc = ulp_mapper_field_blob_write(fld->field_src1,
+ blob, val1, val1_len, &val);
+ val_len = val1_len;
+ break;
+ case BNXT_ULP_FIELD_OPC_SRC1_THEN_SRC2_ELSE_SRC3:
+ if (value1) {
+ rc = ulp_mapper_field_blob_write(fld->field_src2, blob,
+ val2, val2_len, &val);
+ val_len = val2_len;
+ } else {
+ rc = ulp_mapper_field_blob_write(fld->field_src3, blob,
+ val3, val3_len, &val);
+ val_len = val3_len;
}
break;
+ case BNXT_ULP_FIELD_OPC_SRC1_PLUS_SRC2:
+ case BNXT_ULP_FIELD_OPC_SRC1_PLUS_SRC2_POST:
+ val_int = val1_int + val2_int;
+ val_int = tfp_cpu_to_be_64(val_int);
+ val = ulp_blob_push_64(blob, &val_int, fld->field_bit_size);
+ if (!val)
+ rc = -EINVAL;
+ break;
+ case BNXT_ULP_FIELD_OPC_SRC1_MINUS_SRC2:
+ case BNXT_ULP_FIELD_OPC_SRC1_MINUS_SRC2_POST:
+ val_int = val1_int - val2_int;
+ val_int = tfp_cpu_to_be_64(val_int);
+ val = ulp_blob_push_64(blob, &val_int, fld->field_bit_size);
+ if (!val)
+ rc = -EINVAL;
+ break;
+ case BNXT_ULP_FIELD_OPC_SRC1_OR_SRC2:
+ val_int = val1_int | val2_int;
+ val_int = tfp_cpu_to_be_64(val_int);
+ val = ulp_blob_push_64(blob, &val_int, fld->field_bit_size);
+ if (!val)
+ rc = -EINVAL;
+ break;
+ case BNXT_ULP_FIELD_OPC_SRC1_OR_SRC2_OR_SRC3:
+ val_int = val1_int | val2_int | val3_int;
+ val_int = tfp_cpu_to_be_64(val_int);
+ val = ulp_blob_push_64(blob, &val_int, fld->field_bit_size);
+ if (!val)
+ rc = -EINVAL;
+ break;
+ case BNXT_ULP_FIELD_OPC_SRC1_AND_SRC2:
+ val_int = val1_int & val2_int;
+ val_int = tfp_cpu_to_be_64(val_int);
+ val = ulp_blob_push_64(blob, &val_int, fld->field_bit_size);
+ if (!val)
+ rc = -EINVAL;
+ break;
+ case BNXT_ULP_FIELD_OPC_SRC1_AND_SRC2_OR_SRC3:
+ val_int = val1_int & (val2_int | val3_int);
+ val_int = tfp_cpu_to_be_64(val_int);
+ val = ulp_blob_push_64(blob, &val_int, fld->field_bit_size);
+ if (!val)
+ rc = -EINVAL;
+ break;
+ case BNXT_ULP_FIELD_OPC_SKIP:
+ break;
default:
- BNXT_TF_DBG(ERR, "%s invalid field opcode 0x%x at %d\n",
- name, fld_src, write_idx);
- return -EINVAL;
+ BNXT_TF_DBG(ERR, "Invalid fld opcode %u\n", fld->field_opc);
+ rc = -EINVAL;
+ break;
}
- return 0;
+
+ if (!rc) {
+ return rc;
+ }
+error:
+ BNXT_TF_DBG(ERR, "Error in %s:%s process %u:%u\n", name,
+ fld->description, (val) ? write_idx : 0, val_len);
+ return -EINVAL;
}
/*
const char *name)
{
struct bnxt_ulp_mapper_field_info *dflds;
- uint32_t i, num_flds = 0, encap_flds = 0;
+ uint32_t i = 0, num_flds = 0, encap_flds = 0;
+ struct ulp_blob encap_blob;
int32_t rc = 0;
/* Get the result field list */
return -EINVAL;
}
- /* 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 == num_flds)
- ulp_blob_encap_swap_idx_set(data);
-
- /* Process the result fields */
- rc = ulp_mapper_field_process(parms, tbl->direction,
- &dflds[i], data, 0, name);
+ /* process the result fields */
+ for (i = 0; i < num_flds; i++) {
+ rc = ulp_mapper_field_opc_process(parms, tbl->direction,
+ &dflds[i], data, 0, name);
if (rc) {
- BNXT_TF_DBG(ERR, "data field failed\n");
+ BNXT_TF_DBG(ERR, "result field processing failed\n");
return rc;
}
}
- /* 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);
+ /* process encap fields if any */
+ if (encap_flds) {
+ uint32_t pad = 0;
+ /* Initialize the encap blob */
+ if (!tbl->record_size &&
+ !parms->device_params->dynamic_sram_en) {
+ BNXT_TF_DBG(ERR, "Encap tbl record size incorrect\n");
+ return -EINVAL;
+ }
+ if (!ulp_blob_init(&encap_blob,
+ ULP_BYTE_2_BITS(tbl->record_size),
+ parms->device_params->encap_byte_order)) {
+ BNXT_TF_DBG(ERR, "blob inits failed.\n");
+ return -EINVAL;
+ }
+ for (; i < encap_flds; i++) {
+ rc = ulp_mapper_field_opc_process(parms, tbl->direction,
+ &dflds[i],
+ &encap_blob, 0, name);
+ if (rc) {
+ BNXT_TF_DBG(ERR,
+ "encap field processing failed\n");
+ return rc;
+ }
+ }
+ /* add the dynamic pad push */
+ if (parms->device_params->dynamic_sram_en) {
+ uint16_t rec_s = ULP_BYTE_2_BITS(tbl->record_size);
+ (void)ulp_mapper_dyn_tbl_type_get(parms, tbl,
+ &encap_blob, &rec_s);
+ pad = rec_s - ulp_blob_data_len_get(&encap_blob);
+ } else {
+ pad = ULP_BYTE_2_BITS(tbl->record_size) -
+ ulp_blob_data_len_get(&encap_blob);
+ }
+ if (ulp_blob_pad_push(&encap_blob, pad) < 0) {
+ BNXT_TF_DBG(ERR, "encap buffer padding failed\n");
+ return -EINVAL;
+ }
+
+
+ /* perform the 64 bit byte swap */
+ ulp_blob_perform_64B_byte_swap(&encap_blob);
+ /* Append encap blob to the result blob */
+ rc = ulp_blob_buffer_copy(data, &encap_blob);
+ if (rc) {
+ BNXT_TF_DBG(ERR, "encap buffer copy failed\n");
+ return rc;
+ }
+ }
return rc;
}
fid_parms.critical_resource = tbl->critical_resource;
fid_parms.resource_type = mark_flag;
fid_parms.resource_hndl = gfid;
+ ulp_flow_db_shared_session_set(&fid_parms, tbl->shared_session);
+
rc = ulp_mapper_fdb_opc_process(parms, tbl, &fid_parms);
if (rc)
BNXT_TF_DBG(ERR, "Fail to link res to flow rc = %d\n", rc);
fid_parms.critical_resource = tbl->critical_resource;
fid_parms.resource_type = mark_flag;
fid_parms.resource_hndl = act_idx;
+ ulp_flow_db_shared_session_set(&fid_parms, tbl->shared_session);
+
rc = ulp_mapper_fdb_opc_process(parms, tbl, &fid_parms);
if (rc)
BNXT_TF_DBG(ERR, "Fail to link res to flow rc = %d\n", rc);
fid_parms.critical_resource = tbl->critical_resource;
fid_parms.resource_type = mark_flag;
fid_parms.resource_hndl = act_idx;
+ ulp_flow_db_shared_session_set(&fid_parms, tbl->shared_session);
+
rc = ulp_mapper_fdb_opc_process(parms, tbl, &fid_parms);
if (rc)
BNXT_TF_DBG(ERR, "Fail to link res to flow rc = %d\n", rc);
uint16_t tmplen;
int32_t rc;
- tfp = bnxt_ulp_cntxt_tfp_get(parms->ulp_ctx);
+ tfp = bnxt_ulp_cntxt_tfp_get(parms->ulp_ctx, tbl->shared_session);
if (!tfp) {
BNXT_TF_DBG(ERR, "Failed to get truflow pointer\n");
return -EINVAL;
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);
ulp_blob_perform_64B_byte_swap(blob);
}
+static int32_t ulp_mapper_tcam_is_wc_tcam(struct bnxt_ulp_mapper_tbl_info *tbl)
+{
+ if (tbl->resource_type == TF_TCAM_TBL_TYPE_WC_TCAM ||
+ tbl->resource_type == TF_TCAM_TBL_TYPE_WC_TCAM_HIGH ||
+ tbl->resource_type == TF_TCAM_TBL_TYPE_WC_TCAM_LOW)
+ return 1;
+ return 0;
+}
+
static int32_t
ulp_mapper_tcam_tbl_process(struct bnxt_ulp_mapper_parms *parms,
struct bnxt_ulp_mapper_tbl_info *tbl)
uint32_t hit = 0;
uint16_t tmplen = 0;
uint16_t idx;
+ enum bnxt_ulp_byte_order key_byte_order;
/* Set the key and mask to the original key and mask. */
key = &okey;
return 0;
}
- tfp = bnxt_ulp_cntxt_tfp_get(parms->ulp_ctx);
+ tfp = bnxt_ulp_cntxt_tfp_get(parms->ulp_ctx, tbl->shared_session);
if (!tfp) {
BNXT_TF_DBG(ERR, "Failed to get truflow pointer\n");
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");
return -EINVAL;
}
- if (!ulp_blob_init(key, tbl->blob_key_bit_size, tbl->byte_order) ||
- !ulp_blob_init(mask, tbl->blob_key_bit_size, tbl->byte_order) ||
- !ulp_blob_init(&data, tbl->result_bit_size, dparms->byte_order) ||
+ if (ulp_mapper_tcam_is_wc_tcam(tbl))
+ key_byte_order = dparms->wc_key_byte_order;
+ else
+ key_byte_order = dparms->key_byte_order;
+
+ if (!ulp_blob_init(key, tbl->blob_key_bit_size, key_byte_order) ||
+ !ulp_blob_init(mask, tbl->blob_key_bit_size, key_byte_order) ||
+ !ulp_blob_init(&data, tbl->result_bit_size,
+ dparms->result_byte_order) ||
!ulp_blob_init(&update_data, tbl->result_bit_size,
- dparms->byte_order)) {
+ dparms->result_byte_order)) {
BNXT_TF_DBG(ERR, "blob inits failed.\n");
return -EINVAL;
}
*/
for (i = 0; i < num_kflds; i++) {
/* Setup the key */
- rc = ulp_mapper_field_process(parms, tbl->direction,
- &kflds[i].field_info_spec,
- key, 1, "TCAM Key");
+ rc = ulp_mapper_field_opc_process(parms, tbl->direction,
+ &kflds[i].field_info_spec,
+ key, 1, "TCAM Key");
if (rc) {
BNXT_TF_DBG(ERR, "Key field set failed %s\n",
kflds[i].field_info_spec.description);
}
/* Setup the mask */
- rc = ulp_mapper_field_process(parms, tbl->direction,
- &kflds[i].field_info_mask,
- mask, 0, "TCAM Mask");
+ rc = ulp_mapper_field_opc_process(parms, tbl->direction,
+ &kflds[i].field_info_mask,
+ mask, 0, "TCAM Mask");
if (rc) {
BNXT_TF_DBG(ERR, "Mask field set failed %s\n",
kflds[i].field_info_mask.description);
}
/* For wild card tcam perform the post process to swap the blob */
- if (tbl->resource_type == TF_TCAM_TBL_TYPE_WC_TCAM) {
+ if (ulp_mapper_tcam_is_wc_tcam(tbl)) {
if (dparms->dynamic_pad_en) {
/* Sets up the slices for writing to the WC TCAM */
rc = ulp_mapper_wc_tcam_tbl_dyn_post_process(dparms,
fid_parms.resource_type = tbl->resource_type;
fid_parms.critical_resource = tbl->critical_resource;
fid_parms.resource_hndl = idx;
+ ulp_flow_db_shared_session_set(&fid_parms, tbl->shared_session);
+
rc = ulp_mapper_fdb_opc_process(parms, tbl, &fid_parms);
if (rc) {
BNXT_TF_DBG(ERR, "Failed to link resource to flow rc = %d\n",
struct ulp_blob key, data;
uint32_t i, num_kflds;
uint16_t tmplen;
- struct tf *tfp = bnxt_ulp_cntxt_tfp_get(parms->ulp_ctx);
+ struct tf *tfp;
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 };
int32_t trc;
int32_t rc = 0;
int32_t pad = 0;
+ enum bnxt_ulp_byte_order key_order, res_order;
+ tfp = bnxt_ulp_cntxt_tfp_get(parms->ulp_ctx, tbl->shared_session);
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;
}
+ key_order = dparms->em_byte_order;
+ res_order = dparms->em_byte_order;
+
/* Initialize the key/result blobs */
- if (!ulp_blob_init(&key, tbl->blob_key_bit_size,
- tbl->byte_order) ||
- !ulp_blob_init(&data, tbl->result_bit_size,
- tbl->byte_order)) {
+ if (!ulp_blob_init(&key, tbl->blob_key_bit_size, key_order) ||
+ !ulp_blob_init(&data, tbl->result_bit_size, res_order)) {
BNXT_TF_DBG(ERR, "blob inits failed.\n");
return -EINVAL;
}
/* create the key */
for (i = 0; i < num_kflds; i++) {
/* Setup the key */
- rc = ulp_mapper_field_process(parms, tbl->direction,
- &kflds[i].field_info_spec,
- &key, 1, "EM Key");
+ rc = ulp_mapper_field_opc_process(parms, tbl->direction,
+ &kflds[i].field_info_spec,
+ &key, 1, "EM Key");
if (rc) {
BNXT_TF_DBG(ERR, "Key field set failed.\n");
return rc;
struct tf_get_tbl_entry_parms gparms = { 0 };
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);
- struct bnxt_ulp_glb_resource_info glb_res;
+ struct tf *tfp;
+ struct bnxt_ulp_glb_resource_info glb_res = { 0 };
uint16_t bit_size;
bool alloc = false;
bool write = false;
bool global = false;
uint64_t act_rec_size;
+ bool shared = false;
+ enum tf_tbl_type tbl_type = tbl->resource_type;
- /* 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;
+ tfp = bnxt_ulp_cntxt_tfp_get(parms->ulp_ctx, tbl->shared_session);
+ /* compute the blob size */
+ bit_size = ulp_mapper_dyn_blob_size_get(parms, tbl);
/* Initialize the blob data */
if (!ulp_blob_init(&data, bit_size,
- parms->device_params->byte_order)) {
+ parms->device_params->result_byte_order)) {
BNXT_TF_DBG(ERR, "Failed to initialize index table blob\n");
return -EINVAL;
}
if (ulp_mapper_glb_resource_read(parms->mapper_data,
tbl->direction,
tbl->tbl_operand,
- ®val)) {
+ ®val, &shared)) {
BNXT_TF_DBG(ERR,
- "Failed to get tbl idx from Global "
- "regfile[%d].\n",
+ "Failed to get tbl idx from Glb RF[%d].\n",
tbl->tbl_operand);
return -EINVAL;
}
gparms.dir = tbl->direction;
gparms.type = tbl->resource_type;
gparms.data = ulp_blob_data_get(&data, &tmplen);
- gparms.data_sz_in_bytes = ULP_BITS_2_BYTE(tbl->result_bit_size);
+ gparms.data_sz_in_bytes = ULP_BITS_2_BYTE(tmplen);
gparms.idx = index;
rc = tf_get_tbl_entry(tfp, &gparms);
if (rc) {
gparms.data_sz_in_bytes,
data.byte_order);
if (rc) {
- BNXT_TF_DBG(ERR, "Failed to read fields on tbl read "
- "rc=%d\n", rc);
+ BNXT_TF_DBG(ERR,
+ "Failed to get flds on tbl read rc=%d\n",
+ rc);
return rc;
}
return 0;
if (alloc) {
aparms.dir = tbl->direction;
- aparms.type = tbl->resource_type;
+ tbl_type = ulp_mapper_dyn_tbl_type_get(parms, tbl,
+ &data, &tmplen);
+ aparms.type = tbl_type;
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_tbl_type_2_str(aparms.type),
tf_dir_2_str(tbl->direction), rc);
return rc;
}
regval = tfp_cpu_to_be_64(regval);
if (global) {
+ /*
+ * Shared resources are never allocated through this
+ * method, so the shared flag is always false.
+ */
rc = ulp_mapper_glb_resource_write(parms->mapper_data,
- &glb_res, regval);
+ &glb_res, regval,
+ false);
} else {
rc = ulp_regfile_write(parms->regfile,
tbl->tbl_operand, regval);
if (write) {
sparms.dir = tbl->direction;
- sparms.type = tbl->resource_type;
sparms.data = ulp_blob_data_get(&data, &tmplen);
+ tbl_type = ulp_mapper_dyn_tbl_type_get(parms, tbl, &data,
+ &tmplen);
+ sparms.type = tbl_type;
sparms.data_sz_in_bytes = ULP_BITS_2_BYTE(tmplen);
sparms.idx = index;
sparms.tbl_scope_id = tbl_scope_id;
+ if (shared)
+ tfp = bnxt_ulp_cntxt_shared_tfp_get(parms->ulp_ctx);
rc = tf_set_tbl_entry(tfp, &sparms);
if (rc) {
BNXT_TF_DBG(ERR,
- "Index table[%s][%s][%x] write failed "
- "rc=%d\n",
+ "Index table[%s][%s][%x] write fail rc=%d\n",
tf_tbl_type_2_str(sparms.type),
tf_dir_2_str(sparms.dir),
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) {
memset(&fid_parms, 0, sizeof(fid_parms));
fid_parms.direction = tbl->direction;
fid_parms.resource_func = tbl->resource_func;
- fid_parms.resource_type = tbl->resource_type;
+ fid_parms.resource_type = tbl_type;
fid_parms.resource_sub_type = tbl->resource_sub_type;
fid_parms.resource_hndl = index;
fid_parms.critical_resource = tbl->critical_resource;
+ ulp_flow_db_shared_session_set(&fid_parms, tbl->shared_session);
rc = ulp_mapper_fdb_opc_process(parms, tbl, &fid_parms);
if (rc) {
}
return rc;
error:
+ /* Shared resources are not freed */
+ if (shared)
+ return rc;
/*
* Free the allocated resource since we failed to either
* write to the entry or link the flow
*/
free_parms.dir = tbl->direction;
- free_parms.type = tbl->resource_type;
+ free_parms.type = tbl_type;
free_parms.idx = index;
free_parms.tbl_scope_id = tbl_scope_id;
int32_t rc = 0;
struct tf_set_if_tbl_entry_parms iftbl_params = { 0 };
struct tf_get_if_tbl_entry_parms get_parms = { 0 };
- struct tf *tfp = bnxt_ulp_cntxt_tfp_get(parms->ulp_ctx);
+ struct tf *tfp;
enum bnxt_ulp_if_tbl_opc if_opc = tbl->tbl_opcode;
uint32_t res_size;
+ tfp = bnxt_ulp_cntxt_tfp_get(parms->ulp_ctx, tbl->shared_session);
/* Initialize the blob data */
if (!ulp_blob_init(&data, tbl->result_bit_size,
- parms->device_params->byte_order)) {
+ parms->device_params->result_byte_order)) {
BNXT_TF_DBG(ERR, "Failed initial index table blob\n");
return -EINVAL;
}
case BNXT_ULP_IF_TBL_OPC_RD_COMP_FIELD:
/* Initialize the result blob */
if (!ulp_blob_init(&res_blob, tbl->result_bit_size,
- parms->device_params->byte_order)) {
+ parms->device_params->result_byte_order)) {
BNXT_TF_DBG(ERR, "Failed initial result blob\n");
return -EINVAL;
}
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
struct ulp_flow_db_res_params fid_parms;
struct ulp_mapper_gen_tbl_entry gen_tbl_ent, *g;
struct ulp_gen_hash_entry_params hash_entry;
- uint16_t tmplen;
+ uint16_t tmplen = 0;
struct ulp_blob key, data;
uint8_t *cache_key;
int32_t tbl_idx;
}
if (!ulp_blob_init(&key, tbl->key_bit_size,
- parms->device_params->byte_order)) {
+ parms->device_params->key_byte_order)) {
BNXT_TF_DBG(ERR, "Failed to alloc blob\n");
return -EINVAL;
}
for (i = 0; i < num_kflds; i++) {
/* Setup the key */
- rc = ulp_mapper_field_process(parms, tbl->direction,
- &kflds[i].field_info_spec,
- &key, 1, "Gen Tbl Key");
+ rc = ulp_mapper_field_opc_process(parms, tbl->direction,
+ &kflds[i].field_info_spec,
+ &key, 1, "Gen Tbl Key");
if (rc) {
BNXT_TF_DBG(ERR,
"Failed to create key for Gen tbl rc=%d\n",
}
} else {
/* convert key to index directly */
+ if (ULP_BITS_2_BYTE(tmplen) > (int32_t)sizeof(key_index)) {
+ BNXT_TF_DBG(ERR, "%s: keysize is bigger then 4 bytes\n",
+ gen_tbl_list->gen_tbl_name);
+ return -EINVAL;
+ }
memcpy(&key_index, cache_key, ULP_BITS_2_BYTE(tmplen));
/* Get the generic table entry */
if (ulp_mapper_gen_tbl_entry_get(gen_tbl_list, key_index,
fid_parms.resource_sub_type = tbl->resource_sub_type;
fid_parms.resource_hndl = key_index;
fid_parms.critical_resource = tbl->critical_resource;
+ ulp_flow_db_shared_session_set(&fid_parms, tbl->shared_session);
+
rc = ulp_mapper_fdb_opc_process(parms, tbl, &fid_parms);
if (rc)
BNXT_TF_DBG(ERR, "Fail to add gen ent flowdb %d\n", rc);
struct bnxt_ulp_mapper_data *mapper_data)
{
struct bnxt_ulp_glb_resource_info *glb_res;
- uint32_t num_glb_res_ids, idx;
+ uint32_t num_glb_res_ids, idx, dev_id;
+ uint8_t app_id;
int32_t rc = 0;
glb_res = ulp_mapper_glb_resource_info_list_get(&num_glb_res_ids);
return -EINVAL;
}
+ rc = bnxt_ulp_cntxt_dev_id_get(ulp_ctx, &dev_id);
+ if (rc) {
+ BNXT_TF_DBG(ERR, "Failed to get device id for glb init (%d)\n",
+ rc);
+ return rc;
+ }
+
+ rc = bnxt_ulp_cntxt_app_id_get(ulp_ctx, &app_id);
+ if (rc) {
+ BNXT_TF_DBG(ERR, "Failed to get app id for glb init (%d)\n",
+ rc);
+ return rc;
+ }
+
/* Iterate the global resources and process each one */
for (idx = 0; idx < num_glb_res_ids; idx++) {
+ if (dev_id != glb_res[idx].device_id ||
+ glb_res[idx].app_id != app_id)
+ continue;
switch (glb_res[idx].resource_func) {
case BNXT_ULP_RESOURCE_FUNC_IDENTIFIER:
rc = ulp_mapper_resource_ident_allocate(ulp_ctx,
}
/*
- * 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
+ * Iterate over the shared resources assigned during tf_open_session and store
+ * them in the global regfile with the shared flag.
*/
static int32_t
-ulp_mapper_tbl_memtype_opcode_process(struct bnxt_ulp_mapper_parms *parms,
- struct bnxt_ulp_mapper_tbl_info *tbl)
+ulp_mapper_app_glb_resource_info_init(struct bnxt_ulp_context *ulp_ctx,
+ struct bnxt_ulp_mapper_data *mapper_data)
{
- enum bnxt_ulp_flow_mem_type mtype = BNXT_ULP_FLOW_MEM_TYPE_INT;
- int32_t rc = 1;
+ struct tf_get_shared_tbl_increment_parms iparms;
+ struct bnxt_ulp_glb_resource_info *glb_res;
+ struct tf_get_session_info_parms sparms;
+ uint32_t num_entries, i, dev_id, res;
+ struct tf_resource_info *res_info;
+ uint32_t addend;
+ uint64_t regval;
+ enum tf_dir dir;
+ int32_t rc = 0;
+ struct tf *tfp;
+ uint8_t app_id;
- if (bnxt_ulp_cntxt_mem_type_get(parms->ulp_ctx, &mtype)) {
- BNXT_TF_DBG(ERR, "Failed to get the mem type\n");
+ memset(&sparms, 0, sizeof(sparms));
+ glb_res = bnxt_ulp_app_glb_resource_info_list_get(&num_entries);
+ if (!glb_res || !num_entries) {
+ BNXT_TF_DBG(ERR, "Invalid Arguments\n");
+ return -EINVAL;
+ }
+ tfp = bnxt_ulp_cntxt_shared_tfp_get(ulp_ctx);
+ if (!tfp) {
+ BNXT_TF_DBG(ERR, "Failed to get tfp for app global init");
+ return -EINVAL;
+ }
+ /*
+ * Retrieve the resources that were assigned during the shared session
+ * creation.
+ */
+ rc = tf_get_session_info(tfp, &sparms);
+ if (rc) {
+ BNXT_TF_DBG(ERR, "Failed to get session info (%d)\n", rc);
return rc;
}
- switch (tbl->mem_type_opcode) {
- case BNXT_ULP_MEM_TYPE_OPC_EXECUTE_IF_INT:
- if (mtype == BNXT_ULP_FLOW_MEM_TYPE_INT)
- rc = 0;
- break;
- case BNXT_ULP_MEM_TYPE_OPC_EXECUTE_IF_EXT:
- if (mtype == BNXT_ULP_FLOW_MEM_TYPE_EXT)
- rc = 0;
- break;
- case BNXT_ULP_MEM_TYPE_OPC_NOP:
- rc = 0;
- break;
- default:
- BNXT_TF_DBG(ERR,
- "Invalid arg in mapper in memtype opcode\n");
- break;
+ rc = bnxt_ulp_cntxt_app_id_get(ulp_ctx, &app_id);
+ if (rc) {
+ BNXT_TF_DBG(ERR, "Failed to get the app id in glb init (%d).\n",
+ rc);
+ return rc;
+ }
+
+ rc = bnxt_ulp_cntxt_dev_id_get(ulp_ctx, &dev_id);
+ if (rc) {
+ BNXT_TF_DBG(ERR, "Failed to get dev id for app glb init (%d)\n",
+ rc);
+ return rc;
+ }
+
+ /* Store all the app global resources */
+ for (i = 0; i < num_entries; i++) {
+ if (dev_id != glb_res[i].device_id ||
+ app_id != glb_res[i].app_id)
+ continue;
+ dir = glb_res[i].direction;
+ res = glb_res[i].resource_type;
+ addend = 1;
+
+ switch (glb_res[i].resource_func) {
+ case BNXT_ULP_RESOURCE_FUNC_IDENTIFIER:
+ res_info = &sparms.session_info.ident[dir].info[res];
+ break;
+ case BNXT_ULP_RESOURCE_FUNC_INDEX_TABLE:
+ /*
+ * Tables may have various strides for the allocations.
+ * Need to account.
+ */
+ memset(&iparms, 0, sizeof(iparms));
+ iparms.dir = dir;
+ iparms.type = res;
+ rc = tf_get_shared_tbl_increment(tfp, &iparms);
+ if (rc) {
+ BNXT_TF_DBG(ERR,
+ "Failed to get addend for %s[%s] rc=(%d)\n",
+ tf_tbl_type_2_str(res),
+ tf_dir_2_str(dir), rc);
+ return rc;
+ }
+ addend = iparms.increment_cnt;
+ res_info = &sparms.session_info.tbl[dir].info[res];
+ break;
+ case BNXT_ULP_RESOURCE_FUNC_TCAM_TABLE:
+ res_info = &sparms.session_info.tcam[dir].info[res];
+ break;
+ case BNXT_ULP_RESOURCE_FUNC_EM_TABLE:
+ res_info = &sparms.session_info.em[dir].info[res];
+ break;
+ default:
+ BNXT_TF_DBG(ERR, "Unknown resource func (0x%x)\n",
+ glb_res[i].resource_func);
+ continue;
+ }
+ regval = tfp_cpu_to_be_64((uint64_t)res_info->start);
+ res_info->start += addend;
+ /*
+ * All resources written to the global regfile are shared for
+ * this function.
+ */
+ rc = ulp_mapper_glb_resource_write(mapper_data, &glb_res[i],
+ regval, true);
+ if (rc)
+ return rc;
}
+
return rc;
}
uint32_t operand,
int32_t *res)
{
+ enum bnxt_ulp_flow_mem_type mtype = BNXT_ULP_FLOW_MEM_TYPE_INT;
int32_t rc = 0;
uint8_t bit;
uint64_t regval;
*res = regval == 0;
break;
case BNXT_ULP_COND_OPC_FLOW_PAT_MATCH:
- if (parms->flow_pattern_id == operand) {
- BNXT_TF_DBG(ERR, "field pattern match failed %x\n",
- parms->flow_pattern_id);
+ *res = parms->flow_pattern_id == operand;
+ break;
+ case BNXT_ULP_COND_OPC_ACT_PAT_MATCH:
+ *res = parms->act_pattern_id == operand;
+ break;
+ case BNXT_ULP_COND_OPC_EXT_MEM_IS_SET:
+ if (bnxt_ulp_cntxt_mem_type_get(parms->ulp_ctx, &mtype)) {
+ BNXT_TF_DBG(ERR, "Failed to get the mem type\n");
return -EINVAL;
}
+ *res = (mtype == BNXT_ULP_FLOW_MEM_TYPE_INT) ? 0 : 1;
break;
- case BNXT_ULP_COND_OPC_ACT_PAT_MATCH:
- if (parms->act_pattern_id == operand) {
- BNXT_TF_DBG(ERR, "act pattern match failed %x\n",
- parms->act_pattern_id);
+ case BNXT_ULP_COND_OPC_EXT_MEM_NOT_SET:
+ if (bnxt_ulp_cntxt_mem_type_get(parms->ulp_ctx, &mtype)) {
+ BNXT_TF_DBG(ERR, "Failed to get the mem type\n");
return -EINVAL;
}
+ *res = (mtype == BNXT_ULP_FLOW_MEM_TYPE_INT) ? 1 : 0;
+ break;
+ case BNXT_ULP_COND_OPC_ENC_HDR_BIT_IS_SET:
+ if (operand < BNXT_ULP_HDR_BIT_LAST) {
+ *res = ULP_BITMAP_ISSET(parms->enc_hdr_bitmap->bits,
+ operand);
+ } else {
+ BNXT_TF_DBG(ERR, "header bit out of bounds %d\n",
+ operand);
+ rc = -EINVAL;
+ }
+ break;
+ case BNXT_ULP_COND_OPC_ENC_HDR_BIT_NOT_SET:
+ if (operand < BNXT_ULP_HDR_BIT_LAST) {
+ *res = !ULP_BITMAP_ISSET(parms->enc_hdr_bitmap->bits,
+ operand);
+ } else {
+ BNXT_TF_DBG(ERR, "header bit out of bounds %d\n",
+ operand);
+ rc = -EINVAL;
+ }
break;
default:
BNXT_TF_DBG(ERR, "Invalid conditional opcode %d\n", opc);
return (rc);
}
+static int32_t
+ulp_mapper_func_opr_compute(struct bnxt_ulp_mapper_parms *parms,
+ enum tf_dir dir,
+ enum bnxt_ulp_func_src func_src,
+ uint16_t func_opr,
+ uint64_t *result)
+{
+ uint64_t regval;
+ bool shared;
+
+ *result = false;
+ switch (func_src) {
+ case BNXT_ULP_FUNC_SRC_COMP_FIELD:
+ if (func_opr >= BNXT_ULP_CF_IDX_LAST) {
+ BNXT_TF_DBG(ERR, "invalid index %u\n", func_opr);
+ return -EINVAL;
+ }
+ *result = ULP_COMP_FLD_IDX_RD(parms, func_opr);
+ break;
+ case BNXT_ULP_FUNC_SRC_REGFILE:
+ if (!ulp_regfile_read(parms->regfile, func_opr, ®val)) {
+ BNXT_TF_DBG(ERR, "regfile[%d] read oob\n", func_opr);
+ return -EINVAL;
+ }
+ *result = tfp_be_to_cpu_64(regval);
+ break;
+ case BNXT_ULP_FUNC_SRC_GLB_REGFILE:
+ if (ulp_mapper_glb_resource_read(parms->mapper_data, dir,
+ func_opr, ®val, &shared)) {
+ BNXT_TF_DBG(ERR, "global regfile[%d] read failed.\n",
+ func_opr);
+ return -EINVAL;
+ }
+ *result = tfp_be_to_cpu_64(regval);
+ break;
+ case BNXT_ULP_FUNC_SRC_CONST:
+ *result = func_opr;
+ break;
+ default:
+ BNXT_TF_DBG(ERR, "invalid src code %u\n", func_src);
+ return -EINVAL;
+ }
+ return 0;
+}
+
+static int32_t
+ulp_mapper_func_info_process(struct bnxt_ulp_mapper_parms *parms,
+ struct bnxt_ulp_mapper_tbl_info *tbl)
+{
+ struct bnxt_ulp_mapper_func_info *func_info = &tbl->func_info;
+ uint64_t res = 0, res1 = 0, res2 = 0;
+ int32_t rc = 0;
+ uint32_t process_src1 = 0, process_src2 = 0;
+
+ /* determine which functional operands to compute */
+ switch (func_info->func_opc) {
+ case BNXT_ULP_FUNC_OPC_NOP:
+ return rc;
+ case BNXT_ULP_FUNC_OPC_EQ:
+ case BNXT_ULP_FUNC_OPC_NE:
+ case BNXT_ULP_FUNC_OPC_GE:
+ case BNXT_ULP_FUNC_OPC_GT:
+ case BNXT_ULP_FUNC_OPC_LE:
+ case BNXT_ULP_FUNC_OPC_LT:
+ process_src1 = 1;
+ process_src2 = 1;
+ break;
+ case BNXT_ULP_FUNC_OPC_COPY_SRC1_TO_RF:
+ process_src1 = 1;
+ break;
+ default:
+ break;
+ }
+
+ if (process_src1) {
+ rc = ulp_mapper_func_opr_compute(parms, tbl->direction,
+ func_info->func_src1,
+ func_info->func_opr1, &res1);
+ if (rc)
+ return rc;
+ }
+
+ if (process_src2) {
+ rc = ulp_mapper_func_opr_compute(parms, tbl->direction,
+ func_info->func_src2,
+ func_info->func_opr2, &res2);
+ if (rc)
+ return rc;
+ }
+
+ /* perform the functional opcode operations */
+ switch (func_info->func_opc) {
+ case BNXT_ULP_FUNC_OPC_EQ:
+ if (res1 == res2)
+ res = 1;
+ break;
+ case BNXT_ULP_FUNC_OPC_NE:
+ if (res1 != res2)
+ res = 1;
+ break;
+ case BNXT_ULP_FUNC_OPC_GE:
+ if (res1 >= res2)
+ res = 1;
+ break;
+ case BNXT_ULP_FUNC_OPC_GT:
+ if (res1 > res2)
+ res = 1;
+ break;
+ case BNXT_ULP_FUNC_OPC_LE:
+ if (res1 <= res2)
+ res = 1;
+ break;
+ case BNXT_ULP_FUNC_OPC_LT:
+ if (res1 < res2)
+ res = 1;
+ break;
+ case BNXT_ULP_FUNC_OPC_COPY_SRC1_TO_RF:
+ res = res1;
+ break;
+ case BNXT_ULP_FUNC_OPC_RSS_CONFIG:
+ /* apply the rss config using pmd method */
+ return bnxt_rss_config_action_apply(parms);
+ case BNXT_ULP_FUNC_OPC_GET_PARENT_MAC_ADDR:
+ rc = bnxt_pmd_get_parent_mac_addr(parms, (uint8_t *)&res);
+ if (rc)
+ return -EINVAL;
+ res = tfp_be_to_cpu_64(res);
+ break;
+ default:
+ BNXT_TF_DBG(ERR, "invalid func code %u\n", func_info->func_opc);
+ return -EINVAL;
+ }
+ if (ulp_regfile_write(parms->regfile, func_info->func_dst_opr,
+ tfp_cpu_to_be_64(res))) {
+ BNXT_TF_DBG(ERR, "Failed write the func_opc %u\n",
+ func_info->func_dst_opr);
+ return -EINVAL;
+ }
+
+ return rc;
+}
+
/*
* Processes a list of conditions and returns both a status and result of the
* list. The status must be checked prior to verifying the result.
default:
BNXT_TF_DBG(ERR, "Invalid conditional list opcode %d\n",
list_opc);
+ *res = 0;
return -EINVAL;
}
{
int32_t rc = 0;
uint64_t regval;
- uint64_t comp_sig_id;
+ uint64_t comp_sig;
*res = 0;
switch (tbl->accept_opcode) {
BNXT_ULP_RF_IDX_FLOW_SIG_ID);
return -EINVAL;
}
- comp_sig_id = ULP_COMP_FLD_IDX_RD(parms,
- BNXT_ULP_CF_IDX_FLOW_SIG_ID);
+ comp_sig = ULP_COMP_FLD_IDX_RD(parms,
+ BNXT_ULP_CF_IDX_FLOW_SIG_ID);
regval = tfp_be_to_cpu_64(regval);
- if (comp_sig_id == regval)
+ if (comp_sig == regval)
*res = 1;
else
- BNXT_TF_DBG(ERR, "failed signature match %x:%x\n",
- (uint32_t)comp_sig_id, (uint32_t)regval);
+ BNXT_TF_DBG(ERR, "failed signature match 0x%016"
+ PRIX64 ":%x\n", comp_sig, (uint32_t)regval);
break;
default:
BNXT_TF_DBG(ERR, "Invalid accept opcode %d\n",
for (tbl_idx = 0; tbl_idx < num_tbls && cond_goto;) {
tbl = &tbls[tbl_idx];
- /* Handle the table level opcodes to determine if required. */
- if (ulp_mapper_tbl_memtype_opcode_process(parms, tbl)) {
- cond_goto = tbl->execute_info.cond_false_goto;
- goto next_iteration;
+ cond_goto = tbl->execute_info.cond_true_goto;
+ /* Process the conditional func code opcodes */
+ if (ulp_mapper_func_info_process(parms, tbl)) {
+ BNXT_TF_DBG(ERR, "Failed to process cond update\n");
+ rc = -EINVAL;
+ goto error;
}
cond_tbls = ulp_mapper_tbl_execute_list_get(parms, tbl,
cond_tbls, num_cond_tbls,
&cond_rc);
if (rc) {
- BNXT_TF_DBG(ERR, "Failed to process cond opc list "
- "(%d)\n", rc);
- return rc;
+ BNXT_TF_DBG(ERR, "Failed to proc cond opc list (%d)\n",
+ rc);
+ goto error;
}
/* Skip the table if False */
if (!cond_rc) {
goto error;
}
next_iteration:
+ if (cond_goto == BNXT_ULP_COND_GOTO_REJECT) {
+ BNXT_TF_DBG(ERR, "reject the flow\n");
+ rc = -EINVAL;
+ goto error;
+ } else if (cond_goto & BNXT_ULP_COND_GOTO_RF) {
+ uint32_t rf_idx;
+ uint64_t regval;
+
+ /* least significant 16 bits from reg_file index */
+ rf_idx = (uint32_t)(cond_goto & 0xFFFF);
+ if (!ulp_regfile_read(parms->regfile, rf_idx,
+ ®val)) {
+ BNXT_TF_DBG(ERR, "regfile[%d] read oob\n",
+ rf_idx);
+ rc = -EINVAL;
+ goto error;
+ }
+ cond_goto = (int32_t)regval;
+ }
+
if (cond_goto < 0 && ((int32_t)tbl_idx + cond_goto) < 0) {
BNXT_TF_DBG(ERR, "invalid conditional goto %d\n",
cond_goto);
BNXT_TF_DBG(ERR, "Unable to free resource\n ");
return -EINVAL;
}
-
- tfp = bnxt_ulp_cntxt_tfp_get(ulp);
+ if (res->fdb_flags & ULP_FDB_FLAG_SHARED_SESSION)
+ tfp = bnxt_ulp_cntxt_tfp_get(ulp, BNXT_ULP_SHARED_SESSION_YES);
+ else
+ tfp = bnxt_ulp_cntxt_tfp_get(ulp, BNXT_ULP_SHARED_SESSION_NO);
if (!tfp) {
BNXT_TF_DBG(ERR, "Unable to free resource failed to get tfp\n");
return -EINVAL;
* Set the critical resource on the first resource del, then iterate
* while status is good
*/
- if (flow_type != BNXT_ULP_FDB_TYPE_RID)
- res_parms.critical_resource = BNXT_ULP_CRITICAL_RESOURCE_YES;
+ res_parms.critical_resource = BNXT_ULP_CRITICAL_RESOURCE_YES;
rc = ulp_flow_db_resource_del(ulp_ctx, flow_type, fid, &res_parms);
/* Iterate the global resources and process each one */
for (dir = TF_DIR_RX; dir < TF_DIR_MAX; dir++) {
- for (idx = 0; idx < BNXT_ULP_GLB_RESOURCE_TBL_MAX_SZ;
- idx++) {
+ for (idx = 0; idx < BNXT_ULP_GLB_RF_IDX_LAST; idx++) {
ent = &mapper_data->glb_res_tbl[dir][idx];
if (ent->resource_func ==
- BNXT_ULP_RESOURCE_FUNC_INVALID)
+ BNXT_ULP_RESOURCE_FUNC_INVALID ||
+ ent->shared)
continue;
memset(&res, 0, sizeof(struct ulp_flow_db_res_params));
res.resource_func = ent->resource_func;
parms.act_prop = cparms->act_prop;
parms.act_bitmap = cparms->act;
parms.hdr_bitmap = cparms->hdr_bitmap;
+ parms.enc_hdr_bitmap = cparms->enc_hdr_bitmap;
parms.regfile = ®file;
parms.hdr_field = cparms->hdr_field;
+ parms.enc_field = cparms->enc_field;
parms.fld_bitmap = cparms->fld_bitmap;
parms.comp_fld = cparms->comp_fld;
- parms.tfp = bnxt_ulp_cntxt_tfp_get(ulp_ctx);
parms.ulp_ctx = 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.child_flow = cparms->child_flow;
parms.fid = cparms->flow_id;
parms.tun_idx = cparms->tun_idx;
parms.app_priority = cparms->app_priority;
parms.flow_pattern_id = cparms->flow_pattern_id;
parms.act_pattern_id = cparms->act_pattern_id;
+ parms.app_id = cparms->app_id;
+ parms.port_id = cparms->port_id;
/* Get the device id from the ulp context */
if (bnxt_ulp_cntxt_dev_id_get(ulp_ctx, &parms.dev_id)) {
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)
if (!ulp_ctx)
return -EINVAL;
- tfp = bnxt_ulp_cntxt_tfp_get(ulp_ctx);
+ tfp = bnxt_ulp_cntxt_tfp_get(ulp_ctx, BNXT_ULP_SHARED_SESSION_NO);
if (!tfp)
return -EINVAL;
goto error;
}
+ /*
+ * Only initialize the app global resources if a shared session was
+ * created.
+ */
+ if (bnxt_ulp_cntxt_shared_session_enabled(ulp_ctx)) {
+ rc = ulp_mapper_app_glb_resource_info_init(ulp_ctx, data);
+ if (rc) {
+ BNXT_TF_DBG(ERR, "Failed to init app glb resources\n");
+ goto error;
+ }
+ }
+
/* Allocate the generic table list */
rc = ulp_mapper_generic_tbl_list_init(data);
if (rc) {
if (!ulp_ctx) {
BNXT_TF_DBG(ERR,
- "Failed to acquire ulp context, so data may "
- "not be released.\n");
+ "Failed to acquire ulp context, so data may not be released.\n");
return;
}
return;
}
- tfp = bnxt_ulp_cntxt_tfp_get(ulp_ctx);
+ tfp = bnxt_ulp_cntxt_tfp_get(ulp_ctx, BNXT_ULP_SHARED_SESSION_NO);
if (!tfp) {
BNXT_TF_DBG(ERR, "Failed to acquire tfp.\n");
/* Free the mapper data regardless of errors. */