main.c 51 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121
  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_work_sync(&sc->hw_check_work);
  147. cancel_delayed_work_sync(&sc->tx_complete_work);
  148. cancel_delayed_work_sync(&sc->hw_pll_work);
  149. #ifdef CONFIG_ATH9K_BTCOEX_SUPPORT
  150. if (ath9k_hw_mci_is_enabled(sc->sc_ah))
  151. cancel_work_sync(&sc->mci_work);
  152. #endif
  153. }
  154. void ath_cancel_work(struct ath_softc *sc)
  155. {
  156. __ath_cancel_work(sc);
  157. cancel_work_sync(&sc->hw_reset_work);
  158. }
  159. void ath_restart_work(struct ath_softc *sc)
  160. {
  161. ieee80211_queue_delayed_work(sc->hw, &sc->tx_complete_work, 0);
  162. if (AR_SREV_9340(sc->sc_ah) || AR_SREV_9330(sc->sc_ah))
  163. ieee80211_queue_delayed_work(sc->hw, &sc->hw_pll_work,
  164. msecs_to_jiffies(ATH_PLL_WORK_INTERVAL));
  165. ath_start_rx_poll(sc, 3);
  166. ath_start_ani(sc);
  167. }
  168. static bool ath_prepare_reset(struct ath_softc *sc)
  169. {
  170. struct ath_hw *ah = sc->sc_ah;
  171. bool ret = true;
  172. ieee80211_stop_queues(sc->hw);
  173. sc->hw_busy_count = 0;
  174. ath_stop_ani(sc);
  175. del_timer_sync(&sc->rx_poll_timer);
  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->config.txpowlimit, &sc->curtxpow);
  195. clear_bit(SC_OP_HW_RESET, &sc->sc_flags);
  196. ath9k_hw_set_interrupts(ah);
  197. ath9k_hw_enable_interrupts(ah);
  198. if (!(sc->hw->conf.flags & IEEE80211_CONF_OFFCHANNEL) && start) {
  199. if (!test_bit(SC_OP_BEACONS, &sc->sc_flags))
  200. goto work;
  201. if (ah->opmode == NL80211_IFTYPE_STATION &&
  202. test_bit(SC_OP_PRIM_STA_VIF, &sc->sc_flags)) {
  203. spin_lock_irqsave(&sc->sc_pm_lock, flags);
  204. sc->ps_flags |= PS_BEACON_SYNC | PS_WAIT_FOR_BEACON;
  205. spin_unlock_irqrestore(&sc->sc_pm_lock, flags);
  206. } else {
  207. ath9k_set_beacon(sc);
  208. }
  209. work:
  210. ath_restart_work(sc);
  211. for (i = 0; i < ATH9K_NUM_TX_QUEUES; i++) {
  212. if (!ATH_TXQ_SETUP(sc, i))
  213. continue;
  214. spin_lock_bh(&sc->tx.txq[i].axq_lock);
  215. ath_txq_schedule(sc, &sc->tx.txq[i]);
  216. spin_unlock_bh(&sc->tx.txq[i].axq_lock);
  217. }
  218. }
  219. ieee80211_wake_queues(sc->hw);
  220. return true;
  221. }
  222. static int ath_reset_internal(struct ath_softc *sc, struct ath9k_channel *hchan)
  223. {
  224. struct ath_hw *ah = sc->sc_ah;
  225. struct ath_common *common = ath9k_hw_common(ah);
  226. struct ath9k_hw_cal_data *caldata = NULL;
  227. bool fastcc = true;
  228. int r;
  229. __ath_cancel_work(sc);
  230. tasklet_disable(&sc->intr_tq);
  231. spin_lock_bh(&sc->sc_pcu_lock);
  232. if (!(sc->hw->conf.flags & IEEE80211_CONF_OFFCHANNEL)) {
  233. fastcc = false;
  234. caldata = &sc->caldata;
  235. }
  236. if (!hchan) {
  237. fastcc = false;
  238. hchan = ah->curchan;
  239. }
  240. if (!ath_prepare_reset(sc))
  241. fastcc = false;
  242. ath_dbg(common, CONFIG, "Reset to %u MHz, HT40: %d fastcc: %d\n",
  243. hchan->channel, IS_CHAN_HT40(hchan), fastcc);
  244. r = ath9k_hw_reset(ah, hchan, caldata, fastcc);
  245. if (r) {
  246. ath_err(common,
  247. "Unable to reset channel, reset status %d\n", r);
  248. ath9k_hw_enable_interrupts(ah);
  249. ath9k_queue_reset(sc, RESET_TYPE_BB_HANG);
  250. goto out;
  251. }
  252. if (ath9k_hw_mci_is_enabled(sc->sc_ah) &&
  253. (sc->hw->conf.flags & IEEE80211_CONF_OFFCHANNEL))
  254. ath9k_mci_set_txpower(sc, true, false);
  255. if (!ath_complete_reset(sc, true))
  256. r = -EIO;
  257. out:
  258. spin_unlock_bh(&sc->sc_pcu_lock);
  259. tasklet_enable(&sc->intr_tq);
  260. return r;
  261. }
  262. /*
  263. * Set/change channels. If the channel is really being changed, it's done
  264. * by reseting the chip. To accomplish this we must first cleanup any pending
  265. * DMA, then restart stuff.
  266. */
  267. static int ath_set_channel(struct ath_softc *sc, struct cfg80211_chan_def *chandef)
  268. {
  269. struct ath_hw *ah = sc->sc_ah;
  270. struct ath_common *common = ath9k_hw_common(ah);
  271. struct ieee80211_hw *hw = sc->hw;
  272. struct ath9k_channel *hchan;
  273. struct ieee80211_channel *chan = chandef->chan;
  274. unsigned long flags;
  275. bool offchannel;
  276. int pos = chan->hw_value;
  277. int old_pos = -1;
  278. int r;
  279. if (test_bit(SC_OP_INVALID, &sc->sc_flags))
  280. return -EIO;
  281. offchannel = !!(hw->conf.flags & IEEE80211_CONF_OFFCHANNEL);
  282. if (ah->curchan)
  283. old_pos = ah->curchan - &ah->channels[0];
  284. ath_dbg(common, CONFIG, "Set channel: %d MHz width: %d\n",
  285. chan->center_freq, chandef->width);
  286. /* update survey stats for the old channel before switching */
  287. spin_lock_irqsave(&common->cc_lock, flags);
  288. ath_update_survey_stats(sc);
  289. spin_unlock_irqrestore(&common->cc_lock, flags);
  290. ath9k_cmn_get_channel(hw, ah, chandef);
  291. /*
  292. * If the operating channel changes, change the survey in-use flags
  293. * along with it.
  294. * Reset the survey data for the new channel, unless we're switching
  295. * back to the operating channel from an off-channel operation.
  296. */
  297. if (!offchannel && sc->cur_survey != &sc->survey[pos]) {
  298. if (sc->cur_survey)
  299. sc->cur_survey->filled &= ~SURVEY_INFO_IN_USE;
  300. sc->cur_survey = &sc->survey[pos];
  301. memset(sc->cur_survey, 0, sizeof(struct survey_info));
  302. sc->cur_survey->filled |= SURVEY_INFO_IN_USE;
  303. } else if (!(sc->survey[pos].filled & SURVEY_INFO_IN_USE)) {
  304. memset(&sc->survey[pos], 0, sizeof(struct survey_info));
  305. }
  306. hchan = &sc->sc_ah->channels[pos];
  307. r = ath_reset_internal(sc, hchan);
  308. if (r)
  309. return r;
  310. /*
  311. * The most recent snapshot of channel->noisefloor for the old
  312. * channel is only available after the hardware reset. Copy it to
  313. * the survey stats now.
  314. */
  315. if (old_pos >= 0)
  316. ath_update_survey_nf(sc, old_pos);
  317. /*
  318. * Enable radar pulse detection if on a DFS channel. Spectral
  319. * scanning and radar detection can not be used concurrently.
  320. */
  321. if (hw->conf.radar_enabled) {
  322. u32 rxfilter;
  323. /* set HW specific DFS configuration */
  324. ath9k_hw_set_radar_params(ah);
  325. rxfilter = ath9k_hw_getrxfilter(ah);
  326. rxfilter |= ATH9K_RX_FILTER_PHYRADAR |
  327. ATH9K_RX_FILTER_PHYERR;
  328. ath9k_hw_setrxfilter(ah, rxfilter);
  329. ath_dbg(common, DFS, "DFS enabled at freq %d\n",
  330. chan->center_freq);
  331. } else {
  332. /* perform spectral scan if requested. */
  333. if (test_bit(SC_OP_SCANNING, &sc->sc_flags) &&
  334. sc->spectral_mode == SPECTRAL_CHANSCAN)
  335. ath9k_spectral_scan_trigger(hw);
  336. }
  337. return 0;
  338. }
  339. static void ath_node_attach(struct ath_softc *sc, struct ieee80211_sta *sta,
  340. struct ieee80211_vif *vif)
  341. {
  342. struct ath_node *an;
  343. an = (struct ath_node *)sta->drv_priv;
  344. an->sc = sc;
  345. an->sta = sta;
  346. an->vif = vif;
  347. ath_tx_node_init(sc, an);
  348. if (sta->ht_cap.ht_supported) {
  349. an->maxampdu = 1 << (IEEE80211_HT_MAX_AMPDU_FACTOR +
  350. sta->ht_cap.ampdu_factor);
  351. an->mpdudensity = ath9k_parse_mpdudensity(sta->ht_cap.ampdu_density);
  352. }
  353. }
  354. static void ath_node_detach(struct ath_softc *sc, struct ieee80211_sta *sta)
  355. {
  356. struct ath_node *an = (struct ath_node *)sta->drv_priv;
  357. ath_tx_node_cleanup(sc, an);
  358. }
  359. void ath9k_tasklet(unsigned long data)
  360. {
  361. struct ath_softc *sc = (struct ath_softc *)data;
  362. struct ath_hw *ah = sc->sc_ah;
  363. struct ath_common *common = ath9k_hw_common(ah);
  364. enum ath_reset_type type;
  365. unsigned long flags;
  366. u32 status = sc->intrstatus;
  367. u32 rxmask;
  368. ath9k_ps_wakeup(sc);
  369. spin_lock(&sc->sc_pcu_lock);
  370. if ((status & ATH9K_INT_FATAL) ||
  371. (status & ATH9K_INT_BB_WATCHDOG)) {
  372. if (status & ATH9K_INT_FATAL)
  373. type = RESET_TYPE_FATAL_INT;
  374. else
  375. type = RESET_TYPE_BB_WATCHDOG;
  376. ath9k_queue_reset(sc, type);
  377. /*
  378. * Increment the ref. counter here so that
  379. * interrupts are enabled in the reset routine.
  380. */
  381. atomic_inc(&ah->intr_ref_cnt);
  382. ath_dbg(common, ANY, "FATAL: Skipping interrupts\n");
  383. goto out;
  384. }
  385. spin_lock_irqsave(&sc->sc_pm_lock, flags);
  386. if ((status & ATH9K_INT_TSFOOR) && sc->ps_enabled) {
  387. /*
  388. * TSF sync does not look correct; remain awake to sync with
  389. * the next Beacon.
  390. */
  391. ath_dbg(common, PS, "TSFOOR - Sync with next Beacon\n");
  392. sc->ps_flags |= PS_WAIT_FOR_BEACON | PS_BEACON_SYNC;
  393. }
  394. spin_unlock_irqrestore(&sc->sc_pm_lock, flags);
  395. if (ah->caps.hw_caps & ATH9K_HW_CAP_EDMA)
  396. rxmask = (ATH9K_INT_RXHP | ATH9K_INT_RXLP | ATH9K_INT_RXEOL |
  397. ATH9K_INT_RXORN);
  398. else
  399. rxmask = (ATH9K_INT_RX | ATH9K_INT_RXEOL | ATH9K_INT_RXORN);
  400. if (status & rxmask) {
  401. /* Check for high priority Rx first */
  402. if ((ah->caps.hw_caps & ATH9K_HW_CAP_EDMA) &&
  403. (status & ATH9K_INT_RXHP))
  404. ath_rx_tasklet(sc, 0, true);
  405. ath_rx_tasklet(sc, 0, false);
  406. }
  407. if (status & ATH9K_INT_TX) {
  408. if (ah->caps.hw_caps & ATH9K_HW_CAP_EDMA)
  409. ath_tx_edma_tasklet(sc);
  410. else
  411. ath_tx_tasklet(sc);
  412. wake_up(&sc->tx_wait);
  413. }
  414. ath9k_btcoex_handle_interrupt(sc, status);
  415. /* re-enable hardware interrupt */
  416. ath9k_hw_enable_interrupts(ah);
  417. out:
  418. spin_unlock(&sc->sc_pcu_lock);
  419. ath9k_ps_restore(sc);
  420. }
  421. irqreturn_t ath_isr(int irq, void *dev)
  422. {
  423. #define SCHED_INTR ( \
  424. ATH9K_INT_FATAL | \
  425. ATH9K_INT_BB_WATCHDOG | \
  426. ATH9K_INT_RXORN | \
  427. ATH9K_INT_RXEOL | \
  428. ATH9K_INT_RX | \
  429. ATH9K_INT_RXLP | \
  430. ATH9K_INT_RXHP | \
  431. ATH9K_INT_TX | \
  432. ATH9K_INT_BMISS | \
  433. ATH9K_INT_CST | \
  434. ATH9K_INT_TSFOOR | \
  435. ATH9K_INT_GENTIMER | \
  436. ATH9K_INT_MCI)
  437. struct ath_softc *sc = dev;
  438. struct ath_hw *ah = sc->sc_ah;
  439. struct ath_common *common = ath9k_hw_common(ah);
  440. enum ath9k_int status;
  441. bool sched = false;
  442. /*
  443. * The hardware is not ready/present, don't
  444. * touch anything. Note this can happen early
  445. * on if the IRQ is shared.
  446. */
  447. if (test_bit(SC_OP_INVALID, &sc->sc_flags))
  448. return IRQ_NONE;
  449. /* shared irq, not for us */
  450. if (!ath9k_hw_intrpend(ah))
  451. return IRQ_NONE;
  452. if (test_bit(SC_OP_HW_RESET, &sc->sc_flags)) {
  453. ath9k_hw_kill_interrupts(ah);
  454. return IRQ_HANDLED;
  455. }
  456. /*
  457. * Figure out the reason(s) for the interrupt. Note
  458. * that the hal returns a pseudo-ISR that may include
  459. * bits we haven't explicitly enabled so we mask the
  460. * value to insure we only process bits we requested.
  461. */
  462. ath9k_hw_getisr(ah, &status); /* NB: clears ISR too */
  463. status &= ah->imask; /* discard unasked-for bits */
  464. /*
  465. * If there are no status bits set, then this interrupt was not
  466. * for me (should have been caught above).
  467. */
  468. if (!status)
  469. return IRQ_NONE;
  470. /* Cache the status */
  471. sc->intrstatus = status;
  472. if (status & SCHED_INTR)
  473. sched = true;
  474. /*
  475. * If a FATAL or RXORN interrupt is received, we have to reset the
  476. * chip immediately.
  477. */
  478. if ((status & ATH9K_INT_FATAL) || ((status & ATH9K_INT_RXORN) &&
  479. !(ah->caps.hw_caps & ATH9K_HW_CAP_EDMA)))
  480. goto chip_reset;
  481. if ((ah->caps.hw_caps & ATH9K_HW_CAP_EDMA) &&
  482. (status & ATH9K_INT_BB_WATCHDOG)) {
  483. spin_lock(&common->cc_lock);
  484. ath_hw_cycle_counters_update(common);
  485. ar9003_hw_bb_watchdog_dbg_info(ah);
  486. spin_unlock(&common->cc_lock);
  487. goto chip_reset;
  488. }
  489. #ifdef CONFIG_ATH9K_WOW
  490. if (status & ATH9K_INT_BMISS) {
  491. if (atomic_read(&sc->wow_sleep_proc_intr) == 0) {
  492. ath_dbg(common, ANY, "during WoW we got a BMISS\n");
  493. atomic_inc(&sc->wow_got_bmiss_intr);
  494. atomic_dec(&sc->wow_sleep_proc_intr);
  495. }
  496. }
  497. #endif
  498. if (status & ATH9K_INT_SWBA)
  499. tasklet_schedule(&sc->bcon_tasklet);
  500. if (status & ATH9K_INT_TXURN)
  501. ath9k_hw_updatetxtriglevel(ah, true);
  502. if (status & ATH9K_INT_RXEOL) {
  503. ah->imask &= ~(ATH9K_INT_RXEOL | ATH9K_INT_RXORN);
  504. ath9k_hw_set_interrupts(ah);
  505. }
  506. if (!(ah->caps.hw_caps & ATH9K_HW_CAP_AUTOSLEEP))
  507. if (status & ATH9K_INT_TIM_TIMER) {
  508. if (ATH_DBG_WARN_ON_ONCE(sc->ps_idle))
  509. goto chip_reset;
  510. /* Clear RxAbort bit so that we can
  511. * receive frames */
  512. ath9k_setpower(sc, ATH9K_PM_AWAKE);
  513. spin_lock(&sc->sc_pm_lock);
  514. ath9k_hw_setrxabort(sc->sc_ah, 0);
  515. sc->ps_flags |= PS_WAIT_FOR_BEACON;
  516. spin_unlock(&sc->sc_pm_lock);
  517. }
  518. chip_reset:
  519. ath_debug_stat_interrupt(sc, status);
  520. if (sched) {
  521. /* turn off every interrupt */
  522. ath9k_hw_disable_interrupts(ah);
  523. tasklet_schedule(&sc->intr_tq);
  524. }
  525. return IRQ_HANDLED;
  526. #undef SCHED_INTR
  527. }
  528. int ath_reset(struct ath_softc *sc)
  529. {
  530. int r;
  531. ath9k_ps_wakeup(sc);
  532. r = ath_reset_internal(sc, NULL);
  533. ath9k_ps_restore(sc);
  534. return r;
  535. }
  536. void ath9k_queue_reset(struct ath_softc *sc, enum ath_reset_type type)
  537. {
  538. #ifdef CONFIG_ATH9K_DEBUGFS
  539. RESET_STAT_INC(sc, type);
  540. #endif
  541. set_bit(SC_OP_HW_RESET, &sc->sc_flags);
  542. ieee80211_queue_work(sc->hw, &sc->hw_reset_work);
  543. }
  544. void ath_reset_work(struct work_struct *work)
  545. {
  546. struct ath_softc *sc = container_of(work, struct ath_softc, hw_reset_work);
  547. ath_reset(sc);
  548. }
  549. /**********************/
  550. /* mac80211 callbacks */
  551. /**********************/
  552. static int ath9k_start(struct ieee80211_hw *hw)
  553. {
  554. struct ath_softc *sc = hw->priv;
  555. struct ath_hw *ah = sc->sc_ah;
  556. struct ath_common *common = ath9k_hw_common(ah);
  557. struct ieee80211_channel *curchan = hw->conf.chandef.chan;
  558. struct ath9k_channel *init_channel;
  559. int r;
  560. ath_dbg(common, CONFIG,
  561. "Starting driver with initial channel: %d MHz\n",
  562. curchan->center_freq);
  563. ath9k_ps_wakeup(sc);
  564. mutex_lock(&sc->mutex);
  565. init_channel = ath9k_cmn_get_channel(hw, ah, &hw->conf.chandef);
  566. /* Reset SERDES registers */
  567. ath9k_hw_configpcipowersave(ah, false);
  568. /*
  569. * The basic interface to setting the hardware in a good
  570. * state is ``reset''. On return the hardware is known to
  571. * be powered up and with interrupts disabled. This must
  572. * be followed by initialization of the appropriate bits
  573. * and then setup of the interrupt mask.
  574. */
  575. spin_lock_bh(&sc->sc_pcu_lock);
  576. atomic_set(&ah->intr_ref_cnt, -1);
  577. r = ath9k_hw_reset(ah, init_channel, ah->caldata, false);
  578. if (r) {
  579. ath_err(common,
  580. "Unable to reset hardware; reset status %d (freq %u MHz)\n",
  581. r, curchan->center_freq);
  582. ah->reset_power_on = false;
  583. }
  584. /* Setup our intr mask. */
  585. ah->imask = ATH9K_INT_TX | ATH9K_INT_RXEOL |
  586. ATH9K_INT_RXORN | ATH9K_INT_FATAL |
  587. ATH9K_INT_GLOBAL;
  588. if (ah->caps.hw_caps & ATH9K_HW_CAP_EDMA)
  589. ah->imask |= ATH9K_INT_RXHP |
  590. ATH9K_INT_RXLP |
  591. ATH9K_INT_BB_WATCHDOG;
  592. else
  593. ah->imask |= ATH9K_INT_RX;
  594. ah->imask |= ATH9K_INT_GTT;
  595. if (ah->caps.hw_caps & ATH9K_HW_CAP_HT)
  596. ah->imask |= ATH9K_INT_CST;
  597. ath_mci_enable(sc);
  598. clear_bit(SC_OP_INVALID, &sc->sc_flags);
  599. sc->sc_ah->is_monitoring = false;
  600. if (!ath_complete_reset(sc, false))
  601. ah->reset_power_on = false;
  602. if (ah->led_pin >= 0) {
  603. ath9k_hw_cfg_output(ah, ah->led_pin,
  604. AR_GPIO_OUTPUT_MUX_AS_OUTPUT);
  605. ath9k_hw_set_gpio(ah, ah->led_pin, 0);
  606. }
  607. /*
  608. * Reset key cache to sane defaults (all entries cleared) instead of
  609. * semi-random values after suspend/resume.
  610. */
  611. ath9k_cmn_init_crypto(sc->sc_ah);
  612. spin_unlock_bh(&sc->sc_pcu_lock);
  613. mutex_unlock(&sc->mutex);
  614. ath9k_ps_restore(sc);
  615. return 0;
  616. }
  617. static void ath9k_tx(struct ieee80211_hw *hw,
  618. struct ieee80211_tx_control *control,
  619. struct sk_buff *skb)
  620. {
  621. struct ath_softc *sc = hw->priv;
  622. struct ath_common *common = ath9k_hw_common(sc->sc_ah);
  623. struct ath_tx_control txctl;
  624. struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
  625. unsigned long flags;
  626. if (sc->ps_enabled) {
  627. /*
  628. * mac80211 does not set PM field for normal data frames, so we
  629. * need to update that based on the current PS mode.
  630. */
  631. if (ieee80211_is_data(hdr->frame_control) &&
  632. !ieee80211_is_nullfunc(hdr->frame_control) &&
  633. !ieee80211_has_pm(hdr->frame_control)) {
  634. ath_dbg(common, PS,
  635. "Add PM=1 for a TX frame while in PS mode\n");
  636. hdr->frame_control |= cpu_to_le16(IEEE80211_FCTL_PM);
  637. }
  638. }
  639. if (unlikely(sc->sc_ah->power_mode == ATH9K_PM_NETWORK_SLEEP)) {
  640. /*
  641. * We are using PS-Poll and mac80211 can request TX while in
  642. * power save mode. Need to wake up hardware for the TX to be
  643. * completed and if needed, also for RX of buffered frames.
  644. */
  645. ath9k_ps_wakeup(sc);
  646. spin_lock_irqsave(&sc->sc_pm_lock, flags);
  647. if (!(sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_AUTOSLEEP))
  648. ath9k_hw_setrxabort(sc->sc_ah, 0);
  649. if (ieee80211_is_pspoll(hdr->frame_control)) {
  650. ath_dbg(common, PS,
  651. "Sending PS-Poll to pick a buffered frame\n");
  652. sc->ps_flags |= PS_WAIT_FOR_PSPOLL_DATA;
  653. } else {
  654. ath_dbg(common, PS, "Wake up to complete TX\n");
  655. sc->ps_flags |= PS_WAIT_FOR_TX_ACK;
  656. }
  657. /*
  658. * The actual restore operation will happen only after
  659. * the ps_flags bit is cleared. We are just dropping
  660. * the ps_usecount here.
  661. */
  662. spin_unlock_irqrestore(&sc->sc_pm_lock, flags);
  663. ath9k_ps_restore(sc);
  664. }
  665. /*
  666. * Cannot tx while the hardware is in full sleep, it first needs a full
  667. * chip reset to recover from that
  668. */
  669. if (unlikely(sc->sc_ah->power_mode == ATH9K_PM_FULL_SLEEP)) {
  670. ath_err(common, "TX while HW is in FULL_SLEEP mode\n");
  671. goto exit;
  672. }
  673. memset(&txctl, 0, sizeof(struct ath_tx_control));
  674. txctl.txq = sc->tx.txq_map[skb_get_queue_mapping(skb)];
  675. txctl.sta = control->sta;
  676. ath_dbg(common, XMIT, "transmitting packet, skb: %p\n", skb);
  677. if (ath_tx_start(hw, skb, &txctl) != 0) {
  678. ath_dbg(common, XMIT, "TX failed\n");
  679. TX_STAT_INC(txctl.txq->axq_qnum, txfailed);
  680. goto exit;
  681. }
  682. return;
  683. exit:
  684. ieee80211_free_txskb(hw, skb);
  685. }
  686. static void ath9k_stop(struct ieee80211_hw *hw)
  687. {
  688. struct ath_softc *sc = hw->priv;
  689. struct ath_hw *ah = sc->sc_ah;
  690. struct ath_common *common = ath9k_hw_common(ah);
  691. bool prev_idle;
  692. mutex_lock(&sc->mutex);
  693. ath_cancel_work(sc);
  694. del_timer_sync(&sc->rx_poll_timer);
  695. if (test_bit(SC_OP_INVALID, &sc->sc_flags)) {
  696. ath_dbg(common, ANY, "Device not present\n");
  697. mutex_unlock(&sc->mutex);
  698. return;
  699. }
  700. /* Ensure HW is awake when we try to shut it down. */
  701. ath9k_ps_wakeup(sc);
  702. spin_lock_bh(&sc->sc_pcu_lock);
  703. /* prevent tasklets to enable interrupts once we disable them */
  704. ah->imask &= ~ATH9K_INT_GLOBAL;
  705. /* make sure h/w will not generate any interrupt
  706. * before setting the invalid flag. */
  707. ath9k_hw_disable_interrupts(ah);
  708. spin_unlock_bh(&sc->sc_pcu_lock);
  709. /* we can now sync irq and kill any running tasklets, since we already
  710. * disabled interrupts and not holding a spin lock */
  711. synchronize_irq(sc->irq);
  712. tasklet_kill(&sc->intr_tq);
  713. tasklet_kill(&sc->bcon_tasklet);
  714. prev_idle = sc->ps_idle;
  715. sc->ps_idle = true;
  716. spin_lock_bh(&sc->sc_pcu_lock);
  717. if (ah->led_pin >= 0) {
  718. ath9k_hw_set_gpio(ah, ah->led_pin, 1);
  719. ath9k_hw_cfg_gpio_input(ah, ah->led_pin);
  720. }
  721. ath_prepare_reset(sc);
  722. if (sc->rx.frag) {
  723. dev_kfree_skb_any(sc->rx.frag);
  724. sc->rx.frag = NULL;
  725. }
  726. if (!ah->curchan)
  727. ah->curchan = ath9k_cmn_get_channel(hw, ah, &hw->conf.chandef);
  728. ath9k_hw_reset(ah, ah->curchan, ah->caldata, false);
  729. ath9k_hw_phy_disable(ah);
  730. ath9k_hw_configpcipowersave(ah, true);
  731. spin_unlock_bh(&sc->sc_pcu_lock);
  732. ath9k_ps_restore(sc);
  733. set_bit(SC_OP_INVALID, &sc->sc_flags);
  734. sc->ps_idle = prev_idle;
  735. mutex_unlock(&sc->mutex);
  736. ath_dbg(common, CONFIG, "Driver halt\n");
  737. }
  738. static bool ath9k_uses_beacons(int type)
  739. {
  740. switch (type) {
  741. case NL80211_IFTYPE_AP:
  742. case NL80211_IFTYPE_ADHOC:
  743. case NL80211_IFTYPE_MESH_POINT:
  744. return true;
  745. default:
  746. return false;
  747. }
  748. }
  749. static void ath9k_vif_iter(void *data, u8 *mac, struct ieee80211_vif *vif)
  750. {
  751. struct ath9k_vif_iter_data *iter_data = data;
  752. int i;
  753. if (iter_data->has_hw_macaddr) {
  754. for (i = 0; i < ETH_ALEN; i++)
  755. iter_data->mask[i] &=
  756. ~(iter_data->hw_macaddr[i] ^ mac[i]);
  757. } else {
  758. memcpy(iter_data->hw_macaddr, mac, ETH_ALEN);
  759. iter_data->has_hw_macaddr = true;
  760. }
  761. switch (vif->type) {
  762. case NL80211_IFTYPE_AP:
  763. iter_data->naps++;
  764. break;
  765. case NL80211_IFTYPE_STATION:
  766. iter_data->nstations++;
  767. break;
  768. case NL80211_IFTYPE_ADHOC:
  769. iter_data->nadhocs++;
  770. break;
  771. case NL80211_IFTYPE_MESH_POINT:
  772. iter_data->nmeshes++;
  773. break;
  774. case NL80211_IFTYPE_WDS:
  775. iter_data->nwds++;
  776. break;
  777. default:
  778. break;
  779. }
  780. }
  781. static void ath9k_sta_vif_iter(void *data, u8 *mac, struct ieee80211_vif *vif)
  782. {
  783. struct ath_softc *sc = data;
  784. struct ath_vif *avp = (void *)vif->drv_priv;
  785. if (vif->type != NL80211_IFTYPE_STATION)
  786. return;
  787. if (avp->primary_sta_vif)
  788. ath9k_set_assoc_state(sc, vif);
  789. }
  790. /* Called with sc->mutex held. */
  791. void ath9k_calculate_iter_data(struct ieee80211_hw *hw,
  792. struct ieee80211_vif *vif,
  793. struct ath9k_vif_iter_data *iter_data)
  794. {
  795. struct ath_softc *sc = hw->priv;
  796. struct ath_hw *ah = sc->sc_ah;
  797. struct ath_common *common = ath9k_hw_common(ah);
  798. /*
  799. * Use the hardware MAC address as reference, the hardware uses it
  800. * together with the BSSID mask when matching addresses.
  801. */
  802. memset(iter_data, 0, sizeof(*iter_data));
  803. memset(&iter_data->mask, 0xff, ETH_ALEN);
  804. if (vif)
  805. ath9k_vif_iter(iter_data, vif->addr, vif);
  806. /* Get list of all active MAC addresses */
  807. ieee80211_iterate_active_interfaces_atomic(
  808. sc->hw, IEEE80211_IFACE_ITER_RESUME_ALL,
  809. ath9k_vif_iter, iter_data);
  810. memcpy(common->macaddr, iter_data->hw_macaddr, ETH_ALEN);
  811. }
  812. /* Called with sc->mutex held. */
  813. static void ath9k_calculate_summary_state(struct ieee80211_hw *hw,
  814. struct ieee80211_vif *vif)
  815. {
  816. struct ath_softc *sc = hw->priv;
  817. struct ath_hw *ah = sc->sc_ah;
  818. struct ath_common *common = ath9k_hw_common(ah);
  819. struct ath9k_vif_iter_data iter_data;
  820. enum nl80211_iftype old_opmode = ah->opmode;
  821. ath9k_calculate_iter_data(hw, vif, &iter_data);
  822. memcpy(common->bssidmask, iter_data.mask, ETH_ALEN);
  823. ath_hw_setbssidmask(common);
  824. if (iter_data.naps > 0) {
  825. ath9k_hw_set_tsfadjust(ah, true);
  826. ah->opmode = NL80211_IFTYPE_AP;
  827. } else {
  828. ath9k_hw_set_tsfadjust(ah, false);
  829. if (iter_data.nmeshes)
  830. ah->opmode = NL80211_IFTYPE_MESH_POINT;
  831. else if (iter_data.nwds)
  832. ah->opmode = NL80211_IFTYPE_AP;
  833. else if (iter_data.nadhocs)
  834. ah->opmode = NL80211_IFTYPE_ADHOC;
  835. else
  836. ah->opmode = NL80211_IFTYPE_STATION;
  837. }
  838. ath9k_hw_setopmode(ah);
  839. if ((iter_data.nstations + iter_data.nadhocs + iter_data.nmeshes) > 0)
  840. ah->imask |= ATH9K_INT_TSFOOR;
  841. else
  842. ah->imask &= ~ATH9K_INT_TSFOOR;
  843. ath9k_hw_set_interrupts(ah);
  844. /*
  845. * If we are changing the opmode to STATION,
  846. * a beacon sync needs to be done.
  847. */
  848. if (ah->opmode == NL80211_IFTYPE_STATION &&
  849. old_opmode == NL80211_IFTYPE_AP &&
  850. test_bit(SC_OP_PRIM_STA_VIF, &sc->sc_flags)) {
  851. ieee80211_iterate_active_interfaces_atomic(
  852. sc->hw, IEEE80211_IFACE_ITER_RESUME_ALL,
  853. ath9k_sta_vif_iter, sc);
  854. }
  855. }
  856. static int ath9k_add_interface(struct ieee80211_hw *hw,
  857. struct ieee80211_vif *vif)
  858. {
  859. struct ath_softc *sc = hw->priv;
  860. struct ath_hw *ah = sc->sc_ah;
  861. struct ath_common *common = ath9k_hw_common(ah);
  862. struct ath_vif *avp = (void *)vif->drv_priv;
  863. struct ath_node *an = &avp->mcast_node;
  864. mutex_lock(&sc->mutex);
  865. if (config_enabled(CONFIG_ATH9K_TX99)) {
  866. if (sc->nvifs >= 1) {
  867. mutex_unlock(&sc->mutex);
  868. return -EOPNOTSUPP;
  869. }
  870. sc->tx99_vif = vif;
  871. }
  872. ath_dbg(common, CONFIG, "Attach a VIF of type: %d\n", vif->type);
  873. sc->nvifs++;
  874. ath9k_ps_wakeup(sc);
  875. ath9k_calculate_summary_state(hw, vif);
  876. ath9k_ps_restore(sc);
  877. if (ath9k_uses_beacons(vif->type))
  878. ath9k_beacon_assign_slot(sc, vif);
  879. an->sc = sc;
  880. an->sta = NULL;
  881. an->vif = vif;
  882. an->no_ps_filter = true;
  883. ath_tx_node_init(sc, an);
  884. mutex_unlock(&sc->mutex);
  885. return 0;
  886. }
  887. static int ath9k_change_interface(struct ieee80211_hw *hw,
  888. struct ieee80211_vif *vif,
  889. enum nl80211_iftype new_type,
  890. bool p2p)
  891. {
  892. struct ath_softc *sc = hw->priv;
  893. struct ath_common *common = ath9k_hw_common(sc->sc_ah);
  894. mutex_lock(&sc->mutex);
  895. if (config_enabled(CONFIG_ATH9K_TX99)) {
  896. mutex_unlock(&sc->mutex);
  897. return -EOPNOTSUPP;
  898. }
  899. ath_dbg(common, CONFIG, "Change Interface\n");
  900. if (ath9k_uses_beacons(vif->type))
  901. ath9k_beacon_remove_slot(sc, vif);
  902. vif->type = new_type;
  903. vif->p2p = p2p;
  904. ath9k_ps_wakeup(sc);
  905. ath9k_calculate_summary_state(hw, vif);
  906. ath9k_ps_restore(sc);
  907. if (ath9k_uses_beacons(vif->type))
  908. ath9k_beacon_assign_slot(sc, vif);
  909. mutex_unlock(&sc->mutex);
  910. return 0;
  911. }
  912. static void ath9k_remove_interface(struct ieee80211_hw *hw,
  913. struct ieee80211_vif *vif)
  914. {
  915. struct ath_softc *sc = hw->priv;
  916. struct ath_common *common = ath9k_hw_common(sc->sc_ah);
  917. struct ath_vif *avp = (void *)vif->drv_priv;
  918. ath_dbg(common, CONFIG, "Detach Interface\n");
  919. mutex_lock(&sc->mutex);
  920. sc->nvifs--;
  921. sc->tx99_vif = NULL;
  922. if (ath9k_uses_beacons(vif->type))
  923. ath9k_beacon_remove_slot(sc, vif);
  924. if (sc->csa_vif == vif)
  925. sc->csa_vif = NULL;
  926. ath9k_ps_wakeup(sc);
  927. ath9k_calculate_summary_state(hw, NULL);
  928. ath9k_ps_restore(sc);
  929. ath_tx_node_cleanup(sc, &avp->mcast_node);
  930. mutex_unlock(&sc->mutex);
  931. }
  932. static void ath9k_enable_ps(struct ath_softc *sc)
  933. {
  934. struct ath_hw *ah = sc->sc_ah;
  935. struct ath_common *common = ath9k_hw_common(ah);
  936. if (config_enabled(CONFIG_ATH9K_TX99))
  937. return;
  938. sc->ps_enabled = true;
  939. if (!(ah->caps.hw_caps & ATH9K_HW_CAP_AUTOSLEEP)) {
  940. if ((ah->imask & ATH9K_INT_TIM_TIMER) == 0) {
  941. ah->imask |= ATH9K_INT_TIM_TIMER;
  942. ath9k_hw_set_interrupts(ah);
  943. }
  944. ath9k_hw_setrxabort(ah, 1);
  945. }
  946. ath_dbg(common, PS, "PowerSave enabled\n");
  947. }
  948. static void ath9k_disable_ps(struct ath_softc *sc)
  949. {
  950. struct ath_hw *ah = sc->sc_ah;
  951. struct ath_common *common = ath9k_hw_common(ah);
  952. if (config_enabled(CONFIG_ATH9K_TX99))
  953. return;
  954. sc->ps_enabled = false;
  955. ath9k_hw_setpower(ah, ATH9K_PM_AWAKE);
  956. if (!(ah->caps.hw_caps & ATH9K_HW_CAP_AUTOSLEEP)) {
  957. ath9k_hw_setrxabort(ah, 0);
  958. sc->ps_flags &= ~(PS_WAIT_FOR_BEACON |
  959. PS_WAIT_FOR_CAB |
  960. PS_WAIT_FOR_PSPOLL_DATA |
  961. PS_WAIT_FOR_TX_ACK);
  962. if (ah->imask & ATH9K_INT_TIM_TIMER) {
  963. ah->imask &= ~ATH9K_INT_TIM_TIMER;
  964. ath9k_hw_set_interrupts(ah);
  965. }
  966. }
  967. ath_dbg(common, PS, "PowerSave disabled\n");
  968. }
  969. void ath9k_spectral_scan_trigger(struct ieee80211_hw *hw)
  970. {
  971. struct ath_softc *sc = hw->priv;
  972. struct ath_hw *ah = sc->sc_ah;
  973. struct ath_common *common = ath9k_hw_common(ah);
  974. u32 rxfilter;
  975. if (config_enabled(CONFIG_ATH9K_TX99))
  976. return;
  977. if (!ath9k_hw_ops(ah)->spectral_scan_trigger) {
  978. ath_err(common, "spectrum analyzer not implemented on this hardware\n");
  979. return;
  980. }
  981. ath9k_ps_wakeup(sc);
  982. rxfilter = ath9k_hw_getrxfilter(ah);
  983. ath9k_hw_setrxfilter(ah, rxfilter |
  984. ATH9K_RX_FILTER_PHYRADAR |
  985. ATH9K_RX_FILTER_PHYERR);
  986. /* TODO: usually this should not be neccesary, but for some reason
  987. * (or in some mode?) the trigger must be called after the
  988. * configuration, otherwise the register will have its values reset
  989. * (on my ar9220 to value 0x01002310)
  990. */
  991. ath9k_spectral_scan_config(hw, sc->spectral_mode);
  992. ath9k_hw_ops(ah)->spectral_scan_trigger(ah);
  993. ath9k_ps_restore(sc);
  994. }
  995. int ath9k_spectral_scan_config(struct ieee80211_hw *hw,
  996. enum spectral_mode spectral_mode)
  997. {
  998. struct ath_softc *sc = hw->priv;
  999. struct ath_hw *ah = sc->sc_ah;
  1000. struct ath_common *common = ath9k_hw_common(ah);
  1001. if (!ath9k_hw_ops(ah)->spectral_scan_trigger) {
  1002. ath_err(common, "spectrum analyzer not implemented on this hardware\n");
  1003. return -1;
  1004. }
  1005. switch (spectral_mode) {
  1006. case SPECTRAL_DISABLED:
  1007. sc->spec_config.enabled = 0;
  1008. break;
  1009. case SPECTRAL_BACKGROUND:
  1010. /* send endless samples.
  1011. * TODO: is this really useful for "background"?
  1012. */
  1013. sc->spec_config.endless = 1;
  1014. sc->spec_config.enabled = 1;
  1015. break;
  1016. case SPECTRAL_CHANSCAN:
  1017. case SPECTRAL_MANUAL:
  1018. sc->spec_config.endless = 0;
  1019. sc->spec_config.enabled = 1;
  1020. break;
  1021. default:
  1022. return -1;
  1023. }
  1024. ath9k_ps_wakeup(sc);
  1025. ath9k_hw_ops(ah)->spectral_scan_config(ah, &sc->spec_config);
  1026. ath9k_ps_restore(sc);
  1027. sc->spectral_mode = spectral_mode;
  1028. return 0;
  1029. }
  1030. static int ath9k_config(struct ieee80211_hw *hw, u32 changed)
  1031. {
  1032. struct ath_softc *sc = hw->priv;
  1033. struct ath_hw *ah = sc->sc_ah;
  1034. struct ath_common *common = ath9k_hw_common(ah);
  1035. struct ieee80211_conf *conf = &hw->conf;
  1036. bool reset_channel = false;
  1037. ath9k_ps_wakeup(sc);
  1038. mutex_lock(&sc->mutex);
  1039. if (changed & IEEE80211_CONF_CHANGE_IDLE) {
  1040. sc->ps_idle = !!(conf->flags & IEEE80211_CONF_IDLE);
  1041. if (sc->ps_idle) {
  1042. ath_cancel_work(sc);
  1043. ath9k_stop_btcoex(sc);
  1044. } else {
  1045. ath9k_start_btcoex(sc);
  1046. /*
  1047. * The chip needs a reset to properly wake up from
  1048. * full sleep
  1049. */
  1050. reset_channel = ah->chip_fullsleep;
  1051. }
  1052. }
  1053. /*
  1054. * We just prepare to enable PS. We have to wait until our AP has
  1055. * ACK'd our null data frame to disable RX otherwise we'll ignore
  1056. * those ACKs and end up retransmitting the same null data frames.
  1057. * IEEE80211_CONF_CHANGE_PS is only passed by mac80211 for STA mode.
  1058. */
  1059. if (changed & IEEE80211_CONF_CHANGE_PS) {
  1060. unsigned long flags;
  1061. spin_lock_irqsave(&sc->sc_pm_lock, flags);
  1062. if (conf->flags & IEEE80211_CONF_PS)
  1063. ath9k_enable_ps(sc);
  1064. else
  1065. ath9k_disable_ps(sc);
  1066. spin_unlock_irqrestore(&sc->sc_pm_lock, flags);
  1067. }
  1068. if (changed & IEEE80211_CONF_CHANGE_MONITOR) {
  1069. if (conf->flags & IEEE80211_CONF_MONITOR) {
  1070. ath_dbg(common, CONFIG, "Monitor mode is enabled\n");
  1071. sc->sc_ah->is_monitoring = true;
  1072. } else {
  1073. ath_dbg(common, CONFIG, "Monitor mode is disabled\n");
  1074. sc->sc_ah->is_monitoring = false;
  1075. }
  1076. }
  1077. if ((changed & IEEE80211_CONF_CHANGE_CHANNEL) || reset_channel) {
  1078. if (ath_set_channel(sc, &hw->conf.chandef) < 0) {
  1079. ath_err(common, "Unable to set channel\n");
  1080. mutex_unlock(&sc->mutex);
  1081. ath9k_ps_restore(sc);
  1082. return -EINVAL;
  1083. }
  1084. }
  1085. if (changed & IEEE80211_CONF_CHANGE_POWER) {
  1086. ath_dbg(common, CONFIG, "Set power: %d\n", conf->power_level);
  1087. sc->config.txpowlimit = 2 * conf->power_level;
  1088. ath9k_cmn_update_txpow(ah, sc->curtxpow,
  1089. sc->config.txpowlimit, &sc->curtxpow);
  1090. }
  1091. mutex_unlock(&sc->mutex);
  1092. ath9k_ps_restore(sc);
  1093. return 0;
  1094. }
  1095. #define SUPPORTED_FILTERS \
  1096. (FIF_PROMISC_IN_BSS | \
  1097. FIF_ALLMULTI | \
  1098. FIF_CONTROL | \
  1099. FIF_PSPOLL | \
  1100. FIF_OTHER_BSS | \
  1101. FIF_BCN_PRBRESP_PROMISC | \
  1102. FIF_PROBE_REQ | \
  1103. FIF_FCSFAIL)
  1104. /* FIXME: sc->sc_full_reset ? */
  1105. static void ath9k_configure_filter(struct ieee80211_hw *hw,
  1106. unsigned int changed_flags,
  1107. unsigned int *total_flags,
  1108. u64 multicast)
  1109. {
  1110. struct ath_softc *sc = hw->priv;
  1111. u32 rfilt;
  1112. changed_flags &= SUPPORTED_FILTERS;
  1113. *total_flags &= SUPPORTED_FILTERS;
  1114. sc->rx.rxfilter = *total_flags;
  1115. ath9k_ps_wakeup(sc);
  1116. rfilt = ath_calcrxfilter(sc);
  1117. ath9k_hw_setrxfilter(sc->sc_ah, rfilt);
  1118. ath9k_ps_restore(sc);
  1119. ath_dbg(ath9k_hw_common(sc->sc_ah), CONFIG, "Set HW RX filter: 0x%x\n",
  1120. rfilt);
  1121. }
  1122. static int ath9k_sta_add(struct ieee80211_hw *hw,
  1123. struct ieee80211_vif *vif,
  1124. struct ieee80211_sta *sta)
  1125. {
  1126. struct ath_softc *sc = hw->priv;
  1127. struct ath_common *common = ath9k_hw_common(sc->sc_ah);
  1128. struct ath_node *an = (struct ath_node *) sta->drv_priv;
  1129. struct ieee80211_key_conf ps_key = { };
  1130. int key;
  1131. ath_node_attach(sc, sta, vif);
  1132. if (vif->type != NL80211_IFTYPE_AP &&
  1133. vif->type != NL80211_IFTYPE_AP_VLAN)
  1134. return 0;
  1135. key = ath_key_config(common, vif, sta, &ps_key);
  1136. if (key > 0)
  1137. an->ps_key = key;
  1138. return 0;
  1139. }
  1140. static void ath9k_del_ps_key(struct ath_softc *sc,
  1141. struct ieee80211_vif *vif,
  1142. struct ieee80211_sta *sta)
  1143. {
  1144. struct ath_common *common = ath9k_hw_common(sc->sc_ah);
  1145. struct ath_node *an = (struct ath_node *) sta->drv_priv;
  1146. struct ieee80211_key_conf ps_key = { .hw_key_idx = an->ps_key };
  1147. if (!an->ps_key)
  1148. return;
  1149. ath_key_delete(common, &ps_key);
  1150. an->ps_key = 0;
  1151. }
  1152. static int ath9k_sta_remove(struct ieee80211_hw *hw,
  1153. struct ieee80211_vif *vif,
  1154. struct ieee80211_sta *sta)
  1155. {
  1156. struct ath_softc *sc = hw->priv;
  1157. ath9k_del_ps_key(sc, vif, sta);
  1158. ath_node_detach(sc, sta);
  1159. return 0;
  1160. }
  1161. static void ath9k_sta_notify(struct ieee80211_hw *hw,
  1162. struct ieee80211_vif *vif,
  1163. enum sta_notify_cmd cmd,
  1164. struct ieee80211_sta *sta)
  1165. {
  1166. struct ath_softc *sc = hw->priv;
  1167. struct ath_node *an = (struct ath_node *) sta->drv_priv;
  1168. switch (cmd) {
  1169. case STA_NOTIFY_SLEEP:
  1170. an->sleeping = true;
  1171. ath_tx_aggr_sleep(sta, sc, an);
  1172. break;
  1173. case STA_NOTIFY_AWAKE:
  1174. an->sleeping = false;
  1175. ath_tx_aggr_wakeup(sc, an);
  1176. break;
  1177. }
  1178. }
  1179. static int ath9k_conf_tx(struct ieee80211_hw *hw,
  1180. struct ieee80211_vif *vif, u16 queue,
  1181. const struct ieee80211_tx_queue_params *params)
  1182. {
  1183. struct ath_softc *sc = hw->priv;
  1184. struct ath_common *common = ath9k_hw_common(sc->sc_ah);
  1185. struct ath_txq *txq;
  1186. struct ath9k_tx_queue_info qi;
  1187. int ret = 0;
  1188. if (queue >= IEEE80211_NUM_ACS)
  1189. return 0;
  1190. txq = sc->tx.txq_map[queue];
  1191. ath9k_ps_wakeup(sc);
  1192. mutex_lock(&sc->mutex);
  1193. memset(&qi, 0, sizeof(struct ath9k_tx_queue_info));
  1194. qi.tqi_aifs = params->aifs;
  1195. qi.tqi_cwmin = params->cw_min;
  1196. qi.tqi_cwmax = params->cw_max;
  1197. qi.tqi_burstTime = params->txop * 32;
  1198. ath_dbg(common, CONFIG,
  1199. "Configure tx [queue/halq] [%d/%d], aifs: %d, cw_min: %d, cw_max: %d, txop: %d\n",
  1200. queue, txq->axq_qnum, params->aifs, params->cw_min,
  1201. params->cw_max, params->txop);
  1202. ath_update_max_aggr_framelen(sc, queue, qi.tqi_burstTime);
  1203. ret = ath_txq_update(sc, txq->axq_qnum, &qi);
  1204. if (ret)
  1205. ath_err(common, "TXQ Update failed\n");
  1206. mutex_unlock(&sc->mutex);
  1207. ath9k_ps_restore(sc);
  1208. return ret;
  1209. }
  1210. static int ath9k_set_key(struct ieee80211_hw *hw,
  1211. enum set_key_cmd cmd,
  1212. struct ieee80211_vif *vif,
  1213. struct ieee80211_sta *sta,
  1214. struct ieee80211_key_conf *key)
  1215. {
  1216. struct ath_softc *sc = hw->priv;
  1217. struct ath_common *common = ath9k_hw_common(sc->sc_ah);
  1218. int ret = 0;
  1219. if (ath9k_modparam_nohwcrypt)
  1220. return -ENOSPC;
  1221. if ((vif->type == NL80211_IFTYPE_ADHOC ||
  1222. vif->type == NL80211_IFTYPE_MESH_POINT) &&
  1223. (key->cipher == WLAN_CIPHER_SUITE_TKIP ||
  1224. key->cipher == WLAN_CIPHER_SUITE_CCMP) &&
  1225. !(key->flags & IEEE80211_KEY_FLAG_PAIRWISE)) {
  1226. /*
  1227. * For now, disable hw crypto for the RSN IBSS group keys. This
  1228. * could be optimized in the future to use a modified key cache
  1229. * design to support per-STA RX GTK, but until that gets
  1230. * implemented, use of software crypto for group addressed
  1231. * frames is a acceptable to allow RSN IBSS to be used.
  1232. */
  1233. return -EOPNOTSUPP;
  1234. }
  1235. mutex_lock(&sc->mutex);
  1236. ath9k_ps_wakeup(sc);
  1237. ath_dbg(common, CONFIG, "Set HW Key\n");
  1238. switch (cmd) {
  1239. case SET_KEY:
  1240. if (sta)
  1241. ath9k_del_ps_key(sc, vif, sta);
  1242. ret = ath_key_config(common, vif, sta, key);
  1243. if (ret >= 0) {
  1244. key->hw_key_idx = ret;
  1245. /* push IV and Michael MIC generation to stack */
  1246. key->flags |= IEEE80211_KEY_FLAG_GENERATE_IV;
  1247. if (key->cipher == WLAN_CIPHER_SUITE_TKIP)
  1248. key->flags |= IEEE80211_KEY_FLAG_GENERATE_MMIC;
  1249. if (sc->sc_ah->sw_mgmt_crypto &&
  1250. key->cipher == WLAN_CIPHER_SUITE_CCMP)
  1251. key->flags |= IEEE80211_KEY_FLAG_SW_MGMT_TX;
  1252. ret = 0;
  1253. }
  1254. break;
  1255. case DISABLE_KEY:
  1256. ath_key_delete(common, key);
  1257. break;
  1258. default:
  1259. ret = -EINVAL;
  1260. }
  1261. ath9k_ps_restore(sc);
  1262. mutex_unlock(&sc->mutex);
  1263. return ret;
  1264. }
  1265. static void ath9k_set_assoc_state(struct ath_softc *sc,
  1266. struct ieee80211_vif *vif)
  1267. {
  1268. struct ath_common *common = ath9k_hw_common(sc->sc_ah);
  1269. struct ath_vif *avp = (void *)vif->drv_priv;
  1270. struct ieee80211_bss_conf *bss_conf = &vif->bss_conf;
  1271. unsigned long flags;
  1272. set_bit(SC_OP_PRIM_STA_VIF, &sc->sc_flags);
  1273. avp->primary_sta_vif = true;
  1274. /*
  1275. * Set the AID, BSSID and do beacon-sync only when
  1276. * the HW opmode is STATION.
  1277. *
  1278. * But the primary bit is set above in any case.
  1279. */
  1280. if (sc->sc_ah->opmode != NL80211_IFTYPE_STATION)
  1281. return;
  1282. memcpy(common->curbssid, bss_conf->bssid, ETH_ALEN);
  1283. common->curaid = bss_conf->aid;
  1284. ath9k_hw_write_associd(sc->sc_ah);
  1285. sc->last_rssi = ATH_RSSI_DUMMY_MARKER;
  1286. sc->sc_ah->stats.avgbrssi = ATH_RSSI_DUMMY_MARKER;
  1287. spin_lock_irqsave(&sc->sc_pm_lock, flags);
  1288. sc->ps_flags |= PS_BEACON_SYNC | PS_WAIT_FOR_BEACON;
  1289. spin_unlock_irqrestore(&sc->sc_pm_lock, flags);
  1290. if (ath9k_hw_mci_is_enabled(sc->sc_ah))
  1291. ath9k_mci_update_wlan_channels(sc, false);
  1292. ath_dbg(common, CONFIG,
  1293. "Primary Station interface: %pM, BSSID: %pM\n",
  1294. vif->addr, common->curbssid);
  1295. }
  1296. static void ath9k_bss_assoc_iter(void *data, u8 *mac, struct ieee80211_vif *vif)
  1297. {
  1298. struct ath_softc *sc = data;
  1299. struct ieee80211_bss_conf *bss_conf = &vif->bss_conf;
  1300. if (test_bit(SC_OP_PRIM_STA_VIF, &sc->sc_flags))
  1301. return;
  1302. if (bss_conf->assoc)
  1303. ath9k_set_assoc_state(sc, vif);
  1304. }
  1305. static void ath9k_bss_info_changed(struct ieee80211_hw *hw,
  1306. struct ieee80211_vif *vif,
  1307. struct ieee80211_bss_conf *bss_conf,
  1308. u32 changed)
  1309. {
  1310. #define CHECK_ANI \
  1311. (BSS_CHANGED_ASSOC | \
  1312. BSS_CHANGED_IBSS | \
  1313. BSS_CHANGED_BEACON_ENABLED)
  1314. struct ath_softc *sc = hw->priv;
  1315. struct ath_hw *ah = sc->sc_ah;
  1316. struct ath_common *common = ath9k_hw_common(ah);
  1317. struct ath_vif *avp = (void *)vif->drv_priv;
  1318. int slottime;
  1319. ath9k_ps_wakeup(sc);
  1320. mutex_lock(&sc->mutex);
  1321. if (changed & BSS_CHANGED_ASSOC) {
  1322. ath_dbg(common, CONFIG, "BSSID %pM Changed ASSOC %d\n",
  1323. bss_conf->bssid, bss_conf->assoc);
  1324. if (avp->primary_sta_vif && !bss_conf->assoc) {
  1325. clear_bit(SC_OP_PRIM_STA_VIF, &sc->sc_flags);
  1326. avp->primary_sta_vif = false;
  1327. if (ah->opmode == NL80211_IFTYPE_STATION)
  1328. clear_bit(SC_OP_BEACONS, &sc->sc_flags);
  1329. }
  1330. ieee80211_iterate_active_interfaces_atomic(
  1331. sc->hw, IEEE80211_IFACE_ITER_RESUME_ALL,
  1332. ath9k_bss_assoc_iter, sc);
  1333. if (!test_bit(SC_OP_PRIM_STA_VIF, &sc->sc_flags) &&
  1334. ah->opmode == NL80211_IFTYPE_STATION) {
  1335. memset(common->curbssid, 0, ETH_ALEN);
  1336. common->curaid = 0;
  1337. ath9k_hw_write_associd(sc->sc_ah);
  1338. if (ath9k_hw_mci_is_enabled(sc->sc_ah))
  1339. ath9k_mci_update_wlan_channels(sc, true);
  1340. }
  1341. }
  1342. if (changed & BSS_CHANGED_IBSS) {
  1343. memcpy(common->curbssid, bss_conf->bssid, ETH_ALEN);
  1344. common->curaid = bss_conf->aid;
  1345. ath9k_hw_write_associd(sc->sc_ah);
  1346. }
  1347. if ((changed & BSS_CHANGED_BEACON_ENABLED) ||
  1348. (changed & BSS_CHANGED_BEACON_INT)) {
  1349. if (ah->opmode == NL80211_IFTYPE_AP &&
  1350. bss_conf->enable_beacon)
  1351. ath9k_set_tsfadjust(sc, vif);
  1352. if (ath9k_allow_beacon_config(sc, vif))
  1353. ath9k_beacon_config(sc, vif, changed);
  1354. }
  1355. if (changed & BSS_CHANGED_ERP_SLOT) {
  1356. if (bss_conf->use_short_slot)
  1357. slottime = 9;
  1358. else
  1359. slottime = 20;
  1360. if (vif->type == NL80211_IFTYPE_AP) {
  1361. /*
  1362. * Defer update, so that connected stations can adjust
  1363. * their settings at the same time.
  1364. * See beacon.c for more details
  1365. */
  1366. sc->beacon.slottime = slottime;
  1367. sc->beacon.updateslot = UPDATE;
  1368. } else {
  1369. ah->slottime = slottime;
  1370. ath9k_hw_init_global_settings(ah);
  1371. }
  1372. }
  1373. if (changed & CHECK_ANI)
  1374. ath_check_ani(sc);
  1375. mutex_unlock(&sc->mutex);
  1376. ath9k_ps_restore(sc);
  1377. #undef CHECK_ANI
  1378. }
  1379. static u64 ath9k_get_tsf(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
  1380. {
  1381. struct ath_softc *sc = hw->priv;
  1382. u64 tsf;
  1383. mutex_lock(&sc->mutex);
  1384. ath9k_ps_wakeup(sc);
  1385. tsf = ath9k_hw_gettsf64(sc->sc_ah);
  1386. ath9k_ps_restore(sc);
  1387. mutex_unlock(&sc->mutex);
  1388. return tsf;
  1389. }
  1390. static void ath9k_set_tsf(struct ieee80211_hw *hw,
  1391. struct ieee80211_vif *vif,
  1392. u64 tsf)
  1393. {
  1394. struct ath_softc *sc = hw->priv;
  1395. mutex_lock(&sc->mutex);
  1396. ath9k_ps_wakeup(sc);
  1397. ath9k_hw_settsf64(sc->sc_ah, tsf);
  1398. ath9k_ps_restore(sc);
  1399. mutex_unlock(&sc->mutex);
  1400. }
  1401. static void ath9k_reset_tsf(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
  1402. {
  1403. struct ath_softc *sc = hw->priv;
  1404. mutex_lock(&sc->mutex);
  1405. ath9k_ps_wakeup(sc);
  1406. ath9k_hw_reset_tsf(sc->sc_ah);
  1407. ath9k_ps_restore(sc);
  1408. mutex_unlock(&sc->mutex);
  1409. }
  1410. static int ath9k_ampdu_action(struct ieee80211_hw *hw,
  1411. struct ieee80211_vif *vif,
  1412. enum ieee80211_ampdu_mlme_action action,
  1413. struct ieee80211_sta *sta,
  1414. u16 tid, u16 *ssn, u8 buf_size)
  1415. {
  1416. struct ath_softc *sc = hw->priv;
  1417. bool flush = false;
  1418. int ret = 0;
  1419. mutex_lock(&sc->mutex);
  1420. switch (action) {
  1421. case IEEE80211_AMPDU_RX_START:
  1422. break;
  1423. case IEEE80211_AMPDU_RX_STOP:
  1424. break;
  1425. case IEEE80211_AMPDU_TX_START:
  1426. ath9k_ps_wakeup(sc);
  1427. ret = ath_tx_aggr_start(sc, sta, tid, ssn);
  1428. if (!ret)
  1429. ieee80211_start_tx_ba_cb_irqsafe(vif, sta->addr, tid);
  1430. ath9k_ps_restore(sc);
  1431. break;
  1432. case IEEE80211_AMPDU_TX_STOP_FLUSH:
  1433. case IEEE80211_AMPDU_TX_STOP_FLUSH_CONT:
  1434. flush = true;
  1435. case IEEE80211_AMPDU_TX_STOP_CONT:
  1436. ath9k_ps_wakeup(sc);
  1437. ath_tx_aggr_stop(sc, sta, tid);
  1438. if (!flush)
  1439. ieee80211_stop_tx_ba_cb_irqsafe(vif, sta->addr, tid);
  1440. ath9k_ps_restore(sc);
  1441. break;
  1442. case IEEE80211_AMPDU_TX_OPERATIONAL:
  1443. ath9k_ps_wakeup(sc);
  1444. ath_tx_aggr_resume(sc, sta, tid);
  1445. ath9k_ps_restore(sc);
  1446. break;
  1447. default:
  1448. ath_err(ath9k_hw_common(sc->sc_ah), "Unknown AMPDU action\n");
  1449. }
  1450. mutex_unlock(&sc->mutex);
  1451. return ret;
  1452. }
  1453. static int ath9k_get_survey(struct ieee80211_hw *hw, int idx,
  1454. struct survey_info *survey)
  1455. {
  1456. struct ath_softc *sc = hw->priv;
  1457. struct ath_common *common = ath9k_hw_common(sc->sc_ah);
  1458. struct ieee80211_supported_band *sband;
  1459. struct ieee80211_channel *chan;
  1460. unsigned long flags;
  1461. int pos;
  1462. if (config_enabled(CONFIG_ATH9K_TX99))
  1463. return -EOPNOTSUPP;
  1464. spin_lock_irqsave(&common->cc_lock, flags);
  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_irqrestore(&common->cc_lock, flags);
  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_irqrestore(&common->cc_lock, flags);
  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. };