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
ath9k_cmn_init_channels_rates(struct ath_common * common)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_kzalloc(ah->dev,
137 sizeof(ath9k_2ghz_chantable), GFP_KERNEL);
138 if (!channels)
139 return -ENOMEM;
140
141 memcpy(channels, ath9k_2ghz_chantable,
142 sizeof(ath9k_2ghz_chantable));
143 common->sbands[NL80211_BAND_2GHZ].channels = channels;
144 common->sbands[NL80211_BAND_2GHZ].band = NL80211_BAND_2GHZ;
145 common->sbands[NL80211_BAND_2GHZ].n_channels =
146 ARRAY_SIZE(ath9k_2ghz_chantable);
147 common->sbands[NL80211_BAND_2GHZ].bitrates = ath9k_legacy_rates;
148 common->sbands[NL80211_BAND_2GHZ].n_bitrates =
149 ARRAY_SIZE(ath9k_legacy_rates);
150 }
151
152 if (ah->caps.hw_caps & ATH9K_HW_CAP_5GHZ) {
153 channels = devm_kzalloc(ah->dev,
154 sizeof(ath9k_5ghz_chantable), GFP_KERNEL);
155 if (!channels)
156 return -ENOMEM;
157
158 memcpy(channels, ath9k_5ghz_chantable,
159 sizeof(ath9k_5ghz_chantable));
160 common->sbands[NL80211_BAND_5GHZ].channels = channels;
161 common->sbands[NL80211_BAND_5GHZ].band = NL80211_BAND_5GHZ;
162 common->sbands[NL80211_BAND_5GHZ].n_channels =
163 ARRAY_SIZE(ath9k_5ghz_chantable);
164 common->sbands[NL80211_BAND_5GHZ].bitrates =
165 ath9k_legacy_rates + 4;
166 common->sbands[NL80211_BAND_5GHZ].n_bitrates =
167 ARRAY_SIZE(ath9k_legacy_rates) - 4;
168 }
169 return 0;
170 }
171 EXPORT_SYMBOL(ath9k_cmn_init_channels_rates);
172
ath9k_cmn_setup_ht_cap(struct ath_hw * ah,struct ieee80211_sta_ht_cap * ht_info)173 void ath9k_cmn_setup_ht_cap(struct ath_hw *ah,
174 struct ieee80211_sta_ht_cap *ht_info)
175 {
176 struct ath_common *common = ath9k_hw_common(ah);
177 u8 tx_streams, rx_streams;
178 int i, max_streams;
179
180 ht_info->ht_supported = true;
181 ht_info->cap = IEEE80211_HT_CAP_SUP_WIDTH_20_40 |
182 IEEE80211_HT_CAP_SM_PS |
183 IEEE80211_HT_CAP_SGI_40 |
184 IEEE80211_HT_CAP_DSSSCCK40;
185
186 if (ah->caps.hw_caps & ATH9K_HW_CAP_LDPC)
187 ht_info->cap |= IEEE80211_HT_CAP_LDPC_CODING;
188
189 if (ah->caps.hw_caps & ATH9K_HW_CAP_SGI_20)
190 ht_info->cap |= IEEE80211_HT_CAP_SGI_20;
191
192 ht_info->ampdu_factor = IEEE80211_HT_MAX_AMPDU_64K;
193 ht_info->ampdu_density = IEEE80211_HT_MPDU_DENSITY_8;
194
195 if (AR_SREV_9271(ah) || AR_SREV_9330(ah) || AR_SREV_9485(ah) || AR_SREV_9565(ah))
196 max_streams = 1;
197 else if (AR_SREV_9462(ah))
198 max_streams = 2;
199 else if (AR_SREV_9300_20_OR_LATER(ah))
200 max_streams = 3;
201 else
202 max_streams = 2;
203
204 if (AR_SREV_9280_20_OR_LATER(ah)) {
205 if (max_streams >= 2)
206 ht_info->cap |= IEEE80211_HT_CAP_TX_STBC;
207 ht_info->cap |= (1 << IEEE80211_HT_CAP_RX_STBC_SHIFT);
208 }
209
210 /* set up supported mcs set */
211 memset(&ht_info->mcs, 0, sizeof(ht_info->mcs));
212 tx_streams = ath9k_cmn_count_streams(ah->txchainmask, max_streams);
213 rx_streams = ath9k_cmn_count_streams(ah->rxchainmask, max_streams);
214
215 ath_dbg(common, CONFIG, "TX streams %d, RX streams: %d\n",
216 tx_streams, rx_streams);
217
218 if (tx_streams != rx_streams) {
219 ht_info->mcs.tx_params |= IEEE80211_HT_MCS_TX_RX_DIFF;
220 ht_info->mcs.tx_params |= ((tx_streams - 1) <<
221 IEEE80211_HT_MCS_TX_MAX_STREAMS_SHIFT);
222 }
223
224 for (i = 0; i < rx_streams; i++)
225 ht_info->mcs.rx_mask[i] = 0xff;
226
227 ht_info->mcs.tx_params |= IEEE80211_HT_MCS_TX_DEFINED;
228 }
229 EXPORT_SYMBOL(ath9k_cmn_setup_ht_cap);
230
ath9k_cmn_reload_chainmask(struct ath_hw * ah)231 void ath9k_cmn_reload_chainmask(struct ath_hw *ah)
232 {
233 struct ath_common *common = ath9k_hw_common(ah);
234
235 if (!(ah->caps.hw_caps & ATH9K_HW_CAP_HT))
236 return;
237
238 if (ah->caps.hw_caps & ATH9K_HW_CAP_2GHZ)
239 ath9k_cmn_setup_ht_cap(ah,
240 &common->sbands[NL80211_BAND_2GHZ].ht_cap);
241 if (ah->caps.hw_caps & ATH9K_HW_CAP_5GHZ)
242 ath9k_cmn_setup_ht_cap(ah,
243 &common->sbands[NL80211_BAND_5GHZ].ht_cap);
244 }
245 EXPORT_SYMBOL(ath9k_cmn_reload_chainmask);
246