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