main.c 71 KB

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