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 | |
Oleksij Rempel | 32efb0c | 2014-02-04 10:27:39 +0100 | [diff] [blame^] | 30 | void ath9k_cmn_process_rssi(struct ath_common *common, |
| 31 | struct ieee80211_hw *hw, |
| 32 | struct ath_rx_status *rx_stats, |
| 33 | struct ieee80211_rx_status *rxs) |
| 34 | { |
| 35 | struct ath_hw *ah = common->ah; |
| 36 | int last_rssi; |
| 37 | int rssi = rx_stats->rs_rssi; |
| 38 | int i, j; |
| 39 | |
| 40 | /* |
| 41 | * RSSI is not available for subframes in an A-MPDU. |
| 42 | */ |
| 43 | if (rx_stats->rs_moreaggr) { |
| 44 | rxs->flag |= RX_FLAG_NO_SIGNAL_VAL; |
| 45 | return; |
| 46 | } |
| 47 | |
| 48 | /* |
| 49 | * Check if the RSSI for the last subframe in an A-MPDU |
| 50 | * or an unaggregated frame is valid. |
| 51 | */ |
| 52 | if (rx_stats->rs_rssi == ATH9K_RSSI_BAD) { |
| 53 | rxs->flag |= RX_FLAG_NO_SIGNAL_VAL; |
| 54 | return; |
| 55 | } |
| 56 | |
| 57 | for (i = 0, j = 0; i < ARRAY_SIZE(rx_stats->rs_rssi_ctl); i++) { |
| 58 | s8 rssi; |
| 59 | |
| 60 | if (!(ah->rxchainmask & BIT(i))) |
| 61 | continue; |
| 62 | |
| 63 | rssi = rx_stats->rs_rssi_ctl[i]; |
| 64 | if (rssi != ATH9K_RSSI_BAD) { |
| 65 | rxs->chains |= BIT(j); |
| 66 | rxs->chain_signal[j] = ah->noise + rssi; |
| 67 | } |
| 68 | j++; |
| 69 | } |
| 70 | |
| 71 | /* |
| 72 | * Update Beacon RSSI, this is used by ANI. |
| 73 | */ |
| 74 | if (rx_stats->is_mybeacon && |
| 75 | ((ah->opmode == NL80211_IFTYPE_STATION) || |
| 76 | (ah->opmode == NL80211_IFTYPE_ADHOC))) { |
| 77 | ATH_RSSI_LPF(common->last_rssi, rx_stats->rs_rssi); |
| 78 | last_rssi = common->last_rssi; |
| 79 | |
| 80 | if (likely(last_rssi != ATH_RSSI_DUMMY_MARKER)) |
| 81 | rssi = ATH_EP_RND(last_rssi, ATH_RSSI_EP_MULTIPLIER); |
| 82 | if (rssi < 0) |
| 83 | rssi = 0; |
| 84 | |
| 85 | ah->stats.avgbrssi = rssi; |
| 86 | } |
| 87 | |
| 88 | rxs->signal = ah->noise + rx_stats->rs_rssi; |
| 89 | } |
| 90 | EXPORT_SYMBOL(ath9k_cmn_process_rssi); |
| 91 | |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 92 | int ath9k_cmn_get_hw_crypto_keytype(struct sk_buff *skb) |
| 93 | { |
| 94 | struct ieee80211_tx_info *tx_info = IEEE80211_SKB_CB(skb); |
| 95 | |
| 96 | if (tx_info->control.hw_key) { |
Johannes Berg | 97359d1 | 2010-08-10 09:46:38 +0200 | [diff] [blame] | 97 | switch (tx_info->control.hw_key->cipher) { |
| 98 | case WLAN_CIPHER_SUITE_WEP40: |
| 99 | case WLAN_CIPHER_SUITE_WEP104: |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 100 | return ATH9K_KEY_TYPE_WEP; |
Johannes Berg | 97359d1 | 2010-08-10 09:46:38 +0200 | [diff] [blame] | 101 | case WLAN_CIPHER_SUITE_TKIP: |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 102 | return ATH9K_KEY_TYPE_TKIP; |
Johannes Berg | 97359d1 | 2010-08-10 09:46:38 +0200 | [diff] [blame] | 103 | case WLAN_CIPHER_SUITE_CCMP: |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 104 | return ATH9K_KEY_TYPE_AES; |
Johannes Berg | 97359d1 | 2010-08-10 09:46:38 +0200 | [diff] [blame] | 105 | default: |
| 106 | break; |
| 107 | } |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 108 | } |
| 109 | |
| 110 | return ATH9K_KEY_TYPE_CLEAR; |
| 111 | } |
| 112 | EXPORT_SYMBOL(ath9k_cmn_get_hw_crypto_keytype); |
| 113 | |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 114 | /* |
| 115 | * Update internal channel flags. |
| 116 | */ |
Felix Fietkau | 2297f1c | 2013-10-11 23:30:57 +0200 | [diff] [blame] | 117 | static void ath9k_cmn_update_ichannel(struct ath9k_channel *ichan, |
| 118 | struct cfg80211_chan_def *chandef) |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 119 | { |
Felix Fietkau | 6b21fd2 | 2013-10-11 23:30:56 +0200 | [diff] [blame] | 120 | struct ieee80211_channel *chan = chandef->chan; |
| 121 | u16 flags = 0; |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 122 | |
Felix Fietkau | 6b21fd2 | 2013-10-11 23:30:56 +0200 | [diff] [blame] | 123 | ichan->channel = chan->center_freq; |
| 124 | ichan->chan = chan; |
| 125 | |
| 126 | if (chan->band == IEEE80211_BAND_5GHZ) |
| 127 | flags |= CHANNEL_5GHZ; |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 128 | |
Simon Wunderlich | 0671894 | 2013-08-16 10:46:04 +0200 | [diff] [blame] | 129 | switch (chandef->width) { |
| 130 | case NL80211_CHAN_WIDTH_5: |
Felix Fietkau | 6b21fd2 | 2013-10-11 23:30:56 +0200 | [diff] [blame] | 131 | flags |= CHANNEL_QUARTER; |
Simon Wunderlich | 0671894 | 2013-08-16 10:46:04 +0200 | [diff] [blame] | 132 | break; |
| 133 | case NL80211_CHAN_WIDTH_10: |
Felix Fietkau | 6b21fd2 | 2013-10-11 23:30:56 +0200 | [diff] [blame] | 134 | flags |= CHANNEL_HALF; |
Simon Wunderlich | 0671894 | 2013-08-16 10:46:04 +0200 | [diff] [blame] | 135 | break; |
| 136 | case NL80211_CHAN_WIDTH_20_NOHT: |
| 137 | break; |
| 138 | case NL80211_CHAN_WIDTH_20: |
Felix Fietkau | 6b21fd2 | 2013-10-11 23:30:56 +0200 | [diff] [blame] | 139 | flags |= CHANNEL_HT; |
| 140 | break; |
Simon Wunderlich | 0671894 | 2013-08-16 10:46:04 +0200 | [diff] [blame] | 141 | case NL80211_CHAN_WIDTH_40: |
Felix Fietkau | 6b21fd2 | 2013-10-11 23:30:56 +0200 | [diff] [blame] | 142 | if (chandef->center_freq1 > chandef->chan->center_freq) |
| 143 | flags |= CHANNEL_HT40PLUS | CHANNEL_HT; |
| 144 | else |
| 145 | flags |= CHANNEL_HT40MINUS | CHANNEL_HT; |
Simon Wunderlich | 0671894 | 2013-08-16 10:46:04 +0200 | [diff] [blame] | 146 | break; |
| 147 | default: |
| 148 | WARN_ON(1); |
| 149 | } |
Felix Fietkau | 6b21fd2 | 2013-10-11 23:30:56 +0200 | [diff] [blame] | 150 | |
| 151 | ichan->channelFlags = flags; |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 152 | } |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 153 | |
| 154 | /* |
| 155 | * Get the internal channel reference. |
| 156 | */ |
Felix Fietkau | 2297f1c | 2013-10-11 23:30:57 +0200 | [diff] [blame] | 157 | struct ath9k_channel *ath9k_cmn_get_channel(struct ieee80211_hw *hw, |
| 158 | struct ath_hw *ah, |
| 159 | struct cfg80211_chan_def *chandef) |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 160 | { |
Felix Fietkau | 2297f1c | 2013-10-11 23:30:57 +0200 | [diff] [blame] | 161 | struct ieee80211_channel *curchan = chandef->chan; |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 162 | struct ath9k_channel *channel; |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 163 | |
Felix Fietkau | f40c460 | 2013-12-14 18:03:35 +0100 | [diff] [blame] | 164 | channel = &ah->channels[curchan->hw_value]; |
Felix Fietkau | 2297f1c | 2013-10-11 23:30:57 +0200 | [diff] [blame] | 165 | ath9k_cmn_update_ichannel(channel, chandef); |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 166 | |
| 167 | return channel; |
| 168 | } |
Felix Fietkau | 2297f1c | 2013-10-11 23:30:57 +0200 | [diff] [blame] | 169 | EXPORT_SYMBOL(ath9k_cmn_get_channel); |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 170 | |
Sujith | 61389f3 | 2010-06-02 15:53:37 +0530 | [diff] [blame] | 171 | int ath9k_cmn_count_streams(unsigned int chainmask, int max) |
| 172 | { |
| 173 | int streams = 0; |
| 174 | |
| 175 | do { |
| 176 | if (++streams == max) |
| 177 | break; |
| 178 | } while ((chainmask = chainmask & (chainmask - 1))); |
| 179 | |
| 180 | return streams; |
| 181 | } |
| 182 | EXPORT_SYMBOL(ath9k_cmn_count_streams); |
| 183 | |
Rajkumar Manoharan | 5048e8c | 2011-01-31 23:47:44 +0530 | [diff] [blame] | 184 | void ath9k_cmn_update_txpow(struct ath_hw *ah, u16 cur_txpow, |
| 185 | u16 new_txpow, u16 *txpower) |
| 186 | { |
Felix Fietkau | ca2c68c | 2011-10-08 20:06:20 +0200 | [diff] [blame] | 187 | struct ath_regulatory *reg = ath9k_hw_regulatory(ah); |
| 188 | |
| 189 | if (reg->power_limit != new_txpow) { |
Rajkumar Manoharan | 5048e8c | 2011-01-31 23:47:44 +0530 | [diff] [blame] | 190 | ath9k_hw_set_txpowerlimit(ah, new_txpow, false); |
| 191 | /* read back in case value is clamped */ |
Felix Fietkau | ca2c68c | 2011-10-08 20:06:20 +0200 | [diff] [blame] | 192 | *txpower = reg->max_power_level; |
Rajkumar Manoharan | 5048e8c | 2011-01-31 23:47:44 +0530 | [diff] [blame] | 193 | } |
| 194 | } |
| 195 | EXPORT_SYMBOL(ath9k_cmn_update_txpow); |
| 196 | |
Rajkumar Manoharan | f82b4bd | 2011-08-13 10:28:15 +0530 | [diff] [blame] | 197 | void ath9k_cmn_init_crypto(struct ath_hw *ah) |
| 198 | { |
| 199 | struct ath_common *common = ath9k_hw_common(ah); |
| 200 | int i = 0; |
| 201 | |
| 202 | /* Get the hardware key cache size. */ |
| 203 | common->keymax = AR_KEYTABLE_SIZE; |
| 204 | |
| 205 | /* |
| 206 | * Check whether the separate key cache entries |
| 207 | * are required to handle both tx+rx MIC keys. |
| 208 | * With split mic keys the number of stations is limited |
| 209 | * to 27 otherwise 59. |
| 210 | */ |
| 211 | if (ah->misc_mode & AR_PCU_MIC_NEW_LOC_ENA) |
| 212 | common->crypt_caps |= ATH_CRYPT_CAP_MIC_COMBINED; |
| 213 | |
| 214 | /* |
| 215 | * Reset the key cache since some parts do not |
| 216 | * reset the contents on initial power up. |
| 217 | */ |
| 218 | for (i = 0; i < common->keymax; i++) |
| 219 | ath_hw_keyreset(common, (u16) i); |
| 220 | } |
| 221 | EXPORT_SYMBOL(ath9k_cmn_init_crypto); |
| 222 | |
Luis R. Rodriguez | db86f07 | 2009-11-05 08:44:39 -0800 | [diff] [blame] | 223 | static int __init ath9k_cmn_init(void) |
| 224 | { |
| 225 | return 0; |
| 226 | } |
| 227 | module_init(ath9k_cmn_init); |
| 228 | |
| 229 | static void __exit ath9k_cmn_exit(void) |
| 230 | { |
| 231 | return; |
| 232 | } |
| 233 | module_exit(ath9k_cmn_exit); |