main.c 58 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395
  1. /*
  2. * Copyright (c) 2008-2011 Atheros Communications Inc.
  3. *
  4. * Permission to use, copy, modify, and/or distribute this software for any
  5. * purpose with or without fee is hereby granted, provided that the above
  6. * copyright notice and this permission notice appear in all copies.
  7. *
  8. * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
  9. * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
  10. * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
  11. * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  12. * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
  13. * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
  14. * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  15. */
  16. #include <linux/nl80211.h>
  17. #include <linux/delay.h>
  18. #include "ath9k.h"
  19. #include "btcoex.h"
  20. static void ath9k_set_assoc_state(struct ath_softc *sc,
  21. struct ieee80211_vif *vif);
  22. u8 ath9k_parse_mpdudensity(u8 mpdudensity)
  23. {
  24. /*
  25. * 802.11n D2.0 defined values for "Minimum MPDU Start Spacing":
  26. * 0 for no restriction
  27. * 1 for 1/4 us
  28. * 2 for 1/2 us
  29. * 3 for 1 us
  30. * 4 for 2 us
  31. * 5 for 4 us
  32. * 6 for 8 us
  33. * 7 for 16 us
  34. */
  35. switch (mpdudensity) {
  36. case 0:
  37. return 0;
  38. case 1:
  39. case 2:
  40. case 3:
  41. /* Our lower layer calculations limit our precision to
  42. 1 microsecond */
  43. return 1;
  44. case 4:
  45. return 2;
  46. case 5:
  47. return 4;
  48. case 6:
  49. return 8;
  50. case 7:
  51. return 16;
  52. default:
  53. return 0;
  54. }
  55. }
  56. static bool ath9k_has_pending_frames(struct ath_softc *sc, struct ath_txq *txq)
  57. {
  58. bool pending = false;
  59. spin_lock_bh(&txq->axq_lock);
  60. if (txq->axq_depth || !list_empty(&txq->axq_acq))
  61. pending = true;
  62. spin_unlock_bh(&txq->axq_lock);
  63. return pending;
  64. }
  65. static 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. memset(&common->cc_ani, 0, sizeof(common->cc_ani));
  94. spin_unlock(&common->cc_lock);
  95. }
  96. unlock:
  97. spin_unlock_irqrestore(&sc->sc_pm_lock, flags);
  98. }
  99. void ath9k_ps_restore(struct ath_softc *sc)
  100. {
  101. struct ath_common *common = ath9k_hw_common(sc->sc_ah);
  102. enum ath9k_power_mode mode;
  103. unsigned long flags;
  104. bool reset;
  105. spin_lock_irqsave(&sc->sc_pm_lock, flags);
  106. if (--sc->ps_usecount != 0)
  107. goto unlock;
  108. if (sc->ps_idle) {
  109. ath9k_hw_setrxabort(sc->sc_ah, 1);
  110. ath9k_hw_stopdmarecv(sc->sc_ah, &reset);
  111. mode = ATH9K_PM_FULL_SLEEP;
  112. } else if (sc->ps_enabled &&
  113. !(sc->ps_flags & (PS_WAIT_FOR_BEACON |
  114. PS_WAIT_FOR_CAB |
  115. PS_WAIT_FOR_PSPOLL_DATA |
  116. PS_WAIT_FOR_TX_ACK |
  117. PS_WAIT_FOR_ANI))) {
  118. mode = ATH9K_PM_NETWORK_SLEEP;
  119. if (ath9k_hw_btcoex_is_enabled(sc->sc_ah))
  120. ath9k_btcoex_stop_gen_timer(sc);
  121. } else {
  122. goto unlock;
  123. }
  124. spin_lock(&common->cc_lock);
  125. ath_hw_cycle_counters_update(common);
  126. spin_unlock(&common->cc_lock);
  127. ath9k_hw_setpower(sc->sc_ah, mode);
  128. unlock:
  129. spin_unlock_irqrestore(&sc->sc_pm_lock, flags);
  130. }
  131. static void __ath_cancel_work(struct ath_softc *sc)
  132. {
  133. cancel_work_sync(&sc->paprd_work);
  134. cancel_work_sync(&sc->hw_check_work);
  135. cancel_delayed_work_sync(&sc->tx_complete_work);
  136. cancel_delayed_work_sync(&sc->hw_pll_work);
  137. #ifdef CONFIG_ATH9K_BTCOEX_SUPPORT
  138. if (ath9k_hw_mci_is_enabled(sc->sc_ah))
  139. cancel_work_sync(&sc->mci_work);
  140. #endif
  141. }
  142. static void ath_cancel_work(struct ath_softc *sc)
  143. {
  144. __ath_cancel_work(sc);
  145. cancel_work_sync(&sc->hw_reset_work);
  146. }
  147. static void ath_restart_work(struct ath_softc *sc)
  148. {
  149. ieee80211_queue_delayed_work(sc->hw, &sc->tx_complete_work, 0);
  150. if (AR_SREV_9340(sc->sc_ah) || AR_SREV_9330(sc->sc_ah))
  151. ieee80211_queue_delayed_work(sc->hw, &sc->hw_pll_work,
  152. msecs_to_jiffies(ATH_PLL_WORK_INTERVAL));
  153. ath_start_rx_poll(sc, 3);
  154. ath_start_ani(sc);
  155. }
  156. static bool ath_prepare_reset(struct ath_softc *sc)
  157. {
  158. struct ath_hw *ah = sc->sc_ah;
  159. bool ret = true;
  160. ieee80211_stop_queues(sc->hw);
  161. sc->hw_busy_count = 0;
  162. ath_stop_ani(sc);
  163. del_timer_sync(&sc->rx_poll_timer);
  164. ath9k_hw_disable_interrupts(ah);
  165. if (!ath_drain_all_txq(sc))
  166. ret = false;
  167. if (!ath_stoprecv(sc))
  168. ret = false;
  169. return ret;
  170. }
  171. static bool ath_complete_reset(struct ath_softc *sc, bool start)
  172. {
  173. struct ath_hw *ah = sc->sc_ah;
  174. struct ath_common *common = ath9k_hw_common(ah);
  175. unsigned long flags;
  176. if (ath_startrecv(sc) != 0) {
  177. ath_err(common, "Unable to restart recv logic\n");
  178. return false;
  179. }
  180. ath9k_cmn_update_txpow(ah, sc->curtxpow,
  181. sc->config.txpowlimit, &sc->curtxpow);
  182. clear_bit(SC_OP_HW_RESET, &sc->sc_flags);
  183. ath9k_hw_set_interrupts(ah);
  184. ath9k_hw_enable_interrupts(ah);
  185. if (!(sc->hw->conf.flags & IEEE80211_CONF_OFFCHANNEL) && start) {
  186. if (!test_bit(SC_OP_BEACONS, &sc->sc_flags))
  187. goto work;
  188. if (ah->opmode == NL80211_IFTYPE_STATION &&
  189. test_bit(SC_OP_PRIM_STA_VIF, &sc->sc_flags)) {
  190. spin_lock_irqsave(&sc->sc_pm_lock, flags);
  191. sc->ps_flags |= PS_BEACON_SYNC | PS_WAIT_FOR_BEACON;
  192. spin_unlock_irqrestore(&sc->sc_pm_lock, flags);
  193. } else {
  194. ath9k_set_beacon(sc);
  195. }
  196. work:
  197. ath_restart_work(sc);
  198. }
  199. ieee80211_wake_queues(sc->hw);
  200. return true;
  201. }
  202. static int ath_reset_internal(struct ath_softc *sc, struct ath9k_channel *hchan)
  203. {
  204. struct ath_hw *ah = sc->sc_ah;
  205. struct ath_common *common = ath9k_hw_common(ah);
  206. struct ath9k_hw_cal_data *caldata = NULL;
  207. bool fastcc = true;
  208. int r;
  209. __ath_cancel_work(sc);
  210. tasklet_disable(&sc->intr_tq);
  211. spin_lock_bh(&sc->sc_pcu_lock);
  212. if (!(sc->hw->conf.flags & IEEE80211_CONF_OFFCHANNEL)) {
  213. fastcc = false;
  214. caldata = &sc->caldata;
  215. }
  216. if (!hchan) {
  217. fastcc = false;
  218. hchan = ah->curchan;
  219. }
  220. if (!ath_prepare_reset(sc))
  221. fastcc = false;
  222. ath_dbg(common, CONFIG, "Reset to %u MHz, HT40: %d fastcc: %d\n",
  223. hchan->channel, IS_CHAN_HT40(hchan), fastcc);
  224. r = ath9k_hw_reset(ah, hchan, caldata, fastcc);
  225. if (r) {
  226. ath_err(common,
  227. "Unable to reset channel, reset status %d\n", r);
  228. ath9k_hw_enable_interrupts(ah);
  229. ath9k_queue_reset(sc, RESET_TYPE_BB_HANG);
  230. goto out;
  231. }
  232. if (ath9k_hw_mci_is_enabled(sc->sc_ah) &&
  233. (sc->hw->conf.flags & IEEE80211_CONF_OFFCHANNEL))
  234. ath9k_mci_set_txpower(sc, true, false);
  235. if (!ath_complete_reset(sc, true))
  236. r = -EIO;
  237. out:
  238. spin_unlock_bh(&sc->sc_pcu_lock);
  239. tasklet_enable(&sc->intr_tq);
  240. return r;
  241. }
  242. /*
  243. * Set/change channels. If the channel is really being changed, it's done
  244. * by reseting the chip. To accomplish this we must first cleanup any pending
  245. * DMA, then restart stuff.
  246. */
  247. static int ath_set_channel(struct ath_softc *sc, struct cfg80211_chan_def *chandef)
  248. {
  249. struct ath_hw *ah = sc->sc_ah;
  250. struct ath_common *common = ath9k_hw_common(ah);
  251. struct ieee80211_hw *hw = sc->hw;
  252. struct ath9k_channel *hchan;
  253. struct ieee80211_channel *chan = chandef->chan;
  254. unsigned long flags;
  255. bool offchannel;
  256. int pos = chan->hw_value;
  257. int old_pos = -1;
  258. int r;
  259. if (test_bit(SC_OP_INVALID, &sc->sc_flags))
  260. return -EIO;
  261. offchannel = !!(hw->conf.flags & IEEE80211_CONF_OFFCHANNEL);
  262. if (ah->curchan)
  263. old_pos = ah->curchan - &ah->channels[0];
  264. ath_dbg(common, CONFIG, "Set channel: %d MHz width: %d\n",
  265. chan->center_freq, chandef->width);
  266. /* update survey stats for the old channel before switching */
  267. spin_lock_irqsave(&common->cc_lock, flags);
  268. ath_update_survey_stats(sc);
  269. spin_unlock_irqrestore(&common->cc_lock, flags);
  270. ath9k_cmn_get_channel(hw, ah, chandef);
  271. /*
  272. * If the operating channel changes, change the survey in-use flags
  273. * along with it.
  274. * Reset the survey data for the new channel, unless we're switching
  275. * back to the operating channel from an off-channel operation.
  276. */
  277. if (!offchannel && sc->cur_survey != &sc->survey[pos]) {
  278. if (sc->cur_survey)
  279. sc->cur_survey->filled &= ~SURVEY_INFO_IN_USE;
  280. sc->cur_survey = &sc->survey[pos];
  281. memset(sc->cur_survey, 0, sizeof(struct survey_info));
  282. sc->cur_survey->filled |= SURVEY_INFO_IN_USE;
  283. } else if (!(sc->survey[pos].filled & SURVEY_INFO_IN_USE)) {
  284. memset(&sc->survey[pos], 0, sizeof(struct survey_info));
  285. }
  286. hchan = &sc->sc_ah->channels[pos];
  287. r = ath_reset_internal(sc, hchan);
  288. if (r)
  289. return r;
  290. /*
  291. * The most recent snapshot of channel->noisefloor for the old
  292. * channel is only available after the hardware reset. Copy it to
  293. * the survey stats now.
  294. */
  295. if (old_pos >= 0)
  296. ath_update_survey_nf(sc, old_pos);
  297. /*
  298. * Enable radar pulse detection if on a DFS channel. Spectral
  299. * scanning and radar detection can not be used concurrently.
  300. */
  301. if (hw->conf.radar_enabled) {
  302. u32 rxfilter;
  303. /* set HW specific DFS configuration */
  304. ath9k_hw_set_radar_params(ah);
  305. rxfilter = ath9k_hw_getrxfilter(ah);
  306. rxfilter |= ATH9K_RX_FILTER_PHYRADAR |
  307. ATH9K_RX_FILTER_PHYERR;
  308. ath9k_hw_setrxfilter(ah, rxfilter);
  309. ath_dbg(common, DFS, "DFS enabled at freq %d\n",
  310. chan->center_freq);
  311. } else {
  312. /* perform spectral scan if requested. */
  313. if (test_bit(SC_OP_SCANNING, &sc->sc_flags) &&
  314. sc->spectral_mode == SPECTRAL_CHANSCAN)
  315. ath9k_spectral_scan_trigger(hw);
  316. }
  317. return 0;
  318. }
  319. static void ath_node_attach(struct ath_softc *sc, struct ieee80211_sta *sta,
  320. struct ieee80211_vif *vif)
  321. {
  322. struct ath_node *an;
  323. an = (struct ath_node *)sta->drv_priv;
  324. an->sc = sc;
  325. an->sta = sta;
  326. an->vif = vif;
  327. ath_tx_node_init(sc, an);
  328. if (sta->ht_cap.ht_supported) {
  329. an->maxampdu = 1 << (IEEE80211_HT_MAX_AMPDU_FACTOR +
  330. sta->ht_cap.ampdu_factor);
  331. an->mpdudensity = ath9k_parse_mpdudensity(sta->ht_cap.ampdu_density);
  332. }
  333. }
  334. static void ath_node_detach(struct ath_softc *sc, struct ieee80211_sta *sta)
  335. {
  336. struct ath_node *an = (struct ath_node *)sta->drv_priv;
  337. ath_tx_node_cleanup(sc, an);
  338. }
  339. void ath9k_tasklet(unsigned long data)
  340. {
  341. struct ath_softc *sc = (struct ath_softc *)data;
  342. struct ath_hw *ah = sc->sc_ah;
  343. struct ath_common *common = ath9k_hw_common(ah);
  344. enum ath_reset_type type;
  345. unsigned long flags;
  346. u32 status = sc->intrstatus;
  347. u32 rxmask;
  348. ath9k_ps_wakeup(sc);
  349. spin_lock(&sc->sc_pcu_lock);
  350. if ((status & ATH9K_INT_FATAL) ||
  351. (status & ATH9K_INT_BB_WATCHDOG)) {
  352. if (status & ATH9K_INT_FATAL)
  353. type = RESET_TYPE_FATAL_INT;
  354. else
  355. type = RESET_TYPE_BB_WATCHDOG;
  356. ath9k_queue_reset(sc, type);
  357. /*
  358. * Increment the ref. counter here so that
  359. * interrupts are enabled in the reset routine.
  360. */
  361. atomic_inc(&ah->intr_ref_cnt);
  362. ath_dbg(common, ANY, "FATAL: Skipping interrupts\n");
  363. goto out;
  364. }
  365. spin_lock_irqsave(&sc->sc_pm_lock, flags);
  366. if ((status & ATH9K_INT_TSFOOR) && sc->ps_enabled) {
  367. /*
  368. * TSF sync does not look correct; remain awake to sync with
  369. * the next Beacon.
  370. */
  371. ath_dbg(common, PS, "TSFOOR - Sync with next Beacon\n");
  372. sc->ps_flags |= PS_WAIT_FOR_BEACON | PS_BEACON_SYNC;
  373. }
  374. spin_unlock_irqrestore(&sc->sc_pm_lock, flags);
  375. if (ah->caps.hw_caps & ATH9K_HW_CAP_EDMA)
  376. rxmask = (ATH9K_INT_RXHP | ATH9K_INT_RXLP | ATH9K_INT_RXEOL |
  377. ATH9K_INT_RXORN);
  378. else
  379. rxmask = (ATH9K_INT_RX | ATH9K_INT_RXEOL | ATH9K_INT_RXORN);
  380. if (status & rxmask) {
  381. /* Check for high priority Rx first */
  382. if ((ah->caps.hw_caps & ATH9K_HW_CAP_EDMA) &&
  383. (status & ATH9K_INT_RXHP))
  384. ath_rx_tasklet(sc, 0, true);
  385. ath_rx_tasklet(sc, 0, false);
  386. }
  387. if (status & ATH9K_INT_TX) {
  388. if (ah->caps.hw_caps & ATH9K_HW_CAP_EDMA)
  389. ath_tx_edma_tasklet(sc);
  390. else
  391. ath_tx_tasklet(sc);
  392. }
  393. ath9k_btcoex_handle_interrupt(sc, status);
  394. /* re-enable hardware interrupt */
  395. ath9k_hw_enable_interrupts(ah);
  396. out:
  397. spin_unlock(&sc->sc_pcu_lock);
  398. ath9k_ps_restore(sc);
  399. }
  400. irqreturn_t ath_isr(int irq, void *dev)
  401. {
  402. #define SCHED_INTR ( \
  403. ATH9K_INT_FATAL | \
  404. ATH9K_INT_BB_WATCHDOG | \
  405. ATH9K_INT_RXORN | \
  406. ATH9K_INT_RXEOL | \
  407. ATH9K_INT_RX | \
  408. ATH9K_INT_RXLP | \
  409. ATH9K_INT_RXHP | \
  410. ATH9K_INT_TX | \
  411. ATH9K_INT_BMISS | \
  412. ATH9K_INT_CST | \
  413. ATH9K_INT_TSFOOR | \
  414. ATH9K_INT_GENTIMER | \
  415. ATH9K_INT_MCI)
  416. struct ath_softc *sc = dev;
  417. struct ath_hw *ah = sc->sc_ah;
  418. struct ath_common *common = ath9k_hw_common(ah);
  419. enum ath9k_int status;
  420. bool sched = false;
  421. /*
  422. * The hardware is not ready/present, don't
  423. * touch anything. Note this can happen early
  424. * on if the IRQ is shared.
  425. */
  426. if (test_bit(SC_OP_INVALID, &sc->sc_flags))
  427. return IRQ_NONE;
  428. /* shared irq, not for us */
  429. if (!ath9k_hw_intrpend(ah))
  430. return IRQ_NONE;
  431. if (test_bit(SC_OP_HW_RESET, &sc->sc_flags)) {
  432. ath9k_hw_kill_interrupts(ah);
  433. return IRQ_HANDLED;
  434. }
  435. /*
  436. * Figure out the reason(s) for the interrupt. Note
  437. * that the hal returns a pseudo-ISR that may include
  438. * bits we haven't explicitly enabled so we mask the
  439. * value to insure we only process bits we requested.
  440. */
  441. ath9k_hw_getisr(ah, &status); /* NB: clears ISR too */
  442. status &= ah->imask; /* discard unasked-for bits */
  443. /*
  444. * If there are no status bits set, then this interrupt was not
  445. * for me (should have been caught above).
  446. */
  447. if (!status)
  448. return IRQ_NONE;
  449. /* Cache the status */
  450. sc->intrstatus = status;
  451. if (status & SCHED_INTR)
  452. sched = true;
  453. /*
  454. * If a FATAL or RXORN interrupt is received, we have to reset the
  455. * chip immediately.
  456. */
  457. if ((status & ATH9K_INT_FATAL) || ((status & ATH9K_INT_RXORN) &&
  458. !(ah->caps.hw_caps & ATH9K_HW_CAP_EDMA)))
  459. goto chip_reset;
  460. if ((ah->caps.hw_caps & ATH9K_HW_CAP_EDMA) &&
  461. (status & ATH9K_INT_BB_WATCHDOG)) {
  462. spin_lock(&common->cc_lock);
  463. ath_hw_cycle_counters_update(common);
  464. ar9003_hw_bb_watchdog_dbg_info(ah);
  465. spin_unlock(&common->cc_lock);
  466. goto chip_reset;
  467. }
  468. #ifdef CONFIG_PM_SLEEP
  469. if (status & ATH9K_INT_BMISS) {
  470. if (atomic_read(&sc->wow_sleep_proc_intr) == 0) {
  471. ath_dbg(common, ANY, "during WoW we got a BMISS\n");
  472. atomic_inc(&sc->wow_got_bmiss_intr);
  473. atomic_dec(&sc->wow_sleep_proc_intr);
  474. }
  475. }
  476. #endif
  477. if (status & ATH9K_INT_SWBA)
  478. tasklet_schedule(&sc->bcon_tasklet);
  479. if (status & ATH9K_INT_TXURN)
  480. ath9k_hw_updatetxtriglevel(ah, true);
  481. if (status & ATH9K_INT_RXEOL) {
  482. ah->imask &= ~(ATH9K_INT_RXEOL | ATH9K_INT_RXORN);
  483. ath9k_hw_set_interrupts(ah);
  484. }
  485. if (!(ah->caps.hw_caps & ATH9K_HW_CAP_AUTOSLEEP))
  486. if (status & ATH9K_INT_TIM_TIMER) {
  487. if (ATH_DBG_WARN_ON_ONCE(sc->ps_idle))
  488. goto chip_reset;
  489. /* Clear RxAbort bit so that we can
  490. * receive frames */
  491. ath9k_setpower(sc, ATH9K_PM_AWAKE);
  492. spin_lock(&sc->sc_pm_lock);
  493. ath9k_hw_setrxabort(sc->sc_ah, 0);
  494. sc->ps_flags |= PS_WAIT_FOR_BEACON;
  495. spin_unlock(&sc->sc_pm_lock);
  496. }
  497. chip_reset:
  498. ath_debug_stat_interrupt(sc, status);
  499. if (sched) {
  500. /* turn off every interrupt */
  501. ath9k_hw_disable_interrupts(ah);
  502. tasklet_schedule(&sc->intr_tq);
  503. }
  504. return IRQ_HANDLED;
  505. #undef SCHED_INTR
  506. }
  507. static int ath_reset(struct ath_softc *sc)
  508. {
  509. int i, r;
  510. ath9k_ps_wakeup(sc);
  511. r = ath_reset_internal(sc, NULL);
  512. for (i = 0; i < ATH9K_NUM_TX_QUEUES; i++) {
  513. if (!ATH_TXQ_SETUP(sc, i))
  514. continue;
  515. spin_lock_bh(&sc->tx.txq[i].axq_lock);
  516. ath_txq_schedule(sc, &sc->tx.txq[i]);
  517. spin_unlock_bh(&sc->tx.txq[i].axq_lock);
  518. }
  519. ath9k_ps_restore(sc);
  520. return r;
  521. }
  522. void ath9k_queue_reset(struct ath_softc *sc, enum ath_reset_type type)
  523. {
  524. #ifdef CONFIG_ATH9K_DEBUGFS
  525. RESET_STAT_INC(sc, type);
  526. #endif
  527. set_bit(SC_OP_HW_RESET, &sc->sc_flags);
  528. ieee80211_queue_work(sc->hw, &sc->hw_reset_work);
  529. }
  530. void ath_reset_work(struct work_struct *work)
  531. {
  532. struct ath_softc *sc = container_of(work, struct ath_softc, hw_reset_work);
  533. ath_reset(sc);
  534. }
  535. /**********************/
  536. /* mac80211 callbacks */
  537. /**********************/
  538. static int ath9k_start(struct ieee80211_hw *hw)
  539. {
  540. struct ath_softc *sc = hw->priv;
  541. struct ath_hw *ah = sc->sc_ah;
  542. struct ath_common *common = ath9k_hw_common(ah);
  543. struct ieee80211_channel *curchan = hw->conf.chandef.chan;
  544. struct ath9k_channel *init_channel;
  545. int r;
  546. ath_dbg(common, CONFIG,
  547. "Starting driver with initial channel: %d MHz\n",
  548. curchan->center_freq);
  549. ath9k_ps_wakeup(sc);
  550. mutex_lock(&sc->mutex);
  551. init_channel = ath9k_cmn_get_channel(hw, ah, &hw->conf.chandef);
  552. /* Reset SERDES registers */
  553. ath9k_hw_configpcipowersave(ah, false);
  554. /*
  555. * The basic interface to setting the hardware in a good
  556. * state is ``reset''. On return the hardware is known to
  557. * be powered up and with interrupts disabled. This must
  558. * be followed by initialization of the appropriate bits
  559. * and then setup of the interrupt mask.
  560. */
  561. spin_lock_bh(&sc->sc_pcu_lock);
  562. atomic_set(&ah->intr_ref_cnt, -1);
  563. r = ath9k_hw_reset(ah, init_channel, ah->caldata, false);
  564. if (r) {
  565. ath_err(common,
  566. "Unable to reset hardware; reset status %d (freq %u MHz)\n",
  567. r, curchan->center_freq);
  568. ah->reset_power_on = false;
  569. }
  570. /* Setup our intr mask. */
  571. ah->imask = ATH9K_INT_TX | ATH9K_INT_RXEOL |
  572. ATH9K_INT_RXORN | ATH9K_INT_FATAL |
  573. ATH9K_INT_GLOBAL;
  574. if (ah->caps.hw_caps & ATH9K_HW_CAP_EDMA)
  575. ah->imask |= ATH9K_INT_RXHP |
  576. ATH9K_INT_RXLP |
  577. ATH9K_INT_BB_WATCHDOG;
  578. else
  579. ah->imask |= ATH9K_INT_RX;
  580. ah->imask |= ATH9K_INT_GTT;
  581. if (ah->caps.hw_caps & ATH9K_HW_CAP_HT)
  582. ah->imask |= ATH9K_INT_CST;
  583. ath_mci_enable(sc);
  584. clear_bit(SC_OP_INVALID, &sc->sc_flags);
  585. sc->sc_ah->is_monitoring = false;
  586. if (!ath_complete_reset(sc, false))
  587. ah->reset_power_on = false;
  588. if (ah->led_pin >= 0) {
  589. ath9k_hw_cfg_output(ah, ah->led_pin,
  590. AR_GPIO_OUTPUT_MUX_AS_OUTPUT);
  591. ath9k_hw_set_gpio(ah, ah->led_pin, 0);
  592. }
  593. /*
  594. * Reset key cache to sane defaults (all entries cleared) instead of
  595. * semi-random values after suspend/resume.
  596. */
  597. ath9k_cmn_init_crypto(sc->sc_ah);
  598. spin_unlock_bh(&sc->sc_pcu_lock);
  599. mutex_unlock(&sc->mutex);
  600. ath9k_ps_restore(sc);
  601. return 0;
  602. }
  603. static void ath9k_tx(struct ieee80211_hw *hw,
  604. struct ieee80211_tx_control *control,
  605. struct sk_buff *skb)
  606. {
  607. struct ath_softc *sc = hw->priv;
  608. struct ath_common *common = ath9k_hw_common(sc->sc_ah);
  609. struct ath_tx_control txctl;
  610. struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
  611. unsigned long flags;
  612. if (sc->ps_enabled) {
  613. /*
  614. * mac80211 does not set PM field for normal data frames, so we
  615. * need to update that based on the current PS mode.
  616. */
  617. if (ieee80211_is_data(hdr->frame_control) &&
  618. !ieee80211_is_nullfunc(hdr->frame_control) &&
  619. !ieee80211_has_pm(hdr->frame_control)) {
  620. ath_dbg(common, PS,
  621. "Add PM=1 for a TX frame while in PS mode\n");
  622. hdr->frame_control |= cpu_to_le16(IEEE80211_FCTL_PM);
  623. }
  624. }
  625. if (unlikely(sc->sc_ah->power_mode == ATH9K_PM_NETWORK_SLEEP)) {
  626. /*
  627. * We are using PS-Poll and mac80211 can request TX while in
  628. * power save mode. Need to wake up hardware for the TX to be
  629. * completed and if needed, also for RX of buffered frames.
  630. */
  631. ath9k_ps_wakeup(sc);
  632. spin_lock_irqsave(&sc->sc_pm_lock, flags);
  633. if (!(sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_AUTOSLEEP))
  634. ath9k_hw_setrxabort(sc->sc_ah, 0);
  635. if (ieee80211_is_pspoll(hdr->frame_control)) {
  636. ath_dbg(common, PS,
  637. "Sending PS-Poll to pick a buffered frame\n");
  638. sc->ps_flags |= PS_WAIT_FOR_PSPOLL_DATA;
  639. } else {
  640. ath_dbg(common, PS, "Wake up to complete TX\n");
  641. sc->ps_flags |= PS_WAIT_FOR_TX_ACK;
  642. }
  643. /*
  644. * The actual restore operation will happen only after
  645. * the ps_flags bit is cleared. We are just dropping
  646. * the ps_usecount here.
  647. */
  648. spin_unlock_irqrestore(&sc->sc_pm_lock, flags);
  649. ath9k_ps_restore(sc);
  650. }
  651. /*
  652. * Cannot tx while the hardware is in full sleep, it first needs a full
  653. * chip reset to recover from that
  654. */
  655. if (unlikely(sc->sc_ah->power_mode == ATH9K_PM_FULL_SLEEP)) {
  656. ath_err(common, "TX while HW is in FULL_SLEEP mode\n");
  657. goto exit;
  658. }
  659. memset(&txctl, 0, sizeof(struct ath_tx_control));
  660. txctl.txq = sc->tx.txq_map[skb_get_queue_mapping(skb)];
  661. txctl.sta = control->sta;
  662. ath_dbg(common, XMIT, "transmitting packet, skb: %p\n", skb);
  663. if (ath_tx_start(hw, skb, &txctl) != 0) {
  664. ath_dbg(common, XMIT, "TX failed\n");
  665. TX_STAT_INC(txctl.txq->axq_qnum, txfailed);
  666. goto exit;
  667. }
  668. return;
  669. exit:
  670. ieee80211_free_txskb(hw, skb);
  671. }
  672. static void ath9k_stop(struct ieee80211_hw *hw)
  673. {
  674. struct ath_softc *sc = hw->priv;
  675. struct ath_hw *ah = sc->sc_ah;
  676. struct ath_common *common = ath9k_hw_common(ah);
  677. bool prev_idle;
  678. mutex_lock(&sc->mutex);
  679. ath_cancel_work(sc);
  680. del_timer_sync(&sc->rx_poll_timer);
  681. if (test_bit(SC_OP_INVALID, &sc->sc_flags)) {
  682. ath_dbg(common, ANY, "Device not present\n");
  683. mutex_unlock(&sc->mutex);
  684. return;
  685. }
  686. /* Ensure HW is awake when we try to shut it down. */
  687. ath9k_ps_wakeup(sc);
  688. spin_lock_bh(&sc->sc_pcu_lock);
  689. /* prevent tasklets to enable interrupts once we disable them */
  690. ah->imask &= ~ATH9K_INT_GLOBAL;
  691. /* make sure h/w will not generate any interrupt
  692. * before setting the invalid flag. */
  693. ath9k_hw_disable_interrupts(ah);
  694. spin_unlock_bh(&sc->sc_pcu_lock);
  695. /* we can now sync irq and kill any running tasklets, since we already
  696. * disabled interrupts and not holding a spin lock */
  697. synchronize_irq(sc->irq);
  698. tasklet_kill(&sc->intr_tq);
  699. tasklet_kill(&sc->bcon_tasklet);
  700. prev_idle = sc->ps_idle;
  701. sc->ps_idle = true;
  702. spin_lock_bh(&sc->sc_pcu_lock);
  703. if (ah->led_pin >= 0) {
  704. ath9k_hw_set_gpio(ah, ah->led_pin, 1);
  705. ath9k_hw_cfg_gpio_input(ah, ah->led_pin);
  706. }
  707. ath_prepare_reset(sc);
  708. if (sc->rx.frag) {
  709. dev_kfree_skb_any(sc->rx.frag);
  710. sc->rx.frag = NULL;
  711. }
  712. if (!ah->curchan)
  713. ah->curchan = ath9k_cmn_get_channel(hw, ah, &hw->conf.chandef);
  714. ath9k_hw_reset(ah, ah->curchan, ah->caldata, false);
  715. ath9k_hw_phy_disable(ah);
  716. ath9k_hw_configpcipowersave(ah, true);
  717. spin_unlock_bh(&sc->sc_pcu_lock);
  718. ath9k_ps_restore(sc);
  719. set_bit(SC_OP_INVALID, &sc->sc_flags);
  720. sc->ps_idle = prev_idle;
  721. mutex_unlock(&sc->mutex);
  722. ath_dbg(common, CONFIG, "Driver halt\n");
  723. }
  724. static bool ath9k_uses_beacons(int type)
  725. {
  726. switch (type) {
  727. case NL80211_IFTYPE_AP:
  728. case NL80211_IFTYPE_ADHOC:
  729. case NL80211_IFTYPE_MESH_POINT:
  730. return true;
  731. default:
  732. return false;
  733. }
  734. }
  735. static void ath9k_vif_iter(void *data, u8 *mac, struct ieee80211_vif *vif)
  736. {
  737. struct ath9k_vif_iter_data *iter_data = data;
  738. int i;
  739. if (iter_data->has_hw_macaddr) {
  740. for (i = 0; i < ETH_ALEN; i++)
  741. iter_data->mask[i] &=
  742. ~(iter_data->hw_macaddr[i] ^ mac[i]);
  743. } else {
  744. memcpy(iter_data->hw_macaddr, mac, ETH_ALEN);
  745. iter_data->has_hw_macaddr = true;
  746. }
  747. switch (vif->type) {
  748. case NL80211_IFTYPE_AP:
  749. iter_data->naps++;
  750. break;
  751. case NL80211_IFTYPE_STATION:
  752. iter_data->nstations++;
  753. break;
  754. case NL80211_IFTYPE_ADHOC:
  755. iter_data->nadhocs++;
  756. break;
  757. case NL80211_IFTYPE_MESH_POINT:
  758. iter_data->nmeshes++;
  759. break;
  760. case NL80211_IFTYPE_WDS:
  761. iter_data->nwds++;
  762. break;
  763. default:
  764. break;
  765. }
  766. }
  767. static void ath9k_sta_vif_iter(void *data, u8 *mac, struct ieee80211_vif *vif)
  768. {
  769. struct ath_softc *sc = data;
  770. struct ath_vif *avp = (void *)vif->drv_priv;
  771. if (vif->type != NL80211_IFTYPE_STATION)
  772. return;
  773. if (avp->primary_sta_vif)
  774. ath9k_set_assoc_state(sc, vif);
  775. }
  776. /* Called with sc->mutex held. */
  777. void ath9k_calculate_iter_data(struct ieee80211_hw *hw,
  778. struct ieee80211_vif *vif,
  779. struct ath9k_vif_iter_data *iter_data)
  780. {
  781. struct ath_softc *sc = hw->priv;
  782. struct ath_hw *ah = sc->sc_ah;
  783. struct ath_common *common = ath9k_hw_common(ah);
  784. /*
  785. * Use the hardware MAC address as reference, the hardware uses it
  786. * together with the BSSID mask when matching addresses.
  787. */
  788. memset(iter_data, 0, sizeof(*iter_data));
  789. memset(&iter_data->mask, 0xff, ETH_ALEN);
  790. if (vif)
  791. ath9k_vif_iter(iter_data, vif->addr, vif);
  792. /* Get list of all active MAC addresses */
  793. ieee80211_iterate_active_interfaces_atomic(
  794. sc->hw, IEEE80211_IFACE_ITER_RESUME_ALL,
  795. ath9k_vif_iter, iter_data);
  796. memcpy(common->macaddr, iter_data->hw_macaddr, ETH_ALEN);
  797. }
  798. /* Called with sc->mutex held. */
  799. static void ath9k_calculate_summary_state(struct ieee80211_hw *hw,
  800. struct ieee80211_vif *vif)
  801. {
  802. struct ath_softc *sc = hw->priv;
  803. struct ath_hw *ah = sc->sc_ah;
  804. struct ath_common *common = ath9k_hw_common(ah);
  805. struct ath9k_vif_iter_data iter_data;
  806. enum nl80211_iftype old_opmode = ah->opmode;
  807. ath9k_calculate_iter_data(hw, vif, &iter_data);
  808. memcpy(common->bssidmask, iter_data.mask, ETH_ALEN);
  809. ath_hw_setbssidmask(common);
  810. if (iter_data.naps > 0) {
  811. ath9k_hw_set_tsfadjust(ah, true);
  812. ah->opmode = NL80211_IFTYPE_AP;
  813. } else {
  814. ath9k_hw_set_tsfadjust(ah, false);
  815. if (iter_data.nmeshes)
  816. ah->opmode = NL80211_IFTYPE_MESH_POINT;
  817. else if (iter_data.nwds)
  818. ah->opmode = NL80211_IFTYPE_AP;
  819. else if (iter_data.nadhocs)
  820. ah->opmode = NL80211_IFTYPE_ADHOC;
  821. else
  822. ah->opmode = NL80211_IFTYPE_STATION;
  823. }
  824. ath9k_hw_setopmode(ah);
  825. if ((iter_data.nstations + iter_data.nadhocs + iter_data.nmeshes) > 0)
  826. ah->imask |= ATH9K_INT_TSFOOR;
  827. else
  828. ah->imask &= ~ATH9K_INT_TSFOOR;
  829. ath9k_hw_set_interrupts(ah);
  830. /*
  831. * If we are changing the opmode to STATION,
  832. * a beacon sync needs to be done.
  833. */
  834. if (ah->opmode == NL80211_IFTYPE_STATION &&
  835. old_opmode == NL80211_IFTYPE_AP &&
  836. test_bit(SC_OP_PRIM_STA_VIF, &sc->sc_flags)) {
  837. ieee80211_iterate_active_interfaces_atomic(
  838. sc->hw, IEEE80211_IFACE_ITER_RESUME_ALL,
  839. ath9k_sta_vif_iter, sc);
  840. }
  841. }
  842. static int ath9k_add_interface(struct ieee80211_hw *hw,
  843. struct ieee80211_vif *vif)
  844. {
  845. struct ath_softc *sc = hw->priv;
  846. struct ath_hw *ah = sc->sc_ah;
  847. struct ath_common *common = ath9k_hw_common(ah);
  848. struct ath_vif *avp = (void *)vif->drv_priv;
  849. struct ath_node *an = &avp->mcast_node;
  850. mutex_lock(&sc->mutex);
  851. ath_dbg(common, CONFIG, "Attach a VIF of type: %d\n", vif->type);
  852. sc->nvifs++;
  853. ath9k_ps_wakeup(sc);
  854. ath9k_calculate_summary_state(hw, vif);
  855. ath9k_ps_restore(sc);
  856. if (ath9k_uses_beacons(vif->type))
  857. ath9k_beacon_assign_slot(sc, vif);
  858. an->sc = sc;
  859. an->sta = NULL;
  860. an->vif = vif;
  861. an->no_ps_filter = true;
  862. ath_tx_node_init(sc, an);
  863. mutex_unlock(&sc->mutex);
  864. return 0;
  865. }
  866. static int ath9k_change_interface(struct ieee80211_hw *hw,
  867. struct ieee80211_vif *vif,
  868. enum nl80211_iftype new_type,
  869. bool p2p)
  870. {
  871. struct ath_softc *sc = hw->priv;
  872. struct ath_common *common = ath9k_hw_common(sc->sc_ah);
  873. ath_dbg(common, CONFIG, "Change Interface\n");
  874. mutex_lock(&sc->mutex);
  875. if (ath9k_uses_beacons(vif->type))
  876. ath9k_beacon_remove_slot(sc, vif);
  877. vif->type = new_type;
  878. vif->p2p = p2p;
  879. ath9k_ps_wakeup(sc);
  880. ath9k_calculate_summary_state(hw, vif);
  881. ath9k_ps_restore(sc);
  882. if (ath9k_uses_beacons(vif->type))
  883. ath9k_beacon_assign_slot(sc, vif);
  884. mutex_unlock(&sc->mutex);
  885. return 0;
  886. }
  887. static void ath9k_remove_interface(struct ieee80211_hw *hw,
  888. struct ieee80211_vif *vif)
  889. {
  890. struct ath_softc *sc = hw->priv;
  891. struct ath_common *common = ath9k_hw_common(sc->sc_ah);
  892. struct ath_vif *avp = (void *)vif->drv_priv;
  893. ath_dbg(common, CONFIG, "Detach Interface\n");
  894. mutex_lock(&sc->mutex);
  895. sc->nvifs--;
  896. if (ath9k_uses_beacons(vif->type))
  897. ath9k_beacon_remove_slot(sc, vif);
  898. if (sc->csa_vif == vif)
  899. sc->csa_vif = NULL;
  900. ath9k_ps_wakeup(sc);
  901. ath9k_calculate_summary_state(hw, NULL);
  902. ath9k_ps_restore(sc);
  903. ath_tx_node_cleanup(sc, &avp->mcast_node);
  904. mutex_unlock(&sc->mutex);
  905. }
  906. static void ath9k_enable_ps(struct ath_softc *sc)
  907. {
  908. struct ath_hw *ah = sc->sc_ah;
  909. struct ath_common *common = ath9k_hw_common(ah);
  910. sc->ps_enabled = true;
  911. if (!(ah->caps.hw_caps & ATH9K_HW_CAP_AUTOSLEEP)) {
  912. if ((ah->imask & ATH9K_INT_TIM_TIMER) == 0) {
  913. ah->imask |= ATH9K_INT_TIM_TIMER;
  914. ath9k_hw_set_interrupts(ah);
  915. }
  916. ath9k_hw_setrxabort(ah, 1);
  917. }
  918. ath_dbg(common, PS, "PowerSave enabled\n");
  919. }
  920. static void ath9k_disable_ps(struct ath_softc *sc)
  921. {
  922. struct ath_hw *ah = sc->sc_ah;
  923. struct ath_common *common = ath9k_hw_common(ah);
  924. sc->ps_enabled = false;
  925. ath9k_hw_setpower(ah, ATH9K_PM_AWAKE);
  926. if (!(ah->caps.hw_caps & ATH9K_HW_CAP_AUTOSLEEP)) {
  927. ath9k_hw_setrxabort(ah, 0);
  928. sc->ps_flags &= ~(PS_WAIT_FOR_BEACON |
  929. PS_WAIT_FOR_CAB |
  930. PS_WAIT_FOR_PSPOLL_DATA |
  931. PS_WAIT_FOR_TX_ACK);
  932. if (ah->imask & ATH9K_INT_TIM_TIMER) {
  933. ah->imask &= ~ATH9K_INT_TIM_TIMER;
  934. ath9k_hw_set_interrupts(ah);
  935. }
  936. }
  937. ath_dbg(common, PS, "PowerSave disabled\n");
  938. }
  939. void ath9k_spectral_scan_trigger(struct ieee80211_hw *hw)
  940. {
  941. struct ath_softc *sc = hw->priv;
  942. struct ath_hw *ah = sc->sc_ah;
  943. struct ath_common *common = ath9k_hw_common(ah);
  944. u32 rxfilter;
  945. if (!ath9k_hw_ops(ah)->spectral_scan_trigger) {
  946. ath_err(common, "spectrum analyzer not implemented on this hardware\n");
  947. return;
  948. }
  949. ath9k_ps_wakeup(sc);
  950. rxfilter = ath9k_hw_getrxfilter(ah);
  951. ath9k_hw_setrxfilter(ah, rxfilter |
  952. ATH9K_RX_FILTER_PHYRADAR |
  953. ATH9K_RX_FILTER_PHYERR);
  954. /* TODO: usually this should not be neccesary, but for some reason
  955. * (or in some mode?) the trigger must be called after the
  956. * configuration, otherwise the register will have its values reset
  957. * (on my ar9220 to value 0x01002310)
  958. */
  959. ath9k_spectral_scan_config(hw, sc->spectral_mode);
  960. ath9k_hw_ops(ah)->spectral_scan_trigger(ah);
  961. ath9k_ps_restore(sc);
  962. }
  963. int ath9k_spectral_scan_config(struct ieee80211_hw *hw,
  964. enum spectral_mode spectral_mode)
  965. {
  966. struct ath_softc *sc = hw->priv;
  967. struct ath_hw *ah = sc->sc_ah;
  968. struct ath_common *common = ath9k_hw_common(ah);
  969. if (!ath9k_hw_ops(ah)->spectral_scan_trigger) {
  970. ath_err(common, "spectrum analyzer not implemented on this hardware\n");
  971. return -1;
  972. }
  973. switch (spectral_mode) {
  974. case SPECTRAL_DISABLED:
  975. sc->spec_config.enabled = 0;
  976. break;
  977. case SPECTRAL_BACKGROUND:
  978. /* send endless samples.
  979. * TODO: is this really useful for "background"?
  980. */
  981. sc->spec_config.endless = 1;
  982. sc->spec_config.enabled = 1;
  983. break;
  984. case SPECTRAL_CHANSCAN:
  985. case SPECTRAL_MANUAL:
  986. sc->spec_config.endless = 0;
  987. sc->spec_config.enabled = 1;
  988. break;
  989. default:
  990. return -1;
  991. }
  992. ath9k_ps_wakeup(sc);
  993. ath9k_hw_ops(ah)->spectral_scan_config(ah, &sc->spec_config);
  994. ath9k_ps_restore(sc);
  995. sc->spectral_mode = spectral_mode;
  996. return 0;
  997. }
  998. static int ath9k_config(struct ieee80211_hw *hw, u32 changed)
  999. {
  1000. struct ath_softc *sc = hw->priv;
  1001. struct ath_hw *ah = sc->sc_ah;
  1002. struct ath_common *common = ath9k_hw_common(ah);
  1003. struct ieee80211_conf *conf = &hw->conf;
  1004. bool reset_channel = false;
  1005. ath9k_ps_wakeup(sc);
  1006. mutex_lock(&sc->mutex);
  1007. if (changed & IEEE80211_CONF_CHANGE_IDLE) {
  1008. sc->ps_idle = !!(conf->flags & IEEE80211_CONF_IDLE);
  1009. if (sc->ps_idle) {
  1010. ath_cancel_work(sc);
  1011. ath9k_stop_btcoex(sc);
  1012. } else {
  1013. ath9k_start_btcoex(sc);
  1014. /*
  1015. * The chip needs a reset to properly wake up from
  1016. * full sleep
  1017. */
  1018. reset_channel = ah->chip_fullsleep;
  1019. }
  1020. }
  1021. /*
  1022. * We just prepare to enable PS. We have to wait until our AP has
  1023. * ACK'd our null data frame to disable RX otherwise we'll ignore
  1024. * those ACKs and end up retransmitting the same null data frames.
  1025. * IEEE80211_CONF_CHANGE_PS is only passed by mac80211 for STA mode.
  1026. */
  1027. if (changed & IEEE80211_CONF_CHANGE_PS) {
  1028. unsigned long flags;
  1029. spin_lock_irqsave(&sc->sc_pm_lock, flags);
  1030. if (conf->flags & IEEE80211_CONF_PS)
  1031. ath9k_enable_ps(sc);
  1032. else
  1033. ath9k_disable_ps(sc);
  1034. spin_unlock_irqrestore(&sc->sc_pm_lock, flags);
  1035. }
  1036. if (changed & IEEE80211_CONF_CHANGE_MONITOR) {
  1037. if (conf->flags & IEEE80211_CONF_MONITOR) {
  1038. ath_dbg(common, CONFIG, "Monitor mode is enabled\n");
  1039. sc->sc_ah->is_monitoring = true;
  1040. } else {
  1041. ath_dbg(common, CONFIG, "Monitor mode is disabled\n");
  1042. sc->sc_ah->is_monitoring = false;
  1043. }
  1044. }
  1045. if ((changed & IEEE80211_CONF_CHANGE_CHANNEL) || reset_channel) {
  1046. if (ath_set_channel(sc, &hw->conf.chandef) < 0) {
  1047. ath_err(common, "Unable to set channel\n");
  1048. mutex_unlock(&sc->mutex);
  1049. ath9k_ps_restore(sc);
  1050. return -EINVAL;
  1051. }
  1052. }
  1053. if (changed & IEEE80211_CONF_CHANGE_POWER) {
  1054. ath_dbg(common, CONFIG, "Set power: %d\n", conf->power_level);
  1055. sc->config.txpowlimit = 2 * conf->power_level;
  1056. ath9k_cmn_update_txpow(ah, sc->curtxpow,
  1057. sc->config.txpowlimit, &sc->curtxpow);
  1058. }
  1059. mutex_unlock(&sc->mutex);
  1060. ath9k_ps_restore(sc);
  1061. return 0;
  1062. }
  1063. #define SUPPORTED_FILTERS \
  1064. (FIF_PROMISC_IN_BSS | \
  1065. FIF_ALLMULTI | \
  1066. FIF_CONTROL | \
  1067. FIF_PSPOLL | \
  1068. FIF_OTHER_BSS | \
  1069. FIF_BCN_PRBRESP_PROMISC | \
  1070. FIF_PROBE_REQ | \
  1071. FIF_FCSFAIL)
  1072. /* FIXME: sc->sc_full_reset ? */
  1073. static void ath9k_configure_filter(struct ieee80211_hw *hw,
  1074. unsigned int changed_flags,
  1075. unsigned int *total_flags,
  1076. u64 multicast)
  1077. {
  1078. struct ath_softc *sc = hw->priv;
  1079. u32 rfilt;
  1080. changed_flags &= SUPPORTED_FILTERS;
  1081. *total_flags &= SUPPORTED_FILTERS;
  1082. sc->rx.rxfilter = *total_flags;
  1083. ath9k_ps_wakeup(sc);
  1084. rfilt = ath_calcrxfilter(sc);
  1085. ath9k_hw_setrxfilter(sc->sc_ah, rfilt);
  1086. ath9k_ps_restore(sc);
  1087. ath_dbg(ath9k_hw_common(sc->sc_ah), CONFIG, "Set HW RX filter: 0x%x\n",
  1088. rfilt);
  1089. }
  1090. static int ath9k_sta_add(struct ieee80211_hw *hw,
  1091. struct ieee80211_vif *vif,
  1092. struct ieee80211_sta *sta)
  1093. {
  1094. struct ath_softc *sc = hw->priv;
  1095. struct ath_common *common = ath9k_hw_common(sc->sc_ah);
  1096. struct ath_node *an = (struct ath_node *) sta->drv_priv;
  1097. struct ieee80211_key_conf ps_key = { };
  1098. int key;
  1099. ath_node_attach(sc, sta, vif);
  1100. if (vif->type != NL80211_IFTYPE_AP &&
  1101. vif->type != NL80211_IFTYPE_AP_VLAN)
  1102. return 0;
  1103. key = ath_key_config(common, vif, sta, &ps_key);
  1104. if (key > 0)
  1105. an->ps_key = key;
  1106. return 0;
  1107. }
  1108. static void ath9k_del_ps_key(struct ath_softc *sc,
  1109. struct ieee80211_vif *vif,
  1110. struct ieee80211_sta *sta)
  1111. {
  1112. struct ath_common *common = ath9k_hw_common(sc->sc_ah);
  1113. struct ath_node *an = (struct ath_node *) sta->drv_priv;
  1114. struct ieee80211_key_conf ps_key = { .hw_key_idx = an->ps_key };
  1115. if (!an->ps_key)
  1116. return;
  1117. ath_key_delete(common, &ps_key);
  1118. an->ps_key = 0;
  1119. }
  1120. static int ath9k_sta_remove(struct ieee80211_hw *hw,
  1121. struct ieee80211_vif *vif,
  1122. struct ieee80211_sta *sta)
  1123. {
  1124. struct ath_softc *sc = hw->priv;
  1125. ath9k_del_ps_key(sc, vif, sta);
  1126. ath_node_detach(sc, sta);
  1127. return 0;
  1128. }
  1129. static void ath9k_sta_notify(struct ieee80211_hw *hw,
  1130. struct ieee80211_vif *vif,
  1131. enum sta_notify_cmd cmd,
  1132. struct ieee80211_sta *sta)
  1133. {
  1134. struct ath_softc *sc = hw->priv;
  1135. struct ath_node *an = (struct ath_node *) sta->drv_priv;
  1136. switch (cmd) {
  1137. case STA_NOTIFY_SLEEP:
  1138. an->sleeping = true;
  1139. ath_tx_aggr_sleep(sta, sc, an);
  1140. break;
  1141. case STA_NOTIFY_AWAKE:
  1142. an->sleeping = false;
  1143. ath_tx_aggr_wakeup(sc, an);
  1144. break;
  1145. }
  1146. }
  1147. static int ath9k_conf_tx(struct ieee80211_hw *hw,
  1148. struct ieee80211_vif *vif, u16 queue,
  1149. const struct ieee80211_tx_queue_params *params)
  1150. {
  1151. struct ath_softc *sc = hw->priv;
  1152. struct ath_common *common = ath9k_hw_common(sc->sc_ah);
  1153. struct ath_txq *txq;
  1154. struct ath9k_tx_queue_info qi;
  1155. int ret = 0;
  1156. if (queue >= IEEE80211_NUM_ACS)
  1157. return 0;
  1158. txq = sc->tx.txq_map[queue];
  1159. ath9k_ps_wakeup(sc);
  1160. mutex_lock(&sc->mutex);
  1161. memset(&qi, 0, sizeof(struct ath9k_tx_queue_info));
  1162. qi.tqi_aifs = params->aifs;
  1163. qi.tqi_cwmin = params->cw_min;
  1164. qi.tqi_cwmax = params->cw_max;
  1165. qi.tqi_burstTime = params->txop * 32;
  1166. ath_dbg(common, CONFIG,
  1167. "Configure tx [queue/halq] [%d/%d], aifs: %d, cw_min: %d, cw_max: %d, txop: %d\n",
  1168. queue, txq->axq_qnum, params->aifs, params->cw_min,
  1169. params->cw_max, params->txop);
  1170. ath_update_max_aggr_framelen(sc, queue, qi.tqi_burstTime);
  1171. ret = ath_txq_update(sc, txq->axq_qnum, &qi);
  1172. if (ret)
  1173. ath_err(common, "TXQ Update failed\n");
  1174. mutex_unlock(&sc->mutex);
  1175. ath9k_ps_restore(sc);
  1176. return ret;
  1177. }
  1178. static int ath9k_set_key(struct ieee80211_hw *hw,
  1179. enum set_key_cmd cmd,
  1180. struct ieee80211_vif *vif,
  1181. struct ieee80211_sta *sta,
  1182. struct ieee80211_key_conf *key)
  1183. {
  1184. struct ath_softc *sc = hw->priv;
  1185. struct ath_common *common = ath9k_hw_common(sc->sc_ah);
  1186. int ret = 0;
  1187. if (ath9k_modparam_nohwcrypt)
  1188. return -ENOSPC;
  1189. if ((vif->type == NL80211_IFTYPE_ADHOC ||
  1190. vif->type == NL80211_IFTYPE_MESH_POINT) &&
  1191. (key->cipher == WLAN_CIPHER_SUITE_TKIP ||
  1192. key->cipher == WLAN_CIPHER_SUITE_CCMP) &&
  1193. !(key->flags & IEEE80211_KEY_FLAG_PAIRWISE)) {
  1194. /*
  1195. * For now, disable hw crypto for the RSN IBSS group keys. This
  1196. * could be optimized in the future to use a modified key cache
  1197. * design to support per-STA RX GTK, but until that gets
  1198. * implemented, use of software crypto for group addressed
  1199. * frames is a acceptable to allow RSN IBSS to be used.
  1200. */
  1201. return -EOPNOTSUPP;
  1202. }
  1203. mutex_lock(&sc->mutex);
  1204. ath9k_ps_wakeup(sc);
  1205. ath_dbg(common, CONFIG, "Set HW Key\n");
  1206. switch (cmd) {
  1207. case SET_KEY:
  1208. if (sta)
  1209. ath9k_del_ps_key(sc, vif, sta);
  1210. ret = ath_key_config(common, vif, sta, key);
  1211. if (ret >= 0) {
  1212. key->hw_key_idx = ret;
  1213. /* push IV and Michael MIC generation to stack */
  1214. key->flags |= IEEE80211_KEY_FLAG_GENERATE_IV;
  1215. if (key->cipher == WLAN_CIPHER_SUITE_TKIP)
  1216. key->flags |= IEEE80211_KEY_FLAG_GENERATE_MMIC;
  1217. if (sc->sc_ah->sw_mgmt_crypto &&
  1218. key->cipher == WLAN_CIPHER_SUITE_CCMP)
  1219. key->flags |= IEEE80211_KEY_FLAG_SW_MGMT_TX;
  1220. ret = 0;
  1221. }
  1222. break;
  1223. case DISABLE_KEY:
  1224. ath_key_delete(common, key);
  1225. break;
  1226. default:
  1227. ret = -EINVAL;
  1228. }
  1229. ath9k_ps_restore(sc);
  1230. mutex_unlock(&sc->mutex);
  1231. return ret;
  1232. }
  1233. static void ath9k_set_assoc_state(struct ath_softc *sc,
  1234. struct ieee80211_vif *vif)
  1235. {
  1236. struct ath_common *common = ath9k_hw_common(sc->sc_ah);
  1237. struct ath_vif *avp = (void *)vif->drv_priv;
  1238. struct ieee80211_bss_conf *bss_conf = &vif->bss_conf;
  1239. unsigned long flags;
  1240. set_bit(SC_OP_PRIM_STA_VIF, &sc->sc_flags);
  1241. avp->primary_sta_vif = true;
  1242. /*
  1243. * Set the AID, BSSID and do beacon-sync only when
  1244. * the HW opmode is STATION.
  1245. *
  1246. * But the primary bit is set above in any case.
  1247. */
  1248. if (sc->sc_ah->opmode != NL80211_IFTYPE_STATION)
  1249. return;
  1250. memcpy(common->curbssid, bss_conf->bssid, ETH_ALEN);
  1251. common->curaid = bss_conf->aid;
  1252. ath9k_hw_write_associd(sc->sc_ah);
  1253. sc->last_rssi = ATH_RSSI_DUMMY_MARKER;
  1254. sc->sc_ah->stats.avgbrssi = ATH_RSSI_DUMMY_MARKER;
  1255. spin_lock_irqsave(&sc->sc_pm_lock, flags);
  1256. sc->ps_flags |= PS_BEACON_SYNC | PS_WAIT_FOR_BEACON;
  1257. spin_unlock_irqrestore(&sc->sc_pm_lock, flags);
  1258. if (ath9k_hw_mci_is_enabled(sc->sc_ah))
  1259. ath9k_mci_update_wlan_channels(sc, false);
  1260. ath_dbg(common, CONFIG,
  1261. "Primary Station interface: %pM, BSSID: %pM\n",
  1262. vif->addr, common->curbssid);
  1263. }
  1264. static void ath9k_bss_assoc_iter(void *data, u8 *mac, struct ieee80211_vif *vif)
  1265. {
  1266. struct ath_softc *sc = data;
  1267. struct ieee80211_bss_conf *bss_conf = &vif->bss_conf;
  1268. if (test_bit(SC_OP_PRIM_STA_VIF, &sc->sc_flags))
  1269. return;
  1270. if (bss_conf->assoc)
  1271. ath9k_set_assoc_state(sc, vif);
  1272. }
  1273. static void ath9k_bss_info_changed(struct ieee80211_hw *hw,
  1274. struct ieee80211_vif *vif,
  1275. struct ieee80211_bss_conf *bss_conf,
  1276. u32 changed)
  1277. {
  1278. #define CHECK_ANI \
  1279. (BSS_CHANGED_ASSOC | \
  1280. BSS_CHANGED_IBSS | \
  1281. BSS_CHANGED_BEACON_ENABLED)
  1282. struct ath_softc *sc = hw->priv;
  1283. struct ath_hw *ah = sc->sc_ah;
  1284. struct ath_common *common = ath9k_hw_common(ah);
  1285. struct ath_vif *avp = (void *)vif->drv_priv;
  1286. int slottime;
  1287. ath9k_ps_wakeup(sc);
  1288. mutex_lock(&sc->mutex);
  1289. if (changed & BSS_CHANGED_ASSOC) {
  1290. ath_dbg(common, CONFIG, "BSSID %pM Changed ASSOC %d\n",
  1291. bss_conf->bssid, bss_conf->assoc);
  1292. if (avp->primary_sta_vif && !bss_conf->assoc) {
  1293. clear_bit(SC_OP_PRIM_STA_VIF, &sc->sc_flags);
  1294. avp->primary_sta_vif = false;
  1295. if (ah->opmode == NL80211_IFTYPE_STATION)
  1296. clear_bit(SC_OP_BEACONS, &sc->sc_flags);
  1297. }
  1298. ieee80211_iterate_active_interfaces_atomic(
  1299. sc->hw, IEEE80211_IFACE_ITER_RESUME_ALL,
  1300. ath9k_bss_assoc_iter, sc);
  1301. if (!test_bit(SC_OP_PRIM_STA_VIF, &sc->sc_flags) &&
  1302. ah->opmode == NL80211_IFTYPE_STATION) {
  1303. memset(common->curbssid, 0, ETH_ALEN);
  1304. common->curaid = 0;
  1305. ath9k_hw_write_associd(sc->sc_ah);
  1306. if (ath9k_hw_mci_is_enabled(sc->sc_ah))
  1307. ath9k_mci_update_wlan_channels(sc, true);
  1308. }
  1309. }
  1310. if (changed & BSS_CHANGED_IBSS) {
  1311. memcpy(common->curbssid, bss_conf->bssid, ETH_ALEN);
  1312. common->curaid = bss_conf->aid;
  1313. ath9k_hw_write_associd(sc->sc_ah);
  1314. }
  1315. if ((changed & BSS_CHANGED_BEACON_ENABLED) ||
  1316. (changed & BSS_CHANGED_BEACON_INT)) {
  1317. if (ah->opmode == NL80211_IFTYPE_AP &&
  1318. bss_conf->enable_beacon)
  1319. ath9k_set_tsfadjust(sc, vif);
  1320. if (ath9k_allow_beacon_config(sc, vif))
  1321. ath9k_beacon_config(sc, vif, changed);
  1322. }
  1323. if (changed & BSS_CHANGED_ERP_SLOT) {
  1324. if (bss_conf->use_short_slot)
  1325. slottime = 9;
  1326. else
  1327. slottime = 20;
  1328. if (vif->type == NL80211_IFTYPE_AP) {
  1329. /*
  1330. * Defer update, so that connected stations can adjust
  1331. * their settings at the same time.
  1332. * See beacon.c for more details
  1333. */
  1334. sc->beacon.slottime = slottime;
  1335. sc->beacon.updateslot = UPDATE;
  1336. } else {
  1337. ah->slottime = slottime;
  1338. ath9k_hw_init_global_settings(ah);
  1339. }
  1340. }
  1341. if (changed & CHECK_ANI)
  1342. ath_check_ani(sc);
  1343. mutex_unlock(&sc->mutex);
  1344. ath9k_ps_restore(sc);
  1345. #undef CHECK_ANI
  1346. }
  1347. static u64 ath9k_get_tsf(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
  1348. {
  1349. struct ath_softc *sc = hw->priv;
  1350. u64 tsf;
  1351. mutex_lock(&sc->mutex);
  1352. ath9k_ps_wakeup(sc);
  1353. tsf = ath9k_hw_gettsf64(sc->sc_ah);
  1354. ath9k_ps_restore(sc);
  1355. mutex_unlock(&sc->mutex);
  1356. return tsf;
  1357. }
  1358. static void ath9k_set_tsf(struct ieee80211_hw *hw,
  1359. struct ieee80211_vif *vif,
  1360. u64 tsf)
  1361. {
  1362. struct ath_softc *sc = hw->priv;
  1363. mutex_lock(&sc->mutex);
  1364. ath9k_ps_wakeup(sc);
  1365. ath9k_hw_settsf64(sc->sc_ah, tsf);
  1366. ath9k_ps_restore(sc);
  1367. mutex_unlock(&sc->mutex);
  1368. }
  1369. static void ath9k_reset_tsf(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
  1370. {
  1371. struct ath_softc *sc = hw->priv;
  1372. mutex_lock(&sc->mutex);
  1373. ath9k_ps_wakeup(sc);
  1374. ath9k_hw_reset_tsf(sc->sc_ah);
  1375. ath9k_ps_restore(sc);
  1376. mutex_unlock(&sc->mutex);
  1377. }
  1378. static int ath9k_ampdu_action(struct ieee80211_hw *hw,
  1379. struct ieee80211_vif *vif,
  1380. enum ieee80211_ampdu_mlme_action action,
  1381. struct ieee80211_sta *sta,
  1382. u16 tid, u16 *ssn, u8 buf_size)
  1383. {
  1384. struct ath_softc *sc = hw->priv;
  1385. bool flush = false;
  1386. int ret = 0;
  1387. mutex_lock(&sc->mutex);
  1388. switch (action) {
  1389. case IEEE80211_AMPDU_RX_START:
  1390. break;
  1391. case IEEE80211_AMPDU_RX_STOP:
  1392. break;
  1393. case IEEE80211_AMPDU_TX_START:
  1394. ath9k_ps_wakeup(sc);
  1395. ret = ath_tx_aggr_start(sc, sta, tid, ssn);
  1396. if (!ret)
  1397. ieee80211_start_tx_ba_cb_irqsafe(vif, sta->addr, tid);
  1398. ath9k_ps_restore(sc);
  1399. break;
  1400. case IEEE80211_AMPDU_TX_STOP_FLUSH:
  1401. case IEEE80211_AMPDU_TX_STOP_FLUSH_CONT:
  1402. flush = true;
  1403. case IEEE80211_AMPDU_TX_STOP_CONT:
  1404. ath9k_ps_wakeup(sc);
  1405. ath_tx_aggr_stop(sc, sta, tid);
  1406. if (!flush)
  1407. ieee80211_stop_tx_ba_cb_irqsafe(vif, sta->addr, tid);
  1408. ath9k_ps_restore(sc);
  1409. break;
  1410. case IEEE80211_AMPDU_TX_OPERATIONAL:
  1411. ath9k_ps_wakeup(sc);
  1412. ath_tx_aggr_resume(sc, sta, tid);
  1413. ath9k_ps_restore(sc);
  1414. break;
  1415. default:
  1416. ath_err(ath9k_hw_common(sc->sc_ah), "Unknown AMPDU action\n");
  1417. }
  1418. mutex_unlock(&sc->mutex);
  1419. return ret;
  1420. }
  1421. static int ath9k_get_survey(struct ieee80211_hw *hw, int idx,
  1422. struct survey_info *survey)
  1423. {
  1424. struct ath_softc *sc = hw->priv;
  1425. struct ath_common *common = ath9k_hw_common(sc->sc_ah);
  1426. struct ieee80211_supported_band *sband;
  1427. struct ieee80211_channel *chan;
  1428. unsigned long flags;
  1429. int pos;
  1430. spin_lock_irqsave(&common->cc_lock, flags);
  1431. if (idx == 0)
  1432. ath_update_survey_stats(sc);
  1433. sband = hw->wiphy->bands[IEEE80211_BAND_2GHZ];
  1434. if (sband && idx >= sband->n_channels) {
  1435. idx -= sband->n_channels;
  1436. sband = NULL;
  1437. }
  1438. if (!sband)
  1439. sband = hw->wiphy->bands[IEEE80211_BAND_5GHZ];
  1440. if (!sband || idx >= sband->n_channels) {
  1441. spin_unlock_irqrestore(&common->cc_lock, flags);
  1442. return -ENOENT;
  1443. }
  1444. chan = &sband->channels[idx];
  1445. pos = chan->hw_value;
  1446. memcpy(survey, &sc->survey[pos], sizeof(*survey));
  1447. survey->channel = chan;
  1448. spin_unlock_irqrestore(&common->cc_lock, flags);
  1449. return 0;
  1450. }
  1451. static void ath9k_set_coverage_class(struct ieee80211_hw *hw, u8 coverage_class)
  1452. {
  1453. struct ath_softc *sc = hw->priv;
  1454. struct ath_hw *ah = sc->sc_ah;
  1455. mutex_lock(&sc->mutex);
  1456. ah->coverage_class = coverage_class;
  1457. ath9k_ps_wakeup(sc);
  1458. ath9k_hw_init_global_settings(ah);
  1459. ath9k_ps_restore(sc);
  1460. mutex_unlock(&sc->mutex);
  1461. }
  1462. static void ath9k_flush(struct ieee80211_hw *hw, u32 queues, bool drop)
  1463. {
  1464. struct ath_softc *sc = hw->priv;
  1465. struct ath_hw *ah = sc->sc_ah;
  1466. struct ath_common *common = ath9k_hw_common(ah);
  1467. int timeout = 200; /* ms */
  1468. int i, j;
  1469. bool drain_txq;
  1470. mutex_lock(&sc->mutex);
  1471. cancel_delayed_work_sync(&sc->tx_complete_work);
  1472. if (ah->ah_flags & AH_UNPLUGGED) {
  1473. ath_dbg(common, ANY, "Device has been unplugged!\n");
  1474. mutex_unlock(&sc->mutex);
  1475. return;
  1476. }
  1477. if (test_bit(SC_OP_INVALID, &sc->sc_flags)) {
  1478. ath_dbg(common, ANY, "Device not present\n");
  1479. mutex_unlock(&sc->mutex);
  1480. return;
  1481. }
  1482. for (j = 0; j < timeout; j++) {
  1483. bool npend = false;
  1484. if (j)
  1485. usleep_range(1000, 2000);
  1486. for (i = 0; i < ATH9K_NUM_TX_QUEUES; i++) {
  1487. if (!ATH_TXQ_SETUP(sc, i))
  1488. continue;
  1489. npend = ath9k_has_pending_frames(sc, &sc->tx.txq[i]);
  1490. if (npend)
  1491. break;
  1492. }
  1493. if (!npend)
  1494. break;
  1495. }
  1496. if (drop) {
  1497. ath9k_ps_wakeup(sc);
  1498. spin_lock_bh(&sc->sc_pcu_lock);
  1499. drain_txq = ath_drain_all_txq(sc);
  1500. spin_unlock_bh(&sc->sc_pcu_lock);
  1501. if (!drain_txq)
  1502. ath_reset(sc);
  1503. ath9k_ps_restore(sc);
  1504. ieee80211_wake_queues(hw);
  1505. }
  1506. ieee80211_queue_delayed_work(hw, &sc->tx_complete_work, 0);
  1507. mutex_unlock(&sc->mutex);
  1508. }
  1509. static bool ath9k_tx_frames_pending(struct ieee80211_hw *hw)
  1510. {
  1511. struct ath_softc *sc = hw->priv;
  1512. int i;
  1513. for (i = 0; i < ATH9K_NUM_TX_QUEUES; i++) {
  1514. if (!ATH_TXQ_SETUP(sc, i))
  1515. continue;
  1516. if (ath9k_has_pending_frames(sc, &sc->tx.txq[i]))
  1517. return true;
  1518. }
  1519. return false;
  1520. }
  1521. static int ath9k_tx_last_beacon(struct ieee80211_hw *hw)
  1522. {
  1523. struct ath_softc *sc = hw->priv;
  1524. struct ath_hw *ah = sc->sc_ah;
  1525. struct ieee80211_vif *vif;
  1526. struct ath_vif *avp;
  1527. struct ath_buf *bf;
  1528. struct ath_tx_status ts;
  1529. bool edma = !!(ah->caps.hw_caps & ATH9K_HW_CAP_EDMA);
  1530. int status;
  1531. vif = sc->beacon.bslot[0];
  1532. if (!vif)
  1533. return 0;
  1534. if (!vif->bss_conf.enable_beacon)
  1535. return 0;
  1536. avp = (void *)vif->drv_priv;
  1537. if (!sc->beacon.tx_processed && !edma) {
  1538. tasklet_disable(&sc->bcon_tasklet);
  1539. bf = avp->av_bcbuf;
  1540. if (!bf || !bf->bf_mpdu)
  1541. goto skip;
  1542. status = ath9k_hw_txprocdesc(ah, bf->bf_desc, &ts);
  1543. if (status == -EINPROGRESS)
  1544. goto skip;
  1545. sc->beacon.tx_processed = true;
  1546. sc->beacon.tx_last = !(ts.ts_status & ATH9K_TXERR_MASK);
  1547. skip:
  1548. tasklet_enable(&sc->bcon_tasklet);
  1549. }
  1550. return sc->beacon.tx_last;
  1551. }
  1552. static int ath9k_get_stats(struct ieee80211_hw *hw,
  1553. struct ieee80211_low_level_stats *stats)
  1554. {
  1555. struct ath_softc *sc = hw->priv;
  1556. struct ath_hw *ah = sc->sc_ah;
  1557. struct ath9k_mib_stats *mib_stats = &ah->ah_mibStats;
  1558. stats->dot11ACKFailureCount = mib_stats->ackrcv_bad;
  1559. stats->dot11RTSFailureCount = mib_stats->rts_bad;
  1560. stats->dot11FCSErrorCount = mib_stats->fcs_bad;
  1561. stats->dot11RTSSuccessCount = mib_stats->rts_good;
  1562. return 0;
  1563. }
  1564. static u32 fill_chainmask(u32 cap, u32 new)
  1565. {
  1566. u32 filled = 0;
  1567. int i;
  1568. for (i = 0; cap && new; i++, cap >>= 1) {
  1569. if (!(cap & BIT(0)))
  1570. continue;
  1571. if (new & BIT(0))
  1572. filled |= BIT(i);
  1573. new >>= 1;
  1574. }
  1575. return filled;
  1576. }
  1577. static bool validate_antenna_mask(struct ath_hw *ah, u32 val)
  1578. {
  1579. if (AR_SREV_9300_20_OR_LATER(ah))
  1580. return true;
  1581. switch (val & 0x7) {
  1582. case 0x1:
  1583. case 0x3:
  1584. case 0x7:
  1585. return true;
  1586. case 0x2:
  1587. return (ah->caps.rx_chainmask == 1);
  1588. default:
  1589. return false;
  1590. }
  1591. }
  1592. static int ath9k_set_antenna(struct ieee80211_hw *hw, u32 tx_ant, u32 rx_ant)
  1593. {
  1594. struct ath_softc *sc = hw->priv;
  1595. struct ath_hw *ah = sc->sc_ah;
  1596. if (ah->caps.rx_chainmask != 1)
  1597. rx_ant |= tx_ant;
  1598. if (!validate_antenna_mask(ah, rx_ant) || !tx_ant)
  1599. return -EINVAL;
  1600. sc->ant_rx = rx_ant;
  1601. sc->ant_tx = tx_ant;
  1602. if (ah->caps.rx_chainmask == 1)
  1603. return 0;
  1604. /* AR9100 runs into calibration issues if not all rx chains are enabled */
  1605. if (AR_SREV_9100(ah))
  1606. ah->rxchainmask = 0x7;
  1607. else
  1608. ah->rxchainmask = fill_chainmask(ah->caps.rx_chainmask, rx_ant);
  1609. ah->txchainmask = fill_chainmask(ah->caps.tx_chainmask, tx_ant);
  1610. ath9k_reload_chainmask_settings(sc);
  1611. return 0;
  1612. }
  1613. static int ath9k_get_antenna(struct ieee80211_hw *hw, u32 *tx_ant, u32 *rx_ant)
  1614. {
  1615. struct ath_softc *sc = hw->priv;
  1616. *tx_ant = sc->ant_tx;
  1617. *rx_ant = sc->ant_rx;
  1618. return 0;
  1619. }
  1620. #ifdef CONFIG_PM_SLEEP
  1621. static void ath9k_wow_map_triggers(struct ath_softc *sc,
  1622. struct cfg80211_wowlan *wowlan,
  1623. u32 *wow_triggers)
  1624. {
  1625. if (wowlan->disconnect)
  1626. *wow_triggers |= AH_WOW_LINK_CHANGE |
  1627. AH_WOW_BEACON_MISS;
  1628. if (wowlan->magic_pkt)
  1629. *wow_triggers |= AH_WOW_MAGIC_PATTERN_EN;
  1630. if (wowlan->n_patterns)
  1631. *wow_triggers |= AH_WOW_USER_PATTERN_EN;
  1632. sc->wow_enabled = *wow_triggers;
  1633. }
  1634. static void ath9k_wow_add_disassoc_deauth_pattern(struct ath_softc *sc)
  1635. {
  1636. struct ath_hw *ah = sc->sc_ah;
  1637. struct ath_common *common = ath9k_hw_common(ah);
  1638. int pattern_count = 0;
  1639. int i, byte_cnt;
  1640. u8 dis_deauth_pattern[MAX_PATTERN_SIZE];
  1641. u8 dis_deauth_mask[MAX_PATTERN_SIZE];
  1642. memset(dis_deauth_pattern, 0, MAX_PATTERN_SIZE);
  1643. memset(dis_deauth_mask, 0, MAX_PATTERN_SIZE);
  1644. /*
  1645. * Create Dissassociate / Deauthenticate packet filter
  1646. *
  1647. * 2 bytes 2 byte 6 bytes 6 bytes 6 bytes
  1648. * +--------------+----------+---------+--------+--------+----
  1649. * + Frame Control+ Duration + DA + SA + BSSID +
  1650. * +--------------+----------+---------+--------+--------+----
  1651. *
  1652. * The above is the management frame format for disassociate/
  1653. * deauthenticate pattern, from this we need to match the first byte
  1654. * of 'Frame Control' and DA, SA, and BSSID fields
  1655. * (skipping 2nd byte of FC and Duration feild.
  1656. *
  1657. * Disassociate pattern
  1658. * --------------------
  1659. * Frame control = 00 00 1010
  1660. * DA, SA, BSSID = x:x:x:x:x:x
  1661. * Pattern will be A0000000 | x:x:x:x:x:x | x:x:x:x:x:x
  1662. * | x:x:x:x:x:x -- 22 bytes
  1663. *
  1664. * Deauthenticate pattern
  1665. * ----------------------
  1666. * Frame control = 00 00 1100
  1667. * DA, SA, BSSID = x:x:x:x:x:x
  1668. * Pattern will be C0000000 | x:x:x:x:x:x | x:x:x:x:x:x
  1669. * | x:x:x:x:x:x -- 22 bytes
  1670. */
  1671. /* Create Disassociate Pattern first */
  1672. byte_cnt = 0;
  1673. /* Fill out the mask with all FF's */
  1674. for (i = 0; i < MAX_PATTERN_MASK_SIZE; i++)
  1675. dis_deauth_mask[i] = 0xff;
  1676. /* copy the first byte of frame control field */
  1677. dis_deauth_pattern[byte_cnt] = 0xa0;
  1678. byte_cnt++;
  1679. /* skip 2nd byte of frame control and Duration field */
  1680. byte_cnt += 3;
  1681. /*
  1682. * need not match the destination mac address, it can be a broadcast
  1683. * mac address or an unicast to this station
  1684. */
  1685. byte_cnt += 6;
  1686. /* copy the source mac address */
  1687. memcpy((dis_deauth_pattern + byte_cnt), common->curbssid, ETH_ALEN);
  1688. byte_cnt += 6;
  1689. /* copy the bssid, its same as the source mac address */
  1690. memcpy((dis_deauth_pattern + byte_cnt), common->curbssid, ETH_ALEN);
  1691. /* Create Disassociate pattern mask */
  1692. dis_deauth_mask[0] = 0xfe;
  1693. dis_deauth_mask[1] = 0x03;
  1694. dis_deauth_mask[2] = 0xc0;
  1695. ath_dbg(common, WOW, "Adding disassoc/deauth patterns for WoW\n");
  1696. ath9k_hw_wow_apply_pattern(ah, dis_deauth_pattern, dis_deauth_mask,
  1697. pattern_count, byte_cnt);
  1698. pattern_count++;
  1699. /*
  1700. * for de-authenticate pattern, only the first byte of the frame
  1701. * control field gets changed from 0xA0 to 0xC0
  1702. */
  1703. dis_deauth_pattern[0] = 0xC0;
  1704. ath9k_hw_wow_apply_pattern(ah, dis_deauth_pattern, dis_deauth_mask,
  1705. pattern_count, byte_cnt);
  1706. }
  1707. static void ath9k_wow_add_pattern(struct ath_softc *sc,
  1708. struct cfg80211_wowlan *wowlan)
  1709. {
  1710. struct ath_hw *ah = sc->sc_ah;
  1711. struct ath9k_wow_pattern *wow_pattern = NULL;
  1712. struct cfg80211_pkt_pattern *patterns = wowlan->patterns;
  1713. int mask_len;
  1714. s8 i = 0;
  1715. if (!wowlan->n_patterns)
  1716. return;
  1717. /*
  1718. * Add the new user configured patterns
  1719. */
  1720. for (i = 0; i < wowlan->n_patterns; i++) {
  1721. wow_pattern = kzalloc(sizeof(*wow_pattern), GFP_KERNEL);
  1722. if (!wow_pattern)
  1723. return;
  1724. /*
  1725. * TODO: convert the generic user space pattern to
  1726. * appropriate chip specific/802.11 pattern.
  1727. */
  1728. mask_len = DIV_ROUND_UP(wowlan->patterns[i].pattern_len, 8);
  1729. memset(wow_pattern->pattern_bytes, 0, MAX_PATTERN_SIZE);
  1730. memset(wow_pattern->mask_bytes, 0, MAX_PATTERN_SIZE);
  1731. memcpy(wow_pattern->pattern_bytes, patterns[i].pattern,
  1732. patterns[i].pattern_len);
  1733. memcpy(wow_pattern->mask_bytes, patterns[i].mask, mask_len);
  1734. wow_pattern->pattern_len = patterns[i].pattern_len;
  1735. /*
  1736. * just need to take care of deauth and disssoc pattern,
  1737. * make sure we don't overwrite them.
  1738. */
  1739. ath9k_hw_wow_apply_pattern(ah, wow_pattern->pattern_bytes,
  1740. wow_pattern->mask_bytes,
  1741. i + 2,
  1742. wow_pattern->pattern_len);
  1743. kfree(wow_pattern);
  1744. }
  1745. }
  1746. static int ath9k_suspend(struct ieee80211_hw *hw,
  1747. struct cfg80211_wowlan *wowlan)
  1748. {
  1749. struct ath_softc *sc = hw->priv;
  1750. struct ath_hw *ah = sc->sc_ah;
  1751. struct ath_common *common = ath9k_hw_common(ah);
  1752. u32 wow_triggers_enabled = 0;
  1753. int ret = 0;
  1754. mutex_lock(&sc->mutex);
  1755. ath_cancel_work(sc);
  1756. ath_stop_ani(sc);
  1757. del_timer_sync(&sc->rx_poll_timer);
  1758. if (test_bit(SC_OP_INVALID, &sc->sc_flags)) {
  1759. ath_dbg(common, ANY, "Device not present\n");
  1760. ret = -EINVAL;
  1761. goto fail_wow;
  1762. }
  1763. if (WARN_ON(!wowlan)) {
  1764. ath_dbg(common, WOW, "None of the WoW triggers enabled\n");
  1765. ret = -EINVAL;
  1766. goto fail_wow;
  1767. }
  1768. if (!device_can_wakeup(sc->dev)) {
  1769. ath_dbg(common, WOW, "device_can_wakeup failed, WoW is not enabled\n");
  1770. ret = 1;
  1771. goto fail_wow;
  1772. }
  1773. /*
  1774. * none of the sta vifs are associated
  1775. * and we are not currently handling multivif
  1776. * cases, for instance we have to seperately
  1777. * configure 'keep alive frame' for each
  1778. * STA.
  1779. */
  1780. if (!test_bit(SC_OP_PRIM_STA_VIF, &sc->sc_flags)) {
  1781. ath_dbg(common, WOW, "None of the STA vifs are associated\n");
  1782. ret = 1;
  1783. goto fail_wow;
  1784. }
  1785. if (sc->nvifs > 1) {
  1786. ath_dbg(common, WOW, "WoW for multivif is not yet supported\n");
  1787. ret = 1;
  1788. goto fail_wow;
  1789. }
  1790. ath9k_wow_map_triggers(sc, wowlan, &wow_triggers_enabled);
  1791. ath_dbg(common, WOW, "WoW triggers enabled 0x%x\n",
  1792. wow_triggers_enabled);
  1793. ath9k_ps_wakeup(sc);
  1794. ath9k_stop_btcoex(sc);
  1795. /*
  1796. * Enable wake up on recieving disassoc/deauth
  1797. * frame by default.
  1798. */
  1799. ath9k_wow_add_disassoc_deauth_pattern(sc);
  1800. if (wow_triggers_enabled & AH_WOW_USER_PATTERN_EN)
  1801. ath9k_wow_add_pattern(sc, wowlan);
  1802. spin_lock_bh(&sc->sc_pcu_lock);
  1803. /*
  1804. * To avoid false wake, we enable beacon miss interrupt only
  1805. * when we go to sleep. We save the current interrupt mask
  1806. * so we can restore it after the system wakes up
  1807. */
  1808. sc->wow_intr_before_sleep = ah->imask;
  1809. ah->imask &= ~ATH9K_INT_GLOBAL;
  1810. ath9k_hw_disable_interrupts(ah);
  1811. ah->imask = ATH9K_INT_BMISS | ATH9K_INT_GLOBAL;
  1812. ath9k_hw_set_interrupts(ah);
  1813. ath9k_hw_enable_interrupts(ah);
  1814. spin_unlock_bh(&sc->sc_pcu_lock);
  1815. /*
  1816. * we can now sync irq and kill any running tasklets, since we already
  1817. * disabled interrupts and not holding a spin lock
  1818. */
  1819. synchronize_irq(sc->irq);
  1820. tasklet_kill(&sc->intr_tq);
  1821. ath9k_hw_wow_enable(ah, wow_triggers_enabled);
  1822. ath9k_ps_restore(sc);
  1823. ath_dbg(common, ANY, "WoW enabled in ath9k\n");
  1824. atomic_inc(&sc->wow_sleep_proc_intr);
  1825. fail_wow:
  1826. mutex_unlock(&sc->mutex);
  1827. return ret;
  1828. }
  1829. static int ath9k_resume(struct ieee80211_hw *hw)
  1830. {
  1831. struct ath_softc *sc = hw->priv;
  1832. struct ath_hw *ah = sc->sc_ah;
  1833. struct ath_common *common = ath9k_hw_common(ah);
  1834. u32 wow_status;
  1835. mutex_lock(&sc->mutex);
  1836. ath9k_ps_wakeup(sc);
  1837. spin_lock_bh(&sc->sc_pcu_lock);
  1838. ath9k_hw_disable_interrupts(ah);
  1839. ah->imask = sc->wow_intr_before_sleep;
  1840. ath9k_hw_set_interrupts(ah);
  1841. ath9k_hw_enable_interrupts(ah);
  1842. spin_unlock_bh(&sc->sc_pcu_lock);
  1843. wow_status = ath9k_hw_wow_wakeup(ah);
  1844. if (atomic_read(&sc->wow_got_bmiss_intr) == 0) {
  1845. /*
  1846. * some devices may not pick beacon miss
  1847. * as the reason they woke up so we add
  1848. * that here for that shortcoming.
  1849. */
  1850. wow_status |= AH_WOW_BEACON_MISS;
  1851. atomic_dec(&sc->wow_got_bmiss_intr);
  1852. ath_dbg(common, ANY, "Beacon miss interrupt picked up during WoW sleep\n");
  1853. }
  1854. atomic_dec(&sc->wow_sleep_proc_intr);
  1855. if (wow_status) {
  1856. ath_dbg(common, ANY, "Waking up due to WoW triggers %s with WoW status = %x\n",
  1857. ath9k_hw_wow_event_to_string(wow_status), wow_status);
  1858. }
  1859. ath_restart_work(sc);
  1860. ath9k_start_btcoex(sc);
  1861. ath9k_ps_restore(sc);
  1862. mutex_unlock(&sc->mutex);
  1863. return 0;
  1864. }
  1865. static void ath9k_set_wakeup(struct ieee80211_hw *hw, bool enabled)
  1866. {
  1867. struct ath_softc *sc = hw->priv;
  1868. mutex_lock(&sc->mutex);
  1869. device_init_wakeup(sc->dev, 1);
  1870. device_set_wakeup_enable(sc->dev, enabled);
  1871. mutex_unlock(&sc->mutex);
  1872. }
  1873. #endif
  1874. static void ath9k_sw_scan_start(struct ieee80211_hw *hw)
  1875. {
  1876. struct ath_softc *sc = hw->priv;
  1877. set_bit(SC_OP_SCANNING, &sc->sc_flags);
  1878. }
  1879. static void ath9k_sw_scan_complete(struct ieee80211_hw *hw)
  1880. {
  1881. struct ath_softc *sc = hw->priv;
  1882. clear_bit(SC_OP_SCANNING, &sc->sc_flags);
  1883. }
  1884. static void ath9k_channel_switch_beacon(struct ieee80211_hw *hw,
  1885. struct ieee80211_vif *vif,
  1886. struct cfg80211_chan_def *chandef)
  1887. {
  1888. struct ath_softc *sc = hw->priv;
  1889. /* mac80211 does not support CSA in multi-if cases (yet) */
  1890. if (WARN_ON(sc->csa_vif))
  1891. return;
  1892. sc->csa_vif = vif;
  1893. }
  1894. struct ieee80211_ops ath9k_ops = {
  1895. .tx = ath9k_tx,
  1896. .start = ath9k_start,
  1897. .stop = ath9k_stop,
  1898. .add_interface = ath9k_add_interface,
  1899. .change_interface = ath9k_change_interface,
  1900. .remove_interface = ath9k_remove_interface,
  1901. .config = ath9k_config,
  1902. .configure_filter = ath9k_configure_filter,
  1903. .sta_add = ath9k_sta_add,
  1904. .sta_remove = ath9k_sta_remove,
  1905. .sta_notify = ath9k_sta_notify,
  1906. .conf_tx = ath9k_conf_tx,
  1907. .bss_info_changed = ath9k_bss_info_changed,
  1908. .set_key = ath9k_set_key,
  1909. .get_tsf = ath9k_get_tsf,
  1910. .set_tsf = ath9k_set_tsf,
  1911. .reset_tsf = ath9k_reset_tsf,
  1912. .ampdu_action = ath9k_ampdu_action,
  1913. .get_survey = ath9k_get_survey,
  1914. .rfkill_poll = ath9k_rfkill_poll_state,
  1915. .set_coverage_class = ath9k_set_coverage_class,
  1916. .flush = ath9k_flush,
  1917. .tx_frames_pending = ath9k_tx_frames_pending,
  1918. .tx_last_beacon = ath9k_tx_last_beacon,
  1919. .release_buffered_frames = ath9k_release_buffered_frames,
  1920. .get_stats = ath9k_get_stats,
  1921. .set_antenna = ath9k_set_antenna,
  1922. .get_antenna = ath9k_get_antenna,
  1923. #ifdef CONFIG_PM_SLEEP
  1924. .suspend = ath9k_suspend,
  1925. .resume = ath9k_resume,
  1926. .set_wakeup = ath9k_set_wakeup,
  1927. #endif
  1928. #ifdef CONFIG_ATH9K_DEBUGFS
  1929. .get_et_sset_count = ath9k_get_et_sset_count,
  1930. .get_et_stats = ath9k_get_et_stats,
  1931. .get_et_strings = ath9k_get_et_strings,
  1932. #endif
  1933. #if defined(CONFIG_MAC80211_DEBUGFS) && defined(CONFIG_ATH9K_DEBUGFS)
  1934. .sta_add_debugfs = ath9k_sta_add_debugfs,
  1935. #endif
  1936. .sw_scan_start = ath9k_sw_scan_start,
  1937. .sw_scan_complete = ath9k_sw_scan_complete,
  1938. .channel_switch_beacon = ath9k_channel_switch_beacon,
  1939. };