1 /* 2 * Copyright (c) 2008-2011 Atheros Communications Inc. 3 * 4 * Permission to use, copy, modify, and/or distribute this software for any 5 * purpose with or without fee is hereby granted, provided that the above 6 * copyright notice and this permission notice appear in all copies. 7 * 8 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 9 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 10 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 11 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 12 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 13 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 14 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 15 */ 16 17 /* We use the hw_value as an index into our private channel structure */ 18 19 #include <linux/export.h> 20 #include "common.h" 21 22 #define CHAN2G(_freq, _idx) { \ 23 .band = NL80211_BAND_2GHZ, \ 24 .center_freq = (_freq), \ 25 .hw_value = (_idx), \ 26 .max_power = 20, \ 27 } 28 29 #define CHAN5G(_freq, _idx) { \ 30 .band = NL80211_BAND_5GHZ, \ 31 .center_freq = (_freq), \ 32 .hw_value = (_idx), \ 33 .max_power = 20, \ 34 } 35 36 /* Some 2 GHz radios are actually tunable on 2312-2732 37 * on 5 MHz steps, we support the channels which we know 38 * we have calibration data for all cards though to make 39 * this static */ 40 static const struct ieee80211_channel ath9k_2ghz_chantable[] = { 41 CHAN2G(2412, 0), /* Channel 1 */ 42 CHAN2G(2417, 1), /* Channel 2 */ 43 CHAN2G(2422, 2), /* Channel 3 */ 44 CHAN2G(2427, 3), /* Channel 4 */ 45 CHAN2G(2432, 4), /* Channel 5 */ 46 CHAN2G(2437, 5), /* Channel 6 */ 47 CHAN2G(2442, 6), /* Channel 7 */ 48 CHAN2G(2447, 7), /* Channel 8 */ 49 CHAN2G(2452, 8), /* Channel 9 */ 50 CHAN2G(2457, 9), /* Channel 10 */ 51 CHAN2G(2462, 10), /* Channel 11 */ 52 CHAN2G(2467, 11), /* Channel 12 */ 53 CHAN2G(2472, 12), /* Channel 13 */ 54 CHAN2G(2484, 13), /* Channel 14 */ 55 }; 56 57 /* Some 5 GHz radios are actually tunable on XXXX-YYYY 58 * on 5 MHz steps, we support the channels which we know 59 * we have calibration data for all cards though to make 60 * this static */ 61 static const struct ieee80211_channel ath9k_5ghz_chantable[] = { 62 /* _We_ call this UNII 1 */ 63 CHAN5G(5180, 14), /* Channel 36 */ 64 CHAN5G(5200, 15), /* Channel 40 */ 65 CHAN5G(5220, 16), /* Channel 44 */ 66 CHAN5G(5240, 17), /* Channel 48 */ 67 /* _We_ call this UNII 2 */ 68 CHAN5G(5260, 18), /* Channel 52 */ 69 CHAN5G(5280, 19), /* Channel 56 */ 70 CHAN5G(5300, 20), /* Channel 60 */ 71 CHAN5G(5320, 21), /* Channel 64 */ 72 /* _We_ call this "Middle band" */ 73 CHAN5G(5500, 22), /* Channel 100 */ 74 CHAN5G(5520, 23), /* Channel 104 */ 75 CHAN5G(5540, 24), /* Channel 108 */ 76 CHAN5G(5560, 25), /* Channel 112 */ 77 CHAN5G(5580, 26), /* Channel 116 */ 78 CHAN5G(5600, 27), /* Channel 120 */ 79 CHAN5G(5620, 28), /* Channel 124 */ 80 CHAN5G(5640, 29), /* Channel 128 */ 81 CHAN5G(5660, 30), /* Channel 132 */ 82 CHAN5G(5680, 31), /* Channel 136 */ 83 CHAN5G(5700, 32), /* Channel 140 */ 84 /* _We_ call this UNII 3 */ 85 CHAN5G(5745, 33), /* Channel 149 */ 86 CHAN5G(5765, 34), /* Channel 153 */ 87 CHAN5G(5785, 35), /* Channel 157 */ 88 CHAN5G(5805, 36), /* Channel 161 */ 89 CHAN5G(5825, 37), /* Channel 165 */ 90 }; 91 92 /* Atheros hardware rate code addition for short preamble */ 93 #define SHPCHECK(__hw_rate, __flags) \ 94 ((__flags & IEEE80211_RATE_SHORT_PREAMBLE) ? (__hw_rate | 0x04 ) : 0) 95 96 #define RATE(_bitrate, _hw_rate, _flags) { \ 97 .bitrate = (_bitrate), \ 98 .flags = (_flags), \ 99 .hw_value = (_hw_rate), \ 100 .hw_value_short = (SHPCHECK(_hw_rate, _flags)) \ 101 } 102 103 static struct ieee80211_rate ath9k_legacy_rates[] = { 104 RATE(10, 0x1b, 0), 105 RATE(20, 0x1a, IEEE80211_RATE_SHORT_PREAMBLE), 106 RATE(55, 0x19, IEEE80211_RATE_SHORT_PREAMBLE), 107 RATE(110, 0x18, IEEE80211_RATE_SHORT_PREAMBLE), 108 RATE(60, 0x0b, (IEEE80211_RATE_SUPPORTS_5MHZ | 109 IEEE80211_RATE_SUPPORTS_10MHZ)), 110 RATE(90, 0x0f, (IEEE80211_RATE_SUPPORTS_5MHZ | 111 IEEE80211_RATE_SUPPORTS_10MHZ)), 112 RATE(120, 0x0a, (IEEE80211_RATE_SUPPORTS_5MHZ | 113 IEEE80211_RATE_SUPPORTS_10MHZ)), 114 RATE(180, 0x0e, (IEEE80211_RATE_SUPPORTS_5MHZ | 115 IEEE80211_RATE_SUPPORTS_10MHZ)), 116 RATE(240, 0x09, (IEEE80211_RATE_SUPPORTS_5MHZ | 117 IEEE80211_RATE_SUPPORTS_10MHZ)), 118 RATE(360, 0x0d, (IEEE80211_RATE_SUPPORTS_5MHZ | 119 IEEE80211_RATE_SUPPORTS_10MHZ)), 120 RATE(480, 0x08, (IEEE80211_RATE_SUPPORTS_5MHZ | 121 IEEE80211_RATE_SUPPORTS_10MHZ)), 122 RATE(540, 0x0c, (IEEE80211_RATE_SUPPORTS_5MHZ | 123 IEEE80211_RATE_SUPPORTS_10MHZ)), 124 }; 125 126 int ath9k_cmn_init_channels_rates(struct ath_common *common) 127 { 128 struct ath_hw *ah = common->ah; 129 void *channels; 130 131 BUILD_BUG_ON(ARRAY_SIZE(ath9k_2ghz_chantable) + 132 ARRAY_SIZE(ath9k_5ghz_chantable) != 133 ATH9K_NUM_CHANNELS); 134 135 if (ah->caps.hw_caps & ATH9K_HW_CAP_2GHZ) { 136 channels = devm_kmemdup(ah->dev, ath9k_2ghz_chantable, 137 sizeof(ath9k_2ghz_chantable), GFP_KERNEL); 138 if (!channels) 139 return -ENOMEM; 140 141 common->sbands[NL80211_BAND_2GHZ].channels = channels; 142 common->sbands[NL80211_BAND_2GHZ].band = NL80211_BAND_2GHZ; 143 common->sbands[NL80211_BAND_2GHZ].n_channels = 144 ARRAY_SIZE(ath9k_2ghz_chantable); 145 common->sbands[NL80211_BAND_2GHZ].bitrates = ath9k_legacy_rates; 146 common->sbands[NL80211_BAND_2GHZ].n_bitrates = 147 ARRAY_SIZE(ath9k_legacy_rates); 148 } 149 150 if (ah->caps.hw_caps & ATH9K_HW_CAP_5GHZ) { 151 channels = devm_kmemdup(ah->dev, ath9k_5ghz_chantable, 152 sizeof(ath9k_5ghz_chantable), GFP_KERNEL); 153 if (!channels) 154 return -ENOMEM; 155 156 common->sbands[NL80211_BAND_5GHZ].channels = channels; 157 common->sbands[NL80211_BAND_5GHZ].band = NL80211_BAND_5GHZ; 158 common->sbands[NL80211_BAND_5GHZ].n_channels = 159 ARRAY_SIZE(ath9k_5ghz_chantable); 160 common->sbands[NL80211_BAND_5GHZ].bitrates = 161 ath9k_legacy_rates + 4; 162 common->sbands[NL80211_BAND_5GHZ].n_bitrates = 163 ARRAY_SIZE(ath9k_legacy_rates) - 4; 164 } 165 return 0; 166 } 167 EXPORT_SYMBOL(ath9k_cmn_init_channels_rates); 168 169 void ath9k_cmn_setup_ht_cap(struct ath_hw *ah, 170 struct ieee80211_sta_ht_cap *ht_info) 171 { 172 struct ath_common *common = ath9k_hw_common(ah); 173 u8 tx_streams, rx_streams; 174 int i, max_streams; 175 176 ht_info->ht_supported = true; 177 ht_info->cap = IEEE80211_HT_CAP_SUP_WIDTH_20_40 | 178 IEEE80211_HT_CAP_SM_PS | 179 IEEE80211_HT_CAP_SGI_40 | 180 IEEE80211_HT_CAP_DSSSCCK40; 181 182 if (ah->caps.hw_caps & ATH9K_HW_CAP_LDPC) 183 ht_info->cap |= IEEE80211_HT_CAP_LDPC_CODING; 184 185 if (ah->caps.hw_caps & ATH9K_HW_CAP_SGI_20) 186 ht_info->cap |= IEEE80211_HT_CAP_SGI_20; 187 188 ht_info->ampdu_factor = IEEE80211_HT_MAX_AMPDU_64K; 189 ht_info->ampdu_density = IEEE80211_HT_MPDU_DENSITY_8; 190 191 if (AR_SREV_9271(ah) || AR_SREV_9330(ah) || AR_SREV_9485(ah) || AR_SREV_9565(ah)) 192 max_streams = 1; 193 else if (AR_SREV_9462(ah)) 194 max_streams = 2; 195 else if (AR_SREV_9300_20_OR_LATER(ah)) 196 max_streams = 3; 197 else 198 max_streams = 2; 199 200 if (AR_SREV_9280_20_OR_LATER(ah)) { 201 if (max_streams >= 2) 202 ht_info->cap |= IEEE80211_HT_CAP_TX_STBC; 203 ht_info->cap |= (1 << IEEE80211_HT_CAP_RX_STBC_SHIFT); 204 } 205 206 /* set up supported mcs set */ 207 memset(&ht_info->mcs, 0, sizeof(ht_info->mcs)); 208 tx_streams = ath9k_cmn_count_streams(ah->txchainmask, max_streams); 209 rx_streams = ath9k_cmn_count_streams(ah->rxchainmask, max_streams); 210 211 ath_dbg(common, CONFIG, "TX streams %d, RX streams: %d\n", 212 tx_streams, rx_streams); 213 214 if (tx_streams != rx_streams) { 215 ht_info->mcs.tx_params |= IEEE80211_HT_MCS_TX_RX_DIFF; 216 ht_info->mcs.tx_params |= ((tx_streams - 1) << 217 IEEE80211_HT_MCS_TX_MAX_STREAMS_SHIFT); 218 } 219 220 for (i = 0; i < rx_streams; i++) 221 ht_info->mcs.rx_mask[i] = 0xff; 222 223 ht_info->mcs.tx_params |= IEEE80211_HT_MCS_TX_DEFINED; 224 } 225 EXPORT_SYMBOL(ath9k_cmn_setup_ht_cap); 226 227 void ath9k_cmn_reload_chainmask(struct ath_hw *ah) 228 { 229 struct ath_common *common = ath9k_hw_common(ah); 230 231 if (!(ah->caps.hw_caps & ATH9K_HW_CAP_HT)) 232 return; 233 234 if (ah->caps.hw_caps & ATH9K_HW_CAP_2GHZ) 235 ath9k_cmn_setup_ht_cap(ah, 236 &common->sbands[NL80211_BAND_2GHZ].ht_cap); 237 if (ah->caps.hw_caps & ATH9K_HW_CAP_5GHZ) 238 ath9k_cmn_setup_ht_cap(ah, 239 &common->sbands[NL80211_BAND_5GHZ].ht_cap); 240 } 241 EXPORT_SYMBOL(ath9k_cmn_reload_chainmask); 242