main.c 53 KB

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