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