blob: d56453e43d7e353e0890d3962e264448d7185771 [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
Bruno Randolfcd2c5482010-12-22 19:20:32 +090058ath5k_tx(struct ieee80211_hw *hw, struct sk_buff *skb)
59{
Pavel Roskine0d687b2011-07-14 20:21:55 -040060 struct ath5k_hw *ah = hw->priv;
Bruno Randolfcd2c5482010-12-22 19:20:32 +090061 u16 qnum = skb_get_queue_mapping(skb);
62
Pavel Roskine0d687b2011-07-14 20:21:55 -040063 if (WARN_ON(qnum >= ah->ah_capabilities.cap_queues.q_tx_num)) {
Bruno Randolfcd2c5482010-12-22 19:20:32 +090064 dev_kfree_skb_any(skb);
Johannes Berg7bb45682011-02-24 14:42:06 +010065 return;
Bruno Randolfcd2c5482010-12-22 19:20:32 +090066 }
67
Pavel Roskine0d687b2011-07-14 20:21:55 -040068 ath5k_tx_queue(hw, skb, &ah->txqs[qnum]);
Bruno Randolfcd2c5482010-12-22 19:20:32 +090069}
70
71
72static int
Bruno Randolfcd2c5482010-12-22 19:20:32 +090073ath5k_add_interface(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
74{
Pavel Roskine0d687b2011-07-14 20:21:55 -040075 struct ath5k_hw *ah = hw->priv;
Bruno Randolfcd2c5482010-12-22 19:20:32 +090076 int ret;
77 struct ath5k_vif *avf = (void *)vif->drv_priv;
78
Pavel Roskine0d687b2011-07-14 20:21:55 -040079 mutex_lock(&ah->lock);
Bruno Randolfcd2c5482010-12-22 19:20:32 +090080
81 if ((vif->type == NL80211_IFTYPE_AP ||
82 vif->type == NL80211_IFTYPE_ADHOC)
Pavel Roskine0d687b2011-07-14 20:21:55 -040083 && (ah->num_ap_vifs + ah->num_adhoc_vifs) >= ATH_BCBUF) {
Bruno Randolfcd2c5482010-12-22 19:20:32 +090084 ret = -ELNRNG;
85 goto end;
86 }
87
88 /* Don't allow other interfaces if one ad-hoc is configured.
89 * TODO: Fix the problems with ad-hoc and multiple other interfaces.
90 * We would need to operate the HW in ad-hoc mode to allow TSF updates
91 * for the IBSS, but this breaks with additional AP or STA interfaces
92 * at the moment. */
Pavel Roskine0d687b2011-07-14 20:21:55 -040093 if (ah->num_adhoc_vifs ||
94 (ah->nvifs && vif->type == NL80211_IFTYPE_ADHOC)) {
95 ATH5K_ERR(ah, "Only one single ad-hoc interface is allowed.\n");
Bruno Randolfcd2c5482010-12-22 19:20:32 +090096 ret = -ELNRNG;
97 goto end;
98 }
99
100 switch (vif->type) {
101 case NL80211_IFTYPE_AP:
102 case NL80211_IFTYPE_STATION:
103 case NL80211_IFTYPE_ADHOC:
104 case NL80211_IFTYPE_MESH_POINT:
105 avf->opmode = vif->type;
106 break;
107 default:
108 ret = -EOPNOTSUPP;
109 goto end;
110 }
111
Pavel Roskine0d687b2011-07-14 20:21:55 -0400112 ah->nvifs++;
113 ATH5K_DBG(ah, ATH5K_DEBUG_MODE, "add interface mode %d\n", avf->opmode);
Bruno Randolfcd2c5482010-12-22 19:20:32 +0900114
115 /* Assign the vap/adhoc to a beacon xmit slot. */
116 if ((avf->opmode == NL80211_IFTYPE_AP) ||
117 (avf->opmode == NL80211_IFTYPE_ADHOC) ||
118 (avf->opmode == NL80211_IFTYPE_MESH_POINT)) {
119 int slot;
120
Pavel Roskine0d687b2011-07-14 20:21:55 -0400121 WARN_ON(list_empty(&ah->bcbuf));
122 avf->bbuf = list_first_entry(&ah->bcbuf, struct ath5k_buf,
Bruno Randolfcd2c5482010-12-22 19:20:32 +0900123 list);
124 list_del(&avf->bbuf->list);
125
126 avf->bslot = 0;
127 for (slot = 0; slot < ATH_BCBUF; slot++) {
Pavel Roskine0d687b2011-07-14 20:21:55 -0400128 if (!ah->bslot[slot]) {
Bruno Randolfcd2c5482010-12-22 19:20:32 +0900129 avf->bslot = slot;
130 break;
131 }
132 }
Pavel Roskine0d687b2011-07-14 20:21:55 -0400133 BUG_ON(ah->bslot[avf->bslot] != NULL);
134 ah->bslot[avf->bslot] = vif;
Bruno Randolfcd2c5482010-12-22 19:20:32 +0900135 if (avf->opmode == NL80211_IFTYPE_AP)
Pavel Roskine0d687b2011-07-14 20:21:55 -0400136 ah->num_ap_vifs++;
Bruno Randolfcd2c5482010-12-22 19:20:32 +0900137 else if (avf->opmode == NL80211_IFTYPE_ADHOC)
Pavel Roskine0d687b2011-07-14 20:21:55 -0400138 ah->num_adhoc_vifs++;
Chun-Yeow Yeohda473b62012-03-03 09:48:56 +0800139 else if (avf->opmode == NL80211_IFTYPE_MESH_POINT)
140 ah->num_mesh_vifs++;
Bruno Randolfcd2c5482010-12-22 19:20:32 +0900141 }
142
143 /* Any MAC address is fine, all others are included through the
144 * filter.
145 */
Pavel Roskine0d687b2011-07-14 20:21:55 -0400146 ath5k_hw_set_lladdr(ah, vif->addr);
Bruno Randolfcd2c5482010-12-22 19:20:32 +0900147
Pavel Roskine0d687b2011-07-14 20:21:55 -0400148 ath5k_update_bssid_mask_and_opmode(ah, vif);
Bruno Randolfcd2c5482010-12-22 19:20:32 +0900149 ret = 0;
150end:
Pavel Roskine0d687b2011-07-14 20:21:55 -0400151 mutex_unlock(&ah->lock);
Bruno Randolfcd2c5482010-12-22 19:20:32 +0900152 return ret;
153}
154
155
156static void
157ath5k_remove_interface(struct ieee80211_hw *hw,
158 struct ieee80211_vif *vif)
159{
Pavel Roskine0d687b2011-07-14 20:21:55 -0400160 struct ath5k_hw *ah = hw->priv;
Bruno Randolfcd2c5482010-12-22 19:20:32 +0900161 struct ath5k_vif *avf = (void *)vif->drv_priv;
162 unsigned int i;
163
Pavel Roskine0d687b2011-07-14 20:21:55 -0400164 mutex_lock(&ah->lock);
165 ah->nvifs--;
Bruno Randolfcd2c5482010-12-22 19:20:32 +0900166
167 if (avf->bbuf) {
Pavel Roskine0d687b2011-07-14 20:21:55 -0400168 ath5k_txbuf_free_skb(ah, avf->bbuf);
169 list_add_tail(&avf->bbuf->list, &ah->bcbuf);
Bruno Randolfcd2c5482010-12-22 19:20:32 +0900170 for (i = 0; i < ATH_BCBUF; i++) {
Pavel Roskine0d687b2011-07-14 20:21:55 -0400171 if (ah->bslot[i] == vif) {
172 ah->bslot[i] = NULL;
Bruno Randolfcd2c5482010-12-22 19:20:32 +0900173 break;
174 }
175 }
176 avf->bbuf = NULL;
177 }
178 if (avf->opmode == NL80211_IFTYPE_AP)
Pavel Roskine0d687b2011-07-14 20:21:55 -0400179 ah->num_ap_vifs--;
Bruno Randolfcd2c5482010-12-22 19:20:32 +0900180 else if (avf->opmode == NL80211_IFTYPE_ADHOC)
Pavel Roskine0d687b2011-07-14 20:21:55 -0400181 ah->num_adhoc_vifs--;
Chun-Yeow Yeohda473b62012-03-03 09:48:56 +0800182 else if (avf->opmode == NL80211_IFTYPE_MESH_POINT)
183 ah->num_mesh_vifs--;
Bruno Randolfcd2c5482010-12-22 19:20:32 +0900184
Pavel Roskine0d687b2011-07-14 20:21:55 -0400185 ath5k_update_bssid_mask_and_opmode(ah, NULL);
186 mutex_unlock(&ah->lock);
Bruno Randolfcd2c5482010-12-22 19:20:32 +0900187}
188
189
190/*
191 * TODO: Phy disable/diversity etc
192 */
193static int
194ath5k_config(struct ieee80211_hw *hw, u32 changed)
195{
Pavel Roskine0d687b2011-07-14 20:21:55 -0400196 struct ath5k_hw *ah = hw->priv;
Bruno Randolfcd2c5482010-12-22 19:20:32 +0900197 struct ieee80211_conf *conf = &hw->conf;
198 int ret = 0;
Bruno Randolf76a9f6f2011-01-28 16:52:11 +0900199 int i;
Bruno Randolfcd2c5482010-12-22 19:20:32 +0900200
Pavel Roskine0d687b2011-07-14 20:21:55 -0400201 mutex_lock(&ah->lock);
Bruno Randolfcd2c5482010-12-22 19:20:32 +0900202
203 if (changed & IEEE80211_CONF_CHANGE_CHANNEL) {
Pavel Roskine0d687b2011-07-14 20:21:55 -0400204 ret = ath5k_chan_set(ah, conf->channel);
Bruno Randolfcd2c5482010-12-22 19:20:32 +0900205 if (ret < 0)
206 goto unlock;
207 }
208
209 if ((changed & IEEE80211_CONF_CHANGE_POWER) &&
Pavel Roskine0d687b2011-07-14 20:21:55 -0400210 (ah->power_level != conf->power_level)) {
211 ah->power_level = conf->power_level;
Bruno Randolfcd2c5482010-12-22 19:20:32 +0900212
213 /* Half dB steps */
214 ath5k_hw_set_txpower_limit(ah, (conf->power_level * 2));
215 }
216
Bruno Randolf76a9f6f2011-01-28 16:52:11 +0900217 if (changed & IEEE80211_CONF_CHANGE_RETRY_LIMITS) {
218 ah->ah_retry_long = conf->long_frame_max_tx_count;
219 ah->ah_retry_short = conf->short_frame_max_tx_count;
220
221 for (i = 0; i < ah->ah_capabilities.cap_queues.q_tx_num; i++)
222 ath5k_hw_set_tx_retry_limits(ah, i);
223 }
224
Bruno Randolfcd2c5482010-12-22 19:20:32 +0900225 /* TODO:
226 * 1) Move this on config_interface and handle each case
227 * separately eg. when we have only one STA vif, use
228 * AR5K_ANTMODE_SINGLE_AP
229 *
230 * 2) Allow the user to change antenna mode eg. when only
231 * one antenna is present
232 *
233 * 3) Allow the user to set default/tx antenna when possible
234 *
235 * 4) Default mode should handle 90% of the cases, together
236 * with fixed a/b and single AP modes we should be able to
237 * handle 99%. Sectored modes are extreme cases and i still
238 * haven't found a usage for them. If we decide to support them,
239 * then we must allow the user to set how many tx antennas we
240 * have available
241 */
242 ath5k_hw_set_antenna_mode(ah, ah->ah_ant_mode);
243
244unlock:
Pavel Roskine0d687b2011-07-14 20:21:55 -0400245 mutex_unlock(&ah->lock);
Bruno Randolfcd2c5482010-12-22 19:20:32 +0900246 return ret;
247}
248
249
250static void
251ath5k_bss_info_changed(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
252 struct ieee80211_bss_conf *bss_conf, u32 changes)
253{
254 struct ath5k_vif *avf = (void *)vif->drv_priv;
Pavel Roskine0d687b2011-07-14 20:21:55 -0400255 struct ath5k_hw *ah = hw->priv;
Bruno Randolfcd2c5482010-12-22 19:20:32 +0900256 struct ath_common *common = ath5k_hw_common(ah);
Bruno Randolfcd2c5482010-12-22 19:20:32 +0900257
Pavel Roskine0d687b2011-07-14 20:21:55 -0400258 mutex_lock(&ah->lock);
Bruno Randolfcd2c5482010-12-22 19:20:32 +0900259
260 if (changes & BSS_CHANGED_BSSID) {
261 /* Cache for later use during resets */
262 memcpy(common->curbssid, bss_conf->bssid, ETH_ALEN);
263 common->curaid = 0;
264 ath5k_hw_set_bssid(ah);
265 mmiowb();
266 }
267
268 if (changes & BSS_CHANGED_BEACON_INT)
Pavel Roskine0d687b2011-07-14 20:21:55 -0400269 ah->bintval = bss_conf->beacon_int;
Bruno Randolfcd2c5482010-12-22 19:20:32 +0900270
Felix Fietkaub1ad1b62011-04-09 23:10:21 +0200271 if (changes & BSS_CHANGED_ERP_SLOT) {
272 int slot_time;
273
274 ah->ah_short_slot = bss_conf->use_short_slot;
275 slot_time = ath5k_hw_get_default_slottime(ah) +
276 3 * ah->ah_coverage_class;
277 ath5k_hw_set_ifs_intervals(ah, slot_time);
278 }
279
Bruno Randolfcd2c5482010-12-22 19:20:32 +0900280 if (changes & BSS_CHANGED_ASSOC) {
281 avf->assoc = bss_conf->assoc;
282 if (bss_conf->assoc)
Pavel Roskine0d687b2011-07-14 20:21:55 -0400283 ah->assoc = bss_conf->assoc;
Bruno Randolfcd2c5482010-12-22 19:20:32 +0900284 else
Pavel Roskine0d687b2011-07-14 20:21:55 -0400285 ah->assoc = ath5k_any_vif_assoc(ah);
Bruno Randolfcd2c5482010-12-22 19:20:32 +0900286
Pavel Roskine0d687b2011-07-14 20:21:55 -0400287 if (ah->opmode == NL80211_IFTYPE_STATION)
288 ath5k_set_beacon_filter(hw, ah->assoc);
289 ath5k_hw_set_ledstate(ah, ah->assoc ?
Bruno Randolfcd2c5482010-12-22 19:20:32 +0900290 AR5K_LED_ASSOC : AR5K_LED_INIT);
291 if (bss_conf->assoc) {
Pavel Roskine0d687b2011-07-14 20:21:55 -0400292 ATH5K_DBG(ah, ATH5K_DEBUG_ANY,
Bruno Randolfcd2c5482010-12-22 19:20:32 +0900293 "Bss Info ASSOC %d, bssid: %pM\n",
294 bss_conf->aid, common->curbssid);
295 common->curaid = bss_conf->aid;
296 ath5k_hw_set_bssid(ah);
297 /* Once ANI is available you would start it here */
298 }
299 }
300
301 if (changes & BSS_CHANGED_BEACON) {
Bob Copeland7dd67532012-08-12 21:18:33 -0400302 spin_lock_bh(&ah->block);
Bruno Randolfcd2c5482010-12-22 19:20:32 +0900303 ath5k_beacon_update(hw, vif);
Bob Copeland7dd67532012-08-12 21:18:33 -0400304 spin_unlock_bh(&ah->block);
Bruno Randolfcd2c5482010-12-22 19:20:32 +0900305 }
306
307 if (changes & BSS_CHANGED_BEACON_ENABLED)
Pavel Roskine0d687b2011-07-14 20:21:55 -0400308 ah->enable_beacon = bss_conf->enable_beacon;
Bruno Randolfcd2c5482010-12-22 19:20:32 +0900309
310 if (changes & (BSS_CHANGED_BEACON | BSS_CHANGED_BEACON_ENABLED |
311 BSS_CHANGED_BEACON_INT))
Pavel Roskine0d687b2011-07-14 20:21:55 -0400312 ath5k_beacon_config(ah);
Bruno Randolfcd2c5482010-12-22 19:20:32 +0900313
Pavel Roskine0d687b2011-07-14 20:21:55 -0400314 mutex_unlock(&ah->lock);
Bruno Randolfcd2c5482010-12-22 19:20:32 +0900315}
316
317
318static u64
319ath5k_prepare_multicast(struct ieee80211_hw *hw,
320 struct netdev_hw_addr_list *mc_list)
321{
322 u32 mfilt[2], val;
323 u8 pos;
324 struct netdev_hw_addr *ha;
325
326 mfilt[0] = 0;
327 mfilt[1] = 1;
328
329 netdev_hw_addr_list_for_each(ha, mc_list) {
330 /* calculate XOR of eight 6-bit values */
331 val = get_unaligned_le32(ha->addr + 0);
332 pos = (val >> 18) ^ (val >> 12) ^ (val >> 6) ^ val;
333 val = get_unaligned_le32(ha->addr + 3);
334 pos ^= (val >> 18) ^ (val >> 12) ^ (val >> 6) ^ val;
335 pos &= 0x3f;
336 mfilt[pos / 32] |= (1 << (pos % 32));
337 /* XXX: we might be able to just do this instead,
338 * but not sure, needs testing, if we do use this we'd
Pavel Roskin6a2a0e72011-07-09 00:17:51 -0400339 * need to inform below not to reset the mcast */
Bruno Randolfcd2c5482010-12-22 19:20:32 +0900340 /* ath5k_hw_set_mcast_filterindex(ah,
341 * ha->addr[5]); */
342 }
343
344 return ((u64)(mfilt[1]) << 32) | mfilt[0];
345}
346
347
348/*
349 * o always accept unicast, broadcast, and multicast traffic
350 * o multicast traffic for all BSSIDs will be enabled if mac80211
351 * says it should be
352 * o maintain current state of phy ofdm or phy cck error reception.
353 * If the hardware detects any of these type of errors then
354 * ath5k_hw_get_rx_filter() will pass to us the respective
355 * hardware filters to be able to receive these type of frames.
356 * o probe request frames are accepted only when operating in
357 * hostap, adhoc, or monitor modes
358 * o enable promiscuous mode according to the interface state
359 * o accept beacons:
360 * - when operating in adhoc mode so the 802.11 layer creates
361 * node table entries for peers,
362 * - when operating in station mode for collecting rssi data when
363 * the station is otherwise quiet, or
364 * - when scanning
365 */
366static void
367ath5k_configure_filter(struct ieee80211_hw *hw, unsigned int changed_flags,
368 unsigned int *new_flags, u64 multicast)
369{
370#define SUPPORTED_FIF_FLAGS \
371 (FIF_PROMISC_IN_BSS | FIF_ALLMULTI | FIF_FCSFAIL | \
372 FIF_PLCPFAIL | FIF_CONTROL | FIF_OTHER_BSS | \
373 FIF_BCN_PRBRESP_PROMISC)
374
Pavel Roskine0d687b2011-07-14 20:21:55 -0400375 struct ath5k_hw *ah = hw->priv;
Bruno Randolfcd2c5482010-12-22 19:20:32 +0900376 u32 mfilt[2], rfilt;
Ben Greeare4b0b322011-03-03 14:39:05 -0800377 struct ath5k_vif_iter_data iter_data; /* to count STA interfaces */
Bruno Randolfcd2c5482010-12-22 19:20:32 +0900378
Pavel Roskine0d687b2011-07-14 20:21:55 -0400379 mutex_lock(&ah->lock);
Bruno Randolfcd2c5482010-12-22 19:20:32 +0900380
381 mfilt[0] = multicast;
382 mfilt[1] = multicast >> 32;
383
384 /* Only deal with supported flags */
385 changed_flags &= SUPPORTED_FIF_FLAGS;
386 *new_flags &= SUPPORTED_FIF_FLAGS;
387
388 /* If HW detects any phy or radar errors, leave those filters on.
389 * Also, always enable Unicast, Broadcasts and Multicast
390 * XXX: move unicast, bssid broadcasts and multicast to mac80211 */
391 rfilt = (ath5k_hw_get_rx_filter(ah) & (AR5K_RX_FILTER_PHYERR)) |
392 (AR5K_RX_FILTER_UCAST | AR5K_RX_FILTER_BCAST |
393 AR5K_RX_FILTER_MCAST);
394
395 if (changed_flags & (FIF_PROMISC_IN_BSS | FIF_OTHER_BSS)) {
396 if (*new_flags & FIF_PROMISC_IN_BSS)
Pavel Roskine0d687b2011-07-14 20:21:55 -0400397 __set_bit(ATH_STAT_PROMISC, ah->status);
Bruno Randolfcd2c5482010-12-22 19:20:32 +0900398 else
Pavel Roskine0d687b2011-07-14 20:21:55 -0400399 __clear_bit(ATH_STAT_PROMISC, ah->status);
Bruno Randolfcd2c5482010-12-22 19:20:32 +0900400 }
401
Pavel Roskine0d687b2011-07-14 20:21:55 -0400402 if (test_bit(ATH_STAT_PROMISC, ah->status))
Bruno Randolfcd2c5482010-12-22 19:20:32 +0900403 rfilt |= AR5K_RX_FILTER_PROM;
404
405 /* Note, AR5K_RX_FILTER_MCAST is already enabled */
406 if (*new_flags & FIF_ALLMULTI) {
407 mfilt[0] = ~0;
408 mfilt[1] = ~0;
409 }
410
411 /* This is the best we can do */
412 if (*new_flags & (FIF_FCSFAIL | FIF_PLCPFAIL))
413 rfilt |= AR5K_RX_FILTER_PHYERR;
414
415 /* FIF_BCN_PRBRESP_PROMISC really means to enable beacons
416 * and probes for any BSSID */
Pavel Roskine0d687b2011-07-14 20:21:55 -0400417 if ((*new_flags & FIF_BCN_PRBRESP_PROMISC) || (ah->nvifs > 1))
Bruno Randolfcd2c5482010-12-22 19:20:32 +0900418 rfilt |= AR5K_RX_FILTER_BEACON;
419
420 /* FIF_CONTROL doc says that if FIF_PROMISC_IN_BSS is not
421 * set we should only pass on control frames for this
422 * station. This needs testing. I believe right now this
423 * enables *all* control frames, which is OK.. but
424 * but we should see if we can improve on granularity */
425 if (*new_flags & FIF_CONTROL)
426 rfilt |= AR5K_RX_FILTER_CONTROL;
427
428 /* Additional settings per mode -- this is per ath5k */
429
430 /* XXX move these to mac80211, and add a beacon IFF flag to mac80211 */
431
Pavel Roskine0d687b2011-07-14 20:21:55 -0400432 switch (ah->opmode) {
Bruno Randolfcd2c5482010-12-22 19:20:32 +0900433 case NL80211_IFTYPE_MESH_POINT:
434 rfilt |= AR5K_RX_FILTER_CONTROL |
435 AR5K_RX_FILTER_BEACON |
436 AR5K_RX_FILTER_PROBEREQ |
437 AR5K_RX_FILTER_PROM;
438 break;
439 case NL80211_IFTYPE_AP:
440 case NL80211_IFTYPE_ADHOC:
441 rfilt |= AR5K_RX_FILTER_PROBEREQ |
442 AR5K_RX_FILTER_BEACON;
443 break;
444 case NL80211_IFTYPE_STATION:
Pavel Roskine0d687b2011-07-14 20:21:55 -0400445 if (ah->assoc)
Bruno Randolfcd2c5482010-12-22 19:20:32 +0900446 rfilt |= AR5K_RX_FILTER_BEACON;
447 default:
448 break;
449 }
450
Ben Greeare4b0b322011-03-03 14:39:05 -0800451 iter_data.hw_macaddr = NULL;
452 iter_data.n_stas = 0;
453 iter_data.need_set_hw_addr = false;
Pavel Roskine0d687b2011-07-14 20:21:55 -0400454 ieee80211_iterate_active_interfaces_atomic(ah->hw, ath5k_vif_iter,
Ben Greeare4b0b322011-03-03 14:39:05 -0800455 &iter_data);
456
457 /* Set up RX Filter */
458 if (iter_data.n_stas > 1) {
459 /* If you have multiple STA interfaces connected to
460 * different APs, ARPs are not received (most of the time?)
Pavel Roskin6a2a0e72011-07-09 00:17:51 -0400461 * Enabling PROMISC appears to fix that problem.
Ben Greeare4b0b322011-03-03 14:39:05 -0800462 */
463 rfilt |= AR5K_RX_FILTER_PROM;
464 }
465
Bruno Randolfcd2c5482010-12-22 19:20:32 +0900466 /* Set filters */
467 ath5k_hw_set_rx_filter(ah, rfilt);
468
469 /* Set multicast bits */
470 ath5k_hw_set_mcast_filter(ah, mfilt[0], mfilt[1]);
471 /* Set the cached hw filter flags, this will later actually
472 * be set in HW */
Pavel Roskine0d687b2011-07-14 20:21:55 -0400473 ah->filter_flags = rfilt;
Bruno Randolfcd2c5482010-12-22 19:20:32 +0900474
Pavel Roskine0d687b2011-07-14 20:21:55 -0400475 mutex_unlock(&ah->lock);
Bruno Randolfcd2c5482010-12-22 19:20:32 +0900476}
477
478
479static int
480ath5k_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
481 struct ieee80211_vif *vif, struct ieee80211_sta *sta,
482 struct ieee80211_key_conf *key)
483{
Pavel Roskine0d687b2011-07-14 20:21:55 -0400484 struct ath5k_hw *ah = hw->priv;
Bruno Randolfcd2c5482010-12-22 19:20:32 +0900485 struct ath_common *common = ath5k_hw_common(ah);
486 int ret = 0;
487
John W. Linville18cb6e32011-01-05 09:39:59 -0500488 if (ath5k_modparam_nohwcrypt)
Bruno Randolfcd2c5482010-12-22 19:20:32 +0900489 return -EOPNOTSUPP;
490
Antonio Quartullif9972572012-01-14 11:42:43 +0100491 if (vif->type == NL80211_IFTYPE_ADHOC &&
492 (key->cipher == WLAN_CIPHER_SUITE_TKIP ||
493 key->cipher == WLAN_CIPHER_SUITE_CCMP) &&
494 !(key->flags & IEEE80211_KEY_FLAG_PAIRWISE)) {
495 /* don't program group keys when using IBSS_RSN */
496 return -EOPNOTSUPP;
497 }
498
Bruno Randolfcd2c5482010-12-22 19:20:32 +0900499 switch (key->cipher) {
500 case WLAN_CIPHER_SUITE_WEP40:
501 case WLAN_CIPHER_SUITE_WEP104:
502 case WLAN_CIPHER_SUITE_TKIP:
503 break;
504 case WLAN_CIPHER_SUITE_CCMP:
505 if (common->crypt_caps & ATH_CRYPT_CAP_CIPHER_AESCCM)
506 break;
507 return -EOPNOTSUPP;
508 default:
509 WARN_ON(1);
510 return -EINVAL;
511 }
512
Pavel Roskine0d687b2011-07-14 20:21:55 -0400513 mutex_lock(&ah->lock);
Bruno Randolfcd2c5482010-12-22 19:20:32 +0900514
515 switch (cmd) {
516 case SET_KEY:
517 ret = ath_key_config(common, vif, sta, key);
518 if (ret >= 0) {
519 key->hw_key_idx = ret;
520 /* push IV and Michael MIC generation to stack */
521 key->flags |= IEEE80211_KEY_FLAG_GENERATE_IV;
522 if (key->cipher == WLAN_CIPHER_SUITE_TKIP)
523 key->flags |= IEEE80211_KEY_FLAG_GENERATE_MMIC;
524 if (key->cipher == WLAN_CIPHER_SUITE_CCMP)
525 key->flags |= IEEE80211_KEY_FLAG_SW_MGMT;
526 ret = 0;
527 }
528 break;
529 case DISABLE_KEY:
530 ath_key_delete(common, key);
531 break;
532 default:
533 ret = -EINVAL;
534 }
535
536 mmiowb();
Pavel Roskine0d687b2011-07-14 20:21:55 -0400537 mutex_unlock(&ah->lock);
Bruno Randolfcd2c5482010-12-22 19:20:32 +0900538 return ret;
539}
540
541
542static void
543ath5k_sw_scan_start(struct ieee80211_hw *hw)
544{
Pavel Roskine0d687b2011-07-14 20:21:55 -0400545 struct ath5k_hw *ah = hw->priv;
546 if (!ah->assoc)
547 ath5k_hw_set_ledstate(ah, AR5K_LED_SCAN);
Bruno Randolfcd2c5482010-12-22 19:20:32 +0900548}
549
550
551static void
552ath5k_sw_scan_complete(struct ieee80211_hw *hw)
553{
Pavel Roskine0d687b2011-07-14 20:21:55 -0400554 struct ath5k_hw *ah = hw->priv;
555 ath5k_hw_set_ledstate(ah, ah->assoc ?
Bruno Randolfcd2c5482010-12-22 19:20:32 +0900556 AR5K_LED_ASSOC : AR5K_LED_INIT);
557}
558
559
560static int
561ath5k_get_stats(struct ieee80211_hw *hw,
562 struct ieee80211_low_level_stats *stats)
563{
Pavel Roskine0d687b2011-07-14 20:21:55 -0400564 struct ath5k_hw *ah = hw->priv;
Bruno Randolfcd2c5482010-12-22 19:20:32 +0900565
566 /* Force update */
Pavel Roskine0d687b2011-07-14 20:21:55 -0400567 ath5k_hw_update_mib_counters(ah);
Bruno Randolfcd2c5482010-12-22 19:20:32 +0900568
Pavel Roskine0d687b2011-07-14 20:21:55 -0400569 stats->dot11ACKFailureCount = ah->stats.ack_fail;
570 stats->dot11RTSFailureCount = ah->stats.rts_fail;
571 stats->dot11RTSSuccessCount = ah->stats.rts_ok;
572 stats->dot11FCSErrorCount = ah->stats.fcs_error;
Bruno Randolfcd2c5482010-12-22 19:20:32 +0900573
574 return 0;
575}
576
577
578static int
Eliad Peller8a3a3c82011-10-02 10:15:52 +0200579ath5k_conf_tx(struct ieee80211_hw *hw, struct ieee80211_vif *vif, u16 queue,
Bruno Randolfcd2c5482010-12-22 19:20:32 +0900580 const struct ieee80211_tx_queue_params *params)
581{
Pavel Roskine0d687b2011-07-14 20:21:55 -0400582 struct ath5k_hw *ah = hw->priv;
Bruno Randolfcd2c5482010-12-22 19:20:32 +0900583 struct ath5k_txq_info qi;
584 int ret = 0;
585
586 if (queue >= ah->ah_capabilities.cap_queues.q_tx_num)
587 return 0;
588
Pavel Roskine0d687b2011-07-14 20:21:55 -0400589 mutex_lock(&ah->lock);
Bruno Randolfcd2c5482010-12-22 19:20:32 +0900590
591 ath5k_hw_get_tx_queueprops(ah, queue, &qi);
592
593 qi.tqi_aifs = params->aifs;
594 qi.tqi_cw_min = params->cw_min;
595 qi.tqi_cw_max = params->cw_max;
Felix Fietkau0f245ed2012-07-16 19:49:07 +0200596 qi.tqi_burst_time = params->txop * 32;
Bruno Randolfcd2c5482010-12-22 19:20:32 +0900597
Pavel Roskine0d687b2011-07-14 20:21:55 -0400598 ATH5K_DBG(ah, ATH5K_DEBUG_ANY,
Bruno Randolfcd2c5482010-12-22 19:20:32 +0900599 "Configure tx [queue %d], "
600 "aifs: %d, cw_min: %d, cw_max: %d, txop: %d\n",
601 queue, params->aifs, params->cw_min,
602 params->cw_max, params->txop);
603
604 if (ath5k_hw_set_tx_queueprops(ah, queue, &qi)) {
Pavel Roskine0d687b2011-07-14 20:21:55 -0400605 ATH5K_ERR(ah,
Bruno Randolfcd2c5482010-12-22 19:20:32 +0900606 "Unable to update hardware queue %u!\n", queue);
607 ret = -EIO;
608 } else
609 ath5k_hw_reset_tx_queue(ah, queue);
610
Pavel Roskine0d687b2011-07-14 20:21:55 -0400611 mutex_unlock(&ah->lock);
Bruno Randolfcd2c5482010-12-22 19:20:32 +0900612
613 return ret;
614}
615
616
617static u64
Eliad Peller37a41b42011-09-21 14:06:11 +0300618ath5k_get_tsf(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
Bruno Randolfcd2c5482010-12-22 19:20:32 +0900619{
Pavel Roskine0d687b2011-07-14 20:21:55 -0400620 struct ath5k_hw *ah = hw->priv;
Bruno Randolfcd2c5482010-12-22 19:20:32 +0900621
Pavel Roskine0d687b2011-07-14 20:21:55 -0400622 return ath5k_hw_get_tsf64(ah);
Bruno Randolfcd2c5482010-12-22 19:20:32 +0900623}
624
625
626static void
Eliad Peller37a41b42011-09-21 14:06:11 +0300627ath5k_set_tsf(struct ieee80211_hw *hw, struct ieee80211_vif *vif, u64 tsf)
Bruno Randolfcd2c5482010-12-22 19:20:32 +0900628{
Pavel Roskine0d687b2011-07-14 20:21:55 -0400629 struct ath5k_hw *ah = hw->priv;
Bruno Randolfcd2c5482010-12-22 19:20:32 +0900630
Pavel Roskine0d687b2011-07-14 20:21:55 -0400631 ath5k_hw_set_tsf64(ah, tsf);
Bruno Randolfcd2c5482010-12-22 19:20:32 +0900632}
633
634
635static void
Eliad Peller37a41b42011-09-21 14:06:11 +0300636ath5k_reset_tsf(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
Bruno Randolfcd2c5482010-12-22 19:20:32 +0900637{
Pavel Roskine0d687b2011-07-14 20:21:55 -0400638 struct ath5k_hw *ah = hw->priv;
Bruno Randolfcd2c5482010-12-22 19:20:32 +0900639
640 /*
641 * in IBSS mode we need to update the beacon timers too.
642 * this will also reset the TSF if we call it with 0
643 */
Pavel Roskine0d687b2011-07-14 20:21:55 -0400644 if (ah->opmode == NL80211_IFTYPE_ADHOC)
645 ath5k_beacon_update_timers(ah, 0);
Bruno Randolfcd2c5482010-12-22 19:20:32 +0900646 else
Pavel Roskine0d687b2011-07-14 20:21:55 -0400647 ath5k_hw_reset_tsf(ah);
Bruno Randolfcd2c5482010-12-22 19:20:32 +0900648}
649
650
651static int
652ath5k_get_survey(struct ieee80211_hw *hw, int idx, struct survey_info *survey)
653{
Pavel Roskine0d687b2011-07-14 20:21:55 -0400654 struct ath5k_hw *ah = hw->priv;
Bruno Randolfcd2c5482010-12-22 19:20:32 +0900655 struct ieee80211_conf *conf = &hw->conf;
Pavel Roskine0d687b2011-07-14 20:21:55 -0400656 struct ath_common *common = ath5k_hw_common(ah);
Bruno Randolfcd2c5482010-12-22 19:20:32 +0900657 struct ath_cycle_counters *cc = &common->cc_survey;
658 unsigned int div = common->clockrate * 1000;
659
660 if (idx != 0)
661 return -ENOENT;
662
663 spin_lock_bh(&common->cc_lock);
664 ath_hw_cycle_counters_update(common);
665 if (cc->cycles > 0) {
Pavel Roskine0d687b2011-07-14 20:21:55 -0400666 ah->survey.channel_time += cc->cycles / div;
667 ah->survey.channel_time_busy += cc->rx_busy / div;
668 ah->survey.channel_time_rx += cc->rx_frame / div;
669 ah->survey.channel_time_tx += cc->tx_frame / div;
Bruno Randolfcd2c5482010-12-22 19:20:32 +0900670 }
671 memset(cc, 0, sizeof(*cc));
672 spin_unlock_bh(&common->cc_lock);
673
Pavel Roskine0d687b2011-07-14 20:21:55 -0400674 memcpy(survey, &ah->survey, sizeof(*survey));
Bruno Randolfcd2c5482010-12-22 19:20:32 +0900675
676 survey->channel = conf->channel;
Pavel Roskine0d687b2011-07-14 20:21:55 -0400677 survey->noise = ah->ah_noise_floor;
Bruno Randolfcd2c5482010-12-22 19:20:32 +0900678 survey->filled = SURVEY_INFO_NOISE_DBM |
679 SURVEY_INFO_CHANNEL_TIME |
680 SURVEY_INFO_CHANNEL_TIME_BUSY |
681 SURVEY_INFO_CHANNEL_TIME_RX |
682 SURVEY_INFO_CHANNEL_TIME_TX;
683
684 return 0;
685}
686
687
688/**
689 * ath5k_set_coverage_class - Set IEEE 802.11 coverage class
690 *
691 * @hw: struct ieee80211_hw pointer
692 * @coverage_class: IEEE 802.11 coverage class number
693 *
694 * Mac80211 callback. Sets slot time, ACK timeout and CTS timeout for given
695 * coverage class. The values are persistent, they are restored after device
696 * reset.
697 */
698static void
699ath5k_set_coverage_class(struct ieee80211_hw *hw, u8 coverage_class)
700{
Pavel Roskine0d687b2011-07-14 20:21:55 -0400701 struct ath5k_hw *ah = hw->priv;
Bruno Randolfcd2c5482010-12-22 19:20:32 +0900702
Pavel Roskine0d687b2011-07-14 20:21:55 -0400703 mutex_lock(&ah->lock);
704 ath5k_hw_set_coverage_class(ah, coverage_class);
705 mutex_unlock(&ah->lock);
Bruno Randolfcd2c5482010-12-22 19:20:32 +0900706}
707
708
709static int
710ath5k_set_antenna(struct ieee80211_hw *hw, u32 tx_ant, u32 rx_ant)
711{
Pavel Roskine0d687b2011-07-14 20:21:55 -0400712 struct ath5k_hw *ah = hw->priv;
Bruno Randolfcd2c5482010-12-22 19:20:32 +0900713
714 if (tx_ant == 1 && rx_ant == 1)
Pavel Roskine0d687b2011-07-14 20:21:55 -0400715 ath5k_hw_set_antenna_mode(ah, AR5K_ANTMODE_FIXED_A);
Bruno Randolfcd2c5482010-12-22 19:20:32 +0900716 else if (tx_ant == 2 && rx_ant == 2)
Pavel Roskine0d687b2011-07-14 20:21:55 -0400717 ath5k_hw_set_antenna_mode(ah, AR5K_ANTMODE_FIXED_B);
Bruno Randolfcd2c5482010-12-22 19:20:32 +0900718 else if ((tx_ant & 3) == 3 && (rx_ant & 3) == 3)
Pavel Roskine0d687b2011-07-14 20:21:55 -0400719 ath5k_hw_set_antenna_mode(ah, AR5K_ANTMODE_DEFAULT);
Bruno Randolfcd2c5482010-12-22 19:20:32 +0900720 else
721 return -EINVAL;
722 return 0;
723}
724
725
726static int
727ath5k_get_antenna(struct ieee80211_hw *hw, u32 *tx_ant, u32 *rx_ant)
728{
Pavel Roskine0d687b2011-07-14 20:21:55 -0400729 struct ath5k_hw *ah = hw->priv;
Bruno Randolfcd2c5482010-12-22 19:20:32 +0900730
Pavel Roskine0d687b2011-07-14 20:21:55 -0400731 switch (ah->ah_ant_mode) {
Bruno Randolfcd2c5482010-12-22 19:20:32 +0900732 case AR5K_ANTMODE_FIXED_A:
733 *tx_ant = 1; *rx_ant = 1; break;
734 case AR5K_ANTMODE_FIXED_B:
735 *tx_ant = 2; *rx_ant = 2; break;
736 case AR5K_ANTMODE_DEFAULT:
737 *tx_ant = 3; *rx_ant = 3; break;
738 }
739 return 0;
740}
741
742
John W. Linville81266ba2011-03-07 16:32:59 -0500743static void ath5k_get_ringparam(struct ieee80211_hw *hw,
744 u32 *tx, u32 *tx_max, u32 *rx, u32 *rx_max)
745{
Pavel Roskine0d687b2011-07-14 20:21:55 -0400746 struct ath5k_hw *ah = hw->priv;
John W. Linville81266ba2011-03-07 16:32:59 -0500747
Pavel Roskine0d687b2011-07-14 20:21:55 -0400748 *tx = ah->txqs[AR5K_TX_QUEUE_ID_DATA_MIN].txq_max;
John W. Linville81266ba2011-03-07 16:32:59 -0500749
750 *tx_max = ATH5K_TXQ_LEN_MAX;
751 *rx = *rx_max = ATH_RXBUF;
752}
753
754
755static int ath5k_set_ringparam(struct ieee80211_hw *hw, u32 tx, u32 rx)
756{
Pavel Roskine0d687b2011-07-14 20:21:55 -0400757 struct ath5k_hw *ah = hw->priv;
John W. Linville81266ba2011-03-07 16:32:59 -0500758 u16 qnum;
759
760 /* only support setting tx ring size for now */
761 if (rx != ATH_RXBUF)
762 return -EINVAL;
763
764 /* restrict tx ring size min/max */
765 if (!tx || tx > ATH5K_TXQ_LEN_MAX)
766 return -EINVAL;
767
Pavel Roskine0d687b2011-07-14 20:21:55 -0400768 for (qnum = 0; qnum < ARRAY_SIZE(ah->txqs); qnum++) {
769 if (!ah->txqs[qnum].setup)
John W. Linville81266ba2011-03-07 16:32:59 -0500770 continue;
Pavel Roskine0d687b2011-07-14 20:21:55 -0400771 if (ah->txqs[qnum].qnum < AR5K_TX_QUEUE_ID_DATA_MIN ||
772 ah->txqs[qnum].qnum > AR5K_TX_QUEUE_ID_DATA_MAX)
John W. Linville81266ba2011-03-07 16:32:59 -0500773 continue;
774
Pavel Roskine0d687b2011-07-14 20:21:55 -0400775 ah->txqs[qnum].txq_max = tx;
776 if (ah->txqs[qnum].txq_len >= ah->txqs[qnum].txq_max)
777 ieee80211_stop_queue(hw, ah->txqs[qnum].qnum);
John W. Linville81266ba2011-03-07 16:32:59 -0500778 }
779
780 return 0;
781}
782
783
Bruno Randolfcd2c5482010-12-22 19:20:32 +0900784const struct ieee80211_ops ath5k_hw_ops = {
785 .tx = ath5k_tx,
786 .start = ath5k_start,
787 .stop = ath5k_stop,
788 .add_interface = ath5k_add_interface,
789 /* .change_interface = not implemented */
790 .remove_interface = ath5k_remove_interface,
791 .config = ath5k_config,
792 .bss_info_changed = ath5k_bss_info_changed,
793 .prepare_multicast = ath5k_prepare_multicast,
794 .configure_filter = ath5k_configure_filter,
795 /* .set_tim = not implemented */
796 .set_key = ath5k_set_key,
797 /* .update_tkip_key = not implemented */
798 /* .hw_scan = not implemented */
799 .sw_scan_start = ath5k_sw_scan_start,
800 .sw_scan_complete = ath5k_sw_scan_complete,
801 .get_stats = ath5k_get_stats,
802 /* .get_tkip_seq = not implemented */
803 /* .set_frag_threshold = not implemented */
804 /* .set_rts_threshold = not implemented */
805 /* .sta_add = not implemented */
806 /* .sta_remove = not implemented */
807 /* .sta_notify = not implemented */
808 .conf_tx = ath5k_conf_tx,
809 .get_tsf = ath5k_get_tsf,
810 .set_tsf = ath5k_set_tsf,
811 .reset_tsf = ath5k_reset_tsf,
812 /* .tx_last_beacon = not implemented */
813 /* .ampdu_action = not needed */
814 .get_survey = ath5k_get_survey,
815 .set_coverage_class = ath5k_set_coverage_class,
816 /* .rfkill_poll = not implemented */
817 /* .flush = not implemented */
818 /* .channel_switch = not implemented */
819 /* .napi_poll = not implemented */
820 .set_antenna = ath5k_set_antenna,
821 .get_antenna = ath5k_get_antenna,
John W. Linville81266ba2011-03-07 16:32:59 -0500822 .set_ringparam = ath5k_set_ringparam,
823 .get_ringparam = ath5k_get_ringparam,
Bruno Randolfcd2c5482010-12-22 19:20:32 +0900824};