1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(C) 2019 Marvell International Ltd.
5 #ifndef __OTX2_FLOW_H__
6 #define __OTX2_FLOW_H__
10 #include <rte_flow_driver.h>
11 #include <rte_malloc.h>
12 #include <rte_tailq.h>
14 #include "otx2_common.h"
15 #include "otx2_ethdev.h"
16 #include "otx2_mbox.h"
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;
30 #define NPC_IH_LENGTH 8
31 #define NPC_TPID_LENGTH 2
32 #define NPC_COUNTER_NONE (-1)
33 /* 32 bytes from LDATA_CFG & 32 bytes from FLAGS_CFG */
34 #define NPC_MAX_EXTRACT_DATA_LEN (64)
35 #define NPC_LDATA_LFLAG_LEN (16)
36 #define NPC_MCAM_TOT_ENTRIES (4096)
37 #define NPC_MAX_KEY_NIBBLES (31)
39 #define NPC_LAYER_KEYX_SZ (3)
40 #define NPC_PARSE_KEX_S_LA_OFFSET (7)
41 #define NPC_PARSE_KEX_S_LID_OFFSET(lid) \
42 ((((lid) - NPC_LID_LA) * NPC_LAYER_KEYX_SZ) \
43 + NPC_PARSE_KEX_S_LA_OFFSET)
46 /* supported flow actions flags */
47 #define OTX2_FLOW_ACT_MARK (1 << 0)
48 #define OTX2_FLOW_ACT_FLAG (1 << 1)
49 #define OTX2_FLOW_ACT_DROP (1 << 2)
50 #define OTX2_FLOW_ACT_QUEUE (1 << 3)
51 #define OTX2_FLOW_ACT_RSS (1 << 4)
52 #define OTX2_FLOW_ACT_DUP (1 << 5)
53 #define OTX2_FLOW_ACT_SEC (1 << 6)
54 #define OTX2_FLOW_ACT_COUNT (1 << 7)
55 #define OTX2_FLOW_ACT_PF (1 << 8)
56 #define OTX2_FLOW_ACT_VF (1 << 9)
58 /* terminating actions */
59 #define OTX2_FLOW_ACT_TERM (OTX2_FLOW_ACT_DROP | \
60 OTX2_FLOW_ACT_QUEUE | \
65 /* This mark value indicates flag action */
66 #define OTX2_FLOW_FLAG_VAL (0xffff)
68 #define NIX_RX_ACT_MATCH_OFFSET (40)
69 #define NIX_RX_ACT_MATCH_MASK (0xFFFF)
71 #define NIX_RSS_ACT_GRP_OFFSET (20)
72 #define NIX_RSS_ACT_ALG_OFFSET (56)
73 #define NIX_RSS_ACT_GRP_MASK (0xFFFFF)
74 #define NIX_RSS_ACT_ALG_MASK (0x1F)
76 /* PMD-specific definition of the opaque struct rte_flow */
77 #define OTX2_MAX_MCAM_WIDTH_DWORDS 7
84 struct npc_xtract_info {
85 /* Length in bytes of pkt data extracted. len = 0
86 * indicates that extraction is disabled.
89 uint8_t hdr_off; /* Byte offset of proto hdr: extract_src */
90 uint8_t key_off; /* Byte offset in MCAM key where data is placed */
91 uint8_t enable; /* Extraction enabled or disabled */
92 uint8_t flags_enable; /* Flags extraction enabled */
95 /* Information for a given {LAYER, LTYPE} */
96 struct npc_lid_lt_xtract_info {
97 /* Info derived from parser configuration */
98 uint16_t npc_proto; /* Network protocol identified */
99 uint8_t valid_flags_mask; /* Flags applicable */
100 uint8_t is_terminating:1; /* No more parsing */
101 struct npc_xtract_info xtract[NPC_MAX_LD];
104 union npc_kex_ldata_flags_cfg {
106 #if defined(__BIG_ENDIAN_BITFIELD)
107 uint64_t rvsd_62_1 : 61;
111 uint64_t rvsd_62_1 : 61;
118 typedef struct npc_lid_lt_xtract_info
119 otx2_dxcfg_t[NPC_MAX_INTF][NPC_MAX_LID][NPC_MAX_LT];
120 typedef struct npc_lid_lt_xtract_info
121 otx2_fxcfg_t[NPC_MAX_INTF][NPC_MAX_LD][NPC_MAX_LFL];
122 typedef union npc_kex_ldata_flags_cfg otx2_ld_flags_t[NPC_MAX_LD];
125 /* MBOX_MSG_NPC_GET_DATAX_CFG Response */
126 struct npc_get_datax_cfg {
127 /* NPC_AF_KEX_LDATA(0..1)_FLAGS_CFG */
128 union npc_kex_ldata_flags_cfg ld_flags[NPC_MAX_LD];
129 /* Extract information indexed with [LID][LTYPE] */
130 struct npc_lid_lt_xtract_info lid_lt_xtract[NPC_MAX_LID][NPC_MAX_LT];
131 /* Flags based extract indexed with [LDATA][FLAGS_LOWER_NIBBLE]
132 * Fields flags_ena_ld0, flags_ena_ld1 in
133 * struct npc_lid_lt_xtract_info indicate if this is applicable
134 * for a given {LAYER, LTYPE}
136 struct npc_xtract_info flag_xtract[NPC_MAX_LD][NPC_MAX_LT];
139 struct otx2_mcam_ents_info {
140 /* Current max & min values of mcam index */
152 /* Contiguous match string */
153 uint64_t mcam_data[OTX2_MAX_MCAM_WIDTH_DWORDS];
154 uint64_t mcam_mask[OTX2_MAX_MCAM_WIDTH_DWORDS];
156 TAILQ_ENTRY(rte_flow) next;
159 TAILQ_HEAD(otx2_flow_list, rte_flow);
161 /* Accessed from ethdev private - otx2_eth_dev */
162 struct otx2_npc_flow_info {
163 rte_atomic32_t mark_actions;
164 uint32_t keyx_supp_nmask[NPC_MAX_INTF];/* nibble mask */
165 uint32_t keyx_len[NPC_MAX_INTF]; /* per intf key len in bits */
166 uint32_t datax_len[NPC_MAX_INTF]; /* per intf data len in bits */
167 uint32_t keyw[NPC_MAX_INTF]; /* max key + data len bits */
168 uint32_t mcam_entries; /* mcam entries supported */
169 otx2_dxcfg_t prx_dxcfg; /* intf, lid, lt, extract */
170 otx2_fxcfg_t prx_fxcfg; /* Flag extract */
171 otx2_ld_flags_t prx_lfcfg; /* KEX LD_Flags CFG */
172 /* mcam entry info per priority level: both free & in-use */
173 struct otx2_mcam_ents_info *flow_entry_info;
174 /* Bitmap of free preallocated entries in ascending index &
175 * descending priority
177 struct rte_bitmap **free_entries;
178 /* Bitmap of free preallocated entries in descending index &
181 struct rte_bitmap **free_entries_rev;
182 /* Bitmap of live entries in ascending index & descending priority */
183 struct rte_bitmap **live_entries;
184 /* Bitmap of live entries in descending index & ascending priority */
185 struct rte_bitmap **live_entries_rev;
186 /* Priority bucket wise tail queue of all rte_flow resources */
187 struct otx2_flow_list *flow_list;
188 uint32_t rss_grps; /* rss groups supported */
189 struct rte_bitmap *rss_grp_entries;
190 uint16_t channel; /*rx channel */
191 uint16_t flow_prealloc_size;
192 uint16_t flow_max_priority;
195 struct otx2_parse_state {
196 struct otx2_npc_flow_info *npc;
197 const struct rte_flow_item *pattern;
198 const struct rte_flow_item *last_pattern; /* Temp usage */
199 struct rte_flow_error *error;
200 struct rte_flow *flow;
204 uint8_t lt[NPC_MAX_LID];
205 uint8_t flags[NPC_MAX_LID];
206 uint8_t *mcam_data; /* point to flow->mcam_data + key_len */
207 uint8_t *mcam_mask; /* point to flow->mcam_mask + key_len */
210 struct otx2_flow_item_info {
211 const void *def_mask; /* rte_flow default mask */
212 void *hw_mask; /* hardware supported mask */
213 int len; /* length of item */
214 const void *spec; /* spec to use, NULL implies match any */
215 const void *mask; /* mask to use */
216 uint8_t hw_hdr_len; /* Extra data len at each layer*/
219 struct otx2_idev_kex_cfg {
220 struct npc_get_kex_cfg_rsp kex_cfg;
221 rte_atomic16_t kex_refcnt;
224 enum npc_kpu_parser_flag {
240 NPC_F_STAG_STAG_CTAG,
241 NPC_F_STAG_STAG_STAG,
244 NPC_F_QINQ_QINQ_CTAG,
245 NPC_F_QINQ_QINQ_QINQ,
247 NPC_F_BTAG_ITAG_STAG,
248 NPC_F_BTAG_ITAG_CTAG,
251 NPC_F_ETAG_BTAG_ITAG,
255 NPC_F_ETAG_ITAG_STAG,
256 NPC_F_ETAG_ITAG_CTAG,
258 NPC_F_ITAG_STAG_CTAG,
264 NPC_F_IP_HAS_OPTIONS,
269 NPC_F_IP_IP_IN_IP_HAS_OPTIONS,
270 NPC_F_IP_6TO4_HAS_OPTIONS,
271 NPC_F_IP_MPLS_IN_IP_HAS_OPTIONS,
272 NPC_F_IP_UNK_PROTO_HAS_OPTIONS,
275 NPC_F_IP6_MPLS_IN_IP,
276 NPC_F_TCP_HAS_OPTIONS,
281 NPC_F_TCP_HTTP_HAS_OPTIONS,
282 NPC_F_TCP_HTTPS_HAS_OPTIONS,
283 NPC_F_TCP_PPTP_HAS_OPTIONS,
284 NPC_F_TCP_UNK_PORT_HAS_OPTIONS,
286 NPC_F_UDP_VXLAN_NOVNI,
287 NPC_F_UDP_VXLAN_NOVNI_NSH,
289 NPC_F_UDP_VXLANGPE_NSH,
290 NPC_F_UDP_VXLANGPE_MPLS,
291 NPC_F_UDP_VXLANGPE_NOVNI,
292 NPC_F_UDP_VXLANGPE_NOVNI_NSH,
293 NPC_F_UDP_VXLANGPE_NOVNI_MPLS,
294 NPC_F_UDP_VXLANGPE_UNK,
295 NPC_F_UDP_VXLANGPE_NONP,
297 NPC_F_UDP_GTP_GTPU_G_PDU,
298 NPC_F_UDP_GTP_GTPU_UNK,
301 NPC_F_UDP_GENEVE_OAM,
302 NPC_F_UDP_GENEVE_CRI_OPT,
303 NPC_F_UDP_GENEVE_OAM_CRI_OPT,
309 NPC_F_GRE_HAS_CSUM_KEY,
310 NPC_F_GRE_HAS_CSUM_SEQ,
311 NPC_F_GRE_HAS_KEY_SEQ,
312 NPC_F_GRE_HAS_CSUM_KEY_SEQ,
316 NPC_F_GRE_VER1_HAS_SEQ,
317 NPC_F_GRE_VER1_HAS_ACK,
318 NPC_F_GRE_VER1_HAS_SEQ_ACK,
319 NPC_F_GRE_VER1_UNK_PROTO,
322 NPC_F_TU_ETHER_CTAG_UNK,
323 NPC_F_TU_ETHER_STAG_CTAG,
324 NPC_F_TU_ETHER_STAG_CTAG_UNK,
326 NPC_F_TU_ETHER_STAG_UNK,
327 NPC_F_TU_ETHER_QINQ_CTAG,
328 NPC_F_TU_ETHER_QINQ_CTAG_UNK,
330 NPC_F_TU_ETHER_QINQ_UNK,
331 NPC_F_LAST /* has to be the last item */
335 int otx2_flow_mcam_free_counter(struct otx2_mbox *mbox, uint16_t ctr_id);
337 int otx2_flow_mcam_read_counter(struct otx2_mbox *mbox, uint32_t ctr_id,
340 int otx2_flow_mcam_clear_counter(struct otx2_mbox *mbox, uint32_t ctr_id);
342 int otx2_flow_mcam_free_entry(struct otx2_mbox *mbox, uint32_t entry);
344 int otx2_flow_mcam_free_all_entries(struct otx2_mbox *mbox);
346 int otx2_flow_update_parse_state(struct otx2_parse_state *pst,
347 struct otx2_flow_item_info *info,
348 int lid, int lt, uint8_t flags);
350 int otx2_flow_parse_item_basic(const struct rte_flow_item *item,
351 struct otx2_flow_item_info *info,
352 struct rte_flow_error *error);
354 void otx2_flow_keyx_compress(uint64_t *data, uint32_t nibble_mask);
356 int otx2_flow_mcam_alloc_and_write(struct rte_flow *flow,
357 struct otx2_mbox *mbox,
358 struct otx2_parse_state *pst,
359 struct otx2_npc_flow_info *flow_info);
361 void otx2_flow_get_hw_supp_mask(struct otx2_parse_state *pst,
362 struct otx2_flow_item_info *info,
365 const struct rte_flow_item *
366 otx2_flow_skip_void_and_any_items(const struct rte_flow_item *pattern);
368 int otx2_flow_parse_lh(struct otx2_parse_state *pst);
370 int otx2_flow_parse_lg(struct otx2_parse_state *pst);
372 int otx2_flow_parse_lf(struct otx2_parse_state *pst);
374 int otx2_flow_parse_le(struct otx2_parse_state *pst);
376 int otx2_flow_parse_ld(struct otx2_parse_state *pst);
378 int otx2_flow_parse_lc(struct otx2_parse_state *pst);
380 int otx2_flow_parse_lb(struct otx2_parse_state *pst);
382 int otx2_flow_parse_la(struct otx2_parse_state *pst);
384 int otx2_flow_parse_actions(struct rte_eth_dev *dev,
385 const struct rte_flow_attr *attr,
386 const struct rte_flow_action actions[],
387 struct rte_flow_error *error,
388 struct rte_flow *flow);
390 int otx2_flow_free_all_resources(struct otx2_eth_dev *hw);
392 int otx2_flow_parse_mpls(struct otx2_parse_state *pst, int lid);
393 #endif /* __OTX2_FLOW_H__ */