net/bnxt: support mapper flow database opcodes
authorKishore Padmanabha <kishore.padmanabha@broadcom.com>
Sun, 30 May 2021 08:58:59 +0000 (14:28 +0530)
committerAjit Khaparde <ajit.khaparde@broadcom.com>
Thu, 8 Jul 2021 00:01:57 +0000 (02:01 +0200)
Added support for mapper flow database opcode to enable
shared resources like mirror action. This allows mapper
to conditionally populate flow database based on template content.

Signed-off-by: Kishore Padmanabha <kishore.padmanabha@broadcom.com>
Signed-off-by: Venkat Duvvuru <venkatkumar.duvvuru@broadcom.com>
Reviewed-by: Mike Baucom <michael.baucom@broadcom.com>
Reviewed-by: Ajit Khaparde <ajit.khaparde@broadcom.com>
drivers/net/bnxt/tf_ulp/ulp_mapper.c
drivers/net/bnxt/tf_ulp/ulp_template_db_enum.h
drivers/net/bnxt/tf_ulp/ulp_template_struct.h

index 7037297..c8ae924 100644 (file)
@@ -469,6 +469,80 @@ ulp_mapper_child_flow_free(struct bnxt_ulp_context *ulp,
        return 0;
 }
 
+/*
+ * Process the flow database opcode action.
+ * returns 0 on success.
+ */
+static int32_t
+ulp_mapper_fdb_opc_process(struct bnxt_ulp_mapper_parms *parms,
+                          struct bnxt_ulp_mapper_tbl_info *tbl,
+                          struct ulp_flow_db_res_params *fid_parms)
+{
+       uint32_t push_fid, fid = 0;
+       uint64_t val64;
+       int32_t rc = 0;
+
+       switch (tbl->fdb_opcode) {
+       case BNXT_ULP_FDB_OPC_PUSH:
+               push_fid = parms->fid;
+               break;
+       case BNXT_ULP_FDB_OPC_ALLOC_PUSH_REGFILE:
+               /* allocate a new fid */
+               rc = ulp_flow_db_fid_alloc(parms->ulp_ctx,
+                                          BNXT_ULP_FDB_TYPE_REGULAR,
+                                          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,
+                                      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:
+               /* get the fid from the regfile */
+               rc = ulp_regfile_read(parms->regfile, tbl->flow_db_operand,
+                                     &val64);
+               if (!rc) {
+                       BNXT_TF_DBG(ERR, "regfile[%d] read oob\n",
+                                   tbl->flow_db_operand);
+                       return -EINVAL;
+               }
+               /* Use the extracted fid to update the flow resource */
+               push_fid = (uint32_t)val64;
+               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,
+                                     push_fid, fid_parms);
+       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;
+}
+
 /*
  * Process the identifier instruction and either store it in the flow database
  * or return it in the val (if not NULL) on success.  If val is NULL, the
@@ -524,10 +598,7 @@ ulp_mapper_ident_process(struct bnxt_ulp_mapper_parms *parms,
                fid_parms.resource_hndl = iparms.id;
                fid_parms.critical_resource = BNXT_ULP_CRITICAL_RESOURCE_NO;
 
-               rc = ulp_flow_db_resource_add(parms->ulp_ctx,
-                                             parms->flow_type,
-                                             parms->fid,
-                                             &fid_parms);
+               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);
@@ -618,10 +689,7 @@ ulp_mapper_ident_extract(struct bnxt_ulp_mapper_parms *parms,
        fid_parms.resource_type = ident->ident_type;
        fid_parms.resource_hndl = sparms.search_id;
        fid_parms.critical_resource = BNXT_ULP_CRITICAL_RESOURCE_NO;
-       rc = ulp_flow_db_resource_add(parms->ulp_ctx,
-                                     parms->flow_type,
-                                     parms->fid,
-                                     &fid_parms);
+       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);
@@ -1103,10 +1171,7 @@ ulp_mapper_mark_gfid_process(struct bnxt_ulp_mapper_parms *parms,
        fid_parms.critical_resource = BNXT_ULP_CRITICAL_RESOURCE_NO;
        fid_parms.resource_type = mark_flag;
        fid_parms.resource_hndl = gfid;
-       rc = ulp_flow_db_resource_add(parms->ulp_ctx,
-                                     parms->flow_type,
-                                     parms->fid,
-                                     &fid_parms);
+       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);
        return rc;
@@ -1152,10 +1217,7 @@ ulp_mapper_mark_act_ptr_process(struct bnxt_ulp_mapper_parms *parms,
        fid_parms.critical_resource = BNXT_ULP_CRITICAL_RESOURCE_NO;
        fid_parms.resource_type = mark_flag;
        fid_parms.resource_hndl = act_idx;
-       rc = ulp_flow_db_resource_add(parms->ulp_ctx,
-                                     parms->flow_type,
-                                     parms->fid,
-                                     &fid_parms);
+       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);
        return rc;
@@ -1201,10 +1263,7 @@ ulp_mapper_mark_vfr_idx_process(struct bnxt_ulp_mapper_parms *parms,
        fid_parms.critical_resource = BNXT_ULP_CRITICAL_RESOURCE_NO;
        fid_parms.resource_type = mark_flag;
        fid_parms.resource_hndl = act_idx;
-       rc = ulp_flow_db_resource_add(parms->ulp_ctx,
-                                     parms->flow_type,
-                                     parms->fid,
-                                     &fid_parms);
+       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);
        return rc;
@@ -1580,10 +1639,7 @@ ulp_mapper_tcam_tbl_process(struct bnxt_ulp_mapper_parms *parms,
                fid_parms.resource_type = tbl->resource_type;
                fid_parms.critical_resource = tbl->critical_resource;
                fid_parms.resource_hndl = idx;
-               rc = ulp_flow_db_resource_add(parms->ulp_ctx,
-                                             parms->flow_type,
-                                             parms->fid,
-                                             &fid_parms);
+               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",
@@ -1741,10 +1797,7 @@ ulp_mapper_em_tbl_process(struct bnxt_ulp_mapper_parms *parms,
        fid_parms.critical_resource     = tbl->critical_resource;
        fid_parms.resource_hndl         = iparms.flow_handle;
 
-       rc = ulp_flow_db_resource_add(parms->ulp_ctx,
-                                     parms->flow_type,
-                                     parms->fid,
-                                     &fid_parms);
+       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);
@@ -1968,10 +2021,7 @@ ulp_mapper_index_tbl_process(struct bnxt_ulp_mapper_parms *parms,
        fid_parms.resource_hndl = index;
        fid_parms.critical_resource = BNXT_ULP_CRITICAL_RESOURCE_NO;
 
-       rc = ulp_flow_db_resource_add(parms->ulp_ctx,
-                                     parms->flow_type,
-                                     parms->fid,
-                                     &fid_parms);
+       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",
                            rc);
@@ -2280,10 +2330,7 @@ ulp_mapper_gen_tbl_process(struct bnxt_ulp_mapper_parms *parms,
                fid_parms.resource_sub_type = tbl->resource_sub_type;
                fid_parms.resource_hndl = ckey;
                fid_parms.critical_resource = tbl->critical_resource;
-               rc = ulp_flow_db_resource_add(parms->ulp_ctx,
-                                             parms->flow_type,
-                                             parms->fid,
-                                             &fid_parms);
+               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);
        }
index 2a9a290..f16651a 100644 (file)
@@ -179,6 +179,14 @@ enum bnxt_ulp_direction {
        BNXT_ULP_DIRECTION_LAST = 2
 };
 
+enum bnxt_ulp_fdb_opc {
+       BNXT_ULP_FDB_OPC_PUSH = 0,
+       BNXT_ULP_FDB_OPC_ALLOC_PUSH_REGFILE = 1,
+       BNXT_ULP_FDB_OPC_PUSH_REGFILE = 2,
+       BNXT_ULP_FDB_OPC_NOP = 3,
+       BNXT_ULP_FDB_OPC_LAST = 4
+};
+
 enum bnxt_ulp_flow_mem_type {
        BNXT_ULP_FLOW_MEM_TYPE_INT = 0,
        BNXT_ULP_FLOW_MEM_TYPE_EXT = 1,
index 67308f1..167116a 100644 (file)
@@ -220,6 +220,10 @@ struct bnxt_ulp_mapper_tbl_info {
 
        /* Table opcode for table operations */
        uint32_t                        tbl_opcode;
+
+       /* FDB table opcode */
+       enum bnxt_ulp_fdb_opc           fdb_opcode;
+       uint32_t                        flow_db_operand;
 };
 
 struct bnxt_ulp_mapper_key_field_info {