main.c 54 KB

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