+/*
+ * Tcam table - create the result blob.
+ * data [out] - the result blob data
+ */
+static int32_t
+ulp_mapper_tcam_tbl_result_create(struct bnxt_ulp_mapper_parms *parms,
+ struct bnxt_ulp_mapper_tbl_info *tbl,
+ struct ulp_blob *data)
+{
+ struct bnxt_ulp_mapper_result_field_info *dflds;
+ uint32_t num_dflds;
+ uint32_t encap_flds = 0;
+ uint32_t i;
+ int32_t rc = 0;
+
+ /* Create the result data blob */
+ dflds = ulp_mapper_result_fields_get(parms, tbl, &num_dflds,
+ &encap_flds);
+ if (!dflds || !num_dflds || encap_flds) {
+ BNXT_TF_DBG(ERR, "Failed to get data fields.\n");
+ return -EINVAL;
+ }
+
+ for (i = 0; i < num_dflds; i++) {
+ rc = ulp_mapper_result_field_process(parms,
+ tbl->direction,
+ &dflds[i],
+ data,
+ "TCAM Result");
+ if (rc) {
+ BNXT_TF_DBG(ERR, "Failed to set data fields\n");
+ return -EINVAL;
+ }
+ }
+ return rc;
+}
+
+/* Tcam table scan the identifier list and allocate each identifier */
+static int32_t
+ulp_mapper_tcam_tbl_scan_ident_alloc(struct bnxt_ulp_mapper_parms *parms,
+ struct bnxt_ulp_mapper_tbl_info *tbl)
+{
+ struct bnxt_ulp_mapper_ident_info *idents;
+ uint32_t num_idents;
+ uint32_t i;
+
+ /*
+ * Since the cache entry is responsible for allocating
+ * identifiers when in use, allocate the identifiers only
+ * during normal processing.
+ */
+ if (parms->tcam_tbl_opc ==
+ BNXT_ULP_MAPPER_TCAM_TBL_OPC_NORMAL) {
+ idents = ulp_mapper_ident_fields_get(parms, tbl, &num_idents);
+
+ for (i = 0; i < num_idents; i++) {
+ if (ulp_mapper_ident_process(parms, tbl,
+ &idents[i], NULL))
+ return -EINVAL;
+ }
+ }
+ return 0;
+}
+
+/*
+ * Tcam table scan the identifier list and extract the identifier from
+ * the result blob.
+ */
+static int32_t
+ulp_mapper_tcam_tbl_scan_ident_extract(struct bnxt_ulp_mapper_parms *parms,
+ struct bnxt_ulp_mapper_tbl_info *tbl,
+ struct ulp_blob *data)
+{
+ struct bnxt_ulp_mapper_ident_info *idents;
+ uint32_t num_idents = 0, i;
+ int32_t rc = 0;
+
+ /*
+ * Extract the listed identifiers from the result field,
+ * no need to allocate them.
+ */
+ idents = ulp_mapper_ident_fields_get(parms, tbl, &num_idents);
+ for (i = 0; i < num_idents; i++) {
+ rc = ulp_mapper_ident_extract(parms, tbl, &idents[i], data);
+ if (rc) {
+ BNXT_TF_DBG(ERR, "Error in identifier extraction\n");
+ return rc;
+ }
+ }
+ return rc;
+}
+
+/* Internal function to write the tcam entry */
+static int32_t
+ulp_mapper_tcam_tbl_entry_write(struct bnxt_ulp_mapper_parms *parms,
+ struct bnxt_ulp_mapper_tbl_info *tbl,
+ struct ulp_blob *key,
+ struct ulp_blob *mask,
+ struct ulp_blob *data,
+ uint16_t idx)
+{
+ struct tf_set_tcam_entry_parms sparms = { 0 };
+ struct tf *tfp;
+ uint16_t tmplen;
+ int32_t rc;
+
+ tfp = bnxt_ulp_cntxt_tfp_get(parms->ulp_ctx);
+ if (!tfp) {
+ BNXT_TF_DBG(ERR, "Failed to get truflow pointer\n");
+ return -EINVAL;
+ }
+
+ sparms.dir = tbl->direction;
+ sparms.tcam_tbl_type = tbl->resource_type;
+ sparms.idx = idx;
+ /* Already verified the key/mask lengths */
+ sparms.key = ulp_blob_data_get(key, &tmplen);
+ sparms.mask = ulp_blob_data_get(mask, &tmplen);
+ sparms.key_sz_in_bits = tbl->key_bit_size;
+ sparms.result = ulp_blob_data_get(data, &tmplen);
+
+ if (tbl->result_bit_size != tmplen) {
+ BNXT_TF_DBG(ERR, "Result len (%d) != Expected (%d)\n",
+ tmplen, tbl->result_bit_size);
+ return -EINVAL;
+ }
+ sparms.result_sz_in_bits = tbl->result_bit_size;
+ if (tf_set_tcam_entry(tfp, &sparms)) {
+ BNXT_TF_DBG(ERR, "tcam[%s][%s][%x] write failed.\n",
+ tf_tcam_tbl_2_str(sparms.tcam_tbl_type),
+ tf_dir_2_str(sparms.dir), sparms.idx);
+ return -EIO;
+ }
+ BNXT_TF_DBG(INFO, "tcam[%s][%s][%x] write success.\n",
+ tf_tcam_tbl_2_str(sparms.tcam_tbl_type),
+ tf_dir_2_str(sparms.dir), sparms.idx);
+
+ /* Update cache with TCAM index if the was cache allocated. */
+ if (parms->tcam_tbl_opc ==
+ BNXT_ULP_MAPPER_TCAM_TBL_OPC_CACHE_ALLOC) {
+ if (!parms->cache_ptr) {
+ BNXT_TF_DBG(ERR, "Unable to update cache");
+ return -EINVAL;
+ }
+ parms->cache_ptr->tcam_idx = idx;
+ }
+
+ /* Mark action */
+ rc = ulp_mapper_mark_act_ptr_process(parms, tbl);
+ if (rc) {
+ BNXT_TF_DBG(ERR, "failed mark action processing\n");
+ return rc;
+ }
+
+ return rc;
+}
+
+#define BNXT_ULP_WC_TCAM_SLICE_SIZE 80
+/* 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)
+{
+ 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);
+}
+