virtual.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717
  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_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. if (ath_set_channel(sc, aphy->hw,
  249. &sc->sc_ah->channels[sc->chan_idx]) < 0) {
  250. printk(KERN_DEBUG "ath9k: Failed to set channel for new "
  251. "virtual wiphy\n");
  252. mutex_unlock(&sc->mutex);
  253. return;
  254. }
  255. mutex_unlock(&sc->mutex);
  256. ath9k_wiphy_unpause_channel(sc);
  257. }
  258. /*
  259. * ath9k version of ieee80211_tx_status() for TX frames that are generated
  260. * internally in the driver.
  261. */
  262. void ath9k_tx_status(struct ieee80211_hw *hw, struct sk_buff *skb, int ftype)
  263. {
  264. struct ath_wiphy *aphy = hw->priv;
  265. struct ieee80211_tx_info *tx_info = IEEE80211_SKB_CB(skb);
  266. if (ftype == ATH9K_IFT_PAUSE && aphy->state == ATH_WIPHY_PAUSING) {
  267. if (!(tx_info->flags & IEEE80211_TX_STAT_ACK)) {
  268. printk(KERN_DEBUG "ath9k: %s: no ACK for pause "
  269. "frame\n", wiphy_name(hw->wiphy));
  270. /*
  271. * The AP did not reply; ignore this to allow us to
  272. * continue.
  273. */
  274. }
  275. aphy->state = ATH_WIPHY_PAUSED;
  276. if (!ath9k_wiphy_pausing(aphy->sc)) {
  277. /*
  278. * Drop from tasklet to work to allow mutex for channel
  279. * change.
  280. */
  281. ieee80211_queue_work(aphy->sc->hw,
  282. &aphy->sc->chan_work);
  283. }
  284. }
  285. dev_kfree_skb(skb);
  286. }
  287. static void ath9k_mark_paused(struct ath_wiphy *aphy)
  288. {
  289. struct ath_softc *sc = aphy->sc;
  290. aphy->state = ATH_WIPHY_PAUSED;
  291. if (!__ath9k_wiphy_pausing(sc))
  292. ieee80211_queue_work(sc->hw, &sc->chan_work);
  293. }
  294. static void ath9k_pause_iter(void *data, u8 *mac, struct ieee80211_vif *vif)
  295. {
  296. struct ath_wiphy *aphy = data;
  297. struct ath_vif *avp = (void *) vif->drv_priv;
  298. switch (vif->type) {
  299. case NL80211_IFTYPE_STATION:
  300. if (!vif->bss_conf.assoc) {
  301. ath9k_mark_paused(aphy);
  302. break;
  303. }
  304. /* TODO: could avoid this if already in PS mode */
  305. if (ath9k_send_nullfunc(aphy, vif, avp->bssid, 1)) {
  306. printk(KERN_DEBUG "%s: failed to send PS nullfunc\n",
  307. __func__);
  308. ath9k_mark_paused(aphy);
  309. }
  310. break;
  311. case NL80211_IFTYPE_AP:
  312. /* Beacon transmission is paused by aphy->state change */
  313. ath9k_mark_paused(aphy);
  314. break;
  315. default:
  316. break;
  317. }
  318. }
  319. /* caller must hold wiphy_lock */
  320. static int __ath9k_wiphy_pause(struct ath_wiphy *aphy)
  321. {
  322. ieee80211_stop_queues(aphy->hw);
  323. aphy->state = ATH_WIPHY_PAUSING;
  324. /*
  325. * TODO: handle PAUSING->PAUSED for the case where there are multiple
  326. * active vifs (now we do it on the first vif getting ready; should be
  327. * on the last)
  328. */
  329. ieee80211_iterate_active_interfaces_atomic(aphy->hw, ath9k_pause_iter,
  330. aphy);
  331. return 0;
  332. }
  333. int ath9k_wiphy_pause(struct ath_wiphy *aphy)
  334. {
  335. int ret;
  336. spin_lock_bh(&aphy->sc->wiphy_lock);
  337. ret = __ath9k_wiphy_pause(aphy);
  338. spin_unlock_bh(&aphy->sc->wiphy_lock);
  339. return ret;
  340. }
  341. static void ath9k_unpause_iter(void *data, u8 *mac, struct ieee80211_vif *vif)
  342. {
  343. struct ath_wiphy *aphy = data;
  344. struct ath_vif *avp = (void *) vif->drv_priv;
  345. switch (vif->type) {
  346. case NL80211_IFTYPE_STATION:
  347. if (!vif->bss_conf.assoc)
  348. break;
  349. ath9k_send_nullfunc(aphy, vif, avp->bssid, 0);
  350. break;
  351. case NL80211_IFTYPE_AP:
  352. /* Beacon transmission is re-enabled by aphy->state change */
  353. break;
  354. default:
  355. break;
  356. }
  357. }
  358. /* caller must hold wiphy_lock */
  359. static int __ath9k_wiphy_unpause(struct ath_wiphy *aphy)
  360. {
  361. ieee80211_iterate_active_interfaces_atomic(aphy->hw,
  362. ath9k_unpause_iter, aphy);
  363. aphy->state = ATH_WIPHY_ACTIVE;
  364. ieee80211_wake_queues(aphy->hw);
  365. return 0;
  366. }
  367. int ath9k_wiphy_unpause(struct ath_wiphy *aphy)
  368. {
  369. int ret;
  370. spin_lock_bh(&aphy->sc->wiphy_lock);
  371. ret = __ath9k_wiphy_unpause(aphy);
  372. spin_unlock_bh(&aphy->sc->wiphy_lock);
  373. return ret;
  374. }
  375. static void __ath9k_wiphy_mark_all_paused(struct ath_softc *sc)
  376. {
  377. int i;
  378. if (sc->pri_wiphy->state != ATH_WIPHY_INACTIVE)
  379. sc->pri_wiphy->state = ATH_WIPHY_PAUSED;
  380. for (i = 0; i < sc->num_sec_wiphy; i++) {
  381. if (sc->sec_wiphy[i] &&
  382. sc->sec_wiphy[i]->state != ATH_WIPHY_INACTIVE)
  383. sc->sec_wiphy[i]->state = ATH_WIPHY_PAUSED;
  384. }
  385. }
  386. /* caller must hold wiphy_lock */
  387. static void __ath9k_wiphy_pause_all(struct ath_softc *sc)
  388. {
  389. int i;
  390. if (sc->pri_wiphy->state == ATH_WIPHY_ACTIVE)
  391. __ath9k_wiphy_pause(sc->pri_wiphy);
  392. for (i = 0; i < sc->num_sec_wiphy; i++) {
  393. if (sc->sec_wiphy[i] &&
  394. sc->sec_wiphy[i]->state == ATH_WIPHY_ACTIVE)
  395. __ath9k_wiphy_pause(sc->sec_wiphy[i]);
  396. }
  397. }
  398. int ath9k_wiphy_select(struct ath_wiphy *aphy)
  399. {
  400. struct ath_softc *sc = aphy->sc;
  401. bool now;
  402. spin_lock_bh(&sc->wiphy_lock);
  403. if (__ath9k_wiphy_scanning(sc)) {
  404. /*
  405. * For now, we are using mac80211 sw scan and it expects to
  406. * have full control over channel changes, so avoid wiphy
  407. * scheduling during a scan. This could be optimized if the
  408. * scanning control were moved into the driver.
  409. */
  410. spin_unlock_bh(&sc->wiphy_lock);
  411. return -EBUSY;
  412. }
  413. if (__ath9k_wiphy_pausing(sc)) {
  414. if (sc->wiphy_select_failures == 0)
  415. sc->wiphy_select_first_fail = jiffies;
  416. sc->wiphy_select_failures++;
  417. if (time_after(jiffies, sc->wiphy_select_first_fail + HZ / 2))
  418. {
  419. printk(KERN_DEBUG "ath9k: Previous wiphy select timed "
  420. "out; disable/enable hw to recover\n");
  421. __ath9k_wiphy_mark_all_paused(sc);
  422. /*
  423. * TODO: this workaround to fix hardware is unlikely to
  424. * be specific to virtual wiphy changes. It can happen
  425. * on normal channel change, too, and as such, this
  426. * should really be made more generic. For example,
  427. * tricker radio disable/enable on GTT interrupt burst
  428. * (say, 10 GTT interrupts received without any TX
  429. * frame being completed)
  430. */
  431. spin_unlock_bh(&sc->wiphy_lock);
  432. ath_radio_disable(sc, aphy->hw);
  433. ath_radio_enable(sc, aphy->hw);
  434. /* Only the primary wiphy hw is used for queuing work */
  435. ieee80211_queue_work(aphy->sc->hw,
  436. &aphy->sc->chan_work);
  437. return -EBUSY; /* previous select still in progress */
  438. }
  439. spin_unlock_bh(&sc->wiphy_lock);
  440. return -EBUSY; /* previous select still in progress */
  441. }
  442. sc->wiphy_select_failures = 0;
  443. /* Store the new channel */
  444. sc->chan_idx = aphy->chan_idx;
  445. sc->chan_is_ht = aphy->chan_is_ht;
  446. sc->next_wiphy = aphy;
  447. __ath9k_wiphy_pause_all(sc);
  448. now = !__ath9k_wiphy_pausing(aphy->sc);
  449. spin_unlock_bh(&sc->wiphy_lock);
  450. if (now) {
  451. /* Ready to request channel change immediately */
  452. ieee80211_queue_work(aphy->sc->hw, &aphy->sc->chan_work);
  453. }
  454. /*
  455. * wiphys will be unpaused in ath9k_tx_status() once channel has been
  456. * changed if any wiphy needs time to become paused.
  457. */
  458. return 0;
  459. }
  460. bool ath9k_wiphy_started(struct ath_softc *sc)
  461. {
  462. int i;
  463. spin_lock_bh(&sc->wiphy_lock);
  464. if (sc->pri_wiphy->state != ATH_WIPHY_INACTIVE) {
  465. spin_unlock_bh(&sc->wiphy_lock);
  466. return true;
  467. }
  468. for (i = 0; i < sc->num_sec_wiphy; i++) {
  469. if (sc->sec_wiphy[i] &&
  470. sc->sec_wiphy[i]->state != ATH_WIPHY_INACTIVE) {
  471. spin_unlock_bh(&sc->wiphy_lock);
  472. return true;
  473. }
  474. }
  475. spin_unlock_bh(&sc->wiphy_lock);
  476. return false;
  477. }
  478. static void ath9k_wiphy_pause_chan(struct ath_wiphy *aphy,
  479. struct ath_wiphy *selected)
  480. {
  481. if (selected->state == ATH_WIPHY_SCAN) {
  482. if (aphy == selected)
  483. return;
  484. /*
  485. * Pause all other wiphys for the duration of the scan even if
  486. * they are on the current channel now.
  487. */
  488. } else if (aphy->chan_idx == selected->chan_idx)
  489. return;
  490. aphy->state = ATH_WIPHY_PAUSED;
  491. ieee80211_stop_queues(aphy->hw);
  492. }
  493. void ath9k_wiphy_pause_all_forced(struct ath_softc *sc,
  494. struct ath_wiphy *selected)
  495. {
  496. int i;
  497. spin_lock_bh(&sc->wiphy_lock);
  498. if (sc->pri_wiphy->state == ATH_WIPHY_ACTIVE)
  499. ath9k_wiphy_pause_chan(sc->pri_wiphy, selected);
  500. for (i = 0; i < sc->num_sec_wiphy; i++) {
  501. if (sc->sec_wiphy[i] &&
  502. sc->sec_wiphy[i]->state == ATH_WIPHY_ACTIVE)
  503. ath9k_wiphy_pause_chan(sc->sec_wiphy[i], selected);
  504. }
  505. spin_unlock_bh(&sc->wiphy_lock);
  506. }
  507. void ath9k_wiphy_work(struct work_struct *work)
  508. {
  509. struct ath_softc *sc = container_of(work, struct ath_softc,
  510. wiphy_work.work);
  511. struct ath_wiphy *aphy = NULL;
  512. bool first = true;
  513. spin_lock_bh(&sc->wiphy_lock);
  514. if (sc->wiphy_scheduler_int == 0) {
  515. /* wiphy scheduler is disabled */
  516. spin_unlock_bh(&sc->wiphy_lock);
  517. return;
  518. }
  519. try_again:
  520. sc->wiphy_scheduler_index++;
  521. while (sc->wiphy_scheduler_index <= sc->num_sec_wiphy) {
  522. aphy = sc->sec_wiphy[sc->wiphy_scheduler_index - 1];
  523. if (aphy && aphy->state != ATH_WIPHY_INACTIVE)
  524. break;
  525. sc->wiphy_scheduler_index++;
  526. aphy = NULL;
  527. }
  528. if (aphy == NULL) {
  529. sc->wiphy_scheduler_index = 0;
  530. if (sc->pri_wiphy->state == ATH_WIPHY_INACTIVE) {
  531. if (first) {
  532. first = false;
  533. goto try_again;
  534. }
  535. /* No wiphy is ready to be scheduled */
  536. } else
  537. aphy = sc->pri_wiphy;
  538. }
  539. spin_unlock_bh(&sc->wiphy_lock);
  540. if (aphy &&
  541. aphy->state != ATH_WIPHY_ACTIVE && aphy->state != ATH_WIPHY_SCAN &&
  542. ath9k_wiphy_select(aphy)) {
  543. printk(KERN_DEBUG "ath9k: Failed to schedule virtual wiphy "
  544. "change\n");
  545. }
  546. ieee80211_queue_delayed_work(sc->hw,
  547. &sc->wiphy_work,
  548. sc->wiphy_scheduler_int);
  549. }
  550. void ath9k_wiphy_set_scheduler(struct ath_softc *sc, unsigned int msec_int)
  551. {
  552. cancel_delayed_work_sync(&sc->wiphy_work);
  553. sc->wiphy_scheduler_int = msecs_to_jiffies(msec_int);
  554. if (sc->wiphy_scheduler_int)
  555. ieee80211_queue_delayed_work(sc->hw, &sc->wiphy_work,
  556. sc->wiphy_scheduler_int);
  557. }
  558. /* caller must hold wiphy_lock */
  559. bool ath9k_all_wiphys_idle(struct ath_softc *sc)
  560. {
  561. unsigned int i;
  562. if (!sc->pri_wiphy->idle)
  563. return false;
  564. for (i = 0; i < sc->num_sec_wiphy; i++) {
  565. struct ath_wiphy *aphy = sc->sec_wiphy[i];
  566. if (!aphy)
  567. continue;
  568. if (!aphy->idle)
  569. return false;
  570. }
  571. return true;
  572. }
  573. /* caller must hold wiphy_lock */
  574. void ath9k_set_wiphy_idle(struct ath_wiphy *aphy, bool idle)
  575. {
  576. struct ath_softc *sc = aphy->sc;
  577. aphy->idle = idle;
  578. ath_dbg(ath9k_hw_common(sc->sc_ah), ATH_DBG_CONFIG,
  579. "Marking %s as %sidle\n",
  580. wiphy_name(aphy->hw->wiphy), idle ? "" : "not-");
  581. }
  582. /* Only bother starting a queue on an active virtual wiphy */
  583. bool ath_mac80211_start_queue(struct ath_softc *sc, u16 skb_queue)
  584. {
  585. struct ieee80211_hw *hw = sc->pri_wiphy->hw;
  586. unsigned int i;
  587. bool txq_started = false;
  588. spin_lock_bh(&sc->wiphy_lock);
  589. /* Start the primary wiphy */
  590. if (sc->pri_wiphy->state == ATH_WIPHY_ACTIVE) {
  591. ieee80211_wake_queue(hw, skb_queue);
  592. txq_started = true;
  593. goto unlock;
  594. }
  595. /* Now start the secondary wiphy queues */
  596. for (i = 0; i < sc->num_sec_wiphy; i++) {
  597. struct ath_wiphy *aphy = sc->sec_wiphy[i];
  598. if (!aphy)
  599. continue;
  600. if (aphy->state != ATH_WIPHY_ACTIVE)
  601. continue;
  602. hw = aphy->hw;
  603. ieee80211_wake_queue(hw, skb_queue);
  604. txq_started = true;
  605. break;
  606. }
  607. unlock:
  608. spin_unlock_bh(&sc->wiphy_lock);
  609. return txq_started;
  610. }
  611. /* Go ahead and propagate information to all virtual wiphys, it won't hurt */
  612. void ath_mac80211_stop_queue(struct ath_softc *sc, u16 skb_queue)
  613. {
  614. struct ieee80211_hw *hw = sc->pri_wiphy->hw;
  615. unsigned int i;
  616. spin_lock_bh(&sc->wiphy_lock);
  617. /* Stop the primary wiphy */
  618. ieee80211_stop_queue(hw, skb_queue);
  619. /* Now stop the secondary wiphy queues */
  620. for (i = 0; i < sc->num_sec_wiphy; i++) {
  621. struct ath_wiphy *aphy = sc->sec_wiphy[i];
  622. if (!aphy)
  623. continue;
  624. hw = aphy->hw;
  625. ieee80211_stop_queue(hw, skb_queue);
  626. }
  627. spin_unlock_bh(&sc->wiphy_lock);
  628. }