common/cnxk: add NPC init and fini
[dpdk.git] / drivers / common / cnxk / roc_npc.h
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(C) 2021 Marvell.
3  */
4
5 #ifndef _ROC_NPC_H_
6 #define _ROC_NPC_H_
7
8 #include <sys/queue.h>
9
10 enum roc_npc_item_type {
11         ROC_NPC_ITEM_TYPE_VOID,
12         ROC_NPC_ITEM_TYPE_ANY,
13         ROC_NPC_ITEM_TYPE_ETH,
14         ROC_NPC_ITEM_TYPE_VLAN,
15         ROC_NPC_ITEM_TYPE_E_TAG,
16         ROC_NPC_ITEM_TYPE_IPV4,
17         ROC_NPC_ITEM_TYPE_IPV6,
18         ROC_NPC_ITEM_TYPE_ARP_ETH_IPV4,
19         ROC_NPC_ITEM_TYPE_MPLS,
20         ROC_NPC_ITEM_TYPE_ICMP,
21         ROC_NPC_ITEM_TYPE_IGMP,
22         ROC_NPC_ITEM_TYPE_UDP,
23         ROC_NPC_ITEM_TYPE_TCP,
24         ROC_NPC_ITEM_TYPE_SCTP,
25         ROC_NPC_ITEM_TYPE_ESP,
26         ROC_NPC_ITEM_TYPE_GRE,
27         ROC_NPC_ITEM_TYPE_NVGRE,
28         ROC_NPC_ITEM_TYPE_VXLAN,
29         ROC_NPC_ITEM_TYPE_GTPC,
30         ROC_NPC_ITEM_TYPE_GTPU,
31         ROC_NPC_ITEM_TYPE_GENEVE,
32         ROC_NPC_ITEM_TYPE_VXLAN_GPE,
33         ROC_NPC_ITEM_TYPE_IPV6_EXT,
34         ROC_NPC_ITEM_TYPE_GRE_KEY,
35         ROC_NPC_ITEM_TYPE_HIGIG2,
36         ROC_NPC_ITEM_TYPE_CPT_HDR,
37         ROC_NPC_ITEM_TYPE_L3_CUSTOM,
38         ROC_NPC_ITEM_TYPE_QINQ,
39         ROC_NPC_ITEM_TYPE_END,
40 };
41
42 struct roc_npc_item_info {
43         enum roc_npc_item_type type; /* Item type */
44         uint32_t size;               /* item size */
45         const void *spec; /**< Pointer to item specification structure. */
46         const void *mask; /**< Bit-mask applied to spec and last. */
47         const void *last; /* For range */
48 };
49
50 #define ROC_NPC_MAX_ACTION_COUNT 12
51
52 enum roc_npc_action_type {
53         ROC_NPC_ACTION_TYPE_END = (1 << 0),
54         ROC_NPC_ACTION_TYPE_VOID = (1 << 1),
55         ROC_NPC_ACTION_TYPE_MARK = (1 << 2),
56         ROC_NPC_ACTION_TYPE_FLAG = (1 << 3),
57         ROC_NPC_ACTION_TYPE_DROP = (1 << 4),
58         ROC_NPC_ACTION_TYPE_QUEUE = (1 << 5),
59         ROC_NPC_ACTION_TYPE_RSS = (1 << 6),
60         ROC_NPC_ACTION_TYPE_DUP = (1 << 7),
61         ROC_NPC_ACTION_TYPE_SEC = (1 << 8),
62         ROC_NPC_ACTION_TYPE_COUNT = (1 << 9),
63         ROC_NPC_ACTION_TYPE_PF = (1 << 10),
64         ROC_NPC_ACTION_TYPE_VF = (1 << 11),
65 };
66
67 struct roc_npc_action {
68         enum roc_npc_action_type type; /**< Action type. */
69         const void *conf; /**< Pointer to action configuration object. */
70 };
71
72 struct roc_npc_action_mark {
73         uint32_t id; /**< Integer value to return with packets. */
74 };
75
76 struct roc_npc_action_vf {
77         uint32_t original : 1;  /**< Use original VF ID if possible. */
78         uint32_t reserved : 31; /**< Reserved, must be zero. */
79         uint32_t id;            /**< VF ID. */
80 };
81
82 struct roc_npc_action_queue {
83         uint16_t index; /**< Queue index to use. */
84 };
85
86 struct roc_npc_attr {
87         uint32_t priority;      /**< Rule priority level within group. */
88         uint32_t ingress : 1;   /**< Rule applies to ingress traffic. */
89         uint32_t egress : 1;    /**< Rule applies to egress traffic. */
90         uint32_t reserved : 30; /**< Reserved, must be zero. */
91 };
92
93 struct roc_npc_flow {
94         uint8_t nix_intf;
95         uint8_t enable;
96         uint32_t mcam_id;
97         int32_t ctr_id;
98         uint32_t priority;
99 #define ROC_NPC_MAX_MCAM_WIDTH_DWORDS 7
100         /* Contiguous match string */
101         uint64_t mcam_data[ROC_NPC_MAX_MCAM_WIDTH_DWORDS];
102         uint64_t mcam_mask[ROC_NPC_MAX_MCAM_WIDTH_DWORDS];
103         uint64_t npc_action;
104         uint64_t vtag_action;
105
106         TAILQ_ENTRY(roc_npc_flow) next;
107 };
108
109 enum roc_npc_intf {
110         ROC_NPC_INTF_RX = 0,
111         ROC_NPC_INTF_TX = 1,
112         ROC_NPC_INTF_MAX = 2,
113 };
114
115 struct roc_npc {
116         struct roc_nix *roc_nix;
117         uint8_t switch_header_type;
118         uint16_t flow_prealloc_size;
119         uint16_t flow_max_priority;
120         uint16_t channel;
121         uint16_t pf_func;
122         uint64_t kex_capability;
123         uint64_t rx_parse_nibble;
124
125 #define ROC_NPC_MEM_SZ (5 * 1024)
126         uint8_t reserved[ROC_NPC_MEM_SZ];
127 } __plt_cache_aligned;
128
129 int __roc_api roc_npc_init(struct roc_npc *roc_npc);
130 int __roc_api roc_npc_fini(struct roc_npc *roc_npc);
131 const char *__roc_api roc_npc_profile_name_get(struct roc_npc *roc_npc);
132
133 struct roc_npc_flow *__roc_api
134 roc_npc_flow_create(struct roc_npc *roc_npc, const struct roc_npc_attr *attr,
135                     const struct roc_npc_item_info pattern[],
136                     const struct roc_npc_action actions[], int *errcode);
137 int __roc_api roc_npc_flow_destroy(struct roc_npc *roc_npc,
138                                    struct roc_npc_flow *flow);
139 int __roc_api roc_npc_mcam_free_entry(struct roc_npc *roc_npc, uint32_t entry);
140 int __roc_api roc_npc_mcam_alloc_entry(struct roc_npc *roc_npc,
141                                        struct roc_npc_flow *mcam,
142                                        struct roc_npc_flow *ref_mcam, int prio,
143                                        int *resp_count);
144 int __roc_api roc_npc_mcam_alloc_entries(struct roc_npc *roc_npc, int ref_entry,
145                                          int *alloc_entry, int req_count,
146                                          int priority, int *resp_count);
147 int __roc_api roc_npc_mcam_ena_dis_entry(struct roc_npc *roc_npc,
148                                          struct roc_npc_flow *mcam,
149                                          bool enable);
150 int __roc_api roc_npc_mcam_write_entry(struct roc_npc *roc_npc,
151                                        struct roc_npc_flow *mcam);
152 int __roc_api roc_npc_flow_parse(struct roc_npc *roc_npc,
153                                  const struct roc_npc_attr *attr,
154                                  const struct roc_npc_item_info pattern[],
155                                  const struct roc_npc_action actions[],
156                                  struct roc_npc_flow *flow);
157 int __roc_api roc_npc_get_low_priority_mcam(struct roc_npc *roc_npc);
158
159 int __roc_api roc_npc_mcam_free_counter(struct roc_npc *roc_npc,
160                                         uint16_t ctr_id);
161
162 int __roc_api roc_npc_mcam_read_counter(struct roc_npc *roc_npc,
163                                         uint32_t ctr_id, uint64_t *count);
164 int __roc_api roc_npc_mcam_clear_counter(struct roc_npc *roc_npc,
165                                          uint32_t ctr_id);
166
167 int __roc_api roc_npc_mcam_free_all_resources(struct roc_npc *roc_npc);
168
169 #endif /* _ROC_NPC_H_ */