xref: /wlan-dirver/qca-wifi-host-cmn/umac/wifi_pos/src/wifi_pos_utils.c (revision 92d87f51612f6c3b2285266215edee8911647c2f)
1 /*
2  * Copyright (c) 2017-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  * 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 void wifi_pos_set_psoc(struct wlan_objmgr_psoc *psoc)
63 {
64 	struct wlan_objmgr_psoc *tmp;
65 
66 	qdf_spin_lock_bh(&psoc_ptr_lock);
67 	tmp = wifi_pos_psoc_obj;
68 	if (!wifi_pos_psoc_obj)
69 		wifi_pos_psoc_obj = psoc;
70 	qdf_spin_unlock_bh(&psoc_ptr_lock);
71 
72 	if (tmp)
73 		wifi_pos_warn("global psoc obj already set");
74 }
75 
76 void wifi_pos_clear_psoc(void)
77 {
78 	struct wlan_objmgr_psoc *tmp;
79 
80 	qdf_spin_lock_bh(&psoc_ptr_lock);
81 	tmp = wifi_pos_psoc_obj;
82 	if (wifi_pos_psoc_obj)
83 		wifi_pos_psoc_obj = NULL;
84 	qdf_spin_unlock_bh(&psoc_ptr_lock);
85 
86 	if (!tmp)
87 		wifi_pos_warn("global psoc obj already cleared");
88 }
89 
90 /**
91  * wifi_pos_get_psoc_priv_obj: returns wifi_pos priv object within psoc
92  * @psoc: pointer to psoc object
93  *
94  * Return: wifi_pos_psoc_priv_obj
95  */
96 struct wifi_pos_psoc_priv_obj *wifi_pos_get_psoc_priv_obj(
97 		struct wlan_objmgr_psoc *psoc)
98 {
99 	struct wifi_pos_psoc_priv_obj *obj;
100 
101 	obj = wlan_objmgr_psoc_get_comp_private_obj(psoc,
102 						    WLAN_UMAC_COMP_WIFI_POS);
103 
104 	return obj;
105 }
106