rtw_rf.h 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242
  1. /******************************************************************************
  2. *
  3. * Copyright(c) 2007 - 2017 Realtek Corporation.
  4. *
  5. * This program is free software; you can redistribute it and/or modify it
  6. * under the terms of version 2 of the GNU General Public License as
  7. * published by the Free Software Foundation.
  8. *
  9. * This program is distributed in the hope that it will be useful, but WITHOUT
  10. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  12. * more details.
  13. *
  14. *****************************************************************************/
  15. #ifndef __RTW_RF_H_
  16. #define __RTW_RF_H_
  17. #define NumRates (13)
  18. #define B_MODE_RATE_NUM (4)
  19. #define G_MODE_RATE_NUM (8)
  20. #define G_MODE_BASIC_RATE_NUM (3)
  21. /* slot time for 11g */
  22. #define SHORT_SLOT_TIME 9
  23. #define NON_SHORT_SLOT_TIME 20
  24. #define CENTER_CH_2G_40M_NUM 9
  25. #define CENTER_CH_2G_NUM 14
  26. #define CENTER_CH_5G_20M_NUM 28 /* 20M center channels */
  27. #define CENTER_CH_5G_40M_NUM 14 /* 40M center channels */
  28. #define CENTER_CH_5G_80M_NUM 7 /* 80M center channels */
  29. #define CENTER_CH_5G_160M_NUM 3 /* 160M center channels */
  30. #define CENTER_CH_5G_ALL_NUM (CENTER_CH_5G_20M_NUM + CENTER_CH_5G_40M_NUM + CENTER_CH_5G_80M_NUM)
  31. #define MAX_CHANNEL_NUM_2G CENTER_CH_2G_NUM
  32. #define MAX_CHANNEL_NUM_5G CENTER_CH_5G_20M_NUM
  33. #define MAX_CHANNEL_NUM (MAX_CHANNEL_NUM_2G + MAX_CHANNEL_NUM_5G)
  34. extern u8 center_ch_2g[CENTER_CH_2G_NUM];
  35. extern u8 center_ch_2g_40m[CENTER_CH_2G_40M_NUM];
  36. u8 center_chs_2g_num(u8 bw);
  37. u8 center_chs_2g(u8 bw, u8 id);
  38. extern u8 center_ch_5g_20m[CENTER_CH_5G_20M_NUM];
  39. extern u8 center_ch_5g_40m[CENTER_CH_5G_40M_NUM];
  40. extern u8 center_ch_5g_20m_40m[CENTER_CH_5G_20M_NUM + CENTER_CH_5G_40M_NUM];
  41. extern u8 center_ch_5g_80m[CENTER_CH_5G_80M_NUM];
  42. extern u8 center_ch_5g_all[CENTER_CH_5G_ALL_NUM];
  43. u8 center_chs_5g_num(u8 bw);
  44. u8 center_chs_5g(u8 bw, u8 id);
  45. u8 rtw_get_scch_by_cch_offset(u8 cch, u8 bw, u8 offset);
  46. u8 rtw_get_op_chs_by_cch_bw(u8 cch, u8 bw, u8 **op_chs, u8 *op_ch_num);
  47. u8 rtw_get_ch_group(u8 ch, u8 *group, u8 *cck_group);
  48. typedef enum _CAPABILITY {
  49. cESS = 0x0001,
  50. cIBSS = 0x0002,
  51. cPollable = 0x0004,
  52. cPollReq = 0x0008,
  53. cPrivacy = 0x0010,
  54. cShortPreamble = 0x0020,
  55. cPBCC = 0x0040,
  56. cChannelAgility = 0x0080,
  57. cSpectrumMgnt = 0x0100,
  58. cQos = 0x0200, /* For HCCA, use with CF-Pollable and CF-PollReq */
  59. cShortSlotTime = 0x0400,
  60. cAPSD = 0x0800,
  61. cRM = 0x1000, /* RRM (Radio Request Measurement) */
  62. cDSSS_OFDM = 0x2000,
  63. cDelayedBA = 0x4000,
  64. cImmediateBA = 0x8000,
  65. } CAPABILITY, *PCAPABILITY;
  66. enum _REG_PREAMBLE_MODE {
  67. PREAMBLE_LONG = 1,
  68. PREAMBLE_AUTO = 2,
  69. PREAMBLE_SHORT = 3,
  70. };
  71. #define rf_path_char(path) (((path) >= RF_PATH_MAX) ? 'X' : 'A' + (path))
  72. /* Bandwidth Offset */
  73. #define HAL_PRIME_CHNL_OFFSET_DONT_CARE 0
  74. #define HAL_PRIME_CHNL_OFFSET_LOWER 1
  75. #define HAL_PRIME_CHNL_OFFSET_UPPER 2
  76. typedef enum _BAND_TYPE {
  77. BAND_ON_2_4G = 0,
  78. BAND_ON_5G = 1,
  79. BAND_ON_BOTH = 2,
  80. BAND_MAX = 3,
  81. } BAND_TYPE, *PBAND_TYPE;
  82. extern const char *const _band_str[];
  83. #define band_str(band) (((band) >= BAND_MAX) ? _band_str[BAND_MAX] : _band_str[(band)])
  84. extern const u8 _band_to_band_cap[];
  85. #define band_to_band_cap(band) (((band) >= BAND_MAX) ? _band_to_band_cap[BAND_MAX] : _band_to_band_cap[(band)])
  86. extern const char *const _ch_width_str[];
  87. #define ch_width_str(bw) (((bw) < CHANNEL_WIDTH_MAX) ? _ch_width_str[(bw)] : "CHANNEL_WIDTH_MAX")
  88. extern const u8 _ch_width_to_bw_cap[];
  89. #define ch_width_to_bw_cap(bw) (((bw) < CHANNEL_WIDTH_MAX) ? _ch_width_to_bw_cap[(bw)] : 0)
  90. /*
  91. * Represent Extention Channel Offset in HT Capabilities
  92. * This is available only in 40Mhz mode.
  93. * */
  94. typedef enum _EXTCHNL_OFFSET {
  95. EXTCHNL_OFFSET_NO_EXT = 0,
  96. EXTCHNL_OFFSET_UPPER = 1,
  97. EXTCHNL_OFFSET_NO_DEF = 2,
  98. EXTCHNL_OFFSET_LOWER = 3,
  99. } EXTCHNL_OFFSET, *PEXTCHNL_OFFSET;
  100. typedef enum _VHT_DATA_SC {
  101. VHT_DATA_SC_DONOT_CARE = 0,
  102. VHT_DATA_SC_20_UPPER_OF_80MHZ = 1,
  103. VHT_DATA_SC_20_LOWER_OF_80MHZ = 2,
  104. VHT_DATA_SC_20_UPPERST_OF_80MHZ = 3,
  105. VHT_DATA_SC_20_LOWEST_OF_80MHZ = 4,
  106. VHT_DATA_SC_20_RECV1 = 5,
  107. VHT_DATA_SC_20_RECV2 = 6,
  108. VHT_DATA_SC_20_RECV3 = 7,
  109. VHT_DATA_SC_20_RECV4 = 8,
  110. VHT_DATA_SC_40_UPPER_OF_80MHZ = 9,
  111. VHT_DATA_SC_40_LOWER_OF_80MHZ = 10,
  112. } VHT_DATA_SC, *PVHT_DATA_SC_E;
  113. typedef enum _PROTECTION_MODE {
  114. PROTECTION_MODE_AUTO = 0,
  115. PROTECTION_MODE_FORCE_ENABLE = 1,
  116. PROTECTION_MODE_FORCE_DISABLE = 2,
  117. } PROTECTION_MODE, *PPROTECTION_MODE;
  118. #define RF_TYPE_VALID(rf_type) (rf_type < RF_TYPE_MAX)
  119. extern const u8 _rf_type_to_rf_tx_cnt[];
  120. #define rf_type_to_rf_tx_cnt(rf_type) (RF_TYPE_VALID(rf_type) ? _rf_type_to_rf_tx_cnt[rf_type] : 0)
  121. extern const u8 _rf_type_to_rf_rx_cnt[];
  122. #define rf_type_to_rf_rx_cnt(rf_type) (RF_TYPE_VALID(rf_type) ? _rf_type_to_rf_rx_cnt[rf_type] : 0)
  123. int rtw_ch2freq(int chan);
  124. int rtw_freq2ch(int freq);
  125. bool rtw_chbw_to_freq_range(u8 ch, u8 bw, u8 offset, u32 *hi, u32 *lo);
  126. struct rf_ctl_t;
  127. typedef enum _REGULATION_TXPWR_LMT {
  128. TXPWR_LMT_NONE = 0, /* no limit */
  129. TXPWR_LMT_FCC = 1,
  130. TXPWR_LMT_MKK = 2,
  131. TXPWR_LMT_ETSI = 3,
  132. TXPWR_LMT_IC = 4,
  133. TXPWR_LMT_KCC = 5,
  134. TXPWR_LMT_ACMA = 6,
  135. TXPWR_LMT_CHILE = 7,
  136. TXPWR_LMT_WW = 8, /* smallest of all available limit, keep last */
  137. } REGULATION_TXPWR_LMT;
  138. extern const char *const _regd_str[];
  139. #define regd_str(regd) (((regd) > TXPWR_LMT_WW) ? _regd_str[TXPWR_LMT_WW] : _regd_str[(regd)])
  140. #ifdef CONFIG_TXPWR_LIMIT
  141. struct regd_exc_ent {
  142. _list list;
  143. char country[2];
  144. u8 domain;
  145. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(6, 5, 1))
  146. char regd_name[];
  147. #else
  148. char regd_name[0];
  149. #endif
  150. };
  151. void dump_regd_exc_list(void *sel, struct rf_ctl_t *rfctl);
  152. void rtw_regd_exc_add_with_nlen(struct rf_ctl_t *rfctl, const char *country, u8 domain, const char *regd_name, u32 nlen);
  153. void rtw_regd_exc_add(struct rf_ctl_t *rfctl, const char *country, u8 domain, const char *regd_name);
  154. struct regd_exc_ent *_rtw_regd_exc_search(struct rf_ctl_t *rfctl, const char *country, u8 domain);
  155. struct regd_exc_ent *rtw_regd_exc_search(struct rf_ctl_t *rfctl, const char *country, u8 domain);
  156. void rtw_regd_exc_list_free(struct rf_ctl_t *rfctl);
  157. void dump_txpwr_lmt(void *sel, _adapter *adapter);
  158. void rtw_txpwr_lmt_add_with_nlen(struct rf_ctl_t *rfctl, const char *regd_name, u32 nlen
  159. , u8 band, u8 bw, u8 tlrs, u8 ntx_idx, u8 ch_idx, s8 lmt);
  160. void rtw_txpwr_lmt_add(struct rf_ctl_t *rfctl, const char *regd_name
  161. , u8 band, u8 bw, u8 tlrs, u8 ntx_idx, u8 ch_idx, s8 lmt);
  162. struct txpwr_lmt_ent *_rtw_txpwr_lmt_get_by_name(struct rf_ctl_t *rfctl, const char *regd_name);
  163. struct txpwr_lmt_ent *rtw_txpwr_lmt_get_by_name(struct rf_ctl_t *rfctl, const char *regd_name);
  164. void rtw_txpwr_lmt_list_free(struct rf_ctl_t *rfctl);
  165. #endif /* CONFIG_TXPWR_LIMIT */
  166. #define BB_GAIN_2G 0
  167. #ifdef CONFIG_IEEE80211_BAND_5GHZ
  168. #define BB_GAIN_5GLB1 1
  169. #define BB_GAIN_5GLB2 2
  170. #define BB_GAIN_5GMB1 3
  171. #define BB_GAIN_5GMB2 4
  172. #define BB_GAIN_5GHB 5
  173. #endif
  174. #ifdef CONFIG_IEEE80211_BAND_5GHZ
  175. #define BB_GAIN_NUM 6
  176. #else
  177. #define BB_GAIN_NUM 1
  178. #endif
  179. int rtw_ch_to_bb_gain_sel(int ch);
  180. void rtw_rf_set_tx_gain_offset(_adapter *adapter, u8 path, s8 offset);
  181. void rtw_rf_apply_tx_gain_offset(_adapter *adapter, u8 ch);
  182. /* only check channel ranges */
  183. #define rtw_is_2g_ch(ch) (ch >= 1 && ch <= 14)
  184. #define rtw_is_5g_ch(ch) ((ch) >= 36 && (ch) <= 177)
  185. #define rtw_is_same_band(a, b) \
  186. ((rtw_is_2g_ch(a) && rtw_is_2g_ch(b)) \
  187. || (rtw_is_5g_ch(a) && rtw_is_5g_ch(b)))
  188. #define rtw_is_5g_band1(ch) ((ch) >= 36 && (ch) <= 48)
  189. #define rtw_is_5g_band2(ch) ((ch) >= 52 && (ch) <= 64)
  190. #define rtw_is_5g_band3(ch) ((ch) >= 100 && (ch) <= 144)
  191. #define rtw_is_5g_band4(ch) ((ch) >= 149 && (ch) <= 177)
  192. #define rtw_is_same_5g_band(a, b) \
  193. ((rtw_is_5g_band1(a) && rtw_is_5g_band1(b)) \
  194. || (rtw_is_5g_band2(a) && rtw_is_5g_band2(b)) \
  195. || (rtw_is_5g_band3(a) && rtw_is_5g_band3(b)) \
  196. || (rtw_is_5g_band4(a) && rtw_is_5g_band4(b)))
  197. u8 rtw_is_dfs_range(u32 hi, u32 lo);
  198. u8 rtw_is_dfs_ch(u8 ch);
  199. u8 rtw_is_dfs_chbw(u8 ch, u8 bw, u8 offset);
  200. bool rtw_is_long_cac_range(u32 hi, u32 lo, u8 dfs_region);
  201. bool rtw_is_long_cac_ch(u8 ch, u8 bw, u8 offset, u8 dfs_region);
  202. #endif /* _RTL8711_RF_H_ */