Branch data Line data Source code
1 : : /* SPDX-License-Identifier: BSD-3-Clause
2 : : * Copyright(C) 2021 Marvell.
3 : : */
4 : :
5 : : #ifndef _ROC_NPC_PRIV_H_
6 : : #define _ROC_NPC_PRIV_H_
7 : :
8 : : #define NPC_IH_LENGTH 8
9 : : #define NPC_TPID_LENGTH 2
10 : : #define NPC_HIGIG2_LENGTH 16
11 : : #define NPC_MAX_RAW_ITEM_LEN 16
12 : : #define NPC_COUNTER_NONE (-1)
13 : :
14 : : #define NPC_RSS_GRPS 8
15 : :
16 : : #define NPC_ACTION_FLAG_DEFAULT 0xffff
17 : :
18 : : #define NPC_PFVF_FUNC_MASK 0x3FF
19 : :
20 : : /* 32 bytes from LDATA_CFG & 32 bytes from FLAGS_CFG */
21 : : #define NPC_MAX_EXTRACT_DATA_LEN (64)
22 : : #define NPC_MAX_EXTRACT_HW_LEN (4 * NPC_MAX_EXTRACT_DATA_LEN)
23 : : #define NPC_LDATA_LFLAG_LEN (16)
24 : : #define NPC_MAX_KEY_NIBBLES (31)
25 : :
26 : : /* Nibble offsets */
27 : : #define NPC_LAYER_KEYX_SZ (3)
28 : : #define NPC_PARSE_KEX_S_LA_OFFSET (7)
29 : : #define NPC_PARSE_KEX_S_LID_OFFSET(lid) \
30 : : ((((lid) - (NPC_LID_LA)) * NPC_LAYER_KEYX_SZ) + \
31 : : NPC_PARSE_KEX_S_LA_OFFSET)
32 : :
33 : : #define NPC_LAYER_KEYX_SZ_CN20K (2)
34 : : #define NPC_PARSE_KEX_S_LID_OFFSET_CN20K(lid) \
35 : : ((((lid) - (NPC_LID_LA)) * NPC_LAYER_KEYX_SZ_CN20K) + NPC_PARSE_KEX_S_LA_OFFSET)
36 : :
37 : : /* This mark value indicates flag action */
38 : : #define NPC_FLOW_FLAG_VAL (0xffff)
39 : :
40 : : #define NPC_RX_ACT_MATCH_OFFSET (40)
41 : : #define NPC_RX_ACT_MATCH_MASK (0xFFFF)
42 : :
43 : : #define NPC_RSS_ACT_GRP_OFFSET (20)
44 : : #define NPC_RSS_ACT_ALG_OFFSET (56)
45 : : #define NPC_RSS_ACT_GRP_MASK (0xFFFFF)
46 : : #define NPC_RSS_ACT_ALG_MASK (0x1F)
47 : :
48 : : #define NPC_MCAM_KEX_FIELD_MAX 23
49 : : #define NPC_MCAM_MAX_PROTO_FIELDS (NPC_MCAM_KEX_FIELD_MAX + 1)
50 : : #if defined(ROC_PLATFORM_CN20K)
51 : : #define NPC_MCAM_KEY_X4_WORDS 8 /* Number of 64-bit words */
52 : : #else
53 : : #define NPC_MCAM_KEY_X4_WORDS 7 /* Number of 64-bit words */
54 : : #endif
55 : :
56 : : #define NPC_RVUPF_MAX_9XXX 0x10 /* HRM: RVU_PRIV_CONST */
57 : : #define NPC_RVUPF_MAX_98XX 0x18 /* HRM: RVU_PRIV_CONST */
58 : : #define NPC_RVUPF_MAX_10XX 0x20 /* HRM: RVU_PRIV_CONST */
59 : : #define NPC_NIXLF_MAX 0x80 /* HRM: NIX_AF_CONST2 */
60 : : #define NPC_MCAME_PER_PF 3 /* DRV: RSVD_MCAM_ENTRIES_PER_PF */
61 : : #define NPC_MCAME_PER_LF 1 /* DRV: RSVD_MCAM_ENTRIES_PER_NIXLF */
62 : : #define NPC_NIXLF_MAX_98XX (2 * NPC_NIXLF_MAX) /*2 NIXLFs */
63 : : #define NPC_MCAME_RESVD_9XXX \
64 : : (NPC_NIXLF_MAX * NPC_MCAME_PER_LF + \
65 : : (NPC_RVUPF_MAX_9XXX - 1) * NPC_MCAME_PER_PF)
66 : :
67 : : #define NPC_MCAME_RESVD_10XX \
68 : : (NPC_NIXLF_MAX * NPC_MCAME_PER_LF + \
69 : : (NPC_RVUPF_MAX_10XX - 1) * NPC_MCAME_PER_PF)
70 : :
71 : : #define NPC_MCAME_RESVD_98XX \
72 : : (NPC_NIXLF_MAX_98XX * NPC_MCAME_PER_LF + \
73 : : (NPC_RVUPF_MAX_98XX - 1) * NPC_MCAME_PER_PF)
74 : :
75 : : #define NPC_ACTION_MAX_VLAN_PARAMS 3
76 : : #define NPC_ACTION_MAX_VLANS_STRIPPED 2
77 : :
78 : : #define NPC_LTYPE_OFFSET_START 7
79 : : /* LB OFFSET : START + LA (2b flags + 1b ltype) + LB (2b flags) */
80 : : #define NPC_LTYPE_LB_OFFSET (NPC_LTYPE_OFFSET_START + 5)
81 : : #define NPC_LFLAG_LB_OFFSET (NPC_LTYPE_OFFSET_START + 3)
82 : : /* LC OFFSET : START + LA (2b flags + 1b ltype) + LB (2b flags + 1b ltype) + LC
83 : : * (2b flags)
84 : : */
85 : : #define NPC_LFLAG_LC_OFFSET (NPC_LTYPE_OFFSET_START + 6)
86 : : #define NPC_LTYPE_LC_OFFSET (NPC_LTYPE_OFFSET_START + 8)
87 : :
88 : : /* LB OFFSET : START + LA (1b flags + 1b ltype) + LB (1b flags) */
89 : : #define NPC_CN20K_LTYPE_LB_OFFSET (NPC_LTYPE_OFFSET_START + 3)
90 : : #define NPC_CN20K_LFLAG_LB_OFFSET (NPC_LTYPE_OFFSET_START + 2)
91 : :
92 : : /* LC OFFSET : START + LA (1b flags + 1b ltype) + LB (1b flags + 1b ltype) + LC
93 : : * (1b flags)
94 : : */
95 : : #define NPC_CN20K_LFLAG_LC_OFFSET (NPC_LTYPE_OFFSET_START + 4)
96 : : #define NPC_CN20K_LTYPE_LC_OFFSET (NPC_LTYPE_OFFSET_START + 5)
97 : :
98 : : #define NPC_ACTION2_FLOW_VEC_VLD_FIELD 0xE
99 : : #define NPC_ACTION2_FLOW_VEC_FIELD 0xC
100 : :
101 : : #define CN10K_SDP_CH_START 0x80
102 : : #define CN10K_SDP_CH_MASK 0xF80
103 : :
104 : : struct npc_action_vtag_info {
105 : : uint16_t vlan_id;
106 : : uint16_t vlan_ethtype;
107 : : uint8_t vlan_pcp;
108 : : };
109 : :
110 : : enum npc_err_status {
111 : : NPC_ERR_PARAM = -1024,
112 : : NPC_ERR_NO_MEM,
113 : : NPC_ERR_INVALID_SPEC,
114 : : NPC_ERR_INVALID_MASK,
115 : : NPC_ERR_INVALID_RANGE,
116 : : NPC_ERR_INVALID_KEX,
117 : : NPC_ERR_INVALID_SIZE,
118 : : NPC_ERR_INTERNAL,
119 : : NPC_ERR_MCAM_ALLOC,
120 : : NPC_ERR_ACTION_NOTSUP,
121 : : NPC_ERR_PATTERN_NOTSUP,
122 : : };
123 : :
124 : : enum npc_mcam_intf { NPC_MCAM_RX, NPC_MCAM_TX };
125 : :
126 : : typedef union npc_kex_cap_terms_t {
127 : : /** Packet Matching Rule term fields */
128 : : struct {
129 : : /** Total length of received packet */
130 : : uint64_t len : 1;
131 : : /** Initial (outer) Ethertype only */
132 : : uint64_t ethtype_0 : 1;
133 : : /** Ethertype of most inner VLAN tag */
134 : : uint64_t ethtype_x : 1;
135 : : /** First VLAN ID (outer) */
136 : : uint64_t vlan_id_0 : 1;
137 : : /** Last VLAN ID (inner) */
138 : : uint64_t vlan_id_x : 1;
139 : : /** PCP in the first VLAN header */
140 : : uint64_t vlan_pcp_0 : 1;
141 : : /** destination MAC address */
142 : : uint64_t dmac : 1;
143 : : /** IP Protocol or IPv6 Next Header */
144 : : uint64_t ip_proto : 1;
145 : : /** DSCP in IP header */
146 : : uint64_t ip_dscp : 1;
147 : : /** Destination UDP port, implies IPPROTO=17 */
148 : : uint64_t udp_dport : 1;
149 : : /** Destination TCP port implies IPPROTO=6 */
150 : : uint64_t tcp_dport : 1;
151 : : /** Source UDP Port */
152 : : uint64_t udp_sport : 1;
153 : : /** Source TCP port */
154 : : uint64_t tcp_sport : 1;
155 : : /** Source IP address */
156 : : uint64_t sip_addr : 1;
157 : : /** Destination IP address */
158 : : uint64_t dip_addr : 1;
159 : : /** Source IP address */
160 : : uint64_t sip6_addr : 1;
161 : : /** Destination IP address */
162 : : uint64_t dip6_addr : 1;
163 : : /** IPsec session identifier */
164 : : uint64_t ipsec_spi : 1;
165 : : /** NVGRE/VXLAN network identifier */
166 : : uint64_t ld_vni : 1;
167 : : /** Custom frame match rule. PMR offset is counted from
168 : : * the start of the packet.
169 : : */
170 : : uint64_t custom_frame : 1;
171 : : /** Custom layer 3 match rule. PMR offset is counted from
172 : : * the start of layer 3 in the packet.
173 : : */
174 : : uint64_t custom_l3 : 1;
175 : : /** IGMP Group address */
176 : : uint64_t igmp_grp_addr : 1;
177 : : /** ICMP identifier */
178 : : uint64_t icmp_id : 1;
179 : : /** ICMP type */
180 : : uint64_t icmp_type : 1;
181 : : /** ICMP code */
182 : : uint64_t icmp_code : 1;
183 : : /** Source SCTP port */
184 : : uint64_t sctp_sport : 1;
185 : : /** Destination SCTP port */
186 : : uint64_t sctp_dport : 1;
187 : : /** GTPv1 tunnel endpoint identifier */
188 : : uint64_t gtpv1_teid : 1;
189 : : } bit;
190 : :
191 : : /** All bits of the bit field structure */
192 : : uint64_t all_bits;
193 : :
194 : : } npc_kex_cap_terms_t;
195 : :
196 : : struct npc_parse_item_info {
197 : : const void *def_mask; /* default mask */
198 : : void *hw_mask; /* hardware supported mask */
199 : : int len; /* length of item */
200 : : uint8_t hw_hdr_len; /* Extra data len at each layer*/
201 : : const void *spec; /* spec to use, NULL implies match any */
202 : : const void *mask; /* mask to use */
203 : : };
204 : :
205 : : struct npc_parse_state {
206 : : struct npc *npc;
207 : : const struct roc_npc_item_info *pattern;
208 : : const struct roc_npc_item_info *last_pattern;
209 : : struct roc_npc_flow *flow;
210 : : uint8_t nix_intf;
211 : : uint8_t tunnel;
212 : : uint8_t terminate;
213 : : uint8_t layer_mask;
214 : : uint8_t lt[NPC_MAX_LID];
215 : : uint8_t flags[NPC_MAX_LID];
216 : : bool has_eth_type;
217 : : bool is_second_pass_rule;
218 : : bool set_ipv6ext_ltype_mask;
219 : : /* adjust ltype in MCAM to match at least one vlan */
220 : : bool set_vlan_ltype_mask;
221 : : uint8_t *mcam_data; /* point to flow->mcam_data + key_len */
222 : : uint8_t *mcam_mask; /* point to flow->mcam_mask + key_len */
223 : : bool is_vf;
224 : : uint16_t dst_pf_func;
225 : : uint64_t npc_default_action;
226 : : uint16_t nb_tx_queues;
227 : : };
228 : :
229 : : enum npc_kpu_parser_flag {
230 : : NPC_F_NA = 0,
231 : : NPC_F_PKI,
232 : : NPC_F_PKI_VLAN,
233 : : NPC_F_PKI_ETAG,
234 : : NPC_F_PKI_ITAG,
235 : : NPC_F_PKI_MPLS,
236 : : NPC_F_PKI_NSH,
237 : : NPC_F_ETYPE_UNK,
238 : : NPC_F_ETHER_VLAN,
239 : : NPC_F_ETHER_ETAG,
240 : : NPC_F_ETHER_ITAG,
241 : : NPC_F_ETHER_MPLS,
242 : : NPC_F_ETHER_NSH,
243 : : NPC_F_STAG_CTAG,
244 : : NPC_F_STAG_CTAG_UNK,
245 : : NPC_F_STAG_STAG_CTAG,
246 : : NPC_F_STAG_STAG_STAG,
247 : : NPC_F_QINQ_CTAG,
248 : : NPC_F_QINQ_CTAG_UNK,
249 : : NPC_F_QINQ_QINQ_CTAG,
250 : : NPC_F_QINQ_QINQ_QINQ,
251 : : NPC_F_BTAG_ITAG,
252 : : NPC_F_BTAG_ITAG_STAG,
253 : : NPC_F_BTAG_ITAG_CTAG,
254 : : NPC_F_BTAG_ITAG_UNK,
255 : : NPC_F_ETAG_CTAG,
256 : : NPC_F_ETAG_BTAG_ITAG,
257 : : NPC_F_ETAG_STAG,
258 : : NPC_F_ETAG_QINQ,
259 : : NPC_F_ETAG_ITAG,
260 : : NPC_F_ETAG_ITAG_STAG,
261 : : NPC_F_ETAG_ITAG_CTAG,
262 : : NPC_F_ETAG_ITAG_UNK,
263 : : NPC_F_ITAG_STAG_CTAG,
264 : : NPC_F_ITAG_STAG,
265 : : NPC_F_ITAG_CTAG,
266 : : NPC_F_MPLS_4_LABELS,
267 : : NPC_F_MPLS_3_LABELS,
268 : : NPC_F_MPLS_2_LABELS,
269 : : NPC_F_IP_HAS_OPTIONS,
270 : : NPC_F_IP_IP_IN_IP,
271 : : NPC_F_IP_6TO4,
272 : : NPC_F_IP_MPLS_IN_IP,
273 : : NPC_F_IP_UNK_PROTO,
274 : : NPC_F_IP_IP_IN_IP_HAS_OPTIONS,
275 : : NPC_F_IP_6TO4_HAS_OPTIONS,
276 : : NPC_F_IP_MPLS_IN_IP_HAS_OPTIONS,
277 : : NPC_F_IP_UNK_PROTO_HAS_OPTIONS,
278 : : NPC_F_IP6_HAS_EXT,
279 : : NPC_F_IP6_TUN_IP6,
280 : : NPC_F_IP6_MPLS_IN_IP,
281 : : NPC_F_TCP_HAS_OPTIONS,
282 : : NPC_F_TCP_HTTP,
283 : : NPC_F_TCP_HTTPS,
284 : : NPC_F_TCP_PPTP,
285 : : NPC_F_TCP_UNK_PORT,
286 : : NPC_F_TCP_HTTP_HAS_OPTIONS,
287 : : NPC_F_TCP_HTTPS_HAS_OPTIONS,
288 : : NPC_F_TCP_PPTP_HAS_OPTIONS,
289 : : NPC_F_TCP_UNK_PORT_HAS_OPTIONS,
290 : : NPC_F_UDP_VXLAN,
291 : : NPC_F_UDP_VXLAN_NOVNI,
292 : : NPC_F_UDP_VXLAN_NOVNI_NSH,
293 : : NPC_F_UDP_VXLANGPE,
294 : : NPC_F_UDP_VXLANGPE_NSH,
295 : : NPC_F_UDP_VXLANGPE_MPLS,
296 : : NPC_F_UDP_VXLANGPE_NOVNI,
297 : : NPC_F_UDP_VXLANGPE_NOVNI_NSH,
298 : : NPC_F_UDP_VXLANGPE_NOVNI_MPLS,
299 : : NPC_F_UDP_VXLANGPE_UNK,
300 : : NPC_F_UDP_VXLANGPE_NONP,
301 : : NPC_F_UDP_GTP_GTPC,
302 : : NPC_F_UDP_GTP_GTPU_G_PDU,
303 : : NPC_F_UDP_GTP_GTPU_UNK,
304 : : NPC_F_UDP_UNK_PORT,
305 : : NPC_F_UDP_GENEVE,
306 : : NPC_F_UDP_GENEVE_OAM,
307 : : NPC_F_UDP_GENEVE_CRI_OPT,
308 : : NPC_F_UDP_GENEVE_OAM_CRI_OPT,
309 : : NPC_F_GRE_NVGRE,
310 : : NPC_F_GRE_HAS_SRE,
311 : : NPC_F_GRE_HAS_CSUM,
312 : : NPC_F_GRE_HAS_KEY,
313 : : NPC_F_GRE_HAS_SEQ,
314 : : NPC_F_GRE_HAS_CSUM_KEY,
315 : : NPC_F_GRE_HAS_CSUM_SEQ,
316 : : NPC_F_GRE_HAS_KEY_SEQ,
317 : : NPC_F_GRE_HAS_CSUM_KEY_SEQ,
318 : : NPC_F_GRE_HAS_ROUTE,
319 : : NPC_F_GRE_UNK_PROTO,
320 : : NPC_F_GRE_VER1,
321 : : NPC_F_GRE_VER1_HAS_SEQ,
322 : : NPC_F_GRE_VER1_HAS_ACK,
323 : : NPC_F_GRE_VER1_HAS_SEQ_ACK,
324 : : NPC_F_GRE_VER1_UNK_PROTO,
325 : : NPC_F_TU_ETHER_UNK,
326 : : NPC_F_TU_ETHER_CTAG,
327 : : NPC_F_TU_ETHER_CTAG_UNK,
328 : : NPC_F_TU_ETHER_STAG_CTAG,
329 : : NPC_F_TU_ETHER_STAG_CTAG_UNK,
330 : : NPC_F_TU_ETHER_STAG,
331 : : NPC_F_TU_ETHER_STAG_UNK,
332 : : NPC_F_TU_ETHER_QINQ_CTAG,
333 : : NPC_F_TU_ETHER_QINQ_CTAG_UNK,
334 : : NPC_F_TU_ETHER_QINQ,
335 : : NPC_F_TU_ETHER_QINQ_UNK,
336 : : NPC_F_LAST /* has to be the last item */
337 : : };
338 : :
339 : : enum npc_mcam_cn20k_key_width {
340 : : NPC_CN20K_MCAM_KEY_X1 = 0,
341 : : NPC_CN20K_MCAM_KEY_DYN = NPC_CN20K_MCAM_KEY_X1,
342 : : NPC_CN20K_MCAM_KEY_X2,
343 : : NPC_CN20K_MCAM_KEY_X4,
344 : : NPC_CN20K_MCAM_KEY_MAX,
345 : : };
346 : :
347 : : #define NPC_ACTION_TERM \
348 : : (ROC_NPC_ACTION_TYPE_DROP | ROC_NPC_ACTION_TYPE_QUEUE | ROC_NPC_ACTION_TYPE_RSS | \
349 : : ROC_NPC_ACTION_TYPE_DUP | ROC_NPC_ACTION_TYPE_SEC)
350 : :
351 : : struct npc_xtract_info {
352 : : /* Length in bytes of pkt data extracted. len = 0
353 : : * indicates that extraction is disabled.
354 : : */
355 : : uint8_t len;
356 : : uint8_t hdr_off; /* Byte offset of proto hdr: extract_src */
357 : : uint8_t key_off; /* Byte offset in MCAM key where data is placed */
358 : : uint8_t enable; /* Extraction enabled or disabled */
359 : : uint8_t flags_enable; /* Flags extraction enabled */
360 : : uint8_t use_hash; /* Use field hash */
361 : : };
362 : :
363 : : /* Information for a given {LAYER, LTYPE} */
364 : : struct npc_lid_lt_xtract_info {
365 : : /* Info derived from parser configuration */
366 : : uint16_t npc_proto; /* Network protocol identified */
367 : : uint8_t valid_flags_mask; /* Flags applicable */
368 : : uint8_t is_terminating : 1; /* No more parsing */
369 : : struct npc_xtract_info xtract[NPC_MAX_LD];
370 : : };
371 : :
372 : : struct npc_lid_lt_xtract_info_cn20k {
373 : : /* Info derived from parser configuration */
374 : : uint16_t npc_proto; /* Network protocol identified */
375 : : uint8_t valid_flags_mask; /* Flags applicable */
376 : : uint8_t is_terminating : 1; /* No more parsing */
377 : : struct npc_xtract_info xtract;
378 : : };
379 : :
380 : : union npc_kex_ldata_flags_cfg {
381 : : struct {
382 : : uint64_t lid : 3;
383 : : uint64_t rvsd_62_1 : 61;
384 : : } s;
385 : :
386 : : uint64_t i;
387 : : };
388 : :
389 : : #define NPC_MAX_EXTRACTTORS 24
390 : : typedef struct npc_lid_lt_xtract_info_cn20k npc_dxcfg_cn20k_t[NPC_MAX_INTF][NPC_MAX_EXTRACTTORS]
391 : : [NPC_MAX_LT];
392 : : typedef union npc_kex_ldata_flags_cfg npc_lid_cn20k_t[NPC_MAX_INTF][NPC_MAX_EXTRACTTORS];
393 : :
394 : : typedef struct npc_lid_lt_xtract_info npc_dxcfg_t[NPC_MAX_INTF][NPC_MAX_LID]
395 : : [NPC_MAX_LT];
396 : : typedef struct npc_lid_lt_xtract_info npc_fxcfg_t[NPC_MAX_INTF][NPC_MAX_LD]
397 : : [NPC_MAX_LFL];
398 : : typedef union npc_kex_ldata_flags_cfg npc_ld_flags_t[NPC_MAX_LD];
399 : :
400 : : /* MBOX_MSG_NPC_GET_DATAX_CFG Response */
401 : : struct npc_get_datax_cfg {
402 : : /* NPC_AF_KEX_LDATA(0..1)_FLAGS_CFG */
403 : : union npc_kex_ldata_flags_cfg ld_flags[NPC_MAX_LD];
404 : : /* Extract information indexed with [LID][LTYPE] */
405 : : struct npc_lid_lt_xtract_info lid_lt_xtract[NPC_MAX_LID][NPC_MAX_LT];
406 : : /* Flags based extract indexed with [LDATA][FLAGS_LOWER_NIBBLE]
407 : : * Fields flags_ena_ld0, flags_ena_ld1 in
408 : : * struct npc_lid_lt_xtract_info indicate if this is applicable
409 : : * for a given {LAYER, LTYPE}
410 : : */
411 : : struct npc_xtract_info flag_xtract[NPC_MAX_LD][NPC_MAX_LT];
412 : : };
413 : :
414 : : TAILQ_HEAD(npc_flow_list, roc_npc_flow);
415 : :
416 : : struct npc_prio_flow_entry {
417 : : struct roc_npc_flow *flow;
418 : : TAILQ_ENTRY(npc_prio_flow_entry) next;
419 : : };
420 : :
421 : : TAILQ_HEAD(npc_prio_flow_list_head, npc_prio_flow_entry);
422 : :
423 : : struct npc_age_flow_entry {
424 : : struct roc_npc_flow *flow;
425 : : TAILQ_ENTRY(npc_age_flow_entry) next;
426 : : };
427 : :
428 : : TAILQ_HEAD(npc_age_flow_list_head, npc_age_flow_entry);
429 : :
430 : : /* Queue-based async template flow engine types. */
431 : :
432 : : /* One in-flight async op in a queue ring. */
433 : : struct roc_npc_async_op {
434 : : struct roc_npc_template_flow *flow; /**< Rule the op acts on. */
435 : : void *user_data; /**< Echoed back by flow_pull. */
436 : : bool is_create; /**< true = create, false = destroy. */
437 : : bool is_update; /**< true = in-place actions rewrite. */
438 : : bool done; /**< Set once pushed to hardware. */
439 : : int rc; /**< Result captured at push time. */
440 : : };
441 : :
442 : : /* Fixed-size op ring; head/pushed/tail are free-running indices. */
443 : : struct roc_npc_flow_queue {
444 : : struct roc_npc_async_op *ops; /**< size entries, power-of-two. */
445 : : uint32_t size; /**< Ring capacity (power of two). */
446 : : uint32_t head; /**< Next slot to enqueue into. */
447 : : uint32_t pushed; /**< Ops up to here are committed. */
448 : : uint32_t tail; /**< Next slot to return via pull. */
449 : : };
450 : :
451 : : /* A deep-copied, retained rule awaiting (or holding) a hardware entry. */
452 : : struct roc_npc_template_flow {
453 : : struct roc_npc_template_table *table; /**< Owning table. */
454 : : struct roc_npc_flow *roc_flow; /**< HW flow (PATTERN, once committed). */
455 : : struct roc_npc_item_info *items; /**< Deep-copied merged pattern. */
456 : : struct roc_npc_action *actions; /**< Deep-copied merged actions. */
457 : : struct roc_npc_flow flow; /**< Embedded HW flow (INDEX path). */
458 : : struct roc_npc_attr attr; /**< Priority / ingress / egress. */
459 : : uint64_t npc_default_action; /**< Resolved port default action. */
460 : : uint32_t flowkey_cfg; /**< RSS flow key captured at create. */
461 : : uint32_t slot; /**< Pre-reserved index (INDEX path). */
462 : : uint16_t dst_pf_func; /**< Resolved destination pf_func. */
463 : : uint16_t nb_items; /**< Item count (excluding END). */
464 : : uint16_t nb_actions; /**< Action count (excluding END). */
465 : : /* Pending in-place actions update, applied at push. */
466 : : struct {
467 : : uint64_t npc_action;
468 : : uint64_t npc_action2;
469 : : uint64_t vtag_action;
470 : : uint32_t recv_queue;
471 : : bool pending; /**< An update is enqueued, awaiting push. */
472 : : bool old_match_id; /**< Old action set carried a mark/match_id. */
473 : : bool old_vtag; /**< Old action set carried RX vtag strip. */
474 : : bool new_match_id; /**< New action set carries a mark/match_id. */
475 : : bool new_vtag; /**< New action set carries RX vtag strip. */
476 : : } pending_update;
477 : : TAILQ_ENTRY(roc_npc_template_flow) link;
478 : : };
479 : :
480 : : TAILQ_HEAD(roc_npc_template_flow_list, roc_npc_template_flow);
481 : :
482 : : /* Pattern template blueprint. */
483 : : struct roc_npc_pattern_template {
484 : : struct roc_npc_pattern_template_attr attr;
485 : : struct roc_npc_item_info *pattern; /**< nb_items + END terminator. */
486 : : void **copies; /**< Tracked payload allocations. */
487 : : uint16_t nb_copies; /**< Entries used in copies[]. */
488 : : uint16_t nb_items; /**< Item count (excluding END). */
489 : : uint32_t refcnt; /**< Tables referencing this template. */
490 : : };
491 : :
492 : : /* Actions template blueprint. */
493 : : struct roc_npc_actions_template {
494 : : struct roc_npc_actions_template_attr attr;
495 : : struct roc_npc_action *actions; /**< nb_actions + END terminator. */
496 : : struct roc_npc_action *masks; /**< Per-action masks (optional). */
497 : : void **copies; /**< Tracked conf allocations. */
498 : : uint16_t nb_copies; /**< Entries used in copies[]. */
499 : : uint16_t nb_actions; /**< Action count (excluding END). */
500 : : uint32_t refcnt; /**< Tables referencing this template. */
501 : : };
502 : :
503 : : /* Template table and rule storage. */
504 : : struct roc_npc_template_table {
505 : : int *mcam_ids; /**< Reserved entries (index). */
506 : : struct roc_npc_template_flow *flow_pool; /**< Per-index rule slots. */
507 : : struct roc_npc_pattern_template **pattern_templates;
508 : : struct roc_npc_actions_template **actions_templates;
509 : : struct roc_npc_template_flow_list live_flows; /**< Live pattern rules. */
510 : : struct roc_npc_template_table *next; /**< Port table list link. */
511 : : void *cookie; /**< Opaque consumer context. */
512 : : struct roc_npc_attr flow_attr; /**< Priority/ingress/egress. */
513 : : enum roc_npc_template_table_insertion_type insertion_type;
514 : : plt_spinlock_t lock; /**< Guards live_flows/nb_live. */
515 : : uint32_t nb_flows; /**< Max rules the table holds. */
516 : : uint32_t nb_live; /**< Live pattern rules count. */
517 : : uint32_t transfer; /**< Transfer (port) rule. */
518 : : uint8_t nb_pattern_templates; /**< pattern_templates entries. */
519 : : uint8_t nb_actions_templates; /**< actions_templates entries. */
520 : : bool hw_released; /**< Entries freed by a flush. */
521 : : };
522 : :
523 : : struct npc {
524 : : struct mbox *mbox; /* Mbox */
525 : : uint64_t keyx_supp_nmask[NPC_MAX_INTF]; /* nibble mask */
526 : : uint8_t hash_extract_cap; /* hash extract support */
527 : : uint8_t profile_name[MKEX_NAME_LEN]; /* KEX profile name */
528 : : bool is_sdp_link;
529 : : uint16_t channel; /* RX Channel number */
530 : : uint32_t keyx_len[NPC_MAX_INTF]; /* per intf key len in bits */
531 : : uint32_t datax_len[NPC_MAX_INTF]; /* per intf data len in bits */
532 : : uint32_t keyw[NPC_MAX_INTF]; /* max key + data len bits */
533 : : uint32_t mcam_entries; /* mcam entries supported */
534 : : uint16_t switch_header_type; /* Supported switch header type */
535 : : uint16_t flow_max_priority; /* Max priority for flow */
536 : : uint16_t sdp_channel;
537 : : uint16_t sdp_channel_mask;
538 : : uint32_t rss_grps; /* rss groups supported */
539 : : uint16_t flow_prealloc_size; /* Pre allocated mcam size */
540 : : uint8_t exact_match_ena;
541 : : uint16_t pf_func; /* pf_func of device */
542 : : uint32_t mark_actions;
543 : : uint32_t vtag_strip_actions; /* vtag insert/strip actions */
544 : : npc_dxcfg_t prx_dxcfg; /* intf, lid, lt, extract */
545 : : npc_dxcfg_cn20k_t prx_dxcfg_cn20k; /* intf, ext, lt, extract */
546 : : npc_lid_cn20k_t lid_cfg; /* KEX LD_Flags CFG */
547 : : npc_fxcfg_t prx_fxcfg; /* Flag extract */
548 : : npc_ld_flags_t prx_lfcfg; /* KEX LD_Flags CFG */
549 : : struct npc_flow_list *flow_list;
550 : : struct npc_prio_flow_list_head *prio_flow_list;
551 : : struct npc_age_flow_list_head age_flow_list;
552 : : struct plt_bitmap *rss_grp_entries;
553 : : struct npc_flow_list ipsec_list;
554 : : uint8_t enable_debug;
555 : : /* Queue-based async template flow state owned by roc. */
556 : : struct roc_npc_flow_queue *flow_queues;
557 : : uint16_t nb_flow_queues;
558 : : struct roc_npc_template_table *flow_tables;
559 : : };
560 : :
561 : : #define NPC_HASH_FIELD_LEN 16
562 : :
563 : : struct npc_hash_cfg {
564 : : uint64_t secret_key[3];
565 : : /* NPC_AF_INTF(0..1)_HASH(0..1)_MASK(0..1) */
566 : : uint64_t hash_mask[NPC_MAX_INTF][NPC_MAX_HASH][NPC_MAX_HASH_MASK];
567 : : /* NPC_AF_INTF(0..1)_HASH(0..1)_RESULT_CTRL */
568 : : uint64_t hash_ctrl[NPC_MAX_INTF][NPC_MAX_HASH];
569 : : };
570 : :
571 : : static inline struct npc *
572 : : roc_npc_to_npc_priv(struct roc_npc *npc)
573 : : {
574 [ # # # # : 0 : return (struct npc *)npc->reserved;
# # ]
575 : : }
576 : :
577 : : static inline bool
578 : : roc_npc_action_is_rx_inline(uint64_t npc_action)
579 : : {
580 : 0 : uint64_t op = npc_action & 0xFULL;
581 : :
582 [ # # # # : 0 : return (op == NIX_RX_ACTIONOP_UCAST_IPSEC || op == NIX_RX_ACTIONOP_UCAST_CPT);
# # # # ]
583 : : }
584 : :
585 : : int npc_mcam_get_stats(struct mbox *mbox, struct roc_npc_flow *flow, uint64_t *count);
586 : : int npc_mcam_alloc_counter(struct mbox *mbox, uint16_t *ctr);
587 : : int npc_mcam_free_counter(struct mbox *mbox, uint16_t ctr_id);
588 : : int npc_mcam_read_counter(struct mbox *mbox, uint32_t ctr_id, uint64_t *count);
589 : : int npc_mcam_clear_counter(struct mbox *mbox, uint32_t ctr_id);
590 : : int npc_mcam_free_entry(struct mbox *mbox, uint32_t entry);
591 : : int npc_mcam_free_all_entries(struct npc *npc);
592 : : int npc_mcam_alloc_and_write(struct npc *npc, struct roc_npc_flow *flow,
593 : : struct npc_parse_state *pst);
594 : : int npc_mcam_alloc_entry(struct npc *npc, struct roc_npc_flow *mcam, struct roc_npc_flow *ref_mcam,
595 : : uint8_t prio, int *resp_count);
596 : : int npc_mcam_alloc_entry_cn20k(struct npc *npc, struct roc_npc_flow *mcam, int *resp_count);
597 : :
598 : : int npc_mcam_alloc_entries(struct mbox *mbox, int ref_mcam, int *alloc_entry, int req_count,
599 : : int prio, int *resp_count, bool is_conti);
600 : :
601 : : int npc_mcam_ena_dis_entry(struct npc *npc, struct roc_npc_flow *mcam, bool enable);
602 : : int npc_mcam_write_entry(struct mbox *mbox, struct roc_npc_flow *mcam);
603 : : int npc_flow_enable_all_entries(struct npc *npc, bool enable);
604 : : int npc_update_parse_state(struct npc_parse_state *pst, struct npc_parse_item_info *info, int lid,
605 : : int lt, uint8_t flags);
606 : : void npc_get_hw_supp_mask(struct npc_parse_state *pst, struct npc_parse_item_info *info, int lid,
607 : : int lt);
608 : : uint8_t npc_get_key_type(struct npc *npc, struct roc_npc_flow *flow);
609 : : uint8_t npc_kex_key_type_config_get(struct npc *npc);
610 : : int npc_mask_is_supported(const char *mask, const char *hw_mask, int len);
611 : : int npc_parse_item_basic(const struct roc_npc_item_info *item, struct npc_parse_item_info *info);
612 : : int npc_parse_meta_items(struct npc_parse_state *pst);
613 : : int npc_parse_mark_item(struct npc_parse_state *pst);
614 : : int npc_parse_port_representor_id(struct npc_parse_state *pst);
615 : : int npc_parse_represented_port_id(struct npc_parse_state *pst);
616 : : int npc_parse_pre_l2(struct npc_parse_state *pst);
617 : : int npc_parse_higig2_hdr(struct npc_parse_state *pst);
618 : : int npc_parse_cpt_hdr(struct npc_parse_state *pst);
619 : : int npc_parse_tx_queue(struct npc_parse_state *pst);
620 : : int npc_parse_la(struct npc_parse_state *pst);
621 : : int npc_parse_lb(struct npc_parse_state *pst);
622 : : int npc_parse_lc(struct npc_parse_state *pst);
623 : : int npc_parse_ld(struct npc_parse_state *pst);
624 : : int npc_parse_le(struct npc_parse_state *pst);
625 : : int npc_parse_lf(struct npc_parse_state *pst);
626 : : int npc_parse_lg(struct npc_parse_state *pst);
627 : : int npc_parse_lh(struct npc_parse_state *pst);
628 : : int npc_mcam_fetch_kex_cfg(struct npc *npc);
629 : : int npc_mcam_fetch_hw_cap(struct npc *npc, uint8_t *npc_hw_cap);
630 : : int npc_get_free_mcam_entry(struct mbox *mbox, struct roc_npc_flow *flow, struct npc *npc);
631 : : void npc_delete_prio_list_entry(struct npc *npc, struct roc_npc_flow *flow);
632 : : int npc_flow_free_all_resources(struct npc *npc);
633 : : void npc_template_tables_flush_reconcile(struct npc *npc);
634 : : const struct roc_npc_item_info *
635 : : npc_parse_skip_void_and_any_items(const struct roc_npc_item_info *pattern);
636 : : int npc_program_mcam(struct npc *npc, struct npc_parse_state *pst, bool mcam_alloc);
637 : : uint64_t npc_get_kex_capability(struct npc *npc);
638 : : int npc_process_ipv6_field_hash(const struct roc_npc_flow_item_ipv6 *ipv6_spec,
639 : : const struct roc_npc_flow_item_ipv6 *ipv6_mask,
640 : : struct npc_parse_state *pst, uint8_t type);
641 : : int npc_rss_action_configure(struct roc_npc *roc_npc, const struct roc_npc_action_rss *rss,
642 : : uint8_t *alg_idx, uint32_t *rss_grp, uint32_t mcam_id,
643 : : uint16_t rss_repte_pf_func);
644 : : int npc_rss_action_program(struct roc_npc *roc_npc, const struct roc_npc_action actions[],
645 : : struct roc_npc_flow *flow);
646 : : int npc_rss_group_free(struct npc *npc, struct roc_npc_flow *flow);
647 : : int npc_mcam_init(struct npc *npc, struct roc_npc_flow *flow, int mcam_id);
648 : : int npc_mcam_move(struct mbox *mbox, uint16_t old_ent, uint16_t new_ent);
649 : : void npc_age_flow_list_entry_add(struct roc_npc *npc, struct roc_npc_flow *flow);
650 : : void npc_age_flow_list_entry_delete(struct roc_npc *npc, struct roc_npc_flow *flow);
651 : : uint32_t npc_aged_flows_get(void *args);
652 : : int npc_aged_flows_bitmap_alloc(struct roc_npc *roc_npc);
653 : : void npc_aged_flows_bitmap_free(struct roc_npc *roc_npc);
654 : : int npc_aging_ctrl_thread_create(struct roc_npc *roc_npc, const struct roc_npc_action_age *age,
655 : : struct roc_npc_flow *flow);
656 : : void npc_aging_ctrl_thread_destroy(struct roc_npc *roc_npc);
657 : : int npc_rss_free_grp_get(struct npc *npc, uint32_t *pos);
658 : :
659 : : #define SKIP_SIZE_PKIND_MEMZONE "roc_skip_size_pkind_cfg"
660 : :
661 : : struct skip_size_pkind_cfg {
662 : : uint8_t count;
663 : : struct {
664 : : uint8_t skip_size;
665 : : uint8_t pkind;
666 : : } entries[NPC_SKIP_SIZE_PKIND_MAX];
667 : : };
668 : :
669 : : #endif /* _ROC_NPC_PRIV_H_ */
|