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