main.c 61 KB

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