main.c 58 KB

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