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