virtual.c 17 KB

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