1 /* 2 * Copyright (c) 2017-2019 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 * DOC: wifi_pos_utils.c 20 * This file defines the utility helper functions for wifi_pos component. 21 */ 22 23 #include "qdf_types.h" 24 #include "wlan_objmgr_cmn.h" 25 #include "wlan_objmgr_global_obj.h" 26 #include "wlan_objmgr_psoc_obj.h" 27 #include "wifi_pos_utils_i.h" 28 29 /* lock to protect use of psoc global pointer variable */ 30 static qdf_spinlock_t psoc_ptr_lock; 31 32 /* 33 * WIFI pos command are not associated with any pdev/psoc/vdev, so the callback 34 * registered with GENL socket does not receive any pdev/pdev/vdev object. 35 * Since PSOC is top most object, it was decided to keep WIFI POS private obj 36 * within PSOC and hence, this module need to hang on to the first PSOC that 37 * was created for all its internal usage. 38 */ 39 static struct wlan_objmgr_psoc *wifi_pos_psoc_obj; 40 41 void wifi_pos_lock_init(void) 42 { 43 qdf_spinlock_create(&psoc_ptr_lock); 44 } 45 46 void wifi_pos_lock_deinit(void) 47 { 48 qdf_spinlock_destroy(&psoc_ptr_lock); 49 } 50 51 struct wlan_objmgr_psoc *wifi_pos_get_psoc(void) 52 { 53 struct wlan_objmgr_psoc *tmp; 54 55 qdf_spin_lock_bh(&psoc_ptr_lock); 56 tmp = wifi_pos_psoc_obj; 57 qdf_spin_unlock_bh(&psoc_ptr_lock); 58 59 return tmp; 60 } 61 62 qdf_export_symbol(wifi_pos_get_psoc); 63 64 void wifi_pos_set_psoc(struct wlan_objmgr_psoc *psoc) 65 { 66 struct wlan_objmgr_psoc *tmp; 67 68 qdf_spin_lock_bh(&psoc_ptr_lock); 69 tmp = wifi_pos_psoc_obj; 70 if (!wifi_pos_psoc_obj) 71 wifi_pos_psoc_obj = psoc; 72 qdf_spin_unlock_bh(&psoc_ptr_lock); 73 74 if (tmp) 75 wifi_pos_warn("global psoc obj already set"); 76 } 77 78 void wifi_pos_clear_psoc(void) 79 { 80 struct wlan_objmgr_psoc *tmp; 81 82 qdf_spin_lock_bh(&psoc_ptr_lock); 83 tmp = wifi_pos_psoc_obj; 84 if (wifi_pos_psoc_obj) 85 wifi_pos_psoc_obj = NULL; 86 qdf_spin_unlock_bh(&psoc_ptr_lock); 87 88 if (!tmp) 89 wifi_pos_warn("global psoc obj already cleared"); 90 } 91 92 /** 93 * wifi_pos_get_psoc_priv_obj: returns wifi_pos priv object within psoc 94 * @psoc: pointer to psoc object 95 * 96 * Return: wifi_pos_psoc_priv_obj 97 */ 98 struct wifi_pos_psoc_priv_obj *wifi_pos_get_psoc_priv_obj( 99 struct wlan_objmgr_psoc *psoc) 100 { 101 struct wifi_pos_psoc_priv_obj *obj; 102 103 obj = wlan_objmgr_psoc_get_comp_private_obj(psoc, 104 WLAN_UMAC_COMP_WIFI_POS); 105 106 return obj; 107 } 108 109 qdf_export_symbol(wifi_pos_get_psoc_priv_obj); 110