main.c 59 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438
  1. /*
  2. * Copyright (c) 2008-2011 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 <linux/delay.h>
  18. #include "ath9k.h"
  19. #include "btcoex.h"
  20. static u8 parse_mpdudensity(u8 mpdudensity)
  21. {
  22. /*
  23. * 802.11n D2.0 defined values for "Minimum MPDU Start Spacing":
  24. * 0 for no restriction
  25. * 1 for 1/4 us
  26. * 2 for 1/2 us
  27. * 3 for 1 us
  28. * 4 for 2 us
  29. * 5 for 4 us
  30. * 6 for 8 us
  31. * 7 for 16 us
  32. */
  33. switch (mpdudensity) {
  34. case 0:
  35. return 0;
  36. case 1:
  37. case 2:
  38. case 3:
  39. /* Our lower layer calculations limit our precision to
  40. 1 microsecond */
  41. return 1;
  42. case 4:
  43. return 2;
  44. case 5:
  45. return 4;
  46. case 6:
  47. return 8;
  48. case 7:
  49. return 16;
  50. default:
  51. return 0;
  52. }
  53. }
  54. static bool ath9k_has_pending_frames(struct ath_softc *sc, struct ath_txq *txq)
  55. {
  56. bool pending = false;
  57. spin_lock_bh(&txq->axq_lock);
  58. if (txq->axq_depth || !list_empty(&txq->axq_acq))
  59. pending = true;
  60. spin_unlock_bh(&txq->axq_lock);
  61. return pending;
  62. }
  63. static bool ath9k_setpower(struct ath_softc *sc, enum ath9k_power_mode mode)
  64. {
  65. unsigned long flags;
  66. bool ret;
  67. spin_lock_irqsave(&sc->sc_pm_lock, flags);
  68. ret = ath9k_hw_setpower(sc->sc_ah, mode);
  69. spin_unlock_irqrestore(&sc->sc_pm_lock, flags);
  70. return ret;
  71. }
  72. void ath9k_ps_wakeup(struct ath_softc *sc)
  73. {
  74. struct ath_common *common = ath9k_hw_common(sc->sc_ah);
  75. unsigned long flags;
  76. enum ath9k_power_mode power_mode;
  77. spin_lock_irqsave(&sc->sc_pm_lock, flags);
  78. if (++sc->ps_usecount != 1)
  79. goto unlock;
  80. power_mode = sc->sc_ah->power_mode;
  81. ath9k_hw_setpower(sc->sc_ah, ATH9K_PM_AWAKE);
  82. /*
  83. * While the hardware is asleep, the cycle counters contain no
  84. * useful data. Better clear them now so that they don't mess up
  85. * survey data results.
  86. */
  87. if (power_mode != ATH9K_PM_AWAKE) {
  88. spin_lock(&common->cc_lock);
  89. ath_hw_cycle_counters_update(common);
  90. memset(&common->cc_survey, 0, sizeof(common->cc_survey));
  91. spin_unlock(&common->cc_lock);
  92. }
  93. unlock:
  94. spin_unlock_irqrestore(&sc->sc_pm_lock, flags);
  95. }
  96. void ath9k_ps_restore(struct ath_softc *sc)
  97. {
  98. struct ath_common *common = ath9k_hw_common(sc->sc_ah);
  99. enum ath9k_power_mode mode;
  100. unsigned long flags;
  101. spin_lock_irqsave(&sc->sc_pm_lock, flags);
  102. if (--sc->ps_usecount != 0)
  103. goto unlock;
  104. if (sc->ps_flags & PS_WAIT_FOR_TX_ACK)
  105. goto unlock;
  106. if (sc->ps_idle)
  107. mode = ATH9K_PM_FULL_SLEEP;
  108. else if (sc->ps_enabled &&
  109. !(sc->ps_flags & (PS_WAIT_FOR_BEACON |
  110. PS_WAIT_FOR_CAB |
  111. PS_WAIT_FOR_PSPOLL_DATA)))
  112. mode = ATH9K_PM_NETWORK_SLEEP;
  113. else
  114. goto unlock;
  115. spin_lock(&common->cc_lock);
  116. ath_hw_cycle_counters_update(common);
  117. spin_unlock(&common->cc_lock);
  118. ath9k_hw_setpower(sc->sc_ah, mode);
  119. unlock:
  120. spin_unlock_irqrestore(&sc->sc_pm_lock, flags);
  121. }
  122. void ath_start_ani(struct ath_common *common)
  123. {
  124. struct ath_hw *ah = common->ah;
  125. unsigned long timestamp = jiffies_to_msecs(jiffies);
  126. struct ath_softc *sc = (struct ath_softc *) common->priv;
  127. if (!(sc->sc_flags & SC_OP_ANI_RUN))
  128. return;
  129. if (sc->sc_flags & SC_OP_OFFCHANNEL)
  130. return;
  131. common->ani.longcal_timer = timestamp;
  132. common->ani.shortcal_timer = timestamp;
  133. common->ani.checkani_timer = timestamp;
  134. mod_timer(&common->ani.timer,
  135. jiffies +
  136. msecs_to_jiffies((u32)ah->config.ani_poll_interval));
  137. }
  138. static void ath_update_survey_nf(struct ath_softc *sc, int channel)
  139. {
  140. struct ath_hw *ah = sc->sc_ah;
  141. struct ath9k_channel *chan = &ah->channels[channel];
  142. struct survey_info *survey = &sc->survey[channel];
  143. if (chan->noisefloor) {
  144. survey->filled |= SURVEY_INFO_NOISE_DBM;
  145. survey->noise = ath9k_hw_getchan_noise(ah, chan);
  146. }
  147. }
  148. /*
  149. * Updates the survey statistics and returns the busy time since last
  150. * update in %, if the measurement duration was long enough for the
  151. * result to be useful, -1 otherwise.
  152. */
  153. static int ath_update_survey_stats(struct ath_softc *sc)
  154. {
  155. struct ath_hw *ah = sc->sc_ah;
  156. struct ath_common *common = ath9k_hw_common(ah);
  157. int pos = ah->curchan - &ah->channels[0];
  158. struct survey_info *survey = &sc->survey[pos];
  159. struct ath_cycle_counters *cc = &common->cc_survey;
  160. unsigned int div = common->clockrate * 1000;
  161. int ret = 0;
  162. if (!ah->curchan)
  163. return -1;
  164. if (ah->power_mode == ATH9K_PM_AWAKE)
  165. ath_hw_cycle_counters_update(common);
  166. if (cc->cycles > 0) {
  167. survey->filled |= SURVEY_INFO_CHANNEL_TIME |
  168. SURVEY_INFO_CHANNEL_TIME_BUSY |
  169. SURVEY_INFO_CHANNEL_TIME_RX |
  170. SURVEY_INFO_CHANNEL_TIME_TX;
  171. survey->channel_time += cc->cycles / div;
  172. survey->channel_time_busy += cc->rx_busy / div;
  173. survey->channel_time_rx += cc->rx_frame / div;
  174. survey->channel_time_tx += cc->tx_frame / div;
  175. }
  176. if (cc->cycles < div)
  177. return -1;
  178. if (cc->cycles > 0)
  179. ret = cc->rx_busy * 100 / cc->cycles;
  180. memset(cc, 0, sizeof(*cc));
  181. ath_update_survey_nf(sc, pos);
  182. return ret;
  183. }
  184. static void __ath_cancel_work(struct ath_softc *sc)
  185. {
  186. cancel_work_sync(&sc->paprd_work);
  187. cancel_work_sync(&sc->hw_check_work);
  188. cancel_delayed_work_sync(&sc->tx_complete_work);
  189. cancel_delayed_work_sync(&sc->hw_pll_work);
  190. }
  191. static void ath_cancel_work(struct ath_softc *sc)
  192. {
  193. __ath_cancel_work(sc);
  194. cancel_work_sync(&sc->hw_reset_work);
  195. }
  196. static bool ath_prepare_reset(struct ath_softc *sc, bool retry_tx, bool flush)
  197. {
  198. struct ath_hw *ah = sc->sc_ah;
  199. struct ath_common *common = ath9k_hw_common(ah);
  200. bool ret;
  201. ieee80211_stop_queues(sc->hw);
  202. sc->hw_busy_count = 0;
  203. del_timer_sync(&common->ani.timer);
  204. del_timer_sync(&sc->rx_poll_timer);
  205. ath9k_debug_samp_bb_mac(sc);
  206. ath9k_hw_disable_interrupts(ah);
  207. ret = ath_drain_all_txq(sc, retry_tx);
  208. if (!ath_stoprecv(sc))
  209. ret = false;
  210. if (!flush) {
  211. if (ah->caps.hw_caps & ATH9K_HW_CAP_EDMA)
  212. ath_rx_tasklet(sc, 1, true);
  213. ath_rx_tasklet(sc, 1, false);
  214. } else {
  215. ath_flushrecv(sc);
  216. }
  217. return ret;
  218. }
  219. static bool ath_complete_reset(struct ath_softc *sc, bool start)
  220. {
  221. struct ath_hw *ah = sc->sc_ah;
  222. struct ath_common *common = ath9k_hw_common(ah);
  223. if (ath_startrecv(sc) != 0) {
  224. ath_err(common, "Unable to restart recv logic\n");
  225. return false;
  226. }
  227. ath9k_cmn_update_txpow(ah, sc->curtxpow,
  228. sc->config.txpowlimit, &sc->curtxpow);
  229. ath9k_hw_set_interrupts(ah);
  230. ath9k_hw_enable_interrupts(ah);
  231. if (!(sc->sc_flags & (SC_OP_OFFCHANNEL)) && start) {
  232. if (sc->sc_flags & SC_OP_BEACONS)
  233. ath_set_beacon(sc);
  234. ieee80211_queue_delayed_work(sc->hw, &sc->tx_complete_work, 0);
  235. ieee80211_queue_delayed_work(sc->hw, &sc->hw_pll_work, HZ/2);
  236. ath_start_rx_poll(sc, 3);
  237. if (!common->disable_ani)
  238. ath_start_ani(common);
  239. }
  240. if ((ah->caps.hw_caps & ATH9K_HW_CAP_ANT_DIV_COMB) && sc->ant_rx != 3) {
  241. struct ath_hw_antcomb_conf div_ant_conf;
  242. u8 lna_conf;
  243. ath9k_hw_antdiv_comb_conf_get(ah, &div_ant_conf);
  244. if (sc->ant_rx == 1)
  245. lna_conf = ATH_ANT_DIV_COMB_LNA1;
  246. else
  247. lna_conf = ATH_ANT_DIV_COMB_LNA2;
  248. div_ant_conf.main_lna_conf = lna_conf;
  249. div_ant_conf.alt_lna_conf = lna_conf;
  250. ath9k_hw_antdiv_comb_conf_set(ah, &div_ant_conf);
  251. }
  252. ieee80211_wake_queues(sc->hw);
  253. return true;
  254. }
  255. static int ath_reset_internal(struct ath_softc *sc, struct ath9k_channel *hchan,
  256. bool retry_tx)
  257. {
  258. struct ath_hw *ah = sc->sc_ah;
  259. struct ath_common *common = ath9k_hw_common(ah);
  260. struct ath9k_hw_cal_data *caldata = NULL;
  261. bool fastcc = true;
  262. bool flush = false;
  263. int r;
  264. __ath_cancel_work(sc);
  265. spin_lock_bh(&sc->sc_pcu_lock);
  266. if (!(sc->sc_flags & SC_OP_OFFCHANNEL)) {
  267. fastcc = false;
  268. caldata = &sc->caldata;
  269. }
  270. if (!hchan) {
  271. fastcc = false;
  272. flush = true;
  273. hchan = ah->curchan;
  274. }
  275. if (!ath_prepare_reset(sc, retry_tx, flush))
  276. fastcc = false;
  277. ath_dbg(common, CONFIG, "Reset to %u MHz, HT40: %d fastcc: %d\n",
  278. hchan->channel, IS_CHAN_HT40(hchan), fastcc);
  279. r = ath9k_hw_reset(ah, hchan, caldata, fastcc);
  280. if (r) {
  281. ath_err(common,
  282. "Unable to reset channel, reset status %d\n", r);
  283. goto out;
  284. }
  285. if (!ath_complete_reset(sc, true))
  286. r = -EIO;
  287. out:
  288. spin_unlock_bh(&sc->sc_pcu_lock);
  289. return r;
  290. }
  291. /*
  292. * Set/change channels. If the channel is really being changed, it's done
  293. * by reseting the chip. To accomplish this we must first cleanup any pending
  294. * DMA, then restart stuff.
  295. */
  296. static int ath_set_channel(struct ath_softc *sc, struct ieee80211_hw *hw,
  297. struct ath9k_channel *hchan)
  298. {
  299. int r;
  300. if (sc->sc_flags & SC_OP_INVALID)
  301. return -EIO;
  302. r = ath_reset_internal(sc, hchan, false);
  303. return r;
  304. }
  305. static void ath_paprd_activate(struct ath_softc *sc)
  306. {
  307. struct ath_hw *ah = sc->sc_ah;
  308. struct ath9k_hw_cal_data *caldata = ah->caldata;
  309. int chain;
  310. if (!caldata || !caldata->paprd_done)
  311. return;
  312. ath9k_ps_wakeup(sc);
  313. ar9003_paprd_enable(ah, false);
  314. for (chain = 0; chain < AR9300_MAX_CHAINS; chain++) {
  315. if (!(ah->txchainmask & BIT(chain)))
  316. continue;
  317. ar9003_paprd_populate_single_table(ah, caldata, chain);
  318. }
  319. ar9003_paprd_enable(ah, true);
  320. ath9k_ps_restore(sc);
  321. }
  322. static bool ath_paprd_send_frame(struct ath_softc *sc, struct sk_buff *skb, int chain)
  323. {
  324. struct ieee80211_hw *hw = sc->hw;
  325. struct ieee80211_tx_info *tx_info = IEEE80211_SKB_CB(skb);
  326. struct ath_hw *ah = sc->sc_ah;
  327. struct ath_common *common = ath9k_hw_common(ah);
  328. struct ath_tx_control txctl;
  329. int time_left;
  330. memset(&txctl, 0, sizeof(txctl));
  331. txctl.txq = sc->tx.txq_map[WME_AC_BE];
  332. memset(tx_info, 0, sizeof(*tx_info));
  333. tx_info->band = hw->conf.channel->band;
  334. tx_info->flags |= IEEE80211_TX_CTL_NO_ACK;
  335. tx_info->control.rates[0].idx = 0;
  336. tx_info->control.rates[0].count = 1;
  337. tx_info->control.rates[0].flags = IEEE80211_TX_RC_MCS;
  338. tx_info->control.rates[1].idx = -1;
  339. init_completion(&sc->paprd_complete);
  340. txctl.paprd = BIT(chain);
  341. if (ath_tx_start(hw, skb, &txctl) != 0) {
  342. ath_dbg(common, CALIBRATE, "PAPRD TX failed\n");
  343. dev_kfree_skb_any(skb);
  344. return false;
  345. }
  346. time_left = wait_for_completion_timeout(&sc->paprd_complete,
  347. msecs_to_jiffies(ATH_PAPRD_TIMEOUT));
  348. if (!time_left)
  349. ath_dbg(common, CALIBRATE,
  350. "Timeout waiting for paprd training on TX chain %d\n",
  351. chain);
  352. return !!time_left;
  353. }
  354. void ath_paprd_calibrate(struct work_struct *work)
  355. {
  356. struct ath_softc *sc = container_of(work, struct ath_softc, paprd_work);
  357. struct ieee80211_hw *hw = sc->hw;
  358. struct ath_hw *ah = sc->sc_ah;
  359. struct ieee80211_hdr *hdr;
  360. struct sk_buff *skb = NULL;
  361. struct ath9k_hw_cal_data *caldata = ah->caldata;
  362. struct ath_common *common = ath9k_hw_common(ah);
  363. int ftype;
  364. int chain_ok = 0;
  365. int chain;
  366. int len = 1800;
  367. if (!caldata)
  368. return;
  369. ath9k_ps_wakeup(sc);
  370. if (ar9003_paprd_init_table(ah) < 0)
  371. goto fail_paprd;
  372. skb = alloc_skb(len, GFP_KERNEL);
  373. if (!skb)
  374. goto fail_paprd;
  375. skb_put(skb, len);
  376. memset(skb->data, 0, len);
  377. hdr = (struct ieee80211_hdr *)skb->data;
  378. ftype = IEEE80211_FTYPE_DATA | IEEE80211_STYPE_NULLFUNC;
  379. hdr->frame_control = cpu_to_le16(ftype);
  380. hdr->duration_id = cpu_to_le16(10);
  381. memcpy(hdr->addr1, hw->wiphy->perm_addr, ETH_ALEN);
  382. memcpy(hdr->addr2, hw->wiphy->perm_addr, ETH_ALEN);
  383. memcpy(hdr->addr3, hw->wiphy->perm_addr, ETH_ALEN);
  384. for (chain = 0; chain < AR9300_MAX_CHAINS; chain++) {
  385. if (!(ah->txchainmask & BIT(chain)))
  386. continue;
  387. chain_ok = 0;
  388. ath_dbg(common, CALIBRATE,
  389. "Sending PAPRD frame for thermal measurement on chain %d\n",
  390. chain);
  391. if (!ath_paprd_send_frame(sc, skb, chain))
  392. goto fail_paprd;
  393. ar9003_paprd_setup_gain_table(ah, chain);
  394. ath_dbg(common, CALIBRATE,
  395. "Sending PAPRD training frame on chain %d\n", chain);
  396. if (!ath_paprd_send_frame(sc, skb, chain))
  397. goto fail_paprd;
  398. if (!ar9003_paprd_is_done(ah)) {
  399. ath_dbg(common, CALIBRATE,
  400. "PAPRD not yet done on chain %d\n", chain);
  401. break;
  402. }
  403. if (ar9003_paprd_create_curve(ah, caldata, chain)) {
  404. ath_dbg(common, CALIBRATE,
  405. "PAPRD create curve failed on chain %d\n",
  406. chain);
  407. break;
  408. }
  409. chain_ok = 1;
  410. }
  411. kfree_skb(skb);
  412. if (chain_ok) {
  413. caldata->paprd_done = true;
  414. ath_paprd_activate(sc);
  415. }
  416. fail_paprd:
  417. ath9k_ps_restore(sc);
  418. }
  419. /*
  420. * This routine performs the periodic noise floor calibration function
  421. * that is used to adjust and optimize the chip performance. This
  422. * takes environmental changes (location, temperature) into account.
  423. * When the task is complete, it reschedules itself depending on the
  424. * appropriate interval that was calculated.
  425. */
  426. void ath_ani_calibrate(unsigned long data)
  427. {
  428. struct ath_softc *sc = (struct ath_softc *)data;
  429. struct ath_hw *ah = sc->sc_ah;
  430. struct ath_common *common = ath9k_hw_common(ah);
  431. bool longcal = false;
  432. bool shortcal = false;
  433. bool aniflag = false;
  434. unsigned int timestamp = jiffies_to_msecs(jiffies);
  435. u32 cal_interval, short_cal_interval, long_cal_interval;
  436. unsigned long flags;
  437. if (ah->caldata && ah->caldata->nfcal_interference)
  438. long_cal_interval = ATH_LONG_CALINTERVAL_INT;
  439. else
  440. long_cal_interval = ATH_LONG_CALINTERVAL;
  441. short_cal_interval = (ah->opmode == NL80211_IFTYPE_AP) ?
  442. ATH_AP_SHORT_CALINTERVAL : ATH_STA_SHORT_CALINTERVAL;
  443. /* Only calibrate if awake */
  444. if (sc->sc_ah->power_mode != ATH9K_PM_AWAKE)
  445. goto set_timer;
  446. ath9k_ps_wakeup(sc);
  447. /* Long calibration runs independently of short calibration. */
  448. if ((timestamp - common->ani.longcal_timer) >= long_cal_interval) {
  449. longcal = true;
  450. common->ani.longcal_timer = timestamp;
  451. }
  452. /* Short calibration applies only while caldone is false */
  453. if (!common->ani.caldone) {
  454. if ((timestamp - common->ani.shortcal_timer) >= short_cal_interval) {
  455. shortcal = true;
  456. common->ani.shortcal_timer = timestamp;
  457. common->ani.resetcal_timer = timestamp;
  458. }
  459. } else {
  460. if ((timestamp - common->ani.resetcal_timer) >=
  461. ATH_RESTART_CALINTERVAL) {
  462. common->ani.caldone = ath9k_hw_reset_calvalid(ah);
  463. if (common->ani.caldone)
  464. common->ani.resetcal_timer = timestamp;
  465. }
  466. }
  467. /* Verify whether we must check ANI */
  468. if (sc->sc_ah->config.enable_ani
  469. && (timestamp - common->ani.checkani_timer) >=
  470. ah->config.ani_poll_interval) {
  471. aniflag = true;
  472. common->ani.checkani_timer = timestamp;
  473. }
  474. /* Call ANI routine if necessary */
  475. if (aniflag) {
  476. spin_lock_irqsave(&common->cc_lock, flags);
  477. ath9k_hw_ani_monitor(ah, ah->curchan);
  478. ath_update_survey_stats(sc);
  479. spin_unlock_irqrestore(&common->cc_lock, flags);
  480. }
  481. /* Perform calibration if necessary */
  482. if (longcal || shortcal) {
  483. common->ani.caldone =
  484. ath9k_hw_calibrate(ah, ah->curchan,
  485. ah->rxchainmask, longcal);
  486. }
  487. ath_dbg(common, ANI,
  488. "Calibration @%lu finished: %s %s %s, caldone: %s\n",
  489. jiffies,
  490. longcal ? "long" : "", shortcal ? "short" : "",
  491. aniflag ? "ani" : "", common->ani.caldone ? "true" : "false");
  492. ath9k_ps_restore(sc);
  493. set_timer:
  494. /*
  495. * Set timer interval based on previous results.
  496. * The interval must be the shortest necessary to satisfy ANI,
  497. * short calibration and long calibration.
  498. */
  499. ath9k_debug_samp_bb_mac(sc);
  500. cal_interval = ATH_LONG_CALINTERVAL;
  501. if (sc->sc_ah->config.enable_ani)
  502. cal_interval = min(cal_interval,
  503. (u32)ah->config.ani_poll_interval);
  504. if (!common->ani.caldone)
  505. cal_interval = min(cal_interval, (u32)short_cal_interval);
  506. mod_timer(&common->ani.timer, jiffies + msecs_to_jiffies(cal_interval));
  507. if ((sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_PAPRD) && ah->caldata) {
  508. if (!ah->caldata->paprd_done)
  509. ieee80211_queue_work(sc->hw, &sc->paprd_work);
  510. else if (!ah->paprd_table_write_done)
  511. ath_paprd_activate(sc);
  512. }
  513. }
  514. static void ath_node_attach(struct ath_softc *sc, struct ieee80211_sta *sta,
  515. struct ieee80211_vif *vif)
  516. {
  517. struct ath_node *an;
  518. an = (struct ath_node *)sta->drv_priv;
  519. #ifdef CONFIG_ATH9K_DEBUGFS
  520. spin_lock(&sc->nodes_lock);
  521. list_add(&an->list, &sc->nodes);
  522. spin_unlock(&sc->nodes_lock);
  523. #endif
  524. an->sta = sta;
  525. an->vif = vif;
  526. if (sta->ht_cap.ht_supported) {
  527. ath_tx_node_init(sc, an);
  528. an->maxampdu = 1 << (IEEE80211_HT_MAX_AMPDU_FACTOR +
  529. sta->ht_cap.ampdu_factor);
  530. an->mpdudensity = parse_mpdudensity(sta->ht_cap.ampdu_density);
  531. }
  532. }
  533. static void ath_node_detach(struct ath_softc *sc, struct ieee80211_sta *sta)
  534. {
  535. struct ath_node *an = (struct ath_node *)sta->drv_priv;
  536. #ifdef CONFIG_ATH9K_DEBUGFS
  537. spin_lock(&sc->nodes_lock);
  538. list_del(&an->list);
  539. spin_unlock(&sc->nodes_lock);
  540. an->sta = NULL;
  541. #endif
  542. if (sta->ht_cap.ht_supported)
  543. ath_tx_node_cleanup(sc, an);
  544. }
  545. void ath9k_tasklet(unsigned long data)
  546. {
  547. struct ath_softc *sc = (struct ath_softc *)data;
  548. struct ath_hw *ah = sc->sc_ah;
  549. struct ath_common *common = ath9k_hw_common(ah);
  550. u32 status = sc->intrstatus;
  551. u32 rxmask;
  552. ath9k_ps_wakeup(sc);
  553. spin_lock(&sc->sc_pcu_lock);
  554. if ((status & ATH9K_INT_FATAL) ||
  555. (status & ATH9K_INT_BB_WATCHDOG)) {
  556. #ifdef CONFIG_ATH9K_DEBUGFS
  557. enum ath_reset_type type;
  558. if (status & ATH9K_INT_FATAL)
  559. type = RESET_TYPE_FATAL_INT;
  560. else
  561. type = RESET_TYPE_BB_WATCHDOG;
  562. RESET_STAT_INC(sc, type);
  563. #endif
  564. ieee80211_queue_work(sc->hw, &sc->hw_reset_work);
  565. goto out;
  566. }
  567. /*
  568. * Only run the baseband hang check if beacons stop working in AP or
  569. * IBSS mode, because it has a high false positive rate. For station
  570. * mode it should not be necessary, since the upper layers will detect
  571. * this through a beacon miss automatically and the following channel
  572. * change will trigger a hardware reset anyway
  573. */
  574. if (ath9k_hw_numtxpending(ah, sc->beacon.beaconq) != 0 &&
  575. !ath9k_hw_check_alive(ah))
  576. ieee80211_queue_work(sc->hw, &sc->hw_check_work);
  577. if ((status & ATH9K_INT_TSFOOR) && sc->ps_enabled) {
  578. /*
  579. * TSF sync does not look correct; remain awake to sync with
  580. * the next Beacon.
  581. */
  582. ath_dbg(common, PS, "TSFOOR - Sync with next Beacon\n");
  583. sc->ps_flags |= PS_WAIT_FOR_BEACON | PS_BEACON_SYNC;
  584. }
  585. if (ah->caps.hw_caps & ATH9K_HW_CAP_EDMA)
  586. rxmask = (ATH9K_INT_RXHP | ATH9K_INT_RXLP | ATH9K_INT_RXEOL |
  587. ATH9K_INT_RXORN);
  588. else
  589. rxmask = (ATH9K_INT_RX | ATH9K_INT_RXEOL | ATH9K_INT_RXORN);
  590. if (status & rxmask) {
  591. /* Check for high priority Rx first */
  592. if ((ah->caps.hw_caps & ATH9K_HW_CAP_EDMA) &&
  593. (status & ATH9K_INT_RXHP))
  594. ath_rx_tasklet(sc, 0, true);
  595. ath_rx_tasklet(sc, 0, false);
  596. }
  597. if (status & ATH9K_INT_TX) {
  598. if (ah->caps.hw_caps & ATH9K_HW_CAP_EDMA)
  599. ath_tx_edma_tasklet(sc);
  600. else
  601. ath_tx_tasklet(sc);
  602. }
  603. ath9k_btcoex_handle_interrupt(sc, status);
  604. out:
  605. /* re-enable hardware interrupt */
  606. ath9k_hw_enable_interrupts(ah);
  607. spin_unlock(&sc->sc_pcu_lock);
  608. ath9k_ps_restore(sc);
  609. }
  610. irqreturn_t ath_isr(int irq, void *dev)
  611. {
  612. #define SCHED_INTR ( \
  613. ATH9K_INT_FATAL | \
  614. ATH9K_INT_BB_WATCHDOG | \
  615. ATH9K_INT_RXORN | \
  616. ATH9K_INT_RXEOL | \
  617. ATH9K_INT_RX | \
  618. ATH9K_INT_RXLP | \
  619. ATH9K_INT_RXHP | \
  620. ATH9K_INT_TX | \
  621. ATH9K_INT_BMISS | \
  622. ATH9K_INT_CST | \
  623. ATH9K_INT_TSFOOR | \
  624. ATH9K_INT_GENTIMER | \
  625. ATH9K_INT_MCI)
  626. struct ath_softc *sc = dev;
  627. struct ath_hw *ah = sc->sc_ah;
  628. struct ath_common *common = ath9k_hw_common(ah);
  629. enum ath9k_int status;
  630. bool sched = false;
  631. /*
  632. * The hardware is not ready/present, don't
  633. * touch anything. Note this can happen early
  634. * on if the IRQ is shared.
  635. */
  636. if (sc->sc_flags & SC_OP_INVALID)
  637. return IRQ_NONE;
  638. /* shared irq, not for us */
  639. if (!ath9k_hw_intrpend(ah))
  640. return IRQ_NONE;
  641. /*
  642. * Figure out the reason(s) for the interrupt. Note
  643. * that the hal returns a pseudo-ISR that may include
  644. * bits we haven't explicitly enabled so we mask the
  645. * value to insure we only process bits we requested.
  646. */
  647. ath9k_hw_getisr(ah, &status); /* NB: clears ISR too */
  648. status &= ah->imask; /* discard unasked-for bits */
  649. /*
  650. * If there are no status bits set, then this interrupt was not
  651. * for me (should have been caught above).
  652. */
  653. if (!status)
  654. return IRQ_NONE;
  655. /* Cache the status */
  656. sc->intrstatus = status;
  657. if (status & SCHED_INTR)
  658. sched = true;
  659. /*
  660. * If a FATAL or RXORN interrupt is received, we have to reset the
  661. * chip immediately.
  662. */
  663. if ((status & ATH9K_INT_FATAL) || ((status & ATH9K_INT_RXORN) &&
  664. !(ah->caps.hw_caps & ATH9K_HW_CAP_EDMA)))
  665. goto chip_reset;
  666. if ((ah->caps.hw_caps & ATH9K_HW_CAP_EDMA) &&
  667. (status & ATH9K_INT_BB_WATCHDOG)) {
  668. spin_lock(&common->cc_lock);
  669. ath_hw_cycle_counters_update(common);
  670. ar9003_hw_bb_watchdog_dbg_info(ah);
  671. spin_unlock(&common->cc_lock);
  672. goto chip_reset;
  673. }
  674. if (status & ATH9K_INT_SWBA)
  675. tasklet_schedule(&sc->bcon_tasklet);
  676. if (status & ATH9K_INT_TXURN)
  677. ath9k_hw_updatetxtriglevel(ah, true);
  678. if (status & ATH9K_INT_RXEOL) {
  679. ah->imask &= ~(ATH9K_INT_RXEOL | ATH9K_INT_RXORN);
  680. ath9k_hw_set_interrupts(ah);
  681. }
  682. if (status & ATH9K_INT_MIB) {
  683. /*
  684. * Disable interrupts until we service the MIB
  685. * interrupt; otherwise it will continue to
  686. * fire.
  687. */
  688. ath9k_hw_disable_interrupts(ah);
  689. /*
  690. * Let the hal handle the event. We assume
  691. * it will clear whatever condition caused
  692. * the interrupt.
  693. */
  694. spin_lock(&common->cc_lock);
  695. ath9k_hw_proc_mib_event(ah);
  696. spin_unlock(&common->cc_lock);
  697. ath9k_hw_enable_interrupts(ah);
  698. }
  699. if (!(ah->caps.hw_caps & ATH9K_HW_CAP_AUTOSLEEP))
  700. if (status & ATH9K_INT_TIM_TIMER) {
  701. if (ATH_DBG_WARN_ON_ONCE(sc->ps_idle))
  702. goto chip_reset;
  703. /* Clear RxAbort bit so that we can
  704. * receive frames */
  705. ath9k_setpower(sc, ATH9K_PM_AWAKE);
  706. ath9k_hw_setrxabort(sc->sc_ah, 0);
  707. sc->ps_flags |= PS_WAIT_FOR_BEACON;
  708. }
  709. chip_reset:
  710. ath_debug_stat_interrupt(sc, status);
  711. if (sched) {
  712. /* turn off every interrupt */
  713. ath9k_hw_disable_interrupts(ah);
  714. tasklet_schedule(&sc->intr_tq);
  715. }
  716. return IRQ_HANDLED;
  717. #undef SCHED_INTR
  718. }
  719. static int ath_reset(struct ath_softc *sc, bool retry_tx)
  720. {
  721. int r;
  722. ath9k_ps_wakeup(sc);
  723. r = ath_reset_internal(sc, NULL, retry_tx);
  724. if (retry_tx) {
  725. int i;
  726. for (i = 0; i < ATH9K_NUM_TX_QUEUES; i++) {
  727. if (ATH_TXQ_SETUP(sc, i)) {
  728. spin_lock_bh(&sc->tx.txq[i].axq_lock);
  729. ath_txq_schedule(sc, &sc->tx.txq[i]);
  730. spin_unlock_bh(&sc->tx.txq[i].axq_lock);
  731. }
  732. }
  733. }
  734. ath9k_ps_restore(sc);
  735. return r;
  736. }
  737. void ath_reset_work(struct work_struct *work)
  738. {
  739. struct ath_softc *sc = container_of(work, struct ath_softc, hw_reset_work);
  740. ath_reset(sc, true);
  741. }
  742. void ath_hw_check(struct work_struct *work)
  743. {
  744. struct ath_softc *sc = container_of(work, struct ath_softc, hw_check_work);
  745. struct ath_common *common = ath9k_hw_common(sc->sc_ah);
  746. unsigned long flags;
  747. int busy;
  748. u8 is_alive, nbeacon = 1;
  749. ath9k_ps_wakeup(sc);
  750. is_alive = ath9k_hw_check_alive(sc->sc_ah);
  751. if (is_alive && !AR_SREV_9300(sc->sc_ah))
  752. goto out;
  753. else if (!is_alive && AR_SREV_9300(sc->sc_ah)) {
  754. ath_dbg(common, RESET,
  755. "DCU stuck is detected. Schedule chip reset\n");
  756. RESET_STAT_INC(sc, RESET_TYPE_MAC_HANG);
  757. goto sched_reset;
  758. }
  759. spin_lock_irqsave(&common->cc_lock, flags);
  760. busy = ath_update_survey_stats(sc);
  761. spin_unlock_irqrestore(&common->cc_lock, flags);
  762. ath_dbg(common, RESET, "Possible baseband hang, busy=%d (try %d)\n",
  763. busy, sc->hw_busy_count + 1);
  764. if (busy >= 99) {
  765. if (++sc->hw_busy_count >= 3) {
  766. RESET_STAT_INC(sc, RESET_TYPE_BB_HANG);
  767. goto sched_reset;
  768. }
  769. } else if (busy >= 0) {
  770. sc->hw_busy_count = 0;
  771. nbeacon = 3;
  772. }
  773. ath_start_rx_poll(sc, nbeacon);
  774. goto out;
  775. sched_reset:
  776. ieee80211_queue_work(sc->hw, &sc->hw_reset_work);
  777. out:
  778. ath9k_ps_restore(sc);
  779. }
  780. static void ath_hw_pll_rx_hang_check(struct ath_softc *sc, u32 pll_sqsum)
  781. {
  782. static int count;
  783. struct ath_common *common = ath9k_hw_common(sc->sc_ah);
  784. if (pll_sqsum >= 0x40000) {
  785. count++;
  786. if (count == 3) {
  787. /* Rx is hung for more than 500ms. Reset it */
  788. ath_dbg(common, RESET, "Possible RX hang, resetting\n");
  789. RESET_STAT_INC(sc, RESET_TYPE_PLL_HANG);
  790. ieee80211_queue_work(sc->hw, &sc->hw_reset_work);
  791. count = 0;
  792. }
  793. } else
  794. count = 0;
  795. }
  796. void ath_hw_pll_work(struct work_struct *work)
  797. {
  798. struct ath_softc *sc = container_of(work, struct ath_softc,
  799. hw_pll_work.work);
  800. u32 pll_sqsum;
  801. if (AR_SREV_9485(sc->sc_ah)) {
  802. ath9k_ps_wakeup(sc);
  803. pll_sqsum = ar9003_get_pll_sqsum_dvc(sc->sc_ah);
  804. ath9k_ps_restore(sc);
  805. ath_hw_pll_rx_hang_check(sc, pll_sqsum);
  806. ieee80211_queue_delayed_work(sc->hw, &sc->hw_pll_work, HZ/5);
  807. }
  808. }
  809. /**********************/
  810. /* mac80211 callbacks */
  811. /**********************/
  812. static int ath9k_start(struct ieee80211_hw *hw)
  813. {
  814. struct ath_softc *sc = hw->priv;
  815. struct ath_hw *ah = sc->sc_ah;
  816. struct ath_common *common = ath9k_hw_common(ah);
  817. struct ieee80211_channel *curchan = hw->conf.channel;
  818. struct ath9k_channel *init_channel;
  819. int r;
  820. ath_dbg(common, CONFIG,
  821. "Starting driver with initial channel: %d MHz\n",
  822. curchan->center_freq);
  823. ath9k_ps_wakeup(sc);
  824. mutex_lock(&sc->mutex);
  825. init_channel = ath9k_cmn_get_curchannel(hw, ah);
  826. /* Reset SERDES registers */
  827. ath9k_hw_configpcipowersave(ah, false);
  828. /*
  829. * The basic interface to setting the hardware in a good
  830. * state is ``reset''. On return the hardware is known to
  831. * be powered up and with interrupts disabled. This must
  832. * be followed by initialization of the appropriate bits
  833. * and then setup of the interrupt mask.
  834. */
  835. spin_lock_bh(&sc->sc_pcu_lock);
  836. atomic_set(&ah->intr_ref_cnt, -1);
  837. r = ath9k_hw_reset(ah, init_channel, ah->caldata, false);
  838. if (r) {
  839. ath_err(common,
  840. "Unable to reset hardware; reset status %d (freq %u MHz)\n",
  841. r, curchan->center_freq);
  842. spin_unlock_bh(&sc->sc_pcu_lock);
  843. goto mutex_unlock;
  844. }
  845. /* Setup our intr mask. */
  846. ah->imask = ATH9K_INT_TX | ATH9K_INT_RXEOL |
  847. ATH9K_INT_RXORN | ATH9K_INT_FATAL |
  848. ATH9K_INT_GLOBAL;
  849. if (ah->caps.hw_caps & ATH9K_HW_CAP_EDMA)
  850. ah->imask |= ATH9K_INT_RXHP |
  851. ATH9K_INT_RXLP |
  852. ATH9K_INT_BB_WATCHDOG;
  853. else
  854. ah->imask |= ATH9K_INT_RX;
  855. ah->imask |= ATH9K_INT_GTT;
  856. if (ah->caps.hw_caps & ATH9K_HW_CAP_HT)
  857. ah->imask |= ATH9K_INT_CST;
  858. if (ah->caps.hw_caps & ATH9K_HW_CAP_MCI)
  859. ah->imask |= ATH9K_INT_MCI;
  860. sc->sc_flags &= ~SC_OP_INVALID;
  861. sc->sc_ah->is_monitoring = false;
  862. if (!ath_complete_reset(sc, false)) {
  863. r = -EIO;
  864. spin_unlock_bh(&sc->sc_pcu_lock);
  865. goto mutex_unlock;
  866. }
  867. if (ah->led_pin >= 0) {
  868. ath9k_hw_cfg_output(ah, ah->led_pin,
  869. AR_GPIO_OUTPUT_MUX_AS_OUTPUT);
  870. ath9k_hw_set_gpio(ah, ah->led_pin, 0);
  871. }
  872. /*
  873. * Reset key cache to sane defaults (all entries cleared) instead of
  874. * semi-random values after suspend/resume.
  875. */
  876. ath9k_cmn_init_crypto(sc->sc_ah);
  877. spin_unlock_bh(&sc->sc_pcu_lock);
  878. ath9k_start_btcoex(sc);
  879. if (ah->caps.pcie_lcr_extsync_en && common->bus_ops->extn_synch_en)
  880. common->bus_ops->extn_synch_en(common);
  881. mutex_unlock:
  882. mutex_unlock(&sc->mutex);
  883. ath9k_ps_restore(sc);
  884. return r;
  885. }
  886. static void ath9k_tx(struct ieee80211_hw *hw, struct sk_buff *skb)
  887. {
  888. struct ath_softc *sc = hw->priv;
  889. struct ath_common *common = ath9k_hw_common(sc->sc_ah);
  890. struct ath_tx_control txctl;
  891. struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
  892. if (sc->ps_enabled) {
  893. /*
  894. * mac80211 does not set PM field for normal data frames, so we
  895. * need to update that based on the current PS mode.
  896. */
  897. if (ieee80211_is_data(hdr->frame_control) &&
  898. !ieee80211_is_nullfunc(hdr->frame_control) &&
  899. !ieee80211_has_pm(hdr->frame_control)) {
  900. ath_dbg(common, PS,
  901. "Add PM=1 for a TX frame while in PS mode\n");
  902. hdr->frame_control |= cpu_to_le16(IEEE80211_FCTL_PM);
  903. }
  904. }
  905. /*
  906. * Cannot tx while the hardware is in full sleep, it first needs a full
  907. * chip reset to recover from that
  908. */
  909. if (unlikely(sc->sc_ah->power_mode == ATH9K_PM_FULL_SLEEP))
  910. goto exit;
  911. if (unlikely(sc->sc_ah->power_mode != ATH9K_PM_AWAKE)) {
  912. /*
  913. * We are using PS-Poll and mac80211 can request TX while in
  914. * power save mode. Need to wake up hardware for the TX to be
  915. * completed and if needed, also for RX of buffered frames.
  916. */
  917. ath9k_ps_wakeup(sc);
  918. if (!(sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_AUTOSLEEP))
  919. ath9k_hw_setrxabort(sc->sc_ah, 0);
  920. if (ieee80211_is_pspoll(hdr->frame_control)) {
  921. ath_dbg(common, PS,
  922. "Sending PS-Poll to pick a buffered frame\n");
  923. sc->ps_flags |= PS_WAIT_FOR_PSPOLL_DATA;
  924. } else {
  925. ath_dbg(common, PS, "Wake up to complete TX\n");
  926. sc->ps_flags |= PS_WAIT_FOR_TX_ACK;
  927. }
  928. /*
  929. * The actual restore operation will happen only after
  930. * the sc_flags bit is cleared. We are just dropping
  931. * the ps_usecount here.
  932. */
  933. ath9k_ps_restore(sc);
  934. }
  935. memset(&txctl, 0, sizeof(struct ath_tx_control));
  936. txctl.txq = sc->tx.txq_map[skb_get_queue_mapping(skb)];
  937. ath_dbg(common, XMIT, "transmitting packet, skb: %p\n", skb);
  938. if (ath_tx_start(hw, skb, &txctl) != 0) {
  939. ath_dbg(common, XMIT, "TX failed\n");
  940. TX_STAT_INC(txctl.txq->axq_qnum, txfailed);
  941. goto exit;
  942. }
  943. return;
  944. exit:
  945. dev_kfree_skb_any(skb);
  946. }
  947. static void ath9k_stop(struct ieee80211_hw *hw)
  948. {
  949. struct ath_softc *sc = hw->priv;
  950. struct ath_hw *ah = sc->sc_ah;
  951. struct ath_common *common = ath9k_hw_common(ah);
  952. bool prev_idle;
  953. mutex_lock(&sc->mutex);
  954. ath_cancel_work(sc);
  955. del_timer_sync(&sc->rx_poll_timer);
  956. if (sc->sc_flags & SC_OP_INVALID) {
  957. ath_dbg(common, ANY, "Device not present\n");
  958. mutex_unlock(&sc->mutex);
  959. return;
  960. }
  961. /* Ensure HW is awake when we try to shut it down. */
  962. ath9k_ps_wakeup(sc);
  963. ath9k_stop_btcoex(sc);
  964. spin_lock_bh(&sc->sc_pcu_lock);
  965. /* prevent tasklets to enable interrupts once we disable them */
  966. ah->imask &= ~ATH9K_INT_GLOBAL;
  967. /* make sure h/w will not generate any interrupt
  968. * before setting the invalid flag. */
  969. ath9k_hw_disable_interrupts(ah);
  970. spin_unlock_bh(&sc->sc_pcu_lock);
  971. /* we can now sync irq and kill any running tasklets, since we already
  972. * disabled interrupts and not holding a spin lock */
  973. synchronize_irq(sc->irq);
  974. tasklet_kill(&sc->intr_tq);
  975. tasklet_kill(&sc->bcon_tasklet);
  976. prev_idle = sc->ps_idle;
  977. sc->ps_idle = true;
  978. spin_lock_bh(&sc->sc_pcu_lock);
  979. if (ah->led_pin >= 0) {
  980. ath9k_hw_set_gpio(ah, ah->led_pin, 1);
  981. ath9k_hw_cfg_gpio_input(ah, ah->led_pin);
  982. }
  983. ath_prepare_reset(sc, false, true);
  984. if (sc->rx.frag) {
  985. dev_kfree_skb_any(sc->rx.frag);
  986. sc->rx.frag = NULL;
  987. }
  988. if (!ah->curchan)
  989. ah->curchan = ath9k_cmn_get_curchannel(hw, ah);
  990. ath9k_hw_reset(ah, ah->curchan, ah->caldata, false);
  991. ath9k_hw_phy_disable(ah);
  992. ath9k_hw_configpcipowersave(ah, true);
  993. spin_unlock_bh(&sc->sc_pcu_lock);
  994. ath9k_ps_restore(sc);
  995. sc->sc_flags |= SC_OP_INVALID;
  996. sc->ps_idle = prev_idle;
  997. mutex_unlock(&sc->mutex);
  998. ath_dbg(common, CONFIG, "Driver halt\n");
  999. }
  1000. bool ath9k_uses_beacons(int type)
  1001. {
  1002. switch (type) {
  1003. case NL80211_IFTYPE_AP:
  1004. case NL80211_IFTYPE_ADHOC:
  1005. case NL80211_IFTYPE_MESH_POINT:
  1006. return true;
  1007. default:
  1008. return false;
  1009. }
  1010. }
  1011. static void ath9k_reclaim_beacon(struct ath_softc *sc,
  1012. struct ieee80211_vif *vif)
  1013. {
  1014. struct ath_vif *avp = (void *)vif->drv_priv;
  1015. ath9k_set_beaconing_status(sc, false);
  1016. ath_beacon_return(sc, avp);
  1017. ath9k_set_beaconing_status(sc, true);
  1018. sc->sc_flags &= ~SC_OP_BEACONS;
  1019. }
  1020. static void ath9k_vif_iter(void *data, u8 *mac, struct ieee80211_vif *vif)
  1021. {
  1022. struct ath9k_vif_iter_data *iter_data = data;
  1023. int i;
  1024. if (iter_data->hw_macaddr)
  1025. for (i = 0; i < ETH_ALEN; i++)
  1026. iter_data->mask[i] &=
  1027. ~(iter_data->hw_macaddr[i] ^ mac[i]);
  1028. switch (vif->type) {
  1029. case NL80211_IFTYPE_AP:
  1030. iter_data->naps++;
  1031. break;
  1032. case NL80211_IFTYPE_STATION:
  1033. iter_data->nstations++;
  1034. break;
  1035. case NL80211_IFTYPE_ADHOC:
  1036. iter_data->nadhocs++;
  1037. break;
  1038. case NL80211_IFTYPE_MESH_POINT:
  1039. iter_data->nmeshes++;
  1040. break;
  1041. case NL80211_IFTYPE_WDS:
  1042. iter_data->nwds++;
  1043. break;
  1044. default:
  1045. break;
  1046. }
  1047. }
  1048. /* Called with sc->mutex held. */
  1049. void ath9k_calculate_iter_data(struct ieee80211_hw *hw,
  1050. struct ieee80211_vif *vif,
  1051. struct ath9k_vif_iter_data *iter_data)
  1052. {
  1053. struct ath_softc *sc = hw->priv;
  1054. struct ath_hw *ah = sc->sc_ah;
  1055. struct ath_common *common = ath9k_hw_common(ah);
  1056. /*
  1057. * Use the hardware MAC address as reference, the hardware uses it
  1058. * together with the BSSID mask when matching addresses.
  1059. */
  1060. memset(iter_data, 0, sizeof(*iter_data));
  1061. iter_data->hw_macaddr = common->macaddr;
  1062. memset(&iter_data->mask, 0xff, ETH_ALEN);
  1063. if (vif)
  1064. ath9k_vif_iter(iter_data, vif->addr, vif);
  1065. /* Get list of all active MAC addresses */
  1066. ieee80211_iterate_active_interfaces_atomic(sc->hw, ath9k_vif_iter,
  1067. iter_data);
  1068. }
  1069. /* Called with sc->mutex held. */
  1070. static void ath9k_calculate_summary_state(struct ieee80211_hw *hw,
  1071. struct ieee80211_vif *vif)
  1072. {
  1073. struct ath_softc *sc = hw->priv;
  1074. struct ath_hw *ah = sc->sc_ah;
  1075. struct ath_common *common = ath9k_hw_common(ah);
  1076. struct ath9k_vif_iter_data iter_data;
  1077. ath9k_calculate_iter_data(hw, vif, &iter_data);
  1078. /* Set BSSID mask. */
  1079. memcpy(common->bssidmask, iter_data.mask, ETH_ALEN);
  1080. ath_hw_setbssidmask(common);
  1081. /* Set op-mode & TSF */
  1082. if (iter_data.naps > 0) {
  1083. ath9k_hw_set_tsfadjust(ah, 1);
  1084. sc->sc_flags |= SC_OP_TSF_RESET;
  1085. ah->opmode = NL80211_IFTYPE_AP;
  1086. } else {
  1087. ath9k_hw_set_tsfadjust(ah, 0);
  1088. sc->sc_flags &= ~SC_OP_TSF_RESET;
  1089. if (iter_data.nmeshes)
  1090. ah->opmode = NL80211_IFTYPE_MESH_POINT;
  1091. else if (iter_data.nwds)
  1092. ah->opmode = NL80211_IFTYPE_AP;
  1093. else if (iter_data.nadhocs)
  1094. ah->opmode = NL80211_IFTYPE_ADHOC;
  1095. else
  1096. ah->opmode = NL80211_IFTYPE_STATION;
  1097. }
  1098. /*
  1099. * Enable MIB interrupts when there are hardware phy counters.
  1100. */
  1101. if ((iter_data.nstations + iter_data.nadhocs + iter_data.nmeshes) > 0) {
  1102. if (ah->config.enable_ani)
  1103. ah->imask |= ATH9K_INT_MIB;
  1104. ah->imask |= ATH9K_INT_TSFOOR;
  1105. } else {
  1106. ah->imask &= ~ATH9K_INT_MIB;
  1107. ah->imask &= ~ATH9K_INT_TSFOOR;
  1108. }
  1109. ath9k_hw_set_interrupts(ah);
  1110. /* Set up ANI */
  1111. if (iter_data.naps > 0) {
  1112. sc->sc_ah->stats.avgbrssi = ATH_RSSI_DUMMY_MARKER;
  1113. if (!common->disable_ani) {
  1114. sc->sc_flags |= SC_OP_ANI_RUN;
  1115. ath_start_ani(common);
  1116. }
  1117. } else {
  1118. sc->sc_flags &= ~SC_OP_ANI_RUN;
  1119. del_timer_sync(&common->ani.timer);
  1120. }
  1121. }
  1122. /* Called with sc->mutex held, vif counts set up properly. */
  1123. static void ath9k_do_vif_add_setup(struct ieee80211_hw *hw,
  1124. struct ieee80211_vif *vif)
  1125. {
  1126. struct ath_softc *sc = hw->priv;
  1127. ath9k_calculate_summary_state(hw, vif);
  1128. if (ath9k_uses_beacons(vif->type)) {
  1129. int error;
  1130. /* This may fail because upper levels do not have beacons
  1131. * properly configured yet. That's OK, we assume it
  1132. * will be properly configured and then we will be notified
  1133. * in the info_changed method and set up beacons properly
  1134. * there.
  1135. */
  1136. ath9k_set_beaconing_status(sc, false);
  1137. error = ath_beacon_alloc(sc, vif);
  1138. if (!error)
  1139. ath_beacon_config(sc, vif);
  1140. ath9k_set_beaconing_status(sc, true);
  1141. }
  1142. }
  1143. void ath_start_rx_poll(struct ath_softc *sc, u8 nbeacon)
  1144. {
  1145. if (!AR_SREV_9300(sc->sc_ah))
  1146. return;
  1147. if (!(sc->sc_flags & SC_OP_PRIM_STA_VIF))
  1148. return;
  1149. mod_timer(&sc->rx_poll_timer, jiffies + msecs_to_jiffies
  1150. (nbeacon * sc->cur_beacon_conf.beacon_interval));
  1151. }
  1152. void ath_rx_poll(unsigned long data)
  1153. {
  1154. struct ath_softc *sc = (struct ath_softc *)data;
  1155. ieee80211_queue_work(sc->hw, &sc->hw_check_work);
  1156. }
  1157. static int ath9k_add_interface(struct ieee80211_hw *hw,
  1158. struct ieee80211_vif *vif)
  1159. {
  1160. struct ath_softc *sc = hw->priv;
  1161. struct ath_hw *ah = sc->sc_ah;
  1162. struct ath_common *common = ath9k_hw_common(ah);
  1163. int ret = 0;
  1164. ath9k_ps_wakeup(sc);
  1165. mutex_lock(&sc->mutex);
  1166. switch (vif->type) {
  1167. case NL80211_IFTYPE_STATION:
  1168. case NL80211_IFTYPE_WDS:
  1169. case NL80211_IFTYPE_ADHOC:
  1170. case NL80211_IFTYPE_AP:
  1171. case NL80211_IFTYPE_MESH_POINT:
  1172. break;
  1173. default:
  1174. ath_err(common, "Interface type %d not yet supported\n",
  1175. vif->type);
  1176. ret = -EOPNOTSUPP;
  1177. goto out;
  1178. }
  1179. if (ath9k_uses_beacons(vif->type)) {
  1180. if (sc->nbcnvifs >= ATH_BCBUF) {
  1181. ath_err(common, "Not enough beacon buffers when adding"
  1182. " new interface of type: %i\n",
  1183. vif->type);
  1184. ret = -ENOBUFS;
  1185. goto out;
  1186. }
  1187. }
  1188. if ((ah->opmode == NL80211_IFTYPE_ADHOC) ||
  1189. ((vif->type == NL80211_IFTYPE_ADHOC) &&
  1190. sc->nvifs > 0)) {
  1191. ath_err(common, "Cannot create ADHOC interface when other"
  1192. " interfaces already exist.\n");
  1193. ret = -EINVAL;
  1194. goto out;
  1195. }
  1196. ath_dbg(common, CONFIG, "Attach a VIF of type: %d\n", vif->type);
  1197. sc->nvifs++;
  1198. ath9k_do_vif_add_setup(hw, vif);
  1199. out:
  1200. mutex_unlock(&sc->mutex);
  1201. ath9k_ps_restore(sc);
  1202. return ret;
  1203. }
  1204. static int ath9k_change_interface(struct ieee80211_hw *hw,
  1205. struct ieee80211_vif *vif,
  1206. enum nl80211_iftype new_type,
  1207. bool p2p)
  1208. {
  1209. struct ath_softc *sc = hw->priv;
  1210. struct ath_common *common = ath9k_hw_common(sc->sc_ah);
  1211. int ret = 0;
  1212. ath_dbg(common, CONFIG, "Change Interface\n");
  1213. mutex_lock(&sc->mutex);
  1214. ath9k_ps_wakeup(sc);
  1215. /* See if new interface type is valid. */
  1216. if ((new_type == NL80211_IFTYPE_ADHOC) &&
  1217. (sc->nvifs > 1)) {
  1218. ath_err(common, "When using ADHOC, it must be the only"
  1219. " interface.\n");
  1220. ret = -EINVAL;
  1221. goto out;
  1222. }
  1223. if (ath9k_uses_beacons(new_type) &&
  1224. !ath9k_uses_beacons(vif->type)) {
  1225. if (sc->nbcnvifs >= ATH_BCBUF) {
  1226. ath_err(common, "No beacon slot available\n");
  1227. ret = -ENOBUFS;
  1228. goto out;
  1229. }
  1230. }
  1231. /* Clean up old vif stuff */
  1232. if (ath9k_uses_beacons(vif->type))
  1233. ath9k_reclaim_beacon(sc, vif);
  1234. /* Add new settings */
  1235. vif->type = new_type;
  1236. vif->p2p = p2p;
  1237. ath9k_do_vif_add_setup(hw, vif);
  1238. out:
  1239. ath9k_ps_restore(sc);
  1240. mutex_unlock(&sc->mutex);
  1241. return ret;
  1242. }
  1243. static void ath9k_remove_interface(struct ieee80211_hw *hw,
  1244. struct ieee80211_vif *vif)
  1245. {
  1246. struct ath_softc *sc = hw->priv;
  1247. struct ath_common *common = ath9k_hw_common(sc->sc_ah);
  1248. ath_dbg(common, CONFIG, "Detach Interface\n");
  1249. ath9k_ps_wakeup(sc);
  1250. mutex_lock(&sc->mutex);
  1251. sc->nvifs--;
  1252. /* Reclaim beacon resources */
  1253. if (ath9k_uses_beacons(vif->type))
  1254. ath9k_reclaim_beacon(sc, vif);
  1255. ath9k_calculate_summary_state(hw, NULL);
  1256. mutex_unlock(&sc->mutex);
  1257. ath9k_ps_restore(sc);
  1258. }
  1259. static void ath9k_enable_ps(struct ath_softc *sc)
  1260. {
  1261. struct ath_hw *ah = sc->sc_ah;
  1262. sc->ps_enabled = true;
  1263. if (!(ah->caps.hw_caps & ATH9K_HW_CAP_AUTOSLEEP)) {
  1264. if ((ah->imask & ATH9K_INT_TIM_TIMER) == 0) {
  1265. ah->imask |= ATH9K_INT_TIM_TIMER;
  1266. ath9k_hw_set_interrupts(ah);
  1267. }
  1268. ath9k_hw_setrxabort(ah, 1);
  1269. }
  1270. }
  1271. static void ath9k_disable_ps(struct ath_softc *sc)
  1272. {
  1273. struct ath_hw *ah = sc->sc_ah;
  1274. sc->ps_enabled = false;
  1275. ath9k_hw_setpower(ah, ATH9K_PM_AWAKE);
  1276. if (!(ah->caps.hw_caps & ATH9K_HW_CAP_AUTOSLEEP)) {
  1277. ath9k_hw_setrxabort(ah, 0);
  1278. sc->ps_flags &= ~(PS_WAIT_FOR_BEACON |
  1279. PS_WAIT_FOR_CAB |
  1280. PS_WAIT_FOR_PSPOLL_DATA |
  1281. PS_WAIT_FOR_TX_ACK);
  1282. if (ah->imask & ATH9K_INT_TIM_TIMER) {
  1283. ah->imask &= ~ATH9K_INT_TIM_TIMER;
  1284. ath9k_hw_set_interrupts(ah);
  1285. }
  1286. }
  1287. }
  1288. static int ath9k_config(struct ieee80211_hw *hw, u32 changed)
  1289. {
  1290. struct ath_softc *sc = hw->priv;
  1291. struct ath_hw *ah = sc->sc_ah;
  1292. struct ath_common *common = ath9k_hw_common(ah);
  1293. struct ieee80211_conf *conf = &hw->conf;
  1294. ath9k_ps_wakeup(sc);
  1295. mutex_lock(&sc->mutex);
  1296. if (changed & IEEE80211_CONF_CHANGE_IDLE) {
  1297. sc->ps_idle = !!(conf->flags & IEEE80211_CONF_IDLE);
  1298. if (sc->ps_idle)
  1299. ath_cancel_work(sc);
  1300. }
  1301. /*
  1302. * We just prepare to enable PS. We have to wait until our AP has
  1303. * ACK'd our null data frame to disable RX otherwise we'll ignore
  1304. * those ACKs and end up retransmitting the same null data frames.
  1305. * IEEE80211_CONF_CHANGE_PS is only passed by mac80211 for STA mode.
  1306. */
  1307. if (changed & IEEE80211_CONF_CHANGE_PS) {
  1308. unsigned long flags;
  1309. spin_lock_irqsave(&sc->sc_pm_lock, flags);
  1310. if (conf->flags & IEEE80211_CONF_PS)
  1311. ath9k_enable_ps(sc);
  1312. else
  1313. ath9k_disable_ps(sc);
  1314. spin_unlock_irqrestore(&sc->sc_pm_lock, flags);
  1315. }
  1316. if (changed & IEEE80211_CONF_CHANGE_MONITOR) {
  1317. if (conf->flags & IEEE80211_CONF_MONITOR) {
  1318. ath_dbg(common, CONFIG, "Monitor mode is enabled\n");
  1319. sc->sc_ah->is_monitoring = true;
  1320. } else {
  1321. ath_dbg(common, CONFIG, "Monitor mode is disabled\n");
  1322. sc->sc_ah->is_monitoring = false;
  1323. }
  1324. }
  1325. if (changed & IEEE80211_CONF_CHANGE_CHANNEL) {
  1326. struct ieee80211_channel *curchan = hw->conf.channel;
  1327. int pos = curchan->hw_value;
  1328. int old_pos = -1;
  1329. unsigned long flags;
  1330. if (ah->curchan)
  1331. old_pos = ah->curchan - &ah->channels[0];
  1332. if (hw->conf.flags & IEEE80211_CONF_OFFCHANNEL)
  1333. sc->sc_flags |= SC_OP_OFFCHANNEL;
  1334. else
  1335. sc->sc_flags &= ~SC_OP_OFFCHANNEL;
  1336. ath_dbg(common, CONFIG, "Set channel: %d MHz type: %d\n",
  1337. curchan->center_freq, conf->channel_type);
  1338. /* update survey stats for the old channel before switching */
  1339. spin_lock_irqsave(&common->cc_lock, flags);
  1340. ath_update_survey_stats(sc);
  1341. spin_unlock_irqrestore(&common->cc_lock, flags);
  1342. /*
  1343. * Preserve the current channel values, before updating
  1344. * the same channel
  1345. */
  1346. if (ah->curchan && (old_pos == pos))
  1347. ath9k_hw_getnf(ah, ah->curchan);
  1348. ath9k_cmn_update_ichannel(&sc->sc_ah->channels[pos],
  1349. curchan, conf->channel_type);
  1350. /*
  1351. * If the operating channel changes, change the survey in-use flags
  1352. * along with it.
  1353. * Reset the survey data for the new channel, unless we're switching
  1354. * back to the operating channel from an off-channel operation.
  1355. */
  1356. if (!(hw->conf.flags & IEEE80211_CONF_OFFCHANNEL) &&
  1357. sc->cur_survey != &sc->survey[pos]) {
  1358. if (sc->cur_survey)
  1359. sc->cur_survey->filled &= ~SURVEY_INFO_IN_USE;
  1360. sc->cur_survey = &sc->survey[pos];
  1361. memset(sc->cur_survey, 0, sizeof(struct survey_info));
  1362. sc->cur_survey->filled |= SURVEY_INFO_IN_USE;
  1363. } else if (!(sc->survey[pos].filled & SURVEY_INFO_IN_USE)) {
  1364. memset(&sc->survey[pos], 0, sizeof(struct survey_info));
  1365. }
  1366. if (ath_set_channel(sc, hw, &sc->sc_ah->channels[pos]) < 0) {
  1367. ath_err(common, "Unable to set channel\n");
  1368. mutex_unlock(&sc->mutex);
  1369. return -EINVAL;
  1370. }
  1371. /*
  1372. * The most recent snapshot of channel->noisefloor for the old
  1373. * channel is only available after the hardware reset. Copy it to
  1374. * the survey stats now.
  1375. */
  1376. if (old_pos >= 0)
  1377. ath_update_survey_nf(sc, old_pos);
  1378. }
  1379. if (changed & IEEE80211_CONF_CHANGE_POWER) {
  1380. ath_dbg(common, CONFIG, "Set power: %d\n", conf->power_level);
  1381. sc->config.txpowlimit = 2 * conf->power_level;
  1382. ath9k_cmn_update_txpow(ah, sc->curtxpow,
  1383. sc->config.txpowlimit, &sc->curtxpow);
  1384. }
  1385. mutex_unlock(&sc->mutex);
  1386. ath9k_ps_restore(sc);
  1387. return 0;
  1388. }
  1389. #define SUPPORTED_FILTERS \
  1390. (FIF_PROMISC_IN_BSS | \
  1391. FIF_ALLMULTI | \
  1392. FIF_CONTROL | \
  1393. FIF_PSPOLL | \
  1394. FIF_OTHER_BSS | \
  1395. FIF_BCN_PRBRESP_PROMISC | \
  1396. FIF_PROBE_REQ | \
  1397. FIF_FCSFAIL)
  1398. /* FIXME: sc->sc_full_reset ? */
  1399. static void ath9k_configure_filter(struct ieee80211_hw *hw,
  1400. unsigned int changed_flags,
  1401. unsigned int *total_flags,
  1402. u64 multicast)
  1403. {
  1404. struct ath_softc *sc = hw->priv;
  1405. u32 rfilt;
  1406. changed_flags &= SUPPORTED_FILTERS;
  1407. *total_flags &= SUPPORTED_FILTERS;
  1408. sc->rx.rxfilter = *total_flags;
  1409. ath9k_ps_wakeup(sc);
  1410. rfilt = ath_calcrxfilter(sc);
  1411. ath9k_hw_setrxfilter(sc->sc_ah, rfilt);
  1412. ath9k_ps_restore(sc);
  1413. ath_dbg(ath9k_hw_common(sc->sc_ah), CONFIG, "Set HW RX filter: 0x%x\n",
  1414. rfilt);
  1415. }
  1416. static int ath9k_sta_add(struct ieee80211_hw *hw,
  1417. struct ieee80211_vif *vif,
  1418. struct ieee80211_sta *sta)
  1419. {
  1420. struct ath_softc *sc = hw->priv;
  1421. struct ath_common *common = ath9k_hw_common(sc->sc_ah);
  1422. struct ath_node *an = (struct ath_node *) sta->drv_priv;
  1423. struct ieee80211_key_conf ps_key = { };
  1424. ath_node_attach(sc, sta, vif);
  1425. if (vif->type != NL80211_IFTYPE_AP &&
  1426. vif->type != NL80211_IFTYPE_AP_VLAN)
  1427. return 0;
  1428. an->ps_key = ath_key_config(common, vif, sta, &ps_key);
  1429. return 0;
  1430. }
  1431. static void ath9k_del_ps_key(struct ath_softc *sc,
  1432. struct ieee80211_vif *vif,
  1433. struct ieee80211_sta *sta)
  1434. {
  1435. struct ath_common *common = ath9k_hw_common(sc->sc_ah);
  1436. struct ath_node *an = (struct ath_node *) sta->drv_priv;
  1437. struct ieee80211_key_conf ps_key = { .hw_key_idx = an->ps_key };
  1438. if (!an->ps_key)
  1439. return;
  1440. ath_key_delete(common, &ps_key);
  1441. }
  1442. static int ath9k_sta_remove(struct ieee80211_hw *hw,
  1443. struct ieee80211_vif *vif,
  1444. struct ieee80211_sta *sta)
  1445. {
  1446. struct ath_softc *sc = hw->priv;
  1447. ath9k_del_ps_key(sc, vif, sta);
  1448. ath_node_detach(sc, sta);
  1449. return 0;
  1450. }
  1451. static void ath9k_sta_notify(struct ieee80211_hw *hw,
  1452. struct ieee80211_vif *vif,
  1453. enum sta_notify_cmd cmd,
  1454. struct ieee80211_sta *sta)
  1455. {
  1456. struct ath_softc *sc = hw->priv;
  1457. struct ath_node *an = (struct ath_node *) sta->drv_priv;
  1458. if (!sta->ht_cap.ht_supported)
  1459. return;
  1460. switch (cmd) {
  1461. case STA_NOTIFY_SLEEP:
  1462. an->sleeping = true;
  1463. ath_tx_aggr_sleep(sta, sc, an);
  1464. break;
  1465. case STA_NOTIFY_AWAKE:
  1466. an->sleeping = false;
  1467. ath_tx_aggr_wakeup(sc, an);
  1468. break;
  1469. }
  1470. }
  1471. static int ath9k_conf_tx(struct ieee80211_hw *hw,
  1472. struct ieee80211_vif *vif, u16 queue,
  1473. const struct ieee80211_tx_queue_params *params)
  1474. {
  1475. struct ath_softc *sc = hw->priv;
  1476. struct ath_common *common = ath9k_hw_common(sc->sc_ah);
  1477. struct ath_txq *txq;
  1478. struct ath9k_tx_queue_info qi;
  1479. int ret = 0;
  1480. if (queue >= WME_NUM_AC)
  1481. return 0;
  1482. txq = sc->tx.txq_map[queue];
  1483. ath9k_ps_wakeup(sc);
  1484. mutex_lock(&sc->mutex);
  1485. memset(&qi, 0, sizeof(struct ath9k_tx_queue_info));
  1486. qi.tqi_aifs = params->aifs;
  1487. qi.tqi_cwmin = params->cw_min;
  1488. qi.tqi_cwmax = params->cw_max;
  1489. qi.tqi_burstTime = params->txop;
  1490. ath_dbg(common, CONFIG,
  1491. "Configure tx [queue/halq] [%d/%d], aifs: %d, cw_min: %d, cw_max: %d, txop: %d\n",
  1492. queue, txq->axq_qnum, params->aifs, params->cw_min,
  1493. params->cw_max, params->txop);
  1494. ret = ath_txq_update(sc, txq->axq_qnum, &qi);
  1495. if (ret)
  1496. ath_err(common, "TXQ Update failed\n");
  1497. if (sc->sc_ah->opmode == NL80211_IFTYPE_ADHOC)
  1498. if (queue == WME_AC_BE && !ret)
  1499. ath_beaconq_config(sc);
  1500. mutex_unlock(&sc->mutex);
  1501. ath9k_ps_restore(sc);
  1502. return ret;
  1503. }
  1504. static int ath9k_set_key(struct ieee80211_hw *hw,
  1505. enum set_key_cmd cmd,
  1506. struct ieee80211_vif *vif,
  1507. struct ieee80211_sta *sta,
  1508. struct ieee80211_key_conf *key)
  1509. {
  1510. struct ath_softc *sc = hw->priv;
  1511. struct ath_common *common = ath9k_hw_common(sc->sc_ah);
  1512. int ret = 0;
  1513. if (ath9k_modparam_nohwcrypt)
  1514. return -ENOSPC;
  1515. if ((vif->type == NL80211_IFTYPE_ADHOC ||
  1516. vif->type == NL80211_IFTYPE_MESH_POINT) &&
  1517. (key->cipher == WLAN_CIPHER_SUITE_TKIP ||
  1518. key->cipher == WLAN_CIPHER_SUITE_CCMP) &&
  1519. !(key->flags & IEEE80211_KEY_FLAG_PAIRWISE)) {
  1520. /*
  1521. * For now, disable hw crypto for the RSN IBSS group keys. This
  1522. * could be optimized in the future to use a modified key cache
  1523. * design to support per-STA RX GTK, but until that gets
  1524. * implemented, use of software crypto for group addressed
  1525. * frames is a acceptable to allow RSN IBSS to be used.
  1526. */
  1527. return -EOPNOTSUPP;
  1528. }
  1529. mutex_lock(&sc->mutex);
  1530. ath9k_ps_wakeup(sc);
  1531. ath_dbg(common, CONFIG, "Set HW Key\n");
  1532. switch (cmd) {
  1533. case SET_KEY:
  1534. if (sta)
  1535. ath9k_del_ps_key(sc, vif, sta);
  1536. ret = ath_key_config(common, vif, sta, key);
  1537. if (ret >= 0) {
  1538. key->hw_key_idx = ret;
  1539. /* push IV and Michael MIC generation to stack */
  1540. key->flags |= IEEE80211_KEY_FLAG_GENERATE_IV;
  1541. if (key->cipher == WLAN_CIPHER_SUITE_TKIP)
  1542. key->flags |= IEEE80211_KEY_FLAG_GENERATE_MMIC;
  1543. if (sc->sc_ah->sw_mgmt_crypto &&
  1544. key->cipher == WLAN_CIPHER_SUITE_CCMP)
  1545. key->flags |= IEEE80211_KEY_FLAG_SW_MGMT;
  1546. ret = 0;
  1547. }
  1548. break;
  1549. case DISABLE_KEY:
  1550. ath_key_delete(common, key);
  1551. break;
  1552. default:
  1553. ret = -EINVAL;
  1554. }
  1555. ath9k_ps_restore(sc);
  1556. mutex_unlock(&sc->mutex);
  1557. return ret;
  1558. }
  1559. static void ath9k_bss_iter(void *data, u8 *mac, struct ieee80211_vif *vif)
  1560. {
  1561. struct ath_softc *sc = data;
  1562. struct ath_common *common = ath9k_hw_common(sc->sc_ah);
  1563. struct ieee80211_bss_conf *bss_conf = &vif->bss_conf;
  1564. struct ath_vif *avp = (void *)vif->drv_priv;
  1565. /*
  1566. * Skip iteration if primary station vif's bss info
  1567. * was not changed
  1568. */
  1569. if (sc->sc_flags & SC_OP_PRIM_STA_VIF)
  1570. return;
  1571. if (bss_conf->assoc) {
  1572. sc->sc_flags |= SC_OP_PRIM_STA_VIF;
  1573. avp->primary_sta_vif = true;
  1574. memcpy(common->curbssid, bss_conf->bssid, ETH_ALEN);
  1575. common->curaid = bss_conf->aid;
  1576. ath9k_hw_write_associd(sc->sc_ah);
  1577. ath_dbg(common, CONFIG, "Bss Info ASSOC %d, bssid: %pM\n",
  1578. bss_conf->aid, common->curbssid);
  1579. ath_beacon_config(sc, vif);
  1580. /*
  1581. * Request a re-configuration of Beacon related timers
  1582. * on the receipt of the first Beacon frame (i.e.,
  1583. * after time sync with the AP).
  1584. */
  1585. sc->ps_flags |= PS_BEACON_SYNC | PS_WAIT_FOR_BEACON;
  1586. /* Reset rssi stats */
  1587. sc->last_rssi = ATH_RSSI_DUMMY_MARKER;
  1588. sc->sc_ah->stats.avgbrssi = ATH_RSSI_DUMMY_MARKER;
  1589. ath_start_rx_poll(sc, 3);
  1590. if (!common->disable_ani) {
  1591. sc->sc_flags |= SC_OP_ANI_RUN;
  1592. ath_start_ani(common);
  1593. }
  1594. }
  1595. }
  1596. static void ath9k_config_bss(struct ath_softc *sc, struct ieee80211_vif *vif)
  1597. {
  1598. struct ath_common *common = ath9k_hw_common(sc->sc_ah);
  1599. struct ieee80211_bss_conf *bss_conf = &vif->bss_conf;
  1600. struct ath_vif *avp = (void *)vif->drv_priv;
  1601. if (sc->sc_ah->opmode != NL80211_IFTYPE_STATION)
  1602. return;
  1603. /* Reconfigure bss info */
  1604. if (avp->primary_sta_vif && !bss_conf->assoc) {
  1605. ath_dbg(common, CONFIG, "Bss Info DISASSOC %d, bssid %pM\n",
  1606. common->curaid, common->curbssid);
  1607. sc->sc_flags &= ~(SC_OP_PRIM_STA_VIF | SC_OP_BEACONS);
  1608. avp->primary_sta_vif = false;
  1609. memset(common->curbssid, 0, ETH_ALEN);
  1610. common->curaid = 0;
  1611. }
  1612. ieee80211_iterate_active_interfaces_atomic(
  1613. sc->hw, ath9k_bss_iter, sc);
  1614. /*
  1615. * None of station vifs are associated.
  1616. * Clear bssid & aid
  1617. */
  1618. if (!(sc->sc_flags & SC_OP_PRIM_STA_VIF)) {
  1619. ath9k_hw_write_associd(sc->sc_ah);
  1620. /* Stop ANI */
  1621. sc->sc_flags &= ~SC_OP_ANI_RUN;
  1622. del_timer_sync(&common->ani.timer);
  1623. del_timer_sync(&sc->rx_poll_timer);
  1624. memset(&sc->caldata, 0, sizeof(sc->caldata));
  1625. }
  1626. }
  1627. static void ath9k_bss_info_changed(struct ieee80211_hw *hw,
  1628. struct ieee80211_vif *vif,
  1629. struct ieee80211_bss_conf *bss_conf,
  1630. u32 changed)
  1631. {
  1632. struct ath_softc *sc = hw->priv;
  1633. struct ath_hw *ah = sc->sc_ah;
  1634. struct ath_common *common = ath9k_hw_common(ah);
  1635. struct ath_vif *avp = (void *)vif->drv_priv;
  1636. int slottime;
  1637. int error;
  1638. ath9k_ps_wakeup(sc);
  1639. mutex_lock(&sc->mutex);
  1640. if (changed & BSS_CHANGED_ASSOC) {
  1641. ath9k_config_bss(sc, vif);
  1642. ath_dbg(common, CONFIG, "BSSID: %pM aid: 0x%x\n",
  1643. common->curbssid, common->curaid);
  1644. }
  1645. if (changed & BSS_CHANGED_IBSS) {
  1646. /* There can be only one vif available */
  1647. memcpy(common->curbssid, bss_conf->bssid, ETH_ALEN);
  1648. common->curaid = bss_conf->aid;
  1649. ath9k_hw_write_associd(sc->sc_ah);
  1650. if (bss_conf->ibss_joined) {
  1651. sc->sc_ah->stats.avgbrssi = ATH_RSSI_DUMMY_MARKER;
  1652. if (!common->disable_ani) {
  1653. sc->sc_flags |= SC_OP_ANI_RUN;
  1654. ath_start_ani(common);
  1655. }
  1656. } else {
  1657. sc->sc_flags &= ~SC_OP_ANI_RUN;
  1658. del_timer_sync(&common->ani.timer);
  1659. del_timer_sync(&sc->rx_poll_timer);
  1660. }
  1661. }
  1662. /* Enable transmission of beacons (AP, IBSS, MESH) */
  1663. if ((changed & BSS_CHANGED_BEACON) ||
  1664. ((changed & BSS_CHANGED_BEACON_ENABLED) && bss_conf->enable_beacon)) {
  1665. ath9k_set_beaconing_status(sc, false);
  1666. error = ath_beacon_alloc(sc, vif);
  1667. if (!error)
  1668. ath_beacon_config(sc, vif);
  1669. ath9k_set_beaconing_status(sc, true);
  1670. }
  1671. if (changed & BSS_CHANGED_ERP_SLOT) {
  1672. if (bss_conf->use_short_slot)
  1673. slottime = 9;
  1674. else
  1675. slottime = 20;
  1676. if (vif->type == NL80211_IFTYPE_AP) {
  1677. /*
  1678. * Defer update, so that connected stations can adjust
  1679. * their settings at the same time.
  1680. * See beacon.c for more details
  1681. */
  1682. sc->beacon.slottime = slottime;
  1683. sc->beacon.updateslot = UPDATE;
  1684. } else {
  1685. ah->slottime = slottime;
  1686. ath9k_hw_init_global_settings(ah);
  1687. }
  1688. }
  1689. /* Disable transmission of beacons */
  1690. if ((changed & BSS_CHANGED_BEACON_ENABLED) &&
  1691. !bss_conf->enable_beacon) {
  1692. ath9k_set_beaconing_status(sc, false);
  1693. avp->is_bslot_active = false;
  1694. ath9k_set_beaconing_status(sc, true);
  1695. }
  1696. if (changed & BSS_CHANGED_BEACON_INT) {
  1697. /*
  1698. * In case of AP mode, the HW TSF has to be reset
  1699. * when the beacon interval changes.
  1700. */
  1701. if (vif->type == NL80211_IFTYPE_AP) {
  1702. sc->sc_flags |= SC_OP_TSF_RESET;
  1703. ath9k_set_beaconing_status(sc, false);
  1704. error = ath_beacon_alloc(sc, vif);
  1705. if (!error)
  1706. ath_beacon_config(sc, vif);
  1707. ath9k_set_beaconing_status(sc, true);
  1708. } else
  1709. ath_beacon_config(sc, vif);
  1710. }
  1711. mutex_unlock(&sc->mutex);
  1712. ath9k_ps_restore(sc);
  1713. }
  1714. static u64 ath9k_get_tsf(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
  1715. {
  1716. struct ath_softc *sc = hw->priv;
  1717. u64 tsf;
  1718. mutex_lock(&sc->mutex);
  1719. ath9k_ps_wakeup(sc);
  1720. tsf = ath9k_hw_gettsf64(sc->sc_ah);
  1721. ath9k_ps_restore(sc);
  1722. mutex_unlock(&sc->mutex);
  1723. return tsf;
  1724. }
  1725. static void ath9k_set_tsf(struct ieee80211_hw *hw,
  1726. struct ieee80211_vif *vif,
  1727. u64 tsf)
  1728. {
  1729. struct ath_softc *sc = hw->priv;
  1730. mutex_lock(&sc->mutex);
  1731. ath9k_ps_wakeup(sc);
  1732. ath9k_hw_settsf64(sc->sc_ah, tsf);
  1733. ath9k_ps_restore(sc);
  1734. mutex_unlock(&sc->mutex);
  1735. }
  1736. static void ath9k_reset_tsf(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
  1737. {
  1738. struct ath_softc *sc = hw->priv;
  1739. mutex_lock(&sc->mutex);
  1740. ath9k_ps_wakeup(sc);
  1741. ath9k_hw_reset_tsf(sc->sc_ah);
  1742. ath9k_ps_restore(sc);
  1743. mutex_unlock(&sc->mutex);
  1744. }
  1745. static int ath9k_ampdu_action(struct ieee80211_hw *hw,
  1746. struct ieee80211_vif *vif,
  1747. enum ieee80211_ampdu_mlme_action action,
  1748. struct ieee80211_sta *sta,
  1749. u16 tid, u16 *ssn, u8 buf_size)
  1750. {
  1751. struct ath_softc *sc = hw->priv;
  1752. int ret = 0;
  1753. local_bh_disable();
  1754. switch (action) {
  1755. case IEEE80211_AMPDU_RX_START:
  1756. break;
  1757. case IEEE80211_AMPDU_RX_STOP:
  1758. break;
  1759. case IEEE80211_AMPDU_TX_START:
  1760. ath9k_ps_wakeup(sc);
  1761. ret = ath_tx_aggr_start(sc, sta, tid, ssn);
  1762. if (!ret)
  1763. ieee80211_start_tx_ba_cb_irqsafe(vif, sta->addr, tid);
  1764. ath9k_ps_restore(sc);
  1765. break;
  1766. case IEEE80211_AMPDU_TX_STOP:
  1767. ath9k_ps_wakeup(sc);
  1768. ath_tx_aggr_stop(sc, sta, tid);
  1769. ieee80211_stop_tx_ba_cb_irqsafe(vif, sta->addr, tid);
  1770. ath9k_ps_restore(sc);
  1771. break;
  1772. case IEEE80211_AMPDU_TX_OPERATIONAL:
  1773. ath9k_ps_wakeup(sc);
  1774. ath_tx_aggr_resume(sc, sta, tid);
  1775. ath9k_ps_restore(sc);
  1776. break;
  1777. default:
  1778. ath_err(ath9k_hw_common(sc->sc_ah), "Unknown AMPDU action\n");
  1779. }
  1780. local_bh_enable();
  1781. return ret;
  1782. }
  1783. static int ath9k_get_survey(struct ieee80211_hw *hw, int idx,
  1784. struct survey_info *survey)
  1785. {
  1786. struct ath_softc *sc = hw->priv;
  1787. struct ath_common *common = ath9k_hw_common(sc->sc_ah);
  1788. struct ieee80211_supported_band *sband;
  1789. struct ieee80211_channel *chan;
  1790. unsigned long flags;
  1791. int pos;
  1792. spin_lock_irqsave(&common->cc_lock, flags);
  1793. if (idx == 0)
  1794. ath_update_survey_stats(sc);
  1795. sband = hw->wiphy->bands[IEEE80211_BAND_2GHZ];
  1796. if (sband && idx >= sband->n_channels) {
  1797. idx -= sband->n_channels;
  1798. sband = NULL;
  1799. }
  1800. if (!sband)
  1801. sband = hw->wiphy->bands[IEEE80211_BAND_5GHZ];
  1802. if (!sband || idx >= sband->n_channels) {
  1803. spin_unlock_irqrestore(&common->cc_lock, flags);
  1804. return -ENOENT;
  1805. }
  1806. chan = &sband->channels[idx];
  1807. pos = chan->hw_value;
  1808. memcpy(survey, &sc->survey[pos], sizeof(*survey));
  1809. survey->channel = chan;
  1810. spin_unlock_irqrestore(&common->cc_lock, flags);
  1811. return 0;
  1812. }
  1813. static void ath9k_set_coverage_class(struct ieee80211_hw *hw, u8 coverage_class)
  1814. {
  1815. struct ath_softc *sc = hw->priv;
  1816. struct ath_hw *ah = sc->sc_ah;
  1817. mutex_lock(&sc->mutex);
  1818. ah->coverage_class = coverage_class;
  1819. ath9k_ps_wakeup(sc);
  1820. ath9k_hw_init_global_settings(ah);
  1821. ath9k_ps_restore(sc);
  1822. mutex_unlock(&sc->mutex);
  1823. }
  1824. static void ath9k_flush(struct ieee80211_hw *hw, bool drop)
  1825. {
  1826. struct ath_softc *sc = hw->priv;
  1827. struct ath_hw *ah = sc->sc_ah;
  1828. struct ath_common *common = ath9k_hw_common(ah);
  1829. int timeout = 200; /* ms */
  1830. int i, j;
  1831. bool drain_txq;
  1832. mutex_lock(&sc->mutex);
  1833. cancel_delayed_work_sync(&sc->tx_complete_work);
  1834. if (ah->ah_flags & AH_UNPLUGGED) {
  1835. ath_dbg(common, ANY, "Device has been unplugged!\n");
  1836. mutex_unlock(&sc->mutex);
  1837. return;
  1838. }
  1839. if (sc->sc_flags & SC_OP_INVALID) {
  1840. ath_dbg(common, ANY, "Device not present\n");
  1841. mutex_unlock(&sc->mutex);
  1842. return;
  1843. }
  1844. for (j = 0; j < timeout; j++) {
  1845. bool npend = false;
  1846. if (j)
  1847. usleep_range(1000, 2000);
  1848. for (i = 0; i < ATH9K_NUM_TX_QUEUES; i++) {
  1849. if (!ATH_TXQ_SETUP(sc, i))
  1850. continue;
  1851. npend = ath9k_has_pending_frames(sc, &sc->tx.txq[i]);
  1852. if (npend)
  1853. break;
  1854. }
  1855. if (!npend)
  1856. break;
  1857. }
  1858. if (drop) {
  1859. ath9k_ps_wakeup(sc);
  1860. spin_lock_bh(&sc->sc_pcu_lock);
  1861. drain_txq = ath_drain_all_txq(sc, false);
  1862. spin_unlock_bh(&sc->sc_pcu_lock);
  1863. if (!drain_txq)
  1864. ath_reset(sc, false);
  1865. ath9k_ps_restore(sc);
  1866. ieee80211_wake_queues(hw);
  1867. }
  1868. ieee80211_queue_delayed_work(hw, &sc->tx_complete_work, 0);
  1869. mutex_unlock(&sc->mutex);
  1870. }
  1871. static bool ath9k_tx_frames_pending(struct ieee80211_hw *hw)
  1872. {
  1873. struct ath_softc *sc = hw->priv;
  1874. int i;
  1875. for (i = 0; i < ATH9K_NUM_TX_QUEUES; i++) {
  1876. if (!ATH_TXQ_SETUP(sc, i))
  1877. continue;
  1878. if (ath9k_has_pending_frames(sc, &sc->tx.txq[i]))
  1879. return true;
  1880. }
  1881. return false;
  1882. }
  1883. static int ath9k_tx_last_beacon(struct ieee80211_hw *hw)
  1884. {
  1885. struct ath_softc *sc = hw->priv;
  1886. struct ath_hw *ah = sc->sc_ah;
  1887. struct ieee80211_vif *vif;
  1888. struct ath_vif *avp;
  1889. struct ath_buf *bf;
  1890. struct ath_tx_status ts;
  1891. bool edma = !!(ah->caps.hw_caps & ATH9K_HW_CAP_EDMA);
  1892. int status;
  1893. vif = sc->beacon.bslot[0];
  1894. if (!vif)
  1895. return 0;
  1896. avp = (void *)vif->drv_priv;
  1897. if (!avp->is_bslot_active)
  1898. return 0;
  1899. if (!sc->beacon.tx_processed && !edma) {
  1900. tasklet_disable(&sc->bcon_tasklet);
  1901. bf = avp->av_bcbuf;
  1902. if (!bf || !bf->bf_mpdu)
  1903. goto skip;
  1904. status = ath9k_hw_txprocdesc(ah, bf->bf_desc, &ts);
  1905. if (status == -EINPROGRESS)
  1906. goto skip;
  1907. sc->beacon.tx_processed = true;
  1908. sc->beacon.tx_last = !(ts.ts_status & ATH9K_TXERR_MASK);
  1909. skip:
  1910. tasklet_enable(&sc->bcon_tasklet);
  1911. }
  1912. return sc->beacon.tx_last;
  1913. }
  1914. static int ath9k_get_stats(struct ieee80211_hw *hw,
  1915. struct ieee80211_low_level_stats *stats)
  1916. {
  1917. struct ath_softc *sc = hw->priv;
  1918. struct ath_hw *ah = sc->sc_ah;
  1919. struct ath9k_mib_stats *mib_stats = &ah->ah_mibStats;
  1920. stats->dot11ACKFailureCount = mib_stats->ackrcv_bad;
  1921. stats->dot11RTSFailureCount = mib_stats->rts_bad;
  1922. stats->dot11FCSErrorCount = mib_stats->fcs_bad;
  1923. stats->dot11RTSSuccessCount = mib_stats->rts_good;
  1924. return 0;
  1925. }
  1926. static u32 fill_chainmask(u32 cap, u32 new)
  1927. {
  1928. u32 filled = 0;
  1929. int i;
  1930. for (i = 0; cap && new; i++, cap >>= 1) {
  1931. if (!(cap & BIT(0)))
  1932. continue;
  1933. if (new & BIT(0))
  1934. filled |= BIT(i);
  1935. new >>= 1;
  1936. }
  1937. return filled;
  1938. }
  1939. static int ath9k_set_antenna(struct ieee80211_hw *hw, u32 tx_ant, u32 rx_ant)
  1940. {
  1941. struct ath_softc *sc = hw->priv;
  1942. struct ath_hw *ah = sc->sc_ah;
  1943. if (!rx_ant || !tx_ant)
  1944. return -EINVAL;
  1945. sc->ant_rx = rx_ant;
  1946. sc->ant_tx = tx_ant;
  1947. if (ah->caps.rx_chainmask == 1)
  1948. return 0;
  1949. /* AR9100 runs into calibration issues if not all rx chains are enabled */
  1950. if (AR_SREV_9100(ah))
  1951. ah->rxchainmask = 0x7;
  1952. else
  1953. ah->rxchainmask = fill_chainmask(ah->caps.rx_chainmask, rx_ant);
  1954. ah->txchainmask = fill_chainmask(ah->caps.tx_chainmask, tx_ant);
  1955. ath9k_reload_chainmask_settings(sc);
  1956. return 0;
  1957. }
  1958. static int ath9k_get_antenna(struct ieee80211_hw *hw, u32 *tx_ant, u32 *rx_ant)
  1959. {
  1960. struct ath_softc *sc = hw->priv;
  1961. *tx_ant = sc->ant_tx;
  1962. *rx_ant = sc->ant_rx;
  1963. return 0;
  1964. }
  1965. struct ieee80211_ops ath9k_ops = {
  1966. .tx = ath9k_tx,
  1967. .start = ath9k_start,
  1968. .stop = ath9k_stop,
  1969. .add_interface = ath9k_add_interface,
  1970. .change_interface = ath9k_change_interface,
  1971. .remove_interface = ath9k_remove_interface,
  1972. .config = ath9k_config,
  1973. .configure_filter = ath9k_configure_filter,
  1974. .sta_add = ath9k_sta_add,
  1975. .sta_remove = ath9k_sta_remove,
  1976. .sta_notify = ath9k_sta_notify,
  1977. .conf_tx = ath9k_conf_tx,
  1978. .bss_info_changed = ath9k_bss_info_changed,
  1979. .set_key = ath9k_set_key,
  1980. .get_tsf = ath9k_get_tsf,
  1981. .set_tsf = ath9k_set_tsf,
  1982. .reset_tsf = ath9k_reset_tsf,
  1983. .ampdu_action = ath9k_ampdu_action,
  1984. .get_survey = ath9k_get_survey,
  1985. .rfkill_poll = ath9k_rfkill_poll_state,
  1986. .set_coverage_class = ath9k_set_coverage_class,
  1987. .flush = ath9k_flush,
  1988. .tx_frames_pending = ath9k_tx_frames_pending,
  1989. .tx_last_beacon = ath9k_tx_last_beacon,
  1990. .get_stats = ath9k_get_stats,
  1991. .set_antenna = ath9k_set_antenna,
  1992. .get_antenna = ath9k_get_antenna,
  1993. };