main.c 58 KB

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