blob: dc44cfef75176e1710f6622fee85f1f5e9b97e11 [file] [log] [blame]
Bruno Randolfcd2c5482010-12-22 19:20:32 +09001/*-
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 * Copyright (c) 2010 Bruno Randolf <br1@einfach.org>
8 *
9 * All rights reserved.
10 *
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
13 * are met:
14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions and the following disclaimer,
16 * without modification.
17 * 2. Redistributions in binary form must reproduce at minimum a disclaimer
18 * similar to the "NO WARRANTY" disclaimer below ("Disclaimer") and any
19 * redistribution must be conditioned upon including a substantially
20 * similar Disclaimer requirement for further binary redistribution.
21 * 3. Neither the names of the above-listed copyright holders nor the names
22 * of any contributors may be used to endorse or promote products derived
23 * from this software without specific prior written permission.
24 *
25 * Alternatively, this software may be distributed under the terms of the
26 * GNU General Public License ("GPL") version 2 as published by the Free
27 * Software Foundation.
28 *
29 * NO WARRANTY
30 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
31 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
32 * LIMITED TO, THE IMPLIED WARRANTIES OF NONINFRINGEMENT, MERCHANTIBILITY
33 * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
34 * THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY,
35 * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
36 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
37 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
38 * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
39 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
40 * THE POSSIBILITY OF SUCH DAMAGES.
41 *
42 */
43
Joe Perches516304b2012-03-18 17:30:52 -070044#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
45
Pavel Roskin931be262011-07-26 22:26:59 -040046#include <net/mac80211.h>
Bruno Randolfcd2c5482010-12-22 19:20:32 +090047#include <asm/unaligned.h>
48
Pavel Roskin931be262011-07-26 22:26:59 -040049#include "ath5k.h"
Bruno Randolfcd2c5482010-12-22 19:20:32 +090050#include "base.h"
51#include "reg.h"
52
Bruno Randolfcd2c5482010-12-22 19:20:32 +090053/********************\
54* Mac80211 functions *
55\********************/
56
Johannes Berg7bb45682011-02-24 14:42:06 +010057static void
Thomas Huehn36323f82012-07-23 21:33:42 +020058ath5k_tx(struct ieee80211_hw *hw, struct ieee80211_tx_control *control,
59 struct sk_buff *skb)
Bruno Randolfcd2c5482010-12-22 19:20:32 +090060{
Pavel Roskine0d687b2011-07-14 20:21:55 -040061 struct ath5k_hw *ah = hw->priv;
Bruno Randolfcd2c5482010-12-22 19:20:32 +090062 u16 qnum = skb_get_queue_mapping(skb);
63
Pavel Roskine0d687b2011-07-14 20:21:55 -040064 if (WARN_ON(qnum >= ah->ah_capabilities.cap_queues.q_tx_num)) {
Felix Fietkau596ab5e2012-12-10 16:40:41 +010065 ieee80211_free_txskb(hw, skb);
Johannes Berg7bb45682011-02-24 14:42:06 +010066 return;
Bruno Randolfcd2c5482010-12-22 19:20:32 +090067 }
68
Thomas Huehn0967e012013-06-11 15:10:31 +020069 ath5k_tx_queue(hw, skb, &ah->txqs[qnum], control);
Bruno Randolfcd2c5482010-12-22 19:20:32 +090070}
71
72
73static int
Bruno Randolfcd2c5482010-12-22 19:20:32 +090074ath5k_add_interface(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
75{
Pavel Roskine0d687b2011-07-14 20:21:55 -040076 struct ath5k_hw *ah = hw->priv;
Bruno Randolfcd2c5482010-12-22 19:20:32 +090077 int ret;
78 struct ath5k_vif *avf = (void *)vif->drv_priv;
79
Pavel Roskine0d687b2011-07-14 20:21:55 -040080 mutex_lock(&ah->lock);
Bruno Randolfcd2c5482010-12-22 19:20:32 +090081
82 if ((vif->type == NL80211_IFTYPE_AP ||
83 vif->type == NL80211_IFTYPE_ADHOC)
Pavel Roskine0d687b2011-07-14 20:21:55 -040084 && (ah->num_ap_vifs + ah->num_adhoc_vifs) >= ATH_BCBUF) {
Bruno Randolfcd2c5482010-12-22 19:20:32 +090085 ret = -ELNRNG;
86 goto end;
87 }
88
89 /* Don't allow other interfaces if one ad-hoc is configured.
90 * TODO: Fix the problems with ad-hoc and multiple other interfaces.
91 * We would need to operate the HW in ad-hoc mode to allow TSF updates
92 * for the IBSS, but this breaks with additional AP or STA interfaces
93 * at the moment. */
Pavel Roskine0d687b2011-07-14 20:21:55 -040094 if (ah->num_adhoc_vifs ||
95 (ah->nvifs && vif->type == NL80211_IFTYPE_ADHOC)) {
96 ATH5K_ERR(ah, "Only one single ad-hoc interface is allowed.\n");
Bruno Randolfcd2c5482010-12-22 19:20:32 +090097 ret = -ELNRNG;
98 goto end;
99 }
100
101 switch (vif->type) {
102 case NL80211_IFTYPE_AP:
103 case NL80211_IFTYPE_STATION:
104 case NL80211_IFTYPE_ADHOC:
105 case NL80211_IFTYPE_MESH_POINT:
106 avf->opmode = vif->type;
107 break;
108 default:
109 ret = -EOPNOTSUPP;
110 goto end;
111 }
112
Pavel Roskine0d687b2011-07-14 20:21:55 -0400113 ah->nvifs++;
114 ATH5K_DBG(ah, ATH5K_DEBUG_MODE, "add interface mode %d\n", avf->opmode);
Bruno Randolfcd2c5482010-12-22 19:20:32 +0900115
116 /* Assign the vap/adhoc to a beacon xmit slot. */
117 if ((avf->opmode == NL80211_IFTYPE_AP) ||
118 (avf->opmode == NL80211_IFTYPE_ADHOC) ||
119 (avf->opmode == NL80211_IFTYPE_MESH_POINT)) {
120 int slot;
121
Pavel Roskine0d687b2011-07-14 20:21:55 -0400122 WARN_ON(list_empty(&ah->bcbuf));
123 avf->bbuf = list_first_entry(&ah->bcbuf, struct ath5k_buf,
Bruno Randolfcd2c5482010-12-22 19:20:32 +0900124 list);
125 list_del(&avf->bbuf->list);
126
127 avf->bslot = 0;
128 for (slot = 0; slot < ATH_BCBUF; slot++) {
Pavel Roskine0d687b2011-07-14 20:21:55 -0400129 if (!ah->bslot[slot]) {
Bruno Randolfcd2c5482010-12-22 19:20:32 +0900130 avf->bslot = slot;
131 break;
132 }
133 }
Pavel Roskine0d687b2011-07-14 20:21:55 -0400134 BUG_ON(ah->bslot[avf->bslot] != NULL);
135 ah->bslot[avf->bslot] = vif;
Bruno Randolfcd2c5482010-12-22 19:20:32 +0900136 if (avf->opmode == NL80211_IFTYPE_AP)
Pavel Roskine0d687b2011-07-14 20:21:55 -0400137 ah->num_ap_vifs++;
Bruno Randolfcd2c5482010-12-22 19:20:32 +0900138 else if (avf->opmode == NL80211_IFTYPE_ADHOC)
Pavel Roskine0d687b2011-07-14 20:21:55 -0400139 ah->num_adhoc_vifs++;
Chun-Yeow Yeohda473b62012-03-03 09:48:56 +0800140 else if (avf->opmode == NL80211_IFTYPE_MESH_POINT)
141 ah->num_mesh_vifs++;
Bruno Randolfcd2c5482010-12-22 19:20:32 +0900142 }
143
144 /* Any MAC address is fine, all others are included through the
145 * filter.
146 */
Pavel Roskine0d687b2011-07-14 20:21:55 -0400147 ath5k_hw_set_lladdr(ah, vif->addr);
Bruno Randolfcd2c5482010-12-22 19:20:32 +0900148
Pavel Roskine0d687b2011-07-14 20:21:55 -0400149 ath5k_update_bssid_mask_and_opmode(ah, vif);
Bruno Randolfcd2c5482010-12-22 19:20:32 +0900150 ret = 0;
151end:
Pavel Roskine0d687b2011-07-14 20:21:55 -0400152 mutex_unlock(&ah->lock);
Bruno Randolfcd2c5482010-12-22 19:20:32 +0900153 return ret;
154}
155
156
157static void
158ath5k_remove_interface(struct ieee80211_hw *hw,
159 struct ieee80211_vif *vif)
160{
Pavel Roskine0d687b2011-07-14 20:21:55 -0400161 struct ath5k_hw *ah = hw->priv;
Bruno Randolfcd2c5482010-12-22 19:20:32 +0900162 struct ath5k_vif *avf = (void *)vif->drv_priv;
163 unsigned int i;
164
Pavel Roskine0d687b2011-07-14 20:21:55 -0400165 mutex_lock(&ah->lock);
166 ah->nvifs--;
Bruno Randolfcd2c5482010-12-22 19:20:32 +0900167
168 if (avf->bbuf) {
Pavel Roskine0d687b2011-07-14 20:21:55 -0400169 ath5k_txbuf_free_skb(ah, avf->bbuf);
170 list_add_tail(&avf->bbuf->list, &ah->bcbuf);
Bruno Randolfcd2c5482010-12-22 19:20:32 +0900171 for (i = 0; i < ATH_BCBUF; i++) {
Pavel Roskine0d687b2011-07-14 20:21:55 -0400172 if (ah->bslot[i] == vif) {
173 ah->bslot[i] = NULL;
Bruno Randolfcd2c5482010-12-22 19:20:32 +0900174 break;
175 }
176 }
177 avf->bbuf = NULL;
178 }
179 if (avf->opmode == NL80211_IFTYPE_AP)
Pavel Roskine0d687b2011-07-14 20:21:55 -0400180 ah->num_ap_vifs--;
Bruno Randolfcd2c5482010-12-22 19:20:32 +0900181 else if (avf->opmode == NL80211_IFTYPE_ADHOC)
Pavel Roskine0d687b2011-07-14 20:21:55 -0400182 ah->num_adhoc_vifs--;
Chun-Yeow Yeohda473b62012-03-03 09:48:56 +0800183 else if (avf->opmode == NL80211_IFTYPE_MESH_POINT)
184 ah->num_mesh_vifs--;
Bruno Randolfcd2c5482010-12-22 19:20:32 +0900185
Pavel Roskine0d687b2011-07-14 20:21:55 -0400186 ath5k_update_bssid_mask_and_opmode(ah, NULL);
187 mutex_unlock(&ah->lock);
Bruno Randolfcd2c5482010-12-22 19:20:32 +0900188}
189
190
191/*
192 * TODO: Phy disable/diversity etc
193 */
194static int
195ath5k_config(struct ieee80211_hw *hw, u32 changed)
196{
Pavel Roskine0d687b2011-07-14 20:21:55 -0400197 struct ath5k_hw *ah = hw->priv;
Bruno Randolfcd2c5482010-12-22 19:20:32 +0900198 struct ieee80211_conf *conf = &hw->conf;
199 int ret = 0;
Bruno Randolf76a9f6f2011-01-28 16:52:11 +0900200 int i;
Bruno Randolfcd2c5482010-12-22 19:20:32 +0900201
Pavel Roskine0d687b2011-07-14 20:21:55 -0400202 mutex_lock(&ah->lock);
Bruno Randolfcd2c5482010-12-22 19:20:32 +0900203
204 if (changed & IEEE80211_CONF_CHANGE_CHANNEL) {
Simon Wunderlich4d70f2f2013-08-14 08:01:37 +0200205 ret = ath5k_chan_set(ah, &conf->chandef);
Bruno Randolfcd2c5482010-12-22 19:20:32 +0900206 if (ret < 0)
207 goto unlock;
208 }
209
210 if ((changed & IEEE80211_CONF_CHANGE_POWER) &&
Nick Kossifidis987af542012-08-05 22:35:36 +0300211 (ah->ah_txpower.txp_requested != conf->power_level)) {
212 ah->ah_txpower.txp_requested = conf->power_level;
Bruno Randolfcd2c5482010-12-22 19:20:32 +0900213
214 /* Half dB steps */
215 ath5k_hw_set_txpower_limit(ah, (conf->power_level * 2));
216 }
217
Bruno Randolf76a9f6f2011-01-28 16:52:11 +0900218 if (changed & IEEE80211_CONF_CHANGE_RETRY_LIMITS) {
219 ah->ah_retry_long = conf->long_frame_max_tx_count;
220 ah->ah_retry_short = conf->short_frame_max_tx_count;
221
222 for (i = 0; i < ah->ah_capabilities.cap_queues.q_tx_num; i++)
223 ath5k_hw_set_tx_retry_limits(ah, i);
224 }
225
Bruno Randolfcd2c5482010-12-22 19:20:32 +0900226 /* TODO:
227 * 1) Move this on config_interface and handle each case
228 * separately eg. when we have only one STA vif, use
229 * AR5K_ANTMODE_SINGLE_AP
230 *
231 * 2) Allow the user to change antenna mode eg. when only
232 * one antenna is present
233 *
234 * 3) Allow the user to set default/tx antenna when possible
235 *
236 * 4) Default mode should handle 90% of the cases, together
237 * with fixed a/b and single AP modes we should be able to
238 * handle 99%. Sectored modes are extreme cases and i still
239 * haven't found a usage for them. If we decide to support them,
240 * then we must allow the user to set how many tx antennas we
241 * have available
242 */
243 ath5k_hw_set_antenna_mode(ah, ah->ah_ant_mode);
244
245unlock:
Pavel Roskine0d687b2011-07-14 20:21:55 -0400246 mutex_unlock(&ah->lock);
Bruno Randolfcd2c5482010-12-22 19:20:32 +0900247 return ret;
248}
249
250
251static void
252ath5k_bss_info_changed(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
253 struct ieee80211_bss_conf *bss_conf, u32 changes)
254{
255 struct ath5k_vif *avf = (void *)vif->drv_priv;
Pavel Roskine0d687b2011-07-14 20:21:55 -0400256 struct ath5k_hw *ah = hw->priv;
Bruno Randolfcd2c5482010-12-22 19:20:32 +0900257 struct ath_common *common = ath5k_hw_common(ah);
Bruno Randolfcd2c5482010-12-22 19:20:32 +0900258
Pavel Roskine0d687b2011-07-14 20:21:55 -0400259 mutex_lock(&ah->lock);
Bruno Randolfcd2c5482010-12-22 19:20:32 +0900260
261 if (changes & BSS_CHANGED_BSSID) {
262 /* Cache for later use during resets */
263 memcpy(common->curbssid, bss_conf->bssid, ETH_ALEN);
264 common->curaid = 0;
265 ath5k_hw_set_bssid(ah);
266 mmiowb();
267 }
268
269 if (changes & BSS_CHANGED_BEACON_INT)
Pavel Roskine0d687b2011-07-14 20:21:55 -0400270 ah->bintval = bss_conf->beacon_int;
Bruno Randolfcd2c5482010-12-22 19:20:32 +0900271
Felix Fietkaub1ad1b62011-04-09 23:10:21 +0200272 if (changes & BSS_CHANGED_ERP_SLOT) {
273 int slot_time;
274
275 ah->ah_short_slot = bss_conf->use_short_slot;
276 slot_time = ath5k_hw_get_default_slottime(ah) +
277 3 * ah->ah_coverage_class;
278 ath5k_hw_set_ifs_intervals(ah, slot_time);
279 }
280
Bruno Randolfcd2c5482010-12-22 19:20:32 +0900281 if (changes & BSS_CHANGED_ASSOC) {
282 avf->assoc = bss_conf->assoc;
283 if (bss_conf->assoc)
Pavel Roskine0d687b2011-07-14 20:21:55 -0400284 ah->assoc = bss_conf->assoc;
Bruno Randolfcd2c5482010-12-22 19:20:32 +0900285 else
Pavel Roskine0d687b2011-07-14 20:21:55 -0400286 ah->assoc = ath5k_any_vif_assoc(ah);
Bruno Randolfcd2c5482010-12-22 19:20:32 +0900287
Pavel Roskine0d687b2011-07-14 20:21:55 -0400288 if (ah->opmode == NL80211_IFTYPE_STATION)
289 ath5k_set_beacon_filter(hw, ah->assoc);
290 ath5k_hw_set_ledstate(ah, ah->assoc ?
Bruno Randolfcd2c5482010-12-22 19:20:32 +0900291 AR5K_LED_ASSOC : AR5K_LED_INIT);
292 if (bss_conf->assoc) {
Pavel Roskine0d687b2011-07-14 20:21:55 -0400293 ATH5K_DBG(ah, ATH5K_DEBUG_ANY,
Bruno Randolfcd2c5482010-12-22 19:20:32 +0900294 "Bss Info ASSOC %d, bssid: %pM\n",
295 bss_conf->aid, common->curbssid);
296 common->curaid = bss_conf->aid;
297 ath5k_hw_set_bssid(ah);
298 /* Once ANI is available you would start it here */
299 }
300 }
301
302 if (changes & BSS_CHANGED_BEACON) {
Bob Copeland7dd67532012-08-12 21:18:33 -0400303 spin_lock_bh(&ah->block);
Bruno Randolfcd2c5482010-12-22 19:20:32 +0900304 ath5k_beacon_update(hw, vif);
Bob Copeland7dd67532012-08-12 21:18:33 -0400305 spin_unlock_bh(&ah->block);
Bruno Randolfcd2c5482010-12-22 19:20:32 +0900306 }
307
308 if (changes & BSS_CHANGED_BEACON_ENABLED)
Pavel Roskine0d687b2011-07-14 20:21:55 -0400309 ah->enable_beacon = bss_conf->enable_beacon;
Bruno Randolfcd2c5482010-12-22 19:20:32 +0900310
311 if (changes & (BSS_CHANGED_BEACON | BSS_CHANGED_BEACON_ENABLED |
312 BSS_CHANGED_BEACON_INT))
Pavel Roskine0d687b2011-07-14 20:21:55 -0400313 ath5k_beacon_config(ah);
Bruno Randolfcd2c5482010-12-22 19:20:32 +0900314
Pavel Roskine0d687b2011-07-14 20:21:55 -0400315 mutex_unlock(&ah->lock);
Bruno Randolfcd2c5482010-12-22 19:20:32 +0900316}
317
318
319static u64
320ath5k_prepare_multicast(struct ieee80211_hw *hw,
321 struct netdev_hw_addr_list *mc_list)
322{
323 u32 mfilt[2], val;
324 u8 pos;
325 struct netdev_hw_addr *ha;
326
327 mfilt[0] = 0;
Bob Copelandf287cbd2013-07-11 09:19:13 -0400328 mfilt[1] = 0;
Bruno Randolfcd2c5482010-12-22 19:20:32 +0900329
330 netdev_hw_addr_list_for_each(ha, mc_list) {
331 /* calculate XOR of eight 6-bit values */
332 val = get_unaligned_le32(ha->addr + 0);
333 pos = (val >> 18) ^ (val >> 12) ^ (val >> 6) ^ val;
334 val = get_unaligned_le32(ha->addr + 3);
335 pos ^= (val >> 18) ^ (val >> 12) ^ (val >> 6) ^ val;
336 pos &= 0x3f;
337 mfilt[pos / 32] |= (1 << (pos % 32));
338 /* XXX: we might be able to just do this instead,
339 * but not sure, needs testing, if we do use this we'd
Pavel Roskin6a2a0e72011-07-09 00:17:51 -0400340 * need to inform below not to reset the mcast */
Bruno Randolfcd2c5482010-12-22 19:20:32 +0900341 /* ath5k_hw_set_mcast_filterindex(ah,
342 * ha->addr[5]); */
343 }
344
345 return ((u64)(mfilt[1]) << 32) | mfilt[0];
346}
347
348
349/*
350 * o always accept unicast, broadcast, and multicast traffic
351 * o multicast traffic for all BSSIDs will be enabled if mac80211
352 * says it should be
353 * o maintain current state of phy ofdm or phy cck error reception.
354 * If the hardware detects any of these type of errors then
355 * ath5k_hw_get_rx_filter() will pass to us the respective
356 * hardware filters to be able to receive these type of frames.
357 * o probe request frames are accepted only when operating in
358 * hostap, adhoc, or monitor modes
359 * o enable promiscuous mode according to the interface state
360 * o accept beacons:
361 * - when operating in adhoc mode so the 802.11 layer creates
362 * node table entries for peers,
363 * - when operating in station mode for collecting rssi data when
364 * the station is otherwise quiet, or
365 * - when scanning
366 */
367static void
368ath5k_configure_filter(struct ieee80211_hw *hw, unsigned int changed_flags,
369 unsigned int *new_flags, u64 multicast)
370{
371#define SUPPORTED_FIF_FLAGS \
Johannes Bergdf140462015-04-22 14:40:58 +0200372 (FIF_ALLMULTI | FIF_FCSFAIL | \
Bruno Randolfcd2c5482010-12-22 19:20:32 +0900373 FIF_PLCPFAIL | FIF_CONTROL | FIF_OTHER_BSS | \
374 FIF_BCN_PRBRESP_PROMISC)
375
Pavel Roskine0d687b2011-07-14 20:21:55 -0400376 struct ath5k_hw *ah = hw->priv;
Bruno Randolfcd2c5482010-12-22 19:20:32 +0900377 u32 mfilt[2], rfilt;
Ben Greeare4b0b322011-03-03 14:39:05 -0800378 struct ath5k_vif_iter_data iter_data; /* to count STA interfaces */
Bruno Randolfcd2c5482010-12-22 19:20:32 +0900379
Pavel Roskine0d687b2011-07-14 20:21:55 -0400380 mutex_lock(&ah->lock);
Bruno Randolfcd2c5482010-12-22 19:20:32 +0900381
382 mfilt[0] = multicast;
383 mfilt[1] = multicast >> 32;
384
385 /* Only deal with supported flags */
386 changed_flags &= SUPPORTED_FIF_FLAGS;
387 *new_flags &= SUPPORTED_FIF_FLAGS;
388
389 /* If HW detects any phy or radar errors, leave those filters on.
390 * Also, always enable Unicast, Broadcasts and Multicast
391 * XXX: move unicast, bssid broadcasts and multicast to mac80211 */
392 rfilt = (ath5k_hw_get_rx_filter(ah) & (AR5K_RX_FILTER_PHYERR)) |
393 (AR5K_RX_FILTER_UCAST | AR5K_RX_FILTER_BCAST |
394 AR5K_RX_FILTER_MCAST);
395
Bruno Randolfcd2c5482010-12-22 19:20:32 +0900396 /* Note, AR5K_RX_FILTER_MCAST is already enabled */
397 if (*new_flags & FIF_ALLMULTI) {
398 mfilt[0] = ~0;
399 mfilt[1] = ~0;
400 }
401
402 /* This is the best we can do */
403 if (*new_flags & (FIF_FCSFAIL | FIF_PLCPFAIL))
404 rfilt |= AR5K_RX_FILTER_PHYERR;
405
406 /* FIF_BCN_PRBRESP_PROMISC really means to enable beacons
407 * and probes for any BSSID */
Pavel Roskine0d687b2011-07-14 20:21:55 -0400408 if ((*new_flags & FIF_BCN_PRBRESP_PROMISC) || (ah->nvifs > 1))
Bruno Randolfcd2c5482010-12-22 19:20:32 +0900409 rfilt |= AR5K_RX_FILTER_BEACON;
410
Johannes Bergdf140462015-04-22 14:40:58 +0200411 /* FIF_CONTROL doc says we should only pass on control frames for this
Bruno Randolfcd2c5482010-12-22 19:20:32 +0900412 * station. This needs testing. I believe right now this
413 * enables *all* control frames, which is OK.. but
414 * but we should see if we can improve on granularity */
415 if (*new_flags & FIF_CONTROL)
416 rfilt |= AR5K_RX_FILTER_CONTROL;
417
418 /* Additional settings per mode -- this is per ath5k */
419
420 /* XXX move these to mac80211, and add a beacon IFF flag to mac80211 */
421
Pavel Roskine0d687b2011-07-14 20:21:55 -0400422 switch (ah->opmode) {
Bruno Randolfcd2c5482010-12-22 19:20:32 +0900423 case NL80211_IFTYPE_MESH_POINT:
424 rfilt |= AR5K_RX_FILTER_CONTROL |
425 AR5K_RX_FILTER_BEACON |
426 AR5K_RX_FILTER_PROBEREQ |
427 AR5K_RX_FILTER_PROM;
428 break;
429 case NL80211_IFTYPE_AP:
430 case NL80211_IFTYPE_ADHOC:
431 rfilt |= AR5K_RX_FILTER_PROBEREQ |
432 AR5K_RX_FILTER_BEACON;
433 break;
434 case NL80211_IFTYPE_STATION:
Pavel Roskine0d687b2011-07-14 20:21:55 -0400435 if (ah->assoc)
Bruno Randolfcd2c5482010-12-22 19:20:32 +0900436 rfilt |= AR5K_RX_FILTER_BEACON;
437 default:
438 break;
439 }
440
Ben Greeare4b0b322011-03-03 14:39:05 -0800441 iter_data.hw_macaddr = NULL;
442 iter_data.n_stas = 0;
443 iter_data.need_set_hw_addr = false;
Johannes Berg8b2c9822012-11-06 20:23:30 +0100444 ieee80211_iterate_active_interfaces_atomic(
445 ah->hw, IEEE80211_IFACE_ITER_RESUME_ALL,
446 ath5k_vif_iter, &iter_data);
Ben Greeare4b0b322011-03-03 14:39:05 -0800447
448 /* Set up RX Filter */
449 if (iter_data.n_stas > 1) {
450 /* If you have multiple STA interfaces connected to
451 * different APs, ARPs are not received (most of the time?)
Pavel Roskin6a2a0e72011-07-09 00:17:51 -0400452 * Enabling PROMISC appears to fix that problem.
Ben Greeare4b0b322011-03-03 14:39:05 -0800453 */
454 rfilt |= AR5K_RX_FILTER_PROM;
455 }
456
Bruno Randolfcd2c5482010-12-22 19:20:32 +0900457 /* Set filters */
458 ath5k_hw_set_rx_filter(ah, rfilt);
459
460 /* Set multicast bits */
461 ath5k_hw_set_mcast_filter(ah, mfilt[0], mfilt[1]);
462 /* Set the cached hw filter flags, this will later actually
463 * be set in HW */
Pavel Roskine0d687b2011-07-14 20:21:55 -0400464 ah->filter_flags = rfilt;
Mathy Vanhoef41881352014-06-13 23:40:22 +0200465 /* Store current FIF filter flags */
466 ah->fif_filter_flags = *new_flags;
Bruno Randolfcd2c5482010-12-22 19:20:32 +0900467
Pavel Roskine0d687b2011-07-14 20:21:55 -0400468 mutex_unlock(&ah->lock);
Bruno Randolfcd2c5482010-12-22 19:20:32 +0900469}
470
471
472static int
473ath5k_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
474 struct ieee80211_vif *vif, struct ieee80211_sta *sta,
475 struct ieee80211_key_conf *key)
476{
Pavel Roskine0d687b2011-07-14 20:21:55 -0400477 struct ath5k_hw *ah = hw->priv;
Bruno Randolfcd2c5482010-12-22 19:20:32 +0900478 struct ath_common *common = ath5k_hw_common(ah);
479 int ret = 0;
480
John W. Linville18cb6e32011-01-05 09:39:59 -0500481 if (ath5k_modparam_nohwcrypt)
Bruno Randolfcd2c5482010-12-22 19:20:32 +0900482 return -EOPNOTSUPP;
483
Chun-Yeow Yeoh90e62742012-09-14 18:26:11 +0800484 if (key->flags & IEEE80211_KEY_FLAG_RX_MGMT)
485 return -EOPNOTSUPP;
486
Antonio Quartullif9972572012-01-14 11:42:43 +0100487 if (vif->type == NL80211_IFTYPE_ADHOC &&
488 (key->cipher == WLAN_CIPHER_SUITE_TKIP ||
489 key->cipher == WLAN_CIPHER_SUITE_CCMP) &&
490 !(key->flags & IEEE80211_KEY_FLAG_PAIRWISE)) {
491 /* don't program group keys when using IBSS_RSN */
492 return -EOPNOTSUPP;
493 }
494
Bruno Randolfcd2c5482010-12-22 19:20:32 +0900495 switch (key->cipher) {
496 case WLAN_CIPHER_SUITE_WEP40:
497 case WLAN_CIPHER_SUITE_WEP104:
498 case WLAN_CIPHER_SUITE_TKIP:
499 break;
500 case WLAN_CIPHER_SUITE_CCMP:
501 if (common->crypt_caps & ATH_CRYPT_CAP_CIPHER_AESCCM)
502 break;
503 return -EOPNOTSUPP;
504 default:
505 WARN_ON(1);
506 return -EINVAL;
507 }
508
Pavel Roskine0d687b2011-07-14 20:21:55 -0400509 mutex_lock(&ah->lock);
Bruno Randolfcd2c5482010-12-22 19:20:32 +0900510
511 switch (cmd) {
512 case SET_KEY:
513 ret = ath_key_config(common, vif, sta, key);
514 if (ret >= 0) {
515 key->hw_key_idx = ret;
516 /* push IV and Michael MIC generation to stack */
517 key->flags |= IEEE80211_KEY_FLAG_GENERATE_IV;
518 if (key->cipher == WLAN_CIPHER_SUITE_TKIP)
519 key->flags |= IEEE80211_KEY_FLAG_GENERATE_MMIC;
520 if (key->cipher == WLAN_CIPHER_SUITE_CCMP)
Johannes Berge548c492012-09-04 17:08:23 +0200521 key->flags |= IEEE80211_KEY_FLAG_SW_MGMT_TX;
Bruno Randolfcd2c5482010-12-22 19:20:32 +0900522 ret = 0;
523 }
524 break;
525 case DISABLE_KEY:
526 ath_key_delete(common, key);
527 break;
528 default:
529 ret = -EINVAL;
530 }
531
532 mmiowb();
Pavel Roskine0d687b2011-07-14 20:21:55 -0400533 mutex_unlock(&ah->lock);
Bruno Randolfcd2c5482010-12-22 19:20:32 +0900534 return ret;
535}
536
537
538static void
Johannes Berga344d672014-06-12 22:24:31 +0200539ath5k_sw_scan_start(struct ieee80211_hw *hw,
540 struct ieee80211_vif *vif,
541 const u8 *mac_addr)
Bruno Randolfcd2c5482010-12-22 19:20:32 +0900542{
Pavel Roskine0d687b2011-07-14 20:21:55 -0400543 struct ath5k_hw *ah = hw->priv;
544 if (!ah->assoc)
545 ath5k_hw_set_ledstate(ah, AR5K_LED_SCAN);
Bruno Randolfcd2c5482010-12-22 19:20:32 +0900546}
547
548
549static void
Johannes Berga344d672014-06-12 22:24:31 +0200550ath5k_sw_scan_complete(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
Bruno Randolfcd2c5482010-12-22 19:20:32 +0900551{
Pavel Roskine0d687b2011-07-14 20:21:55 -0400552 struct ath5k_hw *ah = hw->priv;
553 ath5k_hw_set_ledstate(ah, ah->assoc ?
Bruno Randolfcd2c5482010-12-22 19:20:32 +0900554 AR5K_LED_ASSOC : AR5K_LED_INIT);
555}
556
557
558static int
559ath5k_get_stats(struct ieee80211_hw *hw,
560 struct ieee80211_low_level_stats *stats)
561{
Pavel Roskine0d687b2011-07-14 20:21:55 -0400562 struct ath5k_hw *ah = hw->priv;
Bruno Randolfcd2c5482010-12-22 19:20:32 +0900563
564 /* Force update */
Pavel Roskine0d687b2011-07-14 20:21:55 -0400565 ath5k_hw_update_mib_counters(ah);
Bruno Randolfcd2c5482010-12-22 19:20:32 +0900566
Pavel Roskine0d687b2011-07-14 20:21:55 -0400567 stats->dot11ACKFailureCount = ah->stats.ack_fail;
568 stats->dot11RTSFailureCount = ah->stats.rts_fail;
569 stats->dot11RTSSuccessCount = ah->stats.rts_ok;
570 stats->dot11FCSErrorCount = ah->stats.fcs_error;
Bruno Randolfcd2c5482010-12-22 19:20:32 +0900571
572 return 0;
573}
574
575
576static int
Eliad Peller8a3a3c82011-10-02 10:15:52 +0200577ath5k_conf_tx(struct ieee80211_hw *hw, struct ieee80211_vif *vif, u16 queue,
Bruno Randolfcd2c5482010-12-22 19:20:32 +0900578 const struct ieee80211_tx_queue_params *params)
579{
Pavel Roskine0d687b2011-07-14 20:21:55 -0400580 struct ath5k_hw *ah = hw->priv;
Bruno Randolfcd2c5482010-12-22 19:20:32 +0900581 struct ath5k_txq_info qi;
582 int ret = 0;
583
584 if (queue >= ah->ah_capabilities.cap_queues.q_tx_num)
585 return 0;
586
Pavel Roskine0d687b2011-07-14 20:21:55 -0400587 mutex_lock(&ah->lock);
Bruno Randolfcd2c5482010-12-22 19:20:32 +0900588
589 ath5k_hw_get_tx_queueprops(ah, queue, &qi);
590
591 qi.tqi_aifs = params->aifs;
592 qi.tqi_cw_min = params->cw_min;
593 qi.tqi_cw_max = params->cw_max;
Felix Fietkau0f245ed2012-07-16 19:49:07 +0200594 qi.tqi_burst_time = params->txop * 32;
Bruno Randolfcd2c5482010-12-22 19:20:32 +0900595
Pavel Roskine0d687b2011-07-14 20:21:55 -0400596 ATH5K_DBG(ah, ATH5K_DEBUG_ANY,
Bruno Randolfcd2c5482010-12-22 19:20:32 +0900597 "Configure tx [queue %d], "
598 "aifs: %d, cw_min: %d, cw_max: %d, txop: %d\n",
599 queue, params->aifs, params->cw_min,
600 params->cw_max, params->txop);
601
602 if (ath5k_hw_set_tx_queueprops(ah, queue, &qi)) {
Pavel Roskine0d687b2011-07-14 20:21:55 -0400603 ATH5K_ERR(ah,
Bruno Randolfcd2c5482010-12-22 19:20:32 +0900604 "Unable to update hardware queue %u!\n", queue);
605 ret = -EIO;
606 } else
607 ath5k_hw_reset_tx_queue(ah, queue);
608
Pavel Roskine0d687b2011-07-14 20:21:55 -0400609 mutex_unlock(&ah->lock);
Bruno Randolfcd2c5482010-12-22 19:20:32 +0900610
611 return ret;
612}
613
614
615static u64
Eliad Peller37a41b42011-09-21 14:06:11 +0300616ath5k_get_tsf(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
Bruno Randolfcd2c5482010-12-22 19:20:32 +0900617{
Pavel Roskine0d687b2011-07-14 20:21:55 -0400618 struct ath5k_hw *ah = hw->priv;
Bruno Randolfcd2c5482010-12-22 19:20:32 +0900619
Pavel Roskine0d687b2011-07-14 20:21:55 -0400620 return ath5k_hw_get_tsf64(ah);
Bruno Randolfcd2c5482010-12-22 19:20:32 +0900621}
622
623
624static void
Eliad Peller37a41b42011-09-21 14:06:11 +0300625ath5k_set_tsf(struct ieee80211_hw *hw, struct ieee80211_vif *vif, u64 tsf)
Bruno Randolfcd2c5482010-12-22 19:20:32 +0900626{
Pavel Roskine0d687b2011-07-14 20:21:55 -0400627 struct ath5k_hw *ah = hw->priv;
Bruno Randolfcd2c5482010-12-22 19:20:32 +0900628
Pavel Roskine0d687b2011-07-14 20:21:55 -0400629 ath5k_hw_set_tsf64(ah, tsf);
Bruno Randolfcd2c5482010-12-22 19:20:32 +0900630}
631
632
633static void
Eliad Peller37a41b42011-09-21 14:06:11 +0300634ath5k_reset_tsf(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
Bruno Randolfcd2c5482010-12-22 19:20:32 +0900635{
Pavel Roskine0d687b2011-07-14 20:21:55 -0400636 struct ath5k_hw *ah = hw->priv;
Bruno Randolfcd2c5482010-12-22 19:20:32 +0900637
638 /*
639 * in IBSS mode we need to update the beacon timers too.
640 * this will also reset the TSF if we call it with 0
641 */
Pavel Roskine0d687b2011-07-14 20:21:55 -0400642 if (ah->opmode == NL80211_IFTYPE_ADHOC)
643 ath5k_beacon_update_timers(ah, 0);
Bruno Randolfcd2c5482010-12-22 19:20:32 +0900644 else
Pavel Roskine0d687b2011-07-14 20:21:55 -0400645 ath5k_hw_reset_tsf(ah);
Bruno Randolfcd2c5482010-12-22 19:20:32 +0900646}
647
648
649static int
650ath5k_get_survey(struct ieee80211_hw *hw, int idx, struct survey_info *survey)
651{
Pavel Roskine0d687b2011-07-14 20:21:55 -0400652 struct ath5k_hw *ah = hw->priv;
Bruno Randolfcd2c5482010-12-22 19:20:32 +0900653 struct ieee80211_conf *conf = &hw->conf;
Pavel Roskine0d687b2011-07-14 20:21:55 -0400654 struct ath_common *common = ath5k_hw_common(ah);
Bruno Randolfcd2c5482010-12-22 19:20:32 +0900655 struct ath_cycle_counters *cc = &common->cc_survey;
656 unsigned int div = common->clockrate * 1000;
657
658 if (idx != 0)
659 return -ENOENT;
660
661 spin_lock_bh(&common->cc_lock);
662 ath_hw_cycle_counters_update(common);
663 if (cc->cycles > 0) {
Johannes Berg4ed20be2014-11-14 16:35:34 +0100664 ah->survey.time += cc->cycles / div;
665 ah->survey.time_busy += cc->rx_busy / div;
666 ah->survey.time_rx += cc->rx_frame / div;
667 ah->survey.time_tx += cc->tx_frame / div;
Bruno Randolfcd2c5482010-12-22 19:20:32 +0900668 }
669 memset(cc, 0, sizeof(*cc));
670 spin_unlock_bh(&common->cc_lock);
671
Pavel Roskine0d687b2011-07-14 20:21:55 -0400672 memcpy(survey, &ah->survey, sizeof(*survey));
Bruno Randolfcd2c5482010-12-22 19:20:32 +0900673
Karl Beldan675a0b02013-03-25 16:26:57 +0100674 survey->channel = conf->chandef.chan;
Pavel Roskine0d687b2011-07-14 20:21:55 -0400675 survey->noise = ah->ah_noise_floor;
Bruno Randolfcd2c5482010-12-22 19:20:32 +0900676 survey->filled = SURVEY_INFO_NOISE_DBM |
Felix Fietkauef1b4142014-02-22 14:55:57 +0100677 SURVEY_INFO_IN_USE |
Johannes Berg4ed20be2014-11-14 16:35:34 +0100678 SURVEY_INFO_TIME |
679 SURVEY_INFO_TIME_BUSY |
680 SURVEY_INFO_TIME_RX |
681 SURVEY_INFO_TIME_TX;
Bruno Randolfcd2c5482010-12-22 19:20:32 +0900682
683 return 0;
684}
685
686
687/**
688 * ath5k_set_coverage_class - Set IEEE 802.11 coverage class
689 *
690 * @hw: struct ieee80211_hw pointer
691 * @coverage_class: IEEE 802.11 coverage class number
692 *
693 * Mac80211 callback. Sets slot time, ACK timeout and CTS timeout for given
694 * coverage class. The values are persistent, they are restored after device
695 * reset.
696 */
697static void
Lorenzo Bianconia4bcaf52014-09-04 23:57:41 +0200698ath5k_set_coverage_class(struct ieee80211_hw *hw, s16 coverage_class)
Bruno Randolfcd2c5482010-12-22 19:20:32 +0900699{
Pavel Roskine0d687b2011-07-14 20:21:55 -0400700 struct ath5k_hw *ah = hw->priv;
Bruno Randolfcd2c5482010-12-22 19:20:32 +0900701
Pavel Roskine0d687b2011-07-14 20:21:55 -0400702 mutex_lock(&ah->lock);
703 ath5k_hw_set_coverage_class(ah, coverage_class);
704 mutex_unlock(&ah->lock);
Bruno Randolfcd2c5482010-12-22 19:20:32 +0900705}
706
707
708static int
709ath5k_set_antenna(struct ieee80211_hw *hw, u32 tx_ant, u32 rx_ant)
710{
Pavel Roskine0d687b2011-07-14 20:21:55 -0400711 struct ath5k_hw *ah = hw->priv;
Bruno Randolfcd2c5482010-12-22 19:20:32 +0900712
713 if (tx_ant == 1 && rx_ant == 1)
Pavel Roskine0d687b2011-07-14 20:21:55 -0400714 ath5k_hw_set_antenna_mode(ah, AR5K_ANTMODE_FIXED_A);
Bruno Randolfcd2c5482010-12-22 19:20:32 +0900715 else if (tx_ant == 2 && rx_ant == 2)
Pavel Roskine0d687b2011-07-14 20:21:55 -0400716 ath5k_hw_set_antenna_mode(ah, AR5K_ANTMODE_FIXED_B);
Bruno Randolfcd2c5482010-12-22 19:20:32 +0900717 else if ((tx_ant & 3) == 3 && (rx_ant & 3) == 3)
Pavel Roskine0d687b2011-07-14 20:21:55 -0400718 ath5k_hw_set_antenna_mode(ah, AR5K_ANTMODE_DEFAULT);
Bruno Randolfcd2c5482010-12-22 19:20:32 +0900719 else
720 return -EINVAL;
721 return 0;
722}
723
724
725static int
726ath5k_get_antenna(struct ieee80211_hw *hw, u32 *tx_ant, u32 *rx_ant)
727{
Pavel Roskine0d687b2011-07-14 20:21:55 -0400728 struct ath5k_hw *ah = hw->priv;
Bruno Randolfcd2c5482010-12-22 19:20:32 +0900729
Pavel Roskine0d687b2011-07-14 20:21:55 -0400730 switch (ah->ah_ant_mode) {
Bruno Randolfcd2c5482010-12-22 19:20:32 +0900731 case AR5K_ANTMODE_FIXED_A:
732 *tx_ant = 1; *rx_ant = 1; break;
733 case AR5K_ANTMODE_FIXED_B:
734 *tx_ant = 2; *rx_ant = 2; break;
735 case AR5K_ANTMODE_DEFAULT:
736 *tx_ant = 3; *rx_ant = 3; break;
737 }
738 return 0;
739}
740
741
John W. Linville81266ba2011-03-07 16:32:59 -0500742static void ath5k_get_ringparam(struct ieee80211_hw *hw,
743 u32 *tx, u32 *tx_max, u32 *rx, u32 *rx_max)
744{
Pavel Roskine0d687b2011-07-14 20:21:55 -0400745 struct ath5k_hw *ah = hw->priv;
John W. Linville81266ba2011-03-07 16:32:59 -0500746
Pavel Roskine0d687b2011-07-14 20:21:55 -0400747 *tx = ah->txqs[AR5K_TX_QUEUE_ID_DATA_MIN].txq_max;
John W. Linville81266ba2011-03-07 16:32:59 -0500748
749 *tx_max = ATH5K_TXQ_LEN_MAX;
750 *rx = *rx_max = ATH_RXBUF;
751}
752
753
754static int ath5k_set_ringparam(struct ieee80211_hw *hw, u32 tx, u32 rx)
755{
Pavel Roskine0d687b2011-07-14 20:21:55 -0400756 struct ath5k_hw *ah = hw->priv;
John W. Linville81266ba2011-03-07 16:32:59 -0500757 u16 qnum;
758
759 /* only support setting tx ring size for now */
760 if (rx != ATH_RXBUF)
761 return -EINVAL;
762
763 /* restrict tx ring size min/max */
764 if (!tx || tx > ATH5K_TXQ_LEN_MAX)
765 return -EINVAL;
766
Pavel Roskine0d687b2011-07-14 20:21:55 -0400767 for (qnum = 0; qnum < ARRAY_SIZE(ah->txqs); qnum++) {
768 if (!ah->txqs[qnum].setup)
John W. Linville81266ba2011-03-07 16:32:59 -0500769 continue;
Pavel Roskine0d687b2011-07-14 20:21:55 -0400770 if (ah->txqs[qnum].qnum < AR5K_TX_QUEUE_ID_DATA_MIN ||
771 ah->txqs[qnum].qnum > AR5K_TX_QUEUE_ID_DATA_MAX)
John W. Linville81266ba2011-03-07 16:32:59 -0500772 continue;
773
Pavel Roskine0d687b2011-07-14 20:21:55 -0400774 ah->txqs[qnum].txq_max = tx;
775 if (ah->txqs[qnum].txq_len >= ah->txqs[qnum].txq_max)
776 ieee80211_stop_queue(hw, ah->txqs[qnum].qnum);
John W. Linville81266ba2011-03-07 16:32:59 -0500777 }
778
779 return 0;
780}
781
782
Bruno Randolfcd2c5482010-12-22 19:20:32 +0900783const struct ieee80211_ops ath5k_hw_ops = {
784 .tx = ath5k_tx,
785 .start = ath5k_start,
786 .stop = ath5k_stop,
787 .add_interface = ath5k_add_interface,
788 /* .change_interface = not implemented */
789 .remove_interface = ath5k_remove_interface,
790 .config = ath5k_config,
791 .bss_info_changed = ath5k_bss_info_changed,
792 .prepare_multicast = ath5k_prepare_multicast,
793 .configure_filter = ath5k_configure_filter,
794 /* .set_tim = not implemented */
795 .set_key = ath5k_set_key,
796 /* .update_tkip_key = not implemented */
797 /* .hw_scan = not implemented */
798 .sw_scan_start = ath5k_sw_scan_start,
799 .sw_scan_complete = ath5k_sw_scan_complete,
800 .get_stats = ath5k_get_stats,
Bruno Randolfcd2c5482010-12-22 19:20:32 +0900801 /* .set_frag_threshold = not implemented */
802 /* .set_rts_threshold = not implemented */
803 /* .sta_add = not implemented */
804 /* .sta_remove = not implemented */
805 /* .sta_notify = not implemented */
806 .conf_tx = ath5k_conf_tx,
807 .get_tsf = ath5k_get_tsf,
808 .set_tsf = ath5k_set_tsf,
809 .reset_tsf = ath5k_reset_tsf,
810 /* .tx_last_beacon = not implemented */
811 /* .ampdu_action = not needed */
812 .get_survey = ath5k_get_survey,
813 .set_coverage_class = ath5k_set_coverage_class,
814 /* .rfkill_poll = not implemented */
815 /* .flush = not implemented */
816 /* .channel_switch = not implemented */
817 /* .napi_poll = not implemented */
818 .set_antenna = ath5k_set_antenna,
819 .get_antenna = ath5k_get_antenna,
John W. Linville81266ba2011-03-07 16:32:59 -0500820 .set_ringparam = ath5k_set_ringparam,
821 .get_ringparam = ath5k_get_ringparam,
Bruno Randolfcd2c5482010-12-22 19:20:32 +0900822};