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