From 02bf1662efe129c064727f81c9dccc50cb88583e Mon Sep 17 00:00:00 2001 From: Satha Rao Date: Wed, 23 Feb 2022 01:04:54 +0530 Subject: [PATCH] common/cnxk: adjust shaper rates to lower boundaries Provide a method to get floor values for a requested shaper rate, which can assure packets should never be transmitted at a rate higher than configured. Keep the old API to get HW suggested values. And introduce new parameter to select appropriate API. Signed-off-by: Satha Rao Acked-by: Jerin Jacob --- drivers/common/cnxk/roc_nix.h | 1 + drivers/common/cnxk/roc_nix_priv.h | 4 +- drivers/common/cnxk/roc_nix_tm_ops.c | 10 ++- drivers/common/cnxk/roc_nix_tm_utils.c | 90 ++++++++++++++++++++++++-- 4 files changed, 96 insertions(+), 9 deletions(-) diff --git a/drivers/common/cnxk/roc_nix.h b/drivers/common/cnxk/roc_nix.h index 680a34cdcd..a0f24d2711 100644 --- a/drivers/common/cnxk/roc_nix.h +++ b/drivers/common/cnxk/roc_nix.h @@ -543,6 +543,7 @@ struct roc_nix_tm_shaper_profile { uint64_t peak_sz; int32_t pkt_len_adj; bool pkt_mode; + int8_t accuracy; /* Function to free this memory */ void (*free_fn)(void *profile); }; diff --git a/drivers/common/cnxk/roc_nix_priv.h b/drivers/common/cnxk/roc_nix_priv.h index afd9d52c8d..c050180f08 100644 --- a/drivers/common/cnxk/roc_nix_priv.h +++ b/drivers/common/cnxk/roc_nix_priv.h @@ -97,6 +97,7 @@ struct nix_tm_shaper_profile { int32_t pkt_mode_adj; bool pkt_mode; uint32_t id; + int8_t accuracy; void (*free_fn)(void *profile); uint32_t ref_cnt; @@ -403,7 +404,8 @@ uint32_t nix_tm_check_rr(struct nix *nix, uint32_t parent_id, uint32_t *max_prio); uint64_t nix_tm_shaper_profile_rate_min(struct nix *nix); uint64_t nix_tm_shaper_rate_conv(uint64_t value, uint64_t *exponent_p, - uint64_t *mantissa_p, uint64_t *div_exp_p); + uint64_t *mantissa_p, uint64_t *div_exp_p, + int8_t accuracy); uint64_t nix_tm_shaper_burst_conv(uint64_t value, uint64_t *exponent_p, uint64_t *mantissa_p); bool nix_tm_child_res_valid(struct nix_tm_node_list *list, diff --git a/drivers/common/cnxk/roc_nix_tm_ops.c b/drivers/common/cnxk/roc_nix_tm_ops.c index d3d39eeb99..5a25b3e9b0 100644 --- a/drivers/common/cnxk/roc_nix_tm_ops.c +++ b/drivers/common/cnxk/roc_nix_tm_ops.c @@ -173,8 +173,8 @@ nix_tm_shaper_profile_add(struct roc_nix *roc_nix, if (commit_rate || commit_sz) { if (commit_sz < min_burst || commit_sz > max_burst) return NIX_ERR_TM_INVALID_COMMIT_SZ; - else if (!nix_tm_shaper_rate_conv(commit_rate, NULL, NULL, - NULL)) + else if (!nix_tm_shaper_rate_conv(commit_rate, NULL, NULL, NULL, + profile->accuracy)) return NIX_ERR_TM_INVALID_COMMIT_RATE; } @@ -182,7 +182,8 @@ nix_tm_shaper_profile_add(struct roc_nix *roc_nix, if (peak_sz || peak_rate) { if (peak_sz < min_burst || peak_sz > max_burst) return NIX_ERR_TM_INVALID_PEAK_SZ; - else if (!nix_tm_shaper_rate_conv(peak_rate, NULL, NULL, NULL)) + else if (!nix_tm_shaper_rate_conv(peak_rate, NULL, NULL, NULL, + profile->accuracy)) return NIX_ERR_TM_INVALID_PEAK_RATE; } @@ -230,6 +231,7 @@ roc_nix_tm_shaper_profile_add(struct roc_nix *roc_nix, profile->pkt_len_adj = roc_profile->pkt_len_adj; profile->pkt_mode = roc_profile->pkt_mode; profile->free_fn = roc_profile->free_fn; + profile->accuracy = roc_profile->accuracy; return nix_tm_shaper_profile_add(roc_nix, profile, 0); } @@ -246,6 +248,8 @@ roc_nix_tm_shaper_profile_update(struct roc_nix *roc_nix, profile->peak.rate = roc_profile->peak_rate; profile->commit.size = roc_profile->commit_sz; profile->peak.size = roc_profile->peak_sz; + profile->pkt_len_adj = roc_profile->pkt_len_adj; + profile->accuracy = roc_profile->accuracy; return nix_tm_shaper_profile_add(roc_nix, profile, 1); } diff --git a/drivers/common/cnxk/roc_nix_tm_utils.c b/drivers/common/cnxk/roc_nix_tm_utils.c index 9e80c2a5fe..bcdf990d6a 100644 --- a/drivers/common/cnxk/roc_nix_tm_utils.c +++ b/drivers/common/cnxk/roc_nix_tm_utils.c @@ -125,9 +125,72 @@ nix_tm_node_search(struct nix *nix, uint32_t node_id, enum roc_nix_tm_tree tree) return NULL; } -uint64_t -nix_tm_shaper_rate_conv(uint64_t value, uint64_t *exponent_p, - uint64_t *mantissa_p, uint64_t *div_exp_p) +static uint64_t +nix_tm_shaper_rate_conv_floor(uint64_t value, uint64_t *exponent_p, + uint64_t *mantissa_p, uint64_t *div_exp_p) +{ + uint64_t div_exp, exponent, mantissa; + + /* Boundary checks */ + if (value < NIX_TM_MIN_SHAPER_RATE || value > NIX_TM_MAX_SHAPER_RATE) + return 0; + + if (value <= NIX_TM_SHAPER_RATE(0, 0, 0)) { + /* Calculate rate div_exp and mantissa using + * the following formula: + * + * value = (2E6 * (256 + mantissa) + * / ((1 << div_exp) * 256)) + */ + div_exp = 0; + exponent = 0; + mantissa = NIX_TM_MAX_RATE_MANTISSA; + + while (value <= (NIX_TM_SHAPER_RATE_CONST / (1 << div_exp))) + div_exp += 1; + + while (value <= ((NIX_TM_SHAPER_RATE_CONST * (256 + mantissa)) / + ((1 << div_exp) * 256))) + mantissa -= 1; + } else { + /* Calculate rate exponent and mantissa using + * the following formula: + * + * value = (2E6 * ((256 + mantissa) << exponent)) / 256 + * + */ + div_exp = 0; + exponent = NIX_TM_MAX_RATE_EXPONENT; + mantissa = NIX_TM_MAX_RATE_MANTISSA; + + while (value <= (NIX_TM_SHAPER_RATE_CONST * (1 << exponent))) + exponent -= 1; + + while (value <= ((NIX_TM_SHAPER_RATE_CONST * + ((256 + mantissa) << exponent)) / + 256)) + mantissa -= 1; + } + + if (div_exp > NIX_TM_MAX_RATE_DIV_EXP || + exponent > NIX_TM_MAX_RATE_EXPONENT || + mantissa > NIX_TM_MAX_RATE_MANTISSA) + return 0; + + if (div_exp_p) + *div_exp_p = div_exp; + if (exponent_p) + *exponent_p = exponent; + if (mantissa_p) + *mantissa_p = mantissa; + + /* Calculate real rate value */ + return NIX_TM_SHAPER_RATE(exponent, mantissa, div_exp); +} + +static uint64_t +nix_tm_shaper_rate_conv_exact(uint64_t value, uint64_t *exponent_p, + uint64_t *mantissa_p, uint64_t *div_exp_p) { uint64_t div_exp, exponent, mantissa; @@ -188,6 +251,23 @@ nix_tm_shaper_rate_conv(uint64_t value, uint64_t *exponent_p, return NIX_TM_SHAPER_RATE(exponent, mantissa, div_exp); } +/* With zero accuracy we will tune parameters as defined by HW, + * non zero accuracy will keep the parameters close to lower values + * and make sure long-term shaper rate will not exceed the requested rate. + */ +uint64_t +nix_tm_shaper_rate_conv(uint64_t value, uint64_t *exponent_p, + uint64_t *mantissa_p, uint64_t *div_exp_p, + int8_t accuracy) +{ + if (!accuracy) + return nix_tm_shaper_rate_conv_exact(value, exponent_p, + mantissa_p, div_exp_p); + + return nix_tm_shaper_rate_conv_floor(value, exponent_p, mantissa_p, + div_exp_p); +} + uint64_t nix_tm_shaper_burst_conv(uint64_t value, uint64_t *exponent_p, uint64_t *mantissa_p) @@ -245,13 +325,13 @@ nix_tm_shaper_conf_get(struct nix_tm_shaper_profile *profile, if (profile->commit.rate) cir->rate = nix_tm_shaper_rate_conv( profile->commit.rate, &cir->exponent, &cir->mantissa, - &cir->div_exp); + &cir->div_exp, profile->accuracy); /* Calculate PIR exponent and mantissa */ if (profile->peak.rate) pir->rate = nix_tm_shaper_rate_conv( profile->peak.rate, &pir->exponent, &pir->mantissa, - &pir->div_exp); + &pir->div_exp, profile->accuracy); /* Calculate CIR burst exponent and mantissa */ if (profile->commit.size) -- 2.39.5