virtual.c 19 KB

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