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