main.c 70 KB

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