main.c 58 KB

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