+ /* populate the search params and search identifier shadow table */
+ sparms.ident_type = ident->ident_type;
+ sparms.dir = tbl->direction;
+ /* convert the idx into cpu format */
+ sparms.search_id = tfp_be_to_cpu_32(idx);
+
+ /* Search identifier also increase the reference count */
+ rc = tf_search_identifier(tfp, &sparms);
+ if (rc) {
+ BNXT_TF_DBG(ERR, "Search ident %s:%s:%x failed.\n",
+ tf_dir_2_str(sparms.dir),
+ tf_ident_2_str(sparms.ident_type),
+ 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);
+ if (ulp_regfile_write(parms->regfile, ident->regfile_idx, id)) {
+ BNXT_TF_DBG(ERR, "Regfile[%d] write failed.\n", idx);
+ rc = -EINVAL;
+ /* Need to free the identifier, so goto error */
+ goto error;
+ }
+
+ /* Link the resource to the flow in the flow db */
+ memset(&fid_parms, 0, sizeof(fid_parms));
+ fid_parms.direction = tbl->direction;
+ fid_parms.resource_func = ident->resource_func;
+ fid_parms.resource_type = ident->ident_type;
+ fid_parms.resource_hndl = sparms.search_id;
+ fid_parms.critical_resource = 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",
+ rc);
+ /* Need to free the identifier, so goto error */
+ goto error;
+ }
+
+#ifdef RTE_LIBRTE_BNXT_TRUFLOW_DEBUG
+#ifdef RTE_LIBRTE_BNXT_TRUFLOW_DEBUG_MAPPER
+ ulp_mapper_ident_field_dump("Ident", ident, tbl, sparms.search_id);
+#endif
+#endif
+ return 0;
+
+error:
+ /* Need to free the identifier */
+ free_parms.dir = tbl->direction;
+ free_parms.ident_type = ident->ident_type;
+ free_parms.id = sparms.search_id;
+ (void)tf_free_identifier(tfp, &free_parms);
+ BNXT_TF_DBG(ERR, "Ident extract failed for %s:%s:%x\n",
+ ident->description,
+ tf_dir_2_str(tbl->direction), sparms.search_id);
+ return rc;
+}
+
+static int32_t
+ulp_mapper_field_port_db_process(struct bnxt_ulp_mapper_parms *parms,
+ uint32_t port_id,
+ uint16_t val16,
+ uint8_t **val)
+{
+ 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;
+ 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, "CF operand read failed\n");
+ return -EINVAL;
+ }
+ idx = tfp_be_to_cpu_16(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;
+ }
+ 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;
+ }
+
+ 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_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;
+ }
+ 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;
+ }
+ 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 = &buffer[field_size - bytelen];
+ break;
+ case BNXT_ULP_FIELD_SRC_ACT_PROP_SZ:
+ if (!ulp_operand_read(field_opr,
+ (uint8_t *)&idx, sizeof(uint16_t))) {
+ 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, "act_prop_sz[%d] oob\n", idx);