81ff7602fe8a7b3f57fe02e322e65ff441afe325
[dpdk.git] / drivers / net / bnxt / tf_core / tf_core.h
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2019-2020 Broadcom
3  * All rights reserved.
4  */
5
6 #ifndef _TF_CORE_H_
7 #define _TF_CORE_H_
8
9 #include <stdint.h>
10 #include <stdlib.h>
11 #include <stdbool.h>
12 #include <stdio.h>
13
14 #include "tf_project.h"
15
16 /**
17  * @file
18  *
19  * Truflow Core API Header File
20  */
21
22 /********** BEGIN Truflow Core DEFINITIONS **********/
23
24
25 #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  * Helper Macros
59  */
60 #define TF_BITS_2_BYTES(num_bits) (((num_bits) + 7) / 8)
61
62 /********** BEGIN API FUNCTION PROTOTYPES/PARAMETERS **********/
63
64 /**
65  * @page general General
66  *
67  * @ref tf_open_session
68  *
69  * @ref tf_attach_session
70  *
71  * @ref tf_close_session
72  */
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 Version
117  *
118  * The version controls the format of the tf_session and
119  * tf_session_info structure. This is to assure upgrade between
120  * versions can be supported.
121  *
122  * Please see the TF_VER_MAJOR/MINOR and UPDATE defines.
123  */
124 struct tf_session_version {
125         uint8_t major;
126         uint8_t minor;
127         uint8_t update;
128 };
129
130 /**
131  * Session supported device types
132  */
133 enum tf_device_type {
134         TF_DEVICE_TYPE_WH = 0, /**< Whitney+  */
135         TF_DEVICE_TYPE_BRD2,   /**< TBD       */
136         TF_DEVICE_TYPE_BRD3,   /**< TBD       */
137         TF_DEVICE_TYPE_BRD4,   /**< TBD       */
138         TF_DEVICE_TYPE_MAX     /**< Maximum   */
139 };
140
141 /** Identifier resource types
142  */
143 enum tf_identifier_type {
144         /** The L2 Context is returned from the L2 Ctxt TCAM lookup
145          *  and can be used in WC TCAM or EM keys to virtualize further
146          *  lookups.
147          */
148         TF_IDENT_TYPE_L2_CTXT,
149         /** The WC profile func is returned from the L2 Ctxt TCAM lookup
150          *  to enable virtualization of the profile TCAM.
151          */
152         TF_IDENT_TYPE_PROF_FUNC,
153         /** The WC profile ID is included in the WC lookup key
154          *  to enable virtualization of the WC TCAM hardware.
155          */
156         TF_IDENT_TYPE_WC_PROF,
157         /** The EM profile ID is included in the EM lookup key
158          *  to enable virtualization of the EM hardware. (not required for SR2
159          *  as it has table scope)
160          */
161         TF_IDENT_TYPE_EM_PROF,
162         /** The L2 func is included in the ILT result and from recycling to
163          *  enable virtualization of further lookups.
164          */
165         TF_IDENT_TYPE_L2_FUNC,
166         TF_IDENT_TYPE_MAX
167 };
168
169 /**
170  * Enumeration of TruFlow table types. A table type is used to identify a
171  * resource object.
172  *
173  * NOTE: The table type TF_TBL_TYPE_EXT is unique in that it is
174  * the only table type that is connected with a table scope.
175  */
176 enum tf_tbl_type {
177         /* Internal */
178
179         /** Wh+/SR Action Record */
180         TF_TBL_TYPE_FULL_ACT_RECORD,
181         /** Wh+/SR/Th Multicast Groups */
182         TF_TBL_TYPE_MCAST_GROUPS,
183         /** Wh+/SR Action Encap 8 Bytes */
184         TF_TBL_TYPE_ACT_ENCAP_8B,
185         /** Wh+/SR Action Encap 16 Bytes */
186         TF_TBL_TYPE_ACT_ENCAP_16B,
187         /** Action Encap 32 Bytes */
188         TF_TBL_TYPE_ACT_ENCAP_32B,
189         /** Wh+/SR Action Encap 64 Bytes */
190         TF_TBL_TYPE_ACT_ENCAP_64B,
191         /** Action Source Properties SMAC */
192         TF_TBL_TYPE_ACT_SP_SMAC,
193         /** Wh+/SR Action Source Properties SMAC IPv4 */
194         TF_TBL_TYPE_ACT_SP_SMAC_IPV4,
195         /** Action Source Properties SMAC IPv6 */
196         TF_TBL_TYPE_ACT_SP_SMAC_IPV6,
197         /** Wh+/SR Action Statistics 64 Bits */
198         TF_TBL_TYPE_ACT_STATS_64,
199         /** Wh+/SR Action Modify L4 Src Port */
200         TF_TBL_TYPE_ACT_MODIFY_SPORT,
201         /** Wh+/SR Action Modify L4 Dest Port */
202         TF_TBL_TYPE_ACT_MODIFY_DPORT,
203         /** Wh+/SR Action Modify IPv4 Source */
204         TF_TBL_TYPE_ACT_MODIFY_IPV4_SRC,
205         /** Wh+/SR Action _Modify L4 Dest Port */
206         TF_TBL_TYPE_ACT_MODIFY_IPV4_DEST,
207         /** Action Modify IPv6 Source */
208         TF_TBL_TYPE_ACT_MODIFY_IPV6_SRC,
209         /** Action Modify IPv6 Destination */
210         TF_TBL_TYPE_ACT_MODIFY_IPV6_DEST,
211         /** Meter Profiles */
212         TF_TBL_TYPE_METER_PROF,
213         /** Meter Instance */
214         TF_TBL_TYPE_METER_INST,
215         /** Mirror Config */
216         TF_TBL_TYPE_MIRROR_CONFIG,
217         /** UPAR */
218         TF_TBL_TYPE_UPAR,
219         /** SR2 Epoch 0 table */
220         TF_TBL_TYPE_EPOCH0,
221         /** SR2 Epoch 1 table  */
222         TF_TBL_TYPE_EPOCH1,
223         /** SR2 Metadata  */
224         TF_TBL_TYPE_METADATA,
225         /** SR2 CT State  */
226         TF_TBL_TYPE_CT_STATE,
227         /** SR2 Range Profile  */
228         TF_TBL_TYPE_RANGE_PROF,
229         /** SR2 Range Entry  */
230         TF_TBL_TYPE_RANGE_ENTRY,
231         /** SR2 LAG Entry  */
232         TF_TBL_TYPE_LAG,
233         /** SR2 VNIC/SVIF Table */
234         TF_TBL_TYPE_VNIC_SVIF,
235         /** Th/SR2 EM Flexible Key builder */
236         TF_TBL_TYPE_EM_FKB,
237         /** Th/SR2 WC Flexible Key builder */
238         TF_TBL_TYPE_WC_FKB,
239
240         /* External */
241
242         /** External table type - initially 1 poolsize entries.
243          * All External table types are associated with a table
244          * scope. Internal types are not.
245          */
246         TF_TBL_TYPE_EXT,
247         TF_TBL_TYPE_MAX
248 };
249
250 /**
251  * TCAM table type
252  */
253 enum tf_tcam_tbl_type {
254         /** L2 Context TCAM */
255         TF_TCAM_TBL_TYPE_L2_CTXT_TCAM,
256         /** Profile TCAM */
257         TF_TCAM_TBL_TYPE_PROF_TCAM,
258         /** Wildcard TCAM */
259         TF_TCAM_TBL_TYPE_WC_TCAM,
260         /** Source Properties TCAM */
261         TF_TCAM_TBL_TYPE_SP_TCAM,
262         /** Connection Tracking Rule TCAM */
263         TF_TCAM_TBL_TYPE_CT_RULE_TCAM,
264         /** Virtual Edge Bridge TCAM */
265         TF_TCAM_TBL_TYPE_VEB_TCAM,
266         TF_TCAM_TBL_TYPE_MAX
267 };
268
269 /**
270  * EM Resources
271  * These defines are provisioned during
272  * tf_open_session()
273  */
274 enum tf_em_tbl_type {
275         /** The number of internal EM records for the session */
276         TF_EM_TBL_TYPE_EM_RECORD,
277         /** The number of table scopes reequested */
278         TF_EM_TBL_TYPE_TBL_SCOPE,
279         TF_EM_TBL_TYPE_MAX
280 };
281
282 /** TruFlow Session Information
283  *
284  * Structure defining a TruFlow Session, also known as a Management
285  * session. This structure is initialized at time of
286  * tf_open_session(). It is passed to all of the TruFlow APIs as way
287  * to prescribe and isolate resources between different TruFlow ULP
288  * Applications.
289  */
290 struct tf_session_info {
291         /**
292          * TrueFlow Version. Used to control the structure layout when
293          * sharing sessions. No guarantee that a secondary process
294          * would come from the same version of an executable.
295          * TruFlow initializes this variable on tf_open_session().
296          *
297          * Owner:  TruFlow
298          * Access: TruFlow
299          */
300         struct tf_session_version ver;
301         /**
302          * will be STAILQ_ENTRY(tf_session_info) next
303          *
304          * Owner:  ULP
305          * Access: ULP
306          */
307         void                 *next;
308         /**
309          * Session ID is a unique identifier for the session. TruFlow
310          * initializes this variable during tf_open_session()
311          * processing.
312          *
313          * Owner:  TruFlow
314          * Access: Truflow & ULP
315          */
316         union tf_session_id   session_id;
317         /**
318          * Protects access to core_data. Lock is initialized and owned
319          * by ULP. TruFlow can access the core_data without checking
320          * the lock.
321          *
322          * Owner:  ULP
323          * Access: ULP
324          */
325         uint8_t               spin_lock;
326         /**
327          * The core_data holds the TruFlow tf_session data
328          * structure. This memory is allocated and owned by TruFlow on
329          * tf_open_session().
330          *
331          * TruFlow uses this memory for session management control
332          * until the session is closed by ULP. Access control is done
333          * by the spin_lock which ULP controls ahead of TruFlow API
334          * calls.
335          *
336          * Please see tf_open_session_parms for specification details
337          * on this variable.
338          *
339          * Owner:  TruFlow
340          * Access: TruFlow
341          */
342         void                 *core_data;
343         /**
344          * The core_data_sz_bytes specifies the size of core_data in
345          * bytes.
346          *
347          * The size is set by TruFlow on tf_open_session().
348          *
349          * Please see tf_open_session_parms for specification details
350          * on this variable.
351          *
352          * Owner:  TruFlow
353          * Access: TruFlow
354          */
355         uint32_t              core_data_sz_bytes;
356 };
357
358 /** TruFlow handle
359  *
360  * Contains a pointer to the session info. Allocated by ULP and passed
361  * to TruFlow using tf_open_session(). TruFlow will populate the
362  * session info at that time. Additional 'opens' can be done using
363  * same session_info by using tf_attach_session().
364  *
365  * It is expected that ULP allocates this memory as shared memory.
366  *
367  * NOTE: This struct must be within the BNXT PMD struct bnxt
368  *       (bp). This allows use of container_of() to get access to the PMD.
369  */
370 struct tf {
371         struct tf_session_info *session;
372 };
373
374
375 /**
376  * tf_open_session parameters definition.
377  */
378 struct tf_open_session_parms {
379         /** [in] ctrl_chan_name
380          *
381          * String containing name of control channel interface to be
382          * used for this session to communicate with firmware.
383          *
384          * The ctrl_chan_name can be looked up by using
385          * rte_eth_dev_get_name_by_port() within the ULP.
386          *
387          * ctrl_chan_name will be used as part of a name for any
388          * shared memory allocation.
389          */
390         char ctrl_chan_name[TF_SESSION_NAME_MAX];
391         /** [in] shadow_copy
392          *
393          * Boolean controlling the use and availability of shadow
394          * copy. Shadow copy will allow the TruFlow to keep track of
395          * resource content on the firmware side without having to
396          * query firmware. Additional private session core_data will
397          * be allocated if this boolean is set to 'true', default
398          * 'false'.
399          *
400          * Size of memory depends on the NVM Resource settings for the
401          * control channel.
402          */
403         bool shadow_copy;
404         /** [in/out] session_id
405          *
406          * Session_id is unique per session.
407          *
408          * Session_id is composed of domain, bus, device and
409          * fw_session_id. The construction is done by parsing the
410          * ctrl_chan_name together with allocation of a fw_session_id.
411          *
412          * The session_id allows a session to be shared between devices.
413          */
414         union tf_session_id session_id;
415         /** [in] device type
416          *
417          * Device type is passed, one of Wh+, Brd2, Brd3, Brd4
418          */
419         enum tf_device_type device_type;
420         /** [in] Requested Identifier Resources
421          *
422          * The number of identifier resources requested for the session.
423          * The index used is tf_identifier_type.
424          */
425         uint16_t identifer_cnt[TF_IDENT_TYPE_MAX];
426         /** [in] Requested Index Table resource counts
427          *
428          * The number of index table resources requested for the session.
429          * The index used is tf_tbl_type.
430          */
431         uint16_t tbl_cnt[TF_TBL_TYPE_MAX];
432         /** [in] Requested TCAM Table resource counts
433          *
434          * The number of TCAM table resources requested for the session.
435          * The index used is tf_tcam_tbl_type.
436          */
437         uint16_t tcam_tbl_cnt[TF_TCAM_TBL_TYPE_MAX];
438         /** [in] Requested EM resource counts
439          *
440          * The number of internal EM table resources requested for the session
441          * The index used is tf_em_tbl_type.
442          */
443         uint16_t em_tbl_cnt[TF_EM_TBL_TYPE_MAX];
444 };
445
446 /**
447  * Opens a new TruFlow management session.
448  *
449  * TruFlow will allocate session specific memory, shared memory, to
450  * hold its session data. This data is private to TruFlow.
451  *
452  * Multiple PFs can share the same session. An association, refcount,
453  * between session and PFs is maintained within TruFlow. Thus, a PF
454  * can attach to an existing session, see tf_attach_session().
455  *
456  * No other TruFlow APIs will succeed unless this API is first called and
457  * succeeds.
458  *
459  * tf_open_session() returns a session id that can be used on attach.
460  *
461  * [in] tfp
462  *   Pointer to TF handle
463  * [in] parms
464  *   Pointer to open parameters
465  *
466  * Returns
467  *   - (0) if successful.
468  *   - (-EINVAL) on failure.
469  */
470 int tf_open_session(struct tf *tfp,
471                     struct tf_open_session_parms *parms);
472
473 struct tf_attach_session_parms {
474         /** [in] ctrl_chan_name
475          *
476          * String containing name of control channel interface to be
477          * used for this session to communicate with firmware.
478          *
479          * The ctrl_chan_name can be looked up by using
480          * rte_eth_dev_get_name_by_port() within the ULP.
481          *
482          * ctrl_chan_name will be used as part of a name for any
483          * shared memory allocation.
484          */
485         char ctrl_chan_name[TF_SESSION_NAME_MAX];
486
487         /** [in] attach_chan_name
488          *
489          * String containing name of attach channel interface to be
490          * used for this session.
491          *
492          * The attach_chan_name must be given to a 2nd process after
493          * the primary process has been created. This is the
494          * ctrl_chan_name of the primary process and is used to find
495          * the shared memory for the session that the attach is going
496          * to use.
497          */
498         char attach_chan_name[TF_SESSION_NAME_MAX];
499
500         /** [in] session_id
501          *
502          * Session_id is unique per session. For Attach the session_id
503          * should be the session_id that was returned on the first
504          * open.
505          *
506          * Session_id is composed of domain, bus, device and
507          * fw_session_id. The construction is done by parsing the
508          * ctrl_chan_name together with allocation of a fw_session_id
509          * during tf_open_session().
510          *
511          * A reference count will be incremented on attach. A session
512          * is first fully closed when reference count is zero by
513          * calling tf_close_session().
514          */
515         union tf_session_id session_id;
516 };
517
518 /**
519  * Attaches to an existing session. Used when more than one PF wants
520  * to share a single session. In that case all TruFlow management
521  * traffic will be sent to the TruFlow firmware using the 'PF' that
522  * did the attach not the session ctrl channel.
523  *
524  * Attach will increment a ref count as to manage the shared session data.
525  *
526  * [in] tfp, pointer to TF handle
527  * [in] parms, pointer to attach parameters
528  *
529  * Returns
530  *   - (0) if successful.
531  *   - (-EINVAL) on failure.
532  */
533 int tf_attach_session(struct tf *tfp,
534                       struct tf_attach_session_parms *parms);
535
536 /**
537  * Closes an existing session. Cleans up all hardware and firmware
538  * state associated with the TruFlow application session when the last
539  * PF associated with the session results in refcount to be zero.
540  *
541  * Returns success or failure code.
542  */
543 int tf_close_session(struct tf *tfp);
544
545 /**
546  * @page  ident Identity Management
547  *
548  * @ref tf_alloc_identifier
549  *
550  * @ref tf_free_identifier
551  */
552 /** tf_alloc_identifier parameter definition
553  */
554 struct tf_alloc_identifier_parms {
555         /**
556          * [in]  receive or transmit direction
557          */
558         enum tf_dir dir;
559         /**
560          * [in] Identifier type
561          */
562         enum tf_identifier_type ident_type;
563         /**
564          * [out] Identifier allocated
565          */
566         uint16_t id;
567 };
568
569 /** tf_free_identifier parameter definition
570  */
571 struct tf_free_identifier_parms {
572         /**
573          * [in]  receive or transmit direction
574          */
575         enum tf_dir dir;
576         /**
577          * [in] Identifier type
578          */
579         enum tf_identifier_type ident_type;
580         /**
581          * [in] ID to free
582          */
583         uint16_t id;
584 };
585
586 /** allocate identifier resource
587  *
588  * TruFlow core will allocate a free id from the per identifier resource type
589  * pool reserved for the session during tf_open().  No firmware is involved.
590  *
591  * Returns success or failure code.
592  */
593 int tf_alloc_identifier(struct tf *tfp,
594                         struct tf_alloc_identifier_parms *parms);
595
596 /** free identifier resource
597  *
598  * TruFlow core will return an id back to the per identifier resource type pool
599  * reserved for the session.  No firmware is involved.  During tf_close, the
600  * complete pool is returned to the firmware.
601  *
602  * Returns success or failure code.
603  */
604 int tf_free_identifier(struct tf *tfp,
605                        struct tf_free_identifier_parms *parms);
606
607 /**
608  * @page dram_table DRAM Table Scope Interface
609  *
610  * @ref tf_alloc_tbl_scope
611  *
612  * @ref tf_free_tbl_scope
613  *
614  * If we allocate the EEM memory from the core, we need to store it in
615  * the shared session data structure to make sure it can be freed later.
616  * (for example if the PF goes away)
617  *
618  * Current thought is that memory is allocated within core.
619  */
620
621
622 /** tf_alloc_tbl_scope_parms definition
623  */
624 struct tf_alloc_tbl_scope_parms {
625         /**
626          * [in] All Maximum key size required.
627          */
628         uint16_t rx_max_key_sz_in_bits;
629         /**
630          * [in] Maximum Action size required (includes inlined items)
631          */
632         uint16_t rx_max_action_entry_sz_in_bits;
633         /**
634          * [in] Memory size in Megabytes
635          * Total memory size allocated by user to be divided
636          * up for actions, hash, counters.  Only inline external actions.
637          * Use this variable or the number of flows, do not set both.
638          */
639         uint32_t rx_mem_size_in_mb;
640         /**
641          * [in] Number of flows * 1000. If set, rx_mem_size_in_mb must equal 0.
642          */
643         uint32_t rx_num_flows_in_k;
644         /**
645          * [in] Brd4 only receive table access interface id
646          */
647         uint32_t rx_tbl_if_id;
648         /**
649          * [in] All Maximum key size required.
650          */
651         uint16_t tx_max_key_sz_in_bits;
652         /**
653          * [in] Maximum Action size required (includes inlined items)
654          */
655         uint16_t tx_max_action_entry_sz_in_bits;
656         /**
657          * [in] Memory size in Megabytes
658          * Total memory size allocated by user to be divided
659          * up for actions, hash, counters.  Only inline external actions.
660          */
661         uint32_t tx_mem_size_in_mb;
662         /**
663          * [in] Number of flows * 1000
664          */
665         uint32_t tx_num_flows_in_k;
666         /**
667          * [in] Brd4 only receive table access interface id
668          */
669         uint32_t tx_tbl_if_id;
670         /**
671          * [in] Flush pending HW cached flows every 1/10th of value
672          * set in seconds, both idle and active flows are flushed
673          * from the HW cache. If set to 0, this feature will be disabled.
674          */
675         uint8_t hw_flow_cache_flush_timer;
676         /**
677          * [out] table scope identifier
678          */
679         uint32_t tbl_scope_id;
680 };
681
682 struct tf_free_tbl_scope_parms {
683         /**
684          * [in] table scope identifier
685          */
686         uint32_t tbl_scope_id;
687 };
688
689 /**
690  * allocate a table scope
691  *
692  * On Brd4 Firmware will allocate a scope ID.  On other devices, the scope
693  * is a software construct to identify an EEM table.  This function will
694  * divide the hash memory/buckets and records according to the device
695  * device constraints based upon calculations using either the number of flows
696  * requested or the size of memory indicated.  Other parameters passed in
697  * determine the configuration (maximum key size, maximum external action record
698  * size.
699  *
700  * This API will allocate the table region in
701  * DRAM, program the PTU page table entries, and program the number of static
702  * buckets (if Brd4) in the RX and TX CFAs.  Buckets are assumed to start at
703  * 0 in the EM memory for the scope.  Upon successful completion of this API,
704  * hash tables are fully initialized and ready for entries to be inserted.
705  *
706  * A single API is used to allocate a common table scope identifier in both
707  * receive and transmit CFA. The scope identifier is common due to nature of
708  * connection tracking sending notifications between RX and TX direction.
709  *
710  * The receive and transmit table access identifiers specify which rings will
711  * be used to initialize table DRAM.  The application must ensure mutual
712  * exclusivity of ring usage for table scope allocation and any table update
713  * operations.
714  *
715  * The hash table buckets, EM keys, and EM lookup results are stored in the
716  * memory allocated based on the rx_em_hash_mb/tx_em_hash_mb parameters.  The
717  * hash table buckets are stored at the beginning of that memory.
718  *
719  * NOTE:  No EM internal setup is done here. On chip EM records are managed
720  * internally by TruFlow core.
721  *
722  * Returns success or failure code.
723  */
724 int tf_alloc_tbl_scope(struct tf *tfp,
725                        struct tf_alloc_tbl_scope_parms *parms);
726
727
728 /**
729  * free a table scope
730  *
731  * Firmware checks that the table scope ID is owned by the TruFlow
732  * session, verifies that no references to this table scope remains
733  * (Brd4 ILT) or Profile TCAM entries for either CFA (RX/TX) direction,
734  * then frees the table scope ID.
735  *
736  * Returns success or failure code.
737  */
738 int tf_free_tbl_scope(struct tf *tfp,
739                       struct tf_free_tbl_scope_parms *parms);
740
741
742 /**
743  * @page tcam TCAM Access
744  *
745  * @ref tf_alloc_tcam_entry
746  *
747  * @ref tf_set_tcam_entry
748  *
749  * @ref tf_get_tcam_entry
750  *
751  * @ref tf_free_tcam_entry
752  */
753
754 /** tf_alloc_tcam_entry parameter definition
755  */
756 struct tf_alloc_tcam_entry_parms {
757         /**
758          * [in] receive or transmit direction
759          */
760         enum tf_dir dir;
761         /**
762          * [in] TCAM table type
763          */
764         enum tf_tcam_tbl_type tcam_tbl_type;
765         /**
766          * [in] Enable search for matching entry
767          */
768         uint8_t search_enable;
769         /**
770          * [in] Key data to match on (if search)
771          */
772         uint8_t *key;
773         /**
774          * [in] key size in bits (if search)
775          */
776         uint16_t key_sz_in_bits;
777         /**
778          * [in] Mask data to match on (if search)
779          */
780         uint8_t *mask;
781         /**
782          * [in] Priority of entry requested (definition TBD)
783          */
784         uint32_t priority;
785         /**
786          * [out] If search, set if matching entry found
787          */
788         uint8_t hit;
789         /**
790          * [out] Current refcnt after allocation
791          */
792         uint16_t ref_cnt;
793         /**
794          * [out] Idx allocated
795          *
796          */
797         uint16_t idx;
798 };
799
800 /** allocate TCAM entry
801  *
802  * Allocate a TCAM entry - one of these types:
803  *
804  * L2 Context
805  * Profile TCAM
806  * WC TCAM
807  * VEB TCAM
808  *
809  * This function allocates a TCAM table record.  This function
810  * will attempt to allocate a TCAM table entry from the session
811  * owned TCAM entries or search a shadow copy of the TCAM table for a
812  * matching entry if search is enabled.  Key, mask and result must match for
813  * hit to be set.  Only TruFlow core data is accessed.
814  * A hash table to entry mapping is maintained for search purposes.  If
815  * search is not enabled, the first available free entry is returned based
816  * on priority and alloc_cnt is set to 1.  If search is enabled and a matching
817  * entry to entry_data is found, hit is set to TRUE and alloc_cnt is set to 1.
818  * RefCnt is also returned.
819  *
820  * Also returns success or failure code.
821  */
822 int tf_alloc_tcam_entry(struct tf *tfp,
823                         struct tf_alloc_tcam_entry_parms *parms);
824
825 /** tf_set_tcam_entry parameter definition
826  */
827 struct  tf_set_tcam_entry_parms {
828         /**
829          * [in] receive or transmit direction
830          */
831         enum tf_dir dir;
832         /**
833          * [in] TCAM table type
834          */
835         enum tf_tcam_tbl_type tcam_tbl_type;
836         /**
837          * [in] base index of the entry to program
838          */
839         uint16_t idx;
840         /**
841          * [in] struct containing key
842          */
843         uint8_t *key;
844         /**
845          * [in] struct containing mask fields
846          */
847         uint8_t *mask;
848         /**
849          * [in] key size in bits (if search)
850          */
851         uint16_t key_sz_in_bits;
852         /**
853          * [in] struct containing result
854          */
855         uint8_t *result;
856         /**
857          * [in] struct containing result size in bits
858          */
859         uint16_t result_sz_in_bits;
860 };
861
862 /** set TCAM entry
863  *
864  * Program a TCAM table entry for a TruFlow session.
865  *
866  * If the entry has not been allocated, an error will be returned.
867  *
868  * Returns success or failure code.
869  */
870 int tf_set_tcam_entry(struct tf *tfp,
871                       struct tf_set_tcam_entry_parms *parms);
872
873 /** tf_get_tcam_entry parameter definition
874  */
875 struct tf_get_tcam_entry_parms {
876         /**
877          * [in] receive or transmit direction
878          */
879         enum tf_dir dir;
880         /**
881          * [in] TCAM table type
882          */
883         enum tf_tcam_tbl_type  tcam_tbl_type;
884         /**
885          * [in] index of the entry to get
886          */
887         uint16_t idx;
888         /**
889          * [out] struct containing key
890          */
891         uint8_t *key;
892         /**
893          * [out] struct containing mask fields
894          */
895         uint8_t *mask;
896         /**
897          * [out] key size in bits
898          */
899         uint16_t key_sz_in_bits;
900         /**
901          * [out] struct containing result
902          */
903         uint8_t *result;
904         /**
905          * [out] struct containing result size in bits
906          */
907         uint16_t result_sz_in_bits;
908 };
909
910 /*
911  * get TCAM entry
912  *
913  * Program a TCAM table entry for a TruFlow session.
914  *
915  * If the entry has not been allocated, an error will be returned.
916  *
917  * Returns success or failure code.
918  */
919 int tf_get_tcam_entry(struct tf *tfp,
920                       struct tf_get_tcam_entry_parms *parms);
921
922 /*
923  * tf_free_tcam_entry parameter definition
924  */
925 struct tf_free_tcam_entry_parms {
926         /**
927          * [in] receive or transmit direction
928          */
929         enum tf_dir dir;
930         /**
931          * [in] TCAM table type
932          */
933         enum tf_tcam_tbl_type tcam_tbl_type;
934         /**
935          * [in] Index to free
936          */
937         uint16_t idx;
938         /**
939          * [out] reference count after free
940          */
941         uint16_t ref_cnt;
942 };
943
944 /*
945  * Free TCAM entry.
946  *
947  * Firmware checks to ensure the TCAM entries are owned by the TruFlow
948  * session.  TCAM entry will be invalidated.  All-ones mask.
949  * writes to hw.
950  *
951  * WCTCAM profile id of 0 must be used to invalidate an entry.
952  *
953  * Returns success or failure code.
954  */
955 int tf_free_tcam_entry(struct tf *tfp,
956                        struct tf_free_tcam_entry_parms *parms);
957
958 /**
959  * @page table Table Access
960  *
961  * @ref tf_alloc_tbl_entry
962  *
963  * @ref tf_free_tbl_entry
964  *
965  * @ref tf_set_tbl_entry
966  *
967  * @ref tf_get_tbl_entry
968  */
969
970 /**
971  * tf_alloc_tbl_entry parameter definition
972  */
973 struct tf_alloc_tbl_entry_parms {
974         /**
975          * [in] Receive or transmit direction
976          */
977         enum tf_dir dir;
978         /**
979          * [in] Type of the allocation
980          */
981         enum tf_tbl_type type;
982         /**
983          * [in] Table scope identifier (ignored unless TF_TBL_TYPE_EXT)
984          */
985         uint32_t tbl_scope_id;
986         /**
987          * [in] Enable search for matching entry. If the table type is
988          * internal the shadow copy will be searched before
989          * alloc. Session must be configured with shadow copy enabled.
990          */
991         uint8_t search_enable;
992         /**
993          * [in] Result data to search for (if search_enable)
994          */
995         uint8_t *result;
996         /**
997          * [in] Result data size in bytes (if search_enable)
998          */
999         uint16_t result_sz_in_bytes;
1000         /**
1001          * [out] If search_enable, set if matching entry found
1002          */
1003         uint8_t hit;
1004         /**
1005          * [out] Current ref count after allocation (if search_enable)
1006          */
1007         uint16_t ref_cnt;
1008         /**
1009          * [out] Idx of allocated entry or found entry (if search_enable)
1010          */
1011         uint32_t idx;
1012 };
1013
1014 /**
1015  * allocate index table entries
1016  *
1017  * Internal types:
1018  *
1019  * Allocate an on chip index table entry or search for a matching
1020  * entry of the indicated type for this TruFlow session.
1021  *
1022  * Allocates an index table record. This function will attempt to
1023  * allocate an entry or search an index table for a matching entry if
1024  * search is enabled (only the shadow copy of the table is accessed).
1025  *
1026  * If search is not enabled, the first available free entry is
1027  * returned. If search is enabled and a matching entry to entry_data
1028  * is found hit is set to TRUE and success is returned.
1029  *
1030  * External types:
1031  *
1032  * These are used to allocate inlined action record memory.
1033  *
1034  * Allocates an external index table action record.
1035  *
1036  * NOTE:
1037  * Implementation of the internals of this function will be a stack with push
1038  * and pop.
1039  *
1040  * Returns success or failure code.
1041  */
1042 int tf_alloc_tbl_entry(struct tf *tfp,
1043                        struct tf_alloc_tbl_entry_parms *parms);
1044
1045 /**
1046  * tf_free_tbl_entry parameter definition
1047  */
1048 struct tf_free_tbl_entry_parms {
1049         /**
1050          * [in] Receive or transmit direction
1051          */
1052         enum tf_dir dir;
1053         /**
1054          * [in] Type of the allocation type
1055          */
1056         enum tf_tbl_type type;
1057         /**
1058          * [in] Table scope identifier (ignored unless TF_TBL_TYPE_EXT)
1059          */
1060         uint32_t tbl_scope_id;
1061         /**
1062          * [in] Index to free
1063          */
1064         uint32_t idx;
1065         /**
1066          * [out] Reference count after free, only valid if session has been
1067          * created with shadow_copy.
1068          */
1069         uint16_t ref_cnt;
1070 };
1071
1072 /**
1073  * free index table entry
1074  *
1075  * Used to free a previously allocated table entry.
1076  *
1077  * Internal types:
1078  *
1079  * If session has shadow_copy enabled the shadow DB is searched and if
1080  * found the element ref_cnt is decremented. If ref_cnt goes to
1081  * zero then the element is returned to the session pool.
1082  *
1083  * If the session does not have a shadow DB the element is free'ed and
1084  * given back to the session pool.
1085  *
1086  * External types:
1087  *
1088  * Free's an external index table action record.
1089  *
1090  * NOTE:
1091  * Implementation of the internals of this function will be a stack with push
1092  * and pop.
1093  *
1094  * Returns success or failure code.
1095  */
1096 int tf_free_tbl_entry(struct tf *tfp,
1097                       struct tf_free_tbl_entry_parms *parms);
1098
1099 /**
1100  * tf_set_tbl_entry parameter definition
1101  */
1102 struct tf_set_tbl_entry_parms {
1103         /**
1104          * [in] Table scope identifier
1105          */
1106         uint32_t tbl_scope_id;
1107         /**
1108          * [in] Receive or transmit direction
1109          */
1110         enum tf_dir dir;
1111         /**
1112          * [in] Type of object to set
1113          */
1114         enum tf_tbl_type type;
1115         /**
1116          * [in] Entry data
1117          */
1118         uint8_t *data;
1119         /**
1120          * [in] Entry size
1121          */
1122         uint16_t data_sz_in_bytes;
1123         /**
1124          * [in] Entry index to write to
1125          */
1126         uint32_t idx;
1127 };
1128
1129 /**
1130  * set index table entry
1131  *
1132  * Used to insert an application programmed index table entry into a
1133  * previous allocated table location.  A shadow copy of the table
1134  * is maintained (if enabled) (only for internal objects)
1135  *
1136  * Returns success or failure code.
1137  */
1138 int tf_set_tbl_entry(struct tf *tfp,
1139                      struct tf_set_tbl_entry_parms *parms);
1140
1141 /**
1142  * tf_get_tbl_entry parameter definition
1143  */
1144 struct tf_get_tbl_entry_parms {
1145         /**
1146          * [in] Receive or transmit direction
1147          */
1148         enum tf_dir dir;
1149         /**
1150          * [in] Type of object to get
1151          */
1152         enum tf_tbl_type type;
1153         /**
1154          * [out] Entry data
1155          */
1156         uint8_t *data;
1157         /**
1158          * [out] Entry size
1159          */
1160         uint16_t data_sz_in_bytes;
1161         /**
1162          * [in] Entry index to read
1163          */
1164         uint32_t idx;
1165 };
1166
1167 /**
1168  * get index table entry
1169  *
1170  * Used to retrieve a previous set index table entry.
1171  *
1172  * Reads and compares with the shadow table copy (if enabled) (only
1173  * for internal objects).
1174  *
1175  * Returns success or failure code. Failure will be returned if the
1176  * provided data buffer is too small for the data type requested.
1177  */
1178 int tf_get_tbl_entry(struct tf *tfp,
1179                      struct tf_get_tbl_entry_parms *parms);
1180
1181 /**
1182  * @page exact_match Exact Match Table
1183  *
1184  * @ref tf_insert_em_entry
1185  *
1186  * @ref tf_delete_em_entry
1187  *
1188  * @ref tf_search_em_entry
1189  *
1190  */
1191 /**
1192  * tf_insert_em_entry parameter definition
1193  */
1194 struct tf_insert_em_entry_parms {
1195         /**
1196          * [in] receive or transmit direction
1197          */
1198         enum tf_dir dir;
1199         /**
1200          * [in] internal or external
1201          */
1202         enum tf_mem mem;
1203         /**
1204          * [in] ID of table scope to use (external only)
1205          */
1206         uint32_t tbl_scope_id;
1207         /**
1208          * [in] ID of table interface to use (Brd4 only)
1209          */
1210         uint32_t tbl_if_id;
1211         /**
1212          * [in] ptr to structure containing key fields
1213          */
1214         uint8_t *key;
1215         /**
1216          * [in] key bit length
1217          */
1218         uint16_t key_sz_in_bits;
1219         /**
1220          * [in] ptr to structure containing result field
1221          */
1222         uint8_t *em_record;
1223         /**
1224          * [out] result size in bits
1225          */
1226         uint16_t em_record_sz_in_bits;
1227         /**
1228          * [in] duplicate check flag
1229          */
1230         uint8_t dup_check;
1231         /**
1232          * [out] Flow handle value for the inserted entry.  This is encoded
1233          * as the entries[4]:bucket[2]:hashId[1]:hash[14]
1234          */
1235         uint64_t flow_handle;
1236         /**
1237          * [out] Flow id is returned as null (internal)
1238          * Flow id is the GFID value for the inserted entry (external)
1239          * This is the value written to the BD and useful information for mark.
1240          */
1241         uint64_t flow_id;
1242 };
1243 /**
1244  * tf_delete_em_entry parameter definition
1245  */
1246 struct tf_delete_em_entry_parms {
1247         /**
1248          * [in] receive or transmit direction
1249          */
1250         enum tf_dir dir;
1251         /**
1252          * [in] internal or external
1253          */
1254         enum tf_mem mem;
1255         /**
1256          * [in] ID of table scope to use (external only)
1257          */
1258         uint32_t tbl_scope_id;
1259         /**
1260          * [in] ID of table interface to use (Brd4 only)
1261          */
1262         uint32_t tbl_if_id;
1263         /**
1264          * [in] epoch group IDs of entry to delete
1265          * 2 element array with 2 ids. (Brd4 only)
1266          */
1267         uint16_t *epochs;
1268         /**
1269          * [out] The index of the entry
1270          */
1271         uint16_t index;
1272         /**
1273          * [in] structure containing flow delete handle information
1274          */
1275         uint64_t flow_handle;
1276 };
1277 /**
1278  * tf_search_em_entry parameter definition
1279  */
1280 struct tf_search_em_entry_parms {
1281         /**
1282          * [in] receive or transmit direction
1283          */
1284         enum tf_dir dir;
1285         /**
1286          * [in] internal or external
1287          */
1288         enum tf_mem mem;
1289         /**
1290          * [in] ID of table scope to use (external only)
1291          */
1292         uint32_t tbl_scope_id;
1293         /**
1294          * [in] ID of table interface to use (Brd4 only)
1295          */
1296         uint32_t tbl_if_id;
1297         /**
1298          * [in] ptr to structure containing key fields
1299          */
1300         uint8_t *key;
1301         /**
1302          * [in] key bit length
1303          */
1304         uint16_t key_sz_in_bits;
1305         /**
1306          * [in/out] ptr to structure containing EM record fields
1307          */
1308         uint8_t *em_record;
1309         /**
1310          * [out] result size in bits
1311          */
1312         uint16_t em_record_sz_in_bits;
1313         /**
1314          * [in] epoch group IDs of entry to lookup
1315          * 2 element array with 2 ids. (Brd4 only)
1316          */
1317         uint16_t *epochs;
1318         /**
1319          * [in] ptr to structure containing flow delete handle
1320          */
1321         uint64_t flow_handle;
1322 };
1323
1324 /**
1325  * insert em hash entry in internal table memory
1326  *
1327  * Internal:
1328  *
1329  * This API inserts an exact match entry into internal EM table memory
1330  * of the specified direction.
1331  *
1332  * Note: The EM record is managed within the TruFlow core and not the
1333  * application.
1334  *
1335  * Shadow copy of internal record table an association with hash and 1,2, or 4
1336  * associated buckets
1337  *
1338  * External:
1339  * This API inserts an exact match entry into DRAM EM table memory of the
1340  * specified direction and table scope.
1341  *
1342  * When inserting an entry into an exact match table, the TruFlow library may
1343  * need to allocate a dynamic bucket for the entry (Brd4 only).
1344  *
1345  * The insertion of duplicate entries in an EM table is not permitted.  If a
1346  * TruFlow application can guarantee that it will never insert duplicates, it
1347  * can disable duplicate checking by passing a zero value in the  dup_check
1348  * parameter to this API.  This will optimize performance. Otherwise, the
1349  * TruFlow library will enforce protection against inserting duplicate entries.
1350  *
1351  * Flow handle is defined in this document:
1352  *
1353  * https://docs.google.com
1354  * /document/d/1NESu7RpTN3jwxbokaPfYORQyChYRmJgs40wMIRe8_-Q/edit
1355  *
1356  * Returns success or busy code.
1357  *
1358  */
1359 int tf_insert_em_entry(struct tf *tfp,
1360                        struct tf_insert_em_entry_parms *parms);
1361
1362 /**
1363  * delete em hash entry table memory
1364  *
1365  * Internal:
1366  *
1367  * This API deletes an exact match entry from internal EM table memory of the
1368  * specified direction. If a valid flow ptr is passed in then that takes
1369  * precedence over the pointer to the complete key passed in.
1370  *
1371  *
1372  * External:
1373  *
1374  * This API deletes an exact match entry from EM table memory of the specified
1375  * direction and table scope. If a valid flow handle is passed in then that
1376  * takes precedence over the pointer to the complete key passed in.
1377  *
1378  * The TruFlow library may release a dynamic bucket when an entry is deleted.
1379  *
1380  *
1381  * Returns success or not found code
1382  *
1383  *
1384  */
1385 int tf_delete_em_entry(struct tf *tfp,
1386                        struct tf_delete_em_entry_parms *parms);
1387
1388 /**
1389  * search em hash entry table memory
1390  *
1391  * Internal:
1392
1393  * This API looks up an EM entry in table memory with the specified EM
1394  * key or flow (flow takes precedence) and direction.
1395  *
1396  * The status will be one of: success or entry not found.  If the lookup
1397  * succeeds, a pointer to the matching entry and the result record associated
1398  * with the matching entry will be provided.
1399  *
1400  * If flow_handle is set, search shadow copy.
1401  *
1402  * Otherwise, query the fw with key to get result.
1403  *
1404  * External:
1405  *
1406  * This API looks up an EM entry in table memory with the specified EM
1407  * key or flow_handle (flow takes precedence), direction and table scope.
1408  *
1409  * The status will be one of: success or entry not found.  If the lookup
1410  * succeeds, a pointer to the matching entry and the result record associated
1411  * with the matching entry will be provided.
1412  *
1413  * Returns success or not found code
1414  *
1415  */
1416 int tf_search_em_entry(struct tf *tfp,
1417                        struct tf_search_em_entry_parms *parms);
1418 #endif /* _TF_CORE_H_ */