#include "ulp_flow_db.h"
#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)
+{
+ switch (tmpl_type) {
+ case BNXT_ULP_TEMPLATE_TYPE_CLASS:
+ return "class";
+ case BNXT_ULP_TEMPLATE_TYPE_ACTION:
+ return "action";
+ default:
+ return "invalid template type";
+ }
+}
static struct bnxt_ulp_glb_resource_info *
ulp_mapper_glb_resource_info_list_get(uint32_t *num_entries)
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 ||
- dir >= TF_DIR_MAX || idx >= BNXT_ULP_GLB_REGFILE_INDEX_LAST)
+ 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;
/* validate the arguments */
if (!data || res->direction >= TF_DIR_MAX ||
- res->glb_regfile_index >= BNXT_ULP_GLB_REGFILE_INDEX_LAST)
+ res->glb_regfile_index >= BNXT_ULP_GLB_RF_IDX_LAST)
return -EINVAL;
/* write to the mapper data */
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;
/* 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 */
return rc;
}
-/* Retrieve the global template table */
-static uint32_t *
-ulp_mapper_glb_template_table_get(uint32_t *num_entries)
-{
- if (!num_entries)
- return NULL;
- *num_entries = BNXT_ULP_GLB_TEMPLATE_TBL_MAX_SZ;
- return ulp_glb_template_tbl;
-}
-
-static uint8_t *
-ulp_mapper_glb_field_tbl_get(uint32_t idx)
+static int32_t
+ulp_mapper_glb_field_tbl_get(struct bnxt_ulp_mapper_parms *parms,
+ uint32_t operand,
+ uint8_t *val)
{
- return &ulp_glb_field_tbl[idx];
+ uint32_t t_idx;
+
+ 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;
+
+ if (t_idx >= BNXT_ULP_GLB_FIELD_TBL_SIZE) {
+ BNXT_TF_DBG(ERR, "Invalid hdr field index %x:%x:%x\n",
+ parms->class_tid, t_idx, operand);
+ *val = 0;
+ return -EINVAL; /* error */
+ }
+ *val = ulp_glb_field_tbl[t_idx];
+ return 0;
}
/*
*
* Returns array of Key fields, or NULL on error.
*/
-static struct bnxt_ulp_mapper_key_field_info *
+static struct bnxt_ulp_mapper_key_info *
ulp_mapper_key_fields_get(struct bnxt_ulp_mapper_parms *mparms,
struct bnxt_ulp_mapper_tbl_info *tbl,
uint32_t *num_flds)
const struct bnxt_ulp_template_device_tbls *dev_tbls;
dev_tbls = &mparms->device_params->dev_tbls[mparms->tmpl_type];
- if (!dev_tbls->key_field_list) {
+ if (!dev_tbls->key_info_list) {
*num_flds = 0;
return NULL;
}
idx = tbl->key_start_idx;
*num_flds = tbl->key_num_fields;
- return &dev_tbls->key_field_list[idx];
+ return &dev_tbls->key_info_list[idx];
}
/*
*
* Returns array of data fields, or NULL on error.
*/
-static struct bnxt_ulp_mapper_result_field_info *
+static struct bnxt_ulp_mapper_field_info *
ulp_mapper_result_fields_get(struct bnxt_ulp_mapper_parms *mparms,
struct bnxt_ulp_mapper_tbl_info *tbl,
uint32_t *num_flds,
}
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);
}
int32_t rc;
fparms.dir = res->direction;
- if (res->resource_func == BNXT_ULP_RESOURCE_FUNC_EXT_EM_TABLE)
- fparms.mem = TF_MEM_EXTERNAL;
- else
- fparms.mem = TF_MEM_INTERNAL;
fparms.flow_handle = res->resource_hndl;
rc = bnxt_ulp_cntxt_tbl_scope_id_get(ulp, &fparms.tbl_scope_id);
return 0;
}
+/*
+ * Process the flow database opcode alloc action.
+ * returns 0 on success
+ */
+static int32_t
+ulp_mapper_fdb_opc_alloc_rid(struct bnxt_ulp_mapper_parms *parms,
+ struct bnxt_ulp_mapper_tbl_info *tbl)
+{
+ uint32_t rid = 0;
+ uint64_t val64;
+ int32_t rc = 0;
+
+ /* allocate a new fid */
+ rc = ulp_flow_db_fid_alloc(parms->ulp_ctx,
+ BNXT_ULP_FDB_TYPE_RID,
+ 0, &rid);
+ if (rc) {
+ BNXT_TF_DBG(ERR,
+ "Unable to allocate flow table entry\n");
+ return -EINVAL;
+ }
+ /* Store the allocated fid in regfile*/
+ val64 = rid;
+ rc = ulp_regfile_write(parms->regfile, tbl->fdb_operand,
+ tfp_cpu_to_be_64(val64));
+ if (rc) {
+ BNXT_TF_DBG(ERR, "Write regfile[%d] failed\n",
+ tbl->fdb_operand);
+ ulp_flow_db_fid_free(parms->ulp_ctx,
+ BNXT_ULP_FDB_TYPE_RID, rid);
+ return -EINVAL;
+ }
+ return 0;
+}
+
/*
* Process the flow database opcode action.
* returns 0 on success.
struct bnxt_ulp_mapper_tbl_info *tbl,
struct ulp_flow_db_res_params *fid_parms)
{
- uint32_t push_fid, fid = 0;
+ uint32_t push_fid;
uint64_t val64;
+ enum bnxt_ulp_fdb_type flow_type;
int32_t rc = 0;
switch (tbl->fdb_opcode) {
- case BNXT_ULP_FDB_OPC_PUSH:
+ case BNXT_ULP_FDB_OPC_PUSH_FID:
push_fid = parms->fid;
+ flow_type = parms->flow_type;
break;
- case BNXT_ULP_FDB_OPC_ALLOC_PUSH_REGFILE:
- /* allocate a new fid */
- rc = ulp_flow_db_fid_alloc(parms->ulp_ctx,
- parms->flow_type,
- tbl->resource_func, &fid);
- if (rc) {
- BNXT_TF_DBG(ERR,
- "Unable to allocate flow table entry\n");
- return rc;
- }
- /* Store the allocated fid in regfile*/
- val64 = fid;
- rc = ulp_regfile_write(parms->regfile, tbl->flow_db_operand,
- tfp_cpu_to_be_64(val64));
- if (!rc) {
- BNXT_TF_DBG(ERR, "Write regfile[%d] failed\n",
- tbl->flow_db_operand);
- rc = -EINVAL;
- goto error;
- }
- /* Use the allocated fid to update the flow resource */
- push_fid = fid;
- break;
- case BNXT_ULP_FDB_OPC_PUSH_REGFILE:
+ case BNXT_ULP_FDB_OPC_PUSH_RID_REGFILE:
/* get the fid from the regfile */
- rc = ulp_regfile_read(parms->regfile, tbl->flow_db_operand,
+ rc = ulp_regfile_read(parms->regfile, tbl->fdb_operand,
&val64);
if (!rc) {
BNXT_TF_DBG(ERR, "regfile[%d] read oob\n",
- tbl->flow_db_operand);
+ tbl->fdb_operand);
return -EINVAL;
}
/* Use the extracted fid to update the flow resource */
- push_fid = tfp_be_to_cpu_64((uint32_t)val64);
+ push_fid = (uint32_t)tfp_be_to_cpu_64(val64);
+ flow_type = BNXT_ULP_FDB_TYPE_RID;
break;
default:
return rc; /* Nothing to be done */
}
/* Add the resource to the flow database */
- rc = ulp_flow_db_resource_add(parms->ulp_ctx, parms->flow_type,
+ rc = ulp_flow_db_resource_add(parms->ulp_ctx, flow_type,
push_fid, fid_parms);
- if (rc) {
+ if (rc)
BNXT_TF_DBG(ERR, "Failed to add res to flow %x rc = %d\n",
push_fid, rc);
- goto error;
- }
- return rc;
-
-error:
- /* free the allocated fid */
- if (fid)
- ulp_flow_db_fid_free(parms->ulp_ctx,
- BNXT_ULP_FDB_TYPE_REGULAR, fid);
return rc;
}
byte_data_size);
return -EINVAL;
}
+ val64 = 0;
if (byte_order == BNXT_ULP_BYTE_ORDER_LE)
ulp_bs_pull_lsb(byte_data, (uint8_t *)&val64,
sizeof(val64),
idents[i].ident_bit_size);
/* Write it to the regfile, val64 is already in big-endian*/
- if (!ulp_regfile_write(parms->regfile,
- idents[i].regfile_idx,
- val64)) {
+ if (ulp_regfile_write(parms->regfile,
+ idents[i].regfile_idx, val64)) {
BNXT_TF_DBG(ERR, "Regfile[%d] write failed.\n",
idents[i].regfile_idx);
return -EINVAL;
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;
}
id = (uint64_t)tfp_cpu_to_be_64(iparms.id);
- if (!ulp_regfile_write(parms->regfile, idx, id)) {
+ if (ulp_regfile_write(parms->regfile, idx, id)) {
BNXT_TF_DBG(ERR, "Regfile[%d] write failed.\n", idx);
rc = -EINVAL;
/* Need to free the identifier, so goto error */
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;
/* Write it to the regfile */
id = (uint64_t)tfp_cpu_to_be_64(sparms.search_id);
- if (!ulp_regfile_write(parms->regfile, ident->regfile_idx, id)) {
+ if (ulp_regfile_write(parms->regfile, ident->regfile_idx, id)) {
BNXT_TF_DBG(ERR, "Regfile[%d] write failed.\n", idx);
rc = -EINVAL;
/* Need to free the identifier, so goto error */
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_result_field_process(struct bnxt_ulp_mapper_parms *parms,
- enum tf_dir dir,
- struct bnxt_ulp_mapper_result_field_info *fld,
- struct ulp_blob *blob,
- const char *name)
+ulp_mapper_field_port_db_process(struct bnxt_ulp_mapper_parms *parms,
+ uint32_t port_id,
+ uint16_t val16,
+ uint8_t **val)
{
- uint16_t idx, size_idx;
- uint8_t *val = NULL;
- uint16_t write_idx = blob->write_idx;
- uint64_t regval;
- uint32_t val_size = 0, field_size = 0;
- uint64_t act_bit;
- uint8_t act_val[16];
- uint64_t hdr_bit;
-
- switch (fld->result_opcode) {
- 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);
+ enum bnxt_ulp_port_table port_data = val16;
+
+ switch (port_data) {
+ case BNXT_ULP_PORT_TABLE_DRV_FUNC_PARENT_MAC:
+ if (ulp_port_db_parent_mac_addr_get(parms->ulp_ctx, port_id,
+ val)) {
+ BNXT_TF_DBG(ERR, "Invalid port id %u\n", port_id);
+ return -EINVAL;
+ }
+ break;
+ case BNXT_ULP_PORT_TABLE_DRV_FUNC_MAC:
+ if (ulp_port_db_drv_mac_addr_get(parms->ulp_ctx, port_id,
+ val)) {
+ BNXT_TF_DBG(ERR, "Invalid port id %u\n", port_id);
+ return -EINVAL;
+ }
+ break;
+ case BNXT_ULP_PORT_TABLE_DRV_FUNC_PARENT_VNIC:
+ if (ulp_port_db_parent_vnic_get(parms->ulp_ctx, port_id,
+ val)) {
+ BNXT_TF_DBG(ERR, "Invalid port id %u\n", port_id);
return -EINVAL;
}
break;
- case BNXT_ULP_MAPPER_OPC_SET_TO_ACT_PROP:
- if (!ulp_operand_read(fld->result_operand,
+ default:
+ BNXT_TF_DBG(ERR, "Invalid port_data %d\n", port_data);
+ return -EINVAL;
+ }
+ return 0;
+}
+
+static int32_t
+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 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 (field_src) {
+ case BNXT_ULP_FIELD_SRC_ZERO:
+ *val = mapper_fld_zeros;
+ break;
+ case BNXT_ULP_FIELD_SRC_CONST:
+ *val = field_opr;
+ break;
+ case BNXT_ULP_FIELD_SRC_ONES:
+ *val = mapper_fld_ones;
+ *value = 1;
+ break;
+ case BNXT_ULP_FIELD_SRC_CF:
+ 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_ACT_PROP_IDX_LAST) {
- BNXT_TF_DBG(ERR, "%s act_prop[%d] 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;
}
- val = &parms->act_prop->act_details[idx];
- field_size = ulp_mapper_act_prop_size_get(idx);
- if (fld->field_bit_size < ULP_BYTE_2_BITS(field_size)) {
- field_size = field_size -
- ((fld->field_bit_size + 7) / 8);
- val += field_size;
+ 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(field_opr,
+ (uint8_t *)&idx, sizeof(uint16_t))) {
+ BNXT_TF_DBG(ERR, "RF operand read failed\n");
+ return -EINVAL;
}
- if (!ulp_blob_push(blob, val, fld->field_bit_size)) {
- BNXT_TF_DBG(ERR, "%s push field failed\n", name);
+
+ idx = tfp_be_to_cpu_16(idx);
+ /* Uninitialized regfile entries return 0 */
+ 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;
}
+ 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_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);
+ case BNXT_ULP_FIELD_SRC_ACT_PROP:
+ if (!ulp_operand_read(field_opr,
+ (uint8_t *)&idx, sizeof(uint16_t))) {
+ BNXT_TF_DBG(ERR, "Action operand read failed\n");
return -EINVAL;
}
- act_bit = tfp_be_to_cpu_64(act_bit);
- memset(act_val, 0, sizeof(act_val));
- if (ULP_BITMAP_ISSET(parms->act_bitmap->bits, act_bit))
- act_val[0] = 1;
- if (fld->field_bit_size > ULP_BYTE_2_BITS(sizeof(act_val))) {
- BNXT_TF_DBG(ERR, "%s field size is incorrect\n", name);
+ idx = tfp_be_to_cpu_16(idx);
+ if (idx >= BNXT_ULP_ACT_PROP_IDX_LAST) {
+ BNXT_TF_DBG(ERR, "act_prop[%d] oob\n", idx);
return -EINVAL;
}
- if (!ulp_blob_push(blob, act_val, fld->field_bit_size)) {
- BNXT_TF_DBG(ERR, "%s push field failed\n", name);
+ buffer = &parms->act_prop->act_details[idx];
+ field_size = ulp_mapper_act_prop_size_get(idx);
+ if (bytelen > field_size) {
+ BNXT_TF_DBG(ERR, "act_prop[%d] field size small %u\n",
+ idx, field_size);
return -EINVAL;
}
- val = act_val;
+ *val = &buffer[field_size - bytelen];
break;
- case BNXT_ULP_MAPPER_OPC_SET_TO_ENCAP_ACT_PROP_SZ:
- if (!ulp_operand_read(fld->result_operand,
+ case BNXT_ULP_FIELD_SRC_ACT_PROP_SZ:
+ 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->result_operand[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_MAPPER_OPC_SET_TO_REGFILE:
- if (!ulp_operand_read(fld->result_operand,
+ case BNXT_ULP_FIELD_SRC_GLB_RF:
+ if (!ulp_operand_read(field_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;
- }
-
- val = ulp_blob_push_64(blob, ®val, fld->field_bit_size);
- if (!val) {
- BNXT_TF_DBG(ERR, "%s push field failed\n", name);
- return -EINVAL;
- }
- break;
- case BNXT_ULP_MAPPER_OPC_SET_TO_GLB_REGFILE:
- if (!ulp_operand_read(fld->result_operand,
- (uint8_t *)&idx,
- sizeof(uint16_t))) {
- BNXT_TF_DBG(ERR, "%s key operand read failed.\n", name);
+ 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 regfile[%d] read failed.\n",
- name, idx);
- return -EINVAL;
- }
- val = ulp_blob_push_64(blob, ®val, fld->field_bit_size);
- if (!val) {
- BNXT_TF_DBG(ERR, "%s push to key blob failed\n", name);
+ dir, idx, &lregval, &shared) ||
+ sizeof(uint64_t) < bytelen) {
+ BNXT_TF_DBG(ERR, "Global regfile[%d] read failed %u\n",
+ idx, bytelen);
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_MAPPER_OPC_SET_TO_COMP_FIELD:
- if (!ulp_operand_read(fld->result_operand,
- (uint8_t *)&idx,
- sizeof(uint16_t))) {
- BNXT_TF_DBG(ERR, "%s key operand read failed.\n", name);
+ case BNXT_ULP_FIELD_SRC_HF:
+ 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);
- if (idx < BNXT_ULP_CF_IDX_LAST)
- val = ulp_blob_push_32(blob, &parms->comp_fld[idx],
- fld->field_bit_size);
- if (!val) {
- BNXT_TF_DBG(ERR, "%s push to key blob failed\n", name);
- return -EINVAL;
- }
- break;
- 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);
+ /* 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 (is_key)
+ buffer = parms->hdr_field[bit].spec;
+ else
+ buffer = parms->hdr_field[bit].mask;
- break;
- case BNXT_ULP_MAPPER_OPC_IF_ACT_BIT_THEN_ACT_PROP_ELSE_CONST:
- if (!ulp_operand_read(fld->result_operand,
- (uint8_t *)&act_bit, sizeof(uint64_t))) {
- BNXT_TF_DBG(ERR, "%s operand read failed\n", name);
+ field_size = parms->hdr_field[bit].size;
+ if (bytelen > field_size) {
+ BNXT_TF_DBG(ERR, "Hdr field[%d] size small %u\n",
+ bit, field_size);
return -EINVAL;
}
- act_bit = tfp_be_to_cpu_64(act_bit);
- if (ULP_BITMAP_ISSET(parms->act_bitmap->bits, act_bit)) {
- /* Action bit is set so consider operand_true */
- if (!ulp_operand_read(fld->result_operand_true,
- (uint8_t *)&idx,
+ 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, "%s operand read failed\n",
- name);
- 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, "Hdr fld size read failed\n");
return -EINVAL;
}
- val = &parms->act_prop->act_details[idx];
- field_size = ulp_mapper_act_prop_size_get(idx);
- if (fld->field_bit_size < ULP_BYTE_2_BITS(field_size)) {
- field_size = field_size -
- ((fld->field_bit_size + 7) / 8);
- val += field_size;
- }
- if (!ulp_blob_push(blob, val, fld->field_bit_size)) {
- BNXT_TF_DBG(ERR, "%s push field failed\n",
- name);
+ 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(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->hdr_bitmap->bits, lregval)) {
+ *val = mapper_fld_one;
+ *value = 1;
} else {
- /* action bit is not set, use the operand false */
- val = fld->result_operand_false;
- if (!ulp_blob_push(blob, val, fld->field_bit_size)) {
- BNXT_TF_DBG(ERR, "%s failed to add field\n",
- name);
- return -EINVAL;
- }
+ *val = mapper_fld_zeros;
}
break;
- case BNXT_ULP_MAPPER_OPC_IF_ACT_BIT_THEN_CONST_ELSE_CONST:
- if (!ulp_operand_read(fld->result_operand,
- (uint8_t *)&act_bit, sizeof(uint64_t))) {
- BNXT_TF_DBG(ERR, "%s operand read failed\n", name);
+ case BNXT_ULP_FIELD_SRC_ACT_BIT:
+ if (!ulp_operand_read(field_opr,
+ (uint8_t *)&lregval, sizeof(uint64_t))) {
+ BNXT_TF_DBG(ERR, "Action bit read failed\n");
return -EINVAL;
}
- act_bit = tfp_be_to_cpu_64(act_bit);
- if (ULP_BITMAP_ISSET(parms->act_bitmap->bits, act_bit)) {
- /* Action bit is set so consider operand_true */
- val = fld->result_operand_true;
+ lregval = tfp_be_to_cpu_64(lregval);
+ if (ULP_BITMAP_ISSET(parms->act_bitmap->bits, lregval)) {
+ *val = mapper_fld_one;
+ *value = 1;
} else {
- /* action bit is not set, use the operand false */
- val = fld->result_operand_false;
+ *val = mapper_fld_zeros;
+ }
+ break;
+ case BNXT_ULP_FIELD_SRC_FIELD_BIT:
+ if (!ulp_operand_read(field_opr,
+ (uint8_t *)&idx, sizeof(uint16_t))) {
+ BNXT_TF_DBG(ERR, "Field bit read failed\n");
+ return -EINVAL;
}
- if (!ulp_blob_push(blob, val, fld->field_bit_size)) {
- BNXT_TF_DBG(ERR, "%s failed to add field\n",
- name);
+ 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 (ULP_INDEX_BITMAP_GET(parms->fld_bitmap->bits, bit)) {
+ *val = mapper_fld_one;
+ *value = 1;
+ } else {
+ *val = mapper_fld_zeros;
+ }
break;
- case BNXT_ULP_MAPPER_OPC_IF_COMP_FIELD_THEN_CF_ELSE_CF:
- if (!ulp_operand_read(fld->result_operand,
- (uint8_t *)&idx,
- sizeof(uint16_t))) {
- BNXT_TF_DBG(ERR, "%s key operand read failed.\n", name);
+ 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;
}
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);
+ if (ulp_mapper_field_port_db_process(parms, port_id, idx,
+ val)) {
+ BNXT_TF_DBG(ERR, "field port table failed\n");
return -EINVAL;
}
- /* check if the computed field is set */
- if (ULP_COMP_FLD_IDX_RD(parms, idx))
- val = fld->result_operand_true;
- else
- val = fld->result_operand_false;
+ case BNXT_ULP_FIELD_SRC_SKIP:
+ /* do nothing */
+ 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;
+}
- /* read the appropriate computed field */
- if (!ulp_operand_read(val, (uint8_t *)&idx, sizeof(uint16_t))) {
- BNXT_TF_DBG(ERR, "%s val operand read failed\n", name);
+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;
}
- 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);
+ } 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;
}
- val = ulp_blob_push_32(blob, &parms->comp_fld[idx],
- fld->field_bit_size);
- if (!val) {
- BNXT_TF_DBG(ERR, "%s push to key blob failed\n", name);
+ } else {
+ if (!ulp_blob_push(blob, val, val_len)) {
+ BNXT_TF_DBG(ERR, "push of val1 failed\n");
return -EINVAL;
}
+ }
+ *out_val = val;
+ return 0;
+}
+
+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_MAPPER_OPC_IF_HDR_BIT_THEN_CONST_ELSE_CONST:
- if (!ulp_operand_read(fld->result_operand,
- (uint8_t *)&hdr_bit, sizeof(uint64_t))) {
- BNXT_TF_DBG(ERR, "%s operand read failed\n", name);
- return -EINVAL;
+ 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;
}
- hdr_bit = tfp_be_to_cpu_64(hdr_bit);
- if (ULP_BITMAP_ISSET(parms->hdr_bitmap->bits, hdr_bit)) {
- /* Header bit is set so consider operand_true */
- val = fld->result_operand_true;
- } else {
- /* Header bit is not set, use the operand false */
- val = fld->result_operand_false;
+ 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;
+ }
}
- if (!ulp_blob_push(blob, val, fld->field_bit_size)) {
- BNXT_TF_DBG(ERR, "%s failed to add field\n",
- name);
- return -EINVAL;
+ }
+
+ /* 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
+ process_src3 = 1;
+ }
+
+ /* 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, "invalid result mapper opcode 0x%x at %d\n",
- fld->result_opcode, write_idx);
- return -EINVAL;
+ BNXT_TF_DBG(ERR, "Invalid fld opcode %u\n", fld->field_opc);
+ rc = -EINVAL;
+ break;
}
- return 0;
+
+ 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;
}
/*
struct ulp_blob *data,
const char *name)
{
- struct bnxt_ulp_mapper_result_field_info *dflds;
+ struct bnxt_ulp_mapper_field_info *dflds;
uint32_t i, num_flds = 0, encap_flds = 0;
int32_t rc = 0;
ulp_blob_encap_swap_idx_set(data);
/* Process the result fields */
- rc = ulp_mapper_result_field_process(parms, tbl->direction,
- &dflds[i], data, name);
+ rc = ulp_mapper_field_opc_process(parms, tbl->direction,
+ &dflds[i], data, 0, name);
if (rc) {
BNXT_TF_DBG(ERR, "data field failed\n");
return rc;
return rc;
}
-/* Function to alloc action record and set the table. */
static int32_t
-ulp_mapper_keymask_field_process(struct bnxt_ulp_mapper_parms *parms,
- enum tf_dir dir,
- struct bnxt_ulp_mapper_key_field_info *f,
- struct ulp_blob *blob,
- uint8_t is_key,
- const char *name)
+ulp_mapper_mark_gfid_process(struct bnxt_ulp_mapper_parms *parms,
+ struct bnxt_ulp_mapper_tbl_info *tbl,
+ uint64_t flow_id)
{
- uint64_t val64;
- uint16_t idx, bitlen;
- uint32_t opcode;
- uint8_t *operand;
- struct ulp_regfile *regfile = parms->regfile;
- uint8_t *val = NULL;
- struct bnxt_ulp_mapper_key_field_info *fld = f;
- uint32_t field_size;
-
- if (is_key) {
- operand = fld->spec_operand;
- opcode = fld->spec_opcode;
- } else {
- operand = fld->mask_operand;
- opcode = fld->mask_opcode;
- }
+ struct ulp_flow_db_res_params fid_parms;
+ uint32_t mark, gfid, mark_flag;
+ enum bnxt_ulp_mark_db_opc mark_op = tbl->mark_db_opcode;
+ int32_t rc = 0;
- bitlen = fld->field_bit_size;
+ if (mark_op == BNXT_ULP_MARK_DB_OPC_NOP ||
+ !(mark_op == BNXT_ULP_MARK_DB_OPC_PUSH_IF_MARK_ACTION &&
+ ULP_BITMAP_ISSET(parms->act_bitmap->bits,
+ BNXT_ULP_ACT_BIT_MARK)))
+ return rc; /* no need to perform gfid process */
- switch (opcode) {
- 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_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;
- }
+ /* 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);
- break;
- 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);
- return -EINVAL;
- }
- idx = tfp_be_to_cpu_16(idx);
- if (is_key)
- val = parms->hdr_field[idx].spec;
- else
- val = parms->hdr_field[idx].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[idx].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 key blob failed\n", name);
- return -EINVAL;
- }
- break;
- 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);
- return -EINVAL;
- }
- idx = tfp_be_to_cpu_16(idx);
- if (idx < BNXT_ULP_CF_IDX_LAST)
- val = ulp_blob_push_32(blob, &parms->comp_fld[idx],
- bitlen);
- if (!val) {
- BNXT_TF_DBG(ERR, "%s push to key blob failed\n", name);
- return -EINVAL;
- }
- break;
- 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);
- return -EINVAL;
- }
- idx = tfp_be_to_cpu_16(idx);
-
- if (!ulp_regfile_read(regfile, idx, &val64)) {
- BNXT_TF_DBG(ERR, "%s regfile[%d] read failed.\n",
- name, idx);
- return -EINVAL;
- }
-
- val = ulp_blob_push_64(blob, &val64, bitlen);
- if (!val) {
- BNXT_TF_DBG(ERR, "%s push to key blob failed\n", name);
- return -EINVAL;
- }
- break;
- 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);
- return -EINVAL;
- }
- idx = tfp_be_to_cpu_16(idx);
- if (ulp_mapper_glb_resource_read(parms->mapper_data,
- dir,
- idx, &val64)) {
- BNXT_TF_DBG(ERR, "%s regfile[%d] read failed.\n",
- name, idx);
- return -EINVAL;
- }
- val = ulp_blob_push_64(blob, &val64, bitlen);
- if (!val) {
- BNXT_TF_DBG(ERR, "%s push to key blob failed\n", name);
- return -EINVAL;
- }
- break;
- default:
- BNXT_TF_DBG(ERR, "invalid keymask mapper opcode 0x%x\n",
- opcode);
- return -EINVAL;
- }
- return 0;
-}
-
-static int32_t
-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;
- uint32_t mark, gfid, mark_flag;
- enum bnxt_ulp_mark_db_opc mark_op = tbl->mark_db_opcode;
- int32_t rc = 0;
-
- if (mark_op == BNXT_ULP_MARK_DB_OPC_NOP ||
- !(mark_op == BNXT_ULP_MARK_DB_OPC_PUSH_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;
+ 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);
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);
if (mark_op == BNXT_ULP_MARK_DB_OPC_NOP ||
!(mark_op == BNXT_ULP_MARK_DB_OPC_PUSH_IF_MARK_ACTION &&
ULP_BITMAP_ISSET(parms->act_bitmap->bits,
- BNXT_ULP_ACTION_BIT_MARK)))
+ BNXT_ULP_ACT_BIT_MARK)))
return rc; /* no need to perform mark action process */
/* Get the mark id details from action property */
mark = tfp_be_to_cpu_32(mark);
if (!ulp_regfile_read(parms->regfile,
- BNXT_ULP_REGFILE_INDEX_MAIN_ACTION_PTR,
+ BNXT_ULP_RF_IDX_MAIN_ACTION_PTR,
&val64)) {
BNXT_TF_DBG(ERR, "read action ptr main failed\n");
return -EINVAL;
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);
/* Get the main action pointer */
if (!ulp_regfile_read(parms->regfile,
- BNXT_ULP_REGFILE_INDEX_MAIN_ACTION_PTR,
+ BNXT_ULP_RF_IDX_MAIN_ACTION_PTR,
&val64)) {
BNXT_TF_DBG(ERR, "read action ptr main failed\n");
return -EINVAL;
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;
sparms.dir = tbl->direction;
sparms.tcam_tbl_type = tbl->resource_type;
sparms.idx = idx;
- /* Already verified the key/mask lengths */
sparms.key = ulp_blob_data_get(key, &tmplen);
sparms.key_sz_in_bits = tmplen;
sparms.mask = ulp_blob_data_get(mask, &tmplen);
sparms.result = ulp_blob_data_get(data, &tmplen);
-
- if (tbl->result_bit_size != tmplen) {
- BNXT_TF_DBG(ERR, "Result len (%d) != Expected (%d)\n",
- tmplen, tbl->result_bit_size);
- return -EINVAL;
- }
- sparms.result_sz_in_bits = tbl->result_bit_size;
+ sparms.result_sz_in_bits = tmplen;
if (tf_set_tcam_entry(tfp, &sparms)) {
BNXT_TF_DBG(ERR, "tcam[%s][%s][%x] write failed.\n",
tf_tcam_tbl_2_str(sparms.tcam_tbl_type),
return rc;
}
-#define BNXT_ULP_WC_TCAM_SLICE_SIZE 80
+/*
+ * internal function to post process key/mask blobs for dynamic pad WC tcam tbl
+ *
+ * parms [in] The mappers parms with data related to the flow.
+ *
+ * key [in] The original key to be transformed
+ *
+ * mask [in] The original mask to be transformed
+ *
+ * tkey [in/out] The transformed key
+ *
+ * tmask [in/out] The transformed mask
+ *
+ * returns zero on success, non-zero on failure
+ */
+static uint32_t
+ulp_mapper_wc_tcam_tbl_dyn_post_process(struct bnxt_ulp_device_params *dparms,
+ struct ulp_blob *key,
+ struct ulp_blob *mask,
+ struct ulp_blob *tkey,
+ struct ulp_blob *tmask)
+{
+ uint16_t tlen, blen, clen, slice_width, num_slices, max_slices, offset;
+ uint32_t cword, i, rc;
+ int32_t pad;
+ uint8_t *val;
+
+ slice_width = dparms->wc_slice_width;
+ clen = dparms->wc_ctl_size_bits;
+ max_slices = dparms->wc_max_slices;
+ blen = ulp_blob_data_len_get(key);
+
+ /* Get the length of the key based on number of slices and width */
+ num_slices = 1;
+ tlen = slice_width;
+ while (tlen < blen &&
+ num_slices <= max_slices) {
+ num_slices = num_slices << 1;
+ tlen = tlen << 1;
+ }
+
+ if (num_slices > max_slices) {
+ BNXT_TF_DBG(ERR, "Key size (%d) too large for WC\n", blen);
+ return -EINVAL;
+ }
+
+ /* The key/mask may not be on a natural slice boundary, pad it */
+ pad = tlen - blen;
+ if (ulp_blob_pad_push(key, pad) < 0 ||
+ ulp_blob_pad_push(mask, pad) < 0) {
+ BNXT_TF_DBG(ERR, "Unable to pad key/mask\n");
+ return -EINVAL;
+ }
+
+ /* The new length accounts for the ctrl word length and num slices */
+ tlen = tlen + clen * num_slices;
+ if (!ulp_blob_init(tkey, tlen, key->byte_order) ||
+ !ulp_blob_init(tmask, tlen, mask->byte_order)) {
+ BNXT_TF_DBG(ERR, "Unable to post process wc tcam entry\n");
+ return -EINVAL;
+ }
+
+ /* Build the transformed key/mask */
+ cword = dparms->wc_mode_list[num_slices - 1];
+ cword = tfp_cpu_to_be_32(cword);
+ offset = 0;
+ for (i = 0; i < num_slices; i++) {
+ val = ulp_blob_push_32(tkey, &cword, clen);
+ if (!val) {
+ BNXT_TF_DBG(ERR, "Key ctrl word push failed\n");
+ return -EINVAL;
+ }
+ val = ulp_blob_push_32(tmask, &cword, clen);
+ if (!val) {
+ BNXT_TF_DBG(ERR, "Mask ctrl word push failed\n");
+ return -EINVAL;
+ }
+ rc = ulp_blob_append(tkey, key, offset, slice_width);
+ if (rc) {
+ BNXT_TF_DBG(ERR, "Key blob append failed\n");
+ return rc;
+ }
+ rc = ulp_blob_append(tmask, mask, offset, slice_width);
+ if (rc) {
+ BNXT_TF_DBG(ERR, "Mask blob append failed\n");
+ return rc;
+ }
+ offset += slice_width;
+ }
+
+ /* The key/mask are byte reversed on every 4 byte chunk */
+ ulp_blob_perform_byte_reverse(tkey, 4);
+ ulp_blob_perform_byte_reverse(tmask, 4);
+
+ return 0;
+}
+
/* internal function to post process the key/mask blobs for wildcard tcam tbl */
-static void ulp_mapper_wc_tcam_tbl_post_process(struct ulp_blob *blob,
- uint32_t len)
+static void ulp_mapper_wc_tcam_tbl_post_process(struct ulp_blob *blob)
{
- uint8_t mode[2] = {0x0, 0x0};
- uint32_t mode_len = len / BNXT_ULP_WC_TCAM_SLICE_SIZE;
- uint32_t size, idx;
-
- /* Add the mode bits to the key and mask*/
- if (mode_len == 2)
- mode[1] = 2;
- else if (mode_len > 2)
- mode[1] = 3;
-
- size = BNXT_ULP_WC_TCAM_SLICE_SIZE + ULP_BYTE_2_BITS(sizeof(mode));
- for (idx = 0; idx < mode_len; idx++)
- ulp_blob_insert(blob, (size * idx), mode,
- ULP_BYTE_2_BITS(sizeof(mode)));
ulp_blob_perform_64B_word_swap(blob);
ulp_blob_perform_64B_byte_swap(blob);
}
ulp_mapper_tcam_tbl_process(struct bnxt_ulp_mapper_parms *parms,
struct bnxt_ulp_mapper_tbl_info *tbl)
{
- struct bnxt_ulp_mapper_key_field_info *kflds;
- struct ulp_blob key, mask, data, update_data;
+ struct bnxt_ulp_mapper_key_info *kflds;
+ struct ulp_blob okey, omask, data, update_data;
+ struct ulp_blob tkey, tmask; /* transform key and mask */
+ struct ulp_blob *key, *mask;
uint32_t i, num_kflds;
struct tf *tfp;
int32_t rc, trc;
+ struct bnxt_ulp_device_params *dparms = parms->device_params;
struct tf_alloc_tcam_entry_parms aparms = { 0 };
struct tf_search_tcam_entry_parms searchparms = { 0 };
struct ulp_flow_db_res_params fid_parms = { 0 };
uint16_t tmplen = 0;
uint16_t idx;
+ /* Set the key and mask to the original key and mask. */
+ key = &okey;
+ mask = &omask;
+
/* Skip this if table opcode is NOP */
if (tbl->tbl_opcode == BNXT_ULP_TCAM_TBL_OPC_NOT_USED ||
tbl->tbl_opcode >= BNXT_ULP_TCAM_TBL_OPC_LAST) {
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;
return -EINVAL;
}
- if (!ulp_blob_init(&key, tbl->blob_key_bit_size,
- parms->device_params->byte_order) ||
- !ulp_blob_init(&mask, tbl->blob_key_bit_size,
- parms->device_params->byte_order) ||
- !ulp_blob_init(&data, tbl->result_bit_size,
- parms->device_params->byte_order) ||
+ 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) ||
!ulp_blob_init(&update_data, tbl->result_bit_size,
- parms->device_params->byte_order)) {
+ dparms->byte_order)) {
BNXT_TF_DBG(ERR, "blob inits failed.\n");
return -EINVAL;
}
- if (tbl->resource_type == TF_TCAM_TBL_TYPE_WC_TCAM) {
- key.byte_order = BNXT_ULP_BYTE_ORDER_BE;
- mask.byte_order = BNXT_ULP_BYTE_ORDER_BE;
- }
-
/* create the key/mask */
/*
* NOTE: The WC table will require some kind of flag to handle the
*/
for (i = 0; i < num_kflds; i++) {
/* Setup the key */
- rc = ulp_mapper_keymask_field_process(parms, tbl->direction,
- &kflds[i],
- &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.\n");
+ BNXT_TF_DBG(ERR, "Key field set failed %s\n",
+ kflds[i].field_info_spec.description);
return rc;
}
/* Setup the mask */
- rc = ulp_mapper_keymask_field_process(parms, tbl->direction,
- &kflds[i],
- &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.\n");
+ BNXT_TF_DBG(ERR, "Mask field set failed %s\n",
+ kflds[i].field_info_mask.description);
return rc;
}
}
/* For wild card tcam perform the post process to swap the blob */
- if (tbl->resource_type == TF_TCAM_TBL_TYPE_WC_TCAM) {
- ulp_mapper_wc_tcam_tbl_post_process(&key, tbl->key_bit_size);
- ulp_mapper_wc_tcam_tbl_post_process(&mask, tbl->key_bit_size);
+ if (tbl->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) {
+ 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,
+ key, mask,
+ &tkey,
+ &tmask);
+ if (rc) {
+ BNXT_TF_DBG(ERR,
+ "Failed to post proc WC entry.\n");
+ return rc;
+ }
+ /* Now need to use the transform Key/Mask */
+ key = &tkey;
+ mask = &tmask;
+ } else {
+ ulp_mapper_wc_tcam_tbl_post_process(key);
+ ulp_mapper_wc_tcam_tbl_post_process(mask);
+ }
+
}
if (tbl->tbl_opcode == BNXT_ULP_TCAM_TBL_OPC_ALLOC_WR_REGFILE) {
/* allocate the tcam index */
aparms.dir = tbl->direction;
aparms.tcam_tbl_type = tbl->resource_type;
- aparms.key = ulp_blob_data_get(&key, &tmplen);
+ aparms.key = ulp_blob_data_get(key, &tmplen);
aparms.key_sz_in_bits = tmplen;
- if (tbl->blob_key_bit_size != tmplen) {
- BNXT_TF_DBG(ERR, "Key len (%d) != Expected (%d)\n",
- tmplen, tbl->blob_key_bit_size);
- return -EINVAL;
- }
-
- aparms.mask = ulp_blob_data_get(&mask, &tmplen);
- if (tbl->blob_key_bit_size != tmplen) {
- BNXT_TF_DBG(ERR, "Mask len (%d) != Expected (%d)\n",
- tmplen, tbl->blob_key_bit_size);
- return -EINVAL;
- }
+ aparms.mask = ulp_blob_data_get(mask, &tmplen);
/* calculate the entry priority */
rc = ulp_mapper_priority_opc_process(parms, tbl,
*/
searchparms.dir = tbl->direction;
searchparms.tcam_tbl_type = tbl->resource_type;
- searchparms.key = ulp_blob_data_get(&key, &tmplen);
+ searchparms.key = ulp_blob_data_get(key, &tmplen);
searchparms.key_sz_in_bits = tbl->key_bit_size;
- searchparms.mask = ulp_blob_data_get(&mask, &tmplen);
+ searchparms.mask = ulp_blob_data_get(mask, &tmplen);
searchparms.alloc = 1;
searchparms.result = ulp_blob_data_get(&data, &tmplen);
searchparms.result_sz_in_bits = tbl->result_bit_size;
}
/* Write the tcam index into the regfile*/
- if (!ulp_regfile_write(parms->regfile, tbl->tbl_operand,
- (uint64_t)tfp_cpu_to_be_64(idx))) {
+ if (ulp_regfile_write(parms->regfile, tbl->tbl_operand,
+ (uint64_t)tfp_cpu_to_be_64(idx))) {
BNXT_TF_DBG(ERR, "Regfile[%d] write failed.\n",
tbl->tbl_operand);
rc = -EINVAL;
"TCAM Result");
/* write the tcam entry */
if (!rc)
- rc = ulp_mapper_tcam_tbl_entry_write(parms, tbl, &key,
- &mask, &data, idx);
+ rc = ulp_mapper_tcam_tbl_entry_write(parms, tbl, key,
+ mask, &data, idx);
} else {
/*Scan identifier list, extract identifier and update regfile*/
rc = ulp_mapper_tcam_tbl_scan_ident_extract(parms, tbl, &data);
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",
ulp_mapper_em_tbl_process(struct bnxt_ulp_mapper_parms *parms,
struct bnxt_ulp_mapper_tbl_info *tbl)
{
- struct bnxt_ulp_mapper_key_field_info *kflds;
+ struct bnxt_ulp_mapper_key_info *kflds;
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 };
enum bnxt_ulp_flow_mem_type mtype;
+ struct bnxt_ulp_device_params *dparms = parms->device_params;
int32_t trc;
int32_t rc = 0;
+ int32_t pad = 0;
+ 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");
/* Initialize the key/result blobs */
if (!ulp_blob_init(&key, tbl->blob_key_bit_size,
- parms->device_params->byte_order) ||
+ tbl->byte_order) ||
!ulp_blob_init(&data, tbl->result_bit_size,
- parms->device_params->byte_order)) {
+ tbl->byte_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_keymask_field_process(parms, tbl->direction,
- &kflds[i],
- &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;
}
}
- /*
- * TBD: Normally should process identifiers in case of using recycle or
- * loopback. Not supporting recycle for now.
- */
+ /* if dynamic padding is enabled then add padding to result data */
+ if (dparms->dynamic_pad_en) {
+ /* add padding to make sure key is at byte boundary */
+ ulp_blob_pad_align(&key, ULP_BUFFER_ALIGN_8_BITS);
+
+ /* add the pad */
+ pad = dparms->em_blk_align_bits - dparms->em_blk_size_bits;
+ if (pad < 0) {
+ BNXT_TF_DBG(ERR, "Invalid em blk size and align\n");
+ return -EINVAL;
+ }
+ ulp_blob_pad_push(&data, (uint32_t)pad);
+ }
/* Create the result data blob */
rc = ulp_mapper_tbl_result_build(parms, tbl, &data, "EM Result");
BNXT_TF_DBG(ERR, "Failed to build the result blob\n");
return rc;
}
+ if (dparms->dynamic_pad_en) {
+ uint32_t abits = dparms->em_blk_align_bits;
+
+ /* when dynamic padding is enabled merge result + key */
+ rc = ulp_blob_block_merge(&data, &key, abits, pad);
+ if (rc) {
+ BNXT_TF_DBG(ERR, "Failed to merge the result blob\n");
+ return rc;
+ }
+
+ /* add padding to make sure merged result is at slice boundary*/
+ ulp_blob_pad_align(&data, abits);
+
+ ulp_blob_perform_byte_reverse(&data, ULP_BITS_2_BYTE(abits));
+ }
+
/* do the transpose for the internal EM keys */
- if (tbl->resource_func == BNXT_ULP_RESOURCE_FUNC_INT_EM_TABLE)
- ulp_blob_perform_byte_reverse(&key);
+ if (tbl->resource_type == TF_MEM_INTERNAL) {
+ if (dparms->em_key_align_bytes) {
+ int32_t b = ULP_BYTE_2_BITS(dparms->em_key_align_bytes);
+
+ tmplen = ulp_blob_data_len_get(&key);
+ ulp_blob_pad_push(&key, b - tmplen);
+ }
+ tmplen = ulp_blob_data_len_get(&key);
+ ulp_blob_perform_byte_reverse(&key, ULP_BITS_2_BYTE(tmplen));
+ }
rc = bnxt_ulp_cntxt_tbl_scope_id_get(parms->ulp_ctx,
&iparms.tbl_scope_id);
iparms.key = ulp_blob_data_get(&key, &tmplen);
iparms.key_sz_in_bits = tbl->key_bit_size;
iparms.em_record = ulp_blob_data_get(&data, &tmplen);
- iparms.em_record_sz_in_bits = tbl->result_bit_size;
+ if (tbl->result_bit_size)
+ iparms.em_record_sz_in_bits = tbl->result_bit_size;
+ else
+ iparms.em_record_sz_in_bits = tmplen;
rc = tf_insert_em_entry(tfp, &iparms);
if (rc) {
struct ulp_blob data;
uint64_t regval = 0;
uint16_t tmplen;
- uint32_t index, hit;
+ uint32_t index;
int32_t rc = 0, trc = 0;
struct tf_alloc_tbl_entry_parms aparms = { 0 };
- struct tf_search_tbl_entry_parms srchparms = { 0 };
struct tf_set_tbl_entry_parms sparms = { 0 };
struct tf_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 tf *tfp;
+ struct bnxt_ulp_glb_resource_info glb_res = { 0 };
uint16_t bit_size;
bool alloc = false;
bool write = false;
- bool search = false;
+ bool global = false;
+ uint64_t act_rec_size;
+ bool shared = false;
+ tfp = bnxt_ulp_cntxt_tfp_get(parms->ulp_ctx, tbl->shared_session);
/* use the max size if encap is enabled */
if (tbl->encap_num_fields)
bit_size = BNXT_ULP_FLMP_BLOB_SIZE_IN_BITS;
alloc = true;
write = true;
break;
- case BNXT_ULP_INDEX_TBL_OPC_SRCH_ALLOC_WR_REGFILE:
- if (tbl->resource_type == TF_TBL_TYPE_EXT) {
- /* Not currently supporting with EXT */
- BNXT_TF_DBG(ERR,
- "Ext Table Search Opcode not supported.\n");
- return -EINVAL;
- }
- /*
- * Search for the entry in the tf core. If it is hit, save the
- * index in the regfile. If it is a miss, Build the entry,
- * alloc an index, write the table, and store the data in the
- * regfile (same as ALLOC_WR).
- */
- search = true;
- break;
case BNXT_ULP_INDEX_TBL_OPC_WR_REGFILE:
/*
* get the index to write to from the regfile and then write
write = true;
break;
+ case BNXT_ULP_INDEX_TBL_OPC_ALLOC_WR_GLB_REGFILE:
+ /*
+ * Build the entry, alloc an index, write the table, and store
+ * the data in the global regfile.
+ */
+ alloc = true;
+ global = true;
+ write = true;
+ glb_res.direction = tbl->direction;
+ glb_res.resource_func = tbl->resource_func;
+ glb_res.resource_type = tbl->resource_type;
+ glb_res.glb_regfile_index = tbl->tbl_operand;
+ break;
case BNXT_ULP_INDEX_TBL_OPC_WR_GLB_REGFILE:
+ if (tbl->fdb_opcode != BNXT_ULP_FDB_OPC_NOP) {
+ BNXT_TF_DBG(ERR, "Template error, wrong fdb opcode\n");
+ return -EINVAL;
+ }
/*
* get the index to write to from the global regfile and then
* write the table.
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.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;
return -EINVAL;
}
- if (write || search) {
+ if (write) {
/* Get the result fields list */
rc = ulp_mapper_tbl_result_build(parms,
tbl,
}
}
- if (search) {
- /* Use the result blob to perform a search */
- memset(&srchparms, 0, sizeof(srchparms));
- srchparms.dir = tbl->direction;
- srchparms.type = tbl->resource_type;
- srchparms.alloc = 1;
- srchparms.result = ulp_blob_data_get(&data, &tmplen);
- srchparms.result_sz_in_bytes = ULP_BITS_2_BYTE(tmplen);
- srchparms.tbl_scope_id = tbl_scope_id;
- rc = tf_search_tbl_entry(tfp, &srchparms);
- if (rc) {
- BNXT_TF_DBG(ERR, "Alloc table[%s][%s] failed rc=%d\n",
- tf_tbl_type_2_str(tbl->resource_type),
- tf_dir_2_str(tbl->direction), rc);
- return rc;
- }
- if (srchparms.search_status == REJECT) {
- BNXT_TF_DBG(ERR, "Alloc table[%s][%s] rejected.\n",
- tf_tbl_type_2_str(tbl->resource_type),
- tf_dir_2_str(tbl->direction));
- return -ENOMEM;
- }
- index = srchparms.idx;
- hit = srchparms.hit;
- if (hit)
- write = false;
- else
- write = true;
- }
-
if (alloc) {
aparms.dir = tbl->direction;
aparms.type = tbl->resource_type;
return rc;
}
index = aparms.idx;
- }
- if (search || alloc) {
/*
* Store the index in the regfile since we either allocated it
* or it was a hit.
regval = TF_ACT_REC_OFFSET_2_PTR(index);
else
regval = index;
+ regval = tfp_cpu_to_be_64(regval);
- rc = ulp_regfile_write(parms->regfile,
- tbl->tbl_operand,
- tfp_cpu_to_be_64(regval));
- if (!rc) {
- BNXT_TF_DBG(ERR, "Failed to write regfile[%d] rc=%d\n",
+ 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,
+ false);
+ } else {
+ rc = ulp_regfile_write(parms->regfile,
+ tbl->tbl_operand, regval);
+ }
+ if (rc) {
+ BNXT_TF_DBG(ERR,
+ "Failed to write %s regfile[%d] rc=%d\n",
+ (global) ? "global" : "reg",
tbl->tbl_operand, rc);
goto error;
}
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;
}
+
+ /* Calculate action record size */
+ if (tbl->resource_type == TF_TBL_TYPE_EXT) {
+ act_rec_size = (ULP_BITS_2_BYTE_NR(tmplen) + 15) / 16;
+ act_rec_size--;
+ if (ulp_regfile_write(parms->regfile,
+ BNXT_ULP_RF_IDX_ACTION_REC_SIZE,
+ tfp_cpu_to_be_64(act_rec_size)))
+ BNXT_TF_DBG(ERR,
+ "Failed write the act rec size\n");
+ }
}
/* Link the resource to the flow in the flow db */
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
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)) {
ulp_mapper_gen_tbl_process(struct bnxt_ulp_mapper_parms *parms,
struct bnxt_ulp_mapper_tbl_info *tbl)
{
- struct bnxt_ulp_mapper_key_field_info *kflds;
+ struct ulp_mapper_gen_tbl_list *gen_tbl_list;
+ struct bnxt_ulp_mapper_key_info *kflds;
struct ulp_flow_db_res_params fid_parms;
struct ulp_mapper_gen_tbl_entry gen_tbl_ent, *g;
- uint16_t tmplen;
+ struct ulp_gen_hash_entry_params hash_entry;
+ uint16_t tmplen = 0;
struct ulp_blob key, data;
uint8_t *cache_key;
int32_t tbl_idx;
- uint32_t i, ckey, num_kflds = 0;
- uint32_t gen_tbl_hit = 0, fdb_write = 0;
+ uint32_t i, num_kflds = 0, key_index = 0;
+ uint32_t gen_tbl_miss = 1, fdb_write = 0;
uint8_t *byte_data;
int32_t rc = 0;
BNXT_TF_DBG(ERR, "Failed to get key fields\n");
return -EINVAL;
}
+
if (!ulp_blob_init(&key, tbl->key_bit_size,
parms->device_params->byte_order)) {
BNXT_TF_DBG(ERR, "Failed to alloc blob\n");
}
for (i = 0; i < num_kflds; i++) {
/* Setup the key */
- rc = ulp_mapper_keymask_field_process(parms, tbl->direction,
- &kflds[i],
- &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",
/* The_key is a byte array convert it to a search index */
cache_key = ulp_blob_data_get(&key, &tmplen);
- memcpy(&ckey, cache_key, sizeof(ckey));
- /* Get the generic table entry */
- rc = ulp_mapper_gen_tbl_entry_get(parms->ulp_ctx,
- tbl_idx, ckey, &gen_tbl_ent);
- if (rc) {
- BNXT_TF_DBG(ERR,
- "Failed to create key for Gen tbl rc=%d\n", rc);
- return -EINVAL;
+ /* get the generic table */
+ gen_tbl_list = &parms->mapper_data->gen_tbl_list[tbl_idx];
+
+ /* Check if generic hash table */
+ if (gen_tbl_list->hash_tbl) {
+ if (tbl->gen_tbl_lkup_type !=
+ BNXT_ULP_GENERIC_TBL_LKUP_TYPE_HASH) {
+ BNXT_TF_DBG(ERR, "%s: Invalid template lkup type\n",
+ gen_tbl_list->gen_tbl_name);
+ return -EINVAL;
+ }
+ hash_entry.key_data = cache_key;
+ hash_entry.key_length = ULP_BITS_2_BYTE(tmplen);
+ rc = ulp_gen_hash_tbl_list_key_search(gen_tbl_list->hash_tbl,
+ &hash_entry);
+ if (rc) {
+ BNXT_TF_DBG(ERR, "%s: hash tbl search failed\n",
+ gen_tbl_list->gen_tbl_name);
+ return rc;
+ }
+ if (hash_entry.search_flag == ULP_GEN_HASH_SEARCH_FOUND) {
+ key_index = hash_entry.key_idx;
+ /* Get the generic table entry */
+ if (ulp_mapper_gen_tbl_entry_get(gen_tbl_list,
+ key_index,
+ &gen_tbl_ent))
+ return -EINVAL;
+ /* store the hash index in the fdb */
+ key_index = hash_entry.hash_index;
+ }
+ } 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,
+ &gen_tbl_ent))
+ return -EINVAL;
}
switch (tbl->tbl_opcode) {
case BNXT_ULP_GENERIC_TBL_OPC_READ:
+ if (gen_tbl_list->hash_tbl) {
+ if (hash_entry.search_flag != ULP_GEN_HASH_SEARCH_FOUND)
+ break; /* nothing to be done , no entry */
+ }
+
/* check the reference count */
if (ULP_GEN_TBL_REF_CNT(&gen_tbl_ent)) {
g = &gen_tbl_ent;
"Failed to scan ident list\n");
return -EINVAL;
}
- /* increment the reference count */
- ULP_GEN_TBL_REF_CNT_INC(&gen_tbl_ent);
+ if (tbl->fdb_opcode != BNXT_ULP_FDB_OPC_NOP) {
+ /* increment the reference count */
+ ULP_GEN_TBL_REF_CNT_INC(&gen_tbl_ent);
+ }
/* it is a hit */
- gen_tbl_hit = 1;
+ gen_tbl_miss = 0;
fdb_write = 1;
}
break;
case BNXT_ULP_GENERIC_TBL_OPC_WRITE:
+ if (gen_tbl_list->hash_tbl) {
+ rc = ulp_mapper_gen_tbl_hash_entry_add(gen_tbl_list,
+ &hash_entry,
+ &gen_tbl_ent);
+ if (rc)
+ return rc;
+ /* store the hash index in the fdb */
+ key_index = hash_entry.hash_index;
+ }
/* check the reference count */
if (ULP_GEN_TBL_REF_CNT(&gen_tbl_ent)) {
/* a hit then error */
- BNXT_TF_DBG(ERR, "generic entry already present %x\n",
- ckey);
+ BNXT_TF_DBG(ERR, "generic entry already present\n");
return -EINVAL; /* success */
}
/* Initialize the blob data */
if (!ulp_blob_init(&data, tbl->result_bit_size,
- BNXT_ULP_BYTE_ORDER_BE)) {
+ gen_tbl_ent.byte_order)) {
BNXT_TF_DBG(ERR, "Failed initial index table blob\n");
return -EINVAL;
}
return rc;
}
byte_data = ulp_blob_data_get(&data, &tmplen);
- rc = ulp_mapper_gen_tbl_entry_data_set(&gen_tbl_ent, 0,
+ rc = ulp_mapper_gen_tbl_entry_data_set(&gen_tbl_ent,
tmplen, byte_data,
ULP_BITS_2_BYTE(tmplen));
if (rc) {
/* increment the reference count */
ULP_GEN_TBL_REF_CNT_INC(&gen_tbl_ent);
fdb_write = 1;
+ parms->shared_hndl = (uint64_t)tbl_idx << 32 | key_index;
break;
default:
BNXT_TF_DBG(ERR, "Invalid table opcode %x\n", tbl->tbl_opcode);
/* Set the generic entry hit */
rc = ulp_regfile_write(parms->regfile,
- BNXT_ULP_REGFILE_INDEX_GENERIC_TBL_HIT,
- tfp_cpu_to_be_64(gen_tbl_hit));
- if (!rc) {
+ BNXT_ULP_RF_IDX_GENERIC_TBL_MISS,
+ tfp_cpu_to_be_64(gen_tbl_miss));
+ if (rc) {
BNXT_TF_DBG(ERR, "Write regfile[%d] failed\n",
- BNXT_ULP_REGFILE_INDEX_GENERIC_TBL_HIT);
+ BNXT_ULP_RF_IDX_GENERIC_TBL_MISS);
return -EIO;
}
fid_parms.direction = tbl->direction;
fid_parms.resource_func = tbl->resource_func;
fid_parms.resource_sub_type = tbl->resource_sub_type;
- fid_parms.resource_hndl = ckey;
+ 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);
return rc;
}
+static int32_t
+ulp_mapper_ctrl_tbl_process(struct bnxt_ulp_mapper_parms *parms,
+ struct bnxt_ulp_mapper_tbl_info *tbl)
+{
+ int32_t rc = 0;
+
+ /* process the fdb opcode for alloc push */
+ if (tbl->fdb_opcode == BNXT_ULP_FDB_OPC_ALLOC_RID_REGFILE) {
+ rc = ulp_mapper_fdb_opc_alloc_rid(parms, tbl);
+ if (rc) {
+ BNXT_TF_DBG(ERR, "Failed to do fdb alloc\n");
+ return rc;
+ }
+ }
+ return rc;
+}
+
static int32_t
ulp_mapper_glb_resource_info_init(struct bnxt_ulp_context *ulp_ctx,
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;
- bnxt_ulp_cntxt_mem_type_get(parms->ulp_ctx, &mtype);
+ 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;
- uint32_t idx;
+ uint8_t bit;
uint64_t regval;
switch (opc) {
- case BNXT_ULP_COND_OPC_COMP_FIELD_IS_SET:
+ case BNXT_ULP_COND_OPC_CF_IS_SET:
if (operand < BNXT_ULP_CF_IDX_LAST) {
*res = ULP_COMP_FLD_IDX_RD(parms, operand);
} else {
rc = -EINVAL;
}
break;
- case BNXT_ULP_COND_OPC_COMP_FIELD_NOT_SET:
+ case BNXT_ULP_COND_OPC_CF_NOT_SET:
if (operand < BNXT_ULP_CF_IDX_LAST) {
*res = !ULP_COMP_FLD_IDX_RD(parms, operand);
} else {
rc = -EINVAL;
}
break;
- case BNXT_ULP_COND_OPC_ACTION_BIT_IS_SET:
- if (operand < BNXT_ULP_ACTION_BIT_LAST) {
+ case BNXT_ULP_COND_OPC_ACT_BIT_IS_SET:
+ if (operand < BNXT_ULP_ACT_BIT_LAST) {
*res = ULP_BITMAP_ISSET(parms->act_bitmap->bits,
operand);
} else {
rc = -EINVAL;
}
break;
- case BNXT_ULP_COND_OPC_ACTION_BIT_NOT_SET:
- if (operand < BNXT_ULP_ACTION_BIT_LAST) {
+ case BNXT_ULP_COND_OPC_ACT_BIT_NOT_SET:
+ if (operand < BNXT_ULP_ACT_BIT_LAST) {
*res = !ULP_BITMAP_ISSET(parms->act_bitmap->bits,
operand);
} else {
}
break;
case BNXT_ULP_COND_OPC_FIELD_BIT_IS_SET:
- idx = (parms->class_tid << BNXT_ULP_GLB_FIELD_TBL_SHIFT) |
- operand;
- bit = ulp_mapper_glb_field_tbl_get(idx);
- if (!bit) {
+ rc = ulp_mapper_glb_field_tbl_get(parms, operand, &bit);
+ if (rc) {
BNXT_TF_DBG(ERR, "invalid ulp_glb_field_tbl idx %d\n",
- idx);
+ operand);
return -EINVAL;
}
- *res = ULP_BITMAP_ISSET(parms->fld_bitmap->bits, (1 << *bit));
+ *res = ULP_INDEX_BITMAP_GET(parms->fld_bitmap->bits, bit);
break;
case BNXT_ULP_COND_OPC_FIELD_BIT_NOT_SET:
- idx = (parms->class_tid << BNXT_ULP_GLB_FIELD_TBL_SHIFT) |
- operand;
- bit = ulp_mapper_glb_field_tbl_get(idx);
- if (!bit) {
+ rc = ulp_mapper_glb_field_tbl_get(parms, operand, &bit);
+ if (rc) {
BNXT_TF_DBG(ERR, "invalid ulp_glb_field_tbl idx %d\n",
- idx);
+ operand);
return -EINVAL;
}
- *res = !ULP_BITMAP_ISSET(parms->fld_bitmap->bits, (1 << *bit));
+ *res = !ULP_INDEX_BITMAP_GET(parms->fld_bitmap->bits, bit);
break;
- case BNXT_ULP_COND_OPC_REGFILE_IS_SET:
+ case BNXT_ULP_COND_OPC_RF_IS_SET:
if (!ulp_regfile_read(parms->regfile, operand, ®val)) {
BNXT_TF_DBG(ERR, "regfile[%d] read oob\n", operand);
return -EINVAL;
}
*res = regval != 0;
break;
- case BNXT_ULP_COND_OPC_REGFILE_NOT_SET:
+ case BNXT_ULP_COND_OPC_RF_NOT_SET:
if (!ulp_regfile_read(parms->regfile, operand, ®val)) {
BNXT_TF_DBG(ERR, "regfile[%d] read oob\n", operand);
return -EINVAL;
}
*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);
+ return -EINVAL;
+ }
+ 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);
+ return -EINVAL;
+ }
+ 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_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;
default:
BNXT_TF_DBG(ERR, "Invalid conditional opcode %d\n", opc);
rc = -EINVAL;
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.
int32_t *res)
{
uint32_t i;
- int32_t rc = 0, trc;
+ int32_t rc = 0, trc = 0;
switch (list_opc) {
case BNXT_ULP_COND_LIST_OPC_AND:
default:
BNXT_TF_DBG(ERR, "Invalid conditional list opcode %d\n",
list_opc);
+ *res = 0;
return -EINVAL;
}
return rc;
}
+/*
+ * Processes conflict resolution and returns both a status and result.
+ * The status must be checked prior to verifying the result.
+ *
+ * returns 0 for success, negative on failure
+ * returns res = 1 for true, res = 0 for false.
+ */
+static int32_t
+ulp_mapper_conflict_resolution_process(struct bnxt_ulp_mapper_parms *parms,
+ struct bnxt_ulp_mapper_tbl_info *tbl,
+ int32_t *res)
+{
+ int32_t rc = 0;
+ uint64_t regval;
+ uint64_t comp_sig;
+
+ *res = 0;
+ switch (tbl->accept_opcode) {
+ case BNXT_ULP_ACCEPT_OPC_ALWAYS:
+ *res = 1;
+ break;
+ case BNXT_ULP_ACCEPT_OPC_FLOW_SIG_ID_MATCH:
+ /* perform the signature validation*/
+ if (tbl->resource_func ==
+ BNXT_ULP_RESOURCE_FUNC_GENERIC_TABLE) {
+ /* Perform the check that generic table is hit or not */
+ if (!ulp_regfile_read(parms->regfile,
+ BNXT_ULP_RF_IDX_GENERIC_TBL_MISS,
+ ®val)) {
+ BNXT_TF_DBG(ERR, "regfile[%d] read oob\n",
+ BNXT_ULP_RF_IDX_GENERIC_TBL_MISS);
+ return -EINVAL;
+ }
+ if (regval) {
+ /* not a hit so no need to check flow sign*/
+ *res = 1;
+ return rc;
+ }
+ }
+ /* compare the new flow signature against stored one */
+ if (!ulp_regfile_read(parms->regfile,
+ BNXT_ULP_RF_IDX_FLOW_SIG_ID,
+ ®val)) {
+ BNXT_TF_DBG(ERR, "regfile[%d] read oob\n",
+ BNXT_ULP_RF_IDX_FLOW_SIG_ID);
+ return -EINVAL;
+ }
+ 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 == regval)
+ *res = 1;
+ else
+ 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",
+ tbl->accept_opcode);
+ return -EINVAL;
+ }
+ return rc;
+}
+
static int32_t
ulp_mapper_tbls_process(struct bnxt_ulp_mapper_parms *parms, uint32_t tid)
{
enum bnxt_ulp_cond_list_opc cond_opc;
struct bnxt_ulp_mapper_tbl_info *tbls;
struct bnxt_ulp_mapper_tbl_info *tbl;
- uint32_t num_tbls, i, num_cond_tbls;
+ uint32_t num_tbls, tbl_idx, num_cond_tbls;
int32_t rc = -EINVAL, cond_rc = 0;
+ int32_t cond_goto = 1;
cond_tbls = ulp_mapper_tmpl_reject_list_get(parms, tid,
&num_cond_tbls,
/* Reject the template if True */
if (cond_rc) {
BNXT_TF_DBG(ERR, "%s Template %d rejected.\n",
- (parms->tmpl_type ==
- BNXT_ULP_TEMPLATE_TYPE_CLASS) ?
- "class" : "action", tid);
+ ulp_mapper_tmpl_name_str(parms->tmpl_type),
+ tid);
return -EINVAL;
}
}
tbls = ulp_mapper_tbl_list_get(parms, tid, &num_tbls);
if (!tbls || !num_tbls) {
BNXT_TF_DBG(ERR, "No %s tables for %d:%d\n",
- (parms->tmpl_type == BNXT_ULP_TEMPLATE_TYPE_CLASS) ?
- "class" : "action", parms->dev_id, tid);
+ ulp_mapper_tmpl_name_str(parms->tmpl_type),
+ parms->dev_id, tid);
return -EINVAL;
}
- for (i = 0; i < num_tbls; i++) {
- tbl = &tbls[i];
+ for (tbl_idx = 0; tbl_idx < num_tbls && cond_goto;) {
+ tbl = &tbls[tbl_idx];
+ 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;
+ }
- /* Handle the table level opcodes to determine if required. */
- if (ulp_mapper_tbl_memtype_opcode_process(parms, tbl))
- continue;
cond_tbls = ulp_mapper_tbl_execute_list_get(parms, tbl,
&num_cond_tbls,
&cond_opc);
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)
- continue;
+ if (!cond_rc) {
+ cond_goto = tbl->execute_info.cond_false_goto;
+ goto next_iteration;
+ }
switch (tbl->resource_func) {
case BNXT_ULP_RESOURCE_FUNC_TCAM_TABLE:
rc = ulp_mapper_tcam_tbl_process(parms, tbl);
break;
- case BNXT_ULP_RESOURCE_FUNC_EXT_EM_TABLE:
- case BNXT_ULP_RESOURCE_FUNC_INT_EM_TABLE:
+ case BNXT_ULP_RESOURCE_FUNC_EM_TABLE:
rc = ulp_mapper_em_tbl_process(parms, tbl);
break;
case BNXT_ULP_RESOURCE_FUNC_INDEX_TABLE:
case BNXT_ULP_RESOURCE_FUNC_GENERIC_TABLE:
rc = ulp_mapper_gen_tbl_process(parms, tbl);
break;
+ case BNXT_ULP_RESOURCE_FUNC_CTRL_TABLE:
+ rc = ulp_mapper_ctrl_tbl_process(parms, tbl);
+ break;
case BNXT_ULP_RESOURCE_FUNC_INVALID:
rc = 0;
break;
tbl->resource_func);
goto error;
}
+
+ /* perform the post table process */
+ rc = ulp_mapper_conflict_resolution_process(parms, tbl,
+ &cond_rc);
+ if (rc || !cond_rc) {
+ BNXT_TF_DBG(ERR, "Failed due to conflict resolution\n");
+ rc = -EINVAL;
+ 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);
+ goto error;
+ }
+ tbl_idx += cond_goto;
}
return rc;
error:
BNXT_TF_DBG(ERR, "%s tables failed creation for %d:%d\n",
- (parms->tmpl_type = BNXT_ULP_TEMPLATE_TYPE_CLASS) ?
- "class" : "action", parms->dev_id, tid);
+ ulp_mapper_tmpl_name_str(parms->tmpl_type),
+ parms->dev_id, tid);
return rc;
}
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;
case BNXT_ULP_RESOURCE_FUNC_TCAM_TABLE:
rc = ulp_mapper_tcam_entry_free(ulp, tfp, res);
break;
- case BNXT_ULP_RESOURCE_FUNC_EXT_EM_TABLE:
- case BNXT_ULP_RESOURCE_FUNC_INT_EM_TABLE:
+ case BNXT_ULP_RESOURCE_FUNC_EM_TABLE:
rc = ulp_mapper_em_entry_free(ulp, tfp, res);
break;
case BNXT_ULP_RESOURCE_FUNC_INDEX_TABLE:
* Set the critical resource on the first resource del, then iterate
* while status is good
*/
- res_parms.critical_resource = BNXT_ULP_CRITICAL_RESOURCE_YES;
+ if (flow_type != BNXT_ULP_FDB_TYPE_RID)
+ res_parms.critical_resource = BNXT_ULP_CRITICAL_RESOURCE_YES;
+
rc = ulp_flow_db_resource_del(ulp_ctx, flow_type, fid, &res_parms);
if (rc) {
* remaining resources. Don't return
*/
BNXT_TF_DBG(ERR,
- "Flow[%d][0x%x] Res[%d][0x%016" PRIx64
+ "Flow[%d][0x%x] Res[%d][0x%016" PRIX64
"] failed rc=%d.\n",
flow_type, fid, res_parms.resource_func,
res_parms.resource_hndl, trc);
/* 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;
return rc;
}
-/* Function to handle the default global templates that are allocated during
- * the startup and reused later.
- */
-static int32_t
-ulp_mapper_glb_template_table_init(struct bnxt_ulp_context *ulp_ctx)
-{
- uint32_t *glbl_tmpl_list;
- uint32_t num_glb_tmpls, idx, dev_id;
- struct bnxt_ulp_mapper_parms parms;
- struct bnxt_ulp_mapper_data *mapper_data;
- int32_t rc = 0;
-
- glbl_tmpl_list = ulp_mapper_glb_template_table_get(&num_glb_tmpls);
- if (!glbl_tmpl_list || !num_glb_tmpls)
- return rc; /* No global templates to process */
-
- /* Get the device id from the ulp context */
- if (bnxt_ulp_cntxt_dev_id_get(ulp_ctx, &dev_id)) {
- BNXT_TF_DBG(ERR, "Invalid ulp context\n");
- return -EINVAL;
- }
-
- mapper_data = bnxt_ulp_cntxt_ptr2_mapper_data_get(ulp_ctx);
- if (!mapper_data) {
- BNXT_TF_DBG(ERR, "Failed to get the ulp mapper data\n");
- return -EINVAL;
- }
-
- /* Iterate the global resources and process each one */
- for (idx = 0; idx < num_glb_tmpls; idx++) {
- /* Initialize the parms structure */
- memset(&parms, 0, sizeof(parms));
- parms.tfp = bnxt_ulp_cntxt_tfp_get(ulp_ctx);
- parms.ulp_ctx = ulp_ctx;
- parms.dev_id = dev_id;
- parms.mapper_data = mapper_data;
- parms.flow_type = BNXT_ULP_FDB_TYPE_DEFAULT;
- parms.tmpl_type = BNXT_ULP_TEMPLATE_TYPE_CLASS;
-
- /* Get the class table entry from dev id and class id */
- parms.class_tid = glbl_tmpl_list[idx];
-
- parms.device_params = bnxt_ulp_device_params_get(parms.dev_id);
- if (!parms.device_params) {
- BNXT_TF_DBG(ERR, "No device for device id %d\n",
- parms.dev_id);
- return -EINVAL;
- }
-
- rc = ulp_mapper_tbls_process(&parms, parms.class_tid);
- if (rc)
- return rc;
- }
- return rc;
-}
-
/* Function to handle the mapping of the Flow to be compatible
* with the underlying hardware.
*/
{
struct bnxt_ulp_mapper_parms parms;
struct ulp_regfile regfile;
- int32_t rc, trc;
+ int32_t rc = 0, trc;
if (!ulp_ctx || !cparms)
return -EINVAL;
parms.hdr_bitmap = cparms->hdr_bitmap;
parms.regfile = ®file;
parms.hdr_field = cparms->hdr_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.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)) {
return -EINVAL;
}
- rc = ulp_regfile_write(parms.regfile,
- BNXT_ULP_REGFILE_INDEX_CLASS_TID,
- tfp_cpu_to_be_64((uint64_t)parms.class_tid));
- if (!rc) {
- BNXT_TF_DBG(ERR, "Unable to write template ID to regfile\n");
- return -EINVAL;
- }
-
/* Process the action template list from the selected action table*/
if (parms.act_tid) {
parms.tmpl_type = BNXT_ULP_TEMPLATE_TYPE_ACTION;
rc = ulp_mapper_tbls_process(&parms, parms.act_tid);
if (rc)
goto flow_error;
+ cparms->shared_hndl = parms.shared_hndl;
}
if (parms.class_tid) {
flow_error:
/* Free all resources that were allocated during flow creation */
- trc = ulp_mapper_flow_destroy(ulp_ctx, BNXT_ULP_FDB_TYPE_REGULAR,
+ trc = ulp_mapper_flow_destroy(ulp_ctx, parms.flow_type,
parms.fid);
if (trc)
BNXT_TF_DBG(ERR, "Failed to free all resources rc=%d\n", trc);
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) {
goto error;
}
- /* Allocate global template table entries */
- rc = ulp_mapper_glb_template_table_init(ulp_ctx);
- if (rc) {
- BNXT_TF_DBG(ERR, "Failed to initialize global templates\n");
- goto error;
- }
-
return 0;
error:
/* Ignore the return code in favor of returning the original error. */
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. */