IPVS: fix netns if reading ip_vs_* procfs entries
[linux-2.6/linux-mips.git] / drivers / net / wireless / ath / ath5k / mac80211-ops.c
blob9be29b728b1cffe2fdc5d9bf0977fe14e77fc562
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>
9 * All rights reserved.
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.
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.
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.
44 #include <asm/unaligned.h>
46 #include "base.h"
47 #include "reg.h"
49 extern int ath5k_modparam_nohwcrypt;
51 /********************\
52 * Mac80211 functions *
53 \********************/
55 static void
56 ath5k_tx(struct ieee80211_hw *hw, struct sk_buff *skb)
58 struct ath5k_softc *sc = hw->priv;
59 u16 qnum = skb_get_queue_mapping(skb);
61 if (WARN_ON(qnum >= sc->ah->ah_capabilities.cap_queues.q_tx_num)) {
62 dev_kfree_skb_any(skb);
63 return;
66 ath5k_tx_queue(hw, skb, &sc->txqs[qnum]);
70 static int
71 ath5k_start(struct ieee80211_hw *hw)
73 return ath5k_init_hw(hw->priv);
77 static void
78 ath5k_stop(struct ieee80211_hw *hw)
80 ath5k_stop_hw(hw->priv);
84 static int
85 ath5k_add_interface(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
87 struct ath5k_softc *sc = hw->priv;
88 int ret;
89 struct ath5k_vif *avf = (void *)vif->drv_priv;
91 mutex_lock(&sc->lock);
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;
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;
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;
124 sc->nvifs++;
125 ATH5K_DBG(sc, ATH5K_DEBUG_MODE, "add interface mode %d\n", avf->opmode);
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;
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);
138 avf->bslot = 0;
139 for (slot = 0; slot < ATH_BCBUF; slot++) {
140 if (!sc->bslot[slot]) {
141 avf->bslot = slot;
142 break;
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++;
153 /* Any MAC address is fine, all others are included through the
154 * filter.
156 memcpy(&sc->lladdr, vif->addr, ETH_ALEN);
157 ath5k_hw_set_lladdr(sc->ah, vif->addr);
159 memcpy(&avf->lladdr, vif->addr, ETH_ALEN);
161 ath5k_update_bssid_mask_and_opmode(sc, vif);
162 ret = 0;
163 end:
164 mutex_unlock(&sc->lock);
165 return ret;
169 static void
170 ath5k_remove_interface(struct ieee80211_hw *hw,
171 struct ieee80211_vif *vif)
173 struct ath5k_softc *sc = hw->priv;
174 struct ath5k_vif *avf = (void *)vif->drv_priv;
175 unsigned int i;
177 mutex_lock(&sc->lock);
178 sc->nvifs--;
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;
189 avf->bbuf = NULL;
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--;
196 ath5k_update_bssid_mask_and_opmode(sc, NULL);
197 mutex_unlock(&sc->lock);
202 * TODO: Phy disable/diversity etc
204 static int
205 ath5k_config(struct ieee80211_hw *hw, u32 changed)
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;
211 int i;
213 mutex_lock(&sc->lock);
215 if (changed & IEEE80211_CONF_CHANGE_CHANNEL) {
216 ret = ath5k_chan_set(sc, conf->channel);
217 if (ret < 0)
218 goto unlock;
221 if ((changed & IEEE80211_CONF_CHANGE_POWER) &&
222 (sc->power_level != conf->power_level)) {
223 sc->power_level = conf->power_level;
225 /* Half dB steps */
226 ath5k_hw_set_txpower_limit(ah, (conf->power_level * 2));
229 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;
233 for (i = 0; i < ah->ah_capabilities.cap_queues.q_tx_num; i++)
234 ath5k_hw_set_tx_retry_limits(ah, i);
237 /* 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
242 * 2) Allow the user to change antenna mode eg. when only
243 * one antenna is present
245 * 3) Allow the user to set default/tx antenna when possible
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
254 ath5k_hw_set_antenna_mode(ah, ah->ah_ant_mode);
256 unlock:
257 mutex_unlock(&sc->lock);
258 return ret;
262 static void
263 ath5k_bss_info_changed(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
264 struct ieee80211_bss_conf *bss_conf, u32 changes)
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;
272 mutex_lock(&sc->lock);
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();
282 if (changes & BSS_CHANGED_BEACON_INT)
283 sc->bintval = bss_conf->beacon_int;
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);
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 */
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);
312 if (changes & BSS_CHANGED_BEACON_ENABLED)
313 sc->enable_beacon = bss_conf->enable_beacon;
315 if (changes & (BSS_CHANGED_BEACON | BSS_CHANGED_BEACON_ENABLED |
316 BSS_CHANGED_BEACON_INT))
317 ath5k_beacon_config(sc);
319 mutex_unlock(&sc->lock);
323 static u64
324 ath5k_prepare_multicast(struct ieee80211_hw *hw,
325 struct netdev_hw_addr_list *mc_list)
327 u32 mfilt[2], val;
328 u8 pos;
329 struct netdev_hw_addr *ha;
331 mfilt[0] = 0;
332 mfilt[1] = 1;
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]); */
349 return ((u64)(mfilt[1]) << 32) | mfilt[0];
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
371 static void
372 ath5k_configure_filter(struct ieee80211_hw *hw, unsigned int changed_flags,
373 unsigned int *new_flags, u64 multicast)
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)
380 struct ath5k_softc *sc = hw->priv;
381 struct ath5k_hw *ah = sc->ah;
382 u32 mfilt[2], rfilt;
383 struct ath5k_vif_iter_data iter_data; /* to count STA interfaces */
385 mutex_lock(&sc->lock);
387 mfilt[0] = multicast;
388 mfilt[1] = multicast >> 32;
390 /* Only deal with supported flags */
391 changed_flags &= SUPPORTED_FIF_FLAGS;
392 *new_flags &= SUPPORTED_FIF_FLAGS;
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);
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);
408 if (test_bit(ATH_STAT_PROMISC, sc->status))
409 rfilt |= AR5K_RX_FILTER_PROM;
411 /* Note, AR5K_RX_FILTER_MCAST is already enabled */
412 if (*new_flags & FIF_ALLMULTI) {
413 mfilt[0] = ~0;
414 mfilt[1] = ~0;
417 /* This is the best we can do */
418 if (*new_flags & (FIF_FCSFAIL | FIF_PLCPFAIL))
419 rfilt |= AR5K_RX_FILTER_PHYERR;
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;
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;
434 /* Additional settings per mode -- this is per ath5k */
436 /* XXX move these to mac80211, and add a beacon IFF flag to mac80211 */
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;
457 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);
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.
469 rfilt |= AR5K_RX_FILTER_PROM;
472 /* Set filters */
473 ath5k_hw_set_rx_filter(ah, rfilt);
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;
481 mutex_unlock(&sc->lock);
485 static int
486 ath5k_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)
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;
495 if (ath5k_modparam_nohwcrypt)
496 return -EOPNOTSUPP;
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;
512 mutex_lock(&sc->lock);
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;
527 break;
528 case DISABLE_KEY:
529 ath_key_delete(common, key);
530 break;
531 default:
532 ret = -EINVAL;
535 mmiowb();
536 mutex_unlock(&sc->lock);
537 return ret;
541 static void
542 ath5k_sw_scan_start(struct ieee80211_hw *hw)
544 struct ath5k_softc *sc = hw->priv;
545 if (!sc->assoc)
546 ath5k_hw_set_ledstate(sc->ah, AR5K_LED_SCAN);
550 static void
551 ath5k_sw_scan_complete(struct ieee80211_hw *hw)
553 struct ath5k_softc *sc = hw->priv;
554 ath5k_hw_set_ledstate(sc->ah, sc->assoc ?
555 AR5K_LED_ASSOC : AR5K_LED_INIT);
559 static int
560 ath5k_get_stats(struct ieee80211_hw *hw,
561 struct ieee80211_low_level_stats *stats)
563 struct ath5k_softc *sc = hw->priv;
565 /* Force update */
566 ath5k_hw_update_mib_counters(sc->ah);
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;
573 return 0;
577 static int
578 ath5k_conf_tx(struct ieee80211_hw *hw, u16 queue,
579 const struct ieee80211_tx_queue_params *params)
581 struct ath5k_softc *sc = hw->priv;
582 struct ath5k_hw *ah = sc->ah;
583 struct ath5k_txq_info qi;
584 int ret = 0;
586 if (queue >= ah->ah_capabilities.cap_queues.q_tx_num)
587 return 0;
589 mutex_lock(&sc->lock);
591 ath5k_hw_get_tx_queueprops(ah, queue, &qi);
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;
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);
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);
611 mutex_unlock(&sc->lock);
613 return ret;
617 static u64
618 ath5k_get_tsf(struct ieee80211_hw *hw)
620 struct ath5k_softc *sc = hw->priv;
622 return ath5k_hw_get_tsf64(sc->ah);
626 static void
627 ath5k_set_tsf(struct ieee80211_hw *hw, u64 tsf)
629 struct ath5k_softc *sc = hw->priv;
631 ath5k_hw_set_tsf64(sc->ah, tsf);
635 static void
636 ath5k_reset_tsf(struct ieee80211_hw *hw)
638 struct ath5k_softc *sc = hw->priv;
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
644 if (sc->opmode == NL80211_IFTYPE_ADHOC)
645 ath5k_beacon_update_timers(sc, 0);
646 else
647 ath5k_hw_reset_tsf(sc->ah);
651 static int
652 ath5k_get_survey(struct ieee80211_hw *hw, int idx, struct survey_info *survey)
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;
660 if (idx != 0)
661 return -ENOENT;
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;
671 memset(cc, 0, sizeof(*cc));
672 spin_unlock_bh(&common->cc_lock);
674 memcpy(survey, &sc->survey, sizeof(*survey));
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;
684 return 0;
689 * ath5k_set_coverage_class - Set IEEE 802.11 coverage class
691 * @hw: struct ieee80211_hw pointer
692 * @coverage_class: IEEE 802.11 coverage class number
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.
698 static void
699 ath5k_set_coverage_class(struct ieee80211_hw *hw, u8 coverage_class)
701 struct ath5k_softc *sc = hw->priv;
703 mutex_lock(&sc->lock);
704 ath5k_hw_set_coverage_class(sc->ah, coverage_class);
705 mutex_unlock(&sc->lock);
709 static int
710 ath5k_set_antenna(struct ieee80211_hw *hw, u32 tx_ant, u32 rx_ant)
712 struct ath5k_softc *sc = hw->priv;
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;
726 static int
727 ath5k_get_antenna(struct ieee80211_hw *hw, u32 *tx_ant, u32 *rx_ant)
729 struct ath5k_softc *sc = hw->priv;
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;
739 return 0;
743 static void ath5k_get_ringparam(struct ieee80211_hw *hw,
744 u32 *tx, u32 *tx_max, u32 *rx, u32 *rx_max)
746 struct ath5k_softc *sc = hw->priv;
748 *tx = sc->txqs[AR5K_TX_QUEUE_ID_DATA_MIN].txq_max;
750 *tx_max = ATH5K_TXQ_LEN_MAX;
751 *rx = *rx_max = ATH_RXBUF;
755 static int ath5k_set_ringparam(struct ieee80211_hw *hw, u32 tx, u32 rx)
757 struct ath5k_softc *sc = hw->priv;
758 u16 qnum;
760 /* only support setting tx ring size for now */
761 if (rx != ATH_RXBUF)
762 return -EINVAL;
764 /* restrict tx ring size min/max */
765 if (!tx || tx > ATH5K_TXQ_LEN_MAX)
766 return -EINVAL;
768 for (qnum = 0; qnum < ARRAY_SIZE(sc->txqs); qnum++) {
769 if (!sc->txqs[qnum].setup)
770 continue;
771 if (sc->txqs[qnum].qnum < AR5K_TX_QUEUE_ID_DATA_MIN ||
772 sc->txqs[qnum].qnum > AR5K_TX_QUEUE_ID_DATA_MAX)
773 continue;
775 sc->txqs[qnum].txq_max = tx;
776 if (sc->txqs[qnum].txq_len >= sc->txqs[qnum].txq_max)
777 ieee80211_stop_queue(hw, sc->txqs[qnum].qnum);
780 return 0;
784 const struct ieee80211_ops ath5k_hw_ops = {
785 .tx = ath5k_tx,
786 .start = ath5k_start,
787 .stop = ath5k_stop,
788 .add_interface = ath5k_add_interface,
789 /* .change_interface = not implemented */
790 .remove_interface = ath5k_remove_interface,
791 .config = ath5k_config,
792 .bss_info_changed = ath5k_bss_info_changed,
793 .prepare_multicast = ath5k_prepare_multicast,
794 .configure_filter = ath5k_configure_filter,
795 /* .set_tim = not implemented */
796 .set_key = ath5k_set_key,
797 /* .update_tkip_key = not implemented */
798 /* .hw_scan = not implemented */
799 .sw_scan_start = ath5k_sw_scan_start,
800 .sw_scan_complete = ath5k_sw_scan_complete,
801 .get_stats = ath5k_get_stats,
802 /* .get_tkip_seq = not implemented */
803 /* .set_frag_threshold = not implemented */
804 /* .set_rts_threshold = not implemented */
805 /* .sta_add = not implemented */
806 /* .sta_remove = not implemented */
807 /* .sta_notify = not implemented */
808 .conf_tx = ath5k_conf_tx,
809 .get_tsf = ath5k_get_tsf,
810 .set_tsf = ath5k_set_tsf,
811 .reset_tsf = ath5k_reset_tsf,
812 /* .tx_last_beacon = not implemented */
813 /* .ampdu_action = not needed */
814 .get_survey = ath5k_get_survey,
815 .set_coverage_class = ath5k_set_coverage_class,
816 /* .rfkill_poll = not implemented */
817 /* .flush = not implemented */
818 /* .channel_switch = not implemented */
819 /* .napi_poll = not implemented */
820 .set_antenna = ath5k_set_antenna,
821 .get_antenna = ath5k_get_antenna,
822 .set_ringparam = ath5k_set_ringparam,
823 .get_ringparam = ath5k_get_ringparam,