main.c 50 KB

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