main.c 53 KB

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