blob: b5ac26994f19470012c9e8cf806bfb3b6d8d7344 [file] [log] [blame]
Luis R. Rodriguezdb86f072009-11-05 08:44:39 -08001/*
Sujith Manoharan5b681382011-05-17 13:36:18 +05302 * Copyright (c) 2009-2011 Atheros Communications Inc.
Luis R. Rodriguezdb86f072009-11-05 08:44:39 -08003 *
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/*
18 * Module for common driver code between ath9k and ath9k_htc
19 */
20
21#include <linux/kernel.h>
22#include <linux/module.h>
23
24#include "common.h"
25
26MODULE_AUTHOR("Atheros Communications");
27MODULE_DESCRIPTION("Shared library for Atheros wireless 802.11n LAN cards.");
28MODULE_LICENSE("Dual BSD/GPL");
29
Sujithfb9987d2010-03-17 14:25:25 +053030int ath9k_cmn_get_hw_crypto_keytype(struct sk_buff *skb)
31{
32 struct ieee80211_tx_info *tx_info = IEEE80211_SKB_CB(skb);
33
34 if (tx_info->control.hw_key) {
Johannes Berg97359d12010-08-10 09:46:38 +020035 switch (tx_info->control.hw_key->cipher) {
36 case WLAN_CIPHER_SUITE_WEP40:
37 case WLAN_CIPHER_SUITE_WEP104:
Sujithfb9987d2010-03-17 14:25:25 +053038 return ATH9K_KEY_TYPE_WEP;
Johannes Berg97359d12010-08-10 09:46:38 +020039 case WLAN_CIPHER_SUITE_TKIP:
Sujithfb9987d2010-03-17 14:25:25 +053040 return ATH9K_KEY_TYPE_TKIP;
Johannes Berg97359d12010-08-10 09:46:38 +020041 case WLAN_CIPHER_SUITE_CCMP:
Sujithfb9987d2010-03-17 14:25:25 +053042 return ATH9K_KEY_TYPE_AES;
Johannes Berg97359d12010-08-10 09:46:38 +020043 default:
44 break;
45 }
Sujithfb9987d2010-03-17 14:25:25 +053046 }
47
48 return ATH9K_KEY_TYPE_CLEAR;
49}
50EXPORT_SYMBOL(ath9k_cmn_get_hw_crypto_keytype);
51
Sujithfb9987d2010-03-17 14:25:25 +053052/*
53 * Update internal channel flags.
54 */
Felix Fietkaubabcbc22010-10-20 02:09:46 +020055void ath9k_cmn_update_ichannel(struct ath9k_channel *ichan,
Simon Wunderlich06718942013-08-16 10:46:04 +020056 struct cfg80211_chan_def *chandef)
Sujithfb9987d2010-03-17 14:25:25 +053057{
Felix Fietkau6b21fd22013-10-11 23:30:56 +020058 struct ieee80211_channel *chan = chandef->chan;
59 u16 flags = 0;
Sujithfb9987d2010-03-17 14:25:25 +053060
Felix Fietkau6b21fd22013-10-11 23:30:56 +020061 ichan->channel = chan->center_freq;
62 ichan->chan = chan;
63
64 if (chan->band == IEEE80211_BAND_5GHZ)
65 flags |= CHANNEL_5GHZ;
Sujithfb9987d2010-03-17 14:25:25 +053066
Simon Wunderlich06718942013-08-16 10:46:04 +020067 switch (chandef->width) {
68 case NL80211_CHAN_WIDTH_5:
Felix Fietkau6b21fd22013-10-11 23:30:56 +020069 flags |= CHANNEL_QUARTER;
Simon Wunderlich06718942013-08-16 10:46:04 +020070 break;
71 case NL80211_CHAN_WIDTH_10:
Felix Fietkau6b21fd22013-10-11 23:30:56 +020072 flags |= CHANNEL_HALF;
Simon Wunderlich06718942013-08-16 10:46:04 +020073 break;
74 case NL80211_CHAN_WIDTH_20_NOHT:
75 break;
76 case NL80211_CHAN_WIDTH_20:
Felix Fietkau6b21fd22013-10-11 23:30:56 +020077 flags |= CHANNEL_HT;
78 break;
Simon Wunderlich06718942013-08-16 10:46:04 +020079 case NL80211_CHAN_WIDTH_40:
Felix Fietkau6b21fd22013-10-11 23:30:56 +020080 if (chandef->center_freq1 > chandef->chan->center_freq)
81 flags |= CHANNEL_HT40PLUS | CHANNEL_HT;
82 else
83 flags |= CHANNEL_HT40MINUS | CHANNEL_HT;
Simon Wunderlich06718942013-08-16 10:46:04 +020084 break;
85 default:
86 WARN_ON(1);
87 }
Felix Fietkau6b21fd22013-10-11 23:30:56 +020088
89 ichan->channelFlags = flags;
Sujithfb9987d2010-03-17 14:25:25 +053090}
91EXPORT_SYMBOL(ath9k_cmn_update_ichannel);
92
93/*
94 * Get the internal channel reference.
95 */
96struct ath9k_channel *ath9k_cmn_get_curchannel(struct ieee80211_hw *hw,
97 struct ath_hw *ah)
98{
Karl Beldan675a0b02013-03-25 16:26:57 +010099 struct ieee80211_channel *curchan = hw->conf.chandef.chan;
Sujithfb9987d2010-03-17 14:25:25 +0530100 struct ath9k_channel *channel;
101 u8 chan_idx;
102
103 chan_idx = curchan->hw_value;
104 channel = &ah->channels[chan_idx];
Simon Wunderlich06718942013-08-16 10:46:04 +0200105 ath9k_cmn_update_ichannel(channel, &hw->conf.chandef);
Sujithfb9987d2010-03-17 14:25:25 +0530106
107 return channel;
108}
109EXPORT_SYMBOL(ath9k_cmn_get_curchannel);
110
Sujith61389f32010-06-02 15:53:37 +0530111int ath9k_cmn_count_streams(unsigned int chainmask, int max)
112{
113 int streams = 0;
114
115 do {
116 if (++streams == max)
117 break;
118 } while ((chainmask = chainmask & (chainmask - 1)));
119
120 return streams;
121}
122EXPORT_SYMBOL(ath9k_cmn_count_streams);
123
Rajkumar Manoharan5048e8c2011-01-31 23:47:44 +0530124void ath9k_cmn_update_txpow(struct ath_hw *ah, u16 cur_txpow,
125 u16 new_txpow, u16 *txpower)
126{
Felix Fietkauca2c68c2011-10-08 20:06:20 +0200127 struct ath_regulatory *reg = ath9k_hw_regulatory(ah);
128
129 if (reg->power_limit != new_txpow) {
Rajkumar Manoharan5048e8c2011-01-31 23:47:44 +0530130 ath9k_hw_set_txpowerlimit(ah, new_txpow, false);
131 /* read back in case value is clamped */
Felix Fietkauca2c68c2011-10-08 20:06:20 +0200132 *txpower = reg->max_power_level;
Rajkumar Manoharan5048e8c2011-01-31 23:47:44 +0530133 }
134}
135EXPORT_SYMBOL(ath9k_cmn_update_txpow);
136
Rajkumar Manoharanf82b4bd2011-08-13 10:28:15 +0530137void ath9k_cmn_init_crypto(struct ath_hw *ah)
138{
139 struct ath_common *common = ath9k_hw_common(ah);
140 int i = 0;
141
142 /* Get the hardware key cache size. */
143 common->keymax = AR_KEYTABLE_SIZE;
144
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 /*
155 * Reset the key cache since some parts do not
156 * reset the contents on initial power up.
157 */
158 for (i = 0; i < common->keymax; i++)
159 ath_hw_keyreset(common, (u16) i);
160}
161EXPORT_SYMBOL(ath9k_cmn_init_crypto);
162
Luis R. Rodriguezdb86f072009-11-05 08:44:39 -0800163static int __init ath9k_cmn_init(void)
164{
165 return 0;
166}
167module_init(ath9k_cmn_init);
168
169static void __exit ath9k_cmn_exit(void)
170{
171 return;
172}
173module_exit(ath9k_cmn_exit);