net/bnxt: update table get to use new design
[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  * Identifier resource definition
389  */
390 struct tf_identifier_resources {
391         /**
392          * Array of TF Identifiers where each entry is expected to be
393          * set to the requested resource number of that specific type.
394          * The index used is tf_identifier_type.
395          */
396         uint16_t cnt[TF_IDENT_TYPE_MAX];
397 };
398
399 /**
400  * Table type resource definition
401  */
402 struct tf_tbl_resources {
403         /**
404          * Array of TF Table types where each entry is expected to be
405          * set to the requeste resource number of that specific
406          * type. The index used is tf_tbl_type.
407          */
408         uint16_t cnt[TF_TBL_TYPE_MAX];
409 };
410
411 /**
412  * TCAM type resource definition
413  */
414 struct tf_tcam_resources {
415         /**
416          * Array of TF TCAM types where each entry is expected to be
417          * set to the requested resource number of that specific
418          * type. The index used is tf_tcam_tbl_type.
419          */
420         uint16_t cnt[TF_TCAM_TBL_TYPE_MAX];
421 };
422
423 /**
424  * EM type resource definition
425  */
426 struct tf_em_resources {
427         /**
428          * Array of TF EM table types where each entry is expected to
429          * be set to the requested resource number of that specific
430          * type. The index used is tf_em_tbl_type.
431          */
432         uint16_t cnt[TF_EM_TBL_TYPE_MAX];
433 };
434
435 /**
436  * tf_session_resources parameter definition.
437  */
438 struct tf_session_resources {
439         /**
440          * [in] Requested Identifier Resources
441          *
442          * Number of identifier resources requested for the
443          * session.
444          */
445         struct tf_identifier_resources ident_cnt[TF_DIR_MAX];
446         /**
447          * [in] Requested Index Table resource counts
448          *
449          * The number of index table resources requested for the
450          * session.
451          */
452         struct tf_tbl_resources tbl_cnt[TF_DIR_MAX];
453         /**
454          * [in] Requested TCAM Table resource counts
455          *
456          * The number of TCAM table resources requested for the
457          * session.
458          */
459
460         struct tf_tcam_resources tcam_cnt[TF_DIR_MAX];
461         /**
462          * [in] Requested EM resource counts
463          *
464          * The number of internal EM table resources requested for the
465          * session.
466          */
467         struct tf_em_resources em_cnt[TF_DIR_MAX];
468 };
469
470 /**
471  * tf_open_session parameters definition.
472  */
473 struct tf_open_session_parms {
474         /**
475          * [in] ctrl_chan_name
476          *
477          * String containing name of control channel interface to be
478          * used for this session to communicate with firmware.
479          *
480          * The ctrl_chan_name can be looked up by using
481          * rte_eth_dev_get_name_by_port() within the ULP.
482          *
483          * ctrl_chan_name will be used as part of a name for any
484          * shared memory allocation.
485          */
486         char ctrl_chan_name[TF_SESSION_NAME_MAX];
487         /**
488          * [in] shadow_copy
489          *
490          * Boolean controlling the use and availability of shadow
491          * copy. Shadow copy will allow the TruFlow to keep track of
492          * resource content on the firmware side without having to
493          * query firmware. Additional private session core_data will
494          * be allocated if this boolean is set to 'true', default
495          * 'false'.
496          *
497          * Size of memory depends on the NVM Resource settings for the
498          * control channel.
499          */
500         bool shadow_copy;
501         /**
502          * [in/out] session_id
503          *
504          * Session_id is unique per session.
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          *
510          * The session_id allows a session to be shared between devices.
511          */
512         union tf_session_id session_id;
513         /**
514          * [in] device type
515          *
516          * Device type is passed, one of Wh+, SR, Thor, SR2
517          */
518         enum tf_device_type device_type;
519         /** [in] resources
520          *
521          * Resource allocation
522          */
523         struct tf_session_resources resources;
524 };
525
526 /**
527  * Opens a new TruFlow management session.
528  *
529  * TruFlow will allocate session specific memory, shared memory, to
530  * hold its session data. This data is private to TruFlow.
531  *
532  * Multiple PFs can share the same session. An association, refcount,
533  * between session and PFs is maintained within TruFlow. Thus, a PF
534  * can attach to an existing session, see tf_attach_session().
535  *
536  * No other TruFlow APIs will succeed unless this API is first called and
537  * succeeds.
538  *
539  * tf_open_session() returns a session id that can be used on attach.
540  *
541  * [in] tfp
542  *   Pointer to TF handle
543  * [in] parms
544  *   Pointer to open parameters
545  *
546  * Returns
547  *   - (0) if successful.
548  *   - (-EINVAL) on failure.
549  */
550 int tf_open_session(struct tf *tfp,
551                     struct tf_open_session_parms *parms);
552
553 struct tf_attach_session_parms {
554         /**
555          * [in] ctrl_chan_name
556          *
557          * String containing name of control channel interface to be
558          * used for this session to communicate with firmware.
559          *
560          * The ctrl_chan_name can be looked up by using
561          * rte_eth_dev_get_name_by_port() within the ULP.
562          *
563          * ctrl_chan_name will be used as part of a name for any
564          * shared memory allocation.
565          */
566         char ctrl_chan_name[TF_SESSION_NAME_MAX];
567
568         /**
569          * [in] attach_chan_name
570          *
571          * String containing name of attach channel interface to be
572          * used for this session.
573          *
574          * The attach_chan_name must be given to a 2nd process after
575          * the primary process has been created. This is the
576          * ctrl_chan_name of the primary process and is used to find
577          * the shared memory for the session that the attach is going
578          * to use.
579          */
580         char attach_chan_name[TF_SESSION_NAME_MAX];
581
582         /**
583          * [in] session_id
584          *
585          * Session_id is unique per session. For Attach the session_id
586          * should be the session_id that was returned on the first
587          * open.
588          *
589          * Session_id is composed of domain, bus, device and
590          * fw_session_id. The construction is done by parsing the
591          * ctrl_chan_name together with allocation of a fw_session_id
592          * during tf_open_session().
593          *
594          * A reference count will be incremented on attach. A session
595          * is first fully closed when reference count is zero by
596          * calling tf_close_session().
597          */
598         union tf_session_id session_id;
599 };
600
601 /**
602  * Attaches to an existing session. Used when more than one PF wants
603  * to share a single session. In that case all TruFlow management
604  * traffic will be sent to the TruFlow firmware using the 'PF' that
605  * did the attach not the session ctrl channel.
606  *
607  * Attach will increment a ref count as to manage the shared session data.
608  *
609  * [in] tfp, pointer to TF handle
610  * [in] parms, pointer to attach parameters
611  *
612  * Returns
613  *   - (0) if successful.
614  *   - (-EINVAL) on failure.
615  */
616 int tf_attach_session(struct tf *tfp,
617                       struct tf_attach_session_parms *parms);
618
619 /**
620  * Closes an existing session. Cleans up all hardware and firmware
621  * state associated with the TruFlow application session when the last
622  * PF associated with the session results in refcount to be zero.
623  *
624  * Returns success or failure code.
625  */
626 int tf_close_session(struct tf *tfp);
627
628 /**
629  * @page  ident Identity Management
630  *
631  * @ref tf_alloc_identifier
632  *
633  * @ref tf_free_identifier
634  */
635 /**
636  * tf_alloc_identifier parameter definition
637  */
638 struct tf_alloc_identifier_parms {
639         /**
640          * [in]  receive or transmit direction
641          */
642         enum tf_dir dir;
643         /**
644          * [in] Identifier type
645          */
646         enum tf_identifier_type ident_type;
647         /**
648          * [out] Identifier allocated
649          */
650         uint16_t id;
651 };
652
653 /**
654  * tf_free_identifier parameter definition
655  */
656 struct tf_free_identifier_parms {
657         /**
658          * [in]  receive or transmit direction
659          */
660         enum tf_dir dir;
661         /**
662          * [in] Identifier type
663          */
664         enum tf_identifier_type ident_type;
665         /**
666          * [in] ID to free
667          */
668         uint16_t id;
669 };
670
671 /**
672  * allocate identifier resource
673  *
674  * TruFlow core will allocate a free id from the per identifier resource type
675  * pool reserved for the session during tf_open().  No firmware is involved.
676  *
677  * Returns success or failure code.
678  */
679 int tf_alloc_identifier(struct tf *tfp,
680                         struct tf_alloc_identifier_parms *parms);
681
682 /**
683  * free identifier resource
684  *
685  * TruFlow core will return an id back to the per identifier resource type pool
686  * reserved for the session.  No firmware is involved.  During tf_close, the
687  * complete pool is returned to the firmware.
688  *
689  * Returns success or failure code.
690  */
691 int tf_free_identifier(struct tf *tfp,
692                        struct tf_free_identifier_parms *parms);
693
694 /**
695  * @page dram_table DRAM Table Scope Interface
696  *
697  * @ref tf_alloc_tbl_scope
698  *
699  * @ref tf_free_tbl_scope
700  *
701  * If we allocate the EEM memory from the core, we need to store it in
702  * the shared session data structure to make sure it can be freed later.
703  * (for example if the PF goes away)
704  *
705  * Current thought is that memory is allocated within core.
706  */
707
708
709 /**
710  * tf_alloc_tbl_scope_parms definition
711  */
712 struct tf_alloc_tbl_scope_parms {
713         /**
714          * [in] All Maximum key size required.
715          */
716         uint16_t rx_max_key_sz_in_bits;
717         /**
718          * [in] Maximum Action size required (includes inlined items)
719          */
720         uint16_t rx_max_action_entry_sz_in_bits;
721         /**
722          * [in] Memory size in Megabytes
723          * Total memory size allocated by user to be divided
724          * up for actions, hash, counters.  Only inline external actions.
725          * Use this variable or the number of flows, do not set both.
726          */
727         uint32_t rx_mem_size_in_mb;
728         /**
729          * [in] Number of flows * 1000. If set, rx_mem_size_in_mb must equal 0.
730          */
731         uint32_t rx_num_flows_in_k;
732         /**
733          * [in] SR2 only receive table access interface id
734          */
735         uint32_t rx_tbl_if_id;
736         /**
737          * [in] All Maximum key size required.
738          */
739         uint16_t tx_max_key_sz_in_bits;
740         /**
741          * [in] Maximum Action size required (includes inlined items)
742          */
743         uint16_t tx_max_action_entry_sz_in_bits;
744         /**
745          * [in] Memory size in Megabytes
746          * Total memory size allocated by user to be divided
747          * up for actions, hash, counters.  Only inline external actions.
748          */
749         uint32_t tx_mem_size_in_mb;
750         /**
751          * [in] Number of flows * 1000
752          */
753         uint32_t tx_num_flows_in_k;
754         /**
755          * [in] SR2 only receive table access interface id
756          */
757         uint32_t tx_tbl_if_id;
758         /**
759          * [in] Flush pending HW cached flows every 1/10th of value
760          * set in seconds, both idle and active flows are flushed
761          * from the HW cache. If set to 0, this feature will be disabled.
762          */
763         uint8_t hw_flow_cache_flush_timer;
764         /**
765          * [out] table scope identifier
766          */
767         uint32_t tbl_scope_id;
768 };
769
770 struct tf_free_tbl_scope_parms {
771         /**
772          * [in] table scope identifier
773          */
774         uint32_t tbl_scope_id;
775 };
776
777 /**
778  * allocate a table scope
779  *
780  * On SR2 Firmware will allocate a scope ID.  On other devices, the scope
781  * is a software construct to identify an EEM table.  This function will
782  * divide the hash memory/buckets and records according to the device
783  * device constraints based upon calculations using either the number of flows
784  * requested or the size of memory indicated.  Other parameters passed in
785  * determine the configuration (maximum key size, maximum external action record
786  * size.
787  *
788  * This API will allocate the table region in
789  * DRAM, program the PTU page table entries, and program the number of static
790  * buckets (if SR2) in the RX and TX CFAs.  Buckets are assumed to start at
791  * 0 in the EM memory for the scope.  Upon successful completion of this API,
792  * hash tables are fully initialized and ready for entries to be inserted.
793  *
794  * A single API is used to allocate a common table scope identifier in both
795  * receive and transmit CFA. The scope identifier is common due to nature of
796  * connection tracking sending notifications between RX and TX direction.
797  *
798  * The receive and transmit table access identifiers specify which rings will
799  * be used to initialize table DRAM.  The application must ensure mutual
800  * exclusivity of ring usage for table scope allocation and any table update
801  * operations.
802  *
803  * The hash table buckets, EM keys, and EM lookup results are stored in the
804  * memory allocated based on the rx_em_hash_mb/tx_em_hash_mb parameters.  The
805  * hash table buckets are stored at the beginning of that memory.
806  *
807  * NOTE:  No EM internal setup is done here. On chip EM records are managed
808  * internally by TruFlow core.
809  *
810  * Returns success or failure code.
811  */
812 int tf_alloc_tbl_scope(struct tf *tfp,
813                        struct tf_alloc_tbl_scope_parms *parms);
814
815
816 /**
817  * free a table scope
818  *
819  * Firmware checks that the table scope ID is owned by the TruFlow
820  * session, verifies that no references to this table scope remains
821  * (SR2 ILT) or Profile TCAM entries for either CFA (RX/TX) direction,
822  * then frees the table scope ID.
823  *
824  * Returns success or failure code.
825  */
826 int tf_free_tbl_scope(struct tf *tfp,
827                       struct tf_free_tbl_scope_parms *parms);
828
829 /**
830  * @page tcam TCAM Access
831  *
832  * @ref tf_alloc_tcam_entry
833  *
834  * @ref tf_set_tcam_entry
835  *
836  * @ref tf_get_tcam_entry
837  *
838  * @ref tf_free_tcam_entry
839  */
840
841
842 /**
843  * tf_alloc_tcam_entry parameter definition
844  */
845 struct tf_alloc_tcam_entry_parms {
846         /**
847          * [in] receive or transmit direction
848          */
849         enum tf_dir dir;
850         /**
851          * [in] TCAM table type
852          */
853         enum tf_tcam_tbl_type tcam_tbl_type;
854         /**
855          * [in] Enable search for matching entry
856          */
857         uint8_t search_enable;
858         /**
859          * [in] Key data to match on (if search)
860          */
861         uint8_t *key;
862         /**
863          * [in] key size in bits (if search)
864          */
865         uint16_t key_sz_in_bits;
866         /**
867          * [in] Mask data to match on (if search)
868          */
869         uint8_t *mask;
870         /**
871          * [in] Priority of entry requested (definition TBD)
872          */
873         uint32_t priority;
874         /**
875          * [out] If search, set if matching entry found
876          */
877         uint8_t hit;
878         /**
879          * [out] Current refcnt after allocation
880          */
881         uint16_t ref_cnt;
882         /**
883          * [out] Idx allocated
884          *
885          */
886         uint16_t idx;
887 };
888
889 /**
890  * allocate TCAM entry
891  *
892  * Allocate a TCAM entry - one of these types:
893  *
894  * L2 Context
895  * Profile TCAM
896  * WC TCAM
897  * VEB TCAM
898  *
899  * This function allocates a TCAM table record.  This function
900  * will attempt to allocate a TCAM table entry from the session
901  * owned TCAM entries or search a shadow copy of the TCAM table for a
902  * matching entry if search is enabled.  Key, mask and result must match for
903  * hit to be set.  Only TruFlow core data is accessed.
904  * A hash table to entry mapping is maintained for search purposes.  If
905  * search is not enabled, the first available free entry is returned based
906  * on priority and alloc_cnt is set to 1.  If search is enabled and a matching
907  * entry to entry_data is found, hit is set to TRUE and alloc_cnt is set to 1.
908  * RefCnt is also returned.
909  *
910  * Also returns success or failure code.
911  */
912 int tf_alloc_tcam_entry(struct tf *tfp,
913                         struct tf_alloc_tcam_entry_parms *parms);
914
915 /**
916  * tf_set_tcam_entry parameter definition
917  */
918 struct  tf_set_tcam_entry_parms {
919         /**
920          * [in] receive or transmit direction
921          */
922         enum tf_dir dir;
923         /**
924          * [in] TCAM table type
925          */
926         enum tf_tcam_tbl_type tcam_tbl_type;
927         /**
928          * [in] base index of the entry to program
929          */
930         uint16_t idx;
931         /**
932          * [in] struct containing key
933          */
934         uint8_t *key;
935         /**
936          * [in] struct containing mask fields
937          */
938         uint8_t *mask;
939         /**
940          * [in] key size in bits (if search)
941          */
942         uint16_t key_sz_in_bits;
943         /**
944          * [in] struct containing result
945          */
946         uint8_t *result;
947         /**
948          * [in] struct containing result size in bits
949          */
950         uint16_t result_sz_in_bits;
951 };
952
953 /**
954  * set TCAM entry
955  *
956  * Program a TCAM table entry for a TruFlow session.
957  *
958  * If the entry has not been allocated, an error will be returned.
959  *
960  * Returns success or failure code.
961  */
962 int tf_set_tcam_entry(struct tf *tfp,
963                       struct tf_set_tcam_entry_parms *parms);
964
965 /**
966  * tf_get_tcam_entry parameter definition
967  */
968 struct tf_get_tcam_entry_parms {
969         /**
970          * [in] receive or transmit direction
971          */
972         enum tf_dir dir;
973         /**
974          * [in] TCAM table type
975          */
976         enum tf_tcam_tbl_type  tcam_tbl_type;
977         /**
978          * [in] index of the entry to get
979          */
980         uint16_t idx;
981         /**
982          * [out] struct containing key
983          */
984         uint8_t *key;
985         /**
986          * [out] struct containing mask fields
987          */
988         uint8_t *mask;
989         /**
990          * [out] key size in bits
991          */
992         uint16_t key_sz_in_bits;
993         /**
994          * [out] struct containing result
995          */
996         uint8_t *result;
997         /**
998          * [out] struct containing result size in bits
999          */
1000         uint16_t result_sz_in_bits;
1001 };
1002
1003 /**
1004  * get TCAM entry
1005  *
1006  * Program a TCAM table entry for a TruFlow session.
1007  *
1008  * If the entry has not been allocated, an error will be returned.
1009  *
1010  * Returns success or failure code.
1011  */
1012 int tf_get_tcam_entry(struct tf *tfp,
1013                       struct tf_get_tcam_entry_parms *parms);
1014
1015 /**
1016  * tf_free_tcam_entry parameter definition
1017  */
1018 struct tf_free_tcam_entry_parms {
1019         /**
1020          * [in] receive or transmit direction
1021          */
1022         enum tf_dir dir;
1023         /**
1024          * [in] TCAM table type
1025          */
1026         enum tf_tcam_tbl_type tcam_tbl_type;
1027         /**
1028          * [in] Index to free
1029          */
1030         uint16_t idx;
1031         /**
1032          * [out] reference count after free
1033          */
1034         uint16_t ref_cnt;
1035 };
1036
1037 /**
1038  * free TCAM entry
1039  *
1040  * Free TCAM entry.
1041  *
1042  * Firmware checks to ensure the TCAM entries are owned by the TruFlow
1043  * session.  TCAM entry will be invalidated.  All-ones mask.
1044  * writes to hw.
1045  *
1046  * WCTCAM profile id of 0 must be used to invalidate an entry.
1047  *
1048  * Returns success or failure code.
1049  */
1050 int tf_free_tcam_entry(struct tf *tfp,
1051                        struct tf_free_tcam_entry_parms *parms);
1052
1053 /**
1054  * @page table Table Access
1055  *
1056  * @ref tf_alloc_tbl_entry
1057  *
1058  * @ref tf_free_tbl_entry
1059  *
1060  * @ref tf_set_tbl_entry
1061  *
1062  * @ref tf_get_tbl_entry
1063  */
1064
1065
1066 /**
1067  * tf_alloc_tbl_entry parameter definition
1068  */
1069 struct tf_alloc_tbl_entry_parms {
1070         /**
1071          * [in] Receive or transmit direction
1072          */
1073         enum tf_dir dir;
1074         /**
1075          * [in] Type of the allocation
1076          */
1077         enum tf_tbl_type type;
1078         /**
1079          * [in] Table scope identifier (ignored unless TF_TBL_TYPE_EXT)
1080          */
1081         uint32_t tbl_scope_id;
1082         /**
1083          * [in] Enable search for matching entry. If the table type is
1084          * internal the shadow copy will be searched before
1085          * alloc. Session must be configured with shadow copy enabled.
1086          */
1087         uint8_t search_enable;
1088         /**
1089          * [in] Result data to search for (if search_enable)
1090          */
1091         uint8_t *result;
1092         /**
1093          * [in] Result data size in bytes (if search_enable)
1094          */
1095         uint16_t result_sz_in_bytes;
1096         /**
1097          * [out] If search_enable, set if matching entry found
1098          */
1099         uint8_t hit;
1100         /**
1101          * [out] Current ref count after allocation (if search_enable)
1102          */
1103         uint16_t ref_cnt;
1104         /**
1105          * [out] Idx of allocated entry or found entry (if search_enable)
1106          */
1107         uint32_t idx;
1108 };
1109
1110 /**
1111  * allocate index table entries
1112  *
1113  * Internal types:
1114  *
1115  * Allocate an on chip index table entry or search for a matching
1116  * entry of the indicated type for this TruFlow session.
1117  *
1118  * Allocates an index table record. This function will attempt to
1119  * allocate an entry or search an index table for a matching entry if
1120  * search is enabled (only the shadow copy of the table is accessed).
1121  *
1122  * If search is not enabled, the first available free entry is
1123  * returned. If search is enabled and a matching entry to entry_data
1124  * is found hit is set to TRUE and success is returned.
1125  *
1126  * External types:
1127  *
1128  * These are used to allocate inlined action record memory.
1129  *
1130  * Allocates an external index table action record.
1131  *
1132  * NOTE:
1133  * Implementation of the internals of this function will be a stack with push
1134  * and pop.
1135  *
1136  * Returns success or failure code.
1137  */
1138 int tf_alloc_tbl_entry(struct tf *tfp,
1139                        struct tf_alloc_tbl_entry_parms *parms);
1140
1141 /**
1142  * tf_free_tbl_entry parameter definition
1143  */
1144 struct tf_free_tbl_entry_parms {
1145         /**
1146          * [in] Receive or transmit direction
1147          */
1148         enum tf_dir dir;
1149         /**
1150          * [in] Type of the allocation type
1151          */
1152         enum tf_tbl_type type;
1153         /**
1154          * [in] Table scope identifier (ignored unless TF_TBL_TYPE_EXT)
1155          */
1156         uint32_t tbl_scope_id;
1157         /**
1158          * [in] Index to free
1159          */
1160         uint32_t idx;
1161         /**
1162          * [out] Reference count after free, only valid if session has been
1163          * created with shadow_copy.
1164          */
1165         uint16_t ref_cnt;
1166 };
1167
1168 /**
1169  * free index table entry
1170  *
1171  * Used to free a previously allocated table entry.
1172  *
1173  * Internal types:
1174  *
1175  * If session has shadow_copy enabled the shadow DB is searched and if
1176  * found the element ref_cnt is decremented. If ref_cnt goes to
1177  * zero then the element is returned to the session pool.
1178  *
1179  * If the session does not have a shadow DB the element is free'ed and
1180  * given back to the session pool.
1181  *
1182  * External types:
1183  *
1184  * Free's an external index table action record.
1185  *
1186  * NOTE:
1187  * Implementation of the internals of this function will be a stack with push
1188  * and pop.
1189  *
1190  * Returns success or failure code.
1191  */
1192 int tf_free_tbl_entry(struct tf *tfp,
1193                       struct tf_free_tbl_entry_parms *parms);
1194
1195 /**
1196  * tf_set_tbl_entry parameter definition
1197  */
1198 struct tf_set_tbl_entry_parms {
1199         /**
1200          * [in] Table scope identifier
1201          */
1202         uint32_t tbl_scope_id;
1203         /**
1204          * [in] Receive or transmit direction
1205          */
1206         enum tf_dir dir;
1207         /**
1208          * [in] Type of object to set
1209          */
1210         enum tf_tbl_type type;
1211         /**
1212          * [in] Entry data
1213          */
1214         uint8_t *data;
1215         /**
1216          * [in] Entry size
1217          */
1218         uint16_t data_sz_in_bytes;
1219         /**
1220          * [in] Entry index to write to
1221          */
1222         uint32_t idx;
1223 };
1224
1225 /**
1226  * set index table entry
1227  *
1228  * Used to insert an application programmed index table entry into a
1229  * previous allocated table location.  A shadow copy of the table
1230  * is maintained (if enabled) (only for internal objects)
1231  *
1232  * Returns success or failure code.
1233  */
1234 int tf_set_tbl_entry(struct tf *tfp,
1235                      struct tf_set_tbl_entry_parms *parms);
1236
1237 /**
1238  * tf_get_tbl_entry parameter definition
1239  */
1240 struct tf_get_tbl_entry_parms {
1241         /**
1242          * [in] Receive or transmit direction
1243          */
1244         enum tf_dir dir;
1245         /**
1246          * [in] Type of object to get
1247          */
1248         enum tf_tbl_type type;
1249         /**
1250          * [out] Entry data
1251          */
1252         uint8_t *data;
1253         /**
1254          * [in] Entry size
1255          */
1256         uint16_t data_sz_in_bytes;
1257         /**
1258          * [in] Entry index to read
1259          */
1260         uint32_t idx;
1261 };
1262
1263 /**
1264  * get index table entry
1265  *
1266  * Used to retrieve a previous set index table entry.
1267  *
1268  * Reads and compares with the shadow table copy (if enabled) (only
1269  * for internal objects).
1270  *
1271  * Returns success or failure code. Failure will be returned if the
1272  * provided data buffer is too small for the data type requested.
1273  */
1274 int tf_get_tbl_entry(struct tf *tfp,
1275                      struct tf_get_tbl_entry_parms *parms);
1276
1277 /**
1278  * tf_bulk_get_tbl_entry parameter definition
1279  */
1280 struct tf_bulk_get_tbl_entry_parms {
1281         /**
1282          * [in] Receive or transmit direction
1283          */
1284         enum tf_dir dir;
1285         /**
1286          * [in] Type of object to get
1287          */
1288         enum tf_tbl_type type;
1289         /**
1290          * [in] Starting index to read from
1291          */
1292         uint32_t starting_idx;
1293         /**
1294          * [in] Number of sequential entries
1295          */
1296         uint16_t num_entries;
1297         /**
1298          * [in] Size of the single entry
1299          */
1300         uint16_t entry_sz_in_bytes;
1301         /**
1302          * [out] Host physical address, where the data
1303          * will be copied to by the firmware.
1304          * Use tfp_calloc() API and mem_pa
1305          * variable of the tfp_calloc_parms
1306          * structure for the physical address.
1307          */
1308         uint64_t physical_mem_addr;
1309 };
1310
1311 /**
1312  * Bulk get index table entry
1313  *
1314  * Used to retrieve a previous set index table entry.
1315  *
1316  * Reads and compares with the shadow table copy (if enabled) (only
1317  * for internal objects).
1318  *
1319  * Returns success or failure code. Failure will be returned if the
1320  * provided data buffer is too small for the data type requested.
1321  */
1322 int tf_bulk_get_tbl_entry(struct tf *tfp,
1323                           struct tf_bulk_get_tbl_entry_parms *parms);
1324
1325 /**
1326  * @page exact_match Exact Match Table
1327  *
1328  * @ref tf_insert_em_entry
1329  *
1330  * @ref tf_delete_em_entry
1331  *
1332  * @ref tf_search_em_entry
1333  *
1334  */
1335 /**
1336  * tf_insert_em_entry parameter definition
1337  */
1338 struct tf_insert_em_entry_parms {
1339         /**
1340          * [in] receive or transmit direction
1341          */
1342         enum tf_dir dir;
1343         /**
1344          * [in] internal or external
1345          */
1346         enum tf_mem mem;
1347         /**
1348          * [in] ID of table scope to use (external only)
1349          */
1350         uint32_t tbl_scope_id;
1351         /**
1352          * [in] ID of table interface to use (SR2 only)
1353          */
1354         uint32_t tbl_if_id;
1355         /**
1356          * [in] ptr to structure containing key fields
1357          */
1358         uint8_t *key;
1359         /**
1360          * [in] key bit length
1361          */
1362         uint16_t key_sz_in_bits;
1363         /**
1364          * [in] ptr to structure containing result field
1365          */
1366         uint8_t *em_record;
1367         /**
1368          * [out] result size in bits
1369          */
1370         uint16_t em_record_sz_in_bits;
1371         /**
1372          * [in] duplicate check flag
1373          */
1374         uint8_t dup_check;
1375         /**
1376          * [out] Flow handle value for the inserted entry.  This is encoded
1377          * as the entries[4]:bucket[2]:hashId[1]:hash[14]
1378          */
1379         uint64_t flow_handle;
1380         /**
1381          * [out] Flow id is returned as null (internal)
1382          * Flow id is the GFID value for the inserted entry (external)
1383          * This is the value written to the BD and useful information for mark.
1384          */
1385         uint64_t flow_id;
1386 };
1387 /**
1388  * tf_delete_em_entry parameter definition
1389  */
1390 struct tf_delete_em_entry_parms {
1391         /**
1392          * [in] receive or transmit direction
1393          */
1394         enum tf_dir dir;
1395         /**
1396          * [in] internal or external
1397          */
1398         enum tf_mem mem;
1399         /**
1400          * [in] ID of table scope to use (external only)
1401          */
1402         uint32_t tbl_scope_id;
1403         /**
1404          * [in] ID of table interface to use (SR2 only)
1405          */
1406         uint32_t tbl_if_id;
1407         /**
1408          * [in] epoch group IDs of entry to delete
1409          * 2 element array with 2 ids. (SR2 only)
1410          */
1411         uint16_t *epochs;
1412         /**
1413          * [out] The index of the entry
1414          */
1415         uint16_t index;
1416         /**
1417          * [in] structure containing flow delete handle information
1418          */
1419         uint64_t flow_handle;
1420 };
1421 /**
1422  * tf_search_em_entry parameter definition
1423  */
1424 struct tf_search_em_entry_parms {
1425         /**
1426          * [in] receive or transmit direction
1427          */
1428         enum tf_dir dir;
1429         /**
1430          * [in] internal or external
1431          */
1432         enum tf_mem mem;
1433         /**
1434          * [in] ID of table scope to use (external only)
1435          */
1436         uint32_t tbl_scope_id;
1437         /**
1438          * [in] ID of table interface to use (SR2 only)
1439          */
1440         uint32_t tbl_if_id;
1441         /**
1442          * [in] ptr to structure containing key fields
1443          */
1444         uint8_t *key;
1445         /**
1446          * [in] key bit length
1447          */
1448         uint16_t key_sz_in_bits;
1449         /**
1450          * [in/out] ptr to structure containing EM record fields
1451          */
1452         uint8_t *em_record;
1453         /**
1454          * [out] result size in bits
1455          */
1456         uint16_t em_record_sz_in_bits;
1457         /**
1458          * [in] epoch group IDs of entry to lookup
1459          * 2 element array with 2 ids. (SR2 only)
1460          */
1461         uint16_t *epochs;
1462         /**
1463          * [in] ptr to structure containing flow delete handle
1464          */
1465         uint64_t flow_handle;
1466 };
1467
1468 /**
1469  * insert em hash entry in internal table memory
1470  *
1471  * Internal:
1472  *
1473  * This API inserts an exact match entry into internal EM table memory
1474  * of the specified direction.
1475  *
1476  * Note: The EM record is managed within the TruFlow core and not the
1477  * application.
1478  *
1479  * Shadow copy of internal record table an association with hash and 1,2, or 4
1480  * associated buckets
1481  *
1482  * External:
1483  * This API inserts an exact match entry into DRAM EM table memory of the
1484  * specified direction and table scope.
1485  *
1486  * When inserting an entry into an exact match table, the TruFlow library may
1487  * need to allocate a dynamic bucket for the entry (SR2 only).
1488  *
1489  * The insertion of duplicate entries in an EM table is not permitted.  If a
1490  * TruFlow application can guarantee that it will never insert duplicates, it
1491  * can disable duplicate checking by passing a zero value in the  dup_check
1492  * parameter to this API.  This will optimize performance. Otherwise, the
1493  * TruFlow library will enforce protection against inserting duplicate entries.
1494  *
1495  * Flow handle is defined in this document:
1496  *
1497  * https://docs.google.com
1498  * /document/d/1NESu7RpTN3jwxbokaPfYORQyChYRmJgs40wMIRe8_-Q/edit
1499  *
1500  * Returns success or busy code.
1501  *
1502  */
1503 int tf_insert_em_entry(struct tf *tfp,
1504                        struct tf_insert_em_entry_parms *parms);
1505
1506 /**
1507  * delete em hash entry table memory
1508  *
1509  * Internal:
1510  *
1511  * This API deletes an exact match entry from internal EM table memory of the
1512  * specified direction. If a valid flow ptr is passed in then that takes
1513  * precedence over the pointer to the complete key passed in.
1514  *
1515  *
1516  * External:
1517  *
1518  * This API deletes an exact match entry from EM table memory of the specified
1519  * direction and table scope. If a valid flow handle is passed in then that
1520  * takes precedence over the pointer to the complete key passed in.
1521  *
1522  * The TruFlow library may release a dynamic bucket when an entry is deleted.
1523  *
1524  *
1525  * Returns success or not found code
1526  *
1527  *
1528  */
1529 int tf_delete_em_entry(struct tf *tfp,
1530                        struct tf_delete_em_entry_parms *parms);
1531
1532 /**
1533  * search em hash entry table memory
1534  *
1535  * Internal:
1536
1537  * This API looks up an EM entry in table memory with the specified EM
1538  * key or flow (flow takes precedence) and direction.
1539  *
1540  * The status will be one of: success or entry not found.  If the lookup
1541  * succeeds, a pointer to the matching entry and the result record associated
1542  * with the matching entry will be provided.
1543  *
1544  * If flow_handle is set, search shadow copy.
1545  *
1546  * Otherwise, query the fw with key to get result.
1547  *
1548  * External:
1549  *
1550  * This API looks up an EM entry in table memory with the specified EM
1551  * key or flow_handle (flow takes precedence), direction and table scope.
1552  *
1553  * The status will be one of: success or entry not found.  If the lookup
1554  * succeeds, a pointer to the matching entry and the result record associated
1555  * with the matching entry will be provided.
1556  *
1557  * Returns success or not found code
1558  *
1559  */
1560 int tf_search_em_entry(struct tf *tfp,
1561                        struct tf_search_em_entry_parms *parms);
1562
1563 #endif /* _TF_CORE_H_ */