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