virtual.c 18 KB

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