virtual.c 17 KB

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