main.c 71 KB

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