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