common-init.c 8.0 KB

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