3d14dc5391a8545f43ef0b944baf5aa58f48835f
[dpdk.git] / drivers / net / bnxt / tf_core / tf_core.h
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2019-2021 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_cfa_defs.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  * External memory control channel type
48  */
49 enum tf_ext_mem_chan_type {
50         /**
51          * Direct memory write(Wh+/SR)
52          */
53         TF_EXT_MEM_CHAN_TYPE_DIRECT = 0,
54         /**
55          * Ring interface MPC
56          */
57         TF_EXT_MEM_CHAN_TYPE_RING_IF,
58         /**
59          * Use HWRM message to firmware
60          */
61         TF_EXT_MEM_CHAN_TYPE_FW,
62         /**
63          * Use ring_if message to firmware
64          */
65         TF_EXT_MEM_CHAN_TYPE_RING_IF_FW,
66         TF_EXT_MEM_CHAN_TYPE_MAX
67 };
68
69 /**
70  * EEM record AR helper
71  *
72  * Helper to handle the Action Record Pointer in the EEM Record Entry.
73  *
74  * Convert absolute offset to action record pointer in EEM record entry
75  * Convert action record pointer in EEM record entry to absolute offset
76  */
77 #define TF_ACT_REC_OFFSET_2_PTR(offset) ((offset) >> 4)
78 #define TF_ACT_REC_PTR_2_OFFSET(offset) ((offset) << 4)
79
80
81 /*
82  * Helper Macros
83  */
84 #define TF_BITS_2_BYTES(num_bits) (((num_bits) + 7) / 8)
85
86 /********** BEGIN API FUNCTION PROTOTYPES/PARAMETERS **********/
87
88 /**
89  * @page general General
90  *
91  * @ref tf_open_session
92  *
93  * @ref tf_attach_session
94  *
95  * @ref tf_close_session
96  */
97
98 /**
99  * Session Version defines
100  *
101  * The version controls the format of the tf_session and
102  * tf_session_info structure. This is to assure upgrade between
103  * versions can be supported.
104  */
105 #define TF_SESSION_VER_MAJOR  1   /**< Major Version */
106 #define TF_SESSION_VER_MINOR  0   /**< Minor Version */
107 #define TF_SESSION_VER_UPDATE 0   /**< Update Version */
108
109 /**
110  * Session Name
111  *
112  * Name of the TruFlow control channel interface.  Expects
113  * format to be RTE Name specific, i.e. rte_eth_dev_get_name_by_port()
114  */
115 #define TF_SESSION_NAME_MAX       64
116
117 #define TF_FW_SESSION_ID_INVALID  0xFF  /**< Invalid FW Session ID define */
118
119 /**
120  * Session Identifier
121  *
122  * Unique session identifier which includes PCIe bus info to
123  * distinguish the PF and session info to identify the associated
124  * TruFlow session. Session ID is constructed from the passed in
125  * ctrl_chan_name in tf_open_session() together with an allocated
126  * fw_session_id. Done by TruFlow on tf_open_session().
127  */
128 union tf_session_id {
129         uint32_t id;
130         struct {
131                 uint8_t domain;
132                 uint8_t bus;
133                 uint8_t device;
134                 uint8_t fw_session_id;
135         } internal;
136 };
137
138 /**
139  * Session Client Identifier
140  *
141  * Unique identifier for a client within a session. Session Client ID
142  * is constructed from the passed in session and a firmware allocated
143  * fw_session_client_id. Done by TruFlow on tf_open_session().
144  */
145 union tf_session_client_id {
146         uint16_t id;
147         struct {
148                 uint8_t fw_session_id;
149                 uint8_t fw_session_client_id;
150         } internal;
151 };
152
153 /**
154  * Session Version
155  *
156  * The version controls the format of the tf_session and
157  * tf_session_info structure. This is to assure upgrade between
158  * versions can be supported.
159  *
160  * Please see the TF_VER_MAJOR/MINOR and UPDATE defines.
161  */
162 struct tf_session_version {
163         uint8_t major;
164         uint8_t minor;
165         uint8_t update;
166 };
167
168 /**
169  * Session supported device types
170  */
171 enum tf_device_type {
172         TF_DEVICE_TYPE_WH = 0, /**< Whitney+  */
173         TF_DEVICE_TYPE_SR,     /**< Stingray  */
174         TF_DEVICE_TYPE_THOR,   /**< Thor      */
175         TF_DEVICE_TYPE_MAX     /**< Maximum   */
176 };
177
178 /**
179  * Module types
180  */
181 enum tf_module_type {
182         /**
183          * Identifier module
184          */
185         TF_MODULE_TYPE_IDENTIFIER,
186         /**
187          * Table type module
188          */
189         TF_MODULE_TYPE_TABLE,
190         /**
191          * TCAM module
192          */
193         TF_MODULE_TYPE_TCAM,
194         /**
195          * EM module
196          */
197         TF_MODULE_TYPE_EM,
198         TF_MODULE_TYPE_MAX
199 };
200
201
202 /**
203  * Identifier resource types
204  */
205 enum tf_identifier_type {
206         /**
207          *  WH/SR/TH
208          *  The L2 Context is returned from the L2 Ctxt TCAM lookup
209          *  and can be used in WC TCAM or EM keys to virtualize further
210          *  lookups.
211          */
212         TF_IDENT_TYPE_L2_CTXT_HIGH,
213         /**
214          *  WH/SR/TH
215          *  The L2 Context is returned from the L2 Ctxt TCAM lookup
216          *  and can be used in WC TCAM or EM keys to virtualize further
217          *  lookups.
218          */
219         TF_IDENT_TYPE_L2_CTXT_LOW,
220         /**
221          *  WH/SR/TH
222          *  The WC profile func is returned from the L2 Ctxt TCAM lookup
223          *  to enable virtualization of the profile TCAM.
224          */
225         TF_IDENT_TYPE_PROF_FUNC,
226         /**
227          *  WH/SR/TH
228          *  The WC profile ID is included in the WC lookup key
229          *  to enable virtualization of the WC TCAM hardware.
230          */
231         TF_IDENT_TYPE_WC_PROF,
232         /**
233          *  WH/SR/TH
234          *  The EM profile ID is included in the EM lookup key
235          *  to enable virtualization of the EM hardware.
236          */
237         TF_IDENT_TYPE_EM_PROF,
238         /**
239          *  TH
240          *  The L2 func is included in the ILT result and from recycling to
241          *  enable virtualization of further lookups.
242          */
243         TF_IDENT_TYPE_L2_FUNC,
244         TF_IDENT_TYPE_MAX
245 };
246
247 /**
248  * Enumeration of TruFlow table types. A table type is used to identify a
249  * resource object.
250  *
251  * NOTE: The table type TF_TBL_TYPE_EXT is unique in that it is
252  * the only table type that is connected with a table scope.
253  */
254 enum tf_tbl_type {
255         /* Internal */
256
257         /** Wh+/SR/TH Action Record */
258         TF_TBL_TYPE_FULL_ACT_RECORD,
259         /** TH Compact Action Record */
260         TF_TBL_TYPE_COMPACT_ACT_RECORD,
261         /** (Future) Multicast Groups */
262         TF_TBL_TYPE_MCAST_GROUPS,
263         /** Wh+/SR/TH Action Encap 8 Bytes */
264         TF_TBL_TYPE_ACT_ENCAP_8B,
265         /** Wh+/SR/TH Action Encap 16 Bytes */
266         TF_TBL_TYPE_ACT_ENCAP_16B,
267         /** WH+/SR/TH Action Encap 32 Bytes */
268         TF_TBL_TYPE_ACT_ENCAP_32B,
269         /** Wh+/SR/TH Action Encap 64 Bytes */
270         TF_TBL_TYPE_ACT_ENCAP_64B,
271         /** WH+/SR/TH Action Source Properties SMAC */
272         TF_TBL_TYPE_ACT_SP_SMAC,
273         /** Wh+/SR/TH Action Source Properties SMAC IPv4 */
274         TF_TBL_TYPE_ACT_SP_SMAC_IPV4,
275         /** WH+/SR/TH Action Source Properties SMAC IPv6 */
276         TF_TBL_TYPE_ACT_SP_SMAC_IPV6,
277         /** Wh+/SR/TH Action Statistics 64 Bits */
278         TF_TBL_TYPE_ACT_STATS_64,
279         /** Wh+/SR Action Modify IPv4 Source */
280         TF_TBL_TYPE_ACT_MODIFY_IPV4,
281         /** TH 8B Modify Record */
282         TF_TBL_TYPE_ACT_MODIFY_8B,
283         /** TH 16B Modify Record */
284         TF_TBL_TYPE_ACT_MODIFY_16B,
285         /** TH 32B Modify Record */
286         TF_TBL_TYPE_ACT_MODIFY_32B,
287         /** TH 64B Modify Record */
288         TF_TBL_TYPE_ACT_MODIFY_64B,
289         /** (Future) Meter Profiles */
290         TF_TBL_TYPE_METER_PROF,
291         /** (Future) Meter Instance */
292         TF_TBL_TYPE_METER_INST,
293         /** Wh+/SR/Th Mirror Config */
294         TF_TBL_TYPE_MIRROR_CONFIG,
295         /** (Future) UPAR */
296         TF_TBL_TYPE_UPAR,
297         /** (Future) TH Metadata  */
298         TF_TBL_TYPE_METADATA,
299         /** (Future) TH CT State  */
300         TF_TBL_TYPE_CT_STATE,
301         /** (Future) TH Range Profile  */
302         TF_TBL_TYPE_RANGE_PROF,
303         /** TH EM Flexible Key builder */
304         TF_TBL_TYPE_EM_FKB,
305         /** TH WC Flexible Key builder */
306         TF_TBL_TYPE_WC_FKB,
307
308         /* External */
309
310         /**
311          * External table type - initially 1 poolsize entries.
312          * All External table types are associated with a table
313          * scope. Internal types are not.  Currently this is
314          * a pool of 64B entries.
315          */
316         TF_TBL_TYPE_EXT,
317         TF_TBL_TYPE_MAX
318 };
319
320 /**
321  * TCAM table type
322  */
323 enum tf_tcam_tbl_type {
324         /** L2 Context TCAM */
325         TF_TCAM_TBL_TYPE_L2_CTXT_TCAM_HIGH,
326         /** L2 Context TCAM */
327         TF_TCAM_TBL_TYPE_L2_CTXT_TCAM_LOW,
328         /** Profile TCAM */
329         TF_TCAM_TBL_TYPE_PROF_TCAM,
330         /** Wildcard TCAM */
331         TF_TCAM_TBL_TYPE_WC_TCAM,
332         /** Source Properties TCAM */
333         TF_TCAM_TBL_TYPE_SP_TCAM,
334         /** Connection Tracking Rule TCAM */
335         TF_TCAM_TBL_TYPE_CT_RULE_TCAM,
336         /** Virtual Edge Bridge TCAM */
337         TF_TCAM_TBL_TYPE_VEB_TCAM,
338         TF_TCAM_TBL_TYPE_MAX
339 };
340
341 /**
342  * SEARCH STATUS
343  */
344 enum tf_search_status {
345         /** The entry was not found, but an idx was allocated if requested. */
346         MISS,
347         /** The entry was found, and the result/idx are valid */
348         HIT,
349         /** The entry was not found and the table is full */
350         REJECT
351 };
352
353 /**
354  * EM Resources
355  * These defines are provisioned during
356  * tf_open_session()
357  */
358 enum tf_em_tbl_type {
359         /** The number of internal EM records for the session */
360         TF_EM_TBL_TYPE_EM_RECORD,
361         /** The number of table scopes reequested */
362         TF_EM_TBL_TYPE_TBL_SCOPE,
363         TF_EM_TBL_TYPE_MAX
364 };
365
366 /**
367  * TruFlow Session Information
368  *
369  * Structure defining a TruFlow Session, also known as a Management
370  * session. This structure is initialized at time of
371  * tf_open_session(). It is passed to all of the TruFlow APIs as way
372  * to prescribe and isolate resources between different TruFlow ULP
373  * Applications.
374  *
375  * Ownership of the elements is split between ULP and TruFlow. Please
376  * see the individual elements.
377  */
378 struct tf_session_info {
379         /**
380          * TrueFlow Version. Used to control the structure layout when
381          * sharing sessions. No guarantee that a secondary process
382          * would come from the same version of an executable.
383          * TruFlow initializes this variable on tf_open_session().
384          *
385          * Owner:  TruFlow
386          * Access: TruFlow
387          */
388         struct tf_session_version ver;
389         /**
390          * will be STAILQ_ENTRY(tf_session_info) next
391          *
392          * Owner:  ULP
393          * Access: ULP
394          */
395         void                 *next;
396         /**
397          * Session ID is a unique identifier for the session. TruFlow
398          * initializes this variable during tf_open_session()
399          * processing.
400          *
401          * Owner:  TruFlow
402          * Access: Truflow & ULP
403          */
404         union tf_session_id   session_id;
405         /**
406          * Protects access to core_data. Lock is initialized and owned
407          * by ULP. TruFlow can access the core_data without checking
408          * the lock.
409          *
410          * Owner:  ULP
411          * Access: ULP
412          */
413         uint8_t               spin_lock;
414         /**
415          * The core_data holds the TruFlow tf_session data
416          * structure. This memory is allocated and owned by TruFlow on
417          * tf_open_session().
418          *
419          * TruFlow uses this memory for session management control
420          * until the session is closed by ULP. Access control is done
421          * by the spin_lock which ULP controls ahead of TruFlow API
422          * calls.
423          *
424          * Please see tf_open_session_parms for specification details
425          * on this variable.
426          *
427          * Owner:  TruFlow
428          * Access: TruFlow
429          */
430         void                 *core_data;
431         /**
432          * The core_data_sz_bytes specifies the size of core_data in
433          * bytes.
434          *
435          * The size is set by TruFlow on tf_open_session().
436          *
437          * Please see tf_open_session_parms for specification details
438          * on this variable.
439          *
440          * Owner:  TruFlow
441          * Access: TruFlow
442          */
443         uint32_t              core_data_sz_bytes;
444 };
445
446 /**
447  * TruFlow handle
448  *
449  * Contains a pointer to the session info. Allocated by ULP and passed
450  * to TruFlow using tf_open_session(). TruFlow will populate the
451  * session info at that time. A TruFlow Session can be used by more
452  * than one PF/VF by using the tf_open_session().
453  *
454  * It is expected that ULP allocates this memory as shared memory.
455  *
456  * NOTE: This struct must be within the BNXT PMD struct bnxt
457  *       (bp). This allows use of container_of() to get access to the PMD.
458  */
459 struct tf {
460         struct tf_session_info *session;
461         /**
462          * the pointer to the parent bp struct
463          */
464         void *bp;
465 };
466
467 /**
468  * Identifier resource definition
469  */
470 struct tf_identifier_resources {
471         /**
472          * Array of TF Identifiers where each entry is expected to be
473          * set to the requested resource number of that specific type.
474          * The index used is tf_identifier_type.
475          */
476         uint16_t cnt[TF_IDENT_TYPE_MAX];
477 };
478
479 /**
480  * Table type resource definition
481  */
482 struct tf_tbl_resources {
483         /**
484          * Array of TF Table types where each entry is expected to be
485          * set to the requeste resource number of that specific
486          * type. The index used is tf_tbl_type.
487          */
488         uint16_t cnt[TF_TBL_TYPE_MAX];
489 };
490
491 /**
492  * TCAM type resource definition
493  */
494 struct tf_tcam_resources {
495         /**
496          * Array of TF TCAM types where each entry is expected to be
497          * set to the requested resource number of that specific
498          * type. The index used is tf_tcam_tbl_type.
499          */
500         uint16_t cnt[TF_TCAM_TBL_TYPE_MAX];
501 };
502
503 /**
504  * EM type resource definition
505  */
506 struct tf_em_resources {
507         /**
508          * Array of TF EM table types where each entry is expected to
509          * be set to the requested resource number of that specific
510          * type. The index used is tf_em_tbl_type.
511          */
512         uint16_t cnt[TF_EM_TBL_TYPE_MAX];
513 };
514
515 /**
516  * tf_session_resources parameter definition.
517  */
518 struct tf_session_resources {
519         /**
520          * [in] Requested Identifier Resources
521          *
522          * Number of identifier resources requested for the
523          * session.
524          */
525         struct tf_identifier_resources ident_cnt[TF_DIR_MAX];
526         /**
527          * [in] Requested Index Table resource counts
528          *
529          * The number of index table resources requested for the
530          * session.
531          */
532         struct tf_tbl_resources tbl_cnt[TF_DIR_MAX];
533         /**
534          * [in] Requested TCAM Table resource counts
535          *
536          * The number of TCAM table resources requested for the
537          * session.
538          */
539
540         struct tf_tcam_resources tcam_cnt[TF_DIR_MAX];
541         /**
542          * [in] Requested EM resource counts
543          *
544          * The number of internal EM table resources requested for the
545          * session.
546          */
547         struct tf_em_resources em_cnt[TF_DIR_MAX];
548 };
549
550 /**
551  * tf_open_session parameters definition.
552  */
553 struct tf_open_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. The ctrl_chan_name is usually in format
565          * 0000:02:00.0. The name for shared session is 0000:02:00.0-tf_shared.
566          */
567         char ctrl_chan_name[TF_SESSION_NAME_MAX];
568         /**
569          * [in] shadow_copy
570          *
571          * Boolean controlling the use and availability of shadow
572          * copy. Shadow copy will allow the TruFlow to keep track of
573          * resource content on the firmware side without having to
574          * query firmware. Additional private session core_data will
575          * be allocated if this boolean is set to 'true', default
576          * 'false'.
577          *
578          * Size of memory depends on the NVM Resource settings for the
579          * control channel.
580          */
581         bool shadow_copy;
582         /**
583          * [in/out] session_id
584          *
585          * Session_id is unique per session.
586          *
587          * Session_id is composed of domain, bus, device and
588          * fw_session_id. The construction is done by parsing the
589          * ctrl_chan_name together with allocation of a fw_session_id.
590          *
591          * The session_id allows a session to be shared between devices.
592          */
593         union tf_session_id session_id;
594         /**
595          * [in/out] session_client_id
596          *
597          * Session_client_id is unique per client.
598          *
599          * Session_client_id is composed of session_id and the
600          * fw_session_client_id fw_session_id. The construction is
601          * done by parsing the ctrl_chan_name together with allocation
602          * of a fw_session_client_id during tf_open_session().
603          *
604          * A reference count will be incremented in the session on
605          * which a client is created.
606          *
607          * A session can first be closed if there is one Session
608          * Client left. Session Clients should closed using
609          * tf_close_session().
610          */
611         union tf_session_client_id session_client_id;
612         /**
613          * [in] device type
614          *
615          * Device type for the session.
616          */
617         enum tf_device_type device_type;
618         /**
619          * [in] resources
620          *
621          * Resource allocation for the session.
622          */
623         struct tf_session_resources resources;
624
625         /**
626          * [in] bp
627          * The pointer to the parent bp struct. This is only used for HWRM
628          * message passing within the portability layer. The type is struct
629          * bnxt.
630          */
631         void *bp;
632
633         /**
634          * [out] shared_session_creator
635          *
636          * Indicates whether the application created the session if set.
637          * Otherwise the shared session already existed.  Just for information
638          * purposes.
639          */
640         int shared_session_creator;
641 };
642
643 /**
644  * Opens a new TruFlow Session or session client.
645  *
646  * What gets created depends on the passed in tfp content. If the tfp does not
647  * have prior session data a new session with associated session client. If tfp
648  * has a session already a session client will be created. In both cases the
649  * session client is created using the provided ctrl_chan_name.
650  *
651  * In case of session creation TruFlow will allocate session specific memory to
652  * hold its session data. This data is private to TruFlow.
653  *
654  * No other TruFlow APIs will succeed unless this API is first called
655  * and succeeds.
656  *
657  * tf_open_session() returns a session id and session client id.  These are
658  * also stored within the tfp structure passed in to all other APIs.
659  *
660  * A Session or session client can be closed using tf_close_session().
661  *
662  * There are 2 types of sessions - shared and not.  For non-shared all
663  * the allocated resources are owned and managed by a single session instance.
664  * No other applications have access to the resources owned by the non-shared
665  * session.  For a shared session, resources are shared between 2 applications.
666  *
667  * When the caller of tf_open_session() sets the ctrl_chan_name[] to a name
668  * like "0000:02:00.0-tf_shared", it is a request to create a new "shared"
669  * session in the firmware or access the existing shared session. There is
670  * only 1 shared session that can be created. If the shared session has
671  * already been created in the firmware, this API will return this indication
672  * by clearing the shared_session_creator flag. Only the first shared session
673  * create will have the shared_session_creator flag set.
674  *
675  * The shared session should always be the first session to be created by
676  * application and the last session closed due to RM management preference.
677  *
678  * Sessions remain open in the firmware until the last client of the session
679  * closes the session (tf_close_session()).
680  *
681  * [in] tfp
682  *   Pointer to TF handle
683  *
684  * [in] parms
685  *   Pointer to open parameters
686  *
687  * Returns
688  *   - (0) if successful.
689  *   - (-EINVAL) on failure.
690  */
691 int tf_open_session(struct tf *tfp,
692                     struct tf_open_session_parms *parms);
693
694 /**
695  * General internal resource info
696  *
697  * TODO: remove tf_rm_new_entry structure and use this structure
698  * internally.
699  */
700 struct tf_resource_info {
701         uint16_t start;
702         uint16_t stride;
703 };
704
705 /**
706  * Identifier resource definition
707  */
708 struct tf_identifier_resource_info {
709         /**
710          * Array of TF Identifiers. The index used is tf_identifier_type.
711          */
712         struct tf_resource_info info[TF_IDENT_TYPE_MAX];
713 };
714
715 /**
716  * Table type resource info definition
717  */
718 struct tf_tbl_resource_info {
719         /**
720          * Array of TF Table types. The index used is tf_tbl_type.
721          */
722         struct tf_resource_info info[TF_TBL_TYPE_MAX];
723 };
724
725 /**
726  * TCAM type resource definition
727  */
728 struct tf_tcam_resource_info {
729         /**
730          * Array of TF TCAM types. The index used is tf_tcam_tbl_type.
731          */
732         struct tf_resource_info info[TF_TCAM_TBL_TYPE_MAX];
733 };
734
735 /**
736  * EM type resource definition
737  */
738 struct tf_em_resource_info {
739         /**
740          * Array of TF EM table types. The index used is tf_em_tbl_type.
741          */
742         struct tf_resource_info info[TF_EM_TBL_TYPE_MAX];
743 };
744
745 /**
746  * tf_session_resources parameter definition.
747  */
748 struct tf_session_resource_info {
749         /**
750          * [in] Requested Identifier Resources
751          *
752          * Number of identifier resources requested for the
753          * session.
754          */
755         struct tf_identifier_resource_info ident[TF_DIR_MAX];
756         /**
757          * [in] Requested Index Table resource counts
758          *
759          * The number of index table resources requested for the
760          * session.
761          */
762         struct tf_tbl_resource_info tbl[TF_DIR_MAX];
763         /**
764          * [in] Requested TCAM Table resource counts
765          *
766          * The number of TCAM table resources requested for the
767          * session.
768          */
769
770         struct tf_tcam_resource_info tcam[TF_DIR_MAX];
771         /**
772          * [in] Requested EM resource counts
773          *
774          * The number of internal EM table resources requested for the
775          * session.
776          */
777         struct tf_em_resource_info em[TF_DIR_MAX];
778 };
779
780 /**
781  * tf_get_session_resources parameter definition.
782  */
783 struct tf_get_session_info_parms {
784         /**
785          * [out] the structure is used to return the information of
786          * allocated resources.
787          *
788          */
789         struct tf_session_resource_info session_info;
790 };
791
792 /** (experimental)
793  * Gets info about a TruFlow Session
794  *
795  * Get info about the session which has been created.  Whether it exists and
796  * what resource start and stride offsets are in use.  This API is primarily
797  * intended to be used by an application which has created a shared session
798  * This application needs to obtain the resources which have already been
799  * allocated for the shared session.
800  *
801  * [in] tfp
802  *   Pointer to TF handle
803  *
804  * [in] parms
805  *   Pointer to get parameters
806  *
807  * Returns
808  *   - (0) if successful.
809  *   - (-EINVAL) on failure.
810  */
811 int tf_get_session_info(struct tf *tfp,
812                         struct tf_get_session_info_parms *parms);
813
814 /**
815  * Experimental
816  *
817  * tf_attach_session parameters definition.
818  */
819 struct tf_attach_session_parms {
820         /**
821          * [in] ctrl_chan_name
822          *
823          * String containing name of control channel interface to be
824          * used for this session to communicate with firmware.
825          *
826          * The ctrl_chan_name can be looked up by using
827          * rte_eth_dev_get_name_by_port() within the ULP.
828          *
829          * ctrl_chan_name will be used as part of a name for any
830          * shared memory allocation.
831          */
832         char ctrl_chan_name[TF_SESSION_NAME_MAX];
833
834         /**
835          * [in] attach_chan_name
836          *
837          * String containing name of attach channel interface to be
838          * used for this session.
839          *
840          * The attach_chan_name must be given to a 2nd process after
841          * the primary process has been created. This is the
842          * ctrl_chan_name of the primary process and is used to find
843          * the shared memory for the session that the attach is going
844          * to use.
845          */
846         char attach_chan_name[TF_SESSION_NAME_MAX];
847
848         /**
849          * [in] session_id
850          *
851          * Session_id is unique per session. For Attach the session_id
852          * should be the session_id that was returned on the first
853          * open.
854          *
855          * Session_id is composed of domain, bus, device and
856          * fw_session_id. The construction is done by parsing the
857          * ctrl_chan_name together with allocation of a fw_session_id
858          * during tf_open_session().
859          *
860          * A reference count will be incremented on attach. A session
861          * is first fully closed when reference count is zero by
862          * calling tf_close_session().
863          */
864         union tf_session_id session_id;
865 };
866
867 /**
868  * Experimental
869  *
870  * Allows a 2nd application instance to attach to an existing
871  * session. Used when a session is to be shared between two processes.
872  *
873  * Attach will increment a ref count as to manage the shared session data.
874  *
875  * [in] tfp
876  *   Pointer to TF handle
877  *
878  * [in] parms
879  *   Pointer to attach parameters
880  *
881  * Returns
882  *   - (0) if successful.
883  *   - (-EINVAL) on failure.
884  */
885 int tf_attach_session(struct tf *tfp,
886                       struct tf_attach_session_parms *parms);
887
888 /**
889  * Closes an existing session client or the session it self. The
890  * session client is default closed and if the session reference count
891  * is 0 then the session is closed as well.
892  *
893  * On session close all hardware and firmware state associated with
894  * the TruFlow application is cleaned up.
895  *
896  * The session client is extracted from the tfp. Thus tf_close_session()
897  * cannot close a session client on behalf of another function.
898  *
899  * Returns success or failure code.
900  */
901 int tf_close_session(struct tf *tfp);
902
903 /**
904  * @page  ident Identity Management
905  *
906  * @ref tf_alloc_identifier
907  *
908  * @ref tf_free_identifier
909  */
910 /**
911  * tf_alloc_identifier parameter definition
912  */
913 struct tf_alloc_identifier_parms {
914         /**
915          * [in]  receive or transmit direction
916          */
917         enum tf_dir dir;
918         /**
919          * [in] Identifier type
920          */
921         enum tf_identifier_type ident_type;
922         /**
923          * [out] Allocated identifier
924          */
925         uint32_t id;
926 };
927
928 /**
929  * tf_free_identifier parameter definition
930  */
931 struct tf_free_identifier_parms {
932         /**
933          * [in]  receive or transmit direction
934          */
935         enum tf_dir dir;
936         /**
937          * [in] Identifier type
938          */
939         enum tf_identifier_type ident_type;
940         /**
941          * [in] ID to free
942          */
943         uint32_t id;
944         /**
945          * (experimental)
946          * [out] Current refcnt after free
947          */
948         uint32_t ref_cnt;
949 };
950
951 /**
952  * tf_search_identifier parameter definition (experimental)
953  */
954 struct tf_search_identifier_parms {
955         /**
956          * [in]  receive or transmit direction
957          */
958         enum tf_dir dir;
959         /**
960          * [in] Identifier type
961          */
962         enum tf_identifier_type ident_type;
963         /**
964          * [in] Identifier data to search for
965          */
966         uint32_t search_id;
967         /**
968          * [out] Set if matching identifier found
969          */
970         bool hit;
971         /**
972          * [out] Current ref count after allocation
973          */
974         uint32_t ref_cnt;
975 };
976
977 /**
978  * allocate identifier resource
979  *
980  * TruFlow core will allocate a free id from the per identifier resource type
981  * pool reserved for the session during tf_open().  No firmware is involved.
982  *
983  * If shadow copy is enabled, the internal ref_cnt is set to 1 in the
984  * shadow table for a newly allocated resource.
985  *
986  * Returns success or failure code.
987  */
988 int tf_alloc_identifier(struct tf *tfp,
989                         struct tf_alloc_identifier_parms *parms);
990
991 /**
992  * free identifier resource
993  *
994  * TruFlow core will return an id back to the per identifier resource type pool
995  * reserved for the session.  No firmware is involved.  During tf_close, the
996  * complete pool is returned to the firmware.
997  *
998  * additional operation (experimental)
999  * Decrement reference count.  Only release resource once refcnt goes to 0 if
1000  * shadow copy is enabled.
1001  *
1002  * Returns success or failure code.
1003  */
1004 int tf_free_identifier(struct tf *tfp,
1005                        struct tf_free_identifier_parms *parms);
1006
1007 /**
1008  * Search identifier resource (experimental)
1009  *
1010  * If the shadow copy is enabled search_id is used to search for a matching
1011  * entry in the shadow table.  The shadow table consists of an array of
1012  * reference counts indexed by identifier.  If a matching entry is found hit is
1013  * set to TRUE, refcnt is increased by 1 and returned.  Otherwise, hit is
1014  * set to false and refcnt is set to 0.
1015  *
1016  * TODO: we may need a per table internal shadow copy enable flag to stage
1017  * the shadow table implementation.  We do not need the shadow table for other
1018  * tables at this time so we may only want to enable the identifier shadow.
1019  *
1020  * TODO: remove this pseudocode below added to show that if search fails
1021  * we shouldn't allocate a new entry but return.
1022  *
1023  * identifier alloc (search_en=1)
1024  * if (ident is allocated and ref_cnt >=1)
1025  *      return ident - hit is set, incr refcnt
1026  * else (not found)
1027  *      return
1028  *
1029  */
1030 int tf_search_identifier(struct tf *tfp,
1031                          struct tf_search_identifier_parms *parms);
1032
1033 /**
1034  * @page dram_table DRAM Table Scope Interface
1035  *
1036  * @ref tf_alloc_tbl_scope
1037  *
1038  * @ref tf_free_tbl_scope
1039  *
1040  * If we allocate the EEM memory from the core, we need to store it in
1041  * the shared session data structure to make sure it can be freed later.
1042  * (for example if the PF goes away)
1043  *
1044  * Current thought is that memory is allocated within core.
1045  */
1046
1047
1048 /**
1049  * tf_alloc_tbl_scope_parms definition
1050  */
1051 struct tf_alloc_tbl_scope_parms {
1052         /**
1053          * [in] All Maximum key size required.
1054          */
1055         uint16_t rx_max_key_sz_in_bits;
1056         /**
1057          * [in] Maximum Action size required (includes inlined items)
1058          */
1059         uint16_t rx_max_action_entry_sz_in_bits;
1060         /**
1061          * [in] Memory size in Megabytes
1062          * Total memory size allocated by user to be divided
1063          * up for actions, hash, counters.  Only inline external actions.
1064          * Use this variable or the number of flows, do not set both.
1065          */
1066         uint32_t rx_mem_size_in_mb;
1067         /**
1068          * [in] Number of flows * 1000. If set, rx_mem_size_in_mb must equal 0.
1069          */
1070         uint32_t rx_num_flows_in_k;
1071         /**
1072          * [in] SR2 only receive table access interface id
1073          */
1074         uint32_t rx_tbl_if_id;
1075         /**
1076          * [in] All Maximum key size required.
1077          */
1078         uint16_t tx_max_key_sz_in_bits;
1079         /**
1080          * [in] Maximum Action size required (includes inlined items)
1081          */
1082         uint16_t tx_max_action_entry_sz_in_bits;
1083         /**
1084          * [in] Memory size in Megabytes
1085          * Total memory size allocated by user to be divided
1086          * up for actions, hash, counters.  Only inline external actions.
1087          */
1088         uint32_t tx_mem_size_in_mb;
1089         /**
1090          * [in] Number of flows * 1000
1091          */
1092         uint32_t tx_num_flows_in_k;
1093         /**
1094          * [in] SR2 only receive table access interface id
1095          */
1096         uint32_t tx_tbl_if_id;
1097         /**
1098          * [in] Flush pending HW cached flows every 1/10th of value
1099          * set in seconds, both idle and active flows are flushed
1100          * from the HW cache. If set to 0, this feature will be disabled.
1101          */
1102         uint8_t hw_flow_cache_flush_timer;
1103         /**
1104          * [out] table scope identifier
1105          */
1106         uint32_t tbl_scope_id;
1107 };
1108 /**
1109  * tf_free_tbl_scope_parms definition
1110  */
1111 struct tf_free_tbl_scope_parms {
1112         /**
1113          * [in] table scope identifier
1114          */
1115         uint32_t tbl_scope_id;
1116 };
1117
1118 /**
1119  * tf_map_tbl_scope_parms definition
1120  */
1121 struct tf_map_tbl_scope_parms {
1122         /**
1123          * [in] table scope identifier
1124          */
1125         uint32_t tbl_scope_id;
1126         /**
1127          * [in] Which parifs are associated with this table scope.  Bit 0
1128          *      indicates parif 0.
1129          */
1130         uint16_t parif_bitmask;
1131 };
1132
1133 /**
1134  * allocate a table scope
1135  *
1136  * The scope is a software construct to identify an EEM table.  This function will
1137  * divide the hash memory/buckets and records according to the device
1138  * device constraints based upon calculations using either the number of flows
1139  * requested or the size of memory indicated.  Other parameters passed in
1140  * determine the configuration (maximum key size, maximum external action record
1141  * size).
1142  *
1143  * A single API is used to allocate a common table scope identifier in both
1144  * receive and transmit CFA. The scope identifier is common due to nature of
1145  * connection tracking sending notifications between RX and TX direction.
1146  *
1147  * The receive and transmit table access identifiers specify which rings will
1148  * be used to initialize table DRAM.  The application must ensure mutual
1149  * exclusivity of ring usage for table scope allocation and any table update
1150  * operations.
1151  *
1152  * The hash table buckets, EM keys, and EM lookup results are stored in the
1153  * memory allocated based on the rx_em_hash_mb/tx_em_hash_mb parameters.  The
1154  * hash table buckets are stored at the beginning of that memory.
1155  *
1156  * NOTE:  No EM internal setup is done here. On chip EM records are managed
1157  * internally by TruFlow core.
1158  *
1159  * Returns success or failure code.
1160  */
1161 int tf_alloc_tbl_scope(struct tf *tfp,
1162                        struct tf_alloc_tbl_scope_parms *parms);
1163
1164 /**
1165  * map a table scope (legacy device only Wh+/SR)
1166  *
1167  * Map a table scope to one or more partition interfaces (parifs).
1168  * The parif can be remapped in the L2 context lookup for legacy devices.  This
1169  * API allows a number of parifs to be mapped to the same table scope.  On
1170  * legacy devices a table scope identifies one of 16 sets of EEM table base
1171  * addresses and is associated with a PF communication channel.  The associated
1172  * PF must be configured for the table scope to operate.
1173  *
1174  * An L2 context TCAM lookup returns a remapped parif value used to
1175  * index into the set of 16 parif_to_pf registers which are used to map to one
1176  * of the 16 table scopes.  This API allows the user to map the parifs in the
1177  * mask to the previously allocated table scope (EEM table).
1178
1179  * Returns success or failure code.
1180  */
1181 int tf_map_tbl_scope(struct tf *tfp,
1182                       struct tf_map_tbl_scope_parms *parms);
1183 /**
1184  * free a table scope
1185  *
1186  * Firmware checks that the table scope ID is owned by the TruFlow
1187  * session, verifies that no references to this table scope remains
1188  * or Profile TCAM entries for either CFA (RX/TX) direction,
1189  * then frees the table scope ID.
1190  *
1191  * Returns success or failure code.
1192  */
1193 int tf_free_tbl_scope(struct tf *tfp,
1194                       struct tf_free_tbl_scope_parms *parms);
1195
1196 /**
1197  * @page tcam TCAM Access
1198  *
1199  * @ref tf_search_tcam_entry
1200  *
1201  * @ref tf_alloc_tcam_entry
1202  *
1203  * @ref tf_set_tcam_entry
1204  *
1205  * @ref tf_get_tcam_entry
1206  *
1207  * @ref tf_free_tcam_entry
1208  */
1209
1210 /**
1211  * tf_search_tcam_entry parameter definition (experimental)
1212  */
1213 struct tf_search_tcam_entry_parms {
1214         /**
1215          * [in] receive or transmit direction
1216          */
1217         enum tf_dir dir;
1218         /**
1219          * [in] TCAM table type
1220          */
1221         enum tf_tcam_tbl_type tcam_tbl_type;
1222         /**
1223          * [in] Key data to match on
1224          */
1225         uint8_t *key;
1226         /**
1227          * [in] key size in bits
1228          */
1229         uint16_t key_sz_in_bits;
1230         /**
1231          * [in] Mask data to match on
1232          */
1233         uint8_t *mask;
1234         /**
1235          * [in] Priority of entry requested (definition TBD)
1236          */
1237         uint32_t priority;
1238         /**
1239          * [in] Allocate on miss.
1240          */
1241         uint8_t alloc;
1242         /**
1243          * [out] Set if matching entry found
1244          */
1245         uint8_t hit;
1246         /**
1247          * [out] Search result status (hit, miss, reject)
1248          */
1249         enum tf_search_status search_status;
1250         /**
1251          * [out] Current refcnt after allocation
1252          */
1253         uint16_t ref_cnt;
1254         /**
1255          * [in out] The result data from the search is copied here
1256          */
1257         uint8_t *result;
1258         /**
1259          * [in out] result size in bits for the result data
1260          */
1261         uint16_t result_sz_in_bits;
1262         /**
1263          * [out] Index found
1264          */
1265         uint16_t idx;
1266 };
1267
1268 /**
1269  * search TCAM entry (experimental)
1270  *
1271  * Search for a TCAM entry
1272  *
1273  * This function searches the shadow copy of the TCAM table for a matching
1274  * entry.  Key and mask must match for hit to be set.  Only TruFlow core data
1275  * is accessed.  If shadow_copy is not enabled, an error is returned.
1276  *
1277  * Implementation:
1278  *
1279  * A hash is performed on the key/mask data and mapped to a shadow copy entry
1280  * where the full key/mask is populated.  If the full key/mask matches the
1281  * entry, hit is set, ref_cnt is incremented, and search_status indicates what
1282  * action the caller can take regarding setting the entry.
1283  *
1284  * search_status should be used as follows:
1285  * - On Miss, the caller should create a result and call tf_set_tcam_entry with
1286  * returned index.
1287  *
1288  * - On Reject, the hash table is full and the entry cannot be added.
1289  *
1290  * - On Hit, the result data is returned to the caller.  Additionally, the
1291  * ref_cnt is updated.
1292  *
1293  * Also returns success or failure code.
1294  */
1295 int tf_search_tcam_entry(struct tf *tfp,
1296                          struct tf_search_tcam_entry_parms *parms);
1297
1298 /**
1299  * tf_alloc_tcam_entry parameter definition
1300  */
1301 struct tf_alloc_tcam_entry_parms {
1302         /**
1303          * [in] receive or transmit direction
1304          */
1305         enum tf_dir dir;
1306         /**
1307          * [in] TCAM table type
1308          */
1309         enum tf_tcam_tbl_type tcam_tbl_type;
1310         /**
1311          * [in] Enable search for matching entry
1312          */
1313         uint8_t search_enable;
1314         /**
1315          * [in] Key data to match on (if search)
1316          */
1317         uint8_t *key;
1318         /**
1319          * [in] key size in bits (if search)
1320          */
1321         uint16_t key_sz_in_bits;
1322         /**
1323          * [in] Mask data to match on (if search)
1324          */
1325         uint8_t *mask;
1326         /**
1327          * [in] Priority of entry requested (definition TBD)
1328          */
1329         uint32_t priority;
1330         /**
1331          * [out] If search, set if matching entry found
1332          */
1333         uint8_t hit;
1334         /**
1335          * [out] Current refcnt after allocation
1336          */
1337         uint16_t ref_cnt;
1338         /**
1339          * [out] Idx allocated
1340          *
1341          */
1342         uint16_t idx;
1343 };
1344
1345 /**
1346  * allocate TCAM entry
1347  *
1348  * Allocate a TCAM entry - one of these types:
1349  *
1350  * L2 Context
1351  * Profile TCAM
1352  * WC TCAM
1353  * VEB TCAM
1354  *
1355  * This function allocates a TCAM table record.  This function
1356  * will attempt to allocate a TCAM table entry from the session
1357  * owned TCAM entries or search a shadow copy of the TCAM table for a
1358  * matching entry if search is enabled.  Key, mask and result must match for
1359  * hit to be set.  Only TruFlow core data is accessed.
1360  * A hash table to entry mapping is maintained for search purposes.  If
1361  * search is not enabled, the first available free entry is returned based
1362  * on priority and alloc_cnt is set to 1.  If search is enabled and a matching
1363  * entry to entry_data is found, hit is set to TRUE and alloc_cnt is set to 1.
1364  * RefCnt is also returned.
1365  *
1366  * Also returns success or failure code.
1367  */
1368 int tf_alloc_tcam_entry(struct tf *tfp,
1369                         struct tf_alloc_tcam_entry_parms *parms);
1370
1371 /**
1372  * tf_set_tcam_entry parameter definition
1373  */
1374 struct  tf_set_tcam_entry_parms {
1375         /**
1376          * [in] receive or transmit direction
1377          */
1378         enum tf_dir dir;
1379         /**
1380          * [in] TCAM table type
1381          */
1382         enum tf_tcam_tbl_type tcam_tbl_type;
1383         /**
1384          * [in] base index of the entry to program
1385          */
1386         uint16_t idx;
1387         /**
1388          * [in] struct containing key
1389          */
1390         uint8_t *key;
1391         /**
1392          * [in] struct containing mask fields
1393          */
1394         uint8_t *mask;
1395         /**
1396          * [in] key size in bits (if search)
1397          */
1398         uint16_t key_sz_in_bits;
1399         /**
1400          * [in] struct containing result
1401          */
1402         uint8_t *result;
1403         /**
1404          * [in] struct containing result size in bits
1405          */
1406         uint16_t result_sz_in_bits;
1407 };
1408
1409 /**
1410  * set TCAM entry
1411  *
1412  * Program a TCAM table entry for a TruFlow session.
1413  *
1414  * If the entry has not been allocated, an error will be returned.
1415  *
1416  * Returns success or failure code.
1417  */
1418 int tf_set_tcam_entry(struct tf *tfp,
1419                       struct tf_set_tcam_entry_parms *parms);
1420
1421 /**
1422  * tf_get_tcam_entry parameter definition
1423  */
1424 struct tf_get_tcam_entry_parms {
1425         /**
1426          * [in] receive or transmit direction
1427          */
1428         enum tf_dir dir;
1429         /**
1430          * [in] TCAM table type
1431          */
1432         enum tf_tcam_tbl_type  tcam_tbl_type;
1433         /**
1434          * [in] index of the entry to get
1435          */
1436         uint16_t idx;
1437         /**
1438          * [out] struct containing key
1439          */
1440         uint8_t *key;
1441         /**
1442          * [out] struct containing mask fields
1443          */
1444         uint8_t *mask;
1445         /**
1446          * [in/out] key size in bits
1447          */
1448         uint16_t key_sz_in_bits;
1449         /**
1450          * [out] struct containing result
1451          */
1452         uint8_t *result;
1453         /**
1454          * [in/out] struct containing result size in bits
1455          */
1456         uint16_t result_sz_in_bits;
1457 };
1458
1459 /**
1460  * get TCAM entry
1461  *
1462  * Program a TCAM table entry for a TruFlow session.
1463  *
1464  * If the entry has not been allocated, an error will be returned.
1465  *
1466  * Returns success or failure code.
1467  */
1468 int tf_get_tcam_entry(struct tf *tfp,
1469                       struct tf_get_tcam_entry_parms *parms);
1470
1471 /**
1472  * tf_free_tcam_entry parameter definition
1473  */
1474 struct tf_free_tcam_entry_parms {
1475         /**
1476          * [in] receive or transmit direction
1477          */
1478         enum tf_dir dir;
1479         /**
1480          * [in] TCAM table type
1481          */
1482         enum tf_tcam_tbl_type tcam_tbl_type;
1483         /**
1484          * [in] Index to free
1485          */
1486         uint16_t idx;
1487         /**
1488          * [out] reference count after free
1489          */
1490         uint16_t ref_cnt;
1491 };
1492
1493 /**
1494  * free TCAM entry
1495  *
1496  * Free TCAM entry.
1497  *
1498  * Firmware checks to ensure the TCAM entries are owned by the TruFlow
1499  * session.  TCAM entry will be invalidated.  All-ones mask.
1500  * writes to hw.
1501  *
1502  * WCTCAM profile id of 0 must be used to invalidate an entry.
1503  *
1504  * Returns success or failure code.
1505  */
1506 int tf_free_tcam_entry(struct tf *tfp,
1507                        struct tf_free_tcam_entry_parms *parms);
1508
1509 /**
1510  * @page table Table Access
1511  *
1512  * @ref tf_alloc_tbl_entry
1513  *
1514  * @ref tf_free_tbl_entry
1515  *
1516  * @ref tf_set_tbl_entry
1517  *
1518  * @ref tf_get_tbl_entry
1519  *
1520  * @ref tf_bulk_get_tbl_entry
1521  */
1522
1523 /**
1524  * tf_alloc_tbl_entry parameter definition
1525  */
1526 struct tf_search_tbl_entry_parms {
1527         /**
1528          * [in] Receive or transmit direction
1529          */
1530         enum tf_dir dir;
1531         /**
1532          * [in] Type of the allocation
1533          */
1534         enum tf_tbl_type type;
1535         /**
1536          * [in] Table scope identifier (ignored unless TF_TBL_TYPE_EXT)
1537          */
1538         uint32_t tbl_scope_id;
1539         /**
1540          * [in] Result data to search for
1541          */
1542         uint8_t *result;
1543         /**
1544          * [in] Result data size in bytes
1545          */
1546         uint16_t result_sz_in_bytes;
1547         /**
1548          * [in] Allocate on miss.
1549          */
1550         uint8_t alloc;
1551         /**
1552          * [out] Set if matching entry found
1553          */
1554         uint8_t hit;
1555         /**
1556          * [out] Search result status (hit, miss, reject)
1557          */
1558         enum tf_search_status search_status;
1559         /**
1560          * [out] Current ref count after allocation
1561          */
1562         uint16_t ref_cnt;
1563         /**
1564          * [out] Idx of allocated entry or found entry
1565          */
1566         uint32_t idx;
1567 };
1568
1569 /**
1570  * search Table Entry (experimental)
1571  *
1572  * This function searches the shadow copy of an index table for a matching
1573  * entry.  The result data must match for hit to be set.  Only TruFlow core
1574  * data is accessed.  If shadow_copy is not enabled, an error is returned.
1575  *
1576  * Implementation:
1577  *
1578  * A hash is performed on the result data and mappe3d to a shadow copy entry
1579  * where the result is populated.  If the result matches the entry, hit is set,
1580  * ref_cnt is incremented (if alloc), and the search status indicates what
1581  * action the caller can take regarding setting the entry.
1582  *
1583  * search status should be used as follows:
1584  * - On MISS, the caller should set the result into the returned index.
1585  *
1586  * - On REJECT, the caller should reject the flow since there are no resources.
1587  *
1588  * - On Hit, the matching index is returned to the caller.  Additionally, the
1589  *   ref_cnt is updated.
1590  *
1591  * Also returns success or failure code.
1592  */
1593 int tf_search_tbl_entry(struct tf *tfp,
1594                         struct tf_search_tbl_entry_parms *parms);
1595
1596 /**
1597  * tf_alloc_tbl_entry parameter definition
1598  */
1599 struct tf_alloc_tbl_entry_parms {
1600         /**
1601          * [in] Receive or transmit direction
1602          */
1603         enum tf_dir dir;
1604         /**
1605          * [in] Type of the allocation
1606          */
1607         enum tf_tbl_type type;
1608         /**
1609          * [in] Table scope identifier (ignored unless TF_TBL_TYPE_EXT)
1610          */
1611         uint32_t tbl_scope_id;
1612         /**
1613          * [in] Enable search for matching entry. If the table type is
1614          * internal the shadow copy will be searched before
1615          * alloc. Session must be configured with shadow copy enabled.
1616          */
1617         uint8_t search_enable;
1618         /**
1619          * [in] Result data to search for (if search_enable)
1620          */
1621         uint8_t *result;
1622         /**
1623          * [in] Result data size in bytes (if search_enable)
1624          */
1625         uint16_t result_sz_in_bytes;
1626         /**
1627          * [out] If search_enable, set if matching entry found
1628          */
1629         uint8_t hit;
1630         /**
1631          * [out] Current ref count after allocation (if search_enable)
1632          */
1633         uint16_t ref_cnt;
1634         /**
1635          * [out] Idx of allocated entry or found entry (if search_enable)
1636          */
1637         uint32_t idx;
1638 };
1639
1640 /**
1641  * allocate index table entries
1642  *
1643  * Internal types:
1644  *
1645  * Allocate an on chip index table entry or search for a matching
1646  * entry of the indicated type for this TruFlow session.
1647  *
1648  * Allocates an index table record. This function will attempt to
1649  * allocate an entry or search an index table for a matching entry if
1650  * search is enabled (only the shadow copy of the table is accessed).
1651  *
1652  * If search is not enabled, the first available free entry is
1653  * returned. If search is enabled and a matching entry to entry_data
1654  * is found hit is set to TRUE and success is returned.
1655  *
1656  * External types:
1657  *
1658  * These are used to allocate inlined action record memory.
1659  *
1660  * Allocates an external index table action record.
1661  *
1662  * NOTE:
1663  * Implementation of the internals of this function will be a stack with push
1664  * and pop.
1665  *
1666  * Returns success or failure code.
1667  */
1668 int tf_alloc_tbl_entry(struct tf *tfp,
1669                        struct tf_alloc_tbl_entry_parms *parms);
1670
1671 /**
1672  * tf_free_tbl_entry parameter definition
1673  */
1674 struct tf_free_tbl_entry_parms {
1675         /**
1676          * [in] Receive or transmit direction
1677          */
1678         enum tf_dir dir;
1679         /**
1680          * [in] Type of the allocation type
1681          */
1682         enum tf_tbl_type type;
1683         /**
1684          * [in] Table scope identifier (ignored unless TF_TBL_TYPE_EXT)
1685          */
1686         uint32_t tbl_scope_id;
1687         /**
1688          * [in] Index to free
1689          */
1690         uint32_t idx;
1691         /**
1692          * [out] Reference count after free, only valid if session has been
1693          * created with shadow_copy.
1694          */
1695         uint16_t ref_cnt;
1696 };
1697
1698 /**
1699  * free index table entry
1700  *
1701  * Used to free a previously allocated table entry.
1702  *
1703  * Internal types:
1704  *
1705  * If session has shadow_copy enabled the shadow DB is searched and if
1706  * found the element ref_cnt is decremented. If ref_cnt goes to
1707  * zero then the element is returned to the session pool.
1708  *
1709  * If the session does not have a shadow DB the element is free'ed and
1710  * given back to the session pool.
1711  *
1712  * External types:
1713  *
1714  * Free's an external index table action record.
1715  *
1716  * NOTE:
1717  * Implementation of the internals of this function will be a stack with push
1718  * and pop.
1719  *
1720  * Returns success or failure code.
1721  */
1722 int tf_free_tbl_entry(struct tf *tfp,
1723                       struct tf_free_tbl_entry_parms *parms);
1724
1725 /**
1726  * tf_set_tbl_entry parameter definition
1727  */
1728 struct tf_set_tbl_entry_parms {
1729         /**
1730          * [in] Table scope identifier
1731          */
1732         uint32_t tbl_scope_id;
1733         /**
1734          * [in] Receive or transmit direction
1735          */
1736         enum tf_dir dir;
1737         /**
1738          * [in] Type of object to set
1739          */
1740         enum tf_tbl_type type;
1741         /**
1742          * [in] Entry data
1743          */
1744         uint8_t *data;
1745         /**
1746          * [in] Entry size
1747          */
1748         uint16_t data_sz_in_bytes;
1749         /**
1750          * [in] External memory channel type to use
1751          */
1752         enum tf_ext_mem_chan_type chan_type;
1753         /**
1754          * [in] Entry index to write to
1755          */
1756         uint32_t idx;
1757 };
1758
1759 /**
1760  * set index table entry
1761  *
1762  * Used to insert an application programmed index table entry into a
1763  * previous allocated table location.  A shadow copy of the table
1764  * is maintained (if enabled) (only for internal objects)
1765  *
1766  * Returns success or failure code.
1767  */
1768 int tf_set_tbl_entry(struct tf *tfp,
1769                      struct tf_set_tbl_entry_parms *parms);
1770
1771 /**
1772  * tf_get_tbl_entry parameter definition
1773  */
1774 struct tf_get_tbl_entry_parms {
1775         /**
1776          * [in] Receive or transmit direction
1777          */
1778         enum tf_dir dir;
1779         /**
1780          * [in] Type of object to get
1781          */
1782         enum tf_tbl_type type;
1783         /**
1784          * [out] Entry data
1785          */
1786         uint8_t *data;
1787         /**
1788          * [in] Entry size
1789          */
1790         uint16_t data_sz_in_bytes;
1791         /**
1792          * [in] External memory channel type to use
1793          */
1794         enum tf_ext_mem_chan_type chan_type;
1795         /**
1796          * [in] Entry index to read
1797          */
1798         uint32_t idx;
1799 };
1800
1801 /**
1802  * get index table entry
1803  *
1804  * Used to retrieve a previous set index table entry.
1805  *
1806  * Reads and compares with the shadow table copy (if enabled) (only
1807  * for internal objects).
1808  *
1809  * Returns success or failure code. Failure will be returned if the
1810  * provided data buffer is too small for the data type requested.
1811  */
1812 int tf_get_tbl_entry(struct tf *tfp,
1813                      struct tf_get_tbl_entry_parms *parms);
1814
1815 /**
1816  * tf_bulk_get_tbl_entry parameter definition
1817  */
1818 struct tf_bulk_get_tbl_entry_parms {
1819         /**
1820          * [in] Receive or transmit direction
1821          */
1822         enum tf_dir dir;
1823         /**
1824          * [in] Type of object to get
1825          */
1826         enum tf_tbl_type type;
1827         /**
1828          * [in] Starting index to read from
1829          */
1830         uint32_t starting_idx;
1831         /**
1832          * [in] Number of sequential entries
1833          */
1834         uint16_t num_entries;
1835         /**
1836          * [in] Size of the single entry
1837          */
1838         uint16_t entry_sz_in_bytes;
1839         /**
1840          * [out] Host physical address, where the data
1841          * will be copied to by the firmware.
1842          * Use tfp_calloc() API and mem_pa
1843          * variable of the tfp_calloc_parms
1844          * structure for the physical address.
1845          */
1846         uint64_t physical_mem_addr;
1847         /**
1848          * [in] External memory channel type to use
1849          */
1850         enum tf_ext_mem_chan_type chan_type;
1851 };
1852
1853 /**
1854  * Bulk get index table entry
1855  *
1856  * Used to retrieve a set of index table entries.
1857  *
1858  * Entries within the range may not have been allocated using
1859  * tf_alloc_tbl_entry() at the time of access. But the range must
1860  * be within the bounds determined from tf_open_session() for the
1861  * given table type.  Currently, this is only used for collecting statistics.
1862  *
1863  * Returns success or failure code. Failure will be returned if the
1864  * provided data buffer is too small for the data type requested.
1865  */
1866 int tf_bulk_get_tbl_entry(struct tf *tfp,
1867                           struct tf_bulk_get_tbl_entry_parms *parms);
1868
1869 /**
1870  * @page exact_match Exact Match Table
1871  *
1872  * @ref tf_insert_em_entry
1873  *
1874  * @ref tf_delete_em_entry
1875  *
1876  * @ref tf_search_em_entry
1877  *
1878  */
1879 /**
1880  * tf_insert_em_entry parameter definition
1881  */
1882 struct tf_insert_em_entry_parms {
1883         /**
1884          * [in] receive or transmit direction
1885          */
1886         enum tf_dir dir;
1887         /**
1888          * [in] internal or external
1889          */
1890         enum tf_mem mem;
1891         /**
1892          * [in] ID of table scope to use (external only)
1893          */
1894         uint32_t tbl_scope_id;
1895         /**
1896          * [in] ptr to structure containing key fields
1897          */
1898         uint8_t *key;
1899         /**
1900          * [in] key bit length
1901          */
1902         uint16_t key_sz_in_bits;
1903         /**
1904          * [in] ptr to structure containing result field
1905          */
1906         uint8_t *em_record;
1907         /**
1908          * [out] result size in bits
1909          */
1910         uint16_t em_record_sz_in_bits;
1911         /**
1912          * [in] duplicate check flag
1913          */
1914         uint8_t dup_check;
1915         /**
1916          * [in] External memory channel type to use
1917          */
1918         enum tf_ext_mem_chan_type chan_type;
1919         /**
1920          * [out] Flow handle value for the inserted entry.  This is encoded
1921          * as the entries[4]:bucket[2]:hashId[1]:hash[14]
1922          */
1923         uint64_t flow_handle;
1924         /**
1925          * [out] Flow id is returned as null (internal)
1926          * Flow id is the GFID value for the inserted entry (external)
1927          * This is the value written to the BD and useful information for mark.
1928          */
1929         uint64_t flow_id;
1930 };
1931 /**
1932  * tf_delete_em_entry parameter definition
1933  */
1934 struct tf_delete_em_entry_parms {
1935         /**
1936          * [in] receive or transmit direction
1937          */
1938         enum tf_dir dir;
1939         /**
1940          * [in] internal or external
1941          */
1942         enum tf_mem mem;
1943         /**
1944          * [in] ID of table scope to use (external only)
1945          */
1946         uint32_t tbl_scope_id;
1947         /**
1948          * [out] The index of the entry
1949          */
1950         uint16_t index;
1951         /**
1952          * [in] External memory channel type to use
1953          */
1954         enum tf_ext_mem_chan_type chan_type;
1955         /**
1956          * [in] structure containing flow delete handle information
1957          */
1958         uint64_t flow_handle;
1959 };
1960 /**
1961  * tf_move_em_entry parameter definition
1962  */
1963 struct tf_move_em_entry_parms {
1964         /**
1965          * [in] receive or transmit direction
1966          */
1967         enum tf_dir dir;
1968         /**
1969          * [in] internal or external
1970          */
1971         enum tf_mem mem;
1972         /**
1973          * [in] ID of table scope to use (external only)
1974          */
1975         uint32_t tbl_scope_id;
1976         /**
1977          * [in] ID of table interface to use (SR2 only)
1978          */
1979         uint32_t tbl_if_id;
1980         /**
1981          * [in] epoch group IDs of entry to delete
1982          * 2 element array with 2 ids. (SR2 only)
1983          */
1984         uint16_t *epochs;
1985         /**
1986          * [out] The index of the entry
1987          */
1988         uint16_t index;
1989         /**
1990          * [in] External memory channel type to use
1991          */
1992         enum tf_ext_mem_chan_type chan_type;
1993         /**
1994          * [in] The index of the new EM record
1995          */
1996         uint32_t new_index;
1997         /**
1998          * [in] structure containing flow delete handle information
1999          */
2000         uint64_t flow_handle;
2001 };
2002 /**
2003  * tf_search_em_entry parameter definition
2004  */
2005 struct tf_search_em_entry_parms {
2006         /**
2007          * [in] receive or transmit direction
2008          */
2009         enum tf_dir dir;
2010         /**
2011          * [in] internal or external
2012          */
2013         enum tf_mem mem;
2014         /**
2015          * [in] ID of table scope to use (external only)
2016          */
2017         uint32_t tbl_scope_id;
2018         /**
2019          * [in] ptr to structure containing key fields
2020          */
2021         uint8_t *key;
2022         /**
2023          * [in] key bit length
2024          */
2025         uint16_t key_sz_in_bits;
2026         /**
2027          * [in/out] ptr to structure containing EM record fields
2028          */
2029         uint8_t *em_record;
2030         /**
2031          * [out] result size in bits
2032          */
2033         uint16_t em_record_sz_in_bits;
2034         /**
2035          * [in] External memory channel type to use
2036          */
2037         enum tf_ext_mem_chan_type chan_type;
2038         /**
2039          * [in] ptr to structure containing flow delete handle
2040          */
2041         uint64_t flow_handle;
2042 };
2043
2044 /**
2045  * insert em hash entry in internal table memory
2046  *
2047  * Internal:
2048  *
2049  * This API inserts an exact match entry into internal EM table memory
2050  * of the specified direction.
2051  *
2052  * Note: The EM record is managed within the TruFlow core and not the
2053  * application.
2054  *
2055  * Shadow copy of internal record table an association with hash and 1,2, or 4
2056  * associated buckets
2057  *
2058  * External:
2059  * This API inserts an exact match entry into DRAM EM table memory of the
2060  * specified direction and table scope.
2061  *
2062  * The insertion of duplicate entries in an EM table is not permitted.  If a
2063  * TruFlow application can guarantee that it will never insert duplicates, it
2064  * can disable duplicate checking by passing a zero value in the  dup_check
2065  * parameter to this API.  This will optimize performance. Otherwise, the
2066  * TruFlow library will enforce protection against inserting duplicate entries.
2067  *
2068  * Flow handle is defined in this document:
2069  *
2070  * https://docs.google.com
2071  * /document/d/1NESu7RpTN3jwxbokaPfYORQyChYRmJgs40wMIRe8_-Q/edit
2072  *
2073  * Returns success or busy code.
2074  *
2075  */
2076 int tf_insert_em_entry(struct tf *tfp,
2077                        struct tf_insert_em_entry_parms *parms);
2078
2079 /**
2080  * delete em hash entry table memory
2081  *
2082  * Internal:
2083  *
2084  * This API deletes an exact match entry from internal EM table memory of the
2085  * specified direction. If a valid flow ptr is passed in then that takes
2086  * precedence over the pointer to the complete key passed in.
2087  *
2088  *
2089  * External:
2090  *
2091  * This API deletes an exact match entry from EM table memory of the specified
2092  * direction and table scope. If a valid flow handle is passed in then that
2093  * takes precedence over the pointer to the complete key passed in.
2094  *
2095  * The TruFlow library may release a dynamic bucket when an entry is deleted.
2096  *
2097  *
2098  * Returns success or not found code
2099  *
2100  *
2101  */
2102 int tf_delete_em_entry(struct tf *tfp,
2103                        struct tf_delete_em_entry_parms *parms);
2104
2105 /**
2106  * search em hash entry table memory
2107  *
2108  * Internal:
2109
2110  * This API looks up an EM entry in table memory with the specified EM
2111  * key or flow (flow takes precedence) and direction.
2112  *
2113  * The status will be one of: success or entry not found.  If the lookup
2114  * succeeds, a pointer to the matching entry and the result record associated
2115  * with the matching entry will be provided.
2116  *
2117  * If flow_handle is set, search shadow copy.
2118  *
2119  * Otherwise, query the fw with key to get result.
2120  *
2121  * External:
2122  *
2123  * This API looks up an EM entry in table memory with the specified EM
2124  * key or flow_handle (flow takes precedence), direction and table scope.
2125  *
2126  * The status will be one of: success or entry not found.  If the lookup
2127  * succeeds, a pointer to the matching entry and the result record associated
2128  * with the matching entry will be provided.
2129  *
2130  * Returns success or not found code
2131  *
2132  */
2133 int tf_search_em_entry(struct tf *tfp,
2134                        struct tf_search_em_entry_parms *parms);
2135
2136 /**
2137  * @page global Global Configuration
2138  *
2139  * @ref tf_set_global_cfg
2140  *
2141  * @ref tf_get_global_cfg
2142  */
2143 /**
2144  * Tunnel Encapsulation Offsets
2145  */
2146 enum tf_tunnel_encap_offsets {
2147         TF_TUNNEL_ENCAP_L2,
2148         TF_TUNNEL_ENCAP_NAT,
2149         TF_TUNNEL_ENCAP_MPLS,
2150         TF_TUNNEL_ENCAP_VXLAN,
2151         TF_TUNNEL_ENCAP_GENEVE,
2152         TF_TUNNEL_ENCAP_NVGRE,
2153         TF_TUNNEL_ENCAP_GRE,
2154         TF_TUNNEL_ENCAP_FULL_GENERIC
2155 };
2156 /**
2157  * Global Configuration Table Types
2158  */
2159 enum tf_global_config_type {
2160         TF_TUNNEL_ENCAP,  /**< Tunnel Encap Config(TECT) */
2161         TF_ACTION_BLOCK,  /**< Action Block Config(ABCR) */
2162         TF_COUNTER_CFG,   /**< Counter Configuration (CNTRS_CTRL) */
2163         TF_GLOBAL_CFG_TYPE_MAX
2164 };
2165
2166 /**
2167  * tf_global_cfg parameter definition
2168  */
2169 struct tf_global_cfg_parms {
2170         /**
2171          * [in] receive or transmit direction
2172          */
2173         enum tf_dir dir;
2174         /**
2175          * [in] Global config type
2176          */
2177         enum tf_global_config_type type;
2178         /**
2179          * [in] Offset @ the type
2180          */
2181         uint32_t offset;
2182         /**
2183          * [in/out] Value of the configuration
2184          * set - Read, Modify and Write
2185          * get - Read the full configuration
2186          */
2187         uint8_t *config;
2188         /**
2189          * [in] Configuration mask
2190          * set - Read, Modify with mask and Write
2191          * get - unused
2192          */
2193         uint8_t *config_mask;
2194         /**
2195          * [in] struct containing size
2196          */
2197         uint16_t config_sz_in_bytes;
2198 };
2199
2200 /**
2201  * Get global configuration
2202  *
2203  * Retrieve the configuration
2204  *
2205  * Returns success or failure code.
2206  */
2207 int tf_get_global_cfg(struct tf *tfp,
2208                       struct tf_global_cfg_parms *parms);
2209
2210 /**
2211  * Update the global configuration table
2212  *
2213  * Read, modify write the value.
2214  *
2215  * Returns success or failure code.
2216  */
2217 int tf_set_global_cfg(struct tf *tfp,
2218                       struct tf_global_cfg_parms *parms);
2219
2220 /**
2221  * @page if_tbl Interface Table Access
2222  *
2223  * @ref tf_set_if_tbl_entry
2224  *
2225  * @ref tf_get_if_tbl_entry
2226  *
2227  * @ref tf_restore_if_tbl_entry
2228  */
2229 /**
2230  * Enumeration of TruFlow interface table types.
2231  */
2232 enum tf_if_tbl_type {
2233         /** Default Profile L2 Context Entry */
2234         TF_IF_TBL_TYPE_PROF_SPIF_DFLT_L2_CTXT,
2235         /** Default Profile TCAM/Lookup Action Record Pointer Table */
2236         TF_IF_TBL_TYPE_PROF_PARIF_DFLT_ACT_REC_PTR,
2237         /** Error Profile TCAM Miss Action Record Pointer Table */
2238         TF_IF_TBL_TYPE_PROF_PARIF_ERR_ACT_REC_PTR,
2239         /** Default Error Profile TCAM Miss Action Record Pointer Table */
2240         TF_IF_TBL_TYPE_LKUP_PARIF_DFLT_ACT_REC_PTR,
2241         /** Ingress lookup table */
2242         TF_IF_TBL_TYPE_ILT,
2243         /** VNIC/SVIF Properties Table */
2244         TF_IF_TBL_TYPE_VSPT,
2245         TF_IF_TBL_TYPE_MAX
2246 };
2247
2248 /**
2249  * tf_set_if_tbl_entry parameter definition
2250  */
2251 struct tf_set_if_tbl_entry_parms {
2252         /**
2253          * [in] Receive or transmit direction
2254          */
2255         enum tf_dir dir;
2256         /**
2257          * [in] Type of object to set
2258          */
2259         enum tf_if_tbl_type type;
2260         /**
2261          * [in] Entry data
2262          */
2263         uint8_t *data;
2264         /**
2265          * [in] Entry size
2266          */
2267         uint16_t data_sz_in_bytes;
2268         /**
2269          * [in] Interface to write
2270          */
2271         uint32_t idx;
2272 };
2273
2274 /**
2275  * set interface table entry
2276  *
2277  * Used to set an interface table. This API is used for managing tables indexed
2278  * by SVIF/SPIF/PARIF interfaces. In current implementation only the value is
2279  * set.
2280  * Returns success or failure code.
2281  */
2282 int tf_set_if_tbl_entry(struct tf *tfp,
2283                         struct tf_set_if_tbl_entry_parms *parms);
2284
2285 /**
2286  * tf_get_if_tbl_entry parameter definition
2287  */
2288 struct tf_get_if_tbl_entry_parms {
2289         /**
2290          * [in] Receive or transmit direction
2291          */
2292         enum tf_dir dir;
2293         /**
2294          * [in] Type of table to get
2295          */
2296         enum tf_if_tbl_type type;
2297         /**
2298          * [out] Entry data
2299          */
2300         uint8_t *data;
2301         /**
2302          * [in] Entry size
2303          */
2304         uint16_t data_sz_in_bytes;
2305         /**
2306          * [in] Entry index to read
2307          */
2308         uint32_t idx;
2309 };
2310
2311 /**
2312  * get interface table entry
2313  *
2314  * Used to retrieve an interface table entry.
2315  *
2316  * Reads the interface table entry value
2317  *
2318  * Returns success or failure code. Failure will be returned if the
2319  * provided data buffer is too small for the data type requested.
2320  */
2321 int tf_get_if_tbl_entry(struct tf *tfp,
2322                         struct tf_get_if_tbl_entry_parms *parms);
2323
2324 #endif /* _TF_CORE_H_ */