main.c 58 KB

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