1 /* SPDX-License-Identifier: BSD-3-Clause 2 * Copyright(c) 2019-2021 Broadcom 3 * All rights reserved. 4 */ 5 6 #ifndef _TFC_EM_H_ 7 #define _TFC_EM_H_ 8 9 #include <stdint.h> 10 #include <stdlib.h> 11 #include <stdbool.h> 12 #include <stdio.h> 13 #include <errno.h> 14 #include <cfa_bld_mpcops.h> 15 16 /* Defines the maximum number of outstanding completions supported. */ 17 #define BNXT_MPC_COMP_MAX_COUNT 64 18 19 struct tfc_mpc_comp_info_t { 20 struct bnxt_mpc_txq *mpc_queue; 21 struct bnxt_mpc_mbuf out_msg; 22 int type; 23 uint16_t read_words; 24 }; 25 26 struct tfc_mpc_batch_info_t { 27 bool enabled; 28 int error; 29 int em_error; 30 uint32_t count; 31 uint32_t result[BNXT_MPC_COMP_MAX_COUNT]; 32 /* List of resources IDs that are to be processed during batch end */ 33 uint64_t res_idx[BNXT_MPC_COMP_MAX_COUNT]; 34 uint64_t em_hdl[BNXT_MPC_COMP_MAX_COUNT]; 35 struct tfc_mpc_comp_info_t comp_info[BNXT_MPC_COMP_MAX_COUNT]; 36 }; 37 38 enum tfc_mpc_cmd_type { 39 TFC_MPC_EM_INSERT, 40 TFC_MPC_EM_DELETE, 41 TFC_MPC_TABLE_WRITE, 42 TFC_MPC_TABLE_READ, 43 TFC_MPC_TABLE_READ_CLEAR, 44 TFC_MPC_INVALIDATE 45 }; 46 47 #define TFC_EM_DYNAMIC_BUCKET_EN 0 48 49 /* 50 * Derived from CAS document 51 */ 52 #define TFC_MPC_MAX_TX_BYTES 188 53 #define TFC_MPC_MAX_RX_BYTES 188 54 55 #define TFC_MPC_HEADER_SIZE_BYTES 16 56 57 #define TFC_MPC_BYTES_PER_WORD 32 58 #define TFC_MPC_MAX_TABLE_READ_WORDS 4 59 #define TFC_MPC_MAX_TABLE_READ_BYTES \ 60 (TFC_MPC_BYTES_PER_WORD * TFC_MPC_MAX_TABLE_READ_WORDS) 61 62 #define TFC_BUCKET_ENTRIES 6 63 64 struct em_info_t { 65 bool valid; 66 uint8_t rec_size; 67 uint16_t epoch0; 68 uint16_t epoch1; 69 uint8_t opcode; 70 uint8_t strength; 71 uint8_t act_hint; 72 73 uint32_t act_rec_ptr; /* Not FAST */ 74 75 uint32_t destination; /* Just FAST */ 76 77 uint8_t tcp_direction; /* Just CT */ 78 uint8_t tcp_update_en; 79 uint8_t tcp_win; 80 uint32_t tcp_msb_loc; 81 uint32_t tcp_msb_opp; 82 uint8_t tcp_msb_opp_init; 83 uint8_t state; 84 uint8_t timer_value; 85 86 uint16_t ring_table_idx; /* Not CT and not RECYCLE */ 87 uint8_t act_rec_size; 88 uint8_t paths_m1; 89 uint8_t fc_op; 90 uint8_t fc_type; 91 uint32_t fc_ptr; 92 93 uint8_t recycle_dest; /* Just Recycle */ 94 uint8_t prof_func; 95 uint8_t meta_prof; 96 uint32_t metadata; 97 98 uint8_t range_profile; 99 uint16_t range_index; 100 101 uint8_t *key; 102 }; 103 104 struct sb_entry_t { 105 uint16_t hash_msb; 106 uint32_t entry_ptr; 107 }; 108 109 struct bucket_info_t { 110 bool valid; 111 bool chain; 112 uint32_t chain_ptr; 113 struct sb_entry_t entries[TFC_BUCKET_ENTRIES]; 114 struct em_info_t em_info[TFC_BUCKET_ENTRIES]; 115 }; 116 117 #define CALC_NUM_RECORDS_IN_POOL(a, b, c) 118 119 /* Calculates number of 32Byte records from total size in 32bit words */ 120 #define CALC_NUM_RECORDS(result, key_sz_words) \ 121 (*(result) = (((key_sz_words) + 7) / 8)) 122 123 /* Calculates the entry offset */ 124 #define CREATE_OFFSET(result, pool_sz_exp, pool_id, record_offset) \ 125 (*(result) = (((pool_id) << (pool_sz_exp)) | (record_offset))) 126 127 int tfc_em_delete_raw(struct tfc *tfcp, 128 uint8_t tsid, 129 enum cfa_dir dir, 130 uint32_t offset, 131 uint32_t static_bucket, 132 struct tfc_mpc_batch_info_t *batch_info 133 #if TFC_EM_DYNAMIC_BUCKET_EN 134 , bool *db_unused, 135 uint32_t *db_offset 136 #endif 137 #ifdef BNXT_MPC_COMP_COUNT 138 , uint32_t comp_count 139 #endif 140 ); 141 142 int tfc_mpc_table_read(struct tfc *tfcp, 143 uint8_t tsid, 144 enum cfa_dir dir, 145 uint32_t type, 146 uint32_t offset, 147 uint8_t words, 148 uint8_t *data, 149 uint8_t debug); 150 151 int tfc_em_delete_entries_by_pool_id(struct tfc *tfcp, 152 uint8_t tsid, 153 enum cfa_dir dir, 154 uint16_t pool_id, 155 uint8_t debug, 156 uint8_t *data); 157 158 int tfc_act_set_response(struct cfa_bld_mpcinfo *mpc_info, 159 struct bnxt_mpc_mbuf *mpc_msg_out, 160 uint8_t *rx_msg); 161 162 int tfc_act_get_only_response(struct cfa_bld_mpcinfo *mpc_info, 163 struct bnxt_mpc_mbuf *mpc_msg_out, 164 uint8_t *rx_msg, 165 uint16_t *data_sz_words); 166 167 int tfc_act_get_clear_response(struct cfa_bld_mpcinfo *mpc_info, 168 struct bnxt_mpc_mbuf *mpc_msg_out, 169 uint8_t *rx_msg, 170 uint16_t *data_sz_words); 171 172 int tfc_mpc_send(struct bnxt *bp, 173 struct bnxt_mpc_mbuf *in_msg, 174 struct bnxt_mpc_mbuf *out_msg, 175 uint32_t *opaque, 176 int type, 177 struct tfc_mpc_batch_info_t *batch_info); 178 179 #endif /* _TFC_EM_H_ */ 180