2 /* SPDX-License-Identifier: BSD-3-Clause
3 * Copyright(c) 2014-2021 Broadcom
9 * \brief Exported functions for CFA HW programming
11 #ifndef _HCAPI_CFA_DEFS_H_
12 #define _HCAPI_CFA_DEFS_H_
20 #define CFA_BITS_PER_BYTE (8)
21 #define __CFA_ALIGN_MASK(x, mask) (((x) + (mask)) & ~(mask))
22 #define CFA_ALIGN(x, a) __CFA_ALIGN_MASK(x, (a) - 1)
23 #define CFA_ALIGN_128(x) CFA_ALIGN(x, 128)
24 #define CFA_ALIGN_32(x) CFA_ALIGN(x, 32)
26 #define NUM_WORDS_ALIGN_32BIT(x) \
27 (CFA_ALIGN_32(x) / (sizeof(uint32_t) * CFA_BITS_PER_BYTE))
28 #define NUM_WORDS_ALIGN_128BIT(x) \
29 (CFA_ALIGN_128(x) / (sizeof(uint32_t) * CFA_BITS_PER_BYTE))
31 #define CFA_GLOBAL_CFG_DATA_SZ (100)
33 #include "hcapi_cfa_p4.h"
34 #define CFA_PROF_L2CTXT_TCAM_MAX_FIELD_CNT CFA_P40_PROF_L2_CTXT_TCAM_MAX_FLD
35 #define CFA_PROF_L2CTXT_REMAP_MAX_FIELD_CNT CFA_P40_PROF_L2_CTXT_RMP_DR_MAX_FLD
36 #define CFA_PROF_MAX_KEY_CFG_SZ sizeof(struct cfa_p4_prof_key_cfg)
37 #define CFA_KEY_MAX_FIELD_CNT 41
38 #define CFA_ACT_MAX_TEMPLATE_SZ sizeof(struct cfa_p4_action_template)
41 * CFA HW version definition
44 HCAPI_CFA_P40 = 0, /**< CFA phase 4.0 */
45 HCAPI_CFA_P45 = 1, /**< CFA phase 4.5 */
46 HCAPI_CFA_P58 = 2, /**< CFA phase 5.8 */
51 * CFA direction definition
54 HCAPI_CFA_DIR_RX = 0, /**< Receive */
55 HCAPI_CFA_DIR_TX = 1, /**< Transmit */
60 * CFA HW OPCODE definition
62 enum hcapi_cfa_hwops {
63 HCAPI_CFA_HWOPS_PUT, /**< Write to HW operation */
64 HCAPI_CFA_HWOPS_GET, /**< Read from HW operation */
65 HCAPI_CFA_HWOPS_ADD, /**< For operations which require more than simple
66 * writes to HW, this operation is used. The
67 * distinction with this operation when compared
68 * to the PUT ops is that this operation is used
69 * in conjunction with the HCAPI_CFA_HWOPS_DEL
70 * op to remove the operations issued by the
73 HCAPI_CFA_HWOPS_DEL, /**< This issues operations to clear the hardware.
74 * This operation is used in conjunction
75 * with the HCAPI_CFA_HWOPS_ADD op and is the
76 * way to undo/clear the ADD op.
82 * CFA HW KEY CONTROL OPCODE definition
84 enum hcapi_cfa_key_ctrlops {
85 HCAPI_CFA_KEY_CTRLOPS_INSERT, /**< insert control bits */
86 HCAPI_CFA_KEY_CTRLOPS_STRIP, /**< strip control bits */
87 HCAPI_CFA_KEY_CTRLOPS_MAX
91 * CFA HW field structure definition
93 struct hcapi_cfa_field {
94 /** [in] Starting bit position pf the HW field within a HW table
98 /** [in] Number of bits for the HW field. */
103 * CFA HW table entry layout structure definition
105 struct hcapi_cfa_layout {
106 /** [out] Bit order of layout */
108 /** [out] Size in bits of entry */
109 uint32_t total_sz_in_bits;
110 /** [out] data pointer of the HW layout fields array */
111 const struct hcapi_cfa_field *field_array;
112 /** [out] number of HW field entries in the HW layout field array */
114 /** [out] layout_id - layout id associated with the layout */
119 * CFA HW data object definition
121 struct hcapi_cfa_data_obj {
122 /** [in] HW field identifier. Used as an index to a HW table layout */
124 /** [in] Value of the HW field */
131 struct hcapi_cfa_hw {
132 /** [in] HW table base address for the operation with optional device
133 * handle. For on-chip HW table operation, this is the either the TX
134 * or RX CFA HW base address. For off-chip table, this field is the
135 * base memory address of the off-chip table.
138 /** [in] Optional opaque device handle. It is generally used to access
139 * an GRC register space through PCIE BAR and passed to the BAR memory
146 * CFA HW operation definition
149 struct hcapi_cfa_hwop {
150 /** [in] HW opcode */
151 enum hcapi_cfa_hwops opcode;
152 /** [in] CFA HW information used by accessor routines.
154 struct hcapi_cfa_hw hw;
158 * CFA HW data structure definition
160 struct hcapi_cfa_data {
161 /** [in] physical offset to the HW table for the data to be
162 * written to. If this is an array of registers, this is the
163 * index into the array of registers. For writing keys, this
164 * is the byte offset into the memory where the key should be
169 uint32_t byte_offset;
171 /** [in] HW data buffer pointer */
173 /** [in] HW data mask buffer pointer */
175 /** [in] size of the HW data buffer in bytes */
179 /*********************** Truflow start ***************************/
180 enum hcapi_cfa_pg_tbl_lvl {
187 enum hcapi_cfa_em_table_type {
195 struct hcapi_cfa_em_page_tbl {
202 struct hcapi_cfa_em_table {
204 uint32_t num_entries;
208 uint32_t page_cnt[TF_PT_LVL_MAX];
209 uint64_t num_data_pages;
211 uint64_t l0_dma_addr;
212 struct hcapi_cfa_em_page_tbl pg_tbl[TF_PT_LVL_MAX];
215 struct hcapi_cfa_em_ctx_mem_info {
216 struct hcapi_cfa_em_table em_tables[TF_MAX_TABLE];
219 /*********************** Truflow end ****************************/
222 * CFA HW key table definition
224 * Applicable to EEM and off-chip EM table only.
226 struct hcapi_cfa_key_tbl {
227 /** [in] For EEM, this is the KEY0 base mem pointer. For off-chip EM,
228 * this is the base mem pointer of the key table.
231 /** [in] total size of the key table in bytes. For EEM, this size is
232 * same for both KEY0 and KEY1 table.
235 /** [in] number of key buckets, applicable for newer chips */
236 uint32_t num_buckets;
237 /** [in] For EEM, this is KEY1 base mem pointer. Fo off-chip EM,
238 * this is the key record memory base pointer within the key table,
239 * applicable for newer chip
242 /** [in] Page size for EEM tables */
247 * CFA HW key buffer definition
249 struct hcapi_cfa_key_obj {
250 /** [in] pointer to the key data buffer */
252 /** [in] buffer len in bits */
254 /** [in] Pointer to the key layout */
255 struct hcapi_cfa_key_layout *layout;
259 * CFA HW key data definition
261 struct hcapi_cfa_key_data {
262 /** [in] For on-chip key table, it is the offset in unit of smallest
263 * key. For off-chip key table, it is the byte offset relative
264 * to the key record memory base and adjusted for page and entry size.
267 /** [in] HW key data buffer pointer */
269 /** [in] size of the key in bytes */
274 * CFA HW key location definition
276 struct hcapi_cfa_key_loc {
277 /** [out] on-chip EM bucket offset or off-chip EM bucket mem pointer */
278 uint64_t bucket_mem_ptr;
279 /** [out] index within the EM bucket */
284 * CFA HW layout table definition
286 struct hcapi_cfa_layout_tbl {
287 /** [out] data pointer to an array of fix formatted layouts supported.
288 * The index to the array is the CFA HW table ID
290 const struct hcapi_cfa_layout *tbl;
291 /** [out] number of fix formatted layouts in the layout array */
292 uint16_t num_layouts;
296 * Key template consists of key fields that can be enabled/disabled
299 struct hcapi_cfa_key_template {
300 /** [in] key field enable field array, set 1 to the correspeonding
301 * field enable to make a field valid
303 uint8_t field_en[CFA_KEY_MAX_FIELD_CNT];
304 /** [in] Identified if the key template is for TCAM. If false, the
305 * the key template is for EM. This field is mandantory for device that
306 * only support fix key formats.
312 * key layout consist of field array, key bitlen, key ID, and other meta data
315 struct hcapi_cfa_key_layout {
316 /** [out] key layout data */
317 struct hcapi_cfa_layout *layout;
318 /** [out] actual key size in number of bits */
320 /** [out] key identifier and this field is only valid for device
321 * that supports fix key formats
324 /** [out] Identified the key layout is WC TCAM key */
326 /** [out] total slices size, valid for WC TCAM key only. It can be
327 * used by the user to determine the total size of WC TCAM key slices
330 uint16_t slices_size;
334 * key layout memory contents
336 struct hcapi_cfa_key_layout_contents {
338 struct hcapi_cfa_key_layout key_layout;
341 struct hcapi_cfa_layout layout;
344 struct hcapi_cfa_field field_array[CFA_KEY_MAX_FIELD_CNT];
348 * Action template consists of action fields that can be enabled/disabled
351 struct hcapi_cfa_action_template {
352 /** [in] CFA version for the action template */
353 enum hcapi_cfa_ver hw_ver;
354 /** [in] action field enable field array, set 1 to the correspeonding
355 * field enable to make a field valid
357 uint8_t data[CFA_ACT_MAX_TEMPLATE_SZ];
361 * action layout consist of field array, action wordlen and action format ID
363 struct hcapi_cfa_action_layout {
364 /** [in] action identifier */
366 /** [out] action layout data */
367 struct hcapi_cfa_layout *layout;
368 /** [out] actual action record size in number of bits */
373 * \defgroup CFA_HCAPI_PUT_API
374 * HCAPI used for writing to the hardware
379 * This API provides the functionality to program a specified value to a
380 * HW field based on the provided programming layout.
382 * @param[in,out] obj_data
383 * A data pointer to a CFA HW key/mask data
386 * A pointer to CFA HW programming layout
388 * @param[in] field_id
389 * ID of the HW field to be programmed
392 * Value of the HW field to be programmed
395 * 0 for SUCCESS, negative value for FAILURE
397 int hcapi_cfa_put_field(uint64_t *data_buf,
398 const struct hcapi_cfa_layout *layout,
399 uint16_t field_id, uint64_t val);
402 * This API provides the functionality to program an array of field values
403 * with corresponding field IDs to a number of profiler sub-block fields
404 * based on the fixed profiler sub-block hardware programming layout.
406 * @param[in, out] obj_data
407 * A pointer to a CFA profiler key/mask object data
410 * A pointer to CFA HW programming layout
412 * @param[in] field_tbl
413 * A pointer to an array that consists of the object field
416 * @param[in] field_tbl_sz
417 * Number of entries in the table
420 * 0 for SUCCESS, negative value for FAILURE
422 int hcapi_cfa_put_fields(uint64_t *obj_data,
423 const struct hcapi_cfa_layout *layout,
424 struct hcapi_cfa_data_obj *field_tbl,
425 uint16_t field_tbl_sz);
428 * This API provides the functionality to write a value to a
429 * field within the bit position and bit length of a HW data
430 * object based on a provided programming layout.
432 * @param[in, out] act_obj
433 * A pointer of the action object to be initialized
436 * A pointer of the programming layout
439 * [in] Identifier of the HW field
441 * @param[in] bitpos_adj
442 * Bit position adjustment value
444 * @param[in] bitlen_adj
445 * Bit length adjustment value
448 * HW field value to be programmed
451 * 0 for SUCCESS, negative value for FAILURE
453 int hcapi_cfa_put_field_rel(uint64_t *obj_data,
454 const struct hcapi_cfa_layout *layout,
455 uint16_t field_id, int16_t bitpos_adj,
456 int16_t bitlen_adj, uint64_t val);
461 * \defgroup CFA_HCAPI_GET_API
462 * HCAPI used for writing to the hardware
467 * This API provides the functionality to get the word length of
471 * A pointer of the HW layout
474 * Word length of the layout object
476 uint16_t hcapi_cfa_get_wordlen(const struct hcapi_cfa_layout *layout);
479 * The API provides the functionality to get bit offset and bit
480 * length information of a field from a programming layout.
483 * A pointer of the action layout
486 * A pointer to the action offset info data structure
489 * 0 for SUCCESS, negative value for FAILURE
491 int hcapi_cfa_get_slice(const struct hcapi_cfa_layout *layout,
492 uint16_t field_id, struct hcapi_cfa_field *slice);
495 * This API provides the functionality to read the value of a
496 * CFA HW field from CFA HW data object based on the hardware
497 * programming layout.
499 * @param[in] obj_data
500 * A pointer to a CFA HW key/mask object data
503 * A pointer to CFA HW programming layout
505 * @param[in] field_id
506 * ID of the HW field to be programmed
509 * Value of the HW field
512 * 0 for SUCCESS, negative value for FAILURE
514 int hcapi_cfa_get_field(uint64_t *obj_data,
515 const struct hcapi_cfa_layout *layout,
516 uint16_t field_id, uint64_t *val);
519 * This API provides the functionality to read a number of
520 * HW fields from a CFA HW data object based on the hardware
521 * programming layout.
523 * @param[in] obj_data
524 * A pointer to a CFA profiler key/mask object data
527 * A pointer to CFA HW programming layout
529 * @param[in, out] field_tbl
530 * A pointer to an array that consists of the object field
533 * @param[in] field_tbl_sz
534 * Number of entries in the table
537 * 0 for SUCCESS, negative value for FAILURE
539 int hcapi_cfa_get_fields(uint64_t *obj_data,
540 const struct hcapi_cfa_layout *layout,
541 struct hcapi_cfa_data_obj *field_tbl,
542 uint16_t field_tbl_sz);
545 * Get a value to a specific location relative to a HW field
547 * This API provides the functionality to read HW field from
548 * a section of a HW data object identified by the bit position
549 * and bit length from a given programming layout in order to avoid
550 * reading the entire HW data object.
552 * @param[in] obj_data
553 * A pointer of the data object to read from
556 * A pointer of the programming layout
558 * @param[in] field_id
559 * Identifier of the HW field
561 * @param[in] bitpos_adj
562 * Bit position adjustment value
564 * @param[in] bitlen_adj
565 * Bit length adjustment value
568 * Value of the HW field
571 * 0 for SUCCESS, negative value for FAILURE
573 int hcapi_cfa_get_field_rel(uint64_t *obj_data,
574 const struct hcapi_cfa_layout *layout,
575 uint16_t field_id, int16_t bitpos_adj,
576 int16_t bitlen_adj, uint64_t *val);
579 * This function is used to initialize a layout_contents structure
581 * The struct hcapi_cfa_key_layout is complex as there are three
582 * layers of abstraction. Each of those layer need to be properly
585 * @param[in] layout_contents
586 * A pointer of the layout contents to initialize
589 * 0 for SUCCESS, negative value for FAILURE
592 hcapi_cfa_init_key_layout_contents(struct hcapi_cfa_key_layout_contents *cont);
595 * This function is used to validate a key template
597 * The struct hcapi_cfa_key_template is complex as there are three
598 * layers of abstraction. Each of those layer need to be properly
601 * @param[in] key_template
602 * A pointer of the key template contents to validate
605 * 0 for SUCCESS, negative value for FAILURE
608 hcapi_cfa_is_valid_key_template(struct hcapi_cfa_key_template *key_template);
611 * This function is used to validate a key layout
613 * The struct hcapi_cfa_key_layout is complex as there are three
614 * layers of abstraction. Each of those layer need to be properly
617 * @param[in] key_layout
618 * A pointer of the key layout contents to validate
621 * 0 for SUCCESS, negative value for FAILURE
623 int hcapi_cfa_is_valid_key_layout(struct hcapi_cfa_key_layout *key_layout);
626 * This function is used to hash E/EM keys
629 * @param[in] key_data
630 * A pointer of the key
633 * Number of bits in the key
636 * CRC32 and Lookup3 hashes of the input key
638 uint64_t hcapi_cfa_key_hash(uint64_t *key_data,
642 * This function is used to execute an operation
654 * @param[in] key_key_loc
657 * 0 for SUCCESS, negative value for FAILURE
659 int hcapi_cfa_key_hw_op(struct hcapi_cfa_hwop *op,
660 struct hcapi_cfa_key_tbl *key_tbl,
661 struct hcapi_cfa_key_data *key_obj,
662 struct hcapi_cfa_key_loc *key_loc);
664 uint64_t hcapi_get_table_page(struct hcapi_cfa_em_table *mem,
666 #endif /* HCAPI_CFA_DEFS_H_ */