xref: /wlan-dirver/qca-wifi-host-cmn/umac/dfs/core/src/dfs_process_radar_found_ind.h (revision b62151f8dd0743da724a4533988c78d2c7385d4f)
1 /*
2  * Copyright (c) 2017-2021 The Linux Foundation. All rights reserved.
3  * Copyright (c) 2021-2023 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_flush_additional_pulses() - 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
208 
209 /**
210  * dfs_handle_radar_puncturing() - Check if the puncture bitmap is valid
211  *                                 and initialize puncture SM for the
212  *                                 punctured channels.
213  * @dfs:                      Pointer to wlan_dfs structure.
214  * @dfs_radar_bitmap:         Puncture bitmap.
215  * @freq_list:                Channel list affected by radar.
216  * @num_channels:             Number of channels affected by radar.
217  * @is_ignore_radar_puncture: Bool to check if radar should be ignored.
218  *
219  * Return: Nothing.
220  */
221 #if defined(QCA_DFS_BW_PUNCTURE) && !defined(CONFIG_REG_CLIENT)
222 void
223 dfs_handle_radar_puncturing(struct wlan_dfs *dfs,
224 			    uint16_t *dfs_radar_bitmap,
225 			    uint16_t *freq_list,
226 			    uint8_t num_channels,
227 			    bool *is_ignore_radar_puncture);
228 #else
229 static inline
230 void dfs_handle_radar_puncturing(struct wlan_dfs *dfs,
231 				 uint16_t *dfs_radar_bitmap,
232 				 uint16_t *freq_list,
233 				 uint8_t num_channels,
234 				 bool *is_ignore_radar_puncture)
235 {
236 }
237 #endif /* QCA_DFS_BW_PUNCTURE */
238 
239 /**
240  * dfs_process_radar_ind() - Process radar indication event
241  * @dfs: Pointer to wlan_dfs structure.
242  * @radar_found: Pointer to radar_found_info structure.
243  *
244  * Wrapper function of dfs_process_radar_found_indication().
245  *
246  * Return: QDF_STATUS
247  */
248 QDF_STATUS dfs_process_radar_ind(struct wlan_dfs *dfs,
249 		struct radar_found_info *radar_found);
250 
251 /**
252  * dfs_process_radar_ind_on_home_chan() - Process radar indication event on
253  * home channel.
254  * @dfs: Pointer to wlan_dfs structure.
255  * @radar_found: Pointer to radar_found_info structure.
256  *
257  * Return: QDF_STATUS
258  */
259 QDF_STATUS
260 dfs_process_radar_ind_on_home_chan(struct wlan_dfs *dfs,
261 				   struct radar_found_info *radar_found);
262 
263 /**
264  * dfs_radarfound_action_generic() - The dfs action on radar detection by host
265  * for domains other than FCC.
266  * @dfs: Pointer to wlan_dfs structure.
267  * @seg_id: segment id.
268  *
269  * Return: None
270  */
271 void dfs_radarfound_action_generic(struct wlan_dfs *dfs, uint8_t seg_id);
272 
273 /**
274  * dfs_get_bonding_channels_for_freq() - Get bonding channels.
275  * @dfs:         Pointer to wlan_dfs structure.
276  * @curchan:     Pointer to dfs_channels to know width and primary channel.
277  * @segment_id:  Segment id, useful for 80+80/160 MHz operating band.
278  * @detector_id: Detector id, used to find if radar is detected on
279  *               Agile detector.
280  * @freq_list:   Pointer to save radar affected channel's frequency.
281  *
282  * Return: Number of channels.
283  */
284 #ifdef CONFIG_CHAN_FREQ_API
285 uint8_t dfs_get_bonding_channels_for_freq(struct wlan_dfs *dfs,
286 					  struct dfs_channel *curchan,
287 					  uint32_t segment_id,
288 					  uint8_t detector_id,
289 					  uint16_t *freq_list);
290 
291 /**
292  * dfs_compute_radar_found_cfreq(): Computes the centre frequency of the
293  * radar hit channel.
294  * @dfs: Pointer to wlan_dfs structure.
295  * @radar_found: Pointer to radar_found_info.
296  * @freq_center: Pointer to retrieve the value of radar found cfreq.
297  */
298 void
299 dfs_compute_radar_found_cfreq(struct wlan_dfs *dfs,
300 			      struct radar_found_info *radar_found,
301 			      uint32_t *freq_center);
302 
303 /**
304  * dfs_find_radar_affected_channels()- Find the radar affected 20MHz channels.
305  * @dfs: Pointer to wlan_dfs structure.
306  * @radar_found: Pointer to radar found structure.
307  * @freq_list: List of 20MHz frequencies on which radar has been detected.
308  * @freq_center: Frequency center of the band on which the radar was detected.
309  *
310  * Return: number of radar affected channels.
311  */
312 uint8_t
313 dfs_find_radar_affected_channels(struct wlan_dfs *dfs,
314 				 struct radar_found_info *radar_found,
315 				 uint16_t *freq_list,
316 				 uint32_t freq_center);
317 
318 /**
319  * dfs_radar_add_channel_list_to_nol_for_freq()- Add given channels to nol
320  * @dfs: Pointer to wlan_dfs structure.
321  * @freq_list: Pointer to list of frequency(has both nonDFS and DFS channels).
322  * Input frequency list.
323  * @nol_freq_list: Pointer to list of NOL frequencies. Output frequency list.
324  * @num_channels: Pointer to number of channels in the list. It is both input
325  * and output to this function.
326  * *Input: Number of subchannels in @freq_list.
327  * *Output: Number of subchannels in @nol_freq_list.
328  *
329  * Add list of channels to nol, only if the channel is dfs.
330  *
331  * Return: QDF_STATUS
332  */
333 QDF_STATUS
334 dfs_radar_add_channel_list_to_nol_for_freq(struct wlan_dfs *dfs,
335 					   uint16_t *freq_list,
336 					   uint16_t *nol_freq_list,
337 					   uint8_t *num_channels);
338 #endif
339 
340 /**
341  * dfs_reset_bangradar() - Rest bangradar parameters.
342  * @dfs: Pointer to wlan_dfs structure.
343  *
344  * Return: void.
345  */
346 void dfs_reset_bangradar(struct wlan_dfs *dfs);
347 
348 /**
349  * dfs_send_csa_to_current_chan() - Send CSA to current channel
350  * @dfs: Pointer to wlan_dfs structure.
351  *
352  * For the test mode(usenol = 0), don't do a CSA; but setup the test timer so
353  * we get a CSA _back_ to the current operating channel.
354  */
355 void dfs_send_csa_to_current_chan(struct wlan_dfs *dfs);
356 
357 /**
358  * dfs_get_bonding_channel_without_seg_info_for_freq() - Get bonding channels
359  * in chan.
360  * @chan: Pointer to dfs_channel structure.
361  * @freq_list: channel array holding list of bonded channel's frequency.
362  *
363  * Return: number of sub channels in the input channel.
364  */
365 #ifdef CONFIG_CHAN_FREQ_API
366 uint8_t
367 dfs_get_bonding_channel_without_seg_info_for_freq(struct dfs_channel *chan,
368 						  uint16_t *freq_list);
369 #endif
370 
371 /**
372  * dfs_set_nol_subchannel_marking() - Set or unset NOL subchannel marking.
373  * @dfs: Pointer to wlan_dfs structure.
374  * @nol_subchannel_marking: Configure NOL subchannel marking.
375  *
376  * Return: Status of the configuration.
377  */
378 int
379 dfs_set_nol_subchannel_marking(struct wlan_dfs *dfs,
380 			       bool nol_subchannel_marking);
381 
382 /**
383  * dfs_get_nol_subchannel_marking() - Get the value of NOL subchannel marking.
384  * @dfs: Pointer to wlan_dfs structure.
385  * @nol_subchannel_marking: Read and store the value of NOL subchannel marking
386  * config.
387  *
388  * Return: Status of the read.
389  */
390 int
391 dfs_get_nol_subchannel_marking(struct wlan_dfs *dfs,
392 			       bool *nol_subchannel_marking);
393 
394 #ifdef WLAN_DFS_FULL_OFFLOAD
395 /**
396  * dfs_inc_num_radar - Increment radar detect stats for FO.
397  *
398  * @dfs: Pointer to the wlan_dfs object.
399  *
400  * Return: void.
401  */
402 void dfs_inc_num_radar(struct wlan_dfs *dfs);
403 #else
404 static inline void dfs_inc_num_radar(struct wlan_dfs *dfs)
405 {
406 }
407 #endif
408 
409 #if defined(WLAN_DFS_TRUE_160MHZ_SUPPORT) && defined(WLAN_DFS_FULL_OFFLOAD)
410 #define DFS_80P80MHZ_SECOND_SEG_OFFSET 85
411 /**
412  * dfs_translate_radar_params() - Translate the radar parameters received in
413  *                                true 160MHz supported chipsets.
414  * @dfs: Pointer to the wlan_dfs object.
415  * @radar_found: Radar found parameters.
416  *
417  * Radar found parameters in true 160MHz detectors are represented below:
418  *
419  * Offset received with respect to the center of 160MHz ranging from -80 to +80.
420  *          __________________________________________
421  *         |                                          |
422  *         |             160 MHz Channel              |
423  *         |__________________________________________|
424  *         |        |           |           |         |
425  *         |        |           |           |         |
426  *        -80    -ve offset   center    +ve offset   +80
427  *
428  *
429  * Radar found parameters after translation by this API:
430  *
431  * Offsets with respect to pri/sec 80MHz center ranging from -40 to +40.
432  *          __________________________________________
433  *         |                    |                     |
434  *         |             160 MHz|Channel              |
435  *         |____________________|_____________________|
436  *         |         |          |           |         |
437  *         |         |          |           |         |
438  *        -40    pri center  +40/-40     sec center  +40
439  *
440  * Return: void.
441  */
442 void
443 dfs_translate_radar_params(struct wlan_dfs *dfs,
444 			   struct radar_found_info *radar_found);
445 #else
446 static inline void
447 dfs_translate_radar_params(struct wlan_dfs *dfs,
448 			   struct radar_found_info *radar_found)
449 {
450 }
451 #endif /* WLAN_DFS_TRUE_160MHZ_SUPPORT */
452 #endif /*_DFS_PROCESS_RADAR_FOUND_IND_H_ */
453