main.c 51 KB

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