Jiri Slaby | fa1c114 | 2007-08-12 17:33:16 +0200 | [diff] [blame] | 1 | /*- |
| 2 | * Copyright (c) 2002-2005 Sam Leffler, Errno Consulting |
| 3 | * Copyright (c) 2004-2005 Atheros Communications, Inc. |
| 4 | * Copyright (c) 2006 Devicescape Software, Inc. |
| 5 | * Copyright (c) 2007 Jiri Slaby <jirislaby@gmail.com> |
| 6 | * Copyright (c) 2007 Luis R. Rodriguez <mcgrof@winlab.rutgers.edu> |
| 7 | * |
| 8 | * All rights reserved. |
| 9 | * |
| 10 | * Redistribution and use in source and binary forms, with or without |
| 11 | * modification, are permitted provided that the following conditions |
| 12 | * are met: |
| 13 | * 1. Redistributions of source code must retain the above copyright |
| 14 | * notice, this list of conditions and the following disclaimer, |
| 15 | * without modification. |
| 16 | * 2. Redistributions in binary form must reproduce at minimum a disclaimer |
| 17 | * similar to the "NO WARRANTY" disclaimer below ("Disclaimer") and any |
| 18 | * redistribution must be conditioned upon including a substantially |
| 19 | * similar Disclaimer requirement for further binary redistribution. |
| 20 | * 3. Neither the names of the above-listed copyright holders nor the names |
| 21 | * of any contributors may be used to endorse or promote products derived |
| 22 | * from this software without specific prior written permission. |
| 23 | * |
| 24 | * Alternatively, this software may be distributed under the terms of the |
| 25 | * GNU General Public License ("GPL") version 2 as published by the Free |
| 26 | * Software Foundation. |
| 27 | * |
| 28 | * NO WARRANTY |
| 29 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 30 | * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 31 | * LIMITED TO, THE IMPLIED WARRANTIES OF NONINFRINGEMENT, MERCHANTIBILITY |
| 32 | * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL |
| 33 | * THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, |
| 34 | * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
| 35 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
| 36 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER |
| 37 | * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
| 38 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF |
| 39 | * THE POSSIBILITY OF SUCH DAMAGES. |
| 40 | * |
| 41 | */ |
| 42 | |
Jiri Slaby | fa1c114 | 2007-08-12 17:33:16 +0200 | [diff] [blame] | 43 | #include <linux/module.h> |
| 44 | #include <linux/delay.h> |
Alexey Dobriyan | b7f080c | 2011-06-16 11:01:34 +0000 | [diff] [blame] | 45 | #include <linux/dma-mapping.h> |
Jiri Slaby | 274c7c3 | 2008-07-15 17:44:20 +0200 | [diff] [blame] | 46 | #include <linux/hardirq.h> |
Jiri Slaby | fa1c114 | 2007-08-12 17:33:16 +0200 | [diff] [blame] | 47 | #include <linux/if.h> |
Jiri Slaby | 274c7c3 | 2008-07-15 17:44:20 +0200 | [diff] [blame] | 48 | #include <linux/io.h> |
Jiri Slaby | fa1c114 | 2007-08-12 17:33:16 +0200 | [diff] [blame] | 49 | #include <linux/netdevice.h> |
| 50 | #include <linux/cache.h> |
Jiri Slaby | fa1c114 | 2007-08-12 17:33:16 +0200 | [diff] [blame] | 51 | #include <linux/ethtool.h> |
| 52 | #include <linux/uaccess.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 53 | #include <linux/slab.h> |
Ben Greear | b1ae1ed | 2010-09-30 12:22:58 -0700 | [diff] [blame] | 54 | #include <linux/etherdevice.h> |
Pavel Roskin | 931be26 | 2011-07-26 22:26:59 -0400 | [diff] [blame] | 55 | #include <linux/nl80211.h> |
Jiri Slaby | fa1c114 | 2007-08-12 17:33:16 +0200 | [diff] [blame] | 56 | |
| 57 | #include <net/ieee80211_radiotap.h> |
| 58 | |
| 59 | #include <asm/unaligned.h> |
| 60 | |
| 61 | #include "base.h" |
| 62 | #include "reg.h" |
| 63 | #include "debug.h" |
Bruno Randolf | 2111ac0 | 2010-04-02 18:44:08 +0900 | [diff] [blame] | 64 | #include "ani.h" |
Pavel Roskin | 931be26 | 2011-07-26 22:26:59 -0400 | [diff] [blame] | 65 | #include "ath5k.h" |
| 66 | #include "../regd.h" |
Jiri Slaby | fa1c114 | 2007-08-12 17:33:16 +0200 | [diff] [blame] | 67 | |
Bob Copeland | 0e47225 | 2011-01-24 23:32:55 -0500 | [diff] [blame] | 68 | #define CREATE_TRACE_POINTS |
| 69 | #include "trace.h" |
| 70 | |
John W. Linville | 18cb6e3 | 2011-01-05 09:39:59 -0500 | [diff] [blame] | 71 | int ath5k_modparam_nohwcrypt; |
| 72 | module_param_named(nohwcrypt, ath5k_modparam_nohwcrypt, bool, S_IRUGO); |
Bob Copeland | 9ad9a26 | 2008-10-29 08:30:54 -0400 | [diff] [blame] | 73 | MODULE_PARM_DESC(nohwcrypt, "Disable hardware encryption."); |
Jiri Slaby | fa1c114 | 2007-08-12 17:33:16 +0200 | [diff] [blame] | 74 | |
Bob Copeland | 42639fc | 2009-03-30 08:05:29 -0400 | [diff] [blame] | 75 | static int modparam_all_channels; |
Bob Copeland | 46802a4 | 2009-04-15 07:57:34 -0400 | [diff] [blame] | 76 | module_param_named(all_channels, modparam_all_channels, bool, S_IRUGO); |
Bob Copeland | 42639fc | 2009-03-30 08:05:29 -0400 | [diff] [blame] | 77 | MODULE_PARM_DESC(all_channels, "Expose all channels the device can use."); |
| 78 | |
Nick Kossifidis | a99168e | 2011-06-02 03:09:48 +0300 | [diff] [blame] | 79 | static int modparam_fastchanswitch; |
| 80 | module_param_named(fastchanswitch, modparam_fastchanswitch, bool, S_IRUGO); |
| 81 | MODULE_PARM_DESC(fastchanswitch, "Enable fast channel switching for AR2413/AR5413 radios."); |
| 82 | |
| 83 | |
Jiri Slaby | fa1c114 | 2007-08-12 17:33:16 +0200 | [diff] [blame] | 84 | /* Module info */ |
| 85 | MODULE_AUTHOR("Jiri Slaby"); |
| 86 | MODULE_AUTHOR("Nick Kossifidis"); |
| 87 | MODULE_DESCRIPTION("Support for 5xxx series of Atheros 802.11 wireless LAN cards."); |
| 88 | MODULE_SUPPORTED_DEVICE("Atheros 5xxx WLAN cards"); |
| 89 | MODULE_LICENSE("Dual BSD/GPL"); |
Jiri Slaby | fa1c114 | 2007-08-12 17:33:16 +0200 | [diff] [blame] | 90 | |
Felix Fietkau | 132b1c3 | 2010-12-02 10:26:56 +0100 | [diff] [blame] | 91 | static int ath5k_init(struct ieee80211_hw *hw); |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 92 | static int ath5k_reset(struct ath5k_hw *ah, struct ieee80211_channel *chan, |
Nick Kossifidis | 8aec7af | 2010-11-23 21:39:28 +0200 | [diff] [blame] | 93 | bool skip_pcu); |
Jiri Slaby | fa1c114 | 2007-08-12 17:33:16 +0200 | [diff] [blame] | 94 | |
Jiri Slaby | fa1c114 | 2007-08-12 17:33:16 +0200 | [diff] [blame] | 95 | /* Known SREVs */ |
Jiri Slaby | 2c91108c | 2009-03-07 10:26:41 +0100 | [diff] [blame] | 96 | static const struct ath5k_srev_name srev_names[] = { |
Felix Fietkau | a0b907e | 2010-12-02 10:27:16 +0100 | [diff] [blame] | 97 | #ifdef CONFIG_ATHEROS_AR231X |
| 98 | { "5312", AR5K_VERSION_MAC, AR5K_SREV_AR5312_R2 }, |
| 99 | { "5312", AR5K_VERSION_MAC, AR5K_SREV_AR5312_R7 }, |
| 100 | { "2313", AR5K_VERSION_MAC, AR5K_SREV_AR2313_R8 }, |
| 101 | { "2315", AR5K_VERSION_MAC, AR5K_SREV_AR2315_R6 }, |
| 102 | { "2315", AR5K_VERSION_MAC, AR5K_SREV_AR2315_R7 }, |
| 103 | { "2317", AR5K_VERSION_MAC, AR5K_SREV_AR2317_R1 }, |
| 104 | { "2317", AR5K_VERSION_MAC, AR5K_SREV_AR2317_R2 }, |
| 105 | #else |
Nick Kossifidis | 1bef016 | 2008-09-29 02:09:09 +0300 | [diff] [blame] | 106 | { "5210", AR5K_VERSION_MAC, AR5K_SREV_AR5210 }, |
| 107 | { "5311", AR5K_VERSION_MAC, AR5K_SREV_AR5311 }, |
| 108 | { "5311A", AR5K_VERSION_MAC, AR5K_SREV_AR5311A }, |
| 109 | { "5311B", AR5K_VERSION_MAC, AR5K_SREV_AR5311B }, |
| 110 | { "5211", AR5K_VERSION_MAC, AR5K_SREV_AR5211 }, |
| 111 | { "5212", AR5K_VERSION_MAC, AR5K_SREV_AR5212 }, |
| 112 | { "5213", AR5K_VERSION_MAC, AR5K_SREV_AR5213 }, |
| 113 | { "5213A", AR5K_VERSION_MAC, AR5K_SREV_AR5213A }, |
| 114 | { "2413", AR5K_VERSION_MAC, AR5K_SREV_AR2413 }, |
| 115 | { "2414", AR5K_VERSION_MAC, AR5K_SREV_AR2414 }, |
| 116 | { "5424", AR5K_VERSION_MAC, AR5K_SREV_AR5424 }, |
| 117 | { "5413", AR5K_VERSION_MAC, AR5K_SREV_AR5413 }, |
| 118 | { "5414", AR5K_VERSION_MAC, AR5K_SREV_AR5414 }, |
| 119 | { "2415", AR5K_VERSION_MAC, AR5K_SREV_AR2415 }, |
| 120 | { "5416", AR5K_VERSION_MAC, AR5K_SREV_AR5416 }, |
| 121 | { "5418", AR5K_VERSION_MAC, AR5K_SREV_AR5418 }, |
| 122 | { "2425", AR5K_VERSION_MAC, AR5K_SREV_AR2425 }, |
| 123 | { "2417", AR5K_VERSION_MAC, AR5K_SREV_AR2417 }, |
Felix Fietkau | a0b907e | 2010-12-02 10:27:16 +0100 | [diff] [blame] | 124 | #endif |
Nick Kossifidis | 1bef016 | 2008-09-29 02:09:09 +0300 | [diff] [blame] | 125 | { "xxxxx", AR5K_VERSION_MAC, AR5K_SREV_UNKNOWN }, |
Jiri Slaby | fa1c114 | 2007-08-12 17:33:16 +0200 | [diff] [blame] | 126 | { "5110", AR5K_VERSION_RAD, AR5K_SREV_RAD_5110 }, |
| 127 | { "5111", AR5K_VERSION_RAD, AR5K_SREV_RAD_5111 }, |
Nick Kossifidis | 1bef016 | 2008-09-29 02:09:09 +0300 | [diff] [blame] | 128 | { "5111A", AR5K_VERSION_RAD, AR5K_SREV_RAD_5111A }, |
Jiri Slaby | fa1c114 | 2007-08-12 17:33:16 +0200 | [diff] [blame] | 129 | { "2111", AR5K_VERSION_RAD, AR5K_SREV_RAD_2111 }, |
| 130 | { "5112", AR5K_VERSION_RAD, AR5K_SREV_RAD_5112 }, |
| 131 | { "5112A", AR5K_VERSION_RAD, AR5K_SREV_RAD_5112A }, |
Nick Kossifidis | 1bef016 | 2008-09-29 02:09:09 +0300 | [diff] [blame] | 132 | { "5112B", AR5K_VERSION_RAD, AR5K_SREV_RAD_5112B }, |
Jiri Slaby | fa1c114 | 2007-08-12 17:33:16 +0200 | [diff] [blame] | 133 | { "2112", AR5K_VERSION_RAD, AR5K_SREV_RAD_2112 }, |
| 134 | { "2112A", AR5K_VERSION_RAD, AR5K_SREV_RAD_2112A }, |
Nick Kossifidis | 1bef016 | 2008-09-29 02:09:09 +0300 | [diff] [blame] | 135 | { "2112B", AR5K_VERSION_RAD, AR5K_SREV_RAD_2112B }, |
| 136 | { "2413", AR5K_VERSION_RAD, AR5K_SREV_RAD_2413 }, |
| 137 | { "5413", AR5K_VERSION_RAD, AR5K_SREV_RAD_5413 }, |
Nick Kossifidis | 1bef016 | 2008-09-29 02:09:09 +0300 | [diff] [blame] | 138 | { "5424", AR5K_VERSION_RAD, AR5K_SREV_RAD_5424 }, |
Jiri Slaby | fa1c114 | 2007-08-12 17:33:16 +0200 | [diff] [blame] | 139 | { "5133", AR5K_VERSION_RAD, AR5K_SREV_RAD_5133 }, |
Felix Fietkau | a0b907e | 2010-12-02 10:27:16 +0100 | [diff] [blame] | 140 | #ifdef CONFIG_ATHEROS_AR231X |
| 141 | { "2316", AR5K_VERSION_RAD, AR5K_SREV_RAD_2316 }, |
| 142 | { "2317", AR5K_VERSION_RAD, AR5K_SREV_RAD_2317 }, |
| 143 | #endif |
Jiri Slaby | fa1c114 | 2007-08-12 17:33:16 +0200 | [diff] [blame] | 144 | { "xxxxx", AR5K_VERSION_RAD, AR5K_SREV_UNKNOWN }, |
| 145 | }; |
| 146 | |
Jiri Slaby | 2c91108c | 2009-03-07 10:26:41 +0100 | [diff] [blame] | 147 | static const struct ieee80211_rate ath5k_rates[] = { |
Bruno Randolf | 63266a6 | 2008-07-30 17:12:58 +0200 | [diff] [blame] | 148 | { .bitrate = 10, |
| 149 | .hw_value = ATH5K_RATE_CODE_1M, }, |
| 150 | { .bitrate = 20, |
| 151 | .hw_value = ATH5K_RATE_CODE_2M, |
| 152 | .hw_value_short = ATH5K_RATE_CODE_2M | AR5K_SET_SHORT_PREAMBLE, |
| 153 | .flags = IEEE80211_RATE_SHORT_PREAMBLE }, |
| 154 | { .bitrate = 55, |
| 155 | .hw_value = ATH5K_RATE_CODE_5_5M, |
| 156 | .hw_value_short = ATH5K_RATE_CODE_5_5M | AR5K_SET_SHORT_PREAMBLE, |
| 157 | .flags = IEEE80211_RATE_SHORT_PREAMBLE }, |
| 158 | { .bitrate = 110, |
| 159 | .hw_value = ATH5K_RATE_CODE_11M, |
| 160 | .hw_value_short = ATH5K_RATE_CODE_11M | AR5K_SET_SHORT_PREAMBLE, |
| 161 | .flags = IEEE80211_RATE_SHORT_PREAMBLE }, |
| 162 | { .bitrate = 60, |
| 163 | .hw_value = ATH5K_RATE_CODE_6M, |
| 164 | .flags = 0 }, |
| 165 | { .bitrate = 90, |
| 166 | .hw_value = ATH5K_RATE_CODE_9M, |
| 167 | .flags = 0 }, |
| 168 | { .bitrate = 120, |
| 169 | .hw_value = ATH5K_RATE_CODE_12M, |
| 170 | .flags = 0 }, |
| 171 | { .bitrate = 180, |
| 172 | .hw_value = ATH5K_RATE_CODE_18M, |
| 173 | .flags = 0 }, |
| 174 | { .bitrate = 240, |
| 175 | .hw_value = ATH5K_RATE_CODE_24M, |
| 176 | .flags = 0 }, |
| 177 | { .bitrate = 360, |
| 178 | .hw_value = ATH5K_RATE_CODE_36M, |
| 179 | .flags = 0 }, |
| 180 | { .bitrate = 480, |
| 181 | .hw_value = ATH5K_RATE_CODE_48M, |
| 182 | .flags = 0 }, |
| 183 | { .bitrate = 540, |
| 184 | .hw_value = ATH5K_RATE_CODE_54M, |
| 185 | .flags = 0 }, |
Bruno Randolf | 63266a6 | 2008-07-30 17:12:58 +0200 | [diff] [blame] | 186 | }; |
| 187 | |
Jiri Slaby | fa1c114 | 2007-08-12 17:33:16 +0200 | [diff] [blame] | 188 | static inline u64 ath5k_extend_tsf(struct ath5k_hw *ah, u32 rstamp) |
| 189 | { |
| 190 | u64 tsf = ath5k_hw_get_tsf64(ah); |
| 191 | |
| 192 | if ((tsf & 0x7fff) < rstamp) |
| 193 | tsf -= 0x8000; |
| 194 | |
| 195 | return (tsf & ~0x7fff) | rstamp; |
| 196 | } |
| 197 | |
Felix Fietkau | e5b046d | 2010-12-02 10:27:01 +0100 | [diff] [blame] | 198 | const char * |
Jiri Slaby | fa1c114 | 2007-08-12 17:33:16 +0200 | [diff] [blame] | 199 | ath5k_chip_name(enum ath5k_srev_type type, u_int16_t val) |
| 200 | { |
| 201 | const char *name = "xxxxx"; |
| 202 | unsigned int i; |
| 203 | |
| 204 | for (i = 0; i < ARRAY_SIZE(srev_names); i++) { |
| 205 | if (srev_names[i].sr_type != type) |
| 206 | continue; |
Nick Kossifidis | 75d0edb | 2008-09-29 01:24:44 +0300 | [diff] [blame] | 207 | |
| 208 | if ((val & 0xf0) == srev_names[i].sr_val) |
| 209 | name = srev_names[i].sr_name; |
| 210 | |
| 211 | if ((val & 0xff) == srev_names[i].sr_val) { |
Jiri Slaby | fa1c114 | 2007-08-12 17:33:16 +0200 | [diff] [blame] | 212 | name = srev_names[i].sr_name; |
| 213 | break; |
| 214 | } |
| 215 | } |
| 216 | |
| 217 | return name; |
| 218 | } |
Luis R. Rodriguez | e5aa847 | 2009-09-10 16:55:11 -0700 | [diff] [blame] | 219 | static unsigned int ath5k_ioread32(void *hw_priv, u32 reg_offset) |
| 220 | { |
| 221 | struct ath5k_hw *ah = (struct ath5k_hw *) hw_priv; |
| 222 | return ath5k_hw_reg_read(ah, reg_offset); |
| 223 | } |
| 224 | |
| 225 | static void ath5k_iowrite32(void *hw_priv, u32 val, u32 reg_offset) |
| 226 | { |
| 227 | struct ath5k_hw *ah = (struct ath5k_hw *) hw_priv; |
| 228 | ath5k_hw_reg_write(ah, val, reg_offset); |
| 229 | } |
| 230 | |
| 231 | static const struct ath_ops ath5k_common_ops = { |
| 232 | .read = ath5k_ioread32, |
| 233 | .write = ath5k_iowrite32, |
| 234 | }; |
Jiri Slaby | fa1c114 | 2007-08-12 17:33:16 +0200 | [diff] [blame] | 235 | |
Jiri Slaby | fa1c114 | 2007-08-12 17:33:16 +0200 | [diff] [blame] | 236 | /***********************\ |
| 237 | * Driver Initialization * |
| 238 | \***********************/ |
| 239 | |
Bob Copeland | f769c36 | 2009-03-30 22:30:31 -0400 | [diff] [blame] | 240 | static int ath5k_reg_notifier(struct wiphy *wiphy, struct regulatory_request *request) |
| 241 | { |
| 242 | struct ieee80211_hw *hw = wiphy_to_ieee80211_hw(wiphy); |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 243 | struct ath5k_hw *ah = hw->priv; |
| 244 | struct ath_regulatory *regulatory = ath5k_hw_regulatory(ah); |
Bob Copeland | f769c36 | 2009-03-30 22:30:31 -0400 | [diff] [blame] | 245 | |
Luis R. Rodriguez | 608b88c | 2009-08-17 18:07:23 -0700 | [diff] [blame] | 246 | return ath_reg_notifier_apply(wiphy, request, regulatory); |
Bob Copeland | f769c36 | 2009-03-30 22:30:31 -0400 | [diff] [blame] | 247 | } |
| 248 | |
Jiri Slaby | fa1c114 | 2007-08-12 17:33:16 +0200 | [diff] [blame] | 249 | /********************\ |
| 250 | * Channel/mode setup * |
| 251 | \********************/ |
| 252 | |
| 253 | /* |
Bob Copeland | 42639fc | 2009-03-30 08:05:29 -0400 | [diff] [blame] | 254 | * Returns true for the channel numbers used without all_channels modparam. |
| 255 | */ |
Bruno Randolf | 410e612 | 2011-01-19 18:20:57 +0900 | [diff] [blame] | 256 | static bool ath5k_is_standard_channel(short chan, enum ieee80211_band band) |
Bob Copeland | 42639fc | 2009-03-30 08:05:29 -0400 | [diff] [blame] | 257 | { |
Bruno Randolf | 410e612 | 2011-01-19 18:20:57 +0900 | [diff] [blame] | 258 | if (band == IEEE80211_BAND_2GHZ && chan <= 14) |
| 259 | return true; |
| 260 | |
| 261 | return /* UNII 1,2 */ |
| 262 | (((chan & 3) == 0 && chan >= 36 && chan <= 64) || |
Bob Copeland | 42639fc | 2009-03-30 08:05:29 -0400 | [diff] [blame] | 263 | /* midband */ |
| 264 | ((chan & 3) == 0 && chan >= 100 && chan <= 140) || |
| 265 | /* UNII-3 */ |
Bruno Randolf | 410e612 | 2011-01-19 18:20:57 +0900 | [diff] [blame] | 266 | ((chan & 3) == 1 && chan >= 149 && chan <= 165) || |
| 267 | /* 802.11j 5.030-5.080 GHz (20MHz) */ |
| 268 | (chan == 8 || chan == 12 || chan == 16) || |
| 269 | /* 802.11j 4.9GHz (20MHz) */ |
| 270 | (chan == 184 || chan == 188 || chan == 192 || chan == 196)); |
Bob Copeland | 42639fc | 2009-03-30 08:05:29 -0400 | [diff] [blame] | 271 | } |
| 272 | |
Jiri Slaby | fa1c114 | 2007-08-12 17:33:16 +0200 | [diff] [blame] | 273 | static unsigned int |
Bruno Randolf | 97d9c3a | 2011-01-19 18:20:52 +0900 | [diff] [blame] | 274 | ath5k_setup_channels(struct ath5k_hw *ah, struct ieee80211_channel *channels, |
| 275 | unsigned int mode, unsigned int max) |
Jiri Slaby | fa1c114 | 2007-08-12 17:33:16 +0200 | [diff] [blame] | 276 | { |
Pavel Roskin | 32c2546 | 2011-07-23 09:29:09 -0400 | [diff] [blame] | 277 | unsigned int count, size, freq, ch; |
Bruno Randolf | 90c02d7 | 2011-01-19 18:20:36 +0900 | [diff] [blame] | 278 | enum ieee80211_band band; |
Jiri Slaby | fa1c114 | 2007-08-12 17:33:16 +0200 | [diff] [blame] | 279 | |
Jiri Slaby | fa1c114 | 2007-08-12 17:33:16 +0200 | [diff] [blame] | 280 | switch (mode) { |
Luis R. Rodriguez | d8ee398 | 2008-02-03 21:51:04 -0500 | [diff] [blame] | 281 | case AR5K_MODE_11A: |
Jiri Slaby | fa1c114 | 2007-08-12 17:33:16 +0200 | [diff] [blame] | 282 | /* 1..220, but 2GHz frequencies are filtered by check_channel */ |
Bruno Randolf | 97d9c3a | 2011-01-19 18:20:52 +0900 | [diff] [blame] | 283 | size = 220; |
Bruno Randolf | 90c02d7 | 2011-01-19 18:20:36 +0900 | [diff] [blame] | 284 | band = IEEE80211_BAND_5GHZ; |
Jiri Slaby | fa1c114 | 2007-08-12 17:33:16 +0200 | [diff] [blame] | 285 | break; |
Luis R. Rodriguez | d8ee398 | 2008-02-03 21:51:04 -0500 | [diff] [blame] | 286 | case AR5K_MODE_11B: |
| 287 | case AR5K_MODE_11G: |
Luis R. Rodriguez | d8ee398 | 2008-02-03 21:51:04 -0500 | [diff] [blame] | 288 | size = 26; |
Bruno Randolf | 90c02d7 | 2011-01-19 18:20:36 +0900 | [diff] [blame] | 289 | band = IEEE80211_BAND_2GHZ; |
Jiri Slaby | fa1c114 | 2007-08-12 17:33:16 +0200 | [diff] [blame] | 290 | break; |
| 291 | default: |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 292 | ATH5K_WARN(ah, "bad mode, not copying channels\n"); |
Jiri Slaby | fa1c114 | 2007-08-12 17:33:16 +0200 | [diff] [blame] | 293 | return 0; |
| 294 | } |
| 295 | |
Bruno Randolf | 2b1351a | 2011-01-21 12:19:52 +0900 | [diff] [blame] | 296 | count = 0; |
| 297 | for (ch = 1; ch <= size && count < max; ch++) { |
Bruno Randolf | 90c02d7 | 2011-01-19 18:20:36 +0900 | [diff] [blame] | 298 | freq = ieee80211_channel_to_frequency(ch, band); |
| 299 | |
| 300 | if (freq == 0) /* mapping failed - not a standard channel */ |
| 301 | continue; |
Luis R. Rodriguez | d8ee398 | 2008-02-03 21:51:04 -0500 | [diff] [blame] | 302 | |
Pavel Roskin | 32c2546 | 2011-07-23 09:29:09 -0400 | [diff] [blame] | 303 | /* Write channel info, needed for ath5k_channel_ok() */ |
| 304 | channels[count].center_freq = freq; |
| 305 | channels[count].band = band; |
| 306 | channels[count].hw_value = mode; |
| 307 | |
Jiri Slaby | fa1c114 | 2007-08-12 17:33:16 +0200 | [diff] [blame] | 308 | /* Check if channel is supported by the chipset */ |
Pavel Roskin | 32c2546 | 2011-07-23 09:29:09 -0400 | [diff] [blame] | 309 | if (!ath5k_channel_ok(ah, &channels[count])) |
Jiri Slaby | fa1c114 | 2007-08-12 17:33:16 +0200 | [diff] [blame] | 310 | continue; |
| 311 | |
Bruno Randolf | 410e612 | 2011-01-19 18:20:57 +0900 | [diff] [blame] | 312 | if (!modparam_all_channels && |
| 313 | !ath5k_is_standard_channel(ch, band)) |
Bob Copeland | 42639fc | 2009-03-30 08:05:29 -0400 | [diff] [blame] | 314 | continue; |
| 315 | |
Jiri Slaby | fa1c114 | 2007-08-12 17:33:16 +0200 | [diff] [blame] | 316 | count++; |
Jiri Slaby | fa1c114 | 2007-08-12 17:33:16 +0200 | [diff] [blame] | 317 | } |
| 318 | |
| 319 | return count; |
| 320 | } |
| 321 | |
Bruno Randolf | 63266a6 | 2008-07-30 17:12:58 +0200 | [diff] [blame] | 322 | static void |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 323 | ath5k_setup_rate_idx(struct ath5k_hw *ah, struct ieee80211_supported_band *b) |
Bruno Randolf | 63266a6 | 2008-07-30 17:12:58 +0200 | [diff] [blame] | 324 | { |
| 325 | u8 i; |
| 326 | |
| 327 | for (i = 0; i < AR5K_MAX_RATES; i++) |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 328 | ah->rate_idx[b->band][i] = -1; |
Bruno Randolf | 63266a6 | 2008-07-30 17:12:58 +0200 | [diff] [blame] | 329 | |
| 330 | for (i = 0; i < b->n_bitrates; i++) { |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 331 | ah->rate_idx[b->band][b->bitrates[i].hw_value] = i; |
Bruno Randolf | 63266a6 | 2008-07-30 17:12:58 +0200 | [diff] [blame] | 332 | if (b->bitrates[i].hw_value_short) |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 333 | ah->rate_idx[b->band][b->bitrates[i].hw_value_short] = i; |
Bruno Randolf | 63266a6 | 2008-07-30 17:12:58 +0200 | [diff] [blame] | 334 | } |
| 335 | } |
| 336 | |
Jiri Slaby | fa1c114 | 2007-08-12 17:33:16 +0200 | [diff] [blame] | 337 | static int |
Bruno Randolf | 63266a6 | 2008-07-30 17:12:58 +0200 | [diff] [blame] | 338 | ath5k_setup_bands(struct ieee80211_hw *hw) |
Jiri Slaby | fa1c114 | 2007-08-12 17:33:16 +0200 | [diff] [blame] | 339 | { |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 340 | struct ath5k_hw *ah = hw->priv; |
Bruno Randolf | 63266a6 | 2008-07-30 17:12:58 +0200 | [diff] [blame] | 341 | struct ieee80211_supported_band *sband; |
| 342 | int max_c, count_c = 0; |
| 343 | int i; |
Jiri Slaby | fa1c114 | 2007-08-12 17:33:16 +0200 | [diff] [blame] | 344 | |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 345 | BUILD_BUG_ON(ARRAY_SIZE(ah->sbands) < IEEE80211_NUM_BANDS); |
| 346 | max_c = ARRAY_SIZE(ah->channels); |
Jiri Slaby | fa1c114 | 2007-08-12 17:33:16 +0200 | [diff] [blame] | 347 | |
Luis R. Rodriguez | d8ee398 | 2008-02-03 21:51:04 -0500 | [diff] [blame] | 348 | /* 2GHz band */ |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 349 | sband = &ah->sbands[IEEE80211_BAND_2GHZ]; |
Bruno Randolf | 63266a6 | 2008-07-30 17:12:58 +0200 | [diff] [blame] | 350 | sband->band = IEEE80211_BAND_2GHZ; |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 351 | sband->bitrates = &ah->rates[IEEE80211_BAND_2GHZ][0]; |
Jiri Slaby | fa1c114 | 2007-08-12 17:33:16 +0200 | [diff] [blame] | 352 | |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 353 | if (test_bit(AR5K_MODE_11G, ah->ah_capabilities.cap_mode)) { |
Bruno Randolf | 63266a6 | 2008-07-30 17:12:58 +0200 | [diff] [blame] | 354 | /* G mode */ |
| 355 | memcpy(sband->bitrates, &ath5k_rates[0], |
| 356 | sizeof(struct ieee80211_rate) * 12); |
| 357 | sband->n_bitrates = 12; |
Jiri Slaby | fa1c114 | 2007-08-12 17:33:16 +0200 | [diff] [blame] | 358 | |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 359 | sband->channels = ah->channels; |
Bruno Randolf | 0810569 | 2011-01-19 18:20:47 +0900 | [diff] [blame] | 360 | sband->n_channels = ath5k_setup_channels(ah, sband->channels, |
Bruno Randolf | 63266a6 | 2008-07-30 17:12:58 +0200 | [diff] [blame] | 361 | AR5K_MODE_11G, max_c); |
Luis R. Rodriguez | d8ee398 | 2008-02-03 21:51:04 -0500 | [diff] [blame] | 362 | |
| 363 | hw->wiphy->bands[IEEE80211_BAND_2GHZ] = sband; |
Bruno Randolf | 63266a6 | 2008-07-30 17:12:58 +0200 | [diff] [blame] | 364 | count_c = sband->n_channels; |
Luis R. Rodriguez | d8ee398 | 2008-02-03 21:51:04 -0500 | [diff] [blame] | 365 | max_c -= count_c; |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 366 | } else if (test_bit(AR5K_MODE_11B, ah->ah_capabilities.cap_mode)) { |
Bruno Randolf | 63266a6 | 2008-07-30 17:12:58 +0200 | [diff] [blame] | 367 | /* B mode */ |
| 368 | memcpy(sband->bitrates, &ath5k_rates[0], |
| 369 | sizeof(struct ieee80211_rate) * 4); |
| 370 | sband->n_bitrates = 4; |
Luis R. Rodriguez | d8ee398 | 2008-02-03 21:51:04 -0500 | [diff] [blame] | 371 | |
Bruno Randolf | 63266a6 | 2008-07-30 17:12:58 +0200 | [diff] [blame] | 372 | /* 5211 only supports B rates and uses 4bit rate codes |
| 373 | * (e.g normally we have 0x1B for 1M, but on 5211 we have 0x0B) |
| 374 | * fix them up here: |
| 375 | */ |
| 376 | if (ah->ah_version == AR5K_AR5211) { |
| 377 | for (i = 0; i < 4; i++) { |
| 378 | sband->bitrates[i].hw_value = |
| 379 | sband->bitrates[i].hw_value & 0xF; |
| 380 | sband->bitrates[i].hw_value_short = |
| 381 | sband->bitrates[i].hw_value_short & 0xF; |
| 382 | } |
| 383 | } |
| 384 | |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 385 | sband->channels = ah->channels; |
Bruno Randolf | 0810569 | 2011-01-19 18:20:47 +0900 | [diff] [blame] | 386 | sband->n_channels = ath5k_setup_channels(ah, sband->channels, |
Bruno Randolf | 63266a6 | 2008-07-30 17:12:58 +0200 | [diff] [blame] | 387 | AR5K_MODE_11B, max_c); |
| 388 | |
| 389 | hw->wiphy->bands[IEEE80211_BAND_2GHZ] = sband; |
| 390 | count_c = sband->n_channels; |
| 391 | max_c -= count_c; |
Luis R. Rodriguez | d8ee398 | 2008-02-03 21:51:04 -0500 | [diff] [blame] | 392 | } |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 393 | ath5k_setup_rate_idx(ah, sband); |
Luis R. Rodriguez | d8ee398 | 2008-02-03 21:51:04 -0500 | [diff] [blame] | 394 | |
Bruno Randolf | 63266a6 | 2008-07-30 17:12:58 +0200 | [diff] [blame] | 395 | /* 5GHz band, A mode */ |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 396 | if (test_bit(AR5K_MODE_11A, ah->ah_capabilities.cap_mode)) { |
| 397 | sband = &ah->sbands[IEEE80211_BAND_5GHZ]; |
Luis R. Rodriguez | d8ee398 | 2008-02-03 21:51:04 -0500 | [diff] [blame] | 398 | sband->band = IEEE80211_BAND_5GHZ; |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 399 | sband->bitrates = &ah->rates[IEEE80211_BAND_5GHZ][0]; |
Bruno Randolf | 63266a6 | 2008-07-30 17:12:58 +0200 | [diff] [blame] | 400 | |
| 401 | memcpy(sband->bitrates, &ath5k_rates[4], |
| 402 | sizeof(struct ieee80211_rate) * 8); |
| 403 | sband->n_bitrates = 8; |
| 404 | |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 405 | sband->channels = &ah->channels[count_c]; |
Bruno Randolf | 0810569 | 2011-01-19 18:20:47 +0900 | [diff] [blame] | 406 | sband->n_channels = ath5k_setup_channels(ah, sband->channels, |
Luis R. Rodriguez | d8ee398 | 2008-02-03 21:51:04 -0500 | [diff] [blame] | 407 | AR5K_MODE_11A, max_c); |
| 408 | |
Luis R. Rodriguez | d8ee398 | 2008-02-03 21:51:04 -0500 | [diff] [blame] | 409 | hw->wiphy->bands[IEEE80211_BAND_5GHZ] = sband; |
| 410 | } |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 411 | ath5k_setup_rate_idx(ah, sband); |
Luis R. Rodriguez | d8ee398 | 2008-02-03 21:51:04 -0500 | [diff] [blame] | 412 | |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 413 | ath5k_debug_dump_bands(ah); |
Luis R. Rodriguez | d8ee398 | 2008-02-03 21:51:04 -0500 | [diff] [blame] | 414 | |
| 415 | return 0; |
Jiri Slaby | fa1c114 | 2007-08-12 17:33:16 +0200 | [diff] [blame] | 416 | } |
| 417 | |
| 418 | /* |
Joerg Albert | e30eb4a | 2009-08-05 01:52:07 +0200 | [diff] [blame] | 419 | * Set/change channels. We always reset the chip. |
| 420 | * To accomplish this we must first cleanup any pending DMA, |
| 421 | * then restart stuff after a la ath5k_init. |
Bob Copeland | be00937 | 2009-01-22 08:44:16 -0500 | [diff] [blame] | 422 | * |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 423 | * Called with ah->lock. |
Jiri Slaby | fa1c114 | 2007-08-12 17:33:16 +0200 | [diff] [blame] | 424 | */ |
Bruno Randolf | cd2c548 | 2010-12-22 19:20:32 +0900 | [diff] [blame] | 425 | int |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 426 | ath5k_chan_set(struct ath5k_hw *ah, struct ieee80211_channel *chan) |
Jiri Slaby | fa1c114 | 2007-08-12 17:33:16 +0200 | [diff] [blame] | 427 | { |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 428 | ATH5K_DBG(ah, ATH5K_DEBUG_RESET, |
Bruno Randolf | 8d67a03 | 2010-06-16 19:11:12 +0900 | [diff] [blame] | 429 | "channel set, resetting (%u -> %u MHz)\n", |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 430 | ah->curchan->center_freq, chan->center_freq); |
Jiri Slaby | fa1c114 | 2007-08-12 17:33:16 +0200 | [diff] [blame] | 431 | |
Joerg Albert | e30eb4a | 2009-08-05 01:52:07 +0200 | [diff] [blame] | 432 | /* |
| 433 | * To switch channels clear any pending DMA operations; |
| 434 | * wait long enough for the RX fifo to drain, reset the |
| 435 | * hardware at the new frequency, and then re-enable |
| 436 | * the relevant bits of the h/w. |
| 437 | */ |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 438 | return ath5k_reset(ah, chan, true); |
Jiri Slaby | fa1c114 | 2007-08-12 17:33:16 +0200 | [diff] [blame] | 439 | } |
| 440 | |
Ben Greear | e4b0b32 | 2011-03-03 14:39:05 -0800 | [diff] [blame] | 441 | void ath5k_vif_iter(void *data, u8 *mac, struct ieee80211_vif *vif) |
Ben Greear | b1ae1ed | 2010-09-30 12:22:58 -0700 | [diff] [blame] | 442 | { |
Ben Greear | e4b0b32 | 2011-03-03 14:39:05 -0800 | [diff] [blame] | 443 | struct ath5k_vif_iter_data *iter_data = data; |
Ben Greear | b1ae1ed | 2010-09-30 12:22:58 -0700 | [diff] [blame] | 444 | int i; |
Ben Greear | 62c58fb | 2010-10-08 12:01:15 -0700 | [diff] [blame] | 445 | struct ath5k_vif *avf = (void *)vif->drv_priv; |
Ben Greear | b1ae1ed | 2010-09-30 12:22:58 -0700 | [diff] [blame] | 446 | |
| 447 | if (iter_data->hw_macaddr) |
| 448 | for (i = 0; i < ETH_ALEN; i++) |
| 449 | iter_data->mask[i] &= |
| 450 | ~(iter_data->hw_macaddr[i] ^ mac[i]); |
| 451 | |
| 452 | if (!iter_data->found_active) { |
| 453 | iter_data->found_active = true; |
| 454 | memcpy(iter_data->active_mac, mac, ETH_ALEN); |
| 455 | } |
| 456 | |
| 457 | if (iter_data->need_set_hw_addr && iter_data->hw_macaddr) |
| 458 | if (compare_ether_addr(iter_data->hw_macaddr, mac) == 0) |
| 459 | iter_data->need_set_hw_addr = false; |
| 460 | |
| 461 | if (!iter_data->any_assoc) { |
Ben Greear | b1ae1ed | 2010-09-30 12:22:58 -0700 | [diff] [blame] | 462 | if (avf->assoc) |
| 463 | iter_data->any_assoc = true; |
| 464 | } |
Ben Greear | 62c58fb | 2010-10-08 12:01:15 -0700 | [diff] [blame] | 465 | |
| 466 | /* Calculate combined mode - when APs are active, operate in AP mode. |
| 467 | * Otherwise use the mode of the new interface. This can currently |
| 468 | * only deal with combinations of APs and STAs. Only one ad-hoc |
Ben Greear | 7afbb2f | 2010-11-10 11:43:51 -0800 | [diff] [blame] | 469 | * interfaces is allowed. |
Ben Greear | 62c58fb | 2010-10-08 12:01:15 -0700 | [diff] [blame] | 470 | */ |
| 471 | if (avf->opmode == NL80211_IFTYPE_AP) |
| 472 | iter_data->opmode = NL80211_IFTYPE_AP; |
Ben Greear | e4b0b32 | 2011-03-03 14:39:05 -0800 | [diff] [blame] | 473 | else { |
| 474 | if (avf->opmode == NL80211_IFTYPE_STATION) |
| 475 | iter_data->n_stas++; |
Ben Greear | 62c58fb | 2010-10-08 12:01:15 -0700 | [diff] [blame] | 476 | if (iter_data->opmode == NL80211_IFTYPE_UNSPECIFIED) |
| 477 | iter_data->opmode = avf->opmode; |
Ben Greear | e4b0b32 | 2011-03-03 14:39:05 -0800 | [diff] [blame] | 478 | } |
Ben Greear | b1ae1ed | 2010-09-30 12:22:58 -0700 | [diff] [blame] | 479 | } |
| 480 | |
Bruno Randolf | cd2c548 | 2010-12-22 19:20:32 +0900 | [diff] [blame] | 481 | void |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 482 | ath5k_update_bssid_mask_and_opmode(struct ath5k_hw *ah, |
Bruno Randolf | cd2c548 | 2010-12-22 19:20:32 +0900 | [diff] [blame] | 483 | struct ieee80211_vif *vif) |
Ben Greear | b1ae1ed | 2010-09-30 12:22:58 -0700 | [diff] [blame] | 484 | { |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 485 | struct ath_common *common = ath5k_hw_common(ah); |
Ben Greear | e4b0b32 | 2011-03-03 14:39:05 -0800 | [diff] [blame] | 486 | struct ath5k_vif_iter_data iter_data; |
| 487 | u32 rfilt; |
Ben Greear | b1ae1ed | 2010-09-30 12:22:58 -0700 | [diff] [blame] | 488 | |
| 489 | /* |
| 490 | * Use the hardware MAC address as reference, the hardware uses it |
| 491 | * together with the BSSID mask when matching addresses. |
| 492 | */ |
| 493 | iter_data.hw_macaddr = common->macaddr; |
| 494 | memset(&iter_data.mask, 0xff, ETH_ALEN); |
| 495 | iter_data.found_active = false; |
| 496 | iter_data.need_set_hw_addr = true; |
Ben Greear | 62c58fb | 2010-10-08 12:01:15 -0700 | [diff] [blame] | 497 | iter_data.opmode = NL80211_IFTYPE_UNSPECIFIED; |
Ben Greear | e4b0b32 | 2011-03-03 14:39:05 -0800 | [diff] [blame] | 498 | iter_data.n_stas = 0; |
Ben Greear | b1ae1ed | 2010-09-30 12:22:58 -0700 | [diff] [blame] | 499 | |
| 500 | if (vif) |
Ben Greear | e4b0b32 | 2011-03-03 14:39:05 -0800 | [diff] [blame] | 501 | ath5k_vif_iter(&iter_data, vif->addr, vif); |
Ben Greear | b1ae1ed | 2010-09-30 12:22:58 -0700 | [diff] [blame] | 502 | |
| 503 | /* Get list of all active MAC addresses */ |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 504 | ieee80211_iterate_active_interfaces_atomic(ah->hw, ath5k_vif_iter, |
Ben Greear | b1ae1ed | 2010-09-30 12:22:58 -0700 | [diff] [blame] | 505 | &iter_data); |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 506 | memcpy(ah->bssidmask, iter_data.mask, ETH_ALEN); |
Ben Greear | b1ae1ed | 2010-09-30 12:22:58 -0700 | [diff] [blame] | 507 | |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 508 | ah->opmode = iter_data.opmode; |
| 509 | if (ah->opmode == NL80211_IFTYPE_UNSPECIFIED) |
Ben Greear | 62c58fb | 2010-10-08 12:01:15 -0700 | [diff] [blame] | 510 | /* Nothing active, default to station mode */ |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 511 | ah->opmode = NL80211_IFTYPE_STATION; |
Ben Greear | 62c58fb | 2010-10-08 12:01:15 -0700 | [diff] [blame] | 512 | |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 513 | ath5k_hw_set_opmode(ah, ah->opmode); |
| 514 | ATH5K_DBG(ah, ATH5K_DEBUG_MODE, "mode setup opmode %d (%s)\n", |
| 515 | ah->opmode, ath_opmode_to_string(ah->opmode)); |
Ben Greear | 62c58fb | 2010-10-08 12:01:15 -0700 | [diff] [blame] | 516 | |
Ben Greear | b1ae1ed | 2010-09-30 12:22:58 -0700 | [diff] [blame] | 517 | if (iter_data.need_set_hw_addr && iter_data.found_active) |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 518 | ath5k_hw_set_lladdr(ah, iter_data.active_mac); |
Ben Greear | b1ae1ed | 2010-09-30 12:22:58 -0700 | [diff] [blame] | 519 | |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 520 | if (ath5k_hw_hasbssidmask(ah)) |
| 521 | ath5k_hw_set_bssid_mask(ah, ah->bssidmask); |
Ben Greear | b1ae1ed | 2010-09-30 12:22:58 -0700 | [diff] [blame] | 522 | |
Ben Greear | e4b0b32 | 2011-03-03 14:39:05 -0800 | [diff] [blame] | 523 | /* Set up RX Filter */ |
| 524 | if (iter_data.n_stas > 1) { |
| 525 | /* If you have multiple STA interfaces connected to |
| 526 | * different APs, ARPs are not received (most of the time?) |
Pavel Roskin | 6a2a0e7 | 2011-07-09 00:17:51 -0400 | [diff] [blame] | 527 | * Enabling PROMISC appears to fix that problem. |
Ben Greear | e4b0b32 | 2011-03-03 14:39:05 -0800 | [diff] [blame] | 528 | */ |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 529 | ah->filter_flags |= AR5K_RX_FILTER_PROM; |
Ben Greear | e4b0b32 | 2011-03-03 14:39:05 -0800 | [diff] [blame] | 530 | } |
Jiri Slaby | fa1c114 | 2007-08-12 17:33:16 +0200 | [diff] [blame] | 531 | |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 532 | rfilt = ah->filter_flags; |
| 533 | ath5k_hw_set_rx_filter(ah, rfilt); |
| 534 | ATH5K_DBG(ah, ATH5K_DEBUG_MODE, "RX filter 0x%x\n", rfilt); |
Jiri Slaby | fa1c114 | 2007-08-12 17:33:16 +0200 | [diff] [blame] | 535 | } |
| 536 | |
Luis R. Rodriguez | d8ee398 | 2008-02-03 21:51:04 -0500 | [diff] [blame] | 537 | static inline int |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 538 | ath5k_hw_to_driver_rix(struct ath5k_hw *ah, int hw_rix) |
Bruno Randolf | 63266a6 | 2008-07-30 17:12:58 +0200 | [diff] [blame] | 539 | { |
Bob Copeland | b726604 | 2009-03-02 21:55:18 -0500 | [diff] [blame] | 540 | int rix; |
| 541 | |
| 542 | /* return base rate on errors */ |
| 543 | if (WARN(hw_rix < 0 || hw_rix >= AR5K_MAX_RATES, |
| 544 | "hw_rix out of bounds: %x\n", hw_rix)) |
| 545 | return 0; |
| 546 | |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 547 | rix = ah->rate_idx[ah->curchan->band][hw_rix]; |
Bob Copeland | b726604 | 2009-03-02 21:55:18 -0500 | [diff] [blame] | 548 | if (WARN(rix < 0, "invalid hw_rix: %x\n", hw_rix)) |
| 549 | rix = 0; |
| 550 | |
| 551 | return rix; |
Luis R. Rodriguez | d8ee398 | 2008-02-03 21:51:04 -0500 | [diff] [blame] | 552 | } |
| 553 | |
Jiri Slaby | fa1c114 | 2007-08-12 17:33:16 +0200 | [diff] [blame] | 554 | /***************\ |
| 555 | * Buffers setup * |
| 556 | \***************/ |
| 557 | |
Bob Copeland | b6ea035 | 2009-01-10 14:42:54 -0500 | [diff] [blame] | 558 | static |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 559 | struct sk_buff *ath5k_rx_skb_alloc(struct ath5k_hw *ah, dma_addr_t *skb_addr) |
Bob Copeland | b6ea035 | 2009-01-10 14:42:54 -0500 | [diff] [blame] | 560 | { |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 561 | struct ath_common *common = ath5k_hw_common(ah); |
Bob Copeland | b6ea035 | 2009-01-10 14:42:54 -0500 | [diff] [blame] | 562 | struct sk_buff *skb; |
Bob Copeland | b6ea035 | 2009-01-10 14:42:54 -0500 | [diff] [blame] | 563 | |
| 564 | /* |
| 565 | * Allocate buffer with headroom_needed space for the |
| 566 | * fake physical layer header at the start. |
| 567 | */ |
Luis R. Rodriguez | db71971 | 2009-09-10 11:20:57 -0700 | [diff] [blame] | 568 | skb = ath_rxbuf_alloc(common, |
Luis R. Rodriguez | dd84978 | 2009-11-04 09:44:50 -0800 | [diff] [blame] | 569 | common->rx_bufsize, |
Luis R. Rodriguez | aeb63cf | 2009-08-12 09:57:00 -0700 | [diff] [blame] | 570 | GFP_ATOMIC); |
Bob Copeland | b6ea035 | 2009-01-10 14:42:54 -0500 | [diff] [blame] | 571 | |
| 572 | if (!skb) { |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 573 | ATH5K_ERR(ah, "can't alloc skbuff of size %u\n", |
Luis R. Rodriguez | dd84978 | 2009-11-04 09:44:50 -0800 | [diff] [blame] | 574 | common->rx_bufsize); |
Bob Copeland | b6ea035 | 2009-01-10 14:42:54 -0500 | [diff] [blame] | 575 | return NULL; |
| 576 | } |
Bob Copeland | b6ea035 | 2009-01-10 14:42:54 -0500 | [diff] [blame] | 577 | |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 578 | *skb_addr = dma_map_single(ah->dev, |
Luis R. Rodriguez | cc861f7 | 2009-11-04 09:11:34 -0800 | [diff] [blame] | 579 | skb->data, common->rx_bufsize, |
Felix Fietkau | aeae4ac | 2010-12-02 10:26:51 +0100 | [diff] [blame] | 580 | DMA_FROM_DEVICE); |
| 581 | |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 582 | if (unlikely(dma_mapping_error(ah->dev, *skb_addr))) { |
| 583 | ATH5K_ERR(ah, "%s: DMA mapping failed\n", __func__); |
Bob Copeland | b6ea035 | 2009-01-10 14:42:54 -0500 | [diff] [blame] | 584 | dev_kfree_skb(skb); |
| 585 | return NULL; |
| 586 | } |
| 587 | return skb; |
| 588 | } |
| 589 | |
Jiri Slaby | fa1c114 | 2007-08-12 17:33:16 +0200 | [diff] [blame] | 590 | static int |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 591 | ath5k_rxbuf_setup(struct ath5k_hw *ah, struct ath5k_buf *bf) |
Jiri Slaby | fa1c114 | 2007-08-12 17:33:16 +0200 | [diff] [blame] | 592 | { |
Jiri Slaby | fa1c114 | 2007-08-12 17:33:16 +0200 | [diff] [blame] | 593 | struct sk_buff *skb = bf->skb; |
| 594 | struct ath5k_desc *ds; |
Bruno Randolf | b5eae9f | 2010-05-19 10:18:16 +0900 | [diff] [blame] | 595 | int ret; |
Jiri Slaby | fa1c114 | 2007-08-12 17:33:16 +0200 | [diff] [blame] | 596 | |
Bob Copeland | b6ea035 | 2009-01-10 14:42:54 -0500 | [diff] [blame] | 597 | if (!skb) { |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 598 | skb = ath5k_rx_skb_alloc(ah, &bf->skbaddr); |
Bob Copeland | b6ea035 | 2009-01-10 14:42:54 -0500 | [diff] [blame] | 599 | if (!skb) |
Jiri Slaby | fa1c114 | 2007-08-12 17:33:16 +0200 | [diff] [blame] | 600 | return -ENOMEM; |
Jiri Slaby | fa1c114 | 2007-08-12 17:33:16 +0200 | [diff] [blame] | 601 | bf->skb = skb; |
Jiri Slaby | fa1c114 | 2007-08-12 17:33:16 +0200 | [diff] [blame] | 602 | } |
| 603 | |
| 604 | /* |
| 605 | * Setup descriptors. For receive we always terminate |
| 606 | * the descriptor list with a self-linked entry so we'll |
| 607 | * not get overrun under high load (as can happen with a |
| 608 | * 5212 when ANI processing enables PHY error frames). |
| 609 | * |
Bruno Randolf | beade63 | 2010-06-16 19:11:25 +0900 | [diff] [blame] | 610 | * To ensure the last descriptor is self-linked we create |
Jiri Slaby | fa1c114 | 2007-08-12 17:33:16 +0200 | [diff] [blame] | 611 | * each descriptor as self-linked and add it to the end. As |
| 612 | * each additional descriptor is added the previous self-linked |
Bruno Randolf | beade63 | 2010-06-16 19:11:25 +0900 | [diff] [blame] | 613 | * entry is "fixed" naturally. This should be safe even |
Jiri Slaby | fa1c114 | 2007-08-12 17:33:16 +0200 | [diff] [blame] | 614 | * if DMA is happening. When processing RX interrupts we |
| 615 | * never remove/process the last, self-linked, entry on the |
Bruno Randolf | beade63 | 2010-06-16 19:11:25 +0900 | [diff] [blame] | 616 | * descriptor list. This ensures the hardware always has |
Jiri Slaby | fa1c114 | 2007-08-12 17:33:16 +0200 | [diff] [blame] | 617 | * someplace to write a new frame. |
| 618 | */ |
| 619 | ds = bf->desc; |
| 620 | ds->ds_link = bf->daddr; /* link to self */ |
| 621 | ds->ds_data = bf->skbaddr; |
Bruno Randolf | a666819 | 2010-06-16 19:12:01 +0900 | [diff] [blame] | 622 | ret = ath5k_hw_setup_rx_desc(ah, ds, ah->common.rx_bufsize, 0); |
Bruno Randolf | 0452d4a | 2010-06-16 19:11:35 +0900 | [diff] [blame] | 623 | if (ret) { |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 624 | ATH5K_ERR(ah, "%s: could not setup RX desc\n", __func__); |
Bruno Randolf | b5eae9f | 2010-05-19 10:18:16 +0900 | [diff] [blame] | 625 | return ret; |
Bruno Randolf | 0452d4a | 2010-06-16 19:11:35 +0900 | [diff] [blame] | 626 | } |
Jiri Slaby | fa1c114 | 2007-08-12 17:33:16 +0200 | [diff] [blame] | 627 | |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 628 | if (ah->rxlink != NULL) |
| 629 | *ah->rxlink = bf->daddr; |
| 630 | ah->rxlink = &ds->ds_link; |
Jiri Slaby | fa1c114 | 2007-08-12 17:33:16 +0200 | [diff] [blame] | 631 | return 0; |
| 632 | } |
| 633 | |
Bob Copeland | 2ac2927 | 2010-02-09 13:06:54 -0500 | [diff] [blame] | 634 | static enum ath5k_pkt_type get_hw_packet_type(struct sk_buff *skb) |
| 635 | { |
| 636 | struct ieee80211_hdr *hdr; |
| 637 | enum ath5k_pkt_type htype; |
| 638 | __le16 fc; |
| 639 | |
| 640 | hdr = (struct ieee80211_hdr *)skb->data; |
| 641 | fc = hdr->frame_control; |
| 642 | |
| 643 | if (ieee80211_is_beacon(fc)) |
| 644 | htype = AR5K_PKT_TYPE_BEACON; |
| 645 | else if (ieee80211_is_probe_resp(fc)) |
| 646 | htype = AR5K_PKT_TYPE_PROBE_RESP; |
| 647 | else if (ieee80211_is_atim(fc)) |
| 648 | htype = AR5K_PKT_TYPE_ATIM; |
| 649 | else if (ieee80211_is_pspoll(fc)) |
| 650 | htype = AR5K_PKT_TYPE_PSPOLL; |
| 651 | else |
| 652 | htype = AR5K_PKT_TYPE_NORMAL; |
| 653 | |
| 654 | return htype; |
| 655 | } |
| 656 | |
Jiri Slaby | fa1c114 | 2007-08-12 17:33:16 +0200 | [diff] [blame] | 657 | static int |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 658 | ath5k_txbuf_setup(struct ath5k_hw *ah, struct ath5k_buf *bf, |
Benoit Papillault | 8127fbd | 2010-02-27 23:05:26 +0100 | [diff] [blame] | 659 | struct ath5k_txq *txq, int padsize) |
Jiri Slaby | fa1c114 | 2007-08-12 17:33:16 +0200 | [diff] [blame] | 660 | { |
Jiri Slaby | fa1c114 | 2007-08-12 17:33:16 +0200 | [diff] [blame] | 661 | struct ath5k_desc *ds = bf->desc; |
| 662 | struct sk_buff *skb = bf->skb; |
Johannes Berg | a888d52 | 2008-05-26 16:43:39 +0200 | [diff] [blame] | 663 | struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb); |
Jiri Slaby | fa1c114 | 2007-08-12 17:33:16 +0200 | [diff] [blame] | 664 | unsigned int pktlen, flags, keyidx = AR5K_TXKEYIX_INVALID; |
Felix Fietkau | 2f7fe87 | 2008-10-05 18:05:48 +0200 | [diff] [blame] | 665 | struct ieee80211_rate *rate; |
| 666 | unsigned int mrr_rate[3], mrr_tries[3]; |
| 667 | int i, ret; |
Bob Copeland | 8902ff4 | 2009-01-22 08:44:20 -0500 | [diff] [blame] | 668 | u16 hw_rate; |
Bob Copeland | 07c1e85 | 2009-01-22 08:44:21 -0500 | [diff] [blame] | 669 | u16 cts_rate = 0; |
| 670 | u16 duration = 0; |
Bob Copeland | 8902ff4 | 2009-01-22 08:44:20 -0500 | [diff] [blame] | 671 | u8 rc_flags; |
Jiri Slaby | fa1c114 | 2007-08-12 17:33:16 +0200 | [diff] [blame] | 672 | |
| 673 | flags = AR5K_TXDESC_INTREQ | AR5K_TXDESC_CLRDMASK; |
Johannes Berg | e039fa4 | 2008-05-15 12:55:29 +0200 | [diff] [blame] | 674 | |
Jiri Slaby | fa1c114 | 2007-08-12 17:33:16 +0200 | [diff] [blame] | 675 | /* XXX endianness */ |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 676 | bf->skbaddr = dma_map_single(ah->dev, skb->data, skb->len, |
Felix Fietkau | aeae4ac | 2010-12-02 10:26:51 +0100 | [diff] [blame] | 677 | DMA_TO_DEVICE); |
Jiri Slaby | fa1c114 | 2007-08-12 17:33:16 +0200 | [diff] [blame] | 678 | |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 679 | rate = ieee80211_get_tx_rate(ah->hw, info); |
John W. Linville | d8e1ba7 | 2010-08-24 15:27:34 -0400 | [diff] [blame] | 680 | if (!rate) { |
| 681 | ret = -EINVAL; |
| 682 | goto err_unmap; |
| 683 | } |
Bob Copeland | 8902ff4 | 2009-01-22 08:44:20 -0500 | [diff] [blame] | 684 | |
Johannes Berg | e039fa4 | 2008-05-15 12:55:29 +0200 | [diff] [blame] | 685 | if (info->flags & IEEE80211_TX_CTL_NO_ACK) |
Jiri Slaby | fa1c114 | 2007-08-12 17:33:16 +0200 | [diff] [blame] | 686 | flags |= AR5K_TXDESC_NOACK; |
| 687 | |
Bob Copeland | 8902ff4 | 2009-01-22 08:44:20 -0500 | [diff] [blame] | 688 | rc_flags = info->control.rates[0].flags; |
| 689 | hw_rate = (rc_flags & IEEE80211_TX_RC_USE_SHORT_PREAMBLE) ? |
| 690 | rate->hw_value_short : rate->hw_value; |
| 691 | |
Bruno Randolf | 281c56d | 2008-02-05 18:44:55 +0900 | [diff] [blame] | 692 | pktlen = skb->len; |
Jiri Slaby | fa1c114 | 2007-08-12 17:33:16 +0200 | [diff] [blame] | 693 | |
Nick Kossifidis | 8f655dd | 2009-03-15 22:20:35 +0200 | [diff] [blame] | 694 | /* FIXME: If we are in g mode and rate is a CCK rate |
| 695 | * subtract ah->ah_txpower.txp_cck_ofdm_pwr_delta |
| 696 | * from tx power (value is in dB units already) */ |
Bob Copeland | 362695e | 2009-02-15 12:06:12 -0500 | [diff] [blame] | 697 | if (info->control.hw_key) { |
| 698 | keyidx = info->control.hw_key->hw_key_idx; |
| 699 | pktlen += info->control.hw_key->icv_len; |
| 700 | } |
Bob Copeland | 07c1e85 | 2009-01-22 08:44:21 -0500 | [diff] [blame] | 701 | if (rc_flags & IEEE80211_TX_RC_USE_RTS_CTS) { |
| 702 | flags |= AR5K_TXDESC_RTSENA; |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 703 | cts_rate = ieee80211_get_rts_cts_rate(ah->hw, info)->hw_value; |
| 704 | duration = le16_to_cpu(ieee80211_rts_duration(ah->hw, |
Ben Greear | b1ae1ed | 2010-09-30 12:22:58 -0700 | [diff] [blame] | 705 | info->control.vif, pktlen, info)); |
Bob Copeland | 07c1e85 | 2009-01-22 08:44:21 -0500 | [diff] [blame] | 706 | } |
| 707 | if (rc_flags & IEEE80211_TX_RC_USE_CTS_PROTECT) { |
| 708 | flags |= AR5K_TXDESC_CTSENA; |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 709 | cts_rate = ieee80211_get_rts_cts_rate(ah->hw, info)->hw_value; |
| 710 | duration = le16_to_cpu(ieee80211_ctstoself_duration(ah->hw, |
Ben Greear | b1ae1ed | 2010-09-30 12:22:58 -0700 | [diff] [blame] | 711 | info->control.vif, pktlen, info)); |
Bob Copeland | 07c1e85 | 2009-01-22 08:44:21 -0500 | [diff] [blame] | 712 | } |
Jiri Slaby | fa1c114 | 2007-08-12 17:33:16 +0200 | [diff] [blame] | 713 | ret = ah->ah_setup_tx_desc(ah, ds, pktlen, |
Benoit Papillault | 8127fbd | 2010-02-27 23:05:26 +0100 | [diff] [blame] | 714 | ieee80211_get_hdrlen_from_skb(skb), padsize, |
Bob Copeland | 2ac2927 | 2010-02-09 13:06:54 -0500 | [diff] [blame] | 715 | get_hw_packet_type(skb), |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 716 | (ah->power_level * 2), |
Bob Copeland | 8902ff4 | 2009-01-22 08:44:20 -0500 | [diff] [blame] | 717 | hw_rate, |
Nick Kossifidis | 2bed03e | 2009-04-30 15:55:49 -0400 | [diff] [blame] | 718 | info->control.rates[0].count, keyidx, ah->ah_tx_ant, flags, |
Bob Copeland | 07c1e85 | 2009-01-22 08:44:21 -0500 | [diff] [blame] | 719 | cts_rate, duration); |
Jiri Slaby | fa1c114 | 2007-08-12 17:33:16 +0200 | [diff] [blame] | 720 | if (ret) |
| 721 | goto err_unmap; |
| 722 | |
Felix Fietkau | 2f7fe87 | 2008-10-05 18:05:48 +0200 | [diff] [blame] | 723 | memset(mrr_rate, 0, sizeof(mrr_rate)); |
| 724 | memset(mrr_tries, 0, sizeof(mrr_tries)); |
| 725 | for (i = 0; i < 3; i++) { |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 726 | rate = ieee80211_get_alt_retry_rate(ah->hw, info, i); |
Felix Fietkau | 2f7fe87 | 2008-10-05 18:05:48 +0200 | [diff] [blame] | 727 | if (!rate) |
| 728 | break; |
| 729 | |
| 730 | mrr_rate[i] = rate->hw_value; |
Johannes Berg | e6a9854 | 2008-10-21 12:40:02 +0200 | [diff] [blame] | 731 | mrr_tries[i] = info->control.rates[i + 1].count; |
Felix Fietkau | 2f7fe87 | 2008-10-05 18:05:48 +0200 | [diff] [blame] | 732 | } |
| 733 | |
Bruno Randolf | a666819 | 2010-06-16 19:12:01 +0900 | [diff] [blame] | 734 | ath5k_hw_setup_mrr_tx_desc(ah, ds, |
Felix Fietkau | 2f7fe87 | 2008-10-05 18:05:48 +0200 | [diff] [blame] | 735 | mrr_rate[0], mrr_tries[0], |
| 736 | mrr_rate[1], mrr_tries[1], |
| 737 | mrr_rate[2], mrr_tries[2]); |
| 738 | |
Jiri Slaby | fa1c114 | 2007-08-12 17:33:16 +0200 | [diff] [blame] | 739 | ds->ds_link = 0; |
| 740 | ds->ds_data = bf->skbaddr; |
| 741 | |
| 742 | spin_lock_bh(&txq->lock); |
| 743 | list_add_tail(&bf->list, &txq->q); |
Bruno Randolf | 925e0b0 | 2010-09-17 11:36:35 +0900 | [diff] [blame] | 744 | txq->txq_len++; |
Jiri Slaby | fa1c114 | 2007-08-12 17:33:16 +0200 | [diff] [blame] | 745 | if (txq->link == NULL) /* is this first packet? */ |
Nick Kossifidis | c6e387a | 2008-08-29 22:45:39 +0300 | [diff] [blame] | 746 | ath5k_hw_set_txdp(ah, txq->qnum, bf->daddr); |
Jiri Slaby | fa1c114 | 2007-08-12 17:33:16 +0200 | [diff] [blame] | 747 | else /* no, so only link it */ |
| 748 | *txq->link = bf->daddr; |
| 749 | |
| 750 | txq->link = &ds->ds_link; |
Nick Kossifidis | c6e387a | 2008-08-29 22:45:39 +0300 | [diff] [blame] | 751 | ath5k_hw_start_tx_dma(ah, txq->qnum); |
Jiri Slaby | 274c7c3 | 2008-07-15 17:44:20 +0200 | [diff] [blame] | 752 | mmiowb(); |
Jiri Slaby | fa1c114 | 2007-08-12 17:33:16 +0200 | [diff] [blame] | 753 | spin_unlock_bh(&txq->lock); |
| 754 | |
| 755 | return 0; |
| 756 | err_unmap: |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 757 | dma_unmap_single(ah->dev, bf->skbaddr, skb->len, DMA_TO_DEVICE); |
Jiri Slaby | fa1c114 | 2007-08-12 17:33:16 +0200 | [diff] [blame] | 758 | return ret; |
| 759 | } |
| 760 | |
| 761 | /*******************\ |
| 762 | * Descriptors setup * |
| 763 | \*******************/ |
| 764 | |
| 765 | static int |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 766 | ath5k_desc_alloc(struct ath5k_hw *ah) |
Jiri Slaby | fa1c114 | 2007-08-12 17:33:16 +0200 | [diff] [blame] | 767 | { |
| 768 | struct ath5k_desc *ds; |
| 769 | struct ath5k_buf *bf; |
| 770 | dma_addr_t da; |
| 771 | unsigned int i; |
| 772 | int ret; |
| 773 | |
| 774 | /* allocate descriptors */ |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 775 | ah->desc_len = sizeof(struct ath5k_desc) * |
Jiri Slaby | fa1c114 | 2007-08-12 17:33:16 +0200 | [diff] [blame] | 776 | (ATH_TXBUF + ATH_RXBUF + ATH_BCBUF + 1); |
Felix Fietkau | aeae4ac | 2010-12-02 10:26:51 +0100 | [diff] [blame] | 777 | |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 778 | ah->desc = dma_alloc_coherent(ah->dev, ah->desc_len, |
| 779 | &ah->desc_daddr, GFP_KERNEL); |
| 780 | if (ah->desc == NULL) { |
| 781 | ATH5K_ERR(ah, "can't allocate descriptors\n"); |
Jiri Slaby | fa1c114 | 2007-08-12 17:33:16 +0200 | [diff] [blame] | 782 | ret = -ENOMEM; |
| 783 | goto err; |
| 784 | } |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 785 | ds = ah->desc; |
| 786 | da = ah->desc_daddr; |
| 787 | ATH5K_DBG(ah, ATH5K_DEBUG_ANY, "DMA map: %p (%zu) -> %llx\n", |
| 788 | ds, ah->desc_len, (unsigned long long)ah->desc_daddr); |
Jiri Slaby | fa1c114 | 2007-08-12 17:33:16 +0200 | [diff] [blame] | 789 | |
| 790 | bf = kcalloc(1 + ATH_TXBUF + ATH_RXBUF + ATH_BCBUF, |
| 791 | sizeof(struct ath5k_buf), GFP_KERNEL); |
| 792 | if (bf == NULL) { |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 793 | ATH5K_ERR(ah, "can't allocate bufptr\n"); |
Jiri Slaby | fa1c114 | 2007-08-12 17:33:16 +0200 | [diff] [blame] | 794 | ret = -ENOMEM; |
| 795 | goto err_free; |
| 796 | } |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 797 | ah->bufptr = bf; |
Jiri Slaby | fa1c114 | 2007-08-12 17:33:16 +0200 | [diff] [blame] | 798 | |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 799 | INIT_LIST_HEAD(&ah->rxbuf); |
Jiri Slaby | fa1c114 | 2007-08-12 17:33:16 +0200 | [diff] [blame] | 800 | for (i = 0; i < ATH_RXBUF; i++, bf++, ds++, da += sizeof(*ds)) { |
| 801 | bf->desc = ds; |
| 802 | bf->daddr = da; |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 803 | list_add_tail(&bf->list, &ah->rxbuf); |
Jiri Slaby | fa1c114 | 2007-08-12 17:33:16 +0200 | [diff] [blame] | 804 | } |
| 805 | |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 806 | INIT_LIST_HEAD(&ah->txbuf); |
| 807 | ah->txbuf_len = ATH_TXBUF; |
Pavel Roskin | e4bbf2f | 2011-07-07 18:14:13 -0400 | [diff] [blame] | 808 | for (i = 0; i < ATH_TXBUF; i++, bf++, ds++, da += sizeof(*ds)) { |
Jiri Slaby | fa1c114 | 2007-08-12 17:33:16 +0200 | [diff] [blame] | 809 | bf->desc = ds; |
| 810 | bf->daddr = da; |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 811 | list_add_tail(&bf->list, &ah->txbuf); |
Jiri Slaby | fa1c114 | 2007-08-12 17:33:16 +0200 | [diff] [blame] | 812 | } |
| 813 | |
Ben Greear | b1ae1ed | 2010-09-30 12:22:58 -0700 | [diff] [blame] | 814 | /* beacon buffers */ |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 815 | INIT_LIST_HEAD(&ah->bcbuf); |
Ben Greear | b1ae1ed | 2010-09-30 12:22:58 -0700 | [diff] [blame] | 816 | for (i = 0; i < ATH_BCBUF; i++, bf++, ds++, da += sizeof(*ds)) { |
| 817 | bf->desc = ds; |
| 818 | bf->daddr = da; |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 819 | list_add_tail(&bf->list, &ah->bcbuf); |
Ben Greear | b1ae1ed | 2010-09-30 12:22:58 -0700 | [diff] [blame] | 820 | } |
Jiri Slaby | fa1c114 | 2007-08-12 17:33:16 +0200 | [diff] [blame] | 821 | |
| 822 | return 0; |
| 823 | err_free: |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 824 | dma_free_coherent(ah->dev, ah->desc_len, ah->desc, ah->desc_daddr); |
Jiri Slaby | fa1c114 | 2007-08-12 17:33:16 +0200 | [diff] [blame] | 825 | err: |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 826 | ah->desc = NULL; |
Jiri Slaby | fa1c114 | 2007-08-12 17:33:16 +0200 | [diff] [blame] | 827 | return ret; |
| 828 | } |
| 829 | |
Bruno Randolf | cd2c548 | 2010-12-22 19:20:32 +0900 | [diff] [blame] | 830 | void |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 831 | ath5k_txbuf_free_skb(struct ath5k_hw *ah, struct ath5k_buf *bf) |
Bruno Randolf | cd2c548 | 2010-12-22 19:20:32 +0900 | [diff] [blame] | 832 | { |
| 833 | BUG_ON(!bf); |
| 834 | if (!bf->skb) |
| 835 | return; |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 836 | dma_unmap_single(ah->dev, bf->skbaddr, bf->skb->len, |
Bruno Randolf | cd2c548 | 2010-12-22 19:20:32 +0900 | [diff] [blame] | 837 | DMA_TO_DEVICE); |
| 838 | dev_kfree_skb_any(bf->skb); |
| 839 | bf->skb = NULL; |
| 840 | bf->skbaddr = 0; |
| 841 | bf->desc->ds_data = 0; |
| 842 | } |
| 843 | |
| 844 | void |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 845 | ath5k_rxbuf_free_skb(struct ath5k_hw *ah, struct ath5k_buf *bf) |
Bruno Randolf | cd2c548 | 2010-12-22 19:20:32 +0900 | [diff] [blame] | 846 | { |
Bruno Randolf | cd2c548 | 2010-12-22 19:20:32 +0900 | [diff] [blame] | 847 | struct ath_common *common = ath5k_hw_common(ah); |
| 848 | |
| 849 | BUG_ON(!bf); |
| 850 | if (!bf->skb) |
| 851 | return; |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 852 | dma_unmap_single(ah->dev, bf->skbaddr, common->rx_bufsize, |
Bruno Randolf | cd2c548 | 2010-12-22 19:20:32 +0900 | [diff] [blame] | 853 | DMA_FROM_DEVICE); |
| 854 | dev_kfree_skb_any(bf->skb); |
| 855 | bf->skb = NULL; |
| 856 | bf->skbaddr = 0; |
| 857 | bf->desc->ds_data = 0; |
| 858 | } |
| 859 | |
Jiri Slaby | fa1c114 | 2007-08-12 17:33:16 +0200 | [diff] [blame] | 860 | static void |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 861 | ath5k_desc_free(struct ath5k_hw *ah) |
Jiri Slaby | fa1c114 | 2007-08-12 17:33:16 +0200 | [diff] [blame] | 862 | { |
| 863 | struct ath5k_buf *bf; |
| 864 | |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 865 | list_for_each_entry(bf, &ah->txbuf, list) |
| 866 | ath5k_txbuf_free_skb(ah, bf); |
| 867 | list_for_each_entry(bf, &ah->rxbuf, list) |
| 868 | ath5k_rxbuf_free_skb(ah, bf); |
| 869 | list_for_each_entry(bf, &ah->bcbuf, list) |
| 870 | ath5k_txbuf_free_skb(ah, bf); |
Jiri Slaby | fa1c114 | 2007-08-12 17:33:16 +0200 | [diff] [blame] | 871 | |
| 872 | /* Free memory associated with all descriptors */ |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 873 | dma_free_coherent(ah->dev, ah->desc_len, ah->desc, ah->desc_daddr); |
| 874 | ah->desc = NULL; |
| 875 | ah->desc_daddr = 0; |
Jiri Slaby | fa1c114 | 2007-08-12 17:33:16 +0200 | [diff] [blame] | 876 | |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 877 | kfree(ah->bufptr); |
| 878 | ah->bufptr = NULL; |
Jiri Slaby | fa1c114 | 2007-08-12 17:33:16 +0200 | [diff] [blame] | 879 | } |
| 880 | |
| 881 | |
Jiri Slaby | fa1c114 | 2007-08-12 17:33:16 +0200 | [diff] [blame] | 882 | /**************\ |
| 883 | * Queues setup * |
| 884 | \**************/ |
| 885 | |
| 886 | static struct ath5k_txq * |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 887 | ath5k_txq_setup(struct ath5k_hw *ah, |
Jiri Slaby | fa1c114 | 2007-08-12 17:33:16 +0200 | [diff] [blame] | 888 | int qtype, int subtype) |
| 889 | { |
Jiri Slaby | fa1c114 | 2007-08-12 17:33:16 +0200 | [diff] [blame] | 890 | struct ath5k_txq *txq; |
| 891 | struct ath5k_txq_info qi = { |
| 892 | .tqi_subtype = subtype, |
Bruno Randolf | de8af45 | 2010-09-17 11:37:12 +0900 | [diff] [blame] | 893 | /* XXX: default values not correct for B and XR channels, |
| 894 | * but who cares? */ |
| 895 | .tqi_aifs = AR5K_TUNE_AIFS, |
| 896 | .tqi_cw_min = AR5K_TUNE_CWMIN, |
| 897 | .tqi_cw_max = AR5K_TUNE_CWMAX |
Jiri Slaby | fa1c114 | 2007-08-12 17:33:16 +0200 | [diff] [blame] | 898 | }; |
| 899 | int qnum; |
| 900 | |
| 901 | /* |
| 902 | * Enable interrupts only for EOL and DESC conditions. |
| 903 | * We mark tx descriptors to receive a DESC interrupt |
Bob Copeland | a180a13 | 2010-08-15 13:03:12 -0400 | [diff] [blame] | 904 | * when a tx queue gets deep; otherwise we wait for the |
Jiri Slaby | fa1c114 | 2007-08-12 17:33:16 +0200 | [diff] [blame] | 905 | * EOL to reap descriptors. Note that this is done to |
| 906 | * reduce interrupt load and this only defers reaping |
| 907 | * descriptors, never transmitting frames. Aside from |
| 908 | * reducing interrupts this also permits more concurrency. |
| 909 | * The only potential downside is if the tx queue backs |
| 910 | * up in which case the top half of the kernel may backup |
| 911 | * due to a lack of tx descriptors. |
| 912 | */ |
| 913 | qi.tqi_flags = AR5K_TXQ_FLAG_TXEOLINT_ENABLE | |
| 914 | AR5K_TXQ_FLAG_TXDESCINT_ENABLE; |
| 915 | qnum = ath5k_hw_setup_tx_queue(ah, qtype, &qi); |
| 916 | if (qnum < 0) { |
| 917 | /* |
| 918 | * NB: don't print a message, this happens |
| 919 | * normally on parts with too few tx queues |
| 920 | */ |
| 921 | return ERR_PTR(qnum); |
| 922 | } |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 923 | txq = &ah->txqs[qnum]; |
Jiri Slaby | fa1c114 | 2007-08-12 17:33:16 +0200 | [diff] [blame] | 924 | if (!txq->setup) { |
| 925 | txq->qnum = qnum; |
| 926 | txq->link = NULL; |
| 927 | INIT_LIST_HEAD(&txq->q); |
| 928 | spin_lock_init(&txq->lock); |
| 929 | txq->setup = true; |
Bruno Randolf | 925e0b0 | 2010-09-17 11:36:35 +0900 | [diff] [blame] | 930 | txq->txq_len = 0; |
John W. Linville | 81266ba | 2011-03-07 16:32:59 -0500 | [diff] [blame] | 931 | txq->txq_max = ATH5K_TXQ_LEN_MAX; |
Bruno Randolf | 4edd761 | 2010-09-17 11:36:56 +0900 | [diff] [blame] | 932 | txq->txq_poll_mark = false; |
Bruno Randolf | 923e5b3 | 2010-09-17 11:37:02 +0900 | [diff] [blame] | 933 | txq->txq_stuck = 0; |
Jiri Slaby | fa1c114 | 2007-08-12 17:33:16 +0200 | [diff] [blame] | 934 | } |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 935 | return &ah->txqs[qnum]; |
Jiri Slaby | fa1c114 | 2007-08-12 17:33:16 +0200 | [diff] [blame] | 936 | } |
| 937 | |
| 938 | static int |
| 939 | ath5k_beaconq_setup(struct ath5k_hw *ah) |
| 940 | { |
| 941 | struct ath5k_txq_info qi = { |
Bruno Randolf | de8af45 | 2010-09-17 11:37:12 +0900 | [diff] [blame] | 942 | /* XXX: default values not correct for B and XR channels, |
| 943 | * but who cares? */ |
| 944 | .tqi_aifs = AR5K_TUNE_AIFS, |
| 945 | .tqi_cw_min = AR5K_TUNE_CWMIN, |
| 946 | .tqi_cw_max = AR5K_TUNE_CWMAX, |
Jiri Slaby | fa1c114 | 2007-08-12 17:33:16 +0200 | [diff] [blame] | 947 | /* NB: for dynamic turbo, don't enable any other interrupts */ |
| 948 | .tqi_flags = AR5K_TXQ_FLAG_TXDESCINT_ENABLE |
| 949 | }; |
| 950 | |
| 951 | return ath5k_hw_setup_tx_queue(ah, AR5K_TX_QUEUE_BEACON, &qi); |
| 952 | } |
| 953 | |
| 954 | static int |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 955 | ath5k_beaconq_config(struct ath5k_hw *ah) |
Jiri Slaby | fa1c114 | 2007-08-12 17:33:16 +0200 | [diff] [blame] | 956 | { |
Jiri Slaby | fa1c114 | 2007-08-12 17:33:16 +0200 | [diff] [blame] | 957 | struct ath5k_txq_info qi; |
| 958 | int ret; |
| 959 | |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 960 | ret = ath5k_hw_get_tx_queueprops(ah, ah->bhalq, &qi); |
Jiri Slaby | fa1c114 | 2007-08-12 17:33:16 +0200 | [diff] [blame] | 961 | if (ret) |
Bob Copeland | a951ae2 | 2010-01-20 23:51:04 -0500 | [diff] [blame] | 962 | goto err; |
| 963 | |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 964 | if (ah->opmode == NL80211_IFTYPE_AP || |
| 965 | ah->opmode == NL80211_IFTYPE_MESH_POINT) { |
Jiri Slaby | fa1c114 | 2007-08-12 17:33:16 +0200 | [diff] [blame] | 966 | /* |
| 967 | * Always burst out beacon and CAB traffic |
| 968 | * (aifs = cwmin = cwmax = 0) |
| 969 | */ |
| 970 | qi.tqi_aifs = 0; |
| 971 | qi.tqi_cw_min = 0; |
| 972 | qi.tqi_cw_max = 0; |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 973 | } else if (ah->opmode == NL80211_IFTYPE_ADHOC) { |
Bruno Randolf | 6d91e1d | 2008-01-19 18:18:41 +0900 | [diff] [blame] | 974 | /* |
| 975 | * Adhoc mode; backoff between 0 and (2 * cw_min). |
| 976 | */ |
| 977 | qi.tqi_aifs = 0; |
| 978 | qi.tqi_cw_min = 0; |
Bruno Randolf | de8af45 | 2010-09-17 11:37:12 +0900 | [diff] [blame] | 979 | qi.tqi_cw_max = 2 * AR5K_TUNE_CWMIN; |
Jiri Slaby | fa1c114 | 2007-08-12 17:33:16 +0200 | [diff] [blame] | 980 | } |
| 981 | |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 982 | ATH5K_DBG(ah, ATH5K_DEBUG_BEACON, |
Bruno Randolf | 6d91e1d | 2008-01-19 18:18:41 +0900 | [diff] [blame] | 983 | "beacon queueprops tqi_aifs:%d tqi_cw_min:%d tqi_cw_max:%d\n", |
| 984 | qi.tqi_aifs, qi.tqi_cw_min, qi.tqi_cw_max); |
| 985 | |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 986 | ret = ath5k_hw_set_tx_queueprops(ah, ah->bhalq, &qi); |
Jiri Slaby | fa1c114 | 2007-08-12 17:33:16 +0200 | [diff] [blame] | 987 | if (ret) { |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 988 | ATH5K_ERR(ah, "%s: unable to update parameters for beacon " |
Jiri Slaby | fa1c114 | 2007-08-12 17:33:16 +0200 | [diff] [blame] | 989 | "hardware queue!\n", __func__); |
Bob Copeland | a951ae2 | 2010-01-20 23:51:04 -0500 | [diff] [blame] | 990 | goto err; |
Jiri Slaby | fa1c114 | 2007-08-12 17:33:16 +0200 | [diff] [blame] | 991 | } |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 992 | ret = ath5k_hw_reset_tx_queue(ah, ah->bhalq); /* push to h/w */ |
Bob Copeland | a951ae2 | 2010-01-20 23:51:04 -0500 | [diff] [blame] | 993 | if (ret) |
| 994 | goto err; |
Jiri Slaby | fa1c114 | 2007-08-12 17:33:16 +0200 | [diff] [blame] | 995 | |
Bob Copeland | a951ae2 | 2010-01-20 23:51:04 -0500 | [diff] [blame] | 996 | /* reconfigure cabq with ready time to 80% of beacon_interval */ |
| 997 | ret = ath5k_hw_get_tx_queueprops(ah, AR5K_TX_QUEUE_ID_CAB, &qi); |
| 998 | if (ret) |
| 999 | goto err; |
| 1000 | |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 1001 | qi.tqi_ready_time = (ah->bintval * 80) / 100; |
Bob Copeland | a951ae2 | 2010-01-20 23:51:04 -0500 | [diff] [blame] | 1002 | ret = ath5k_hw_set_tx_queueprops(ah, AR5K_TX_QUEUE_ID_CAB, &qi); |
| 1003 | if (ret) |
| 1004 | goto err; |
| 1005 | |
| 1006 | ret = ath5k_hw_reset_tx_queue(ah, AR5K_TX_QUEUE_ID_CAB); |
| 1007 | err: |
| 1008 | return ret; |
Jiri Slaby | fa1c114 | 2007-08-12 17:33:16 +0200 | [diff] [blame] | 1009 | } |
| 1010 | |
Nick Kossifidis | 80dac9e | 2010-11-23 20:45:38 +0200 | [diff] [blame] | 1011 | /** |
| 1012 | * ath5k_drain_tx_buffs - Empty tx buffers |
| 1013 | * |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 1014 | * @ah The &struct ath5k_hw |
Nick Kossifidis | 80dac9e | 2010-11-23 20:45:38 +0200 | [diff] [blame] | 1015 | * |
| 1016 | * Empty tx buffers from all queues in preparation |
| 1017 | * of a reset or during shutdown. |
| 1018 | * |
| 1019 | * NB: this assumes output has been stopped and |
| 1020 | * we do not need to block ath5k_tx_tasklet |
Jiri Slaby | fa1c114 | 2007-08-12 17:33:16 +0200 | [diff] [blame] | 1021 | */ |
| 1022 | static void |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 1023 | ath5k_drain_tx_buffs(struct ath5k_hw *ah) |
Jiri Slaby | fa1c114 | 2007-08-12 17:33:16 +0200 | [diff] [blame] | 1024 | { |
Nick Kossifidis | 80dac9e | 2010-11-23 20:45:38 +0200 | [diff] [blame] | 1025 | struct ath5k_txq *txq; |
| 1026 | struct ath5k_buf *bf, *bf0; |
| 1027 | int i; |
Jiri Slaby | fa1c114 | 2007-08-12 17:33:16 +0200 | [diff] [blame] | 1028 | |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 1029 | for (i = 0; i < ARRAY_SIZE(ah->txqs); i++) { |
| 1030 | if (ah->txqs[i].setup) { |
| 1031 | txq = &ah->txqs[i]; |
Nick Kossifidis | 80dac9e | 2010-11-23 20:45:38 +0200 | [diff] [blame] | 1032 | spin_lock_bh(&txq->lock); |
| 1033 | list_for_each_entry_safe(bf, bf0, &txq->q, list) { |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 1034 | ath5k_debug_printtxbuf(ah, bf); |
Nick Kossifidis | 80dac9e | 2010-11-23 20:45:38 +0200 | [diff] [blame] | 1035 | |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 1036 | ath5k_txbuf_free_skb(ah, bf); |
Nick Kossifidis | 80dac9e | 2010-11-23 20:45:38 +0200 | [diff] [blame] | 1037 | |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 1038 | spin_lock_bh(&ah->txbuflock); |
| 1039 | list_move_tail(&bf->list, &ah->txbuf); |
| 1040 | ah->txbuf_len++; |
Nick Kossifidis | 80dac9e | 2010-11-23 20:45:38 +0200 | [diff] [blame] | 1041 | txq->txq_len--; |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 1042 | spin_unlock_bh(&ah->txbuflock); |
Jiri Slaby | fa1c114 | 2007-08-12 17:33:16 +0200 | [diff] [blame] | 1043 | } |
Nick Kossifidis | 80dac9e | 2010-11-23 20:45:38 +0200 | [diff] [blame] | 1044 | txq->link = NULL; |
| 1045 | txq->txq_poll_mark = false; |
| 1046 | spin_unlock_bh(&txq->lock); |
| 1047 | } |
Jiri Slaby | fa1c114 | 2007-08-12 17:33:16 +0200 | [diff] [blame] | 1048 | } |
Jiri Slaby | fa1c114 | 2007-08-12 17:33:16 +0200 | [diff] [blame] | 1049 | } |
| 1050 | |
| 1051 | static void |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 1052 | ath5k_txq_release(struct ath5k_hw *ah) |
Jiri Slaby | fa1c114 | 2007-08-12 17:33:16 +0200 | [diff] [blame] | 1053 | { |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 1054 | struct ath5k_txq *txq = ah->txqs; |
Jiri Slaby | fa1c114 | 2007-08-12 17:33:16 +0200 | [diff] [blame] | 1055 | unsigned int i; |
| 1056 | |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 1057 | for (i = 0; i < ARRAY_SIZE(ah->txqs); i++, txq++) |
Jiri Slaby | fa1c114 | 2007-08-12 17:33:16 +0200 | [diff] [blame] | 1058 | if (txq->setup) { |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 1059 | ath5k_hw_release_tx_queue(ah, txq->qnum); |
Jiri Slaby | fa1c114 | 2007-08-12 17:33:16 +0200 | [diff] [blame] | 1060 | txq->setup = false; |
| 1061 | } |
| 1062 | } |
| 1063 | |
| 1064 | |
Jiri Slaby | fa1c114 | 2007-08-12 17:33:16 +0200 | [diff] [blame] | 1065 | /*************\ |
| 1066 | * RX Handling * |
| 1067 | \*************/ |
| 1068 | |
| 1069 | /* |
| 1070 | * Enable the receive h/w following a reset. |
| 1071 | */ |
| 1072 | static int |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 1073 | ath5k_rx_start(struct ath5k_hw *ah) |
Jiri Slaby | fa1c114 | 2007-08-12 17:33:16 +0200 | [diff] [blame] | 1074 | { |
Luis R. Rodriguez | db71971 | 2009-09-10 11:20:57 -0700 | [diff] [blame] | 1075 | struct ath_common *common = ath5k_hw_common(ah); |
Jiri Slaby | fa1c114 | 2007-08-12 17:33:16 +0200 | [diff] [blame] | 1076 | struct ath5k_buf *bf; |
| 1077 | int ret; |
| 1078 | |
Nick Kossifidis | b612798 | 2010-08-15 13:03:11 -0400 | [diff] [blame] | 1079 | common->rx_bufsize = roundup(IEEE80211_MAX_FRAME_LEN, common->cachelsz); |
Jiri Slaby | fa1c114 | 2007-08-12 17:33:16 +0200 | [diff] [blame] | 1080 | |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 1081 | ATH5K_DBG(ah, ATH5K_DEBUG_RESET, "cachelsz %u rx_bufsize %u\n", |
Luis R. Rodriguez | cc861f7 | 2009-11-04 09:11:34 -0800 | [diff] [blame] | 1082 | common->cachelsz, common->rx_bufsize); |
Jiri Slaby | fa1c114 | 2007-08-12 17:33:16 +0200 | [diff] [blame] | 1083 | |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 1084 | spin_lock_bh(&ah->rxbuflock); |
| 1085 | ah->rxlink = NULL; |
| 1086 | list_for_each_entry(bf, &ah->rxbuf, list) { |
| 1087 | ret = ath5k_rxbuf_setup(ah, bf); |
Jiri Slaby | fa1c114 | 2007-08-12 17:33:16 +0200 | [diff] [blame] | 1088 | if (ret != 0) { |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 1089 | spin_unlock_bh(&ah->rxbuflock); |
Jiri Slaby | fa1c114 | 2007-08-12 17:33:16 +0200 | [diff] [blame] | 1090 | goto err; |
| 1091 | } |
| 1092 | } |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 1093 | bf = list_first_entry(&ah->rxbuf, struct ath5k_buf, list); |
Bob Copeland | 2692504 | 2009-04-15 07:57:36 -0400 | [diff] [blame] | 1094 | ath5k_hw_set_rxdp(ah, bf->daddr); |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 1095 | spin_unlock_bh(&ah->rxbuflock); |
Jiri Slaby | fa1c114 | 2007-08-12 17:33:16 +0200 | [diff] [blame] | 1096 | |
Nick Kossifidis | c6e387a | 2008-08-29 22:45:39 +0300 | [diff] [blame] | 1097 | ath5k_hw_start_rx_dma(ah); /* enable recv descriptors */ |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 1098 | ath5k_update_bssid_mask_and_opmode(ah, NULL); /* set filters, etc. */ |
Jiri Slaby | fa1c114 | 2007-08-12 17:33:16 +0200 | [diff] [blame] | 1099 | ath5k_hw_start_rx_pcu(ah); /* re-enable PCU/DMA engine */ |
| 1100 | |
| 1101 | return 0; |
| 1102 | err: |
| 1103 | return ret; |
| 1104 | } |
| 1105 | |
| 1106 | /* |
Nick Kossifidis | 80dac9e | 2010-11-23 20:45:38 +0200 | [diff] [blame] | 1107 | * Disable the receive logic on PCU (DRU) |
| 1108 | * In preparation for a shutdown. |
| 1109 | * |
| 1110 | * Note: Doesn't stop rx DMA, ath5k_hw_dma_stop |
| 1111 | * does. |
Jiri Slaby | fa1c114 | 2007-08-12 17:33:16 +0200 | [diff] [blame] | 1112 | */ |
| 1113 | static void |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 1114 | ath5k_rx_stop(struct ath5k_hw *ah) |
Jiri Slaby | fa1c114 | 2007-08-12 17:33:16 +0200 | [diff] [blame] | 1115 | { |
Jiri Slaby | fa1c114 | 2007-08-12 17:33:16 +0200 | [diff] [blame] | 1116 | |
Jiri Slaby | fa1c114 | 2007-08-12 17:33:16 +0200 | [diff] [blame] | 1117 | ath5k_hw_set_rx_filter(ah, 0); /* clear recv filter */ |
Nick Kossifidis | 80dac9e | 2010-11-23 20:45:38 +0200 | [diff] [blame] | 1118 | ath5k_hw_stop_rx_pcu(ah); /* disable PCU */ |
Jiri Slaby | fa1c114 | 2007-08-12 17:33:16 +0200 | [diff] [blame] | 1119 | |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 1120 | ath5k_debug_printrxbuffs(ah); |
Jiri Slaby | fa1c114 | 2007-08-12 17:33:16 +0200 | [diff] [blame] | 1121 | } |
| 1122 | |
| 1123 | static unsigned int |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 1124 | ath5k_rx_decrypted(struct ath5k_hw *ah, struct sk_buff *skb, |
Bruno Randolf | 8a89f06 | 2010-06-16 19:11:51 +0900 | [diff] [blame] | 1125 | struct ath5k_rx_status *rs) |
Jiri Slaby | fa1c114 | 2007-08-12 17:33:16 +0200 | [diff] [blame] | 1126 | { |
Luis R. Rodriguez | dc1e001 | 2009-11-04 17:47:31 -0800 | [diff] [blame] | 1127 | struct ath_common *common = ath5k_hw_common(ah); |
Jiri Slaby | fa1c114 | 2007-08-12 17:33:16 +0200 | [diff] [blame] | 1128 | struct ieee80211_hdr *hdr = (void *)skb->data; |
Harvey Harrison | 798ee98 | 2008-07-15 18:44:02 -0700 | [diff] [blame] | 1129 | unsigned int keyix, hlen; |
Jiri Slaby | fa1c114 | 2007-08-12 17:33:16 +0200 | [diff] [blame] | 1130 | |
Bruno Randolf | b47f407 | 2008-03-05 18:35:45 +0900 | [diff] [blame] | 1131 | if (!(rs->rs_status & AR5K_RXERR_DECRYPT) && |
| 1132 | rs->rs_keyix != AR5K_RXKEYIX_INVALID) |
Jiri Slaby | fa1c114 | 2007-08-12 17:33:16 +0200 | [diff] [blame] | 1133 | return RX_FLAG_DECRYPTED; |
| 1134 | |
| 1135 | /* Apparently when a default key is used to decrypt the packet |
| 1136 | the hw does not set the index used to decrypt. In such cases |
| 1137 | get the index from the packet. */ |
Harvey Harrison | 798ee98 | 2008-07-15 18:44:02 -0700 | [diff] [blame] | 1138 | hlen = ieee80211_hdrlen(hdr->frame_control); |
Harvey Harrison | 24b56e7 | 2008-06-14 23:33:38 -0700 | [diff] [blame] | 1139 | if (ieee80211_has_protected(hdr->frame_control) && |
| 1140 | !(rs->rs_status & AR5K_RXERR_DECRYPT) && |
| 1141 | skb->len >= hlen + 4) { |
Jiri Slaby | fa1c114 | 2007-08-12 17:33:16 +0200 | [diff] [blame] | 1142 | keyix = skb->data[hlen + 3] >> 6; |
| 1143 | |
Luis R. Rodriguez | dc1e001 | 2009-11-04 17:47:31 -0800 | [diff] [blame] | 1144 | if (test_bit(keyix, common->keymap)) |
Jiri Slaby | fa1c114 | 2007-08-12 17:33:16 +0200 | [diff] [blame] | 1145 | return RX_FLAG_DECRYPTED; |
| 1146 | } |
| 1147 | |
| 1148 | return 0; |
| 1149 | } |
| 1150 | |
Bruno Randolf | 036cd1e | 2008-01-19 18:18:21 +0900 | [diff] [blame] | 1151 | |
| 1152 | static void |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 1153 | ath5k_check_ibss_tsf(struct ath5k_hw *ah, struct sk_buff *skb, |
Bruno Randolf | 6ba81c2 | 2008-03-05 18:36:26 +0900 | [diff] [blame] | 1154 | struct ieee80211_rx_status *rxs) |
Bruno Randolf | 036cd1e | 2008-01-19 18:18:21 +0900 | [diff] [blame] | 1155 | { |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 1156 | struct ath_common *common = ath5k_hw_common(ah); |
Bruno Randolf | 6ba81c2 | 2008-03-05 18:36:26 +0900 | [diff] [blame] | 1157 | u64 tsf, bc_tstamp; |
Bruno Randolf | 036cd1e | 2008-01-19 18:18:21 +0900 | [diff] [blame] | 1158 | u32 hw_tu; |
| 1159 | struct ieee80211_mgmt *mgmt = (struct ieee80211_mgmt *)skb->data; |
| 1160 | |
Harvey Harrison | 24b56e7 | 2008-06-14 23:33:38 -0700 | [diff] [blame] | 1161 | if (ieee80211_is_beacon(mgmt->frame_control) && |
Pavel Roskin | 38c07b4 | 2008-02-26 17:59:14 -0500 | [diff] [blame] | 1162 | le16_to_cpu(mgmt->u.beacon.capab_info) & WLAN_CAPABILITY_IBSS && |
Luis R. Rodriguez | 954fece | 2009-09-10 10:51:33 -0700 | [diff] [blame] | 1163 | memcmp(mgmt->bssid, common->curbssid, ETH_ALEN) == 0) { |
Bruno Randolf | 036cd1e | 2008-01-19 18:18:21 +0900 | [diff] [blame] | 1164 | /* |
Bruno Randolf | 6ba81c2 | 2008-03-05 18:36:26 +0900 | [diff] [blame] | 1165 | * Received an IBSS beacon with the same BSSID. Hardware *must* |
| 1166 | * have updated the local TSF. We have to work around various |
| 1167 | * hardware bugs, though... |
Bruno Randolf | 036cd1e | 2008-01-19 18:18:21 +0900 | [diff] [blame] | 1168 | */ |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 1169 | tsf = ath5k_hw_get_tsf64(ah); |
Bruno Randolf | 6ba81c2 | 2008-03-05 18:36:26 +0900 | [diff] [blame] | 1170 | bc_tstamp = le64_to_cpu(mgmt->u.beacon.timestamp); |
| 1171 | hw_tu = TSF_TO_TU(tsf); |
| 1172 | |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 1173 | ATH5K_DBG_UNLIMIT(ah, ATH5K_DEBUG_BEACON, |
Bruno Randolf | 6ba81c2 | 2008-03-05 18:36:26 +0900 | [diff] [blame] | 1174 | "beacon %llx mactime %llx (diff %lld) tsf now %llx\n", |
John W. Linville | 06501d2 | 2008-04-01 17:38:47 -0400 | [diff] [blame] | 1175 | (unsigned long long)bc_tstamp, |
| 1176 | (unsigned long long)rxs->mactime, |
| 1177 | (unsigned long long)(rxs->mactime - bc_tstamp), |
| 1178 | (unsigned long long)tsf); |
Bruno Randolf | 6ba81c2 | 2008-03-05 18:36:26 +0900 | [diff] [blame] | 1179 | |
| 1180 | /* |
| 1181 | * Sometimes the HW will give us a wrong tstamp in the rx |
| 1182 | * status, causing the timestamp extension to go wrong. |
| 1183 | * (This seems to happen especially with beacon frames bigger |
| 1184 | * than 78 byte (incl. FCS)) |
| 1185 | * But we know that the receive timestamp must be later than the |
| 1186 | * timestamp of the beacon since HW must have synced to that. |
| 1187 | * |
| 1188 | * NOTE: here we assume mactime to be after the frame was |
| 1189 | * received, not like mac80211 which defines it at the start. |
| 1190 | */ |
| 1191 | if (bc_tstamp > rxs->mactime) { |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 1192 | ATH5K_DBG_UNLIMIT(ah, ATH5K_DEBUG_BEACON, |
Bruno Randolf | 6ba81c2 | 2008-03-05 18:36:26 +0900 | [diff] [blame] | 1193 | "fixing mactime from %llx to %llx\n", |
John W. Linville | 06501d2 | 2008-04-01 17:38:47 -0400 | [diff] [blame] | 1194 | (unsigned long long)rxs->mactime, |
| 1195 | (unsigned long long)tsf); |
Bruno Randolf | 6ba81c2 | 2008-03-05 18:36:26 +0900 | [diff] [blame] | 1196 | rxs->mactime = tsf; |
Bruno Randolf | 036cd1e | 2008-01-19 18:18:21 +0900 | [diff] [blame] | 1197 | } |
Bruno Randolf | 6ba81c2 | 2008-03-05 18:36:26 +0900 | [diff] [blame] | 1198 | |
| 1199 | /* |
| 1200 | * Local TSF might have moved higher than our beacon timers, |
| 1201 | * in that case we have to update them to continue sending |
| 1202 | * beacons. This also takes care of synchronizing beacon sending |
| 1203 | * times with other stations. |
| 1204 | */ |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 1205 | if (hw_tu >= ah->nexttbtt) |
| 1206 | ath5k_beacon_update_timers(ah, bc_tstamp); |
Bruno Randolf | 7f89612 | 2010-09-27 12:22:21 +0900 | [diff] [blame] | 1207 | |
| 1208 | /* Check if the beacon timers are still correct, because a TSF |
| 1209 | * update might have created a window between them - for a |
| 1210 | * longer description see the comment of this function: */ |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 1211 | if (!ath5k_hw_check_beacon_timers(ah, ah->bintval)) { |
| 1212 | ath5k_beacon_update_timers(ah, bc_tstamp); |
| 1213 | ATH5K_DBG_UNLIMIT(ah, ATH5K_DEBUG_BEACON, |
Bruno Randolf | 7f89612 | 2010-09-27 12:22:21 +0900 | [diff] [blame] | 1214 | "fixed beacon timers after beacon receive\n"); |
| 1215 | } |
Bruno Randolf | 036cd1e | 2008-01-19 18:18:21 +0900 | [diff] [blame] | 1216 | } |
| 1217 | } |
| 1218 | |
Bruno Randolf | b4ea449 | 2010-03-25 14:49:25 +0900 | [diff] [blame] | 1219 | static void |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 1220 | ath5k_update_beacon_rssi(struct ath5k_hw *ah, struct sk_buff *skb, int rssi) |
Bruno Randolf | b4ea449 | 2010-03-25 14:49:25 +0900 | [diff] [blame] | 1221 | { |
| 1222 | struct ieee80211_mgmt *mgmt = (struct ieee80211_mgmt *)skb->data; |
Bruno Randolf | b4ea449 | 2010-03-25 14:49:25 +0900 | [diff] [blame] | 1223 | struct ath_common *common = ath5k_hw_common(ah); |
| 1224 | |
| 1225 | /* only beacons from our BSSID */ |
| 1226 | if (!ieee80211_is_beacon(mgmt->frame_control) || |
| 1227 | memcmp(mgmt->bssid, common->curbssid, ETH_ALEN) != 0) |
| 1228 | return; |
| 1229 | |
Bruno Randolf | eef39be | 2010-11-16 10:58:43 +0900 | [diff] [blame] | 1230 | ewma_add(&ah->ah_beacon_rssi_avg, rssi); |
Bruno Randolf | b4ea449 | 2010-03-25 14:49:25 +0900 | [diff] [blame] | 1231 | |
| 1232 | /* in IBSS mode we should keep RSSI statistics per neighbour */ |
| 1233 | /* le16_to_cpu(mgmt->u.beacon.capab_info) & WLAN_CAPABILITY_IBSS */ |
| 1234 | } |
| 1235 | |
Benoit Papillault | 8127fbd | 2010-02-27 23:05:26 +0100 | [diff] [blame] | 1236 | /* |
Bob Copeland | a180a13 | 2010-08-15 13:03:12 -0400 | [diff] [blame] | 1237 | * Compute padding position. skb must contain an IEEE 802.11 frame |
Benoit Papillault | 8127fbd | 2010-02-27 23:05:26 +0100 | [diff] [blame] | 1238 | */ |
| 1239 | static int ath5k_common_padpos(struct sk_buff *skb) |
| 1240 | { |
Pavel Roskin | e4bbf2f | 2011-07-07 18:14:13 -0400 | [diff] [blame] | 1241 | struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data; |
Benoit Papillault | 8127fbd | 2010-02-27 23:05:26 +0100 | [diff] [blame] | 1242 | __le16 frame_control = hdr->frame_control; |
| 1243 | int padpos = 24; |
| 1244 | |
Pavel Roskin | d2c7f77 | 2011-07-07 18:14:07 -0400 | [diff] [blame] | 1245 | if (ieee80211_has_a4(frame_control)) |
Benoit Papillault | 8127fbd | 2010-02-27 23:05:26 +0100 | [diff] [blame] | 1246 | padpos += ETH_ALEN; |
Pavel Roskin | d2c7f77 | 2011-07-07 18:14:07 -0400 | [diff] [blame] | 1247 | |
| 1248 | if (ieee80211_is_data_qos(frame_control)) |
Benoit Papillault | 8127fbd | 2010-02-27 23:05:26 +0100 | [diff] [blame] | 1249 | padpos += IEEE80211_QOS_CTL_LEN; |
Benoit Papillault | 8127fbd | 2010-02-27 23:05:26 +0100 | [diff] [blame] | 1250 | |
| 1251 | return padpos; |
| 1252 | } |
| 1253 | |
| 1254 | /* |
Bob Copeland | a180a13 | 2010-08-15 13:03:12 -0400 | [diff] [blame] | 1255 | * This function expects an 802.11 frame and returns the number of |
| 1256 | * bytes added, or -1 if we don't have enough header room. |
Benoit Papillault | 8127fbd | 2010-02-27 23:05:26 +0100 | [diff] [blame] | 1257 | */ |
Benoit Papillault | 8127fbd | 2010-02-27 23:05:26 +0100 | [diff] [blame] | 1258 | static int ath5k_add_padding(struct sk_buff *skb) |
| 1259 | { |
| 1260 | int padpos = ath5k_common_padpos(skb); |
| 1261 | int padsize = padpos & 3; |
| 1262 | |
Pavel Roskin | e4bbf2f | 2011-07-07 18:14:13 -0400 | [diff] [blame] | 1263 | if (padsize && skb->len > padpos) { |
Benoit Papillault | 8127fbd | 2010-02-27 23:05:26 +0100 | [diff] [blame] | 1264 | |
| 1265 | if (skb_headroom(skb) < padsize) |
| 1266 | return -1; |
| 1267 | |
| 1268 | skb_push(skb, padsize); |
Pavel Roskin | e4bbf2f | 2011-07-07 18:14:13 -0400 | [diff] [blame] | 1269 | memmove(skb->data, skb->data + padsize, padpos); |
Benoit Papillault | 8127fbd | 2010-02-27 23:05:26 +0100 | [diff] [blame] | 1270 | return padsize; |
| 1271 | } |
| 1272 | |
| 1273 | return 0; |
| 1274 | } |
| 1275 | |
| 1276 | /* |
Bob Copeland | a180a13 | 2010-08-15 13:03:12 -0400 | [diff] [blame] | 1277 | * The MAC header is padded to have 32-bit boundary if the |
| 1278 | * packet payload is non-zero. The general calculation for |
| 1279 | * padsize would take into account odd header lengths: |
| 1280 | * padsize = 4 - (hdrlen & 3); however, since only |
| 1281 | * even-length headers are used, padding can only be 0 or 2 |
| 1282 | * bytes and we can optimize this a bit. We must not try to |
| 1283 | * remove padding from short control frames that do not have a |
| 1284 | * payload. |
| 1285 | * |
| 1286 | * This function expects an 802.11 frame and returns the number of |
| 1287 | * bytes removed. |
Benoit Papillault | 8127fbd | 2010-02-27 23:05:26 +0100 | [diff] [blame] | 1288 | */ |
Benoit Papillault | 8127fbd | 2010-02-27 23:05:26 +0100 | [diff] [blame] | 1289 | static int ath5k_remove_padding(struct sk_buff *skb) |
| 1290 | { |
| 1291 | int padpos = ath5k_common_padpos(skb); |
| 1292 | int padsize = padpos & 3; |
| 1293 | |
Pavel Roskin | e4bbf2f | 2011-07-07 18:14:13 -0400 | [diff] [blame] | 1294 | if (padsize && skb->len >= padpos + padsize) { |
Benoit Papillault | 8127fbd | 2010-02-27 23:05:26 +0100 | [diff] [blame] | 1295 | memmove(skb->data + padsize, skb->data, padpos); |
| 1296 | skb_pull(skb, padsize); |
| 1297 | return padsize; |
| 1298 | } |
| 1299 | |
| 1300 | return 0; |
| 1301 | } |
| 1302 | |
Jiri Slaby | fa1c114 | 2007-08-12 17:33:16 +0200 | [diff] [blame] | 1303 | static void |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 1304 | ath5k_receive_frame(struct ath5k_hw *ah, struct sk_buff *skb, |
Bruno Randolf | 8a89f06 | 2010-06-16 19:11:51 +0900 | [diff] [blame] | 1305 | struct ath5k_rx_status *rs) |
Jiri Slaby | fa1c114 | 2007-08-12 17:33:16 +0200 | [diff] [blame] | 1306 | { |
Bob Copeland | 1c5256b | 2009-08-24 23:00:32 -0400 | [diff] [blame] | 1307 | struct ieee80211_rx_status *rxs; |
Bruno Randolf | 8a89f06 | 2010-06-16 19:11:51 +0900 | [diff] [blame] | 1308 | |
Bruno Randolf | 8a89f06 | 2010-06-16 19:11:51 +0900 | [diff] [blame] | 1309 | ath5k_remove_padding(skb); |
| 1310 | |
| 1311 | rxs = IEEE80211_SKB_RXCB(skb); |
| 1312 | |
| 1313 | rxs->flag = 0; |
| 1314 | if (unlikely(rs->rs_status & AR5K_RXERR_MIC)) |
| 1315 | rxs->flag |= RX_FLAG_MMIC_ERROR; |
| 1316 | |
| 1317 | /* |
| 1318 | * always extend the mac timestamp, since this information is |
| 1319 | * also needed for proper IBSS merging. |
| 1320 | * |
| 1321 | * XXX: it might be too late to do it here, since rs_tstamp is |
| 1322 | * 15bit only. that means TSF extension has to be done within |
| 1323 | * 32768usec (about 32ms). it might be necessary to move this to |
| 1324 | * the interrupt handler, like it is done in madwifi. |
| 1325 | * |
| 1326 | * Unfortunately we don't know when the hardware takes the rx |
| 1327 | * timestamp (beginning of phy frame, data frame, end of rx?). |
| 1328 | * The only thing we know is that it is hardware specific... |
| 1329 | * On AR5213 it seems the rx timestamp is at the end of the |
Pavel Roskin | 6a2a0e7 | 2011-07-09 00:17:51 -0400 | [diff] [blame] | 1330 | * frame, but I'm not sure. |
Bruno Randolf | 8a89f06 | 2010-06-16 19:11:51 +0900 | [diff] [blame] | 1331 | * |
| 1332 | * NOTE: mac80211 defines mactime at the beginning of the first |
| 1333 | * data symbol. Since we don't have any time references it's |
| 1334 | * impossible to comply to that. This affects IBSS merge only |
| 1335 | * right now, so it's not too bad... |
| 1336 | */ |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 1337 | rxs->mactime = ath5k_extend_tsf(ah, rs->rs_tstamp); |
Johannes Berg | 6ebacbb | 2011-02-23 15:06:08 +0100 | [diff] [blame] | 1338 | rxs->flag |= RX_FLAG_MACTIME_MPDU; |
Bruno Randolf | 8a89f06 | 2010-06-16 19:11:51 +0900 | [diff] [blame] | 1339 | |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 1340 | rxs->freq = ah->curchan->center_freq; |
| 1341 | rxs->band = ah->curchan->band; |
Bruno Randolf | 8a89f06 | 2010-06-16 19:11:51 +0900 | [diff] [blame] | 1342 | |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 1343 | rxs->signal = ah->ah_noise_floor + rs->rs_rssi; |
Bruno Randolf | 8a89f06 | 2010-06-16 19:11:51 +0900 | [diff] [blame] | 1344 | |
| 1345 | rxs->antenna = rs->rs_antenna; |
| 1346 | |
| 1347 | if (rs->rs_antenna > 0 && rs->rs_antenna < 5) |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 1348 | ah->stats.antenna_rx[rs->rs_antenna]++; |
Bruno Randolf | 8a89f06 | 2010-06-16 19:11:51 +0900 | [diff] [blame] | 1349 | else |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 1350 | ah->stats.antenna_rx[0]++; /* invalid */ |
Bruno Randolf | 8a89f06 | 2010-06-16 19:11:51 +0900 | [diff] [blame] | 1351 | |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 1352 | rxs->rate_idx = ath5k_hw_to_driver_rix(ah, rs->rs_rate); |
| 1353 | rxs->flag |= ath5k_rx_decrypted(ah, skb, rs); |
Bruno Randolf | 8a89f06 | 2010-06-16 19:11:51 +0900 | [diff] [blame] | 1354 | |
| 1355 | if (rxs->rate_idx >= 0 && rs->rs_rate == |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 1356 | ah->sbands[ah->curchan->band].bitrates[rxs->rate_idx].hw_value_short) |
Bruno Randolf | 8a89f06 | 2010-06-16 19:11:51 +0900 | [diff] [blame] | 1357 | rxs->flag |= RX_FLAG_SHORTPRE; |
| 1358 | |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 1359 | trace_ath5k_rx(ah, skb); |
Bruno Randolf | 8a89f06 | 2010-06-16 19:11:51 +0900 | [diff] [blame] | 1360 | |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 1361 | ath5k_update_beacon_rssi(ah, skb, rs->rs_rssi); |
Bruno Randolf | 8a89f06 | 2010-06-16 19:11:51 +0900 | [diff] [blame] | 1362 | |
| 1363 | /* check beacons in IBSS mode */ |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 1364 | if (ah->opmode == NL80211_IFTYPE_ADHOC) |
| 1365 | ath5k_check_ibss_tsf(ah, skb, rxs); |
Bruno Randolf | 8a89f06 | 2010-06-16 19:11:51 +0900 | [diff] [blame] | 1366 | |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 1367 | ieee80211_rx(ah->hw, skb); |
Bruno Randolf | 8a89f06 | 2010-06-16 19:11:51 +0900 | [diff] [blame] | 1368 | } |
| 1369 | |
Bruno Randolf | 02a78b4 | 2010-06-16 19:11:56 +0900 | [diff] [blame] | 1370 | /** ath5k_frame_receive_ok() - Do we want to receive this frame or not? |
| 1371 | * |
| 1372 | * Check if we want to further process this frame or not. Also update |
| 1373 | * statistics. Return true if we want this frame, false if not. |
| 1374 | */ |
| 1375 | static bool |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 1376 | ath5k_receive_frame_ok(struct ath5k_hw *ah, struct ath5k_rx_status *rs) |
Bruno Randolf | 02a78b4 | 2010-06-16 19:11:56 +0900 | [diff] [blame] | 1377 | { |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 1378 | ah->stats.rx_all_count++; |
| 1379 | ah->stats.rx_bytes_count += rs->rs_datalen; |
Bruno Randolf | 02a78b4 | 2010-06-16 19:11:56 +0900 | [diff] [blame] | 1380 | |
| 1381 | if (unlikely(rs->rs_status)) { |
| 1382 | if (rs->rs_status & AR5K_RXERR_CRC) |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 1383 | ah->stats.rxerr_crc++; |
Bruno Randolf | 02a78b4 | 2010-06-16 19:11:56 +0900 | [diff] [blame] | 1384 | if (rs->rs_status & AR5K_RXERR_FIFO) |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 1385 | ah->stats.rxerr_fifo++; |
Bruno Randolf | 02a78b4 | 2010-06-16 19:11:56 +0900 | [diff] [blame] | 1386 | if (rs->rs_status & AR5K_RXERR_PHY) { |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 1387 | ah->stats.rxerr_phy++; |
Bruno Randolf | 02a78b4 | 2010-06-16 19:11:56 +0900 | [diff] [blame] | 1388 | if (rs->rs_phyerr > 0 && rs->rs_phyerr < 32) |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 1389 | ah->stats.rxerr_phy_code[rs->rs_phyerr]++; |
Bruno Randolf | 02a78b4 | 2010-06-16 19:11:56 +0900 | [diff] [blame] | 1390 | return false; |
| 1391 | } |
| 1392 | if (rs->rs_status & AR5K_RXERR_DECRYPT) { |
| 1393 | /* |
| 1394 | * Decrypt error. If the error occurred |
| 1395 | * because there was no hardware key, then |
| 1396 | * let the frame through so the upper layers |
| 1397 | * can process it. This is necessary for 5210 |
| 1398 | * parts which have no way to setup a ``clear'' |
| 1399 | * key cache entry. |
| 1400 | * |
| 1401 | * XXX do key cache faulting |
| 1402 | */ |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 1403 | ah->stats.rxerr_decrypt++; |
Bruno Randolf | 02a78b4 | 2010-06-16 19:11:56 +0900 | [diff] [blame] | 1404 | if (rs->rs_keyix == AR5K_RXKEYIX_INVALID && |
| 1405 | !(rs->rs_status & AR5K_RXERR_CRC)) |
| 1406 | return true; |
| 1407 | } |
| 1408 | if (rs->rs_status & AR5K_RXERR_MIC) { |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 1409 | ah->stats.rxerr_mic++; |
Bruno Randolf | 02a78b4 | 2010-06-16 19:11:56 +0900 | [diff] [blame] | 1410 | return true; |
| 1411 | } |
| 1412 | |
Bob Copeland | 23538c2 | 2010-08-15 13:03:13 -0400 | [diff] [blame] | 1413 | /* reject any frames with non-crypto errors */ |
| 1414 | if (rs->rs_status & ~(AR5K_RXERR_DECRYPT)) |
Bruno Randolf | 02a78b4 | 2010-06-16 19:11:56 +0900 | [diff] [blame] | 1415 | return false; |
| 1416 | } |
| 1417 | |
| 1418 | if (unlikely(rs->rs_more)) { |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 1419 | ah->stats.rxerr_jumbo++; |
Bruno Randolf | 02a78b4 | 2010-06-16 19:11:56 +0900 | [diff] [blame] | 1420 | return false; |
| 1421 | } |
| 1422 | return true; |
| 1423 | } |
| 1424 | |
Bruno Randolf | 8a89f06 | 2010-06-16 19:11:51 +0900 | [diff] [blame] | 1425 | static void |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 1426 | ath5k_set_current_imask(struct ath5k_hw *ah) |
Felix Fietkau | c266c71 | 2011-04-10 18:32:19 +0200 | [diff] [blame] | 1427 | { |
Pavel Roskin | 4fc5401 | 2011-07-07 18:14:25 -0400 | [diff] [blame] | 1428 | enum ath5k_int imask; |
Felix Fietkau | c266c71 | 2011-04-10 18:32:19 +0200 | [diff] [blame] | 1429 | unsigned long flags; |
| 1430 | |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 1431 | spin_lock_irqsave(&ah->irqlock, flags); |
| 1432 | imask = ah->imask; |
| 1433 | if (ah->rx_pending) |
Felix Fietkau | c266c71 | 2011-04-10 18:32:19 +0200 | [diff] [blame] | 1434 | imask &= ~AR5K_INT_RX_ALL; |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 1435 | if (ah->tx_pending) |
Felix Fietkau | c266c71 | 2011-04-10 18:32:19 +0200 | [diff] [blame] | 1436 | imask &= ~AR5K_INT_TX_ALL; |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 1437 | ath5k_hw_set_imr(ah, imask); |
| 1438 | spin_unlock_irqrestore(&ah->irqlock, flags); |
Felix Fietkau | c266c71 | 2011-04-10 18:32:19 +0200 | [diff] [blame] | 1439 | } |
| 1440 | |
| 1441 | static void |
Bruno Randolf | 8a89f06 | 2010-06-16 19:11:51 +0900 | [diff] [blame] | 1442 | ath5k_tasklet_rx(unsigned long data) |
| 1443 | { |
Bruno Randolf | b47f407 | 2008-03-05 18:35:45 +0900 | [diff] [blame] | 1444 | struct ath5k_rx_status rs = {}; |
Bob Copeland | b6ea035 | 2009-01-10 14:42:54 -0500 | [diff] [blame] | 1445 | struct sk_buff *skb, *next_skb; |
| 1446 | dma_addr_t next_skb_addr; |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 1447 | struct ath5k_hw *ah = (void *)data; |
Luis R. Rodriguez | cc861f7 | 2009-11-04 09:11:34 -0800 | [diff] [blame] | 1448 | struct ath_common *common = ath5k_hw_common(ah); |
Bob Copeland | c57ca81 | 2009-04-15 07:57:35 -0400 | [diff] [blame] | 1449 | struct ath5k_buf *bf; |
Jiri Slaby | fa1c114 | 2007-08-12 17:33:16 +0200 | [diff] [blame] | 1450 | struct ath5k_desc *ds; |
Jiri Slaby | fa1c114 | 2007-08-12 17:33:16 +0200 | [diff] [blame] | 1451 | int ret; |
Jiri Slaby | fa1c114 | 2007-08-12 17:33:16 +0200 | [diff] [blame] | 1452 | |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 1453 | spin_lock(&ah->rxbuflock); |
| 1454 | if (list_empty(&ah->rxbuf)) { |
| 1455 | ATH5K_WARN(ah, "empty rx buf pool\n"); |
Jiri Slaby | 3a0f2c8 | 2008-07-15 17:44:18 +0200 | [diff] [blame] | 1456 | goto unlock; |
| 1457 | } |
Jiri Slaby | fa1c114 | 2007-08-12 17:33:16 +0200 | [diff] [blame] | 1458 | do { |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 1459 | bf = list_first_entry(&ah->rxbuf, struct ath5k_buf, list); |
Jiri Slaby | fa1c114 | 2007-08-12 17:33:16 +0200 | [diff] [blame] | 1460 | BUG_ON(bf->skb == NULL); |
| 1461 | skb = bf->skb; |
| 1462 | ds = bf->desc; |
| 1463 | |
Bob Copeland | c57ca81 | 2009-04-15 07:57:35 -0400 | [diff] [blame] | 1464 | /* bail if HW is still using self-linked descriptor */ |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 1465 | if (ath5k_hw_get_rxdp(ah) == bf->daddr) |
Bob Copeland | c57ca81 | 2009-04-15 07:57:35 -0400 | [diff] [blame] | 1466 | break; |
Jiri Slaby | fa1c114 | 2007-08-12 17:33:16 +0200 | [diff] [blame] | 1467 | |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 1468 | ret = ah->ah_proc_rx_desc(ah, ds, &rs); |
Jiri Slaby | fa1c114 | 2007-08-12 17:33:16 +0200 | [diff] [blame] | 1469 | if (unlikely(ret == -EINPROGRESS)) |
| 1470 | break; |
| 1471 | else if (unlikely(ret)) { |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 1472 | ATH5K_ERR(ah, "error in processing rx descriptor\n"); |
| 1473 | ah->stats.rxerr_proc++; |
Bruno Randolf | b16062f | 2010-06-16 19:11:46 +0900 | [diff] [blame] | 1474 | break; |
Jiri Slaby | fa1c114 | 2007-08-12 17:33:16 +0200 | [diff] [blame] | 1475 | } |
| 1476 | |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 1477 | if (ath5k_receive_frame_ok(ah, &rs)) { |
| 1478 | next_skb = ath5k_rx_skb_alloc(ah, &next_skb_addr); |
Bruno Randolf | 7644395 | 2010-03-09 16:56:00 +0900 | [diff] [blame] | 1479 | |
Bruno Randolf | 02a78b4 | 2010-06-16 19:11:56 +0900 | [diff] [blame] | 1480 | /* |
| 1481 | * If we can't replace bf->skb with a new skb under |
| 1482 | * memory pressure, just skip this packet |
| 1483 | */ |
| 1484 | if (!next_skb) |
Jiri Slaby | fa1c114 | 2007-08-12 17:33:16 +0200 | [diff] [blame] | 1485 | goto next; |
Jiri Slaby | fa1c114 | 2007-08-12 17:33:16 +0200 | [diff] [blame] | 1486 | |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 1487 | dma_unmap_single(ah->dev, bf->skbaddr, |
Bruno Randolf | 02a78b4 | 2010-06-16 19:11:56 +0900 | [diff] [blame] | 1488 | common->rx_bufsize, |
Felix Fietkau | aeae4ac | 2010-12-02 10:26:51 +0100 | [diff] [blame] | 1489 | DMA_FROM_DEVICE); |
Bruno Randolf | 02a78b4 | 2010-06-16 19:11:56 +0900 | [diff] [blame] | 1490 | |
| 1491 | skb_put(skb, rs.rs_datalen); |
| 1492 | |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 1493 | ath5k_receive_frame(ah, skb, &rs); |
Bruno Randolf | 02a78b4 | 2010-06-16 19:11:56 +0900 | [diff] [blame] | 1494 | |
| 1495 | bf->skb = next_skb; |
| 1496 | bf->skbaddr = next_skb_addr; |
Jiri Slaby | fa1c114 | 2007-08-12 17:33:16 +0200 | [diff] [blame] | 1497 | } |
Jiri Slaby | fa1c114 | 2007-08-12 17:33:16 +0200 | [diff] [blame] | 1498 | next: |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 1499 | list_move_tail(&bf->list, &ah->rxbuf); |
| 1500 | } while (ath5k_rxbuf_setup(ah, bf) == 0); |
Jiri Slaby | 3a0f2c8 | 2008-07-15 17:44:18 +0200 | [diff] [blame] | 1501 | unlock: |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 1502 | spin_unlock(&ah->rxbuflock); |
| 1503 | ah->rx_pending = false; |
| 1504 | ath5k_set_current_imask(ah); |
Jiri Slaby | fa1c114 | 2007-08-12 17:33:16 +0200 | [diff] [blame] | 1505 | } |
| 1506 | |
| 1507 | |
Jiri Slaby | fa1c114 | 2007-08-12 17:33:16 +0200 | [diff] [blame] | 1508 | /*************\ |
| 1509 | * TX Handling * |
| 1510 | \*************/ |
| 1511 | |
Johannes Berg | 7bb4568 | 2011-02-24 14:42:06 +0100 | [diff] [blame] | 1512 | void |
Bruno Randolf | cd2c548 | 2010-12-22 19:20:32 +0900 | [diff] [blame] | 1513 | ath5k_tx_queue(struct ieee80211_hw *hw, struct sk_buff *skb, |
| 1514 | struct ath5k_txq *txq) |
Bob Copeland | 8a63fac | 2010-09-17 12:45:07 +0900 | [diff] [blame] | 1515 | { |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 1516 | struct ath5k_hw *ah = hw->priv; |
Bob Copeland | 8a63fac | 2010-09-17 12:45:07 +0900 | [diff] [blame] | 1517 | struct ath5k_buf *bf; |
| 1518 | unsigned long flags; |
| 1519 | int padsize; |
| 1520 | |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 1521 | trace_ath5k_tx(ah, skb, txq); |
Bob Copeland | 8a63fac | 2010-09-17 12:45:07 +0900 | [diff] [blame] | 1522 | |
| 1523 | /* |
| 1524 | * The hardware expects the header padded to 4 byte boundaries. |
| 1525 | * If this is not the case, we add the padding after the header. |
| 1526 | */ |
| 1527 | padsize = ath5k_add_padding(skb); |
| 1528 | if (padsize < 0) { |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 1529 | ATH5K_ERR(ah, "tx hdrlen not %%4: not enough" |
Bob Copeland | 8a63fac | 2010-09-17 12:45:07 +0900 | [diff] [blame] | 1530 | " headroom to pad"); |
| 1531 | goto drop_packet; |
| 1532 | } |
| 1533 | |
Felix Fietkau | 4e86879 | 2011-07-12 09:02:05 +0800 | [diff] [blame] | 1534 | if (txq->txq_len >= txq->txq_max && |
| 1535 | txq->qnum <= AR5K_TX_QUEUE_ID_DATA_MAX) |
Bruno Randolf | 925e0b0 | 2010-09-17 11:36:35 +0900 | [diff] [blame] | 1536 | ieee80211_stop_queue(hw, txq->qnum); |
| 1537 | |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 1538 | spin_lock_irqsave(&ah->txbuflock, flags); |
| 1539 | if (list_empty(&ah->txbuf)) { |
| 1540 | ATH5K_ERR(ah, "no further txbuf available, dropping packet\n"); |
| 1541 | spin_unlock_irqrestore(&ah->txbuflock, flags); |
Bruno Randolf | 651d937 | 2010-09-17 11:36:46 +0900 | [diff] [blame] | 1542 | ieee80211_stop_queues(hw); |
Bob Copeland | 8a63fac | 2010-09-17 12:45:07 +0900 | [diff] [blame] | 1543 | goto drop_packet; |
| 1544 | } |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 1545 | bf = list_first_entry(&ah->txbuf, struct ath5k_buf, list); |
Bob Copeland | 8a63fac | 2010-09-17 12:45:07 +0900 | [diff] [blame] | 1546 | list_del(&bf->list); |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 1547 | ah->txbuf_len--; |
| 1548 | if (list_empty(&ah->txbuf)) |
Bob Copeland | 8a63fac | 2010-09-17 12:45:07 +0900 | [diff] [blame] | 1549 | ieee80211_stop_queues(hw); |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 1550 | spin_unlock_irqrestore(&ah->txbuflock, flags); |
Bob Copeland | 8a63fac | 2010-09-17 12:45:07 +0900 | [diff] [blame] | 1551 | |
| 1552 | bf->skb = skb; |
| 1553 | |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 1554 | if (ath5k_txbuf_setup(ah, bf, txq, padsize)) { |
Bob Copeland | 8a63fac | 2010-09-17 12:45:07 +0900 | [diff] [blame] | 1555 | bf->skb = NULL; |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 1556 | spin_lock_irqsave(&ah->txbuflock, flags); |
| 1557 | list_add_tail(&bf->list, &ah->txbuf); |
| 1558 | ah->txbuf_len++; |
| 1559 | spin_unlock_irqrestore(&ah->txbuflock, flags); |
Bob Copeland | 8a63fac | 2010-09-17 12:45:07 +0900 | [diff] [blame] | 1560 | goto drop_packet; |
| 1561 | } |
Johannes Berg | 7bb4568 | 2011-02-24 14:42:06 +0100 | [diff] [blame] | 1562 | return; |
Bob Copeland | 8a63fac | 2010-09-17 12:45:07 +0900 | [diff] [blame] | 1563 | |
| 1564 | drop_packet: |
| 1565 | dev_kfree_skb_any(skb); |
Bob Copeland | 8a63fac | 2010-09-17 12:45:07 +0900 | [diff] [blame] | 1566 | } |
| 1567 | |
Bruno Randolf | 1440401 | 2010-09-17 11:36:51 +0900 | [diff] [blame] | 1568 | static void |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 1569 | ath5k_tx_frame_completed(struct ath5k_hw *ah, struct sk_buff *skb, |
Bob Copeland | 0e47225 | 2011-01-24 23:32:55 -0500 | [diff] [blame] | 1570 | struct ath5k_txq *txq, struct ath5k_tx_status *ts) |
Bruno Randolf | 1440401 | 2010-09-17 11:36:51 +0900 | [diff] [blame] | 1571 | { |
| 1572 | struct ieee80211_tx_info *info; |
Felix Fietkau | ed89508 | 2011-04-10 18:32:17 +0200 | [diff] [blame] | 1573 | u8 tries[3]; |
Bruno Randolf | 1440401 | 2010-09-17 11:36:51 +0900 | [diff] [blame] | 1574 | int i; |
| 1575 | |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 1576 | ah->stats.tx_all_count++; |
| 1577 | ah->stats.tx_bytes_count += skb->len; |
Bruno Randolf | 1440401 | 2010-09-17 11:36:51 +0900 | [diff] [blame] | 1578 | info = IEEE80211_SKB_CB(skb); |
| 1579 | |
Felix Fietkau | ed89508 | 2011-04-10 18:32:17 +0200 | [diff] [blame] | 1580 | tries[0] = info->status.rates[0].count; |
| 1581 | tries[1] = info->status.rates[1].count; |
| 1582 | tries[2] = info->status.rates[2].count; |
| 1583 | |
Bruno Randolf | 1440401 | 2010-09-17 11:36:51 +0900 | [diff] [blame] | 1584 | ieee80211_tx_info_clear_status(info); |
Felix Fietkau | ed89508 | 2011-04-10 18:32:17 +0200 | [diff] [blame] | 1585 | |
| 1586 | for (i = 0; i < ts->ts_final_idx; i++) { |
Bruno Randolf | 1440401 | 2010-09-17 11:36:51 +0900 | [diff] [blame] | 1587 | struct ieee80211_tx_rate *r = |
| 1588 | &info->status.rates[i]; |
| 1589 | |
Felix Fietkau | ed89508 | 2011-04-10 18:32:17 +0200 | [diff] [blame] | 1590 | r->count = tries[i]; |
Bruno Randolf | 1440401 | 2010-09-17 11:36:51 +0900 | [diff] [blame] | 1591 | } |
| 1592 | |
Felix Fietkau | ed89508 | 2011-04-10 18:32:17 +0200 | [diff] [blame] | 1593 | info->status.rates[ts->ts_final_idx].count = ts->ts_final_retry; |
Felix Fietkau | 6d7b97b | 2011-04-09 21:37:14 +0200 | [diff] [blame] | 1594 | info->status.rates[ts->ts_final_idx + 1].idx = -1; |
Bruno Randolf | 1440401 | 2010-09-17 11:36:51 +0900 | [diff] [blame] | 1595 | |
| 1596 | if (unlikely(ts->ts_status)) { |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 1597 | ah->stats.ack_fail++; |
Bruno Randolf | 1440401 | 2010-09-17 11:36:51 +0900 | [diff] [blame] | 1598 | if (ts->ts_status & AR5K_TXERR_FILT) { |
| 1599 | info->flags |= IEEE80211_TX_STAT_TX_FILTERED; |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 1600 | ah->stats.txerr_filt++; |
Bruno Randolf | 1440401 | 2010-09-17 11:36:51 +0900 | [diff] [blame] | 1601 | } |
| 1602 | if (ts->ts_status & AR5K_TXERR_XRETRY) |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 1603 | ah->stats.txerr_retry++; |
Bruno Randolf | 1440401 | 2010-09-17 11:36:51 +0900 | [diff] [blame] | 1604 | if (ts->ts_status & AR5K_TXERR_FIFO) |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 1605 | ah->stats.txerr_fifo++; |
Bruno Randolf | 1440401 | 2010-09-17 11:36:51 +0900 | [diff] [blame] | 1606 | } else { |
| 1607 | info->flags |= IEEE80211_TX_STAT_ACK; |
| 1608 | info->status.ack_signal = ts->ts_rssi; |
Felix Fietkau | 6d7b97b | 2011-04-09 21:37:14 +0200 | [diff] [blame] | 1609 | |
| 1610 | /* count the successful attempt as well */ |
| 1611 | info->status.rates[ts->ts_final_idx].count++; |
Bruno Randolf | 1440401 | 2010-09-17 11:36:51 +0900 | [diff] [blame] | 1612 | } |
| 1613 | |
| 1614 | /* |
| 1615 | * Remove MAC header padding before giving the frame |
| 1616 | * back to mac80211. |
| 1617 | */ |
| 1618 | ath5k_remove_padding(skb); |
| 1619 | |
| 1620 | if (ts->ts_antenna > 0 && ts->ts_antenna < 5) |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 1621 | ah->stats.antenna_tx[ts->ts_antenna]++; |
Bruno Randolf | 1440401 | 2010-09-17 11:36:51 +0900 | [diff] [blame] | 1622 | else |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 1623 | ah->stats.antenna_tx[0]++; /* invalid */ |
Bruno Randolf | 1440401 | 2010-09-17 11:36:51 +0900 | [diff] [blame] | 1624 | |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 1625 | trace_ath5k_tx_complete(ah, skb, txq, ts); |
| 1626 | ieee80211_tx_status(ah->hw, skb); |
Bruno Randolf | 1440401 | 2010-09-17 11:36:51 +0900 | [diff] [blame] | 1627 | } |
Bob Copeland | 8a63fac | 2010-09-17 12:45:07 +0900 | [diff] [blame] | 1628 | |
Jiri Slaby | fa1c114 | 2007-08-12 17:33:16 +0200 | [diff] [blame] | 1629 | static void |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 1630 | ath5k_tx_processq(struct ath5k_hw *ah, struct ath5k_txq *txq) |
Jiri Slaby | fa1c114 | 2007-08-12 17:33:16 +0200 | [diff] [blame] | 1631 | { |
Bruno Randolf | b47f407 | 2008-03-05 18:35:45 +0900 | [diff] [blame] | 1632 | struct ath5k_tx_status ts = {}; |
Jiri Slaby | fa1c114 | 2007-08-12 17:33:16 +0200 | [diff] [blame] | 1633 | struct ath5k_buf *bf, *bf0; |
| 1634 | struct ath5k_desc *ds; |
| 1635 | struct sk_buff *skb; |
Bruno Randolf | 1440401 | 2010-09-17 11:36:51 +0900 | [diff] [blame] | 1636 | int ret; |
Jiri Slaby | fa1c114 | 2007-08-12 17:33:16 +0200 | [diff] [blame] | 1637 | |
| 1638 | spin_lock(&txq->lock); |
| 1639 | list_for_each_entry_safe(bf, bf0, &txq->q, list) { |
Bruno Randolf | 2341329 | 2010-09-17 11:37:07 +0900 | [diff] [blame] | 1640 | |
| 1641 | txq->txq_poll_mark = false; |
| 1642 | |
| 1643 | /* skb might already have been processed last time. */ |
| 1644 | if (bf->skb != NULL) { |
| 1645 | ds = bf->desc; |
| 1646 | |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 1647 | ret = ah->ah_proc_tx_desc(ah, ds, &ts); |
Bruno Randolf | 2341329 | 2010-09-17 11:37:07 +0900 | [diff] [blame] | 1648 | if (unlikely(ret == -EINPROGRESS)) |
| 1649 | break; |
| 1650 | else if (unlikely(ret)) { |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 1651 | ATH5K_ERR(ah, |
Bruno Randolf | 2341329 | 2010-09-17 11:37:07 +0900 | [diff] [blame] | 1652 | "error %d while processing " |
| 1653 | "queue %u\n", ret, txq->qnum); |
| 1654 | break; |
| 1655 | } |
| 1656 | |
| 1657 | skb = bf->skb; |
| 1658 | bf->skb = NULL; |
Felix Fietkau | aeae4ac | 2010-12-02 10:26:51 +0100 | [diff] [blame] | 1659 | |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 1660 | dma_unmap_single(ah->dev, bf->skbaddr, skb->len, |
Felix Fietkau | aeae4ac | 2010-12-02 10:26:51 +0100 | [diff] [blame] | 1661 | DMA_TO_DEVICE); |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 1662 | ath5k_tx_frame_completed(ah, skb, txq, &ts); |
Bruno Randolf | 2341329 | 2010-09-17 11:37:07 +0900 | [diff] [blame] | 1663 | } |
Jiri Slaby | fa1c114 | 2007-08-12 17:33:16 +0200 | [diff] [blame] | 1664 | |
Bob Copeland | a05988b | 2010-04-07 23:55:58 -0400 | [diff] [blame] | 1665 | /* |
| 1666 | * It's possible that the hardware can say the buffer is |
| 1667 | * completed when it hasn't yet loaded the ds_link from |
Bruno Randolf | 2341329 | 2010-09-17 11:37:07 +0900 | [diff] [blame] | 1668 | * host memory and moved on. |
| 1669 | * Always keep the last descriptor to avoid HW races... |
Bob Copeland | a05988b | 2010-04-07 23:55:58 -0400 | [diff] [blame] | 1670 | */ |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 1671 | if (ath5k_hw_get_txdp(ah, txq->qnum) != bf->daddr) { |
| 1672 | spin_lock(&ah->txbuflock); |
| 1673 | list_move_tail(&bf->list, &ah->txbuf); |
| 1674 | ah->txbuf_len++; |
Bruno Randolf | 2341329 | 2010-09-17 11:37:07 +0900 | [diff] [blame] | 1675 | txq->txq_len--; |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 1676 | spin_unlock(&ah->txbuflock); |
Jiri Slaby | fa1c114 | 2007-08-12 17:33:16 +0200 | [diff] [blame] | 1677 | } |
Jiri Slaby | fa1c114 | 2007-08-12 17:33:16 +0200 | [diff] [blame] | 1678 | } |
Jiri Slaby | fa1c114 | 2007-08-12 17:33:16 +0200 | [diff] [blame] | 1679 | spin_unlock(&txq->lock); |
Bruno Randolf | 4198a8d | 2010-10-05 13:27:17 +0900 | [diff] [blame] | 1680 | if (txq->txq_len < ATH5K_TXQ_LEN_LOW && txq->qnum < 4) |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 1681 | ieee80211_wake_queue(ah->hw, txq->qnum); |
Jiri Slaby | fa1c114 | 2007-08-12 17:33:16 +0200 | [diff] [blame] | 1682 | } |
| 1683 | |
| 1684 | static void |
| 1685 | ath5k_tasklet_tx(unsigned long data) |
| 1686 | { |
Bob Copeland | 8784d2e | 2009-07-29 17:32:28 -0400 | [diff] [blame] | 1687 | int i; |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 1688 | struct ath5k_hw *ah = (void *)data; |
Jiri Slaby | fa1c114 | 2007-08-12 17:33:16 +0200 | [diff] [blame] | 1689 | |
Pavel Roskin | e4bbf2f | 2011-07-07 18:14:13 -0400 | [diff] [blame] | 1690 | for (i = 0; i < AR5K_NUM_TX_QUEUES; i++) |
Nick Kossifidis | 7ff7c82 | 2011-11-25 20:40:20 +0200 | [diff] [blame] | 1691 | if (ah->txqs[i].setup && (ah->ah_txq_isr_txok_all & BIT(i))) |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 1692 | ath5k_tx_processq(ah, &ah->txqs[i]); |
Felix Fietkau | c266c71 | 2011-04-10 18:32:19 +0200 | [diff] [blame] | 1693 | |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 1694 | ah->tx_pending = false; |
| 1695 | ath5k_set_current_imask(ah); |
Jiri Slaby | fa1c114 | 2007-08-12 17:33:16 +0200 | [diff] [blame] | 1696 | } |
| 1697 | |
| 1698 | |
Jiri Slaby | fa1c114 | 2007-08-12 17:33:16 +0200 | [diff] [blame] | 1699 | /*****************\ |
| 1700 | * Beacon handling * |
| 1701 | \*****************/ |
| 1702 | |
| 1703 | /* |
| 1704 | * Setup the beacon frame for transmit. |
| 1705 | */ |
| 1706 | static int |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 1707 | ath5k_beacon_setup(struct ath5k_hw *ah, struct ath5k_buf *bf) |
Jiri Slaby | fa1c114 | 2007-08-12 17:33:16 +0200 | [diff] [blame] | 1708 | { |
| 1709 | struct sk_buff *skb = bf->skb; |
Johannes Berg | a888d52 | 2008-05-26 16:43:39 +0200 | [diff] [blame] | 1710 | struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb); |
Jiri Slaby | fa1c114 | 2007-08-12 17:33:16 +0200 | [diff] [blame] | 1711 | struct ath5k_desc *ds; |
Nick Kossifidis | 2bed03e | 2009-04-30 15:55:49 -0400 | [diff] [blame] | 1712 | int ret = 0; |
| 1713 | u8 antenna; |
Jiri Slaby | fa1c114 | 2007-08-12 17:33:16 +0200 | [diff] [blame] | 1714 | u32 flags; |
Benoit Papillault | 8127fbd | 2010-02-27 23:05:26 +0100 | [diff] [blame] | 1715 | const int padsize = 0; |
Jiri Slaby | fa1c114 | 2007-08-12 17:33:16 +0200 | [diff] [blame] | 1716 | |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 1717 | bf->skbaddr = dma_map_single(ah->dev, skb->data, skb->len, |
Felix Fietkau | aeae4ac | 2010-12-02 10:26:51 +0100 | [diff] [blame] | 1718 | DMA_TO_DEVICE); |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 1719 | ATH5K_DBG(ah, ATH5K_DEBUG_BEACON, "skb %p [data %p len %u] " |
Jiri Slaby | fa1c114 | 2007-08-12 17:33:16 +0200 | [diff] [blame] | 1720 | "skbaddr %llx\n", skb, skb->data, skb->len, |
| 1721 | (unsigned long long)bf->skbaddr); |
Felix Fietkau | aeae4ac | 2010-12-02 10:26:51 +0100 | [diff] [blame] | 1722 | |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 1723 | if (dma_mapping_error(ah->dev, bf->skbaddr)) { |
| 1724 | ATH5K_ERR(ah, "beacon DMA mapping failed\n"); |
Bob Copeland | bdc71bc | 2011-08-07 19:36:07 -0400 | [diff] [blame] | 1725 | dev_kfree_skb_any(skb); |
| 1726 | bf->skb = NULL; |
Jiri Slaby | fa1c114 | 2007-08-12 17:33:16 +0200 | [diff] [blame] | 1727 | return -EIO; |
| 1728 | } |
| 1729 | |
| 1730 | ds = bf->desc; |
Nick Kossifidis | 2bed03e | 2009-04-30 15:55:49 -0400 | [diff] [blame] | 1731 | antenna = ah->ah_tx_ant; |
Jiri Slaby | fa1c114 | 2007-08-12 17:33:16 +0200 | [diff] [blame] | 1732 | |
| 1733 | flags = AR5K_TXDESC_NOACK; |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 1734 | if (ah->opmode == NL80211_IFTYPE_ADHOC && ath5k_hw_hasveol(ah)) { |
Jiri Slaby | fa1c114 | 2007-08-12 17:33:16 +0200 | [diff] [blame] | 1735 | ds->ds_link = bf->daddr; /* self-linked */ |
| 1736 | flags |= AR5K_TXDESC_VEOL; |
Nick Kossifidis | 2bed03e | 2009-04-30 15:55:49 -0400 | [diff] [blame] | 1737 | } else |
Jiri Slaby | fa1c114 | 2007-08-12 17:33:16 +0200 | [diff] [blame] | 1738 | ds->ds_link = 0; |
Nick Kossifidis | 2bed03e | 2009-04-30 15:55:49 -0400 | [diff] [blame] | 1739 | |
| 1740 | /* |
| 1741 | * If we use multiple antennas on AP and use |
| 1742 | * the Sectored AP scenario, switch antenna every |
| 1743 | * 4 beacons to make sure everybody hears our AP. |
| 1744 | * When a client tries to associate, hw will keep |
| 1745 | * track of the tx antenna to be used for this client |
Pavel Roskin | 6a2a0e7 | 2011-07-09 00:17:51 -0400 | [diff] [blame] | 1746 | * automatically, based on ACKed packets. |
Nick Kossifidis | 2bed03e | 2009-04-30 15:55:49 -0400 | [diff] [blame] | 1747 | * |
| 1748 | * Note: AP still listens and transmits RTS on the |
| 1749 | * default antenna which is supposed to be an omni. |
| 1750 | * |
| 1751 | * Note2: On sectored scenarios it's possible to have |
Bob Copeland | a180a13 | 2010-08-15 13:03:12 -0400 | [diff] [blame] | 1752 | * multiple antennas (1 omni -- the default -- and 14 |
| 1753 | * sectors), so if we choose to actually support this |
| 1754 | * mode, we need to allow the user to set how many antennas |
| 1755 | * we have and tweak the code below to send beacons |
| 1756 | * on all of them. |
Nick Kossifidis | 2bed03e | 2009-04-30 15:55:49 -0400 | [diff] [blame] | 1757 | */ |
| 1758 | if (ah->ah_ant_mode == AR5K_ANTMODE_SECTOR_AP) |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 1759 | antenna = ah->bsent & 4 ? 2 : 1; |
Nick Kossifidis | 2bed03e | 2009-04-30 15:55:49 -0400 | [diff] [blame] | 1760 | |
Jiri Slaby | fa1c114 | 2007-08-12 17:33:16 +0200 | [diff] [blame] | 1761 | |
Nick Kossifidis | 8f655dd | 2009-03-15 22:20:35 +0200 | [diff] [blame] | 1762 | /* FIXME: If we are in g mode and rate is a CCK rate |
| 1763 | * subtract ah->ah_txpower.txp_cck_ofdm_pwr_delta |
| 1764 | * from tx power (value is in dB units already) */ |
Jiri Slaby | fa1c114 | 2007-08-12 17:33:16 +0200 | [diff] [blame] | 1765 | ds->ds_data = bf->skbaddr; |
Bruno Randolf | 281c56d | 2008-02-05 18:44:55 +0900 | [diff] [blame] | 1766 | ret = ah->ah_setup_tx_desc(ah, ds, skb->len, |
Benoit Papillault | 8127fbd | 2010-02-27 23:05:26 +0100 | [diff] [blame] | 1767 | ieee80211_get_hdrlen_from_skb(skb), padsize, |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 1768 | AR5K_PKT_TYPE_BEACON, (ah->power_level * 2), |
| 1769 | ieee80211_get_tx_rate(ah->hw, info)->hw_value, |
Johannes Berg | 2e92e6f | 2008-05-15 12:55:27 +0200 | [diff] [blame] | 1770 | 1, AR5K_TXKEYIX_INVALID, |
Luis R. Rodriguez | 400ec45 | 2008-02-03 21:51:49 -0500 | [diff] [blame] | 1771 | antenna, flags, 0, 0); |
Jiri Slaby | fa1c114 | 2007-08-12 17:33:16 +0200 | [diff] [blame] | 1772 | if (ret) |
| 1773 | goto err_unmap; |
| 1774 | |
| 1775 | return 0; |
| 1776 | err_unmap: |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 1777 | dma_unmap_single(ah->dev, bf->skbaddr, skb->len, DMA_TO_DEVICE); |
Jiri Slaby | fa1c114 | 2007-08-12 17:33:16 +0200 | [diff] [blame] | 1778 | return ret; |
| 1779 | } |
| 1780 | |
| 1781 | /* |
Bob Copeland | 8a63fac | 2010-09-17 12:45:07 +0900 | [diff] [blame] | 1782 | * Updates the beacon that is sent by ath5k_beacon_send. For adhoc, |
| 1783 | * this is called only once at config_bss time, for AP we do it every |
| 1784 | * SWBA interrupt so that the TIM will reflect buffered frames. |
| 1785 | * |
| 1786 | * Called with the beacon lock. |
| 1787 | */ |
Bruno Randolf | cd2c548 | 2010-12-22 19:20:32 +0900 | [diff] [blame] | 1788 | int |
Bob Copeland | 8a63fac | 2010-09-17 12:45:07 +0900 | [diff] [blame] | 1789 | ath5k_beacon_update(struct ieee80211_hw *hw, struct ieee80211_vif *vif) |
| 1790 | { |
| 1791 | int ret; |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 1792 | struct ath5k_hw *ah = hw->priv; |
Ben Greear | b1ae1ed | 2010-09-30 12:22:58 -0700 | [diff] [blame] | 1793 | struct ath5k_vif *avf = (void *)vif->drv_priv; |
Bob Copeland | 8a63fac | 2010-09-17 12:45:07 +0900 | [diff] [blame] | 1794 | struct sk_buff *skb; |
| 1795 | |
| 1796 | if (WARN_ON(!vif)) { |
| 1797 | ret = -EINVAL; |
| 1798 | goto out; |
| 1799 | } |
| 1800 | |
| 1801 | skb = ieee80211_beacon_get(hw, vif); |
| 1802 | |
| 1803 | if (!skb) { |
| 1804 | ret = -ENOMEM; |
| 1805 | goto out; |
| 1806 | } |
| 1807 | |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 1808 | ath5k_txbuf_free_skb(ah, avf->bbuf); |
Ben Greear | b1ae1ed | 2010-09-30 12:22:58 -0700 | [diff] [blame] | 1809 | avf->bbuf->skb = skb; |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 1810 | ret = ath5k_beacon_setup(ah, avf->bbuf); |
Bob Copeland | 8a63fac | 2010-09-17 12:45:07 +0900 | [diff] [blame] | 1811 | out: |
| 1812 | return ret; |
| 1813 | } |
| 1814 | |
| 1815 | /* |
Jiri Slaby | fa1c114 | 2007-08-12 17:33:16 +0200 | [diff] [blame] | 1816 | * Transmit a beacon frame at SWBA. Dynamic updates to the |
| 1817 | * frame contents are done as needed and the slot time is |
| 1818 | * also adjusted based on current state. |
| 1819 | * |
Bob Copeland | 5faaff7 | 2010-07-13 11:32:40 -0400 | [diff] [blame] | 1820 | * This is called from software irq context (beacontq tasklets) |
| 1821 | * or user context from ath5k_beacon_config. |
Jiri Slaby | fa1c114 | 2007-08-12 17:33:16 +0200 | [diff] [blame] | 1822 | */ |
| 1823 | static void |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 1824 | ath5k_beacon_send(struct ath5k_hw *ah) |
Jiri Slaby | fa1c114 | 2007-08-12 17:33:16 +0200 | [diff] [blame] | 1825 | { |
Ben Greear | b1ae1ed | 2010-09-30 12:22:58 -0700 | [diff] [blame] | 1826 | struct ieee80211_vif *vif; |
| 1827 | struct ath5k_vif *avf; |
| 1828 | struct ath5k_buf *bf; |
Bob Copeland | cec8db2 | 2009-07-04 12:59:51 -0400 | [diff] [blame] | 1829 | struct sk_buff *skb; |
Bob Copeland | bdc71bc | 2011-08-07 19:36:07 -0400 | [diff] [blame] | 1830 | int err; |
Jiri Slaby | fa1c114 | 2007-08-12 17:33:16 +0200 | [diff] [blame] | 1831 | |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 1832 | ATH5K_DBG_UNLIMIT(ah, ATH5K_DEBUG_BEACON, "in beacon_send\n"); |
Jiri Slaby | fa1c114 | 2007-08-12 17:33:16 +0200 | [diff] [blame] | 1833 | |
Jiri Slaby | fa1c114 | 2007-08-12 17:33:16 +0200 | [diff] [blame] | 1834 | /* |
| 1835 | * Check if the previous beacon has gone out. If |
Bob Copeland | a180a13 | 2010-08-15 13:03:12 -0400 | [diff] [blame] | 1836 | * not, don't don't try to post another: skip this |
Jiri Slaby | fa1c114 | 2007-08-12 17:33:16 +0200 | [diff] [blame] | 1837 | * period and wait for the next. Missed beacons |
| 1838 | * indicate a problem and should not occur. If we |
| 1839 | * miss too many consecutive beacons reset the device. |
| 1840 | */ |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 1841 | if (unlikely(ath5k_hw_num_tx_pending(ah, ah->bhalq) != 0)) { |
| 1842 | ah->bmisscount++; |
| 1843 | ATH5K_DBG(ah, ATH5K_DEBUG_BEACON, |
| 1844 | "missed %u consecutive beacons\n", ah->bmisscount); |
| 1845 | if (ah->bmisscount > 10) { /* NB: 10 is a guess */ |
| 1846 | ATH5K_DBG(ah, ATH5K_DEBUG_BEACON, |
Jiri Slaby | fa1c114 | 2007-08-12 17:33:16 +0200 | [diff] [blame] | 1847 | "stuck beacon time (%u missed)\n", |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 1848 | ah->bmisscount); |
| 1849 | ATH5K_DBG(ah, ATH5K_DEBUG_RESET, |
Bruno Randolf | 8d67a03 | 2010-06-16 19:11:12 +0900 | [diff] [blame] | 1850 | "stuck beacon, resetting\n"); |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 1851 | ieee80211_queue_work(ah->hw, &ah->reset_work); |
Jiri Slaby | fa1c114 | 2007-08-12 17:33:16 +0200 | [diff] [blame] | 1852 | } |
| 1853 | return; |
| 1854 | } |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 1855 | if (unlikely(ah->bmisscount != 0)) { |
| 1856 | ATH5K_DBG(ah, ATH5K_DEBUG_BEACON, |
Jiri Slaby | fa1c114 | 2007-08-12 17:33:16 +0200 | [diff] [blame] | 1857 | "resume beacon xmit after %u misses\n", |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 1858 | ah->bmisscount); |
| 1859 | ah->bmisscount = 0; |
Jiri Slaby | fa1c114 | 2007-08-12 17:33:16 +0200 | [diff] [blame] | 1860 | } |
| 1861 | |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 1862 | if ((ah->opmode == NL80211_IFTYPE_AP && ah->num_ap_vifs > 1) || |
| 1863 | ah->opmode == NL80211_IFTYPE_MESH_POINT) { |
Ben Greear | b1ae1ed | 2010-09-30 12:22:58 -0700 | [diff] [blame] | 1864 | u64 tsf = ath5k_hw_get_tsf64(ah); |
| 1865 | u32 tsftu = TSF_TO_TU(tsf); |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 1866 | int slot = ((tsftu % ah->bintval) * ATH_BCBUF) / ah->bintval; |
| 1867 | vif = ah->bslot[(slot + 1) % ATH_BCBUF]; |
| 1868 | ATH5K_DBG(ah, ATH5K_DEBUG_BEACON, |
Ben Greear | b1ae1ed | 2010-09-30 12:22:58 -0700 | [diff] [blame] | 1869 | "tsf %llx tsftu %x intval %u slot %u vif %p\n", |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 1870 | (unsigned long long)tsf, tsftu, ah->bintval, slot, vif); |
Ben Greear | b1ae1ed | 2010-09-30 12:22:58 -0700 | [diff] [blame] | 1871 | } else /* only one interface */ |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 1872 | vif = ah->bslot[0]; |
Ben Greear | b1ae1ed | 2010-09-30 12:22:58 -0700 | [diff] [blame] | 1873 | |
| 1874 | if (!vif) |
| 1875 | return; |
| 1876 | |
| 1877 | avf = (void *)vif->drv_priv; |
| 1878 | bf = avf->bbuf; |
Ben Greear | b1ae1ed | 2010-09-30 12:22:58 -0700 | [diff] [blame] | 1879 | |
Jiri Slaby | fa1c114 | 2007-08-12 17:33:16 +0200 | [diff] [blame] | 1880 | /* |
| 1881 | * Stop any current dma and put the new frame on the queue. |
| 1882 | * This should never fail since we check above that no frames |
| 1883 | * are still pending on the queue. |
| 1884 | */ |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 1885 | if (unlikely(ath5k_hw_stop_beacon_queue(ah, ah->bhalq))) { |
| 1886 | ATH5K_WARN(ah, "beacon queue %u didn't start/stop ?\n", ah->bhalq); |
Jiri Slaby | fa1c114 | 2007-08-12 17:33:16 +0200 | [diff] [blame] | 1887 | /* NB: hw still stops DMA, so proceed */ |
| 1888 | } |
Jiri Slaby | fa1c114 | 2007-08-12 17:33:16 +0200 | [diff] [blame] | 1889 | |
Javier Cardona | d82b577 | 2010-12-07 13:35:55 -0800 | [diff] [blame] | 1890 | /* refresh the beacon for AP or MESH mode */ |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 1891 | if (ah->opmode == NL80211_IFTYPE_AP || |
Bob Copeland | bdc71bc | 2011-08-07 19:36:07 -0400 | [diff] [blame] | 1892 | ah->opmode == NL80211_IFTYPE_MESH_POINT) { |
| 1893 | err = ath5k_beacon_update(ah->hw, vif); |
| 1894 | if (err) |
| 1895 | return; |
| 1896 | } |
| 1897 | |
| 1898 | if (unlikely(bf->skb == NULL || ah->opmode == NL80211_IFTYPE_STATION || |
| 1899 | ah->opmode == NL80211_IFTYPE_MONITOR)) { |
| 1900 | ATH5K_WARN(ah, "bf=%p bf_skb=%p\n", bf, bf->skb); |
| 1901 | return; |
| 1902 | } |
Bob Copeland | 1071db8 | 2009-05-18 10:59:52 -0400 | [diff] [blame] | 1903 | |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 1904 | trace_ath5k_tx(ah, bf->skb, &ah->txqs[ah->bhalq]); |
Bob Copeland | 0e47225 | 2011-01-24 23:32:55 -0500 | [diff] [blame] | 1905 | |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 1906 | ath5k_hw_set_txdp(ah, ah->bhalq, bf->daddr); |
| 1907 | ath5k_hw_start_tx_dma(ah, ah->bhalq); |
| 1908 | ATH5K_DBG(ah, ATH5K_DEBUG_BEACON, "TXDP[%u] = %llx (%p)\n", |
| 1909 | ah->bhalq, (unsigned long long)bf->daddr, bf->desc); |
Jiri Slaby | fa1c114 | 2007-08-12 17:33:16 +0200 | [diff] [blame] | 1910 | |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 1911 | skb = ieee80211_get_buffered_bc(ah->hw, vif); |
Bob Copeland | cec8db2 | 2009-07-04 12:59:51 -0400 | [diff] [blame] | 1912 | while (skb) { |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 1913 | ath5k_tx_queue(ah->hw, skb, ah->cabq); |
Felix Fietkau | 4e86879 | 2011-07-12 09:02:05 +0800 | [diff] [blame] | 1914 | |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 1915 | if (ah->cabq->txq_len >= ah->cabq->txq_max) |
Felix Fietkau | 4e86879 | 2011-07-12 09:02:05 +0800 | [diff] [blame] | 1916 | break; |
| 1917 | |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 1918 | skb = ieee80211_get_buffered_bc(ah->hw, vif); |
Bob Copeland | cec8db2 | 2009-07-04 12:59:51 -0400 | [diff] [blame] | 1919 | } |
| 1920 | |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 1921 | ah->bsent++; |
Jiri Slaby | fa1c114 | 2007-08-12 17:33:16 +0200 | [diff] [blame] | 1922 | } |
| 1923 | |
Bruno Randolf | 9804b98 | 2008-01-19 18:17:59 +0900 | [diff] [blame] | 1924 | /** |
| 1925 | * ath5k_beacon_update_timers - update beacon timers |
| 1926 | * |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 1927 | * @ah: struct ath5k_hw pointer we are operating on |
Bruno Randolf | 9804b98 | 2008-01-19 18:17:59 +0900 | [diff] [blame] | 1928 | * @bc_tsf: the timestamp of the beacon. 0 to reset the TSF. -1 to perform a |
| 1929 | * beacon timer update based on the current HW TSF. |
| 1930 | * |
| 1931 | * Calculate the next target beacon transmit time (TBTT) based on the timestamp |
| 1932 | * of a received beacon or the current local hardware TSF and write it to the |
| 1933 | * beacon timer registers. |
| 1934 | * |
| 1935 | * This is called in a variety of situations, e.g. when a beacon is received, |
Bruno Randolf | 6ba81c2 | 2008-03-05 18:36:26 +0900 | [diff] [blame] | 1936 | * when a TSF update has been detected, but also when an new IBSS is created or |
Bruno Randolf | 9804b98 | 2008-01-19 18:17:59 +0900 | [diff] [blame] | 1937 | * when we otherwise know we have to update the timers, but we keep it in this |
| 1938 | * function to have it all together in one place. |
| 1939 | */ |
Bruno Randolf | cd2c548 | 2010-12-22 19:20:32 +0900 | [diff] [blame] | 1940 | void |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 1941 | ath5k_beacon_update_timers(struct ath5k_hw *ah, u64 bc_tsf) |
Jiri Slaby | fa1c114 | 2007-08-12 17:33:16 +0200 | [diff] [blame] | 1942 | { |
Bruno Randolf | 9804b98 | 2008-01-19 18:17:59 +0900 | [diff] [blame] | 1943 | u32 nexttbtt, intval, hw_tu, bc_tu; |
| 1944 | u64 hw_tsf; |
Jiri Slaby | fa1c114 | 2007-08-12 17:33:16 +0200 | [diff] [blame] | 1945 | |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 1946 | intval = ah->bintval & AR5K_BEACON_PERIOD; |
| 1947 | if (ah->opmode == NL80211_IFTYPE_AP && ah->num_ap_vifs > 1) { |
Ben Greear | b1ae1ed | 2010-09-30 12:22:58 -0700 | [diff] [blame] | 1948 | intval /= ATH_BCBUF; /* staggered multi-bss beacons */ |
| 1949 | if (intval < 15) |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 1950 | ATH5K_WARN(ah, "intval %u is too low, min 15\n", |
Ben Greear | b1ae1ed | 2010-09-30 12:22:58 -0700 | [diff] [blame] | 1951 | intval); |
| 1952 | } |
Jiri Slaby | fa1c114 | 2007-08-12 17:33:16 +0200 | [diff] [blame] | 1953 | if (WARN_ON(!intval)) |
| 1954 | return; |
| 1955 | |
Bruno Randolf | 9804b98 | 2008-01-19 18:17:59 +0900 | [diff] [blame] | 1956 | /* beacon TSF converted to TU */ |
| 1957 | bc_tu = TSF_TO_TU(bc_tsf); |
| 1958 | |
Jiri Slaby | fa1c114 | 2007-08-12 17:33:16 +0200 | [diff] [blame] | 1959 | /* current TSF converted to TU */ |
Bruno Randolf | 9804b98 | 2008-01-19 18:17:59 +0900 | [diff] [blame] | 1960 | hw_tsf = ath5k_hw_get_tsf64(ah); |
| 1961 | hw_tu = TSF_TO_TU(hw_tsf); |
Jiri Slaby | fa1c114 | 2007-08-12 17:33:16 +0200 | [diff] [blame] | 1962 | |
Pavel Roskin | 633d006 | 2011-07-07 18:14:01 -0400 | [diff] [blame] | 1963 | #define FUDGE (AR5K_TUNE_SW_BEACON_RESP + 3) |
Bruno Randolf | 11f21df | 2010-09-27 12:22:26 +0900 | [diff] [blame] | 1964 | /* We use FUDGE to make sure the next TBTT is ahead of the current TU. |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 1965 | * Since we later subtract AR5K_TUNE_SW_BEACON_RESP (10) in the timer |
Bruno Randolf | 11f21df | 2010-09-27 12:22:26 +0900 | [diff] [blame] | 1966 | * configuration we need to make sure it is bigger than that. */ |
| 1967 | |
Bruno Randolf | 9804b98 | 2008-01-19 18:17:59 +0900 | [diff] [blame] | 1968 | if (bc_tsf == -1) { |
| 1969 | /* |
| 1970 | * no beacons received, called internally. |
| 1971 | * just need to refresh timers based on HW TSF. |
| 1972 | */ |
| 1973 | nexttbtt = roundup(hw_tu + FUDGE, intval); |
| 1974 | } else if (bc_tsf == 0) { |
| 1975 | /* |
| 1976 | * no beacon received, probably called by ath5k_reset_tsf(). |
| 1977 | * reset TSF to start with 0. |
| 1978 | */ |
| 1979 | nexttbtt = intval; |
| 1980 | intval |= AR5K_BEACON_RESET_TSF; |
| 1981 | } else if (bc_tsf > hw_tsf) { |
| 1982 | /* |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 1983 | * beacon received, SW merge happened but HW TSF not yet updated. |
Bruno Randolf | 9804b98 | 2008-01-19 18:17:59 +0900 | [diff] [blame] | 1984 | * not possible to reconfigure timers yet, but next time we |
| 1985 | * receive a beacon with the same BSSID, the hardware will |
| 1986 | * automatically update the TSF and then we need to reconfigure |
| 1987 | * the timers. |
| 1988 | */ |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 1989 | ATH5K_DBG_UNLIMIT(ah, ATH5K_DEBUG_BEACON, |
Bruno Randolf | 9804b98 | 2008-01-19 18:17:59 +0900 | [diff] [blame] | 1990 | "need to wait for HW TSF sync\n"); |
| 1991 | return; |
| 1992 | } else { |
| 1993 | /* |
| 1994 | * most important case for beacon synchronization between STA. |
| 1995 | * |
| 1996 | * beacon received and HW TSF has been already updated by HW. |
| 1997 | * update next TBTT based on the TSF of the beacon, but make |
| 1998 | * sure it is ahead of our local TSF timer. |
| 1999 | */ |
| 2000 | nexttbtt = bc_tu + roundup(hw_tu + FUDGE - bc_tu, intval); |
| 2001 | } |
| 2002 | #undef FUDGE |
Jiri Slaby | fa1c114 | 2007-08-12 17:33:16 +0200 | [diff] [blame] | 2003 | |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 2004 | ah->nexttbtt = nexttbtt; |
Bruno Randolf | 036cd1e | 2008-01-19 18:18:21 +0900 | [diff] [blame] | 2005 | |
Jiri Slaby | fa1c114 | 2007-08-12 17:33:16 +0200 | [diff] [blame] | 2006 | intval |= AR5K_BEACON_ENA; |
Nick Kossifidis | c47faa3 | 2011-11-25 20:40:25 +0200 | [diff] [blame^] | 2007 | ath5k_hw_init_beacon_timers(ah, nexttbtt, intval); |
Bruno Randolf | 9804b98 | 2008-01-19 18:17:59 +0900 | [diff] [blame] | 2008 | |
| 2009 | /* |
| 2010 | * debugging output last in order to preserve the time critical aspect |
| 2011 | * of this function |
| 2012 | */ |
| 2013 | if (bc_tsf == -1) |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 2014 | ATH5K_DBG_UNLIMIT(ah, ATH5K_DEBUG_BEACON, |
Bruno Randolf | 9804b98 | 2008-01-19 18:17:59 +0900 | [diff] [blame] | 2015 | "reconfigured timers based on HW TSF\n"); |
| 2016 | else if (bc_tsf == 0) |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 2017 | ATH5K_DBG_UNLIMIT(ah, ATH5K_DEBUG_BEACON, |
Bruno Randolf | 9804b98 | 2008-01-19 18:17:59 +0900 | [diff] [blame] | 2018 | "reset HW TSF and timers\n"); |
| 2019 | else |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 2020 | ATH5K_DBG_UNLIMIT(ah, ATH5K_DEBUG_BEACON, |
Bruno Randolf | 9804b98 | 2008-01-19 18:17:59 +0900 | [diff] [blame] | 2021 | "updated timers based on beacon TSF\n"); |
| 2022 | |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 2023 | ATH5K_DBG_UNLIMIT(ah, ATH5K_DEBUG_BEACON, |
David Miller | 04f93a8 | 2008-02-15 16:08:59 -0800 | [diff] [blame] | 2024 | "bc_tsf %llx hw_tsf %llx bc_tu %u hw_tu %u nexttbtt %u\n", |
| 2025 | (unsigned long long) bc_tsf, |
| 2026 | (unsigned long long) hw_tsf, bc_tu, hw_tu, nexttbtt); |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 2027 | ATH5K_DBG_UNLIMIT(ah, ATH5K_DEBUG_BEACON, "intval %u %s %s\n", |
Bruno Randolf | 9804b98 | 2008-01-19 18:17:59 +0900 | [diff] [blame] | 2028 | intval & AR5K_BEACON_PERIOD, |
| 2029 | intval & AR5K_BEACON_ENA ? "AR5K_BEACON_ENA" : "", |
| 2030 | intval & AR5K_BEACON_RESET_TSF ? "AR5K_BEACON_RESET_TSF" : ""); |
Jiri Slaby | fa1c114 | 2007-08-12 17:33:16 +0200 | [diff] [blame] | 2031 | } |
| 2032 | |
Bruno Randolf | 036cd1e | 2008-01-19 18:18:21 +0900 | [diff] [blame] | 2033 | /** |
| 2034 | * ath5k_beacon_config - Configure the beacon queues and interrupts |
| 2035 | * |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 2036 | * @ah: struct ath5k_hw pointer we are operating on |
Jiri Slaby | fa1c114 | 2007-08-12 17:33:16 +0200 | [diff] [blame] | 2037 | * |
Bruno Randolf | 036cd1e | 2008-01-19 18:18:21 +0900 | [diff] [blame] | 2038 | * In IBSS mode we use a self-linked tx descriptor if possible. We enable SWBA |
Bruno Randolf | 6ba81c2 | 2008-03-05 18:36:26 +0900 | [diff] [blame] | 2039 | * interrupts to detect TSF updates only. |
Jiri Slaby | fa1c114 | 2007-08-12 17:33:16 +0200 | [diff] [blame] | 2040 | */ |
Bruno Randolf | cd2c548 | 2010-12-22 19:20:32 +0900 | [diff] [blame] | 2041 | void |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 2042 | ath5k_beacon_config(struct ath5k_hw *ah) |
Jiri Slaby | fa1c114 | 2007-08-12 17:33:16 +0200 | [diff] [blame] | 2043 | { |
Bob Copeland | b5f0395 | 2009-02-15 12:06:10 -0500 | [diff] [blame] | 2044 | unsigned long flags; |
Jiri Slaby | fa1c114 | 2007-08-12 17:33:16 +0200 | [diff] [blame] | 2045 | |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 2046 | spin_lock_irqsave(&ah->block, flags); |
| 2047 | ah->bmisscount = 0; |
| 2048 | ah->imask &= ~(AR5K_INT_BMISS | AR5K_INT_SWBA); |
Jiri Slaby | fa1c114 | 2007-08-12 17:33:16 +0200 | [diff] [blame] | 2049 | |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 2050 | if (ah->enable_beacon) { |
Jiri Slaby | fa1c114 | 2007-08-12 17:33:16 +0200 | [diff] [blame] | 2051 | /* |
Bruno Randolf | 036cd1e | 2008-01-19 18:18:21 +0900 | [diff] [blame] | 2052 | * In IBSS mode we use a self-linked tx descriptor and let the |
| 2053 | * hardware send the beacons automatically. We have to load it |
Jiri Slaby | fa1c114 | 2007-08-12 17:33:16 +0200 | [diff] [blame] | 2054 | * only once here. |
Bruno Randolf | 036cd1e | 2008-01-19 18:18:21 +0900 | [diff] [blame] | 2055 | * We use the SWBA interrupt only to keep track of the beacon |
Bruno Randolf | 6ba81c2 | 2008-03-05 18:36:26 +0900 | [diff] [blame] | 2056 | * timers in order to detect automatic TSF updates. |
Jiri Slaby | fa1c114 | 2007-08-12 17:33:16 +0200 | [diff] [blame] | 2057 | */ |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 2058 | ath5k_beaconq_config(ah); |
Jiri Slaby | fa1c114 | 2007-08-12 17:33:16 +0200 | [diff] [blame] | 2059 | |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 2060 | ah->imask |= AR5K_INT_SWBA; |
Bruno Randolf | 036cd1e | 2008-01-19 18:18:21 +0900 | [diff] [blame] | 2061 | |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 2062 | if (ah->opmode == NL80211_IFTYPE_ADHOC) { |
Bob Copeland | 2180049 | 2009-07-04 12:59:52 -0400 | [diff] [blame] | 2063 | if (ath5k_hw_hasveol(ah)) |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 2064 | ath5k_beacon_send(ah); |
Jiri Slaby | da966bc | 2008-10-12 22:54:10 +0200 | [diff] [blame] | 2065 | } else |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 2066 | ath5k_beacon_update_timers(ah, -1); |
Bob Copeland | 2180049 | 2009-07-04 12:59:52 -0400 | [diff] [blame] | 2067 | } else { |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 2068 | ath5k_hw_stop_beacon_queue(ah, ah->bhalq); |
Jiri Slaby | fa1c114 | 2007-08-12 17:33:16 +0200 | [diff] [blame] | 2069 | } |
Jiri Slaby | fa1c114 | 2007-08-12 17:33:16 +0200 | [diff] [blame] | 2070 | |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 2071 | ath5k_hw_set_imr(ah, ah->imask); |
Bob Copeland | 2180049 | 2009-07-04 12:59:52 -0400 | [diff] [blame] | 2072 | mmiowb(); |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 2073 | spin_unlock_irqrestore(&ah->block, flags); |
Jiri Slaby | fa1c114 | 2007-08-12 17:33:16 +0200 | [diff] [blame] | 2074 | } |
| 2075 | |
Nick Kossifidis | 428cbd4 | 2009-04-30 15:55:47 -0400 | [diff] [blame] | 2076 | static void ath5k_tasklet_beacon(unsigned long data) |
| 2077 | { |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 2078 | struct ath5k_hw *ah = (struct ath5k_hw *) data; |
Nick Kossifidis | 428cbd4 | 2009-04-30 15:55:47 -0400 | [diff] [blame] | 2079 | |
| 2080 | /* |
| 2081 | * Software beacon alert--time to send a beacon. |
| 2082 | * |
| 2083 | * In IBSS mode we use this interrupt just to |
| 2084 | * keep track of the next TBTT (target beacon |
Pavel Roskin | 6a2a0e7 | 2011-07-09 00:17:51 -0400 | [diff] [blame] | 2085 | * transmission time) in order to detect whether |
Nick Kossifidis | 428cbd4 | 2009-04-30 15:55:47 -0400 | [diff] [blame] | 2086 | * automatic TSF updates happened. |
| 2087 | */ |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 2088 | if (ah->opmode == NL80211_IFTYPE_ADHOC) { |
Pavel Roskin | 6a2a0e7 | 2011-07-09 00:17:51 -0400 | [diff] [blame] | 2089 | /* XXX: only if VEOL supported */ |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 2090 | u64 tsf = ath5k_hw_get_tsf64(ah); |
| 2091 | ah->nexttbtt += ah->bintval; |
| 2092 | ATH5K_DBG(ah, ATH5K_DEBUG_BEACON, |
Nick Kossifidis | 428cbd4 | 2009-04-30 15:55:47 -0400 | [diff] [blame] | 2093 | "SWBA nexttbtt: %x hw_tu: %x " |
| 2094 | "TSF: %llx\n", |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 2095 | ah->nexttbtt, |
Nick Kossifidis | 428cbd4 | 2009-04-30 15:55:47 -0400 | [diff] [blame] | 2096 | TSF_TO_TU(tsf), |
| 2097 | (unsigned long long) tsf); |
| 2098 | } else { |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 2099 | spin_lock(&ah->block); |
| 2100 | ath5k_beacon_send(ah); |
| 2101 | spin_unlock(&ah->block); |
Nick Kossifidis | 428cbd4 | 2009-04-30 15:55:47 -0400 | [diff] [blame] | 2102 | } |
| 2103 | } |
| 2104 | |
Jiri Slaby | fa1c114 | 2007-08-12 17:33:16 +0200 | [diff] [blame] | 2105 | |
| 2106 | /********************\ |
| 2107 | * Interrupt handling * |
| 2108 | \********************/ |
| 2109 | |
Bruno Randolf | 6a8a3f6 | 2010-03-25 14:49:19 +0900 | [diff] [blame] | 2110 | static void |
| 2111 | ath5k_intr_calibration_poll(struct ath5k_hw *ah) |
| 2112 | { |
Bruno Randolf | 2111ac0 | 2010-04-02 18:44:08 +0900 | [diff] [blame] | 2113 | if (time_is_before_eq_jiffies(ah->ah_cal_next_ani) && |
Nick Kossifidis | ce169ac | 2011-11-25 20:40:23 +0200 | [diff] [blame] | 2114 | !(ah->ah_cal_mask & AR5K_CALIBRATION_FULL) && |
| 2115 | !(ah->ah_cal_mask & AR5K_CALIBRATION_SHORT)) { |
| 2116 | |
| 2117 | /* Run ANI only when calibration is not active */ |
| 2118 | |
Bruno Randolf | 2111ac0 | 2010-04-02 18:44:08 +0900 | [diff] [blame] | 2119 | ah->ah_cal_next_ani = jiffies + |
| 2120 | msecs_to_jiffies(ATH5K_TUNE_CALIBRATION_INTERVAL_ANI); |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 2121 | tasklet_schedule(&ah->ani_tasklet); |
Bruno Randolf | 2111ac0 | 2010-04-02 18:44:08 +0900 | [diff] [blame] | 2122 | |
Nick Kossifidis | ce169ac | 2011-11-25 20:40:23 +0200 | [diff] [blame] | 2123 | } else if (time_is_before_eq_jiffies(ah->ah_cal_next_short) && |
| 2124 | !(ah->ah_cal_mask & AR5K_CALIBRATION_FULL) && |
| 2125 | !(ah->ah_cal_mask & AR5K_CALIBRATION_SHORT)) { |
| 2126 | |
| 2127 | /* Run calibration only when another calibration |
| 2128 | * is not running. |
| 2129 | * |
| 2130 | * Note: This is for both full/short calibration, |
| 2131 | * if it's time for a full one, ath5k_calibrate_work will deal |
| 2132 | * with it. */ |
| 2133 | |
| 2134 | ah->ah_cal_next_short = jiffies + |
| 2135 | msecs_to_jiffies(ATH5K_TUNE_CALIBRATION_INTERVAL_SHORT); |
| 2136 | ieee80211_queue_work(ah->hw, &ah->calib_work); |
Bruno Randolf | 6a8a3f6 | 2010-03-25 14:49:19 +0900 | [diff] [blame] | 2137 | } |
| 2138 | /* we could use SWI to generate enough interrupts to meet our |
| 2139 | * calibration interval requirements, if necessary: |
| 2140 | * AR5K_REG_ENABLE_BITS(ah, AR5K_CR, AR5K_CR_SWI); */ |
| 2141 | } |
| 2142 | |
Felix Fietkau | c266c71 | 2011-04-10 18:32:19 +0200 | [diff] [blame] | 2143 | static void |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 2144 | ath5k_schedule_rx(struct ath5k_hw *ah) |
Felix Fietkau | c266c71 | 2011-04-10 18:32:19 +0200 | [diff] [blame] | 2145 | { |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 2146 | ah->rx_pending = true; |
| 2147 | tasklet_schedule(&ah->rxtq); |
Felix Fietkau | c266c71 | 2011-04-10 18:32:19 +0200 | [diff] [blame] | 2148 | } |
| 2149 | |
| 2150 | static void |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 2151 | ath5k_schedule_tx(struct ath5k_hw *ah) |
Felix Fietkau | c266c71 | 2011-04-10 18:32:19 +0200 | [diff] [blame] | 2152 | { |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 2153 | ah->tx_pending = true; |
| 2154 | tasklet_schedule(&ah->txtq); |
Felix Fietkau | c266c71 | 2011-04-10 18:32:19 +0200 | [diff] [blame] | 2155 | } |
| 2156 | |
Pavel Roskin | f5cbc8b | 2011-06-15 18:03:22 -0400 | [diff] [blame] | 2157 | static irqreturn_t |
Jiri Slaby | fa1c114 | 2007-08-12 17:33:16 +0200 | [diff] [blame] | 2158 | ath5k_intr(int irq, void *dev_id) |
| 2159 | { |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 2160 | struct ath5k_hw *ah = dev_id; |
Jiri Slaby | fa1c114 | 2007-08-12 17:33:16 +0200 | [diff] [blame] | 2161 | enum ath5k_int status; |
| 2162 | unsigned int counter = 1000; |
| 2163 | |
Nick Kossifidis | 34ce644 | 2011-11-25 20:40:22 +0200 | [diff] [blame] | 2164 | |
| 2165 | /* |
| 2166 | * If hw is not ready (or detached) and we get an |
| 2167 | * interrupt, or if we have no interrupts pending |
| 2168 | * (that means it's not for us) skip it. |
| 2169 | * |
| 2170 | * NOTE: Group 0/1 PCI interface registers are not |
| 2171 | * supported on WiSOCs, so we can't check for pending |
| 2172 | * interrupts (ISR belongs to another register group |
| 2173 | * so we are ok). |
| 2174 | */ |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 2175 | if (unlikely(test_bit(ATH_STAT_INVALID, ah->status) || |
Nick Kossifidis | 34ce644 | 2011-11-25 20:40:22 +0200 | [diff] [blame] | 2176 | ((ath5k_get_bus_type(ah) != ATH_AHB) && |
| 2177 | !ath5k_hw_is_intr_pending(ah)))) |
Jiri Slaby | fa1c114 | 2007-08-12 17:33:16 +0200 | [diff] [blame] | 2178 | return IRQ_NONE; |
| 2179 | |
Nick Kossifidis | 34ce644 | 2011-11-25 20:40:22 +0200 | [diff] [blame] | 2180 | /** Main loop **/ |
Jiri Slaby | fa1c114 | 2007-08-12 17:33:16 +0200 | [diff] [blame] | 2181 | do { |
Nick Kossifidis | 34ce644 | 2011-11-25 20:40:22 +0200 | [diff] [blame] | 2182 | ath5k_hw_get_isr(ah, &status); /* NB: clears IRQ too */ |
| 2183 | |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 2184 | ATH5K_DBG(ah, ATH5K_DEBUG_INTR, "status 0x%x/0x%x\n", |
| 2185 | status, ah->imask); |
Nick Kossifidis | 34ce644 | 2011-11-25 20:40:22 +0200 | [diff] [blame] | 2186 | |
| 2187 | /* |
| 2188 | * Fatal hw error -> Log and reset |
| 2189 | * |
| 2190 | * Fatal errors are unrecoverable so we have to |
| 2191 | * reset the card. These errors include bus and |
| 2192 | * dma errors. |
| 2193 | */ |
Jiri Slaby | fa1c114 | 2007-08-12 17:33:16 +0200 | [diff] [blame] | 2194 | if (unlikely(status & AR5K_INT_FATAL)) { |
Nick Kossifidis | 34ce644 | 2011-11-25 20:40:22 +0200 | [diff] [blame] | 2195 | |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 2196 | ATH5K_DBG(ah, ATH5K_DEBUG_RESET, |
Bruno Randolf | 8d67a03 | 2010-06-16 19:11:12 +0900 | [diff] [blame] | 2197 | "fatal int, resetting\n"); |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 2198 | ieee80211_queue_work(ah->hw, &ah->reset_work); |
Nick Kossifidis | 34ce644 | 2011-11-25 20:40:22 +0200 | [diff] [blame] | 2199 | |
| 2200 | /* |
| 2201 | * RX Overrun -> Count and reset if needed |
| 2202 | * |
| 2203 | * Receive buffers are full. Either the bus is busy or |
| 2204 | * the CPU is not fast enough to process all received |
| 2205 | * frames. |
| 2206 | */ |
Jiri Slaby | fa1c114 | 2007-08-12 17:33:16 +0200 | [diff] [blame] | 2207 | } else if (unlikely(status & AR5K_INT_RXORN)) { |
Nick Kossifidis | 34ce644 | 2011-11-25 20:40:22 +0200 | [diff] [blame] | 2208 | |
Bruno Randolf | 87d77c4 | 2010-04-12 16:38:52 +0900 | [diff] [blame] | 2209 | /* |
Bruno Randolf | 87d77c4 | 2010-04-12 16:38:52 +0900 | [diff] [blame] | 2210 | * Older chipsets need a reset to come out of this |
| 2211 | * condition, but we treat it as RX for newer chips. |
Nick Kossifidis | 34ce644 | 2011-11-25 20:40:22 +0200 | [diff] [blame] | 2212 | * We don't know exactly which versions need a reset |
Bruno Randolf | 87d77c4 | 2010-04-12 16:38:52 +0900 | [diff] [blame] | 2213 | * this guess is copied from the HAL. |
| 2214 | */ |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 2215 | ah->stats.rxorn_intr++; |
Nick Kossifidis | 34ce644 | 2011-11-25 20:40:22 +0200 | [diff] [blame] | 2216 | |
Bruno Randolf | 8d67a03 | 2010-06-16 19:11:12 +0900 | [diff] [blame] | 2217 | if (ah->ah_mac_srev < AR5K_SREV_AR5212) { |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 2218 | ATH5K_DBG(ah, ATH5K_DEBUG_RESET, |
Bruno Randolf | 8d67a03 | 2010-06-16 19:11:12 +0900 | [diff] [blame] | 2219 | "rx overrun, resetting\n"); |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 2220 | ieee80211_queue_work(ah->hw, &ah->reset_work); |
Pavel Roskin | d2c7f77 | 2011-07-07 18:14:07 -0400 | [diff] [blame] | 2221 | } else |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 2222 | ath5k_schedule_rx(ah); |
Nick Kossifidis | 34ce644 | 2011-11-25 20:40:22 +0200 | [diff] [blame] | 2223 | |
Jiri Slaby | fa1c114 | 2007-08-12 17:33:16 +0200 | [diff] [blame] | 2224 | } else { |
Nick Kossifidis | 34ce644 | 2011-11-25 20:40:22 +0200 | [diff] [blame] | 2225 | |
| 2226 | /* Software Beacon Alert -> Schedule beacon tasklet */ |
Pavel Roskin | d2c7f77 | 2011-07-07 18:14:07 -0400 | [diff] [blame] | 2227 | if (status & AR5K_INT_SWBA) |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 2228 | tasklet_hi_schedule(&ah->beacontq); |
Pavel Roskin | d2c7f77 | 2011-07-07 18:14:07 -0400 | [diff] [blame] | 2229 | |
Nick Kossifidis | 34ce644 | 2011-11-25 20:40:22 +0200 | [diff] [blame] | 2230 | /* |
| 2231 | * No more RX descriptors -> Just count |
| 2232 | * |
| 2233 | * NB: the hardware should re-read the link when |
| 2234 | * RXE bit is written, but it doesn't work at |
| 2235 | * least on older hardware revs. |
| 2236 | */ |
| 2237 | if (status & AR5K_INT_RXEOL) |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 2238 | ah->stats.rxeol_intr++; |
Nick Kossifidis | 34ce644 | 2011-11-25 20:40:22 +0200 | [diff] [blame] | 2239 | |
| 2240 | |
| 2241 | /* TX Underrun -> Bump tx trigger level */ |
| 2242 | if (status & AR5K_INT_TXURN) |
Jiri Slaby | fa1c114 | 2007-08-12 17:33:16 +0200 | [diff] [blame] | 2243 | ath5k_hw_update_tx_triglevel(ah, true); |
Nick Kossifidis | 34ce644 | 2011-11-25 20:40:22 +0200 | [diff] [blame] | 2244 | |
| 2245 | /* RX -> Schedule rx tasklet */ |
Nick Kossifidis | 4c674c6 | 2008-10-26 20:40:25 +0200 | [diff] [blame] | 2246 | if (status & (AR5K_INT_RXOK | AR5K_INT_RXERR)) |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 2247 | ath5k_schedule_rx(ah); |
Nick Kossifidis | 34ce644 | 2011-11-25 20:40:22 +0200 | [diff] [blame] | 2248 | |
| 2249 | /* TX -> Schedule tx tasklet */ |
| 2250 | if (status & (AR5K_INT_TXOK |
| 2251 | | AR5K_INT_TXDESC |
| 2252 | | AR5K_INT_TXERR |
| 2253 | | AR5K_INT_TXEOL)) |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 2254 | ath5k_schedule_tx(ah); |
Nick Kossifidis | 34ce644 | 2011-11-25 20:40:22 +0200 | [diff] [blame] | 2255 | |
| 2256 | /* Missed beacon -> TODO |
| 2257 | if (status & AR5K_INT_BMISS) |
| 2258 | */ |
| 2259 | |
| 2260 | /* MIB event -> Update counters and notify ANI */ |
Jiri Slaby | fa1c114 | 2007-08-12 17:33:16 +0200 | [diff] [blame] | 2261 | if (status & AR5K_INT_MIB) { |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 2262 | ah->stats.mib_intr++; |
Bruno Randolf | 495391d | 2010-03-25 14:49:36 +0900 | [diff] [blame] | 2263 | ath5k_hw_update_mib_counters(ah); |
Bruno Randolf | 2111ac0 | 2010-04-02 18:44:08 +0900 | [diff] [blame] | 2264 | ath5k_ani_mib_intr(ah); |
Jiri Slaby | fa1c114 | 2007-08-12 17:33:16 +0200 | [diff] [blame] | 2265 | } |
Nick Kossifidis | 34ce644 | 2011-11-25 20:40:22 +0200 | [diff] [blame] | 2266 | |
| 2267 | /* GPIO -> Notify RFKill layer */ |
Tobias Doerffel | e6a3b61 | 2009-06-09 17:33:27 +0200 | [diff] [blame] | 2268 | if (status & AR5K_INT_GPIO) |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 2269 | tasklet_schedule(&ah->rf_kill.toggleq); |
Bob Copeland | a6ae071 | 2009-06-09 23:43:11 -0400 | [diff] [blame] | 2270 | |
Jiri Slaby | fa1c114 | 2007-08-12 17:33:16 +0200 | [diff] [blame] | 2271 | } |
Felix Fietkau | 4cebb34 | 2010-12-02 10:27:21 +0100 | [diff] [blame] | 2272 | |
| 2273 | if (ath5k_get_bus_type(ah) == ATH_AHB) |
| 2274 | break; |
| 2275 | |
Bob Copeland | 2516baa | 2009-04-27 22:18:10 -0400 | [diff] [blame] | 2276 | } while (ath5k_hw_is_intr_pending(ah) && --counter > 0); |
Jiri Slaby | fa1c114 | 2007-08-12 17:33:16 +0200 | [diff] [blame] | 2277 | |
Nick Kossifidis | 34ce644 | 2011-11-25 20:40:22 +0200 | [diff] [blame] | 2278 | /* |
| 2279 | * Until we handle rx/tx interrupts mask them on IMR |
| 2280 | * |
| 2281 | * NOTE: ah->(rx/tx)_pending are set when scheduling the tasklets |
| 2282 | * and unset after we 've handled the interrupts. |
| 2283 | */ |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 2284 | if (ah->rx_pending || ah->tx_pending) |
| 2285 | ath5k_set_current_imask(ah); |
Felix Fietkau | c266c71 | 2011-04-10 18:32:19 +0200 | [diff] [blame] | 2286 | |
Jiri Slaby | fa1c114 | 2007-08-12 17:33:16 +0200 | [diff] [blame] | 2287 | if (unlikely(!counter)) |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 2288 | ATH5K_WARN(ah, "too many interrupts, giving up for now\n"); |
Jiri Slaby | fa1c114 | 2007-08-12 17:33:16 +0200 | [diff] [blame] | 2289 | |
Nick Kossifidis | 34ce644 | 2011-11-25 20:40:22 +0200 | [diff] [blame] | 2290 | /* Fire up calibration poll */ |
Bruno Randolf | 6a8a3f6 | 2010-03-25 14:49:19 +0900 | [diff] [blame] | 2291 | ath5k_intr_calibration_poll(ah); |
Nick Kossifidis | 6e220662 | 2009-08-10 03:31:31 +0300 | [diff] [blame] | 2292 | |
Jiri Slaby | fa1c114 | 2007-08-12 17:33:16 +0200 | [diff] [blame] | 2293 | return IRQ_HANDLED; |
| 2294 | } |
| 2295 | |
Jiri Slaby | fa1c114 | 2007-08-12 17:33:16 +0200 | [diff] [blame] | 2296 | /* |
| 2297 | * Periodically recalibrate the PHY to account |
| 2298 | * for temperature/environment changes. |
| 2299 | */ |
| 2300 | static void |
Nick Kossifidis | ce169ac | 2011-11-25 20:40:23 +0200 | [diff] [blame] | 2301 | ath5k_calibrate_work(struct work_struct *work) |
Jiri Slaby | fa1c114 | 2007-08-12 17:33:16 +0200 | [diff] [blame] | 2302 | { |
Nick Kossifidis | ce169ac | 2011-11-25 20:40:23 +0200 | [diff] [blame] | 2303 | struct ath5k_hw *ah = container_of(work, struct ath5k_hw, |
| 2304 | calib_work); |
Jiri Slaby | fa1c114 | 2007-08-12 17:33:16 +0200 | [diff] [blame] | 2305 | |
Nick Kossifidis | ce169ac | 2011-11-25 20:40:23 +0200 | [diff] [blame] | 2306 | /* Should we run a full calibration ? */ |
| 2307 | if (time_is_before_eq_jiffies(ah->ah_cal_next_full)) { |
| 2308 | |
| 2309 | ah->ah_cal_next_full = jiffies + |
| 2310 | msecs_to_jiffies(ATH5K_TUNE_CALIBRATION_INTERVAL_FULL); |
| 2311 | ah->ah_cal_mask |= AR5K_CALIBRATION_FULL; |
| 2312 | |
| 2313 | ATH5K_DBG(ah, ATH5K_DEBUG_CALIBRATE, |
| 2314 | "running full calibration\n"); |
| 2315 | |
| 2316 | if (ath5k_hw_gainf_calibrate(ah) == AR5K_RFGAIN_NEED_CHANGE) { |
| 2317 | /* |
| 2318 | * Rfgain is out of bounds, reset the chip |
| 2319 | * to load new gain values. |
| 2320 | */ |
| 2321 | ATH5K_DBG(ah, ATH5K_DEBUG_RESET, |
| 2322 | "got new rfgain, resetting\n"); |
| 2323 | ieee80211_queue_work(ah->hw, &ah->reset_work); |
| 2324 | } |
| 2325 | |
| 2326 | /* TODO: On full calibration we should stop TX here, |
| 2327 | * so that it doesn't interfere (mostly due to gain_f |
| 2328 | * calibration that messes with tx packets -see phy.c). |
| 2329 | * |
| 2330 | * NOTE: Stopping the queues from above is not enough |
| 2331 | * to stop TX but saves us from disconecting (at least |
| 2332 | * we don't lose packets). */ |
| 2333 | ieee80211_stop_queues(ah->hw); |
| 2334 | } else |
| 2335 | ah->ah_cal_mask |= AR5K_CALIBRATION_SHORT; |
| 2336 | |
Nick Kossifidis | 6e220662 | 2009-08-10 03:31:31 +0300 | [diff] [blame] | 2337 | |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 2338 | ATH5K_DBG(ah, ATH5K_DEBUG_CALIBRATE, "channel %u/%x\n", |
| 2339 | ieee80211_frequency_to_channel(ah->curchan->center_freq), |
| 2340 | ah->curchan->hw_value); |
Jiri Slaby | fa1c114 | 2007-08-12 17:33:16 +0200 | [diff] [blame] | 2341 | |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 2342 | if (ath5k_hw_phy_calibrate(ah, ah->curchan)) |
| 2343 | ATH5K_ERR(ah, "calibration of channel %u failed\n", |
Luis R. Rodriguez | 400ec45 | 2008-02-03 21:51:49 -0500 | [diff] [blame] | 2344 | ieee80211_frequency_to_channel( |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 2345 | ah->curchan->center_freq)); |
Jiri Slaby | fa1c114 | 2007-08-12 17:33:16 +0200 | [diff] [blame] | 2346 | |
Nick Kossifidis | ce169ac | 2011-11-25 20:40:23 +0200 | [diff] [blame] | 2347 | /* Clear calibration flags */ |
| 2348 | if (ah->ah_cal_mask & AR5K_CALIBRATION_FULL) { |
| 2349 | ieee80211_wake_queues(ah->hw); |
| 2350 | ah->ah_cal_mask &= ~AR5K_CALIBRATION_FULL; |
| 2351 | } else if (ah->ah_cal_mask & AR5K_CALIBRATION_SHORT) |
| 2352 | ah->ah_cal_mask &= ~AR5K_CALIBRATION_SHORT; |
Jiri Slaby | fa1c114 | 2007-08-12 17:33:16 +0200 | [diff] [blame] | 2353 | } |
| 2354 | |
| 2355 | |
Bruno Randolf | 2111ac0 | 2010-04-02 18:44:08 +0900 | [diff] [blame] | 2356 | static void |
| 2357 | ath5k_tasklet_ani(unsigned long data) |
| 2358 | { |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 2359 | struct ath5k_hw *ah = (void *)data; |
Bruno Randolf | 2111ac0 | 2010-04-02 18:44:08 +0900 | [diff] [blame] | 2360 | |
| 2361 | ah->ah_cal_mask |= AR5K_CALIBRATION_ANI; |
| 2362 | ath5k_ani_calibration(ah); |
| 2363 | ah->ah_cal_mask &= ~AR5K_CALIBRATION_ANI; |
Jiri Slaby | fa1c114 | 2007-08-12 17:33:16 +0200 | [diff] [blame] | 2364 | } |
| 2365 | |
| 2366 | |
Bruno Randolf | 4edd761 | 2010-09-17 11:36:56 +0900 | [diff] [blame] | 2367 | static void |
| 2368 | ath5k_tx_complete_poll_work(struct work_struct *work) |
| 2369 | { |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 2370 | struct ath5k_hw *ah = container_of(work, struct ath5k_hw, |
Bruno Randolf | 4edd761 | 2010-09-17 11:36:56 +0900 | [diff] [blame] | 2371 | tx_complete_work.work); |
| 2372 | struct ath5k_txq *txq; |
| 2373 | int i; |
| 2374 | bool needreset = false; |
| 2375 | |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 2376 | mutex_lock(&ah->lock); |
Bob Copeland | 599b13a | 2011-01-18 08:06:43 -0500 | [diff] [blame] | 2377 | |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 2378 | for (i = 0; i < ARRAY_SIZE(ah->txqs); i++) { |
| 2379 | if (ah->txqs[i].setup) { |
| 2380 | txq = &ah->txqs[i]; |
Bruno Randolf | 4edd761 | 2010-09-17 11:36:56 +0900 | [diff] [blame] | 2381 | spin_lock_bh(&txq->lock); |
Bruno Randolf | 2341329 | 2010-09-17 11:37:07 +0900 | [diff] [blame] | 2382 | if (txq->txq_len > 1) { |
Bruno Randolf | 4edd761 | 2010-09-17 11:36:56 +0900 | [diff] [blame] | 2383 | if (txq->txq_poll_mark) { |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 2384 | ATH5K_DBG(ah, ATH5K_DEBUG_XMIT, |
Bruno Randolf | 4edd761 | 2010-09-17 11:36:56 +0900 | [diff] [blame] | 2385 | "TX queue stuck %d\n", |
| 2386 | txq->qnum); |
| 2387 | needreset = true; |
Bruno Randolf | 923e5b3 | 2010-09-17 11:37:02 +0900 | [diff] [blame] | 2388 | txq->txq_stuck++; |
Bruno Randolf | 4edd761 | 2010-09-17 11:36:56 +0900 | [diff] [blame] | 2389 | spin_unlock_bh(&txq->lock); |
| 2390 | break; |
| 2391 | } else { |
| 2392 | txq->txq_poll_mark = true; |
| 2393 | } |
| 2394 | } |
| 2395 | spin_unlock_bh(&txq->lock); |
| 2396 | } |
| 2397 | } |
| 2398 | |
| 2399 | if (needreset) { |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 2400 | ATH5K_DBG(ah, ATH5K_DEBUG_RESET, |
Bruno Randolf | 4edd761 | 2010-09-17 11:36:56 +0900 | [diff] [blame] | 2401 | "TX queues stuck, resetting\n"); |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 2402 | ath5k_reset(ah, NULL, true); |
Bruno Randolf | 4edd761 | 2010-09-17 11:36:56 +0900 | [diff] [blame] | 2403 | } |
| 2404 | |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 2405 | mutex_unlock(&ah->lock); |
Bob Copeland | 599b13a | 2011-01-18 08:06:43 -0500 | [diff] [blame] | 2406 | |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 2407 | ieee80211_queue_delayed_work(ah->hw, &ah->tx_complete_work, |
Bruno Randolf | 4edd761 | 2010-09-17 11:36:56 +0900 | [diff] [blame] | 2408 | msecs_to_jiffies(ATH5K_TX_COMPLETE_POLL_INT)); |
| 2409 | } |
| 2410 | |
| 2411 | |
Bob Copeland | 8a63fac | 2010-09-17 12:45:07 +0900 | [diff] [blame] | 2412 | /*************************\ |
| 2413 | * Initialization routines * |
| 2414 | \*************************/ |
Jiri Slaby | fa1c114 | 2007-08-12 17:33:16 +0200 | [diff] [blame] | 2415 | |
Pavel Roskin | 25380d8 | 2011-07-07 18:13:42 -0400 | [diff] [blame] | 2416 | int __devinit |
Pavel Roskin | bb1f3ad | 2011-07-26 22:27:05 -0400 | [diff] [blame] | 2417 | ath5k_init_ah(struct ath5k_hw *ah, const struct ath_bus_ops *bus_ops) |
Felix Fietkau | 132b1c3 | 2010-12-02 10:26:56 +0100 | [diff] [blame] | 2418 | { |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 2419 | struct ieee80211_hw *hw = ah->hw; |
Felix Fietkau | 132b1c3 | 2010-12-02 10:26:56 +0100 | [diff] [blame] | 2420 | struct ath_common *common; |
| 2421 | int ret; |
| 2422 | int csz; |
| 2423 | |
| 2424 | /* Initialize driver private data */ |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 2425 | SET_IEEE80211_DEV(hw, ah->dev); |
Felix Fietkau | 132b1c3 | 2010-12-02 10:26:56 +0100 | [diff] [blame] | 2426 | hw->flags = IEEE80211_HW_RX_INCLUDES_FCS | |
Nick Kossifidis | b9e61f1 | 2010-12-03 06:12:39 +0200 | [diff] [blame] | 2427 | IEEE80211_HW_HOST_BROADCAST_PS_BUFFERING | |
| 2428 | IEEE80211_HW_SIGNAL_DBM | |
| 2429 | IEEE80211_HW_REPORTS_TX_ACK_STATUS; |
Felix Fietkau | 132b1c3 | 2010-12-02 10:26:56 +0100 | [diff] [blame] | 2430 | |
| 2431 | hw->wiphy->interface_modes = |
| 2432 | BIT(NL80211_IFTYPE_AP) | |
| 2433 | BIT(NL80211_IFTYPE_STATION) | |
| 2434 | BIT(NL80211_IFTYPE_ADHOC) | |
| 2435 | BIT(NL80211_IFTYPE_MESH_POINT); |
| 2436 | |
Bruno Randolf | 3de135d | 2010-12-16 11:30:33 +0900 | [diff] [blame] | 2437 | /* both antennas can be configured as RX or TX */ |
| 2438 | hw->wiphy->available_antennas_tx = 0x3; |
| 2439 | hw->wiphy->available_antennas_rx = 0x3; |
| 2440 | |
Felix Fietkau | 132b1c3 | 2010-12-02 10:26:56 +0100 | [diff] [blame] | 2441 | hw->extra_tx_headroom = 2; |
| 2442 | hw->channel_change_time = 5000; |
| 2443 | |
| 2444 | /* |
| 2445 | * Mark the device as detached to avoid processing |
| 2446 | * interrupts until setup is complete. |
| 2447 | */ |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 2448 | __set_bit(ATH_STAT_INVALID, ah->status); |
Felix Fietkau | 132b1c3 | 2010-12-02 10:26:56 +0100 | [diff] [blame] | 2449 | |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 2450 | ah->opmode = NL80211_IFTYPE_STATION; |
| 2451 | ah->bintval = 1000; |
| 2452 | mutex_init(&ah->lock); |
| 2453 | spin_lock_init(&ah->rxbuflock); |
| 2454 | spin_lock_init(&ah->txbuflock); |
| 2455 | spin_lock_init(&ah->block); |
| 2456 | spin_lock_init(&ah->irqlock); |
Felix Fietkau | 132b1c3 | 2010-12-02 10:26:56 +0100 | [diff] [blame] | 2457 | |
| 2458 | /* Setup interrupt handler */ |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 2459 | ret = request_irq(ah->irq, ath5k_intr, IRQF_SHARED, "ath", ah); |
Felix Fietkau | 132b1c3 | 2010-12-02 10:26:56 +0100 | [diff] [blame] | 2460 | if (ret) { |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 2461 | ATH5K_ERR(ah, "request_irq failed\n"); |
Felix Fietkau | 132b1c3 | 2010-12-02 10:26:56 +0100 | [diff] [blame] | 2462 | goto err; |
| 2463 | } |
| 2464 | |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 2465 | common = ath5k_hw_common(ah); |
Felix Fietkau | 132b1c3 | 2010-12-02 10:26:56 +0100 | [diff] [blame] | 2466 | common->ops = &ath5k_common_ops; |
| 2467 | common->bus_ops = bus_ops; |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 2468 | common->ah = ah; |
Felix Fietkau | 132b1c3 | 2010-12-02 10:26:56 +0100 | [diff] [blame] | 2469 | common->hw = hw; |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 2470 | common->priv = ah; |
Felix Fietkau | 26d16d2 | 2011-07-12 09:02:01 +0800 | [diff] [blame] | 2471 | common->clockrate = 40; |
Felix Fietkau | 132b1c3 | 2010-12-02 10:26:56 +0100 | [diff] [blame] | 2472 | |
| 2473 | /* |
| 2474 | * Cache line size is used to size and align various |
| 2475 | * structures used to communicate with the hardware. |
| 2476 | */ |
| 2477 | ath5k_read_cachesize(common, &csz); |
| 2478 | common->cachelsz = csz << 2; /* convert to bytes */ |
| 2479 | |
| 2480 | spin_lock_init(&common->cc_lock); |
| 2481 | |
| 2482 | /* Initialize device */ |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 2483 | ret = ath5k_hw_init(ah); |
Felix Fietkau | 132b1c3 | 2010-12-02 10:26:56 +0100 | [diff] [blame] | 2484 | if (ret) |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 2485 | goto err_irq; |
Felix Fietkau | 132b1c3 | 2010-12-02 10:26:56 +0100 | [diff] [blame] | 2486 | |
| 2487 | /* set up multi-rate retry capabilities */ |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 2488 | if (ah->ah_version == AR5K_AR5212) { |
Felix Fietkau | 132b1c3 | 2010-12-02 10:26:56 +0100 | [diff] [blame] | 2489 | hw->max_rates = 4; |
Bruno Randolf | 76a9f6f | 2011-01-28 16:52:11 +0900 | [diff] [blame] | 2490 | hw->max_rate_tries = max(AR5K_INIT_RETRY_SHORT, |
| 2491 | AR5K_INIT_RETRY_LONG); |
Felix Fietkau | 132b1c3 | 2010-12-02 10:26:56 +0100 | [diff] [blame] | 2492 | } |
| 2493 | |
| 2494 | hw->vif_data_size = sizeof(struct ath5k_vif); |
| 2495 | |
| 2496 | /* Finish private driver data initialization */ |
| 2497 | ret = ath5k_init(hw); |
| 2498 | if (ret) |
| 2499 | goto err_ah; |
| 2500 | |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 2501 | ATH5K_INFO(ah, "Atheros AR%s chip found (MAC: 0x%x, PHY: 0x%x)\n", |
| 2502 | ath5k_chip_name(AR5K_VERSION_MAC, ah->ah_mac_srev), |
| 2503 | ah->ah_mac_srev, |
| 2504 | ah->ah_phy_revision); |
Felix Fietkau | 132b1c3 | 2010-12-02 10:26:56 +0100 | [diff] [blame] | 2505 | |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 2506 | if (!ah->ah_single_chip) { |
Felix Fietkau | 132b1c3 | 2010-12-02 10:26:56 +0100 | [diff] [blame] | 2507 | /* Single chip radio (!RF5111) */ |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 2508 | if (ah->ah_radio_5ghz_revision && |
| 2509 | !ah->ah_radio_2ghz_revision) { |
Felix Fietkau | 132b1c3 | 2010-12-02 10:26:56 +0100 | [diff] [blame] | 2510 | /* No 5GHz support -> report 2GHz radio */ |
| 2511 | if (!test_bit(AR5K_MODE_11A, |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 2512 | ah->ah_capabilities.cap_mode)) { |
| 2513 | ATH5K_INFO(ah, "RF%s 2GHz radio found (0x%x)\n", |
Felix Fietkau | 132b1c3 | 2010-12-02 10:26:56 +0100 | [diff] [blame] | 2514 | ath5k_chip_name(AR5K_VERSION_RAD, |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 2515 | ah->ah_radio_5ghz_revision), |
| 2516 | ah->ah_radio_5ghz_revision); |
Felix Fietkau | 132b1c3 | 2010-12-02 10:26:56 +0100 | [diff] [blame] | 2517 | /* No 2GHz support (5110 and some |
Pavel Roskin | 6a2a0e7 | 2011-07-09 00:17:51 -0400 | [diff] [blame] | 2518 | * 5GHz only cards) -> report 5GHz radio */ |
Felix Fietkau | 132b1c3 | 2010-12-02 10:26:56 +0100 | [diff] [blame] | 2519 | } else if (!test_bit(AR5K_MODE_11B, |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 2520 | ah->ah_capabilities.cap_mode)) { |
| 2521 | ATH5K_INFO(ah, "RF%s 5GHz radio found (0x%x)\n", |
Felix Fietkau | 132b1c3 | 2010-12-02 10:26:56 +0100 | [diff] [blame] | 2522 | ath5k_chip_name(AR5K_VERSION_RAD, |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 2523 | ah->ah_radio_5ghz_revision), |
| 2524 | ah->ah_radio_5ghz_revision); |
Felix Fietkau | 132b1c3 | 2010-12-02 10:26:56 +0100 | [diff] [blame] | 2525 | /* Multiband radio */ |
| 2526 | } else { |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 2527 | ATH5K_INFO(ah, "RF%s multiband radio found" |
Felix Fietkau | 132b1c3 | 2010-12-02 10:26:56 +0100 | [diff] [blame] | 2528 | " (0x%x)\n", |
| 2529 | ath5k_chip_name(AR5K_VERSION_RAD, |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 2530 | ah->ah_radio_5ghz_revision), |
| 2531 | ah->ah_radio_5ghz_revision); |
Felix Fietkau | 132b1c3 | 2010-12-02 10:26:56 +0100 | [diff] [blame] | 2532 | } |
| 2533 | } |
| 2534 | /* Multi chip radio (RF5111 - RF2111) -> |
| 2535 | * report both 2GHz/5GHz radios */ |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 2536 | else if (ah->ah_radio_5ghz_revision && |
| 2537 | ah->ah_radio_2ghz_revision) { |
| 2538 | ATH5K_INFO(ah, "RF%s 5GHz radio found (0x%x)\n", |
Felix Fietkau | 132b1c3 | 2010-12-02 10:26:56 +0100 | [diff] [blame] | 2539 | ath5k_chip_name(AR5K_VERSION_RAD, |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 2540 | ah->ah_radio_5ghz_revision), |
| 2541 | ah->ah_radio_5ghz_revision); |
| 2542 | ATH5K_INFO(ah, "RF%s 2GHz radio found (0x%x)\n", |
Felix Fietkau | 132b1c3 | 2010-12-02 10:26:56 +0100 | [diff] [blame] | 2543 | ath5k_chip_name(AR5K_VERSION_RAD, |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 2544 | ah->ah_radio_2ghz_revision), |
| 2545 | ah->ah_radio_2ghz_revision); |
Felix Fietkau | 132b1c3 | 2010-12-02 10:26:56 +0100 | [diff] [blame] | 2546 | } |
| 2547 | } |
| 2548 | |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 2549 | ath5k_debug_init_device(ah); |
Felix Fietkau | 132b1c3 | 2010-12-02 10:26:56 +0100 | [diff] [blame] | 2550 | |
| 2551 | /* ready to process interrupts */ |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 2552 | __clear_bit(ATH_STAT_INVALID, ah->status); |
Felix Fietkau | 132b1c3 | 2010-12-02 10:26:56 +0100 | [diff] [blame] | 2553 | |
| 2554 | return 0; |
| 2555 | err_ah: |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 2556 | ath5k_hw_deinit(ah); |
Felix Fietkau | 132b1c3 | 2010-12-02 10:26:56 +0100 | [diff] [blame] | 2557 | err_irq: |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 2558 | free_irq(ah->irq, ah); |
Felix Fietkau | 132b1c3 | 2010-12-02 10:26:56 +0100 | [diff] [blame] | 2559 | err: |
| 2560 | return ret; |
| 2561 | } |
| 2562 | |
Jiri Slaby | fa1c114 | 2007-08-12 17:33:16 +0200 | [diff] [blame] | 2563 | static int |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 2564 | ath5k_stop_locked(struct ath5k_hw *ah) |
Jiri Slaby | fa1c114 | 2007-08-12 17:33:16 +0200 | [diff] [blame] | 2565 | { |
Bob Copeland | cec8db2 | 2009-07-04 12:59:51 -0400 | [diff] [blame] | 2566 | |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 2567 | ATH5K_DBG(ah, ATH5K_DEBUG_RESET, "invalid %u\n", |
| 2568 | test_bit(ATH_STAT_INVALID, ah->status)); |
Jiri Slaby | fa1c114 | 2007-08-12 17:33:16 +0200 | [diff] [blame] | 2569 | |
Jiri Slaby | fa1c114 | 2007-08-12 17:33:16 +0200 | [diff] [blame] | 2570 | /* |
Bob Copeland | 8a63fac | 2010-09-17 12:45:07 +0900 | [diff] [blame] | 2571 | * Shutdown the hardware and driver: |
| 2572 | * stop output from above |
| 2573 | * disable interrupts |
| 2574 | * turn off timers |
| 2575 | * turn off the radio |
| 2576 | * clear transmit machinery |
| 2577 | * clear receive machinery |
| 2578 | * drain and release tx queues |
| 2579 | * reclaim beacon resources |
| 2580 | * power down hardware |
| 2581 | * |
| 2582 | * Note that some of this work is not possible if the |
| 2583 | * hardware is gone (invalid). |
Jiri Slaby | fa1c114 | 2007-08-12 17:33:16 +0200 | [diff] [blame] | 2584 | */ |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 2585 | ieee80211_stop_queues(ah->hw); |
Bob Copeland | 8a63fac | 2010-09-17 12:45:07 +0900 | [diff] [blame] | 2586 | |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 2587 | if (!test_bit(ATH_STAT_INVALID, ah->status)) { |
| 2588 | ath5k_led_off(ah); |
Bob Copeland | 8a63fac | 2010-09-17 12:45:07 +0900 | [diff] [blame] | 2589 | ath5k_hw_set_imr(ah, 0); |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 2590 | synchronize_irq(ah->irq); |
| 2591 | ath5k_rx_stop(ah); |
Nick Kossifidis | 80dac9e | 2010-11-23 20:45:38 +0200 | [diff] [blame] | 2592 | ath5k_hw_dma_stop(ah); |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 2593 | ath5k_drain_tx_buffs(ah); |
Bob Copeland | 8a63fac | 2010-09-17 12:45:07 +0900 | [diff] [blame] | 2594 | ath5k_hw_phy_disable(ah); |
Jiri Slaby | fa1c114 | 2007-08-12 17:33:16 +0200 | [diff] [blame] | 2595 | } |
| 2596 | |
Bob Copeland | 8a63fac | 2010-09-17 12:45:07 +0900 | [diff] [blame] | 2597 | return 0; |
| 2598 | } |
| 2599 | |
Pavel Roskin | fabba04 | 2011-07-21 13:36:28 -0400 | [diff] [blame] | 2600 | int ath5k_start(struct ieee80211_hw *hw) |
Bob Copeland | 8a63fac | 2010-09-17 12:45:07 +0900 | [diff] [blame] | 2601 | { |
Pavel Roskin | fabba04 | 2011-07-21 13:36:28 -0400 | [diff] [blame] | 2602 | struct ath5k_hw *ah = hw->priv; |
Bob Copeland | 8a63fac | 2010-09-17 12:45:07 +0900 | [diff] [blame] | 2603 | struct ath_common *common = ath5k_hw_common(ah); |
| 2604 | int ret, i; |
| 2605 | |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 2606 | mutex_lock(&ah->lock); |
Bob Copeland | 8a63fac | 2010-09-17 12:45:07 +0900 | [diff] [blame] | 2607 | |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 2608 | ATH5K_DBG(ah, ATH5K_DEBUG_RESET, "mode %d\n", ah->opmode); |
Bob Copeland | 8a63fac | 2010-09-17 12:45:07 +0900 | [diff] [blame] | 2609 | |
| 2610 | /* |
| 2611 | * Stop anything previously setup. This is safe |
| 2612 | * no matter this is the first time through or not. |
| 2613 | */ |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 2614 | ath5k_stop_locked(ah); |
Bob Copeland | 8a63fac | 2010-09-17 12:45:07 +0900 | [diff] [blame] | 2615 | |
| 2616 | /* |
| 2617 | * The basic interface to setting the hardware in a good |
| 2618 | * state is ``reset''. On return the hardware is known to |
| 2619 | * be powered up and with interrupts disabled. This must |
| 2620 | * be followed by initialization of the appropriate bits |
| 2621 | * and then setup of the interrupt mask. |
| 2622 | */ |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 2623 | ah->curchan = ah->hw->conf.channel; |
Nick Kossifidis | 34ce644 | 2011-11-25 20:40:22 +0200 | [diff] [blame] | 2624 | ah->imask = AR5K_INT_RXOK |
| 2625 | | AR5K_INT_RXERR |
| 2626 | | AR5K_INT_RXEOL |
| 2627 | | AR5K_INT_RXORN |
| 2628 | | AR5K_INT_TXDESC |
| 2629 | | AR5K_INT_TXEOL |
| 2630 | | AR5K_INT_FATAL |
| 2631 | | AR5K_INT_GLOBAL |
| 2632 | | AR5K_INT_MIB; |
Bob Copeland | 8a63fac | 2010-09-17 12:45:07 +0900 | [diff] [blame] | 2633 | |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 2634 | ret = ath5k_reset(ah, NULL, false); |
Bob Copeland | 8a63fac | 2010-09-17 12:45:07 +0900 | [diff] [blame] | 2635 | if (ret) |
| 2636 | goto done; |
| 2637 | |
| 2638 | ath5k_rfkill_hw_start(ah); |
| 2639 | |
| 2640 | /* |
| 2641 | * Reset the key cache since some parts do not reset the |
| 2642 | * contents on initial power up or resume from suspend. |
| 2643 | */ |
| 2644 | for (i = 0; i < common->keymax; i++) |
| 2645 | ath_hw_keyreset(common, (u16) i); |
| 2646 | |
Nick Kossifidis | 61cde03 | 2010-11-23 21:12:23 +0200 | [diff] [blame] | 2647 | /* Use higher rates for acks instead of base |
| 2648 | * rate */ |
| 2649 | ah->ah_ack_bitrate_high = true; |
Ben Greear | b1ae1ed | 2010-09-30 12:22:58 -0700 | [diff] [blame] | 2650 | |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 2651 | for (i = 0; i < ARRAY_SIZE(ah->bslot); i++) |
| 2652 | ah->bslot[i] = NULL; |
Ben Greear | b1ae1ed | 2010-09-30 12:22:58 -0700 | [diff] [blame] | 2653 | |
Bob Copeland | 8a63fac | 2010-09-17 12:45:07 +0900 | [diff] [blame] | 2654 | ret = 0; |
| 2655 | done: |
| 2656 | mmiowb(); |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 2657 | mutex_unlock(&ah->lock); |
Bruno Randolf | 4edd761 | 2010-09-17 11:36:56 +0900 | [diff] [blame] | 2658 | |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 2659 | ieee80211_queue_delayed_work(ah->hw, &ah->tx_complete_work, |
Bruno Randolf | 4edd761 | 2010-09-17 11:36:56 +0900 | [diff] [blame] | 2660 | msecs_to_jiffies(ATH5K_TX_COMPLETE_POLL_INT)); |
| 2661 | |
Bob Copeland | 8a63fac | 2010-09-17 12:45:07 +0900 | [diff] [blame] | 2662 | return ret; |
| 2663 | } |
| 2664 | |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 2665 | static void ath5k_stop_tasklets(struct ath5k_hw *ah) |
Bob Copeland | 8a63fac | 2010-09-17 12:45:07 +0900 | [diff] [blame] | 2666 | { |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 2667 | ah->rx_pending = false; |
| 2668 | ah->tx_pending = false; |
| 2669 | tasklet_kill(&ah->rxtq); |
| 2670 | tasklet_kill(&ah->txtq); |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 2671 | tasklet_kill(&ah->beacontq); |
| 2672 | tasklet_kill(&ah->ani_tasklet); |
Bob Copeland | 8a63fac | 2010-09-17 12:45:07 +0900 | [diff] [blame] | 2673 | } |
| 2674 | |
| 2675 | /* |
| 2676 | * Stop the device, grabbing the top-level lock to protect |
| 2677 | * against concurrent entry through ath5k_init (which can happen |
| 2678 | * if another thread does a system call and the thread doing the |
| 2679 | * stop is preempted). |
| 2680 | */ |
Pavel Roskin | fabba04 | 2011-07-21 13:36:28 -0400 | [diff] [blame] | 2681 | void ath5k_stop(struct ieee80211_hw *hw) |
Bob Copeland | 8a63fac | 2010-09-17 12:45:07 +0900 | [diff] [blame] | 2682 | { |
Pavel Roskin | fabba04 | 2011-07-21 13:36:28 -0400 | [diff] [blame] | 2683 | struct ath5k_hw *ah = hw->priv; |
Bob Copeland | 8a63fac | 2010-09-17 12:45:07 +0900 | [diff] [blame] | 2684 | int ret; |
| 2685 | |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 2686 | mutex_lock(&ah->lock); |
| 2687 | ret = ath5k_stop_locked(ah); |
| 2688 | if (ret == 0 && !test_bit(ATH_STAT_INVALID, ah->status)) { |
Bob Copeland | 8a63fac | 2010-09-17 12:45:07 +0900 | [diff] [blame] | 2689 | /* |
| 2690 | * Don't set the card in full sleep mode! |
| 2691 | * |
| 2692 | * a) When the device is in this state it must be carefully |
| 2693 | * woken up or references to registers in the PCI clock |
| 2694 | * domain may freeze the bus (and system). This varies |
| 2695 | * by chip and is mostly an issue with newer parts |
| 2696 | * (madwifi sources mentioned srev >= 0x78) that go to |
| 2697 | * sleep more quickly. |
| 2698 | * |
| 2699 | * b) On older chips full sleep results a weird behaviour |
| 2700 | * during wakeup. I tested various cards with srev < 0x78 |
| 2701 | * and they don't wake up after module reload, a second |
| 2702 | * module reload is needed to bring the card up again. |
| 2703 | * |
| 2704 | * Until we figure out what's going on don't enable |
| 2705 | * full chip reset on any chip (this is what Legacy HAL |
| 2706 | * and Sam's HAL do anyway). Instead Perform a full reset |
| 2707 | * on the device (same as initial state after attach) and |
| 2708 | * leave it idle (keep MAC/BB on warm reset) */ |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 2709 | ret = ath5k_hw_on_hold(ah); |
Bob Copeland | 8a63fac | 2010-09-17 12:45:07 +0900 | [diff] [blame] | 2710 | |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 2711 | ATH5K_DBG(ah, ATH5K_DEBUG_RESET, |
Bob Copeland | 8a63fac | 2010-09-17 12:45:07 +0900 | [diff] [blame] | 2712 | "putting device to sleep\n"); |
Jiri Slaby | fa1c114 | 2007-08-12 17:33:16 +0200 | [diff] [blame] | 2713 | } |
Jiri Slaby | fa1c114 | 2007-08-12 17:33:16 +0200 | [diff] [blame] | 2714 | |
Bob Copeland | 8a63fac | 2010-09-17 12:45:07 +0900 | [diff] [blame] | 2715 | mmiowb(); |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 2716 | mutex_unlock(&ah->lock); |
Jiri Slaby | fa1c114 | 2007-08-12 17:33:16 +0200 | [diff] [blame] | 2717 | |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 2718 | ath5k_stop_tasklets(ah); |
Jiri Slaby | fa1c114 | 2007-08-12 17:33:16 +0200 | [diff] [blame] | 2719 | |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 2720 | cancel_delayed_work_sync(&ah->tx_complete_work); |
Bruno Randolf | 4edd761 | 2010-09-17 11:36:56 +0900 | [diff] [blame] | 2721 | |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 2722 | ath5k_rfkill_hw_stop(ah); |
Jiri Slaby | fa1c114 | 2007-08-12 17:33:16 +0200 | [diff] [blame] | 2723 | } |
| 2724 | |
Bob Copeland | 209d889 | 2009-05-07 08:09:08 -0400 | [diff] [blame] | 2725 | /* |
| 2726 | * Reset the hardware. If chan is not NULL, then also pause rx/tx |
| 2727 | * and change to the given channel. |
Bob Copeland | 5faaff7 | 2010-07-13 11:32:40 -0400 | [diff] [blame] | 2728 | * |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 2729 | * This should be called with ah->lock. |
Bob Copeland | 209d889 | 2009-05-07 08:09:08 -0400 | [diff] [blame] | 2730 | */ |
Jiri Slaby | fa1c114 | 2007-08-12 17:33:16 +0200 | [diff] [blame] | 2731 | static int |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 2732 | ath5k_reset(struct ath5k_hw *ah, struct ieee80211_channel *chan, |
Nick Kossifidis | 8aec7af | 2010-11-23 21:39:28 +0200 | [diff] [blame] | 2733 | bool skip_pcu) |
Jiri Slaby | fa1c114 | 2007-08-12 17:33:16 +0200 | [diff] [blame] | 2734 | { |
Bruno Randolf | f15a4bb | 2010-12-16 16:22:20 +0900 | [diff] [blame] | 2735 | struct ath_common *common = ath5k_hw_common(ah); |
Nick Kossifidis | 344b54b | 2010-12-03 06:07:13 +0200 | [diff] [blame] | 2736 | int ret, ani_mode; |
Nick Kossifidis | a99168e | 2011-06-02 03:09:48 +0300 | [diff] [blame] | 2737 | bool fast; |
Jiri Slaby | fa1c114 | 2007-08-12 17:33:16 +0200 | [diff] [blame] | 2738 | |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 2739 | ATH5K_DBG(ah, ATH5K_DEBUG_RESET, "resetting\n"); |
Jiri Slaby | fa1c114 | 2007-08-12 17:33:16 +0200 | [diff] [blame] | 2740 | |
Bob Copeland | 450464d | 2010-07-13 11:32:41 -0400 | [diff] [blame] | 2741 | ath5k_hw_set_imr(ah, 0); |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 2742 | synchronize_irq(ah->irq); |
| 2743 | ath5k_stop_tasklets(ah); |
Bob Copeland | 450464d | 2010-07-13 11:32:41 -0400 | [diff] [blame] | 2744 | |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 2745 | /* Save ani mode and disable ANI during |
Nick Kossifidis | 344b54b | 2010-12-03 06:07:13 +0200 | [diff] [blame] | 2746 | * reset. If we don't we might get false |
| 2747 | * PHY error interrupts. */ |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 2748 | ani_mode = ah->ani_state.ani_mode; |
Nick Kossifidis | 344b54b | 2010-12-03 06:07:13 +0200 | [diff] [blame] | 2749 | ath5k_ani_init(ah, ATH5K_ANI_MODE_OFF); |
| 2750 | |
Nick Kossifidis | 19252ec | 2010-12-03 06:05:19 +0200 | [diff] [blame] | 2751 | /* We are going to empty hw queues |
| 2752 | * so we should also free any remaining |
| 2753 | * tx buffers */ |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 2754 | ath5k_drain_tx_buffs(ah); |
Bruno Randolf | 930a762 | 2011-01-19 18:21:13 +0900 | [diff] [blame] | 2755 | if (chan) |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 2756 | ah->curchan = chan; |
Nick Kossifidis | a99168e | 2011-06-02 03:09:48 +0300 | [diff] [blame] | 2757 | |
| 2758 | fast = ((chan != NULL) && modparam_fastchanswitch) ? 1 : 0; |
| 2759 | |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 2760 | ret = ath5k_hw_reset(ah, ah->opmode, ah->curchan, fast, skip_pcu); |
Jiri Slaby | d7dc100 | 2008-07-23 13:17:35 +0200 | [diff] [blame] | 2761 | if (ret) { |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 2762 | ATH5K_ERR(ah, "can't reset hardware (%d)\n", ret); |
Jiri Slaby | fa1c114 | 2007-08-12 17:33:16 +0200 | [diff] [blame] | 2763 | goto err; |
| 2764 | } |
Jiri Slaby | d7dc100 | 2008-07-23 13:17:35 +0200 | [diff] [blame] | 2765 | |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 2766 | ret = ath5k_rx_start(ah); |
Jiri Slaby | d7dc100 | 2008-07-23 13:17:35 +0200 | [diff] [blame] | 2767 | if (ret) { |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 2768 | ATH5K_ERR(ah, "can't start recv logic\n"); |
Jiri Slaby | fa1c114 | 2007-08-12 17:33:16 +0200 | [diff] [blame] | 2769 | goto err; |
| 2770 | } |
Jiri Slaby | d7dc100 | 2008-07-23 13:17:35 +0200 | [diff] [blame] | 2771 | |
Nick Kossifidis | 344b54b | 2010-12-03 06:07:13 +0200 | [diff] [blame] | 2772 | ath5k_ani_init(ah, ani_mode); |
Bruno Randolf | 2111ac0 | 2010-04-02 18:44:08 +0900 | [diff] [blame] | 2773 | |
Nick Kossifidis | ce169ac | 2011-11-25 20:40:23 +0200 | [diff] [blame] | 2774 | /* |
| 2775 | * Set calibration intervals |
| 2776 | * |
| 2777 | * Note: We don't need to run calibration imediately |
| 2778 | * since some initial calibration is done on reset |
| 2779 | * even for fast channel switching. Also on scanning |
| 2780 | * this will get set again and again and it won't get |
| 2781 | * executed unless we connect somewhere and spend some |
| 2782 | * time on the channel (that's what calibration needs |
| 2783 | * anyway to be accurate). |
| 2784 | */ |
| 2785 | ah->ah_cal_next_full = jiffies + |
| 2786 | msecs_to_jiffies(ATH5K_TUNE_CALIBRATION_INTERVAL_FULL); |
| 2787 | ah->ah_cal_next_ani = jiffies + |
| 2788 | msecs_to_jiffies(ATH5K_TUNE_CALIBRATION_INTERVAL_ANI); |
| 2789 | ah->ah_cal_next_short = jiffies + |
| 2790 | msecs_to_jiffies(ATH5K_TUNE_CALIBRATION_INTERVAL_SHORT); |
| 2791 | |
Bruno Randolf | 5dcc03f | 2010-12-02 19:12:31 +0900 | [diff] [blame] | 2792 | ewma_init(&ah->ah_beacon_rssi_avg, 1024, 8); |
Bruno Randolf | afe8628 | 2010-05-19 10:31:10 +0900 | [diff] [blame] | 2793 | |
Bruno Randolf | f15a4bb | 2010-12-16 16:22:20 +0900 | [diff] [blame] | 2794 | /* clear survey data and cycle counters */ |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 2795 | memset(&ah->survey, 0, sizeof(ah->survey)); |
Bob Copeland | bb00755 | 2010-12-26 12:10:05 -0500 | [diff] [blame] | 2796 | spin_lock_bh(&common->cc_lock); |
Bruno Randolf | f15a4bb | 2010-12-16 16:22:20 +0900 | [diff] [blame] | 2797 | ath_hw_cycle_counters_update(common); |
| 2798 | memset(&common->cc_survey, 0, sizeof(common->cc_survey)); |
| 2799 | memset(&common->cc_ani, 0, sizeof(common->cc_ani)); |
Bob Copeland | bb00755 | 2010-12-26 12:10:05 -0500 | [diff] [blame] | 2800 | spin_unlock_bh(&common->cc_lock); |
Bruno Randolf | f15a4bb | 2010-12-16 16:22:20 +0900 | [diff] [blame] | 2801 | |
Jiri Slaby | fa1c114 | 2007-08-12 17:33:16 +0200 | [diff] [blame] | 2802 | /* |
Jiri Slaby | d7dc100 | 2008-07-23 13:17:35 +0200 | [diff] [blame] | 2803 | * Change channels and update the h/w rate map if we're switching; |
| 2804 | * e.g. 11a to 11b/g. |
| 2805 | * |
| 2806 | * We may be doing a reset in response to an ioctl that changes the |
| 2807 | * channel so update any state that might change as a result. |
Jiri Slaby | fa1c114 | 2007-08-12 17:33:16 +0200 | [diff] [blame] | 2808 | * |
| 2809 | * XXX needed? |
| 2810 | */ |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 2811 | /* ath5k_chan_change(ah, c); */ |
Jiri Slaby | fa1c114 | 2007-08-12 17:33:16 +0200 | [diff] [blame] | 2812 | |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 2813 | ath5k_beacon_config(ah); |
Jiri Slaby | d7dc100 | 2008-07-23 13:17:35 +0200 | [diff] [blame] | 2814 | /* intrs are enabled by ath5k_beacon_config */ |
Jiri Slaby | fa1c114 | 2007-08-12 17:33:16 +0200 | [diff] [blame] | 2815 | |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 2816 | ieee80211_wake_queues(ah->hw); |
Bruno Randolf | 397f385 | 2010-05-19 10:30:49 +0900 | [diff] [blame] | 2817 | |
Jiri Slaby | fa1c114 | 2007-08-12 17:33:16 +0200 | [diff] [blame] | 2818 | return 0; |
| 2819 | err: |
| 2820 | return ret; |
| 2821 | } |
| 2822 | |
Bob Copeland | 5faaff7 | 2010-07-13 11:32:40 -0400 | [diff] [blame] | 2823 | static void ath5k_reset_work(struct work_struct *work) |
| 2824 | { |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 2825 | struct ath5k_hw *ah = container_of(work, struct ath5k_hw, |
Bob Copeland | 5faaff7 | 2010-07-13 11:32:40 -0400 | [diff] [blame] | 2826 | reset_work); |
| 2827 | |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 2828 | mutex_lock(&ah->lock); |
| 2829 | ath5k_reset(ah, NULL, true); |
| 2830 | mutex_unlock(&ah->lock); |
Bob Copeland | 5faaff7 | 2010-07-13 11:32:40 -0400 | [diff] [blame] | 2831 | } |
| 2832 | |
Pavel Roskin | 25380d8 | 2011-07-07 18:13:42 -0400 | [diff] [blame] | 2833 | static int __devinit |
Felix Fietkau | 132b1c3 | 2010-12-02 10:26:56 +0100 | [diff] [blame] | 2834 | ath5k_init(struct ieee80211_hw *hw) |
Bob Copeland | 8a63fac | 2010-09-17 12:45:07 +0900 | [diff] [blame] | 2835 | { |
Felix Fietkau | 132b1c3 | 2010-12-02 10:26:56 +0100 | [diff] [blame] | 2836 | |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 2837 | struct ath5k_hw *ah = hw->priv; |
Bob Copeland | 8a63fac | 2010-09-17 12:45:07 +0900 | [diff] [blame] | 2838 | struct ath_regulatory *regulatory = ath5k_hw_regulatory(ah); |
Bruno Randolf | 925e0b0 | 2010-09-17 11:36:35 +0900 | [diff] [blame] | 2839 | struct ath5k_txq *txq; |
Bob Copeland | 8a63fac | 2010-09-17 12:45:07 +0900 | [diff] [blame] | 2840 | u8 mac[ETH_ALEN] = {}; |
| 2841 | int ret; |
| 2842 | |
Bob Copeland | 8a63fac | 2010-09-17 12:45:07 +0900 | [diff] [blame] | 2843 | |
| 2844 | /* |
| 2845 | * Check if the MAC has multi-rate retry support. |
| 2846 | * We do this by trying to setup a fake extended |
| 2847 | * descriptor. MACs that don't have support will |
| 2848 | * return false w/o doing anything. MACs that do |
| 2849 | * support it will return true w/o doing anything. |
| 2850 | */ |
| 2851 | ret = ath5k_hw_setup_mrr_tx_desc(ah, NULL, 0, 0, 0, 0, 0, 0); |
| 2852 | |
| 2853 | if (ret < 0) |
| 2854 | goto err; |
| 2855 | if (ret > 0) |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 2856 | __set_bit(ATH_STAT_MRRETRY, ah->status); |
Bob Copeland | 8a63fac | 2010-09-17 12:45:07 +0900 | [diff] [blame] | 2857 | |
| 2858 | /* |
| 2859 | * Collect the channel list. The 802.11 layer |
Pavel Roskin | 6a2a0e7 | 2011-07-09 00:17:51 -0400 | [diff] [blame] | 2860 | * is responsible for filtering this list based |
Bob Copeland | 8a63fac | 2010-09-17 12:45:07 +0900 | [diff] [blame] | 2861 | * on settings like the phy mode and regulatory |
| 2862 | * domain restrictions. |
| 2863 | */ |
| 2864 | ret = ath5k_setup_bands(hw); |
| 2865 | if (ret) { |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 2866 | ATH5K_ERR(ah, "can't get channels\n"); |
Bob Copeland | 8a63fac | 2010-09-17 12:45:07 +0900 | [diff] [blame] | 2867 | goto err; |
| 2868 | } |
| 2869 | |
Bob Copeland | 8a63fac | 2010-09-17 12:45:07 +0900 | [diff] [blame] | 2870 | /* |
| 2871 | * Allocate tx+rx descriptors and populate the lists. |
| 2872 | */ |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 2873 | ret = ath5k_desc_alloc(ah); |
Bob Copeland | 8a63fac | 2010-09-17 12:45:07 +0900 | [diff] [blame] | 2874 | if (ret) { |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 2875 | ATH5K_ERR(ah, "can't allocate descriptors\n"); |
Bob Copeland | 8a63fac | 2010-09-17 12:45:07 +0900 | [diff] [blame] | 2876 | goto err; |
| 2877 | } |
| 2878 | |
| 2879 | /* |
| 2880 | * Allocate hardware transmit queues: one queue for |
| 2881 | * beacon frames and one data queue for each QoS |
| 2882 | * priority. Note that hw functions handle resetting |
| 2883 | * these queues at the needed time. |
| 2884 | */ |
| 2885 | ret = ath5k_beaconq_setup(ah); |
| 2886 | if (ret < 0) { |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 2887 | ATH5K_ERR(ah, "can't setup a beacon xmit queue\n"); |
Bob Copeland | 8a63fac | 2010-09-17 12:45:07 +0900 | [diff] [blame] | 2888 | goto err_desc; |
| 2889 | } |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 2890 | ah->bhalq = ret; |
| 2891 | ah->cabq = ath5k_txq_setup(ah, AR5K_TX_QUEUE_CAB, 0); |
| 2892 | if (IS_ERR(ah->cabq)) { |
| 2893 | ATH5K_ERR(ah, "can't setup cab queue\n"); |
| 2894 | ret = PTR_ERR(ah->cabq); |
Bob Copeland | 8a63fac | 2010-09-17 12:45:07 +0900 | [diff] [blame] | 2895 | goto err_bhal; |
| 2896 | } |
| 2897 | |
Bruno Randolf | 22d8d9f | 2010-12-07 11:08:12 +0900 | [diff] [blame] | 2898 | /* 5211 and 5212 usually support 10 queues but we better rely on the |
| 2899 | * capability information */ |
| 2900 | if (ah->ah_capabilities.cap_queues.q_tx_num >= 6) { |
| 2901 | /* This order matches mac80211's queue priority, so we can |
| 2902 | * directly use the mac80211 queue number without any mapping */ |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 2903 | txq = ath5k_txq_setup(ah, AR5K_TX_QUEUE_DATA, AR5K_WME_AC_VO); |
Bruno Randolf | 22d8d9f | 2010-12-07 11:08:12 +0900 | [diff] [blame] | 2904 | if (IS_ERR(txq)) { |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 2905 | ATH5K_ERR(ah, "can't setup xmit queue\n"); |
Bruno Randolf | 22d8d9f | 2010-12-07 11:08:12 +0900 | [diff] [blame] | 2906 | ret = PTR_ERR(txq); |
| 2907 | goto err_queues; |
| 2908 | } |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 2909 | txq = ath5k_txq_setup(ah, AR5K_TX_QUEUE_DATA, AR5K_WME_AC_VI); |
Bruno Randolf | 22d8d9f | 2010-12-07 11:08:12 +0900 | [diff] [blame] | 2910 | if (IS_ERR(txq)) { |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 2911 | ATH5K_ERR(ah, "can't setup xmit queue\n"); |
Bruno Randolf | 22d8d9f | 2010-12-07 11:08:12 +0900 | [diff] [blame] | 2912 | ret = PTR_ERR(txq); |
| 2913 | goto err_queues; |
| 2914 | } |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 2915 | txq = ath5k_txq_setup(ah, AR5K_TX_QUEUE_DATA, AR5K_WME_AC_BE); |
Bruno Randolf | 22d8d9f | 2010-12-07 11:08:12 +0900 | [diff] [blame] | 2916 | if (IS_ERR(txq)) { |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 2917 | ATH5K_ERR(ah, "can't setup xmit queue\n"); |
Bruno Randolf | 22d8d9f | 2010-12-07 11:08:12 +0900 | [diff] [blame] | 2918 | ret = PTR_ERR(txq); |
| 2919 | goto err_queues; |
| 2920 | } |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 2921 | txq = ath5k_txq_setup(ah, AR5K_TX_QUEUE_DATA, AR5K_WME_AC_BK); |
Bruno Randolf | 22d8d9f | 2010-12-07 11:08:12 +0900 | [diff] [blame] | 2922 | if (IS_ERR(txq)) { |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 2923 | ATH5K_ERR(ah, "can't setup xmit queue\n"); |
Bruno Randolf | 22d8d9f | 2010-12-07 11:08:12 +0900 | [diff] [blame] | 2924 | ret = PTR_ERR(txq); |
| 2925 | goto err_queues; |
| 2926 | } |
| 2927 | hw->queues = 4; |
| 2928 | } else { |
| 2929 | /* older hardware (5210) can only support one data queue */ |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 2930 | txq = ath5k_txq_setup(ah, AR5K_TX_QUEUE_DATA, AR5K_WME_AC_BE); |
Bruno Randolf | 22d8d9f | 2010-12-07 11:08:12 +0900 | [diff] [blame] | 2931 | if (IS_ERR(txq)) { |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 2932 | ATH5K_ERR(ah, "can't setup xmit queue\n"); |
Bruno Randolf | 22d8d9f | 2010-12-07 11:08:12 +0900 | [diff] [blame] | 2933 | ret = PTR_ERR(txq); |
| 2934 | goto err_queues; |
| 2935 | } |
| 2936 | hw->queues = 1; |
Bob Copeland | 8a63fac | 2010-09-17 12:45:07 +0900 | [diff] [blame] | 2937 | } |
| 2938 | |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 2939 | tasklet_init(&ah->rxtq, ath5k_tasklet_rx, (unsigned long)ah); |
| 2940 | tasklet_init(&ah->txtq, ath5k_tasklet_tx, (unsigned long)ah); |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 2941 | tasklet_init(&ah->beacontq, ath5k_tasklet_beacon, (unsigned long)ah); |
| 2942 | tasklet_init(&ah->ani_tasklet, ath5k_tasklet_ani, (unsigned long)ah); |
Bob Copeland | 8a63fac | 2010-09-17 12:45:07 +0900 | [diff] [blame] | 2943 | |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 2944 | INIT_WORK(&ah->reset_work, ath5k_reset_work); |
Nick Kossifidis | ce169ac | 2011-11-25 20:40:23 +0200 | [diff] [blame] | 2945 | INIT_WORK(&ah->calib_work, ath5k_calibrate_work); |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 2946 | INIT_DELAYED_WORK(&ah->tx_complete_work, ath5k_tx_complete_poll_work); |
Bob Copeland | 8a63fac | 2010-09-17 12:45:07 +0900 | [diff] [blame] | 2947 | |
Felix Fietkau | fa9bfd6 | 2011-04-13 21:56:44 +0200 | [diff] [blame] | 2948 | ret = ath5k_hw_common(ah)->bus_ops->eeprom_read_mac(ah, mac); |
Bob Copeland | 8a63fac | 2010-09-17 12:45:07 +0900 | [diff] [blame] | 2949 | if (ret) { |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 2950 | ATH5K_ERR(ah, "unable to read address from EEPROM\n"); |
Bob Copeland | 8a63fac | 2010-09-17 12:45:07 +0900 | [diff] [blame] | 2951 | goto err_queues; |
| 2952 | } |
| 2953 | |
| 2954 | SET_IEEE80211_PERM_ADDR(hw, mac); |
| 2955 | /* All MAC address bits matter for ACKs */ |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 2956 | ath5k_update_bssid_mask_and_opmode(ah, NULL); |
Bob Copeland | 8a63fac | 2010-09-17 12:45:07 +0900 | [diff] [blame] | 2957 | |
| 2958 | regulatory->current_rd = ah->ah_capabilities.cap_eeprom.ee_regdomain; |
| 2959 | ret = ath_regd_init(regulatory, hw->wiphy, ath5k_reg_notifier); |
| 2960 | if (ret) { |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 2961 | ATH5K_ERR(ah, "can't initialize regulatory system\n"); |
Bob Copeland | 8a63fac | 2010-09-17 12:45:07 +0900 | [diff] [blame] | 2962 | goto err_queues; |
| 2963 | } |
| 2964 | |
| 2965 | ret = ieee80211_register_hw(hw); |
| 2966 | if (ret) { |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 2967 | ATH5K_ERR(ah, "can't register ieee80211 hw\n"); |
Bob Copeland | 8a63fac | 2010-09-17 12:45:07 +0900 | [diff] [blame] | 2968 | goto err_queues; |
| 2969 | } |
| 2970 | |
| 2971 | if (!ath_is_world_regd(regulatory)) |
| 2972 | regulatory_hint(hw->wiphy, regulatory->alpha2); |
| 2973 | |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 2974 | ath5k_init_leds(ah); |
Bob Copeland | 8a63fac | 2010-09-17 12:45:07 +0900 | [diff] [blame] | 2975 | |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 2976 | ath5k_sysfs_register(ah); |
Bob Copeland | 8a63fac | 2010-09-17 12:45:07 +0900 | [diff] [blame] | 2977 | |
| 2978 | return 0; |
| 2979 | err_queues: |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 2980 | ath5k_txq_release(ah); |
Bob Copeland | 8a63fac | 2010-09-17 12:45:07 +0900 | [diff] [blame] | 2981 | err_bhal: |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 2982 | ath5k_hw_release_tx_queue(ah, ah->bhalq); |
Bob Copeland | 8a63fac | 2010-09-17 12:45:07 +0900 | [diff] [blame] | 2983 | err_desc: |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 2984 | ath5k_desc_free(ah); |
Bob Copeland | 8a63fac | 2010-09-17 12:45:07 +0900 | [diff] [blame] | 2985 | err: |
| 2986 | return ret; |
| 2987 | } |
| 2988 | |
Felix Fietkau | 132b1c3 | 2010-12-02 10:26:56 +0100 | [diff] [blame] | 2989 | void |
Pavel Roskin | bb1f3ad | 2011-07-26 22:27:05 -0400 | [diff] [blame] | 2990 | ath5k_deinit_ah(struct ath5k_hw *ah) |
Bob Copeland | 8a63fac | 2010-09-17 12:45:07 +0900 | [diff] [blame] | 2991 | { |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 2992 | struct ieee80211_hw *hw = ah->hw; |
Bob Copeland | 8a63fac | 2010-09-17 12:45:07 +0900 | [diff] [blame] | 2993 | |
| 2994 | /* |
| 2995 | * NB: the order of these is important: |
| 2996 | * o call the 802.11 layer before detaching ath5k_hw to |
| 2997 | * ensure callbacks into the driver to delete global |
| 2998 | * key cache entries can be handled |
| 2999 | * o reclaim the tx queue data structures after calling |
| 3000 | * the 802.11 layer as we'll get called back to reclaim |
| 3001 | * node state and potentially want to use them |
| 3002 | * o to cleanup the tx queues the hal is called, so detach |
| 3003 | * it last |
| 3004 | * XXX: ??? detach ath5k_hw ??? |
| 3005 | * Other than that, it's straightforward... |
| 3006 | */ |
| 3007 | ieee80211_unregister_hw(hw); |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 3008 | ath5k_desc_free(ah); |
| 3009 | ath5k_txq_release(ah); |
| 3010 | ath5k_hw_release_tx_queue(ah, ah->bhalq); |
| 3011 | ath5k_unregister_leds(ah); |
Bob Copeland | 8a63fac | 2010-09-17 12:45:07 +0900 | [diff] [blame] | 3012 | |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 3013 | ath5k_sysfs_unregister(ah); |
Bob Copeland | 8a63fac | 2010-09-17 12:45:07 +0900 | [diff] [blame] | 3014 | /* |
| 3015 | * NB: can't reclaim these until after ieee80211_ifdetach |
| 3016 | * returns because we'll get called back to reclaim node |
| 3017 | * state and potentially want to use them. |
| 3018 | */ |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 3019 | ath5k_hw_deinit(ah); |
| 3020 | free_irq(ah->irq, ah); |
Bob Copeland | 8a63fac | 2010-09-17 12:45:07 +0900 | [diff] [blame] | 3021 | } |
| 3022 | |
Bruno Randolf | cd2c548 | 2010-12-22 19:20:32 +0900 | [diff] [blame] | 3023 | bool |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 3024 | ath5k_any_vif_assoc(struct ath5k_hw *ah) |
Ben Greear | b1ae1ed | 2010-09-30 12:22:58 -0700 | [diff] [blame] | 3025 | { |
Ben Greear | e4b0b32 | 2011-03-03 14:39:05 -0800 | [diff] [blame] | 3026 | struct ath5k_vif_iter_data iter_data; |
Ben Greear | b1ae1ed | 2010-09-30 12:22:58 -0700 | [diff] [blame] | 3027 | iter_data.hw_macaddr = NULL; |
| 3028 | iter_data.any_assoc = false; |
| 3029 | iter_data.need_set_hw_addr = false; |
| 3030 | iter_data.found_active = true; |
| 3031 | |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 3032 | ieee80211_iterate_active_interfaces_atomic(ah->hw, ath5k_vif_iter, |
Ben Greear | b1ae1ed | 2010-09-30 12:22:58 -0700 | [diff] [blame] | 3033 | &iter_data); |
| 3034 | return iter_data.any_assoc; |
| 3035 | } |
| 3036 | |
Bruno Randolf | cd2c548 | 2010-12-22 19:20:32 +0900 | [diff] [blame] | 3037 | void |
Pavel Roskin | f5cbc8b | 2011-06-15 18:03:22 -0400 | [diff] [blame] | 3038 | ath5k_set_beacon_filter(struct ieee80211_hw *hw, bool enable) |
Martin Xu | 02969b3 | 2008-11-24 10:49:27 +0800 | [diff] [blame] | 3039 | { |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 3040 | struct ath5k_hw *ah = hw->priv; |
Martin Xu | 02969b3 | 2008-11-24 10:49:27 +0800 | [diff] [blame] | 3041 | u32 rfilt; |
| 3042 | rfilt = ath5k_hw_get_rx_filter(ah); |
| 3043 | if (enable) |
| 3044 | rfilt |= AR5K_RX_FILTER_BEACON; |
| 3045 | else |
| 3046 | rfilt &= ~AR5K_RX_FILTER_BEACON; |
| 3047 | ath5k_hw_set_rx_filter(ah, rfilt); |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 3048 | ah->filter_flags = rfilt; |
Martin Xu | 02969b3 | 2008-11-24 10:49:27 +0800 | [diff] [blame] | 3049 | } |