blob: a4a09bb8f2f3cb91c9ffd96336b6eab25ce63e41 [file] [log] [blame]
Jiri Slabyfa1c1142007-08-12 17:33:16 +02001/*-
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
Joe Perches516304b2012-03-18 17:30:52 -070043#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
44
Jiri Slabyfa1c1142007-08-12 17:33:16 +020045#include <linux/module.h>
46#include <linux/delay.h>
Alexey Dobriyanb7f080c2011-06-16 11:01:34 +000047#include <linux/dma-mapping.h>
Jiri Slaby274c7c32008-07-15 17:44:20 +020048#include <linux/hardirq.h>
Jiri Slabyfa1c1142007-08-12 17:33:16 +020049#include <linux/if.h>
Jiri Slaby274c7c32008-07-15 17:44:20 +020050#include <linux/io.h>
Jiri Slabyfa1c1142007-08-12 17:33:16 +020051#include <linux/netdevice.h>
52#include <linux/cache.h>
Jiri Slabyfa1c1142007-08-12 17:33:16 +020053#include <linux/ethtool.h>
54#include <linux/uaccess.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090055#include <linux/slab.h>
Ben Greearb1ae1ed2010-09-30 12:22:58 -070056#include <linux/etherdevice.h>
Pavel Roskin931be262011-07-26 22:26:59 -040057#include <linux/nl80211.h>
Jiri Slabyfa1c1142007-08-12 17:33:16 +020058
Simon Wunderlich4d70f2f2013-08-14 08:01:37 +020059#include <net/cfg80211.h>
Jiri Slabyfa1c1142007-08-12 17:33:16 +020060#include <net/ieee80211_radiotap.h>
61
62#include <asm/unaligned.h>
63
Thomas Huehn0967e012013-06-11 15:10:31 +020064#include <net/mac80211.h>
Jiri Slabyfa1c1142007-08-12 17:33:16 +020065#include "base.h"
66#include "reg.h"
67#include "debug.h"
Bruno Randolf2111ac02010-04-02 18:44:08 +090068#include "ani.h"
Pavel Roskin931be262011-07-26 22:26:59 -040069#include "ath5k.h"
70#include "../regd.h"
Jiri Slabyfa1c1142007-08-12 17:33:16 +020071
Bob Copeland0e472252011-01-24 23:32:55 -050072#define CREATE_TRACE_POINTS
73#include "trace.h"
74
Rusty Russelleb939922011-12-19 14:08:01 +000075bool ath5k_modparam_nohwcrypt;
John W. Linville18cb6e32011-01-05 09:39:59 -050076module_param_named(nohwcrypt, ath5k_modparam_nohwcrypt, bool, S_IRUGO);
Bob Copeland9ad9a262008-10-29 08:30:54 -040077MODULE_PARM_DESC(nohwcrypt, "Disable hardware encryption.");
Jiri Slabyfa1c1142007-08-12 17:33:16 +020078
Rusty Russelleb939922011-12-19 14:08:01 +000079static bool modparam_fastchanswitch;
Nick Kossifidisa99168e2011-06-02 03:09:48 +030080module_param_named(fastchanswitch, modparam_fastchanswitch, bool, S_IRUGO);
81MODULE_PARM_DESC(fastchanswitch, "Enable fast channel switching for AR2413/AR5413 radios.");
82
John W. Linville11deb532012-01-24 14:58:47 -050083static bool ath5k_modparam_no_hw_rfkill_switch;
Nick Kossifidis84e1e732011-11-25 20:40:27 +020084module_param_named(no_hw_rfkill_switch, ath5k_modparam_no_hw_rfkill_switch,
85 bool, S_IRUGO);
86MODULE_PARM_DESC(no_hw_rfkill_switch, "Ignore the GPIO RFKill switch state");
87
Nick Kossifidisa99168e2011-06-02 03:09:48 +030088
Jiri Slabyfa1c1142007-08-12 17:33:16 +020089/* Module info */
90MODULE_AUTHOR("Jiri Slaby");
91MODULE_AUTHOR("Nick Kossifidis");
92MODULE_DESCRIPTION("Support for 5xxx series of Atheros 802.11 wireless LAN cards.");
93MODULE_SUPPORTED_DEVICE("Atheros 5xxx WLAN cards");
94MODULE_LICENSE("Dual BSD/GPL");
Jiri Slabyfa1c1142007-08-12 17:33:16 +020095
Felix Fietkau132b1c32010-12-02 10:26:56 +010096static int ath5k_init(struct ieee80211_hw *hw);
Pavel Roskine0d687b2011-07-14 20:21:55 -040097static int ath5k_reset(struct ath5k_hw *ah, struct ieee80211_channel *chan,
Nick Kossifidis8aec7af2010-11-23 21:39:28 +020098 bool skip_pcu);
Jiri Slabyfa1c1142007-08-12 17:33:16 +020099
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200100/* Known SREVs */
Jiri Slaby2c91108c2009-03-07 10:26:41 +0100101static const struct ath5k_srev_name srev_names[] = {
Nick Kossifidis1bef0162008-09-29 02:09:09 +0300102 { "5210", AR5K_VERSION_MAC, AR5K_SREV_AR5210 },
103 { "5311", AR5K_VERSION_MAC, AR5K_SREV_AR5311 },
104 { "5311A", AR5K_VERSION_MAC, AR5K_SREV_AR5311A },
105 { "5311B", AR5K_VERSION_MAC, AR5K_SREV_AR5311B },
106 { "5211", AR5K_VERSION_MAC, AR5K_SREV_AR5211 },
107 { "5212", AR5K_VERSION_MAC, AR5K_SREV_AR5212 },
108 { "5213", AR5K_VERSION_MAC, AR5K_SREV_AR5213 },
109 { "5213A", AR5K_VERSION_MAC, AR5K_SREV_AR5213A },
110 { "2413", AR5K_VERSION_MAC, AR5K_SREV_AR2413 },
111 { "2414", AR5K_VERSION_MAC, AR5K_SREV_AR2414 },
112 { "5424", AR5K_VERSION_MAC, AR5K_SREV_AR5424 },
113 { "5413", AR5K_VERSION_MAC, AR5K_SREV_AR5413 },
114 { "5414", AR5K_VERSION_MAC, AR5K_SREV_AR5414 },
115 { "2415", AR5K_VERSION_MAC, AR5K_SREV_AR2415 },
116 { "5416", AR5K_VERSION_MAC, AR5K_SREV_AR5416 },
117 { "5418", AR5K_VERSION_MAC, AR5K_SREV_AR5418 },
118 { "2425", AR5K_VERSION_MAC, AR5K_SREV_AR2425 },
119 { "2417", AR5K_VERSION_MAC, AR5K_SREV_AR2417 },
120 { "xxxxx", AR5K_VERSION_MAC, AR5K_SREV_UNKNOWN },
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200121 { "5110", AR5K_VERSION_RAD, AR5K_SREV_RAD_5110 },
122 { "5111", AR5K_VERSION_RAD, AR5K_SREV_RAD_5111 },
Nick Kossifidis1bef0162008-09-29 02:09:09 +0300123 { "5111A", AR5K_VERSION_RAD, AR5K_SREV_RAD_5111A },
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200124 { "2111", AR5K_VERSION_RAD, AR5K_SREV_RAD_2111 },
125 { "5112", AR5K_VERSION_RAD, AR5K_SREV_RAD_5112 },
126 { "5112A", AR5K_VERSION_RAD, AR5K_SREV_RAD_5112A },
Nick Kossifidis1bef0162008-09-29 02:09:09 +0300127 { "5112B", AR5K_VERSION_RAD, AR5K_SREV_RAD_5112B },
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200128 { "2112", AR5K_VERSION_RAD, AR5K_SREV_RAD_2112 },
129 { "2112A", AR5K_VERSION_RAD, AR5K_SREV_RAD_2112A },
Nick Kossifidis1bef0162008-09-29 02:09:09 +0300130 { "2112B", AR5K_VERSION_RAD, AR5K_SREV_RAD_2112B },
131 { "2413", AR5K_VERSION_RAD, AR5K_SREV_RAD_2413 },
132 { "5413", AR5K_VERSION_RAD, AR5K_SREV_RAD_5413 },
Nick Kossifidis1bef0162008-09-29 02:09:09 +0300133 { "5424", AR5K_VERSION_RAD, AR5K_SREV_RAD_5424 },
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200134 { "5133", AR5K_VERSION_RAD, AR5K_SREV_RAD_5133 },
135 { "xxxxx", AR5K_VERSION_RAD, AR5K_SREV_UNKNOWN },
136};
137
Jiri Slaby2c91108c2009-03-07 10:26:41 +0100138static const struct ieee80211_rate ath5k_rates[] = {
Bruno Randolf63266a62008-07-30 17:12:58 +0200139 { .bitrate = 10,
140 .hw_value = ATH5K_RATE_CODE_1M, },
141 { .bitrate = 20,
142 .hw_value = ATH5K_RATE_CODE_2M,
143 .hw_value_short = ATH5K_RATE_CODE_2M | AR5K_SET_SHORT_PREAMBLE,
144 .flags = IEEE80211_RATE_SHORT_PREAMBLE },
145 { .bitrate = 55,
146 .hw_value = ATH5K_RATE_CODE_5_5M,
147 .hw_value_short = ATH5K_RATE_CODE_5_5M | AR5K_SET_SHORT_PREAMBLE,
148 .flags = IEEE80211_RATE_SHORT_PREAMBLE },
149 { .bitrate = 110,
150 .hw_value = ATH5K_RATE_CODE_11M,
151 .hw_value_short = ATH5K_RATE_CODE_11M | AR5K_SET_SHORT_PREAMBLE,
152 .flags = IEEE80211_RATE_SHORT_PREAMBLE },
153 { .bitrate = 60,
154 .hw_value = ATH5K_RATE_CODE_6M,
Simon Wunderlich6a09ae92013-08-14 08:01:36 +0200155 .flags = IEEE80211_RATE_SUPPORTS_5MHZ |
156 IEEE80211_RATE_SUPPORTS_10MHZ },
Bruno Randolf63266a62008-07-30 17:12:58 +0200157 { .bitrate = 90,
158 .hw_value = ATH5K_RATE_CODE_9M,
Simon Wunderlich6a09ae92013-08-14 08:01:36 +0200159 .flags = IEEE80211_RATE_SUPPORTS_5MHZ |
160 IEEE80211_RATE_SUPPORTS_10MHZ },
Bruno Randolf63266a62008-07-30 17:12:58 +0200161 { .bitrate = 120,
162 .hw_value = ATH5K_RATE_CODE_12M,
Simon Wunderlich6a09ae92013-08-14 08:01:36 +0200163 .flags = IEEE80211_RATE_SUPPORTS_5MHZ |
164 IEEE80211_RATE_SUPPORTS_10MHZ },
Bruno Randolf63266a62008-07-30 17:12:58 +0200165 { .bitrate = 180,
166 .hw_value = ATH5K_RATE_CODE_18M,
Simon Wunderlich6a09ae92013-08-14 08:01:36 +0200167 .flags = IEEE80211_RATE_SUPPORTS_5MHZ |
168 IEEE80211_RATE_SUPPORTS_10MHZ },
Bruno Randolf63266a62008-07-30 17:12:58 +0200169 { .bitrate = 240,
170 .hw_value = ATH5K_RATE_CODE_24M,
Simon Wunderlich6a09ae92013-08-14 08:01:36 +0200171 .flags = IEEE80211_RATE_SUPPORTS_5MHZ |
172 IEEE80211_RATE_SUPPORTS_10MHZ },
Bruno Randolf63266a62008-07-30 17:12:58 +0200173 { .bitrate = 360,
174 .hw_value = ATH5K_RATE_CODE_36M,
Simon Wunderlich6a09ae92013-08-14 08:01:36 +0200175 .flags = IEEE80211_RATE_SUPPORTS_5MHZ |
176 IEEE80211_RATE_SUPPORTS_10MHZ },
Bruno Randolf63266a62008-07-30 17:12:58 +0200177 { .bitrate = 480,
178 .hw_value = ATH5K_RATE_CODE_48M,
Simon Wunderlich6a09ae92013-08-14 08:01:36 +0200179 .flags = IEEE80211_RATE_SUPPORTS_5MHZ |
180 IEEE80211_RATE_SUPPORTS_10MHZ },
Bruno Randolf63266a62008-07-30 17:12:58 +0200181 { .bitrate = 540,
182 .hw_value = ATH5K_RATE_CODE_54M,
Simon Wunderlich6a09ae92013-08-14 08:01:36 +0200183 .flags = IEEE80211_RATE_SUPPORTS_5MHZ |
184 IEEE80211_RATE_SUPPORTS_10MHZ },
Bruno Randolf63266a62008-07-30 17:12:58 +0200185};
186
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200187static inline u64 ath5k_extend_tsf(struct ath5k_hw *ah, u32 rstamp)
188{
189 u64 tsf = ath5k_hw_get_tsf64(ah);
190
191 if ((tsf & 0x7fff) < rstamp)
192 tsf -= 0x8000;
193
194 return (tsf & ~0x7fff) | rstamp;
195}
196
Felix Fietkaue5b046d2010-12-02 10:27:01 +0100197const char *
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200198ath5k_chip_name(enum ath5k_srev_type type, u_int16_t val)
199{
200 const char *name = "xxxxx";
201 unsigned int i;
202
203 for (i = 0; i < ARRAY_SIZE(srev_names); i++) {
204 if (srev_names[i].sr_type != type)
205 continue;
Nick Kossifidis75d0edb2008-09-29 01:24:44 +0300206
207 if ((val & 0xf0) == srev_names[i].sr_val)
208 name = srev_names[i].sr_name;
209
210 if ((val & 0xff) == srev_names[i].sr_val) {
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200211 name = srev_names[i].sr_name;
212 break;
213 }
214 }
215
216 return name;
217}
Luis R. Rodrigueze5aa8472009-09-10 16:55:11 -0700218static unsigned int ath5k_ioread32(void *hw_priv, u32 reg_offset)
219{
220 struct ath5k_hw *ah = (struct ath5k_hw *) hw_priv;
221 return ath5k_hw_reg_read(ah, reg_offset);
222}
223
224static void ath5k_iowrite32(void *hw_priv, u32 val, u32 reg_offset)
225{
226 struct ath5k_hw *ah = (struct ath5k_hw *) hw_priv;
227 ath5k_hw_reg_write(ah, val, reg_offset);
228}
229
230static const struct ath_ops ath5k_common_ops = {
231 .read = ath5k_ioread32,
232 .write = ath5k_iowrite32,
233};
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200234
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200235/***********************\
236* Driver Initialization *
237\***********************/
238
Luis R. Rodriguez0c0280b2013-01-11 18:39:36 +0000239static void ath5k_reg_notifier(struct wiphy *wiphy,
240 struct regulatory_request *request)
Bob Copelandf769c362009-03-30 22:30:31 -0400241{
242 struct ieee80211_hw *hw = wiphy_to_ieee80211_hw(wiphy);
Pavel Roskine0d687b2011-07-14 20:21:55 -0400243 struct ath5k_hw *ah = hw->priv;
244 struct ath_regulatory *regulatory = ath5k_hw_regulatory(ah);
Bob Copelandf769c362009-03-30 22:30:31 -0400245
Luis R. Rodriguez0c0280b2013-01-11 18:39:36 +0000246 ath_reg_notifier_apply(wiphy, request, regulatory);
Bob Copelandf769c362009-03-30 22:30:31 -0400247}
248
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200249/********************\
250* Channel/mode setup *
251\********************/
252
253/*
Luis R. Rodriguez2f8684c2012-07-06 15:21:51 -0700254 * Returns true for the channel numbers used.
Bob Copeland42639fc2009-03-30 08:05:29 -0400255 */
Luis R. Rodriguez2f8684c2012-07-06 15:21:51 -0700256#ifdef CONFIG_ATH5K_TEST_CHANNELS
257static bool ath5k_is_standard_channel(short chan, enum ieee80211_band band)
258{
259 return true;
260}
261
262#else
Bruno Randolf410e6122011-01-19 18:20:57 +0900263static bool ath5k_is_standard_channel(short chan, enum ieee80211_band band)
Bob Copeland42639fc2009-03-30 08:05:29 -0400264{
Bruno Randolf410e6122011-01-19 18:20:57 +0900265 if (band == IEEE80211_BAND_2GHZ && chan <= 14)
266 return true;
267
268 return /* UNII 1,2 */
269 (((chan & 3) == 0 && chan >= 36 && chan <= 64) ||
Bob Copeland42639fc2009-03-30 08:05:29 -0400270 /* midband */
271 ((chan & 3) == 0 && chan >= 100 && chan <= 140) ||
272 /* UNII-3 */
Bruno Randolf410e6122011-01-19 18:20:57 +0900273 ((chan & 3) == 1 && chan >= 149 && chan <= 165) ||
274 /* 802.11j 5.030-5.080 GHz (20MHz) */
275 (chan == 8 || chan == 12 || chan == 16) ||
276 /* 802.11j 4.9GHz (20MHz) */
277 (chan == 184 || chan == 188 || chan == 192 || chan == 196));
Bob Copeland42639fc2009-03-30 08:05:29 -0400278}
Luis R. Rodriguez2f8684c2012-07-06 15:21:51 -0700279#endif
Bob Copeland42639fc2009-03-30 08:05:29 -0400280
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200281static unsigned int
Bruno Randolf97d9c3a2011-01-19 18:20:52 +0900282ath5k_setup_channels(struct ath5k_hw *ah, struct ieee80211_channel *channels,
283 unsigned int mode, unsigned int max)
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200284{
Pavel Roskin32c25462011-07-23 09:29:09 -0400285 unsigned int count, size, freq, ch;
Bruno Randolf90c02d72011-01-19 18:20:36 +0900286 enum ieee80211_band band;
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200287
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200288 switch (mode) {
Luis R. Rodriguezd8ee3982008-02-03 21:51:04 -0500289 case AR5K_MODE_11A:
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200290 /* 1..220, but 2GHz frequencies are filtered by check_channel */
Bruno Randolf97d9c3a2011-01-19 18:20:52 +0900291 size = 220;
Bruno Randolf90c02d72011-01-19 18:20:36 +0900292 band = IEEE80211_BAND_5GHZ;
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200293 break;
Luis R. Rodriguezd8ee3982008-02-03 21:51:04 -0500294 case AR5K_MODE_11B:
295 case AR5K_MODE_11G:
Luis R. Rodriguezd8ee3982008-02-03 21:51:04 -0500296 size = 26;
Bruno Randolf90c02d72011-01-19 18:20:36 +0900297 band = IEEE80211_BAND_2GHZ;
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200298 break;
299 default:
Pavel Roskine0d687b2011-07-14 20:21:55 -0400300 ATH5K_WARN(ah, "bad mode, not copying channels\n");
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200301 return 0;
302 }
303
Bruno Randolf2b1351a2011-01-21 12:19:52 +0900304 count = 0;
305 for (ch = 1; ch <= size && count < max; ch++) {
Bruno Randolf90c02d72011-01-19 18:20:36 +0900306 freq = ieee80211_channel_to_frequency(ch, band);
307
308 if (freq == 0) /* mapping failed - not a standard channel */
309 continue;
Luis R. Rodriguezd8ee3982008-02-03 21:51:04 -0500310
Pavel Roskin32c25462011-07-23 09:29:09 -0400311 /* Write channel info, needed for ath5k_channel_ok() */
312 channels[count].center_freq = freq;
313 channels[count].band = band;
314 channels[count].hw_value = mode;
315
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200316 /* Check if channel is supported by the chipset */
Pavel Roskin32c25462011-07-23 09:29:09 -0400317 if (!ath5k_channel_ok(ah, &channels[count]))
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200318 continue;
319
Luis R. Rodriguez2f8684c2012-07-06 15:21:51 -0700320 if (!ath5k_is_standard_channel(ch, band))
Bob Copeland42639fc2009-03-30 08:05:29 -0400321 continue;
322
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200323 count++;
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200324 }
325
326 return count;
327}
328
Bruno Randolf63266a62008-07-30 17:12:58 +0200329static void
Pavel Roskine0d687b2011-07-14 20:21:55 -0400330ath5k_setup_rate_idx(struct ath5k_hw *ah, struct ieee80211_supported_band *b)
Bruno Randolf63266a62008-07-30 17:12:58 +0200331{
332 u8 i;
333
334 for (i = 0; i < AR5K_MAX_RATES; i++)
Pavel Roskine0d687b2011-07-14 20:21:55 -0400335 ah->rate_idx[b->band][i] = -1;
Bruno Randolf63266a62008-07-30 17:12:58 +0200336
337 for (i = 0; i < b->n_bitrates; i++) {
Pavel Roskine0d687b2011-07-14 20:21:55 -0400338 ah->rate_idx[b->band][b->bitrates[i].hw_value] = i;
Bruno Randolf63266a62008-07-30 17:12:58 +0200339 if (b->bitrates[i].hw_value_short)
Pavel Roskine0d687b2011-07-14 20:21:55 -0400340 ah->rate_idx[b->band][b->bitrates[i].hw_value_short] = i;
Bruno Randolf63266a62008-07-30 17:12:58 +0200341 }
342}
343
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200344static int
Bruno Randolf63266a62008-07-30 17:12:58 +0200345ath5k_setup_bands(struct ieee80211_hw *hw)
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200346{
Pavel Roskine0d687b2011-07-14 20:21:55 -0400347 struct ath5k_hw *ah = hw->priv;
Bruno Randolf63266a62008-07-30 17:12:58 +0200348 struct ieee80211_supported_band *sband;
349 int max_c, count_c = 0;
350 int i;
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200351
Pavel Roskine0d687b2011-07-14 20:21:55 -0400352 BUILD_BUG_ON(ARRAY_SIZE(ah->sbands) < IEEE80211_NUM_BANDS);
353 max_c = ARRAY_SIZE(ah->channels);
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200354
Luis R. Rodriguezd8ee3982008-02-03 21:51:04 -0500355 /* 2GHz band */
Pavel Roskine0d687b2011-07-14 20:21:55 -0400356 sband = &ah->sbands[IEEE80211_BAND_2GHZ];
Bruno Randolf63266a62008-07-30 17:12:58 +0200357 sband->band = IEEE80211_BAND_2GHZ;
Pavel Roskine0d687b2011-07-14 20:21:55 -0400358 sband->bitrates = &ah->rates[IEEE80211_BAND_2GHZ][0];
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200359
Pavel Roskine0d687b2011-07-14 20:21:55 -0400360 if (test_bit(AR5K_MODE_11G, ah->ah_capabilities.cap_mode)) {
Bruno Randolf63266a62008-07-30 17:12:58 +0200361 /* G mode */
362 memcpy(sband->bitrates, &ath5k_rates[0],
363 sizeof(struct ieee80211_rate) * 12);
364 sband->n_bitrates = 12;
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200365
Pavel Roskine0d687b2011-07-14 20:21:55 -0400366 sband->channels = ah->channels;
Bruno Randolf08105692011-01-19 18:20:47 +0900367 sband->n_channels = ath5k_setup_channels(ah, sband->channels,
Bruno Randolf63266a62008-07-30 17:12:58 +0200368 AR5K_MODE_11G, max_c);
Luis R. Rodriguezd8ee3982008-02-03 21:51:04 -0500369
370 hw->wiphy->bands[IEEE80211_BAND_2GHZ] = sband;
Bruno Randolf63266a62008-07-30 17:12:58 +0200371 count_c = sband->n_channels;
Luis R. Rodriguezd8ee3982008-02-03 21:51:04 -0500372 max_c -= count_c;
Pavel Roskine0d687b2011-07-14 20:21:55 -0400373 } else if (test_bit(AR5K_MODE_11B, ah->ah_capabilities.cap_mode)) {
Bruno Randolf63266a62008-07-30 17:12:58 +0200374 /* B mode */
375 memcpy(sband->bitrates, &ath5k_rates[0],
376 sizeof(struct ieee80211_rate) * 4);
377 sband->n_bitrates = 4;
Luis R. Rodriguezd8ee3982008-02-03 21:51:04 -0500378
Bruno Randolf63266a62008-07-30 17:12:58 +0200379 /* 5211 only supports B rates and uses 4bit rate codes
380 * (e.g normally we have 0x1B for 1M, but on 5211 we have 0x0B)
381 * fix them up here:
382 */
383 if (ah->ah_version == AR5K_AR5211) {
384 for (i = 0; i < 4; i++) {
385 sband->bitrates[i].hw_value =
386 sband->bitrates[i].hw_value & 0xF;
387 sband->bitrates[i].hw_value_short =
388 sband->bitrates[i].hw_value_short & 0xF;
389 }
390 }
391
Pavel Roskine0d687b2011-07-14 20:21:55 -0400392 sband->channels = ah->channels;
Bruno Randolf08105692011-01-19 18:20:47 +0900393 sband->n_channels = ath5k_setup_channels(ah, sband->channels,
Bruno Randolf63266a62008-07-30 17:12:58 +0200394 AR5K_MODE_11B, max_c);
395
396 hw->wiphy->bands[IEEE80211_BAND_2GHZ] = sband;
397 count_c = sband->n_channels;
398 max_c -= count_c;
Luis R. Rodriguezd8ee3982008-02-03 21:51:04 -0500399 }
Pavel Roskine0d687b2011-07-14 20:21:55 -0400400 ath5k_setup_rate_idx(ah, sband);
Luis R. Rodriguezd8ee3982008-02-03 21:51:04 -0500401
Bruno Randolf63266a62008-07-30 17:12:58 +0200402 /* 5GHz band, A mode */
Pavel Roskine0d687b2011-07-14 20:21:55 -0400403 if (test_bit(AR5K_MODE_11A, ah->ah_capabilities.cap_mode)) {
404 sband = &ah->sbands[IEEE80211_BAND_5GHZ];
Luis R. Rodriguezd8ee3982008-02-03 21:51:04 -0500405 sband->band = IEEE80211_BAND_5GHZ;
Pavel Roskine0d687b2011-07-14 20:21:55 -0400406 sband->bitrates = &ah->rates[IEEE80211_BAND_5GHZ][0];
Bruno Randolf63266a62008-07-30 17:12:58 +0200407
408 memcpy(sband->bitrates, &ath5k_rates[4],
409 sizeof(struct ieee80211_rate) * 8);
410 sband->n_bitrates = 8;
411
Pavel Roskine0d687b2011-07-14 20:21:55 -0400412 sband->channels = &ah->channels[count_c];
Bruno Randolf08105692011-01-19 18:20:47 +0900413 sband->n_channels = ath5k_setup_channels(ah, sband->channels,
Luis R. Rodriguezd8ee3982008-02-03 21:51:04 -0500414 AR5K_MODE_11A, max_c);
415
Luis R. Rodriguezd8ee3982008-02-03 21:51:04 -0500416 hw->wiphy->bands[IEEE80211_BAND_5GHZ] = sband;
417 }
Pavel Roskine0d687b2011-07-14 20:21:55 -0400418 ath5k_setup_rate_idx(ah, sband);
Luis R. Rodriguezd8ee3982008-02-03 21:51:04 -0500419
Pavel Roskine0d687b2011-07-14 20:21:55 -0400420 ath5k_debug_dump_bands(ah);
Luis R. Rodriguezd8ee3982008-02-03 21:51:04 -0500421
422 return 0;
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200423}
424
425/*
Joerg Alberte30eb4a2009-08-05 01:52:07 +0200426 * Set/change channels. We always reset the chip.
427 * To accomplish this we must first cleanup any pending DMA,
428 * then restart stuff after a la ath5k_init.
Bob Copelandbe009372009-01-22 08:44:16 -0500429 *
Pavel Roskine0d687b2011-07-14 20:21:55 -0400430 * Called with ah->lock.
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200431 */
Bruno Randolfcd2c5482010-12-22 19:20:32 +0900432int
Simon Wunderlich4d70f2f2013-08-14 08:01:37 +0200433ath5k_chan_set(struct ath5k_hw *ah, struct cfg80211_chan_def *chandef)
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200434{
Pavel Roskine0d687b2011-07-14 20:21:55 -0400435 ATH5K_DBG(ah, ATH5K_DEBUG_RESET,
Bruno Randolf8d67a032010-06-16 19:11:12 +0900436 "channel set, resetting (%u -> %u MHz)\n",
Simon Wunderlich4d70f2f2013-08-14 08:01:37 +0200437 ah->curchan->center_freq, chandef->chan->center_freq);
438
439 switch (chandef->width) {
440 case NL80211_CHAN_WIDTH_20:
441 case NL80211_CHAN_WIDTH_20_NOHT:
442 ah->ah_bwmode = AR5K_BWMODE_DEFAULT;
443 break;
444 case NL80211_CHAN_WIDTH_5:
445 ah->ah_bwmode = AR5K_BWMODE_5MHZ;
446 break;
447 case NL80211_CHAN_WIDTH_10:
448 ah->ah_bwmode = AR5K_BWMODE_10MHZ;
449 break;
450 default:
451 WARN_ON(1);
452 return -EINVAL;
453 }
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200454
Joerg Alberte30eb4a2009-08-05 01:52:07 +0200455 /*
456 * To switch channels clear any pending DMA operations;
457 * wait long enough for the RX fifo to drain, reset the
458 * hardware at the new frequency, and then re-enable
459 * the relevant bits of the h/w.
460 */
Simon Wunderlich4d70f2f2013-08-14 08:01:37 +0200461 return ath5k_reset(ah, chandef->chan, true);
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200462}
463
Ben Greeare4b0b322011-03-03 14:39:05 -0800464void ath5k_vif_iter(void *data, u8 *mac, struct ieee80211_vif *vif)
Ben Greearb1ae1ed2010-09-30 12:22:58 -0700465{
Ben Greeare4b0b322011-03-03 14:39:05 -0800466 struct ath5k_vif_iter_data *iter_data = data;
Ben Greearb1ae1ed2010-09-30 12:22:58 -0700467 int i;
Ben Greear62c58fb2010-10-08 12:01:15 -0700468 struct ath5k_vif *avf = (void *)vif->drv_priv;
Ben Greearb1ae1ed2010-09-30 12:22:58 -0700469
470 if (iter_data->hw_macaddr)
471 for (i = 0; i < ETH_ALEN; i++)
472 iter_data->mask[i] &=
473 ~(iter_data->hw_macaddr[i] ^ mac[i]);
474
475 if (!iter_data->found_active) {
476 iter_data->found_active = true;
477 memcpy(iter_data->active_mac, mac, ETH_ALEN);
478 }
479
480 if (iter_data->need_set_hw_addr && iter_data->hw_macaddr)
Joe Perches2e42e472012-05-09 17:17:46 +0000481 if (ether_addr_equal(iter_data->hw_macaddr, mac))
Ben Greearb1ae1ed2010-09-30 12:22:58 -0700482 iter_data->need_set_hw_addr = false;
483
484 if (!iter_data->any_assoc) {
Ben Greearb1ae1ed2010-09-30 12:22:58 -0700485 if (avf->assoc)
486 iter_data->any_assoc = true;
487 }
Ben Greear62c58fb2010-10-08 12:01:15 -0700488
489 /* Calculate combined mode - when APs are active, operate in AP mode.
490 * Otherwise use the mode of the new interface. This can currently
491 * only deal with combinations of APs and STAs. Only one ad-hoc
Ben Greear7afbb2f2010-11-10 11:43:51 -0800492 * interfaces is allowed.
Ben Greear62c58fb2010-10-08 12:01:15 -0700493 */
494 if (avf->opmode == NL80211_IFTYPE_AP)
495 iter_data->opmode = NL80211_IFTYPE_AP;
Ben Greeare4b0b322011-03-03 14:39:05 -0800496 else {
497 if (avf->opmode == NL80211_IFTYPE_STATION)
498 iter_data->n_stas++;
Ben Greear62c58fb2010-10-08 12:01:15 -0700499 if (iter_data->opmode == NL80211_IFTYPE_UNSPECIFIED)
500 iter_data->opmode = avf->opmode;
Ben Greeare4b0b322011-03-03 14:39:05 -0800501 }
Ben Greearb1ae1ed2010-09-30 12:22:58 -0700502}
503
Bruno Randolfcd2c5482010-12-22 19:20:32 +0900504void
Pavel Roskine0d687b2011-07-14 20:21:55 -0400505ath5k_update_bssid_mask_and_opmode(struct ath5k_hw *ah,
Bruno Randolfcd2c5482010-12-22 19:20:32 +0900506 struct ieee80211_vif *vif)
Ben Greearb1ae1ed2010-09-30 12:22:58 -0700507{
Pavel Roskine0d687b2011-07-14 20:21:55 -0400508 struct ath_common *common = ath5k_hw_common(ah);
Ben Greeare4b0b322011-03-03 14:39:05 -0800509 struct ath5k_vif_iter_data iter_data;
510 u32 rfilt;
Ben Greearb1ae1ed2010-09-30 12:22:58 -0700511
512 /*
513 * Use the hardware MAC address as reference, the hardware uses it
514 * together with the BSSID mask when matching addresses.
515 */
516 iter_data.hw_macaddr = common->macaddr;
517 memset(&iter_data.mask, 0xff, ETH_ALEN);
518 iter_data.found_active = false;
519 iter_data.need_set_hw_addr = true;
Ben Greear62c58fb2010-10-08 12:01:15 -0700520 iter_data.opmode = NL80211_IFTYPE_UNSPECIFIED;
Ben Greeare4b0b322011-03-03 14:39:05 -0800521 iter_data.n_stas = 0;
Ben Greearb1ae1ed2010-09-30 12:22:58 -0700522
523 if (vif)
Ben Greeare4b0b322011-03-03 14:39:05 -0800524 ath5k_vif_iter(&iter_data, vif->addr, vif);
Ben Greearb1ae1ed2010-09-30 12:22:58 -0700525
526 /* Get list of all active MAC addresses */
Johannes Berg8b2c9822012-11-06 20:23:30 +0100527 ieee80211_iterate_active_interfaces_atomic(
528 ah->hw, IEEE80211_IFACE_ITER_RESUME_ALL,
529 ath5k_vif_iter, &iter_data);
Pavel Roskine0d687b2011-07-14 20:21:55 -0400530 memcpy(ah->bssidmask, iter_data.mask, ETH_ALEN);
Ben Greearb1ae1ed2010-09-30 12:22:58 -0700531
Pavel Roskine0d687b2011-07-14 20:21:55 -0400532 ah->opmode = iter_data.opmode;
533 if (ah->opmode == NL80211_IFTYPE_UNSPECIFIED)
Ben Greear62c58fb2010-10-08 12:01:15 -0700534 /* Nothing active, default to station mode */
Pavel Roskine0d687b2011-07-14 20:21:55 -0400535 ah->opmode = NL80211_IFTYPE_STATION;
Ben Greear62c58fb2010-10-08 12:01:15 -0700536
Pavel Roskine0d687b2011-07-14 20:21:55 -0400537 ath5k_hw_set_opmode(ah, ah->opmode);
538 ATH5K_DBG(ah, ATH5K_DEBUG_MODE, "mode setup opmode %d (%s)\n",
539 ah->opmode, ath_opmode_to_string(ah->opmode));
Ben Greear62c58fb2010-10-08 12:01:15 -0700540
Ben Greearb1ae1ed2010-09-30 12:22:58 -0700541 if (iter_data.need_set_hw_addr && iter_data.found_active)
Pavel Roskine0d687b2011-07-14 20:21:55 -0400542 ath5k_hw_set_lladdr(ah, iter_data.active_mac);
Ben Greearb1ae1ed2010-09-30 12:22:58 -0700543
Pavel Roskine0d687b2011-07-14 20:21:55 -0400544 if (ath5k_hw_hasbssidmask(ah))
545 ath5k_hw_set_bssid_mask(ah, ah->bssidmask);
Ben Greearb1ae1ed2010-09-30 12:22:58 -0700546
Ben Greeare4b0b322011-03-03 14:39:05 -0800547 /* Set up RX Filter */
548 if (iter_data.n_stas > 1) {
549 /* If you have multiple STA interfaces connected to
550 * different APs, ARPs are not received (most of the time?)
Pavel Roskin6a2a0e72011-07-09 00:17:51 -0400551 * Enabling PROMISC appears to fix that problem.
Ben Greeare4b0b322011-03-03 14:39:05 -0800552 */
Pavel Roskine0d687b2011-07-14 20:21:55 -0400553 ah->filter_flags |= AR5K_RX_FILTER_PROM;
Ben Greeare4b0b322011-03-03 14:39:05 -0800554 }
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200555
Pavel Roskine0d687b2011-07-14 20:21:55 -0400556 rfilt = ah->filter_flags;
557 ath5k_hw_set_rx_filter(ah, rfilt);
558 ATH5K_DBG(ah, ATH5K_DEBUG_MODE, "RX filter 0x%x\n", rfilt);
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200559}
560
Luis R. Rodriguezd8ee3982008-02-03 21:51:04 -0500561static inline int
Pavel Roskine0d687b2011-07-14 20:21:55 -0400562ath5k_hw_to_driver_rix(struct ath5k_hw *ah, int hw_rix)
Bruno Randolf63266a62008-07-30 17:12:58 +0200563{
Bob Copelandb7266042009-03-02 21:55:18 -0500564 int rix;
565
566 /* return base rate on errors */
567 if (WARN(hw_rix < 0 || hw_rix >= AR5K_MAX_RATES,
568 "hw_rix out of bounds: %x\n", hw_rix))
569 return 0;
570
Pavel Roskine0d687b2011-07-14 20:21:55 -0400571 rix = ah->rate_idx[ah->curchan->band][hw_rix];
Bob Copelandb7266042009-03-02 21:55:18 -0500572 if (WARN(rix < 0, "invalid hw_rix: %x\n", hw_rix))
573 rix = 0;
574
575 return rix;
Luis R. Rodriguezd8ee3982008-02-03 21:51:04 -0500576}
577
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200578/***************\
579* Buffers setup *
580\***************/
581
Bob Copelandb6ea0352009-01-10 14:42:54 -0500582static
Pavel Roskine0d687b2011-07-14 20:21:55 -0400583struct sk_buff *ath5k_rx_skb_alloc(struct ath5k_hw *ah, dma_addr_t *skb_addr)
Bob Copelandb6ea0352009-01-10 14:42:54 -0500584{
Pavel Roskine0d687b2011-07-14 20:21:55 -0400585 struct ath_common *common = ath5k_hw_common(ah);
Bob Copelandb6ea0352009-01-10 14:42:54 -0500586 struct sk_buff *skb;
Bob Copelandb6ea0352009-01-10 14:42:54 -0500587
588 /*
589 * Allocate buffer with headroom_needed space for the
590 * fake physical layer header at the start.
591 */
Luis R. Rodriguezdb719712009-09-10 11:20:57 -0700592 skb = ath_rxbuf_alloc(common,
Luis R. Rodriguezdd849782009-11-04 09:44:50 -0800593 common->rx_bufsize,
Luis R. Rodriguezaeb63cf2009-08-12 09:57:00 -0700594 GFP_ATOMIC);
Bob Copelandb6ea0352009-01-10 14:42:54 -0500595
596 if (!skb) {
Pavel Roskine0d687b2011-07-14 20:21:55 -0400597 ATH5K_ERR(ah, "can't alloc skbuff of size %u\n",
Luis R. Rodriguezdd849782009-11-04 09:44:50 -0800598 common->rx_bufsize);
Bob Copelandb6ea0352009-01-10 14:42:54 -0500599 return NULL;
600 }
Bob Copelandb6ea0352009-01-10 14:42:54 -0500601
Pavel Roskine0d687b2011-07-14 20:21:55 -0400602 *skb_addr = dma_map_single(ah->dev,
Luis R. Rodriguezcc861f72009-11-04 09:11:34 -0800603 skb->data, common->rx_bufsize,
Felix Fietkauaeae4ac2010-12-02 10:26:51 +0100604 DMA_FROM_DEVICE);
605
Pavel Roskine0d687b2011-07-14 20:21:55 -0400606 if (unlikely(dma_mapping_error(ah->dev, *skb_addr))) {
607 ATH5K_ERR(ah, "%s: DMA mapping failed\n", __func__);
Bob Copelandb6ea0352009-01-10 14:42:54 -0500608 dev_kfree_skb(skb);
609 return NULL;
610 }
611 return skb;
612}
613
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200614static int
Pavel Roskine0d687b2011-07-14 20:21:55 -0400615ath5k_rxbuf_setup(struct ath5k_hw *ah, struct ath5k_buf *bf)
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200616{
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200617 struct sk_buff *skb = bf->skb;
618 struct ath5k_desc *ds;
Bruno Randolfb5eae9f2010-05-19 10:18:16 +0900619 int ret;
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200620
Bob Copelandb6ea0352009-01-10 14:42:54 -0500621 if (!skb) {
Pavel Roskine0d687b2011-07-14 20:21:55 -0400622 skb = ath5k_rx_skb_alloc(ah, &bf->skbaddr);
Bob Copelandb6ea0352009-01-10 14:42:54 -0500623 if (!skb)
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200624 return -ENOMEM;
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200625 bf->skb = skb;
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200626 }
627
628 /*
629 * Setup descriptors. For receive we always terminate
630 * the descriptor list with a self-linked entry so we'll
631 * not get overrun under high load (as can happen with a
632 * 5212 when ANI processing enables PHY error frames).
633 *
Bruno Randolfbeade632010-06-16 19:11:25 +0900634 * To ensure the last descriptor is self-linked we create
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200635 * each descriptor as self-linked and add it to the end. As
636 * each additional descriptor is added the previous self-linked
Bruno Randolfbeade632010-06-16 19:11:25 +0900637 * entry is "fixed" naturally. This should be safe even
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200638 * if DMA is happening. When processing RX interrupts we
639 * never remove/process the last, self-linked, entry on the
Bruno Randolfbeade632010-06-16 19:11:25 +0900640 * descriptor list. This ensures the hardware always has
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200641 * someplace to write a new frame.
642 */
643 ds = bf->desc;
644 ds->ds_link = bf->daddr; /* link to self */
645 ds->ds_data = bf->skbaddr;
Bruno Randolfa6668192010-06-16 19:12:01 +0900646 ret = ath5k_hw_setup_rx_desc(ah, ds, ah->common.rx_bufsize, 0);
Bruno Randolf0452d4a2010-06-16 19:11:35 +0900647 if (ret) {
Pavel Roskine0d687b2011-07-14 20:21:55 -0400648 ATH5K_ERR(ah, "%s: could not setup RX desc\n", __func__);
Bruno Randolfb5eae9f2010-05-19 10:18:16 +0900649 return ret;
Bruno Randolf0452d4a2010-06-16 19:11:35 +0900650 }
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200651
Pavel Roskine0d687b2011-07-14 20:21:55 -0400652 if (ah->rxlink != NULL)
653 *ah->rxlink = bf->daddr;
654 ah->rxlink = &ds->ds_link;
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200655 return 0;
656}
657
Bob Copeland2ac29272010-02-09 13:06:54 -0500658static enum ath5k_pkt_type get_hw_packet_type(struct sk_buff *skb)
659{
660 struct ieee80211_hdr *hdr;
661 enum ath5k_pkt_type htype;
662 __le16 fc;
663
664 hdr = (struct ieee80211_hdr *)skb->data;
665 fc = hdr->frame_control;
666
667 if (ieee80211_is_beacon(fc))
668 htype = AR5K_PKT_TYPE_BEACON;
669 else if (ieee80211_is_probe_resp(fc))
670 htype = AR5K_PKT_TYPE_PROBE_RESP;
671 else if (ieee80211_is_atim(fc))
672 htype = AR5K_PKT_TYPE_ATIM;
673 else if (ieee80211_is_pspoll(fc))
674 htype = AR5K_PKT_TYPE_PSPOLL;
675 else
676 htype = AR5K_PKT_TYPE_NORMAL;
677
678 return htype;
679}
680
Thomas Huehn0967e012013-06-11 15:10:31 +0200681static struct ieee80211_rate *
682ath5k_get_rate(const struct ieee80211_hw *hw,
683 const struct ieee80211_tx_info *info,
684 struct ath5k_buf *bf, int idx)
685{
686 /*
687 * convert a ieee80211_tx_rate RC-table entry to
688 * the respective ieee80211_rate struct
689 */
690 if (bf->rates[idx].idx < 0) {
691 return NULL;
692 }
693
694 return &hw->wiphy->bands[info->band]->bitrates[ bf->rates[idx].idx ];
695}
696
697static u16
698ath5k_get_rate_hw_value(const struct ieee80211_hw *hw,
699 const struct ieee80211_tx_info *info,
700 struct ath5k_buf *bf, int idx)
701{
702 struct ieee80211_rate *rate;
703 u16 hw_rate;
704 u8 rc_flags;
705
706 rate = ath5k_get_rate(hw, info, bf, idx);
707 if (!rate)
708 return 0;
709
710 rc_flags = bf->rates[idx].flags;
711 hw_rate = (rc_flags & IEEE80211_TX_RC_USE_SHORT_PREAMBLE) ?
712 rate->hw_value_short : rate->hw_value;
713
714 return hw_rate;
715}
716
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200717static int
Pavel Roskine0d687b2011-07-14 20:21:55 -0400718ath5k_txbuf_setup(struct ath5k_hw *ah, struct ath5k_buf *bf,
Thomas Huehn0967e012013-06-11 15:10:31 +0200719 struct ath5k_txq *txq, int padsize,
720 struct ieee80211_tx_control *control)
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200721{
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200722 struct ath5k_desc *ds = bf->desc;
723 struct sk_buff *skb = bf->skb;
Johannes Berga888d522008-05-26 16:43:39 +0200724 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200725 unsigned int pktlen, flags, keyidx = AR5K_TXKEYIX_INVALID;
Felix Fietkau2f7fe872008-10-05 18:05:48 +0200726 struct ieee80211_rate *rate;
727 unsigned int mrr_rate[3], mrr_tries[3];
728 int i, ret;
Bob Copeland8902ff42009-01-22 08:44:20 -0500729 u16 hw_rate;
Bob Copeland07c1e852009-01-22 08:44:21 -0500730 u16 cts_rate = 0;
731 u16 duration = 0;
Bob Copeland8902ff42009-01-22 08:44:20 -0500732 u8 rc_flags;
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200733
734 flags = AR5K_TXDESC_INTREQ | AR5K_TXDESC_CLRDMASK;
Johannes Berge039fa42008-05-15 12:55:29 +0200735
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200736 /* XXX endianness */
Pavel Roskine0d687b2011-07-14 20:21:55 -0400737 bf->skbaddr = dma_map_single(ah->dev, skb->data, skb->len,
Felix Fietkauaeae4ac2010-12-02 10:26:51 +0100738 DMA_TO_DEVICE);
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200739
John Greeneb499abd2014-03-11 14:08:34 -0400740 if (dma_mapping_error(ah->dev, bf->skbaddr))
741 return -ENOSPC;
742
Thomas Huehn0967e012013-06-11 15:10:31 +0200743 ieee80211_get_tx_rates(info->control.vif, (control) ? control->sta : NULL, skb, bf->rates,
744 ARRAY_SIZE(bf->rates));
745
746 rate = ath5k_get_rate(ah->hw, info, bf, 0);
747
John W. Linvilled8e1ba72010-08-24 15:27:34 -0400748 if (!rate) {
749 ret = -EINVAL;
750 goto err_unmap;
751 }
Bob Copeland8902ff42009-01-22 08:44:20 -0500752
Johannes Berge039fa42008-05-15 12:55:29 +0200753 if (info->flags & IEEE80211_TX_CTL_NO_ACK)
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200754 flags |= AR5K_TXDESC_NOACK;
755
Bob Copeland8902ff42009-01-22 08:44:20 -0500756 rc_flags = info->control.rates[0].flags;
Thomas Huehn0967e012013-06-11 15:10:31 +0200757
758 hw_rate = ath5k_get_rate_hw_value(ah->hw, info, bf, 0);
Bob Copeland8902ff42009-01-22 08:44:20 -0500759
Bruno Randolf281c56d2008-02-05 18:44:55 +0900760 pktlen = skb->len;
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200761
Nick Kossifidis8f655dd2009-03-15 22:20:35 +0200762 /* FIXME: If we are in g mode and rate is a CCK rate
763 * subtract ah->ah_txpower.txp_cck_ofdm_pwr_delta
764 * from tx power (value is in dB units already) */
Bob Copeland362695e2009-02-15 12:06:12 -0500765 if (info->control.hw_key) {
766 keyidx = info->control.hw_key->hw_key_idx;
767 pktlen += info->control.hw_key->icv_len;
768 }
Bob Copeland07c1e852009-01-22 08:44:21 -0500769 if (rc_flags & IEEE80211_TX_RC_USE_RTS_CTS) {
770 flags |= AR5K_TXDESC_RTSENA;
Pavel Roskine0d687b2011-07-14 20:21:55 -0400771 cts_rate = ieee80211_get_rts_cts_rate(ah->hw, info)->hw_value;
772 duration = le16_to_cpu(ieee80211_rts_duration(ah->hw,
Ben Greearb1ae1ed2010-09-30 12:22:58 -0700773 info->control.vif, pktlen, info));
Bob Copeland07c1e852009-01-22 08:44:21 -0500774 }
775 if (rc_flags & IEEE80211_TX_RC_USE_CTS_PROTECT) {
776 flags |= AR5K_TXDESC_CTSENA;
Pavel Roskine0d687b2011-07-14 20:21:55 -0400777 cts_rate = ieee80211_get_rts_cts_rate(ah->hw, info)->hw_value;
778 duration = le16_to_cpu(ieee80211_ctstoself_duration(ah->hw,
Ben Greearb1ae1ed2010-09-30 12:22:58 -0700779 info->control.vif, pktlen, info));
Bob Copeland07c1e852009-01-22 08:44:21 -0500780 }
Thomas Huehn0967e012013-06-11 15:10:31 +0200781
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200782 ret = ah->ah_setup_tx_desc(ah, ds, pktlen,
Benoit Papillault8127fbd2010-02-27 23:05:26 +0100783 ieee80211_get_hdrlen_from_skb(skb), padsize,
Bob Copeland2ac29272010-02-09 13:06:54 -0500784 get_hw_packet_type(skb),
Nick Kossifidis987af542012-08-05 22:35:36 +0300785 (ah->ah_txpower.txp_requested * 2),
Bob Copeland8902ff42009-01-22 08:44:20 -0500786 hw_rate,
Thomas Huehn0967e012013-06-11 15:10:31 +0200787 bf->rates[0].count, keyidx, ah->ah_tx_ant, flags,
Bob Copeland07c1e852009-01-22 08:44:21 -0500788 cts_rate, duration);
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200789 if (ret)
790 goto err_unmap;
791
Nick Kossifidis86f62d92011-11-25 20:40:28 +0200792 /* Set up MRR descriptor */
793 if (ah->ah_capabilities.cap_has_mrr_support) {
794 memset(mrr_rate, 0, sizeof(mrr_rate));
795 memset(mrr_tries, 0, sizeof(mrr_tries));
Thomas Huehn0967e012013-06-11 15:10:31 +0200796
Nick Kossifidis86f62d92011-11-25 20:40:28 +0200797 for (i = 0; i < 3; i++) {
Thomas Huehn0967e012013-06-11 15:10:31 +0200798
799 rate = ath5k_get_rate(ah->hw, info, bf, i);
Nick Kossifidis86f62d92011-11-25 20:40:28 +0200800 if (!rate)
801 break;
Felix Fietkau2f7fe872008-10-05 18:05:48 +0200802
Thomas Huehn0967e012013-06-11 15:10:31 +0200803 mrr_rate[i] = ath5k_get_rate_hw_value(ah->hw, info, bf, i);
804 mrr_tries[i] = bf->rates[i].count;
Nick Kossifidis86f62d92011-11-25 20:40:28 +0200805 }
806
807 ath5k_hw_setup_mrr_tx_desc(ah, ds,
808 mrr_rate[0], mrr_tries[0],
809 mrr_rate[1], mrr_tries[1],
810 mrr_rate[2], mrr_tries[2]);
Felix Fietkau2f7fe872008-10-05 18:05:48 +0200811 }
812
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200813 ds->ds_link = 0;
814 ds->ds_data = bf->skbaddr;
815
816 spin_lock_bh(&txq->lock);
817 list_add_tail(&bf->list, &txq->q);
Bruno Randolf925e0b02010-09-17 11:36:35 +0900818 txq->txq_len++;
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200819 if (txq->link == NULL) /* is this first packet? */
Nick Kossifidisc6e387a2008-08-29 22:45:39 +0300820 ath5k_hw_set_txdp(ah, txq->qnum, bf->daddr);
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200821 else /* no, so only link it */
822 *txq->link = bf->daddr;
823
824 txq->link = &ds->ds_link;
Nick Kossifidisc6e387a2008-08-29 22:45:39 +0300825 ath5k_hw_start_tx_dma(ah, txq->qnum);
Jiri Slaby274c7c32008-07-15 17:44:20 +0200826 mmiowb();
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200827 spin_unlock_bh(&txq->lock);
828
829 return 0;
830err_unmap:
Pavel Roskine0d687b2011-07-14 20:21:55 -0400831 dma_unmap_single(ah->dev, bf->skbaddr, skb->len, DMA_TO_DEVICE);
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200832 return ret;
833}
834
835/*******************\
836* Descriptors setup *
837\*******************/
838
839static int
Pavel Roskine0d687b2011-07-14 20:21:55 -0400840ath5k_desc_alloc(struct ath5k_hw *ah)
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200841{
842 struct ath5k_desc *ds;
843 struct ath5k_buf *bf;
844 dma_addr_t da;
845 unsigned int i;
846 int ret;
847
848 /* allocate descriptors */
Pavel Roskine0d687b2011-07-14 20:21:55 -0400849 ah->desc_len = sizeof(struct ath5k_desc) *
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200850 (ATH_TXBUF + ATH_RXBUF + ATH_BCBUF + 1);
Felix Fietkauaeae4ac2010-12-02 10:26:51 +0100851
Pavel Roskine0d687b2011-07-14 20:21:55 -0400852 ah->desc = dma_alloc_coherent(ah->dev, ah->desc_len,
853 &ah->desc_daddr, GFP_KERNEL);
854 if (ah->desc == NULL) {
855 ATH5K_ERR(ah, "can't allocate descriptors\n");
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200856 ret = -ENOMEM;
857 goto err;
858 }
Pavel Roskine0d687b2011-07-14 20:21:55 -0400859 ds = ah->desc;
860 da = ah->desc_daddr;
861 ATH5K_DBG(ah, ATH5K_DEBUG_ANY, "DMA map: %p (%zu) -> %llx\n",
862 ds, ah->desc_len, (unsigned long long)ah->desc_daddr);
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200863
864 bf = kcalloc(1 + ATH_TXBUF + ATH_RXBUF + ATH_BCBUF,
865 sizeof(struct ath5k_buf), GFP_KERNEL);
866 if (bf == NULL) {
Pavel Roskine0d687b2011-07-14 20:21:55 -0400867 ATH5K_ERR(ah, "can't allocate bufptr\n");
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200868 ret = -ENOMEM;
869 goto err_free;
870 }
Pavel Roskine0d687b2011-07-14 20:21:55 -0400871 ah->bufptr = bf;
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200872
Pavel Roskine0d687b2011-07-14 20:21:55 -0400873 INIT_LIST_HEAD(&ah->rxbuf);
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200874 for (i = 0; i < ATH_RXBUF; i++, bf++, ds++, da += sizeof(*ds)) {
875 bf->desc = ds;
876 bf->daddr = da;
Pavel Roskine0d687b2011-07-14 20:21:55 -0400877 list_add_tail(&bf->list, &ah->rxbuf);
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200878 }
879
Pavel Roskine0d687b2011-07-14 20:21:55 -0400880 INIT_LIST_HEAD(&ah->txbuf);
881 ah->txbuf_len = ATH_TXBUF;
Pavel Roskine4bbf2f2011-07-07 18:14:13 -0400882 for (i = 0; i < ATH_TXBUF; i++, bf++, ds++, da += sizeof(*ds)) {
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200883 bf->desc = ds;
884 bf->daddr = da;
Pavel Roskine0d687b2011-07-14 20:21:55 -0400885 list_add_tail(&bf->list, &ah->txbuf);
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200886 }
887
Ben Greearb1ae1ed2010-09-30 12:22:58 -0700888 /* beacon buffers */
Pavel Roskine0d687b2011-07-14 20:21:55 -0400889 INIT_LIST_HEAD(&ah->bcbuf);
Ben Greearb1ae1ed2010-09-30 12:22:58 -0700890 for (i = 0; i < ATH_BCBUF; i++, bf++, ds++, da += sizeof(*ds)) {
891 bf->desc = ds;
892 bf->daddr = da;
Pavel Roskine0d687b2011-07-14 20:21:55 -0400893 list_add_tail(&bf->list, &ah->bcbuf);
Ben Greearb1ae1ed2010-09-30 12:22:58 -0700894 }
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200895
896 return 0;
897err_free:
Pavel Roskine0d687b2011-07-14 20:21:55 -0400898 dma_free_coherent(ah->dev, ah->desc_len, ah->desc, ah->desc_daddr);
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200899err:
Pavel Roskine0d687b2011-07-14 20:21:55 -0400900 ah->desc = NULL;
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200901 return ret;
902}
903
Bruno Randolfcd2c5482010-12-22 19:20:32 +0900904void
Pavel Roskine0d687b2011-07-14 20:21:55 -0400905ath5k_txbuf_free_skb(struct ath5k_hw *ah, struct ath5k_buf *bf)
Bruno Randolfcd2c5482010-12-22 19:20:32 +0900906{
907 BUG_ON(!bf);
908 if (!bf->skb)
909 return;
Pavel Roskine0d687b2011-07-14 20:21:55 -0400910 dma_unmap_single(ah->dev, bf->skbaddr, bf->skb->len,
Bruno Randolfcd2c5482010-12-22 19:20:32 +0900911 DMA_TO_DEVICE);
Felix Fietkau596ab5e2012-12-10 16:40:41 +0100912 ieee80211_free_txskb(ah->hw, bf->skb);
Bruno Randolfcd2c5482010-12-22 19:20:32 +0900913 bf->skb = NULL;
914 bf->skbaddr = 0;
915 bf->desc->ds_data = 0;
916}
917
918void
Pavel Roskine0d687b2011-07-14 20:21:55 -0400919ath5k_rxbuf_free_skb(struct ath5k_hw *ah, struct ath5k_buf *bf)
Bruno Randolfcd2c5482010-12-22 19:20:32 +0900920{
Bruno Randolfcd2c5482010-12-22 19:20:32 +0900921 struct ath_common *common = ath5k_hw_common(ah);
922
923 BUG_ON(!bf);
924 if (!bf->skb)
925 return;
Pavel Roskine0d687b2011-07-14 20:21:55 -0400926 dma_unmap_single(ah->dev, bf->skbaddr, common->rx_bufsize,
Bruno Randolfcd2c5482010-12-22 19:20:32 +0900927 DMA_FROM_DEVICE);
928 dev_kfree_skb_any(bf->skb);
929 bf->skb = NULL;
930 bf->skbaddr = 0;
931 bf->desc->ds_data = 0;
932}
933
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200934static void
Pavel Roskine0d687b2011-07-14 20:21:55 -0400935ath5k_desc_free(struct ath5k_hw *ah)
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200936{
937 struct ath5k_buf *bf;
938
Pavel Roskine0d687b2011-07-14 20:21:55 -0400939 list_for_each_entry(bf, &ah->txbuf, list)
940 ath5k_txbuf_free_skb(ah, bf);
941 list_for_each_entry(bf, &ah->rxbuf, list)
942 ath5k_rxbuf_free_skb(ah, bf);
943 list_for_each_entry(bf, &ah->bcbuf, list)
944 ath5k_txbuf_free_skb(ah, bf);
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200945
946 /* Free memory associated with all descriptors */
Pavel Roskine0d687b2011-07-14 20:21:55 -0400947 dma_free_coherent(ah->dev, ah->desc_len, ah->desc, ah->desc_daddr);
948 ah->desc = NULL;
949 ah->desc_daddr = 0;
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200950
Pavel Roskine0d687b2011-07-14 20:21:55 -0400951 kfree(ah->bufptr);
952 ah->bufptr = NULL;
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200953}
954
955
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200956/**************\
957* Queues setup *
958\**************/
959
960static struct ath5k_txq *
Pavel Roskine0d687b2011-07-14 20:21:55 -0400961ath5k_txq_setup(struct ath5k_hw *ah,
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200962 int qtype, int subtype)
963{
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200964 struct ath5k_txq *txq;
965 struct ath5k_txq_info qi = {
966 .tqi_subtype = subtype,
Bruno Randolfde8af452010-09-17 11:37:12 +0900967 /* XXX: default values not correct for B and XR channels,
968 * but who cares? */
969 .tqi_aifs = AR5K_TUNE_AIFS,
970 .tqi_cw_min = AR5K_TUNE_CWMIN,
971 .tqi_cw_max = AR5K_TUNE_CWMAX
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200972 };
973 int qnum;
974
975 /*
976 * Enable interrupts only for EOL and DESC conditions.
977 * We mark tx descriptors to receive a DESC interrupt
Bob Copelanda180a132010-08-15 13:03:12 -0400978 * when a tx queue gets deep; otherwise we wait for the
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200979 * EOL to reap descriptors. Note that this is done to
980 * reduce interrupt load and this only defers reaping
981 * descriptors, never transmitting frames. Aside from
982 * reducing interrupts this also permits more concurrency.
983 * The only potential downside is if the tx queue backs
984 * up in which case the top half of the kernel may backup
985 * due to a lack of tx descriptors.
986 */
987 qi.tqi_flags = AR5K_TXQ_FLAG_TXEOLINT_ENABLE |
988 AR5K_TXQ_FLAG_TXDESCINT_ENABLE;
989 qnum = ath5k_hw_setup_tx_queue(ah, qtype, &qi);
990 if (qnum < 0) {
991 /*
992 * NB: don't print a message, this happens
993 * normally on parts with too few tx queues
994 */
995 return ERR_PTR(qnum);
996 }
Pavel Roskine0d687b2011-07-14 20:21:55 -0400997 txq = &ah->txqs[qnum];
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200998 if (!txq->setup) {
999 txq->qnum = qnum;
1000 txq->link = NULL;
1001 INIT_LIST_HEAD(&txq->q);
1002 spin_lock_init(&txq->lock);
1003 txq->setup = true;
Bruno Randolf925e0b02010-09-17 11:36:35 +09001004 txq->txq_len = 0;
John W. Linville81266ba2011-03-07 16:32:59 -05001005 txq->txq_max = ATH5K_TXQ_LEN_MAX;
Bruno Randolf4edd7612010-09-17 11:36:56 +09001006 txq->txq_poll_mark = false;
Bruno Randolf923e5b32010-09-17 11:37:02 +09001007 txq->txq_stuck = 0;
Jiri Slabyfa1c1142007-08-12 17:33:16 +02001008 }
Pavel Roskine0d687b2011-07-14 20:21:55 -04001009 return &ah->txqs[qnum];
Jiri Slabyfa1c1142007-08-12 17:33:16 +02001010}
1011
1012static int
1013ath5k_beaconq_setup(struct ath5k_hw *ah)
1014{
1015 struct ath5k_txq_info qi = {
Bruno Randolfde8af452010-09-17 11:37:12 +09001016 /* XXX: default values not correct for B and XR channels,
1017 * but who cares? */
1018 .tqi_aifs = AR5K_TUNE_AIFS,
1019 .tqi_cw_min = AR5K_TUNE_CWMIN,
1020 .tqi_cw_max = AR5K_TUNE_CWMAX,
Jiri Slabyfa1c1142007-08-12 17:33:16 +02001021 /* NB: for dynamic turbo, don't enable any other interrupts */
1022 .tqi_flags = AR5K_TXQ_FLAG_TXDESCINT_ENABLE
1023 };
1024
1025 return ath5k_hw_setup_tx_queue(ah, AR5K_TX_QUEUE_BEACON, &qi);
1026}
1027
1028static int
Pavel Roskine0d687b2011-07-14 20:21:55 -04001029ath5k_beaconq_config(struct ath5k_hw *ah)
Jiri Slabyfa1c1142007-08-12 17:33:16 +02001030{
Jiri Slabyfa1c1142007-08-12 17:33:16 +02001031 struct ath5k_txq_info qi;
1032 int ret;
1033
Pavel Roskine0d687b2011-07-14 20:21:55 -04001034 ret = ath5k_hw_get_tx_queueprops(ah, ah->bhalq, &qi);
Jiri Slabyfa1c1142007-08-12 17:33:16 +02001035 if (ret)
Bob Copelanda951ae22010-01-20 23:51:04 -05001036 goto err;
1037
Pavel Roskine0d687b2011-07-14 20:21:55 -04001038 if (ah->opmode == NL80211_IFTYPE_AP ||
1039 ah->opmode == NL80211_IFTYPE_MESH_POINT) {
Jiri Slabyfa1c1142007-08-12 17:33:16 +02001040 /*
1041 * Always burst out beacon and CAB traffic
1042 * (aifs = cwmin = cwmax = 0)
1043 */
1044 qi.tqi_aifs = 0;
1045 qi.tqi_cw_min = 0;
1046 qi.tqi_cw_max = 0;
Pavel Roskine0d687b2011-07-14 20:21:55 -04001047 } else if (ah->opmode == NL80211_IFTYPE_ADHOC) {
Bruno Randolf6d91e1d2008-01-19 18:18:41 +09001048 /*
1049 * Adhoc mode; backoff between 0 and (2 * cw_min).
1050 */
1051 qi.tqi_aifs = 0;
1052 qi.tqi_cw_min = 0;
Bruno Randolfde8af452010-09-17 11:37:12 +09001053 qi.tqi_cw_max = 2 * AR5K_TUNE_CWMIN;
Jiri Slabyfa1c1142007-08-12 17:33:16 +02001054 }
1055
Pavel Roskine0d687b2011-07-14 20:21:55 -04001056 ATH5K_DBG(ah, ATH5K_DEBUG_BEACON,
Bruno Randolf6d91e1d2008-01-19 18:18:41 +09001057 "beacon queueprops tqi_aifs:%d tqi_cw_min:%d tqi_cw_max:%d\n",
1058 qi.tqi_aifs, qi.tqi_cw_min, qi.tqi_cw_max);
1059
Pavel Roskine0d687b2011-07-14 20:21:55 -04001060 ret = ath5k_hw_set_tx_queueprops(ah, ah->bhalq, &qi);
Jiri Slabyfa1c1142007-08-12 17:33:16 +02001061 if (ret) {
Pavel Roskine0d687b2011-07-14 20:21:55 -04001062 ATH5K_ERR(ah, "%s: unable to update parameters for beacon "
Jiri Slabyfa1c1142007-08-12 17:33:16 +02001063 "hardware queue!\n", __func__);
Bob Copelanda951ae22010-01-20 23:51:04 -05001064 goto err;
Jiri Slabyfa1c1142007-08-12 17:33:16 +02001065 }
Pavel Roskine0d687b2011-07-14 20:21:55 -04001066 ret = ath5k_hw_reset_tx_queue(ah, ah->bhalq); /* push to h/w */
Bob Copelanda951ae22010-01-20 23:51:04 -05001067 if (ret)
1068 goto err;
Jiri Slabyfa1c1142007-08-12 17:33:16 +02001069
Bob Copelanda951ae22010-01-20 23:51:04 -05001070 /* reconfigure cabq with ready time to 80% of beacon_interval */
1071 ret = ath5k_hw_get_tx_queueprops(ah, AR5K_TX_QUEUE_ID_CAB, &qi);
1072 if (ret)
1073 goto err;
1074
Pavel Roskine0d687b2011-07-14 20:21:55 -04001075 qi.tqi_ready_time = (ah->bintval * 80) / 100;
Bob Copelanda951ae22010-01-20 23:51:04 -05001076 ret = ath5k_hw_set_tx_queueprops(ah, AR5K_TX_QUEUE_ID_CAB, &qi);
1077 if (ret)
1078 goto err;
1079
1080 ret = ath5k_hw_reset_tx_queue(ah, AR5K_TX_QUEUE_ID_CAB);
1081err:
1082 return ret;
Jiri Slabyfa1c1142007-08-12 17:33:16 +02001083}
1084
Nick Kossifidis80dac9e2010-11-23 20:45:38 +02001085/**
1086 * ath5k_drain_tx_buffs - Empty tx buffers
1087 *
Pavel Roskine0d687b2011-07-14 20:21:55 -04001088 * @ah The &struct ath5k_hw
Nick Kossifidis80dac9e2010-11-23 20:45:38 +02001089 *
1090 * Empty tx buffers from all queues in preparation
1091 * of a reset or during shutdown.
1092 *
1093 * NB: this assumes output has been stopped and
1094 * we do not need to block ath5k_tx_tasklet
Jiri Slabyfa1c1142007-08-12 17:33:16 +02001095 */
1096static void
Pavel Roskine0d687b2011-07-14 20:21:55 -04001097ath5k_drain_tx_buffs(struct ath5k_hw *ah)
Jiri Slabyfa1c1142007-08-12 17:33:16 +02001098{
Nick Kossifidis80dac9e2010-11-23 20:45:38 +02001099 struct ath5k_txq *txq;
1100 struct ath5k_buf *bf, *bf0;
1101 int i;
Jiri Slabyfa1c1142007-08-12 17:33:16 +02001102
Pavel Roskine0d687b2011-07-14 20:21:55 -04001103 for (i = 0; i < ARRAY_SIZE(ah->txqs); i++) {
1104 if (ah->txqs[i].setup) {
1105 txq = &ah->txqs[i];
Nick Kossifidis80dac9e2010-11-23 20:45:38 +02001106 spin_lock_bh(&txq->lock);
1107 list_for_each_entry_safe(bf, bf0, &txq->q, list) {
Pavel Roskine0d687b2011-07-14 20:21:55 -04001108 ath5k_debug_printtxbuf(ah, bf);
Nick Kossifidis80dac9e2010-11-23 20:45:38 +02001109
Pavel Roskine0d687b2011-07-14 20:21:55 -04001110 ath5k_txbuf_free_skb(ah, bf);
Nick Kossifidis80dac9e2010-11-23 20:45:38 +02001111
Bob Copeland66179422012-06-15 16:03:29 -04001112 spin_lock(&ah->txbuflock);
Pavel Roskine0d687b2011-07-14 20:21:55 -04001113 list_move_tail(&bf->list, &ah->txbuf);
1114 ah->txbuf_len++;
Nick Kossifidis80dac9e2010-11-23 20:45:38 +02001115 txq->txq_len--;
Bob Copeland66179422012-06-15 16:03:29 -04001116 spin_unlock(&ah->txbuflock);
Jiri Slabyfa1c1142007-08-12 17:33:16 +02001117 }
Nick Kossifidis80dac9e2010-11-23 20:45:38 +02001118 txq->link = NULL;
1119 txq->txq_poll_mark = false;
1120 spin_unlock_bh(&txq->lock);
1121 }
Jiri Slabyfa1c1142007-08-12 17:33:16 +02001122 }
Jiri Slabyfa1c1142007-08-12 17:33:16 +02001123}
1124
1125static void
Pavel Roskine0d687b2011-07-14 20:21:55 -04001126ath5k_txq_release(struct ath5k_hw *ah)
Jiri Slabyfa1c1142007-08-12 17:33:16 +02001127{
Pavel Roskine0d687b2011-07-14 20:21:55 -04001128 struct ath5k_txq *txq = ah->txqs;
Jiri Slabyfa1c1142007-08-12 17:33:16 +02001129 unsigned int i;
1130
Pavel Roskine0d687b2011-07-14 20:21:55 -04001131 for (i = 0; i < ARRAY_SIZE(ah->txqs); i++, txq++)
Jiri Slabyfa1c1142007-08-12 17:33:16 +02001132 if (txq->setup) {
Pavel Roskine0d687b2011-07-14 20:21:55 -04001133 ath5k_hw_release_tx_queue(ah, txq->qnum);
Jiri Slabyfa1c1142007-08-12 17:33:16 +02001134 txq->setup = false;
1135 }
1136}
1137
1138
Jiri Slabyfa1c1142007-08-12 17:33:16 +02001139/*************\
1140* RX Handling *
1141\*************/
1142
1143/*
1144 * Enable the receive h/w following a reset.
1145 */
1146static int
Pavel Roskine0d687b2011-07-14 20:21:55 -04001147ath5k_rx_start(struct ath5k_hw *ah)
Jiri Slabyfa1c1142007-08-12 17:33:16 +02001148{
Luis R. Rodriguezdb719712009-09-10 11:20:57 -07001149 struct ath_common *common = ath5k_hw_common(ah);
Jiri Slabyfa1c1142007-08-12 17:33:16 +02001150 struct ath5k_buf *bf;
1151 int ret;
1152
Nick Kossifidisb6127982010-08-15 13:03:11 -04001153 common->rx_bufsize = roundup(IEEE80211_MAX_FRAME_LEN, common->cachelsz);
Jiri Slabyfa1c1142007-08-12 17:33:16 +02001154
Pavel Roskine0d687b2011-07-14 20:21:55 -04001155 ATH5K_DBG(ah, ATH5K_DEBUG_RESET, "cachelsz %u rx_bufsize %u\n",
Luis R. Rodriguezcc861f72009-11-04 09:11:34 -08001156 common->cachelsz, common->rx_bufsize);
Jiri Slabyfa1c1142007-08-12 17:33:16 +02001157
Pavel Roskine0d687b2011-07-14 20:21:55 -04001158 spin_lock_bh(&ah->rxbuflock);
1159 ah->rxlink = NULL;
1160 list_for_each_entry(bf, &ah->rxbuf, list) {
1161 ret = ath5k_rxbuf_setup(ah, bf);
Jiri Slabyfa1c1142007-08-12 17:33:16 +02001162 if (ret != 0) {
Pavel Roskine0d687b2011-07-14 20:21:55 -04001163 spin_unlock_bh(&ah->rxbuflock);
Jiri Slabyfa1c1142007-08-12 17:33:16 +02001164 goto err;
1165 }
1166 }
Pavel Roskine0d687b2011-07-14 20:21:55 -04001167 bf = list_first_entry(&ah->rxbuf, struct ath5k_buf, list);
Bob Copeland26925042009-04-15 07:57:36 -04001168 ath5k_hw_set_rxdp(ah, bf->daddr);
Pavel Roskine0d687b2011-07-14 20:21:55 -04001169 spin_unlock_bh(&ah->rxbuflock);
Jiri Slabyfa1c1142007-08-12 17:33:16 +02001170
Nick Kossifidisc6e387a2008-08-29 22:45:39 +03001171 ath5k_hw_start_rx_dma(ah); /* enable recv descriptors */
Pavel Roskine0d687b2011-07-14 20:21:55 -04001172 ath5k_update_bssid_mask_and_opmode(ah, NULL); /* set filters, etc. */
Jiri Slabyfa1c1142007-08-12 17:33:16 +02001173 ath5k_hw_start_rx_pcu(ah); /* re-enable PCU/DMA engine */
1174
1175 return 0;
1176err:
1177 return ret;
1178}
1179
1180/*
Nick Kossifidis80dac9e2010-11-23 20:45:38 +02001181 * Disable the receive logic on PCU (DRU)
1182 * In preparation for a shutdown.
1183 *
1184 * Note: Doesn't stop rx DMA, ath5k_hw_dma_stop
1185 * does.
Jiri Slabyfa1c1142007-08-12 17:33:16 +02001186 */
1187static void
Pavel Roskine0d687b2011-07-14 20:21:55 -04001188ath5k_rx_stop(struct ath5k_hw *ah)
Jiri Slabyfa1c1142007-08-12 17:33:16 +02001189{
Jiri Slabyfa1c1142007-08-12 17:33:16 +02001190
Jiri Slabyfa1c1142007-08-12 17:33:16 +02001191 ath5k_hw_set_rx_filter(ah, 0); /* clear recv filter */
Nick Kossifidis80dac9e2010-11-23 20:45:38 +02001192 ath5k_hw_stop_rx_pcu(ah); /* disable PCU */
Jiri Slabyfa1c1142007-08-12 17:33:16 +02001193
Pavel Roskine0d687b2011-07-14 20:21:55 -04001194 ath5k_debug_printrxbuffs(ah);
Jiri Slabyfa1c1142007-08-12 17:33:16 +02001195}
1196
1197static unsigned int
Pavel Roskine0d687b2011-07-14 20:21:55 -04001198ath5k_rx_decrypted(struct ath5k_hw *ah, struct sk_buff *skb,
Bruno Randolf8a89f062010-06-16 19:11:51 +09001199 struct ath5k_rx_status *rs)
Jiri Slabyfa1c1142007-08-12 17:33:16 +02001200{
Luis R. Rodriguezdc1e0012009-11-04 17:47:31 -08001201 struct ath_common *common = ath5k_hw_common(ah);
Jiri Slabyfa1c1142007-08-12 17:33:16 +02001202 struct ieee80211_hdr *hdr = (void *)skb->data;
Harvey Harrison798ee982008-07-15 18:44:02 -07001203 unsigned int keyix, hlen;
Jiri Slabyfa1c1142007-08-12 17:33:16 +02001204
Bruno Randolfb47f4072008-03-05 18:35:45 +09001205 if (!(rs->rs_status & AR5K_RXERR_DECRYPT) &&
1206 rs->rs_keyix != AR5K_RXKEYIX_INVALID)
Jiri Slabyfa1c1142007-08-12 17:33:16 +02001207 return RX_FLAG_DECRYPTED;
1208
1209 /* Apparently when a default key is used to decrypt the packet
1210 the hw does not set the index used to decrypt. In such cases
1211 get the index from the packet. */
Harvey Harrison798ee982008-07-15 18:44:02 -07001212 hlen = ieee80211_hdrlen(hdr->frame_control);
Harvey Harrison24b56e72008-06-14 23:33:38 -07001213 if (ieee80211_has_protected(hdr->frame_control) &&
1214 !(rs->rs_status & AR5K_RXERR_DECRYPT) &&
1215 skb->len >= hlen + 4) {
Jiri Slabyfa1c1142007-08-12 17:33:16 +02001216 keyix = skb->data[hlen + 3] >> 6;
1217
Luis R. Rodriguezdc1e0012009-11-04 17:47:31 -08001218 if (test_bit(keyix, common->keymap))
Jiri Slabyfa1c1142007-08-12 17:33:16 +02001219 return RX_FLAG_DECRYPTED;
1220 }
1221
1222 return 0;
1223}
1224
Bruno Randolf036cd1e2008-01-19 18:18:21 +09001225
1226static void
Pavel Roskine0d687b2011-07-14 20:21:55 -04001227ath5k_check_ibss_tsf(struct ath5k_hw *ah, struct sk_buff *skb,
Bruno Randolf6ba81c22008-03-05 18:36:26 +09001228 struct ieee80211_rx_status *rxs)
Bruno Randolf036cd1e2008-01-19 18:18:21 +09001229{
Bruno Randolf6ba81c22008-03-05 18:36:26 +09001230 u64 tsf, bc_tstamp;
Bruno Randolf036cd1e2008-01-19 18:18:21 +09001231 u32 hw_tu;
1232 struct ieee80211_mgmt *mgmt = (struct ieee80211_mgmt *)skb->data;
1233
Oleksij Rempeld44efe22014-01-15 17:11:15 +01001234 if (le16_to_cpu(mgmt->u.beacon.capab_info) & WLAN_CAPABILITY_IBSS) {
Bruno Randolf036cd1e2008-01-19 18:18:21 +09001235 /*
Bruno Randolf6ba81c22008-03-05 18:36:26 +09001236 * Received an IBSS beacon with the same BSSID. Hardware *must*
1237 * have updated the local TSF. We have to work around various
1238 * hardware bugs, though...
Bruno Randolf036cd1e2008-01-19 18:18:21 +09001239 */
Pavel Roskine0d687b2011-07-14 20:21:55 -04001240 tsf = ath5k_hw_get_tsf64(ah);
Bruno Randolf6ba81c22008-03-05 18:36:26 +09001241 bc_tstamp = le64_to_cpu(mgmt->u.beacon.timestamp);
1242 hw_tu = TSF_TO_TU(tsf);
1243
Pavel Roskine0d687b2011-07-14 20:21:55 -04001244 ATH5K_DBG_UNLIMIT(ah, ATH5K_DEBUG_BEACON,
Bruno Randolf6ba81c22008-03-05 18:36:26 +09001245 "beacon %llx mactime %llx (diff %lld) tsf now %llx\n",
John W. Linville06501d22008-04-01 17:38:47 -04001246 (unsigned long long)bc_tstamp,
1247 (unsigned long long)rxs->mactime,
1248 (unsigned long long)(rxs->mactime - bc_tstamp),
1249 (unsigned long long)tsf);
Bruno Randolf6ba81c22008-03-05 18:36:26 +09001250
1251 /*
1252 * Sometimes the HW will give us a wrong tstamp in the rx
1253 * status, causing the timestamp extension to go wrong.
1254 * (This seems to happen especially with beacon frames bigger
1255 * than 78 byte (incl. FCS))
1256 * But we know that the receive timestamp must be later than the
1257 * timestamp of the beacon since HW must have synced to that.
1258 *
1259 * NOTE: here we assume mactime to be after the frame was
1260 * received, not like mac80211 which defines it at the start.
1261 */
1262 if (bc_tstamp > rxs->mactime) {
Pavel Roskine0d687b2011-07-14 20:21:55 -04001263 ATH5K_DBG_UNLIMIT(ah, ATH5K_DEBUG_BEACON,
Bruno Randolf6ba81c22008-03-05 18:36:26 +09001264 "fixing mactime from %llx to %llx\n",
John W. Linville06501d22008-04-01 17:38:47 -04001265 (unsigned long long)rxs->mactime,
1266 (unsigned long long)tsf);
Bruno Randolf6ba81c22008-03-05 18:36:26 +09001267 rxs->mactime = tsf;
Bruno Randolf036cd1e2008-01-19 18:18:21 +09001268 }
Bruno Randolf6ba81c22008-03-05 18:36:26 +09001269
1270 /*
1271 * Local TSF might have moved higher than our beacon timers,
1272 * in that case we have to update them to continue sending
1273 * beacons. This also takes care of synchronizing beacon sending
1274 * times with other stations.
1275 */
Pavel Roskine0d687b2011-07-14 20:21:55 -04001276 if (hw_tu >= ah->nexttbtt)
1277 ath5k_beacon_update_timers(ah, bc_tstamp);
Bruno Randolf7f896122010-09-27 12:22:21 +09001278
1279 /* Check if the beacon timers are still correct, because a TSF
1280 * update might have created a window between them - for a
1281 * longer description see the comment of this function: */
Pavel Roskine0d687b2011-07-14 20:21:55 -04001282 if (!ath5k_hw_check_beacon_timers(ah, ah->bintval)) {
1283 ath5k_beacon_update_timers(ah, bc_tstamp);
1284 ATH5K_DBG_UNLIMIT(ah, ATH5K_DEBUG_BEACON,
Bruno Randolf7f896122010-09-27 12:22:21 +09001285 "fixed beacon timers after beacon receive\n");
1286 }
Bruno Randolf036cd1e2008-01-19 18:18:21 +09001287 }
1288}
1289
Benoit Papillault8127fbd2010-02-27 23:05:26 +01001290/*
Bob Copelanda180a132010-08-15 13:03:12 -04001291 * Compute padding position. skb must contain an IEEE 802.11 frame
Benoit Papillault8127fbd2010-02-27 23:05:26 +01001292 */
1293static int ath5k_common_padpos(struct sk_buff *skb)
1294{
Pavel Roskine4bbf2f2011-07-07 18:14:13 -04001295 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
Benoit Papillault8127fbd2010-02-27 23:05:26 +01001296 __le16 frame_control = hdr->frame_control;
1297 int padpos = 24;
1298
Pavel Roskind2c7f772011-07-07 18:14:07 -04001299 if (ieee80211_has_a4(frame_control))
Benoit Papillault8127fbd2010-02-27 23:05:26 +01001300 padpos += ETH_ALEN;
Pavel Roskind2c7f772011-07-07 18:14:07 -04001301
1302 if (ieee80211_is_data_qos(frame_control))
Benoit Papillault8127fbd2010-02-27 23:05:26 +01001303 padpos += IEEE80211_QOS_CTL_LEN;
Benoit Papillault8127fbd2010-02-27 23:05:26 +01001304
1305 return padpos;
1306}
1307
1308/*
Bob Copelanda180a132010-08-15 13:03:12 -04001309 * This function expects an 802.11 frame and returns the number of
1310 * bytes added, or -1 if we don't have enough header room.
Benoit Papillault8127fbd2010-02-27 23:05:26 +01001311 */
Benoit Papillault8127fbd2010-02-27 23:05:26 +01001312static int ath5k_add_padding(struct sk_buff *skb)
1313{
1314 int padpos = ath5k_common_padpos(skb);
1315 int padsize = padpos & 3;
1316
Pavel Roskine4bbf2f2011-07-07 18:14:13 -04001317 if (padsize && skb->len > padpos) {
Benoit Papillault8127fbd2010-02-27 23:05:26 +01001318
1319 if (skb_headroom(skb) < padsize)
1320 return -1;
1321
1322 skb_push(skb, padsize);
Pavel Roskine4bbf2f2011-07-07 18:14:13 -04001323 memmove(skb->data, skb->data + padsize, padpos);
Benoit Papillault8127fbd2010-02-27 23:05:26 +01001324 return padsize;
1325 }
1326
1327 return 0;
1328}
1329
1330/*
Bob Copelanda180a132010-08-15 13:03:12 -04001331 * The MAC header is padded to have 32-bit boundary if the
1332 * packet payload is non-zero. The general calculation for
1333 * padsize would take into account odd header lengths:
1334 * padsize = 4 - (hdrlen & 3); however, since only
1335 * even-length headers are used, padding can only be 0 or 2
1336 * bytes and we can optimize this a bit. We must not try to
1337 * remove padding from short control frames that do not have a
1338 * payload.
1339 *
1340 * This function expects an 802.11 frame and returns the number of
1341 * bytes removed.
Benoit Papillault8127fbd2010-02-27 23:05:26 +01001342 */
Benoit Papillault8127fbd2010-02-27 23:05:26 +01001343static int ath5k_remove_padding(struct sk_buff *skb)
1344{
1345 int padpos = ath5k_common_padpos(skb);
1346 int padsize = padpos & 3;
1347
Pavel Roskine4bbf2f2011-07-07 18:14:13 -04001348 if (padsize && skb->len >= padpos + padsize) {
Benoit Papillault8127fbd2010-02-27 23:05:26 +01001349 memmove(skb->data + padsize, skb->data, padpos);
1350 skb_pull(skb, padsize);
1351 return padsize;
1352 }
1353
1354 return 0;
1355}
1356
Jiri Slabyfa1c1142007-08-12 17:33:16 +02001357static void
Pavel Roskine0d687b2011-07-14 20:21:55 -04001358ath5k_receive_frame(struct ath5k_hw *ah, struct sk_buff *skb,
Bruno Randolf8a89f062010-06-16 19:11:51 +09001359 struct ath5k_rx_status *rs)
Jiri Slabyfa1c1142007-08-12 17:33:16 +02001360{
Bob Copeland1c5256b2009-08-24 23:00:32 -04001361 struct ieee80211_rx_status *rxs;
Oleksij Rempeld44efe22014-01-15 17:11:15 +01001362 struct ath_common *common = ath5k_hw_common(ah);
Bruno Randolf8a89f062010-06-16 19:11:51 +09001363
Bruno Randolf8a89f062010-06-16 19:11:51 +09001364 ath5k_remove_padding(skb);
1365
1366 rxs = IEEE80211_SKB_RXCB(skb);
1367
1368 rxs->flag = 0;
1369 if (unlikely(rs->rs_status & AR5K_RXERR_MIC))
1370 rxs->flag |= RX_FLAG_MMIC_ERROR;
Mathy Vanhoef41881352014-06-13 23:40:22 +02001371 if (unlikely(rs->rs_status & AR5K_RXERR_CRC))
1372 rxs->flag |= RX_FLAG_FAILED_FCS_CRC;
1373
Bruno Randolf8a89f062010-06-16 19:11:51 +09001374
1375 /*
1376 * always extend the mac timestamp, since this information is
1377 * also needed for proper IBSS merging.
1378 *
1379 * XXX: it might be too late to do it here, since rs_tstamp is
1380 * 15bit only. that means TSF extension has to be done within
1381 * 32768usec (about 32ms). it might be necessary to move this to
1382 * the interrupt handler, like it is done in madwifi.
Bruno Randolf8a89f062010-06-16 19:11:51 +09001383 */
Pavel Roskine0d687b2011-07-14 20:21:55 -04001384 rxs->mactime = ath5k_extend_tsf(ah, rs->rs_tstamp);
Thomas Pedersene576def2012-12-10 14:48:03 -08001385 rxs->flag |= RX_FLAG_MACTIME_END;
Bruno Randolf8a89f062010-06-16 19:11:51 +09001386
Pavel Roskine0d687b2011-07-14 20:21:55 -04001387 rxs->freq = ah->curchan->center_freq;
1388 rxs->band = ah->curchan->band;
Bruno Randolf8a89f062010-06-16 19:11:51 +09001389
Pavel Roskine0d687b2011-07-14 20:21:55 -04001390 rxs->signal = ah->ah_noise_floor + rs->rs_rssi;
Bruno Randolf8a89f062010-06-16 19:11:51 +09001391
1392 rxs->antenna = rs->rs_antenna;
1393
1394 if (rs->rs_antenna > 0 && rs->rs_antenna < 5)
Pavel Roskine0d687b2011-07-14 20:21:55 -04001395 ah->stats.antenna_rx[rs->rs_antenna]++;
Bruno Randolf8a89f062010-06-16 19:11:51 +09001396 else
Pavel Roskine0d687b2011-07-14 20:21:55 -04001397 ah->stats.antenna_rx[0]++; /* invalid */
Bruno Randolf8a89f062010-06-16 19:11:51 +09001398
Pavel Roskine0d687b2011-07-14 20:21:55 -04001399 rxs->rate_idx = ath5k_hw_to_driver_rix(ah, rs->rs_rate);
1400 rxs->flag |= ath5k_rx_decrypted(ah, skb, rs);
Simon Wunderlich312a6442013-08-14 08:01:35 +02001401 switch (ah->ah_bwmode) {
1402 case AR5K_BWMODE_5MHZ:
1403 rxs->flag |= RX_FLAG_5MHZ;
1404 break;
1405 case AR5K_BWMODE_10MHZ:
1406 rxs->flag |= RX_FLAG_10MHZ;
1407 break;
1408 default:
1409 break;
1410 }
Bruno Randolf8a89f062010-06-16 19:11:51 +09001411
Bob Copelande6938ea2014-08-22 09:18:00 -04001412 if (rs->rs_rate ==
Pavel Roskine0d687b2011-07-14 20:21:55 -04001413 ah->sbands[ah->curchan->band].bitrates[rxs->rate_idx].hw_value_short)
Bruno Randolf8a89f062010-06-16 19:11:51 +09001414 rxs->flag |= RX_FLAG_SHORTPRE;
1415
Pavel Roskine0d687b2011-07-14 20:21:55 -04001416 trace_ath5k_rx(ah, skb);
Bruno Randolf8a89f062010-06-16 19:11:51 +09001417
Oleksij Rempeld44efe22014-01-15 17:11:15 +01001418 if (ath_is_mybeacon(common, (struct ieee80211_hdr *)skb->data)) {
1419 ewma_add(&ah->ah_beacon_rssi_avg, rs->rs_rssi);
Bruno Randolf8a89f062010-06-16 19:11:51 +09001420
Oleksij Rempeld44efe22014-01-15 17:11:15 +01001421 /* check beacons in IBSS mode */
1422 if (ah->opmode == NL80211_IFTYPE_ADHOC)
1423 ath5k_check_ibss_tsf(ah, skb, rxs);
1424 }
Bruno Randolf8a89f062010-06-16 19:11:51 +09001425
Pavel Roskine0d687b2011-07-14 20:21:55 -04001426 ieee80211_rx(ah->hw, skb);
Bruno Randolf8a89f062010-06-16 19:11:51 +09001427}
1428
Bruno Randolf02a78b42010-06-16 19:11:56 +09001429/** ath5k_frame_receive_ok() - Do we want to receive this frame or not?
1430 *
1431 * Check if we want to further process this frame or not. Also update
1432 * statistics. Return true if we want this frame, false if not.
1433 */
1434static bool
Pavel Roskine0d687b2011-07-14 20:21:55 -04001435ath5k_receive_frame_ok(struct ath5k_hw *ah, struct ath5k_rx_status *rs)
Bruno Randolf02a78b42010-06-16 19:11:56 +09001436{
Pavel Roskine0d687b2011-07-14 20:21:55 -04001437 ah->stats.rx_all_count++;
1438 ah->stats.rx_bytes_count += rs->rs_datalen;
Bruno Randolf02a78b42010-06-16 19:11:56 +09001439
1440 if (unlikely(rs->rs_status)) {
Mathy Vanhoef41881352014-06-13 23:40:22 +02001441 unsigned int filters;
1442
Bruno Randolf02a78b42010-06-16 19:11:56 +09001443 if (rs->rs_status & AR5K_RXERR_CRC)
Pavel Roskine0d687b2011-07-14 20:21:55 -04001444 ah->stats.rxerr_crc++;
Bruno Randolf02a78b42010-06-16 19:11:56 +09001445 if (rs->rs_status & AR5K_RXERR_FIFO)
Pavel Roskine0d687b2011-07-14 20:21:55 -04001446 ah->stats.rxerr_fifo++;
Bruno Randolf02a78b42010-06-16 19:11:56 +09001447 if (rs->rs_status & AR5K_RXERR_PHY) {
Pavel Roskine0d687b2011-07-14 20:21:55 -04001448 ah->stats.rxerr_phy++;
Bruno Randolf02a78b42010-06-16 19:11:56 +09001449 if (rs->rs_phyerr > 0 && rs->rs_phyerr < 32)
Pavel Roskine0d687b2011-07-14 20:21:55 -04001450 ah->stats.rxerr_phy_code[rs->rs_phyerr]++;
Mathy Vanhoefb76ff0d2014-06-14 01:14:56 +02001451
1452 /*
1453 * Treat packets that underwent a CCK or OFDM reset as having a bad CRC.
1454 * These restarts happen when the radio resynchronizes to a stronger frame
1455 * while receiving a weaker frame. Here we receive the prefix of the weak
1456 * frame. Since these are incomplete packets, mark their CRC as invalid.
1457 */
1458 if (rs->rs_phyerr == AR5K_RX_PHY_ERROR_OFDM_RESTART ||
1459 rs->rs_phyerr == AR5K_RX_PHY_ERROR_CCK_RESTART) {
1460 rs->rs_status |= AR5K_RXERR_CRC;
1461 rs->rs_status &= ~AR5K_RXERR_PHY;
1462 } else {
1463 return false;
1464 }
Bruno Randolf02a78b42010-06-16 19:11:56 +09001465 }
1466 if (rs->rs_status & AR5K_RXERR_DECRYPT) {
1467 /*
1468 * Decrypt error. If the error occurred
1469 * because there was no hardware key, then
1470 * let the frame through so the upper layers
1471 * can process it. This is necessary for 5210
1472 * parts which have no way to setup a ``clear''
1473 * key cache entry.
1474 *
1475 * XXX do key cache faulting
1476 */
Pavel Roskine0d687b2011-07-14 20:21:55 -04001477 ah->stats.rxerr_decrypt++;
Bruno Randolf02a78b42010-06-16 19:11:56 +09001478 if (rs->rs_keyix == AR5K_RXKEYIX_INVALID &&
1479 !(rs->rs_status & AR5K_RXERR_CRC))
1480 return true;
1481 }
1482 if (rs->rs_status & AR5K_RXERR_MIC) {
Pavel Roskine0d687b2011-07-14 20:21:55 -04001483 ah->stats.rxerr_mic++;
Bruno Randolf02a78b42010-06-16 19:11:56 +09001484 return true;
1485 }
1486
Mathy Vanhoef41881352014-06-13 23:40:22 +02001487 /*
1488 * Reject any frames with non-crypto errors, and take into account the
1489 * current FIF_* filters.
1490 */
1491 filters = AR5K_RXERR_DECRYPT;
1492 if (ah->fif_filter_flags & FIF_FCSFAIL)
1493 filters |= AR5K_RXERR_CRC;
1494
1495 if (rs->rs_status & ~filters)
Bruno Randolf02a78b42010-06-16 19:11:56 +09001496 return false;
1497 }
1498
1499 if (unlikely(rs->rs_more)) {
Pavel Roskine0d687b2011-07-14 20:21:55 -04001500 ah->stats.rxerr_jumbo++;
Bruno Randolf02a78b42010-06-16 19:11:56 +09001501 return false;
1502 }
1503 return true;
1504}
1505
Bruno Randolf8a89f062010-06-16 19:11:51 +09001506static void
Pavel Roskine0d687b2011-07-14 20:21:55 -04001507ath5k_set_current_imask(struct ath5k_hw *ah)
Felix Fietkauc266c712011-04-10 18:32:19 +02001508{
Pavel Roskin4fc54012011-07-07 18:14:25 -04001509 enum ath5k_int imask;
Felix Fietkauc266c712011-04-10 18:32:19 +02001510 unsigned long flags;
1511
Pavel Roskine0d687b2011-07-14 20:21:55 -04001512 spin_lock_irqsave(&ah->irqlock, flags);
1513 imask = ah->imask;
1514 if (ah->rx_pending)
Felix Fietkauc266c712011-04-10 18:32:19 +02001515 imask &= ~AR5K_INT_RX_ALL;
Pavel Roskine0d687b2011-07-14 20:21:55 -04001516 if (ah->tx_pending)
Felix Fietkauc266c712011-04-10 18:32:19 +02001517 imask &= ~AR5K_INT_TX_ALL;
Pavel Roskine0d687b2011-07-14 20:21:55 -04001518 ath5k_hw_set_imr(ah, imask);
1519 spin_unlock_irqrestore(&ah->irqlock, flags);
Felix Fietkauc266c712011-04-10 18:32:19 +02001520}
1521
1522static void
Bruno Randolf8a89f062010-06-16 19:11:51 +09001523ath5k_tasklet_rx(unsigned long data)
1524{
Bruno Randolfb47f4072008-03-05 18:35:45 +09001525 struct ath5k_rx_status rs = {};
Bob Copelandb6ea0352009-01-10 14:42:54 -05001526 struct sk_buff *skb, *next_skb;
1527 dma_addr_t next_skb_addr;
Pavel Roskine0d687b2011-07-14 20:21:55 -04001528 struct ath5k_hw *ah = (void *)data;
Luis R. Rodriguezcc861f72009-11-04 09:11:34 -08001529 struct ath_common *common = ath5k_hw_common(ah);
Bob Copelandc57ca812009-04-15 07:57:35 -04001530 struct ath5k_buf *bf;
Jiri Slabyfa1c1142007-08-12 17:33:16 +02001531 struct ath5k_desc *ds;
Jiri Slabyfa1c1142007-08-12 17:33:16 +02001532 int ret;
Jiri Slabyfa1c1142007-08-12 17:33:16 +02001533
Pavel Roskine0d687b2011-07-14 20:21:55 -04001534 spin_lock(&ah->rxbuflock);
1535 if (list_empty(&ah->rxbuf)) {
1536 ATH5K_WARN(ah, "empty rx buf pool\n");
Jiri Slaby3a0f2c82008-07-15 17:44:18 +02001537 goto unlock;
1538 }
Jiri Slabyfa1c1142007-08-12 17:33:16 +02001539 do {
Pavel Roskine0d687b2011-07-14 20:21:55 -04001540 bf = list_first_entry(&ah->rxbuf, struct ath5k_buf, list);
Jiri Slabyfa1c1142007-08-12 17:33:16 +02001541 BUG_ON(bf->skb == NULL);
1542 skb = bf->skb;
1543 ds = bf->desc;
1544
Bob Copelandc57ca812009-04-15 07:57:35 -04001545 /* bail if HW is still using self-linked descriptor */
Pavel Roskine0d687b2011-07-14 20:21:55 -04001546 if (ath5k_hw_get_rxdp(ah) == bf->daddr)
Bob Copelandc57ca812009-04-15 07:57:35 -04001547 break;
Jiri Slabyfa1c1142007-08-12 17:33:16 +02001548
Pavel Roskine0d687b2011-07-14 20:21:55 -04001549 ret = ah->ah_proc_rx_desc(ah, ds, &rs);
Jiri Slabyfa1c1142007-08-12 17:33:16 +02001550 if (unlikely(ret == -EINPROGRESS))
1551 break;
1552 else if (unlikely(ret)) {
Pavel Roskine0d687b2011-07-14 20:21:55 -04001553 ATH5K_ERR(ah, "error in processing rx descriptor\n");
1554 ah->stats.rxerr_proc++;
Bruno Randolfb16062f2010-06-16 19:11:46 +09001555 break;
Jiri Slabyfa1c1142007-08-12 17:33:16 +02001556 }
1557
Pavel Roskine0d687b2011-07-14 20:21:55 -04001558 if (ath5k_receive_frame_ok(ah, &rs)) {
1559 next_skb = ath5k_rx_skb_alloc(ah, &next_skb_addr);
Bruno Randolf76443952010-03-09 16:56:00 +09001560
Bruno Randolf02a78b42010-06-16 19:11:56 +09001561 /*
1562 * If we can't replace bf->skb with a new skb under
1563 * memory pressure, just skip this packet
1564 */
1565 if (!next_skb)
Jiri Slabyfa1c1142007-08-12 17:33:16 +02001566 goto next;
Jiri Slabyfa1c1142007-08-12 17:33:16 +02001567
Pavel Roskine0d687b2011-07-14 20:21:55 -04001568 dma_unmap_single(ah->dev, bf->skbaddr,
Bruno Randolf02a78b42010-06-16 19:11:56 +09001569 common->rx_bufsize,
Felix Fietkauaeae4ac2010-12-02 10:26:51 +01001570 DMA_FROM_DEVICE);
Bruno Randolf02a78b42010-06-16 19:11:56 +09001571
1572 skb_put(skb, rs.rs_datalen);
1573
Pavel Roskine0d687b2011-07-14 20:21:55 -04001574 ath5k_receive_frame(ah, skb, &rs);
Bruno Randolf02a78b42010-06-16 19:11:56 +09001575
1576 bf->skb = next_skb;
1577 bf->skbaddr = next_skb_addr;
Jiri Slabyfa1c1142007-08-12 17:33:16 +02001578 }
Jiri Slabyfa1c1142007-08-12 17:33:16 +02001579next:
Pavel Roskine0d687b2011-07-14 20:21:55 -04001580 list_move_tail(&bf->list, &ah->rxbuf);
1581 } while (ath5k_rxbuf_setup(ah, bf) == 0);
Jiri Slaby3a0f2c82008-07-15 17:44:18 +02001582unlock:
Pavel Roskine0d687b2011-07-14 20:21:55 -04001583 spin_unlock(&ah->rxbuflock);
1584 ah->rx_pending = false;
1585 ath5k_set_current_imask(ah);
Jiri Slabyfa1c1142007-08-12 17:33:16 +02001586}
1587
1588
Jiri Slabyfa1c1142007-08-12 17:33:16 +02001589/*************\
1590* TX Handling *
1591\*************/
1592
Johannes Berg7bb45682011-02-24 14:42:06 +01001593void
Bruno Randolfcd2c5482010-12-22 19:20:32 +09001594ath5k_tx_queue(struct ieee80211_hw *hw, struct sk_buff *skb,
Thomas Huehn0967e012013-06-11 15:10:31 +02001595 struct ath5k_txq *txq, struct ieee80211_tx_control *control)
Bob Copeland8a63fac2010-09-17 12:45:07 +09001596{
Pavel Roskine0d687b2011-07-14 20:21:55 -04001597 struct ath5k_hw *ah = hw->priv;
Bob Copeland8a63fac2010-09-17 12:45:07 +09001598 struct ath5k_buf *bf;
1599 unsigned long flags;
1600 int padsize;
1601
Pavel Roskine0d687b2011-07-14 20:21:55 -04001602 trace_ath5k_tx(ah, skb, txq);
Bob Copeland8a63fac2010-09-17 12:45:07 +09001603
1604 /*
1605 * The hardware expects the header padded to 4 byte boundaries.
1606 * If this is not the case, we add the padding after the header.
1607 */
1608 padsize = ath5k_add_padding(skb);
1609 if (padsize < 0) {
Pavel Roskine0d687b2011-07-14 20:21:55 -04001610 ATH5K_ERR(ah, "tx hdrlen not %%4: not enough"
Bob Copeland8a63fac2010-09-17 12:45:07 +09001611 " headroom to pad");
1612 goto drop_packet;
1613 }
1614
Felix Fietkau4e868792011-07-12 09:02:05 +08001615 if (txq->txq_len >= txq->txq_max &&
1616 txq->qnum <= AR5K_TX_QUEUE_ID_DATA_MAX)
Bruno Randolf925e0b02010-09-17 11:36:35 +09001617 ieee80211_stop_queue(hw, txq->qnum);
1618
Pavel Roskine0d687b2011-07-14 20:21:55 -04001619 spin_lock_irqsave(&ah->txbuflock, flags);
1620 if (list_empty(&ah->txbuf)) {
1621 ATH5K_ERR(ah, "no further txbuf available, dropping packet\n");
1622 spin_unlock_irqrestore(&ah->txbuflock, flags);
Bruno Randolf651d9372010-09-17 11:36:46 +09001623 ieee80211_stop_queues(hw);
Bob Copeland8a63fac2010-09-17 12:45:07 +09001624 goto drop_packet;
1625 }
Pavel Roskine0d687b2011-07-14 20:21:55 -04001626 bf = list_first_entry(&ah->txbuf, struct ath5k_buf, list);
Bob Copeland8a63fac2010-09-17 12:45:07 +09001627 list_del(&bf->list);
Pavel Roskine0d687b2011-07-14 20:21:55 -04001628 ah->txbuf_len--;
1629 if (list_empty(&ah->txbuf))
Bob Copeland8a63fac2010-09-17 12:45:07 +09001630 ieee80211_stop_queues(hw);
Pavel Roskine0d687b2011-07-14 20:21:55 -04001631 spin_unlock_irqrestore(&ah->txbuflock, flags);
Bob Copeland8a63fac2010-09-17 12:45:07 +09001632
1633 bf->skb = skb;
1634
Thomas Huehn0967e012013-06-11 15:10:31 +02001635 if (ath5k_txbuf_setup(ah, bf, txq, padsize, control)) {
Bob Copeland8a63fac2010-09-17 12:45:07 +09001636 bf->skb = NULL;
Pavel Roskine0d687b2011-07-14 20:21:55 -04001637 spin_lock_irqsave(&ah->txbuflock, flags);
1638 list_add_tail(&bf->list, &ah->txbuf);
1639 ah->txbuf_len++;
1640 spin_unlock_irqrestore(&ah->txbuflock, flags);
Bob Copeland8a63fac2010-09-17 12:45:07 +09001641 goto drop_packet;
1642 }
Johannes Berg7bb45682011-02-24 14:42:06 +01001643 return;
Bob Copeland8a63fac2010-09-17 12:45:07 +09001644
1645drop_packet:
Felix Fietkau596ab5e2012-12-10 16:40:41 +01001646 ieee80211_free_txskb(hw, skb);
Bob Copeland8a63fac2010-09-17 12:45:07 +09001647}
1648
Bruno Randolf14404012010-09-17 11:36:51 +09001649static void
Pavel Roskine0d687b2011-07-14 20:21:55 -04001650ath5k_tx_frame_completed(struct ath5k_hw *ah, struct sk_buff *skb,
Thomas Huehn0967e012013-06-11 15:10:31 +02001651 struct ath5k_txq *txq, struct ath5k_tx_status *ts,
1652 struct ath5k_buf *bf)
Bruno Randolf14404012010-09-17 11:36:51 +09001653{
1654 struct ieee80211_tx_info *info;
Felix Fietkaued895082011-04-10 18:32:17 +02001655 u8 tries[3];
Bruno Randolf14404012010-09-17 11:36:51 +09001656 int i;
Thomas Huehn0967e012013-06-11 15:10:31 +02001657 int size = 0;
Bruno Randolf14404012010-09-17 11:36:51 +09001658
Pavel Roskine0d687b2011-07-14 20:21:55 -04001659 ah->stats.tx_all_count++;
1660 ah->stats.tx_bytes_count += skb->len;
Bruno Randolf14404012010-09-17 11:36:51 +09001661 info = IEEE80211_SKB_CB(skb);
1662
Felix Fietkau7ede6122013-10-14 21:18:48 +02001663 size = min_t(int, sizeof(info->status.rates), sizeof(bf->rates));
1664 memcpy(info->status.rates, bf->rates, size);
1665
Felix Fietkaued895082011-04-10 18:32:17 +02001666 tries[0] = info->status.rates[0].count;
1667 tries[1] = info->status.rates[1].count;
1668 tries[2] = info->status.rates[2].count;
1669
Bruno Randolf14404012010-09-17 11:36:51 +09001670 ieee80211_tx_info_clear_status(info);
Felix Fietkaued895082011-04-10 18:32:17 +02001671
1672 for (i = 0; i < ts->ts_final_idx; i++) {
Bruno Randolf14404012010-09-17 11:36:51 +09001673 struct ieee80211_tx_rate *r =
1674 &info->status.rates[i];
1675
Felix Fietkaued895082011-04-10 18:32:17 +02001676 r->count = tries[i];
Bruno Randolf14404012010-09-17 11:36:51 +09001677 }
1678
Felix Fietkaued895082011-04-10 18:32:17 +02001679 info->status.rates[ts->ts_final_idx].count = ts->ts_final_retry;
Felix Fietkau6d7b97b2011-04-09 21:37:14 +02001680 info->status.rates[ts->ts_final_idx + 1].idx = -1;
Bruno Randolf14404012010-09-17 11:36:51 +09001681
1682 if (unlikely(ts->ts_status)) {
Pavel Roskine0d687b2011-07-14 20:21:55 -04001683 ah->stats.ack_fail++;
Bruno Randolf14404012010-09-17 11:36:51 +09001684 if (ts->ts_status & AR5K_TXERR_FILT) {
1685 info->flags |= IEEE80211_TX_STAT_TX_FILTERED;
Pavel Roskine0d687b2011-07-14 20:21:55 -04001686 ah->stats.txerr_filt++;
Bruno Randolf14404012010-09-17 11:36:51 +09001687 }
1688 if (ts->ts_status & AR5K_TXERR_XRETRY)
Pavel Roskine0d687b2011-07-14 20:21:55 -04001689 ah->stats.txerr_retry++;
Bruno Randolf14404012010-09-17 11:36:51 +09001690 if (ts->ts_status & AR5K_TXERR_FIFO)
Pavel Roskine0d687b2011-07-14 20:21:55 -04001691 ah->stats.txerr_fifo++;
Bruno Randolf14404012010-09-17 11:36:51 +09001692 } else {
1693 info->flags |= IEEE80211_TX_STAT_ACK;
1694 info->status.ack_signal = ts->ts_rssi;
Felix Fietkau6d7b97b2011-04-09 21:37:14 +02001695
1696 /* count the successful attempt as well */
1697 info->status.rates[ts->ts_final_idx].count++;
Bruno Randolf14404012010-09-17 11:36:51 +09001698 }
1699
1700 /*
1701 * Remove MAC header padding before giving the frame
1702 * back to mac80211.
1703 */
1704 ath5k_remove_padding(skb);
1705
1706 if (ts->ts_antenna > 0 && ts->ts_antenna < 5)
Pavel Roskine0d687b2011-07-14 20:21:55 -04001707 ah->stats.antenna_tx[ts->ts_antenna]++;
Bruno Randolf14404012010-09-17 11:36:51 +09001708 else
Pavel Roskine0d687b2011-07-14 20:21:55 -04001709 ah->stats.antenna_tx[0]++; /* invalid */
Bruno Randolf14404012010-09-17 11:36:51 +09001710
Pavel Roskine0d687b2011-07-14 20:21:55 -04001711 trace_ath5k_tx_complete(ah, skb, txq, ts);
1712 ieee80211_tx_status(ah->hw, skb);
Bruno Randolf14404012010-09-17 11:36:51 +09001713}
Bob Copeland8a63fac2010-09-17 12:45:07 +09001714
Jiri Slabyfa1c1142007-08-12 17:33:16 +02001715static void
Pavel Roskine0d687b2011-07-14 20:21:55 -04001716ath5k_tx_processq(struct ath5k_hw *ah, struct ath5k_txq *txq)
Jiri Slabyfa1c1142007-08-12 17:33:16 +02001717{
Bruno Randolfb47f4072008-03-05 18:35:45 +09001718 struct ath5k_tx_status ts = {};
Jiri Slabyfa1c1142007-08-12 17:33:16 +02001719 struct ath5k_buf *bf, *bf0;
1720 struct ath5k_desc *ds;
1721 struct sk_buff *skb;
Bruno Randolf14404012010-09-17 11:36:51 +09001722 int ret;
Jiri Slabyfa1c1142007-08-12 17:33:16 +02001723
1724 spin_lock(&txq->lock);
1725 list_for_each_entry_safe(bf, bf0, &txq->q, list) {
Bruno Randolf23413292010-09-17 11:37:07 +09001726
1727 txq->txq_poll_mark = false;
1728
1729 /* skb might already have been processed last time. */
1730 if (bf->skb != NULL) {
1731 ds = bf->desc;
1732
Pavel Roskine0d687b2011-07-14 20:21:55 -04001733 ret = ah->ah_proc_tx_desc(ah, ds, &ts);
Bruno Randolf23413292010-09-17 11:37:07 +09001734 if (unlikely(ret == -EINPROGRESS))
1735 break;
1736 else if (unlikely(ret)) {
Pavel Roskine0d687b2011-07-14 20:21:55 -04001737 ATH5K_ERR(ah,
Bruno Randolf23413292010-09-17 11:37:07 +09001738 "error %d while processing "
1739 "queue %u\n", ret, txq->qnum);
1740 break;
1741 }
1742
1743 skb = bf->skb;
1744 bf->skb = NULL;
Felix Fietkauaeae4ac2010-12-02 10:26:51 +01001745
Pavel Roskine0d687b2011-07-14 20:21:55 -04001746 dma_unmap_single(ah->dev, bf->skbaddr, skb->len,
Felix Fietkauaeae4ac2010-12-02 10:26:51 +01001747 DMA_TO_DEVICE);
Thomas Huehn0967e012013-06-11 15:10:31 +02001748 ath5k_tx_frame_completed(ah, skb, txq, &ts, bf);
Bruno Randolf23413292010-09-17 11:37:07 +09001749 }
Jiri Slabyfa1c1142007-08-12 17:33:16 +02001750
Bob Copelanda05988b2010-04-07 23:55:58 -04001751 /*
1752 * It's possible that the hardware can say the buffer is
1753 * completed when it hasn't yet loaded the ds_link from
Bruno Randolf23413292010-09-17 11:37:07 +09001754 * host memory and moved on.
1755 * Always keep the last descriptor to avoid HW races...
Bob Copelanda05988b2010-04-07 23:55:58 -04001756 */
Pavel Roskine0d687b2011-07-14 20:21:55 -04001757 if (ath5k_hw_get_txdp(ah, txq->qnum) != bf->daddr) {
1758 spin_lock(&ah->txbuflock);
1759 list_move_tail(&bf->list, &ah->txbuf);
1760 ah->txbuf_len++;
Bruno Randolf23413292010-09-17 11:37:07 +09001761 txq->txq_len--;
Pavel Roskine0d687b2011-07-14 20:21:55 -04001762 spin_unlock(&ah->txbuflock);
Jiri Slabyfa1c1142007-08-12 17:33:16 +02001763 }
Jiri Slabyfa1c1142007-08-12 17:33:16 +02001764 }
Jiri Slabyfa1c1142007-08-12 17:33:16 +02001765 spin_unlock(&txq->lock);
Bruno Randolf4198a8d2010-10-05 13:27:17 +09001766 if (txq->txq_len < ATH5K_TXQ_LEN_LOW && txq->qnum < 4)
Pavel Roskine0d687b2011-07-14 20:21:55 -04001767 ieee80211_wake_queue(ah->hw, txq->qnum);
Jiri Slabyfa1c1142007-08-12 17:33:16 +02001768}
1769
1770static void
1771ath5k_tasklet_tx(unsigned long data)
1772{
Bob Copeland8784d2e2009-07-29 17:32:28 -04001773 int i;
Pavel Roskine0d687b2011-07-14 20:21:55 -04001774 struct ath5k_hw *ah = (void *)data;
Jiri Slabyfa1c1142007-08-12 17:33:16 +02001775
Pavel Roskine4bbf2f2011-07-07 18:14:13 -04001776 for (i = 0; i < AR5K_NUM_TX_QUEUES; i++)
Nick Kossifidis7ff7c822011-11-25 20:40:20 +02001777 if (ah->txqs[i].setup && (ah->ah_txq_isr_txok_all & BIT(i)))
Pavel Roskine0d687b2011-07-14 20:21:55 -04001778 ath5k_tx_processq(ah, &ah->txqs[i]);
Felix Fietkauc266c712011-04-10 18:32:19 +02001779
Pavel Roskine0d687b2011-07-14 20:21:55 -04001780 ah->tx_pending = false;
1781 ath5k_set_current_imask(ah);
Jiri Slabyfa1c1142007-08-12 17:33:16 +02001782}
1783
1784
Jiri Slabyfa1c1142007-08-12 17:33:16 +02001785/*****************\
1786* Beacon handling *
1787\*****************/
1788
1789/*
1790 * Setup the beacon frame for transmit.
1791 */
1792static int
Pavel Roskine0d687b2011-07-14 20:21:55 -04001793ath5k_beacon_setup(struct ath5k_hw *ah, struct ath5k_buf *bf)
Jiri Slabyfa1c1142007-08-12 17:33:16 +02001794{
1795 struct sk_buff *skb = bf->skb;
Johannes Berga888d522008-05-26 16:43:39 +02001796 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
Jiri Slabyfa1c1142007-08-12 17:33:16 +02001797 struct ath5k_desc *ds;
Nick Kossifidis2bed03e2009-04-30 15:55:49 -04001798 int ret = 0;
1799 u8 antenna;
Jiri Slabyfa1c1142007-08-12 17:33:16 +02001800 u32 flags;
Benoit Papillault8127fbd2010-02-27 23:05:26 +01001801 const int padsize = 0;
Jiri Slabyfa1c1142007-08-12 17:33:16 +02001802
Pavel Roskine0d687b2011-07-14 20:21:55 -04001803 bf->skbaddr = dma_map_single(ah->dev, skb->data, skb->len,
Felix Fietkauaeae4ac2010-12-02 10:26:51 +01001804 DMA_TO_DEVICE);
Pavel Roskine0d687b2011-07-14 20:21:55 -04001805 ATH5K_DBG(ah, ATH5K_DEBUG_BEACON, "skb %p [data %p len %u] "
Jiri Slabyfa1c1142007-08-12 17:33:16 +02001806 "skbaddr %llx\n", skb, skb->data, skb->len,
1807 (unsigned long long)bf->skbaddr);
Felix Fietkauaeae4ac2010-12-02 10:26:51 +01001808
Pavel Roskine0d687b2011-07-14 20:21:55 -04001809 if (dma_mapping_error(ah->dev, bf->skbaddr)) {
1810 ATH5K_ERR(ah, "beacon DMA mapping failed\n");
Bob Copelandbdc71bc2011-08-07 19:36:07 -04001811 dev_kfree_skb_any(skb);
1812 bf->skb = NULL;
Jiri Slabyfa1c1142007-08-12 17:33:16 +02001813 return -EIO;
1814 }
1815
1816 ds = bf->desc;
Nick Kossifidis2bed03e2009-04-30 15:55:49 -04001817 antenna = ah->ah_tx_ant;
Jiri Slabyfa1c1142007-08-12 17:33:16 +02001818
1819 flags = AR5K_TXDESC_NOACK;
Pavel Roskine0d687b2011-07-14 20:21:55 -04001820 if (ah->opmode == NL80211_IFTYPE_ADHOC && ath5k_hw_hasveol(ah)) {
Jiri Slabyfa1c1142007-08-12 17:33:16 +02001821 ds->ds_link = bf->daddr; /* self-linked */
1822 flags |= AR5K_TXDESC_VEOL;
Nick Kossifidis2bed03e2009-04-30 15:55:49 -04001823 } else
Jiri Slabyfa1c1142007-08-12 17:33:16 +02001824 ds->ds_link = 0;
Nick Kossifidis2bed03e2009-04-30 15:55:49 -04001825
1826 /*
1827 * If we use multiple antennas on AP and use
1828 * the Sectored AP scenario, switch antenna every
1829 * 4 beacons to make sure everybody hears our AP.
1830 * When a client tries to associate, hw will keep
1831 * track of the tx antenna to be used for this client
Pavel Roskin6a2a0e72011-07-09 00:17:51 -04001832 * automatically, based on ACKed packets.
Nick Kossifidis2bed03e2009-04-30 15:55:49 -04001833 *
1834 * Note: AP still listens and transmits RTS on the
1835 * default antenna which is supposed to be an omni.
1836 *
1837 * Note2: On sectored scenarios it's possible to have
Bob Copelanda180a132010-08-15 13:03:12 -04001838 * multiple antennas (1 omni -- the default -- and 14
1839 * sectors), so if we choose to actually support this
1840 * mode, we need to allow the user to set how many antennas
1841 * we have and tweak the code below to send beacons
1842 * on all of them.
Nick Kossifidis2bed03e2009-04-30 15:55:49 -04001843 */
1844 if (ah->ah_ant_mode == AR5K_ANTMODE_SECTOR_AP)
Pavel Roskine0d687b2011-07-14 20:21:55 -04001845 antenna = ah->bsent & 4 ? 2 : 1;
Nick Kossifidis2bed03e2009-04-30 15:55:49 -04001846
Jiri Slabyfa1c1142007-08-12 17:33:16 +02001847
Nick Kossifidis8f655dd2009-03-15 22:20:35 +02001848 /* FIXME: If we are in g mode and rate is a CCK rate
1849 * subtract ah->ah_txpower.txp_cck_ofdm_pwr_delta
1850 * from tx power (value is in dB units already) */
Jiri Slabyfa1c1142007-08-12 17:33:16 +02001851 ds->ds_data = bf->skbaddr;
Bruno Randolf281c56d2008-02-05 18:44:55 +09001852 ret = ah->ah_setup_tx_desc(ah, ds, skb->len,
Benoit Papillault8127fbd2010-02-27 23:05:26 +01001853 ieee80211_get_hdrlen_from_skb(skb), padsize,
Nick Kossifidis987af542012-08-05 22:35:36 +03001854 AR5K_PKT_TYPE_BEACON,
1855 (ah->ah_txpower.txp_requested * 2),
Pavel Roskine0d687b2011-07-14 20:21:55 -04001856 ieee80211_get_tx_rate(ah->hw, info)->hw_value,
Johannes Berg2e92e6f2008-05-15 12:55:27 +02001857 1, AR5K_TXKEYIX_INVALID,
Luis R. Rodriguez400ec452008-02-03 21:51:49 -05001858 antenna, flags, 0, 0);
Jiri Slabyfa1c1142007-08-12 17:33:16 +02001859 if (ret)
1860 goto err_unmap;
1861
1862 return 0;
1863err_unmap:
Pavel Roskine0d687b2011-07-14 20:21:55 -04001864 dma_unmap_single(ah->dev, bf->skbaddr, skb->len, DMA_TO_DEVICE);
Jiri Slabyfa1c1142007-08-12 17:33:16 +02001865 return ret;
1866}
1867
1868/*
Bob Copeland8a63fac2010-09-17 12:45:07 +09001869 * Updates the beacon that is sent by ath5k_beacon_send. For adhoc,
1870 * this is called only once at config_bss time, for AP we do it every
1871 * SWBA interrupt so that the TIM will reflect buffered frames.
1872 *
1873 * Called with the beacon lock.
1874 */
Bruno Randolfcd2c5482010-12-22 19:20:32 +09001875int
Bob Copeland8a63fac2010-09-17 12:45:07 +09001876ath5k_beacon_update(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
1877{
1878 int ret;
Pavel Roskine0d687b2011-07-14 20:21:55 -04001879 struct ath5k_hw *ah = hw->priv;
Wei Yongjun9c371f92012-10-08 08:42:58 +08001880 struct ath5k_vif *avf;
Bob Copeland8a63fac2010-09-17 12:45:07 +09001881 struct sk_buff *skb;
1882
1883 if (WARN_ON(!vif)) {
1884 ret = -EINVAL;
1885 goto out;
1886 }
1887
1888 skb = ieee80211_beacon_get(hw, vif);
1889
1890 if (!skb) {
1891 ret = -ENOMEM;
1892 goto out;
1893 }
1894
Wei Yongjun9c371f92012-10-08 08:42:58 +08001895 avf = (void *)vif->drv_priv;
Pavel Roskine0d687b2011-07-14 20:21:55 -04001896 ath5k_txbuf_free_skb(ah, avf->bbuf);
Ben Greearb1ae1ed2010-09-30 12:22:58 -07001897 avf->bbuf->skb = skb;
Pavel Roskine0d687b2011-07-14 20:21:55 -04001898 ret = ath5k_beacon_setup(ah, avf->bbuf);
Bob Copeland8a63fac2010-09-17 12:45:07 +09001899out:
1900 return ret;
1901}
1902
1903/*
Jiri Slabyfa1c1142007-08-12 17:33:16 +02001904 * Transmit a beacon frame at SWBA. Dynamic updates to the
1905 * frame contents are done as needed and the slot time is
1906 * also adjusted based on current state.
1907 *
Bob Copeland5faaff72010-07-13 11:32:40 -04001908 * This is called from software irq context (beacontq tasklets)
1909 * or user context from ath5k_beacon_config.
Jiri Slabyfa1c1142007-08-12 17:33:16 +02001910 */
1911static void
Pavel Roskine0d687b2011-07-14 20:21:55 -04001912ath5k_beacon_send(struct ath5k_hw *ah)
Jiri Slabyfa1c1142007-08-12 17:33:16 +02001913{
Ben Greearb1ae1ed2010-09-30 12:22:58 -07001914 struct ieee80211_vif *vif;
1915 struct ath5k_vif *avf;
1916 struct ath5k_buf *bf;
Bob Copelandcec8db22009-07-04 12:59:51 -04001917 struct sk_buff *skb;
Bob Copelandbdc71bc2011-08-07 19:36:07 -04001918 int err;
Jiri Slabyfa1c1142007-08-12 17:33:16 +02001919
Pavel Roskine0d687b2011-07-14 20:21:55 -04001920 ATH5K_DBG_UNLIMIT(ah, ATH5K_DEBUG_BEACON, "in beacon_send\n");
Jiri Slabyfa1c1142007-08-12 17:33:16 +02001921
Jiri Slabyfa1c1142007-08-12 17:33:16 +02001922 /*
1923 * Check if the previous beacon has gone out. If
Bob Copelanda180a132010-08-15 13:03:12 -04001924 * not, don't don't try to post another: skip this
Jiri Slabyfa1c1142007-08-12 17:33:16 +02001925 * period and wait for the next. Missed beacons
1926 * indicate a problem and should not occur. If we
1927 * miss too many consecutive beacons reset the device.
1928 */
Pavel Roskine0d687b2011-07-14 20:21:55 -04001929 if (unlikely(ath5k_hw_num_tx_pending(ah, ah->bhalq) != 0)) {
1930 ah->bmisscount++;
1931 ATH5K_DBG(ah, ATH5K_DEBUG_BEACON,
1932 "missed %u consecutive beacons\n", ah->bmisscount);
1933 if (ah->bmisscount > 10) { /* NB: 10 is a guess */
1934 ATH5K_DBG(ah, ATH5K_DEBUG_BEACON,
Jiri Slabyfa1c1142007-08-12 17:33:16 +02001935 "stuck beacon time (%u missed)\n",
Pavel Roskine0d687b2011-07-14 20:21:55 -04001936 ah->bmisscount);
1937 ATH5K_DBG(ah, ATH5K_DEBUG_RESET,
Bruno Randolf8d67a032010-06-16 19:11:12 +09001938 "stuck beacon, resetting\n");
Pavel Roskine0d687b2011-07-14 20:21:55 -04001939 ieee80211_queue_work(ah->hw, &ah->reset_work);
Jiri Slabyfa1c1142007-08-12 17:33:16 +02001940 }
1941 return;
1942 }
Pavel Roskine0d687b2011-07-14 20:21:55 -04001943 if (unlikely(ah->bmisscount != 0)) {
1944 ATH5K_DBG(ah, ATH5K_DEBUG_BEACON,
Jiri Slabyfa1c1142007-08-12 17:33:16 +02001945 "resume beacon xmit after %u misses\n",
Pavel Roskine0d687b2011-07-14 20:21:55 -04001946 ah->bmisscount);
1947 ah->bmisscount = 0;
Jiri Slabyfa1c1142007-08-12 17:33:16 +02001948 }
1949
Chun-Yeow Yeohda473b62012-03-03 09:48:56 +08001950 if ((ah->opmode == NL80211_IFTYPE_AP && ah->num_ap_vifs +
1951 ah->num_mesh_vifs > 1) ||
Pavel Roskine0d687b2011-07-14 20:21:55 -04001952 ah->opmode == NL80211_IFTYPE_MESH_POINT) {
Ben Greearb1ae1ed2010-09-30 12:22:58 -07001953 u64 tsf = ath5k_hw_get_tsf64(ah);
1954 u32 tsftu = TSF_TO_TU(tsf);
Pavel Roskine0d687b2011-07-14 20:21:55 -04001955 int slot = ((tsftu % ah->bintval) * ATH_BCBUF) / ah->bintval;
1956 vif = ah->bslot[(slot + 1) % ATH_BCBUF];
1957 ATH5K_DBG(ah, ATH5K_DEBUG_BEACON,
Ben Greearb1ae1ed2010-09-30 12:22:58 -07001958 "tsf %llx tsftu %x intval %u slot %u vif %p\n",
Pavel Roskine0d687b2011-07-14 20:21:55 -04001959 (unsigned long long)tsf, tsftu, ah->bintval, slot, vif);
Ben Greearb1ae1ed2010-09-30 12:22:58 -07001960 } else /* only one interface */
Pavel Roskine0d687b2011-07-14 20:21:55 -04001961 vif = ah->bslot[0];
Ben Greearb1ae1ed2010-09-30 12:22:58 -07001962
1963 if (!vif)
1964 return;
1965
1966 avf = (void *)vif->drv_priv;
1967 bf = avf->bbuf;
Ben Greearb1ae1ed2010-09-30 12:22:58 -07001968
Jiri Slabyfa1c1142007-08-12 17:33:16 +02001969 /*
1970 * Stop any current dma and put the new frame on the queue.
1971 * This should never fail since we check above that no frames
1972 * are still pending on the queue.
1973 */
Pavel Roskine0d687b2011-07-14 20:21:55 -04001974 if (unlikely(ath5k_hw_stop_beacon_queue(ah, ah->bhalq))) {
1975 ATH5K_WARN(ah, "beacon queue %u didn't start/stop ?\n", ah->bhalq);
Jiri Slabyfa1c1142007-08-12 17:33:16 +02001976 /* NB: hw still stops DMA, so proceed */
1977 }
Jiri Slabyfa1c1142007-08-12 17:33:16 +02001978
Javier Cardonad82b5772010-12-07 13:35:55 -08001979 /* refresh the beacon for AP or MESH mode */
Pavel Roskine0d687b2011-07-14 20:21:55 -04001980 if (ah->opmode == NL80211_IFTYPE_AP ||
Bob Copelandbdc71bc2011-08-07 19:36:07 -04001981 ah->opmode == NL80211_IFTYPE_MESH_POINT) {
1982 err = ath5k_beacon_update(ah->hw, vif);
1983 if (err)
1984 return;
1985 }
1986
1987 if (unlikely(bf->skb == NULL || ah->opmode == NL80211_IFTYPE_STATION ||
1988 ah->opmode == NL80211_IFTYPE_MONITOR)) {
1989 ATH5K_WARN(ah, "bf=%p bf_skb=%p\n", bf, bf->skb);
1990 return;
1991 }
Bob Copeland1071db82009-05-18 10:59:52 -04001992
Pavel Roskine0d687b2011-07-14 20:21:55 -04001993 trace_ath5k_tx(ah, bf->skb, &ah->txqs[ah->bhalq]);
Bob Copeland0e472252011-01-24 23:32:55 -05001994
Pavel Roskine0d687b2011-07-14 20:21:55 -04001995 ath5k_hw_set_txdp(ah, ah->bhalq, bf->daddr);
1996 ath5k_hw_start_tx_dma(ah, ah->bhalq);
1997 ATH5K_DBG(ah, ATH5K_DEBUG_BEACON, "TXDP[%u] = %llx (%p)\n",
1998 ah->bhalq, (unsigned long long)bf->daddr, bf->desc);
Jiri Slabyfa1c1142007-08-12 17:33:16 +02001999
Pavel Roskine0d687b2011-07-14 20:21:55 -04002000 skb = ieee80211_get_buffered_bc(ah->hw, vif);
Bob Copelandcec8db22009-07-04 12:59:51 -04002001 while (skb) {
Thomas Huehn0967e012013-06-11 15:10:31 +02002002 ath5k_tx_queue(ah->hw, skb, ah->cabq, NULL);
Felix Fietkau4e868792011-07-12 09:02:05 +08002003
Pavel Roskine0d687b2011-07-14 20:21:55 -04002004 if (ah->cabq->txq_len >= ah->cabq->txq_max)
Felix Fietkau4e868792011-07-12 09:02:05 +08002005 break;
2006
Pavel Roskine0d687b2011-07-14 20:21:55 -04002007 skb = ieee80211_get_buffered_bc(ah->hw, vif);
Bob Copelandcec8db22009-07-04 12:59:51 -04002008 }
2009
Pavel Roskine0d687b2011-07-14 20:21:55 -04002010 ah->bsent++;
Jiri Slabyfa1c1142007-08-12 17:33:16 +02002011}
2012
Bruno Randolf9804b982008-01-19 18:17:59 +09002013/**
2014 * ath5k_beacon_update_timers - update beacon timers
2015 *
Pavel Roskine0d687b2011-07-14 20:21:55 -04002016 * @ah: struct ath5k_hw pointer we are operating on
Bruno Randolf9804b982008-01-19 18:17:59 +09002017 * @bc_tsf: the timestamp of the beacon. 0 to reset the TSF. -1 to perform a
2018 * beacon timer update based on the current HW TSF.
2019 *
2020 * Calculate the next target beacon transmit time (TBTT) based on the timestamp
2021 * of a received beacon or the current local hardware TSF and write it to the
2022 * beacon timer registers.
2023 *
2024 * This is called in a variety of situations, e.g. when a beacon is received,
Bruno Randolf6ba81c22008-03-05 18:36:26 +09002025 * when a TSF update has been detected, but also when an new IBSS is created or
Bruno Randolf9804b982008-01-19 18:17:59 +09002026 * when we otherwise know we have to update the timers, but we keep it in this
2027 * function to have it all together in one place.
2028 */
Bruno Randolfcd2c5482010-12-22 19:20:32 +09002029void
Pavel Roskine0d687b2011-07-14 20:21:55 -04002030ath5k_beacon_update_timers(struct ath5k_hw *ah, u64 bc_tsf)
Jiri Slabyfa1c1142007-08-12 17:33:16 +02002031{
Bruno Randolf9804b982008-01-19 18:17:59 +09002032 u32 nexttbtt, intval, hw_tu, bc_tu;
2033 u64 hw_tsf;
Jiri Slabyfa1c1142007-08-12 17:33:16 +02002034
Pavel Roskine0d687b2011-07-14 20:21:55 -04002035 intval = ah->bintval & AR5K_BEACON_PERIOD;
Chun-Yeow Yeohda473b62012-03-03 09:48:56 +08002036 if (ah->opmode == NL80211_IFTYPE_AP && ah->num_ap_vifs
2037 + ah->num_mesh_vifs > 1) {
Ben Greearb1ae1ed2010-09-30 12:22:58 -07002038 intval /= ATH_BCBUF; /* staggered multi-bss beacons */
2039 if (intval < 15)
Pavel Roskine0d687b2011-07-14 20:21:55 -04002040 ATH5K_WARN(ah, "intval %u is too low, min 15\n",
Ben Greearb1ae1ed2010-09-30 12:22:58 -07002041 intval);
2042 }
Jiri Slabyfa1c1142007-08-12 17:33:16 +02002043 if (WARN_ON(!intval))
2044 return;
2045
Bruno Randolf9804b982008-01-19 18:17:59 +09002046 /* beacon TSF converted to TU */
2047 bc_tu = TSF_TO_TU(bc_tsf);
2048
Jiri Slabyfa1c1142007-08-12 17:33:16 +02002049 /* current TSF converted to TU */
Bruno Randolf9804b982008-01-19 18:17:59 +09002050 hw_tsf = ath5k_hw_get_tsf64(ah);
2051 hw_tu = TSF_TO_TU(hw_tsf);
Jiri Slabyfa1c1142007-08-12 17:33:16 +02002052
Pavel Roskin633d0062011-07-07 18:14:01 -04002053#define FUDGE (AR5K_TUNE_SW_BEACON_RESP + 3)
Bruno Randolf11f21df2010-09-27 12:22:26 +09002054 /* We use FUDGE to make sure the next TBTT is ahead of the current TU.
Lucas De Marchi25985ed2011-03-30 22:57:33 -03002055 * Since we later subtract AR5K_TUNE_SW_BEACON_RESP (10) in the timer
Bruno Randolf11f21df2010-09-27 12:22:26 +09002056 * configuration we need to make sure it is bigger than that. */
2057
Bruno Randolf9804b982008-01-19 18:17:59 +09002058 if (bc_tsf == -1) {
2059 /*
2060 * no beacons received, called internally.
2061 * just need to refresh timers based on HW TSF.
2062 */
2063 nexttbtt = roundup(hw_tu + FUDGE, intval);
2064 } else if (bc_tsf == 0) {
2065 /*
2066 * no beacon received, probably called by ath5k_reset_tsf().
2067 * reset TSF to start with 0.
2068 */
2069 nexttbtt = intval;
2070 intval |= AR5K_BEACON_RESET_TSF;
2071 } else if (bc_tsf > hw_tsf) {
2072 /*
Lucas De Marchi25985ed2011-03-30 22:57:33 -03002073 * beacon received, SW merge happened but HW TSF not yet updated.
Bruno Randolf9804b982008-01-19 18:17:59 +09002074 * not possible to reconfigure timers yet, but next time we
2075 * receive a beacon with the same BSSID, the hardware will
2076 * automatically update the TSF and then we need to reconfigure
2077 * the timers.
2078 */
Pavel Roskine0d687b2011-07-14 20:21:55 -04002079 ATH5K_DBG_UNLIMIT(ah, ATH5K_DEBUG_BEACON,
Bruno Randolf9804b982008-01-19 18:17:59 +09002080 "need to wait for HW TSF sync\n");
2081 return;
2082 } else {
2083 /*
2084 * most important case for beacon synchronization between STA.
2085 *
2086 * beacon received and HW TSF has been already updated by HW.
2087 * update next TBTT based on the TSF of the beacon, but make
2088 * sure it is ahead of our local TSF timer.
2089 */
2090 nexttbtt = bc_tu + roundup(hw_tu + FUDGE - bc_tu, intval);
2091 }
2092#undef FUDGE
Jiri Slabyfa1c1142007-08-12 17:33:16 +02002093
Pavel Roskine0d687b2011-07-14 20:21:55 -04002094 ah->nexttbtt = nexttbtt;
Bruno Randolf036cd1e2008-01-19 18:18:21 +09002095
Jiri Slabyfa1c1142007-08-12 17:33:16 +02002096 intval |= AR5K_BEACON_ENA;
Nick Kossifidisc47faa32011-11-25 20:40:25 +02002097 ath5k_hw_init_beacon_timers(ah, nexttbtt, intval);
Bruno Randolf9804b982008-01-19 18:17:59 +09002098
2099 /*
2100 * debugging output last in order to preserve the time critical aspect
2101 * of this function
2102 */
2103 if (bc_tsf == -1)
Pavel Roskine0d687b2011-07-14 20:21:55 -04002104 ATH5K_DBG_UNLIMIT(ah, ATH5K_DEBUG_BEACON,
Bruno Randolf9804b982008-01-19 18:17:59 +09002105 "reconfigured timers based on HW TSF\n");
2106 else if (bc_tsf == 0)
Pavel Roskine0d687b2011-07-14 20:21:55 -04002107 ATH5K_DBG_UNLIMIT(ah, ATH5K_DEBUG_BEACON,
Bruno Randolf9804b982008-01-19 18:17:59 +09002108 "reset HW TSF and timers\n");
2109 else
Pavel Roskine0d687b2011-07-14 20:21:55 -04002110 ATH5K_DBG_UNLIMIT(ah, ATH5K_DEBUG_BEACON,
Bruno Randolf9804b982008-01-19 18:17:59 +09002111 "updated timers based on beacon TSF\n");
2112
Pavel Roskine0d687b2011-07-14 20:21:55 -04002113 ATH5K_DBG_UNLIMIT(ah, ATH5K_DEBUG_BEACON,
David Miller04f93a82008-02-15 16:08:59 -08002114 "bc_tsf %llx hw_tsf %llx bc_tu %u hw_tu %u nexttbtt %u\n",
2115 (unsigned long long) bc_tsf,
2116 (unsigned long long) hw_tsf, bc_tu, hw_tu, nexttbtt);
Pavel Roskine0d687b2011-07-14 20:21:55 -04002117 ATH5K_DBG_UNLIMIT(ah, ATH5K_DEBUG_BEACON, "intval %u %s %s\n",
Bruno Randolf9804b982008-01-19 18:17:59 +09002118 intval & AR5K_BEACON_PERIOD,
2119 intval & AR5K_BEACON_ENA ? "AR5K_BEACON_ENA" : "",
2120 intval & AR5K_BEACON_RESET_TSF ? "AR5K_BEACON_RESET_TSF" : "");
Jiri Slabyfa1c1142007-08-12 17:33:16 +02002121}
2122
Bruno Randolf036cd1e2008-01-19 18:18:21 +09002123/**
2124 * ath5k_beacon_config - Configure the beacon queues and interrupts
2125 *
Pavel Roskine0d687b2011-07-14 20:21:55 -04002126 * @ah: struct ath5k_hw pointer we are operating on
Jiri Slabyfa1c1142007-08-12 17:33:16 +02002127 *
Bruno Randolf036cd1e2008-01-19 18:18:21 +09002128 * In IBSS mode we use a self-linked tx descriptor if possible. We enable SWBA
Bruno Randolf6ba81c22008-03-05 18:36:26 +09002129 * interrupts to detect TSF updates only.
Jiri Slabyfa1c1142007-08-12 17:33:16 +02002130 */
Bruno Randolfcd2c5482010-12-22 19:20:32 +09002131void
Pavel Roskine0d687b2011-07-14 20:21:55 -04002132ath5k_beacon_config(struct ath5k_hw *ah)
Jiri Slabyfa1c1142007-08-12 17:33:16 +02002133{
Bob Copeland7dd67532012-08-12 21:18:33 -04002134 spin_lock_bh(&ah->block);
Pavel Roskine0d687b2011-07-14 20:21:55 -04002135 ah->bmisscount = 0;
2136 ah->imask &= ~(AR5K_INT_BMISS | AR5K_INT_SWBA);
Jiri Slabyfa1c1142007-08-12 17:33:16 +02002137
Pavel Roskine0d687b2011-07-14 20:21:55 -04002138 if (ah->enable_beacon) {
Jiri Slabyfa1c1142007-08-12 17:33:16 +02002139 /*
Bruno Randolf036cd1e2008-01-19 18:18:21 +09002140 * In IBSS mode we use a self-linked tx descriptor and let the
2141 * hardware send the beacons automatically. We have to load it
Jiri Slabyfa1c1142007-08-12 17:33:16 +02002142 * only once here.
Bruno Randolf036cd1e2008-01-19 18:18:21 +09002143 * We use the SWBA interrupt only to keep track of the beacon
Bruno Randolf6ba81c22008-03-05 18:36:26 +09002144 * timers in order to detect automatic TSF updates.
Jiri Slabyfa1c1142007-08-12 17:33:16 +02002145 */
Pavel Roskine0d687b2011-07-14 20:21:55 -04002146 ath5k_beaconq_config(ah);
Jiri Slabyfa1c1142007-08-12 17:33:16 +02002147
Pavel Roskine0d687b2011-07-14 20:21:55 -04002148 ah->imask |= AR5K_INT_SWBA;
Bruno Randolf036cd1e2008-01-19 18:18:21 +09002149
Pavel Roskine0d687b2011-07-14 20:21:55 -04002150 if (ah->opmode == NL80211_IFTYPE_ADHOC) {
Bob Copeland21800492009-07-04 12:59:52 -04002151 if (ath5k_hw_hasveol(ah))
Pavel Roskine0d687b2011-07-14 20:21:55 -04002152 ath5k_beacon_send(ah);
Jiri Slabyda966bc2008-10-12 22:54:10 +02002153 } else
Pavel Roskine0d687b2011-07-14 20:21:55 -04002154 ath5k_beacon_update_timers(ah, -1);
Bob Copeland21800492009-07-04 12:59:52 -04002155 } else {
Pavel Roskine0d687b2011-07-14 20:21:55 -04002156 ath5k_hw_stop_beacon_queue(ah, ah->bhalq);
Jiri Slabyfa1c1142007-08-12 17:33:16 +02002157 }
Jiri Slabyfa1c1142007-08-12 17:33:16 +02002158
Pavel Roskine0d687b2011-07-14 20:21:55 -04002159 ath5k_hw_set_imr(ah, ah->imask);
Bob Copeland21800492009-07-04 12:59:52 -04002160 mmiowb();
Bob Copeland7dd67532012-08-12 21:18:33 -04002161 spin_unlock_bh(&ah->block);
Jiri Slabyfa1c1142007-08-12 17:33:16 +02002162}
2163
Nick Kossifidis428cbd42009-04-30 15:55:47 -04002164static void ath5k_tasklet_beacon(unsigned long data)
2165{
Pavel Roskine0d687b2011-07-14 20:21:55 -04002166 struct ath5k_hw *ah = (struct ath5k_hw *) data;
Nick Kossifidis428cbd42009-04-30 15:55:47 -04002167
2168 /*
2169 * Software beacon alert--time to send a beacon.
2170 *
2171 * In IBSS mode we use this interrupt just to
2172 * keep track of the next TBTT (target beacon
Pavel Roskin6a2a0e72011-07-09 00:17:51 -04002173 * transmission time) in order to detect whether
Nick Kossifidis428cbd42009-04-30 15:55:47 -04002174 * automatic TSF updates happened.
2175 */
Pavel Roskine0d687b2011-07-14 20:21:55 -04002176 if (ah->opmode == NL80211_IFTYPE_ADHOC) {
Pavel Roskin6a2a0e72011-07-09 00:17:51 -04002177 /* XXX: only if VEOL supported */
Pavel Roskine0d687b2011-07-14 20:21:55 -04002178 u64 tsf = ath5k_hw_get_tsf64(ah);
2179 ah->nexttbtt += ah->bintval;
2180 ATH5K_DBG(ah, ATH5K_DEBUG_BEACON,
Nick Kossifidis428cbd42009-04-30 15:55:47 -04002181 "SWBA nexttbtt: %x hw_tu: %x "
2182 "TSF: %llx\n",
Pavel Roskine0d687b2011-07-14 20:21:55 -04002183 ah->nexttbtt,
Nick Kossifidis428cbd42009-04-30 15:55:47 -04002184 TSF_TO_TU(tsf),
2185 (unsigned long long) tsf);
2186 } else {
Pavel Roskine0d687b2011-07-14 20:21:55 -04002187 spin_lock(&ah->block);
2188 ath5k_beacon_send(ah);
2189 spin_unlock(&ah->block);
Nick Kossifidis428cbd42009-04-30 15:55:47 -04002190 }
2191}
2192
Jiri Slabyfa1c1142007-08-12 17:33:16 +02002193
2194/********************\
2195* Interrupt handling *
2196\********************/
2197
Bruno Randolf6a8a3f62010-03-25 14:49:19 +09002198static void
2199ath5k_intr_calibration_poll(struct ath5k_hw *ah)
2200{
Bruno Randolf2111ac02010-04-02 18:44:08 +09002201 if (time_is_before_eq_jiffies(ah->ah_cal_next_ani) &&
Nick Kossifidisce169ac2011-11-25 20:40:23 +02002202 !(ah->ah_cal_mask & AR5K_CALIBRATION_FULL) &&
2203 !(ah->ah_cal_mask & AR5K_CALIBRATION_SHORT)) {
2204
2205 /* Run ANI only when calibration is not active */
2206
Bruno Randolf2111ac02010-04-02 18:44:08 +09002207 ah->ah_cal_next_ani = jiffies +
2208 msecs_to_jiffies(ATH5K_TUNE_CALIBRATION_INTERVAL_ANI);
Pavel Roskine0d687b2011-07-14 20:21:55 -04002209 tasklet_schedule(&ah->ani_tasklet);
Bruno Randolf2111ac02010-04-02 18:44:08 +09002210
Nick Kossifidisce169ac2011-11-25 20:40:23 +02002211 } else if (time_is_before_eq_jiffies(ah->ah_cal_next_short) &&
2212 !(ah->ah_cal_mask & AR5K_CALIBRATION_FULL) &&
2213 !(ah->ah_cal_mask & AR5K_CALIBRATION_SHORT)) {
2214
2215 /* Run calibration only when another calibration
2216 * is not running.
2217 *
2218 * Note: This is for both full/short calibration,
2219 * if it's time for a full one, ath5k_calibrate_work will deal
2220 * with it. */
2221
2222 ah->ah_cal_next_short = jiffies +
2223 msecs_to_jiffies(ATH5K_TUNE_CALIBRATION_INTERVAL_SHORT);
2224 ieee80211_queue_work(ah->hw, &ah->calib_work);
Bruno Randolf6a8a3f62010-03-25 14:49:19 +09002225 }
2226 /* we could use SWI to generate enough interrupts to meet our
2227 * calibration interval requirements, if necessary:
2228 * AR5K_REG_ENABLE_BITS(ah, AR5K_CR, AR5K_CR_SWI); */
2229}
2230
Felix Fietkauc266c712011-04-10 18:32:19 +02002231static void
Pavel Roskine0d687b2011-07-14 20:21:55 -04002232ath5k_schedule_rx(struct ath5k_hw *ah)
Felix Fietkauc266c712011-04-10 18:32:19 +02002233{
Pavel Roskine0d687b2011-07-14 20:21:55 -04002234 ah->rx_pending = true;
2235 tasklet_schedule(&ah->rxtq);
Felix Fietkauc266c712011-04-10 18:32:19 +02002236}
2237
2238static void
Pavel Roskine0d687b2011-07-14 20:21:55 -04002239ath5k_schedule_tx(struct ath5k_hw *ah)
Felix Fietkauc266c712011-04-10 18:32:19 +02002240{
Pavel Roskine0d687b2011-07-14 20:21:55 -04002241 ah->tx_pending = true;
2242 tasklet_schedule(&ah->txtq);
Felix Fietkauc266c712011-04-10 18:32:19 +02002243}
2244
Pavel Roskinf5cbc8b2011-06-15 18:03:22 -04002245static irqreturn_t
Jiri Slabyfa1c1142007-08-12 17:33:16 +02002246ath5k_intr(int irq, void *dev_id)
2247{
Pavel Roskine0d687b2011-07-14 20:21:55 -04002248 struct ath5k_hw *ah = dev_id;
Jiri Slabyfa1c1142007-08-12 17:33:16 +02002249 enum ath5k_int status;
2250 unsigned int counter = 1000;
2251
Nick Kossifidis34ce6442011-11-25 20:40:22 +02002252
2253 /*
2254 * If hw is not ready (or detached) and we get an
2255 * interrupt, or if we have no interrupts pending
2256 * (that means it's not for us) skip it.
2257 *
2258 * NOTE: Group 0/1 PCI interface registers are not
2259 * supported on WiSOCs, so we can't check for pending
2260 * interrupts (ISR belongs to another register group
2261 * so we are ok).
2262 */
Pavel Roskine0d687b2011-07-14 20:21:55 -04002263 if (unlikely(test_bit(ATH_STAT_INVALID, ah->status) ||
Nick Kossifidis34ce6442011-11-25 20:40:22 +02002264 ((ath5k_get_bus_type(ah) != ATH_AHB) &&
2265 !ath5k_hw_is_intr_pending(ah))))
Jiri Slabyfa1c1142007-08-12 17:33:16 +02002266 return IRQ_NONE;
2267
Nick Kossifidis34ce6442011-11-25 20:40:22 +02002268 /** Main loop **/
Jiri Slabyfa1c1142007-08-12 17:33:16 +02002269 do {
Nick Kossifidis34ce6442011-11-25 20:40:22 +02002270 ath5k_hw_get_isr(ah, &status); /* NB: clears IRQ too */
2271
Pavel Roskine0d687b2011-07-14 20:21:55 -04002272 ATH5K_DBG(ah, ATH5K_DEBUG_INTR, "status 0x%x/0x%x\n",
2273 status, ah->imask);
Nick Kossifidis34ce6442011-11-25 20:40:22 +02002274
2275 /*
2276 * Fatal hw error -> Log and reset
2277 *
2278 * Fatal errors are unrecoverable so we have to
2279 * reset the card. These errors include bus and
2280 * dma errors.
2281 */
Jiri Slabyfa1c1142007-08-12 17:33:16 +02002282 if (unlikely(status & AR5K_INT_FATAL)) {
Nick Kossifidis34ce6442011-11-25 20:40:22 +02002283
Pavel Roskine0d687b2011-07-14 20:21:55 -04002284 ATH5K_DBG(ah, ATH5K_DEBUG_RESET,
Bruno Randolf8d67a032010-06-16 19:11:12 +09002285 "fatal int, resetting\n");
Pavel Roskine0d687b2011-07-14 20:21:55 -04002286 ieee80211_queue_work(ah->hw, &ah->reset_work);
Nick Kossifidis34ce6442011-11-25 20:40:22 +02002287
2288 /*
2289 * RX Overrun -> Count and reset if needed
2290 *
2291 * Receive buffers are full. Either the bus is busy or
2292 * the CPU is not fast enough to process all received
2293 * frames.
2294 */
Jiri Slabyfa1c1142007-08-12 17:33:16 +02002295 } else if (unlikely(status & AR5K_INT_RXORN)) {
Nick Kossifidis34ce6442011-11-25 20:40:22 +02002296
Bruno Randolf87d77c42010-04-12 16:38:52 +09002297 /*
Bruno Randolf87d77c42010-04-12 16:38:52 +09002298 * Older chipsets need a reset to come out of this
2299 * condition, but we treat it as RX for newer chips.
Nick Kossifidis34ce6442011-11-25 20:40:22 +02002300 * We don't know exactly which versions need a reset
Bruno Randolf87d77c42010-04-12 16:38:52 +09002301 * this guess is copied from the HAL.
2302 */
Pavel Roskine0d687b2011-07-14 20:21:55 -04002303 ah->stats.rxorn_intr++;
Nick Kossifidis34ce6442011-11-25 20:40:22 +02002304
Bruno Randolf8d67a032010-06-16 19:11:12 +09002305 if (ah->ah_mac_srev < AR5K_SREV_AR5212) {
Pavel Roskine0d687b2011-07-14 20:21:55 -04002306 ATH5K_DBG(ah, ATH5K_DEBUG_RESET,
Bruno Randolf8d67a032010-06-16 19:11:12 +09002307 "rx overrun, resetting\n");
Pavel Roskine0d687b2011-07-14 20:21:55 -04002308 ieee80211_queue_work(ah->hw, &ah->reset_work);
Pavel Roskind2c7f772011-07-07 18:14:07 -04002309 } else
Pavel Roskine0d687b2011-07-14 20:21:55 -04002310 ath5k_schedule_rx(ah);
Nick Kossifidis34ce6442011-11-25 20:40:22 +02002311
Jiri Slabyfa1c1142007-08-12 17:33:16 +02002312 } else {
Nick Kossifidis34ce6442011-11-25 20:40:22 +02002313
2314 /* Software Beacon Alert -> Schedule beacon tasklet */
Pavel Roskind2c7f772011-07-07 18:14:07 -04002315 if (status & AR5K_INT_SWBA)
Pavel Roskine0d687b2011-07-14 20:21:55 -04002316 tasklet_hi_schedule(&ah->beacontq);
Pavel Roskind2c7f772011-07-07 18:14:07 -04002317
Nick Kossifidis34ce6442011-11-25 20:40:22 +02002318 /*
2319 * No more RX descriptors -> Just count
2320 *
2321 * NB: the hardware should re-read the link when
2322 * RXE bit is written, but it doesn't work at
2323 * least on older hardware revs.
2324 */
2325 if (status & AR5K_INT_RXEOL)
Pavel Roskine0d687b2011-07-14 20:21:55 -04002326 ah->stats.rxeol_intr++;
Nick Kossifidis34ce6442011-11-25 20:40:22 +02002327
2328
2329 /* TX Underrun -> Bump tx trigger level */
2330 if (status & AR5K_INT_TXURN)
Jiri Slabyfa1c1142007-08-12 17:33:16 +02002331 ath5k_hw_update_tx_triglevel(ah, true);
Nick Kossifidis34ce6442011-11-25 20:40:22 +02002332
2333 /* RX -> Schedule rx tasklet */
Nick Kossifidis4c674c62008-10-26 20:40:25 +02002334 if (status & (AR5K_INT_RXOK | AR5K_INT_RXERR))
Pavel Roskine0d687b2011-07-14 20:21:55 -04002335 ath5k_schedule_rx(ah);
Nick Kossifidis34ce6442011-11-25 20:40:22 +02002336
2337 /* TX -> Schedule tx tasklet */
2338 if (status & (AR5K_INT_TXOK
2339 | AR5K_INT_TXDESC
2340 | AR5K_INT_TXERR
2341 | AR5K_INT_TXEOL))
Pavel Roskine0d687b2011-07-14 20:21:55 -04002342 ath5k_schedule_tx(ah);
Nick Kossifidis34ce6442011-11-25 20:40:22 +02002343
2344 /* Missed beacon -> TODO
2345 if (status & AR5K_INT_BMISS)
2346 */
2347
2348 /* MIB event -> Update counters and notify ANI */
Jiri Slabyfa1c1142007-08-12 17:33:16 +02002349 if (status & AR5K_INT_MIB) {
Pavel Roskine0d687b2011-07-14 20:21:55 -04002350 ah->stats.mib_intr++;
Bruno Randolf495391d2010-03-25 14:49:36 +09002351 ath5k_hw_update_mib_counters(ah);
Bruno Randolf2111ac02010-04-02 18:44:08 +09002352 ath5k_ani_mib_intr(ah);
Jiri Slabyfa1c1142007-08-12 17:33:16 +02002353 }
Nick Kossifidis34ce6442011-11-25 20:40:22 +02002354
2355 /* GPIO -> Notify RFKill layer */
Tobias Doerffele6a3b612009-06-09 17:33:27 +02002356 if (status & AR5K_INT_GPIO)
Pavel Roskine0d687b2011-07-14 20:21:55 -04002357 tasklet_schedule(&ah->rf_kill.toggleq);
Bob Copelanda6ae0712009-06-09 23:43:11 -04002358
Jiri Slabyfa1c1142007-08-12 17:33:16 +02002359 }
Felix Fietkau4cebb342010-12-02 10:27:21 +01002360
2361 if (ath5k_get_bus_type(ah) == ATH_AHB)
2362 break;
2363
Bob Copeland2516baa2009-04-27 22:18:10 -04002364 } while (ath5k_hw_is_intr_pending(ah) && --counter > 0);
Jiri Slabyfa1c1142007-08-12 17:33:16 +02002365
Nick Kossifidis34ce6442011-11-25 20:40:22 +02002366 /*
2367 * Until we handle rx/tx interrupts mask them on IMR
2368 *
2369 * NOTE: ah->(rx/tx)_pending are set when scheduling the tasklets
2370 * and unset after we 've handled the interrupts.
2371 */
Pavel Roskine0d687b2011-07-14 20:21:55 -04002372 if (ah->rx_pending || ah->tx_pending)
2373 ath5k_set_current_imask(ah);
Felix Fietkauc266c712011-04-10 18:32:19 +02002374
Jiri Slabyfa1c1142007-08-12 17:33:16 +02002375 if (unlikely(!counter))
Pavel Roskine0d687b2011-07-14 20:21:55 -04002376 ATH5K_WARN(ah, "too many interrupts, giving up for now\n");
Jiri Slabyfa1c1142007-08-12 17:33:16 +02002377
Nick Kossifidis34ce6442011-11-25 20:40:22 +02002378 /* Fire up calibration poll */
Bruno Randolf6a8a3f62010-03-25 14:49:19 +09002379 ath5k_intr_calibration_poll(ah);
Nick Kossifidis6e2206622009-08-10 03:31:31 +03002380
Jiri Slabyfa1c1142007-08-12 17:33:16 +02002381 return IRQ_HANDLED;
2382}
2383
Jiri Slabyfa1c1142007-08-12 17:33:16 +02002384/*
2385 * Periodically recalibrate the PHY to account
2386 * for temperature/environment changes.
2387 */
2388static void
Nick Kossifidisce169ac2011-11-25 20:40:23 +02002389ath5k_calibrate_work(struct work_struct *work)
Jiri Slabyfa1c1142007-08-12 17:33:16 +02002390{
Nick Kossifidisce169ac2011-11-25 20:40:23 +02002391 struct ath5k_hw *ah = container_of(work, struct ath5k_hw,
2392 calib_work);
Jiri Slabyfa1c1142007-08-12 17:33:16 +02002393
Nick Kossifidisce169ac2011-11-25 20:40:23 +02002394 /* Should we run a full calibration ? */
2395 if (time_is_before_eq_jiffies(ah->ah_cal_next_full)) {
2396
2397 ah->ah_cal_next_full = jiffies +
2398 msecs_to_jiffies(ATH5K_TUNE_CALIBRATION_INTERVAL_FULL);
2399 ah->ah_cal_mask |= AR5K_CALIBRATION_FULL;
2400
2401 ATH5K_DBG(ah, ATH5K_DEBUG_CALIBRATE,
2402 "running full calibration\n");
2403
2404 if (ath5k_hw_gainf_calibrate(ah) == AR5K_RFGAIN_NEED_CHANGE) {
2405 /*
2406 * Rfgain is out of bounds, reset the chip
2407 * to load new gain values.
2408 */
2409 ATH5K_DBG(ah, ATH5K_DEBUG_RESET,
2410 "got new rfgain, resetting\n");
2411 ieee80211_queue_work(ah->hw, &ah->reset_work);
2412 }
Nick Kossifidisce169ac2011-11-25 20:40:23 +02002413 } else
2414 ah->ah_cal_mask |= AR5K_CALIBRATION_SHORT;
2415
Nick Kossifidis6e2206622009-08-10 03:31:31 +03002416
Pavel Roskine0d687b2011-07-14 20:21:55 -04002417 ATH5K_DBG(ah, ATH5K_DEBUG_CALIBRATE, "channel %u/%x\n",
2418 ieee80211_frequency_to_channel(ah->curchan->center_freq),
2419 ah->curchan->hw_value);
Jiri Slabyfa1c1142007-08-12 17:33:16 +02002420
Pavel Roskine0d687b2011-07-14 20:21:55 -04002421 if (ath5k_hw_phy_calibrate(ah, ah->curchan))
2422 ATH5K_ERR(ah, "calibration of channel %u failed\n",
Luis R. Rodriguez400ec452008-02-03 21:51:49 -05002423 ieee80211_frequency_to_channel(
Pavel Roskine0d687b2011-07-14 20:21:55 -04002424 ah->curchan->center_freq));
Jiri Slabyfa1c1142007-08-12 17:33:16 +02002425
Nick Kossifidisce169ac2011-11-25 20:40:23 +02002426 /* Clear calibration flags */
Felix Fietkau62e2c102012-03-06 11:06:37 +01002427 if (ah->ah_cal_mask & AR5K_CALIBRATION_FULL)
Nick Kossifidisce169ac2011-11-25 20:40:23 +02002428 ah->ah_cal_mask &= ~AR5K_CALIBRATION_FULL;
Felix Fietkau62e2c102012-03-06 11:06:37 +01002429 else if (ah->ah_cal_mask & AR5K_CALIBRATION_SHORT)
Nick Kossifidisce169ac2011-11-25 20:40:23 +02002430 ah->ah_cal_mask &= ~AR5K_CALIBRATION_SHORT;
Jiri Slabyfa1c1142007-08-12 17:33:16 +02002431}
2432
2433
Bruno Randolf2111ac02010-04-02 18:44:08 +09002434static void
2435ath5k_tasklet_ani(unsigned long data)
2436{
Pavel Roskine0d687b2011-07-14 20:21:55 -04002437 struct ath5k_hw *ah = (void *)data;
Bruno Randolf2111ac02010-04-02 18:44:08 +09002438
2439 ah->ah_cal_mask |= AR5K_CALIBRATION_ANI;
2440 ath5k_ani_calibration(ah);
2441 ah->ah_cal_mask &= ~AR5K_CALIBRATION_ANI;
Jiri Slabyfa1c1142007-08-12 17:33:16 +02002442}
2443
2444
Bruno Randolf4edd7612010-09-17 11:36:56 +09002445static void
2446ath5k_tx_complete_poll_work(struct work_struct *work)
2447{
Pavel Roskine0d687b2011-07-14 20:21:55 -04002448 struct ath5k_hw *ah = container_of(work, struct ath5k_hw,
Bruno Randolf4edd7612010-09-17 11:36:56 +09002449 tx_complete_work.work);
2450 struct ath5k_txq *txq;
2451 int i;
2452 bool needreset = false;
2453
Stanislaw Gruszkadb178342013-05-02 09:43:57 +02002454 if (!test_bit(ATH_STAT_STARTED, ah->status))
2455 return;
2456
Pavel Roskine0d687b2011-07-14 20:21:55 -04002457 mutex_lock(&ah->lock);
Bob Copeland599b13a2011-01-18 08:06:43 -05002458
Pavel Roskine0d687b2011-07-14 20:21:55 -04002459 for (i = 0; i < ARRAY_SIZE(ah->txqs); i++) {
2460 if (ah->txqs[i].setup) {
2461 txq = &ah->txqs[i];
Bruno Randolf4edd7612010-09-17 11:36:56 +09002462 spin_lock_bh(&txq->lock);
Bruno Randolf23413292010-09-17 11:37:07 +09002463 if (txq->txq_len > 1) {
Bruno Randolf4edd7612010-09-17 11:36:56 +09002464 if (txq->txq_poll_mark) {
Pavel Roskine0d687b2011-07-14 20:21:55 -04002465 ATH5K_DBG(ah, ATH5K_DEBUG_XMIT,
Bruno Randolf4edd7612010-09-17 11:36:56 +09002466 "TX queue stuck %d\n",
2467 txq->qnum);
2468 needreset = true;
Bruno Randolf923e5b32010-09-17 11:37:02 +09002469 txq->txq_stuck++;
Bruno Randolf4edd7612010-09-17 11:36:56 +09002470 spin_unlock_bh(&txq->lock);
2471 break;
2472 } else {
2473 txq->txq_poll_mark = true;
2474 }
2475 }
2476 spin_unlock_bh(&txq->lock);
2477 }
2478 }
2479
2480 if (needreset) {
Pavel Roskine0d687b2011-07-14 20:21:55 -04002481 ATH5K_DBG(ah, ATH5K_DEBUG_RESET,
Bruno Randolf4edd7612010-09-17 11:36:56 +09002482 "TX queues stuck, resetting\n");
Pavel Roskine0d687b2011-07-14 20:21:55 -04002483 ath5k_reset(ah, NULL, true);
Bruno Randolf4edd7612010-09-17 11:36:56 +09002484 }
2485
Pavel Roskine0d687b2011-07-14 20:21:55 -04002486 mutex_unlock(&ah->lock);
Bob Copeland599b13a2011-01-18 08:06:43 -05002487
Pavel Roskine0d687b2011-07-14 20:21:55 -04002488 ieee80211_queue_delayed_work(ah->hw, &ah->tx_complete_work,
Bruno Randolf4edd7612010-09-17 11:36:56 +09002489 msecs_to_jiffies(ATH5K_TX_COMPLETE_POLL_INT));
2490}
2491
2492
Bob Copeland8a63fac2010-09-17 12:45:07 +09002493/*************************\
2494* Initialization routines *
2495\*************************/
Jiri Slabyfa1c1142007-08-12 17:33:16 +02002496
Felix Fietkau9b4760e2012-04-17 00:39:27 -04002497static const struct ieee80211_iface_limit if_limits[] = {
2498 { .max = 2048, .types = BIT(NL80211_IFTYPE_STATION) },
2499 { .max = 4, .types =
2500#ifdef CONFIG_MAC80211_MESH
2501 BIT(NL80211_IFTYPE_MESH_POINT) |
2502#endif
2503 BIT(NL80211_IFTYPE_AP) },
2504};
2505
2506static const struct ieee80211_iface_combination if_comb = {
2507 .limits = if_limits,
2508 .n_limits = ARRAY_SIZE(if_limits),
2509 .max_interfaces = 2048,
2510 .num_different_channels = 1,
2511};
2512
Bill Pembertone829cf92012-12-03 09:56:28 -05002513int
Pavel Roskinbb1f3ad2011-07-26 22:27:05 -04002514ath5k_init_ah(struct ath5k_hw *ah, const struct ath_bus_ops *bus_ops)
Felix Fietkau132b1c32010-12-02 10:26:56 +01002515{
Pavel Roskine0d687b2011-07-14 20:21:55 -04002516 struct ieee80211_hw *hw = ah->hw;
Felix Fietkau132b1c32010-12-02 10:26:56 +01002517 struct ath_common *common;
2518 int ret;
2519 int csz;
2520
2521 /* Initialize driver private data */
Pavel Roskine0d687b2011-07-14 20:21:55 -04002522 SET_IEEE80211_DEV(hw, ah->dev);
Felix Fietkau132b1c32010-12-02 10:26:56 +01002523 hw->flags = IEEE80211_HW_RX_INCLUDES_FCS |
Nick Kossifidisb9e61f12010-12-03 06:12:39 +02002524 IEEE80211_HW_HOST_BROADCAST_PS_BUFFERING |
2525 IEEE80211_HW_SIGNAL_DBM |
Chun-Yeow Yeoh90e62742012-09-14 18:26:11 +08002526 IEEE80211_HW_MFP_CAPABLE |
Thomas Huehn0967e012013-06-11 15:10:31 +02002527 IEEE80211_HW_REPORTS_TX_ACK_STATUS |
2528 IEEE80211_HW_SUPPORTS_RC_TABLE;
Felix Fietkau132b1c32010-12-02 10:26:56 +01002529
2530 hw->wiphy->interface_modes =
2531 BIT(NL80211_IFTYPE_AP) |
2532 BIT(NL80211_IFTYPE_STATION) |
2533 BIT(NL80211_IFTYPE_ADHOC) |
2534 BIT(NL80211_IFTYPE_MESH_POINT);
2535
Felix Fietkau9b4760e2012-04-17 00:39:27 -04002536 hw->wiphy->iface_combinations = &if_comb;
2537 hw->wiphy->n_iface_combinations = 1;
2538
Antonio Quartullif9972572012-01-14 11:42:43 +01002539 /* SW support for IBSS_RSN is provided by mac80211 */
2540 hw->wiphy->flags |= WIPHY_FLAG_IBSS_RSN;
2541
Simon Wunderlich4d70f2f2013-08-14 08:01:37 +02002542 hw->wiphy->flags |= WIPHY_FLAG_SUPPORTS_5_10_MHZ;
2543
Bruno Randolf3de135d2010-12-16 11:30:33 +09002544 /* both antennas can be configured as RX or TX */
2545 hw->wiphy->available_antennas_tx = 0x3;
2546 hw->wiphy->available_antennas_rx = 0x3;
2547
Felix Fietkau132b1c32010-12-02 10:26:56 +01002548 hw->extra_tx_headroom = 2;
Felix Fietkau132b1c32010-12-02 10:26:56 +01002549
2550 /*
2551 * Mark the device as detached to avoid processing
2552 * interrupts until setup is complete.
2553 */
Pavel Roskine0d687b2011-07-14 20:21:55 -04002554 __set_bit(ATH_STAT_INVALID, ah->status);
Felix Fietkau132b1c32010-12-02 10:26:56 +01002555
Pavel Roskine0d687b2011-07-14 20:21:55 -04002556 ah->opmode = NL80211_IFTYPE_STATION;
2557 ah->bintval = 1000;
2558 mutex_init(&ah->lock);
2559 spin_lock_init(&ah->rxbuflock);
2560 spin_lock_init(&ah->txbuflock);
2561 spin_lock_init(&ah->block);
2562 spin_lock_init(&ah->irqlock);
Felix Fietkau132b1c32010-12-02 10:26:56 +01002563
2564 /* Setup interrupt handler */
Pavel Roskine0d687b2011-07-14 20:21:55 -04002565 ret = request_irq(ah->irq, ath5k_intr, IRQF_SHARED, "ath", ah);
Felix Fietkau132b1c32010-12-02 10:26:56 +01002566 if (ret) {
Pavel Roskine0d687b2011-07-14 20:21:55 -04002567 ATH5K_ERR(ah, "request_irq failed\n");
Felix Fietkau132b1c32010-12-02 10:26:56 +01002568 goto err;
2569 }
2570
Pavel Roskine0d687b2011-07-14 20:21:55 -04002571 common = ath5k_hw_common(ah);
Felix Fietkau132b1c32010-12-02 10:26:56 +01002572 common->ops = &ath5k_common_ops;
2573 common->bus_ops = bus_ops;
Pavel Roskine0d687b2011-07-14 20:21:55 -04002574 common->ah = ah;
Felix Fietkau132b1c32010-12-02 10:26:56 +01002575 common->hw = hw;
Pavel Roskine0d687b2011-07-14 20:21:55 -04002576 common->priv = ah;
Felix Fietkau26d16d22011-07-12 09:02:01 +08002577 common->clockrate = 40;
Felix Fietkau132b1c32010-12-02 10:26:56 +01002578
2579 /*
2580 * Cache line size is used to size and align various
2581 * structures used to communicate with the hardware.
2582 */
2583 ath5k_read_cachesize(common, &csz);
2584 common->cachelsz = csz << 2; /* convert to bytes */
2585
2586 spin_lock_init(&common->cc_lock);
2587
2588 /* Initialize device */
Pavel Roskine0d687b2011-07-14 20:21:55 -04002589 ret = ath5k_hw_init(ah);
Felix Fietkau132b1c32010-12-02 10:26:56 +01002590 if (ret)
Pavel Roskine0d687b2011-07-14 20:21:55 -04002591 goto err_irq;
Felix Fietkau132b1c32010-12-02 10:26:56 +01002592
Nick Kossifidis86f62d92011-11-25 20:40:28 +02002593 /* Set up multi-rate retry capabilities */
2594 if (ah->ah_capabilities.cap_has_mrr_support) {
Felix Fietkau132b1c32010-12-02 10:26:56 +01002595 hw->max_rates = 4;
Bruno Randolf76a9f6f2011-01-28 16:52:11 +09002596 hw->max_rate_tries = max(AR5K_INIT_RETRY_SHORT,
2597 AR5K_INIT_RETRY_LONG);
Felix Fietkau132b1c32010-12-02 10:26:56 +01002598 }
2599
2600 hw->vif_data_size = sizeof(struct ath5k_vif);
2601
2602 /* Finish private driver data initialization */
2603 ret = ath5k_init(hw);
2604 if (ret)
2605 goto err_ah;
2606
Pavel Roskine0d687b2011-07-14 20:21:55 -04002607 ATH5K_INFO(ah, "Atheros AR%s chip found (MAC: 0x%x, PHY: 0x%x)\n",
2608 ath5k_chip_name(AR5K_VERSION_MAC, ah->ah_mac_srev),
2609 ah->ah_mac_srev,
2610 ah->ah_phy_revision);
Felix Fietkau132b1c32010-12-02 10:26:56 +01002611
Pavel Roskine0d687b2011-07-14 20:21:55 -04002612 if (!ah->ah_single_chip) {
Felix Fietkau132b1c32010-12-02 10:26:56 +01002613 /* Single chip radio (!RF5111) */
Pavel Roskine0d687b2011-07-14 20:21:55 -04002614 if (ah->ah_radio_5ghz_revision &&
2615 !ah->ah_radio_2ghz_revision) {
Felix Fietkau132b1c32010-12-02 10:26:56 +01002616 /* No 5GHz support -> report 2GHz radio */
2617 if (!test_bit(AR5K_MODE_11A,
Pavel Roskine0d687b2011-07-14 20:21:55 -04002618 ah->ah_capabilities.cap_mode)) {
2619 ATH5K_INFO(ah, "RF%s 2GHz radio found (0x%x)\n",
Felix Fietkau132b1c32010-12-02 10:26:56 +01002620 ath5k_chip_name(AR5K_VERSION_RAD,
Pavel Roskine0d687b2011-07-14 20:21:55 -04002621 ah->ah_radio_5ghz_revision),
2622 ah->ah_radio_5ghz_revision);
Felix Fietkau132b1c32010-12-02 10:26:56 +01002623 /* No 2GHz support (5110 and some
Pavel Roskin6a2a0e72011-07-09 00:17:51 -04002624 * 5GHz only cards) -> report 5GHz radio */
Felix Fietkau132b1c32010-12-02 10:26:56 +01002625 } else if (!test_bit(AR5K_MODE_11B,
Pavel Roskine0d687b2011-07-14 20:21:55 -04002626 ah->ah_capabilities.cap_mode)) {
2627 ATH5K_INFO(ah, "RF%s 5GHz radio found (0x%x)\n",
Felix Fietkau132b1c32010-12-02 10:26:56 +01002628 ath5k_chip_name(AR5K_VERSION_RAD,
Pavel Roskine0d687b2011-07-14 20:21:55 -04002629 ah->ah_radio_5ghz_revision),
2630 ah->ah_radio_5ghz_revision);
Felix Fietkau132b1c32010-12-02 10:26:56 +01002631 /* Multiband radio */
2632 } else {
Pavel Roskine0d687b2011-07-14 20:21:55 -04002633 ATH5K_INFO(ah, "RF%s multiband radio found"
Felix Fietkau132b1c32010-12-02 10:26:56 +01002634 " (0x%x)\n",
2635 ath5k_chip_name(AR5K_VERSION_RAD,
Pavel Roskine0d687b2011-07-14 20:21:55 -04002636 ah->ah_radio_5ghz_revision),
2637 ah->ah_radio_5ghz_revision);
Felix Fietkau132b1c32010-12-02 10:26:56 +01002638 }
2639 }
2640 /* Multi chip radio (RF5111 - RF2111) ->
2641 * report both 2GHz/5GHz radios */
Pavel Roskine0d687b2011-07-14 20:21:55 -04002642 else if (ah->ah_radio_5ghz_revision &&
2643 ah->ah_radio_2ghz_revision) {
2644 ATH5K_INFO(ah, "RF%s 5GHz radio found (0x%x)\n",
Felix Fietkau132b1c32010-12-02 10:26:56 +01002645 ath5k_chip_name(AR5K_VERSION_RAD,
Pavel Roskine0d687b2011-07-14 20:21:55 -04002646 ah->ah_radio_5ghz_revision),
2647 ah->ah_radio_5ghz_revision);
2648 ATH5K_INFO(ah, "RF%s 2GHz radio found (0x%x)\n",
Felix Fietkau132b1c32010-12-02 10:26:56 +01002649 ath5k_chip_name(AR5K_VERSION_RAD,
Pavel Roskine0d687b2011-07-14 20:21:55 -04002650 ah->ah_radio_2ghz_revision),
2651 ah->ah_radio_2ghz_revision);
Felix Fietkau132b1c32010-12-02 10:26:56 +01002652 }
2653 }
2654
Pavel Roskine0d687b2011-07-14 20:21:55 -04002655 ath5k_debug_init_device(ah);
Felix Fietkau132b1c32010-12-02 10:26:56 +01002656
2657 /* ready to process interrupts */
Pavel Roskine0d687b2011-07-14 20:21:55 -04002658 __clear_bit(ATH_STAT_INVALID, ah->status);
Felix Fietkau132b1c32010-12-02 10:26:56 +01002659
2660 return 0;
2661err_ah:
Pavel Roskine0d687b2011-07-14 20:21:55 -04002662 ath5k_hw_deinit(ah);
Felix Fietkau132b1c32010-12-02 10:26:56 +01002663err_irq:
Pavel Roskine0d687b2011-07-14 20:21:55 -04002664 free_irq(ah->irq, ah);
Felix Fietkau132b1c32010-12-02 10:26:56 +01002665err:
2666 return ret;
2667}
2668
Jiri Slabyfa1c1142007-08-12 17:33:16 +02002669static int
Pavel Roskine0d687b2011-07-14 20:21:55 -04002670ath5k_stop_locked(struct ath5k_hw *ah)
Jiri Slabyfa1c1142007-08-12 17:33:16 +02002671{
Bob Copelandcec8db22009-07-04 12:59:51 -04002672
Pavel Roskine0d687b2011-07-14 20:21:55 -04002673 ATH5K_DBG(ah, ATH5K_DEBUG_RESET, "invalid %u\n",
2674 test_bit(ATH_STAT_INVALID, ah->status));
Jiri Slabyfa1c1142007-08-12 17:33:16 +02002675
Jiri Slabyfa1c1142007-08-12 17:33:16 +02002676 /*
Bob Copeland8a63fac2010-09-17 12:45:07 +09002677 * Shutdown the hardware and driver:
2678 * stop output from above
2679 * disable interrupts
2680 * turn off timers
2681 * turn off the radio
2682 * clear transmit machinery
2683 * clear receive machinery
2684 * drain and release tx queues
2685 * reclaim beacon resources
2686 * power down hardware
2687 *
2688 * Note that some of this work is not possible if the
2689 * hardware is gone (invalid).
Jiri Slabyfa1c1142007-08-12 17:33:16 +02002690 */
Pavel Roskine0d687b2011-07-14 20:21:55 -04002691 ieee80211_stop_queues(ah->hw);
Bob Copeland8a63fac2010-09-17 12:45:07 +09002692
Pavel Roskine0d687b2011-07-14 20:21:55 -04002693 if (!test_bit(ATH_STAT_INVALID, ah->status)) {
2694 ath5k_led_off(ah);
Bob Copeland8a63fac2010-09-17 12:45:07 +09002695 ath5k_hw_set_imr(ah, 0);
Pavel Roskine0d687b2011-07-14 20:21:55 -04002696 synchronize_irq(ah->irq);
2697 ath5k_rx_stop(ah);
Nick Kossifidis80dac9e2010-11-23 20:45:38 +02002698 ath5k_hw_dma_stop(ah);
Pavel Roskine0d687b2011-07-14 20:21:55 -04002699 ath5k_drain_tx_buffs(ah);
Bob Copeland8a63fac2010-09-17 12:45:07 +09002700 ath5k_hw_phy_disable(ah);
Jiri Slabyfa1c1142007-08-12 17:33:16 +02002701 }
2702
Bob Copeland8a63fac2010-09-17 12:45:07 +09002703 return 0;
2704}
2705
Pavel Roskinfabba042011-07-21 13:36:28 -04002706int ath5k_start(struct ieee80211_hw *hw)
Bob Copeland8a63fac2010-09-17 12:45:07 +09002707{
Pavel Roskinfabba042011-07-21 13:36:28 -04002708 struct ath5k_hw *ah = hw->priv;
Bob Copeland8a63fac2010-09-17 12:45:07 +09002709 struct ath_common *common = ath5k_hw_common(ah);
2710 int ret, i;
2711
Pavel Roskine0d687b2011-07-14 20:21:55 -04002712 mutex_lock(&ah->lock);
Bob Copeland8a63fac2010-09-17 12:45:07 +09002713
Pavel Roskine0d687b2011-07-14 20:21:55 -04002714 ATH5K_DBG(ah, ATH5K_DEBUG_RESET, "mode %d\n", ah->opmode);
Bob Copeland8a63fac2010-09-17 12:45:07 +09002715
2716 /*
2717 * Stop anything previously setup. This is safe
2718 * no matter this is the first time through or not.
2719 */
Pavel Roskine0d687b2011-07-14 20:21:55 -04002720 ath5k_stop_locked(ah);
Bob Copeland8a63fac2010-09-17 12:45:07 +09002721
2722 /*
2723 * The basic interface to setting the hardware in a good
2724 * state is ``reset''. On return the hardware is known to
2725 * be powered up and with interrupts disabled. This must
2726 * be followed by initialization of the appropriate bits
2727 * and then setup of the interrupt mask.
2728 */
Karl Beldan675a0b02013-03-25 16:26:57 +01002729 ah->curchan = ah->hw->conf.chandef.chan;
Nick Kossifidis34ce6442011-11-25 20:40:22 +02002730 ah->imask = AR5K_INT_RXOK
2731 | AR5K_INT_RXERR
2732 | AR5K_INT_RXEOL
2733 | AR5K_INT_RXORN
2734 | AR5K_INT_TXDESC
2735 | AR5K_INT_TXEOL
2736 | AR5K_INT_FATAL
2737 | AR5K_INT_GLOBAL
2738 | AR5K_INT_MIB;
Bob Copeland8a63fac2010-09-17 12:45:07 +09002739
Pavel Roskine0d687b2011-07-14 20:21:55 -04002740 ret = ath5k_reset(ah, NULL, false);
Bob Copeland8a63fac2010-09-17 12:45:07 +09002741 if (ret)
2742 goto done;
2743
Nick Kossifidis84e1e732011-11-25 20:40:27 +02002744 if (!ath5k_modparam_no_hw_rfkill_switch)
2745 ath5k_rfkill_hw_start(ah);
Bob Copeland8a63fac2010-09-17 12:45:07 +09002746
2747 /*
2748 * Reset the key cache since some parts do not reset the
2749 * contents on initial power up or resume from suspend.
2750 */
2751 for (i = 0; i < common->keymax; i++)
2752 ath_hw_keyreset(common, (u16) i);
2753
Nick Kossifidis61cde032010-11-23 21:12:23 +02002754 /* Use higher rates for acks instead of base
2755 * rate */
2756 ah->ah_ack_bitrate_high = true;
Ben Greearb1ae1ed2010-09-30 12:22:58 -07002757
Pavel Roskine0d687b2011-07-14 20:21:55 -04002758 for (i = 0; i < ARRAY_SIZE(ah->bslot); i++)
2759 ah->bslot[i] = NULL;
Ben Greearb1ae1ed2010-09-30 12:22:58 -07002760
Bob Copeland8a63fac2010-09-17 12:45:07 +09002761 ret = 0;
2762done:
2763 mmiowb();
Pavel Roskine0d687b2011-07-14 20:21:55 -04002764 mutex_unlock(&ah->lock);
Bruno Randolf4edd7612010-09-17 11:36:56 +09002765
Stanislaw Gruszkadb178342013-05-02 09:43:57 +02002766 set_bit(ATH_STAT_STARTED, ah->status);
Pavel Roskine0d687b2011-07-14 20:21:55 -04002767 ieee80211_queue_delayed_work(ah->hw, &ah->tx_complete_work,
Bruno Randolf4edd7612010-09-17 11:36:56 +09002768 msecs_to_jiffies(ATH5K_TX_COMPLETE_POLL_INT));
2769
Bob Copeland8a63fac2010-09-17 12:45:07 +09002770 return ret;
2771}
2772
Pavel Roskine0d687b2011-07-14 20:21:55 -04002773static void ath5k_stop_tasklets(struct ath5k_hw *ah)
Bob Copeland8a63fac2010-09-17 12:45:07 +09002774{
Pavel Roskine0d687b2011-07-14 20:21:55 -04002775 ah->rx_pending = false;
2776 ah->tx_pending = false;
2777 tasklet_kill(&ah->rxtq);
2778 tasklet_kill(&ah->txtq);
Pavel Roskine0d687b2011-07-14 20:21:55 -04002779 tasklet_kill(&ah->beacontq);
2780 tasklet_kill(&ah->ani_tasklet);
Bob Copeland8a63fac2010-09-17 12:45:07 +09002781}
2782
2783/*
2784 * Stop the device, grabbing the top-level lock to protect
2785 * against concurrent entry through ath5k_init (which can happen
2786 * if another thread does a system call and the thread doing the
2787 * stop is preempted).
2788 */
Pavel Roskinfabba042011-07-21 13:36:28 -04002789void ath5k_stop(struct ieee80211_hw *hw)
Bob Copeland8a63fac2010-09-17 12:45:07 +09002790{
Pavel Roskinfabba042011-07-21 13:36:28 -04002791 struct ath5k_hw *ah = hw->priv;
Bob Copeland8a63fac2010-09-17 12:45:07 +09002792 int ret;
2793
Pavel Roskine0d687b2011-07-14 20:21:55 -04002794 mutex_lock(&ah->lock);
2795 ret = ath5k_stop_locked(ah);
2796 if (ret == 0 && !test_bit(ATH_STAT_INVALID, ah->status)) {
Bob Copeland8a63fac2010-09-17 12:45:07 +09002797 /*
2798 * Don't set the card in full sleep mode!
2799 *
2800 * a) When the device is in this state it must be carefully
2801 * woken up or references to registers in the PCI clock
2802 * domain may freeze the bus (and system). This varies
2803 * by chip and is mostly an issue with newer parts
2804 * (madwifi sources mentioned srev >= 0x78) that go to
2805 * sleep more quickly.
2806 *
2807 * b) On older chips full sleep results a weird behaviour
2808 * during wakeup. I tested various cards with srev < 0x78
2809 * and they don't wake up after module reload, a second
2810 * module reload is needed to bring the card up again.
2811 *
2812 * Until we figure out what's going on don't enable
2813 * full chip reset on any chip (this is what Legacy HAL
2814 * and Sam's HAL do anyway). Instead Perform a full reset
2815 * on the device (same as initial state after attach) and
2816 * leave it idle (keep MAC/BB on warm reset) */
Pavel Roskine0d687b2011-07-14 20:21:55 -04002817 ret = ath5k_hw_on_hold(ah);
Bob Copeland8a63fac2010-09-17 12:45:07 +09002818
Pavel Roskine0d687b2011-07-14 20:21:55 -04002819 ATH5K_DBG(ah, ATH5K_DEBUG_RESET,
Bob Copeland8a63fac2010-09-17 12:45:07 +09002820 "putting device to sleep\n");
Jiri Slabyfa1c1142007-08-12 17:33:16 +02002821 }
Jiri Slabyfa1c1142007-08-12 17:33:16 +02002822
Bob Copeland8a63fac2010-09-17 12:45:07 +09002823 mmiowb();
Pavel Roskine0d687b2011-07-14 20:21:55 -04002824 mutex_unlock(&ah->lock);
Jiri Slabyfa1c1142007-08-12 17:33:16 +02002825
Pavel Roskine0d687b2011-07-14 20:21:55 -04002826 ath5k_stop_tasklets(ah);
Jiri Slabyfa1c1142007-08-12 17:33:16 +02002827
Stanislaw Gruszkadb178342013-05-02 09:43:57 +02002828 clear_bit(ATH_STAT_STARTED, ah->status);
Pavel Roskine0d687b2011-07-14 20:21:55 -04002829 cancel_delayed_work_sync(&ah->tx_complete_work);
Bruno Randolf4edd7612010-09-17 11:36:56 +09002830
Nick Kossifidis84e1e732011-11-25 20:40:27 +02002831 if (!ath5k_modparam_no_hw_rfkill_switch)
2832 ath5k_rfkill_hw_stop(ah);
Jiri Slabyfa1c1142007-08-12 17:33:16 +02002833}
2834
Bob Copeland209d8892009-05-07 08:09:08 -04002835/*
2836 * Reset the hardware. If chan is not NULL, then also pause rx/tx
2837 * and change to the given channel.
Bob Copeland5faaff72010-07-13 11:32:40 -04002838 *
Pavel Roskine0d687b2011-07-14 20:21:55 -04002839 * This should be called with ah->lock.
Bob Copeland209d8892009-05-07 08:09:08 -04002840 */
Jiri Slabyfa1c1142007-08-12 17:33:16 +02002841static int
Pavel Roskine0d687b2011-07-14 20:21:55 -04002842ath5k_reset(struct ath5k_hw *ah, struct ieee80211_channel *chan,
Nick Kossifidis8aec7af2010-11-23 21:39:28 +02002843 bool skip_pcu)
Jiri Slabyfa1c1142007-08-12 17:33:16 +02002844{
Bruno Randolff15a4bb2010-12-16 16:22:20 +09002845 struct ath_common *common = ath5k_hw_common(ah);
Nick Kossifidis344b54b2010-12-03 06:07:13 +02002846 int ret, ani_mode;
Nick Kossifidisa99168e2011-06-02 03:09:48 +03002847 bool fast;
Jiri Slabyfa1c1142007-08-12 17:33:16 +02002848
Pavel Roskine0d687b2011-07-14 20:21:55 -04002849 ATH5K_DBG(ah, ATH5K_DEBUG_RESET, "resetting\n");
Jiri Slabyfa1c1142007-08-12 17:33:16 +02002850
Bob Copeland450464d2010-07-13 11:32:41 -04002851 ath5k_hw_set_imr(ah, 0);
Pavel Roskine0d687b2011-07-14 20:21:55 -04002852 synchronize_irq(ah->irq);
2853 ath5k_stop_tasklets(ah);
Bob Copeland450464d2010-07-13 11:32:41 -04002854
Lucas De Marchi25985ed2011-03-30 22:57:33 -03002855 /* Save ani mode and disable ANI during
Nick Kossifidis344b54b2010-12-03 06:07:13 +02002856 * reset. If we don't we might get false
2857 * PHY error interrupts. */
Pavel Roskine0d687b2011-07-14 20:21:55 -04002858 ani_mode = ah->ani_state.ani_mode;
Nick Kossifidis344b54b2010-12-03 06:07:13 +02002859 ath5k_ani_init(ah, ATH5K_ANI_MODE_OFF);
2860
Nick Kossifidis19252ec2010-12-03 06:05:19 +02002861 /* We are going to empty hw queues
2862 * so we should also free any remaining
2863 * tx buffers */
Pavel Roskine0d687b2011-07-14 20:21:55 -04002864 ath5k_drain_tx_buffs(ah);
Bruno Randolf930a7622011-01-19 18:21:13 +09002865 if (chan)
Pavel Roskine0d687b2011-07-14 20:21:55 -04002866 ah->curchan = chan;
Nick Kossifidisa99168e2011-06-02 03:09:48 +03002867
2868 fast = ((chan != NULL) && modparam_fastchanswitch) ? 1 : 0;
2869
Pavel Roskine0d687b2011-07-14 20:21:55 -04002870 ret = ath5k_hw_reset(ah, ah->opmode, ah->curchan, fast, skip_pcu);
Jiri Slabyd7dc1002008-07-23 13:17:35 +02002871 if (ret) {
Pavel Roskine0d687b2011-07-14 20:21:55 -04002872 ATH5K_ERR(ah, "can't reset hardware (%d)\n", ret);
Jiri Slabyfa1c1142007-08-12 17:33:16 +02002873 goto err;
2874 }
Jiri Slabyd7dc1002008-07-23 13:17:35 +02002875
Pavel Roskine0d687b2011-07-14 20:21:55 -04002876 ret = ath5k_rx_start(ah);
Jiri Slabyd7dc1002008-07-23 13:17:35 +02002877 if (ret) {
Pavel Roskine0d687b2011-07-14 20:21:55 -04002878 ATH5K_ERR(ah, "can't start recv logic\n");
Jiri Slabyfa1c1142007-08-12 17:33:16 +02002879 goto err;
2880 }
Jiri Slabyd7dc1002008-07-23 13:17:35 +02002881
Nick Kossifidis344b54b2010-12-03 06:07:13 +02002882 ath5k_ani_init(ah, ani_mode);
Bruno Randolf2111ac02010-04-02 18:44:08 +09002883
Nick Kossifidisce169ac2011-11-25 20:40:23 +02002884 /*
2885 * Set calibration intervals
2886 *
2887 * Note: We don't need to run calibration imediately
2888 * since some initial calibration is done on reset
2889 * even for fast channel switching. Also on scanning
2890 * this will get set again and again and it won't get
2891 * executed unless we connect somewhere and spend some
2892 * time on the channel (that's what calibration needs
2893 * anyway to be accurate).
2894 */
2895 ah->ah_cal_next_full = jiffies +
2896 msecs_to_jiffies(ATH5K_TUNE_CALIBRATION_INTERVAL_FULL);
2897 ah->ah_cal_next_ani = jiffies +
2898 msecs_to_jiffies(ATH5K_TUNE_CALIBRATION_INTERVAL_ANI);
2899 ah->ah_cal_next_short = jiffies +
2900 msecs_to_jiffies(ATH5K_TUNE_CALIBRATION_INTERVAL_SHORT);
2901
Bruno Randolf5dcc03f2010-12-02 19:12:31 +09002902 ewma_init(&ah->ah_beacon_rssi_avg, 1024, 8);
Bruno Randolfafe86282010-05-19 10:31:10 +09002903
Bruno Randolff15a4bb2010-12-16 16:22:20 +09002904 /* clear survey data and cycle counters */
Pavel Roskine0d687b2011-07-14 20:21:55 -04002905 memset(&ah->survey, 0, sizeof(ah->survey));
Bob Copelandbb007552010-12-26 12:10:05 -05002906 spin_lock_bh(&common->cc_lock);
Bruno Randolff15a4bb2010-12-16 16:22:20 +09002907 ath_hw_cycle_counters_update(common);
2908 memset(&common->cc_survey, 0, sizeof(common->cc_survey));
2909 memset(&common->cc_ani, 0, sizeof(common->cc_ani));
Bob Copelandbb007552010-12-26 12:10:05 -05002910 spin_unlock_bh(&common->cc_lock);
Bruno Randolff15a4bb2010-12-16 16:22:20 +09002911
Jiri Slabyfa1c1142007-08-12 17:33:16 +02002912 /*
Jiri Slabyd7dc1002008-07-23 13:17:35 +02002913 * Change channels and update the h/w rate map if we're switching;
2914 * e.g. 11a to 11b/g.
2915 *
2916 * We may be doing a reset in response to an ioctl that changes the
2917 * channel so update any state that might change as a result.
Jiri Slabyfa1c1142007-08-12 17:33:16 +02002918 *
2919 * XXX needed?
2920 */
Pavel Roskine0d687b2011-07-14 20:21:55 -04002921/* ath5k_chan_change(ah, c); */
Jiri Slabyfa1c1142007-08-12 17:33:16 +02002922
Pavel Roskine0d687b2011-07-14 20:21:55 -04002923 ath5k_beacon_config(ah);
Jiri Slabyd7dc1002008-07-23 13:17:35 +02002924 /* intrs are enabled by ath5k_beacon_config */
Jiri Slabyfa1c1142007-08-12 17:33:16 +02002925
Pavel Roskine0d687b2011-07-14 20:21:55 -04002926 ieee80211_wake_queues(ah->hw);
Bruno Randolf397f3852010-05-19 10:30:49 +09002927
Jiri Slabyfa1c1142007-08-12 17:33:16 +02002928 return 0;
2929err:
2930 return ret;
2931}
2932
Bob Copeland5faaff72010-07-13 11:32:40 -04002933static void ath5k_reset_work(struct work_struct *work)
2934{
Pavel Roskine0d687b2011-07-14 20:21:55 -04002935 struct ath5k_hw *ah = container_of(work, struct ath5k_hw,
Bob Copeland5faaff72010-07-13 11:32:40 -04002936 reset_work);
2937
Pavel Roskine0d687b2011-07-14 20:21:55 -04002938 mutex_lock(&ah->lock);
2939 ath5k_reset(ah, NULL, true);
2940 mutex_unlock(&ah->lock);
Bob Copeland5faaff72010-07-13 11:32:40 -04002941}
2942
Bill Pembertone829cf92012-12-03 09:56:28 -05002943static int
Felix Fietkau132b1c32010-12-02 10:26:56 +01002944ath5k_init(struct ieee80211_hw *hw)
Bob Copeland8a63fac2010-09-17 12:45:07 +09002945{
Felix Fietkau132b1c32010-12-02 10:26:56 +01002946
Pavel Roskine0d687b2011-07-14 20:21:55 -04002947 struct ath5k_hw *ah = hw->priv;
Bob Copeland8a63fac2010-09-17 12:45:07 +09002948 struct ath_regulatory *regulatory = ath5k_hw_regulatory(ah);
Bruno Randolf925e0b02010-09-17 11:36:35 +09002949 struct ath5k_txq *txq;
Bob Copeland8a63fac2010-09-17 12:45:07 +09002950 u8 mac[ETH_ALEN] = {};
2951 int ret;
2952
Bob Copeland8a63fac2010-09-17 12:45:07 +09002953
2954 /*
Bob Copeland8a63fac2010-09-17 12:45:07 +09002955 * Collect the channel list. The 802.11 layer
Pavel Roskin6a2a0e72011-07-09 00:17:51 -04002956 * is responsible for filtering this list based
Bob Copeland8a63fac2010-09-17 12:45:07 +09002957 * on settings like the phy mode and regulatory
2958 * domain restrictions.
2959 */
2960 ret = ath5k_setup_bands(hw);
2961 if (ret) {
Pavel Roskine0d687b2011-07-14 20:21:55 -04002962 ATH5K_ERR(ah, "can't get channels\n");
Bob Copeland8a63fac2010-09-17 12:45:07 +09002963 goto err;
2964 }
2965
Bob Copeland8a63fac2010-09-17 12:45:07 +09002966 /*
2967 * Allocate tx+rx descriptors and populate the lists.
2968 */
Pavel Roskine0d687b2011-07-14 20:21:55 -04002969 ret = ath5k_desc_alloc(ah);
Bob Copeland8a63fac2010-09-17 12:45:07 +09002970 if (ret) {
Pavel Roskine0d687b2011-07-14 20:21:55 -04002971 ATH5K_ERR(ah, "can't allocate descriptors\n");
Bob Copeland8a63fac2010-09-17 12:45:07 +09002972 goto err;
2973 }
2974
2975 /*
2976 * Allocate hardware transmit queues: one queue for
2977 * beacon frames and one data queue for each QoS
2978 * priority. Note that hw functions handle resetting
2979 * these queues at the needed time.
2980 */
2981 ret = ath5k_beaconq_setup(ah);
2982 if (ret < 0) {
Pavel Roskine0d687b2011-07-14 20:21:55 -04002983 ATH5K_ERR(ah, "can't setup a beacon xmit queue\n");
Bob Copeland8a63fac2010-09-17 12:45:07 +09002984 goto err_desc;
2985 }
Pavel Roskine0d687b2011-07-14 20:21:55 -04002986 ah->bhalq = ret;
2987 ah->cabq = ath5k_txq_setup(ah, AR5K_TX_QUEUE_CAB, 0);
2988 if (IS_ERR(ah->cabq)) {
2989 ATH5K_ERR(ah, "can't setup cab queue\n");
2990 ret = PTR_ERR(ah->cabq);
Bob Copeland8a63fac2010-09-17 12:45:07 +09002991 goto err_bhal;
2992 }
2993
Bruno Randolf22d8d9f2010-12-07 11:08:12 +09002994 /* 5211 and 5212 usually support 10 queues but we better rely on the
2995 * capability information */
2996 if (ah->ah_capabilities.cap_queues.q_tx_num >= 6) {
2997 /* This order matches mac80211's queue priority, so we can
2998 * directly use the mac80211 queue number without any mapping */
Pavel Roskine0d687b2011-07-14 20:21:55 -04002999 txq = ath5k_txq_setup(ah, AR5K_TX_QUEUE_DATA, AR5K_WME_AC_VO);
Bruno Randolf22d8d9f2010-12-07 11:08:12 +09003000 if (IS_ERR(txq)) {
Pavel Roskine0d687b2011-07-14 20:21:55 -04003001 ATH5K_ERR(ah, "can't setup xmit queue\n");
Bruno Randolf22d8d9f2010-12-07 11:08:12 +09003002 ret = PTR_ERR(txq);
3003 goto err_queues;
3004 }
Pavel Roskine0d687b2011-07-14 20:21:55 -04003005 txq = ath5k_txq_setup(ah, AR5K_TX_QUEUE_DATA, AR5K_WME_AC_VI);
Bruno Randolf22d8d9f2010-12-07 11:08:12 +09003006 if (IS_ERR(txq)) {
Pavel Roskine0d687b2011-07-14 20:21:55 -04003007 ATH5K_ERR(ah, "can't setup xmit queue\n");
Bruno Randolf22d8d9f2010-12-07 11:08:12 +09003008 ret = PTR_ERR(txq);
3009 goto err_queues;
3010 }
Pavel Roskine0d687b2011-07-14 20:21:55 -04003011 txq = ath5k_txq_setup(ah, AR5K_TX_QUEUE_DATA, AR5K_WME_AC_BE);
Bruno Randolf22d8d9f2010-12-07 11:08:12 +09003012 if (IS_ERR(txq)) {
Pavel Roskine0d687b2011-07-14 20:21:55 -04003013 ATH5K_ERR(ah, "can't setup xmit queue\n");
Bruno Randolf22d8d9f2010-12-07 11:08:12 +09003014 ret = PTR_ERR(txq);
3015 goto err_queues;
3016 }
Pavel Roskine0d687b2011-07-14 20:21:55 -04003017 txq = ath5k_txq_setup(ah, AR5K_TX_QUEUE_DATA, AR5K_WME_AC_BK);
Bruno Randolf22d8d9f2010-12-07 11:08:12 +09003018 if (IS_ERR(txq)) {
Pavel Roskine0d687b2011-07-14 20:21:55 -04003019 ATH5K_ERR(ah, "can't setup xmit queue\n");
Bruno Randolf22d8d9f2010-12-07 11:08:12 +09003020 ret = PTR_ERR(txq);
3021 goto err_queues;
3022 }
3023 hw->queues = 4;
3024 } else {
3025 /* older hardware (5210) can only support one data queue */
Pavel Roskine0d687b2011-07-14 20:21:55 -04003026 txq = ath5k_txq_setup(ah, AR5K_TX_QUEUE_DATA, AR5K_WME_AC_BE);
Bruno Randolf22d8d9f2010-12-07 11:08:12 +09003027 if (IS_ERR(txq)) {
Pavel Roskine0d687b2011-07-14 20:21:55 -04003028 ATH5K_ERR(ah, "can't setup xmit queue\n");
Bruno Randolf22d8d9f2010-12-07 11:08:12 +09003029 ret = PTR_ERR(txq);
3030 goto err_queues;
3031 }
3032 hw->queues = 1;
Bob Copeland8a63fac2010-09-17 12:45:07 +09003033 }
3034
Pavel Roskine0d687b2011-07-14 20:21:55 -04003035 tasklet_init(&ah->rxtq, ath5k_tasklet_rx, (unsigned long)ah);
3036 tasklet_init(&ah->txtq, ath5k_tasklet_tx, (unsigned long)ah);
Pavel Roskine0d687b2011-07-14 20:21:55 -04003037 tasklet_init(&ah->beacontq, ath5k_tasklet_beacon, (unsigned long)ah);
3038 tasklet_init(&ah->ani_tasklet, ath5k_tasklet_ani, (unsigned long)ah);
Bob Copeland8a63fac2010-09-17 12:45:07 +09003039
Pavel Roskine0d687b2011-07-14 20:21:55 -04003040 INIT_WORK(&ah->reset_work, ath5k_reset_work);
Nick Kossifidisce169ac2011-11-25 20:40:23 +02003041 INIT_WORK(&ah->calib_work, ath5k_calibrate_work);
Pavel Roskine0d687b2011-07-14 20:21:55 -04003042 INIT_DELAYED_WORK(&ah->tx_complete_work, ath5k_tx_complete_poll_work);
Bob Copeland8a63fac2010-09-17 12:45:07 +09003043
Felix Fietkaufa9bfd62011-04-13 21:56:44 +02003044 ret = ath5k_hw_common(ah)->bus_ops->eeprom_read_mac(ah, mac);
Bob Copeland8a63fac2010-09-17 12:45:07 +09003045 if (ret) {
Pavel Roskine0d687b2011-07-14 20:21:55 -04003046 ATH5K_ERR(ah, "unable to read address from EEPROM\n");
Bob Copeland8a63fac2010-09-17 12:45:07 +09003047 goto err_queues;
3048 }
3049
3050 SET_IEEE80211_PERM_ADDR(hw, mac);
3051 /* All MAC address bits matter for ACKs */
Pavel Roskine0d687b2011-07-14 20:21:55 -04003052 ath5k_update_bssid_mask_and_opmode(ah, NULL);
Bob Copeland8a63fac2010-09-17 12:45:07 +09003053
3054 regulatory->current_rd = ah->ah_capabilities.cap_eeprom.ee_regdomain;
3055 ret = ath_regd_init(regulatory, hw->wiphy, ath5k_reg_notifier);
3056 if (ret) {
Pavel Roskine0d687b2011-07-14 20:21:55 -04003057 ATH5K_ERR(ah, "can't initialize regulatory system\n");
Bob Copeland8a63fac2010-09-17 12:45:07 +09003058 goto err_queues;
3059 }
3060
3061 ret = ieee80211_register_hw(hw);
3062 if (ret) {
Pavel Roskine0d687b2011-07-14 20:21:55 -04003063 ATH5K_ERR(ah, "can't register ieee80211 hw\n");
Bob Copeland8a63fac2010-09-17 12:45:07 +09003064 goto err_queues;
3065 }
3066
3067 if (!ath_is_world_regd(regulatory))
3068 regulatory_hint(hw->wiphy, regulatory->alpha2);
3069
Pavel Roskine0d687b2011-07-14 20:21:55 -04003070 ath5k_init_leds(ah);
Bob Copeland8a63fac2010-09-17 12:45:07 +09003071
Pavel Roskine0d687b2011-07-14 20:21:55 -04003072 ath5k_sysfs_register(ah);
Bob Copeland8a63fac2010-09-17 12:45:07 +09003073
3074 return 0;
3075err_queues:
Pavel Roskine0d687b2011-07-14 20:21:55 -04003076 ath5k_txq_release(ah);
Bob Copeland8a63fac2010-09-17 12:45:07 +09003077err_bhal:
Pavel Roskine0d687b2011-07-14 20:21:55 -04003078 ath5k_hw_release_tx_queue(ah, ah->bhalq);
Bob Copeland8a63fac2010-09-17 12:45:07 +09003079err_desc:
Pavel Roskine0d687b2011-07-14 20:21:55 -04003080 ath5k_desc_free(ah);
Bob Copeland8a63fac2010-09-17 12:45:07 +09003081err:
3082 return ret;
3083}
3084
Felix Fietkau132b1c32010-12-02 10:26:56 +01003085void
Pavel Roskinbb1f3ad2011-07-26 22:27:05 -04003086ath5k_deinit_ah(struct ath5k_hw *ah)
Bob Copeland8a63fac2010-09-17 12:45:07 +09003087{
Pavel Roskine0d687b2011-07-14 20:21:55 -04003088 struct ieee80211_hw *hw = ah->hw;
Bob Copeland8a63fac2010-09-17 12:45:07 +09003089
3090 /*
3091 * NB: the order of these is important:
3092 * o call the 802.11 layer before detaching ath5k_hw to
3093 * ensure callbacks into the driver to delete global
3094 * key cache entries can be handled
3095 * o reclaim the tx queue data structures after calling
3096 * the 802.11 layer as we'll get called back to reclaim
3097 * node state and potentially want to use them
3098 * o to cleanup the tx queues the hal is called, so detach
3099 * it last
3100 * XXX: ??? detach ath5k_hw ???
3101 * Other than that, it's straightforward...
3102 */
3103 ieee80211_unregister_hw(hw);
Pavel Roskine0d687b2011-07-14 20:21:55 -04003104 ath5k_desc_free(ah);
3105 ath5k_txq_release(ah);
3106 ath5k_hw_release_tx_queue(ah, ah->bhalq);
3107 ath5k_unregister_leds(ah);
Bob Copeland8a63fac2010-09-17 12:45:07 +09003108
Pavel Roskine0d687b2011-07-14 20:21:55 -04003109 ath5k_sysfs_unregister(ah);
Bob Copeland8a63fac2010-09-17 12:45:07 +09003110 /*
3111 * NB: can't reclaim these until after ieee80211_ifdetach
3112 * returns because we'll get called back to reclaim node
3113 * state and potentially want to use them.
3114 */
Pavel Roskine0d687b2011-07-14 20:21:55 -04003115 ath5k_hw_deinit(ah);
3116 free_irq(ah->irq, ah);
Bob Copeland8a63fac2010-09-17 12:45:07 +09003117}
3118
Bruno Randolfcd2c5482010-12-22 19:20:32 +09003119bool
Pavel Roskine0d687b2011-07-14 20:21:55 -04003120ath5k_any_vif_assoc(struct ath5k_hw *ah)
Ben Greearb1ae1ed2010-09-30 12:22:58 -07003121{
Ben Greeare4b0b322011-03-03 14:39:05 -08003122 struct ath5k_vif_iter_data iter_data;
Ben Greearb1ae1ed2010-09-30 12:22:58 -07003123 iter_data.hw_macaddr = NULL;
3124 iter_data.any_assoc = false;
3125 iter_data.need_set_hw_addr = false;
3126 iter_data.found_active = true;
3127
Johannes Berg8b2c9822012-11-06 20:23:30 +01003128 ieee80211_iterate_active_interfaces_atomic(
3129 ah->hw, IEEE80211_IFACE_ITER_RESUME_ALL,
3130 ath5k_vif_iter, &iter_data);
Ben Greearb1ae1ed2010-09-30 12:22:58 -07003131 return iter_data.any_assoc;
3132}
3133
Bruno Randolfcd2c5482010-12-22 19:20:32 +09003134void
Pavel Roskinf5cbc8b2011-06-15 18:03:22 -04003135ath5k_set_beacon_filter(struct ieee80211_hw *hw, bool enable)
Martin Xu02969b32008-11-24 10:49:27 +08003136{
Pavel Roskine0d687b2011-07-14 20:21:55 -04003137 struct ath5k_hw *ah = hw->priv;
Martin Xu02969b32008-11-24 10:49:27 +08003138 u32 rfilt;
3139 rfilt = ath5k_hw_get_rx_filter(ah);
3140 if (enable)
3141 rfilt |= AR5K_RX_FILTER_BEACON;
3142 else
3143 rfilt &= ~AR5K_RX_FILTER_BEACON;
3144 ath5k_hw_set_rx_filter(ah, rfilt);
Pavel Roskine0d687b2011-07-14 20:21:55 -04003145 ah->filter_flags = rfilt;
Martin Xu02969b32008-11-24 10:49:27 +08003146}
Joe Perches227842d2012-03-18 17:30:53 -07003147
3148void _ath5k_printk(const struct ath5k_hw *ah, const char *level,
3149 const char *fmt, ...)
3150{
3151 struct va_format vaf;
3152 va_list args;
3153
3154 va_start(args, fmt);
3155
3156 vaf.fmt = fmt;
3157 vaf.va = &args;
3158
3159 if (ah && ah->hw)
3160 printk("%s" pr_fmt("%s: %pV"),
3161 level, wiphy_name(ah->hw->wiphy), &vaf);
3162 else
3163 printk("%s" pr_fmt("%pV"), level, &vaf);
3164
3165 va_end(args);
3166}