common.c 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  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. /*
  45. * Update internal channel flags.
  46. */
  47. static void ath9k_cmn_update_ichannel(struct ath9k_channel *ichan,
  48. struct cfg80211_chan_def *chandef)
  49. {
  50. struct ieee80211_channel *chan = chandef->chan;
  51. u16 flags = 0;
  52. ichan->channel = chan->center_freq;
  53. ichan->chan = chan;
  54. if (chan->band == IEEE80211_BAND_5GHZ)
  55. flags |= CHANNEL_5GHZ;
  56. switch (chandef->width) {
  57. case NL80211_CHAN_WIDTH_5:
  58. flags |= CHANNEL_QUARTER;
  59. break;
  60. case NL80211_CHAN_WIDTH_10:
  61. flags |= CHANNEL_HALF;
  62. break;
  63. case NL80211_CHAN_WIDTH_20_NOHT:
  64. break;
  65. case NL80211_CHAN_WIDTH_20:
  66. flags |= CHANNEL_HT;
  67. break;
  68. case NL80211_CHAN_WIDTH_40:
  69. if (chandef->center_freq1 > chandef->chan->center_freq)
  70. flags |= CHANNEL_HT40PLUS | CHANNEL_HT;
  71. else
  72. flags |= CHANNEL_HT40MINUS | CHANNEL_HT;
  73. break;
  74. default:
  75. WARN_ON(1);
  76. }
  77. ichan->channelFlags = flags;
  78. }
  79. /*
  80. * Get the internal channel reference.
  81. */
  82. struct ath9k_channel *ath9k_cmn_get_channel(struct ieee80211_hw *hw,
  83. struct ath_hw *ah,
  84. struct cfg80211_chan_def *chandef)
  85. {
  86. struct ieee80211_channel *curchan = chandef->chan;
  87. struct ath9k_channel *channel;
  88. u8 chan_idx;
  89. chan_idx = curchan->hw_value;
  90. channel = &ah->channels[chan_idx];
  91. ath9k_cmn_update_ichannel(channel, chandef);
  92. return channel;
  93. }
  94. EXPORT_SYMBOL(ath9k_cmn_get_channel);
  95. int ath9k_cmn_count_streams(unsigned int chainmask, int max)
  96. {
  97. int streams = 0;
  98. do {
  99. if (++streams == max)
  100. break;
  101. } while ((chainmask = chainmask & (chainmask - 1)));
  102. return streams;
  103. }
  104. EXPORT_SYMBOL(ath9k_cmn_count_streams);
  105. void ath9k_cmn_update_txpow(struct ath_hw *ah, u16 cur_txpow,
  106. u16 new_txpow, u16 *txpower)
  107. {
  108. struct ath_regulatory *reg = ath9k_hw_regulatory(ah);
  109. if (reg->power_limit != new_txpow) {
  110. ath9k_hw_set_txpowerlimit(ah, new_txpow, false);
  111. /* read back in case value is clamped */
  112. *txpower = reg->max_power_level;
  113. }
  114. }
  115. EXPORT_SYMBOL(ath9k_cmn_update_txpow);
  116. void ath9k_cmn_init_crypto(struct ath_hw *ah)
  117. {
  118. struct ath_common *common = ath9k_hw_common(ah);
  119. int i = 0;
  120. /* Get the hardware key cache size. */
  121. common->keymax = AR_KEYTABLE_SIZE;
  122. /*
  123. * Check whether the separate key cache entries
  124. * are required to handle both tx+rx MIC keys.
  125. * With split mic keys the number of stations is limited
  126. * to 27 otherwise 59.
  127. */
  128. if (ah->misc_mode & AR_PCU_MIC_NEW_LOC_ENA)
  129. common->crypt_caps |= ATH_CRYPT_CAP_MIC_COMBINED;
  130. /*
  131. * Reset the key cache since some parts do not
  132. * reset the contents on initial power up.
  133. */
  134. for (i = 0; i < common->keymax; i++)
  135. ath_hw_keyreset(common, (u16) i);
  136. }
  137. EXPORT_SYMBOL(ath9k_cmn_init_crypto);
  138. static int __init ath9k_cmn_init(void)
  139. {
  140. return 0;
  141. }
  142. module_init(ath9k_cmn_init);
  143. static void __exit ath9k_cmn_exit(void)
  144. {
  145. return;
  146. }
  147. module_exit(ath9k_cmn_exit);