common.c 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  1. /*
  2. * Copyright (c) 2009 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_padpos(__le16 frame_control)
  26. {
  27. int padpos = 24;
  28. if (ieee80211_has_a4(frame_control)) {
  29. padpos += ETH_ALEN;
  30. }
  31. if (ieee80211_is_data_qos(frame_control)) {
  32. padpos += IEEE80211_QOS_CTL_LEN;
  33. }
  34. return padpos;
  35. }
  36. EXPORT_SYMBOL(ath9k_cmn_padpos);
  37. int ath9k_cmn_get_hw_crypto_keytype(struct sk_buff *skb)
  38. {
  39. struct ieee80211_tx_info *tx_info = IEEE80211_SKB_CB(skb);
  40. if (tx_info->control.hw_key) {
  41. switch (tx_info->control.hw_key->cipher) {
  42. case WLAN_CIPHER_SUITE_WEP40:
  43. case WLAN_CIPHER_SUITE_WEP104:
  44. return ATH9K_KEY_TYPE_WEP;
  45. case WLAN_CIPHER_SUITE_TKIP:
  46. return ATH9K_KEY_TYPE_TKIP;
  47. case WLAN_CIPHER_SUITE_CCMP:
  48. return ATH9K_KEY_TYPE_AES;
  49. default:
  50. break;
  51. }
  52. }
  53. return ATH9K_KEY_TYPE_CLEAR;
  54. }
  55. EXPORT_SYMBOL(ath9k_cmn_get_hw_crypto_keytype);
  56. static u32 ath9k_get_extchanmode(struct ieee80211_channel *chan,
  57. enum nl80211_channel_type channel_type)
  58. {
  59. u32 chanmode = 0;
  60. switch (chan->band) {
  61. case IEEE80211_BAND_2GHZ:
  62. switch (channel_type) {
  63. case NL80211_CHAN_NO_HT:
  64. case NL80211_CHAN_HT20:
  65. chanmode = CHANNEL_G_HT20;
  66. break;
  67. case NL80211_CHAN_HT40PLUS:
  68. chanmode = CHANNEL_G_HT40PLUS;
  69. break;
  70. case NL80211_CHAN_HT40MINUS:
  71. chanmode = CHANNEL_G_HT40MINUS;
  72. break;
  73. }
  74. break;
  75. case IEEE80211_BAND_5GHZ:
  76. switch (channel_type) {
  77. case NL80211_CHAN_NO_HT:
  78. case NL80211_CHAN_HT20:
  79. chanmode = CHANNEL_A_HT20;
  80. break;
  81. case NL80211_CHAN_HT40PLUS:
  82. chanmode = CHANNEL_A_HT40PLUS;
  83. break;
  84. case NL80211_CHAN_HT40MINUS:
  85. chanmode = CHANNEL_A_HT40MINUS;
  86. break;
  87. }
  88. break;
  89. default:
  90. break;
  91. }
  92. return chanmode;
  93. }
  94. /*
  95. * Update internal channel flags.
  96. */
  97. void ath9k_cmn_update_ichannel(struct ieee80211_hw *hw,
  98. struct ath9k_channel *ichan)
  99. {
  100. struct ieee80211_channel *chan = hw->conf.channel;
  101. struct ieee80211_conf *conf = &hw->conf;
  102. ichan->channel = chan->center_freq;
  103. ichan->chan = chan;
  104. if (chan->band == IEEE80211_BAND_2GHZ) {
  105. ichan->chanmode = CHANNEL_G;
  106. ichan->channelFlags = CHANNEL_2GHZ | CHANNEL_OFDM | CHANNEL_G;
  107. } else {
  108. ichan->chanmode = CHANNEL_A;
  109. ichan->channelFlags = CHANNEL_5GHZ | CHANNEL_OFDM;
  110. }
  111. if (conf_is_ht(conf))
  112. ichan->chanmode = ath9k_get_extchanmode(chan,
  113. conf->channel_type);
  114. }
  115. EXPORT_SYMBOL(ath9k_cmn_update_ichannel);
  116. /*
  117. * Get the internal channel reference.
  118. */
  119. struct ath9k_channel *ath9k_cmn_get_curchannel(struct ieee80211_hw *hw,
  120. struct ath_hw *ah)
  121. {
  122. struct ieee80211_channel *curchan = hw->conf.channel;
  123. struct ath9k_channel *channel;
  124. u8 chan_idx;
  125. chan_idx = curchan->hw_value;
  126. channel = &ah->channels[chan_idx];
  127. ath9k_cmn_update_ichannel(hw, channel);
  128. return channel;
  129. }
  130. EXPORT_SYMBOL(ath9k_cmn_get_curchannel);
  131. int ath9k_cmn_count_streams(unsigned int chainmask, int max)
  132. {
  133. int streams = 0;
  134. do {
  135. if (++streams == max)
  136. break;
  137. } while ((chainmask = chainmask & (chainmask - 1)));
  138. return streams;
  139. }
  140. EXPORT_SYMBOL(ath9k_cmn_count_streams);
  141. /*
  142. * Configures appropriate weight based on stomp type.
  143. */
  144. void ath9k_cmn_btcoex_bt_stomp(struct ath_common *common,
  145. enum ath_stomp_type stomp_type)
  146. {
  147. struct ath_hw *ah = common->ah;
  148. switch (stomp_type) {
  149. case ATH_BTCOEX_STOMP_ALL:
  150. ath9k_hw_btcoex_set_weight(ah, AR_BT_COEX_WGHT,
  151. AR_STOMP_ALL_WLAN_WGHT);
  152. break;
  153. case ATH_BTCOEX_STOMP_LOW:
  154. ath9k_hw_btcoex_set_weight(ah, AR_BT_COEX_WGHT,
  155. AR_STOMP_LOW_WLAN_WGHT);
  156. break;
  157. case ATH_BTCOEX_STOMP_NONE:
  158. ath9k_hw_btcoex_set_weight(ah, AR_BT_COEX_WGHT,
  159. AR_STOMP_NONE_WLAN_WGHT);
  160. break;
  161. default:
  162. ath_print(common, ATH_DBG_BTCOEX,
  163. "Invalid Stomptype\n");
  164. break;
  165. }
  166. ath9k_hw_btcoex_enable(ah);
  167. }
  168. EXPORT_SYMBOL(ath9k_cmn_btcoex_bt_stomp);
  169. static int __init ath9k_cmn_init(void)
  170. {
  171. return 0;
  172. }
  173. module_init(ath9k_cmn_init);
  174. static void __exit ath9k_cmn_exit(void)
  175. {
  176. return;
  177. }
  178. module_exit(ath9k_cmn_exit);