main.c 57 KB

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