net/i40e: fix crash in AVX512
[dpdk.git] / drivers / net / octeontx2 / otx2_flow.h
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(C) 2019 Marvell International Ltd.
3  */
4
5 #ifndef __OTX2_FLOW_H__
6 #define __OTX2_FLOW_H__
7
8 #include <stdint.h>
9
10 #include <rte_flow_driver.h>
11 #include <rte_malloc.h>
12 #include <rte_tailq.h>
13
14 #include "otx2_common.h"
15 #include "otx2_ethdev.h"
16 #include "otx2_mbox.h"
17
18 struct otx2_eth_dev;
19
20 int otx2_flow_init(struct otx2_eth_dev *hw);
21 int otx2_flow_fini(struct otx2_eth_dev *hw);
22 extern const struct rte_flow_ops otx2_flow_ops;
23
24 enum {
25         OTX2_INTF_RX = 0,
26         OTX2_INTF_TX = 1,
27         OTX2_INTF_MAX = 2,
28 };
29
30 #define NPC_IH_LENGTH                   8
31 #define NPC_TPID_LENGTH                 2
32 #define NPC_HIGIG2_LENGTH               16
33 #define NPC_MAX_RAW_ITEM_LEN            16
34 #define NPC_COUNTER_NONE                (-1)
35 /* 32 bytes from LDATA_CFG & 32 bytes from FLAGS_CFG */
36 #define NPC_MAX_EXTRACT_DATA_LEN        (64)
37 #define NPC_LDATA_LFLAG_LEN             (16)
38 #define NPC_MCAM_TOT_ENTRIES            (4096)
39 #define NPC_MAX_KEY_NIBBLES             (31)
40 /* Nibble offsets */
41 #define NPC_LAYER_KEYX_SZ               (3)
42 #define NPC_PARSE_KEX_S_LA_OFFSET       (7)
43 #define NPC_PARSE_KEX_S_LID_OFFSET(lid)         \
44         ((((lid) - NPC_LID_LA) * NPC_LAYER_KEYX_SZ)  \
45         + NPC_PARSE_KEX_S_LA_OFFSET)
46
47
48 /* supported flow actions flags */
49 #define OTX2_FLOW_ACT_MARK    (1 << 0)
50 #define OTX2_FLOW_ACT_FLAG    (1 << 1)
51 #define OTX2_FLOW_ACT_DROP    (1 << 2)
52 #define OTX2_FLOW_ACT_QUEUE   (1 << 3)
53 #define OTX2_FLOW_ACT_RSS     (1 << 4)
54 #define OTX2_FLOW_ACT_DUP     (1 << 5)
55 #define OTX2_FLOW_ACT_SEC     (1 << 6)
56 #define OTX2_FLOW_ACT_COUNT   (1 << 7)
57 #define OTX2_FLOW_ACT_PF      (1 << 8)
58 #define OTX2_FLOW_ACT_VF      (1 << 9)
59 #define OTX2_FLOW_ACT_VLAN_STRIP (1 << 10)
60 #define OTX2_FLOW_ACT_VLAN_INSERT (1 << 11)
61 #define OTX2_FLOW_ACT_VLAN_ETHTYPE_INSERT (1 << 12)
62 #define OTX2_FLOW_ACT_VLAN_PCP_INSERT (1 << 13)
63
64 /* terminating actions */
65 #define OTX2_FLOW_ACT_TERM    (OTX2_FLOW_ACT_DROP  | \
66                                OTX2_FLOW_ACT_QUEUE | \
67                                OTX2_FLOW_ACT_RSS   | \
68                                OTX2_FLOW_ACT_DUP   | \
69                                OTX2_FLOW_ACT_SEC)
70
71 /* This mark value indicates flag action */
72 #define OTX2_FLOW_FLAG_VAL    (0xffff)
73
74 #define NIX_RX_ACT_MATCH_OFFSET         (40)
75 #define NIX_RX_ACT_MATCH_MASK           (0xFFFF)
76
77 #define NIX_RSS_ACT_GRP_OFFSET          (20)
78 #define NIX_RSS_ACT_ALG_OFFSET          (56)
79 #define NIX_RSS_ACT_GRP_MASK            (0xFFFFF)
80 #define NIX_RSS_ACT_ALG_MASK            (0x1F)
81
82 /* PMD-specific definition of the opaque struct rte_flow */
83 #define OTX2_MAX_MCAM_WIDTH_DWORDS      7
84
85 enum npc_mcam_intf {
86         NPC_MCAM_RX,
87         NPC_MCAM_TX
88 };
89
90 struct npc_xtract_info {
91         /* Length in bytes of pkt data extracted. len = 0
92          * indicates that extraction is disabled.
93          */
94         uint8_t len;
95         uint8_t hdr_off; /* Byte offset of proto hdr: extract_src */
96         uint8_t key_off; /* Byte offset in MCAM key where data is placed */
97         uint8_t enable; /* Extraction enabled or disabled */
98         uint8_t flags_enable; /* Flags extraction enabled */
99 };
100
101 /* Information for a given {LAYER, LTYPE} */
102 struct npc_lid_lt_xtract_info {
103         /* Info derived from parser configuration */
104         uint16_t npc_proto;              /* Network protocol identified */
105         uint8_t  valid_flags_mask;       /* Flags applicable */
106         uint8_t  is_terminating:1;       /* No more parsing */
107         struct npc_xtract_info xtract[NPC_MAX_LD];
108 };
109
110 union npc_kex_ldata_flags_cfg {
111         struct {
112         #if defined(__BIG_ENDIAN_BITFIELD)
113                 uint64_t rvsd_62_1      : 61;
114                 uint64_t lid            : 3;
115         #else
116                 uint64_t lid            : 3;
117                 uint64_t rvsd_62_1      : 61;
118         #endif
119         } s;
120
121         uint64_t i;
122 };
123
124 typedef struct npc_lid_lt_xtract_info
125         otx2_dxcfg_t[NPC_MAX_INTF][NPC_MAX_LID][NPC_MAX_LT];
126 typedef struct npc_lid_lt_xtract_info
127         otx2_fxcfg_t[NPC_MAX_INTF][NPC_MAX_LD][NPC_MAX_LFL];
128 typedef union npc_kex_ldata_flags_cfg otx2_ld_flags_t[NPC_MAX_LD];
129
130
131 /* MBOX_MSG_NPC_GET_DATAX_CFG Response */
132 struct npc_get_datax_cfg {
133         /* NPC_AF_KEX_LDATA(0..1)_FLAGS_CFG */
134         union npc_kex_ldata_flags_cfg ld_flags[NPC_MAX_LD];
135         /* Extract information indexed with [LID][LTYPE] */
136         struct npc_lid_lt_xtract_info lid_lt_xtract[NPC_MAX_LID][NPC_MAX_LT];
137         /* Flags based extract indexed with [LDATA][FLAGS_LOWER_NIBBLE]
138          * Fields flags_ena_ld0, flags_ena_ld1 in
139          * struct npc_lid_lt_xtract_info indicate if this is applicable
140          * for a given {LAYER, LTYPE}
141          */
142         struct npc_xtract_info flag_xtract[NPC_MAX_LD][NPC_MAX_LT];
143 };
144
145 struct otx2_mcam_ents_info {
146         /* Current max & min values of mcam index */
147         uint32_t max_id;
148         uint32_t min_id;
149         uint32_t free_ent;
150         uint32_t live_ent;
151 };
152
153 struct otx2_flow_dump_data {
154         uint8_t lid;
155         uint16_t ltype;
156 };
157
158 struct rte_flow {
159         uint8_t  nix_intf;
160         uint32_t  mcam_id;
161         int32_t ctr_id;
162         uint32_t priority;
163         /* Contiguous match string */
164         uint64_t mcam_data[OTX2_MAX_MCAM_WIDTH_DWORDS];
165         uint64_t mcam_mask[OTX2_MAX_MCAM_WIDTH_DWORDS];
166         uint64_t npc_action;
167         uint64_t vtag_action;
168         struct otx2_flow_dump_data dump_data[32];
169         uint16_t num_patterns;
170         TAILQ_ENTRY(rte_flow) next;
171 };
172
173 TAILQ_HEAD(otx2_flow_list, rte_flow);
174
175 /* Accessed from ethdev private - otx2_eth_dev */
176 struct otx2_npc_flow_info {
177         rte_atomic32_t mark_actions;
178         uint32_t vtag_actions;
179         uint32_t keyx_supp_nmask[NPC_MAX_INTF];/* nibble mask */
180         uint32_t keyx_len[NPC_MAX_INTF];        /* per intf key len in bits */
181         uint32_t datax_len[NPC_MAX_INTF];       /* per intf data len in bits */
182         uint32_t keyw[NPC_MAX_INTF];            /* max key + data len bits */
183         uint32_t mcam_entries;                  /* mcam entries supported */
184         otx2_dxcfg_t prx_dxcfg;                 /* intf, lid, lt, extract */
185         otx2_fxcfg_t prx_fxcfg;                 /* Flag extract */
186         otx2_ld_flags_t prx_lfcfg;              /* KEX LD_Flags CFG */
187         /* mcam entry info per priority level: both free & in-use */
188         struct otx2_mcam_ents_info *flow_entry_info;
189         /* Bitmap of free preallocated entries in ascending index &
190          * descending priority
191          */
192         struct rte_bitmap **free_entries;
193         /* Bitmap of free preallocated entries in descending index &
194          * ascending priority
195          */
196         struct rte_bitmap **free_entries_rev;
197         /* Bitmap of live entries in ascending index & descending priority */
198         struct rte_bitmap **live_entries;
199         /* Bitmap of live entries in descending index & ascending priority */
200         struct rte_bitmap **live_entries_rev;
201         /* Priority bucket wise tail queue of all rte_flow resources */
202         struct otx2_flow_list *flow_list;
203         uint32_t rss_grps;  /* rss groups supported */
204         struct rte_bitmap *rss_grp_entries;
205         uint16_t channel; /*rx channel */
206         uint16_t flow_prealloc_size;
207         uint16_t flow_max_priority;
208         uint16_t switch_header_type;
209 };
210
211 struct otx2_parse_state {
212         struct otx2_npc_flow_info *npc;
213         const struct rte_flow_item *pattern;
214         const struct rte_flow_item *last_pattern; /* Temp usage */
215         struct rte_flow_error *error;
216         struct rte_flow *flow;
217         uint8_t tunnel;
218         uint8_t terminate;
219         uint8_t layer_mask;
220         uint8_t lt[NPC_MAX_LID];
221         uint8_t flags[NPC_MAX_LID];
222         uint8_t *mcam_data; /* point to flow->mcam_data + key_len */
223         uint8_t *mcam_mask; /* point to flow->mcam_mask + key_len */
224         bool is_vf;
225 };
226
227 struct otx2_flow_item_info {
228         const void *def_mask; /* rte_flow default mask */
229         void *hw_mask;        /* hardware supported mask */
230         int  len;             /* length of item */
231         const void *spec;     /* spec to use, NULL implies match any */
232         const void *mask;     /* mask to use */
233         uint8_t hw_hdr_len;  /* Extra data len at each layer*/
234 };
235
236 struct otx2_idev_kex_cfg {
237         struct npc_get_kex_cfg_rsp kex_cfg;
238         rte_atomic16_t kex_refcnt;
239 };
240
241 enum npc_kpu_parser_flag {
242         NPC_F_NA = 0,
243         NPC_F_PKI,
244         NPC_F_PKI_VLAN,
245         NPC_F_PKI_ETAG,
246         NPC_F_PKI_ITAG,
247         NPC_F_PKI_MPLS,
248         NPC_F_PKI_NSH,
249         NPC_F_ETYPE_UNK,
250         NPC_F_ETHER_VLAN,
251         NPC_F_ETHER_ETAG,
252         NPC_F_ETHER_ITAG,
253         NPC_F_ETHER_MPLS,
254         NPC_F_ETHER_NSH,
255         NPC_F_STAG_CTAG,
256         NPC_F_STAG_CTAG_UNK,
257         NPC_F_STAG_STAG_CTAG,
258         NPC_F_STAG_STAG_STAG,
259         NPC_F_QINQ_CTAG,
260         NPC_F_QINQ_CTAG_UNK,
261         NPC_F_QINQ_QINQ_CTAG,
262         NPC_F_QINQ_QINQ_QINQ,
263         NPC_F_BTAG_ITAG,
264         NPC_F_BTAG_ITAG_STAG,
265         NPC_F_BTAG_ITAG_CTAG,
266         NPC_F_BTAG_ITAG_UNK,
267         NPC_F_ETAG_CTAG,
268         NPC_F_ETAG_BTAG_ITAG,
269         NPC_F_ETAG_STAG,
270         NPC_F_ETAG_QINQ,
271         NPC_F_ETAG_ITAG,
272         NPC_F_ETAG_ITAG_STAG,
273         NPC_F_ETAG_ITAG_CTAG,
274         NPC_F_ETAG_ITAG_UNK,
275         NPC_F_ITAG_STAG_CTAG,
276         NPC_F_ITAG_STAG,
277         NPC_F_ITAG_CTAG,
278         NPC_F_MPLS_4_LABELS,
279         NPC_F_MPLS_3_LABELS,
280         NPC_F_MPLS_2_LABELS,
281         NPC_F_IP_HAS_OPTIONS,
282         NPC_F_IP_IP_IN_IP,
283         NPC_F_IP_6TO4,
284         NPC_F_IP_MPLS_IN_IP,
285         NPC_F_IP_UNK_PROTO,
286         NPC_F_IP_IP_IN_IP_HAS_OPTIONS,
287         NPC_F_IP_6TO4_HAS_OPTIONS,
288         NPC_F_IP_MPLS_IN_IP_HAS_OPTIONS,
289         NPC_F_IP_UNK_PROTO_HAS_OPTIONS,
290         NPC_F_IP6_HAS_EXT,
291         NPC_F_IP6_TUN_IP6,
292         NPC_F_IP6_MPLS_IN_IP,
293         NPC_F_TCP_HAS_OPTIONS,
294         NPC_F_TCP_HTTP,
295         NPC_F_TCP_HTTPS,
296         NPC_F_TCP_PPTP,
297         NPC_F_TCP_UNK_PORT,
298         NPC_F_TCP_HTTP_HAS_OPTIONS,
299         NPC_F_TCP_HTTPS_HAS_OPTIONS,
300         NPC_F_TCP_PPTP_HAS_OPTIONS,
301         NPC_F_TCP_UNK_PORT_HAS_OPTIONS,
302         NPC_F_UDP_VXLAN,
303         NPC_F_UDP_VXLAN_NOVNI,
304         NPC_F_UDP_VXLAN_NOVNI_NSH,
305         NPC_F_UDP_VXLANGPE,
306         NPC_F_UDP_VXLANGPE_NSH,
307         NPC_F_UDP_VXLANGPE_MPLS,
308         NPC_F_UDP_VXLANGPE_NOVNI,
309         NPC_F_UDP_VXLANGPE_NOVNI_NSH,
310         NPC_F_UDP_VXLANGPE_NOVNI_MPLS,
311         NPC_F_UDP_VXLANGPE_UNK,
312         NPC_F_UDP_VXLANGPE_NONP,
313         NPC_F_UDP_GTP_GTPC,
314         NPC_F_UDP_GTP_GTPU_G_PDU,
315         NPC_F_UDP_GTP_GTPU_UNK,
316         NPC_F_UDP_UNK_PORT,
317         NPC_F_UDP_GENEVE,
318         NPC_F_UDP_GENEVE_OAM,
319         NPC_F_UDP_GENEVE_CRI_OPT,
320         NPC_F_UDP_GENEVE_OAM_CRI_OPT,
321         NPC_F_GRE_NVGRE,
322         NPC_F_GRE_HAS_SRE,
323         NPC_F_GRE_HAS_CSUM,
324         NPC_F_GRE_HAS_KEY,
325         NPC_F_GRE_HAS_SEQ,
326         NPC_F_GRE_HAS_CSUM_KEY,
327         NPC_F_GRE_HAS_CSUM_SEQ,
328         NPC_F_GRE_HAS_KEY_SEQ,
329         NPC_F_GRE_HAS_CSUM_KEY_SEQ,
330         NPC_F_GRE_HAS_ROUTE,
331         NPC_F_GRE_UNK_PROTO,
332         NPC_F_GRE_VER1,
333         NPC_F_GRE_VER1_HAS_SEQ,
334         NPC_F_GRE_VER1_HAS_ACK,
335         NPC_F_GRE_VER1_HAS_SEQ_ACK,
336         NPC_F_GRE_VER1_UNK_PROTO,
337         NPC_F_TU_ETHER_UNK,
338         NPC_F_TU_ETHER_CTAG,
339         NPC_F_TU_ETHER_CTAG_UNK,
340         NPC_F_TU_ETHER_STAG_CTAG,
341         NPC_F_TU_ETHER_STAG_CTAG_UNK,
342         NPC_F_TU_ETHER_STAG,
343         NPC_F_TU_ETHER_STAG_UNK,
344         NPC_F_TU_ETHER_QINQ_CTAG,
345         NPC_F_TU_ETHER_QINQ_CTAG_UNK,
346         NPC_F_TU_ETHER_QINQ,
347         NPC_F_TU_ETHER_QINQ_UNK,
348         NPC_F_LAST /* has to be the last item */
349 };
350
351
352 int otx2_flow_mcam_free_counter(struct otx2_mbox *mbox, uint16_t ctr_id);
353
354 int otx2_flow_mcam_read_counter(struct otx2_mbox *mbox, uint32_t ctr_id,
355                                 uint64_t *count);
356
357 int otx2_flow_mcam_clear_counter(struct otx2_mbox *mbox, uint32_t ctr_id);
358
359 int otx2_flow_mcam_free_entry(struct otx2_mbox *mbox, uint32_t entry);
360
361 int otx2_flow_mcam_free_all_entries(struct otx2_mbox *mbox);
362
363 int otx2_flow_update_parse_state(struct otx2_parse_state *pst,
364                                  struct otx2_flow_item_info *info,
365                                  int lid, int lt, uint8_t flags);
366
367 int otx2_flow_parse_item_basic(const struct rte_flow_item *item,
368                                struct otx2_flow_item_info *info,
369                                struct rte_flow_error *error);
370
371 void otx2_flow_keyx_compress(uint64_t *data, uint32_t nibble_mask);
372
373 int otx2_flow_mcam_alloc_and_write(struct rte_flow *flow,
374                                    struct otx2_mbox *mbox,
375                                    struct otx2_parse_state *pst,
376                                    struct otx2_npc_flow_info *flow_info);
377
378 void otx2_flow_get_hw_supp_mask(struct otx2_parse_state *pst,
379                                 struct otx2_flow_item_info *info,
380                                 int lid, int lt);
381
382 const struct rte_flow_item *
383 otx2_flow_skip_void_and_any_items(const struct rte_flow_item *pattern);
384
385 int otx2_flow_parse_lh(struct otx2_parse_state *pst);
386
387 int otx2_flow_parse_lg(struct otx2_parse_state *pst);
388
389 int otx2_flow_parse_lf(struct otx2_parse_state *pst);
390
391 int otx2_flow_parse_le(struct otx2_parse_state *pst);
392
393 int otx2_flow_parse_ld(struct otx2_parse_state *pst);
394
395 int otx2_flow_parse_lc(struct otx2_parse_state *pst);
396
397 int otx2_flow_parse_lb(struct otx2_parse_state *pst);
398
399 int otx2_flow_parse_la(struct otx2_parse_state *pst);
400
401 int otx2_flow_parse_higig2_hdr(struct otx2_parse_state *pst);
402
403 int otx2_flow_parse_actions(struct rte_eth_dev *dev,
404                             const struct rte_flow_attr *attr,
405                             const struct rte_flow_action actions[],
406                             struct rte_flow_error *error,
407                             struct rte_flow *flow);
408
409 int otx2_flow_free_all_resources(struct otx2_eth_dev *hw);
410
411 int otx2_flow_parse_mpls(struct otx2_parse_state *pst, int lid);
412
413 void otx2_flow_dump(FILE *file, struct otx2_eth_dev *hw,
414                     struct rte_flow *flow);
415 #endif /* __OTX2_FLOW_H__ */