main.c 59 KB

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