main.c 73 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915
  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. static char *dev_info = "ath9k";
  19. MODULE_AUTHOR("Atheros Communications");
  20. MODULE_DESCRIPTION("Support for Atheros 802.11n wireless LAN cards.");
  21. MODULE_SUPPORTED_DEVICE("Atheros 802.11n WLAN cards");
  22. MODULE_LICENSE("Dual BSD/GPL");
  23. static int modparam_nohwcrypt;
  24. module_param_named(nohwcrypt, modparam_nohwcrypt, int, 0444);
  25. MODULE_PARM_DESC(nohwcrypt, "Disable hardware encryption");
  26. /* We use the hw_value as an index into our private channel structure */
  27. #define CHAN2G(_freq, _idx) { \
  28. .center_freq = (_freq), \
  29. .hw_value = (_idx), \
  30. .max_power = 20, \
  31. }
  32. #define CHAN5G(_freq, _idx) { \
  33. .band = IEEE80211_BAND_5GHZ, \
  34. .center_freq = (_freq), \
  35. .hw_value = (_idx), \
  36. .max_power = 20, \
  37. }
  38. /* Some 2 GHz radios are actually tunable on 2312-2732
  39. * on 5 MHz steps, we support the channels which we know
  40. * we have calibration data for all cards though to make
  41. * this static */
  42. static struct ieee80211_channel ath9k_2ghz_chantable[] = {
  43. CHAN2G(2412, 0), /* Channel 1 */
  44. CHAN2G(2417, 1), /* Channel 2 */
  45. CHAN2G(2422, 2), /* Channel 3 */
  46. CHAN2G(2427, 3), /* Channel 4 */
  47. CHAN2G(2432, 4), /* Channel 5 */
  48. CHAN2G(2437, 5), /* Channel 6 */
  49. CHAN2G(2442, 6), /* Channel 7 */
  50. CHAN2G(2447, 7), /* Channel 8 */
  51. CHAN2G(2452, 8), /* Channel 9 */
  52. CHAN2G(2457, 9), /* Channel 10 */
  53. CHAN2G(2462, 10), /* Channel 11 */
  54. CHAN2G(2467, 11), /* Channel 12 */
  55. CHAN2G(2472, 12), /* Channel 13 */
  56. CHAN2G(2484, 13), /* Channel 14 */
  57. };
  58. /* Some 5 GHz radios are actually tunable on XXXX-YYYY
  59. * on 5 MHz steps, we support the channels which we know
  60. * we have calibration data for all cards though to make
  61. * this static */
  62. static struct ieee80211_channel ath9k_5ghz_chantable[] = {
  63. /* _We_ call this UNII 1 */
  64. CHAN5G(5180, 14), /* Channel 36 */
  65. CHAN5G(5200, 15), /* Channel 40 */
  66. CHAN5G(5220, 16), /* Channel 44 */
  67. CHAN5G(5240, 17), /* Channel 48 */
  68. /* _We_ call this UNII 2 */
  69. CHAN5G(5260, 18), /* Channel 52 */
  70. CHAN5G(5280, 19), /* Channel 56 */
  71. CHAN5G(5300, 20), /* Channel 60 */
  72. CHAN5G(5320, 21), /* Channel 64 */
  73. /* _We_ call this "Middle band" */
  74. CHAN5G(5500, 22), /* Channel 100 */
  75. CHAN5G(5520, 23), /* Channel 104 */
  76. CHAN5G(5540, 24), /* Channel 108 */
  77. CHAN5G(5560, 25), /* Channel 112 */
  78. CHAN5G(5580, 26), /* Channel 116 */
  79. CHAN5G(5600, 27), /* Channel 120 */
  80. CHAN5G(5620, 28), /* Channel 124 */
  81. CHAN5G(5640, 29), /* Channel 128 */
  82. CHAN5G(5660, 30), /* Channel 132 */
  83. CHAN5G(5680, 31), /* Channel 136 */
  84. CHAN5G(5700, 32), /* Channel 140 */
  85. /* _We_ call this UNII 3 */
  86. CHAN5G(5745, 33), /* Channel 149 */
  87. CHAN5G(5765, 34), /* Channel 153 */
  88. CHAN5G(5785, 35), /* Channel 157 */
  89. CHAN5G(5805, 36), /* Channel 161 */
  90. CHAN5G(5825, 37), /* Channel 165 */
  91. };
  92. static void ath_cache_conf_rate(struct ath_softc *sc,
  93. struct ieee80211_conf *conf)
  94. {
  95. switch (conf->channel->band) {
  96. case IEEE80211_BAND_2GHZ:
  97. if (conf_is_ht20(conf))
  98. sc->cur_rate_table =
  99. sc->hw_rate_table[ATH9K_MODE_11NG_HT20];
  100. else if (conf_is_ht40_minus(conf))
  101. sc->cur_rate_table =
  102. sc->hw_rate_table[ATH9K_MODE_11NG_HT40MINUS];
  103. else if (conf_is_ht40_plus(conf))
  104. sc->cur_rate_table =
  105. sc->hw_rate_table[ATH9K_MODE_11NG_HT40PLUS];
  106. else
  107. sc->cur_rate_table =
  108. sc->hw_rate_table[ATH9K_MODE_11G];
  109. break;
  110. case IEEE80211_BAND_5GHZ:
  111. if (conf_is_ht20(conf))
  112. sc->cur_rate_table =
  113. sc->hw_rate_table[ATH9K_MODE_11NA_HT20];
  114. else if (conf_is_ht40_minus(conf))
  115. sc->cur_rate_table =
  116. sc->hw_rate_table[ATH9K_MODE_11NA_HT40MINUS];
  117. else if (conf_is_ht40_plus(conf))
  118. sc->cur_rate_table =
  119. sc->hw_rate_table[ATH9K_MODE_11NA_HT40PLUS];
  120. else
  121. sc->cur_rate_table =
  122. sc->hw_rate_table[ATH9K_MODE_11A];
  123. break;
  124. default:
  125. BUG_ON(1);
  126. break;
  127. }
  128. }
  129. static void ath_update_txpow(struct ath_softc *sc)
  130. {
  131. struct ath_hw *ah = sc->sc_ah;
  132. u32 txpow;
  133. if (sc->curtxpow != sc->config.txpowlimit) {
  134. ath9k_hw_set_txpowerlimit(ah, sc->config.txpowlimit);
  135. /* read back in case value is clamped */
  136. ath9k_hw_getcapability(ah, ATH9K_CAP_TXPOW, 1, &txpow);
  137. sc->curtxpow = txpow;
  138. }
  139. }
  140. static u8 parse_mpdudensity(u8 mpdudensity)
  141. {
  142. /*
  143. * 802.11n D2.0 defined values for "Minimum MPDU Start Spacing":
  144. * 0 for no restriction
  145. * 1 for 1/4 us
  146. * 2 for 1/2 us
  147. * 3 for 1 us
  148. * 4 for 2 us
  149. * 5 for 4 us
  150. * 6 for 8 us
  151. * 7 for 16 us
  152. */
  153. switch (mpdudensity) {
  154. case 0:
  155. return 0;
  156. case 1:
  157. case 2:
  158. case 3:
  159. /* Our lower layer calculations limit our precision to
  160. 1 microsecond */
  161. return 1;
  162. case 4:
  163. return 2;
  164. case 5:
  165. return 4;
  166. case 6:
  167. return 8;
  168. case 7:
  169. return 16;
  170. default:
  171. return 0;
  172. }
  173. }
  174. static void ath_setup_rates(struct ath_softc *sc, enum ieee80211_band band)
  175. {
  176. const struct ath_rate_table *rate_table = NULL;
  177. struct ieee80211_supported_band *sband;
  178. struct ieee80211_rate *rate;
  179. int i, maxrates;
  180. switch (band) {
  181. case IEEE80211_BAND_2GHZ:
  182. rate_table = sc->hw_rate_table[ATH9K_MODE_11G];
  183. break;
  184. case IEEE80211_BAND_5GHZ:
  185. rate_table = sc->hw_rate_table[ATH9K_MODE_11A];
  186. break;
  187. default:
  188. break;
  189. }
  190. if (rate_table == NULL)
  191. return;
  192. sband = &sc->sbands[band];
  193. rate = sc->rates[band];
  194. if (rate_table->rate_cnt > ATH_RATE_MAX)
  195. maxrates = ATH_RATE_MAX;
  196. else
  197. maxrates = rate_table->rate_cnt;
  198. for (i = 0; i < maxrates; i++) {
  199. rate[i].bitrate = rate_table->info[i].ratekbps / 100;
  200. rate[i].hw_value = rate_table->info[i].ratecode;
  201. if (rate_table->info[i].short_preamble) {
  202. rate[i].hw_value_short = rate_table->info[i].ratecode |
  203. rate_table->info[i].short_preamble;
  204. rate[i].flags = IEEE80211_RATE_SHORT_PREAMBLE;
  205. }
  206. sband->n_bitrates++;
  207. DPRINTF(sc, ATH_DBG_CONFIG, "Rate: %2dMbps, ratecode: %2d\n",
  208. rate[i].bitrate / 10, rate[i].hw_value);
  209. }
  210. }
  211. static struct ath9k_channel *ath_get_curchannel(struct ath_softc *sc,
  212. struct ieee80211_hw *hw)
  213. {
  214. struct ieee80211_channel *curchan = hw->conf.channel;
  215. struct ath9k_channel *channel;
  216. u8 chan_idx;
  217. chan_idx = curchan->hw_value;
  218. channel = &sc->sc_ah->channels[chan_idx];
  219. ath9k_update_ichannel(sc, hw, channel);
  220. return channel;
  221. }
  222. /*
  223. * Set/change channels. If the channel is really being changed, it's done
  224. * by reseting the chip. To accomplish this we must first cleanup any pending
  225. * DMA, then restart stuff.
  226. */
  227. int ath_set_channel(struct ath_softc *sc, struct ieee80211_hw *hw,
  228. struct ath9k_channel *hchan)
  229. {
  230. struct ath_hw *ah = sc->sc_ah;
  231. bool fastcc = true, stopped;
  232. struct ieee80211_channel *channel = hw->conf.channel;
  233. int r;
  234. if (sc->sc_flags & SC_OP_INVALID)
  235. return -EIO;
  236. ath9k_ps_wakeup(sc);
  237. /*
  238. * This is only performed if the channel settings have
  239. * actually changed.
  240. *
  241. * To switch channels clear any pending DMA operations;
  242. * wait long enough for the RX fifo to drain, reset the
  243. * hardware at the new frequency, and then re-enable
  244. * the relevant bits of the h/w.
  245. */
  246. ath9k_hw_set_interrupts(ah, 0);
  247. ath_drain_all_txq(sc, false);
  248. stopped = ath_stoprecv(sc);
  249. /* XXX: do not flush receive queue here. We don't want
  250. * to flush data frames already in queue because of
  251. * changing channel. */
  252. if (!stopped || (sc->sc_flags & SC_OP_FULL_RESET))
  253. fastcc = false;
  254. DPRINTF(sc, ATH_DBG_CONFIG,
  255. "(%u MHz) -> (%u MHz), chanwidth: %d\n",
  256. sc->sc_ah->curchan->channel,
  257. channel->center_freq, sc->tx_chan_width);
  258. spin_lock_bh(&sc->sc_resetlock);
  259. r = ath9k_hw_reset(ah, hchan, fastcc);
  260. if (r) {
  261. DPRINTF(sc, ATH_DBG_FATAL,
  262. "Unable to reset channel (%u Mhz) "
  263. "reset status %d\n",
  264. channel->center_freq, r);
  265. spin_unlock_bh(&sc->sc_resetlock);
  266. goto ps_restore;
  267. }
  268. spin_unlock_bh(&sc->sc_resetlock);
  269. sc->sc_flags &= ~SC_OP_FULL_RESET;
  270. if (ath_startrecv(sc) != 0) {
  271. DPRINTF(sc, ATH_DBG_FATAL,
  272. "Unable to restart recv logic\n");
  273. r = -EIO;
  274. goto ps_restore;
  275. }
  276. ath_cache_conf_rate(sc, &hw->conf);
  277. ath_update_txpow(sc);
  278. ath9k_hw_set_interrupts(ah, sc->imask);
  279. ps_restore:
  280. ath9k_ps_restore(sc);
  281. return r;
  282. }
  283. /*
  284. * This routine performs the periodic noise floor calibration function
  285. * that is used to adjust and optimize the chip performance. This
  286. * takes environmental changes (location, temperature) into account.
  287. * When the task is complete, it reschedules itself depending on the
  288. * appropriate interval that was calculated.
  289. */
  290. static void ath_ani_calibrate(unsigned long data)
  291. {
  292. struct ath_softc *sc = (struct ath_softc *)data;
  293. struct ath_hw *ah = sc->sc_ah;
  294. bool longcal = false;
  295. bool shortcal = false;
  296. bool aniflag = false;
  297. unsigned int timestamp = jiffies_to_msecs(jiffies);
  298. u32 cal_interval, short_cal_interval;
  299. short_cal_interval = (ah->opmode == NL80211_IFTYPE_AP) ?
  300. ATH_AP_SHORT_CALINTERVAL : ATH_STA_SHORT_CALINTERVAL;
  301. /*
  302. * don't calibrate when we're scanning.
  303. * we are most likely not on our home channel.
  304. */
  305. spin_lock(&sc->ani_lock);
  306. if (sc->sc_flags & SC_OP_SCANNING)
  307. goto set_timer;
  308. /* Only calibrate if awake */
  309. if (sc->sc_ah->power_mode != ATH9K_PM_AWAKE)
  310. goto set_timer;
  311. ath9k_ps_wakeup(sc);
  312. /* Long calibration runs independently of short calibration. */
  313. if ((timestamp - sc->ani.longcal_timer) >= ATH_LONG_CALINTERVAL) {
  314. longcal = true;
  315. DPRINTF(sc, ATH_DBG_ANI, "longcal @%lu\n", jiffies);
  316. sc->ani.longcal_timer = timestamp;
  317. }
  318. /* Short calibration applies only while caldone is false */
  319. if (!sc->ani.caldone) {
  320. if ((timestamp - sc->ani.shortcal_timer) >= short_cal_interval) {
  321. shortcal = true;
  322. DPRINTF(sc, ATH_DBG_ANI, "shortcal @%lu\n", jiffies);
  323. sc->ani.shortcal_timer = timestamp;
  324. sc->ani.resetcal_timer = timestamp;
  325. }
  326. } else {
  327. if ((timestamp - sc->ani.resetcal_timer) >=
  328. ATH_RESTART_CALINTERVAL) {
  329. sc->ani.caldone = ath9k_hw_reset_calvalid(ah);
  330. if (sc->ani.caldone)
  331. sc->ani.resetcal_timer = timestamp;
  332. }
  333. }
  334. /* Verify whether we must check ANI */
  335. if ((timestamp - sc->ani.checkani_timer) >= ATH_ANI_POLLINTERVAL) {
  336. aniflag = true;
  337. sc->ani.checkani_timer = timestamp;
  338. }
  339. /* Skip all processing if there's nothing to do. */
  340. if (longcal || shortcal || aniflag) {
  341. /* Call ANI routine if necessary */
  342. if (aniflag)
  343. ath9k_hw_ani_monitor(ah, ah->curchan);
  344. /* Perform calibration if necessary */
  345. if (longcal || shortcal) {
  346. sc->ani.caldone = ath9k_hw_calibrate(ah, ah->curchan,
  347. sc->rx_chainmask, longcal);
  348. if (longcal)
  349. sc->ani.noise_floor = ath9k_hw_getchan_noise(ah,
  350. ah->curchan);
  351. DPRINTF(sc, ATH_DBG_ANI," calibrate chan %u/%x nf: %d\n",
  352. ah->curchan->channel, ah->curchan->channelFlags,
  353. sc->ani.noise_floor);
  354. }
  355. }
  356. ath9k_ps_restore(sc);
  357. set_timer:
  358. spin_unlock(&sc->ani_lock);
  359. /*
  360. * Set timer interval based on previous results.
  361. * The interval must be the shortest necessary to satisfy ANI,
  362. * short calibration and long calibration.
  363. */
  364. cal_interval = ATH_LONG_CALINTERVAL;
  365. if (sc->sc_ah->config.enable_ani)
  366. cal_interval = min(cal_interval, (u32)ATH_ANI_POLLINTERVAL);
  367. if (!sc->ani.caldone)
  368. cal_interval = min(cal_interval, (u32)short_cal_interval);
  369. mod_timer(&sc->ani.timer, jiffies + msecs_to_jiffies(cal_interval));
  370. }
  371. static void ath_start_ani(struct ath_softc *sc)
  372. {
  373. unsigned long timestamp = jiffies_to_msecs(jiffies);
  374. sc->ani.longcal_timer = timestamp;
  375. sc->ani.shortcal_timer = timestamp;
  376. sc->ani.checkani_timer = timestamp;
  377. mod_timer(&sc->ani.timer,
  378. jiffies + msecs_to_jiffies(ATH_ANI_POLLINTERVAL));
  379. }
  380. /*
  381. * Update tx/rx chainmask. For legacy association,
  382. * hard code chainmask to 1x1, for 11n association, use
  383. * the chainmask configuration, for bt coexistence, use
  384. * the chainmask configuration even in legacy mode.
  385. */
  386. void ath_update_chainmask(struct ath_softc *sc, int is_ht)
  387. {
  388. if ((sc->sc_flags & SC_OP_SCANNING) || is_ht ||
  389. (sc->btcoex_info.btcoex_scheme != ATH_BTCOEX_CFG_NONE)) {
  390. sc->tx_chainmask = sc->sc_ah->caps.tx_chainmask;
  391. sc->rx_chainmask = sc->sc_ah->caps.rx_chainmask;
  392. } else {
  393. sc->tx_chainmask = 1;
  394. sc->rx_chainmask = 1;
  395. }
  396. DPRINTF(sc, ATH_DBG_CONFIG, "tx chmask: %d, rx chmask: %d\n",
  397. sc->tx_chainmask, sc->rx_chainmask);
  398. }
  399. static void ath_node_attach(struct ath_softc *sc, struct ieee80211_sta *sta)
  400. {
  401. struct ath_node *an;
  402. an = (struct ath_node *)sta->drv_priv;
  403. if (sc->sc_flags & SC_OP_TXAGGR) {
  404. ath_tx_node_init(sc, an);
  405. an->maxampdu = 1 << (IEEE80211_HT_MAX_AMPDU_FACTOR +
  406. sta->ht_cap.ampdu_factor);
  407. an->mpdudensity = parse_mpdudensity(sta->ht_cap.ampdu_density);
  408. an->last_rssi = ATH_RSSI_DUMMY_MARKER;
  409. }
  410. }
  411. static void ath_node_detach(struct ath_softc *sc, struct ieee80211_sta *sta)
  412. {
  413. struct ath_node *an = (struct ath_node *)sta->drv_priv;
  414. if (sc->sc_flags & SC_OP_TXAGGR)
  415. ath_tx_node_cleanup(sc, an);
  416. }
  417. static void ath9k_tasklet(unsigned long data)
  418. {
  419. struct ath_softc *sc = (struct ath_softc *)data;
  420. u32 status = sc->intrstatus;
  421. ath9k_ps_wakeup(sc);
  422. if (status & ATH9K_INT_FATAL) {
  423. ath_reset(sc, false);
  424. ath9k_ps_restore(sc);
  425. return;
  426. }
  427. if (status & (ATH9K_INT_RX | ATH9K_INT_RXEOL | ATH9K_INT_RXORN)) {
  428. spin_lock_bh(&sc->rx.rxflushlock);
  429. ath_rx_tasklet(sc, 0);
  430. spin_unlock_bh(&sc->rx.rxflushlock);
  431. }
  432. if (status & ATH9K_INT_TX)
  433. ath_tx_tasklet(sc);
  434. if ((status & ATH9K_INT_TSFOOR) && sc->ps_enabled) {
  435. /*
  436. * TSF sync does not look correct; remain awake to sync with
  437. * the next Beacon.
  438. */
  439. DPRINTF(sc, ATH_DBG_PS, "TSFOOR - Sync with next Beacon\n");
  440. sc->sc_flags |= SC_OP_WAIT_FOR_BEACON | SC_OP_BEACON_SYNC;
  441. }
  442. if (sc->btcoex_info.btcoex_scheme == ATH_BTCOEX_CFG_3WIRE)
  443. if (status & ATH9K_INT_GENTIMER)
  444. ath_gen_timer_isr(sc->sc_ah);
  445. /* re-enable hardware interrupt */
  446. ath9k_hw_set_interrupts(sc->sc_ah, sc->imask);
  447. ath9k_ps_restore(sc);
  448. }
  449. irqreturn_t ath_isr(int irq, void *dev)
  450. {
  451. #define SCHED_INTR ( \
  452. ATH9K_INT_FATAL | \
  453. ATH9K_INT_RXORN | \
  454. ATH9K_INT_RXEOL | \
  455. ATH9K_INT_RX | \
  456. ATH9K_INT_TX | \
  457. ATH9K_INT_BMISS | \
  458. ATH9K_INT_CST | \
  459. ATH9K_INT_TSFOOR | \
  460. ATH9K_INT_GENTIMER)
  461. struct ath_softc *sc = dev;
  462. struct ath_hw *ah = sc->sc_ah;
  463. enum ath9k_int status;
  464. bool sched = false;
  465. /*
  466. * The hardware is not ready/present, don't
  467. * touch anything. Note this can happen early
  468. * on if the IRQ is shared.
  469. */
  470. if (sc->sc_flags & SC_OP_INVALID)
  471. return IRQ_NONE;
  472. /* shared irq, not for us */
  473. if (!ath9k_hw_intrpend(ah))
  474. return IRQ_NONE;
  475. /*
  476. * Figure out the reason(s) for the interrupt. Note
  477. * that the hal returns a pseudo-ISR that may include
  478. * bits we haven't explicitly enabled so we mask the
  479. * value to insure we only process bits we requested.
  480. */
  481. ath9k_hw_getisr(ah, &status); /* NB: clears ISR too */
  482. status &= sc->imask; /* discard unasked-for bits */
  483. /*
  484. * If there are no status bits set, then this interrupt was not
  485. * for me (should have been caught above).
  486. */
  487. if (!status)
  488. return IRQ_NONE;
  489. /* Cache the status */
  490. sc->intrstatus = status;
  491. if (status & SCHED_INTR)
  492. sched = true;
  493. /*
  494. * If a FATAL or RXORN interrupt is received, we have to reset the
  495. * chip immediately.
  496. */
  497. if (status & (ATH9K_INT_FATAL | ATH9K_INT_RXORN))
  498. goto chip_reset;
  499. if (status & ATH9K_INT_SWBA)
  500. tasklet_schedule(&sc->bcon_tasklet);
  501. if (status & ATH9K_INT_TXURN)
  502. ath9k_hw_updatetxtriglevel(ah, true);
  503. if (status & ATH9K_INT_MIB) {
  504. /*
  505. * Disable interrupts until we service the MIB
  506. * interrupt; otherwise it will continue to
  507. * fire.
  508. */
  509. ath9k_hw_set_interrupts(ah, 0);
  510. /*
  511. * Let the hal handle the event. We assume
  512. * it will clear whatever condition caused
  513. * the interrupt.
  514. */
  515. ath9k_hw_procmibevent(ah);
  516. ath9k_hw_set_interrupts(ah, sc->imask);
  517. }
  518. if (!(ah->caps.hw_caps & ATH9K_HW_CAP_AUTOSLEEP))
  519. if (status & ATH9K_INT_TIM_TIMER) {
  520. /* Clear RxAbort bit so that we can
  521. * receive frames */
  522. ath9k_hw_setpower(ah, ATH9K_PM_AWAKE);
  523. ath9k_hw_setrxabort(sc->sc_ah, 0);
  524. sc->sc_flags |= SC_OP_WAIT_FOR_BEACON;
  525. }
  526. chip_reset:
  527. ath_debug_stat_interrupt(sc, status);
  528. if (sched) {
  529. /* turn off every interrupt except SWBA */
  530. ath9k_hw_set_interrupts(ah, (sc->imask & ATH9K_INT_SWBA));
  531. tasklet_schedule(&sc->intr_tq);
  532. }
  533. return IRQ_HANDLED;
  534. #undef SCHED_INTR
  535. }
  536. static u32 ath_get_extchanmode(struct ath_softc *sc,
  537. struct ieee80211_channel *chan,
  538. enum nl80211_channel_type channel_type)
  539. {
  540. u32 chanmode = 0;
  541. switch (chan->band) {
  542. case IEEE80211_BAND_2GHZ:
  543. switch(channel_type) {
  544. case NL80211_CHAN_NO_HT:
  545. case NL80211_CHAN_HT20:
  546. chanmode = CHANNEL_G_HT20;
  547. break;
  548. case NL80211_CHAN_HT40PLUS:
  549. chanmode = CHANNEL_G_HT40PLUS;
  550. break;
  551. case NL80211_CHAN_HT40MINUS:
  552. chanmode = CHANNEL_G_HT40MINUS;
  553. break;
  554. }
  555. break;
  556. case IEEE80211_BAND_5GHZ:
  557. switch(channel_type) {
  558. case NL80211_CHAN_NO_HT:
  559. case NL80211_CHAN_HT20:
  560. chanmode = CHANNEL_A_HT20;
  561. break;
  562. case NL80211_CHAN_HT40PLUS:
  563. chanmode = CHANNEL_A_HT40PLUS;
  564. break;
  565. case NL80211_CHAN_HT40MINUS:
  566. chanmode = CHANNEL_A_HT40MINUS;
  567. break;
  568. }
  569. break;
  570. default:
  571. break;
  572. }
  573. return chanmode;
  574. }
  575. static int ath_setkey_tkip(struct ath_softc *sc, u16 keyix, const u8 *key,
  576. struct ath9k_keyval *hk, const u8 *addr,
  577. bool authenticator)
  578. {
  579. const u8 *key_rxmic;
  580. const u8 *key_txmic;
  581. key_txmic = key + NL80211_TKIP_DATA_OFFSET_TX_MIC_KEY;
  582. key_rxmic = key + NL80211_TKIP_DATA_OFFSET_RX_MIC_KEY;
  583. if (addr == NULL) {
  584. /*
  585. * Group key installation - only two key cache entries are used
  586. * regardless of splitmic capability since group key is only
  587. * used either for TX or RX.
  588. */
  589. if (authenticator) {
  590. memcpy(hk->kv_mic, key_txmic, sizeof(hk->kv_mic));
  591. memcpy(hk->kv_txmic, key_txmic, sizeof(hk->kv_mic));
  592. } else {
  593. memcpy(hk->kv_mic, key_rxmic, sizeof(hk->kv_mic));
  594. memcpy(hk->kv_txmic, key_rxmic, sizeof(hk->kv_mic));
  595. }
  596. return ath9k_hw_set_keycache_entry(sc->sc_ah, keyix, hk, addr);
  597. }
  598. if (!sc->splitmic) {
  599. /* TX and RX keys share the same key cache entry. */
  600. memcpy(hk->kv_mic, key_rxmic, sizeof(hk->kv_mic));
  601. memcpy(hk->kv_txmic, key_txmic, sizeof(hk->kv_txmic));
  602. return ath9k_hw_set_keycache_entry(sc->sc_ah, keyix, hk, addr);
  603. }
  604. /* Separate key cache entries for TX and RX */
  605. /* TX key goes at first index, RX key at +32. */
  606. memcpy(hk->kv_mic, key_txmic, sizeof(hk->kv_mic));
  607. if (!ath9k_hw_set_keycache_entry(sc->sc_ah, keyix, hk, NULL)) {
  608. /* TX MIC entry failed. No need to proceed further */
  609. DPRINTF(sc, ATH_DBG_FATAL,
  610. "Setting TX MIC Key Failed\n");
  611. return 0;
  612. }
  613. memcpy(hk->kv_mic, key_rxmic, sizeof(hk->kv_mic));
  614. /* XXX delete tx key on failure? */
  615. return ath9k_hw_set_keycache_entry(sc->sc_ah, keyix + 32, hk, addr);
  616. }
  617. static int ath_reserve_key_cache_slot_tkip(struct ath_softc *sc)
  618. {
  619. int i;
  620. for (i = IEEE80211_WEP_NKID; i < sc->keymax / 2; i++) {
  621. if (test_bit(i, sc->keymap) ||
  622. test_bit(i + 64, sc->keymap))
  623. continue; /* At least one part of TKIP key allocated */
  624. if (sc->splitmic &&
  625. (test_bit(i + 32, sc->keymap) ||
  626. test_bit(i + 64 + 32, sc->keymap)))
  627. continue; /* At least one part of TKIP key allocated */
  628. /* Found a free slot for a TKIP key */
  629. return i;
  630. }
  631. return -1;
  632. }
  633. static int ath_reserve_key_cache_slot(struct ath_softc *sc)
  634. {
  635. int i;
  636. /* First, try to find slots that would not be available for TKIP. */
  637. if (sc->splitmic) {
  638. for (i = IEEE80211_WEP_NKID; i < sc->keymax / 4; i++) {
  639. if (!test_bit(i, sc->keymap) &&
  640. (test_bit(i + 32, sc->keymap) ||
  641. test_bit(i + 64, sc->keymap) ||
  642. test_bit(i + 64 + 32, sc->keymap)))
  643. return i;
  644. if (!test_bit(i + 32, sc->keymap) &&
  645. (test_bit(i, sc->keymap) ||
  646. test_bit(i + 64, sc->keymap) ||
  647. test_bit(i + 64 + 32, sc->keymap)))
  648. return i + 32;
  649. if (!test_bit(i + 64, sc->keymap) &&
  650. (test_bit(i , sc->keymap) ||
  651. test_bit(i + 32, sc->keymap) ||
  652. test_bit(i + 64 + 32, sc->keymap)))
  653. return i + 64;
  654. if (!test_bit(i + 64 + 32, sc->keymap) &&
  655. (test_bit(i, sc->keymap) ||
  656. test_bit(i + 32, sc->keymap) ||
  657. test_bit(i + 64, sc->keymap)))
  658. return i + 64 + 32;
  659. }
  660. } else {
  661. for (i = IEEE80211_WEP_NKID; i < sc->keymax / 2; i++) {
  662. if (!test_bit(i, sc->keymap) &&
  663. test_bit(i + 64, sc->keymap))
  664. return i;
  665. if (test_bit(i, sc->keymap) &&
  666. !test_bit(i + 64, sc->keymap))
  667. return i + 64;
  668. }
  669. }
  670. /* No partially used TKIP slots, pick any available slot */
  671. for (i = IEEE80211_WEP_NKID; i < sc->keymax; i++) {
  672. /* Do not allow slots that could be needed for TKIP group keys
  673. * to be used. This limitation could be removed if we know that
  674. * TKIP will not be used. */
  675. if (i >= 64 && i < 64 + IEEE80211_WEP_NKID)
  676. continue;
  677. if (sc->splitmic) {
  678. if (i >= 32 && i < 32 + IEEE80211_WEP_NKID)
  679. continue;
  680. if (i >= 64 + 32 && i < 64 + 32 + IEEE80211_WEP_NKID)
  681. continue;
  682. }
  683. if (!test_bit(i, sc->keymap))
  684. return i; /* Found a free slot for a key */
  685. }
  686. /* No free slot found */
  687. return -1;
  688. }
  689. static int ath_key_config(struct ath_softc *sc,
  690. struct ieee80211_vif *vif,
  691. struct ieee80211_sta *sta,
  692. struct ieee80211_key_conf *key)
  693. {
  694. struct ath9k_keyval hk;
  695. const u8 *mac = NULL;
  696. int ret = 0;
  697. int idx;
  698. memset(&hk, 0, sizeof(hk));
  699. switch (key->alg) {
  700. case ALG_WEP:
  701. hk.kv_type = ATH9K_CIPHER_WEP;
  702. break;
  703. case ALG_TKIP:
  704. hk.kv_type = ATH9K_CIPHER_TKIP;
  705. break;
  706. case ALG_CCMP:
  707. hk.kv_type = ATH9K_CIPHER_AES_CCM;
  708. break;
  709. default:
  710. return -EOPNOTSUPP;
  711. }
  712. hk.kv_len = key->keylen;
  713. memcpy(hk.kv_val, key->key, key->keylen);
  714. if (!(key->flags & IEEE80211_KEY_FLAG_PAIRWISE)) {
  715. /* For now, use the default keys for broadcast keys. This may
  716. * need to change with virtual interfaces. */
  717. idx = key->keyidx;
  718. } else if (key->keyidx) {
  719. if (WARN_ON(!sta))
  720. return -EOPNOTSUPP;
  721. mac = sta->addr;
  722. if (vif->type != NL80211_IFTYPE_AP) {
  723. /* Only keyidx 0 should be used with unicast key, but
  724. * allow this for client mode for now. */
  725. idx = key->keyidx;
  726. } else
  727. return -EIO;
  728. } else {
  729. if (WARN_ON(!sta))
  730. return -EOPNOTSUPP;
  731. mac = sta->addr;
  732. if (key->alg == ALG_TKIP)
  733. idx = ath_reserve_key_cache_slot_tkip(sc);
  734. else
  735. idx = ath_reserve_key_cache_slot(sc);
  736. if (idx < 0)
  737. return -ENOSPC; /* no free key cache entries */
  738. }
  739. if (key->alg == ALG_TKIP)
  740. ret = ath_setkey_tkip(sc, idx, key->key, &hk, mac,
  741. vif->type == NL80211_IFTYPE_AP);
  742. else
  743. ret = ath9k_hw_set_keycache_entry(sc->sc_ah, idx, &hk, mac);
  744. if (!ret)
  745. return -EIO;
  746. set_bit(idx, sc->keymap);
  747. if (key->alg == ALG_TKIP) {
  748. set_bit(idx + 64, sc->keymap);
  749. if (sc->splitmic) {
  750. set_bit(idx + 32, sc->keymap);
  751. set_bit(idx + 64 + 32, sc->keymap);
  752. }
  753. }
  754. return idx;
  755. }
  756. static void ath_key_delete(struct ath_softc *sc, struct ieee80211_key_conf *key)
  757. {
  758. ath9k_hw_keyreset(sc->sc_ah, key->hw_key_idx);
  759. if (key->hw_key_idx < IEEE80211_WEP_NKID)
  760. return;
  761. clear_bit(key->hw_key_idx, sc->keymap);
  762. if (key->alg != ALG_TKIP)
  763. return;
  764. clear_bit(key->hw_key_idx + 64, sc->keymap);
  765. if (sc->splitmic) {
  766. clear_bit(key->hw_key_idx + 32, sc->keymap);
  767. clear_bit(key->hw_key_idx + 64 + 32, sc->keymap);
  768. }
  769. }
  770. static void setup_ht_cap(struct ath_softc *sc,
  771. struct ieee80211_sta_ht_cap *ht_info)
  772. {
  773. u8 tx_streams, rx_streams;
  774. ht_info->ht_supported = true;
  775. ht_info->cap = IEEE80211_HT_CAP_SUP_WIDTH_20_40 |
  776. IEEE80211_HT_CAP_SM_PS |
  777. IEEE80211_HT_CAP_SGI_40 |
  778. IEEE80211_HT_CAP_DSSSCCK40;
  779. ht_info->ampdu_factor = IEEE80211_HT_MAX_AMPDU_64K;
  780. ht_info->ampdu_density = IEEE80211_HT_MPDU_DENSITY_8;
  781. /* set up supported mcs set */
  782. memset(&ht_info->mcs, 0, sizeof(ht_info->mcs));
  783. tx_streams = !(sc->tx_chainmask & (sc->tx_chainmask - 1)) ? 1 : 2;
  784. rx_streams = !(sc->rx_chainmask & (sc->rx_chainmask - 1)) ? 1 : 2;
  785. if (tx_streams != rx_streams) {
  786. DPRINTF(sc, ATH_DBG_CONFIG, "TX streams %d, RX streams: %d\n",
  787. tx_streams, rx_streams);
  788. ht_info->mcs.tx_params |= IEEE80211_HT_MCS_TX_RX_DIFF;
  789. ht_info->mcs.tx_params |= ((tx_streams - 1) <<
  790. IEEE80211_HT_MCS_TX_MAX_STREAMS_SHIFT);
  791. }
  792. ht_info->mcs.rx_mask[0] = 0xff;
  793. if (rx_streams >= 2)
  794. ht_info->mcs.rx_mask[1] = 0xff;
  795. ht_info->mcs.tx_params |= IEEE80211_HT_MCS_TX_DEFINED;
  796. }
  797. static void ath9k_bss_assoc_info(struct ath_softc *sc,
  798. struct ieee80211_vif *vif,
  799. struct ieee80211_bss_conf *bss_conf)
  800. {
  801. if (bss_conf->assoc) {
  802. DPRINTF(sc, ATH_DBG_CONFIG, "Bss Info ASSOC %d, bssid: %pM\n",
  803. bss_conf->aid, sc->curbssid);
  804. /* New association, store aid */
  805. sc->curaid = bss_conf->aid;
  806. ath9k_hw_write_associd(sc);
  807. /*
  808. * Request a re-configuration of Beacon related timers
  809. * on the receipt of the first Beacon frame (i.e.,
  810. * after time sync with the AP).
  811. */
  812. sc->sc_flags |= SC_OP_BEACON_SYNC;
  813. /* Configure the beacon */
  814. ath_beacon_config(sc, vif);
  815. /* Reset rssi stats */
  816. sc->sc_ah->stats.avgbrssi = ATH_RSSI_DUMMY_MARKER;
  817. ath_start_ani(sc);
  818. } else {
  819. DPRINTF(sc, ATH_DBG_CONFIG, "Bss Info DISASSOC\n");
  820. sc->curaid = 0;
  821. /* Stop ANI */
  822. del_timer_sync(&sc->ani.timer);
  823. }
  824. }
  825. /********************************/
  826. /* LED functions */
  827. /********************************/
  828. static void ath_led_blink_work(struct work_struct *work)
  829. {
  830. struct ath_softc *sc = container_of(work, struct ath_softc,
  831. ath_led_blink_work.work);
  832. if (!(sc->sc_flags & SC_OP_LED_ASSOCIATED))
  833. return;
  834. if ((sc->led_on_duration == ATH_LED_ON_DURATION_IDLE) ||
  835. (sc->led_off_duration == ATH_LED_OFF_DURATION_IDLE))
  836. ath9k_hw_set_gpio(sc->sc_ah, sc->sc_ah->led_pin, 0);
  837. else
  838. ath9k_hw_set_gpio(sc->sc_ah, sc->sc_ah->led_pin,
  839. (sc->sc_flags & SC_OP_LED_ON) ? 1 : 0);
  840. ieee80211_queue_delayed_work(sc->hw,
  841. &sc->ath_led_blink_work,
  842. (sc->sc_flags & SC_OP_LED_ON) ?
  843. msecs_to_jiffies(sc->led_off_duration) :
  844. msecs_to_jiffies(sc->led_on_duration));
  845. sc->led_on_duration = sc->led_on_cnt ?
  846. max((ATH_LED_ON_DURATION_IDLE - sc->led_on_cnt), 25) :
  847. ATH_LED_ON_DURATION_IDLE;
  848. sc->led_off_duration = sc->led_off_cnt ?
  849. max((ATH_LED_OFF_DURATION_IDLE - sc->led_off_cnt), 10) :
  850. ATH_LED_OFF_DURATION_IDLE;
  851. sc->led_on_cnt = sc->led_off_cnt = 0;
  852. if (sc->sc_flags & SC_OP_LED_ON)
  853. sc->sc_flags &= ~SC_OP_LED_ON;
  854. else
  855. sc->sc_flags |= SC_OP_LED_ON;
  856. }
  857. static void ath_led_brightness(struct led_classdev *led_cdev,
  858. enum led_brightness brightness)
  859. {
  860. struct ath_led *led = container_of(led_cdev, struct ath_led, led_cdev);
  861. struct ath_softc *sc = led->sc;
  862. switch (brightness) {
  863. case LED_OFF:
  864. if (led->led_type == ATH_LED_ASSOC ||
  865. led->led_type == ATH_LED_RADIO) {
  866. ath9k_hw_set_gpio(sc->sc_ah, sc->sc_ah->led_pin,
  867. (led->led_type == ATH_LED_RADIO));
  868. sc->sc_flags &= ~SC_OP_LED_ASSOCIATED;
  869. if (led->led_type == ATH_LED_RADIO)
  870. sc->sc_flags &= ~SC_OP_LED_ON;
  871. } else {
  872. sc->led_off_cnt++;
  873. }
  874. break;
  875. case LED_FULL:
  876. if (led->led_type == ATH_LED_ASSOC) {
  877. sc->sc_flags |= SC_OP_LED_ASSOCIATED;
  878. ieee80211_queue_delayed_work(sc->hw,
  879. &sc->ath_led_blink_work, 0);
  880. } else if (led->led_type == ATH_LED_RADIO) {
  881. ath9k_hw_set_gpio(sc->sc_ah, sc->sc_ah->led_pin, 0);
  882. sc->sc_flags |= SC_OP_LED_ON;
  883. } else {
  884. sc->led_on_cnt++;
  885. }
  886. break;
  887. default:
  888. break;
  889. }
  890. }
  891. static int ath_register_led(struct ath_softc *sc, struct ath_led *led,
  892. char *trigger)
  893. {
  894. int ret;
  895. led->sc = sc;
  896. led->led_cdev.name = led->name;
  897. led->led_cdev.default_trigger = trigger;
  898. led->led_cdev.brightness_set = ath_led_brightness;
  899. ret = led_classdev_register(wiphy_dev(sc->hw->wiphy), &led->led_cdev);
  900. if (ret)
  901. DPRINTF(sc, ATH_DBG_FATAL,
  902. "Failed to register led:%s", led->name);
  903. else
  904. led->registered = 1;
  905. return ret;
  906. }
  907. static void ath_unregister_led(struct ath_led *led)
  908. {
  909. if (led->registered) {
  910. led_classdev_unregister(&led->led_cdev);
  911. led->registered = 0;
  912. }
  913. }
  914. static void ath_deinit_leds(struct ath_softc *sc)
  915. {
  916. ath_unregister_led(&sc->assoc_led);
  917. sc->sc_flags &= ~SC_OP_LED_ASSOCIATED;
  918. ath_unregister_led(&sc->tx_led);
  919. ath_unregister_led(&sc->rx_led);
  920. ath_unregister_led(&sc->radio_led);
  921. ath9k_hw_set_gpio(sc->sc_ah, sc->sc_ah->led_pin, 1);
  922. }
  923. static void ath_init_leds(struct ath_softc *sc)
  924. {
  925. char *trigger;
  926. int ret;
  927. if (AR_SREV_9287(sc->sc_ah))
  928. sc->sc_ah->led_pin = ATH_LED_PIN_9287;
  929. else
  930. sc->sc_ah->led_pin = ATH_LED_PIN_DEF;
  931. /* Configure gpio 1 for output */
  932. ath9k_hw_cfg_output(sc->sc_ah, sc->sc_ah->led_pin,
  933. AR_GPIO_OUTPUT_MUX_AS_OUTPUT);
  934. /* LED off, active low */
  935. ath9k_hw_set_gpio(sc->sc_ah, sc->sc_ah->led_pin, 1);
  936. INIT_DELAYED_WORK(&sc->ath_led_blink_work, ath_led_blink_work);
  937. trigger = ieee80211_get_radio_led_name(sc->hw);
  938. snprintf(sc->radio_led.name, sizeof(sc->radio_led.name),
  939. "ath9k-%s::radio", wiphy_name(sc->hw->wiphy));
  940. ret = ath_register_led(sc, &sc->radio_led, trigger);
  941. sc->radio_led.led_type = ATH_LED_RADIO;
  942. if (ret)
  943. goto fail;
  944. trigger = ieee80211_get_assoc_led_name(sc->hw);
  945. snprintf(sc->assoc_led.name, sizeof(sc->assoc_led.name),
  946. "ath9k-%s::assoc", wiphy_name(sc->hw->wiphy));
  947. ret = ath_register_led(sc, &sc->assoc_led, trigger);
  948. sc->assoc_led.led_type = ATH_LED_ASSOC;
  949. if (ret)
  950. goto fail;
  951. trigger = ieee80211_get_tx_led_name(sc->hw);
  952. snprintf(sc->tx_led.name, sizeof(sc->tx_led.name),
  953. "ath9k-%s::tx", wiphy_name(sc->hw->wiphy));
  954. ret = ath_register_led(sc, &sc->tx_led, trigger);
  955. sc->tx_led.led_type = ATH_LED_TX;
  956. if (ret)
  957. goto fail;
  958. trigger = ieee80211_get_rx_led_name(sc->hw);
  959. snprintf(sc->rx_led.name, sizeof(sc->rx_led.name),
  960. "ath9k-%s::rx", wiphy_name(sc->hw->wiphy));
  961. ret = ath_register_led(sc, &sc->rx_led, trigger);
  962. sc->rx_led.led_type = ATH_LED_RX;
  963. if (ret)
  964. goto fail;
  965. return;
  966. fail:
  967. cancel_delayed_work_sync(&sc->ath_led_blink_work);
  968. ath_deinit_leds(sc);
  969. }
  970. void ath_radio_enable(struct ath_softc *sc)
  971. {
  972. struct ath_hw *ah = sc->sc_ah;
  973. struct ieee80211_channel *channel = sc->hw->conf.channel;
  974. int r;
  975. ath9k_ps_wakeup(sc);
  976. ath9k_hw_configpcipowersave(ah, 0, 0);
  977. if (!ah->curchan)
  978. ah->curchan = ath_get_curchannel(sc, sc->hw);
  979. spin_lock_bh(&sc->sc_resetlock);
  980. r = ath9k_hw_reset(ah, ah->curchan, false);
  981. if (r) {
  982. DPRINTF(sc, ATH_DBG_FATAL,
  983. "Unable to reset channel %u (%uMhz) ",
  984. "reset status %d\n",
  985. channel->center_freq, r);
  986. }
  987. spin_unlock_bh(&sc->sc_resetlock);
  988. ath_update_txpow(sc);
  989. if (ath_startrecv(sc) != 0) {
  990. DPRINTF(sc, ATH_DBG_FATAL,
  991. "Unable to restart recv logic\n");
  992. return;
  993. }
  994. if (sc->sc_flags & SC_OP_BEACONS)
  995. ath_beacon_config(sc, NULL); /* restart beacons */
  996. /* Re-Enable interrupts */
  997. ath9k_hw_set_interrupts(ah, sc->imask);
  998. /* Enable LED */
  999. ath9k_hw_cfg_output(ah, ah->led_pin,
  1000. AR_GPIO_OUTPUT_MUX_AS_OUTPUT);
  1001. ath9k_hw_set_gpio(ah, ah->led_pin, 0);
  1002. ieee80211_wake_queues(sc->hw);
  1003. ath9k_ps_restore(sc);
  1004. }
  1005. void ath_radio_disable(struct ath_softc *sc)
  1006. {
  1007. struct ath_hw *ah = sc->sc_ah;
  1008. struct ieee80211_channel *channel = sc->hw->conf.channel;
  1009. int r;
  1010. ath9k_ps_wakeup(sc);
  1011. ieee80211_stop_queues(sc->hw);
  1012. /* Disable LED */
  1013. ath9k_hw_set_gpio(ah, ah->led_pin, 1);
  1014. ath9k_hw_cfg_gpio_input(ah, ah->led_pin);
  1015. /* Disable interrupts */
  1016. ath9k_hw_set_interrupts(ah, 0);
  1017. ath_drain_all_txq(sc, false); /* clear pending tx frames */
  1018. ath_stoprecv(sc); /* turn off frame recv */
  1019. ath_flushrecv(sc); /* flush recv queue */
  1020. if (!ah->curchan)
  1021. ah->curchan = ath_get_curchannel(sc, sc->hw);
  1022. spin_lock_bh(&sc->sc_resetlock);
  1023. r = ath9k_hw_reset(ah, ah->curchan, false);
  1024. if (r) {
  1025. DPRINTF(sc, ATH_DBG_FATAL,
  1026. "Unable to reset channel %u (%uMhz) "
  1027. "reset status %d\n",
  1028. channel->center_freq, r);
  1029. }
  1030. spin_unlock_bh(&sc->sc_resetlock);
  1031. ath9k_hw_phy_disable(ah);
  1032. ath9k_hw_configpcipowersave(ah, 1, 1);
  1033. ath9k_ps_restore(sc);
  1034. ath9k_hw_setpower(ah, ATH9K_PM_FULL_SLEEP);
  1035. }
  1036. /*******************/
  1037. /* Rfkill */
  1038. /*******************/
  1039. static bool ath_is_rfkill_set(struct ath_softc *sc)
  1040. {
  1041. struct ath_hw *ah = sc->sc_ah;
  1042. return ath9k_hw_gpio_get(ah, ah->rfkill_gpio) ==
  1043. ah->rfkill_polarity;
  1044. }
  1045. static void ath9k_rfkill_poll_state(struct ieee80211_hw *hw)
  1046. {
  1047. struct ath_wiphy *aphy = hw->priv;
  1048. struct ath_softc *sc = aphy->sc;
  1049. bool blocked = !!ath_is_rfkill_set(sc);
  1050. wiphy_rfkill_set_hw_state(hw->wiphy, blocked);
  1051. }
  1052. static void ath_start_rfkill_poll(struct ath_softc *sc)
  1053. {
  1054. struct ath_hw *ah = sc->sc_ah;
  1055. if (ah->caps.hw_caps & ATH9K_HW_CAP_RFSILENT)
  1056. wiphy_rfkill_start_polling(sc->hw->wiphy);
  1057. }
  1058. void ath_cleanup(struct ath_softc *sc)
  1059. {
  1060. ath_detach(sc);
  1061. free_irq(sc->irq, sc);
  1062. ath_bus_cleanup(sc);
  1063. kfree(sc->sec_wiphy);
  1064. ieee80211_free_hw(sc->hw);
  1065. }
  1066. void ath_detach(struct ath_softc *sc)
  1067. {
  1068. struct ieee80211_hw *hw = sc->hw;
  1069. int i = 0;
  1070. ath9k_ps_wakeup(sc);
  1071. DPRINTF(sc, ATH_DBG_CONFIG, "Detach ATH hw\n");
  1072. ath_deinit_leds(sc);
  1073. wiphy_rfkill_stop_polling(sc->hw->wiphy);
  1074. for (i = 0; i < sc->num_sec_wiphy; i++) {
  1075. struct ath_wiphy *aphy = sc->sec_wiphy[i];
  1076. if (aphy == NULL)
  1077. continue;
  1078. sc->sec_wiphy[i] = NULL;
  1079. ieee80211_unregister_hw(aphy->hw);
  1080. ieee80211_free_hw(aphy->hw);
  1081. }
  1082. ieee80211_unregister_hw(hw);
  1083. ath_rx_cleanup(sc);
  1084. ath_tx_cleanup(sc);
  1085. tasklet_kill(&sc->intr_tq);
  1086. tasklet_kill(&sc->bcon_tasklet);
  1087. if (!(sc->sc_flags & SC_OP_INVALID))
  1088. ath9k_hw_setpower(sc->sc_ah, ATH9K_PM_AWAKE);
  1089. /* cleanup tx queues */
  1090. for (i = 0; i < ATH9K_NUM_TX_QUEUES; i++)
  1091. if (ATH_TXQ_SETUP(sc, i))
  1092. ath_tx_cleanupq(sc, &sc->tx.txq[i]);
  1093. if ((sc->btcoex_info.no_stomp_timer) &&
  1094. sc->btcoex_info.btcoex_scheme == ATH_BTCOEX_CFG_3WIRE)
  1095. ath_gen_timer_free(sc->sc_ah, sc->btcoex_info.no_stomp_timer);
  1096. ath9k_hw_detach(sc->sc_ah);
  1097. sc->sc_ah = NULL;
  1098. ath9k_exit_debug(sc);
  1099. }
  1100. static int ath9k_reg_notifier(struct wiphy *wiphy,
  1101. struct regulatory_request *request)
  1102. {
  1103. struct ieee80211_hw *hw = wiphy_to_ieee80211_hw(wiphy);
  1104. struct ath_wiphy *aphy = hw->priv;
  1105. struct ath_softc *sc = aphy->sc;
  1106. struct ath_regulatory *reg = &sc->common.regulatory;
  1107. return ath_reg_notifier_apply(wiphy, request, reg);
  1108. }
  1109. /*
  1110. * Initialize and fill ath_softc, ath_sofct is the
  1111. * "Software Carrier" struct. Historically it has existed
  1112. * to allow the separation between hardware specific
  1113. * variables (now in ath_hw) and driver specific variables.
  1114. */
  1115. static int ath_init_softc(u16 devid, struct ath_softc *sc, u16 subsysid)
  1116. {
  1117. struct ath_hw *ah = NULL;
  1118. int r = 0, i;
  1119. int csz = 0;
  1120. /* XXX: hardware will not be ready until ath_open() being called */
  1121. sc->sc_flags |= SC_OP_INVALID;
  1122. if (ath9k_init_debug(sc) < 0)
  1123. printk(KERN_ERR "Unable to create debugfs files\n");
  1124. spin_lock_init(&sc->wiphy_lock);
  1125. spin_lock_init(&sc->sc_resetlock);
  1126. spin_lock_init(&sc->sc_serial_rw);
  1127. spin_lock_init(&sc->ani_lock);
  1128. spin_lock_init(&sc->sc_pm_lock);
  1129. mutex_init(&sc->mutex);
  1130. tasklet_init(&sc->intr_tq, ath9k_tasklet, (unsigned long)sc);
  1131. tasklet_init(&sc->bcon_tasklet, ath_beacon_tasklet,
  1132. (unsigned long)sc);
  1133. /*
  1134. * Cache line size is used to size and align various
  1135. * structures used to communicate with the hardware.
  1136. */
  1137. ath_read_cachesize(sc, &csz);
  1138. /* XXX assert csz is non-zero */
  1139. sc->common.cachelsz = csz << 2; /* convert to bytes */
  1140. ah = kzalloc(sizeof(struct ath_hw), GFP_KERNEL);
  1141. if (!ah) {
  1142. r = -ENOMEM;
  1143. goto bad_no_ah;
  1144. }
  1145. ah->ah_sc = sc;
  1146. ah->hw_version.devid = devid;
  1147. ah->hw_version.subsysid = subsysid;
  1148. sc->sc_ah = ah;
  1149. r = ath9k_hw_init(ah);
  1150. if (r) {
  1151. DPRINTF(sc, ATH_DBG_FATAL,
  1152. "Unable to initialize hardware; "
  1153. "initialization status: %d\n", r);
  1154. goto bad;
  1155. }
  1156. /* Get the hardware key cache size. */
  1157. sc->keymax = ah->caps.keycache_size;
  1158. if (sc->keymax > ATH_KEYMAX) {
  1159. DPRINTF(sc, ATH_DBG_ANY,
  1160. "Warning, using only %u entries in %u key cache\n",
  1161. ATH_KEYMAX, sc->keymax);
  1162. sc->keymax = ATH_KEYMAX;
  1163. }
  1164. /*
  1165. * Reset the key cache since some parts do not
  1166. * reset the contents on initial power up.
  1167. */
  1168. for (i = 0; i < sc->keymax; i++)
  1169. ath9k_hw_keyreset(ah, (u16) i);
  1170. /* default to MONITOR mode */
  1171. sc->sc_ah->opmode = NL80211_IFTYPE_MONITOR;
  1172. /* Setup rate tables */
  1173. ath_rate_attach(sc);
  1174. ath_setup_rates(sc, IEEE80211_BAND_2GHZ);
  1175. ath_setup_rates(sc, IEEE80211_BAND_5GHZ);
  1176. /*
  1177. * Allocate hardware transmit queues: one queue for
  1178. * beacon frames and one data queue for each QoS
  1179. * priority. Note that the hal handles reseting
  1180. * these queues at the needed time.
  1181. */
  1182. sc->beacon.beaconq = ath_beaconq_setup(ah);
  1183. if (sc->beacon.beaconq == -1) {
  1184. DPRINTF(sc, ATH_DBG_FATAL,
  1185. "Unable to setup a beacon xmit queue\n");
  1186. r = -EIO;
  1187. goto bad2;
  1188. }
  1189. sc->beacon.cabq = ath_txq_setup(sc, ATH9K_TX_QUEUE_CAB, 0);
  1190. if (sc->beacon.cabq == NULL) {
  1191. DPRINTF(sc, ATH_DBG_FATAL,
  1192. "Unable to setup CAB xmit queue\n");
  1193. r = -EIO;
  1194. goto bad2;
  1195. }
  1196. sc->config.cabqReadytime = ATH_CABQ_READY_TIME;
  1197. ath_cabq_update(sc);
  1198. for (i = 0; i < ARRAY_SIZE(sc->tx.hwq_map); i++)
  1199. sc->tx.hwq_map[i] = -1;
  1200. /* Setup data queues */
  1201. /* NB: ensure BK queue is the lowest priority h/w queue */
  1202. if (!ath_tx_setup(sc, ATH9K_WME_AC_BK)) {
  1203. DPRINTF(sc, ATH_DBG_FATAL,
  1204. "Unable to setup xmit queue for BK traffic\n");
  1205. r = -EIO;
  1206. goto bad2;
  1207. }
  1208. if (!ath_tx_setup(sc, ATH9K_WME_AC_BE)) {
  1209. DPRINTF(sc, ATH_DBG_FATAL,
  1210. "Unable to setup xmit queue for BE traffic\n");
  1211. r = -EIO;
  1212. goto bad2;
  1213. }
  1214. if (!ath_tx_setup(sc, ATH9K_WME_AC_VI)) {
  1215. DPRINTF(sc, ATH_DBG_FATAL,
  1216. "Unable to setup xmit queue for VI traffic\n");
  1217. r = -EIO;
  1218. goto bad2;
  1219. }
  1220. if (!ath_tx_setup(sc, ATH9K_WME_AC_VO)) {
  1221. DPRINTF(sc, ATH_DBG_FATAL,
  1222. "Unable to setup xmit queue for VO traffic\n");
  1223. r = -EIO;
  1224. goto bad2;
  1225. }
  1226. /* Initializes the noise floor to a reasonable default value.
  1227. * Later on this will be updated during ANI processing. */
  1228. sc->ani.noise_floor = ATH_DEFAULT_NOISE_FLOOR;
  1229. setup_timer(&sc->ani.timer, ath_ani_calibrate, (unsigned long)sc);
  1230. if (ath9k_hw_getcapability(ah, ATH9K_CAP_CIPHER,
  1231. ATH9K_CIPHER_TKIP, NULL)) {
  1232. /*
  1233. * Whether we should enable h/w TKIP MIC.
  1234. * XXX: if we don't support WME TKIP MIC, then we wouldn't
  1235. * report WMM capable, so it's always safe to turn on
  1236. * TKIP MIC in this case.
  1237. */
  1238. ath9k_hw_setcapability(sc->sc_ah, ATH9K_CAP_TKIP_MIC,
  1239. 0, 1, NULL);
  1240. }
  1241. /*
  1242. * Check whether the separate key cache entries
  1243. * are required to handle both tx+rx MIC keys.
  1244. * With split mic keys the number of stations is limited
  1245. * to 27 otherwise 59.
  1246. */
  1247. if (ath9k_hw_getcapability(ah, ATH9K_CAP_CIPHER,
  1248. ATH9K_CIPHER_TKIP, NULL)
  1249. && ath9k_hw_getcapability(ah, ATH9K_CAP_CIPHER,
  1250. ATH9K_CIPHER_MIC, NULL)
  1251. && ath9k_hw_getcapability(ah, ATH9K_CAP_TKIP_SPLIT,
  1252. 0, NULL))
  1253. sc->splitmic = 1;
  1254. /* turn on mcast key search if possible */
  1255. if (!ath9k_hw_getcapability(ah, ATH9K_CAP_MCAST_KEYSRCH, 0, NULL))
  1256. (void)ath9k_hw_setcapability(ah, ATH9K_CAP_MCAST_KEYSRCH, 1,
  1257. 1, NULL);
  1258. sc->config.txpowlimit = ATH_TXPOWER_MAX;
  1259. /* 11n Capabilities */
  1260. if (ah->caps.hw_caps & ATH9K_HW_CAP_HT) {
  1261. sc->sc_flags |= SC_OP_TXAGGR;
  1262. sc->sc_flags |= SC_OP_RXAGGR;
  1263. }
  1264. sc->tx_chainmask = ah->caps.tx_chainmask;
  1265. sc->rx_chainmask = ah->caps.rx_chainmask;
  1266. ath9k_hw_setcapability(ah, ATH9K_CAP_DIVERSITY, 1, true, NULL);
  1267. sc->rx.defant = ath9k_hw_getdefantenna(ah);
  1268. if (ah->caps.hw_caps & ATH9K_HW_CAP_BSSIDMASK)
  1269. memcpy(sc->bssidmask, ath_bcast_mac, ETH_ALEN);
  1270. sc->beacon.slottime = ATH9K_SLOT_TIME_9; /* default to short slot time */
  1271. /* initialize beacon slots */
  1272. for (i = 0; i < ARRAY_SIZE(sc->beacon.bslot); i++) {
  1273. sc->beacon.bslot[i] = NULL;
  1274. sc->beacon.bslot_aphy[i] = NULL;
  1275. }
  1276. /* setup channels and rates */
  1277. sc->sbands[IEEE80211_BAND_2GHZ].channels = ath9k_2ghz_chantable;
  1278. sc->sbands[IEEE80211_BAND_2GHZ].bitrates =
  1279. sc->rates[IEEE80211_BAND_2GHZ];
  1280. sc->sbands[IEEE80211_BAND_2GHZ].band = IEEE80211_BAND_2GHZ;
  1281. sc->sbands[IEEE80211_BAND_2GHZ].n_channels =
  1282. ARRAY_SIZE(ath9k_2ghz_chantable);
  1283. if (test_bit(ATH9K_MODE_11A, sc->sc_ah->caps.wireless_modes)) {
  1284. sc->sbands[IEEE80211_BAND_5GHZ].channels = ath9k_5ghz_chantable;
  1285. sc->sbands[IEEE80211_BAND_5GHZ].bitrates =
  1286. sc->rates[IEEE80211_BAND_5GHZ];
  1287. sc->sbands[IEEE80211_BAND_5GHZ].band = IEEE80211_BAND_5GHZ;
  1288. sc->sbands[IEEE80211_BAND_5GHZ].n_channels =
  1289. ARRAY_SIZE(ath9k_5ghz_chantable);
  1290. }
  1291. if (sc->btcoex_info.btcoex_scheme != ATH_BTCOEX_CFG_NONE) {
  1292. r = ath9k_hw_btcoex_init(ah);
  1293. if (r)
  1294. goto bad2;
  1295. }
  1296. return 0;
  1297. bad2:
  1298. /* cleanup tx queues */
  1299. for (i = 0; i < ATH9K_NUM_TX_QUEUES; i++)
  1300. if (ATH_TXQ_SETUP(sc, i))
  1301. ath_tx_cleanupq(sc, &sc->tx.txq[i]);
  1302. bad:
  1303. ath9k_hw_detach(ah);
  1304. sc->sc_ah = NULL;
  1305. bad_no_ah:
  1306. ath9k_exit_debug(sc);
  1307. return r;
  1308. }
  1309. void ath_set_hw_capab(struct ath_softc *sc, struct ieee80211_hw *hw)
  1310. {
  1311. hw->flags = IEEE80211_HW_RX_INCLUDES_FCS |
  1312. IEEE80211_HW_HOST_BROADCAST_PS_BUFFERING |
  1313. IEEE80211_HW_SIGNAL_DBM |
  1314. IEEE80211_HW_AMPDU_AGGREGATION |
  1315. IEEE80211_HW_SUPPORTS_PS |
  1316. IEEE80211_HW_PS_NULLFUNC_STACK |
  1317. IEEE80211_HW_SPECTRUM_MGMT;
  1318. if (AR_SREV_9160_10_OR_LATER(sc->sc_ah) || modparam_nohwcrypt)
  1319. hw->flags |= IEEE80211_HW_MFP_CAPABLE;
  1320. hw->wiphy->interface_modes =
  1321. BIT(NL80211_IFTYPE_AP) |
  1322. BIT(NL80211_IFTYPE_STATION) |
  1323. BIT(NL80211_IFTYPE_ADHOC) |
  1324. BIT(NL80211_IFTYPE_MESH_POINT);
  1325. hw->wiphy->ps_default = false;
  1326. hw->queues = 4;
  1327. hw->max_rates = 4;
  1328. hw->channel_change_time = 5000;
  1329. hw->max_listen_interval = 10;
  1330. /* Hardware supports 10 but we use 4 */
  1331. hw->max_rate_tries = 4;
  1332. hw->sta_data_size = sizeof(struct ath_node);
  1333. hw->vif_data_size = sizeof(struct ath_vif);
  1334. hw->rate_control_algorithm = "ath9k_rate_control";
  1335. hw->wiphy->bands[IEEE80211_BAND_2GHZ] =
  1336. &sc->sbands[IEEE80211_BAND_2GHZ];
  1337. if (test_bit(ATH9K_MODE_11A, sc->sc_ah->caps.wireless_modes))
  1338. hw->wiphy->bands[IEEE80211_BAND_5GHZ] =
  1339. &sc->sbands[IEEE80211_BAND_5GHZ];
  1340. }
  1341. /* Device driver core initialization */
  1342. int ath_init_device(u16 devid, struct ath_softc *sc, u16 subsysid)
  1343. {
  1344. struct ieee80211_hw *hw = sc->hw;
  1345. int error = 0, i;
  1346. struct ath_regulatory *reg;
  1347. DPRINTF(sc, ATH_DBG_CONFIG, "Attach ATH hw\n");
  1348. error = ath_init_softc(devid, sc, subsysid);
  1349. if (error != 0)
  1350. return error;
  1351. /* get mac address from hardware and set in mac80211 */
  1352. SET_IEEE80211_PERM_ADDR(hw, sc->sc_ah->macaddr);
  1353. ath_set_hw_capab(sc, hw);
  1354. error = ath_regd_init(&sc->common.regulatory, sc->hw->wiphy,
  1355. ath9k_reg_notifier);
  1356. if (error)
  1357. return error;
  1358. reg = &sc->common.regulatory;
  1359. if (sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_HT) {
  1360. setup_ht_cap(sc, &sc->sbands[IEEE80211_BAND_2GHZ].ht_cap);
  1361. if (test_bit(ATH9K_MODE_11A, sc->sc_ah->caps.wireless_modes))
  1362. setup_ht_cap(sc, &sc->sbands[IEEE80211_BAND_5GHZ].ht_cap);
  1363. }
  1364. /* initialize tx/rx engine */
  1365. error = ath_tx_init(sc, ATH_TXBUF);
  1366. if (error != 0)
  1367. goto error_attach;
  1368. error = ath_rx_init(sc, ATH_RXBUF);
  1369. if (error != 0)
  1370. goto error_attach;
  1371. INIT_WORK(&sc->chan_work, ath9k_wiphy_chan_work);
  1372. INIT_DELAYED_WORK(&sc->wiphy_work, ath9k_wiphy_work);
  1373. sc->wiphy_scheduler_int = msecs_to_jiffies(500);
  1374. error = ieee80211_register_hw(hw);
  1375. if (!ath_is_world_regd(reg)) {
  1376. error = regulatory_hint(hw->wiphy, reg->alpha2);
  1377. if (error)
  1378. goto error_attach;
  1379. }
  1380. /* Initialize LED control */
  1381. ath_init_leds(sc);
  1382. ath_start_rfkill_poll(sc);
  1383. return 0;
  1384. error_attach:
  1385. /* cleanup tx queues */
  1386. for (i = 0; i < ATH9K_NUM_TX_QUEUES; i++)
  1387. if (ATH_TXQ_SETUP(sc, i))
  1388. ath_tx_cleanupq(sc, &sc->tx.txq[i]);
  1389. ath9k_hw_detach(sc->sc_ah);
  1390. sc->sc_ah = NULL;
  1391. ath9k_exit_debug(sc);
  1392. return error;
  1393. }
  1394. int ath_reset(struct ath_softc *sc, bool retry_tx)
  1395. {
  1396. struct ath_hw *ah = sc->sc_ah;
  1397. struct ieee80211_hw *hw = sc->hw;
  1398. int r;
  1399. ath9k_hw_set_interrupts(ah, 0);
  1400. ath_drain_all_txq(sc, retry_tx);
  1401. ath_stoprecv(sc);
  1402. ath_flushrecv(sc);
  1403. spin_lock_bh(&sc->sc_resetlock);
  1404. r = ath9k_hw_reset(ah, sc->sc_ah->curchan, false);
  1405. if (r)
  1406. DPRINTF(sc, ATH_DBG_FATAL,
  1407. "Unable to reset hardware; reset status %d\n", r);
  1408. spin_unlock_bh(&sc->sc_resetlock);
  1409. if (ath_startrecv(sc) != 0)
  1410. DPRINTF(sc, ATH_DBG_FATAL, "Unable to start recv logic\n");
  1411. /*
  1412. * We may be doing a reset in response to a request
  1413. * that changes the channel so update any state that
  1414. * might change as a result.
  1415. */
  1416. ath_cache_conf_rate(sc, &hw->conf);
  1417. ath_update_txpow(sc);
  1418. if (sc->sc_flags & SC_OP_BEACONS)
  1419. ath_beacon_config(sc, NULL); /* restart beacons */
  1420. ath9k_hw_set_interrupts(ah, sc->imask);
  1421. if (retry_tx) {
  1422. int i;
  1423. for (i = 0; i < ATH9K_NUM_TX_QUEUES; i++) {
  1424. if (ATH_TXQ_SETUP(sc, i)) {
  1425. spin_lock_bh(&sc->tx.txq[i].axq_lock);
  1426. ath_txq_schedule(sc, &sc->tx.txq[i]);
  1427. spin_unlock_bh(&sc->tx.txq[i].axq_lock);
  1428. }
  1429. }
  1430. }
  1431. return r;
  1432. }
  1433. /*
  1434. * This function will allocate both the DMA descriptor structure, and the
  1435. * buffers it contains. These are used to contain the descriptors used
  1436. * by the system.
  1437. */
  1438. int ath_descdma_setup(struct ath_softc *sc, struct ath_descdma *dd,
  1439. struct list_head *head, const char *name,
  1440. int nbuf, int ndesc)
  1441. {
  1442. #define DS2PHYS(_dd, _ds) \
  1443. ((_dd)->dd_desc_paddr + ((caddr_t)(_ds) - (caddr_t)(_dd)->dd_desc))
  1444. #define ATH_DESC_4KB_BOUND_CHECK(_daddr) ((((_daddr) & 0xFFF) > 0xF7F) ? 1 : 0)
  1445. #define ATH_DESC_4KB_BOUND_NUM_SKIPPED(_len) ((_len) / 4096)
  1446. struct ath_desc *ds;
  1447. struct ath_buf *bf;
  1448. int i, bsize, error;
  1449. DPRINTF(sc, ATH_DBG_CONFIG, "%s DMA: %u buffers %u desc/buf\n",
  1450. name, nbuf, ndesc);
  1451. INIT_LIST_HEAD(head);
  1452. /* ath_desc must be a multiple of DWORDs */
  1453. if ((sizeof(struct ath_desc) % 4) != 0) {
  1454. DPRINTF(sc, ATH_DBG_FATAL, "ath_desc not DWORD aligned\n");
  1455. ASSERT((sizeof(struct ath_desc) % 4) == 0);
  1456. error = -ENOMEM;
  1457. goto fail;
  1458. }
  1459. dd->dd_desc_len = sizeof(struct ath_desc) * nbuf * ndesc;
  1460. /*
  1461. * Need additional DMA memory because we can't use
  1462. * descriptors that cross the 4K page boundary. Assume
  1463. * one skipped descriptor per 4K page.
  1464. */
  1465. if (!(sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_4KB_SPLITTRANS)) {
  1466. u32 ndesc_skipped =
  1467. ATH_DESC_4KB_BOUND_NUM_SKIPPED(dd->dd_desc_len);
  1468. u32 dma_len;
  1469. while (ndesc_skipped) {
  1470. dma_len = ndesc_skipped * sizeof(struct ath_desc);
  1471. dd->dd_desc_len += dma_len;
  1472. ndesc_skipped = ATH_DESC_4KB_BOUND_NUM_SKIPPED(dma_len);
  1473. };
  1474. }
  1475. /* allocate descriptors */
  1476. dd->dd_desc = dma_alloc_coherent(sc->dev, dd->dd_desc_len,
  1477. &dd->dd_desc_paddr, GFP_KERNEL);
  1478. if (dd->dd_desc == NULL) {
  1479. error = -ENOMEM;
  1480. goto fail;
  1481. }
  1482. ds = dd->dd_desc;
  1483. DPRINTF(sc, ATH_DBG_CONFIG, "%s DMA map: %p (%u) -> %llx (%u)\n",
  1484. name, ds, (u32) dd->dd_desc_len,
  1485. ito64(dd->dd_desc_paddr), /*XXX*/(u32) dd->dd_desc_len);
  1486. /* allocate buffers */
  1487. bsize = sizeof(struct ath_buf) * nbuf;
  1488. bf = kzalloc(bsize, GFP_KERNEL);
  1489. if (bf == NULL) {
  1490. error = -ENOMEM;
  1491. goto fail2;
  1492. }
  1493. dd->dd_bufptr = bf;
  1494. for (i = 0; i < nbuf; i++, bf++, ds += ndesc) {
  1495. bf->bf_desc = ds;
  1496. bf->bf_daddr = DS2PHYS(dd, ds);
  1497. if (!(sc->sc_ah->caps.hw_caps &
  1498. ATH9K_HW_CAP_4KB_SPLITTRANS)) {
  1499. /*
  1500. * Skip descriptor addresses which can cause 4KB
  1501. * boundary crossing (addr + length) with a 32 dword
  1502. * descriptor fetch.
  1503. */
  1504. while (ATH_DESC_4KB_BOUND_CHECK(bf->bf_daddr)) {
  1505. ASSERT((caddr_t) bf->bf_desc <
  1506. ((caddr_t) dd->dd_desc +
  1507. dd->dd_desc_len));
  1508. ds += ndesc;
  1509. bf->bf_desc = ds;
  1510. bf->bf_daddr = DS2PHYS(dd, ds);
  1511. }
  1512. }
  1513. list_add_tail(&bf->list, head);
  1514. }
  1515. return 0;
  1516. fail2:
  1517. dma_free_coherent(sc->dev, dd->dd_desc_len, dd->dd_desc,
  1518. dd->dd_desc_paddr);
  1519. fail:
  1520. memset(dd, 0, sizeof(*dd));
  1521. return error;
  1522. #undef ATH_DESC_4KB_BOUND_CHECK
  1523. #undef ATH_DESC_4KB_BOUND_NUM_SKIPPED
  1524. #undef DS2PHYS
  1525. }
  1526. void ath_descdma_cleanup(struct ath_softc *sc,
  1527. struct ath_descdma *dd,
  1528. struct list_head *head)
  1529. {
  1530. dma_free_coherent(sc->dev, dd->dd_desc_len, dd->dd_desc,
  1531. dd->dd_desc_paddr);
  1532. INIT_LIST_HEAD(head);
  1533. kfree(dd->dd_bufptr);
  1534. memset(dd, 0, sizeof(*dd));
  1535. }
  1536. int ath_get_hal_qnum(u16 queue, struct ath_softc *sc)
  1537. {
  1538. int qnum;
  1539. switch (queue) {
  1540. case 0:
  1541. qnum = sc->tx.hwq_map[ATH9K_WME_AC_VO];
  1542. break;
  1543. case 1:
  1544. qnum = sc->tx.hwq_map[ATH9K_WME_AC_VI];
  1545. break;
  1546. case 2:
  1547. qnum = sc->tx.hwq_map[ATH9K_WME_AC_BE];
  1548. break;
  1549. case 3:
  1550. qnum = sc->tx.hwq_map[ATH9K_WME_AC_BK];
  1551. break;
  1552. default:
  1553. qnum = sc->tx.hwq_map[ATH9K_WME_AC_BE];
  1554. break;
  1555. }
  1556. return qnum;
  1557. }
  1558. int ath_get_mac80211_qnum(u32 queue, struct ath_softc *sc)
  1559. {
  1560. int qnum;
  1561. switch (queue) {
  1562. case ATH9K_WME_AC_VO:
  1563. qnum = 0;
  1564. break;
  1565. case ATH9K_WME_AC_VI:
  1566. qnum = 1;
  1567. break;
  1568. case ATH9K_WME_AC_BE:
  1569. qnum = 2;
  1570. break;
  1571. case ATH9K_WME_AC_BK:
  1572. qnum = 3;
  1573. break;
  1574. default:
  1575. qnum = -1;
  1576. break;
  1577. }
  1578. return qnum;
  1579. }
  1580. /* XXX: Remove me once we don't depend on ath9k_channel for all
  1581. * this redundant data */
  1582. void ath9k_update_ichannel(struct ath_softc *sc, struct ieee80211_hw *hw,
  1583. struct ath9k_channel *ichan)
  1584. {
  1585. struct ieee80211_channel *chan = hw->conf.channel;
  1586. struct ieee80211_conf *conf = &hw->conf;
  1587. ichan->channel = chan->center_freq;
  1588. ichan->chan = chan;
  1589. if (chan->band == IEEE80211_BAND_2GHZ) {
  1590. ichan->chanmode = CHANNEL_G;
  1591. ichan->channelFlags = CHANNEL_2GHZ | CHANNEL_OFDM | CHANNEL_G;
  1592. } else {
  1593. ichan->chanmode = CHANNEL_A;
  1594. ichan->channelFlags = CHANNEL_5GHZ | CHANNEL_OFDM;
  1595. }
  1596. sc->tx_chan_width = ATH9K_HT_MACMODE_20;
  1597. if (conf_is_ht(conf)) {
  1598. if (conf_is_ht40(conf))
  1599. sc->tx_chan_width = ATH9K_HT_MACMODE_2040;
  1600. ichan->chanmode = ath_get_extchanmode(sc, chan,
  1601. conf->channel_type);
  1602. }
  1603. }
  1604. /**********************/
  1605. /* mac80211 callbacks */
  1606. /**********************/
  1607. static int ath9k_start(struct ieee80211_hw *hw)
  1608. {
  1609. struct ath_wiphy *aphy = hw->priv;
  1610. struct ath_softc *sc = aphy->sc;
  1611. struct ieee80211_channel *curchan = hw->conf.channel;
  1612. struct ath9k_channel *init_channel;
  1613. int r;
  1614. DPRINTF(sc, ATH_DBG_CONFIG, "Starting driver with "
  1615. "initial channel: %d MHz\n", curchan->center_freq);
  1616. mutex_lock(&sc->mutex);
  1617. if (ath9k_wiphy_started(sc)) {
  1618. if (sc->chan_idx == curchan->hw_value) {
  1619. /*
  1620. * Already on the operational channel, the new wiphy
  1621. * can be marked active.
  1622. */
  1623. aphy->state = ATH_WIPHY_ACTIVE;
  1624. ieee80211_wake_queues(hw);
  1625. } else {
  1626. /*
  1627. * Another wiphy is on another channel, start the new
  1628. * wiphy in paused state.
  1629. */
  1630. aphy->state = ATH_WIPHY_PAUSED;
  1631. ieee80211_stop_queues(hw);
  1632. }
  1633. mutex_unlock(&sc->mutex);
  1634. return 0;
  1635. }
  1636. aphy->state = ATH_WIPHY_ACTIVE;
  1637. /* setup initial channel */
  1638. sc->chan_idx = curchan->hw_value;
  1639. init_channel = ath_get_curchannel(sc, hw);
  1640. /* Reset SERDES registers */
  1641. ath9k_hw_configpcipowersave(sc->sc_ah, 0, 0);
  1642. /*
  1643. * The basic interface to setting the hardware in a good
  1644. * state is ``reset''. On return the hardware is known to
  1645. * be powered up and with interrupts disabled. This must
  1646. * be followed by initialization of the appropriate bits
  1647. * and then setup of the interrupt mask.
  1648. */
  1649. spin_lock_bh(&sc->sc_resetlock);
  1650. r = ath9k_hw_reset(sc->sc_ah, init_channel, false);
  1651. if (r) {
  1652. DPRINTF(sc, ATH_DBG_FATAL,
  1653. "Unable to reset hardware; reset status %d "
  1654. "(freq %u MHz)\n", r,
  1655. curchan->center_freq);
  1656. spin_unlock_bh(&sc->sc_resetlock);
  1657. goto mutex_unlock;
  1658. }
  1659. spin_unlock_bh(&sc->sc_resetlock);
  1660. /*
  1661. * This is needed only to setup initial state
  1662. * but it's best done after a reset.
  1663. */
  1664. ath_update_txpow(sc);
  1665. /*
  1666. * Setup the hardware after reset:
  1667. * The receive engine is set going.
  1668. * Frame transmit is handled entirely
  1669. * in the frame output path; there's nothing to do
  1670. * here except setup the interrupt mask.
  1671. */
  1672. if (ath_startrecv(sc) != 0) {
  1673. DPRINTF(sc, ATH_DBG_FATAL, "Unable to start recv logic\n");
  1674. r = -EIO;
  1675. goto mutex_unlock;
  1676. }
  1677. /* Setup our intr mask. */
  1678. sc->imask = ATH9K_INT_RX | ATH9K_INT_TX
  1679. | ATH9K_INT_RXEOL | ATH9K_INT_RXORN
  1680. | ATH9K_INT_FATAL | ATH9K_INT_GLOBAL;
  1681. if (sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_GTT)
  1682. sc->imask |= ATH9K_INT_GTT;
  1683. if (sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_HT)
  1684. sc->imask |= ATH9K_INT_CST;
  1685. ath_cache_conf_rate(sc, &hw->conf);
  1686. sc->sc_flags &= ~SC_OP_INVALID;
  1687. /* Disable BMISS interrupt when we're not associated */
  1688. sc->imask &= ~(ATH9K_INT_SWBA | ATH9K_INT_BMISS);
  1689. ath9k_hw_set_interrupts(sc->sc_ah, sc->imask);
  1690. ieee80211_wake_queues(hw);
  1691. ieee80211_queue_delayed_work(sc->hw, &sc->tx_complete_work, 0);
  1692. if ((sc->btcoex_info.btcoex_scheme != ATH_BTCOEX_CFG_NONE) &&
  1693. !(sc->sc_flags & SC_OP_BTCOEX_ENABLED)) {
  1694. ath_btcoex_set_weight(&sc->btcoex_info, AR_BT_COEX_WGHT,
  1695. AR_STOMP_LOW_WLAN_WGHT);
  1696. ath9k_hw_btcoex_enable(sc->sc_ah);
  1697. ath_pcie_aspm_disable(sc);
  1698. if (sc->btcoex_info.btcoex_scheme == ATH_BTCOEX_CFG_3WIRE)
  1699. ath_btcoex_timer_resume(sc, &sc->btcoex_info);
  1700. }
  1701. mutex_unlock:
  1702. mutex_unlock(&sc->mutex);
  1703. return r;
  1704. }
  1705. static int ath9k_tx(struct ieee80211_hw *hw,
  1706. struct sk_buff *skb)
  1707. {
  1708. struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
  1709. struct ath_wiphy *aphy = hw->priv;
  1710. struct ath_softc *sc = aphy->sc;
  1711. struct ath_tx_control txctl;
  1712. int hdrlen, padsize;
  1713. if (aphy->state != ATH_WIPHY_ACTIVE && aphy->state != ATH_WIPHY_SCAN) {
  1714. printk(KERN_DEBUG "ath9k: %s: TX in unexpected wiphy state "
  1715. "%d\n", wiphy_name(hw->wiphy), aphy->state);
  1716. goto exit;
  1717. }
  1718. if (sc->ps_enabled) {
  1719. struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
  1720. /*
  1721. * mac80211 does not set PM field for normal data frames, so we
  1722. * need to update that based on the current PS mode.
  1723. */
  1724. if (ieee80211_is_data(hdr->frame_control) &&
  1725. !ieee80211_is_nullfunc(hdr->frame_control) &&
  1726. !ieee80211_has_pm(hdr->frame_control)) {
  1727. DPRINTF(sc, ATH_DBG_PS, "Add PM=1 for a TX frame "
  1728. "while in PS mode\n");
  1729. hdr->frame_control |= cpu_to_le16(IEEE80211_FCTL_PM);
  1730. }
  1731. }
  1732. if (unlikely(sc->sc_ah->power_mode != ATH9K_PM_AWAKE)) {
  1733. /*
  1734. * We are using PS-Poll and mac80211 can request TX while in
  1735. * power save mode. Need to wake up hardware for the TX to be
  1736. * completed and if needed, also for RX of buffered frames.
  1737. */
  1738. struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
  1739. ath9k_ps_wakeup(sc);
  1740. ath9k_hw_setrxabort(sc->sc_ah, 0);
  1741. if (ieee80211_is_pspoll(hdr->frame_control)) {
  1742. DPRINTF(sc, ATH_DBG_PS, "Sending PS-Poll to pick a "
  1743. "buffered frame\n");
  1744. sc->sc_flags |= SC_OP_WAIT_FOR_PSPOLL_DATA;
  1745. } else {
  1746. DPRINTF(sc, ATH_DBG_PS, "Wake up to complete TX\n");
  1747. sc->sc_flags |= SC_OP_WAIT_FOR_TX_ACK;
  1748. }
  1749. /*
  1750. * The actual restore operation will happen only after
  1751. * the sc_flags bit is cleared. We are just dropping
  1752. * the ps_usecount here.
  1753. */
  1754. ath9k_ps_restore(sc);
  1755. }
  1756. memset(&txctl, 0, sizeof(struct ath_tx_control));
  1757. /*
  1758. * As a temporary workaround, assign seq# here; this will likely need
  1759. * to be cleaned up to work better with Beacon transmission and virtual
  1760. * BSSes.
  1761. */
  1762. if (info->flags & IEEE80211_TX_CTL_ASSIGN_SEQ) {
  1763. struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
  1764. if (info->flags & IEEE80211_TX_CTL_FIRST_FRAGMENT)
  1765. sc->tx.seq_no += 0x10;
  1766. hdr->seq_ctrl &= cpu_to_le16(IEEE80211_SCTL_FRAG);
  1767. hdr->seq_ctrl |= cpu_to_le16(sc->tx.seq_no);
  1768. }
  1769. /* Add the padding after the header if this is not already done */
  1770. hdrlen = ieee80211_get_hdrlen_from_skb(skb);
  1771. if (hdrlen & 3) {
  1772. padsize = hdrlen % 4;
  1773. if (skb_headroom(skb) < padsize)
  1774. return -1;
  1775. skb_push(skb, padsize);
  1776. memmove(skb->data, skb->data + padsize, hdrlen);
  1777. }
  1778. /* Check if a tx queue is available */
  1779. txctl.txq = ath_test_get_txq(sc, skb);
  1780. if (!txctl.txq)
  1781. goto exit;
  1782. DPRINTF(sc, ATH_DBG_XMIT, "transmitting packet, skb: %p\n", skb);
  1783. if (ath_tx_start(hw, skb, &txctl) != 0) {
  1784. DPRINTF(sc, ATH_DBG_XMIT, "TX failed\n");
  1785. goto exit;
  1786. }
  1787. return 0;
  1788. exit:
  1789. dev_kfree_skb_any(skb);
  1790. return 0;
  1791. }
  1792. static void ath9k_stop(struct ieee80211_hw *hw)
  1793. {
  1794. struct ath_wiphy *aphy = hw->priv;
  1795. struct ath_softc *sc = aphy->sc;
  1796. mutex_lock(&sc->mutex);
  1797. aphy->state = ATH_WIPHY_INACTIVE;
  1798. cancel_delayed_work_sync(&sc->ath_led_blink_work);
  1799. cancel_delayed_work_sync(&sc->tx_complete_work);
  1800. if (!sc->num_sec_wiphy) {
  1801. cancel_delayed_work_sync(&sc->wiphy_work);
  1802. cancel_work_sync(&sc->chan_work);
  1803. }
  1804. if (sc->sc_flags & SC_OP_INVALID) {
  1805. DPRINTF(sc, ATH_DBG_ANY, "Device not present\n");
  1806. mutex_unlock(&sc->mutex);
  1807. return;
  1808. }
  1809. if (ath9k_wiphy_started(sc)) {
  1810. mutex_unlock(&sc->mutex);
  1811. return; /* another wiphy still in use */
  1812. }
  1813. if (sc->sc_flags & SC_OP_BTCOEX_ENABLED) {
  1814. ath9k_hw_btcoex_disable(sc->sc_ah);
  1815. if (sc->btcoex_info.btcoex_scheme == ATH_BTCOEX_CFG_3WIRE)
  1816. ath_btcoex_timer_pause(sc, &sc->btcoex_info);
  1817. }
  1818. /* make sure h/w will not generate any interrupt
  1819. * before setting the invalid flag. */
  1820. ath9k_hw_set_interrupts(sc->sc_ah, 0);
  1821. if (!(sc->sc_flags & SC_OP_INVALID)) {
  1822. ath_drain_all_txq(sc, false);
  1823. ath_stoprecv(sc);
  1824. ath9k_hw_phy_disable(sc->sc_ah);
  1825. } else
  1826. sc->rx.rxlink = NULL;
  1827. /* disable HAL and put h/w to sleep */
  1828. ath9k_hw_disable(sc->sc_ah);
  1829. ath9k_hw_configpcipowersave(sc->sc_ah, 1, 1);
  1830. ath9k_hw_setpower(sc->sc_ah, ATH9K_PM_FULL_SLEEP);
  1831. sc->sc_flags |= SC_OP_INVALID;
  1832. mutex_unlock(&sc->mutex);
  1833. DPRINTF(sc, ATH_DBG_CONFIG, "Driver halt\n");
  1834. }
  1835. static int ath9k_add_interface(struct ieee80211_hw *hw,
  1836. struct ieee80211_if_init_conf *conf)
  1837. {
  1838. struct ath_wiphy *aphy = hw->priv;
  1839. struct ath_softc *sc = aphy->sc;
  1840. struct ath_vif *avp = (void *)conf->vif->drv_priv;
  1841. enum nl80211_iftype ic_opmode = NL80211_IFTYPE_UNSPECIFIED;
  1842. int ret = 0;
  1843. mutex_lock(&sc->mutex);
  1844. if (!(sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_BSSIDMASK) &&
  1845. sc->nvifs > 0) {
  1846. ret = -ENOBUFS;
  1847. goto out;
  1848. }
  1849. switch (conf->type) {
  1850. case NL80211_IFTYPE_STATION:
  1851. ic_opmode = NL80211_IFTYPE_STATION;
  1852. break;
  1853. case NL80211_IFTYPE_ADHOC:
  1854. case NL80211_IFTYPE_AP:
  1855. case NL80211_IFTYPE_MESH_POINT:
  1856. if (sc->nbcnvifs >= ATH_BCBUF) {
  1857. ret = -ENOBUFS;
  1858. goto out;
  1859. }
  1860. ic_opmode = conf->type;
  1861. break;
  1862. default:
  1863. DPRINTF(sc, ATH_DBG_FATAL,
  1864. "Interface type %d not yet supported\n", conf->type);
  1865. ret = -EOPNOTSUPP;
  1866. goto out;
  1867. }
  1868. DPRINTF(sc, ATH_DBG_CONFIG, "Attach a VIF of type: %d\n", ic_opmode);
  1869. /* Set the VIF opmode */
  1870. avp->av_opmode = ic_opmode;
  1871. avp->av_bslot = -1;
  1872. sc->nvifs++;
  1873. if (sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_BSSIDMASK)
  1874. ath9k_set_bssid_mask(hw);
  1875. if (sc->nvifs > 1)
  1876. goto out; /* skip global settings for secondary vif */
  1877. if (ic_opmode == NL80211_IFTYPE_AP) {
  1878. ath9k_hw_set_tsfadjust(sc->sc_ah, 1);
  1879. sc->sc_flags |= SC_OP_TSF_RESET;
  1880. }
  1881. /* Set the device opmode */
  1882. sc->sc_ah->opmode = ic_opmode;
  1883. /*
  1884. * Enable MIB interrupts when there are hardware phy counters.
  1885. * Note we only do this (at the moment) for station mode.
  1886. */
  1887. if ((conf->type == NL80211_IFTYPE_STATION) ||
  1888. (conf->type == NL80211_IFTYPE_ADHOC) ||
  1889. (conf->type == NL80211_IFTYPE_MESH_POINT)) {
  1890. sc->imask |= ATH9K_INT_MIB;
  1891. sc->imask |= ATH9K_INT_TSFOOR;
  1892. }
  1893. ath9k_hw_set_interrupts(sc->sc_ah, sc->imask);
  1894. if (conf->type == NL80211_IFTYPE_AP ||
  1895. conf->type == NL80211_IFTYPE_ADHOC ||
  1896. conf->type == NL80211_IFTYPE_MONITOR)
  1897. ath_start_ani(sc);
  1898. out:
  1899. mutex_unlock(&sc->mutex);
  1900. return ret;
  1901. }
  1902. static void ath9k_remove_interface(struct ieee80211_hw *hw,
  1903. struct ieee80211_if_init_conf *conf)
  1904. {
  1905. struct ath_wiphy *aphy = hw->priv;
  1906. struct ath_softc *sc = aphy->sc;
  1907. struct ath_vif *avp = (void *)conf->vif->drv_priv;
  1908. int i;
  1909. DPRINTF(sc, ATH_DBG_CONFIG, "Detach Interface\n");
  1910. mutex_lock(&sc->mutex);
  1911. /* Stop ANI */
  1912. del_timer_sync(&sc->ani.timer);
  1913. /* Reclaim beacon resources */
  1914. if ((sc->sc_ah->opmode == NL80211_IFTYPE_AP) ||
  1915. (sc->sc_ah->opmode == NL80211_IFTYPE_ADHOC) ||
  1916. (sc->sc_ah->opmode == NL80211_IFTYPE_MESH_POINT)) {
  1917. ath9k_hw_stoptxdma(sc->sc_ah, sc->beacon.beaconq);
  1918. ath_beacon_return(sc, avp);
  1919. }
  1920. sc->sc_flags &= ~SC_OP_BEACONS;
  1921. for (i = 0; i < ARRAY_SIZE(sc->beacon.bslot); i++) {
  1922. if (sc->beacon.bslot[i] == conf->vif) {
  1923. printk(KERN_DEBUG "%s: vif had allocated beacon "
  1924. "slot\n", __func__);
  1925. sc->beacon.bslot[i] = NULL;
  1926. sc->beacon.bslot_aphy[i] = NULL;
  1927. }
  1928. }
  1929. sc->nvifs--;
  1930. mutex_unlock(&sc->mutex);
  1931. }
  1932. static int ath9k_config(struct ieee80211_hw *hw, u32 changed)
  1933. {
  1934. struct ath_wiphy *aphy = hw->priv;
  1935. struct ath_softc *sc = aphy->sc;
  1936. struct ieee80211_conf *conf = &hw->conf;
  1937. struct ath_hw *ah = sc->sc_ah;
  1938. bool all_wiphys_idle = false, disable_radio = false;
  1939. mutex_lock(&sc->mutex);
  1940. /* Leave this as the first check */
  1941. if (changed & IEEE80211_CONF_CHANGE_IDLE) {
  1942. spin_lock_bh(&sc->wiphy_lock);
  1943. all_wiphys_idle = ath9k_all_wiphys_idle(sc);
  1944. spin_unlock_bh(&sc->wiphy_lock);
  1945. if (conf->flags & IEEE80211_CONF_IDLE){
  1946. if (all_wiphys_idle)
  1947. disable_radio = true;
  1948. }
  1949. else if (all_wiphys_idle) {
  1950. ath_radio_enable(sc);
  1951. DPRINTF(sc, ATH_DBG_CONFIG,
  1952. "not-idle: enabling radio\n");
  1953. }
  1954. }
  1955. if (changed & IEEE80211_CONF_CHANGE_PS) {
  1956. if (conf->flags & IEEE80211_CONF_PS) {
  1957. if (!(ah->caps.hw_caps &
  1958. ATH9K_HW_CAP_AUTOSLEEP)) {
  1959. if ((sc->imask & ATH9K_INT_TIM_TIMER) == 0) {
  1960. sc->imask |= ATH9K_INT_TIM_TIMER;
  1961. ath9k_hw_set_interrupts(sc->sc_ah,
  1962. sc->imask);
  1963. }
  1964. ath9k_hw_setrxabort(sc->sc_ah, 1);
  1965. }
  1966. sc->ps_enabled = true;
  1967. } else {
  1968. sc->ps_enabled = false;
  1969. ath9k_hw_setpower(sc->sc_ah, ATH9K_PM_AWAKE);
  1970. if (!(ah->caps.hw_caps &
  1971. ATH9K_HW_CAP_AUTOSLEEP)) {
  1972. ath9k_hw_setrxabort(sc->sc_ah, 0);
  1973. sc->sc_flags &= ~(SC_OP_WAIT_FOR_BEACON |
  1974. SC_OP_WAIT_FOR_CAB |
  1975. SC_OP_WAIT_FOR_PSPOLL_DATA |
  1976. SC_OP_WAIT_FOR_TX_ACK);
  1977. if (sc->imask & ATH9K_INT_TIM_TIMER) {
  1978. sc->imask &= ~ATH9K_INT_TIM_TIMER;
  1979. ath9k_hw_set_interrupts(sc->sc_ah,
  1980. sc->imask);
  1981. }
  1982. }
  1983. }
  1984. }
  1985. if (changed & IEEE80211_CONF_CHANGE_CHANNEL) {
  1986. struct ieee80211_channel *curchan = hw->conf.channel;
  1987. int pos = curchan->hw_value;
  1988. aphy->chan_idx = pos;
  1989. aphy->chan_is_ht = conf_is_ht(conf);
  1990. if (aphy->state == ATH_WIPHY_SCAN ||
  1991. aphy->state == ATH_WIPHY_ACTIVE)
  1992. ath9k_wiphy_pause_all_forced(sc, aphy);
  1993. else {
  1994. /*
  1995. * Do not change operational channel based on a paused
  1996. * wiphy changes.
  1997. */
  1998. goto skip_chan_change;
  1999. }
  2000. DPRINTF(sc, ATH_DBG_CONFIG, "Set channel: %d MHz\n",
  2001. curchan->center_freq);
  2002. /* XXX: remove me eventualy */
  2003. ath9k_update_ichannel(sc, hw, &sc->sc_ah->channels[pos]);
  2004. ath_update_chainmask(sc, conf_is_ht(conf));
  2005. if (ath_set_channel(sc, hw, &sc->sc_ah->channels[pos]) < 0) {
  2006. DPRINTF(sc, ATH_DBG_FATAL, "Unable to set channel\n");
  2007. mutex_unlock(&sc->mutex);
  2008. return -EINVAL;
  2009. }
  2010. }
  2011. skip_chan_change:
  2012. if (changed & IEEE80211_CONF_CHANGE_POWER)
  2013. sc->config.txpowlimit = 2 * conf->power_level;
  2014. if (disable_radio) {
  2015. DPRINTF(sc, ATH_DBG_CONFIG, "idle: disabling radio\n");
  2016. ath_radio_disable(sc);
  2017. }
  2018. mutex_unlock(&sc->mutex);
  2019. return 0;
  2020. }
  2021. #define SUPPORTED_FILTERS \
  2022. (FIF_PROMISC_IN_BSS | \
  2023. FIF_ALLMULTI | \
  2024. FIF_CONTROL | \
  2025. FIF_PSPOLL | \
  2026. FIF_OTHER_BSS | \
  2027. FIF_BCN_PRBRESP_PROMISC | \
  2028. FIF_FCSFAIL)
  2029. /* FIXME: sc->sc_full_reset ? */
  2030. static void ath9k_configure_filter(struct ieee80211_hw *hw,
  2031. unsigned int changed_flags,
  2032. unsigned int *total_flags,
  2033. u64 multicast)
  2034. {
  2035. struct ath_wiphy *aphy = hw->priv;
  2036. struct ath_softc *sc = aphy->sc;
  2037. u32 rfilt;
  2038. changed_flags &= SUPPORTED_FILTERS;
  2039. *total_flags &= SUPPORTED_FILTERS;
  2040. sc->rx.rxfilter = *total_flags;
  2041. ath9k_ps_wakeup(sc);
  2042. rfilt = ath_calcrxfilter(sc);
  2043. ath9k_hw_setrxfilter(sc->sc_ah, rfilt);
  2044. ath9k_ps_restore(sc);
  2045. DPRINTF(sc, ATH_DBG_CONFIG, "Set HW RX filter: 0x%x\n", rfilt);
  2046. }
  2047. static void ath9k_sta_notify(struct ieee80211_hw *hw,
  2048. struct ieee80211_vif *vif,
  2049. enum sta_notify_cmd cmd,
  2050. struct ieee80211_sta *sta)
  2051. {
  2052. struct ath_wiphy *aphy = hw->priv;
  2053. struct ath_softc *sc = aphy->sc;
  2054. switch (cmd) {
  2055. case STA_NOTIFY_ADD:
  2056. ath_node_attach(sc, sta);
  2057. break;
  2058. case STA_NOTIFY_REMOVE:
  2059. ath_node_detach(sc, sta);
  2060. break;
  2061. default:
  2062. break;
  2063. }
  2064. }
  2065. static int ath9k_conf_tx(struct ieee80211_hw *hw, u16 queue,
  2066. const struct ieee80211_tx_queue_params *params)
  2067. {
  2068. struct ath_wiphy *aphy = hw->priv;
  2069. struct ath_softc *sc = aphy->sc;
  2070. struct ath9k_tx_queue_info qi;
  2071. int ret = 0, qnum;
  2072. if (queue >= WME_NUM_AC)
  2073. return 0;
  2074. mutex_lock(&sc->mutex);
  2075. memset(&qi, 0, sizeof(struct ath9k_tx_queue_info));
  2076. qi.tqi_aifs = params->aifs;
  2077. qi.tqi_cwmin = params->cw_min;
  2078. qi.tqi_cwmax = params->cw_max;
  2079. qi.tqi_burstTime = params->txop;
  2080. qnum = ath_get_hal_qnum(queue, sc);
  2081. DPRINTF(sc, ATH_DBG_CONFIG,
  2082. "Configure tx [queue/halq] [%d/%d], "
  2083. "aifs: %d, cw_min: %d, cw_max: %d, txop: %d\n",
  2084. queue, qnum, params->aifs, params->cw_min,
  2085. params->cw_max, params->txop);
  2086. ret = ath_txq_update(sc, qnum, &qi);
  2087. if (ret)
  2088. DPRINTF(sc, ATH_DBG_FATAL, "TXQ Update failed\n");
  2089. mutex_unlock(&sc->mutex);
  2090. return ret;
  2091. }
  2092. static int ath9k_set_key(struct ieee80211_hw *hw,
  2093. enum set_key_cmd cmd,
  2094. struct ieee80211_vif *vif,
  2095. struct ieee80211_sta *sta,
  2096. struct ieee80211_key_conf *key)
  2097. {
  2098. struct ath_wiphy *aphy = hw->priv;
  2099. struct ath_softc *sc = aphy->sc;
  2100. int ret = 0;
  2101. if (modparam_nohwcrypt)
  2102. return -ENOSPC;
  2103. mutex_lock(&sc->mutex);
  2104. ath9k_ps_wakeup(sc);
  2105. DPRINTF(sc, ATH_DBG_CONFIG, "Set HW Key\n");
  2106. switch (cmd) {
  2107. case SET_KEY:
  2108. ret = ath_key_config(sc, vif, sta, key);
  2109. if (ret >= 0) {
  2110. key->hw_key_idx = ret;
  2111. /* push IV and Michael MIC generation to stack */
  2112. key->flags |= IEEE80211_KEY_FLAG_GENERATE_IV;
  2113. if (key->alg == ALG_TKIP)
  2114. key->flags |= IEEE80211_KEY_FLAG_GENERATE_MMIC;
  2115. if (sc->sc_ah->sw_mgmt_crypto && key->alg == ALG_CCMP)
  2116. key->flags |= IEEE80211_KEY_FLAG_SW_MGMT;
  2117. ret = 0;
  2118. }
  2119. break;
  2120. case DISABLE_KEY:
  2121. ath_key_delete(sc, key);
  2122. break;
  2123. default:
  2124. ret = -EINVAL;
  2125. }
  2126. ath9k_ps_restore(sc);
  2127. mutex_unlock(&sc->mutex);
  2128. return ret;
  2129. }
  2130. static void ath9k_bss_info_changed(struct ieee80211_hw *hw,
  2131. struct ieee80211_vif *vif,
  2132. struct ieee80211_bss_conf *bss_conf,
  2133. u32 changed)
  2134. {
  2135. struct ath_wiphy *aphy = hw->priv;
  2136. struct ath_softc *sc = aphy->sc;
  2137. struct ath_hw *ah = sc->sc_ah;
  2138. struct ath_vif *avp = (void *)vif->drv_priv;
  2139. u32 rfilt = 0;
  2140. int error, i;
  2141. mutex_lock(&sc->mutex);
  2142. /*
  2143. * TODO: Need to decide which hw opmode to use for
  2144. * multi-interface cases
  2145. * XXX: This belongs into add_interface!
  2146. */
  2147. if (vif->type == NL80211_IFTYPE_AP &&
  2148. ah->opmode != NL80211_IFTYPE_AP) {
  2149. ah->opmode = NL80211_IFTYPE_STATION;
  2150. ath9k_hw_setopmode(ah);
  2151. memcpy(sc->curbssid, sc->sc_ah->macaddr, ETH_ALEN);
  2152. sc->curaid = 0;
  2153. ath9k_hw_write_associd(sc);
  2154. /* Request full reset to get hw opmode changed properly */
  2155. sc->sc_flags |= SC_OP_FULL_RESET;
  2156. }
  2157. if ((changed & BSS_CHANGED_BSSID) &&
  2158. !is_zero_ether_addr(bss_conf->bssid)) {
  2159. switch (vif->type) {
  2160. case NL80211_IFTYPE_STATION:
  2161. case NL80211_IFTYPE_ADHOC:
  2162. case NL80211_IFTYPE_MESH_POINT:
  2163. /* Set BSSID */
  2164. memcpy(sc->curbssid, bss_conf->bssid, ETH_ALEN);
  2165. memcpy(avp->bssid, bss_conf->bssid, ETH_ALEN);
  2166. sc->curaid = 0;
  2167. ath9k_hw_write_associd(sc);
  2168. /* Set aggregation protection mode parameters */
  2169. sc->config.ath_aggr_prot = 0;
  2170. DPRINTF(sc, ATH_DBG_CONFIG,
  2171. "RX filter 0x%x bssid %pM aid 0x%x\n",
  2172. rfilt, sc->curbssid, sc->curaid);
  2173. /* need to reconfigure the beacon */
  2174. sc->sc_flags &= ~SC_OP_BEACONS ;
  2175. break;
  2176. default:
  2177. break;
  2178. }
  2179. }
  2180. if ((vif->type == NL80211_IFTYPE_ADHOC) ||
  2181. (vif->type == NL80211_IFTYPE_AP) ||
  2182. (vif->type == NL80211_IFTYPE_MESH_POINT)) {
  2183. if ((changed & BSS_CHANGED_BEACON) ||
  2184. (changed & BSS_CHANGED_BEACON_ENABLED &&
  2185. bss_conf->enable_beacon)) {
  2186. /*
  2187. * Allocate and setup the beacon frame.
  2188. *
  2189. * Stop any previous beacon DMA. This may be
  2190. * necessary, for example, when an ibss merge
  2191. * causes reconfiguration; we may be called
  2192. * with beacon transmission active.
  2193. */
  2194. ath9k_hw_stoptxdma(sc->sc_ah, sc->beacon.beaconq);
  2195. error = ath_beacon_alloc(aphy, vif);
  2196. if (!error)
  2197. ath_beacon_config(sc, vif);
  2198. }
  2199. }
  2200. /* Check for WLAN_CAPABILITY_PRIVACY ? */
  2201. if ((avp->av_opmode != NL80211_IFTYPE_STATION)) {
  2202. for (i = 0; i < IEEE80211_WEP_NKID; i++)
  2203. if (ath9k_hw_keyisvalid(sc->sc_ah, (u16)i))
  2204. ath9k_hw_keysetmac(sc->sc_ah,
  2205. (u16)i,
  2206. sc->curbssid);
  2207. }
  2208. /* Only legacy IBSS for now */
  2209. if (vif->type == NL80211_IFTYPE_ADHOC)
  2210. ath_update_chainmask(sc, 0);
  2211. if (changed & BSS_CHANGED_ERP_PREAMBLE) {
  2212. DPRINTF(sc, ATH_DBG_CONFIG, "BSS Changed PREAMBLE %d\n",
  2213. bss_conf->use_short_preamble);
  2214. if (bss_conf->use_short_preamble)
  2215. sc->sc_flags |= SC_OP_PREAMBLE_SHORT;
  2216. else
  2217. sc->sc_flags &= ~SC_OP_PREAMBLE_SHORT;
  2218. }
  2219. if (changed & BSS_CHANGED_ERP_CTS_PROT) {
  2220. DPRINTF(sc, ATH_DBG_CONFIG, "BSS Changed CTS PROT %d\n",
  2221. bss_conf->use_cts_prot);
  2222. if (bss_conf->use_cts_prot &&
  2223. hw->conf.channel->band != IEEE80211_BAND_5GHZ)
  2224. sc->sc_flags |= SC_OP_PROTECT_ENABLE;
  2225. else
  2226. sc->sc_flags &= ~SC_OP_PROTECT_ENABLE;
  2227. }
  2228. if (changed & BSS_CHANGED_ASSOC) {
  2229. DPRINTF(sc, ATH_DBG_CONFIG, "BSS Changed ASSOC %d\n",
  2230. bss_conf->assoc);
  2231. ath9k_bss_assoc_info(sc, vif, bss_conf);
  2232. }
  2233. /*
  2234. * The HW TSF has to be reset when the beacon interval changes.
  2235. * We set the flag here, and ath_beacon_config_ap() would take this
  2236. * into account when it gets called through the subsequent
  2237. * config_interface() call - with IFCC_BEACON in the changed field.
  2238. */
  2239. if (changed & BSS_CHANGED_BEACON_INT) {
  2240. sc->sc_flags |= SC_OP_TSF_RESET;
  2241. sc->beacon_interval = bss_conf->beacon_int;
  2242. }
  2243. mutex_unlock(&sc->mutex);
  2244. }
  2245. static u64 ath9k_get_tsf(struct ieee80211_hw *hw)
  2246. {
  2247. u64 tsf;
  2248. struct ath_wiphy *aphy = hw->priv;
  2249. struct ath_softc *sc = aphy->sc;
  2250. mutex_lock(&sc->mutex);
  2251. tsf = ath9k_hw_gettsf64(sc->sc_ah);
  2252. mutex_unlock(&sc->mutex);
  2253. return tsf;
  2254. }
  2255. static void ath9k_set_tsf(struct ieee80211_hw *hw, u64 tsf)
  2256. {
  2257. struct ath_wiphy *aphy = hw->priv;
  2258. struct ath_softc *sc = aphy->sc;
  2259. mutex_lock(&sc->mutex);
  2260. ath9k_hw_settsf64(sc->sc_ah, tsf);
  2261. mutex_unlock(&sc->mutex);
  2262. }
  2263. static void ath9k_reset_tsf(struct ieee80211_hw *hw)
  2264. {
  2265. struct ath_wiphy *aphy = hw->priv;
  2266. struct ath_softc *sc = aphy->sc;
  2267. mutex_lock(&sc->mutex);
  2268. ath9k_hw_reset_tsf(sc->sc_ah);
  2269. mutex_unlock(&sc->mutex);
  2270. }
  2271. static int ath9k_ampdu_action(struct ieee80211_hw *hw,
  2272. enum ieee80211_ampdu_mlme_action action,
  2273. struct ieee80211_sta *sta,
  2274. u16 tid, u16 *ssn)
  2275. {
  2276. struct ath_wiphy *aphy = hw->priv;
  2277. struct ath_softc *sc = aphy->sc;
  2278. int ret = 0;
  2279. switch (action) {
  2280. case IEEE80211_AMPDU_RX_START:
  2281. if (!(sc->sc_flags & SC_OP_RXAGGR))
  2282. ret = -ENOTSUPP;
  2283. break;
  2284. case IEEE80211_AMPDU_RX_STOP:
  2285. break;
  2286. case IEEE80211_AMPDU_TX_START:
  2287. ath_tx_aggr_start(sc, sta, tid, ssn);
  2288. ieee80211_start_tx_ba_cb_irqsafe(hw, sta->addr, tid);
  2289. break;
  2290. case IEEE80211_AMPDU_TX_STOP:
  2291. ath_tx_aggr_stop(sc, sta, tid);
  2292. ieee80211_stop_tx_ba_cb_irqsafe(hw, sta->addr, tid);
  2293. break;
  2294. case IEEE80211_AMPDU_TX_OPERATIONAL:
  2295. ath_tx_aggr_resume(sc, sta, tid);
  2296. break;
  2297. default:
  2298. DPRINTF(sc, ATH_DBG_FATAL, "Unknown AMPDU action\n");
  2299. }
  2300. return ret;
  2301. }
  2302. static void ath9k_sw_scan_start(struct ieee80211_hw *hw)
  2303. {
  2304. struct ath_wiphy *aphy = hw->priv;
  2305. struct ath_softc *sc = aphy->sc;
  2306. mutex_lock(&sc->mutex);
  2307. if (ath9k_wiphy_scanning(sc)) {
  2308. printk(KERN_DEBUG "ath9k: Two wiphys trying to scan at the "
  2309. "same time\n");
  2310. /*
  2311. * Do not allow the concurrent scanning state for now. This
  2312. * could be improved with scanning control moved into ath9k.
  2313. */
  2314. mutex_unlock(&sc->mutex);
  2315. return;
  2316. }
  2317. aphy->state = ATH_WIPHY_SCAN;
  2318. ath9k_wiphy_pause_all_forced(sc, aphy);
  2319. spin_lock_bh(&sc->ani_lock);
  2320. sc->sc_flags |= SC_OP_SCANNING;
  2321. spin_unlock_bh(&sc->ani_lock);
  2322. mutex_unlock(&sc->mutex);
  2323. }
  2324. static void ath9k_sw_scan_complete(struct ieee80211_hw *hw)
  2325. {
  2326. struct ath_wiphy *aphy = hw->priv;
  2327. struct ath_softc *sc = aphy->sc;
  2328. mutex_lock(&sc->mutex);
  2329. spin_lock_bh(&sc->ani_lock);
  2330. aphy->state = ATH_WIPHY_ACTIVE;
  2331. sc->sc_flags &= ~SC_OP_SCANNING;
  2332. sc->sc_flags |= SC_OP_FULL_RESET;
  2333. spin_unlock_bh(&sc->ani_lock);
  2334. ath_beacon_config(sc, NULL);
  2335. mutex_unlock(&sc->mutex);
  2336. }
  2337. struct ieee80211_ops ath9k_ops = {
  2338. .tx = ath9k_tx,
  2339. .start = ath9k_start,
  2340. .stop = ath9k_stop,
  2341. .add_interface = ath9k_add_interface,
  2342. .remove_interface = ath9k_remove_interface,
  2343. .config = ath9k_config,
  2344. .configure_filter = ath9k_configure_filter,
  2345. .sta_notify = ath9k_sta_notify,
  2346. .conf_tx = ath9k_conf_tx,
  2347. .bss_info_changed = ath9k_bss_info_changed,
  2348. .set_key = ath9k_set_key,
  2349. .get_tsf = ath9k_get_tsf,
  2350. .set_tsf = ath9k_set_tsf,
  2351. .reset_tsf = ath9k_reset_tsf,
  2352. .ampdu_action = ath9k_ampdu_action,
  2353. .sw_scan_start = ath9k_sw_scan_start,
  2354. .sw_scan_complete = ath9k_sw_scan_complete,
  2355. .rfkill_poll = ath9k_rfkill_poll_state,
  2356. };
  2357. static struct {
  2358. u32 version;
  2359. const char * name;
  2360. } ath_mac_bb_names[] = {
  2361. { AR_SREV_VERSION_5416_PCI, "5416" },
  2362. { AR_SREV_VERSION_5416_PCIE, "5418" },
  2363. { AR_SREV_VERSION_9100, "9100" },
  2364. { AR_SREV_VERSION_9160, "9160" },
  2365. { AR_SREV_VERSION_9280, "9280" },
  2366. { AR_SREV_VERSION_9285, "9285" },
  2367. { AR_SREV_VERSION_9287, "9287" }
  2368. };
  2369. static struct {
  2370. u16 version;
  2371. const char * name;
  2372. } ath_rf_names[] = {
  2373. { 0, "5133" },
  2374. { AR_RAD5133_SREV_MAJOR, "5133" },
  2375. { AR_RAD5122_SREV_MAJOR, "5122" },
  2376. { AR_RAD2133_SREV_MAJOR, "2133" },
  2377. { AR_RAD2122_SREV_MAJOR, "2122" }
  2378. };
  2379. /*
  2380. * Return the MAC/BB name. "????" is returned if the MAC/BB is unknown.
  2381. */
  2382. const char *
  2383. ath_mac_bb_name(u32 mac_bb_version)
  2384. {
  2385. int i;
  2386. for (i=0; i<ARRAY_SIZE(ath_mac_bb_names); i++) {
  2387. if (ath_mac_bb_names[i].version == mac_bb_version) {
  2388. return ath_mac_bb_names[i].name;
  2389. }
  2390. }
  2391. return "????";
  2392. }
  2393. /*
  2394. * Return the RF name. "????" is returned if the RF is unknown.
  2395. */
  2396. const char *
  2397. ath_rf_name(u16 rf_version)
  2398. {
  2399. int i;
  2400. for (i=0; i<ARRAY_SIZE(ath_rf_names); i++) {
  2401. if (ath_rf_names[i].version == rf_version) {
  2402. return ath_rf_names[i].name;
  2403. }
  2404. }
  2405. return "????";
  2406. }
  2407. static int __init ath9k_init(void)
  2408. {
  2409. int error;
  2410. /* Register rate control algorithm */
  2411. error = ath_rate_control_register();
  2412. if (error != 0) {
  2413. printk(KERN_ERR
  2414. "ath9k: Unable to register rate control "
  2415. "algorithm: %d\n",
  2416. error);
  2417. goto err_out;
  2418. }
  2419. error = ath9k_debug_create_root();
  2420. if (error) {
  2421. printk(KERN_ERR
  2422. "ath9k: Unable to create debugfs root: %d\n",
  2423. error);
  2424. goto err_rate_unregister;
  2425. }
  2426. error = ath_pci_init();
  2427. if (error < 0) {
  2428. printk(KERN_ERR
  2429. "ath9k: No PCI devices found, driver not installed.\n");
  2430. error = -ENODEV;
  2431. goto err_remove_root;
  2432. }
  2433. error = ath_ahb_init();
  2434. if (error < 0) {
  2435. error = -ENODEV;
  2436. goto err_pci_exit;
  2437. }
  2438. return 0;
  2439. err_pci_exit:
  2440. ath_pci_exit();
  2441. err_remove_root:
  2442. ath9k_debug_remove_root();
  2443. err_rate_unregister:
  2444. ath_rate_control_unregister();
  2445. err_out:
  2446. return error;
  2447. }
  2448. module_init(ath9k_init);
  2449. static void __exit ath9k_exit(void)
  2450. {
  2451. ath_ahb_exit();
  2452. ath_pci_exit();
  2453. ath9k_debug_remove_root();
  2454. ath_rate_control_unregister();
  2455. printk(KERN_INFO "%s: Driver unloaded\n", dev_info);
  2456. }
  2457. module_exit(ath9k_exit);