main.c 71 KB

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