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