net/bnxt: modify resource management scheme
[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 #include "hcapi/hcapi_cfa.h"
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 #define TF_KILOBYTE  1024
26 #define TF_MEGABYTE  (1024 * 1024)
27
28 /**
29  * direction
30  */
31 enum tf_dir {
32         TF_DIR_RX,  /**< Receive */
33         TF_DIR_TX,  /**< Transmit */
34         TF_DIR_MAX
35 };
36
37 /**
38  * memory choice
39  */
40 enum tf_mem {
41         TF_MEM_INTERNAL, /**< Internal */
42         TF_MEM_EXTERNAL, /**< External */
43         TF_MEM_MAX
44 };
45
46 /**
47  * EEM record AR helper
48  *
49  * Helper to handle the Action Record Pointer in the EEM Record Entry.
50  *
51  * Convert absolute offset to action record pointer in EEM record entry
52  * Convert action record pointer in EEM record entry to absolute offset
53  */
54 #define TF_ACT_REC_OFFSET_2_PTR(offset) ((offset) >> 4)
55 #define TF_ACT_REC_PTR_2_OFFSET(offset) ((offset) << 4)
56
57
58 /*
59  * Helper Macros
60  */
61 #define TF_BITS_2_BYTES(num_bits) (((num_bits) + 7) / 8)
62
63 /********** BEGIN API FUNCTION PROTOTYPES/PARAMETERS **********/
64
65 /**
66  * @page general General
67  *
68  * @ref tf_open_session
69  *
70  * @ref tf_attach_session
71  *
72  * @ref tf_close_session
73  */
74
75 /**
76  * Session Version defines
77  *
78  * The version controls the format of the tf_session and
79  * tf_session_info structure. This is to assure upgrade between
80  * versions can be supported.
81  */
82 #define TF_SESSION_VER_MAJOR  1   /**< Major Version */
83 #define TF_SESSION_VER_MINOR  0   /**< Minor Version */
84 #define TF_SESSION_VER_UPDATE 0   /**< Update Version */
85
86 /**
87  * Session Name
88  *
89  * Name of the TruFlow control channel interface.  Expects
90  * format to be RTE Name specific, i.e. rte_eth_dev_get_name_by_port()
91  */
92 #define TF_SESSION_NAME_MAX       64
93
94 #define TF_FW_SESSION_ID_INVALID  0xFF  /**< Invalid FW Session ID define */
95
96 /**
97  * Session Identifier
98  *
99  * Unique session identifier which includes PCIe bus info to
100  * distinguish the PF and session info to identify the associated
101  * TruFlow session. Session ID is constructed from the passed in
102  * ctrl_chan_name in tf_open_session() together with an allocated
103  * fw_session_id. Done by TruFlow on tf_open_session().
104  */
105 union tf_session_id {
106         uint32_t id;
107         struct {
108                 uint8_t domain;
109                 uint8_t bus;
110                 uint8_t device;
111                 uint8_t fw_session_id;
112         } internal;
113 };
114
115 /**
116  * Session Client Identifier
117  *
118  * Unique identifier for a client within a session. Session Client ID
119  * is constructed from the passed in session and a firmware allocated
120  * fw_session_client_id. Done by TruFlow on tf_open_session().
121  */
122 union tf_session_client_id {
123         uint16_t id;
124         struct {
125                 uint8_t fw_session_id;
126                 uint8_t fw_session_client_id;
127         } internal;
128 };
129
130 /**
131  * Session Version
132  *
133  * The version controls the format of the tf_session and
134  * tf_session_info structure. This is to assure upgrade between
135  * versions can be supported.
136  *
137  * Please see the TF_VER_MAJOR/MINOR and UPDATE defines.
138  */
139 struct tf_session_version {
140         uint8_t major;
141         uint8_t minor;
142         uint8_t update;
143 };
144
145 /**
146  * Session supported device types
147  */
148 enum tf_device_type {
149         TF_DEVICE_TYPE_WH = 0, /**< Whitney+  */
150         TF_DEVICE_TYPE_SR,     /**< Stingray  */
151         TF_DEVICE_TYPE_THOR,   /**< Thor      */
152         TF_DEVICE_TYPE_SR2,    /**< Stingray2 */
153         TF_DEVICE_TYPE_MAX     /**< Maximum   */
154 };
155
156 /**
157  * Identifier resource types
158  */
159 enum tf_identifier_type {
160         /**
161          *  The L2 Context is returned from the L2 Ctxt TCAM lookup
162          *  and can be used in WC TCAM or EM keys to virtualize further
163          *  lookups.
164          */
165         TF_IDENT_TYPE_L2_CTXT_HIGH,
166         /**
167          *  The L2 Context is returned from the L2 Ctxt TCAM lookup
168          *  and can be used in WC TCAM or EM keys to virtualize further
169          *  lookups.
170          */
171         TF_IDENT_TYPE_L2_CTXT_LOW,
172         /**
173          *  The WC profile func is returned from the L2 Ctxt TCAM lookup
174          *  to enable virtualization of the profile TCAM.
175          */
176         TF_IDENT_TYPE_PROF_FUNC,
177         /**
178          *  The WC profile ID is included in the WC lookup key
179          *  to enable virtualization of the WC TCAM hardware.
180          */
181         TF_IDENT_TYPE_WC_PROF,
182         /**
183          *  The EM profile ID is included in the EM lookup key
184          *  to enable virtualization of the EM hardware. (not required for SR2
185          *  as it has table scope)
186          */
187         TF_IDENT_TYPE_EM_PROF,
188         /**
189          *  The L2 func is included in the ILT result and from recycling to
190          *  enable virtualization of further lookups.
191          */
192         TF_IDENT_TYPE_L2_FUNC,
193         TF_IDENT_TYPE_MAX
194 };
195
196 /**
197  * Enumeration of TruFlow table types. A table type is used to identify a
198  * resource object.
199  *
200  * NOTE: The table type TF_TBL_TYPE_EXT is unique in that it is
201  * the only table type that is connected with a table scope.
202  */
203 enum tf_tbl_type {
204         /* Internal */
205
206         /** Wh+/SR Action Record */
207         TF_TBL_TYPE_FULL_ACT_RECORD,
208         /** Wh+/SR/Th Multicast Groups */
209         TF_TBL_TYPE_MCAST_GROUPS,
210         /** Wh+/SR Action Encap 8 Bytes */
211         TF_TBL_TYPE_ACT_ENCAP_8B,
212         /** Wh+/SR Action Encap 16 Bytes */
213         TF_TBL_TYPE_ACT_ENCAP_16B,
214         /** Action Encap 32 Bytes */
215         TF_TBL_TYPE_ACT_ENCAP_32B,
216         /** Wh+/SR Action Encap 64 Bytes */
217         TF_TBL_TYPE_ACT_ENCAP_64B,
218         /** Action Source Properties SMAC */
219         TF_TBL_TYPE_ACT_SP_SMAC,
220         /** Wh+/SR Action Source Properties SMAC IPv4 */
221         TF_TBL_TYPE_ACT_SP_SMAC_IPV4,
222         /** Action Source Properties SMAC IPv6 */
223         TF_TBL_TYPE_ACT_SP_SMAC_IPV6,
224         /** Wh+/SR Action Statistics 64 Bits */
225         TF_TBL_TYPE_ACT_STATS_64,
226         /** Wh+/SR Action Modify L4 Src Port */
227         TF_TBL_TYPE_ACT_MODIFY_SPORT,
228         /** Wh+/SR Action Modify L4 Dest Port */
229         TF_TBL_TYPE_ACT_MODIFY_DPORT,
230         /** Wh+/SR Action Modify IPv4 Source */
231         TF_TBL_TYPE_ACT_MODIFY_IPV4_SRC,
232         /** Wh+/SR Action _Modify L4 Dest Port */
233         TF_TBL_TYPE_ACT_MODIFY_IPV4_DEST,
234         /** Meter Profiles */
235         TF_TBL_TYPE_METER_PROF,
236         /** Meter Instance */
237         TF_TBL_TYPE_METER_INST,
238         /** Mirror Config */
239         TF_TBL_TYPE_MIRROR_CONFIG,
240         /** UPAR */
241         TF_TBL_TYPE_UPAR,
242         /** SR2 Epoch 0 table */
243         TF_TBL_TYPE_EPOCH0,
244         /** SR2 Epoch 1 table  */
245         TF_TBL_TYPE_EPOCH1,
246         /** SR2 Metadata  */
247         TF_TBL_TYPE_METADATA,
248         /** SR2 CT State  */
249         TF_TBL_TYPE_CT_STATE,
250         /** SR2 Range Profile  */
251         TF_TBL_TYPE_RANGE_PROF,
252         /** SR2 Range Entry  */
253         TF_TBL_TYPE_RANGE_ENTRY,
254         /** SR2 LAG Entry  */
255         TF_TBL_TYPE_LAG,
256         /** SR2 VNIC/SVIF Table */
257         TF_TBL_TYPE_VNIC_SVIF,
258         /** Th/SR2 EM Flexible Key builder */
259         TF_TBL_TYPE_EM_FKB,
260         /** Th/SR2 WC Flexible Key builder */
261         TF_TBL_TYPE_WC_FKB,
262
263         /* External */
264
265         /**
266          * External table type - initially 1 poolsize entries.
267          * All External table types are associated with a table
268          * scope. Internal types are not.
269          */
270         TF_TBL_TYPE_EXT,
271         TF_TBL_TYPE_MAX
272 };
273
274 /**
275  * TCAM table type
276  */
277 enum tf_tcam_tbl_type {
278         /** L2 Context TCAM */
279         TF_TCAM_TBL_TYPE_L2_CTXT_TCAM_HIGH,
280         /** L2 Context TCAM */
281         TF_TCAM_TBL_TYPE_L2_CTXT_TCAM_LOW,
282         /** Profile TCAM */
283         TF_TCAM_TBL_TYPE_PROF_TCAM,
284         /** Wildcard TCAM */
285         TF_TCAM_TBL_TYPE_WC_TCAM,
286         /** Source Properties TCAM */
287         TF_TCAM_TBL_TYPE_SP_TCAM,
288         /** Connection Tracking Rule TCAM */
289         TF_TCAM_TBL_TYPE_CT_RULE_TCAM,
290         /** Virtual Edge Bridge TCAM */
291         TF_TCAM_TBL_TYPE_VEB_TCAM,
292         TF_TCAM_TBL_TYPE_MAX
293 };
294
295 /**
296  * EM Resources
297  * These defines are provisioned during
298  * tf_open_session()
299  */
300 enum tf_em_tbl_type {
301         /** The number of internal EM records for the session */
302         TF_EM_TBL_TYPE_EM_RECORD,
303         /** The number of table scopes reequested */
304         TF_EM_TBL_TYPE_TBL_SCOPE,
305         TF_EM_TBL_TYPE_MAX
306 };
307
308 /**
309  * TruFlow Session Information
310  *
311  * Structure defining a TruFlow Session, also known as a Management
312  * session. This structure is initialized at time of
313  * tf_open_session(). It is passed to all of the TruFlow APIs as way
314  * to prescribe and isolate resources between different TruFlow ULP
315  * Applications.
316  *
317  * Ownership of the elements is split between ULP and TruFlow. Please
318  * see the individual elements.
319  */
320 struct tf_session_info {
321         /**
322          * TrueFlow Version. Used to control the structure layout when
323          * sharing sessions. No guarantee that a secondary process
324          * would come from the same version of an executable.
325          * TruFlow initializes this variable on tf_open_session().
326          *
327          * Owner:  TruFlow
328          * Access: TruFlow
329          */
330         struct tf_session_version ver;
331         /**
332          * will be STAILQ_ENTRY(tf_session_info) next
333          *
334          * Owner:  ULP
335          * Access: ULP
336          */
337         void                 *next;
338         /**
339          * Session ID is a unique identifier for the session. TruFlow
340          * initializes this variable during tf_open_session()
341          * processing.
342          *
343          * Owner:  TruFlow
344          * Access: Truflow & ULP
345          */
346         union tf_session_id   session_id;
347         /**
348          * Protects access to core_data. Lock is initialized and owned
349          * by ULP. TruFlow can access the core_data without checking
350          * the lock.
351          *
352          * Owner:  ULP
353          * Access: ULP
354          */
355         uint8_t               spin_lock;
356         /**
357          * The core_data holds the TruFlow tf_session data
358          * structure. This memory is allocated and owned by TruFlow on
359          * tf_open_session().
360          *
361          * TruFlow uses this memory for session management control
362          * until the session is closed by ULP. Access control is done
363          * by the spin_lock which ULP controls ahead of TruFlow API
364          * calls.
365          *
366          * Please see tf_open_session_parms for specification details
367          * on this variable.
368          *
369          * Owner:  TruFlow
370          * Access: TruFlow
371          */
372         void                 *core_data;
373         /**
374          * The core_data_sz_bytes specifies the size of core_data in
375          * bytes.
376          *
377          * The size is set by TruFlow on tf_open_session().
378          *
379          * Please see tf_open_session_parms for specification details
380          * on this variable.
381          *
382          * Owner:  TruFlow
383          * Access: TruFlow
384          */
385         uint32_t              core_data_sz_bytes;
386 };
387
388 /**
389  * TruFlow handle
390  *
391  * Contains a pointer to the session info. Allocated by ULP and passed
392  * to TruFlow using tf_open_session(). TruFlow will populate the
393  * session info at that time. A TruFlow Session can be used by more
394  * than one PF/VF by using the tf_open_session().
395  *
396  * It is expected that ULP allocates this memory as shared memory.
397  *
398  * NOTE: This struct must be within the BNXT PMD struct bnxt
399  *       (bp). This allows use of container_of() to get access to the PMD.
400  */
401 struct tf {
402         struct tf_session_info *session;
403 };
404
405 /**
406  * Identifier resource definition
407  */
408 struct tf_identifier_resources {
409         /**
410          * Array of TF Identifiers where each entry is expected to be
411          * set to the requested resource number of that specific type.
412          * The index used is tf_identifier_type.
413          */
414         uint16_t cnt[TF_IDENT_TYPE_MAX];
415 };
416
417 /**
418  * Table type resource definition
419  */
420 struct tf_tbl_resources {
421         /**
422          * Array of TF Table types where each entry is expected to be
423          * set to the requeste resource number of that specific
424          * type. The index used is tf_tbl_type.
425          */
426         uint16_t cnt[TF_TBL_TYPE_MAX];
427 };
428
429 /**
430  * TCAM type resource definition
431  */
432 struct tf_tcam_resources {
433         /**
434          * Array of TF TCAM types where each entry is expected to be
435          * set to the requested resource number of that specific
436          * type. The index used is tf_tcam_tbl_type.
437          */
438         uint16_t cnt[TF_TCAM_TBL_TYPE_MAX];
439 };
440
441 /**
442  * EM type resource definition
443  */
444 struct tf_em_resources {
445         /**
446          * Array of TF EM table types where each entry is expected to
447          * be set to the requested resource number of that specific
448          * type. The index used is tf_em_tbl_type.
449          */
450         uint16_t cnt[TF_EM_TBL_TYPE_MAX];
451 };
452
453 /**
454  * tf_session_resources parameter definition.
455  */
456 struct tf_session_resources {
457         /**
458          * [in] Requested Identifier Resources
459          *
460          * Number of identifier resources requested for the
461          * session.
462          */
463         struct tf_identifier_resources ident_cnt[TF_DIR_MAX];
464         /**
465          * [in] Requested Index Table resource counts
466          *
467          * The number of index table resources requested for the
468          * session.
469          */
470         struct tf_tbl_resources tbl_cnt[TF_DIR_MAX];
471         /**
472          * [in] Requested TCAM Table resource counts
473          *
474          * The number of TCAM table resources requested for the
475          * session.
476          */
477
478         struct tf_tcam_resources tcam_cnt[TF_DIR_MAX];
479         /**
480          * [in] Requested EM resource counts
481          *
482          * The number of internal EM table resources requested for the
483          * session.
484          */
485         struct tf_em_resources em_cnt[TF_DIR_MAX];
486 };
487
488 /**
489  * tf_open_session parameters definition.
490  */
491 struct tf_open_session_parms {
492         /**
493          * [in] ctrl_chan_name
494          *
495          * String containing name of control channel interface to be
496          * used for this session to communicate with firmware.
497          *
498          * The ctrl_chan_name can be looked up by using
499          * rte_eth_dev_get_name_by_port() within the ULP.
500          *
501          * ctrl_chan_name will be used as part of a name for any
502          * shared memory allocation.
503          */
504         char ctrl_chan_name[TF_SESSION_NAME_MAX];
505         /**
506          * [in] shadow_copy
507          *
508          * Boolean controlling the use and availability of shadow
509          * copy. Shadow copy will allow the TruFlow to keep track of
510          * resource content on the firmware side without having to
511          * query firmware. Additional private session core_data will
512          * be allocated if this boolean is set to 'true', default
513          * 'false'.
514          *
515          * Size of memory depends on the NVM Resource settings for the
516          * control channel.
517          */
518         bool shadow_copy;
519         /**
520          * [in/out] session_id
521          *
522          * Session_id is unique per session.
523          *
524          * Session_id is composed of domain, bus, device and
525          * fw_session_id. The construction is done by parsing the
526          * ctrl_chan_name together with allocation of a fw_session_id.
527          *
528          * The session_id allows a session to be shared between devices.
529          */
530         union tf_session_id session_id;
531         /**
532          * [in/out] session_client_id
533          *
534          * Session_client_id is unique per client.
535          *
536          * Session_client_id is composed of session_id and the
537          * fw_session_client_id fw_session_id. The construction is
538          * done by parsing the ctrl_chan_name together with allocation
539          * of a fw_session_client_id during tf_open_session().
540          *
541          * A reference count will be incremented in the session on
542          * which a client is created.
543          *
544          * A session can first be closed if there is one Session
545          * Client left. Session Clients should closed using
546          * tf_close_session().
547          */
548         union tf_session_client_id session_client_id;
549         /**
550          * [in] device type
551          *
552          * Device type for the session.
553          */
554         enum tf_device_type device_type;
555         /**
556          * [in] resources
557          *
558          * Resource allocation for the session.
559          */
560         struct tf_session_resources resources;
561 };
562
563 /**
564  * Opens a new TruFlow Session or session client.
565  *
566  * What gets created depends on the passed in tfp content. If the tfp
567  * does not have prior session data a new session with associated
568  * session client. If tfp has a session already a session client will
569  * be created. In both cases the session client is created using the
570  * provided ctrl_chan_name.
571  *
572  * In case of session creation TruFlow will allocate session specific
573  * memory, shared memory, to hold its session data. This data is
574  * private to TruFlow.
575  *
576  * No other TruFlow APIs will succeed unless this API is first called
577  * and succeeds.
578  *
579  * tf_open_session() returns a session id and session client id that
580  * is used on all other TF APIs.
581  *
582  * A Session or session client can be closed using tf_close_session().
583  *
584  * [in] tfp
585  *   Pointer to TF handle
586  *
587  * [in] parms
588  *   Pointer to open parameters
589  *
590  * Returns
591  *   - (0) if successful.
592  *   - (-EINVAL) on failure.
593  */
594 int tf_open_session(struct tf *tfp,
595                     struct tf_open_session_parms *parms);
596
597 /**
598  * Experimental
599  *
600  * tf_attach_session parameters definition.
601  */
602 struct tf_attach_session_parms {
603         /**
604          * [in] ctrl_chan_name
605          *
606          * String containing name of control channel interface to be
607          * used for this session to communicate with firmware.
608          *
609          * The ctrl_chan_name can be looked up by using
610          * rte_eth_dev_get_name_by_port() within the ULP.
611          *
612          * ctrl_chan_name will be used as part of a name for any
613          * shared memory allocation.
614          */
615         char ctrl_chan_name[TF_SESSION_NAME_MAX];
616
617         /**
618          * [in] attach_chan_name
619          *
620          * String containing name of attach channel interface to be
621          * used for this session.
622          *
623          * The attach_chan_name must be given to a 2nd process after
624          * the primary process has been created. This is the
625          * ctrl_chan_name of the primary process and is used to find
626          * the shared memory for the session that the attach is going
627          * to use.
628          */
629         char attach_chan_name[TF_SESSION_NAME_MAX];
630
631         /**
632          * [in] session_id
633          *
634          * Session_id is unique per session. For Attach the session_id
635          * should be the session_id that was returned on the first
636          * open.
637          *
638          * Session_id is composed of domain, bus, device and
639          * fw_session_id. The construction is done by parsing the
640          * ctrl_chan_name together with allocation of a fw_session_id
641          * during tf_open_session().
642          *
643          * A reference count will be incremented on attach. A session
644          * is first fully closed when reference count is zero by
645          * calling tf_close_session().
646          */
647         union tf_session_id session_id;
648 };
649
650 /**
651  * Experimental
652  *
653  * Allows a 2nd application instance to attach to an existing
654  * session. Used when a session is to be shared between two processes.
655  *
656  * Attach will increment a ref count as to manage the shared session data.
657  *
658  * [in] tfp
659  *   Pointer to TF handle
660  *
661  * [in] parms
662  *   Pointer to attach parameters
663  *
664  * Returns
665  *   - (0) if successful.
666  *   - (-EINVAL) on failure.
667  */
668 int tf_attach_session(struct tf *tfp,
669                       struct tf_attach_session_parms *parms);
670
671 /**
672  * Closes an existing session client or the session it self. The
673  * session client is default closed and if the session reference count
674  * is 0 then the session is closed as well.
675  *
676  * On session close all hardware and firmware state associated with
677  * the TruFlow application is cleaned up.
678  *
679  * The session client is extracted from the tfp. Thus tf_close_session()
680  * cannot close a session client on behalf of another function.
681  *
682  * Returns success or failure code.
683  */
684 int tf_close_session(struct tf *tfp);
685
686 /**
687  * @page  ident Identity Management
688  *
689  * @ref tf_alloc_identifier
690  *
691  * @ref tf_free_identifier
692  */
693 /**
694  * tf_alloc_identifier parameter definition
695  */
696 struct tf_alloc_identifier_parms {
697         /**
698          * [in]  receive or transmit direction
699          */
700         enum tf_dir dir;
701         /**
702          * [in] Identifier type
703          */
704         enum tf_identifier_type ident_type;
705         /**
706          * [out] Allocated identifier
707          */
708         uint32_t id;
709 };
710
711 /**
712  * tf_free_identifier parameter definition
713  */
714 struct tf_free_identifier_parms {
715         /**
716          * [in]  receive or transmit direction
717          */
718         enum tf_dir dir;
719         /**
720          * [in] Identifier type
721          */
722         enum tf_identifier_type ident_type;
723         /**
724          * [in] ID to free
725          */
726         uint32_t id;
727         /**
728          * (experimental)
729          * [out] Current refcnt after free
730          */
731         uint32_t ref_cnt;
732 };
733
734 /**
735  * tf_search_identifier parameter definition (experimental)
736  */
737 struct tf_search_identifier_parms {
738         /**
739          * [in]  receive or transmit direction
740          */
741         enum tf_dir dir;
742         /**
743          * [in] Identifier type
744          */
745         enum tf_identifier_type ident_type;
746         /**
747          * [in] Identifier data to search for
748          */
749         uint32_t search_id;
750         /**
751          * [out] Set if matching identifier found
752          */
753         bool hit;
754         /**
755          * [out] Current ref count after allocation
756          */
757         uint32_t ref_cnt;
758 };
759
760 /**
761  * allocate identifier resource
762  *
763  * TruFlow core will allocate a free id from the per identifier resource type
764  * pool reserved for the session during tf_open().  No firmware is involved.
765  *
766  * If shadow copy is enabled, the internal ref_cnt is set to 1 in the
767  * shadow table for a newly allocated resource.
768  *
769  * Returns success or failure code.
770  */
771 int tf_alloc_identifier(struct tf *tfp,
772                         struct tf_alloc_identifier_parms *parms);
773
774 /**
775  * free identifier resource
776  *
777  * TruFlow core will return an id back to the per identifier resource type pool
778  * reserved for the session.  No firmware is involved.  During tf_close, the
779  * complete pool is returned to the firmware.
780  *
781  * additional operation (experimental)
782  * Decrement reference count.  Only release resource once refcnt goes to 0 if
783  * shadow copy is enabled.
784  *
785  * Returns success or failure code.
786  */
787 int tf_free_identifier(struct tf *tfp,
788                        struct tf_free_identifier_parms *parms);
789
790 /**
791  * Search identifier resource (experimental)
792  *
793  * If the shadow copy is enabled search_id is used to search for a matching
794  * entry in the shadow table.  The shadow table consists of an array of
795  * reference counts indexed by identifier.  If a matching entry is found hit is
796  * set to TRUE, refcnt is increased by 1 and returned.  Otherwise, hit is
797  * set to false and refcnt is set to 0.
798  *
799  * TODO: we may need a per table internal shadow copy enable flag to stage
800  * the shadow table implementation.  We do not need the shadow table for other
801  * tables at this time so we may only want to enable the identifier shadow.
802  *
803  * TODO: remove this pseudocode below added to show that if search fails
804  * we shouldn't allocate a new entry but return.
805  *
806  * identifier alloc (search_en=1)
807  * if (ident is allocated and ref_cnt >=1)
808  *      return ident - hit is set, incr refcnt
809  * else (not found)
810  *      return
811  *
812  */
813 int tf_search_identifier(struct tf *tfp,
814                          struct tf_search_identifier_parms *parms);
815
816 /**
817  * @page dram_table DRAM Table Scope Interface
818  *
819  * @ref tf_alloc_tbl_scope
820  *
821  * @ref tf_free_tbl_scope
822  *
823  * If we allocate the EEM memory from the core, we need to store it in
824  * the shared session data structure to make sure it can be freed later.
825  * (for example if the PF goes away)
826  *
827  * Current thought is that memory is allocated within core.
828  */
829
830
831 /**
832  * tf_alloc_tbl_scope_parms definition
833  */
834 struct tf_alloc_tbl_scope_parms {
835         /**
836          * [in] All Maximum key size required.
837          */
838         uint16_t rx_max_key_sz_in_bits;
839         /**
840          * [in] Maximum Action size required (includes inlined items)
841          */
842         uint16_t rx_max_action_entry_sz_in_bits;
843         /**
844          * [in] Memory size in Megabytes
845          * Total memory size allocated by user to be divided
846          * up for actions, hash, counters.  Only inline external actions.
847          * Use this variable or the number of flows, do not set both.
848          */
849         uint32_t rx_mem_size_in_mb;
850         /**
851          * [in] Number of flows * 1000. If set, rx_mem_size_in_mb must equal 0.
852          */
853         uint32_t rx_num_flows_in_k;
854         /**
855          * [in] SR2 only receive table access interface id
856          */
857         uint32_t rx_tbl_if_id;
858         /**
859          * [in] All Maximum key size required.
860          */
861         uint16_t tx_max_key_sz_in_bits;
862         /**
863          * [in] Maximum Action size required (includes inlined items)
864          */
865         uint16_t tx_max_action_entry_sz_in_bits;
866         /**
867          * [in] Memory size in Megabytes
868          * Total memory size allocated by user to be divided
869          * up for actions, hash, counters.  Only inline external actions.
870          */
871         uint32_t tx_mem_size_in_mb;
872         /**
873          * [in] Number of flows * 1000
874          */
875         uint32_t tx_num_flows_in_k;
876         /**
877          * [in] SR2 only receive table access interface id
878          */
879         uint32_t tx_tbl_if_id;
880         /**
881          * [in] Flush pending HW cached flows every 1/10th of value
882          * set in seconds, both idle and active flows are flushed
883          * from the HW cache. If set to 0, this feature will be disabled.
884          */
885         uint8_t hw_flow_cache_flush_timer;
886         /**
887          * [out] table scope identifier
888          */
889         uint32_t tbl_scope_id;
890 };
891
892 struct tf_free_tbl_scope_parms {
893         /**
894          * [in] table scope identifier
895          */
896         uint32_t tbl_scope_id;
897 };
898
899 /**
900  * allocate a table scope
901  *
902  * On SR2 Firmware will allocate a scope ID.  On other devices, the scope
903  * is a software construct to identify an EEM table.  This function will
904  * divide the hash memory/buckets and records according to the device
905  * device constraints based upon calculations using either the number of flows
906  * requested or the size of memory indicated.  Other parameters passed in
907  * determine the configuration (maximum key size, maximum external action record
908  * size.
909  *
910  * This API will allocate the table region in
911  * DRAM, program the PTU page table entries, and program the number of static
912  * buckets (if SR2) in the RX and TX CFAs.  Buckets are assumed to start at
913  * 0 in the EM memory for the scope.  Upon successful completion of this API,
914  * hash tables are fully initialized and ready for entries to be inserted.
915  *
916  * A single API is used to allocate a common table scope identifier in both
917  * receive and transmit CFA. The scope identifier is common due to nature of
918  * connection tracking sending notifications between RX and TX direction.
919  *
920  * The receive and transmit table access identifiers specify which rings will
921  * be used to initialize table DRAM.  The application must ensure mutual
922  * exclusivity of ring usage for table scope allocation and any table update
923  * operations.
924  *
925  * The hash table buckets, EM keys, and EM lookup results are stored in the
926  * memory allocated based on the rx_em_hash_mb/tx_em_hash_mb parameters.  The
927  * hash table buckets are stored at the beginning of that memory.
928  *
929  * NOTE:  No EM internal setup is done here. On chip EM records are managed
930  * internally by TruFlow core.
931  *
932  * Returns success or failure code.
933  */
934 int tf_alloc_tbl_scope(struct tf *tfp,
935                        struct tf_alloc_tbl_scope_parms *parms);
936
937
938 /**
939  * free a table scope
940  *
941  * Firmware checks that the table scope ID is owned by the TruFlow
942  * session, verifies that no references to this table scope remains
943  * (SR2 ILT) or Profile TCAM entries for either CFA (RX/TX) direction,
944  * then frees the table scope ID.
945  *
946  * Returns success or failure code.
947  */
948 int tf_free_tbl_scope(struct tf *tfp,
949                       struct tf_free_tbl_scope_parms *parms);
950
951 /**
952  * @page tcam TCAM Access
953  *
954  * @ref tf_alloc_tcam_entry
955  *
956  * @ref tf_set_tcam_entry
957  *
958  * @ref tf_get_tcam_entry
959  *
960  * @ref tf_free_tcam_entry
961  */
962
963
964 /**
965  * tf_alloc_tcam_entry parameter definition
966  */
967 struct tf_alloc_tcam_entry_parms {
968         /**
969          * [in] receive or transmit direction
970          */
971         enum tf_dir dir;
972         /**
973          * [in] TCAM table type
974          */
975         enum tf_tcam_tbl_type tcam_tbl_type;
976         /**
977          * [in] Enable search for matching entry
978          */
979         uint8_t search_enable;
980         /**
981          * [in] Key data to match on (if search)
982          */
983         uint8_t *key;
984         /**
985          * [in] key size in bits (if search)
986          */
987         uint16_t key_sz_in_bits;
988         /**
989          * [in] Mask data to match on (if search)
990          */
991         uint8_t *mask;
992         /**
993          * [in] Priority of entry requested (definition TBD)
994          */
995         uint32_t priority;
996         /**
997          * [out] If search, set if matching entry found
998          */
999         uint8_t hit;
1000         /**
1001          * [out] Current refcnt after allocation
1002          */
1003         uint16_t ref_cnt;
1004         /**
1005          * [out] Idx allocated
1006          *
1007          */
1008         uint16_t idx;
1009 };
1010
1011 /**
1012  * allocate TCAM entry
1013  *
1014  * Allocate a TCAM entry - one of these types:
1015  *
1016  * L2 Context
1017  * Profile TCAM
1018  * WC TCAM
1019  * VEB TCAM
1020  *
1021  * This function allocates a TCAM table record.  This function
1022  * will attempt to allocate a TCAM table entry from the session
1023  * owned TCAM entries or search a shadow copy of the TCAM table for a
1024  * matching entry if search is enabled.  Key, mask and result must match for
1025  * hit to be set.  Only TruFlow core data is accessed.
1026  * A hash table to entry mapping is maintained for search purposes.  If
1027  * search is not enabled, the first available free entry is returned based
1028  * on priority and alloc_cnt is set to 1.  If search is enabled and a matching
1029  * entry to entry_data is found, hit is set to TRUE and alloc_cnt is set to 1.
1030  * RefCnt is also returned.
1031  *
1032  * Also returns success or failure code.
1033  */
1034 int tf_alloc_tcam_entry(struct tf *tfp,
1035                         struct tf_alloc_tcam_entry_parms *parms);
1036
1037 /**
1038  * tf_set_tcam_entry parameter definition
1039  */
1040 struct  tf_set_tcam_entry_parms {
1041         /**
1042          * [in] receive or transmit direction
1043          */
1044         enum tf_dir dir;
1045         /**
1046          * [in] TCAM table type
1047          */
1048         enum tf_tcam_tbl_type tcam_tbl_type;
1049         /**
1050          * [in] base index of the entry to program
1051          */
1052         uint16_t idx;
1053         /**
1054          * [in] struct containing key
1055          */
1056         uint8_t *key;
1057         /**
1058          * [in] struct containing mask fields
1059          */
1060         uint8_t *mask;
1061         /**
1062          * [in] key size in bits (if search)
1063          */
1064         uint16_t key_sz_in_bits;
1065         /**
1066          * [in] struct containing result
1067          */
1068         uint8_t *result;
1069         /**
1070          * [in] struct containing result size in bits
1071          */
1072         uint16_t result_sz_in_bits;
1073 };
1074
1075 /**
1076  * set TCAM entry
1077  *
1078  * Program a TCAM table entry for a TruFlow session.
1079  *
1080  * If the entry has not been allocated, an error will be returned.
1081  *
1082  * Returns success or failure code.
1083  */
1084 int tf_set_tcam_entry(struct tf *tfp,
1085                       struct tf_set_tcam_entry_parms *parms);
1086
1087 /**
1088  * tf_get_tcam_entry parameter definition
1089  */
1090 struct tf_get_tcam_entry_parms {
1091         /**
1092          * [in] receive or transmit direction
1093          */
1094         enum tf_dir dir;
1095         /**
1096          * [in] TCAM table type
1097          */
1098         enum tf_tcam_tbl_type  tcam_tbl_type;
1099         /**
1100          * [in] index of the entry to get
1101          */
1102         uint16_t idx;
1103         /**
1104          * [out] struct containing key
1105          */
1106         uint8_t *key;
1107         /**
1108          * [out] struct containing mask fields
1109          */
1110         uint8_t *mask;
1111         /**
1112          * [out] key size in bits
1113          */
1114         uint16_t key_sz_in_bits;
1115         /**
1116          * [out] struct containing result
1117          */
1118         uint8_t *result;
1119         /**
1120          * [out] struct containing result size in bits
1121          */
1122         uint16_t result_sz_in_bits;
1123 };
1124
1125 /**
1126  * get TCAM entry
1127  *
1128  * Program a TCAM table entry for a TruFlow session.
1129  *
1130  * If the entry has not been allocated, an error will be returned.
1131  *
1132  * Returns success or failure code.
1133  */
1134 int tf_get_tcam_entry(struct tf *tfp,
1135                       struct tf_get_tcam_entry_parms *parms);
1136
1137 /**
1138  * tf_free_tcam_entry parameter definition
1139  */
1140 struct tf_free_tcam_entry_parms {
1141         /**
1142          * [in] receive or transmit direction
1143          */
1144         enum tf_dir dir;
1145         /**
1146          * [in] TCAM table type
1147          */
1148         enum tf_tcam_tbl_type tcam_tbl_type;
1149         /**
1150          * [in] Index to free
1151          */
1152         uint16_t idx;
1153         /**
1154          * [out] reference count after free
1155          */
1156         uint16_t ref_cnt;
1157 };
1158
1159 /**
1160  * free TCAM entry
1161  *
1162  * Free TCAM entry.
1163  *
1164  * Firmware checks to ensure the TCAM entries are owned by the TruFlow
1165  * session.  TCAM entry will be invalidated.  All-ones mask.
1166  * writes to hw.
1167  *
1168  * WCTCAM profile id of 0 must be used to invalidate an entry.
1169  *
1170  * Returns success or failure code.
1171  */
1172 int tf_free_tcam_entry(struct tf *tfp,
1173                        struct tf_free_tcam_entry_parms *parms);
1174
1175 /**
1176  * @page table Table Access
1177  *
1178  * @ref tf_alloc_tbl_entry
1179  *
1180  * @ref tf_free_tbl_entry
1181  *
1182  * @ref tf_set_tbl_entry
1183  *
1184  * @ref tf_get_tbl_entry
1185  *
1186  * @ref tf_bulk_get_tbl_entry
1187  */
1188
1189 /**
1190  * tf_alloc_tbl_entry parameter definition
1191  */
1192 struct tf_alloc_tbl_entry_parms {
1193         /**
1194          * [in] Receive or transmit direction
1195          */
1196         enum tf_dir dir;
1197         /**
1198          * [in] Type of the allocation
1199          */
1200         enum tf_tbl_type type;
1201         /**
1202          * [in] Table scope identifier (ignored unless TF_TBL_TYPE_EXT)
1203          */
1204         uint32_t tbl_scope_id;
1205         /**
1206          * [in] Enable search for matching entry. If the table type is
1207          * internal the shadow copy will be searched before
1208          * alloc. Session must be configured with shadow copy enabled.
1209          */
1210         uint8_t search_enable;
1211         /**
1212          * [in] Result data to search for (if search_enable)
1213          */
1214         uint8_t *result;
1215         /**
1216          * [in] Result data size in bytes (if search_enable)
1217          */
1218         uint16_t result_sz_in_bytes;
1219         /**
1220          * [out] If search_enable, set if matching entry found
1221          */
1222         uint8_t hit;
1223         /**
1224          * [out] Current ref count after allocation (if search_enable)
1225          */
1226         uint16_t ref_cnt;
1227         /**
1228          * [out] Idx of allocated entry or found entry (if search_enable)
1229          */
1230         uint32_t idx;
1231 };
1232
1233 /**
1234  * allocate index table entries
1235  *
1236  * Internal types:
1237  *
1238  * Allocate an on chip index table entry or search for a matching
1239  * entry of the indicated type for this TruFlow session.
1240  *
1241  * Allocates an index table record. This function will attempt to
1242  * allocate an entry or search an index table for a matching entry if
1243  * search is enabled (only the shadow copy of the table is accessed).
1244  *
1245  * If search is not enabled, the first available free entry is
1246  * returned. If search is enabled and a matching entry to entry_data
1247  * is found hit is set to TRUE and success is returned.
1248  *
1249  * External types:
1250  *
1251  * These are used to allocate inlined action record memory.
1252  *
1253  * Allocates an external index table action record.
1254  *
1255  * NOTE:
1256  * Implementation of the internals of this function will be a stack with push
1257  * and pop.
1258  *
1259  * Returns success or failure code.
1260  */
1261 int tf_alloc_tbl_entry(struct tf *tfp,
1262                        struct tf_alloc_tbl_entry_parms *parms);
1263
1264 /**
1265  * tf_free_tbl_entry parameter definition
1266  */
1267 struct tf_free_tbl_entry_parms {
1268         /**
1269          * [in] Receive or transmit direction
1270          */
1271         enum tf_dir dir;
1272         /**
1273          * [in] Type of the allocation type
1274          */
1275         enum tf_tbl_type type;
1276         /**
1277          * [in] Table scope identifier (ignored unless TF_TBL_TYPE_EXT)
1278          */
1279         uint32_t tbl_scope_id;
1280         /**
1281          * [in] Index to free
1282          */
1283         uint32_t idx;
1284         /**
1285          * [out] Reference count after free, only valid if session has been
1286          * created with shadow_copy.
1287          */
1288         uint16_t ref_cnt;
1289 };
1290
1291 /**
1292  * free index table entry
1293  *
1294  * Used to free a previously allocated table entry.
1295  *
1296  * Internal types:
1297  *
1298  * If session has shadow_copy enabled the shadow DB is searched and if
1299  * found the element ref_cnt is decremented. If ref_cnt goes to
1300  * zero then the element is returned to the session pool.
1301  *
1302  * If the session does not have a shadow DB the element is free'ed and
1303  * given back to the session pool.
1304  *
1305  * External types:
1306  *
1307  * Free's an external index table action record.
1308  *
1309  * NOTE:
1310  * Implementation of the internals of this function will be a stack with push
1311  * and pop.
1312  *
1313  * Returns success or failure code.
1314  */
1315 int tf_free_tbl_entry(struct tf *tfp,
1316                       struct tf_free_tbl_entry_parms *parms);
1317
1318 /**
1319  * tf_set_tbl_entry parameter definition
1320  */
1321 struct tf_set_tbl_entry_parms {
1322         /**
1323          * [in] Table scope identifier
1324          */
1325         uint32_t tbl_scope_id;
1326         /**
1327          * [in] Receive or transmit direction
1328          */
1329         enum tf_dir dir;
1330         /**
1331          * [in] Type of object to set
1332          */
1333         enum tf_tbl_type type;
1334         /**
1335          * [in] Entry data
1336          */
1337         uint8_t *data;
1338         /**
1339          * [in] Entry size
1340          */
1341         uint16_t data_sz_in_bytes;
1342         /**
1343          * [in] Entry index to write to
1344          */
1345         uint32_t idx;
1346 };
1347
1348 /**
1349  * set index table entry
1350  *
1351  * Used to insert an application programmed index table entry into a
1352  * previous allocated table location.  A shadow copy of the table
1353  * is maintained (if enabled) (only for internal objects)
1354  *
1355  * Returns success or failure code.
1356  */
1357 int tf_set_tbl_entry(struct tf *tfp,
1358                      struct tf_set_tbl_entry_parms *parms);
1359
1360 /**
1361  * tf_get_tbl_entry parameter definition
1362  */
1363 struct tf_get_tbl_entry_parms {
1364         /**
1365          * [in] Receive or transmit direction
1366          */
1367         enum tf_dir dir;
1368         /**
1369          * [in] Type of object to get
1370          */
1371         enum tf_tbl_type type;
1372         /**
1373          * [out] Entry data
1374          */
1375         uint8_t *data;
1376         /**
1377          * [in] Entry size
1378          */
1379         uint16_t data_sz_in_bytes;
1380         /**
1381          * [in] Entry index to read
1382          */
1383         uint32_t idx;
1384 };
1385
1386 /**
1387  * get index table entry
1388  *
1389  * Used to retrieve a previous set index table entry.
1390  *
1391  * Reads and compares with the shadow table copy (if enabled) (only
1392  * for internal objects).
1393  *
1394  * Returns success or failure code. Failure will be returned if the
1395  * provided data buffer is too small for the data type requested.
1396  */
1397 int tf_get_tbl_entry(struct tf *tfp,
1398                      struct tf_get_tbl_entry_parms *parms);
1399
1400 /**
1401  * tf_bulk_get_tbl_entry parameter definition
1402  */
1403 struct tf_bulk_get_tbl_entry_parms {
1404         /**
1405          * [in] Receive or transmit direction
1406          */
1407         enum tf_dir dir;
1408         /**
1409          * [in] Type of object to get
1410          */
1411         enum tf_tbl_type type;
1412         /**
1413          * [in] Starting index to read from
1414          */
1415         uint32_t starting_idx;
1416         /**
1417          * [in] Number of sequential entries
1418          */
1419         uint16_t num_entries;
1420         /**
1421          * [in] Size of the single entry
1422          */
1423         uint16_t entry_sz_in_bytes;
1424         /**
1425          * [out] Host physical address, where the data
1426          * will be copied to by the firmware.
1427          * Use tfp_calloc() API and mem_pa
1428          * variable of the tfp_calloc_parms
1429          * structure for the physical address.
1430          */
1431         uint64_t physical_mem_addr;
1432 };
1433
1434 /**
1435  * Bulk get index table entry
1436  *
1437  * Used to retrieve a set of index table entries.
1438  *
1439  * Entries within the range may not have been allocated using
1440  * tf_alloc_tbl_entry() at the time of access. But the range must
1441  * be within the bounds determined from tf_open_session() for the
1442  * given table type.  Currently, this is only used for collecting statistics.
1443  *
1444  * Returns success or failure code. Failure will be returned if the
1445  * provided data buffer is too small for the data type requested.
1446  */
1447 int tf_bulk_get_tbl_entry(struct tf *tfp,
1448                           struct tf_bulk_get_tbl_entry_parms *parms);
1449
1450 /**
1451  * @page exact_match Exact Match Table
1452  *
1453  * @ref tf_insert_em_entry
1454  *
1455  * @ref tf_delete_em_entry
1456  *
1457  * @ref tf_search_em_entry
1458  *
1459  */
1460 /**
1461  * tf_insert_em_entry parameter definition
1462  */
1463 struct tf_insert_em_entry_parms {
1464         /**
1465          * [in] receive or transmit direction
1466          */
1467         enum tf_dir dir;
1468         /**
1469          * [in] internal or external
1470          */
1471         enum tf_mem mem;
1472         /**
1473          * [in] ID of table scope to use (external only)
1474          */
1475         uint32_t tbl_scope_id;
1476         /**
1477          * [in] ID of table interface to use (SR2 only)
1478          */
1479         uint32_t tbl_if_id;
1480         /**
1481          * [in] ptr to structure containing key fields
1482          */
1483         uint8_t *key;
1484         /**
1485          * [in] key bit length
1486          */
1487         uint16_t key_sz_in_bits;
1488         /**
1489          * [in] ptr to structure containing result field
1490          */
1491         uint8_t *em_record;
1492         /**
1493          * [out] result size in bits
1494          */
1495         uint16_t em_record_sz_in_bits;
1496         /**
1497          * [in] duplicate check flag
1498          */
1499         uint8_t dup_check;
1500         /**
1501          * [out] Flow handle value for the inserted entry.  This is encoded
1502          * as the entries[4]:bucket[2]:hashId[1]:hash[14]
1503          */
1504         uint64_t flow_handle;
1505         /**
1506          * [out] Flow id is returned as null (internal)
1507          * Flow id is the GFID value for the inserted entry (external)
1508          * This is the value written to the BD and useful information for mark.
1509          */
1510         uint64_t flow_id;
1511 };
1512 /**
1513  * tf_delete_em_entry parameter definition
1514  */
1515 struct tf_delete_em_entry_parms {
1516         /**
1517          * [in] receive or transmit direction
1518          */
1519         enum tf_dir dir;
1520         /**
1521          * [in] internal or external
1522          */
1523         enum tf_mem mem;
1524         /**
1525          * [in] ID of table scope to use (external only)
1526          */
1527         uint32_t tbl_scope_id;
1528         /**
1529          * [in] ID of table interface to use (SR2 only)
1530          */
1531         uint32_t tbl_if_id;
1532         /**
1533          * [in] epoch group IDs of entry to delete
1534          * 2 element array with 2 ids. (SR2 only)
1535          */
1536         uint16_t *epochs;
1537         /**
1538          * [out] The index of the entry
1539          */
1540         uint16_t index;
1541         /**
1542          * [in] structure containing flow delete handle information
1543          */
1544         uint64_t flow_handle;
1545 };
1546 /**
1547  * tf_search_em_entry parameter definition
1548  */
1549 struct tf_search_em_entry_parms {
1550         /**
1551          * [in] receive or transmit direction
1552          */
1553         enum tf_dir dir;
1554         /**
1555          * [in] internal or external
1556          */
1557         enum tf_mem mem;
1558         /**
1559          * [in] ID of table scope to use (external only)
1560          */
1561         uint32_t tbl_scope_id;
1562         /**
1563          * [in] ID of table interface to use (SR2 only)
1564          */
1565         uint32_t tbl_if_id;
1566         /**
1567          * [in] ptr to structure containing key fields
1568          */
1569         uint8_t *key;
1570         /**
1571          * [in] key bit length
1572          */
1573         uint16_t key_sz_in_bits;
1574         /**
1575          * [in/out] ptr to structure containing EM record fields
1576          */
1577         uint8_t *em_record;
1578         /**
1579          * [out] result size in bits
1580          */
1581         uint16_t em_record_sz_in_bits;
1582         /**
1583          * [in] epoch group IDs of entry to lookup
1584          * 2 element array with 2 ids. (SR2 only)
1585          */
1586         uint16_t *epochs;
1587         /**
1588          * [in] ptr to structure containing flow delete handle
1589          */
1590         uint64_t flow_handle;
1591 };
1592
1593 /**
1594  * insert em hash entry in internal table memory
1595  *
1596  * Internal:
1597  *
1598  * This API inserts an exact match entry into internal EM table memory
1599  * of the specified direction.
1600  *
1601  * Note: The EM record is managed within the TruFlow core and not the
1602  * application.
1603  *
1604  * Shadow copy of internal record table an association with hash and 1,2, or 4
1605  * associated buckets
1606  *
1607  * External:
1608  * This API inserts an exact match entry into DRAM EM table memory of the
1609  * specified direction and table scope.
1610  *
1611  * When inserting an entry into an exact match table, the TruFlow library may
1612  * need to allocate a dynamic bucket for the entry (SR2 only).
1613  *
1614  * The insertion of duplicate entries in an EM table is not permitted.  If a
1615  * TruFlow application can guarantee that it will never insert duplicates, it
1616  * can disable duplicate checking by passing a zero value in the  dup_check
1617  * parameter to this API.  This will optimize performance. Otherwise, the
1618  * TruFlow library will enforce protection against inserting duplicate entries.
1619  *
1620  * Flow handle is defined in this document:
1621  *
1622  * https://docs.google.com
1623  * /document/d/1NESu7RpTN3jwxbokaPfYORQyChYRmJgs40wMIRe8_-Q/edit
1624  *
1625  * Returns success or busy code.
1626  *
1627  */
1628 int tf_insert_em_entry(struct tf *tfp,
1629                        struct tf_insert_em_entry_parms *parms);
1630
1631 /**
1632  * delete em hash entry table memory
1633  *
1634  * Internal:
1635  *
1636  * This API deletes an exact match entry from internal EM table memory of the
1637  * specified direction. If a valid flow ptr is passed in then that takes
1638  * precedence over the pointer to the complete key passed in.
1639  *
1640  *
1641  * External:
1642  *
1643  * This API deletes an exact match entry from EM table memory of the specified
1644  * direction and table scope. If a valid flow handle is passed in then that
1645  * takes precedence over the pointer to the complete key passed in.
1646  *
1647  * The TruFlow library may release a dynamic bucket when an entry is deleted.
1648  *
1649  *
1650  * Returns success or not found code
1651  *
1652  *
1653  */
1654 int tf_delete_em_entry(struct tf *tfp,
1655                        struct tf_delete_em_entry_parms *parms);
1656
1657 /**
1658  * search em hash entry table memory
1659  *
1660  * Internal:
1661
1662  * This API looks up an EM entry in table memory with the specified EM
1663  * key or flow (flow takes precedence) and direction.
1664  *
1665  * The status will be one of: success or entry not found.  If the lookup
1666  * succeeds, a pointer to the matching entry and the result record associated
1667  * with the matching entry will be provided.
1668  *
1669  * If flow_handle is set, search shadow copy.
1670  *
1671  * Otherwise, query the fw with key to get result.
1672  *
1673  * External:
1674  *
1675  * This API looks up an EM entry in table memory with the specified EM
1676  * key or flow_handle (flow takes precedence), direction and table scope.
1677  *
1678  * The status will be one of: success or entry not found.  If the lookup
1679  * succeeds, a pointer to the matching entry and the result record associated
1680  * with the matching entry will be provided.
1681  *
1682  * Returns success or not found code
1683  *
1684  */
1685 int tf_search_em_entry(struct tf *tfp,
1686                        struct tf_search_em_entry_parms *parms);
1687
1688 /**
1689  * @page global Global Configuration
1690  *
1691  * @ref tf_set_global_cfg
1692  *
1693  * @ref tf_get_global_cfg
1694  */
1695 /**
1696  * Tunnel Encapsulation Offsets
1697  */
1698 enum tf_tunnel_encap_offsets {
1699         TF_TUNNEL_ENCAP_L2,
1700         TF_TUNNEL_ENCAP_NAT,
1701         TF_TUNNEL_ENCAP_MPLS,
1702         TF_TUNNEL_ENCAP_VXLAN,
1703         TF_TUNNEL_ENCAP_GENEVE,
1704         TF_TUNNEL_ENCAP_NVGRE,
1705         TF_TUNNEL_ENCAP_GRE,
1706         TF_TUNNEL_ENCAP_FULL_GENERIC
1707 };
1708 /**
1709  * Global Configuration Table Types
1710  */
1711 enum tf_global_config_type {
1712         TF_TUNNEL_ENCAP,  /**< Tunnel Encap Config(TECT) */
1713         TF_ACTION_BLOCK,  /**< Action Block Config(ABCR) */
1714         TF_GLOBAL_CFG_TYPE_MAX
1715 };
1716
1717 /**
1718  * tf_global_cfg parameter definition
1719  */
1720 struct tf_global_cfg_parms {
1721         /**
1722          * [in] receive or transmit direction
1723          */
1724         enum tf_dir dir;
1725         /**
1726          * [in] Global config type
1727          */
1728         enum tf_global_config_type type;
1729         /**
1730          * [in] Offset @ the type
1731          */
1732         uint32_t offset;
1733         /**
1734          * [in/out] Value of the configuration
1735          * set - Read, Modify and Write
1736          * get - Read the full configuration
1737          */
1738         uint8_t *config;
1739         /**
1740          * [in] struct containing size
1741          */
1742         uint16_t config_sz_in_bytes;
1743 };
1744
1745 /**
1746  * Get global configuration
1747  *
1748  * Retrieve the configuration
1749  *
1750  * Returns success or failure code.
1751  */
1752 int tf_get_global_cfg(struct tf *tfp,
1753                       struct tf_global_cfg_parms *parms);
1754
1755 /**
1756  * Update the global configuration table
1757  *
1758  * Read, modify write the value.
1759  *
1760  * Returns success or failure code.
1761  */
1762 int tf_set_global_cfg(struct tf *tfp,
1763                       struct tf_global_cfg_parms *parms);
1764
1765 /**
1766  * @page if_tbl Interface Table Access
1767  *
1768  * @ref tf_set_if_tbl_entry
1769  *
1770  * @ref tf_get_if_tbl_entry
1771  *
1772  * @ref tf_restore_if_tbl_entry
1773  */
1774 /**
1775  * Enumeration of TruFlow interface table types.
1776  */
1777 enum tf_if_tbl_type {
1778         /** Default Profile L2 Context Entry */
1779         TF_IF_TBL_TYPE_PROF_SPIF_DFLT_L2_CTXT,
1780         /** Default Profile TCAM/Lookup Action Record Pointer Table */
1781         TF_IF_TBL_TYPE_PROF_PARIF_DFLT_ACT_REC_PTR,
1782         /** Error Profile TCAM Miss Action Record Pointer Table */
1783         TF_IF_TBL_TYPE_PROF_PARIF_ERR_ACT_REC_PTR,
1784         /** Default Error Profile TCAM Miss Action Record Pointer Table */
1785         TF_IF_TBL_TYPE_LKUP_PARIF_DFLT_ACT_REC_PTR,
1786         /** SR2 Ingress lookup table */
1787         TF_IF_TBL_TYPE_ILT,
1788         /** SR2 VNIC/SVIF Table */
1789         TF_IF_TBL_TYPE_VNIC_SVIF,
1790         TF_IF_TBL_TYPE_MAX
1791 };
1792
1793 /**
1794  * tf_set_if_tbl_entry parameter definition
1795  */
1796 struct tf_set_if_tbl_entry_parms {
1797         /**
1798          * [in] Receive or transmit direction
1799          */
1800         enum tf_dir dir;
1801         /**
1802          * [in] Type of object to set
1803          */
1804         enum tf_if_tbl_type type;
1805         /**
1806          * [in] Entry data
1807          */
1808         uint8_t *data;
1809         /**
1810          * [in] Entry size
1811          */
1812         uint16_t data_sz_in_bytes;
1813         /**
1814          * [in] Interface to write
1815          */
1816         uint32_t idx;
1817 };
1818
1819 /**
1820  * set interface table entry
1821  *
1822  * Used to set an interface table. This API is used for managing tables indexed
1823  * by SVIF/SPIF/PARIF interfaces. In current implementation only the value is
1824  * set.
1825  * Returns success or failure code.
1826  */
1827 int tf_set_if_tbl_entry(struct tf *tfp,
1828                         struct tf_set_if_tbl_entry_parms *parms);
1829
1830 /**
1831  * tf_get_if_tbl_entry parameter definition
1832  */
1833 struct tf_get_if_tbl_entry_parms {
1834         /**
1835          * [in] Receive or transmit direction
1836          */
1837         enum tf_dir dir;
1838         /**
1839          * [in] Type of table to get
1840          */
1841         enum tf_if_tbl_type type;
1842         /**
1843          * [out] Entry data
1844          */
1845         uint8_t *data;
1846         /**
1847          * [in] Entry size
1848          */
1849         uint16_t data_sz_in_bytes;
1850         /**
1851          * [in] Entry index to read
1852          */
1853         uint32_t idx;
1854 };
1855
1856 /**
1857  * get interface table entry
1858  *
1859  * Used to retrieve an interface table entry.
1860  *
1861  * Reads the interface table entry value
1862  *
1863  * Returns success or failure code. Failure will be returned if the
1864  * provided data buffer is too small for the data type requested.
1865  */
1866 int tf_get_if_tbl_entry(struct tf *tfp,
1867                         struct tf_get_if_tbl_entry_parms *parms);
1868
1869 #endif /* _TF_CORE_H_ */