1 /*
2 * Copyright (c) 2022 Qualcomm Innovation Center, Inc. All rights reserved.
3 *
4 * Permission to use, copy, modify, and/or distribute this software for
5 * any purpose with or without fee is hereby granted, provided that the
6 * above copyright notice and this permission notice appear in all
7 * copies.
8 *
9 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
10 * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
11 * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
12 * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
13 * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
14 * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
15 * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
16 * PERFORMANCE OF THIS SOFTWARE.
17 */
18
19 #if !defined(WLAN_DP_BUS_BANDWIDTH_H)
20 #define WLAN_DP_BUS_BANDWIDTH_H
21 /**
22 * DOC: wlan_dp_bus_bandwidth.h
23 *
24 * Bus Bandwidth Manager implementation
25 */
26
27 #include "wlan_dp_priv.h"
28 #include <qdf_types.h>
29 #include <qca_vendor.h>
30 #include <wlan_objmgr_psoc_obj.h>
31 #include "wlan_dp_public_struct.h"
32 #include "wlan_dp_priv.h"
33 #include <cdp_txrx_misc.h>
34
35 typedef const enum bus_bw_level
36 bus_bw_table_type[QCA_WLAN_802_11_MODE_INVALID][TPUT_LEVEL_MAX];
37
38 /**
39 * struct bbm_context: Bus Bandwidth Manager context
40 *
41 * @curr_bus_bw_lookup_table: current bus bw lookup table
42 * @curr_vote_level: current vote level
43 * @per_policy_vote: per BBM policy related vote
44 * @bbm_lock: BBM API lock
45 */
46 struct bbm_context {
47 bus_bw_table_type *curr_bus_bw_lookup_table;
48 enum bus_bw_level curr_vote_level;
49 enum bus_bw_level per_policy_vote[BBM_MAX_POLICY];
50 qdf_mutex_t bbm_lock;
51 };
52
53 #ifdef FEATURE_BUS_BANDWIDTH_MGR
54 /**
55 * dp_bbm_context_init() - Initialize BBM context
56 * @psoc: psoc Handle
57 *
58 * Returns: error code
59 */
60 int dp_bbm_context_init(struct wlan_objmgr_psoc *psoc);
61
62 /**
63 * dp_bbm_context_deinit() - De-initialize BBM context
64 * @psoc: psoc Handle
65 *
66 * Returns: None
67 */
68 void dp_bbm_context_deinit(struct wlan_objmgr_psoc *psoc);
69
70 /**
71 * dp_bbm_apply_independent_policy() - Function to apply independent policies
72 * to set the bus bw level
73 * @psoc: psoc Handle
74 * @params: BBM policy related params
75 *
76 * The function applies BBM related policies and appropriately sets the bus
77 * bandwidth level.
78 *
79 * Returns: None
80 */
81 void dp_bbm_apply_independent_policy(struct wlan_objmgr_psoc *psoc,
82 struct bbm_params *params);
83 #else
dp_bbm_context_init(struct wlan_objmgr_psoc * psoc)84 static inline int dp_bbm_context_init(struct wlan_objmgr_psoc *psoc)
85 {
86 return 0;
87 }
88
dp_bbm_context_deinit(struct wlan_objmgr_psoc * psoc)89 static inline void dp_bbm_context_deinit(struct wlan_objmgr_psoc *psoc)
90 {
91 }
92
93 static inline
dp_bbm_apply_independent_policy(struct wlan_objmgr_psoc * psoc,struct bbm_params * params)94 void dp_bbm_apply_independent_policy(struct wlan_objmgr_psoc *psoc,
95 struct bbm_params *params)
96 {
97 }
98 #endif /* FEATURE_BUS_BANDWIDTH_MGR */
99
100 #if defined(WLAN_FEATURE_DP_BUS_BANDWIDTH) && defined(FEATURE_RUNTIME_PM)
101 /**
102 * dp_rtpm_tput_policy_init() - Initialize RTPM tput policy
103 * @psoc: psoc handle
104 *
105 * Returns: None
106 */
107 void dp_rtpm_tput_policy_init(struct wlan_objmgr_psoc *psoc);
108
109 /**
110 * dp_rtpm_tput_policy_deinit() - Deinitialize RTPM tput policy
111 * @psoc: psoc handle
112 *
113 * Returns: None
114 */
115 void dp_rtpm_tput_policy_deinit(struct wlan_objmgr_psoc *psoc);
116
117 /**
118 * dp_rtpm_tput_policy_apply() - Apply RTPM tput policy
119 * @dp_ctx: dp_ctx handle
120 * @tput_level : Tput level
121 *
122 * Returns: None
123 */
124 void dp_rtpm_tput_policy_apply(struct wlan_dp_psoc_context *dp_ctx,
125 enum tput_level tput_level);
126
127 /**
128 * dp_rtpm_tput_policy_get_vote() - Get RTPM tput policy vote
129 * @dp_ctx: dp_ctx handle
130 *
131 * Returns: Current vote
132 */
133 int dp_rtpm_tput_policy_get_vote(struct wlan_dp_psoc_context *dp_ctx);
134 #else
135 static inline
dp_rtpm_tput_policy_init(struct wlan_objmgr_psoc * psoc)136 void dp_rtpm_tput_policy_init(struct wlan_objmgr_psoc *psoc)
137 {
138 }
139
140 static inline
dp_rtpm_tput_policy_deinit(struct wlan_objmgr_psoc * psoc)141 void dp_rtpm_tput_policy_deinit(struct wlan_objmgr_psoc *psoc)
142 {
143 }
144
145 static inline
dp_rtpm_tput_policy_apply(struct wlan_dp_psoc_context * dp_ctx,enum tput_level tput_level)146 void dp_rtpm_tput_policy_apply(struct wlan_dp_psoc_context *dp_ctx,
147 enum tput_level tput_level)
148 {
149 }
150
151 static inline int
dp_rtpm_tput_policy_get_vote(struct wlan_dp_psoc_context * dp_ctx)152 dp_rtpm_tput_policy_get_vote(struct wlan_dp_psoc_context *dp_ctx)
153 {
154 return -EINVAL;
155 }
156 #endif /* WLAN_FEATURE_DP_BUS_BANDWIDTH && FEATURE_RUNTIME_PM */
157
158 /**
159 * dp_set_high_bus_bw_request() - Set High Bandwidth request value
160 * @psoc: psoc handle
161 * @vdev_id: Vdev ID
162 * @high_bus_bw : Flag to set or clear high bandwidth request
163 *
164 * Return: None
165 */
dp_set_high_bus_bw_request(struct wlan_objmgr_psoc * psoc,uint8_t vdev_id,bool high_bus_bw)166 static inline void dp_set_high_bus_bw_request(struct wlan_objmgr_psoc *psoc,
167 uint8_t vdev_id,
168 bool high_bus_bw)
169 {
170 struct wlan_dp_psoc_context *dp_ctx = dp_psoc_get_priv(psoc);
171
172 if (high_bus_bw)
173 dp_ctx->high_bus_bw_request |= (1 << vdev_id);
174 else
175 dp_ctx->high_bus_bw_request &= ~(1 << vdev_id);
176 }
177
178 #ifdef WLAN_FEATURE_DP_BUS_BANDWIDTH
179 /**
180 * dp_reset_tcp_delack() - Reset tcp delack value to default
181 * @psoc: psoc handle
182 *
183 * Function used to reset TCP delack value to its default value
184 *
185 * Return: None
186 */
187 void dp_reset_tcp_delack(struct wlan_objmgr_psoc *psoc);
188
189 /**
190 * wlan_dp_update_tcp_rx_param() - update TCP param in RX dir
191 * @dp_ctx: Pointer to DP context
192 * @data: Parameters to update
193 *
194 * Return: None
195 */
196 void wlan_dp_update_tcp_rx_param(struct wlan_dp_psoc_context *dp_ctx,
197 struct wlan_rx_tp_data *data);
198
199 #ifdef RX_PERFORMANCE
200 /**
201 * dp_is_current_high_throughput() - Check if vote level is high
202 * @dp_ctx: Pointer to DP context
203 *
204 * Function used to check if vote level is high
205 *
206 * Return: True if vote level is high
207 */
208 bool dp_is_current_high_throughput(struct wlan_dp_psoc_context *dp_ctx);
209 #else
210 static inline
dp_is_current_high_throughput(struct wlan_dp_psoc_context * dp_ctx)211 bool dp_is_current_high_throughput(struct wlan_dp_psoc_context *dp_ctx)
212 {
213 return false;
214 }
215 #endif /* RX_PERFORMANCE */
216
217 /**
218 * dp_reset_tcp_delack() - Reset TCP delack
219 * @psoc: psoc handle
220 *
221 * Return: None
222 */
223 void dp_reset_tcp_delack(struct wlan_objmgr_psoc *psoc);
224
225 /**
226 * dp_get_current_throughput_level() - Get the current vote
227 * level
228 * @dp_ctx: DP Context handle
229 *
230 * Return: current vote level
231 */
232 static inline enum pld_bus_width_type
dp_get_current_throughput_level(struct wlan_dp_psoc_context * dp_ctx)233 dp_get_current_throughput_level(struct wlan_dp_psoc_context *dp_ctx)
234 {
235 return dp_ctx->cur_vote_level;
236 }
237
238 /**
239 * dp_set_current_throughput_level() - update the current vote
240 * level
241 * @psoc: psoc object
242 * @next_vote_level: pld_bus_width_type voting level
243 *
244 * This function updates the current vote level to the new level
245 * provided
246 *
247 * Return: None
248 */
249 static inline void
dp_set_current_throughput_level(struct wlan_objmgr_psoc * psoc,enum pld_bus_width_type next_vote_level)250 dp_set_current_throughput_level(struct wlan_objmgr_psoc *psoc,
251 enum pld_bus_width_type next_vote_level)
252 {
253 struct wlan_dp_psoc_context *dp_ctx = dp_psoc_get_priv(psoc);
254
255 dp_ctx->cur_vote_level = next_vote_level;
256 }
257
258 /**
259 * wlan_dp_display_tx_rx_histogram() - display tx rx histogram
260 * @psoc: psoc handle
261 *
262 * Return: none
263 */
264 void wlan_dp_display_tx_rx_histogram(struct wlan_objmgr_psoc *psoc);
265
266 /**
267 * wlan_dp_clear_tx_rx_histogram() - clear tx rx histogram
268 * @psoc: psoc handle
269 *
270 * Return: none
271 */
272 void wlan_dp_clear_tx_rx_histogram(struct wlan_objmgr_psoc *psoc);
273
274 /**
275 * dp_bus_bandwidth_init() - Initialize bus bandwidth data structures.
276 * @psoc: psoc handle
277 *
278 * Initialize bus bandwidth related data structures like spinlock and timer.
279 *
280 * Return: None.
281 */
282 int dp_bus_bandwidth_init(struct wlan_objmgr_psoc *psoc);
283
284 /**
285 * dp_bus_bandwidth_deinit() - De-initialize bus bandwidth data structures.
286 * @psoc: psoc handle
287 *
288 * De-initialize bus bandwidth related data structures like timer.
289 *
290 * Return: None.
291 */
292 void dp_bus_bandwidth_deinit(struct wlan_objmgr_psoc *psoc);
293
294 /**
295 * dp_bus_bw_compute_timer_start() - start the bandwidth timer
296 * @psoc: psoc handle
297 *
298 * Return: None
299 */
300 void dp_bus_bw_compute_timer_start(struct wlan_objmgr_psoc *psoc);
301
302 /**
303 * dp_bus_bw_compute_timer_try_start() - try to start the bandwidth timer
304 * @psoc: psoc handle
305 *
306 * This function ensures there is at least one interface in the assoc state
307 * before starting the bandwidth timer.
308 *
309 * Return: None
310 */
311 void dp_bus_bw_compute_timer_try_start(struct wlan_objmgr_psoc *psoc);
312
313 /**
314 * dp_bus_bw_compute_timer_stop() - stop the bandwidth timer
315 * @psoc: psoc handle
316 *
317 * Return: None
318 */
319 void dp_bus_bw_compute_timer_stop(struct wlan_objmgr_psoc *psoc);
320
321 /**
322 * dp_bus_bw_compute_timer_try_stop() - try to stop the bandwidth timer
323 * @psoc: psoc handle
324 *
325 * This function ensures there are no interface in the assoc state before
326 * stopping the bandwidth timer.
327 *
328 * Return: None
329 */
330 void dp_bus_bw_compute_timer_try_stop(struct wlan_objmgr_psoc *psoc);
331
332 /**
333 * dp_bus_bw_compute_prev_txrx_stats() - get tx and rx stats
334 * @vdev: vdev handle
335 *
336 * This function get the collected tx and rx stats before starting
337 * the bus bandwidth timer.
338 *
339 * Return: None
340 */
341 void dp_bus_bw_compute_prev_txrx_stats(struct wlan_objmgr_vdev *vdev);
342
343 /**
344 * dp_bus_bw_compute_reset_prev_txrx_stats() - reset previous tx and rx stats
345 * @vdev: vdev handle
346 *
347 * This function resets the previous tx rx stats.
348 *
349 * Return: None
350 */
351 void dp_bus_bw_compute_reset_prev_txrx_stats(struct wlan_objmgr_vdev *vdev);
352
353 /**
354 * dp_get_bus_bw_high_threshold() - Get the bus bw high threshold
355 * level
356 * @dp_ctx: DP Context handle
357 *
358 * Return: bus bw high threshold
359 */
360 static inline uint32_t
dp_get_bus_bw_high_threshold(struct wlan_dp_psoc_context * dp_ctx)361 dp_get_bus_bw_high_threshold(struct wlan_dp_psoc_context *dp_ctx)
362 {
363 return dp_ctx->dp_cfg.bus_bw_high_threshold;
364 }
365
366 #else
367 static inline
dp_reset_tcp_delack(struct wlan_objmgr_psoc * psoc)368 void dp_reset_tcp_delack(struct wlan_objmgr_psoc *psoc)
369 {
370 }
371
372 static inline
wlan_dp_update_tcp_rx_param(struct wlan_dp_psoc_context * dp_ctx,struct wlan_rx_tp_data * data)373 void wlan_dp_update_tcp_rx_param(struct wlan_dp_psoc_context *dp_ctx,
374 struct wlan_rx_tp_data *data)
375 {
376 }
377
378 static inline
dp_is_current_high_throughput(struct wlan_dp_psoc_context * dp_ctx)379 bool dp_is_current_high_throughput(struct wlan_dp_psoc_context *dp_ctx)
380 {
381 return false;
382 }
383
384 static inline enum pld_bus_width_type
dp_get_current_throughput_level(struct wlan_dp_psoc_context * dp_ctx)385 dp_get_current_throughput_level(struct wlan_dp_psoc_context *dp_ctx)
386 {
387 return PLD_BUS_WIDTH_NONE;
388 }
389
390 static inline
dp_set_current_throughput_level(struct wlan_objmgr_psoc * psoc,enum pld_bus_width_type next_vote_level)391 void dp_set_current_throughput_level(struct wlan_objmgr_psoc *psoc,
392 enum pld_bus_width_type next_vote_level)
393 {
394 }
395
396 static inline
wlan_dp_display_tx_rx_histogram(struct wlan_objmgr_psoc * psoc)397 void wlan_dp_display_tx_rx_histogram(struct wlan_objmgr_psoc *psoc)
398 {
399 }
400
401 static inline
wlan_dp_clear_tx_rx_histogram(struct wlan_objmgr_psoc * psoc)402 void wlan_dp_clear_tx_rx_histogram(struct wlan_objmgr_psoc *psoc)
403 {
404 }
405
406 static inline
dp_bus_bandwidth_init(struct wlan_objmgr_psoc * psoc)407 void dp_bus_bandwidth_init(struct wlan_objmgr_psoc *psoc)
408 {
409 }
410
411 static inline
dp_bus_bandwidth_deinit(struct wlan_objmgr_psoc * psoc)412 void dp_bus_bandwidth_deinit(struct wlan_objmgr_psoc *psoc)
413 {
414 }
415
416 static inline
dp_bus_bw_compute_timer_start(struct wlan_objmgr_psoc * psoc)417 void dp_bus_bw_compute_timer_start(struct wlan_objmgr_psoc *psoc)
418 {
419 }
420
421 static inline
dp_bus_bw_compute_timer_try_start(struct wlan_objmgr_psoc * psoc)422 void dp_bus_bw_compute_timer_try_start(struct wlan_objmgr_psoc *psoc)
423 {
424 }
425
426 static inline
dp_bus_bw_compute_timer_stop(struct wlan_objmgr_psoc * psoc)427 void dp_bus_bw_compute_timer_stop(struct wlan_objmgr_psoc *psoc)
428 {
429 }
430
431 static inline
dp_bus_bw_compute_timer_try_stop(struct wlan_objmgr_psoc * psoc)432 void dp_bus_bw_compute_timer_try_stop(struct wlan_objmgr_psoc *psoc)
433 {
434 }
435
436 static inline
dp_bus_bw_compute_prev_txrx_stats(struct wlan_objmgr_vdev * vdev)437 void dp_bus_bw_compute_prev_txrx_stats(struct wlan_objmgr_vdev *vdev)
438 {
439 }
440
441 static inline
dp_bus_bw_compute_reset_prev_txrx_stats(struct wlan_objmgr_vdev * vdev)442 void dp_bus_bw_compute_reset_prev_txrx_stats(struct wlan_objmgr_vdev *vdev)
443 {
444 }
445
446 static inline uint32_t
dp_get_bus_bw_high_threshold(struct wlan_dp_psoc_context * dp_ctx)447 dp_get_bus_bw_high_threshold(struct wlan_dp_psoc_context *dp_ctx)
448 {
449 return 0;
450 }
451
452 #endif /* WLAN_FEATURE_DP_BUS_BANDWIDTH */
453 #endif /* WLAN_DP_BUS_BANDWIDTH_H */
454