10d1ac82a4bd17cd712e759412e1afc05de0aad2
[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_RAW,
40         ROC_NPC_ITEM_TYPE_END,
41 };
42
43 struct roc_npc_item_info {
44         enum roc_npc_item_type type; /* Item type */
45         uint32_t size;               /* item size */
46         const void *spec; /**< Pointer to item specification structure. */
47         const void *mask; /**< Bit-mask applied to spec and last. */
48         const void *last; /* For range */
49 };
50
51 struct roc_npc_flow_item_raw {
52         uint32_t relative : 1; /**< Look for pattern after the previous item. */
53         uint32_t search : 1;   /**< Search pattern from offset. */
54         uint32_t reserved : 30; /**< Reserved, must be set to zero. */
55         int32_t offset;         /**< Absolute or relative offset for pattern. */
56         uint16_t limit;         /**< Search area limit for start of pattern. */
57         uint16_t length;        /**< Pattern length. */
58         const uint8_t *pattern; /**< Byte string to look for. */
59 };
60
61 #define ROC_NPC_MAX_ACTION_COUNT 19
62
63 enum roc_npc_action_type {
64         ROC_NPC_ACTION_TYPE_END = (1 << 0),
65         ROC_NPC_ACTION_TYPE_VOID = (1 << 1),
66         ROC_NPC_ACTION_TYPE_MARK = (1 << 2),
67         ROC_NPC_ACTION_TYPE_FLAG = (1 << 3),
68         ROC_NPC_ACTION_TYPE_DROP = (1 << 4),
69         ROC_NPC_ACTION_TYPE_QUEUE = (1 << 5),
70         ROC_NPC_ACTION_TYPE_RSS = (1 << 6),
71         ROC_NPC_ACTION_TYPE_DUP = (1 << 7),
72         ROC_NPC_ACTION_TYPE_SEC = (1 << 8),
73         ROC_NPC_ACTION_TYPE_COUNT = (1 << 9),
74         ROC_NPC_ACTION_TYPE_PF = (1 << 10),
75         ROC_NPC_ACTION_TYPE_VF = (1 << 11),
76         ROC_NPC_ACTION_TYPE_VLAN_STRIP = (1 << 12),
77         ROC_NPC_ACTION_TYPE_VLAN_INSERT = (1 << 13),
78         ROC_NPC_ACTION_TYPE_VLAN_ETHTYPE_INSERT = (1 << 14),
79         ROC_NPC_ACTION_TYPE_VLAN_PCP_INSERT = (1 << 15),
80         ROC_NPC_ACTION_TYPE_METER = (1 << 17),
81 };
82
83 struct roc_npc_action {
84         enum roc_npc_action_type type; /**< Action type. */
85         const void *conf; /**< Pointer to action configuration object. */
86 };
87
88 struct roc_npc_action_mark {
89         uint32_t id; /**< Integer value to return with packets. */
90 };
91
92 struct roc_npc_action_vf {
93         uint32_t original : 1;  /**< Use original VF ID if possible. */
94         uint32_t reserved : 31; /**< Reserved, must be zero. */
95         uint32_t id;            /**< VF ID. */
96 };
97
98 struct roc_npc_action_queue {
99         uint16_t index; /**< Queue index to use. */
100 };
101
102 struct roc_npc_action_of_push_vlan {
103         uint16_t ethertype; /**< EtherType. */
104 };
105
106 struct roc_npc_action_of_set_vlan_vid {
107         uint16_t vlan_vid; /**< VLAN id. */
108 };
109
110 struct roc_npc_action_of_set_vlan_pcp {
111         uint8_t vlan_pcp; /**< VLAN priority. */
112 };
113
114 struct roc_npc_action_meter {
115         uint32_t mtr_id; /**< Meter id to be applied. > */
116 };
117
118 struct roc_npc_attr {
119         uint32_t priority;      /**< Rule priority level within group. */
120         uint32_t ingress : 1;   /**< Rule applies to ingress traffic. */
121         uint32_t egress : 1;    /**< Rule applies to egress traffic. */
122         uint32_t reserved : 30; /**< Reserved, must be zero. */
123 };
124
125 struct roc_npc_flow_dump_data {
126         uint8_t lid;
127         uint16_t ltype;
128 };
129
130 struct roc_npc_flow {
131         uint8_t nix_intf;
132         uint8_t enable;
133         uint32_t mcam_id;
134         int32_t ctr_id;
135         uint32_t priority;
136         uint32_t mtr_id;
137 #define ROC_NPC_MAX_MCAM_WIDTH_DWORDS 7
138         /* Contiguous match string */
139         uint64_t mcam_data[ROC_NPC_MAX_MCAM_WIDTH_DWORDS];
140         uint64_t mcam_mask[ROC_NPC_MAX_MCAM_WIDTH_DWORDS];
141         uint64_t npc_action;
142         uint64_t vtag_action;
143         bool vtag_insert_enabled;
144         uint8_t vtag_insert_count;
145 #define ROC_NPC_MAX_FLOW_PATTERNS 32
146         struct roc_npc_flow_dump_data dump_data[ROC_NPC_MAX_FLOW_PATTERNS];
147         uint16_t num_patterns;
148
149         TAILQ_ENTRY(roc_npc_flow) next;
150 };
151
152 enum roc_npc_rss_hash_function {
153         ROC_NPC_RSS_HASH_FUNCTION_DEFAULT = 0,
154         ROC_NPC_RSS_HASH_FUNCTION_TOEPLITZ,   /**< Toeplitz */
155         ROC_NPC_RSS_HASH_FUNCTION_SIMPLE_XOR, /**< Simple XOR */
156         ROC_NPC_RSS_HASH_FUNCTION_SYMMETRIC_TOEPLITZ,
157         ROC_NPC_RSS_HASH_FUNCTION_MAX,
158 };
159
160 struct roc_npc_action_rss {
161         enum roc_npc_rss_hash_function func;
162         uint32_t level;
163         uint64_t types;        /**< Specific RSS hash types (see ETH_RSS_*). */
164         uint32_t key_len;      /**< Hash key length in bytes. */
165         uint32_t queue_num;    /**< Number of entries in @p queue. */
166         const uint8_t *key;    /**< Hash key. */
167         const uint16_t *queue; /**< Queue indices to use. */
168 };
169
170 enum roc_npc_intf {
171         ROC_NPC_INTF_RX = 0,
172         ROC_NPC_INTF_TX = 1,
173         ROC_NPC_INTF_MAX = 2,
174 };
175
176 enum flow_vtag_cfg_dir { VTAG_TX, VTAG_RX };
177 #define ROC_ETHER_TYPE_VLAN 0x8100 /**< IEEE 802.1Q VLAN tagging. */
178 #define ROC_ETHER_TYPE_QINQ 0x88A8 /**< IEEE 802.1ad QinQ tagging. */
179
180 struct roc_npc {
181         struct roc_nix *roc_nix;
182         uint8_t switch_header_type;
183         uint16_t flow_prealloc_size;
184         uint16_t flow_max_priority;
185         uint16_t channel;
186         uint16_t pf_func;
187         uint64_t kex_capability;
188         uint64_t rx_parse_nibble;
189         /* Parsed RSS Flowkey cfg for current flow being created */
190         uint32_t flowkey_cfg_state;
191
192 #define ROC_NPC_MEM_SZ (5 * 1024)
193         uint8_t reserved[ROC_NPC_MEM_SZ];
194 } __plt_cache_aligned;
195
196 int __roc_api roc_npc_init(struct roc_npc *roc_npc);
197 int __roc_api roc_npc_fini(struct roc_npc *roc_npc);
198 const char *__roc_api roc_npc_profile_name_get(struct roc_npc *roc_npc);
199
200 struct roc_npc_flow *__roc_api
201 roc_npc_flow_create(struct roc_npc *roc_npc, const struct roc_npc_attr *attr,
202                     const struct roc_npc_item_info pattern[],
203                     const struct roc_npc_action actions[], int *errcode);
204 int __roc_api roc_npc_flow_destroy(struct roc_npc *roc_npc,
205                                    struct roc_npc_flow *flow);
206 int __roc_api roc_npc_mcam_free_entry(struct roc_npc *roc_npc, uint32_t entry);
207 int __roc_api roc_npc_mcam_alloc_entry(struct roc_npc *roc_npc,
208                                        struct roc_npc_flow *mcam,
209                                        struct roc_npc_flow *ref_mcam, int prio,
210                                        int *resp_count);
211 int __roc_api roc_npc_mcam_alloc_entries(struct roc_npc *roc_npc, int ref_entry,
212                                          int *alloc_entry, int req_count,
213                                          int priority, int *resp_count);
214 int __roc_api roc_npc_mcam_ena_dis_entry(struct roc_npc *roc_npc,
215                                          struct roc_npc_flow *mcam,
216                                          bool enable);
217 int __roc_api roc_npc_mcam_write_entry(struct roc_npc *roc_npc,
218                                        struct roc_npc_flow *mcam);
219 int __roc_api roc_npc_flow_parse(struct roc_npc *roc_npc,
220                                  const struct roc_npc_attr *attr,
221                                  const struct roc_npc_item_info pattern[],
222                                  const struct roc_npc_action actions[],
223                                  struct roc_npc_flow *flow);
224 int __roc_api roc_npc_get_low_priority_mcam(struct roc_npc *roc_npc);
225 int __roc_api roc_npc_mcam_free_counter(struct roc_npc *roc_npc,
226                                         uint16_t ctr_id);
227 int __roc_api roc_npc_mcam_read_counter(struct roc_npc *roc_npc,
228                                         uint32_t ctr_id, uint64_t *count);
229 int __roc_api roc_npc_mcam_clear_counter(struct roc_npc *roc_npc,
230                                          uint32_t ctr_id);
231 int __roc_api roc_npc_mcam_free_all_resources(struct roc_npc *roc_npc);
232 void __roc_api roc_npc_flow_dump(FILE *file, struct roc_npc *roc_npc);
233 void __roc_api roc_npc_flow_mcam_dump(FILE *file, struct roc_npc *roc_npc,
234                                       struct roc_npc_flow *mcam);
235 int __roc_api roc_npc_mark_actions_get(struct roc_npc *roc_npc);
236 int __roc_api roc_npc_mark_actions_sub_return(struct roc_npc *roc_npc,
237                                               uint32_t count);
238 int __roc_api roc_npc_vtag_actions_get(struct roc_npc *roc_npc);
239 int __roc_api roc_npc_vtag_actions_sub_return(struct roc_npc *roc_npc,
240                                               uint32_t count);
241 int __roc_api roc_npc_mcam_merge_base_steering_rule(struct roc_npc *roc_npc,
242                                                     struct roc_npc_flow *flow);
243 #endif /* _ROC_NPC_H_ */