main.c 52 KB

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