main.c 71 KB

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