net/bnxt: add TruFlow core identifier
[dpdk.git] / drivers / net / bnxt / tf_core / tf_core.h
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2019-2020 Broadcom
3  * All rights reserved.
4  */
5
6 #ifndef _TF_CORE_H_
7 #define _TF_CORE_H_
8
9 #include <stdint.h>
10 #include <stdlib.h>
11 #include <stdbool.h>
12 #include <stdio.h>
13
14 #include "tf_project.h"
15
16 /**
17  * @file
18  *
19  * Truflow Core API Header File
20  */
21
22 /********** BEGIN Truflow Core DEFINITIONS **********/
23
24 /**
25  * direction
26  */
27 enum tf_dir {
28         TF_DIR_RX,  /**< Receive */
29         TF_DIR_TX,  /**< Transmit */
30         TF_DIR_MAX
31 };
32
33 /**
34  * External pool size
35  *
36  * Defines a single pool of external action records of
37  * fixed size.  Currently, this is an index.
38  */
39 #define TF_EXT_POOL_ENTRY_SZ_BYTES 1
40
41 /**
42  *  External pool entry count
43  *
44  *  Defines the number of entries in the external action pool
45  */
46 #define TF_EXT_POOL_ENTRY_CNT (1 * 1024)
47
48 /**
49  * Number of external pools
50  */
51 #define TF_EXT_POOL_CNT_MAX 1
52
53 /**
54  * External pool Id
55  */
56 #define TF_EXT_POOL_0      0 /**< matches TF_TBL_TYPE_EXT   */
57 #define TF_EXT_POOL_1      1 /**< matches TF_TBL_TYPE_EXT_0 */
58
59 /********** BEGIN API FUNCTION PROTOTYPES/PARAMETERS **********/
60
61 /**
62  * @page general General
63  *
64  * @ref tf_open_session
65  *
66  * @ref tf_attach_session
67  *
68  * @ref tf_close_session
69  */
70
71
72 /** Session Version defines
73  *
74  * The version controls the format of the tf_session and
75  * tf_session_info structure. This is to assure upgrade between
76  * versions can be supported.
77  */
78 #define TF_SESSION_VER_MAJOR  1   /**< Major Version */
79 #define TF_SESSION_VER_MINOR  0   /**< Minor Version */
80 #define TF_SESSION_VER_UPDATE 0   /**< Update Version */
81
82 /** Session Name
83  *
84  * Name of the TruFlow control channel interface.  Expects
85  * format to be RTE Name specific, i.e. rte_eth_dev_get_name_by_port()
86  */
87 #define TF_SESSION_NAME_MAX       64
88
89 #define TF_FW_SESSION_ID_INVALID  0xFF  /**< Invalid FW Session ID define */
90
91 /** Session Identifier
92  *
93  * Unique session identifier which includes PCIe bus info to
94  * distinguish the PF and session info to identify the associated
95  * TruFlow session. Session ID is constructed from the passed in
96  * ctrl_chan_name in tf_open_session() together with an allocated
97  * fw_session_id. Done by TruFlow on tf_open_session().
98  */
99 union tf_session_id {
100         uint32_t id;
101         struct {
102                 uint8_t domain;
103                 uint8_t bus;
104                 uint8_t device;
105                 uint8_t fw_session_id;
106         } internal;
107 };
108
109 /** Session Version
110  *
111  * The version controls the format of the tf_session and
112  * tf_session_info structure. This is to assure upgrade between
113  * versions can be supported.
114  *
115  * Please see the TF_VER_MAJOR/MINOR and UPDATE defines.
116  */
117 struct tf_session_version {
118         uint8_t major;
119         uint8_t minor;
120         uint8_t update;
121 };
122
123 /** Session supported device types
124  *
125  */
126 enum tf_device_type {
127         TF_DEVICE_TYPE_WH = 0, /**< Whitney+  */
128         TF_DEVICE_TYPE_BRD2,   /**< TBD       */
129         TF_DEVICE_TYPE_BRD3,   /**< TBD       */
130         TF_DEVICE_TYPE_BRD4,   /**< TBD       */
131         TF_DEVICE_TYPE_MAX     /**< Maximum   */
132 };
133
134 /** TruFlow Session Information
135  *
136  * Structure defining a TruFlow Session, also known as a Management
137  * session. This structure is initialized at time of
138  * tf_open_session(). It is passed to all of the TruFlow APIs as way
139  * to prescribe and isolate resources between different TruFlow ULP
140  * Applications.
141  */
142 struct tf_session_info {
143         /**
144          * TrueFlow Version. Used to control the structure layout when
145          * sharing sessions. No guarantee that a secondary process
146          * would come from the same version of an executable.
147          * TruFlow initializes this variable on tf_open_session().
148          *
149          * Owner:  TruFlow
150          * Access: TruFlow
151          */
152         struct tf_session_version ver;
153         /**
154          * will be STAILQ_ENTRY(tf_session_info) next
155          *
156          * Owner:  ULP
157          * Access: ULP
158          */
159         void                 *next;
160         /**
161          * Session ID is a unique identifier for the session. TruFlow
162          * initializes this variable during tf_open_session()
163          * processing.
164          *
165          * Owner:  TruFlow
166          * Access: Truflow & ULP
167          */
168         union tf_session_id   session_id;
169         /**
170          * Protects access to core_data. Lock is initialized and owned
171          * by ULP. TruFlow can access the core_data without checking
172          * the lock.
173          *
174          * Owner:  ULP
175          * Access: ULP
176          */
177         uint8_t               spin_lock;
178         /**
179          * The core_data holds the TruFlow tf_session data
180          * structure. This memory is allocated and owned by TruFlow on
181          * tf_open_session().
182          *
183          * TruFlow uses this memory for session management control
184          * until the session is closed by ULP. Access control is done
185          * by the spin_lock which ULP controls ahead of TruFlow API
186          * calls.
187          *
188          * Please see tf_open_session_parms for specification details
189          * on this variable.
190          *
191          * Owner:  TruFlow
192          * Access: TruFlow
193          */
194         void                 *core_data;
195         /**
196          * The core_data_sz_bytes specifies the size of core_data in
197          * bytes.
198          *
199          * The size is set by TruFlow on tf_open_session().
200          *
201          * Please see tf_open_session_parms for specification details
202          * on this variable.
203          *
204          * Owner:  TruFlow
205          * Access: TruFlow
206          */
207         uint32_t              core_data_sz_bytes;
208 };
209
210 /** TruFlow handle
211  *
212  * Contains a pointer to the session info. Allocated by ULP and passed
213  * to TruFlow using tf_open_session(). TruFlow will populate the
214  * session info at that time. Additional 'opens' can be done using
215  * same session_info by using tf_attach_session().
216  *
217  * It is expected that ULP allocates this memory as shared memory.
218  *
219  * NOTE: This struct must be within the BNXT PMD struct bnxt
220  *       (bp). This allows use of container_of() to get access to the PMD.
221  */
222 struct tf {
223         struct tf_session_info *session;
224 };
225
226
227 /**
228  * tf_open_session parameters definition.
229  */
230 struct tf_open_session_parms {
231         /** [in] ctrl_chan_name
232          *
233          * String containing name of control channel interface to be
234          * used for this session to communicate with firmware.
235          *
236          * The ctrl_chan_name can be looked up by using
237          * rte_eth_dev_get_name_by_port() within the ULP.
238          *
239          * ctrl_chan_name will be used as part of a name for any
240          * shared memory allocation.
241          */
242         char ctrl_chan_name[TF_SESSION_NAME_MAX];
243         /** [in] shadow_copy
244          *
245          * Boolean controlling the use and availability of shadow
246          * copy. Shadow copy will allow the TruFlow to keep track of
247          * resource content on the firmware side without having to
248          * query firmware. Additional private session core_data will
249          * be allocated if this boolean is set to 'true', default
250          * 'false'.
251          *
252          * Size of memory depends on the NVM Resource settings for the
253          * control channel.
254          */
255         bool shadow_copy;
256         /** [in/out] session_id
257          *
258          * Session_id is unique per session.
259          *
260          * Session_id is composed of domain, bus, device and
261          * fw_session_id. The construction is done by parsing the
262          * ctrl_chan_name together with allocation of a fw_session_id.
263          *
264          * The session_id allows a session to be shared between devices.
265          */
266         union tf_session_id session_id;
267         /** [in] device type
268          *
269          * Device type is passed, one of Wh+, Brd2, Brd3, Brd4
270          */
271         enum tf_device_type device_type;
272 };
273
274 /**
275  * Opens a new TruFlow management session.
276  *
277  * TruFlow will allocate session specific memory, shared memory, to
278  * hold its session data. This data is private to TruFlow.
279  *
280  * Multiple PFs can share the same session. An association, refcount,
281  * between session and PFs is maintained within TruFlow. Thus, a PF
282  * can attach to an existing session, see tf_attach_session().
283  *
284  * No other TruFlow APIs will succeed unless this API is first called and
285  * succeeds.
286  *
287  * tf_open_session() returns a session id that can be used on attach.
288  *
289  * [in] tfp
290  *   Pointer to TF handle
291  * [in] parms
292  *   Pointer to open parameters
293  *
294  * Returns
295  *   - (0) if successful.
296  *   - (-EINVAL) on failure.
297  */
298 int tf_open_session(struct tf *tfp,
299                     struct tf_open_session_parms *parms);
300
301 struct tf_attach_session_parms {
302         /** [in] ctrl_chan_name
303          *
304          * String containing name of control channel interface to be
305          * used for this session to communicate with firmware.
306          *
307          * The ctrl_chan_name can be looked up by using
308          * rte_eth_dev_get_name_by_port() within the ULP.
309          *
310          * ctrl_chan_name will be used as part of a name for any
311          * shared memory allocation.
312          */
313         char ctrl_chan_name[TF_SESSION_NAME_MAX];
314
315         /** [in] attach_chan_name
316          *
317          * String containing name of attach channel interface to be
318          * used for this session.
319          *
320          * The attach_chan_name must be given to a 2nd process after
321          * the primary process has been created. This is the
322          * ctrl_chan_name of the primary process and is used to find
323          * the shared memory for the session that the attach is going
324          * to use.
325          */
326         char attach_chan_name[TF_SESSION_NAME_MAX];
327
328         /** [in] session_id
329          *
330          * Session_id is unique per session. For Attach the session_id
331          * should be the session_id that was returned on the first
332          * open.
333          *
334          * Session_id is composed of domain, bus, device and
335          * fw_session_id. The construction is done by parsing the
336          * ctrl_chan_name together with allocation of a fw_session_id
337          * during tf_open_session().
338          *
339          * A reference count will be incremented on attach. A session
340          * is first fully closed when reference count is zero by
341          * calling tf_close_session().
342          */
343         union tf_session_id session_id;
344 };
345
346 /**
347  * Attaches to an existing session. Used when more than one PF wants
348  * to share a single session. In that case all TruFlow management
349  * traffic will be sent to the TruFlow firmware using the 'PF' that
350  * did the attach not the session ctrl channel.
351  *
352  * Attach will increment a ref count as to manage the shared session data.
353  *
354  * [in] tfp, pointer to TF handle
355  * [in] parms, pointer to attach parameters
356  *
357  * Returns
358  *   - (0) if successful.
359  *   - (-EINVAL) on failure.
360  */
361 int tf_attach_session(struct tf *tfp,
362                       struct tf_attach_session_parms *parms);
363
364 /**
365  * Closes an existing session. Cleans up all hardware and firmware
366  * state associated with the TruFlow application session when the last
367  * PF associated with the session results in refcount to be zero.
368  *
369  * Returns success or failure code.
370  */
371 int tf_close_session(struct tf *tfp);
372
373 /**
374  * @page  ident Identity Management
375  *
376  * @ref tf_alloc_identifier
377  *
378  * @ref tf_free_identifier
379  */
380 enum tf_identifier_type {
381         /** The L2 Context is returned from the L2 Ctxt TCAM lookup
382          *  and can be used in WC TCAM or EM keys to virtualize further
383          *  lookups.
384          */
385         TF_IDENT_TYPE_L2_CTXT,
386         /** The WC profile func is returned from the L2 Ctxt TCAM lookup
387          *  to enable virtualization of the profile TCAM.
388          */
389         TF_IDENT_TYPE_PROF_FUNC,
390         /** The WC profile ID is included in the WC lookup key
391          *  to enable virtualization of the WC TCAM hardware.
392          */
393         TF_IDENT_TYPE_WC_PROF,
394         /** The EM profile ID is included in the EM lookup key
395          *  to enable virtualization of the EM hardware. (not required for Brd4
396          *  as it has table scope)
397          */
398         TF_IDENT_TYPE_EM_PROF,
399         /** The L2 func is included in the ILT result and from recycling to
400          *  enable virtualization of further lookups.
401          */
402         TF_IDENT_TYPE_L2_FUNC
403 };
404
405 /** tf_alloc_identifier parameter definition
406  */
407 struct tf_alloc_identifier_parms {
408         /**
409          * [in]  receive or transmit direction
410          */
411         enum tf_dir dir;
412         /**
413          * [in] Identifier type
414          */
415         enum tf_identifier_type ident_type;
416         /**
417          * [out] Identifier allocated
418          */
419         uint16_t id;
420 };
421
422 /** tf_free_identifier parameter definition
423  */
424 struct tf_free_identifier_parms {
425         /**
426          * [in]  receive or transmit direction
427          */
428         enum tf_dir dir;
429         /**
430          * [in] Identifier type
431          */
432         enum tf_identifier_type ident_type;
433         /**
434          * [in] ID to free
435          */
436         uint16_t id;
437 };
438
439 /** allocate identifier resource
440  *
441  * TruFlow core will allocate a free id from the per identifier resource type
442  * pool reserved for the session during tf_open().  No firmware is involved.
443  *
444  * Returns success or failure code.
445  */
446 int tf_alloc_identifier(struct tf *tfp,
447                         struct tf_alloc_identifier_parms *parms);
448
449 /** free identifier resource
450  *
451  * TruFlow core will return an id back to the per identifier resource type pool
452  * reserved for the session.  No firmware is involved.  During tf_close, the
453  * complete pool is returned to the firmware.
454  *
455  * Returns success or failure code.
456  */
457 int tf_free_identifier(struct tf *tfp,
458                        struct tf_free_identifier_parms *parms);
459
460 /**
461  * TCAM table type
462  */
463 enum tf_tcam_tbl_type {
464         TF_TCAM_TBL_TYPE_L2_CTXT_TCAM,
465         TF_TCAM_TBL_TYPE_PROF_TCAM,
466         TF_TCAM_TBL_TYPE_WC_TCAM,
467         TF_TCAM_TBL_TYPE_SP_TCAM,
468         TF_TCAM_TBL_TYPE_CT_RULE_TCAM,
469         TF_TCAM_TBL_TYPE_VEB_TCAM,
470         TF_TCAM_TBL_TYPE_MAX
471
472 };
473
474 /**
475  * Enumeration of TruFlow table types. A table type is used to identify a
476  * resource object.
477  *
478  * NOTE: The table type TF_TBL_TYPE_EXT is unique in that it is
479  * the only table type that is connected with a table scope.
480  */
481 enum tf_tbl_type {
482         /** Wh+/Brd2 Action Record */
483         TF_TBL_TYPE_FULL_ACT_RECORD,
484         /** Multicast Groups */
485         TF_TBL_TYPE_MCAST_GROUPS,
486         /** Action Encap 8 Bytes */
487         TF_TBL_TYPE_ACT_ENCAP_8B,
488         /** Action Encap 16 Bytes */
489         TF_TBL_TYPE_ACT_ENCAP_16B,
490         /** Action Encap 64 Bytes */
491         TF_TBL_TYPE_ACT_ENCAP_32B,
492         /** Action Encap 64 Bytes */
493         TF_TBL_TYPE_ACT_ENCAP_64B,
494         /** Action Source Properties SMAC */
495         TF_TBL_TYPE_ACT_SP_SMAC,
496         /** Action Source Properties SMAC IPv4 */
497         TF_TBL_TYPE_ACT_SP_SMAC_IPV4,
498         /** Action Source Properties SMAC IPv6 */
499         TF_TBL_TYPE_ACT_SP_SMAC_IPV6,
500         /** Action Statistics 64 Bits */
501         TF_TBL_TYPE_ACT_STATS_64,
502         /** Action Modify L4 Src Port */
503         TF_TBL_TYPE_ACT_MODIFY_SPORT,
504         /** Action Modify L4 Dest Port */
505         TF_TBL_TYPE_ACT_MODIFY_DPORT,
506         /** Action Modify IPv4 Source */
507         TF_TBL_TYPE_ACT_MODIFY_IPV4_SRC,
508         /** Action _Modify L4 Dest Port */
509         TF_TBL_TYPE_ACT_MODIFY_IPV4_DEST,
510         /** Action Modify IPv6 Source */
511         TF_TBL_TYPE_ACT_MODIFY_IPV6_SRC,
512         /** Action Modify IPv6 Destination */
513         TF_TBL_TYPE_ACT_MODIFY_IPV6_DEST,
514
515         /* HW */
516
517         /** Meter Profiles */
518         TF_TBL_TYPE_METER_PROF,
519         /** Meter Instance */
520         TF_TBL_TYPE_METER_INST,
521         /** Mirror Config */
522         TF_TBL_TYPE_MIRROR_CONFIG,
523         /** UPAR */
524         TF_TBL_TYPE_UPAR,
525         /** Brd4 Epoch 0 table */
526         TF_TBL_TYPE_EPOCH0,
527         /** Brd4 Epoch 1 table  */
528         TF_TBL_TYPE_EPOCH1,
529         /** Brd4 Metadata  */
530         TF_TBL_TYPE_METADATA,
531         /** Brd4 CT State  */
532         TF_TBL_TYPE_CT_STATE,
533         /** Brd4 Range Profile  */
534         TF_TBL_TYPE_RANGE_PROF,
535         /** Brd4 Range Entry  */
536         TF_TBL_TYPE_RANGE_ENTRY,
537         /** Brd4 LAG Entry  */
538         TF_TBL_TYPE_LAG,
539         /** Brd4 only VNIC/SVIF Table */
540         TF_TBL_TYPE_VNIC_SVIF,
541
542         /* External */
543
544         /** External table type - initially 1 poolsize entries.
545          * All External table types are associated with a table
546          * scope. Internal types are not.
547          */
548         TF_TBL_TYPE_EXT,
549         /** Future - external pool of size0 entries */
550         TF_TBL_TYPE_EXT_0,
551         TF_TBL_TYPE_MAX
552 };
553 #endif /* _TF_CORE_H_ */