mac80211: make tx() operation return void
[deliverable/linux.git] / drivers / net / wireless / ath / ath5k / mac80211-ops.c
1 /*-
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
49 extern int ath5k_modparam_nohwcrypt;
50
51 /********************\
52 * Mac80211 functions *
53 \********************/
54
55 static void
56 ath5k_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);
63 return;
64 }
65
66 ath5k_tx_queue(hw, skb, &sc->txqs[qnum]);
67 }
68
69
70 static int
71 ath5k_start(struct ieee80211_hw *hw)
72 {
73 return ath5k_init_hw(hw->priv);
74 }
75
76
77 static void
78 ath5k_stop(struct ieee80211_hw *hw)
79 {
80 ath5k_stop_hw(hw->priv);
81 }
82
83
84 static int
85 ath5k_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
161 ath5k_mode_setup(sc, vif);
162
163 ret = 0;
164 end:
165 mutex_unlock(&sc->lock);
166 return ret;
167 }
168
169
170 static void
171 ath5k_remove_interface(struct ieee80211_hw *hw,
172 struct ieee80211_vif *vif)
173 {
174 struct ath5k_softc *sc = hw->priv;
175 struct ath5k_vif *avf = (void *)vif->drv_priv;
176 unsigned int i;
177
178 mutex_lock(&sc->lock);
179 sc->nvifs--;
180
181 if (avf->bbuf) {
182 ath5k_txbuf_free_skb(sc, avf->bbuf);
183 list_add_tail(&avf->bbuf->list, &sc->bcbuf);
184 for (i = 0; i < ATH_BCBUF; i++) {
185 if (sc->bslot[i] == vif) {
186 sc->bslot[i] = NULL;
187 break;
188 }
189 }
190 avf->bbuf = NULL;
191 }
192 if (avf->opmode == NL80211_IFTYPE_AP)
193 sc->num_ap_vifs--;
194 else if (avf->opmode == NL80211_IFTYPE_ADHOC)
195 sc->num_adhoc_vifs--;
196
197 ath5k_update_bssid_mask_and_opmode(sc, NULL);
198 mutex_unlock(&sc->lock);
199 }
200
201
202 /*
203 * TODO: Phy disable/diversity etc
204 */
205 static int
206 ath5k_config(struct ieee80211_hw *hw, u32 changed)
207 {
208 struct ath5k_softc *sc = hw->priv;
209 struct ath5k_hw *ah = sc->ah;
210 struct ieee80211_conf *conf = &hw->conf;
211 int ret = 0;
212 int i;
213
214 mutex_lock(&sc->lock);
215
216 if (changed & IEEE80211_CONF_CHANGE_CHANNEL) {
217 ret = ath5k_chan_set(sc, conf->channel);
218 if (ret < 0)
219 goto unlock;
220 }
221
222 if ((changed & IEEE80211_CONF_CHANGE_POWER) &&
223 (sc->power_level != conf->power_level)) {
224 sc->power_level = conf->power_level;
225
226 /* Half dB steps */
227 ath5k_hw_set_txpower_limit(ah, (conf->power_level * 2));
228 }
229
230 if (changed & IEEE80211_CONF_CHANGE_RETRY_LIMITS) {
231 ah->ah_retry_long = conf->long_frame_max_tx_count;
232 ah->ah_retry_short = conf->short_frame_max_tx_count;
233
234 for (i = 0; i < ah->ah_capabilities.cap_queues.q_tx_num; i++)
235 ath5k_hw_set_tx_retry_limits(ah, i);
236 }
237
238 /* TODO:
239 * 1) Move this on config_interface and handle each case
240 * separately eg. when we have only one STA vif, use
241 * AR5K_ANTMODE_SINGLE_AP
242 *
243 * 2) Allow the user to change antenna mode eg. when only
244 * one antenna is present
245 *
246 * 3) Allow the user to set default/tx antenna when possible
247 *
248 * 4) Default mode should handle 90% of the cases, together
249 * with fixed a/b and single AP modes we should be able to
250 * handle 99%. Sectored modes are extreme cases and i still
251 * haven't found a usage for them. If we decide to support them,
252 * then we must allow the user to set how many tx antennas we
253 * have available
254 */
255 ath5k_hw_set_antenna_mode(ah, ah->ah_ant_mode);
256
257 unlock:
258 mutex_unlock(&sc->lock);
259 return ret;
260 }
261
262
263 static void
264 ath5k_bss_info_changed(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
265 struct ieee80211_bss_conf *bss_conf, u32 changes)
266 {
267 struct ath5k_vif *avf = (void *)vif->drv_priv;
268 struct ath5k_softc *sc = hw->priv;
269 struct ath5k_hw *ah = sc->ah;
270 struct ath_common *common = ath5k_hw_common(ah);
271 unsigned long flags;
272
273 mutex_lock(&sc->lock);
274
275 if (changes & BSS_CHANGED_BSSID) {
276 /* Cache for later use during resets */
277 memcpy(common->curbssid, bss_conf->bssid, ETH_ALEN);
278 common->curaid = 0;
279 ath5k_hw_set_bssid(ah);
280 mmiowb();
281 }
282
283 if (changes & BSS_CHANGED_BEACON_INT)
284 sc->bintval = bss_conf->beacon_int;
285
286 if (changes & BSS_CHANGED_ASSOC) {
287 avf->assoc = bss_conf->assoc;
288 if (bss_conf->assoc)
289 sc->assoc = bss_conf->assoc;
290 else
291 sc->assoc = ath_any_vif_assoc(sc);
292
293 if (sc->opmode == NL80211_IFTYPE_STATION)
294 set_beacon_filter(hw, sc->assoc);
295 ath5k_hw_set_ledstate(sc->ah, sc->assoc ?
296 AR5K_LED_ASSOC : AR5K_LED_INIT);
297 if (bss_conf->assoc) {
298 ATH5K_DBG(sc, ATH5K_DEBUG_ANY,
299 "Bss Info ASSOC %d, bssid: %pM\n",
300 bss_conf->aid, common->curbssid);
301 common->curaid = bss_conf->aid;
302 ath5k_hw_set_bssid(ah);
303 /* Once ANI is available you would start it here */
304 }
305 }
306
307 if (changes & BSS_CHANGED_BEACON) {
308 spin_lock_irqsave(&sc->block, flags);
309 ath5k_beacon_update(hw, vif);
310 spin_unlock_irqrestore(&sc->block, flags);
311 }
312
313 if (changes & BSS_CHANGED_BEACON_ENABLED)
314 sc->enable_beacon = bss_conf->enable_beacon;
315
316 if (changes & (BSS_CHANGED_BEACON | BSS_CHANGED_BEACON_ENABLED |
317 BSS_CHANGED_BEACON_INT))
318 ath5k_beacon_config(sc);
319
320 mutex_unlock(&sc->lock);
321 }
322
323
324 static u64
325 ath5k_prepare_multicast(struct ieee80211_hw *hw,
326 struct netdev_hw_addr_list *mc_list)
327 {
328 u32 mfilt[2], val;
329 u8 pos;
330 struct netdev_hw_addr *ha;
331
332 mfilt[0] = 0;
333 mfilt[1] = 1;
334
335 netdev_hw_addr_list_for_each(ha, mc_list) {
336 /* calculate XOR of eight 6-bit values */
337 val = get_unaligned_le32(ha->addr + 0);
338 pos = (val >> 18) ^ (val >> 12) ^ (val >> 6) ^ val;
339 val = get_unaligned_le32(ha->addr + 3);
340 pos ^= (val >> 18) ^ (val >> 12) ^ (val >> 6) ^ val;
341 pos &= 0x3f;
342 mfilt[pos / 32] |= (1 << (pos % 32));
343 /* XXX: we might be able to just do this instead,
344 * but not sure, needs testing, if we do use this we'd
345 * neet to inform below to not reset the mcast */
346 /* ath5k_hw_set_mcast_filterindex(ah,
347 * ha->addr[5]); */
348 }
349
350 return ((u64)(mfilt[1]) << 32) | mfilt[0];
351 }
352
353
354 /*
355 * o always accept unicast, broadcast, and multicast traffic
356 * o multicast traffic for all BSSIDs will be enabled if mac80211
357 * says it should be
358 * o maintain current state of phy ofdm or phy cck error reception.
359 * If the hardware detects any of these type of errors then
360 * ath5k_hw_get_rx_filter() will pass to us the respective
361 * hardware filters to be able to receive these type of frames.
362 * o probe request frames are accepted only when operating in
363 * hostap, adhoc, or monitor modes
364 * o enable promiscuous mode according to the interface state
365 * o accept beacons:
366 * - when operating in adhoc mode so the 802.11 layer creates
367 * node table entries for peers,
368 * - when operating in station mode for collecting rssi data when
369 * the station is otherwise quiet, or
370 * - when scanning
371 */
372 static void
373 ath5k_configure_filter(struct ieee80211_hw *hw, unsigned int changed_flags,
374 unsigned int *new_flags, u64 multicast)
375 {
376 #define SUPPORTED_FIF_FLAGS \
377 (FIF_PROMISC_IN_BSS | FIF_ALLMULTI | FIF_FCSFAIL | \
378 FIF_PLCPFAIL | FIF_CONTROL | FIF_OTHER_BSS | \
379 FIF_BCN_PRBRESP_PROMISC)
380
381 struct ath5k_softc *sc = hw->priv;
382 struct ath5k_hw *ah = sc->ah;
383 u32 mfilt[2], rfilt;
384
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
457 /* Set filters */
458 ath5k_hw_set_rx_filter(ah, rfilt);
459
460 /* Set multicast bits */
461 ath5k_hw_set_mcast_filter(ah, mfilt[0], mfilt[1]);
462 /* Set the cached hw filter flags, this will later actually
463 * be set in HW */
464 sc->filter_flags = rfilt;
465
466 mutex_unlock(&sc->lock);
467 }
468
469
470 static int
471 ath5k_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
472 struct ieee80211_vif *vif, struct ieee80211_sta *sta,
473 struct ieee80211_key_conf *key)
474 {
475 struct ath5k_softc *sc = hw->priv;
476 struct ath5k_hw *ah = sc->ah;
477 struct ath_common *common = ath5k_hw_common(ah);
478 int ret = 0;
479
480 if (ath5k_modparam_nohwcrypt)
481 return -EOPNOTSUPP;
482
483 switch (key->cipher) {
484 case WLAN_CIPHER_SUITE_WEP40:
485 case WLAN_CIPHER_SUITE_WEP104:
486 case WLAN_CIPHER_SUITE_TKIP:
487 break;
488 case WLAN_CIPHER_SUITE_CCMP:
489 if (common->crypt_caps & ATH_CRYPT_CAP_CIPHER_AESCCM)
490 break;
491 return -EOPNOTSUPP;
492 default:
493 WARN_ON(1);
494 return -EINVAL;
495 }
496
497 mutex_lock(&sc->lock);
498
499 switch (cmd) {
500 case SET_KEY:
501 ret = ath_key_config(common, vif, sta, key);
502 if (ret >= 0) {
503 key->hw_key_idx = ret;
504 /* push IV and Michael MIC generation to stack */
505 key->flags |= IEEE80211_KEY_FLAG_GENERATE_IV;
506 if (key->cipher == WLAN_CIPHER_SUITE_TKIP)
507 key->flags |= IEEE80211_KEY_FLAG_GENERATE_MMIC;
508 if (key->cipher == WLAN_CIPHER_SUITE_CCMP)
509 key->flags |= IEEE80211_KEY_FLAG_SW_MGMT;
510 ret = 0;
511 }
512 break;
513 case DISABLE_KEY:
514 ath_key_delete(common, key);
515 break;
516 default:
517 ret = -EINVAL;
518 }
519
520 mmiowb();
521 mutex_unlock(&sc->lock);
522 return ret;
523 }
524
525
526 static void
527 ath5k_sw_scan_start(struct ieee80211_hw *hw)
528 {
529 struct ath5k_softc *sc = hw->priv;
530 if (!sc->assoc)
531 ath5k_hw_set_ledstate(sc->ah, AR5K_LED_SCAN);
532 }
533
534
535 static void
536 ath5k_sw_scan_complete(struct ieee80211_hw *hw)
537 {
538 struct ath5k_softc *sc = hw->priv;
539 ath5k_hw_set_ledstate(sc->ah, sc->assoc ?
540 AR5K_LED_ASSOC : AR5K_LED_INIT);
541 }
542
543
544 static int
545 ath5k_get_stats(struct ieee80211_hw *hw,
546 struct ieee80211_low_level_stats *stats)
547 {
548 struct ath5k_softc *sc = hw->priv;
549
550 /* Force update */
551 ath5k_hw_update_mib_counters(sc->ah);
552
553 stats->dot11ACKFailureCount = sc->stats.ack_fail;
554 stats->dot11RTSFailureCount = sc->stats.rts_fail;
555 stats->dot11RTSSuccessCount = sc->stats.rts_ok;
556 stats->dot11FCSErrorCount = sc->stats.fcs_error;
557
558 return 0;
559 }
560
561
562 static int
563 ath5k_conf_tx(struct ieee80211_hw *hw, u16 queue,
564 const struct ieee80211_tx_queue_params *params)
565 {
566 struct ath5k_softc *sc = hw->priv;
567 struct ath5k_hw *ah = sc->ah;
568 struct ath5k_txq_info qi;
569 int ret = 0;
570
571 if (queue >= ah->ah_capabilities.cap_queues.q_tx_num)
572 return 0;
573
574 mutex_lock(&sc->lock);
575
576 ath5k_hw_get_tx_queueprops(ah, queue, &qi);
577
578 qi.tqi_aifs = params->aifs;
579 qi.tqi_cw_min = params->cw_min;
580 qi.tqi_cw_max = params->cw_max;
581 qi.tqi_burst_time = params->txop;
582
583 ATH5K_DBG(sc, ATH5K_DEBUG_ANY,
584 "Configure tx [queue %d], "
585 "aifs: %d, cw_min: %d, cw_max: %d, txop: %d\n",
586 queue, params->aifs, params->cw_min,
587 params->cw_max, params->txop);
588
589 if (ath5k_hw_set_tx_queueprops(ah, queue, &qi)) {
590 ATH5K_ERR(sc,
591 "Unable to update hardware queue %u!\n", queue);
592 ret = -EIO;
593 } else
594 ath5k_hw_reset_tx_queue(ah, queue);
595
596 mutex_unlock(&sc->lock);
597
598 return ret;
599 }
600
601
602 static u64
603 ath5k_get_tsf(struct ieee80211_hw *hw)
604 {
605 struct ath5k_softc *sc = hw->priv;
606
607 return ath5k_hw_get_tsf64(sc->ah);
608 }
609
610
611 static void
612 ath5k_set_tsf(struct ieee80211_hw *hw, u64 tsf)
613 {
614 struct ath5k_softc *sc = hw->priv;
615
616 ath5k_hw_set_tsf64(sc->ah, tsf);
617 }
618
619
620 static void
621 ath5k_reset_tsf(struct ieee80211_hw *hw)
622 {
623 struct ath5k_softc *sc = hw->priv;
624
625 /*
626 * in IBSS mode we need to update the beacon timers too.
627 * this will also reset the TSF if we call it with 0
628 */
629 if (sc->opmode == NL80211_IFTYPE_ADHOC)
630 ath5k_beacon_update_timers(sc, 0);
631 else
632 ath5k_hw_reset_tsf(sc->ah);
633 }
634
635
636 static int
637 ath5k_get_survey(struct ieee80211_hw *hw, int idx, struct survey_info *survey)
638 {
639 struct ath5k_softc *sc = hw->priv;
640 struct ieee80211_conf *conf = &hw->conf;
641 struct ath_common *common = ath5k_hw_common(sc->ah);
642 struct ath_cycle_counters *cc = &common->cc_survey;
643 unsigned int div = common->clockrate * 1000;
644
645 if (idx != 0)
646 return -ENOENT;
647
648 spin_lock_bh(&common->cc_lock);
649 ath_hw_cycle_counters_update(common);
650 if (cc->cycles > 0) {
651 sc->survey.channel_time += cc->cycles / div;
652 sc->survey.channel_time_busy += cc->rx_busy / div;
653 sc->survey.channel_time_rx += cc->rx_frame / div;
654 sc->survey.channel_time_tx += cc->tx_frame / div;
655 }
656 memset(cc, 0, sizeof(*cc));
657 spin_unlock_bh(&common->cc_lock);
658
659 memcpy(survey, &sc->survey, sizeof(*survey));
660
661 survey->channel = conf->channel;
662 survey->noise = sc->ah->ah_noise_floor;
663 survey->filled = SURVEY_INFO_NOISE_DBM |
664 SURVEY_INFO_CHANNEL_TIME |
665 SURVEY_INFO_CHANNEL_TIME_BUSY |
666 SURVEY_INFO_CHANNEL_TIME_RX |
667 SURVEY_INFO_CHANNEL_TIME_TX;
668
669 return 0;
670 }
671
672
673 /**
674 * ath5k_set_coverage_class - Set IEEE 802.11 coverage class
675 *
676 * @hw: struct ieee80211_hw pointer
677 * @coverage_class: IEEE 802.11 coverage class number
678 *
679 * Mac80211 callback. Sets slot time, ACK timeout and CTS timeout for given
680 * coverage class. The values are persistent, they are restored after device
681 * reset.
682 */
683 static void
684 ath5k_set_coverage_class(struct ieee80211_hw *hw, u8 coverage_class)
685 {
686 struct ath5k_softc *sc = hw->priv;
687
688 mutex_lock(&sc->lock);
689 ath5k_hw_set_coverage_class(sc->ah, coverage_class);
690 mutex_unlock(&sc->lock);
691 }
692
693
694 static int
695 ath5k_set_antenna(struct ieee80211_hw *hw, u32 tx_ant, u32 rx_ant)
696 {
697 struct ath5k_softc *sc = hw->priv;
698
699 if (tx_ant == 1 && rx_ant == 1)
700 ath5k_hw_set_antenna_mode(sc->ah, AR5K_ANTMODE_FIXED_A);
701 else if (tx_ant == 2 && rx_ant == 2)
702 ath5k_hw_set_antenna_mode(sc->ah, AR5K_ANTMODE_FIXED_B);
703 else if ((tx_ant & 3) == 3 && (rx_ant & 3) == 3)
704 ath5k_hw_set_antenna_mode(sc->ah, AR5K_ANTMODE_DEFAULT);
705 else
706 return -EINVAL;
707 return 0;
708 }
709
710
711 static int
712 ath5k_get_antenna(struct ieee80211_hw *hw, u32 *tx_ant, u32 *rx_ant)
713 {
714 struct ath5k_softc *sc = hw->priv;
715
716 switch (sc->ah->ah_ant_mode) {
717 case AR5K_ANTMODE_FIXED_A:
718 *tx_ant = 1; *rx_ant = 1; break;
719 case AR5K_ANTMODE_FIXED_B:
720 *tx_ant = 2; *rx_ant = 2; break;
721 case AR5K_ANTMODE_DEFAULT:
722 *tx_ant = 3; *rx_ant = 3; break;
723 }
724 return 0;
725 }
726
727
728 const struct ieee80211_ops ath5k_hw_ops = {
729 .tx = ath5k_tx,
730 .start = ath5k_start,
731 .stop = ath5k_stop,
732 .add_interface = ath5k_add_interface,
733 /* .change_interface = not implemented */
734 .remove_interface = ath5k_remove_interface,
735 .config = ath5k_config,
736 .bss_info_changed = ath5k_bss_info_changed,
737 .prepare_multicast = ath5k_prepare_multicast,
738 .configure_filter = ath5k_configure_filter,
739 /* .set_tim = not implemented */
740 .set_key = ath5k_set_key,
741 /* .update_tkip_key = not implemented */
742 /* .hw_scan = not implemented */
743 .sw_scan_start = ath5k_sw_scan_start,
744 .sw_scan_complete = ath5k_sw_scan_complete,
745 .get_stats = ath5k_get_stats,
746 /* .get_tkip_seq = not implemented */
747 /* .set_frag_threshold = not implemented */
748 /* .set_rts_threshold = not implemented */
749 /* .sta_add = not implemented */
750 /* .sta_remove = not implemented */
751 /* .sta_notify = not implemented */
752 .conf_tx = ath5k_conf_tx,
753 .get_tsf = ath5k_get_tsf,
754 .set_tsf = ath5k_set_tsf,
755 .reset_tsf = ath5k_reset_tsf,
756 /* .tx_last_beacon = not implemented */
757 /* .ampdu_action = not needed */
758 .get_survey = ath5k_get_survey,
759 .set_coverage_class = ath5k_set_coverage_class,
760 /* .rfkill_poll = not implemented */
761 /* .flush = not implemented */
762 /* .channel_switch = not implemented */
763 /* .napi_poll = not implemented */
764 .set_antenna = ath5k_set_antenna,
765 .get_antenna = ath5k_get_antenna,
766 };
This page took 0.081177 seconds and 5 git commands to generate.