main.c 71 KB

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