htc_drv_beacon.c 18 KB

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