htc_drv_beacon.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625
  1. /*
  2. * Copyright (c) 2010 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[WME_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;
  64. u8 cmd_rsp;
  65. memset(&bs, 0, sizeof(bs));
  66. intval = bss_conf->beacon_interval & ATH9K_BEACON_PERIOD;
  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, ATH_DBG_CONFIG, "intval: %u tsf: %llu tsftu: %u\n",
  142. intval, tsf, tsftu);
  143. ath_dbg(common, ATH_DBG_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;
  162. u8 cmd_rsp;
  163. u64 tsf;
  164. intval = bss_conf->beacon_interval & ATH9K_BEACON_PERIOD;
  165. intval /= ATH9K_HTC_MAX_BCN_VIF;
  166. nexttbtt = intval;
  167. if (priv->op_flags & OP_TSF_RESET) {
  168. ath9k_hw_reset_tsf(priv->ah);
  169. priv->op_flags &= ~OP_TSF_RESET;
  170. } else {
  171. /*
  172. * Pull nexttbtt forward to reflect the current TSF.
  173. */
  174. tsf = ath9k_hw_gettsf64(priv->ah);
  175. tsftu = TSF_TO_TU(tsf >> 32, tsf) + FUDGE;
  176. do {
  177. nexttbtt += intval;
  178. } while (nexttbtt < tsftu);
  179. }
  180. if (priv->op_flags & OP_ENABLE_BEACON)
  181. imask |= ATH9K_INT_SWBA;
  182. ath_dbg(common, ATH_DBG_CONFIG,
  183. "AP Beacon config, intval: %d, nexttbtt: %u "
  184. "imask: 0x%x\n",
  185. bss_conf->beacon_interval, nexttbtt, imask);
  186. ath9k_htc_beaconq_config(priv);
  187. WMI_CMD(WMI_DISABLE_INTR_CMDID);
  188. ath9k_hw_beaconinit(priv->ah, TU_TO_USEC(nexttbtt), TU_TO_USEC(intval));
  189. priv->cur_beacon_conf.bmiss_cnt = 0;
  190. htc_imask = cpu_to_be32(imask);
  191. WMI_CMD_BUF(WMI_ENABLE_INTR_CMDID, &htc_imask);
  192. }
  193. static void ath9k_htc_beacon_config_adhoc(struct ath9k_htc_priv *priv,
  194. struct htc_beacon_config *bss_conf)
  195. {
  196. struct ath_common *common = ath9k_hw_common(priv->ah);
  197. enum ath9k_int imask = 0;
  198. u32 nexttbtt, intval, tsftu;
  199. __be32 htc_imask = 0;
  200. int ret;
  201. u8 cmd_rsp;
  202. u64 tsf;
  203. intval = bss_conf->beacon_interval & ATH9K_BEACON_PERIOD;
  204. nexttbtt = intval;
  205. /*
  206. * Pull nexttbtt forward to reflect the current TSF.
  207. */
  208. tsf = ath9k_hw_gettsf64(priv->ah);
  209. tsftu = TSF_TO_TU(tsf >> 32, tsf) + FUDGE;
  210. do {
  211. nexttbtt += intval;
  212. } while (nexttbtt < tsftu);
  213. if (priv->op_flags & OP_ENABLE_BEACON)
  214. imask |= ATH9K_INT_SWBA;
  215. ath_dbg(common, ATH_DBG_CONFIG,
  216. "IBSS Beacon config, intval: %d, nexttbtt: %u, imask: 0x%x\n",
  217. bss_conf->beacon_interval, nexttbtt, imask);
  218. WMI_CMD(WMI_DISABLE_INTR_CMDID);
  219. ath9k_hw_beaconinit(priv->ah, TU_TO_USEC(nexttbtt), TU_TO_USEC(intval));
  220. priv->cur_beacon_conf.bmiss_cnt = 0;
  221. htc_imask = cpu_to_be32(imask);
  222. WMI_CMD_BUF(WMI_ENABLE_INTR_CMDID, &htc_imask);
  223. }
  224. void ath9k_htc_beaconep(void *drv_priv, struct sk_buff *skb,
  225. enum htc_endpoint_id ep_id, bool txok)
  226. {
  227. dev_kfree_skb_any(skb);
  228. }
  229. static void ath9k_htc_send_buffered(struct ath9k_htc_priv *priv,
  230. int slot)
  231. {
  232. struct ath_common *common = ath9k_hw_common(priv->ah);
  233. struct ieee80211_vif *vif;
  234. struct sk_buff *skb;
  235. struct ieee80211_hdr *hdr;
  236. int padpos, padsize, ret;
  237. spin_lock_bh(&priv->beacon_lock);
  238. vif = priv->cur_beacon_conf.bslot[slot];
  239. skb = ieee80211_get_buffered_bc(priv->hw, vif);
  240. while(skb) {
  241. hdr = (struct ieee80211_hdr *) skb->data;
  242. padpos = ath9k_cmn_padpos(hdr->frame_control);
  243. padsize = padpos & 3;
  244. if (padsize && skb->len > padpos) {
  245. if (skb_headroom(skb) < padsize) {
  246. dev_kfree_skb_any(skb);
  247. goto next;
  248. }
  249. skb_push(skb, padsize);
  250. memmove(skb->data, skb->data + padsize, padpos);
  251. }
  252. ret = ath9k_htc_tx_start(priv, skb, true);
  253. if (ret != 0) {
  254. ath_dbg(common, ATH_DBG_FATAL,
  255. "Failed to send CAB frame\n");
  256. dev_kfree_skb_any(skb);
  257. }
  258. next:
  259. skb = ieee80211_get_buffered_bc(priv->hw, vif);
  260. }
  261. spin_unlock_bh(&priv->beacon_lock);
  262. }
  263. static void ath9k_htc_send_beacon(struct ath9k_htc_priv *priv,
  264. int slot)
  265. {
  266. struct ieee80211_vif *vif;
  267. struct ath9k_htc_vif *avp;
  268. struct tx_beacon_header beacon_hdr;
  269. struct ath9k_htc_tx_ctl tx_ctl;
  270. struct ieee80211_tx_info *info;
  271. struct ieee80211_mgmt *mgmt;
  272. struct sk_buff *beacon;
  273. u8 *tx_fhdr;
  274. memset(&beacon_hdr, 0, sizeof(struct tx_beacon_header));
  275. memset(&tx_ctl, 0, sizeof(struct ath9k_htc_tx_ctl));
  276. spin_lock_bh(&priv->beacon_lock);
  277. vif = priv->cur_beacon_conf.bslot[slot];
  278. avp = (struct ath9k_htc_vif *)vif->drv_priv;
  279. if (unlikely(priv->op_flags & OP_SCANNING)) {
  280. spin_unlock_bh(&priv->beacon_lock);
  281. return;
  282. }
  283. /* Get a new beacon */
  284. beacon = ieee80211_beacon_get(priv->hw, vif);
  285. if (!beacon) {
  286. spin_unlock_bh(&priv->beacon_lock);
  287. return;
  288. }
  289. /*
  290. * Update the TSF adjust value here, the HW will
  291. * add this value for every beacon.
  292. */
  293. mgmt = (struct ieee80211_mgmt *)beacon->data;
  294. mgmt->u.beacon.timestamp = avp->tsfadjust;
  295. info = IEEE80211_SKB_CB(beacon);
  296. if (info->flags & IEEE80211_TX_CTL_ASSIGN_SEQ) {
  297. struct ieee80211_hdr *hdr =
  298. (struct ieee80211_hdr *) beacon->data;
  299. avp->seq_no += 0x10;
  300. hdr->seq_ctrl &= cpu_to_le16(IEEE80211_SCTL_FRAG);
  301. hdr->seq_ctrl |= cpu_to_le16(avp->seq_no);
  302. }
  303. tx_ctl.type = ATH9K_HTC_NORMAL;
  304. beacon_hdr.vif_index = avp->index;
  305. tx_fhdr = skb_push(beacon, sizeof(beacon_hdr));
  306. memcpy(tx_fhdr, (u8 *) &beacon_hdr, sizeof(beacon_hdr));
  307. htc_send(priv->htc, beacon, priv->beacon_ep, &tx_ctl);
  308. spin_unlock_bh(&priv->beacon_lock);
  309. }
  310. static int ath9k_htc_choose_bslot(struct ath9k_htc_priv *priv)
  311. {
  312. struct ath_common *common = ath9k_hw_common(priv->ah);
  313. unsigned long flags;
  314. u64 tsf;
  315. u32 tsftu;
  316. u16 intval;
  317. int slot;
  318. intval = priv->cur_beacon_conf.beacon_interval & ATH9K_BEACON_PERIOD;
  319. spin_lock_irqsave(&priv->wmi->wmi_lock, flags);
  320. tsf = priv->wmi->tsf;
  321. spin_unlock_irqrestore(&priv->wmi->wmi_lock, flags);
  322. tsftu = TSF_TO_TU(tsf >> 32, tsf);
  323. slot = ((tsftu % intval) * ATH9K_HTC_MAX_BCN_VIF) / intval;
  324. slot = ATH9K_HTC_MAX_BCN_VIF - slot - 1;
  325. ath_dbg(common, ATH_DBG_BEACON,
  326. "Choose slot: %d, tsf: %llu, tsftu: %u, intval: %u\n",
  327. slot, tsf, tsftu, intval);
  328. return slot;
  329. }
  330. void ath9k_htc_swba(struct ath9k_htc_priv *priv)
  331. {
  332. struct ath_common *common = ath9k_hw_common(priv->ah);
  333. unsigned long flags;
  334. int slot;
  335. spin_lock_irqsave(&priv->wmi->wmi_lock, flags);
  336. if (priv->wmi->beacon_pending != 0) {
  337. spin_unlock_irqrestore(&priv->wmi->wmi_lock, flags);
  338. priv->cur_beacon_conf.bmiss_cnt++;
  339. if (priv->cur_beacon_conf.bmiss_cnt > BSTUCK_THRESHOLD) {
  340. ath_dbg(common, ATH_DBG_BEACON,
  341. "Beacon stuck, HW reset\n");
  342. ath9k_htc_reset(priv);
  343. }
  344. return;
  345. }
  346. spin_unlock_irqrestore(&priv->wmi->wmi_lock, flags);
  347. if (priv->cur_beacon_conf.bmiss_cnt) {
  348. ath_dbg(common, ATH_DBG_BEACON,
  349. "Resuming beacon xmit after %u misses\n",
  350. priv->cur_beacon_conf.bmiss_cnt);
  351. priv->cur_beacon_conf.bmiss_cnt = 0;
  352. }
  353. slot = ath9k_htc_choose_bslot(priv);
  354. spin_lock_bh(&priv->beacon_lock);
  355. if (priv->cur_beacon_conf.bslot[slot] == NULL) {
  356. spin_unlock_bh(&priv->beacon_lock);
  357. return;
  358. }
  359. spin_unlock_bh(&priv->beacon_lock);
  360. ath9k_htc_send_buffered(priv, slot);
  361. ath9k_htc_send_beacon(priv, slot);
  362. }
  363. void ath9k_htc_assign_bslot(struct ath9k_htc_priv *priv,
  364. struct ieee80211_vif *vif)
  365. {
  366. struct ath_common *common = ath9k_hw_common(priv->ah);
  367. struct ath9k_htc_vif *avp = (struct ath9k_htc_vif *)vif->drv_priv;
  368. int i = 0;
  369. spin_lock_bh(&priv->beacon_lock);
  370. for (i = 0; i < ATH9K_HTC_MAX_BCN_VIF; i++) {
  371. if (priv->cur_beacon_conf.bslot[i] == NULL) {
  372. avp->bslot = i;
  373. break;
  374. }
  375. }
  376. priv->cur_beacon_conf.bslot[avp->bslot] = vif;
  377. spin_unlock_bh(&priv->beacon_lock);
  378. ath_dbg(common, ATH_DBG_CONFIG,
  379. "Added interface at beacon slot: %d\n", avp->bslot);
  380. }
  381. void ath9k_htc_remove_bslot(struct ath9k_htc_priv *priv,
  382. struct ieee80211_vif *vif)
  383. {
  384. struct ath_common *common = ath9k_hw_common(priv->ah);
  385. struct ath9k_htc_vif *avp = (struct ath9k_htc_vif *)vif->drv_priv;
  386. spin_lock_bh(&priv->beacon_lock);
  387. priv->cur_beacon_conf.bslot[avp->bslot] = NULL;
  388. spin_unlock_bh(&priv->beacon_lock);
  389. ath_dbg(common, ATH_DBG_CONFIG,
  390. "Removed interface at beacon slot: %d\n", avp->bslot);
  391. }
  392. /*
  393. * Calculate the TSF adjustment value for all slots
  394. * other than zero.
  395. */
  396. void ath9k_htc_set_tsfadjust(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. struct htc_beacon_config *cur_conf = &priv->cur_beacon_conf;
  402. u64 tsfadjust;
  403. if (avp->bslot == 0)
  404. return;
  405. /*
  406. * The beacon interval cannot be different for multi-AP mode,
  407. * and we reach here only for VIF slots greater than zero,
  408. * so beacon_interval is guaranteed to be set in cur_conf.
  409. */
  410. tsfadjust = cur_conf->beacon_interval * avp->bslot / ATH9K_HTC_MAX_BCN_VIF;
  411. avp->tsfadjust = cpu_to_le64(TU_TO_USEC(tsfadjust));
  412. ath_dbg(common, ATH_DBG_CONFIG,
  413. "tsfadjust is: %llu for bslot: %d\n",
  414. (unsigned long long)tsfadjust, avp->bslot);
  415. }
  416. static void ath9k_htc_beacon_iter(void *data, u8 *mac, struct ieee80211_vif *vif)
  417. {
  418. bool *beacon_configured = (bool *)data;
  419. struct ath9k_htc_vif *avp = (struct ath9k_htc_vif *) vif->drv_priv;
  420. if (vif->type == NL80211_IFTYPE_STATION &&
  421. avp->beacon_configured)
  422. *beacon_configured = true;
  423. }
  424. static bool ath9k_htc_check_beacon_config(struct ath9k_htc_priv *priv,
  425. struct ieee80211_vif *vif)
  426. {
  427. struct ath_common *common = ath9k_hw_common(priv->ah);
  428. struct htc_beacon_config *cur_conf = &priv->cur_beacon_conf;
  429. struct ieee80211_bss_conf *bss_conf = &vif->bss_conf;
  430. bool beacon_configured;
  431. /*
  432. * Changing the beacon interval when multiple AP interfaces
  433. * are configured will affect beacon transmission of all
  434. * of them.
  435. */
  436. if ((priv->ah->opmode == NL80211_IFTYPE_AP) &&
  437. (priv->num_ap_vif > 1) &&
  438. (vif->type == NL80211_IFTYPE_AP) &&
  439. (cur_conf->beacon_interval != bss_conf->beacon_int)) {
  440. ath_dbg(common, ATH_DBG_CONFIG,
  441. "Changing beacon interval of multiple AP interfaces !\n");
  442. return false;
  443. }
  444. /*
  445. * If the HW is operating in AP mode, any new station interfaces that
  446. * are added cannot change the beacon parameters.
  447. */
  448. if (priv->num_ap_vif &&
  449. (vif->type != NL80211_IFTYPE_AP)) {
  450. ath_dbg(common, ATH_DBG_CONFIG,
  451. "HW in AP mode, cannot set STA beacon parameters\n");
  452. return false;
  453. }
  454. /*
  455. * The beacon parameters are configured only for the first
  456. * station interface.
  457. */
  458. if ((priv->ah->opmode == NL80211_IFTYPE_STATION) &&
  459. (priv->num_sta_vif > 1) &&
  460. (vif->type == NL80211_IFTYPE_STATION)) {
  461. beacon_configured = false;
  462. ieee80211_iterate_active_interfaces_atomic(priv->hw,
  463. ath9k_htc_beacon_iter,
  464. &beacon_configured);
  465. if (beacon_configured) {
  466. ath_dbg(common, ATH_DBG_CONFIG,
  467. "Beacon already configured for a station interface\n");
  468. return false;
  469. }
  470. }
  471. return true;
  472. }
  473. void ath9k_htc_beacon_config(struct ath9k_htc_priv *priv,
  474. struct ieee80211_vif *vif)
  475. {
  476. struct ath_common *common = ath9k_hw_common(priv->ah);
  477. struct htc_beacon_config *cur_conf = &priv->cur_beacon_conf;
  478. struct ieee80211_bss_conf *bss_conf = &vif->bss_conf;
  479. struct ath9k_htc_vif *avp = (struct ath9k_htc_vif *) vif->drv_priv;
  480. if (!ath9k_htc_check_beacon_config(priv, vif))
  481. return;
  482. cur_conf->beacon_interval = bss_conf->beacon_int;
  483. if (cur_conf->beacon_interval == 0)
  484. cur_conf->beacon_interval = 100;
  485. cur_conf->dtim_period = bss_conf->dtim_period;
  486. cur_conf->bmiss_timeout =
  487. ATH_DEFAULT_BMISS_LIMIT * cur_conf->beacon_interval;
  488. switch (vif->type) {
  489. case NL80211_IFTYPE_STATION:
  490. ath9k_htc_beacon_config_sta(priv, cur_conf);
  491. avp->beacon_configured = true;
  492. break;
  493. case NL80211_IFTYPE_ADHOC:
  494. ath9k_htc_beacon_config_adhoc(priv, cur_conf);
  495. break;
  496. case NL80211_IFTYPE_AP:
  497. ath9k_htc_beacon_config_ap(priv, cur_conf);
  498. break;
  499. default:
  500. ath_dbg(common, ATH_DBG_CONFIG,
  501. "Unsupported beaconing mode\n");
  502. return;
  503. }
  504. }
  505. void ath9k_htc_beacon_reconfig(struct ath9k_htc_priv *priv)
  506. {
  507. struct ath_common *common = ath9k_hw_common(priv->ah);
  508. struct htc_beacon_config *cur_conf = &priv->cur_beacon_conf;
  509. switch (priv->ah->opmode) {
  510. case NL80211_IFTYPE_STATION:
  511. ath9k_htc_beacon_config_sta(priv, cur_conf);
  512. break;
  513. case NL80211_IFTYPE_ADHOC:
  514. ath9k_htc_beacon_config_adhoc(priv, cur_conf);
  515. break;
  516. case NL80211_IFTYPE_AP:
  517. ath9k_htc_beacon_config_ap(priv, cur_conf);
  518. break;
  519. default:
  520. ath_dbg(common, ATH_DBG_CONFIG,
  521. "Unsupported beaconing mode\n");
  522. return;
  523. }
  524. }