htc_drv_beacon.c 18 KB

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