xref: /wlan-dirver/qca-wifi-host-cmn/umac/dfs/core/src/dfs_process_radar_found_ind.h (revision 2f4b444fb7e689b83a4ab0e7b3b38f0bf4def8e0)
1 /*
2  * Copyright (c) 2017-2021 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 /**
20  * DOC: dfs_process_radar_found_ind.h
21  * This file provides prototypes of the routines needed for the
22  * external components to utilize the services provided by the
23  * DFS component.
24  */
25 
26 #ifndef _DFS_PROCESS_RADAR_FOUND_IND_H_
27 #define _DFS_PROCESS_RADAR_FOUND_IND_H_
28 #include "dfs_partial_offload_radar.h"
29 
30 /**
31  * dfs_false_radarfound_reset_vars () - Reset dfs radar detection related
32  * variables and queues after processing radar and disabling phyerror reception.
33  *
34  * @dfs: Pointer to wlan_dfs structure.
35  */
36 static inline void
37 dfs_flush_additional_pulses(struct wlan_dfs *dfs)
38 {
39 	dfs_false_radarfound_reset_vars(dfs);
40 }
41 
42 /* Number of channel marking offsets */
43 #define DFS_NUM_FREQ_OFFSET   3
44 
45 /* Lower channel from 20 Mhz center channel */
46 #define DFS_20MHZ_LOWER_CHANNEL(_f)    ((_f) - 20)
47 /* Upper channel from 20 Mhz center channel */
48 #define DFS_20MHZ_UPPER_CHANNEL(_f)    ((_f) + 20)
49 /* 1st lower channel from center channel of bandwidth 40/80/160Mhz */
50 #define DFS_FIRST_LOWER_CHANNEL(_f)    ((_f) - 10)
51 /* 2nd lower channel from center channel of bandwidth 40/80/160Mhz */
52 #define DFS_SECOND_LOWER_CHANNEL(_f)   ((_f) - 30)
53 /* 3rd lower channel from center channel of bandwidth 80/160Mhz */
54 #define DFS_THIRD_LOWER_CHANNEL(_f)    ((_f) - 50)
55 /* 1st upper channel from center channel of bandwidth 40/80/160Mhz */
56 #define DFS_FIRST_UPPER_CHANNEL(_f)    ((_f) + 10)
57 /* 2nd upper channel from center channel of bandwidth 40/80/160Mhz */
58 #define DFS_SECOND_UPPER_CHANNEL(_f)   ((_f) + 30)
59 /* 3rd upper channel from center channel of bandwidth 80/160Mhz */
60 #define DFS_THIRD_UPPER_CHANNEL(_f)    ((_f) + 50)
61 
62 /* 20 Mhz freq_offset lower */
63 #define DFS_20MZ_OFFSET_LOWER    (-10)
64 /* 20 Mhz freq_offset upper */
65 #define DFS_20MZ_OFFSET_UPPER     (10)
66 /* 40/80 Mhz freq_offset first lower */
67 #define DFS_OFFSET_FIRST_LOWER    (-20)
68 /* 40/80 Mhz freq_offset second lower */
69 #define DFS_OFFSET_SECOND_LOWER   (-40)
70 /* 40/80 Mhz freq_offset first upper */
71 #define DFS_OFFSET_FIRST_UPPER     (20)
72 /* 40/80 Mhz freq_offset second upper */
73 #define DFS_OFFSET_SECOND_UPPER    (40)
74 
75 /* Frequency offset to sidx */
76 #define DFS_FREQ_OFFSET_TO_SIDX(_f)  ((32 * (_f)) / 10)
77 /* Sidx to frequency offset */
78 #define DFS_SIDX_TO_FREQ_OFFSET(_s)  ((10 * (_s)) / 32)
79 /* sidx offset boundary */
80 #define DFS_BOUNDARY_SIDX  32
81 /* freq offset for chirp */
82 #define DFS_CHIRP_OFFSET  10
83 /* second segment freq offset */
84 #define DFS_160MHZ_SECOND_SEG_OFFSET  40
85 #define DFS_165MHZ_SECOND_SEG_OFFSET_LEFT 40 /* in MHz */
86 #define DFS_165MHZ_SECOND_SEG_OFFSET_RIGHT 45 /* in MHz  */
87 /*Primary segment id is 0 */
88 #define PRIMARY_SEG 0
89 /* Secondary segment id is 1 */
90 #define SECONDARY_SEG 1
91 
92 /* Frequency offset indices */
93 #define CENTER_CH 0
94 #define LEFT_CH   1
95 #define RIGHT_CH  2
96 
97 #ifdef CONFIG_CHAN_FREQ_API
98 /* Next channel frequency offsets from center channel frequency */
99 #define DFS_5GHZ_NEXT_CHAN_FREQ_OFFSET  10
100 #define DFS_5GHZ_2ND_CHAN_FREQ_OFFSET   30
101 #define DFS_5GHZ_3RD_CHAN_FREQ_OFFSET   50
102 #define DFS_5GHZ_4TH_CHAN_FREQ_OFFSET   70
103 #endif
104 /* Max number of bonding channels in 160 MHz segment */
105 #define NUM_CHANNELS_160MHZ 8
106 
107 #if defined(QCA_DFS_RCSA_SUPPORT)
108 /**
109  * dfs_send_nol_ie_and_rcsa()- Send NOL IE and RCSA action frames.
110  * @dfs: Pointer to wlan_dfs structure.
111  * @radar_found: Pointer to radar found structure.
112  * @nol_freq_list: List of 20MHz frequencies on which radar has been detected.
113  * @num_channels: number of radar affected channels.
114  * @wait_for_csa: indicates if the repeater AP should take DFS action or wait
115  * for CSA
116  *
117  * Return: void.
118  */
119 void dfs_send_nol_ie_and_rcsa(struct wlan_dfs *dfs,
120 			      struct radar_found_info *radar_found,
121 			      uint16_t *nol_freq_list,
122 			      uint8_t num_channels,
123 			      bool *wait_for_csa);
124 #else
125 static inline
126 void dfs_send_nol_ie_and_rcsa(struct wlan_dfs *dfs,
127 			      struct radar_found_info *radar_found,
128 			      uint16_t *nol_freq_list,
129 			      uint8_t num_channels,
130 			      bool *wait_for_csa)
131 {
132 }
133 #endif /* QCA_DFS_RCSA_SUPPORT */
134 
135 /**
136  * struct freqs_offsets - frequency and offset information
137  * @freq: channel frequency in mhz.
138  * @offset: offset from center frequency.
139  *
140  * Index 0 - Center channel affected by RADAR.
141  * Index 1 - Left of Center channel affected by RADAR.
142  * Index 2 - Right of Center channel affected by RADAR.
143  *
144  * This information is needed to find and mark radar infected
145  * channels in NOL and regulatory database.
146  */
147 struct freqs_offsets {
148 	uint32_t freq[DFS_NUM_FREQ_OFFSET];
149 	int32_t offset[DFS_NUM_FREQ_OFFSET];
150 };
151 
152 /**
153  * dfs_process_radar_found_indication() - Process radar found indication
154  * @dfs: Pointer to wlan_dfs structure.
155  * @radar_found: radar found info.
156  *
157  * Process radar found indication and update radar effected channel in NOL
158  * and regulatory.
159  *
160  * Return: None
161  */
162 void dfs_process_radar_found_indication(struct wlan_dfs *dfs,
163 		struct radar_found_info *radar_found);
164 
165 /**
166  * dfs_process_radar_ind() - Process radar indication event
167  * @dfs: Pointer to wlan_dfs structure.
168  * @radar_found: Pointer to radar_found_info structure.
169  *
170  * Wrapper function of dfs_process_radar_found_indication().
171  *
172  * Return: QDF_STATUS
173  */
174 QDF_STATUS dfs_process_radar_ind(struct wlan_dfs *dfs,
175 		struct radar_found_info *radar_found);
176 
177 /**
178  * dfs_process_radar_ind_on_home_chan() - Process radar indication event on
179  * home channel.
180  * @dfs: Pointer to wlan_dfs structure.
181  * @radar_found: Pointer to radar_found_info structure.
182  *
183  * Return: QDF_STATUS
184  */
185 QDF_STATUS
186 dfs_process_radar_ind_on_home_chan(struct wlan_dfs *dfs,
187 				   struct radar_found_info *radar_found);
188 
189 /**
190  * dfs_radarfound_action_generic() - The dfs action on radar detection by host
191  * for domains other than FCC.
192  * @dfs: Pointer to wlan_dfs structure.
193  * @seg_id: segment id.
194  *
195  * Return: None
196  */
197 void dfs_radarfound_action_generic(struct wlan_dfs *dfs, uint8_t seg_id);
198 
199 /**
200  * dfs_get_bonding_channels_for_freq() - Get bonding channels.
201  * @dfs:         Pointer to wlan_dfs structure.
202  * @curchan:     Pointer to dfs_channels to know width and primary channel.
203  * @segment_id:  Segment id, useful for 80+80/160 MHz operating band.
204  * @detector_id: Detector id, used to find if radar is detected on
205  *               Agile detector.
206  * @freq_list:   Pointer to save radar affected channel's frequency.
207  *
208  * Return: Number of channels.
209  */
210 #ifdef CONFIG_CHAN_FREQ_API
211 uint8_t dfs_get_bonding_channels_for_freq(struct wlan_dfs *dfs,
212 					  struct dfs_channel *curchan,
213 					  uint32_t segment_id,
214 					  uint8_t detector_id,
215 					  uint16_t *freq_list);
216 
217 /**
218  * dfs_compute_radar_found_cfreq(): Computes the centre frequency of the
219  * radar hit channel.
220  * @dfs: Pointer to wlan_dfs structure.
221  * @radar_found: Pointer to radar_found_info.
222  * @freq_center: Pointer to retrieve the value of radar found cfreq.
223  */
224 void
225 dfs_compute_radar_found_cfreq(struct wlan_dfs *dfs,
226 			      struct radar_found_info *radar_found,
227 			      uint32_t *freq_center);
228 
229 /**
230  * dfs_find_radar_affected_channels()- Find the radar affected 20MHz channels.
231  * @dfs: Pointer to wlan_dfs structure.
232  * @radar_found: Pointer to radar found structure.
233  * @freq_list: List of 20MHz frequencies on which radar has been detected.
234  * @freq_center: Frequency center of the band on which the radar was detected.
235  *
236  * Return: number of radar affected channels.
237  */
238 uint8_t
239 dfs_find_radar_affected_channels(struct wlan_dfs *dfs,
240 				 struct radar_found_info *radar_found,
241 				 uint16_t *freq_list,
242 				 uint32_t freq_center);
243 
244 /**
245  * dfs_radar_add_channel_list_to_nol_for_freq()- Add given channels to nol
246  * @dfs: Pointer to wlan_dfs structure.
247  * @freq_list: Pointer to list of frequency(has both nonDFS and DFS channels).
248  * Input frequency list.
249  * @nol_freq_list: Pointer to list of NOL frequencies. Output frequency list.
250  * @num_channels: Pointer to number of channels in the list. It is both input
251  * and output to this function.
252  * *Input: Number of subchannels in @freq_list.
253  * *Output: Number of subchannels in @nol_freq_list.
254  *
255  * Add list of channels to nol, only if the channel is dfs.
256  *
257  * Return: QDF_STATUS
258  */
259 QDF_STATUS
260 dfs_radar_add_channel_list_to_nol_for_freq(struct wlan_dfs *dfs,
261 					   uint16_t *freq_list,
262 					   uint16_t *nol_freq_list,
263 					   uint8_t *num_channels);
264 #endif
265 
266 /**
267  * dfs_reset_bangradar() - Rest bangradar parameters.
268  * @dfs: Pointer to wlan_dfs structure.
269  *
270  * Return: void.
271  */
272 void dfs_reset_bangradar(struct wlan_dfs *dfs);
273 
274 /**
275  * dfs_send_csa_to_current_chan() - Send CSA to current channel
276  * @dfs: Pointer to wlan_dfs structure.
277  *
278  * For the test mode(usenol = 0), don't do a CSA; but setup the test timer so
279  * we get a CSA _back_ to the current operating channel.
280  */
281 void dfs_send_csa_to_current_chan(struct wlan_dfs *dfs);
282 
283 /**
284  * dfs_get_bonding_channel_without_seg_info_for_freq() - Get bonding channels
285  * in chan.
286  * @chan: Pointer to dfs_channel structure.
287  * @freq_list: channel array holding list of bonded channel's frequency.
288  *
289  * Return: number of sub channels in the input channel.
290  */
291 #ifdef CONFIG_CHAN_FREQ_API
292 uint8_t
293 dfs_get_bonding_channel_without_seg_info_for_freq(struct dfs_channel *chan,
294 						  uint16_t *freq_list);
295 #endif
296 
297 /**
298  * dfs_set_nol_subchannel_marking() - Set or unset NOL subchannel marking.
299  * @dfs: Pointer to wlan_dfs structure.
300  * @nol_subchannel_marking - Configure NOL subchannel marking.
301  *
302  * Return: Status of the configuration.
303  */
304 int
305 dfs_set_nol_subchannel_marking(struct wlan_dfs *dfs,
306 			       bool nol_subchannel_marking);
307 
308 /**
309  * dfs_get_nol_subchannel_marking() - Get the value of NOL subchannel marking.
310  * @dfs: Pointer to wlan_dfs structure.
311  * @nol_subchannel_marking - Read and store the value of NOL subchannel marking
312  * config.
313  *
314  * Return: Status of the read.
315  */
316 int
317 dfs_get_nol_subchannel_marking(struct wlan_dfs *dfs,
318 			       bool *nol_subchannel_marking);
319 
320 #ifdef WLAN_DFS_FULL_OFFLOAD
321 /**
322  * dfs_inc_num_radar - Increment radar detect stats for FO.
323  *
324  * @dfs: Pointer to the wlan_dfs object.
325  *
326  * Return: void.
327  */
328 void dfs_inc_num_radar(struct wlan_dfs *dfs);
329 #else
330 static inline void dfs_inc_num_radar(struct wlan_dfs *dfs)
331 {
332 }
333 #endif
334 
335 #if defined(WLAN_DFS_TRUE_160MHZ_SUPPORT) && defined(WLAN_DFS_FULL_OFFLOAD)
336 #define DFS_80P80MHZ_SECOND_SEG_OFFSET 85
337 /**
338  * dfs_translate_radar_params() - Translate the radar parameters received in
339  *                                true 160MHz supported chipsets.
340  * @dfs: Pointer to the wlan_dfs object.
341  * @radar_found: Radar found parameters.
342  *
343  * Radar found parameters in true 160MHz detectors are represented below:
344  *
345  * Offset received with respect to the center of 160MHz ranging from -80 to +80.
346  *          __________________________________________
347  *         |                                          |
348  *         |             160 MHz Channel              |
349  *         |__________________________________________|
350  *         |        |           |           |         |
351  *         |        |           |           |         |
352  *        -80    -ve offset   center    +ve offset   +80
353  *
354  *
355  * Radar found parameters after translation by this API:
356  *
357  * Offsets with respect to pri/sec 80MHz center ranging from -40 to +40.
358  *          __________________________________________
359  *         |                    |                     |
360  *         |             160 MHz|Channel              |
361  *         |____________________|_____________________|
362  *         |         |          |           |         |
363  *         |         |          |           |         |
364  *        -40    pri center  +40/-40     sec center  +40
365  *
366  * Return: void.
367  */
368 void
369 dfs_translate_radar_params(struct wlan_dfs *dfs,
370 			   struct radar_found_info *radar_found);
371 #else
372 static inline void
373 dfs_translate_radar_params(struct wlan_dfs *dfs,
374 			   struct radar_found_info *radar_found)
375 {
376 }
377 #endif /* WLAN_DFS_TRUE_160MHZ_SUPPORT */
378 #endif /*_DFS_PROCESS_RADAR_FOUND_IND_H_ */
379