main.c 51 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111
  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. u8 ath9k_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. memset(&common->cc_ani, 0, sizeof(common->cc_ani));
  92. spin_unlock(&common->cc_lock);
  93. }
  94. unlock:
  95. spin_unlock_irqrestore(&sc->sc_pm_lock, flags);
  96. }
  97. void ath9k_ps_restore(struct ath_softc *sc)
  98. {
  99. struct ath_common *common = ath9k_hw_common(sc->sc_ah);
  100. enum ath9k_power_mode mode;
  101. unsigned long flags;
  102. bool reset;
  103. spin_lock_irqsave(&sc->sc_pm_lock, flags);
  104. if (--sc->ps_usecount != 0)
  105. goto unlock;
  106. if (sc->ps_idle) {
  107. ath9k_hw_setrxabort(sc->sc_ah, 1);
  108. ath9k_hw_stopdmarecv(sc->sc_ah, &reset);
  109. mode = 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. mode = ATH9K_PM_NETWORK_SLEEP;
  116. if (ath9k_hw_btcoex_is_enabled(sc->sc_ah))
  117. ath9k_btcoex_stop_gen_timer(sc);
  118. } else {
  119. goto unlock;
  120. }
  121. spin_lock(&common->cc_lock);
  122. ath_hw_cycle_counters_update(common);
  123. spin_unlock(&common->cc_lock);
  124. ath9k_hw_setpower(sc->sc_ah, mode);
  125. unlock:
  126. spin_unlock_irqrestore(&sc->sc_pm_lock, flags);
  127. }
  128. static void __ath_cancel_work(struct ath_softc *sc)
  129. {
  130. cancel_work_sync(&sc->paprd_work);
  131. cancel_work_sync(&sc->hw_check_work);
  132. cancel_delayed_work_sync(&sc->tx_complete_work);
  133. cancel_delayed_work_sync(&sc->hw_pll_work);
  134. #ifdef CONFIG_ATH9K_BTCOEX_SUPPORT
  135. if (ath9k_hw_mci_is_enabled(sc->sc_ah))
  136. cancel_work_sync(&sc->mci_work);
  137. #endif
  138. }
  139. static void ath_cancel_work(struct ath_softc *sc)
  140. {
  141. __ath_cancel_work(sc);
  142. cancel_work_sync(&sc->hw_reset_work);
  143. }
  144. static void ath_restart_work(struct ath_softc *sc)
  145. {
  146. struct ath_common *common = ath9k_hw_common(sc->sc_ah);
  147. ieee80211_queue_delayed_work(sc->hw, &sc->tx_complete_work, 0);
  148. if (AR_SREV_9485(sc->sc_ah) || AR_SREV_9340(sc->sc_ah))
  149. ieee80211_queue_delayed_work(sc->hw, &sc->hw_pll_work,
  150. msecs_to_jiffies(ATH_PLL_WORK_INTERVAL));
  151. ath_start_rx_poll(sc, 3);
  152. if (!common->disable_ani)
  153. ath_start_ani(common);
  154. }
  155. static bool ath_prepare_reset(struct ath_softc *sc, bool retry_tx, bool flush)
  156. {
  157. struct ath_hw *ah = sc->sc_ah;
  158. struct ath_common *common = ath9k_hw_common(ah);
  159. bool ret = true;
  160. ieee80211_stop_queues(sc->hw);
  161. sc->hw_busy_count = 0;
  162. del_timer_sync(&common->ani.timer);
  163. del_timer_sync(&sc->rx_poll_timer);
  164. ath9k_debug_samp_bb_mac(sc);
  165. ath9k_hw_disable_interrupts(ah);
  166. if (!ath_stoprecv(sc))
  167. ret = false;
  168. if (!ath_drain_all_txq(sc, retry_tx))
  169. ret = false;
  170. if (!flush) {
  171. if (ah->caps.hw_caps & ATH9K_HW_CAP_EDMA)
  172. ath_rx_tasklet(sc, 1, true);
  173. ath_rx_tasklet(sc, 1, false);
  174. } else {
  175. ath_flushrecv(sc);
  176. }
  177. return ret;
  178. }
  179. static bool ath_complete_reset(struct ath_softc *sc, bool start)
  180. {
  181. struct ath_hw *ah = sc->sc_ah;
  182. struct ath_common *common = ath9k_hw_common(ah);
  183. unsigned long flags;
  184. if (ath_startrecv(sc) != 0) {
  185. ath_err(common, "Unable to restart recv logic\n");
  186. return false;
  187. }
  188. ath9k_cmn_update_txpow(ah, sc->curtxpow,
  189. sc->config.txpowlimit, &sc->curtxpow);
  190. clear_bit(SC_OP_HW_RESET, &sc->sc_flags);
  191. ath9k_hw_set_interrupts(ah);
  192. ath9k_hw_enable_interrupts(ah);
  193. if (!(sc->hw->conf.flags & IEEE80211_CONF_OFFCHANNEL) && start) {
  194. if (!test_bit(SC_OP_BEACONS, &sc->sc_flags))
  195. goto work;
  196. ath_set_beacon(sc);
  197. if (ah->opmode == NL80211_IFTYPE_STATION &&
  198. test_bit(SC_OP_PRIM_STA_VIF, &sc->sc_flags)) {
  199. spin_lock_irqsave(&sc->sc_pm_lock, flags);
  200. sc->ps_flags |= PS_BEACON_SYNC | PS_WAIT_FOR_BEACON;
  201. spin_unlock_irqrestore(&sc->sc_pm_lock, flags);
  202. }
  203. work:
  204. ath_restart_work(sc);
  205. }
  206. if ((ah->caps.hw_caps & ATH9K_HW_CAP_ANT_DIV_COMB) && sc->ant_rx != 3)
  207. ath_ant_comb_update(sc);
  208. ieee80211_wake_queues(sc->hw);
  209. return true;
  210. }
  211. static int ath_reset_internal(struct ath_softc *sc, struct ath9k_channel *hchan,
  212. bool retry_tx)
  213. {
  214. struct ath_hw *ah = sc->sc_ah;
  215. struct ath_common *common = ath9k_hw_common(ah);
  216. struct ath9k_hw_cal_data *caldata = NULL;
  217. bool fastcc = true;
  218. bool flush = false;
  219. int r;
  220. __ath_cancel_work(sc);
  221. spin_lock_bh(&sc->sc_pcu_lock);
  222. if (!(sc->hw->conf.flags & IEEE80211_CONF_OFFCHANNEL)) {
  223. fastcc = false;
  224. caldata = &sc->caldata;
  225. }
  226. if (!hchan) {
  227. fastcc = false;
  228. flush = true;
  229. hchan = ah->curchan;
  230. }
  231. if (!ath_prepare_reset(sc, retry_tx, flush))
  232. fastcc = false;
  233. ath_dbg(common, CONFIG, "Reset to %u MHz, HT40: %d fastcc: %d\n",
  234. hchan->channel, IS_CHAN_HT40(hchan), fastcc);
  235. r = ath9k_hw_reset(ah, hchan, caldata, fastcc);
  236. if (r) {
  237. ath_err(common,
  238. "Unable to reset channel, reset status %d\n", r);
  239. goto out;
  240. }
  241. if (!ath_complete_reset(sc, true))
  242. r = -EIO;
  243. out:
  244. spin_unlock_bh(&sc->sc_pcu_lock);
  245. return r;
  246. }
  247. /*
  248. * Set/change channels. If the channel is really being changed, it's done
  249. * by reseting the chip. To accomplish this we must first cleanup any pending
  250. * DMA, then restart stuff.
  251. */
  252. static int ath_set_channel(struct ath_softc *sc, struct ieee80211_hw *hw,
  253. struct ath9k_channel *hchan)
  254. {
  255. int r;
  256. if (test_bit(SC_OP_INVALID, &sc->sc_flags))
  257. return -EIO;
  258. r = ath_reset_internal(sc, hchan, false);
  259. return r;
  260. }
  261. static void ath_node_attach(struct ath_softc *sc, struct ieee80211_sta *sta,
  262. struct ieee80211_vif *vif)
  263. {
  264. struct ath_node *an;
  265. u8 density;
  266. an = (struct ath_node *)sta->drv_priv;
  267. #ifdef CONFIG_ATH9K_DEBUGFS
  268. spin_lock(&sc->nodes_lock);
  269. list_add(&an->list, &sc->nodes);
  270. spin_unlock(&sc->nodes_lock);
  271. #endif
  272. an->sta = sta;
  273. an->vif = vif;
  274. if (sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_HT) {
  275. ath_tx_node_init(sc, an);
  276. an->maxampdu = 1 << (IEEE80211_HT_MAX_AMPDU_FACTOR +
  277. sta->ht_cap.ampdu_factor);
  278. density = ath9k_parse_mpdudensity(sta->ht_cap.ampdu_density);
  279. an->mpdudensity = density;
  280. }
  281. }
  282. static void ath_node_detach(struct ath_softc *sc, struct ieee80211_sta *sta)
  283. {
  284. struct ath_node *an = (struct ath_node *)sta->drv_priv;
  285. #ifdef CONFIG_ATH9K_DEBUGFS
  286. spin_lock(&sc->nodes_lock);
  287. list_del(&an->list);
  288. spin_unlock(&sc->nodes_lock);
  289. an->sta = NULL;
  290. #endif
  291. if (sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_HT)
  292. ath_tx_node_cleanup(sc, an);
  293. }
  294. void ath9k_tasklet(unsigned long data)
  295. {
  296. struct ath_softc *sc = (struct ath_softc *)data;
  297. struct ath_hw *ah = sc->sc_ah;
  298. struct ath_common *common = ath9k_hw_common(ah);
  299. unsigned long flags;
  300. u32 status = sc->intrstatus;
  301. u32 rxmask;
  302. ath9k_ps_wakeup(sc);
  303. spin_lock(&sc->sc_pcu_lock);
  304. if ((status & ATH9K_INT_FATAL) ||
  305. (status & ATH9K_INT_BB_WATCHDOG)) {
  306. #ifdef CONFIG_ATH9K_DEBUGFS
  307. enum ath_reset_type type;
  308. if (status & ATH9K_INT_FATAL)
  309. type = RESET_TYPE_FATAL_INT;
  310. else
  311. type = RESET_TYPE_BB_WATCHDOG;
  312. RESET_STAT_INC(sc, type);
  313. #endif
  314. set_bit(SC_OP_HW_RESET, &sc->sc_flags);
  315. ieee80211_queue_work(sc->hw, &sc->hw_reset_work);
  316. goto out;
  317. }
  318. spin_lock_irqsave(&sc->sc_pm_lock, flags);
  319. if ((status & ATH9K_INT_TSFOOR) && sc->ps_enabled) {
  320. /*
  321. * TSF sync does not look correct; remain awake to sync with
  322. * the next Beacon.
  323. */
  324. ath_dbg(common, PS, "TSFOOR - Sync with next Beacon\n");
  325. sc->ps_flags |= PS_WAIT_FOR_BEACON | PS_BEACON_SYNC;
  326. }
  327. spin_unlock_irqrestore(&sc->sc_pm_lock, flags);
  328. if (ah->caps.hw_caps & ATH9K_HW_CAP_EDMA)
  329. rxmask = (ATH9K_INT_RXHP | ATH9K_INT_RXLP | ATH9K_INT_RXEOL |
  330. ATH9K_INT_RXORN);
  331. else
  332. rxmask = (ATH9K_INT_RX | ATH9K_INT_RXEOL | ATH9K_INT_RXORN);
  333. if (status & rxmask) {
  334. /* Check for high priority Rx first */
  335. if ((ah->caps.hw_caps & ATH9K_HW_CAP_EDMA) &&
  336. (status & ATH9K_INT_RXHP))
  337. ath_rx_tasklet(sc, 0, true);
  338. ath_rx_tasklet(sc, 0, false);
  339. }
  340. if (status & ATH9K_INT_TX) {
  341. if (ah->caps.hw_caps & ATH9K_HW_CAP_EDMA)
  342. ath_tx_edma_tasklet(sc);
  343. else
  344. ath_tx_tasklet(sc);
  345. }
  346. ath9k_btcoex_handle_interrupt(sc, status);
  347. out:
  348. /* re-enable hardware interrupt */
  349. ath9k_hw_enable_interrupts(ah);
  350. spin_unlock(&sc->sc_pcu_lock);
  351. ath9k_ps_restore(sc);
  352. }
  353. irqreturn_t ath_isr(int irq, void *dev)
  354. {
  355. #define SCHED_INTR ( \
  356. ATH9K_INT_FATAL | \
  357. ATH9K_INT_BB_WATCHDOG | \
  358. ATH9K_INT_RXORN | \
  359. ATH9K_INT_RXEOL | \
  360. ATH9K_INT_RX | \
  361. ATH9K_INT_RXLP | \
  362. ATH9K_INT_RXHP | \
  363. ATH9K_INT_TX | \
  364. ATH9K_INT_BMISS | \
  365. ATH9K_INT_CST | \
  366. ATH9K_INT_TSFOOR | \
  367. ATH9K_INT_GENTIMER | \
  368. ATH9K_INT_MCI)
  369. struct ath_softc *sc = dev;
  370. struct ath_hw *ah = sc->sc_ah;
  371. struct ath_common *common = ath9k_hw_common(ah);
  372. enum ath9k_int status;
  373. bool sched = false;
  374. /*
  375. * The hardware is not ready/present, don't
  376. * touch anything. Note this can happen early
  377. * on if the IRQ is shared.
  378. */
  379. if (test_bit(SC_OP_INVALID, &sc->sc_flags))
  380. return IRQ_NONE;
  381. /* shared irq, not for us */
  382. if (!ath9k_hw_intrpend(ah))
  383. return IRQ_NONE;
  384. if(test_bit(SC_OP_HW_RESET, &sc->sc_flags))
  385. return IRQ_HANDLED;
  386. /*
  387. * Figure out the reason(s) for the interrupt. Note
  388. * that the hal returns a pseudo-ISR that may include
  389. * bits we haven't explicitly enabled so we mask the
  390. * value to insure we only process bits we requested.
  391. */
  392. ath9k_hw_getisr(ah, &status); /* NB: clears ISR too */
  393. status &= ah->imask; /* discard unasked-for bits */
  394. /*
  395. * If there are no status bits set, then this interrupt was not
  396. * for me (should have been caught above).
  397. */
  398. if (!status)
  399. return IRQ_NONE;
  400. /* Cache the status */
  401. sc->intrstatus = status;
  402. if (status & SCHED_INTR)
  403. sched = true;
  404. /*
  405. * If a FATAL or RXORN interrupt is received, we have to reset the
  406. * chip immediately.
  407. */
  408. if ((status & ATH9K_INT_FATAL) || ((status & ATH9K_INT_RXORN) &&
  409. !(ah->caps.hw_caps & ATH9K_HW_CAP_EDMA)))
  410. goto chip_reset;
  411. if ((ah->caps.hw_caps & ATH9K_HW_CAP_EDMA) &&
  412. (status & ATH9K_INT_BB_WATCHDOG)) {
  413. spin_lock(&common->cc_lock);
  414. ath_hw_cycle_counters_update(common);
  415. ar9003_hw_bb_watchdog_dbg_info(ah);
  416. spin_unlock(&common->cc_lock);
  417. goto chip_reset;
  418. }
  419. if (status & ATH9K_INT_SWBA)
  420. tasklet_schedule(&sc->bcon_tasklet);
  421. if (status & ATH9K_INT_TXURN)
  422. ath9k_hw_updatetxtriglevel(ah, true);
  423. if (status & ATH9K_INT_RXEOL) {
  424. ah->imask &= ~(ATH9K_INT_RXEOL | ATH9K_INT_RXORN);
  425. ath9k_hw_set_interrupts(ah);
  426. }
  427. if (!(ah->caps.hw_caps & ATH9K_HW_CAP_AUTOSLEEP))
  428. if (status & ATH9K_INT_TIM_TIMER) {
  429. if (ATH_DBG_WARN_ON_ONCE(sc->ps_idle))
  430. goto chip_reset;
  431. /* Clear RxAbort bit so that we can
  432. * receive frames */
  433. ath9k_setpower(sc, ATH9K_PM_AWAKE);
  434. spin_lock(&sc->sc_pm_lock);
  435. ath9k_hw_setrxabort(sc->sc_ah, 0);
  436. sc->ps_flags |= PS_WAIT_FOR_BEACON;
  437. spin_unlock(&sc->sc_pm_lock);
  438. }
  439. chip_reset:
  440. ath_debug_stat_interrupt(sc, status);
  441. if (sched) {
  442. /* turn off every interrupt */
  443. ath9k_hw_disable_interrupts(ah);
  444. tasklet_schedule(&sc->intr_tq);
  445. }
  446. return IRQ_HANDLED;
  447. #undef SCHED_INTR
  448. }
  449. static int ath_reset(struct ath_softc *sc, bool retry_tx)
  450. {
  451. int r;
  452. ath9k_ps_wakeup(sc);
  453. r = ath_reset_internal(sc, NULL, retry_tx);
  454. if (retry_tx) {
  455. int i;
  456. for (i = 0; i < ATH9K_NUM_TX_QUEUES; i++) {
  457. if (ATH_TXQ_SETUP(sc, i)) {
  458. spin_lock_bh(&sc->tx.txq[i].axq_lock);
  459. ath_txq_schedule(sc, &sc->tx.txq[i]);
  460. spin_unlock_bh(&sc->tx.txq[i].axq_lock);
  461. }
  462. }
  463. }
  464. ath9k_ps_restore(sc);
  465. return r;
  466. }
  467. void ath_reset_work(struct work_struct *work)
  468. {
  469. struct ath_softc *sc = container_of(work, struct ath_softc, hw_reset_work);
  470. ath_reset(sc, true);
  471. }
  472. /**********************/
  473. /* mac80211 callbacks */
  474. /**********************/
  475. static int ath9k_start(struct ieee80211_hw *hw)
  476. {
  477. struct ath_softc *sc = hw->priv;
  478. struct ath_hw *ah = sc->sc_ah;
  479. struct ath_common *common = ath9k_hw_common(ah);
  480. struct ieee80211_channel *curchan = hw->conf.channel;
  481. struct ath9k_channel *init_channel;
  482. int r;
  483. ath_dbg(common, CONFIG,
  484. "Starting driver with initial channel: %d MHz\n",
  485. curchan->center_freq);
  486. ath9k_ps_wakeup(sc);
  487. mutex_lock(&sc->mutex);
  488. init_channel = ath9k_cmn_get_curchannel(hw, ah);
  489. /* Reset SERDES registers */
  490. ath9k_hw_configpcipowersave(ah, false);
  491. /*
  492. * The basic interface to setting the hardware in a good
  493. * state is ``reset''. On return the hardware is known to
  494. * be powered up and with interrupts disabled. This must
  495. * be followed by initialization of the appropriate bits
  496. * and then setup of the interrupt mask.
  497. */
  498. spin_lock_bh(&sc->sc_pcu_lock);
  499. atomic_set(&ah->intr_ref_cnt, -1);
  500. r = ath9k_hw_reset(ah, init_channel, ah->caldata, false);
  501. if (r) {
  502. ath_err(common,
  503. "Unable to reset hardware; reset status %d (freq %u MHz)\n",
  504. r, curchan->center_freq);
  505. spin_unlock_bh(&sc->sc_pcu_lock);
  506. goto mutex_unlock;
  507. }
  508. /* Setup our intr mask. */
  509. ah->imask = ATH9K_INT_TX | ATH9K_INT_RXEOL |
  510. ATH9K_INT_RXORN | ATH9K_INT_FATAL |
  511. ATH9K_INT_GLOBAL;
  512. if (ah->caps.hw_caps & ATH9K_HW_CAP_EDMA)
  513. ah->imask |= ATH9K_INT_RXHP |
  514. ATH9K_INT_RXLP |
  515. ATH9K_INT_BB_WATCHDOG;
  516. else
  517. ah->imask |= ATH9K_INT_RX;
  518. ah->imask |= ATH9K_INT_GTT;
  519. if (ah->caps.hw_caps & ATH9K_HW_CAP_HT)
  520. ah->imask |= ATH9K_INT_CST;
  521. ath_mci_enable(sc);
  522. clear_bit(SC_OP_INVALID, &sc->sc_flags);
  523. sc->sc_ah->is_monitoring = false;
  524. if (!ath_complete_reset(sc, false)) {
  525. r = -EIO;
  526. spin_unlock_bh(&sc->sc_pcu_lock);
  527. goto mutex_unlock;
  528. }
  529. if (ah->led_pin >= 0) {
  530. ath9k_hw_cfg_output(ah, ah->led_pin,
  531. AR_GPIO_OUTPUT_MUX_AS_OUTPUT);
  532. ath9k_hw_set_gpio(ah, ah->led_pin, 0);
  533. }
  534. /*
  535. * Reset key cache to sane defaults (all entries cleared) instead of
  536. * semi-random values after suspend/resume.
  537. */
  538. ath9k_cmn_init_crypto(sc->sc_ah);
  539. spin_unlock_bh(&sc->sc_pcu_lock);
  540. if (ah->caps.pcie_lcr_extsync_en && common->bus_ops->extn_synch_en)
  541. common->bus_ops->extn_synch_en(common);
  542. mutex_unlock:
  543. mutex_unlock(&sc->mutex);
  544. ath9k_ps_restore(sc);
  545. return r;
  546. }
  547. static void ath9k_tx(struct ieee80211_hw *hw, struct sk_buff *skb)
  548. {
  549. struct ath_softc *sc = hw->priv;
  550. struct ath_common *common = ath9k_hw_common(sc->sc_ah);
  551. struct ath_tx_control txctl;
  552. struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
  553. unsigned long flags;
  554. if (sc->ps_enabled) {
  555. /*
  556. * mac80211 does not set PM field for normal data frames, so we
  557. * need to update that based on the current PS mode.
  558. */
  559. if (ieee80211_is_data(hdr->frame_control) &&
  560. !ieee80211_is_nullfunc(hdr->frame_control) &&
  561. !ieee80211_has_pm(hdr->frame_control)) {
  562. ath_dbg(common, PS,
  563. "Add PM=1 for a TX frame while in PS mode\n");
  564. hdr->frame_control |= cpu_to_le16(IEEE80211_FCTL_PM);
  565. }
  566. }
  567. if (unlikely(sc->sc_ah->power_mode == ATH9K_PM_NETWORK_SLEEP)) {
  568. /*
  569. * We are using PS-Poll and mac80211 can request TX while in
  570. * power save mode. Need to wake up hardware for the TX to be
  571. * completed and if needed, also for RX of buffered frames.
  572. */
  573. ath9k_ps_wakeup(sc);
  574. spin_lock_irqsave(&sc->sc_pm_lock, flags);
  575. if (!(sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_AUTOSLEEP))
  576. ath9k_hw_setrxabort(sc->sc_ah, 0);
  577. if (ieee80211_is_pspoll(hdr->frame_control)) {
  578. ath_dbg(common, PS,
  579. "Sending PS-Poll to pick a buffered frame\n");
  580. sc->ps_flags |= PS_WAIT_FOR_PSPOLL_DATA;
  581. } else {
  582. ath_dbg(common, PS, "Wake up to complete TX\n");
  583. sc->ps_flags |= PS_WAIT_FOR_TX_ACK;
  584. }
  585. /*
  586. * The actual restore operation will happen only after
  587. * the ps_flags bit is cleared. We are just dropping
  588. * the ps_usecount here.
  589. */
  590. spin_unlock_irqrestore(&sc->sc_pm_lock, flags);
  591. ath9k_ps_restore(sc);
  592. }
  593. /*
  594. * Cannot tx while the hardware is in full sleep, it first needs a full
  595. * chip reset to recover from that
  596. */
  597. if (unlikely(sc->sc_ah->power_mode == ATH9K_PM_FULL_SLEEP)) {
  598. ath_err(common, "TX while HW is in FULL_SLEEP mode\n");
  599. goto exit;
  600. }
  601. memset(&txctl, 0, sizeof(struct ath_tx_control));
  602. txctl.txq = sc->tx.txq_map[skb_get_queue_mapping(skb)];
  603. ath_dbg(common, XMIT, "transmitting packet, skb: %p\n", skb);
  604. if (ath_tx_start(hw, skb, &txctl) != 0) {
  605. ath_dbg(common, XMIT, "TX failed\n");
  606. TX_STAT_INC(txctl.txq->axq_qnum, txfailed);
  607. goto exit;
  608. }
  609. return;
  610. exit:
  611. dev_kfree_skb_any(skb);
  612. }
  613. static void ath9k_stop(struct ieee80211_hw *hw)
  614. {
  615. struct ath_softc *sc = hw->priv;
  616. struct ath_hw *ah = sc->sc_ah;
  617. struct ath_common *common = ath9k_hw_common(ah);
  618. bool prev_idle;
  619. mutex_lock(&sc->mutex);
  620. ath_cancel_work(sc);
  621. del_timer_sync(&sc->rx_poll_timer);
  622. if (test_bit(SC_OP_INVALID, &sc->sc_flags)) {
  623. ath_dbg(common, ANY, "Device not present\n");
  624. mutex_unlock(&sc->mutex);
  625. return;
  626. }
  627. /* Ensure HW is awake when we try to shut it down. */
  628. ath9k_ps_wakeup(sc);
  629. spin_lock_bh(&sc->sc_pcu_lock);
  630. /* prevent tasklets to enable interrupts once we disable them */
  631. ah->imask &= ~ATH9K_INT_GLOBAL;
  632. /* make sure h/w will not generate any interrupt
  633. * before setting the invalid flag. */
  634. ath9k_hw_disable_interrupts(ah);
  635. spin_unlock_bh(&sc->sc_pcu_lock);
  636. /* we can now sync irq and kill any running tasklets, since we already
  637. * disabled interrupts and not holding a spin lock */
  638. synchronize_irq(sc->irq);
  639. tasklet_kill(&sc->intr_tq);
  640. tasklet_kill(&sc->bcon_tasklet);
  641. prev_idle = sc->ps_idle;
  642. sc->ps_idle = true;
  643. spin_lock_bh(&sc->sc_pcu_lock);
  644. if (ah->led_pin >= 0) {
  645. ath9k_hw_set_gpio(ah, ah->led_pin, 1);
  646. ath9k_hw_cfg_gpio_input(ah, ah->led_pin);
  647. }
  648. ath_prepare_reset(sc, false, true);
  649. if (sc->rx.frag) {
  650. dev_kfree_skb_any(sc->rx.frag);
  651. sc->rx.frag = NULL;
  652. }
  653. if (!ah->curchan)
  654. ah->curchan = ath9k_cmn_get_curchannel(hw, ah);
  655. ath9k_hw_reset(ah, ah->curchan, ah->caldata, false);
  656. ath9k_hw_phy_disable(ah);
  657. ath9k_hw_configpcipowersave(ah, true);
  658. spin_unlock_bh(&sc->sc_pcu_lock);
  659. ath9k_ps_restore(sc);
  660. set_bit(SC_OP_INVALID, &sc->sc_flags);
  661. sc->ps_idle = prev_idle;
  662. mutex_unlock(&sc->mutex);
  663. ath_dbg(common, CONFIG, "Driver halt\n");
  664. }
  665. bool ath9k_uses_beacons(int type)
  666. {
  667. switch (type) {
  668. case NL80211_IFTYPE_AP:
  669. case NL80211_IFTYPE_ADHOC:
  670. case NL80211_IFTYPE_MESH_POINT:
  671. return true;
  672. default:
  673. return false;
  674. }
  675. }
  676. static void ath9k_reclaim_beacon(struct ath_softc *sc,
  677. struct ieee80211_vif *vif)
  678. {
  679. struct ath_vif *avp = (void *)vif->drv_priv;
  680. ath9k_set_beaconing_status(sc, false);
  681. ath_beacon_return(sc, avp);
  682. ath9k_set_beaconing_status(sc, true);
  683. }
  684. static void ath9k_vif_iter(void *data, u8 *mac, struct ieee80211_vif *vif)
  685. {
  686. struct ath9k_vif_iter_data *iter_data = data;
  687. int i;
  688. if (iter_data->hw_macaddr)
  689. for (i = 0; i < ETH_ALEN; i++)
  690. iter_data->mask[i] &=
  691. ~(iter_data->hw_macaddr[i] ^ mac[i]);
  692. switch (vif->type) {
  693. case NL80211_IFTYPE_AP:
  694. iter_data->naps++;
  695. break;
  696. case NL80211_IFTYPE_STATION:
  697. iter_data->nstations++;
  698. break;
  699. case NL80211_IFTYPE_ADHOC:
  700. iter_data->nadhocs++;
  701. break;
  702. case NL80211_IFTYPE_MESH_POINT:
  703. iter_data->nmeshes++;
  704. break;
  705. case NL80211_IFTYPE_WDS:
  706. iter_data->nwds++;
  707. break;
  708. default:
  709. break;
  710. }
  711. }
  712. /* Called with sc->mutex held. */
  713. void ath9k_calculate_iter_data(struct ieee80211_hw *hw,
  714. struct ieee80211_vif *vif,
  715. struct ath9k_vif_iter_data *iter_data)
  716. {
  717. struct ath_softc *sc = hw->priv;
  718. struct ath_hw *ah = sc->sc_ah;
  719. struct ath_common *common = ath9k_hw_common(ah);
  720. /*
  721. * Use the hardware MAC address as reference, the hardware uses it
  722. * together with the BSSID mask when matching addresses.
  723. */
  724. memset(iter_data, 0, sizeof(*iter_data));
  725. iter_data->hw_macaddr = common->macaddr;
  726. memset(&iter_data->mask, 0xff, ETH_ALEN);
  727. if (vif)
  728. ath9k_vif_iter(iter_data, vif->addr, vif);
  729. /* Get list of all active MAC addresses */
  730. ieee80211_iterate_active_interfaces_atomic(sc->hw, ath9k_vif_iter,
  731. iter_data);
  732. }
  733. /* Called with sc->mutex held. */
  734. static void ath9k_calculate_summary_state(struct ieee80211_hw *hw,
  735. struct ieee80211_vif *vif)
  736. {
  737. struct ath_softc *sc = hw->priv;
  738. struct ath_hw *ah = sc->sc_ah;
  739. struct ath_common *common = ath9k_hw_common(ah);
  740. struct ath9k_vif_iter_data iter_data;
  741. ath9k_calculate_iter_data(hw, vif, &iter_data);
  742. /* Set BSSID mask. */
  743. memcpy(common->bssidmask, iter_data.mask, ETH_ALEN);
  744. ath_hw_setbssidmask(common);
  745. /* Set op-mode & TSF */
  746. if (iter_data.naps > 0) {
  747. ath9k_hw_set_tsfadjust(ah, 1);
  748. set_bit(SC_OP_TSF_RESET, &sc->sc_flags);
  749. ah->opmode = NL80211_IFTYPE_AP;
  750. } else {
  751. ath9k_hw_set_tsfadjust(ah, 0);
  752. clear_bit(SC_OP_TSF_RESET, &sc->sc_flags);
  753. if (iter_data.nmeshes)
  754. ah->opmode = NL80211_IFTYPE_MESH_POINT;
  755. else if (iter_data.nwds)
  756. ah->opmode = NL80211_IFTYPE_AP;
  757. else if (iter_data.nadhocs)
  758. ah->opmode = NL80211_IFTYPE_ADHOC;
  759. else
  760. ah->opmode = NL80211_IFTYPE_STATION;
  761. }
  762. /*
  763. * Enable MIB interrupts when there are hardware phy counters.
  764. */
  765. if ((iter_data.nstations + iter_data.nadhocs + iter_data.nmeshes) > 0)
  766. ah->imask |= ATH9K_INT_TSFOOR;
  767. else
  768. ah->imask &= ~ATH9K_INT_TSFOOR;
  769. ath9k_hw_set_interrupts(ah);
  770. /* Set up ANI */
  771. if (iter_data.naps > 0) {
  772. sc->sc_ah->stats.avgbrssi = ATH_RSSI_DUMMY_MARKER;
  773. if (!common->disable_ani) {
  774. set_bit(SC_OP_ANI_RUN, &sc->sc_flags);
  775. ath_start_ani(common);
  776. }
  777. } else {
  778. clear_bit(SC_OP_ANI_RUN, &sc->sc_flags);
  779. del_timer_sync(&common->ani.timer);
  780. }
  781. }
  782. /* Called with sc->mutex held, vif counts set up properly. */
  783. static void ath9k_do_vif_add_setup(struct ieee80211_hw *hw,
  784. struct ieee80211_vif *vif)
  785. {
  786. struct ath_softc *sc = hw->priv;
  787. ath9k_calculate_summary_state(hw, vif);
  788. if (ath9k_uses_beacons(vif->type)) {
  789. /* Reserve a beacon slot for the vif */
  790. ath9k_set_beaconing_status(sc, false);
  791. ath_beacon_alloc(sc, vif);
  792. ath9k_set_beaconing_status(sc, true);
  793. }
  794. }
  795. static int ath9k_add_interface(struct ieee80211_hw *hw,
  796. struct ieee80211_vif *vif)
  797. {
  798. struct ath_softc *sc = hw->priv;
  799. struct ath_hw *ah = sc->sc_ah;
  800. struct ath_common *common = ath9k_hw_common(ah);
  801. int ret = 0;
  802. ath9k_ps_wakeup(sc);
  803. mutex_lock(&sc->mutex);
  804. switch (vif->type) {
  805. case NL80211_IFTYPE_STATION:
  806. case NL80211_IFTYPE_WDS:
  807. case NL80211_IFTYPE_ADHOC:
  808. case NL80211_IFTYPE_AP:
  809. case NL80211_IFTYPE_MESH_POINT:
  810. break;
  811. default:
  812. ath_err(common, "Interface type %d not yet supported\n",
  813. vif->type);
  814. ret = -EOPNOTSUPP;
  815. goto out;
  816. }
  817. if (ath9k_uses_beacons(vif->type)) {
  818. if (sc->nbcnvifs >= ATH_BCBUF) {
  819. ath_err(common, "Not enough beacon buffers when adding"
  820. " new interface of type: %i\n",
  821. vif->type);
  822. ret = -ENOBUFS;
  823. goto out;
  824. }
  825. }
  826. ath_dbg(common, CONFIG, "Attach a VIF of type: %d\n", vif->type);
  827. sc->nvifs++;
  828. ath9k_do_vif_add_setup(hw, vif);
  829. out:
  830. mutex_unlock(&sc->mutex);
  831. ath9k_ps_restore(sc);
  832. return ret;
  833. }
  834. static int ath9k_change_interface(struct ieee80211_hw *hw,
  835. struct ieee80211_vif *vif,
  836. enum nl80211_iftype new_type,
  837. bool p2p)
  838. {
  839. struct ath_softc *sc = hw->priv;
  840. struct ath_common *common = ath9k_hw_common(sc->sc_ah);
  841. int ret = 0;
  842. ath_dbg(common, CONFIG, "Change Interface\n");
  843. mutex_lock(&sc->mutex);
  844. ath9k_ps_wakeup(sc);
  845. if (ath9k_uses_beacons(new_type) &&
  846. !ath9k_uses_beacons(vif->type)) {
  847. if (sc->nbcnvifs >= ATH_BCBUF) {
  848. ath_err(common, "No beacon slot available\n");
  849. ret = -ENOBUFS;
  850. goto out;
  851. }
  852. }
  853. /* Clean up old vif stuff */
  854. if (ath9k_uses_beacons(vif->type))
  855. ath9k_reclaim_beacon(sc, vif);
  856. /* Add new settings */
  857. vif->type = new_type;
  858. vif->p2p = p2p;
  859. ath9k_do_vif_add_setup(hw, vif);
  860. out:
  861. ath9k_ps_restore(sc);
  862. mutex_unlock(&sc->mutex);
  863. return ret;
  864. }
  865. static void ath9k_remove_interface(struct ieee80211_hw *hw,
  866. struct ieee80211_vif *vif)
  867. {
  868. struct ath_softc *sc = hw->priv;
  869. struct ath_common *common = ath9k_hw_common(sc->sc_ah);
  870. ath_dbg(common, CONFIG, "Detach Interface\n");
  871. ath9k_ps_wakeup(sc);
  872. mutex_lock(&sc->mutex);
  873. sc->nvifs--;
  874. /* Reclaim beacon resources */
  875. if (ath9k_uses_beacons(vif->type))
  876. ath9k_reclaim_beacon(sc, vif);
  877. ath9k_calculate_summary_state(hw, NULL);
  878. mutex_unlock(&sc->mutex);
  879. ath9k_ps_restore(sc);
  880. }
  881. static void ath9k_enable_ps(struct ath_softc *sc)
  882. {
  883. struct ath_hw *ah = sc->sc_ah;
  884. struct ath_common *common = ath9k_hw_common(ah);
  885. sc->ps_enabled = true;
  886. if (!(ah->caps.hw_caps & ATH9K_HW_CAP_AUTOSLEEP)) {
  887. if ((ah->imask & ATH9K_INT_TIM_TIMER) == 0) {
  888. ah->imask |= ATH9K_INT_TIM_TIMER;
  889. ath9k_hw_set_interrupts(ah);
  890. }
  891. ath9k_hw_setrxabort(ah, 1);
  892. }
  893. ath_dbg(common, PS, "PowerSave enabled\n");
  894. }
  895. static void ath9k_disable_ps(struct ath_softc *sc)
  896. {
  897. struct ath_hw *ah = sc->sc_ah;
  898. struct ath_common *common = ath9k_hw_common(ah);
  899. sc->ps_enabled = false;
  900. ath9k_hw_setpower(ah, ATH9K_PM_AWAKE);
  901. if (!(ah->caps.hw_caps & ATH9K_HW_CAP_AUTOSLEEP)) {
  902. ath9k_hw_setrxabort(ah, 0);
  903. sc->ps_flags &= ~(PS_WAIT_FOR_BEACON |
  904. PS_WAIT_FOR_CAB |
  905. PS_WAIT_FOR_PSPOLL_DATA |
  906. PS_WAIT_FOR_TX_ACK);
  907. if (ah->imask & ATH9K_INT_TIM_TIMER) {
  908. ah->imask &= ~ATH9K_INT_TIM_TIMER;
  909. ath9k_hw_set_interrupts(ah);
  910. }
  911. }
  912. ath_dbg(common, PS, "PowerSave disabled\n");
  913. }
  914. static int ath9k_config(struct ieee80211_hw *hw, u32 changed)
  915. {
  916. struct ath_softc *sc = hw->priv;
  917. struct ath_hw *ah = sc->sc_ah;
  918. struct ath_common *common = ath9k_hw_common(ah);
  919. struct ieee80211_conf *conf = &hw->conf;
  920. bool reset_channel = false;
  921. ath9k_ps_wakeup(sc);
  922. mutex_lock(&sc->mutex);
  923. if (changed & IEEE80211_CONF_CHANGE_IDLE) {
  924. sc->ps_idle = !!(conf->flags & IEEE80211_CONF_IDLE);
  925. if (sc->ps_idle) {
  926. ath_cancel_work(sc);
  927. ath9k_stop_btcoex(sc);
  928. } else {
  929. ath9k_start_btcoex(sc);
  930. /*
  931. * The chip needs a reset to properly wake up from
  932. * full sleep
  933. */
  934. reset_channel = ah->chip_fullsleep;
  935. }
  936. }
  937. /*
  938. * We just prepare to enable PS. We have to wait until our AP has
  939. * ACK'd our null data frame to disable RX otherwise we'll ignore
  940. * those ACKs and end up retransmitting the same null data frames.
  941. * IEEE80211_CONF_CHANGE_PS is only passed by mac80211 for STA mode.
  942. */
  943. if (changed & IEEE80211_CONF_CHANGE_PS) {
  944. unsigned long flags;
  945. spin_lock_irqsave(&sc->sc_pm_lock, flags);
  946. if (conf->flags & IEEE80211_CONF_PS)
  947. ath9k_enable_ps(sc);
  948. else
  949. ath9k_disable_ps(sc);
  950. spin_unlock_irqrestore(&sc->sc_pm_lock, flags);
  951. }
  952. if (changed & IEEE80211_CONF_CHANGE_MONITOR) {
  953. if (conf->flags & IEEE80211_CONF_MONITOR) {
  954. ath_dbg(common, CONFIG, "Monitor mode is enabled\n");
  955. sc->sc_ah->is_monitoring = true;
  956. } else {
  957. ath_dbg(common, CONFIG, "Monitor mode is disabled\n");
  958. sc->sc_ah->is_monitoring = false;
  959. }
  960. }
  961. if ((changed & IEEE80211_CONF_CHANGE_CHANNEL) || reset_channel) {
  962. struct ieee80211_channel *curchan = hw->conf.channel;
  963. int pos = curchan->hw_value;
  964. int old_pos = -1;
  965. unsigned long flags;
  966. if (ah->curchan)
  967. old_pos = ah->curchan - &ah->channels[0];
  968. ath_dbg(common, CONFIG, "Set channel: %d MHz type: %d\n",
  969. curchan->center_freq, conf->channel_type);
  970. /* update survey stats for the old channel before switching */
  971. spin_lock_irqsave(&common->cc_lock, flags);
  972. ath_update_survey_stats(sc);
  973. spin_unlock_irqrestore(&common->cc_lock, flags);
  974. /*
  975. * Preserve the current channel values, before updating
  976. * the same channel
  977. */
  978. if (ah->curchan && (old_pos == pos))
  979. ath9k_hw_getnf(ah, ah->curchan);
  980. ath9k_cmn_update_ichannel(&sc->sc_ah->channels[pos],
  981. curchan, conf->channel_type);
  982. /*
  983. * If the operating channel changes, change the survey in-use flags
  984. * along with it.
  985. * Reset the survey data for the new channel, unless we're switching
  986. * back to the operating channel from an off-channel operation.
  987. */
  988. if (!(hw->conf.flags & IEEE80211_CONF_OFFCHANNEL) &&
  989. sc->cur_survey != &sc->survey[pos]) {
  990. if (sc->cur_survey)
  991. sc->cur_survey->filled &= ~SURVEY_INFO_IN_USE;
  992. sc->cur_survey = &sc->survey[pos];
  993. memset(sc->cur_survey, 0, sizeof(struct survey_info));
  994. sc->cur_survey->filled |= SURVEY_INFO_IN_USE;
  995. } else if (!(sc->survey[pos].filled & SURVEY_INFO_IN_USE)) {
  996. memset(&sc->survey[pos], 0, sizeof(struct survey_info));
  997. }
  998. if (ath_set_channel(sc, hw, &sc->sc_ah->channels[pos]) < 0) {
  999. ath_err(common, "Unable to set channel\n");
  1000. mutex_unlock(&sc->mutex);
  1001. ath9k_ps_restore(sc);
  1002. return -EINVAL;
  1003. }
  1004. /*
  1005. * The most recent snapshot of channel->noisefloor for the old
  1006. * channel is only available after the hardware reset. Copy it to
  1007. * the survey stats now.
  1008. */
  1009. if (old_pos >= 0)
  1010. ath_update_survey_nf(sc, old_pos);
  1011. }
  1012. if (changed & IEEE80211_CONF_CHANGE_POWER) {
  1013. ath_dbg(common, CONFIG, "Set power: %d\n", conf->power_level);
  1014. sc->config.txpowlimit = 2 * conf->power_level;
  1015. ath9k_cmn_update_txpow(ah, sc->curtxpow,
  1016. sc->config.txpowlimit, &sc->curtxpow);
  1017. }
  1018. mutex_unlock(&sc->mutex);
  1019. ath9k_ps_restore(sc);
  1020. return 0;
  1021. }
  1022. #define SUPPORTED_FILTERS \
  1023. (FIF_PROMISC_IN_BSS | \
  1024. FIF_ALLMULTI | \
  1025. FIF_CONTROL | \
  1026. FIF_PSPOLL | \
  1027. FIF_OTHER_BSS | \
  1028. FIF_BCN_PRBRESP_PROMISC | \
  1029. FIF_PROBE_REQ | \
  1030. FIF_FCSFAIL)
  1031. /* FIXME: sc->sc_full_reset ? */
  1032. static void ath9k_configure_filter(struct ieee80211_hw *hw,
  1033. unsigned int changed_flags,
  1034. unsigned int *total_flags,
  1035. u64 multicast)
  1036. {
  1037. struct ath_softc *sc = hw->priv;
  1038. u32 rfilt;
  1039. changed_flags &= SUPPORTED_FILTERS;
  1040. *total_flags &= SUPPORTED_FILTERS;
  1041. sc->rx.rxfilter = *total_flags;
  1042. ath9k_ps_wakeup(sc);
  1043. rfilt = ath_calcrxfilter(sc);
  1044. ath9k_hw_setrxfilter(sc->sc_ah, rfilt);
  1045. ath9k_ps_restore(sc);
  1046. ath_dbg(ath9k_hw_common(sc->sc_ah), CONFIG, "Set HW RX filter: 0x%x\n",
  1047. rfilt);
  1048. }
  1049. static int ath9k_sta_add(struct ieee80211_hw *hw,
  1050. struct ieee80211_vif *vif,
  1051. struct ieee80211_sta *sta)
  1052. {
  1053. struct ath_softc *sc = hw->priv;
  1054. struct ath_common *common = ath9k_hw_common(sc->sc_ah);
  1055. struct ath_node *an = (struct ath_node *) sta->drv_priv;
  1056. struct ieee80211_key_conf ps_key = { };
  1057. ath_node_attach(sc, sta, vif);
  1058. if (vif->type != NL80211_IFTYPE_AP &&
  1059. vif->type != NL80211_IFTYPE_AP_VLAN)
  1060. return 0;
  1061. an->ps_key = ath_key_config(common, vif, sta, &ps_key);
  1062. return 0;
  1063. }
  1064. static void ath9k_del_ps_key(struct ath_softc *sc,
  1065. struct ieee80211_vif *vif,
  1066. struct ieee80211_sta *sta)
  1067. {
  1068. struct ath_common *common = ath9k_hw_common(sc->sc_ah);
  1069. struct ath_node *an = (struct ath_node *) sta->drv_priv;
  1070. struct ieee80211_key_conf ps_key = { .hw_key_idx = an->ps_key };
  1071. if (!an->ps_key)
  1072. return;
  1073. ath_key_delete(common, &ps_key);
  1074. }
  1075. static int ath9k_sta_remove(struct ieee80211_hw *hw,
  1076. struct ieee80211_vif *vif,
  1077. struct ieee80211_sta *sta)
  1078. {
  1079. struct ath_softc *sc = hw->priv;
  1080. ath9k_del_ps_key(sc, vif, sta);
  1081. ath_node_detach(sc, sta);
  1082. return 0;
  1083. }
  1084. static void ath9k_sta_notify(struct ieee80211_hw *hw,
  1085. struct ieee80211_vif *vif,
  1086. enum sta_notify_cmd cmd,
  1087. struct ieee80211_sta *sta)
  1088. {
  1089. struct ath_softc *sc = hw->priv;
  1090. struct ath_node *an = (struct ath_node *) sta->drv_priv;
  1091. if (!sta->ht_cap.ht_supported)
  1092. return;
  1093. switch (cmd) {
  1094. case STA_NOTIFY_SLEEP:
  1095. an->sleeping = true;
  1096. ath_tx_aggr_sleep(sta, sc, an);
  1097. break;
  1098. case STA_NOTIFY_AWAKE:
  1099. an->sleeping = false;
  1100. ath_tx_aggr_wakeup(sc, an);
  1101. break;
  1102. }
  1103. }
  1104. static int ath9k_conf_tx(struct ieee80211_hw *hw,
  1105. struct ieee80211_vif *vif, u16 queue,
  1106. const struct ieee80211_tx_queue_params *params)
  1107. {
  1108. struct ath_softc *sc = hw->priv;
  1109. struct ath_common *common = ath9k_hw_common(sc->sc_ah);
  1110. struct ath_txq *txq;
  1111. struct ath9k_tx_queue_info qi;
  1112. int ret = 0;
  1113. if (queue >= WME_NUM_AC)
  1114. return 0;
  1115. txq = sc->tx.txq_map[queue];
  1116. ath9k_ps_wakeup(sc);
  1117. mutex_lock(&sc->mutex);
  1118. memset(&qi, 0, sizeof(struct ath9k_tx_queue_info));
  1119. qi.tqi_aifs = params->aifs;
  1120. qi.tqi_cwmin = params->cw_min;
  1121. qi.tqi_cwmax = params->cw_max;
  1122. qi.tqi_burstTime = params->txop;
  1123. ath_dbg(common, CONFIG,
  1124. "Configure tx [queue/halq] [%d/%d], aifs: %d, cw_min: %d, cw_max: %d, txop: %d\n",
  1125. queue, txq->axq_qnum, params->aifs, params->cw_min,
  1126. params->cw_max, params->txop);
  1127. ret = ath_txq_update(sc, txq->axq_qnum, &qi);
  1128. if (ret)
  1129. ath_err(common, "TXQ Update failed\n");
  1130. if (sc->sc_ah->opmode == NL80211_IFTYPE_ADHOC)
  1131. if (queue == WME_AC_BE && !ret)
  1132. ath_beaconq_config(sc);
  1133. mutex_unlock(&sc->mutex);
  1134. ath9k_ps_restore(sc);
  1135. return ret;
  1136. }
  1137. static int ath9k_set_key(struct ieee80211_hw *hw,
  1138. enum set_key_cmd cmd,
  1139. struct ieee80211_vif *vif,
  1140. struct ieee80211_sta *sta,
  1141. struct ieee80211_key_conf *key)
  1142. {
  1143. struct ath_softc *sc = hw->priv;
  1144. struct ath_common *common = ath9k_hw_common(sc->sc_ah);
  1145. int ret = 0;
  1146. if (ath9k_modparam_nohwcrypt)
  1147. return -ENOSPC;
  1148. if ((vif->type == NL80211_IFTYPE_ADHOC ||
  1149. vif->type == NL80211_IFTYPE_MESH_POINT) &&
  1150. (key->cipher == WLAN_CIPHER_SUITE_TKIP ||
  1151. key->cipher == WLAN_CIPHER_SUITE_CCMP) &&
  1152. !(key->flags & IEEE80211_KEY_FLAG_PAIRWISE)) {
  1153. /*
  1154. * For now, disable hw crypto for the RSN IBSS group keys. This
  1155. * could be optimized in the future to use a modified key cache
  1156. * design to support per-STA RX GTK, but until that gets
  1157. * implemented, use of software crypto for group addressed
  1158. * frames is a acceptable to allow RSN IBSS to be used.
  1159. */
  1160. return -EOPNOTSUPP;
  1161. }
  1162. mutex_lock(&sc->mutex);
  1163. ath9k_ps_wakeup(sc);
  1164. ath_dbg(common, CONFIG, "Set HW Key\n");
  1165. switch (cmd) {
  1166. case SET_KEY:
  1167. if (sta)
  1168. ath9k_del_ps_key(sc, vif, sta);
  1169. ret = ath_key_config(common, vif, sta, key);
  1170. if (ret >= 0) {
  1171. key->hw_key_idx = ret;
  1172. /* push IV and Michael MIC generation to stack */
  1173. key->flags |= IEEE80211_KEY_FLAG_GENERATE_IV;
  1174. if (key->cipher == WLAN_CIPHER_SUITE_TKIP)
  1175. key->flags |= IEEE80211_KEY_FLAG_GENERATE_MMIC;
  1176. if (sc->sc_ah->sw_mgmt_crypto &&
  1177. key->cipher == WLAN_CIPHER_SUITE_CCMP)
  1178. key->flags |= IEEE80211_KEY_FLAG_SW_MGMT;
  1179. ret = 0;
  1180. }
  1181. break;
  1182. case DISABLE_KEY:
  1183. ath_key_delete(common, key);
  1184. break;
  1185. default:
  1186. ret = -EINVAL;
  1187. }
  1188. ath9k_ps_restore(sc);
  1189. mutex_unlock(&sc->mutex);
  1190. return ret;
  1191. }
  1192. static void ath9k_bss_iter(void *data, u8 *mac, struct ieee80211_vif *vif)
  1193. {
  1194. struct ath_softc *sc = data;
  1195. struct ath_common *common = ath9k_hw_common(sc->sc_ah);
  1196. struct ieee80211_bss_conf *bss_conf = &vif->bss_conf;
  1197. struct ath_vif *avp = (void *)vif->drv_priv;
  1198. unsigned long flags;
  1199. /*
  1200. * Skip iteration if primary station vif's bss info
  1201. * was not changed
  1202. */
  1203. if (test_bit(SC_OP_PRIM_STA_VIF, &sc->sc_flags))
  1204. return;
  1205. if (bss_conf->assoc) {
  1206. set_bit(SC_OP_PRIM_STA_VIF, &sc->sc_flags);
  1207. avp->primary_sta_vif = true;
  1208. memcpy(common->curbssid, bss_conf->bssid, ETH_ALEN);
  1209. common->curaid = bss_conf->aid;
  1210. ath9k_hw_write_associd(sc->sc_ah);
  1211. ath_dbg(common, CONFIG, "Bss Info ASSOC %d, bssid: %pM\n",
  1212. bss_conf->aid, common->curbssid);
  1213. ath_beacon_config(sc, vif);
  1214. /*
  1215. * Request a re-configuration of Beacon related timers
  1216. * on the receipt of the first Beacon frame (i.e.,
  1217. * after time sync with the AP).
  1218. */
  1219. spin_lock_irqsave(&sc->sc_pm_lock, flags);
  1220. sc->ps_flags |= PS_BEACON_SYNC | PS_WAIT_FOR_BEACON;
  1221. spin_unlock_irqrestore(&sc->sc_pm_lock, flags);
  1222. /* Reset rssi stats */
  1223. sc->last_rssi = ATH_RSSI_DUMMY_MARKER;
  1224. sc->sc_ah->stats.avgbrssi = ATH_RSSI_DUMMY_MARKER;
  1225. ath_start_rx_poll(sc, 3);
  1226. if (!common->disable_ani) {
  1227. set_bit(SC_OP_ANI_RUN, &sc->sc_flags);
  1228. ath_start_ani(common);
  1229. }
  1230. }
  1231. }
  1232. static void ath9k_config_bss(struct ath_softc *sc, struct ieee80211_vif *vif)
  1233. {
  1234. struct ath_common *common = ath9k_hw_common(sc->sc_ah);
  1235. struct ieee80211_bss_conf *bss_conf = &vif->bss_conf;
  1236. struct ath_vif *avp = (void *)vif->drv_priv;
  1237. if (sc->sc_ah->opmode != NL80211_IFTYPE_STATION)
  1238. return;
  1239. /* Reconfigure bss info */
  1240. if (avp->primary_sta_vif && !bss_conf->assoc) {
  1241. ath_dbg(common, CONFIG, "Bss Info DISASSOC %d, bssid %pM\n",
  1242. common->curaid, common->curbssid);
  1243. clear_bit(SC_OP_PRIM_STA_VIF, &sc->sc_flags);
  1244. clear_bit(SC_OP_BEACONS, &sc->sc_flags);
  1245. avp->primary_sta_vif = false;
  1246. memset(common->curbssid, 0, ETH_ALEN);
  1247. common->curaid = 0;
  1248. }
  1249. ieee80211_iterate_active_interfaces_atomic(
  1250. sc->hw, ath9k_bss_iter, sc);
  1251. /*
  1252. * None of station vifs are associated.
  1253. * Clear bssid & aid
  1254. */
  1255. if (!test_bit(SC_OP_PRIM_STA_VIF, &sc->sc_flags)) {
  1256. ath9k_hw_write_associd(sc->sc_ah);
  1257. clear_bit(SC_OP_ANI_RUN, &sc->sc_flags);
  1258. del_timer_sync(&common->ani.timer);
  1259. del_timer_sync(&sc->rx_poll_timer);
  1260. memset(&sc->caldata, 0, sizeof(sc->caldata));
  1261. }
  1262. }
  1263. static void ath9k_bss_info_changed(struct ieee80211_hw *hw,
  1264. struct ieee80211_vif *vif,
  1265. struct ieee80211_bss_conf *bss_conf,
  1266. u32 changed)
  1267. {
  1268. struct ath_softc *sc = hw->priv;
  1269. struct ath_hw *ah = sc->sc_ah;
  1270. struct ath_common *common = ath9k_hw_common(ah);
  1271. struct ath_vif *avp = (void *)vif->drv_priv;
  1272. int slottime;
  1273. ath9k_ps_wakeup(sc);
  1274. mutex_lock(&sc->mutex);
  1275. if (changed & BSS_CHANGED_ASSOC) {
  1276. ath9k_config_bss(sc, vif);
  1277. ath_dbg(common, CONFIG, "BSSID: %pM aid: 0x%x\n",
  1278. common->curbssid, common->curaid);
  1279. }
  1280. if (changed & BSS_CHANGED_IBSS) {
  1281. /* There can be only one vif available */
  1282. memcpy(common->curbssid, bss_conf->bssid, ETH_ALEN);
  1283. common->curaid = bss_conf->aid;
  1284. ath9k_hw_write_associd(sc->sc_ah);
  1285. if (bss_conf->ibss_joined) {
  1286. sc->sc_ah->stats.avgbrssi = ATH_RSSI_DUMMY_MARKER;
  1287. if (!common->disable_ani) {
  1288. set_bit(SC_OP_ANI_RUN, &sc->sc_flags);
  1289. ath_start_ani(common);
  1290. }
  1291. } else {
  1292. clear_bit(SC_OP_ANI_RUN, &sc->sc_flags);
  1293. del_timer_sync(&common->ani.timer);
  1294. del_timer_sync(&sc->rx_poll_timer);
  1295. }
  1296. }
  1297. /*
  1298. * In case of AP mode, the HW TSF has to be reset
  1299. * when the beacon interval changes.
  1300. */
  1301. if ((changed & BSS_CHANGED_BEACON_INT) &&
  1302. (vif->type == NL80211_IFTYPE_AP))
  1303. set_bit(SC_OP_TSF_RESET, &sc->sc_flags);
  1304. /* Configure beaconing (AP, IBSS, MESH) */
  1305. if (ath9k_uses_beacons(vif->type) &&
  1306. ((changed & BSS_CHANGED_BEACON) ||
  1307. (changed & BSS_CHANGED_BEACON_ENABLED) ||
  1308. (changed & BSS_CHANGED_BEACON_INT))) {
  1309. ath9k_set_beaconing_status(sc, false);
  1310. if (bss_conf->enable_beacon)
  1311. ath_beacon_alloc(sc, vif);
  1312. else
  1313. avp->is_bslot_active = false;
  1314. ath_beacon_config(sc, vif);
  1315. ath9k_set_beaconing_status(sc, true);
  1316. }
  1317. if (changed & BSS_CHANGED_ERP_SLOT) {
  1318. if (bss_conf->use_short_slot)
  1319. slottime = 9;
  1320. else
  1321. slottime = 20;
  1322. if (vif->type == NL80211_IFTYPE_AP) {
  1323. /*
  1324. * Defer update, so that connected stations can adjust
  1325. * their settings at the same time.
  1326. * See beacon.c for more details
  1327. */
  1328. sc->beacon.slottime = slottime;
  1329. sc->beacon.updateslot = UPDATE;
  1330. } else {
  1331. ah->slottime = slottime;
  1332. ath9k_hw_init_global_settings(ah);
  1333. }
  1334. }
  1335. mutex_unlock(&sc->mutex);
  1336. ath9k_ps_restore(sc);
  1337. }
  1338. static u64 ath9k_get_tsf(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
  1339. {
  1340. struct ath_softc *sc = hw->priv;
  1341. u64 tsf;
  1342. mutex_lock(&sc->mutex);
  1343. ath9k_ps_wakeup(sc);
  1344. tsf = ath9k_hw_gettsf64(sc->sc_ah);
  1345. ath9k_ps_restore(sc);
  1346. mutex_unlock(&sc->mutex);
  1347. return tsf;
  1348. }
  1349. static void ath9k_set_tsf(struct ieee80211_hw *hw,
  1350. struct ieee80211_vif *vif,
  1351. u64 tsf)
  1352. {
  1353. struct ath_softc *sc = hw->priv;
  1354. mutex_lock(&sc->mutex);
  1355. ath9k_ps_wakeup(sc);
  1356. ath9k_hw_settsf64(sc->sc_ah, tsf);
  1357. ath9k_ps_restore(sc);
  1358. mutex_unlock(&sc->mutex);
  1359. }
  1360. static void ath9k_reset_tsf(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
  1361. {
  1362. struct ath_softc *sc = hw->priv;
  1363. mutex_lock(&sc->mutex);
  1364. ath9k_ps_wakeup(sc);
  1365. ath9k_hw_reset_tsf(sc->sc_ah);
  1366. ath9k_ps_restore(sc);
  1367. mutex_unlock(&sc->mutex);
  1368. }
  1369. static int ath9k_ampdu_action(struct ieee80211_hw *hw,
  1370. struct ieee80211_vif *vif,
  1371. enum ieee80211_ampdu_mlme_action action,
  1372. struct ieee80211_sta *sta,
  1373. u16 tid, u16 *ssn, u8 buf_size)
  1374. {
  1375. struct ath_softc *sc = hw->priv;
  1376. int ret = 0;
  1377. local_bh_disable();
  1378. switch (action) {
  1379. case IEEE80211_AMPDU_RX_START:
  1380. break;
  1381. case IEEE80211_AMPDU_RX_STOP:
  1382. break;
  1383. case IEEE80211_AMPDU_TX_START:
  1384. ath9k_ps_wakeup(sc);
  1385. ret = ath_tx_aggr_start(sc, sta, tid, ssn);
  1386. if (!ret)
  1387. ieee80211_start_tx_ba_cb_irqsafe(vif, sta->addr, tid);
  1388. ath9k_ps_restore(sc);
  1389. break;
  1390. case IEEE80211_AMPDU_TX_STOP:
  1391. ath9k_ps_wakeup(sc);
  1392. ath_tx_aggr_stop(sc, sta, tid);
  1393. ieee80211_stop_tx_ba_cb_irqsafe(vif, sta->addr, tid);
  1394. ath9k_ps_restore(sc);
  1395. break;
  1396. case IEEE80211_AMPDU_TX_OPERATIONAL:
  1397. ath9k_ps_wakeup(sc);
  1398. ath_tx_aggr_resume(sc, sta, tid);
  1399. ath9k_ps_restore(sc);
  1400. break;
  1401. default:
  1402. ath_err(ath9k_hw_common(sc->sc_ah), "Unknown AMPDU action\n");
  1403. }
  1404. local_bh_enable();
  1405. return ret;
  1406. }
  1407. static int ath9k_get_survey(struct ieee80211_hw *hw, int idx,
  1408. struct survey_info *survey)
  1409. {
  1410. struct ath_softc *sc = hw->priv;
  1411. struct ath_common *common = ath9k_hw_common(sc->sc_ah);
  1412. struct ieee80211_supported_band *sband;
  1413. struct ieee80211_channel *chan;
  1414. unsigned long flags;
  1415. int pos;
  1416. spin_lock_irqsave(&common->cc_lock, flags);
  1417. if (idx == 0)
  1418. ath_update_survey_stats(sc);
  1419. sband = hw->wiphy->bands[IEEE80211_BAND_2GHZ];
  1420. if (sband && idx >= sband->n_channels) {
  1421. idx -= sband->n_channels;
  1422. sband = NULL;
  1423. }
  1424. if (!sband)
  1425. sband = hw->wiphy->bands[IEEE80211_BAND_5GHZ];
  1426. if (!sband || idx >= sband->n_channels) {
  1427. spin_unlock_irqrestore(&common->cc_lock, flags);
  1428. return -ENOENT;
  1429. }
  1430. chan = &sband->channels[idx];
  1431. pos = chan->hw_value;
  1432. memcpy(survey, &sc->survey[pos], sizeof(*survey));
  1433. survey->channel = chan;
  1434. spin_unlock_irqrestore(&common->cc_lock, flags);
  1435. return 0;
  1436. }
  1437. static void ath9k_set_coverage_class(struct ieee80211_hw *hw, u8 coverage_class)
  1438. {
  1439. struct ath_softc *sc = hw->priv;
  1440. struct ath_hw *ah = sc->sc_ah;
  1441. mutex_lock(&sc->mutex);
  1442. ah->coverage_class = coverage_class;
  1443. ath9k_ps_wakeup(sc);
  1444. ath9k_hw_init_global_settings(ah);
  1445. ath9k_ps_restore(sc);
  1446. mutex_unlock(&sc->mutex);
  1447. }
  1448. static void ath9k_flush(struct ieee80211_hw *hw, bool drop)
  1449. {
  1450. struct ath_softc *sc = hw->priv;
  1451. struct ath_hw *ah = sc->sc_ah;
  1452. struct ath_common *common = ath9k_hw_common(ah);
  1453. int timeout = 200; /* ms */
  1454. int i, j;
  1455. bool drain_txq;
  1456. mutex_lock(&sc->mutex);
  1457. cancel_delayed_work_sync(&sc->tx_complete_work);
  1458. if (ah->ah_flags & AH_UNPLUGGED) {
  1459. ath_dbg(common, ANY, "Device has been unplugged!\n");
  1460. mutex_unlock(&sc->mutex);
  1461. return;
  1462. }
  1463. if (test_bit(SC_OP_INVALID, &sc->sc_flags)) {
  1464. ath_dbg(common, ANY, "Device not present\n");
  1465. mutex_unlock(&sc->mutex);
  1466. return;
  1467. }
  1468. for (j = 0; j < timeout; j++) {
  1469. bool npend = false;
  1470. if (j)
  1471. usleep_range(1000, 2000);
  1472. for (i = 0; i < ATH9K_NUM_TX_QUEUES; i++) {
  1473. if (!ATH_TXQ_SETUP(sc, i))
  1474. continue;
  1475. npend = ath9k_has_pending_frames(sc, &sc->tx.txq[i]);
  1476. if (npend)
  1477. break;
  1478. }
  1479. if (!npend)
  1480. break;
  1481. }
  1482. if (drop) {
  1483. ath9k_ps_wakeup(sc);
  1484. spin_lock_bh(&sc->sc_pcu_lock);
  1485. drain_txq = ath_drain_all_txq(sc, false);
  1486. spin_unlock_bh(&sc->sc_pcu_lock);
  1487. if (!drain_txq)
  1488. ath_reset(sc, false);
  1489. ath9k_ps_restore(sc);
  1490. ieee80211_wake_queues(hw);
  1491. }
  1492. ieee80211_queue_delayed_work(hw, &sc->tx_complete_work, 0);
  1493. mutex_unlock(&sc->mutex);
  1494. }
  1495. static bool ath9k_tx_frames_pending(struct ieee80211_hw *hw)
  1496. {
  1497. struct ath_softc *sc = hw->priv;
  1498. int i;
  1499. for (i = 0; i < ATH9K_NUM_TX_QUEUES; i++) {
  1500. if (!ATH_TXQ_SETUP(sc, i))
  1501. continue;
  1502. if (ath9k_has_pending_frames(sc, &sc->tx.txq[i]))
  1503. return true;
  1504. }
  1505. return false;
  1506. }
  1507. static int ath9k_tx_last_beacon(struct ieee80211_hw *hw)
  1508. {
  1509. struct ath_softc *sc = hw->priv;
  1510. struct ath_hw *ah = sc->sc_ah;
  1511. struct ieee80211_vif *vif;
  1512. struct ath_vif *avp;
  1513. struct ath_buf *bf;
  1514. struct ath_tx_status ts;
  1515. bool edma = !!(ah->caps.hw_caps & ATH9K_HW_CAP_EDMA);
  1516. int status;
  1517. vif = sc->beacon.bslot[0];
  1518. if (!vif)
  1519. return 0;
  1520. avp = (void *)vif->drv_priv;
  1521. if (!avp->is_bslot_active)
  1522. return 0;
  1523. if (!sc->beacon.tx_processed && !edma) {
  1524. tasklet_disable(&sc->bcon_tasklet);
  1525. bf = avp->av_bcbuf;
  1526. if (!bf || !bf->bf_mpdu)
  1527. goto skip;
  1528. status = ath9k_hw_txprocdesc(ah, bf->bf_desc, &ts);
  1529. if (status == -EINPROGRESS)
  1530. goto skip;
  1531. sc->beacon.tx_processed = true;
  1532. sc->beacon.tx_last = !(ts.ts_status & ATH9K_TXERR_MASK);
  1533. skip:
  1534. tasklet_enable(&sc->bcon_tasklet);
  1535. }
  1536. return sc->beacon.tx_last;
  1537. }
  1538. static int ath9k_get_stats(struct ieee80211_hw *hw,
  1539. struct ieee80211_low_level_stats *stats)
  1540. {
  1541. struct ath_softc *sc = hw->priv;
  1542. struct ath_hw *ah = sc->sc_ah;
  1543. struct ath9k_mib_stats *mib_stats = &ah->ah_mibStats;
  1544. stats->dot11ACKFailureCount = mib_stats->ackrcv_bad;
  1545. stats->dot11RTSFailureCount = mib_stats->rts_bad;
  1546. stats->dot11FCSErrorCount = mib_stats->fcs_bad;
  1547. stats->dot11RTSSuccessCount = mib_stats->rts_good;
  1548. return 0;
  1549. }
  1550. static u32 fill_chainmask(u32 cap, u32 new)
  1551. {
  1552. u32 filled = 0;
  1553. int i;
  1554. for (i = 0; cap && new; i++, cap >>= 1) {
  1555. if (!(cap & BIT(0)))
  1556. continue;
  1557. if (new & BIT(0))
  1558. filled |= BIT(i);
  1559. new >>= 1;
  1560. }
  1561. return filled;
  1562. }
  1563. static int ath9k_set_antenna(struct ieee80211_hw *hw, u32 tx_ant, u32 rx_ant)
  1564. {
  1565. struct ath_softc *sc = hw->priv;
  1566. struct ath_hw *ah = sc->sc_ah;
  1567. if (!rx_ant || !tx_ant)
  1568. return -EINVAL;
  1569. sc->ant_rx = rx_ant;
  1570. sc->ant_tx = tx_ant;
  1571. if (ah->caps.rx_chainmask == 1)
  1572. return 0;
  1573. /* AR9100 runs into calibration issues if not all rx chains are enabled */
  1574. if (AR_SREV_9100(ah))
  1575. ah->rxchainmask = 0x7;
  1576. else
  1577. ah->rxchainmask = fill_chainmask(ah->caps.rx_chainmask, rx_ant);
  1578. ah->txchainmask = fill_chainmask(ah->caps.tx_chainmask, tx_ant);
  1579. ath9k_reload_chainmask_settings(sc);
  1580. return 0;
  1581. }
  1582. static int ath9k_get_antenna(struct ieee80211_hw *hw, u32 *tx_ant, u32 *rx_ant)
  1583. {
  1584. struct ath_softc *sc = hw->priv;
  1585. *tx_ant = sc->ant_tx;
  1586. *rx_ant = sc->ant_rx;
  1587. return 0;
  1588. }
  1589. #ifdef CONFIG_ATH9K_DEBUGFS
  1590. /* Ethtool support for get-stats */
  1591. #define AMKSTR(nm) #nm "_BE", #nm "_BK", #nm "_VI", #nm "_VO"
  1592. static const char ath9k_gstrings_stats[][ETH_GSTRING_LEN] = {
  1593. "tx_pkts_nic",
  1594. "tx_bytes_nic",
  1595. "rx_pkts_nic",
  1596. "rx_bytes_nic",
  1597. AMKSTR(d_tx_pkts),
  1598. AMKSTR(d_tx_bytes),
  1599. AMKSTR(d_tx_mpdus_queued),
  1600. AMKSTR(d_tx_mpdus_completed),
  1601. AMKSTR(d_tx_mpdu_xretries),
  1602. AMKSTR(d_tx_aggregates),
  1603. AMKSTR(d_tx_ampdus_queued_hw),
  1604. AMKSTR(d_tx_ampdus_queued_sw),
  1605. AMKSTR(d_tx_ampdus_completed),
  1606. AMKSTR(d_tx_ampdu_retries),
  1607. AMKSTR(d_tx_ampdu_xretries),
  1608. AMKSTR(d_tx_fifo_underrun),
  1609. AMKSTR(d_tx_op_exceeded),
  1610. AMKSTR(d_tx_timer_expiry),
  1611. AMKSTR(d_tx_desc_cfg_err),
  1612. AMKSTR(d_tx_data_underrun),
  1613. AMKSTR(d_tx_delim_underrun),
  1614. "d_rx_decrypt_crc_err",
  1615. "d_rx_phy_err",
  1616. "d_rx_mic_err",
  1617. "d_rx_pre_delim_crc_err",
  1618. "d_rx_post_delim_crc_err",
  1619. "d_rx_decrypt_busy_err",
  1620. "d_rx_phyerr_radar",
  1621. "d_rx_phyerr_ofdm_timing",
  1622. "d_rx_phyerr_cck_timing",
  1623. };
  1624. #define ATH9K_SSTATS_LEN ARRAY_SIZE(ath9k_gstrings_stats)
  1625. static void ath9k_get_et_strings(struct ieee80211_hw *hw,
  1626. struct ieee80211_vif *vif,
  1627. u32 sset, u8 *data)
  1628. {
  1629. if (sset == ETH_SS_STATS)
  1630. memcpy(data, *ath9k_gstrings_stats,
  1631. sizeof(ath9k_gstrings_stats));
  1632. }
  1633. static int ath9k_get_et_sset_count(struct ieee80211_hw *hw,
  1634. struct ieee80211_vif *vif, int sset)
  1635. {
  1636. if (sset == ETH_SS_STATS)
  1637. return ATH9K_SSTATS_LEN;
  1638. return 0;
  1639. }
  1640. #define PR_QNUM(_n) (sc->tx.txq_map[_n]->axq_qnum)
  1641. #define AWDATA(elem) \
  1642. do { \
  1643. data[i++] = sc->debug.stats.txstats[PR_QNUM(WME_AC_BE)].elem; \
  1644. data[i++] = sc->debug.stats.txstats[PR_QNUM(WME_AC_BK)].elem; \
  1645. data[i++] = sc->debug.stats.txstats[PR_QNUM(WME_AC_VI)].elem; \
  1646. data[i++] = sc->debug.stats.txstats[PR_QNUM(WME_AC_VO)].elem; \
  1647. } while (0)
  1648. #define AWDATA_RX(elem) \
  1649. do { \
  1650. data[i++] = sc->debug.stats.rxstats.elem; \
  1651. } while (0)
  1652. static void ath9k_get_et_stats(struct ieee80211_hw *hw,
  1653. struct ieee80211_vif *vif,
  1654. struct ethtool_stats *stats, u64 *data)
  1655. {
  1656. struct ath_softc *sc = hw->priv;
  1657. int i = 0;
  1658. data[i++] = (sc->debug.stats.txstats[PR_QNUM(WME_AC_BE)].tx_pkts_all +
  1659. sc->debug.stats.txstats[PR_QNUM(WME_AC_BK)].tx_pkts_all +
  1660. sc->debug.stats.txstats[PR_QNUM(WME_AC_VI)].tx_pkts_all +
  1661. sc->debug.stats.txstats[PR_QNUM(WME_AC_VO)].tx_pkts_all);
  1662. data[i++] = (sc->debug.stats.txstats[PR_QNUM(WME_AC_BE)].tx_bytes_all +
  1663. sc->debug.stats.txstats[PR_QNUM(WME_AC_BK)].tx_bytes_all +
  1664. sc->debug.stats.txstats[PR_QNUM(WME_AC_VI)].tx_bytes_all +
  1665. sc->debug.stats.txstats[PR_QNUM(WME_AC_VO)].tx_bytes_all);
  1666. AWDATA_RX(rx_pkts_all);
  1667. AWDATA_RX(rx_bytes_all);
  1668. AWDATA(tx_pkts_all);
  1669. AWDATA(tx_bytes_all);
  1670. AWDATA(queued);
  1671. AWDATA(completed);
  1672. AWDATA(xretries);
  1673. AWDATA(a_aggr);
  1674. AWDATA(a_queued_hw);
  1675. AWDATA(a_queued_sw);
  1676. AWDATA(a_completed);
  1677. AWDATA(a_retries);
  1678. AWDATA(a_xretries);
  1679. AWDATA(fifo_underrun);
  1680. AWDATA(xtxop);
  1681. AWDATA(timer_exp);
  1682. AWDATA(desc_cfg_err);
  1683. AWDATA(data_underrun);
  1684. AWDATA(delim_underrun);
  1685. AWDATA_RX(decrypt_crc_err);
  1686. AWDATA_RX(phy_err);
  1687. AWDATA_RX(mic_err);
  1688. AWDATA_RX(pre_delim_crc_err);
  1689. AWDATA_RX(post_delim_crc_err);
  1690. AWDATA_RX(decrypt_busy_err);
  1691. AWDATA_RX(phy_err_stats[ATH9K_PHYERR_RADAR]);
  1692. AWDATA_RX(phy_err_stats[ATH9K_PHYERR_OFDM_TIMING]);
  1693. AWDATA_RX(phy_err_stats[ATH9K_PHYERR_CCK_TIMING]);
  1694. WARN_ON(i != ATH9K_SSTATS_LEN);
  1695. }
  1696. /* End of ethtool get-stats functions */
  1697. #endif
  1698. struct ieee80211_ops ath9k_ops = {
  1699. .tx = ath9k_tx,
  1700. .start = ath9k_start,
  1701. .stop = ath9k_stop,
  1702. .add_interface = ath9k_add_interface,
  1703. .change_interface = ath9k_change_interface,
  1704. .remove_interface = ath9k_remove_interface,
  1705. .config = ath9k_config,
  1706. .configure_filter = ath9k_configure_filter,
  1707. .sta_add = ath9k_sta_add,
  1708. .sta_remove = ath9k_sta_remove,
  1709. .sta_notify = ath9k_sta_notify,
  1710. .conf_tx = ath9k_conf_tx,
  1711. .bss_info_changed = ath9k_bss_info_changed,
  1712. .set_key = ath9k_set_key,
  1713. .get_tsf = ath9k_get_tsf,
  1714. .set_tsf = ath9k_set_tsf,
  1715. .reset_tsf = ath9k_reset_tsf,
  1716. .ampdu_action = ath9k_ampdu_action,
  1717. .get_survey = ath9k_get_survey,
  1718. .rfkill_poll = ath9k_rfkill_poll_state,
  1719. .set_coverage_class = ath9k_set_coverage_class,
  1720. .flush = ath9k_flush,
  1721. .tx_frames_pending = ath9k_tx_frames_pending,
  1722. .tx_last_beacon = ath9k_tx_last_beacon,
  1723. .get_stats = ath9k_get_stats,
  1724. .set_antenna = ath9k_set_antenna,
  1725. .get_antenna = ath9k_get_antenna,
  1726. #ifdef CONFIG_ATH9K_DEBUGFS
  1727. .get_et_sset_count = ath9k_get_et_sset_count,
  1728. .get_et_stats = ath9k_get_et_stats,
  1729. .get_et_strings = ath9k_get_et_strings,
  1730. #endif
  1731. };