2 /* SPDX-License-Identifier: BSD-3-Clause
3 * Copyright(c) 2014-2020 Broadcom
9 * \brief Exported functions for CFA HW programming
11 #ifndef _HCAPI_CFA_DEFS_H_
12 #define _HCAPI_CFA_DEFS_H_
20 #define SUPPORT_CFA_HW_ALL 0
21 #define SUPPORT_CFA_HW_P4 1
22 #define SUPPORT_CFA_HW_P58 0
23 #define SUPPORT_CFA_HW_P59 0
25 #define CFA_BITS_PER_BYTE (8)
26 #define __CFA_ALIGN_MASK(x, mask) (((x) + (mask)) & ~(mask))
27 #define CFA_ALIGN(x, a) __CFA_ALIGN_MASK(x, (a) - 1)
28 #define CFA_ALIGN_128(x) CFA_ALIGN(x, 128)
29 #define CFA_ALIGN_32(x) CFA_ALIGN(x, 32)
31 #define NUM_WORDS_ALIGN_32BIT(x) \
32 (CFA_ALIGN_32(x) / (sizeof(uint32_t) * CFA_BITS_PER_BYTE))
33 #define NUM_WORDS_ALIGN_128BIT(x) \
34 (CFA_ALIGN_128(x) / (sizeof(uint32_t) * CFA_BITS_PER_BYTE))
36 #define CFA_GLOBAL_CFG_DATA_SZ (100)
38 #include "hcapi_cfa_p4.h"
39 #define CFA_PROF_L2CTXT_TCAM_MAX_FIELD_CNT CFA_P40_PROF_L2_CTXT_TCAM_MAX_FLD
40 #define CFA_PROF_L2CTXT_REMAP_MAX_FIELD_CNT CFA_P40_PROF_L2_CTXT_RMP_DR_MAX_FLD
41 #define CFA_PROF_MAX_KEY_CFG_SZ sizeof(struct cfa_p4_prof_key_cfg)
42 #define CFA_KEY_MAX_FIELD_CNT 41
43 #define CFA_ACT_MAX_TEMPLATE_SZ sizeof(struct cfa_p4_action_template)
46 * CFA HW version definition
49 HCAPI_CFA_P40 = 0, /**< CFA phase 4.0 */
50 HCAPI_CFA_P45 = 1, /**< CFA phase 4.5 */
51 HCAPI_CFA_P58 = 2, /**< CFA phase 5.8 */
52 HCAPI_CFA_P59 = 3, /**< CFA phase 5.9 */
57 * CFA direction definition
60 HCAPI_CFA_DIR_RX = 0, /**< Receive */
61 HCAPI_CFA_DIR_TX = 1, /**< Transmit */
66 * CFA HW OPCODE definition
68 enum hcapi_cfa_hwops {
69 HCAPI_CFA_HWOPS_PUT, /**< Write to HW operation */
70 HCAPI_CFA_HWOPS_GET, /**< Read from HW operation */
71 HCAPI_CFA_HWOPS_ADD, /**< For operations which require more than simple
72 * writes to HW, this operation is used. The
73 * distinction with this operation when compared
74 * to the PUT ops is that this operation is used
75 * in conjunction with the HCAPI_CFA_HWOPS_DEL
76 * op to remove the operations issued by the
79 HCAPI_CFA_HWOPS_DEL, /**< This issues operations to clear the hardware.
80 * This operation is used in conjunction
81 * with the HCAPI_CFA_HWOPS_ADD op and is the
82 * way to undo/clear the ADD op.
88 * CFA HW KEY CONTROL OPCODE definition
90 enum hcapi_cfa_key_ctrlops {
91 HCAPI_CFA_KEY_CTRLOPS_INSERT, /**< insert control bits */
92 HCAPI_CFA_KEY_CTRLOPS_STRIP, /**< strip control bits */
93 HCAPI_CFA_KEY_CTRLOPS_MAX
97 * CFA HW field structure definition
99 struct hcapi_cfa_field {
100 /** [in] Starting bit position pf the HW field within a HW table
104 /** [in] Number of bits for the HW field. */
109 * CFA HW table entry layout structure definition
111 struct hcapi_cfa_layout {
112 /** [out] Bit order of layout */
114 /** [out] Size in bits of entry */
115 uint32_t total_sz_in_bits;
116 /** [out] data pointer of the HW layout fields array */
117 const struct hcapi_cfa_field *field_array;
118 /** [out] number of HW field entries in the HW layout field array */
120 /** [out] layout_id - layout id associated with the layout */
125 * CFA HW data object definition
127 struct hcapi_cfa_data_obj {
128 /** [in] HW field identifier. Used as an index to a HW table layout */
130 /** [in] Value of the HW field */
137 struct hcapi_cfa_hw {
138 /** [in] HW table base address for the operation with optional device
139 * handle. For on-chip HW table operation, this is the either the TX
140 * or RX CFA HW base address. For off-chip table, this field is the
141 * base memory address of the off-chip table.
144 /** [in] Optional opaque device handle. It is generally used to access
145 * an GRC register space through PCIE BAR and passed to the BAR memory
152 * CFA HW operation definition
155 struct hcapi_cfa_hwop {
156 /** [in] HW opcode */
157 enum hcapi_cfa_hwops opcode;
158 /** [in] CFA HW information used by accessor routines.
160 struct hcapi_cfa_hw hw;
164 * CFA HW data structure definition
166 struct hcapi_cfa_data {
167 /** [in] physical offset to the HW table for the data to be
168 * written to. If this is an array of registers, this is the
169 * index into the array of registers. For writing keys, this
170 * is the byte offset into the memory where the key should be
175 uint32_t byte_offset;
177 /** [in] HW data buffer pointer */
179 /** [in] HW data mask buffer pointer */
181 /** [in] size of the HW data buffer in bytes */
185 /*********************** Truflow start ***************************/
186 enum hcapi_cfa_pg_tbl_lvl {
193 enum hcapi_cfa_em_table_type {
201 struct hcapi_cfa_em_page_tbl {
208 struct hcapi_cfa_em_table {
210 uint32_t num_entries;
214 uint32_t page_cnt[TF_PT_LVL_MAX];
215 uint64_t num_data_pages;
217 uint64_t l0_dma_addr;
218 struct hcapi_cfa_em_page_tbl pg_tbl[TF_PT_LVL_MAX];
221 struct hcapi_cfa_em_ctx_mem_info {
222 struct hcapi_cfa_em_table em_tables[TF_MAX_TABLE];
225 /*********************** Truflow end ****************************/
228 * CFA HW key table definition
230 * Applicable to EEM and off-chip EM table only.
232 struct hcapi_cfa_key_tbl {
233 /** [in] For EEM, this is the KEY0 base mem pointer. For off-chip EM,
234 * this is the base mem pointer of the key table.
237 /** [in] total size of the key table in bytes. For EEM, this size is
238 * same for both KEY0 and KEY1 table.
241 /** [in] number of key buckets, applicable for newer chips */
242 uint32_t num_buckets;
243 /** [in] For EEM, this is KEY1 base mem pointer. Fo off-chip EM,
244 * this is the key record memory base pointer within the key table,
245 * applicable for newer chip
248 /** [in] Page size for EEM tables */
253 * CFA HW key buffer definition
255 struct hcapi_cfa_key_obj {
256 /** [in] pointer to the key data buffer */
258 /** [in] buffer len in bits */
260 /** [in] Pointer to the key layout */
261 struct hcapi_cfa_key_layout *layout;
265 * CFA HW key data definition
267 struct hcapi_cfa_key_data {
268 /** [in] For on-chip key table, it is the offset in unit of smallest
269 * key. For off-chip key table, it is the byte offset relative
270 * to the key record memory base and adjusted for page and entry size.
273 /** [in] HW key data buffer pointer */
275 /** [in] size of the key in bytes */
280 * CFA HW key location definition
282 struct hcapi_cfa_key_loc {
283 /** [out] on-chip EM bucket offset or off-chip EM bucket mem pointer */
284 uint64_t bucket_mem_ptr;
285 /** [out] index within the EM bucket */
290 * CFA HW layout table definition
292 struct hcapi_cfa_layout_tbl {
293 /** [out] data pointer to an array of fix formatted layouts supported.
294 * The index to the array is the CFA HW table ID
296 const struct hcapi_cfa_layout *tbl;
297 /** [out] number of fix formatted layouts in the layout array */
298 uint16_t num_layouts;
302 * Key template consists of key fields that can be enabled/disabled
305 struct hcapi_cfa_key_template {
306 /** [in] key field enable field array, set 1 to the correspeonding
307 * field enable to make a field valid
309 uint8_t field_en[CFA_KEY_MAX_FIELD_CNT];
310 /** [in] Identified if the key template is for TCAM. If false, the
311 * the key template is for EM. This field is mandantory for device that
312 * only support fix key formats.
318 * key layout consist of field array, key bitlen, key ID, and other meta data
321 struct hcapi_cfa_key_layout {
322 /** [out] key layout data */
323 struct hcapi_cfa_layout *layout;
324 /** [out] actual key size in number of bits */
326 /** [out] key identifier and this field is only valid for device
327 * that supports fix key formats
330 /** [out] Identified the key layout is WC TCAM key */
332 /** [out] total slices size, valid for WC TCAM key only. It can be
333 * used by the user to determine the total size of WC TCAM key slices
336 uint16_t slices_size;
340 * key layout memory contents
342 struct hcapi_cfa_key_layout_contents {
344 struct hcapi_cfa_key_layout key_layout;
347 struct hcapi_cfa_layout layout;
350 struct hcapi_cfa_field field_array[CFA_KEY_MAX_FIELD_CNT];
354 * Action template consists of action fields that can be enabled/disabled
357 struct hcapi_cfa_action_template {
358 /** [in] CFA version for the action template */
359 enum hcapi_cfa_ver hw_ver;
360 /** [in] action field enable field array, set 1 to the correspeonding
361 * field enable to make a field valid
363 uint8_t data[CFA_ACT_MAX_TEMPLATE_SZ];
367 * action layout consist of field array, action wordlen and action format ID
369 struct hcapi_cfa_action_layout {
370 /** [in] action identifier */
372 /** [out] action layout data */
373 struct hcapi_cfa_layout *layout;
374 /** [out] actual action record size in number of bits */
379 * \defgroup CFA_HCAPI_PUT_API
380 * HCAPI used for writing to the hardware
385 * This API provides the functionality to program a specified value to a
386 * HW field based on the provided programming layout.
388 * @param[in,out] obj_data
389 * A data pointer to a CFA HW key/mask data
392 * A pointer to CFA HW programming layout
394 * @param[in] field_id
395 * ID of the HW field to be programmed
398 * Value of the HW field to be programmed
401 * 0 for SUCCESS, negative value for FAILURE
403 int hcapi_cfa_put_field(uint64_t *data_buf,
404 const struct hcapi_cfa_layout *layout,
405 uint16_t field_id, uint64_t val);
408 * This API provides the functionality to program an array of field values
409 * with corresponding field IDs to a number of profiler sub-block fields
410 * based on the fixed profiler sub-block hardware programming layout.
412 * @param[in, out] obj_data
413 * A pointer to a CFA profiler key/mask object data
416 * A pointer to CFA HW programming layout
418 * @param[in] field_tbl
419 * A pointer to an array that consists of the object field
422 * @param[in] field_tbl_sz
423 * Number of entries in the table
426 * 0 for SUCCESS, negative value for FAILURE
428 int hcapi_cfa_put_fields(uint64_t *obj_data,
429 const struct hcapi_cfa_layout *layout,
430 struct hcapi_cfa_data_obj *field_tbl,
431 uint16_t field_tbl_sz);
434 * This API provides the functionality to write a value to a
435 * field within the bit position and bit length of a HW data
436 * object based on a provided programming layout.
438 * @param[in, out] act_obj
439 * A pointer of the action object to be initialized
442 * A pointer of the programming layout
445 * [in] Identifier of the HW field
447 * @param[in] bitpos_adj
448 * Bit position adjustment value
450 * @param[in] bitlen_adj
451 * Bit length adjustment value
454 * HW field value to be programmed
457 * 0 for SUCCESS, negative value for FAILURE
459 int hcapi_cfa_put_field_rel(uint64_t *obj_data,
460 const struct hcapi_cfa_layout *layout,
461 uint16_t field_id, int16_t bitpos_adj,
462 int16_t bitlen_adj, uint64_t val);
467 * \defgroup CFA_HCAPI_GET_API
468 * HCAPI used for writing to the hardware
473 * This API provides the functionality to get the word length of
477 * A pointer of the HW layout
480 * Word length of the layout object
482 uint16_t hcapi_cfa_get_wordlen(const struct hcapi_cfa_layout *layout);
485 * The API provides the functionality to get bit offset and bit
486 * length information of a field from a programming layout.
489 * A pointer of the action layout
492 * A pointer to the action offset info data structure
495 * 0 for SUCCESS, negative value for FAILURE
497 int hcapi_cfa_get_slice(const struct hcapi_cfa_layout *layout,
498 uint16_t field_id, struct hcapi_cfa_field *slice);
501 * This API provides the functionality to read the value of a
502 * CFA HW field from CFA HW data object based on the hardware
503 * programming layout.
505 * @param[in] obj_data
506 * A pointer to a CFA HW key/mask object data
509 * A pointer to CFA HW programming layout
511 * @param[in] field_id
512 * ID of the HW field to be programmed
515 * Value of the HW field
518 * 0 for SUCCESS, negative value for FAILURE
520 int hcapi_cfa_get_field(uint64_t *obj_data,
521 const struct hcapi_cfa_layout *layout,
522 uint16_t field_id, uint64_t *val);
525 * This API provides the functionality to read a number of
526 * HW fields from a CFA HW data object based on the hardware
527 * programming layout.
529 * @param[in] obj_data
530 * A pointer to a CFA profiler key/mask object data
533 * A pointer to CFA HW programming layout
535 * @param[in, out] field_tbl
536 * A pointer to an array that consists of the object field
539 * @param[in] field_tbl_sz
540 * Number of entries in the table
543 * 0 for SUCCESS, negative value for FAILURE
545 int hcapi_cfa_get_fields(uint64_t *obj_data,
546 const struct hcapi_cfa_layout *layout,
547 struct hcapi_cfa_data_obj *field_tbl,
548 uint16_t field_tbl_sz);
551 * Get a value to a specific location relative to a HW field
553 * This API provides the functionality to read HW field from
554 * a section of a HW data object identified by the bit position
555 * and bit length from a given programming layout in order to avoid
556 * reading the entire HW data object.
558 * @param[in] obj_data
559 * A pointer of the data object to read from
562 * A pointer of the programming layout
564 * @param[in] field_id
565 * Identifier of the HW field
567 * @param[in] bitpos_adj
568 * Bit position adjustment value
570 * @param[in] bitlen_adj
571 * Bit length adjustment value
574 * Value of the HW field
577 * 0 for SUCCESS, negative value for FAILURE
579 int hcapi_cfa_get_field_rel(uint64_t *obj_data,
580 const struct hcapi_cfa_layout *layout,
581 uint16_t field_id, int16_t bitpos_adj,
582 int16_t bitlen_adj, uint64_t *val);
585 * This function is used to initialize a layout_contents structure
587 * The struct hcapi_cfa_key_layout is complex as there are three
588 * layers of abstraction. Each of those layer need to be properly
591 * @param[in] layout_contents
592 * A pointer of the layout contents to initialize
595 * 0 for SUCCESS, negative value for FAILURE
598 hcapi_cfa_init_key_layout_contents(struct hcapi_cfa_key_layout_contents *cont);
601 * This function is used to validate a key template
603 * The struct hcapi_cfa_key_template is complex as there are three
604 * layers of abstraction. Each of those layer need to be properly
607 * @param[in] key_template
608 * A pointer of the key template contents to validate
611 * 0 for SUCCESS, negative value for FAILURE
614 hcapi_cfa_is_valid_key_template(struct hcapi_cfa_key_template *key_template);
617 * This function is used to validate a key layout
619 * The struct hcapi_cfa_key_layout is complex as there are three
620 * layers of abstraction. Each of those layer need to be properly
623 * @param[in] key_layout
624 * A pointer of the key layout contents to validate
627 * 0 for SUCCESS, negative value for FAILURE
629 int hcapi_cfa_is_valid_key_layout(struct hcapi_cfa_key_layout *key_layout);
632 * This function is used to hash E/EM keys
635 * @param[in] key_data
636 * A pointer of the key
639 * Number of bits in the key
642 * CRC32 and Lookup3 hashes of the input key
644 uint64_t hcapi_cfa_key_hash(uint64_t *key_data,
648 * This function is used to execute an operation
660 * @param[in] key_key_loc
663 * 0 for SUCCESS, negative value for FAILURE
665 int hcapi_cfa_key_hw_op(struct hcapi_cfa_hwop *op,
666 struct hcapi_cfa_key_tbl *key_tbl,
667 struct hcapi_cfa_key_data *key_obj,
668 struct hcapi_cfa_key_loc *key_loc);
670 uint64_t hcapi_get_table_page(struct hcapi_cfa_em_table *mem,
672 #endif /* HCAPI_CFA_DEFS_H_ */