main.c 58 KB

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