main.c 72 KB

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