main.c 63 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654
  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. u8 ath9k_parse_mpdudensity(u8 mpdudensity)
  21. {
  22. /*
  23. * 802.11n D2.0 defined values for "Minimum MPDU Start Spacing":
  24. * 0 for no restriction
  25. * 1 for 1/4 us
  26. * 2 for 1/2 us
  27. * 3 for 1 us
  28. * 4 for 2 us
  29. * 5 for 4 us
  30. * 6 for 8 us
  31. * 7 for 16 us
  32. */
  33. switch (mpdudensity) {
  34. case 0:
  35. return 0;
  36. case 1:
  37. case 2:
  38. case 3:
  39. /* Our lower layer calculations limit our precision to
  40. 1 microsecond */
  41. return 1;
  42. case 4:
  43. return 2;
  44. case 5:
  45. return 4;
  46. case 6:
  47. return 8;
  48. case 7:
  49. return 16;
  50. default:
  51. return 0;
  52. }
  53. }
  54. static bool ath9k_has_pending_frames(struct ath_softc *sc, struct ath_txq *txq)
  55. {
  56. bool pending = false;
  57. spin_lock_bh(&txq->axq_lock);
  58. if (txq->axq_depth)
  59. pending = true;
  60. if (txq->mac80211_qnum >= 0) {
  61. struct list_head *list;
  62. list = &sc->cur_chan->acq[txq->mac80211_qnum];
  63. if (!list_empty(list))
  64. pending = true;
  65. }
  66. spin_unlock_bh(&txq->axq_lock);
  67. return pending;
  68. }
  69. static bool ath9k_setpower(struct ath_softc *sc, enum ath9k_power_mode mode)
  70. {
  71. unsigned long flags;
  72. bool ret;
  73. spin_lock_irqsave(&sc->sc_pm_lock, flags);
  74. ret = ath9k_hw_setpower(sc->sc_ah, mode);
  75. spin_unlock_irqrestore(&sc->sc_pm_lock, flags);
  76. return ret;
  77. }
  78. void ath_ps_full_sleep(unsigned long data)
  79. {
  80. struct ath_softc *sc = (struct ath_softc *) data;
  81. struct ath_common *common = ath9k_hw_common(sc->sc_ah);
  82. bool reset;
  83. spin_lock(&common->cc_lock);
  84. ath_hw_cycle_counters_update(common);
  85. spin_unlock(&common->cc_lock);
  86. ath9k_hw_setrxabort(sc->sc_ah, 1);
  87. ath9k_hw_stopdmarecv(sc->sc_ah, &reset);
  88. ath9k_hw_setpower(sc->sc_ah, ATH9K_PM_FULL_SLEEP);
  89. }
  90. void ath9k_ps_wakeup(struct ath_softc *sc)
  91. {
  92. struct ath_common *common = ath9k_hw_common(sc->sc_ah);
  93. unsigned long flags;
  94. enum ath9k_power_mode power_mode;
  95. spin_lock_irqsave(&sc->sc_pm_lock, flags);
  96. if (++sc->ps_usecount != 1)
  97. goto unlock;
  98. del_timer_sync(&sc->sleep_timer);
  99. power_mode = sc->sc_ah->power_mode;
  100. ath9k_hw_setpower(sc->sc_ah, ATH9K_PM_AWAKE);
  101. /*
  102. * While the hardware is asleep, the cycle counters contain no
  103. * useful data. Better clear them now so that they don't mess up
  104. * survey data results.
  105. */
  106. if (power_mode != ATH9K_PM_AWAKE) {
  107. spin_lock(&common->cc_lock);
  108. ath_hw_cycle_counters_update(common);
  109. memset(&common->cc_survey, 0, sizeof(common->cc_survey));
  110. memset(&common->cc_ani, 0, sizeof(common->cc_ani));
  111. spin_unlock(&common->cc_lock);
  112. }
  113. unlock:
  114. spin_unlock_irqrestore(&sc->sc_pm_lock, flags);
  115. }
  116. void ath9k_ps_restore(struct ath_softc *sc)
  117. {
  118. struct ath_common *common = ath9k_hw_common(sc->sc_ah);
  119. enum ath9k_power_mode mode;
  120. unsigned long flags;
  121. spin_lock_irqsave(&sc->sc_pm_lock, flags);
  122. if (--sc->ps_usecount != 0)
  123. goto unlock;
  124. if (sc->ps_idle) {
  125. mod_timer(&sc->sleep_timer, jiffies + HZ / 10);
  126. goto unlock;
  127. }
  128. if (sc->ps_enabled &&
  129. !(sc->ps_flags & (PS_WAIT_FOR_BEACON |
  130. PS_WAIT_FOR_CAB |
  131. PS_WAIT_FOR_PSPOLL_DATA |
  132. PS_WAIT_FOR_TX_ACK |
  133. PS_WAIT_FOR_ANI))) {
  134. mode = ATH9K_PM_NETWORK_SLEEP;
  135. if (ath9k_hw_btcoex_is_enabled(sc->sc_ah))
  136. ath9k_btcoex_stop_gen_timer(sc);
  137. } else {
  138. goto unlock;
  139. }
  140. spin_lock(&common->cc_lock);
  141. ath_hw_cycle_counters_update(common);
  142. spin_unlock(&common->cc_lock);
  143. ath9k_hw_setpower(sc->sc_ah, mode);
  144. unlock:
  145. spin_unlock_irqrestore(&sc->sc_pm_lock, flags);
  146. }
  147. static void __ath_cancel_work(struct ath_softc *sc)
  148. {
  149. cancel_work_sync(&sc->paprd_work);
  150. cancel_delayed_work_sync(&sc->tx_complete_work);
  151. cancel_delayed_work_sync(&sc->hw_pll_work);
  152. #ifdef CONFIG_ATH9K_BTCOEX_SUPPORT
  153. if (ath9k_hw_mci_is_enabled(sc->sc_ah))
  154. cancel_work_sync(&sc->mci_work);
  155. #endif
  156. }
  157. void ath_cancel_work(struct ath_softc *sc)
  158. {
  159. __ath_cancel_work(sc);
  160. cancel_work_sync(&sc->hw_reset_work);
  161. }
  162. void ath_restart_work(struct ath_softc *sc)
  163. {
  164. ieee80211_queue_delayed_work(sc->hw, &sc->tx_complete_work, 0);
  165. if (AR_SREV_9340(sc->sc_ah) || AR_SREV_9330(sc->sc_ah))
  166. ieee80211_queue_delayed_work(sc->hw, &sc->hw_pll_work,
  167. msecs_to_jiffies(ATH_PLL_WORK_INTERVAL));
  168. ath_start_ani(sc);
  169. }
  170. static bool ath_prepare_reset(struct ath_softc *sc)
  171. {
  172. struct ath_hw *ah = sc->sc_ah;
  173. bool ret = true;
  174. ieee80211_stop_queues(sc->hw);
  175. ath_stop_ani(sc);
  176. ath9k_hw_disable_interrupts(ah);
  177. if (!ath_drain_all_txq(sc))
  178. ret = false;
  179. if (!ath_stoprecv(sc))
  180. ret = false;
  181. return ret;
  182. }
  183. static bool ath_complete_reset(struct ath_softc *sc, bool start)
  184. {
  185. struct ath_hw *ah = sc->sc_ah;
  186. struct ath_common *common = ath9k_hw_common(ah);
  187. unsigned long flags;
  188. int i;
  189. if (ath_startrecv(sc) != 0) {
  190. ath_err(common, "Unable to restart recv logic\n");
  191. return false;
  192. }
  193. ath9k_cmn_update_txpow(ah, sc->curtxpow,
  194. sc->cur_chan->txpower, &sc->curtxpow);
  195. clear_bit(ATH_OP_HW_RESET, &common->op_flags);
  196. ath9k_calculate_summary_state(sc, sc->cur_chan);
  197. if (!sc->cur_chan->offchannel && start) {
  198. /* restore per chanctx TSF timer */
  199. if (sc->cur_chan->tsf_val) {
  200. u32 offset;
  201. offset = ath9k_hw_get_tsf_offset(&sc->cur_chan->tsf_ts,
  202. NULL);
  203. ath9k_hw_settsf64(ah, sc->cur_chan->tsf_val + offset);
  204. }
  205. if (!test_bit(ATH_OP_BEACONS, &common->op_flags))
  206. goto work;
  207. if (ah->opmode == NL80211_IFTYPE_STATION &&
  208. test_bit(ATH_OP_PRIM_STA_VIF, &common->op_flags)) {
  209. spin_lock_irqsave(&sc->sc_pm_lock, flags);
  210. sc->ps_flags |= PS_BEACON_SYNC | PS_WAIT_FOR_BEACON;
  211. spin_unlock_irqrestore(&sc->sc_pm_lock, flags);
  212. } else {
  213. ath9k_set_beacon(sc);
  214. }
  215. work:
  216. ath_restart_work(sc);
  217. ath_txq_schedule_all(sc);
  218. }
  219. sc->gtt_cnt = 0;
  220. ath9k_hw_set_interrupts(ah);
  221. ath9k_hw_enable_interrupts(ah);
  222. if (!ath9k_use_chanctx)
  223. ieee80211_wake_queues(sc->hw);
  224. else {
  225. if (sc->cur_chan == &sc->offchannel.chan)
  226. ieee80211_wake_queue(sc->hw,
  227. sc->hw->offchannel_tx_hw_queue);
  228. else {
  229. for (i = 0; i < IEEE80211_NUM_ACS; i++)
  230. ieee80211_wake_queue(sc->hw,
  231. sc->cur_chan->hw_queue_base + i);
  232. }
  233. if (ah->opmode == NL80211_IFTYPE_AP)
  234. ieee80211_wake_queue(sc->hw, sc->hw->queues - 2);
  235. }
  236. ath9k_p2p_ps_timer(sc);
  237. return true;
  238. }
  239. int ath_reset_internal(struct ath_softc *sc, struct ath9k_channel *hchan)
  240. {
  241. struct ath_hw *ah = sc->sc_ah;
  242. struct ath_common *common = ath9k_hw_common(ah);
  243. struct ath9k_hw_cal_data *caldata = NULL;
  244. bool fastcc = true;
  245. int r;
  246. __ath_cancel_work(sc);
  247. tasklet_disable(&sc->intr_tq);
  248. spin_lock_bh(&sc->sc_pcu_lock);
  249. if (!sc->cur_chan->offchannel) {
  250. fastcc = false;
  251. caldata = &sc->cur_chan->caldata;
  252. }
  253. if (!hchan) {
  254. fastcc = false;
  255. hchan = ah->curchan;
  256. }
  257. if (!ath_prepare_reset(sc))
  258. fastcc = false;
  259. if (hchan) {
  260. spin_lock_bh(&sc->chan_lock);
  261. sc->cur_chandef = sc->cur_chan->chandef;
  262. spin_unlock_bh(&sc->chan_lock);
  263. }
  264. ath_dbg(common, CONFIG, "Reset to %u MHz, HT40: %d fastcc: %d\n",
  265. hchan->channel, IS_CHAN_HT40(hchan), fastcc);
  266. r = ath9k_hw_reset(ah, hchan, caldata, fastcc);
  267. if (r) {
  268. ath_err(common,
  269. "Unable to reset channel, reset status %d\n", r);
  270. ath9k_hw_enable_interrupts(ah);
  271. ath9k_queue_reset(sc, RESET_TYPE_BB_HANG);
  272. goto out;
  273. }
  274. if (ath9k_hw_mci_is_enabled(sc->sc_ah) &&
  275. sc->cur_chan->offchannel)
  276. ath9k_mci_set_txpower(sc, true, false);
  277. if (!ath_complete_reset(sc, true))
  278. r = -EIO;
  279. out:
  280. spin_unlock_bh(&sc->sc_pcu_lock);
  281. tasklet_enable(&sc->intr_tq);
  282. return r;
  283. }
  284. static void ath_node_attach(struct ath_softc *sc, struct ieee80211_sta *sta,
  285. struct ieee80211_vif *vif)
  286. {
  287. struct ath_node *an;
  288. an = (struct ath_node *)sta->drv_priv;
  289. an->sc = sc;
  290. an->sta = sta;
  291. an->vif = vif;
  292. memset(&an->key_idx, 0, sizeof(an->key_idx));
  293. ath_tx_node_init(sc, an);
  294. }
  295. static void ath_node_detach(struct ath_softc *sc, struct ieee80211_sta *sta)
  296. {
  297. struct ath_node *an = (struct ath_node *)sta->drv_priv;
  298. ath_tx_node_cleanup(sc, an);
  299. }
  300. void ath9k_tasklet(unsigned long data)
  301. {
  302. struct ath_softc *sc = (struct ath_softc *)data;
  303. struct ath_hw *ah = sc->sc_ah;
  304. struct ath_common *common = ath9k_hw_common(ah);
  305. enum ath_reset_type type;
  306. unsigned long flags;
  307. u32 status = sc->intrstatus;
  308. u32 rxmask;
  309. ath9k_ps_wakeup(sc);
  310. spin_lock(&sc->sc_pcu_lock);
  311. if (status & ATH9K_INT_FATAL) {
  312. type = RESET_TYPE_FATAL_INT;
  313. ath9k_queue_reset(sc, type);
  314. /*
  315. * Increment the ref. counter here so that
  316. * interrupts are enabled in the reset routine.
  317. */
  318. atomic_inc(&ah->intr_ref_cnt);
  319. ath_dbg(common, RESET, "FATAL: Skipping interrupts\n");
  320. goto out;
  321. }
  322. if ((ah->config.hw_hang_checks & HW_BB_WATCHDOG) &&
  323. (status & ATH9K_INT_BB_WATCHDOG)) {
  324. spin_lock(&common->cc_lock);
  325. ath_hw_cycle_counters_update(common);
  326. ar9003_hw_bb_watchdog_dbg_info(ah);
  327. spin_unlock(&common->cc_lock);
  328. if (ar9003_hw_bb_watchdog_check(ah)) {
  329. type = RESET_TYPE_BB_WATCHDOG;
  330. ath9k_queue_reset(sc, type);
  331. /*
  332. * Increment the ref. counter here so that
  333. * interrupts are enabled in the reset routine.
  334. */
  335. atomic_inc(&ah->intr_ref_cnt);
  336. ath_dbg(common, RESET,
  337. "BB_WATCHDOG: Skipping interrupts\n");
  338. goto out;
  339. }
  340. }
  341. if (status & ATH9K_INT_GTT) {
  342. sc->gtt_cnt++;
  343. if ((sc->gtt_cnt >= MAX_GTT_CNT) && !ath9k_hw_check_alive(ah)) {
  344. type = RESET_TYPE_TX_GTT;
  345. ath9k_queue_reset(sc, type);
  346. atomic_inc(&ah->intr_ref_cnt);
  347. ath_dbg(common, RESET,
  348. "GTT: Skipping interrupts\n");
  349. goto out;
  350. }
  351. }
  352. spin_lock_irqsave(&sc->sc_pm_lock, flags);
  353. if ((status & ATH9K_INT_TSFOOR) && sc->ps_enabled) {
  354. /*
  355. * TSF sync does not look correct; remain awake to sync with
  356. * the next Beacon.
  357. */
  358. ath_dbg(common, PS, "TSFOOR - Sync with next Beacon\n");
  359. sc->ps_flags |= PS_WAIT_FOR_BEACON | PS_BEACON_SYNC;
  360. }
  361. spin_unlock_irqrestore(&sc->sc_pm_lock, flags);
  362. if (ah->caps.hw_caps & ATH9K_HW_CAP_EDMA)
  363. rxmask = (ATH9K_INT_RXHP | ATH9K_INT_RXLP | ATH9K_INT_RXEOL |
  364. ATH9K_INT_RXORN);
  365. else
  366. rxmask = (ATH9K_INT_RX | ATH9K_INT_RXEOL | ATH9K_INT_RXORN);
  367. if (status & rxmask) {
  368. /* Check for high priority Rx first */
  369. if ((ah->caps.hw_caps & ATH9K_HW_CAP_EDMA) &&
  370. (status & ATH9K_INT_RXHP))
  371. ath_rx_tasklet(sc, 0, true);
  372. ath_rx_tasklet(sc, 0, false);
  373. }
  374. if (status & ATH9K_INT_TX) {
  375. if (ah->caps.hw_caps & ATH9K_HW_CAP_EDMA) {
  376. /*
  377. * For EDMA chips, TX completion is enabled for the
  378. * beacon queue, so if a beacon has been transmitted
  379. * successfully after a GTT interrupt, the GTT counter
  380. * gets reset to zero here.
  381. */
  382. sc->gtt_cnt = 0;
  383. ath_tx_edma_tasklet(sc);
  384. } else {
  385. ath_tx_tasklet(sc);
  386. }
  387. wake_up(&sc->tx_wait);
  388. }
  389. if (status & ATH9K_INT_GENTIMER)
  390. ath_gen_timer_isr(sc->sc_ah);
  391. ath9k_btcoex_handle_interrupt(sc, status);
  392. /* re-enable hardware interrupt */
  393. ath9k_hw_enable_interrupts(ah);
  394. out:
  395. spin_unlock(&sc->sc_pcu_lock);
  396. ath9k_ps_restore(sc);
  397. }
  398. irqreturn_t ath_isr(int irq, void *dev)
  399. {
  400. #define SCHED_INTR ( \
  401. ATH9K_INT_FATAL | \
  402. ATH9K_INT_BB_WATCHDOG | \
  403. ATH9K_INT_RXORN | \
  404. ATH9K_INT_RXEOL | \
  405. ATH9K_INT_RX | \
  406. ATH9K_INT_RXLP | \
  407. ATH9K_INT_RXHP | \
  408. ATH9K_INT_TX | \
  409. ATH9K_INT_BMISS | \
  410. ATH9K_INT_CST | \
  411. ATH9K_INT_GTT | \
  412. ATH9K_INT_TSFOOR | \
  413. ATH9K_INT_GENTIMER | \
  414. ATH9K_INT_MCI)
  415. struct ath_softc *sc = dev;
  416. struct ath_hw *ah = sc->sc_ah;
  417. struct ath_common *common = ath9k_hw_common(ah);
  418. enum ath9k_int status;
  419. u32 sync_cause = 0;
  420. bool sched = false;
  421. /*
  422. * The hardware is not ready/present, don't
  423. * touch anything. Note this can happen early
  424. * on if the IRQ is shared.
  425. */
  426. if (test_bit(ATH_OP_INVALID, &common->op_flags))
  427. return IRQ_NONE;
  428. /* shared irq, not for us */
  429. if (!ath9k_hw_intrpend(ah))
  430. return IRQ_NONE;
  431. if (test_bit(ATH_OP_HW_RESET, &common->op_flags)) {
  432. ath9k_hw_kill_interrupts(ah);
  433. return IRQ_HANDLED;
  434. }
  435. /*
  436. * Figure out the reason(s) for the interrupt. Note
  437. * that the hal returns a pseudo-ISR that may include
  438. * bits we haven't explicitly enabled so we mask the
  439. * value to insure we only process bits we requested.
  440. */
  441. ath9k_hw_getisr(ah, &status, &sync_cause); /* NB: clears ISR too */
  442. ath9k_debug_sync_cause(sc, sync_cause);
  443. status &= ah->imask; /* discard unasked-for bits */
  444. /*
  445. * If there are no status bits set, then this interrupt was not
  446. * for me (should have been caught above).
  447. */
  448. if (!status)
  449. return IRQ_NONE;
  450. /* Cache the status */
  451. sc->intrstatus = status;
  452. if (status & SCHED_INTR)
  453. sched = true;
  454. /*
  455. * If a FATAL or RXORN interrupt is received, we have to reset the
  456. * chip immediately.
  457. */
  458. if ((status & ATH9K_INT_FATAL) || ((status & ATH9K_INT_RXORN) &&
  459. !(ah->caps.hw_caps & ATH9K_HW_CAP_EDMA)))
  460. goto chip_reset;
  461. if ((ah->config.hw_hang_checks & HW_BB_WATCHDOG) &&
  462. (status & ATH9K_INT_BB_WATCHDOG))
  463. goto chip_reset;
  464. #ifdef CONFIG_ATH9K_WOW
  465. if (status & ATH9K_INT_BMISS) {
  466. if (atomic_read(&sc->wow_sleep_proc_intr) == 0) {
  467. atomic_inc(&sc->wow_got_bmiss_intr);
  468. atomic_dec(&sc->wow_sleep_proc_intr);
  469. }
  470. }
  471. #endif
  472. if (status & ATH9K_INT_SWBA)
  473. tasklet_schedule(&sc->bcon_tasklet);
  474. if (status & ATH9K_INT_TXURN)
  475. ath9k_hw_updatetxtriglevel(ah, true);
  476. if (status & ATH9K_INT_RXEOL) {
  477. ah->imask &= ~(ATH9K_INT_RXEOL | ATH9K_INT_RXORN);
  478. ath9k_hw_set_interrupts(ah);
  479. }
  480. if (!(ah->caps.hw_caps & ATH9K_HW_CAP_AUTOSLEEP))
  481. if (status & ATH9K_INT_TIM_TIMER) {
  482. if (ATH_DBG_WARN_ON_ONCE(sc->ps_idle))
  483. goto chip_reset;
  484. /* Clear RxAbort bit so that we can
  485. * receive frames */
  486. ath9k_setpower(sc, ATH9K_PM_AWAKE);
  487. spin_lock(&sc->sc_pm_lock);
  488. ath9k_hw_setrxabort(sc->sc_ah, 0);
  489. sc->ps_flags |= PS_WAIT_FOR_BEACON;
  490. spin_unlock(&sc->sc_pm_lock);
  491. }
  492. chip_reset:
  493. ath_debug_stat_interrupt(sc, status);
  494. if (sched) {
  495. /* turn off every interrupt */
  496. ath9k_hw_disable_interrupts(ah);
  497. tasklet_schedule(&sc->intr_tq);
  498. }
  499. return IRQ_HANDLED;
  500. #undef SCHED_INTR
  501. }
  502. int ath_reset(struct ath_softc *sc)
  503. {
  504. int r;
  505. ath9k_ps_wakeup(sc);
  506. r = ath_reset_internal(sc, NULL);
  507. ath9k_ps_restore(sc);
  508. return r;
  509. }
  510. void ath9k_queue_reset(struct ath_softc *sc, enum ath_reset_type type)
  511. {
  512. struct ath_common *common = ath9k_hw_common(sc->sc_ah);
  513. #ifdef CONFIG_ATH9K_DEBUGFS
  514. RESET_STAT_INC(sc, type);
  515. #endif
  516. set_bit(ATH_OP_HW_RESET, &common->op_flags);
  517. ieee80211_queue_work(sc->hw, &sc->hw_reset_work);
  518. }
  519. void ath_reset_work(struct work_struct *work)
  520. {
  521. struct ath_softc *sc = container_of(work, struct ath_softc, hw_reset_work);
  522. ath_reset(sc);
  523. }
  524. /**********************/
  525. /* mac80211 callbacks */
  526. /**********************/
  527. static int ath9k_start(struct ieee80211_hw *hw)
  528. {
  529. struct ath_softc *sc = hw->priv;
  530. struct ath_hw *ah = sc->sc_ah;
  531. struct ath_common *common = ath9k_hw_common(ah);
  532. struct ieee80211_channel *curchan = sc->cur_chan->chandef.chan;
  533. struct ath_chanctx *ctx = sc->cur_chan;
  534. struct ath9k_channel *init_channel;
  535. int r;
  536. ath_dbg(common, CONFIG,
  537. "Starting driver with initial channel: %d MHz\n",
  538. curchan->center_freq);
  539. ath9k_ps_wakeup(sc);
  540. mutex_lock(&sc->mutex);
  541. init_channel = ath9k_cmn_get_channel(hw, ah, &ctx->chandef);
  542. sc->cur_chandef = hw->conf.chandef;
  543. /* Reset SERDES registers */
  544. ath9k_hw_configpcipowersave(ah, false);
  545. /*
  546. * The basic interface to setting the hardware in a good
  547. * state is ``reset''. On return the hardware is known to
  548. * be powered up and with interrupts disabled. This must
  549. * be followed by initialization of the appropriate bits
  550. * and then setup of the interrupt mask.
  551. */
  552. spin_lock_bh(&sc->sc_pcu_lock);
  553. atomic_set(&ah->intr_ref_cnt, -1);
  554. r = ath9k_hw_reset(ah, init_channel, ah->caldata, false);
  555. if (r) {
  556. ath_err(common,
  557. "Unable to reset hardware; reset status %d (freq %u MHz)\n",
  558. r, curchan->center_freq);
  559. ah->reset_power_on = false;
  560. }
  561. /* Setup our intr mask. */
  562. ah->imask = ATH9K_INT_TX | ATH9K_INT_RXEOL |
  563. ATH9K_INT_RXORN | ATH9K_INT_FATAL |
  564. ATH9K_INT_GLOBAL;
  565. if (ah->caps.hw_caps & ATH9K_HW_CAP_EDMA)
  566. ah->imask |= ATH9K_INT_RXHP |
  567. ATH9K_INT_RXLP;
  568. else
  569. ah->imask |= ATH9K_INT_RX;
  570. if (ah->config.hw_hang_checks & HW_BB_WATCHDOG)
  571. ah->imask |= ATH9K_INT_BB_WATCHDOG;
  572. /*
  573. * Enable GTT interrupts only for AR9003/AR9004 chips
  574. * for now.
  575. */
  576. if (AR_SREV_9300_20_OR_LATER(ah))
  577. ah->imask |= ATH9K_INT_GTT;
  578. if (ah->caps.hw_caps & ATH9K_HW_CAP_HT)
  579. ah->imask |= ATH9K_INT_CST;
  580. ath_mci_enable(sc);
  581. clear_bit(ATH_OP_INVALID, &common->op_flags);
  582. sc->sc_ah->is_monitoring = false;
  583. if (!ath_complete_reset(sc, false))
  584. ah->reset_power_on = false;
  585. if (ah->led_pin >= 0) {
  586. ath9k_hw_cfg_output(ah, ah->led_pin,
  587. AR_GPIO_OUTPUT_MUX_AS_OUTPUT);
  588. ath9k_hw_set_gpio(ah, ah->led_pin, 0);
  589. }
  590. /*
  591. * Reset key cache to sane defaults (all entries cleared) instead of
  592. * semi-random values after suspend/resume.
  593. */
  594. ath9k_cmn_init_crypto(sc->sc_ah);
  595. ath9k_hw_reset_tsf(ah);
  596. spin_unlock_bh(&sc->sc_pcu_lock);
  597. mutex_unlock(&sc->mutex);
  598. ath9k_ps_restore(sc);
  599. return 0;
  600. }
  601. static void ath9k_tx(struct ieee80211_hw *hw,
  602. struct ieee80211_tx_control *control,
  603. struct sk_buff *skb)
  604. {
  605. struct ath_softc *sc = hw->priv;
  606. struct ath_common *common = ath9k_hw_common(sc->sc_ah);
  607. struct ath_tx_control txctl;
  608. struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
  609. unsigned long flags;
  610. if (sc->ps_enabled) {
  611. /*
  612. * mac80211 does not set PM field for normal data frames, so we
  613. * need to update that based on the current PS mode.
  614. */
  615. if (ieee80211_is_data(hdr->frame_control) &&
  616. !ieee80211_is_nullfunc(hdr->frame_control) &&
  617. !ieee80211_has_pm(hdr->frame_control)) {
  618. ath_dbg(common, PS,
  619. "Add PM=1 for a TX frame while in PS mode\n");
  620. hdr->frame_control |= cpu_to_le16(IEEE80211_FCTL_PM);
  621. }
  622. }
  623. if (unlikely(sc->sc_ah->power_mode == ATH9K_PM_NETWORK_SLEEP)) {
  624. /*
  625. * We are using PS-Poll and mac80211 can request TX while in
  626. * power save mode. Need to wake up hardware for the TX to be
  627. * completed and if needed, also for RX of buffered frames.
  628. */
  629. ath9k_ps_wakeup(sc);
  630. spin_lock_irqsave(&sc->sc_pm_lock, flags);
  631. if (!(sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_AUTOSLEEP))
  632. ath9k_hw_setrxabort(sc->sc_ah, 0);
  633. if (ieee80211_is_pspoll(hdr->frame_control)) {
  634. ath_dbg(common, PS,
  635. "Sending PS-Poll to pick a buffered frame\n");
  636. sc->ps_flags |= PS_WAIT_FOR_PSPOLL_DATA;
  637. } else {
  638. ath_dbg(common, PS, "Wake up to complete TX\n");
  639. sc->ps_flags |= PS_WAIT_FOR_TX_ACK;
  640. }
  641. /*
  642. * The actual restore operation will happen only after
  643. * the ps_flags bit is cleared. We are just dropping
  644. * the ps_usecount here.
  645. */
  646. spin_unlock_irqrestore(&sc->sc_pm_lock, flags);
  647. ath9k_ps_restore(sc);
  648. }
  649. /*
  650. * Cannot tx while the hardware is in full sleep, it first needs a full
  651. * chip reset to recover from that
  652. */
  653. if (unlikely(sc->sc_ah->power_mode == ATH9K_PM_FULL_SLEEP)) {
  654. ath_err(common, "TX while HW is in FULL_SLEEP mode\n");
  655. goto exit;
  656. }
  657. memset(&txctl, 0, sizeof(struct ath_tx_control));
  658. txctl.txq = sc->tx.txq_map[skb_get_queue_mapping(skb)];
  659. txctl.sta = control->sta;
  660. ath_dbg(common, XMIT, "transmitting packet, skb: %p\n", skb);
  661. if (ath_tx_start(hw, skb, &txctl) != 0) {
  662. ath_dbg(common, XMIT, "TX failed\n");
  663. TX_STAT_INC(txctl.txq->axq_qnum, txfailed);
  664. goto exit;
  665. }
  666. return;
  667. exit:
  668. ieee80211_free_txskb(hw, skb);
  669. }
  670. static void ath9k_stop(struct ieee80211_hw *hw)
  671. {
  672. struct ath_softc *sc = hw->priv;
  673. struct ath_hw *ah = sc->sc_ah;
  674. struct ath_common *common = ath9k_hw_common(ah);
  675. bool prev_idle;
  676. cancel_work_sync(&sc->chanctx_work);
  677. mutex_lock(&sc->mutex);
  678. ath_cancel_work(sc);
  679. if (test_bit(ATH_OP_INVALID, &common->op_flags)) {
  680. ath_dbg(common, ANY, "Device not present\n");
  681. mutex_unlock(&sc->mutex);
  682. return;
  683. }
  684. /* Ensure HW is awake when we try to shut it down. */
  685. ath9k_ps_wakeup(sc);
  686. spin_lock_bh(&sc->sc_pcu_lock);
  687. /* prevent tasklets to enable interrupts once we disable them */
  688. ah->imask &= ~ATH9K_INT_GLOBAL;
  689. /* make sure h/w will not generate any interrupt
  690. * before setting the invalid flag. */
  691. ath9k_hw_disable_interrupts(ah);
  692. spin_unlock_bh(&sc->sc_pcu_lock);
  693. /* we can now sync irq and kill any running tasklets, since we already
  694. * disabled interrupts and not holding a spin lock */
  695. synchronize_irq(sc->irq);
  696. tasklet_kill(&sc->intr_tq);
  697. tasklet_kill(&sc->bcon_tasklet);
  698. prev_idle = sc->ps_idle;
  699. sc->ps_idle = true;
  700. spin_lock_bh(&sc->sc_pcu_lock);
  701. if (ah->led_pin >= 0) {
  702. ath9k_hw_set_gpio(ah, ah->led_pin, 1);
  703. ath9k_hw_cfg_gpio_input(ah, ah->led_pin);
  704. }
  705. ath_prepare_reset(sc);
  706. if (sc->rx.frag) {
  707. dev_kfree_skb_any(sc->rx.frag);
  708. sc->rx.frag = NULL;
  709. }
  710. if (!ah->curchan)
  711. ah->curchan = ath9k_cmn_get_channel(hw, ah,
  712. &sc->cur_chan->chandef);
  713. ath9k_hw_reset(ah, ah->curchan, ah->caldata, false);
  714. ath9k_hw_phy_disable(ah);
  715. ath9k_hw_configpcipowersave(ah, true);
  716. spin_unlock_bh(&sc->sc_pcu_lock);
  717. ath9k_ps_restore(sc);
  718. set_bit(ATH_OP_INVALID, &common->op_flags);
  719. sc->ps_idle = prev_idle;
  720. mutex_unlock(&sc->mutex);
  721. ath_dbg(common, CONFIG, "Driver halt\n");
  722. }
  723. static bool ath9k_uses_beacons(int type)
  724. {
  725. switch (type) {
  726. case NL80211_IFTYPE_AP:
  727. case NL80211_IFTYPE_ADHOC:
  728. case NL80211_IFTYPE_MESH_POINT:
  729. return true;
  730. default:
  731. return false;
  732. }
  733. }
  734. static void ath9k_vif_iter(void *data, u8 *mac, struct ieee80211_vif *vif)
  735. {
  736. struct ath9k_vif_iter_data *iter_data = data;
  737. int i;
  738. if (iter_data->has_hw_macaddr) {
  739. for (i = 0; i < ETH_ALEN; i++)
  740. iter_data->mask[i] &=
  741. ~(iter_data->hw_macaddr[i] ^ mac[i]);
  742. } else {
  743. memcpy(iter_data->hw_macaddr, mac, ETH_ALEN);
  744. iter_data->has_hw_macaddr = true;
  745. }
  746. if (!vif->bss_conf.use_short_slot)
  747. iter_data->slottime = ATH9K_SLOT_TIME_20;
  748. switch (vif->type) {
  749. case NL80211_IFTYPE_AP:
  750. iter_data->naps++;
  751. if (vif->bss_conf.enable_beacon)
  752. iter_data->beacons = true;
  753. break;
  754. case NL80211_IFTYPE_STATION:
  755. iter_data->nstations++;
  756. if (vif->bss_conf.assoc && !iter_data->primary_sta)
  757. iter_data->primary_sta = vif;
  758. break;
  759. case NL80211_IFTYPE_ADHOC:
  760. iter_data->nadhocs++;
  761. if (vif->bss_conf.enable_beacon)
  762. iter_data->beacons = true;
  763. break;
  764. case NL80211_IFTYPE_MESH_POINT:
  765. iter_data->nmeshes++;
  766. if (vif->bss_conf.enable_beacon)
  767. iter_data->beacons = true;
  768. break;
  769. case NL80211_IFTYPE_WDS:
  770. iter_data->nwds++;
  771. break;
  772. default:
  773. break;
  774. }
  775. }
  776. /* Called with sc->mutex held. */
  777. void ath9k_calculate_iter_data(struct ath_softc *sc,
  778. struct ath_chanctx *ctx,
  779. struct ath9k_vif_iter_data *iter_data)
  780. {
  781. struct ath_vif *avp;
  782. /*
  783. * Pick the MAC address of the first interface as the new hardware
  784. * MAC address. The hardware will use it together with the BSSID mask
  785. * when matching addresses.
  786. */
  787. memset(iter_data, 0, sizeof(*iter_data));
  788. memset(&iter_data->mask, 0xff, ETH_ALEN);
  789. iter_data->slottime = ATH9K_SLOT_TIME_9;
  790. list_for_each_entry(avp, &ctx->vifs, list)
  791. ath9k_vif_iter(iter_data, avp->vif->addr, avp->vif);
  792. if (ctx == &sc->offchannel.chan) {
  793. struct ieee80211_vif *vif;
  794. if (sc->offchannel.state < ATH_OFFCHANNEL_ROC_START)
  795. vif = sc->offchannel.scan_vif;
  796. else
  797. vif = sc->offchannel.roc_vif;
  798. if (vif)
  799. ath9k_vif_iter(iter_data, vif->addr, vif);
  800. iter_data->beacons = false;
  801. }
  802. }
  803. static void ath9k_set_assoc_state(struct ath_softc *sc,
  804. struct ieee80211_vif *vif, bool changed)
  805. {
  806. struct ath_common *common = ath9k_hw_common(sc->sc_ah);
  807. struct ieee80211_bss_conf *bss_conf = &vif->bss_conf;
  808. unsigned long flags;
  809. set_bit(ATH_OP_PRIM_STA_VIF, &common->op_flags);
  810. /* Set the AID, BSSID and do beacon-sync only when
  811. * the HW opmode is STATION.
  812. *
  813. * But the primary bit is set above in any case.
  814. */
  815. if (sc->sc_ah->opmode != NL80211_IFTYPE_STATION)
  816. return;
  817. ether_addr_copy(common->curbssid, bss_conf->bssid);
  818. common->curaid = bss_conf->aid;
  819. ath9k_hw_write_associd(sc->sc_ah);
  820. if (changed) {
  821. common->last_rssi = ATH_RSSI_DUMMY_MARKER;
  822. sc->sc_ah->stats.avgbrssi = ATH_RSSI_DUMMY_MARKER;
  823. spin_lock_irqsave(&sc->sc_pm_lock, flags);
  824. sc->ps_flags |= PS_BEACON_SYNC | PS_WAIT_FOR_BEACON;
  825. spin_unlock_irqrestore(&sc->sc_pm_lock, flags);
  826. }
  827. if (ath9k_hw_mci_is_enabled(sc->sc_ah))
  828. ath9k_mci_update_wlan_channels(sc, false);
  829. ath_dbg(common, CONFIG,
  830. "Primary Station interface: %pM, BSSID: %pM\n",
  831. vif->addr, common->curbssid);
  832. }
  833. /* Called with sc->mutex held. */
  834. void ath9k_calculate_summary_state(struct ath_softc *sc,
  835. struct ath_chanctx *ctx)
  836. {
  837. struct ath_hw *ah = sc->sc_ah;
  838. struct ath_common *common = ath9k_hw_common(ah);
  839. struct ath9k_vif_iter_data iter_data;
  840. ath_chanctx_check_active(sc, ctx);
  841. if (ctx != sc->cur_chan)
  842. return;
  843. ath9k_ps_wakeup(sc);
  844. ath9k_calculate_iter_data(sc, ctx, &iter_data);
  845. if (iter_data.has_hw_macaddr)
  846. ether_addr_copy(common->macaddr, iter_data.hw_macaddr);
  847. memcpy(common->bssidmask, iter_data.mask, ETH_ALEN);
  848. ath_hw_setbssidmask(common);
  849. if (iter_data.naps > 0) {
  850. ath9k_hw_set_tsfadjust(ah, true);
  851. ah->opmode = NL80211_IFTYPE_AP;
  852. } else {
  853. ath9k_hw_set_tsfadjust(ah, false);
  854. if (iter_data.nmeshes)
  855. ah->opmode = NL80211_IFTYPE_MESH_POINT;
  856. else if (iter_data.nwds)
  857. ah->opmode = NL80211_IFTYPE_AP;
  858. else if (iter_data.nadhocs)
  859. ah->opmode = NL80211_IFTYPE_ADHOC;
  860. else
  861. ah->opmode = NL80211_IFTYPE_STATION;
  862. }
  863. ath9k_hw_setopmode(ah);
  864. ctx->switch_after_beacon = false;
  865. if ((iter_data.nstations + iter_data.nadhocs + iter_data.nmeshes) > 0)
  866. ah->imask |= ATH9K_INT_TSFOOR;
  867. else {
  868. ah->imask &= ~ATH9K_INT_TSFOOR;
  869. if (iter_data.naps == 1 && iter_data.beacons)
  870. ctx->switch_after_beacon = true;
  871. }
  872. ah->imask &= ~ATH9K_INT_SWBA;
  873. if (ah->opmode == NL80211_IFTYPE_STATION) {
  874. bool changed = (iter_data.primary_sta != ctx->primary_sta);
  875. iter_data.beacons = true;
  876. if (iter_data.primary_sta) {
  877. ath9k_set_assoc_state(sc, iter_data.primary_sta,
  878. changed);
  879. if (!ctx->primary_sta ||
  880. !ctx->primary_sta->bss_conf.assoc)
  881. ctx->primary_sta = iter_data.primary_sta;
  882. } else {
  883. ctx->primary_sta = NULL;
  884. memset(common->curbssid, 0, ETH_ALEN);
  885. common->curaid = 0;
  886. ath9k_hw_write_associd(sc->sc_ah);
  887. if (ath9k_hw_mci_is_enabled(sc->sc_ah))
  888. ath9k_mci_update_wlan_channels(sc, true);
  889. }
  890. } else if (iter_data.beacons) {
  891. ah->imask |= ATH9K_INT_SWBA;
  892. }
  893. ath9k_hw_set_interrupts(ah);
  894. if (iter_data.beacons)
  895. set_bit(ATH_OP_BEACONS, &common->op_flags);
  896. else
  897. clear_bit(ATH_OP_BEACONS, &common->op_flags);
  898. if (ah->slottime != iter_data.slottime) {
  899. ah->slottime = iter_data.slottime;
  900. ath9k_hw_init_global_settings(ah);
  901. }
  902. if (iter_data.primary_sta)
  903. set_bit(ATH_OP_PRIM_STA_VIF, &common->op_flags);
  904. else
  905. clear_bit(ATH_OP_PRIM_STA_VIF, &common->op_flags);
  906. ctx->primary_sta = iter_data.primary_sta;
  907. ath9k_ps_restore(sc);
  908. }
  909. static int ath9k_add_interface(struct ieee80211_hw *hw,
  910. struct ieee80211_vif *vif)
  911. {
  912. struct ath_softc *sc = hw->priv;
  913. struct ath_hw *ah = sc->sc_ah;
  914. struct ath_common *common = ath9k_hw_common(ah);
  915. struct ath_vif *avp = (void *)vif->drv_priv;
  916. struct ath_node *an = &avp->mcast_node;
  917. int i;
  918. mutex_lock(&sc->mutex);
  919. if (config_enabled(CONFIG_ATH9K_TX99)) {
  920. if (sc->nvifs >= 1) {
  921. mutex_unlock(&sc->mutex);
  922. return -EOPNOTSUPP;
  923. }
  924. sc->tx99_vif = vif;
  925. }
  926. ath_dbg(common, CONFIG, "Attach a VIF of type: %d\n", vif->type);
  927. sc->nvifs++;
  928. if (ath9k_uses_beacons(vif->type))
  929. ath9k_beacon_assign_slot(sc, vif);
  930. avp->vif = vif;
  931. if (!ath9k_use_chanctx) {
  932. avp->chanctx = sc->cur_chan;
  933. list_add_tail(&avp->list, &avp->chanctx->vifs);
  934. }
  935. for (i = 0; i < IEEE80211_NUM_ACS; i++)
  936. vif->hw_queue[i] = i;
  937. if (vif->type == NL80211_IFTYPE_AP)
  938. vif->cab_queue = hw->queues - 2;
  939. else
  940. vif->cab_queue = IEEE80211_INVAL_HW_QUEUE;
  941. an->sc = sc;
  942. an->sta = NULL;
  943. an->vif = vif;
  944. an->no_ps_filter = true;
  945. ath_tx_node_init(sc, an);
  946. mutex_unlock(&sc->mutex);
  947. return 0;
  948. }
  949. static int ath9k_change_interface(struct ieee80211_hw *hw,
  950. struct ieee80211_vif *vif,
  951. enum nl80211_iftype new_type,
  952. bool p2p)
  953. {
  954. struct ath_softc *sc = hw->priv;
  955. struct ath_common *common = ath9k_hw_common(sc->sc_ah);
  956. struct ath_vif *avp = (void *)vif->drv_priv;
  957. int i;
  958. mutex_lock(&sc->mutex);
  959. if (config_enabled(CONFIG_ATH9K_TX99)) {
  960. mutex_unlock(&sc->mutex);
  961. return -EOPNOTSUPP;
  962. }
  963. ath_dbg(common, CONFIG, "Change Interface\n");
  964. if (ath9k_uses_beacons(vif->type))
  965. ath9k_beacon_remove_slot(sc, vif);
  966. vif->type = new_type;
  967. vif->p2p = p2p;
  968. if (ath9k_uses_beacons(vif->type))
  969. ath9k_beacon_assign_slot(sc, vif);
  970. for (i = 0; i < IEEE80211_NUM_ACS; i++)
  971. vif->hw_queue[i] = i;
  972. if (vif->type == NL80211_IFTYPE_AP)
  973. vif->cab_queue = hw->queues - 2;
  974. else
  975. vif->cab_queue = IEEE80211_INVAL_HW_QUEUE;
  976. ath9k_calculate_summary_state(sc, avp->chanctx);
  977. mutex_unlock(&sc->mutex);
  978. return 0;
  979. }
  980. static void
  981. ath9k_update_p2p_ps_timer(struct ath_softc *sc, struct ath_vif *avp)
  982. {
  983. struct ath_hw *ah = sc->sc_ah;
  984. s32 tsf, target_tsf;
  985. if (!avp || !avp->noa.has_next_tsf)
  986. return;
  987. ath9k_hw_gen_timer_stop(ah, sc->p2p_ps_timer);
  988. tsf = ath9k_hw_gettsf32(sc->sc_ah);
  989. target_tsf = avp->noa.next_tsf;
  990. if (!avp->noa.absent)
  991. target_tsf -= ATH_P2P_PS_STOP_TIME;
  992. if (target_tsf - tsf < ATH_P2P_PS_STOP_TIME)
  993. target_tsf = tsf + ATH_P2P_PS_STOP_TIME;
  994. ath9k_hw_gen_timer_start(ah, sc->p2p_ps_timer, (u32) target_tsf, 1000000);
  995. }
  996. static void ath9k_remove_interface(struct ieee80211_hw *hw,
  997. struct ieee80211_vif *vif)
  998. {
  999. struct ath_softc *sc = hw->priv;
  1000. struct ath_common *common = ath9k_hw_common(sc->sc_ah);
  1001. struct ath_vif *avp = (void *)vif->drv_priv;
  1002. ath_dbg(common, CONFIG, "Detach Interface\n");
  1003. mutex_lock(&sc->mutex);
  1004. spin_lock_bh(&sc->sc_pcu_lock);
  1005. if (avp == sc->p2p_ps_vif) {
  1006. sc->p2p_ps_vif = NULL;
  1007. ath9k_update_p2p_ps_timer(sc, NULL);
  1008. }
  1009. spin_unlock_bh(&sc->sc_pcu_lock);
  1010. sc->nvifs--;
  1011. sc->tx99_vif = NULL;
  1012. if (!ath9k_use_chanctx)
  1013. list_del(&avp->list);
  1014. if (ath9k_uses_beacons(vif->type))
  1015. ath9k_beacon_remove_slot(sc, vif);
  1016. ath_tx_node_cleanup(sc, &avp->mcast_node);
  1017. mutex_unlock(&sc->mutex);
  1018. }
  1019. static void ath9k_enable_ps(struct ath_softc *sc)
  1020. {
  1021. struct ath_hw *ah = sc->sc_ah;
  1022. struct ath_common *common = ath9k_hw_common(ah);
  1023. if (config_enabled(CONFIG_ATH9K_TX99))
  1024. return;
  1025. sc->ps_enabled = true;
  1026. if (!(ah->caps.hw_caps & ATH9K_HW_CAP_AUTOSLEEP)) {
  1027. if ((ah->imask & ATH9K_INT_TIM_TIMER) == 0) {
  1028. ah->imask |= ATH9K_INT_TIM_TIMER;
  1029. ath9k_hw_set_interrupts(ah);
  1030. }
  1031. ath9k_hw_setrxabort(ah, 1);
  1032. }
  1033. ath_dbg(common, PS, "PowerSave enabled\n");
  1034. }
  1035. static void ath9k_disable_ps(struct ath_softc *sc)
  1036. {
  1037. struct ath_hw *ah = sc->sc_ah;
  1038. struct ath_common *common = ath9k_hw_common(ah);
  1039. if (config_enabled(CONFIG_ATH9K_TX99))
  1040. return;
  1041. sc->ps_enabled = false;
  1042. ath9k_hw_setpower(ah, ATH9K_PM_AWAKE);
  1043. if (!(ah->caps.hw_caps & ATH9K_HW_CAP_AUTOSLEEP)) {
  1044. ath9k_hw_setrxabort(ah, 0);
  1045. sc->ps_flags &= ~(PS_WAIT_FOR_BEACON |
  1046. PS_WAIT_FOR_CAB |
  1047. PS_WAIT_FOR_PSPOLL_DATA |
  1048. PS_WAIT_FOR_TX_ACK);
  1049. if (ah->imask & ATH9K_INT_TIM_TIMER) {
  1050. ah->imask &= ~ATH9K_INT_TIM_TIMER;
  1051. ath9k_hw_set_interrupts(ah);
  1052. }
  1053. }
  1054. ath_dbg(common, PS, "PowerSave disabled\n");
  1055. }
  1056. void ath9k_spectral_scan_trigger(struct ieee80211_hw *hw)
  1057. {
  1058. struct ath_softc *sc = hw->priv;
  1059. struct ath_hw *ah = sc->sc_ah;
  1060. struct ath_common *common = ath9k_hw_common(ah);
  1061. u32 rxfilter;
  1062. if (config_enabled(CONFIG_ATH9K_TX99))
  1063. return;
  1064. if (!ath9k_hw_ops(ah)->spectral_scan_trigger) {
  1065. ath_err(common, "spectrum analyzer not implemented on this hardware\n");
  1066. return;
  1067. }
  1068. ath9k_ps_wakeup(sc);
  1069. rxfilter = ath9k_hw_getrxfilter(ah);
  1070. ath9k_hw_setrxfilter(ah, rxfilter |
  1071. ATH9K_RX_FILTER_PHYRADAR |
  1072. ATH9K_RX_FILTER_PHYERR);
  1073. /* TODO: usually this should not be neccesary, but for some reason
  1074. * (or in some mode?) the trigger must be called after the
  1075. * configuration, otherwise the register will have its values reset
  1076. * (on my ar9220 to value 0x01002310)
  1077. */
  1078. ath9k_spectral_scan_config(hw, sc->spectral_mode);
  1079. ath9k_hw_ops(ah)->spectral_scan_trigger(ah);
  1080. ath9k_ps_restore(sc);
  1081. }
  1082. int ath9k_spectral_scan_config(struct ieee80211_hw *hw,
  1083. enum spectral_mode spectral_mode)
  1084. {
  1085. struct ath_softc *sc = hw->priv;
  1086. struct ath_hw *ah = sc->sc_ah;
  1087. struct ath_common *common = ath9k_hw_common(ah);
  1088. if (!ath9k_hw_ops(ah)->spectral_scan_trigger) {
  1089. ath_err(common, "spectrum analyzer not implemented on this hardware\n");
  1090. return -1;
  1091. }
  1092. switch (spectral_mode) {
  1093. case SPECTRAL_DISABLED:
  1094. sc->spec_config.enabled = 0;
  1095. break;
  1096. case SPECTRAL_BACKGROUND:
  1097. /* send endless samples.
  1098. * TODO: is this really useful for "background"?
  1099. */
  1100. sc->spec_config.endless = 1;
  1101. sc->spec_config.enabled = 1;
  1102. break;
  1103. case SPECTRAL_CHANSCAN:
  1104. case SPECTRAL_MANUAL:
  1105. sc->spec_config.endless = 0;
  1106. sc->spec_config.enabled = 1;
  1107. break;
  1108. default:
  1109. return -1;
  1110. }
  1111. ath9k_ps_wakeup(sc);
  1112. ath9k_hw_ops(ah)->spectral_scan_config(ah, &sc->spec_config);
  1113. ath9k_ps_restore(sc);
  1114. sc->spectral_mode = spectral_mode;
  1115. return 0;
  1116. }
  1117. static int ath9k_config(struct ieee80211_hw *hw, u32 changed)
  1118. {
  1119. struct ath_softc *sc = hw->priv;
  1120. struct ath_hw *ah = sc->sc_ah;
  1121. struct ath_common *common = ath9k_hw_common(ah);
  1122. struct ieee80211_conf *conf = &hw->conf;
  1123. struct ath_chanctx *ctx = sc->cur_chan;
  1124. ath9k_ps_wakeup(sc);
  1125. mutex_lock(&sc->mutex);
  1126. if (changed & IEEE80211_CONF_CHANGE_IDLE) {
  1127. sc->ps_idle = !!(conf->flags & IEEE80211_CONF_IDLE);
  1128. if (sc->ps_idle) {
  1129. ath_cancel_work(sc);
  1130. ath9k_stop_btcoex(sc);
  1131. } else {
  1132. ath9k_start_btcoex(sc);
  1133. /*
  1134. * The chip needs a reset to properly wake up from
  1135. * full sleep
  1136. */
  1137. ath_chanctx_set_channel(sc, ctx, &ctx->chandef);
  1138. }
  1139. }
  1140. /*
  1141. * We just prepare to enable PS. We have to wait until our AP has
  1142. * ACK'd our null data frame to disable RX otherwise we'll ignore
  1143. * those ACKs and end up retransmitting the same null data frames.
  1144. * IEEE80211_CONF_CHANGE_PS is only passed by mac80211 for STA mode.
  1145. */
  1146. if (changed & IEEE80211_CONF_CHANGE_PS) {
  1147. unsigned long flags;
  1148. spin_lock_irqsave(&sc->sc_pm_lock, flags);
  1149. if (conf->flags & IEEE80211_CONF_PS)
  1150. ath9k_enable_ps(sc);
  1151. else
  1152. ath9k_disable_ps(sc);
  1153. spin_unlock_irqrestore(&sc->sc_pm_lock, flags);
  1154. }
  1155. if (changed & IEEE80211_CONF_CHANGE_MONITOR) {
  1156. if (conf->flags & IEEE80211_CONF_MONITOR) {
  1157. ath_dbg(common, CONFIG, "Monitor mode is enabled\n");
  1158. sc->sc_ah->is_monitoring = true;
  1159. } else {
  1160. ath_dbg(common, CONFIG, "Monitor mode is disabled\n");
  1161. sc->sc_ah->is_monitoring = false;
  1162. }
  1163. }
  1164. if (!ath9k_use_chanctx && (changed & IEEE80211_CONF_CHANGE_CHANNEL)) {
  1165. ctx->offchannel = !!(conf->flags & IEEE80211_CONF_OFFCHANNEL);
  1166. ath_chanctx_set_channel(sc, ctx, &hw->conf.chandef);
  1167. }
  1168. if (changed & IEEE80211_CONF_CHANGE_POWER) {
  1169. ath_dbg(common, CONFIG, "Set power: %d\n", conf->power_level);
  1170. sc->cur_chan->txpower = 2 * conf->power_level;
  1171. ath9k_cmn_update_txpow(ah, sc->curtxpow,
  1172. sc->cur_chan->txpower, &sc->curtxpow);
  1173. }
  1174. mutex_unlock(&sc->mutex);
  1175. ath9k_ps_restore(sc);
  1176. return 0;
  1177. }
  1178. #define SUPPORTED_FILTERS \
  1179. (FIF_PROMISC_IN_BSS | \
  1180. FIF_ALLMULTI | \
  1181. FIF_CONTROL | \
  1182. FIF_PSPOLL | \
  1183. FIF_OTHER_BSS | \
  1184. FIF_BCN_PRBRESP_PROMISC | \
  1185. FIF_PROBE_REQ | \
  1186. FIF_FCSFAIL)
  1187. /* FIXME: sc->sc_full_reset ? */
  1188. static void ath9k_configure_filter(struct ieee80211_hw *hw,
  1189. unsigned int changed_flags,
  1190. unsigned int *total_flags,
  1191. u64 multicast)
  1192. {
  1193. struct ath_softc *sc = hw->priv;
  1194. u32 rfilt;
  1195. changed_flags &= SUPPORTED_FILTERS;
  1196. *total_flags &= SUPPORTED_FILTERS;
  1197. sc->rx.rxfilter = *total_flags;
  1198. ath9k_ps_wakeup(sc);
  1199. rfilt = ath_calcrxfilter(sc);
  1200. ath9k_hw_setrxfilter(sc->sc_ah, rfilt);
  1201. ath9k_ps_restore(sc);
  1202. ath_dbg(ath9k_hw_common(sc->sc_ah), CONFIG, "Set HW RX filter: 0x%x\n",
  1203. rfilt);
  1204. }
  1205. static int ath9k_sta_add(struct ieee80211_hw *hw,
  1206. struct ieee80211_vif *vif,
  1207. struct ieee80211_sta *sta)
  1208. {
  1209. struct ath_softc *sc = hw->priv;
  1210. struct ath_common *common = ath9k_hw_common(sc->sc_ah);
  1211. struct ath_node *an = (struct ath_node *) sta->drv_priv;
  1212. struct ieee80211_key_conf ps_key = { };
  1213. int key;
  1214. ath_node_attach(sc, sta, vif);
  1215. if (vif->type != NL80211_IFTYPE_AP &&
  1216. vif->type != NL80211_IFTYPE_AP_VLAN)
  1217. return 0;
  1218. key = ath_key_config(common, vif, sta, &ps_key);
  1219. if (key > 0) {
  1220. an->ps_key = key;
  1221. an->key_idx[0] = key;
  1222. }
  1223. return 0;
  1224. }
  1225. static void ath9k_del_ps_key(struct ath_softc *sc,
  1226. struct ieee80211_vif *vif,
  1227. struct ieee80211_sta *sta)
  1228. {
  1229. struct ath_common *common = ath9k_hw_common(sc->sc_ah);
  1230. struct ath_node *an = (struct ath_node *) sta->drv_priv;
  1231. struct ieee80211_key_conf ps_key = { .hw_key_idx = an->ps_key };
  1232. if (!an->ps_key)
  1233. return;
  1234. ath_key_delete(common, &ps_key);
  1235. an->ps_key = 0;
  1236. an->key_idx[0] = 0;
  1237. }
  1238. static int ath9k_sta_remove(struct ieee80211_hw *hw,
  1239. struct ieee80211_vif *vif,
  1240. struct ieee80211_sta *sta)
  1241. {
  1242. struct ath_softc *sc = hw->priv;
  1243. ath9k_del_ps_key(sc, vif, sta);
  1244. ath_node_detach(sc, sta);
  1245. return 0;
  1246. }
  1247. static void ath9k_sta_set_tx_filter(struct ath_hw *ah,
  1248. struct ath_node *an,
  1249. bool set)
  1250. {
  1251. int i;
  1252. for (i = 0; i < ARRAY_SIZE(an->key_idx); i++) {
  1253. if (!an->key_idx[i])
  1254. continue;
  1255. ath9k_hw_set_tx_filter(ah, an->key_idx[i], set);
  1256. }
  1257. }
  1258. static void ath9k_sta_notify(struct ieee80211_hw *hw,
  1259. struct ieee80211_vif *vif,
  1260. enum sta_notify_cmd cmd,
  1261. struct ieee80211_sta *sta)
  1262. {
  1263. struct ath_softc *sc = hw->priv;
  1264. struct ath_node *an = (struct ath_node *) sta->drv_priv;
  1265. switch (cmd) {
  1266. case STA_NOTIFY_SLEEP:
  1267. an->sleeping = true;
  1268. ath_tx_aggr_sleep(sta, sc, an);
  1269. ath9k_sta_set_tx_filter(sc->sc_ah, an, true);
  1270. break;
  1271. case STA_NOTIFY_AWAKE:
  1272. ath9k_sta_set_tx_filter(sc->sc_ah, an, false);
  1273. an->sleeping = false;
  1274. ath_tx_aggr_wakeup(sc, an);
  1275. break;
  1276. }
  1277. }
  1278. static int ath9k_conf_tx(struct ieee80211_hw *hw,
  1279. struct ieee80211_vif *vif, u16 queue,
  1280. const struct ieee80211_tx_queue_params *params)
  1281. {
  1282. struct ath_softc *sc = hw->priv;
  1283. struct ath_common *common = ath9k_hw_common(sc->sc_ah);
  1284. struct ath_txq *txq;
  1285. struct ath9k_tx_queue_info qi;
  1286. int ret = 0;
  1287. if (queue >= IEEE80211_NUM_ACS)
  1288. return 0;
  1289. txq = sc->tx.txq_map[queue];
  1290. ath9k_ps_wakeup(sc);
  1291. mutex_lock(&sc->mutex);
  1292. memset(&qi, 0, sizeof(struct ath9k_tx_queue_info));
  1293. qi.tqi_aifs = params->aifs;
  1294. qi.tqi_cwmin = params->cw_min;
  1295. qi.tqi_cwmax = params->cw_max;
  1296. qi.tqi_burstTime = params->txop * 32;
  1297. ath_dbg(common, CONFIG,
  1298. "Configure tx [queue/halq] [%d/%d], aifs: %d, cw_min: %d, cw_max: %d, txop: %d\n",
  1299. queue, txq->axq_qnum, params->aifs, params->cw_min,
  1300. params->cw_max, params->txop);
  1301. ath_update_max_aggr_framelen(sc, queue, qi.tqi_burstTime);
  1302. ret = ath_txq_update(sc, txq->axq_qnum, &qi);
  1303. if (ret)
  1304. ath_err(common, "TXQ Update failed\n");
  1305. mutex_unlock(&sc->mutex);
  1306. ath9k_ps_restore(sc);
  1307. return ret;
  1308. }
  1309. static int ath9k_set_key(struct ieee80211_hw *hw,
  1310. enum set_key_cmd cmd,
  1311. struct ieee80211_vif *vif,
  1312. struct ieee80211_sta *sta,
  1313. struct ieee80211_key_conf *key)
  1314. {
  1315. struct ath_softc *sc = hw->priv;
  1316. struct ath_common *common = ath9k_hw_common(sc->sc_ah);
  1317. struct ath_node *an = NULL;
  1318. int ret = 0, i;
  1319. if (ath9k_modparam_nohwcrypt)
  1320. return -ENOSPC;
  1321. if ((vif->type == NL80211_IFTYPE_ADHOC ||
  1322. vif->type == NL80211_IFTYPE_MESH_POINT) &&
  1323. (key->cipher == WLAN_CIPHER_SUITE_TKIP ||
  1324. key->cipher == WLAN_CIPHER_SUITE_CCMP) &&
  1325. !(key->flags & IEEE80211_KEY_FLAG_PAIRWISE)) {
  1326. /*
  1327. * For now, disable hw crypto for the RSN IBSS group keys. This
  1328. * could be optimized in the future to use a modified key cache
  1329. * design to support per-STA RX GTK, but until that gets
  1330. * implemented, use of software crypto for group addressed
  1331. * frames is a acceptable to allow RSN IBSS to be used.
  1332. */
  1333. return -EOPNOTSUPP;
  1334. }
  1335. mutex_lock(&sc->mutex);
  1336. ath9k_ps_wakeup(sc);
  1337. ath_dbg(common, CONFIG, "Set HW Key %d\n", cmd);
  1338. if (sta)
  1339. an = (struct ath_node *)sta->drv_priv;
  1340. switch (cmd) {
  1341. case SET_KEY:
  1342. if (sta)
  1343. ath9k_del_ps_key(sc, vif, sta);
  1344. key->hw_key_idx = 0;
  1345. ret = ath_key_config(common, vif, sta, key);
  1346. if (ret >= 0) {
  1347. key->hw_key_idx = ret;
  1348. /* push IV and Michael MIC generation to stack */
  1349. key->flags |= IEEE80211_KEY_FLAG_GENERATE_IV;
  1350. if (key->cipher == WLAN_CIPHER_SUITE_TKIP)
  1351. key->flags |= IEEE80211_KEY_FLAG_GENERATE_MMIC;
  1352. if (sc->sc_ah->sw_mgmt_crypto &&
  1353. key->cipher == WLAN_CIPHER_SUITE_CCMP)
  1354. key->flags |= IEEE80211_KEY_FLAG_SW_MGMT_TX;
  1355. ret = 0;
  1356. }
  1357. if (an && key->hw_key_idx) {
  1358. for (i = 0; i < ARRAY_SIZE(an->key_idx); i++) {
  1359. if (an->key_idx[i])
  1360. continue;
  1361. an->key_idx[i] = key->hw_key_idx;
  1362. break;
  1363. }
  1364. WARN_ON(i == ARRAY_SIZE(an->key_idx));
  1365. }
  1366. break;
  1367. case DISABLE_KEY:
  1368. ath_key_delete(common, key);
  1369. if (an) {
  1370. for (i = 0; i < ARRAY_SIZE(an->key_idx); i++) {
  1371. if (an->key_idx[i] != key->hw_key_idx)
  1372. continue;
  1373. an->key_idx[i] = 0;
  1374. break;
  1375. }
  1376. }
  1377. key->hw_key_idx = 0;
  1378. break;
  1379. default:
  1380. ret = -EINVAL;
  1381. }
  1382. ath9k_ps_restore(sc);
  1383. mutex_unlock(&sc->mutex);
  1384. return ret;
  1385. }
  1386. void ath9k_p2p_ps_timer(void *priv)
  1387. {
  1388. struct ath_softc *sc = priv;
  1389. struct ath_vif *avp = sc->p2p_ps_vif;
  1390. struct ieee80211_vif *vif;
  1391. struct ieee80211_sta *sta;
  1392. struct ath_node *an;
  1393. u32 tsf;
  1394. del_timer_sync(&sc->sched.timer);
  1395. ath9k_hw_gen_timer_stop(sc->sc_ah, sc->p2p_ps_timer);
  1396. ath_chanctx_event(sc, NULL, ATH_CHANCTX_EVENT_TSF_TIMER);
  1397. if (!avp || avp->chanctx != sc->cur_chan)
  1398. return;
  1399. tsf = ath9k_hw_gettsf32(sc->sc_ah);
  1400. if (!avp->noa.absent)
  1401. tsf += ATH_P2P_PS_STOP_TIME;
  1402. if (!avp->noa.has_next_tsf ||
  1403. avp->noa.next_tsf - tsf > BIT(31))
  1404. ieee80211_update_p2p_noa(&avp->noa, tsf);
  1405. ath9k_update_p2p_ps_timer(sc, avp);
  1406. rcu_read_lock();
  1407. vif = avp->vif;
  1408. sta = ieee80211_find_sta(vif, vif->bss_conf.bssid);
  1409. if (!sta)
  1410. goto out;
  1411. an = (void *) sta->drv_priv;
  1412. if (an->sleeping == !!avp->noa.absent)
  1413. goto out;
  1414. an->sleeping = avp->noa.absent;
  1415. if (an->sleeping)
  1416. ath_tx_aggr_sleep(sta, sc, an);
  1417. else
  1418. ath_tx_aggr_wakeup(sc, an);
  1419. out:
  1420. rcu_read_unlock();
  1421. }
  1422. void ath9k_update_p2p_ps(struct ath_softc *sc, struct ieee80211_vif *vif)
  1423. {
  1424. struct ath_vif *avp = (void *)vif->drv_priv;
  1425. u32 tsf;
  1426. if (!sc->p2p_ps_timer)
  1427. return;
  1428. if (vif->type != NL80211_IFTYPE_STATION || !vif->p2p)
  1429. return;
  1430. sc->p2p_ps_vif = avp;
  1431. tsf = ath9k_hw_gettsf32(sc->sc_ah);
  1432. ieee80211_parse_p2p_noa(&vif->bss_conf.p2p_noa_attr, &avp->noa, tsf);
  1433. ath9k_update_p2p_ps_timer(sc, avp);
  1434. }
  1435. static void ath9k_bss_info_changed(struct ieee80211_hw *hw,
  1436. struct ieee80211_vif *vif,
  1437. struct ieee80211_bss_conf *bss_conf,
  1438. u32 changed)
  1439. {
  1440. #define CHECK_ANI \
  1441. (BSS_CHANGED_ASSOC | \
  1442. BSS_CHANGED_IBSS | \
  1443. BSS_CHANGED_BEACON_ENABLED)
  1444. struct ath_softc *sc = hw->priv;
  1445. struct ath_hw *ah = sc->sc_ah;
  1446. struct ath_common *common = ath9k_hw_common(ah);
  1447. struct ath_vif *avp = (void *)vif->drv_priv;
  1448. unsigned long flags;
  1449. int slottime;
  1450. ath9k_ps_wakeup(sc);
  1451. mutex_lock(&sc->mutex);
  1452. if (changed & BSS_CHANGED_ASSOC) {
  1453. ath_dbg(common, CONFIG, "BSSID %pM Changed ASSOC %d\n",
  1454. bss_conf->bssid, bss_conf->assoc);
  1455. ath9k_calculate_summary_state(sc, avp->chanctx);
  1456. if (bss_conf->assoc)
  1457. ath_chanctx_event(sc, vif, ATH_CHANCTX_EVENT_ASSOC);
  1458. }
  1459. if (changed & BSS_CHANGED_IBSS) {
  1460. memcpy(common->curbssid, bss_conf->bssid, ETH_ALEN);
  1461. common->curaid = bss_conf->aid;
  1462. ath9k_hw_write_associd(sc->sc_ah);
  1463. }
  1464. if ((changed & BSS_CHANGED_BEACON_ENABLED) ||
  1465. (changed & BSS_CHANGED_BEACON_INT)) {
  1466. if (changed & BSS_CHANGED_BEACON_ENABLED)
  1467. ath9k_calculate_summary_state(sc, avp->chanctx);
  1468. ath9k_beacon_config(sc, vif, changed);
  1469. }
  1470. if ((avp->chanctx == sc->cur_chan) &&
  1471. (changed & BSS_CHANGED_ERP_SLOT)) {
  1472. if (bss_conf->use_short_slot)
  1473. slottime = 9;
  1474. else
  1475. slottime = 20;
  1476. if (vif->type == NL80211_IFTYPE_AP) {
  1477. /*
  1478. * Defer update, so that connected stations can adjust
  1479. * their settings at the same time.
  1480. * See beacon.c for more details
  1481. */
  1482. sc->beacon.slottime = slottime;
  1483. sc->beacon.updateslot = UPDATE;
  1484. } else {
  1485. ah->slottime = slottime;
  1486. ath9k_hw_init_global_settings(ah);
  1487. }
  1488. }
  1489. if (changed & BSS_CHANGED_P2P_PS) {
  1490. spin_lock_bh(&sc->sc_pcu_lock);
  1491. spin_lock_irqsave(&sc->sc_pm_lock, flags);
  1492. if (!(sc->ps_flags & PS_BEACON_SYNC))
  1493. ath9k_update_p2p_ps(sc, vif);
  1494. spin_unlock_irqrestore(&sc->sc_pm_lock, flags);
  1495. spin_unlock_bh(&sc->sc_pcu_lock);
  1496. }
  1497. if (changed & CHECK_ANI)
  1498. ath_check_ani(sc);
  1499. mutex_unlock(&sc->mutex);
  1500. ath9k_ps_restore(sc);
  1501. #undef CHECK_ANI
  1502. }
  1503. static u64 ath9k_get_tsf(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
  1504. {
  1505. struct ath_softc *sc = hw->priv;
  1506. u64 tsf;
  1507. mutex_lock(&sc->mutex);
  1508. ath9k_ps_wakeup(sc);
  1509. tsf = ath9k_hw_gettsf64(sc->sc_ah);
  1510. ath9k_ps_restore(sc);
  1511. mutex_unlock(&sc->mutex);
  1512. return tsf;
  1513. }
  1514. static void ath9k_set_tsf(struct ieee80211_hw *hw,
  1515. struct ieee80211_vif *vif,
  1516. u64 tsf)
  1517. {
  1518. struct ath_softc *sc = hw->priv;
  1519. mutex_lock(&sc->mutex);
  1520. ath9k_ps_wakeup(sc);
  1521. ath9k_hw_settsf64(sc->sc_ah, tsf);
  1522. ath9k_ps_restore(sc);
  1523. mutex_unlock(&sc->mutex);
  1524. }
  1525. static void ath9k_reset_tsf(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
  1526. {
  1527. struct ath_softc *sc = hw->priv;
  1528. mutex_lock(&sc->mutex);
  1529. ath9k_ps_wakeup(sc);
  1530. ath9k_hw_reset_tsf(sc->sc_ah);
  1531. ath9k_ps_restore(sc);
  1532. mutex_unlock(&sc->mutex);
  1533. }
  1534. static int ath9k_ampdu_action(struct ieee80211_hw *hw,
  1535. struct ieee80211_vif *vif,
  1536. enum ieee80211_ampdu_mlme_action action,
  1537. struct ieee80211_sta *sta,
  1538. u16 tid, u16 *ssn, u8 buf_size)
  1539. {
  1540. struct ath_softc *sc = hw->priv;
  1541. bool flush = false;
  1542. int ret = 0;
  1543. mutex_lock(&sc->mutex);
  1544. switch (action) {
  1545. case IEEE80211_AMPDU_RX_START:
  1546. break;
  1547. case IEEE80211_AMPDU_RX_STOP:
  1548. break;
  1549. case IEEE80211_AMPDU_TX_START:
  1550. ath9k_ps_wakeup(sc);
  1551. ret = ath_tx_aggr_start(sc, sta, tid, ssn);
  1552. if (!ret)
  1553. ieee80211_start_tx_ba_cb_irqsafe(vif, sta->addr, tid);
  1554. ath9k_ps_restore(sc);
  1555. break;
  1556. case IEEE80211_AMPDU_TX_STOP_FLUSH:
  1557. case IEEE80211_AMPDU_TX_STOP_FLUSH_CONT:
  1558. flush = true;
  1559. case IEEE80211_AMPDU_TX_STOP_CONT:
  1560. ath9k_ps_wakeup(sc);
  1561. ath_tx_aggr_stop(sc, sta, tid);
  1562. if (!flush)
  1563. ieee80211_stop_tx_ba_cb_irqsafe(vif, sta->addr, tid);
  1564. ath9k_ps_restore(sc);
  1565. break;
  1566. case IEEE80211_AMPDU_TX_OPERATIONAL:
  1567. ath9k_ps_wakeup(sc);
  1568. ath_tx_aggr_resume(sc, sta, tid);
  1569. ath9k_ps_restore(sc);
  1570. break;
  1571. default:
  1572. ath_err(ath9k_hw_common(sc->sc_ah), "Unknown AMPDU action\n");
  1573. }
  1574. mutex_unlock(&sc->mutex);
  1575. return ret;
  1576. }
  1577. static int ath9k_get_survey(struct ieee80211_hw *hw, int idx,
  1578. struct survey_info *survey)
  1579. {
  1580. struct ath_softc *sc = hw->priv;
  1581. struct ath_common *common = ath9k_hw_common(sc->sc_ah);
  1582. struct ieee80211_supported_band *sband;
  1583. struct ieee80211_channel *chan;
  1584. int pos;
  1585. if (config_enabled(CONFIG_ATH9K_TX99))
  1586. return -EOPNOTSUPP;
  1587. spin_lock_bh(&common->cc_lock);
  1588. if (idx == 0)
  1589. ath_update_survey_stats(sc);
  1590. sband = hw->wiphy->bands[IEEE80211_BAND_2GHZ];
  1591. if (sband && idx >= sband->n_channels) {
  1592. idx -= sband->n_channels;
  1593. sband = NULL;
  1594. }
  1595. if (!sband)
  1596. sband = hw->wiphy->bands[IEEE80211_BAND_5GHZ];
  1597. if (!sband || idx >= sband->n_channels) {
  1598. spin_unlock_bh(&common->cc_lock);
  1599. return -ENOENT;
  1600. }
  1601. chan = &sband->channels[idx];
  1602. pos = chan->hw_value;
  1603. memcpy(survey, &sc->survey[pos], sizeof(*survey));
  1604. survey->channel = chan;
  1605. spin_unlock_bh(&common->cc_lock);
  1606. return 0;
  1607. }
  1608. static void ath9k_set_coverage_class(struct ieee80211_hw *hw, u8 coverage_class)
  1609. {
  1610. struct ath_softc *sc = hw->priv;
  1611. struct ath_hw *ah = sc->sc_ah;
  1612. if (config_enabled(CONFIG_ATH9K_TX99))
  1613. return;
  1614. mutex_lock(&sc->mutex);
  1615. ah->coverage_class = coverage_class;
  1616. ath9k_ps_wakeup(sc);
  1617. ath9k_hw_init_global_settings(ah);
  1618. ath9k_ps_restore(sc);
  1619. mutex_unlock(&sc->mutex);
  1620. }
  1621. static bool ath9k_has_tx_pending(struct ath_softc *sc)
  1622. {
  1623. int i, npend = 0;
  1624. for (i = 0; i < ATH9K_NUM_TX_QUEUES; i++) {
  1625. if (!ATH_TXQ_SETUP(sc, i))
  1626. continue;
  1627. if (!sc->tx.txq[i].axq_depth)
  1628. continue;
  1629. npend = ath9k_has_pending_frames(sc, &sc->tx.txq[i]);
  1630. if (npend)
  1631. break;
  1632. }
  1633. return !!npend;
  1634. }
  1635. static void ath9k_flush(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
  1636. u32 queues, bool drop)
  1637. {
  1638. struct ath_softc *sc = hw->priv;
  1639. mutex_lock(&sc->mutex);
  1640. __ath9k_flush(hw, queues, drop);
  1641. mutex_unlock(&sc->mutex);
  1642. }
  1643. void __ath9k_flush(struct ieee80211_hw *hw, u32 queues, bool drop)
  1644. {
  1645. struct ath_softc *sc = hw->priv;
  1646. struct ath_hw *ah = sc->sc_ah;
  1647. struct ath_common *common = ath9k_hw_common(ah);
  1648. int timeout = HZ / 5; /* 200 ms */
  1649. bool drain_txq;
  1650. int i;
  1651. cancel_delayed_work_sync(&sc->tx_complete_work);
  1652. if (ah->ah_flags & AH_UNPLUGGED) {
  1653. ath_dbg(common, ANY, "Device has been unplugged!\n");
  1654. return;
  1655. }
  1656. if (test_bit(ATH_OP_INVALID, &common->op_flags)) {
  1657. ath_dbg(common, ANY, "Device not present\n");
  1658. return;
  1659. }
  1660. if (wait_event_timeout(sc->tx_wait, !ath9k_has_tx_pending(sc),
  1661. timeout) > 0)
  1662. drop = false;
  1663. if (drop) {
  1664. ath9k_ps_wakeup(sc);
  1665. spin_lock_bh(&sc->sc_pcu_lock);
  1666. drain_txq = ath_drain_all_txq(sc);
  1667. spin_unlock_bh(&sc->sc_pcu_lock);
  1668. if (!drain_txq)
  1669. ath_reset(sc);
  1670. ath9k_ps_restore(sc);
  1671. for (i = 0; i < IEEE80211_NUM_ACS; i++) {
  1672. ieee80211_wake_queue(sc->hw,
  1673. sc->cur_chan->hw_queue_base + i);
  1674. }
  1675. }
  1676. ieee80211_queue_delayed_work(hw, &sc->tx_complete_work, 0);
  1677. }
  1678. static bool ath9k_tx_frames_pending(struct ieee80211_hw *hw)
  1679. {
  1680. struct ath_softc *sc = hw->priv;
  1681. int i;
  1682. for (i = 0; i < ATH9K_NUM_TX_QUEUES; i++) {
  1683. if (!ATH_TXQ_SETUP(sc, i))
  1684. continue;
  1685. if (ath9k_has_pending_frames(sc, &sc->tx.txq[i]))
  1686. return true;
  1687. }
  1688. return false;
  1689. }
  1690. static int ath9k_tx_last_beacon(struct ieee80211_hw *hw)
  1691. {
  1692. struct ath_softc *sc = hw->priv;
  1693. struct ath_hw *ah = sc->sc_ah;
  1694. struct ieee80211_vif *vif;
  1695. struct ath_vif *avp;
  1696. struct ath_buf *bf;
  1697. struct ath_tx_status ts;
  1698. bool edma = !!(ah->caps.hw_caps & ATH9K_HW_CAP_EDMA);
  1699. int status;
  1700. vif = sc->beacon.bslot[0];
  1701. if (!vif)
  1702. return 0;
  1703. if (!vif->bss_conf.enable_beacon)
  1704. return 0;
  1705. avp = (void *)vif->drv_priv;
  1706. if (!sc->beacon.tx_processed && !edma) {
  1707. tasklet_disable(&sc->bcon_tasklet);
  1708. bf = avp->av_bcbuf;
  1709. if (!bf || !bf->bf_mpdu)
  1710. goto skip;
  1711. status = ath9k_hw_txprocdesc(ah, bf->bf_desc, &ts);
  1712. if (status == -EINPROGRESS)
  1713. goto skip;
  1714. sc->beacon.tx_processed = true;
  1715. sc->beacon.tx_last = !(ts.ts_status & ATH9K_TXERR_MASK);
  1716. skip:
  1717. tasklet_enable(&sc->bcon_tasklet);
  1718. }
  1719. return sc->beacon.tx_last;
  1720. }
  1721. static int ath9k_get_stats(struct ieee80211_hw *hw,
  1722. struct ieee80211_low_level_stats *stats)
  1723. {
  1724. struct ath_softc *sc = hw->priv;
  1725. struct ath_hw *ah = sc->sc_ah;
  1726. struct ath9k_mib_stats *mib_stats = &ah->ah_mibStats;
  1727. stats->dot11ACKFailureCount = mib_stats->ackrcv_bad;
  1728. stats->dot11RTSFailureCount = mib_stats->rts_bad;
  1729. stats->dot11FCSErrorCount = mib_stats->fcs_bad;
  1730. stats->dot11RTSSuccessCount = mib_stats->rts_good;
  1731. return 0;
  1732. }
  1733. static u32 fill_chainmask(u32 cap, u32 new)
  1734. {
  1735. u32 filled = 0;
  1736. int i;
  1737. for (i = 0; cap && new; i++, cap >>= 1) {
  1738. if (!(cap & BIT(0)))
  1739. continue;
  1740. if (new & BIT(0))
  1741. filled |= BIT(i);
  1742. new >>= 1;
  1743. }
  1744. return filled;
  1745. }
  1746. static bool validate_antenna_mask(struct ath_hw *ah, u32 val)
  1747. {
  1748. if (AR_SREV_9300_20_OR_LATER(ah))
  1749. return true;
  1750. switch (val & 0x7) {
  1751. case 0x1:
  1752. case 0x3:
  1753. case 0x7:
  1754. return true;
  1755. case 0x2:
  1756. return (ah->caps.rx_chainmask == 1);
  1757. default:
  1758. return false;
  1759. }
  1760. }
  1761. static int ath9k_set_antenna(struct ieee80211_hw *hw, u32 tx_ant, u32 rx_ant)
  1762. {
  1763. struct ath_softc *sc = hw->priv;
  1764. struct ath_hw *ah = sc->sc_ah;
  1765. if (ah->caps.rx_chainmask != 1)
  1766. rx_ant |= tx_ant;
  1767. if (!validate_antenna_mask(ah, rx_ant) || !tx_ant)
  1768. return -EINVAL;
  1769. sc->ant_rx = rx_ant;
  1770. sc->ant_tx = tx_ant;
  1771. if (ah->caps.rx_chainmask == 1)
  1772. return 0;
  1773. /* AR9100 runs into calibration issues if not all rx chains are enabled */
  1774. if (AR_SREV_9100(ah))
  1775. ah->rxchainmask = 0x7;
  1776. else
  1777. ah->rxchainmask = fill_chainmask(ah->caps.rx_chainmask, rx_ant);
  1778. ah->txchainmask = fill_chainmask(ah->caps.tx_chainmask, tx_ant);
  1779. ath9k_cmn_reload_chainmask(ah);
  1780. return 0;
  1781. }
  1782. static int ath9k_get_antenna(struct ieee80211_hw *hw, u32 *tx_ant, u32 *rx_ant)
  1783. {
  1784. struct ath_softc *sc = hw->priv;
  1785. *tx_ant = sc->ant_tx;
  1786. *rx_ant = sc->ant_rx;
  1787. return 0;
  1788. }
  1789. static void ath9k_sw_scan_start(struct ieee80211_hw *hw)
  1790. {
  1791. struct ath_softc *sc = hw->priv;
  1792. struct ath_common *common = ath9k_hw_common(sc->sc_ah);
  1793. set_bit(ATH_OP_SCANNING, &common->op_flags);
  1794. }
  1795. static void ath9k_sw_scan_complete(struct ieee80211_hw *hw)
  1796. {
  1797. struct ath_softc *sc = hw->priv;
  1798. struct ath_common *common = ath9k_hw_common(sc->sc_ah);
  1799. clear_bit(ATH_OP_SCANNING, &common->op_flags);
  1800. }
  1801. static int ath_scan_channel_duration(struct ath_softc *sc,
  1802. struct ieee80211_channel *chan)
  1803. {
  1804. struct cfg80211_scan_request *req = sc->offchannel.scan_req;
  1805. if (!req->n_ssids || (chan->flags & IEEE80211_CHAN_NO_IR))
  1806. return (HZ / 9); /* ~110 ms */
  1807. return (HZ / 16); /* ~60 ms */
  1808. }
  1809. static void
  1810. ath_scan_next_channel(struct ath_softc *sc)
  1811. {
  1812. struct cfg80211_scan_request *req = sc->offchannel.scan_req;
  1813. struct ieee80211_channel *chan;
  1814. if (sc->offchannel.scan_idx >= req->n_channels) {
  1815. sc->offchannel.state = ATH_OFFCHANNEL_IDLE;
  1816. ath_chanctx_switch(sc, ath_chanctx_get_oper_chan(sc, false),
  1817. NULL);
  1818. return;
  1819. }
  1820. chan = req->channels[sc->offchannel.scan_idx++];
  1821. sc->offchannel.duration = ath_scan_channel_duration(sc, chan);
  1822. sc->offchannel.state = ATH_OFFCHANNEL_PROBE_SEND;
  1823. ath_chanctx_offchan_switch(sc, chan);
  1824. }
  1825. static void ath_offchannel_next(struct ath_softc *sc)
  1826. {
  1827. struct ieee80211_vif *vif;
  1828. if (sc->offchannel.scan_req) {
  1829. vif = sc->offchannel.scan_vif;
  1830. sc->offchannel.chan.txpower = vif->bss_conf.txpower;
  1831. ath_scan_next_channel(sc);
  1832. } else if (sc->offchannel.roc_vif) {
  1833. vif = sc->offchannel.roc_vif;
  1834. sc->offchannel.chan.txpower = vif->bss_conf.txpower;
  1835. sc->offchannel.duration = sc->offchannel.roc_duration;
  1836. sc->offchannel.state = ATH_OFFCHANNEL_ROC_START;
  1837. ath_chanctx_offchan_switch(sc, sc->offchannel.roc_chan);
  1838. } else {
  1839. ath_chanctx_switch(sc, ath_chanctx_get_oper_chan(sc, false),
  1840. NULL);
  1841. sc->offchannel.state = ATH_OFFCHANNEL_IDLE;
  1842. if (sc->ps_idle)
  1843. ath_cancel_work(sc);
  1844. }
  1845. }
  1846. static void ath_roc_complete(struct ath_softc *sc, bool abort)
  1847. {
  1848. sc->offchannel.roc_vif = NULL;
  1849. sc->offchannel.roc_chan = NULL;
  1850. if (!abort)
  1851. ieee80211_remain_on_channel_expired(sc->hw);
  1852. ath_offchannel_next(sc);
  1853. ath9k_ps_restore(sc);
  1854. }
  1855. static void ath_scan_complete(struct ath_softc *sc, bool abort)
  1856. {
  1857. struct ath_common *common = ath9k_hw_common(sc->sc_ah);
  1858. sc->offchannel.scan_req = NULL;
  1859. sc->offchannel.scan_vif = NULL;
  1860. sc->offchannel.state = ATH_OFFCHANNEL_IDLE;
  1861. ieee80211_scan_completed(sc->hw, abort);
  1862. clear_bit(ATH_OP_SCANNING, &common->op_flags);
  1863. ath_offchannel_next(sc);
  1864. ath9k_ps_restore(sc);
  1865. }
  1866. static void ath_scan_send_probe(struct ath_softc *sc,
  1867. struct cfg80211_ssid *ssid)
  1868. {
  1869. struct cfg80211_scan_request *req = sc->offchannel.scan_req;
  1870. struct ieee80211_vif *vif = sc->offchannel.scan_vif;
  1871. struct ath_tx_control txctl = {};
  1872. struct sk_buff *skb;
  1873. struct ieee80211_tx_info *info;
  1874. int band = sc->offchannel.chan.chandef.chan->band;
  1875. skb = ieee80211_probereq_get(sc->hw, vif,
  1876. ssid->ssid, ssid->ssid_len, req->ie_len);
  1877. if (!skb)
  1878. return;
  1879. info = IEEE80211_SKB_CB(skb);
  1880. if (req->no_cck)
  1881. info->flags |= IEEE80211_TX_CTL_NO_CCK_RATE;
  1882. if (req->ie_len)
  1883. memcpy(skb_put(skb, req->ie_len), req->ie, req->ie_len);
  1884. skb_set_queue_mapping(skb, IEEE80211_AC_VO);
  1885. if (!ieee80211_tx_prepare_skb(sc->hw, vif, skb, band, NULL))
  1886. goto error;
  1887. txctl.txq = sc->tx.txq_map[IEEE80211_AC_VO];
  1888. txctl.force_channel = true;
  1889. if (ath_tx_start(sc->hw, skb, &txctl))
  1890. goto error;
  1891. return;
  1892. error:
  1893. ieee80211_free_txskb(sc->hw, skb);
  1894. }
  1895. static void ath_scan_channel_start(struct ath_softc *sc)
  1896. {
  1897. struct cfg80211_scan_request *req = sc->offchannel.scan_req;
  1898. int i;
  1899. if (!(sc->cur_chan->chandef.chan->flags & IEEE80211_CHAN_NO_IR) &&
  1900. req->n_ssids) {
  1901. for (i = 0; i < req->n_ssids; i++)
  1902. ath_scan_send_probe(sc, &req->ssids[i]);
  1903. }
  1904. sc->offchannel.state = ATH_OFFCHANNEL_PROBE_WAIT;
  1905. mod_timer(&sc->offchannel.timer, jiffies + sc->offchannel.duration);
  1906. }
  1907. void ath_offchannel_channel_change(struct ath_softc *sc)
  1908. {
  1909. switch (sc->offchannel.state) {
  1910. case ATH_OFFCHANNEL_PROBE_SEND:
  1911. if (!sc->offchannel.scan_req)
  1912. return;
  1913. if (sc->cur_chan->chandef.chan !=
  1914. sc->offchannel.chan.chandef.chan)
  1915. return;
  1916. ath_scan_channel_start(sc);
  1917. break;
  1918. case ATH_OFFCHANNEL_IDLE:
  1919. if (!sc->offchannel.scan_req)
  1920. return;
  1921. ath_scan_complete(sc, false);
  1922. break;
  1923. case ATH_OFFCHANNEL_ROC_START:
  1924. if (sc->cur_chan != &sc->offchannel.chan)
  1925. break;
  1926. sc->offchannel.state = ATH_OFFCHANNEL_ROC_WAIT;
  1927. mod_timer(&sc->offchannel.timer, jiffies +
  1928. msecs_to_jiffies(sc->offchannel.duration));
  1929. ieee80211_ready_on_channel(sc->hw);
  1930. break;
  1931. case ATH_OFFCHANNEL_ROC_DONE:
  1932. ath_roc_complete(sc, false);
  1933. break;
  1934. default:
  1935. break;
  1936. }
  1937. }
  1938. void ath_offchannel_timer(unsigned long data)
  1939. {
  1940. struct ath_softc *sc = (struct ath_softc *)data;
  1941. struct ath_chanctx *ctx;
  1942. switch (sc->offchannel.state) {
  1943. case ATH_OFFCHANNEL_PROBE_WAIT:
  1944. if (!sc->offchannel.scan_req)
  1945. return;
  1946. /* get first active channel context */
  1947. ctx = ath_chanctx_get_oper_chan(sc, true);
  1948. if (ctx->active) {
  1949. sc->offchannel.state = ATH_OFFCHANNEL_SUSPEND;
  1950. ath_chanctx_switch(sc, ctx, NULL);
  1951. mod_timer(&sc->offchannel.timer, jiffies + HZ / 10);
  1952. break;
  1953. }
  1954. /* fall through */
  1955. case ATH_OFFCHANNEL_SUSPEND:
  1956. if (!sc->offchannel.scan_req)
  1957. return;
  1958. ath_scan_next_channel(sc);
  1959. break;
  1960. case ATH_OFFCHANNEL_ROC_START:
  1961. case ATH_OFFCHANNEL_ROC_WAIT:
  1962. ctx = ath_chanctx_get_oper_chan(sc, false);
  1963. sc->offchannel.state = ATH_OFFCHANNEL_ROC_DONE;
  1964. ath_chanctx_switch(sc, ctx, NULL);
  1965. break;
  1966. default:
  1967. break;
  1968. }
  1969. }
  1970. static int ath9k_hw_scan(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
  1971. struct cfg80211_scan_request *req)
  1972. {
  1973. struct ath_softc *sc = hw->priv;
  1974. struct ath_common *common = ath9k_hw_common(sc->sc_ah);
  1975. int ret = 0;
  1976. mutex_lock(&sc->mutex);
  1977. if (WARN_ON(sc->offchannel.scan_req)) {
  1978. ret = -EBUSY;
  1979. goto out;
  1980. }
  1981. ath9k_ps_wakeup(sc);
  1982. set_bit(ATH_OP_SCANNING, &common->op_flags);
  1983. sc->offchannel.scan_vif = vif;
  1984. sc->offchannel.scan_req = req;
  1985. sc->offchannel.scan_idx = 0;
  1986. if (sc->offchannel.state == ATH_OFFCHANNEL_IDLE)
  1987. ath_offchannel_next(sc);
  1988. out:
  1989. mutex_unlock(&sc->mutex);
  1990. return ret;
  1991. }
  1992. static void ath9k_cancel_hw_scan(struct ieee80211_hw *hw,
  1993. struct ieee80211_vif *vif)
  1994. {
  1995. struct ath_softc *sc = hw->priv;
  1996. mutex_lock(&sc->mutex);
  1997. del_timer_sync(&sc->offchannel.timer);
  1998. ath_scan_complete(sc, true);
  1999. mutex_unlock(&sc->mutex);
  2000. }
  2001. static int ath9k_remain_on_channel(struct ieee80211_hw *hw,
  2002. struct ieee80211_vif *vif,
  2003. struct ieee80211_channel *chan, int duration,
  2004. enum ieee80211_roc_type type)
  2005. {
  2006. struct ath_softc *sc = hw->priv;
  2007. int ret = 0;
  2008. mutex_lock(&sc->mutex);
  2009. if (WARN_ON(sc->offchannel.roc_vif)) {
  2010. ret = -EBUSY;
  2011. goto out;
  2012. }
  2013. ath9k_ps_wakeup(sc);
  2014. sc->offchannel.roc_vif = vif;
  2015. sc->offchannel.roc_chan = chan;
  2016. sc->offchannel.roc_duration = duration;
  2017. if (sc->offchannel.state == ATH_OFFCHANNEL_IDLE)
  2018. ath_offchannel_next(sc);
  2019. out:
  2020. mutex_unlock(&sc->mutex);
  2021. return ret;
  2022. }
  2023. static int ath9k_cancel_remain_on_channel(struct ieee80211_hw *hw)
  2024. {
  2025. struct ath_softc *sc = hw->priv;
  2026. mutex_lock(&sc->mutex);
  2027. del_timer_sync(&sc->offchannel.timer);
  2028. if (sc->offchannel.roc_vif) {
  2029. if (sc->offchannel.state >= ATH_OFFCHANNEL_ROC_START)
  2030. ath_roc_complete(sc, true);
  2031. }
  2032. mutex_unlock(&sc->mutex);
  2033. return 0;
  2034. }
  2035. static int ath9k_add_chanctx(struct ieee80211_hw *hw,
  2036. struct ieee80211_chanctx_conf *conf)
  2037. {
  2038. struct ath_softc *sc = hw->priv;
  2039. struct ath_chanctx *ctx, **ptr;
  2040. int pos;
  2041. mutex_lock(&sc->mutex);
  2042. ath_for_each_chanctx(sc, ctx) {
  2043. if (ctx->assigned)
  2044. continue;
  2045. ptr = (void *) conf->drv_priv;
  2046. *ptr = ctx;
  2047. ctx->assigned = true;
  2048. pos = ctx - &sc->chanctx[0];
  2049. ctx->hw_queue_base = pos * IEEE80211_NUM_ACS;
  2050. ath_chanctx_set_channel(sc, ctx, &conf->def);
  2051. mutex_unlock(&sc->mutex);
  2052. return 0;
  2053. }
  2054. mutex_unlock(&sc->mutex);
  2055. return -ENOSPC;
  2056. }
  2057. static void ath9k_remove_chanctx(struct ieee80211_hw *hw,
  2058. struct ieee80211_chanctx_conf *conf)
  2059. {
  2060. struct ath_softc *sc = hw->priv;
  2061. struct ath_chanctx *ctx = ath_chanctx_get(conf);
  2062. mutex_lock(&sc->mutex);
  2063. ctx->assigned = false;
  2064. ctx->hw_queue_base = -1;
  2065. ath_chanctx_event(sc, NULL, ATH_CHANCTX_EVENT_UNASSIGN);
  2066. mutex_unlock(&sc->mutex);
  2067. }
  2068. static void ath9k_change_chanctx(struct ieee80211_hw *hw,
  2069. struct ieee80211_chanctx_conf *conf,
  2070. u32 changed)
  2071. {
  2072. struct ath_softc *sc = hw->priv;
  2073. struct ath_chanctx *ctx = ath_chanctx_get(conf);
  2074. mutex_lock(&sc->mutex);
  2075. ath_chanctx_set_channel(sc, ctx, &conf->def);
  2076. mutex_unlock(&sc->mutex);
  2077. }
  2078. static int ath9k_assign_vif_chanctx(struct ieee80211_hw *hw,
  2079. struct ieee80211_vif *vif,
  2080. struct ieee80211_chanctx_conf *conf)
  2081. {
  2082. struct ath_softc *sc = hw->priv;
  2083. struct ath_vif *avp = (void *)vif->drv_priv;
  2084. struct ath_chanctx *ctx = ath_chanctx_get(conf);
  2085. int i;
  2086. mutex_lock(&sc->mutex);
  2087. avp->chanctx = ctx;
  2088. list_add_tail(&avp->list, &ctx->vifs);
  2089. ath9k_calculate_summary_state(sc, ctx);
  2090. for (i = 0; i < IEEE80211_NUM_ACS; i++)
  2091. vif->hw_queue[i] = ctx->hw_queue_base + i;
  2092. mutex_unlock(&sc->mutex);
  2093. return 0;
  2094. }
  2095. static void ath9k_unassign_vif_chanctx(struct ieee80211_hw *hw,
  2096. struct ieee80211_vif *vif,
  2097. struct ieee80211_chanctx_conf *conf)
  2098. {
  2099. struct ath_softc *sc = hw->priv;
  2100. struct ath_vif *avp = (void *)vif->drv_priv;
  2101. struct ath_chanctx *ctx = ath_chanctx_get(conf);
  2102. int ac;
  2103. mutex_lock(&sc->mutex);
  2104. avp->chanctx = NULL;
  2105. list_del(&avp->list);
  2106. ath9k_calculate_summary_state(sc, ctx);
  2107. for (ac = 0; ac < IEEE80211_NUM_ACS; ac++)
  2108. vif->hw_queue[ac] = IEEE80211_INVAL_HW_QUEUE;
  2109. mutex_unlock(&sc->mutex);
  2110. }
  2111. void ath9k_fill_chanctx_ops(void)
  2112. {
  2113. if (!ath9k_use_chanctx)
  2114. return;
  2115. ath9k_ops.hw_scan = ath9k_hw_scan;
  2116. ath9k_ops.cancel_hw_scan = ath9k_cancel_hw_scan;
  2117. ath9k_ops.remain_on_channel = ath9k_remain_on_channel;
  2118. ath9k_ops.cancel_remain_on_channel = ath9k_cancel_remain_on_channel;
  2119. ath9k_ops.add_chanctx = ath9k_add_chanctx;
  2120. ath9k_ops.remove_chanctx = ath9k_remove_chanctx;
  2121. ath9k_ops.change_chanctx = ath9k_change_chanctx;
  2122. ath9k_ops.assign_vif_chanctx = ath9k_assign_vif_chanctx;
  2123. ath9k_ops.unassign_vif_chanctx = ath9k_unassign_vif_chanctx;
  2124. ath9k_ops.mgd_prepare_tx = ath9k_chanctx_force_active;
  2125. }
  2126. struct ieee80211_ops ath9k_ops = {
  2127. .tx = ath9k_tx,
  2128. .start = ath9k_start,
  2129. .stop = ath9k_stop,
  2130. .add_interface = ath9k_add_interface,
  2131. .change_interface = ath9k_change_interface,
  2132. .remove_interface = ath9k_remove_interface,
  2133. .config = ath9k_config,
  2134. .configure_filter = ath9k_configure_filter,
  2135. .sta_add = ath9k_sta_add,
  2136. .sta_remove = ath9k_sta_remove,
  2137. .sta_notify = ath9k_sta_notify,
  2138. .conf_tx = ath9k_conf_tx,
  2139. .bss_info_changed = ath9k_bss_info_changed,
  2140. .set_key = ath9k_set_key,
  2141. .get_tsf = ath9k_get_tsf,
  2142. .set_tsf = ath9k_set_tsf,
  2143. .reset_tsf = ath9k_reset_tsf,
  2144. .ampdu_action = ath9k_ampdu_action,
  2145. .get_survey = ath9k_get_survey,
  2146. .rfkill_poll = ath9k_rfkill_poll_state,
  2147. .set_coverage_class = ath9k_set_coverage_class,
  2148. .flush = ath9k_flush,
  2149. .tx_frames_pending = ath9k_tx_frames_pending,
  2150. .tx_last_beacon = ath9k_tx_last_beacon,
  2151. .release_buffered_frames = ath9k_release_buffered_frames,
  2152. .get_stats = ath9k_get_stats,
  2153. .set_antenna = ath9k_set_antenna,
  2154. .get_antenna = ath9k_get_antenna,
  2155. #ifdef CONFIG_ATH9K_WOW
  2156. .suspend = ath9k_suspend,
  2157. .resume = ath9k_resume,
  2158. .set_wakeup = ath9k_set_wakeup,
  2159. #endif
  2160. #ifdef CONFIG_ATH9K_DEBUGFS
  2161. .get_et_sset_count = ath9k_get_et_sset_count,
  2162. .get_et_stats = ath9k_get_et_stats,
  2163. .get_et_strings = ath9k_get_et_strings,
  2164. #endif
  2165. #if defined(CONFIG_MAC80211_DEBUGFS) && defined(CONFIG_ATH9K_STATION_STATISTICS)
  2166. .sta_add_debugfs = ath9k_sta_add_debugfs,
  2167. #endif
  2168. .sw_scan_start = ath9k_sw_scan_start,
  2169. .sw_scan_complete = ath9k_sw_scan_complete,
  2170. };