main.c 60 KB

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