dcf26c0a2d299d42ee71f7fad3e6991a0d51bfca
[dpdk.git] / drivers / common / cnxk / roc_npc_priv.h
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_COUNTER_NONE  (-1)
12
13 #define NPC_RSS_GRPS 8
14
15 #define NPC_ACTION_FLAG_DEFAULT 0xffff
16
17 #define NPC_PFVF_FUNC_MASK 0x3FF
18
19 /* 32 bytes from LDATA_CFG & 32 bytes from FLAGS_CFG */
20 #define NPC_MAX_EXTRACT_DATA_LEN (64)
21 #define NPC_MAX_EXTRACT_HW_LEN   (4 * NPC_MAX_EXTRACT_DATA_LEN)
22 #define NPC_LDATA_LFLAG_LEN      (16)
23 #define NPC_MAX_KEY_NIBBLES      (31)
24
25 /* Nibble offsets */
26 #define NPC_LAYER_KEYX_SZ         (3)
27 #define NPC_PARSE_KEX_S_LA_OFFSET (7)
28 #define NPC_PARSE_KEX_S_LID_OFFSET(lid)                                        \
29         ((((lid) - (NPC_LID_LA)) * NPC_LAYER_KEYX_SZ) +                        \
30          NPC_PARSE_KEX_S_LA_OFFSET)
31
32 /* This mark value indicates flag action */
33 #define NPC_FLOW_FLAG_VAL (0xffff)
34
35 #define NPC_RX_ACT_MATCH_OFFSET (40)
36 #define NPC_RX_ACT_MATCH_MASK   (0xFFFF)
37
38 #define NPC_RSS_ACT_GRP_OFFSET (20)
39 #define NPC_RSS_ACT_ALG_OFFSET (56)
40 #define NPC_RSS_ACT_GRP_MASK   (0xFFFFF)
41 #define NPC_RSS_ACT_ALG_MASK   (0x1F)
42
43 #define NPC_MCAM_KEX_FIELD_MAX    23
44 #define NPC_MCAM_MAX_PROTO_FIELDS (NPC_MCAM_KEX_FIELD_MAX + 1)
45 #define NPC_MCAM_KEY_X4_WORDS     7 /* Number of 64-bit words */
46
47 #define NPC_RVUPF_MAX_9XXX 0x10 /* HRM: RVU_PRIV_CONST */
48 #define NPC_RVUPF_MAX_10XX 0x20 /* HRM: RVU_PRIV_CONST */
49 #define NPC_NIXLF_MAX      0x80 /* HRM: NIX_AF_CONST2 */
50 #define NPC_MCAME_PER_PF   2    /* DRV: RSVD_MCAM_ENTRIES_PER_PF */
51 #define NPC_MCAME_PER_LF   1    /* DRV: RSVD_MCAM_ENTRIES_PER_NIXLF */
52 #define NPC_MCAME_RESVD_9XXX                                                   \
53         (NPC_NIXLF_MAX * NPC_MCAME_PER_LF +                                    \
54          (NPC_RVUPF_MAX_9XXX - 1) * NPC_MCAME_PER_PF)
55
56 #define NPC_MCAME_RESVD_10XX                                                   \
57         (NPC_NIXLF_MAX * NPC_MCAME_PER_LF +                                    \
58          (NPC_RVUPF_MAX_10XX - 1) * NPC_MCAME_PER_PF)
59
60 enum npc_err_status {
61         NPC_ERR_PARAM = -1024,
62         NPC_ERR_NO_MEM,
63         NPC_ERR_INVALID_SPEC,
64         NPC_ERR_INVALID_MASK,
65         NPC_ERR_INVALID_RANGE,
66         NPC_ERR_INVALID_KEX,
67         NPC_ERR_INVALID_SIZE,
68         NPC_ERR_INTERNAL,
69         NPC_ERR_MCAM_ALLOC,
70         NPC_ERR_ACTION_NOTSUP,
71         NPC_ERR_PATTERN_NOTSUP,
72 };
73
74 enum npc_mcam_intf { NPC_MCAM_RX, NPC_MCAM_TX };
75
76 typedef union npc_kex_cap_terms_t {
77         struct {
78                 /** Total length of received packet */
79                 uint64_t len : 1;
80                 /** Initial (outer) Ethertype only */
81                 uint64_t ethtype_0 : 1;
82                 /** Ethertype of most inner VLAN tag */
83                 uint64_t ethtype_x : 1;
84                 /** First VLAN ID (outer) */
85                 uint64_t vlan_id_0 : 1;
86                 /** Last VLAN ID (inner) */
87                 uint64_t vlan_id_x : 1;
88                 /** destination MAC address */
89                 uint64_t dmac : 1;
90                 /** IP Protocol or IPv6 Next Header */
91                 uint64_t ip_proto : 1;
92                 /** Destination UDP port, implies IPPROTO=17 */
93                 uint64_t udp_dport : 1;
94                 /** Destination TCP port implies IPPROTO=6 */
95                 uint64_t tcp_dport : 1;
96                 /** Source UDP Port */
97                 uint64_t udp_sport : 1;
98                 /** Source TCP port */
99                 uint64_t tcp_sport : 1;
100                 /** Source IP address */
101                 uint64_t sip_addr : 1;
102                 /** Destination IP address */
103                 uint64_t dip_addr : 1;
104                 /** Source IP address */
105                 uint64_t sip6_addr : 1;
106                 /** Destination IP address */
107                 uint64_t dip6_addr : 1;
108                 /** IPsec session identifier */
109                 uint64_t ipsec_spi : 1;
110                 /** NVGRE/VXLAN network identifier */
111                 uint64_t ld_vni : 1;
112                 /** Custom frame match rule. PMR offset is counted from
113                  *  the start of the packet.
114                  */
115                 uint64_t custom_frame : 1;
116                 /** Custom layer 3 match rule. PMR offset is counted from
117                  *  the start of layer 3 in the packet.
118                  */
119                 uint64_t custom_l3 : 1;
120                 /** IGMP Group address */
121                 uint64_t igmp_grp_addr : 1;
122                 /** ICMP identifier */
123                 uint64_t icmp_id : 1;
124                 /** ICMP type */
125                 uint64_t icmp_type : 1;
126                 /** ICMP code */
127                 uint64_t icmp_code : 1;
128                 /** Source SCTP port */
129                 uint64_t sctp_sport : 1;
130                 /** Destination SCTP port */
131                 uint64_t sctp_dport : 1;
132                 /** GTPU Tunnel endpoint identifier */
133                 uint64_t gtpu_teid : 1;
134
135         } bit;
136         /** All bits of the bit field structure */
137         uint64_t all_bits;
138 } npc_kex_cap_terms_t;
139
140 struct npc_parse_item_info {
141         const void *def_mask; /* default mask */
142         void *hw_mask;        /* hardware supported mask */
143         int len;              /* length of item */
144         const void *spec;     /* spec to use, NULL implies match any */
145         const void *mask;     /* mask to use */
146         uint8_t hw_hdr_len;   /* Extra data len at each layer*/
147 };
148
149 struct npc_parse_state {
150         struct npc *npc;
151         const struct roc_npc_item_info *pattern;
152         const struct roc_npc_item_info *last_pattern;
153         struct roc_npc_flow *flow;
154         uint8_t nix_intf;
155         uint8_t tunnel;
156         uint8_t terminate;
157         uint8_t layer_mask;
158         uint8_t lt[NPC_MAX_LID];
159         uint8_t flags[NPC_MAX_LID];
160         uint8_t *mcam_data; /* point to flow->mcam_data + key_len */
161         uint8_t *mcam_mask; /* point to flow->mcam_mask + key_len */
162         bool is_vf;
163 };
164
165 enum npc_kpu_parser_flag {
166         NPC_F_NA = 0,
167         NPC_F_PKI,
168         NPC_F_PKI_VLAN,
169         NPC_F_PKI_ETAG,
170         NPC_F_PKI_ITAG,
171         NPC_F_PKI_MPLS,
172         NPC_F_PKI_NSH,
173         NPC_F_ETYPE_UNK,
174         NPC_F_ETHER_VLAN,
175         NPC_F_ETHER_ETAG,
176         NPC_F_ETHER_ITAG,
177         NPC_F_ETHER_MPLS,
178         NPC_F_ETHER_NSH,
179         NPC_F_STAG_CTAG,
180         NPC_F_STAG_CTAG_UNK,
181         NPC_F_STAG_STAG_CTAG,
182         NPC_F_STAG_STAG_STAG,
183         NPC_F_QINQ_CTAG,
184         NPC_F_QINQ_CTAG_UNK,
185         NPC_F_QINQ_QINQ_CTAG,
186         NPC_F_QINQ_QINQ_QINQ,
187         NPC_F_BTAG_ITAG,
188         NPC_F_BTAG_ITAG_STAG,
189         NPC_F_BTAG_ITAG_CTAG,
190         NPC_F_BTAG_ITAG_UNK,
191         NPC_F_ETAG_CTAG,
192         NPC_F_ETAG_BTAG_ITAG,
193         NPC_F_ETAG_STAG,
194         NPC_F_ETAG_QINQ,
195         NPC_F_ETAG_ITAG,
196         NPC_F_ETAG_ITAG_STAG,
197         NPC_F_ETAG_ITAG_CTAG,
198         NPC_F_ETAG_ITAG_UNK,
199         NPC_F_ITAG_STAG_CTAG,
200         NPC_F_ITAG_STAG,
201         NPC_F_ITAG_CTAG,
202         NPC_F_MPLS_4_LABELS,
203         NPC_F_MPLS_3_LABELS,
204         NPC_F_MPLS_2_LABELS,
205         NPC_F_IP_HAS_OPTIONS,
206         NPC_F_IP_IP_IN_IP,
207         NPC_F_IP_6TO4,
208         NPC_F_IP_MPLS_IN_IP,
209         NPC_F_IP_UNK_PROTO,
210         NPC_F_IP_IP_IN_IP_HAS_OPTIONS,
211         NPC_F_IP_6TO4_HAS_OPTIONS,
212         NPC_F_IP_MPLS_IN_IP_HAS_OPTIONS,
213         NPC_F_IP_UNK_PROTO_HAS_OPTIONS,
214         NPC_F_IP6_HAS_EXT,
215         NPC_F_IP6_TUN_IP6,
216         NPC_F_IP6_MPLS_IN_IP,
217         NPC_F_TCP_HAS_OPTIONS,
218         NPC_F_TCP_HTTP,
219         NPC_F_TCP_HTTPS,
220         NPC_F_TCP_PPTP,
221         NPC_F_TCP_UNK_PORT,
222         NPC_F_TCP_HTTP_HAS_OPTIONS,
223         NPC_F_TCP_HTTPS_HAS_OPTIONS,
224         NPC_F_TCP_PPTP_HAS_OPTIONS,
225         NPC_F_TCP_UNK_PORT_HAS_OPTIONS,
226         NPC_F_UDP_VXLAN,
227         NPC_F_UDP_VXLAN_NOVNI,
228         NPC_F_UDP_VXLAN_NOVNI_NSH,
229         NPC_F_UDP_VXLANGPE,
230         NPC_F_UDP_VXLANGPE_NSH,
231         NPC_F_UDP_VXLANGPE_MPLS,
232         NPC_F_UDP_VXLANGPE_NOVNI,
233         NPC_F_UDP_VXLANGPE_NOVNI_NSH,
234         NPC_F_UDP_VXLANGPE_NOVNI_MPLS,
235         NPC_F_UDP_VXLANGPE_UNK,
236         NPC_F_UDP_VXLANGPE_NONP,
237         NPC_F_UDP_GTP_GTPC,
238         NPC_F_UDP_GTP_GTPU_G_PDU,
239         NPC_F_UDP_GTP_GTPU_UNK,
240         NPC_F_UDP_UNK_PORT,
241         NPC_F_UDP_GENEVE,
242         NPC_F_UDP_GENEVE_OAM,
243         NPC_F_UDP_GENEVE_CRI_OPT,
244         NPC_F_UDP_GENEVE_OAM_CRI_OPT,
245         NPC_F_GRE_NVGRE,
246         NPC_F_GRE_HAS_SRE,
247         NPC_F_GRE_HAS_CSUM,
248         NPC_F_GRE_HAS_KEY,
249         NPC_F_GRE_HAS_SEQ,
250         NPC_F_GRE_HAS_CSUM_KEY,
251         NPC_F_GRE_HAS_CSUM_SEQ,
252         NPC_F_GRE_HAS_KEY_SEQ,
253         NPC_F_GRE_HAS_CSUM_KEY_SEQ,
254         NPC_F_GRE_HAS_ROUTE,
255         NPC_F_GRE_UNK_PROTO,
256         NPC_F_GRE_VER1,
257         NPC_F_GRE_VER1_HAS_SEQ,
258         NPC_F_GRE_VER1_HAS_ACK,
259         NPC_F_GRE_VER1_HAS_SEQ_ACK,
260         NPC_F_GRE_VER1_UNK_PROTO,
261         NPC_F_TU_ETHER_UNK,
262         NPC_F_TU_ETHER_CTAG,
263         NPC_F_TU_ETHER_CTAG_UNK,
264         NPC_F_TU_ETHER_STAG_CTAG,
265         NPC_F_TU_ETHER_STAG_CTAG_UNK,
266         NPC_F_TU_ETHER_STAG,
267         NPC_F_TU_ETHER_STAG_UNK,
268         NPC_F_TU_ETHER_QINQ_CTAG,
269         NPC_F_TU_ETHER_QINQ_CTAG_UNK,
270         NPC_F_TU_ETHER_QINQ,
271         NPC_F_TU_ETHER_QINQ_UNK,
272         NPC_F_LAST /* has to be the last item */
273 };
274
275 #define NPC_ACTION_TERM                                                        \
276         (ROC_NPC_ACTION_TYPE_DROP | ROC_NPC_ACTION_TYPE_QUEUE |                \
277          ROC_NPC_ACTION_TYPE_RSS | ROC_NPC_ACTION_TYPE_DUP |                   \
278          ROC_NPC_ACTION_TYPE_SEC)
279
280 struct npc_xtract_info {
281         /* Length in bytes of pkt data extracted. len = 0
282          * indicates that extraction is disabled.
283          */
284         uint8_t len;
285         uint8_t hdr_off;      /* Byte offset of proto hdr: extract_src */
286         uint8_t key_off;      /* Byte offset in MCAM key where data is placed */
287         uint8_t enable;       /* Extraction enabled or disabled */
288         uint8_t flags_enable; /* Flags extraction enabled */
289 };
290
291 /* Information for a given {LAYER, LTYPE} */
292 struct npc_lid_lt_xtract_info {
293         /* Info derived from parser configuration */
294         uint16_t npc_proto;         /* Network protocol identified */
295         uint8_t valid_flags_mask;   /* Flags applicable */
296         uint8_t is_terminating : 1; /* No more parsing */
297         struct npc_xtract_info xtract[NPC_MAX_LD];
298 };
299
300 union npc_kex_ldata_flags_cfg {
301         struct {
302                 uint64_t lid : 3;
303                 uint64_t rvsd_62_1 : 61;
304         } s;
305
306         uint64_t i;
307 };
308
309 typedef struct npc_lid_lt_xtract_info npc_dxcfg_t[NPC_MAX_INTF][NPC_MAX_LID]
310                                                  [NPC_MAX_LT];
311 typedef struct npc_lid_lt_xtract_info npc_fxcfg_t[NPC_MAX_INTF][NPC_MAX_LD]
312                                                  [NPC_MAX_LFL];
313 typedef union npc_kex_ldata_flags_cfg npc_ld_flags_t[NPC_MAX_LD];
314
315 /* MBOX_MSG_NPC_GET_DATAX_CFG Response */
316 struct npc_get_datax_cfg {
317         /* NPC_AF_KEX_LDATA(0..1)_FLAGS_CFG */
318         union npc_kex_ldata_flags_cfg ld_flags[NPC_MAX_LD];
319         /* Extract information indexed with [LID][LTYPE] */
320         struct npc_lid_lt_xtract_info lid_lt_xtract[NPC_MAX_LID][NPC_MAX_LT];
321         /* Flags based extract indexed with [LDATA][FLAGS_LOWER_NIBBLE]
322          * Fields flags_ena_ld0, flags_ena_ld1 in
323          * struct npc_lid_lt_xtract_info indicate if this is applicable
324          * for a given {LAYER, LTYPE}
325          */
326         struct npc_xtract_info flag_xtract[NPC_MAX_LD][NPC_MAX_LT];
327 };
328
329 TAILQ_HEAD(npc_flow_list, roc_npc_flow);
330
331 struct npc_mcam_ents_info {
332         /* Current max & min values of mcam index */
333         uint32_t max_id;
334         uint32_t min_id;
335         uint32_t free_ent;
336         uint32_t live_ent;
337 };
338
339 struct npc {
340         struct mbox *mbox;                      /* Mbox */
341         uint32_t keyx_supp_nmask[NPC_MAX_INTF]; /* nibble mask */
342         uint8_t profile_name[MKEX_NAME_LEN];    /* KEX profile name */
343         uint32_t keyx_len[NPC_MAX_INTF];        /* per intf key len in bits */
344         uint32_t datax_len[NPC_MAX_INTF];       /* per intf data len in bits */
345         uint32_t keyw[NPC_MAX_INTF];            /* max key + data len bits */
346         uint32_t mcam_entries;                  /* mcam entries supported */
347         uint16_t channel;                       /* RX Channel number */
348         uint32_t rss_grps;                      /* rss groups supported */
349         uint16_t flow_prealloc_size;            /* Pre allocated mcam size */
350         uint16_t flow_max_priority;             /* Max priority for flow */
351         uint16_t switch_header_type; /* Suppprted switch header type */
352         uint32_t mark_actions;       /* Number of mark actions */
353         uint16_t pf_func;            /* pf_func of device */
354         npc_dxcfg_t prx_dxcfg;       /* intf, lid, lt, extract */
355         npc_fxcfg_t prx_fxcfg;       /* Flag extract */
356         npc_ld_flags_t prx_lfcfg;    /* KEX LD_Flags CFG */
357         /* mcam entry info per priority level: both free & in-use */
358         struct npc_mcam_ents_info *flow_entry_info;
359         /* Bitmap of free preallocated entries in ascending index &
360          * descending priority
361          */
362         struct plt_bitmap **free_entries;
363         /* Bitmap of free preallocated entries in descending index &
364          * ascending priority
365          */
366         struct plt_bitmap **free_entries_rev;
367         /* Bitmap of live entries in ascending index & descending priority */
368         struct plt_bitmap **live_entries;
369         /* Bitmap of live entries in descending index & ascending priority */
370         struct plt_bitmap **live_entries_rev;
371         /* Priority bucket wise tail queue of all npc_flow resources */
372         struct npc_flow_list *flow_list;
373         struct plt_bitmap *rss_grp_entries;
374 };
375
376 static inline struct npc *
377 roc_npc_to_npc_priv(struct roc_npc *npc)
378 {
379         return (struct npc *)npc->reserved;
380 }
381
382 int npc_mcam_free_counter(struct npc *npc, uint16_t ctr_id);
383 int npc_mcam_read_counter(struct npc *npc, uint32_t ctr_id, uint64_t *count);
384 int npc_mcam_clear_counter(struct npc *npc, uint32_t ctr_id);
385 int npc_mcam_free_entry(struct npc *npc, uint32_t entry);
386 int npc_mcam_free_all_entries(struct npc *npc);
387 int npc_mcam_alloc_and_write(struct npc *npc, struct roc_npc_flow *flow,
388                              struct npc_parse_state *pst);
389 int npc_mcam_alloc_entry(struct npc *npc, struct roc_npc_flow *mcam,
390                          struct roc_npc_flow *ref_mcam, int prio,
391                          int *resp_count);
392 int npc_mcam_alloc_entries(struct npc *npc, int ref_mcam, int *alloc_entry,
393                            int req_count, int prio, int *resp_count);
394
395 int npc_mcam_ena_dis_entry(struct npc *npc, struct roc_npc_flow *mcam,
396                            bool enable);
397 int npc_mcam_write_entry(struct npc *npc, struct roc_npc_flow *mcam);
398 int npc_update_parse_state(struct npc_parse_state *pst,
399                            struct npc_parse_item_info *info, int lid, int lt,
400                            uint8_t flags);
401 void npc_get_hw_supp_mask(struct npc_parse_state *pst,
402                           struct npc_parse_item_info *info, int lid, int lt);
403 int npc_parse_item_basic(const struct roc_npc_item_info *item,
404                          struct npc_parse_item_info *info);
405 int npc_parse_meta_items(struct npc_parse_state *pst);
406 int npc_parse_higig2_hdr(struct npc_parse_state *pst);
407 int npc_parse_cpt_hdr(struct npc_parse_state *pst);
408 int npc_parse_la(struct npc_parse_state *pst);
409 int npc_parse_lb(struct npc_parse_state *pst);
410 int npc_parse_lc(struct npc_parse_state *pst);
411 int npc_parse_ld(struct npc_parse_state *pst);
412 int npc_parse_le(struct npc_parse_state *pst);
413 int npc_parse_lf(struct npc_parse_state *pst);
414 int npc_parse_lg(struct npc_parse_state *pst);
415 int npc_parse_lh(struct npc_parse_state *pst);
416 int npc_mcam_fetch_kex_cfg(struct npc *npc);
417 int npc_check_preallocated_entry_cache(struct mbox *mbox,
418                                        struct roc_npc_flow *flow,
419                                        struct npc *npc);
420 int npc_flow_free_all_resources(struct npc *npc);
421 const struct roc_npc_item_info *
422 npc_parse_skip_void_and_any_items(const struct roc_npc_item_info *pattern);
423 int npc_program_mcam(struct npc *npc, struct npc_parse_state *pst,
424                      bool mcam_alloc);
425 uint64_t npc_get_kex_capability(struct npc *npc);
426 #endif /* _ROC_NPC_PRIV_H_ */