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