main.c 61 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511
  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 u8 parse_mpdudensity(u8 mpdudensity)
  21. {
  22. /*
  23. * 802.11n D2.0 defined values for "Minimum MPDU Start Spacing":
  24. * 0 for no restriction
  25. * 1 for 1/4 us
  26. * 2 for 1/2 us
  27. * 3 for 1 us
  28. * 4 for 2 us
  29. * 5 for 4 us
  30. * 6 for 8 us
  31. * 7 for 16 us
  32. */
  33. switch (mpdudensity) {
  34. case 0:
  35. return 0;
  36. case 1:
  37. case 2:
  38. case 3:
  39. /* Our lower layer calculations limit our precision to
  40. 1 microsecond */
  41. return 1;
  42. case 4:
  43. return 2;
  44. case 5:
  45. return 4;
  46. case 6:
  47. return 8;
  48. case 7:
  49. return 16;
  50. default:
  51. return 0;
  52. }
  53. }
  54. static bool ath9k_has_pending_frames(struct ath_softc *sc, struct ath_txq *txq)
  55. {
  56. bool pending = false;
  57. spin_lock_bh(&txq->axq_lock);
  58. if (txq->axq_depth || !list_empty(&txq->axq_acq))
  59. pending = true;
  60. spin_unlock_bh(&txq->axq_lock);
  61. return pending;
  62. }
  63. static bool ath9k_setpower(struct ath_softc *sc, enum ath9k_power_mode mode)
  64. {
  65. unsigned long flags;
  66. bool ret;
  67. spin_lock_irqsave(&sc->sc_pm_lock, flags);
  68. ret = ath9k_hw_setpower(sc->sc_ah, mode);
  69. spin_unlock_irqrestore(&sc->sc_pm_lock, flags);
  70. return ret;
  71. }
  72. void ath9k_ps_wakeup(struct ath_softc *sc)
  73. {
  74. struct ath_common *common = ath9k_hw_common(sc->sc_ah);
  75. unsigned long flags;
  76. enum ath9k_power_mode power_mode;
  77. spin_lock_irqsave(&sc->sc_pm_lock, flags);
  78. if (++sc->ps_usecount != 1)
  79. goto unlock;
  80. power_mode = sc->sc_ah->power_mode;
  81. ath9k_hw_setpower(sc->sc_ah, ATH9K_PM_AWAKE);
  82. /*
  83. * While the hardware is asleep, the cycle counters contain no
  84. * useful data. Better clear them now so that they don't mess up
  85. * survey data results.
  86. */
  87. if (power_mode != ATH9K_PM_AWAKE) {
  88. spin_lock(&common->cc_lock);
  89. ath_hw_cycle_counters_update(common);
  90. memset(&common->cc_survey, 0, sizeof(common->cc_survey));
  91. spin_unlock(&common->cc_lock);
  92. }
  93. unlock:
  94. spin_unlock_irqrestore(&sc->sc_pm_lock, flags);
  95. }
  96. void ath9k_ps_restore(struct ath_softc *sc)
  97. {
  98. struct ath_common *common = ath9k_hw_common(sc->sc_ah);
  99. enum ath9k_power_mode mode;
  100. unsigned long flags;
  101. spin_lock_irqsave(&sc->sc_pm_lock, flags);
  102. if (--sc->ps_usecount != 0)
  103. goto unlock;
  104. if (sc->ps_idle)
  105. mode = ATH9K_PM_FULL_SLEEP;
  106. else if (sc->ps_enabled &&
  107. !(sc->ps_flags & (PS_WAIT_FOR_BEACON |
  108. PS_WAIT_FOR_CAB |
  109. PS_WAIT_FOR_PSPOLL_DATA |
  110. PS_WAIT_FOR_TX_ACK)))
  111. mode = ATH9K_PM_NETWORK_SLEEP;
  112. else
  113. goto unlock;
  114. spin_lock(&common->cc_lock);
  115. ath_hw_cycle_counters_update(common);
  116. spin_unlock(&common->cc_lock);
  117. ath9k_hw_setpower(sc->sc_ah, mode);
  118. unlock:
  119. spin_unlock_irqrestore(&sc->sc_pm_lock, flags);
  120. }
  121. void ath_start_ani(struct ath_common *common)
  122. {
  123. struct ath_hw *ah = common->ah;
  124. unsigned long timestamp = jiffies_to_msecs(jiffies);
  125. struct ath_softc *sc = (struct ath_softc *) common->priv;
  126. if (!(sc->sc_flags & SC_OP_ANI_RUN))
  127. return;
  128. if (sc->sc_flags & SC_OP_OFFCHANNEL)
  129. return;
  130. common->ani.longcal_timer = timestamp;
  131. common->ani.shortcal_timer = timestamp;
  132. common->ani.checkani_timer = timestamp;
  133. mod_timer(&common->ani.timer,
  134. jiffies +
  135. msecs_to_jiffies((u32)ah->config.ani_poll_interval));
  136. }
  137. static void ath_update_survey_nf(struct ath_softc *sc, int channel)
  138. {
  139. struct ath_hw *ah = sc->sc_ah;
  140. struct ath9k_channel *chan = &ah->channels[channel];
  141. struct survey_info *survey = &sc->survey[channel];
  142. if (chan->noisefloor) {
  143. survey->filled |= SURVEY_INFO_NOISE_DBM;
  144. survey->noise = ath9k_hw_getchan_noise(ah, chan);
  145. }
  146. }
  147. /*
  148. * Updates the survey statistics and returns the busy time since last
  149. * update in %, if the measurement duration was long enough for the
  150. * result to be useful, -1 otherwise.
  151. */
  152. static int ath_update_survey_stats(struct ath_softc *sc)
  153. {
  154. struct ath_hw *ah = sc->sc_ah;
  155. struct ath_common *common = ath9k_hw_common(ah);
  156. int pos = ah->curchan - &ah->channels[0];
  157. struct survey_info *survey = &sc->survey[pos];
  158. struct ath_cycle_counters *cc = &common->cc_survey;
  159. unsigned int div = common->clockrate * 1000;
  160. int ret = 0;
  161. if (!ah->curchan)
  162. return -1;
  163. if (ah->power_mode == ATH9K_PM_AWAKE)
  164. ath_hw_cycle_counters_update(common);
  165. if (cc->cycles > 0) {
  166. survey->filled |= SURVEY_INFO_CHANNEL_TIME |
  167. SURVEY_INFO_CHANNEL_TIME_BUSY |
  168. SURVEY_INFO_CHANNEL_TIME_RX |
  169. SURVEY_INFO_CHANNEL_TIME_TX;
  170. survey->channel_time += cc->cycles / div;
  171. survey->channel_time_busy += cc->rx_busy / div;
  172. survey->channel_time_rx += cc->rx_frame / div;
  173. survey->channel_time_tx += cc->tx_frame / div;
  174. }
  175. if (cc->cycles < div)
  176. return -1;
  177. if (cc->cycles > 0)
  178. ret = cc->rx_busy * 100 / cc->cycles;
  179. memset(cc, 0, sizeof(*cc));
  180. ath_update_survey_nf(sc, pos);
  181. return ret;
  182. }
  183. static void __ath_cancel_work(struct ath_softc *sc)
  184. {
  185. cancel_work_sync(&sc->paprd_work);
  186. cancel_work_sync(&sc->hw_check_work);
  187. cancel_delayed_work_sync(&sc->tx_complete_work);
  188. cancel_delayed_work_sync(&sc->hw_pll_work);
  189. }
  190. static void ath_cancel_work(struct ath_softc *sc)
  191. {
  192. __ath_cancel_work(sc);
  193. cancel_work_sync(&sc->hw_reset_work);
  194. }
  195. static bool ath_prepare_reset(struct ath_softc *sc, bool retry_tx, bool flush)
  196. {
  197. struct ath_hw *ah = sc->sc_ah;
  198. struct ath_common *common = ath9k_hw_common(ah);
  199. bool ret;
  200. ieee80211_stop_queues(sc->hw);
  201. sc->hw_busy_count = 0;
  202. del_timer_sync(&common->ani.timer);
  203. ath9k_debug_samp_bb_mac(sc);
  204. ath9k_hw_disable_interrupts(ah);
  205. ret = ath_drain_all_txq(sc, retry_tx);
  206. if (!ath_stoprecv(sc))
  207. ret = false;
  208. if (!flush) {
  209. if (ah->caps.hw_caps & ATH9K_HW_CAP_EDMA)
  210. ath_rx_tasklet(sc, 1, true);
  211. ath_rx_tasklet(sc, 1, false);
  212. } else {
  213. ath_flushrecv(sc);
  214. }
  215. return ret;
  216. }
  217. static bool ath_complete_reset(struct ath_softc *sc, bool start)
  218. {
  219. struct ath_hw *ah = sc->sc_ah;
  220. struct ath_common *common = ath9k_hw_common(ah);
  221. if (ath_startrecv(sc) != 0) {
  222. ath_err(common, "Unable to restart recv logic\n");
  223. return false;
  224. }
  225. ath9k_cmn_update_txpow(ah, sc->curtxpow,
  226. sc->config.txpowlimit, &sc->curtxpow);
  227. ath9k_hw_set_interrupts(ah);
  228. ath9k_hw_enable_interrupts(ah);
  229. if (!(sc->sc_flags & (SC_OP_OFFCHANNEL)) && start) {
  230. if (sc->sc_flags & SC_OP_BEACONS)
  231. ath_set_beacon(sc);
  232. ieee80211_queue_delayed_work(sc->hw, &sc->tx_complete_work, 0);
  233. ieee80211_queue_delayed_work(sc->hw, &sc->hw_pll_work, HZ/2);
  234. if (!common->disable_ani)
  235. ath_start_ani(common);
  236. }
  237. if (ath9k_hw_ops(ah)->antdiv_comb_conf_get && sc->ant_rx != 3) {
  238. struct ath_hw_antcomb_conf div_ant_conf;
  239. u8 lna_conf;
  240. ath9k_hw_antdiv_comb_conf_get(ah, &div_ant_conf);
  241. if (sc->ant_rx == 1)
  242. lna_conf = ATH_ANT_DIV_COMB_LNA1;
  243. else
  244. lna_conf = ATH_ANT_DIV_COMB_LNA2;
  245. div_ant_conf.main_lna_conf = lna_conf;
  246. div_ant_conf.alt_lna_conf = lna_conf;
  247. ath9k_hw_antdiv_comb_conf_set(ah, &div_ant_conf);
  248. }
  249. ieee80211_wake_queues(sc->hw);
  250. return true;
  251. }
  252. static int ath_reset_internal(struct ath_softc *sc, struct ath9k_channel *hchan,
  253. bool retry_tx)
  254. {
  255. struct ath_hw *ah = sc->sc_ah;
  256. struct ath_common *common = ath9k_hw_common(ah);
  257. struct ath9k_hw_cal_data *caldata = NULL;
  258. bool fastcc = true;
  259. bool flush = false;
  260. int r;
  261. __ath_cancel_work(sc);
  262. spin_lock_bh(&sc->sc_pcu_lock);
  263. if (!(sc->sc_flags & SC_OP_OFFCHANNEL)) {
  264. fastcc = false;
  265. caldata = &sc->caldata;
  266. }
  267. if (!hchan) {
  268. fastcc = false;
  269. flush = true;
  270. hchan = ah->curchan;
  271. }
  272. if (fastcc && !ath9k_hw_check_alive(ah))
  273. fastcc = false;
  274. if (!ath_prepare_reset(sc, retry_tx, flush))
  275. fastcc = false;
  276. ath_dbg(common, ATH_DBG_CONFIG,
  277. "Reset to %u MHz, HT40: %d fastcc: %d\n",
  278. hchan->channel, !!(hchan->channelFlags & (CHANNEL_HT40MINUS |
  279. CHANNEL_HT40PLUS)),
  280. fastcc);
  281. r = ath9k_hw_reset(ah, hchan, caldata, fastcc);
  282. if (r) {
  283. ath_err(common,
  284. "Unable to reset channel, reset status %d\n", r);
  285. goto out;
  286. }
  287. if (!ath_complete_reset(sc, true))
  288. r = -EIO;
  289. out:
  290. spin_unlock_bh(&sc->sc_pcu_lock);
  291. return r;
  292. }
  293. /*
  294. * Set/change channels. If the channel is really being changed, it's done
  295. * by reseting the chip. To accomplish this we must first cleanup any pending
  296. * DMA, then restart stuff.
  297. */
  298. static int ath_set_channel(struct ath_softc *sc, struct ieee80211_hw *hw,
  299. struct ath9k_channel *hchan)
  300. {
  301. int r;
  302. if (sc->sc_flags & SC_OP_INVALID)
  303. return -EIO;
  304. ath9k_ps_wakeup(sc);
  305. r = ath_reset_internal(sc, hchan, false);
  306. ath9k_ps_restore(sc);
  307. return r;
  308. }
  309. static void ath_paprd_activate(struct ath_softc *sc)
  310. {
  311. struct ath_hw *ah = sc->sc_ah;
  312. struct ath9k_hw_cal_data *caldata = ah->caldata;
  313. int chain;
  314. if (!caldata || !caldata->paprd_done)
  315. return;
  316. ath9k_ps_wakeup(sc);
  317. ar9003_paprd_enable(ah, false);
  318. for (chain = 0; chain < AR9300_MAX_CHAINS; chain++) {
  319. if (!(ah->txchainmask & BIT(chain)))
  320. continue;
  321. ar9003_paprd_populate_single_table(ah, caldata, chain);
  322. }
  323. ar9003_paprd_enable(ah, true);
  324. ath9k_ps_restore(sc);
  325. }
  326. static bool ath_paprd_send_frame(struct ath_softc *sc, struct sk_buff *skb, int chain)
  327. {
  328. struct ieee80211_hw *hw = sc->hw;
  329. struct ieee80211_tx_info *tx_info = IEEE80211_SKB_CB(skb);
  330. struct ath_hw *ah = sc->sc_ah;
  331. struct ath_common *common = ath9k_hw_common(ah);
  332. struct ath_tx_control txctl;
  333. int time_left;
  334. memset(&txctl, 0, sizeof(txctl));
  335. txctl.txq = sc->tx.txq_map[WME_AC_BE];
  336. memset(tx_info, 0, sizeof(*tx_info));
  337. tx_info->band = hw->conf.channel->band;
  338. tx_info->flags |= IEEE80211_TX_CTL_NO_ACK;
  339. tx_info->control.rates[0].idx = 0;
  340. tx_info->control.rates[0].count = 1;
  341. tx_info->control.rates[0].flags = IEEE80211_TX_RC_MCS;
  342. tx_info->control.rates[1].idx = -1;
  343. init_completion(&sc->paprd_complete);
  344. txctl.paprd = BIT(chain);
  345. if (ath_tx_start(hw, skb, &txctl) != 0) {
  346. ath_dbg(common, ATH_DBG_CALIBRATE, "PAPRD TX failed\n");
  347. dev_kfree_skb_any(skb);
  348. return false;
  349. }
  350. time_left = wait_for_completion_timeout(&sc->paprd_complete,
  351. msecs_to_jiffies(ATH_PAPRD_TIMEOUT));
  352. if (!time_left)
  353. ath_dbg(common, ATH_DBG_CALIBRATE,
  354. "Timeout waiting for paprd training on TX chain %d\n",
  355. chain);
  356. return !!time_left;
  357. }
  358. void ath_paprd_calibrate(struct work_struct *work)
  359. {
  360. struct ath_softc *sc = container_of(work, struct ath_softc, paprd_work);
  361. struct ieee80211_hw *hw = sc->hw;
  362. struct ath_hw *ah = sc->sc_ah;
  363. struct ieee80211_hdr *hdr;
  364. struct sk_buff *skb = NULL;
  365. struct ath9k_hw_cal_data *caldata = ah->caldata;
  366. struct ath_common *common = ath9k_hw_common(ah);
  367. int ftype;
  368. int chain_ok = 0;
  369. int chain;
  370. int len = 1800;
  371. if (!caldata)
  372. return;
  373. ath9k_ps_wakeup(sc);
  374. if (ar9003_paprd_init_table(ah) < 0)
  375. goto fail_paprd;
  376. skb = alloc_skb(len, GFP_KERNEL);
  377. if (!skb)
  378. goto fail_paprd;
  379. skb_put(skb, len);
  380. memset(skb->data, 0, len);
  381. hdr = (struct ieee80211_hdr *)skb->data;
  382. ftype = IEEE80211_FTYPE_DATA | IEEE80211_STYPE_NULLFUNC;
  383. hdr->frame_control = cpu_to_le16(ftype);
  384. hdr->duration_id = cpu_to_le16(10);
  385. memcpy(hdr->addr1, hw->wiphy->perm_addr, ETH_ALEN);
  386. memcpy(hdr->addr2, hw->wiphy->perm_addr, ETH_ALEN);
  387. memcpy(hdr->addr3, hw->wiphy->perm_addr, ETH_ALEN);
  388. for (chain = 0; chain < AR9300_MAX_CHAINS; chain++) {
  389. if (!(ah->txchainmask & BIT(chain)))
  390. continue;
  391. chain_ok = 0;
  392. ath_dbg(common, ATH_DBG_CALIBRATE,
  393. "Sending PAPRD frame for thermal measurement "
  394. "on chain %d\n", chain);
  395. if (!ath_paprd_send_frame(sc, skb, chain))
  396. goto fail_paprd;
  397. ar9003_paprd_setup_gain_table(ah, chain);
  398. ath_dbg(common, ATH_DBG_CALIBRATE,
  399. "Sending PAPRD training frame on chain %d\n", chain);
  400. if (!ath_paprd_send_frame(sc, skb, chain))
  401. goto fail_paprd;
  402. if (!ar9003_paprd_is_done(ah)) {
  403. ath_dbg(common, ATH_DBG_CALIBRATE,
  404. "PAPRD not yet done on chain %d\n", chain);
  405. break;
  406. }
  407. if (ar9003_paprd_create_curve(ah, caldata, chain)) {
  408. ath_dbg(common, ATH_DBG_CALIBRATE,
  409. "PAPRD create curve failed on chain %d\n",
  410. chain);
  411. break;
  412. }
  413. chain_ok = 1;
  414. }
  415. kfree_skb(skb);
  416. if (chain_ok) {
  417. caldata->paprd_done = true;
  418. ath_paprd_activate(sc);
  419. }
  420. fail_paprd:
  421. ath9k_ps_restore(sc);
  422. }
  423. /*
  424. * This routine performs the periodic noise floor calibration function
  425. * that is used to adjust and optimize the chip performance. This
  426. * takes environmental changes (location, temperature) into account.
  427. * When the task is complete, it reschedules itself depending on the
  428. * appropriate interval that was calculated.
  429. */
  430. void ath_ani_calibrate(unsigned long data)
  431. {
  432. struct ath_softc *sc = (struct ath_softc *)data;
  433. struct ath_hw *ah = sc->sc_ah;
  434. struct ath_common *common = ath9k_hw_common(ah);
  435. bool longcal = false;
  436. bool shortcal = false;
  437. bool aniflag = false;
  438. unsigned int timestamp = jiffies_to_msecs(jiffies);
  439. u32 cal_interval, short_cal_interval, long_cal_interval;
  440. unsigned long flags;
  441. if (ah->caldata && ah->caldata->nfcal_interference)
  442. long_cal_interval = ATH_LONG_CALINTERVAL_INT;
  443. else
  444. long_cal_interval = ATH_LONG_CALINTERVAL;
  445. short_cal_interval = (ah->opmode == NL80211_IFTYPE_AP) ?
  446. ATH_AP_SHORT_CALINTERVAL : ATH_STA_SHORT_CALINTERVAL;
  447. /* Only calibrate if awake */
  448. if (sc->sc_ah->power_mode != ATH9K_PM_AWAKE)
  449. goto set_timer;
  450. ath9k_ps_wakeup(sc);
  451. /* Long calibration runs independently of short calibration. */
  452. if ((timestamp - common->ani.longcal_timer) >= long_cal_interval) {
  453. longcal = true;
  454. ath_dbg(common, ATH_DBG_ANI, "longcal @%lu\n", jiffies);
  455. common->ani.longcal_timer = timestamp;
  456. }
  457. /* Short calibration applies only while caldone is false */
  458. if (!common->ani.caldone) {
  459. if ((timestamp - common->ani.shortcal_timer) >= short_cal_interval) {
  460. shortcal = true;
  461. ath_dbg(common, ATH_DBG_ANI,
  462. "shortcal @%lu\n", jiffies);
  463. common->ani.shortcal_timer = timestamp;
  464. common->ani.resetcal_timer = timestamp;
  465. }
  466. } else {
  467. if ((timestamp - common->ani.resetcal_timer) >=
  468. ATH_RESTART_CALINTERVAL) {
  469. common->ani.caldone = ath9k_hw_reset_calvalid(ah);
  470. if (common->ani.caldone)
  471. common->ani.resetcal_timer = timestamp;
  472. }
  473. }
  474. /* Verify whether we must check ANI */
  475. if ((timestamp - common->ani.checkani_timer) >=
  476. ah->config.ani_poll_interval) {
  477. aniflag = true;
  478. common->ani.checkani_timer = timestamp;
  479. }
  480. /* Call ANI routine if necessary */
  481. if (aniflag) {
  482. spin_lock_irqsave(&common->cc_lock, flags);
  483. ath9k_hw_ani_monitor(ah, ah->curchan);
  484. ath_update_survey_stats(sc);
  485. spin_unlock_irqrestore(&common->cc_lock, flags);
  486. }
  487. /* Perform calibration if necessary */
  488. if (longcal || shortcal) {
  489. common->ani.caldone =
  490. ath9k_hw_calibrate(ah, ah->curchan,
  491. ah->rxchainmask, longcal);
  492. }
  493. ath9k_ps_restore(sc);
  494. set_timer:
  495. /*
  496. * Set timer interval based on previous results.
  497. * The interval must be the shortest necessary to satisfy ANI,
  498. * short calibration and long calibration.
  499. */
  500. ath9k_debug_samp_bb_mac(sc);
  501. cal_interval = ATH_LONG_CALINTERVAL;
  502. if (sc->sc_ah->config.enable_ani)
  503. cal_interval = min(cal_interval,
  504. (u32)ah->config.ani_poll_interval);
  505. if (!common->ani.caldone)
  506. cal_interval = min(cal_interval, (u32)short_cal_interval);
  507. mod_timer(&common->ani.timer, jiffies + msecs_to_jiffies(cal_interval));
  508. if ((sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_PAPRD) && ah->caldata) {
  509. if (!ah->caldata->paprd_done)
  510. ieee80211_queue_work(sc->hw, &sc->paprd_work);
  511. else if (!ah->paprd_table_write_done)
  512. ath_paprd_activate(sc);
  513. }
  514. }
  515. static void ath_node_attach(struct ath_softc *sc, struct ieee80211_sta *sta)
  516. {
  517. struct ath_node *an;
  518. an = (struct ath_node *)sta->drv_priv;
  519. #ifdef CONFIG_ATH9K_DEBUGFS
  520. spin_lock(&sc->nodes_lock);
  521. list_add(&an->list, &sc->nodes);
  522. spin_unlock(&sc->nodes_lock);
  523. an->sta = sta;
  524. #endif
  525. if (sc->sc_flags & SC_OP_TXAGGR) {
  526. ath_tx_node_init(sc, an);
  527. an->maxampdu = 1 << (IEEE80211_HT_MAX_AMPDU_FACTOR +
  528. sta->ht_cap.ampdu_factor);
  529. an->mpdudensity = parse_mpdudensity(sta->ht_cap.ampdu_density);
  530. }
  531. }
  532. static void ath_node_detach(struct ath_softc *sc, struct ieee80211_sta *sta)
  533. {
  534. struct ath_node *an = (struct ath_node *)sta->drv_priv;
  535. #ifdef CONFIG_ATH9K_DEBUGFS
  536. spin_lock(&sc->nodes_lock);
  537. list_del(&an->list);
  538. spin_unlock(&sc->nodes_lock);
  539. an->sta = NULL;
  540. #endif
  541. if (sc->sc_flags & SC_OP_TXAGGR)
  542. ath_tx_node_cleanup(sc, an);
  543. }
  544. void ath9k_tasklet(unsigned long data)
  545. {
  546. struct ath_softc *sc = (struct ath_softc *)data;
  547. struct ath_hw *ah = sc->sc_ah;
  548. struct ath_common *common = ath9k_hw_common(ah);
  549. u32 status = sc->intrstatus;
  550. u32 rxmask;
  551. ath9k_ps_wakeup(sc);
  552. spin_lock(&sc->sc_pcu_lock);
  553. if ((status & ATH9K_INT_FATAL) ||
  554. (status & ATH9K_INT_BB_WATCHDOG)) {
  555. #ifdef CONFIG_ATH9K_DEBUGFS
  556. enum ath_reset_type type;
  557. if (status & ATH9K_INT_FATAL)
  558. type = RESET_TYPE_FATAL_INT;
  559. else
  560. type = RESET_TYPE_BB_WATCHDOG;
  561. RESET_STAT_INC(sc, type);
  562. #endif
  563. ieee80211_queue_work(sc->hw, &sc->hw_reset_work);
  564. goto out;
  565. }
  566. /*
  567. * Only run the baseband hang check if beacons stop working in AP or
  568. * IBSS mode, because it has a high false positive rate. For station
  569. * mode it should not be necessary, since the upper layers will detect
  570. * this through a beacon miss automatically and the following channel
  571. * change will trigger a hardware reset anyway
  572. */
  573. if (ath9k_hw_numtxpending(ah, sc->beacon.beaconq) != 0 &&
  574. !ath9k_hw_check_alive(ah))
  575. ieee80211_queue_work(sc->hw, &sc->hw_check_work);
  576. if ((status & ATH9K_INT_TSFOOR) && sc->ps_enabled) {
  577. /*
  578. * TSF sync does not look correct; remain awake to sync with
  579. * the next Beacon.
  580. */
  581. ath_dbg(common, ATH_DBG_PS,
  582. "TSFOOR - Sync with next Beacon\n");
  583. sc->ps_flags |= PS_WAIT_FOR_BEACON | PS_BEACON_SYNC;
  584. }
  585. if (ah->caps.hw_caps & ATH9K_HW_CAP_EDMA)
  586. rxmask = (ATH9K_INT_RXHP | ATH9K_INT_RXLP | ATH9K_INT_RXEOL |
  587. ATH9K_INT_RXORN);
  588. else
  589. rxmask = (ATH9K_INT_RX | ATH9K_INT_RXEOL | ATH9K_INT_RXORN);
  590. if (status & rxmask) {
  591. /* Check for high priority Rx first */
  592. if ((ah->caps.hw_caps & ATH9K_HW_CAP_EDMA) &&
  593. (status & ATH9K_INT_RXHP))
  594. ath_rx_tasklet(sc, 0, true);
  595. ath_rx_tasklet(sc, 0, false);
  596. }
  597. if (status & ATH9K_INT_TX) {
  598. if (ah->caps.hw_caps & ATH9K_HW_CAP_EDMA)
  599. ath_tx_edma_tasklet(sc);
  600. else
  601. ath_tx_tasklet(sc);
  602. }
  603. if (ah->btcoex_hw.scheme == ATH_BTCOEX_CFG_3WIRE)
  604. if (status & ATH9K_INT_GENTIMER)
  605. ath_gen_timer_isr(sc->sc_ah);
  606. out:
  607. /* re-enable hardware interrupt */
  608. ath9k_hw_enable_interrupts(ah);
  609. spin_unlock(&sc->sc_pcu_lock);
  610. ath9k_ps_restore(sc);
  611. }
  612. irqreturn_t ath_isr(int irq, void *dev)
  613. {
  614. #define SCHED_INTR ( \
  615. ATH9K_INT_FATAL | \
  616. ATH9K_INT_BB_WATCHDOG | \
  617. ATH9K_INT_RXORN | \
  618. ATH9K_INT_RXEOL | \
  619. ATH9K_INT_RX | \
  620. ATH9K_INT_RXLP | \
  621. ATH9K_INT_RXHP | \
  622. ATH9K_INT_TX | \
  623. ATH9K_INT_BMISS | \
  624. ATH9K_INT_CST | \
  625. ATH9K_INT_TSFOOR | \
  626. ATH9K_INT_GENTIMER)
  627. struct ath_softc *sc = dev;
  628. struct ath_hw *ah = sc->sc_ah;
  629. struct ath_common *common = ath9k_hw_common(ah);
  630. enum ath9k_int status;
  631. bool sched = false;
  632. /*
  633. * The hardware is not ready/present, don't
  634. * touch anything. Note this can happen early
  635. * on if the IRQ is shared.
  636. */
  637. if (sc->sc_flags & SC_OP_INVALID)
  638. return IRQ_NONE;
  639. /* shared irq, not for us */
  640. if (!ath9k_hw_intrpend(ah))
  641. return IRQ_NONE;
  642. /*
  643. * Figure out the reason(s) for the interrupt. Note
  644. * that the hal returns a pseudo-ISR that may include
  645. * bits we haven't explicitly enabled so we mask the
  646. * value to insure we only process bits we requested.
  647. */
  648. ath9k_hw_getisr(ah, &status); /* NB: clears ISR too */
  649. status &= ah->imask; /* discard unasked-for bits */
  650. /*
  651. * If there are no status bits set, then this interrupt was not
  652. * for me (should have been caught above).
  653. */
  654. if (!status)
  655. return IRQ_NONE;
  656. /* Cache the status */
  657. sc->intrstatus = status;
  658. if (status & SCHED_INTR)
  659. sched = true;
  660. /*
  661. * If a FATAL or RXORN interrupt is received, we have to reset the
  662. * chip immediately.
  663. */
  664. if ((status & ATH9K_INT_FATAL) || ((status & ATH9K_INT_RXORN) &&
  665. !(ah->caps.hw_caps & ATH9K_HW_CAP_EDMA)))
  666. goto chip_reset;
  667. if ((ah->caps.hw_caps & ATH9K_HW_CAP_EDMA) &&
  668. (status & ATH9K_INT_BB_WATCHDOG)) {
  669. spin_lock(&common->cc_lock);
  670. ath_hw_cycle_counters_update(common);
  671. ar9003_hw_bb_watchdog_dbg_info(ah);
  672. spin_unlock(&common->cc_lock);
  673. goto chip_reset;
  674. }
  675. if (status & ATH9K_INT_SWBA)
  676. tasklet_schedule(&sc->bcon_tasklet);
  677. if (status & ATH9K_INT_TXURN)
  678. ath9k_hw_updatetxtriglevel(ah, true);
  679. if (status & ATH9K_INT_RXEOL) {
  680. ah->imask &= ~(ATH9K_INT_RXEOL | ATH9K_INT_RXORN);
  681. ath9k_hw_set_interrupts(ah);
  682. }
  683. if (status & ATH9K_INT_MIB) {
  684. /*
  685. * Disable interrupts until we service the MIB
  686. * interrupt; otherwise it will continue to
  687. * fire.
  688. */
  689. ath9k_hw_disable_interrupts(ah);
  690. /*
  691. * Let the hal handle the event. We assume
  692. * it will clear whatever condition caused
  693. * the interrupt.
  694. */
  695. spin_lock(&common->cc_lock);
  696. ath9k_hw_proc_mib_event(ah);
  697. spin_unlock(&common->cc_lock);
  698. ath9k_hw_enable_interrupts(ah);
  699. }
  700. if (!(ah->caps.hw_caps & ATH9K_HW_CAP_AUTOSLEEP))
  701. if (status & ATH9K_INT_TIM_TIMER) {
  702. if (ATH_DBG_WARN_ON_ONCE(sc->ps_idle))
  703. goto chip_reset;
  704. /* Clear RxAbort bit so that we can
  705. * receive frames */
  706. ath9k_setpower(sc, ATH9K_PM_AWAKE);
  707. ath9k_hw_setrxabort(sc->sc_ah, 0);
  708. sc->ps_flags |= PS_WAIT_FOR_BEACON;
  709. }
  710. chip_reset:
  711. ath_debug_stat_interrupt(sc, status);
  712. if (sched) {
  713. /* turn off every interrupt */
  714. ath9k_hw_disable_interrupts(ah);
  715. tasklet_schedule(&sc->intr_tq);
  716. }
  717. return IRQ_HANDLED;
  718. #undef SCHED_INTR
  719. }
  720. static void ath_radio_enable(struct ath_softc *sc, struct ieee80211_hw *hw)
  721. {
  722. struct ath_hw *ah = sc->sc_ah;
  723. struct ath_common *common = ath9k_hw_common(ah);
  724. struct ieee80211_channel *channel = hw->conf.channel;
  725. int r;
  726. ath9k_ps_wakeup(sc);
  727. spin_lock_bh(&sc->sc_pcu_lock);
  728. atomic_set(&ah->intr_ref_cnt, -1);
  729. ath9k_hw_configpcipowersave(ah, false);
  730. if (!ah->curchan)
  731. ah->curchan = ath9k_cmn_get_curchannel(sc->hw, ah);
  732. r = ath9k_hw_reset(ah, ah->curchan, ah->caldata, false);
  733. if (r) {
  734. ath_err(common,
  735. "Unable to reset channel (%u MHz), reset status %d\n",
  736. channel->center_freq, r);
  737. }
  738. ath_complete_reset(sc, true);
  739. /* Enable LED */
  740. ath9k_hw_cfg_output(ah, ah->led_pin,
  741. AR_GPIO_OUTPUT_MUX_AS_OUTPUT);
  742. ath9k_hw_set_gpio(ah, ah->led_pin, 0);
  743. spin_unlock_bh(&sc->sc_pcu_lock);
  744. ath9k_ps_restore(sc);
  745. }
  746. void ath_radio_disable(struct ath_softc *sc, struct ieee80211_hw *hw)
  747. {
  748. struct ath_hw *ah = sc->sc_ah;
  749. struct ieee80211_channel *channel = hw->conf.channel;
  750. int r;
  751. ath9k_ps_wakeup(sc);
  752. ath_cancel_work(sc);
  753. spin_lock_bh(&sc->sc_pcu_lock);
  754. /*
  755. * Keep the LED on when the radio is disabled
  756. * during idle unassociated state.
  757. */
  758. if (!sc->ps_idle) {
  759. ath9k_hw_set_gpio(ah, ah->led_pin, 1);
  760. ath9k_hw_cfg_gpio_input(ah, ah->led_pin);
  761. }
  762. ath_prepare_reset(sc, false, true);
  763. if (!ah->curchan)
  764. ah->curchan = ath9k_cmn_get_curchannel(hw, ah);
  765. r = ath9k_hw_reset(ah, ah->curchan, ah->caldata, false);
  766. if (r) {
  767. ath_err(ath9k_hw_common(sc->sc_ah),
  768. "Unable to reset channel (%u MHz), reset status %d\n",
  769. channel->center_freq, r);
  770. }
  771. ath9k_hw_phy_disable(ah);
  772. ath9k_hw_configpcipowersave(ah, true);
  773. spin_unlock_bh(&sc->sc_pcu_lock);
  774. ath9k_ps_restore(sc);
  775. }
  776. static int ath_reset(struct ath_softc *sc, bool retry_tx)
  777. {
  778. int r;
  779. ath9k_ps_wakeup(sc);
  780. r = ath_reset_internal(sc, NULL, retry_tx);
  781. if (retry_tx) {
  782. int i;
  783. for (i = 0; i < ATH9K_NUM_TX_QUEUES; i++) {
  784. if (ATH_TXQ_SETUP(sc, i)) {
  785. spin_lock_bh(&sc->tx.txq[i].axq_lock);
  786. ath_txq_schedule(sc, &sc->tx.txq[i]);
  787. spin_unlock_bh(&sc->tx.txq[i].axq_lock);
  788. }
  789. }
  790. }
  791. ath9k_ps_restore(sc);
  792. return r;
  793. }
  794. void ath_reset_work(struct work_struct *work)
  795. {
  796. struct ath_softc *sc = container_of(work, struct ath_softc, hw_reset_work);
  797. ath_reset(sc, true);
  798. }
  799. void ath_hw_check(struct work_struct *work)
  800. {
  801. struct ath_softc *sc = container_of(work, struct ath_softc, hw_check_work);
  802. struct ath_common *common = ath9k_hw_common(sc->sc_ah);
  803. unsigned long flags;
  804. int busy;
  805. ath9k_ps_wakeup(sc);
  806. if (ath9k_hw_check_alive(sc->sc_ah))
  807. goto out;
  808. spin_lock_irqsave(&common->cc_lock, flags);
  809. busy = ath_update_survey_stats(sc);
  810. spin_unlock_irqrestore(&common->cc_lock, flags);
  811. ath_dbg(common, ATH_DBG_RESET, "Possible baseband hang, "
  812. "busy=%d (try %d)\n", busy, sc->hw_busy_count + 1);
  813. if (busy >= 99) {
  814. if (++sc->hw_busy_count >= 3) {
  815. RESET_STAT_INC(sc, RESET_TYPE_BB_HANG);
  816. ieee80211_queue_work(sc->hw, &sc->hw_reset_work);
  817. }
  818. } else if (busy >= 0)
  819. sc->hw_busy_count = 0;
  820. out:
  821. ath9k_ps_restore(sc);
  822. }
  823. static void ath_hw_pll_rx_hang_check(struct ath_softc *sc, u32 pll_sqsum)
  824. {
  825. static int count;
  826. struct ath_common *common = ath9k_hw_common(sc->sc_ah);
  827. if (pll_sqsum >= 0x40000) {
  828. count++;
  829. if (count == 3) {
  830. /* Rx is hung for more than 500ms. Reset it */
  831. ath_dbg(common, ATH_DBG_RESET,
  832. "Possible RX hang, resetting");
  833. RESET_STAT_INC(sc, RESET_TYPE_PLL_HANG);
  834. ieee80211_queue_work(sc->hw, &sc->hw_reset_work);
  835. count = 0;
  836. }
  837. } else
  838. count = 0;
  839. }
  840. void ath_hw_pll_work(struct work_struct *work)
  841. {
  842. struct ath_softc *sc = container_of(work, struct ath_softc,
  843. hw_pll_work.work);
  844. u32 pll_sqsum;
  845. if (AR_SREV_9485(sc->sc_ah)) {
  846. ath9k_ps_wakeup(sc);
  847. pll_sqsum = ar9003_get_pll_sqsum_dvc(sc->sc_ah);
  848. ath9k_ps_restore(sc);
  849. ath_hw_pll_rx_hang_check(sc, pll_sqsum);
  850. ieee80211_queue_delayed_work(sc->hw, &sc->hw_pll_work, HZ/5);
  851. }
  852. }
  853. /**********************/
  854. /* mac80211 callbacks */
  855. /**********************/
  856. static int ath9k_start(struct ieee80211_hw *hw)
  857. {
  858. struct ath_softc *sc = hw->priv;
  859. struct ath_hw *ah = sc->sc_ah;
  860. struct ath_common *common = ath9k_hw_common(ah);
  861. struct ieee80211_channel *curchan = hw->conf.channel;
  862. struct ath9k_channel *init_channel;
  863. int r;
  864. ath_dbg(common, ATH_DBG_CONFIG,
  865. "Starting driver with initial channel: %d MHz\n",
  866. curchan->center_freq);
  867. ath9k_ps_wakeup(sc);
  868. mutex_lock(&sc->mutex);
  869. /* setup initial channel */
  870. sc->chan_idx = curchan->hw_value;
  871. init_channel = ath9k_cmn_get_curchannel(hw, ah);
  872. /* Reset SERDES registers */
  873. ath9k_hw_configpcipowersave(ah, false);
  874. /*
  875. * The basic interface to setting the hardware in a good
  876. * state is ``reset''. On return the hardware is known to
  877. * be powered up and with interrupts disabled. This must
  878. * be followed by initialization of the appropriate bits
  879. * and then setup of the interrupt mask.
  880. */
  881. spin_lock_bh(&sc->sc_pcu_lock);
  882. r = ath9k_hw_reset(ah, init_channel, ah->caldata, false);
  883. if (r) {
  884. ath_err(common,
  885. "Unable to reset hardware; reset status %d (freq %u MHz)\n",
  886. r, curchan->center_freq);
  887. spin_unlock_bh(&sc->sc_pcu_lock);
  888. goto mutex_unlock;
  889. }
  890. /* Setup our intr mask. */
  891. ah->imask = ATH9K_INT_TX | ATH9K_INT_RXEOL |
  892. ATH9K_INT_RXORN | ATH9K_INT_FATAL |
  893. ATH9K_INT_GLOBAL;
  894. if (ah->caps.hw_caps & ATH9K_HW_CAP_EDMA)
  895. ah->imask |= ATH9K_INT_RXHP |
  896. ATH9K_INT_RXLP |
  897. ATH9K_INT_BB_WATCHDOG;
  898. else
  899. ah->imask |= ATH9K_INT_RX;
  900. ah->imask |= ATH9K_INT_GTT;
  901. if (ah->caps.hw_caps & ATH9K_HW_CAP_HT)
  902. ah->imask |= ATH9K_INT_CST;
  903. sc->sc_flags &= ~SC_OP_INVALID;
  904. sc->sc_ah->is_monitoring = false;
  905. /* Disable BMISS interrupt when we're not associated */
  906. ah->imask &= ~(ATH9K_INT_SWBA | ATH9K_INT_BMISS);
  907. if (!ath_complete_reset(sc, false)) {
  908. r = -EIO;
  909. spin_unlock_bh(&sc->sc_pcu_lock);
  910. goto mutex_unlock;
  911. }
  912. spin_unlock_bh(&sc->sc_pcu_lock);
  913. if ((ah->btcoex_hw.scheme != ATH_BTCOEX_CFG_NONE) &&
  914. !ah->btcoex_hw.enabled) {
  915. ath9k_hw_btcoex_set_weight(ah, AR_BT_COEX_WGHT,
  916. AR_STOMP_LOW_WLAN_WGHT);
  917. ath9k_hw_btcoex_enable(ah);
  918. if (ah->btcoex_hw.scheme == ATH_BTCOEX_CFG_3WIRE)
  919. ath9k_btcoex_timer_resume(sc);
  920. }
  921. if (ah->caps.pcie_lcr_extsync_en && common->bus_ops->extn_synch_en)
  922. common->bus_ops->extn_synch_en(common);
  923. mutex_unlock:
  924. mutex_unlock(&sc->mutex);
  925. ath9k_ps_restore(sc);
  926. return r;
  927. }
  928. static void ath9k_tx(struct ieee80211_hw *hw, struct sk_buff *skb)
  929. {
  930. struct ath_softc *sc = hw->priv;
  931. struct ath_common *common = ath9k_hw_common(sc->sc_ah);
  932. struct ath_tx_control txctl;
  933. struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
  934. if (sc->ps_enabled) {
  935. /*
  936. * mac80211 does not set PM field for normal data frames, so we
  937. * need to update that based on the current PS mode.
  938. */
  939. if (ieee80211_is_data(hdr->frame_control) &&
  940. !ieee80211_is_nullfunc(hdr->frame_control) &&
  941. !ieee80211_has_pm(hdr->frame_control)) {
  942. ath_dbg(common, ATH_DBG_PS,
  943. "Add PM=1 for a TX frame while in PS mode\n");
  944. hdr->frame_control |= cpu_to_le16(IEEE80211_FCTL_PM);
  945. }
  946. }
  947. if (unlikely(sc->sc_ah->power_mode != ATH9K_PM_AWAKE)) {
  948. /*
  949. * We are using PS-Poll and mac80211 can request TX while in
  950. * power save mode. Need to wake up hardware for the TX to be
  951. * completed and if needed, also for RX of buffered frames.
  952. */
  953. ath9k_ps_wakeup(sc);
  954. if (!(sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_AUTOSLEEP))
  955. ath9k_hw_setrxabort(sc->sc_ah, 0);
  956. if (ieee80211_is_pspoll(hdr->frame_control)) {
  957. ath_dbg(common, ATH_DBG_PS,
  958. "Sending PS-Poll to pick a buffered frame\n");
  959. sc->ps_flags |= PS_WAIT_FOR_PSPOLL_DATA;
  960. } else {
  961. ath_dbg(common, ATH_DBG_PS,
  962. "Wake up to complete TX\n");
  963. sc->ps_flags |= PS_WAIT_FOR_TX_ACK;
  964. }
  965. /*
  966. * The actual restore operation will happen only after
  967. * the sc_flags bit is cleared. We are just dropping
  968. * the ps_usecount here.
  969. */
  970. ath9k_ps_restore(sc);
  971. }
  972. memset(&txctl, 0, sizeof(struct ath_tx_control));
  973. txctl.txq = sc->tx.txq_map[skb_get_queue_mapping(skb)];
  974. ath_dbg(common, ATH_DBG_XMIT, "transmitting packet, skb: %p\n", skb);
  975. if (ath_tx_start(hw, skb, &txctl) != 0) {
  976. ath_dbg(common, ATH_DBG_XMIT, "TX failed\n");
  977. goto exit;
  978. }
  979. return;
  980. exit:
  981. dev_kfree_skb_any(skb);
  982. }
  983. static void ath9k_stop(struct ieee80211_hw *hw)
  984. {
  985. struct ath_softc *sc = hw->priv;
  986. struct ath_hw *ah = sc->sc_ah;
  987. struct ath_common *common = ath9k_hw_common(ah);
  988. mutex_lock(&sc->mutex);
  989. ath_cancel_work(sc);
  990. if (sc->sc_flags & SC_OP_INVALID) {
  991. ath_dbg(common, ATH_DBG_ANY, "Device not present\n");
  992. mutex_unlock(&sc->mutex);
  993. return;
  994. }
  995. /* Ensure HW is awake when we try to shut it down. */
  996. ath9k_ps_wakeup(sc);
  997. if (ah->btcoex_hw.enabled) {
  998. ath9k_hw_btcoex_disable(ah);
  999. if (ah->btcoex_hw.scheme == ATH_BTCOEX_CFG_3WIRE)
  1000. ath9k_btcoex_timer_pause(sc);
  1001. }
  1002. spin_lock_bh(&sc->sc_pcu_lock);
  1003. /* prevent tasklets to enable interrupts once we disable them */
  1004. ah->imask &= ~ATH9K_INT_GLOBAL;
  1005. /* make sure h/w will not generate any interrupt
  1006. * before setting the invalid flag. */
  1007. ath9k_hw_disable_interrupts(ah);
  1008. if (!(sc->sc_flags & SC_OP_INVALID)) {
  1009. ath_drain_all_txq(sc, false);
  1010. ath_stoprecv(sc);
  1011. ath9k_hw_phy_disable(ah);
  1012. } else
  1013. sc->rx.rxlink = NULL;
  1014. if (sc->rx.frag) {
  1015. dev_kfree_skb_any(sc->rx.frag);
  1016. sc->rx.frag = NULL;
  1017. }
  1018. /* disable HAL and put h/w to sleep */
  1019. ath9k_hw_disable(ah);
  1020. spin_unlock_bh(&sc->sc_pcu_lock);
  1021. /* we can now sync irq and kill any running tasklets, since we already
  1022. * disabled interrupts and not holding a spin lock */
  1023. synchronize_irq(sc->irq);
  1024. tasklet_kill(&sc->intr_tq);
  1025. tasklet_kill(&sc->bcon_tasklet);
  1026. ath9k_ps_restore(sc);
  1027. sc->ps_idle = true;
  1028. ath_radio_disable(sc, hw);
  1029. sc->sc_flags |= SC_OP_INVALID;
  1030. mutex_unlock(&sc->mutex);
  1031. ath_dbg(common, ATH_DBG_CONFIG, "Driver halt\n");
  1032. }
  1033. bool ath9k_uses_beacons(int type)
  1034. {
  1035. switch (type) {
  1036. case NL80211_IFTYPE_AP:
  1037. case NL80211_IFTYPE_ADHOC:
  1038. case NL80211_IFTYPE_MESH_POINT:
  1039. return true;
  1040. default:
  1041. return false;
  1042. }
  1043. }
  1044. static void ath9k_reclaim_beacon(struct ath_softc *sc,
  1045. struct ieee80211_vif *vif)
  1046. {
  1047. struct ath_vif *avp = (void *)vif->drv_priv;
  1048. ath9k_set_beaconing_status(sc, false);
  1049. ath_beacon_return(sc, avp);
  1050. ath9k_set_beaconing_status(sc, true);
  1051. sc->sc_flags &= ~SC_OP_BEACONS;
  1052. }
  1053. static void ath9k_vif_iter(void *data, u8 *mac, struct ieee80211_vif *vif)
  1054. {
  1055. struct ath9k_vif_iter_data *iter_data = data;
  1056. int i;
  1057. if (iter_data->hw_macaddr)
  1058. for (i = 0; i < ETH_ALEN; i++)
  1059. iter_data->mask[i] &=
  1060. ~(iter_data->hw_macaddr[i] ^ mac[i]);
  1061. switch (vif->type) {
  1062. case NL80211_IFTYPE_AP:
  1063. iter_data->naps++;
  1064. break;
  1065. case NL80211_IFTYPE_STATION:
  1066. iter_data->nstations++;
  1067. break;
  1068. case NL80211_IFTYPE_ADHOC:
  1069. iter_data->nadhocs++;
  1070. break;
  1071. case NL80211_IFTYPE_MESH_POINT:
  1072. iter_data->nmeshes++;
  1073. break;
  1074. case NL80211_IFTYPE_WDS:
  1075. iter_data->nwds++;
  1076. break;
  1077. default:
  1078. iter_data->nothers++;
  1079. break;
  1080. }
  1081. }
  1082. /* Called with sc->mutex held. */
  1083. void ath9k_calculate_iter_data(struct ieee80211_hw *hw,
  1084. struct ieee80211_vif *vif,
  1085. struct ath9k_vif_iter_data *iter_data)
  1086. {
  1087. struct ath_softc *sc = hw->priv;
  1088. struct ath_hw *ah = sc->sc_ah;
  1089. struct ath_common *common = ath9k_hw_common(ah);
  1090. /*
  1091. * Use the hardware MAC address as reference, the hardware uses it
  1092. * together with the BSSID mask when matching addresses.
  1093. */
  1094. memset(iter_data, 0, sizeof(*iter_data));
  1095. iter_data->hw_macaddr = common->macaddr;
  1096. memset(&iter_data->mask, 0xff, ETH_ALEN);
  1097. if (vif)
  1098. ath9k_vif_iter(iter_data, vif->addr, vif);
  1099. /* Get list of all active MAC addresses */
  1100. ieee80211_iterate_active_interfaces_atomic(sc->hw, ath9k_vif_iter,
  1101. iter_data);
  1102. }
  1103. /* Called with sc->mutex held. */
  1104. static void ath9k_calculate_summary_state(struct ieee80211_hw *hw,
  1105. struct ieee80211_vif *vif)
  1106. {
  1107. struct ath_softc *sc = hw->priv;
  1108. struct ath_hw *ah = sc->sc_ah;
  1109. struct ath_common *common = ath9k_hw_common(ah);
  1110. struct ath9k_vif_iter_data iter_data;
  1111. ath9k_calculate_iter_data(hw, vif, &iter_data);
  1112. /* Set BSSID mask. */
  1113. memcpy(common->bssidmask, iter_data.mask, ETH_ALEN);
  1114. ath_hw_setbssidmask(common);
  1115. /* Set op-mode & TSF */
  1116. if (iter_data.naps > 0) {
  1117. ath9k_hw_set_tsfadjust(ah, 1);
  1118. sc->sc_flags |= SC_OP_TSF_RESET;
  1119. ah->opmode = NL80211_IFTYPE_AP;
  1120. } else {
  1121. ath9k_hw_set_tsfadjust(ah, 0);
  1122. sc->sc_flags &= ~SC_OP_TSF_RESET;
  1123. if (iter_data.nmeshes)
  1124. ah->opmode = NL80211_IFTYPE_MESH_POINT;
  1125. else if (iter_data.nwds)
  1126. ah->opmode = NL80211_IFTYPE_AP;
  1127. else if (iter_data.nadhocs)
  1128. ah->opmode = NL80211_IFTYPE_ADHOC;
  1129. else
  1130. ah->opmode = NL80211_IFTYPE_STATION;
  1131. }
  1132. /*
  1133. * Enable MIB interrupts when there are hardware phy counters.
  1134. */
  1135. if ((iter_data.nstations + iter_data.nadhocs + iter_data.nmeshes) > 0) {
  1136. if (ah->config.enable_ani)
  1137. ah->imask |= ATH9K_INT_MIB;
  1138. ah->imask |= ATH9K_INT_TSFOOR;
  1139. } else {
  1140. ah->imask &= ~ATH9K_INT_MIB;
  1141. ah->imask &= ~ATH9K_INT_TSFOOR;
  1142. }
  1143. ath9k_hw_set_interrupts(ah);
  1144. /* Set up ANI */
  1145. if (iter_data.naps > 0) {
  1146. sc->sc_ah->stats.avgbrssi = ATH_RSSI_DUMMY_MARKER;
  1147. if (!common->disable_ani) {
  1148. sc->sc_flags |= SC_OP_ANI_RUN;
  1149. ath_start_ani(common);
  1150. }
  1151. } else {
  1152. sc->sc_flags &= ~SC_OP_ANI_RUN;
  1153. del_timer_sync(&common->ani.timer);
  1154. }
  1155. }
  1156. /* Called with sc->mutex held, vif counts set up properly. */
  1157. static void ath9k_do_vif_add_setup(struct ieee80211_hw *hw,
  1158. struct ieee80211_vif *vif)
  1159. {
  1160. struct ath_softc *sc = hw->priv;
  1161. ath9k_calculate_summary_state(hw, vif);
  1162. if (ath9k_uses_beacons(vif->type)) {
  1163. int error;
  1164. /* This may fail because upper levels do not have beacons
  1165. * properly configured yet. That's OK, we assume it
  1166. * will be properly configured and then we will be notified
  1167. * in the info_changed method and set up beacons properly
  1168. * there.
  1169. */
  1170. ath9k_set_beaconing_status(sc, false);
  1171. error = ath_beacon_alloc(sc, vif);
  1172. if (!error)
  1173. ath_beacon_config(sc, vif);
  1174. ath9k_set_beaconing_status(sc, true);
  1175. }
  1176. }
  1177. static int ath9k_add_interface(struct ieee80211_hw *hw,
  1178. struct ieee80211_vif *vif)
  1179. {
  1180. struct ath_softc *sc = hw->priv;
  1181. struct ath_hw *ah = sc->sc_ah;
  1182. struct ath_common *common = ath9k_hw_common(ah);
  1183. int ret = 0;
  1184. ath9k_ps_wakeup(sc);
  1185. mutex_lock(&sc->mutex);
  1186. switch (vif->type) {
  1187. case NL80211_IFTYPE_STATION:
  1188. case NL80211_IFTYPE_WDS:
  1189. case NL80211_IFTYPE_ADHOC:
  1190. case NL80211_IFTYPE_AP:
  1191. case NL80211_IFTYPE_MESH_POINT:
  1192. break;
  1193. default:
  1194. ath_err(common, "Interface type %d not yet supported\n",
  1195. vif->type);
  1196. ret = -EOPNOTSUPP;
  1197. goto out;
  1198. }
  1199. if (ath9k_uses_beacons(vif->type)) {
  1200. if (sc->nbcnvifs >= ATH_BCBUF) {
  1201. ath_err(common, "Not enough beacon buffers when adding"
  1202. " new interface of type: %i\n",
  1203. vif->type);
  1204. ret = -ENOBUFS;
  1205. goto out;
  1206. }
  1207. }
  1208. if ((ah->opmode == NL80211_IFTYPE_ADHOC) ||
  1209. ((vif->type == NL80211_IFTYPE_ADHOC) &&
  1210. sc->nvifs > 0)) {
  1211. ath_err(common, "Cannot create ADHOC interface when other"
  1212. " interfaces already exist.\n");
  1213. ret = -EINVAL;
  1214. goto out;
  1215. }
  1216. ath_dbg(common, ATH_DBG_CONFIG,
  1217. "Attach a VIF of type: %d\n", vif->type);
  1218. sc->nvifs++;
  1219. ath9k_do_vif_add_setup(hw, vif);
  1220. out:
  1221. mutex_unlock(&sc->mutex);
  1222. ath9k_ps_restore(sc);
  1223. return ret;
  1224. }
  1225. static int ath9k_change_interface(struct ieee80211_hw *hw,
  1226. struct ieee80211_vif *vif,
  1227. enum nl80211_iftype new_type,
  1228. bool p2p)
  1229. {
  1230. struct ath_softc *sc = hw->priv;
  1231. struct ath_common *common = ath9k_hw_common(sc->sc_ah);
  1232. int ret = 0;
  1233. ath_dbg(common, ATH_DBG_CONFIG, "Change Interface\n");
  1234. mutex_lock(&sc->mutex);
  1235. ath9k_ps_wakeup(sc);
  1236. /* See if new interface type is valid. */
  1237. if ((new_type == NL80211_IFTYPE_ADHOC) &&
  1238. (sc->nvifs > 1)) {
  1239. ath_err(common, "When using ADHOC, it must be the only"
  1240. " interface.\n");
  1241. ret = -EINVAL;
  1242. goto out;
  1243. }
  1244. if (ath9k_uses_beacons(new_type) &&
  1245. !ath9k_uses_beacons(vif->type)) {
  1246. if (sc->nbcnvifs >= ATH_BCBUF) {
  1247. ath_err(common, "No beacon slot available\n");
  1248. ret = -ENOBUFS;
  1249. goto out;
  1250. }
  1251. }
  1252. /* Clean up old vif stuff */
  1253. if (ath9k_uses_beacons(vif->type))
  1254. ath9k_reclaim_beacon(sc, vif);
  1255. /* Add new settings */
  1256. vif->type = new_type;
  1257. vif->p2p = p2p;
  1258. ath9k_do_vif_add_setup(hw, vif);
  1259. out:
  1260. ath9k_ps_restore(sc);
  1261. mutex_unlock(&sc->mutex);
  1262. return ret;
  1263. }
  1264. static void ath9k_remove_interface(struct ieee80211_hw *hw,
  1265. struct ieee80211_vif *vif)
  1266. {
  1267. struct ath_softc *sc = hw->priv;
  1268. struct ath_common *common = ath9k_hw_common(sc->sc_ah);
  1269. ath_dbg(common, ATH_DBG_CONFIG, "Detach Interface\n");
  1270. ath9k_ps_wakeup(sc);
  1271. mutex_lock(&sc->mutex);
  1272. sc->nvifs--;
  1273. /* Reclaim beacon resources */
  1274. if (ath9k_uses_beacons(vif->type))
  1275. ath9k_reclaim_beacon(sc, vif);
  1276. ath9k_calculate_summary_state(hw, NULL);
  1277. mutex_unlock(&sc->mutex);
  1278. ath9k_ps_restore(sc);
  1279. }
  1280. static void ath9k_enable_ps(struct ath_softc *sc)
  1281. {
  1282. struct ath_hw *ah = sc->sc_ah;
  1283. sc->ps_enabled = true;
  1284. if (!(ah->caps.hw_caps & ATH9K_HW_CAP_AUTOSLEEP)) {
  1285. if ((ah->imask & ATH9K_INT_TIM_TIMER) == 0) {
  1286. ah->imask |= ATH9K_INT_TIM_TIMER;
  1287. ath9k_hw_set_interrupts(ah);
  1288. }
  1289. ath9k_hw_setrxabort(ah, 1);
  1290. }
  1291. }
  1292. static void ath9k_disable_ps(struct ath_softc *sc)
  1293. {
  1294. struct ath_hw *ah = sc->sc_ah;
  1295. sc->ps_enabled = false;
  1296. ath9k_hw_setpower(ah, ATH9K_PM_AWAKE);
  1297. if (!(ah->caps.hw_caps & ATH9K_HW_CAP_AUTOSLEEP)) {
  1298. ath9k_hw_setrxabort(ah, 0);
  1299. sc->ps_flags &= ~(PS_WAIT_FOR_BEACON |
  1300. PS_WAIT_FOR_CAB |
  1301. PS_WAIT_FOR_PSPOLL_DATA |
  1302. PS_WAIT_FOR_TX_ACK);
  1303. if (ah->imask & ATH9K_INT_TIM_TIMER) {
  1304. ah->imask &= ~ATH9K_INT_TIM_TIMER;
  1305. ath9k_hw_set_interrupts(ah);
  1306. }
  1307. }
  1308. }
  1309. static int ath9k_config(struct ieee80211_hw *hw, u32 changed)
  1310. {
  1311. struct ath_softc *sc = hw->priv;
  1312. struct ath_hw *ah = sc->sc_ah;
  1313. struct ath_common *common = ath9k_hw_common(ah);
  1314. struct ieee80211_conf *conf = &hw->conf;
  1315. bool disable_radio = false;
  1316. mutex_lock(&sc->mutex);
  1317. /*
  1318. * Leave this as the first check because we need to turn on the
  1319. * radio if it was disabled before prior to processing the rest
  1320. * of the changes. Likewise we must only disable the radio towards
  1321. * the end.
  1322. */
  1323. if (changed & IEEE80211_CONF_CHANGE_IDLE) {
  1324. sc->ps_idle = !!(conf->flags & IEEE80211_CONF_IDLE);
  1325. if (!sc->ps_idle) {
  1326. ath_radio_enable(sc, hw);
  1327. ath_dbg(common, ATH_DBG_CONFIG,
  1328. "not-idle: enabling radio\n");
  1329. } else {
  1330. disable_radio = true;
  1331. }
  1332. }
  1333. /*
  1334. * We just prepare to enable PS. We have to wait until our AP has
  1335. * ACK'd our null data frame to disable RX otherwise we'll ignore
  1336. * those ACKs and end up retransmitting the same null data frames.
  1337. * IEEE80211_CONF_CHANGE_PS is only passed by mac80211 for STA mode.
  1338. */
  1339. if (changed & IEEE80211_CONF_CHANGE_PS) {
  1340. unsigned long flags;
  1341. spin_lock_irqsave(&sc->sc_pm_lock, flags);
  1342. if (conf->flags & IEEE80211_CONF_PS)
  1343. ath9k_enable_ps(sc);
  1344. else
  1345. ath9k_disable_ps(sc);
  1346. spin_unlock_irqrestore(&sc->sc_pm_lock, flags);
  1347. }
  1348. if (changed & IEEE80211_CONF_CHANGE_MONITOR) {
  1349. if (conf->flags & IEEE80211_CONF_MONITOR) {
  1350. ath_dbg(common, ATH_DBG_CONFIG,
  1351. "Monitor mode is enabled\n");
  1352. sc->sc_ah->is_monitoring = true;
  1353. } else {
  1354. ath_dbg(common, ATH_DBG_CONFIG,
  1355. "Monitor mode is disabled\n");
  1356. sc->sc_ah->is_monitoring = false;
  1357. }
  1358. }
  1359. if (changed & IEEE80211_CONF_CHANGE_CHANNEL) {
  1360. struct ieee80211_channel *curchan = hw->conf.channel;
  1361. struct ath9k_channel old_chan;
  1362. int pos = curchan->hw_value;
  1363. int old_pos = -1;
  1364. unsigned long flags;
  1365. if (ah->curchan)
  1366. old_pos = ah->curchan - &ah->channels[0];
  1367. if (hw->conf.flags & IEEE80211_CONF_OFFCHANNEL)
  1368. sc->sc_flags |= SC_OP_OFFCHANNEL;
  1369. else
  1370. sc->sc_flags &= ~SC_OP_OFFCHANNEL;
  1371. ath_dbg(common, ATH_DBG_CONFIG,
  1372. "Set channel: %d MHz type: %d\n",
  1373. curchan->center_freq, conf->channel_type);
  1374. /* update survey stats for the old channel before switching */
  1375. spin_lock_irqsave(&common->cc_lock, flags);
  1376. ath_update_survey_stats(sc);
  1377. spin_unlock_irqrestore(&common->cc_lock, flags);
  1378. /*
  1379. * Preserve the current channel values, before updating
  1380. * the same channel
  1381. */
  1382. if (old_pos == pos) {
  1383. memcpy(&old_chan, &sc->sc_ah->channels[pos],
  1384. sizeof(struct ath9k_channel));
  1385. ah->curchan = &old_chan;
  1386. }
  1387. ath9k_cmn_update_ichannel(&sc->sc_ah->channels[pos],
  1388. curchan, conf->channel_type);
  1389. /*
  1390. * If the operating channel changes, change the survey in-use flags
  1391. * along with it.
  1392. * Reset the survey data for the new channel, unless we're switching
  1393. * back to the operating channel from an off-channel operation.
  1394. */
  1395. if (!(hw->conf.flags & IEEE80211_CONF_OFFCHANNEL) &&
  1396. sc->cur_survey != &sc->survey[pos]) {
  1397. if (sc->cur_survey)
  1398. sc->cur_survey->filled &= ~SURVEY_INFO_IN_USE;
  1399. sc->cur_survey = &sc->survey[pos];
  1400. memset(sc->cur_survey, 0, sizeof(struct survey_info));
  1401. sc->cur_survey->filled |= SURVEY_INFO_IN_USE;
  1402. } else if (!(sc->survey[pos].filled & SURVEY_INFO_IN_USE)) {
  1403. memset(&sc->survey[pos], 0, sizeof(struct survey_info));
  1404. }
  1405. if (ath_set_channel(sc, hw, &sc->sc_ah->channels[pos]) < 0) {
  1406. ath_err(common, "Unable to set channel\n");
  1407. mutex_unlock(&sc->mutex);
  1408. return -EINVAL;
  1409. }
  1410. /*
  1411. * The most recent snapshot of channel->noisefloor for the old
  1412. * channel is only available after the hardware reset. Copy it to
  1413. * the survey stats now.
  1414. */
  1415. if (old_pos >= 0)
  1416. ath_update_survey_nf(sc, old_pos);
  1417. }
  1418. if (changed & IEEE80211_CONF_CHANGE_POWER) {
  1419. ath_dbg(common, ATH_DBG_CONFIG,
  1420. "Set power: %d\n", conf->power_level);
  1421. sc->config.txpowlimit = 2 * conf->power_level;
  1422. ath9k_ps_wakeup(sc);
  1423. ath9k_cmn_update_txpow(ah, sc->curtxpow,
  1424. sc->config.txpowlimit, &sc->curtxpow);
  1425. ath9k_ps_restore(sc);
  1426. }
  1427. if (disable_radio) {
  1428. ath_dbg(common, ATH_DBG_CONFIG, "idle: disabling radio\n");
  1429. ath_radio_disable(sc, hw);
  1430. }
  1431. mutex_unlock(&sc->mutex);
  1432. return 0;
  1433. }
  1434. #define SUPPORTED_FILTERS \
  1435. (FIF_PROMISC_IN_BSS | \
  1436. FIF_ALLMULTI | \
  1437. FIF_CONTROL | \
  1438. FIF_PSPOLL | \
  1439. FIF_OTHER_BSS | \
  1440. FIF_BCN_PRBRESP_PROMISC | \
  1441. FIF_PROBE_REQ | \
  1442. FIF_FCSFAIL)
  1443. /* FIXME: sc->sc_full_reset ? */
  1444. static void ath9k_configure_filter(struct ieee80211_hw *hw,
  1445. unsigned int changed_flags,
  1446. unsigned int *total_flags,
  1447. u64 multicast)
  1448. {
  1449. struct ath_softc *sc = hw->priv;
  1450. u32 rfilt;
  1451. changed_flags &= SUPPORTED_FILTERS;
  1452. *total_flags &= SUPPORTED_FILTERS;
  1453. sc->rx.rxfilter = *total_flags;
  1454. ath9k_ps_wakeup(sc);
  1455. rfilt = ath_calcrxfilter(sc);
  1456. ath9k_hw_setrxfilter(sc->sc_ah, rfilt);
  1457. ath9k_ps_restore(sc);
  1458. ath_dbg(ath9k_hw_common(sc->sc_ah), ATH_DBG_CONFIG,
  1459. "Set HW RX filter: 0x%x\n", rfilt);
  1460. }
  1461. static int ath9k_sta_add(struct ieee80211_hw *hw,
  1462. struct ieee80211_vif *vif,
  1463. struct ieee80211_sta *sta)
  1464. {
  1465. struct ath_softc *sc = hw->priv;
  1466. struct ath_common *common = ath9k_hw_common(sc->sc_ah);
  1467. struct ath_node *an = (struct ath_node *) sta->drv_priv;
  1468. struct ieee80211_key_conf ps_key = { };
  1469. ath_node_attach(sc, sta);
  1470. if (vif->type != NL80211_IFTYPE_AP &&
  1471. vif->type != NL80211_IFTYPE_AP_VLAN)
  1472. return 0;
  1473. an->ps_key = ath_key_config(common, vif, sta, &ps_key);
  1474. return 0;
  1475. }
  1476. static void ath9k_del_ps_key(struct ath_softc *sc,
  1477. struct ieee80211_vif *vif,
  1478. struct ieee80211_sta *sta)
  1479. {
  1480. struct ath_common *common = ath9k_hw_common(sc->sc_ah);
  1481. struct ath_node *an = (struct ath_node *) sta->drv_priv;
  1482. struct ieee80211_key_conf ps_key = { .hw_key_idx = an->ps_key };
  1483. if (!an->ps_key)
  1484. return;
  1485. ath_key_delete(common, &ps_key);
  1486. }
  1487. static int ath9k_sta_remove(struct ieee80211_hw *hw,
  1488. struct ieee80211_vif *vif,
  1489. struct ieee80211_sta *sta)
  1490. {
  1491. struct ath_softc *sc = hw->priv;
  1492. ath9k_del_ps_key(sc, vif, sta);
  1493. ath_node_detach(sc, sta);
  1494. return 0;
  1495. }
  1496. static void ath9k_sta_notify(struct ieee80211_hw *hw,
  1497. struct ieee80211_vif *vif,
  1498. enum sta_notify_cmd cmd,
  1499. struct ieee80211_sta *sta)
  1500. {
  1501. struct ath_softc *sc = hw->priv;
  1502. struct ath_node *an = (struct ath_node *) sta->drv_priv;
  1503. switch (cmd) {
  1504. case STA_NOTIFY_SLEEP:
  1505. an->sleeping = true;
  1506. ath_tx_aggr_sleep(sta, sc, an);
  1507. break;
  1508. case STA_NOTIFY_AWAKE:
  1509. an->sleeping = false;
  1510. ath_tx_aggr_wakeup(sc, an);
  1511. break;
  1512. }
  1513. }
  1514. static int ath9k_conf_tx(struct ieee80211_hw *hw,
  1515. struct ieee80211_vif *vif, u16 queue,
  1516. const struct ieee80211_tx_queue_params *params)
  1517. {
  1518. struct ath_softc *sc = hw->priv;
  1519. struct ath_common *common = ath9k_hw_common(sc->sc_ah);
  1520. struct ath_txq *txq;
  1521. struct ath9k_tx_queue_info qi;
  1522. int ret = 0;
  1523. if (queue >= WME_NUM_AC)
  1524. return 0;
  1525. txq = sc->tx.txq_map[queue];
  1526. ath9k_ps_wakeup(sc);
  1527. mutex_lock(&sc->mutex);
  1528. memset(&qi, 0, sizeof(struct ath9k_tx_queue_info));
  1529. qi.tqi_aifs = params->aifs;
  1530. qi.tqi_cwmin = params->cw_min;
  1531. qi.tqi_cwmax = params->cw_max;
  1532. qi.tqi_burstTime = params->txop;
  1533. ath_dbg(common, ATH_DBG_CONFIG,
  1534. "Configure tx [queue/halq] [%d/%d], aifs: %d, cw_min: %d, cw_max: %d, txop: %d\n",
  1535. queue, txq->axq_qnum, params->aifs, params->cw_min,
  1536. params->cw_max, params->txop);
  1537. ret = ath_txq_update(sc, txq->axq_qnum, &qi);
  1538. if (ret)
  1539. ath_err(common, "TXQ Update failed\n");
  1540. if (sc->sc_ah->opmode == NL80211_IFTYPE_ADHOC)
  1541. if (queue == WME_AC_BE && !ret)
  1542. ath_beaconq_config(sc);
  1543. mutex_unlock(&sc->mutex);
  1544. ath9k_ps_restore(sc);
  1545. return ret;
  1546. }
  1547. static int ath9k_set_key(struct ieee80211_hw *hw,
  1548. enum set_key_cmd cmd,
  1549. struct ieee80211_vif *vif,
  1550. struct ieee80211_sta *sta,
  1551. struct ieee80211_key_conf *key)
  1552. {
  1553. struct ath_softc *sc = hw->priv;
  1554. struct ath_common *common = ath9k_hw_common(sc->sc_ah);
  1555. int ret = 0;
  1556. if (ath9k_modparam_nohwcrypt)
  1557. return -ENOSPC;
  1558. if (vif->type == NL80211_IFTYPE_ADHOC &&
  1559. (key->cipher == WLAN_CIPHER_SUITE_TKIP ||
  1560. key->cipher == WLAN_CIPHER_SUITE_CCMP) &&
  1561. !(key->flags & IEEE80211_KEY_FLAG_PAIRWISE)) {
  1562. /*
  1563. * For now, disable hw crypto for the RSN IBSS group keys. This
  1564. * could be optimized in the future to use a modified key cache
  1565. * design to support per-STA RX GTK, but until that gets
  1566. * implemented, use of software crypto for group addressed
  1567. * frames is a acceptable to allow RSN IBSS to be used.
  1568. */
  1569. return -EOPNOTSUPP;
  1570. }
  1571. mutex_lock(&sc->mutex);
  1572. ath9k_ps_wakeup(sc);
  1573. ath_dbg(common, ATH_DBG_CONFIG, "Set HW Key\n");
  1574. switch (cmd) {
  1575. case SET_KEY:
  1576. if (sta)
  1577. ath9k_del_ps_key(sc, vif, sta);
  1578. ret = ath_key_config(common, vif, sta, key);
  1579. if (ret >= 0) {
  1580. key->hw_key_idx = ret;
  1581. /* push IV and Michael MIC generation to stack */
  1582. key->flags |= IEEE80211_KEY_FLAG_GENERATE_IV;
  1583. if (key->cipher == WLAN_CIPHER_SUITE_TKIP)
  1584. key->flags |= IEEE80211_KEY_FLAG_GENERATE_MMIC;
  1585. if (sc->sc_ah->sw_mgmt_crypto &&
  1586. key->cipher == WLAN_CIPHER_SUITE_CCMP)
  1587. key->flags |= IEEE80211_KEY_FLAG_SW_MGMT;
  1588. ret = 0;
  1589. }
  1590. break;
  1591. case DISABLE_KEY:
  1592. ath_key_delete(common, key);
  1593. break;
  1594. default:
  1595. ret = -EINVAL;
  1596. }
  1597. ath9k_ps_restore(sc);
  1598. mutex_unlock(&sc->mutex);
  1599. return ret;
  1600. }
  1601. static void ath9k_bss_iter(void *data, u8 *mac, struct ieee80211_vif *vif)
  1602. {
  1603. struct ath_softc *sc = data;
  1604. struct ath_common *common = ath9k_hw_common(sc->sc_ah);
  1605. struct ieee80211_bss_conf *bss_conf = &vif->bss_conf;
  1606. struct ath_vif *avp = (void *)vif->drv_priv;
  1607. /*
  1608. * Skip iteration if primary station vif's bss info
  1609. * was not changed
  1610. */
  1611. if (sc->sc_flags & SC_OP_PRIM_STA_VIF)
  1612. return;
  1613. if (bss_conf->assoc) {
  1614. sc->sc_flags |= SC_OP_PRIM_STA_VIF;
  1615. avp->primary_sta_vif = true;
  1616. memcpy(common->curbssid, bss_conf->bssid, ETH_ALEN);
  1617. common->curaid = bss_conf->aid;
  1618. ath9k_hw_write_associd(sc->sc_ah);
  1619. ath_dbg(common, ATH_DBG_CONFIG,
  1620. "Bss Info ASSOC %d, bssid: %pM\n",
  1621. bss_conf->aid, common->curbssid);
  1622. ath_beacon_config(sc, vif);
  1623. /*
  1624. * Request a re-configuration of Beacon related timers
  1625. * on the receipt of the first Beacon frame (i.e.,
  1626. * after time sync with the AP).
  1627. */
  1628. sc->ps_flags |= PS_BEACON_SYNC | PS_WAIT_FOR_BEACON;
  1629. /* Reset rssi stats */
  1630. sc->last_rssi = ATH_RSSI_DUMMY_MARKER;
  1631. sc->sc_ah->stats.avgbrssi = ATH_RSSI_DUMMY_MARKER;
  1632. if (!common->disable_ani) {
  1633. sc->sc_flags |= SC_OP_ANI_RUN;
  1634. ath_start_ani(common);
  1635. }
  1636. }
  1637. }
  1638. static void ath9k_config_bss(struct ath_softc *sc, struct ieee80211_vif *vif)
  1639. {
  1640. struct ath_common *common = ath9k_hw_common(sc->sc_ah);
  1641. struct ieee80211_bss_conf *bss_conf = &vif->bss_conf;
  1642. struct ath_vif *avp = (void *)vif->drv_priv;
  1643. if (sc->sc_ah->opmode != NL80211_IFTYPE_STATION)
  1644. return;
  1645. /* Reconfigure bss info */
  1646. if (avp->primary_sta_vif && !bss_conf->assoc) {
  1647. ath_dbg(common, ATH_DBG_CONFIG,
  1648. "Bss Info DISASSOC %d, bssid %pM\n",
  1649. common->curaid, common->curbssid);
  1650. sc->sc_flags &= ~(SC_OP_PRIM_STA_VIF | SC_OP_BEACONS);
  1651. avp->primary_sta_vif = false;
  1652. memset(common->curbssid, 0, ETH_ALEN);
  1653. common->curaid = 0;
  1654. }
  1655. ieee80211_iterate_active_interfaces_atomic(
  1656. sc->hw, ath9k_bss_iter, sc);
  1657. /*
  1658. * None of station vifs are associated.
  1659. * Clear bssid & aid
  1660. */
  1661. if (!(sc->sc_flags & SC_OP_PRIM_STA_VIF)) {
  1662. ath9k_hw_write_associd(sc->sc_ah);
  1663. /* Stop ANI */
  1664. sc->sc_flags &= ~SC_OP_ANI_RUN;
  1665. del_timer_sync(&common->ani.timer);
  1666. memset(&sc->caldata, 0, sizeof(sc->caldata));
  1667. }
  1668. }
  1669. static void ath9k_bss_info_changed(struct ieee80211_hw *hw,
  1670. struct ieee80211_vif *vif,
  1671. struct ieee80211_bss_conf *bss_conf,
  1672. u32 changed)
  1673. {
  1674. struct ath_softc *sc = hw->priv;
  1675. struct ath_hw *ah = sc->sc_ah;
  1676. struct ath_common *common = ath9k_hw_common(ah);
  1677. struct ath_vif *avp = (void *)vif->drv_priv;
  1678. int slottime;
  1679. int error;
  1680. ath9k_ps_wakeup(sc);
  1681. mutex_lock(&sc->mutex);
  1682. if (changed & BSS_CHANGED_BSSID) {
  1683. ath9k_config_bss(sc, vif);
  1684. ath_dbg(common, ATH_DBG_CONFIG, "BSSID: %pM aid: 0x%x\n",
  1685. common->curbssid, common->curaid);
  1686. }
  1687. if (changed & BSS_CHANGED_IBSS) {
  1688. /* There can be only one vif available */
  1689. memcpy(common->curbssid, bss_conf->bssid, ETH_ALEN);
  1690. common->curaid = bss_conf->aid;
  1691. ath9k_hw_write_associd(sc->sc_ah);
  1692. if (bss_conf->ibss_joined) {
  1693. sc->sc_ah->stats.avgbrssi = ATH_RSSI_DUMMY_MARKER;
  1694. if (!common->disable_ani) {
  1695. sc->sc_flags |= SC_OP_ANI_RUN;
  1696. ath_start_ani(common);
  1697. }
  1698. } else {
  1699. sc->sc_flags &= ~SC_OP_ANI_RUN;
  1700. del_timer_sync(&common->ani.timer);
  1701. }
  1702. }
  1703. /* Enable transmission of beacons (AP, IBSS, MESH) */
  1704. if ((changed & BSS_CHANGED_BEACON) ||
  1705. ((changed & BSS_CHANGED_BEACON_ENABLED) && bss_conf->enable_beacon)) {
  1706. ath9k_set_beaconing_status(sc, false);
  1707. error = ath_beacon_alloc(sc, vif);
  1708. if (!error)
  1709. ath_beacon_config(sc, vif);
  1710. ath9k_set_beaconing_status(sc, true);
  1711. }
  1712. if (changed & BSS_CHANGED_ERP_SLOT) {
  1713. if (bss_conf->use_short_slot)
  1714. slottime = 9;
  1715. else
  1716. slottime = 20;
  1717. if (vif->type == NL80211_IFTYPE_AP) {
  1718. /*
  1719. * Defer update, so that connected stations can adjust
  1720. * their settings at the same time.
  1721. * See beacon.c for more details
  1722. */
  1723. sc->beacon.slottime = slottime;
  1724. sc->beacon.updateslot = UPDATE;
  1725. } else {
  1726. ah->slottime = slottime;
  1727. ath9k_hw_init_global_settings(ah);
  1728. }
  1729. }
  1730. /* Disable transmission of beacons */
  1731. if ((changed & BSS_CHANGED_BEACON_ENABLED) &&
  1732. !bss_conf->enable_beacon) {
  1733. ath9k_set_beaconing_status(sc, false);
  1734. avp->is_bslot_active = false;
  1735. ath9k_set_beaconing_status(sc, true);
  1736. }
  1737. if (changed & BSS_CHANGED_BEACON_INT) {
  1738. /*
  1739. * In case of AP mode, the HW TSF has to be reset
  1740. * when the beacon interval changes.
  1741. */
  1742. if (vif->type == NL80211_IFTYPE_AP) {
  1743. sc->sc_flags |= SC_OP_TSF_RESET;
  1744. ath9k_set_beaconing_status(sc, false);
  1745. error = ath_beacon_alloc(sc, vif);
  1746. if (!error)
  1747. ath_beacon_config(sc, vif);
  1748. ath9k_set_beaconing_status(sc, true);
  1749. } else
  1750. ath_beacon_config(sc, vif);
  1751. }
  1752. if (changed & BSS_CHANGED_ERP_PREAMBLE) {
  1753. ath_dbg(common, ATH_DBG_CONFIG, "BSS Changed PREAMBLE %d\n",
  1754. bss_conf->use_short_preamble);
  1755. if (bss_conf->use_short_preamble)
  1756. sc->sc_flags |= SC_OP_PREAMBLE_SHORT;
  1757. else
  1758. sc->sc_flags &= ~SC_OP_PREAMBLE_SHORT;
  1759. }
  1760. if (changed & BSS_CHANGED_ERP_CTS_PROT) {
  1761. ath_dbg(common, ATH_DBG_CONFIG, "BSS Changed CTS PROT %d\n",
  1762. bss_conf->use_cts_prot);
  1763. if (bss_conf->use_cts_prot &&
  1764. hw->conf.channel->band != IEEE80211_BAND_5GHZ)
  1765. sc->sc_flags |= SC_OP_PROTECT_ENABLE;
  1766. else
  1767. sc->sc_flags &= ~SC_OP_PROTECT_ENABLE;
  1768. }
  1769. mutex_unlock(&sc->mutex);
  1770. ath9k_ps_restore(sc);
  1771. }
  1772. static u64 ath9k_get_tsf(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
  1773. {
  1774. struct ath_softc *sc = hw->priv;
  1775. u64 tsf;
  1776. mutex_lock(&sc->mutex);
  1777. ath9k_ps_wakeup(sc);
  1778. tsf = ath9k_hw_gettsf64(sc->sc_ah);
  1779. ath9k_ps_restore(sc);
  1780. mutex_unlock(&sc->mutex);
  1781. return tsf;
  1782. }
  1783. static void ath9k_set_tsf(struct ieee80211_hw *hw,
  1784. struct ieee80211_vif *vif,
  1785. u64 tsf)
  1786. {
  1787. struct ath_softc *sc = hw->priv;
  1788. mutex_lock(&sc->mutex);
  1789. ath9k_ps_wakeup(sc);
  1790. ath9k_hw_settsf64(sc->sc_ah, tsf);
  1791. ath9k_ps_restore(sc);
  1792. mutex_unlock(&sc->mutex);
  1793. }
  1794. static void ath9k_reset_tsf(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
  1795. {
  1796. struct ath_softc *sc = hw->priv;
  1797. mutex_lock(&sc->mutex);
  1798. ath9k_ps_wakeup(sc);
  1799. ath9k_hw_reset_tsf(sc->sc_ah);
  1800. ath9k_ps_restore(sc);
  1801. mutex_unlock(&sc->mutex);
  1802. }
  1803. static int ath9k_ampdu_action(struct ieee80211_hw *hw,
  1804. struct ieee80211_vif *vif,
  1805. enum ieee80211_ampdu_mlme_action action,
  1806. struct ieee80211_sta *sta,
  1807. u16 tid, u16 *ssn, u8 buf_size)
  1808. {
  1809. struct ath_softc *sc = hw->priv;
  1810. int ret = 0;
  1811. local_bh_disable();
  1812. switch (action) {
  1813. case IEEE80211_AMPDU_RX_START:
  1814. if (!(sc->sc_flags & SC_OP_RXAGGR))
  1815. ret = -ENOTSUPP;
  1816. break;
  1817. case IEEE80211_AMPDU_RX_STOP:
  1818. break;
  1819. case IEEE80211_AMPDU_TX_START:
  1820. if (!(sc->sc_flags & SC_OP_TXAGGR))
  1821. return -EOPNOTSUPP;
  1822. ath9k_ps_wakeup(sc);
  1823. ret = ath_tx_aggr_start(sc, sta, tid, ssn);
  1824. if (!ret)
  1825. ieee80211_start_tx_ba_cb_irqsafe(vif, sta->addr, tid);
  1826. ath9k_ps_restore(sc);
  1827. break;
  1828. case IEEE80211_AMPDU_TX_STOP:
  1829. ath9k_ps_wakeup(sc);
  1830. ath_tx_aggr_stop(sc, sta, tid);
  1831. ieee80211_stop_tx_ba_cb_irqsafe(vif, sta->addr, tid);
  1832. ath9k_ps_restore(sc);
  1833. break;
  1834. case IEEE80211_AMPDU_TX_OPERATIONAL:
  1835. ath9k_ps_wakeup(sc);
  1836. ath_tx_aggr_resume(sc, sta, tid);
  1837. ath9k_ps_restore(sc);
  1838. break;
  1839. default:
  1840. ath_err(ath9k_hw_common(sc->sc_ah), "Unknown AMPDU action\n");
  1841. }
  1842. local_bh_enable();
  1843. return ret;
  1844. }
  1845. static int ath9k_get_survey(struct ieee80211_hw *hw, int idx,
  1846. struct survey_info *survey)
  1847. {
  1848. struct ath_softc *sc = hw->priv;
  1849. struct ath_common *common = ath9k_hw_common(sc->sc_ah);
  1850. struct ieee80211_supported_band *sband;
  1851. struct ieee80211_channel *chan;
  1852. unsigned long flags;
  1853. int pos;
  1854. spin_lock_irqsave(&common->cc_lock, flags);
  1855. if (idx == 0)
  1856. ath_update_survey_stats(sc);
  1857. sband = hw->wiphy->bands[IEEE80211_BAND_2GHZ];
  1858. if (sband && idx >= sband->n_channels) {
  1859. idx -= sband->n_channels;
  1860. sband = NULL;
  1861. }
  1862. if (!sband)
  1863. sband = hw->wiphy->bands[IEEE80211_BAND_5GHZ];
  1864. if (!sband || idx >= sband->n_channels) {
  1865. spin_unlock_irqrestore(&common->cc_lock, flags);
  1866. return -ENOENT;
  1867. }
  1868. chan = &sband->channels[idx];
  1869. pos = chan->hw_value;
  1870. memcpy(survey, &sc->survey[pos], sizeof(*survey));
  1871. survey->channel = chan;
  1872. spin_unlock_irqrestore(&common->cc_lock, flags);
  1873. return 0;
  1874. }
  1875. static void ath9k_set_coverage_class(struct ieee80211_hw *hw, u8 coverage_class)
  1876. {
  1877. struct ath_softc *sc = hw->priv;
  1878. struct ath_hw *ah = sc->sc_ah;
  1879. mutex_lock(&sc->mutex);
  1880. ah->coverage_class = coverage_class;
  1881. ath9k_ps_wakeup(sc);
  1882. ath9k_hw_init_global_settings(ah);
  1883. ath9k_ps_restore(sc);
  1884. mutex_unlock(&sc->mutex);
  1885. }
  1886. static void ath9k_flush(struct ieee80211_hw *hw, bool drop)
  1887. {
  1888. struct ath_softc *sc = hw->priv;
  1889. struct ath_hw *ah = sc->sc_ah;
  1890. struct ath_common *common = ath9k_hw_common(ah);
  1891. int timeout = 200; /* ms */
  1892. int i, j;
  1893. bool drain_txq;
  1894. mutex_lock(&sc->mutex);
  1895. cancel_delayed_work_sync(&sc->tx_complete_work);
  1896. if (ah->ah_flags & AH_UNPLUGGED) {
  1897. ath_dbg(common, ATH_DBG_ANY, "Device has been unplugged!\n");
  1898. mutex_unlock(&sc->mutex);
  1899. return;
  1900. }
  1901. if (sc->sc_flags & SC_OP_INVALID) {
  1902. ath_dbg(common, ATH_DBG_ANY, "Device not present\n");
  1903. mutex_unlock(&sc->mutex);
  1904. return;
  1905. }
  1906. if (drop)
  1907. timeout = 1;
  1908. for (j = 0; j < timeout; j++) {
  1909. bool npend = false;
  1910. if (j)
  1911. usleep_range(1000, 2000);
  1912. for (i = 0; i < ATH9K_NUM_TX_QUEUES; i++) {
  1913. if (!ATH_TXQ_SETUP(sc, i))
  1914. continue;
  1915. npend = ath9k_has_pending_frames(sc, &sc->tx.txq[i]);
  1916. if (npend)
  1917. break;
  1918. }
  1919. if (!npend)
  1920. goto out;
  1921. }
  1922. ath9k_ps_wakeup(sc);
  1923. spin_lock_bh(&sc->sc_pcu_lock);
  1924. drain_txq = ath_drain_all_txq(sc, false);
  1925. spin_unlock_bh(&sc->sc_pcu_lock);
  1926. if (!drain_txq)
  1927. ath_reset(sc, false);
  1928. ath9k_ps_restore(sc);
  1929. ieee80211_wake_queues(hw);
  1930. out:
  1931. ieee80211_queue_delayed_work(hw, &sc->tx_complete_work, 0);
  1932. mutex_unlock(&sc->mutex);
  1933. }
  1934. static bool ath9k_tx_frames_pending(struct ieee80211_hw *hw)
  1935. {
  1936. struct ath_softc *sc = hw->priv;
  1937. int i;
  1938. for (i = 0; i < ATH9K_NUM_TX_QUEUES; i++) {
  1939. if (!ATH_TXQ_SETUP(sc, i))
  1940. continue;
  1941. if (ath9k_has_pending_frames(sc, &sc->tx.txq[i]))
  1942. return true;
  1943. }
  1944. return false;
  1945. }
  1946. static int ath9k_tx_last_beacon(struct ieee80211_hw *hw)
  1947. {
  1948. struct ath_softc *sc = hw->priv;
  1949. struct ath_hw *ah = sc->sc_ah;
  1950. struct ieee80211_vif *vif;
  1951. struct ath_vif *avp;
  1952. struct ath_buf *bf;
  1953. struct ath_tx_status ts;
  1954. int status;
  1955. vif = sc->beacon.bslot[0];
  1956. if (!vif)
  1957. return 0;
  1958. avp = (void *)vif->drv_priv;
  1959. if (!avp->is_bslot_active)
  1960. return 0;
  1961. if (!sc->beacon.tx_processed) {
  1962. tasklet_disable(&sc->bcon_tasklet);
  1963. bf = avp->av_bcbuf;
  1964. if (!bf || !bf->bf_mpdu)
  1965. goto skip;
  1966. status = ath9k_hw_txprocdesc(ah, bf->bf_desc, &ts);
  1967. if (status == -EINPROGRESS)
  1968. goto skip;
  1969. sc->beacon.tx_processed = true;
  1970. sc->beacon.tx_last = !(ts.ts_status & ATH9K_TXERR_MASK);
  1971. skip:
  1972. tasklet_enable(&sc->bcon_tasklet);
  1973. }
  1974. return sc->beacon.tx_last;
  1975. }
  1976. static int ath9k_get_stats(struct ieee80211_hw *hw,
  1977. struct ieee80211_low_level_stats *stats)
  1978. {
  1979. struct ath_softc *sc = hw->priv;
  1980. struct ath_hw *ah = sc->sc_ah;
  1981. struct ath9k_mib_stats *mib_stats = &ah->ah_mibStats;
  1982. stats->dot11ACKFailureCount = mib_stats->ackrcv_bad;
  1983. stats->dot11RTSFailureCount = mib_stats->rts_bad;
  1984. stats->dot11FCSErrorCount = mib_stats->fcs_bad;
  1985. stats->dot11RTSSuccessCount = mib_stats->rts_good;
  1986. return 0;
  1987. }
  1988. static u32 fill_chainmask(u32 cap, u32 new)
  1989. {
  1990. u32 filled = 0;
  1991. int i;
  1992. for (i = 0; cap && new; i++, cap >>= 1) {
  1993. if (!(cap & BIT(0)))
  1994. continue;
  1995. if (new & BIT(0))
  1996. filled |= BIT(i);
  1997. new >>= 1;
  1998. }
  1999. return filled;
  2000. }
  2001. static int ath9k_set_antenna(struct ieee80211_hw *hw, u32 tx_ant, u32 rx_ant)
  2002. {
  2003. struct ath_softc *sc = hw->priv;
  2004. struct ath_hw *ah = sc->sc_ah;
  2005. if (!rx_ant || !tx_ant)
  2006. return -EINVAL;
  2007. sc->ant_rx = rx_ant;
  2008. sc->ant_tx = tx_ant;
  2009. if (ah->caps.rx_chainmask == 1)
  2010. return 0;
  2011. /* AR9100 runs into calibration issues if not all rx chains are enabled */
  2012. if (AR_SREV_9100(ah))
  2013. ah->rxchainmask = 0x7;
  2014. else
  2015. ah->rxchainmask = fill_chainmask(ah->caps.rx_chainmask, rx_ant);
  2016. ah->txchainmask = fill_chainmask(ah->caps.tx_chainmask, tx_ant);
  2017. ath9k_reload_chainmask_settings(sc);
  2018. return 0;
  2019. }
  2020. static int ath9k_get_antenna(struct ieee80211_hw *hw, u32 *tx_ant, u32 *rx_ant)
  2021. {
  2022. struct ath_softc *sc = hw->priv;
  2023. *tx_ant = sc->ant_tx;
  2024. *rx_ant = sc->ant_rx;
  2025. return 0;
  2026. }
  2027. struct ieee80211_ops ath9k_ops = {
  2028. .tx = ath9k_tx,
  2029. .start = ath9k_start,
  2030. .stop = ath9k_stop,
  2031. .add_interface = ath9k_add_interface,
  2032. .change_interface = ath9k_change_interface,
  2033. .remove_interface = ath9k_remove_interface,
  2034. .config = ath9k_config,
  2035. .configure_filter = ath9k_configure_filter,
  2036. .sta_add = ath9k_sta_add,
  2037. .sta_remove = ath9k_sta_remove,
  2038. .sta_notify = ath9k_sta_notify,
  2039. .conf_tx = ath9k_conf_tx,
  2040. .bss_info_changed = ath9k_bss_info_changed,
  2041. .set_key = ath9k_set_key,
  2042. .get_tsf = ath9k_get_tsf,
  2043. .set_tsf = ath9k_set_tsf,
  2044. .reset_tsf = ath9k_reset_tsf,
  2045. .ampdu_action = ath9k_ampdu_action,
  2046. .get_survey = ath9k_get_survey,
  2047. .rfkill_poll = ath9k_rfkill_poll_state,
  2048. .set_coverage_class = ath9k_set_coverage_class,
  2049. .flush = ath9k_flush,
  2050. .tx_frames_pending = ath9k_tx_frames_pending,
  2051. .tx_last_beacon = ath9k_tx_last_beacon,
  2052. .get_stats = ath9k_get_stats,
  2053. .set_antenna = ath9k_set_antenna,
  2054. .get_antenna = ath9k_get_antenna,
  2055. };