main.c 59 KB

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