blob: 7aa2a6348f2ff91c3926eb371bd582d527f81e0e [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
69ath5k_start(struct ieee80211_hw *hw)
70{
71 return ath5k_init_hw(hw->priv);
72}
73
74
75static void
76ath5k_stop(struct ieee80211_hw *hw)
77{
78 ath5k_stop_hw(hw->priv);
79}
80
81
82static int
83ath5k_add_interface(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
84{
Pavel Roskine0d687b2011-07-14 20:21:55 -040085 struct ath5k_hw *ah = hw->priv;
Bruno Randolfcd2c5482010-12-22 19:20:32 +090086 int ret;
87 struct ath5k_vif *avf = (void *)vif->drv_priv;
88
Pavel Roskine0d687b2011-07-14 20:21:55 -040089 mutex_lock(&ah->lock);
Bruno Randolfcd2c5482010-12-22 19:20:32 +090090
91 if ((vif->type == NL80211_IFTYPE_AP ||
92 vif->type == NL80211_IFTYPE_ADHOC)
Pavel Roskine0d687b2011-07-14 20:21:55 -040093 && (ah->num_ap_vifs + ah->num_adhoc_vifs) >= ATH_BCBUF) {
Bruno Randolfcd2c5482010-12-22 19:20:32 +090094 ret = -ELNRNG;
95 goto end;
96 }
97
98 /* Don't allow other interfaces if one ad-hoc is configured.
99 * TODO: Fix the problems with ad-hoc and multiple other interfaces.
100 * We would need to operate the HW in ad-hoc mode to allow TSF updates
101 * for the IBSS, but this breaks with additional AP or STA interfaces
102 * at the moment. */
Pavel Roskine0d687b2011-07-14 20:21:55 -0400103 if (ah->num_adhoc_vifs ||
104 (ah->nvifs && vif->type == NL80211_IFTYPE_ADHOC)) {
105 ATH5K_ERR(ah, "Only one single ad-hoc interface is allowed.\n");
Bruno Randolfcd2c5482010-12-22 19:20:32 +0900106 ret = -ELNRNG;
107 goto end;
108 }
109
110 switch (vif->type) {
111 case NL80211_IFTYPE_AP:
112 case NL80211_IFTYPE_STATION:
113 case NL80211_IFTYPE_ADHOC:
114 case NL80211_IFTYPE_MESH_POINT:
115 avf->opmode = vif->type;
116 break;
117 default:
118 ret = -EOPNOTSUPP;
119 goto end;
120 }
121
Pavel Roskine0d687b2011-07-14 20:21:55 -0400122 ah->nvifs++;
123 ATH5K_DBG(ah, ATH5K_DEBUG_MODE, "add interface mode %d\n", avf->opmode);
Bruno Randolfcd2c5482010-12-22 19:20:32 +0900124
125 /* Assign the vap/adhoc to a beacon xmit slot. */
126 if ((avf->opmode == NL80211_IFTYPE_AP) ||
127 (avf->opmode == NL80211_IFTYPE_ADHOC) ||
128 (avf->opmode == NL80211_IFTYPE_MESH_POINT)) {
129 int slot;
130
Pavel Roskine0d687b2011-07-14 20:21:55 -0400131 WARN_ON(list_empty(&ah->bcbuf));
132 avf->bbuf = list_first_entry(&ah->bcbuf, struct ath5k_buf,
Bruno Randolfcd2c5482010-12-22 19:20:32 +0900133 list);
134 list_del(&avf->bbuf->list);
135
136 avf->bslot = 0;
137 for (slot = 0; slot < ATH_BCBUF; slot++) {
Pavel Roskine0d687b2011-07-14 20:21:55 -0400138 if (!ah->bslot[slot]) {
Bruno Randolfcd2c5482010-12-22 19:20:32 +0900139 avf->bslot = slot;
140 break;
141 }
142 }
Pavel Roskine0d687b2011-07-14 20:21:55 -0400143 BUG_ON(ah->bslot[avf->bslot] != NULL);
144 ah->bslot[avf->bslot] = vif;
Bruno Randolfcd2c5482010-12-22 19:20:32 +0900145 if (avf->opmode == NL80211_IFTYPE_AP)
Pavel Roskine0d687b2011-07-14 20:21:55 -0400146 ah->num_ap_vifs++;
Bruno Randolfcd2c5482010-12-22 19:20:32 +0900147 else if (avf->opmode == NL80211_IFTYPE_ADHOC)
Pavel Roskine0d687b2011-07-14 20:21:55 -0400148 ah->num_adhoc_vifs++;
Bruno Randolfcd2c5482010-12-22 19:20:32 +0900149 }
150
151 /* Any MAC address is fine, all others are included through the
152 * filter.
153 */
Pavel Roskine0d687b2011-07-14 20:21:55 -0400154 memcpy(&ah->lladdr, vif->addr, ETH_ALEN);
155 ath5k_hw_set_lladdr(ah, vif->addr);
Bruno Randolfcd2c5482010-12-22 19:20:32 +0900156
157 memcpy(&avf->lladdr, vif->addr, ETH_ALEN);
158
Pavel Roskine0d687b2011-07-14 20:21:55 -0400159 ath5k_update_bssid_mask_and_opmode(ah, vif);
Bruno Randolfcd2c5482010-12-22 19:20:32 +0900160 ret = 0;
161end:
Pavel Roskine0d687b2011-07-14 20:21:55 -0400162 mutex_unlock(&ah->lock);
Bruno Randolfcd2c5482010-12-22 19:20:32 +0900163 return ret;
164}
165
166
167static void
168ath5k_remove_interface(struct ieee80211_hw *hw,
169 struct ieee80211_vif *vif)
170{
Pavel Roskine0d687b2011-07-14 20:21:55 -0400171 struct ath5k_hw *ah = hw->priv;
Bruno Randolfcd2c5482010-12-22 19:20:32 +0900172 struct ath5k_vif *avf = (void *)vif->drv_priv;
173 unsigned int i;
174
Pavel Roskine0d687b2011-07-14 20:21:55 -0400175 mutex_lock(&ah->lock);
176 ah->nvifs--;
Bruno Randolfcd2c5482010-12-22 19:20:32 +0900177
178 if (avf->bbuf) {
Pavel Roskine0d687b2011-07-14 20:21:55 -0400179 ath5k_txbuf_free_skb(ah, avf->bbuf);
180 list_add_tail(&avf->bbuf->list, &ah->bcbuf);
Bruno Randolfcd2c5482010-12-22 19:20:32 +0900181 for (i = 0; i < ATH_BCBUF; i++) {
Pavel Roskine0d687b2011-07-14 20:21:55 -0400182 if (ah->bslot[i] == vif) {
183 ah->bslot[i] = NULL;
Bruno Randolfcd2c5482010-12-22 19:20:32 +0900184 break;
185 }
186 }
187 avf->bbuf = NULL;
188 }
189 if (avf->opmode == NL80211_IFTYPE_AP)
Pavel Roskine0d687b2011-07-14 20:21:55 -0400190 ah->num_ap_vifs--;
Bruno Randolfcd2c5482010-12-22 19:20:32 +0900191 else if (avf->opmode == NL80211_IFTYPE_ADHOC)
Pavel Roskine0d687b2011-07-14 20:21:55 -0400192 ah->num_adhoc_vifs--;
Bruno Randolfcd2c5482010-12-22 19:20:32 +0900193
Pavel Roskine0d687b2011-07-14 20:21:55 -0400194 ath5k_update_bssid_mask_and_opmode(ah, NULL);
195 mutex_unlock(&ah->lock);
Bruno Randolfcd2c5482010-12-22 19:20:32 +0900196}
197
198
199/*
200 * TODO: Phy disable/diversity etc
201 */
202static int
203ath5k_config(struct ieee80211_hw *hw, u32 changed)
204{
Pavel Roskine0d687b2011-07-14 20:21:55 -0400205 struct ath5k_hw *ah = hw->priv;
Bruno Randolfcd2c5482010-12-22 19:20:32 +0900206 struct ieee80211_conf *conf = &hw->conf;
207 int ret = 0;
Bruno Randolf76a9f6f2011-01-28 16:52:11 +0900208 int i;
Bruno Randolfcd2c5482010-12-22 19:20:32 +0900209
Pavel Roskine0d687b2011-07-14 20:21:55 -0400210 mutex_lock(&ah->lock);
Bruno Randolfcd2c5482010-12-22 19:20:32 +0900211
212 if (changed & IEEE80211_CONF_CHANGE_CHANNEL) {
Pavel Roskine0d687b2011-07-14 20:21:55 -0400213 ret = ath5k_chan_set(ah, conf->channel);
Bruno Randolfcd2c5482010-12-22 19:20:32 +0900214 if (ret < 0)
215 goto unlock;
216 }
217
218 if ((changed & IEEE80211_CONF_CHANGE_POWER) &&
Pavel Roskine0d687b2011-07-14 20:21:55 -0400219 (ah->power_level != conf->power_level)) {
220 ah->power_level = conf->power_level;
Bruno Randolfcd2c5482010-12-22 19:20:32 +0900221
222 /* Half dB steps */
223 ath5k_hw_set_txpower_limit(ah, (conf->power_level * 2));
224 }
225
Bruno Randolf76a9f6f2011-01-28 16:52:11 +0900226 if (changed & IEEE80211_CONF_CHANGE_RETRY_LIMITS) {
227 ah->ah_retry_long = conf->long_frame_max_tx_count;
228 ah->ah_retry_short = conf->short_frame_max_tx_count;
229
230 for (i = 0; i < ah->ah_capabilities.cap_queues.q_tx_num; i++)
231 ath5k_hw_set_tx_retry_limits(ah, i);
232 }
233
Bruno Randolfcd2c5482010-12-22 19:20:32 +0900234 /* TODO:
235 * 1) Move this on config_interface and handle each case
236 * separately eg. when we have only one STA vif, use
237 * AR5K_ANTMODE_SINGLE_AP
238 *
239 * 2) Allow the user to change antenna mode eg. when only
240 * one antenna is present
241 *
242 * 3) Allow the user to set default/tx antenna when possible
243 *
244 * 4) Default mode should handle 90% of the cases, together
245 * with fixed a/b and single AP modes we should be able to
246 * handle 99%. Sectored modes are extreme cases and i still
247 * haven't found a usage for them. If we decide to support them,
248 * then we must allow the user to set how many tx antennas we
249 * have available
250 */
251 ath5k_hw_set_antenna_mode(ah, ah->ah_ant_mode);
252
253unlock:
Pavel Roskine0d687b2011-07-14 20:21:55 -0400254 mutex_unlock(&ah->lock);
Bruno Randolfcd2c5482010-12-22 19:20:32 +0900255 return ret;
256}
257
258
259static void
260ath5k_bss_info_changed(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
261 struct ieee80211_bss_conf *bss_conf, u32 changes)
262{
263 struct ath5k_vif *avf = (void *)vif->drv_priv;
Pavel Roskine0d687b2011-07-14 20:21:55 -0400264 struct ath5k_hw *ah = hw->priv;
Bruno Randolfcd2c5482010-12-22 19:20:32 +0900265 struct ath_common *common = ath5k_hw_common(ah);
266 unsigned long flags;
267
Pavel Roskine0d687b2011-07-14 20:21:55 -0400268 mutex_lock(&ah->lock);
Bruno Randolfcd2c5482010-12-22 19:20:32 +0900269
270 if (changes & BSS_CHANGED_BSSID) {
271 /* Cache for later use during resets */
272 memcpy(common->curbssid, bss_conf->bssid, ETH_ALEN);
273 common->curaid = 0;
274 ath5k_hw_set_bssid(ah);
275 mmiowb();
276 }
277
278 if (changes & BSS_CHANGED_BEACON_INT)
Pavel Roskine0d687b2011-07-14 20:21:55 -0400279 ah->bintval = bss_conf->beacon_int;
Bruno Randolfcd2c5482010-12-22 19:20:32 +0900280
Felix Fietkaub1ad1b62011-04-09 23:10:21 +0200281 if (changes & BSS_CHANGED_ERP_SLOT) {
282 int slot_time;
283
284 ah->ah_short_slot = bss_conf->use_short_slot;
285 slot_time = ath5k_hw_get_default_slottime(ah) +
286 3 * ah->ah_coverage_class;
287 ath5k_hw_set_ifs_intervals(ah, slot_time);
288 }
289
Bruno Randolfcd2c5482010-12-22 19:20:32 +0900290 if (changes & BSS_CHANGED_ASSOC) {
291 avf->assoc = bss_conf->assoc;
292 if (bss_conf->assoc)
Pavel Roskine0d687b2011-07-14 20:21:55 -0400293 ah->assoc = bss_conf->assoc;
Bruno Randolfcd2c5482010-12-22 19:20:32 +0900294 else
Pavel Roskine0d687b2011-07-14 20:21:55 -0400295 ah->assoc = ath5k_any_vif_assoc(ah);
Bruno Randolfcd2c5482010-12-22 19:20:32 +0900296
Pavel Roskine0d687b2011-07-14 20:21:55 -0400297 if (ah->opmode == NL80211_IFTYPE_STATION)
298 ath5k_set_beacon_filter(hw, ah->assoc);
299 ath5k_hw_set_ledstate(ah, ah->assoc ?
Bruno Randolfcd2c5482010-12-22 19:20:32 +0900300 AR5K_LED_ASSOC : AR5K_LED_INIT);
301 if (bss_conf->assoc) {
Pavel Roskine0d687b2011-07-14 20:21:55 -0400302 ATH5K_DBG(ah, ATH5K_DEBUG_ANY,
Bruno Randolfcd2c5482010-12-22 19:20:32 +0900303 "Bss Info ASSOC %d, bssid: %pM\n",
304 bss_conf->aid, common->curbssid);
305 common->curaid = bss_conf->aid;
306 ath5k_hw_set_bssid(ah);
307 /* Once ANI is available you would start it here */
308 }
309 }
310
311 if (changes & BSS_CHANGED_BEACON) {
Pavel Roskine0d687b2011-07-14 20:21:55 -0400312 spin_lock_irqsave(&ah->block, flags);
Bruno Randolfcd2c5482010-12-22 19:20:32 +0900313 ath5k_beacon_update(hw, vif);
Pavel Roskine0d687b2011-07-14 20:21:55 -0400314 spin_unlock_irqrestore(&ah->block, flags);
Bruno Randolfcd2c5482010-12-22 19:20:32 +0900315 }
316
317 if (changes & BSS_CHANGED_BEACON_ENABLED)
Pavel Roskine0d687b2011-07-14 20:21:55 -0400318 ah->enable_beacon = bss_conf->enable_beacon;
Bruno Randolfcd2c5482010-12-22 19:20:32 +0900319
320 if (changes & (BSS_CHANGED_BEACON | BSS_CHANGED_BEACON_ENABLED |
321 BSS_CHANGED_BEACON_INT))
Pavel Roskine0d687b2011-07-14 20:21:55 -0400322 ath5k_beacon_config(ah);
Bruno Randolfcd2c5482010-12-22 19:20:32 +0900323
Pavel Roskine0d687b2011-07-14 20:21:55 -0400324 mutex_unlock(&ah->lock);
Bruno Randolfcd2c5482010-12-22 19:20:32 +0900325}
326
327
328static u64
329ath5k_prepare_multicast(struct ieee80211_hw *hw,
330 struct netdev_hw_addr_list *mc_list)
331{
332 u32 mfilt[2], val;
333 u8 pos;
334 struct netdev_hw_addr *ha;
335
336 mfilt[0] = 0;
337 mfilt[1] = 1;
338
339 netdev_hw_addr_list_for_each(ha, mc_list) {
340 /* calculate XOR of eight 6-bit values */
341 val = get_unaligned_le32(ha->addr + 0);
342 pos = (val >> 18) ^ (val >> 12) ^ (val >> 6) ^ val;
343 val = get_unaligned_le32(ha->addr + 3);
344 pos ^= (val >> 18) ^ (val >> 12) ^ (val >> 6) ^ val;
345 pos &= 0x3f;
346 mfilt[pos / 32] |= (1 << (pos % 32));
347 /* XXX: we might be able to just do this instead,
348 * but not sure, needs testing, if we do use this we'd
Pavel Roskin6a2a0e72011-07-09 00:17:51 -0400349 * need to inform below not to reset the mcast */
Bruno Randolfcd2c5482010-12-22 19:20:32 +0900350 /* ath5k_hw_set_mcast_filterindex(ah,
351 * ha->addr[5]); */
352 }
353
354 return ((u64)(mfilt[1]) << 32) | mfilt[0];
355}
356
357
358/*
359 * o always accept unicast, broadcast, and multicast traffic
360 * o multicast traffic for all BSSIDs will be enabled if mac80211
361 * says it should be
362 * o maintain current state of phy ofdm or phy cck error reception.
363 * If the hardware detects any of these type of errors then
364 * ath5k_hw_get_rx_filter() will pass to us the respective
365 * hardware filters to be able to receive these type of frames.
366 * o probe request frames are accepted only when operating in
367 * hostap, adhoc, or monitor modes
368 * o enable promiscuous mode according to the interface state
369 * o accept beacons:
370 * - when operating in adhoc mode so the 802.11 layer creates
371 * node table entries for peers,
372 * - when operating in station mode for collecting rssi data when
373 * the station is otherwise quiet, or
374 * - when scanning
375 */
376static void
377ath5k_configure_filter(struct ieee80211_hw *hw, unsigned int changed_flags,
378 unsigned int *new_flags, u64 multicast)
379{
380#define SUPPORTED_FIF_FLAGS \
381 (FIF_PROMISC_IN_BSS | FIF_ALLMULTI | FIF_FCSFAIL | \
382 FIF_PLCPFAIL | FIF_CONTROL | FIF_OTHER_BSS | \
383 FIF_BCN_PRBRESP_PROMISC)
384
Pavel Roskine0d687b2011-07-14 20:21:55 -0400385 struct ath5k_hw *ah = hw->priv;
Bruno Randolfcd2c5482010-12-22 19:20:32 +0900386 u32 mfilt[2], rfilt;
Ben Greeare4b0b322011-03-03 14:39:05 -0800387 struct ath5k_vif_iter_data iter_data; /* to count STA interfaces */
Bruno Randolfcd2c5482010-12-22 19:20:32 +0900388
Pavel Roskine0d687b2011-07-14 20:21:55 -0400389 mutex_lock(&ah->lock);
Bruno Randolfcd2c5482010-12-22 19:20:32 +0900390
391 mfilt[0] = multicast;
392 mfilt[1] = multicast >> 32;
393
394 /* Only deal with supported flags */
395 changed_flags &= SUPPORTED_FIF_FLAGS;
396 *new_flags &= SUPPORTED_FIF_FLAGS;
397
398 /* If HW detects any phy or radar errors, leave those filters on.
399 * Also, always enable Unicast, Broadcasts and Multicast
400 * XXX: move unicast, bssid broadcasts and multicast to mac80211 */
401 rfilt = (ath5k_hw_get_rx_filter(ah) & (AR5K_RX_FILTER_PHYERR)) |
402 (AR5K_RX_FILTER_UCAST | AR5K_RX_FILTER_BCAST |
403 AR5K_RX_FILTER_MCAST);
404
405 if (changed_flags & (FIF_PROMISC_IN_BSS | FIF_OTHER_BSS)) {
406 if (*new_flags & FIF_PROMISC_IN_BSS)
Pavel Roskine0d687b2011-07-14 20:21:55 -0400407 __set_bit(ATH_STAT_PROMISC, ah->status);
Bruno Randolfcd2c5482010-12-22 19:20:32 +0900408 else
Pavel Roskine0d687b2011-07-14 20:21:55 -0400409 __clear_bit(ATH_STAT_PROMISC, ah->status);
Bruno Randolfcd2c5482010-12-22 19:20:32 +0900410 }
411
Pavel Roskine0d687b2011-07-14 20:21:55 -0400412 if (test_bit(ATH_STAT_PROMISC, ah->status))
Bruno Randolfcd2c5482010-12-22 19:20:32 +0900413 rfilt |= AR5K_RX_FILTER_PROM;
414
415 /* Note, AR5K_RX_FILTER_MCAST is already enabled */
416 if (*new_flags & FIF_ALLMULTI) {
417 mfilt[0] = ~0;
418 mfilt[1] = ~0;
419 }
420
421 /* This is the best we can do */
422 if (*new_flags & (FIF_FCSFAIL | FIF_PLCPFAIL))
423 rfilt |= AR5K_RX_FILTER_PHYERR;
424
425 /* FIF_BCN_PRBRESP_PROMISC really means to enable beacons
426 * and probes for any BSSID */
Pavel Roskine0d687b2011-07-14 20:21:55 -0400427 if ((*new_flags & FIF_BCN_PRBRESP_PROMISC) || (ah->nvifs > 1))
Bruno Randolfcd2c5482010-12-22 19:20:32 +0900428 rfilt |= AR5K_RX_FILTER_BEACON;
429
430 /* FIF_CONTROL doc says that if FIF_PROMISC_IN_BSS is not
431 * set we should only pass on control frames for this
432 * station. This needs testing. I believe right now this
433 * enables *all* control frames, which is OK.. but
434 * but we should see if we can improve on granularity */
435 if (*new_flags & FIF_CONTROL)
436 rfilt |= AR5K_RX_FILTER_CONTROL;
437
438 /* Additional settings per mode -- this is per ath5k */
439
440 /* XXX move these to mac80211, and add a beacon IFF flag to mac80211 */
441
Pavel Roskine0d687b2011-07-14 20:21:55 -0400442 switch (ah->opmode) {
Bruno Randolfcd2c5482010-12-22 19:20:32 +0900443 case NL80211_IFTYPE_MESH_POINT:
444 rfilt |= AR5K_RX_FILTER_CONTROL |
445 AR5K_RX_FILTER_BEACON |
446 AR5K_RX_FILTER_PROBEREQ |
447 AR5K_RX_FILTER_PROM;
448 break;
449 case NL80211_IFTYPE_AP:
450 case NL80211_IFTYPE_ADHOC:
451 rfilt |= AR5K_RX_FILTER_PROBEREQ |
452 AR5K_RX_FILTER_BEACON;
453 break;
454 case NL80211_IFTYPE_STATION:
Pavel Roskine0d687b2011-07-14 20:21:55 -0400455 if (ah->assoc)
Bruno Randolfcd2c5482010-12-22 19:20:32 +0900456 rfilt |= AR5K_RX_FILTER_BEACON;
457 default:
458 break;
459 }
460
Ben Greeare4b0b322011-03-03 14:39:05 -0800461 iter_data.hw_macaddr = NULL;
462 iter_data.n_stas = 0;
463 iter_data.need_set_hw_addr = false;
Pavel Roskine0d687b2011-07-14 20:21:55 -0400464 ieee80211_iterate_active_interfaces_atomic(ah->hw, ath5k_vif_iter,
Ben Greeare4b0b322011-03-03 14:39:05 -0800465 &iter_data);
466
467 /* Set up RX Filter */
468 if (iter_data.n_stas > 1) {
469 /* If you have multiple STA interfaces connected to
470 * different APs, ARPs are not received (most of the time?)
Pavel Roskin6a2a0e72011-07-09 00:17:51 -0400471 * Enabling PROMISC appears to fix that problem.
Ben Greeare4b0b322011-03-03 14:39:05 -0800472 */
473 rfilt |= AR5K_RX_FILTER_PROM;
474 }
475
Bruno Randolfcd2c5482010-12-22 19:20:32 +0900476 /* Set filters */
477 ath5k_hw_set_rx_filter(ah, rfilt);
478
479 /* Set multicast bits */
480 ath5k_hw_set_mcast_filter(ah, mfilt[0], mfilt[1]);
481 /* Set the cached hw filter flags, this will later actually
482 * be set in HW */
Pavel Roskine0d687b2011-07-14 20:21:55 -0400483 ah->filter_flags = rfilt;
Bruno Randolfcd2c5482010-12-22 19:20:32 +0900484
Pavel Roskine0d687b2011-07-14 20:21:55 -0400485 mutex_unlock(&ah->lock);
Bruno Randolfcd2c5482010-12-22 19:20:32 +0900486}
487
488
489static int
490ath5k_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
491 struct ieee80211_vif *vif, struct ieee80211_sta *sta,
492 struct ieee80211_key_conf *key)
493{
Pavel Roskine0d687b2011-07-14 20:21:55 -0400494 struct ath5k_hw *ah = hw->priv;
Bruno Randolfcd2c5482010-12-22 19:20:32 +0900495 struct ath_common *common = ath5k_hw_common(ah);
496 int ret = 0;
497
John W. Linville18cb6e32011-01-05 09:39:59 -0500498 if (ath5k_modparam_nohwcrypt)
Bruno Randolfcd2c5482010-12-22 19:20:32 +0900499 return -EOPNOTSUPP;
500
501 switch (key->cipher) {
502 case WLAN_CIPHER_SUITE_WEP40:
503 case WLAN_CIPHER_SUITE_WEP104:
504 case WLAN_CIPHER_SUITE_TKIP:
505 break;
506 case WLAN_CIPHER_SUITE_CCMP:
507 if (common->crypt_caps & ATH_CRYPT_CAP_CIPHER_AESCCM)
508 break;
509 return -EOPNOTSUPP;
510 default:
511 WARN_ON(1);
512 return -EINVAL;
513 }
514
Pavel Roskine0d687b2011-07-14 20:21:55 -0400515 mutex_lock(&ah->lock);
Bruno Randolfcd2c5482010-12-22 19:20:32 +0900516
517 switch (cmd) {
518 case SET_KEY:
519 ret = ath_key_config(common, vif, sta, key);
520 if (ret >= 0) {
521 key->hw_key_idx = ret;
522 /* push IV and Michael MIC generation to stack */
523 key->flags |= IEEE80211_KEY_FLAG_GENERATE_IV;
524 if (key->cipher == WLAN_CIPHER_SUITE_TKIP)
525 key->flags |= IEEE80211_KEY_FLAG_GENERATE_MMIC;
526 if (key->cipher == WLAN_CIPHER_SUITE_CCMP)
527 key->flags |= IEEE80211_KEY_FLAG_SW_MGMT;
528 ret = 0;
529 }
530 break;
531 case DISABLE_KEY:
532 ath_key_delete(common, key);
533 break;
534 default:
535 ret = -EINVAL;
536 }
537
538 mmiowb();
Pavel Roskine0d687b2011-07-14 20:21:55 -0400539 mutex_unlock(&ah->lock);
Bruno Randolfcd2c5482010-12-22 19:20:32 +0900540 return ret;
541}
542
543
544static void
545ath5k_sw_scan_start(struct ieee80211_hw *hw)
546{
Pavel Roskine0d687b2011-07-14 20:21:55 -0400547 struct ath5k_hw *ah = hw->priv;
548 if (!ah->assoc)
549 ath5k_hw_set_ledstate(ah, AR5K_LED_SCAN);
Bruno Randolfcd2c5482010-12-22 19:20:32 +0900550}
551
552
553static void
554ath5k_sw_scan_complete(struct ieee80211_hw *hw)
555{
Pavel Roskine0d687b2011-07-14 20:21:55 -0400556 struct ath5k_hw *ah = hw->priv;
557 ath5k_hw_set_ledstate(ah, ah->assoc ?
Bruno Randolfcd2c5482010-12-22 19:20:32 +0900558 AR5K_LED_ASSOC : AR5K_LED_INIT);
559}
560
561
562static int
563ath5k_get_stats(struct ieee80211_hw *hw,
564 struct ieee80211_low_level_stats *stats)
565{
Pavel Roskine0d687b2011-07-14 20:21:55 -0400566 struct ath5k_hw *ah = hw->priv;
Bruno Randolfcd2c5482010-12-22 19:20:32 +0900567
568 /* Force update */
Pavel Roskine0d687b2011-07-14 20:21:55 -0400569 ath5k_hw_update_mib_counters(ah);
Bruno Randolfcd2c5482010-12-22 19:20:32 +0900570
Pavel Roskine0d687b2011-07-14 20:21:55 -0400571 stats->dot11ACKFailureCount = ah->stats.ack_fail;
572 stats->dot11RTSFailureCount = ah->stats.rts_fail;
573 stats->dot11RTSSuccessCount = ah->stats.rts_ok;
574 stats->dot11FCSErrorCount = ah->stats.fcs_error;
Bruno Randolfcd2c5482010-12-22 19:20:32 +0900575
576 return 0;
577}
578
579
580static int
581ath5k_conf_tx(struct ieee80211_hw *hw, u16 queue,
582 const struct ieee80211_tx_queue_params *params)
583{
Pavel Roskine0d687b2011-07-14 20:21:55 -0400584 struct ath5k_hw *ah = hw->priv;
Bruno Randolfcd2c5482010-12-22 19:20:32 +0900585 struct ath5k_txq_info qi;
586 int ret = 0;
587
588 if (queue >= ah->ah_capabilities.cap_queues.q_tx_num)
589 return 0;
590
Pavel Roskine0d687b2011-07-14 20:21:55 -0400591 mutex_lock(&ah->lock);
Bruno Randolfcd2c5482010-12-22 19:20:32 +0900592
593 ath5k_hw_get_tx_queueprops(ah, queue, &qi);
594
595 qi.tqi_aifs = params->aifs;
596 qi.tqi_cw_min = params->cw_min;
597 qi.tqi_cw_max = params->cw_max;
598 qi.tqi_burst_time = params->txop;
599
Pavel Roskine0d687b2011-07-14 20:21:55 -0400600 ATH5K_DBG(ah, ATH5K_DEBUG_ANY,
Bruno Randolfcd2c5482010-12-22 19:20:32 +0900601 "Configure tx [queue %d], "
602 "aifs: %d, cw_min: %d, cw_max: %d, txop: %d\n",
603 queue, params->aifs, params->cw_min,
604 params->cw_max, params->txop);
605
606 if (ath5k_hw_set_tx_queueprops(ah, queue, &qi)) {
Pavel Roskine0d687b2011-07-14 20:21:55 -0400607 ATH5K_ERR(ah,
Bruno Randolfcd2c5482010-12-22 19:20:32 +0900608 "Unable to update hardware queue %u!\n", queue);
609 ret = -EIO;
610 } else
611 ath5k_hw_reset_tx_queue(ah, queue);
612
Pavel Roskine0d687b2011-07-14 20:21:55 -0400613 mutex_unlock(&ah->lock);
Bruno Randolfcd2c5482010-12-22 19:20:32 +0900614
615 return ret;
616}
617
618
619static u64
620ath5k_get_tsf(struct ieee80211_hw *hw)
621{
Pavel Roskine0d687b2011-07-14 20:21:55 -0400622 struct ath5k_hw *ah = hw->priv;
Bruno Randolfcd2c5482010-12-22 19:20:32 +0900623
Pavel Roskine0d687b2011-07-14 20:21:55 -0400624 return ath5k_hw_get_tsf64(ah);
Bruno Randolfcd2c5482010-12-22 19:20:32 +0900625}
626
627
628static void
629ath5k_set_tsf(struct ieee80211_hw *hw, u64 tsf)
630{
Pavel Roskine0d687b2011-07-14 20:21:55 -0400631 struct ath5k_hw *ah = hw->priv;
Bruno Randolfcd2c5482010-12-22 19:20:32 +0900632
Pavel Roskine0d687b2011-07-14 20:21:55 -0400633 ath5k_hw_set_tsf64(ah, tsf);
Bruno Randolfcd2c5482010-12-22 19:20:32 +0900634}
635
636
637static void
638ath5k_reset_tsf(struct ieee80211_hw *hw)
639{
Pavel Roskine0d687b2011-07-14 20:21:55 -0400640 struct ath5k_hw *ah = hw->priv;
Bruno Randolfcd2c5482010-12-22 19:20:32 +0900641
642 /*
643 * in IBSS mode we need to update the beacon timers too.
644 * this will also reset the TSF if we call it with 0
645 */
Pavel Roskine0d687b2011-07-14 20:21:55 -0400646 if (ah->opmode == NL80211_IFTYPE_ADHOC)
647 ath5k_beacon_update_timers(ah, 0);
Bruno Randolfcd2c5482010-12-22 19:20:32 +0900648 else
Pavel Roskine0d687b2011-07-14 20:21:55 -0400649 ath5k_hw_reset_tsf(ah);
Bruno Randolfcd2c5482010-12-22 19:20:32 +0900650}
651
652
653static int
654ath5k_get_survey(struct ieee80211_hw *hw, int idx, struct survey_info *survey)
655{
Pavel Roskine0d687b2011-07-14 20:21:55 -0400656 struct ath5k_hw *ah = hw->priv;
Bruno Randolfcd2c5482010-12-22 19:20:32 +0900657 struct ieee80211_conf *conf = &hw->conf;
Pavel Roskine0d687b2011-07-14 20:21:55 -0400658 struct ath_common *common = ath5k_hw_common(ah);
Bruno Randolfcd2c5482010-12-22 19:20:32 +0900659 struct ath_cycle_counters *cc = &common->cc_survey;
660 unsigned int div = common->clockrate * 1000;
661
662 if (idx != 0)
663 return -ENOENT;
664
665 spin_lock_bh(&common->cc_lock);
666 ath_hw_cycle_counters_update(common);
667 if (cc->cycles > 0) {
Pavel Roskine0d687b2011-07-14 20:21:55 -0400668 ah->survey.channel_time += cc->cycles / div;
669 ah->survey.channel_time_busy += cc->rx_busy / div;
670 ah->survey.channel_time_rx += cc->rx_frame / div;
671 ah->survey.channel_time_tx += cc->tx_frame / div;
Bruno Randolfcd2c5482010-12-22 19:20:32 +0900672 }
673 memset(cc, 0, sizeof(*cc));
674 spin_unlock_bh(&common->cc_lock);
675
Pavel Roskine0d687b2011-07-14 20:21:55 -0400676 memcpy(survey, &ah->survey, sizeof(*survey));
Bruno Randolfcd2c5482010-12-22 19:20:32 +0900677
678 survey->channel = conf->channel;
Pavel Roskine0d687b2011-07-14 20:21:55 -0400679 survey->noise = ah->ah_noise_floor;
Bruno Randolfcd2c5482010-12-22 19:20:32 +0900680 survey->filled = SURVEY_INFO_NOISE_DBM |
681 SURVEY_INFO_CHANNEL_TIME |
682 SURVEY_INFO_CHANNEL_TIME_BUSY |
683 SURVEY_INFO_CHANNEL_TIME_RX |
684 SURVEY_INFO_CHANNEL_TIME_TX;
685
686 return 0;
687}
688
689
690/**
691 * ath5k_set_coverage_class - Set IEEE 802.11 coverage class
692 *
693 * @hw: struct ieee80211_hw pointer
694 * @coverage_class: IEEE 802.11 coverage class number
695 *
696 * Mac80211 callback. Sets slot time, ACK timeout and CTS timeout for given
697 * coverage class. The values are persistent, they are restored after device
698 * reset.
699 */
700static void
701ath5k_set_coverage_class(struct ieee80211_hw *hw, u8 coverage_class)
702{
Pavel Roskine0d687b2011-07-14 20:21:55 -0400703 struct ath5k_hw *ah = hw->priv;
Bruno Randolfcd2c5482010-12-22 19:20:32 +0900704
Pavel Roskine0d687b2011-07-14 20:21:55 -0400705 mutex_lock(&ah->lock);
706 ath5k_hw_set_coverage_class(ah, coverage_class);
707 mutex_unlock(&ah->lock);
Bruno Randolfcd2c5482010-12-22 19:20:32 +0900708}
709
710
711static int
712ath5k_set_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
716 if (tx_ant == 1 && rx_ant == 1)
Pavel Roskine0d687b2011-07-14 20:21:55 -0400717 ath5k_hw_set_antenna_mode(ah, AR5K_ANTMODE_FIXED_A);
Bruno Randolfcd2c5482010-12-22 19:20:32 +0900718 else if (tx_ant == 2 && rx_ant == 2)
Pavel Roskine0d687b2011-07-14 20:21:55 -0400719 ath5k_hw_set_antenna_mode(ah, AR5K_ANTMODE_FIXED_B);
Bruno Randolfcd2c5482010-12-22 19:20:32 +0900720 else if ((tx_ant & 3) == 3 && (rx_ant & 3) == 3)
Pavel Roskine0d687b2011-07-14 20:21:55 -0400721 ath5k_hw_set_antenna_mode(ah, AR5K_ANTMODE_DEFAULT);
Bruno Randolfcd2c5482010-12-22 19:20:32 +0900722 else
723 return -EINVAL;
724 return 0;
725}
726
727
728static int
729ath5k_get_antenna(struct ieee80211_hw *hw, u32 *tx_ant, u32 *rx_ant)
730{
Pavel Roskine0d687b2011-07-14 20:21:55 -0400731 struct ath5k_hw *ah = hw->priv;
Bruno Randolfcd2c5482010-12-22 19:20:32 +0900732
Pavel Roskine0d687b2011-07-14 20:21:55 -0400733 switch (ah->ah_ant_mode) {
Bruno Randolfcd2c5482010-12-22 19:20:32 +0900734 case AR5K_ANTMODE_FIXED_A:
735 *tx_ant = 1; *rx_ant = 1; break;
736 case AR5K_ANTMODE_FIXED_B:
737 *tx_ant = 2; *rx_ant = 2; break;
738 case AR5K_ANTMODE_DEFAULT:
739 *tx_ant = 3; *rx_ant = 3; break;
740 }
741 return 0;
742}
743
744
John W. Linville81266ba2011-03-07 16:32:59 -0500745static void ath5k_get_ringparam(struct ieee80211_hw *hw,
746 u32 *tx, u32 *tx_max, u32 *rx, u32 *rx_max)
747{
Pavel Roskine0d687b2011-07-14 20:21:55 -0400748 struct ath5k_hw *ah = hw->priv;
John W. Linville81266ba2011-03-07 16:32:59 -0500749
Pavel Roskine0d687b2011-07-14 20:21:55 -0400750 *tx = ah->txqs[AR5K_TX_QUEUE_ID_DATA_MIN].txq_max;
John W. Linville81266ba2011-03-07 16:32:59 -0500751
752 *tx_max = ATH5K_TXQ_LEN_MAX;
753 *rx = *rx_max = ATH_RXBUF;
754}
755
756
757static int ath5k_set_ringparam(struct ieee80211_hw *hw, u32 tx, u32 rx)
758{
Pavel Roskine0d687b2011-07-14 20:21:55 -0400759 struct ath5k_hw *ah = hw->priv;
John W. Linville81266ba2011-03-07 16:32:59 -0500760 u16 qnum;
761
762 /* only support setting tx ring size for now */
763 if (rx != ATH_RXBUF)
764 return -EINVAL;
765
766 /* restrict tx ring size min/max */
767 if (!tx || tx > ATH5K_TXQ_LEN_MAX)
768 return -EINVAL;
769
Pavel Roskine0d687b2011-07-14 20:21:55 -0400770 for (qnum = 0; qnum < ARRAY_SIZE(ah->txqs); qnum++) {
771 if (!ah->txqs[qnum].setup)
John W. Linville81266ba2011-03-07 16:32:59 -0500772 continue;
Pavel Roskine0d687b2011-07-14 20:21:55 -0400773 if (ah->txqs[qnum].qnum < AR5K_TX_QUEUE_ID_DATA_MIN ||
774 ah->txqs[qnum].qnum > AR5K_TX_QUEUE_ID_DATA_MAX)
John W. Linville81266ba2011-03-07 16:32:59 -0500775 continue;
776
Pavel Roskine0d687b2011-07-14 20:21:55 -0400777 ah->txqs[qnum].txq_max = tx;
778 if (ah->txqs[qnum].txq_len >= ah->txqs[qnum].txq_max)
779 ieee80211_stop_queue(hw, ah->txqs[qnum].qnum);
John W. Linville81266ba2011-03-07 16:32:59 -0500780 }
781
782 return 0;
783}
784
785
Bruno Randolfcd2c5482010-12-22 19:20:32 +0900786const struct ieee80211_ops ath5k_hw_ops = {
787 .tx = ath5k_tx,
788 .start = ath5k_start,
789 .stop = ath5k_stop,
790 .add_interface = ath5k_add_interface,
791 /* .change_interface = not implemented */
792 .remove_interface = ath5k_remove_interface,
793 .config = ath5k_config,
794 .bss_info_changed = ath5k_bss_info_changed,
795 .prepare_multicast = ath5k_prepare_multicast,
796 .configure_filter = ath5k_configure_filter,
797 /* .set_tim = not implemented */
798 .set_key = ath5k_set_key,
799 /* .update_tkip_key = not implemented */
800 /* .hw_scan = not implemented */
801 .sw_scan_start = ath5k_sw_scan_start,
802 .sw_scan_complete = ath5k_sw_scan_complete,
803 .get_stats = ath5k_get_stats,
804 /* .get_tkip_seq = not implemented */
805 /* .set_frag_threshold = not implemented */
806 /* .set_rts_threshold = not implemented */
807 /* .sta_add = not implemented */
808 /* .sta_remove = not implemented */
809 /* .sta_notify = not implemented */
810 .conf_tx = ath5k_conf_tx,
811 .get_tsf = ath5k_get_tsf,
812 .set_tsf = ath5k_set_tsf,
813 .reset_tsf = ath5k_reset_tsf,
814 /* .tx_last_beacon = not implemented */
815 /* .ampdu_action = not needed */
816 .get_survey = ath5k_get_survey,
817 .set_coverage_class = ath5k_set_coverage_class,
818 /* .rfkill_poll = not implemented */
819 /* .flush = not implemented */
820 /* .channel_switch = not implemented */
821 /* .napi_poll = not implemented */
822 .set_antenna = ath5k_set_antenna,
823 .get_antenna = ath5k_get_antenna,
John W. Linville81266ba2011-03-07 16:32:59 -0500824 .set_ringparam = ath5k_set_ringparam,
825 .get_ringparam = ath5k_get_ringparam,
Bruno Randolfcd2c5482010-12-22 19:20:32 +0900826};