main.c 71 KB

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