1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2019-2021 Broadcom
8 * \brief Exported functions for CFA HW programming
10 #ifndef _HCAPI_CFA_DEFS_H_
11 #define _HCAPI_CFA_DEFS_H_
19 #if !defined(__GNUC__)
23 #define CFA_BITS_PER_BYTE (8)
24 #define CFA_BITS_PER_WORD (sizeof(uint32_t) * CFA_BITS_PER_BYTE)
25 #define __CFA_ALIGN_MASK(x, mask) (((x) + (mask)) & ~(mask))
26 #define CFA_ALIGN(x, a) __CFA_ALIGN_MASK((x), (a) - 1)
27 #define CFA_ALIGN_256(x) CFA_ALIGN(x, 256)
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) (CFA_ALIGN_32(x) / CFA_BITS_PER_WORD)
32 #define NUM_WORDS_ALIGN_128BIT(x) (CFA_ALIGN_128(x) / CFA_BITS_PER_WORD)
33 #define NUM_WORDS_ALIGN_256BIT(x) (CFA_ALIGN_256(x) / CFA_BITS_PER_WORD)
35 /* TODO: redefine according to chip variant */
36 #define CFA_GLOBAL_CFG_DATA_SZ (100)
38 #ifndef SUPPORT_CFA_HW_P4
39 #define SUPPORT_CFA_HW_P4 (0)
42 #ifndef SUPPORT_CFA_HW_P45
43 #define SUPPORT_CFA_HW_P45 (0)
46 #ifndef SUPPORT_CFA_HW_P58
47 #define SUPPORT_CFA_HW_P58 (0)
50 #if SUPPORT_CFA_HW_ALL
51 #include "hcapi_cfa_p4.h"
52 #include "hcapi_cfa_p58.h"
53 #endif /* SUPPORT_CFA_HW_ALL */
58 #define HCAPI_CFA_LKUP_SEED_MEM_SIZE 512
60 /* CRC32i support for Key0 hash */
61 #define ucrc32(ch, crc) (crc32tbl[((crc) ^ (ch)) & 0xff] ^ ((crc) >> 8))
62 #define crc32(x, y) crc32i(~0, x, y)
65 * CFA HW version definition
68 HCAPI_CFA_P40 = 0, /**< CFA phase 4.0 */
69 HCAPI_CFA_P45 = 1, /**< CFA phase 4.5 */
70 HCAPI_CFA_P58 = 2, /**< CFA phase 5.8 */
75 * CFA direction definition
78 HCAPI_CFA_DIR_RX = 0, /**< Receive */
79 HCAPI_CFA_DIR_TX = 1, /**< Transmit */
84 * CFA HW OPCODE definition
86 enum hcapi_cfa_hwops {
87 HCAPI_CFA_HWOPS_PUT, /**< Write to HW operation */
88 HCAPI_CFA_HWOPS_GET, /**< Read from HW operation */
89 HCAPI_CFA_HWOPS_ADD, /*<
90 * For operations which require more then
91 * simple writes to HW, this operation is
92 * used. The distinction with this operation
93 * when compared to the PUT ops is that this
94 * operation is used in conjunction with
95 * the HCAPI_CFA_HWOPS_DEL op to remove
96 * the operations issued by the ADD OP.
98 HCAPI_CFA_HWOPS_DEL, /*<
99 * Beside to delete from the hardware, this
100 * operation is also undo the add operation
101 * performed by the HCAPI_CFA_HWOPS_ADD op.
103 HCAPI_CFA_HWOPS_EVICT, /*< This operation is used to evict entries from
104 * CFA cache memories. This operation is only
105 * applicable to tables that use CFA caches.
111 * CFA HW KEY CONTROL OPCODE definition
113 enum hcapi_cfa_key_ctrlops {
114 HCAPI_CFA_KEY_CTRLOPS_INSERT, /**< insert control bits */
115 HCAPI_CFA_KEY_CTRLOPS_STRIP, /**< strip control bits */
116 HCAPI_CFA_KEY_CTRLOPS_MAX
122 struct hcapi_cfa_hw {
123 /** [in] HW table base address for the operation with optional device
124 * handle. For on-chip HW table operation, this is the either the TX
125 * or RX CFA HW base address. For off-chip table, this field is the
126 * base memory address of the off-chip table.
129 /** [in] Optional opaque device handle. It is generally used to access
130 * an GRC register space through PCIE BAR and passed to the BAR memory
137 * CFA HW operation definition
140 struct hcapi_cfa_hwop {
141 /** [in] HW opcode */
142 enum hcapi_cfa_hwops opcode;
143 /** [in] CFA HW information used by accessor routines.
145 struct hcapi_cfa_hw hw;
149 * CFA HW data structure definition
151 struct hcapi_cfa_data {
152 /** [in] physical offset to the HW table for the data to be
153 * written to. If this is an array of registers, this is the
154 * index into the array of registers. For writing keys, this
155 * is the byte pointer into the memory where the key should be
160 uint32_t byte_offset;
162 /** [in] HW data buffer pointer */
164 /** [in] HW data mask buffer pointer.
165 * When the CFA data is a FKB and data_mask pointer
166 * is NULL, then the default mask to enable all bit will
170 /** [in/out] size of the HW data buffer in bytes
175 /*********************** Truflow start ***************************/
176 enum hcapi_cfa_pg_tbl_lvl {
183 enum hcapi_cfa_em_table_type {
193 struct hcapi_cfa_em_page_tbl {
200 struct hcapi_cfa_em_table {
202 uint32_t num_entries;
206 uint32_t page_cnt[TF_PT_LVL_MAX];
207 uint64_t num_data_pages;
209 uint64_t l0_dma_addr;
210 struct hcapi_cfa_em_page_tbl pg_tbl[TF_PT_LVL_MAX];
213 struct hcapi_cfa_em_ctx_mem_info {
214 struct hcapi_cfa_em_table em_tables[TF_MAX_TABLE];
217 /*********************** Truflow end ****************************/
219 * CFA HW key table definition
221 * Applicable to EEM and off-chip EM table only.
223 struct hcapi_cfa_key_tbl {
224 /** [in] For EEM, this is the KEY0 base mem pointer. For off-chip EM,
225 * this is the base mem pointer of the key table.
228 /** [in] total size of the key table in bytes. For EEM, this size is
229 * same for both KEY0 and KEY1 table.
232 /** [in] number of key buckets, applicable for newer chips */
233 uint32_t num_buckets;
234 /** [in] For EEM, this is KEY1 base mem pointer. For off-chip EM,
235 * this is the key record memory base pointer within the key table,
236 * applicable for newer chip
239 /** [in] Optional - If the table is managed by a Backing Store
240 * database, then this object can be use to configure the EM Key.
242 struct hcapi_cfa_bs_db *bs_db;
243 /** [in] Page size for EEM tables */
248 * CFA HW key buffer definition
250 struct hcapi_cfa_key_obj {
251 /** [in] pointer to the key data buffer */
253 /** [in] buffer len in bytes */
255 /** [in] Pointer to the key layout */
256 struct hcapi_cfa_key_layout *layout;
260 * CFA HW key data definition
262 struct hcapi_cfa_key_data {
263 /** [in] For on-chip key table, it is the offset in unit of smallest
264 * key. For off-chip key table, it is the byte offset relative
265 * to the key record memory base and adjusted for page and entry size.
268 /** [in] HW key data buffer pointer */
270 /** [in] size of the key in bytes */
272 /** [in] optional table scope ID */
274 /** [in] the fid owner of the key */
276 /** [in] stored with the bucket which can be used by
277 * the caller to retrieve later via the GET HW OP.
282 * CFA HW key location definition
284 struct hcapi_cfa_key_loc {
285 /** [out] on-chip EM bucket offset or off-chip EM bucket mem pointer */
286 uint64_t bucket_mem_ptr;
287 /** [out] off-chip EM key offset mem pointer */
289 /** [out] index within the array of the EM buckets */
290 uint32_t bucket_mem_idx;
291 /** [out] index within the EM bucket */
293 /** [out] index within the EM records */
300 struct hcapi_cfa_action_addr {
301 /** [in] action SRAM block ID for on-chip action records or table
302 * scope of the action backing store
305 /** [in] ar_id or cache line aligned address offset for the action
312 * Action data definition
314 struct hcapi_cfa_action_data {
315 /** [in] action record addr info for on-chip action records */
316 struct hcapi_cfa_action_addr addr;
317 /** [in/out] pointer to the action data buffer */
319 /** [in] action data buffer len in bytes */
324 * Action object definition
326 struct hcapi_cfa_action_obj {
327 /** [in] pointer to the action data buffer */
329 /** [in] buffer len in bytes */
331 /** [in] pointer to the action layout */
332 struct hcapi_cfa_action_layout *layout;
336 * This function is used to hash E/EM keys
339 * @param[in] key_data
340 * A pointer of the key
343 * Number of bits in the key
346 * CRC32 and Lookup3 hashes of the input key
348 uint64_t hcapi_cfa_key_hash(uint64_t *key_data,
352 * This function is used to execute an operation
364 * @param[in] key_key_loc
367 * 0 for SUCCESS, negative value for FAILURE
369 int hcapi_cfa_key_hw_op(struct hcapi_cfa_hwop *op,
370 struct hcapi_cfa_key_tbl *key_tbl,
371 struct hcapi_cfa_key_data *key_obj,
372 struct hcapi_cfa_key_loc *key_loc);
374 uint64_t hcapi_get_table_page(struct hcapi_cfa_em_table *mem,
376 uint32_t hcapi_cfa_crc32i(uint32_t crc, const uint8_t *buf, size_t len);
377 uint64_t hcapi_cfa_p4_key_hash(uint64_t *key_data,
379 uint64_t hcapi_cfa_p58_key_hash(uint64_t *key_data,
381 #endif /* HCAPI_CFA_DEFS_H_ */