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