#define NIX_RPM_MAX_HW_FRS 16380UL
#define NIX_MIN_HW_FRS 60UL
+/** NIX policer rate limits */
+#define NIX_BPF_MAX_RATE_DIV_EXP 12
+#define NIX_BPF_MAX_RATE_EXPONENT 0xf
+#define NIX_BPF_MAX_RATE_MANTISSA 0xff
+
+#define NIX_BPF_RATE_CONST 2000000ULL
+
+/* NIX rate calculation in Bits/Sec
+ * PIR_ADD = ((256 + NIX_*_PIR[RATE_MANTISSA])
+ * << NIX_*_PIR[RATE_EXPONENT]) / 256
+ * PIR = (2E6 * PIR_ADD / (1 << NIX_*_PIR[RATE_DIVIDER_EXPONENT]))
+ *
+ * CIR_ADD = ((256 + NIX_*_CIR[RATE_MANTISSA])
+ * << NIX_*_CIR[RATE_EXPONENT]) / 256
+ * CIR = (2E6 * CIR_ADD / (CCLK_TICKS << NIX_*_CIR[RATE_DIVIDER_EXPONENT]))
+ */
+#define NIX_BPF_RATE(exponent, mantissa, div_exp) \
+ ((NIX_BPF_RATE_CONST * ((256 + (mantissa)) << (exponent))) / \
+ (((1ull << (div_exp)) * 256)))
+
+/* Meter rate limits in Bits/Sec */
+#define NIX_BPF_RATE_MIN NIX_BPF_RATE(0, 0, NIX_BPF_MAX_RATE_DIV_EXP)
+#define NIX_BPF_RATE_MAX \
+ NIX_BPF_RATE(NIX_BPF_MAX_RATE_EXPONENT, NIX_BPF_MAX_RATE_MANTISSA, 0)
+
+#define NIX_BPF_DEFAULT_ADJUST_MANTISSA 511
+#define NIX_BPF_DEFAULT_ADJUST_EXPONENT 0
+
+/** NIX burst limits */
+#define NIX_BPF_MAX_BURST_EXPONENT 0xf
+#define NIX_BPF_MAX_BURST_MANTISSA 0xff
+
+/* NIX burst calculation
+ * PIR_BURST = ((256 + NIX_*_PIR[BURST_MANTISSA])
+ * << (NIX_*_PIR[BURST_EXPONENT] + 1))
+ * / 256
+ *
+ * CIR_BURST = ((256 + NIX_*_CIR[BURST_MANTISSA])
+ * << (NIX_*_CIR[BURST_EXPONENT] + 1))
+ * / 256
+ */
+#define NIX_BPF_BURST(exponent, mantissa) \
+ (((256 + (mantissa)) << ((exponent) + 1)) / 256)
+
+/** Meter burst limits */
+#define NIX_BPF_BURST_MIN NIX_BPF_BURST(0, 0)
+#define NIX_BPF_BURST_MAX \
+ NIX_BPF_BURST(NIX_BPF_MAX_BURST_EXPONENT, NIX_BPF_MAX_BURST_MANTISSA)
+
/* NIX rate limits */
#define NIX_TM_MAX_RATE_DIV_EXP 12
#define NIX_TM_MAX_RATE_EXPONENT 0xf
ROC_NIX_BPF_LEVEL_F_TOP = BIT(2),
};
+enum roc_nix_bpf_pc_mode {
+ ROC_NIX_BPF_PC_MODE_VLAN_INNER,
+ ROC_NIX_BPF_PC_MODE_VLAN_OUTER,
+ ROC_NIX_BPF_PC_MODE_DSCP_INNER,
+ ROC_NIX_BPF_PC_MODE_DSCP_OUTER,
+ ROC_NIX_BPF_PC_MODE_GEN_INNER,
+ ROC_NIX_BPF_PC_MODE_GEN_OUTER
+};
+
+enum roc_nix_bpf_color {
+ ROC_NIX_BPF_COLOR_GREEN,
+ ROC_NIX_BPF_COLOR_YELLOW,
+ ROC_NIX_BPF_COLOR_RED,
+ ROC_NIX_BPF_COLOR_MAX
+};
+
+enum roc_nix_bpf_algo {
+ ROC_NIX_BPF_ALGO_NONE,
+ ROC_NIX_BPF_ALGO_2698,
+ ROC_NIX_BPF_ALGO_4115,
+ ROC_NIX_BPF_ALGO_2697
+};
+
+enum roc_nix_bpf_lmode { ROC_NIX_BPF_LMODE_BYTE, ROC_NIX_BPF_LMODE_PACKET };
+
+enum roc_nix_bpf_action {
+ ROC_NIX_BPF_ACTION_PASS,
+ ROC_NIX_BPF_ACTION_DROP,
+ ROC_NIX_BPF_ACTION_RED
+};
+
+struct roc_nix_bpf_cfg {
+ enum roc_nix_bpf_algo alg;
+ enum roc_nix_bpf_lmode lmode;
+ enum roc_nix_bpf_color icolor;
+ enum roc_nix_bpf_pc_mode pc_mode;
+ bool tnl_ena;
+ union {
+ /* Valid when *alg* is set to ROC_NIX_BPF_ALGO_2697. */
+ struct {
+ uint64_t cir;
+ uint64_t cbs;
+ uint64_t ebs;
+ } algo2697;
+
+ /* Valid when *alg* is set to ROC_NIX_BPF_ALGO_2698. */
+ struct {
+ uint64_t cir;
+ uint64_t pir;
+ uint64_t cbs;
+ uint64_t pbs;
+ } algo2698;
+
+ /* Valid when *alg* is set to ROC_NIX_BPF_ALGO_4115. */
+ struct {
+ uint64_t cir;
+ uint64_t eir;
+ uint64_t cbs;
+ uint64_t ebs;
+ } algo4115;
+ };
+
+ enum roc_nix_bpf_action action[ROC_NIX_BPF_COLOR_MAX];
+
+ /* Reserved for future config*/
+ uint32_t rsvd[3];
+};
+
struct roc_nix_bpf_objs {
uint16_t level;
uint16_t count;
int __roc_api roc_nix_bpf_free_all(struct roc_nix *roc_nix);
+int __roc_api roc_nix_bpf_config(struct roc_nix *roc_nix, uint16_t id,
+ enum roc_nix_bpf_level_flag lvl_flag,
+ struct roc_nix_bpf_cfg *cfg);
+
uint8_t __roc_api
roc_nix_bpf_level_to_idx(enum roc_nix_bpf_level_flag lvl_flag);
return dev->mbox;
}
+static inline uint64_t
+meter_rate_to_nix(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_BPF_RATE_MIN || value > NIX_BPF_RATE_MAX)
+ return 0;
+
+ if (value <= NIX_BPF_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_BPF_MAX_RATE_MANTISSA;
+
+ while (value < (NIX_BPF_RATE_CONST / (1 << div_exp)))
+ div_exp += 1;
+
+ while (value < ((NIX_BPF_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_BPF_MAX_RATE_EXPONENT;
+ mantissa = NIX_BPF_MAX_RATE_MANTISSA;
+
+ while (value < (NIX_BPF_RATE_CONST * (1 << exponent)))
+ exponent -= 1;
+
+ while (value <
+ ((NIX_BPF_RATE_CONST * ((256 + mantissa) << exponent)) /
+ 256))
+ mantissa -= 1;
+ }
+
+ if (div_exp > NIX_BPF_MAX_RATE_DIV_EXP ||
+ exponent > NIX_BPF_MAX_RATE_EXPONENT ||
+ mantissa > NIX_BPF_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_BPF_RATE(exponent, mantissa, div_exp);
+}
+
+static inline uint64_t
+meter_burst_to_nix(uint64_t value, uint64_t *exponent_p, uint64_t *mantissa_p)
+{
+ uint64_t exponent, mantissa;
+
+ if (value < NIX_BPF_BURST_MIN || value > NIX_BPF_BURST_MAX)
+ return 0;
+
+ /* Calculate burst exponent and mantissa using
+ * the following formula:
+ *
+ * value = (((256 + mantissa) << (exponent + 1)
+ / 256)
+ *
+ */
+ exponent = NIX_BPF_MAX_BURST_EXPONENT;
+ mantissa = NIX_BPF_MAX_BURST_MANTISSA;
+
+ while (value < (1ull << (exponent + 1)))
+ exponent -= 1;
+
+ while (value < ((256 + mantissa) << (exponent + 1)) / 256)
+ mantissa -= 1;
+
+ if (exponent > NIX_BPF_MAX_BURST_EXPONENT ||
+ mantissa > NIX_BPF_MAX_BURST_MANTISSA)
+ return 0;
+
+ if (exponent_p)
+ *exponent_p = exponent;
+ if (mantissa_p)
+ *mantissa_p = mantissa;
+
+ return NIX_BPF_BURST(exponent, mantissa);
+}
+
uint8_t
roc_nix_bpf_level_to_idx(enum roc_nix_bpf_level_flag level_f)
{
req->free_all = true;
return mbox_process(mbox);
}
+
+int
+roc_nix_bpf_config(struct roc_nix *roc_nix, uint16_t id,
+ enum roc_nix_bpf_level_flag lvl_flag,
+ struct roc_nix_bpf_cfg *cfg)
+{
+ uint64_t exponent_p = 0, mantissa_p = 0, div_exp_p = 0;
+ struct mbox *mbox = get_mbox(roc_nix);
+ struct nix_cn10k_aq_enq_req *aq;
+ uint8_t level_idx;
+
+ if (roc_model_is_cn9k())
+ return NIX_ERR_HW_NOTSUP;
+
+ if (!cfg)
+ return NIX_ERR_PARAM;
+
+ level_idx = roc_nix_bpf_level_to_idx(lvl_flag);
+ if (level_idx == ROC_NIX_BPF_LEVEL_IDX_INVALID)
+ return NIX_ERR_PARAM;
+
+ aq = mbox_alloc_msg_nix_cn10k_aq_enq(mbox);
+ if (aq == NULL)
+ return -ENOSPC;
+ aq->qidx = (sw_to_hw_lvl_map[level_idx] << 14) | id;
+ aq->ctype = NIX_AQ_CTYPE_BAND_PROF;
+ aq->op = NIX_AQ_INSTOP_WRITE;
+
+ aq->prof.adjust_exponent = NIX_BPF_DEFAULT_ADJUST_EXPONENT;
+ aq->prof.adjust_mantissa = NIX_BPF_DEFAULT_ADJUST_MANTISSA;
+ if (cfg->lmode == ROC_NIX_BPF_LMODE_BYTE)
+ aq->prof.adjust_mantissa = NIX_BPF_DEFAULT_ADJUST_MANTISSA / 2;
+
+ aq->prof_mask.adjust_exponent = ~(aq->prof_mask.adjust_exponent);
+ aq->prof_mask.adjust_mantissa = ~(aq->prof_mask.adjust_mantissa);
+
+ switch (cfg->alg) {
+ case ROC_NIX_BPF_ALGO_2697:
+ meter_rate_to_nix(cfg->algo2697.cir, &exponent_p, &mantissa_p,
+ &div_exp_p);
+ aq->prof.cir_mantissa = mantissa_p;
+ aq->prof.cir_exponent = exponent_p;
+
+ meter_burst_to_nix(cfg->algo2697.cbs, &exponent_p, &mantissa_p);
+ aq->prof.cbs_mantissa = mantissa_p;
+ aq->prof.cbs_exponent = exponent_p;
+
+ meter_burst_to_nix(cfg->algo2697.ebs, &exponent_p, &mantissa_p);
+ aq->prof.pebs_mantissa = mantissa_p;
+ aq->prof.pebs_exponent = exponent_p;
+
+ aq->prof_mask.cir_mantissa = ~(aq->prof_mask.cir_mantissa);
+ aq->prof_mask.cbs_mantissa = ~(aq->prof_mask.cbs_mantissa);
+ aq->prof_mask.pebs_mantissa = ~(aq->prof_mask.pebs_mantissa);
+ aq->prof_mask.cir_exponent = ~(aq->prof_mask.cir_exponent);
+ aq->prof_mask.cbs_exponent = ~(aq->prof_mask.cbs_exponent);
+ aq->prof_mask.pebs_exponent = ~(aq->prof_mask.pebs_exponent);
+ break;
+
+ case ROC_NIX_BPF_ALGO_2698:
+ meter_rate_to_nix(cfg->algo2698.cir, &exponent_p, &mantissa_p,
+ &div_exp_p);
+ aq->prof.cir_mantissa = mantissa_p;
+ aq->prof.cir_exponent = exponent_p;
+
+ meter_rate_to_nix(cfg->algo2698.pir, &exponent_p, &mantissa_p,
+ &div_exp_p);
+ aq->prof.peir_mantissa = mantissa_p;
+ aq->prof.peir_exponent = exponent_p;
+
+ meter_burst_to_nix(cfg->algo2698.cbs, &exponent_p, &mantissa_p);
+ aq->prof.cbs_mantissa = mantissa_p;
+ aq->prof.cbs_exponent = exponent_p;
+
+ meter_burst_to_nix(cfg->algo2698.pbs, &exponent_p, &mantissa_p);
+ aq->prof.pebs_mantissa = mantissa_p;
+ aq->prof.pebs_exponent = exponent_p;
+
+ aq->prof_mask.cir_mantissa = ~(aq->prof_mask.cir_mantissa);
+ aq->prof_mask.peir_mantissa = ~(aq->prof_mask.peir_mantissa);
+ aq->prof_mask.cbs_mantissa = ~(aq->prof_mask.cbs_mantissa);
+ aq->prof_mask.pebs_mantissa = ~(aq->prof_mask.pebs_mantissa);
+ aq->prof_mask.cir_exponent = ~(aq->prof_mask.cir_exponent);
+ aq->prof_mask.peir_exponent = ~(aq->prof_mask.peir_exponent);
+ aq->prof_mask.cbs_exponent = ~(aq->prof_mask.cbs_exponent);
+ aq->prof_mask.pebs_exponent = ~(aq->prof_mask.pebs_exponent);
+ break;
+
+ case ROC_NIX_BPF_ALGO_4115:
+ meter_rate_to_nix(cfg->algo4115.cir, &exponent_p, &mantissa_p,
+ &div_exp_p);
+ aq->prof.cir_mantissa = mantissa_p;
+ aq->prof.cir_exponent = exponent_p;
+
+ meter_rate_to_nix(cfg->algo4115.eir, &exponent_p, &mantissa_p,
+ &div_exp_p);
+ aq->prof.peir_mantissa = mantissa_p;
+ aq->prof.peir_exponent = exponent_p;
+
+ meter_burst_to_nix(cfg->algo4115.cbs, &exponent_p, &mantissa_p);
+ aq->prof.cbs_mantissa = mantissa_p;
+ aq->prof.cbs_exponent = exponent_p;
+
+ meter_burst_to_nix(cfg->algo4115.ebs, &exponent_p, &mantissa_p);
+ aq->prof.pebs_mantissa = mantissa_p;
+ aq->prof.pebs_exponent = exponent_p;
+
+ aq->prof_mask.cir_mantissa = ~(aq->prof_mask.cir_mantissa);
+ aq->prof_mask.peir_mantissa = ~(aq->prof_mask.peir_mantissa);
+ aq->prof_mask.cbs_mantissa = ~(aq->prof_mask.cbs_mantissa);
+ aq->prof_mask.pebs_mantissa = ~(aq->prof_mask.pebs_mantissa);
+
+ aq->prof_mask.cir_exponent = ~(aq->prof_mask.cir_exponent);
+ aq->prof_mask.peir_exponent = ~(aq->prof_mask.peir_exponent);
+ aq->prof_mask.cbs_exponent = ~(aq->prof_mask.cbs_exponent);
+ aq->prof_mask.pebs_exponent = ~(aq->prof_mask.pebs_exponent);
+ break;
+
+ default:
+ return NIX_ERR_PARAM;
+ }
+
+ aq->prof.lmode = cfg->lmode;
+ aq->prof.icolor = cfg->icolor;
+ aq->prof.pc_mode = cfg->pc_mode;
+ aq->prof.tnl_ena = cfg->tnl_ena;
+ aq->prof.gc_action = cfg->action[ROC_NIX_BPF_COLOR_GREEN];
+ aq->prof.yc_action = cfg->action[ROC_NIX_BPF_COLOR_YELLOW];
+ aq->prof.rc_action = cfg->action[ROC_NIX_BPF_COLOR_RED];
+
+ aq->prof_mask.lmode = ~(aq->prof_mask.lmode);
+ aq->prof_mask.icolor = ~(aq->prof_mask.icolor);
+ aq->prof_mask.pc_mode = ~(aq->prof_mask.pc_mode);
+ aq->prof_mask.tnl_ena = ~(aq->prof_mask.tnl_ena);
+ aq->prof_mask.gc_action = ~(aq->prof_mask.gc_action);
+ aq->prof_mask.yc_action = ~(aq->prof_mask.yc_action);
+ aq->prof_mask.rc_action = ~(aq->prof_mask.rc_action);
+
+ return mbox_process(mbox);
+}