GUI: Fix Tomato RAF theme for all builds. Compilation typo.
[tomato.git] / release / src-rt-6.x.4708 / linux / linux-2.6.36 / drivers / net / wireless / ath / ath9k / virtual.c
blobd24f7d11ce540b418235cfd32ce845546ab424cb
1 /*
2 * Copyright (c) 2008-2009 Atheros Communications Inc.
4 * Permission to use, copy, modify, and/or distribute this software for any
5 * purpose with or without fee is hereby granted, provided that the above
6 * copyright notice and this permission notice appear in all copies.
8 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17 #include <linux/slab.h>
19 #include "ath9k.h"
21 struct ath9k_vif_iter_data {
22 int count;
23 u8 *addr;
26 static void ath9k_vif_iter(void *data, u8 *mac, struct ieee80211_vif *vif)
28 struct ath9k_vif_iter_data *iter_data = data;
29 u8 *nbuf;
31 nbuf = krealloc(iter_data->addr, (iter_data->count + 1) * ETH_ALEN,
32 GFP_ATOMIC);
33 if (nbuf == NULL)
34 return;
36 memcpy(nbuf + iter_data->count * ETH_ALEN, mac, ETH_ALEN);
37 iter_data->addr = nbuf;
38 iter_data->count++;
41 void ath9k_set_bssid_mask(struct ieee80211_hw *hw)
43 struct ath_wiphy *aphy = hw->priv;
44 struct ath_softc *sc = aphy->sc;
45 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
46 struct ath9k_vif_iter_data iter_data;
47 int i, j;
48 u8 mask[ETH_ALEN];
51 * Add primary MAC address even if it is not in active use since it
52 * will be configured to the hardware as the starting point and the
53 * BSSID mask will need to be changed if another address is active.
55 iter_data.addr = kmalloc(ETH_ALEN, GFP_ATOMIC);
56 if (iter_data.addr) {
57 memcpy(iter_data.addr, common->macaddr, ETH_ALEN);
58 iter_data.count = 1;
59 } else
60 iter_data.count = 0;
62 /* Get list of all active MAC addresses */
63 spin_lock_bh(&sc->wiphy_lock);
64 ieee80211_iterate_active_interfaces_atomic(sc->hw, ath9k_vif_iter,
65 &iter_data);
66 for (i = 0; i < sc->num_sec_wiphy; i++) {
67 if (sc->sec_wiphy[i] == NULL)
68 continue;
69 ieee80211_iterate_active_interfaces_atomic(
70 sc->sec_wiphy[i]->hw, ath9k_vif_iter, &iter_data);
72 spin_unlock_bh(&sc->wiphy_lock);
74 /* Generate an address mask to cover all active addresses */
75 memset(mask, 0, ETH_ALEN);
76 for (i = 0; i < iter_data.count; i++) {
77 u8 *a1 = iter_data.addr + i * ETH_ALEN;
78 for (j = i + 1; j < iter_data.count; j++) {
79 u8 *a2 = iter_data.addr + j * ETH_ALEN;
80 mask[0] |= a1[0] ^ a2[0];
81 mask[1] |= a1[1] ^ a2[1];
82 mask[2] |= a1[2] ^ a2[2];
83 mask[3] |= a1[3] ^ a2[3];
84 mask[4] |= a1[4] ^ a2[4];
85 mask[5] |= a1[5] ^ a2[5];
89 kfree(iter_data.addr);
91 /* Invert the mask and configure hardware */
92 common->bssidmask[0] = ~mask[0];
93 common->bssidmask[1] = ~mask[1];
94 common->bssidmask[2] = ~mask[2];
95 common->bssidmask[3] = ~mask[3];
96 common->bssidmask[4] = ~mask[4];
97 common->bssidmask[5] = ~mask[5];
99 ath_hw_setbssidmask(common);
102 int ath9k_wiphy_add(struct ath_softc *sc)
104 int i, error;
105 struct ath_wiphy *aphy;
106 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
107 struct ieee80211_hw *hw;
108 u8 addr[ETH_ALEN];
110 hw = ieee80211_alloc_hw(sizeof(struct ath_wiphy), &ath9k_ops);
111 if (hw == NULL)
112 return -ENOMEM;
114 spin_lock_bh(&sc->wiphy_lock);
115 for (i = 0; i < sc->num_sec_wiphy; i++) {
116 if (sc->sec_wiphy[i] == NULL)
117 break;
120 if (i == sc->num_sec_wiphy) {
121 /* No empty slot available; increase array length */
122 struct ath_wiphy **n;
123 n = krealloc(sc->sec_wiphy,
124 (sc->num_sec_wiphy + 1) *
125 sizeof(struct ath_wiphy *),
126 GFP_ATOMIC);
127 if (n == NULL) {
128 spin_unlock_bh(&sc->wiphy_lock);
129 ieee80211_free_hw(hw);
130 return -ENOMEM;
132 n[i] = NULL;
133 sc->sec_wiphy = n;
134 sc->num_sec_wiphy++;
137 SET_IEEE80211_DEV(hw, sc->dev);
139 aphy = hw->priv;
140 aphy->sc = sc;
141 aphy->hw = hw;
142 sc->sec_wiphy[i] = aphy;
143 spin_unlock_bh(&sc->wiphy_lock);
145 memcpy(addr, common->macaddr, ETH_ALEN);
146 addr[0] |= 0x02; /* Locally managed address */
148 * XOR virtual wiphy index into the least significant bits to generate
149 * a different MAC address for each virtual wiphy.
151 addr[5] ^= i & 0xff;
152 addr[4] ^= (i & 0xff00) >> 8;
153 addr[3] ^= (i & 0xff0000) >> 16;
155 SET_IEEE80211_PERM_ADDR(hw, addr);
157 ath9k_set_hw_capab(sc, hw);
159 error = ieee80211_register_hw(hw);
161 if (error == 0) {
162 /* Make sure wiphy scheduler is started (if enabled) */
163 ath9k_wiphy_set_scheduler(sc, sc->wiphy_scheduler_int);
166 return error;
169 int ath9k_wiphy_del(struct ath_wiphy *aphy)
171 struct ath_softc *sc = aphy->sc;
172 int i;
174 spin_lock_bh(&sc->wiphy_lock);
175 for (i = 0; i < sc->num_sec_wiphy; i++) {
176 if (aphy == sc->sec_wiphy[i]) {
177 sc->sec_wiphy[i] = NULL;
178 spin_unlock_bh(&sc->wiphy_lock);
179 ieee80211_unregister_hw(aphy->hw);
180 ieee80211_free_hw(aphy->hw);
181 return 0;
184 spin_unlock_bh(&sc->wiphy_lock);
185 return -ENOENT;
188 static int ath9k_send_nullfunc(struct ath_wiphy *aphy,
189 struct ieee80211_vif *vif, const u8 *bssid,
190 int ps)
192 struct ath_softc *sc = aphy->sc;
193 struct ath_tx_control txctl;
194 struct sk_buff *skb;
195 struct ieee80211_hdr *hdr;
196 __le16 fc;
197 struct ieee80211_tx_info *info;
199 skb = dev_alloc_skb(24);
200 if (skb == NULL)
201 return -ENOMEM;
202 hdr = (struct ieee80211_hdr *) skb_put(skb, 24);
203 memset(hdr, 0, 24);
204 fc = cpu_to_le16(IEEE80211_FTYPE_DATA | IEEE80211_STYPE_NULLFUNC |
205 IEEE80211_FCTL_TODS);
206 if (ps)
207 fc |= cpu_to_le16(IEEE80211_FCTL_PM);
208 hdr->frame_control = fc;
209 memcpy(hdr->addr1, bssid, ETH_ALEN);
210 memcpy(hdr->addr2, aphy->hw->wiphy->perm_addr, ETH_ALEN);
211 memcpy(hdr->addr3, bssid, ETH_ALEN);
213 info = IEEE80211_SKB_CB(skb);
214 memset(info, 0, sizeof(*info));
215 info->flags = IEEE80211_TX_CTL_REQ_TX_STATUS;
216 info->control.vif = vif;
217 info->control.rates[0].idx = 0;
218 info->control.rates[0].count = 4;
219 info->control.rates[1].idx = -1;
221 memset(&txctl, 0, sizeof(struct ath_tx_control));
222 txctl.txq = &sc->tx.txq[sc->tx.hwq_map[WME_AC_VO]];
223 txctl.frame_type = ps ? ATH9K_IFT_PAUSE : ATH9K_IFT_UNPAUSE;
225 if (ath_tx_start(aphy->hw, skb, &txctl) != 0)
226 goto exit;
228 return 0;
229 exit:
230 dev_kfree_skb_any(skb);
231 return -1;
234 static bool __ath9k_wiphy_pausing(struct ath_softc *sc)
236 int i;
237 if (sc->pri_wiphy->state == ATH_WIPHY_PAUSING)
238 return true;
239 for (i = 0; i < sc->num_sec_wiphy; i++) {
240 if (sc->sec_wiphy[i] &&
241 sc->sec_wiphy[i]->state == ATH_WIPHY_PAUSING)
242 return true;
244 return false;
247 static bool ath9k_wiphy_pausing(struct ath_softc *sc)
249 bool ret;
250 spin_lock_bh(&sc->wiphy_lock);
251 ret = __ath9k_wiphy_pausing(sc);
252 spin_unlock_bh(&sc->wiphy_lock);
253 return ret;
256 static bool __ath9k_wiphy_scanning(struct ath_softc *sc)
258 int i;
259 if (sc->pri_wiphy->state == ATH_WIPHY_SCAN)
260 return true;
261 for (i = 0; i < sc->num_sec_wiphy; i++) {
262 if (sc->sec_wiphy[i] &&
263 sc->sec_wiphy[i]->state == ATH_WIPHY_SCAN)
264 return true;
266 return false;
269 bool ath9k_wiphy_scanning(struct ath_softc *sc)
271 bool ret;
272 spin_lock_bh(&sc->wiphy_lock);
273 ret = __ath9k_wiphy_scanning(sc);
274 spin_unlock_bh(&sc->wiphy_lock);
275 return ret;
278 static int __ath9k_wiphy_unpause(struct ath_wiphy *aphy);
280 /* caller must hold wiphy_lock */
281 static void __ath9k_wiphy_unpause_ch(struct ath_wiphy *aphy)
283 if (aphy == NULL)
284 return;
285 if (aphy->chan_idx != aphy->sc->chan_idx)
286 return; /* wiphy not on the selected channel */
287 __ath9k_wiphy_unpause(aphy);
290 static void ath9k_wiphy_unpause_channel(struct ath_softc *sc)
292 int i;
293 spin_lock_bh(&sc->wiphy_lock);
294 __ath9k_wiphy_unpause_ch(sc->pri_wiphy);
295 for (i = 0; i < sc->num_sec_wiphy; i++)
296 __ath9k_wiphy_unpause_ch(sc->sec_wiphy[i]);
297 spin_unlock_bh(&sc->wiphy_lock);
300 void ath9k_wiphy_chan_work(struct work_struct *work)
302 struct ath_softc *sc = container_of(work, struct ath_softc, chan_work);
303 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
304 struct ath_wiphy *aphy = sc->next_wiphy;
306 if (aphy == NULL)
307 return;
310 * All pending interfaces paused; ready to change
311 * channels.
314 /* Change channels */
315 mutex_lock(&sc->mutex);
316 ath9k_update_ichannel(sc, aphy->hw,
317 &sc->sc_ah->channels[sc->chan_idx]);
319 /* sync hw configuration for hw code */
320 common->hw = aphy->hw;
322 ath_update_chainmask(sc, sc->chan_is_ht);
323 if (ath_set_channel(sc, aphy->hw,
324 &sc->sc_ah->channels[sc->chan_idx]) < 0) {
325 printk(KERN_DEBUG "ath9k: Failed to set channel for new "
326 "virtual wiphy\n");
327 mutex_unlock(&sc->mutex);
328 return;
330 mutex_unlock(&sc->mutex);
332 ath9k_wiphy_unpause_channel(sc);
336 * ath9k version of ieee80211_tx_status() for TX frames that are generated
337 * internally in the driver.
339 void ath9k_tx_status(struct ieee80211_hw *hw, struct sk_buff *skb)
341 struct ath_wiphy *aphy = hw->priv;
342 struct ieee80211_tx_info *tx_info = IEEE80211_SKB_CB(skb);
344 if ((tx_info->pad[0] & ATH_TX_INFO_FRAME_TYPE_PAUSE) &&
345 aphy->state == ATH_WIPHY_PAUSING) {
346 if (!(tx_info->flags & IEEE80211_TX_STAT_ACK)) {
347 printk(KERN_DEBUG "ath9k: %s: no ACK for pause "
348 "frame\n", wiphy_name(hw->wiphy));
350 * The AP did not reply; ignore this to allow us to
351 * continue.
354 aphy->state = ATH_WIPHY_PAUSED;
355 if (!ath9k_wiphy_pausing(aphy->sc)) {
357 * Drop from tasklet to work to allow mutex for channel
358 * change.
360 ieee80211_queue_work(aphy->sc->hw,
361 &aphy->sc->chan_work);
365 dev_kfree_skb(skb);
368 static void ath9k_mark_paused(struct ath_wiphy *aphy)
370 struct ath_softc *sc = aphy->sc;
371 aphy->state = ATH_WIPHY_PAUSED;
372 if (!__ath9k_wiphy_pausing(sc))
373 ieee80211_queue_work(sc->hw, &sc->chan_work);
376 static void ath9k_pause_iter(void *data, u8 *mac, struct ieee80211_vif *vif)
378 struct ath_wiphy *aphy = data;
379 struct ath_vif *avp = (void *) vif->drv_priv;
381 switch (vif->type) {
382 case NL80211_IFTYPE_STATION:
383 if (!vif->bss_conf.assoc) {
384 ath9k_mark_paused(aphy);
385 break;
387 /* TODO: could avoid this if already in PS mode */
388 if (ath9k_send_nullfunc(aphy, vif, avp->bssid, 1)) {
389 printk(KERN_DEBUG "%s: failed to send PS nullfunc\n",
390 __func__);
391 ath9k_mark_paused(aphy);
393 break;
394 case NL80211_IFTYPE_AP:
395 /* Beacon transmission is paused by aphy->state change */
396 ath9k_mark_paused(aphy);
397 break;
398 default:
399 break;
403 /* caller must hold wiphy_lock */
404 static int __ath9k_wiphy_pause(struct ath_wiphy *aphy)
406 ieee80211_stop_queues(aphy->hw);
407 aphy->state = ATH_WIPHY_PAUSING;
409 * TODO: handle PAUSING->PAUSED for the case where there are multiple
410 * active vifs (now we do it on the first vif getting ready; should be
411 * on the last)
413 ieee80211_iterate_active_interfaces_atomic(aphy->hw, ath9k_pause_iter,
414 aphy);
415 return 0;
418 int ath9k_wiphy_pause(struct ath_wiphy *aphy)
420 int ret;
421 spin_lock_bh(&aphy->sc->wiphy_lock);
422 ret = __ath9k_wiphy_pause(aphy);
423 spin_unlock_bh(&aphy->sc->wiphy_lock);
424 return ret;
427 static void ath9k_unpause_iter(void *data, u8 *mac, struct ieee80211_vif *vif)
429 struct ath_wiphy *aphy = data;
430 struct ath_vif *avp = (void *) vif->drv_priv;
432 switch (vif->type) {
433 case NL80211_IFTYPE_STATION:
434 if (!vif->bss_conf.assoc)
435 break;
436 ath9k_send_nullfunc(aphy, vif, avp->bssid, 0);
437 break;
438 case NL80211_IFTYPE_AP:
439 /* Beacon transmission is re-enabled by aphy->state change */
440 break;
441 default:
442 break;
446 /* caller must hold wiphy_lock */
447 static int __ath9k_wiphy_unpause(struct ath_wiphy *aphy)
449 ieee80211_iterate_active_interfaces_atomic(aphy->hw,
450 ath9k_unpause_iter, aphy);
451 aphy->state = ATH_WIPHY_ACTIVE;
452 ieee80211_wake_queues(aphy->hw);
453 return 0;
456 int ath9k_wiphy_unpause(struct ath_wiphy *aphy)
458 int ret;
459 spin_lock_bh(&aphy->sc->wiphy_lock);
460 ret = __ath9k_wiphy_unpause(aphy);
461 spin_unlock_bh(&aphy->sc->wiphy_lock);
462 return ret;
465 static void __ath9k_wiphy_mark_all_paused(struct ath_softc *sc)
467 int i;
468 if (sc->pri_wiphy->state != ATH_WIPHY_INACTIVE)
469 sc->pri_wiphy->state = ATH_WIPHY_PAUSED;
470 for (i = 0; i < sc->num_sec_wiphy; i++) {
471 if (sc->sec_wiphy[i] &&
472 sc->sec_wiphy[i]->state != ATH_WIPHY_INACTIVE)
473 sc->sec_wiphy[i]->state = ATH_WIPHY_PAUSED;
477 /* caller must hold wiphy_lock */
478 static void __ath9k_wiphy_pause_all(struct ath_softc *sc)
480 int i;
481 if (sc->pri_wiphy->state == ATH_WIPHY_ACTIVE)
482 __ath9k_wiphy_pause(sc->pri_wiphy);
483 for (i = 0; i < sc->num_sec_wiphy; i++) {
484 if (sc->sec_wiphy[i] &&
485 sc->sec_wiphy[i]->state == ATH_WIPHY_ACTIVE)
486 __ath9k_wiphy_pause(sc->sec_wiphy[i]);
490 int ath9k_wiphy_select(struct ath_wiphy *aphy)
492 struct ath_softc *sc = aphy->sc;
493 bool now;
495 spin_lock_bh(&sc->wiphy_lock);
496 if (__ath9k_wiphy_scanning(sc)) {
498 * For now, we are using mac80211 sw scan and it expects to
499 * have full control over channel changes, so avoid wiphy
500 * scheduling during a scan. This could be optimized if the
501 * scanning control were moved into the driver.
503 spin_unlock_bh(&sc->wiphy_lock);
504 return -EBUSY;
506 if (__ath9k_wiphy_pausing(sc)) {
507 if (sc->wiphy_select_failures == 0)
508 sc->wiphy_select_first_fail = jiffies;
509 sc->wiphy_select_failures++;
510 if (time_after(jiffies, sc->wiphy_select_first_fail + HZ / 2))
512 printk(KERN_DEBUG "ath9k: Previous wiphy select timed "
513 "out; disable/enable hw to recover\n");
514 __ath9k_wiphy_mark_all_paused(sc);
515 spin_unlock_bh(&sc->wiphy_lock);
516 ath_radio_disable(sc, aphy->hw);
517 ath_radio_enable(sc, aphy->hw);
518 /* Only the primary wiphy hw is used for queuing work */
519 ieee80211_queue_work(aphy->sc->hw,
520 &aphy->sc->chan_work);
521 return -EBUSY; /* previous select still in progress */
523 spin_unlock_bh(&sc->wiphy_lock);
524 return -EBUSY; /* previous select still in progress */
526 sc->wiphy_select_failures = 0;
528 /* Store the new channel */
529 sc->chan_idx = aphy->chan_idx;
530 sc->chan_is_ht = aphy->chan_is_ht;
531 sc->next_wiphy = aphy;
533 __ath9k_wiphy_pause_all(sc);
534 now = !__ath9k_wiphy_pausing(aphy->sc);
535 spin_unlock_bh(&sc->wiphy_lock);
537 if (now) {
538 /* Ready to request channel change immediately */
539 ieee80211_queue_work(aphy->sc->hw, &aphy->sc->chan_work);
543 * wiphys will be unpaused in ath9k_tx_status() once channel has been
544 * changed if any wiphy needs time to become paused.
547 return 0;
550 bool ath9k_wiphy_started(struct ath_softc *sc)
552 int i;
553 spin_lock_bh(&sc->wiphy_lock);
554 if (sc->pri_wiphy->state != ATH_WIPHY_INACTIVE) {
555 spin_unlock_bh(&sc->wiphy_lock);
556 return true;
558 for (i = 0; i < sc->num_sec_wiphy; i++) {
559 if (sc->sec_wiphy[i] &&
560 sc->sec_wiphy[i]->state != ATH_WIPHY_INACTIVE) {
561 spin_unlock_bh(&sc->wiphy_lock);
562 return true;
565 spin_unlock_bh(&sc->wiphy_lock);
566 return false;
569 static void ath9k_wiphy_pause_chan(struct ath_wiphy *aphy,
570 struct ath_wiphy *selected)
572 if (selected->state == ATH_WIPHY_SCAN) {
573 if (aphy == selected)
574 return;
576 * Pause all other wiphys for the duration of the scan even if
577 * they are on the current channel now.
579 } else if (aphy->chan_idx == selected->chan_idx)
580 return;
581 aphy->state = ATH_WIPHY_PAUSED;
582 ieee80211_stop_queues(aphy->hw);
585 void ath9k_wiphy_pause_all_forced(struct ath_softc *sc,
586 struct ath_wiphy *selected)
588 int i;
589 spin_lock_bh(&sc->wiphy_lock);
590 if (sc->pri_wiphy->state == ATH_WIPHY_ACTIVE)
591 ath9k_wiphy_pause_chan(sc->pri_wiphy, selected);
592 for (i = 0; i < sc->num_sec_wiphy; i++) {
593 if (sc->sec_wiphy[i] &&
594 sc->sec_wiphy[i]->state == ATH_WIPHY_ACTIVE)
595 ath9k_wiphy_pause_chan(sc->sec_wiphy[i], selected);
597 spin_unlock_bh(&sc->wiphy_lock);
600 void ath9k_wiphy_work(struct work_struct *work)
602 struct ath_softc *sc = container_of(work, struct ath_softc,
603 wiphy_work.work);
604 struct ath_wiphy *aphy = NULL;
605 bool first = true;
607 spin_lock_bh(&sc->wiphy_lock);
609 if (sc->wiphy_scheduler_int == 0) {
610 /* wiphy scheduler is disabled */
611 spin_unlock_bh(&sc->wiphy_lock);
612 return;
615 try_again:
616 sc->wiphy_scheduler_index++;
617 while (sc->wiphy_scheduler_index <= sc->num_sec_wiphy) {
618 aphy = sc->sec_wiphy[sc->wiphy_scheduler_index - 1];
619 if (aphy && aphy->state != ATH_WIPHY_INACTIVE)
620 break;
622 sc->wiphy_scheduler_index++;
623 aphy = NULL;
625 if (aphy == NULL) {
626 sc->wiphy_scheduler_index = 0;
627 if (sc->pri_wiphy->state == ATH_WIPHY_INACTIVE) {
628 if (first) {
629 first = false;
630 goto try_again;
632 /* No wiphy is ready to be scheduled */
633 } else
634 aphy = sc->pri_wiphy;
637 spin_unlock_bh(&sc->wiphy_lock);
639 if (aphy &&
640 aphy->state != ATH_WIPHY_ACTIVE && aphy->state != ATH_WIPHY_SCAN &&
641 ath9k_wiphy_select(aphy)) {
642 printk(KERN_DEBUG "ath9k: Failed to schedule virtual wiphy "
643 "change\n");
646 ieee80211_queue_delayed_work(sc->hw,
647 &sc->wiphy_work,
648 sc->wiphy_scheduler_int);
651 void ath9k_wiphy_set_scheduler(struct ath_softc *sc, unsigned int msec_int)
653 cancel_delayed_work_sync(&sc->wiphy_work);
654 sc->wiphy_scheduler_int = msecs_to_jiffies(msec_int);
655 if (sc->wiphy_scheduler_int)
656 ieee80211_queue_delayed_work(sc->hw, &sc->wiphy_work,
657 sc->wiphy_scheduler_int);
660 /* caller must hold wiphy_lock */
661 bool ath9k_all_wiphys_idle(struct ath_softc *sc)
663 unsigned int i;
664 if (!sc->pri_wiphy->idle)
665 return false;
666 for (i = 0; i < sc->num_sec_wiphy; i++) {
667 struct ath_wiphy *aphy = sc->sec_wiphy[i];
668 if (!aphy)
669 continue;
670 if (!aphy->idle)
671 return false;
673 return true;
676 /* caller must hold wiphy_lock */
677 void ath9k_set_wiphy_idle(struct ath_wiphy *aphy, bool idle)
679 struct ath_softc *sc = aphy->sc;
681 aphy->idle = idle;
682 ath_print(ath9k_hw_common(sc->sc_ah), ATH_DBG_CONFIG,
683 "Marking %s as %s\n",
684 wiphy_name(aphy->hw->wiphy),
685 idle ? "idle" : "not-idle");
687 /* Only bother starting a queue on an active virtual wiphy */
688 bool ath_mac80211_start_queue(struct ath_softc *sc, u16 skb_queue)
690 struct ieee80211_hw *hw = sc->pri_wiphy->hw;
691 unsigned int i;
692 bool txq_started = false;
694 spin_lock_bh(&sc->wiphy_lock);
696 /* Start the primary wiphy */
697 if (sc->pri_wiphy->state == ATH_WIPHY_ACTIVE) {
698 ieee80211_wake_queue(hw, skb_queue);
699 txq_started = true;
700 goto unlock;
703 /* Now start the secondary wiphy queues */
704 for (i = 0; i < sc->num_sec_wiphy; i++) {
705 struct ath_wiphy *aphy = sc->sec_wiphy[i];
706 if (!aphy)
707 continue;
708 if (aphy->state != ATH_WIPHY_ACTIVE)
709 continue;
711 hw = aphy->hw;
712 ieee80211_wake_queue(hw, skb_queue);
713 txq_started = true;
714 break;
717 unlock:
718 spin_unlock_bh(&sc->wiphy_lock);
719 return txq_started;
722 /* Go ahead and propagate information to all virtual wiphys, it won't hurt */
723 void ath_mac80211_stop_queue(struct ath_softc *sc, u16 skb_queue)
725 struct ieee80211_hw *hw = sc->pri_wiphy->hw;
726 unsigned int i;
728 spin_lock_bh(&sc->wiphy_lock);
730 /* Stop the primary wiphy */
731 ieee80211_stop_queue(hw, skb_queue);
733 /* Now stop the secondary wiphy queues */
734 for (i = 0; i < sc->num_sec_wiphy; i++) {
735 struct ath_wiphy *aphy = sc->sec_wiphy[i];
736 if (!aphy)
737 continue;
738 hw = aphy->hw;
739 ieee80211_stop_queue(hw, skb_queue);
741 spin_unlock_bh(&sc->wiphy_lock);