1 /* 2 * Copyright (c) 2018 The Linux Foundation. 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 /** 20 * DOC: wlan_cp_stats_utils_api.c 21 * 22 * This file provide public API definitions for other accessing other UMAC 23 * components 24 */ 25 #include "../../core/src/wlan_cp_stats_defs.h" 26 #include "../../core/src/wlan_cp_stats_obj_mgr_handler.h" 27 #include <wlan_cp_stats_utils_api.h> 28 #include <wlan_cp_stats_ucfg_api.h> 29 30 QDF_STATUS wlan_cp_stats_init(void) 31 { 32 QDF_STATUS status = QDF_STATUS_E_FAILURE; 33 34 status = wlan_objmgr_register_psoc_create_handler 35 (WLAN_UMAC_COMP_CP_STATS, 36 wlan_cp_stats_psoc_obj_create_handler, 37 NULL); 38 if (QDF_IS_STATUS_ERROR(status)) { 39 cp_stats_err("Failed to register psoc create handler"); 40 goto wlan_cp_stats_psoc_init_fail1; 41 } 42 43 status = wlan_objmgr_register_psoc_destroy_handler 44 (WLAN_UMAC_COMP_CP_STATS, 45 wlan_cp_stats_psoc_obj_destroy_handler, 46 NULL); 47 if (QDF_IS_STATUS_ERROR(status)) { 48 cp_stats_err("Failed to register psoc destroy handler"); 49 goto wlan_cp_stats_psoc_init_fail2; 50 } 51 52 status = wlan_objmgr_register_pdev_create_handler 53 (WLAN_UMAC_COMP_CP_STATS, 54 wlan_cp_stats_pdev_obj_create_handler, 55 NULL); 56 if (QDF_IS_STATUS_ERROR(status)) { 57 cp_stats_err("Failed to register pdev create handler"); 58 goto wlan_cp_stats_pdev_init_fail1; 59 } 60 61 status = wlan_objmgr_register_pdev_destroy_handler 62 (WLAN_UMAC_COMP_CP_STATS, 63 wlan_cp_stats_pdev_obj_destroy_handler, 64 NULL); 65 if (QDF_IS_STATUS_ERROR(status)) { 66 cp_stats_err("Failed to register pdev destroy handler"); 67 goto wlan_cp_stats_pdev_init_fail2; 68 } 69 70 status = wlan_objmgr_register_vdev_create_handler 71 (WLAN_UMAC_COMP_CP_STATS, 72 wlan_cp_stats_vdev_obj_create_handler, 73 NULL); 74 if (QDF_IS_STATUS_ERROR(status)) { 75 cp_stats_err("Failed to register vdev create handler"); 76 goto wlan_cp_stats_vdev_init_fail1; 77 } 78 79 status = wlan_objmgr_register_vdev_destroy_handler 80 (WLAN_UMAC_COMP_CP_STATS, 81 wlan_cp_stats_vdev_obj_destroy_handler, 82 NULL); 83 if (QDF_IS_STATUS_ERROR(status)) { 84 cp_stats_err("Failed to register vdev destroy handler"); 85 goto wlan_cp_stats_vdev_init_fail2; 86 } 87 88 status = wlan_objmgr_register_peer_create_handler 89 (WLAN_UMAC_COMP_CP_STATS, 90 wlan_cp_stats_peer_obj_create_handler, 91 NULL); 92 if (QDF_IS_STATUS_ERROR(status)) { 93 cp_stats_err("Failed to register peer create handler"); 94 goto wlan_cp_stats_peer_init_fail1; 95 } 96 97 status = wlan_objmgr_register_peer_destroy_handler 98 (WLAN_UMAC_COMP_CP_STATS, 99 wlan_cp_stats_peer_obj_destroy_handler, 100 NULL); 101 if (QDF_IS_STATUS_ERROR(status)) { 102 cp_stats_err("Failed to register peer destroy handler"); 103 goto wlan_cp_stats_peer_init_fail2; 104 } 105 106 return QDF_STATUS_SUCCESS; 107 108 wlan_cp_stats_peer_init_fail2: 109 wlan_objmgr_unregister_peer_create_handler 110 (WLAN_UMAC_COMP_CP_STATS, 111 wlan_cp_stats_peer_obj_create_handler, 112 NULL); 113 wlan_cp_stats_peer_init_fail1: 114 wlan_objmgr_unregister_vdev_destroy_handler 115 (WLAN_UMAC_COMP_CP_STATS, 116 wlan_cp_stats_vdev_obj_destroy_handler, 117 NULL); 118 wlan_cp_stats_vdev_init_fail2: 119 wlan_objmgr_unregister_vdev_create_handler 120 (WLAN_UMAC_COMP_CP_STATS, 121 wlan_cp_stats_vdev_obj_create_handler, 122 NULL); 123 wlan_cp_stats_vdev_init_fail1: 124 wlan_objmgr_unregister_pdev_destroy_handler 125 (WLAN_UMAC_COMP_CP_STATS, 126 wlan_cp_stats_pdev_obj_destroy_handler, 127 NULL); 128 wlan_cp_stats_pdev_init_fail2: 129 wlan_objmgr_unregister_pdev_create_handler 130 (WLAN_UMAC_COMP_CP_STATS, 131 wlan_cp_stats_pdev_obj_create_handler, 132 NULL); 133 wlan_cp_stats_pdev_init_fail1: 134 wlan_objmgr_unregister_psoc_destroy_handler 135 (WLAN_UMAC_COMP_CP_STATS, 136 wlan_cp_stats_psoc_obj_destroy_handler, 137 NULL); 138 wlan_cp_stats_psoc_init_fail2: 139 wlan_objmgr_unregister_psoc_create_handler 140 (WLAN_UMAC_COMP_CP_STATS, 141 wlan_cp_stats_psoc_obj_create_handler, 142 NULL); 143 wlan_cp_stats_psoc_init_fail1: 144 return status; 145 } 146 147 QDF_STATUS wlan_cp_stats_deinit(void) 148 { 149 QDF_STATUS status = QDF_STATUS_E_FAILURE; 150 151 status = wlan_objmgr_unregister_psoc_create_handler 152 (WLAN_UMAC_COMP_CP_STATS, 153 wlan_cp_stats_psoc_obj_create_handler, 154 NULL); 155 if (QDF_IS_STATUS_ERROR(status)) 156 cp_stats_err("Failed to unregister psoc create handler"); 157 158 status = wlan_objmgr_unregister_psoc_destroy_handler 159 (WLAN_UMAC_COMP_CP_STATS, 160 wlan_cp_stats_psoc_obj_destroy_handler, 161 NULL); 162 if (QDF_IS_STATUS_ERROR(status)) 163 cp_stats_err("Failed to unregister psoc destroy handler"); 164 165 status = wlan_objmgr_unregister_pdev_create_handler 166 (WLAN_UMAC_COMP_CP_STATS, 167 wlan_cp_stats_pdev_obj_create_handler, 168 NULL); 169 if (QDF_IS_STATUS_ERROR(status)) 170 cp_stats_err("Failed to unregister pdev create handler"); 171 172 status = wlan_objmgr_unregister_pdev_destroy_handler 173 (WLAN_UMAC_COMP_CP_STATS, 174 wlan_cp_stats_pdev_obj_destroy_handler, 175 NULL); 176 if (QDF_IS_STATUS_ERROR(status)) 177 cp_stats_err("Failed to unregister pdev destroy handler"); 178 179 status = wlan_objmgr_unregister_vdev_create_handler 180 (WLAN_UMAC_COMP_CP_STATS, 181 wlan_cp_stats_vdev_obj_create_handler, 182 NULL); 183 if (QDF_IS_STATUS_ERROR(status)) 184 cp_stats_err("Failed to unregister vdev create handler"); 185 186 status = wlan_objmgr_unregister_vdev_destroy_handler 187 (WLAN_UMAC_COMP_CP_STATS, 188 wlan_cp_stats_vdev_obj_destroy_handler, 189 NULL); 190 if (QDF_IS_STATUS_ERROR(status)) 191 cp_stats_err("Failed to unregister vdev destroy handler"); 192 193 status = wlan_objmgr_unregister_peer_create_handler 194 (WLAN_UMAC_COMP_CP_STATS, 195 wlan_cp_stats_peer_obj_create_handler, 196 NULL); 197 if (QDF_IS_STATUS_ERROR(status)) 198 cp_stats_err("Failed to unregister peer create handler"); 199 200 status = wlan_objmgr_unregister_peer_destroy_handler 201 (WLAN_UMAC_COMP_CP_STATS, 202 wlan_cp_stats_peer_obj_destroy_handler, 203 NULL); 204 if (QDF_IS_STATUS_ERROR(status)) 205 cp_stats_err("Failed to unregister peer destroy handler"); 206 207 return status; 208 } 209 210 /* DA/OL specific call back initialization */ 211 QDF_STATUS wlan_cp_stats_open(struct wlan_objmgr_psoc *psoc) 212 { 213 QDF_STATUS status = QDF_STATUS_E_FAILURE; 214 struct cp_stats_context *csc; 215 216 if (!psoc) { 217 cp_stats_err("PSOC is null!"); 218 return QDF_STATUS_E_INVAL; 219 } 220 csc = 221 wlan_objmgr_psoc_get_comp_private_obj(psoc, WLAN_UMAC_COMP_CP_STATS); 222 if (!csc) { 223 cp_stats_err("cp_stats_context is null!"); 224 return QDF_STATUS_E_FAILURE; 225 } 226 227 if (csc->cp_stats_open) 228 status = csc->cp_stats_open(psoc); 229 230 qdf_spinlock_create(&csc->csc_lock); 231 return status; 232 } 233 234 QDF_STATUS wlan_cp_stats_close(struct wlan_objmgr_psoc *psoc) 235 { 236 struct cp_stats_context *csc; 237 238 if (!psoc) { 239 cp_stats_err("PSOC is null!"); 240 return QDF_STATUS_E_INVAL; 241 } 242 csc = 243 wlan_objmgr_psoc_get_comp_private_obj(psoc, WLAN_UMAC_COMP_CP_STATS); 244 if (csc && csc->cp_stats_close) { 245 csc->cp_stats_close(psoc); 246 qdf_spinlock_destroy(&csc->csc_lock); 247 } 248 249 return QDF_STATUS_SUCCESS; 250 } 251 252 /* WMI registrations stage */ 253 QDF_STATUS wlan_cp_stats_enable(struct wlan_objmgr_psoc *psoc) 254 { 255 QDF_STATUS status = QDF_STATUS_E_FAILURE; 256 struct cp_stats_context *csc; 257 258 if (!psoc) { 259 cp_stats_err("PSOC is null!"); 260 return QDF_STATUS_E_INVAL; 261 } 262 csc = 263 wlan_objmgr_psoc_get_comp_private_obj(psoc, WLAN_UMAC_COMP_CP_STATS); 264 if (!csc) { 265 cp_stats_err("cp_stats_context is null!"); 266 return QDF_STATUS_E_FAILURE; 267 } 268 269 if (csc->cp_stats_enable) 270 status = csc->cp_stats_enable(psoc); 271 272 return status; 273 } 274 275 QDF_STATUS wlan_cp_stats_disable(struct wlan_objmgr_psoc *psoc) 276 { 277 struct cp_stats_context *csc; 278 279 if (!psoc) { 280 cp_stats_err("PSOC is null!\n"); 281 return QDF_STATUS_E_INVAL; 282 } 283 csc = 284 wlan_objmgr_psoc_get_comp_private_obj(psoc, WLAN_UMAC_COMP_CP_STATS); 285 if (csc && csc->cp_stats_disable) 286 csc->cp_stats_disable(psoc); 287 288 return QDF_STATUS_SUCCESS; 289 } 290 291 QDF_STATUS 292 wlan_cp_stats_comp_obj_cfg(enum wlan_objmgr_obj_type obj_type, 293 enum wlan_cp_stats_cfg_state cfg_state, 294 enum wlan_umac_comp_id comp_id, 295 void *cmn_obj, void *data) 296 { 297 QDF_STATUS status = QDF_STATUS_E_FAILURE; 298 struct cp_stats_context *csc; 299 struct wlan_objmgr_psoc *psoc; 300 struct wlan_objmgr_pdev *pdev; 301 struct wlan_objmgr_vdev *vdev; 302 struct wlan_objmgr_peer *peer; 303 enum wlan_cp_stats_comp_id cp_stats_comp_id; 304 305 if (!cmn_obj) { 306 cp_stats_err("common object is null!"); 307 return QDF_STATUS_E_INVAL; 308 } 309 310 cp_stats_comp_id = wlan_cp_stats_get_comp_id(comp_id); 311 if (cp_stats_comp_id >= WLAN_CP_STATS_MAX_COMPONENTS) { 312 cp_stats_err("Invalid UMAC id provided to cp_stats"); 313 return QDF_STATUS_E_INVAL; 314 } 315 316 switch (obj_type) { 317 case WLAN_PSOC_OP: 318 psoc = (struct wlan_objmgr_psoc *)cmn_obj; 319 csc = 320 wlan_objmgr_psoc_get_comp_private_obj 321 (psoc, WLAN_UMAC_COMP_CP_STATS); 322 break; 323 case WLAN_PDEV_OP: 324 pdev = (struct wlan_objmgr_pdev *)cmn_obj; 325 csc = wlan_cp_stats_ctx_get_from_pdev(pdev); 326 break; 327 case WLAN_VDEV_OP: 328 vdev = (struct wlan_objmgr_vdev *)cmn_obj; 329 csc = wlan_cp_stats_ctx_get_from_vdev(vdev); 330 break; 331 case WLAN_PEER_OP: 332 peer = (struct wlan_objmgr_peer *)cmn_obj; 333 csc = wlan_cp_stats_ctx_get_from_peer(peer); 334 break; 335 default: 336 cp_stats_err("Invalid common object type"); 337 return QDF_STATUS_E_INVAL; 338 } 339 340 if (!csc) { 341 cp_stats_err("cp_stats_context is null!"); 342 return QDF_STATUS_E_FAILURE; 343 } 344 345 if (csc->cp_stats_comp_obj_config) 346 status = csc->cp_stats_comp_obj_config(obj_type, cfg_state, 347 cp_stats_comp_id, 348 cmn_obj, data); 349 350 return status; 351 } 352