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