main.c 72 KB

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