main.c 59 KB

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