common.c 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  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 ieee80211_channel *chan,
  45. enum nl80211_channel_type channel_type)
  46. {
  47. u32 chanmode = 0;
  48. switch (chan->band) {
  49. case IEEE80211_BAND_2GHZ:
  50. switch (channel_type) {
  51. case NL80211_CHAN_NO_HT:
  52. case NL80211_CHAN_HT20:
  53. chanmode = CHANNEL_G_HT20;
  54. break;
  55. case NL80211_CHAN_HT40PLUS:
  56. chanmode = CHANNEL_G_HT40PLUS;
  57. break;
  58. case NL80211_CHAN_HT40MINUS:
  59. chanmode = CHANNEL_G_HT40MINUS;
  60. break;
  61. }
  62. break;
  63. case IEEE80211_BAND_5GHZ:
  64. switch (channel_type) {
  65. case NL80211_CHAN_NO_HT:
  66. case NL80211_CHAN_HT20:
  67. chanmode = CHANNEL_A_HT20;
  68. break;
  69. case NL80211_CHAN_HT40PLUS:
  70. chanmode = CHANNEL_A_HT40PLUS;
  71. break;
  72. case NL80211_CHAN_HT40MINUS:
  73. chanmode = CHANNEL_A_HT40MINUS;
  74. break;
  75. }
  76. break;
  77. default:
  78. break;
  79. }
  80. return chanmode;
  81. }
  82. /*
  83. * Update internal channel flags.
  84. */
  85. void ath9k_cmn_update_ichannel(struct ath9k_channel *ichan,
  86. struct ieee80211_channel *chan,
  87. enum nl80211_channel_type channel_type)
  88. {
  89. ichan->channel = chan->center_freq;
  90. ichan->chan = chan;
  91. if (chan->band == IEEE80211_BAND_2GHZ) {
  92. ichan->chanmode = CHANNEL_G;
  93. ichan->channelFlags = CHANNEL_2GHZ | CHANNEL_OFDM;
  94. } else {
  95. ichan->chanmode = CHANNEL_A;
  96. ichan->channelFlags = CHANNEL_5GHZ | CHANNEL_OFDM;
  97. }
  98. if (channel_type != NL80211_CHAN_NO_HT)
  99. ichan->chanmode = ath9k_get_extchanmode(chan, channel_type);
  100. }
  101. EXPORT_SYMBOL(ath9k_cmn_update_ichannel);
  102. /*
  103. * Get the internal channel reference.
  104. */
  105. struct ath9k_channel *ath9k_cmn_get_curchannel(struct ieee80211_hw *hw,
  106. struct ath_hw *ah)
  107. {
  108. struct ieee80211_channel *curchan = hw->conf.chandef.chan;
  109. struct ath9k_channel *channel;
  110. u8 chan_idx;
  111. chan_idx = curchan->hw_value;
  112. channel = &ah->channels[chan_idx];
  113. ath9k_cmn_update_ichannel(channel, curchan,
  114. cfg80211_get_chandef_type(&hw->conf.chandef));
  115. return channel;
  116. }
  117. EXPORT_SYMBOL(ath9k_cmn_get_curchannel);
  118. int ath9k_cmn_count_streams(unsigned int chainmask, int max)
  119. {
  120. int streams = 0;
  121. do {
  122. if (++streams == max)
  123. break;
  124. } while ((chainmask = chainmask & (chainmask - 1)));
  125. return streams;
  126. }
  127. EXPORT_SYMBOL(ath9k_cmn_count_streams);
  128. void ath9k_cmn_update_txpow(struct ath_hw *ah, u16 cur_txpow,
  129. u16 new_txpow, u16 *txpower)
  130. {
  131. struct ath_regulatory *reg = ath9k_hw_regulatory(ah);
  132. if (reg->power_limit != new_txpow) {
  133. ath9k_hw_set_txpowerlimit(ah, new_txpow, false);
  134. /* read back in case value is clamped */
  135. *txpower = reg->max_power_level;
  136. }
  137. }
  138. EXPORT_SYMBOL(ath9k_cmn_update_txpow);
  139. void ath9k_cmn_init_crypto(struct ath_hw *ah)
  140. {
  141. struct ath_common *common = ath9k_hw_common(ah);
  142. int i = 0;
  143. /* Get the hardware key cache size. */
  144. common->keymax = AR_KEYTABLE_SIZE;
  145. /*
  146. * Check whether the separate key cache entries
  147. * are required to handle both tx+rx MIC keys.
  148. * With split mic keys the number of stations is limited
  149. * to 27 otherwise 59.
  150. */
  151. if (ah->misc_mode & AR_PCU_MIC_NEW_LOC_ENA)
  152. common->crypt_caps |= ATH_CRYPT_CAP_MIC_COMBINED;
  153. /*
  154. * Reset the key cache since some parts do not
  155. * reset the contents on initial power up.
  156. */
  157. for (i = 0; i < common->keymax; i++)
  158. ath_hw_keyreset(common, (u16) i);
  159. }
  160. EXPORT_SYMBOL(ath9k_cmn_init_crypto);
  161. static int __init ath9k_cmn_init(void)
  162. {
  163. return 0;
  164. }
  165. module_init(ath9k_cmn_init);
  166. static void __exit ath9k_cmn_exit(void)
  167. {
  168. return;
  169. }
  170. module_exit(ath9k_cmn_exit);