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 init/deint functions for dcs module. 19 */ 20 21 #include "wlan_dcs_init_deinit_api.h" 22 #include "../../core/src/wlan_dcs.h" 23 #include "wlan_dcs_cfg.h" 24 #include "cfg_ucfg_api.h" 25 26 /** 27 * wlan_dcs_psoc_obj_create_notification() - dcs psoc cretae handler 28 * @psoc: psoc object 29 * @arg_list: Argument list 30 * 31 * return: QDF_STATUS_SUCCESS for success or error code 32 */ 33 static QDF_STATUS 34 wlan_dcs_psoc_obj_create_notification(struct wlan_objmgr_psoc *psoc, 35 void *arg_list) 36 { 37 QDF_STATUS status; 38 struct dcs_psoc_priv_obj *dcs_psoc_obj; 39 40 dcs_psoc_obj = qdf_mem_malloc(sizeof(*dcs_psoc_obj)); 41 42 if (!dcs_psoc_obj) 43 return QDF_STATUS_E_NOMEM; 44 45 status = wlan_objmgr_psoc_component_obj_attach(psoc, 46 WLAN_UMAC_COMP_DCS, 47 dcs_psoc_obj, 48 QDF_STATUS_SUCCESS); 49 50 if (QDF_IS_STATUS_ERROR(status)) { 51 dcs_err("dcs pdev obj attach failed"); 52 qdf_mem_free(dcs_psoc_obj); 53 return status; 54 } 55 56 dcs_info("dcs psoc object attached"); 57 58 return status; 59 } 60 61 /** 62 * wlan_dcs_psoc_obj_destroy_notification() - dcs psoc destroy handler 63 * @psoc: psoc object 64 * @arg_list: Argument list 65 * 66 * return: QDF_STATUS_SUCCESS for success or error code 67 */ 68 static QDF_STATUS 69 wlan_dcs_psoc_obj_destroy_notification(struct wlan_objmgr_psoc *psoc, 70 void *arg_list) 71 { 72 QDF_STATUS status; 73 uint8_t loop; 74 struct dcs_psoc_priv_obj *dcs_psoc_obj = 75 wlan_objmgr_psoc_get_comp_private_obj(psoc, WLAN_UMAC_COMP_DCS); 76 77 if (!dcs_psoc_obj) { 78 dcs_err("invalid wifi dcs obj"); 79 return QDF_STATUS_E_FAULT; 80 } 81 82 status = wlan_objmgr_psoc_component_obj_detach(psoc, 83 WLAN_UMAC_COMP_DCS, 84 dcs_psoc_obj); 85 for (loop = 0; loop < WLAN_DCS_MAX_PDEVS; loop++) 86 qdf_timer_free(&dcs_psoc_obj->dcs_pdev_priv[loop]. 87 dcs_disable_timer); 88 qdf_mem_free(dcs_psoc_obj); 89 90 return status; 91 } 92 93 QDF_STATUS wlan_dcs_init(void) 94 { 95 QDF_STATUS status = QDF_STATUS_SUCCESS; 96 97 status = wlan_objmgr_register_psoc_create_handler( 98 WLAN_UMAC_COMP_DCS, 99 wlan_dcs_psoc_obj_create_notification, 100 NULL); 101 102 if (QDF_IS_STATUS_ERROR(status)) 103 goto err_psoc_create; 104 105 status = wlan_objmgr_register_psoc_destroy_handler( 106 WLAN_UMAC_COMP_DCS, 107 wlan_dcs_psoc_obj_destroy_notification, 108 NULL); 109 110 if (QDF_IS_STATUS_ERROR(status)) 111 goto err_psoc_delete; 112 113 return QDF_STATUS_SUCCESS; 114 115 err_psoc_delete: 116 wlan_objmgr_unregister_psoc_create_handler( 117 WLAN_UMAC_COMP_DCS, 118 wlan_dcs_psoc_obj_create_notification, 119 NULL); 120 err_psoc_create: 121 return status; 122 } 123 124 QDF_STATUS wlan_dcs_deinit(void) 125 { 126 QDF_STATUS status = QDF_STATUS_SUCCESS; 127 128 status = wlan_objmgr_unregister_psoc_create_handler( 129 WLAN_UMAC_COMP_DCS, 130 wlan_dcs_psoc_obj_create_notification, 131 NULL); 132 133 if (QDF_IS_STATUS_ERROR(status)) 134 return QDF_STATUS_E_FAILURE; 135 136 status = wlan_objmgr_unregister_psoc_destroy_handler( 137 WLAN_UMAC_COMP_DCS, 138 wlan_dcs_psoc_obj_destroy_notification, 139 NULL); 140 141 if (QDF_IS_STATUS_ERROR(status)) 142 return QDF_STATUS_E_FAILURE; 143 144 return QDF_STATUS_SUCCESS; 145 } 146 147 QDF_STATUS wlan_dcs_enable(struct wlan_objmgr_psoc *psoc) 148 { 149 return wlan_dcs_attach(psoc); 150 } 151 152 QDF_STATUS wlan_dcs_disable(struct wlan_objmgr_psoc *psoc) 153 { 154 return wlan_dcs_detach(psoc); 155 } 156 157 QDF_STATUS wlan_dcs_psoc_open(struct wlan_objmgr_psoc *psoc) 158 { 159 struct dcs_psoc_priv_obj *dcs_psoc_obj; 160 struct dcs_pdev_priv_obj *dcs_pdev_priv; 161 uint8_t loop; 162 163 if (!psoc) { 164 dcs_err("psoc is NULL"); 165 return QDF_STATUS_E_INVAL; 166 } 167 168 dcs_psoc_obj = wlan_objmgr_psoc_get_comp_private_obj( 169 psoc, WLAN_UMAC_COMP_DCS); 170 if (!dcs_psoc_obj) { 171 dcs_err("dcs psoc private object is NULL"); 172 return QDF_STATUS_E_FAILURE; 173 } 174 175 for (loop = 0; loop < WLAN_DCS_MAX_PDEVS; loop++) { 176 dcs_pdev_priv = &dcs_psoc_obj->dcs_pdev_priv[loop]; 177 dcs_pdev_priv->dcs_host_params.dcs_enable_cfg = 178 cfg_get(psoc, CFG_DCS_ENABLE); 179 dcs_pdev_priv->dcs_host_params.dcs_debug = 180 cfg_get(psoc, CFG_DCS_DEBUG); 181 dcs_pdev_priv->dcs_host_params.phy_err_penalty = 182 cfg_get(psoc, CFG_DCS_PHY_ERR_PENALTY); 183 dcs_pdev_priv->dcs_host_params.phy_err_threshold = 184 cfg_get(psoc, CFG_DCS_PHY_ERR_THRESHOLD); 185 dcs_pdev_priv->dcs_host_params.radar_err_threshold = 186 cfg_get(psoc, CFG_DCS_RADAR_ERR_THRESHOLD); 187 dcs_pdev_priv->dcs_host_params.coch_intfr_threshold = 188 cfg_get(psoc, CFG_DCS_COCH_INTFR_THRESHOLD); 189 dcs_pdev_priv->dcs_host_params.user_max_cu = 190 cfg_get(psoc, CFG_DCS_USER_MAX_CU); 191 dcs_pdev_priv->dcs_host_params.intfr_detection_threshold = 192 cfg_get(psoc, CFG_DCS_INTFR_DETECTION_THRESHOLD); 193 dcs_pdev_priv->dcs_host_params.intfr_detection_window = 194 cfg_get(psoc, CFG_DCS_INTFR_DETECTION_WINDOW); 195 dcs_pdev_priv->dcs_host_params.tx_err_threshold = 196 cfg_get(psoc, CFG_DCS_TX_ERR_THRESHOLD); 197 dcs_pdev_priv->dcs_freq_ctrl_params. 198 disable_threshold_per_5mins = 199 cfg_get(psoc, CFG_DCS_DISABLE_THRESHOLD_PER_5MINS); 200 dcs_pdev_priv->dcs_freq_ctrl_params.restart_delay = 201 cfg_get(psoc, CFG_DCS_RESTART_DELAY); 202 203 qdf_timer_init(NULL, &dcs_pdev_priv->dcs_disable_timer, 204 wlan_dcs_disable_timer_fn, 205 &dcs_pdev_priv->dcs_timer_args, 206 QDF_TIMER_TYPE_WAKE_APPS); 207 } 208 209 return QDF_STATUS_SUCCESS; 210 } 211