main.c 51 KB

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