main.c 71 KB

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