main.c 71 KB

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