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