Luis R. Rodriguez | db86f07 | 2009-11-05 08:44:39 -0800 | [diff] [blame] | 1 | /* |
Sujith Manoharan | 5b68138 | 2011-05-17 13:36:18 +0530 | [diff] [blame] | 2 | * Copyright (c) 2009-2011 Atheros Communications Inc. |
Luis R. Rodriguez | db86f07 | 2009-11-05 08:44:39 -0800 | [diff] [blame] | 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 | |
| 26 | MODULE_AUTHOR("Atheros Communications"); |
| 27 | MODULE_DESCRIPTION("Shared library for Atheros wireless 802.11n LAN cards."); |
| 28 | MODULE_LICENSE("Dual BSD/GPL"); |
| 29 | |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 30 | int 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 Berg | 97359d1 | 2010-08-10 09:46:38 +0200 | [diff] [blame] | 35 | switch (tx_info->control.hw_key->cipher) { |
| 36 | case WLAN_CIPHER_SUITE_WEP40: |
| 37 | case WLAN_CIPHER_SUITE_WEP104: |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 38 | return ATH9K_KEY_TYPE_WEP; |
Johannes Berg | 97359d1 | 2010-08-10 09:46:38 +0200 | [diff] [blame] | 39 | case WLAN_CIPHER_SUITE_TKIP: |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 40 | return ATH9K_KEY_TYPE_TKIP; |
Johannes Berg | 97359d1 | 2010-08-10 09:46:38 +0200 | [diff] [blame] | 41 | case WLAN_CIPHER_SUITE_CCMP: |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 42 | return ATH9K_KEY_TYPE_AES; |
Johannes Berg | 97359d1 | 2010-08-10 09:46:38 +0200 | [diff] [blame] | 43 | default: |
| 44 | break; |
| 45 | } |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 46 | } |
| 47 | |
| 48 | return ATH9K_KEY_TYPE_CLEAR; |
| 49 | } |
| 50 | EXPORT_SYMBOL(ath9k_cmn_get_hw_crypto_keytype); |
| 51 | |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 52 | /* |
| 53 | * Update internal channel flags. |
| 54 | */ |
Felix Fietkau | 2297f1c | 2013-10-11 23:30:57 +0200 | [diff] [blame] | 55 | static void ath9k_cmn_update_ichannel(struct ath9k_channel *ichan, |
| 56 | struct cfg80211_chan_def *chandef) |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 57 | { |
Felix Fietkau | 6b21fd2 | 2013-10-11 23:30:56 +0200 | [diff] [blame] | 58 | struct ieee80211_channel *chan = chandef->chan; |
| 59 | u16 flags = 0; |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 60 | |
Felix Fietkau | 6b21fd2 | 2013-10-11 23:30:56 +0200 | [diff] [blame] | 61 | ichan->channel = chan->center_freq; |
| 62 | ichan->chan = chan; |
| 63 | |
| 64 | if (chan->band == IEEE80211_BAND_5GHZ) |
| 65 | flags |= CHANNEL_5GHZ; |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 66 | |
Simon Wunderlich | 0671894 | 2013-08-16 10:46:04 +0200 | [diff] [blame] | 67 | switch (chandef->width) { |
| 68 | case NL80211_CHAN_WIDTH_5: |
Felix Fietkau | 6b21fd2 | 2013-10-11 23:30:56 +0200 | [diff] [blame] | 69 | flags |= CHANNEL_QUARTER; |
Simon Wunderlich | 0671894 | 2013-08-16 10:46:04 +0200 | [diff] [blame] | 70 | break; |
| 71 | case NL80211_CHAN_WIDTH_10: |
Felix Fietkau | 6b21fd2 | 2013-10-11 23:30:56 +0200 | [diff] [blame] | 72 | flags |= CHANNEL_HALF; |
Simon Wunderlich | 0671894 | 2013-08-16 10:46:04 +0200 | [diff] [blame] | 73 | break; |
| 74 | case NL80211_CHAN_WIDTH_20_NOHT: |
| 75 | break; |
| 76 | case NL80211_CHAN_WIDTH_20: |
Felix Fietkau | 6b21fd2 | 2013-10-11 23:30:56 +0200 | [diff] [blame] | 77 | flags |= CHANNEL_HT; |
| 78 | break; |
Simon Wunderlich | 0671894 | 2013-08-16 10:46:04 +0200 | [diff] [blame] | 79 | case NL80211_CHAN_WIDTH_40: |
Felix Fietkau | 6b21fd2 | 2013-10-11 23:30:56 +0200 | [diff] [blame] | 80 | if (chandef->center_freq1 > chandef->chan->center_freq) |
| 81 | flags |= CHANNEL_HT40PLUS | CHANNEL_HT; |
| 82 | else |
| 83 | flags |= CHANNEL_HT40MINUS | CHANNEL_HT; |
Simon Wunderlich | 0671894 | 2013-08-16 10:46:04 +0200 | [diff] [blame] | 84 | break; |
| 85 | default: |
| 86 | WARN_ON(1); |
| 87 | } |
Felix Fietkau | 6b21fd2 | 2013-10-11 23:30:56 +0200 | [diff] [blame] | 88 | |
| 89 | ichan->channelFlags = flags; |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 90 | } |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 91 | |
| 92 | /* |
| 93 | * Get the internal channel reference. |
| 94 | */ |
Felix Fietkau | 2297f1c | 2013-10-11 23:30:57 +0200 | [diff] [blame] | 95 | struct ath9k_channel *ath9k_cmn_get_channel(struct ieee80211_hw *hw, |
| 96 | struct ath_hw *ah, |
| 97 | struct cfg80211_chan_def *chandef) |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 98 | { |
Felix Fietkau | 2297f1c | 2013-10-11 23:30:57 +0200 | [diff] [blame] | 99 | struct ieee80211_channel *curchan = chandef->chan; |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 100 | struct ath9k_channel *channel; |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 101 | |
Felix Fietkau | f40c460 | 2013-12-14 18:03:35 +0100 | [diff] [blame^] | 102 | channel = &ah->channels[curchan->hw_value]; |
Felix Fietkau | 2297f1c | 2013-10-11 23:30:57 +0200 | [diff] [blame] | 103 | ath9k_cmn_update_ichannel(channel, chandef); |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 104 | |
| 105 | return channel; |
| 106 | } |
Felix Fietkau | 2297f1c | 2013-10-11 23:30:57 +0200 | [diff] [blame] | 107 | EXPORT_SYMBOL(ath9k_cmn_get_channel); |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 108 | |
Sujith | 61389f3 | 2010-06-02 15:53:37 +0530 | [diff] [blame] | 109 | int ath9k_cmn_count_streams(unsigned int chainmask, int max) |
| 110 | { |
| 111 | int streams = 0; |
| 112 | |
| 113 | do { |
| 114 | if (++streams == max) |
| 115 | break; |
| 116 | } while ((chainmask = chainmask & (chainmask - 1))); |
| 117 | |
| 118 | return streams; |
| 119 | } |
| 120 | EXPORT_SYMBOL(ath9k_cmn_count_streams); |
| 121 | |
Rajkumar Manoharan | 5048e8c | 2011-01-31 23:47:44 +0530 | [diff] [blame] | 122 | void ath9k_cmn_update_txpow(struct ath_hw *ah, u16 cur_txpow, |
| 123 | u16 new_txpow, u16 *txpower) |
| 124 | { |
Felix Fietkau | ca2c68c | 2011-10-08 20:06:20 +0200 | [diff] [blame] | 125 | struct ath_regulatory *reg = ath9k_hw_regulatory(ah); |
| 126 | |
| 127 | if (reg->power_limit != new_txpow) { |
Rajkumar Manoharan | 5048e8c | 2011-01-31 23:47:44 +0530 | [diff] [blame] | 128 | ath9k_hw_set_txpowerlimit(ah, new_txpow, false); |
| 129 | /* read back in case value is clamped */ |
Felix Fietkau | ca2c68c | 2011-10-08 20:06:20 +0200 | [diff] [blame] | 130 | *txpower = reg->max_power_level; |
Rajkumar Manoharan | 5048e8c | 2011-01-31 23:47:44 +0530 | [diff] [blame] | 131 | } |
| 132 | } |
| 133 | EXPORT_SYMBOL(ath9k_cmn_update_txpow); |
| 134 | |
Rajkumar Manoharan | f82b4bd | 2011-08-13 10:28:15 +0530 | [diff] [blame] | 135 | void ath9k_cmn_init_crypto(struct ath_hw *ah) |
| 136 | { |
| 137 | struct ath_common *common = ath9k_hw_common(ah); |
| 138 | int i = 0; |
| 139 | |
| 140 | /* Get the hardware key cache size. */ |
| 141 | common->keymax = AR_KEYTABLE_SIZE; |
| 142 | |
| 143 | /* |
| 144 | * Check whether the separate key cache entries |
| 145 | * are required to handle both tx+rx MIC keys. |
| 146 | * With split mic keys the number of stations is limited |
| 147 | * to 27 otherwise 59. |
| 148 | */ |
| 149 | if (ah->misc_mode & AR_PCU_MIC_NEW_LOC_ENA) |
| 150 | common->crypt_caps |= ATH_CRYPT_CAP_MIC_COMBINED; |
| 151 | |
| 152 | /* |
| 153 | * Reset the key cache since some parts do not |
| 154 | * reset the contents on initial power up. |
| 155 | */ |
| 156 | for (i = 0; i < common->keymax; i++) |
| 157 | ath_hw_keyreset(common, (u16) i); |
| 158 | } |
| 159 | EXPORT_SYMBOL(ath9k_cmn_init_crypto); |
| 160 | |
Luis R. Rodriguez | db86f07 | 2009-11-05 08:44:39 -0800 | [diff] [blame] | 161 | static int __init ath9k_cmn_init(void) |
| 162 | { |
| 163 | return 0; |
| 164 | } |
| 165 | module_init(ath9k_cmn_init); |
| 166 | |
| 167 | static void __exit ath9k_cmn_exit(void) |
| 168 | { |
| 169 | return; |
| 170 | } |
| 171 | module_exit(ath9k_cmn_exit); |