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