main.c 53 KB

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