1 /* 2 * Copyright (c) 2020, The Linux Foundation. All rights reserved. 3 * 4 * Permission to use, copy, modify, and/or distribute this software for any 5 * purpose with or without fee is hereby granted, provided that the above 6 * copyright notice and this permission notice appear in all copies. 7 * 8 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 9 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 10 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 11 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 12 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 13 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 14 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 15 */ 16 17 /** 18 * DOC: This file has main dcs structures definition. 19 */ 20 21 #ifndef _WLAN_DCS_H_ 22 #define _WLAN_DCS_H_ 23 24 #include <wmi_unified_param.h> 25 #include "wlan_dcs_tgt_api.h" 26 #include "wlan_dcs_ucfg_api.h" 27 28 #define dcs_debug(args ...) \ 29 QDF_TRACE_DEBUG(QDF_MODULE_ID_DCS, ## args) 30 #define dcs_info(args ...) \ 31 QDF_TRACE_INFO(QDF_MODULE_ID_DCS, ## args) 32 #define dcs_err(args ...) \ 33 QDF_TRACE_ERROR(QDF_MODULE_ID_DCS, ## args) 34 35 #define WLAN_DCS_MAX_PDEVS 3 36 37 #define DCS_TX_MAX_CU 30 38 #define MAX_DCS_TIME_RECORD 10 39 #define DCS_FREQ_CONTROL_TIME (5 * 60 * 1000) 40 41 /** 42 * enum wlan_dcs_debug_level - dcs debug trace level 43 * @DCS_DEBUG_DISABLE: disable debug trace 44 * @DCS_DEBUG_CRITICAL: critical debug trace level 45 * @DCS_DEBUG_VERBOSE: verbose debug trace level 46 */ 47 enum wlan_dcs_debug_level { 48 DCS_DEBUG_DISABLE = 0, 49 DCS_DEBUG_CRITICAL = 1, 50 DCS_DEBUG_VERBOSE = 2 51 }; 52 53 /** 54 * struct pdev_dcs_im_stats - define dcs interference mitigation 55 * stats in pdev object 56 * @prev_dcs_im_stats: previous statistics at last time 57 * @user_dcs_im_stats: statistics requested from userspace 58 * @im_intfr_cnt: number of times the interference is 59 * detected within detection window 60 * @im_sample_cnt: sample counter 61 */ 62 struct pdev_dcs_im_stats { 63 struct wlan_host_dcs_im_tgt_stats prev_dcs_im_stats; 64 struct wlan_host_dcs_im_user_stats user_dcs_im_stats; 65 uint8_t im_intfr_cnt; 66 uint8_t im_samp_cnt; 67 }; 68 69 /** 70 * struct pdev_dcs_params - define dcs configuration parameter in pdev object 71 * @dcs_enable_cfg: dcs enable from ini config 72 * @dcs_enable: dcs enable from ucfg config 73 * @dcs_algorithm_process: do dcs algorithm process or not 74 * @dcs_debug: dcs debug trace level 75 * @phy_err_penalty: phy error penalty 76 * @phy_err_threshold: phy error threshold 77 * @radar_err_threshold: radar error threshold 78 * @coch_intfr_threshold: co-channel interference threshold 79 * @user_max_cu: tx channel utilization due to AP's tx and rx 80 * @intfr_detection_threshold: interference detection threshold 81 * @intfr_detection_window: interference sampling window 82 * @tx_err_threshold: transmission failure rate threshold 83 * @user_request_count: counter of stats requested from userspace 84 * @notify_user: whether to notify userspace 85 */ 86 struct pdev_dcs_params { 87 uint8_t dcs_enable_cfg; 88 uint8_t dcs_enable; 89 bool dcs_algorithm_process; 90 enum wlan_dcs_debug_level dcs_debug; 91 uint32_t phy_err_penalty; 92 uint32_t phy_err_threshold; 93 uint32_t radar_err_threshold; 94 uint32_t coch_intfr_threshold; 95 uint32_t user_max_cu; 96 uint32_t intfr_detection_threshold; 97 uint32_t intfr_detection_window; 98 uint32_t tx_err_threshold; 99 uint32_t user_request_count; 100 uint8_t notify_user; 101 }; 102 103 /** 104 * struct pdev_dcs_freq_ctrl_params - define dcs frequency control parameter 105 * in pdebv object 106 * @disable_threshold_per_5mins: in five minutes, if dcs happen more than 107 * threshold, then disable dcs for some time 108 * @restart_delay: when dcs happen more than threshold in five minutes, 109 * then start to disable dcs for restart_delay minutes 110 * @timestamp: record dcs happened timestamp 111 * @dcs_happened_count: dcs happened count 112 * @disable_delay_process: in dcs disable delay process or not 113 */ 114 struct pdev_dcs_freq_ctrl_params { 115 uint8_t disable_threshold_per_5mins; 116 uint32_t restart_delay; 117 unsigned long timestamp[MAX_DCS_TIME_RECORD]; 118 unsigned long dcs_happened_count; 119 bool disable_delay_process; 120 }; 121 122 /** 123 * struct pdev_dcs_timer_args - define pdev dcs timer args 124 * @psoc: psoc pointer 125 * @pdev_id: pdev id 126 */ 127 struct pdev_dcs_timer_args { 128 struct wlan_objmgr_psoc *psoc; 129 uint32_t pdev_id; 130 }; 131 132 /** 133 * struct psoc_dcs_cbk - define dcs callback in psoc oject 134 * @cbk: callback 135 * @arg: arguments 136 */ 137 struct psoc_dcs_cbk { 138 dcs_callback cbk; 139 void *arg; 140 }; 141 142 /** 143 * struct dcs_pdev_priv_obj - define dcs pdev priv 144 * @dcs_host_params: dcs host configuration parameter 145 * @dcs_im_stats: dcs im statistics 146 * @dcs_freq_ctrl_params: dcs frequency control parameter 147 * @dcs_disable_timer: dcs disable timer 148 * @dcs_timer_args: dcs disable timer args 149 * @lock: lock to protect dcs pdev priv 150 * @requestor_vdev_id: user request vdev id 151 * @user_cb: user request callback 152 */ 153 struct dcs_pdev_priv_obj { 154 struct pdev_dcs_params dcs_host_params; 155 struct pdev_dcs_im_stats dcs_im_stats; 156 struct pdev_dcs_freq_ctrl_params dcs_freq_ctrl_params; 157 qdf_timer_t dcs_disable_timer; 158 struct pdev_dcs_timer_args dcs_timer_args; 159 qdf_spinlock_t lock; 160 uint8_t requestor_vdev_id; 161 void (*user_cb)(uint8_t vdev_id, 162 struct wlan_host_dcs_im_user_stats *stats, 163 int status); 164 }; 165 166 /** 167 * struct dcs_psoc_priv_obj - define dcs psoc priv 168 * @dcs_pdev_priv: dcs pdev priv 169 * @dcs_cbk: dcs callback 170 */ 171 struct dcs_psoc_priv_obj { 172 struct dcs_pdev_priv_obj dcs_pdev_priv[WLAN_DCS_MAX_PDEVS]; 173 struct psoc_dcs_cbk dcs_cbk; 174 }; 175 176 /** 177 * wlan_dcs_get_pdev_private_obj() - get dcs pdev private object 178 * @psoc: psoc pointer 179 * @pdev_id: pdev_id 180 * 181 * API to retrieve the pdev private object from the psoc context 182 * 183 * Return: pdev private object pointer on success, NULL on error 184 */ 185 struct dcs_pdev_priv_obj * 186 wlan_dcs_get_pdev_private_obj(struct wlan_objmgr_psoc *psoc, uint32_t pdev_id); 187 188 /** 189 * wlan_dcs_attach() - Attach dcs handler 190 * @psoc: psoc pointer 191 * 192 * This function gets called to register dcs FW events handler 193 * 194 * Return: QDF_STATUS 195 */ 196 QDF_STATUS wlan_dcs_attach(struct wlan_objmgr_psoc *psoc); 197 198 /** 199 * wlan_dcs_detach() - Detach dcs handler 200 * @psoc: psoc pointer 201 * 202 * This function gets called to unregister dcs FW events handler 203 * 204 * Return: QDF_STATUS 205 */ 206 QDF_STATUS wlan_dcs_detach(struct wlan_objmgr_psoc *psoc); 207 208 /** 209 * wlan_dcs_cmd_send() - Send dcs command to target_if layer 210 * @psoc: psoc pointer 211 * @pdev_id: pdev_id 212 * @is_host_pdev_id: pdev_id is host id or not 213 * 214 * The function gets called to send dcs command to FW 215 * 216 * return: QDF_STATUS_SUCCESS for success or error code 217 */ 218 QDF_STATUS wlan_dcs_cmd_send(struct wlan_objmgr_psoc *psoc, 219 uint32_t pdev_id, 220 bool is_host_pdev_id); 221 222 /** 223 * wlan_dcs_process() - dcs process main entry 224 * @psoc: psoc pointer 225 * @event: dcs stats event pointer 226 * 227 * This function is the main entry to do dcs related operation 228 * such as algorithm handling and dcs frequency control. 229 * 230 * Return: QDF_STATUS 231 */ 232 QDF_STATUS wlan_dcs_process(struct wlan_objmgr_psoc *psoc, 233 struct dcs_stats_event *event); 234 235 /** 236 * wlan_dcs_disable_timer_fn() - dcs disable timer callback 237 * @dcs_timer_args: dcs timer argument pointer 238 * 239 * This function gets called when dcs disable timer timeout 240 * 241 * Return: None 242 */ 243 void wlan_dcs_disable_timer_fn(void *dcs_timer_args); 244 245 /** 246 * wlan_dcs_clear() - clear dcs information 247 * @psoc: psoc pointer 248 * @pdev_id: pdev_id 249 * 250 * The function gets called to clear dcs information such as dcs 251 * frequency control parameters and stop dcs disable timer 252 * 253 * Return: None 254 */ 255 void wlan_dcs_clear(struct wlan_objmgr_psoc *psoc, uint32_t pdev_id); 256 257 /** 258 * wlan_dcs_set_algorithm_process() - config dcs event data to do algorithm 259 * process or not 260 * @psoc: psoc pointer 261 * @pdev_id: pdev_id 262 * @dcs_algorithm_process: dcs algorithm process 263 * 264 * The function gets called to config dcs event data to do algorithm 265 * process or not 266 * 267 * Return: None 268 */ 269 void wlan_dcs_set_algorithm_process(struct wlan_objmgr_psoc *psoc, 270 uint32_t pdev_id, 271 bool dcs_algorithm_process); 272 273 /* 274 * wlan_dcs_pdev_obj_lock() - private API to acquire spinlock at pdev 275 * @dcs_pdev: pointer to dcs pdev object 276 * 277 * Return: void 278 */ 279 static inline void wlan_dcs_pdev_obj_lock(struct dcs_pdev_priv_obj *dcs_pdev) 280 { 281 qdf_spin_lock_bh(&dcs_pdev->lock); 282 } 283 284 /** 285 * wlan_dcs_pdev_obj_unlock() - private api to release spinlock at pdev 286 * @dcs_pdev: pointer to dcs pdev object 287 * 288 * Return: void 289 */ 290 static inline void wlan_dcs_pdev_obj_unlock(struct dcs_pdev_priv_obj *dcs_pdev) 291 { 292 qdf_spin_unlock_bh(&dcs_pdev->lock); 293 } 294 #endif /* _WLAN_DCS_H_ */ 295