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