1 /* SPDX-License-Identifier: BSD-3-Clause 2 * Copyright(c) 2014-2019 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 }; 30 31 struct hw_fc_mem_info { 32 /* 33 * [out] mem_va, pointer to the allocated memory. 34 */ 35 void *mem_va; 36 /* 37 * [out] mem_pa, physical address of the allocated memory. 38 */ 39 void *mem_pa; 40 uint32_t start_idx; 41 }; 42 43 struct bnxt_ulp_fc_info { 44 struct sw_acc_counter *sw_acc_tbl[TF_DIR_MAX]; 45 struct hw_fc_mem_info shadow_hw_tbl[TF_DIR_MAX]; 46 uint32_t flags; 47 uint32_t num_entries; 48 pthread_mutex_t fc_lock; 49 }; 50 51 int32_t 52 ulp_fc_mgr_init(struct bnxt_ulp_context *ctxt); 53 54 /* 55 * Release all resources in the flow counter manager for this ulp context 56 * 57 * ctxt [in] The ulp context for the flow counter manager 58 */ 59 int32_t 60 ulp_fc_mgr_deinit(struct bnxt_ulp_context *ctxt); 61 62 /* 63 * Setup the Flow counter timer thread that will fetch/accumulate raw counter 64 * data from the chip's internal flow counters 65 * 66 * ctxt [in] The ulp context for the flow counter manager 67 */ 68 int32_t 69 ulp_fc_mgr_thread_start(struct bnxt_ulp_context *ctxt); 70 71 /* 72 * Alarm handler that will issue the TF-Core API to fetch 73 * data from the chip's internal flow counters 74 * 75 * ctxt [in] The ulp context for the flow counter manager 76 */ 77 void 78 ulp_fc_mgr_alarm_cb(void *arg); 79 80 /* 81 * Cancel the alarm handler 82 * 83 * ctxt [in] The ulp context for the flow counter manager 84 * 85 */ 86 void ulp_fc_mgr_thread_cancel(struct bnxt_ulp_context *ctxt); 87 88 /* 89 * Set the starting index that indicates the first HW flow 90 * counter ID 91 * 92 * ctxt [in] The ulp context for the flow counter manager 93 * 94 * dir [in] The direction of the flow 95 * 96 * start_idx [in] The HW flow counter ID 97 * 98 */ 99 int ulp_fc_mgr_start_idx_set(struct bnxt_ulp_context *ctxt, enum tf_dir dir, 100 uint32_t start_idx); 101 102 /* 103 * Set the corresponding SW accumulator table entry based on 104 * the difference between this counter ID and the starting 105 * counter ID. Also, keep track of num of active counter enabled 106 * flows. 107 * 108 * ctxt [in] The ulp context for the flow counter manager 109 * 110 * dir [in] The direction of the flow 111 * 112 * hw_cntr_id [in] The HW flow counter ID 113 * 114 */ 115 int ulp_fc_mgr_cntr_set(struct bnxt_ulp_context *ctxt, enum tf_dir dir, 116 uint32_t hw_cntr_id); 117 /* 118 * Reset the corresponding SW accumulator table entry based on 119 * the difference between this counter ID and the starting 120 * counter ID. 121 * 122 * ctxt [in] The ulp context for the flow counter manager 123 * 124 * dir [in] The direction of the flow 125 * 126 * hw_cntr_id [in] The HW flow counter ID 127 * 128 */ 129 int ulp_fc_mgr_cntr_reset(struct bnxt_ulp_context *ctxt, enum tf_dir dir, 130 uint32_t hw_cntr_id); 131 /* 132 * Check if the starting HW counter ID value is set in the 133 * flow counter manager. 134 * 135 * ctxt [in] The ulp context for the flow counter manager 136 * 137 * dir [in] The direction of the flow 138 * 139 */ 140 bool ulp_fc_mgr_start_idx_isset(struct bnxt_ulp_context *ctxt, enum tf_dir dir); 141 142 /* 143 * Check if the alarm thread that walks through the flows is started 144 * 145 * ctxt [in] The ulp context for the flow counter manager 146 * 147 */ 148 bool ulp_fc_mgr_thread_isstarted(struct bnxt_ulp_context *ctxt); 149 150 /* 151 * Fill the rte_flow_query_count 'data' argument passed 152 * in the rte_flow_query() with the values obtained and 153 * accumulated locally. 154 * 155 * ctxt [in] The ulp context for the flow counter manager 156 * 157 * flow_id [in] The HW flow ID 158 * 159 * count [out] The rte_flow_query_count 'data' that is set 160 * 161 */ 162 int ulp_fc_mgr_query_count_get(struct bnxt_ulp_context *ulp_ctx, 163 uint32_t flow_id, 164 struct rte_flow_query_count *count); 165 #endif /* _ULP_FC_MGR_H_ */ 166