main.c 51 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073
  1. /*
  2. * Copyright (c) 2008-2009 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 "ath9k.h"
  18. #include "btcoex.h"
  19. static void ath_cache_conf_rate(struct ath_softc *sc,
  20. struct ieee80211_conf *conf)
  21. {
  22. switch (conf->channel->band) {
  23. case IEEE80211_BAND_2GHZ:
  24. if (conf_is_ht20(conf))
  25. sc->cur_rate_mode = ATH9K_MODE_11NG_HT20;
  26. else if (conf_is_ht40_minus(conf))
  27. sc->cur_rate_mode = ATH9K_MODE_11NG_HT40MINUS;
  28. else if (conf_is_ht40_plus(conf))
  29. sc->cur_rate_mode = ATH9K_MODE_11NG_HT40PLUS;
  30. else
  31. sc->cur_rate_mode = ATH9K_MODE_11G;
  32. break;
  33. case IEEE80211_BAND_5GHZ:
  34. if (conf_is_ht20(conf))
  35. sc->cur_rate_mode = ATH9K_MODE_11NA_HT20;
  36. else if (conf_is_ht40_minus(conf))
  37. sc->cur_rate_mode = ATH9K_MODE_11NA_HT40MINUS;
  38. else if (conf_is_ht40_plus(conf))
  39. sc->cur_rate_mode = ATH9K_MODE_11NA_HT40PLUS;
  40. else
  41. sc->cur_rate_mode = ATH9K_MODE_11A;
  42. break;
  43. default:
  44. BUG_ON(1);
  45. break;
  46. }
  47. }
  48. static void ath_update_txpow(struct ath_softc *sc)
  49. {
  50. struct ath_hw *ah = sc->sc_ah;
  51. if (sc->curtxpow != sc->config.txpowlimit) {
  52. ath9k_hw_set_txpowerlimit(ah, sc->config.txpowlimit);
  53. /* read back in case value is clamped */
  54. sc->curtxpow = ath9k_hw_regulatory(ah)->power_limit;
  55. }
  56. }
  57. static u8 parse_mpdudensity(u8 mpdudensity)
  58. {
  59. /*
  60. * 802.11n D2.0 defined values for "Minimum MPDU Start Spacing":
  61. * 0 for no restriction
  62. * 1 for 1/4 us
  63. * 2 for 1/2 us
  64. * 3 for 1 us
  65. * 4 for 2 us
  66. * 5 for 4 us
  67. * 6 for 8 us
  68. * 7 for 16 us
  69. */
  70. switch (mpdudensity) {
  71. case 0:
  72. return 0;
  73. case 1:
  74. case 2:
  75. case 3:
  76. /* Our lower layer calculations limit our precision to
  77. 1 microsecond */
  78. return 1;
  79. case 4:
  80. return 2;
  81. case 5:
  82. return 4;
  83. case 6:
  84. return 8;
  85. case 7:
  86. return 16;
  87. default:
  88. return 0;
  89. }
  90. }
  91. static struct ath9k_channel *ath_get_curchannel(struct ath_softc *sc,
  92. struct ieee80211_hw *hw)
  93. {
  94. struct ieee80211_channel *curchan = hw->conf.channel;
  95. struct ath9k_channel *channel;
  96. u8 chan_idx;
  97. chan_idx = curchan->hw_value;
  98. channel = &sc->sc_ah->channels[chan_idx];
  99. ath9k_update_ichannel(sc, hw, channel);
  100. return channel;
  101. }
  102. bool ath9k_setpower(struct ath_softc *sc, enum ath9k_power_mode mode)
  103. {
  104. unsigned long flags;
  105. bool ret;
  106. spin_lock_irqsave(&sc->sc_pm_lock, flags);
  107. ret = ath9k_hw_setpower(sc->sc_ah, mode);
  108. spin_unlock_irqrestore(&sc->sc_pm_lock, flags);
  109. return ret;
  110. }
  111. void ath9k_ps_wakeup(struct ath_softc *sc)
  112. {
  113. unsigned long flags;
  114. spin_lock_irqsave(&sc->sc_pm_lock, flags);
  115. if (++sc->ps_usecount != 1)
  116. goto unlock;
  117. ath9k_hw_setpower(sc->sc_ah, ATH9K_PM_AWAKE);
  118. unlock:
  119. spin_unlock_irqrestore(&sc->sc_pm_lock, flags);
  120. }
  121. void ath9k_ps_restore(struct ath_softc *sc)
  122. {
  123. unsigned long flags;
  124. spin_lock_irqsave(&sc->sc_pm_lock, flags);
  125. if (--sc->ps_usecount != 0)
  126. goto unlock;
  127. if (sc->ps_idle)
  128. ath9k_hw_setpower(sc->sc_ah, ATH9K_PM_FULL_SLEEP);
  129. else if (sc->ps_enabled &&
  130. !(sc->ps_flags & (PS_WAIT_FOR_BEACON |
  131. PS_WAIT_FOR_CAB |
  132. PS_WAIT_FOR_PSPOLL_DATA |
  133. PS_WAIT_FOR_TX_ACK)))
  134. ath9k_hw_setpower(sc->sc_ah, ATH9K_PM_NETWORK_SLEEP);
  135. unlock:
  136. spin_unlock_irqrestore(&sc->sc_pm_lock, flags);
  137. }
  138. /*
  139. * Set/change channels. If the channel is really being changed, it's done
  140. * by reseting the chip. To accomplish this we must first cleanup any pending
  141. * DMA, then restart stuff.
  142. */
  143. int ath_set_channel(struct ath_softc *sc, struct ieee80211_hw *hw,
  144. struct ath9k_channel *hchan)
  145. {
  146. struct ath_hw *ah = sc->sc_ah;
  147. struct ath_common *common = ath9k_hw_common(ah);
  148. struct ieee80211_conf *conf = &common->hw->conf;
  149. bool fastcc = true, stopped;
  150. struct ieee80211_channel *channel = hw->conf.channel;
  151. int r;
  152. if (sc->sc_flags & SC_OP_INVALID)
  153. return -EIO;
  154. ath9k_ps_wakeup(sc);
  155. /*
  156. * This is only performed if the channel settings have
  157. * actually changed.
  158. *
  159. * To switch channels clear any pending DMA operations;
  160. * wait long enough for the RX fifo to drain, reset the
  161. * hardware at the new frequency, and then re-enable
  162. * the relevant bits of the h/w.
  163. */
  164. ath9k_hw_set_interrupts(ah, 0);
  165. ath_drain_all_txq(sc, false);
  166. stopped = ath_stoprecv(sc);
  167. /* XXX: do not flush receive queue here. We don't want
  168. * to flush data frames already in queue because of
  169. * changing channel. */
  170. if (!stopped || (sc->sc_flags & SC_OP_FULL_RESET))
  171. fastcc = false;
  172. ath_print(common, ATH_DBG_CONFIG,
  173. "(%u MHz) -> (%u MHz), conf_is_ht40: %d\n",
  174. sc->sc_ah->curchan->channel,
  175. channel->center_freq, conf_is_ht40(conf));
  176. spin_lock_bh(&sc->sc_resetlock);
  177. r = ath9k_hw_reset(ah, hchan, fastcc);
  178. if (r) {
  179. ath_print(common, ATH_DBG_FATAL,
  180. "Unable to reset channel (%u MHz), "
  181. "reset status %d\n",
  182. channel->center_freq, r);
  183. spin_unlock_bh(&sc->sc_resetlock);
  184. goto ps_restore;
  185. }
  186. spin_unlock_bh(&sc->sc_resetlock);
  187. sc->sc_flags &= ~SC_OP_FULL_RESET;
  188. if (ath_startrecv(sc) != 0) {
  189. ath_print(common, ATH_DBG_FATAL,
  190. "Unable to restart recv logic\n");
  191. r = -EIO;
  192. goto ps_restore;
  193. }
  194. ath_cache_conf_rate(sc, &hw->conf);
  195. ath_update_txpow(sc);
  196. ath9k_hw_set_interrupts(ah, ah->imask);
  197. ps_restore:
  198. ath9k_ps_restore(sc);
  199. return r;
  200. }
  201. static void ath_paprd_activate(struct ath_softc *sc)
  202. {
  203. struct ath_hw *ah = sc->sc_ah;
  204. int chain;
  205. if (!ah->curchan->paprd_done)
  206. return;
  207. ath9k_ps_wakeup(sc);
  208. ar9003_paprd_enable(ah, false);
  209. for (chain = 0; chain < AR9300_MAX_CHAINS; chain++) {
  210. if (!(ah->caps.tx_chainmask & BIT(chain)))
  211. continue;
  212. ar9003_paprd_populate_single_table(ah, ah->curchan, chain);
  213. }
  214. ar9003_paprd_enable(ah, true);
  215. ath9k_ps_restore(sc);
  216. }
  217. void ath_paprd_calibrate(struct work_struct *work)
  218. {
  219. struct ath_softc *sc = container_of(work, struct ath_softc, paprd_work);
  220. struct ieee80211_hw *hw = sc->hw;
  221. struct ath_hw *ah = sc->sc_ah;
  222. struct ieee80211_hdr *hdr;
  223. struct sk_buff *skb = NULL;
  224. struct ieee80211_tx_info *tx_info;
  225. int band = hw->conf.channel->band;
  226. struct ieee80211_supported_band *sband = &sc->sbands[band];
  227. struct ath_tx_control txctl;
  228. int qnum, ftype;
  229. int chain_ok = 0;
  230. int chain;
  231. int len = 1800;
  232. int time_left;
  233. int i;
  234. skb = alloc_skb(len, GFP_KERNEL);
  235. if (!skb)
  236. return;
  237. tx_info = IEEE80211_SKB_CB(skb);
  238. skb_put(skb, len);
  239. memset(skb->data, 0, len);
  240. hdr = (struct ieee80211_hdr *)skb->data;
  241. ftype = IEEE80211_FTYPE_DATA | IEEE80211_STYPE_NULLFUNC;
  242. hdr->frame_control = cpu_to_le16(ftype);
  243. hdr->duration_id = cpu_to_le16(10);
  244. memcpy(hdr->addr1, hw->wiphy->perm_addr, ETH_ALEN);
  245. memcpy(hdr->addr2, hw->wiphy->perm_addr, ETH_ALEN);
  246. memcpy(hdr->addr3, hw->wiphy->perm_addr, ETH_ALEN);
  247. memset(&txctl, 0, sizeof(txctl));
  248. qnum = sc->tx.hwq_map[WME_AC_BE];
  249. txctl.txq = &sc->tx.txq[qnum];
  250. ath9k_ps_wakeup(sc);
  251. ar9003_paprd_init_table(ah);
  252. for (chain = 0; chain < AR9300_MAX_CHAINS; chain++) {
  253. if (!(ah->caps.tx_chainmask & BIT(chain)))
  254. continue;
  255. chain_ok = 0;
  256. memset(tx_info, 0, sizeof(*tx_info));
  257. tx_info->band = band;
  258. for (i = 0; i < 4; i++) {
  259. tx_info->control.rates[i].idx = sband->n_bitrates - 1;
  260. tx_info->control.rates[i].count = 6;
  261. }
  262. init_completion(&sc->paprd_complete);
  263. ar9003_paprd_setup_gain_table(ah, chain);
  264. txctl.paprd = BIT(chain);
  265. if (ath_tx_start(hw, skb, &txctl) != 0)
  266. break;
  267. time_left = wait_for_completion_timeout(&sc->paprd_complete,
  268. msecs_to_jiffies(ATH_PAPRD_TIMEOUT));
  269. if (!time_left) {
  270. ath_print(ath9k_hw_common(ah), ATH_DBG_CALIBRATE,
  271. "Timeout waiting for paprd training on "
  272. "TX chain %d\n",
  273. chain);
  274. goto fail_paprd;
  275. }
  276. if (!ar9003_paprd_is_done(ah))
  277. break;
  278. if (ar9003_paprd_create_curve(ah, ah->curchan, chain) != 0)
  279. break;
  280. chain_ok = 1;
  281. }
  282. kfree_skb(skb);
  283. if (chain_ok) {
  284. ah->curchan->paprd_done = true;
  285. ath_paprd_activate(sc);
  286. }
  287. fail_paprd:
  288. ath9k_ps_restore(sc);
  289. }
  290. /*
  291. * This routine performs the periodic noise floor calibration function
  292. * that is used to adjust and optimize the chip performance. This
  293. * takes environmental changes (location, temperature) into account.
  294. * When the task is complete, it reschedules itself depending on the
  295. * appropriate interval that was calculated.
  296. */
  297. void ath_ani_calibrate(unsigned long data)
  298. {
  299. struct ath_softc *sc = (struct ath_softc *)data;
  300. struct ath_hw *ah = sc->sc_ah;
  301. struct ath_common *common = ath9k_hw_common(ah);
  302. bool longcal = false;
  303. bool shortcal = false;
  304. bool aniflag = false;
  305. unsigned int timestamp = jiffies_to_msecs(jiffies);
  306. u32 cal_interval, short_cal_interval;
  307. short_cal_interval = (ah->opmode == NL80211_IFTYPE_AP) ?
  308. ATH_AP_SHORT_CALINTERVAL : ATH_STA_SHORT_CALINTERVAL;
  309. /* Only calibrate if awake */
  310. if (sc->sc_ah->power_mode != ATH9K_PM_AWAKE)
  311. goto set_timer;
  312. ath9k_ps_wakeup(sc);
  313. /* Long calibration runs independently of short calibration. */
  314. if ((timestamp - common->ani.longcal_timer) >= ATH_LONG_CALINTERVAL) {
  315. longcal = true;
  316. ath_print(common, ATH_DBG_ANI, "longcal @%lu\n", jiffies);
  317. common->ani.longcal_timer = timestamp;
  318. }
  319. /* Short calibration applies only while caldone is false */
  320. if (!common->ani.caldone) {
  321. if ((timestamp - common->ani.shortcal_timer) >= short_cal_interval) {
  322. shortcal = true;
  323. ath_print(common, ATH_DBG_ANI,
  324. "shortcal @%lu\n", jiffies);
  325. common->ani.shortcal_timer = timestamp;
  326. common->ani.resetcal_timer = timestamp;
  327. }
  328. } else {
  329. if ((timestamp - common->ani.resetcal_timer) >=
  330. ATH_RESTART_CALINTERVAL) {
  331. common->ani.caldone = ath9k_hw_reset_calvalid(ah);
  332. if (common->ani.caldone)
  333. common->ani.resetcal_timer = timestamp;
  334. }
  335. }
  336. /* Verify whether we must check ANI */
  337. if ((timestamp - common->ani.checkani_timer) >=
  338. ah->config.ani_poll_interval) {
  339. aniflag = true;
  340. common->ani.checkani_timer = timestamp;
  341. }
  342. /* Skip all processing if there's nothing to do. */
  343. if (longcal || shortcal || aniflag) {
  344. /* Call ANI routine if necessary */
  345. if (aniflag)
  346. ath9k_hw_ani_monitor(ah, ah->curchan);
  347. /* Perform calibration if necessary */
  348. if (longcal || shortcal) {
  349. common->ani.caldone =
  350. ath9k_hw_calibrate(ah,
  351. ah->curchan,
  352. common->rx_chainmask,
  353. longcal);
  354. if (longcal)
  355. common->ani.noise_floor = ath9k_hw_getchan_noise(ah,
  356. ah->curchan);
  357. ath_print(common, ATH_DBG_ANI,
  358. " calibrate chan %u/%x nf: %d\n",
  359. ah->curchan->channel,
  360. ah->curchan->channelFlags,
  361. common->ani.noise_floor);
  362. }
  363. }
  364. ath9k_ps_restore(sc);
  365. set_timer:
  366. /*
  367. * Set timer interval based on previous results.
  368. * The interval must be the shortest necessary to satisfy ANI,
  369. * short calibration and long calibration.
  370. */
  371. cal_interval = ATH_LONG_CALINTERVAL;
  372. if (sc->sc_ah->config.enable_ani)
  373. cal_interval = min(cal_interval,
  374. (u32)ah->config.ani_poll_interval);
  375. if (!common->ani.caldone)
  376. cal_interval = min(cal_interval, (u32)short_cal_interval);
  377. mod_timer(&common->ani.timer, jiffies + msecs_to_jiffies(cal_interval));
  378. if ((sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_PAPRD) &&
  379. !(sc->sc_flags & SC_OP_SCANNING)) {
  380. if (!sc->sc_ah->curchan->paprd_done)
  381. ieee80211_queue_work(sc->hw, &sc->paprd_work);
  382. else
  383. ath_paprd_activate(sc);
  384. }
  385. }
  386. static void ath_start_ani(struct ath_common *common)
  387. {
  388. struct ath_hw *ah = common->ah;
  389. unsigned long timestamp = jiffies_to_msecs(jiffies);
  390. struct ath_softc *sc = (struct ath_softc *) common->priv;
  391. if (!(sc->sc_flags & SC_OP_ANI_RUN))
  392. return;
  393. common->ani.longcal_timer = timestamp;
  394. common->ani.shortcal_timer = timestamp;
  395. common->ani.checkani_timer = timestamp;
  396. mod_timer(&common->ani.timer,
  397. jiffies +
  398. msecs_to_jiffies((u32)ah->config.ani_poll_interval));
  399. }
  400. /*
  401. * Update tx/rx chainmask. For legacy association,
  402. * hard code chainmask to 1x1, for 11n association, use
  403. * the chainmask configuration, for bt coexistence, use
  404. * the chainmask configuration even in legacy mode.
  405. */
  406. void ath_update_chainmask(struct ath_softc *sc, int is_ht)
  407. {
  408. struct ath_hw *ah = sc->sc_ah;
  409. struct ath_common *common = ath9k_hw_common(ah);
  410. if ((sc->sc_flags & SC_OP_SCANNING) || is_ht ||
  411. (ah->btcoex_hw.scheme != ATH_BTCOEX_CFG_NONE)) {
  412. common->tx_chainmask = ah->caps.tx_chainmask;
  413. common->rx_chainmask = ah->caps.rx_chainmask;
  414. } else {
  415. common->tx_chainmask = 1;
  416. common->rx_chainmask = 1;
  417. }
  418. ath_print(common, ATH_DBG_CONFIG,
  419. "tx chmask: %d, rx chmask: %d\n",
  420. common->tx_chainmask,
  421. common->rx_chainmask);
  422. }
  423. static void ath_node_attach(struct ath_softc *sc, struct ieee80211_sta *sta)
  424. {
  425. struct ath_node *an;
  426. an = (struct ath_node *)sta->drv_priv;
  427. if (sc->sc_flags & SC_OP_TXAGGR) {
  428. ath_tx_node_init(sc, an);
  429. an->maxampdu = 1 << (IEEE80211_HT_MAX_AMPDU_FACTOR +
  430. sta->ht_cap.ampdu_factor);
  431. an->mpdudensity = parse_mpdudensity(sta->ht_cap.ampdu_density);
  432. an->last_rssi = ATH_RSSI_DUMMY_MARKER;
  433. }
  434. }
  435. static void ath_node_detach(struct ath_softc *sc, struct ieee80211_sta *sta)
  436. {
  437. struct ath_node *an = (struct ath_node *)sta->drv_priv;
  438. if (sc->sc_flags & SC_OP_TXAGGR)
  439. ath_tx_node_cleanup(sc, an);
  440. }
  441. void ath_hw_check(struct work_struct *work)
  442. {
  443. struct ath_softc *sc = container_of(work, struct ath_softc, hw_check_work);
  444. int i;
  445. ath9k_ps_wakeup(sc);
  446. for (i = 0; i < 3; i++) {
  447. if (ath9k_hw_check_alive(sc->sc_ah))
  448. goto out;
  449. msleep(1);
  450. }
  451. ath_reset(sc, false);
  452. out:
  453. ath9k_ps_restore(sc);
  454. }
  455. void ath9k_tasklet(unsigned long data)
  456. {
  457. struct ath_softc *sc = (struct ath_softc *)data;
  458. struct ath_hw *ah = sc->sc_ah;
  459. struct ath_common *common = ath9k_hw_common(ah);
  460. u32 status = sc->intrstatus;
  461. u32 rxmask;
  462. ath9k_ps_wakeup(sc);
  463. if (status & ATH9K_INT_FATAL) {
  464. ath_reset(sc, false);
  465. ath9k_ps_restore(sc);
  466. return;
  467. }
  468. if (!ath9k_hw_check_alive(ah))
  469. ieee80211_queue_work(sc->hw, &sc->hw_check_work);
  470. if (ah->caps.hw_caps & ATH9K_HW_CAP_EDMA)
  471. rxmask = (ATH9K_INT_RXHP | ATH9K_INT_RXLP | ATH9K_INT_RXEOL |
  472. ATH9K_INT_RXORN);
  473. else
  474. rxmask = (ATH9K_INT_RX | ATH9K_INT_RXEOL | ATH9K_INT_RXORN);
  475. if (status & rxmask) {
  476. spin_lock_bh(&sc->rx.rxflushlock);
  477. /* Check for high priority Rx first */
  478. if ((ah->caps.hw_caps & ATH9K_HW_CAP_EDMA) &&
  479. (status & ATH9K_INT_RXHP))
  480. ath_rx_tasklet(sc, 0, true);
  481. ath_rx_tasklet(sc, 0, false);
  482. spin_unlock_bh(&sc->rx.rxflushlock);
  483. }
  484. if (status & ATH9K_INT_TX) {
  485. if (ah->caps.hw_caps & ATH9K_HW_CAP_EDMA)
  486. ath_tx_edma_tasklet(sc);
  487. else
  488. ath_tx_tasklet(sc);
  489. }
  490. if ((status & ATH9K_INT_TSFOOR) && sc->ps_enabled) {
  491. /*
  492. * TSF sync does not look correct; remain awake to sync with
  493. * the next Beacon.
  494. */
  495. ath_print(common, ATH_DBG_PS,
  496. "TSFOOR - Sync with next Beacon\n");
  497. sc->ps_flags |= PS_WAIT_FOR_BEACON | PS_BEACON_SYNC;
  498. }
  499. if (ah->btcoex_hw.scheme == ATH_BTCOEX_CFG_3WIRE)
  500. if (status & ATH9K_INT_GENTIMER)
  501. ath_gen_timer_isr(sc->sc_ah);
  502. /* re-enable hardware interrupt */
  503. ath9k_hw_set_interrupts(ah, ah->imask);
  504. ath9k_ps_restore(sc);
  505. }
  506. irqreturn_t ath_isr(int irq, void *dev)
  507. {
  508. #define SCHED_INTR ( \
  509. ATH9K_INT_FATAL | \
  510. ATH9K_INT_RXORN | \
  511. ATH9K_INT_RXEOL | \
  512. ATH9K_INT_RX | \
  513. ATH9K_INT_RXLP | \
  514. ATH9K_INT_RXHP | \
  515. ATH9K_INT_TX | \
  516. ATH9K_INT_BMISS | \
  517. ATH9K_INT_CST | \
  518. ATH9K_INT_TSFOOR | \
  519. ATH9K_INT_GENTIMER)
  520. struct ath_softc *sc = dev;
  521. struct ath_hw *ah = sc->sc_ah;
  522. enum ath9k_int status;
  523. bool sched = false;
  524. /*
  525. * The hardware is not ready/present, don't
  526. * touch anything. Note this can happen early
  527. * on if the IRQ is shared.
  528. */
  529. if (sc->sc_flags & SC_OP_INVALID)
  530. return IRQ_NONE;
  531. /* shared irq, not for us */
  532. if (!ath9k_hw_intrpend(ah))
  533. return IRQ_NONE;
  534. /*
  535. * Figure out the reason(s) for the interrupt. Note
  536. * that the hal returns a pseudo-ISR that may include
  537. * bits we haven't explicitly enabled so we mask the
  538. * value to insure we only process bits we requested.
  539. */
  540. ath9k_hw_getisr(ah, &status); /* NB: clears ISR too */
  541. status &= ah->imask; /* discard unasked-for bits */
  542. /*
  543. * If there are no status bits set, then this interrupt was not
  544. * for me (should have been caught above).
  545. */
  546. if (!status)
  547. return IRQ_NONE;
  548. /* Cache the status */
  549. sc->intrstatus = status;
  550. if (status & SCHED_INTR)
  551. sched = true;
  552. /*
  553. * If a FATAL or RXORN interrupt is received, we have to reset the
  554. * chip immediately.
  555. */
  556. if ((status & ATH9K_INT_FATAL) || ((status & ATH9K_INT_RXORN) &&
  557. !(ah->caps.hw_caps & ATH9K_HW_CAP_EDMA)))
  558. goto chip_reset;
  559. if ((ah->caps.hw_caps & ATH9K_HW_CAP_EDMA) &&
  560. (status & ATH9K_INT_BB_WATCHDOG)) {
  561. ar9003_hw_bb_watchdog_dbg_info(ah);
  562. goto chip_reset;
  563. }
  564. if (status & ATH9K_INT_SWBA)
  565. tasklet_schedule(&sc->bcon_tasklet);
  566. if (status & ATH9K_INT_TXURN)
  567. ath9k_hw_updatetxtriglevel(ah, true);
  568. if (ah->caps.hw_caps & ATH9K_HW_CAP_EDMA) {
  569. if (status & ATH9K_INT_RXEOL) {
  570. ah->imask &= ~(ATH9K_INT_RXEOL | ATH9K_INT_RXORN);
  571. ath9k_hw_set_interrupts(ah, ah->imask);
  572. }
  573. }
  574. if (status & ATH9K_INT_MIB) {
  575. /*
  576. * Disable interrupts until we service the MIB
  577. * interrupt; otherwise it will continue to
  578. * fire.
  579. */
  580. ath9k_hw_set_interrupts(ah, 0);
  581. /*
  582. * Let the hal handle the event. We assume
  583. * it will clear whatever condition caused
  584. * the interrupt.
  585. */
  586. ath9k_hw_procmibevent(ah);
  587. ath9k_hw_set_interrupts(ah, ah->imask);
  588. }
  589. if (!(ah->caps.hw_caps & ATH9K_HW_CAP_AUTOSLEEP))
  590. if (status & ATH9K_INT_TIM_TIMER) {
  591. /* Clear RxAbort bit so that we can
  592. * receive frames */
  593. ath9k_setpower(sc, ATH9K_PM_AWAKE);
  594. ath9k_hw_setrxabort(sc->sc_ah, 0);
  595. sc->ps_flags |= PS_WAIT_FOR_BEACON;
  596. }
  597. chip_reset:
  598. ath_debug_stat_interrupt(sc, status);
  599. if (sched) {
  600. /* turn off every interrupt except SWBA */
  601. ath9k_hw_set_interrupts(ah, (ah->imask & ATH9K_INT_SWBA));
  602. tasklet_schedule(&sc->intr_tq);
  603. }
  604. return IRQ_HANDLED;
  605. #undef SCHED_INTR
  606. }
  607. static u32 ath_get_extchanmode(struct ath_softc *sc,
  608. struct ieee80211_channel *chan,
  609. enum nl80211_channel_type channel_type)
  610. {
  611. u32 chanmode = 0;
  612. switch (chan->band) {
  613. case IEEE80211_BAND_2GHZ:
  614. switch(channel_type) {
  615. case NL80211_CHAN_NO_HT:
  616. case NL80211_CHAN_HT20:
  617. chanmode = CHANNEL_G_HT20;
  618. break;
  619. case NL80211_CHAN_HT40PLUS:
  620. chanmode = CHANNEL_G_HT40PLUS;
  621. break;
  622. case NL80211_CHAN_HT40MINUS:
  623. chanmode = CHANNEL_G_HT40MINUS;
  624. break;
  625. }
  626. break;
  627. case IEEE80211_BAND_5GHZ:
  628. switch(channel_type) {
  629. case NL80211_CHAN_NO_HT:
  630. case NL80211_CHAN_HT20:
  631. chanmode = CHANNEL_A_HT20;
  632. break;
  633. case NL80211_CHAN_HT40PLUS:
  634. chanmode = CHANNEL_A_HT40PLUS;
  635. break;
  636. case NL80211_CHAN_HT40MINUS:
  637. chanmode = CHANNEL_A_HT40MINUS;
  638. break;
  639. }
  640. break;
  641. default:
  642. break;
  643. }
  644. return chanmode;
  645. }
  646. static void ath9k_bss_assoc_info(struct ath_softc *sc,
  647. struct ieee80211_vif *vif,
  648. struct ieee80211_bss_conf *bss_conf)
  649. {
  650. struct ath_hw *ah = sc->sc_ah;
  651. struct ath_common *common = ath9k_hw_common(ah);
  652. if (bss_conf->assoc) {
  653. ath_print(common, ATH_DBG_CONFIG,
  654. "Bss Info ASSOC %d, bssid: %pM\n",
  655. bss_conf->aid, common->curbssid);
  656. /* New association, store aid */
  657. common->curaid = bss_conf->aid;
  658. ath9k_hw_write_associd(ah);
  659. /*
  660. * Request a re-configuration of Beacon related timers
  661. * on the receipt of the first Beacon frame (i.e.,
  662. * after time sync with the AP).
  663. */
  664. sc->ps_flags |= PS_BEACON_SYNC;
  665. /* Configure the beacon */
  666. ath_beacon_config(sc, vif);
  667. /* Reset rssi stats */
  668. sc->sc_ah->stats.avgbrssi = ATH_RSSI_DUMMY_MARKER;
  669. sc->sc_flags |= SC_OP_ANI_RUN;
  670. ath_start_ani(common);
  671. } else {
  672. ath_print(common, ATH_DBG_CONFIG, "Bss Info DISASSOC\n");
  673. common->curaid = 0;
  674. /* Stop ANI */
  675. sc->sc_flags &= ~SC_OP_ANI_RUN;
  676. del_timer_sync(&common->ani.timer);
  677. }
  678. }
  679. void ath_radio_enable(struct ath_softc *sc, struct ieee80211_hw *hw)
  680. {
  681. struct ath_hw *ah = sc->sc_ah;
  682. struct ath_common *common = ath9k_hw_common(ah);
  683. struct ieee80211_channel *channel = hw->conf.channel;
  684. int r;
  685. ath9k_ps_wakeup(sc);
  686. ath9k_hw_configpcipowersave(ah, 0, 0);
  687. if (!ah->curchan)
  688. ah->curchan = ath_get_curchannel(sc, sc->hw);
  689. spin_lock_bh(&sc->sc_resetlock);
  690. r = ath9k_hw_reset(ah, ah->curchan, false);
  691. if (r) {
  692. ath_print(common, ATH_DBG_FATAL,
  693. "Unable to reset channel (%u MHz), "
  694. "reset status %d\n",
  695. channel->center_freq, r);
  696. }
  697. spin_unlock_bh(&sc->sc_resetlock);
  698. ath_update_txpow(sc);
  699. if (ath_startrecv(sc) != 0) {
  700. ath_print(common, ATH_DBG_FATAL,
  701. "Unable to restart recv logic\n");
  702. return;
  703. }
  704. if (sc->sc_flags & SC_OP_BEACONS)
  705. ath_beacon_config(sc, NULL); /* restart beacons */
  706. /* Re-Enable interrupts */
  707. ath9k_hw_set_interrupts(ah, ah->imask);
  708. /* Enable LED */
  709. ath9k_hw_cfg_output(ah, ah->led_pin,
  710. AR_GPIO_OUTPUT_MUX_AS_OUTPUT);
  711. ath9k_hw_set_gpio(ah, ah->led_pin, 0);
  712. ieee80211_wake_queues(hw);
  713. ath9k_ps_restore(sc);
  714. }
  715. void ath_radio_disable(struct ath_softc *sc, struct ieee80211_hw *hw)
  716. {
  717. struct ath_hw *ah = sc->sc_ah;
  718. struct ieee80211_channel *channel = hw->conf.channel;
  719. int r;
  720. ath9k_ps_wakeup(sc);
  721. ieee80211_stop_queues(hw);
  722. /*
  723. * Keep the LED on when the radio is disabled
  724. * during idle unassociated state.
  725. */
  726. if (!sc->ps_idle) {
  727. ath9k_hw_set_gpio(ah, ah->led_pin, 1);
  728. ath9k_hw_cfg_gpio_input(ah, ah->led_pin);
  729. }
  730. /* Disable interrupts */
  731. ath9k_hw_set_interrupts(ah, 0);
  732. ath_drain_all_txq(sc, false); /* clear pending tx frames */
  733. ath_stoprecv(sc); /* turn off frame recv */
  734. ath_flushrecv(sc); /* flush recv queue */
  735. if (!ah->curchan)
  736. ah->curchan = ath_get_curchannel(sc, hw);
  737. spin_lock_bh(&sc->sc_resetlock);
  738. r = ath9k_hw_reset(ah, ah->curchan, false);
  739. if (r) {
  740. ath_print(ath9k_hw_common(sc->sc_ah), ATH_DBG_FATAL,
  741. "Unable to reset channel (%u MHz), "
  742. "reset status %d\n",
  743. channel->center_freq, r);
  744. }
  745. spin_unlock_bh(&sc->sc_resetlock);
  746. ath9k_hw_phy_disable(ah);
  747. ath9k_hw_configpcipowersave(ah, 1, 1);
  748. ath9k_ps_restore(sc);
  749. ath9k_setpower(sc, ATH9K_PM_FULL_SLEEP);
  750. }
  751. int ath_reset(struct ath_softc *sc, bool retry_tx)
  752. {
  753. struct ath_hw *ah = sc->sc_ah;
  754. struct ath_common *common = ath9k_hw_common(ah);
  755. struct ieee80211_hw *hw = sc->hw;
  756. int r;
  757. /* Stop ANI */
  758. del_timer_sync(&common->ani.timer);
  759. ieee80211_stop_queues(hw);
  760. ath9k_hw_set_interrupts(ah, 0);
  761. ath_drain_all_txq(sc, retry_tx);
  762. ath_stoprecv(sc);
  763. ath_flushrecv(sc);
  764. spin_lock_bh(&sc->sc_resetlock);
  765. r = ath9k_hw_reset(ah, sc->sc_ah->curchan, false);
  766. if (r)
  767. ath_print(common, ATH_DBG_FATAL,
  768. "Unable to reset hardware; reset status %d\n", r);
  769. spin_unlock_bh(&sc->sc_resetlock);
  770. if (ath_startrecv(sc) != 0)
  771. ath_print(common, ATH_DBG_FATAL,
  772. "Unable to start recv logic\n");
  773. /*
  774. * We may be doing a reset in response to a request
  775. * that changes the channel so update any state that
  776. * might change as a result.
  777. */
  778. ath_cache_conf_rate(sc, &hw->conf);
  779. ath_update_txpow(sc);
  780. if (sc->sc_flags & SC_OP_BEACONS)
  781. ath_beacon_config(sc, NULL); /* restart beacons */
  782. ath9k_hw_set_interrupts(ah, ah->imask);
  783. if (retry_tx) {
  784. int i;
  785. for (i = 0; i < ATH9K_NUM_TX_QUEUES; i++) {
  786. if (ATH_TXQ_SETUP(sc, i)) {
  787. spin_lock_bh(&sc->tx.txq[i].axq_lock);
  788. ath_txq_schedule(sc, &sc->tx.txq[i]);
  789. spin_unlock_bh(&sc->tx.txq[i].axq_lock);
  790. }
  791. }
  792. }
  793. ieee80211_wake_queues(hw);
  794. /* Start ANI */
  795. ath_start_ani(common);
  796. return r;
  797. }
  798. static int ath_get_hal_qnum(u16 queue, struct ath_softc *sc)
  799. {
  800. int qnum;
  801. switch (queue) {
  802. case 0:
  803. qnum = sc->tx.hwq_map[WME_AC_VO];
  804. break;
  805. case 1:
  806. qnum = sc->tx.hwq_map[WME_AC_VI];
  807. break;
  808. case 2:
  809. qnum = sc->tx.hwq_map[WME_AC_BE];
  810. break;
  811. case 3:
  812. qnum = sc->tx.hwq_map[WME_AC_BK];
  813. break;
  814. default:
  815. qnum = sc->tx.hwq_map[WME_AC_BE];
  816. break;
  817. }
  818. return qnum;
  819. }
  820. int ath_get_mac80211_qnum(u32 queue, struct ath_softc *sc)
  821. {
  822. int qnum;
  823. switch (queue) {
  824. case WME_AC_VO:
  825. qnum = 0;
  826. break;
  827. case WME_AC_VI:
  828. qnum = 1;
  829. break;
  830. case WME_AC_BE:
  831. qnum = 2;
  832. break;
  833. case WME_AC_BK:
  834. qnum = 3;
  835. break;
  836. default:
  837. qnum = -1;
  838. break;
  839. }
  840. return qnum;
  841. }
  842. /* XXX: Remove me once we don't depend on ath9k_channel for all
  843. * this redundant data */
  844. void ath9k_update_ichannel(struct ath_softc *sc, struct ieee80211_hw *hw,
  845. struct ath9k_channel *ichan)
  846. {
  847. struct ieee80211_channel *chan = hw->conf.channel;
  848. struct ieee80211_conf *conf = &hw->conf;
  849. ichan->channel = chan->center_freq;
  850. ichan->chan = chan;
  851. if (chan->band == IEEE80211_BAND_2GHZ) {
  852. ichan->chanmode = CHANNEL_G;
  853. ichan->channelFlags = CHANNEL_2GHZ | CHANNEL_OFDM | CHANNEL_G;
  854. } else {
  855. ichan->chanmode = CHANNEL_A;
  856. ichan->channelFlags = CHANNEL_5GHZ | CHANNEL_OFDM;
  857. }
  858. if (conf_is_ht(conf))
  859. ichan->chanmode = ath_get_extchanmode(sc, chan,
  860. conf->channel_type);
  861. }
  862. /**********************/
  863. /* mac80211 callbacks */
  864. /**********************/
  865. static int ath9k_start(struct ieee80211_hw *hw)
  866. {
  867. struct ath_wiphy *aphy = hw->priv;
  868. struct ath_softc *sc = aphy->sc;
  869. struct ath_hw *ah = sc->sc_ah;
  870. struct ath_common *common = ath9k_hw_common(ah);
  871. struct ieee80211_channel *curchan = hw->conf.channel;
  872. struct ath9k_channel *init_channel;
  873. int r;
  874. ath_print(common, ATH_DBG_CONFIG,
  875. "Starting driver with initial channel: %d MHz\n",
  876. curchan->center_freq);
  877. mutex_lock(&sc->mutex);
  878. if (ath9k_wiphy_started(sc)) {
  879. if (sc->chan_idx == curchan->hw_value) {
  880. /*
  881. * Already on the operational channel, the new wiphy
  882. * can be marked active.
  883. */
  884. aphy->state = ATH_WIPHY_ACTIVE;
  885. ieee80211_wake_queues(hw);
  886. } else {
  887. /*
  888. * Another wiphy is on another channel, start the new
  889. * wiphy in paused state.
  890. */
  891. aphy->state = ATH_WIPHY_PAUSED;
  892. ieee80211_stop_queues(hw);
  893. }
  894. mutex_unlock(&sc->mutex);
  895. return 0;
  896. }
  897. aphy->state = ATH_WIPHY_ACTIVE;
  898. /* setup initial channel */
  899. sc->chan_idx = curchan->hw_value;
  900. init_channel = ath_get_curchannel(sc, hw);
  901. /* Reset SERDES registers */
  902. ath9k_hw_configpcipowersave(ah, 0, 0);
  903. /*
  904. * The basic interface to setting the hardware in a good
  905. * state is ``reset''. On return the hardware is known to
  906. * be powered up and with interrupts disabled. This must
  907. * be followed by initialization of the appropriate bits
  908. * and then setup of the interrupt mask.
  909. */
  910. spin_lock_bh(&sc->sc_resetlock);
  911. r = ath9k_hw_reset(ah, init_channel, false);
  912. if (r) {
  913. ath_print(common, ATH_DBG_FATAL,
  914. "Unable to reset hardware; reset status %d "
  915. "(freq %u MHz)\n", r,
  916. curchan->center_freq);
  917. spin_unlock_bh(&sc->sc_resetlock);
  918. goto mutex_unlock;
  919. }
  920. spin_unlock_bh(&sc->sc_resetlock);
  921. /*
  922. * This is needed only to setup initial state
  923. * but it's best done after a reset.
  924. */
  925. ath_update_txpow(sc);
  926. /*
  927. * Setup the hardware after reset:
  928. * The receive engine is set going.
  929. * Frame transmit is handled entirely
  930. * in the frame output path; there's nothing to do
  931. * here except setup the interrupt mask.
  932. */
  933. if (ath_startrecv(sc) != 0) {
  934. ath_print(common, ATH_DBG_FATAL,
  935. "Unable to start recv logic\n");
  936. r = -EIO;
  937. goto mutex_unlock;
  938. }
  939. /* Setup our intr mask. */
  940. ah->imask = ATH9K_INT_TX | ATH9K_INT_RXEOL |
  941. ATH9K_INT_RXORN | ATH9K_INT_FATAL |
  942. ATH9K_INT_GLOBAL;
  943. if (ah->caps.hw_caps & ATH9K_HW_CAP_EDMA)
  944. ah->imask |= ATH9K_INT_RXHP |
  945. ATH9K_INT_RXLP |
  946. ATH9K_INT_BB_WATCHDOG;
  947. else
  948. ah->imask |= ATH9K_INT_RX;
  949. if (ah->caps.hw_caps & ATH9K_HW_CAP_GTT)
  950. ah->imask |= ATH9K_INT_GTT;
  951. if (ah->caps.hw_caps & ATH9K_HW_CAP_HT)
  952. ah->imask |= ATH9K_INT_CST;
  953. ath_cache_conf_rate(sc, &hw->conf);
  954. sc->sc_flags &= ~SC_OP_INVALID;
  955. /* Disable BMISS interrupt when we're not associated */
  956. ah->imask &= ~(ATH9K_INT_SWBA | ATH9K_INT_BMISS);
  957. ath9k_hw_set_interrupts(ah, ah->imask);
  958. ieee80211_wake_queues(hw);
  959. ieee80211_queue_delayed_work(sc->hw, &sc->tx_complete_work, 0);
  960. if ((ah->btcoex_hw.scheme != ATH_BTCOEX_CFG_NONE) &&
  961. !ah->btcoex_hw.enabled) {
  962. ath9k_hw_btcoex_set_weight(ah, AR_BT_COEX_WGHT,
  963. AR_STOMP_LOW_WLAN_WGHT);
  964. ath9k_hw_btcoex_enable(ah);
  965. if (common->bus_ops->bt_coex_prep)
  966. common->bus_ops->bt_coex_prep(common);
  967. if (ah->btcoex_hw.scheme == ATH_BTCOEX_CFG_3WIRE)
  968. ath9k_btcoex_timer_resume(sc);
  969. }
  970. mutex_unlock:
  971. mutex_unlock(&sc->mutex);
  972. return r;
  973. }
  974. static int ath9k_tx(struct ieee80211_hw *hw,
  975. struct sk_buff *skb)
  976. {
  977. struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
  978. struct ath_wiphy *aphy = hw->priv;
  979. struct ath_softc *sc = aphy->sc;
  980. struct ath_common *common = ath9k_hw_common(sc->sc_ah);
  981. struct ath_tx_control txctl;
  982. int padpos, padsize;
  983. struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
  984. int qnum;
  985. if (aphy->state != ATH_WIPHY_ACTIVE && aphy->state != ATH_WIPHY_SCAN) {
  986. ath_print(common, ATH_DBG_XMIT,
  987. "ath9k: %s: TX in unexpected wiphy state "
  988. "%d\n", wiphy_name(hw->wiphy), aphy->state);
  989. goto exit;
  990. }
  991. if (sc->ps_enabled) {
  992. /*
  993. * mac80211 does not set PM field for normal data frames, so we
  994. * need to update that based on the current PS mode.
  995. */
  996. if (ieee80211_is_data(hdr->frame_control) &&
  997. !ieee80211_is_nullfunc(hdr->frame_control) &&
  998. !ieee80211_has_pm(hdr->frame_control)) {
  999. ath_print(common, ATH_DBG_PS, "Add PM=1 for a TX frame "
  1000. "while in PS mode\n");
  1001. hdr->frame_control |= cpu_to_le16(IEEE80211_FCTL_PM);
  1002. }
  1003. }
  1004. if (unlikely(sc->sc_ah->power_mode != ATH9K_PM_AWAKE)) {
  1005. /*
  1006. * We are using PS-Poll and mac80211 can request TX while in
  1007. * power save mode. Need to wake up hardware for the TX to be
  1008. * completed and if needed, also for RX of buffered frames.
  1009. */
  1010. ath9k_ps_wakeup(sc);
  1011. if (!(sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_AUTOSLEEP))
  1012. ath9k_hw_setrxabort(sc->sc_ah, 0);
  1013. if (ieee80211_is_pspoll(hdr->frame_control)) {
  1014. ath_print(common, ATH_DBG_PS,
  1015. "Sending PS-Poll to pick a buffered frame\n");
  1016. sc->ps_flags |= PS_WAIT_FOR_PSPOLL_DATA;
  1017. } else {
  1018. ath_print(common, ATH_DBG_PS,
  1019. "Wake up to complete TX\n");
  1020. sc->ps_flags |= PS_WAIT_FOR_TX_ACK;
  1021. }
  1022. /*
  1023. * The actual restore operation will happen only after
  1024. * the sc_flags bit is cleared. We are just dropping
  1025. * the ps_usecount here.
  1026. */
  1027. ath9k_ps_restore(sc);
  1028. }
  1029. memset(&txctl, 0, sizeof(struct ath_tx_control));
  1030. /*
  1031. * As a temporary workaround, assign seq# here; this will likely need
  1032. * to be cleaned up to work better with Beacon transmission and virtual
  1033. * BSSes.
  1034. */
  1035. if (info->flags & IEEE80211_TX_CTL_ASSIGN_SEQ) {
  1036. if (info->flags & IEEE80211_TX_CTL_FIRST_FRAGMENT)
  1037. sc->tx.seq_no += 0x10;
  1038. hdr->seq_ctrl &= cpu_to_le16(IEEE80211_SCTL_FRAG);
  1039. hdr->seq_ctrl |= cpu_to_le16(sc->tx.seq_no);
  1040. }
  1041. /* Add the padding after the header if this is not already done */
  1042. padpos = ath9k_cmn_padpos(hdr->frame_control);
  1043. padsize = padpos & 3;
  1044. if (padsize && skb->len>padpos) {
  1045. if (skb_headroom(skb) < padsize)
  1046. return -1;
  1047. skb_push(skb, padsize);
  1048. memmove(skb->data, skb->data + padsize, padpos);
  1049. }
  1050. qnum = ath_get_hal_qnum(skb_get_queue_mapping(skb), sc);
  1051. txctl.txq = &sc->tx.txq[qnum];
  1052. ath_print(common, ATH_DBG_XMIT, "transmitting packet, skb: %p\n", skb);
  1053. if (ath_tx_start(hw, skb, &txctl) != 0) {
  1054. ath_print(common, ATH_DBG_XMIT, "TX failed\n");
  1055. goto exit;
  1056. }
  1057. return 0;
  1058. exit:
  1059. dev_kfree_skb_any(skb);
  1060. return 0;
  1061. }
  1062. static void ath9k_stop(struct ieee80211_hw *hw)
  1063. {
  1064. struct ath_wiphy *aphy = hw->priv;
  1065. struct ath_softc *sc = aphy->sc;
  1066. struct ath_hw *ah = sc->sc_ah;
  1067. struct ath_common *common = ath9k_hw_common(ah);
  1068. int i;
  1069. mutex_lock(&sc->mutex);
  1070. aphy->state = ATH_WIPHY_INACTIVE;
  1071. if (led_blink)
  1072. cancel_delayed_work_sync(&sc->ath_led_blink_work);
  1073. cancel_delayed_work_sync(&sc->tx_complete_work);
  1074. cancel_work_sync(&sc->paprd_work);
  1075. cancel_work_sync(&sc->hw_check_work);
  1076. for (i = 0; i < sc->num_sec_wiphy; i++) {
  1077. if (sc->sec_wiphy[i])
  1078. break;
  1079. }
  1080. if (i == sc->num_sec_wiphy) {
  1081. cancel_delayed_work_sync(&sc->wiphy_work);
  1082. cancel_work_sync(&sc->chan_work);
  1083. }
  1084. if (sc->sc_flags & SC_OP_INVALID) {
  1085. ath_print(common, ATH_DBG_ANY, "Device not present\n");
  1086. mutex_unlock(&sc->mutex);
  1087. return;
  1088. }
  1089. if (ath9k_wiphy_started(sc)) {
  1090. mutex_unlock(&sc->mutex);
  1091. return; /* another wiphy still in use */
  1092. }
  1093. /* Ensure HW is awake when we try to shut it down. */
  1094. ath9k_ps_wakeup(sc);
  1095. if (ah->btcoex_hw.enabled) {
  1096. ath9k_hw_btcoex_disable(ah);
  1097. if (ah->btcoex_hw.scheme == ATH_BTCOEX_CFG_3WIRE)
  1098. ath9k_btcoex_timer_pause(sc);
  1099. }
  1100. /* make sure h/w will not generate any interrupt
  1101. * before setting the invalid flag. */
  1102. ath9k_hw_set_interrupts(ah, 0);
  1103. if (!(sc->sc_flags & SC_OP_INVALID)) {
  1104. ath_drain_all_txq(sc, false);
  1105. ath_stoprecv(sc);
  1106. ath9k_hw_phy_disable(ah);
  1107. } else
  1108. sc->rx.rxlink = NULL;
  1109. /* disable HAL and put h/w to sleep */
  1110. ath9k_hw_disable(ah);
  1111. ath9k_hw_configpcipowersave(ah, 1, 1);
  1112. ath9k_ps_restore(sc);
  1113. /* Finally, put the chip in FULL SLEEP mode */
  1114. ath9k_setpower(sc, ATH9K_PM_FULL_SLEEP);
  1115. sc->sc_flags |= SC_OP_INVALID;
  1116. mutex_unlock(&sc->mutex);
  1117. ath_print(common, ATH_DBG_CONFIG, "Driver halt\n");
  1118. }
  1119. static int ath9k_add_interface(struct ieee80211_hw *hw,
  1120. struct ieee80211_vif *vif)
  1121. {
  1122. struct ath_wiphy *aphy = hw->priv;
  1123. struct ath_softc *sc = aphy->sc;
  1124. struct ath_hw *ah = sc->sc_ah;
  1125. struct ath_common *common = ath9k_hw_common(ah);
  1126. struct ath_vif *avp = (void *)vif->drv_priv;
  1127. enum nl80211_iftype ic_opmode = NL80211_IFTYPE_UNSPECIFIED;
  1128. int ret = 0;
  1129. mutex_lock(&sc->mutex);
  1130. if (!(ah->caps.hw_caps & ATH9K_HW_CAP_BSSIDMASK) &&
  1131. sc->nvifs > 0) {
  1132. ret = -ENOBUFS;
  1133. goto out;
  1134. }
  1135. switch (vif->type) {
  1136. case NL80211_IFTYPE_STATION:
  1137. ic_opmode = NL80211_IFTYPE_STATION;
  1138. break;
  1139. case NL80211_IFTYPE_ADHOC:
  1140. case NL80211_IFTYPE_AP:
  1141. case NL80211_IFTYPE_MESH_POINT:
  1142. if (sc->nbcnvifs >= ATH_BCBUF) {
  1143. ret = -ENOBUFS;
  1144. goto out;
  1145. }
  1146. ic_opmode = vif->type;
  1147. break;
  1148. default:
  1149. ath_print(common, ATH_DBG_FATAL,
  1150. "Interface type %d not yet supported\n", vif->type);
  1151. ret = -EOPNOTSUPP;
  1152. goto out;
  1153. }
  1154. ath_print(common, ATH_DBG_CONFIG,
  1155. "Attach a VIF of type: %d\n", ic_opmode);
  1156. /* Set the VIF opmode */
  1157. avp->av_opmode = ic_opmode;
  1158. avp->av_bslot = -1;
  1159. sc->nvifs++;
  1160. if (ah->caps.hw_caps & ATH9K_HW_CAP_BSSIDMASK)
  1161. ath9k_set_bssid_mask(hw);
  1162. if (sc->nvifs > 1)
  1163. goto out; /* skip global settings for secondary vif */
  1164. if (ic_opmode == NL80211_IFTYPE_AP) {
  1165. ath9k_hw_set_tsfadjust(ah, 1);
  1166. sc->sc_flags |= SC_OP_TSF_RESET;
  1167. }
  1168. /* Set the device opmode */
  1169. ah->opmode = ic_opmode;
  1170. /*
  1171. * Enable MIB interrupts when there are hardware phy counters.
  1172. * Note we only do this (at the moment) for station mode.
  1173. */
  1174. if ((vif->type == NL80211_IFTYPE_STATION) ||
  1175. (vif->type == NL80211_IFTYPE_ADHOC) ||
  1176. (vif->type == NL80211_IFTYPE_MESH_POINT)) {
  1177. if (ah->config.enable_ani)
  1178. ah->imask |= ATH9K_INT_MIB;
  1179. ah->imask |= ATH9K_INT_TSFOOR;
  1180. }
  1181. ath9k_hw_set_interrupts(ah, ah->imask);
  1182. if (vif->type == NL80211_IFTYPE_AP ||
  1183. vif->type == NL80211_IFTYPE_ADHOC ||
  1184. vif->type == NL80211_IFTYPE_MONITOR) {
  1185. sc->sc_flags |= SC_OP_ANI_RUN;
  1186. ath_start_ani(common);
  1187. }
  1188. out:
  1189. mutex_unlock(&sc->mutex);
  1190. return ret;
  1191. }
  1192. static void ath9k_remove_interface(struct ieee80211_hw *hw,
  1193. struct ieee80211_vif *vif)
  1194. {
  1195. struct ath_wiphy *aphy = hw->priv;
  1196. struct ath_softc *sc = aphy->sc;
  1197. struct ath_common *common = ath9k_hw_common(sc->sc_ah);
  1198. struct ath_vif *avp = (void *)vif->drv_priv;
  1199. int i;
  1200. ath_print(common, ATH_DBG_CONFIG, "Detach Interface\n");
  1201. mutex_lock(&sc->mutex);
  1202. /* Stop ANI */
  1203. sc->sc_flags &= ~SC_OP_ANI_RUN;
  1204. del_timer_sync(&common->ani.timer);
  1205. /* Reclaim beacon resources */
  1206. if ((sc->sc_ah->opmode == NL80211_IFTYPE_AP) ||
  1207. (sc->sc_ah->opmode == NL80211_IFTYPE_ADHOC) ||
  1208. (sc->sc_ah->opmode == NL80211_IFTYPE_MESH_POINT)) {
  1209. ath9k_ps_wakeup(sc);
  1210. ath9k_hw_stoptxdma(sc->sc_ah, sc->beacon.beaconq);
  1211. ath9k_ps_restore(sc);
  1212. }
  1213. ath_beacon_return(sc, avp);
  1214. sc->sc_flags &= ~SC_OP_BEACONS;
  1215. for (i = 0; i < ARRAY_SIZE(sc->beacon.bslot); i++) {
  1216. if (sc->beacon.bslot[i] == vif) {
  1217. printk(KERN_DEBUG "%s: vif had allocated beacon "
  1218. "slot\n", __func__);
  1219. sc->beacon.bslot[i] = NULL;
  1220. sc->beacon.bslot_aphy[i] = NULL;
  1221. }
  1222. }
  1223. sc->nvifs--;
  1224. mutex_unlock(&sc->mutex);
  1225. }
  1226. void ath9k_enable_ps(struct ath_softc *sc)
  1227. {
  1228. struct ath_hw *ah = sc->sc_ah;
  1229. sc->ps_enabled = true;
  1230. if (!(ah->caps.hw_caps & ATH9K_HW_CAP_AUTOSLEEP)) {
  1231. if ((ah->imask & ATH9K_INT_TIM_TIMER) == 0) {
  1232. ah->imask |= ATH9K_INT_TIM_TIMER;
  1233. ath9k_hw_set_interrupts(ah, ah->imask);
  1234. }
  1235. ath9k_hw_setrxabort(ah, 1);
  1236. }
  1237. }
  1238. static int ath9k_config(struct ieee80211_hw *hw, u32 changed)
  1239. {
  1240. struct ath_wiphy *aphy = hw->priv;
  1241. struct ath_softc *sc = aphy->sc;
  1242. struct ath_common *common = ath9k_hw_common(sc->sc_ah);
  1243. struct ieee80211_conf *conf = &hw->conf;
  1244. struct ath_hw *ah = sc->sc_ah;
  1245. bool disable_radio;
  1246. mutex_lock(&sc->mutex);
  1247. /*
  1248. * Leave this as the first check because we need to turn on the
  1249. * radio if it was disabled before prior to processing the rest
  1250. * of the changes. Likewise we must only disable the radio towards
  1251. * the end.
  1252. */
  1253. if (changed & IEEE80211_CONF_CHANGE_IDLE) {
  1254. bool enable_radio;
  1255. bool all_wiphys_idle;
  1256. bool idle = !!(conf->flags & IEEE80211_CONF_IDLE);
  1257. spin_lock_bh(&sc->wiphy_lock);
  1258. all_wiphys_idle = ath9k_all_wiphys_idle(sc);
  1259. ath9k_set_wiphy_idle(aphy, idle);
  1260. enable_radio = (!idle && all_wiphys_idle);
  1261. /*
  1262. * After we unlock here its possible another wiphy
  1263. * can be re-renabled so to account for that we will
  1264. * only disable the radio toward the end of this routine
  1265. * if by then all wiphys are still idle.
  1266. */
  1267. spin_unlock_bh(&sc->wiphy_lock);
  1268. if (enable_radio) {
  1269. sc->ps_idle = false;
  1270. ath_radio_enable(sc, hw);
  1271. ath_print(common, ATH_DBG_CONFIG,
  1272. "not-idle: enabling radio\n");
  1273. }
  1274. }
  1275. /*
  1276. * We just prepare to enable PS. We have to wait until our AP has
  1277. * ACK'd our null data frame to disable RX otherwise we'll ignore
  1278. * those ACKs and end up retransmitting the same null data frames.
  1279. * IEEE80211_CONF_CHANGE_PS is only passed by mac80211 for STA mode.
  1280. */
  1281. if (changed & IEEE80211_CONF_CHANGE_PS) {
  1282. if (conf->flags & IEEE80211_CONF_PS) {
  1283. sc->ps_flags |= PS_ENABLED;
  1284. /*
  1285. * At this point we know hardware has received an ACK
  1286. * of a previously sent null data frame.
  1287. */
  1288. if ((sc->ps_flags & PS_NULLFUNC_COMPLETED)) {
  1289. sc->ps_flags &= ~PS_NULLFUNC_COMPLETED;
  1290. ath9k_enable_ps(sc);
  1291. }
  1292. } else {
  1293. sc->ps_enabled = false;
  1294. sc->ps_flags &= ~(PS_ENABLED |
  1295. PS_NULLFUNC_COMPLETED);
  1296. ath9k_setpower(sc, ATH9K_PM_AWAKE);
  1297. if (!(ah->caps.hw_caps &
  1298. ATH9K_HW_CAP_AUTOSLEEP)) {
  1299. ath9k_hw_setrxabort(sc->sc_ah, 0);
  1300. sc->ps_flags &= ~(PS_WAIT_FOR_BEACON |
  1301. PS_WAIT_FOR_CAB |
  1302. PS_WAIT_FOR_PSPOLL_DATA |
  1303. PS_WAIT_FOR_TX_ACK);
  1304. if (ah->imask & ATH9K_INT_TIM_TIMER) {
  1305. ah->imask &= ~ATH9K_INT_TIM_TIMER;
  1306. ath9k_hw_set_interrupts(sc->sc_ah,
  1307. ah->imask);
  1308. }
  1309. }
  1310. }
  1311. }
  1312. if (changed & IEEE80211_CONF_CHANGE_MONITOR) {
  1313. if (conf->flags & IEEE80211_CONF_MONITOR) {
  1314. ath_print(common, ATH_DBG_CONFIG,
  1315. "HW opmode set to Monitor mode\n");
  1316. sc->sc_ah->opmode = NL80211_IFTYPE_MONITOR;
  1317. }
  1318. }
  1319. if (changed & IEEE80211_CONF_CHANGE_CHANNEL) {
  1320. struct ieee80211_channel *curchan = hw->conf.channel;
  1321. int pos = curchan->hw_value;
  1322. aphy->chan_idx = pos;
  1323. aphy->chan_is_ht = conf_is_ht(conf);
  1324. if (aphy->state == ATH_WIPHY_SCAN ||
  1325. aphy->state == ATH_WIPHY_ACTIVE)
  1326. ath9k_wiphy_pause_all_forced(sc, aphy);
  1327. else {
  1328. /*
  1329. * Do not change operational channel based on a paused
  1330. * wiphy changes.
  1331. */
  1332. goto skip_chan_change;
  1333. }
  1334. ath_print(common, ATH_DBG_CONFIG, "Set channel: %d MHz\n",
  1335. curchan->center_freq);
  1336. /* XXX: remove me eventualy */
  1337. ath9k_update_ichannel(sc, hw, &sc->sc_ah->channels[pos]);
  1338. ath_update_chainmask(sc, conf_is_ht(conf));
  1339. if (ath_set_channel(sc, hw, &sc->sc_ah->channels[pos]) < 0) {
  1340. ath_print(common, ATH_DBG_FATAL,
  1341. "Unable to set channel\n");
  1342. mutex_unlock(&sc->mutex);
  1343. return -EINVAL;
  1344. }
  1345. }
  1346. skip_chan_change:
  1347. if (changed & IEEE80211_CONF_CHANGE_POWER) {
  1348. sc->config.txpowlimit = 2 * conf->power_level;
  1349. ath_update_txpow(sc);
  1350. }
  1351. spin_lock_bh(&sc->wiphy_lock);
  1352. disable_radio = ath9k_all_wiphys_idle(sc);
  1353. spin_unlock_bh(&sc->wiphy_lock);
  1354. if (disable_radio) {
  1355. ath_print(common, ATH_DBG_CONFIG, "idle: disabling radio\n");
  1356. sc->ps_idle = true;
  1357. ath_radio_disable(sc, hw);
  1358. }
  1359. mutex_unlock(&sc->mutex);
  1360. return 0;
  1361. }
  1362. #define SUPPORTED_FILTERS \
  1363. (FIF_PROMISC_IN_BSS | \
  1364. FIF_ALLMULTI | \
  1365. FIF_CONTROL | \
  1366. FIF_PSPOLL | \
  1367. FIF_OTHER_BSS | \
  1368. FIF_BCN_PRBRESP_PROMISC | \
  1369. FIF_FCSFAIL)
  1370. /* FIXME: sc->sc_full_reset ? */
  1371. static void ath9k_configure_filter(struct ieee80211_hw *hw,
  1372. unsigned int changed_flags,
  1373. unsigned int *total_flags,
  1374. u64 multicast)
  1375. {
  1376. struct ath_wiphy *aphy = hw->priv;
  1377. struct ath_softc *sc = aphy->sc;
  1378. u32 rfilt;
  1379. changed_flags &= SUPPORTED_FILTERS;
  1380. *total_flags &= SUPPORTED_FILTERS;
  1381. sc->rx.rxfilter = *total_flags;
  1382. ath9k_ps_wakeup(sc);
  1383. rfilt = ath_calcrxfilter(sc);
  1384. ath9k_hw_setrxfilter(sc->sc_ah, rfilt);
  1385. ath9k_ps_restore(sc);
  1386. ath_print(ath9k_hw_common(sc->sc_ah), ATH_DBG_CONFIG,
  1387. "Set HW RX filter: 0x%x\n", rfilt);
  1388. }
  1389. static int ath9k_sta_add(struct ieee80211_hw *hw,
  1390. struct ieee80211_vif *vif,
  1391. struct ieee80211_sta *sta)
  1392. {
  1393. struct ath_wiphy *aphy = hw->priv;
  1394. struct ath_softc *sc = aphy->sc;
  1395. ath_node_attach(sc, sta);
  1396. return 0;
  1397. }
  1398. static int ath9k_sta_remove(struct ieee80211_hw *hw,
  1399. struct ieee80211_vif *vif,
  1400. struct ieee80211_sta *sta)
  1401. {
  1402. struct ath_wiphy *aphy = hw->priv;
  1403. struct ath_softc *sc = aphy->sc;
  1404. ath_node_detach(sc, sta);
  1405. return 0;
  1406. }
  1407. static int ath9k_conf_tx(struct ieee80211_hw *hw, u16 queue,
  1408. const struct ieee80211_tx_queue_params *params)
  1409. {
  1410. struct ath_wiphy *aphy = hw->priv;
  1411. struct ath_softc *sc = aphy->sc;
  1412. struct ath_common *common = ath9k_hw_common(sc->sc_ah);
  1413. struct ath9k_tx_queue_info qi;
  1414. int ret = 0, qnum;
  1415. if (queue >= WME_NUM_AC)
  1416. return 0;
  1417. mutex_lock(&sc->mutex);
  1418. memset(&qi, 0, sizeof(struct ath9k_tx_queue_info));
  1419. qi.tqi_aifs = params->aifs;
  1420. qi.tqi_cwmin = params->cw_min;
  1421. qi.tqi_cwmax = params->cw_max;
  1422. qi.tqi_burstTime = params->txop;
  1423. qnum = ath_get_hal_qnum(queue, sc);
  1424. ath_print(common, ATH_DBG_CONFIG,
  1425. "Configure tx [queue/halq] [%d/%d], "
  1426. "aifs: %d, cw_min: %d, cw_max: %d, txop: %d\n",
  1427. queue, qnum, params->aifs, params->cw_min,
  1428. params->cw_max, params->txop);
  1429. ret = ath_txq_update(sc, qnum, &qi);
  1430. if (ret)
  1431. ath_print(common, ATH_DBG_FATAL, "TXQ Update failed\n");
  1432. if (sc->sc_ah->opmode == NL80211_IFTYPE_ADHOC)
  1433. if ((qnum == sc->tx.hwq_map[WME_AC_BE]) && !ret)
  1434. ath_beaconq_config(sc);
  1435. mutex_unlock(&sc->mutex);
  1436. return ret;
  1437. }
  1438. static int ath9k_set_key(struct ieee80211_hw *hw,
  1439. enum set_key_cmd cmd,
  1440. struct ieee80211_vif *vif,
  1441. struct ieee80211_sta *sta,
  1442. struct ieee80211_key_conf *key)
  1443. {
  1444. struct ath_wiphy *aphy = hw->priv;
  1445. struct ath_softc *sc = aphy->sc;
  1446. struct ath_common *common = ath9k_hw_common(sc->sc_ah);
  1447. int ret = 0;
  1448. if (modparam_nohwcrypt)
  1449. return -ENOSPC;
  1450. mutex_lock(&sc->mutex);
  1451. ath9k_ps_wakeup(sc);
  1452. ath_print(common, ATH_DBG_CONFIG, "Set HW Key\n");
  1453. switch (cmd) {
  1454. case SET_KEY:
  1455. ret = ath9k_cmn_key_config(common, vif, sta, key);
  1456. if (ret >= 0) {
  1457. key->hw_key_idx = ret;
  1458. /* push IV and Michael MIC generation to stack */
  1459. key->flags |= IEEE80211_KEY_FLAG_GENERATE_IV;
  1460. if (key->alg == ALG_TKIP)
  1461. key->flags |= IEEE80211_KEY_FLAG_GENERATE_MMIC;
  1462. if (sc->sc_ah->sw_mgmt_crypto && key->alg == ALG_CCMP)
  1463. key->flags |= IEEE80211_KEY_FLAG_SW_MGMT;
  1464. ret = 0;
  1465. }
  1466. break;
  1467. case DISABLE_KEY:
  1468. ath9k_cmn_key_delete(common, key);
  1469. break;
  1470. default:
  1471. ret = -EINVAL;
  1472. }
  1473. ath9k_ps_restore(sc);
  1474. mutex_unlock(&sc->mutex);
  1475. return ret;
  1476. }
  1477. static void ath9k_bss_info_changed(struct ieee80211_hw *hw,
  1478. struct ieee80211_vif *vif,
  1479. struct ieee80211_bss_conf *bss_conf,
  1480. u32 changed)
  1481. {
  1482. struct ath_wiphy *aphy = hw->priv;
  1483. struct ath_softc *sc = aphy->sc;
  1484. struct ath_hw *ah = sc->sc_ah;
  1485. struct ath_common *common = ath9k_hw_common(ah);
  1486. struct ath_vif *avp = (void *)vif->drv_priv;
  1487. int slottime;
  1488. int error;
  1489. mutex_lock(&sc->mutex);
  1490. if (changed & BSS_CHANGED_BSSID) {
  1491. /* Set BSSID */
  1492. memcpy(common->curbssid, bss_conf->bssid, ETH_ALEN);
  1493. memcpy(avp->bssid, bss_conf->bssid, ETH_ALEN);
  1494. common->curaid = 0;
  1495. ath9k_hw_write_associd(ah);
  1496. /* Set aggregation protection mode parameters */
  1497. sc->config.ath_aggr_prot = 0;
  1498. /* Only legacy IBSS for now */
  1499. if (vif->type == NL80211_IFTYPE_ADHOC)
  1500. ath_update_chainmask(sc, 0);
  1501. ath_print(common, ATH_DBG_CONFIG,
  1502. "BSSID: %pM aid: 0x%x\n",
  1503. common->curbssid, common->curaid);
  1504. /* need to reconfigure the beacon */
  1505. sc->sc_flags &= ~SC_OP_BEACONS ;
  1506. }
  1507. /* Enable transmission of beacons (AP, IBSS, MESH) */
  1508. if ((changed & BSS_CHANGED_BEACON) ||
  1509. ((changed & BSS_CHANGED_BEACON_ENABLED) && bss_conf->enable_beacon)) {
  1510. ath9k_hw_stoptxdma(sc->sc_ah, sc->beacon.beaconq);
  1511. error = ath_beacon_alloc(aphy, vif);
  1512. if (!error)
  1513. ath_beacon_config(sc, vif);
  1514. }
  1515. if (changed & BSS_CHANGED_ERP_SLOT) {
  1516. if (bss_conf->use_short_slot)
  1517. slottime = 9;
  1518. else
  1519. slottime = 20;
  1520. if (vif->type == NL80211_IFTYPE_AP) {
  1521. /*
  1522. * Defer update, so that connected stations can adjust
  1523. * their settings at the same time.
  1524. * See beacon.c for more details
  1525. */
  1526. sc->beacon.slottime = slottime;
  1527. sc->beacon.updateslot = UPDATE;
  1528. } else {
  1529. ah->slottime = slottime;
  1530. ath9k_hw_init_global_settings(ah);
  1531. }
  1532. }
  1533. /* Disable transmission of beacons */
  1534. if ((changed & BSS_CHANGED_BEACON_ENABLED) && !bss_conf->enable_beacon)
  1535. ath9k_hw_stoptxdma(sc->sc_ah, sc->beacon.beaconq);
  1536. if (changed & BSS_CHANGED_BEACON_INT) {
  1537. sc->beacon_interval = bss_conf->beacon_int;
  1538. /*
  1539. * In case of AP mode, the HW TSF has to be reset
  1540. * when the beacon interval changes.
  1541. */
  1542. if (vif->type == NL80211_IFTYPE_AP) {
  1543. sc->sc_flags |= SC_OP_TSF_RESET;
  1544. ath9k_hw_stoptxdma(sc->sc_ah, sc->beacon.beaconq);
  1545. error = ath_beacon_alloc(aphy, vif);
  1546. if (!error)
  1547. ath_beacon_config(sc, vif);
  1548. } else {
  1549. ath_beacon_config(sc, vif);
  1550. }
  1551. }
  1552. if (changed & BSS_CHANGED_ERP_PREAMBLE) {
  1553. ath_print(common, ATH_DBG_CONFIG, "BSS Changed PREAMBLE %d\n",
  1554. bss_conf->use_short_preamble);
  1555. if (bss_conf->use_short_preamble)
  1556. sc->sc_flags |= SC_OP_PREAMBLE_SHORT;
  1557. else
  1558. sc->sc_flags &= ~SC_OP_PREAMBLE_SHORT;
  1559. }
  1560. if (changed & BSS_CHANGED_ERP_CTS_PROT) {
  1561. ath_print(common, ATH_DBG_CONFIG, "BSS Changed CTS PROT %d\n",
  1562. bss_conf->use_cts_prot);
  1563. if (bss_conf->use_cts_prot &&
  1564. hw->conf.channel->band != IEEE80211_BAND_5GHZ)
  1565. sc->sc_flags |= SC_OP_PROTECT_ENABLE;
  1566. else
  1567. sc->sc_flags &= ~SC_OP_PROTECT_ENABLE;
  1568. }
  1569. if (changed & BSS_CHANGED_ASSOC) {
  1570. ath_print(common, ATH_DBG_CONFIG, "BSS Changed ASSOC %d\n",
  1571. bss_conf->assoc);
  1572. ath9k_bss_assoc_info(sc, vif, bss_conf);
  1573. }
  1574. mutex_unlock(&sc->mutex);
  1575. }
  1576. static u64 ath9k_get_tsf(struct ieee80211_hw *hw)
  1577. {
  1578. u64 tsf;
  1579. struct ath_wiphy *aphy = hw->priv;
  1580. struct ath_softc *sc = aphy->sc;
  1581. mutex_lock(&sc->mutex);
  1582. tsf = ath9k_hw_gettsf64(sc->sc_ah);
  1583. mutex_unlock(&sc->mutex);
  1584. return tsf;
  1585. }
  1586. static void ath9k_set_tsf(struct ieee80211_hw *hw, u64 tsf)
  1587. {
  1588. struct ath_wiphy *aphy = hw->priv;
  1589. struct ath_softc *sc = aphy->sc;
  1590. mutex_lock(&sc->mutex);
  1591. ath9k_hw_settsf64(sc->sc_ah, tsf);
  1592. mutex_unlock(&sc->mutex);
  1593. }
  1594. static void ath9k_reset_tsf(struct ieee80211_hw *hw)
  1595. {
  1596. struct ath_wiphy *aphy = hw->priv;
  1597. struct ath_softc *sc = aphy->sc;
  1598. mutex_lock(&sc->mutex);
  1599. ath9k_ps_wakeup(sc);
  1600. ath9k_hw_reset_tsf(sc->sc_ah);
  1601. ath9k_ps_restore(sc);
  1602. mutex_unlock(&sc->mutex);
  1603. }
  1604. static int ath9k_ampdu_action(struct ieee80211_hw *hw,
  1605. struct ieee80211_vif *vif,
  1606. enum ieee80211_ampdu_mlme_action action,
  1607. struct ieee80211_sta *sta,
  1608. u16 tid, u16 *ssn)
  1609. {
  1610. struct ath_wiphy *aphy = hw->priv;
  1611. struct ath_softc *sc = aphy->sc;
  1612. int ret = 0;
  1613. local_bh_disable();
  1614. switch (action) {
  1615. case IEEE80211_AMPDU_RX_START:
  1616. if (!(sc->sc_flags & SC_OP_RXAGGR))
  1617. ret = -ENOTSUPP;
  1618. break;
  1619. case IEEE80211_AMPDU_RX_STOP:
  1620. break;
  1621. case IEEE80211_AMPDU_TX_START:
  1622. ath9k_ps_wakeup(sc);
  1623. ath_tx_aggr_start(sc, sta, tid, ssn);
  1624. ieee80211_start_tx_ba_cb_irqsafe(vif, sta->addr, tid);
  1625. ath9k_ps_restore(sc);
  1626. break;
  1627. case IEEE80211_AMPDU_TX_STOP:
  1628. ath9k_ps_wakeup(sc);
  1629. ath_tx_aggr_stop(sc, sta, tid);
  1630. ieee80211_stop_tx_ba_cb_irqsafe(vif, sta->addr, tid);
  1631. ath9k_ps_restore(sc);
  1632. break;
  1633. case IEEE80211_AMPDU_TX_OPERATIONAL:
  1634. ath9k_ps_wakeup(sc);
  1635. ath_tx_aggr_resume(sc, sta, tid);
  1636. ath9k_ps_restore(sc);
  1637. break;
  1638. default:
  1639. ath_print(ath9k_hw_common(sc->sc_ah), ATH_DBG_FATAL,
  1640. "Unknown AMPDU action\n");
  1641. }
  1642. local_bh_enable();
  1643. return ret;
  1644. }
  1645. static int ath9k_get_survey(struct ieee80211_hw *hw, int idx,
  1646. struct survey_info *survey)
  1647. {
  1648. struct ath_wiphy *aphy = hw->priv;
  1649. struct ath_softc *sc = aphy->sc;
  1650. struct ath_hw *ah = sc->sc_ah;
  1651. struct ath_common *common = ath9k_hw_common(ah);
  1652. struct ieee80211_conf *conf = &hw->conf;
  1653. if (idx != 0)
  1654. return -ENOENT;
  1655. survey->channel = conf->channel;
  1656. survey->filled = SURVEY_INFO_NOISE_DBM;
  1657. survey->noise = common->ani.noise_floor;
  1658. return 0;
  1659. }
  1660. static void ath9k_sw_scan_start(struct ieee80211_hw *hw)
  1661. {
  1662. struct ath_wiphy *aphy = hw->priv;
  1663. struct ath_softc *sc = aphy->sc;
  1664. struct ath_common *common = ath9k_hw_common(sc->sc_ah);
  1665. mutex_lock(&sc->mutex);
  1666. if (ath9k_wiphy_scanning(sc)) {
  1667. /*
  1668. * There is a race here in mac80211 but fixing it requires
  1669. * we revisit how we handle the scan complete callback.
  1670. * After mac80211 fixes we will not have configured hardware
  1671. * to the home channel nor would we have configured the RX
  1672. * filter yet.
  1673. */
  1674. mutex_unlock(&sc->mutex);
  1675. return;
  1676. }
  1677. aphy->state = ATH_WIPHY_SCAN;
  1678. ath9k_wiphy_pause_all_forced(sc, aphy);
  1679. sc->sc_flags |= SC_OP_SCANNING;
  1680. del_timer_sync(&common->ani.timer);
  1681. cancel_work_sync(&sc->paprd_work);
  1682. cancel_work_sync(&sc->hw_check_work);
  1683. cancel_delayed_work_sync(&sc->tx_complete_work);
  1684. mutex_unlock(&sc->mutex);
  1685. }
  1686. /*
  1687. * XXX: this requires a revisit after the driver
  1688. * scan_complete gets moved to another place/removed in mac80211.
  1689. */
  1690. static void ath9k_sw_scan_complete(struct ieee80211_hw *hw)
  1691. {
  1692. struct ath_wiphy *aphy = hw->priv;
  1693. struct ath_softc *sc = aphy->sc;
  1694. struct ath_common *common = ath9k_hw_common(sc->sc_ah);
  1695. mutex_lock(&sc->mutex);
  1696. aphy->state = ATH_WIPHY_ACTIVE;
  1697. sc->sc_flags &= ~SC_OP_SCANNING;
  1698. sc->sc_flags |= SC_OP_FULL_RESET;
  1699. ath_start_ani(common);
  1700. ieee80211_queue_delayed_work(sc->hw, &sc->tx_complete_work, 0);
  1701. ath_beacon_config(sc, NULL);
  1702. mutex_unlock(&sc->mutex);
  1703. }
  1704. static void ath9k_set_coverage_class(struct ieee80211_hw *hw, u8 coverage_class)
  1705. {
  1706. struct ath_wiphy *aphy = hw->priv;
  1707. struct ath_softc *sc = aphy->sc;
  1708. struct ath_hw *ah = sc->sc_ah;
  1709. mutex_lock(&sc->mutex);
  1710. ah->coverage_class = coverage_class;
  1711. ath9k_hw_init_global_settings(ah);
  1712. mutex_unlock(&sc->mutex);
  1713. }
  1714. struct ieee80211_ops ath9k_ops = {
  1715. .tx = ath9k_tx,
  1716. .start = ath9k_start,
  1717. .stop = ath9k_stop,
  1718. .add_interface = ath9k_add_interface,
  1719. .remove_interface = ath9k_remove_interface,
  1720. .config = ath9k_config,
  1721. .configure_filter = ath9k_configure_filter,
  1722. .sta_add = ath9k_sta_add,
  1723. .sta_remove = ath9k_sta_remove,
  1724. .conf_tx = ath9k_conf_tx,
  1725. .bss_info_changed = ath9k_bss_info_changed,
  1726. .set_key = ath9k_set_key,
  1727. .get_tsf = ath9k_get_tsf,
  1728. .set_tsf = ath9k_set_tsf,
  1729. .reset_tsf = ath9k_reset_tsf,
  1730. .ampdu_action = ath9k_ampdu_action,
  1731. .get_survey = ath9k_get_survey,
  1732. .sw_scan_start = ath9k_sw_scan_start,
  1733. .sw_scan_complete = ath9k_sw_scan_complete,
  1734. .rfkill_poll = ath9k_rfkill_poll_state,
  1735. .set_coverage_class = ath9k_set_coverage_class,
  1736. };