1 /* SPDX-License-Identifier: BSD-3-Clause 2 * Copyright(c) 2014-2023 Broadcom 3 * All rights reserved. 4 */ 5 6 #ifndef _ULP_FC_MGR_H_ 7 #define _ULP_FC_MGR_H_ 8 9 #include "bnxt_ulp.h" 10 #include "ulp_flow_db.h" 11 12 #define ULP_FLAG_FC_THREAD BIT(0) 13 #define ULP_FLAG_FC_SW_AGG_EN BIT(1) 14 #define ULP_FLAG_FC_PARENT_AGG_EN BIT(2) 15 #define ULP_FC_TIMER 1/* Timer freq in Sec Flow Counters */ 16 17 /* Macros to extract packet/byte counters from a 64-bit flow counter. */ 18 #define FLOW_CNTR_BYTE_WIDTH 36 19 #define FLOW_CNTR_BYTE_MASK (((uint64_t)1 << FLOW_CNTR_BYTE_WIDTH) - 1) 20 21 #define FLOW_CNTR_PKTS(v, d) (((v) & (d)->packet_count_mask) >> \ 22 (d)->packet_count_shift) 23 #define FLOW_CNTR_BYTES(v, d) (((v) & (d)->byte_count_mask) >> \ 24 (d)->byte_count_shift) 25 26 #define FLOW_CNTR_PC_FLOW_VALID 0x1000000 27 28 struct bnxt_ulp_fc_core_ops { 29 int32_t 30 (*ulp_flow_stat_get)(struct bnxt_ulp_context *ctxt, 31 uint8_t direction, 32 uint32_t session_type, 33 uint64_t handle, 34 struct rte_flow_query_count *count); 35 int32_t 36 (*ulp_flow_stats_accum_update)(struct bnxt_ulp_context *ctxt, 37 struct bnxt_ulp_fc_info *ulp_fc_info, 38 struct bnxt_ulp_device_params *dparms); 39 }; 40 41 struct sw_acc_counter { 42 uint64_t pkt_count; 43 uint64_t byte_count; 44 bool valid; 45 uint32_t hw_cntr_id; 46 uint32_t pc_flow_idx; 47 enum bnxt_ulp_session_type session_type; 48 }; 49 50 struct hw_fc_mem_info { 51 /* 52 * [out] mem_va, pointer to the allocated memory. 53 */ 54 void *mem_va; 55 /* 56 * [out] mem_pa, physical address of the allocated memory. 57 */ 58 void *mem_pa; 59 uint32_t start_idx; 60 bool start_idx_is_set; 61 }; 62 63 struct bnxt_ulp_fc_info { 64 struct sw_acc_counter *sw_acc_tbl[TF_DIR_MAX]; 65 struct hw_fc_mem_info shadow_hw_tbl[TF_DIR_MAX]; 66 uint32_t flags; 67 uint32_t num_entries; 68 pthread_mutex_t fc_lock; 69 uint32_t num_counters; 70 const struct bnxt_ulp_fc_core_ops *fc_ops; 71 }; 72 73 int32_t 74 ulp_fc_mgr_init(struct bnxt_ulp_context *ctxt); 75 76 /* 77 * Release all resources in the flow counter manager for this ulp context 78 * 79 * ctxt [in] The ulp context for the flow counter manager 80 */ 81 int32_t 82 ulp_fc_mgr_deinit(struct bnxt_ulp_context *ctxt); 83 84 /* 85 * Setup the Flow counter timer thread that will fetch/accumulate raw counter 86 * data from the chip's internal flow counters 87 * 88 * ctxt [in] The ulp context for the flow counter manager 89 */ 90 int32_t 91 ulp_fc_mgr_thread_start(struct bnxt_ulp_context *ctxt); 92 93 /* 94 * Alarm handler that will issue the TF-Core API to fetch 95 * data from the chip's internal flow counters 96 * 97 * ctxt [in] The ulp context for the flow counter manager 98 */ 99 void 100 ulp_fc_mgr_alarm_cb(void *arg); 101 102 /* 103 * Cancel the alarm handler 104 * 105 * ctxt [in] The ulp context for the flow counter manager 106 * 107 */ 108 void ulp_fc_mgr_thread_cancel(struct bnxt_ulp_context *ctxt); 109 110 /* 111 * Set the starting index that indicates the first HW flow 112 * counter ID 113 * 114 * ctxt [in] The ulp context for the flow counter manager 115 * 116 * dir [in] The direction of the flow 117 * 118 * start_idx [in] The HW flow counter ID 119 * 120 */ 121 int ulp_fc_mgr_start_idx_set(struct bnxt_ulp_context *ctxt, uint8_t dir, 122 uint32_t start_idx); 123 124 /* 125 * Set the corresponding SW accumulator table entry based on 126 * the difference between this counter ID and the starting 127 * counter ID. Also, keep track of num of active counter enabled 128 * flows. 129 * 130 * ctxt [in] The ulp context for the flow counter manager 131 * 132 * dir [in] The direction of the flow 133 * 134 * hw_cntr_id [in] The HW flow counter ID 135 * 136 */ 137 int ulp_fc_mgr_cntr_set(struct bnxt_ulp_context *ctxt, enum tf_dir dir, 138 uint32_t hw_cntr_id, 139 enum bnxt_ulp_session_type session_type); 140 141 /* 142 * Reset the corresponding SW accumulator table entry based on 143 * the difference between this counter ID and the starting 144 * counter ID. 145 * 146 * ctxt [in] The ulp context for the flow counter manager 147 * 148 * dir [in] The direction of the flow 149 * 150 * hw_cntr_id [in] The HW flow counter ID 151 * 152 */ 153 int ulp_fc_mgr_cntr_reset(struct bnxt_ulp_context *ctxt, uint8_t dir, 154 uint32_t hw_cntr_id); 155 /* 156 * Check if the starting HW counter ID value is set in the 157 * flow counter manager. 158 * 159 * ctxt [in] The ulp context for the flow counter manager 160 * 161 * dir [in] The direction of the flow 162 * 163 */ 164 bool ulp_fc_mgr_start_idx_isset(struct bnxt_ulp_context *ctxt, uint8_t dir); 165 166 /* 167 * Check if the alarm thread that walks through the flows is started 168 * 169 * ctxt [in] The ulp context for the flow counter manager 170 * 171 */ 172 bool ulp_fc_mgr_thread_isstarted(struct bnxt_ulp_context *ctxt); 173 174 /* 175 * Fill the rte_flow_query_count 'data' argument passed 176 * in the rte_flow_query() with the values obtained and 177 * accumulated locally. 178 * 179 * ctxt [in] The ulp context for the flow counter manager 180 * 181 * flow_id [in] The HW flow ID 182 * 183 * count [out] The rte_flow_query_count 'data' that is set 184 * 185 */ 186 int ulp_fc_mgr_query_count_get(struct bnxt_ulp_context *ulp_ctx, 187 uint32_t flow_id, 188 struct rte_flow_query_count *count); 189 190 /* 191 * Set the parent flow if in the SW accumulator table entry 192 * 193 * ctxt [in] The ulp context for the flow counter manager 194 * 195 * dir [in] The direction of the flow 196 * 197 * hw_cntr_id [in] The HW flow counter ID 198 * 199 * pc_idx [in] parent child db index 200 * 201 */ 202 int32_t ulp_fc_mgr_cntr_parent_flow_set(struct bnxt_ulp_context *ctxt, 203 uint8_t dir, 204 uint32_t hw_cntr_id, 205 uint32_t pc_idx); 206 207 extern const struct bnxt_ulp_fc_core_ops ulp_fc_tf_core_ops; 208 extern const struct bnxt_ulp_fc_core_ops ulp_fc_tfc_core_ops; 209 210 #endif /* _ULP_FC_MGR_H_ */ 211