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"
18 int otx2_flow_init(struct otx2_eth_dev *hw);
19 int otx2_flow_fini(struct otx2_eth_dev *hw);
20 extern const struct rte_flow_ops otx2_flow_ops;
28 #define NPC_IH_LENGTH 8
29 #define NPC_TPID_LENGTH 2
30 #define NPC_COUNTER_NONE (-1)
31 /* 32 bytes from LDATA_CFG & 32 bytes from FLAGS_CFG */
32 #define NPC_MAX_EXTRACT_DATA_LEN (64)
33 #define NPC_LDATA_LFLAG_LEN (16)
34 #define NPC_MCAM_TOT_ENTRIES (4096)
35 #define NPC_MAX_KEY_NIBBLES (31)
37 #define NPC_LAYER_KEYX_SZ (3)
38 #define NPC_PARSE_KEX_S_LA_OFFSET (7)
39 #define NPC_PARSE_KEX_S_LID_OFFSET(lid) \
40 ((((lid) - NPC_LID_LA) * NPC_LAYER_KEYX_SZ) \
41 + NPC_PARSE_KEX_S_LA_OFFSET)
44 /* supported flow actions flags */
45 #define OTX2_FLOW_ACT_MARK (1 << 0)
46 #define OTX2_FLOW_ACT_FLAG (1 << 1)
47 #define OTX2_FLOW_ACT_DROP (1 << 2)
48 #define OTX2_FLOW_ACT_QUEUE (1 << 3)
49 #define OTX2_FLOW_ACT_RSS (1 << 4)
50 #define OTX2_FLOW_ACT_DUP (1 << 5)
51 #define OTX2_FLOW_ACT_SEC (1 << 6)
52 #define OTX2_FLOW_ACT_COUNT (1 << 7)
54 /* terminating actions */
55 #define OTX2_FLOW_ACT_TERM (OTX2_FLOW_ACT_DROP | \
56 OTX2_FLOW_ACT_QUEUE | \
61 /* This mark value indicates flag action */
62 #define OTX2_FLOW_FLAG_VAL (0xffff)
64 #define NIX_RX_ACT_MATCH_OFFSET (40)
65 #define NIX_RX_ACT_MATCH_MASK (0xFFFF)
67 #define NIX_RSS_ACT_GRP_OFFSET (20)
68 #define NIX_RSS_ACT_ALG_OFFSET (56)
69 #define NIX_RSS_ACT_GRP_MASK (0xFFFFF)
70 #define NIX_RSS_ACT_ALG_MASK (0x1F)
72 /* PMD-specific definition of the opaque struct rte_flow */
73 #define OTX2_MAX_MCAM_WIDTH_DWORDS 7
80 struct npc_xtract_info {
81 /* Length in bytes of pkt data extracted. len = 0
82 * indicates that extraction is disabled.
85 uint8_t hdr_off; /* Byte offset of proto hdr: extract_src */
86 uint8_t key_off; /* Byte offset in MCAM key where data is placed */
87 uint8_t enable; /* Extraction enabled or disabled */
90 /* Information for a given {LAYER, LTYPE} */
91 struct npc_lid_lt_xtract_info {
92 /* Info derived from parser configuration */
93 uint16_t npc_proto; /* Network protocol identified */
94 uint8_t valid_flags_mask; /* Flags applicable */
95 uint8_t is_terminating:1; /* No more parsing */
96 struct npc_xtract_info xtract[NPC_MAX_LD];
99 union npc_kex_ldata_flags_cfg {
101 #if defined(__BIG_ENDIAN_BITFIELD)
102 uint64_t rvsd_62_1 : 61;
106 uint64_t rvsd_62_1 : 61;
113 typedef struct npc_lid_lt_xtract_info
114 otx2_dxcfg_t[NPC_MAX_INTF][NPC_MAX_LID][NPC_MAX_LT];
115 typedef struct npc_lid_lt_xtract_info
116 otx2_fxcfg_t[NPC_MAX_INTF][NPC_MAX_LD][NPC_MAX_LFL];
117 typedef union npc_kex_ldata_flags_cfg otx2_ld_flags_t[NPC_MAX_LD];
120 /* MBOX_MSG_NPC_GET_DATAX_CFG Response */
121 struct npc_get_datax_cfg {
122 /* NPC_AF_KEX_LDATA(0..1)_FLAGS_CFG */
123 union npc_kex_ldata_flags_cfg ld_flags[NPC_MAX_LD];
124 /* Extract information indexed with [LID][LTYPE] */
125 struct npc_lid_lt_xtract_info lid_lt_xtract[NPC_MAX_LID][NPC_MAX_LT];
126 /* Flags based extract indexed with [LDATA][FLAGS_LOWER_NIBBLE]
127 * Fields flags_ena_ld0, flags_ena_ld1 in
128 * struct npc_lid_lt_xtract_info indicate if this is applicable
129 * for a given {LAYER, LTYPE}
131 struct npc_xtract_info flag_xtract[NPC_MAX_LD][NPC_MAX_LT];
134 struct otx2_mcam_ents_info {
135 /* Current max & min values of mcam index */
147 /* Contiguous match string */
148 uint64_t mcam_data[OTX2_MAX_MCAM_WIDTH_DWORDS];
149 uint64_t mcam_mask[OTX2_MAX_MCAM_WIDTH_DWORDS];
151 TAILQ_ENTRY(rte_flow) next;
154 TAILQ_HEAD(otx2_flow_list, rte_flow);
156 /* Accessed from ethdev private - otx2_eth_dev */
157 struct otx2_npc_flow_info {
158 rte_atomic32_t mark_actions;
159 uint32_t keyx_supp_nmask[NPC_MAX_INTF];/* nibble mask */
160 uint32_t keyx_len[NPC_MAX_INTF]; /* per intf key len in bits */
161 uint32_t datax_len[NPC_MAX_INTF]; /* per intf data len in bits */
162 uint32_t keyw[NPC_MAX_INTF]; /* max key + data len bits */
163 uint32_t mcam_entries; /* mcam entries supported */
164 otx2_dxcfg_t prx_dxcfg; /* intf, lid, lt, extract */
165 otx2_fxcfg_t prx_fxcfg; /* Flag extract */
166 otx2_ld_flags_t prx_lfcfg; /* KEX LD_Flags CFG */
167 /* mcam entry info per priority level: both free & in-use */
168 struct otx2_mcam_ents_info *flow_entry_info;
169 /* Bitmap of free preallocated entries in ascending index &
170 * descending priority
172 struct rte_bitmap **free_entries;
173 /* Bitmap of free preallocated entries in descending index &
176 struct rte_bitmap **free_entries_rev;
177 /* Bitmap of live entries in ascending index & descending priority */
178 struct rte_bitmap **live_entries;
179 /* Bitmap of live entries in descending index & ascending priority */
180 struct rte_bitmap **live_entries_rev;
181 /* Priority bucket wise tail queue of all rte_flow resources */
182 struct otx2_flow_list *flow_list;
183 uint32_t rss_grps; /* rss groups supported */
184 struct rte_bitmap *rss_grp_entries;
185 uint16_t channel; /*rx channel */
186 uint16_t flow_prealloc_size;
187 uint16_t flow_max_priority;
190 struct otx2_parse_state {
191 struct otx2_npc_flow_info *npc;
192 const struct rte_flow_item *pattern;
193 const struct rte_flow_item *last_pattern; /* Temp usage */
194 struct rte_flow_error *error;
195 struct rte_flow *flow;
199 uint8_t lt[NPC_MAX_LID];
200 uint8_t flags[NPC_MAX_LID];
201 uint8_t *mcam_data; /* point to flow->mcam_data + key_len */
202 uint8_t *mcam_mask; /* point to flow->mcam_mask + key_len */
205 struct otx2_flow_item_info {
206 const void *def_mask; /* rte_flow default mask */
207 void *hw_mask; /* hardware supported mask */
208 int len; /* length of item */
209 const void *spec; /* spec to use, NULL implies match any */
210 const void *mask; /* mask to use */
211 uint8_t hw_hdr_len; /* Extra data len at each layer*/
214 struct otx2_idev_kex_cfg {
215 struct npc_get_kex_cfg_rsp kex_cfg;
216 rte_atomic16_t kex_refcnt;
219 enum npc_kpu_parser_flag {
235 NPC_F_STAG_STAG_CTAG,
236 NPC_F_STAG_STAG_STAG,
239 NPC_F_QINQ_QINQ_CTAG,
240 NPC_F_QINQ_QINQ_QINQ,
242 NPC_F_BTAG_ITAG_STAG,
243 NPC_F_BTAG_ITAG_CTAG,
246 NPC_F_ETAG_BTAG_ITAG,
250 NPC_F_ETAG_ITAG_STAG,
251 NPC_F_ETAG_ITAG_CTAG,
253 NPC_F_ITAG_STAG_CTAG,
259 NPC_F_IP_HAS_OPTIONS,
264 NPC_F_IP_IP_IN_IP_HAS_OPTIONS,
265 NPC_F_IP_6TO4_HAS_OPTIONS,
266 NPC_F_IP_MPLS_IN_IP_HAS_OPTIONS,
267 NPC_F_IP_UNK_PROTO_HAS_OPTIONS,
270 NPC_F_IP6_MPLS_IN_IP,
271 NPC_F_TCP_HAS_OPTIONS,
276 NPC_F_TCP_HTTP_HAS_OPTIONS,
277 NPC_F_TCP_HTTPS_HAS_OPTIONS,
278 NPC_F_TCP_PPTP_HAS_OPTIONS,
279 NPC_F_TCP_UNK_PORT_HAS_OPTIONS,
281 NPC_F_UDP_VXLAN_NOVNI,
282 NPC_F_UDP_VXLAN_NOVNI_NSH,
284 NPC_F_UDP_VXLANGPE_NSH,
285 NPC_F_UDP_VXLANGPE_MPLS,
286 NPC_F_UDP_VXLANGPE_NOVNI,
287 NPC_F_UDP_VXLANGPE_NOVNI_NSH,
288 NPC_F_UDP_VXLANGPE_NOVNI_MPLS,
289 NPC_F_UDP_VXLANGPE_UNK,
290 NPC_F_UDP_VXLANGPE_NONP,
292 NPC_F_UDP_GTP_GTPU_G_PDU,
293 NPC_F_UDP_GTP_GTPU_UNK,
296 NPC_F_UDP_GENEVE_OAM,
297 NPC_F_UDP_GENEVE_CRI_OPT,
298 NPC_F_UDP_GENEVE_OAM_CRI_OPT,
304 NPC_F_GRE_HAS_CSUM_KEY,
305 NPC_F_GRE_HAS_CSUM_SEQ,
306 NPC_F_GRE_HAS_KEY_SEQ,
307 NPC_F_GRE_HAS_CSUM_KEY_SEQ,
311 NPC_F_GRE_VER1_HAS_SEQ,
312 NPC_F_GRE_VER1_HAS_ACK,
313 NPC_F_GRE_VER1_HAS_SEQ_ACK,
314 NPC_F_GRE_VER1_UNK_PROTO,
317 NPC_F_TU_ETHER_CTAG_UNK,
318 NPC_F_TU_ETHER_STAG_CTAG,
319 NPC_F_TU_ETHER_STAG_CTAG_UNK,
321 NPC_F_TU_ETHER_STAG_UNK,
322 NPC_F_TU_ETHER_QINQ_CTAG,
323 NPC_F_TU_ETHER_QINQ_CTAG_UNK,
325 NPC_F_TU_ETHER_QINQ_UNK,
326 NPC_F_LAST /* has to be the last item */
330 int otx2_flow_mcam_free_counter(struct otx2_mbox *mbox, uint16_t ctr_id);
332 int otx2_flow_mcam_read_counter(struct otx2_mbox *mbox, uint32_t ctr_id,
335 int otx2_flow_mcam_clear_counter(struct otx2_mbox *mbox, uint32_t ctr_id);
337 int otx2_flow_mcam_free_entry(struct otx2_mbox *mbox, uint32_t entry);
339 int otx2_flow_mcam_free_all_entries(struct otx2_mbox *mbox);
341 int otx2_flow_update_parse_state(struct otx2_parse_state *pst,
342 struct otx2_flow_item_info *info,
343 int lid, int lt, uint8_t flags);
345 int otx2_flow_parse_item_basic(const struct rte_flow_item *item,
346 struct otx2_flow_item_info *info,
347 struct rte_flow_error *error);
349 void otx2_flow_keyx_compress(uint64_t *data, uint32_t nibble_mask);
351 int otx2_flow_mcam_alloc_and_write(struct rte_flow *flow,
352 struct otx2_mbox *mbox,
353 struct otx2_parse_state *pst,
354 struct otx2_npc_flow_info *flow_info);
356 void otx2_flow_get_hw_supp_mask(struct otx2_parse_state *pst,
357 struct otx2_flow_item_info *info,
360 const struct rte_flow_item *
361 otx2_flow_skip_void_and_any_items(const struct rte_flow_item *pattern);
363 int otx2_flow_parse_lh(struct otx2_parse_state *pst);
365 int otx2_flow_parse_lg(struct otx2_parse_state *pst);
367 int otx2_flow_parse_lf(struct otx2_parse_state *pst);
369 int otx2_flow_parse_le(struct otx2_parse_state *pst);
371 int otx2_flow_parse_ld(struct otx2_parse_state *pst);
373 int otx2_flow_parse_lc(struct otx2_parse_state *pst);
375 int otx2_flow_parse_lb(struct otx2_parse_state *pst);
377 int otx2_flow_parse_la(struct otx2_parse_state *pst);
379 int otx2_flow_parse_actions(struct rte_eth_dev *dev,
380 const struct rte_flow_attr *attr,
381 const struct rte_flow_action actions[],
382 struct rte_flow_error *error,
383 struct rte_flow *flow);
385 int otx2_flow_free_all_resources(struct otx2_eth_dev *hw);
387 int otx2_flow_parse_mpls(struct otx2_parse_state *pst, int lid);
388 #endif /* __OTX2_FLOW_H__ */