blob: c9b0b676adda2d19c61118dd7628f0c7df782650 [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
John W. Linville18cb6e32011-01-05 09:39:59 -050049extern int ath5k_modparam_nohwcrypt;
Bruno Randolfcd2c5482010-12-22 19:20:32 +090050
Bruno Randolfcd2c5482010-12-22 19:20:32 +090051/********************\
52* Mac80211 functions *
53\********************/
54
Johannes Berg7bb45682011-02-24 14:42:06 +010055static void
Bruno Randolfcd2c5482010-12-22 19:20:32 +090056ath5k_tx(struct ieee80211_hw *hw, struct sk_buff *skb)
57{
58 struct ath5k_softc *sc = hw->priv;
59 u16 qnum = skb_get_queue_mapping(skb);
60
61 if (WARN_ON(qnum >= sc->ah->ah_capabilities.cap_queues.q_tx_num)) {
62 dev_kfree_skb_any(skb);
Johannes Berg7bb45682011-02-24 14:42:06 +010063 return;
Bruno Randolfcd2c5482010-12-22 19:20:32 +090064 }
65
Johannes Berg7bb45682011-02-24 14:42:06 +010066 ath5k_tx_queue(hw, skb, &sc->txqs[qnum]);
Bruno Randolfcd2c5482010-12-22 19:20:32 +090067}
68
69
70static int
71ath5k_start(struct ieee80211_hw *hw)
72{
73 return ath5k_init_hw(hw->priv);
74}
75
76
77static void
78ath5k_stop(struct ieee80211_hw *hw)
79{
80 ath5k_stop_hw(hw->priv);
81}
82
83
84static int
85ath5k_add_interface(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
86{
87 struct ath5k_softc *sc = hw->priv;
88 int ret;
89 struct ath5k_vif *avf = (void *)vif->drv_priv;
90
91 mutex_lock(&sc->lock);
92
93 if ((vif->type == NL80211_IFTYPE_AP ||
94 vif->type == NL80211_IFTYPE_ADHOC)
95 && (sc->num_ap_vifs + sc->num_adhoc_vifs) >= ATH_BCBUF) {
96 ret = -ELNRNG;
97 goto end;
98 }
99
100 /* Don't allow other interfaces if one ad-hoc is configured.
101 * TODO: Fix the problems with ad-hoc and multiple other interfaces.
102 * We would need to operate the HW in ad-hoc mode to allow TSF updates
103 * for the IBSS, but this breaks with additional AP or STA interfaces
104 * at the moment. */
105 if (sc->num_adhoc_vifs ||
106 (sc->nvifs && vif->type == NL80211_IFTYPE_ADHOC)) {
107 ATH5K_ERR(sc, "Only one single ad-hoc interface is allowed.\n");
108 ret = -ELNRNG;
109 goto end;
110 }
111
112 switch (vif->type) {
113 case NL80211_IFTYPE_AP:
114 case NL80211_IFTYPE_STATION:
115 case NL80211_IFTYPE_ADHOC:
116 case NL80211_IFTYPE_MESH_POINT:
117 avf->opmode = vif->type;
118 break;
119 default:
120 ret = -EOPNOTSUPP;
121 goto end;
122 }
123
124 sc->nvifs++;
125 ATH5K_DBG(sc, ATH5K_DEBUG_MODE, "add interface mode %d\n", avf->opmode);
126
127 /* Assign the vap/adhoc to a beacon xmit slot. */
128 if ((avf->opmode == NL80211_IFTYPE_AP) ||
129 (avf->opmode == NL80211_IFTYPE_ADHOC) ||
130 (avf->opmode == NL80211_IFTYPE_MESH_POINT)) {
131 int slot;
132
133 WARN_ON(list_empty(&sc->bcbuf));
134 avf->bbuf = list_first_entry(&sc->bcbuf, struct ath5k_buf,
135 list);
136 list_del(&avf->bbuf->list);
137
138 avf->bslot = 0;
139 for (slot = 0; slot < ATH_BCBUF; slot++) {
140 if (!sc->bslot[slot]) {
141 avf->bslot = slot;
142 break;
143 }
144 }
145 BUG_ON(sc->bslot[avf->bslot] != NULL);
146 sc->bslot[avf->bslot] = vif;
147 if (avf->opmode == NL80211_IFTYPE_AP)
148 sc->num_ap_vifs++;
149 else if (avf->opmode == NL80211_IFTYPE_ADHOC)
150 sc->num_adhoc_vifs++;
151 }
152
153 /* Any MAC address is fine, all others are included through the
154 * filter.
155 */
156 memcpy(&sc->lladdr, vif->addr, ETH_ALEN);
157 ath5k_hw_set_lladdr(sc->ah, vif->addr);
158
159 memcpy(&avf->lladdr, vif->addr, ETH_ALEN);
160
Ben Greeare4b0b322011-03-03 14:39:05 -0800161 ath5k_update_bssid_mask_and_opmode(sc, vif);
Bruno Randolfcd2c5482010-12-22 19:20:32 +0900162 ret = 0;
163end:
164 mutex_unlock(&sc->lock);
165 return ret;
166}
167
168
169static void
170ath5k_remove_interface(struct ieee80211_hw *hw,
171 struct ieee80211_vif *vif)
172{
173 struct ath5k_softc *sc = hw->priv;
174 struct ath5k_vif *avf = (void *)vif->drv_priv;
175 unsigned int i;
176
177 mutex_lock(&sc->lock);
178 sc->nvifs--;
179
180 if (avf->bbuf) {
181 ath5k_txbuf_free_skb(sc, avf->bbuf);
182 list_add_tail(&avf->bbuf->list, &sc->bcbuf);
183 for (i = 0; i < ATH_BCBUF; i++) {
184 if (sc->bslot[i] == vif) {
185 sc->bslot[i] = NULL;
186 break;
187 }
188 }
189 avf->bbuf = NULL;
190 }
191 if (avf->opmode == NL80211_IFTYPE_AP)
192 sc->num_ap_vifs--;
193 else if (avf->opmode == NL80211_IFTYPE_ADHOC)
194 sc->num_adhoc_vifs--;
195
196 ath5k_update_bssid_mask_and_opmode(sc, NULL);
197 mutex_unlock(&sc->lock);
198}
199
200
201/*
202 * TODO: Phy disable/diversity etc
203 */
204static int
205ath5k_config(struct ieee80211_hw *hw, u32 changed)
206{
207 struct ath5k_softc *sc = hw->priv;
208 struct ath5k_hw *ah = sc->ah;
209 struct ieee80211_conf *conf = &hw->conf;
210 int ret = 0;
Bruno Randolf76a9f6f2011-01-28 16:52:11 +0900211 int i;
Bruno Randolfcd2c5482010-12-22 19:20:32 +0900212
213 mutex_lock(&sc->lock);
214
215 if (changed & IEEE80211_CONF_CHANGE_CHANNEL) {
216 ret = ath5k_chan_set(sc, conf->channel);
217 if (ret < 0)
218 goto unlock;
219 }
220
221 if ((changed & IEEE80211_CONF_CHANGE_POWER) &&
222 (sc->power_level != conf->power_level)) {
223 sc->power_level = conf->power_level;
224
225 /* Half dB steps */
226 ath5k_hw_set_txpower_limit(ah, (conf->power_level * 2));
227 }
228
Bruno Randolf76a9f6f2011-01-28 16:52:11 +0900229 if (changed & IEEE80211_CONF_CHANGE_RETRY_LIMITS) {
230 ah->ah_retry_long = conf->long_frame_max_tx_count;
231 ah->ah_retry_short = conf->short_frame_max_tx_count;
232
233 for (i = 0; i < ah->ah_capabilities.cap_queues.q_tx_num; i++)
234 ath5k_hw_set_tx_retry_limits(ah, i);
235 }
236
Bruno Randolfcd2c5482010-12-22 19:20:32 +0900237 /* TODO:
238 * 1) Move this on config_interface and handle each case
239 * separately eg. when we have only one STA vif, use
240 * AR5K_ANTMODE_SINGLE_AP
241 *
242 * 2) Allow the user to change antenna mode eg. when only
243 * one antenna is present
244 *
245 * 3) Allow the user to set default/tx antenna when possible
246 *
247 * 4) Default mode should handle 90% of the cases, together
248 * with fixed a/b and single AP modes we should be able to
249 * handle 99%. Sectored modes are extreme cases and i still
250 * haven't found a usage for them. If we decide to support them,
251 * then we must allow the user to set how many tx antennas we
252 * have available
253 */
254 ath5k_hw_set_antenna_mode(ah, ah->ah_ant_mode);
255
256unlock:
257 mutex_unlock(&sc->lock);
258 return ret;
259}
260
261
262static void
263ath5k_bss_info_changed(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
264 struct ieee80211_bss_conf *bss_conf, u32 changes)
265{
266 struct ath5k_vif *avf = (void *)vif->drv_priv;
267 struct ath5k_softc *sc = hw->priv;
268 struct ath5k_hw *ah = sc->ah;
269 struct ath_common *common = ath5k_hw_common(ah);
270 unsigned long flags;
271
272 mutex_lock(&sc->lock);
273
274 if (changes & BSS_CHANGED_BSSID) {
275 /* Cache for later use during resets */
276 memcpy(common->curbssid, bss_conf->bssid, ETH_ALEN);
277 common->curaid = 0;
278 ath5k_hw_set_bssid(ah);
279 mmiowb();
280 }
281
282 if (changes & BSS_CHANGED_BEACON_INT)
283 sc->bintval = bss_conf->beacon_int;
284
285 if (changes & BSS_CHANGED_ASSOC) {
286 avf->assoc = bss_conf->assoc;
287 if (bss_conf->assoc)
288 sc->assoc = bss_conf->assoc;
289 else
290 sc->assoc = ath_any_vif_assoc(sc);
291
292 if (sc->opmode == NL80211_IFTYPE_STATION)
293 set_beacon_filter(hw, sc->assoc);
294 ath5k_hw_set_ledstate(sc->ah, sc->assoc ?
295 AR5K_LED_ASSOC : AR5K_LED_INIT);
296 if (bss_conf->assoc) {
297 ATH5K_DBG(sc, ATH5K_DEBUG_ANY,
298 "Bss Info ASSOC %d, bssid: %pM\n",
299 bss_conf->aid, common->curbssid);
300 common->curaid = bss_conf->aid;
301 ath5k_hw_set_bssid(ah);
302 /* Once ANI is available you would start it here */
303 }
304 }
305
306 if (changes & BSS_CHANGED_BEACON) {
307 spin_lock_irqsave(&sc->block, flags);
308 ath5k_beacon_update(hw, vif);
309 spin_unlock_irqrestore(&sc->block, flags);
310 }
311
312 if (changes & BSS_CHANGED_BEACON_ENABLED)
313 sc->enable_beacon = bss_conf->enable_beacon;
314
315 if (changes & (BSS_CHANGED_BEACON | BSS_CHANGED_BEACON_ENABLED |
316 BSS_CHANGED_BEACON_INT))
317 ath5k_beacon_config(sc);
318
319 mutex_unlock(&sc->lock);
320}
321
322
323static u64
324ath5k_prepare_multicast(struct ieee80211_hw *hw,
325 struct netdev_hw_addr_list *mc_list)
326{
327 u32 mfilt[2], val;
328 u8 pos;
329 struct netdev_hw_addr *ha;
330
331 mfilt[0] = 0;
332 mfilt[1] = 1;
333
334 netdev_hw_addr_list_for_each(ha, mc_list) {
335 /* calculate XOR of eight 6-bit values */
336 val = get_unaligned_le32(ha->addr + 0);
337 pos = (val >> 18) ^ (val >> 12) ^ (val >> 6) ^ val;
338 val = get_unaligned_le32(ha->addr + 3);
339 pos ^= (val >> 18) ^ (val >> 12) ^ (val >> 6) ^ val;
340 pos &= 0x3f;
341 mfilt[pos / 32] |= (1 << (pos % 32));
342 /* XXX: we might be able to just do this instead,
343 * but not sure, needs testing, if we do use this we'd
344 * neet to inform below to not reset the mcast */
345 /* ath5k_hw_set_mcast_filterindex(ah,
346 * ha->addr[5]); */
347 }
348
349 return ((u64)(mfilt[1]) << 32) | mfilt[0];
350}
351
352
353/*
354 * o always accept unicast, broadcast, and multicast traffic
355 * o multicast traffic for all BSSIDs will be enabled if mac80211
356 * says it should be
357 * o maintain current state of phy ofdm or phy cck error reception.
358 * If the hardware detects any of these type of errors then
359 * ath5k_hw_get_rx_filter() will pass to us the respective
360 * hardware filters to be able to receive these type of frames.
361 * o probe request frames are accepted only when operating in
362 * hostap, adhoc, or monitor modes
363 * o enable promiscuous mode according to the interface state
364 * o accept beacons:
365 * - when operating in adhoc mode so the 802.11 layer creates
366 * node table entries for peers,
367 * - when operating in station mode for collecting rssi data when
368 * the station is otherwise quiet, or
369 * - when scanning
370 */
371static void
372ath5k_configure_filter(struct ieee80211_hw *hw, unsigned int changed_flags,
373 unsigned int *new_flags, u64 multicast)
374{
375#define SUPPORTED_FIF_FLAGS \
376 (FIF_PROMISC_IN_BSS | FIF_ALLMULTI | FIF_FCSFAIL | \
377 FIF_PLCPFAIL | FIF_CONTROL | FIF_OTHER_BSS | \
378 FIF_BCN_PRBRESP_PROMISC)
379
380 struct ath5k_softc *sc = hw->priv;
381 struct ath5k_hw *ah = sc->ah;
382 u32 mfilt[2], rfilt;
Ben Greeare4b0b322011-03-03 14:39:05 -0800383 struct ath5k_vif_iter_data iter_data; /* to count STA interfaces */
Bruno Randolfcd2c5482010-12-22 19:20:32 +0900384
385 mutex_lock(&sc->lock);
386
387 mfilt[0] = multicast;
388 mfilt[1] = multicast >> 32;
389
390 /* Only deal with supported flags */
391 changed_flags &= SUPPORTED_FIF_FLAGS;
392 *new_flags &= SUPPORTED_FIF_FLAGS;
393
394 /* If HW detects any phy or radar errors, leave those filters on.
395 * Also, always enable Unicast, Broadcasts and Multicast
396 * XXX: move unicast, bssid broadcasts and multicast to mac80211 */
397 rfilt = (ath5k_hw_get_rx_filter(ah) & (AR5K_RX_FILTER_PHYERR)) |
398 (AR5K_RX_FILTER_UCAST | AR5K_RX_FILTER_BCAST |
399 AR5K_RX_FILTER_MCAST);
400
401 if (changed_flags & (FIF_PROMISC_IN_BSS | FIF_OTHER_BSS)) {
402 if (*new_flags & FIF_PROMISC_IN_BSS)
403 __set_bit(ATH_STAT_PROMISC, sc->status);
404 else
405 __clear_bit(ATH_STAT_PROMISC, sc->status);
406 }
407
408 if (test_bit(ATH_STAT_PROMISC, sc->status))
409 rfilt |= AR5K_RX_FILTER_PROM;
410
411 /* Note, AR5K_RX_FILTER_MCAST is already enabled */
412 if (*new_flags & FIF_ALLMULTI) {
413 mfilt[0] = ~0;
414 mfilt[1] = ~0;
415 }
416
417 /* This is the best we can do */
418 if (*new_flags & (FIF_FCSFAIL | FIF_PLCPFAIL))
419 rfilt |= AR5K_RX_FILTER_PHYERR;
420
421 /* FIF_BCN_PRBRESP_PROMISC really means to enable beacons
422 * and probes for any BSSID */
423 if ((*new_flags & FIF_BCN_PRBRESP_PROMISC) || (sc->nvifs > 1))
424 rfilt |= AR5K_RX_FILTER_BEACON;
425
426 /* FIF_CONTROL doc says that if FIF_PROMISC_IN_BSS is not
427 * set we should only pass on control frames for this
428 * station. This needs testing. I believe right now this
429 * enables *all* control frames, which is OK.. but
430 * but we should see if we can improve on granularity */
431 if (*new_flags & FIF_CONTROL)
432 rfilt |= AR5K_RX_FILTER_CONTROL;
433
434 /* Additional settings per mode -- this is per ath5k */
435
436 /* XXX move these to mac80211, and add a beacon IFF flag to mac80211 */
437
438 switch (sc->opmode) {
439 case NL80211_IFTYPE_MESH_POINT:
440 rfilt |= AR5K_RX_FILTER_CONTROL |
441 AR5K_RX_FILTER_BEACON |
442 AR5K_RX_FILTER_PROBEREQ |
443 AR5K_RX_FILTER_PROM;
444 break;
445 case NL80211_IFTYPE_AP:
446 case NL80211_IFTYPE_ADHOC:
447 rfilt |= AR5K_RX_FILTER_PROBEREQ |
448 AR5K_RX_FILTER_BEACON;
449 break;
450 case NL80211_IFTYPE_STATION:
451 if (sc->assoc)
452 rfilt |= AR5K_RX_FILTER_BEACON;
453 default:
454 break;
455 }
456
Ben Greeare4b0b322011-03-03 14:39:05 -0800457 iter_data.hw_macaddr = NULL;
458 iter_data.n_stas = 0;
459 iter_data.need_set_hw_addr = false;
460 ieee80211_iterate_active_interfaces_atomic(sc->hw, ath5k_vif_iter,
461 &iter_data);
462
463 /* Set up RX Filter */
464 if (iter_data.n_stas > 1) {
465 /* If you have multiple STA interfaces connected to
466 * different APs, ARPs are not received (most of the time?)
467 * Enabling PROMISC appears to fix that probem.
468 */
469 rfilt |= AR5K_RX_FILTER_PROM;
470 }
471
Bruno Randolfcd2c5482010-12-22 19:20:32 +0900472 /* Set filters */
473 ath5k_hw_set_rx_filter(ah, rfilt);
474
475 /* Set multicast bits */
476 ath5k_hw_set_mcast_filter(ah, mfilt[0], mfilt[1]);
477 /* Set the cached hw filter flags, this will later actually
478 * be set in HW */
479 sc->filter_flags = rfilt;
480
481 mutex_unlock(&sc->lock);
482}
483
484
485static int
486ath5k_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
487 struct ieee80211_vif *vif, struct ieee80211_sta *sta,
488 struct ieee80211_key_conf *key)
489{
490 struct ath5k_softc *sc = hw->priv;
491 struct ath5k_hw *ah = sc->ah;
492 struct ath_common *common = ath5k_hw_common(ah);
493 int ret = 0;
494
John W. Linville18cb6e32011-01-05 09:39:59 -0500495 if (ath5k_modparam_nohwcrypt)
Bruno Randolfcd2c5482010-12-22 19:20:32 +0900496 return -EOPNOTSUPP;
497
498 switch (key->cipher) {
499 case WLAN_CIPHER_SUITE_WEP40:
500 case WLAN_CIPHER_SUITE_WEP104:
501 case WLAN_CIPHER_SUITE_TKIP:
502 break;
503 case WLAN_CIPHER_SUITE_CCMP:
504 if (common->crypt_caps & ATH_CRYPT_CAP_CIPHER_AESCCM)
505 break;
506 return -EOPNOTSUPP;
507 default:
508 WARN_ON(1);
509 return -EINVAL;
510 }
511
512 mutex_lock(&sc->lock);
513
514 switch (cmd) {
515 case SET_KEY:
516 ret = ath_key_config(common, vif, sta, key);
517 if (ret >= 0) {
518 key->hw_key_idx = ret;
519 /* push IV and Michael MIC generation to stack */
520 key->flags |= IEEE80211_KEY_FLAG_GENERATE_IV;
521 if (key->cipher == WLAN_CIPHER_SUITE_TKIP)
522 key->flags |= IEEE80211_KEY_FLAG_GENERATE_MMIC;
523 if (key->cipher == WLAN_CIPHER_SUITE_CCMP)
524 key->flags |= IEEE80211_KEY_FLAG_SW_MGMT;
525 ret = 0;
526 }
527 break;
528 case DISABLE_KEY:
529 ath_key_delete(common, key);
530 break;
531 default:
532 ret = -EINVAL;
533 }
534
535 mmiowb();
536 mutex_unlock(&sc->lock);
537 return ret;
538}
539
540
541static void
542ath5k_sw_scan_start(struct ieee80211_hw *hw)
543{
544 struct ath5k_softc *sc = hw->priv;
545 if (!sc->assoc)
546 ath5k_hw_set_ledstate(sc->ah, AR5K_LED_SCAN);
547}
548
549
550static void
551ath5k_sw_scan_complete(struct ieee80211_hw *hw)
552{
553 struct ath5k_softc *sc = hw->priv;
554 ath5k_hw_set_ledstate(sc->ah, sc->assoc ?
555 AR5K_LED_ASSOC : AR5K_LED_INIT);
556}
557
558
559static int
560ath5k_get_stats(struct ieee80211_hw *hw,
561 struct ieee80211_low_level_stats *stats)
562{
563 struct ath5k_softc *sc = hw->priv;
564
565 /* Force update */
566 ath5k_hw_update_mib_counters(sc->ah);
567
568 stats->dot11ACKFailureCount = sc->stats.ack_fail;
569 stats->dot11RTSFailureCount = sc->stats.rts_fail;
570 stats->dot11RTSSuccessCount = sc->stats.rts_ok;
571 stats->dot11FCSErrorCount = sc->stats.fcs_error;
572
573 return 0;
574}
575
576
577static int
578ath5k_conf_tx(struct ieee80211_hw *hw, u16 queue,
579 const struct ieee80211_tx_queue_params *params)
580{
581 struct ath5k_softc *sc = hw->priv;
582 struct ath5k_hw *ah = sc->ah;
583 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
589 mutex_lock(&sc->lock);
590
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;
596 qi.tqi_burst_time = params->txop;
597
598 ATH5K_DBG(sc, ATH5K_DEBUG_ANY,
599 "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)) {
605 ATH5K_ERR(sc,
606 "Unable to update hardware queue %u!\n", queue);
607 ret = -EIO;
608 } else
609 ath5k_hw_reset_tx_queue(ah, queue);
610
611 mutex_unlock(&sc->lock);
612
613 return ret;
614}
615
616
617static u64
618ath5k_get_tsf(struct ieee80211_hw *hw)
619{
620 struct ath5k_softc *sc = hw->priv;
621
622 return ath5k_hw_get_tsf64(sc->ah);
623}
624
625
626static void
627ath5k_set_tsf(struct ieee80211_hw *hw, u64 tsf)
628{
629 struct ath5k_softc *sc = hw->priv;
630
631 ath5k_hw_set_tsf64(sc->ah, tsf);
632}
633
634
635static void
636ath5k_reset_tsf(struct ieee80211_hw *hw)
637{
638 struct ath5k_softc *sc = hw->priv;
639
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 */
644 if (sc->opmode == NL80211_IFTYPE_ADHOC)
645 ath5k_beacon_update_timers(sc, 0);
646 else
647 ath5k_hw_reset_tsf(sc->ah);
648}
649
650
651static int
652ath5k_get_survey(struct ieee80211_hw *hw, int idx, struct survey_info *survey)
653{
654 struct ath5k_softc *sc = hw->priv;
655 struct ieee80211_conf *conf = &hw->conf;
656 struct ath_common *common = ath5k_hw_common(sc->ah);
657 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) {
666 sc->survey.channel_time += cc->cycles / div;
667 sc->survey.channel_time_busy += cc->rx_busy / div;
668 sc->survey.channel_time_rx += cc->rx_frame / div;
669 sc->survey.channel_time_tx += cc->tx_frame / div;
670 }
671 memset(cc, 0, sizeof(*cc));
672 spin_unlock_bh(&common->cc_lock);
673
674 memcpy(survey, &sc->survey, sizeof(*survey));
675
676 survey->channel = conf->channel;
677 survey->noise = sc->ah->ah_noise_floor;
678 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{
701 struct ath5k_softc *sc = hw->priv;
702
703 mutex_lock(&sc->lock);
704 ath5k_hw_set_coverage_class(sc->ah, coverage_class);
705 mutex_unlock(&sc->lock);
706}
707
708
709static int
710ath5k_set_antenna(struct ieee80211_hw *hw, u32 tx_ant, u32 rx_ant)
711{
712 struct ath5k_softc *sc = hw->priv;
713
714 if (tx_ant == 1 && rx_ant == 1)
715 ath5k_hw_set_antenna_mode(sc->ah, AR5K_ANTMODE_FIXED_A);
716 else if (tx_ant == 2 && rx_ant == 2)
717 ath5k_hw_set_antenna_mode(sc->ah, AR5K_ANTMODE_FIXED_B);
718 else if ((tx_ant & 3) == 3 && (rx_ant & 3) == 3)
719 ath5k_hw_set_antenna_mode(sc->ah, AR5K_ANTMODE_DEFAULT);
720 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{
729 struct ath5k_softc *sc = hw->priv;
730
731 switch (sc->ah->ah_ant_mode) {
732 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
743const struct ieee80211_ops ath5k_hw_ops = {
744 .tx = ath5k_tx,
745 .start = ath5k_start,
746 .stop = ath5k_stop,
747 .add_interface = ath5k_add_interface,
748 /* .change_interface = not implemented */
749 .remove_interface = ath5k_remove_interface,
750 .config = ath5k_config,
751 .bss_info_changed = ath5k_bss_info_changed,
752 .prepare_multicast = ath5k_prepare_multicast,
753 .configure_filter = ath5k_configure_filter,
754 /* .set_tim = not implemented */
755 .set_key = ath5k_set_key,
756 /* .update_tkip_key = not implemented */
757 /* .hw_scan = not implemented */
758 .sw_scan_start = ath5k_sw_scan_start,
759 .sw_scan_complete = ath5k_sw_scan_complete,
760 .get_stats = ath5k_get_stats,
761 /* .get_tkip_seq = not implemented */
762 /* .set_frag_threshold = not implemented */
763 /* .set_rts_threshold = not implemented */
764 /* .sta_add = not implemented */
765 /* .sta_remove = not implemented */
766 /* .sta_notify = not implemented */
767 .conf_tx = ath5k_conf_tx,
768 .get_tsf = ath5k_get_tsf,
769 .set_tsf = ath5k_set_tsf,
770 .reset_tsf = ath5k_reset_tsf,
771 /* .tx_last_beacon = not implemented */
772 /* .ampdu_action = not needed */
773 .get_survey = ath5k_get_survey,
774 .set_coverage_class = ath5k_set_coverage_class,
775 /* .rfkill_poll = not implemented */
776 /* .flush = not implemented */
777 /* .channel_switch = not implemented */
778 /* .napi_poll = not implemented */
779 .set_antenna = ath5k_set_antenna,
780 .get_antenna = ath5k_get_antenna,
781};