main.c 51 KB

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