main.c 60 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515
  1. /*
  2. * Copyright (c) 2008-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 <linux/nl80211.h>
  17. #include <linux/delay.h>
  18. #include "ath9k.h"
  19. #include "btcoex.h"
  20. u8 ath9k_parse_mpdudensity(u8 mpdudensity)
  21. {
  22. /*
  23. * 802.11n D2.0 defined values for "Minimum MPDU Start Spacing":
  24. * 0 for no restriction
  25. * 1 for 1/4 us
  26. * 2 for 1/2 us
  27. * 3 for 1 us
  28. * 4 for 2 us
  29. * 5 for 4 us
  30. * 6 for 8 us
  31. * 7 for 16 us
  32. */
  33. switch (mpdudensity) {
  34. case 0:
  35. return 0;
  36. case 1:
  37. case 2:
  38. case 3:
  39. /* Our lower layer calculations limit our precision to
  40. 1 microsecond */
  41. return 1;
  42. case 4:
  43. return 2;
  44. case 5:
  45. return 4;
  46. case 6:
  47. return 8;
  48. case 7:
  49. return 16;
  50. default:
  51. return 0;
  52. }
  53. }
  54. static bool ath9k_has_pending_frames(struct ath_softc *sc, struct ath_txq *txq)
  55. {
  56. bool pending = false;
  57. spin_lock_bh(&txq->axq_lock);
  58. if (txq->axq_depth) {
  59. pending = true;
  60. goto out;
  61. }
  62. if (txq->mac80211_qnum >= 0) {
  63. struct list_head *list;
  64. list = &sc->cur_chan->acq[txq->mac80211_qnum];
  65. if (!list_empty(list))
  66. pending = true;
  67. }
  68. out:
  69. spin_unlock_bh(&txq->axq_lock);
  70. return pending;
  71. }
  72. static bool ath9k_setpower(struct ath_softc *sc, enum ath9k_power_mode mode)
  73. {
  74. unsigned long flags;
  75. bool ret;
  76. spin_lock_irqsave(&sc->sc_pm_lock, flags);
  77. ret = ath9k_hw_setpower(sc->sc_ah, mode);
  78. spin_unlock_irqrestore(&sc->sc_pm_lock, flags);
  79. return ret;
  80. }
  81. void ath_ps_full_sleep(unsigned long data)
  82. {
  83. struct ath_softc *sc = (struct ath_softc *) data;
  84. struct ath_common *common = ath9k_hw_common(sc->sc_ah);
  85. bool reset;
  86. spin_lock(&common->cc_lock);
  87. ath_hw_cycle_counters_update(common);
  88. spin_unlock(&common->cc_lock);
  89. ath9k_hw_setrxabort(sc->sc_ah, 1);
  90. ath9k_hw_stopdmarecv(sc->sc_ah, &reset);
  91. ath9k_hw_setpower(sc->sc_ah, ATH9K_PM_FULL_SLEEP);
  92. }
  93. void ath9k_ps_wakeup(struct ath_softc *sc)
  94. {
  95. struct ath_common *common = ath9k_hw_common(sc->sc_ah);
  96. unsigned long flags;
  97. enum ath9k_power_mode power_mode;
  98. spin_lock_irqsave(&sc->sc_pm_lock, flags);
  99. if (++sc->ps_usecount != 1)
  100. goto unlock;
  101. del_timer_sync(&sc->sleep_timer);
  102. power_mode = sc->sc_ah->power_mode;
  103. ath9k_hw_setpower(sc->sc_ah, ATH9K_PM_AWAKE);
  104. /*
  105. * While the hardware is asleep, the cycle counters contain no
  106. * useful data. Better clear them now so that they don't mess up
  107. * survey data results.
  108. */
  109. if (power_mode != ATH9K_PM_AWAKE) {
  110. spin_lock(&common->cc_lock);
  111. ath_hw_cycle_counters_update(common);
  112. memset(&common->cc_survey, 0, sizeof(common->cc_survey));
  113. memset(&common->cc_ani, 0, sizeof(common->cc_ani));
  114. spin_unlock(&common->cc_lock);
  115. }
  116. unlock:
  117. spin_unlock_irqrestore(&sc->sc_pm_lock, flags);
  118. }
  119. void ath9k_ps_restore(struct ath_softc *sc)
  120. {
  121. struct ath_common *common = ath9k_hw_common(sc->sc_ah);
  122. enum ath9k_power_mode mode;
  123. unsigned long flags;
  124. spin_lock_irqsave(&sc->sc_pm_lock, flags);
  125. if (--sc->ps_usecount != 0)
  126. goto unlock;
  127. if (sc->ps_idle) {
  128. mod_timer(&sc->sleep_timer, jiffies + HZ / 10);
  129. goto unlock;
  130. }
  131. if (sc->ps_enabled &&
  132. !(sc->ps_flags & (PS_WAIT_FOR_BEACON |
  133. PS_WAIT_FOR_CAB |
  134. PS_WAIT_FOR_PSPOLL_DATA |
  135. PS_WAIT_FOR_TX_ACK |
  136. PS_WAIT_FOR_ANI))) {
  137. mode = ATH9K_PM_NETWORK_SLEEP;
  138. if (ath9k_hw_btcoex_is_enabled(sc->sc_ah))
  139. ath9k_btcoex_stop_gen_timer(sc);
  140. } else {
  141. goto unlock;
  142. }
  143. spin_lock(&common->cc_lock);
  144. ath_hw_cycle_counters_update(common);
  145. spin_unlock(&common->cc_lock);
  146. ath9k_hw_setpower(sc->sc_ah, mode);
  147. unlock:
  148. spin_unlock_irqrestore(&sc->sc_pm_lock, flags);
  149. }
  150. static void __ath_cancel_work(struct ath_softc *sc)
  151. {
  152. cancel_work_sync(&sc->paprd_work);
  153. cancel_delayed_work_sync(&sc->tx_complete_work);
  154. cancel_delayed_work_sync(&sc->hw_pll_work);
  155. #ifdef CONFIG_ATH9K_BTCOEX_SUPPORT
  156. if (ath9k_hw_mci_is_enabled(sc->sc_ah))
  157. cancel_work_sync(&sc->mci_work);
  158. #endif
  159. }
  160. void ath_cancel_work(struct ath_softc *sc)
  161. {
  162. __ath_cancel_work(sc);
  163. cancel_work_sync(&sc->hw_reset_work);
  164. }
  165. void ath_restart_work(struct ath_softc *sc)
  166. {
  167. ieee80211_queue_delayed_work(sc->hw, &sc->tx_complete_work, 0);
  168. if (AR_SREV_9340(sc->sc_ah) || AR_SREV_9330(sc->sc_ah))
  169. ieee80211_queue_delayed_work(sc->hw, &sc->hw_pll_work,
  170. msecs_to_jiffies(ATH_PLL_WORK_INTERVAL));
  171. ath_start_ani(sc);
  172. }
  173. static bool ath_prepare_reset(struct ath_softc *sc)
  174. {
  175. struct ath_hw *ah = sc->sc_ah;
  176. bool ret = true;
  177. ieee80211_stop_queues(sc->hw);
  178. ath_stop_ani(sc);
  179. ath9k_hw_disable_interrupts(ah);
  180. if (!ath_drain_all_txq(sc))
  181. ret = false;
  182. if (!ath_stoprecv(sc))
  183. ret = false;
  184. return ret;
  185. }
  186. static bool ath_complete_reset(struct ath_softc *sc, bool start)
  187. {
  188. struct ath_hw *ah = sc->sc_ah;
  189. struct ath_common *common = ath9k_hw_common(ah);
  190. unsigned long flags;
  191. ath9k_calculate_summary_state(sc, sc->cur_chan);
  192. ath_startrecv(sc);
  193. ath9k_cmn_update_txpow(ah, sc->curtxpow,
  194. sc->cur_chan->txpower, &sc->curtxpow);
  195. clear_bit(ATH_OP_HW_RESET, &common->op_flags);
  196. if (!sc->cur_chan->offchannel && start) {
  197. /* restore per chanctx TSF timer */
  198. if (sc->cur_chan->tsf_val) {
  199. u32 offset;
  200. offset = ath9k_hw_get_tsf_offset(&sc->cur_chan->tsf_ts,
  201. NULL);
  202. ath9k_hw_settsf64(ah, sc->cur_chan->tsf_val + offset);
  203. }
  204. if (!test_bit(ATH_OP_BEACONS, &common->op_flags))
  205. goto work;
  206. if (ah->opmode == NL80211_IFTYPE_STATION &&
  207. test_bit(ATH_OP_PRIM_STA_VIF, &common->op_flags)) {
  208. spin_lock_irqsave(&sc->sc_pm_lock, flags);
  209. sc->ps_flags |= PS_BEACON_SYNC | PS_WAIT_FOR_BEACON;
  210. spin_unlock_irqrestore(&sc->sc_pm_lock, flags);
  211. } else {
  212. ath9k_set_beacon(sc);
  213. }
  214. work:
  215. ath_restart_work(sc);
  216. ath_txq_schedule_all(sc);
  217. }
  218. sc->gtt_cnt = 0;
  219. ath9k_hw_set_interrupts(ah);
  220. ath9k_hw_enable_interrupts(ah);
  221. ieee80211_wake_queues(sc->hw);
  222. ath9k_p2p_ps_timer(sc);
  223. return true;
  224. }
  225. int ath_reset_internal(struct ath_softc *sc, struct ath9k_channel *hchan)
  226. {
  227. struct ath_hw *ah = sc->sc_ah;
  228. struct ath_common *common = ath9k_hw_common(ah);
  229. struct ath9k_hw_cal_data *caldata = NULL;
  230. bool fastcc = true;
  231. int r;
  232. __ath_cancel_work(sc);
  233. tasklet_disable(&sc->intr_tq);
  234. spin_lock_bh(&sc->sc_pcu_lock);
  235. if (!sc->cur_chan->offchannel) {
  236. fastcc = false;
  237. caldata = &sc->cur_chan->caldata;
  238. }
  239. if (!hchan) {
  240. fastcc = false;
  241. hchan = ah->curchan;
  242. }
  243. if (!ath_prepare_reset(sc))
  244. fastcc = false;
  245. if (ath9k_is_chanctx_enabled())
  246. fastcc = false;
  247. spin_lock_bh(&sc->chan_lock);
  248. sc->cur_chandef = sc->cur_chan->chandef;
  249. spin_unlock_bh(&sc->chan_lock);
  250. ath_dbg(common, CONFIG, "Reset to %u MHz, HT40: %d fastcc: %d\n",
  251. hchan->channel, IS_CHAN_HT40(hchan), fastcc);
  252. r = ath9k_hw_reset(ah, hchan, caldata, fastcc);
  253. if (r) {
  254. ath_err(common,
  255. "Unable to reset channel, reset status %d\n", r);
  256. ath9k_hw_enable_interrupts(ah);
  257. ath9k_queue_reset(sc, RESET_TYPE_BB_HANG);
  258. goto out;
  259. }
  260. if (ath9k_hw_mci_is_enabled(sc->sc_ah) &&
  261. sc->cur_chan->offchannel)
  262. ath9k_mci_set_txpower(sc, true, false);
  263. if (!ath_complete_reset(sc, true))
  264. r = -EIO;
  265. out:
  266. spin_unlock_bh(&sc->sc_pcu_lock);
  267. tasklet_enable(&sc->intr_tq);
  268. return r;
  269. }
  270. static void ath_node_attach(struct ath_softc *sc, struct ieee80211_sta *sta,
  271. struct ieee80211_vif *vif)
  272. {
  273. struct ath_node *an;
  274. an = (struct ath_node *)sta->drv_priv;
  275. an->sc = sc;
  276. an->sta = sta;
  277. an->vif = vif;
  278. memset(&an->key_idx, 0, sizeof(an->key_idx));
  279. ath_tx_node_init(sc, an);
  280. ath_dynack_node_init(sc->sc_ah, an);
  281. }
  282. static void ath_node_detach(struct ath_softc *sc, struct ieee80211_sta *sta)
  283. {
  284. struct ath_node *an = (struct ath_node *)sta->drv_priv;
  285. ath_tx_node_cleanup(sc, an);
  286. ath_dynack_node_deinit(sc->sc_ah, an);
  287. }
  288. void ath9k_tasklet(unsigned long data)
  289. {
  290. struct ath_softc *sc = (struct ath_softc *)data;
  291. struct ath_hw *ah = sc->sc_ah;
  292. struct ath_common *common = ath9k_hw_common(ah);
  293. enum ath_reset_type type;
  294. unsigned long flags;
  295. u32 status = sc->intrstatus;
  296. u32 rxmask;
  297. ath9k_ps_wakeup(sc);
  298. spin_lock(&sc->sc_pcu_lock);
  299. if (status & ATH9K_INT_FATAL) {
  300. type = RESET_TYPE_FATAL_INT;
  301. ath9k_queue_reset(sc, type);
  302. /*
  303. * Increment the ref. counter here so that
  304. * interrupts are enabled in the reset routine.
  305. */
  306. atomic_inc(&ah->intr_ref_cnt);
  307. ath_dbg(common, RESET, "FATAL: Skipping interrupts\n");
  308. goto out;
  309. }
  310. if ((ah->config.hw_hang_checks & HW_BB_WATCHDOG) &&
  311. (status & ATH9K_INT_BB_WATCHDOG)) {
  312. spin_lock(&common->cc_lock);
  313. ath_hw_cycle_counters_update(common);
  314. ar9003_hw_bb_watchdog_dbg_info(ah);
  315. spin_unlock(&common->cc_lock);
  316. if (ar9003_hw_bb_watchdog_check(ah)) {
  317. type = RESET_TYPE_BB_WATCHDOG;
  318. ath9k_queue_reset(sc, type);
  319. /*
  320. * Increment the ref. counter here so that
  321. * interrupts are enabled in the reset routine.
  322. */
  323. atomic_inc(&ah->intr_ref_cnt);
  324. ath_dbg(common, RESET,
  325. "BB_WATCHDOG: Skipping interrupts\n");
  326. goto out;
  327. }
  328. }
  329. if (status & ATH9K_INT_GTT) {
  330. sc->gtt_cnt++;
  331. if ((sc->gtt_cnt >= MAX_GTT_CNT) && !ath9k_hw_check_alive(ah)) {
  332. type = RESET_TYPE_TX_GTT;
  333. ath9k_queue_reset(sc, type);
  334. atomic_inc(&ah->intr_ref_cnt);
  335. ath_dbg(common, RESET,
  336. "GTT: Skipping interrupts\n");
  337. goto out;
  338. }
  339. }
  340. spin_lock_irqsave(&sc->sc_pm_lock, flags);
  341. if ((status & ATH9K_INT_TSFOOR) && sc->ps_enabled) {
  342. /*
  343. * TSF sync does not look correct; remain awake to sync with
  344. * the next Beacon.
  345. */
  346. ath_dbg(common, PS, "TSFOOR - Sync with next Beacon\n");
  347. sc->ps_flags |= PS_WAIT_FOR_BEACON | PS_BEACON_SYNC;
  348. }
  349. spin_unlock_irqrestore(&sc->sc_pm_lock, flags);
  350. if (ah->caps.hw_caps & ATH9K_HW_CAP_EDMA)
  351. rxmask = (ATH9K_INT_RXHP | ATH9K_INT_RXLP | ATH9K_INT_RXEOL |
  352. ATH9K_INT_RXORN);
  353. else
  354. rxmask = (ATH9K_INT_RX | ATH9K_INT_RXEOL | ATH9K_INT_RXORN);
  355. if (status & rxmask) {
  356. /* Check for high priority Rx first */
  357. if ((ah->caps.hw_caps & ATH9K_HW_CAP_EDMA) &&
  358. (status & ATH9K_INT_RXHP))
  359. ath_rx_tasklet(sc, 0, true);
  360. ath_rx_tasklet(sc, 0, false);
  361. }
  362. if (status & ATH9K_INT_TX) {
  363. if (ah->caps.hw_caps & ATH9K_HW_CAP_EDMA) {
  364. /*
  365. * For EDMA chips, TX completion is enabled for the
  366. * beacon queue, so if a beacon has been transmitted
  367. * successfully after a GTT interrupt, the GTT counter
  368. * gets reset to zero here.
  369. */
  370. sc->gtt_cnt = 0;
  371. ath_tx_edma_tasklet(sc);
  372. } else {
  373. ath_tx_tasklet(sc);
  374. }
  375. wake_up(&sc->tx_wait);
  376. }
  377. if (status & ATH9K_INT_GENTIMER)
  378. ath_gen_timer_isr(sc->sc_ah);
  379. ath9k_btcoex_handle_interrupt(sc, status);
  380. /* re-enable hardware interrupt */
  381. ath9k_hw_enable_interrupts(ah);
  382. out:
  383. spin_unlock(&sc->sc_pcu_lock);
  384. ath9k_ps_restore(sc);
  385. }
  386. irqreturn_t ath_isr(int irq, void *dev)
  387. {
  388. #define SCHED_INTR ( \
  389. ATH9K_INT_FATAL | \
  390. ATH9K_INT_BB_WATCHDOG | \
  391. ATH9K_INT_RXORN | \
  392. ATH9K_INT_RXEOL | \
  393. ATH9K_INT_RX | \
  394. ATH9K_INT_RXLP | \
  395. ATH9K_INT_RXHP | \
  396. ATH9K_INT_TX | \
  397. ATH9K_INT_BMISS | \
  398. ATH9K_INT_CST | \
  399. ATH9K_INT_GTT | \
  400. ATH9K_INT_TSFOOR | \
  401. ATH9K_INT_GENTIMER | \
  402. ATH9K_INT_MCI)
  403. struct ath_softc *sc = dev;
  404. struct ath_hw *ah = sc->sc_ah;
  405. struct ath_common *common = ath9k_hw_common(ah);
  406. enum ath9k_int status;
  407. u32 sync_cause = 0;
  408. bool sched = false;
  409. /*
  410. * The hardware is not ready/present, don't
  411. * touch anything. Note this can happen early
  412. * on if the IRQ is shared.
  413. */
  414. if (!ah || test_bit(ATH_OP_INVALID, &common->op_flags))
  415. return IRQ_NONE;
  416. /* shared irq, not for us */
  417. if (!ath9k_hw_intrpend(ah))
  418. return IRQ_NONE;
  419. if (test_bit(ATH_OP_HW_RESET, &common->op_flags)) {
  420. ath9k_hw_kill_interrupts(ah);
  421. return IRQ_HANDLED;
  422. }
  423. /*
  424. * Figure out the reason(s) for the interrupt. Note
  425. * that the hal returns a pseudo-ISR that may include
  426. * bits we haven't explicitly enabled so we mask the
  427. * value to insure we only process bits we requested.
  428. */
  429. ath9k_hw_getisr(ah, &status, &sync_cause); /* NB: clears ISR too */
  430. ath9k_debug_sync_cause(sc, sync_cause);
  431. status &= ah->imask; /* discard unasked-for bits */
  432. /*
  433. * If there are no status bits set, then this interrupt was not
  434. * for me (should have been caught above).
  435. */
  436. if (!status)
  437. return IRQ_NONE;
  438. /* Cache the status */
  439. sc->intrstatus = status;
  440. if (status & SCHED_INTR)
  441. sched = true;
  442. /*
  443. * If a FATAL or RXORN interrupt is received, we have to reset the
  444. * chip immediately.
  445. */
  446. if ((status & ATH9K_INT_FATAL) || ((status & ATH9K_INT_RXORN) &&
  447. !(ah->caps.hw_caps & ATH9K_HW_CAP_EDMA)))
  448. goto chip_reset;
  449. if ((ah->config.hw_hang_checks & HW_BB_WATCHDOG) &&
  450. (status & ATH9K_INT_BB_WATCHDOG))
  451. goto chip_reset;
  452. #ifdef CONFIG_ATH9K_WOW
  453. if (status & ATH9K_INT_BMISS) {
  454. if (atomic_read(&sc->wow_sleep_proc_intr) == 0) {
  455. atomic_inc(&sc->wow_got_bmiss_intr);
  456. atomic_dec(&sc->wow_sleep_proc_intr);
  457. }
  458. }
  459. #endif
  460. if (status & ATH9K_INT_SWBA)
  461. tasklet_schedule(&sc->bcon_tasklet);
  462. if (status & ATH9K_INT_TXURN)
  463. ath9k_hw_updatetxtriglevel(ah, true);
  464. if (status & ATH9K_INT_RXEOL) {
  465. ah->imask &= ~(ATH9K_INT_RXEOL | ATH9K_INT_RXORN);
  466. ath9k_hw_set_interrupts(ah);
  467. }
  468. if (!(ah->caps.hw_caps & ATH9K_HW_CAP_AUTOSLEEP))
  469. if (status & ATH9K_INT_TIM_TIMER) {
  470. if (ATH_DBG_WARN_ON_ONCE(sc->ps_idle))
  471. goto chip_reset;
  472. /* Clear RxAbort bit so that we can
  473. * receive frames */
  474. ath9k_setpower(sc, ATH9K_PM_AWAKE);
  475. spin_lock(&sc->sc_pm_lock);
  476. ath9k_hw_setrxabort(sc->sc_ah, 0);
  477. sc->ps_flags |= PS_WAIT_FOR_BEACON;
  478. spin_unlock(&sc->sc_pm_lock);
  479. }
  480. chip_reset:
  481. ath_debug_stat_interrupt(sc, status);
  482. if (sched) {
  483. /* turn off every interrupt */
  484. ath9k_hw_disable_interrupts(ah);
  485. tasklet_schedule(&sc->intr_tq);
  486. }
  487. return IRQ_HANDLED;
  488. #undef SCHED_INTR
  489. }
  490. int ath_reset(struct ath_softc *sc)
  491. {
  492. int r;
  493. ath9k_ps_wakeup(sc);
  494. r = ath_reset_internal(sc, NULL);
  495. ath9k_ps_restore(sc);
  496. return r;
  497. }
  498. void ath9k_queue_reset(struct ath_softc *sc, enum ath_reset_type type)
  499. {
  500. struct ath_common *common = ath9k_hw_common(sc->sc_ah);
  501. #ifdef CONFIG_ATH9K_DEBUGFS
  502. RESET_STAT_INC(sc, type);
  503. #endif
  504. set_bit(ATH_OP_HW_RESET, &common->op_flags);
  505. ieee80211_queue_work(sc->hw, &sc->hw_reset_work);
  506. }
  507. void ath_reset_work(struct work_struct *work)
  508. {
  509. struct ath_softc *sc = container_of(work, struct ath_softc, hw_reset_work);
  510. ath_reset(sc);
  511. }
  512. /**********************/
  513. /* mac80211 callbacks */
  514. /**********************/
  515. static int ath9k_start(struct ieee80211_hw *hw)
  516. {
  517. struct ath_softc *sc = hw->priv;
  518. struct ath_hw *ah = sc->sc_ah;
  519. struct ath_common *common = ath9k_hw_common(ah);
  520. struct ieee80211_channel *curchan = sc->cur_chan->chandef.chan;
  521. struct ath_chanctx *ctx = sc->cur_chan;
  522. struct ath9k_channel *init_channel;
  523. int r;
  524. ath_dbg(common, CONFIG,
  525. "Starting driver with initial channel: %d MHz\n",
  526. curchan->center_freq);
  527. ath9k_ps_wakeup(sc);
  528. mutex_lock(&sc->mutex);
  529. init_channel = ath9k_cmn_get_channel(hw, ah, &ctx->chandef);
  530. sc->cur_chandef = hw->conf.chandef;
  531. /* Reset SERDES registers */
  532. ath9k_hw_configpcipowersave(ah, false);
  533. /*
  534. * The basic interface to setting the hardware in a good
  535. * state is ``reset''. On return the hardware is known to
  536. * be powered up and with interrupts disabled. This must
  537. * be followed by initialization of the appropriate bits
  538. * and then setup of the interrupt mask.
  539. */
  540. spin_lock_bh(&sc->sc_pcu_lock);
  541. atomic_set(&ah->intr_ref_cnt, -1);
  542. r = ath9k_hw_reset(ah, init_channel, ah->caldata, false);
  543. if (r) {
  544. ath_err(common,
  545. "Unable to reset hardware; reset status %d (freq %u MHz)\n",
  546. r, curchan->center_freq);
  547. ah->reset_power_on = false;
  548. }
  549. /* Setup our intr mask. */
  550. ah->imask = ATH9K_INT_TX | ATH9K_INT_RXEOL |
  551. ATH9K_INT_RXORN | ATH9K_INT_FATAL |
  552. ATH9K_INT_GLOBAL;
  553. if (ah->caps.hw_caps & ATH9K_HW_CAP_EDMA)
  554. ah->imask |= ATH9K_INT_RXHP |
  555. ATH9K_INT_RXLP;
  556. else
  557. ah->imask |= ATH9K_INT_RX;
  558. if (ah->config.hw_hang_checks & HW_BB_WATCHDOG)
  559. ah->imask |= ATH9K_INT_BB_WATCHDOG;
  560. /*
  561. * Enable GTT interrupts only for AR9003/AR9004 chips
  562. * for now.
  563. */
  564. if (AR_SREV_9300_20_OR_LATER(ah))
  565. ah->imask |= ATH9K_INT_GTT;
  566. if (ah->caps.hw_caps & ATH9K_HW_CAP_HT)
  567. ah->imask |= ATH9K_INT_CST;
  568. ath_mci_enable(sc);
  569. clear_bit(ATH_OP_INVALID, &common->op_flags);
  570. sc->sc_ah->is_monitoring = false;
  571. if (!ath_complete_reset(sc, false))
  572. ah->reset_power_on = false;
  573. if (ah->led_pin >= 0) {
  574. ath9k_hw_cfg_output(ah, ah->led_pin,
  575. AR_GPIO_OUTPUT_MUX_AS_OUTPUT);
  576. ath9k_hw_set_gpio(ah, ah->led_pin, 0);
  577. }
  578. /*
  579. * Reset key cache to sane defaults (all entries cleared) instead of
  580. * semi-random values after suspend/resume.
  581. */
  582. ath9k_cmn_init_crypto(sc->sc_ah);
  583. ath9k_hw_reset_tsf(ah);
  584. spin_unlock_bh(&sc->sc_pcu_lock);
  585. mutex_unlock(&sc->mutex);
  586. ath9k_ps_restore(sc);
  587. return 0;
  588. }
  589. static void ath9k_tx(struct ieee80211_hw *hw,
  590. struct ieee80211_tx_control *control,
  591. struct sk_buff *skb)
  592. {
  593. struct ath_softc *sc = hw->priv;
  594. struct ath_common *common = ath9k_hw_common(sc->sc_ah);
  595. struct ath_tx_control txctl;
  596. struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
  597. unsigned long flags;
  598. if (sc->ps_enabled) {
  599. /*
  600. * mac80211 does not set PM field for normal data frames, so we
  601. * need to update that based on the current PS mode.
  602. */
  603. if (ieee80211_is_data(hdr->frame_control) &&
  604. !ieee80211_is_nullfunc(hdr->frame_control) &&
  605. !ieee80211_has_pm(hdr->frame_control)) {
  606. ath_dbg(common, PS,
  607. "Add PM=1 for a TX frame while in PS mode\n");
  608. hdr->frame_control |= cpu_to_le16(IEEE80211_FCTL_PM);
  609. }
  610. }
  611. if (unlikely(sc->sc_ah->power_mode == ATH9K_PM_NETWORK_SLEEP)) {
  612. /*
  613. * We are using PS-Poll and mac80211 can request TX while in
  614. * power save mode. Need to wake up hardware for the TX to be
  615. * completed and if needed, also for RX of buffered frames.
  616. */
  617. ath9k_ps_wakeup(sc);
  618. spin_lock_irqsave(&sc->sc_pm_lock, flags);
  619. if (!(sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_AUTOSLEEP))
  620. ath9k_hw_setrxabort(sc->sc_ah, 0);
  621. if (ieee80211_is_pspoll(hdr->frame_control)) {
  622. ath_dbg(common, PS,
  623. "Sending PS-Poll to pick a buffered frame\n");
  624. sc->ps_flags |= PS_WAIT_FOR_PSPOLL_DATA;
  625. } else {
  626. ath_dbg(common, PS, "Wake up to complete TX\n");
  627. sc->ps_flags |= PS_WAIT_FOR_TX_ACK;
  628. }
  629. /*
  630. * The actual restore operation will happen only after
  631. * the ps_flags bit is cleared. We are just dropping
  632. * the ps_usecount here.
  633. */
  634. spin_unlock_irqrestore(&sc->sc_pm_lock, flags);
  635. ath9k_ps_restore(sc);
  636. }
  637. /*
  638. * Cannot tx while the hardware is in full sleep, it first needs a full
  639. * chip reset to recover from that
  640. */
  641. if (unlikely(sc->sc_ah->power_mode == ATH9K_PM_FULL_SLEEP)) {
  642. ath_err(common, "TX while HW is in FULL_SLEEP mode\n");
  643. goto exit;
  644. }
  645. memset(&txctl, 0, sizeof(struct ath_tx_control));
  646. txctl.txq = sc->tx.txq_map[skb_get_queue_mapping(skb)];
  647. txctl.sta = control->sta;
  648. ath_dbg(common, XMIT, "transmitting packet, skb: %p\n", skb);
  649. if (ath_tx_start(hw, skb, &txctl) != 0) {
  650. ath_dbg(common, XMIT, "TX failed\n");
  651. TX_STAT_INC(txctl.txq->axq_qnum, txfailed);
  652. goto exit;
  653. }
  654. return;
  655. exit:
  656. ieee80211_free_txskb(hw, skb);
  657. }
  658. static void ath9k_stop(struct ieee80211_hw *hw)
  659. {
  660. struct ath_softc *sc = hw->priv;
  661. struct ath_hw *ah = sc->sc_ah;
  662. struct ath_common *common = ath9k_hw_common(ah);
  663. bool prev_idle;
  664. ath9k_deinit_channel_context(sc);
  665. mutex_lock(&sc->mutex);
  666. ath_cancel_work(sc);
  667. if (test_bit(ATH_OP_INVALID, &common->op_flags)) {
  668. ath_dbg(common, ANY, "Device not present\n");
  669. mutex_unlock(&sc->mutex);
  670. return;
  671. }
  672. /* Ensure HW is awake when we try to shut it down. */
  673. ath9k_ps_wakeup(sc);
  674. spin_lock_bh(&sc->sc_pcu_lock);
  675. /* prevent tasklets to enable interrupts once we disable them */
  676. ah->imask &= ~ATH9K_INT_GLOBAL;
  677. /* make sure h/w will not generate any interrupt
  678. * before setting the invalid flag. */
  679. ath9k_hw_disable_interrupts(ah);
  680. spin_unlock_bh(&sc->sc_pcu_lock);
  681. /* we can now sync irq and kill any running tasklets, since we already
  682. * disabled interrupts and not holding a spin lock */
  683. synchronize_irq(sc->irq);
  684. tasklet_kill(&sc->intr_tq);
  685. tasklet_kill(&sc->bcon_tasklet);
  686. prev_idle = sc->ps_idle;
  687. sc->ps_idle = true;
  688. spin_lock_bh(&sc->sc_pcu_lock);
  689. if (ah->led_pin >= 0) {
  690. ath9k_hw_set_gpio(ah, ah->led_pin, 1);
  691. ath9k_hw_cfg_gpio_input(ah, ah->led_pin);
  692. }
  693. ath_prepare_reset(sc);
  694. if (sc->rx.frag) {
  695. dev_kfree_skb_any(sc->rx.frag);
  696. sc->rx.frag = NULL;
  697. }
  698. if (!ah->curchan)
  699. ah->curchan = ath9k_cmn_get_channel(hw, ah,
  700. &sc->cur_chan->chandef);
  701. ath9k_hw_reset(ah, ah->curchan, ah->caldata, false);
  702. ath9k_hw_phy_disable(ah);
  703. ath9k_hw_configpcipowersave(ah, true);
  704. spin_unlock_bh(&sc->sc_pcu_lock);
  705. ath9k_ps_restore(sc);
  706. set_bit(ATH_OP_INVALID, &common->op_flags);
  707. sc->ps_idle = prev_idle;
  708. mutex_unlock(&sc->mutex);
  709. ath_dbg(common, CONFIG, "Driver halt\n");
  710. }
  711. static bool ath9k_uses_beacons(int type)
  712. {
  713. switch (type) {
  714. case NL80211_IFTYPE_AP:
  715. case NL80211_IFTYPE_ADHOC:
  716. case NL80211_IFTYPE_MESH_POINT:
  717. return true;
  718. default:
  719. return false;
  720. }
  721. }
  722. static void ath9k_vif_iter(struct ath9k_vif_iter_data *iter_data,
  723. u8 *mac, struct ieee80211_vif *vif)
  724. {
  725. struct ath_vif *avp = (struct ath_vif *)vif->drv_priv;
  726. int i;
  727. if (iter_data->has_hw_macaddr) {
  728. for (i = 0; i < ETH_ALEN; i++)
  729. iter_data->mask[i] &=
  730. ~(iter_data->hw_macaddr[i] ^ mac[i]);
  731. } else {
  732. memcpy(iter_data->hw_macaddr, mac, ETH_ALEN);
  733. iter_data->has_hw_macaddr = true;
  734. }
  735. if (!vif->bss_conf.use_short_slot)
  736. iter_data->slottime = ATH9K_SLOT_TIME_20;
  737. switch (vif->type) {
  738. case NL80211_IFTYPE_AP:
  739. iter_data->naps++;
  740. break;
  741. case NL80211_IFTYPE_STATION:
  742. iter_data->nstations++;
  743. if (avp->assoc && !iter_data->primary_sta)
  744. iter_data->primary_sta = vif;
  745. break;
  746. case NL80211_IFTYPE_ADHOC:
  747. iter_data->nadhocs++;
  748. if (vif->bss_conf.enable_beacon)
  749. iter_data->beacons = true;
  750. break;
  751. case NL80211_IFTYPE_MESH_POINT:
  752. iter_data->nmeshes++;
  753. if (vif->bss_conf.enable_beacon)
  754. iter_data->beacons = true;
  755. break;
  756. case NL80211_IFTYPE_WDS:
  757. iter_data->nwds++;
  758. break;
  759. default:
  760. break;
  761. }
  762. }
  763. static void ath9k_update_bssid_mask(struct ath_softc *sc,
  764. struct ath_chanctx *ctx,
  765. struct ath9k_vif_iter_data *iter_data)
  766. {
  767. struct ath_common *common = ath9k_hw_common(sc->sc_ah);
  768. struct ath_vif *avp;
  769. int i;
  770. if (!ath9k_is_chanctx_enabled())
  771. return;
  772. list_for_each_entry(avp, &ctx->vifs, list) {
  773. if (ctx->nvifs_assigned != 1)
  774. continue;
  775. if (!avp->vif->p2p || !iter_data->has_hw_macaddr)
  776. continue;
  777. ether_addr_copy(common->curbssid, avp->bssid);
  778. /* perm_addr will be used as the p2p device address. */
  779. for (i = 0; i < ETH_ALEN; i++)
  780. iter_data->mask[i] &=
  781. ~(iter_data->hw_macaddr[i] ^
  782. sc->hw->wiphy->perm_addr[i]);
  783. }
  784. }
  785. /* Called with sc->mutex held. */
  786. void ath9k_calculate_iter_data(struct ath_softc *sc,
  787. struct ath_chanctx *ctx,
  788. struct ath9k_vif_iter_data *iter_data)
  789. {
  790. struct ath_vif *avp;
  791. /*
  792. * Pick the MAC address of the first interface as the new hardware
  793. * MAC address. The hardware will use it together with the BSSID mask
  794. * when matching addresses.
  795. */
  796. memset(iter_data, 0, sizeof(*iter_data));
  797. memset(&iter_data->mask, 0xff, ETH_ALEN);
  798. iter_data->slottime = ATH9K_SLOT_TIME_9;
  799. list_for_each_entry(avp, &ctx->vifs, list)
  800. ath9k_vif_iter(iter_data, avp->vif->addr, avp->vif);
  801. ath9k_update_bssid_mask(sc, ctx, iter_data);
  802. }
  803. static void ath9k_set_assoc_state(struct ath_softc *sc,
  804. struct ieee80211_vif *vif, bool changed)
  805. {
  806. struct ath_common *common = ath9k_hw_common(sc->sc_ah);
  807. struct ath_vif *avp = (struct ath_vif *)vif->drv_priv;
  808. unsigned long flags;
  809. set_bit(ATH_OP_PRIM_STA_VIF, &common->op_flags);
  810. ether_addr_copy(common->curbssid, avp->bssid);
  811. common->curaid = avp->aid;
  812. ath9k_hw_write_associd(sc->sc_ah);
  813. if (changed) {
  814. common->last_rssi = ATH_RSSI_DUMMY_MARKER;
  815. sc->sc_ah->stats.avgbrssi = ATH_RSSI_DUMMY_MARKER;
  816. spin_lock_irqsave(&sc->sc_pm_lock, flags);
  817. sc->ps_flags |= PS_BEACON_SYNC | PS_WAIT_FOR_BEACON;
  818. spin_unlock_irqrestore(&sc->sc_pm_lock, flags);
  819. }
  820. if (ath9k_hw_mci_is_enabled(sc->sc_ah))
  821. ath9k_mci_update_wlan_channels(sc, false);
  822. ath_dbg(common, CONFIG,
  823. "Primary Station interface: %pM, BSSID: %pM\n",
  824. vif->addr, common->curbssid);
  825. }
  826. #ifdef CONFIG_ATH9K_CHANNEL_CONTEXT
  827. static void ath9k_set_offchannel_state(struct ath_softc *sc)
  828. {
  829. struct ath_hw *ah = sc->sc_ah;
  830. struct ath_common *common = ath9k_hw_common(ah);
  831. struct ieee80211_vif *vif = NULL;
  832. ath9k_ps_wakeup(sc);
  833. if (sc->offchannel.state < ATH_OFFCHANNEL_ROC_START)
  834. vif = sc->offchannel.scan_vif;
  835. else
  836. vif = sc->offchannel.roc_vif;
  837. if (WARN_ON(!vif))
  838. goto exit;
  839. eth_zero_addr(common->curbssid);
  840. eth_broadcast_addr(common->bssidmask);
  841. ether_addr_copy(common->macaddr, vif->addr);
  842. common->curaid = 0;
  843. ah->opmode = vif->type;
  844. ah->imask &= ~ATH9K_INT_SWBA;
  845. ah->imask &= ~ATH9K_INT_TSFOOR;
  846. ah->slottime = ATH9K_SLOT_TIME_9;
  847. ath_hw_setbssidmask(common);
  848. ath9k_hw_setopmode(ah);
  849. ath9k_hw_write_associd(sc->sc_ah);
  850. ath9k_hw_set_interrupts(ah);
  851. ath9k_hw_init_global_settings(ah);
  852. exit:
  853. ath9k_ps_restore(sc);
  854. }
  855. #endif
  856. /* Called with sc->mutex held. */
  857. void ath9k_calculate_summary_state(struct ath_softc *sc,
  858. struct ath_chanctx *ctx)
  859. {
  860. struct ath_hw *ah = sc->sc_ah;
  861. struct ath_common *common = ath9k_hw_common(ah);
  862. struct ath9k_vif_iter_data iter_data;
  863. struct ath_beacon_config *cur_conf;
  864. ath_chanctx_check_active(sc, ctx);
  865. if (ctx != sc->cur_chan)
  866. return;
  867. #ifdef CONFIG_ATH9K_CHANNEL_CONTEXT
  868. if (ctx == &sc->offchannel.chan)
  869. return ath9k_set_offchannel_state(sc);
  870. #endif
  871. ath9k_ps_wakeup(sc);
  872. ath9k_calculate_iter_data(sc, ctx, &iter_data);
  873. if (iter_data.has_hw_macaddr)
  874. ether_addr_copy(common->macaddr, iter_data.hw_macaddr);
  875. memcpy(common->bssidmask, iter_data.mask, ETH_ALEN);
  876. ath_hw_setbssidmask(common);
  877. if (iter_data.naps > 0) {
  878. cur_conf = &ctx->beacon;
  879. ath9k_hw_set_tsfadjust(ah, true);
  880. ah->opmode = NL80211_IFTYPE_AP;
  881. if (cur_conf->enable_beacon)
  882. iter_data.beacons = true;
  883. } else {
  884. ath9k_hw_set_tsfadjust(ah, false);
  885. if (iter_data.nmeshes)
  886. ah->opmode = NL80211_IFTYPE_MESH_POINT;
  887. else if (iter_data.nwds)
  888. ah->opmode = NL80211_IFTYPE_AP;
  889. else if (iter_data.nadhocs)
  890. ah->opmode = NL80211_IFTYPE_ADHOC;
  891. else
  892. ah->opmode = NL80211_IFTYPE_STATION;
  893. }
  894. ath9k_hw_setopmode(ah);
  895. ctx->switch_after_beacon = false;
  896. if ((iter_data.nstations + iter_data.nadhocs + iter_data.nmeshes) > 0)
  897. ah->imask |= ATH9K_INT_TSFOOR;
  898. else {
  899. ah->imask &= ~ATH9K_INT_TSFOOR;
  900. if (iter_data.naps == 1 && iter_data.beacons)
  901. ctx->switch_after_beacon = true;
  902. }
  903. ah->imask &= ~ATH9K_INT_SWBA;
  904. if (ah->opmode == NL80211_IFTYPE_STATION) {
  905. bool changed = (iter_data.primary_sta != ctx->primary_sta);
  906. if (iter_data.primary_sta) {
  907. iter_data.beacons = true;
  908. ath9k_set_assoc_state(sc, iter_data.primary_sta,
  909. changed);
  910. ctx->primary_sta = iter_data.primary_sta;
  911. } else {
  912. ctx->primary_sta = NULL;
  913. memset(common->curbssid, 0, ETH_ALEN);
  914. common->curaid = 0;
  915. ath9k_hw_write_associd(sc->sc_ah);
  916. if (ath9k_hw_mci_is_enabled(sc->sc_ah))
  917. ath9k_mci_update_wlan_channels(sc, true);
  918. }
  919. } else if (iter_data.beacons) {
  920. ah->imask |= ATH9K_INT_SWBA;
  921. }
  922. ath9k_hw_set_interrupts(ah);
  923. if (iter_data.beacons)
  924. set_bit(ATH_OP_BEACONS, &common->op_flags);
  925. else
  926. clear_bit(ATH_OP_BEACONS, &common->op_flags);
  927. if (ah->slottime != iter_data.slottime) {
  928. ah->slottime = iter_data.slottime;
  929. ath9k_hw_init_global_settings(ah);
  930. }
  931. if (iter_data.primary_sta)
  932. set_bit(ATH_OP_PRIM_STA_VIF, &common->op_flags);
  933. else
  934. clear_bit(ATH_OP_PRIM_STA_VIF, &common->op_flags);
  935. ath_dbg(common, CONFIG,
  936. "macaddr: %pM, bssid: %pM, bssidmask: %pM\n",
  937. common->macaddr, common->curbssid, common->bssidmask);
  938. ath9k_ps_restore(sc);
  939. }
  940. static void ath9k_assign_hw_queues(struct ieee80211_hw *hw,
  941. struct ieee80211_vif *vif)
  942. {
  943. int i;
  944. if (!ath9k_is_chanctx_enabled())
  945. return;
  946. for (i = 0; i < IEEE80211_NUM_ACS; i++)
  947. vif->hw_queue[i] = i;
  948. if (vif->type == NL80211_IFTYPE_AP)
  949. vif->cab_queue = hw->queues - 2;
  950. else
  951. vif->cab_queue = IEEE80211_INVAL_HW_QUEUE;
  952. }
  953. static int ath9k_add_interface(struct ieee80211_hw *hw,
  954. struct ieee80211_vif *vif)
  955. {
  956. struct ath_softc *sc = hw->priv;
  957. struct ath_hw *ah = sc->sc_ah;
  958. struct ath_common *common = ath9k_hw_common(ah);
  959. struct ath_vif *avp = (void *)vif->drv_priv;
  960. struct ath_node *an = &avp->mcast_node;
  961. mutex_lock(&sc->mutex);
  962. if (config_enabled(CONFIG_ATH9K_TX99)) {
  963. if (sc->cur_chan->nvifs >= 1) {
  964. mutex_unlock(&sc->mutex);
  965. return -EOPNOTSUPP;
  966. }
  967. sc->tx99_vif = vif;
  968. }
  969. ath_dbg(common, CONFIG, "Attach a VIF of type: %d\n", vif->type);
  970. sc->cur_chan->nvifs++;
  971. if (ath9k_uses_beacons(vif->type))
  972. ath9k_beacon_assign_slot(sc, vif);
  973. avp->vif = vif;
  974. if (!ath9k_is_chanctx_enabled()) {
  975. avp->chanctx = sc->cur_chan;
  976. list_add_tail(&avp->list, &avp->chanctx->vifs);
  977. }
  978. ath9k_assign_hw_queues(hw, vif);
  979. an->sc = sc;
  980. an->sta = NULL;
  981. an->vif = vif;
  982. an->no_ps_filter = true;
  983. ath_tx_node_init(sc, an);
  984. mutex_unlock(&sc->mutex);
  985. return 0;
  986. }
  987. static int ath9k_change_interface(struct ieee80211_hw *hw,
  988. struct ieee80211_vif *vif,
  989. enum nl80211_iftype new_type,
  990. bool p2p)
  991. {
  992. struct ath_softc *sc = hw->priv;
  993. struct ath_common *common = ath9k_hw_common(sc->sc_ah);
  994. struct ath_vif *avp = (void *)vif->drv_priv;
  995. mutex_lock(&sc->mutex);
  996. if (config_enabled(CONFIG_ATH9K_TX99)) {
  997. mutex_unlock(&sc->mutex);
  998. return -EOPNOTSUPP;
  999. }
  1000. ath_dbg(common, CONFIG, "Change Interface\n");
  1001. if (ath9k_uses_beacons(vif->type))
  1002. ath9k_beacon_remove_slot(sc, vif);
  1003. vif->type = new_type;
  1004. vif->p2p = p2p;
  1005. if (ath9k_uses_beacons(vif->type))
  1006. ath9k_beacon_assign_slot(sc, vif);
  1007. ath9k_assign_hw_queues(hw, vif);
  1008. ath9k_calculate_summary_state(sc, avp->chanctx);
  1009. mutex_unlock(&sc->mutex);
  1010. return 0;
  1011. }
  1012. static void ath9k_remove_interface(struct ieee80211_hw *hw,
  1013. struct ieee80211_vif *vif)
  1014. {
  1015. struct ath_softc *sc = hw->priv;
  1016. struct ath_common *common = ath9k_hw_common(sc->sc_ah);
  1017. struct ath_vif *avp = (void *)vif->drv_priv;
  1018. ath_dbg(common, CONFIG, "Detach Interface\n");
  1019. mutex_lock(&sc->mutex);
  1020. ath9k_p2p_remove_vif(sc, vif);
  1021. sc->cur_chan->nvifs--;
  1022. sc->tx99_vif = NULL;
  1023. if (!ath9k_is_chanctx_enabled())
  1024. list_del(&avp->list);
  1025. if (ath9k_uses_beacons(vif->type))
  1026. ath9k_beacon_remove_slot(sc, vif);
  1027. ath_tx_node_cleanup(sc, &avp->mcast_node);
  1028. mutex_unlock(&sc->mutex);
  1029. }
  1030. static void ath9k_enable_ps(struct ath_softc *sc)
  1031. {
  1032. struct ath_hw *ah = sc->sc_ah;
  1033. struct ath_common *common = ath9k_hw_common(ah);
  1034. if (config_enabled(CONFIG_ATH9K_TX99))
  1035. return;
  1036. sc->ps_enabled = true;
  1037. if (!(ah->caps.hw_caps & ATH9K_HW_CAP_AUTOSLEEP)) {
  1038. if ((ah->imask & ATH9K_INT_TIM_TIMER) == 0) {
  1039. ah->imask |= ATH9K_INT_TIM_TIMER;
  1040. ath9k_hw_set_interrupts(ah);
  1041. }
  1042. ath9k_hw_setrxabort(ah, 1);
  1043. }
  1044. ath_dbg(common, PS, "PowerSave enabled\n");
  1045. }
  1046. static void ath9k_disable_ps(struct ath_softc *sc)
  1047. {
  1048. struct ath_hw *ah = sc->sc_ah;
  1049. struct ath_common *common = ath9k_hw_common(ah);
  1050. if (config_enabled(CONFIG_ATH9K_TX99))
  1051. return;
  1052. sc->ps_enabled = false;
  1053. ath9k_hw_setpower(ah, ATH9K_PM_AWAKE);
  1054. if (!(ah->caps.hw_caps & ATH9K_HW_CAP_AUTOSLEEP)) {
  1055. ath9k_hw_setrxabort(ah, 0);
  1056. sc->ps_flags &= ~(PS_WAIT_FOR_BEACON |
  1057. PS_WAIT_FOR_CAB |
  1058. PS_WAIT_FOR_PSPOLL_DATA |
  1059. PS_WAIT_FOR_TX_ACK);
  1060. if (ah->imask & ATH9K_INT_TIM_TIMER) {
  1061. ah->imask &= ~ATH9K_INT_TIM_TIMER;
  1062. ath9k_hw_set_interrupts(ah);
  1063. }
  1064. }
  1065. ath_dbg(common, PS, "PowerSave disabled\n");
  1066. }
  1067. void ath9k_spectral_scan_trigger(struct ieee80211_hw *hw)
  1068. {
  1069. struct ath_softc *sc = hw->priv;
  1070. struct ath_hw *ah = sc->sc_ah;
  1071. struct ath_common *common = ath9k_hw_common(ah);
  1072. u32 rxfilter;
  1073. if (config_enabled(CONFIG_ATH9K_TX99))
  1074. return;
  1075. if (!ath9k_hw_ops(ah)->spectral_scan_trigger) {
  1076. ath_err(common, "spectrum analyzer not implemented on this hardware\n");
  1077. return;
  1078. }
  1079. ath9k_ps_wakeup(sc);
  1080. rxfilter = ath9k_hw_getrxfilter(ah);
  1081. ath9k_hw_setrxfilter(ah, rxfilter |
  1082. ATH9K_RX_FILTER_PHYRADAR |
  1083. ATH9K_RX_FILTER_PHYERR);
  1084. /* TODO: usually this should not be neccesary, but for some reason
  1085. * (or in some mode?) the trigger must be called after the
  1086. * configuration, otherwise the register will have its values reset
  1087. * (on my ar9220 to value 0x01002310)
  1088. */
  1089. ath9k_spectral_scan_config(hw, sc->spectral_mode);
  1090. ath9k_hw_ops(ah)->spectral_scan_trigger(ah);
  1091. ath9k_ps_restore(sc);
  1092. }
  1093. int ath9k_spectral_scan_config(struct ieee80211_hw *hw,
  1094. enum spectral_mode spectral_mode)
  1095. {
  1096. struct ath_softc *sc = hw->priv;
  1097. struct ath_hw *ah = sc->sc_ah;
  1098. struct ath_common *common = ath9k_hw_common(ah);
  1099. if (!ath9k_hw_ops(ah)->spectral_scan_trigger) {
  1100. ath_err(common, "spectrum analyzer not implemented on this hardware\n");
  1101. return -1;
  1102. }
  1103. switch (spectral_mode) {
  1104. case SPECTRAL_DISABLED:
  1105. sc->spec_config.enabled = 0;
  1106. break;
  1107. case SPECTRAL_BACKGROUND:
  1108. /* send endless samples.
  1109. * TODO: is this really useful for "background"?
  1110. */
  1111. sc->spec_config.endless = 1;
  1112. sc->spec_config.enabled = 1;
  1113. break;
  1114. case SPECTRAL_CHANSCAN:
  1115. case SPECTRAL_MANUAL:
  1116. sc->spec_config.endless = 0;
  1117. sc->spec_config.enabled = 1;
  1118. break;
  1119. default:
  1120. return -1;
  1121. }
  1122. ath9k_ps_wakeup(sc);
  1123. ath9k_hw_ops(ah)->spectral_scan_config(ah, &sc->spec_config);
  1124. ath9k_ps_restore(sc);
  1125. sc->spectral_mode = spectral_mode;
  1126. return 0;
  1127. }
  1128. static int ath9k_config(struct ieee80211_hw *hw, u32 changed)
  1129. {
  1130. struct ath_softc *sc = hw->priv;
  1131. struct ath_hw *ah = sc->sc_ah;
  1132. struct ath_common *common = ath9k_hw_common(ah);
  1133. struct ieee80211_conf *conf = &hw->conf;
  1134. struct ath_chanctx *ctx = sc->cur_chan;
  1135. ath9k_ps_wakeup(sc);
  1136. mutex_lock(&sc->mutex);
  1137. if (changed & IEEE80211_CONF_CHANGE_IDLE) {
  1138. sc->ps_idle = !!(conf->flags & IEEE80211_CONF_IDLE);
  1139. if (sc->ps_idle) {
  1140. ath_cancel_work(sc);
  1141. ath9k_stop_btcoex(sc);
  1142. } else {
  1143. ath9k_start_btcoex(sc);
  1144. /*
  1145. * The chip needs a reset to properly wake up from
  1146. * full sleep
  1147. */
  1148. ath_chanctx_set_channel(sc, ctx, &ctx->chandef);
  1149. }
  1150. }
  1151. /*
  1152. * We just prepare to enable PS. We have to wait until our AP has
  1153. * ACK'd our null data frame to disable RX otherwise we'll ignore
  1154. * those ACKs and end up retransmitting the same null data frames.
  1155. * IEEE80211_CONF_CHANGE_PS is only passed by mac80211 for STA mode.
  1156. */
  1157. if (changed & IEEE80211_CONF_CHANGE_PS) {
  1158. unsigned long flags;
  1159. spin_lock_irqsave(&sc->sc_pm_lock, flags);
  1160. if (conf->flags & IEEE80211_CONF_PS)
  1161. ath9k_enable_ps(sc);
  1162. else
  1163. ath9k_disable_ps(sc);
  1164. spin_unlock_irqrestore(&sc->sc_pm_lock, flags);
  1165. }
  1166. if (changed & IEEE80211_CONF_CHANGE_MONITOR) {
  1167. if (conf->flags & IEEE80211_CONF_MONITOR) {
  1168. ath_dbg(common, CONFIG, "Monitor mode is enabled\n");
  1169. sc->sc_ah->is_monitoring = true;
  1170. } else {
  1171. ath_dbg(common, CONFIG, "Monitor mode is disabled\n");
  1172. sc->sc_ah->is_monitoring = false;
  1173. }
  1174. }
  1175. if (!ath9k_is_chanctx_enabled() && (changed & IEEE80211_CONF_CHANGE_CHANNEL)) {
  1176. ctx->offchannel = !!(conf->flags & IEEE80211_CONF_OFFCHANNEL);
  1177. ath_chanctx_set_channel(sc, ctx, &hw->conf.chandef);
  1178. }
  1179. if (changed & IEEE80211_CONF_CHANGE_POWER) {
  1180. ath_dbg(common, CONFIG, "Set power: %d\n", conf->power_level);
  1181. sc->cur_chan->txpower = 2 * conf->power_level;
  1182. ath9k_cmn_update_txpow(ah, sc->curtxpow,
  1183. sc->cur_chan->txpower, &sc->curtxpow);
  1184. }
  1185. mutex_unlock(&sc->mutex);
  1186. ath9k_ps_restore(sc);
  1187. return 0;
  1188. }
  1189. #define SUPPORTED_FILTERS \
  1190. (FIF_PROMISC_IN_BSS | \
  1191. FIF_ALLMULTI | \
  1192. FIF_CONTROL | \
  1193. FIF_PSPOLL | \
  1194. FIF_OTHER_BSS | \
  1195. FIF_BCN_PRBRESP_PROMISC | \
  1196. FIF_PROBE_REQ | \
  1197. FIF_FCSFAIL)
  1198. /* FIXME: sc->sc_full_reset ? */
  1199. static void ath9k_configure_filter(struct ieee80211_hw *hw,
  1200. unsigned int changed_flags,
  1201. unsigned int *total_flags,
  1202. u64 multicast)
  1203. {
  1204. struct ath_softc *sc = hw->priv;
  1205. u32 rfilt;
  1206. changed_flags &= SUPPORTED_FILTERS;
  1207. *total_flags &= SUPPORTED_FILTERS;
  1208. spin_lock_bh(&sc->chan_lock);
  1209. sc->cur_chan->rxfilter = *total_flags;
  1210. spin_unlock_bh(&sc->chan_lock);
  1211. ath9k_ps_wakeup(sc);
  1212. rfilt = ath_calcrxfilter(sc);
  1213. ath9k_hw_setrxfilter(sc->sc_ah, rfilt);
  1214. ath9k_ps_restore(sc);
  1215. ath_dbg(ath9k_hw_common(sc->sc_ah), CONFIG, "Set HW RX filter: 0x%x\n",
  1216. rfilt);
  1217. }
  1218. static int ath9k_sta_add(struct ieee80211_hw *hw,
  1219. struct ieee80211_vif *vif,
  1220. struct ieee80211_sta *sta)
  1221. {
  1222. struct ath_softc *sc = hw->priv;
  1223. struct ath_common *common = ath9k_hw_common(sc->sc_ah);
  1224. struct ath_node *an = (struct ath_node *) sta->drv_priv;
  1225. struct ieee80211_key_conf ps_key = { };
  1226. int key;
  1227. ath_node_attach(sc, sta, vif);
  1228. if (vif->type != NL80211_IFTYPE_AP &&
  1229. vif->type != NL80211_IFTYPE_AP_VLAN)
  1230. return 0;
  1231. key = ath_key_config(common, vif, sta, &ps_key);
  1232. if (key > 0) {
  1233. an->ps_key = key;
  1234. an->key_idx[0] = key;
  1235. }
  1236. return 0;
  1237. }
  1238. static void ath9k_del_ps_key(struct ath_softc *sc,
  1239. struct ieee80211_vif *vif,
  1240. struct ieee80211_sta *sta)
  1241. {
  1242. struct ath_common *common = ath9k_hw_common(sc->sc_ah);
  1243. struct ath_node *an = (struct ath_node *) sta->drv_priv;
  1244. struct ieee80211_key_conf ps_key = { .hw_key_idx = an->ps_key };
  1245. if (!an->ps_key)
  1246. return;
  1247. ath_key_delete(common, &ps_key);
  1248. an->ps_key = 0;
  1249. an->key_idx[0] = 0;
  1250. }
  1251. static int ath9k_sta_remove(struct ieee80211_hw *hw,
  1252. struct ieee80211_vif *vif,
  1253. struct ieee80211_sta *sta)
  1254. {
  1255. struct ath_softc *sc = hw->priv;
  1256. ath9k_del_ps_key(sc, vif, sta);
  1257. ath_node_detach(sc, sta);
  1258. return 0;
  1259. }
  1260. static void ath9k_sta_set_tx_filter(struct ath_hw *ah,
  1261. struct ath_node *an,
  1262. bool set)
  1263. {
  1264. int i;
  1265. for (i = 0; i < ARRAY_SIZE(an->key_idx); i++) {
  1266. if (!an->key_idx[i])
  1267. continue;
  1268. ath9k_hw_set_tx_filter(ah, an->key_idx[i], set);
  1269. }
  1270. }
  1271. static void ath9k_sta_notify(struct ieee80211_hw *hw,
  1272. struct ieee80211_vif *vif,
  1273. enum sta_notify_cmd cmd,
  1274. struct ieee80211_sta *sta)
  1275. {
  1276. struct ath_softc *sc = hw->priv;
  1277. struct ath_node *an = (struct ath_node *) sta->drv_priv;
  1278. switch (cmd) {
  1279. case STA_NOTIFY_SLEEP:
  1280. an->sleeping = true;
  1281. ath_tx_aggr_sleep(sta, sc, an);
  1282. ath9k_sta_set_tx_filter(sc->sc_ah, an, true);
  1283. break;
  1284. case STA_NOTIFY_AWAKE:
  1285. ath9k_sta_set_tx_filter(sc->sc_ah, an, false);
  1286. an->sleeping = false;
  1287. ath_tx_aggr_wakeup(sc, an);
  1288. break;
  1289. }
  1290. }
  1291. static int ath9k_conf_tx(struct ieee80211_hw *hw,
  1292. struct ieee80211_vif *vif, u16 queue,
  1293. const struct ieee80211_tx_queue_params *params)
  1294. {
  1295. struct ath_softc *sc = hw->priv;
  1296. struct ath_common *common = ath9k_hw_common(sc->sc_ah);
  1297. struct ath_txq *txq;
  1298. struct ath9k_tx_queue_info qi;
  1299. int ret = 0;
  1300. if (queue >= IEEE80211_NUM_ACS)
  1301. return 0;
  1302. txq = sc->tx.txq_map[queue];
  1303. ath9k_ps_wakeup(sc);
  1304. mutex_lock(&sc->mutex);
  1305. memset(&qi, 0, sizeof(struct ath9k_tx_queue_info));
  1306. qi.tqi_aifs = params->aifs;
  1307. qi.tqi_cwmin = params->cw_min;
  1308. qi.tqi_cwmax = params->cw_max;
  1309. qi.tqi_burstTime = params->txop * 32;
  1310. ath_dbg(common, CONFIG,
  1311. "Configure tx [queue/halq] [%d/%d], aifs: %d, cw_min: %d, cw_max: %d, txop: %d\n",
  1312. queue, txq->axq_qnum, params->aifs, params->cw_min,
  1313. params->cw_max, params->txop);
  1314. ath_update_max_aggr_framelen(sc, queue, qi.tqi_burstTime);
  1315. ret = ath_txq_update(sc, txq->axq_qnum, &qi);
  1316. if (ret)
  1317. ath_err(common, "TXQ Update failed\n");
  1318. mutex_unlock(&sc->mutex);
  1319. ath9k_ps_restore(sc);
  1320. return ret;
  1321. }
  1322. static int ath9k_set_key(struct ieee80211_hw *hw,
  1323. enum set_key_cmd cmd,
  1324. struct ieee80211_vif *vif,
  1325. struct ieee80211_sta *sta,
  1326. struct ieee80211_key_conf *key)
  1327. {
  1328. struct ath_softc *sc = hw->priv;
  1329. struct ath_common *common = ath9k_hw_common(sc->sc_ah);
  1330. struct ath_node *an = NULL;
  1331. int ret = 0, i;
  1332. if (ath9k_modparam_nohwcrypt)
  1333. return -ENOSPC;
  1334. if ((vif->type == NL80211_IFTYPE_ADHOC ||
  1335. vif->type == NL80211_IFTYPE_MESH_POINT) &&
  1336. (key->cipher == WLAN_CIPHER_SUITE_TKIP ||
  1337. key->cipher == WLAN_CIPHER_SUITE_CCMP) &&
  1338. !(key->flags & IEEE80211_KEY_FLAG_PAIRWISE)) {
  1339. /*
  1340. * For now, disable hw crypto for the RSN IBSS group keys. This
  1341. * could be optimized in the future to use a modified key cache
  1342. * design to support per-STA RX GTK, but until that gets
  1343. * implemented, use of software crypto for group addressed
  1344. * frames is a acceptable to allow RSN IBSS to be used.
  1345. */
  1346. return -EOPNOTSUPP;
  1347. }
  1348. mutex_lock(&sc->mutex);
  1349. ath9k_ps_wakeup(sc);
  1350. ath_dbg(common, CONFIG, "Set HW Key %d\n", cmd);
  1351. if (sta)
  1352. an = (struct ath_node *)sta->drv_priv;
  1353. switch (cmd) {
  1354. case SET_KEY:
  1355. if (sta)
  1356. ath9k_del_ps_key(sc, vif, sta);
  1357. key->hw_key_idx = 0;
  1358. ret = ath_key_config(common, vif, sta, key);
  1359. if (ret >= 0) {
  1360. key->hw_key_idx = ret;
  1361. /* push IV and Michael MIC generation to stack */
  1362. key->flags |= IEEE80211_KEY_FLAG_GENERATE_IV;
  1363. if (key->cipher == WLAN_CIPHER_SUITE_TKIP)
  1364. key->flags |= IEEE80211_KEY_FLAG_GENERATE_MMIC;
  1365. if (sc->sc_ah->sw_mgmt_crypto &&
  1366. key->cipher == WLAN_CIPHER_SUITE_CCMP)
  1367. key->flags |= IEEE80211_KEY_FLAG_SW_MGMT_TX;
  1368. ret = 0;
  1369. }
  1370. if (an && key->hw_key_idx) {
  1371. for (i = 0; i < ARRAY_SIZE(an->key_idx); i++) {
  1372. if (an->key_idx[i])
  1373. continue;
  1374. an->key_idx[i] = key->hw_key_idx;
  1375. break;
  1376. }
  1377. WARN_ON(i == ARRAY_SIZE(an->key_idx));
  1378. }
  1379. break;
  1380. case DISABLE_KEY:
  1381. ath_key_delete(common, key);
  1382. if (an) {
  1383. for (i = 0; i < ARRAY_SIZE(an->key_idx); i++) {
  1384. if (an->key_idx[i] != key->hw_key_idx)
  1385. continue;
  1386. an->key_idx[i] = 0;
  1387. break;
  1388. }
  1389. }
  1390. key->hw_key_idx = 0;
  1391. break;
  1392. default:
  1393. ret = -EINVAL;
  1394. }
  1395. ath9k_ps_restore(sc);
  1396. mutex_unlock(&sc->mutex);
  1397. return ret;
  1398. }
  1399. static void ath9k_bss_info_changed(struct ieee80211_hw *hw,
  1400. struct ieee80211_vif *vif,
  1401. struct ieee80211_bss_conf *bss_conf,
  1402. u32 changed)
  1403. {
  1404. #define CHECK_ANI \
  1405. (BSS_CHANGED_ASSOC | \
  1406. BSS_CHANGED_IBSS | \
  1407. BSS_CHANGED_BEACON_ENABLED)
  1408. struct ath_softc *sc = hw->priv;
  1409. struct ath_hw *ah = sc->sc_ah;
  1410. struct ath_common *common = ath9k_hw_common(ah);
  1411. struct ath_vif *avp = (void *)vif->drv_priv;
  1412. int slottime;
  1413. ath9k_ps_wakeup(sc);
  1414. mutex_lock(&sc->mutex);
  1415. if (changed & BSS_CHANGED_ASSOC) {
  1416. ath_dbg(common, CONFIG, "BSSID %pM Changed ASSOC %d\n",
  1417. bss_conf->bssid, bss_conf->assoc);
  1418. ether_addr_copy(avp->bssid, bss_conf->bssid);
  1419. avp->aid = bss_conf->aid;
  1420. avp->assoc = bss_conf->assoc;
  1421. ath9k_calculate_summary_state(sc, avp->chanctx);
  1422. if (ath9k_is_chanctx_enabled()) {
  1423. if (bss_conf->assoc)
  1424. ath_chanctx_event(sc, vif,
  1425. ATH_CHANCTX_EVENT_ASSOC);
  1426. }
  1427. }
  1428. if (changed & BSS_CHANGED_IBSS) {
  1429. memcpy(common->curbssid, bss_conf->bssid, ETH_ALEN);
  1430. common->curaid = bss_conf->aid;
  1431. ath9k_hw_write_associd(sc->sc_ah);
  1432. }
  1433. if ((changed & BSS_CHANGED_BEACON_ENABLED) ||
  1434. (changed & BSS_CHANGED_BEACON_INT) ||
  1435. (changed & BSS_CHANGED_BEACON_INFO)) {
  1436. ath9k_beacon_config(sc, vif, changed);
  1437. if (changed & BSS_CHANGED_BEACON_ENABLED)
  1438. ath9k_calculate_summary_state(sc, avp->chanctx);
  1439. }
  1440. if ((avp->chanctx == sc->cur_chan) &&
  1441. (changed & BSS_CHANGED_ERP_SLOT)) {
  1442. if (bss_conf->use_short_slot)
  1443. slottime = 9;
  1444. else
  1445. slottime = 20;
  1446. if (vif->type == NL80211_IFTYPE_AP) {
  1447. /*
  1448. * Defer update, so that connected stations can adjust
  1449. * their settings at the same time.
  1450. * See beacon.c for more details
  1451. */
  1452. sc->beacon.slottime = slottime;
  1453. sc->beacon.updateslot = UPDATE;
  1454. } else {
  1455. ah->slottime = slottime;
  1456. ath9k_hw_init_global_settings(ah);
  1457. }
  1458. }
  1459. if (changed & BSS_CHANGED_P2P_PS)
  1460. ath9k_p2p_bss_info_changed(sc, vif);
  1461. if (changed & CHECK_ANI)
  1462. ath_check_ani(sc);
  1463. mutex_unlock(&sc->mutex);
  1464. ath9k_ps_restore(sc);
  1465. #undef CHECK_ANI
  1466. }
  1467. static u64 ath9k_get_tsf(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
  1468. {
  1469. struct ath_softc *sc = hw->priv;
  1470. u64 tsf;
  1471. mutex_lock(&sc->mutex);
  1472. ath9k_ps_wakeup(sc);
  1473. tsf = ath9k_hw_gettsf64(sc->sc_ah);
  1474. ath9k_ps_restore(sc);
  1475. mutex_unlock(&sc->mutex);
  1476. return tsf;
  1477. }
  1478. static void ath9k_set_tsf(struct ieee80211_hw *hw,
  1479. struct ieee80211_vif *vif,
  1480. u64 tsf)
  1481. {
  1482. struct ath_softc *sc = hw->priv;
  1483. mutex_lock(&sc->mutex);
  1484. ath9k_ps_wakeup(sc);
  1485. ath9k_hw_settsf64(sc->sc_ah, tsf);
  1486. ath9k_ps_restore(sc);
  1487. mutex_unlock(&sc->mutex);
  1488. }
  1489. static void ath9k_reset_tsf(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
  1490. {
  1491. struct ath_softc *sc = hw->priv;
  1492. mutex_lock(&sc->mutex);
  1493. ath9k_ps_wakeup(sc);
  1494. ath9k_hw_reset_tsf(sc->sc_ah);
  1495. ath9k_ps_restore(sc);
  1496. mutex_unlock(&sc->mutex);
  1497. }
  1498. static int ath9k_ampdu_action(struct ieee80211_hw *hw,
  1499. struct ieee80211_vif *vif,
  1500. enum ieee80211_ampdu_mlme_action action,
  1501. struct ieee80211_sta *sta,
  1502. u16 tid, u16 *ssn, u8 buf_size)
  1503. {
  1504. struct ath_softc *sc = hw->priv;
  1505. bool flush = false;
  1506. int ret = 0;
  1507. mutex_lock(&sc->mutex);
  1508. switch (action) {
  1509. case IEEE80211_AMPDU_RX_START:
  1510. break;
  1511. case IEEE80211_AMPDU_RX_STOP:
  1512. break;
  1513. case IEEE80211_AMPDU_TX_START:
  1514. ath9k_ps_wakeup(sc);
  1515. ret = ath_tx_aggr_start(sc, sta, tid, ssn);
  1516. if (!ret)
  1517. ieee80211_start_tx_ba_cb_irqsafe(vif, sta->addr, tid);
  1518. ath9k_ps_restore(sc);
  1519. break;
  1520. case IEEE80211_AMPDU_TX_STOP_FLUSH:
  1521. case IEEE80211_AMPDU_TX_STOP_FLUSH_CONT:
  1522. flush = true;
  1523. case IEEE80211_AMPDU_TX_STOP_CONT:
  1524. ath9k_ps_wakeup(sc);
  1525. ath_tx_aggr_stop(sc, sta, tid);
  1526. if (!flush)
  1527. ieee80211_stop_tx_ba_cb_irqsafe(vif, sta->addr, tid);
  1528. ath9k_ps_restore(sc);
  1529. break;
  1530. case IEEE80211_AMPDU_TX_OPERATIONAL:
  1531. ath9k_ps_wakeup(sc);
  1532. ath_tx_aggr_resume(sc, sta, tid);
  1533. ath9k_ps_restore(sc);
  1534. break;
  1535. default:
  1536. ath_err(ath9k_hw_common(sc->sc_ah), "Unknown AMPDU action\n");
  1537. }
  1538. mutex_unlock(&sc->mutex);
  1539. return ret;
  1540. }
  1541. static int ath9k_get_survey(struct ieee80211_hw *hw, int idx,
  1542. struct survey_info *survey)
  1543. {
  1544. struct ath_softc *sc = hw->priv;
  1545. struct ath_common *common = ath9k_hw_common(sc->sc_ah);
  1546. struct ieee80211_supported_band *sband;
  1547. struct ieee80211_channel *chan;
  1548. int pos;
  1549. if (config_enabled(CONFIG_ATH9K_TX99))
  1550. return -EOPNOTSUPP;
  1551. spin_lock_bh(&common->cc_lock);
  1552. if (idx == 0)
  1553. ath_update_survey_stats(sc);
  1554. sband = hw->wiphy->bands[IEEE80211_BAND_2GHZ];
  1555. if (sband && idx >= sband->n_channels) {
  1556. idx -= sband->n_channels;
  1557. sband = NULL;
  1558. }
  1559. if (!sband)
  1560. sband = hw->wiphy->bands[IEEE80211_BAND_5GHZ];
  1561. if (!sband || idx >= sband->n_channels) {
  1562. spin_unlock_bh(&common->cc_lock);
  1563. return -ENOENT;
  1564. }
  1565. chan = &sband->channels[idx];
  1566. pos = chan->hw_value;
  1567. memcpy(survey, &sc->survey[pos], sizeof(*survey));
  1568. survey->channel = chan;
  1569. spin_unlock_bh(&common->cc_lock);
  1570. return 0;
  1571. }
  1572. static void ath9k_enable_dynack(struct ath_softc *sc)
  1573. {
  1574. #ifdef CONFIG_ATH9K_DYNACK
  1575. u32 rfilt;
  1576. struct ath_hw *ah = sc->sc_ah;
  1577. ath_dynack_reset(ah);
  1578. ah->dynack.enabled = true;
  1579. rfilt = ath_calcrxfilter(sc);
  1580. ath9k_hw_setrxfilter(ah, rfilt);
  1581. #endif
  1582. }
  1583. static void ath9k_set_coverage_class(struct ieee80211_hw *hw,
  1584. s16 coverage_class)
  1585. {
  1586. struct ath_softc *sc = hw->priv;
  1587. struct ath_hw *ah = sc->sc_ah;
  1588. if (config_enabled(CONFIG_ATH9K_TX99))
  1589. return;
  1590. mutex_lock(&sc->mutex);
  1591. if (coverage_class >= 0) {
  1592. ah->coverage_class = coverage_class;
  1593. if (ah->dynack.enabled) {
  1594. u32 rfilt;
  1595. ah->dynack.enabled = false;
  1596. rfilt = ath_calcrxfilter(sc);
  1597. ath9k_hw_setrxfilter(ah, rfilt);
  1598. }
  1599. ath9k_ps_wakeup(sc);
  1600. ath9k_hw_init_global_settings(ah);
  1601. ath9k_ps_restore(sc);
  1602. } else if (!ah->dynack.enabled) {
  1603. ath9k_enable_dynack(sc);
  1604. }
  1605. mutex_unlock(&sc->mutex);
  1606. }
  1607. static bool ath9k_has_tx_pending(struct ath_softc *sc)
  1608. {
  1609. int i, npend = 0;
  1610. for (i = 0; i < ATH9K_NUM_TX_QUEUES; i++) {
  1611. if (!ATH_TXQ_SETUP(sc, i))
  1612. continue;
  1613. npend = ath9k_has_pending_frames(sc, &sc->tx.txq[i]);
  1614. if (npend)
  1615. break;
  1616. }
  1617. return !!npend;
  1618. }
  1619. static void ath9k_flush(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
  1620. u32 queues, bool drop)
  1621. {
  1622. struct ath_softc *sc = hw->priv;
  1623. mutex_lock(&sc->mutex);
  1624. __ath9k_flush(hw, queues, drop);
  1625. mutex_unlock(&sc->mutex);
  1626. }
  1627. void __ath9k_flush(struct ieee80211_hw *hw, u32 queues, bool drop)
  1628. {
  1629. struct ath_softc *sc = hw->priv;
  1630. struct ath_hw *ah = sc->sc_ah;
  1631. struct ath_common *common = ath9k_hw_common(ah);
  1632. int timeout = HZ / 5; /* 200 ms */
  1633. bool drain_txq;
  1634. cancel_delayed_work_sync(&sc->tx_complete_work);
  1635. if (ah->ah_flags & AH_UNPLUGGED) {
  1636. ath_dbg(common, ANY, "Device has been unplugged!\n");
  1637. return;
  1638. }
  1639. if (test_bit(ATH_OP_INVALID, &common->op_flags)) {
  1640. ath_dbg(common, ANY, "Device not present\n");
  1641. return;
  1642. }
  1643. if (wait_event_timeout(sc->tx_wait, !ath9k_has_tx_pending(sc),
  1644. timeout) > 0)
  1645. drop = false;
  1646. if (drop) {
  1647. ath9k_ps_wakeup(sc);
  1648. spin_lock_bh(&sc->sc_pcu_lock);
  1649. drain_txq = ath_drain_all_txq(sc);
  1650. spin_unlock_bh(&sc->sc_pcu_lock);
  1651. if (!drain_txq)
  1652. ath_reset(sc);
  1653. ath9k_ps_restore(sc);
  1654. }
  1655. ieee80211_queue_delayed_work(hw, &sc->tx_complete_work, 0);
  1656. }
  1657. static bool ath9k_tx_frames_pending(struct ieee80211_hw *hw)
  1658. {
  1659. struct ath_softc *sc = hw->priv;
  1660. return ath9k_has_tx_pending(sc);
  1661. }
  1662. static int ath9k_tx_last_beacon(struct ieee80211_hw *hw)
  1663. {
  1664. struct ath_softc *sc = hw->priv;
  1665. struct ath_hw *ah = sc->sc_ah;
  1666. struct ieee80211_vif *vif;
  1667. struct ath_vif *avp;
  1668. struct ath_buf *bf;
  1669. struct ath_tx_status ts;
  1670. bool edma = !!(ah->caps.hw_caps & ATH9K_HW_CAP_EDMA);
  1671. int status;
  1672. vif = sc->beacon.bslot[0];
  1673. if (!vif)
  1674. return 0;
  1675. if (!vif->bss_conf.enable_beacon)
  1676. return 0;
  1677. avp = (void *)vif->drv_priv;
  1678. if (!sc->beacon.tx_processed && !edma) {
  1679. tasklet_disable(&sc->bcon_tasklet);
  1680. bf = avp->av_bcbuf;
  1681. if (!bf || !bf->bf_mpdu)
  1682. goto skip;
  1683. status = ath9k_hw_txprocdesc(ah, bf->bf_desc, &ts);
  1684. if (status == -EINPROGRESS)
  1685. goto skip;
  1686. sc->beacon.tx_processed = true;
  1687. sc->beacon.tx_last = !(ts.ts_status & ATH9K_TXERR_MASK);
  1688. skip:
  1689. tasklet_enable(&sc->bcon_tasklet);
  1690. }
  1691. return sc->beacon.tx_last;
  1692. }
  1693. static int ath9k_get_stats(struct ieee80211_hw *hw,
  1694. struct ieee80211_low_level_stats *stats)
  1695. {
  1696. struct ath_softc *sc = hw->priv;
  1697. struct ath_hw *ah = sc->sc_ah;
  1698. struct ath9k_mib_stats *mib_stats = &ah->ah_mibStats;
  1699. stats->dot11ACKFailureCount = mib_stats->ackrcv_bad;
  1700. stats->dot11RTSFailureCount = mib_stats->rts_bad;
  1701. stats->dot11FCSErrorCount = mib_stats->fcs_bad;
  1702. stats->dot11RTSSuccessCount = mib_stats->rts_good;
  1703. return 0;
  1704. }
  1705. static u32 fill_chainmask(u32 cap, u32 new)
  1706. {
  1707. u32 filled = 0;
  1708. int i;
  1709. for (i = 0; cap && new; i++, cap >>= 1) {
  1710. if (!(cap & BIT(0)))
  1711. continue;
  1712. if (new & BIT(0))
  1713. filled |= BIT(i);
  1714. new >>= 1;
  1715. }
  1716. return filled;
  1717. }
  1718. static bool validate_antenna_mask(struct ath_hw *ah, u32 val)
  1719. {
  1720. if (AR_SREV_9300_20_OR_LATER(ah))
  1721. return true;
  1722. switch (val & 0x7) {
  1723. case 0x1:
  1724. case 0x3:
  1725. case 0x7:
  1726. return true;
  1727. case 0x2:
  1728. return (ah->caps.rx_chainmask == 1);
  1729. default:
  1730. return false;
  1731. }
  1732. }
  1733. static int ath9k_set_antenna(struct ieee80211_hw *hw, u32 tx_ant, u32 rx_ant)
  1734. {
  1735. struct ath_softc *sc = hw->priv;
  1736. struct ath_hw *ah = sc->sc_ah;
  1737. if (ah->caps.rx_chainmask != 1)
  1738. rx_ant |= tx_ant;
  1739. if (!validate_antenna_mask(ah, rx_ant) || !tx_ant)
  1740. return -EINVAL;
  1741. sc->ant_rx = rx_ant;
  1742. sc->ant_tx = tx_ant;
  1743. if (ah->caps.rx_chainmask == 1)
  1744. return 0;
  1745. /* AR9100 runs into calibration issues if not all rx chains are enabled */
  1746. if (AR_SREV_9100(ah))
  1747. ah->rxchainmask = 0x7;
  1748. else
  1749. ah->rxchainmask = fill_chainmask(ah->caps.rx_chainmask, rx_ant);
  1750. ah->txchainmask = fill_chainmask(ah->caps.tx_chainmask, tx_ant);
  1751. ath9k_cmn_reload_chainmask(ah);
  1752. return 0;
  1753. }
  1754. static int ath9k_get_antenna(struct ieee80211_hw *hw, u32 *tx_ant, u32 *rx_ant)
  1755. {
  1756. struct ath_softc *sc = hw->priv;
  1757. *tx_ant = sc->ant_tx;
  1758. *rx_ant = sc->ant_rx;
  1759. return 0;
  1760. }
  1761. static void ath9k_sw_scan_start(struct ieee80211_hw *hw)
  1762. {
  1763. struct ath_softc *sc = hw->priv;
  1764. struct ath_common *common = ath9k_hw_common(sc->sc_ah);
  1765. set_bit(ATH_OP_SCANNING, &common->op_flags);
  1766. }
  1767. static void ath9k_sw_scan_complete(struct ieee80211_hw *hw)
  1768. {
  1769. struct ath_softc *sc = hw->priv;
  1770. struct ath_common *common = ath9k_hw_common(sc->sc_ah);
  1771. clear_bit(ATH_OP_SCANNING, &common->op_flags);
  1772. }
  1773. #ifdef CONFIG_ATH9K_CHANNEL_CONTEXT
  1774. static int ath9k_hw_scan(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
  1775. struct ieee80211_scan_request *hw_req)
  1776. {
  1777. struct cfg80211_scan_request *req = &hw_req->req;
  1778. struct ath_softc *sc = hw->priv;
  1779. struct ath_common *common = ath9k_hw_common(sc->sc_ah);
  1780. int ret = 0;
  1781. mutex_lock(&sc->mutex);
  1782. if (WARN_ON(sc->offchannel.scan_req)) {
  1783. ret = -EBUSY;
  1784. goto out;
  1785. }
  1786. ath9k_ps_wakeup(sc);
  1787. set_bit(ATH_OP_SCANNING, &common->op_flags);
  1788. sc->offchannel.scan_vif = vif;
  1789. sc->offchannel.scan_req = req;
  1790. sc->offchannel.scan_idx = 0;
  1791. ath_dbg(common, CHAN_CTX, "HW scan request received on vif: %pM\n",
  1792. vif->addr);
  1793. if (sc->offchannel.state == ATH_OFFCHANNEL_IDLE) {
  1794. ath_dbg(common, CHAN_CTX, "Starting HW scan\n");
  1795. ath_offchannel_next(sc);
  1796. }
  1797. out:
  1798. mutex_unlock(&sc->mutex);
  1799. return ret;
  1800. }
  1801. static void ath9k_cancel_hw_scan(struct ieee80211_hw *hw,
  1802. struct ieee80211_vif *vif)
  1803. {
  1804. struct ath_softc *sc = hw->priv;
  1805. struct ath_common *common = ath9k_hw_common(sc->sc_ah);
  1806. ath_dbg(common, CHAN_CTX, "Cancel HW scan on vif: %pM\n", vif->addr);
  1807. mutex_lock(&sc->mutex);
  1808. del_timer_sync(&sc->offchannel.timer);
  1809. ath_scan_complete(sc, true);
  1810. mutex_unlock(&sc->mutex);
  1811. }
  1812. static int ath9k_remain_on_channel(struct ieee80211_hw *hw,
  1813. struct ieee80211_vif *vif,
  1814. struct ieee80211_channel *chan, int duration,
  1815. enum ieee80211_roc_type type)
  1816. {
  1817. struct ath_softc *sc = hw->priv;
  1818. struct ath_common *common = ath9k_hw_common(sc->sc_ah);
  1819. int ret = 0;
  1820. mutex_lock(&sc->mutex);
  1821. if (WARN_ON(sc->offchannel.roc_vif)) {
  1822. ret = -EBUSY;
  1823. goto out;
  1824. }
  1825. ath9k_ps_wakeup(sc);
  1826. sc->offchannel.roc_vif = vif;
  1827. sc->offchannel.roc_chan = chan;
  1828. sc->offchannel.roc_duration = duration;
  1829. ath_dbg(common, CHAN_CTX,
  1830. "RoC request on vif: %pM, type: %d duration: %d\n",
  1831. vif->addr, type, duration);
  1832. if (sc->offchannel.state == ATH_OFFCHANNEL_IDLE) {
  1833. ath_dbg(common, CHAN_CTX, "Starting RoC period\n");
  1834. ath_offchannel_next(sc);
  1835. }
  1836. out:
  1837. mutex_unlock(&sc->mutex);
  1838. return ret;
  1839. }
  1840. static int ath9k_cancel_remain_on_channel(struct ieee80211_hw *hw)
  1841. {
  1842. struct ath_softc *sc = hw->priv;
  1843. struct ath_common *common = ath9k_hw_common(sc->sc_ah);
  1844. mutex_lock(&sc->mutex);
  1845. ath_dbg(common, CHAN_CTX, "Cancel RoC\n");
  1846. del_timer_sync(&sc->offchannel.timer);
  1847. if (sc->offchannel.roc_vif) {
  1848. if (sc->offchannel.state >= ATH_OFFCHANNEL_ROC_START)
  1849. ath_roc_complete(sc, true);
  1850. }
  1851. mutex_unlock(&sc->mutex);
  1852. return 0;
  1853. }
  1854. static int ath9k_add_chanctx(struct ieee80211_hw *hw,
  1855. struct ieee80211_chanctx_conf *conf)
  1856. {
  1857. struct ath_softc *sc = hw->priv;
  1858. struct ath_common *common = ath9k_hw_common(sc->sc_ah);
  1859. struct ath_chanctx *ctx, **ptr;
  1860. int pos;
  1861. mutex_lock(&sc->mutex);
  1862. ath_for_each_chanctx(sc, ctx) {
  1863. if (ctx->assigned)
  1864. continue;
  1865. ptr = (void *) conf->drv_priv;
  1866. *ptr = ctx;
  1867. ctx->assigned = true;
  1868. pos = ctx - &sc->chanctx[0];
  1869. ctx->hw_queue_base = pos * IEEE80211_NUM_ACS;
  1870. ath_dbg(common, CHAN_CTX,
  1871. "Add channel context: %d MHz\n",
  1872. conf->def.chan->center_freq);
  1873. ath_chanctx_set_channel(sc, ctx, &conf->def);
  1874. ath_chanctx_event(sc, NULL, ATH_CHANCTX_EVENT_ASSIGN);
  1875. mutex_unlock(&sc->mutex);
  1876. return 0;
  1877. }
  1878. mutex_unlock(&sc->mutex);
  1879. return -ENOSPC;
  1880. }
  1881. static void ath9k_remove_chanctx(struct ieee80211_hw *hw,
  1882. struct ieee80211_chanctx_conf *conf)
  1883. {
  1884. struct ath_softc *sc = hw->priv;
  1885. struct ath_common *common = ath9k_hw_common(sc->sc_ah);
  1886. struct ath_chanctx *ctx = ath_chanctx_get(conf);
  1887. mutex_lock(&sc->mutex);
  1888. ath_dbg(common, CHAN_CTX,
  1889. "Remove channel context: %d MHz\n",
  1890. conf->def.chan->center_freq);
  1891. ctx->assigned = false;
  1892. ctx->hw_queue_base = 0;
  1893. ath_chanctx_event(sc, NULL, ATH_CHANCTX_EVENT_UNASSIGN);
  1894. mutex_unlock(&sc->mutex);
  1895. }
  1896. static void ath9k_change_chanctx(struct ieee80211_hw *hw,
  1897. struct ieee80211_chanctx_conf *conf,
  1898. u32 changed)
  1899. {
  1900. struct ath_softc *sc = hw->priv;
  1901. struct ath_common *common = ath9k_hw_common(sc->sc_ah);
  1902. struct ath_chanctx *ctx = ath_chanctx_get(conf);
  1903. mutex_lock(&sc->mutex);
  1904. ath_dbg(common, CHAN_CTX,
  1905. "Change channel context: %d MHz\n",
  1906. conf->def.chan->center_freq);
  1907. ath_chanctx_set_channel(sc, ctx, &conf->def);
  1908. mutex_unlock(&sc->mutex);
  1909. }
  1910. static int ath9k_assign_vif_chanctx(struct ieee80211_hw *hw,
  1911. struct ieee80211_vif *vif,
  1912. struct ieee80211_chanctx_conf *conf)
  1913. {
  1914. struct ath_softc *sc = hw->priv;
  1915. struct ath_common *common = ath9k_hw_common(sc->sc_ah);
  1916. struct ath_vif *avp = (void *)vif->drv_priv;
  1917. struct ath_chanctx *ctx = ath_chanctx_get(conf);
  1918. int i;
  1919. mutex_lock(&sc->mutex);
  1920. ath_dbg(common, CHAN_CTX,
  1921. "Assign VIF (addr: %pM, type: %d, p2p: %d) to channel context: %d MHz\n",
  1922. vif->addr, vif->type, vif->p2p,
  1923. conf->def.chan->center_freq);
  1924. avp->chanctx = ctx;
  1925. ctx->nvifs_assigned++;
  1926. list_add_tail(&avp->list, &ctx->vifs);
  1927. ath9k_calculate_summary_state(sc, ctx);
  1928. for (i = 0; i < IEEE80211_NUM_ACS; i++)
  1929. vif->hw_queue[i] = ctx->hw_queue_base + i;
  1930. mutex_unlock(&sc->mutex);
  1931. return 0;
  1932. }
  1933. static void ath9k_unassign_vif_chanctx(struct ieee80211_hw *hw,
  1934. struct ieee80211_vif *vif,
  1935. struct ieee80211_chanctx_conf *conf)
  1936. {
  1937. struct ath_softc *sc = hw->priv;
  1938. struct ath_common *common = ath9k_hw_common(sc->sc_ah);
  1939. struct ath_vif *avp = (void *)vif->drv_priv;
  1940. struct ath_chanctx *ctx = ath_chanctx_get(conf);
  1941. int ac;
  1942. mutex_lock(&sc->mutex);
  1943. ath_dbg(common, CHAN_CTX,
  1944. "Remove VIF (addr: %pM, type: %d, p2p: %d) from channel context: %d MHz\n",
  1945. vif->addr, vif->type, vif->p2p,
  1946. conf->def.chan->center_freq);
  1947. avp->chanctx = NULL;
  1948. ctx->nvifs_assigned--;
  1949. list_del(&avp->list);
  1950. ath9k_calculate_summary_state(sc, ctx);
  1951. for (ac = 0; ac < IEEE80211_NUM_ACS; ac++)
  1952. vif->hw_queue[ac] = IEEE80211_INVAL_HW_QUEUE;
  1953. mutex_unlock(&sc->mutex);
  1954. }
  1955. static void ath9k_mgd_prepare_tx(struct ieee80211_hw *hw,
  1956. struct ieee80211_vif *vif)
  1957. {
  1958. struct ath_softc *sc = hw->priv;
  1959. struct ath_common *common = ath9k_hw_common(sc->sc_ah);
  1960. struct ath_vif *avp = (struct ath_vif *) vif->drv_priv;
  1961. bool changed = false;
  1962. if (!test_bit(ATH_OP_MULTI_CHANNEL, &common->op_flags))
  1963. return;
  1964. if (!avp->chanctx)
  1965. return;
  1966. mutex_lock(&sc->mutex);
  1967. spin_lock_bh(&sc->chan_lock);
  1968. if (sc->next_chan || (sc->cur_chan != avp->chanctx)) {
  1969. sc->next_chan = avp->chanctx;
  1970. changed = true;
  1971. }
  1972. ath_dbg(common, CHAN_CTX,
  1973. "%s: Set chanctx state to FORCE_ACTIVE, changed: %d\n",
  1974. __func__, changed);
  1975. sc->sched.state = ATH_CHANCTX_STATE_FORCE_ACTIVE;
  1976. spin_unlock_bh(&sc->chan_lock);
  1977. if (changed)
  1978. ath_chanctx_set_next(sc, true);
  1979. mutex_unlock(&sc->mutex);
  1980. }
  1981. void ath9k_fill_chanctx_ops(void)
  1982. {
  1983. if (!ath9k_is_chanctx_enabled())
  1984. return;
  1985. ath9k_ops.hw_scan = ath9k_hw_scan;
  1986. ath9k_ops.cancel_hw_scan = ath9k_cancel_hw_scan;
  1987. ath9k_ops.remain_on_channel = ath9k_remain_on_channel;
  1988. ath9k_ops.cancel_remain_on_channel = ath9k_cancel_remain_on_channel;
  1989. ath9k_ops.add_chanctx = ath9k_add_chanctx;
  1990. ath9k_ops.remove_chanctx = ath9k_remove_chanctx;
  1991. ath9k_ops.change_chanctx = ath9k_change_chanctx;
  1992. ath9k_ops.assign_vif_chanctx = ath9k_assign_vif_chanctx;
  1993. ath9k_ops.unassign_vif_chanctx = ath9k_unassign_vif_chanctx;
  1994. ath9k_ops.mgd_prepare_tx = ath9k_mgd_prepare_tx;
  1995. }
  1996. #endif
  1997. struct ieee80211_ops ath9k_ops = {
  1998. .tx = ath9k_tx,
  1999. .start = ath9k_start,
  2000. .stop = ath9k_stop,
  2001. .add_interface = ath9k_add_interface,
  2002. .change_interface = ath9k_change_interface,
  2003. .remove_interface = ath9k_remove_interface,
  2004. .config = ath9k_config,
  2005. .configure_filter = ath9k_configure_filter,
  2006. .sta_add = ath9k_sta_add,
  2007. .sta_remove = ath9k_sta_remove,
  2008. .sta_notify = ath9k_sta_notify,
  2009. .conf_tx = ath9k_conf_tx,
  2010. .bss_info_changed = ath9k_bss_info_changed,
  2011. .set_key = ath9k_set_key,
  2012. .get_tsf = ath9k_get_tsf,
  2013. .set_tsf = ath9k_set_tsf,
  2014. .reset_tsf = ath9k_reset_tsf,
  2015. .ampdu_action = ath9k_ampdu_action,
  2016. .get_survey = ath9k_get_survey,
  2017. .rfkill_poll = ath9k_rfkill_poll_state,
  2018. .set_coverage_class = ath9k_set_coverage_class,
  2019. .flush = ath9k_flush,
  2020. .tx_frames_pending = ath9k_tx_frames_pending,
  2021. .tx_last_beacon = ath9k_tx_last_beacon,
  2022. .release_buffered_frames = ath9k_release_buffered_frames,
  2023. .get_stats = ath9k_get_stats,
  2024. .set_antenna = ath9k_set_antenna,
  2025. .get_antenna = ath9k_get_antenna,
  2026. #ifdef CONFIG_ATH9K_WOW
  2027. .suspend = ath9k_suspend,
  2028. .resume = ath9k_resume,
  2029. .set_wakeup = ath9k_set_wakeup,
  2030. #endif
  2031. #ifdef CONFIG_ATH9K_DEBUGFS
  2032. .get_et_sset_count = ath9k_get_et_sset_count,
  2033. .get_et_stats = ath9k_get_et_stats,
  2034. .get_et_strings = ath9k_get_et_strings,
  2035. #endif
  2036. #if defined(CONFIG_MAC80211_DEBUGFS) && defined(CONFIG_ATH9K_STATION_STATISTICS)
  2037. .sta_add_debugfs = ath9k_sta_add_debugfs,
  2038. #endif
  2039. .sw_scan_start = ath9k_sw_scan_start,
  2040. .sw_scan_complete = ath9k_sw_scan_complete,
  2041. };