main.c 47 KB

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