main.c 60 KB

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