common.c 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  1. /*
  2. * Copyright (c) 2009-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. * Module for common driver code between ath9k and ath9k_htc
  18. */
  19. #include <linux/kernel.h>
  20. #include <linux/module.h>
  21. #include "common.h"
  22. MODULE_AUTHOR("Atheros Communications");
  23. MODULE_DESCRIPTION("Shared library for Atheros wireless 802.11n LAN cards.");
  24. MODULE_LICENSE("Dual BSD/GPL");
  25. int ath9k_cmn_get_hw_crypto_keytype(struct sk_buff *skb)
  26. {
  27. struct ieee80211_tx_info *tx_info = IEEE80211_SKB_CB(skb);
  28. if (tx_info->control.hw_key) {
  29. switch (tx_info->control.hw_key->cipher) {
  30. case WLAN_CIPHER_SUITE_WEP40:
  31. case WLAN_CIPHER_SUITE_WEP104:
  32. return ATH9K_KEY_TYPE_WEP;
  33. case WLAN_CIPHER_SUITE_TKIP:
  34. return ATH9K_KEY_TYPE_TKIP;
  35. case WLAN_CIPHER_SUITE_CCMP:
  36. return ATH9K_KEY_TYPE_AES;
  37. default:
  38. break;
  39. }
  40. }
  41. return ATH9K_KEY_TYPE_CLEAR;
  42. }
  43. EXPORT_SYMBOL(ath9k_cmn_get_hw_crypto_keytype);
  44. static u32 ath9k_get_extchanmode(struct cfg80211_chan_def *chandef)
  45. {
  46. u32 chanmode = 0;
  47. switch (chandef->chan->band) {
  48. case IEEE80211_BAND_2GHZ:
  49. switch (chandef->width) {
  50. case NL80211_CHAN_WIDTH_20_NOHT:
  51. case NL80211_CHAN_WIDTH_20:
  52. chanmode = CHANNEL_G_HT20;
  53. break;
  54. case NL80211_CHAN_WIDTH_40:
  55. if (chandef->center_freq1 > chandef->chan->center_freq)
  56. chanmode = CHANNEL_G_HT40PLUS;
  57. else
  58. chanmode = CHANNEL_G_HT40MINUS;
  59. break;
  60. default:
  61. break;
  62. }
  63. break;
  64. case IEEE80211_BAND_5GHZ:
  65. switch (chandef->width) {
  66. case NL80211_CHAN_WIDTH_20_NOHT:
  67. case NL80211_CHAN_WIDTH_20:
  68. chanmode = CHANNEL_A_HT20;
  69. break;
  70. case NL80211_CHAN_WIDTH_40:
  71. if (chandef->center_freq1 > chandef->chan->center_freq)
  72. chanmode = CHANNEL_A_HT40PLUS;
  73. else
  74. chanmode = CHANNEL_A_HT40MINUS;
  75. break;
  76. default:
  77. break;
  78. }
  79. break;
  80. default:
  81. break;
  82. }
  83. return chanmode;
  84. }
  85. /*
  86. * Update internal channel flags.
  87. */
  88. void ath9k_cmn_update_ichannel(struct ath9k_channel *ichan,
  89. struct cfg80211_chan_def *chandef)
  90. {
  91. ichan->channel = chandef->chan->center_freq;
  92. ichan->chan = chandef->chan;
  93. if (chandef->chan->band == IEEE80211_BAND_2GHZ) {
  94. ichan->chanmode = CHANNEL_G;
  95. ichan->channelFlags = CHANNEL_2GHZ | CHANNEL_OFDM;
  96. } else {
  97. ichan->chanmode = CHANNEL_A;
  98. ichan->channelFlags = CHANNEL_5GHZ | CHANNEL_OFDM;
  99. }
  100. switch (chandef->width) {
  101. case NL80211_CHAN_WIDTH_5:
  102. ichan->channelFlags |= CHANNEL_QUARTER;
  103. break;
  104. case NL80211_CHAN_WIDTH_10:
  105. ichan->channelFlags |= CHANNEL_HALF;
  106. break;
  107. case NL80211_CHAN_WIDTH_20_NOHT:
  108. break;
  109. case NL80211_CHAN_WIDTH_20:
  110. case NL80211_CHAN_WIDTH_40:
  111. ichan->chanmode = ath9k_get_extchanmode(chandef);
  112. break;
  113. default:
  114. WARN_ON(1);
  115. }
  116. }
  117. EXPORT_SYMBOL(ath9k_cmn_update_ichannel);
  118. /*
  119. * Get the internal channel reference.
  120. */
  121. struct ath9k_channel *ath9k_cmn_get_curchannel(struct ieee80211_hw *hw,
  122. struct ath_hw *ah)
  123. {
  124. struct ieee80211_channel *curchan = hw->conf.chandef.chan;
  125. struct ath9k_channel *channel;
  126. u8 chan_idx;
  127. chan_idx = curchan->hw_value;
  128. channel = &ah->channels[chan_idx];
  129. ath9k_cmn_update_ichannel(channel, &hw->conf.chandef);
  130. return channel;
  131. }
  132. EXPORT_SYMBOL(ath9k_cmn_get_curchannel);
  133. int ath9k_cmn_count_streams(unsigned int chainmask, int max)
  134. {
  135. int streams = 0;
  136. do {
  137. if (++streams == max)
  138. break;
  139. } while ((chainmask = chainmask & (chainmask - 1)));
  140. return streams;
  141. }
  142. EXPORT_SYMBOL(ath9k_cmn_count_streams);
  143. void ath9k_cmn_update_txpow(struct ath_hw *ah, u16 cur_txpow,
  144. u16 new_txpow, u16 *txpower)
  145. {
  146. struct ath_regulatory *reg = ath9k_hw_regulatory(ah);
  147. if (reg->power_limit != new_txpow) {
  148. ath9k_hw_set_txpowerlimit(ah, new_txpow, false);
  149. /* read back in case value is clamped */
  150. *txpower = reg->max_power_level;
  151. }
  152. }
  153. EXPORT_SYMBOL(ath9k_cmn_update_txpow);
  154. void ath9k_cmn_init_crypto(struct ath_hw *ah)
  155. {
  156. struct ath_common *common = ath9k_hw_common(ah);
  157. int i = 0;
  158. /* Get the hardware key cache size. */
  159. common->keymax = AR_KEYTABLE_SIZE;
  160. /*
  161. * Check whether the separate key cache entries
  162. * are required to handle both tx+rx MIC keys.
  163. * With split mic keys the number of stations is limited
  164. * to 27 otherwise 59.
  165. */
  166. if (ah->misc_mode & AR_PCU_MIC_NEW_LOC_ENA)
  167. common->crypt_caps |= ATH_CRYPT_CAP_MIC_COMBINED;
  168. /*
  169. * Reset the key cache since some parts do not
  170. * reset the contents on initial power up.
  171. */
  172. for (i = 0; i < common->keymax; i++)
  173. ath_hw_keyreset(common, (u16) i);
  174. }
  175. EXPORT_SYMBOL(ath9k_cmn_init_crypto);
  176. static int __init ath9k_cmn_init(void)
  177. {
  178. return 0;
  179. }
  180. module_init(ath9k_cmn_init);
  181. static void __exit ath9k_cmn_exit(void)
  182. {
  183. return;
  184. }
  185. module_exit(ath9k_cmn_exit);