af9dffa90ce43a2b643661e20ed7de8f12356dcd
[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_LEVEL_F_MASK                                                   \
13         (ROC_NIX_BPF_LEVEL_F_LEAF | ROC_NIX_BPF_LEVEL_F_MID |                  \
14          ROC_NIX_BPF_LEVEL_F_TOP)
15
16 uint8_t
17 roc_nix_bpf_level_to_idx(enum roc_nix_bpf_level_flag level_f)
18 {
19         uint8_t idx;
20
21         if (level_f & ROC_NIX_BPF_LEVEL_F_LEAF)
22                 idx = 0;
23         else if (level_f & ROC_NIX_BPF_LEVEL_F_MID)
24                 idx = 1;
25         else if (level_f & ROC_NIX_BPF_LEVEL_F_TOP)
26                 idx = 2;
27         else
28                 idx = ROC_NIX_BPF_LEVEL_IDX_INVALID;
29         return idx;
30 }
31
32 int
33 roc_nix_bpf_count_get(struct roc_nix *roc_nix, uint8_t lvl_mask,
34                       uint16_t count[ROC_NIX_BPF_LEVEL_MAX])
35 {
36         uint8_t mask = lvl_mask & NIX_BPF_LEVEL_F_MASK;
37         uint8_t leaf_idx, mid_idx, top_idx;
38
39         PLT_SET_USED(roc_nix);
40
41         if (roc_model_is_cn9k())
42                 return NIX_ERR_HW_NOTSUP;
43
44         if (!mask)
45                 return NIX_ERR_PARAM;
46
47         /* Currently No MBOX interface is available to get number
48          * of bandwidth profiles. So numbers per level are hard coded,
49          * considering 3 RPM blocks and each block has 4 LMAC's.
50          * So total 12 physical interfaces are in system. Each interface
51          * supports following bandwidth profiles.
52          */
53
54         leaf_idx = roc_nix_bpf_level_to_idx(mask & ROC_NIX_BPF_LEVEL_F_LEAF);
55         mid_idx = roc_nix_bpf_level_to_idx(mask & ROC_NIX_BPF_LEVEL_F_MID);
56         top_idx = roc_nix_bpf_level_to_idx(mask & ROC_NIX_BPF_LEVEL_F_TOP);
57
58         if (leaf_idx != ROC_NIX_BPF_LEVEL_IDX_INVALID)
59                 count[leaf_idx] = NIX_MAX_BPF_COUNT_LEAF_LAYER;
60
61         if (mid_idx != ROC_NIX_BPF_LEVEL_IDX_INVALID)
62                 count[mid_idx] = NIX_MAX_BPF_COUNT_MID_LAYER;
63
64         if (top_idx != ROC_NIX_BPF_LEVEL_IDX_INVALID)
65                 count[top_idx] = NIX_MAX_BPF_COUNT_TOP_LAYER;
66
67         return 0;
68 }