1*5113495bSYour Name /*
2*5113495bSYour Name * Copyright (c) 2019-2020 The Linux Foundation. All rights reserved.
3*5113495bSYour Name *
4*5113495bSYour Name * Permission to use, copy, modify, and/or distribute this software for
5*5113495bSYour Name * any purpose with or without fee is hereby granted, provided that the
6*5113495bSYour Name * above copyright notice and this permission notice appear in all
7*5113495bSYour Name * copies.
8*5113495bSYour Name *
9*5113495bSYour Name * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
10*5113495bSYour Name * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
11*5113495bSYour Name * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
12*5113495bSYour Name * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
13*5113495bSYour Name * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
14*5113495bSYour Name * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
15*5113495bSYour Name * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
16*5113495bSYour Name * PERFORMANCE OF THIS SOFTWARE.
17*5113495bSYour Name */
18*5113495bSYour Name
19*5113495bSYour Name #include <wlan_cfr_utils_api.h>
20*5113495bSYour Name #include <wlan_cfr_tgt_api.h>
21*5113495bSYour Name #include <qdf_module.h>
22*5113495bSYour Name #include <cfr_defs_i.h>
23*5113495bSYour Name #include <wlan_objmgr_global_obj.h>
24*5113495bSYour Name #include <wlan_objmgr_pdev_obj.h>
25*5113495bSYour Name
wlan_cfr_init(void)26*5113495bSYour Name QDF_STATUS wlan_cfr_init(void)
27*5113495bSYour Name {
28*5113495bSYour Name if (wlan_objmgr_register_psoc_create_handler(WLAN_UMAC_COMP_CFR,
29*5113495bSYour Name wlan_cfr_psoc_obj_create_handler, NULL)
30*5113495bSYour Name != QDF_STATUS_SUCCESS) {
31*5113495bSYour Name return QDF_STATUS_E_FAILURE;
32*5113495bSYour Name }
33*5113495bSYour Name if (wlan_objmgr_register_psoc_destroy_handler(WLAN_UMAC_COMP_CFR,
34*5113495bSYour Name wlan_cfr_psoc_obj_destroy_handler, NULL)
35*5113495bSYour Name != QDF_STATUS_SUCCESS) {
36*5113495bSYour Name return QDF_STATUS_E_FAILURE;
37*5113495bSYour Name }
38*5113495bSYour Name if (wlan_objmgr_register_pdev_create_handler(WLAN_UMAC_COMP_CFR,
39*5113495bSYour Name wlan_cfr_pdev_obj_create_handler, NULL)
40*5113495bSYour Name != QDF_STATUS_SUCCESS) {
41*5113495bSYour Name return QDF_STATUS_E_FAILURE;
42*5113495bSYour Name }
43*5113495bSYour Name if (wlan_objmgr_register_pdev_destroy_handler(WLAN_UMAC_COMP_CFR,
44*5113495bSYour Name wlan_cfr_pdev_obj_destroy_handler, NULL)
45*5113495bSYour Name != QDF_STATUS_SUCCESS) {
46*5113495bSYour Name return QDF_STATUS_E_FAILURE;
47*5113495bSYour Name }
48*5113495bSYour Name if (wlan_objmgr_register_peer_create_handler(WLAN_UMAC_COMP_CFR,
49*5113495bSYour Name wlan_cfr_peer_obj_create_handler, NULL)
50*5113495bSYour Name != QDF_STATUS_SUCCESS) {
51*5113495bSYour Name return QDF_STATUS_E_FAILURE;
52*5113495bSYour Name }
53*5113495bSYour Name if (wlan_objmgr_register_peer_destroy_handler(WLAN_UMAC_COMP_CFR,
54*5113495bSYour Name wlan_cfr_peer_obj_destroy_handler, NULL)
55*5113495bSYour Name != QDF_STATUS_SUCCESS) {
56*5113495bSYour Name return QDF_STATUS_E_FAILURE;
57*5113495bSYour Name }
58*5113495bSYour Name
59*5113495bSYour Name return QDF_STATUS_SUCCESS;
60*5113495bSYour Name }
61*5113495bSYour Name
wlan_cfr_deinit(void)62*5113495bSYour Name QDF_STATUS wlan_cfr_deinit(void)
63*5113495bSYour Name {
64*5113495bSYour Name if (wlan_objmgr_unregister_psoc_create_handler(WLAN_UMAC_COMP_CFR,
65*5113495bSYour Name wlan_cfr_psoc_obj_create_handler, NULL)
66*5113495bSYour Name != QDF_STATUS_SUCCESS) {
67*5113495bSYour Name return QDF_STATUS_E_FAILURE;
68*5113495bSYour Name }
69*5113495bSYour Name if (wlan_objmgr_unregister_psoc_destroy_handler(WLAN_UMAC_COMP_CFR,
70*5113495bSYour Name wlan_cfr_psoc_obj_destroy_handler, NULL)
71*5113495bSYour Name != QDF_STATUS_SUCCESS) {
72*5113495bSYour Name return QDF_STATUS_E_FAILURE;
73*5113495bSYour Name }
74*5113495bSYour Name if (wlan_objmgr_unregister_pdev_create_handler(WLAN_UMAC_COMP_CFR,
75*5113495bSYour Name wlan_cfr_pdev_obj_create_handler, NULL)
76*5113495bSYour Name != QDF_STATUS_SUCCESS) {
77*5113495bSYour Name return QDF_STATUS_E_FAILURE;
78*5113495bSYour Name }
79*5113495bSYour Name if (wlan_objmgr_unregister_pdev_destroy_handler(WLAN_UMAC_COMP_CFR,
80*5113495bSYour Name wlan_cfr_pdev_obj_destroy_handler, NULL)
81*5113495bSYour Name != QDF_STATUS_SUCCESS) {
82*5113495bSYour Name return QDF_STATUS_E_FAILURE;
83*5113495bSYour Name }
84*5113495bSYour Name if (wlan_objmgr_unregister_peer_create_handler(WLAN_UMAC_COMP_CFR,
85*5113495bSYour Name wlan_cfr_peer_obj_create_handler, NULL)
86*5113495bSYour Name != QDF_STATUS_SUCCESS) {
87*5113495bSYour Name return QDF_STATUS_E_FAILURE;
88*5113495bSYour Name }
89*5113495bSYour Name if (wlan_objmgr_unregister_peer_destroy_handler(WLAN_UMAC_COMP_CFR,
90*5113495bSYour Name wlan_cfr_peer_obj_destroy_handler, NULL)
91*5113495bSYour Name != QDF_STATUS_SUCCESS) {
92*5113495bSYour Name return QDF_STATUS_E_FAILURE;
93*5113495bSYour Name }
94*5113495bSYour Name return QDF_STATUS_SUCCESS;
95*5113495bSYour Name }
96*5113495bSYour Name
wlan_cfr_pdev_open(struct wlan_objmgr_pdev * pdev)97*5113495bSYour Name QDF_STATUS wlan_cfr_pdev_open(struct wlan_objmgr_pdev *pdev)
98*5113495bSYour Name {
99*5113495bSYour Name QDF_STATUS status;
100*5113495bSYour Name
101*5113495bSYour Name if (wlan_cfr_is_feature_disabled(pdev)) {
102*5113495bSYour Name cfr_err("cfr is disabled");
103*5113495bSYour Name return QDF_STATUS_COMP_DISABLED;
104*5113495bSYour Name }
105*5113495bSYour Name /* chip specific init */
106*5113495bSYour Name status = tgt_cfr_init_pdev(pdev);
107*5113495bSYour Name
108*5113495bSYour Name if (status != QDF_STATUS_SUCCESS) {
109*5113495bSYour Name cfr_err("tgt_cfr_init_pdev failed with %d\n", status);
110*5113495bSYour Name return QDF_STATUS_SUCCESS;
111*5113495bSYour Name }
112*5113495bSYour Name
113*5113495bSYour Name /* RealyFS init */
114*5113495bSYour Name status = cfr_streamfs_init(pdev);
115*5113495bSYour Name
116*5113495bSYour Name if (status != QDF_STATUS_SUCCESS) {
117*5113495bSYour Name cfr_err("cfr_streamfs_init failed with %d\n", status);
118*5113495bSYour Name return QDF_STATUS_SUCCESS;
119*5113495bSYour Name }
120*5113495bSYour Name
121*5113495bSYour Name return QDF_STATUS_SUCCESS;
122*5113495bSYour Name }
123*5113495bSYour Name
wlan_cfr_pdev_close(struct wlan_objmgr_pdev * pdev)124*5113495bSYour Name QDF_STATUS wlan_cfr_pdev_close(struct wlan_objmgr_pdev *pdev)
125*5113495bSYour Name {
126*5113495bSYour Name QDF_STATUS status = QDF_STATUS_SUCCESS;
127*5113495bSYour Name
128*5113495bSYour Name if (wlan_cfr_is_feature_disabled(pdev)) {
129*5113495bSYour Name cfr_err("cfr is disabled");
130*5113495bSYour Name return QDF_STATUS_COMP_DISABLED;
131*5113495bSYour Name }
132*5113495bSYour Name /*
133*5113495bSYour Name * DBR does not have close as of now;
134*5113495bSYour Name * but this is getting added as part for new gerrit
135*5113495bSYour Name * Once we have that support we will add it.
136*5113495bSYour Name */
137*5113495bSYour Name status = cfr_streamfs_remove(pdev);
138*5113495bSYour Name
139*5113495bSYour Name return status;
140*5113495bSYour Name }
141*5113495bSYour Name
cfr_initialize_pdev(struct wlan_objmgr_pdev * pdev)142*5113495bSYour Name QDF_STATUS cfr_initialize_pdev(struct wlan_objmgr_pdev *pdev)
143*5113495bSYour Name {
144*5113495bSYour Name QDF_STATUS status = QDF_STATUS_SUCCESS;
145*5113495bSYour Name
146*5113495bSYour Name if (wlan_cfr_is_feature_disabled(pdev)) {
147*5113495bSYour Name cfr_err("cfr is disabled");
148*5113495bSYour Name return QDF_STATUS_COMP_DISABLED;
149*5113495bSYour Name }
150*5113495bSYour Name
151*5113495bSYour Name /* chip specific init */
152*5113495bSYour Name
153*5113495bSYour Name status = tgt_cfr_init_pdev(pdev);
154*5113495bSYour Name
155*5113495bSYour Name if (status != QDF_STATUS_SUCCESS)
156*5113495bSYour Name cfr_err("cfr_initialize_pdev status=%d\n", status);
157*5113495bSYour Name
158*5113495bSYour Name return status;
159*5113495bSYour Name }
160*5113495bSYour Name qdf_export_symbol(cfr_initialize_pdev);
161*5113495bSYour Name
cfr_deinitialize_pdev(struct wlan_objmgr_pdev * pdev)162*5113495bSYour Name QDF_STATUS cfr_deinitialize_pdev(struct wlan_objmgr_pdev *pdev)
163*5113495bSYour Name {
164*5113495bSYour Name QDF_STATUS status = QDF_STATUS_SUCCESS;
165*5113495bSYour Name
166*5113495bSYour Name if (wlan_cfr_is_feature_disabled(pdev)) {
167*5113495bSYour Name cfr_err("cfr is disabled");
168*5113495bSYour Name return QDF_STATUS_COMP_DISABLED;
169*5113495bSYour Name }
170*5113495bSYour Name
171*5113495bSYour Name /* chip specific deinit */
172*5113495bSYour Name
173*5113495bSYour Name status = tgt_cfr_deinit_pdev(pdev);
174*5113495bSYour Name
175*5113495bSYour Name if (status != QDF_STATUS_SUCCESS)
176*5113495bSYour Name cfr_err("cfr_deinitialize_pdev status=%d\n", status);
177*5113495bSYour Name
178*5113495bSYour Name return status;
179*5113495bSYour Name }
180*5113495bSYour Name qdf_export_symbol(cfr_deinitialize_pdev);
181*5113495bSYour Name
count_set_bits(unsigned long value)182*5113495bSYour Name uint8_t count_set_bits(unsigned long value)
183*5113495bSYour Name {
184*5113495bSYour Name uint8_t count = 0;
185*5113495bSYour Name
186*5113495bSYour Name while (value) {
187*5113495bSYour Name value &= (value - 1);
188*5113495bSYour Name count++;
189*5113495bSYour Name }
190*5113495bSYour Name
191*5113495bSYour Name return count;
192*5113495bSYour Name }
193*5113495bSYour Name
194*5113495bSYour Name qdf_export_symbol(count_set_bits);
195*5113495bSYour Name
196*5113495bSYour Name #ifdef WLAN_ENH_CFR_ENABLE
wlan_cfr_rx_tlv_process(struct wlan_objmgr_pdev * pdev,void * nbuf)197*5113495bSYour Name void wlan_cfr_rx_tlv_process(struct wlan_objmgr_pdev *pdev, void *nbuf)
198*5113495bSYour Name {
199*5113495bSYour Name tgt_cfr_rx_tlv_process(pdev, nbuf);
200*5113495bSYour Name }
201*5113495bSYour Name
202*5113495bSYour Name qdf_export_symbol(wlan_cfr_rx_tlv_process);
203*5113495bSYour Name #endif
204*5113495bSYour Name
wlan_cfr_is_feature_disabled(struct wlan_objmgr_pdev * pdev)205*5113495bSYour Name bool wlan_cfr_is_feature_disabled(struct wlan_objmgr_pdev *pdev)
206*5113495bSYour Name {
207*5113495bSYour Name if (!pdev) {
208*5113495bSYour Name cfr_err("PDEV is NULL!");
209*5113495bSYour Name return true;
210*5113495bSYour Name }
211*5113495bSYour Name
212*5113495bSYour Name return (wlan_pdev_nif_feat_ext_cap_get(pdev, WLAN_PDEV_FEXT_CFR_EN) ?
213*5113495bSYour Name false : true);
214*5113495bSYour Name }
215*5113495bSYour Name
216*5113495bSYour Name qdf_export_symbol(wlan_cfr_is_feature_disabled);
217