htc_drv_beacon.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647
  1. /*
  2. * Copyright (c) 2010-2011 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 "htc.h"
  17. #define FUDGE 2
  18. void ath9k_htc_beaconq_config(struct ath9k_htc_priv *priv)
  19. {
  20. struct ath_hw *ah = priv->ah;
  21. struct ath9k_tx_queue_info qi, qi_be;
  22. memset(&qi, 0, sizeof(struct ath9k_tx_queue_info));
  23. memset(&qi_be, 0, sizeof(struct ath9k_tx_queue_info));
  24. ath9k_hw_get_txq_props(ah, priv->beaconq, &qi);
  25. if (priv->ah->opmode == NL80211_IFTYPE_AP ||
  26. priv->ah->opmode == NL80211_IFTYPE_MESH_POINT) {
  27. qi.tqi_aifs = 1;
  28. qi.tqi_cwmin = 0;
  29. qi.tqi_cwmax = 0;
  30. } else if (priv->ah->opmode == NL80211_IFTYPE_ADHOC) {
  31. int qnum = priv->hwq_map[IEEE80211_AC_BE];
  32. ath9k_hw_get_txq_props(ah, qnum, &qi_be);
  33. qi.tqi_aifs = qi_be.tqi_aifs;
  34. /*
  35. * For WIFI Beacon Distribution
  36. * Long slot time : 2x cwmin
  37. * Short slot time : 4x cwmin
  38. */
  39. if (ah->slottime == ATH9K_SLOT_TIME_20)
  40. qi.tqi_cwmin = 2*qi_be.tqi_cwmin;
  41. else
  42. qi.tqi_cwmin = 4*qi_be.tqi_cwmin;
  43. qi.tqi_cwmax = qi_be.tqi_cwmax;
  44. }
  45. if (!ath9k_hw_set_txq_props(ah, priv->beaconq, &qi)) {
  46. ath_err(ath9k_hw_common(ah),
  47. "Unable to update beacon queue %u!\n", priv->beaconq);
  48. } else {
  49. ath9k_hw_resettxqueue(ah, priv->beaconq);
  50. }
  51. }
  52. static void ath9k_htc_beacon_config_sta(struct ath9k_htc_priv *priv,
  53. struct htc_beacon_config *bss_conf)
  54. {
  55. struct ath_common *common = ath9k_hw_common(priv->ah);
  56. struct ath9k_beacon_state bs;
  57. enum ath9k_int imask = 0;
  58. int dtimperiod, dtimcount, sleepduration;
  59. int bmiss_timeout;
  60. u32 nexttbtt = 0, intval, tsftu;
  61. __be32 htc_imask = 0;
  62. u64 tsf;
  63. int num_beacons, offset, dtim_dec_count;
  64. int ret __attribute__ ((unused));
  65. u8 cmd_rsp;
  66. memset(&bs, 0, sizeof(bs));
  67. intval = bss_conf->beacon_interval;
  68. bmiss_timeout = (ATH_DEFAULT_BMISS_LIMIT * bss_conf->beacon_interval);
  69. /*
  70. * Setup dtim parameters according to
  71. * last beacon we received (which may be none).
  72. */
  73. dtimperiod = bss_conf->dtim_period;
  74. if (dtimperiod <= 0) /* NB: 0 if not known */
  75. dtimperiod = 1;
  76. dtimcount = 1;
  77. if (dtimcount >= dtimperiod) /* NB: sanity check */
  78. dtimcount = 0;
  79. sleepduration = intval;
  80. if (sleepduration <= 0)
  81. sleepduration = intval;
  82. /*
  83. * Pull nexttbtt forward to reflect the current
  84. * TSF and calculate dtim state for the result.
  85. */
  86. tsf = ath9k_hw_gettsf64(priv->ah);
  87. tsftu = TSF_TO_TU(tsf>>32, tsf) + FUDGE;
  88. num_beacons = tsftu / intval + 1;
  89. offset = tsftu % intval;
  90. nexttbtt = tsftu - offset;
  91. if (offset)
  92. nexttbtt += intval;
  93. /* DTIM Beacon every dtimperiod Beacon */
  94. dtim_dec_count = num_beacons % dtimperiod;
  95. dtimcount -= dtim_dec_count;
  96. if (dtimcount < 0)
  97. dtimcount += dtimperiod;
  98. bs.bs_intval = TU_TO_USEC(intval);
  99. bs.bs_nexttbtt = TU_TO_USEC(nexttbtt);
  100. bs.bs_dtimperiod = dtimperiod * bs.bs_intval;
  101. bs.bs_nextdtim = bs.bs_nexttbtt + dtimcount * bs.bs_intval;
  102. /*
  103. * Calculate the number of consecutive beacons to miss* before taking
  104. * a BMISS interrupt. The configuration is specified in TU so we only
  105. * need calculate based on the beacon interval. Note that we clamp the
  106. * result to at most 15 beacons.
  107. */
  108. if (sleepduration > intval) {
  109. bs.bs_bmissthreshold = ATH_DEFAULT_BMISS_LIMIT / 2;
  110. } else {
  111. bs.bs_bmissthreshold = DIV_ROUND_UP(bmiss_timeout, intval);
  112. if (bs.bs_bmissthreshold > 15)
  113. bs.bs_bmissthreshold = 15;
  114. else if (bs.bs_bmissthreshold <= 0)
  115. bs.bs_bmissthreshold = 1;
  116. }
  117. /*
  118. * Calculate sleep duration. The configuration is given in ms.
  119. * We ensure a multiple of the beacon period is used. Also, if the sleep
  120. * duration is greater than the DTIM period then it makes senses
  121. * to make it a multiple of that.
  122. *
  123. * XXX fixed at 100ms
  124. */
  125. bs.bs_sleepduration = TU_TO_USEC(roundup(IEEE80211_MS_TO_TU(100),
  126. sleepduration));
  127. if (bs.bs_sleepduration > bs.bs_dtimperiod)
  128. bs.bs_sleepduration = bs.bs_dtimperiod;
  129. /* TSF out of range threshold fixed at 1 second */
  130. bs.bs_tsfoor_threshold = ATH9K_TSFOOR_THRESHOLD;
  131. ath_dbg(common, CONFIG, "intval: %u tsf: %llu tsftu: %u\n",
  132. intval, tsf, tsftu);
  133. ath_dbg(common, CONFIG, "bmiss: %u sleep: %u\n",
  134. bs.bs_bmissthreshold, bs.bs_sleepduration);
  135. /* Set the computed STA beacon timers */
  136. WMI_CMD(WMI_DISABLE_INTR_CMDID);
  137. ath9k_hw_set_sta_beacon_timers(priv->ah, &bs);
  138. imask |= ATH9K_INT_BMISS;
  139. htc_imask = cpu_to_be32(imask);
  140. WMI_CMD_BUF(WMI_ENABLE_INTR_CMDID, &htc_imask);
  141. }
  142. static void ath9k_htc_beacon_config_ap(struct ath9k_htc_priv *priv,
  143. struct htc_beacon_config *bss_conf)
  144. {
  145. struct ath_common *common = ath9k_hw_common(priv->ah);
  146. enum ath9k_int imask = 0;
  147. u32 nexttbtt, intval, tsftu;
  148. __be32 htc_imask = 0;
  149. int ret __attribute__ ((unused));
  150. u8 cmd_rsp;
  151. u64 tsf;
  152. intval = bss_conf->beacon_interval;
  153. intval /= ATH9K_HTC_MAX_BCN_VIF;
  154. nexttbtt = intval;
  155. /*
  156. * To reduce beacon misses under heavy TX load,
  157. * set the beacon response time to a larger value.
  158. */
  159. if (intval > DEFAULT_SWBA_RESPONSE)
  160. priv->ah->config.sw_beacon_response_time = DEFAULT_SWBA_RESPONSE;
  161. else
  162. priv->ah->config.sw_beacon_response_time = MIN_SWBA_RESPONSE;
  163. if (test_bit(OP_TSF_RESET, &priv->op_flags)) {
  164. ath9k_hw_reset_tsf(priv->ah);
  165. clear_bit(OP_TSF_RESET, &priv->op_flags);
  166. } else {
  167. /*
  168. * Pull nexttbtt forward to reflect the current TSF.
  169. */
  170. tsf = ath9k_hw_gettsf64(priv->ah);
  171. tsftu = TSF_TO_TU(tsf >> 32, tsf) + FUDGE;
  172. do {
  173. nexttbtt += intval;
  174. } while (nexttbtt < tsftu);
  175. }
  176. if (test_bit(OP_ENABLE_BEACON, &priv->op_flags))
  177. imask |= ATH9K_INT_SWBA;
  178. ath_dbg(common, CONFIG,
  179. "AP Beacon config, intval: %d, nexttbtt: %u, resp_time: %d imask: 0x%x\n",
  180. bss_conf->beacon_interval, nexttbtt,
  181. priv->ah->config.sw_beacon_response_time, imask);
  182. ath9k_htc_beaconq_config(priv);
  183. WMI_CMD(WMI_DISABLE_INTR_CMDID);
  184. ath9k_hw_beaconinit(priv->ah, TU_TO_USEC(nexttbtt), TU_TO_USEC(intval));
  185. priv->cur_beacon_conf.bmiss_cnt = 0;
  186. htc_imask = cpu_to_be32(imask);
  187. WMI_CMD_BUF(WMI_ENABLE_INTR_CMDID, &htc_imask);
  188. }
  189. static void ath9k_htc_beacon_config_adhoc(struct ath9k_htc_priv *priv,
  190. struct htc_beacon_config *bss_conf)
  191. {
  192. struct ath_common *common = ath9k_hw_common(priv->ah);
  193. enum ath9k_int imask = 0;
  194. u32 nexttbtt, intval, tsftu;
  195. __be32 htc_imask = 0;
  196. int ret __attribute__ ((unused));
  197. u8 cmd_rsp;
  198. u64 tsf;
  199. intval = bss_conf->beacon_interval;
  200. nexttbtt = intval;
  201. /*
  202. * Pull nexttbtt forward to reflect the current TSF.
  203. */
  204. tsf = ath9k_hw_gettsf64(priv->ah);
  205. tsftu = TSF_TO_TU(tsf >> 32, tsf) + FUDGE;
  206. do {
  207. nexttbtt += intval;
  208. } while (nexttbtt < tsftu);
  209. /*
  210. * Only one IBSS interfce is allowed.
  211. */
  212. if (intval > DEFAULT_SWBA_RESPONSE)
  213. priv->ah->config.sw_beacon_response_time = DEFAULT_SWBA_RESPONSE;
  214. else
  215. priv->ah->config.sw_beacon_response_time = MIN_SWBA_RESPONSE;
  216. if (test_bit(OP_ENABLE_BEACON, &priv->op_flags))
  217. imask |= ATH9K_INT_SWBA;
  218. ath_dbg(common, CONFIG,
  219. "IBSS Beacon config, intval: %d, nexttbtt: %u, resp_time: %d, imask: 0x%x\n",
  220. bss_conf->beacon_interval, nexttbtt,
  221. priv->ah->config.sw_beacon_response_time, imask);
  222. WMI_CMD(WMI_DISABLE_INTR_CMDID);
  223. ath9k_hw_beaconinit(priv->ah, TU_TO_USEC(nexttbtt), TU_TO_USEC(intval));
  224. priv->cur_beacon_conf.bmiss_cnt = 0;
  225. htc_imask = cpu_to_be32(imask);
  226. WMI_CMD_BUF(WMI_ENABLE_INTR_CMDID, &htc_imask);
  227. }
  228. void ath9k_htc_beaconep(void *drv_priv, struct sk_buff *skb,
  229. enum htc_endpoint_id ep_id, bool txok)
  230. {
  231. dev_kfree_skb_any(skb);
  232. }
  233. static void ath9k_htc_send_buffered(struct ath9k_htc_priv *priv,
  234. int slot)
  235. {
  236. struct ath_common *common = ath9k_hw_common(priv->ah);
  237. struct ieee80211_vif *vif;
  238. struct sk_buff *skb;
  239. struct ieee80211_hdr *hdr;
  240. int padpos, padsize, ret, tx_slot;
  241. spin_lock_bh(&priv->beacon_lock);
  242. vif = priv->cur_beacon_conf.bslot[slot];
  243. skb = ieee80211_get_buffered_bc(priv->hw, vif);
  244. while(skb) {
  245. hdr = (struct ieee80211_hdr *) skb->data;
  246. padpos = ieee80211_hdrlen(hdr->frame_control);
  247. padsize = padpos & 3;
  248. if (padsize && skb->len > padpos) {
  249. if (skb_headroom(skb) < padsize) {
  250. dev_kfree_skb_any(skb);
  251. goto next;
  252. }
  253. skb_push(skb, padsize);
  254. memmove(skb->data, skb->data + padsize, padpos);
  255. }
  256. tx_slot = ath9k_htc_tx_get_slot(priv);
  257. if (tx_slot < 0) {
  258. ath_dbg(common, XMIT, "No free CAB slot\n");
  259. dev_kfree_skb_any(skb);
  260. goto next;
  261. }
  262. ret = ath9k_htc_tx_start(priv, NULL, skb, tx_slot, true);
  263. if (ret != 0) {
  264. ath9k_htc_tx_clear_slot(priv, tx_slot);
  265. dev_kfree_skb_any(skb);
  266. ath_dbg(common, XMIT, "Failed to send CAB frame\n");
  267. } else {
  268. spin_lock_bh(&priv->tx.tx_lock);
  269. priv->tx.queued_cnt++;
  270. spin_unlock_bh(&priv->tx.tx_lock);
  271. }
  272. next:
  273. skb = ieee80211_get_buffered_bc(priv->hw, vif);
  274. }
  275. spin_unlock_bh(&priv->beacon_lock);
  276. }
  277. static void ath9k_htc_send_beacon(struct ath9k_htc_priv *priv,
  278. int slot)
  279. {
  280. struct ath_common *common = ath9k_hw_common(priv->ah);
  281. struct ieee80211_vif *vif;
  282. struct ath9k_htc_vif *avp;
  283. struct tx_beacon_header beacon_hdr;
  284. struct ath9k_htc_tx_ctl *tx_ctl;
  285. struct ieee80211_tx_info *info;
  286. struct ieee80211_mgmt *mgmt;
  287. struct sk_buff *beacon;
  288. u8 *tx_fhdr;
  289. int ret;
  290. memset(&beacon_hdr, 0, sizeof(struct tx_beacon_header));
  291. spin_lock_bh(&priv->beacon_lock);
  292. vif = priv->cur_beacon_conf.bslot[slot];
  293. avp = (struct ath9k_htc_vif *)vif->drv_priv;
  294. if (unlikely(test_bit(OP_SCANNING, &priv->op_flags))) {
  295. spin_unlock_bh(&priv->beacon_lock);
  296. return;
  297. }
  298. /* Get a new beacon */
  299. beacon = ieee80211_beacon_get(priv->hw, vif);
  300. if (!beacon) {
  301. spin_unlock_bh(&priv->beacon_lock);
  302. return;
  303. }
  304. /*
  305. * Update the TSF adjust value here, the HW will
  306. * add this value for every beacon.
  307. */
  308. mgmt = (struct ieee80211_mgmt *)beacon->data;
  309. mgmt->u.beacon.timestamp = avp->tsfadjust;
  310. info = IEEE80211_SKB_CB(beacon);
  311. if (info->flags & IEEE80211_TX_CTL_ASSIGN_SEQ) {
  312. struct ieee80211_hdr *hdr =
  313. (struct ieee80211_hdr *) beacon->data;
  314. avp->seq_no += 0x10;
  315. hdr->seq_ctrl &= cpu_to_le16(IEEE80211_SCTL_FRAG);
  316. hdr->seq_ctrl |= cpu_to_le16(avp->seq_no);
  317. }
  318. tx_ctl = HTC_SKB_CB(beacon);
  319. memset(tx_ctl, 0, sizeof(*tx_ctl));
  320. tx_ctl->type = ATH9K_HTC_BEACON;
  321. tx_ctl->epid = priv->beacon_ep;
  322. beacon_hdr.vif_index = avp->index;
  323. tx_fhdr = skb_push(beacon, sizeof(beacon_hdr));
  324. memcpy(tx_fhdr, (u8 *) &beacon_hdr, sizeof(beacon_hdr));
  325. ret = htc_send(priv->htc, beacon);
  326. if (ret != 0) {
  327. if (ret == -ENOMEM) {
  328. ath_dbg(common, BSTUCK,
  329. "Failed to send beacon, no free TX buffer\n");
  330. }
  331. dev_kfree_skb_any(beacon);
  332. }
  333. spin_unlock_bh(&priv->beacon_lock);
  334. }
  335. static int ath9k_htc_choose_bslot(struct ath9k_htc_priv *priv,
  336. struct wmi_event_swba *swba)
  337. {
  338. struct ath_common *common = ath9k_hw_common(priv->ah);
  339. u64 tsf;
  340. u32 tsftu;
  341. u16 intval;
  342. int slot;
  343. intval = priv->cur_beacon_conf.beacon_interval;
  344. tsf = be64_to_cpu(swba->tsf);
  345. tsftu = TSF_TO_TU(tsf >> 32, tsf);
  346. slot = ((tsftu % intval) * ATH9K_HTC_MAX_BCN_VIF) / intval;
  347. slot = ATH9K_HTC_MAX_BCN_VIF - slot - 1;
  348. ath_dbg(common, BEACON,
  349. "Choose slot: %d, tsf: %llu, tsftu: %u, intval: %u\n",
  350. slot, tsf, tsftu, intval);
  351. return slot;
  352. }
  353. void ath9k_htc_swba(struct ath9k_htc_priv *priv,
  354. struct wmi_event_swba *swba)
  355. {
  356. struct ath_common *common = ath9k_hw_common(priv->ah);
  357. int slot;
  358. if (swba->beacon_pending != 0) {
  359. priv->cur_beacon_conf.bmiss_cnt++;
  360. if (priv->cur_beacon_conf.bmiss_cnt > BSTUCK_THRESHOLD) {
  361. ath_dbg(common, BSTUCK, "Beacon stuck, HW reset\n");
  362. ieee80211_queue_work(priv->hw,
  363. &priv->fatal_work);
  364. }
  365. return;
  366. }
  367. if (priv->cur_beacon_conf.bmiss_cnt) {
  368. ath_dbg(common, BSTUCK,
  369. "Resuming beacon xmit after %u misses\n",
  370. priv->cur_beacon_conf.bmiss_cnt);
  371. priv->cur_beacon_conf.bmiss_cnt = 0;
  372. }
  373. slot = ath9k_htc_choose_bslot(priv, swba);
  374. spin_lock_bh(&priv->beacon_lock);
  375. if (priv->cur_beacon_conf.bslot[slot] == NULL) {
  376. spin_unlock_bh(&priv->beacon_lock);
  377. return;
  378. }
  379. spin_unlock_bh(&priv->beacon_lock);
  380. ath9k_htc_send_buffered(priv, slot);
  381. ath9k_htc_send_beacon(priv, slot);
  382. }
  383. void ath9k_htc_assign_bslot(struct ath9k_htc_priv *priv,
  384. struct ieee80211_vif *vif)
  385. {
  386. struct ath_common *common = ath9k_hw_common(priv->ah);
  387. struct ath9k_htc_vif *avp = (struct ath9k_htc_vif *)vif->drv_priv;
  388. int i = 0;
  389. spin_lock_bh(&priv->beacon_lock);
  390. for (i = 0; i < ATH9K_HTC_MAX_BCN_VIF; i++) {
  391. if (priv->cur_beacon_conf.bslot[i] == NULL) {
  392. avp->bslot = i;
  393. break;
  394. }
  395. }
  396. priv->cur_beacon_conf.bslot[avp->bslot] = vif;
  397. spin_unlock_bh(&priv->beacon_lock);
  398. ath_dbg(common, CONFIG, "Added interface at beacon slot: %d\n",
  399. avp->bslot);
  400. }
  401. void ath9k_htc_remove_bslot(struct ath9k_htc_priv *priv,
  402. struct ieee80211_vif *vif)
  403. {
  404. struct ath_common *common = ath9k_hw_common(priv->ah);
  405. struct ath9k_htc_vif *avp = (struct ath9k_htc_vif *)vif->drv_priv;
  406. spin_lock_bh(&priv->beacon_lock);
  407. priv->cur_beacon_conf.bslot[avp->bslot] = NULL;
  408. spin_unlock_bh(&priv->beacon_lock);
  409. ath_dbg(common, CONFIG, "Removed interface at beacon slot: %d\n",
  410. avp->bslot);
  411. }
  412. /*
  413. * Calculate the TSF adjustment value for all slots
  414. * other than zero.
  415. */
  416. void ath9k_htc_set_tsfadjust(struct ath9k_htc_priv *priv,
  417. struct ieee80211_vif *vif)
  418. {
  419. struct ath_common *common = ath9k_hw_common(priv->ah);
  420. struct ath9k_htc_vif *avp = (struct ath9k_htc_vif *)vif->drv_priv;
  421. struct htc_beacon_config *cur_conf = &priv->cur_beacon_conf;
  422. u64 tsfadjust;
  423. if (avp->bslot == 0)
  424. return;
  425. /*
  426. * The beacon interval cannot be different for multi-AP mode,
  427. * and we reach here only for VIF slots greater than zero,
  428. * so beacon_interval is guaranteed to be set in cur_conf.
  429. */
  430. tsfadjust = cur_conf->beacon_interval * avp->bslot / ATH9K_HTC_MAX_BCN_VIF;
  431. avp->tsfadjust = cpu_to_le64(TU_TO_USEC(tsfadjust));
  432. ath_dbg(common, CONFIG, "tsfadjust is: %llu for bslot: %d\n",
  433. (unsigned long long)tsfadjust, avp->bslot);
  434. }
  435. static void ath9k_htc_beacon_iter(void *data, u8 *mac, struct ieee80211_vif *vif)
  436. {
  437. bool *beacon_configured = (bool *)data;
  438. struct ath9k_htc_vif *avp = (struct ath9k_htc_vif *) vif->drv_priv;
  439. if (vif->type == NL80211_IFTYPE_STATION &&
  440. avp->beacon_configured)
  441. *beacon_configured = true;
  442. }
  443. static bool ath9k_htc_check_beacon_config(struct ath9k_htc_priv *priv,
  444. struct ieee80211_vif *vif)
  445. {
  446. struct ath_common *common = ath9k_hw_common(priv->ah);
  447. struct htc_beacon_config *cur_conf = &priv->cur_beacon_conf;
  448. struct ieee80211_bss_conf *bss_conf = &vif->bss_conf;
  449. bool beacon_configured;
  450. /*
  451. * Changing the beacon interval when multiple AP interfaces
  452. * are configured will affect beacon transmission of all
  453. * of them.
  454. */
  455. if ((priv->ah->opmode == NL80211_IFTYPE_AP) &&
  456. (priv->num_ap_vif > 1) &&
  457. (vif->type == NL80211_IFTYPE_AP) &&
  458. (cur_conf->beacon_interval != bss_conf->beacon_int)) {
  459. ath_dbg(common, CONFIG,
  460. "Changing beacon interval of multiple AP interfaces !\n");
  461. return false;
  462. }
  463. /*
  464. * If the HW is operating in AP mode, any new station interfaces that
  465. * are added cannot change the beacon parameters.
  466. */
  467. if (priv->num_ap_vif &&
  468. (vif->type != NL80211_IFTYPE_AP)) {
  469. ath_dbg(common, CONFIG,
  470. "HW in AP mode, cannot set STA beacon parameters\n");
  471. return false;
  472. }
  473. /*
  474. * The beacon parameters are configured only for the first
  475. * station interface.
  476. */
  477. if ((priv->ah->opmode == NL80211_IFTYPE_STATION) &&
  478. (priv->num_sta_vif > 1) &&
  479. (vif->type == NL80211_IFTYPE_STATION)) {
  480. beacon_configured = false;
  481. ieee80211_iterate_active_interfaces_atomic(
  482. priv->hw, IEEE80211_IFACE_ITER_RESUME_ALL,
  483. ath9k_htc_beacon_iter, &beacon_configured);
  484. if (beacon_configured) {
  485. ath_dbg(common, CONFIG,
  486. "Beacon already configured for a station interface\n");
  487. return false;
  488. }
  489. }
  490. return true;
  491. }
  492. void ath9k_htc_beacon_config(struct ath9k_htc_priv *priv,
  493. struct ieee80211_vif *vif)
  494. {
  495. struct ath_common *common = ath9k_hw_common(priv->ah);
  496. struct htc_beacon_config *cur_conf = &priv->cur_beacon_conf;
  497. struct ieee80211_bss_conf *bss_conf = &vif->bss_conf;
  498. struct ath9k_htc_vif *avp = (struct ath9k_htc_vif *) vif->drv_priv;
  499. if (!ath9k_htc_check_beacon_config(priv, vif))
  500. return;
  501. cur_conf->beacon_interval = bss_conf->beacon_int;
  502. if (cur_conf->beacon_interval == 0)
  503. cur_conf->beacon_interval = 100;
  504. cur_conf->dtim_period = bss_conf->dtim_period;
  505. cur_conf->bmiss_timeout =
  506. ATH_DEFAULT_BMISS_LIMIT * cur_conf->beacon_interval;
  507. switch (vif->type) {
  508. case NL80211_IFTYPE_STATION:
  509. ath9k_htc_beacon_config_sta(priv, cur_conf);
  510. avp->beacon_configured = true;
  511. break;
  512. case NL80211_IFTYPE_ADHOC:
  513. ath9k_htc_beacon_config_adhoc(priv, cur_conf);
  514. break;
  515. case NL80211_IFTYPE_MESH_POINT:
  516. case NL80211_IFTYPE_AP:
  517. ath9k_htc_beacon_config_ap(priv, cur_conf);
  518. break;
  519. default:
  520. ath_dbg(common, CONFIG, "Unsupported beaconing mode\n");
  521. return;
  522. }
  523. }
  524. void ath9k_htc_beacon_reconfig(struct ath9k_htc_priv *priv)
  525. {
  526. struct ath_common *common = ath9k_hw_common(priv->ah);
  527. struct htc_beacon_config *cur_conf = &priv->cur_beacon_conf;
  528. switch (priv->ah->opmode) {
  529. case NL80211_IFTYPE_STATION:
  530. ath9k_htc_beacon_config_sta(priv, cur_conf);
  531. break;
  532. case NL80211_IFTYPE_ADHOC:
  533. ath9k_htc_beacon_config_adhoc(priv, cur_conf);
  534. break;
  535. case NL80211_IFTYPE_MESH_POINT:
  536. case NL80211_IFTYPE_AP:
  537. ath9k_htc_beacon_config_ap(priv, cur_conf);
  538. break;
  539. default:
  540. ath_dbg(common, CONFIG, "Unsupported beaconing mode\n");
  541. return;
  542. }
  543. }