main.c 59 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456
  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. int ret = 0;
  803. ath9k_ps_wakeup(sc);
  804. mutex_lock(&sc->mutex);
  805. switch (vif->type) {
  806. case NL80211_IFTYPE_STATION:
  807. case NL80211_IFTYPE_WDS:
  808. case NL80211_IFTYPE_ADHOC:
  809. case NL80211_IFTYPE_AP:
  810. case NL80211_IFTYPE_MESH_POINT:
  811. break;
  812. default:
  813. ath_err(common, "Interface type %d not yet supported\n",
  814. vif->type);
  815. ret = -EOPNOTSUPP;
  816. goto out;
  817. }
  818. if (ath9k_uses_beacons(vif->type)) {
  819. if (sc->nbcnvifs >= ATH_BCBUF) {
  820. ath_err(common, "Not enough beacon buffers when adding"
  821. " new interface of type: %i\n",
  822. vif->type);
  823. ret = -ENOBUFS;
  824. goto out;
  825. }
  826. }
  827. ath_dbg(common, CONFIG, "Attach a VIF of type: %d\n", vif->type);
  828. sc->nvifs++;
  829. ath9k_calculate_summary_state(hw, vif);
  830. if (ath9k_uses_beacons(vif->type))
  831. ath9k_beacon_assign_slot(sc, vif);
  832. out:
  833. mutex_unlock(&sc->mutex);
  834. ath9k_ps_restore(sc);
  835. return ret;
  836. }
  837. static int ath9k_change_interface(struct ieee80211_hw *hw,
  838. struct ieee80211_vif *vif,
  839. enum nl80211_iftype new_type,
  840. bool p2p)
  841. {
  842. struct ath_softc *sc = hw->priv;
  843. struct ath_common *common = ath9k_hw_common(sc->sc_ah);
  844. int ret = 0;
  845. ath_dbg(common, CONFIG, "Change Interface\n");
  846. mutex_lock(&sc->mutex);
  847. ath9k_ps_wakeup(sc);
  848. if (ath9k_uses_beacons(new_type) &&
  849. !ath9k_uses_beacons(vif->type)) {
  850. if (sc->nbcnvifs >= ATH_BCBUF) {
  851. ath_err(common, "No beacon slot available\n");
  852. ret = -ENOBUFS;
  853. goto out;
  854. }
  855. }
  856. if (ath9k_uses_beacons(vif->type))
  857. ath9k_beacon_remove_slot(sc, vif);
  858. vif->type = new_type;
  859. vif->p2p = p2p;
  860. ath9k_calculate_summary_state(hw, vif);
  861. if (ath9k_uses_beacons(vif->type))
  862. ath9k_beacon_assign_slot(sc, vif);
  863. out:
  864. ath9k_ps_restore(sc);
  865. mutex_unlock(&sc->mutex);
  866. return ret;
  867. }
  868. static void ath9k_remove_interface(struct ieee80211_hw *hw,
  869. struct ieee80211_vif *vif)
  870. {
  871. struct ath_softc *sc = hw->priv;
  872. struct ath_common *common = ath9k_hw_common(sc->sc_ah);
  873. ath_dbg(common, CONFIG, "Detach Interface\n");
  874. ath9k_ps_wakeup(sc);
  875. mutex_lock(&sc->mutex);
  876. sc->nvifs--;
  877. if (ath9k_uses_beacons(vif->type))
  878. ath9k_beacon_remove_slot(sc, vif);
  879. ath9k_calculate_summary_state(hw, NULL);
  880. mutex_unlock(&sc->mutex);
  881. ath9k_ps_restore(sc);
  882. }
  883. static void ath9k_enable_ps(struct ath_softc *sc)
  884. {
  885. struct ath_hw *ah = sc->sc_ah;
  886. struct ath_common *common = ath9k_hw_common(ah);
  887. sc->ps_enabled = true;
  888. if (!(ah->caps.hw_caps & ATH9K_HW_CAP_AUTOSLEEP)) {
  889. if ((ah->imask & ATH9K_INT_TIM_TIMER) == 0) {
  890. ah->imask |= ATH9K_INT_TIM_TIMER;
  891. ath9k_hw_set_interrupts(ah);
  892. }
  893. ath9k_hw_setrxabort(ah, 1);
  894. }
  895. ath_dbg(common, PS, "PowerSave enabled\n");
  896. }
  897. static void ath9k_disable_ps(struct ath_softc *sc)
  898. {
  899. struct ath_hw *ah = sc->sc_ah;
  900. struct ath_common *common = ath9k_hw_common(ah);
  901. sc->ps_enabled = false;
  902. ath9k_hw_setpower(ah, ATH9K_PM_AWAKE);
  903. if (!(ah->caps.hw_caps & ATH9K_HW_CAP_AUTOSLEEP)) {
  904. ath9k_hw_setrxabort(ah, 0);
  905. sc->ps_flags &= ~(PS_WAIT_FOR_BEACON |
  906. PS_WAIT_FOR_CAB |
  907. PS_WAIT_FOR_PSPOLL_DATA |
  908. PS_WAIT_FOR_TX_ACK);
  909. if (ah->imask & ATH9K_INT_TIM_TIMER) {
  910. ah->imask &= ~ATH9K_INT_TIM_TIMER;
  911. ath9k_hw_set_interrupts(ah);
  912. }
  913. }
  914. ath_dbg(common, PS, "PowerSave disabled\n");
  915. }
  916. static int ath9k_config(struct ieee80211_hw *hw, u32 changed)
  917. {
  918. struct ath_softc *sc = hw->priv;
  919. struct ath_hw *ah = sc->sc_ah;
  920. struct ath_common *common = ath9k_hw_common(ah);
  921. struct ieee80211_conf *conf = &hw->conf;
  922. bool reset_channel = false;
  923. ath9k_ps_wakeup(sc);
  924. mutex_lock(&sc->mutex);
  925. if (changed & IEEE80211_CONF_CHANGE_IDLE) {
  926. sc->ps_idle = !!(conf->flags & IEEE80211_CONF_IDLE);
  927. if (sc->ps_idle) {
  928. ath_cancel_work(sc);
  929. ath9k_stop_btcoex(sc);
  930. } else {
  931. ath9k_start_btcoex(sc);
  932. /*
  933. * The chip needs a reset to properly wake up from
  934. * full sleep
  935. */
  936. reset_channel = ah->chip_fullsleep;
  937. }
  938. }
  939. /*
  940. * We just prepare to enable PS. We have to wait until our AP has
  941. * ACK'd our null data frame to disable RX otherwise we'll ignore
  942. * those ACKs and end up retransmitting the same null data frames.
  943. * IEEE80211_CONF_CHANGE_PS is only passed by mac80211 for STA mode.
  944. */
  945. if (changed & IEEE80211_CONF_CHANGE_PS) {
  946. unsigned long flags;
  947. spin_lock_irqsave(&sc->sc_pm_lock, flags);
  948. if (conf->flags & IEEE80211_CONF_PS)
  949. ath9k_enable_ps(sc);
  950. else
  951. ath9k_disable_ps(sc);
  952. spin_unlock_irqrestore(&sc->sc_pm_lock, flags);
  953. }
  954. if (changed & IEEE80211_CONF_CHANGE_MONITOR) {
  955. if (conf->flags & IEEE80211_CONF_MONITOR) {
  956. ath_dbg(common, CONFIG, "Monitor mode is enabled\n");
  957. sc->sc_ah->is_monitoring = true;
  958. } else {
  959. ath_dbg(common, CONFIG, "Monitor mode is disabled\n");
  960. sc->sc_ah->is_monitoring = false;
  961. }
  962. }
  963. if ((changed & IEEE80211_CONF_CHANGE_CHANNEL) || reset_channel) {
  964. struct ieee80211_channel *curchan = hw->conf.channel;
  965. int pos = curchan->hw_value;
  966. int old_pos = -1;
  967. unsigned long flags;
  968. if (ah->curchan)
  969. old_pos = ah->curchan - &ah->channels[0];
  970. ath_dbg(common, CONFIG, "Set channel: %d MHz type: %d\n",
  971. curchan->center_freq, conf->channel_type);
  972. /* update survey stats for the old channel before switching */
  973. spin_lock_irqsave(&common->cc_lock, flags);
  974. ath_update_survey_stats(sc);
  975. spin_unlock_irqrestore(&common->cc_lock, flags);
  976. /*
  977. * Preserve the current channel values, before updating
  978. * the same channel
  979. */
  980. if (ah->curchan && (old_pos == pos))
  981. ath9k_hw_getnf(ah, ah->curchan);
  982. ath9k_cmn_update_ichannel(&sc->sc_ah->channels[pos],
  983. curchan, conf->channel_type);
  984. /*
  985. * If the operating channel changes, change the survey in-use flags
  986. * along with it.
  987. * Reset the survey data for the new channel, unless we're switching
  988. * back to the operating channel from an off-channel operation.
  989. */
  990. if (!(hw->conf.flags & IEEE80211_CONF_OFFCHANNEL) &&
  991. sc->cur_survey != &sc->survey[pos]) {
  992. if (sc->cur_survey)
  993. sc->cur_survey->filled &= ~SURVEY_INFO_IN_USE;
  994. sc->cur_survey = &sc->survey[pos];
  995. memset(sc->cur_survey, 0, sizeof(struct survey_info));
  996. sc->cur_survey->filled |= SURVEY_INFO_IN_USE;
  997. } else if (!(sc->survey[pos].filled & SURVEY_INFO_IN_USE)) {
  998. memset(&sc->survey[pos], 0, sizeof(struct survey_info));
  999. }
  1000. if (ath_set_channel(sc, hw, &sc->sc_ah->channels[pos]) < 0) {
  1001. ath_err(common, "Unable to set channel\n");
  1002. mutex_unlock(&sc->mutex);
  1003. ath9k_ps_restore(sc);
  1004. return -EINVAL;
  1005. }
  1006. /*
  1007. * The most recent snapshot of channel->noisefloor for the old
  1008. * channel is only available after the hardware reset. Copy it to
  1009. * the survey stats now.
  1010. */
  1011. if (old_pos >= 0)
  1012. ath_update_survey_nf(sc, old_pos);
  1013. }
  1014. if (changed & IEEE80211_CONF_CHANGE_POWER) {
  1015. ath_dbg(common, CONFIG, "Set power: %d\n", conf->power_level);
  1016. sc->config.txpowlimit = 2 * conf->power_level;
  1017. ath9k_cmn_update_txpow(ah, sc->curtxpow,
  1018. sc->config.txpowlimit, &sc->curtxpow);
  1019. }
  1020. mutex_unlock(&sc->mutex);
  1021. ath9k_ps_restore(sc);
  1022. return 0;
  1023. }
  1024. #define SUPPORTED_FILTERS \
  1025. (FIF_PROMISC_IN_BSS | \
  1026. FIF_ALLMULTI | \
  1027. FIF_CONTROL | \
  1028. FIF_PSPOLL | \
  1029. FIF_OTHER_BSS | \
  1030. FIF_BCN_PRBRESP_PROMISC | \
  1031. FIF_PROBE_REQ | \
  1032. FIF_FCSFAIL)
  1033. /* FIXME: sc->sc_full_reset ? */
  1034. static void ath9k_configure_filter(struct ieee80211_hw *hw,
  1035. unsigned int changed_flags,
  1036. unsigned int *total_flags,
  1037. u64 multicast)
  1038. {
  1039. struct ath_softc *sc = hw->priv;
  1040. u32 rfilt;
  1041. changed_flags &= SUPPORTED_FILTERS;
  1042. *total_flags &= SUPPORTED_FILTERS;
  1043. sc->rx.rxfilter = *total_flags;
  1044. ath9k_ps_wakeup(sc);
  1045. rfilt = ath_calcrxfilter(sc);
  1046. ath9k_hw_setrxfilter(sc->sc_ah, rfilt);
  1047. ath9k_ps_restore(sc);
  1048. ath_dbg(ath9k_hw_common(sc->sc_ah), CONFIG, "Set HW RX filter: 0x%x\n",
  1049. rfilt);
  1050. }
  1051. static int ath9k_sta_add(struct ieee80211_hw *hw,
  1052. struct ieee80211_vif *vif,
  1053. struct ieee80211_sta *sta)
  1054. {
  1055. struct ath_softc *sc = hw->priv;
  1056. struct ath_common *common = ath9k_hw_common(sc->sc_ah);
  1057. struct ath_node *an = (struct ath_node *) sta->drv_priv;
  1058. struct ieee80211_key_conf ps_key = { };
  1059. ath_node_attach(sc, sta, vif);
  1060. if (vif->type != NL80211_IFTYPE_AP &&
  1061. vif->type != NL80211_IFTYPE_AP_VLAN)
  1062. return 0;
  1063. an->ps_key = ath_key_config(common, vif, sta, &ps_key);
  1064. return 0;
  1065. }
  1066. static void ath9k_del_ps_key(struct ath_softc *sc,
  1067. struct ieee80211_vif *vif,
  1068. struct ieee80211_sta *sta)
  1069. {
  1070. struct ath_common *common = ath9k_hw_common(sc->sc_ah);
  1071. struct ath_node *an = (struct ath_node *) sta->drv_priv;
  1072. struct ieee80211_key_conf ps_key = { .hw_key_idx = an->ps_key };
  1073. if (!an->ps_key)
  1074. return;
  1075. ath_key_delete(common, &ps_key);
  1076. }
  1077. static int ath9k_sta_remove(struct ieee80211_hw *hw,
  1078. struct ieee80211_vif *vif,
  1079. struct ieee80211_sta *sta)
  1080. {
  1081. struct ath_softc *sc = hw->priv;
  1082. ath9k_del_ps_key(sc, vif, sta);
  1083. ath_node_detach(sc, sta);
  1084. return 0;
  1085. }
  1086. static void ath9k_sta_notify(struct ieee80211_hw *hw,
  1087. struct ieee80211_vif *vif,
  1088. enum sta_notify_cmd cmd,
  1089. struct ieee80211_sta *sta)
  1090. {
  1091. struct ath_softc *sc = hw->priv;
  1092. struct ath_node *an = (struct ath_node *) sta->drv_priv;
  1093. if (!sta->ht_cap.ht_supported)
  1094. return;
  1095. switch (cmd) {
  1096. case STA_NOTIFY_SLEEP:
  1097. an->sleeping = true;
  1098. ath_tx_aggr_sleep(sta, sc, an);
  1099. break;
  1100. case STA_NOTIFY_AWAKE:
  1101. an->sleeping = false;
  1102. ath_tx_aggr_wakeup(sc, an);
  1103. break;
  1104. }
  1105. }
  1106. static int ath9k_conf_tx(struct ieee80211_hw *hw,
  1107. struct ieee80211_vif *vif, u16 queue,
  1108. const struct ieee80211_tx_queue_params *params)
  1109. {
  1110. struct ath_softc *sc = hw->priv;
  1111. struct ath_common *common = ath9k_hw_common(sc->sc_ah);
  1112. struct ath_txq *txq;
  1113. struct ath9k_tx_queue_info qi;
  1114. int ret = 0;
  1115. if (queue >= WME_NUM_AC)
  1116. return 0;
  1117. txq = sc->tx.txq_map[queue];
  1118. ath9k_ps_wakeup(sc);
  1119. mutex_lock(&sc->mutex);
  1120. memset(&qi, 0, sizeof(struct ath9k_tx_queue_info));
  1121. qi.tqi_aifs = params->aifs;
  1122. qi.tqi_cwmin = params->cw_min;
  1123. qi.tqi_cwmax = params->cw_max;
  1124. qi.tqi_burstTime = params->txop * 32;
  1125. ath_dbg(common, CONFIG,
  1126. "Configure tx [queue/halq] [%d/%d], aifs: %d, cw_min: %d, cw_max: %d, txop: %d\n",
  1127. queue, txq->axq_qnum, params->aifs, params->cw_min,
  1128. params->cw_max, params->txop);
  1129. ath_update_max_aggr_framelen(sc, queue, qi.tqi_burstTime);
  1130. ret = ath_txq_update(sc, txq->axq_qnum, &qi);
  1131. if (ret)
  1132. ath_err(common, "TXQ Update failed\n");
  1133. mutex_unlock(&sc->mutex);
  1134. ath9k_ps_restore(sc);
  1135. return ret;
  1136. }
  1137. static int ath9k_set_key(struct ieee80211_hw *hw,
  1138. enum set_key_cmd cmd,
  1139. struct ieee80211_vif *vif,
  1140. struct ieee80211_sta *sta,
  1141. struct ieee80211_key_conf *key)
  1142. {
  1143. struct ath_softc *sc = hw->priv;
  1144. struct ath_common *common = ath9k_hw_common(sc->sc_ah);
  1145. int ret = 0;
  1146. if (ath9k_modparam_nohwcrypt)
  1147. return -ENOSPC;
  1148. if ((vif->type == NL80211_IFTYPE_ADHOC ||
  1149. vif->type == NL80211_IFTYPE_MESH_POINT) &&
  1150. (key->cipher == WLAN_CIPHER_SUITE_TKIP ||
  1151. key->cipher == WLAN_CIPHER_SUITE_CCMP) &&
  1152. !(key->flags & IEEE80211_KEY_FLAG_PAIRWISE)) {
  1153. /*
  1154. * For now, disable hw crypto for the RSN IBSS group keys. This
  1155. * could be optimized in the future to use a modified key cache
  1156. * design to support per-STA RX GTK, but until that gets
  1157. * implemented, use of software crypto for group addressed
  1158. * frames is a acceptable to allow RSN IBSS to be used.
  1159. */
  1160. return -EOPNOTSUPP;
  1161. }
  1162. mutex_lock(&sc->mutex);
  1163. ath9k_ps_wakeup(sc);
  1164. ath_dbg(common, CONFIG, "Set HW Key\n");
  1165. switch (cmd) {
  1166. case SET_KEY:
  1167. if (sta)
  1168. ath9k_del_ps_key(sc, vif, sta);
  1169. ret = ath_key_config(common, vif, sta, key);
  1170. if (ret >= 0) {
  1171. key->hw_key_idx = ret;
  1172. /* push IV and Michael MIC generation to stack */
  1173. key->flags |= IEEE80211_KEY_FLAG_GENERATE_IV;
  1174. if (key->cipher == WLAN_CIPHER_SUITE_TKIP)
  1175. key->flags |= IEEE80211_KEY_FLAG_GENERATE_MMIC;
  1176. if (sc->sc_ah->sw_mgmt_crypto &&
  1177. key->cipher == WLAN_CIPHER_SUITE_CCMP)
  1178. key->flags |= IEEE80211_KEY_FLAG_SW_MGMT;
  1179. ret = 0;
  1180. }
  1181. break;
  1182. case DISABLE_KEY:
  1183. ath_key_delete(common, key);
  1184. break;
  1185. default:
  1186. ret = -EINVAL;
  1187. }
  1188. ath9k_ps_restore(sc);
  1189. mutex_unlock(&sc->mutex);
  1190. return ret;
  1191. }
  1192. static void ath9k_set_assoc_state(struct ath_softc *sc,
  1193. struct ieee80211_vif *vif)
  1194. {
  1195. struct ath_common *common = ath9k_hw_common(sc->sc_ah);
  1196. struct ath_vif *avp = (void *)vif->drv_priv;
  1197. struct ieee80211_bss_conf *bss_conf = &vif->bss_conf;
  1198. unsigned long flags;
  1199. set_bit(SC_OP_PRIM_STA_VIF, &sc->sc_flags);
  1200. avp->primary_sta_vif = true;
  1201. /*
  1202. * Set the AID, BSSID and do beacon-sync only when
  1203. * the HW opmode is STATION.
  1204. *
  1205. * But the primary bit is set above in any case.
  1206. */
  1207. if (sc->sc_ah->opmode != NL80211_IFTYPE_STATION)
  1208. return;
  1209. memcpy(common->curbssid, bss_conf->bssid, ETH_ALEN);
  1210. common->curaid = bss_conf->aid;
  1211. ath9k_hw_write_associd(sc->sc_ah);
  1212. sc->last_rssi = ATH_RSSI_DUMMY_MARKER;
  1213. sc->sc_ah->stats.avgbrssi = ATH_RSSI_DUMMY_MARKER;
  1214. spin_lock_irqsave(&sc->sc_pm_lock, flags);
  1215. sc->ps_flags |= PS_BEACON_SYNC | PS_WAIT_FOR_BEACON;
  1216. spin_unlock_irqrestore(&sc->sc_pm_lock, flags);
  1217. ath_dbg(common, CONFIG,
  1218. "Primary Station interface: %pM, BSSID: %pM\n",
  1219. vif->addr, common->curbssid);
  1220. }
  1221. static void ath9k_bss_assoc_iter(void *data, u8 *mac, struct ieee80211_vif *vif)
  1222. {
  1223. struct ath_softc *sc = data;
  1224. struct ieee80211_bss_conf *bss_conf = &vif->bss_conf;
  1225. if (test_bit(SC_OP_PRIM_STA_VIF, &sc->sc_flags))
  1226. return;
  1227. if (bss_conf->assoc)
  1228. ath9k_set_assoc_state(sc, vif);
  1229. }
  1230. static void ath9k_bss_info_changed(struct ieee80211_hw *hw,
  1231. struct ieee80211_vif *vif,
  1232. struct ieee80211_bss_conf *bss_conf,
  1233. u32 changed)
  1234. {
  1235. #define CHECK_ANI \
  1236. (BSS_CHANGED_ASSOC | \
  1237. BSS_CHANGED_IBSS | \
  1238. BSS_CHANGED_BEACON_ENABLED)
  1239. struct ath_softc *sc = hw->priv;
  1240. struct ath_hw *ah = sc->sc_ah;
  1241. struct ath_common *common = ath9k_hw_common(ah);
  1242. struct ath_vif *avp = (void *)vif->drv_priv;
  1243. int slottime;
  1244. ath9k_ps_wakeup(sc);
  1245. mutex_lock(&sc->mutex);
  1246. if (changed & BSS_CHANGED_ASSOC) {
  1247. ath_dbg(common, CONFIG, "BSSID %pM Changed ASSOC %d\n",
  1248. bss_conf->bssid, bss_conf->assoc);
  1249. if (avp->primary_sta_vif && !bss_conf->assoc) {
  1250. clear_bit(SC_OP_PRIM_STA_VIF, &sc->sc_flags);
  1251. avp->primary_sta_vif = false;
  1252. if (ah->opmode == NL80211_IFTYPE_STATION)
  1253. clear_bit(SC_OP_BEACONS, &sc->sc_flags);
  1254. }
  1255. ieee80211_iterate_active_interfaces_atomic(sc->hw,
  1256. ath9k_bss_assoc_iter, sc);
  1257. if (!test_bit(SC_OP_PRIM_STA_VIF, &sc->sc_flags) &&
  1258. ah->opmode == NL80211_IFTYPE_STATION) {
  1259. memset(common->curbssid, 0, ETH_ALEN);
  1260. common->curaid = 0;
  1261. ath9k_hw_write_associd(sc->sc_ah);
  1262. }
  1263. }
  1264. if (changed & BSS_CHANGED_IBSS) {
  1265. memcpy(common->curbssid, bss_conf->bssid, ETH_ALEN);
  1266. common->curaid = bss_conf->aid;
  1267. ath9k_hw_write_associd(sc->sc_ah);
  1268. }
  1269. if ((changed & BSS_CHANGED_BEACON_ENABLED) ||
  1270. (changed & BSS_CHANGED_BEACON_INT)) {
  1271. if (ah->opmode == NL80211_IFTYPE_AP &&
  1272. bss_conf->enable_beacon)
  1273. ath9k_set_tsfadjust(sc, vif);
  1274. if (ath9k_allow_beacon_config(sc, vif))
  1275. ath9k_beacon_config(sc, vif, changed);
  1276. }
  1277. if (changed & BSS_CHANGED_ERP_SLOT) {
  1278. if (bss_conf->use_short_slot)
  1279. slottime = 9;
  1280. else
  1281. slottime = 20;
  1282. if (vif->type == NL80211_IFTYPE_AP) {
  1283. /*
  1284. * Defer update, so that connected stations can adjust
  1285. * their settings at the same time.
  1286. * See beacon.c for more details
  1287. */
  1288. sc->beacon.slottime = slottime;
  1289. sc->beacon.updateslot = UPDATE;
  1290. } else {
  1291. ah->slottime = slottime;
  1292. ath9k_hw_init_global_settings(ah);
  1293. }
  1294. }
  1295. if (changed & CHECK_ANI)
  1296. ath_check_ani(sc);
  1297. mutex_unlock(&sc->mutex);
  1298. ath9k_ps_restore(sc);
  1299. #undef CHECK_ANI
  1300. }
  1301. static u64 ath9k_get_tsf(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
  1302. {
  1303. struct ath_softc *sc = hw->priv;
  1304. u64 tsf;
  1305. mutex_lock(&sc->mutex);
  1306. ath9k_ps_wakeup(sc);
  1307. tsf = ath9k_hw_gettsf64(sc->sc_ah);
  1308. ath9k_ps_restore(sc);
  1309. mutex_unlock(&sc->mutex);
  1310. return tsf;
  1311. }
  1312. static void ath9k_set_tsf(struct ieee80211_hw *hw,
  1313. struct ieee80211_vif *vif,
  1314. u64 tsf)
  1315. {
  1316. struct ath_softc *sc = hw->priv;
  1317. mutex_lock(&sc->mutex);
  1318. ath9k_ps_wakeup(sc);
  1319. ath9k_hw_settsf64(sc->sc_ah, tsf);
  1320. ath9k_ps_restore(sc);
  1321. mutex_unlock(&sc->mutex);
  1322. }
  1323. static void ath9k_reset_tsf(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
  1324. {
  1325. struct ath_softc *sc = hw->priv;
  1326. mutex_lock(&sc->mutex);
  1327. ath9k_ps_wakeup(sc);
  1328. ath9k_hw_reset_tsf(sc->sc_ah);
  1329. ath9k_ps_restore(sc);
  1330. mutex_unlock(&sc->mutex);
  1331. }
  1332. static int ath9k_ampdu_action(struct ieee80211_hw *hw,
  1333. struct ieee80211_vif *vif,
  1334. enum ieee80211_ampdu_mlme_action action,
  1335. struct ieee80211_sta *sta,
  1336. u16 tid, u16 *ssn, u8 buf_size)
  1337. {
  1338. struct ath_softc *sc = hw->priv;
  1339. int ret = 0;
  1340. local_bh_disable();
  1341. switch (action) {
  1342. case IEEE80211_AMPDU_RX_START:
  1343. break;
  1344. case IEEE80211_AMPDU_RX_STOP:
  1345. break;
  1346. case IEEE80211_AMPDU_TX_START:
  1347. ath9k_ps_wakeup(sc);
  1348. ret = ath_tx_aggr_start(sc, sta, tid, ssn);
  1349. if (!ret)
  1350. ieee80211_start_tx_ba_cb_irqsafe(vif, sta->addr, tid);
  1351. ath9k_ps_restore(sc);
  1352. break;
  1353. case IEEE80211_AMPDU_TX_STOP:
  1354. ath9k_ps_wakeup(sc);
  1355. ath_tx_aggr_stop(sc, sta, tid);
  1356. ieee80211_stop_tx_ba_cb_irqsafe(vif, sta->addr, tid);
  1357. ath9k_ps_restore(sc);
  1358. break;
  1359. case IEEE80211_AMPDU_TX_OPERATIONAL:
  1360. ath9k_ps_wakeup(sc);
  1361. ath_tx_aggr_resume(sc, sta, tid);
  1362. ath9k_ps_restore(sc);
  1363. break;
  1364. default:
  1365. ath_err(ath9k_hw_common(sc->sc_ah), "Unknown AMPDU action\n");
  1366. }
  1367. local_bh_enable();
  1368. return ret;
  1369. }
  1370. static int ath9k_get_survey(struct ieee80211_hw *hw, int idx,
  1371. struct survey_info *survey)
  1372. {
  1373. struct ath_softc *sc = hw->priv;
  1374. struct ath_common *common = ath9k_hw_common(sc->sc_ah);
  1375. struct ieee80211_supported_band *sband;
  1376. struct ieee80211_channel *chan;
  1377. unsigned long flags;
  1378. int pos;
  1379. spin_lock_irqsave(&common->cc_lock, flags);
  1380. if (idx == 0)
  1381. ath_update_survey_stats(sc);
  1382. sband = hw->wiphy->bands[IEEE80211_BAND_2GHZ];
  1383. if (sband && idx >= sband->n_channels) {
  1384. idx -= sband->n_channels;
  1385. sband = NULL;
  1386. }
  1387. if (!sband)
  1388. sband = hw->wiphy->bands[IEEE80211_BAND_5GHZ];
  1389. if (!sband || idx >= sband->n_channels) {
  1390. spin_unlock_irqrestore(&common->cc_lock, flags);
  1391. return -ENOENT;
  1392. }
  1393. chan = &sband->channels[idx];
  1394. pos = chan->hw_value;
  1395. memcpy(survey, &sc->survey[pos], sizeof(*survey));
  1396. survey->channel = chan;
  1397. spin_unlock_irqrestore(&common->cc_lock, flags);
  1398. return 0;
  1399. }
  1400. static void ath9k_set_coverage_class(struct ieee80211_hw *hw, u8 coverage_class)
  1401. {
  1402. struct ath_softc *sc = hw->priv;
  1403. struct ath_hw *ah = sc->sc_ah;
  1404. mutex_lock(&sc->mutex);
  1405. ah->coverage_class = coverage_class;
  1406. ath9k_ps_wakeup(sc);
  1407. ath9k_hw_init_global_settings(ah);
  1408. ath9k_ps_restore(sc);
  1409. mutex_unlock(&sc->mutex);
  1410. }
  1411. static void ath9k_flush(struct ieee80211_hw *hw, bool drop)
  1412. {
  1413. struct ath_softc *sc = hw->priv;
  1414. struct ath_hw *ah = sc->sc_ah;
  1415. struct ath_common *common = ath9k_hw_common(ah);
  1416. int timeout = 200; /* ms */
  1417. int i, j;
  1418. bool drain_txq;
  1419. mutex_lock(&sc->mutex);
  1420. cancel_delayed_work_sync(&sc->tx_complete_work);
  1421. if (ah->ah_flags & AH_UNPLUGGED) {
  1422. ath_dbg(common, ANY, "Device has been unplugged!\n");
  1423. mutex_unlock(&sc->mutex);
  1424. return;
  1425. }
  1426. if (test_bit(SC_OP_INVALID, &sc->sc_flags)) {
  1427. ath_dbg(common, ANY, "Device not present\n");
  1428. mutex_unlock(&sc->mutex);
  1429. return;
  1430. }
  1431. for (j = 0; j < timeout; j++) {
  1432. bool npend = false;
  1433. if (j)
  1434. usleep_range(1000, 2000);
  1435. for (i = 0; i < ATH9K_NUM_TX_QUEUES; i++) {
  1436. if (!ATH_TXQ_SETUP(sc, i))
  1437. continue;
  1438. npend = ath9k_has_pending_frames(sc, &sc->tx.txq[i]);
  1439. if (npend)
  1440. break;
  1441. }
  1442. if (!npend)
  1443. break;
  1444. }
  1445. if (drop) {
  1446. ath9k_ps_wakeup(sc);
  1447. spin_lock_bh(&sc->sc_pcu_lock);
  1448. drain_txq = ath_drain_all_txq(sc, false);
  1449. spin_unlock_bh(&sc->sc_pcu_lock);
  1450. if (!drain_txq)
  1451. ath_reset(sc, false);
  1452. ath9k_ps_restore(sc);
  1453. ieee80211_wake_queues(hw);
  1454. }
  1455. ieee80211_queue_delayed_work(hw, &sc->tx_complete_work, 0);
  1456. mutex_unlock(&sc->mutex);
  1457. }
  1458. static bool ath9k_tx_frames_pending(struct ieee80211_hw *hw)
  1459. {
  1460. struct ath_softc *sc = hw->priv;
  1461. int i;
  1462. for (i = 0; i < ATH9K_NUM_TX_QUEUES; i++) {
  1463. if (!ATH_TXQ_SETUP(sc, i))
  1464. continue;
  1465. if (ath9k_has_pending_frames(sc, &sc->tx.txq[i]))
  1466. return true;
  1467. }
  1468. return false;
  1469. }
  1470. static int ath9k_tx_last_beacon(struct ieee80211_hw *hw)
  1471. {
  1472. struct ath_softc *sc = hw->priv;
  1473. struct ath_hw *ah = sc->sc_ah;
  1474. struct ieee80211_vif *vif;
  1475. struct ath_vif *avp;
  1476. struct ath_buf *bf;
  1477. struct ath_tx_status ts;
  1478. bool edma = !!(ah->caps.hw_caps & ATH9K_HW_CAP_EDMA);
  1479. int status;
  1480. vif = sc->beacon.bslot[0];
  1481. if (!vif)
  1482. return 0;
  1483. if (!vif->bss_conf.enable_beacon)
  1484. return 0;
  1485. avp = (void *)vif->drv_priv;
  1486. if (!sc->beacon.tx_processed && !edma) {
  1487. tasklet_disable(&sc->bcon_tasklet);
  1488. bf = avp->av_bcbuf;
  1489. if (!bf || !bf->bf_mpdu)
  1490. goto skip;
  1491. status = ath9k_hw_txprocdesc(ah, bf->bf_desc, &ts);
  1492. if (status == -EINPROGRESS)
  1493. goto skip;
  1494. sc->beacon.tx_processed = true;
  1495. sc->beacon.tx_last = !(ts.ts_status & ATH9K_TXERR_MASK);
  1496. skip:
  1497. tasklet_enable(&sc->bcon_tasklet);
  1498. }
  1499. return sc->beacon.tx_last;
  1500. }
  1501. static int ath9k_get_stats(struct ieee80211_hw *hw,
  1502. struct ieee80211_low_level_stats *stats)
  1503. {
  1504. struct ath_softc *sc = hw->priv;
  1505. struct ath_hw *ah = sc->sc_ah;
  1506. struct ath9k_mib_stats *mib_stats = &ah->ah_mibStats;
  1507. stats->dot11ACKFailureCount = mib_stats->ackrcv_bad;
  1508. stats->dot11RTSFailureCount = mib_stats->rts_bad;
  1509. stats->dot11FCSErrorCount = mib_stats->fcs_bad;
  1510. stats->dot11RTSSuccessCount = mib_stats->rts_good;
  1511. return 0;
  1512. }
  1513. static u32 fill_chainmask(u32 cap, u32 new)
  1514. {
  1515. u32 filled = 0;
  1516. int i;
  1517. for (i = 0; cap && new; i++, cap >>= 1) {
  1518. if (!(cap & BIT(0)))
  1519. continue;
  1520. if (new & BIT(0))
  1521. filled |= BIT(i);
  1522. new >>= 1;
  1523. }
  1524. return filled;
  1525. }
  1526. static bool validate_antenna_mask(struct ath_hw *ah, u32 val)
  1527. {
  1528. switch (val & 0x7) {
  1529. case 0x1:
  1530. case 0x3:
  1531. case 0x7:
  1532. return true;
  1533. case 0x2:
  1534. return (ah->caps.rx_chainmask == 1);
  1535. default:
  1536. return false;
  1537. }
  1538. }
  1539. static int ath9k_set_antenna(struct ieee80211_hw *hw, u32 tx_ant, u32 rx_ant)
  1540. {
  1541. struct ath_softc *sc = hw->priv;
  1542. struct ath_hw *ah = sc->sc_ah;
  1543. if (ah->caps.rx_chainmask != 1)
  1544. rx_ant |= tx_ant;
  1545. if (!validate_antenna_mask(ah, rx_ant) || !tx_ant)
  1546. return -EINVAL;
  1547. sc->ant_rx = rx_ant;
  1548. sc->ant_tx = tx_ant;
  1549. if (ah->caps.rx_chainmask == 1)
  1550. return 0;
  1551. /* AR9100 runs into calibration issues if not all rx chains are enabled */
  1552. if (AR_SREV_9100(ah))
  1553. ah->rxchainmask = 0x7;
  1554. else
  1555. ah->rxchainmask = fill_chainmask(ah->caps.rx_chainmask, rx_ant);
  1556. ah->txchainmask = fill_chainmask(ah->caps.tx_chainmask, tx_ant);
  1557. ath9k_reload_chainmask_settings(sc);
  1558. return 0;
  1559. }
  1560. static int ath9k_get_antenna(struct ieee80211_hw *hw, u32 *tx_ant, u32 *rx_ant)
  1561. {
  1562. struct ath_softc *sc = hw->priv;
  1563. *tx_ant = sc->ant_tx;
  1564. *rx_ant = sc->ant_rx;
  1565. return 0;
  1566. }
  1567. #ifdef CONFIG_ATH9K_DEBUGFS
  1568. /* Ethtool support for get-stats */
  1569. #define AMKSTR(nm) #nm "_BE", #nm "_BK", #nm "_VI", #nm "_VO"
  1570. static const char ath9k_gstrings_stats[][ETH_GSTRING_LEN] = {
  1571. "tx_pkts_nic",
  1572. "tx_bytes_nic",
  1573. "rx_pkts_nic",
  1574. "rx_bytes_nic",
  1575. AMKSTR(d_tx_pkts),
  1576. AMKSTR(d_tx_bytes),
  1577. AMKSTR(d_tx_mpdus_queued),
  1578. AMKSTR(d_tx_mpdus_completed),
  1579. AMKSTR(d_tx_mpdu_xretries),
  1580. AMKSTR(d_tx_aggregates),
  1581. AMKSTR(d_tx_ampdus_queued_hw),
  1582. AMKSTR(d_tx_ampdus_queued_sw),
  1583. AMKSTR(d_tx_ampdus_completed),
  1584. AMKSTR(d_tx_ampdu_retries),
  1585. AMKSTR(d_tx_ampdu_xretries),
  1586. AMKSTR(d_tx_fifo_underrun),
  1587. AMKSTR(d_tx_op_exceeded),
  1588. AMKSTR(d_tx_timer_expiry),
  1589. AMKSTR(d_tx_desc_cfg_err),
  1590. AMKSTR(d_tx_data_underrun),
  1591. AMKSTR(d_tx_delim_underrun),
  1592. "d_rx_decrypt_crc_err",
  1593. "d_rx_phy_err",
  1594. "d_rx_mic_err",
  1595. "d_rx_pre_delim_crc_err",
  1596. "d_rx_post_delim_crc_err",
  1597. "d_rx_decrypt_busy_err",
  1598. "d_rx_phyerr_radar",
  1599. "d_rx_phyerr_ofdm_timing",
  1600. "d_rx_phyerr_cck_timing",
  1601. };
  1602. #define ATH9K_SSTATS_LEN ARRAY_SIZE(ath9k_gstrings_stats)
  1603. static void ath9k_get_et_strings(struct ieee80211_hw *hw,
  1604. struct ieee80211_vif *vif,
  1605. u32 sset, u8 *data)
  1606. {
  1607. if (sset == ETH_SS_STATS)
  1608. memcpy(data, *ath9k_gstrings_stats,
  1609. sizeof(ath9k_gstrings_stats));
  1610. }
  1611. static int ath9k_get_et_sset_count(struct ieee80211_hw *hw,
  1612. struct ieee80211_vif *vif, int sset)
  1613. {
  1614. if (sset == ETH_SS_STATS)
  1615. return ATH9K_SSTATS_LEN;
  1616. return 0;
  1617. }
  1618. #define PR_QNUM(_n) (sc->tx.txq_map[_n]->axq_qnum)
  1619. #define AWDATA(elem) \
  1620. do { \
  1621. data[i++] = sc->debug.stats.txstats[PR_QNUM(WME_AC_BE)].elem; \
  1622. data[i++] = sc->debug.stats.txstats[PR_QNUM(WME_AC_BK)].elem; \
  1623. data[i++] = sc->debug.stats.txstats[PR_QNUM(WME_AC_VI)].elem; \
  1624. data[i++] = sc->debug.stats.txstats[PR_QNUM(WME_AC_VO)].elem; \
  1625. } while (0)
  1626. #define AWDATA_RX(elem) \
  1627. do { \
  1628. data[i++] = sc->debug.stats.rxstats.elem; \
  1629. } while (0)
  1630. static void ath9k_get_et_stats(struct ieee80211_hw *hw,
  1631. struct ieee80211_vif *vif,
  1632. struct ethtool_stats *stats, u64 *data)
  1633. {
  1634. struct ath_softc *sc = hw->priv;
  1635. int i = 0;
  1636. data[i++] = (sc->debug.stats.txstats[PR_QNUM(WME_AC_BE)].tx_pkts_all +
  1637. sc->debug.stats.txstats[PR_QNUM(WME_AC_BK)].tx_pkts_all +
  1638. sc->debug.stats.txstats[PR_QNUM(WME_AC_VI)].tx_pkts_all +
  1639. sc->debug.stats.txstats[PR_QNUM(WME_AC_VO)].tx_pkts_all);
  1640. data[i++] = (sc->debug.stats.txstats[PR_QNUM(WME_AC_BE)].tx_bytes_all +
  1641. sc->debug.stats.txstats[PR_QNUM(WME_AC_BK)].tx_bytes_all +
  1642. sc->debug.stats.txstats[PR_QNUM(WME_AC_VI)].tx_bytes_all +
  1643. sc->debug.stats.txstats[PR_QNUM(WME_AC_VO)].tx_bytes_all);
  1644. AWDATA_RX(rx_pkts_all);
  1645. AWDATA_RX(rx_bytes_all);
  1646. AWDATA(tx_pkts_all);
  1647. AWDATA(tx_bytes_all);
  1648. AWDATA(queued);
  1649. AWDATA(completed);
  1650. AWDATA(xretries);
  1651. AWDATA(a_aggr);
  1652. AWDATA(a_queued_hw);
  1653. AWDATA(a_queued_sw);
  1654. AWDATA(a_completed);
  1655. AWDATA(a_retries);
  1656. AWDATA(a_xretries);
  1657. AWDATA(fifo_underrun);
  1658. AWDATA(xtxop);
  1659. AWDATA(timer_exp);
  1660. AWDATA(desc_cfg_err);
  1661. AWDATA(data_underrun);
  1662. AWDATA(delim_underrun);
  1663. AWDATA_RX(decrypt_crc_err);
  1664. AWDATA_RX(phy_err);
  1665. AWDATA_RX(mic_err);
  1666. AWDATA_RX(pre_delim_crc_err);
  1667. AWDATA_RX(post_delim_crc_err);
  1668. AWDATA_RX(decrypt_busy_err);
  1669. AWDATA_RX(phy_err_stats[ATH9K_PHYERR_RADAR]);
  1670. AWDATA_RX(phy_err_stats[ATH9K_PHYERR_OFDM_TIMING]);
  1671. AWDATA_RX(phy_err_stats[ATH9K_PHYERR_CCK_TIMING]);
  1672. WARN_ON(i != ATH9K_SSTATS_LEN);
  1673. }
  1674. /* End of ethtool get-stats functions */
  1675. #endif
  1676. #ifdef CONFIG_PM_SLEEP
  1677. static void ath9k_wow_map_triggers(struct ath_softc *sc,
  1678. struct cfg80211_wowlan *wowlan,
  1679. u32 *wow_triggers)
  1680. {
  1681. if (wowlan->disconnect)
  1682. *wow_triggers |= AH_WOW_LINK_CHANGE |
  1683. AH_WOW_BEACON_MISS;
  1684. if (wowlan->magic_pkt)
  1685. *wow_triggers |= AH_WOW_MAGIC_PATTERN_EN;
  1686. if (wowlan->n_patterns)
  1687. *wow_triggers |= AH_WOW_USER_PATTERN_EN;
  1688. sc->wow_enabled = *wow_triggers;
  1689. }
  1690. static void ath9k_wow_add_disassoc_deauth_pattern(struct ath_softc *sc)
  1691. {
  1692. struct ath_hw *ah = sc->sc_ah;
  1693. struct ath_common *common = ath9k_hw_common(ah);
  1694. struct ath9k_hw_capabilities *pcaps = &ah->caps;
  1695. int pattern_count = 0;
  1696. int i, byte_cnt;
  1697. u8 dis_deauth_pattern[MAX_PATTERN_SIZE];
  1698. u8 dis_deauth_mask[MAX_PATTERN_SIZE];
  1699. memset(dis_deauth_pattern, 0, MAX_PATTERN_SIZE);
  1700. memset(dis_deauth_mask, 0, MAX_PATTERN_SIZE);
  1701. /*
  1702. * Create Dissassociate / Deauthenticate packet filter
  1703. *
  1704. * 2 bytes 2 byte 6 bytes 6 bytes 6 bytes
  1705. * +--------------+----------+---------+--------+--------+----
  1706. * + Frame Control+ Duration + DA + SA + BSSID +
  1707. * +--------------+----------+---------+--------+--------+----
  1708. *
  1709. * The above is the management frame format for disassociate/
  1710. * deauthenticate pattern, from this we need to match the first byte
  1711. * of 'Frame Control' and DA, SA, and BSSID fields
  1712. * (skipping 2nd byte of FC and Duration feild.
  1713. *
  1714. * Disassociate pattern
  1715. * --------------------
  1716. * Frame control = 00 00 1010
  1717. * DA, SA, BSSID = x:x:x:x:x:x
  1718. * Pattern will be A0000000 | x:x:x:x:x:x | x:x:x:x:x:x
  1719. * | x:x:x:x:x:x -- 22 bytes
  1720. *
  1721. * Deauthenticate pattern
  1722. * ----------------------
  1723. * Frame control = 00 00 1100
  1724. * DA, SA, BSSID = x:x:x:x:x:x
  1725. * Pattern will be C0000000 | x:x:x:x:x:x | x:x:x:x:x:x
  1726. * | x:x:x:x:x:x -- 22 bytes
  1727. */
  1728. /* Create Disassociate Pattern first */
  1729. byte_cnt = 0;
  1730. /* Fill out the mask with all FF's */
  1731. for (i = 0; i < MAX_PATTERN_MASK_SIZE; i++)
  1732. dis_deauth_mask[i] = 0xff;
  1733. /* copy the first byte of frame control field */
  1734. dis_deauth_pattern[byte_cnt] = 0xa0;
  1735. byte_cnt++;
  1736. /* skip 2nd byte of frame control and Duration field */
  1737. byte_cnt += 3;
  1738. /*
  1739. * need not match the destination mac address, it can be a broadcast
  1740. * mac address or an unicast to this station
  1741. */
  1742. byte_cnt += 6;
  1743. /* copy the source mac address */
  1744. memcpy((dis_deauth_pattern + byte_cnt), common->curbssid, ETH_ALEN);
  1745. byte_cnt += 6;
  1746. /* copy the bssid, its same as the source mac address */
  1747. memcpy((dis_deauth_pattern + byte_cnt), common->curbssid, ETH_ALEN);
  1748. /* Create Disassociate pattern mask */
  1749. if (pcaps->hw_caps & ATH9K_HW_WOW_PATTERN_MATCH_EXACT) {
  1750. if (pcaps->hw_caps & ATH9K_HW_WOW_PATTERN_MATCH_DWORD) {
  1751. /*
  1752. * for AR9280, because of hardware limitation, the
  1753. * first 4 bytes have to be matched for all patterns.
  1754. * the mask for disassociation and de-auth pattern
  1755. * matching need to enable the first 4 bytes.
  1756. * also the duration field needs to be filled.
  1757. */
  1758. dis_deauth_mask[0] = 0xf0;
  1759. /*
  1760. * fill in duration field
  1761. FIXME: what is the exact value ?
  1762. */
  1763. dis_deauth_pattern[2] = 0xff;
  1764. dis_deauth_pattern[3] = 0xff;
  1765. } else {
  1766. dis_deauth_mask[0] = 0xfe;
  1767. }
  1768. dis_deauth_mask[1] = 0x03;
  1769. dis_deauth_mask[2] = 0xc0;
  1770. } else {
  1771. dis_deauth_mask[0] = 0xef;
  1772. dis_deauth_mask[1] = 0x3f;
  1773. dis_deauth_mask[2] = 0x00;
  1774. dis_deauth_mask[3] = 0xfc;
  1775. }
  1776. ath_dbg(common, WOW, "Adding disassoc/deauth patterns for WoW\n");
  1777. ath9k_hw_wow_apply_pattern(ah, dis_deauth_pattern, dis_deauth_mask,
  1778. pattern_count, byte_cnt);
  1779. pattern_count++;
  1780. /*
  1781. * for de-authenticate pattern, only the first byte of the frame
  1782. * control field gets changed from 0xA0 to 0xC0
  1783. */
  1784. dis_deauth_pattern[0] = 0xC0;
  1785. ath9k_hw_wow_apply_pattern(ah, dis_deauth_pattern, dis_deauth_mask,
  1786. pattern_count, byte_cnt);
  1787. }
  1788. static void ath9k_wow_add_pattern(struct ath_softc *sc,
  1789. struct cfg80211_wowlan *wowlan)
  1790. {
  1791. struct ath_hw *ah = sc->sc_ah;
  1792. struct ath9k_wow_pattern *wow_pattern = NULL;
  1793. struct cfg80211_wowlan_trig_pkt_pattern *patterns = wowlan->patterns;
  1794. int mask_len;
  1795. s8 i = 0;
  1796. if (!wowlan->n_patterns)
  1797. return;
  1798. /*
  1799. * Add the new user configured patterns
  1800. */
  1801. for (i = 0; i < wowlan->n_patterns; i++) {
  1802. wow_pattern = kzalloc(sizeof(*wow_pattern), GFP_KERNEL);
  1803. if (!wow_pattern)
  1804. return;
  1805. /*
  1806. * TODO: convert the generic user space pattern to
  1807. * appropriate chip specific/802.11 pattern.
  1808. */
  1809. mask_len = DIV_ROUND_UP(wowlan->patterns[i].pattern_len, 8);
  1810. memset(wow_pattern->pattern_bytes, 0, MAX_PATTERN_SIZE);
  1811. memset(wow_pattern->mask_bytes, 0, MAX_PATTERN_SIZE);
  1812. memcpy(wow_pattern->pattern_bytes, patterns[i].pattern,
  1813. patterns[i].pattern_len);
  1814. memcpy(wow_pattern->mask_bytes, patterns[i].mask, mask_len);
  1815. wow_pattern->pattern_len = patterns[i].pattern_len;
  1816. /*
  1817. * just need to take care of deauth and disssoc pattern,
  1818. * make sure we don't overwrite them.
  1819. */
  1820. ath9k_hw_wow_apply_pattern(ah, wow_pattern->pattern_bytes,
  1821. wow_pattern->mask_bytes,
  1822. i + 2,
  1823. wow_pattern->pattern_len);
  1824. kfree(wow_pattern);
  1825. }
  1826. }
  1827. static int ath9k_suspend(struct ieee80211_hw *hw,
  1828. struct cfg80211_wowlan *wowlan)
  1829. {
  1830. struct ath_softc *sc = hw->priv;
  1831. struct ath_hw *ah = sc->sc_ah;
  1832. struct ath_common *common = ath9k_hw_common(ah);
  1833. u32 wow_triggers_enabled = 0;
  1834. int ret = 0;
  1835. mutex_lock(&sc->mutex);
  1836. ath_cancel_work(sc);
  1837. del_timer_sync(&common->ani.timer);
  1838. del_timer_sync(&sc->rx_poll_timer);
  1839. if (test_bit(SC_OP_INVALID, &sc->sc_flags)) {
  1840. ath_dbg(common, ANY, "Device not present\n");
  1841. ret = -EINVAL;
  1842. goto fail_wow;
  1843. }
  1844. if (WARN_ON(!wowlan)) {
  1845. ath_dbg(common, WOW, "None of the WoW triggers enabled\n");
  1846. ret = -EINVAL;
  1847. goto fail_wow;
  1848. }
  1849. if (!device_can_wakeup(sc->dev)) {
  1850. ath_dbg(common, WOW, "device_can_wakeup failed, WoW is not enabled\n");
  1851. ret = 1;
  1852. goto fail_wow;
  1853. }
  1854. /*
  1855. * none of the sta vifs are associated
  1856. * and we are not currently handling multivif
  1857. * cases, for instance we have to seperately
  1858. * configure 'keep alive frame' for each
  1859. * STA.
  1860. */
  1861. if (!test_bit(SC_OP_PRIM_STA_VIF, &sc->sc_flags)) {
  1862. ath_dbg(common, WOW, "None of the STA vifs are associated\n");
  1863. ret = 1;
  1864. goto fail_wow;
  1865. }
  1866. if (sc->nvifs > 1) {
  1867. ath_dbg(common, WOW, "WoW for multivif is not yet supported\n");
  1868. ret = 1;
  1869. goto fail_wow;
  1870. }
  1871. ath9k_wow_map_triggers(sc, wowlan, &wow_triggers_enabled);
  1872. ath_dbg(common, WOW, "WoW triggers enabled 0x%x\n",
  1873. wow_triggers_enabled);
  1874. ath9k_ps_wakeup(sc);
  1875. ath9k_stop_btcoex(sc);
  1876. /*
  1877. * Enable wake up on recieving disassoc/deauth
  1878. * frame by default.
  1879. */
  1880. ath9k_wow_add_disassoc_deauth_pattern(sc);
  1881. if (wow_triggers_enabled & AH_WOW_USER_PATTERN_EN)
  1882. ath9k_wow_add_pattern(sc, wowlan);
  1883. spin_lock_bh(&sc->sc_pcu_lock);
  1884. /*
  1885. * To avoid false wake, we enable beacon miss interrupt only
  1886. * when we go to sleep. We save the current interrupt mask
  1887. * so we can restore it after the system wakes up
  1888. */
  1889. sc->wow_intr_before_sleep = ah->imask;
  1890. ah->imask &= ~ATH9K_INT_GLOBAL;
  1891. ath9k_hw_disable_interrupts(ah);
  1892. ah->imask = ATH9K_INT_BMISS | ATH9K_INT_GLOBAL;
  1893. ath9k_hw_set_interrupts(ah);
  1894. ath9k_hw_enable_interrupts(ah);
  1895. spin_unlock_bh(&sc->sc_pcu_lock);
  1896. /*
  1897. * we can now sync irq and kill any running tasklets, since we already
  1898. * disabled interrupts and not holding a spin lock
  1899. */
  1900. synchronize_irq(sc->irq);
  1901. tasklet_kill(&sc->intr_tq);
  1902. ath9k_hw_wow_enable(ah, wow_triggers_enabled);
  1903. ath9k_ps_restore(sc);
  1904. ath_dbg(common, ANY, "WoW enabled in ath9k\n");
  1905. atomic_inc(&sc->wow_sleep_proc_intr);
  1906. fail_wow:
  1907. mutex_unlock(&sc->mutex);
  1908. return ret;
  1909. }
  1910. static int ath9k_resume(struct ieee80211_hw *hw)
  1911. {
  1912. struct ath_softc *sc = hw->priv;
  1913. struct ath_hw *ah = sc->sc_ah;
  1914. struct ath_common *common = ath9k_hw_common(ah);
  1915. u32 wow_status;
  1916. mutex_lock(&sc->mutex);
  1917. ath9k_ps_wakeup(sc);
  1918. spin_lock_bh(&sc->sc_pcu_lock);
  1919. ath9k_hw_disable_interrupts(ah);
  1920. ah->imask = sc->wow_intr_before_sleep;
  1921. ath9k_hw_set_interrupts(ah);
  1922. ath9k_hw_enable_interrupts(ah);
  1923. spin_unlock_bh(&sc->sc_pcu_lock);
  1924. wow_status = ath9k_hw_wow_wakeup(ah);
  1925. if (atomic_read(&sc->wow_got_bmiss_intr) == 0) {
  1926. /*
  1927. * some devices may not pick beacon miss
  1928. * as the reason they woke up so we add
  1929. * that here for that shortcoming.
  1930. */
  1931. wow_status |= AH_WOW_BEACON_MISS;
  1932. atomic_dec(&sc->wow_got_bmiss_intr);
  1933. ath_dbg(common, ANY, "Beacon miss interrupt picked up during WoW sleep\n");
  1934. }
  1935. atomic_dec(&sc->wow_sleep_proc_intr);
  1936. if (wow_status) {
  1937. ath_dbg(common, ANY, "Waking up due to WoW triggers %s with WoW status = %x\n",
  1938. ath9k_hw_wow_event_to_string(wow_status), wow_status);
  1939. }
  1940. ath_restart_work(sc);
  1941. ath9k_start_btcoex(sc);
  1942. ath9k_ps_restore(sc);
  1943. mutex_unlock(&sc->mutex);
  1944. return 0;
  1945. }
  1946. static void ath9k_set_wakeup(struct ieee80211_hw *hw, bool enabled)
  1947. {
  1948. struct ath_softc *sc = hw->priv;
  1949. mutex_lock(&sc->mutex);
  1950. device_init_wakeup(sc->dev, 1);
  1951. device_set_wakeup_enable(sc->dev, enabled);
  1952. mutex_unlock(&sc->mutex);
  1953. }
  1954. #endif
  1955. struct ieee80211_ops ath9k_ops = {
  1956. .tx = ath9k_tx,
  1957. .start = ath9k_start,
  1958. .stop = ath9k_stop,
  1959. .add_interface = ath9k_add_interface,
  1960. .change_interface = ath9k_change_interface,
  1961. .remove_interface = ath9k_remove_interface,
  1962. .config = ath9k_config,
  1963. .configure_filter = ath9k_configure_filter,
  1964. .sta_add = ath9k_sta_add,
  1965. .sta_remove = ath9k_sta_remove,
  1966. .sta_notify = ath9k_sta_notify,
  1967. .conf_tx = ath9k_conf_tx,
  1968. .bss_info_changed = ath9k_bss_info_changed,
  1969. .set_key = ath9k_set_key,
  1970. .get_tsf = ath9k_get_tsf,
  1971. .set_tsf = ath9k_set_tsf,
  1972. .reset_tsf = ath9k_reset_tsf,
  1973. .ampdu_action = ath9k_ampdu_action,
  1974. .get_survey = ath9k_get_survey,
  1975. .rfkill_poll = ath9k_rfkill_poll_state,
  1976. .set_coverage_class = ath9k_set_coverage_class,
  1977. .flush = ath9k_flush,
  1978. .tx_frames_pending = ath9k_tx_frames_pending,
  1979. .tx_last_beacon = ath9k_tx_last_beacon,
  1980. .get_stats = ath9k_get_stats,
  1981. .set_antenna = ath9k_set_antenna,
  1982. .get_antenna = ath9k_get_antenna,
  1983. #ifdef CONFIG_PM_SLEEP
  1984. .suspend = ath9k_suspend,
  1985. .resume = ath9k_resume,
  1986. .set_wakeup = ath9k_set_wakeup,
  1987. #endif
  1988. #ifdef CONFIG_ATH9K_DEBUGFS
  1989. .get_et_sset_count = ath9k_get_et_sset_count,
  1990. .get_et_stats = ath9k_get_et_stats,
  1991. .get_et_strings = ath9k_get_et_strings,
  1992. #endif
  1993. };