common-init.c 8.1 KB

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