1 /*
2 * Copyright (c) 2021, Qualcomm Innovation Center, Inc. All rights reserved.
3
4 * Permission to use, copy, modify, and/or distribute this software for any
5 * purpose with or without fee is hereby granted, provided that the above
6 * copyright notice and this permission notice appear in all copies.
7
8 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15 */
16
17 #include <wlan_wifi_radar_utils_api.h>
18 #include <wlan_wifi_radar_tgt_api.h>
19 #include <qdf_module.h>
20 #include <wifi_radar_defs_i.h>
21 #include <wlan_objmgr_global_obj.h>
22 #include <wlan_objmgr_pdev_obj.h>
23
wlan_wifi_radar_init(void)24 QDF_STATUS wlan_wifi_radar_init(void)
25 {
26 if (wlan_objmgr_register_psoc_create_handler(
27 WLAN_UMAC_COMP_WIFI_RADAR,
28 wlan_wifi_radar_psoc_obj_create_handler, NULL)
29 != QDF_STATUS_SUCCESS) {
30 return QDF_STATUS_E_FAILURE;
31 }
32 if (wlan_objmgr_register_psoc_destroy_handler(
33 WLAN_UMAC_COMP_WIFI_RADAR,
34 wlan_wifi_radar_psoc_obj_destroy_handler, NULL)
35 != QDF_STATUS_SUCCESS) {
36 return QDF_STATUS_E_FAILURE;
37 }
38 if (wlan_objmgr_register_pdev_create_handler(
39 WLAN_UMAC_COMP_WIFI_RADAR,
40 wlan_wifi_radar_pdev_obj_create_handler, NULL)
41 != QDF_STATUS_SUCCESS) {
42 return QDF_STATUS_E_FAILURE;
43 }
44 if (wlan_objmgr_register_pdev_destroy_handler(
45 WLAN_UMAC_COMP_WIFI_RADAR,
46 wlan_wifi_radar_pdev_obj_destroy_handler, NULL)
47 != QDF_STATUS_SUCCESS) {
48 return QDF_STATUS_E_FAILURE;
49 }
50 return QDF_STATUS_SUCCESS;
51 }
52
wlan_wifi_radar_deinit(void)53 QDF_STATUS wlan_wifi_radar_deinit(void)
54 {
55 QDF_STATUS ret_status = QDF_STATUS_SUCCESS;
56
57 if (wlan_objmgr_unregister_psoc_create_handler(
58 WLAN_UMAC_COMP_WIFI_RADAR,
59 wlan_wifi_radar_psoc_obj_create_handler, NULL)
60 != QDF_STATUS_SUCCESS) {
61 wifi_radar_err("failed to unregister psoc create handler");
62 ret_status = QDF_STATUS_E_FAILURE;
63 }
64 if (wlan_objmgr_unregister_psoc_destroy_handler(
65 WLAN_UMAC_COMP_WIFI_RADAR,
66 wlan_wifi_radar_psoc_obj_destroy_handler, NULL)
67 != QDF_STATUS_SUCCESS) {
68 wifi_radar_err("failed to unregister psoc destroy handler");
69 ret_status = QDF_STATUS_E_FAILURE;
70 }
71 if (wlan_objmgr_unregister_pdev_create_handler(
72 WLAN_UMAC_COMP_WIFI_RADAR,
73 wlan_wifi_radar_pdev_obj_create_handler, NULL)
74 != QDF_STATUS_SUCCESS) {
75 wifi_radar_err("failed to unregister pdev create handler");
76 ret_status = QDF_STATUS_E_FAILURE;
77 }
78 if (wlan_objmgr_unregister_pdev_destroy_handler(
79 WLAN_UMAC_COMP_WIFI_RADAR,
80 wlan_wifi_radar_pdev_obj_destroy_handler, NULL)
81 != QDF_STATUS_SUCCESS) {
82 wifi_radar_err("failed to unregister pdev destroy handler");
83 ret_status = QDF_STATUS_E_FAILURE;
84 }
85 return ret_status;
86 }
87
wlan_wifi_radar_pdev_open(struct wlan_objmgr_pdev * pdev)88 QDF_STATUS wlan_wifi_radar_pdev_open(struct wlan_objmgr_pdev *pdev)
89 {
90 QDF_STATUS status;
91
92 if (wlan_wifi_radar_is_feature_disabled(pdev)) {
93 wifi_radar_err("WiFi Radar is disabled");
94 return QDF_STATUS_COMP_DISABLED;
95 }
96
97 /* RealyFS init */
98 status = wifi_radar_streamfs_init(pdev);
99 if (status != QDF_STATUS_SUCCESS) {
100 wifi_radar_err(
101 "wifi_radar_streamfs_init failed with %d",
102 status);
103 return QDF_STATUS_SUCCESS;
104 }
105
106 return QDF_STATUS_SUCCESS;
107 }
108
wlan_wifi_radar_pdev_close(struct wlan_objmgr_pdev * pdev)109 QDF_STATUS wlan_wifi_radar_pdev_close(struct wlan_objmgr_pdev *pdev)
110 {
111 QDF_STATUS status = QDF_STATUS_SUCCESS;
112
113 if (wlan_wifi_radar_is_feature_disabled(pdev)) {
114 wifi_radar_err("WiFi Radar is disabled");
115 return QDF_STATUS_COMP_DISABLED;
116 }
117
118 status = wifi_radar_streamfs_remove(pdev);
119
120 return status;
121 }
122
wifi_radar_initialize_pdev(struct wlan_objmgr_pdev * pdev)123 QDF_STATUS wifi_radar_initialize_pdev(struct wlan_objmgr_pdev *pdev)
124 {
125 QDF_STATUS status = QDF_STATUS_SUCCESS;
126
127 if (wlan_wifi_radar_is_feature_disabled(pdev)) {
128 wifi_radar_err("WiFi Radar is disabled");
129 return QDF_STATUS_COMP_DISABLED;
130 }
131
132 return status;
133 }
134
135 qdf_export_symbol(wifi_radar_initialize_pdev);
136
wifi_radar_deinitialize_pdev(struct wlan_objmgr_pdev * pdev)137 QDF_STATUS wifi_radar_deinitialize_pdev(struct wlan_objmgr_pdev *pdev)
138 {
139 QDF_STATUS status = QDF_STATUS_SUCCESS;
140
141 if (wlan_wifi_radar_is_feature_disabled(pdev)) {
142 wifi_radar_err("WiFi Radar is disabled");
143 return QDF_STATUS_COMP_DISABLED;
144 }
145
146 return status;
147 }
148
149 qdf_export_symbol(wifi_radar_deinitialize_pdev);
150
wlan_wifi_radar_is_feature_disabled(struct wlan_objmgr_pdev * pdev)151 bool wlan_wifi_radar_is_feature_disabled(struct wlan_objmgr_pdev *pdev)
152 {
153 if (!pdev) {
154 wifi_radar_err("PDEV is NULL!");
155 return true;
156 }
157
158 return (wlan_pdev_nif_feat_ext_cap_get(
159 pdev, WLAN_PDEV_FEXT_WIFI_RADAR_ENABLE) ? false : true);
160 }
161