From: Farah Smith <[email protected]>

In order for the pool size to be calculated correctly flow counts
must be updated to the next power of 2 so that the pool_size_exp
shift can be used correctly without losing pool entries due to
rounding errors.  Also, max_pools must be a power of 2 for same
reasons.

Signed-off-by: Farah Smith <[email protected]>
Reviewed-by: Peter Spreadborough <[email protected]>
---
 drivers/net/bnxt/tf_core/v3/tfc_tbl_scope.c | 16 +++++++++++++++-
 1 file changed, 15 insertions(+), 1 deletion(-)

diff --git a/drivers/net/bnxt/tf_core/v3/tfc_tbl_scope.c 
b/drivers/net/bnxt/tf_core/v3/tfc_tbl_scope.c
index 88863ed6ad..e7b82eee49 100644
--- a/drivers/net/bnxt/tf_core/v3/tfc_tbl_scope.c
+++ b/drivers/net/bnxt/tf_core/v3/tfc_tbl_scope.c
@@ -86,6 +86,8 @@ static int calc_lkup_rec_cnt(uint32_t flow_cnt, uint16_t 
key_sz_in_bytes,
        unsigned int flow_adj;    /* flow_cnt adjusted for factor */
        unsigned int key_rec_cnt;
 
+       flow_cnt = 1 << next_pow2(flow_cnt);
+
        switch (factor) {
        case TFC_TBL_SCOPE_BUCKET_FACTOR_1:
                flow_adj = flow_cnt;
@@ -924,6 +926,12 @@ int tfc_tbl_scope_size_query(struct tfc *tfcp,
                return -EINVAL;
        }
 
+       if (parms->max_pools != next_pow2(parms->max_pools)) {
+               PMD_DRV_LOG(ERR, "%s: Invalid max_pools %u not pow2\n",
+                           __func__, parms->max_pools);
+               return -EINVAL;
+       }
+
        for (dir = CFA_DIR_RX; dir < CFA_DIR_MAX; dir++) {
                rc = calc_lkup_rec_cnt(parms->flow_cnt[dir],
                                       parms->key_sz_in_bytes[dir],
@@ -941,7 +949,8 @@ int tfc_tbl_scope_size_query(struct tfc *tfcp,
                        break;
 
                rc = calc_pool_sz_exp(&parms->lkup_pool_sz_exp[dir],
-                                     parms->lkup_rec_cnt[dir],
+                                     parms->lkup_rec_cnt[dir] -
+                                     (1 << parms->static_bucket_cnt_exp[dir]),
                                      parms->max_pools);
                if (rc)
                        break;
@@ -1033,6 +1042,11 @@ int tfc_tbl_scope_mem_alloc(struct tfc *tfcp, uint16_t 
fid, uint8_t tsid,
                PMD_DRV_LOG_LINE(ERR, "tsid(%d) not allocated", tsid);
                return -EINVAL;
        }
+       if (parms->max_pools != next_pow2(parms->max_pools)) {
+               PMD_DRV_LOG(ERR, "%s: Invalid max_pools %u not pow2\n", 
__func__,
+                           parms->max_pools);
+               return -EINVAL;
+       }
 
        /* Normalize page size to a power of 2 */
        page_sz = 1 << next_pow2(parms->pbl_page_sz_in_bytes);
-- 
2.39.5 (Apple Git-154)

Reply via email to