1 /*
2  * Copyright (c) 2022-2024, 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 /**
18  * DOC: Declare private API which shall be used internally only
19  * in pre_cac component. This file shall include prototypes of
20  * various notification handlers and logging functions.
21  *
22  * Note: This API should be never accessed out of pre_cac component.
23  */
24 
25 #ifndef _WLAN_PRE_CAC_MAIN_H_
26 #define _WLAN_PRE_CAC_MAIN_H_
27 
28 #include <qdf_types.h>
29 #include "wlan_objmgr_vdev_obj.h"
30 #include "wlan_pre_cac_public_struct.h"
31 
32 #define pre_cac_log(level, args...) \
33 	QDF_TRACE(QDF_MODULE_ID_WLAN_PRE_CAC, level, ## args)
34 
35 #define pre_cac_logfl(level, format, args...) \
36 	pre_cac_log(level, FL(format), ## args)
37 
38 #define pre_cac_fatal(format, args...) \
39 		      pre_cac_logfl(QDF_TRACE_LEVEL_FATAL, format, ## args)
40 #define pre_cac_err(format, args...) \
41 		    pre_cac_logfl(QDF_TRACE_LEVEL_ERROR, format, ## args)
42 #define pre_cac_warn(format, args...) \
43 		     pre_cac_logfl(QDF_TRACE_LEVEL_WARN, format, ## args)
44 #define pre_cac_info(format, args...) \
45 		     pre_cac_logfl(QDF_TRACE_LEVEL_INFO, format, ## args)
46 #define pre_cac_debug(format, args...) \
47 		      pre_cac_logfl(QDF_TRACE_LEVEL_DEBUG, format, ## args)
48 
49 #define pre_cac_nofl_err(format, args...) \
50 	pre_cac_log(QDF_TRACE_LEVEL_ERROR, format, ## args)
51 #define pre_cac_nofl_warn(format, args...) \
52 		     pre_cac_log(QDF_TRACE_LEVEL_WARN, format, ## args)
53 #define pre_cac_nofl_info(format, args...) \
54 		     pre_cac_log(QDF_TRACE_LEVEL_INFO, format, ## args)
55 #define pre_cac_nofl_debug(format, args...) \
56 		      pre_cac_log(QDF_TRACE_LEVEL_DEBUG, format, ## args)
57 
58 #define PRE_CAC_ENTER() pre_cac_debug("enter")
59 #define PRE_CAC_EXIT() pre_cac_debug("exit")
60 
61 /**
62  * struct pre_cac_vdev_priv - Private object to be stored in vdev
63  * @is_pre_cac_on: status of pre_cac
64  * @pre_cac_complete: pre cac complete status
65  * @is_pre_cac_adapter: pre cac adapter status
66  * @freq_before_pre_cac: frequency before pre cac
67  * @pre_cac_freq: pre cac frequency
68  */
69 struct pre_cac_vdev_priv {
70 	bool is_pre_cac_on;
71 	bool pre_cac_complete;
72 	bool is_pre_cac_adapter;
73 	qdf_freq_t freq_before_pre_cac;
74 	qdf_freq_t pre_cac_freq;
75 };
76 
77 /**
78  * struct pre_cac_psoc_priv - Private object to be stored in psoc
79  * @pre_cac_work: pre cac work handler
80  * @pre_cac_vdev_id: pre cac vdev id
81  */
82 struct pre_cac_psoc_priv {
83 	qdf_work_t pre_cac_work;
84 	uint8_t pre_cac_vdev_id;
85 };
86 
87 /**
88  * pre_cac_vdev_create_notification() - Handler for vdev create notify.
89  * @vdev: vdev which is going to be created by objmgr
90  * @arg: argument for notification handler.
91  *
92  * Allocate and attach vdev private object.
93  *
94  * Return: QDF_STATUS status in case of success else return error.
95  */
96 QDF_STATUS pre_cac_vdev_create_notification(struct wlan_objmgr_vdev *vdev,
97 					    void *arg);
98 
99 /**
100  * pre_cac_vdev_destroy_notification() - Handler for vdev destroy notify.
101  * @vdev: vdev which is going to be destroyed by objmgr
102  * @arg: argument for notification handler.
103  *
104  * Deallocate and detach vdev private object.
105  *
106  * Return QDF_STATUS status in case of success else return error
107  */
108 QDF_STATUS
109 pre_cac_vdev_destroy_notification(struct wlan_objmgr_vdev *vdev,
110 				  void *arg);
111 
112 /**
113  * pre_cac_psoc_create_notification() - Handler for psoc create notify.
114  * @psoc: psoc which is going to be created by objmgr
115  * @arg: argument for notification handler.
116  *
117  * Allocate and attach psoc private object.
118  *
119  * Return: QDF_STATUS
120  */
121 QDF_STATUS
122 pre_cac_psoc_create_notification(struct wlan_objmgr_psoc *psoc, void *arg);
123 
124 /**
125  * pre_cac_psoc_destroy_notification() - Handler for psoc destroy notify.
126  * @psoc: psoc which is going to be destroyed by objmgr
127  * @arg: argument for notification handler.
128  *
129  * Deallocate and detach psoc private object.
130  *
131  * Return: QDF_STATUS
132  */
133 QDF_STATUS
134 pre_cac_psoc_destroy_notification(struct wlan_objmgr_psoc *psoc, void *arg);
135 
136 /**
137  * pre_cac_vdev_get_priv_fl() - retrieve vdev priv obj
138  * @vdev: vdev pointer
139  * @func: invoking function (for debugging)
140  * @line: invoking source file line number (for debugging)
141  *
142  * Retrieves pre_cac vdev private object pointer.
143  *
144  * Return: Private object of vdev
145  */
146 struct pre_cac_vdev_priv *
147 pre_cac_vdev_get_priv_fl(struct wlan_objmgr_vdev *vdev,
148 			 const char *func, uint32_t line);
149 
150 /**
151  * pre_cac_vdev_get_priv() - Wrapper to retrieve vdev priv obj
152  * @vdev: vdev pointer
153  *
154  * Wrapper for pre_cac to get vdev private object pointer.
155  *
156  * Return: Private object of vdev
157  */
158 #define pre_cac_vdev_get_priv(vdev) \
159 			      pre_cac_vdev_get_priv_fl(vdev, __func__, __LINE__)
160 
161 /**
162  * pre_cac_psoc_get_priv_fl() - retrieve psoc priv obj
163  * @psoc: psoc pointer
164  * @func: invoking function (for debugging)
165  * @line: invoking source file line number (for debugging)
166  *
167  * Retrieves pre_cac psoc private object pointer.
168  *
169  * Return: pre_cac psoc private object
170  */
171 struct pre_cac_psoc_priv *
172 pre_cac_psoc_get_priv_fl(struct wlan_objmgr_psoc *psoc,
173 			 const char *func, uint32_t line);
174 
175 /**
176  * pre_cac_psoc_get_priv() - Wrapper to retrieve psoc priv obj
177  * @psoc: psoc pointer
178  *
179  * Wrapper for pre_cac to get psoc private object pointer.
180  *
181  * Return: pre_cac psoc private object
182  */
183 #define pre_cac_psoc_get_priv(psoc) \
184 			      pre_cac_psoc_get_priv_fl(psoc, __func__, __LINE__)
185 
186 /**
187  * pre_cac_init() - pre cac component initialization.
188  *
189  * This function initializes the pre cac component and registers
190  * the handlers which are invoked on vdev creation.
191  *
192  * Return: For successful registration - QDF_STATUS_SUCCESS,
193  *         else QDF_STATUS error codes.
194  */
195 QDF_STATUS pre_cac_init(void);
196 
197 /**
198  * pre_cac_deinit() - pre cac component deinit.
199  *
200  * This function deinits pre cac component.
201  *
202  * Return: None
203  */
204 void pre_cac_deinit(void);
205 
206 /**
207  * pre_cac_set_osif_cb() - set pre cac osif callbacks
208  * @osif_pre_cac_ops: pre cac ops
209  *
210  *
211  * Return: None
212  */
213 void pre_cac_set_osif_cb(struct pre_cac_ops *osif_pre_cac_ops);
214 
215 /**
216  * pre_cac_is_active() - status of pre_cac
217  * @psoc: psoc pointer
218  *
219  * Return: status of pre_cac
220  */
221 bool pre_cac_is_active(struct wlan_objmgr_psoc *psoc);
222 
223 /**
224  * pre_cac_clear_work() - clear pre cac work fn and arg
225  * @psoc: psoc object manager
226  *
227  * Return: None
228  */
229 void pre_cac_clear_work(struct wlan_objmgr_psoc *psoc);
230 
231 /**
232  * pre_cac_validate_and_get_freq() - Validate and get pre cac frequency
233  * @pdev: pdev object manager
234  * @chan_freq: Channel frequency requested by userspace
235  * @pre_cac_chan_freq: Pointer to the pre CAC channel frequency storage
236  * @cac_ch_width: bandwidth of channel frequency pre_cac_chan_freq
237  *
238  * Validates the channel provided by userspace. If user provided channel 0,
239  * a valid outdoor channel must be selected from the regulatory channel.
240  *
241  * Return: Zero on success and non zero value on error
242  */
243 int pre_cac_validate_and_get_freq(struct wlan_objmgr_pdev *pdev,
244 				  uint32_t chan_freq,
245 				  uint32_t *pre_cac_chan_freq,
246 				  enum phy_ch_width cac_ch_width);
247 
248 /**
249  * pre_cac_set_status() - Set pre cac status
250  * @vdev: vdev object manager
251  * @status: status of pre_cac
252  *
253  * Sets pre_cac status
254  *
255  * Return: QDF_STATUS
256  */
257 QDF_STATUS pre_cac_set_status(struct wlan_objmgr_vdev *vdev, bool status);
258 
259 /**
260  * pre_cac_get_vdev_id() - Get pre cac vdev id
261  * @psoc: psoc object manager
262  * @vdev_id: pointer to the pre cac vdev id
263  *
264  * Return: None
265  */
266 void pre_cac_get_vdev_id(struct wlan_objmgr_psoc *psoc,
267 			 uint8_t *vdev_id);
268 
269 /**
270  * pre_cac_handle_cac_end() - Handle pre cac end
271  * @vdev: vdev object manager
272  *
273  * Return: None
274  */
275 void pre_cac_handle_cac_end(struct wlan_objmgr_vdev *vdev);
276 
277 /**
278  * pre_cac_complete_set() - Set pre cac complete status
279  * @vdev: vdev object manager
280  * @status: status
281  *
282  * Return: None
283  */
284 void pre_cac_complete_set(struct wlan_objmgr_vdev *vdev,
285 			  bool status);
286 
287 /**
288  * pre_cac_complete_get() - Get pre cac complete status
289  * @vdev: vdev object manager
290  *
291  * Return: pre cac complete status
292  */
293 bool pre_cac_complete_get(struct wlan_objmgr_vdev *vdev);
294 
295 /**
296  * pre_cac_adapter_set() - Set pre cac adapter flag
297  * @vdev: vdev object manager
298  * @status: status
299  *
300  * Return: None
301  */
302 void pre_cac_adapter_set(struct wlan_objmgr_vdev *vdev,
303 			 bool status);
304 
305 /**
306  * pre_cac_adapter_is_active() - Get pre cac adapter status
307  * @vdev: vdev object manager
308  *
309  * Return: pre cac adapter status
310  */
311 bool pre_cac_adapter_is_active(struct wlan_objmgr_vdev *vdev);
312 
313 /**
314  * pre_cac_set_freq_before_pre_cac() - Set frequency before pre cac
315  * @vdev: vdev object manager
316  * @freq: frequency before pre cac
317  *
318  * Return: None
319  */
320 void pre_cac_set_freq_before_pre_cac(struct wlan_objmgr_vdev *vdev,
321 				     qdf_freq_t freq);
322 
323 /**
324  * pre_cac_get_freq_before_pre_cac() - Get frequency before pre cac
325  * @vdev: vdev object manager
326  *
327  * Return: frequency before pre cac
328  */
329 qdf_freq_t pre_cac_get_freq_before_pre_cac(struct wlan_objmgr_vdev *vdev);
330 
331 /**
332  * pre_cac_set_freq() - Set pre cac frequency
333  * @vdev: vdev object manager
334  * @freq: pre cac frequency
335  *
336  * Return: None
337  */
338 void pre_cac_set_freq(struct wlan_objmgr_vdev *vdev,
339 		      qdf_freq_t freq);
340 
341 /**
342  * pre_cac_get_freq() - Get pre cac frequency
343  * @vdev: vdev object manager
344  *
345  * Return: pre cac frequency
346  */
347 qdf_freq_t pre_cac_get_freq(struct wlan_objmgr_vdev *vdev);
348 
349 /**
350  * pre_cac_handle_radar_ind() - Handle pre cac radar indication
351  * @vdev: vdev object manager
352  *
353  * Return: None
354  */
355 void pre_cac_handle_radar_ind(struct wlan_objmgr_vdev *vdev);
356 
357 /**
358  * pre_cac_stop() - Stop pre cac
359  * @psoc: psoc object manager
360  *
361  * Return: None
362  */
363 void pre_cac_stop(struct wlan_objmgr_psoc *psoc);
364 
365 /**
366  * pre_cac_clean_up() - Cleanup pre cac
367  * @psoc: psoc object manager
368  *
369  * Return: None
370  */
371 void pre_cac_clean_up(struct wlan_objmgr_psoc *psoc);
372 #endif /* end of _WLAN_PRE_CAC_MAIN_H_ */
373