virtual.c 18 KB

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