main.c 71 KB

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