net/bnxt: add CFA subdirectory of HCAPI
[dpdk.git] / drivers / net / bnxt / hcapi / cfa / hcapi_cfa_p4.h
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2014-2021 Broadcom
3  * All rights reserved.
4  */
5
6 #ifndef _HCAPI_CFA_P4_H_
7 #define _HCAPI_CFA_P4_H_
8
9 /** CFA phase 4 fix formatted table(layout) ID definition
10  *
11  */
12 enum cfa_p4_tbl_id {
13         CFA_P4_TBL_L2CTXT_TCAM = 0,
14         CFA_P4_TBL_L2CTXT_REMAP,
15         CFA_P4_TBL_PROF_TCAM,
16         CFA_P4_TBL_PROF_TCAM_REMAP,
17         CFA_P4_TBL_WC_TCAM,
18         CFA_P4_TBL_WC_TCAM_REC,
19         CFA_P4_TBL_WC_TCAM_REMAP,
20         CFA_P4_TBL_VEB_TCAM,
21         CFA_P4_TBL_SP_TCAM,
22         CFA_P4_TBL_PROF_SPIF_DFLT_L2CTXT,
23         CFA_P4_TBL_PROF_PARIF_DFLT_ACT_REC_PTR,
24         CFA_P4_TBL_PROF_PARIF_ERR_ACT_REC_PTR,
25         CFA_P4_TBL_LKUP_PARIF_DFLT_ACT_REC_PTR,
26         CFA_P4_TBL_MAX
27 };
28
29 #define CFA_P4_PROF_MAX_KEYS 4
30 enum cfa_p4_mac_sel_mode {
31         CFA_P4_MAC_SEL_MODE_FIRST = 0,
32         CFA_P4_MAC_SEL_MODE_LOWEST = 1,
33 };
34
35 struct cfa_p4_prof_key_cfg {
36         uint8_t mac_sel[CFA_P4_PROF_MAX_KEYS];
37 #define CFA_P4_PROF_MAC_SEL_DMAC0 (1 << 0)
38 #define CFA_P4_PROF_MAC_SEL_T_MAC0 (1 << 1)
39 #define CFA_P4_PROF_MAC_SEL_OUTERMOST_MAC0 (1 << 2)
40 #define CFA_P4_PROF_MAC_SEL_DMAC1 (1 << 3)
41 #define CFA_P4_PROF_MAC_SEL_T_MAC1 (1 << 4)
42 #define CFA_P4_PROF_MAC_OUTERMOST_MAC1 (1 << 5)
43         uint8_t pass_cnt;
44         enum cfa_p4_mac_sel_mode mode;
45 };
46
47 /**
48  * CFA action layout definition
49  */
50
51 #define CFA_P4_ACTION_MAX_LAYOUT_SIZE 184
52
53 /**
54  * Action object template structure
55  *
56  * Template structure presents data fields that are necessary to know
57  * at the beginning of Action Builder (AB) processing. Like before the
58  * AB compilation. One such example could be a template that is
59  * flexible in size (Encap Record) and the presence of these fields
60  * allows for determining the template size as well as where the
61  * fields are located in the record.
62  *
63  * The template may also present fields that are not made visible to
64  * the caller by way of the action fields.
65  *
66  * Template fields also allow for additional checking on user visible
67  * fields. One such example could be the encap pointer behavior on a
68  * CFA_P4_ACT_OBJ_TYPE_ACT or CFA_P4_ACT_OBJ_TYPE_ACT_SRAM.
69  */
70 struct cfa_p4_action_template {
71         /** Action Object type
72          *
73          * Controls the type of the Action Template
74          */
75         enum {
76                 /** Select this type to build an Action Record Object
77                  */
78                 CFA_P4_ACT_OBJ_TYPE_ACT,
79                 /** Select this type to build an Action Statistics
80                  * Object
81                  */
82                 CFA_P4_ACT_OBJ_TYPE_STAT,
83                 /** Select this type to build a SRAM Action Record
84                  * Object.
85                  */
86                 CFA_P4_ACT_OBJ_TYPE_ACT_SRAM,
87                 /** Select this type to build a SRAM Action
88                  * Encapsulation Object.
89                  */
90                 CFA_P4_ACT_OBJ_TYPE_ENCAP_SRAM,
91                 /** Select this type to build a SRAM Action Modify
92                  * Object, with IPv4 capability.
93                  */
94                 /* In case of Stingray the term Modify is used for the 'NAT
95                  * action'. Action builder is leveraged to fill in the NAT
96                  * object which then can be referenced by the action
97                  * record.
98                  */
99                 CFA_P4_ACT_OBJ_TYPE_MODIFY_IPV4_SRAM,
100                 /** Select this type to build a SRAM Action Source
101                  * Property Object.
102                  */
103                 /* In case of Stingray this is not a 'pure' action record.
104                  * Action builder is leveraged to full in the Source Property
105                  * object which can then be referenced by the action
106                  * record.
107                  */
108                 CFA_P4_ACT_OBJ_TYPE_SRC_PROP_SRAM,
109                 /** Select this type to build a SRAM Action Statistics
110                  * Object
111                  */
112                 CFA_P4_ACT_OBJ_TYPE_STAT_SRAM,
113         } obj_type;
114
115         /** Action Control
116          *
117          * Controls the internals of the Action Template
118          *
119          * act is valid when:
120          * (obj_type == CFA_P4_ACT_OBJ_TYPE_ACT)
121          */
122         /*
123          * Stat and encap are always inline for EEM as table scope
124          * allocation does not allow for separate Stats allocation,
125          * but has the xx_inline flags as to be forward compatible
126          * with Stingray 2, always treated as TRUE.
127          */
128         struct {
129                 /** Set to CFA_HCAPI_TRUE to enable statistics
130                  */
131                 uint8_t stat_enable;
132                 /** Set to CFA_HCAPI_TRUE to enable statistics to be inlined
133                  */
134                 uint8_t stat_inline;
135
136                 /** Set to CFA_HCAPI_TRUE to enable encapsulation
137                  */
138                 uint8_t encap_enable;
139                 /** Set to CFA_HCAPI_TRUE to enable encapsulation to be inlined
140                  */
141                 uint8_t encap_inline;
142         } act;
143
144         /** Modify Setting
145          *
146          * Controls the type of the Modify Action the template is
147          * describing
148          *
149          * modify is valid when:
150          * (obj_type == CFA_P4_ACT_OBJ_TYPE_MODIFY_SRAM)
151          */
152         enum {
153                 /** Set to enable Modify of Source IPv4 Address
154                  */
155                 CFA_P4_MR_REPLACE_SOURCE_IPV4 = 0,
156                 /** Set to enable Modify of Destination IPv4 Address
157                  */
158                 CFA_P4_MR_REPLACE_DEST_IPV4
159         } modify;
160
161         /** Encap Control
162          * Controls the type of encapsulation the template is
163          * describing
164          *
165          * encap is valid when:
166          * ((obj_type == CFA_P4_ACT_OBJ_TYPE_ACT) &&
167          *   act.encap_enable) ||
168          * ((obj_type == CFA_P4_ACT_OBJ_TYPE_SRC_PROP_SRAM)
169          */
170         struct {
171                 /* Direction is required as Stingray Encap on RX is
172                  * limited to l2 and VTAG only.
173                  */
174                 /** Receive or Transmit direction
175                  */
176                 uint8_t direction;
177                 /** Set to CFA_HCAPI_TRUE to enable L2 capability in the
178                  *  template
179                  */
180                 uint8_t l2_enable;
181                 /** vtag controls the Encap Vector - VTAG Encoding, 4 bits
182                  *
183                  * <ul>
184                  * <li> CFA_P4_ACT_ENCAP_VTAGS_PUSH_0, default, no VLAN
185                  *      Tags applied
186                  * <li> CFA_P4_ACT_ENCAP_VTAGS_PUSH_1, adds capability to
187                  *      set 1 VLAN Tag. Action Template compile adds
188                  *      the following field to the action object
189                  *      ::TF_ER_VLAN1
190                  * <li> CFA_P4_ACT_ENCAP_VTAGS_PUSH_2, adds capability to
191                  *      set 2 VLAN Tags. Action Template compile adds
192                  *      the following fields to the action object
193                  *      ::TF_ER_VLAN1 and ::TF_ER_VLAN2
194                  * </ul>
195                  */
196                 enum { CFA_P4_ACT_ENCAP_VTAGS_PUSH_0 = 0,
197                        CFA_P4_ACT_ENCAP_VTAGS_PUSH_1,
198                        CFA_P4_ACT_ENCAP_VTAGS_PUSH_2 } vtag;
199
200                 /*
201                  * The remaining fields are NOT supported when
202                  * direction is RX and ((obj_type ==
203                  * CFA_P4_ACT_OBJ_TYPE_ACT) && act.encap_enable).
204                  * ab_compile_layout will perform the checking and
205                  * skip remaining fields.
206                  */
207                 /** L3 Encap controls the Encap Vector - L3 Encoding,
208                  *  3 bits. Defines the type of L3 Encapsulation the
209                  *  template is describing.
210                  * <ul>
211                  * <li> CFA_P4_ACT_ENCAP_L3_NONE, default, no L3
212                  *      Encapsulation processing.
213                  * <li> CFA_P4_ACT_ENCAP_L3_IPV4, enables L3 IPv4
214                  *      Encapsulation.
215                  * <li> CFA_P4_ACT_ENCAP_L3_IPV6, enables L3 IPv6
216                  *      Encapsulation.
217                  * <li> CFA_P4_ACT_ENCAP_L3_MPLS_8847, enables L3 MPLS
218                  *      8847 Encapsulation.
219                  * <li> CFA_P4_ACT_ENCAP_L3_MPLS_8848, enables L3 MPLS
220                  *      8848 Encapsulation.
221                  * </ul>
222                  */
223                 enum {
224                         /** Set to disable any L3 encapsulation
225                          * processing, default
226                          */
227                         CFA_P4_ACT_ENCAP_L3_NONE = 0,
228                         /** Set to enable L3 IPv4 encapsulation
229                          */
230                         CFA_P4_ACT_ENCAP_L3_IPV4 = 4,
231                         /** Set to enable L3 IPv6 encapsulation
232                          */
233                         CFA_P4_ACT_ENCAP_L3_IPV6 = 5,
234                         /** Set to enable L3 MPLS 8847 encapsulation
235                          */
236                         CFA_P4_ACT_ENCAP_L3_MPLS_8847 = 6,
237                         /** Set to enable L3 MPLS 8848 encapsulation
238                          */
239                         CFA_P4_ACT_ENCAP_L3_MPLS_8848 = 7
240                 } l3;
241
242 #define CFA_P4_ACT_ENCAP_MAX_MPLS_LABELS 8
243                 /** 1-8 labels, valid when
244                  * (l3 == CFA_P4_ACT_ENCAP_L3_MPLS_8847) ||
245                  * (l3 == CFA_P4_ACT_ENCAP_L3_MPLS_8848)
246                  *
247                  * MAX number of MPLS Labels 8.
248                  */
249                 uint8_t l3_num_mpls_labels;
250
251                 /** Set to CFA_HCAPI_TRUE to enable L4 capability in the
252                  * template.
253                  *
254                  * CFA_HCAPI_TRUE adds ::TF_EN_UDP_SRC_PORT and
255                  * ::TF_EN_UDP_DST_PORT to the template.
256                  */
257                 uint8_t l4_enable;
258
259                 /** Tunnel Encap controls the Encap Vector - Tunnel
260                  *  Encap, 3 bits. Defines the type of Tunnel
261                  *  encapsulation the template is describing
262                  * <ul>
263                  * <li> CFA_P4_ACT_ENCAP_TNL_NONE, default, no Tunnel
264                  *      Encapsulation processing.
265                  * <li> CFA_P4_ACT_ENCAP_TNL_GENERIC_FULL
266                  * <li> CFA_P4_ACT_ENCAP_TNL_VXLAN. NOTE: Expects
267                  *      l4_enable set to CFA_P4_TRUE;
268                  * <li> CFA_P4_ACT_ENCAP_TNL_NGE. NOTE: Expects l4_enable
269                  *      set to CFA_P4_TRUE;
270                  * <li> CFA_P4_ACT_ENCAP_TNL_NVGRE. NOTE: only valid if
271                  *      l4_enable set to CFA_HCAPI_FALSE.
272                  * <li> CFA_P4_ACT_ENCAP_TNL_GRE.NOTE: only valid if
273                  *      l4_enable set to CFA_HCAPI_FALSE.
274                  * <li> CFA_P4_ACT_ENCAP_TNL_GENERIC_AFTER_TL4
275                  * <li> CFA_P4_ACT_ENCAP_TNL_GENERIC_AFTER_TNL
276                  * </ul>
277                  */
278                 enum {
279                         /** Set to disable Tunnel header encapsulation
280                          * processing, default
281                          */
282                         CFA_P4_ACT_ENCAP_TNL_NONE = 0,
283                         /** Set to enable Tunnel Generic Full header
284                          * encapsulation
285                          */
286                         CFA_P4_ACT_ENCAP_TNL_GENERIC_FULL,
287                         /** Set to enable VXLAN header encapsulation
288                          */
289                         CFA_P4_ACT_ENCAP_TNL_VXLAN,
290                         /** Set to enable NGE (VXLAN2) header encapsulation
291                          */
292                         CFA_P4_ACT_ENCAP_TNL_NGE,
293                         /** Set to enable NVGRE header encapsulation
294                          */
295                         CFA_P4_ACT_ENCAP_TNL_NVGRE,
296                         /** Set to enable GRE header encapsulation
297                          */
298                         CFA_P4_ACT_ENCAP_TNL_GRE,
299                         /** Set to enable Generic header after Tunnel
300                          * L4 encapsulation
301                          */
302                         CFA_P4_ACT_ENCAP_TNL_GENERIC_AFTER_TL4,
303                         /** Set to enable Generic header after Tunnel
304                          * encapsulation
305                          */
306                         CFA_P4_ACT_ENCAP_TNL_GENERIC_AFTER_TNL
307                 } tnl;
308
309                 /** Number of bytes of generic tunnel header,
310                  * valid when
311                  * (tnl == CFA_P4_ACT_ENCAP_TNL_GENERIC_FULL) ||
312                  * (tnl == CFA_P4_ACT_ENCAP_TNL_GENERIC_AFTER_TL4) ||
313                  * (tnl == CFA_P4_ACT_ENCAP_TNL_GENERIC_AFTER_TNL)
314                  */
315                 uint8_t tnl_generic_size;
316                 /** Number of 32b words of nge options,
317                  * valid when
318                  * (tnl == CFA_P4_ACT_ENCAP_TNL_NGE)
319                  */
320                 uint8_t tnl_nge_op_len;
321                 /* Currently not planned */
322                 /* Custom Header */
323                 /*      uint8_t custom_enable; */
324         } encap;
325 };
326
327 /**
328  * Enumeration of SRAM entry types, used for allocation of
329  * fixed SRAM entities. The memory model for CFA HCAPI
330  * determines if an SRAM entry type is supported.
331  */
332 enum cfa_p4_action_sram_entry_type {
333         /* NOTE: Any additions to this enum must be reflected on FW
334          * side as well.
335          */
336
337         /** SRAM Action Record */
338         CFA_P4_ACTION_SRAM_ENTRY_TYPE_FULL_ACTION,
339
340         CFA_P4_ACTION_SRAM_ENTRY_TYPE_FORMAT_0_ACTION,
341         CFA_P4_ACTION_SRAM_ENTRY_TYPE_FORMAT_1_ACTION,
342         CFA_P4_ACTION_SRAM_ENTRY_TYPE_FORMAT_2_ACTION,
343         CFA_P4_ACTION_SRAM_ENTRY_TYPE_FORMAT_3_ACTION,
344         CFA_P4_ACTION_SRAM_ENTRY_TYPE_FORMAT_4_ACTION,
345
346         /** SRAM Action Encap 8 Bytes */
347         CFA_P4_ACTION_SRAM_ENTRY_TYPE_ENCAP_8B,
348         /** SRAM Action Encap 16 Bytes */
349         CFA_P4_ACTION_SRAM_ENTRY_TYPE_ENCAP_16B,
350         /** SRAM Action Encap 64 Bytes */
351         CFA_P4_ACTION_SRAM_ENTRY_TYPE_ENCAP_64B,
352
353         CFA_P4_ACTION_SRAM_ENTRY_TYPE_MODIFY_PORT_SRC,
354         CFA_P4_ACTION_SRAM_ENTRY_TYPE_MODIFY_PORT_DEST,
355
356         /** SRAM Action Modify IPv4 Source */
357         CFA_P4_ACTION_SRAM_ENTRY_TYPE_MODIFY_IPV4_SRC,
358         /** SRAM Action Modify IPv4 Destination */
359         CFA_P4_ACTION_SRAM_ENTRY_TYPE_MODIFY_IPV4_DEST,
360
361         /** SRAM Action Source Properties SMAC */
362         CFA_P4_ACTION_SRAM_ENTRY_TYPE_SP_SMAC,
363         /** SRAM Action Source Properties SMAC IPv4 */
364         CFA_P4_ACTION_SRAM_ENTRY_TYPE_SP_SMAC_IPV4,
365         /** SRAM Action Source Properties SMAC IPv6 */
366         CFA_P4_ACTION_SRAM_ENTRY_TYPE_SP_SMAC_IPV6,
367         /** SRAM Action Statistics 64 Bits */
368         CFA_P4_ACTION_SRAM_ENTRY_TYPE_STATS_64,
369         CFA_P4_ACTION_SRAM_ENTRY_TYPE_MAX
370 };
371
372 /**
373  * SRAM Action Record structure holding either an action index or an
374  * action ptr.
375  */
376 union cfa_p4_action_sram_act_record {
377         /** SRAM Action idx specifies the offset of the SRAM
378          * element within its SRAM Entry Type block. This
379          * index can be written into i.e. an L2 Context. Use
380          * this type for all SRAM Action Record types except
381          * SRAM Full Action records. Use act_ptr instead.
382          */
383         uint16_t act_idx;
384         /** SRAM Full Action is special in that it needs an
385          * action record pointer. This pointer can be written
386          * into i.e. a Wildcard TCAM entry.
387          */
388         uint32_t act_ptr;
389 };
390
391 /**
392  * cfa_p4_action_param parameter definition
393  */
394 struct cfa_p4_action_param {
395         /**
396          * [in] receive or transmit direction
397          */
398         uint8_t dir;
399         /**
400          * [in] type of the sram allocation type
401          */
402         enum cfa_p4_action_sram_entry_type type;
403         /**
404          * [in] action record to set. The 'type' specified lists the
405          *      record definition to use in the passed in record.
406          */
407         union cfa_p4_action_sram_act_record record;
408         /**
409          * [in] number of elements in act_data
410          */
411         uint32_t act_size;
412         /**
413          * [in] ptr to array of action data
414          */
415         uint64_t *act_data;
416 };
417
418 /**
419  * EEM Key entry sizes
420  */
421 #define CFA_P4_EEM_KEY_MAX_SIZE 52
422 #define CFA_P4_EEM_KEY_RECORD_SIZE 64
423
424 /**
425  * cfa_eem_entry_hdr
426  */
427 struct cfa_p4_eem_entry_hdr {
428         uint32_t pointer;
429         uint32_t word1;  /*
430                           * The header is made up of two words,
431                           * this is the first word. This field has multiple
432                           * subfields, there is no suitable single name for
433                           * it so just going with word1.
434                           */
435 #define CFA_P4_EEM_ENTRY_VALID_SHIFT 31
436 #define CFA_P4_EEM_ENTRY_VALID_MASK 0x80000000
437 #define CFA_P4_EEM_ENTRY_L1_CACHEABLE_SHIFT 30
438 #define CFA_P4_EEM_ENTRY_L1_CACHEABLE_MASK 0x40000000
439 #define CFA_P4_EEM_ENTRY_STRENGTH_SHIFT 28
440 #define CFA_P4_EEM_ENTRY_STRENGTH_MASK 0x30000000
441 #define CFA_P4_EEM_ENTRY_RESERVED_SHIFT 17
442 #define CFA_P4_EEM_ENTRY_RESERVED_MASK 0x0FFE0000
443 #define CFA_P4_EEM_ENTRY_KEY_SIZE_SHIFT 8
444 #define CFA_P4_EEM_ENTRY_KEY_SIZE_MASK 0x0001FF00
445 #define CFA_P4_EEM_ENTRY_ACT_REC_SIZE_SHIFT 3
446 #define CFA_P4_EEM_ENTRY_ACT_REC_SIZE_MASK 0x000000F8
447 #define CFA_P4_EEM_ENTRY_ACT_REC_INT_SHIFT 2
448 #define CFA_P4_EEM_ENTRY_ACT_REC_INT_MASK 0x00000004
449 #define CFA_P4_EEM_ENTRY_EXT_FLOW_CTR_SHIFT 1
450 #define CFA_P4_EEM_ENTRY_EXT_FLOW_CTR_MASK 0x00000002
451 #define CFA_P4_EEM_ENTRY_ACT_PTR_MSB_SHIFT 0
452 #define CFA_P4_EEM_ENTRY_ACT_PTR_MSB_MASK 0x00000001
453 };
454
455 /**
456  *  cfa_p4_eem_key_entry
457  */
458 struct cfa_p4_eem_64b_entry {
459         /** Key is 448 bits - 56 bytes */
460         uint8_t key[CFA_P4_EEM_KEY_RECORD_SIZE - sizeof(struct cfa_p4_eem_entry_hdr)];
461         /** Header is 8 bytes long */
462         struct cfa_p4_eem_entry_hdr hdr;
463 };
464
465 #endif /* _CFA_HW_P4_H_ */