net/bnxt: modify table processing
[dpdk.git] / drivers / net / bnxt / tf_core / tf_tbl.c
index ca1aef8..ced5913 100644 (file)
@@ -41,6 +41,7 @@ tf_tbl_bind(struct tf *tfp,
            struct tf_tbl_cfg_parms *parms)
 {
        int rc, d, i;
+       int db_rc[TF_DIR_MAX] = { 0 };
        struct tf_rm_create_db_parms db_cfg = { 0 };
        struct tbl_rm_db *tbl_db;
        struct tfp_calloc_parms cparms;
@@ -79,16 +80,17 @@ tf_tbl_bind(struct tf *tfp,
                db_cfg.rm_db = (void *)&tbl_db->tbl_db[d];
                if (tf_session_is_shared_session(tfs) &&
                        (!tf_session_is_shared_session_creator(tfs)))
-                       rc = tf_rm_create_db_no_reservation(tfp, &db_cfg);
+                       db_rc[d] = tf_rm_create_db_no_reservation(tfp, &db_cfg);
                else
-                       rc = tf_rm_create_db(tfp, &db_cfg);
-               if (rc) {
-                       TFP_DRV_LOG(ERR,
-                                   "%s: Table DB creation failed\n",
-                                   tf_dir_2_str(d));
+                       db_rc[d] = tf_rm_create_db(tfp, &db_cfg);
+       }
 
-                       return rc;
-               }
+       /* No db created */
+       if (db_rc[TF_DIR_RX] && db_rc[TF_DIR_TX]) {
+               TFP_DRV_LOG(ERR,
+                           "%s: No Table DB created\n",
+                           tf_dir_2_str(d));
+               return db_rc[TF_DIR_RX];
        }
 
        TFP_DRV_LOG(INFO,
@@ -108,12 +110,8 @@ tf_tbl_unbind(struct tf *tfp)
        TF_CHECK_PARMS1(tfp);
 
        rc = tf_session_get_db(tfp, TF_MODULE_TYPE_TABLE, &tbl_db_ptr);
-       if (rc) {
-               TFP_DRV_LOG(INFO,
-                           "Tbl_db is not initialized, rc:%s\n",
-                           strerror(-rc));
+       if (rc)
                return 0;
-       }
        tbl_db = (struct tbl_rm_db *)tbl_db_ptr;
 
        for (i = 0; i < TF_DIR_MAX; i++) {
@@ -272,6 +270,44 @@ tf_tbl_free(struct tf *tfp __rte_unused,
                            parms->idx);
                return -EINVAL;
        }
+
+       /* If this is counter table, clear the entry on free */
+       if (parms->type == TF_TBL_TYPE_ACT_STATS_64) {
+               uint8_t data[8] = { 0 };
+               uint16_t hcapi_type = 0;
+               struct tf_rm_get_hcapi_parms hparms = { 0 };
+
+               /* Get the hcapi type */
+               hparms.rm_db = tbl_db->tbl_db[parms->dir];
+               hparms.subtype = parms->type;
+               hparms.hcapi_type = &hcapi_type;
+               rc = tf_rm_get_hcapi_type(&hparms);
+               if (rc) {
+                       TFP_DRV_LOG(ERR,
+                                   "%s, Failed type lookup, type:%d, rc:%s\n",
+                                   tf_dir_2_str(parms->dir),
+                                   parms->type,
+                                   strerror(-rc));
+                       return rc;
+               }
+               /* Clear the counter
+                */
+               rc = tf_msg_set_tbl_entry(tfp,
+                                         parms->dir,
+                                         hcapi_type,
+                                         sizeof(data),
+                                         data,
+                                         parms->idx);
+               if (rc) {
+                       TFP_DRV_LOG(ERR,
+                                   "%s, Set failed, type:%d, rc:%s\n",
+                                   tf_dir_2_str(parms->dir),
+                                   parms->type,
+                                   strerror(-rc));
+                       return rc;
+               }
+       }
+
        /* Free requested element */
        fparms.rm_db = tbl_db->tbl_db[parms->dir];
        fparms.subtype = parms->type;
@@ -645,19 +681,21 @@ tf_tbl_get_resc_info(struct tf *tfp,
                return rc;
 
        rc = tf_session_get_db(tfp, TF_MODULE_TYPE_TABLE, &tbl_db_ptr);
-       if (rc) {
-               TFP_DRV_LOG(INFO,
-                           "No resource allocated for table from session\n");
-               return 0;
-       }
-       tbl_db = (struct tbl_rm_db *)tbl_db_ptr;
+       if (rc == -ENOMEM)
+               return 0; /* db doesn't exist */
+       else if (rc)
+               return rc; /* error getting db */
 
+       tbl_db = (struct tbl_rm_db *)tbl_db_ptr;
 
        /* check if reserved resource for WC is multiple of num_slices */
        for (d = 0; d < TF_DIR_MAX; d++) {
                ainfo.rm_db = tbl_db->tbl_db[d];
                dinfo = tbl[d].info;
 
+               if (!ainfo.rm_db)
+                       continue;
+
                ainfo.info = (struct tf_rm_alloc_info *)dinfo;
                ainfo.subtype = 0;
                rc = tf_rm_get_all_info(&ainfo, TF_TBL_TYPE_MAX);
@@ -689,7 +727,5 @@ tf_tbl_get_resc_info(struct tf *tfp,
                }
        }
 
-
-
        return 0;
 }