main.c 59 KB

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