main.c 52 KB

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