xref: /wlan-dirver/qca-wifi-host-cmn/umac/regulatory/dispatcher/inc/wlan_reg_services_api.h (revision 1f55ed1a9f5050d8da228aa8dd3fff7c0242aa71)
1 /*
2  * Copyright (c) 2017-2018 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: wlan_reg_services_api.h
21  * This file provides prototypes of the routines needed for the
22  * external components to utilize the services provided by the
23  * regulatory component.
24  */
25 
26 #ifndef __WLAN_REG_SERVICES_API_H
27 #define __WLAN_REG_SERVICES_API_H
28 
29 #include "../../core/src/reg_services.h"
30 #include <reg_services_public_struct.h>
31 
32 
33 #define WLAN_REG_MIN_24GHZ_CH_NUM REG_MIN_24GHZ_CH_NUM
34 #define WLAN_REG_MAX_24GHZ_CH_NUM REG_MAX_24GHZ_CH_NUM
35 #define WLAN_REG_MIN_5GHZ_CH_NUM REG_MIN_5GHZ_CH_NUM
36 #define WLAN_REG_MAX_5GHZ_CH_NUM REG_MAX_5GHZ_CH_NUM
37 
38 #define WLAN_REG_IS_24GHZ_CH(chan) REG_IS_24GHZ_CH(chan)
39 #define WLAN_REG_IS_5GHZ_CH(chan) REG_IS_5GHZ_CH(chan)
40 
41 #define WLAN_REG_IS_24GHZ_CH_FREQ(freq) REG_IS_24GHZ_CH_FREQ(freq)
42 #define WLAN_REG_IS_5GHZ_CH_FREQ(freq) REG_IS_5GHZ_FREQ(freq)
43 
44 #ifndef CONFIG_LEGACY_CHAN_ENUM
45 #define WLAN_REG_IS_49GHZ_FREQ(freq) REG_IS_49GHZ_FREQ(freq)
46 #endif
47 
48 #define WLAN_REG_CH_NUM(ch_enum) REG_CH_NUM(ch_enum)
49 #define WLAN_REG_CH_TO_FREQ(ch_enum) REG_CH_TO_FREQ(ch_enum)
50 
51 #define WLAN_REG_IS_SAME_BAND_CHANNELS(chan_num1, chan_num2) \
52 	(chan_num1 && chan_num2 &&					\
53 	(WLAN_REG_IS_5GHZ_CH(chan_num1) == WLAN_REG_IS_5GHZ_CH(chan_num2)))
54 
55 
56 #define WLAN_REG_IS_CHANNEL_VALID_5G_SBS(curchan, newchan) \
57 	(curchan > newchan ?				   \
58 	 REG_CH_TO_FREQ(reg_get_chan_enum(curchan))	   \
59 	 - REG_CH_TO_FREQ(reg_get_chan_enum(newchan))	   \
60 	 > REG_SBS_SEPARATION_THRESHOLD :		   \
61 	 REG_CH_TO_FREQ(reg_get_chan_enum(newchan))	   \
62 	 - REG_CH_TO_FREQ(reg_get_chan_enum(curchan))	   \
63 	 > REG_SBS_SEPARATION_THRESHOLD)
64 
65 #define WLAN_REG_INVALID_CHANNEL_ID
66 #define WLAN_REG_GET_24_END_CHAN_NUM 14
67 
68 #define WLAN_REG_CHAN_TO_BAND(chan_num)  reg_chan_to_band(chan_num)
69 
70 /**
71  * wlan_reg_get_channel_list_with_power() - Provide the channel list with power
72  * @ch_list: pointer to the channel list.
73  *
74  * Return: QDF_STATUS
75  */
76 QDF_STATUS wlan_reg_get_channel_list_with_power(struct wlan_objmgr_pdev *pdev,
77 						struct channel_power *ch_list,
78 						uint8_t *num_chan);
79 
80 /**
81  * wlan_reg_read_default_country() - Read the default country for the regdomain
82  * @country: pointer to the country code.
83  *
84  * Return: QDF_STATUS
85  */
86 QDF_STATUS wlan_reg_read_default_country(struct wlan_objmgr_psoc *psoc,
87 				   uint8_t *country);
88 
89 /**
90  * wlan_reg_read_current_country() - Read the current country for the regdomain
91  * @country: pointer to the country code.
92  *
93  * Return: QDF_STATUS
94  */
95 QDF_STATUS wlan_reg_read_current_country(struct wlan_objmgr_psoc *psoc,
96 				   uint8_t *country);
97 
98 /**
99  * wlan_reg_get_channel_state() - Get channel state from regulatory
100  * @ch: channel number.
101  *
102  * Return: channel state
103  */
104 enum channel_state wlan_reg_get_channel_state(struct wlan_objmgr_pdev *pdev,
105 					      uint32_t ch);
106 
107 /**
108  * wlan_reg_chan_has_dfs_attribute() - check channel has dfs attribute flag
109  * @ch: channel number.
110  *
111  * This API get chan initial dfs attribute from regdomain
112  *
113  * Return: true if chan is dfs, otherwise false
114  */
115 bool
116 wlan_reg_chan_has_dfs_attribute(struct wlan_objmgr_pdev *pdev, uint32_t ch);
117 
118 /**
119  * wlan_reg_get_5g_bonded_channel_state() - Get 5G bonded channel state
120  * @pdev: The physical dev to program country code or regdomain
121  * @ch: channel number.
122  * @bw: channel band width
123  *
124  * Return: channel state
125  */
126 enum channel_state wlan_reg_get_5g_bonded_channel_state(
127 		struct wlan_objmgr_pdev *pdev, uint8_t ch,
128 		enum phy_ch_width bw);
129 
130 /**
131  * wlan_reg_get_2g_bonded_channel_state() - Get 2G bonded channel state
132  * @pdev: The physical dev to program country code or regdomain
133  * @ch: channel number.
134  * @sec_ch: Secondary channel.
135  * @bw: channel band width
136  *
137  * Return: channel state
138  */
139 enum channel_state wlan_reg_get_2g_bonded_channel_state(
140 		struct wlan_objmgr_pdev *pdev, uint8_t ch,
141 		uint8_t sec_ch, enum phy_ch_width bw);
142 
143 /**
144  * wlan_reg_set_channel_params () - Sets channel parameteres for given bandwidth
145  * @pdev: The physical dev to program country code or regdomain
146  * @ch: channel number.
147  * @sec_ch_2g: Secondary channel.
148  * @ch_params: pointer to the channel parameters.
149  *
150  * Return: None
151  */
152 void wlan_reg_set_channel_params(struct wlan_objmgr_pdev *pdev, uint8_t ch,
153 				 uint8_t sec_ch_2g,
154 				 struct ch_params *ch_params);
155 
156 /**
157  * wlan_reg_get_dfs_region () - Get the current dfs region
158  * @dfs_reg: pointer to dfs region
159  *
160  * Return: Status
161  */
162 QDF_STATUS wlan_reg_get_dfs_region(struct wlan_objmgr_pdev *pdev,
163 			     enum dfs_reg *dfs_reg);
164 
165 /**
166  * wlan_reg_get_channel_reg_power() - Provide the channel regulatory power
167  * @chan_num: chennal number
168  *
169  * Return: int
170  */
171 uint32_t wlan_reg_get_channel_reg_power(struct wlan_objmgr_pdev *pdev,
172 					uint32_t chan_num);
173 
174 /**
175  * wlan_reg_get_channel_freq() - provide the channel center freq
176  * @chan_num: chennal number
177  *
178  * Return: int
179  */
180 uint32_t wlan_reg_get_channel_freq(struct wlan_objmgr_pdev *pdev,
181 				   uint32_t chan_num);
182 
183 /**
184  * wlan_reg_get_current_chan_list() - provide the pdev current channel list
185  * @pdev: pdev pointer
186  * @chan_list: channel list pointer
187  *
188  * Return: QDF_STATUS
189  */
190 QDF_STATUS wlan_reg_get_current_chan_list(struct wlan_objmgr_pdev *pdev,
191 		struct regulatory_channel *chan_list);
192 /**
193  * wlan_reg_get_bonded_channel_state() - get bonded channel state
194  * @pdev: pdev ptr
195  * @ch: chennal number
196  * @bw: chennal number
197  * @sec_ch: secondary channel
198  *
199  * Return: enum channel_state
200  */
201 enum channel_state wlan_reg_get_bonded_channel_state(
202 	struct wlan_objmgr_pdev *pdev, uint8_t ch,
203 	enum phy_ch_width bw, uint8_t sec_ch);
204 
205 /**
206  * wlan_reg_set_dfs_region() - set the dfs region
207  * @pdev: pdev ptr
208  * @dfs_reg: dfs region
209  *
210  * Return: void
211  */
212 void wlan_reg_set_dfs_region(struct wlan_objmgr_pdev *pdev,
213 			     enum dfs_reg dfs_reg);
214 
215 /**
216  * wlan_reg_get_bw_value() - provide the channel center freq
217  * @chan_num: chennal number
218  *
219  * Return: int
220  */
221 uint16_t wlan_reg_get_bw_value(enum phy_ch_width bw);
222 
223 /**
224  * wlan_reg_get_domain_from_country_code() - provide the channel center freq
225  * @reg_domain_ptr: regulatory domain ptr
226  * @country_alpha2: country alpha2
227  * @source: alpha2 source
228  *
229  * Return: int
230  */
231 QDF_STATUS wlan_reg_get_domain_from_country_code(v_REGDOMAIN_t *reg_domain_ptr,
232 						 const uint8_t *country_alpha2,
233 						 enum country_src source);
234 
235 /**
236  * wlan_reg_dmn_get_opclass_from_channel() - provide the channel center freq
237  * @country: country alpha2
238  * @channel: channel number
239  * @offset: offset
240  *
241  * Return: int
242  */
243 uint16_t wlan_reg_dmn_get_opclass_from_channel(uint8_t *country,
244 					       uint8_t channel,
245 					       uint8_t offset);
246 
247 /**
248  * wlan_reg_dmn_get_chanwidth_from_opclass() - get channel width from
249  *                                             operating class
250  * @country: country alpha2
251  * @channel: channel number
252  * @opclass: operating class
253  *
254  * Return: int
255  */
256 uint16_t wlan_reg_dmn_get_chanwidth_from_opclass(uint8_t *country,
257 						 uint8_t channel,
258 						 uint8_t opclass);
259 /**
260  * wlan_reg_dmn_set_curr_opclasses() - set operating class
261  * @num_classes: number of classes
262  * @class: operating class
263  *
264  * Return: int
265  */
266 uint16_t wlan_reg_dmn_set_curr_opclasses(uint8_t num_classes,
267 					 uint8_t *class);
268 
269 /**
270  * wlan_reg_dmn_get_curr_opclasses() - get current oper classes
271  * @num_classes: number of classes
272  * @class: operating class
273  *
274  * Return: int
275  */
276 uint16_t wlan_reg_dmn_get_curr_opclasses(uint8_t *num_classes,
277 					 uint8_t *class);
278 
279 
280 /**
281  * wlan_regulatory_init() - init regulatory component
282  *
283  * Return: Success or Failure
284  */
285 QDF_STATUS wlan_regulatory_init(void);
286 
287 /**
288  * wlan_regulatory_deinit() - deinit regulatory component
289  *
290  * Return: Success or Failure
291  */
292 QDF_STATUS wlan_regulatory_deinit(void);
293 
294 /**
295  * regulatory_psoc_open() - open regulatory component
296  *
297  * Return: Success or Failure
298  */
299 QDF_STATUS regulatory_psoc_open(struct wlan_objmgr_psoc *psoc);
300 
301 
302 /**
303  * regulatory_psoc_close() - close regulatory component
304  *
305  * Return: Success or Failure
306  */
307 QDF_STATUS regulatory_psoc_close(struct wlan_objmgr_psoc *psoc);
308 
309 /**
310  * regulatory_pdev_open() - Open regulatory component
311  * @pdev: Pointer to pdev structure.
312  *
313  * Return: Success or Failure
314  */
315 QDF_STATUS regulatory_pdev_open(struct wlan_objmgr_pdev *pdev);
316 
317 /**
318  * regulatory_pdev_close() - Close regulatory component
319  * @pdev: Pointer to pdev structure.
320  *
321  * Return: Success or Failure
322  */
323 QDF_STATUS regulatory_pdev_close(struct wlan_objmgr_pdev *pdev);
324 
325 /**
326  * wlan_reg_update_nol_ch () - set nol channel
327  * @pdev: pdev ptr
328  * @ch_list: channel list to be returned
329  * @num_ch: number of channels
330  * @nol_ch: nol flag
331  *
332  * Return: void
333  */
334 void wlan_reg_update_nol_ch(struct wlan_objmgr_pdev *pdev,
335 			    uint8_t *ch_list,
336 			    uint8_t num_ch,
337 			    bool nol_ch);
338 
339 /**
340  * wlan_reg_is_dfs_ch () - Checks the channel state for DFS
341  * @pdev: pdev ptr
342  * @chan: channel
343  *
344  * Return: true or false
345  */
346 bool wlan_reg_is_dfs_ch(struct wlan_objmgr_pdev *pdev, uint32_t chan);
347 
348 /**
349  * wlan_reg_is_dsrc_chan () - Checks if the channel is dsrc channel or not
350  * @pdev: pdev ptr
351  * @chan_num: channel
352  *
353  * Return: true or false
354  */
355 bool wlan_reg_is_dsrc_chan(struct wlan_objmgr_pdev *pdev, uint8_t chan_num);
356 
357 /**
358  * wlan_reg_is_etsi13_srd_chan () - Checks if the ch is ETSI13 srd ch or not
359  * @pdev: pdev ptr
360  * @chan_num: channel
361  *
362  * Return: true or false
363  */
364 bool wlan_reg_is_etsi13_srd_chan(struct wlan_objmgr_pdev *pdev,
365 				 uint8_t chan_num);
366 
367 /**
368  * wlan_reg_is_etsi13_regdmn() - Checks if current reg domain is ETSI13 or not
369  * @pdev: pdev ptr
370  *
371  * Return: true or false
372  */
373 bool wlan_reg_is_etsi13_regdmn(struct wlan_objmgr_pdev *pdev);
374 
375 /**
376  * wlan_reg_is_etsi13_srd_chan_allowed_master_mode() - Checks if regdmn is
377  * ETSI13 and SRD channels are allowed in master mode or not.
378  *
379  * @pdev: pdev ptr
380  *
381  * Return: true or false
382  */
383 bool wlan_reg_is_etsi13_srd_chan_allowed_master_mode(struct wlan_objmgr_pdev
384 						     *pdev);
385 
386 /**
387  * wlan_reg_is_passive_or_disable_ch () - Checks chan state for passive
388  * and disabled
389  * @pdev: pdev ptr
390  * @chan: channel
391  *
392  * Return: true or false
393  */
394 bool wlan_reg_is_passive_or_disable_ch(struct wlan_objmgr_pdev *pdev,
395 				       uint32_t chan);
396 
397 /**
398  * wlan_reg_is_disable_ch () - Checks chan state for disabled
399  * @pdev: pdev ptr
400  * @chan: channel
401  *
402  * Return: true or false
403  */
404 bool wlan_reg_is_disable_ch(struct wlan_objmgr_pdev *pdev, uint32_t chan);
405 
406 /**
407  * wlan_reg_freq_to_chan () - convert channel freq to channel number
408  * @pdev: The physical dev to set current country for
409  * @freq: frequency
410  *
411  * Return: true or false
412  */
413 uint32_t wlan_reg_freq_to_chan(struct wlan_objmgr_pdev *pdev,
414 			       uint32_t freq);
415 
416 /**
417  * wlan_reg_chan_to_freq () - convert channel number to frequency
418  * @chan: channel number
419  *
420  * Return: true or false
421  */
422 uint32_t wlan_reg_chan_to_freq(struct wlan_objmgr_pdev *pdev,
423 			       uint32_t chan);
424 /**
425  * wlan_reg_is_world() - reg is world mode
426  * @country: The country information
427  *
428  * Return: true or false
429  */
430 bool wlan_reg_is_world(uint8_t *country);
431 
432 /**
433  * wlan_reg_is_us() - reg is us country
434  * @country: The country information
435  *
436  * Return: true or false
437  */
438 bool wlan_reg_is_us(uint8_t *country);
439 
440 /**
441  * wlan_reg_chan_is_49ghz() - Check if the input channel number is 4.9GHz
442  * @pdev: Pdev pointer
443  * @chan_num: Input channel number
444  *
445  * Return: true if the channel is 4.9GHz else false.
446  */
447 
448 bool wlan_reg_chan_is_49ghz(struct wlan_objmgr_pdev *pdev,
449 		uint8_t chan_num);
450 
451 /**
452  * wlan_reg_set_country() - Set the current regulatory country
453  * @pdev: The physical dev to set current country for
454  * @country: The country information to configure
455  *
456  * Return: QDF_STATUS
457  */
458 QDF_STATUS wlan_reg_set_country(struct wlan_objmgr_pdev *pdev,
459 				uint8_t *country);
460 
461 /**
462  * wlan_reg_set_11d_country() - Set the 11d regulatory country
463  * @pdev: The physical dev to set current country for
464  * @country: The country information to configure
465  *
466  * Return: QDF_STATUS
467  */
468 QDF_STATUS wlan_reg_set_11d_country(struct wlan_objmgr_pdev *pdev,
469 				    uint8_t *country);
470 
471 /**
472  * wlan_reg_register_chan_change_callback () - add chan change cbk
473  * @psoc: psoc ptr
474  * @cbk: callback
475  * @arg: argument
476  *
477  * Return: true or false
478  */
479 void wlan_reg_register_chan_change_callback(struct wlan_objmgr_psoc *psoc,
480 					    reg_chan_change_callback cbk,
481 					    void *arg);
482 
483 /**
484  * wlan_reg_unregister_chan_change_callback () - remove chan change cbk
485  * @psoc: psoc ptr
486  * @cbk:callback
487  *
488  * Return: true or false
489  */
490 void wlan_reg_unregister_chan_change_callback(struct wlan_objmgr_psoc *psoc,
491 					      reg_chan_change_callback cbk);
492 
493 /**
494  * wlan_reg_is_11d_offloaded() - 11d offloaded supported
495  * @psoc: psoc ptr
496  *
497  * Return: bool
498  */
499 bool wlan_reg_is_11d_offloaded(struct wlan_objmgr_psoc *psoc);
500 
501 /**
502  * wlan_reg_11d_enabled_on_host() - 11d enabled don host
503  * @psoc: psoc ptr
504  *
505  * Return: bool
506  */
507 bool wlan_reg_11d_enabled_on_host(struct wlan_objmgr_psoc *psoc);
508 
509 /**
510  * wlan_reg_get_chip_mode() - get supported chip mode
511  * @pdev: pdev pointer
512  * @chip_mode: chip mode
513  *
514  * Return: QDF STATUS
515  */
516 QDF_STATUS wlan_reg_get_chip_mode(struct wlan_objmgr_pdev *pdev,
517 		uint32_t *chip_mode);
518 
519 /**
520  * wlan_reg_is_11d_scan_inprogress() - checks 11d scan status
521  * @psoc: psoc ptr
522  *
523  * Return: bool
524  */
525 bool wlan_reg_is_11d_scan_inprogress(struct wlan_objmgr_psoc *psoc);
526 /**
527  * wlan_reg_get_freq_range() - Get 2GHz and 5GHz frequency range
528  * @pdev: pdev pointer
529  * @low_2g: low 2GHz frequency range
530  * @high_2g: high 2GHz frequency range
531  * @low_5g: low 5GHz frequency range
532  * @high_5g: high 5GHz frequency range
533  *
534  * Return: QDF status
535  */
536 QDF_STATUS wlan_reg_get_freq_range(struct wlan_objmgr_pdev *pdev,
537 		uint32_t *low_2g,
538 		uint32_t *high_2g,
539 		uint32_t *low_5g,
540 		uint32_t *high_5g);
541 /**
542  * wlan_reg_get_tx_ops () - get regulatory tx ops
543  * @psoc: psoc ptr
544  *
545  */
546 struct wlan_lmac_if_reg_tx_ops *
547 wlan_reg_get_tx_ops(struct wlan_objmgr_psoc *psoc);
548 
549 /**
550  * wlan_reg_get_curr_regdomain() - Get current regdomain in use
551  * @pdev: pdev pointer
552  * @cur_regdmn: Current regdomain info
553  *
554  * Return: QDF status
555  */
556 QDF_STATUS wlan_reg_get_curr_regdomain(struct wlan_objmgr_pdev *pdev,
557 		struct cur_regdmn_info *cur_regdmn);
558 
559 /**
560  * wlan_reg_update_nol_history_ch() - Set nol-history flag for the channels in
561  * the list.
562  *
563  * @pdev: Pdev ptr
564  * @ch_list: Input channel list.
565  * @num_ch: Number of channels.
566  * @nol_history_ch: Nol history value.
567  *
568  * Return: void
569  */
570 void wlan_reg_update_nol_history_ch(struct wlan_objmgr_pdev *pdev,
571 				    uint8_t *ch_list,
572 				    uint8_t num_ch,
573 				    bool nol_history_ch);
574 #endif
575