LCOV - code coverage report
Current view: top level - drivers/common/cnxk - roc_nix_bpf.c (source / functions) Hit Total Coverage
Test: Code coverage Lines: 0 688 0.0 %
Date: 2025-03-01 20:23:48 Functions: 0 21 0.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 0 357 0.0 %

           Branch data     Line data    Source code
       1                 :            : /* SPDX-License-Identifier: BSD-3-Clause
       2                 :            :  * Copyright(C) 2021 Marvell.
       3                 :            :  */
       4                 :            : 
       5                 :            : #include "roc_api.h"
       6                 :            : #include "roc_priv.h"
       7                 :            : 
       8                 :            : #define NIX_MAX_BPF_COUNT_LEAF_LAYER 64
       9                 :            : #define NIX_MAX_BPF_COUNT_MID_LAYER  8
      10                 :            : #define NIX_MAX_BPF_COUNT_TOP_LAYER  1
      11                 :            : 
      12                 :            : #define NIX_BPF_PRECOLOR_GEN_TABLE_SIZE  16
      13                 :            : #define NIX_BPF_PRECOLOR_VLAN_TABLE_SIZE 16
      14                 :            : #define NIX_BPF_PRECOLOR_DSCP_TABLE_SIZE 64
      15                 :            : 
      16                 :            : #define NIX_BPF_LEVEL_F_MASK                                                   \
      17                 :            :         (ROC_NIX_BPF_LEVEL_F_LEAF | ROC_NIX_BPF_LEVEL_F_MID |                  \
      18                 :            :          ROC_NIX_BPF_LEVEL_F_TOP)
      19                 :            : 
      20                 :            : #define NIX_RD_STATS(val)  plt_read64(nix->base + NIX_LF_RX_STATX(val))
      21                 :            : #define NIX_RST_STATS(val) plt_write64(0, nix->base + NIX_LF_RX_STATX(val))
      22                 :            : 
      23                 :            : static uint8_t sw_to_hw_lvl_map[] = {NIX_RX_BAND_PROF_LAYER_LEAF,
      24                 :            :                                      NIX_RX_BAND_PROF_LAYER_MIDDLE,
      25                 :            :                                      NIX_RX_BAND_PROF_LAYER_TOP};
      26                 :            : 
      27                 :            : static inline uint64_t
      28                 :          0 : meter_rate_to_nix(uint64_t value, uint64_t *exponent_p, uint64_t *mantissa_p,
      29                 :            :                   uint64_t *div_exp_p, uint32_t timeunit_p)
      30                 :            : {
      31                 :            :         uint64_t div_exp, exponent, mantissa;
      32                 :            :         uint32_t time_ns = timeunit_p;
      33                 :            : 
      34                 :            :         /* Boundary checks */
      35         [ #  # ]:          0 :         if (value < NIX_BPF_RATE(time_ns, 0, 0, 0) ||
      36         [ #  # ]:          0 :             value > NIX_BPF_RATE(time_ns, NIX_BPF_MAX_RATE_EXPONENT,
      37                 :            :                                  NIX_BPF_MAX_RATE_MANTISSA, 0))
      38                 :            :                 return 0;
      39                 :            : 
      40                 :            :         div_exp = 0;
      41                 :            :         exponent = NIX_BPF_MAX_RATE_EXPONENT;
      42                 :            :         mantissa = NIX_BPF_MAX_RATE_MANTISSA;
      43                 :            : 
      44         [ #  # ]:          0 :         while (value < (NIX_BPF_RATE(time_ns, exponent, 0, 0)))
      45                 :          0 :                 exponent -= 1;
      46                 :            : 
      47         [ #  # ]:          0 :         while (value < (NIX_BPF_RATE(time_ns, exponent, mantissa, 0)))
      48                 :          0 :                 mantissa -= 1;
      49                 :            : 
      50         [ #  # ]:          0 :         if (div_exp > NIX_BPF_MAX_RATE_DIV_EXP ||
      51         [ #  # ]:          0 :             exponent > NIX_BPF_MAX_RATE_EXPONENT ||
      52                 :            :             mantissa > NIX_BPF_MAX_RATE_MANTISSA)
      53                 :            :                 return 0;
      54                 :            : 
      55         [ #  # ]:          0 :         if (div_exp_p)
      56                 :          0 :                 *div_exp_p = div_exp;
      57         [ #  # ]:          0 :         if (exponent_p)
      58                 :          0 :                 *exponent_p = exponent;
      59         [ #  # ]:          0 :         if (mantissa_p)
      60                 :          0 :                 *mantissa_p = mantissa;
      61                 :            : 
      62                 :            :         /* Calculate real rate value */
      63                 :            :         return NIX_BPF_RATE(time_ns, exponent, mantissa, div_exp);
      64                 :            : }
      65                 :            : 
      66                 :            : static inline uint64_t
      67                 :          0 : meter_burst_to_nix(uint64_t value, uint64_t *exponent_p, uint64_t *mantissa_p)
      68                 :            : {
      69                 :            :         uint64_t exponent, mantissa;
      70                 :            : 
      71         [ #  # ]:          0 :         if (value < NIX_BPF_BURST_MIN || value > NIX_BPF_BURST_MAX)
      72                 :            :                 return 0;
      73                 :            : 
      74                 :            :         /* Calculate burst exponent and mantissa using
      75                 :            :          * the following formula:
      76                 :            :          *
      77                 :            :          * value = (((256 + mantissa) << (exponent + 1)
      78                 :            :          / 256)
      79                 :            :          *
      80                 :            :          */
      81                 :            :         exponent = NIX_BPF_MAX_BURST_EXPONENT;
      82                 :            :         mantissa = NIX_BPF_MAX_BURST_MANTISSA;
      83                 :            : 
      84         [ #  # ]:          0 :         while (value < (1ull << (exponent + 1)))
      85                 :          0 :                 exponent -= 1;
      86                 :            : 
      87         [ #  # ]:          0 :         while (value < ((256 + mantissa) << (exponent + 1)) / 256)
      88                 :          0 :                 mantissa -= 1;
      89                 :            : 
      90                 :          0 :         if (exponent > NIX_BPF_MAX_BURST_EXPONENT ||
      91         [ #  # ]:          0 :             mantissa > NIX_BPF_MAX_BURST_MANTISSA)
      92                 :            :                 return 0;
      93                 :            : 
      94         [ #  # ]:          0 :         if (exponent_p)
      95                 :          0 :                 *exponent_p = exponent;
      96         [ #  # ]:          0 :         if (mantissa_p)
      97                 :          0 :                 *mantissa_p = mantissa;
      98                 :            : 
      99                 :            :         return NIX_BPF_BURST(exponent, mantissa);
     100                 :            : }
     101                 :            : 
     102                 :            : static inline void
     103                 :          0 : nix_lf_bpf_dump(__io struct nix_band_prof_s *bpf)
     104                 :            : {
     105                 :          0 :         plt_dump("W0: cir_mantissa  \t\t\t%d\nW0: pebs_mantissa \t\t\t0x%03x",
     106                 :            :                  bpf->cir_mantissa, bpf->pebs_mantissa);
     107                 :          0 :         plt_dump("W0: peir_mantissa \t\t\t\t%d\nW0: cbs_exponent \t\t\t%d",
     108                 :            :                  bpf->peir_mantissa, bpf->cbs_exponent);
     109                 :          0 :         plt_dump("W0: cir_exponent \t\t\t%d\nW0: pebs_exponent \t\t\t%d",
     110                 :            :                  bpf->cir_exponent, bpf->pebs_exponent);
     111                 :          0 :         plt_dump("W0: peir_exponent \t\t\t%d\n", bpf->peir_exponent);
     112                 :          0 :         plt_dump("W0: tnl_ena \t\t\t%d\n", bpf->tnl_ena);
     113                 :          0 :         plt_dump("W0: icolor \t\t\t%d\n", bpf->icolor);
     114                 :          0 :         plt_dump("W0: pc_mode \t\t\t%d\n", bpf->pc_mode);
     115                 :          0 :         plt_dump("W1: hl_en \t\t%d\nW1: band_prof_id \t\t%d", bpf->hl_en,
     116                 :            :                  bpf->band_prof_id);
     117                 :          0 :         plt_dump("W1: meter_algo \t\t%d\nW1: rc_action \t\t%d", bpf->meter_algo,
     118                 :            :                  bpf->rc_action);
     119                 :          0 :         plt_dump("W1: yc_action \t\t\t%d\nW1: gc_action \t\t\t%d",
     120                 :            :                  bpf->yc_action, bpf->gc_action);
     121                 :          0 :         plt_dump("W1: adjust_mantissa\t\t\t%d\nW1: adjust_exponent \t\t\t%d",
     122                 :            :                  bpf->adjust_mantissa, bpf->adjust_exponent);
     123                 :          0 :         plt_dump("W1: rdiv \t\t\t%d\n", bpf->rdiv);
     124                 :          0 :         plt_dump("W1: l_select \t\t%d\nW2: lmode \t\t%d", bpf->l_sellect,
     125                 :            :                  bpf->lmode);
     126                 :          0 :         plt_dump("W1: cbs_mantissa \t\t\t%d\n", bpf->cbs_mantissa);
     127                 :          0 :         plt_dump("W2: tsa \t\t\t0x%" PRIx64 "\n", (uint64_t)bpf->ts);
     128                 :          0 :         plt_dump("W3: c_accum \t\t%d\nW3: pe_accum \t\t%d", bpf->c_accum,
     129                 :            :                  bpf->pe_accum);
     130                 :          0 :         plt_dump("W4: green_pkt_pass \t\t\t0x%" PRIx64 "",
     131                 :            :                  (uint64_t)bpf->green_pkt_pass);
     132                 :          0 :         plt_dump("W5: yellow_pkt_pass \t\t\t0x%" PRIx64 "",
     133                 :            :                  (uint64_t)bpf->yellow_pkt_pass);
     134                 :          0 :         plt_dump("W6: red_pkt_pass \t\t\t0x%" PRIx64 "",
     135                 :            :                  (uint64_t)bpf->red_pkt_pass);
     136                 :          0 :         plt_dump("W7: green_octs_pass \t\t\t0x%" PRIx64 "",
     137                 :            :                  (uint64_t)bpf->green_octs_pass);
     138                 :          0 :         plt_dump("W8: yellow_octs_pass \t\t\t0x%" PRIx64 "",
     139                 :            :                  (uint64_t)bpf->yellow_octs_pass);
     140                 :          0 :         plt_dump("W9: red_octs_pass \t\t\t0x%" PRIx64 "",
     141                 :            :                  (uint64_t)bpf->red_octs_pass);
     142                 :          0 :         plt_dump("W10: green_pkt_drop \t\t\t0x%" PRIx64 "",
     143                 :            :                  (uint64_t)bpf->green_pkt_drop);
     144                 :          0 :         plt_dump("W11: yellow_pkt_drop \t\t\t0x%" PRIx64 "",
     145                 :            :                  (uint64_t)bpf->yellow_pkt_drop);
     146                 :          0 :         plt_dump("W12: red_pkt_drop \t\t\t0x%" PRIx64 "",
     147                 :            :                  (uint64_t)bpf->red_pkt_drop);
     148                 :          0 :         plt_dump("W13: green_octs_drop \t\t\t0x%" PRIx64 "",
     149                 :            :                  (uint64_t)bpf->green_octs_drop);
     150                 :          0 :         plt_dump("W14: yellow_octs_drop \t\t\t0x%" PRIx64 "",
     151                 :            :                  (uint64_t)bpf->yellow_octs_drop);
     152                 :          0 :         plt_dump("W15: red_octs_drop \t\t\t0x%" PRIx64 "",
     153                 :            :                  (uint64_t)bpf->red_octs_drop);
     154                 :          0 : }
     155                 :            : 
     156                 :            : static inline void
     157                 :            : nix_precolor_conv_table_write(struct roc_nix *roc_nix, uint64_t val,
     158                 :            :                               uint32_t off)
     159                 :            : {
     160                 :            :         struct nix *nix = roc_nix_to_nix_priv(roc_nix);
     161                 :            :         int64_t *addr;
     162                 :            : 
     163                 :          0 :         addr = PLT_PTR_ADD(nix->base, off);
     164                 :            :         plt_write64(val, addr);
     165                 :            : }
     166                 :            : 
     167                 :            : static uint8_t
     168                 :            : nix_precolor_vlan_table_update(struct roc_nix *roc_nix,
     169                 :            :                                struct roc_nix_bpf_precolor *tbl)
     170                 :            : {
     171                 :            :         uint64_t val = 0, i;
     172                 :            :         uint8_t tn_ena;
     173                 :            :         uint32_t off;
     174                 :            : 
     175         [ #  # ]:          0 :         for (i = 0; i < tbl->count; i++)
     176                 :          0 :                 val |= (((uint64_t)tbl->color[i]) << (2 * i));
     177                 :            : 
     178         [ #  # ]:          0 :         if (tbl->mode == ROC_NIX_BPF_PC_MODE_VLAN_INNER) {
     179                 :            :                 off = NIX_LF_RX_VLAN1_COLOR_CONV;
     180                 :            :                 tn_ena = true;
     181                 :            :         } else {
     182                 :            :                 off = NIX_LF_RX_VLAN0_COLOR_CONV;
     183                 :            :                 tn_ena = false;
     184                 :            :         }
     185                 :            : 
     186                 :            :         nix_precolor_conv_table_write(roc_nix, val, off);
     187                 :            :         return tn_ena;
     188                 :            : }
     189                 :            : 
     190                 :            : static uint8_t
     191                 :          0 : nix_precolor_inner_dscp_table_update(struct roc_nix *roc_nix,
     192                 :            :                                      struct roc_nix_bpf_precolor *tbl)
     193                 :            : {
     194                 :            :         uint64_t val_lo = 0, val_hi = 0, i, j;
     195                 :            : 
     196         [ #  # ]:          0 :         for (i = 0, j = 0; i < (tbl->count / 2); i++, j++)
     197                 :          0 :                 val_lo |= (((uint64_t)tbl->color[i]) << (2 * j));
     198                 :            : 
     199         [ #  # ]:          0 :         for (j = 0; i < tbl->count; i++, j++)
     200                 :          0 :                 val_hi |= (((uint64_t)tbl->color[i]) << (2 * j));
     201                 :            : 
     202                 :            :         nix_precolor_conv_table_write(roc_nix, val_lo,
     203                 :            :                                       NIX_LF_RX_IIP_COLOR_CONV_LO);
     204                 :            :         nix_precolor_conv_table_write(roc_nix, val_hi,
     205                 :            :                                       NIX_LF_RX_IIP_COLOR_CONV_HI);
     206                 :            : 
     207                 :          0 :         return true;
     208                 :            : }
     209                 :            : 
     210                 :            : static uint8_t
     211                 :          0 : nix_precolor_outer_dscp_table_update(struct roc_nix *roc_nix,
     212                 :            :                                      struct roc_nix_bpf_precolor *tbl)
     213                 :            : {
     214                 :            :         uint64_t val_lo = 0, val_hi = 0, i, j;
     215                 :            : 
     216         [ #  # ]:          0 :         for (i = 0, j = 0; i < (tbl->count / 2); i++, j++)
     217                 :          0 :                 val_lo |= (((uint64_t)tbl->color[i]) << (2 * j));
     218                 :            : 
     219         [ #  # ]:          0 :         for (j = 0; i < tbl->count; i++, j++)
     220                 :          0 :                 val_hi |= (((uint64_t)tbl->color[i]) << (2 * j));
     221                 :            : 
     222                 :            :         nix_precolor_conv_table_write(roc_nix, val_lo,
     223                 :            :                                       NIX_LF_RX_OIP_COLOR_CONV_LO);
     224                 :            :         nix_precolor_conv_table_write(roc_nix, val_hi,
     225                 :            :                                       NIX_LF_RX_OIP_COLOR_CONV_HI);
     226                 :            : 
     227                 :          0 :         return false;
     228                 :            : }
     229                 :            : 
     230                 :            : static uint8_t
     231                 :            : nix_precolor_gen_table_update(struct roc_nix *roc_nix,
     232                 :            :                               struct roc_nix_bpf_precolor *tbl)
     233                 :            : {
     234                 :            :         uint64_t val = 0, i;
     235                 :            :         uint8_t tn_ena;
     236                 :            :         uint32_t off;
     237                 :            : 
     238         [ #  # ]:          0 :         for (i = 0; i < tbl->count; i++)
     239                 :          0 :                 val |= (((uint64_t)tbl->color[i]) << (2 * i));
     240                 :            : 
     241         [ #  # ]:          0 :         if (tbl->mode == ROC_NIX_BPF_PC_MODE_GEN_INNER) {
     242                 :            :                 off = NIX_LF_RX_GEN_COLOR_CONVX(1);
     243                 :            :                 tn_ena = true;
     244                 :            :         } else {
     245                 :            :                 off = NIX_LF_RX_GEN_COLOR_CONVX(0);
     246                 :            :                 tn_ena = false;
     247                 :            :         }
     248                 :            : 
     249                 :            :         nix_precolor_conv_table_write(roc_nix, val, off);
     250                 :            :         return tn_ena;
     251                 :            : }
     252                 :            : 
     253                 :            : uint8_t
     254                 :          0 : roc_nix_bpf_level_to_idx(enum roc_nix_bpf_level_flag level_f)
     255                 :            : {
     256                 :            :         uint8_t idx;
     257                 :            : 
     258         [ #  # ]:          0 :         if (level_f & ROC_NIX_BPF_LEVEL_F_LEAF)
     259                 :            :                 idx = 0;
     260         [ #  # ]:          0 :         else if (level_f & ROC_NIX_BPF_LEVEL_F_MID)
     261                 :            :                 idx = 1;
     262         [ #  # ]:          0 :         else if (level_f & ROC_NIX_BPF_LEVEL_F_TOP)
     263                 :            :                 idx = 2;
     264                 :            :         else
     265                 :            :                 idx = ROC_NIX_BPF_LEVEL_IDX_INVALID;
     266                 :          0 :         return idx;
     267                 :            : }
     268                 :            : 
     269                 :            : uint8_t
     270                 :          0 : roc_nix_bpf_stats_to_idx(enum roc_nix_bpf_stats level_f)
     271                 :            : {
     272                 :            :         uint8_t idx;
     273                 :            : 
     274         [ #  # ]:          0 :         if (level_f & ROC_NIX_BPF_GREEN_PKT_F_PASS)
     275                 :            :                 idx = 0;
     276         [ #  # ]:          0 :         else if (level_f & ROC_NIX_BPF_GREEN_OCTS_F_PASS)
     277                 :            :                 idx = 1;
     278         [ #  # ]:          0 :         else if (level_f & ROC_NIX_BPF_GREEN_PKT_F_DROP)
     279                 :            :                 idx = 2;
     280         [ #  # ]:          0 :         else if (level_f & ROC_NIX_BPF_GREEN_OCTS_F_DROP)
     281                 :            :                 idx = 3;
     282         [ #  # ]:          0 :         else if (level_f & ROC_NIX_BPF_YELLOW_PKT_F_PASS)
     283                 :            :                 idx = 4;
     284         [ #  # ]:          0 :         else if (level_f & ROC_NIX_BPF_YELLOW_OCTS_F_PASS)
     285                 :            :                 idx = 5;
     286         [ #  # ]:          0 :         else if (level_f & ROC_NIX_BPF_YELLOW_PKT_F_DROP)
     287                 :            :                 idx = 6;
     288         [ #  # ]:          0 :         else if (level_f & ROC_NIX_BPF_YELLOW_OCTS_F_DROP)
     289                 :            :                 idx = 7;
     290         [ #  # ]:          0 :         else if (level_f & ROC_NIX_BPF_RED_PKT_F_PASS)
     291                 :            :                 idx = 8;
     292         [ #  # ]:          0 :         else if (level_f & ROC_NIX_BPF_RED_OCTS_F_PASS)
     293                 :            :                 idx = 9;
     294         [ #  # ]:          0 :         else if (level_f & ROC_NIX_BPF_RED_PKT_F_DROP)
     295                 :            :                 idx = 10;
     296         [ #  # ]:          0 :         else if (level_f & ROC_NIX_BPF_RED_OCTS_F_DROP)
     297                 :            :                 idx = 11;
     298                 :            :         else
     299                 :            :                 idx = ROC_NIX_BPF_STATS_MAX;
     300                 :          0 :         return idx;
     301                 :            : }
     302                 :            : 
     303                 :            : int
     304                 :          0 : roc_nix_bpf_timeunit_get(struct roc_nix *roc_nix, uint32_t *time_unit)
     305                 :            : {
     306                 :            :         struct nix_bandprof_get_hwinfo_rsp *rsp;
     307                 :            :         struct nix *nix = roc_nix_to_nix_priv(roc_nix);
     308                 :            :         struct dev *dev = &nix->dev;
     309                 :          0 :         struct mbox *mbox = mbox_get(dev->mbox);
     310                 :            :         struct msg_req *req;
     311                 :            :         int rc = -ENOSPC;
     312                 :            : 
     313         [ #  # ]:          0 :         if (roc_model_is_cn9k()) {
     314                 :            :                 rc = NIX_ERR_HW_NOTSUP;
     315                 :          0 :                 goto exit;
     316                 :            :         }
     317                 :            : 
     318                 :          0 :         req = mbox_alloc_msg_nix_bandprof_get_hwinfo(mbox);
     319         [ #  # ]:          0 :         if (req == NULL)
     320                 :          0 :                 goto exit;
     321                 :            : 
     322                 :            :         rc = mbox_process_msg(mbox, (void *)&rsp);
     323         [ #  # ]:          0 :         if (rc)
     324                 :          0 :                 goto exit;
     325                 :            : 
     326                 :          0 :         *time_unit = rsp->policer_timeunit;
     327                 :            : 
     328                 :          0 : exit:
     329                 :            :         mbox_put(mbox);
     330                 :          0 :         return rc;
     331                 :            : }
     332                 :            : 
     333                 :            : int
     334                 :          0 : roc_nix_bpf_count_get(struct roc_nix *roc_nix, uint8_t lvl_mask,
     335                 :            :                       uint16_t count[ROC_NIX_BPF_LEVEL_MAX])
     336                 :            : {
     337                 :          0 :         uint8_t mask = lvl_mask & NIX_BPF_LEVEL_F_MASK;
     338                 :            :         struct nix_bandprof_get_hwinfo_rsp *rsp;
     339                 :            :         struct nix *nix = roc_nix_to_nix_priv(roc_nix);
     340                 :            :         struct dev *dev = &nix->dev;
     341                 :          0 :         struct mbox *mbox = mbox_get(dev->mbox);
     342                 :            :         uint8_t leaf_idx, mid_idx, top_idx;
     343                 :            :         struct msg_req *req;
     344                 :            :         int rc = -ENOSPC;
     345                 :            : 
     346         [ #  # ]:          0 :         if (roc_model_is_cn9k()) {
     347                 :            :                 rc = NIX_ERR_HW_NOTSUP;
     348                 :          0 :                 goto exit;
     349                 :            :         }
     350                 :            : 
     351         [ #  # ]:          0 :         if (!mask) {
     352                 :            :                 rc = NIX_ERR_PARAM;
     353                 :          0 :                 goto exit;
     354                 :            :         }
     355                 :            : 
     356                 :          0 :         req = mbox_alloc_msg_nix_bandprof_get_hwinfo(mbox);
     357         [ #  # ]:          0 :         if (req == NULL)
     358                 :          0 :                 goto exit;
     359                 :            : 
     360                 :            :         rc = mbox_process_msg(mbox, (void *)&rsp);
     361         [ #  # ]:          0 :         if (rc)
     362                 :          0 :                 goto exit;
     363                 :            : 
     364                 :          0 :         leaf_idx = roc_nix_bpf_level_to_idx(mask & ROC_NIX_BPF_LEVEL_F_LEAF);
     365                 :          0 :         mid_idx = roc_nix_bpf_level_to_idx(mask & ROC_NIX_BPF_LEVEL_F_MID);
     366                 :          0 :         top_idx = roc_nix_bpf_level_to_idx(mask & ROC_NIX_BPF_LEVEL_F_TOP);
     367                 :            : 
     368         [ #  # ]:          0 :         if (leaf_idx != ROC_NIX_BPF_LEVEL_IDX_INVALID)
     369                 :          0 :                 count[leaf_idx] = rsp->prof_count[sw_to_hw_lvl_map[leaf_idx]];
     370                 :            : 
     371         [ #  # ]:          0 :         if (mid_idx != ROC_NIX_BPF_LEVEL_IDX_INVALID)
     372                 :          0 :                 count[mid_idx] = rsp->prof_count[sw_to_hw_lvl_map[mid_idx]];
     373                 :            : 
     374         [ #  # ]:          0 :         if (top_idx != ROC_NIX_BPF_LEVEL_IDX_INVALID)
     375                 :          0 :                 count[top_idx] = rsp->prof_count[sw_to_hw_lvl_map[top_idx]];
     376                 :            : 
     377                 :          0 : exit:
     378                 :            :         mbox_put(mbox);
     379                 :          0 :         return rc;
     380                 :            : }
     381                 :            : 
     382                 :            : int
     383                 :          0 : roc_nix_bpf_alloc(struct roc_nix *roc_nix, uint8_t lvl_mask,
     384                 :            :                   uint16_t per_lvl_cnt[ROC_NIX_BPF_LEVEL_MAX],
     385                 :            :                   struct roc_nix_bpf_objs *profs)
     386                 :            : {
     387                 :          0 :         uint8_t mask = lvl_mask & NIX_BPF_LEVEL_F_MASK;
     388                 :            :         struct nix *nix = roc_nix_to_nix_priv(roc_nix);
     389                 :            :         struct dev *dev = &nix->dev;
     390                 :          0 :         struct mbox *mbox = mbox_get(dev->mbox);
     391                 :            :         struct nix_bandprof_alloc_req *req;
     392                 :            :         struct nix_bandprof_alloc_rsp *rsp;
     393                 :            :         uint8_t leaf_idx, mid_idx, top_idx;
     394                 :            :         int rc = -ENOSPC, i;
     395                 :            : 
     396         [ #  # ]:          0 :         if (roc_model_is_cn9k()) {
     397                 :            :                 rc = NIX_ERR_HW_NOTSUP;
     398                 :          0 :                 goto exit;
     399                 :            :         }
     400                 :            : 
     401         [ #  # ]:          0 :         if (!mask) {
     402                 :            :                 rc = NIX_ERR_PARAM;
     403                 :          0 :                 goto exit;
     404                 :            :         }
     405                 :            : 
     406                 :          0 :         leaf_idx = roc_nix_bpf_level_to_idx(mask & ROC_NIX_BPF_LEVEL_F_LEAF);
     407                 :          0 :         mid_idx = roc_nix_bpf_level_to_idx(mask & ROC_NIX_BPF_LEVEL_F_MID);
     408                 :          0 :         top_idx = roc_nix_bpf_level_to_idx(mask & ROC_NIX_BPF_LEVEL_F_TOP);
     409                 :            : 
     410         [ #  # ]:          0 :         if ((leaf_idx != ROC_NIX_BPF_LEVEL_IDX_INVALID) &&
     411         [ #  # ]:          0 :             (per_lvl_cnt[leaf_idx] > NIX_MAX_BPF_COUNT_LEAF_LAYER)) {
     412                 :            :                 rc = NIX_ERR_INVALID_RANGE;
     413                 :          0 :                 goto exit;
     414                 :            :         }
     415                 :            : 
     416         [ #  # ]:          0 :         if ((mid_idx != ROC_NIX_BPF_LEVEL_IDX_INVALID) &&
     417         [ #  # ]:          0 :             (per_lvl_cnt[mid_idx] > NIX_MAX_BPF_COUNT_MID_LAYER)) {
     418                 :            :                 rc = NIX_ERR_INVALID_RANGE;
     419                 :          0 :                 goto exit;
     420                 :            :         }
     421                 :            : 
     422         [ #  # ]:          0 :         if ((top_idx != ROC_NIX_BPF_LEVEL_IDX_INVALID) &&
     423         [ #  # ]:          0 :             (per_lvl_cnt[top_idx] > NIX_MAX_BPF_COUNT_TOP_LAYER)) {
     424                 :            :                 rc = NIX_ERR_INVALID_RANGE;
     425                 :          0 :                 goto exit;
     426                 :            :         }
     427                 :            : 
     428                 :          0 :         req = mbox_alloc_msg_nix_bandprof_alloc(mbox);
     429         [ #  # ]:          0 :         if (req == NULL)
     430                 :          0 :                 goto exit;
     431                 :            : 
     432         [ #  # ]:          0 :         if (leaf_idx != ROC_NIX_BPF_LEVEL_IDX_INVALID) {
     433                 :          0 :                 req->prof_count[sw_to_hw_lvl_map[leaf_idx]] =
     434                 :          0 :                         per_lvl_cnt[leaf_idx];
     435                 :            :         }
     436                 :            : 
     437         [ #  # ]:          0 :         if (mid_idx != ROC_NIX_BPF_LEVEL_IDX_INVALID) {
     438                 :          0 :                 req->prof_count[sw_to_hw_lvl_map[mid_idx]] =
     439                 :          0 :                         per_lvl_cnt[mid_idx];
     440                 :            :         }
     441                 :            : 
     442         [ #  # ]:          0 :         if (top_idx != ROC_NIX_BPF_LEVEL_IDX_INVALID) {
     443                 :          0 :                 req->prof_count[sw_to_hw_lvl_map[top_idx]] =
     444                 :          0 :                         per_lvl_cnt[top_idx];
     445                 :            :         }
     446                 :            : 
     447                 :            :         rc = mbox_process_msg(mbox, (void *)&rsp);
     448         [ #  # ]:          0 :         if (rc)
     449                 :          0 :                 goto exit;
     450                 :            : 
     451         [ #  # ]:          0 :         if (leaf_idx != ROC_NIX_BPF_LEVEL_IDX_INVALID) {
     452                 :          0 :                 profs[leaf_idx].level = leaf_idx;
     453                 :          0 :                 profs[leaf_idx].count =
     454                 :          0 :                         rsp->prof_count[sw_to_hw_lvl_map[leaf_idx]];
     455         [ #  # ]:          0 :                 for (i = 0; i < profs[leaf_idx].count; i++) {
     456                 :          0 :                         profs[leaf_idx].ids[i] =
     457                 :          0 :                                 rsp->prof_idx[sw_to_hw_lvl_map[leaf_idx]][i];
     458                 :            :                 }
     459                 :            :         }
     460                 :            : 
     461         [ #  # ]:          0 :         if (mid_idx != ROC_NIX_BPF_LEVEL_IDX_INVALID) {
     462                 :          0 :                 profs[mid_idx].level = mid_idx;
     463                 :          0 :                 profs[mid_idx].count =
     464                 :          0 :                         rsp->prof_count[sw_to_hw_lvl_map[mid_idx]];
     465         [ #  # ]:          0 :                 for (i = 0; i < profs[mid_idx].count; i++) {
     466                 :          0 :                         profs[mid_idx].ids[i] =
     467                 :          0 :                                 rsp->prof_idx[sw_to_hw_lvl_map[mid_idx]][i];
     468                 :            :                 }
     469                 :            :         }
     470                 :            : 
     471         [ #  # ]:          0 :         if (top_idx != ROC_NIX_BPF_LEVEL_IDX_INVALID) {
     472                 :          0 :                 profs[top_idx].level = top_idx;
     473                 :          0 :                 profs[top_idx].count =
     474                 :          0 :                         rsp->prof_count[sw_to_hw_lvl_map[top_idx]];
     475         [ #  # ]:          0 :                 for (i = 0; i < profs[top_idx].count; i++) {
     476                 :          0 :                         profs[top_idx].ids[i] =
     477                 :          0 :                                 rsp->prof_idx[sw_to_hw_lvl_map[top_idx]][i];
     478                 :            :                 }
     479                 :            :         }
     480                 :            : 
     481                 :          0 : exit:
     482                 :            :         mbox_put(mbox);
     483                 :          0 :         return rc;
     484                 :            : }
     485                 :            : 
     486                 :            : int
     487                 :          0 : roc_nix_bpf_free(struct roc_nix *roc_nix, struct roc_nix_bpf_objs *profs,
     488                 :            :                  uint8_t num_prof)
     489                 :            : {
     490                 :            :         struct nix *nix = roc_nix_to_nix_priv(roc_nix);
     491                 :            :         struct dev *dev = &nix->dev;
     492                 :          0 :         struct mbox *mbox = mbox_get(dev->mbox);
     493                 :            :         struct nix_bandprof_free_req *req;
     494                 :            :         uint8_t level;
     495                 :            :         int i, j, rc;
     496                 :            : 
     497         [ #  # ]:          0 :         if (num_prof >= NIX_RX_BAND_PROF_LAYER_MAX) {
     498                 :            :                 rc = NIX_ERR_INVALID_RANGE;
     499                 :          0 :                 goto exit;
     500                 :            :         }
     501                 :            : 
     502                 :          0 :         req = mbox_alloc_msg_nix_bandprof_free(mbox);
     503         [ #  # ]:          0 :         if (req == NULL) {
     504                 :            :                 rc = -ENOSPC;
     505                 :          0 :                 goto exit;
     506                 :            :         }
     507                 :            : 
     508         [ #  # ]:          0 :         for (i = 0; i < num_prof; i++) {
     509                 :          0 :                 level = sw_to_hw_lvl_map[profs[i].level];
     510                 :          0 :                 req->prof_count[level] = profs[i].count;
     511         [ #  # ]:          0 :                 for (j = 0; j < profs[i].count; j++)
     512                 :          0 :                         req->prof_idx[level][j] = profs[i].ids[j];
     513                 :            :         }
     514                 :            : 
     515                 :          0 :         rc = mbox_process(mbox);
     516                 :          0 : exit:
     517                 :            :         mbox_put(mbox);
     518                 :          0 :         return rc;
     519                 :            : }
     520                 :            : 
     521                 :            : int
     522                 :          0 : roc_nix_bpf_free_all(struct roc_nix *roc_nix)
     523                 :            : {
     524                 :            :         struct nix *nix = roc_nix_to_nix_priv(roc_nix);
     525                 :            :         struct dev *dev = &nix->dev;
     526                 :          0 :         struct mbox *mbox = mbox_get(dev->mbox);
     527                 :            :         struct nix_bandprof_free_req *req;
     528                 :            :         int rc;
     529                 :            : 
     530                 :          0 :         req = mbox_alloc_msg_nix_bandprof_free(mbox);
     531         [ #  # ]:          0 :         if (req == NULL) {
     532                 :            :                 rc = -ENOSPC;
     533                 :          0 :                 goto exit;
     534                 :            :         }
     535                 :            : 
     536                 :          0 :         req->free_all = true;
     537                 :          0 :         rc = mbox_process(mbox);
     538                 :          0 : exit:
     539                 :            :         mbox_put(mbox);
     540                 :          0 :         return rc;
     541                 :            : }
     542                 :            : 
     543                 :            : int
     544                 :          0 : roc_nix_bpf_config(struct roc_nix *roc_nix, uint16_t id,
     545                 :            :                    enum roc_nix_bpf_level_flag lvl_flag,
     546                 :            :                    struct roc_nix_bpf_cfg *cfg)
     547                 :            : {
     548                 :          0 :         uint64_t exponent_p = 0, mantissa_p = 0, div_exp_p = 0;
     549                 :            :         struct nix *nix = roc_nix_to_nix_priv(roc_nix);
     550                 :            :         volatile struct nix_band_prof_s *prof, *prof_mask;
     551                 :            :         struct dev *dev = &nix->dev;
     552         [ #  # ]:          0 :         struct mbox *mbox = dev->mbox;
     553                 :            :         uint32_t policer_timeunit;
     554                 :            :         uint8_t level_idx;
     555                 :            :         int rc;
     556                 :            : 
     557         [ #  # ]:          0 :         if (roc_model_is_cn9k())
     558                 :            :                 return NIX_ERR_HW_NOTSUP;
     559                 :            : 
     560         [ #  # ]:          0 :         if (!cfg)
     561                 :            :                 return NIX_ERR_PARAM;
     562                 :            : 
     563                 :          0 :         rc = roc_nix_bpf_timeunit_get(roc_nix, &policer_timeunit);
     564         [ #  # ]:          0 :         if (rc)
     565                 :            :                 return rc;
     566                 :            : 
     567                 :          0 :         level_idx = roc_nix_bpf_level_to_idx(lvl_flag);
     568         [ #  # ]:          0 :         if (level_idx == ROC_NIX_BPF_LEVEL_IDX_INVALID)
     569                 :            :                 return NIX_ERR_PARAM;
     570                 :            : 
     571         [ #  # ]:          0 :         if (roc_model_is_cn10k()) {
     572                 :            :                 struct nix_cn10k_aq_enq_req *aq;
     573                 :            : 
     574                 :          0 :                 aq = mbox_alloc_msg_nix_cn10k_aq_enq(mbox_get(mbox));
     575         [ #  # ]:          0 :                 if (aq == NULL) {
     576                 :            :                         rc = -ENOSPC;
     577                 :          0 :                         goto exit;
     578                 :            :                 }
     579                 :          0 :                 aq->qidx = (sw_to_hw_lvl_map[level_idx] << 14) | id;
     580                 :          0 :                 aq->ctype = NIX_AQ_CTYPE_BAND_PROF;
     581                 :          0 :                 aq->op = NIX_AQ_INSTOP_WRITE;
     582                 :          0 :                 prof = &aq->prof;
     583                 :          0 :                 prof_mask = &aq->prof_mask;
     584                 :            :         } else {
     585                 :            :                 struct nix_cn20k_aq_enq_req *aq;
     586                 :            : 
     587                 :          0 :                 aq = mbox_alloc_msg_nix_cn20k_aq_enq(mbox_get(mbox));
     588         [ #  # ]:          0 :                 if (aq == NULL) {
     589                 :            :                         rc = -ENOSPC;
     590                 :          0 :                         goto exit;
     591                 :            :                 }
     592                 :          0 :                 aq->qidx = (sw_to_hw_lvl_map[level_idx] << 14) | id;
     593                 :          0 :                 aq->ctype = NIX_AQ_CTYPE_BAND_PROF;
     594                 :          0 :                 aq->op = NIX_AQ_INSTOP_WRITE;
     595                 :          0 :                 prof = &aq->prof;
     596                 :          0 :                 prof_mask = &aq->prof_mask;
     597                 :            :         }
     598                 :            : 
     599                 :          0 :         prof->adjust_exponent = NIX_BPF_DEFAULT_ADJUST_EXPONENT;
     600                 :          0 :         prof->adjust_mantissa = NIX_BPF_DEFAULT_ADJUST_MANTISSA;
     601         [ #  # ]:          0 :         if (cfg->lmode == ROC_NIX_BPF_LMODE_BYTE)
     602                 :          0 :                 prof->adjust_mantissa = NIX_BPF_DEFAULT_ADJUST_MANTISSA / 2;
     603                 :            : 
     604                 :          0 :         prof_mask->adjust_exponent = ~(prof_mask->adjust_exponent);
     605                 :          0 :         prof_mask->adjust_mantissa = ~(prof_mask->adjust_mantissa);
     606                 :            : 
     607   [ #  #  #  # ]:          0 :         switch (cfg->alg) {
     608                 :          0 :         case ROC_NIX_BPF_ALGO_2697:
     609                 :          0 :                 meter_rate_to_nix(cfg->algo2697.cir, &exponent_p, &mantissa_p,
     610                 :            :                                   &div_exp_p, policer_timeunit);
     611                 :          0 :                 prof->cir_mantissa = mantissa_p;
     612                 :          0 :                 prof->cir_exponent = exponent_p;
     613                 :            : 
     614                 :          0 :                 meter_burst_to_nix(cfg->algo2697.cbs, &exponent_p, &mantissa_p);
     615                 :          0 :                 prof->cbs_mantissa = mantissa_p;
     616                 :          0 :                 prof->cbs_exponent = exponent_p;
     617                 :            : 
     618                 :          0 :                 meter_burst_to_nix(cfg->algo2697.ebs, &exponent_p, &mantissa_p);
     619                 :          0 :                 prof->pebs_mantissa = mantissa_p;
     620                 :          0 :                 prof->pebs_exponent = exponent_p;
     621                 :            : 
     622                 :          0 :                 prof_mask->cir_mantissa = ~(prof_mask->cir_mantissa);
     623                 :          0 :                 prof_mask->cbs_mantissa = ~(prof_mask->cbs_mantissa);
     624                 :          0 :                 prof_mask->pebs_mantissa = ~(prof_mask->pebs_mantissa);
     625                 :          0 :                 prof_mask->cir_exponent = ~(prof_mask->cir_exponent);
     626                 :          0 :                 prof_mask->cbs_exponent = ~(prof_mask->cbs_exponent);
     627                 :          0 :                 prof_mask->pebs_exponent = ~(prof_mask->pebs_exponent);
     628                 :          0 :                 break;
     629                 :            : 
     630                 :          0 :         case ROC_NIX_BPF_ALGO_2698:
     631                 :          0 :                 meter_rate_to_nix(cfg->algo2698.cir, &exponent_p, &mantissa_p,
     632                 :            :                                   &div_exp_p, policer_timeunit);
     633                 :          0 :                 prof->cir_mantissa = mantissa_p;
     634                 :          0 :                 prof->cir_exponent = exponent_p;
     635                 :            : 
     636                 :          0 :                 meter_rate_to_nix(cfg->algo2698.pir, &exponent_p, &mantissa_p,
     637                 :            :                                   &div_exp_p, policer_timeunit);
     638                 :          0 :                 prof->peir_mantissa = mantissa_p;
     639                 :          0 :                 prof->peir_exponent = exponent_p;
     640                 :            : 
     641                 :          0 :                 meter_burst_to_nix(cfg->algo2698.cbs, &exponent_p, &mantissa_p);
     642                 :          0 :                 prof->cbs_mantissa = mantissa_p;
     643                 :          0 :                 prof->cbs_exponent = exponent_p;
     644                 :            : 
     645                 :          0 :                 meter_burst_to_nix(cfg->algo2698.pbs, &exponent_p, &mantissa_p);
     646                 :          0 :                 prof->pebs_mantissa = mantissa_p;
     647                 :          0 :                 prof->pebs_exponent = exponent_p;
     648                 :            : 
     649                 :          0 :                 prof_mask->cir_mantissa = ~(prof_mask->cir_mantissa);
     650                 :          0 :                 prof_mask->peir_mantissa = ~(prof_mask->peir_mantissa);
     651                 :          0 :                 prof_mask->cbs_mantissa = ~(prof_mask->cbs_mantissa);
     652                 :          0 :                 prof_mask->pebs_mantissa = ~(prof_mask->pebs_mantissa);
     653                 :          0 :                 prof_mask->cir_exponent = ~(prof_mask->cir_exponent);
     654                 :          0 :                 prof_mask->peir_exponent = ~(prof_mask->peir_exponent);
     655                 :          0 :                 prof_mask->cbs_exponent = ~(prof_mask->cbs_exponent);
     656                 :          0 :                 prof_mask->pebs_exponent = ~(prof_mask->pebs_exponent);
     657                 :          0 :                 break;
     658                 :            : 
     659                 :          0 :         case ROC_NIX_BPF_ALGO_4115:
     660                 :          0 :                 meter_rate_to_nix(cfg->algo4115.cir, &exponent_p, &mantissa_p,
     661                 :            :                                   &div_exp_p, policer_timeunit);
     662                 :          0 :                 prof->cir_mantissa = mantissa_p;
     663                 :          0 :                 prof->cir_exponent = exponent_p;
     664                 :            : 
     665                 :          0 :                 meter_rate_to_nix(cfg->algo4115.eir, &exponent_p, &mantissa_p,
     666                 :            :                                   &div_exp_p, policer_timeunit);
     667                 :          0 :                 prof->peir_mantissa = mantissa_p;
     668                 :          0 :                 prof->peir_exponent = exponent_p;
     669                 :            : 
     670                 :          0 :                 meter_burst_to_nix(cfg->algo4115.cbs, &exponent_p, &mantissa_p);
     671                 :          0 :                 prof->cbs_mantissa = mantissa_p;
     672                 :          0 :                 prof->cbs_exponent = exponent_p;
     673                 :            : 
     674                 :          0 :                 meter_burst_to_nix(cfg->algo4115.ebs, &exponent_p, &mantissa_p);
     675                 :          0 :                 prof->pebs_mantissa = mantissa_p;
     676                 :          0 :                 prof->pebs_exponent = exponent_p;
     677                 :            : 
     678                 :          0 :                 prof_mask->cir_mantissa = ~(prof_mask->cir_mantissa);
     679                 :          0 :                 prof_mask->peir_mantissa = ~(prof_mask->peir_mantissa);
     680                 :          0 :                 prof_mask->cbs_mantissa = ~(prof_mask->cbs_mantissa);
     681                 :          0 :                 prof_mask->pebs_mantissa = ~(prof_mask->pebs_mantissa);
     682                 :            : 
     683                 :          0 :                 prof_mask->cir_exponent = ~(prof_mask->cir_exponent);
     684                 :          0 :                 prof_mask->peir_exponent = ~(prof_mask->peir_exponent);
     685                 :          0 :                 prof_mask->cbs_exponent = ~(prof_mask->cbs_exponent);
     686                 :          0 :                 prof_mask->pebs_exponent = ~(prof_mask->pebs_exponent);
     687                 :          0 :                 break;
     688                 :            : 
     689                 :          0 :         default:
     690                 :            :                 rc = NIX_ERR_PARAM;
     691                 :          0 :                 goto exit;
     692                 :            :         }
     693                 :            : 
     694                 :          0 :         prof->lmode = cfg->lmode;
     695                 :          0 :         prof->icolor = cfg->icolor;
     696                 :          0 :         prof->meter_algo = cfg->alg;
     697                 :          0 :         prof->pc_mode = cfg->pc_mode;
     698                 :          0 :         prof->tnl_ena = cfg->tnl_ena;
     699                 :          0 :         prof->gc_action = cfg->action[ROC_NIX_BPF_COLOR_GREEN];
     700                 :          0 :         prof->yc_action = cfg->action[ROC_NIX_BPF_COLOR_YELLOW];
     701                 :          0 :         prof->rc_action = cfg->action[ROC_NIX_BPF_COLOR_RED];
     702                 :            : 
     703                 :          0 :         prof_mask->lmode = ~(prof_mask->lmode);
     704                 :          0 :         prof_mask->icolor = ~(prof_mask->icolor);
     705                 :          0 :         prof_mask->meter_algo = ~(prof_mask->meter_algo);
     706                 :          0 :         prof_mask->pc_mode = ~(prof_mask->pc_mode);
     707                 :          0 :         prof_mask->tnl_ena = ~(prof_mask->tnl_ena);
     708                 :          0 :         prof_mask->gc_action = ~(prof_mask->gc_action);
     709                 :          0 :         prof_mask->yc_action = ~(prof_mask->yc_action);
     710                 :          0 :         prof_mask->rc_action = ~(prof_mask->rc_action);
     711                 :            : 
     712                 :          0 :         rc = mbox_process(mbox);
     713                 :          0 : exit:
     714                 :            :         mbox_put(mbox);
     715                 :          0 :         return rc;
     716                 :            : }
     717                 :            : 
     718                 :            : int
     719                 :          0 : roc_nix_bpf_ena_dis(struct roc_nix *roc_nix, uint16_t id, struct roc_nix_rq *rq,
     720                 :            :                     bool enable)
     721                 :            : {
     722                 :            :         struct nix *nix = roc_nix_to_nix_priv(roc_nix);
     723                 :            :         struct dev *dev = &nix->dev;
     724                 :          0 :         struct mbox *mbox = mbox_get(dev->mbox);
     725                 :            :         int rc;
     726                 :            : 
     727         [ #  # ]:          0 :         if (roc_model_is_cn9k()) {
     728                 :            :                 rc = NIX_ERR_HW_NOTSUP;
     729                 :          0 :                 goto exit;
     730                 :            :         }
     731                 :            : 
     732         [ #  # ]:          0 :         if (rq->qid >= nix->nb_rx_queues) {
     733                 :            :                 rc =  NIX_ERR_QUEUE_INVALID_RANGE;
     734                 :          0 :                 goto exit;
     735                 :            :         }
     736                 :            : 
     737         [ #  # ]:          0 :         if (roc_model_is_cn10k()) {
     738                 :            :                 struct nix_cn10k_aq_enq_req *aq;
     739                 :            : 
     740                 :          0 :                 aq = mbox_alloc_msg_nix_cn10k_aq_enq(mbox);
     741         [ #  # ]:          0 :                 if (aq == NULL) {
     742                 :            :                         rc = -ENOSPC;
     743                 :          0 :                         goto exit;
     744                 :            :                 }
     745                 :          0 :                 aq->qidx = rq->qid;
     746                 :          0 :                 aq->ctype = NIX_AQ_CTYPE_RQ;
     747                 :          0 :                 aq->op = NIX_AQ_INSTOP_WRITE;
     748                 :            : 
     749                 :          0 :                 aq->rq.policer_ena = enable;
     750                 :          0 :                 aq->rq_mask.policer_ena = ~(aq->rq_mask.policer_ena);
     751         [ #  # ]:          0 :                 if (enable) {
     752                 :          0 :                         aq->rq.band_prof_id = id;
     753                 :          0 :                         aq->rq_mask.band_prof_id = ~(aq->rq_mask.band_prof_id);
     754                 :            :                 }
     755                 :            : 
     756                 :          0 :                 rc = mbox_process(mbox);
     757         [ #  # ]:          0 :                 if (rc)
     758                 :          0 :                         goto exit;
     759                 :            :         } else {
     760                 :            :                 struct nix_cn20k_aq_enq_req *aq;
     761                 :            : 
     762                 :          0 :                 aq = mbox_alloc_msg_nix_cn20k_aq_enq(mbox);
     763         [ #  # ]:          0 :                 if (aq == NULL) {
     764                 :            :                         rc = -ENOSPC;
     765                 :          0 :                         goto exit;
     766                 :            :                 }
     767                 :          0 :                 aq->qidx = rq->qid;
     768                 :          0 :                 aq->ctype = NIX_AQ_CTYPE_RQ;
     769                 :          0 :                 aq->op = NIX_AQ_INSTOP_WRITE;
     770                 :            : 
     771                 :          0 :                 aq->rq.policer_ena = enable;
     772                 :          0 :                 aq->rq_mask.policer_ena = ~(aq->rq_mask.policer_ena);
     773         [ #  # ]:          0 :                 if (enable) {
     774                 :          0 :                         aq->rq.band_prof_id_l = id & 0x3FF;
     775                 :          0 :                         aq->rq.band_prof_id_h = (id >> 10) & 0xF;
     776                 :          0 :                         aq->rq_mask.band_prof_id_l = ~(aq->rq_mask.band_prof_id_l);
     777                 :          0 :                         aq->rq_mask.band_prof_id_h = ~(aq->rq_mask.band_prof_id_h);
     778                 :            :                 }
     779                 :            : 
     780                 :          0 :                 rc = mbox_process(mbox);
     781         [ #  # ]:          0 :                 if (rc)
     782                 :          0 :                         goto exit;
     783                 :            :         }
     784                 :            : 
     785                 :          0 :         rq->bpf_id = id;
     786                 :            : 
     787                 :          0 : exit:
     788                 :            :         mbox_put(mbox);
     789                 :          0 :         return rc;
     790                 :            : }
     791                 :            : 
     792                 :            : int
     793                 :          0 : roc_nix_bpf_dump(struct roc_nix *roc_nix, uint16_t id,
     794                 :            :                  enum roc_nix_bpf_level_flag lvl_flag)
     795                 :            : {
     796                 :            :         struct nix *nix = roc_nix_to_nix_priv(roc_nix);
     797                 :            :         struct dev *dev = &nix->dev;
     798                 :          0 :         struct mbox *mbox = mbox_get(dev->mbox);
     799                 :            :         volatile struct nix_band_prof_s *prof;
     800                 :            :         uint8_t level_idx;
     801                 :            :         int rc;
     802                 :            : 
     803         [ #  # ]:          0 :         if (roc_model_is_cn9k()) {
     804                 :            :                 rc = NIX_ERR_HW_NOTSUP;
     805                 :          0 :                 goto exit;
     806                 :            :         }
     807                 :            : 
     808                 :          0 :         level_idx = roc_nix_bpf_level_to_idx(lvl_flag);
     809         [ #  # ]:          0 :         if (level_idx == ROC_NIX_BPF_LEVEL_IDX_INVALID) {
     810                 :            :                 rc = NIX_ERR_PARAM;
     811                 :          0 :                 goto exit;
     812                 :            :         }
     813         [ #  # ]:          0 :         if (roc_model_is_cn10k()) {
     814                 :            :                 struct nix_cn10k_aq_enq_rsp *rsp;
     815                 :            :                 struct nix_cn10k_aq_enq_req *aq;
     816                 :            : 
     817                 :          0 :                 aq = mbox_alloc_msg_nix_cn10k_aq_enq(mbox);
     818         [ #  # ]:          0 :                 if (aq == NULL) {
     819                 :            :                         rc = -ENOSPC;
     820                 :          0 :                         goto exit;
     821                 :            :                 }
     822                 :          0 :                 aq->qidx = (sw_to_hw_lvl_map[level_idx] << 14 | id);
     823                 :          0 :                 aq->ctype = NIX_AQ_CTYPE_BAND_PROF;
     824                 :          0 :                 aq->op = NIX_AQ_INSTOP_READ;
     825                 :            :                 rc = mbox_process_msg(mbox, (void *)&rsp);
     826         [ #  # ]:          0 :                 if (rc)
     827                 :          0 :                         goto exit;
     828                 :          0 :                 prof = &rsp->prof;
     829                 :            :         } else {
     830                 :            :                 struct nix_cn20k_aq_enq_rsp *rsp;
     831                 :            :                 struct nix_cn20k_aq_enq_req *aq;
     832                 :            : 
     833                 :          0 :                 aq = mbox_alloc_msg_nix_cn20k_aq_enq(mbox);
     834         [ #  # ]:          0 :                 if (aq == NULL) {
     835                 :            :                         rc = -ENOSPC;
     836                 :          0 :                         goto exit;
     837                 :            :                 }
     838                 :          0 :                 aq->qidx = (sw_to_hw_lvl_map[level_idx] << 14 | id);
     839                 :          0 :                 aq->ctype = NIX_AQ_CTYPE_BAND_PROF;
     840                 :          0 :                 aq->op = NIX_AQ_INSTOP_READ;
     841                 :            :                 rc = mbox_process_msg(mbox, (void *)&rsp);
     842         [ #  # ]:          0 :                 if (rc)
     843                 :          0 :                         goto exit;
     844                 :          0 :                 prof = &rsp->prof;
     845                 :            :         }
     846                 :            :         if (!rc) {
     847                 :          0 :                 plt_dump("============= band prof id =%d ===============", id);
     848                 :          0 :                 nix_lf_bpf_dump(prof);
     849                 :            :         }
     850                 :          0 : exit:
     851                 :            :         mbox_put(mbox);
     852                 :          0 :         return rc;
     853                 :            : }
     854                 :            : 
     855                 :            : int
     856                 :          0 : roc_nix_bpf_pre_color_tbl_setup(struct roc_nix *roc_nix, uint16_t id,
     857                 :            :                                 enum roc_nix_bpf_level_flag lvl_flag,
     858                 :            :                                 struct roc_nix_bpf_precolor *tbl)
     859                 :            : {
     860                 :            :         struct nix *nix = roc_nix_to_nix_priv(roc_nix);
     861                 :            :         struct dev *dev = &nix->dev;
     862                 :          0 :         struct mbox *mbox = dev->mbox;
     863                 :            :         uint8_t pc_mode, tn_ena;
     864                 :            :         uint8_t level_idx;
     865                 :            :         int rc;
     866                 :            : 
     867   [ #  #  #  # ]:          0 :         if (!tbl || !tbl->count)
     868                 :            :                 return NIX_ERR_PARAM;
     869                 :            : 
     870         [ #  # ]:          0 :         if (roc_model_is_cn9k())
     871                 :            :                 return NIX_ERR_HW_NOTSUP;
     872                 :            : 
     873                 :          0 :         level_idx = roc_nix_bpf_level_to_idx(lvl_flag);
     874         [ #  # ]:          0 :         if (level_idx == ROC_NIX_BPF_LEVEL_IDX_INVALID)
     875                 :            :                 return NIX_ERR_PARAM;
     876                 :            : 
     877   [ #  #  #  #  :          0 :         switch (tbl->mode) {
                      # ]
     878                 :          0 :         case ROC_NIX_BPF_PC_MODE_VLAN_INNER:
     879                 :            :         case ROC_NIX_BPF_PC_MODE_VLAN_OUTER:
     880         [ #  # ]:          0 :                 if (tbl->count != NIX_BPF_PRECOLOR_VLAN_TABLE_SIZE) {
     881                 :          0 :                         plt_err("Table size must be %d",
     882                 :            :                                 NIX_BPF_PRECOLOR_VLAN_TABLE_SIZE);
     883                 :            :                         rc = NIX_ERR_PARAM;
     884                 :          0 :                         goto exit;
     885                 :            :                 }
     886                 :            :                 tn_ena = nix_precolor_vlan_table_update(roc_nix, tbl);
     887                 :            :                 pc_mode = NIX_RX_BAND_PROF_PC_MODE_VLAN;
     888                 :          0 :                 break;
     889                 :          0 :         case ROC_NIX_BPF_PC_MODE_DSCP_INNER:
     890         [ #  # ]:          0 :                 if (tbl->count != NIX_BPF_PRECOLOR_DSCP_TABLE_SIZE) {
     891                 :          0 :                         plt_err("Table size must be %d",
     892                 :            :                                 NIX_BPF_PRECOLOR_DSCP_TABLE_SIZE);
     893                 :            :                         rc = NIX_ERR_PARAM;
     894                 :          0 :                         goto exit;
     895                 :            :                 }
     896                 :          0 :                 tn_ena = nix_precolor_inner_dscp_table_update(roc_nix, tbl);
     897                 :            :                 pc_mode = NIX_RX_BAND_PROF_PC_MODE_DSCP;
     898                 :          0 :                 break;
     899                 :          0 :         case ROC_NIX_BPF_PC_MODE_DSCP_OUTER:
     900         [ #  # ]:          0 :                 if (tbl->count != NIX_BPF_PRECOLOR_DSCP_TABLE_SIZE) {
     901                 :          0 :                         plt_err("Table size must be %d",
     902                 :            :                                 NIX_BPF_PRECOLOR_DSCP_TABLE_SIZE);
     903                 :            :                         rc = NIX_ERR_PARAM;
     904                 :          0 :                         goto exit;
     905                 :            :                 }
     906                 :          0 :                 tn_ena = nix_precolor_outer_dscp_table_update(roc_nix, tbl);
     907                 :            :                 pc_mode = NIX_RX_BAND_PROF_PC_MODE_DSCP;
     908                 :          0 :                 break;
     909                 :          0 :         case ROC_NIX_BPF_PC_MODE_GEN_INNER:
     910                 :            :         case ROC_NIX_BPF_PC_MODE_GEN_OUTER:
     911         [ #  # ]:          0 :                 if (tbl->count != NIX_BPF_PRECOLOR_GEN_TABLE_SIZE) {
     912                 :          0 :                         plt_err("Table size must be %d",
     913                 :            :                                 NIX_BPF_PRECOLOR_GEN_TABLE_SIZE);
     914                 :            :                         rc = NIX_ERR_PARAM;
     915                 :          0 :                         goto exit;
     916                 :            :                 }
     917                 :            : 
     918                 :            :                 tn_ena = nix_precolor_gen_table_update(roc_nix, tbl);
     919                 :            :                 pc_mode = NIX_RX_BAND_PROF_PC_MODE_GEN;
     920                 :          0 :                 break;
     921                 :          0 :         default:
     922                 :            :                 rc = NIX_ERR_PARAM;
     923                 :          0 :                 goto exit;
     924                 :            :         }
     925                 :            : 
     926         [ #  # ]:          0 :         if (roc_model_is_cn10k()) {
     927                 :            :                 struct nix_cn10k_aq_enq_req *aq;
     928                 :            : 
     929                 :            :                 /* Update corresponding bandwidth profile too */
     930                 :          0 :                 aq = mbox_alloc_msg_nix_cn10k_aq_enq(mbox_get(mbox));
     931         [ #  # ]:          0 :                 if (aq == NULL) {
     932                 :            :                         rc = -ENOSPC;
     933                 :          0 :                         goto exit;
     934                 :            :                 }
     935                 :          0 :                 aq->qidx = (sw_to_hw_lvl_map[level_idx] << 14) | id;
     936                 :          0 :                 aq->ctype = NIX_AQ_CTYPE_BAND_PROF;
     937                 :          0 :                 aq->op = NIX_AQ_INSTOP_WRITE;
     938                 :          0 :                 aq->prof.pc_mode = pc_mode;
     939                 :          0 :                 aq->prof.tnl_ena = tn_ena;
     940                 :          0 :                 aq->prof_mask.pc_mode = ~(aq->prof_mask.pc_mode);
     941                 :          0 :                 aq->prof_mask.tnl_ena = ~(aq->prof_mask.tnl_ena);
     942                 :            : 
     943                 :          0 :                 rc = mbox_process(mbox);
     944                 :            :         } else {
     945                 :            :                 struct nix_cn20k_aq_enq_req *aq;
     946                 :            : 
     947                 :            :                 /* Update corresponding bandwidth profile too */
     948                 :          0 :                 aq = mbox_alloc_msg_nix_cn20k_aq_enq(mbox_get(mbox));
     949         [ #  # ]:          0 :                 if (aq == NULL) {
     950                 :            :                         rc = -ENOSPC;
     951                 :          0 :                         goto exit;
     952                 :            :                 }
     953                 :          0 :                 aq->qidx = (sw_to_hw_lvl_map[level_idx] << 14) | id;
     954                 :          0 :                 aq->ctype = NIX_AQ_CTYPE_BAND_PROF;
     955                 :          0 :                 aq->op = NIX_AQ_INSTOP_WRITE;
     956                 :          0 :                 aq->prof.pc_mode = pc_mode;
     957                 :          0 :                 aq->prof.tnl_ena = tn_ena;
     958                 :          0 :                 aq->prof_mask.pc_mode = ~(aq->prof_mask.pc_mode);
     959                 :          0 :                 aq->prof_mask.tnl_ena = ~(aq->prof_mask.tnl_ena);
     960                 :            : 
     961                 :          0 :                 rc = mbox_process(mbox);
     962                 :            :         }
     963                 :            : 
     964                 :          0 : exit:
     965                 :            :         mbox_put(mbox);
     966                 :          0 :         return rc;
     967                 :            : }
     968                 :            : 
     969                 :            : int
     970                 :          0 : roc_nix_bpf_connect(struct roc_nix *roc_nix,
     971                 :            :                     enum roc_nix_bpf_level_flag lvl_flag, uint16_t src_id,
     972                 :            :                     uint16_t dst_id)
     973                 :            : {
     974                 :            :         struct nix *nix = roc_nix_to_nix_priv(roc_nix);
     975                 :            :         volatile struct nix_band_prof_s *prof, *prof_mask;
     976                 :            :         struct dev *dev = &nix->dev;
     977                 :          0 :         struct mbox *mbox = mbox_get(dev->mbox);
     978                 :            :         uint8_t level_idx;
     979                 :            :         int rc;
     980                 :            : 
     981         [ #  # ]:          0 :         if (roc_model_is_cn9k()) {
     982                 :            :                 rc = NIX_ERR_HW_NOTSUP;
     983                 :          0 :                 goto exit;
     984                 :            :         }
     985                 :            : 
     986                 :          0 :         level_idx = roc_nix_bpf_level_to_idx(lvl_flag);
     987         [ #  # ]:          0 :         if (level_idx == ROC_NIX_BPF_LEVEL_IDX_INVALID) {
     988                 :            :                 rc = NIX_ERR_PARAM;
     989                 :          0 :                 goto exit;
     990                 :            :         }
     991                 :            : 
     992         [ #  # ]:          0 :         if (roc_model_is_cn10k()) {
     993                 :            :                 struct nix_cn10k_aq_enq_req *aq;
     994                 :            : 
     995                 :          0 :                 aq = mbox_alloc_msg_nix_cn10k_aq_enq(mbox);
     996         [ #  # ]:          0 :                 if (aq == NULL) {
     997                 :            :                         rc = -ENOSPC;
     998                 :          0 :                         goto exit;
     999                 :            :                 }
    1000                 :          0 :                 aq->qidx = (sw_to_hw_lvl_map[level_idx] << 14) | src_id;
    1001                 :          0 :                 aq->ctype = NIX_AQ_CTYPE_BAND_PROF;
    1002                 :          0 :                 aq->op = NIX_AQ_INSTOP_WRITE;
    1003                 :          0 :                 prof = &aq->prof;
    1004                 :          0 :                 prof_mask = &aq->prof_mask;
    1005                 :            :         } else {
    1006                 :            :                 struct nix_cn20k_aq_enq_req *aq;
    1007                 :            : 
    1008                 :          0 :                 aq = mbox_alloc_msg_nix_cn20k_aq_enq(mbox);
    1009         [ #  # ]:          0 :                 if (aq == NULL) {
    1010                 :            :                         rc = -ENOSPC;
    1011                 :          0 :                         goto exit;
    1012                 :            :                 }
    1013                 :          0 :                 aq->qidx = (sw_to_hw_lvl_map[level_idx] << 14) | src_id;
    1014                 :          0 :                 aq->ctype = NIX_AQ_CTYPE_BAND_PROF;
    1015                 :          0 :                 aq->op = NIX_AQ_INSTOP_WRITE;
    1016                 :          0 :                 prof = &aq->prof;
    1017                 :          0 :                 prof_mask = &aq->prof_mask;
    1018                 :            :         }
    1019                 :            : 
    1020         [ #  # ]:          0 :         if (dst_id == ROC_NIX_BPF_ID_INVALID) {
    1021                 :          0 :                 prof->hl_en = false;
    1022                 :          0 :                 prof_mask->hl_en = ~(prof_mask->hl_en);
    1023                 :            :         } else {
    1024                 :          0 :                 prof->hl_en = true;
    1025                 :          0 :                 prof->band_prof_id = dst_id;
    1026                 :          0 :                 prof_mask->hl_en = ~(prof_mask->hl_en);
    1027                 :          0 :                 prof_mask->band_prof_id = ~(prof_mask->band_prof_id);
    1028                 :            :         }
    1029                 :            : 
    1030                 :          0 :         rc = mbox_process(mbox);
    1031                 :          0 : exit:
    1032                 :            :         mbox_put(mbox);
    1033                 :          0 :         return rc;
    1034                 :            : }
    1035                 :            : 
    1036                 :            : int
    1037                 :          0 : roc_nix_bpf_stats_read(struct roc_nix *roc_nix, uint16_t id, uint64_t mask,
    1038                 :            :                        enum roc_nix_bpf_level_flag lvl_flag,
    1039                 :            :                        uint64_t stats[ROC_NIX_BPF_STATS_MAX])
    1040                 :            : {
    1041                 :            :         uint8_t yellow_pkt_pass, yellow_octs_pass, yellow_pkt_drop;
    1042                 :            :         uint8_t green_octs_drop, yellow_octs_drop, red_octs_drop;
    1043                 :            :         uint8_t green_pkt_pass, green_octs_pass, green_pkt_drop;
    1044                 :            :         uint8_t red_pkt_pass, red_octs_pass, red_pkt_drop;
    1045                 :            :         struct nix *nix = roc_nix_to_nix_priv(roc_nix);
    1046                 :            :         struct dev *dev = &nix->dev;
    1047                 :          0 :         struct mbox *mbox = mbox_get(dev->mbox);
    1048                 :            :         volatile struct nix_band_prof_s *prof;
    1049                 :            :         uint8_t level_idx;
    1050                 :            :         int rc;
    1051                 :            : 
    1052         [ #  # ]:          0 :         if (roc_model_is_cn9k()) {
    1053                 :            :                 rc = NIX_ERR_HW_NOTSUP;
    1054                 :          0 :                 goto exit;
    1055                 :            :         }
    1056                 :            : 
    1057                 :          0 :         level_idx = roc_nix_bpf_level_to_idx(lvl_flag);
    1058         [ #  # ]:          0 :         if (level_idx == ROC_NIX_BPF_LEVEL_IDX_INVALID) {
    1059                 :            :                 rc = NIX_ERR_PARAM;
    1060                 :          0 :                 goto exit;
    1061                 :            :         }
    1062                 :            : 
    1063         [ #  # ]:          0 :         if (roc_model_is_cn10k()) {
    1064                 :            :                 struct nix_cn10k_aq_enq_rsp *rsp;
    1065                 :            :                 struct nix_cn10k_aq_enq_req *aq;
    1066                 :            : 
    1067                 :          0 :                 aq = mbox_alloc_msg_nix_cn10k_aq_enq(mbox);
    1068         [ #  # ]:          0 :                 if (aq == NULL) {
    1069                 :            :                         rc = -ENOSPC;
    1070                 :          0 :                         goto exit;
    1071                 :            :                 }
    1072                 :          0 :                 aq->qidx = (sw_to_hw_lvl_map[level_idx] << 14 | id);
    1073                 :          0 :                 aq->ctype = NIX_AQ_CTYPE_BAND_PROF;
    1074                 :          0 :                 aq->op = NIX_AQ_INSTOP_READ;
    1075                 :            :                 rc = mbox_process_msg(mbox, (void *)&rsp);
    1076         [ #  # ]:          0 :                 if (rc)
    1077                 :          0 :                         goto exit;
    1078                 :          0 :                 prof = &rsp->prof;
    1079                 :            :         } else {
    1080                 :            :                 struct nix_cn20k_aq_enq_rsp *rsp;
    1081                 :            :                 struct nix_cn20k_aq_enq_req *aq;
    1082                 :            : 
    1083                 :          0 :                 aq = mbox_alloc_msg_nix_cn20k_aq_enq(mbox);
    1084         [ #  # ]:          0 :                 if (aq == NULL) {
    1085                 :            :                         rc = -ENOSPC;
    1086                 :          0 :                         goto exit;
    1087                 :            :                 }
    1088                 :          0 :                 aq->qidx = (sw_to_hw_lvl_map[level_idx] << 14 | id);
    1089                 :          0 :                 aq->ctype = NIX_AQ_CTYPE_BAND_PROF;
    1090                 :          0 :                 aq->op = NIX_AQ_INSTOP_READ;
    1091                 :            :                 rc = mbox_process_msg(mbox, (void *)&rsp);
    1092         [ #  # ]:          0 :                 if (rc)
    1093                 :          0 :                         goto exit;
    1094                 :          0 :                 prof = &rsp->prof;
    1095                 :            :         }
    1096                 :            : 
    1097                 :            :         green_pkt_pass =
    1098                 :          0 :                 roc_nix_bpf_stats_to_idx(mask & ROC_NIX_BPF_GREEN_PKT_F_PASS);
    1099                 :            :         green_octs_pass =
    1100                 :          0 :                 roc_nix_bpf_stats_to_idx(mask & ROC_NIX_BPF_GREEN_OCTS_F_PASS);
    1101                 :            :         green_pkt_drop =
    1102                 :          0 :                 roc_nix_bpf_stats_to_idx(mask & ROC_NIX_BPF_GREEN_PKT_F_DROP);
    1103                 :            :         green_octs_drop =
    1104                 :          0 :                 roc_nix_bpf_stats_to_idx(mask & ROC_NIX_BPF_GREEN_OCTS_F_DROP);
    1105                 :            :         yellow_pkt_pass =
    1106                 :          0 :                 roc_nix_bpf_stats_to_idx(mask & ROC_NIX_BPF_YELLOW_PKT_F_PASS);
    1107                 :            :         yellow_octs_pass =
    1108                 :          0 :                 roc_nix_bpf_stats_to_idx(mask & ROC_NIX_BPF_YELLOW_OCTS_F_PASS);
    1109                 :            :         yellow_pkt_drop =
    1110                 :          0 :                 roc_nix_bpf_stats_to_idx(mask & ROC_NIX_BPF_YELLOW_PKT_F_DROP);
    1111                 :            :         yellow_octs_drop =
    1112                 :          0 :                 roc_nix_bpf_stats_to_idx(mask & ROC_NIX_BPF_YELLOW_OCTS_F_DROP);
    1113                 :            :         red_pkt_pass =
    1114                 :          0 :                 roc_nix_bpf_stats_to_idx(mask & ROC_NIX_BPF_RED_PKT_F_PASS);
    1115                 :            :         red_octs_pass =
    1116                 :          0 :                 roc_nix_bpf_stats_to_idx(mask & ROC_NIX_BPF_RED_OCTS_F_PASS);
    1117                 :            :         red_pkt_drop =
    1118                 :          0 :                 roc_nix_bpf_stats_to_idx(mask & ROC_NIX_BPF_RED_PKT_F_DROP);
    1119                 :            :         red_octs_drop =
    1120                 :          0 :                 roc_nix_bpf_stats_to_idx(mask & ROC_NIX_BPF_RED_OCTS_F_DROP);
    1121                 :            : 
    1122         [ #  # ]:          0 :         if (green_pkt_pass != ROC_NIX_BPF_STATS_MAX)
    1123                 :          0 :                 stats[green_pkt_pass] = prof->green_pkt_pass;
    1124                 :            : 
    1125         [ #  # ]:          0 :         if (green_octs_pass != ROC_NIX_BPF_STATS_MAX)
    1126                 :          0 :                 stats[green_octs_pass] = prof->green_octs_pass;
    1127                 :            : 
    1128         [ #  # ]:          0 :         if (green_pkt_drop != ROC_NIX_BPF_STATS_MAX)
    1129                 :          0 :                 stats[green_pkt_drop] = prof->green_pkt_drop;
    1130                 :            : 
    1131         [ #  # ]:          0 :         if (green_octs_drop != ROC_NIX_BPF_STATS_MAX)
    1132                 :          0 :                 stats[green_octs_drop] = prof->green_octs_pass;
    1133                 :            : 
    1134         [ #  # ]:          0 :         if (yellow_pkt_pass != ROC_NIX_BPF_STATS_MAX)
    1135                 :          0 :                 stats[yellow_pkt_pass] = prof->yellow_pkt_pass;
    1136                 :            : 
    1137         [ #  # ]:          0 :         if (yellow_octs_pass != ROC_NIX_BPF_STATS_MAX)
    1138                 :          0 :                 stats[yellow_octs_pass] = prof->yellow_octs_pass;
    1139                 :            : 
    1140         [ #  # ]:          0 :         if (yellow_pkt_drop != ROC_NIX_BPF_STATS_MAX)
    1141                 :          0 :                 stats[yellow_pkt_drop] = prof->yellow_pkt_drop;
    1142                 :            : 
    1143         [ #  # ]:          0 :         if (yellow_octs_drop != ROC_NIX_BPF_STATS_MAX)
    1144                 :          0 :                 stats[yellow_octs_drop] = prof->yellow_octs_drop;
    1145                 :            : 
    1146         [ #  # ]:          0 :         if (red_pkt_pass != ROC_NIX_BPF_STATS_MAX)
    1147                 :          0 :                 stats[red_pkt_pass] = prof->red_pkt_pass;
    1148                 :            : 
    1149         [ #  # ]:          0 :         if (red_octs_pass != ROC_NIX_BPF_STATS_MAX)
    1150                 :          0 :                 stats[red_octs_pass] = prof->red_octs_pass;
    1151                 :            : 
    1152         [ #  # ]:          0 :         if (red_pkt_drop != ROC_NIX_BPF_STATS_MAX)
    1153                 :          0 :                 stats[red_pkt_drop] = prof->red_pkt_drop;
    1154                 :            : 
    1155         [ #  # ]:          0 :         if (red_octs_drop != ROC_NIX_BPF_STATS_MAX)
    1156                 :          0 :                 stats[red_octs_drop] = prof->red_octs_drop;
    1157                 :            : 
    1158                 :            :         rc = 0;
    1159                 :          0 : exit:
    1160                 :            :         mbox_put(mbox);
    1161                 :          0 :         return rc;
    1162                 :            : }
    1163                 :            : 
    1164                 :            : int
    1165                 :          0 : roc_nix_bpf_stats_reset(struct roc_nix *roc_nix, uint16_t id, uint64_t mask,
    1166                 :            :                         enum roc_nix_bpf_level_flag lvl_flag)
    1167                 :            : {
    1168                 :            :         struct nix *nix = roc_nix_to_nix_priv(roc_nix);
    1169                 :            :         volatile struct nix_band_prof_s *prof, *prof_mask;
    1170                 :            :         struct dev *dev = &nix->dev;
    1171                 :          0 :         struct mbox *mbox = mbox_get(dev->mbox);
    1172                 :            :         uint8_t level_idx;
    1173                 :            :         int rc;
    1174                 :            : 
    1175         [ #  # ]:          0 :         if (roc_model_is_cn9k()) {
    1176                 :            :                 rc = NIX_ERR_HW_NOTSUP;
    1177                 :          0 :                 goto exit;
    1178                 :            :         }
    1179                 :            : 
    1180                 :          0 :         level_idx = roc_nix_bpf_level_to_idx(lvl_flag);
    1181         [ #  # ]:          0 :         if (level_idx == ROC_NIX_BPF_LEVEL_IDX_INVALID) {
    1182                 :            :                 rc = NIX_ERR_PARAM;
    1183                 :          0 :                 goto exit;
    1184                 :            :         }
    1185                 :            : 
    1186         [ #  # ]:          0 :         if (roc_model_is_cn10k()) {
    1187                 :            :                 struct nix_cn10k_aq_enq_req *aq;
    1188                 :            : 
    1189                 :          0 :                 aq = mbox_alloc_msg_nix_cn10k_aq_enq(mbox);
    1190         [ #  # ]:          0 :                 if (aq == NULL) {
    1191                 :            :                         rc = -ENOSPC;
    1192                 :          0 :                         goto exit;
    1193                 :            :                 }
    1194                 :          0 :                 aq->qidx = (sw_to_hw_lvl_map[level_idx] << 14 | id);
    1195                 :          0 :                 aq->ctype = NIX_AQ_CTYPE_BAND_PROF;
    1196                 :          0 :                 aq->op = NIX_AQ_INSTOP_WRITE;
    1197                 :          0 :                 prof = &aq->prof;
    1198                 :          0 :                 prof_mask = &aq->prof_mask;
    1199                 :            :         } else {
    1200                 :            :                 struct nix_cn20k_aq_enq_req *aq;
    1201                 :            : 
    1202                 :          0 :                 aq = mbox_alloc_msg_nix_cn20k_aq_enq(mbox);
    1203         [ #  # ]:          0 :                 if (aq == NULL) {
    1204                 :            :                         rc = -ENOSPC;
    1205                 :          0 :                         goto exit;
    1206                 :            :                 }
    1207                 :          0 :                 aq->qidx = (sw_to_hw_lvl_map[level_idx] << 14 | id);
    1208                 :          0 :                 aq->ctype = NIX_AQ_CTYPE_BAND_PROF;
    1209                 :          0 :                 aq->op = NIX_AQ_INSTOP_WRITE;
    1210                 :          0 :                 prof = &aq->prof;
    1211                 :          0 :                 prof_mask = &aq->prof_mask;
    1212                 :            :         }
    1213                 :            : 
    1214         [ #  # ]:          0 :         if (mask & ROC_NIX_BPF_GREEN_PKT_F_PASS) {
    1215                 :          0 :                 prof->green_pkt_pass = 0;
    1216                 :          0 :                 prof_mask->green_pkt_pass = ~(prof_mask->green_pkt_pass);
    1217                 :            :         }
    1218         [ #  # ]:          0 :         if (mask & ROC_NIX_BPF_GREEN_OCTS_F_PASS) {
    1219                 :          0 :                 prof->green_octs_pass = 0;
    1220                 :          0 :                 prof_mask->green_octs_pass = ~(prof_mask->green_octs_pass);
    1221                 :            :         }
    1222         [ #  # ]:          0 :         if (mask & ROC_NIX_BPF_GREEN_PKT_F_DROP) {
    1223                 :          0 :                 prof->green_pkt_drop = 0;
    1224                 :          0 :                 prof_mask->green_pkt_drop = ~(prof_mask->green_pkt_drop);
    1225                 :            :         }
    1226         [ #  # ]:          0 :         if (mask & ROC_NIX_BPF_GREEN_OCTS_F_DROP) {
    1227                 :          0 :                 prof->green_octs_drop = 0;
    1228                 :          0 :                 prof_mask->green_octs_drop = ~(prof_mask->green_octs_drop);
    1229                 :            :         }
    1230         [ #  # ]:          0 :         if (mask & ROC_NIX_BPF_YELLOW_PKT_F_PASS) {
    1231                 :          0 :                 prof->yellow_pkt_pass = 0;
    1232                 :          0 :                 prof_mask->yellow_pkt_pass = ~(prof_mask->yellow_pkt_pass);
    1233                 :            :         }
    1234         [ #  # ]:          0 :         if (mask & ROC_NIX_BPF_YELLOW_OCTS_F_PASS) {
    1235                 :          0 :                 prof->yellow_octs_pass = 0;
    1236                 :          0 :                 prof_mask->yellow_octs_pass = ~(prof_mask->yellow_octs_pass);
    1237                 :            :         }
    1238         [ #  # ]:          0 :         if (mask & ROC_NIX_BPF_YELLOW_PKT_F_DROP) {
    1239                 :          0 :                 prof->yellow_pkt_drop = 0;
    1240                 :          0 :                 prof_mask->yellow_pkt_drop = ~(prof_mask->yellow_pkt_drop);
    1241                 :            :         }
    1242         [ #  # ]:          0 :         if (mask & ROC_NIX_BPF_YELLOW_OCTS_F_DROP) {
    1243                 :          0 :                 prof->yellow_octs_drop = 0;
    1244                 :          0 :                 prof_mask->yellow_octs_drop = ~(prof_mask->yellow_octs_drop);
    1245                 :            :         }
    1246         [ #  # ]:          0 :         if (mask & ROC_NIX_BPF_RED_PKT_F_PASS) {
    1247                 :          0 :                 prof->red_pkt_pass = 0;
    1248                 :          0 :                 prof_mask->red_pkt_pass = ~(prof_mask->red_pkt_pass);
    1249                 :            :         }
    1250         [ #  # ]:          0 :         if (mask & ROC_NIX_BPF_RED_OCTS_F_PASS) {
    1251                 :          0 :                 prof->red_octs_pass = 0;
    1252                 :          0 :                 prof_mask->red_octs_pass = ~(prof_mask->red_octs_pass);
    1253                 :            :         }
    1254         [ #  # ]:          0 :         if (mask & ROC_NIX_BPF_RED_PKT_F_DROP) {
    1255                 :          0 :                 prof->red_pkt_drop = 0;
    1256                 :          0 :                 prof_mask->red_pkt_drop = ~(prof_mask->red_pkt_drop);
    1257                 :            :         }
    1258         [ #  # ]:          0 :         if (mask & ROC_NIX_BPF_RED_OCTS_F_DROP) {
    1259                 :          0 :                 prof->red_octs_drop = 0;
    1260                 :          0 :                 prof_mask->red_octs_drop = ~(prof_mask->red_octs_drop);
    1261                 :            :         }
    1262                 :            : 
    1263                 :          0 :         rc = mbox_process(mbox);
    1264                 :          0 : exit:
    1265                 :            :         mbox_put(mbox);
    1266                 :          0 :         return rc;
    1267                 :            : }
    1268                 :            : 
    1269                 :            : int
    1270                 :          0 : roc_nix_bpf_lf_stats_read(struct roc_nix *roc_nix, uint64_t mask,
    1271                 :            :                           uint64_t stats[ROC_NIX_BPF_STATS_MAX])
    1272                 :            : {
    1273                 :            :         uint8_t yellow_pkt_pass, yellow_octs_pass, yellow_pkt_drop;
    1274                 :            :         uint8_t green_octs_drop, yellow_octs_drop, red_octs_drop;
    1275                 :            :         uint8_t green_pkt_pass, green_octs_pass, green_pkt_drop;
    1276                 :            :         uint8_t red_pkt_pass, red_octs_pass, red_pkt_drop;
    1277                 :            :         struct nix *nix = roc_nix_to_nix_priv(roc_nix);
    1278                 :            : 
    1279                 :            :         green_pkt_pass =
    1280                 :          0 :                 roc_nix_bpf_stats_to_idx(mask & ROC_NIX_BPF_GREEN_PKT_F_PASS);
    1281                 :            :         green_octs_pass =
    1282                 :          0 :                 roc_nix_bpf_stats_to_idx(mask & ROC_NIX_BPF_GREEN_OCTS_F_PASS);
    1283                 :            :         green_pkt_drop =
    1284                 :          0 :                 roc_nix_bpf_stats_to_idx(mask & ROC_NIX_BPF_GREEN_PKT_F_DROP);
    1285                 :            :         green_octs_drop =
    1286                 :          0 :                 roc_nix_bpf_stats_to_idx(mask & ROC_NIX_BPF_GREEN_OCTS_F_DROP);
    1287                 :            :         yellow_pkt_pass =
    1288                 :          0 :                 roc_nix_bpf_stats_to_idx(mask & ROC_NIX_BPF_YELLOW_PKT_F_PASS);
    1289                 :            :         yellow_octs_pass =
    1290                 :          0 :                 roc_nix_bpf_stats_to_idx(mask & ROC_NIX_BPF_YELLOW_OCTS_F_PASS);
    1291                 :            :         yellow_pkt_drop =
    1292                 :          0 :                 roc_nix_bpf_stats_to_idx(mask & ROC_NIX_BPF_YELLOW_PKT_F_DROP);
    1293                 :            :         yellow_octs_drop =
    1294                 :          0 :                 roc_nix_bpf_stats_to_idx(mask & ROC_NIX_BPF_YELLOW_OCTS_F_DROP);
    1295                 :            :         red_pkt_pass =
    1296                 :          0 :                 roc_nix_bpf_stats_to_idx(mask & ROC_NIX_BPF_RED_PKT_F_PASS);
    1297                 :            :         red_octs_pass =
    1298                 :          0 :                 roc_nix_bpf_stats_to_idx(mask & ROC_NIX_BPF_RED_OCTS_F_PASS);
    1299                 :            :         red_pkt_drop =
    1300                 :          0 :                 roc_nix_bpf_stats_to_idx(mask & ROC_NIX_BPF_RED_PKT_F_DROP);
    1301                 :            :         red_octs_drop =
    1302                 :          0 :                 roc_nix_bpf_stats_to_idx(mask & ROC_NIX_BPF_RED_OCTS_F_DROP);
    1303                 :            : 
    1304         [ #  # ]:          0 :         if (green_pkt_pass != ROC_NIX_BPF_STATS_MAX) {
    1305                 :          0 :                 stats[green_pkt_pass] =
    1306                 :          0 :                         NIX_RD_STATS(NIX_STAT_LF_RX_RX_GC_OCTS_PASSED);
    1307                 :            :         }
    1308                 :            : 
    1309         [ #  # ]:          0 :         if (green_octs_pass != ROC_NIX_BPF_STATS_MAX) {
    1310                 :          0 :                 stats[green_octs_pass] =
    1311                 :          0 :                         NIX_RD_STATS(NIX_STAT_LF_RX_RX_YC_PKTS_PASSED);
    1312                 :            :         }
    1313                 :            : 
    1314         [ #  # ]:          0 :         if (green_pkt_drop != ROC_NIX_BPF_STATS_MAX) {
    1315                 :          0 :                 stats[green_pkt_drop] =
    1316                 :          0 :                         NIX_RD_STATS(NIX_STAT_LF_RX_RX_GC_OCTS_DROP);
    1317                 :            :         }
    1318                 :            : 
    1319         [ #  # ]:          0 :         if (green_octs_drop != ROC_NIX_BPF_STATS_MAX) {
    1320                 :          0 :                 stats[green_octs_drop] =
    1321                 :          0 :                         NIX_RD_STATS(NIX_STAT_LF_RX_RX_YC_PKTS_DROP);
    1322                 :            :         }
    1323                 :            : 
    1324         [ #  # ]:          0 :         if (yellow_pkt_pass != ROC_NIX_BPF_STATS_MAX) {
    1325                 :          0 :                 stats[yellow_pkt_pass] =
    1326                 :          0 :                         NIX_RD_STATS(NIX_STAT_LF_RX_RX_GC_PKTS_PASSED);
    1327                 :            :         }
    1328                 :            : 
    1329         [ #  # ]:          0 :         if (yellow_octs_pass != ROC_NIX_BPF_STATS_MAX) {
    1330                 :          0 :                 stats[yellow_octs_pass] =
    1331                 :          0 :                         NIX_RD_STATS(NIX_STAT_LF_RX_RX_RC_OCTS_PASSED);
    1332                 :            :         }
    1333                 :            : 
    1334         [ #  # ]:          0 :         if (yellow_pkt_drop != ROC_NIX_BPF_STATS_MAX) {
    1335                 :          0 :                 stats[yellow_pkt_drop] =
    1336                 :          0 :                         NIX_RD_STATS(NIX_STAT_LF_RX_RX_GC_PKTS_DROP);
    1337                 :            :         }
    1338                 :            : 
    1339         [ #  # ]:          0 :         if (yellow_octs_drop != ROC_NIX_BPF_STATS_MAX) {
    1340                 :          0 :                 stats[yellow_octs_drop] =
    1341                 :          0 :                         NIX_RD_STATS(NIX_STAT_LF_RX_RX_RC_OCTS_DROP);
    1342                 :            :         }
    1343                 :            : 
    1344         [ #  # ]:          0 :         if (red_pkt_pass != ROC_NIX_BPF_STATS_MAX) {
    1345                 :          0 :                 stats[red_pkt_pass] =
    1346                 :          0 :                         NIX_RD_STATS(NIX_STAT_LF_RX_RX_YC_OCTS_PASSED);
    1347                 :            :         }
    1348                 :            : 
    1349         [ #  # ]:          0 :         if (red_octs_pass != ROC_NIX_BPF_STATS_MAX) {
    1350                 :          0 :                 stats[red_octs_pass] =
    1351                 :          0 :                         NIX_RD_STATS(NIX_STAT_LF_RX_RX_RC_PKTS_PASSED);
    1352                 :            :         }
    1353                 :            : 
    1354         [ #  # ]:          0 :         if (red_pkt_drop != ROC_NIX_BPF_STATS_MAX) {
    1355                 :          0 :                 stats[red_pkt_drop] =
    1356                 :          0 :                         NIX_RD_STATS(NIX_STAT_LF_RX_RX_YC_OCTS_DROP);
    1357                 :            :         }
    1358                 :            : 
    1359         [ #  # ]:          0 :         if (red_octs_drop != ROC_NIX_BPF_STATS_MAX) {
    1360                 :          0 :                 stats[red_octs_drop] =
    1361                 :          0 :                         NIX_RD_STATS(NIX_STAT_LF_RX_RX_RC_PKTS_DROP);
    1362                 :            :         }
    1363                 :            : 
    1364                 :          0 :         return 0;
    1365                 :            : }
    1366                 :            : 
    1367                 :            : int
    1368                 :          0 : roc_nix_bpf_lf_stats_reset(struct roc_nix *roc_nix, uint64_t mask)
    1369                 :            : {
    1370                 :            :         struct nix *nix = roc_nix_to_nix_priv(roc_nix);
    1371                 :            : 
    1372         [ #  # ]:          0 :         if (mask & ROC_NIX_BPF_GREEN_PKT_F_PASS)
    1373                 :          0 :                 NIX_RST_STATS(ROC_NIX_BPF_GREEN_PKT_F_PASS);
    1374         [ #  # ]:          0 :         if (mask & ROC_NIX_BPF_GREEN_OCTS_F_PASS)
    1375                 :          0 :                 NIX_RST_STATS(ROC_NIX_BPF_GREEN_OCTS_F_PASS);
    1376         [ #  # ]:          0 :         if (mask & ROC_NIX_BPF_GREEN_PKT_F_DROP)
    1377                 :          0 :                 NIX_RST_STATS(ROC_NIX_BPF_GREEN_PKT_F_DROP);
    1378         [ #  # ]:          0 :         if (mask & ROC_NIX_BPF_GREEN_OCTS_F_DROP)
    1379                 :          0 :                 NIX_RST_STATS(ROC_NIX_BPF_GREEN_OCTS_F_DROP);
    1380         [ #  # ]:          0 :         if (mask & ROC_NIX_BPF_YELLOW_PKT_F_PASS)
    1381                 :          0 :                 NIX_RST_STATS(ROC_NIX_BPF_YELLOW_PKT_F_PASS);
    1382         [ #  # ]:          0 :         if (mask & ROC_NIX_BPF_YELLOW_OCTS_F_PASS)
    1383                 :          0 :                 NIX_RST_STATS(ROC_NIX_BPF_YELLOW_OCTS_F_PASS);
    1384         [ #  # ]:          0 :         if (mask & ROC_NIX_BPF_YELLOW_PKT_F_DROP)
    1385                 :          0 :                 NIX_RST_STATS(ROC_NIX_BPF_YELLOW_PKT_F_DROP);
    1386         [ #  # ]:          0 :         if (mask & ROC_NIX_BPF_YELLOW_OCTS_F_DROP)
    1387                 :          0 :                 NIX_RST_STATS(ROC_NIX_BPF_YELLOW_OCTS_F_DROP);
    1388         [ #  # ]:          0 :         if (mask & ROC_NIX_BPF_RED_PKT_F_PASS)
    1389                 :          0 :                 NIX_RST_STATS(ROC_NIX_BPF_RED_PKT_F_PASS);
    1390         [ #  # ]:          0 :         if (mask & ROC_NIX_BPF_RED_OCTS_F_PASS)
    1391                 :          0 :                 NIX_RST_STATS(ROC_NIX_BPF_RED_OCTS_F_PASS);
    1392         [ #  # ]:          0 :         if (mask & ROC_NIX_BPF_RED_PKT_F_DROP)
    1393                 :          0 :                 NIX_RST_STATS(ROC_NIX_BPF_RED_PKT_F_DROP);
    1394         [ #  # ]:          0 :         if (mask & ROC_NIX_BPF_RED_OCTS_F_DROP)
    1395                 :          0 :                 NIX_RST_STATS(ROC_NIX_BPF_RED_OCTS_F_DROP);
    1396                 :            : 
    1397                 :          0 :         return 0;
    1398                 :            : }

Generated by: LCOV version 1.14