2 * Copyright (c) 2009-2011 Atheros Communications Inc.
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.
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.
18 * Module for common driver code between ath9k and ath9k_htc
21 #include <linux/kernel.h>
22 #include <linux/module.h>
26 MODULE_AUTHOR("Atheros Communications");
27 MODULE_DESCRIPTION("Shared library for Atheros wireless 802.11n LAN cards.");
28 MODULE_LICENSE("Dual BSD/GPL");
30 int ath9k_cmn_get_hw_crypto_keytype(struct sk_buff *skb)
32 struct ieee80211_tx_info *tx_info = IEEE80211_SKB_CB(skb);
34 if (tx_info->control.hw_key) {
35 switch (tx_info->control.hw_key->cipher) {
36 case WLAN_CIPHER_SUITE_WEP40:
37 case WLAN_CIPHER_SUITE_WEP104:
38 return ATH9K_KEY_TYPE_WEP;
39 case WLAN_CIPHER_SUITE_TKIP:
40 return ATH9K_KEY_TYPE_TKIP;
41 case WLAN_CIPHER_SUITE_CCMP:
42 return ATH9K_KEY_TYPE_AES;
48 return ATH9K_KEY_TYPE_CLEAR;
50 EXPORT_SYMBOL(ath9k_cmn_get_hw_crypto_keytype);
53 * Update internal channel flags.
55 static void ath9k_cmn_update_ichannel(struct ath9k_channel *ichan,
56 struct cfg80211_chan_def *chandef)
58 struct ieee80211_channel *chan = chandef->chan;
61 ichan->channel = chan->center_freq;
64 if (chan->band == IEEE80211_BAND_5GHZ)
65 flags |= CHANNEL_5GHZ;
67 switch (chandef->width) {
68 case NL80211_CHAN_WIDTH_5:
69 flags |= CHANNEL_QUARTER;
71 case NL80211_CHAN_WIDTH_10:
72 flags |= CHANNEL_HALF;
74 case NL80211_CHAN_WIDTH_20_NOHT:
76 case NL80211_CHAN_WIDTH_20:
79 case NL80211_CHAN_WIDTH_40:
80 if (chandef->center_freq1 > chandef->chan->center_freq)
81 flags |= CHANNEL_HT40PLUS | CHANNEL_HT;
83 flags |= CHANNEL_HT40MINUS | CHANNEL_HT;
89 ichan->channelFlags = flags;
93 * Get the internal channel reference.
95 struct ath9k_channel *ath9k_cmn_get_channel(struct ieee80211_hw *hw,
97 struct cfg80211_chan_def *chandef)
99 struct ieee80211_channel *curchan = chandef->chan;
100 struct ath9k_channel *channel;
103 chan_idx = curchan->hw_value;
104 channel = &ah->channels[chan_idx];
105 ath9k_cmn_update_ichannel(channel, chandef);
109 EXPORT_SYMBOL(ath9k_cmn_get_channel);
111 int ath9k_cmn_count_streams(unsigned int chainmask, int max)
116 if (++streams == max)
118 } while ((chainmask = chainmask & (chainmask - 1)));
122 EXPORT_SYMBOL(ath9k_cmn_count_streams);
124 void ath9k_cmn_update_txpow(struct ath_hw *ah, u16 cur_txpow,
125 u16 new_txpow, u16 *txpower)
127 struct ath_regulatory *reg = ath9k_hw_regulatory(ah);
129 if (reg->power_limit != new_txpow) {
130 ath9k_hw_set_txpowerlimit(ah, new_txpow, false);
131 /* read back in case value is clamped */
132 *txpower = reg->max_power_level;
135 EXPORT_SYMBOL(ath9k_cmn_update_txpow);
137 void ath9k_cmn_init_crypto(struct ath_hw *ah)
139 struct ath_common *common = ath9k_hw_common(ah);
142 /* Get the hardware key cache size. */
143 common->keymax = AR_KEYTABLE_SIZE;
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.
151 if (ah->misc_mode & AR_PCU_MIC_NEW_LOC_ENA)
152 common->crypt_caps |= ATH_CRYPT_CAP_MIC_COMBINED;
155 * Reset the key cache since some parts do not
156 * reset the contents on initial power up.
158 for (i = 0; i < common->keymax; i++)
159 ath_hw_keyreset(common, (u16) i);
161 EXPORT_SYMBOL(ath9k_cmn_init_crypto);
163 static int __init ath9k_cmn_init(void)
167 module_init(ath9k_cmn_init);
169 static void __exit ath9k_cmn_exit(void)
173 module_exit(ath9k_cmn_exit);