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