main.c 58 KB

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