1 /* 2 * Copyright (c) 2017-2019 The Linux Foundation. All rights reserved. 3 * Copyright (c) 2021-2022 Qualcomm Innovation Center, Inc. All rights reserved. 4 * 5 * Permission to use, copy, modify, and/or distribute this software for 6 * any purpose with or without fee is hereby granted, provided that the 7 * above copyright notice and this permission notice appear in all 8 * copies. 9 * 10 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL 11 * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED 12 * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE 13 * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL 14 * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR 15 * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER 16 * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR 17 * PERFORMANCE OF THIS SOFTWARE. 18 */ 19 /** 20 * DOC: wifi_pos_utils.c 21 * This file defines the utility helper functions for wifi_pos component. 22 */ 23 24 #include "qdf_types.h" 25 #include "wlan_objmgr_cmn.h" 26 #include "wlan_objmgr_global_obj.h" 27 #include "wlan_objmgr_psoc_obj.h" 28 #include <wlan_lmac_if_def.h> 29 #include "wifi_pos_utils_i.h" 30 31 /* lock to protect use of psoc global pointer variable */ 32 static qdf_spinlock_t psoc_ptr_lock; 33 34 /* 35 * WIFI pos command are not associated with any pdev/psoc/vdev, so the callback 36 * registered with GENL socket does not receive any pdev/pdev/vdev object. 37 * Since PSOC is top most object, it was decided to keep WIFI POS private obj 38 * within PSOC and hence, this module need to hang on to the first PSOC that 39 * was created for all its internal usage. 40 */ 41 static struct wlan_objmgr_psoc *wifi_pos_psoc_obj; 42 43 void wifi_pos_lock_init(void) 44 { 45 qdf_spinlock_create(&psoc_ptr_lock); 46 } 47 48 void wifi_pos_lock_deinit(void) 49 { 50 qdf_spinlock_destroy(&psoc_ptr_lock); 51 } 52 53 struct wlan_objmgr_psoc *wifi_pos_get_psoc(void) 54 { 55 struct wlan_objmgr_psoc *tmp; 56 57 qdf_spin_lock_bh(&psoc_ptr_lock); 58 tmp = wifi_pos_psoc_obj; 59 qdf_spin_unlock_bh(&psoc_ptr_lock); 60 61 return tmp; 62 } 63 64 qdf_export_symbol(wifi_pos_get_psoc); 65 66 void wifi_pos_set_psoc(struct wlan_objmgr_psoc *psoc) 67 { 68 struct wlan_objmgr_psoc *tmp; 69 70 qdf_spin_lock_bh(&psoc_ptr_lock); 71 tmp = wifi_pos_psoc_obj; 72 if (!wifi_pos_psoc_obj) 73 wifi_pos_psoc_obj = psoc; 74 qdf_spin_unlock_bh(&psoc_ptr_lock); 75 76 if (tmp) 77 wifi_pos_warn("global psoc obj already set"); 78 } 79 80 void wifi_pos_clear_psoc(void) 81 { 82 struct wlan_objmgr_psoc *tmp; 83 84 qdf_spin_lock_bh(&psoc_ptr_lock); 85 tmp = wifi_pos_psoc_obj; 86 if (wifi_pos_psoc_obj) 87 wifi_pos_psoc_obj = NULL; 88 qdf_spin_unlock_bh(&psoc_ptr_lock); 89 90 if (!tmp) 91 wifi_pos_warn("global psoc obj already cleared"); 92 } 93 94 /** 95 * wifi_pos_get_psoc_priv_obj: returns wifi_pos priv object within psoc 96 * @psoc: pointer to psoc object 97 * 98 * Return: wifi_pos_psoc_priv_obj 99 */ 100 struct wifi_pos_psoc_priv_obj *wifi_pos_get_psoc_priv_obj( 101 struct wlan_objmgr_psoc *psoc) 102 { 103 struct wifi_pos_psoc_priv_obj *obj; 104 105 obj = wlan_objmgr_psoc_get_comp_private_obj(psoc, 106 WLAN_UMAC_COMP_WIFI_POS); 107 108 return obj; 109 } 110 111 qdf_export_symbol(wifi_pos_get_psoc_priv_obj); 112 113 struct wifi_pos_vdev_priv_obj * 114 wifi_pos_get_vdev_priv_obj(struct wlan_objmgr_vdev *vdev) 115 { 116 struct wifi_pos_vdev_priv_obj *vdev_obj; 117 118 vdev_obj = wlan_objmgr_vdev_get_comp_private_obj( 119 vdev, WLAN_UMAC_COMP_WIFI_POS); 120 121 return vdev_obj; 122 } 123 124 qdf_export_symbol(wifi_pos_get_vdev_priv_obj); 125