main.c 71 KB

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