main.c 52 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095
  1. /*
  2. * Copyright (c) 2008-2009 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 "ath9k.h"
  18. #include "btcoex.h"
  19. static void ath_cache_conf_rate(struct ath_softc *sc,
  20. struct ieee80211_conf *conf)
  21. {
  22. switch (conf->channel->band) {
  23. case IEEE80211_BAND_2GHZ:
  24. if (conf_is_ht20(conf))
  25. sc->cur_rate_mode = ATH9K_MODE_11NG_HT20;
  26. else if (conf_is_ht40_minus(conf))
  27. sc->cur_rate_mode = ATH9K_MODE_11NG_HT40MINUS;
  28. else if (conf_is_ht40_plus(conf))
  29. sc->cur_rate_mode = ATH9K_MODE_11NG_HT40PLUS;
  30. else
  31. sc->cur_rate_mode = ATH9K_MODE_11G;
  32. break;
  33. case IEEE80211_BAND_5GHZ:
  34. if (conf_is_ht20(conf))
  35. sc->cur_rate_mode = ATH9K_MODE_11NA_HT20;
  36. else if (conf_is_ht40_minus(conf))
  37. sc->cur_rate_mode = ATH9K_MODE_11NA_HT40MINUS;
  38. else if (conf_is_ht40_plus(conf))
  39. sc->cur_rate_mode = ATH9K_MODE_11NA_HT40PLUS;
  40. else
  41. sc->cur_rate_mode = ATH9K_MODE_11A;
  42. break;
  43. default:
  44. BUG_ON(1);
  45. break;
  46. }
  47. }
  48. static void ath_update_txpow(struct ath_softc *sc)
  49. {
  50. struct ath_hw *ah = sc->sc_ah;
  51. if (sc->curtxpow != sc->config.txpowlimit) {
  52. ath9k_hw_set_txpowerlimit(ah, sc->config.txpowlimit);
  53. /* read back in case value is clamped */
  54. sc->curtxpow = ath9k_hw_regulatory(ah)->power_limit;
  55. }
  56. }
  57. static u8 parse_mpdudensity(u8 mpdudensity)
  58. {
  59. /*
  60. * 802.11n D2.0 defined values for "Minimum MPDU Start Spacing":
  61. * 0 for no restriction
  62. * 1 for 1/4 us
  63. * 2 for 1/2 us
  64. * 3 for 1 us
  65. * 4 for 2 us
  66. * 5 for 4 us
  67. * 6 for 8 us
  68. * 7 for 16 us
  69. */
  70. switch (mpdudensity) {
  71. case 0:
  72. return 0;
  73. case 1:
  74. case 2:
  75. case 3:
  76. /* Our lower layer calculations limit our precision to
  77. 1 microsecond */
  78. return 1;
  79. case 4:
  80. return 2;
  81. case 5:
  82. return 4;
  83. case 6:
  84. return 8;
  85. case 7:
  86. return 16;
  87. default:
  88. return 0;
  89. }
  90. }
  91. static struct ath9k_channel *ath_get_curchannel(struct ath_softc *sc,
  92. struct ieee80211_hw *hw)
  93. {
  94. struct ieee80211_channel *curchan = hw->conf.channel;
  95. struct ath9k_channel *channel;
  96. u8 chan_idx;
  97. chan_idx = curchan->hw_value;
  98. channel = &sc->sc_ah->channels[chan_idx];
  99. ath9k_update_ichannel(sc, hw, channel);
  100. return channel;
  101. }
  102. bool ath9k_setpower(struct ath_softc *sc, enum ath9k_power_mode mode)
  103. {
  104. unsigned long flags;
  105. bool ret;
  106. spin_lock_irqsave(&sc->sc_pm_lock, flags);
  107. ret = ath9k_hw_setpower(sc->sc_ah, mode);
  108. spin_unlock_irqrestore(&sc->sc_pm_lock, flags);
  109. return ret;
  110. }
  111. void ath9k_ps_wakeup(struct ath_softc *sc)
  112. {
  113. unsigned long flags;
  114. spin_lock_irqsave(&sc->sc_pm_lock, flags);
  115. if (++sc->ps_usecount != 1)
  116. goto unlock;
  117. ath9k_hw_setpower(sc->sc_ah, ATH9K_PM_AWAKE);
  118. unlock:
  119. spin_unlock_irqrestore(&sc->sc_pm_lock, flags);
  120. }
  121. void ath9k_ps_restore(struct ath_softc *sc)
  122. {
  123. unsigned long flags;
  124. spin_lock_irqsave(&sc->sc_pm_lock, flags);
  125. if (--sc->ps_usecount != 0)
  126. goto unlock;
  127. if (sc->ps_idle)
  128. ath9k_hw_setpower(sc->sc_ah, ATH9K_PM_FULL_SLEEP);
  129. else if (sc->ps_enabled &&
  130. !(sc->ps_flags & (PS_WAIT_FOR_BEACON |
  131. PS_WAIT_FOR_CAB |
  132. PS_WAIT_FOR_PSPOLL_DATA |
  133. PS_WAIT_FOR_TX_ACK)))
  134. ath9k_hw_setpower(sc->sc_ah, ATH9K_PM_NETWORK_SLEEP);
  135. unlock:
  136. spin_unlock_irqrestore(&sc->sc_pm_lock, flags);
  137. }
  138. static void ath_start_ani(struct ath_common *common)
  139. {
  140. struct ath_hw *ah = common->ah;
  141. unsigned long timestamp = jiffies_to_msecs(jiffies);
  142. struct ath_softc *sc = (struct ath_softc *) common->priv;
  143. if (!(sc->sc_flags & SC_OP_ANI_RUN))
  144. return;
  145. if (sc->sc_flags & SC_OP_OFFCHANNEL)
  146. return;
  147. common->ani.longcal_timer = timestamp;
  148. common->ani.shortcal_timer = timestamp;
  149. common->ani.checkani_timer = timestamp;
  150. mod_timer(&common->ani.timer,
  151. jiffies +
  152. msecs_to_jiffies((u32)ah->config.ani_poll_interval));
  153. }
  154. /*
  155. * Set/change channels. If the channel is really being changed, it's done
  156. * by reseting the chip. To accomplish this we must first cleanup any pending
  157. * DMA, then restart stuff.
  158. */
  159. int ath_set_channel(struct ath_softc *sc, struct ieee80211_hw *hw,
  160. struct ath9k_channel *hchan)
  161. {
  162. struct ath_wiphy *aphy = hw->priv;
  163. struct ath_hw *ah = sc->sc_ah;
  164. struct ath_common *common = ath9k_hw_common(ah);
  165. struct ieee80211_conf *conf = &common->hw->conf;
  166. bool fastcc = true, stopped;
  167. struct ieee80211_channel *channel = hw->conf.channel;
  168. struct ath9k_hw_cal_data *caldata = NULL;
  169. int r;
  170. if (sc->sc_flags & SC_OP_INVALID)
  171. return -EIO;
  172. del_timer_sync(&common->ani.timer);
  173. cancel_work_sync(&sc->paprd_work);
  174. cancel_work_sync(&sc->hw_check_work);
  175. cancel_delayed_work_sync(&sc->tx_complete_work);
  176. ath9k_ps_wakeup(sc);
  177. /*
  178. * This is only performed if the channel settings have
  179. * actually changed.
  180. *
  181. * To switch channels clear any pending DMA operations;
  182. * wait long enough for the RX fifo to drain, reset the
  183. * hardware at the new frequency, and then re-enable
  184. * the relevant bits of the h/w.
  185. */
  186. ath9k_hw_set_interrupts(ah, 0);
  187. ath_drain_all_txq(sc, false);
  188. stopped = ath_stoprecv(sc);
  189. /* XXX: do not flush receive queue here. We don't want
  190. * to flush data frames already in queue because of
  191. * changing channel. */
  192. if (!stopped || !(sc->sc_flags & SC_OP_OFFCHANNEL))
  193. fastcc = false;
  194. if (!(sc->sc_flags & SC_OP_OFFCHANNEL))
  195. caldata = &aphy->caldata;
  196. ath_print(common, ATH_DBG_CONFIG,
  197. "(%u MHz) -> (%u MHz), conf_is_ht40: %d fastcc: %d\n",
  198. sc->sc_ah->curchan->channel,
  199. channel->center_freq, conf_is_ht40(conf),
  200. fastcc);
  201. spin_lock_bh(&sc->sc_resetlock);
  202. r = ath9k_hw_reset(ah, hchan, caldata, fastcc);
  203. if (r) {
  204. ath_print(common, ATH_DBG_FATAL,
  205. "Unable to reset channel (%u MHz), "
  206. "reset status %d\n",
  207. channel->center_freq, r);
  208. spin_unlock_bh(&sc->sc_resetlock);
  209. goto ps_restore;
  210. }
  211. spin_unlock_bh(&sc->sc_resetlock);
  212. if (ath_startrecv(sc) != 0) {
  213. ath_print(common, ATH_DBG_FATAL,
  214. "Unable to restart recv logic\n");
  215. r = -EIO;
  216. goto ps_restore;
  217. }
  218. ath_cache_conf_rate(sc, &hw->conf);
  219. ath_update_txpow(sc);
  220. ath9k_hw_set_interrupts(ah, ah->imask);
  221. if (!(sc->sc_flags & (SC_OP_OFFCHANNEL | SC_OP_SCANNING))) {
  222. ath_start_ani(common);
  223. ieee80211_queue_delayed_work(sc->hw, &sc->tx_complete_work, 0);
  224. ath_beacon_config(sc, NULL);
  225. }
  226. ps_restore:
  227. ath9k_ps_restore(sc);
  228. return r;
  229. }
  230. static void ath_paprd_activate(struct ath_softc *sc)
  231. {
  232. struct ath_hw *ah = sc->sc_ah;
  233. struct ath9k_hw_cal_data *caldata = ah->caldata;
  234. int chain;
  235. if (!caldata || !caldata->paprd_done)
  236. return;
  237. ath9k_ps_wakeup(sc);
  238. ar9003_paprd_enable(ah, false);
  239. for (chain = 0; chain < AR9300_MAX_CHAINS; chain++) {
  240. if (!(ah->caps.tx_chainmask & BIT(chain)))
  241. continue;
  242. ar9003_paprd_populate_single_table(ah, caldata, chain);
  243. }
  244. ar9003_paprd_enable(ah, true);
  245. ath9k_ps_restore(sc);
  246. }
  247. void ath_paprd_calibrate(struct work_struct *work)
  248. {
  249. struct ath_softc *sc = container_of(work, struct ath_softc, paprd_work);
  250. struct ieee80211_hw *hw = sc->hw;
  251. struct ath_hw *ah = sc->sc_ah;
  252. struct ieee80211_hdr *hdr;
  253. struct sk_buff *skb = NULL;
  254. struct ieee80211_tx_info *tx_info;
  255. int band = hw->conf.channel->band;
  256. struct ieee80211_supported_band *sband = &sc->sbands[band];
  257. struct ath_tx_control txctl;
  258. struct ath9k_hw_cal_data *caldata = ah->caldata;
  259. int qnum, ftype;
  260. int chain_ok = 0;
  261. int chain;
  262. int len = 1800;
  263. int time_left;
  264. int i;
  265. if (!caldata)
  266. return;
  267. skb = alloc_skb(len, GFP_KERNEL);
  268. if (!skb)
  269. return;
  270. tx_info = IEEE80211_SKB_CB(skb);
  271. skb_put(skb, len);
  272. memset(skb->data, 0, len);
  273. hdr = (struct ieee80211_hdr *)skb->data;
  274. ftype = IEEE80211_FTYPE_DATA | IEEE80211_STYPE_NULLFUNC;
  275. hdr->frame_control = cpu_to_le16(ftype);
  276. hdr->duration_id = cpu_to_le16(10);
  277. memcpy(hdr->addr1, hw->wiphy->perm_addr, ETH_ALEN);
  278. memcpy(hdr->addr2, hw->wiphy->perm_addr, ETH_ALEN);
  279. memcpy(hdr->addr3, hw->wiphy->perm_addr, ETH_ALEN);
  280. memset(&txctl, 0, sizeof(txctl));
  281. qnum = sc->tx.hwq_map[WME_AC_BE];
  282. txctl.txq = &sc->tx.txq[qnum];
  283. ath9k_ps_wakeup(sc);
  284. ar9003_paprd_init_table(ah);
  285. for (chain = 0; chain < AR9300_MAX_CHAINS; chain++) {
  286. if (!(ah->caps.tx_chainmask & BIT(chain)))
  287. continue;
  288. chain_ok = 0;
  289. memset(tx_info, 0, sizeof(*tx_info));
  290. tx_info->band = band;
  291. for (i = 0; i < 4; i++) {
  292. tx_info->control.rates[i].idx = sband->n_bitrates - 1;
  293. tx_info->control.rates[i].count = 6;
  294. }
  295. init_completion(&sc->paprd_complete);
  296. ar9003_paprd_setup_gain_table(ah, chain);
  297. txctl.paprd = BIT(chain);
  298. if (ath_tx_start(hw, skb, &txctl) != 0)
  299. break;
  300. time_left = wait_for_completion_timeout(&sc->paprd_complete,
  301. msecs_to_jiffies(ATH_PAPRD_TIMEOUT));
  302. if (!time_left) {
  303. ath_print(ath9k_hw_common(ah), ATH_DBG_CALIBRATE,
  304. "Timeout waiting for paprd training on "
  305. "TX chain %d\n",
  306. chain);
  307. goto fail_paprd;
  308. }
  309. if (!ar9003_paprd_is_done(ah))
  310. break;
  311. if (ar9003_paprd_create_curve(ah, caldata, chain) != 0)
  312. break;
  313. chain_ok = 1;
  314. }
  315. kfree_skb(skb);
  316. if (chain_ok) {
  317. caldata->paprd_done = true;
  318. ath_paprd_activate(sc);
  319. }
  320. fail_paprd:
  321. ath9k_ps_restore(sc);
  322. }
  323. /*
  324. * This routine performs the periodic noise floor calibration function
  325. * that is used to adjust and optimize the chip performance. This
  326. * takes environmental changes (location, temperature) into account.
  327. * When the task is complete, it reschedules itself depending on the
  328. * appropriate interval that was calculated.
  329. */
  330. void ath_ani_calibrate(unsigned long data)
  331. {
  332. struct ath_softc *sc = (struct ath_softc *)data;
  333. struct ath_hw *ah = sc->sc_ah;
  334. struct ath_common *common = ath9k_hw_common(ah);
  335. bool longcal = false;
  336. bool shortcal = false;
  337. bool aniflag = false;
  338. unsigned int timestamp = jiffies_to_msecs(jiffies);
  339. u32 cal_interval, short_cal_interval, long_cal_interval;
  340. if (ah->caldata && ah->caldata->nfcal_interference)
  341. long_cal_interval = ATH_LONG_CALINTERVAL_INT;
  342. else
  343. long_cal_interval = ATH_LONG_CALINTERVAL;
  344. short_cal_interval = (ah->opmode == NL80211_IFTYPE_AP) ?
  345. ATH_AP_SHORT_CALINTERVAL : ATH_STA_SHORT_CALINTERVAL;
  346. /* Only calibrate if awake */
  347. if (sc->sc_ah->power_mode != ATH9K_PM_AWAKE)
  348. goto set_timer;
  349. ath9k_ps_wakeup(sc);
  350. /* Long calibration runs independently of short calibration. */
  351. if ((timestamp - common->ani.longcal_timer) >= long_cal_interval) {
  352. longcal = true;
  353. ath_print(common, ATH_DBG_ANI, "longcal @%lu\n", jiffies);
  354. common->ani.longcal_timer = timestamp;
  355. }
  356. /* Short calibration applies only while caldone is false */
  357. if (!common->ani.caldone) {
  358. if ((timestamp - common->ani.shortcal_timer) >= short_cal_interval) {
  359. shortcal = true;
  360. ath_print(common, ATH_DBG_ANI,
  361. "shortcal @%lu\n", jiffies);
  362. common->ani.shortcal_timer = timestamp;
  363. common->ani.resetcal_timer = timestamp;
  364. }
  365. } else {
  366. if ((timestamp - common->ani.resetcal_timer) >=
  367. ATH_RESTART_CALINTERVAL) {
  368. common->ani.caldone = ath9k_hw_reset_calvalid(ah);
  369. if (common->ani.caldone)
  370. common->ani.resetcal_timer = timestamp;
  371. }
  372. }
  373. /* Verify whether we must check ANI */
  374. if ((timestamp - common->ani.checkani_timer) >=
  375. ah->config.ani_poll_interval) {
  376. aniflag = true;
  377. common->ani.checkani_timer = timestamp;
  378. }
  379. /* Skip all processing if there's nothing to do. */
  380. if (longcal || shortcal || aniflag) {
  381. /* Call ANI routine if necessary */
  382. if (aniflag)
  383. ath9k_hw_ani_monitor(ah, ah->curchan);
  384. /* Perform calibration if necessary */
  385. if (longcal || shortcal) {
  386. common->ani.caldone =
  387. ath9k_hw_calibrate(ah,
  388. ah->curchan,
  389. common->rx_chainmask,
  390. longcal);
  391. if (longcal)
  392. common->ani.noise_floor = ath9k_hw_getchan_noise(ah,
  393. ah->curchan);
  394. ath_print(common, ATH_DBG_ANI,
  395. " calibrate chan %u/%x nf: %d\n",
  396. ah->curchan->channel,
  397. ah->curchan->channelFlags,
  398. common->ani.noise_floor);
  399. }
  400. }
  401. ath9k_ps_restore(sc);
  402. set_timer:
  403. /*
  404. * Set timer interval based on previous results.
  405. * The interval must be the shortest necessary to satisfy ANI,
  406. * short calibration and long calibration.
  407. */
  408. cal_interval = ATH_LONG_CALINTERVAL;
  409. if (sc->sc_ah->config.enable_ani)
  410. cal_interval = min(cal_interval,
  411. (u32)ah->config.ani_poll_interval);
  412. if (!common->ani.caldone)
  413. cal_interval = min(cal_interval, (u32)short_cal_interval);
  414. mod_timer(&common->ani.timer, jiffies + msecs_to_jiffies(cal_interval));
  415. if ((sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_PAPRD) && ah->caldata) {
  416. if (!ah->caldata->paprd_done)
  417. ieee80211_queue_work(sc->hw, &sc->paprd_work);
  418. else
  419. ath_paprd_activate(sc);
  420. }
  421. }
  422. /*
  423. * Update tx/rx chainmask. For legacy association,
  424. * hard code chainmask to 1x1, for 11n association, use
  425. * the chainmask configuration, for bt coexistence, use
  426. * the chainmask configuration even in legacy mode.
  427. */
  428. void ath_update_chainmask(struct ath_softc *sc, int is_ht)
  429. {
  430. struct ath_hw *ah = sc->sc_ah;
  431. struct ath_common *common = ath9k_hw_common(ah);
  432. if ((sc->sc_flags & SC_OP_OFFCHANNEL) || is_ht ||
  433. (ah->btcoex_hw.scheme != ATH_BTCOEX_CFG_NONE)) {
  434. common->tx_chainmask = ah->caps.tx_chainmask;
  435. common->rx_chainmask = ah->caps.rx_chainmask;
  436. } else {
  437. common->tx_chainmask = 1;
  438. common->rx_chainmask = 1;
  439. }
  440. ath_print(common, ATH_DBG_CONFIG,
  441. "tx chmask: %d, rx chmask: %d\n",
  442. common->tx_chainmask,
  443. common->rx_chainmask);
  444. }
  445. static void ath_node_attach(struct ath_softc *sc, struct ieee80211_sta *sta)
  446. {
  447. struct ath_node *an;
  448. an = (struct ath_node *)sta->drv_priv;
  449. if (sc->sc_flags & SC_OP_TXAGGR) {
  450. ath_tx_node_init(sc, an);
  451. an->maxampdu = 1 << (IEEE80211_HT_MAX_AMPDU_FACTOR +
  452. sta->ht_cap.ampdu_factor);
  453. an->mpdudensity = parse_mpdudensity(sta->ht_cap.ampdu_density);
  454. an->last_rssi = ATH_RSSI_DUMMY_MARKER;
  455. }
  456. }
  457. static void ath_node_detach(struct ath_softc *sc, struct ieee80211_sta *sta)
  458. {
  459. struct ath_node *an = (struct ath_node *)sta->drv_priv;
  460. if (sc->sc_flags & SC_OP_TXAGGR)
  461. ath_tx_node_cleanup(sc, an);
  462. }
  463. void ath_hw_check(struct work_struct *work)
  464. {
  465. struct ath_softc *sc = container_of(work, struct ath_softc, hw_check_work);
  466. int i;
  467. ath9k_ps_wakeup(sc);
  468. for (i = 0; i < 3; i++) {
  469. if (ath9k_hw_check_alive(sc->sc_ah))
  470. goto out;
  471. msleep(1);
  472. }
  473. ath_reset(sc, false);
  474. out:
  475. ath9k_ps_restore(sc);
  476. }
  477. void ath9k_tasklet(unsigned long data)
  478. {
  479. struct ath_softc *sc = (struct ath_softc *)data;
  480. struct ath_hw *ah = sc->sc_ah;
  481. struct ath_common *common = ath9k_hw_common(ah);
  482. u32 status = sc->intrstatus;
  483. u32 rxmask;
  484. ath9k_ps_wakeup(sc);
  485. if (status & ATH9K_INT_FATAL) {
  486. ath_reset(sc, false);
  487. ath9k_ps_restore(sc);
  488. return;
  489. }
  490. if (!ath9k_hw_check_alive(ah))
  491. ieee80211_queue_work(sc->hw, &sc->hw_check_work);
  492. if (ah->caps.hw_caps & ATH9K_HW_CAP_EDMA)
  493. rxmask = (ATH9K_INT_RXHP | ATH9K_INT_RXLP | ATH9K_INT_RXEOL |
  494. ATH9K_INT_RXORN);
  495. else
  496. rxmask = (ATH9K_INT_RX | ATH9K_INT_RXEOL | ATH9K_INT_RXORN);
  497. if (status & rxmask) {
  498. spin_lock_bh(&sc->rx.rxflushlock);
  499. /* Check for high priority Rx first */
  500. if ((ah->caps.hw_caps & ATH9K_HW_CAP_EDMA) &&
  501. (status & ATH9K_INT_RXHP))
  502. ath_rx_tasklet(sc, 0, true);
  503. ath_rx_tasklet(sc, 0, false);
  504. spin_unlock_bh(&sc->rx.rxflushlock);
  505. }
  506. if (status & ATH9K_INT_TX) {
  507. if (ah->caps.hw_caps & ATH9K_HW_CAP_EDMA)
  508. ath_tx_edma_tasklet(sc);
  509. else
  510. ath_tx_tasklet(sc);
  511. }
  512. if ((status & ATH9K_INT_TSFOOR) && sc->ps_enabled) {
  513. /*
  514. * TSF sync does not look correct; remain awake to sync with
  515. * the next Beacon.
  516. */
  517. ath_print(common, ATH_DBG_PS,
  518. "TSFOOR - Sync with next Beacon\n");
  519. sc->ps_flags |= PS_WAIT_FOR_BEACON | PS_BEACON_SYNC;
  520. }
  521. if (ah->btcoex_hw.scheme == ATH_BTCOEX_CFG_3WIRE)
  522. if (status & ATH9K_INT_GENTIMER)
  523. ath_gen_timer_isr(sc->sc_ah);
  524. /* re-enable hardware interrupt */
  525. ath9k_hw_set_interrupts(ah, ah->imask);
  526. ath9k_ps_restore(sc);
  527. }
  528. irqreturn_t ath_isr(int irq, void *dev)
  529. {
  530. #define SCHED_INTR ( \
  531. ATH9K_INT_FATAL | \
  532. ATH9K_INT_RXORN | \
  533. ATH9K_INT_RXEOL | \
  534. ATH9K_INT_RX | \
  535. ATH9K_INT_RXLP | \
  536. ATH9K_INT_RXHP | \
  537. ATH9K_INT_TX | \
  538. ATH9K_INT_BMISS | \
  539. ATH9K_INT_CST | \
  540. ATH9K_INT_TSFOOR | \
  541. ATH9K_INT_GENTIMER)
  542. struct ath_softc *sc = dev;
  543. struct ath_hw *ah = sc->sc_ah;
  544. enum ath9k_int status;
  545. bool sched = false;
  546. /*
  547. * The hardware is not ready/present, don't
  548. * touch anything. Note this can happen early
  549. * on if the IRQ is shared.
  550. */
  551. if (sc->sc_flags & SC_OP_INVALID)
  552. return IRQ_NONE;
  553. /* shared irq, not for us */
  554. if (!ath9k_hw_intrpend(ah))
  555. return IRQ_NONE;
  556. /*
  557. * Figure out the reason(s) for the interrupt. Note
  558. * that the hal returns a pseudo-ISR that may include
  559. * bits we haven't explicitly enabled so we mask the
  560. * value to insure we only process bits we requested.
  561. */
  562. ath9k_hw_getisr(ah, &status); /* NB: clears ISR too */
  563. status &= ah->imask; /* discard unasked-for bits */
  564. /*
  565. * If there are no status bits set, then this interrupt was not
  566. * for me (should have been caught above).
  567. */
  568. if (!status)
  569. return IRQ_NONE;
  570. /* Cache the status */
  571. sc->intrstatus = status;
  572. if (status & SCHED_INTR)
  573. sched = true;
  574. /*
  575. * If a FATAL or RXORN interrupt is received, we have to reset the
  576. * chip immediately.
  577. */
  578. if ((status & ATH9K_INT_FATAL) || ((status & ATH9K_INT_RXORN) &&
  579. !(ah->caps.hw_caps & ATH9K_HW_CAP_EDMA)))
  580. goto chip_reset;
  581. if ((ah->caps.hw_caps & ATH9K_HW_CAP_EDMA) &&
  582. (status & ATH9K_INT_BB_WATCHDOG)) {
  583. ar9003_hw_bb_watchdog_dbg_info(ah);
  584. goto chip_reset;
  585. }
  586. if (status & ATH9K_INT_SWBA)
  587. tasklet_schedule(&sc->bcon_tasklet);
  588. if (status & ATH9K_INT_TXURN)
  589. ath9k_hw_updatetxtriglevel(ah, true);
  590. if (ah->caps.hw_caps & ATH9K_HW_CAP_EDMA) {
  591. if (status & ATH9K_INT_RXEOL) {
  592. ah->imask &= ~(ATH9K_INT_RXEOL | ATH9K_INT_RXORN);
  593. ath9k_hw_set_interrupts(ah, ah->imask);
  594. }
  595. }
  596. if (status & ATH9K_INT_MIB) {
  597. /*
  598. * Disable interrupts until we service the MIB
  599. * interrupt; otherwise it will continue to
  600. * fire.
  601. */
  602. ath9k_hw_set_interrupts(ah, 0);
  603. /*
  604. * Let the hal handle the event. We assume
  605. * it will clear whatever condition caused
  606. * the interrupt.
  607. */
  608. ath9k_hw_procmibevent(ah);
  609. ath9k_hw_set_interrupts(ah, ah->imask);
  610. }
  611. if (!(ah->caps.hw_caps & ATH9K_HW_CAP_AUTOSLEEP))
  612. if (status & ATH9K_INT_TIM_TIMER) {
  613. /* Clear RxAbort bit so that we can
  614. * receive frames */
  615. ath9k_setpower(sc, ATH9K_PM_AWAKE);
  616. ath9k_hw_setrxabort(sc->sc_ah, 0);
  617. sc->ps_flags |= PS_WAIT_FOR_BEACON;
  618. }
  619. chip_reset:
  620. ath_debug_stat_interrupt(sc, status);
  621. if (sched) {
  622. /* turn off every interrupt except SWBA */
  623. ath9k_hw_set_interrupts(ah, (ah->imask & ATH9K_INT_SWBA));
  624. tasklet_schedule(&sc->intr_tq);
  625. }
  626. return IRQ_HANDLED;
  627. #undef SCHED_INTR
  628. }
  629. static u32 ath_get_extchanmode(struct ath_softc *sc,
  630. struct ieee80211_channel *chan,
  631. enum nl80211_channel_type channel_type)
  632. {
  633. u32 chanmode = 0;
  634. switch (chan->band) {
  635. case IEEE80211_BAND_2GHZ:
  636. switch(channel_type) {
  637. case NL80211_CHAN_NO_HT:
  638. case NL80211_CHAN_HT20:
  639. chanmode = CHANNEL_G_HT20;
  640. break;
  641. case NL80211_CHAN_HT40PLUS:
  642. chanmode = CHANNEL_G_HT40PLUS;
  643. break;
  644. case NL80211_CHAN_HT40MINUS:
  645. chanmode = CHANNEL_G_HT40MINUS;
  646. break;
  647. }
  648. break;
  649. case IEEE80211_BAND_5GHZ:
  650. switch(channel_type) {
  651. case NL80211_CHAN_NO_HT:
  652. case NL80211_CHAN_HT20:
  653. chanmode = CHANNEL_A_HT20;
  654. break;
  655. case NL80211_CHAN_HT40PLUS:
  656. chanmode = CHANNEL_A_HT40PLUS;
  657. break;
  658. case NL80211_CHAN_HT40MINUS:
  659. chanmode = CHANNEL_A_HT40MINUS;
  660. break;
  661. }
  662. break;
  663. default:
  664. break;
  665. }
  666. return chanmode;
  667. }
  668. static void ath9k_bss_assoc_info(struct ath_softc *sc,
  669. struct ieee80211_vif *vif,
  670. struct ieee80211_bss_conf *bss_conf)
  671. {
  672. struct ath_hw *ah = sc->sc_ah;
  673. struct ath_common *common = ath9k_hw_common(ah);
  674. if (bss_conf->assoc) {
  675. ath_print(common, ATH_DBG_CONFIG,
  676. "Bss Info ASSOC %d, bssid: %pM\n",
  677. bss_conf->aid, common->curbssid);
  678. /* New association, store aid */
  679. common->curaid = bss_conf->aid;
  680. ath9k_hw_write_associd(ah);
  681. /*
  682. * Request a re-configuration of Beacon related timers
  683. * on the receipt of the first Beacon frame (i.e.,
  684. * after time sync with the AP).
  685. */
  686. sc->ps_flags |= PS_BEACON_SYNC;
  687. /* Configure the beacon */
  688. ath_beacon_config(sc, vif);
  689. /* Reset rssi stats */
  690. sc->sc_ah->stats.avgbrssi = ATH_RSSI_DUMMY_MARKER;
  691. sc->sc_flags |= SC_OP_ANI_RUN;
  692. ath_start_ani(common);
  693. } else {
  694. ath_print(common, ATH_DBG_CONFIG, "Bss Info DISASSOC\n");
  695. common->curaid = 0;
  696. /* Stop ANI */
  697. sc->sc_flags &= ~SC_OP_ANI_RUN;
  698. del_timer_sync(&common->ani.timer);
  699. }
  700. }
  701. void ath_radio_enable(struct ath_softc *sc, struct ieee80211_hw *hw)
  702. {
  703. struct ath_hw *ah = sc->sc_ah;
  704. struct ath_common *common = ath9k_hw_common(ah);
  705. struct ieee80211_channel *channel = hw->conf.channel;
  706. int r;
  707. ath9k_ps_wakeup(sc);
  708. ath9k_hw_configpcipowersave(ah, 0, 0);
  709. if (!ah->curchan)
  710. ah->curchan = ath_get_curchannel(sc, sc->hw);
  711. spin_lock_bh(&sc->sc_resetlock);
  712. r = ath9k_hw_reset(ah, ah->curchan, ah->caldata, false);
  713. if (r) {
  714. ath_print(common, ATH_DBG_FATAL,
  715. "Unable to reset channel (%u MHz), "
  716. "reset status %d\n",
  717. channel->center_freq, r);
  718. }
  719. spin_unlock_bh(&sc->sc_resetlock);
  720. ath_update_txpow(sc);
  721. if (ath_startrecv(sc) != 0) {
  722. ath_print(common, ATH_DBG_FATAL,
  723. "Unable to restart recv logic\n");
  724. return;
  725. }
  726. if (sc->sc_flags & SC_OP_BEACONS)
  727. ath_beacon_config(sc, NULL); /* restart beacons */
  728. /* Re-Enable interrupts */
  729. ath9k_hw_set_interrupts(ah, ah->imask);
  730. /* Enable LED */
  731. ath9k_hw_cfg_output(ah, ah->led_pin,
  732. AR_GPIO_OUTPUT_MUX_AS_OUTPUT);
  733. ath9k_hw_set_gpio(ah, ah->led_pin, 0);
  734. ieee80211_wake_queues(hw);
  735. ath9k_ps_restore(sc);
  736. }
  737. void ath_radio_disable(struct ath_softc *sc, struct ieee80211_hw *hw)
  738. {
  739. struct ath_hw *ah = sc->sc_ah;
  740. struct ieee80211_channel *channel = hw->conf.channel;
  741. int r;
  742. ath9k_ps_wakeup(sc);
  743. ieee80211_stop_queues(hw);
  744. /*
  745. * Keep the LED on when the radio is disabled
  746. * during idle unassociated state.
  747. */
  748. if (!sc->ps_idle) {
  749. ath9k_hw_set_gpio(ah, ah->led_pin, 1);
  750. ath9k_hw_cfg_gpio_input(ah, ah->led_pin);
  751. }
  752. /* Disable interrupts */
  753. ath9k_hw_set_interrupts(ah, 0);
  754. ath_drain_all_txq(sc, false); /* clear pending tx frames */
  755. ath_stoprecv(sc); /* turn off frame recv */
  756. ath_flushrecv(sc); /* flush recv queue */
  757. if (!ah->curchan)
  758. ah->curchan = ath_get_curchannel(sc, hw);
  759. spin_lock_bh(&sc->sc_resetlock);
  760. r = ath9k_hw_reset(ah, ah->curchan, ah->caldata, false);
  761. if (r) {
  762. ath_print(ath9k_hw_common(sc->sc_ah), ATH_DBG_FATAL,
  763. "Unable to reset channel (%u MHz), "
  764. "reset status %d\n",
  765. channel->center_freq, r);
  766. }
  767. spin_unlock_bh(&sc->sc_resetlock);
  768. ath9k_hw_phy_disable(ah);
  769. ath9k_hw_configpcipowersave(ah, 1, 1);
  770. ath9k_ps_restore(sc);
  771. ath9k_setpower(sc, ATH9K_PM_FULL_SLEEP);
  772. }
  773. int ath_reset(struct ath_softc *sc, bool retry_tx)
  774. {
  775. struct ath_hw *ah = sc->sc_ah;
  776. struct ath_common *common = ath9k_hw_common(ah);
  777. struct ieee80211_hw *hw = sc->hw;
  778. int r;
  779. /* Stop ANI */
  780. del_timer_sync(&common->ani.timer);
  781. ieee80211_stop_queues(hw);
  782. ath9k_hw_set_interrupts(ah, 0);
  783. ath_drain_all_txq(sc, retry_tx);
  784. ath_stoprecv(sc);
  785. ath_flushrecv(sc);
  786. spin_lock_bh(&sc->sc_resetlock);
  787. r = ath9k_hw_reset(ah, sc->sc_ah->curchan, ah->caldata, false);
  788. if (r)
  789. ath_print(common, ATH_DBG_FATAL,
  790. "Unable to reset hardware; reset status %d\n", r);
  791. spin_unlock_bh(&sc->sc_resetlock);
  792. if (ath_startrecv(sc) != 0)
  793. ath_print(common, ATH_DBG_FATAL,
  794. "Unable to start recv logic\n");
  795. /*
  796. * We may be doing a reset in response to a request
  797. * that changes the channel so update any state that
  798. * might change as a result.
  799. */
  800. ath_cache_conf_rate(sc, &hw->conf);
  801. ath_update_txpow(sc);
  802. if (sc->sc_flags & SC_OP_BEACONS)
  803. ath_beacon_config(sc, NULL); /* restart beacons */
  804. ath9k_hw_set_interrupts(ah, ah->imask);
  805. if (retry_tx) {
  806. int i;
  807. for (i = 0; i < ATH9K_NUM_TX_QUEUES; i++) {
  808. if (ATH_TXQ_SETUP(sc, i)) {
  809. spin_lock_bh(&sc->tx.txq[i].axq_lock);
  810. ath_txq_schedule(sc, &sc->tx.txq[i]);
  811. spin_unlock_bh(&sc->tx.txq[i].axq_lock);
  812. }
  813. }
  814. }
  815. ieee80211_wake_queues(hw);
  816. /* Start ANI */
  817. ath_start_ani(common);
  818. return r;
  819. }
  820. static int ath_get_hal_qnum(u16 queue, struct ath_softc *sc)
  821. {
  822. int qnum;
  823. switch (queue) {
  824. case 0:
  825. qnum = sc->tx.hwq_map[WME_AC_VO];
  826. break;
  827. case 1:
  828. qnum = sc->tx.hwq_map[WME_AC_VI];
  829. break;
  830. case 2:
  831. qnum = sc->tx.hwq_map[WME_AC_BE];
  832. break;
  833. case 3:
  834. qnum = sc->tx.hwq_map[WME_AC_BK];
  835. break;
  836. default:
  837. qnum = sc->tx.hwq_map[WME_AC_BE];
  838. break;
  839. }
  840. return qnum;
  841. }
  842. int ath_get_mac80211_qnum(u32 queue, struct ath_softc *sc)
  843. {
  844. int qnum;
  845. switch (queue) {
  846. case WME_AC_VO:
  847. qnum = 0;
  848. break;
  849. case WME_AC_VI:
  850. qnum = 1;
  851. break;
  852. case WME_AC_BE:
  853. qnum = 2;
  854. break;
  855. case WME_AC_BK:
  856. qnum = 3;
  857. break;
  858. default:
  859. qnum = -1;
  860. break;
  861. }
  862. return qnum;
  863. }
  864. /* XXX: Remove me once we don't depend on ath9k_channel for all
  865. * this redundant data */
  866. void ath9k_update_ichannel(struct ath_softc *sc, struct ieee80211_hw *hw,
  867. struct ath9k_channel *ichan)
  868. {
  869. struct ieee80211_channel *chan = hw->conf.channel;
  870. struct ieee80211_conf *conf = &hw->conf;
  871. ichan->channel = chan->center_freq;
  872. ichan->chan = chan;
  873. if (chan->band == IEEE80211_BAND_2GHZ) {
  874. ichan->chanmode = CHANNEL_G;
  875. ichan->channelFlags = CHANNEL_2GHZ | CHANNEL_OFDM | CHANNEL_G;
  876. } else {
  877. ichan->chanmode = CHANNEL_A;
  878. ichan->channelFlags = CHANNEL_5GHZ | CHANNEL_OFDM;
  879. }
  880. if (conf_is_ht(conf))
  881. ichan->chanmode = ath_get_extchanmode(sc, chan,
  882. conf->channel_type);
  883. }
  884. /**********************/
  885. /* mac80211 callbacks */
  886. /**********************/
  887. static int ath9k_start(struct ieee80211_hw *hw)
  888. {
  889. struct ath_wiphy *aphy = hw->priv;
  890. struct ath_softc *sc = aphy->sc;
  891. struct ath_hw *ah = sc->sc_ah;
  892. struct ath_common *common = ath9k_hw_common(ah);
  893. struct ieee80211_channel *curchan = hw->conf.channel;
  894. struct ath9k_channel *init_channel;
  895. int r;
  896. ath_print(common, ATH_DBG_CONFIG,
  897. "Starting driver with initial channel: %d MHz\n",
  898. curchan->center_freq);
  899. mutex_lock(&sc->mutex);
  900. if (ath9k_wiphy_started(sc)) {
  901. if (sc->chan_idx == curchan->hw_value) {
  902. /*
  903. * Already on the operational channel, the new wiphy
  904. * can be marked active.
  905. */
  906. aphy->state = ATH_WIPHY_ACTIVE;
  907. ieee80211_wake_queues(hw);
  908. } else {
  909. /*
  910. * Another wiphy is on another channel, start the new
  911. * wiphy in paused state.
  912. */
  913. aphy->state = ATH_WIPHY_PAUSED;
  914. ieee80211_stop_queues(hw);
  915. }
  916. mutex_unlock(&sc->mutex);
  917. return 0;
  918. }
  919. aphy->state = ATH_WIPHY_ACTIVE;
  920. /* setup initial channel */
  921. sc->chan_idx = curchan->hw_value;
  922. init_channel = ath_get_curchannel(sc, hw);
  923. /* Reset SERDES registers */
  924. ath9k_hw_configpcipowersave(ah, 0, 0);
  925. /*
  926. * The basic interface to setting the hardware in a good
  927. * state is ``reset''. On return the hardware is known to
  928. * be powered up and with interrupts disabled. This must
  929. * be followed by initialization of the appropriate bits
  930. * and then setup of the interrupt mask.
  931. */
  932. spin_lock_bh(&sc->sc_resetlock);
  933. r = ath9k_hw_reset(ah, init_channel, ah->caldata, false);
  934. if (r) {
  935. ath_print(common, ATH_DBG_FATAL,
  936. "Unable to reset hardware; reset status %d "
  937. "(freq %u MHz)\n", r,
  938. curchan->center_freq);
  939. spin_unlock_bh(&sc->sc_resetlock);
  940. goto mutex_unlock;
  941. }
  942. spin_unlock_bh(&sc->sc_resetlock);
  943. /*
  944. * This is needed only to setup initial state
  945. * but it's best done after a reset.
  946. */
  947. ath_update_txpow(sc);
  948. /*
  949. * Setup the hardware after reset:
  950. * The receive engine is set going.
  951. * Frame transmit is handled entirely
  952. * in the frame output path; there's nothing to do
  953. * here except setup the interrupt mask.
  954. */
  955. if (ath_startrecv(sc) != 0) {
  956. ath_print(common, ATH_DBG_FATAL,
  957. "Unable to start recv logic\n");
  958. r = -EIO;
  959. goto mutex_unlock;
  960. }
  961. /* Setup our intr mask. */
  962. ah->imask = ATH9K_INT_TX | ATH9K_INT_RXEOL |
  963. ATH9K_INT_RXORN | ATH9K_INT_FATAL |
  964. ATH9K_INT_GLOBAL;
  965. if (ah->caps.hw_caps & ATH9K_HW_CAP_EDMA)
  966. ah->imask |= ATH9K_INT_RXHP |
  967. ATH9K_INT_RXLP |
  968. ATH9K_INT_BB_WATCHDOG;
  969. else
  970. ah->imask |= ATH9K_INT_RX;
  971. if (ah->caps.hw_caps & ATH9K_HW_CAP_GTT)
  972. ah->imask |= ATH9K_INT_GTT;
  973. if (ah->caps.hw_caps & ATH9K_HW_CAP_HT)
  974. ah->imask |= ATH9K_INT_CST;
  975. ath_cache_conf_rate(sc, &hw->conf);
  976. sc->sc_flags &= ~SC_OP_INVALID;
  977. /* Disable BMISS interrupt when we're not associated */
  978. ah->imask &= ~(ATH9K_INT_SWBA | ATH9K_INT_BMISS);
  979. ath9k_hw_set_interrupts(ah, ah->imask);
  980. ieee80211_wake_queues(hw);
  981. ieee80211_queue_delayed_work(sc->hw, &sc->tx_complete_work, 0);
  982. if ((ah->btcoex_hw.scheme != ATH_BTCOEX_CFG_NONE) &&
  983. !ah->btcoex_hw.enabled) {
  984. ath9k_hw_btcoex_set_weight(ah, AR_BT_COEX_WGHT,
  985. AR_STOMP_LOW_WLAN_WGHT);
  986. ath9k_hw_btcoex_enable(ah);
  987. if (common->bus_ops->bt_coex_prep)
  988. common->bus_ops->bt_coex_prep(common);
  989. if (ah->btcoex_hw.scheme == ATH_BTCOEX_CFG_3WIRE)
  990. ath9k_btcoex_timer_resume(sc);
  991. }
  992. mutex_unlock:
  993. mutex_unlock(&sc->mutex);
  994. return r;
  995. }
  996. static int ath9k_tx(struct ieee80211_hw *hw,
  997. struct sk_buff *skb)
  998. {
  999. struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
  1000. struct ath_wiphy *aphy = hw->priv;
  1001. struct ath_softc *sc = aphy->sc;
  1002. struct ath_common *common = ath9k_hw_common(sc->sc_ah);
  1003. struct ath_tx_control txctl;
  1004. int padpos, padsize;
  1005. struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
  1006. int qnum;
  1007. if (aphy->state != ATH_WIPHY_ACTIVE && aphy->state != ATH_WIPHY_SCAN) {
  1008. ath_print(common, ATH_DBG_XMIT,
  1009. "ath9k: %s: TX in unexpected wiphy state "
  1010. "%d\n", wiphy_name(hw->wiphy), aphy->state);
  1011. goto exit;
  1012. }
  1013. if (sc->ps_enabled) {
  1014. /*
  1015. * mac80211 does not set PM field for normal data frames, so we
  1016. * need to update that based on the current PS mode.
  1017. */
  1018. if (ieee80211_is_data(hdr->frame_control) &&
  1019. !ieee80211_is_nullfunc(hdr->frame_control) &&
  1020. !ieee80211_has_pm(hdr->frame_control)) {
  1021. ath_print(common, ATH_DBG_PS, "Add PM=1 for a TX frame "
  1022. "while in PS mode\n");
  1023. hdr->frame_control |= cpu_to_le16(IEEE80211_FCTL_PM);
  1024. }
  1025. }
  1026. if (unlikely(sc->sc_ah->power_mode != ATH9K_PM_AWAKE)) {
  1027. /*
  1028. * We are using PS-Poll and mac80211 can request TX while in
  1029. * power save mode. Need to wake up hardware for the TX to be
  1030. * completed and if needed, also for RX of buffered frames.
  1031. */
  1032. ath9k_ps_wakeup(sc);
  1033. if (!(sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_AUTOSLEEP))
  1034. ath9k_hw_setrxabort(sc->sc_ah, 0);
  1035. if (ieee80211_is_pspoll(hdr->frame_control)) {
  1036. ath_print(common, ATH_DBG_PS,
  1037. "Sending PS-Poll to pick a buffered frame\n");
  1038. sc->ps_flags |= PS_WAIT_FOR_PSPOLL_DATA;
  1039. } else {
  1040. ath_print(common, ATH_DBG_PS,
  1041. "Wake up to complete TX\n");
  1042. sc->ps_flags |= PS_WAIT_FOR_TX_ACK;
  1043. }
  1044. /*
  1045. * The actual restore operation will happen only after
  1046. * the sc_flags bit is cleared. We are just dropping
  1047. * the ps_usecount here.
  1048. */
  1049. ath9k_ps_restore(sc);
  1050. }
  1051. memset(&txctl, 0, sizeof(struct ath_tx_control));
  1052. /*
  1053. * As a temporary workaround, assign seq# here; this will likely need
  1054. * to be cleaned up to work better with Beacon transmission and virtual
  1055. * BSSes.
  1056. */
  1057. if (info->flags & IEEE80211_TX_CTL_ASSIGN_SEQ) {
  1058. if (info->flags & IEEE80211_TX_CTL_FIRST_FRAGMENT)
  1059. sc->tx.seq_no += 0x10;
  1060. hdr->seq_ctrl &= cpu_to_le16(IEEE80211_SCTL_FRAG);
  1061. hdr->seq_ctrl |= cpu_to_le16(sc->tx.seq_no);
  1062. }
  1063. /* Add the padding after the header if this is not already done */
  1064. padpos = ath9k_cmn_padpos(hdr->frame_control);
  1065. padsize = padpos & 3;
  1066. if (padsize && skb->len>padpos) {
  1067. if (skb_headroom(skb) < padsize)
  1068. return -1;
  1069. skb_push(skb, padsize);
  1070. memmove(skb->data, skb->data + padsize, padpos);
  1071. }
  1072. qnum = ath_get_hal_qnum(skb_get_queue_mapping(skb), sc);
  1073. txctl.txq = &sc->tx.txq[qnum];
  1074. ath_print(common, ATH_DBG_XMIT, "transmitting packet, skb: %p\n", skb);
  1075. if (ath_tx_start(hw, skb, &txctl) != 0) {
  1076. ath_print(common, ATH_DBG_XMIT, "TX failed\n");
  1077. goto exit;
  1078. }
  1079. return 0;
  1080. exit:
  1081. dev_kfree_skb_any(skb);
  1082. return 0;
  1083. }
  1084. static void ath9k_stop(struct ieee80211_hw *hw)
  1085. {
  1086. struct ath_wiphy *aphy = hw->priv;
  1087. struct ath_softc *sc = aphy->sc;
  1088. struct ath_hw *ah = sc->sc_ah;
  1089. struct ath_common *common = ath9k_hw_common(ah);
  1090. int i;
  1091. mutex_lock(&sc->mutex);
  1092. aphy->state = ATH_WIPHY_INACTIVE;
  1093. if (led_blink)
  1094. cancel_delayed_work_sync(&sc->ath_led_blink_work);
  1095. cancel_delayed_work_sync(&sc->tx_complete_work);
  1096. cancel_work_sync(&sc->paprd_work);
  1097. cancel_work_sync(&sc->hw_check_work);
  1098. for (i = 0; i < sc->num_sec_wiphy; i++) {
  1099. if (sc->sec_wiphy[i])
  1100. break;
  1101. }
  1102. if (i == sc->num_sec_wiphy) {
  1103. cancel_delayed_work_sync(&sc->wiphy_work);
  1104. cancel_work_sync(&sc->chan_work);
  1105. }
  1106. if (sc->sc_flags & SC_OP_INVALID) {
  1107. ath_print(common, ATH_DBG_ANY, "Device not present\n");
  1108. mutex_unlock(&sc->mutex);
  1109. return;
  1110. }
  1111. if (ath9k_wiphy_started(sc)) {
  1112. mutex_unlock(&sc->mutex);
  1113. return; /* another wiphy still in use */
  1114. }
  1115. /* Ensure HW is awake when we try to shut it down. */
  1116. ath9k_ps_wakeup(sc);
  1117. if (ah->btcoex_hw.enabled) {
  1118. ath9k_hw_btcoex_disable(ah);
  1119. if (ah->btcoex_hw.scheme == ATH_BTCOEX_CFG_3WIRE)
  1120. ath9k_btcoex_timer_pause(sc);
  1121. }
  1122. /* make sure h/w will not generate any interrupt
  1123. * before setting the invalid flag. */
  1124. ath9k_hw_set_interrupts(ah, 0);
  1125. if (!(sc->sc_flags & SC_OP_INVALID)) {
  1126. ath_drain_all_txq(sc, false);
  1127. ath_stoprecv(sc);
  1128. ath9k_hw_phy_disable(ah);
  1129. } else
  1130. sc->rx.rxlink = NULL;
  1131. /* disable HAL and put h/w to sleep */
  1132. ath9k_hw_disable(ah);
  1133. ath9k_hw_configpcipowersave(ah, 1, 1);
  1134. ath9k_ps_restore(sc);
  1135. /* Finally, put the chip in FULL SLEEP mode */
  1136. ath9k_setpower(sc, ATH9K_PM_FULL_SLEEP);
  1137. sc->sc_flags |= SC_OP_INVALID;
  1138. mutex_unlock(&sc->mutex);
  1139. ath_print(common, ATH_DBG_CONFIG, "Driver halt\n");
  1140. }
  1141. static int ath9k_add_interface(struct ieee80211_hw *hw,
  1142. struct ieee80211_vif *vif)
  1143. {
  1144. struct ath_wiphy *aphy = hw->priv;
  1145. struct ath_softc *sc = aphy->sc;
  1146. struct ath_hw *ah = sc->sc_ah;
  1147. struct ath_common *common = ath9k_hw_common(ah);
  1148. struct ath_vif *avp = (void *)vif->drv_priv;
  1149. enum nl80211_iftype ic_opmode = NL80211_IFTYPE_UNSPECIFIED;
  1150. int ret = 0;
  1151. mutex_lock(&sc->mutex);
  1152. if (!(ah->caps.hw_caps & ATH9K_HW_CAP_BSSIDMASK) &&
  1153. sc->nvifs > 0) {
  1154. ret = -ENOBUFS;
  1155. goto out;
  1156. }
  1157. switch (vif->type) {
  1158. case NL80211_IFTYPE_STATION:
  1159. ic_opmode = NL80211_IFTYPE_STATION;
  1160. break;
  1161. case NL80211_IFTYPE_ADHOC:
  1162. case NL80211_IFTYPE_AP:
  1163. case NL80211_IFTYPE_MESH_POINT:
  1164. if (sc->nbcnvifs >= ATH_BCBUF) {
  1165. ret = -ENOBUFS;
  1166. goto out;
  1167. }
  1168. ic_opmode = vif->type;
  1169. break;
  1170. default:
  1171. ath_print(common, ATH_DBG_FATAL,
  1172. "Interface type %d not yet supported\n", vif->type);
  1173. ret = -EOPNOTSUPP;
  1174. goto out;
  1175. }
  1176. ath_print(common, ATH_DBG_CONFIG,
  1177. "Attach a VIF of type: %d\n", ic_opmode);
  1178. /* Set the VIF opmode */
  1179. avp->av_opmode = ic_opmode;
  1180. avp->av_bslot = -1;
  1181. sc->nvifs++;
  1182. if (ah->caps.hw_caps & ATH9K_HW_CAP_BSSIDMASK)
  1183. ath9k_set_bssid_mask(hw);
  1184. if (sc->nvifs > 1)
  1185. goto out; /* skip global settings for secondary vif */
  1186. if (ic_opmode == NL80211_IFTYPE_AP) {
  1187. ath9k_hw_set_tsfadjust(ah, 1);
  1188. sc->sc_flags |= SC_OP_TSF_RESET;
  1189. }
  1190. /* Set the device opmode */
  1191. ah->opmode = ic_opmode;
  1192. /*
  1193. * Enable MIB interrupts when there are hardware phy counters.
  1194. * Note we only do this (at the moment) for station mode.
  1195. */
  1196. if ((vif->type == NL80211_IFTYPE_STATION) ||
  1197. (vif->type == NL80211_IFTYPE_ADHOC) ||
  1198. (vif->type == NL80211_IFTYPE_MESH_POINT)) {
  1199. if (ah->config.enable_ani)
  1200. ah->imask |= ATH9K_INT_MIB;
  1201. ah->imask |= ATH9K_INT_TSFOOR;
  1202. }
  1203. ath9k_hw_set_interrupts(ah, ah->imask);
  1204. if (vif->type == NL80211_IFTYPE_AP ||
  1205. vif->type == NL80211_IFTYPE_ADHOC ||
  1206. vif->type == NL80211_IFTYPE_MONITOR) {
  1207. sc->sc_flags |= SC_OP_ANI_RUN;
  1208. ath_start_ani(common);
  1209. }
  1210. out:
  1211. mutex_unlock(&sc->mutex);
  1212. return ret;
  1213. }
  1214. static void ath9k_remove_interface(struct ieee80211_hw *hw,
  1215. struct ieee80211_vif *vif)
  1216. {
  1217. struct ath_wiphy *aphy = hw->priv;
  1218. struct ath_softc *sc = aphy->sc;
  1219. struct ath_common *common = ath9k_hw_common(sc->sc_ah);
  1220. struct ath_vif *avp = (void *)vif->drv_priv;
  1221. int i;
  1222. ath_print(common, ATH_DBG_CONFIG, "Detach Interface\n");
  1223. mutex_lock(&sc->mutex);
  1224. /* Stop ANI */
  1225. sc->sc_flags &= ~SC_OP_ANI_RUN;
  1226. del_timer_sync(&common->ani.timer);
  1227. /* Reclaim beacon resources */
  1228. if ((sc->sc_ah->opmode == NL80211_IFTYPE_AP) ||
  1229. (sc->sc_ah->opmode == NL80211_IFTYPE_ADHOC) ||
  1230. (sc->sc_ah->opmode == NL80211_IFTYPE_MESH_POINT)) {
  1231. ath9k_ps_wakeup(sc);
  1232. ath9k_hw_stoptxdma(sc->sc_ah, sc->beacon.beaconq);
  1233. ath9k_ps_restore(sc);
  1234. }
  1235. ath_beacon_return(sc, avp);
  1236. sc->sc_flags &= ~SC_OP_BEACONS;
  1237. for (i = 0; i < ARRAY_SIZE(sc->beacon.bslot); i++) {
  1238. if (sc->beacon.bslot[i] == vif) {
  1239. printk(KERN_DEBUG "%s: vif had allocated beacon "
  1240. "slot\n", __func__);
  1241. sc->beacon.bslot[i] = NULL;
  1242. sc->beacon.bslot_aphy[i] = NULL;
  1243. }
  1244. }
  1245. sc->nvifs--;
  1246. mutex_unlock(&sc->mutex);
  1247. }
  1248. void ath9k_enable_ps(struct ath_softc *sc)
  1249. {
  1250. struct ath_hw *ah = sc->sc_ah;
  1251. sc->ps_enabled = true;
  1252. if (!(ah->caps.hw_caps & ATH9K_HW_CAP_AUTOSLEEP)) {
  1253. if ((ah->imask & ATH9K_INT_TIM_TIMER) == 0) {
  1254. ah->imask |= ATH9K_INT_TIM_TIMER;
  1255. ath9k_hw_set_interrupts(ah, ah->imask);
  1256. }
  1257. ath9k_hw_setrxabort(ah, 1);
  1258. }
  1259. }
  1260. static int ath9k_config(struct ieee80211_hw *hw, u32 changed)
  1261. {
  1262. struct ath_wiphy *aphy = hw->priv;
  1263. struct ath_softc *sc = aphy->sc;
  1264. struct ath_common *common = ath9k_hw_common(sc->sc_ah);
  1265. struct ieee80211_conf *conf = &hw->conf;
  1266. struct ath_hw *ah = sc->sc_ah;
  1267. bool disable_radio;
  1268. mutex_lock(&sc->mutex);
  1269. /*
  1270. * Leave this as the first check because we need to turn on the
  1271. * radio if it was disabled before prior to processing the rest
  1272. * of the changes. Likewise we must only disable the radio towards
  1273. * the end.
  1274. */
  1275. if (changed & IEEE80211_CONF_CHANGE_IDLE) {
  1276. bool enable_radio;
  1277. bool all_wiphys_idle;
  1278. bool idle = !!(conf->flags & IEEE80211_CONF_IDLE);
  1279. spin_lock_bh(&sc->wiphy_lock);
  1280. all_wiphys_idle = ath9k_all_wiphys_idle(sc);
  1281. ath9k_set_wiphy_idle(aphy, idle);
  1282. enable_radio = (!idle && all_wiphys_idle);
  1283. /*
  1284. * After we unlock here its possible another wiphy
  1285. * can be re-renabled so to account for that we will
  1286. * only disable the radio toward the end of this routine
  1287. * if by then all wiphys are still idle.
  1288. */
  1289. spin_unlock_bh(&sc->wiphy_lock);
  1290. if (enable_radio) {
  1291. sc->ps_idle = false;
  1292. ath_radio_enable(sc, hw);
  1293. ath_print(common, ATH_DBG_CONFIG,
  1294. "not-idle: enabling radio\n");
  1295. }
  1296. }
  1297. /*
  1298. * We just prepare to enable PS. We have to wait until our AP has
  1299. * ACK'd our null data frame to disable RX otherwise we'll ignore
  1300. * those ACKs and end up retransmitting the same null data frames.
  1301. * IEEE80211_CONF_CHANGE_PS is only passed by mac80211 for STA mode.
  1302. */
  1303. if (changed & IEEE80211_CONF_CHANGE_PS) {
  1304. if (conf->flags & IEEE80211_CONF_PS) {
  1305. sc->ps_flags |= PS_ENABLED;
  1306. /*
  1307. * At this point we know hardware has received an ACK
  1308. * of a previously sent null data frame.
  1309. */
  1310. if ((sc->ps_flags & PS_NULLFUNC_COMPLETED)) {
  1311. sc->ps_flags &= ~PS_NULLFUNC_COMPLETED;
  1312. ath9k_enable_ps(sc);
  1313. }
  1314. } else {
  1315. sc->ps_enabled = false;
  1316. sc->ps_flags &= ~(PS_ENABLED |
  1317. PS_NULLFUNC_COMPLETED);
  1318. ath9k_setpower(sc, ATH9K_PM_AWAKE);
  1319. if (!(ah->caps.hw_caps &
  1320. ATH9K_HW_CAP_AUTOSLEEP)) {
  1321. ath9k_hw_setrxabort(sc->sc_ah, 0);
  1322. sc->ps_flags &= ~(PS_WAIT_FOR_BEACON |
  1323. PS_WAIT_FOR_CAB |
  1324. PS_WAIT_FOR_PSPOLL_DATA |
  1325. PS_WAIT_FOR_TX_ACK);
  1326. if (ah->imask & ATH9K_INT_TIM_TIMER) {
  1327. ah->imask &= ~ATH9K_INT_TIM_TIMER;
  1328. ath9k_hw_set_interrupts(sc->sc_ah,
  1329. ah->imask);
  1330. }
  1331. }
  1332. }
  1333. }
  1334. if (changed & IEEE80211_CONF_CHANGE_MONITOR) {
  1335. if (conf->flags & IEEE80211_CONF_MONITOR) {
  1336. ath_print(common, ATH_DBG_CONFIG,
  1337. "HW opmode set to Monitor mode\n");
  1338. sc->sc_ah->opmode = NL80211_IFTYPE_MONITOR;
  1339. }
  1340. }
  1341. if (changed & IEEE80211_CONF_CHANGE_CHANNEL) {
  1342. struct ieee80211_channel *curchan = hw->conf.channel;
  1343. int pos = curchan->hw_value;
  1344. aphy->chan_idx = pos;
  1345. aphy->chan_is_ht = conf_is_ht(conf);
  1346. if (hw->conf.flags & IEEE80211_CONF_OFFCHANNEL)
  1347. sc->sc_flags |= SC_OP_OFFCHANNEL;
  1348. else
  1349. sc->sc_flags &= ~SC_OP_OFFCHANNEL;
  1350. if (aphy->state == ATH_WIPHY_SCAN ||
  1351. aphy->state == ATH_WIPHY_ACTIVE)
  1352. ath9k_wiphy_pause_all_forced(sc, aphy);
  1353. else {
  1354. /*
  1355. * Do not change operational channel based on a paused
  1356. * wiphy changes.
  1357. */
  1358. goto skip_chan_change;
  1359. }
  1360. ath_print(common, ATH_DBG_CONFIG, "Set channel: %d MHz\n",
  1361. curchan->center_freq);
  1362. /* XXX: remove me eventualy */
  1363. ath9k_update_ichannel(sc, hw, &sc->sc_ah->channels[pos]);
  1364. ath_update_chainmask(sc, conf_is_ht(conf));
  1365. if (ath_set_channel(sc, hw, &sc->sc_ah->channels[pos]) < 0) {
  1366. ath_print(common, ATH_DBG_FATAL,
  1367. "Unable to set channel\n");
  1368. mutex_unlock(&sc->mutex);
  1369. return -EINVAL;
  1370. }
  1371. }
  1372. skip_chan_change:
  1373. if (changed & IEEE80211_CONF_CHANGE_POWER) {
  1374. sc->config.txpowlimit = 2 * conf->power_level;
  1375. ath_update_txpow(sc);
  1376. }
  1377. spin_lock_bh(&sc->wiphy_lock);
  1378. disable_radio = ath9k_all_wiphys_idle(sc);
  1379. spin_unlock_bh(&sc->wiphy_lock);
  1380. if (disable_radio) {
  1381. ath_print(common, ATH_DBG_CONFIG, "idle: disabling radio\n");
  1382. sc->ps_idle = true;
  1383. ath_radio_disable(sc, hw);
  1384. }
  1385. mutex_unlock(&sc->mutex);
  1386. return 0;
  1387. }
  1388. #define SUPPORTED_FILTERS \
  1389. (FIF_PROMISC_IN_BSS | \
  1390. FIF_ALLMULTI | \
  1391. FIF_CONTROL | \
  1392. FIF_PSPOLL | \
  1393. FIF_OTHER_BSS | \
  1394. FIF_BCN_PRBRESP_PROMISC | \
  1395. FIF_FCSFAIL)
  1396. /* FIXME: sc->sc_full_reset ? */
  1397. static void ath9k_configure_filter(struct ieee80211_hw *hw,
  1398. unsigned int changed_flags,
  1399. unsigned int *total_flags,
  1400. u64 multicast)
  1401. {
  1402. struct ath_wiphy *aphy = hw->priv;
  1403. struct ath_softc *sc = aphy->sc;
  1404. u32 rfilt;
  1405. changed_flags &= SUPPORTED_FILTERS;
  1406. *total_flags &= SUPPORTED_FILTERS;
  1407. sc->rx.rxfilter = *total_flags;
  1408. ath9k_ps_wakeup(sc);
  1409. rfilt = ath_calcrxfilter(sc);
  1410. ath9k_hw_setrxfilter(sc->sc_ah, rfilt);
  1411. ath9k_ps_restore(sc);
  1412. ath_print(ath9k_hw_common(sc->sc_ah), ATH_DBG_CONFIG,
  1413. "Set HW RX filter: 0x%x\n", rfilt);
  1414. }
  1415. static int ath9k_sta_add(struct ieee80211_hw *hw,
  1416. struct ieee80211_vif *vif,
  1417. struct ieee80211_sta *sta)
  1418. {
  1419. struct ath_wiphy *aphy = hw->priv;
  1420. struct ath_softc *sc = aphy->sc;
  1421. ath_node_attach(sc, sta);
  1422. return 0;
  1423. }
  1424. static int ath9k_sta_remove(struct ieee80211_hw *hw,
  1425. struct ieee80211_vif *vif,
  1426. struct ieee80211_sta *sta)
  1427. {
  1428. struct ath_wiphy *aphy = hw->priv;
  1429. struct ath_softc *sc = aphy->sc;
  1430. ath_node_detach(sc, sta);
  1431. return 0;
  1432. }
  1433. static int ath9k_conf_tx(struct ieee80211_hw *hw, u16 queue,
  1434. const struct ieee80211_tx_queue_params *params)
  1435. {
  1436. struct ath_wiphy *aphy = hw->priv;
  1437. struct ath_softc *sc = aphy->sc;
  1438. struct ath_common *common = ath9k_hw_common(sc->sc_ah);
  1439. struct ath9k_tx_queue_info qi;
  1440. int ret = 0, qnum;
  1441. if (queue >= WME_NUM_AC)
  1442. return 0;
  1443. mutex_lock(&sc->mutex);
  1444. memset(&qi, 0, sizeof(struct ath9k_tx_queue_info));
  1445. qi.tqi_aifs = params->aifs;
  1446. qi.tqi_cwmin = params->cw_min;
  1447. qi.tqi_cwmax = params->cw_max;
  1448. qi.tqi_burstTime = params->txop;
  1449. qnum = ath_get_hal_qnum(queue, sc);
  1450. ath_print(common, ATH_DBG_CONFIG,
  1451. "Configure tx [queue/halq] [%d/%d], "
  1452. "aifs: %d, cw_min: %d, cw_max: %d, txop: %d\n",
  1453. queue, qnum, params->aifs, params->cw_min,
  1454. params->cw_max, params->txop);
  1455. ret = ath_txq_update(sc, qnum, &qi);
  1456. if (ret)
  1457. ath_print(common, ATH_DBG_FATAL, "TXQ Update failed\n");
  1458. if (sc->sc_ah->opmode == NL80211_IFTYPE_ADHOC)
  1459. if ((qnum == sc->tx.hwq_map[WME_AC_BE]) && !ret)
  1460. ath_beaconq_config(sc);
  1461. mutex_unlock(&sc->mutex);
  1462. return ret;
  1463. }
  1464. static int ath9k_set_key(struct ieee80211_hw *hw,
  1465. enum set_key_cmd cmd,
  1466. struct ieee80211_vif *vif,
  1467. struct ieee80211_sta *sta,
  1468. struct ieee80211_key_conf *key)
  1469. {
  1470. struct ath_wiphy *aphy = hw->priv;
  1471. struct ath_softc *sc = aphy->sc;
  1472. struct ath_common *common = ath9k_hw_common(sc->sc_ah);
  1473. int ret = 0;
  1474. if (modparam_nohwcrypt)
  1475. return -ENOSPC;
  1476. mutex_lock(&sc->mutex);
  1477. ath9k_ps_wakeup(sc);
  1478. ath_print(common, ATH_DBG_CONFIG, "Set HW Key\n");
  1479. switch (cmd) {
  1480. case SET_KEY:
  1481. ret = ath9k_cmn_key_config(common, vif, sta, key);
  1482. if (ret >= 0) {
  1483. key->hw_key_idx = ret;
  1484. /* push IV and Michael MIC generation to stack */
  1485. key->flags |= IEEE80211_KEY_FLAG_GENERATE_IV;
  1486. if (key->cipher == WLAN_CIPHER_SUITE_TKIP)
  1487. key->flags |= IEEE80211_KEY_FLAG_GENERATE_MMIC;
  1488. if (sc->sc_ah->sw_mgmt_crypto &&
  1489. key->cipher == WLAN_CIPHER_SUITE_CCMP)
  1490. key->flags |= IEEE80211_KEY_FLAG_SW_MGMT;
  1491. ret = 0;
  1492. }
  1493. break;
  1494. case DISABLE_KEY:
  1495. ath9k_cmn_key_delete(common, key);
  1496. break;
  1497. default:
  1498. ret = -EINVAL;
  1499. }
  1500. ath9k_ps_restore(sc);
  1501. mutex_unlock(&sc->mutex);
  1502. return ret;
  1503. }
  1504. static void ath9k_bss_info_changed(struct ieee80211_hw *hw,
  1505. struct ieee80211_vif *vif,
  1506. struct ieee80211_bss_conf *bss_conf,
  1507. u32 changed)
  1508. {
  1509. struct ath_wiphy *aphy = hw->priv;
  1510. struct ath_softc *sc = aphy->sc;
  1511. struct ath_hw *ah = sc->sc_ah;
  1512. struct ath_common *common = ath9k_hw_common(ah);
  1513. struct ath_vif *avp = (void *)vif->drv_priv;
  1514. int slottime;
  1515. int error;
  1516. mutex_lock(&sc->mutex);
  1517. if (changed & BSS_CHANGED_BSSID) {
  1518. /* Set BSSID */
  1519. memcpy(common->curbssid, bss_conf->bssid, ETH_ALEN);
  1520. memcpy(avp->bssid, bss_conf->bssid, ETH_ALEN);
  1521. common->curaid = 0;
  1522. ath9k_hw_write_associd(ah);
  1523. /* Set aggregation protection mode parameters */
  1524. sc->config.ath_aggr_prot = 0;
  1525. /* Only legacy IBSS for now */
  1526. if (vif->type == NL80211_IFTYPE_ADHOC)
  1527. ath_update_chainmask(sc, 0);
  1528. ath_print(common, ATH_DBG_CONFIG,
  1529. "BSSID: %pM aid: 0x%x\n",
  1530. common->curbssid, common->curaid);
  1531. /* need to reconfigure the beacon */
  1532. sc->sc_flags &= ~SC_OP_BEACONS ;
  1533. }
  1534. /* Enable transmission of beacons (AP, IBSS, MESH) */
  1535. if ((changed & BSS_CHANGED_BEACON) ||
  1536. ((changed & BSS_CHANGED_BEACON_ENABLED) && bss_conf->enable_beacon)) {
  1537. ath9k_hw_stoptxdma(sc->sc_ah, sc->beacon.beaconq);
  1538. error = ath_beacon_alloc(aphy, vif);
  1539. if (!error)
  1540. ath_beacon_config(sc, vif);
  1541. }
  1542. if (changed & BSS_CHANGED_ERP_SLOT) {
  1543. if (bss_conf->use_short_slot)
  1544. slottime = 9;
  1545. else
  1546. slottime = 20;
  1547. if (vif->type == NL80211_IFTYPE_AP) {
  1548. /*
  1549. * Defer update, so that connected stations can adjust
  1550. * their settings at the same time.
  1551. * See beacon.c for more details
  1552. */
  1553. sc->beacon.slottime = slottime;
  1554. sc->beacon.updateslot = UPDATE;
  1555. } else {
  1556. ah->slottime = slottime;
  1557. ath9k_hw_init_global_settings(ah);
  1558. }
  1559. }
  1560. /* Disable transmission of beacons */
  1561. if ((changed & BSS_CHANGED_BEACON_ENABLED) && !bss_conf->enable_beacon)
  1562. ath9k_hw_stoptxdma(sc->sc_ah, sc->beacon.beaconq);
  1563. if (changed & BSS_CHANGED_BEACON_INT) {
  1564. sc->beacon_interval = bss_conf->beacon_int;
  1565. /*
  1566. * In case of AP mode, the HW TSF has to be reset
  1567. * when the beacon interval changes.
  1568. */
  1569. if (vif->type == NL80211_IFTYPE_AP) {
  1570. sc->sc_flags |= SC_OP_TSF_RESET;
  1571. ath9k_hw_stoptxdma(sc->sc_ah, sc->beacon.beaconq);
  1572. error = ath_beacon_alloc(aphy, vif);
  1573. if (!error)
  1574. ath_beacon_config(sc, vif);
  1575. } else {
  1576. ath_beacon_config(sc, vif);
  1577. }
  1578. }
  1579. if (changed & BSS_CHANGED_ERP_PREAMBLE) {
  1580. ath_print(common, ATH_DBG_CONFIG, "BSS Changed PREAMBLE %d\n",
  1581. bss_conf->use_short_preamble);
  1582. if (bss_conf->use_short_preamble)
  1583. sc->sc_flags |= SC_OP_PREAMBLE_SHORT;
  1584. else
  1585. sc->sc_flags &= ~SC_OP_PREAMBLE_SHORT;
  1586. }
  1587. if (changed & BSS_CHANGED_ERP_CTS_PROT) {
  1588. ath_print(common, ATH_DBG_CONFIG, "BSS Changed CTS PROT %d\n",
  1589. bss_conf->use_cts_prot);
  1590. if (bss_conf->use_cts_prot &&
  1591. hw->conf.channel->band != IEEE80211_BAND_5GHZ)
  1592. sc->sc_flags |= SC_OP_PROTECT_ENABLE;
  1593. else
  1594. sc->sc_flags &= ~SC_OP_PROTECT_ENABLE;
  1595. }
  1596. if (changed & BSS_CHANGED_ASSOC) {
  1597. ath_print(common, ATH_DBG_CONFIG, "BSS Changed ASSOC %d\n",
  1598. bss_conf->assoc);
  1599. ath9k_bss_assoc_info(sc, vif, bss_conf);
  1600. }
  1601. mutex_unlock(&sc->mutex);
  1602. }
  1603. static u64 ath9k_get_tsf(struct ieee80211_hw *hw)
  1604. {
  1605. u64 tsf;
  1606. struct ath_wiphy *aphy = hw->priv;
  1607. struct ath_softc *sc = aphy->sc;
  1608. mutex_lock(&sc->mutex);
  1609. tsf = ath9k_hw_gettsf64(sc->sc_ah);
  1610. mutex_unlock(&sc->mutex);
  1611. return tsf;
  1612. }
  1613. static void ath9k_set_tsf(struct ieee80211_hw *hw, u64 tsf)
  1614. {
  1615. struct ath_wiphy *aphy = hw->priv;
  1616. struct ath_softc *sc = aphy->sc;
  1617. mutex_lock(&sc->mutex);
  1618. ath9k_hw_settsf64(sc->sc_ah, tsf);
  1619. mutex_unlock(&sc->mutex);
  1620. }
  1621. static void ath9k_reset_tsf(struct ieee80211_hw *hw)
  1622. {
  1623. struct ath_wiphy *aphy = hw->priv;
  1624. struct ath_softc *sc = aphy->sc;
  1625. mutex_lock(&sc->mutex);
  1626. ath9k_ps_wakeup(sc);
  1627. ath9k_hw_reset_tsf(sc->sc_ah);
  1628. ath9k_ps_restore(sc);
  1629. mutex_unlock(&sc->mutex);
  1630. }
  1631. static int ath9k_ampdu_action(struct ieee80211_hw *hw,
  1632. struct ieee80211_vif *vif,
  1633. enum ieee80211_ampdu_mlme_action action,
  1634. struct ieee80211_sta *sta,
  1635. u16 tid, u16 *ssn)
  1636. {
  1637. struct ath_wiphy *aphy = hw->priv;
  1638. struct ath_softc *sc = aphy->sc;
  1639. int ret = 0;
  1640. local_bh_disable();
  1641. switch (action) {
  1642. case IEEE80211_AMPDU_RX_START:
  1643. if (!(sc->sc_flags & SC_OP_RXAGGR))
  1644. ret = -ENOTSUPP;
  1645. break;
  1646. case IEEE80211_AMPDU_RX_STOP:
  1647. break;
  1648. case IEEE80211_AMPDU_TX_START:
  1649. ath9k_ps_wakeup(sc);
  1650. ath_tx_aggr_start(sc, sta, tid, ssn);
  1651. ieee80211_start_tx_ba_cb_irqsafe(vif, sta->addr, tid);
  1652. ath9k_ps_restore(sc);
  1653. break;
  1654. case IEEE80211_AMPDU_TX_STOP:
  1655. ath9k_ps_wakeup(sc);
  1656. ath_tx_aggr_stop(sc, sta, tid);
  1657. ieee80211_stop_tx_ba_cb_irqsafe(vif, sta->addr, tid);
  1658. ath9k_ps_restore(sc);
  1659. break;
  1660. case IEEE80211_AMPDU_TX_OPERATIONAL:
  1661. ath9k_ps_wakeup(sc);
  1662. ath_tx_aggr_resume(sc, sta, tid);
  1663. ath9k_ps_restore(sc);
  1664. break;
  1665. default:
  1666. ath_print(ath9k_hw_common(sc->sc_ah), ATH_DBG_FATAL,
  1667. "Unknown AMPDU action\n");
  1668. }
  1669. local_bh_enable();
  1670. return ret;
  1671. }
  1672. static int ath9k_get_survey(struct ieee80211_hw *hw, int idx,
  1673. struct survey_info *survey)
  1674. {
  1675. struct ath_wiphy *aphy = hw->priv;
  1676. struct ath_softc *sc = aphy->sc;
  1677. struct ath_hw *ah = sc->sc_ah;
  1678. struct ath_common *common = ath9k_hw_common(ah);
  1679. struct ieee80211_conf *conf = &hw->conf;
  1680. if (idx != 0)
  1681. return -ENOENT;
  1682. survey->channel = conf->channel;
  1683. survey->filled = SURVEY_INFO_NOISE_DBM;
  1684. survey->noise = common->ani.noise_floor;
  1685. return 0;
  1686. }
  1687. static void ath9k_sw_scan_start(struct ieee80211_hw *hw)
  1688. {
  1689. struct ath_wiphy *aphy = hw->priv;
  1690. struct ath_softc *sc = aphy->sc;
  1691. mutex_lock(&sc->mutex);
  1692. if (ath9k_wiphy_scanning(sc)) {
  1693. /*
  1694. * There is a race here in mac80211 but fixing it requires
  1695. * we revisit how we handle the scan complete callback.
  1696. * After mac80211 fixes we will not have configured hardware
  1697. * to the home channel nor would we have configured the RX
  1698. * filter yet.
  1699. */
  1700. mutex_unlock(&sc->mutex);
  1701. return;
  1702. }
  1703. aphy->state = ATH_WIPHY_SCAN;
  1704. ath9k_wiphy_pause_all_forced(sc, aphy);
  1705. sc->sc_flags |= SC_OP_SCANNING;
  1706. mutex_unlock(&sc->mutex);
  1707. }
  1708. /*
  1709. * XXX: this requires a revisit after the driver
  1710. * scan_complete gets moved to another place/removed in mac80211.
  1711. */
  1712. static void ath9k_sw_scan_complete(struct ieee80211_hw *hw)
  1713. {
  1714. struct ath_wiphy *aphy = hw->priv;
  1715. struct ath_softc *sc = aphy->sc;
  1716. mutex_lock(&sc->mutex);
  1717. aphy->state = ATH_WIPHY_ACTIVE;
  1718. sc->sc_flags &= ~SC_OP_SCANNING;
  1719. mutex_unlock(&sc->mutex);
  1720. }
  1721. static void ath9k_set_coverage_class(struct ieee80211_hw *hw, u8 coverage_class)
  1722. {
  1723. struct ath_wiphy *aphy = hw->priv;
  1724. struct ath_softc *sc = aphy->sc;
  1725. struct ath_hw *ah = sc->sc_ah;
  1726. mutex_lock(&sc->mutex);
  1727. ah->coverage_class = coverage_class;
  1728. ath9k_hw_init_global_settings(ah);
  1729. mutex_unlock(&sc->mutex);
  1730. }
  1731. struct ieee80211_ops ath9k_ops = {
  1732. .tx = ath9k_tx,
  1733. .start = ath9k_start,
  1734. .stop = ath9k_stop,
  1735. .add_interface = ath9k_add_interface,
  1736. .remove_interface = ath9k_remove_interface,
  1737. .config = ath9k_config,
  1738. .configure_filter = ath9k_configure_filter,
  1739. .sta_add = ath9k_sta_add,
  1740. .sta_remove = ath9k_sta_remove,
  1741. .conf_tx = ath9k_conf_tx,
  1742. .bss_info_changed = ath9k_bss_info_changed,
  1743. .set_key = ath9k_set_key,
  1744. .get_tsf = ath9k_get_tsf,
  1745. .set_tsf = ath9k_set_tsf,
  1746. .reset_tsf = ath9k_reset_tsf,
  1747. .ampdu_action = ath9k_ampdu_action,
  1748. .get_survey = ath9k_get_survey,
  1749. .sw_scan_start = ath9k_sw_scan_start,
  1750. .sw_scan_complete = ath9k_sw_scan_complete,
  1751. .rfkill_poll = ath9k_rfkill_poll_state,
  1752. .set_coverage_class = ath9k_set_coverage_class,
  1753. };