xref: /wlan-dirver/qca-wifi-host-cmn/umac/wifi_pos/src/wifi_pos_utils.c (revision 8cfe6b10058a04cafb17eed051f2ddf11bee8931)
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 #include "wlan_objmgr_vdev_obj.h"
31 
32 
33 /* lock to protect use of psoc global pointer variable */
34 static qdf_spinlock_t psoc_ptr_lock;
35 
36 /*
37  * WIFI pos command are not associated with any pdev/psoc/vdev, so the callback
38  * registered with GENL socket does not receive any pdev/pdev/vdev object.
39  * Since PSOC is top most object, it was decided to keep WIFI POS private obj
40  * within PSOC and hence, this module need to hang on to the first PSOC that
41  * was created for all its internal usage.
42  */
43 static struct wlan_objmgr_psoc *wifi_pos_psoc_obj;
44 
45 struct wlan_objmgr_vdev;
46 struct wifi_pos_psoc_priv_obj;
47 
48 void wifi_pos_lock_init(void)
49 {
50 	qdf_spinlock_create(&psoc_ptr_lock);
51 }
52 
53 void wifi_pos_lock_deinit(void)
54 {
55 	qdf_spinlock_destroy(&psoc_ptr_lock);
56 }
57 
58 struct wlan_objmgr_psoc *wifi_pos_get_psoc(void)
59 {
60 	struct wlan_objmgr_psoc  *tmp;
61 
62 	qdf_spin_lock_bh(&psoc_ptr_lock);
63 	tmp = wifi_pos_psoc_obj;
64 	qdf_spin_unlock_bh(&psoc_ptr_lock);
65 
66 	return tmp;
67 }
68 
69 qdf_export_symbol(wifi_pos_get_psoc);
70 
71 void wifi_pos_set_psoc(struct wlan_objmgr_psoc *psoc)
72 {
73 	struct wlan_objmgr_psoc *tmp;
74 
75 	qdf_spin_lock_bh(&psoc_ptr_lock);
76 	tmp = wifi_pos_psoc_obj;
77 	if (!wifi_pos_psoc_obj)
78 		wifi_pos_psoc_obj = psoc;
79 	qdf_spin_unlock_bh(&psoc_ptr_lock);
80 
81 	if (tmp)
82 		wifi_pos_warn("global psoc obj already set");
83 }
84 
85 void wifi_pos_clear_psoc(void)
86 {
87 	struct wlan_objmgr_psoc *tmp;
88 
89 	qdf_spin_lock_bh(&psoc_ptr_lock);
90 	tmp = wifi_pos_psoc_obj;
91 	if (wifi_pos_psoc_obj)
92 		wifi_pos_psoc_obj = NULL;
93 	qdf_spin_unlock_bh(&psoc_ptr_lock);
94 
95 	if (!tmp)
96 		wifi_pos_warn("global psoc obj already cleared");
97 }
98 
99 /**
100  * wifi_pos_get_psoc_priv_obj: returns wifi_pos priv object within psoc
101  * @psoc: pointer to psoc object
102  *
103  * Return: wifi_pos_psoc_priv_obj
104  */
105 struct wifi_pos_psoc_priv_obj *wifi_pos_get_psoc_priv_obj(
106 		struct wlan_objmgr_psoc *psoc)
107 {
108 	struct wifi_pos_psoc_priv_obj *obj;
109 
110 	obj = (struct wifi_pos_psoc_priv_obj *)wlan_objmgr_psoc_get_comp_private_obj(psoc,
111 					       WLAN_UMAC_COMP_WIFI_POS);
112 
113 	return obj;
114 }
115 
116 qdf_export_symbol(wifi_pos_get_psoc_priv_obj);
117 
118 struct wifi_pos_vdev_priv_obj *
119 wifi_pos_get_vdev_priv_obj(struct wlan_objmgr_vdev *vdev)
120 {
121 	struct wifi_pos_vdev_priv_obj *vdev_obj;
122 
123 	vdev_obj = (struct wifi_pos_vdev_priv_obj *)wlan_objmgr_vdev_get_comp_private_obj(
124 						    vdev,
125 						    WLAN_UMAC_COMP_WIFI_POS);
126 
127 	return vdev_obj;
128 }
129 
130 qdf_export_symbol(wifi_pos_get_vdev_priv_obj);
131