1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2014-2021 Broadcom
12 #define ULP_FLAG_FC_THREAD BIT(0)
13 #define ULP_FC_TIMER 1/* Timer freq in Sec Flow Counters */
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)
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)
24 struct sw_acc_counter {
29 uint32_t parent_flow_id;
32 struct hw_fc_mem_info {
34 * [out] mem_va, pointer to the allocated memory.
38 * [out] mem_pa, physical address of the allocated memory.
42 bool start_idx_is_set;
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];
50 pthread_mutex_t fc_lock;
51 uint32_t num_counters;
55 ulp_fc_mgr_init(struct bnxt_ulp_context *ctxt);
58 * Release all resources in the flow counter manager for this ulp context
60 * ctxt [in] The ulp context for the flow counter manager
63 ulp_fc_mgr_deinit(struct bnxt_ulp_context *ctxt);
66 * Setup the Flow counter timer thread that will fetch/accumulate raw counter
67 * data from the chip's internal flow counters
69 * ctxt [in] The ulp context for the flow counter manager
72 ulp_fc_mgr_thread_start(struct bnxt_ulp_context *ctxt);
75 * Alarm handler that will issue the TF-Core API to fetch
76 * data from the chip's internal flow counters
78 * ctxt [in] The ulp context for the flow counter manager
81 ulp_fc_mgr_alarm_cb(void *arg);
84 * Cancel the alarm handler
86 * ctxt [in] The ulp context for the flow counter manager
89 void ulp_fc_mgr_thread_cancel(struct bnxt_ulp_context *ctxt);
92 * Set the starting index that indicates the first HW flow
95 * ctxt [in] The ulp context for the flow counter manager
97 * dir [in] The direction of the flow
99 * start_idx [in] The HW flow counter ID
102 int ulp_fc_mgr_start_idx_set(struct bnxt_ulp_context *ctxt, enum tf_dir dir,
106 * Set the corresponding SW accumulator table entry based on
107 * the difference between this counter ID and the starting
108 * counter ID. Also, keep track of num of active counter enabled
111 * ctxt [in] The ulp context for the flow counter manager
113 * dir [in] The direction of the flow
115 * hw_cntr_id [in] The HW flow counter ID
118 int ulp_fc_mgr_cntr_set(struct bnxt_ulp_context *ctxt, enum tf_dir dir,
119 uint32_t hw_cntr_id);
121 * Reset the corresponding SW accumulator table entry based on
122 * the difference between this counter ID and the starting
125 * ctxt [in] The ulp context for the flow counter manager
127 * dir [in] The direction of the flow
129 * hw_cntr_id [in] The HW flow counter ID
132 int ulp_fc_mgr_cntr_reset(struct bnxt_ulp_context *ctxt, enum tf_dir dir,
133 uint32_t hw_cntr_id);
135 * Check if the starting HW counter ID value is set in the
136 * flow counter manager.
138 * ctxt [in] The ulp context for the flow counter manager
140 * dir [in] The direction of the flow
143 bool ulp_fc_mgr_start_idx_isset(struct bnxt_ulp_context *ctxt, enum tf_dir dir);
146 * Check if the alarm thread that walks through the flows is started
148 * ctxt [in] The ulp context for the flow counter manager
151 bool ulp_fc_mgr_thread_isstarted(struct bnxt_ulp_context *ctxt);
154 * Fill the rte_flow_query_count 'data' argument passed
155 * in the rte_flow_query() with the values obtained and
156 * accumulated locally.
158 * ctxt [in] The ulp context for the flow counter manager
160 * flow_id [in] The HW flow ID
162 * count [out] The rte_flow_query_count 'data' that is set
165 int ulp_fc_mgr_query_count_get(struct bnxt_ulp_context *ulp_ctx,
167 struct rte_flow_query_count *count);
170 * Set the parent flow if in the SW accumulator table entry
172 * ctxt [in] The ulp context for the flow counter manager
174 * dir [in] The direction of the flow
176 * hw_cntr_id [in] The HW flow counter ID
178 * fid [in] parent flow id
181 int32_t ulp_fc_mgr_cntr_parent_flow_set(struct bnxt_ulp_context *ctxt,
186 #endif /* _ULP_FC_MGR_H_ */