main.c 72 KB

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