main.c 51 KB

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