virtual.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720
  1. /*
  2. * Copyright (c) 2008-2009 Atheros Communications Inc.
  3. *
  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.
  7. *
  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.
  15. */
  16. #include <linux/slab.h>
  17. #include "ath9k.h"
  18. struct ath9k_vif_iter_data {
  19. const u8 *hw_macaddr;
  20. u8 mask[ETH_ALEN];
  21. };
  22. static void ath9k_vif_iter(void *data, u8 *mac, struct ieee80211_vif *vif)
  23. {
  24. struct ath9k_vif_iter_data *iter_data = data;
  25. int i;
  26. for (i = 0; i < ETH_ALEN; i++)
  27. iter_data->mask[i] &= ~(iter_data->hw_macaddr[i] ^ mac[i]);
  28. }
  29. void ath9k_set_bssid_mask(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
  30. {
  31. struct ath_wiphy *aphy = hw->priv;
  32. struct ath_softc *sc = aphy->sc;
  33. struct ath_common *common = ath9k_hw_common(sc->sc_ah);
  34. struct ath9k_vif_iter_data iter_data;
  35. int i;
  36. /*
  37. * Use the hardware MAC address as reference, the hardware uses it
  38. * together with the BSSID mask when matching addresses.
  39. */
  40. iter_data.hw_macaddr = common->macaddr;
  41. memset(&iter_data.mask, 0xff, ETH_ALEN);
  42. if (vif)
  43. ath9k_vif_iter(&iter_data, vif->addr, vif);
  44. /* Get list of all active MAC addresses */
  45. spin_lock_bh(&sc->wiphy_lock);
  46. ieee80211_iterate_active_interfaces_atomic(sc->hw, ath9k_vif_iter,
  47. &iter_data);
  48. for (i = 0; i < sc->num_sec_wiphy; i++) {
  49. if (sc->sec_wiphy[i] == NULL)
  50. continue;
  51. ieee80211_iterate_active_interfaces_atomic(
  52. sc->sec_wiphy[i]->hw, ath9k_vif_iter, &iter_data);
  53. }
  54. spin_unlock_bh(&sc->wiphy_lock);
  55. memcpy(common->bssidmask, iter_data.mask, ETH_ALEN);
  56. ath_hw_setbssidmask(common);
  57. }
  58. int ath9k_wiphy_add(struct ath_softc *sc)
  59. {
  60. int i, error;
  61. struct ath_wiphy *aphy;
  62. struct ath_common *common = ath9k_hw_common(sc->sc_ah);
  63. struct ieee80211_hw *hw;
  64. u8 addr[ETH_ALEN];
  65. hw = ieee80211_alloc_hw(sizeof(struct ath_wiphy), &ath9k_ops);
  66. if (hw == NULL)
  67. return -ENOMEM;
  68. spin_lock_bh(&sc->wiphy_lock);
  69. for (i = 0; i < sc->num_sec_wiphy; i++) {
  70. if (sc->sec_wiphy[i] == NULL)
  71. break;
  72. }
  73. if (i == sc->num_sec_wiphy) {
  74. /* No empty slot available; increase array length */
  75. struct ath_wiphy **n;
  76. n = krealloc(sc->sec_wiphy,
  77. (sc->num_sec_wiphy + 1) *
  78. sizeof(struct ath_wiphy *),
  79. GFP_ATOMIC);
  80. if (n == NULL) {
  81. spin_unlock_bh(&sc->wiphy_lock);
  82. ieee80211_free_hw(hw);
  83. return -ENOMEM;
  84. }
  85. n[i] = NULL;
  86. sc->sec_wiphy = n;
  87. sc->num_sec_wiphy++;
  88. }
  89. SET_IEEE80211_DEV(hw, sc->dev);
  90. aphy = hw->priv;
  91. aphy->sc = sc;
  92. aphy->hw = hw;
  93. sc->sec_wiphy[i] = aphy;
  94. aphy->last_rssi = ATH_RSSI_DUMMY_MARKER;
  95. spin_unlock_bh(&sc->wiphy_lock);
  96. memcpy(addr, common->macaddr, ETH_ALEN);
  97. addr[0] |= 0x02; /* Locally managed address */
  98. /*
  99. * XOR virtual wiphy index into the least significant bits to generate
  100. * a different MAC address for each virtual wiphy.
  101. */
  102. addr[5] ^= i & 0xff;
  103. addr[4] ^= (i & 0xff00) >> 8;
  104. addr[3] ^= (i & 0xff0000) >> 16;
  105. SET_IEEE80211_PERM_ADDR(hw, addr);
  106. ath9k_set_hw_capab(sc, hw);
  107. error = ieee80211_register_hw(hw);
  108. if (error == 0) {
  109. /* Make sure wiphy scheduler is started (if enabled) */
  110. ath9k_wiphy_set_scheduler(sc, sc->wiphy_scheduler_int);
  111. }
  112. return error;
  113. }
  114. int ath9k_wiphy_del(struct ath_wiphy *aphy)
  115. {
  116. struct ath_softc *sc = aphy->sc;
  117. int i;
  118. spin_lock_bh(&sc->wiphy_lock);
  119. for (i = 0; i < sc->num_sec_wiphy; i++) {
  120. if (aphy == sc->sec_wiphy[i]) {
  121. sc->sec_wiphy[i] = NULL;
  122. spin_unlock_bh(&sc->wiphy_lock);
  123. ieee80211_unregister_hw(aphy->hw);
  124. ieee80211_free_hw(aphy->hw);
  125. return 0;
  126. }
  127. }
  128. spin_unlock_bh(&sc->wiphy_lock);
  129. return -ENOENT;
  130. }
  131. static int ath9k_send_nullfunc(struct ath_wiphy *aphy,
  132. struct ieee80211_vif *vif, const u8 *bssid,
  133. int ps)
  134. {
  135. struct ath_softc *sc = aphy->sc;
  136. struct ath_tx_control txctl;
  137. struct sk_buff *skb;
  138. struct ieee80211_hdr *hdr;
  139. __le16 fc;
  140. struct ieee80211_tx_info *info;
  141. skb = dev_alloc_skb(24);
  142. if (skb == NULL)
  143. return -ENOMEM;
  144. hdr = (struct ieee80211_hdr *) skb_put(skb, 24);
  145. memset(hdr, 0, 24);
  146. fc = cpu_to_le16(IEEE80211_FTYPE_DATA | IEEE80211_STYPE_NULLFUNC |
  147. IEEE80211_FCTL_TODS);
  148. if (ps)
  149. fc |= cpu_to_le16(IEEE80211_FCTL_PM);
  150. hdr->frame_control = fc;
  151. memcpy(hdr->addr1, bssid, ETH_ALEN);
  152. memcpy(hdr->addr2, aphy->hw->wiphy->perm_addr, ETH_ALEN);
  153. memcpy(hdr->addr3, bssid, ETH_ALEN);
  154. info = IEEE80211_SKB_CB(skb);
  155. memset(info, 0, sizeof(*info));
  156. info->flags = IEEE80211_TX_CTL_REQ_TX_STATUS;
  157. info->control.vif = vif;
  158. info->control.rates[0].idx = 0;
  159. info->control.rates[0].count = 4;
  160. info->control.rates[1].idx = -1;
  161. memset(&txctl, 0, sizeof(struct ath_tx_control));
  162. txctl.txq = &sc->tx.txq[sc->tx.hwq_map[WME_AC_VO]];
  163. txctl.frame_type = ps ? ATH9K_IFT_PAUSE : ATH9K_IFT_UNPAUSE;
  164. if (ath_tx_start(aphy->hw, skb, &txctl) != 0)
  165. goto exit;
  166. return 0;
  167. exit:
  168. dev_kfree_skb_any(skb);
  169. return -1;
  170. }
  171. static bool __ath9k_wiphy_pausing(struct ath_softc *sc)
  172. {
  173. int i;
  174. if (sc->pri_wiphy->state == ATH_WIPHY_PAUSING)
  175. return true;
  176. for (i = 0; i < sc->num_sec_wiphy; i++) {
  177. if (sc->sec_wiphy[i] &&
  178. sc->sec_wiphy[i]->state == ATH_WIPHY_PAUSING)
  179. return true;
  180. }
  181. return false;
  182. }
  183. static bool ath9k_wiphy_pausing(struct ath_softc *sc)
  184. {
  185. bool ret;
  186. spin_lock_bh(&sc->wiphy_lock);
  187. ret = __ath9k_wiphy_pausing(sc);
  188. spin_unlock_bh(&sc->wiphy_lock);
  189. return ret;
  190. }
  191. static bool __ath9k_wiphy_scanning(struct ath_softc *sc)
  192. {
  193. int i;
  194. if (sc->pri_wiphy->state == ATH_WIPHY_SCAN)
  195. return true;
  196. for (i = 0; i < sc->num_sec_wiphy; i++) {
  197. if (sc->sec_wiphy[i] &&
  198. sc->sec_wiphy[i]->state == ATH_WIPHY_SCAN)
  199. return true;
  200. }
  201. return false;
  202. }
  203. bool ath9k_wiphy_scanning(struct ath_softc *sc)
  204. {
  205. bool ret;
  206. spin_lock_bh(&sc->wiphy_lock);
  207. ret = __ath9k_wiphy_scanning(sc);
  208. spin_unlock_bh(&sc->wiphy_lock);
  209. return ret;
  210. }
  211. static int __ath9k_wiphy_unpause(struct ath_wiphy *aphy);
  212. /* caller must hold wiphy_lock */
  213. static void __ath9k_wiphy_unpause_ch(struct ath_wiphy *aphy)
  214. {
  215. if (aphy == NULL)
  216. return;
  217. if (aphy->chan_idx != aphy->sc->chan_idx)
  218. return; /* wiphy not on the selected channel */
  219. __ath9k_wiphy_unpause(aphy);
  220. }
  221. static void ath9k_wiphy_unpause_channel(struct ath_softc *sc)
  222. {
  223. int i;
  224. spin_lock_bh(&sc->wiphy_lock);
  225. __ath9k_wiphy_unpause_ch(sc->pri_wiphy);
  226. for (i = 0; i < sc->num_sec_wiphy; i++)
  227. __ath9k_wiphy_unpause_ch(sc->sec_wiphy[i]);
  228. spin_unlock_bh(&sc->wiphy_lock);
  229. }
  230. void ath9k_wiphy_chan_work(struct work_struct *work)
  231. {
  232. struct ath_softc *sc = container_of(work, struct ath_softc, chan_work);
  233. struct ath_common *common = ath9k_hw_common(sc->sc_ah);
  234. struct ath_wiphy *aphy = sc->next_wiphy;
  235. if (aphy == NULL)
  236. return;
  237. /*
  238. * All pending interfaces paused; ready to change
  239. * channels.
  240. */
  241. /* Change channels */
  242. mutex_lock(&sc->mutex);
  243. /* XXX: remove me eventually */
  244. ath9k_update_ichannel(sc, aphy->hw,
  245. &sc->sc_ah->channels[sc->chan_idx]);
  246. /* sync hw configuration for hw code */
  247. common->hw = aphy->hw;
  248. ath_update_chainmask(sc, sc->chan_is_ht);
  249. if (ath_set_channel(sc, aphy->hw,
  250. &sc->sc_ah->channels[sc->chan_idx]) < 0) {
  251. printk(KERN_DEBUG "ath9k: Failed to set channel for new "
  252. "virtual wiphy\n");
  253. mutex_unlock(&sc->mutex);
  254. return;
  255. }
  256. mutex_unlock(&sc->mutex);
  257. ath9k_wiphy_unpause_channel(sc);
  258. }
  259. /*
  260. * ath9k version of ieee80211_tx_status() for TX frames that are generated
  261. * internally in the driver.
  262. */
  263. void ath9k_tx_status(struct ieee80211_hw *hw, struct sk_buff *skb)
  264. {
  265. struct ath_wiphy *aphy = hw->priv;
  266. struct ieee80211_tx_info *tx_info = IEEE80211_SKB_CB(skb);
  267. if ((tx_info->pad[0] & ATH_TX_INFO_FRAME_TYPE_PAUSE) &&
  268. aphy->state == ATH_WIPHY_PAUSING) {
  269. if (!(tx_info->flags & IEEE80211_TX_STAT_ACK)) {
  270. printk(KERN_DEBUG "ath9k: %s: no ACK for pause "
  271. "frame\n", wiphy_name(hw->wiphy));
  272. /*
  273. * The AP did not reply; ignore this to allow us to
  274. * continue.
  275. */
  276. }
  277. aphy->state = ATH_WIPHY_PAUSED;
  278. if (!ath9k_wiphy_pausing(aphy->sc)) {
  279. /*
  280. * Drop from tasklet to work to allow mutex for channel
  281. * change.
  282. */
  283. ieee80211_queue_work(aphy->sc->hw,
  284. &aphy->sc->chan_work);
  285. }
  286. }
  287. dev_kfree_skb(skb);
  288. }
  289. static void ath9k_mark_paused(struct ath_wiphy *aphy)
  290. {
  291. struct ath_softc *sc = aphy->sc;
  292. aphy->state = ATH_WIPHY_PAUSED;
  293. if (!__ath9k_wiphy_pausing(sc))
  294. ieee80211_queue_work(sc->hw, &sc->chan_work);
  295. }
  296. static void ath9k_pause_iter(void *data, u8 *mac, struct ieee80211_vif *vif)
  297. {
  298. struct ath_wiphy *aphy = data;
  299. struct ath_vif *avp = (void *) vif->drv_priv;
  300. switch (vif->type) {
  301. case NL80211_IFTYPE_STATION:
  302. if (!vif->bss_conf.assoc) {
  303. ath9k_mark_paused(aphy);
  304. break;
  305. }
  306. /* TODO: could avoid this if already in PS mode */
  307. if (ath9k_send_nullfunc(aphy, vif, avp->bssid, 1)) {
  308. printk(KERN_DEBUG "%s: failed to send PS nullfunc\n",
  309. __func__);
  310. ath9k_mark_paused(aphy);
  311. }
  312. break;
  313. case NL80211_IFTYPE_AP:
  314. /* Beacon transmission is paused by aphy->state change */
  315. ath9k_mark_paused(aphy);
  316. break;
  317. default:
  318. break;
  319. }
  320. }
  321. /* caller must hold wiphy_lock */
  322. static int __ath9k_wiphy_pause(struct ath_wiphy *aphy)
  323. {
  324. ieee80211_stop_queues(aphy->hw);
  325. aphy->state = ATH_WIPHY_PAUSING;
  326. /*
  327. * TODO: handle PAUSING->PAUSED for the case where there are multiple
  328. * active vifs (now we do it on the first vif getting ready; should be
  329. * on the last)
  330. */
  331. ieee80211_iterate_active_interfaces_atomic(aphy->hw, ath9k_pause_iter,
  332. aphy);
  333. return 0;
  334. }
  335. int ath9k_wiphy_pause(struct ath_wiphy *aphy)
  336. {
  337. int ret;
  338. spin_lock_bh(&aphy->sc->wiphy_lock);
  339. ret = __ath9k_wiphy_pause(aphy);
  340. spin_unlock_bh(&aphy->sc->wiphy_lock);
  341. return ret;
  342. }
  343. static void ath9k_unpause_iter(void *data, u8 *mac, struct ieee80211_vif *vif)
  344. {
  345. struct ath_wiphy *aphy = data;
  346. struct ath_vif *avp = (void *) vif->drv_priv;
  347. switch (vif->type) {
  348. case NL80211_IFTYPE_STATION:
  349. if (!vif->bss_conf.assoc)
  350. break;
  351. ath9k_send_nullfunc(aphy, vif, avp->bssid, 0);
  352. break;
  353. case NL80211_IFTYPE_AP:
  354. /* Beacon transmission is re-enabled by aphy->state change */
  355. break;
  356. default:
  357. break;
  358. }
  359. }
  360. /* caller must hold wiphy_lock */
  361. static int __ath9k_wiphy_unpause(struct ath_wiphy *aphy)
  362. {
  363. ieee80211_iterate_active_interfaces_atomic(aphy->hw,
  364. ath9k_unpause_iter, aphy);
  365. aphy->state = ATH_WIPHY_ACTIVE;
  366. ieee80211_wake_queues(aphy->hw);
  367. return 0;
  368. }
  369. int ath9k_wiphy_unpause(struct ath_wiphy *aphy)
  370. {
  371. int ret;
  372. spin_lock_bh(&aphy->sc->wiphy_lock);
  373. ret = __ath9k_wiphy_unpause(aphy);
  374. spin_unlock_bh(&aphy->sc->wiphy_lock);
  375. return ret;
  376. }
  377. static void __ath9k_wiphy_mark_all_paused(struct ath_softc *sc)
  378. {
  379. int i;
  380. if (sc->pri_wiphy->state != ATH_WIPHY_INACTIVE)
  381. sc->pri_wiphy->state = ATH_WIPHY_PAUSED;
  382. for (i = 0; i < sc->num_sec_wiphy; i++) {
  383. if (sc->sec_wiphy[i] &&
  384. sc->sec_wiphy[i]->state != ATH_WIPHY_INACTIVE)
  385. sc->sec_wiphy[i]->state = ATH_WIPHY_PAUSED;
  386. }
  387. }
  388. /* caller must hold wiphy_lock */
  389. static void __ath9k_wiphy_pause_all(struct ath_softc *sc)
  390. {
  391. int i;
  392. if (sc->pri_wiphy->state == ATH_WIPHY_ACTIVE)
  393. __ath9k_wiphy_pause(sc->pri_wiphy);
  394. for (i = 0; i < sc->num_sec_wiphy; i++) {
  395. if (sc->sec_wiphy[i] &&
  396. sc->sec_wiphy[i]->state == ATH_WIPHY_ACTIVE)
  397. __ath9k_wiphy_pause(sc->sec_wiphy[i]);
  398. }
  399. }
  400. int ath9k_wiphy_select(struct ath_wiphy *aphy)
  401. {
  402. struct ath_softc *sc = aphy->sc;
  403. bool now;
  404. spin_lock_bh(&sc->wiphy_lock);
  405. if (__ath9k_wiphy_scanning(sc)) {
  406. /*
  407. * For now, we are using mac80211 sw scan and it expects to
  408. * have full control over channel changes, so avoid wiphy
  409. * scheduling during a scan. This could be optimized if the
  410. * scanning control were moved into the driver.
  411. */
  412. spin_unlock_bh(&sc->wiphy_lock);
  413. return -EBUSY;
  414. }
  415. if (__ath9k_wiphy_pausing(sc)) {
  416. if (sc->wiphy_select_failures == 0)
  417. sc->wiphy_select_first_fail = jiffies;
  418. sc->wiphy_select_failures++;
  419. if (time_after(jiffies, sc->wiphy_select_first_fail + HZ / 2))
  420. {
  421. printk(KERN_DEBUG "ath9k: Previous wiphy select timed "
  422. "out; disable/enable hw to recover\n");
  423. __ath9k_wiphy_mark_all_paused(sc);
  424. /*
  425. * TODO: this workaround to fix hardware is unlikely to
  426. * be specific to virtual wiphy changes. It can happen
  427. * on normal channel change, too, and as such, this
  428. * should really be made more generic. For example,
  429. * tricker radio disable/enable on GTT interrupt burst
  430. * (say, 10 GTT interrupts received without any TX
  431. * frame being completed)
  432. */
  433. spin_unlock_bh(&sc->wiphy_lock);
  434. ath_radio_disable(sc, aphy->hw);
  435. ath_radio_enable(sc, aphy->hw);
  436. /* Only the primary wiphy hw is used for queuing work */
  437. ieee80211_queue_work(aphy->sc->hw,
  438. &aphy->sc->chan_work);
  439. return -EBUSY; /* previous select still in progress */
  440. }
  441. spin_unlock_bh(&sc->wiphy_lock);
  442. return -EBUSY; /* previous select still in progress */
  443. }
  444. sc->wiphy_select_failures = 0;
  445. /* Store the new channel */
  446. sc->chan_idx = aphy->chan_idx;
  447. sc->chan_is_ht = aphy->chan_is_ht;
  448. sc->next_wiphy = aphy;
  449. __ath9k_wiphy_pause_all(sc);
  450. now = !__ath9k_wiphy_pausing(aphy->sc);
  451. spin_unlock_bh(&sc->wiphy_lock);
  452. if (now) {
  453. /* Ready to request channel change immediately */
  454. ieee80211_queue_work(aphy->sc->hw, &aphy->sc->chan_work);
  455. }
  456. /*
  457. * wiphys will be unpaused in ath9k_tx_status() once channel has been
  458. * changed if any wiphy needs time to become paused.
  459. */
  460. return 0;
  461. }
  462. bool ath9k_wiphy_started(struct ath_softc *sc)
  463. {
  464. int i;
  465. spin_lock_bh(&sc->wiphy_lock);
  466. if (sc->pri_wiphy->state != ATH_WIPHY_INACTIVE) {
  467. spin_unlock_bh(&sc->wiphy_lock);
  468. return true;
  469. }
  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. spin_unlock_bh(&sc->wiphy_lock);
  474. return true;
  475. }
  476. }
  477. spin_unlock_bh(&sc->wiphy_lock);
  478. return false;
  479. }
  480. static void ath9k_wiphy_pause_chan(struct ath_wiphy *aphy,
  481. struct ath_wiphy *selected)
  482. {
  483. if (selected->state == ATH_WIPHY_SCAN) {
  484. if (aphy == selected)
  485. return;
  486. /*
  487. * Pause all other wiphys for the duration of the scan even if
  488. * they are on the current channel now.
  489. */
  490. } else if (aphy->chan_idx == selected->chan_idx)
  491. return;
  492. aphy->state = ATH_WIPHY_PAUSED;
  493. ieee80211_stop_queues(aphy->hw);
  494. }
  495. void ath9k_wiphy_pause_all_forced(struct ath_softc *sc,
  496. struct ath_wiphy *selected)
  497. {
  498. int i;
  499. spin_lock_bh(&sc->wiphy_lock);
  500. if (sc->pri_wiphy->state == ATH_WIPHY_ACTIVE)
  501. ath9k_wiphy_pause_chan(sc->pri_wiphy, selected);
  502. for (i = 0; i < sc->num_sec_wiphy; i++) {
  503. if (sc->sec_wiphy[i] &&
  504. sc->sec_wiphy[i]->state == ATH_WIPHY_ACTIVE)
  505. ath9k_wiphy_pause_chan(sc->sec_wiphy[i], selected);
  506. }
  507. spin_unlock_bh(&sc->wiphy_lock);
  508. }
  509. void ath9k_wiphy_work(struct work_struct *work)
  510. {
  511. struct ath_softc *sc = container_of(work, struct ath_softc,
  512. wiphy_work.work);
  513. struct ath_wiphy *aphy = NULL;
  514. bool first = true;
  515. spin_lock_bh(&sc->wiphy_lock);
  516. if (sc->wiphy_scheduler_int == 0) {
  517. /* wiphy scheduler is disabled */
  518. spin_unlock_bh(&sc->wiphy_lock);
  519. return;
  520. }
  521. try_again:
  522. sc->wiphy_scheduler_index++;
  523. while (sc->wiphy_scheduler_index <= sc->num_sec_wiphy) {
  524. aphy = sc->sec_wiphy[sc->wiphy_scheduler_index - 1];
  525. if (aphy && aphy->state != ATH_WIPHY_INACTIVE)
  526. break;
  527. sc->wiphy_scheduler_index++;
  528. aphy = NULL;
  529. }
  530. if (aphy == NULL) {
  531. sc->wiphy_scheduler_index = 0;
  532. if (sc->pri_wiphy->state == ATH_WIPHY_INACTIVE) {
  533. if (first) {
  534. first = false;
  535. goto try_again;
  536. }
  537. /* No wiphy is ready to be scheduled */
  538. } else
  539. aphy = sc->pri_wiphy;
  540. }
  541. spin_unlock_bh(&sc->wiphy_lock);
  542. if (aphy &&
  543. aphy->state != ATH_WIPHY_ACTIVE && aphy->state != ATH_WIPHY_SCAN &&
  544. ath9k_wiphy_select(aphy)) {
  545. printk(KERN_DEBUG "ath9k: Failed to schedule virtual wiphy "
  546. "change\n");
  547. }
  548. ieee80211_queue_delayed_work(sc->hw,
  549. &sc->wiphy_work,
  550. sc->wiphy_scheduler_int);
  551. }
  552. void ath9k_wiphy_set_scheduler(struct ath_softc *sc, unsigned int msec_int)
  553. {
  554. cancel_delayed_work_sync(&sc->wiphy_work);
  555. sc->wiphy_scheduler_int = msecs_to_jiffies(msec_int);
  556. if (sc->wiphy_scheduler_int)
  557. ieee80211_queue_delayed_work(sc->hw, &sc->wiphy_work,
  558. sc->wiphy_scheduler_int);
  559. }
  560. /* caller must hold wiphy_lock */
  561. bool ath9k_all_wiphys_idle(struct ath_softc *sc)
  562. {
  563. unsigned int i;
  564. if (!sc->pri_wiphy->idle)
  565. return false;
  566. for (i = 0; i < sc->num_sec_wiphy; i++) {
  567. struct ath_wiphy *aphy = sc->sec_wiphy[i];
  568. if (!aphy)
  569. continue;
  570. if (!aphy->idle)
  571. return false;
  572. }
  573. return true;
  574. }
  575. /* caller must hold wiphy_lock */
  576. void ath9k_set_wiphy_idle(struct ath_wiphy *aphy, bool idle)
  577. {
  578. struct ath_softc *sc = aphy->sc;
  579. aphy->idle = idle;
  580. ath_print(ath9k_hw_common(sc->sc_ah), ATH_DBG_CONFIG,
  581. "Marking %s as %s\n",
  582. wiphy_name(aphy->hw->wiphy),
  583. idle ? "idle" : "not-idle");
  584. }
  585. /* Only bother starting a queue on an active virtual wiphy */
  586. bool ath_mac80211_start_queue(struct ath_softc *sc, u16 skb_queue)
  587. {
  588. struct ieee80211_hw *hw = sc->pri_wiphy->hw;
  589. unsigned int i;
  590. bool txq_started = false;
  591. spin_lock_bh(&sc->wiphy_lock);
  592. /* Start the primary wiphy */
  593. if (sc->pri_wiphy->state == ATH_WIPHY_ACTIVE) {
  594. ieee80211_wake_queue(hw, skb_queue);
  595. txq_started = true;
  596. goto unlock;
  597. }
  598. /* Now start the secondary wiphy queues */
  599. for (i = 0; i < sc->num_sec_wiphy; i++) {
  600. struct ath_wiphy *aphy = sc->sec_wiphy[i];
  601. if (!aphy)
  602. continue;
  603. if (aphy->state != ATH_WIPHY_ACTIVE)
  604. continue;
  605. hw = aphy->hw;
  606. ieee80211_wake_queue(hw, skb_queue);
  607. txq_started = true;
  608. break;
  609. }
  610. unlock:
  611. spin_unlock_bh(&sc->wiphy_lock);
  612. return txq_started;
  613. }
  614. /* Go ahead and propagate information to all virtual wiphys, it won't hurt */
  615. void ath_mac80211_stop_queue(struct ath_softc *sc, u16 skb_queue)
  616. {
  617. struct ieee80211_hw *hw = sc->pri_wiphy->hw;
  618. unsigned int i;
  619. spin_lock_bh(&sc->wiphy_lock);
  620. /* Stop the primary wiphy */
  621. ieee80211_stop_queue(hw, skb_queue);
  622. /* Now stop the secondary wiphy queues */
  623. for (i = 0; i < sc->num_sec_wiphy; i++) {
  624. struct ath_wiphy *aphy = sc->sec_wiphy[i];
  625. if (!aphy)
  626. continue;
  627. hw = aphy->hw;
  628. ieee80211_stop_queue(hw, skb_queue);
  629. }
  630. spin_unlock_bh(&sc->wiphy_lock);
  631. }