blob: 53d3af92bffaad361f563099c3cd1e0b7ee5abf0 [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
44#include <asm/unaligned.h>
45
46#include "base.h"
47#include "reg.h"
48
Bruno Randolfcd2c5482010-12-22 19:20:32 +090049/********************\
50* Mac80211 functions *
51\********************/
52
Johannes Berg7bb45682011-02-24 14:42:06 +010053static void
Bruno Randolfcd2c5482010-12-22 19:20:32 +090054ath5k_tx(struct ieee80211_hw *hw, struct sk_buff *skb)
55{
Pavel Roskine0d687b2011-07-14 20:21:55 -040056 struct ath5k_hw *ah = hw->priv;
Bruno Randolfcd2c5482010-12-22 19:20:32 +090057 u16 qnum = skb_get_queue_mapping(skb);
58
Pavel Roskine0d687b2011-07-14 20:21:55 -040059 if (WARN_ON(qnum >= ah->ah_capabilities.cap_queues.q_tx_num)) {
Bruno Randolfcd2c5482010-12-22 19:20:32 +090060 dev_kfree_skb_any(skb);
Johannes Berg7bb45682011-02-24 14:42:06 +010061 return;
Bruno Randolfcd2c5482010-12-22 19:20:32 +090062 }
63
Pavel Roskine0d687b2011-07-14 20:21:55 -040064 ath5k_tx_queue(hw, skb, &ah->txqs[qnum]);
Bruno Randolfcd2c5482010-12-22 19:20:32 +090065}
66
67
68static int
Bruno Randolfcd2c5482010-12-22 19:20:32 +090069ath5k_add_interface(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
70{
Pavel Roskine0d687b2011-07-14 20:21:55 -040071 struct ath5k_hw *ah = hw->priv;
Bruno Randolfcd2c5482010-12-22 19:20:32 +090072 int ret;
73 struct ath5k_vif *avf = (void *)vif->drv_priv;
74
Pavel Roskine0d687b2011-07-14 20:21:55 -040075 mutex_lock(&ah->lock);
Bruno Randolfcd2c5482010-12-22 19:20:32 +090076
77 if ((vif->type == NL80211_IFTYPE_AP ||
78 vif->type == NL80211_IFTYPE_ADHOC)
Pavel Roskine0d687b2011-07-14 20:21:55 -040079 && (ah->num_ap_vifs + ah->num_adhoc_vifs) >= ATH_BCBUF) {
Bruno Randolfcd2c5482010-12-22 19:20:32 +090080 ret = -ELNRNG;
81 goto end;
82 }
83
84 /* Don't allow other interfaces if one ad-hoc is configured.
85 * TODO: Fix the problems with ad-hoc and multiple other interfaces.
86 * We would need to operate the HW in ad-hoc mode to allow TSF updates
87 * for the IBSS, but this breaks with additional AP or STA interfaces
88 * at the moment. */
Pavel Roskine0d687b2011-07-14 20:21:55 -040089 if (ah->num_adhoc_vifs ||
90 (ah->nvifs && vif->type == NL80211_IFTYPE_ADHOC)) {
91 ATH5K_ERR(ah, "Only one single ad-hoc interface is allowed.\n");
Bruno Randolfcd2c5482010-12-22 19:20:32 +090092 ret = -ELNRNG;
93 goto end;
94 }
95
96 switch (vif->type) {
97 case NL80211_IFTYPE_AP:
98 case NL80211_IFTYPE_STATION:
99 case NL80211_IFTYPE_ADHOC:
100 case NL80211_IFTYPE_MESH_POINT:
101 avf->opmode = vif->type;
102 break;
103 default:
104 ret = -EOPNOTSUPP;
105 goto end;
106 }
107
Pavel Roskine0d687b2011-07-14 20:21:55 -0400108 ah->nvifs++;
109 ATH5K_DBG(ah, ATH5K_DEBUG_MODE, "add interface mode %d\n", avf->opmode);
Bruno Randolfcd2c5482010-12-22 19:20:32 +0900110
111 /* Assign the vap/adhoc to a beacon xmit slot. */
112 if ((avf->opmode == NL80211_IFTYPE_AP) ||
113 (avf->opmode == NL80211_IFTYPE_ADHOC) ||
114 (avf->opmode == NL80211_IFTYPE_MESH_POINT)) {
115 int slot;
116
Pavel Roskine0d687b2011-07-14 20:21:55 -0400117 WARN_ON(list_empty(&ah->bcbuf));
118 avf->bbuf = list_first_entry(&ah->bcbuf, struct ath5k_buf,
Bruno Randolfcd2c5482010-12-22 19:20:32 +0900119 list);
120 list_del(&avf->bbuf->list);
121
122 avf->bslot = 0;
123 for (slot = 0; slot < ATH_BCBUF; slot++) {
Pavel Roskine0d687b2011-07-14 20:21:55 -0400124 if (!ah->bslot[slot]) {
Bruno Randolfcd2c5482010-12-22 19:20:32 +0900125 avf->bslot = slot;
126 break;
127 }
128 }
Pavel Roskine0d687b2011-07-14 20:21:55 -0400129 BUG_ON(ah->bslot[avf->bslot] != NULL);
130 ah->bslot[avf->bslot] = vif;
Bruno Randolfcd2c5482010-12-22 19:20:32 +0900131 if (avf->opmode == NL80211_IFTYPE_AP)
Pavel Roskine0d687b2011-07-14 20:21:55 -0400132 ah->num_ap_vifs++;
Bruno Randolfcd2c5482010-12-22 19:20:32 +0900133 else if (avf->opmode == NL80211_IFTYPE_ADHOC)
Pavel Roskine0d687b2011-07-14 20:21:55 -0400134 ah->num_adhoc_vifs++;
Bruno Randolfcd2c5482010-12-22 19:20:32 +0900135 }
136
137 /* Any MAC address is fine, all others are included through the
138 * filter.
139 */
Pavel Roskine0d687b2011-07-14 20:21:55 -0400140 ath5k_hw_set_lladdr(ah, vif->addr);
Bruno Randolfcd2c5482010-12-22 19:20:32 +0900141
Pavel Roskine0d687b2011-07-14 20:21:55 -0400142 ath5k_update_bssid_mask_and_opmode(ah, vif);
Bruno Randolfcd2c5482010-12-22 19:20:32 +0900143 ret = 0;
144end:
Pavel Roskine0d687b2011-07-14 20:21:55 -0400145 mutex_unlock(&ah->lock);
Bruno Randolfcd2c5482010-12-22 19:20:32 +0900146 return ret;
147}
148
149
150static void
151ath5k_remove_interface(struct ieee80211_hw *hw,
152 struct ieee80211_vif *vif)
153{
Pavel Roskine0d687b2011-07-14 20:21:55 -0400154 struct ath5k_hw *ah = hw->priv;
Bruno Randolfcd2c5482010-12-22 19:20:32 +0900155 struct ath5k_vif *avf = (void *)vif->drv_priv;
156 unsigned int i;
157
Pavel Roskine0d687b2011-07-14 20:21:55 -0400158 mutex_lock(&ah->lock);
159 ah->nvifs--;
Bruno Randolfcd2c5482010-12-22 19:20:32 +0900160
161 if (avf->bbuf) {
Pavel Roskine0d687b2011-07-14 20:21:55 -0400162 ath5k_txbuf_free_skb(ah, avf->bbuf);
163 list_add_tail(&avf->bbuf->list, &ah->bcbuf);
Bruno Randolfcd2c5482010-12-22 19:20:32 +0900164 for (i = 0; i < ATH_BCBUF; i++) {
Pavel Roskine0d687b2011-07-14 20:21:55 -0400165 if (ah->bslot[i] == vif) {
166 ah->bslot[i] = NULL;
Bruno Randolfcd2c5482010-12-22 19:20:32 +0900167 break;
168 }
169 }
170 avf->bbuf = NULL;
171 }
172 if (avf->opmode == NL80211_IFTYPE_AP)
Pavel Roskine0d687b2011-07-14 20:21:55 -0400173 ah->num_ap_vifs--;
Bruno Randolfcd2c5482010-12-22 19:20:32 +0900174 else if (avf->opmode == NL80211_IFTYPE_ADHOC)
Pavel Roskine0d687b2011-07-14 20:21:55 -0400175 ah->num_adhoc_vifs--;
Bruno Randolfcd2c5482010-12-22 19:20:32 +0900176
Pavel Roskine0d687b2011-07-14 20:21:55 -0400177 ath5k_update_bssid_mask_and_opmode(ah, NULL);
178 mutex_unlock(&ah->lock);
Bruno Randolfcd2c5482010-12-22 19:20:32 +0900179}
180
181
182/*
183 * TODO: Phy disable/diversity etc
184 */
185static int
186ath5k_config(struct ieee80211_hw *hw, u32 changed)
187{
Pavel Roskine0d687b2011-07-14 20:21:55 -0400188 struct ath5k_hw *ah = hw->priv;
Bruno Randolfcd2c5482010-12-22 19:20:32 +0900189 struct ieee80211_conf *conf = &hw->conf;
190 int ret = 0;
Bruno Randolf76a9f6f2011-01-28 16:52:11 +0900191 int i;
Bruno Randolfcd2c5482010-12-22 19:20:32 +0900192
Pavel Roskine0d687b2011-07-14 20:21:55 -0400193 mutex_lock(&ah->lock);
Bruno Randolfcd2c5482010-12-22 19:20:32 +0900194
195 if (changed & IEEE80211_CONF_CHANGE_CHANNEL) {
Pavel Roskine0d687b2011-07-14 20:21:55 -0400196 ret = ath5k_chan_set(ah, conf->channel);
Bruno Randolfcd2c5482010-12-22 19:20:32 +0900197 if (ret < 0)
198 goto unlock;
199 }
200
201 if ((changed & IEEE80211_CONF_CHANGE_POWER) &&
Pavel Roskine0d687b2011-07-14 20:21:55 -0400202 (ah->power_level != conf->power_level)) {
203 ah->power_level = conf->power_level;
Bruno Randolfcd2c5482010-12-22 19:20:32 +0900204
205 /* Half dB steps */
206 ath5k_hw_set_txpower_limit(ah, (conf->power_level * 2));
207 }
208
Bruno Randolf76a9f6f2011-01-28 16:52:11 +0900209 if (changed & IEEE80211_CONF_CHANGE_RETRY_LIMITS) {
210 ah->ah_retry_long = conf->long_frame_max_tx_count;
211 ah->ah_retry_short = conf->short_frame_max_tx_count;
212
213 for (i = 0; i < ah->ah_capabilities.cap_queues.q_tx_num; i++)
214 ath5k_hw_set_tx_retry_limits(ah, i);
215 }
216
Bruno Randolfcd2c5482010-12-22 19:20:32 +0900217 /* TODO:
218 * 1) Move this on config_interface and handle each case
219 * separately eg. when we have only one STA vif, use
220 * AR5K_ANTMODE_SINGLE_AP
221 *
222 * 2) Allow the user to change antenna mode eg. when only
223 * one antenna is present
224 *
225 * 3) Allow the user to set default/tx antenna when possible
226 *
227 * 4) Default mode should handle 90% of the cases, together
228 * with fixed a/b and single AP modes we should be able to
229 * handle 99%. Sectored modes are extreme cases and i still
230 * haven't found a usage for them. If we decide to support them,
231 * then we must allow the user to set how many tx antennas we
232 * have available
233 */
234 ath5k_hw_set_antenna_mode(ah, ah->ah_ant_mode);
235
236unlock:
Pavel Roskine0d687b2011-07-14 20:21:55 -0400237 mutex_unlock(&ah->lock);
Bruno Randolfcd2c5482010-12-22 19:20:32 +0900238 return ret;
239}
240
241
242static void
243ath5k_bss_info_changed(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
244 struct ieee80211_bss_conf *bss_conf, u32 changes)
245{
246 struct ath5k_vif *avf = (void *)vif->drv_priv;
Pavel Roskine0d687b2011-07-14 20:21:55 -0400247 struct ath5k_hw *ah = hw->priv;
Bruno Randolfcd2c5482010-12-22 19:20:32 +0900248 struct ath_common *common = ath5k_hw_common(ah);
249 unsigned long flags;
250
Pavel Roskine0d687b2011-07-14 20:21:55 -0400251 mutex_lock(&ah->lock);
Bruno Randolfcd2c5482010-12-22 19:20:32 +0900252
253 if (changes & BSS_CHANGED_BSSID) {
254 /* Cache for later use during resets */
255 memcpy(common->curbssid, bss_conf->bssid, ETH_ALEN);
256 common->curaid = 0;
257 ath5k_hw_set_bssid(ah);
258 mmiowb();
259 }
260
261 if (changes & BSS_CHANGED_BEACON_INT)
Pavel Roskine0d687b2011-07-14 20:21:55 -0400262 ah->bintval = bss_conf->beacon_int;
Bruno Randolfcd2c5482010-12-22 19:20:32 +0900263
Felix Fietkaub1ad1b62011-04-09 23:10:21 +0200264 if (changes & BSS_CHANGED_ERP_SLOT) {
265 int slot_time;
266
267 ah->ah_short_slot = bss_conf->use_short_slot;
268 slot_time = ath5k_hw_get_default_slottime(ah) +
269 3 * ah->ah_coverage_class;
270 ath5k_hw_set_ifs_intervals(ah, slot_time);
271 }
272
Bruno Randolfcd2c5482010-12-22 19:20:32 +0900273 if (changes & BSS_CHANGED_ASSOC) {
274 avf->assoc = bss_conf->assoc;
275 if (bss_conf->assoc)
Pavel Roskine0d687b2011-07-14 20:21:55 -0400276 ah->assoc = bss_conf->assoc;
Bruno Randolfcd2c5482010-12-22 19:20:32 +0900277 else
Pavel Roskine0d687b2011-07-14 20:21:55 -0400278 ah->assoc = ath5k_any_vif_assoc(ah);
Bruno Randolfcd2c5482010-12-22 19:20:32 +0900279
Pavel Roskine0d687b2011-07-14 20:21:55 -0400280 if (ah->opmode == NL80211_IFTYPE_STATION)
281 ath5k_set_beacon_filter(hw, ah->assoc);
282 ath5k_hw_set_ledstate(ah, ah->assoc ?
Bruno Randolfcd2c5482010-12-22 19:20:32 +0900283 AR5K_LED_ASSOC : AR5K_LED_INIT);
284 if (bss_conf->assoc) {
Pavel Roskine0d687b2011-07-14 20:21:55 -0400285 ATH5K_DBG(ah, ATH5K_DEBUG_ANY,
Bruno Randolfcd2c5482010-12-22 19:20:32 +0900286 "Bss Info ASSOC %d, bssid: %pM\n",
287 bss_conf->aid, common->curbssid);
288 common->curaid = bss_conf->aid;
289 ath5k_hw_set_bssid(ah);
290 /* Once ANI is available you would start it here */
291 }
292 }
293
294 if (changes & BSS_CHANGED_BEACON) {
Pavel Roskine0d687b2011-07-14 20:21:55 -0400295 spin_lock_irqsave(&ah->block, flags);
Bruno Randolfcd2c5482010-12-22 19:20:32 +0900296 ath5k_beacon_update(hw, vif);
Pavel Roskine0d687b2011-07-14 20:21:55 -0400297 spin_unlock_irqrestore(&ah->block, flags);
Bruno Randolfcd2c5482010-12-22 19:20:32 +0900298 }
299
300 if (changes & BSS_CHANGED_BEACON_ENABLED)
Pavel Roskine0d687b2011-07-14 20:21:55 -0400301 ah->enable_beacon = bss_conf->enable_beacon;
Bruno Randolfcd2c5482010-12-22 19:20:32 +0900302
303 if (changes & (BSS_CHANGED_BEACON | BSS_CHANGED_BEACON_ENABLED |
304 BSS_CHANGED_BEACON_INT))
Pavel Roskine0d687b2011-07-14 20:21:55 -0400305 ath5k_beacon_config(ah);
Bruno Randolfcd2c5482010-12-22 19:20:32 +0900306
Pavel Roskine0d687b2011-07-14 20:21:55 -0400307 mutex_unlock(&ah->lock);
Bruno Randolfcd2c5482010-12-22 19:20:32 +0900308}
309
310
311static u64
312ath5k_prepare_multicast(struct ieee80211_hw *hw,
313 struct netdev_hw_addr_list *mc_list)
314{
315 u32 mfilt[2], val;
316 u8 pos;
317 struct netdev_hw_addr *ha;
318
319 mfilt[0] = 0;
320 mfilt[1] = 1;
321
322 netdev_hw_addr_list_for_each(ha, mc_list) {
323 /* calculate XOR of eight 6-bit values */
324 val = get_unaligned_le32(ha->addr + 0);
325 pos = (val >> 18) ^ (val >> 12) ^ (val >> 6) ^ val;
326 val = get_unaligned_le32(ha->addr + 3);
327 pos ^= (val >> 18) ^ (val >> 12) ^ (val >> 6) ^ val;
328 pos &= 0x3f;
329 mfilt[pos / 32] |= (1 << (pos % 32));
330 /* XXX: we might be able to just do this instead,
331 * but not sure, needs testing, if we do use this we'd
Pavel Roskin6a2a0e72011-07-09 00:17:51 -0400332 * need to inform below not to reset the mcast */
Bruno Randolfcd2c5482010-12-22 19:20:32 +0900333 /* ath5k_hw_set_mcast_filterindex(ah,
334 * ha->addr[5]); */
335 }
336
337 return ((u64)(mfilt[1]) << 32) | mfilt[0];
338}
339
340
341/*
342 * o always accept unicast, broadcast, and multicast traffic
343 * o multicast traffic for all BSSIDs will be enabled if mac80211
344 * says it should be
345 * o maintain current state of phy ofdm or phy cck error reception.
346 * If the hardware detects any of these type of errors then
347 * ath5k_hw_get_rx_filter() will pass to us the respective
348 * hardware filters to be able to receive these type of frames.
349 * o probe request frames are accepted only when operating in
350 * hostap, adhoc, or monitor modes
351 * o enable promiscuous mode according to the interface state
352 * o accept beacons:
353 * - when operating in adhoc mode so the 802.11 layer creates
354 * node table entries for peers,
355 * - when operating in station mode for collecting rssi data when
356 * the station is otherwise quiet, or
357 * - when scanning
358 */
359static void
360ath5k_configure_filter(struct ieee80211_hw *hw, unsigned int changed_flags,
361 unsigned int *new_flags, u64 multicast)
362{
363#define SUPPORTED_FIF_FLAGS \
364 (FIF_PROMISC_IN_BSS | FIF_ALLMULTI | FIF_FCSFAIL | \
365 FIF_PLCPFAIL | FIF_CONTROL | FIF_OTHER_BSS | \
366 FIF_BCN_PRBRESP_PROMISC)
367
Pavel Roskine0d687b2011-07-14 20:21:55 -0400368 struct ath5k_hw *ah = hw->priv;
Bruno Randolfcd2c5482010-12-22 19:20:32 +0900369 u32 mfilt[2], rfilt;
Ben Greeare4b0b322011-03-03 14:39:05 -0800370 struct ath5k_vif_iter_data iter_data; /* to count STA interfaces */
Bruno Randolfcd2c5482010-12-22 19:20:32 +0900371
Pavel Roskine0d687b2011-07-14 20:21:55 -0400372 mutex_lock(&ah->lock);
Bruno Randolfcd2c5482010-12-22 19:20:32 +0900373
374 mfilt[0] = multicast;
375 mfilt[1] = multicast >> 32;
376
377 /* Only deal with supported flags */
378 changed_flags &= SUPPORTED_FIF_FLAGS;
379 *new_flags &= SUPPORTED_FIF_FLAGS;
380
381 /* If HW detects any phy or radar errors, leave those filters on.
382 * Also, always enable Unicast, Broadcasts and Multicast
383 * XXX: move unicast, bssid broadcasts and multicast to mac80211 */
384 rfilt = (ath5k_hw_get_rx_filter(ah) & (AR5K_RX_FILTER_PHYERR)) |
385 (AR5K_RX_FILTER_UCAST | AR5K_RX_FILTER_BCAST |
386 AR5K_RX_FILTER_MCAST);
387
388 if (changed_flags & (FIF_PROMISC_IN_BSS | FIF_OTHER_BSS)) {
389 if (*new_flags & FIF_PROMISC_IN_BSS)
Pavel Roskine0d687b2011-07-14 20:21:55 -0400390 __set_bit(ATH_STAT_PROMISC, ah->status);
Bruno Randolfcd2c5482010-12-22 19:20:32 +0900391 else
Pavel Roskine0d687b2011-07-14 20:21:55 -0400392 __clear_bit(ATH_STAT_PROMISC, ah->status);
Bruno Randolfcd2c5482010-12-22 19:20:32 +0900393 }
394
Pavel Roskine0d687b2011-07-14 20:21:55 -0400395 if (test_bit(ATH_STAT_PROMISC, ah->status))
Bruno Randolfcd2c5482010-12-22 19:20:32 +0900396 rfilt |= AR5K_RX_FILTER_PROM;
397
398 /* Note, AR5K_RX_FILTER_MCAST is already enabled */
399 if (*new_flags & FIF_ALLMULTI) {
400 mfilt[0] = ~0;
401 mfilt[1] = ~0;
402 }
403
404 /* This is the best we can do */
405 if (*new_flags & (FIF_FCSFAIL | FIF_PLCPFAIL))
406 rfilt |= AR5K_RX_FILTER_PHYERR;
407
408 /* FIF_BCN_PRBRESP_PROMISC really means to enable beacons
409 * and probes for any BSSID */
Pavel Roskine0d687b2011-07-14 20:21:55 -0400410 if ((*new_flags & FIF_BCN_PRBRESP_PROMISC) || (ah->nvifs > 1))
Bruno Randolfcd2c5482010-12-22 19:20:32 +0900411 rfilt |= AR5K_RX_FILTER_BEACON;
412
413 /* FIF_CONTROL doc says that if FIF_PROMISC_IN_BSS is not
414 * set we should only pass on control frames for this
415 * station. This needs testing. I believe right now this
416 * enables *all* control frames, which is OK.. but
417 * but we should see if we can improve on granularity */
418 if (*new_flags & FIF_CONTROL)
419 rfilt |= AR5K_RX_FILTER_CONTROL;
420
421 /* Additional settings per mode -- this is per ath5k */
422
423 /* XXX move these to mac80211, and add a beacon IFF flag to mac80211 */
424
Pavel Roskine0d687b2011-07-14 20:21:55 -0400425 switch (ah->opmode) {
Bruno Randolfcd2c5482010-12-22 19:20:32 +0900426 case NL80211_IFTYPE_MESH_POINT:
427 rfilt |= AR5K_RX_FILTER_CONTROL |
428 AR5K_RX_FILTER_BEACON |
429 AR5K_RX_FILTER_PROBEREQ |
430 AR5K_RX_FILTER_PROM;
431 break;
432 case NL80211_IFTYPE_AP:
433 case NL80211_IFTYPE_ADHOC:
434 rfilt |= AR5K_RX_FILTER_PROBEREQ |
435 AR5K_RX_FILTER_BEACON;
436 break;
437 case NL80211_IFTYPE_STATION:
Pavel Roskine0d687b2011-07-14 20:21:55 -0400438 if (ah->assoc)
Bruno Randolfcd2c5482010-12-22 19:20:32 +0900439 rfilt |= AR5K_RX_FILTER_BEACON;
440 default:
441 break;
442 }
443
Ben Greeare4b0b322011-03-03 14:39:05 -0800444 iter_data.hw_macaddr = NULL;
445 iter_data.n_stas = 0;
446 iter_data.need_set_hw_addr = false;
Pavel Roskine0d687b2011-07-14 20:21:55 -0400447 ieee80211_iterate_active_interfaces_atomic(ah->hw, ath5k_vif_iter,
Ben Greeare4b0b322011-03-03 14:39:05 -0800448 &iter_data);
449
450 /* Set up RX Filter */
451 if (iter_data.n_stas > 1) {
452 /* If you have multiple STA interfaces connected to
453 * different APs, ARPs are not received (most of the time?)
Pavel Roskin6a2a0e72011-07-09 00:17:51 -0400454 * Enabling PROMISC appears to fix that problem.
Ben Greeare4b0b322011-03-03 14:39:05 -0800455 */
456 rfilt |= AR5K_RX_FILTER_PROM;
457 }
458
Bruno Randolfcd2c5482010-12-22 19:20:32 +0900459 /* Set filters */
460 ath5k_hw_set_rx_filter(ah, rfilt);
461
462 /* Set multicast bits */
463 ath5k_hw_set_mcast_filter(ah, mfilt[0], mfilt[1]);
464 /* Set the cached hw filter flags, this will later actually
465 * be set in HW */
Pavel Roskine0d687b2011-07-14 20:21:55 -0400466 ah->filter_flags = rfilt;
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
484 switch (key->cipher) {
485 case WLAN_CIPHER_SUITE_WEP40:
486 case WLAN_CIPHER_SUITE_WEP104:
487 case WLAN_CIPHER_SUITE_TKIP:
488 break;
489 case WLAN_CIPHER_SUITE_CCMP:
490 if (common->crypt_caps & ATH_CRYPT_CAP_CIPHER_AESCCM)
491 break;
492 return -EOPNOTSUPP;
493 default:
494 WARN_ON(1);
495 return -EINVAL;
496 }
497
Pavel Roskine0d687b2011-07-14 20:21:55 -0400498 mutex_lock(&ah->lock);
Bruno Randolfcd2c5482010-12-22 19:20:32 +0900499
500 switch (cmd) {
501 case SET_KEY:
502 ret = ath_key_config(common, vif, sta, key);
503 if (ret >= 0) {
504 key->hw_key_idx = ret;
505 /* push IV and Michael MIC generation to stack */
506 key->flags |= IEEE80211_KEY_FLAG_GENERATE_IV;
507 if (key->cipher == WLAN_CIPHER_SUITE_TKIP)
508 key->flags |= IEEE80211_KEY_FLAG_GENERATE_MMIC;
509 if (key->cipher == WLAN_CIPHER_SUITE_CCMP)
510 key->flags |= IEEE80211_KEY_FLAG_SW_MGMT;
511 ret = 0;
512 }
513 break;
514 case DISABLE_KEY:
515 ath_key_delete(common, key);
516 break;
517 default:
518 ret = -EINVAL;
519 }
520
521 mmiowb();
Pavel Roskine0d687b2011-07-14 20:21:55 -0400522 mutex_unlock(&ah->lock);
Bruno Randolfcd2c5482010-12-22 19:20:32 +0900523 return ret;
524}
525
526
527static void
528ath5k_sw_scan_start(struct ieee80211_hw *hw)
529{
Pavel Roskine0d687b2011-07-14 20:21:55 -0400530 struct ath5k_hw *ah = hw->priv;
531 if (!ah->assoc)
532 ath5k_hw_set_ledstate(ah, AR5K_LED_SCAN);
Bruno Randolfcd2c5482010-12-22 19:20:32 +0900533}
534
535
536static void
537ath5k_sw_scan_complete(struct ieee80211_hw *hw)
538{
Pavel Roskine0d687b2011-07-14 20:21:55 -0400539 struct ath5k_hw *ah = hw->priv;
540 ath5k_hw_set_ledstate(ah, ah->assoc ?
Bruno Randolfcd2c5482010-12-22 19:20:32 +0900541 AR5K_LED_ASSOC : AR5K_LED_INIT);
542}
543
544
545static int
546ath5k_get_stats(struct ieee80211_hw *hw,
547 struct ieee80211_low_level_stats *stats)
548{
Pavel Roskine0d687b2011-07-14 20:21:55 -0400549 struct ath5k_hw *ah = hw->priv;
Bruno Randolfcd2c5482010-12-22 19:20:32 +0900550
551 /* Force update */
Pavel Roskine0d687b2011-07-14 20:21:55 -0400552 ath5k_hw_update_mib_counters(ah);
Bruno Randolfcd2c5482010-12-22 19:20:32 +0900553
Pavel Roskine0d687b2011-07-14 20:21:55 -0400554 stats->dot11ACKFailureCount = ah->stats.ack_fail;
555 stats->dot11RTSFailureCount = ah->stats.rts_fail;
556 stats->dot11RTSSuccessCount = ah->stats.rts_ok;
557 stats->dot11FCSErrorCount = ah->stats.fcs_error;
Bruno Randolfcd2c5482010-12-22 19:20:32 +0900558
559 return 0;
560}
561
562
563static int
564ath5k_conf_tx(struct ieee80211_hw *hw, u16 queue,
565 const struct ieee80211_tx_queue_params *params)
566{
Pavel Roskine0d687b2011-07-14 20:21:55 -0400567 struct ath5k_hw *ah = hw->priv;
Bruno Randolfcd2c5482010-12-22 19:20:32 +0900568 struct ath5k_txq_info qi;
569 int ret = 0;
570
571 if (queue >= ah->ah_capabilities.cap_queues.q_tx_num)
572 return 0;
573
Pavel Roskine0d687b2011-07-14 20:21:55 -0400574 mutex_lock(&ah->lock);
Bruno Randolfcd2c5482010-12-22 19:20:32 +0900575
576 ath5k_hw_get_tx_queueprops(ah, queue, &qi);
577
578 qi.tqi_aifs = params->aifs;
579 qi.tqi_cw_min = params->cw_min;
580 qi.tqi_cw_max = params->cw_max;
581 qi.tqi_burst_time = params->txop;
582
Pavel Roskine0d687b2011-07-14 20:21:55 -0400583 ATH5K_DBG(ah, ATH5K_DEBUG_ANY,
Bruno Randolfcd2c5482010-12-22 19:20:32 +0900584 "Configure tx [queue %d], "
585 "aifs: %d, cw_min: %d, cw_max: %d, txop: %d\n",
586 queue, params->aifs, params->cw_min,
587 params->cw_max, params->txop);
588
589 if (ath5k_hw_set_tx_queueprops(ah, queue, &qi)) {
Pavel Roskine0d687b2011-07-14 20:21:55 -0400590 ATH5K_ERR(ah,
Bruno Randolfcd2c5482010-12-22 19:20:32 +0900591 "Unable to update hardware queue %u!\n", queue);
592 ret = -EIO;
593 } else
594 ath5k_hw_reset_tx_queue(ah, queue);
595
Pavel Roskine0d687b2011-07-14 20:21:55 -0400596 mutex_unlock(&ah->lock);
Bruno Randolfcd2c5482010-12-22 19:20:32 +0900597
598 return ret;
599}
600
601
602static u64
603ath5k_get_tsf(struct ieee80211_hw *hw)
604{
Pavel Roskine0d687b2011-07-14 20:21:55 -0400605 struct ath5k_hw *ah = hw->priv;
Bruno Randolfcd2c5482010-12-22 19:20:32 +0900606
Pavel Roskine0d687b2011-07-14 20:21:55 -0400607 return ath5k_hw_get_tsf64(ah);
Bruno Randolfcd2c5482010-12-22 19:20:32 +0900608}
609
610
611static void
612ath5k_set_tsf(struct ieee80211_hw *hw, u64 tsf)
613{
Pavel Roskine0d687b2011-07-14 20:21:55 -0400614 struct ath5k_hw *ah = hw->priv;
Bruno Randolfcd2c5482010-12-22 19:20:32 +0900615
Pavel Roskine0d687b2011-07-14 20:21:55 -0400616 ath5k_hw_set_tsf64(ah, tsf);
Bruno Randolfcd2c5482010-12-22 19:20:32 +0900617}
618
619
620static void
621ath5k_reset_tsf(struct ieee80211_hw *hw)
622{
Pavel Roskine0d687b2011-07-14 20:21:55 -0400623 struct ath5k_hw *ah = hw->priv;
Bruno Randolfcd2c5482010-12-22 19:20:32 +0900624
625 /*
626 * in IBSS mode we need to update the beacon timers too.
627 * this will also reset the TSF if we call it with 0
628 */
Pavel Roskine0d687b2011-07-14 20:21:55 -0400629 if (ah->opmode == NL80211_IFTYPE_ADHOC)
630 ath5k_beacon_update_timers(ah, 0);
Bruno Randolfcd2c5482010-12-22 19:20:32 +0900631 else
Pavel Roskine0d687b2011-07-14 20:21:55 -0400632 ath5k_hw_reset_tsf(ah);
Bruno Randolfcd2c5482010-12-22 19:20:32 +0900633}
634
635
636static int
637ath5k_get_survey(struct ieee80211_hw *hw, int idx, struct survey_info *survey)
638{
Pavel Roskine0d687b2011-07-14 20:21:55 -0400639 struct ath5k_hw *ah = hw->priv;
Bruno Randolfcd2c5482010-12-22 19:20:32 +0900640 struct ieee80211_conf *conf = &hw->conf;
Pavel Roskine0d687b2011-07-14 20:21:55 -0400641 struct ath_common *common = ath5k_hw_common(ah);
Bruno Randolfcd2c5482010-12-22 19:20:32 +0900642 struct ath_cycle_counters *cc = &common->cc_survey;
643 unsigned int div = common->clockrate * 1000;
644
645 if (idx != 0)
646 return -ENOENT;
647
648 spin_lock_bh(&common->cc_lock);
649 ath_hw_cycle_counters_update(common);
650 if (cc->cycles > 0) {
Pavel Roskine0d687b2011-07-14 20:21:55 -0400651 ah->survey.channel_time += cc->cycles / div;
652 ah->survey.channel_time_busy += cc->rx_busy / div;
653 ah->survey.channel_time_rx += cc->rx_frame / div;
654 ah->survey.channel_time_tx += cc->tx_frame / div;
Bruno Randolfcd2c5482010-12-22 19:20:32 +0900655 }
656 memset(cc, 0, sizeof(*cc));
657 spin_unlock_bh(&common->cc_lock);
658
Pavel Roskine0d687b2011-07-14 20:21:55 -0400659 memcpy(survey, &ah->survey, sizeof(*survey));
Bruno Randolfcd2c5482010-12-22 19:20:32 +0900660
661 survey->channel = conf->channel;
Pavel Roskine0d687b2011-07-14 20:21:55 -0400662 survey->noise = ah->ah_noise_floor;
Bruno Randolfcd2c5482010-12-22 19:20:32 +0900663 survey->filled = SURVEY_INFO_NOISE_DBM |
664 SURVEY_INFO_CHANNEL_TIME |
665 SURVEY_INFO_CHANNEL_TIME_BUSY |
666 SURVEY_INFO_CHANNEL_TIME_RX |
667 SURVEY_INFO_CHANNEL_TIME_TX;
668
669 return 0;
670}
671
672
673/**
674 * ath5k_set_coverage_class - Set IEEE 802.11 coverage class
675 *
676 * @hw: struct ieee80211_hw pointer
677 * @coverage_class: IEEE 802.11 coverage class number
678 *
679 * Mac80211 callback. Sets slot time, ACK timeout and CTS timeout for given
680 * coverage class. The values are persistent, they are restored after device
681 * reset.
682 */
683static void
684ath5k_set_coverage_class(struct ieee80211_hw *hw, u8 coverage_class)
685{
Pavel Roskine0d687b2011-07-14 20:21:55 -0400686 struct ath5k_hw *ah = hw->priv;
Bruno Randolfcd2c5482010-12-22 19:20:32 +0900687
Pavel Roskine0d687b2011-07-14 20:21:55 -0400688 mutex_lock(&ah->lock);
689 ath5k_hw_set_coverage_class(ah, coverage_class);
690 mutex_unlock(&ah->lock);
Bruno Randolfcd2c5482010-12-22 19:20:32 +0900691}
692
693
694static int
695ath5k_set_antenna(struct ieee80211_hw *hw, u32 tx_ant, u32 rx_ant)
696{
Pavel Roskine0d687b2011-07-14 20:21:55 -0400697 struct ath5k_hw *ah = hw->priv;
Bruno Randolfcd2c5482010-12-22 19:20:32 +0900698
699 if (tx_ant == 1 && rx_ant == 1)
Pavel Roskine0d687b2011-07-14 20:21:55 -0400700 ath5k_hw_set_antenna_mode(ah, AR5K_ANTMODE_FIXED_A);
Bruno Randolfcd2c5482010-12-22 19:20:32 +0900701 else if (tx_ant == 2 && rx_ant == 2)
Pavel Roskine0d687b2011-07-14 20:21:55 -0400702 ath5k_hw_set_antenna_mode(ah, AR5K_ANTMODE_FIXED_B);
Bruno Randolfcd2c5482010-12-22 19:20:32 +0900703 else if ((tx_ant & 3) == 3 && (rx_ant & 3) == 3)
Pavel Roskine0d687b2011-07-14 20:21:55 -0400704 ath5k_hw_set_antenna_mode(ah, AR5K_ANTMODE_DEFAULT);
Bruno Randolfcd2c5482010-12-22 19:20:32 +0900705 else
706 return -EINVAL;
707 return 0;
708}
709
710
711static int
712ath5k_get_antenna(struct ieee80211_hw *hw, u32 *tx_ant, u32 *rx_ant)
713{
Pavel Roskine0d687b2011-07-14 20:21:55 -0400714 struct ath5k_hw *ah = hw->priv;
Bruno Randolfcd2c5482010-12-22 19:20:32 +0900715
Pavel Roskine0d687b2011-07-14 20:21:55 -0400716 switch (ah->ah_ant_mode) {
Bruno Randolfcd2c5482010-12-22 19:20:32 +0900717 case AR5K_ANTMODE_FIXED_A:
718 *tx_ant = 1; *rx_ant = 1; break;
719 case AR5K_ANTMODE_FIXED_B:
720 *tx_ant = 2; *rx_ant = 2; break;
721 case AR5K_ANTMODE_DEFAULT:
722 *tx_ant = 3; *rx_ant = 3; break;
723 }
724 return 0;
725}
726
727
John W. Linville81266ba2011-03-07 16:32:59 -0500728static void ath5k_get_ringparam(struct ieee80211_hw *hw,
729 u32 *tx, u32 *tx_max, u32 *rx, u32 *rx_max)
730{
Pavel Roskine0d687b2011-07-14 20:21:55 -0400731 struct ath5k_hw *ah = hw->priv;
John W. Linville81266ba2011-03-07 16:32:59 -0500732
Pavel Roskine0d687b2011-07-14 20:21:55 -0400733 *tx = ah->txqs[AR5K_TX_QUEUE_ID_DATA_MIN].txq_max;
John W. Linville81266ba2011-03-07 16:32:59 -0500734
735 *tx_max = ATH5K_TXQ_LEN_MAX;
736 *rx = *rx_max = ATH_RXBUF;
737}
738
739
740static int ath5k_set_ringparam(struct ieee80211_hw *hw, u32 tx, u32 rx)
741{
Pavel Roskine0d687b2011-07-14 20:21:55 -0400742 struct ath5k_hw *ah = hw->priv;
John W. Linville81266ba2011-03-07 16:32:59 -0500743 u16 qnum;
744
745 /* only support setting tx ring size for now */
746 if (rx != ATH_RXBUF)
747 return -EINVAL;
748
749 /* restrict tx ring size min/max */
750 if (!tx || tx > ATH5K_TXQ_LEN_MAX)
751 return -EINVAL;
752
Pavel Roskine0d687b2011-07-14 20:21:55 -0400753 for (qnum = 0; qnum < ARRAY_SIZE(ah->txqs); qnum++) {
754 if (!ah->txqs[qnum].setup)
John W. Linville81266ba2011-03-07 16:32:59 -0500755 continue;
Pavel Roskine0d687b2011-07-14 20:21:55 -0400756 if (ah->txqs[qnum].qnum < AR5K_TX_QUEUE_ID_DATA_MIN ||
757 ah->txqs[qnum].qnum > AR5K_TX_QUEUE_ID_DATA_MAX)
John W. Linville81266ba2011-03-07 16:32:59 -0500758 continue;
759
Pavel Roskine0d687b2011-07-14 20:21:55 -0400760 ah->txqs[qnum].txq_max = tx;
761 if (ah->txqs[qnum].txq_len >= ah->txqs[qnum].txq_max)
762 ieee80211_stop_queue(hw, ah->txqs[qnum].qnum);
John W. Linville81266ba2011-03-07 16:32:59 -0500763 }
764
765 return 0;
766}
767
768
Bruno Randolfcd2c5482010-12-22 19:20:32 +0900769const struct ieee80211_ops ath5k_hw_ops = {
770 .tx = ath5k_tx,
771 .start = ath5k_start,
772 .stop = ath5k_stop,
773 .add_interface = ath5k_add_interface,
774 /* .change_interface = not implemented */
775 .remove_interface = ath5k_remove_interface,
776 .config = ath5k_config,
777 .bss_info_changed = ath5k_bss_info_changed,
778 .prepare_multicast = ath5k_prepare_multicast,
779 .configure_filter = ath5k_configure_filter,
780 /* .set_tim = not implemented */
781 .set_key = ath5k_set_key,
782 /* .update_tkip_key = not implemented */
783 /* .hw_scan = not implemented */
784 .sw_scan_start = ath5k_sw_scan_start,
785 .sw_scan_complete = ath5k_sw_scan_complete,
786 .get_stats = ath5k_get_stats,
787 /* .get_tkip_seq = not implemented */
788 /* .set_frag_threshold = not implemented */
789 /* .set_rts_threshold = not implemented */
790 /* .sta_add = not implemented */
791 /* .sta_remove = not implemented */
792 /* .sta_notify = not implemented */
793 .conf_tx = ath5k_conf_tx,
794 .get_tsf = ath5k_get_tsf,
795 .set_tsf = ath5k_set_tsf,
796 .reset_tsf = ath5k_reset_tsf,
797 /* .tx_last_beacon = not implemented */
798 /* .ampdu_action = not needed */
799 .get_survey = ath5k_get_survey,
800 .set_coverage_class = ath5k_set_coverage_class,
801 /* .rfkill_poll = not implemented */
802 /* .flush = not implemented */
803 /* .channel_switch = not implemented */
804 /* .napi_poll = not implemented */
805 .set_antenna = ath5k_set_antenna,
806 .get_antenna = ath5k_get_antenna,
John W. Linville81266ba2011-03-07 16:32:59 -0500807 .set_ringparam = ath5k_set_ringparam,
808 .get_ringparam = ath5k_get_ringparam,
Bruno Randolfcd2c5482010-12-22 19:20:32 +0900809};