blob: 493908299bb464ee549385ed176f8b9b63797414 [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{
56 struct ath5k_softc *sc = hw->priv;
57 u16 qnum = skb_get_queue_mapping(skb);
58
59 if (WARN_ON(qnum >= sc->ah->ah_capabilities.cap_queues.q_tx_num)) {
60 dev_kfree_skb_any(skb);
Johannes Berg7bb45682011-02-24 14:42:06 +010061 return;
Bruno Randolfcd2c5482010-12-22 19:20:32 +090062 }
63
Johannes Berg7bb45682011-02-24 14:42:06 +010064 ath5k_tx_queue(hw, skb, &sc->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{
85 struct ath5k_softc *sc = hw->priv;
86 int ret;
87 struct ath5k_vif *avf = (void *)vif->drv_priv;
88
89 mutex_lock(&sc->lock);
90
91 if ((vif->type == NL80211_IFTYPE_AP ||
92 vif->type == NL80211_IFTYPE_ADHOC)
93 && (sc->num_ap_vifs + sc->num_adhoc_vifs) >= ATH_BCBUF) {
94 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. */
103 if (sc->num_adhoc_vifs ||
104 (sc->nvifs && vif->type == NL80211_IFTYPE_ADHOC)) {
105 ATH5K_ERR(sc, "Only one single ad-hoc interface is allowed.\n");
106 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
122 sc->nvifs++;
123 ATH5K_DBG(sc, ATH5K_DEBUG_MODE, "add interface mode %d\n", avf->opmode);
124
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
131 WARN_ON(list_empty(&sc->bcbuf));
132 avf->bbuf = list_first_entry(&sc->bcbuf, struct ath5k_buf,
133 list);
134 list_del(&avf->bbuf->list);
135
136 avf->bslot = 0;
137 for (slot = 0; slot < ATH_BCBUF; slot++) {
138 if (!sc->bslot[slot]) {
139 avf->bslot = slot;
140 break;
141 }
142 }
143 BUG_ON(sc->bslot[avf->bslot] != NULL);
144 sc->bslot[avf->bslot] = vif;
145 if (avf->opmode == NL80211_IFTYPE_AP)
146 sc->num_ap_vifs++;
147 else if (avf->opmode == NL80211_IFTYPE_ADHOC)
148 sc->num_adhoc_vifs++;
149 }
150
151 /* Any MAC address is fine, all others are included through the
152 * filter.
153 */
154 memcpy(&sc->lladdr, vif->addr, ETH_ALEN);
155 ath5k_hw_set_lladdr(sc->ah, vif->addr);
156
157 memcpy(&avf->lladdr, vif->addr, ETH_ALEN);
158
Ben Greeare4b0b322011-03-03 14:39:05 -0800159 ath5k_update_bssid_mask_and_opmode(sc, vif);
Bruno Randolfcd2c5482010-12-22 19:20:32 +0900160 ret = 0;
161end:
162 mutex_unlock(&sc->lock);
163 return ret;
164}
165
166
167static void
168ath5k_remove_interface(struct ieee80211_hw *hw,
169 struct ieee80211_vif *vif)
170{
171 struct ath5k_softc *sc = hw->priv;
172 struct ath5k_vif *avf = (void *)vif->drv_priv;
173 unsigned int i;
174
175 mutex_lock(&sc->lock);
176 sc->nvifs--;
177
178 if (avf->bbuf) {
179 ath5k_txbuf_free_skb(sc, avf->bbuf);
180 list_add_tail(&avf->bbuf->list, &sc->bcbuf);
181 for (i = 0; i < ATH_BCBUF; i++) {
182 if (sc->bslot[i] == vif) {
183 sc->bslot[i] = NULL;
184 break;
185 }
186 }
187 avf->bbuf = NULL;
188 }
189 if (avf->opmode == NL80211_IFTYPE_AP)
190 sc->num_ap_vifs--;
191 else if (avf->opmode == NL80211_IFTYPE_ADHOC)
192 sc->num_adhoc_vifs--;
193
194 ath5k_update_bssid_mask_and_opmode(sc, NULL);
195 mutex_unlock(&sc->lock);
196}
197
198
199/*
200 * TODO: Phy disable/diversity etc
201 */
202static int
203ath5k_config(struct ieee80211_hw *hw, u32 changed)
204{
205 struct ath5k_softc *sc = hw->priv;
206 struct ath5k_hw *ah = sc->ah;
207 struct ieee80211_conf *conf = &hw->conf;
208 int ret = 0;
Bruno Randolf76a9f6f2011-01-28 16:52:11 +0900209 int i;
Bruno Randolfcd2c5482010-12-22 19:20:32 +0900210
211 mutex_lock(&sc->lock);
212
213 if (changed & IEEE80211_CONF_CHANGE_CHANNEL) {
214 ret = ath5k_chan_set(sc, conf->channel);
215 if (ret < 0)
216 goto unlock;
217 }
218
219 if ((changed & IEEE80211_CONF_CHANGE_POWER) &&
220 (sc->power_level != conf->power_level)) {
221 sc->power_level = conf->power_level;
222
223 /* Half dB steps */
224 ath5k_hw_set_txpower_limit(ah, (conf->power_level * 2));
225 }
226
Bruno Randolf76a9f6f2011-01-28 16:52:11 +0900227 if (changed & IEEE80211_CONF_CHANGE_RETRY_LIMITS) {
228 ah->ah_retry_long = conf->long_frame_max_tx_count;
229 ah->ah_retry_short = conf->short_frame_max_tx_count;
230
231 for (i = 0; i < ah->ah_capabilities.cap_queues.q_tx_num; i++)
232 ath5k_hw_set_tx_retry_limits(ah, i);
233 }
234
Bruno Randolfcd2c5482010-12-22 19:20:32 +0900235 /* TODO:
236 * 1) Move this on config_interface and handle each case
237 * separately eg. when we have only one STA vif, use
238 * AR5K_ANTMODE_SINGLE_AP
239 *
240 * 2) Allow the user to change antenna mode eg. when only
241 * one antenna is present
242 *
243 * 3) Allow the user to set default/tx antenna when possible
244 *
245 * 4) Default mode should handle 90% of the cases, together
246 * with fixed a/b and single AP modes we should be able to
247 * handle 99%. Sectored modes are extreme cases and i still
248 * haven't found a usage for them. If we decide to support them,
249 * then we must allow the user to set how many tx antennas we
250 * have available
251 */
252 ath5k_hw_set_antenna_mode(ah, ah->ah_ant_mode);
253
254unlock:
255 mutex_unlock(&sc->lock);
256 return ret;
257}
258
259
260static void
261ath5k_bss_info_changed(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
262 struct ieee80211_bss_conf *bss_conf, u32 changes)
263{
264 struct ath5k_vif *avf = (void *)vif->drv_priv;
265 struct ath5k_softc *sc = hw->priv;
266 struct ath5k_hw *ah = sc->ah;
267 struct ath_common *common = ath5k_hw_common(ah);
268 unsigned long flags;
269
270 mutex_lock(&sc->lock);
271
272 if (changes & BSS_CHANGED_BSSID) {
273 /* Cache for later use during resets */
274 memcpy(common->curbssid, bss_conf->bssid, ETH_ALEN);
275 common->curaid = 0;
276 ath5k_hw_set_bssid(ah);
277 mmiowb();
278 }
279
280 if (changes & BSS_CHANGED_BEACON_INT)
281 sc->bintval = bss_conf->beacon_int;
282
Felix Fietkaub1ad1b62011-04-09 23:10:21 +0200283 if (changes & BSS_CHANGED_ERP_SLOT) {
284 int slot_time;
285
286 ah->ah_short_slot = bss_conf->use_short_slot;
287 slot_time = ath5k_hw_get_default_slottime(ah) +
288 3 * ah->ah_coverage_class;
289 ath5k_hw_set_ifs_intervals(ah, slot_time);
290 }
291
Bruno Randolfcd2c5482010-12-22 19:20:32 +0900292 if (changes & BSS_CHANGED_ASSOC) {
293 avf->assoc = bss_conf->assoc;
294 if (bss_conf->assoc)
295 sc->assoc = bss_conf->assoc;
296 else
Pavel Roskinf5cbc8b2011-06-15 18:03:22 -0400297 sc->assoc = ath5k_any_vif_assoc(sc);
Bruno Randolfcd2c5482010-12-22 19:20:32 +0900298
299 if (sc->opmode == NL80211_IFTYPE_STATION)
Pavel Roskinf5cbc8b2011-06-15 18:03:22 -0400300 ath5k_set_beacon_filter(hw, sc->assoc);
Bruno Randolfcd2c5482010-12-22 19:20:32 +0900301 ath5k_hw_set_ledstate(sc->ah, sc->assoc ?
302 AR5K_LED_ASSOC : AR5K_LED_INIT);
303 if (bss_conf->assoc) {
304 ATH5K_DBG(sc, ATH5K_DEBUG_ANY,
305 "Bss Info ASSOC %d, bssid: %pM\n",
306 bss_conf->aid, common->curbssid);
307 common->curaid = bss_conf->aid;
308 ath5k_hw_set_bssid(ah);
309 /* Once ANI is available you would start it here */
310 }
311 }
312
313 if (changes & BSS_CHANGED_BEACON) {
314 spin_lock_irqsave(&sc->block, flags);
315 ath5k_beacon_update(hw, vif);
316 spin_unlock_irqrestore(&sc->block, flags);
317 }
318
319 if (changes & BSS_CHANGED_BEACON_ENABLED)
320 sc->enable_beacon = bss_conf->enable_beacon;
321
322 if (changes & (BSS_CHANGED_BEACON | BSS_CHANGED_BEACON_ENABLED |
323 BSS_CHANGED_BEACON_INT))
324 ath5k_beacon_config(sc);
325
326 mutex_unlock(&sc->lock);
327}
328
329
330static u64
331ath5k_prepare_multicast(struct ieee80211_hw *hw,
332 struct netdev_hw_addr_list *mc_list)
333{
334 u32 mfilt[2], val;
335 u8 pos;
336 struct netdev_hw_addr *ha;
337
338 mfilt[0] = 0;
339 mfilt[1] = 1;
340
341 netdev_hw_addr_list_for_each(ha, mc_list) {
342 /* calculate XOR of eight 6-bit values */
343 val = get_unaligned_le32(ha->addr + 0);
344 pos = (val >> 18) ^ (val >> 12) ^ (val >> 6) ^ val;
345 val = get_unaligned_le32(ha->addr + 3);
346 pos ^= (val >> 18) ^ (val >> 12) ^ (val >> 6) ^ val;
347 pos &= 0x3f;
348 mfilt[pos / 32] |= (1 << (pos % 32));
349 /* XXX: we might be able to just do this instead,
350 * but not sure, needs testing, if we do use this we'd
351 * neet to inform below to not reset the mcast */
352 /* ath5k_hw_set_mcast_filterindex(ah,
353 * ha->addr[5]); */
354 }
355
356 return ((u64)(mfilt[1]) << 32) | mfilt[0];
357}
358
359
360/*
361 * o always accept unicast, broadcast, and multicast traffic
362 * o multicast traffic for all BSSIDs will be enabled if mac80211
363 * says it should be
364 * o maintain current state of phy ofdm or phy cck error reception.
365 * If the hardware detects any of these type of errors then
366 * ath5k_hw_get_rx_filter() will pass to us the respective
367 * hardware filters to be able to receive these type of frames.
368 * o probe request frames are accepted only when operating in
369 * hostap, adhoc, or monitor modes
370 * o enable promiscuous mode according to the interface state
371 * o accept beacons:
372 * - when operating in adhoc mode so the 802.11 layer creates
373 * node table entries for peers,
374 * - when operating in station mode for collecting rssi data when
375 * the station is otherwise quiet, or
376 * - when scanning
377 */
378static void
379ath5k_configure_filter(struct ieee80211_hw *hw, unsigned int changed_flags,
380 unsigned int *new_flags, u64 multicast)
381{
382#define SUPPORTED_FIF_FLAGS \
383 (FIF_PROMISC_IN_BSS | FIF_ALLMULTI | FIF_FCSFAIL | \
384 FIF_PLCPFAIL | FIF_CONTROL | FIF_OTHER_BSS | \
385 FIF_BCN_PRBRESP_PROMISC)
386
387 struct ath5k_softc *sc = hw->priv;
388 struct ath5k_hw *ah = sc->ah;
389 u32 mfilt[2], rfilt;
Ben Greeare4b0b322011-03-03 14:39:05 -0800390 struct ath5k_vif_iter_data iter_data; /* to count STA interfaces */
Bruno Randolfcd2c5482010-12-22 19:20:32 +0900391
392 mutex_lock(&sc->lock);
393
394 mfilt[0] = multicast;
395 mfilt[1] = multicast >> 32;
396
397 /* Only deal with supported flags */
398 changed_flags &= SUPPORTED_FIF_FLAGS;
399 *new_flags &= SUPPORTED_FIF_FLAGS;
400
401 /* If HW detects any phy or radar errors, leave those filters on.
402 * Also, always enable Unicast, Broadcasts and Multicast
403 * XXX: move unicast, bssid broadcasts and multicast to mac80211 */
404 rfilt = (ath5k_hw_get_rx_filter(ah) & (AR5K_RX_FILTER_PHYERR)) |
405 (AR5K_RX_FILTER_UCAST | AR5K_RX_FILTER_BCAST |
406 AR5K_RX_FILTER_MCAST);
407
408 if (changed_flags & (FIF_PROMISC_IN_BSS | FIF_OTHER_BSS)) {
409 if (*new_flags & FIF_PROMISC_IN_BSS)
410 __set_bit(ATH_STAT_PROMISC, sc->status);
411 else
412 __clear_bit(ATH_STAT_PROMISC, sc->status);
413 }
414
415 if (test_bit(ATH_STAT_PROMISC, sc->status))
416 rfilt |= AR5K_RX_FILTER_PROM;
417
418 /* Note, AR5K_RX_FILTER_MCAST is already enabled */
419 if (*new_flags & FIF_ALLMULTI) {
420 mfilt[0] = ~0;
421 mfilt[1] = ~0;
422 }
423
424 /* This is the best we can do */
425 if (*new_flags & (FIF_FCSFAIL | FIF_PLCPFAIL))
426 rfilt |= AR5K_RX_FILTER_PHYERR;
427
428 /* FIF_BCN_PRBRESP_PROMISC really means to enable beacons
429 * and probes for any BSSID */
430 if ((*new_flags & FIF_BCN_PRBRESP_PROMISC) || (sc->nvifs > 1))
431 rfilt |= AR5K_RX_FILTER_BEACON;
432
433 /* FIF_CONTROL doc says that if FIF_PROMISC_IN_BSS is not
434 * set we should only pass on control frames for this
435 * station. This needs testing. I believe right now this
436 * enables *all* control frames, which is OK.. but
437 * but we should see if we can improve on granularity */
438 if (*new_flags & FIF_CONTROL)
439 rfilt |= AR5K_RX_FILTER_CONTROL;
440
441 /* Additional settings per mode -- this is per ath5k */
442
443 /* XXX move these to mac80211, and add a beacon IFF flag to mac80211 */
444
445 switch (sc->opmode) {
446 case NL80211_IFTYPE_MESH_POINT:
447 rfilt |= AR5K_RX_FILTER_CONTROL |
448 AR5K_RX_FILTER_BEACON |
449 AR5K_RX_FILTER_PROBEREQ |
450 AR5K_RX_FILTER_PROM;
451 break;
452 case NL80211_IFTYPE_AP:
453 case NL80211_IFTYPE_ADHOC:
454 rfilt |= AR5K_RX_FILTER_PROBEREQ |
455 AR5K_RX_FILTER_BEACON;
456 break;
457 case NL80211_IFTYPE_STATION:
458 if (sc->assoc)
459 rfilt |= AR5K_RX_FILTER_BEACON;
460 default:
461 break;
462 }
463
Ben Greeare4b0b322011-03-03 14:39:05 -0800464 iter_data.hw_macaddr = NULL;
465 iter_data.n_stas = 0;
466 iter_data.need_set_hw_addr = false;
467 ieee80211_iterate_active_interfaces_atomic(sc->hw, ath5k_vif_iter,
468 &iter_data);
469
470 /* Set up RX Filter */
471 if (iter_data.n_stas > 1) {
472 /* If you have multiple STA interfaces connected to
473 * different APs, ARPs are not received (most of the time?)
474 * Enabling PROMISC appears to fix that probem.
475 */
476 rfilt |= AR5K_RX_FILTER_PROM;
477 }
478
Bruno Randolfcd2c5482010-12-22 19:20:32 +0900479 /* Set filters */
480 ath5k_hw_set_rx_filter(ah, rfilt);
481
482 /* Set multicast bits */
483 ath5k_hw_set_mcast_filter(ah, mfilt[0], mfilt[1]);
484 /* Set the cached hw filter flags, this will later actually
485 * be set in HW */
486 sc->filter_flags = rfilt;
487
488 mutex_unlock(&sc->lock);
489}
490
491
492static int
493ath5k_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
494 struct ieee80211_vif *vif, struct ieee80211_sta *sta,
495 struct ieee80211_key_conf *key)
496{
497 struct ath5k_softc *sc = hw->priv;
498 struct ath5k_hw *ah = sc->ah;
499 struct ath_common *common = ath5k_hw_common(ah);
500 int ret = 0;
501
John W. Linville18cb6e32011-01-05 09:39:59 -0500502 if (ath5k_modparam_nohwcrypt)
Bruno Randolfcd2c5482010-12-22 19:20:32 +0900503 return -EOPNOTSUPP;
504
505 switch (key->cipher) {
506 case WLAN_CIPHER_SUITE_WEP40:
507 case WLAN_CIPHER_SUITE_WEP104:
508 case WLAN_CIPHER_SUITE_TKIP:
509 break;
510 case WLAN_CIPHER_SUITE_CCMP:
511 if (common->crypt_caps & ATH_CRYPT_CAP_CIPHER_AESCCM)
512 break;
513 return -EOPNOTSUPP;
514 default:
515 WARN_ON(1);
516 return -EINVAL;
517 }
518
519 mutex_lock(&sc->lock);
520
521 switch (cmd) {
522 case SET_KEY:
523 ret = ath_key_config(common, vif, sta, key);
524 if (ret >= 0) {
525 key->hw_key_idx = ret;
526 /* push IV and Michael MIC generation to stack */
527 key->flags |= IEEE80211_KEY_FLAG_GENERATE_IV;
528 if (key->cipher == WLAN_CIPHER_SUITE_TKIP)
529 key->flags |= IEEE80211_KEY_FLAG_GENERATE_MMIC;
530 if (key->cipher == WLAN_CIPHER_SUITE_CCMP)
531 key->flags |= IEEE80211_KEY_FLAG_SW_MGMT;
532 ret = 0;
533 }
534 break;
535 case DISABLE_KEY:
536 ath_key_delete(common, key);
537 break;
538 default:
539 ret = -EINVAL;
540 }
541
542 mmiowb();
543 mutex_unlock(&sc->lock);
544 return ret;
545}
546
547
548static void
549ath5k_sw_scan_start(struct ieee80211_hw *hw)
550{
551 struct ath5k_softc *sc = hw->priv;
552 if (!sc->assoc)
553 ath5k_hw_set_ledstate(sc->ah, AR5K_LED_SCAN);
554}
555
556
557static void
558ath5k_sw_scan_complete(struct ieee80211_hw *hw)
559{
560 struct ath5k_softc *sc = hw->priv;
561 ath5k_hw_set_ledstate(sc->ah, sc->assoc ?
562 AR5K_LED_ASSOC : AR5K_LED_INIT);
563}
564
565
566static int
567ath5k_get_stats(struct ieee80211_hw *hw,
568 struct ieee80211_low_level_stats *stats)
569{
570 struct ath5k_softc *sc = hw->priv;
571
572 /* Force update */
573 ath5k_hw_update_mib_counters(sc->ah);
574
575 stats->dot11ACKFailureCount = sc->stats.ack_fail;
576 stats->dot11RTSFailureCount = sc->stats.rts_fail;
577 stats->dot11RTSSuccessCount = sc->stats.rts_ok;
578 stats->dot11FCSErrorCount = sc->stats.fcs_error;
579
580 return 0;
581}
582
583
584static int
585ath5k_conf_tx(struct ieee80211_hw *hw, u16 queue,
586 const struct ieee80211_tx_queue_params *params)
587{
588 struct ath5k_softc *sc = hw->priv;
589 struct ath5k_hw *ah = sc->ah;
590 struct ath5k_txq_info qi;
591 int ret = 0;
592
593 if (queue >= ah->ah_capabilities.cap_queues.q_tx_num)
594 return 0;
595
596 mutex_lock(&sc->lock);
597
598 ath5k_hw_get_tx_queueprops(ah, queue, &qi);
599
600 qi.tqi_aifs = params->aifs;
601 qi.tqi_cw_min = params->cw_min;
602 qi.tqi_cw_max = params->cw_max;
603 qi.tqi_burst_time = params->txop;
604
605 ATH5K_DBG(sc, ATH5K_DEBUG_ANY,
606 "Configure tx [queue %d], "
607 "aifs: %d, cw_min: %d, cw_max: %d, txop: %d\n",
608 queue, params->aifs, params->cw_min,
609 params->cw_max, params->txop);
610
611 if (ath5k_hw_set_tx_queueprops(ah, queue, &qi)) {
612 ATH5K_ERR(sc,
613 "Unable to update hardware queue %u!\n", queue);
614 ret = -EIO;
615 } else
616 ath5k_hw_reset_tx_queue(ah, queue);
617
618 mutex_unlock(&sc->lock);
619
620 return ret;
621}
622
623
624static u64
625ath5k_get_tsf(struct ieee80211_hw *hw)
626{
627 struct ath5k_softc *sc = hw->priv;
628
629 return ath5k_hw_get_tsf64(sc->ah);
630}
631
632
633static void
634ath5k_set_tsf(struct ieee80211_hw *hw, u64 tsf)
635{
636 struct ath5k_softc *sc = hw->priv;
637
638 ath5k_hw_set_tsf64(sc->ah, tsf);
639}
640
641
642static void
643ath5k_reset_tsf(struct ieee80211_hw *hw)
644{
645 struct ath5k_softc *sc = hw->priv;
646
647 /*
648 * in IBSS mode we need to update the beacon timers too.
649 * this will also reset the TSF if we call it with 0
650 */
651 if (sc->opmode == NL80211_IFTYPE_ADHOC)
652 ath5k_beacon_update_timers(sc, 0);
653 else
654 ath5k_hw_reset_tsf(sc->ah);
655}
656
657
658static int
659ath5k_get_survey(struct ieee80211_hw *hw, int idx, struct survey_info *survey)
660{
661 struct ath5k_softc *sc = hw->priv;
662 struct ieee80211_conf *conf = &hw->conf;
663 struct ath_common *common = ath5k_hw_common(sc->ah);
664 struct ath_cycle_counters *cc = &common->cc_survey;
665 unsigned int div = common->clockrate * 1000;
666
667 if (idx != 0)
668 return -ENOENT;
669
670 spin_lock_bh(&common->cc_lock);
671 ath_hw_cycle_counters_update(common);
672 if (cc->cycles > 0) {
673 sc->survey.channel_time += cc->cycles / div;
674 sc->survey.channel_time_busy += cc->rx_busy / div;
675 sc->survey.channel_time_rx += cc->rx_frame / div;
676 sc->survey.channel_time_tx += cc->tx_frame / div;
677 }
678 memset(cc, 0, sizeof(*cc));
679 spin_unlock_bh(&common->cc_lock);
680
681 memcpy(survey, &sc->survey, sizeof(*survey));
682
683 survey->channel = conf->channel;
684 survey->noise = sc->ah->ah_noise_floor;
685 survey->filled = SURVEY_INFO_NOISE_DBM |
686 SURVEY_INFO_CHANNEL_TIME |
687 SURVEY_INFO_CHANNEL_TIME_BUSY |
688 SURVEY_INFO_CHANNEL_TIME_RX |
689 SURVEY_INFO_CHANNEL_TIME_TX;
690
691 return 0;
692}
693
694
695/**
696 * ath5k_set_coverage_class - Set IEEE 802.11 coverage class
697 *
698 * @hw: struct ieee80211_hw pointer
699 * @coverage_class: IEEE 802.11 coverage class number
700 *
701 * Mac80211 callback. Sets slot time, ACK timeout and CTS timeout for given
702 * coverage class. The values are persistent, they are restored after device
703 * reset.
704 */
705static void
706ath5k_set_coverage_class(struct ieee80211_hw *hw, u8 coverage_class)
707{
708 struct ath5k_softc *sc = hw->priv;
709
710 mutex_lock(&sc->lock);
711 ath5k_hw_set_coverage_class(sc->ah, coverage_class);
712 mutex_unlock(&sc->lock);
713}
714
715
716static int
717ath5k_set_antenna(struct ieee80211_hw *hw, u32 tx_ant, u32 rx_ant)
718{
719 struct ath5k_softc *sc = hw->priv;
720
721 if (tx_ant == 1 && rx_ant == 1)
722 ath5k_hw_set_antenna_mode(sc->ah, AR5K_ANTMODE_FIXED_A);
723 else if (tx_ant == 2 && rx_ant == 2)
724 ath5k_hw_set_antenna_mode(sc->ah, AR5K_ANTMODE_FIXED_B);
725 else if ((tx_ant & 3) == 3 && (rx_ant & 3) == 3)
726 ath5k_hw_set_antenna_mode(sc->ah, AR5K_ANTMODE_DEFAULT);
727 else
728 return -EINVAL;
729 return 0;
730}
731
732
733static int
734ath5k_get_antenna(struct ieee80211_hw *hw, u32 *tx_ant, u32 *rx_ant)
735{
736 struct ath5k_softc *sc = hw->priv;
737
738 switch (sc->ah->ah_ant_mode) {
739 case AR5K_ANTMODE_FIXED_A:
740 *tx_ant = 1; *rx_ant = 1; break;
741 case AR5K_ANTMODE_FIXED_B:
742 *tx_ant = 2; *rx_ant = 2; break;
743 case AR5K_ANTMODE_DEFAULT:
744 *tx_ant = 3; *rx_ant = 3; break;
745 }
746 return 0;
747}
748
749
John W. Linville81266ba2011-03-07 16:32:59 -0500750static void ath5k_get_ringparam(struct ieee80211_hw *hw,
751 u32 *tx, u32 *tx_max, u32 *rx, u32 *rx_max)
752{
753 struct ath5k_softc *sc = hw->priv;
754
755 *tx = sc->txqs[AR5K_TX_QUEUE_ID_DATA_MIN].txq_max;
756
757 *tx_max = ATH5K_TXQ_LEN_MAX;
758 *rx = *rx_max = ATH_RXBUF;
759}
760
761
762static int ath5k_set_ringparam(struct ieee80211_hw *hw, u32 tx, u32 rx)
763{
764 struct ath5k_softc *sc = hw->priv;
765 u16 qnum;
766
767 /* only support setting tx ring size for now */
768 if (rx != ATH_RXBUF)
769 return -EINVAL;
770
771 /* restrict tx ring size min/max */
772 if (!tx || tx > ATH5K_TXQ_LEN_MAX)
773 return -EINVAL;
774
775 for (qnum = 0; qnum < ARRAY_SIZE(sc->txqs); qnum++) {
776 if (!sc->txqs[qnum].setup)
777 continue;
778 if (sc->txqs[qnum].qnum < AR5K_TX_QUEUE_ID_DATA_MIN ||
779 sc->txqs[qnum].qnum > AR5K_TX_QUEUE_ID_DATA_MAX)
780 continue;
781
782 sc->txqs[qnum].txq_max = tx;
783 if (sc->txqs[qnum].txq_len >= sc->txqs[qnum].txq_max)
784 ieee80211_stop_queue(hw, sc->txqs[qnum].qnum);
785 }
786
787 return 0;
788}
789
790
Bruno Randolfcd2c5482010-12-22 19:20:32 +0900791const struct ieee80211_ops ath5k_hw_ops = {
792 .tx = ath5k_tx,
793 .start = ath5k_start,
794 .stop = ath5k_stop,
795 .add_interface = ath5k_add_interface,
796 /* .change_interface = not implemented */
797 .remove_interface = ath5k_remove_interface,
798 .config = ath5k_config,
799 .bss_info_changed = ath5k_bss_info_changed,
800 .prepare_multicast = ath5k_prepare_multicast,
801 .configure_filter = ath5k_configure_filter,
802 /* .set_tim = not implemented */
803 .set_key = ath5k_set_key,
804 /* .update_tkip_key = not implemented */
805 /* .hw_scan = not implemented */
806 .sw_scan_start = ath5k_sw_scan_start,
807 .sw_scan_complete = ath5k_sw_scan_complete,
808 .get_stats = ath5k_get_stats,
809 /* .get_tkip_seq = not implemented */
810 /* .set_frag_threshold = not implemented */
811 /* .set_rts_threshold = not implemented */
812 /* .sta_add = not implemented */
813 /* .sta_remove = not implemented */
814 /* .sta_notify = not implemented */
815 .conf_tx = ath5k_conf_tx,
816 .get_tsf = ath5k_get_tsf,
817 .set_tsf = ath5k_set_tsf,
818 .reset_tsf = ath5k_reset_tsf,
819 /* .tx_last_beacon = not implemented */
820 /* .ampdu_action = not needed */
821 .get_survey = ath5k_get_survey,
822 .set_coverage_class = ath5k_set_coverage_class,
823 /* .rfkill_poll = not implemented */
824 /* .flush = not implemented */
825 /* .channel_switch = not implemented */
826 /* .napi_poll = not implemented */
827 .set_antenna = ath5k_set_antenna,
828 .get_antenna = ath5k_get_antenna,
John W. Linville81266ba2011-03-07 16:32:59 -0500829 .set_ringparam = ath5k_set_ringparam,
830 .get_ringparam = ath5k_get_ringparam,
Bruno Randolfcd2c5482010-12-22 19:20:32 +0900831};