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